akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define ll long long int
#define ull unsigned long long int
#define ld long double
#define mod 1000000007
#define FT() int t; scanf("%d",&t); while(t--)
#define pb push_back
#define nl printf("\n")
#define fi(i,start,end) for(int i=start; i < (int)end ; ++i)
#define ip(n)   scanf("%d",&n)
#define mz(a)   memset(a,0,sizeof(a))
#define inpArr(A,n) fi(i,0,n)   ip(A[i]);
#define print(a)  for(auto i : a)   cout<<i<<" "; nl;
#define Fastio ios_base::sync_with_stdio(false); cin.tie(NULL);
using namespace std;
ll max(ll a,ll b) { return a>b?a:b;}
ll min(ll a,ll b) { return a<b?a:b;}
const int N = 1e5+1;
int a[N],b[N],c[N];
int n;
int dp[N][4];
int f(int n,int prev)
{
    if(n==0)
        return 0;
    if(dp[n][prev]!=-1)
        return dp[n][prev];
    int val;
    if(prev == 1)
        val = max(f(n-1,2) + b[n-1], f(n-1,3) + c[n-1]);
    else if(prev == 2)
        val = max(f(n-1,1) + a[n-1], f(n-1,3) + c[n-1]);
    else
        val =max(f(n-1,1) + a[n-1], f(n-1,2) + b[n-1]);
    dp[n][prev] = val;
    return val;
}   
void solve()
{   cin>>n;
    fi(i,0,n)
        cin>>a[i]>>b[i]>>c[i];
    memset(dp,-1,sizeof(dp));
    cout<<max(f(n,1),max(f(n,2),f(n,3)));
}
int main() {
    
    
        solve();
return 0;
}


Measured memory_bytes: 7680
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
int main(void){
    // Your code here!
    vector<int> v;
    long long N,K,tmp_num,ans=0;
    
    cin >> N >> K;
    
    for(int i=0;i<N;i++){
        cin >> tmp_num;
        v.push_back(tmp_num);
    }
    sort(v.begin(),v.end());
    
    for(int j=0;j<K;j++){
        ans = ans + v[j];
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3620
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <vector>
#include <map>
#include <set>
#include <unordered_set>
#include <unordered_map>
#include <cstring>
#include <string>
#include <algorithm>
#include <cmath>
#include <queue>
#include <ctime>
#include <random>
#include <queue>
  
using namespace std;
 
const int MAXN = 1e5 + 10;

int n, m;
set < int > kek;
vector < int > lol;

int main(){
#ifdef _DEBUG
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#endif
#ifndef _DEBUG
    /*freopen("trap.in", "r", stdin);
    freopen("trap.out", "w", stdout);*/
#endif
    cin >> n >> m;
    int a, b;
    for (int i = 0; i < m; i++){
        cin >> a >> b;
        if (a > b){
            swap(a, b);
        }
        if (a == 1){
            kek.insert(b);
        }
        if (b == n){
            lol.push_back(a);
        }
    }
    for (int i = 0; i < lol.size(); i++){
        if (kek.count(lol[i])){
            cout << "POSSIBLE";
            return 0;
        }
    }
    cout << "IMPOSSIBLE";
    return 0;
}

Measured memory_bytes: 5368
#include <bits/stdc++.h>
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(obj) (obj).begin(), (obj).end()
#define INF 1e9
#define LINF 1e18
typedef long long ll;


int main() {
    int N; cin >> N;
    vector<ll> P(N);
    REP(i,N){
        ll p; cin >> p;
        P[p-1] = i+1;
    }
    multiset<ll> ms;
    ms.insert(0);
    ms.insert(0);
    ms.insert(N+1);
    ms.insert(N+1);

    ll ans = 0;
    REPR(i,N-1){
        auto itr = ms.lower_bound(P[i]);//現在の座標より大きい最小の座標
        ll pos_r,pos_r2, pos_l,pos_l2;
        pos_r = *itr;
        itr++;
        pos_r2 = *itr;

        itr--;
        itr--;
        pos_l = *itr;
        
        itr--;
        pos_l2 = *itr;
        ans += (i+1) * (pos_l - pos_l2) * (pos_r - P[i]);
        ans += (i+1) * (pos_r2 - pos_r) * (P[i] - pos_l);

        ms.insert(P[i]);
    }
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 8736
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
#include <bits/stdc++.h>
#define rc(x) return cout<<x<<endl,0
#define pb push_back
#define mkp make_pair
#define in insert
#define er erase
#define fd find
#define fr first
#define sc second
typedef long long ll;
typedef long double ld;
const ll INF=0x3f3f3f3f3f3f3f3f;
const ll llinf=(1LL<<62);
const int inf=(1<<30);
const int nmax=2e5+50;
const int mod=1e9+7;
using namespace std;
int n,k,i;
ld a[nmax],rs;
int main()
{
	//freopen("sol.in","r",stdin);
	//freopen("sol.out","w",stdout);
	//mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
	ios_base::sync_with_stdio(false);cin.tie(0);cerr.tie(0);cout.tie(0);
	cin>>n>>k;
	for(i=1;i<=n;i++)
	{
		cin>>a[i];
		a[i]=(a[i]+1)/2;
		a[i]+=a[i-1];
	}
	for(i=k;i<=n;i++)
	{
		rs=max(rs,a[i]-a[i-k]);
	}
	cout<<fixed<<setprecision(10)<<rs<<endl;
	return 0;
}


Measured memory_bytes: 3456
import sys
import math
from collections import Counter
import itertools
import fractions
#from functools import reduce

# 入力を整数に変換して受け取る
def II(): return int(sys.stdin.readline())
def MI(): return map(int, sys.stdin.readline().split())
# 入力全てを整数に変換したものの配列を受け取る
def LI(): return list(map(int, sys.stdin.readline().split()))
# 入力全てを整数に変換して1引いたものの配列を受け取る
def LLI(rows_number): return [LI() for _ in range(rows_number)]
def SR(): return sys.stdin.readline().rstrip()

ascii_lowercase = 'abcdefghijklmnopqrstuvwxyz'
ascii_uppercase = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'
ascii_uppercase2 = 'ABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZ'

# リストを改行区切りで出力する
p2D = lambda x: print(*x, sep="\n")
p2E = lambda x: print(''.join(x))
p2S = lambda x: print(*x, sep=" ")

# ###########################################

a,b,c,k=MI()
ans=0

if k-a>=0:
    ans+=a
    k-=a
else:
    print(k)
    exit()

if k-b>=0:
    k-=b
else:
    print(ans)
    exit()

print(ans-k)



Measured memory_bytes: 10372
#include <bits/stdc++.h>
typedef long long ll;

int n, m;
std::vector<int> v;

inline bool cmp(int a, int b) {
	return a > b;
}

int main() {
	std::cin >> n >> m;
	for (int i = 1; i * i <= m; ++i) {
		if (!(m % i)) {
			v.push_back(i);
			v.push_back(m / i);	
		}
	}
	sort(v.begin(), v.end(), cmp);
	int S = v.size();
	for (int i = 0; i < S; ++i) {
		if(m / n >= v[i]) {
			printf("%d", v[i]);
			return 0;
		}
	}
	return 0;
} 

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, a) for (ll i = 0; i < (a); ++i)
#define pb push_back
#define all(v) v.begin(),v.end()
#define sort_1(v) sort(v.begin(),v.end())
#define sort_2(v) sort(v.begin(),v.end(),greater<ll>())
#define reverse(v) reverse(v.begin(),v.end())
typedef long long ll;
typedef long double la;
using namespace std;
 
int main(){
  ll a,b,c,k;
  cin >> a >> b>> c >> k;
  if(a+b <= k){
    cout << a + (k-(a+b))*(-1) << endl;
    return 0;
  }else{
    cout << k << endl;
    return 0;
  }
}

Measured memory_bytes: 3596
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vi=vector<int>;
using vvi=vector<vi>;
using vl=vector<ll>;
using vvl=vector<vl>;
using pii = pair<int,int>;
using pli = pair<ll,int>;
using pll = pair<ll,ll>;
using vpii = vector<pii>;
using vpli = vector<pli>;
using vpll = vector<pll>;

#define rep(i, n) for(int i=0;i<(int)n;i++)
#define rep2(i, s, n) for(int i=(s);i<(int)n;i++)
int INF=1e9+7;

int main() {
  int N,K;
  cin >> N >> K;
  vi A(N);
  rep(i,N) cin >> A[i];
  
  bool flag;
  rep(i,K) {
    flag=true;
    vi count(N+1);
    rep(j,N) {
      count[max(0,j-A[j])]++;
      count[min(N-1,j+A[j])+1]--;
    }
    A[0]=count[0];
    flag&=(A[0]==N);
    rep2(j,1,N) {
      A[j]=A[j-1]+count[j];
      flag&=(A[j]==N);
    }
    if(flag) break;
  }
  
  rep(i,N) cout << A[i] << ' ';
  cout << endl;
}

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

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

#define fst first
#define snd second
#define pb push_back

const int maxn=300005,maxm=1006;
const double pi=acos(-1.0);
//const ll mod=1000000007;
const ll mod=998244353;
const double eps=1e-8;

int n;

ll a,b,v,w,t;

void solve()
{
    b-=a;if(b<0) b=-b;
    if(v<=w) {printf("NO\n");return;}
    v-=w;
    if(v*t>=b) printf("YES\n");
    else printf("NO\n");
}

int main()
{
	int i,j;
	scanf("%lld %lld %lld %lld %lld",&a,&v,&b,&w,&t);
	solve();
    return 0;
}


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


#define int long long
#define ll long long
#define pb push_back
#define F first
#define S second
#define ld long double


using namespace std;


const int MAXN = 101*1001; ;

int n ;
string s,t;

bool check(int i)
{
    int j = 0 , k = n - i ;
    while(j<i)
    {
        if(t[j]!=s[k])
            return 0 ;
        j ++ ;
        k ++ ;
    }
    return 1 ;

}


int32_t main()
{
    ios::sync_with_stdio(0);cin.tie(0);
    cin >> n >> s >> t ;
    for(int i = n ; i ; i -- )
    {
        if(check(i))
            return cout<<2*n-i,0;
    }
    cout<<2*n;


}


Measured memory_bytes: 256
from collections import deque


def main():
    N, Q = map(int, input().split())
    g = [[] for _ in range(N)]
    score = [0] * N
    seen = [0] * N
    for _ in range(N-1):
        a, b = map(int, input().split())
        g[a-1].append(b-1)
        g[b-1].append(a-1)

    for _ in range(Q):
        a, b = map(int, input().split())
        score[a-1] += b

    q = deque()
    q.append(0)
    while q:
        v = q.pop()
        seen[v] += 1
        for i in g[v]:
            if seen[i]:
                continue
            q.append(i)
            score[i] += score[v]

    print(*score)


if __name__ == '__main__':
    main()

Measured memory_bytes: 128228
#include<bits/stdc++.h>
using namespace std;
#define INFTY 1<<20
typedef long long int ll;
const int MOD=1000000007;
using Graph = vector<vector<int>>;
using ipair = pair<ll,ll>;
bool operator< (const ipair a, const ipair b){return a.first < b.first;};
#define rep(i,n) for (int i = 0; i < (n); ++i)
ll gcd(ll a, ll b) { return b?gcd(b,a%b):a;}
ll lcm(ll a, ll b) { return a/gcd(a,b)*b;}

int main(){
string s,t;
cin>>s>>t;
int sz = s.length();
rep(i,sz){
  if(s[i]!=t[i]){
    cout<<"No";
    return 0;
  }
}
cout<<"Yes";



  return 0;
}

Measured memory_bytes: 3628
n=int(input())
h=[int(i) for i in input().split()]
for i in range(n-2,-1,-1):
    if h[i+1]<h[i]:
        h[i]-=1
flag=True
for i in range(n-1):
    if h[i]>h[i+1]:
        flag=False
if flag:
    print("Yes")
else:
    print("No")

Measured memory_bytes: 63984
#!/usr/bin/python3

import sys
# input = sys.stdin.readline
sys.setrecursionlimit(100000)
INF = float('inf')
MOD = 10**9+7
EPS = 10**-7

#N = int(input())
#A = [int(x) for x in input().split()]
#V = [[0] * 100 for _ in range(100)]

N, M = [int(x) for x in input().split()]
A = [int(x) for x in input().split()]

s = sum(A)
cnt = 0
for a in A:
    if a * (4 * M) >= s:
        cnt += 1

if cnt >= M :
    print('Yes')
else:
    print('No')

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N=1e5+10;
ll n,sum[N][21],ans;
int x,m,nex[N][21];
int main(){
    scanf("%lld%d%d",&n,&x,&m);
    for(int i=0;i<m;++i){
        nex[i][0]=1ll*i*i%m;
        sum[i][0]=nex[i][0];
    }
    for(int i=1;i<=20;++i){
        for(int j=0;j<m;++j){
            nex[j][i]=nex[nex[j][i-1]][i-1];
            sum[j][i]=sum[j][i-1]+sum[nex[j][i-1]][i-1];
        }
    }
    n--;
    ll a=n/(1<<20),b=n%(1<<20);
    ll ans=x;int now=x;
    for(int i=1;i<=a;++i){
        ans+=sum[now][20];
        now=nex[now][20];
    }
    for(int j=19;j>=0;--j){
        if(b>>j&1){
            ans+=sum[now][j];
            now=nex[now][j];
        }
    }
    printf("%lld\n",ans);
    return 0;
}


Measured memory_bytes: 28432
h,w,a,b = map(int,input().split())

MOD = 1000000007
fac = [1]
inv = [1]
for i in range(1,200010):
	fac.append(fac[i-1]*i%MOD)
	inv.append(pow(fac[i],MOD-2,MOD))

ans = 0

for i in range(b+1,w+1):
	ans += fac[h-a+i-2]*inv[h-a-1]*inv[i-1]*fac[a+w-i-1]*inv[a-1]*inv[w-i]%MOD
	ans %= MOD

print(ans)

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

int main()
{
	int n[3];
	for(int i=0;i<3;i++){
		cin >> n[i];
	}
	sort(n,n+3);
	cout << n[2]*10+n[1]+n[0] << endl;
	return 0;
}

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

using namespace std;
int a[100005][4];
int dp[100005][4];
int n;

int func(int ind, int flag) {

	if (ind == n) return 0;

	if (dp[ind][flag] != -1) return dp[ind][flag];

	int maxi = 0;
	if (flag == 0) {
		maxi = max(maxi, a[ind][1] + func(ind + 1, 1));
		maxi = max(maxi, a[ind][2] + func(ind + 1, 2));
		maxi = max(maxi, a[ind][3] + func(ind + 1, 3));
	}
	else if (flag == 1) {
		maxi = max(maxi, a[ind][2] + func(ind + 1, 2));
		maxi = max(maxi, a[ind][3] + func(ind + 1, 3));
	}
	else if (flag == 2) {
		maxi = max(maxi, a[ind][1] + func(ind + 1, 1));
		maxi = max(maxi, a[ind][3] + func(ind + 1, 3));
	}
	else {
		maxi = max(maxi, a[ind][1] + func(ind + 1, 1));
		maxi = max(maxi, a[ind][2] + func(ind + 1, 2));
	}

	return dp[ind][flag] = maxi;
}

int main() {

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

	memset(dp, -1, sizeof dp);

	cout << func(0, 0);

	return 0;
}



Measured memory_bytes: 14504
#include<bits/stdc++.h>
using namespace std;
#define INF (1<<28)
#define DEKAI 1000000007
#define lp(i,n) for(int i=0;i<n;i++)
#define int long long
int ans[100010];

signed main(){
  int n;
  cin>>n;
  vector<pair<int,int> > l[100010];
  lp(i,n-1){
    int a,b,c;
    cin>>a>>b>>c;
    l[a].push_back({b,c});
    l[b].push_back({a,c});
  }
  queue<pair<int,int> > q;
  q.push({1,0});
  while(!q.empty()){
    int now=q.front().first;
    int dis=q.front().second;
    q.pop();
    lp(i,l[now].size()){
      int next=l[now][i].first;
      int d=l[now][i].second;
      if(ans[next]==0){
        if((dis+d)%2==0) ans[next]=1;
        else ans[next]=2;
        q.push({next,dis+d});
      }
    }
  }
  int sum=0;
  lp(i,n){
    sum+=ans[i+1]-1;
    if(i==n-1){
      if(sum==0)cout<<1<<endl;
      else if(sum==n) cout<<0<<endl;
      else cout<<ans[i+1]-1<<endl;
      break;
    }
    cout<<ans[i+1]-1<<endl;
  }
  return 0;
}

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

#define pb push_back
#define mp make_pair

typedef long long ll;

const int inf = 1e9;
const ll linf = 1e18;
const ll mod = 1e9 + 7;

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

  deque<int> que;
  for(int i = 0; i < n; i++){
    int a;
    cin >> a;

    if(i%2) que.push_front(a);
    else que.push_back(a); 
  }

  if(n%2) reverse(que.begin(), que.end());

  for(auto u : que){
    cout << u << " ";
  }
  cout << endl;

  return 0;
}


Measured memory_bytes: 2944
X, N = map(int, input().split())

if N != 0:
    p = [int(i) for i in input().split()]

ans = 0
if N == 0:
    ans = X
else:

    for i in range(N):
        key = X - i

        if key in p:
            pass
        else:
            ans = key
            break

        key = X + i

        if key in p:
            pass
        else:
            ans = key
            break

print(ans)



Measured memory_bytes: 9188
N=int(input())

C0=0
C1=0
C2=0
C3=0

for n in range(N):
    S=input()
    if S=="AC":
        C0+=1
    elif S=="WA":
        C1+=1
    elif S=="TLE":
        C2+=1
    else:
        C3+=1   

print("AC x "+str(C0))
print("WA x "+str(C1))
print("TLE x "+str(C2))
print("RE x "+str(C3))

Measured memory_bytes: 9208
#include <iostream>
#include <set>
#include <string>

using namespace std;

int main() {
  int n;
  cin >> n;
  
  string s;
  set<string> seen;
  cin >> s;
  char c = s[s.size() - 1];
  bool ok = true;
  seen.insert(s);
  for (int i = 1; i < n; i++) {
    cin >> s;
    if ((s[0] != c) || (seen.find(s) != seen.end())) {
      ok = false;
    }
    seen.insert(s);
    c = s[s.size() - 1];
  }
  cout << (ok ? "Yes" : "No");

}


Measured memory_bytes: 256
#include <stdio.h>

int N;
char S[1123];
int memo[1123][8];

int to_num(int i) {
	if (S[i] == 'J') { return 1; }
	if (S[i] == 'O') { return 2; }
	if (S[i] == 'I') { return 4; }
}
// dp(i,s) = i??\????????????????????????????????????s?????¨??????i??\????????§???????????¨?????°
int do_dp(int i, int s) {
	if (i >= N) { return 1; }
	if (memo[i][s] != 0) { return memo[i][s]; }
	int tmp = 0;
	for (int j = 1; j <= 7; ++j) {
		if ((s&j) && (j&to_num(i))) {
			tmp += do_dp(i + 1, j);
			tmp %= 10007;
		}
	}
	return memo[i][s] = tmp;
}

int main(void) {
	scanf("%d", &N);
	scanf("%s", &S);

	printf("%d\n", do_dp(0, 1));
	return 0;
}

Measured memory_bytes: 2816
#include <bits/stdc++.h>
using namespace std;
 
#define REP(i, n) for (ll i = 0; i < n; i++)
#define REPR(i, n) for (ll i = n; i >= 0; i--)
#define FOR(i, m, n) for (ll i = m; i < n; i++)
#define FORR(i, m, n) for (ll i = m; i >= n; i--)
#define REPO(i, n) for (ll i = 1; i <= n; i++)
#define ll long long
#define INF (ll)1 << 60
#define MINF (-1 * INF)
#define ALL(n) n.begin(), n.end()
#define MOD 1000000007
#define P pair<ll, ll>

ll powmod(ll a, ll b) {
    a %= MOD;
    ll res = 1;
    while (b > 0) {
        if (b % 2 == 1)res = res * a % MOD;
        a = a * a % MOD;
        b /= 2;
    }
    return res;
}
ll n, k, z, ma;
bool ze, p;
int main() {
    cin >> n >> k;
    vector<ll> s(n), t1, t2, v1, v2;
    REP(i, n){
        cin >> s[i];
        if (s[i] == 0) z++;
        else if (s[i] < 0) t2.push_back(s[i] * -1);
        else t1.push_back(s[i]);
    }
    sort(ALL(t1));
    sort(ALL(t2));
    ll t2s = t2.size(), t1s = t1.size();
    if (z > 0) ze = true;
    v1.push_back(0);
    v2.push_back(0);
    //正判定
    REP(i, k + 1){
        //cout << i << " " << k - i << " " << t1s << " " << t2s << endl;
        if (i % 2 == 1) continue;
        if (t1s < k - i) continue;
        if (t2s < i) continue;
        p = true;
        ma = max(i, ma);
    }
    //正が作れない
    if(!p){
        if(ze){
            cout << 0 << endl;
            return 0;
        }
        vector<ll> l;
        REP(i, t1s){
            l.push_back(t1[i]);
        }
        REP(i, t2s){
            l.push_back(t2[i]);
        }
        sort(ALL(l));
        ll ans = 1;
        REP(i, k){
            ans *= l[i];
            ans %= MOD;
        }
        cout << (MOD * 2 - ans) % MOD << endl;
        return 0;
    }
    vector<P> l;
    REP(i, t1s){
        l.push_back(P(t1[i], 1));
    }
    REP(i, t2s){
        l.push_back(P(t2[i], -1));
    }
    sort(ALL(l), greater<P>());
    ll ans = 1, cnt = 0, m1 = -1, p1 = -1, m2 = -1, p2 = -1;
    REP(i, k){
        ans *= l[i].first;
        ans %= MOD;
        if (l[i].second == -1) cnt++;
        if (l[i].second == -1) m1 = l[i].first;
        if (l[i].second == 1) p1 = l[i].first;
    }
    if(cnt % 2 == 0){
        cout << ans << endl;
        return 0;
    }
    FOR(i, k, n){
        if (m2 == -1 and l[i].second == -1) m2 = l[i].first;
        if (p2 == -1 and l[i].second == 1) p2 = l[i].first;
    }
    if(m1 == -1 or p2 == -1){
        ans = ans * m2 % MOD * powmod(p1, MOD - 2) % MOD;
    }
    else if(m2 == -1 or p1 == -1){
        ans = ans * p2 % MOD * powmod(m1, MOD - 2) % MOD;
    }
    else if(p1 * p2 >= m1 * m2) {
        ans = ans * p2 % MOD * powmod(m1, MOD - 2) % MOD;
    }
    else{
        ans = ans * m2 % MOD * powmod(p1, MOD - 2) % MOD;
    }
    cout << ans << endl;
}


Measured memory_bytes: 10556
#include<bits/stdc++.h>
using namespace std;
const int maxn=3e5+5;
const int mod=1e9+7;
typedef long long ll;
ll a[maxn];
int main(){
	int n;
	cin>>n;
	ll sum=0;
	for(int i=0;i<n;i++)
	scanf("%lld",&a[i]);
	for(int i=0;i<=60;i++){
		int cnd=0;
		for(int j=0;j<n;j++){
			if((a[j]>>i)&1) cnd++;
		}
		sum=(sum+(1ll<<i)%mod*cnd%mod*(n-cnd))%mod;
	}
	cout<<sum%mod;
	return 0;
} 

Measured memory_bytes: 2560
#include <iostream>
#include <algorithm>
#include <cstdio>

using namespace std;

int A[101], n, cnt = 0;

void print () {
  for (int i = 0; i < n; i++)
    if (i == n - 1)
      cout << A[i] << endl;
    else
      cout << A[i] << " ";
}

void BubbleSort () {
  bool flag = true;

  while (flag) {
    flag = false;

    for (int j = n - 1; j >= 1; j--) {
      if (A[j] < A[j - 1]) {
        swap(A[j], A[j - 1]);
        flag = true;
        cnt++;
      }
    }
  }
}

int main () {
  cin >> n;

  for (int i = 0; i < n; i++)
    cin >> A[i];

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

  print();
  cout << cnt << endl;

  return 0;
}



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

using namespace std;

int main()
{
   char a,b;
    cin>>a>>b;
    if(a=='H'&& b=='H')
    {
        cout<<"H"<<"\n";
    }
    else if(a=='H'&& b=='D')
    {
        cout<<"D"<<"\n";
    }
    else if(a=='D'&& b=='H')
    {
        cout<<"D"<<"\n";
    }
    else
    {
       cout<<"H"<<"\n";
    }
    return 0;
}


Measured memory_bytes: 256
#include <stdio.h>

int main(void){

	int i, j, n, a;
	int card[5][16] = {0};

	scanf("%d", &n);			/* ?????£??????????????????????????? */
		for(i = 1;i <= n;i++){
			char c;
		scanf(" %c %d", &c, &a);
			if(c == 'S') {		/* ????????????????????? */
				card[0][a-1]=1;
			}

		else if(c == 'H'){		/* ?????????????????? */
			card[1][a-1]=1;
		}

		else if(c == 'C'){		/* ?????????????????? */
			card[2][a-1]=1;
		}

		else{					/* ??????????????????????????????????????? */
			card[3][a-1]=1;
		}
	}
	for(i = 0;i < 4;i++) {
		for(j = 0;j < 13;j++){
			char m;
			if(card[i][j] == 0){	/* ?????£???????????????????????¶??????4??13???????¬??????????????¨???? */
				if(i == 0){
					m='S';			/* ??????????????????????????§?????? */
				}

				else if(i == 1){
					m='H';			/* ???????????????????????§?????? */
				}

				else if(i == 2){
					m='C';			/* ???????????????????????§?????? */
				}

				else{
					m='D';			/* ???????????????????????§?????? */
				}
				printf("%c %d\n", m, j + 1);
			}
		}
	}

	return 0;
}

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

int main(){
  char c;
  cin >> c;
  if(c == 'a' || c == 'e' || c == 'i' || c == 'o' || c == 'u'){
    cout << "vowel" << endl;
  } else {
    cout << "consonant" << endl;
  }
}

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

int main()
{
    int n, k;
    cin >> n >> k;
    int cnt[n + 5] = {0};
    for (int i = 1; i <= k; i++)
    {
        int d;
        cin >> d;
        for (int j = 1; j <= d; j++)
        {
            int a;
            cin >> a;
            cnt[a]++;
        }
    }
    int ans = 0;
    for (int i = 1; i <= n; i++)
        if (!cnt[i])
            ans++;
    cout << ans;
}

Measured memory_bytes: 3624
#include <cstdio>
#include <cstring>
#include <cctype>
#include <algorithm>
#include <vector>
inline int getint()
{
	int r = 0,s = 0;char c = getchar();for(;!isdigit(c);c = getchar()) s |= c == '-';
	for(;isdigit(c);c = getchar()) r = (((r << 2) + r) << 1) + (c ^ '0');return s ? -r : r;
}
const int N = 2020;
int head[N],next[N << 1],to[N << 1],tot = 1;
inline void addedge(int u,int v)
{
	next[++tot] = head[u];to[tot] = v;head[u] = tot;
	next[++tot] = head[v];to[tot] = u;head[v] = tot;
}
int S[N],T[N],cnt[N];
std::vector<int> path[N],edge[N];
int n,m;
inline int dfs(int u,int f,int de,int id)
{
	if(u == de) return 1;
	for(int i = head[u],v = to[i];~i;v = to[i = next[i]])
	{
		if(v == f) continue;
		++cnt[i >> 1];path[id].push_back(i);edge[i >> 1].push_back(id);
		if(dfs(v,u,de,id)) return 1;
		--cnt[i >> 1];path[id].pop_back();edge[i >> 1].pop_back();
	}
	return 0;
}
int vis[N << 1],used[N];
int main()
{
	memset(head,-1,sizeof(head));
	n = getint(),m = getint();
	for(int i = 1;i < n;i++) addedge(getint(),getint());
	for(int i = 1;i <= m;i++)
	{
		S[i] = getint(),T[i] = getint();
		dfs(S[i],0,T[i],i);
	}
	int ans = 0;
	for(int i = 1;i < n;i++) ans += std::min(cnt[i],2);
	printf("%d\n",ans);
	while(1)
	{
		int p = 0,q;
		for(int i = 1;i < n;i++) if(cnt[i] == 1 && vis[i << 1 | 1] ^ vis[i << 1]) {p = i;break;}
		if(!p) for(int i = 1;i < n;i++) if(cnt[i] >= 2) {p = i;break;}
		if(!p) break;
		for(int i = 0,sz = edge[p].size();i < sz;i++) if(!used[edge[p][i]]) {q = edge[p][i];break;}
		used[q] = 1;
		for(int i = 0,sz = path[q].size(),u = path[q][i];i < sz;u = path[q][++i])
		{
			if((u >> 1) != p) continue;
			if(vis[u])
			{
				std::swap(S[q],T[q]);
				for(int j = 0;j < sz;++j) path[q][j] ^= 1;
			}
			for(int j = 0,v = path[q][j];j < sz;v = path[q][++j]) --cnt[v >> 1],vis[v] = 1;
			break;
		}
	}
	for(int i = 1;i <= m;i++) printf("%d %d\n",S[i],T[i]);
	return 0;
}


Measured memory_bytes: 15488
// finish date: 2018/01/24
#include <iostream>
#include <cmath>
#include <vector>
#include <bitset>
#include <algorithm>
#include <stack>
#include <map>
#include <climits>

using namespace std;

#define FOR(i, a, b) for(int (i)=a;(i)<(b);(i)++)
#define rep(i, n)  FOR(i,0,n)
#define ll long long
#define vi vector<int>
#define vvi vector<vector<int>>
#define vl vector<ll>
#define vvl vector<vector<ll>>
#define vb vector<bool>
#define vvb vector<vector<bool>>
#define bigmod 1000000007
#define INF 500000000


int main() {
    int N, M;
    cin >> N >> M;
    int time = 1900 * M + (N - M) * 100;
    cout << time * (1 << M) << endl;


    return 0;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, n) for(ll i=0; i<(n); ++i)
#define rep1(i,n) for(ll i=1; i<=(n); ++i)
#define repi(i,a,b) for(ll i=a; i<=(b); ++i)
#define rrep(i,n) for(ll i=(n-1); i>=0; --i)
#define ALL(obj) (obj).begin(), (obj).end()
#define RALL(obj) (obj).rbegin(), (obj).rend()
#define pb push_back
#define mp make_pair
#define to_s to_string
#define sz(v) (int)v.size()
#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() )
#define pr(x) cout<<(x)<<'\n'
#define debug(x) cout << #x << ": " << (x) << '\n'
using namespace std;
using ll = long long;
using Edge = pair<ll,ll>;
using Graph = vector<vector<Edge>>;
typedef pair<ll,ll> P;
struct aaa{aaa(){ cin.tie(0); ios::sync_with_stdio(0); cout<<fixed<<setprecision(20);};}aaaaaaa;
int MOD = 1e9 + 7;
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
ll lcm(ll a,ll b){return (a*b)/gcd(a,b);}
ll devc(ll x, ll y){return 1 + (x-1)/y;}

string solve(string S){
    sort(ALL(S));
    bool judge = true;
    if(!(S[0] == S[1] && S[2] == S[3])) judge = false;
    if(S[1]==S[2]) judge = false;
    if(judge) return "Yes";
    return "No";
}

int main(){
    string S; cin >> S;
    pr(solve(S));
    return 0;
}

Measured memory_bytes: 256
N, M  = map(int, input().split())
pS = [input().split() for a in range(M)]

total = [0 for a in range(N)]
correct = [0 for a in range(N)]
for ptext, S in pS:
  p = int(ptext)-1
  if S == 'WA' and correct[p] == 0:
    total[p] += 1
  elif S == 'AC':
    correct[p] = 1

for i in range(N):
  if correct[i] == 0:
    total[i] = 0
print(sum(correct), sum(total))

Measured memory_bytes: 33896
import java.io.*;
import java.util.StringTokenizer;

public class Main {

    public static void main(String[] args) throws IOException {
        init();
        int m1 = nextInt(), d1 = nextInt(), m2 = nextInt(), d2 = nextInt();
        if (m2 == m1 + 1) System.out.println('1');
        else System.out.println('0');
    }

    //Input Reader
    private static BufferedReader reader;
    private static StringTokenizer tokenizer;

    private static void init() {
        reader = new BufferedReader(new InputStreamReader(System.in));
        tokenizer = new StringTokenizer("");
    }

    private static String next() throws IOException {
        String read;
        while (!tokenizer.hasMoreTokens()) {
            read = reader.readLine();
            if (read == null || read.equals(""))
                return "-1";
            tokenizer = new StringTokenizer(read);
        }

        return tokenizer.nextToken();
    }

    private static int nextInt() throws IOException {
        return Integer.parseInt(next());
    }

//    private static long nextLong() throws IOException {
//        return Long.parseLong(next());
//    }
//
//    //    Get a whole line.
//    private static String line() throws IOException {
//        return reader.readLine();
//    }
//
//    private static double nextDouble() throws IOException {
//        return Double.parseDouble(next());
//    }
}

Measured memory_bytes: 22612
#include<bits/stdc++.h>
using namespace std;
const int N = 1e5 + 1;
int n , b[N];
long long dp[101][N] , a[N] , w , INF = 1e18L + 10; 
int sum = 0;
int main(){
    scanf("%d%lld", &n , &w);
    for(int i = 1 ; i <= n ; i++){
        scanf("%lld%d", &a[i] , &b[i]);
        sum += b[i];
    }
    for(int i = 0 ; i <= n ; i++)
        for(int j = 0 ; j <= sum ; j++)
            dp[i][j] = INF;
    for(int i = 0 ; i <= n ; i++)
        dp[i][0] = 0;
    for(int i = 1 ; i <= n ; i++){
        for(int j = 0 ; j <= sum ; j++){
            if(j >= b[i])
            dp[i][j] = min(dp[i][j] , dp[i - 1][j - b[i]] + a[i]);
            dp[i][j] = min(dp[i][j] , dp[i - 1][j]);
        }
    }
    int ans = 0;
     for(int i = 1 ; i <= n ; i++){
        for(int j = 0 ; j <= sum ; j++){
            if(dp[i][j] <= w)
                ans = max(ans , j);
            }
    }
    cout<<ans;
    return 0;
}

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

#define int long long

vector<int> bfs(vector<vector<int> > &G, int s) {  
  vector<int> d(G.size(), -1);  
  queue<int> Q;
  Q.push(s);
  d[s] = 0;
  while ( !Q.empty() ) {
    int v = Q.front(); Q.pop();

    for ( int u : G[v] ) {
      if ( d[u] >= 0 ) continue;
      d[u] = d[v]+1;
      Q.push(u);      
    }    
  }

  return d;  
}

signed main() {
  cin.tie(0);
  ios_base::sync_with_stdio(0);
  cout << fixed << setprecision(12);

  int N, M, s, t;
  cin >> N >> M >> s >> t;
  s--; t--;

  vector<vector<int> > G(N);
  for ( int i = 0; i < M; i++ ) {
    int x, y;
    cin >> x >> y;
    x--; y--;
    G[x].emplace_back(y);
    G[y].emplace_back(x);    
  }

  vector<int> ds = bfs(G, s);
  vector<int> dt = bfs(G, t);
  vector<int> cnts(N, 0), cntt(N, 0);  
  for ( int i = 0; i < N; i++ ) {
    if ( ds[i] >= 0 ) cnts[ds[i]]++;
    if ( dt[i] >= 0 ) cntt[dt[i]]++;    
  }

  int ans = 0;
  int mi = ds[t];
  for ( int i = 0; i < N; i++ ) {    
    if ( mi-i-2 >= 0 ) ans += cnts[i] * cntt[mi-i-2];    
  }

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



Measured memory_bytes: 13560
#include <iostream>
using namespace std;
 
int main() {
while(1){
	int a[5];
	cin>>a[0];
	if(a[0]==0){break;}
	for(int i = 1;i<5;i++){cin>>a[i];}
	int g[3];
	for(int i = 0;i<3;i++){g[i]=0;}
	for(int i = 0;i<5;i++){
		g[a[i]-1]++;
	}
	int aiko = 0;
	for(int i = 0;i<3;i++){
		if(g[i]==0){aiko++;}
	}
	if(aiko==0||aiko ==2){
		for(int i = 0;i<5;i++){cout<<3<<endl;}
	}
	else{
		int kati;
		if(g[0]==0){
			kati = 2;
		}
		else if(g[1]==0){
			kati = 3;
		}
		else{
			kati = 1;
		}
		for(int i = 0;i<5;i++){
			if(a[i]==kati){cout << 1<<endl;}
			else{cout << 2 << endl;}
		}
	}
}
	return 0;
}

Measured memory_bytes: 1160
import java.util.*;
import java.io.*;
import java.math.*;
public class Main {
    public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		PrintWriter ou = new PrintWriter(System.out);
		int[] a = new int[3];
		for(int i = 0 ; i < 3 ; i++) a[i] = Integer.parseInt(sc.next());
		sc.close();
		Arrays.sort(a);
		ou.println(a[2] - a[0]);
		ou.flush();
	}
}

Measured memory_bytes: 35756
#include<iostream>
#include<algorithm>
#include<string>
#include<vector>
#include<math.h>
using namespace std;
int main(){
    int n,y;
    cin>>n>>y;
    int xx=-1;
    int yy=-1;
    int zz=-1;
    for(int i =0;i<=n;i++){
        for(int j = 0;j<=n-i;j++){
            if((10000*i+5000*j+1000*(n-i-j))==y){
                xx=i;
                yy=j;
                zz=n-i-j;
                break;
            }
        }
    }
    cout<<xx<<" "<<yy<<" "<<zz<<endl;
    return 0;
}



Measured memory_bytes: 256
#include "iostream"
#include "climits"
#include "list"
#include "queue"
#include "stack"
#include "set"
#include "functional"
#include "algorithm"
#include "string"
#include "map"
#include "unordered_map"
#include "unordered_set"
#include "iomanip"
#include "cmath"
#include "random"
#include "bitset"
#include "cstdio"
#include "numeric"
#include "cassert"
#include "ctime"

using namespace std;

constexpr long long int MOD = 1000000007;
//constexpr int MOD = 1000000007;
//constexpr int MOD = 998244353;
//constexpr long long int MOD = 998244353;
constexpr double EPS = 1e-9;

//int N, M, K, H, W, L, R;
long long int N, M, K, H, W, L, R;


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

	cin >> N;
	cout << (1000000000 - N) % 1000 << endl;
}


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

class Program
{
    static string InputPattern = "InputX";

    static List<string> GetInputList()
    {
        var WillReturn = new List<string>();

        if (InputPattern == "Input1") {
            WillReturn.Add("abaccaba");
            //Yes
        }
        else if (InputPattern == "Input2") {
            WillReturn.Add("hthth");
            //No
        }
        else {
            string wkStr;
            while ((wkStr = Console.ReadLine()) != null) WillReturn.Add(wkStr);
        }
        return WillReturn;
    }

    static void Main()
    {
        List<string> InputList = GetInputList();
        string w = InputList[0];

        var CntDict = new Dictionary<char, int>();
        foreach (char EachChar in w) {
            if (CntDict.ContainsKey(EachChar)) {
                CntDict[EachChar]++;
            }
            else CntDict[EachChar] = 1;
        }
        if (CntDict.All(X => X.Value % 2 == 0)) {
            Console.WriteLine("Yes");
        }
        else Console.WriteLine("No");
    }
}


Measured memory_bytes: 3288
N=int(input())
T,A=map(int,input().split())
H=[int(i) for i in input().split()]
d=10**4
n=0
for j in range(N):
  dj=abs(A-(T-H[j]*0.006))
  if dj<d:
    d=dj
    n=j
print(n+1)
  

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

int main(){
  int N;
  vector<long long> luca(90);
  cin >> N;
  luca[0]=2; luca[1]=1;
  for(int i=2;i<=N;++i){
    luca[i]=luca[i-1]+luca[i-2];
  }

  cout << luca[N] << endl;
}

Measured memory_bytes: 256
#include<stdio.h>
int main(){
int a,b,c;
scanf("%d %d %d",&a,&b,&c); 
if(a<=b&&b<=c){
printf("%d %d %d\n",a,b,c);
}else if(a<=c&&c<=b){
printf("%d %d %d\n",a,c,b);
}else if(b<=a&&a<=c){
printf("%d %d %d\n",b,a,c);
}else if(b<=c&&c<=a){
printf("%d %d %d\n",b,c,a);
}else if(c<=a&&a<=b){
printf("%d %d %d\n",c,a,b);}
else if(c<=b&&b<=a){
printf("%d %d %d\n",c,b,a);
}
return 0;
}


Measured memory_bytes: 2096
N = int(input())
t = [0] * (N + 1)
x = [0] * (N + 1)
y = [0] * (N + 1)
for i in range(1, N + 1):
    t[i], x[i], y[i] = map(int, input().split())
for i in range(1, N + 1):
    if t[i] - t[i - 1] < abs(x[i] - x[i - 1]) + abs(y[i] - y[i - 1]):
        print('No')
        exit()
    elif t[i] % 2 != (x[i] + y[i]) % 2:
        print('No')
        exit()
print('Yes')


Measured memory_bytes: 11636
#include<bits/stdc++.h>
#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define lli long long int
#define ulli unsigned long long int
#define ff first
#define ss second
#define mp make_pair
#define pb push_back
#define pf pop_front()
#define lb lower_bound
#define ub upper_bound
#define bs binary_search
#define loopl(i,a,b) for(lli i=a;i<b;i++) 
#define loop(i,a,b) for(int i=a;i<b;i++)
#define mod 1000000007
#define inf 7+1e18
#define lld long double
#define eps 0.000001
#define endl '\n'
using namespace std ;

int gcd(int a, int b)
{
    if (a == 0)   return b;
    if(b==0)      return a;
    if (a == b)   return a;
    if (a > b)    return gcd(a%b, b);
    return gcd(a, b%a);
}

/*seive
 int d[302]={0};
 int l=300;
  for(int i=2;i<l;i++)
		if(d[i]==0)
			for(int j=i;j<=l;j+=i)
				d[j]=d[j/i]+1;


  loop(i,1,301) cout<<i<<" "<<d[i]<<endl;
*/
bool vis[2005]={false};
int conn=0;
vector<int> v[2005];
void dfs(int q) 
{
	vis[q] = 1;
	
	for(int i=0;i<v[q].size() ;i++)
		if (!vis[v[q][i]])
			dfs(v[q][i]);
    
} 

/*lli power(lli x, lli y, lli p)
{
    lli 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()
{
	////////////////////
	fastio;
	///////////////////
	
	string s,t;
	cin>>s>>t;
	if(s == t)
	{
	    cout<<"Yes"<<endl;
	    return 0;
	}
	else
	{
	    //lli j=0;
	for(lli i=0;i<101;i++)
	{
	    lli j=i;
	    string test;
	    lli k=0,ind=i;
	    for(j;j<s.length();j++)
	    {
	        test.pb(t[j]);
	    }
	    if(test.length()!=s.length())
	    for(lli k=0;k<ind;k++)
	    test.pb(t[k]);
	    
	    if(test == s)
	    {
	        cout<<"Yes"<<endl;
	        return 0;
	    }
	}
	    
	}
	cout<<"No"<<endl;
}


Measured memory_bytes: 256
import bisect
import os
from collections import Counter, deque
from fractions import gcd
from functools import lru_cache
from functools import reduce
import functools
import heapq
import itertools
import math
import numpy as np
import re
import sys

if os.getenv("LOCAL"):
    sys.stdin = open("_in.txt", "r")

sys.setrecursionlimit(2147483647)
INF = float("inf")

S = sys.stdin.readline().rstrip()

N = int(S)

if N % sum(map(int, list(S))) == 0:
    print('Yes')
else:
    print('No')



Measured memory_bytes: 22048
#include<stdio.h>
#define MAX 100000

typedef long long llong;
int n, k;
llong w[MAX];

int check(llong P){
  int v = 0;
  for (int j = 0; j < k; j++) {
    llong s = 0;
    while(s + w[v] <= P){
      s += w[v];
      v++;
      if (v == n) {
        return n;
      }
    }
  }
  return v;
}

int solve(){
  llong left = 0;
  llong right = 100000 * 10000;
  llong mid;
  while (right - left > 1) {
    mid = (left +  right) / 2;
    int v = check(mid);
    if (v >= n) {
      right = mid;
    }else {
      left = mid;
    }
  }
  return right;
}

int main(int argc, char const *argv[]) {
  scanf("%d%d", &n, &k);
  for(int i = 0; i < n; i++){
    scanf("%lld", &w[i]);
  }
  llong result = solve();
  printf("%lld\n", result);
  return 0;
}



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

#define       sf                 scanf
#define       pf                 printf
#define       pb                 push_back
#define       sz                 200005
#define       inf                0x3f3f3f3f
#define       MOD                1000000007
#define       READ               freopen("in.txt", "r", stdin);
#define       WRITE              freopen("out.txt", "w", stdout);
#define       optimize           ios::sync_with_stdio(0);cin.tie(0);

using namespace std;

typedef       long long int      ll;

int main()
{
    //READ
    optimize

    string s;

    int ans = 0;

    cin >> s;

    if(s[0]==s[1] and s[1]==s[2] and s[0]=='R') cout << 3 << endl;
    else if((s[0]==s[1] and s[0]=='R') or (s[1]==s[2] and s[1]=='R')) cout << 2 << endl;
    else if(s[0]=='R' or s[1]=='R' or s[2]=='R') cout << 1 << endl;
    else cout << 0 << endl;

    return 0;
}


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

int main(){
 int X,N;
 int A,B;
 cin >> X >> N;
 vector<int> vec(N);

if(N==0){
  cout << X << endl;
  return 0;
}

for(int i=0;i<N;i++){
  cin >> vec.at(i);
}
map<int,int> a;
for(int j=0;j<=101;j++){
  a[j]=j;
}
for(int k=0;k<N;k++){
  a.erase(vec.at(k));
}
for(int k=0;k<=X;k++){
  if(a.count(X-k)){
    A=k;
    break;
  }
}
for(int l=0;l<=101-X;l++){
  if(a.count(X+l)){
    B=l;
    break;
  }
}
if(A<=B){
  cout << X-A << endl;
}
if(A>B){
  cout << X+B << endl;
}
}

Measured memory_bytes: 3636
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int A, B;
  cin >> A >> B;
  int count = 0;
  
  for(int i = A; i <= B; i++){
    int man = i / 10000;
    int sen = i / 1000 - man * 10;
    int iti = i % 10;
    int juu = (i % 100 - iti) / 10;
    
    if((man == iti) && (sen == juu)){
      count++;
    }
  }
  cout << count << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i,n) for(int (i)=0;(i)<(int)(n);++(i))
#define all(x) (x).begin(),(x).end()
#define pb push_back
#define fi first
#define se second
#define dbg(x) cout<<#x" = "<<((x))<<endl
template<class T,class U> ostream& operator<<(ostream& o, const pair<T,U> &p){o<<"("<<p.fi<<","<<p.se<<")";return o;}
template<class T> ostream& operator<<(ostream& o, const vector<T> &v){o<<"[";for(T t:v){o<<t<<",";}o<<"]";return o;}

using vi = vector<int>;

ll f(ll x){
    return x*(x+1)/2;
}

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

    vector<vi> add(n+1,vi(3));
    rep(i,m){
        int q;
        ll k;
        scanf(" %d %lld", &q, &k);
        if(q==0){
            ll l=0, r=100000;
            while(r-l>1){
                ll mid = (l+r)/2;
                if(f(mid)<k) l=mid;
                else r=mid;
            }
            if(r<=n) ++add[r][q];
        }
        else{
            if(k<=n) ++add[k][q];
        }
    }

    ll ans = 0;
    ll a[3]={};
    for(ll i=1; i<=n; ++i){
        a[0] = add[i][0];
        for(int j=1; j<3; ++j) a[j] += add[i][j];

        ans += i*i*i;
        ans -= i*i*(a[0]+a[1]+a[2]);
        ans += i*(a[0]*a[1]+a[1]*a[2]+a[2]*a[0]);
        ans -= a[0]*a[1]*a[2];
    }
    printf("%lld\n", ans);
    return 0;
}



Measured memory_bytes: 5508
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<ctime>
#include<cctype>
#include<climits>
#include<iostream>
#include<string>
#include<vector>
#include<map>
#include<list>
#include<queue>
#include<deque>
#include<algorithm>
#include<numeric>
#include<utility>
#include<complex>
#include<memory>
#include<functional>
#include<set>
 
using namespace std;
 
#define ALL(g) (g).begin(),(g).end()
#define REP(i, x, n) for(int i = x; i < n; i++)
#define rep(i,n) REP(i,0,n)
#define F(i,j,k) fill(i[0],i[0]+j*j,k)
#define P(p) cout<<(p)<<endl;
#define INF 1<<25
 
typedef long long ll;

int dy[8]={1,1,1,0,0,-1,-1,-1};
int dx[8]={-1,0,1,-1,1,-1,0,1};
struct S{
	int a,b,c;
};
bool asc(const S& left,const S& right){
	return left.c > right.c;
}

int main(){
	int sx,sy,tx,ty;
	cin>>sx>>sy>>tx>>ty;
	int dx=tx-sx;
	int dy=ty-sy;

	rep(i,dy)cout<<"U";
	rep(i,dx)cout<<"R";
	rep(i,dy)cout<<"D";
	rep(i,dx)cout<<"L";
	cout<<"L";
	rep(i,dy+1)cout<<"U";
	rep(i,dx+1)cout<<"R";
	cout<<"D"<<"R";
	rep(i,dy+1)cout<<"D";
	rep(i,dx+1)cout<<"L";
	cout<<"U"<<endl;
	
	return 0;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define  rep(i, n) for(int i = 0; i < n; i++) 
#define  all(x) (x).begin(),(x).end()     // 昇順ソート
#define  rall(v) (v).rbegin(), (v).rend() // 降順ソート
#define  INF 1LL << 60
typedef long long int LL;
typedef long long int ll;
#define pll pair<ll, ll>
#define F first
#define S second
const int MOD = 1000000007;
template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return true; } return false; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return true; } return false; }
//sort(all(x))とするとソートできるよ
// 10^x は pow(10,(x)) 
// 任意のlogは　対数の底の変換を使う    log(N) / log(任意の底)

int main(){
    int N,M,R;cin >> N >> M >> R;
    vector<int> r(R);
    rep(i,R)cin >> r[i];
    sort(all(r));
    vector<vector<LL>> G(N+1,vector<LL>(N+1,INF));
    rep(i,M){
        int s,t,u;cin >> s >> t >> u;
        G[s][t] = u;
        G[t][s] = u;
    }


    // WF
    rep(k,N+1)rep(i,N+1)rep(j,N+1)G[i][j] = min(G[i][j],G[i][k] + G[k][j]);
    rep(i,N+1)G[i][i] = 0;
    vector<int> np(R);

    LL ans = INF;

/*    rep(i,G.size()){
        rep(j,G[i].size()){
            cout << G[i][j] << " ";
        }
        cout << endl;
    }*/
 
    do{
        LL tmp = 0;
        for(int i = 1;i < R;++i){
            int s = r[i-1];
            int t = r[i];
            tmp += G[s][t]; 
        }
        ans = min(ans,tmp);
    }while(next_permutation(all(r)));

    cout << ans << endl;
}


Measured memory_bytes: 512
#include <iostream>
#include <vector>
using namespace std;
#define rep(i,n) for(int i=0;i<(int)(n);i++)
typedef long long ll;

int m,sz,cnt;
ll n;
vector<int> v[100001];
int used[100001];
bool ok;

void dfs(int x){
  sz++;
  rep(i,v[x].size()){
    if(used[v[x][i]]==0){
      used[v[x][i]]=-used[x];
      dfs(v[x][i]);
      }
    else if(used[v[x][i]]==used[x])ok=false;
    }
  }
  
int main(){
  cin>>n>>m;
  rep(i,m){
    int l,r;
    cin>>l>>r;
    l--;r--;
    v[l].push_back(r);
    v[r].push_back(l);
    }
  rep(i,n)used[i]=0;
  ll cycle,line,point;
  cycle=line=point=0;
  rep(i,n){
    if(used[i]==0){
      sz=0;ok=true;
      used[i]=1;
      dfs(i);
      if(sz==1)point++;
      else if(ok)line++;
      else cycle++;
      }
    }
  cout<<(cycle+line)*(cycle+line)+line*line+2*n*point-point*point<<endl;
  return 0;
} 


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

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

    bool flag = true;
    int count = 0;

    if (s[0] != 'A') flag = false;
    for (int i = 1; i < s.length(); i++) {
        if (s[i] == 'C' && 2 <= i && i <= s.length() - 2) {
            count++;
        } else if (s[i] != 'C' && (s[i] < 'a' || 'z' < s[i])) {
            flag = false;
        }
    }
    if (count != 1) flag = false;

    cout << (flag ? "AC" : "WA") << endl;
}

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

using namespace std ;
typedef long long ll ;
int main() {
    ll a , b ,c,d;
    cin >> a >> b >> c >> d ;
    ll x = 0 ;
    while(a>0 and c>0) {
        if (x%2==0) c-=b ;
        else a-=d ;
        if (c<=0) break ;
        if (a<=0) break ;
        //cout << a << ' ' << c<<' ' << x<< endl ;
        x++ ;
    }
    if (a<=0) cout << "No\n" ;
    else cout << "Yes\n" ;
}


Measured memory_bytes: 3616
#include<bits/stdc++.h>
#define _overload3(_1, _2, _3, name, ...) name
#define _rep(i, n) repi(i, 0, n)
#define repi(i, a, b) \
  for (ll i = static_cast<int>(a); i < static_cast<int>(b); ++i)
#define rep(...) _overload3(__VA_ARGS__, repi, _rep, ) (__VA_ARGS__)  // NOLINT
#define chmax(x, a)  do { x = max(x, a); } while(0)
#define chmin(x, a)  do { x = min(x, a); } while(0)

using namespace std;
typedef long long int ll;
typedef unsigned long long int ull;
typedef pair<ll,ll> PLL;

ll N, X, M;

// 最初の頂点からの距離
vector<ll> visited(300000, -1);
vector<ll> sum(300000, 0);
ll ans = 0;

void solve() {
  cin >> N >> X >> M;
  visited.resize(M, -1);
  sum.resize(M, -1);

  ll i = 1;
  ll cur = X % M;
  ans += cur, visited[cur] = 1, sum[cur] = ans;
  i++;

  while (i <= N) {
    ll nxt = (cur * cur) % M;
    ll len = (i - visited[nxt]);
    ll _sum = ans - sum[nxt] + nxt;
    ll t = (N - i + 1) / len;

    if (visited[nxt] != -1 && t > 0) {
      // 2回目に訪れる
      ans += t * _sum;
      i   += t * len;
    } else {
      // 初回に訪れる
      ans += nxt, visited[nxt] = i, sum[nxt] = ans;
      cur = nxt;
      i++;
    }
  }
  cout << ans << endl;
}

int main() {
  //ll T;
  //cin >> T;
  //rep(_,T)
    solve();
  return 0;
}


Measured memory_bytes: 7864
#include<iostream>
#include<algorithm>
#include<string>
#include<functional>
#include<utility>
#include<stack>
#include<queue>
#include<cmath>
#include<list>
#include<cstdint>
#include<vector>
#include<map>
#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
#define rep(i,rept)	for(ll i = 0; i<rept;i++)
typedef long long ll;

ll nCr(ll n, ll r) {
	if (r > n) { return 0; }
	if (r * 2 > n) r = n - r;
	ll dividend = 1;
	ll divisor = 1;
	for (ll i = 1; i <= r; ++i) {
		dividend *= (n - i + 1);
		divisor *= i;
	}
	return dividend / divisor;
}
ll sumdigit(ll n) {
	ll dig = 0, sum = 0;
	while (n) {
		dig = n % 10;
		sum = sum + dig;
		n = n / 10;
	}
	return sum;
}



int main() {
	char at, top;
	std::cin >> at >> top;
	if (at == 'H') {
		if (top == 'H') {
			std::cout << 'H' << std::endl;
			return 0;
		}
		else {
			std::cout << 'D' << std::endl;
			return 0;
		}
	}
	else {
		if (top == 'H') {
			std::cout << 'D' << std::endl;
			return 0;
		}
		else {
			std::cout << 'H' << std::endl;
			return 0;
		}
	}
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main(){
     string S;
     cin >> S;

     if(S.at(0)=='A' && S.at(1)=='A' && S.at(2)=='A'){
        cout << "No" << endl;
     }
    else if(S.at(0)=='B' && S.at(1)=='B' && S.at(2)=='B'){
        cout << "No" << endl;
     } 
     else{
         cout << "Yes" << endl;
     }
}


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

list_n = [str(i) for i in range(n+1)] 
list_f = [ int(t[0]) for t in list_n]
list_e = [ int(t[-1]) for t in list_n]

a = [[0 for i in range(10)] for j in range(10)]
b = [[0 for i in range(10)] for j in range(10)]

for i in range(n):
    a[list_f[i+1]][list_e[i+1]] += 1
    b[list_e[i+1]][list_f[i+1]] += 1

ans = 0
for i in range(10):
    for j in range(10):
       ans += a[i][j] * b[i][j]

print(ans)


Measured memory_bytes: 18968