akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define MX 1000000
#define P 998244353
using namespace std;
typedef long long lnt;
template <class T> inline void read(T &x) {
	x = 0; int c = getchar(), f = 1;
	for (; !isdigit(c); c = getchar()) if (c == 45) f = -1;
	for (; isdigit(c); c = getchar()) (x *= 10) += f*(c-'0');
}
int n, m; lnt ans;
lnt fac[MX+5], inv[MX+5];
void init() {
	fac[0] = inv[0] = inv[1] = 1;
	for (int i = 1; i <= MX; i++) fac[i] = fac[i-1]*i%P;
	for (int i = 2; i <= MX; i++) inv[i] = (P-P/i*inv[P%i]%P)%P;
	for (int i = 2; i <= MX; i++) inv[i] = inv[i-1]*inv[i]%P;
}
lnt Inv(lnt x) {
	lnt ret = 1;
	for (int k = P-2; k; k >>= 1, x = x*x%P)
		if (k&1) ret = ret*x%P;
	return ret;
}
lnt C(int n, int m) {return fac[n]*inv[m]%P*inv[n-m]%P;}
int main() {
	read(n), read(m), init();
	for (int i = 1; i <= min(n, m); i++)
		ans = (ans+C(n+m-i*2, n-i)%P*C(i*2, i)%P)%P;
	ans = (ans*Inv(2*C(n+m, n)%P)%P+max(n, m))%P;
	return printf("%lld\n", ans), 0;
}

Measured memory_bytes: 15872
#include<bits/stdc++.h>
//#include <ext/pb_ds/assoc_container.hpp>
//using namespace __gnu_pbds;
using namespace std;
 
#define ff              first
#define ss              second
#define int             long long
#define ll              long long 
#define pb              push_back
#define mp              make_pair
#define pii             pair<int,int>
#define vi              vector<int>
#define mii             map<int,int>
#define pqb             priority_queue<int>
#define pqs             priority_queue<int,vi,greater<int> >
#define setbits(x)      __builtin_popcountll(x)
#define zerobits(x)      __builtin_ctzll(x)
#define mod             998244353
#define Mod             1000000007
#define inf             1e18
#define ps(x,y)         fixed<<setprecision(y)<<x
#define mk(arr,n,type)  type *arr=new type[n];
#define w(x)            int x; cin>>x; while(x--)
#define vpii            vector<pair<int,int> >
#define all(x)          x.begin(),x.end()
#define sort(x)         sort(all(x))
#define umii            unordered_map<int,int>
#define lli             list<int>             
#define gcd(m,n)        __gcd(m,n)   
#define mib             map<int,bool>

#define TRACE
#ifdef TRACE
#define deb(...) __f(#__VA_ARGS__, __VA_ARGS__)
    template <typename Arg1>
    void __f(const char* name, Arg1&& arg1){
        cout << name << " : " << arg1 << std::endl;
    }
    template <typename Arg1, typename... Args>
    void __f(const char* names, Arg1&& arg1, Args&&... args){
        const char* comma = strchr(names + 1, ','); cout.write(names, comma - names) << " : " << arg1<<" | ";__f(comma+1, args...);
    }
#else
#define deb(...)
#endif

void fast()
{
	ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
//#ifndef ONLINE_JUDGE
//	freopen("input.txt", "r", stdin);
//	freopen("output.txt", "w", stdout);
//#endif
}
 
//////////////////////////////code//////////////////////////////

int32_t main()
{
  fast();

  int sum=0,r,m;
  cin>>r>>m;
  for(int i=0;i<m;i++) 
  {
  	int d;
  	cin>>d;
  	sum+=d;
  }
  int ans= r-sum;
 // cout<<ans;
  
  if(ans<0)
  cout<<-1;
  else
  cout<<ans;

}

Measured memory_bytes: 3624
import java.util.*;

public class Main {
	
	private static void printbit(int n) {
		for(int i=0;i<5;i++) {
			int bit=n%2;
			System.out.print(bit);
			n=n>>1;
		}
		System.out.println();
	}
	
	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ
		Scanner sc = new Scanner(System.in);
		int n=sc.nextInt(),m=sc.nextInt();
		int[] k = new int[m];
		int[][] s = new int[m][n];
		int[] p = new int[m];
		
		for(int i=0;i<m;i++) {
			k[i] = sc.nextInt();
			for(int j=0;j<k[i];j++) {
				s[i][j]=sc.nextInt();
			}
		}
		
		for(int i=0;i<m;i++) {
			p[i]=sc.nextInt();
		}
		
		int ans = 0;
		
		for(int i=0;i<Math.pow(2, n);i++) {//スイッチのパターンごと
			int temps[] = new int[n];
			int temp = i;
			for(int j=0;j<n;j++) {
				if(temp%2==1) {
					temps[j]=1;
					temp=temp>>1;
				}else {
					temps[j]=0;
					temp=temp>>1;
				}
			}
			/*
			System.out.print("temps ");
			for(int q=0;q<n;q++)System.out.print(temps[q]);
			System.out.println();
			System.out.print("    i ");
			printbit(i);
			System.out.println();
			*/
			
			int on=0;
			for(int j=0;j<m;j++) {//各電球
				int sum=0;
				for(int l=0;l<k[j];l++) {
					
					sum+=temps[s[j][l]-1];
				}
				if(sum%2==p[j]) {
					on++;
				}
			}
			if(on==m) {
				ans++;
				//printbit(i);
			}
			
		}
		
		
		
		System.out.println(ans);
		
		
	}

}


Measured memory_bytes: 23124
#include<stdio.h>
#define N 8
#define NOT_FREE 1
#define FREE 0
 
int putQueen(int);
int Board[N][N] = {};
int row[N] = {}, col[N] = {}, dpos[2*N-1] = {}, dneg[2*N-1] = {};
 
int main(){
  int k, r, c;
  int i;
 
  scanf("%d", &k);
 
  for(i = 0; i < k; i++){
    scanf("%d %d", &r, &c);
    Board[r][c] = row[r] = col[c] = dpos[r+c] = dneg[r-c+N-1] = NOT_FREE;
  }
 
  putQueen(0);
   
  return 0;
}
 
int putQueen(int i){
  int j, k, l;
  if(i == N){
    for(k = 0; k < N; k++){
      for(l = 0; l < N; l++){
    if(Board[k][l] == FREE)
      printf(".");
    else
      printf("Q");
      }
      printf("\n");
    }
    return;
  }
  if(row[i] == NOT_FREE)
    putQueen(i+1);
  else{
    for(j = 0; j < N; j++){
      if(col[j] == NOT_FREE || dpos[i+j] == NOT_FREE || dneg[i-j+N-1] == NOT_FREE)
    continue;
      col[j] = dpos[i+j] = dneg[i-j+N-1] = Board[i][j] = NOT_FREE;
      putQueen(i+1);
      col[j] = dpos[i+j] = dneg[i-j+N-1] = Board[i][j] = FREE;
    }
  }
}

Measured memory_bytes: 572
#include <iostream>
#include <vector>
#include <cmath>
#include <algorithm>
using namespace std;
int main(void){
    int X, A;
    string result = "10";
    cin >> X >> A;
    if (X < A) {
        result = "0";
    }
    cout << result << endl;
   return 0;
}

Measured memory_bytes: 256
#include <algorithm>
#include <string.h>
#include <iostream>
#include <stdio.h>
#include <string>

using namespace std;

typedef long long ll;
typedef pair<ll, ll> PLL;

const ll N = 100010;
ll n, a[3];
string s[N];
string res;

ll get(string s) {
	if (s == "AB") return 0;
	if (s == "BC") return 1;
	if (s == "AC") return 2;
}

int main() {
	cin >> n;
	ll sum = 0;
	for (ll i = 0; i < 3; i++) {
		cin >> a[i];
		sum += a[i];
	}

	for (ll i = 1; i <= n; i++) {
		cin >> s[i];
	}

	for (ll i = 1; i <= n; i++) {
		ll x = get(s[i]), y = (x + 1) % 3;
		ll p, q;

		if (a[x] >= 2) {
			p = x;
		}
		else if (a[y] >= 2) {
			p = y;
		}
		else if (a[x] == 1 && a[y] == 1) {
			if (i == n || get(s[i + 1]) == y) {
				p = x;
			}
			else {
				p = y;
			}
		}
		else if (a[x] == 1) {
			p = x;
		}
		else if (a[y] == 1) {
			p = y;
		}
		else {
			cout << "No" << endl;
			return 0;
		}

		if (p == x) {
			q = y;
		}
		else {
			q = x;
		}

		a[p]--, a[q]++;
		res += "ABC"[q];
	}

	cout << "Yes" << endl;
	for (int i = 0; i < res.size(); i++) {
		cout << res[i] << endl;
	}

	return 0;
}

Measured memory_bytes: 6856
#include <cstring>
#include <cmath>
#include <algorithm>
#include <string>
#include <map>
#include <iostream>
#include <vector>
#include <queue>
#include <unordered_map>
#include <random>
#include <stack>
#include <set>
#include <unordered_set>

#define bug(x) cout<<"zdongdebug1: "<<x<<endl;
#define bug2(x, y) cout<<"zdongdebug2: "<<x<<" "<<y<<endl;
#define bug3(x, y, z) cout<<"zdongdebug3: "<<x<<" "<<y<<" "<<z<<endl;
using namespace std;
typedef long long ll;
const int maxn = 2005;
const int mod = 1000000007;

ll c[maxn][maxn];

int main() {
#ifdef suiyuan2009
  freopen("/Users/suiyuan2009/CLionProjects/icpc/input.txt", "r", stdin);
  //freopen("/Users/suiyuan2009/CLionProjects/icpc/output.txt", "w", stdout);
#endif
  for(int i=0;i<maxn;i++)c[i][i] = c[i][0] = 1;
  for(int i=1;i<maxn;i++)
    for(int j=1;j<i;j++){
      c[i][j] = (c[i-1][j] + c[i-1][j-1])%mod;
    }
  int n;
  cin>>n;
  ll ret = 0;
  for(int i=1;i<=n;i++){
    int tt = n - i * 2;
    if(tt<i)continue;
    ret = (ret + c[tt-1][i-1])%mod;
  }
  cout<<ret<<endl;
  return 0;
}


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

int main(){
  int T, D, tA, tB, dA, dB;
  cin >> T >> D;
  cin >> tA >> tB;
  cin >> dA >> dB;
  double res = 1 << 10;
  for(int a = 0; a <= D; a += dA){
    for(int b = 0; b <= D - a; b += dB){
      if(a == 0 && b == 0){
        continue;
      }
      double tmp = ((double)(tA * a + tB * b)) / (a + b) - T;
      if(tmp < 0){
        tmp = -tmp;
      }
      if(res > tmp){
        res = tmp;
      }
    }
  }
  cout << res << endl;
  return 0;
}

Measured memory_bytes: 1236
#include<cstdio>
#include<algorithm>
#include<assert.h>
using namespace std;
#define reg register
typedef unsigned long long ll;
const int N=1010,p=1e9+7;
int T,ans1,ans2;
int inc(int x,int y){x+=y;return x>=p?x-p:x;}
struct seq{
	ll f[N];
	int cnt,ans1,ans2;
	void init(int start){
		for (cnt=start+1;f[cnt-1]+f[cnt-2]<=1e18;cnt++)
			f[cnt]=f[cnt-1]+f[cnt-2];
		cnt--;
		for (int i=cnt+1;i<N;i++) f[i]=2e18+1;
	}
	inline int rank(reg ll x){
		reg int l=1,r=cnt,mid;
		while (l<r){
			mid=(l+r)>>1;
			if (f[mid+1]<=x) l=mid+1;else r=mid;
		}
		return l;
	}
	inline void calc(reg ll x,reg ll y){
		reg int a=rank(x);
		if (y<f[a+1]){
			ans1=--a;
			ans2=((y-f[a-1])/f[a]+(x-f[a-1])/f[a])%p;
		}
		else{
			ans1=a;
			ans2=(y-f[a-1])/f[a]%p;
		}
	}
}A[N];
ll n,m,fib[N];
int times[N][N],Max[N][N],cnt[N][N];
void init_times(){
	for (int i=1;i<N;i++)
	for (int j=1;j<N;j++){
		int x=i,y=j;
		if (x<y) swap(x,y);
		times[i][j]=times[y][x%y]+1;
		Max[i][j]=max(times[i][j],max(Max[i-1][j],Max[i][j-1]));
		if (Max[i][j]==times[i][j]) cnt[i][j]++;
		if (Max[i][j]==Max[i-1][j]) cnt[i][j]+=cnt[i-1][j];
		if (Max[i][j]==Max[i][j-1]) cnt[i][j]+=cnt[i][j-1];
		if (Max[i][j]==Max[i-1][j-1]) cnt[i][j]-=cnt[i-1][j-1];
	}
}
ll read(){
	ll x=0;char ch=getchar();
	while (ch>'9'||ch<'0') ch=getchar();
	while (ch>='0'&&ch<='9') x=x*10+ch-'0',ch=getchar();
	return x;
}
void print(int x){
	if (!x) return void(putchar('0'));
	static char str[30];
	int l=0;
	for (;x;x/=10) str[++l]=x%10;
	while (l) putchar(str[l--]+'0');
}
int main()
{
	init_times();
	fib[0]=fib[1]=1;
	for (int i=2;i<=87;i++) fib[i]=fib[i-1]+fib[i-2];
	for (int i=1;i<=87;i++){
		for (int j=0;j<=i+1;j++) A[i].f[j]=fib[j];
		A[i].f[i+1]+=fib[i];
		A[i].init(i+1);
	}
	scanf("%d",&T);
	while (T--){
		n=read();m=read();
		if (n>1e18||m>1e18) assert(0);
		if (n>m) swap(n,m);
	if (n<N&&m<N){
			printf("%d %d\n",Max[n][m],cnt[n][m]);
			continue;
		}
		if (n==1){
			printf("1 %d\n",int(m%p));
			continue;
		}
		if (n==2&&m==2){
			puts("1 4");
			continue;
		}
		A[87].calc(n,m);
		ans1=A[87].ans1;
		ans2=A[87].ans2;
		for (int i=86;i;i--) A[i].calc(n,m);
		for (int i=86;i;i--)
			if (A[i].ans1==ans1&&ans1>i)
				ans2=inc(ans2,A[i].ans2);
		print(ans1);
		putchar(' ');
		print(ans2);
		putchar('\n');
	}
	return 0;
}

Measured memory_bytes: 18304
#include <iostream>
 
using namespace std;
 
int main()
{
	long long N,A,B;
	long long X[100000];
	long long fatigue=0;
	cin >> N >> A >> B;
	for(int i=0;i<N;i++)
	{
		cin >> X[i];
	}
	
	for(int i=0;i<N-1;i++)
	{
		if(A*(X[i+1]-X[i]) > B)
		{
			fatigue += B;
		}else{
			fatigue += A*(X[i+1]-X[i]);
		}
	}
	
	cout << fatigue << endl;
	return 0;
}

Measured memory_bytes: 1024
import math

N, M = list(map(int, input().split()))

keys = []

for i in range(M):
    a, b = list(map(int, input().split()))
    key_bit = 0
    c = list(map(int, input().split()))
    for j in range(b):
        key_bit |= 1 << (c[j] - 1)
    keys.append([a, key_bit])

dp = [math.inf]*(1 << N)

dp[0] = 0

for i in range(M):
    for j in range(1 << N):
        dp[j | keys[i][1]] = min(dp[j | keys[i][1]], dp[j] + keys[i][0])

if dp[-1] == math.inf:
    dp[-1] = -1

print(dp[-1])


Measured memory_bytes: 76872
#include<bits/stdc++.h>
#define ll long long 
#define ull unsigned long long 
#define ld long double
#define ui unsigned int 
using namespace std;

int main() {
	int x;
	for (int i = 1;; i++) {
		cin >> x;
		if (x == 0) { break; }
		else
			cout << "Case " << i << ":" << " " << x<<endl;
	}
}



Measured memory_bytes: 3040
#include<iostream>
using namespace std;
int main()
{
	int n;
	double a,ans=0;
	string s;
  	cin>>n;
	for(int i=0;i<n;i++)
	{
		cin>>a>>s;
		if(s[0]=='J')ans+=a;
		else ans+=a*380000;
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 256
import sys
import copy
from collections import deque
stdin = sys.stdin
 
mod = 10**9+7
 
ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
ns = lambda: stdin.readline().rstrip()  # ignore trailing spaces
 
n = ni()
a = na()
a.sort()
a_max = max(a)

c = [0 for _ in range(1000005)]
for aa in a:
    c[aa] += 1

dp = [False for _ in range(1000005)]
cnt = 0
for ai in set(a):
    if dp[ai]:
        continue
    if c[ai]==1:
        cnt += 1
    for j in range(ai+ai, a_max+1, ai):
        dp[j] = True

print(cnt)

Measured memory_bytes: 217940
#include <iostream>

using namespace std;

int main(){

    int n;
    cin >> n;

    if (n < 1200){
        cout << "ABC" << endl;
    }
    else if (n < 2800){
        cout << "ARC" << endl;
    }
    else {
        cout << "AGC" << endl;
    }

    
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <math.h>
using namespace std;
int main(void){
    int N;
    cin>>N;
    int A[200];
    int count=-1;
    for(int i=0;i<N;i++) cin>>A[i];
    bool exist_odd=true;
    while (exist_odd){
        for (int i=0;i<N;i++){
            if (A[i]%2==1){
                exist_odd=false;
                break;
            }
            A[i]/=2;
        }
        
        count+=1;
    }
    cout<<count<<endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <cassert>
typedef long long int ll;
using namespace std;

#define DEBUG 0

#if DEBUG
  #define DLOG(...) fprintf(stderr, __VA_ARGS__)
  #define DFUNC(fname, ...) fname(__VA_ARGS__)
#else
  #define DLOG(...)
  #define DFUNC(fname, ...)
#endif

ll N;
ll ba = 0;
ll bx = 0;
ll xa = 0;
ll xx = 0;
ll inner = 0;
ll outer = 0;

int main() {
#if !DEBUG
  ios_base::sync_with_stdio(false);
#endif

  cin >> N;
  for (ll i = 0; i < N; i++)  {
    string s;
    cin >> s;
    for (ll j = 0; j < (ll) s.size()-1; j++) {
      if (s.at(j) == 'A' && s.at(j+1) == 'B') inner++;
    }

    if (s.at(0) == 'B') {
      if (s.at(s.size()-1) == 'A')  ba++;
      else                   bx++;
    }else {
      if (s.at(s.size()-1) == 'A')  xa++;
      else                   xx++;
    }

  }

  if (ba >= 1) {
    outer = ba - 1;
    if (xa >= 1) {
      outer += 1;
      xa -= 1;
    }
    if (bx >= 1) {
      outer += 1;
      bx -= 1;
    }
    outer += min(xa, bx);
  }else {
    outer = min(xa, bx);
  }

  cout << inner + outer << endl;

  return 0;
}



Measured memory_bytes: 256
#include<bits/stdc++.h>
#include<sstream>

#define ll long long

using namespace std;



int main(){
    string S;
    cin >> S;
    int count = 0;
    for(int i = 0; i < S.length()/2; i++){
        if(S[i] != S[S.length() - i - 1]) count++;
    }
    cout << count << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define pb push_back
using namespace std;
double pi=3.141592653; 
vector<vector<int>>g;
int main(){
  int n,m;
  cin>>n>>m;
  g.assign(n+1,vector<int>());
  for(int i=0;i<m;i++){
      int u,v;
      cin>>u>>v;
      g[u].push_back(v);
      g[v].push_back(u);    
  }
    int dis[n+1];
    for(int i=1;i<=n;i++)   
        dis[i]=INT_MAX;

    dis[1]=0;
    queue<int>q;
    q.push(1);
    while(!q.empty()){
        int n=q.front();
        q.pop();
        for(int u:g[n]){
            if(dis[u]==INT_MAX){
                dis[u]=dis[n]+1;
                q.push(u);
                }
        }
    }
    for(int i=2;i<=n;i++)
        if(dis[i]==INT_MAX){
            cout<<"No";return 0;}

    cout<<"Yes"<<endl;
    for(int i=2;i<=n;i++)
    {
        int cur=INT_MAX,temp=0;
        for(auto u:g[i]){
            if(dis[u]<cur){
                cur=dis[u];
                temp=u;
            }
        }
        cout<<temp<<endl;
    }

return 0;
}

Measured memory_bytes: 10200
#include<bits/stdc++.h>
using namespace std;
#define INIT  ios_base :: sync_with_stdio(0); cin.tie(); cout.tie();mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
#define mp make_pair
#define pb push_back
#define ft first
#define sc second
#define ll long long
#define pii pair<int, int>




int n, m, a[15][15], c[15], x;
int sk[15];


int32_t main(){
INIT
cin>>n>>m>>x;




for(int i=1; i<=n; i++){
    cin>>c[i];
    for(int j=1; j<=m; j++){
        cin>>a[i][j];
    }
}




ll res=10e12;
for(int b=1; b<(1<<(n) ); b++ ){
    ll sum=0;
    for(int i=1; i<=m; i++){sk[i]=0;}

    for(int i=0; (1<<i)<=b; i++ ){
        if( (b&(1<<i) )>0 ){
            for(int j=1; j<=m; j++){
                sk[j]+=a[i+1][j];
            }
            sum+=c[i+1];
        }
    }

    for(int i=1; i<=m; i++){
        if( sk[i]<x ){goto Next;}
    }
    res=min(res, sum);
    Next:continue;
}

if(res>=10e12){cout<<"-1\n";}
else{
    cout<<res;
}


return 0;
}



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

int main()
{
    int n;
    cin >> n;
    vector<int> p(n);
    rep(i,n) cin >> p[i];

    int ans = 0;
    rep(i, n - 2)
    {
        int n_min, n_max;
        n_min = min(min(p[i], p[i + 1]), p[i + 2]);
        n_max = max(max(p[i], p[i + 1]), p[i + 2]);
        if (p[i + 1] != n_min and p[i + 1] != n_max)
            ans++;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define pb push_back
#define fi first
#define se second
#define mp make_pair
#define all(v) v.begin(), v.end()

using namespace std;
typedef long long LL;

int main() {
	string s;
	cin >> s;
	int l1 = s.length();
	if (l1 % 2) printf("No\n");
	else {
		bool cek = 1;
		for (int i = 0; i < l1; i += 2) {
			if (s[i] != 'h'|| s[i + 1] != 'i') cek = 0;
		}
		if (cek) printf("Yes\n");
		else printf("No\n");
	}
}

Measured memory_bytes: 256
#include<cstdio>
#include<cstring>
#include<cmath>
#include<cassert>
#include<iostream>
#include<iomanip>
#include<map>
#include<set>
#include<vector>
#include<algorithm>
#include<string>
#include<queue>
using namespace std;
#define DEBUG(x) cout<<#x<<"="<<x<<endl
#define DEBUG2(x,y) cout<<#x<<"="<<x<<","<<#y<<"="<<y<<endl
typedef long long ll;
class Solver{
public:
    static const int MAXN=60;
    int H,W;
    char grid[MAXN][MAXN];
    int xdir[4]={1,-1,0,0};
    int ydir[4]={0,0,1,-1};
    int dis[MAXN][MAXN];
    int vis[MAXN][MAXN];
    bool legal(int x,int y){
        return x>=1&&x<=H&&y>=1&&y<=W;
    }
    void bfs(){
        memset(dis,0x3f,sizeof(dis));
        memset(vis,0,sizeof(vis));
        queue<pair<int,int>>q;
        dis[1][1]=0;
        q.push({1,1});
        while(!q.empty()){
            auto p=q.front();
            q.pop();
            int x=p.first,y=p.second;
            if(vis[x][y])continue;
            vis[x][y]=true;
            for(int d=0;d<4;d++){
                int nx=x+xdir[d]
                ,ny=y+ydir[d];
                if(legal(nx,ny)==false
                ||vis[nx][ny]||grid[nx][ny]=='#')continue;
                dis[nx][ny]=min(dis[nx][ny],dis[x][y]+1);
                q.push({nx,ny});
            }
        }
    }
    void solve(){
        ios::sync_with_stdio(false);
        cin>>H>>W;
        for(int u=1;u<=H;u++){
            cin>>grid[u]+1;
        }
        bfs();
        int blk=0;
        for(int u=1;u<=H;u++){
            for(int v=1;v<=W;v++)
            if(grid[u][v]=='#')blk++;
        }
        if(dis[H][W]==0x3f3f3f3f)cout<<-1;
        else cout<<H*W-(dis[H][W]+1)-blk;
    }
};
int main()
{
    // freopen("in.txt","r",stdin);
    (new Solver())->solve();
}

Measured memory_bytes: 256
# https://atcoder.jp/contests/abc080/tasks/abc080_c
# 普通にbit全探索では？

N = int(input())
F = []
for _ in range(N):
    F.append(list(map(int, input().split())))
P = []
for _ in range(N):
    P.append(list(map(int, input().split())))

bitlen = 10


# def ret_score(n: int):
#     # 営業時間かぶり計算
#     C = []
#     for i in range(N):  # Nでiter
#         cnt = 0
#         for bit in range(bitlen):  # 桁とFを対応
#             if ((n >> bit) & 1) and F[i][bit]:  # もし1その桁で1なら
#                 cnt += 1
#         C.append(cnt)

#     # スコア計算
#     ret = 0
#     for i, c in enumerate(C):
#         ret += P[i][c]
#     return ret


# ans = -10**10
# for n in range(1, 1 << bitlen):
#     ans = max(ans, ret_score(n))
# print(ans)


# numpyでも実装してみる
import numpy as np
F = np.array(F)
P = np.array(P)

bitshifter = np.array([x for x in range(bitlen)])


def ret_score(n: int):
    bit_arr = (n >> bitshifter) & 1
    F_matched = bit_arr & F
    C = F_matched.sum(axis=1)

    # スコア計算
    ret = 0
    for i, c in enumerate(C):
        ret += P[i, c]
    return ret


ans = -10**10
for n in range(1, 1 << bitlen):
    ans = max(ans, ret_score(n))
print(ans)


Measured memory_bytes: 21376
/**
 * File    : D.cpp
 * Author  : Kazune Takahashi
 * Created : 1/13/2019, 9:11:50 PM
 * Powered by Visual Studio Code
 */

#include <iostream>
#include <iomanip>   // << fixed << setprecision(xxx)
#include <algorithm> // do { } while ( next_permutation(A, A+xxx) ) ;
#include <vector>
#include <string> // to_string(nnn) // substr(m, n) // stoi(nnn)
#include <complex>
#include <tuple>
#include <queue>
#include <stack>
#include <map> // if (M.find(key) != M.end()) { }
#include <set>
#include <functional>
#include <random> // auto rd = bind(uniform_int_distribution<int>(0, 9), mt19937(19920725));
#include <chrono> // std::chrono::system_clock::time_point start_time, end_time;
// start = std::chrono::system_clock::now();
// double elapsed = std::chrono::duration_cast<std::chrono::milliseconds>(end_time-start_time).count();
#include <cctype>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <cstdlib>
using namespace std;

#define DEBUG 0 // change 0 -> 1 if we need debug.

typedef long long ll;

// const int dx[4] = {1, 0, -1, 0};
// const int dy[4] = {0, 1, 0, -1};

// const int C = 1e6+10;
const ll MOD = 1000000007;

int N, M;
int A[1010];
int B[1010];
vector<int> V;
ll ans = 1;

int main()
{
  cin >> N >> M;
  for (auto i = 0; i < N; i++)
  {
    cin >> A[i];
  }
  for (auto i = 0; i < M; i++)
  {
    cin >> B[i];
  }
  sort(A, A + N);
  reverse(A, A + N);
  sort(B, B + M);
  reverse(B, B + M);
  A[N] = 0;
  B[M] = 0;
  int ind_a = 0;
  int ind_b = 0;
  int P = 0;
  for (auto i = N * M; i >= 1; i--)
  {
    // cerr << "i = " << i << ", A[" << ind_a << "] = " << A[ind_a]
    // << ", B[" << ind_b << "] = " << B[ind_b] << endl;
    if (i == A[ind_a] && i == B[ind_b])
    {
      ind_a++;
      ind_b++;
      P++;
    }
    else if (i == A[ind_a])
    {
      ans *= ind_b;
      ans %= MOD;
      ind_a++;
      P++;
    }
    else if (i == B[ind_b])
    {
      ans *= ind_a;
      ans %= MOD;
      ind_b++;
      P++;
    }
    else if (ind_a * ind_b - P > 0)
    {
      ans *= ind_a * ind_b - P;
      ans %= MOD;
      P++;
    }
    else
    {
      cout << 0 << endl;
      return 0;
    }
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner cin = new Scanner(System.in);
        String S = cin.next().toLowerCase();
        int x = 0;
        for (int i = 97; i <= 97 + 25; i++) {
            if (!S.contains((char)i + "")) {
                x = i;
                break;
            }
        }

        if (x == 0) {
            System.out.println("None");
        } else {
            System.out.println((char)x);
        }
    }
}

Measured memory_bytes: 24148
import numpy as np

def main():
    args = input().rstrip().split(' ')
    N, K = int(args[0]), int(args[1])
    args = input().rstrip().split(' ')
    p = np.array([int(i) for i in args])
    
    p = np.sort(p)
    sum = 0
    for i in range(K):
        sum += p[i]
    print(sum)
    
if __name__ == "__main__":
    main()

Measured memory_bytes: 27288
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int k,s;
  cin >> k >> s;
  int i,j;
  int ans=0;
  int x=s+1,y=0,z=0;
  for(i=0;i<s+1;i++){
    x--;
    for(j=0;j<i+1;j++){
      y=j;
      z=i-j;
      if(x<=k&&y<=k&&z<=k)ans++;
    }
  }
  cout<<ans<<endl;
}

Measured memory_bytes: 256
n = int(input())
a = list(map(int, input().split()))
tot = a[0]

if a.count(0) > 0:
  print(0)
  exit()

for i in range(1,n):
  if (tot > 1e18):
    print(-1)
    exit()
  tot *= a[i]
  
if (tot > 1e18):
  print(-1)
  exit()

print(tot)

Measured memory_bytes: 21792
#include <algorithm>
#include <iomanip>
#include <iostream>
#include <tuple>
#include <vector>

using namespace std;

int main()
{
    int n, m;
    cin >> n >> m;
    vector<int> counter(n, 0);
    vector<tuple<int, int, int>> input(m);
    int c = 0;
    for (auto& i : input)
    {
        cin >> get<1>(i) >> get<0>(i);
        get<2>(i) = c;
        c++;
    }
    sort(input.begin(), input.end());
    vector<pair<int, int>> result(m);
    for (auto i : input)
    {
        counter[get<1>(i)]++;
        result[get<2>(i)].first = get<1>(i);
        result[get<2>(i)].second = counter[get<1>(i)];
    }
    for (auto i : result)
    {
        cout << setfill('0') << right << setw(6) << i.first;
        cout << setfill('0') << right << setw(6) << i.second << endl;
    }
}

Measured memory_bytes: 3840
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
typedef pair<ll,ll> l_l;
const int INF=1001001000;
const int mINF=-1001001000;
const ll LINF=10100100100100100;
int main(){
    ll n,W;cin >> n >> W;
    vector<ll> w(n),v(n);
    ll sumv=0;
    for(int i=0; i<n; i++){
        cin >> w[i] >> v[i];
        sumv+=v[i];
    }
    vector<vector<ll>> dp(n+1,vector<ll>(sumv+1,LINF));
    dp[0][0]=0;
    for(int i=0; i<n; i++){
        for(int j=0; j<=sumv; j++){
            if(j-v[i]>=0){
                dp[i+1][j]=min(dp[i][j],dp[i][j-v[i]]+w[i]);
            }
            else dp[i+1][j]=dp[i][j];
        }
    }
    ll ans=0;
    for(int i=0; i<=sumv; i++){
        if(dp[n][i]<=W) ans=i;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 80256
#include <iostream>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/assoc_container.hpp>
#include <bits/stdc++.h>
#define FIO ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define ll long long
using namespace std;
using namespace __gnu_pbds;

typedef tree<pair<long long int,long long int>,null_type,less<pair<long long int,long long int> >,rb_tree_tag,tree_order_statistics_node_update> ordered_set;

void go()
{
    ll int n;
    cin>>n;
    map<ll int,ll int> h;
    vector<ll int> a(n);
    ll int an=0;
    set<vector<ll int> > ans;
    for(int i=0;i<n;i++)
        cin>>a[i],h[a[i]]++;
    for(int i=0;i<n-2;i++)
    {
        for(int j=i+1;j<n-1;j++)
        {
            for(int k=j+1;k<n;k++)
            {
                vector<ll int> t;
                if(a[i]!=a[j] && a[j]!=a[k] && a[i]!=a[k])
                {
                    t.push_back(a[i]),t.push_back(a[j]),t.push_back(a[k]);
                    sort(t.begin(),t.end());
                    if(t[0]+t[1] > t[2] && ans.count(t) == 0)
                        ans.insert(t),an+=h[a[i]]*h[a[j]]*h[a[k]];
                }
            }
        }
    }
    cout<<an;
}
int main()
{
    FIO;
//    int t;
//    cin>>t;
//    while(t--)
        go();
    return 0;
}


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

int main(){
    long long H, N;
    int A[100001];
    cin >> H >> N;

    long sum = 0;
    string result = "No";
    for(int i=0; i<N; i++){
        cin >> A[i];
        sum += A[i];
        if(sum >= H){
            result = "Yes";
            break;
        }
    }

    cout << result << endl;    
    return 0;
}

Measured memory_bytes: 640
#include<iostream>
using namespace std;
main()
{
	long n,t,sum=0;
	cin>>n>>t;
	long now=0;
	for(int i=0;i<n;i++)
	{
		long a;
		cin>>a;
		if(now>a)
		{
			sum+=a+t-now;
		}
		else
		{
			sum+=t;
		}
		now=a+t;
	}
	cout<<sum<<endl;
}

Measured memory_bytes: 764
#include <algorithm>
#include <cstdio>
#include <iostream>
#include <map>
#include <cmath>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
#include <stdlib.h>
#include <stdio.h>
#include <bitset>
#include <cstring>
#include <deque>
using namespace std;
#define FOR(I,A,B) for(int I = (A); I < (B); ++I)
#define CLR(mat) memset(mat, 0, sizeof(mat))
typedef long long ll;
typedef pair<ll, ll> P;
const int MOD = 1000000007;
map<P, ll> MAP;
ll f(ll S, ll T) {
  if(MAP.count(P(S, T))) return MAP[P(S, T)];
  if(S < 0 || T < 0) return 0;
  if(S == 0 && T == 0) return 1;
  ll ret = f(S / 2, T / 2);
  if(S > 0 && T > 0) ret += f((S - 1) / 2, (T - 1) / 2);
  if(T > 1) ret += f(S / 2, (T - 2) / 2);
  return MAP[P(S, T)] = ret % MOD;
}
int main()
{
  ios::sync_with_stdio(false);
  cin.tie(0);
  ll N; cin >> N;
  cout << f(N, N) << endl;
  return 0;
}

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

long long _gcd(long long x, long long y){
    if(x < y) swap(x, y);
    long long r = x % y;
    if(r == 0) return y;
    else return _gcd(y, r);
}
 
long long _lcm(long long x, long long y){
    return x * y / _gcd(x, y);
}
 

int main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);

    long long a, b;
    cin >> a >> b;
    cout << _lcm(a, b)  << endl;

    return 0;
}

Measured memory_bytes: 3616
from collections import Counter
n,p = map(int,input().split())
S = input()
dp = [0]
mod = p
if p==2:
    ans =0
    for i in reversed(range(n)):
        if int(S[i])%2==0:
            ans += i+1
    print(ans);exit()
elif p==5:
    ans =0
    for i in reversed(range(n)):
        if int(S[i])%5==0:
            ans += i+1
    print(ans);exit()
for i in reversed(range(n)):
    dp.append(dp[-1]%mod + pow(10,n-1-i,mod)*int(S[i]))
    dp[-1]%=mod
count = Counter(dp)
ans = 0
for key,val in count.items():
    if val>=2:
        ans += val*(val-1)//2
print(ans)

Measured memory_bytes: 84580
#include<bits/stdc++.h>
using namespace std;
int main()
{
	int a;
	cin>>a;
	int r=0,b=0;
	for(int i=0;i<a;i++)
	{
		char c;
		cin>>c;
		if(c=='R')
		{
			r++;
		}
		else
		{
			b++;
		}
	}
	if(r>b)
	{
		cout<<"Yes"<<endl;
	}
	else
	{
		cout<<"No"<<endl;
	}
}

Measured memory_bytes: 256
#include <cstdio>
#include <cstdlib>
#include <string>
#include <cmath>
#include <queue>
#include <map>
#include <iostream>
#include <algorithm>
using namespace std;
typedef long long ll;
const int maxn = 3e5 + 7;
queue <int> qua;
map <int, int> mp;
char s[maxn];
int sum[maxn];
int n;

int main() {
	cin >> n;
	scanf("%s", s);
	int mint = maxn - 6;
	int s1 = 0, s2 = 0;
	for(int i = 0; i < n; i++) {
		if(s[i] == 'W') s1++;
		sum[i] = s1;
	}
	for(int i = n - 1; i >= 0; i--) {
		if(s[i] == 'E') s2++;
		sum[i] += s2;
		mint = min(mint, sum[i]);
	}
	cout << mint - 1 << endl;
}

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

int main(){
    int N,P;
    int result=0;
    int maxiP=0;
    cin >> N;
    for(int i=0;i<N;i++){
        cin >> P;
        result += P;
        if(i==0 || maxiP<P){
            maxiP=P;
        }
    }
    result -= maxiP/2;
    cout << result << endl;
}

Measured memory_bytes: 256
using System;
using System.Diagnostics;
using System.IO;
using System.Text;
using System.Linq;
using System.Collections.Generic;
using System.Text.RegularExpressions;

class Program
{
    const string Yes = "Yes";
    const string No = "No";
    const char White = '.';
    const char Black = '#';
    const long Mod = 1000000007;

    static void Main(string[] args) {
#if DEBUG
        MyDebugger.Test(process, "../TextFile1.txt");
#else
        object ret = process(new StreamReader(Console.OpenStandardInput()));
        Console.WriteLine(ret);
#endif
    }

    static object process(TextReader input) {
        var s = input.ReadLine();

        var co = 0;
        var i1 = 0;
        var i2 = s.Length-1;

        while (i1 < i2) {
            var c1 = s[i1];
            var c2 = s[i2];

            if(c1 == c2) {
                i1++;
                i2--;
            }else if(c1 == 'x') {
                i1++;
                co++;
            }else if(c2 == 'x') {
                i2--;
                co++;
            } else {
                return -1;
            }
        }

        return co;
    }

    static int[] ToIntArray(string strs, int n) {
        var ret = new int[n];
        var spl = strs.Split(' ');
        for (int i = 0; i < n; i++)
            ret[i] = int.Parse(spl[i]);
        return ret;
    }
}


Measured memory_bytes: 13280
#include<iostream>
#include<vector>
#include<algorithm>
#include<iomanip>
#include<map>
#include<set>
#include<queue>
#include<string>

using namespace std;

#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define ALL(a) (a).begin(),(a).end()
#define PI 3.141592653589793238
#define INF 1050000000
#define INFL (long long)(4e18)

using vi = vector<int>;

template<class T>
struct Edge {
    int to;
    T cost;
    Edge() {};
    Edge(int to, T cost) : to(to), cost(cost) {};
};

template<class T>
class Graph {
    int n;
    bool directed;
    vector<vector<Edge<T>>> edges;
public:

    Graph(int n, bool directed) :n(n), directed(directed), edges(vector<vector<Edge<T>>>(n)){};
    Graph() {};

    void add(int from,int to, T cost) {
        edges[from].emplace_back(to, cost);
        if(!directed){
            edges[to].emplace_back(from,cost);
        }
    }

    int size() {
        return n;
    }
};




int main() {

    string S;

    cin >> S;

    vi sum(2019);

    REP(i,2019)sum[i] = 0;

    reverse(ALL(S));

    int tmp = 0;
    int keta = 1;

    REP(i,S.size()){
        int c = S[i] - '0';
        sum[(tmp + keta * c % 2019)%2019]++;
        tmp = (tmp + keta * c % 2019) % 2019;
        keta *= 10; keta %= 2019;
   }

    long long int ans = 0;

    REP(i,2019){
        ans += sum[i] * (sum[i]-1) / 2;
    }
    
    

    cout << ans+sum[0] << endl;

    return 0;
}

Measured memory_bytes: 3724
list_in = list(map(int, input().split()))
list_house = list(map(int, input().split()))
K = list_in[0]
N = list_in[1]
list_diff = [0] * N

for i in range(1, N):
    list_diff[i] = list_house[i] - list_house[i-1]

list_diff[0] = K + list_house[0] - list_house[N-1]

max_diff = max(list_diff)
start_idx = list_diff.index(max_diff)

sum = 0
for i in range(N-1):
    tmp_idx = ( start_idx + i + 1 ) % N
    sum += list_diff[tmp_idx]

print(sum)


Measured memory_bytes: 26444
#include <algorithm>
#include <array>
#include <cstddef>
#include <cstdint>
#include <iomanip>
#include <iostream>
#include <map>
#include <set>
#include <vector>

using namespace std;

int main()
{
    int n;
    cin >> n;
    cout << (n + 1) / 2 << endl;
}


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

#define all(v) v.begin(), v.end()
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define intll int long long
const int INF = 1e9;
const int MOD = 1e9 + 7;

int main() {
  int n ; 
  cin >> n  ;
  vector<intll> d(n) ;
  rep(i,n) cin >> d.at(i) ;
  intll ans = 1 ;
  
  rep(i,n){
    if(d.at(i) == 0) {
      cout << 0 ;
      return 0  ;
    }
  }
  
  rep(i,n){
    if(d.at(i) <= 1000000000000000000 / ans){  
      ans *= d.at(i) ;
    }
    else {
      ans = -1 ;
      break ;
    }
  }
   cout << ans ;
}
  


Measured memory_bytes: 4000
#include <bits/stdc++.h>
#include <cmath>

using namespace std;
typedef long long ll;
//typedef unsigned long long ll;

#define rep(i, n) for (int i = 0; i < (n); ++i)
//#define rep(i, n) for (ll i = 0; i < (n); ++i)
//#define sz(x) ll(x.size())
//typedef pair<ll, int> P;
typedef pair<ll, ll> P;
//const double INF = 1e10;
const ll INF = LONG_LONG_MAX / 10;
//const ll INF = 1e15;
const ll MINF = LONG_LONG_MIN;
//const int INF = INT_MAX / 10;
#define cmin(x, y) x = min(x, y)
#define cmax(x, y) x = max(x, y)
//typedef pair<int, int> P;
//typedef pair<double, double> P;

bool contain(set<P> &s, P a) { return s.find(a) != s.end(); }

//ifstream myfile("C:\\Users\\riku\\Downloads\\0_00.txt");
//ofstream outfile("log.txt");
//outfile << setw(6) << setfill('0') << prefecture << setw(6) << setfill('0') << rank << endl;
// std::cout << std::bitset<8>(9);


void print_line(vector<ll> &line) {
    if (line.size() == 0ll) {
        cout << endl;
        return;
    }
    for (ll i = 0; i < line.size(); i++) {
        cout << line[i];
        if (i == line.size() - 1) cout << endl;
        else cout << ' ';
    }
}


typedef priority_queue<long long, vector<long long>, greater<long long>> PQ_ASK;
const int mod = 1000000007;

template<typename T>
struct WeightedUnionFind {
    T d;
    vector<int> r, p;
    vector<T> ws;

    WeightedUnionFind() {}

    WeightedUnionFind(int n, T d) :
            d(d), r(n, 1), p(n), ws(n, d) { iota(p.begin(), p.end(), 0); }

    int find(int x) {
        if (x == p[x]) return x;
        int t = find(p[x]);
        ws[x] += ws[p[x]];
        return p[x] = t;
    }

    T weight(int x) {
        find(x);
        return ws[x];
    }

    bool same(int x, int y) {
        return find(x) == find(y);
    }

    void unite(int x, int y, T w) {
        w += weight(x);
        w -= weight(y);
        x = find(x);
        y = find(y);
        if (x == y) return;
        if (r[x] < r[y]) swap(x, y), w = -w;
        r[x] += r[y];
        p[y] = x;
        ws[y] = w;
    }

    T diff(int x, int y) {
        return weight(y) - weight(x);
    }
};

int main() {
    int n, q;
    cin >> n >> q;

    WeightedUnionFind<int> uf(n, 0);

    rep(i, q) {
        int query;
        cin >> query;
        if (query == 0) {
            int x, y, z;
            cin >> x >> y >> z;
            uf.unite(x, y, z);
        } else {
            int x, y;
            cin >> x >> y;
            if (uf.same(x, y)) {
                cout << uf.diff(x, y) << endl;
            } else {
                cout << '?' << endl;
            }
        }
    }


}



Measured memory_bytes: 3892
using System;

class Program
{
    static void Main(string[] args)
    {
        int n = int.Parse(Console.ReadLine());

        string[] input = Console.ReadLine().Split(' ');
        int[] b = new int[n];
        int[] c = new int[n];
        int i = 0;
        foreach (string s in input)
        {
            b[i] = int.Parse(s);
            c[i] = b[i];
            i++;
        }
        for (int ii = 0; ii < n - 1; ii++)
        {
            for (int jj = ii+1; jj < n; jj++)
            {
                if (b[ii] > b[jj])
                {
                    int buf = b[ii];
                    b[ii] = b[jj];
                    b[jj] = buf;
                }
            }

        }
        int counter = 0;
        for (int ii = 0; ii < n; ii++)
        {
            if (b[ii] != c[ii])
            {
                counter++;
            }
            if (counter > 2)
            {
                Console.WriteLine("NO");
                return;
            }
        }




        if (counter == 2)
        {
            Console.WriteLine("YES");
        }
        else if (counter == 0)
        {
            Console.WriteLine("YES");
        }
        else
        {
            Console.WriteLine("NO");
        }

    }
}



Measured memory_bytes: 11092
import java.util.Scanner;
import java.util.Arrays;

class Main{
	public static void main(String[] args){
		Scanner scanner = new Scanner(System.in);
		int n = scanner.nextInt();
		int[] numbers = new int[n];
		
		for(int i = n-1; i >= 0; i--){
			numbers[i] = scanner.nextInt();
		}

		for(int i = 0; i < n; i++){
		    if(i == n-1){
		        System.out.print(numbers[i]);
		    }else{
		        System.out.print(numbers[i] + " ");
		    }
			
		}

		System.out.print("\n");
	}
}

Measured memory_bytes: 26356
n = int(input())
l = [list(input().split()) for i in range(n)]
s,p = [list(i) for i in zip(*l)]
p = [int(i) for i in p]
z = list(set(s))
z.sort()
m = list(p)
m.sort(reverse = True)
l = []
 
k = 0
for i in range(len(z)):
    l.append(k)
    k += 200
 
o = []
for i in range(n):
    w = l[z.index(s[i])]
    w += m.index(p[i])
    o.append(w)
 
r = list(o)
r.sort()
for i in range(n):
    print(o.index(r[i]) + 1) 

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

using ll = long long;

int main()
{
	ios_base::sync_with_stdio(0);
	cin.tie(0); cout.tie(0);
	int n, k, sum = 0;
	cin >> k >> n;
	vector <int> a(n);
	for (int i=0; i<n; i++) {
		cin >> a[i];
		sum += a[i];
	}
	cout << (sum >= k ? "Yes" : "No");
	return 0;
}


Measured memory_bytes: 640
//raja1999
#include <bits/stdc++.h>
#include <vector>
#include <set>
#include <map>
#include <string>
#include <cstdio>
#include <cstdlib>
#include <climits>
#include <utility>
#include <algorithm>
#include <cmath>
#include <queue>
#include <stack>
#include <iomanip> 
//setbase - cout << setbase (16)a; cout << 100 << endl; Prints 64
//setfill -   cout << setfill ('x') << setw (5); cout << 77 <<endl;prints xxx77
//setprecision - cout << setprecision (14) << f << endl; Prints x.xxxx
//cout.precision(x)  cout<<fixed<<val;  // prints x digits after decimal in val

using namespace std;
#define f(i,a,b) for(i=a;i<b;i++)
#define rep(i,n) f(i,0,n)
#define fd(i,a,b) for(i=a;i>=b;i--)
#define pb push_back
#define mp make_pair
#define vi vector< int >
#define vl vector< ll >
#define ss second
#define ff first
#define ll long long
#define pii pair< int,int >
#define pll pair< ll,ll >
#define sz(a) a.size()
#define inf (1000*1000*1000+5)
#define all(a) a.begin(),a.end()
#define tri pair<int,pii>
#define vii vector<pii>
#define vll vector<pll>
#define viii vector<tri>
#define mod (1000*1000*1000+7)
#define pqueue priority_queue< int >
#define pdqueue priority_queue< int,vi ,greater< int > >

//std::ios::sync_with_stdio(false);
int a[1000];
int main(){
	std::ios::sync_with_stdio(false);
	int n,i,ans=0,c,prev;
	cin>>n;
	rep(i,n){
		cin>>a[i];
	}	
	c=1;
	prev=a[0];
	f(i,1,n){
		if(a[i]!=prev){
			ans+=c/2;
			prev=a[i];
			c=1;
		}
		else{
			c++;
		}
	}
	ans+=c/2;
	cout<<ans<<endl;

} 
	

Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
int main(){
    string s;
    cin >> s;
    int n = s.size();
    for(int i = 0; i < n; i++){
        if(s.at(i) == 'A')
        s.at(i) = 'T';
        else if(s.at(i) == 'T')
        s.at(i) = 'A';
        else if(s.at(i) == 'G')
        s.at(i) = 'C';
        else 
        s.at(i) = 'G';
    }
    cout << s << endl;
}

Measured memory_bytes: 256
n = int(input())

dic = {}

for i in range(n):
    s = input()
    if s in dic:
        dic[s] += 1
    else:
        dic[s] = 1

d = max(dic.values())
max_k_list = [kv[0] for kv in dic.items() if kv[1] == d]
max_k_list.sort()

for s in max_k_list:
    print(s)


Measured memory_bytes: 94424
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;

#define rep(i,n) for(int i=0; i<n; i++)
#define all(x) (x).begin(),(x).end()
#define INF (1000000000)
#define MOD (1000000007)

int main(){
  string s;
  int k;
  cin >> s >> k;
  int n = s.size();
  vector<string> v;
  string sub;
  rep(i,n){
    rep(j,min(n-i,5)){
      sub = s.substr(i,j+1);
      v.push_back(sub);
    }
  }
  sort(all(v));
  map <string,bool> m;
  int cnt=0;
  rep(i,v.size()){
    if(!m[v[i]]){
      cnt++;
      m[v[i]]=1;
      if(cnt == k){
        cout << v[i] << endl;
        return 0;
      }
    }
  }
}

Measured memory_bytes: 1660
fn main() {
    proconio::input! {
        n: usize,
        a_s: [usize; n],
    }
    let mut all_xor = a_s[0];
    for a in a_s.iter().skip(1) {
        all_xor ^= a;
    }
    let mut v = vec![];
    for a in a_s {
        v.push(all_xor ^ a);
    }
    let ans = v
        .iter()
        .map(|item| item.to_string())
        .collect::<Vec<_>>()
        .join(" ");
    println!("{}", ans);
}


Measured memory_bytes: 18828
#include <bits/stdc++.h>
#define fi first
#define se second
#define mp make_pair

using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
const double eps = 1e-8;
const int NINF = 0xc0c0c0c0;
const int INF = 0x3f3f3f3f;
const ll mod  = 1e9 + 7;
const ll N = 1e6 + 5;

int main(){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    string s;cin>>s;
    int ans=0;
    for(auto c:s){
    	ans=(ans+c-'0')%9;
    }
    if(!ans) cout<<"Yes\n";
    else cout<<"No\n";
    return 0;
}

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

int main(void){
  int N, K;
  cin >> N >> K;
  char S[N];
  cin >> S;
  for(int i = 0; i < N; i++){
    if(i == K - 1)
      S[i] = S[i] + 32;
  }
  printf("%s\n",S);
  return 0;
}


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

template<typename T>
void out(T x) { cout << x << endl; exit(0); }
#define watch(x) cout << (#x) << " is " << (x) << endl





typedef long long ll;
const ll mod = 1e9+7;
const int maxn = 1e6+10;
const ll inf = 1LL<<60;

int n, m;
ll p;

ll a[maxn], b[maxn], c[maxn];
ll dist[maxn], prevdist[maxn];

bool reach1[maxn];
bool reachn[maxn];

//use reach1 and reachn to detect if a positive cycle can happen between 1 and n
//see sample 3 for more clarification

int main() {
    ios_base::sync_with_stdio(false); cin.tie(0);  cout.tie(0);
    cin>>n>>m;
    cin>>p;
    for (int i=1; i<=m; i++) {
	cin>>a[i]>>b[i]>>c[i];
	c[i] -= p;
    }

    reach1[1] = true;
    for (int iter=1; iter<=n; iter++) {
	for (int j=1; j<=m; j++) {
	    if (reach1[a[j]]) reach1[b[j]] = true;
	}
    }


    reachn[n] = true;
    for (int iter=1; iter<=n; iter++) {
	for (int j=1; j<=m; j++) {
	    if (reachn[b[j]]) reachn[a[j]]=true;
	}
    }


    for (int i=1; i<=n; i++) {
	dist[i] = -inf;
    }
    dist[1] = 0;
    
    for (int iter=0; iter<=2*n; iter++) {
	for (int i=1; i<=n; i++) {
	    prevdist[i] = dist[i];
	}
	for (int j=1; j<=m; j++) {
	    dist[b[j]] = max(dist[b[j]], dist[a[j]] + c[j]);
	}

	bool changed = false;
	for (int i=1; i<=n; i++) {
	    if (prevdist[i] != dist[i] && reach1[i] && reachn[i]) {
		changed = true;
	    }
	}
	if (!changed) break;
	if (iter == 2*n) out(-1);
    }

    ll ans = max(0LL, dist[n]);
    out(ans);
    return 0;
}


Measured memory_bytes: 8448
#include <bits/stdc++.h>
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
using namespace std;
const long long INF = 1LL << 60;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

int main(){
    int N, K;
    cin >> N >> K;
    int p[N];
    rep(i, N) cin >> p[i];
    sort(p + 0, p + N);
    int ans = 0; 
    rep(i, K) ans += p[i];
    cout << ans <<endl;

    return 0;    
}

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

bool check(vector<string> const& v, vector<string> const& flag, int x, int y) {
    if(x < 0 || x+1 >= v[0].size() || y < 0 || y+1 >= v.size()) {
        return false;
    }
    return v[y][x] == flag[0][0] && v[y+1][x] == flag[1][0] && v[y][x+1] == flag[0][1] && v[y+1][x+1] == flag[1][1];
}

int main() {
    int M, N;
    cin >> M >> N;
    vector<string> v(M);
    for(int i=0; i<M; ++i) {
        cin >> v[i];
    }
    vector<string> flag(2);
    for(int i=0; i<2; ++i) {
        cin >> flag[i];
    }

    int sum = 0;
    for(int i=0; i<N; ++i) {
        for(int j=0; j<M; ++j) {
            sum += check(v, flag, i, j);
        }
    }
    int res = 0;
    for(int x=0; x<N; ++x) {
        for(int y=0; y<M; ++y) {
            int t = 0;
            int dx[4] = {-1, 0, -1, 0},
                dy[4] = {-1, -1, 0, 0};
            for(int k=0; k<4; ++k) {
                t += check(v, flag, x+dx[k], y+dy[k]);
            }
            array<char, 3> ar = {'J', 'O', 'I'};
            for(int k=0; k<3; ++k) {
                int s = 0;
                char tmp = v[y][x];
                v[y][x] = ar[k];
                for(int l=0; l<4; ++l) {
                    s += check(v, flag, x+dx[l], y+dy[l]);
                }
                v[y][x] = tmp;
                res = max(res, sum - t + s);
            }
        }
    }
    cout << res << endl;
}


Measured memory_bytes: 3964