akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define endl '\n'
#define mod 1000000007
#define dd double
#define ld long double
#define f(i,a,b) for(ll i = a; i < b; i++)
#define fr(i,a,b) for(ll i = b;i>=a;i--)
#define vec vector<ll>
#define pb push_back
#define mp make_pair
#define pii pair<ll,ll>
#define VP vector< pii >
#define clr(x) x.clear()
#define sz(x) ((int)(x).size())
#define F first
#define S second
#define all(v) (v).begin(),(v).end()
#define Sort(v) sort(v.begin(), v.end(), sortbysec)
#define MEM(a, b) memset(a, (b), sizeof(a))
#define N 1000000

ll power(ll x, ll y, ll p)  
{  
    ll res = 1;      
    x = x % p; 
                
    while (y > 0)  
    {   
        if (y & 1)  
            res = (res*x) % p;   
        y = y>>1;
        x = (x*x) % p;  
    }  
    return res;  
}  

 

int main() 
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);

//ll t; cin>>t; while(t--){}
ll h1,s1,h2,s2;
cin>>h1>>s1>>h2>>s2;

ll c = 1;

while(1)
{
    if(c%2)
    {
        h2-=s1;
        if(h2 <= 0)
        {
            cout<<"Yes";
            break;
        }
        
    }
    else
    {
        h1-=s2;
        if(h1 <=0)
        {
            cout<<"No";
            break;
        }
    }
    c++;
    
}



return 0;
}


Measured memory_bytes: 3552
def main():
    s = input()
    q = int(input())
    reverse_count = 0
    left = []
    right = []
    for _ in range(q):
        query = list(input().split())
        if query[0] == "1":
            reverse_count += 1
        else:
            if reverse_count % 2:
                if query[1] == "1":
                    right.append(query[2])
                else:
                    left.append(query[2])
            else:
                if query[1] == "1":
                    left.append(query[2])
                else:
                    right.append(query[2])
    print("".join(right[::-1]) + s[::-1] + "".join(left) if reverse_count % 2
          else "".join(left[::-1]) + s + "".join(right))


if __name__ == '__main__':
    main()



Measured memory_bytes: 6252
A, B = map(int, input().split())
S = list(input())
flag = 1
a = "".join(S[:A])
b = "".join(S[A+1:])
if not(str.isdecimal(a)):
  flag = 0
if S[A] != "-":
  flag = 0
if not(str.isdecimal(b)):
  flag = 0
if flag == 1:
  print("Yes")
else:
  print("No")


Measured memory_bytes: 38384
#pragma comment(linker, "/stack:20000000")
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx")
 
#include <stdio.h>
#include <bits/stdc++.h>
 
using namespace std;
 
#include <x86intrin.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
template <typename T> using ordered_set = tree<T, null_type, std::less<T>, rb_tree_tag, tree_order_statistics_node_update>;
  
#define pb push_back
#define mp make_pair
#define in insert
#define f first
#define s second
#define ll long long
#define ld long double
  
const int mod = 1e9 + 7;
const int N = 2e5 + 7;
const int inf = 2e9;
const ll INF = 1e18;

int a[N], b[N], c[N], dp[N][3];

int main() {
	ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
	// freopen("*.in", "r", stdin);freopen("*.out", "w", stdout);
	int n;
	cin >> n;
	for(int i = 1; i <= n; i++) {
		cin >> a[i] >> b[i] >> c[i];
	}
	dp[1][0] = a[1];
	dp[1][1] = b[1];
	dp[1][2] = c[1];
	for(int i = 2; i <= n; i++) {
		dp[i][0] = max(dp[i - 1][1], dp[i - 1][2]) + a[i];
		dp[i][1] = max(dp[i - 1][2], dp[i - 1][0]) + b[i];
		dp[i][2] = max(dp[i - 1][1], dp[i - 1][0]) + c[i];
	}
	cout << max(dp[n][0], max(dp[n][1], dp[n][2]));
}

Measured memory_bytes: 3712
#include <stdio.h>

int main(void){

  int n,k,x,y,sum;

  scanf("%d\n%d\n%d\n%d/n",&n,&k,&x,&y);

  if(n<=k){

    sum = x*n;

  }else{

    sum = x*k + y*(n-k);

  }

  printf("%d\n",sum);

  return 0;

}

    

  


Measured memory_bytes: 1704
X, K, D = map(int, input().split())
div = abs(X) // D
if div <= K:
    if (K - div) % 2 == 0:
        print(min(abs(X - div * D), abs(X + div * D)))
    else:
        print(min(abs(X - (div + 1) * D), abs(X + (div + 1) * D)))
else:
    print(min(abs(X + K * D), abs(X - K * D)))


Measured memory_bytes: 61848
#include <cstdio>
#include <bits/stdc++.h>
#include <algorithm>
#include <iostream>
#include <string>
#include <cmath>
#include <functional>
#include <vector>
#include <stack>
#include <queue>
#include <map>
#define rep(i,n) for (int i=0;i<n;i++)
using ll = long long;
using namespace std;

void solve(){

}
int main (){
    ios::sync_with_stdio(0);
    cin.tie(0);
    ll a,v,b,w,t;
    cin >> a >> v >>b >> w >> t;
    ll d = abs(b-a);
    ll q = v-w;
    if(q<=0){
        cout << "NO";
        return 0;
    }
    if(q*t>=d){
        cout << "YES";
    }
    else{
        cout << "NO";
    }

    return 0;
}

Measured memory_bytes: 3648
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
typedef vector<int> VI;

template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return 1; } return 0; }
#define _overload3(_1,_2,_3,name,...) name
#define _rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(int i=int(a);i<int(b);++i)
#define rep(...) _overload3(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)
#define all(x) (x).begin(),(x).end()


int main() {
    string s;
    int k;
    cin >> s >> k;
    rep (i, s.size()) {
        if (s[i] == 'a') continue;
        int toa = 'z' + 1 - s[i];
        if (toa <= k) {
            k -= toa;
            s[i] = 'a';
        }
    }
    if (k > 0) {
        k %= 26;
        s[s.size() - 1] = (s[s.size() - 1] - 'a' + k) % 26 + 'a';
    }
    cout << s << endl;
}

Measured memory_bytes: 512
#include<bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(n);i++)
typedef  long long ll;
ll gcd(ll x,ll y){
   if(y==0) return x;
   else return gcd(y,x%y);
}
ll lcm(ll x,ll y){
   return x/gcd(x,y)*y;
}
using namespace std;
int main(){ 
   int n;
   cin>>n;
   vector<ll> lucas(n+1);

   rep(i,n+1){
      if(i==0) lucas[0]=2;
      else if(i==1) lucas[1]=1;
      else lucas[i]=ll(lucas[i-1])+lucas[i-2];
   }
   cout<<lucas[n];

   



   
   return 0;
}

Measured memory_bytes: 256
n, q = map(int, input().split())

s = input()

count = [0] * n

for i in range(1, n):
    if s[i-1] == 'A' and s[i] == 'C':
        count[i] += 1

from itertools import accumulate

accum = list(accumulate(count))

for _ in range(q):
    l, r = map(int, input().split())
    print(accum[r-1] - accum[l-1])

Measured memory_bytes: 52000
#include<bits/stdc++.h>
using namespace std;
#define pb push_back
#define mp make_pair
#define li long long int
#define F first
#define S second
//const li M = 1000000007;
#define ld long double
li N,M,K;
li dx[]={-1,1,0,0};
li dy[]={0,0,-1,1};
const li INF = 99999999;
vector<string> A;
vector<vector <li> > D;
bool e(li x,li y)
{
    if(x>=0 && y>=0 && x<N && y<M)
    return true;
    return false;
}
void print(vector<vector<li>> &C)
{
    for(int i=0;i<C.size();i++)
    {
        for(int j=0;j<C[0].size();j++)
        cout<<C[i][j]<<" ";
        cout<<"\n";
    }cout<<"\n";
}void print(vector<string> &C)
{
    for(int i=0;i<C.size();i++)
    {
        for(int j=0;j<C[0].size();j++)
        cout<<C[i][j]<<" ";
        cout<<"\n";
    }cout<<"\n";
}
void bfs(li x,li y)
{
    list<pair<li,li> > myl;
    myl.pb(mp(x,y));

    while(!myl.empty())
    {
        li xx=myl.front().F,yy=myl.front().S;
        li d=D[xx][yy];
        myl.pop_front();
        for(li k=0;k<4;k++)
    {
        for(li i=1;i<=K;i++)
        {
            if(!e(xx+i*dx[k], yy+i*dy[k]) || A[xx+i*dx[k]][yy+i*dy[k]]=='@')
                break;
            if(D[xx+i*dx[k]][yy+i*dy[k]]!=INF && D[xx+i*dx[k]][yy+i*dy[k]]<=d)
                break;
            if(D[xx+i*dx[k]][yy+i*dy[k]]!=INF)
            continue;
            D[xx+i*dx[k]][yy+i*dy[k]]=d+1;
            myl.pb(mp(xx+i*dx[k],yy+i*dy[k]));
        }
    }
    }
    
}
int main()
{
    int i,j,k,l; 
    cin>>N>>M>>K;
    pair<li,li> st,en;
    cin>>st.F>>st.S>>en.F>>en.S;
    st.F--;st.S--;en.F--;en.S--;

    A.clear(); D.clear(); A.resize(N);
    for(i=0;i<N;i++)
    {
        vector<li> B(M,INF);
        cin>>A[i]; D.pb(B);
    }
    for(i=0;i<N;i++)
    {
        for(j=0;j<M;j++)
        cin>>A[i][j];
    }
    //print(A);print(D);
    D[st.F][st.S]=0;
    bfs(st.F,st.S);
    //print(A);print(D);
    if(D[en.F][en.S] == INF)
        cout<<"-1";
        else
        cout<<D[en.F][en.S];

    return 0;
}


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

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

    int c=0;
    for(int i=0; i<n;i++){
        int a;
        cin >> a;
        c += a;
    }
    if(h>c){
        cout << "No";
    }
    else{
        cout <<"Yes";
    }
}

Measured memory_bytes: 256
#include<iostream>

#define REP(i,a,b) for(i=a;i<b;i++)
#define rep(i,n) REP(i,0,n)
using namespace std;


int main () {
  int n, num;
  int cards[4][13] = {{0}};
  char mark;
  int i,j;
  cin >> n;

  // S:0, H:1, C:2, D:3
  rep(i,n) {
    cin >> mark >> num;
    switch (mark)
      {
      case 'S':
	cards[0][num-1] = 1;
	break;
      case 'H':
	cards[1][num-1] = 1;
	break;
      case 'C':
	cards[2][num-1] = 1;
	break;      
      case 'D':
	cards[3][num-1] = 1;
	break;
      default:
	break;
      }
  }

  rep(i,4) {
    rep(j,13) {
      if (cards[i][j] == 0) {
	switch (i)
	  {
	  case 0:
	    cout << "S " << j+1;
	    break;
	  case 1:
	    cout << "H " << j+1;
	    break;
	  case 2:
	    cout << "C " << j+1;
	    break;
	  case 3:
	    cout << "D " << j+1;
	    break;
	  default:
	    break;
	  }
	cout << endl;
      }
    }
  }
  return 0;
}

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

//#define int long long
#define all(v) (v).begin(), (v).end()
#define rall(v) (v).rbegin(), (v).rend()
#define rep(i,n) for(int i=0;i<n;++i)
#define rep1(i,n) for(int i=1;i<n;++i)
#define exrep(i, a, b) for(ll i = a; i < b; i++)
#define out(x) cout << x << endl
#define EPS (1e-7)
#define gearup ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);

typedef long long int ll;
typedef long double ld;
typedef unsigned long long int ull;
typedef vector<int> vi;
typedef vector<char> vc;
typedef vector<bool> vb;
typedef vector<double> vd;
typedef vector<string> vs;
typedef vector<pair<int,int> > vpii;
typedef vector<vector<int> > vvi;
typedef vector<vector<char> > vvc;
typedef vector<vector<bool> > vvb;
typedef vector<vector<double> > vvd;
typedef vector<vector<string> > vvs;
typedef vector<ll> vl;
typedef vector<vector<ll> > vvl;
typedef vector<vector<vector<ll> > > vvvl;
ll MOD = 1000000007;
const long long L_INF = 1LL << 60;
const int INF = 2147483647; // 2^31-1
const double PI = acos(-1);
//cout<<fixed<<setprecision(10);

template<class T> inline bool chmin(T& a, T b) {if (a > b) {a = b;return true;}return false;}
template<class T> inline bool chmax(T& a, T b) {if (a < b) {a = b;return true;}return false;}
template<class T> void debug(T v){rep(i,v.size()) cout<<v[i]<<" ";cout<<endl;}
const ll dx[8] = {1, 1, 0, -1, -1, -1, 0, 1};
const ll dy[8] = {0, 1, 1, 1, 0, -1, -1, -1};

signed main()
{   
    gearup;
    ll n; cin >> n;
    string s; cin >> s;
    rep(bit,4){ //４通りを考える SS,SW,WS,WW S:0, W:1
        vl a(n+1);
        rep(i,2){
            if( (bit>>i) & 1)a[i] = 1;
            else a[i] = 0;
        }
        //cout << a[0] << " " << a[1] << endl;
        for(int i=1;i<n;i++){
            if(a[i] == 0 && s[i] == 'o')a[i+1] = a[i-1];
            if(a[i] == 0 && s[i] == 'x')a[i+1] = !a[i-1];
            if(a[i] && s[i] == 'o')a[i+1] = !a[i-1];
            if(a[i] && s[i] == 'x')a[i+1] = a[i-1];
        }
        //仮定したaの並びで文字列を生成する
        string res;
        rep(i,n){
            int pre = (i- 1 + n) % n;
            int next = (i + 1) % n;
            if(a[i] == 0){
                if(a[pre] == a[next])res+='o';
                else res+='x';
            }
            else{
                if(a[pre] == a[next])res+='x';
                else res+='o';
            }
        }
        //仮定が合っていたら
        if(res == s){
            rep(i,n){
                if(a[i] == 0)cout << 'S';
                else cout << 'W';
            }
            cout << endl;
            return 0;
        }
    }
    out(-1);
}


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

int main(void) {
	int N, s[100], sum = 0, min = 100000 ,minN=-5;
	cin >> N ;
	for (int i = 0; i < N; i++) {
		cin >> s[i];
		sum += s[i];
		if (s[i] != 0 && min > s[i] && s[i] % 10 != 0) {
			min = s[i];
			minN = i;
		}
	}
	if (minN == -5) {
		cout << 0 << endl;
		return 0;
	}

	for (int i = 0; i < N; i++) {
		if (sum % 10 == 0) {
			s[minN] = 0;
			sum = 0;
			min = 100000;
			for (int k = 0; k < N; k++) {
				if (s[k] != 0 && min > s[k] && s[i] % 10 != 0) {
					min = s[k];
					minN = k;
				}
			}
			for (int i = 0; i < N; i++) {
				sum += s[i];
			}
		}
		else break;
	}
	cout << sum << endl;
	return 0;
}

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

#define all(x) begin(x), end(x)

using i64 = int_fast64_t;
using f64 = double;
using p64 = pair<i64, i64>;

constexpr i64 INF = INT_FAST64_MAX / 2;
constexpr f64 EPS = DBL_EPSILON;

void solve() {
    i64 n;
    cin >> n;
    vector<i64> a(n), b(n);
    for (i64 i = 0; i < n; i++) {
        cin >> a[i] >> b[i];
    }
    sort(all(a));
    sort(all(b));

    if (n % 2) {
        cout << b[n / 2] - a[n / 2] + 1 << endl;
    } else {
        cout << (b[n / 2] + b[n / 2 - 1]) - (a[n / 2] + a[n / 2 - 1]) + 1 << endl;
    }
}

int main() {
    cin.tie(nullptr);
    ios_base::sync_with_stdio(false);
    cout << fixed << setprecision(15);
    solve();
}


Measured memory_bytes: 6344
def main():
    N = int(input())
    G = [[] for _ in range(N)]
    for i in range(N):
        a = int(input())
        for j in range(a):
            x, y = (int(i) for i in input().split())
            G[i].append((x-1, y))
            # 人iは人xのことをyと言っている
    ans = 0
    for bit in range(1 << N):
        cur = 0
        good = True  # 矛盾がない
        for i in range(N):
            if bit & (1 << i):
                # 人iは正直者
                cur += 1
                for j, y in G[i]:
                    if (bit & (1 << j)) and y == 0:
                        good = False
                    elif not(bit & (1 << j)) and y == 1:
                        good = False
        # print(bit, ":", good)
        if good:
            ans = max(ans, cur)
    print(ans)


if __name__ == '__main__':
    main()


Measured memory_bytes: 43756
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ
		Scanner sc = new Scanner(System.in);
		while(true) {
			
			int pre,angle;
			int xmax=0,ymax=0,xmin=0,ymin=0;
			
			int n = sc.nextInt();
			if(n==0) {break;}
			int[][] pos = new int[n][2];
			pos[0][0] = 0;  //x
			pos[0][1] = 0;  //y
			
			for(int i=1; i<n; i++) {
				pre = sc.nextInt();
				angle = sc.nextInt();
				
				switch(angle) {
				case 0: //left
					pos[i][0] = pos[pre][0]-1;
					pos[i][1] = pos[pre][1];
					if(pos[i][0] < xmin) {
						xmin = pos[i][0];
					}
					break;

				case 1: //down
					pos[i][0] = pos[pre][0];
					pos[i][1] = pos[pre][1]-1;
					if(pos[i][1] < ymin) {
						ymin = pos[i][1];
					}
					break;
					
				case 2: //right
					pos[i][0] = pos[pre][0]+1;
					pos[i][1] = pos[pre][1];
					if(pos[i][0] > xmax) {
						xmax = pos[i][0];
					}
					break;
					
				case 3: //up
					pos[i][0] = pos[pre][0];
					pos[i][1] = pos[pre][1]+1;
					if(pos[i][1] > ymax) {
						ymax = pos[i][1];
					}
					break;
				} //end switch
			} //end for
			System.out.print(xmax - xmin + 1);
			System.out.print(" ");
			System.out.println(ymax - ymin + 1);
			
		}

	sc.close();
	}

}



Measured memory_bytes: 41348
#include <iostream>
#include<algorithm>
#include<sstream>
#include<cmath>
#include<vector>
#include<iomanip>
#include<map>
using namespace std;
typedef long long ll;
#define rep(i,n) for(int i = 0; i < n;i++)
int main(void) {
	int a, b;cin >> a >> b;
	int s = b - a, d = s * (s + 1) / 2;
	cout << d - b << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define fr(i,a,b) for (int i=(a); i<(b);i++)
#define frr(i,a,b) for(int i=(a-1);i>=(b);i--)
#define vi vector<int>
#define de deque<int>
#define del deque<ll>
#define vl vector<ll>
#define pb push_back
#define ppb pop_back()
#define pf push_front
#define ppf pop_front()
#define mp map<ll,ll>
#define rev(a) reverse(a.begin(),a.end())
#define srt(a) sort(a.begin(),a.end())
#define ln(a) a.length()
#define sz(a) a.size()
ll M=1e18L;

int main()
{ios_base::sync_with_stdio(false);
	cin.tie(NULL);cout.tie(NULL);

ll n,w;
cin>>n>>w;
ll a,b;
ll dp[n][w+1];
fr(i,0,n)dp[i][0]=0;
cin>>a>>b;
fr(i,0,w+1){if(i>=a)dp[0][i]=b;else dp[0][i]=0;}

fr(i,1,n)
{
  cin>>a>>b;
  fr(j,1,w+1)
  {
   if(j>=a)
   {
   	dp[i][j]=max(b+dp[i-1][j-a],dp[i-1][j]);
   }
   else dp[i][j]=dp[i-1][j];

  }


}
cout<<dp[n-1][w]<<endl;


}


   



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

using namespace std;
using ll=long long;
using vi=vector<int>;
using vl=vector<ll>;
using vs=vector<string>;

#define pb push_back
#define pf push_front
#define mp make_pair
#define fi first
#define se second
#define All(s) s.begin(),s.end()
#define rAll(s) s.rbegin(),s.rend()
#define rep(i, a, n) for (int i = (a); i < (n); ++i)
#define repr(i, a, n) for (int i = (n); i >= (a); --i)

template<typename T,typename U>
void Inparray(T &f,U n){
  for(int i=0;i<n;i++) cin>>f[i];
}

void flag2func(bool flag){
  flag ? cout<<"Yes"<<endl : cout<<"No"<<endl;
}

int main(){
  cin.tie(nullptr);ios_base::sync_with_stdio(false);
  cout << fixed << setprecision(15);
  int n,m;cin>>n>>m;
  vs a(n),b(m);Inparray(a,n);Inparray(b,m);
  int hoge;
  bool  flag=false;

  //画像A
  rep(i,0,n-m+1){
   rep(j,0,n-m+1){
    //テンプレート画像B
    hoge=0;
    rep(k,0,m){
      rep(l,0,m){
        if(b[k][l]==a[k+i][l+j]){hoge++;}else{goto repend1;}
      }
    }
    repend1:
    //cout<<hoge<<endl;
    if(hoge==m*m){flag=true;goto repend2;}
   }
  }
repend2:
  flag2func(flag);
}

Measured memory_bytes: 256
# 入力が10**5とかになったときに100ms程度早い
import sys
read = sys.stdin.readline


def read_ints():
    return list(map(int, read().split()))


def read_a_int():
    return int(read())


def read_matrix(H):
    '''
    H is number of rows
    '''
    return [list(map(int, read().split())) for _ in range(H)]


def read_map(H):
    '''
    H is number of rows
    文字列で与えられた盤面を読み取る用
    '''
    return [read()[:-1] for _ in range(H)]


def read_col(H, n_cols):
    '''
    H is number of rows
    n_cols is number of cols

    A列、B列が与えられるようなとき
    '''
    ret = [[] for _ in range(n_cols)]
    for _ in range(H):
        tmp = list(map(int, read().split()))
        for col in range(n_cols):
            ret[col].append(tmp[col])

    return ret


MOD = 10**9 + 7

X, Y = read_ints()
if (X + Y) % 3 != 0 or Y / X > 2 or Y / X < 1 / 2:  # !=0
    print(0)
    exit()

pascal_depth = int((X + Y) / 3)  # パスカルの三角形に当たるn
x = ((X + Y) * 2) // 3
pascal_k = x - X  # 端からいくつずれているか


def combination(n, r, mod=MOD):
    r = min(r, n - r)
    nf = rf = 1
    for i in range(r):
        nf = nf * (n - i) % mod
        rf = rf * (i + 1) % mod
    return nf * pow(rf, mod - 2, mod) % mod


# def com(n, k, mod):
#     if k == 0:
#         return 1
#     s = n
#     mod = 10**9 + 7
#     inv = [0, 1]
#     for c in range(2, k + 1):
#         inv.append((-(mod // c) * inv[mod % c]) % mod)
#         s = (((s * (n + 1 - c)) % mod) * inv[c]) % mod
#     return s


a = combination(pascal_depth, pascal_k, MOD)
print(a)


Measured memory_bytes: 3064
#include<bits/stdc++.h>
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<cmath>
#define ll long long
#define PB push_back
#define POP pop_back()
#define PII pair<int,int>
#define FI first
#define SE second
#define ULL unsigned long long
#define endl '\n'
using namespace std;
const int INF=0x3f3f3f3f;
const double pi=acos(-1),eps=1e-8;
const int maxn=202000;
int a[maxn],b[maxn];
int main()
{
//	ios::sync_with_stdio(false);
//	cin.tie(0);cout.tie(0);
	string s;
	ll sum=0;
	cin>>s;
	int len=s.length();
	for(int i=0;i<len;i++){
		int tmp=s[i]-'0';
		b[tmp]=1;
		for(int j=0;j<2019;j++){
			b[(j*10+tmp)%2019]+=a[j];
		}
		for(int j=0;j<2019;j++){
			a[j]=b[j];
			b[j]=0;
		}
		sum+=a[0];
	}
	
	
	cout<<sum<<endl;
 	return 0;
}







Measured memory_bytes: 3696
from collections import Counter
from heapq import heappush, heappop


N = int(input())
A = list(map(int, input().split()))
B = list(map(int, input().split()))

AC = Counter(A)
BC = Counter(B)
S = AC + BC

q = []
for k, v in S.items():
    heappush(q, (-v, k))

ans = []
while q:
    v, k = heappop(q)
    v = -v
    if v != S[k]:
        if S[k] != 0:
            heappush(q, (-S[k], k))
    else:
        if v != 1:
            heappush(q, (-(v - 1), k))
        if v > N:
            print('No')
            exit()
        else:
            if AC[k] > 0:
                a = k
                for l in BC.keys():
                    if l != k:
                        b = l
                        break
            else:
                b = k
                for l in AC.keys():
                    if l != k:
                        a = l
                        break
            ans.append((a, b))
            S[a] -= 1
            S[b] -= 1
            AC[a] -= 1
            if not AC[a]:
                AC.pop(a)
            BC[b] -= 1
            if not BC[b]:
                BC.pop(b)

print('Yes')
ans.sort()
X = [b for a, b in ans]
print(*X)


Measured memory_bytes: 198752
#include "cmath"
#include "cstdio"
#include "vector"

std::vector<bool> eratos(int upper) {
  std::vector<bool> v(upper + 1, true);
  int i, j;
  v[0] = false;
  v[1] = false;
  for (i = 2; i < upper + 1; ++i) {
    if (v[i] == true) {
      for (j = 2; j <= int(upper / i); ++j) {
        v[i * j] = false;
      }
    }
  }
  return v;
}

bool is_prime(int n) {
  if (n != 2 && n % 2 == 0) {
    return false;
  } else if (n == 2) {
    return true;
  } else if (n == 1) {
    return false;
  }
  int i;
  for (i = 3; i <= int(std::sqrt(n)) + 1; ++i) {
    if (n % i == 0) {
      return false;
    }
  }
  return true;
}

int main() {
  int i, m;
  int n;
  int out = 0;
  scanf("%d\n", &n);
  for (i = 0; i < n; ++i) {
    scanf("%d\n", &m);
    if (is_prime(m)) {
      out += 1;
    }
  }
  printf("%d\n", out);
}



Measured memory_bytes: 2696
while 0<n=gets.to_i
h={};(1..n).map{a,b,c=gets.split.map &:to_i;h[a]||=0;h[a]+=b*c};h=h.reject{|a,x|x<1e6}.map{|a,x|a};puts h[0]&&h||"NA";end

Measured memory_bytes: 6148
#include<bits/stdc++.h>//alias g='g++ -std=c++17 pra.cpp'
using namespace std;
#define rep(i, n) ;for(int i=0; i<(n); i++)
using veci = vector<int>;
int INF = INT_MAX;
int a[1000000];
int completed[1000000];
int L[300000];
int R[300000];
int counter=0;
void merge(int a[], int left, int mid, int right){
    int n1 = mid - left;
    int n2 = right - mid;
    for (int i=0; i<n1; i++) L[i] = a[left + i];
    for (int i=0; i<n2; i++) R[i] = a[mid + i];
    L[n1] = INF;//番兵
    R[n2] = INF;
    int i=0;
    int j=0;
    for (int k=left; k<right; k++){
        if (L[i] <= R[j]){
            a[k] = L[i];
            i++;
        }
        else{
            a[k] = R[j];
            j++;
        }
        counter++;
    }
}
void mergeSort(int a[], int left, int right){
    if (left+1 < right){//要素が一つになるまで分割する
        int mid = (left + right)/2;
        mergeSort(a, left, mid);
        mergeSort(a, mid, right);
        merge(a, left, mid, right);
    }
}
int main(){
    int n; cin >> n;
    rep(i, n) cin >> a[i];
    veci b(n);
    mergeSort(a, 0, n);
    rep(i, n){
        if (i != 0) cout << " ";
        cout << a[i];
    }
    cout << endl;
    cout << counter << endl;
}


Measured memory_bytes: 8540
import collections
N = int(input())
S = [input() for _ in range(N)]
Scol = collections.Counter(S)

if 'AC' in Scol:
    AC = Scol['AC']
else:
    AC = 0

if 'WA' in Scol:
    WA = Scol['WA']
else:
    WA = 0

if 'TLE' in Scol:
    TLE = Scol['TLE']
else:
    TLE = 0

if 'RE' in Scol:
    RE = Scol['RE']
else:
    RE = 0

print('AC x '+str(AC))
print('WA x '+str(WA))
print('TLE x '+str(TLE))
print('RE x '+str(RE))
    


Measured memory_bytes: 16620
use std::io::BufRead;

fn run() {
    let stdin = std::io::stdin();
    let mut stdin = stdin.lock();
    let mut s = String::new();
    stdin.read_line(&mut s).unwrap();
    let n: usize = s.trim().parse().ok().unwrap();
    let mut ans: u64 = 0;
    let mut map = std::collections::BTreeMap::new();
    for _ in 0..n {
        s.clear();
        stdin.read_line(&mut s).unwrap();
        let mut s: Vec<char> = s.trim().to_owned().chars().collect();
        s.sort();
        let po = map.entry(s).or_insert(0);
        ans += *po;
        *po += 1;
    }
    println!("{}", ans);
}

fn main() {
    run();
}


Measured memory_bytes: 14588
#include <iostream>
#include <map>
#include <set>

int main()
{
  int N, M;
  std::map<std::string, int> s_plus, s_minus;
  std::set<std::string> keys;

  std::cin >> N;
  for(int i=0; i<N; i++) {
    std::string s;
    std::cin >> s;
    s_plus[s]++;
    keys.insert(s);
  }

  std::cin >> M;
  for(int i=0; i<M; i++) {
    std::string s;
    std::cin >> s;
    s_minus[s]++;
    keys.insert(s);
  }

  int max_plus = -M;
  for(auto &s: keys) {
    int tmp = s_plus[s] - s_minus[s];
    max_plus = std::max(max_plus, tmp);
  }

  if(max_plus < 0) {
    max_plus = 0;  // if minus, say no word.
  }

  std::cout << max_plus << std::endl;

  return 0;
}


Measured memory_bytes: 3604
#include <stdio.h>
int main() {
	int n,a[200000]={};
	long long sum=0;
	long long aNum[200001]={};
	scanf("%lld", &n);
	for (int i = 0; i < n; i++) {
		scanf("%d", &a[i]);
		aNum[a[i]]++;
	}
	for (int i = 0; i <= n; i++) {
		sum+=aNum[i]*(aNum[i]-1)/2;
	}
	//printf("sum:%lld\n", sum);
	for (int i = 0; i < n; i++) {
		printf("%lld\n", sum-aNum[a[i]]+1);
	}
	return 0;
}


Measured memory_bytes: 4864
#include <iostream>
#include <iomanip>
#include <cassert>
#include <algorithm>
#include <functional>
#include <vector>
#include <string>
#include <cstring>
#include <stack>
#include <queue>
#include <map>
#include <bitset>
#include <sstream>
#include <istream>
#include <cmath>
#include <cstdio>
#include <complex>

using namespace std;

#define vci vector<int>
#define vcs vector<string>
#define pb push_back
#define sz size()
#define mapii map<int, int>
#define mapci map<char, int>
#define mapsi map<string, int>
#define all(x) x.begin(), x.end()
#define minit(a, i) memset(a, i, sizeof(a));

#define for_(i, a, b) for (int i=(int)a; i<(int)b; i++)
#define for_d(i, a, b) for (int i=(int)a-1; i>=b; i--)
#define for_r(i, a, b, c) for (int i=(int)a; i<(int)b; i += c)
#define for_dr(i, a, b, c) for (int i=(int)a-1; i>=b; i -= c)
#define FOR(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)

template <class T> int __builtin_popcount(T n) { return n ? 1 + __builtin_popcount(n & (n - 1)) : 0; }

typedef long long ll;
typedef double D;

const int iINF = 2147483647;
const ll lINF = 9223372036854775807;



struct Point2D { 
	double x, y;
	Point2D (double a=0, double b=0) : x(a), y(b) {}
};

double dist2D(const Point2D& a, const Point2D& b) { return sqrt( (a.x-b.x)*(a.x-b.x) + (a.y-b.y)*(a.y-b.y) ); }



typedef double Weight;

struct Edge {
	int from, to;
	Weight weight;
	Edge(int f, int t, double w) : from(f), to(t), weight(w) { }
};

bool operator < (const Edge& e, const Edge& f) {
	return e.weight != f.weight ? e.weight > f.weight : 
			e.from != f.from ? e.from < f.from : e.to < f.to;
}

typedef vector<Edge> Edges;
typedef vector<Edges> Graph;

void Dijkstra(const Graph& g, int s, vector<Weight>& dist, vector<int>& prev) {
	int n = (int)g.size();
	dist.assign(n, iINF); dist[s] = 0;
	prev.assign(n, -1);
	priority_queue<Edge> q; q.push(Edge(-2, s, 0));
	
	while (!q.empty()) {
		Edge e = q.top(); q.pop();
		if (prev[e.to] != -1) continue;
		prev[e.to] = e.from;
		
		FOR (it, g[e.to]) {
			if (dist[it->to] > e.weight + it->weight) {
				dist[it->to] = e.weight + it->weight;
				q.push(Edge(it->from, it->to, e.weight + it->weight));
			}
		}
	}
}

vector<int> buildPath(const vector<int>& prev, int t) {
	vector<int> path;
	for (int u = t; u >= 0; u = prev[u]) path.pb(u);
	reverse(all(path));
	return path;
}

int main() {

	while (1) {
		int n; cin >> n;
		if (n==0) break;
		
		vector<Point2D> bils(n + 1, Point2D());
		for_(i, 0, n) {
			int b; cin >> b;
			cin >> bils[b].x >> bils[b].y;
		}
		
		Graph graph(n + 1, Edges());
		for_(i, 1, n + 1) {
			for_(j, 1, n + 1) {
				if (i==j) continue;
				Edge e(i, j, dist2D(bils[i], bils[j]));
				if (e.weight <= 50.0) graph[i].pb(e);
			}
		}
		
		int m; cin >> m;
		for_(rep, 0, m) {
			int s, g; cin >> s >> g;
		
			vector<Weight> dist;
			vector<int> prev;
			Dijkstra(graph, s, dist, prev);
		
			if (dist[g] == iINF) cout << "NA" << endl;
			else {
				vector<int> path = buildPath(prev, g);
				int ps = (int)path.sz;
				for_(i, 0, ps-1) {
					cout << path[i] << " ";
				}
				cout << path[ps-1] << endl;
			}
		}
	}
	
	
	
	return 0;
}

Measured memory_bytes: 1268
k = str(input())
d = int(input())

DP = [[[0 for _ in range(d)] for _ in range(2)] for _ in range(len(k)+1)]
DP[0][0][0] = 1

for i in range(len(k)):
    now = int(k[i])
    for j in range(2):
        for mod in range(d):
            for n in range(10):
                # 対象の数字未満が確定する場合
                if j==1 or (j==0 and n < now):
                    next_j = 1
                # 対象の数字とこの桁まで同じ場合
                elif n == now:
                    next_j = 0
                # 対象の数字よりも大きな値の場合
                else: 
                    continue

                n_mod = n % d
                next_mod = (mod + n_mod) % d
                DP[i+1][next_j][next_mod] = (DP[i+1][next_j][next_mod] + DP[i][j][mod]) % (10**9+7)

ans = (DP[len(k)][0][0] + DP[len(k)][1][0] -1) % (10**9+7)
print(ans)
# print(DP)

Measured memory_bytes: 64988
#include <iostream>
#include <cmath>
#include <vector>
#include <string>
#include <map>
#include <algorithm>
#include <limits>
#include <ios>
#include <iomanip>
#include <stdio.h>
#include <iomanip>
#include <queue>
#include <set>
using namespace std;

#define rep(i,N) for(int (i)=0; (i)<(N); (i)++)
#define revrep(i,N) for(int (i)=(N)-1; (i)>=0; (i)--)
#define dump(vec) for(int i = 0; i < (vec).size(); i++){cout << vec.at(i) << ",";}cout << endl

typedef long long ll;

int main(void)
{
    
    int N,X;
    cin >> N >> X;

    vector<int> L(N);
    rep(i,N){
        cin >> L.at(i);
    }

    int D = 0;
    int i = 0;
    
    int count = 1;
    for (int i = 0; i<L.size();i++){
        D = D + L.at(i);
        if (D <= X) {
            count++;
        } else {
            break;
        }
       
    }

    cout << count << endl;

    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<ll> vec;
typedef vector<vec> mat;
typedef pair<ll,ll> pll;
const ll mod=1e9+7;
//const ll mod=998244353;
const ll inf=5e15;
 
int main() {
  string s;
  cin >> s;
  ll n=s.size();
  string abc="ABC";
  mat dp(n+1,vec(4,0));
  dp[n][3]=1;
  for(ll i=n;i;i--) {
    for(ll j=3;j>-1;j--) {
      ll m=1;
      if(s[i-1]=='?') m=3;
      dp[i-1][j]=m*dp[i][j];
      if(j!=3&&(s[i-1]=='?'||s[i-1]==abc[j])) {
        dp[i-1][j]+=dp[i][j+1];
      }
      dp[i-1][j]%=mod;
    }
  }
  cout << dp[0][0] << endl;
}

Measured memory_bytes: 7424
#include<bits/stdc++.h>
using namespace std;
long long l,r;
int main()
{
	cin>>l>>r;
	long long r2=(int)(r/2019)*2019;
	if(r-l+1>=2019)
	{
		cout<<0;
		return 0;
	}
	if(r2>=l&&r2<=r)
	{
		cout<<0;
		return 0;
	}
	long long ans=1e18;
	for(int i=0;i<=r-l;i++)
	for(int j=i+1;j<=r-l;j++)
	{
		r2=(long long)(l+i);
		r2%=2019;
		long long r1=(long long)(l+j);
		r1%=2019;
		r2*=r1;
		r2%=2019;
		ans=min(ans,r2);
	}
	cout<<ans;
	return 0;
}


Measured memory_bytes: 256
/*
ID: alec3
LANG: C++14
PROG:
*/

#include <bits/stdc++.h>

#define check(x) cout<<(#x)<<": "<<x<<" ";
#define io ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define ss second
#define ff first
#define pb push_back
#define lb lower_bound
#define ub upper_bound
#define ld long double
#define all(c) (c).begin(), (c).end()
#define FOR(i, a, b) for (int i = a; i < b; i++)

typedef long long ll;
typedef unsigned long long ull;

using namespace std;

int pct(int x) { return __builtin_popcount(x); }
bool absComp (int i, int j) { return (abs(i) < abs(j)); }


int main()
{
    io;
    int k;
    cin >> k;

    string s;
    cin >> s;

    if (s.size() <= k)
        cout << s << endl;
    else {
        int c = s.size() - k + 1;
        s.erase(k, c);
        s += "...";
        cout << s << endl;
    }

    return 0;
}


Measured memory_bytes: 3660
#include <bits/stdc++.h>
typedef long long ll;
using namespace std;
#define repr(i,a,b) for(int i=a;i<b;i++)
#define rep(i,n) for(int i=0;i<n;i++)
#define invrepr(i,a,b) for(int i=b-1;i>=a;i--)
#define invrep(i,n) invrepr(i,0,n)
#define repitr(itr,a) for(auto itr=a.begin();itr!=a.end();++itr)
#define P pair<int,ll>
const ll MOD=998244353;
const int INF=1e9;
const double PI=acos(-1);


int main() {
    ios_base::sync_with_stdio(false);

    int n;
    cin >> n;
    vector<int> l(n);
    int s=0;
    rep(i,n) {
        cin >> l[i];
        s+=l[i];
    }
    bool flag=1;
    rep(i,n) {
        if (l[i]>=s-l[i]) flag=0;
    }
    if (flag) cout << "Yes" << endl;
    else cout << "No" << endl;


    return 0; 
}


Measured memory_bytes: 3644
import java.util.Scanner;

public class Main {

  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int x = sc.nextInt();
    int n = sc.nextInt();
    int[] array = new int[102];
    for(int i = 0; i < n; i++){
      array[sc.nextInt()]++;
    }
    int distance = 0;
    while(distance <= 100){
      if(x - distance == 0){
        System.out.println(x - distance);
        return;
      }

      if(array[x - distance] == 0){
        System.out.println(x - distance);
        return;
      } else if(array[x + distance] == 0){
        System.out.println(x + distance);
        return;
      }

      if(x + distance == 101){
        System.out.println(x + distance);
        return;
      }
      distance++;
    }
    //System.out.println(Math.abs(x + 1) > Math.abs(101 - x) ? 101 : 0);
  }
}

Measured memory_bytes: 36044
#include <iostream>
using namespace std;
#include<stdio.h>

/* 値を入れ替える関数 */
void swap (int *x, int *y) {
  int temp;    // 値を一時保存する変数

  temp = *x;
  *x = *y;
  *y = temp;
}


int partition (int array[], int left, int right) {
  int i, j, pivot;
  i = left;
  j = right + 1;
  pivot = left;

  do {
    do { i++; } while (array[i] < array[pivot]);
    do { j--; } while (array[pivot] < array[j]);
    if (i < j) { swap(&array[i], &array[j]); }
  } while (i < j);

  swap(&array[pivot], &array[j]);

  return j;
}

/* クイックソート */
void quick_sort (int array[], int left, int right) {
  int pivot;

  if (left < right) {
    pivot = partition(array, left, right);
    quick_sort(array, left, pivot-1);
    quick_sort(array, pivot+1, right);
  }
}

int main (void) {
    
    int n;
    
    cin >> n ;
    
    if(n%2 == 1){
        cout << 0 << endl;
    }
    else{
    
  int array[n];
  
  for(int i = 0; i < n; i++){
    cin >> array[i];
  }

  quick_sort(array, 0, n-1);

    cout << array[(n/2)] - array[n/2-1] << endl;
}

  return 0;
}

Measured memory_bytes: 640
# -*- coding: utf-8 -*-
def solve():
    N = int(input())
    A = sorted([int(input()) for _ in (None,)*N])
    if N == 1:
        return str(0)
    if N == 2:
        return str(abs(A[0]-A[1]))
    m = -(N>>1)
    b = N&1
    c1 = 2*sum(A[m+(1-b):]) - sum(A[m-1-b:m]) - 2*sum(A[:m-1-b]) + (1-b)*A[m]
    A = A[::-1]
    c2 = -2*sum(A[m+(1-b):]) + sum(A[m-1-b:m]) + 2*sum(A[:m-1-b]) - (1-b)*A[m]
    return str(max(c1,c2))

if __name__ == '__main__':
    print(solve())

Measured memory_bytes: 8184
#include <stdio.h>

#define MAX 200000
#define INFTY 2000000000

typedef long long llong;

int L[MAX/2+2],R[MAX/2+2];

llong merge(int A[],int n,int left,int mid,int right){
int n1,n2,i,j,k;
 llong c=0;
  n1=mid-left;
  n2=right-mid;
  for(i=0;i<n1;i++){
    L[i]=A[left+i];
  }
  for(i=0;i<n2;i++){
    R[i]=A[mid+i];
  }
  L[n1]=INFTY;
  R[n2]=INFTY;
  i=0;
  j=0;

  for(k=left;k<right;k++){
    if(L[i]<=R[j]){
      A[k]=L[i++];
    }
    else{
      A[k]=R[j++];
      c+=n1-i;
    }
  }
  return c;
}

llong mergeSort(int A[],int n,int left,int right){
int mid;
 llong v1,v2,v3;
  if(left+1<right){
    mid=(left+right)/2;
    v1=mergeSort(A,n,left,mid);
    v2=mergeSort(A,n,mid,right);
    v3=merge(A,n,left,mid,right);
    return v1+v2+v3;
  }
  else return 0;
}

int main(){
  int A[MAX],n,i;
  llong ans;
  scanf("%d",&n);
  for(i=0;i<n;i++){
    scanf("%d",&A[i]);
  }

  ans=mergeSort(A,n,0,n);
  printf("%lld\n",ans);
  
  return 0;
}



Measured memory_bytes: 3340
#include<stdio.h>
#include<iostream>
using namespace std;
const int N=2e5+10;
int a[N];
int main()
{
	int n,m,i,j;
	scanf("%d%d",&n,&m);
	for(i=1;i<=n;i++)
	{
		scanf("%d",&a[i]);
	}
	for(j=m+1;j<=n;j++)
	{
		if(a[j]>a[j-m])
		printf("Yes\n");
		else 
		printf("No\n");
	}
	return 0;
}


Measured memory_bytes: 4424
package main

import (
	"bufio"
	"os"
	"strconv"
	"strings"
	"fmt"
	"sort"
)

func main() {
	var n int
	fmt.Scan(&n)

	an := NextIntArray()

	sort.Ints(an)

	maxCount := 0
	for i := 0; i < len(an); {

		sameCount := 0
		for j := i; j < len(an) && an[i] == an[j]; j++ {
			sameCount++
		}

		plusCount := 0
		for j := i + sameCount; j < len(an) && an[i] == an[j]-1; j++ {
			plusCount++
		}

		minusCount := 0
		for j := i - 1; 0 <= j && an[i] == an[j]+1; j-- {
			minusCount++

		}

		sum := sameCount + plusCount + minusCount
		if maxCount < sum {
			maxCount = sum
		}
		i += sameCount

	}

	fmt.Println(maxCount)
}

// reader

var size = 100000
var rdr = bufio.NewReaderSize(os.Stdin, size)

func ReadLine() string {
	buf := make([]byte, 0, size)
	for {
		line, isPrefix, err := rdr.ReadLine()
		if err != nil {
			panic(err)
		}
		buf = append(buf, line...)
		if !isPrefix {
			break
		}
	}
	return string(buf)
}

func NextArray() []string {
	s := ReadLine()
	return strings.Split(s, " ")
}

func NextIntArray() []int {
	a := NextArray()
	na := make([]int, 0)

	for _, v := range a {
		if n, e := strconv.Atoi(v); e == nil {
			na = append(na, n)
		}
	}

	return na
}


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

using namespace std;

int main()
{
    double s;

    int a;

    cin>>a;

    if(a % 2 == 0)
    {

        s = ((double)a / 2) / (double) a;
    }
    else
        s = (((double) a + 1) / 2) / (double)a;

    printf("%.10lf\n", s);
}


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

int main(){
    int n; cin >> n;
    vector<int64_t> a(n);
    for (auto i = 0; i < n; i++) cin >> a[i];
    sort(a.begin(), a.end(), greater<>());

    int64_t ans = a[0]; int index = 1;
    for (auto i = 2; i < n; i++) {
        ans += a[index];
        if(i % 2) index++;
    }

    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 4736
// from https://atcoder.jp/contests/aising2019/submissions/3972253
#include<bits/stdc++.h>

#define rep(i,n) for(int i = 0; i < (n); i++)
#define ll long long

using namespace std;

vector<string> s;

const int dx[] = {1, 0, -1, 0};
const int dy[] = {0, -1, 0, 1};
int h, w;

bool is_in(int x, int y){
  return x>=0 && x<w && y>=0 && y<h;
}

bool check(int x, int y, int d){
  int nx = x + dx[d];
  int ny = y+dy[d];
  if(!is_in(nx, ny))return false;
  return (s[y][x]!=s[ny][nx]);
}

int main(){
  cin>>h>>w;
  s.resize(h);
  rep(i,h)cin>>s[i];

  ll result=0;
  ll bl,wh;
  set<pair<int, int>> used;
  rep(i, h)rep(j,w){

    bl=0;
    wh=0;
    queue<pair<int, int>> q;
    auto fp = make_pair(i,j);
    q.push(fp);
    used.insert(fp);
    while(!q.empty()){
      auto p = q.front();q.pop();
      int cy = p.first;
      int cx = p.second;
      if(s[cy][cx]=='#')bl++;
      else wh++;
      rep(k, 4){
        if(!check(cx, cy, k))continue;
        int nx=cx+dx[k];
        int ny = cy+dy[k];
        auto np = make_pair(ny, nx);
        if(used.count(np)==1)continue;
        used.insert(np);
        q.push(np);
      }
    }
//cout<<i<<j<<'|'<<wh<<' '<<bl<<endl;
    result += wh*bl;
  }

  cout<<result;

  return 0;
}

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

using namespace std;

using ll = long long;

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n;
    cin >> n;
    vector<ll> x(n), y(n);
    int parity = 0;
    for (int i = 0; i < n; i++) {
        cin >> x[i] >> y[i];
        parity += (abs(x[i]) + abs(y[i])) % 2;
    }

    if (parity != 0 && parity != n) {
        cout << -1 << endl;
        return 0;
    }

    int m = 31 + (parity == 0);
    vector<ll> d(m, 1);

    cout << m << endl;
    cout << d[0];
    for (int i = 1; i < m; i++) {
        d[i] = (1LL << (i % 31));
        cout << " " << d[i];
    }
    cout << endl;

    for (int i = 0; i < n; i++) {
        vector<int> ans(m, 0);

        ll u = x[i] + y[i] + (parity == 0);
        u = (u - 1 + (1LL << 31)) >> 1;
        for (int j = 0; j < 31; j++) {
            if (u & (1LL << j)) ans[j] |= 1;
        }

        ll v = x[i] - y[i] + (parity == 0);
        v = (v - 1 + (1LL << 31)) >> 1;
        for (int j = 0; j < 31; j++) {
            if (v & (1LL << j)) ans[j] |= 2;
        }

        for (int j = 0; j < m; j++) {
            cout << "LUDR"[ans[j]];
        }
        cout << endl;
    }
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <set>
#include <string>
#include <algorithm>

#define MAX 22

using namespace std;

char f[MAX][MAX];
int dx[8]={1,1,0,-1,-1,-1,0,1};   //右から
int dy[8]={0,1,1,1,0,-1,-1,-1};

int main(void)
{
	int h,w;
	int i1,i2,i3;
	int x,y;
	string s;
	int len;

	while(1){
		cin>>h>>w;
		if(h+w==0) break;

		for(i1=0;i1<h;i1++){
			for(i2=0;i2<w;i2++){
				cin>>f[i1][i2];
			}
		}


		set<string> p;
		set<string> ok;
		len=0;

		for(i1=0;i1<h;i1++){
			for(i2=0;i2<w;i2++){
				for(i3=0;i3<8;i3++){
					x=i2;
					y=i1;
					s="";
					while(1){

						s+=f[y][x];
						if(s.size()!=1 && p.find(s)!=p.end()) {
							ok.insert(s);
							len=max(len,(int)s.size());
						}
						else p.insert(s);
						
						x+=dx[i3];
						y+=dy[i3];
						if(x==w) x=0;
						if(y==h) y=0;
						if(x==-1) x=w-1;
						if(y==-1) y=h-1; 

						if(x==i2 && y==i1) break;
					}
				}
			}
		}

		set<string>::iterator it;
		set<string> ans;
		
		for(it=ok.begin();it!=ok.end();it++){
			if(len==(*it).size()) ans.insert((*it));
		}
		
		if(ans.empty()) cout<<"0"<<endl;
		else cout<<(*ans.begin())<<endl;

	}
	return 0;
}

Measured memory_bytes: 34608
import sys
input = sys.stdin.readline
from collections import *

def bfs(s):
    q = deque([s])
    dist = [-1]*N
    dist[s] = 0
    
    while q:
        v = q.popleft()
        
        for nv in G[v]:
            if dist[nv]==-1:
                dist[nv] = dist[v]+1
                q.append(nv)
        
    return dist

N = int(input())
G = [[] for _ in range(N)]

for _ in range(N-1):
    a, b = map(int, input().split())
    G[a-1].append(b-1)
    G[b-1].append(a-1)

d1 = bfs(0)
d2 = bfs(N-1)
c = 0

for i in range(N):
    if d1[i]<=d2[i]:
        c += 1

if c>N-c:
    print('Fennec')
else:
    print('Snuke')

Measured memory_bytes: 88516
import itertools
N = int(input())
A = list(map(int, input().split()))
B = list(map(int, input().split()))

maxi = 0

for i in range(N):
    if sum(A[0:i+1]) + sum(B[i:N]) > maxi:
        maxi = sum(A[0:i+1]) + sum(B[i:N])

print(maxi)


Measured memory_bytes: 9152
#include <iostream>

using namespace std;

int main(int argc, const char * argv[]) {
    
    int N;
    
    cin >> N;
    
    int x, count;
    int result = INT_MAX;
    
    for(int i=0; i<N; ++i)
    {
        cin >> x;
        count = 0;
        while(!(x%2))
        {
            x /= 2;
            count++;
        }
        if(count < result) result = count;
    }
    
    
    cout << result;
    
    return 0;
}


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

using namespace std;


int main(void)
{
    int N,K,Q; cin >> N >> K >> Q;
    int tmp = K;

    vector<int> cnt(N,0);

    for(int i = 0; i < Q; i++)
    {
        int a; cin >> a;
        cnt.at(a-1)++;
    }

    for(int i = 0; i < N; i++)
    {
        K = tmp;
        if(K - (Q-cnt.at(i)) > 0) cout << "Yes" << endl;
        else cout << "No" << endl; 
    }
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define rrep(ri,n) for(int ri = (int)(n-1); ri >= 0; ri--)
#define rep2(i,x,n) for(int i = (int)(x); i < (int)(n); i++)
#define rrep2(ri,x,n) for(int ri = (int)(n-1); ri >= (int)(x); ri--)
#define repit(itr,x) for(auto itr = x.begin(); itr != x.end(); itr++)
#define rrepit(ritr,x) for(auto ritr = x.rbegin(); ritr != x.rend(); ritr++)
#define ALL(x) x.begin(), x.end()
using ll = long long;
using namespace std;

int main(){
  int sx, sy;
  cin >> sx >> sy;
  int tx, ty;
  cin >> tx >> ty;
  int dx = tx - sx, dy = ty - sy;
  cout << string(dy, 'U');
  cout << string(dx, 'R');
  cout << string(dy, 'D');
  cout << string(dx, 'L');
  cout << 'L';
  cout << string(dy+1, 'U');
  cout << string(dx+1, 'R');
  cout << "DR";
  cout << string(dy+1, 'D');
  cout << string(dx+1, 'L');
  cout << "U" << endl;
  return 0;
}

Measured memory_bytes: 3632
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < n; i++)
#define REPS(i, x) for (int i = 1; i <= (int)(x); 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 FORS(i, m, n) for (int i = m; i <= n; i++)
#define bit(n) (1LL << (n))
#define INF 1e11
#define MOD (1000000007)
#define EPS 1e-9
#define ALL(v) v.begin(), v.end()
using namespace std;
typedef long long ll;
typedef long long int lli;
int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    lli A, B, Q;
    cin >> A >> B >> Q;
    vector<lli> S(A);
    vector<lli> Sm(A);
    vector<lli> T(B);
    vector<lli> Tm(B);
    vector<lli> x(Q);
    REP(i, A)
    {
        cin >> S[i];
        Sm[i] = S[i] * -1;
    }
    sort(ALL(S));
    sort(ALL(Sm));
    REP(i, B)
    {
        cin >> T[i];
        Tm[i] = T[i] * -1;
    }
    REP(i, Q)
    {
        cin >> x[i];
    }
    sort(ALL(T));
    sort(ALL(Tm));
    //find nearest temple
    vector<lli> nearT(A);
    vector<lli> nearS(B);
    REP(i, A)
    {
        auto t0 = lower_bound(ALL(T), S[i]);
        auto t1 = lower_bound(ALL(Tm), -S[i]);
        lli val0 = (t0 == T.end()) ? INF : *t0;
        lli val1 = (t1 == Tm.end()) ? INF : *t1;
        lli ans = min(val0 - S[i], S[i] + val1);
        nearT[i] = ans;
        //cout << ans << "\n";
        //cout << val0 << " " << val1 << " " << S[i] << " " << ans << "\n";
    } //300 300

    REP(i, B)
    {
        auto s0 = lower_bound(ALL(S), T[i]);
        auto s1 = lower_bound(ALL(Sm), -T[i]);
        lli val0 = (s0 == S.end()) ? INF : *s0;
        lli val1 = (s1 == Sm.end()) ? INF : *s1;

        lli ans = min(val0 - T[i], T[i] + val1);
        nearS[i] = ans;
        //cout << ans << "\n";
        // cout << val0 << " " << val1 << " " << T[i] << " " << ans << "\n";
    } //300 300

    REP(i, Q)
    {
        auto t0 = lower_bound(ALL(T), x[i]);
        auto t1 = lower_bound(ALL(Tm), -x[i]);

        auto s0 = lower_bound(ALL(S), x[i]);
        auto s1 = lower_bound(ALL(Sm), -x[i]);
        lli val0 = (t0 == T.end()) ? INF : (-x[i] + *t0 + nearS[t0 - T.begin()]);
        lli val1 = (t1 == Tm.end()) ? INF : (x[i] + *t1 + nearS[B - 1 - (t1 - Tm.begin())]);
        lli val2 = (s0 == S.end()) ? INF : (-x[i] + *s0 + nearT[s0 - S.begin()]);
        lli val3 = (s1 == Sm.end()) ? INF : (x[i] + *s1 + nearT[A - 1 - (s1 - Sm.begin())]);
        lli ans = min({val0, val1,
                       val2, val3});
        cout << ans << "\n";
    }
}

Measured memory_bytes: 6784