akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;
long long int gcd(long long int a, long long int b) {
	if (a % b == 0) return b;
	else return gcd(b, a % b);
}
int main() {
	int N;
	cin >> N;
	vector<int> A(N);
	for (int i = 0; i < N; i++) {
		cin >> A[i];
	}
	sort(A.begin(), A.end());
	vector<int> left(N);//左からi番目までのgcd
	vector<int> right(N);
	left[0] = A[0];
	right[0] = A[N - 1];
	for (int i = 1; i < N; i++) {
		left[i] = gcd(left[i - 1], A[i]);
	}
	reverse(A.begin(), A.end());
	for (int i = 1; i < N; i++) {
		right[i] = gcd(right[i - 1], A[i]);
	}
	long long Max = max(right[N - 2], left[N - 2]);
	if (N > 2) {
		for (int i = 0; i < N - 2; i++) {
			if (Max < gcd(right[N - 3 - i], left[i])) {
				Max = gcd(right[N - 3 - i], left[i]);
			}
		}
	}
	cout << Max << endl;
	return 0;
}

Measured memory_bytes: 1408
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for(ll i = 0, i##_len = (n); i < i##_len; i++)
#define reps(i, s, n) for(ll i = (s), i##_len = (n); i < i##_len; i++)
#define rrep(i, n) for(ll i = (n) - 1; i >= 0; i--)
#define rreps(i, e, n) for(ll i = (n) - 1; i >= (e); i--)
#define all(x) (x).begin(), (x).end()
#define sz(x) ((ll)(x).size())
#define len(x) ((ll)(x).length())

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    // std::ifstream in("input.txt");
    // std::cin.rdbuf(in.rdbuf());
    ll n, k;
    cin >> n >> k;
    vector<vector<ll>> black(k, vector<ll>(k, 0)), white(k, vector<ll>(k, 0));
    rep(i, n) {
        ll x, y;
        char c;
        cin >> x >> y >> c;
        x %= 2 * k;
        y %= 2 * k;
        if (x >= k) {
            x -= k;
            c = ((c == 'B') ? 'W' : 'B');
        }
        if (y >= k) {
            y -= k;
            c = ((c == 'B') ? 'W' : 'B');
        }
        if (c == 'B') black[x][y]++;
        else white[x][y]++;
    }
    vector<vector<ll>> bdp(k + 1, vector<ll>(k + 1, 0)), wdp(k + 1, vector<ll>(k + 1, 0));
    rep(i, k) {
        rep(ii, k) {
            bdp[i + 1][ii + 1] = bdp[i][ii + 1] + bdp[i + 1][ii] - bdp[i][ii] + black[i][ii];
            wdp[i + 1][ii + 1] = wdp[i][ii + 1] + wdp[i + 1][ii] - wdp[i][ii] + white[i][ii];
        }
    }
    // rep(i, k + 1) rep(ii, k + 1) printf("%lld%s", bdp[i][ii], (ii == k) ? "\n" : " ");
    // rep(i, k + 1) rep(ii, k + 1) printf("%lld%s", wdp[i][ii], (ii == k) ? "\n" : " ");
    ll ans = 0;
    rep(y, k + 1) {
        rep(x, k + 1) {
            ll bcnt = 0, wcnt = 0;
            bcnt += bdp[x][k] - bdp[x][k - y] - bdp[0][k] + bdp[0][k - y];
            // printf("[step1] x=%lld, y=%lld, bcnt=%lld, wcnt=%lld\n", x, y, bcnt, wcnt);
            bcnt += bdp[k][k - y] - bdp[k][0] - bdp[x][k - y] + bdp[x][0];
            // printf("[step2] x=%lld, y=%lld, bcnt=%lld, wcnt=%lld\n", x, y, bcnt, wcnt);
            wcnt += wdp[x][k - y] - wdp[x][0] - wdp[0][k - y] + wdp[0][0];
            // printf("[step3] x=%lld, y=%lld, bcnt=%lld, wcnt=%lld\n", x, y, bcnt, wcnt);
            wcnt += wdp[k][k] - wdp[k][k - y] - wdp[x][k] + wdp[x][k - y];
            // printf("[step4] x=%lld, y=%lld, bcnt=%lld, wcnt=%lld\n", x, y, bcnt, wcnt);
            ans = max(ans, bcnt + wcnt);
            bcnt = 0, wcnt = 0;
            wcnt += wdp[x][k] - wdp[x][k - y] - wdp[0][k] + wdp[0][k - y];
            // printf("[step1] x=%lld, y=%lld, bcnt=%lld, wcnt=%lld\n", x, y, bcnt, wcnt);
            wcnt += wdp[k][k - y] - wdp[k][0] - wdp[x][k - y] + wdp[x][0];
            // printf("[step2] x=%lld, y=%lld, bcnt=%lld, wcnt=%lld\n", x, y, bcnt, wcnt);
            bcnt += bdp[x][k - y] - bdp[x][0] - bdp[0][k - y] + bdp[0][0];
            // printf("[step3] x=%lld, y=%lld, bcnt=%lld, wcnt=%lld\n", x, y, bcnt, wcnt);
            bcnt += bdp[k][k] - bdp[k][k - y] - bdp[x][k] + bdp[x][k - y];
            // printf("[step4] x=%lld, y=%lld, bcnt=%lld, wcnt=%lld\n", x, y, bcnt, wcnt);
            ans = max(ans, bcnt + wcnt);
        }
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 31872
#include <cstdio>
#include <cstdlib>
#define repi(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,a) repi(i,0,a)

int N, x;
int p[200000];

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

  if( x == 1 || x == 2*N-1 )
  {
    puts( "No" );
   
    return 0;
  }

  puts( "Yes" );

  int mid = (2*N-1)/2;
  p[mid] = x;
  p[mid-1] = x-1;
  p[mid+1] = x+1;

  int ptr = 0;
  repi( i, 1, 2*N-1+1 ) if( abs(i-x) > 1 )
  {
    if( ptr == mid-1 )
      ptr += 3;

    p[ptr++] = i;
  }

  rep( i, 2*N-1 )
    printf( "%d\n", p[i] );

  return 0;
}

Measured memory_bytes: 2176
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

using namespace std;
using namespace __gnu_pbds;

using vi = vector<int>;
using pi = pair<int, int>;
using ll = long long;

typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update>Order_Set;

const int mxn = 1e4+10;
const int Mod = 1e9+7;

void solve()
{
    int n;
    cin>>n;
    unordered_map<int, int>mp;
    for(int i=1 ; i<n ; i++){
        int x;
        cin>>x;
        mp[x]++;
    }
    for(int i=1  ; i<=n ; i++) cout<<mp[i]<<endl;
}

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

    int tc = 1;
    //cin>>tc;
    while(tc--) solve();

    return 0;
}


Measured memory_bytes: 11492
#include <iostream>
#include <bitset>
#include <string>
#include <algorithm>
#include <vector>
using namespace std;

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

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

    int count[9999] = {0};

    for(size_t index = 0; index < w.size(); index++)
    {
        /* code */
        char input = w[index];
        count[input]++;
    }

    bool ok = true;
    for(auto &i:w)
    {
        if (count[i]%2 == 0)
        {

        }
        else
        {
            ok = false;
        }
        
    }
    
    if (ok) {
        cout << "Yes" << endl;
    }
    else
    {
        cout << "No" << endl;
    }
    
    
}

Measured memory_bytes: 256
from collections import deque
n, m  = map(int, input().split())
a  = []
b = [[] for _ in range(n)]
for i in range(m):
    a.append(list(map(int, input().split())))
    

for i in range(m):
    b[a[i][0]-1].append(a[i][1])
    b[a[i][1]-1].append(a[i][0])

seen = [-1]*n
seen[0] = 1
que = deque([1])
while que:
    v = que.popleft()
    for i in b[v-1]:
        if seen[i-1] != -1:
            continue
        que.append(i)
        seen[i-1] = v

for i in range(n):
    if seen[i] == -1:
        print("No")
else:
    del seen[0]
    print("Yes")
    for i in range(n-1):
        print(seen[i])

Measured memory_bytes: 57860
#include <bits/stdc++.h>
using namespace std;
const int MOD=1e9+7;
int main(){
  int N,M;
  cin>>N>>M;
  vector<int> price(M);
  unordered_map<int,int> mp;
  int dp[1020][4100];
  for(int i=0;i<M;i++){
    int a,b;//値段、開けれる宝箱の数
    int rock=0;
    cin>>a>>b;
    price.at(i)=a;
    for(int j=0;j<b;j++){
      int c;
      cin>>c;
      int d=1<<(c-1);
      rock+=d;
    }
    mp[i+1]=rock;
  }
  for(int i=1;i<=M;i++){
    for(int j=0;j<(1<<N);j++){
      if(j==0){dp[i][j]=0;}
      else{dp[i][j]=MOD;}
    }
  }
  for(int i=1;i<=M;i++){
    for(int j=0;j<(1<<N);j++){
      if(i>1){dp[i][j]=dp[i-1][j];}
      int a=j&mp[i],c=j-(j&mp[i]);
      if(a==j){dp[i][j]=min(dp[i][j],price.at(i-1));}
      else if(a==mp[i] && i>1){dp[i][j]=min(dp[i][j-mp[i]]+price.at(i-1),dp[i][j]);}
      if(i>1){dp[i][j]=min(dp[i][j],dp[i-1][c]+price.at(i-1));}
    }
  }
  if(dp[M][(1<<N)-1]!=MOD){cout<<dp[M][(1<<N)-1]<<endl;}
  else{cout<<-1<<endl;}
}

Measured memory_bytes: 19552
#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=(a);i<=(b);i++)
#define per(i,a,b) for(int i=(a);i>=(b);i--)
#define REP(i,n) for(int i=0;i<(n);i++)
#define qwq(x) cout<<"# "<<#x<<" = "<<x<<endl;
#define fi first
#define se second
#define pb push_back
#define mp make_pair
using namespace std;
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef long long ll;
 
template<class T> inline void read(T &x){
	int f=0;x=0;char ch=getchar();
	for(;!isdigit(ch);ch=getchar())f|=(ch=='-');
	for(;isdigit(ch);ch=getchar())x=x*10+ch-'0';
	if(f)x=-x;
}

const int N=605,mod=1e9+7;
int f[2][N][N],g[N],a[N],ty[N];
int n,tot,cnt,las,now,ans;

int fix(int x){
	return x>=mod?x-mod:x;
}

void add(int &x,int y){
	x=fix(x+y);
}

int power(int x,int p){
	int res=1;
	for(;p;p>>=1,x=(ll)x*x%mod)
		if(p&1)res=(ll)res*x%mod;
	return res;
}

int main(){
	read(n);
	rep(i,1,n*2){
		read(a[i]);
		if(a[i]!=-1)ty[a[i]]=1;
		if(i%2==0&&a[i]!=-1&&a[i-1]!=-1)
			ty[a[i]]=ty[a[i-1]]=-1;
		if(i%2==0&&a[i]==-1&&a[i-1]==-1)
			++tot;
	}
	f[las][0][0]=1,now=1;
	rep(i,1,2*n)
		if(ty[i]==0){
			memset(f[now],0,sizeof f[now]);
			rep(a,0,n*2)rep(b,0,n*2)
				if(f[las][a][b]){
					if(a) add(f[now][a-1][b],f[las][a][b]);
					add(f[now][a][b+1],f[las][a][b]);
					add(f[now][a+1][b],f[las][a][b]);
				}
			swap(now,las);
		}
		else if(ty[i]==1){
			memset(f[now],0,sizeof f[now]);
			rep(a,0,n*2)rep(b,0,n*2)
				if(f[las][a][b]){
					if(b) add(f[now][a][b-1],(ll)f[las][a][b]*b%mod);
					add(f[now][a+1][b],f[las][a][b]);
				}
			swap(now,las);
		}
	ans=f[las][0][0];
	rep(i,1,tot)ans=(ll)ans*i%mod;
	printf("%d\n",ans);
	return 0;
}

Measured memory_bytes: 3072
#include <bits/stdc++.h>
using namespace std;
#define rep(i,a,b) for(int i=a;i<b;i++)
#define rrep(i,a,b) for(int i=a;i>=b;i--)
typedef long long ll;
typedef vector<string> vs;
typedef vector<int> vi;

int main()
{
	while (1)
	{
		int n; cin >> n;
		if (n == 0) return 0;

		vi imos(n + 1, 0);
		rep(i, 0, n + 1) imos[i] = i;
		rep(i, 1, n + 1) imos[i] += imos[i - 1];

		int ans = 0;
		rep(i, 1, n) rep(j, i + 1, n + 1)
		{
			int sum = imos[j] - imos[i - 1];
			if (n == sum) ans++;
		}
		cout << ans << endl;
	}
}

Measured memory_bytes: 3008
n, m = list(map(int, input().split()))
p, s = [], []
for i in range(m):
    tp, ts = input().split()
    p.append(int(tp))
    s.append(ts)

wa_counts = [0 for i in range(n)]
acs = [False for i in range(n)]

for i in range(m):
    if s[i] == 'AC':
        acs[p[i]-1] = True
    elif not acs[p[i]-1]:
        wa_counts[p[i]-1] += 1

wa_count = 0
ac_count = 0

for i in range(n):
    if acs[i] == True:
        ac_count += 1
        wa_count += wa_counts[i]

print(ac_count, wa_count, sep=' ')


Measured memory_bytes: 14920
#include <bits/stdc++.h>
using namespace std;
#define ll long long
int main() {
	ll n,ct=0,l=1;
	cin>>n;
	ll a[n];
	for(ll i=0;i<n;i++)
	cin>>a[i];
	for(ll i=0;i<n;i++)
	{	if(a[i]==l)
		l++;
		else
		ct++;
		
	}
	if(l==1)
	cout<<-1;
	else
	cout<<ct;
	return 0;
}

Measured memory_bytes: 1792
import sys
sys.setrecursionlimit(10**6)

N = int(input())
G = [[] for i in range(N)]
temp = sys.stdin.readlines()
for line in temp:
    u, v, d = map(int, line.split())
    G[u-1].append([v-1, d])
    G[v-1].append([u-1, d])
    
def dfs(v, G, cur=0):
    # 色をメモ
    color[v] = cur
        
    # 隣接するノードの色を調べる
    for next_v in G[v]:
        # 隣接ノードが探索済みなら、色が正しいか確かめる
        if color[next_v[0]] != -1:
            continue
            
        # 隣接ノードが未探索なら、正しい色に更新して再帰的に探索
        if next_v[1] % 2 == 0:
            dfs(next_v[0], G, cur)
        else:
            dfs(next_v[0], G, 1-cur)

color = [-1 for i in range(N)]
dfs(0, G)
for i in range(N):
    print(color[i])

Measured memory_bytes: 102048
N,M = map(int,input().split())
lsab = []
for i in range(N):
    a,b = map(int,input().split())
    lsab.append([a,b])
lscd = []
for j in range(M):
    c,d= map(int,input().split())
    lscd.append([c,d])

lsans = []
for i in range(N):
    max1 = 4*10**8+100
    ans = 0
    for j in range(M):
        dis = abs(lsab[i][0]-lscd[j][0])+abs(lsab[i][1]-lscd[j][1])
        if dis < max1:
            ans = j+1
            max1 = dis
    lsans.append(ans)

for i in range(N):
    print(lsans[i])

Measured memory_bytes: 9160
#include <stdio.h>

int isprime(int n) {
	int i;
    for(int i = 2; i * i <= n; i++) {
        if(n % i == 0) return 0;
    }
    return 1; 
}

int main(){
	int k,suu,an1,an2;
    while(1){
        scanf("%d",&suu);
        if(suu == 0)  break;
        for(k=suu;k>0;k--){
            if(isprime(k-2)==1 && isprime(k)==1){
                an1=k-2;
                an2=k;
                break;
            }
        }
        printf("%d %d\n",an1,an2);
    }
}

Measured memory_bytes: 1028
#include<bits/stdc++.h>
using namespace std;
using lint = long long int;
using pint = pair<int, int>;
using plint = pair<lint, lint>;
struct fast_ios { fast_ios(){ cin.tie(0); ios::sync_with_stdio(false); cout << fixed << setprecision(20); }; } fast_ios_;
#define ALL(x) (x).begin(), (x).end()
#define SZ(x) ((lint)(x).size())
#define POW2(n) (1LL << (n))
#define FOR(i, begin, end) for(int i=(begin),i##_end_=(end);i<i##_end_;i++)
#define IFOR(i, begin, end) for(int i=(end)-1,i##_begin_=(begin);i>=i##_begin_;i--)
#define REP(i, n) FOR(i,0,n)
#define IREP(i, n) IFOR(i,0,n)

int main()
{
  int n, d;
  cin >> n >> d;
  vector<vector<int>> x(n,vector<int>(d));
  REP(i,n) REP(j,d) cin >> x[i][j];

  int result = 0;
  REP(i,n){
    FOR(j,i+1,n){
      int tmp = 0;
      REP(k,d) tmp += pow(x[i][k] - x[j][k], 2);
      if(tmp == pow((int)sqrt(tmp),2)) result++;
    }
  }

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


Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<string>
#include<vector>
#include<queue>
#include<math.h>

using namespace std;

int main()
{
    int n;
    cin >> n;
    vector<string> s;
    for(int i = 0; i < n; i++){
        string in;
        cin >> in;
        s.push_back(in);
        for(int j = 0; j < n; j++){
            s[i].push_back(s[i][j]);
        }
    }
    /*for(int i = 0; i < n; i++){
        s.push_back(s[i]);
    }*/
    //cout << s[3] << endl;
    long long ans = 0;
    for(int i = 0; i < n; i++){
    bool check = true;
        for(int j = 0; j < n; j++){
            for(int k = 0; k < n; k++){
                if(s[j][k + i] != s[k][j + i]){
                    check = false;
                    break;
                }
            }
        }
    if(check == true){
        ans++;
        }
    }
    cout << ans * n << endl;

    

    return 0;
}

Measured memory_bytes: 384
#include<bits/stdc++.h>
using namespace std;
int main()
{
	int n,begin;
	cin>>n>>begin;
	int mgcd=0;
	for(int i=0;i<n;i++)
	{
		int temp;
		cin>>temp;
		mgcd=__gcd(mgcd,abs(temp-begin));
	}
	cout<<mgcd;
 } 

Measured memory_bytes: 256
#include <algorithm>
#include <iostream>
#include <vector>
#include <map>
#include <cstdio>
#include <string>
#include <cmath>
#include <queue>
#include <tuple>
#include <set>
#include <assert.h>
#include <sstream>
#include <string>
//#include <bits/stdc++.h>
#define maxs(x,y) x = max(x,y)
#define mins(x,y) x = min(x,y)
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define repr(i, n) for (int i = (n) - 1; i >= 0; i--)
#define FOR(i,i0,n) for(int (i)=(i0);(i)<(n);(i)++)
#define FORR(i,i0,n) for(int (i)=(n)-1; (i)>=(i0);(i)--)
#define SORT(x) sort(x.begin(),x.end())
#define SORTR(x) sort(x.begin(),x.end(),greater <>())
#define rn return
#define fi first
#define se second
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define mt make_tuple
typedef std::pair<int,int> P;
using namespace std;
using ll = long long;





// auto mod int
// https://youtu.be/L8grWxBlIZ4?t=9858
// https://youtu.be/ERZuLAxZffQ?t=4807 : optimize
// https://youtu.be/8uowVvQ_-Mo?t=1329 : division
const int mod = 998244353;
struct mint {
    ll x; // typedef long long ll;
    mint(ll x=0):x((x%mod+mod)%mod){}
    mint& operator+=(const mint a) {
        if ((x += a.x) >= mod) x -= mod;
        return *this;
    }
    mint& operator-=(const mint a) {
        if ((x += mod-a.x) >= mod) x -= mod;
        return *this;
    }
    mint& operator*=(const mint a) {
        (x *= a.x) %= mod;
        return *this;
    }
    mint operator+(const mint a) const {
        mint res(*this);
        return res+=a;
    }
    mint operator-(const mint a) const {
        mint res(*this);
        return res-=a;
    }
    mint operator*(const mint a) const {
        mint res(*this);
        return res*=a;
    }
    mint pow(ll t) const {
        if (!t) return 1;
        mint a = pow(t>>1);
        a *= a;
        if (t&1) a *= *this;
        return a;
    }
    
    // for prime mod
    mint inv() const {
        return pow(mod-2);
    }
    mint& operator/=(const mint a) {
        return (*this) *= a.inv();
    }
    mint operator/(const mint a) const {
        mint res(*this);
        return res/=a;
    }
};
// combination mod prime
// https://www.youtube.com/watch?v=8uowVvQ_-Mo&t=1619
struct combination {
    vector<mint> fact, ifact;
    combination(int n):fact(n+1),ifact(n+1) {
        assert(n < mod);
        fact[0] = 1;
        for (int i = 1; i <= n; ++i) fact[i] = fact[i-1]*i;
        ifact[n] = fact[n].inv();
        for (int i = n; i >= 1; --i) ifact[i-1] = ifact[i]*i;
    }
    mint operator()(int n, int k) {
        if (k < 0 || k > n) return 0;
        return fact[n]*ifact[k]*ifact[n-k];
    }
};



int main(){
    int n;
    cin >> n;
    vector<int> d(n);
    rep(i,n) cin >> d[i];
    if (d[0] != 0){ cout << 0; rn 0;}
    SORT(d);
    map<int,int> m;
    m[0] = 1;
    mint ans = 1;
    FOR(i,1,n){
        if (m[d[i]-1] == 0) { cout << 0; rn 0;}
        m[d[i]]++;
        ans *= m[d[i]-1];
    }
    cout << ans.x;
    rn 0;
    
    
}







Measured memory_bytes: 5376
//
// Created by Rea1 on 2020/2/22.
//

#pragma comment(linker, "/STACK:1024000000,1024000000")

#include <bits/stdc++.h>

using namespace std;
typedef long long ll;
typedef unsigned long long ull;
#define lson l, mid, rt << 1
#define rson mid + 1, r, rt << 1 | 1
const int mod = 1e9 + 7;
ll qmi(ll m, ll k, ll p)
{
    ll res = 1 % p, t = m;
    while (k)
    {
        if (k&1) res = res * t % p;
        t = t * t % p;
        k >>= 1;
    }
    return res;
}
ll inv(ll x, ll p)
{
    return qmi(x, p - 2, p);
}
ll C(ll n, ll m, ll p)
{
    if(m > n)return 0;
    ll up = 1, down = 1;
    for(int i = n - m + 1; i <= n; i++)up = up * i % p;
    for(int i = 1; i <= m; i++)down = down * i % p;
    return up * inv(down, p) % p;
}
ll Lucas(ll n, ll m, ll p)
{
    if(m == 0)return 1;
    return C(n % p, m % p, p) * Lucas(n / p, m / p, p) % p;
}
int main() {
    ll n, a, b;
    scanf("%lld%lld%lld", &n, &a, &b);
    ll ans = (((qmi(2, n, mod) - Lucas(n, a, mod) + mod)%mod - Lucas(n, b, mod) + mod ) % mod - 1 + mod )%mod;
    printf("%lld", ans);
    return 0;
}

Measured memory_bytes: 256
n,m=map(int,input().split())
a=[]
for i in range(n):
  a.append(input())
b=[]
for i in range(m):
  b.append(input())

res=0
for i in range(0,n-m+1):
  for k in range(0,n-m+1):
    keep=0
    for j in range(i,i+m):    
      if b[j-i] in a[j][k:k+m]:
        keep+=1
      if keep==m:
        print("Yes")
        res=1
        break
  if res==1:
    break
if res==0:
  print("No")


Measured memory_bytes: 3064
n = int(input())
a = list(map(int, input().split()))
xor = 0
total = 0
cur = 0
cnt = 0
for i in range(n):
    xor = xor ^ a[i]
    total += a[i]
    if xor != total:
        while True:
            total -= a[cur]
            xor = xor ^ a[cur]
            cur += 1
            if total == xor:
                break
    cnt += (i - cur + 1)
print(cnt)


Measured memory_bytes: 24712
H, W = map(int, input().split())

A = []

for i in range(H):
    tmp = input()
    A.append(tmp)
    
c = 0
    
for i in range(H):
    for j in range(W):
        if A[i][j]=='#':
            c = c+1
            
if not c==H+W-1:
    print('Impossible')
else:
    print('Possible')

Measured memory_bytes: 3060
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i = 0;i<n;i++)
#define erep(i,n) for(int i = 0;i<=n;i++)
#define rep1(i,n) for(int i = 1;i<n;i++)
#define erep1(i,n) for(int i = 1;i<=n;i++)
typedef long long ll;
#define vint vector<int>
#define vstring vector<string>
#define vll vector<ll>
#define vbool vector<bool>
#define INF 100000000

int main(){
  int sx,sy,tx,ty;
  cin >> sx >> sy >> tx >> ty;
  rep(i,tx-sx) cout << 'R';
  rep(i,ty-sy) cout << 'U';
  rep(i,tx-sx) cout << 'L';
  rep(i,ty-sy) cout << 'D';
  cout << 'L';
  rep(i,ty-sy+1) cout << 'U';
  rep(i,tx-sx+1) cout << 'R';
  cout << 'D';
  cout << 'R';
  rep(i,ty-sy+1) cout << 'D';
  rep(i,tx-sx+1) cout << 'L';
  cout << 'U';
  
}

Measured memory_bytes: 256
from math import isfinite

n, knapsack = map(int, input().split())
dpn = n * 100  # MAX VALUE
dp = [float('inf')] * (dpn + 1)
dp[0] = 0
for i in range(n):
    value, weight = map(int, input().split())
    for j in range(dpn - value, -1, -1):
        if not isfinite(dp[j]):
            continue
        new_weight = dp[j] + weight
        if new_weight <= knapsack and dp[j + value] > new_weight:
            dp[j + value] = new_weight

print(next(filter(lambda i: isfinite(dp[i]), range(dpn, -1, -1))))

Measured memory_bytes: 7828
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int, int>; 
using pll = pair<long long, long long>;
constexpr char ln =  '\n';
constexpr long long MOD = 1000000007LL;
constexpr long long INF = 1001001001LL;
constexpr long long LINF = 1001001001001001001;
#define all(x) (x).begin(),(x).end()
#define rep(i,n) for(int i=0;i<(n);i++)
#define rept(i, j, n) for(int i=(j); i<(n); i++)
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

struct edge{
    long long from, to, cost;
};

// v:=頂点数 es:=辺の集合 cost:=始点からの最短経路のコストを格納する配列
// s:=始点(指定しなければ頂点0) g:=終点(指定しなければ頂点v-1)
// 始点から到達可能で、かつ終点へ到達可能な負閉路が検出された場合falseを、それ以外の場合trueを返す
bool bellman_ford(int v, const vector<edge>& es, vector<long long>& cost, int s = 0, int g = -1){
    if(g == -1){
        g = v - 1;
    }

    cost.assign(v, LINF);
    cost[s] = 0;

    for(int i = 0 ; i < v * 2 ; ++i){
        for(auto& e : es){
            if(cost[e.from] < LINF && cost[e.from] + e.cost < cost[e.to]){
                if(i >= v - 1 && e.to == g){
                    return true;
                }else if(i >= v - 1){
                    cost[e.to] = -LINF;
                }else{
                    cost[e.to] = cost[e.from] + e.cost;
                }
            }
        }
    }return false;
}


int main(){
    ll n, m, p; cin >> n >> m >> p;
    vector<edge> E;
    rep(i, m){
        int a, b; ll c; cin >> a >> b >> c; a--, b--;
        c = -c + p;
        E.push_back(edge{a, b, c});
    }
    vector<ll> dis;
    bool isCycle = bellman_ford(n, E, dis, 0);
    if(isCycle)cout << -1 << ln;
    else cout << max(0LL, -dis[n-1]) << ln;
}


Measured memory_bytes: 3756
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <map>
#include <set>
#include <vector>
#include <stack>
#include <queue>
#include <bitset>
#include <algorithm>
#include <numeric>
#include <functional>
using namespace std;

#define Rep(b, e, i) for(int i = b; i <= e; i++)
#define Repr(e, b, i) for(int i = e; i >= b; i--)
#define rep(n, i) Rep(0, n-1, i)
#define repr(n, i) Repr(n-1, 0, i)
#define all(v) (v).begin(), (v).end()
#define pb(v) push_back(v)
#define uniq(v) (v).erase(unique(all(v)),(v).end())
#define bitcnt(x) __builtin_popcount(x)
#define fst first
#define snd second
#define Pqaz(T) priority_queue<T,vector<T>,greater<T>>
#define Pqza(T) priority_queue<T>
#define ENJYU std::ios::sync_with_stdio(false);std::cin.tie(0);

typedef long long ll;
typedef pair<ll, ll> llP;
typedef pair<int, int> intP;

//vector の中身を出力
template <class T>ostream &operator<<(ostream &o,const vector<T>&v)
{o<<"{";for(int i=0;i<(int)v.size();i++)o<<(i>0?", ":"")<<v[i];o<<"}";return o;}

void solve(void){
	int N; ll C;
	cin >> N >> C;
	vector <ll> xs(N), vs(N), rs(N), ls(N);
	rep(N, i) {
		cin >> xs[i] >> vs[i];
	}
	ll sum = 0LL;
	rep(N, i) {
		sum += vs[i];
		rs[i] = sum - xs[i];
	}
	rep(N, i) {
		ls[i] = sum - C + xs[i];
		sum -= vs[i];
	}

	ll ans = max({rs[0], ls[0], 0LL});
	rep(N-1, i) {
		rs[i+1] = max(rs[i], rs[i+1]);
		ls[N-i-2] = max(ls[N-i-1], ls[N-i-2]);
		ans = max({rs[i+1], ls[N-i-2], ans});
	}
	//cout << rs << endl << ls << endl;
	rep(N-1, i) {
		ans = max(ans, rs[i] + ls[i+1] - min(xs[i], C - xs[i+1]));
	}
	cout << ans << endl;
}

int main(void){
	solve();
	//cout << "yui(*-v・)yui" << endl;
	return 0;
}


Measured memory_bytes: 3328
//AtCoder ABC102 B - Maximum Difference
#include <bits/stdc++.h>
using namespace std;
using ll=int64_t;
int main() {
    ll N; cin>>N;
    vector<ll> an(N);
    for(auto&& a:an){
        cin>>a;
    }
    sort(an.begin(),an.end());
    cout<<abs(an.back()-an[0])<<endl;
    return 0;
}

Measured memory_bytes: 256
K = gets.to_i

def rec(d, val, all)
  all << val
  return if d == 10

  for i in -1..1
    add = (val % 10) + i
    rec(d+1,val*10 + add, all) if add >= 0 && add <=9
  end
end

all = []

[*1..9].each do |i|
  rec(0,i,all)
end

puts all.sort[K-1]


Measured memory_bytes: 27892
S = input()

ACGT = ['A', 'C', 'G', 'T']
cntList = []
cnt = 0
cntList.append(cnt)
for s in S:
    if s in ACGT:
        cnt += 1
        cntList.append(cnt)
    else:
        cnt = 0
print(max(cntList))

Measured memory_bytes: 61860
program main
    use,intrinsic :: iso_fortran_env
    implicit none
    integer(int32):: n,k
    integer(int32):: i,cnt=0
    character(:),allocatable::  s

    read*, n,k
    allocate(character(n):: s)
    read*, s

    do i=2,n
        if (s(i-1:i-1) /= s(i:i)) cnt=cnt+1
    end do

    do i=1,k
        cnt=cnt-2
    end do

    print'(i0)', n-1 - max(cnt,0)

end program main

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

using namespace std;

#ifdef WIN32
	#define I64 "%I64d"
#else
	#define I64 "%lld"
#endif

typedef long long ll;

#define f first
#define s second
#define mp make_pair
#define pb push_back
#define all(s) s.begin(), s.end()
#define sz(s) (int(s.size()))
#define fname "a"
#define MAXN 200002

int a[MAXN];
set < pair<int, int> > s;
ll ans[MAXN];

int main()
{
	#ifdef LOCAL
	freopen(fname".in", "r", stdin);
	freopen(fname".out", "w", stdout);
	#endif

	int n;
	scanf("%d", &n);
	for (int i = 0; i < n; ++i) {
		scanf("%d", &a[i]);
		s.insert(mp(a[i], i));
	}

	ll x = 0;
	for (int i = 0; i < n; ++i) {
		if (a[i] - x <= 0) continue;
		ll t = 0;
		while(!s.empty() && s.begin()->f - x <= a[i] - x) {
			pair <int, int> cur = *s.begin();
			s.erase(s.begin());
			if (cur.f - x <= 0) continue;
			ans[i] += cur.f - x;
		}
		ans[i] += 1LL * sz(s) * (a[i] - x);
		x = max(1LL * a[i], x);
	}

	for (int i = 0; i < n; ++i) {
		printf(I64"\n", ans[i]);
	}

	return 0;
}


Measured memory_bytes: 6912
s = input()

while len(s) > 7:
  if s[-5:] in ["dream", "erase"]:
    s = s[:-5]
  elif s[-6:] in ["eraser"]:
    s = s[:-6]
  elif s[-7:] in ["dreamer"]:
    s = s[:-7]
  else:
    break

if (len(s)==5 and s in ["dream", "erase"]) or (len(s)==6 and s in ["eraser"]) or (len(s)==7 and s in ["dreamer"]):
  print("YES")
else:
  print("NO")

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

using namespace std;

struct Initializer {
  Initializer() {
    cin.tie(0);
    ios::sync_with_stdio(0);
    cout << fixed << setprecision(15);
  }
} initializer;

int main() {
  int n;
  cin >> n;
  vector<pair<int, int>> v;
  for (int i = 1; i < n; i += 2) v.emplace_back(i, 0);
  for (int i = 1; i < n - 2; i += 6) {
    for (int j = 2; j < n; j += 2) v.emplace_back(i, j);
  }
  for (int i = 4; i < n - 2; i += 6) {
    for (int j = 1; j < n; j += 2) v.emplace_back(i, j);
  }
  
  for (int j = n % 2 + 1; j < n; j += 2) v.emplace_back(n - 2, j);
  cout << v.size() << endl;
  for (auto c : v) cout << c.first << " " << c.second << endl;
  /*
  vector<vector<int>> k(n, vector<int>(n));
  for (auto c : v) k[c.first][c.second] = 1;
  for (int i = 0; i < n; ++i) {
    for (int j = 0; j < n; ++j) {
      if ((i + j) % 2 == 0) k[i][j] = 1;
      cout << k[i][j];
    }
    cout << endl;
  }
  */
}


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

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

const int INF = 1e9;

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

  int ret = INF;
  REP(offset, 2) {
    int tmp = 0;
    REP(i, S.length()) {
      if(((i + offset) % 2 == 0) && (S[i] == '1')) ++tmp;
      else if(((i + offset) % 2 == 1) && (S[i] == '0')) ++tmp;
    }
    ret = min(ret, tmp);
  }

  cout << ret << endl;
  return 0;
}


Measured memory_bytes: 512
#include <stdio.h>
int n, k, ans;
char s[100001];
int main() {
	scanf("%d%d", &n, &k);
	scanf(" %s", s);
	for (int i = 0; i < n - 1; i++) {
		if (s[i] == s[i + 1])ans++;
	}
	if (ans + 2 * k < n - 1)printf("%d\n", ans + 2 * k);
	else printf("%d\n", n - 1);
}

Measured memory_bytes: 256
import java.util.*;
//import java.util.stream.Collectors;

public class Main{
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		
		int n = Integer.parseInt(sc.next());
		for(int i=1; ; i++){
			if(n * i % 360 == 0){
				System.out.println(i);
				break;
			}
		}
	}
}


Measured memory_bytes: 35604
D = int(input())
C = [0]*27
C[1:] = list(map(int,input().split()))
S = [[0]*27 for _ in range(D+1)]
for i in range(1,D+1):
    S[i][1:] = list(map(int,input().split()))

T = [0]*(D+1)
T[1:] = [int(input()) for _ in range(D)]

last = [0]*27
score = 0
for i in range(1,D+1):
    score += S[i][T[i]]
    last[T[i]] = i
    for j in range(1,27):
        score -= (i-last[j])*C[j]
    print(score)

Measured memory_bytes: 68456
#include <iostream>
#include <map>
#include <vector>
#include <algorithm>

int main(){
    std::string str;
    std::cin >> str;

    bool flg = false;
    int center = (str.size() + 1) / 2;
    int clip;
    for(int i = 1; i <= center; ++i){
        clip = (str.size() + 1) / 2 - i;
//       std::cout << str.substr(0, clip) << std::endl;
//       std::cout << str.substr(clip, clip) << std::endl;
        if(str.substr(0, clip) == str.substr(clip, clip)){
            flg = true;
            break;
        }
    }

    std::cout << clip * 2 << std::endl;

    return 0;
}


Measured memory_bytes: 256
n , k  = map(int , input().split())
o = []
ans = 0
for i in range(1,n+1):
    o.append(0)
for i in range(k):
    d = int(input())
    s = list(map(int , input().split()))
    for i in range(d):
        o[s[i]-1] = d
for i in range(len(o)):
    if o[i] == 0:
        ans += 1
print(ans)

Measured memory_bytes: 9204
import sys
import math
import string
import fractions
import random
from operator import itemgetter
import itertools
from collections import deque
import copy
import heapq
import bisect

MOD = 10 ** 9 + 7
INF = float('inf')
input = lambda: sys.stdin.readline().strip()

a, b, c = map(int, input().split())

if c - a - b > 0 and (c - a - b) ** 2 > 4 * a * b:
    print("Yes")
else:
    print("No")


Measured memory_bytes: 6184
#include <bits/stdc++.h>
using namespace std;
int k, s, ans;
int main ()
{
	cin>>k>>s;
	for(int i=0;i<=k;i++)
	{
		for(int j=0;j<=k;j++){
			int f=s-i-j;
            if(f<=k&&f>=0) ans++;
		}
			
	}
	
	cout<<ans<<"\n";
	return 0;
}  

Measured memory_bytes: 256
#include <iostream>
#include <cstdlib>
#include <string>
#include <vector>
#include <map>
#include <algorithm>
#include <functional>
using namespace std;

int main(){
    string s;
    cin >> s;
    int count = 0;
    for(auto c: s){
        if(c == '2'){
            count++;
        }
    }
    cout << count << endl;
    return 0;
}


Measured memory_bytes: 888
def dfs(num,x,y,z)
  if num == N
    [x,y,z].min == 0 ? 100000 : (x-A).abs + (y-B).abs + (z-C).abs - 30
  else
    ret1 = dfs(num+1,x,y,z)
    ret2 = dfs(num+1,x+L[num],y,z) + 10
    ret3 = dfs(num+1,x,y+L[num],z) + 10
    ret4 = dfs(num+1,x,y,z+L[num]) + 10
      [ret1,ret2,ret3,ret4].min
  end
end
N,A,B,C = gets.chomp.split(" ").map(&:to_i)
L = N.times.map{gets.to_i}
puts dfs(0,0,0,0)

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

int main(){
	int tn=0;
	string input;
	char charl[32]=".,!? abcdefghijklmnopqrstuvwxyz";
	int charn[10]={0,5,8,11,14,17,20,24,27,31};
	cin >> tn;
	for (int i=0;i<tn;i++){
		int cu=0;
		string outs;
		int temp=0;
		cin >> input;
		for (string::iterator it=input.begin();it!=input.end();it++){
			int inp=(int)(*it -'0');
			if(inp==0){
				if(cu!=0){
					cu+=temp;
					temp=0;
					outs+=charl[cu-1];
					cu=0;
				}
			}else{
				if(cu==0){
					cu=charn[inp-1]+1;
				}else{
					temp++;
					temp%=(charn[inp]-charn[inp-1]);
				}
			}
		}
		cout << outs << endl;
	}
}
			


Measured memory_bytes: 1208
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define rep(i, a, b) for (int i = (a); i < (int)(b); ++i)
#define rrep(i, a, b) for (int i = (int)(b) - 1; i >= (int)(a); --i)
#define all(c) c.begin(),c.end()
#define sz(x) ((int)x.size())
using pii = pair<int, int>;
using vvi = vector<vector<int>>;
using vi  = vector<int>;
constexpr int INF = 1001001001001001001LL;

// ret: {ord, low}
pair<vi, vi> ord_lowlink(vvi &g, vector<pii> *bridge = nullptr, vi *artics = nullptr) {
    int N = sz(g);
    vector<bool> vis(N, false);
    vi ord(N), low(N);
    int k = 0;
    auto dfs = [&](auto f, int v, int p) -> void {
        vis[v] = true;
        ord[v] = low[v] = k++;
        int cnt = 0;
        bool is_artic = false;
        for (int w : g[v]) {
            if (!vis[w]) {
                cnt++;
                f(f, w, v);
                low[v] = min(low[v], low[w]);
                if (p != -1 && ord[v] <= low[w]) is_artic = true;
                if (bridge && ord[v] < low[w]) bridge->push_back({v, w});
            } else if (w != p) {
                low[v] = min(low[v], ord[w]);
            }
        }
        if (p == -1 && cnt > 1) is_artic = true;
        if (is_artic && artics) artics->push_back(v);
    };
    dfs(dfs, 0, -1);
    return {ord, low};
}

signed main() {
    int V, E;
    cin >> V >> E;
    vvi G(V);
    rep(i, 0, E) {
        int vs, vt;
        cin >> vs >> vt;
        G[vs].push_back(vt);
        G[vt].push_back(vs);
    }
    vi ans;
    ord_lowlink(G, nullptr, &ans);
    sort(all(ans));
    for (int x : ans) cout << x << endl;
}



Measured memory_bytes: 5796
s=input()
f=-1
b=' '
l=len(s)
if l==4:
	f=0
	for i in range(l):
		if(s[i]<'0' or s[i]>'9'):
			f=-1
			break;
		elif(s[i]==b):
			f=1
			break;
		else:
			b=s[i]
if(f==-1):
	print('Illegal')
elif(f==1):
	print('Bad')
else:
	print('Good')


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

 
 
int main() {
   
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);cout.tie(NULL);
     
    string s;
    cin>>s;
    string s1="AKIHABARA";
    int i;
    
    if(s=="KIHBR")//
      cout<<"YES";
      
    else if(s=="AKIHBR")//
      cout<<"YES";
      
    else if(s=="AKIHABR")//
       cout<<"YES";
    
    else if(s=="AKIHABAR")//
       cout<<"YES";
          
    else if(s=="AKIHABARA")//
       cout<<"YES";
       
    else if(s=="KIHABR")//
      cout<<"YES";  
      
    else if(s=="KIHABAR")//
      cout<<"YES"; 
      
    else if(s=="KIHABARA")//
      cout<<"YES";  
      
    else if(s=="KIHBAR")//
      cout<<"YES";  
      
    else if(s=="KIHBRA")//
      cout<<"YES";  
      
    else if(s=="AKIHBAR")//
      cout<<"YES";  
      
    else if(s=="AKIHBARA")//
      cout<<"YES";  
      
    else if(s=="AKIHBRA")//
      cout<<"YES";  
      
    else if(s=="KIHABRA")//
      cout<<"YES";  
      
    else if(s=="AKIHABRA")//
      cout<<"YES";  
      
    else if(s=="AKIHABR")//
      cout<<"YES"; 
      
    else if(s=="KIHBARA")//
      cout<<"YES";  
      
    else if(s=="AKIHBARA")//
      cout<<"YES";  
      
    else if(s=="KIHABARA")//
      cout<<"YES";  
      
   else if(s=="AKIHBRA")//
      cout<<"YES";  
    
    else if(s=="AKIHBRA")//
      cout<<"YES";  
      
    else if(s=="KIHBARA")//
      cout<<"YES";  
      
    else if(s=="KIHABRA")//
      cout<<"YES";  
        
    else if(s=="AKIHABRA")
      cout<<"YES";  
            
       
      
    else 
      cout<<"NO";
      
      
         
	return 0;
	
} 

Measured memory_bytes: 3616
#include <bits/stdc++.h>
#define rep(i, n) for(int i=0; i < n; i++)
#define reps(i, n) for(int i=1; i <= n; i++)
#define INF 1e9
#define ALL(v) v.begin(), v.end()
#define pb(x) push_back(x)

using namespace std;
using ll=long long;


int main() {
  int n,m;cin >> n >> m;
  map<int,pair<int,int>> data;
  auto ret=make_pair(0,0);
  rep(i,m){
    int p;
    string s;
    cin >> p >>s;
    if(data.count(p)==0)data[p] = make_pair(0,0);
    if(!data[p].first){
      if(s=="AC"){data[p].first=1;
        ret.first ++;
        ret.second += data[p].second;
      }
      else data[p].second++;
    }
  }

  cout << ret.first <<' '<<ret.second;
}


Measured memory_bytes: 6528
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <string>
#include <utility>

#define rep(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define all(x) (x).begin(),(x).end()
#define MEMSET(v, h) memset((v), h, sizeof(v))
typedef long long ll;

using namespace std;

int main(void){
    int N, Ain, Bin, daycount=0;
    bool cannotFinish = false;
    vector<pair<int, int> > task;
    cin >> N;
    rep(i, N){
        cin >> Bin>> Ain;
        task.emplace_back(Ain, Bin);
    }
    sort(all(task));
    rep(i, N){
        daycount += task[i].second;
        if(daycount > task[i].first){
            cannotFinish = true;
            break;
        }
    }
    cout << (cannotFinish ? "No" : "Yes") << endl;
    return 0;
}



Measured memory_bytes: 2420
#include<queue>
#include<vector>
#include<utility>
#include<functional>

namespace ProconLib{
    template<typename cost_t>
    constexpr cost_t INF(){return cost_t(1e15);}
    template<class graph_t,typename cost_t,cost_t INF=INF<cost_t>()>
    std::vector<cost_t> Dijkstra(int s,const graph_t& g){
        int n=g.size();
        std::vector<cost_t> res(n,INF);
        std::vector<char> used(n,0);
        res[s]=0;
        std::priority_queue<std::pair<cost_t,int>,std::vector<std::pair<cost_t,int>>,std::greater<>> que;
        que.push(std::make_pair(cost_t(0),s));
        while(!que.empty()){
            auto p=que.top(); que.pop();
            cost_t dist=p.first;
            int v=p.second;
            if(used[v]) continue;
            used[v]=true;
            for(int i=0;i<g[v].size();i++){
                cost_t tdist=dist+g[v][i].weight;
                if(tdist<res[g[v][i].to]){
                    res[g[v][i].to]=tdist;
                    que.push(std::make_pair(tdist,g[v][i].to));
                }
            }
        }
        return res;
    }

    // using Weight=long long;
    // struct Edge{
    //     int to;
    //     Weight weight;
    // };
    // using Edges=vector<Edge>;
    // using Graph=vector<Edges>;
}
// AOJ(GRL_1_A)
#include<iostream>
using namespace std;
using namespace ProconLib;
using Weight=long long;
struct Edge{
    int to;
    Weight weight;
};
using Edges=vector<Edge>;
using Graph=vector<Edges>;
int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n,m,r;
    cin>>n>>m>>r;
    Graph g(n);
    for(int i=0;i<m;i++){
        int u,v;
        Weight d;
        cin>>u>>v>>d;
        g[u].push_back(Edge{v,d});
    }
    
    auto d=Dijkstra<Graph,Weight>(r,g);
    for(int i=0;i<n;i++){
        if(d[i]==INF<Weight>()) cout<<"INF\n";
        else cout<<d[i]<<"\n";
    }

    return 0;
}



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

int main()
{
    //　数値の定義
    //　文字列の定義
    int amount; //入力文字
    cin >> amount;
    
    // 識別
    int five_hand_yen = 0;
    int five_yen = 0;

    five_hand_yen = amount / 500;
    amount = amount - 500 * five_hand_yen;
    five_yen = amount / 5;

    //判定
    int happy = 0;
    happy = five_hand_yen * 1000 + five_yen * 5;


    cout << happy << endl;


    return 0;
}

Measured memory_bytes: 888
/*@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
Code author: Saurabh Singhal
Code copy karne vaale tera muh kaala
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@*/

#include<bits/stdc++.h>
#define mp(a,b) make_pair(a,b)
#define pb push_back
#define ppb pop_back

using namespace std;
typedef long long int ll;
typedef vector<int> vi_t;
typedef vector<ll> vll_t;
int t=1;
vll_t a,b;
int  main(){
	// #ifndef ONLINE_JUDGE
 //    // for getting input from input.txt
 //    freopen("input.txt", "r", stdin);
 //    // for writing output to output.txt
 //    freopen("output.txt", "w", stdout);
	// #endif
	int n;string s;cin>>n>>s;
	vector<int>w(n,0),e(n,0);
	if(s[0]=='E'){
		e[0]++;
	}
	else{
		w[0]++;
	}
	for(int i=1;i<s.size();i++){
		if(s[i]=='E'){
			e[i]=e[i-1]+1;
			w[i]=w[i-1];
		}
		else{
			w[i]=w[i-1]+1;
			e[i]=e[i-1];
		}
	}
	// for(int i=0;i<n;i++){
	// 	cout<<e[i]<<" ";
	// }
	// cout<<endl;
	// for(int i=0;i<n;i++){
	// 	cout<<w[i]<<" ";
	// }
	// cout<<endl;
	int ans=INT_MAX;
	for(int i=1;i<n-1;i++){
		//cout<<"i="<<
		int leftw=w[i-1];
		int righte=e[n-1]-e[i];
		ans=min(ans,leftw+righte);
	}
	ans=min(ans,e[n-1]-e[0]);
	ans=min(ans,w[n-2]);
	cout<<ans<<endl;
}

Measured memory_bytes: 3076
#include <iostream>
using namespace std;
typedef int disp;

class dice {
	public:
		disp surface[7];
		void roll(char d) {
			if (d == 'E') {
				disp tmp = surface[1];
				surface[1] = surface[4];
				surface[4] = surface[6];
				surface[6] = surface[3];
				surface[3] = tmp;
			}
			if (d == 'N') {
				disp tmp = surface[1];
				surface[1] = surface[2];
				surface[2] = surface[6];
				surface[6] = surface[5];
				surface[5] = tmp;
			}
			if (d == 'S') {
				disp tmp = surface[1];
				surface[1] = surface[5];
				surface[5] = surface[6];
				surface[6] = surface[2];
				surface[2] = tmp;
			}
			if (d == 'W') {
				disp tmp = surface[1];
				surface[1] = surface[3];
				surface[3] = surface[6];
				surface[6] = surface[4];
				surface[4] = tmp;
			}
		};
};

main () {
	dice a;
	for (int i=1; i<=6; i++) cin >> a.surface[i];
	string str;
	cin >> str;
	for (int i=0; i<str.length(); i++) a.roll(str[i]);
	cout << a.surface[1] << endl;
}

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

using namespace std;

typedef long long int ll;
typedef long double ld;

int main(){
	ios_base::sync_with_stdio(false);
    cin.tie(NULL); cout.tie(NULL);
    
	int n, arr[100010];
	
	cin >> n;
	for(int i = 1; i <= n; i++){
		cin >> arr[i];
	}
	
	sort(arr + 1, arr + n + 1);
	
	int ans = 0;
	
	ans = arr[n / 2 + 1] == arr[n / 2] ? 0 : arr[n / 2 + 1] - arr[n / 2];
	
	cout << ans << endl;


	return 0;
}




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

int main() {
  ll L, R;
  vector<int> arr(2040, 0);
  cin >> L >> R;
  ll ans = INT_MAX;
  for(ll l=L; l<R; ++l) {
    for(ll r=l+1; r<=R; ++r) {
      ll rem = (l*r)%2019;
      if(arr[rem] == 3000) goto end;
      else ++arr[rem];
      ans = min(ans, (l*r)%2019);
    }
  }
  end:
  cout << ans << endl;
  return 0;
}

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

int main() {
  int n, m;
   cin >> n;
   int t[n];
   int i;
   for (i = 0; i < n; i++) {
     cin >> t[i];
   }
   cin >> m;
   int p[m], x[m];
   for (i = 0; i < m; i++) {
     cin >> p[i] >> x[i];
   }

   int time = 0;
   for (i = 0; i < n; i++) {
     time += t[i];
   }

   for (i = 0; i < m; i++) {
     cout << (time - (t[p[i] - 1] - x[i])) << endl;
   }

  return 0;
}


Measured memory_bytes: 256
//
// Created by David Sarpong on 5/6/20.
//

#include <iostream>
#include <string>
#include <queue>
using namespace std;

int main(int argc, char** argv) {
    string sa, sb, sc;

    cin >> sa >> sb >> sc;

    int i = 0, j = 0, k = 0;
    char turn = 'a';
    while (true) {
        if (turn == 'a') {

            if (i >= sa.size()) {
                cout << 'A' << endl;
                return 0;
            }

            turn = sa.at(i);
            i++;
        } else if (turn == 'b') {

            if (j >= sb.size()) {
                cout << 'B' << endl;
                return 0;
            }

            turn = sb.at(j);
            j++;
        } else {

            if (k >= sc.size()) {
                cout << 'C' << endl;
                return 0;
            }

            turn = sc.at(k);
            k++;
        }

//        cout << i << " " << j << " " << k << endl;
    }
}

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

namespace CsharpSpiral {
    partial class Program {
        static void Main(string[] args) {
            var sw = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false };
            Console.SetOut(sw);
            new Program().Solve(new ConsoleInput(Console.In, ' '));
            Console.Out.Flush();
        }
        public void Solve(ConsoleInput cin) {
            var N = cin.ReadInt;
            var M = cin.ReadInt;
            var res = N * (N - 1) + M * (M - 1);
            res /= 2;
            Console.WriteLine(res);
        }

    }

    static class ExtendClass {
        public static string Join<T>(this T[] X, string separator = " ") => string.Join(separator, X);
        public static S[] Clone<S>(this S[] src) where S : struct {
            var res = new S[src.Length];
            Array.Copy(src, res, src.Length);
            return res;
        }
    }

    class ConsoleInput {
        private readonly TextReader _stream;
        private readonly char _separator = ' ';
        private readonly Queue<string> inputStream;
        public ConsoleInput(TextReader stream, char separator = ' ') {
            this._separator = separator;
            this._stream = stream;
            inputStream = new Queue<string>();
        }
        public string Read {
            get {
                if(inputStream.Count != 0) return inputStream.Dequeue();
                string[] tmp = _stream.ReadLine().Split(_separator);
                for(int i = 0; i < tmp.Length; ++i)
                    inputStream.Enqueue(tmp[i]);
                return inputStream.Dequeue();
            }
        }
        public string ReadLine { get { return _stream.ReadLine(); } }
        public int ReadInt { get { return int.Parse(Read); } }
        public long ReadLong { get { return long.Parse(Read); } }
        public double ReadDouble { get { return double.Parse(Read); } }
        public string[] ReadStrArray(long N) {
            var ret = new string[N];
            for(long i = 0; i < N; ++i)
                ret[i] = Read;
            return ret;
        }
        public int[] ReadIntArray(long N) { var ret = new int[N]; for(long i = 0; i < N; ++i) ret[i] = ReadInt; return ret; }
        public long[] ReadLongArray(long N) { var ret = new long[N]; for(long i = 0; i < N; ++i) ret[i] = ReadLong; return ret; }
        public double[] ReadDoubleArray(long N) { var ret = new double[N]; for(long i = 0; i < N; ++i) ret[i] = ReadDouble; return ret; }
    }
}


Measured memory_bytes: 11220