akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define FOR(i,a,b) for (int i=(a);i<(b);i++)
#define FORR(i,a,b) for (int i=(a);i>=(b);i--)
#define pb push_back
#define pcnt __builtin_popcount
#define show(x) cout<<#x<<" = "<<x<<endl;
#define maxs(x,y) x = max(x,y)
#define mins(x,y) x = min(x,y)
#define fi first
#define se second
#define rng(a) (a.begin()),(a.end())
#define each(it,c) for(__typeof((c).begin()) it=(c).begin();it!=(c).end();it++)
#define sz(x) (int)(x).size()
#define mp make_pair

using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<pii> vpii;
typedef set<int> si;
typedef pair<ll,ll> pll;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<pll> vpll;
typedef set<ll> sl;
typedef __int128_t lll;
typedef pair<lll,lll> plll;
typedef vector<lll> vlll;
template<typename T>string join(vector<T>&v)
{stringstream s;FOR(i,0,sz(v))s<<' '<<v[i];return s.str().substr(1);}
template<typename A, size_t N, typename T>void Fill(A (&array)[N], const T&v)
{fill((T*)array,(T*)(array+N),v);}
ll gcd(ll a,ll b){if(a>b)swap(a,b);for(;a>0;b%=a,swap(a,b));return b;}
int modpow(ll a,ll n,int m){if(a==0)return a;ll p=1;for(;n>0;n/=2,a=a*a%m)if(n&1)p=p*a%m;return(int)p;}
void dout(double d){printf("%.12f\n",d);}

const int iinf = 1e9;
const ll linf = 1e18;
const int mod = 1e9+7;
const double pi = acos(-1);
const double eps = 1e-10;
const int N = 401;
ll DP[N+10][N+10], n, ma, mb, a, b, c;
main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  Fill(DP, linf);
  DP[0][0] = 0;
  cin >> n >> ma >> mb;
  FOR(i, 0, n){
    cin >> a >> b >> c;
    FORR(j, N-1, 0)FORR(k, N-1, 0) mins(DP[j+a][k+b], DP[j][k] + c);
  }
  ll sma = 0, smb = 0, ans = linf;
  while(sma < N && smb < N){
    sma += ma;
    smb += mb;
    mins(ans, DP[sma][smb]);
  }
  cout << (ans < linf ? ans : -1) << endl;
  return 0;
}


Measured memory_bytes: 1536
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);

		int H = sc.nextInt();
		int W = sc.nextInt();

		while (!(H == 0 && W == 0)) {
			for (int i = 0; i < H; i++) {
				for (int j = 0; j < W; j++) {
					System.out.print("#");
				}
				System.out.println();
			}
			System.out.println();

			H = sc.nextInt();
			W = sc.nextInt();
		}
	}
}



Measured memory_bytes: 32596
#include <bits/stdc++.h>
using namespace std;
#define nl '\n'
typedef long long ll;
ll a, b, c;
int main(){
	cin.tie(0);
	cin.sync_with_stdio(0);
	cin >> a >> b >> c;
	if(c-a-b>=0&&(c-a-b)*(c-a-b)>4*a*b){
		cout << "Yes" << nl;
	}else{
		cout << "No" << nl;
	}
	return 0;
}

Measured memory_bytes: 256
// Problem : H - Grid 1
// Contest : AtCoder - Educational DP Contest
// URL : https://atcoder.jp/contests/dp/tasks/dp_h
// Memory Limit : 1024 MB
// Time Limit : 2000 ms
// Powered by CP Editor (https://github.com/cpeditor/cp-editor)

#include <bits/stdc++.h>
using namespace std;
#define SPEED ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define ll long long
#define endl '\n'
#define vi vector<ll>
#define vb vector<bool>
#define mii map<ll, ll>
#define pii pair<ll, ll>
#define pb push_back
#define fi first
#define se second
#define m_p make_pair
#define vpii vector<pii>
#define vvi vector<vi>
#define vs vector<string>
#define all(x) x.begin(), x.end()
#define mod 1000000007
//Proof: 
//Complexity:
void print(vi v){
	ll n = v.size();
	for(ll i = 0;i<n;i++){
		cout<<v[i]<<" ";
	}
        cout<<endl;
}
ll power(ll a, ll b){
    ll res = 1;
    while(b!=0){
        if(b&1){
            res *= a; 
        }
        a = (a * a);
        b = (b / 2);
    }
    return res;
}
int main(){
    SPEED;
    ll h, w;
    cin>>h>>w;
    vector<vector<char>> v(h + 1, vector<char>(w + 1));
    for(ll i = 1;i<=h;i++){
    	for(ll j = 1;j<=w;j++)cin>>v[i][j];
    }
    vvi dp(h + 1, vi(w + 1, 0));
    dp[1][1] = 1;
    for(ll i = 1;i<=h;i++){
    	for(ll j = 1;j<=w;j++){
    		if(i == 1 && j == 1)continue;
    		if(v[i][j]=='#')continue;
    		dp[i][j] = (dp[i][j-1]%mod + dp[i-1][j]%mod)%mod;
    	}
    }
    // for(ll i = 0;i<=h;i++){
    	// for(ll j = 0;j<=w;j++)cout<<dp[i][j]<<" ";
    	// cout<<endl;
    // }
    cout<<dp[h][w];
    return 0;
}

Measured memory_bytes: 9088
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using ll = long long;
using P = pair<string,int>;

int main() {
int n;
cin >> n;
vector<int> a(n);
rep(i,n) cin >> a.at(i);

sort(a.begin(),a.end());
int ans = a.at(n/2) - a.at(n/2-1);
cout << ans << endl;
}


Measured memory_bytes: 3752
#include <bits/stdc++.h>
using namespace std;
#define endl '\n'
#define ini(a,i) memset(a,i,sizeof(a))
#define pb push_back
#define ll int64_t
#define inf LLONG_MAX

void solve()
{
	ll n,i,ans,l,r;
	cin>>n;
	ll arr[n+1];
	for(i=0;i<n;i++)	{cin>>arr[i];}

	sort(arr,arr+n,greater<ll>());

	ans=arr[0];
	vector<ll> v;

	for(i=1;i<n;i++)	
	{
		v.pb(arr[i]);
		v.pb(arr[i]);
	}

	for(i=0;i<n-2;i++)	
	{
		ans+=v[i];
	}
	
	
	cout<<ans<<endl;
}


signed main()
{
	std::ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
	//ll tt;	cin>>tt;	while(tt--)
	{
		solve();
 	}
	cerr<<" Execution : "<<(1.0*clock())/CLOCKS_PER_SEC<<"s \n";
		
		
return 0;
}

Measured memory_bytes: 8988
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <iostream>
#include <algorithm>
using namespace std;

int main()
{
	int n;
	int a[100005];
	int ok=0;
	scanf("%d",&n);
	int sum1=0,sum2=0,sum4=0;
	for(int i=0;i<n;i++)
	{
		scanf("%d",&a[i]);	
	}
	for(int i=0;i<n;i++)
	{
		if(a[i]%4==0)
		{
			sum4++;
		}
		if(a[i]%2==0&&a[i]%4!=0)
		{
			sum2++;
		}
		if(a[i]%2!=0&&a[i]%4!=0)
		{
			sum1++;
		}
	}
	if(sum4==n)
	{
		ok=1;
	}
	if(sum1+1<=sum4)
	{
		ok=1;
	}
	if(sum2!=0)
	{
		sum1++;
	}
	if(sum4>=sum1-1)
	{
		ok=1;
	}
	if(ok==1)
	{
		printf("Yes\n");
	}
	else
	{
		printf("No\n");
	}
	return 0;
}

Measured memory_bytes: 640
#include<bits/stdc++.h>
using namespace std;
#define mod 1000000007
typedef long long LL;
const int maxn=200010,maxm=4040;
LL fac[maxn],ifac[maxn],inv[maxn];
LL dp[maxm+10][maxm+10];
LL c(int n,int m){
	if(n>m)return 0;
	return fac[m]*ifac[n]%mod*ifac[m-n]%mod;
}
int n,a[maxn],b[maxn];
int main(){
	scanf("%d",&n);
	for(int i=1;i<=n;++i)scanf("%d%d",&a[i],&b[i]);
	fac[0]=1;fac[1]=1;inv[0]=1;inv[1]=1;ifac[0]=1;ifac[1]=1;
	for(LL i=2;i<=maxn-2;++i){
		fac[i]=fac[i-1]*i%mod;
		inv[i]=(mod-mod/i)*inv[mod%i]%mod;
		ifac[i]=inv[i]*ifac[i-1]%mod;
	}
	for(int i=1;i<=n;++i){
		dp[2020-a[i]][2020-b[i]]++;
	}
	for(int i=1;i<=maxm;++i){
		for(int j=1;j<=maxm;++j){
			dp[i][j]=((dp[i][j]+dp[i-1][j])%mod+dp[i][j-1])%mod;
		}
	}
	LL ans=0;
	for(int i=1;i<=n;++i){
		ans=(ans+dp[2020+a[i]][2020+b[i]])%mod;
		ans=((ans-c(a[i]+a[i],a[i]+a[i]+b[i]+b[i]))%mod+mod)%mod;
	}
	ans=(ans*inv[2])%mod;
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 134656
import java.util.*;
import java.lang.*;
 
public class Main
{
	public static void main (String[] args) throws java.lang.Exception
	{
		Scanner sc=new Scanner(System.in);
		int a,b,c,k;
		a=sc.nextInt();b=sc.nextInt();c=sc.nextInt();k=sc.nextInt();
		if(k<=a)
		{
		 System.out.println(k);   		
		}
	  else if(k>a && k<(a+b))
		{
		 System.out.println(a);   
		}
		else{
		    System.out.println(a-(k-a-b));
		} 
	}
}
		

Measured memory_bytes: 35740
a,b,c=map(int,input().split())
if a>b:
    d=b
    e=a
    f=c
else:
    d=a
    e=b
    f=c

if e>f:
    g=d
    h=f
    i=e
else:
    g=d
    h=e
    i=f
    
if g>h:
    j=h
    k=g
    l=i
else:
    j=g
    k=h
    l=i
    
print(str(j)+" "+str(k)+" "+str(l))


Measured memory_bytes: 5596
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define rep(i, n) for (ll i = 0; i < n; ++i)
#define P pair<ll, ll>
#define Graph vector<vector<ll>>
#define fi first
#define se second
constexpr ll mod = 1000000007;
constexpr ll INF = (1ll << 60);
constexpr double pi = 3.14159265358979323846;
template <typename T>
inline bool chmax(T &a, T b) {
    if (a < b) {
        a = b;
        return 1;
    }
    return 0;
}
template <typename T>
inline bool chmin(T &a, T b) {
    if (a > b) {
        a = b;
        return 1;
    }
    return 0;
}

int main() {
    string s;
    cin >> s;
    ll two = 0;
    rep(i, s.size()) {
        if (s[i] == '2') two++;
    }

    cout << two << "\n";
    return 0;
}

Measured memory_bytes: 3628
//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
#define rep(i, n) for(int i=0; i<n; ++i)
using namespace std;
using ll = int64_t;
using vi = vector<int>;
using vvi = vector<vi>;


int main() {
    
    int n, m;
    cin >> n >> m;
    vector<pair<int, int> > p;
    rep(i, m) {
        p.push_back(make_pair(0,0));
        cin >> p[i].first >> p[i].second;
    }
    bool x=false;
    int ans;
    rep(i, 1000) {
        if(n==1){
            if(i>9) {
                break;
            }
            string S = to_string(i);
            int c=0;
            rep(j, m) {
                if(S[p[j].first-1] != p[j].second+'0'){
                    break;
                }
                ++c;
            }
            if(c==m) {
                x = true;
                ans = i;
                break;
            }
        }
        if(n==2){
            if(i>99) {
                break;
            }
            if(i<10) {
                continue;
            }
            string S = to_string(i);
            int c=0;
            rep(j, m) {
                if(S[p[j].first-1] != p[j].second+'0'){
                    break;
                }
                ++c;
            }
            if(c==m) {
                x = true;
                ans = i;
                break;
            }
        }
        if(n==3){
            if(i<100) {
                continue;
            }
            string S = to_string(i);
            int c=0;
            rep(j, m) {
                if(S[p[j].first-1] != p[j].second+'0'){
                    break;
                }
                ++c;
            }
            if(c==m) {
                x = true;
                ans = i;
                break;
            }
        }
    }
    if(x) {
        cout << ans << '\n';
    } else {
        cout << -1 << '\n';
    }
}

Measured memory_bytes: 256
#include<stdio.h>

int main(void){
	int H,W,i,j;
	while(1){
	scanf("%d %d",&H,&W);
		if((H==0)&&(W==0)){
			break;
		}
	for(i=1;i<=H;i++){
		for(j=1;j<=W;j++){
			printf("#");
		}
		printf("\n");
		
		
	}
		printf("\n");
	}
	return 0;
	
}

Measured memory_bytes: 572
#include <iostream>
#include <sstream>
#include <vector>
#include <string>
#include <cstring>
#include <algorithm>
#include <queue>
#include <map>
#include <set>

#define REP(i,k,n) for(int i=k;i<n;i++)
#define rep(i,n) for(int i=0;i<n;i++)
#define each(it,v) for(__typeof((v).begin()) it=(v).begin();it!=(v).end();it++)
#define INF 1<<30
#define mp make_pair

using namespace std;
typedef long long ll;
typedef pair<int,int> P;

int main() {
	string s;
	cin >> s;

	int k;
	cin >> k;

	rep(i, s.size()) {
		if(s[i] == 'a') continue;
		int dist = 26 - int(s[i] - 'a');

		if(k >= dist) {
			k -= dist;
			s[i] = 'a';
		}
	}

	if(k > 0) {
		k %= 26;
		rep(i, k) {
			char c = s[s.size()-1];
			if(c == 'z') c = 'a';
			else {
				c++;
			}

			s[s.size()-1] = c;
		}
	}

	cout << s << endl;

	return 0;
}


Measured memory_bytes: 640
n,m=map(int,input().split())
c=set(list(range(1,m+1)))#from 1 to m+1 set {}
#print(c)
for i in range(n):
    l=list(map(int,input().split()))
    a=l[1:]
    #l[0] no mean
    c=c & set(a) # and > & 
    #print(c)
print(len(c))

Measured memory_bytes: 3060
#include <iostream>
#include <algorithm>
using namespace std;

int main(void)
{
    int N;
    int a[110];
    int num = 0, cnt = 0;

    cin >> N;
    for(int i = 0; i < N; i++)
        cin >> a[i];
    
    sort(a, a + N);
    for(int i = 0; i < N; i++)
    {
        if(num != a[i])
        {
            cnt++;
        }
        num = a[i];
    }
    cout << cnt <<endl;

    return 0;
}

Measured memory_bytes: 256
import math

S = input().strip()
N = len(S)
A = [0] * N

i = 0
while i < N:
  points = [i, 0, 0, 0]
  right = True
  for j in range(points[0], N):
    c = S[j]
    if right and c == 'L':
      right = False
      points[1] = j - 1
      points[2] = j
    elif not right and c == 'R':
      points[3] = j - 1
      break
  else:
    points[3] = N - 1

  #print(points)
  nl = points[1] - points[0] + 1
  nr = points[3] - points[2] + 1
  #print(nl, nr)

  A[points[1]] += math.ceil(nl / 2)
  A[points[2]] += math.floor(nl / 2)
  A[points[1]] += math.floor(nr / 2)
  A[points[2]] += math.ceil(nr / 2)

  i = points[3] + 1

print(' '.join(map(str, A)))

Measured memory_bytes: 10484
using System;

namespace ConsoleApplication3
{
    class Program
    {
        static void Main(string[] args)
        {
            double a, b;
            string[] input = Console.ReadLine().Split(' ');
            a = double.Parse(input[0]);
            b = double.Parse(input[1]);
            double c = a / b;
            Console.WriteLine(((int)a / (int)b) + " " + (a % b) + " " + c.ToString("F20"));
        }
    }
}

Measured memory_bytes: 9268
#include <bits/stdc++.h>
#define ll long long int
#define MOD1        1000000007
#define MOD2        998244353
#define BOOST       ios_base::sync_with_stdio(false); cin.tie(NULL)

using namespace std;

ll n, x, y;
vector<ll> adj[2005];
ll dist[2005][2005];

void BFS(ll s)
{
    queue<ll> q;
    vector<ll> used(2005, 0);
    q.push(s);
    used[s] = true;
    while (!q.empty())
    {
        int v = q.front();
        q.pop();
        for (int u : adj[v])
        {
            if (!used[u])
            {
                used[u] = true;
                q.push(u);
                dist[s][u] = dist[s][v] + 1;
            }
        }
    }
}

void solve()
{
    cin >> n >> x >> y;
    x--; y--;
    for(int i = 0; i < n-1; i++)
    {
        adj[i+1].push_back(i);
        adj[i].push_back(i+1);
    }
    adj[x].push_back(y);
    adj[y].push_back(x);

    for(int i = 0; i < n; i++)
        BFS(i);

    vector<ll> ans(n);
    for(int x = 0; x < n; x++)
    {
        for(int y = 0; y < n; y++)
            ans[dist[x][y]]++;   
    }

    for(int i = 1; i < n; i++)
        cout << ans[i]/2 << "\n";
}   


int main()
{
	// #ifndef ONLINE_JUDGE
 //    freopen("input.txt", "r", stdin);
 //    freopen("output.txt", "w", stdout);
	// #endif

    ll t = 1;
    //cin >> t;
    while(t--)
        solve();

    return 0;
}

Measured memory_bytes: 31744
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner cin = new Scanner(System.in);
        int h = cin.nextInt();
        int w = cin.nextInt();
        cin.nextLine();
        char [][] lines = new char[h][];
        for (int i = 0; i < h; i++) {
            lines[i] = cin.nextLine().toCharArray();
        }
        for (int j = 0; j < h; j++) {
            for (int i = 0; i < w; i++) {
                if (lines[j][i] == '#') {
                    if (i < w - 1 && lines[j][i + 1] == '#') {
                        do {
                            i++;
                        } while (i < w - 1 && lines[j][i + 1] == '#');
                    } else {
                        if ((j == 0 || lines[j-1][i] == '.') && (j == h-1 || lines[j+1][i] == '.')) {
                            System.out.println("No");
                            return;
                        }
                    }
                }
            }
        }
        System.out.println("Yes");

    }
}


Measured memory_bytes: 23252
n = int(input())
numlist = list(map(int,input().split()))
numcount = [0]*10**6

numset = set()
for num in numlist:
    numcount[num] += 1
    numset.add(num)
n = int(input())
anslist = []
result = 0
for num in list(numset):
    result += numcount[num]*num
    
for i in range(n):
    b,c = map(int,input().split())
    numcount[c] += numcount[b]
    result += (c-b)*numcount[b]
    anslist.append(result)

    numcount[b] = 0
    numset.add(c)
    numset.discard(b)

for ans in anslist:
    print(ans)


Measured memory_bytes: 32472
#include<iostream>
#include<cmath>
#include<string.h>
#include<stdio.h>
#include<algorithm>
using namespace std;

int n;
long long a[1011];
long long ans1,ans2;
bool u[1011];

int ans[1011];
int len;
long long ans0;
int main()
{
    int i,j;
    cin>>n;
    for(i=1;i<=n;i++)
    {
        cin>>a[i];
    }
    
    ans1=ans2=0;
    for(i=1;i<=n;i+=2)
    {
        ans1+=max(0ll,a[i]);
    }
    for(i=2;i<=n;i+=2)
    {
        ans2+=max(0ll,a[i]);
    }
    
    memset(u,0,sizeof(u));
    
    if(ans1==0 && ans2==0)
    {
        long long mm=1;
        for(i=2;i<=n;i++)
        {
            if(a[i]>a[mm])
            {
                mm=i;
            }
        }
        u[mm]=1;
        ans0=a[mm];
    }
    else if(ans1>ans2)
    {
        for(i=1;i<=n;i+=2)
        {
            if(a[i]>0)
            {
                u[i]=1;
            }
        }
        ans0=ans1;
    }
    else
    {
        for(i=2;i<=n;i+=2)
        {
            if(a[i]>0)
            {
                u[i]=1;
            }
        }
        ans0=ans2;
    }
    
    int b=0;
    int r=0;
    len=0;
    
    int ss=-1;
    int tt=0;
    /*
    for(i=1;i<=n;i++)
    {
         cout<<u[i]<<' ';
    }
    cout<<"UUU"<<endl;
    */
    for(i=1;i<=n;i++)
    {
        if(u[i]==0)
        {
            r++;
            if(r>=3)
            {
                len++;
                ans[len]=i-1-b;
                b+=2;
                r-=2;
            }
        }
        else
        {
            if(ss==-1)
            {
                ss=r;
            }
            r=0;
        }
    }
    tt=r;
    if(ss==-1)
    {
        ss=0;
    }
    for(i=1;i<=ss;i++)
    {
        len++;
        b++;
        ans[len]=1;
    }
    
    for(i=1;i<=tt;i++)
    {
        len++;
        ans[len]=n-b;
        b++;
    }
    
    while(n-b>=2)
    {
        len++;
        b+=2;
        ans[len]=2;
    }
    
    
    cout<<ans0<<endl<<len<<endl;
    for(i=1;i<=len;i++)
    {
        cout<<ans[i]<<endl;
    }
    
    return 0;
}


Measured memory_bytes: 256
H, W = list(map(int, input().split()))
rows = []
for i in range(H):
    rows.append(input())

output_rows = [['#' for _ in range(W)] for __ in range(H)]

for i in range(H):
    for j in range(W):
        if rows[i][j] == '#':
            continue
        else:
            total = 0
            for dy in range(-1, 1 + 1):
                for dx in range(-1, 1 + 1):

                    y, x = i + dy, j + dx
                    if x < 0 or x > W - 1 or y < 0 or y > H - 1:
                        continue
                    else:
                        if rows[y][x] == '#':
                            total += 1
            output_rows[i][j] = str(total)

for i in range(H):
    print("".join(output_rows[i]))

Measured memory_bytes: 3188
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <cstdio>
#include <cstring>
#include <cmath>
using namespace std;
using ll = long long;

int main() {
    int a, b;
    cin >> a >> b;

    cout << (a - 1) * (b - 1) << endl;

    return 0;
}

Measured memory_bytes: 256
import math
n, m = map(int, input().split())
div = 10**9 + 7

if abs(n-m)>1:
    print(0)
    exit()
elif n == m:
    ans1 = math.factorial(n)
    ans2 = math.factorial(m)
    ans = 2 * ans1 * ans2 
else:
    ans1 = math.factorial(n)
    ans2 = math.factorial(m)
    ans = ans2*ans1

print(ans % div)

Measured memory_bytes: 11112
#include <iostream>
#include <algorithm>
#include <vector>
using namespace std;
#define rep(i, j, n) for(int i = j; i < (int)n; ++i)
#define rrep(i, j, n) for(int i = (int)n - 1; j <= i; --i)

int main() {
    int n; string s; cin >> n >> s;
    vector<int> l(n + 1), r(n + 1);
    rep(i, 0, n - 1) l[i + 1] = l[i] + (s[i] == 'W');
    rrep(i, 1, n) r[i - 1] = r[i] + (s[i] == 'E');
    int ans = 1 << 30;
    rep(i, 0, n) ans = min(ans, l[i] + r[i]);
    cout << ans << endl;
}

Measured memory_bytes: 6084
N = int(input())
s = input()
t = input()
check = 0
if s == t:
    print(N)
else:
    for i in range(1, N):
        if s[i:] == t[:-i]:
            print(N + (N-len(t[:-i])))
            break
    else:
        print(2*N)

Measured memory_bytes: 3060
using System;
using System.Collections.Generic;
using System.Linq;

namespace debug
{
    public static partial class Program
    {
        public static void Main()
        {
            var n = Console.ReadLine().ToLong();
            var ais = Console.ReadLine().ToLongArray();
            var bis = Console.ReadLine().ToLongArray();

            long cnt = 0;
            for (int i = 0; i < n; i++)
            {
                var m = Math.Min(ais[i], bis[i]);
                cnt += m;
                bis[i] -= m;
                var na = Math.Min(ais[i + 1], bis[i]);
                cnt += na;
                ais[i + 1] -= na;
            }

            Console.WriteLine(cnt);
        }
    }

    public static partial class Program
    {
        //テンプレここから
        private static long GCD(long aaa, long bbb) => bbb == 0 ? aaa : GCD(bbb, aaa % bbb);
        private static long LCM(long aaa, long bbb) => aaa * bbb / GCD(aaa, bbb);
        private static long ToLong(this double ddd) => (long) ddd;
        private static long ToLong(this string str) => long.Parse(str);
        private static long[] ToLong(this IEnumerable<string> strs) => strs.Select(x => x.ToLong()).ToArray();
        private static long[] ToLongArray(this string str, char opr = ' ') => str.Split(opr).ToLong();
        private static long Diff(long aaa, long bbb) => Math.Abs(Math.Max(aaa, bbb) - Math.Min(aaa, bbb));
        private static long Sign(this long iii) => Math.Sign(iii);
        private static bool IsEven(this long iii) => iii % 2 == 0;
        private static readonly int[] Dx = {0, -1, 0, 1};
        private static readonly int[] Dy = {-1, 0, 1, 0};
        public const int MOD = 1000000007;
        public const string ALPHABET = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
        public const string alphabet = "abcdefghijklmnopqrstuvwxyz";
        public static long ToLong(this char ccc) => ccc.ToString().ToLong();
        public static string Join(this IEnumerable<string> array, string sep = "") => string.Join(sep, array);
        public static string Join(this IEnumerable<char> array, string sep = "") => string.Join(sep, array);

        public static string JoinToStr(this IEnumerable<long> array, string sep = "")
            => array.Select(xxx => xxx.ToString()).Join(sep);

        public static string JoinToStr(this IEnumerable<int> array, string sep = "")
            => array.Select(xxx => xxx.ToString()).Join(sep);

        //テンプレここまで
    }
}

Measured memory_bytes: 36676
import java.util.HashMap;
import java.util.Scanner;

class Main{
	static Scanner s=new Scanner(System.in);
	static int gInt(){return Integer.parseInt(s.next());}

	public static void main(String[]$){
		HashMap<Integer,Integer>m=new HashMap<>();
		int n=gInt();
		for(int i=0;i<n;++i)
			m.merge(gInt(),1,Integer::sum);
		System.out.println(
				m.entrySet().stream()
				.mapToInt(o->o.getValue()>=o.getKey()?o.getValue()-o.getKey():o.getValue())
				.sum()
				);
	}
}

Measured memory_bytes: 49736
#include<bits/stdc++.h>
#include<cstring>
#include<cmath>
#include<iterator>
#include<cstdlib>
#define IOS   ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define ses   "\n"
#define whp   " "
#define mxi 99999

#define rep0(i,a,b) for(int i=a; i<b; i++)
#define rep1(i,a,b) for(int i=a; i<=b; i++)
#define rep0in(i,a,b) for(int i=a-1; i>=b; i--)
#define rep1in(i,a,b) for(int i=a; i>b; i--)
#define repv(i,a) for(auto i=a.begin(); i!=a.end();++i)

///set <int, greater <int> > ::iterator it;
///vector<pair<int,int> >a;
#define MS(a,b) memset(a,b,sizeof(a));

typedef long long ll;
typedef unsigned long long ull;
using namespace std;
ll fx[4]= {1,-1,0,0};
ll fy[4]= {0,0,1,-1};
int smallest(int x, int y, int z)
{
    int c = 0;
    while (x && y && z) {
        x--;
        y--;
        z--;
        c++;
    }
    return c;
}
bool rs(ll a, ll b){
    return(a>b);

    }
int main()
{
    ll n,k;
    cin>>n>>k;
    ll a[n];
    for(ll i=0; i<n; i++){
        cin>>a[i];
    }
    sort(a,a+n);
    ll s=0;
    for(ll i=0; i<k; i++){
        s=s+a[i];
    }
    cout<<s<<endl;
return 0;
}


Measured memory_bytes: 3660
#include <iostream>

using namespace std;

int main() {
    int A, B;
    string S;
    cin >> A >> B >> S;

    if (S[A] != '-') {
        cout << "No" << endl;
        return 0;
    }

    for (int i = 0; i < A + B + 1; ++i) {
        if (i != A && (0 > S[i] - '0' || S[i] - '0' > 9)) {
            cout << "No" << endl;
            return 0;
        }
    }

    cout << "Yes" << endl;
}

Measured memory_bytes: 256
#include<stdio.h>
int main()
{
    int x1,y1,x2,y2,x3,y3,x4,y4,d1,d2;
    scanf("%d %d %d %d",&x1,&y1,&x2,&y2);
    d1=y2-y1;
    d2=x2-x1;
    x3=x2-d1;
    x4=x1-d1;
    y3=y2+d2;
    y4=y1+d2;
    printf("%d %d %d %d\n",x3,y3,x4,y4);
    return 0;
}



Measured memory_bytes: 128
#include <stdio.h>
 
 
 
int main() {
	int H, W;
	int i, j;
    int p, q;
	int ans=0;
	char c;
	int a[1000][100];
    int b[1000][100];
	scanf("%d %d", &H, &W);
	getchar();
	for (i = 0; i < H; i++) {
		for (j = 0; j < W; j++) {
			scanf("%c", &c);
			if (c == '#')a[i][j] = 1;
			else a[i][j] = 0;
		}
		getchar();
	}
    b[0][0]=a[0][0];
	for (i = 1; i < H; i++) {
		b[i][0] = b[i - 1][0] + (a[i][0]==1 && a[i-1][0]==0);
	}
	for (j = 1; j < W; j++) {
		b[0][j] = b[0][j - 1] + (a[0][j]==1 && a[0][j-1]==0);
	}
	for (i = 1; i < H; i++) {
		for (j = 1; j < W; j++) {
            p = b[i - 1][j] + (a[i][j]==1 && a[i-1][j]==0);
            q = b[i][j - 1] + (a[i][j]==1 && a[i][j-1]==0);
			if ( p < q )b[i][j]=p;
			else b[i][j]=q;
		}
	}
	
	printf("%d", b[H-1][W-1]);
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using lint = long long;
using P = pair<int, int>;
using vec = vector<int>;
using mat = vector<vector<int>>;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(v) v.begin(), v.end()
#define endl "\n"

constexpr int MOD = 1000000007;
const int INF = 1 << 30;

int main() {
    int n, k;
    cin >> n >> k;
    vec a(n);
    rep(i, n) cin >> a[i];

    map<int, int> mp;
    rep(i, n) mp[a[i]]++;

    vector<P> type;
    for (auto&& p : mp) {
        int k = p.first, v = p.second;
        type.push_back({v, k});
    }

    sort(all(type));

    if (type.size() <= k) {
        cout << 0 << endl;
        exit(0);
    }
    
    lint res = 0;

    rep(i, type.size() - k) {
        res += type[i].first;
    }

    cout << res << endl;
    return 0;
}

Measured memory_bytes: 12536
<?php
    $line_first = explode(' ',trim(fgets(STDIN)));
    $hp = intval($line_first[0]);
    $line_second = array_map('intval', explode(' ',trim(fgets(STDIN))));
    rsort($line_second);
    
    foreach ($line_second as $value) {
        $hp -= $value;
    }
    
    if (0 < $hp) {
        echo 'No';
    } else {
        echo 'Yes';
    }
?>


Measured memory_bytes: 35284
#include<stdio.h>
 
const int MAX_V = 1000000;
int data[999999], sum[1000000];
 
int main() {
  int i, k, n;
  for(i = 2; i < MAX_V; i++) {
    data[i] = 1;   
  }
  for(i = 2; i * i < MAX_V; i++) {
    if(data[i] == 1) {
      for(k = 2 * i; k < MAX_V; k += i) {
        data[k] = 0;
      }
    }
  }
  for(i = 2; i < MAX_V; i ++) {
    sum[i + 1] = sum[i] + data[i];
  }
  while(scanf("%d", &n) != EOF) {
    printf("%d\n", sum[n + 1]);
  }
  return 0;
}

Measured memory_bytes: 8408
#include <bits/stdc++.h>	
using namespace std;

int main()
{
	int N;
	cin >> N;
	vector<int> A( N );
	for( int i = 0; i < N; i++ ) {
		cin >> A[i];
	}

	long long ans = 0;
	long long sum = 0;
	for( int i = 0; i < N; i++ ) {
		if( A[i] == 0 ) {
			ans += sum / 2;
			sum = 0;
		}
		else sum += A[i];
	}
	ans += sum / 2;

	cout << ans << endl;
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define RFOR(i,a,b) for(int i=(b) - 1;i>=(a);i--)
#define REP(i,n) for(int i=0;i<(n);i++)
#define RREP(i,n) for(int i=n-1;i>=0;i--)

#define PB push_back
#define INF INT_MAX/3
#define ALL(a) (a).begin(),(a).end()
#define RALL(a) (a).rbegin(),(a).rend()
#define CLR(a) memset(a,0,sizeof(a))

typedef long long int ll;

using namespace std;

int main(){
    while(true){
	string s;
	ll ans = 0;
	cin >> s;
	if(s == "0000") break;
	else if(s[0] == s[1] && s[0] == s[2] && s[0] == s[3]){
	    cout << "NA" << endl;
	    continue;
	}
	while(s.compare("6174")){
	    vector<int> a(4);
	    vector<int> b(4);
	    a[0] = (int)(s[0] - '0');
	    a[1] = (int)(s[1] - '0');
	    a[2] = (int)(s[2] - '0');
	    a[3] = (int)(s[3] - '0');
	    b[0] = (int)(s[0] - '0');
	    b[1] = (int)(s[1] - '0');
	    b[2] = (int)(s[2] - '0');
	    b[3] = (int)(s[3] - '0');
	    sort(RALL(a));
	    sort(ALL(b));
	    int an = 1000 * a[0] + 100 * a[1] + 10 * a[2] + a[3];
	    int bn = 1000 * b[0] + 100 * b[1] + 10 * b[2] + b[3];
	    int dif = an - bn;
	    if(dif / 1000 >= 1)
		s = to_string(dif);
	    else if(dif / 100 >= 1)
		s = "0" + to_string(dif);
	    else if(dif / 10 >= 1)
		s = "00" + to_string(dif);
	    else s = "000" + to_string(dif);
	    ans++;
	}
	cout << ans << endl;
    }
    return 0;
}

Measured memory_bytes: 3256
def main():
    n = int(input())
    a = list(map(int, input().split()))
    t = 1
    flag = 0
    for sa in a:
        if sa == t:
            flag = 1
            t += 1
    if flag == 0:
        return -1
    else:
        t -= 1
        return n - t


print(main())


Measured memory_bytes: 77516
#include <iostream>
#include <vector>

using namespace std;

struct UnionFind {
    vector<int> par;
    vector<int> group_num;
    UnionFind(int N) : par(N+1), group_num(N+1, 1) {
        for(int n=0; n<=N; n++) {
            par[n] = n;
        }
    }
    
    int root(int x) {
        if(x==par[x]) return x;
        return par[x]=root(par[x]);
    }
    
    void unite(int x, int y) {
        int rx=root(x);
        int ry=root(y);
        
        if(rx==ry) return;
        group_num[ry] += group_num[par[rx]];
        par[rx] = ry;
    }
    
    bool is_same_group(int x, int y) {
        int rx=root(x);
        int ry=root(y);
        return rx==ry;
    }
    
    int ret_group_num(int x) {
        return group_num[root(x)];
    }
};

int main() {
    int N, M, K;
    cin >> N >> M >> K;
    UnionFind tree(N);
    vector<int> frnd(N+1, 0);
    vector<int> bl_num(N+1, 0);
    for(int m=0; m<M; m++) {
        int a, b;
        cin >> a >> b;
        tree.unite(a, b);
        // cout << tree.ret_group_num(b) << endl;
        frnd[a]++;
        frnd[b]++;
    }
    for(int k=0; k<K; k++) {
        int c, d;
        cin >> c >> d;
        if(tree.is_same_group(c, d)) {
            bl_num[c]++;
            bl_num[d]++;
        }
    }
    
    for(int n=1; n<=N; n++) {
        cout << tree.ret_group_num(n)-1-frnd[n]-bl_num[n] << " ";
    }
    cout << endl;
    

    return 0;
    
}

Measured memory_bytes: 2816
#include <iostream>
using namespace std;

int main() {
    int m;
    cin >> m;
    while (m--) {
        int x, y, w, h;
        cin >> x >> y >> w >> h;
        int n;
        cin >> n;
        int count = 0;
        while (n--) {
            int xi, yi;
            cin >> xi >> yi;
            if (x <= xi && xi <= x + w && y <= yi && yi <= y + h) {
                count++;
            }
        }
        cout << count << endl;
    }
}

Measured memory_bytes: 0
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main {
	public static final int BIG_NUM = 2000000000;
	public static final int MOD = 1000000007;

	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		try {
			int n = Integer.parseInt(br.readLine());
			String input_str[] = br.readLine().split("\\s+");
			int[] array = new int[n];
			for(int i=0; i < n; i++) {
				array[i] = Integer.parseInt(input_str[i]);
			}
			
			output(array);
			
			int work,loc;
			for(int i=1; i<n; i++) {
				work = array[i];
				loc = i-1;
				while(loc >= 0 && array[loc] > work) {
					array[loc+1] = array[loc];
					loc--;
				}
				array[loc+1] = work;
				
				output(array);
			}
		} catch (NumberFormatException | IOException e) {
			e.printStackTrace();
		}
	}
	private static void output(int[] array) {
		System.out.printf("%d", array[0]);
		for (int i=1; i<array.length; i++) {
			System.out.printf(" %d", array[i]);
		}
		System.out.printf("\n");
	}

}



Measured memory_bytes: 43376
#include<iostream>
#include<stdio.h>
#include<string.h>
#include<algorithm>
#include<vector>
#include<queue>
#include<map>
#include<set>
#include<iomanip>



#define REP(i,n) for (int i = 0; (i) < (n); ++ (i))

using namespace std;
char a,b;

int main(){
  cin >> a >> b;
  if(a==b) cout << "H" << endl;
  
  else cout << "D" << endl;

  
  return 0;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
template<class T> inline bool chmin(T&a, T b){if(a > b){a = b; return true;}else{return false;}}
template<class T> inline bool chmax(T&a, T b){if(a < b){a = b; return true;}else{return false;}}
#define ll long long
#define double long double
#define rep(i,n) for(int i=0;i<(n);i++)
#define REP(i,n) for(int i=1;i<=(n);i++)
#define mod (ll)(1e9+7)
#define inf (ll)(3e18+7)
#define pi (double) acos(-1.0)
#define P pair<int,int>
#define PiP pair<int,pair<int,int>>
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(),x.rend()
using namespace std;

bool check(int w, int bit){
    bool ok = true;
    vector<int> a(w);
    rep(i, w){
        if(bit & (1<<i))a[i] = 1;
        else a[i] = 0;
    }
    REP(i, w-1)if(a[i] == a[i-1] && a[i] == 1)ok = false;
    return ok;
}

int main() {
    int h, w, k;
    cin >> h >> w >> k;
    vector<vector<ll>> dp(h+1, vector<ll>(w, 0));
    dp[0][0] = 1;
    rep(i, h){
        for(int bit = 0; bit < (1<<(w-1)); bit++){
            if(!check(w-1, bit))continue;
            vector<int> to(w);
            rep(j, w)to[j] = j;
            rep(j, w-1){
                if(bit & (1<<j)){
                    to[j] = j+1;
                    to[j+1] = j;
                }
            }
            rep(j, w){
                dp[i+1][to[j]] += dp[i][j];
                dp[i+1][to[j]] %= mod;
            }
        }
    }
    cout << dp[h][k-1] << endl;
}

Measured memory_bytes: 3636
n = gets.to_i
until n == 0
    count = 0
    arry = []
    n.times do
        x = gets.to_i
        arry << x
    end
    arrytimes = arry.length
    (arrytimes-1).times do
        for i in 0..(arry.length-2) do
            if arry[i] > arry[i+1]
                k = arry[i]
                arry[i] = arry[i+1]
                arry[i+1] = k
                count += 1
            end 
        end
        arry.pop
    end
    puts count
    n = gets.to_i
end


Measured memory_bytes: 6840
using System;
using System.Collections.Generic;
using System.Linq;
using System.IO;
using System.Text;
using static System.Math;
using static System.Array;
namespace AtCoderSolve
{
    class Solve
    {
        const int mod = 1000000007;
        const int INF = 2147483647;
        const long SINF = 9223372036854775807;

        static int N;
        //static long X;
        static int[] H;
        //static string S, T; 

        public static void Input()
        {
            var cin = new Scanner();
           
            N = int.Parse(Console.ReadLine());
            H = cin.SplitReader();
        }

        static void Main(string[] args)
        {
            Input();
            //var sw = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false };
            //Console.SetOut(sw);

            int l = 0;
            int cur = H[0];
            List<int> len = new List<int>();
                
            for(var i = 0; i < N; i++)
            {
                if (i == N - 1) { len.Add(l);
                    continue;
                }
                else
                {
                    if (H[i + 1] <= cur) { l++;
                       
                    }
                    else
                    {
                        len.Add(l);
                        l = 0;
                    }

                    cur = H[i + 1];
                }

            }

            Console.WriteLine(len.Max());

            //Console.Out.Flush();
        }

    }

    public class Scanner
    {
        public int[] SplitReader()
        {
            int[] array = Console.ReadLine().Split().Select(int.Parse).ToArray();
            return array;
        }
        public long[] SplitReaderL()
        {
            long[] array = Console.ReadLine().Split().Select(long.Parse).ToArray();
            return array;
        }

        public int[] MultiLineReader(int N)
        {
            int[] ret = new int[N];
            for(var i = 0; i < N; i++)
            {
                ret[i] = int.Parse(Console.ReadLine());
            }

            return ret;
        }
        public long[] MultiLineReaderL(int N)
        {
            long[] ret = new long[N];
            for (var i = 0; i < N; i++)
            {
                ret[i] = long.Parse(Console.ReadLine());
            }

            return ret;
        }

    }

    public class Graph
    {
        
    }
}

    



Measured memory_bytes: 26204
#include <bits/stdc++.h>
using namespace std;

int main(){

    int N, K, x;
    cin >> N >> K;

    int pointA = 0;
    int pointB = K;
    vector<int> answer(N);

    vector<int> xList(N);

    for(int i=0; i<N; i++) {
        x = 0;
        cin >> x;
        xList[i] = x;
    }

    for(int i=0; i<N; i++) {
        if((xList[i] - pointA) < (pointB - xList[i])) {
            answer[i] = abs(2 * (xList[i] - pointA));
        } else {
            answer[i] = abs(2 * (xList[i] - pointB));
        }
        // cout << "answer[i] is " << answer[i] << endl;
    }

    int final = 0;
    for(int i=0; i<answer.size(); i++) {
        final = final + answer[i];
    }
    cout << final << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <string>
#include <cmath>
#include <set>
#include <algorithm>
#include <array>
#include <complex>
#include <utility>
#include <map>
int needleX[4] = { -1,0,1,0 };
int needleY[4] = { 0,1,0,-1 };

bool isprime(int m){
    if(m==1) return false;
    for(int i=2;i<m;i++){
        if(m%i==0){
            return false;
        }
    }
    return true;
}
int main(void) {
    int n;
    std::cin >> n;
    int count=0;
    
    for(int i=11;i<55555;i+=10){
        if(isprime(i)==true){
            if(i!=11) std::cout << " ";
            std::cout << i;
            count++;
        }
        if(count==n){
            std::cout << std::endl;
            return 0;
        }
    }
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;

#define mp make_pair
#define pb push_back
#define ll long long int
#define sd(x) scanf("%lld",&x)
#define inf 1000000000000000000
#define pll pair<ll,ll>
#define fastio ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define bits(x) __builtin_popcountll(x)
#define ld long double
#define test() ll test; cin>>test; while(test--)
#define fi first
#define se second


void __print(int x) {cerr << x;}
void __print(long x) {cerr << x;}
void __print(long long x) {cerr << x;}
void __print(unsigned x) {cerr << x;}
void __print(unsigned long x) {cerr << x;}
void __print(unsigned long long x) {cerr << x;}
void __print(float x) {cerr << x;}
void __print(double x) {cerr << x;}
void __print(long double x) {cerr << x;}
void __print(char x) {cerr << '\'' << x << '\'';}
void __print(const char *x) {cerr << '\"' << x << '\"';}
void __print(const string &x) {cerr << '\"' << x << '\"';}
void __print(bool x) {cerr << (x ? "true" : "false");}

template<typename T, typename V>
void __print(const pair<T, V> &x) {cerr << '{'; __print(x.first); cerr << ','; __print(x.second); cerr << '}';}
template<typename T>
void __print(const T &x) {int f = 0; cerr << '{'; for (auto &i: x) cerr << (f++ ? "," : ""), __print(i); cerr << "}";}
void _print() {cerr << "]\n";}
template <typename T, typename... V>
void _print(T t, V... v) {__print(t); if (sizeof...(v)) cerr << ", "; _print(v...);}
#ifndef ONLINE_JUDGE
#define debug(x...) cerr << "[" << #x << "] = ["; _print(x)
#else
#define debug(x...)
#endif


inline ll GCD(ll x, ll y) {
    if(x<y) swap(x,y);
    if(x==0) return y;
    if(y==0) return x;
    return GCD(x%y,y);
}

ll phi(ll n) {
    ll result = n;
    for (ll i = 2; i * i <= n; i++) {
        if(n % i == 0) {
            while(n % i == 0)
                n /= i;
            result -= result / i;
        }
    }
    if(n > 1)
        result -= result / n;
    return result;
}

ll power(ll x, ll n, ll mod) {
    ll res = 1;
    x %= mod;
    while(n) {
        if(n&1) {
            res = ((res*x)%mod+mod)%mod;
        }
        x = ((x*x)%mod+mod)%mod;
        n>>=1;
    }

    return res;
}

int main() {
    fastio;
    string s;
    cin>>s;

    char x = s.back();

    if(x=='s') {
        s += "es";
        cout<<s<<endl;
    } else {
        s += "s";
        cout<<s<<endl;
    }
    
}




Measured memory_bytes: 3668
#include<bits/stdc++.h>
#define int int64_t
using namespace std;

int dp[20005][100][2] , D , M = 1e9+7;
string num; 

int solve(int pos , int rem , int flag , int n) {
    if(pos == n) {
        if(rem == 0) return 1;
        else return 0;
    }
    else if(dp[pos][rem][flag] != -1) return dp[pos][rem][flag];
    int lmt , res = 0;
    if(!flag) lmt = 9;
    else lmt = num[pos]-'0'; 
    for(int i = 0; i <= lmt; i++) {
        if(i < num[pos]-'0') res = (res + solve(pos+1 , (rem+i)%D , 0 , n))%M;
        else res = (res + solve(pos+1 , (rem + i)%D , flag, n))%M;
    }
    dp[pos][rem][flag] = res;
    return dp[pos][rem][flag];
}

signed main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);

    cin >> num >> D;
    int n = num.length();
    memset(dp , -1 , sizeof(dp));
    cout << (solve(0, 0, 1, n) - 1 + M)%M << "\n";

    return 0;
}



Measured memory_bytes: 35696
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main {
	public static void main(String[] args) throws NumberFormatException, IOException {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		String[] nk = br.readLine().split(" ");
		
		int n = Integer.parseInt(nk[0]);
		int k = Integer.parseInt(nk[1]);
		
		String[] a = new String[n];

		for (int i = 0; i < n; i++) {
			a[i] = br.readLine();
		}
		
		int ans = solve(a,n,k);
		
		System.out.println(ans);
	}

	private static int solve(String[] a, int n, int k) {
		
		int[][] dp = new int[n][k];
		int mod = 1000000007;
		
		for (int i = 0; i < n; i++) {
			if(a[i].charAt(0)=='#')
				break;
			dp[i][0] = 1;
		}
		
		
		for (int i = 0; i < k; i++) {
			if(a[0].charAt(i)=='#')
				break;
			dp[0][i] = 1;
		}
		
		for (int i = 1; i < n; i++) {
			for (int j = 1; j < k; j++) {
				
				if(a[i].charAt(j)=='#')
					continue;
				
				dp[i][j] = (dp[i-1][j]+dp[i][j-1])%mod;
				
			}
		}
		
		
		
		return dp[n-1][k-1];
	}
}

Measured memory_bytes: 29700
#include <iostream>
#include<bits/stdc++.h>

using namespace std;

typedef unsigned long long int ll;

int main() {
    int N;
    cin>>N;
    ll arr[N];
    ll ans = 1;
    ll anst;
    for(int i=0;i<N;i++){
        cin>>arr[i];
    }
    sort(arr,arr+N);
    if(arr[0]==0){
        cout<<0<<endl;
        return 0;
    }
    for(int i=0;i<N;i++){
        if(__builtin_mul_overflow(ans, arr[i], &anst)){
            cout<<-1<<endl;
            return 0;
        }
        ans*=arr[i];
        anst = ans;
    }
    if(ans>1000000000000000000LL){
        cout<<-1<<endl;
    }
    else
        cout<<ans<<endl;
}

Measured memory_bytes: 4408
#include<bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(n);++i)
using namespace std;
typedef long long ll;

int main(){
  string s;cin >> s;
  if(s[0] == 'R'){
    if(s[1] == 'R'){
      if(s[2] == 'R'){
        cout << 3;
      } else {
        cout << 2;
      }
    } else {
      cout << 1;
    }
  } else {
    if(s[1] == 'R'){
      if(s[2] == 'R'){
        cout << 2;
      } else {
        cout << 1;
      }
    } else {
      if(s[2] == 'R'){
        cout << 1;
      } else {
        cout << 0;
      }
    }
  }
  return 0;
}

Measured memory_bytes: 3612
/*
    飲んだ魔剤で家が建つ。
    created at: 2020-04-07 19:48:27
*/

#include <bits/stdc++.h>
using namespace std;

#define all(x) (x).begin(),(x).end()
#define rev(x) greater<x>()
#define MOD 1000000007
#define INF 55555

typedef long long LL;
typedef long double LD;

bool compare_by_b(pair<int, int> a, pair<int, int> b)
{
    if (a.second != b.second) {
        return a.second < b.second;
    } else {
        return a.first < b.first;
    }
}

LL modpower(LL n, LL m, LL mod)
{
    if (m == 0) {
        return 1;
    } else if (m % 2 == 0) {
        LL p = modpower(n, m/2, mod);
        return p*p % mod;
    } else {
        return n*modpower(n, m-1, mod) % mod;
    }
}

LL modinv(LL n, LL mod)
{
    return modpower(n, mod-2, mod);
}

LL modcombination(LL n, LL r, LL mod)
{
    LL ret = 1;

    for (int i = 0; i < r; i++) {
        ret *= (n-i);
        ret %= mod;
        ret *= modinv(i+1, mod);
        ret % mod;
    }

    return ret % mod;
}

int gcd(int k, int l)
{
    if (l > 0) return gcd(l, k%l);
    else return k;
}

struct UnionFind
{
    vector<int> par;

    UnionFind(int n) : par(n) {
        for (int i = 0; i < n; i++) par[i] = i;
    }

    int root(int x) {
        if (par[x] == x) return x;
        return par[x] = root(par[x]);
    }

    void unite(int x, int y) {
        int rx = root(x);
        int ry = root(y);
        if (rx == ry) return;
        par[rx] = ry;
    }

    bool same(int x, int y) {
        int rx = root(x);
        int ry = root(y);
        return rx == ry;
    }
};

int n, p_limit;
vector<int> p, a;

void find_prime()
{
    p_limit = 0;
    for (int i = 2; i < INF; i++) {
        int m = sqrt(i);
        int ok = 1;
        for (int j = 2; j <= m; j++) {
            if (i % j == 0) ok = 0;
        }

        if (ok) {
            p.push_back(i);
            p_limit++;
        }
    }
}

void solve()
{
    for (int i = 0; i < p_limit; i++)
        if (p[i] % 5 == 1) a.push_back(p[i]);

    for (int i = 0; i < n; i++) 
        cout << a[i] << " ";
    cout << endl;
}

int main()
{
    scanf("%d", &n);

    find_prime();

    solve();

    return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
int main (void)
{
int a,i,k,j,temp;
int s[10000][9]={{}};
int sec[10000]={};
int min[10000]={};
int sumsec[10000]={};
int sumsec2[10000]={};
 
while(1){
scanf("%d",&a);
if(a==0)
break;
 
for(i=0;i<a;i++)
for(k=0;k<9;k++)
scanf("%d",&s[i][k]);
 
for(i=0;i<a;i++){
sec[i]=s[i][2]+s[i][4]+s[i][6]+s[i][8];
min[i]=(s[i][1]+s[i][3]+s[i][5]+s[i][7])*60;
sumsec[i]=sec[i]+min[i];
sumsec2[i]=sumsec[i];
}
 
for(i=0;i<a-1;i++)
for(k=0;k<a-1;k++)
if(sumsec[k]>sumsec[k+1]){
temp=sumsec[k];
sumsec[k]=sumsec[k+1];
sumsec[k+1]=temp;
}
 
int num[3]={};
int p=0;
for(i=0;i<3;i++)
for(j=0;j<a;j++){
if(sumsec2[j]==sumsec[i]){
num[p]=j;
p++;
}
}

int y;
for(i=0;i<a;i++)
if(sumsec2[i]==sumsec[a-2])
y=i;
 
for(i=0;i<2;i++)
printf("%d\n",s[num[i]][0]);
printf("%d\n",s[y][0]);

}
return 0;
}

Measured memory_bytes: 1036
#include <cstdio>
#include <cstring>
#include <iostream>
#include <string>
#include <cmath>
#include <bitset>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <algorithm>
#include <complex>
#include <unordered_map>
#include <unordered_set>
#include <random>
#include <cassert>
#include <fstream>
#define popcount __builtin_popcount
using namespace std;
typedef long long int ll;
typedef pair<int, int> P;

int main()
{
    int h, w; cin>>h>>w;
    string s[1010];
    for(int i=0; i<h; i++) cin>>s[i];
    int mn1=h+w, mn2=h+w, mx1=-h-w, mx2=-h-w;
    for(int i=0; i<h; i++){
        for(int j=0; j<w; j++){
            if(s[i][j]=='B'){
                mn1=min(mn1, i+j);
                mx1=max(mx1, i+j);
                mn2=min(mn2, i-j);
                mx2=max(mx2, i-j);
            }
        }
    }
    cout<<max(mx1-mn1, mx2-mn2)<<endl;
    return 0;
}


Measured memory_bytes: 3216
n, m = map(int, input().split())
point = 0 ; penalty = 0
false = [0] * n
correct = [0] * n
for i in range(m) :
    p, s = input().split()
    p = int(p)
    if s == "WA" and correct[p-1] != 1 :
        false[p-1] += 1
    if s == "AC" :
        correct[p-1] = 1

for i in range(n) :
    if false[i] > 0 and correct[i] == 1 :
        penalty += false[i]

print(sum(correct),penalty)


Measured memory_bytes: 10344