akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define IOS ios_base::sync_with_stdio(0); cin.tie(0)
#define F first
#define S second
#define rep(i,n) for(int i=0;i<((int)n);i++)
#define rep1(i,n) for(int i=1;i<=((int)n);i++)
#define pb push_back
#define mp(a,b) make_pair(a,b)
const ll maxn=5000005;
const ll inf=1e9+7;
const ll mod=1e9+7;
ll n,m,l,q;
ll dp[305][305];
int main()
{
    while(cin>>n>>m>>l)
    {
        rep1(i,n) rep1(j,n)
        {
            if(i==j) dp[i][j]=0;
            else dp[i][j]=inf;
        }
        rep(i,m)
        {
            ll a,b,c;
            cin>>a>>b>>c;
            dp[a][b]=c;
            dp[b][a]=c;
            //cout<<"ha\n";
        }
        rep1(k,n) rep1(i,n) rep1(j,n)
        {
            dp[i][j]=min(dp[i][j],dp[i][k]+dp[k][j]);
        }
        rep1(i,n) rep1(j,n)
        {
            if(dp[i][j]<=l) dp[i][j]=1;
            else dp[i][j]=inf;
        }
        rep1(k,n) rep1(i,n) rep1(j,n)
        {
            dp[i][j]=min(dp[i][j],dp[i][k]+dp[k][j]);
        }
        cin>>q;
        while(q--)
        {
            ll s,t;
            cin>>s>>t;
            //cout<<"ha\n";
            if(dp[s][t]==inf) cout<<"-1\n";
            else cout<<dp[s][t]-1<<"\n";
        }


    }

}


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

using namespace __gnu_pbds;
using namespace std;

template<typename T>
using Tree = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

const int MOD = 998244353;

int mul(int a , int b) {
    return a * 1ll * b % MOD;
}

int add (int a , int b) {
    a += b;
    while (a >= MOD) a -= MOD;
    while (a < 0) a += MOD;
    return a;
}

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

    int n;
    cin >> n;

    vector<int> r(n) , c(n) , power(n + 1);
    vector<array<int , 2> > p(n);
    vector<array<int , 4> > ans(n);

    power[0] = 1;
    for (int i = 0 ;i < n ;i++) {
        cin >> r[i] >> c[i];
        p[i] = {r[i] , c[i]};
        power[i + 1] = mul(power[i] , 2);
    }

    vector<int> ind(n);
    iota(ind.begin() , ind.end() , 0);

    sort(ind.begin() , ind.end() , [&](int i , int j) {
       return p[i][0] < p[j][0];
    });


    sort(r.begin() , r.end());
    r.resize(unique(r.begin() , r.end()) - r.begin());

    Tree<int> os;
    int j = 0;
    for (int i = 0 ;i < r.size() ;i++) {
        int st = j;
        while (j < ind.size() && p[ind[j]][0] == r[i]) {
            os.insert(p[ind[j]][1]);
            j++;
        }

        j = st;
        while (j < ind.size() && p[ind[j]][0] == r[i]) {
            int lf = os.order_of_key(p[ind[j]][1] + 1);
            int rt = os.size() - os.order_of_key(p[ind[j]][1]);
            ans[ind[j]][2] = lf - 1;
            ans[ind[j]][0] = rt - 1;
            j++;
        }
    }


    sort(ind.begin() , ind.end() , [&](int i , int j) {
        return p[i][0] > p[j][0];
    });


    reverse(r.begin() , r.end());
    os.clear();

    j = 0;
    for (int i = 0 ;i < r.size() ;i++) {
        int st = j;
        while (j < ind.size() && p[ind[j]][0] == r[i]) {
            os.insert(p[ind[j]][1]);
            j++;
        }

        j = st;
        while (j < ind.size() && p[ind[j]][0] == r[i]) {
            int lf = os.order_of_key(p[ind[j]][1] + 1);
            int rt = os.size() - os.order_of_key(p[ind[j]][1]);
            ans[ind[j]][3] = lf - 1;
            ans[ind[j]][1] = rt - 1;
            j++;
        }
    }

    int res = mul(n , power[n - 1]);
    for (int i = 0 ;i < n ;i++) {
        int a = ans[i][0] , b = ans[i][1];
        int c = ans[i][2] , d = ans[i][3];
        res = add(res , mul(mul(power[a] - 1, power[d] - 1) , power[c]));
        res = add(res , mul(mul(power[a] - 1, power[d] - 1) , power[b] - 1));
        res = add(res , mul(mul(power[b] - 1, power[c] - 1) , power[a]));
        res = add(res , mul(mul(power[b] - 1, power[c] - 1) , power[d] - 1));
        res = add(res , mul(power[a] - 1 , mul(power[b] - 1 ,
                                               mul(power[c] - 1 , power[d] - 1))));
    }

    cout << res;
}

Measured memory_bytes: 20344
#!/usr/bin/env python3
# from typing import *


# def solve(K: int) -> str:
def solve(K):
    return "ACL" * K


# generated by online-judge-template-generator v4.7.1 (https://github.com/online-judge-tools/template-generator)
def main():
    K = int(input())
    a = solve(K)
    print(a)


if __name__ == '__main__':
    main()


Measured memory_bytes: 9140
#include <cstdio>
#include <cmath>
#include <iostream>
#include <vector>
#include <string>
#include <utility>
#include <algorithm>
#include <queue>
using namespace std;
#define FOR(i,a,b) for(ll i=a;i<b;i++)
#define REP(i,n) for(ll i=0;i<n;i++)
#define REPR(i,n) for(ll i=n-1;i>=0;i--)

typedef long long ll;
#define INF 1e18

int main(){
	ll n; cin>>n;
	ll m; cin>>m;
	vector<ll> p(m);
	vector<ll> s(m);
	REP(i,m){
		string tmp;
		cin>>p[i];
		p[i]--;
		cin>>tmp;
		if(tmp=="AC"){
			s[i]=1;
		}else{
			s[i]=0;
		}
	}
	vector<ll> ch(n,0);
	ll ans0=0;
	ll ans1=0;
	REP(i,m){
		if(s[i]==1 && ch[p[i]]==0){
			ch[p[i]]=1;
			ans1++;
		}
	}
	REP(i,m){
		if(ch[p[i]]==1){
			if(s[i]==1){
				ch[p[i]]=2;
			}else{
				ans0++;
			}
		}
	}
	cout<<ans1<<" "<<ans0<<endl;
	return 0;
}


Measured memory_bytes: 2560
#include <iostream>
using namespace std;
int main(){
	int a,b;
	cin >> a >> b;
	cout << "a";
	if(a < b){
		cout << " < ";
	}else if(a == b){
		cout << " == ";
	}else if(a > b){
		cout << " > ";
	}
	cout << "b" << endl;
	
return 0;
}

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

int main() {
  string  S, T;
  cin >> S >> T;
  int ans=0;

  for(int i=0; i<S.size(); i++){
    if(S.at(i)!=T.at(i)){
      ans=ans+1;
    }
  }

  cout << ans << endl;

return 0;
}


Measured memory_bytes: 3924
#include <bits/stdc++.h>
using namespace std;
long long n,i,j,a[55],mx,s;
struct segment_tree
{
    long long l,r,sum,add;
    void update(long long x)
    {
        sum+=(r-l+1)*x;
        add+=x;
    }
}c[400005];
void pushdown(long long id)
{
    if (c[id].add)
    {
        c[id*2].update(c[id].add);
        c[id*2+1].update(c[id].add);
        c[id].add=0;
    }
}
void pushup(long long id)
{
    c[id].sum=c[id*2].sum+c[id*2+1].sum;
}
void build(long long id,long long l,long long r)
{
    c[id].l=l; 
	c[id].r=r;
    c[id].sum=0; 
	c[id].add=0;
    if(l==r) c[id].sum=a[l];
    else
    {
        long long mid=l+(r-l)/2;
        build(id*2,l,mid);
        build(id*2+1,mid+1,r);
        pushup(id);
    }
}
void update(long long id,long long le,long long ri,long long x)
{
    if (le>c[id].r||ri<c[id].l) return;
    if (le<=c[id].l&&c[id].r<=ri) c[id].update(x);
    else
    {
        pushdown(id);
        update(id*2,le,ri,x);
        update(id*2+1,le,ri,x);
        pushup(id);
    }
}
long long query(long long id,long long le,long long ri)
{
    if (ri<c[id].l||c[id].r<le) return 0;
    if (le<=c[id].l&&c[id].r<=ri) return c[id].sum;
    long long ans=0;
    pushdown(id);
    ans+=query(id*2,le,ri);
    ans+=query(id*2+1,le,ri);
    pushup(id);
    return ans;
}
int main()
{
	cin>>n;for (i=1;i<=n;i++) cin>>a[i];build(1,1,n);
	for (;;)
	{
		//for (i=1;i<=n;i++) cerr<<query(1,i,i)<<' ';
		//cerr<<endl;
		mx=1;
		for (i=2;i<=n;i++)
		{
			if (query(1,i,i)>query(1,mx,mx)) mx=i;
		}
		if (query(1,mx,mx)<n) break;
		s+=(query(1,mx,mx)-(n-1)+n-1)/n;
		//cerr<<s<<endl;
		if (mx>1) update(1,1,mx-1,(query(1,mx,mx)-(n-1)+n-1)/n);
		if (mx<n) update(1,mx+1,n,(query(1,mx,mx)-(n-1)+n-1)/n);
		update(1,mx,mx,-((query(1,mx,mx)-(n-1)+n-1)/n*n));
	}
	cout<<s;
	return 0;
} 

Measured memory_bytes: 256
import java.util.*;
public class Main{
  public static void main(String[]args){
      Scanner sc = new Scanner(System.in);

      int[]  n = new int[3];

      for(int i =0;i<3;i++){
          n[i]=sc.nextInt();
        }

        Arrays.sort(n);
          System.out.print(n[2]*10+n[1]+n[0]);
      }

  }


Measured memory_bytes: 21716
#include<stdio.h>
int main()
{
    int a,i,j=0;

    scanf("%d",&a);

    int Ar[a];

    for(i = 0;i < a; i++)
    {
        scanf("%d", &Ar[i]);

        if(Ar[i] != i+1)
            j++;
    }

    if(j > 2)
        printf("NO\n");
    else
        printf("YES\n");

    return 0;
}


Measured memory_bytes: 128
#include <iostream>
#include <string>

using namespace std;
bool is_checked[30];

int main() {
    string s;
    cin >> s;
    for (char c: s) {
        int numc = c - 'a';
        if (is_checked[numc]) {
            cout << "no" << endl;
            return 0;
        }
        is_checked[numc] = true;
    }
    cout << "yes" << endl;
}

Measured memory_bytes: 256
def solve():
    from sys import stdin
    f_i = stdin
    
    N, M = map(int, f_i.readline().split())
    
    cleared = dict(zip(range(N), [False] * N))
    penalty = dict(zip(range(N), [0] * N))
    
    for i in range(M):
        p, S = f_i.readline().split()
        p = int(p) - 1
        if S == 'AC':
            cleared[p] = True
        elif not cleared[p]:
            penalty[p] += 1
    
    clear_count = list(cleared.values()).count(True)
    
    penalty_count = 0
    for k, v in penalty.items():
        if cleared[k]:
            penalty_count += v
    
    print(clear_count, penalty_count)

solve()

Measured memory_bytes: 28128
#include <bits/stdc++.h>
using namespace std;
long long gcd(long long a, long long b) {return b ? gcd(b, a % b) : abs(a);}
int main(void){
    // Your code here!
    long long N,X;
    cin >> N >> X;
    vector<long long> city(N);
    vector<long long> dis(N);
    for(int i=0;i<N;i++){
        cin >> city.at(i);
        dis.at(i)=max(city.at(i),X)-min(city.at(i),X);
    }
    sort(dis.begin(),dis.end());
    reverse(dis.begin(),dis.end());
    long long ans;
    for(int i=0;i<N;i++){
    	ans=gcd(ans,dis.at(i));
    }
    if(N==1){
    	ans=dis.at(0);
    }
    cout << ans << endl;
}   


Measured memory_bytes: 1792
using System;

class Program
{
    static void Main(string[] args)
    {
        var hw = Console.ReadLine().Split();
        var h = long.Parse(hw[0]);
        var w = long.Parse(hw[1]);
        var ans = Math.Min(f(h, w), f(w, h));
        Console.WriteLine(ans);
    }

    static long f(long x, long y)
    {
        var ans = long.MaxValue;

        for (long x1 = 1; x1 < x; x1++)
        {
            var x2 = (x - x1) / 2;
            var x3 = x - x1 - x2;

            var max = Math.Max(Math.Max(
                x1 * y,
                x2 * y),
                x3 * y);

            var min = Math.Min(Math.Min(
                x1 * y,
                x2 * y),
                x3 * y);

            ans = Math.Min(ans, max - min);

            var y1 = y / 2;
            var y2 = y - y1;

            max = Math.Max(Math.Max(
                x1 * y,
                (x - x1) * y1),
                (x - x1) * y2);

            min = Math.Min(Math.Min(
                x1 * y,
                (x - x1) * y1),
                (x - x1) * y2);

            ans = Math.Min(ans, max - min);
        }

        return ans;
    }
}


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

string S;

int main(){
  cin >> S;
  if (S[0]=='R' && S[1]=='R' && S[2]=='R') cout << 3 << endl;
  else if ((S[0]=='R' && S[1]=='R') || (S[1]=='R' && S[2]=='R')) cout << 2 << endl;
  else if (S[0]=='R' || S[1]=='R' || S[2]=='R') cout << 1 << endl;
  else cout << 0 << endl;
}


Measured memory_bytes: 3628
#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 a, b;
  cin >> a >> b;
  cout << (a * b % 2 ? "Odd" : "Even") << endl;
}



Measured memory_bytes: 256
import java.util.Scanner;

class Main {

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

        long x=stdIn.nextLong();
        long y=stdIn.nextLong();
        
        long t=x%y;
    
        if(t>=-(t-y)){
            System.out.println(Math.abs(t-y));
            
        }
        else{
            System.out.println(Math.abs(t));
            
        }
    }
}

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

using namespace std;

#define PB push_back
#define f first
#define s second

typedef long long ll;
typedef pair<ll, ll> pll;
typedef pair<int, int> pii;

const int MOD = 1000000007;
const int INF = 1000000007;

int main()
{
    ios_base::sync_with_stdio(0); cin.tie(0);
    int k, a, b;
    cin >> k >> a >> b;
    if(b/k > (a-1)/k)
    {
        cout << "OK";
    }
    else
    {
        cout << "NG";
    }
        return 0;

}


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

#define repd(i,a,b) for (ll i=(a);i<(b);i++)
#define rep(i,n) repd(i,0,n)
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
typedef long long ll;

const long long INF = 1LL << 60;
const long long MOD = 1000000007;

int main()
{
    ll N, K;
    cin >> N >> K;

    vector<ll> A(N);
    rep(i, N) {
        cin >> A[i];
    }

    ll ans = 0;
    rep(i, N) {
        ll cnt = 0;
        repd(j, i + 1, N) {
            if (A[i] > A[j]) cnt++;
        }
        ans += (cnt * K) % MOD;
        ans %= MOD;
    }

    sort(A.begin(), A.end());
    reverse(A.begin(), A.end());

    rep(i, N - 1) {
        ll gr = 0;
        repd(j, i + 1, N) {
            if (A[i] > A[j]) gr++;
        }
        ll tmp = K * (K - 1LL) / 2LL % MOD;
        tmp = gr * tmp % MOD;
        ans += tmp % MOD;
        ans %= MOD;
    }

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

Measured memory_bytes: 256
import sys
def LI2(): return list(map(int,sys.stdin.readline().rstrip()))  #空白なし
def S(): return sys.stdin.readline().rstrip()

N,P = map(int,S().split())
S = LI2()

if P == 2 or P == 5:  #10と素でない場合一番右の桁で決まる
    ans = 0
    for i in range(N):
        if S[i] % P == 0:
            ans += i+1
    print(ans)
    exit()

A = [0]  #A[i] = 下i桁をPで割った余り
for i in range(1,N+1):
    A.append((A[i-1]+pow(10,i,P)*S[N-i]) % P)

from collections import Counter

c = Counter(A)
B = c.values()

ans = 0

for i in B:
    ans += (i*(i-1)//2)

print(ans)

Measured memory_bytes: 13368
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<cassert>
#include<iostream>
#include<sstream>
#include<string>
#include<vector>
#include<queue>
#include<set>
#include<map>
#include<utility>
#include<numeric>
#include<algorithm>
#include<bitset>
#include<complex>

using namespace std;

typedef long long Int;
typedef vector<int> vint;
typedef pair<int,int> pint;
#define mp make_pair

template<class T> void pv(T a, T b) { for (T i = a; i != b; ++i) cout << *i << " "; cout << endl; }
template<class T> void chmin(T &t, T f) { if (t > f) t = f; }
template<class T> void chmax(T &t, T f) { if (t < f) t = f; }
int in() { int x; scanf("%d", &x); return x; }

int main() {
	int n;
	while(cin>>n){
		printf("3C%02d\n",n%39?n%39:39);
	}
	return 0;
}

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

using namespace std;

typedef long long ll;

const ll upb = 1e18;

int main(){
  ll N;
  cin >> N;
  
  vector<ll> A(N);
  for(int i=0; i<N; i++){
    cin >> A[i];
    if(A[i]==0){
      cout << 0 << endl;
      return 0;
    }
  }
  
  
  ll ret = 1;
  double logret = 0;
  int i=0;
  for(i=0; i<N; i++){
    double logA = log10(A[i]);
    if(logret + logA > 19) break;
    ret *= A[i];
    if (ret > upb) break;
    logret = log10(ret);
  }
  
  if(i != N) ret = -1;
  cout << ret << endl;
  return 0;
}

Measured memory_bytes: 4116
#!/usr/bin/env python3
import sys


def solve(S: str):
    alp = sorted(set(S))
    for abc in [chr(i) for i in range(97, 97 + 26)]:
        if not abc in alp:
            print(abc)
            break
    else:
        print("None")
    return


# Generated by 1.1.7.1 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word

    tokens = iterate_tokens()
    S = next(tokens)  # type: str
    solve(S)


if __name__ == "__main__":
    main()


Measured memory_bytes: 3316
my ($r, $g, $b, $n) = split(/\s+/, <>);

if ($r < $b) { my $swap = $r; $r=$b; $b=$swap; }
if ($g < $b) { my $swap = $g; $g=$b; $b=$swap; }

my $count=0;
for my $i (0..int($n/$r)) {
    for my $j (0..int($n/$g)) {
	my $k=$n-$r*$i-$g*$j;
	last if ($k < 0);
	if ($k % $b == 0) {
	    $count++;
	}
    }
}
print $count, "\n";


Measured memory_bytes: 512
#include <iostream>
using namespace std;
int main(){
    long s;
    cin >> s;

    s = s%10;
    
    if(s == 3){
        cout << "bon" << endl;
    }else if (s == 0 || s == 1 || s == 6 || s == 8){
        cout << "pon" << endl;
    }else{
        cout << "hon" << endl;
    }
}

Measured memory_bytes: 3636
import Data.Array

main = do
  li <- getLine
  let n = read li
  li <- getLine
  let as = map read $ words li
  let ans = compute n as
  print ans

compute :: Int -> [Int] -> Int
compute n as = length [ () | (i,ai) <- zip [1..] as, i < ai, i == ar ! ai ]
  where
    ar = listArray (1,n) as


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

using namespace std;

#define ll long long int

int main()
{
ios_base::sync_with_stdio(false);
cout.tie(NULL);
cin.tie(NULL);
              ll n,x,t,ans;
              cin>>n>>x>>t;
              ans=n/x;
              if(n%x!=0)
                ans++;
              ans*=t;
              cout<<ans;
              return(0);
}


Measured memory_bytes: 3604
#include <cstdio>
using namespace std;
#define MIN(a, b) (((a) > (b)) ? (b) : (a))
int main() {
	int Q, H, S, D, N;
	scanf("%d %d %d %d %d", &Q, &H, &S, &D, &N);
	long long unit_min = S;
	unit_min = MIN(unit_min, 2 * H);
	unit_min = MIN(unit_min, 4 * Q);
	long long Dunit_min = MIN(D, unit_min * 2);
	long long value = 0;
	if(N % 2 == 1) {
		value += unit_min;
	}
	value += Dunit_min * (N / 2);
	printf("%lld", value);
	return 0;
}

Measured memory_bytes: 128
#include <iostream>
#include <cstring>
#include <map>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <set>
#include <vector>
#include <queue>
#include <list>
#include <numeric>
#include <stdio.h>
#include <string>
#include <cstdlib>
#include <math.h>
#include <stack>
#include <climits>
#include <bitset>

using namespace std;
typedef long long ll;

ll gcd(ll x, ll y) {
  ll tmp = 0;
  if (x < y){
    tmp=x;
    x=y;
    y=tmp;
  }
  while (y > 0) {
    ll r = x % y;
    x = y;
    y = r;
  }
  return x;
}

//for(int i = ; i < ; i++){}

int main(){
  int a,b,c;
  cin>>a>>b>>c;
  if(a==b)cout<<c<<endl;
  else if(b==c)cout<<a<<endl;
  else cout<<b<<endl;
  return 0;
}




Measured memory_bytes: 256
#include<iostream>
#include<stdio.h>
//#include <bits/stdc++.h>
#include<vector>
#include<float.h>
#include<iomanip>
#include<algorithm>
#include<string>
#include<cstring>
#include<math.h>
#include<cmath>
#include<sstream>
#include<set>
#include<map>
#include<queue>
#include<cassert>
#include<cmath>
#include<cstdint>

#define INF 1e9
#define rep(i,n)for(int i=0;(i)<(int)(n);i++)
#define REP(i,a,b)for(int i=(int)(a);(i)<=(int)(b);i++)
#define VEC(type, c, n) std::vector<type> c(n);for(auto& i:c)std::cin>>i;
#define vec(type,n) vector<type>(n)
#define vvec(m,n) vector<vector<int>> (int(m),vector<int>(n))
#define ALL(a)  (a).begin(),(a).end()
#define pb push_back
#define sz size()

using namespace std;
using ll = long long;
using Graph = vector<vector<int>>;
using P = pair<ll, ll>;

int cnt[3];

int main(){
    string s;
    cin >> s;
    rep(i, s.sz)cnt[s[i] - 'a']++;
    int mi = INF;
    rep(i, 3)mi = min(mi, cnt[i]);
    rep(i, 3)cnt[i] -= mi;
    bool f = true;
    rep(i, 3)if(cnt[i] > 1)f = false;
    cout << (f ? "YES" : "NO") << endl;
}

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

int main(){
    long long N;
    cin >> N;
    long long i;
    bool counta = 0;
    for(i = 0; i <= 5; i++){
        if(N%10 == 7) counta = 1;
        N = N/10;
    }
    if(counta) cout << "Yes" << endl;
    else cout << "No" << endl;
    system("pause");
    return 0;
}

Measured memory_bytes: 3660
#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;

int main()
{

    int N,Y;
    cin >> N >> Y;

    int x = Y / 10000;
    int y = (Y % 10000) / 5000;
    int z = (Y - x * 10000 - y * 5000) / 1000;

    while (N > x+y+z) {
        int d = N - x-y-z;
        if (d >= 9 && x >= 1) {
            int xx = min(d / 9, x);
            x -= xx;
            z += xx * 10;
        } else if (d >= 5 && x >= 1) {
            int xx = min(d / 5, x);
            x -= xx;
            y += xx * 1;
            z += xx * 5;
        } else if (d >= 4 && y >= 1) {
            int yy = min(d / 4, y);
            y -= yy;
            z += yy * 5;
        } else if (d >= 1 && x >= 1) {
            int xx = min(d, x);
            x -= xx;
            y += xx * 2;
        } else {
            break;
        }
    }

    if (N == x+y+z) {
        cout << x << " " << y << " " << z << endl;
    } else {
        cout << "-1 -1 -1" << endl;
    }

    return 0;
}

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

int main(){
    map<ll,ll> c;
    ll N;
    cin >> N;
    rep(i, 0, N){
        ll a; cin >> a;
        c[a]++;
    }
    ll R = 0;
    for(auto aa : c){
        R += aa.second - 1;
    }
    if(R%2 == 1){
        cout << c.size()-1 << endl;
    }else{
        cout << c.size() << endl;
    }
    return 0;
}

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



int main() {
  ll x,y,ans=0;
  cin >> x>>y;
  while(y>=x){
    x*=2;
    ans++;
  }
  cout << ans <<endl;
}


Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<cmath>
#include<climits>
#include<map>
#include<set>
#include<queue>
#include<stack>
#include<bitset>
#include<iomanip>
using namespace std;

#define rep(i,j,n) for(int i=(j);i<(n);i++)
#define rep2(i,j,n) for(int i=(j);i<=(n);i++)
#define all(i) i.begin(),i.end()

typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef vector<string> vs;
typedef vector<vector<string>> vvs;
typedef pair<int, int> pi;
typedef long long i64;

int main() {
	int n;
	cin >> n;
	vi c(n - 1), s(n - 1), f(n - 1);
	rep(i, 0, n - 1) {
		cin >> c[i] >> s[i] >> f[i];
	}
	rep(i, 0, n) {
		int time = 0;
		rep(j, i, n - 1) {
			time += (f[j] - (time % f[j])) % f[j];
			if (time < s[j]) {
				time += s[j] - time;
			}
			time += c[j];
		}
		cout << time << endl;
	}
}

Measured memory_bytes: 256
from sys import stdin
from math import sqrt, factorial

def input():
    return stdin.readline()[:-1]


def intput():
    return int(input())


def sinput():
    return input().split()


def intsput():
    return map(int, sinput())



def distance(a, b):
    dx = a[0] - b[0]
    dy = a[1] - b[1]
    return sqrt(dx ** 2 + dy ** 2)

n = intput()

towns = []
dists = []

for _ in range(n):
    towns.append(list(intsput()))

for i in range(n):
    for j in range(i + 1, n):
        dists.append(distance(towns[i], towns[j]))

s = sum(dists)

print(s * 2 / n)


Measured memory_bytes: 38384
// C - Switches
#include <bits/stdc++.h>

using namespace std;

int main(int argc, char *argv[])
{
	int n, m;
	cin >> n >> m;
	vector<int> s(n);
	for (int i = 0; i < m; i++) {
		int k, j;
		cin >> k;
		while (k--) {
			cin >> j;
			s[j - 1] |= (1 << i);
		}
	}
	int t, z = 0;
	for (int i = 0; i < m; i++) cin >> t, z += (t << i);

	int ans = 0;
	for (int i = 0; i < (1 << n); i++) {
		int y = 0;
		for (int j = 0; j < n; j++)
			if (i & (1 << j)) y ^= s[j];
			if (y == z) ans++;
	}

	cout << ans << endl;

	return 0;
}


Measured memory_bytes: 256
class Main{public static void main(String[]z)throws Exception{int n,b=0,s=0,r=0;for(;(n=System.in.read())>0;){n-=48;if(b>0&&!(0<=n&&n<=9)){r+=s;b=0;}if(0<=n&&n<=9)if(b>0)s=10*s+n;else{s=n;b=1;}}System.out.println(r);}}

Measured memory_bytes: 9116
#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 P(p) cout<<(p)<<endl;
#define PP(p) cout<<(p)<<" ";
#define INF 1e18

typedef long long ll;
#define int ll
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int, int> pi;
//int dy[8]={1,1,1,0,-1,-1,-1,0};
//int dx[8]={-1,0,1,1,1,0,-1,-1};
int dx[4]={0,1,0,-1};
int dy[4]={1,0,-1,0};
int N,M;
vi a,b;
#define MAX_V 100000

vi G[MAX_V];

vi depth;

void inputG(int a,int b){
    G[a].push_back(b);
    G[b].push_back(a);
}

signed main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    cin>>N>>M;
    depth.resize(N,INF);
    a.resize(M+1);b.resize(M+1);
    rep(i,M){
        cin>>a[i]>>b[i];
        a[i]--;b[i]--;
        inputG(a[i],b[i]);
    }
    queue<int> que; //now
    que.push(0);
    depth[0]=0;
    while ((!que.empty())){
        int now = que.front();
        que.pop();
        rep(i,G[now].size()){
            int ni = G[now][i];
            if( depth[ni]> depth[now]+1){
                depth[ni] = depth[now]+1;
                que.push(ni);
            }
        }
    }
    vi ans;
    REP(i,1,N){
        bool f = false;
        rep(j,G[i].size()){
            if(depth[i]-1 == depth[G[i][j]]){
                ans.push_back(G[i][j]);
                f = true;
                break;
            }
        }
        if(!f){
            cout<<"No"<<endl;
            return 0;
        }
    }
    cout<<"Yes"<<endl;
    rep(i,ans.size()){
        cout<<ans[i]+1<<endl;
    }
    return 0;
}


Measured memory_bytes: 17096
#include <iostream>
#include <fstream>
#include <iomanip>
#include <climits>
#include <limits>
#include <algorithm>
#include <array>
#include <vector>
#include <deque>
#include <queue>
#include <list>
#include <stack>
#include <string>
#include <functional>
#include <numeric>
#include <map>
#include <set>
#include <cstdlib>
#include <bitset>
#include <unordered_map>
#include <random>
#include <cmath>
#include <complex>
// #include "utiltime.hpp"

using namespace std;

typedef long long int ll;
typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef pair<int, int> P;
typedef pair<ll, ll> Pll;
typedef vector<ll> vll;
typedef vector<vector<ll>> vvll;
typedef complex<double> cdouble;

const int INFL = (int)1e9;
const ll INFLL = (ll)1e18;
const double INFD = numeric_limits<double>::infinity();
const double PI = 3.14159265358979323846;
#define Loop(i, n) for(int i = 0; i < (int)(n); i++)
#define Loopll(i, n) for(ll i = 0; i < (ll)(n); i++)
#define Loop1(i, n) for(int i = 1; i <= (int)(n); i++)
#define Loopll1(i, n) for(ll i = 1; i <= (ll)(n); i++)
#define Loopr(i, n) for(int i = (int)(n) - 1; i >= 0; i--)
#define Looprll(i, n) for(ll i = (ll)(n) - 1; i >= 0; i--)
#define Loopr1(i, n) for(int i = (int)(n); i >= 1; i--)
#define Looprll1(i, n) for(ll i = (ll)(n); i >= 1; i--)
#define Foreach(buf, container) for(auto buf : container)
#define Loopdiag(i, j, h, w, sum) for(int i = ((sum) >= (h) ? (h) - 1 : (sum)), j = (sum) - i; i >= 0 && j < (w); i--, j++)
#define Loopdiagr(i, j, h, w, sum) for(int j = ((sum) >= (w) ? (w) - 1 : (sum)), i = (sum) - j; j >= 0 && i < (h); j--, i++)
#define Loopdiagsym(i, j, h, w, gap) for (int i = ((gap) >= 0 ? (gap) : 0), j = i - (gap); i < (h) && j < (w); i++, j++)
#define Loopdiagsymr(i, j, h, w, gap) for (int i = ((gap) > (h) - (w) - 1 ? (h) - 1 : (w) - 1 + (gap)), j = i - (gap); i >= 0 && j >= 0; i--, j--)
#define Loopitr(itr, container) for(auto itr = container.begin(); itr != container.end(); itr++)
#define printv(vector) Loop(extra_i, vector.size()) { cout << vector[extra_i] << " "; } cout << endl;
#define printmx(matrix) Loop(extra_i, matrix.size()) { Loop(extra_j, matrix[extra_i].size()) { cout << matrix[extra_i][extra_j] << " "; } cout << endl; }
#define quickio() ios::sync_with_stdio(false); cin.tie(0);
#define readfile(filename) ifstream in(filename); cin.rdbuf(in.rdbuf());
#define bitmanip(m,val) static_cast<bitset<(int)m>>(val)
bool nearlyeq(double x, double y) { return abs(x - y) < 1e-9; }
bool inrange(int x, int t) { return x >= 0 && x < t; }
ll rndf(double x) { return (ll)(x + (x >= 0 ? 0.5 : -0.5)); }
ll floorsqrt(double x) { ll m = (ll)sqrt(x); return m + (m * m <= (ll)(x) ? 0 : -1); }
ll ceilsqrt(double x) { ll m = (ll)sqrt(x); return m + ((ll)x <= m * m ? 0 : 1); }
ll rnddiv(ll a, ll b) { return (a / b + (a % b * 2 >= b ? 1 : 0)); }
ll ceildiv(ll a, ll b) { return (a / b + (a % b == 0 ? 0 : 1)); }
ll gcd(ll m, ll n) { if (n == 0) return m; else return gcd(n, m % n); }

/*******************************************************/

int main() {
	int n, a, b; cin >> n >> a >> b;
	cout << min(a, b) << " " <<  max(0, a + b - n) << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define debug(x) cout << '>' << #x << ':' << x << endl;
#define ll long long

int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	ll x, y;
	cin >> x >> y;
	if (x == y) {
		cout << 0 << endl;
	} else if (x > y) {
		cout << min(2 + abs(x - y), 1 + abs(x + y));
	} else {
		cout << min(abs(y - x), abs((-y) - x) + 1);
	}

	return 0;

}


Measured memory_bytes: 3564
#include<iostream>
using namespace std;
 
int main() 
{
  int n;
  while(true) 
  {
    cin>>n;
    if(!n) break;
    int c = 5,sum = 0;
    while(c<=n) 
     {
      sum += n/c;
      c *= 5;
    }
    cout<<sum<<endl;
  }
}

Measured memory_bytes: 1160
#include "bits/stdc++.h"

#define REP(i, n) for (ll i = 0; i < ll(n); ++i)
#define RREP(i, n) for (ll i = ll(n) - 1; i >= 0; --i)
#define FOR(i, m, n) for (ll i = m; i < ll(n); ++i)
#define RFOR(i, m, n) for (ll i = ll(n) - 1; i >= ll(m); --i)
#define ALL(v) (v).begin(), (v).end()
#define UNIQUE(v) v.erase(unique(ALL(v)), v.end());
#define INF 1000000001ll
#define MOD 1000000007ll
#define EPS 1e-9

constexpr int dx[8] = {1, 1, 0, -1, -1, -1, 0, 1};
constexpr int dy[8] = {0, 1, 1, 1, 0, -1, -1, -1};

using namespace std;

using ll = long long;
using vi = vector<int>;
using vl = vector<ll>;
using vvi = vector<vi>;
using vvl = vector<vl>;
using pii = pair<int, int>;
using pll = pair<ll, ll>;

template <class T> bool chmin(T &a, const T &b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}
template <class T> bool chmax(T &a, const T &b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  using ld = long double;
  ld a, b, x;
  cin >> a >> b >> x;
  x /= a;
  ld pi = acos(-1);
  if (x <= a * b / 2) {
    ld t = 2 * x / b;

    cout << fixed << setprecision(12) << atan2(b, t) * 180 / pi << endl;
  } else {
    ld t = (x - a * b / 2) * 2 / a;
    cout << fixed << setprecision(12) << 90 - atan2(a, b - t) * 180 / pi
         << endl;
  }
}


Measured memory_bytes: 256
#include<stdio.h>

int main()
{
  int i, j, k;   //Loop counter variable
  int A[100];       //Array
  int N;         //Element count
  int v;         //Variable to store temporarily

  scanf("%d", &N);   //input of element count
  
  //error processing
  if( 1 > N || N > 100 ) printf("入力された要素数は範囲外です。\n");
  
  else{
    //input of element
    for( i = 0 ; i < N ; i++ ){
      scanf("%d", &A[i]); 
      //error processing
      if( 0 > A[i] || 1000 < A[i] )
	printf("入力された要素は範囲外です。\n");
    }
    
    for( i = 0 ; i < N ; i++ ){
      printf("%d", A[i]);
      if( i < N-1 ) printf(" ");
    }
    printf("\n");

    //ascending sort
    for( i = 1 ; i <= N-1 ; i++ ){   
      v = A[i];
      j = i - 1;
      while( j >= 0 && A[j] > v ){
	A[j+1] = A[j];
	j--;
	A[j+1] = v;
      }
      //output of intermediate results
      for( k = 0 ; k < N ; k++ ){
	printf("%d", A[k]);
	if( k < N-1 ) printf(" ");
      }
      printf("\n");
    }
  }
  
  return 0;
}

Measured memory_bytes: 604
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
using namespace std;
#define int         long long
#define mod         1000000007
#define FAST        ios::sync_with_stdio(0),cin.tie(0),cout.tie(0);
#define f(i,n)      for(int i=0;i<n;i++)
#define fp(i,k,n)   for(int i=k;i<=n;i++)
#define fr(i,k,n)   for(int i=k;i>=n;i--)
#define pb          push_back
#define pii         pair<int,int>
#define vi          vector<int>
#define vii         vector<pii>
#define dbg(x)      cout << (#x) << " is " << (x) << '\n' 
#define F           first
#define S           second
#define sz(x)       (int)(x).size()
#define lb          lower_bound
#define ub          upper_bound
#define mems(x)     memset(x,0,sizeof(x))
#define all(a)      a.begin(),a.end()
typedef tree<int,null_type,less_equal<int>,rb_tree_tag,tree_order_statistics_node_update>ordered_set;
/*---------------------------------------------------------------------------------------------------*/

void solve()
{
  string a,b;
  cin >> a >> b;
  int n=a.length(),m=b.length();
  int dp[n+1][m+1];
  mems(dp);
  f(i,n+1)
  {
      f(j,m+1)
      {
          if(i==0 || j==0)
            continue;
           if(a[i-1]==b[j-1])
            dp[i][j]=max(dp[i][j],dp[i-1][j-1]+1);
           else
            dp[i][j]=max({dp[i][j],dp[i-1][j],dp[i][j-1]});
      }
  }
  int len=dp[n][m];
  string s;
  s="";
  int l=n,r=m;
  while(len>0)
  {
      if(a[l-1]==b[r-1])
      {
          s+=a[l-1];
          l--;r--;
          len--;
      }
      else if(dp[l-1][r]>dp[l][r-1])
        l--;
      else
        r--;
  }
  reverse(all(s));
  cout << s << '\n';
  return;
} 

signed main()
{
  FAST
  int T=1;
//   cin >> T;
  while(T--)
  {
    solve();
  }
  return 0;
}


Measured memory_bytes: 73984
#pragma GCC target("avx2")
#pragma GCC optimize ("O3")
#pragma GCC optimize ("unroll-loops")
#include<bits/stdc++.h>

#define f			first
#define sz(a)       ((int)(a).size())
#define s			second
#define all(v)		v.begin(),v.end()
#define pii 		pair<int,int>
#define vpii 		vector<pii>
#define eb			emplace_back
#define pb			push_back
#define fo(i,n)		for(int i=0;i<n;i++)
#define Fo(i,k,n)	for(int i=k;i<n;i++)
#define vi			vector<int>
#define deb(x)		cout << #x << " " << x << endl

using namespace std;
using ll  = long long;
using lld = long double;

const int oo = 0x3f3f3f3f;
const ll MOD = 1000000007;
const int N = 1e5 + 10;
int n , m;
vi adj[N];
deque<int> dq;
bool vis[N];
int dp[N];

void dfs(int src){
    vis[src] = 1;
    for(int i : adj[src])
        if(vis[i]) continue;
        else
            dfs(i);
    dq.push_front(src);
}

inline void relax(int & a , int b){
    a = max(a , b);
}

signed main(){

#ifndef ONLINE_JUDGE
	//freopen("in.txt" , "r" , stdin);
#endif
	ios_base::sync_with_stdio(0);cin.tie(0);

    cin >> n >> m;
    fo(i , m){
        int u , v;
        cin >> u >> v;
        u--;--v;
        adj[u].pb(v);
    }
    
    fo(i , n) if(!vis[i]) dfs(i);

    for(int i : dq){
        for(int j : adj[i])
            relax(dp[j] , 1 + dp[i]);
    }

    cout << *max_element(dp , dp + n) << '\n';

    return 0;
}



Measured memory_bytes: 13924
#include<stdio.h>
#include<string.h>

void print(char *str, int p, int q){
  char *ptr = str + p;
  for(int i=p;i<=q;i++){
    printf("%c", *ptr++);
  }
  printf("\n");
}

void reverse(char *str, int p, int q){
  char tmp[q-p+1], *ptmp=tmp+q-p, *ptr = str + p;
  for(int i=p;i<=q;i++){
    strncpy(tmp, ptr, q-p+1);
  }
  for(int j=0;j<=q-p;j++){
    str[p+j] = *ptmp--;
  }
}

void replace(char *str, int p, int q, char *tmp){
  char *ptr=str+p, *ptmp=tmp;
  for(int i=p;i<=q;i++){
    *ptr++ = *ptmp++;
  }
}


int main(void){
  int times, p, q;
  char tmp[1000], str[1000];

  scanf("%s", str);
  scanf("%d", &times);
  for(int i=0;i<times;i++){
    scanf("%s", tmp);
    if(strcmp(tmp, "print") == 0){
      scanf("%d %d", &p, &q);
      print(str, p, q);

    }else if(strcmp(tmp, "reverse") == 0){
      scanf("%d %d", &p, &q);
      reverse(str, p, q);

    }else{
      scanf("%d %d %s", &p, &q, tmp);
      replace(str, p, q, tmp);
    }
  }
  return 0;
}



Measured memory_bytes: 2140
N, M = map(int, input().split())
E = [list(map(int, input().split())) for k in range(M)]

ans = 0
for k in range(M):
    F = E[:k]+E[k+1:]
    D = [[10**9+7 for l in range(N)] for m in range(N)]
    for p in range(N):
        D[p][p] = 0
    for n in F:
        D[n[0]-1][n[1]-1] = D[n[1]-1][n[0]-1] = 1
    for s in range(N):
        for t in range(N):
            for u in range(N):
                if D[t][u] > D[t][s] + D[s][u]:
                    D[t][u] = D[t][s] + D[s][u]
    f = 0
    for p in range(N):
        for q in range(N):
            if D[p][q] > N:
                f = 1
    ans += f
print(ans)

Measured memory_bytes: 3316
using System;
using System.Diagnostics.CodeAnalysis;
using System.Globalization;
using System.Text;

namespace ChokudaiScanner
{
    class MainClass
    {
        static void Main()
        {
            Scanner cin = new Scanner();

            int N = cin.NextInt() + 1;
            int[][] vs = new int[N][];
            vs[0] = new int[3];
            for (int i = 1; i < N; i++)
            {
                vs[i] = cin.ArrayInt(3);
            }
            string ans = "Yes";
            
            for(int i = 1; i < vs.Length; i++)
            { 
                int dt = vs[i][0] - vs[i-1][0];
                int dist = Math.Abs(vs[i][1] - vs[i-1][1]) + Math.Abs(vs[i][2] - vs[i-1][2]);
                if (dt < dist)
                {
                    ans = "No";
                    break;
                }
                if (dt % 2 != dist % 2)
                {
                        ans = "No";
                        break;
                }
            }
            Console.WriteLine(ans);
        }
    }

    class Scanner
    {
        string[] s;
        int i;

        char[] cs = new char[] { ' ' };

        public Scanner()
        {
            s = new string[0];
            i = 0;
        }

        public string Next()
        {
            if (i < s.Length) return s[i++];
            string st = Console.ReadLine();
            while (st == "") st = Console.ReadLine();
            s = st.Split(cs, StringSplitOptions.RemoveEmptyEntries);
            if (s.Length == 0) return Next();
            i = 0;
            return s[i++];
        }

        public string[] ArrayNext(int N)
        {
            string[] Array = new string[N];
            for (int i = 0; i < N; i++)
            {
                Array[i] = Next();
            }
            return Array;
        }

        public int NextInt()
        {
            return int.Parse(Next());
        }
        public int[] ArrayInt(int N, int add = 0)
        {
            int[] Array = new int[N];
            for (int i = 0; i < N; i++)
            {
                Array[i] = NextInt() + add;
            }
            return Array;
        }

        public long NextLong()
        {
            return long.Parse(Next());
        }

        public long[] ArrayLong(int N, long add = 0)
        {
            long[] Array = new long[N];
            for (int i = 0; i < N; i++)
            {
                Array[i] = NextLong() + add;
            }
            return Array;
        }

        public double NextDouble()
        {
            return double.Parse(Next());
        }


        public double[] ArrayDouble(int N, double add = 0)
        {
            double[] Array = new double[N];
            for (int i = 0; i < N; i++)
            {
                Array[i] = NextDouble() + add;
            }
            return Array;
        }
    }
}



Measured memory_bytes: 22212
#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 - 1; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i <= n; i++)
#define FORR(i, m, n) for(int i = m; i >= n; i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
 
using ll = long long;
using vll = vector<ll>;
using vvll = vector<vector<ll>>;
using P = pair<ll, ll>;

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

    string s;
    cin >> s;
    ll n = s.size(), sum = 0;
    for(int i = 0; i < (1<<(n - 1)); i++){
        vll a(n, 0);
        a[n - 1] = 1;
        REP(j, n - 1) if((i>>j) & 1) a[j] = 1;
        ll res = 0, dig;
        REP(j, n){
            if(a[j]){
                dig = j - res + 1;
                vll tmp;
                REP(k, dig){
                    tmp.push_back(s[res + k] - '0');
                    if(k) REP(l, tmp.size() - 1) tmp[l] *= 10;
                }
                REP(k, dig) sum += tmp[k];
                res = j + 1;
            }
        }
    }
    cout << sum << endl;
    return 0;
}

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

int main() {

    string s;
    cin >> s;

    int ans = 0;
    s.pop_back();

    int len = s.size();
    for (int i=0; i<len; ++i) {

        if (s.size()%2) {
            s.pop_back();
            continue;
        }

        string a = s.substr(0, s.size()/2), b = s.substr(s.size()/2, s.size()/2);

        if (a == b) {
            cout << s.size() << endl;
            return 0;
        }

        s.pop_back();
    }

    cout << 0 << endl;


}


Measured memory_bytes: 256
import java.util.Scanner;

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

        char[] S = scanner.next().toCharArray();
        char[] T = scanner.next().toCharArray();
        
        int count = 0;
        for (int i = 0 ; i < S.length ; i++) {
            if (S[i] == T[i]) count++;
        }

        System.out.println(count);
    }
}


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

using namespace std;
typedef long long ll;
#define int ll

template<typename T1,typename T2> inline void chmin(T1 &a, T2 b){ if(a > b) a = b; }
template<typename T1,typename T2> inline void chmax(T1 &a, T2 b){ if(a < b) a = b; }

#define REP(i,n) for(int i=0;i<n;++i)
#define SORT(name) sort(name.begin(), name.end())
#define ZERO(p) memset(p, 0, sizeof(p))
#define MINUS(p) memset(p, -1, sizeof(p))
#if 1
#  define DBG(fmt, ...) printf(fmt, ##__VA_ARGS__)
#else
#  define DBG(fmt, ...)
#endif

const ll LLINF = (1LL<<60);
const int INF = (1LL<<30);
const double DINF = std::numeric_limits<double>::infinity();
const int MOD = 1000000007;
const int MAX_N = 100010;

int N, M, X;
vector<int> C;
vector< vector<int> > A;

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

    cin >> N >> M >> X;
    C.resize(N);
    A.assign(N, vector<int>(M, 0));
    REP(i, N) {
        cin >> C[i];
        REP(j, M) {
            cin >> A[i][j];
        }
    }

    int ans = LLINF;
    for(int pat = 0; pat < (1 << N); ++pat) {
        int cand = 0;
        vector<int> und(M, 0);  // 理解度
        for(int i = 0; i < N; ++i) {
            if((pat >> i) & 1) {
                // 買っているなら、理解度をあげる
                REP(j, M) {
                    und[j] += A[i][j];
                }
                cand += C[i];
            }
        }
        // 全部 X を超えた？
        bool isOk = true;
        REP(i, M) {
            if(und[i] < X) {
                isOk = false;
                break;
            }
        }
        if(isOk) {
            chmin(ans, cand);
        }
    }

    if(ans == LLINF) { ans = -1; }

    printf("%lld\n", ans);

    return 0;
}


Measured memory_bytes: 3760
n, m = map(int, input().split())
a = list(map(int, input().split()))

inf = float("inf")
dp = [-inf for i in range(n+1)]
dp[0] = 0

cost = {1:2, 2:5, 3:5, 4:4, 5:5, 6:6, 7:3, 8:7, 9:6}

for i in a:
    for j in range(1, n+1):
        if j - cost[i] >= 0:
            dp[j] = max(dp[j], dp[j-cost[i]]+1)

a.sort(reverse=True)
ans = ""
while n > 0:
    for i in a:
        state = True
        if n-cost[i] >= 0 and dp[n-cost[i]] == dp[n]-1:
            ans += str(i)
            n -= cost[i]
            state = False
            break
    if state:
        break

if ans == "":
    print(0)
else:
    print(ans)


Measured memory_bytes: 3444
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;

int par[100005];

int h[100005];

void init(int n)
{
	for(int i=0;i<=n;i++)
	{
		par[i]=i;
		h[i]=0;
	}
}

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

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

void unite(int x,int y)
{
	x=root(x);
	y=root(y);
	if(x==y)return;
	if(h[x]<h[y])par[x]=y;
	else
	{
		par[y]=x;
		if(h[x]==h[y])h[x]++;
	}
}


int main()
{
	int n,m,p,a,b,sum=0;
	vector<int>v;
	cin>>n>>m;
	init(n);
	for(int i=0;i<n;i++)
	{
		cin>>p;
		v.push_back(p);
	}
	for(int i=0;i<m;i++)
	{
		cin>>a>>b;
		unite(a,b);
	}
	for(int i=0;i<n;i++)
	{
		if(same(v[i],i+1))sum++;
	}
	cout<<sum<<endl;
	return 0;
}

Measured memory_bytes: 1660
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int i,count=0;
    string s1,s2;
    cin>>s1>>s2;
    for(i=0;i<=2;i++){
        if(s1[i]==s2[i])
            count++;
    }
    cout<<count<<endl;
}

Measured memory_bytes: 256
N = int(input())
names = [0] * 5
pattern = []

def make_pattern(arr, cnt):
    if len(arr) == 5:
        if cnt == 3 :
            pattern.append(arr)
        return
    make_pattern(arr + '1', cnt + 1)
    make_pattern(arr + '0', cnt)

for _ in range(N):
    name = input()
    initial = name[0]
    if 'M' == initial:
        names[0] += 1
    elif 'A' == initial:
        names[1] += 1
    elif 'R' == initial:
        names[2] += 1
    elif 'C' == initial:
        names[3] += 1
    elif 'H' == initial:
        names[4] += 1
    else:
        continue

make_pattern('', 0)

ans = 0
for p in pattern:
    ret = 1
    for i in range(5):
        if p[i] == '1':
            ret *= names[i]
    ans += ret
print(ans) 


Measured memory_bytes: 45160
n = int(input())
A = list(map(int, input().split()))
A = list(map(lambda x: x//400, A))
#print(A)

import collections
c = collections.Counter(A)
#print(c)
f1 = f2 = 0
for k in c.keys():
    if k >= 8:
        f1 += 1
        f2 += c[k]
        
if f1 == 0:
    min_ = max_ = len(c.keys())

else:
    min_ = len(c.keys()) -f1
    max_ = len(c.keys()) -f1 +f2
'''if max_ >8:
    max_ = 8'''
if min_ <1:
    min_ = 1
print(min_, max_)

Measured memory_bytes: 3316
import Control.Monad
import Data.Maybe (fromJust)
import Data.List
import Data.Char

isDayDream :: String -> Bool
isDayDream "" = True
isDayDream s
    | (isPrefixOf "maerd" s) = isDayDream (drop 5 s)
    | (isPrefixOf "remaerd" s) = isDayDream (drop 7 s)
    | (isPrefixOf "esare" s) = isDayDream (drop 5 s)
    | (isPrefixOf "resare" s) = isDayDream (drop 6 s)
    | otherwise =  False

toYesNo :: Bool -> String
toYesNo True = "YES"
toYesNo _ = "NO"

solve :: String -> String
solve = toYesNo . isDayDream . reverse

main :: IO ()
main = do
    s <- getLine
    putStrLn $ solve s


Measured memory_bytes: 7548
import itertools
n = int(input())
a = tuple([ int(v)-1 for v in input().split() ])
b = tuple([ int(v)-1 for v in input().split() ])
t = 0
for i in itertools.permutations(range(n)):
    if a == i:
        xa = t
    if b == i:
        xb = t
    t += 1
print(abs(xa-xb))

Measured memory_bytes: 39280