akhauriyash/Code-Regression huggingface dataset:
// OURL: https://atcoder.jp/contests/abc166/tasks/abc166_b
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
#define REP(i,n) for(int i=0,i##_len=(n);i<i##_len;++i)
#define RREP(i,a,n) for(int i=(a),i##_len=(n);i<i##_len;++i)
#define MAT1D(V,T,a) vector<T> V (a)
#define MAT2D(V,T,a,b) vector<vector<T>> V (a, vector<T>(b))
#define MAT3D(V,T,a,b,c) vector<vector<vector<T>>> V (a, vector<vector<T>>(b, vector<T>(c)))

// http://beet-aizu.hatenablog.com/entry/2018/04/08/145516
template<typename T>
vector<T> make_v(size_t a){return vector<T>(a);}
template<typename T,typename... Ts>
auto make_v(size_t a,Ts... ts){ return vector<decltype(make_v<T>(ts...))>(a,make_v<T>(ts...));  }

template<typename T,typename V>
typename enable_if<is_class<T>::value==0>::type
fill_v(T &t,const V &v){t=v;}
template<typename T,typename V>
typename enable_if<is_class<T>::value!=0>::type
fill_v(T &t,const V &v){ for(auto &e:t) fill_v(e,v);  }

template <typename A>
string to_string(A v) { bool first = true; string res = "{"; for (const auto &x : v) { if (!first) { res += ", ";  } first = false; res += to_string(x);  } res += "}"; return res;  }

string to_string(string s) { return '"' + s + '"';  }
string to_string(const char* s) { return to_string((string) s);  }
string to_string(bool b) { return (b ? "true" : "false");  }
string to_string(vector<bool>::reference b) { return to_string(bool(b));  }
template <typename A, typename B>
string to_string(pair<A, B> p) { return "(" + to_string(p.first) + ", " + to_string(p.second) + ")";  }
template <typename A>
string to_string(vector<vector<A>> v) { string res; for(const auto &x : v) {res+="\n ";res += to_string(x);} return res; }

void debug_out() { cerr << endl;  }
template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) { cerr << " " << to_string(H); debug_out(T...);  }

#ifdef LOCAL
#define debug(...) cerr << "[L" << to_string(__LINE__) << ":" <<#__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
#else
#define debug(...) 42
#endif

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

  int n, k;
  cin >> n >> k;
  auto have = make_v<int>(n);
  for (int i = 0; i < k; ++i) {
    int d;
    cin >> d;
    for (int j = 0; j < d; ++j) {
      int a;
      cin >> a;
      have[a-1] = 1;
    }
  }
  debug(have);
  int ans = 0;
  for (int i = 0; i < n; ++i) {
    if (have[i] == 0) ans++;
  }
  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 3652
#include<stdio.h>

int main(){
	int n;
	char str[255];
	
	scanf("%d", &n);
	scanf("%s", str);
	
	int flag=1;
	if(n%2!=0){
	    flag=0;    
	} 
	for(int i=0; i<n/2; i++){
     	if(str[i] != (str[(n/2)+i])){
     	    flag=0;
     	    }	
        }
        
        if(flag){
            printf("Yes\n");
        }
        else{
            printf("No\n");
        }
    return 0;
}
	
	

Measured memory_bytes: 3156
#include<stdio.h>
#include<stdlib.h>
#include<string.h>

#define N 100
int top;
class Stack
{
    private:
        int Array[N];
        int x;

    public:
        Stack():x(0)
        {
            for(int i=0; i<N; ++i)
                Array[i] = 0;
        }

        void push(int x) {
            Array[top] = x;
            ++top;
        }

        int pop(void) {
            top--;
            return Array[top];
        }

        int getmember(int index) {
            return Array[index];
        }
};

int main()
{
    Stack _stack;
    int x = 0, a = 0, b = 0;
    char StrIn[N];

    while(scanf("%s", StrIn) != EOF) {
        x = atoi(StrIn);
        if(x != 0)
            _stack.push(x);

        else {
            a = _stack.pop();
            //printf("top=%d\n", top);
            b = _stack.pop();
            //printf("top=%d\n", top);

            //printf("a=%d\nb=%d\n", a, b);

            if(strcmp(StrIn, "+") == 0) 
                _stack.push(a+b);
            
            if(strcmp(StrIn, "-") == 0)
                _stack.push(b-a);
            if(strcmp(StrIn, "*") == 0)
                _stack.push(a*b);
        }
    }
    printf("%d\n", _stack.getmember(0));
    return 0;
}


Measured memory_bytes: 2688
# print(abs(-1000001) - abs(-1000000))
k,x = map(int , input().split())

mini = -1000000
maxi = 1000000

left = x-k+1
right = x+k-1

if left < mini:
    right = right + (abs(left) - abs(mini))
    left = mini
if right > maxi:
    left = left - (maxi - right)
    right = maxi
# print(left,right)
while left<=right:
    print(left,end=" ")
    left+=1

Measured memory_bytes: 38384
n = int(input())
As = [int(i) for i in input().split()]
Bs = [int(i) for i in input().split()]
ABs = [a - b for a, b in zip(As, Bs)]
if sum(As) < sum(Bs):
    print(-1)
    exit()
mABs = [ab for ab in ABs if ab < 0]
pABs = [ab for ab in ABs if ab > 0]
ans, t = len(mABs), sum(mABs)
for pab in sorted(pABs, reverse=True):
    if t >= 0:
        break
    ans += 1
    t += pab
print(ans)

Measured memory_bytes: 18296
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < n; i++)
#define INF 1000000
using namespace std;
int main()
{
    int n;
    cin >> n;
    vector<int> a(n + 1);
    vector<string> vec;
    rep(i, n)
    {
        scanf("%d", &a[i]);
    }
    for (int i = 0; i < n; i++)
    {
        for (int j = i + 1; j < n; j++)
        {
            vec.push_back(to_string(a[i] * a[j]));
        }
    }
    //rep(i, vec.size()) cout << vec[i] << endl;
    int ans = -1;
    rep(i, vec.size())
    {
        bool flag = false;
        rep(j, vec[i].size() - 1)
        {
            //cout << vec[i][j] << " " << vec[i][j + 1] << endl;
            if (vec[i][j] != (int)(vec[i][j + 1] - 1))
                flag = true;
        }
        if (flag == false)
        {
            int tmp = stoi(vec[i]);
            //cout << tmp << endl;
            if (tmp > ans)
                ans = tmp;
        }
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 30036
n,m,x = map(int,input().split())
a = [int(i) for i in input().split()]
cnt1 = 0
cnt2 = 0
for i in range(x,n+1):
    if i in a:
        cnt1 += 1
for i in range(x,-1,-1):
    if i in a:
        cnt2 += 1
print(min(cnt1,cnt2))

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

#define NREP() for(ll i = 0; i < n; i++)
#define MREP() for(ll j = 0; j < m; j++)
#define REP(i, x, y) for(ll i = x; i < y; i++)
#define ALL(x) (x).begin(), (x).end()
#define MSG(x) cout << x << endl;
#define MSGF(x, n) MSG(fixed << setprecision(n) << x)
#define END(x) cout << x << endl; exit(0);
#define IPT(v, n) REP(i, 0, n){ cin >> v[i]; }
#define YN(x) x ? cout << "YES" << endl : cout << "NO" << endl;
#define Yn(x) x ? cout << "Yes" << endl : cout << "No" << endl;
#define yn(x) x ? cout << "yes" << endl : cout << "no" << endl;

using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef vector<bool> vb;
typedef vector<vector<bool>> vvb;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
typedef vector<ull> vul;
typedef vector<vector<ull>> vvul;
typedef vector<char> vc;
typedef vector<vector<char>> vvc;
typedef vector<string> vs;
typedef vector<vector<string>> vvs;

const static ll MOD = 1e9 + 7;
const static ll INF = 1LL << 30;

ll a, b, c, d, k, l, m, n, h, w, q, x, y;
string s, t;

ll ans = 0;
ll sum = 0;
ll cnt = 0;
ll cur = 0;
ll tmp = 0;
ll mini = INF;
ll maxi = 0;

double ave = 0.0;

ll mod_pow(ll base, ll power) {
    if (power == 0) return 1;
    if (power == 1) return base % MOD;
    if (power % 2 == 0) return ((mod_pow(base % MOD, (power / 2)) % MOD) * (mod_pow(base, (power / 2)) % MOD)) % MOD;
    return (base % MOD * (mod_pow(base % MOD, power - 1) % MOD)) % MOD;
}

ll mod_fact(ll number) {
    ll ret = 1;
    ll count = 1;
    while (count <= number) {
        ret *= (count % MOD);
        ret %= MOD;
        count++;
    }
    return ret % MOD;
}

////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

int main() {
    cin >> n >> k;
    vl x(n + 10);
    NREP() {
        cin >> x[i];
    }
    ans = LLONG_MAX;

    if (n == k) {
        ll l = 0;
        ll r = n - 1;
        if (x[l] < 0 && x[r] > 0) {
            // <- から ->
            ans = min(ans, abs(x[l]) + abs(x[l]) + x[r]);
            // -> から <-
            ans = min(ans, x[r] + x[r] + abs(x[l]));
            END(ans)
        } else if (x[l] < 0 && x[r] <= 0) {
            END(abs(x[l]))
        } else if (x[l] >= 0 && x[r] > 0) {
            END(abs(x[r]))
        } else {
            END(x[l])
        }
    }

    REP(i, 0, n - k + 1) {
        ll l = i;
        ll r = i + k - 1;
        if (x[l] < 0 && x[r] > 0) {
            // <- から ->
            ans = min(ans, abs(x[l]) + abs(x[l]) + x[r]);
            // -> から <-
            ans = min(ans, x[r] + x[r] + abs(x[l]));
        } else if (x[l] < 0 && x[r] <= 0) {
            ans = min(ans, abs(x[l]));
        } else if (x[l] >= 0 && x[r] > 0) {
            ans = min(ans, x[r]);
        }
    }
    MSG(ans)
}


Measured memory_bytes: 1024
/*
    ThunderClap and Flash
    Raunaq Singh
*/
#include "bits/stdc++.h" 
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<ll,ll> pll;
#define ThunderClap ios::sync_with_stdio(0),cin.tie(NULL),cout.tie(NULL);
#define debugg(something)   cout<<#something<<" - "<<something<<"\n";
#define vi vector
#define umap unordered_map
#define uset unordered_set
#define mset multiset
#define LB lower_bound
#define UB upper_bound
#define mp make_pair
#define pb push_back
#define in insert
#define s second
#define f first
#define pQueue priority_queue
#define maxElement *max_element
#define minElement *min_element
#define MAX 100000LL
#define mod 1000000007LL
#define inf 1000000000000000000LL
#define mI2 500000004LL
inline ll add(ll a, ll b){ return ((a%mod) + (b%mod))%mod;}
inline ll mul(ll a, ll b){ return ((a%mod) * (b%mod))%mod;}
inline ll sub(ll a, ll b){ return ((a%mod) - (b%mod) + mod)%mod;}

bool isAns (ll x, ll y, ll d) {
    ll dist = ceil(sqrt(x * x + y * y));
    --dist;
    return (dist < d);
}

void Flash(){
    ll n, d;
    cin>>n>>d;
    ll x, y;
    ll ans = 0;
    for (ll i = 0; i < n; i++) {
        cin>>x>>y;
        ans += isAns(x, y, d);
    }
    cout<<ans<<"\n";
}

int main(int argc, char const *argv[]){ 
    #ifndef ONLINE_JUDGE
        freopen("input.txt", "r", stdin);
    #endif
    ThunderClap;
    ll t = 1;
    //cin>>t;
    for(ll i = 1; i <= t; i++){
        //cout<<"Case #"<<i<<": ";
        Flash();
    }
    return 0;
}


Measured memory_bytes: 3728
#include<stdio.h>

int A[7],B[7],i;
int G[55][6]={
	{1,2,3},{1,3,5},{1,5,4},{1,4,2},
	{2,1,4},{2,4,6},{2,6,3},{2,3,1},
	{3,1,2},{3,2,6},{3,6,5},{3,5,1},
	{4,1,5},{4,2,1},{4,6,2},{4,5,6},
	{5,1,3},{5,3,6},{5,4,1},{5,6,4},
	{6,2,4},{6,4,5},{6,5,3},{6,3,2}};

int main()
{
	for(i=1;i<7;i++)scanf("%d",A+i);
	for(i=1;i<7;i++)scanf("%d",B+i);
	for(i=0;i<24;i++)
	{
		if(A[1]==B[G[i][0]]&&
		   A[2]==B[G[i][1]]&&
		   A[3]==B[G[i][2]]&&
		   A[6]==B[7-G[i][0]]&&
		   A[5]==B[7-G[i][1]]&&
		   A[4]==B[7-G[i][2]])
		{puts("Yes");
		return 0;
		}
	}
	puts("No");
	return 0;
}


Measured memory_bytes: 2108
import java.io.*;
import java.util.Arrays;
import java.util.Scanner;

public class Main{
	public static void main(String[] args) throws IOException{ 
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		String line1 = br.readLine();
		char[] c = line1.toCharArray();
		int len = line1.length();
		String num = br.readLine();
		int q = Integer.parseInt(num);
		String ans = "";
		for (int i = 0 ; i<q ; i++ ) {
			String line = br.readLine();
			String[] str = line.split(" ");
			int a = Integer.parseInt(str[1]);
			int b = Integer.parseInt(str[2]);
		char[] e = (char[]) c.clone();
			if (str[0].equals("replace")) {
				char[] d = str[3].toCharArray();
				for (int j = 0 ; j <= b-a  ; j++ ) {
					c[a+j] = d[j];
				}

			}else if(str[0].equals("reverse")){
				for (int j = 0 ; j <= (b-a)  ; j++ ) {
					c[a+j] = e[b-j];

				}

			}else if(str[0].equals("print")){
				for (int j = 0 ; j<=b-a ; j++ ){
					ans += String.valueOf(c[a+j]);
				} 
				System.out.println(ans);
				ans = "";
			}
		}

	}
}

Measured memory_bytes: 41988
#include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>

using namespace std;

bool is_range(int a){
	if( a == 0 || 12 < a ){
		return false;
	}
	return true;
}

int main(){
	int a,b;
	scanf("%02d%02d", &a, &b);
	if( is_range(a) && is_range(b) ){
		cout << "AMBIGUOUS" << endl;
	}
	else if( !is_range(a) && is_range(b) ){
		cout << "YYMM" << endl;
	}
	else if( is_range(a) && !is_range(b) ){
		cout << "MMYY" << endl;
	}
	else{
		cout << "NA" << endl;
	}

	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long
#define rep(i, n) for(ll i=0; i<n; i++)
#define repr(i, s, e) for(ll i=s; i>=e; i--)
#define reps(i, s, e) for(ll i=s; i<=e; i++)
#define inf 1e18
#define all(v) v.begin(),v.end()
#define vsort(v) sort(v.begin(), v.end())
#define vsortr(v) sort(v.begin(), v.end(), greater<ll>())
#define sz(x) x.size()
#define ceil(a, b) (a+b-1)/b
#define ok cout << "ok" << endl;
#define sp << " " <<
using namespace std;
template<typename T> inline bool chmax(T &a, T b){ if(a<b){ a=b; return true; } return false; }
template<typename T> inline bool chmin(T &a, T b){ if(b<a){ a=b; return true; } return false; }
template<typename T> T gcd(T a, T b){ if(b==0) return a; return gcd(b, a%b); }
template<typename T> T lcm(T a, T b){ return a*(b/gcd(a, b)); }
template<typename T> T keta(T num){ T k=0; while(num>0){ num/=10; k++; } return k; }
template<typename T> void vdebug(vector<T> v){ for(auto vv : v){ cout << vv << " "; } cout << endl; }
template<typename T> void adebug(T arr[], ll n){ reps(i, 0, n){ cout << arr[i] << " "; } cout << endl; }
void ans(bool b){ if(b) cout << "Yes" << endl; else cout << "No" << endl; }
void ans2(bool b){ if(b) cout << "YES" << endl; else cout << "NO" << endl; }
int dx[] = {1, -1, 0, 0, 1, -1, 1, -1};
int dy[] = {0, 0, 1, -1, 1, -1, -1, 1};


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

    int n, tmpl, cnt=0;
    vector<int> l;

    cin >> n;
    rep(i, 2*n){
        cin >> tmpl;
        l.push_back(tmpl);
    }

    vsort(l);

    ll res = 0;
    rep(i, 2*n){
        if(i%2==1) continue;
        else res += l[i];
    }

    cout << res << endl;

    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ll long long int
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
static const ll MAX = 1000000000000000;
static const int NIL = -1;
using namespace std;
const long double EPS = 0.0000000001;
const long double PI = (acos(-1));
const ll MOD = 1e9 + 7;

#pragma GCC target("avx2")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")


int main(){
    ll x,y,a,b,c; cin >> x >> y >> a >> b >> c;
    ll ans = 0;
    vector<ll> p(a),q(b),r(c);
    priority_queue<ll> apple;

    rep(i,a) cin >> p[i];
    rep(i,b) cin >> q[i];
    rep(i,c) cin >> r[i];

    sort(p.begin(),p.end(),greater<>());
    sort(q.begin(),q.end(),greater<>());
    sort(r.begin(),r.end(),greater<>());

    rep(i,x){
        apple.push(p[i]);
    }
    rep(i,y) {
        apple.push(q[i]);
    }

    rep(i,c){
        apple.push(r[i]);
    }

    rep(i,x+y){
        ans += apple.top();
        apple.pop();
    }
    cout << ans;


}

Measured memory_bytes: 9800
k, n = map(int, input().split())
h_list = list(map(int, input().split()))
distance = []
tmp = h_list[0]
for i in range(len(h_list)):
    a = h_list[i] - tmp
    distance.append(a)
    tmp = h_list[i]
x = (k - h_list[len(h_list)-1] )+ h_list[0]
distance.append(x)
sorted_d_list = sorted(distance)
sorted_d_list.pop()
print(sum(sorted_d_list))

Measured memory_bytes: 26444
#include <stdio.h>
#include <string.h>
#include <vector>
#include <algorithm>
using namespace std;
const int MOD=998244353;
int fac[10001],inv[10001];
long long qpow(long long a,int b)
{
    long long ret=1;
    for (;b;(a*=a)%=MOD,b>>=1)
        if (b&1)
            (ret*=a)%=MOD;
    return ret;
}
void ntt(vector<int> &src,int bits,bool rev)
{
    for (int i=0;i<(1<<bits);++i)
    {
        int t=i,rev=0;
        for (int j=0;j<bits;++j)
        {
            (rev<<=1)^=t&1;
            t>>=1;
        }
        if (rev>i)
            swap(src[i],src[rev]);
    }
    for (int i=2;i<=(1<<bits);i<<=1)
    {
        int w=qpow(3,(MOD-1)/i);
        if (rev)
            w=qpow(w,MOD-2);
        for (int j=0;j<(1<<bits);j+=i)
        {
            int cur=1;
            for (int k=j;k<j+i/2;++k)
            {
                int v2=(long long)src[k+i/2]*cur%MOD;
                src[k+i/2]=src[k]-v2;
                if (src[k+i/2]<0)
                    src[k+i/2]+=MOD;
                src[k]+=v2;
                if (src[k]>=MOD)
                    src[k]-=MOD;
                cur=(long long)cur*w%MOD;
            }
        }
    }
    if (rev)
    {
        int inv=qpow(1<<bits,MOD-2);
        for (int i=0;i<(1<<bits);++i)
            src[i]=(long long)src[i]*inv%MOD;
    }
}
vector<int> polynomial_pow(vector<int> base,int p,int reserved_len)
{
    int bits=0;
    while ((1<<bits)<(reserved_len+reserved_len+1))
        ++bits;
    base.resize(1<<bits);
    for (size_t i=reserved_len+1;i<base.size();++i)
        base[i]=0;
    vector<int> ret(1<<bits);
    ret[0]=1;
    while (p)
    {
        ntt(base,bits,0);
        if (p&1)
        {
            ntt(ret,bits,0);
            for (int i=0;i<(1<<bits);++i)
                ret[i]=(long long)ret[i]*base[i]%MOD;
            ntt(ret,bits,1);
            for (size_t i=reserved_len+1;i<ret.size();++i)
                ret[i]=0;
        }
        for (int i=0;i<(1<<bits);++i)
            base[i]=(long long)base[i]*base[i]%MOD;
        ntt(base,bits,1);
        for (size_t i=reserved_len+1;i<base.size();++i)
            base[i]=0;
        p>>=1;
    }
    ret.resize(reserved_len+1);
    return ret;
}
char s1[10001],s2[10001];
int binomial_coefficient(int a,int b)
{
    return (long long)fac[a]*inv[b]%MOD*inv[a-b]%MOD;
}
int main()
{
    fac[0]=inv[0]=fac[1]=inv[1]=1;
    for (int i=2;i<=10000;++i)
    {
        fac[i]=(long long)fac[i-1]*i%MOD;
        inv[i]=MOD-(long long)MOD/i*inv[MOD%i]%MOD;
    }
    for (int i=2;i<=10000;++i)
        inv[i]=(long long)inv[i-1]*inv[i]%MOD;
    scanf("%s%s",s1,s2);
    int n=strlen(s1),only=0,both=0;
    for (int i=0;i<n;++i)
        if (s1[i]=='1')
            (s2[i]=='0'?only:both)+=1;
    vector<int> dp(only+both+1);
    for (int i=1;i<=only+both;++i)
        dp[i]=inv[i];
    dp=polynomial_pow(dp,only,only+both);
    int ans=0;
    for (int i=0;i<=both;++i)
    {
        ans+=(long long)binomial_coefficient(only+both,only+i)*fac[both-i]%MOD*fac[both-i]%MOD*binomial_coefficient(both,i)%MOD*fac[i]%MOD*fac[only+i]%MOD*dp[only+i]%MOD*fac[only]%MOD;
        if (ans>=MOD)
            ans-=MOD;
    }
    printf("%d\n",ans);
    return 0;
}


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

int main(){
	int N,M;
	cin >> N >> M;
	map<int,int> c;
	for(int i = 0 ; i < M ; i++){
		int a,b;
		cin >> a >> b;
		if( a > b ) swap(a,b);
		if( a == 1 ) c[b]++;
		if( b == N ) c[a]++;
	}
	for( auto i : c ){
		if( i.second == 2 ){
			cout << "POSSIBLE" << endl;
			return 0;
		}
	}
	cout << "IMPOSSIBLE" << endl;
}

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

int main(){
  int x;
  cin >> x;
  if(30 <= x) cout << "Yes" << endl;
  else cout << "No" << endl;
  return 0;
}

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

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

int main(){
	int n;
	string s;
	cin>>n>>s;
	if(n%2==0&&s.substr(0,n/2)==s.substr(n/2,n/2)) cout<<"Yes"<<endl;
	else cout<<"No"<<endl;
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>

using namespace std;

int main() {
    string s;   cin >> s;
    int ans1 = 0, ans2 = 0, tmp = 1;
    
    for (int i = 0; i < s.length(); i++) {
        if (tmp%2 == s[i]-'0')
            ans1++;
        tmp++;
    }

    tmp = 1;
    for (int i = 0; i < s.length(); i++) {
        if (tmp%2 != s[i]-'0')
            ans2++;
        tmp++;
    }

    cout << min(ans1,ans2) << endl;

    return 0;
}

Measured memory_bytes: 512
#include<set>
#include<iostream>

#define	mp	make_pair
#define	X	first
#define	Y	second

using namespace std;

typedef	pair<int,int>	pii;

pii operator-(const pii &a,const pii &b){ return mp(a.X-b.X,a.Y-b.Y); }

int main()
{
	for(int m;cin>>m,m;){
		set<pii> star,sky;
		for(int i=0;i<m;i++){
			int x,y;	cin>>x>>y;
			star.insert(mp(x,y));
		}
		int n;	cin>>n;
		for(int i=0;i<n;i++){
			int x,y;	cin>>x>>y;
			sky.insert(mp(x,y));
		}

		pii shift;
		set<pii>::iterator it_sky,it_star;
		for(it_sky=sky.begin();it_sky!=sky.end();it_sky++){
			bool ok=true;
			shift=*star.begin()-*it_sky;
			for(it_star=star.begin();it_star!=star.end();it_star++){
				if(sky.count(*it_star-shift)==0){
						ok=false;
						break;
					}
			}
			if(ok)	break;
		}
		cout<<-shift.X<<' '<<-shift.Y<<endl;
	}

	return 0;
}

Measured memory_bytes: 0
#include<bits/stdc++.h>
using namespace std;
int main()
{
	int n,m,k=0,c=0,p=0;
	float t;
	cin>>n>>m;
	int a[n][m];
	for(int i=0;i<n;i++)
	{
		for(int j=0;j<m;j++)
		{
		cin>>a[i][j];
		}
	}
	for(int i=0;i<n;i++)
	{
		k=0;
		k=i+1;
		while(k<n)
		{
			t=0;
			for(int j=0;j<m;j++)
			{
				t=t+pow(abs(a[i][j]-a[k][j]),2);
			}
			
			p=(int)sqrt(t);
			t=float(sqrt(t));
			if(t==p)
			++c;
			++k;
		}
	}
	cout<<c;
}

Measured memory_bytes: 256
import java.util.*;

public class Main {
	public static void main(String[] args) throws Exception {
		Scanner s = new Scanner(System.in);
		long N = s.nextLong(), n = 5l;
		Double Cap = 1e15;
		for (int i = 0; i < n; i++){
			Double cap = s.nextDouble();
			if (Cap > cap) Cap = cap;
		}
		long t = (long)Math.ceil(N / Cap);
		System.out.println(t + n - 1l);
		/*
		5 3 2 4 3 5 -> 7
		10 123 123 123 123 123 -> 5
		10000000007 2 3 5 7 11 -> 5000000008
		*/
	}
}


Measured memory_bytes: 24404
#include <bits/stdc++.h>
#define syosu(x) fixed<<setprecision(x)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> P;
typedef pair<double,double> pdd;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<string> vs;
typedef vector<P> vp;
typedef vector<vp> vvp;
typedef vector<pll> vpll;
typedef pair<int,P> pip;
typedef vector<pip> vip;
const int inf=1<<30;
const ll INF=1ll<<60;
const double pi=acos(-1);
const double eps=1e-9;
const ll mod=998244353;
const int dx[4]={0,1,0,-1},dy[4]={1,0,-1,0};

ll n;
vl a;

int main(){
	cin>>n;
	ll s=0,t=1;
	a=vl(n);
	for(int i=0;i<n;i++){
		cin>>a[i];
		s+=a[i];
		(t*=3)%=mod;
	}
	vl dp(s+1);
	dp[0]++;
	for(int i=0;i<n;i++) for(int j=s;j>=0;j--) dp[j]=(dp[j]*2+(j>=a[i]?dp[j-a[i]]:0))%mod;
	for(int i=(s+1)/2;i<=s;i++) (t+=mod-3*dp[i]%mod)%=mod;
	if(s%2==0){
		dp=vl(s+1);
		dp[0]++;
		for(int i=0;i<n;i++) for(int j=s;j>=a[i];j--) (dp[j]+=dp[j-a[i]])%=mod;
		(t+=3*dp[s/2])%=mod;
	}
	cout<<t<<endl;
}

Measured memory_bytes: 1664
#include<iostream>
#include<algorithm>
#include<vector>
#include<queue>
#include<string>
#include<map>
using namespace std;
typedef long long ll;
#define int ll
ll cnt[100005]={0};
signed main(){
  ll n,mod;
  cin>>n>>mod;
  string s;
  cin>>s;
  reverse(s.begin(),s.end());
  ll tens=1;
  if(mod==2){
    ll ans=0;
    for(int i=0;i<n;i++){
      if((int)(s[i]-'0')%2==0){
        ans+=n-i;
      }
    }
    cout<<ans<<endl;
    return 0;
  }
  else if(mod==5){
    ll ans=0;
    for(int i=0;i<n;i++){
      if((int)(s[i]-'0')%5==0){
        ans+=n-i;
      }
    }
    cout<<ans<<endl;
    return 0;
  }
  vector<ll> vec;
  for(int i=0;i<n;i++){
    ll num=(ll)(s[i]-'0');
    num*=tens;
    num%=mod;
    vec.push_back(num);

    tens*=10;
    tens%=mod;
  }
  ll rsum=0;
  cnt[0]++;
  for(int i=0;i<n;i++){
    rsum+=vec[i];
    rsum%=mod;
    cnt[rsum]++;
  }
  ll ans=0;
  for(int i=0;i<mod;i++){
    if(cnt[i]>0) ans+=(cnt[i]*(cnt[i]-1))/2;
  }
  cout<<ans<<endl;
}


Measured memory_bytes: 2680
import java.util.*;
class Main
{
    public static void main (String[] args)
    {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int[] a = new int[n];
        for(int i = 0; i < n; i++) a[i] = sc.nextInt();
        int ans = 0;
        int tmp = 101;
        for(int i = 1; i < n; i++){
            if(a[i] == a[i-1]){
                a[i] = ++tmp;
                ans++;
            }
        }
        System.out.print(ans);
    }
}

Measured memory_bytes: 21844
N = int(input())
dp = [[0, 0, 0] for _ in range(N)]
a, b, c = map(int, input().split())
dp[0][0], dp[0][1], dp[0][2] = a, b, c

for i in range(1, N):
  a, b, c = map(int, input().split())
  dp[i][0] = max(dp[i-1][1], dp[i-1][2]) + a
  dp[i][1] = max(dp[i-1][2], dp[i-1][0]) + b
  dp[i][2] = max(dp[i-1][0], dp[i-1][1]) + c
print(max(dp[N-1]))

Measured memory_bytes: 22772
#include <iostream>
#include <vector>
#include <queue>

using namespace std;

vector <vector <int> > vec;
vector <bool> us;
vector <long long> dist;

void bfs(int v) {
    queue <int> q;
    q.push(v);
    while (!q.empty()) {
        int f = q.front();
        us[f] = true;
        for (int j = 0; j < vec[f].size(); j += 2) {
            int u = vec[f][j];
            if (!us[u]) {
                dist[u] = dist[f] + vec[f][j + 1];
                q.push(u);
            }
        }
        q.pop();
    }
}

int main()
{
    long long n, a, b, c, k;
    cin >> n;
    vec.resize(n);
    us.resize(n, false);
    dist.resize(n);
    for (int j = 1; j < n; j++) {
        cin >> a >> b >> c;
        vec[--a].push_back(--b);
        vec[a].push_back(c);
        vec[b].push_back(a);
        vec[b].push_back(c);
    }
    cin >> n >> k;
    dist[--k] = 0;
    bfs(k);
    for (int j = 0; j < n; j++) {
        cin >> a >> b;
        cout << dist[--a] + dist[--b] << '\n';
    }
}


Measured memory_bytes: 8820
s=input()
a=[0]*(len(s)+1)
for i in range(len(s)):
    if s[i]=="<":
        a[i+1]=a[i]+1
for i in range(len(s)-1,-1,-1):
    if s[i]==">":
        a[i]=max(a[i],a[i+1]+1)
print(sum(a))

Measured memory_bytes: 29232
#include <bits/stdc++.h>
using namespace std;
 
int main(){
    string s[3];
    for(int i=0;i<3;i++){
           cin>>s[i];
    }
    
    //cout<<((n=>3)?n/3:0)<<endl;
    cout<<s[0][0]<<s[1][1]<<s[2][2]<<endl;

    return 0;
}

Measured memory_bytes: 256
######################################################
############Created by Devesh Kumar###################
#############devesh1102@gmail.com####################
##########For CodeForces(Devesh1102)#################
#####################2020#############################
######################################################
import sys
input = sys.stdin.readline

# import sys
import heapq 
import copy
import math
import decimal
# import sys.stdout.flush as flush
# from decimal import *
#heapq.heapify(li) 
#
#heapq.heappush(li,4) 
#
#heapq.heappop(li)
#
# &	Bitwise AND Operator	10 & 7 = 2
# |	Bitwise OR Operator	10 | 7 = 15
# ^	Bitwise XOR Operator	10 ^ 7 = 13
 
# <<	Bitwise Left Shift operator	10<<2 = 40
# >>	Bitwise Right Shift Operator
# '''############ ---- Input Functions ---- #######Start#####'''
 

def inp():
	return(int(input()))
def inlt(): 
	return(list(map(int,input().split())))
def insr():
	s = input()
	return(list(s[:len(s) - 1]))
def insr2():
	s = input()
	return((s[:len(s) - 1]))
def invr():
	return(map(int,input().split()))
 ############ ---- Input Functions ---- #######End
 # #####   

def pr_list(a):
	print(*a, sep=" ")
def main():
	# tests =  inp()
	tests = 1
	mod = 998244353
	limit = 10**18
	ans = 0
	for test in range(tests):
		n = inp()
		val = []
		for i in range(n):
			a = inlt()
			val.append(a)
		dp = [[0 for i in range(n)] for j in range(3)]
		dp[0][0] = val[0][0]
		dp[1][0] = val[0][1]
		dp[2][0] = val[0][2]
		for i in range(1,n):
			for j in range(3):
				dp[j][i] = val[i][j] + max(dp[(j+1)%3][i-1],dp[(j+2)%3][i-1])
		print(max(dp[0][n-1] , dp[1][n-1]  , dp[2][n-1] ))
if __name__== "__main__":
	main()

Measured memory_bytes: 95448
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P  = pair <int, int>;

#define rep(i, n)     for (int i = 0; i < (int) (n); i++)
#define repr(i, a, b) for (int i = a; i < b; i++)
#define each(i, mp)   for (auto &i : mp)

const int INF = 1001001001;

int main()
{
  int a;
  cin >> a;
  ll ans = 0;

  rep(i, 3) ans += pow(a, i + 1);
  cout << ans << endl;

  return 0;
}


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

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


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

    vector<int> x(n);
    rep(i,n)cin>>x.at(i);

    ll sum=0;
    ll ans=999999999999;
    for(int i=1;i<100;i++){
        sum=0;
        for(int j=0;j<n;j++){
            sum += (x.at(j)-i)*(x.at(j)-i);
        }
        ans = min(ans,sum);
    }

    cout<<ans<<endl;
}

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

using namespace std;

#define int long long

template<class T>
struct Segtree {
	int n;
	vector<T> node;
	Segtree(int sz) {
		n = 1;
		while (n < sz) n *= 2;
		node.resize(2 * n - 1, INT_MAX); // UNITY
	}
	T merge(T a, T b) { // NEED TO EDIT
		return min(a, b);
	}
	void set(int p, T v) {
		p += n - 1;
		node[p] = v;
		while (p) {
			p = (p - 1) / 2;
			node[p] = merge(node[p * 2 + 1], node[p * 2 + 2]);
		}
	}
	T get(int a, int b, int k = 0, int l = 0, int r = -1) {
		if (r < 0) r = n;
		if (b <= l || r <= a) {
			return INT_MAX; // UNITY
		}
		if (a <= l && r <= b) {
			return node[k];
		}
		return merge(get(a, b, k * 2 + 1, l, (l + r) / 2),
					 get(a, b, k * 2 + 2, (l + r) / 2, r));
	}
};

signed main()
{
	int n, q;
	cin >> n >> q;
	Segtree<int> seg(n);
	while (q--) {
		int c, a, b;
		cin >> c >> a >> b;
		if (c == 0) seg.set(a, b);
		else cout << seg.get(a, b + 1) << endl;
	}
}
/*
	verified on 2019/5/3
	https://onlinejudge.u-aizu.ac.jp/courses/library/3/DSL/all/DSL_2_A
*/


Measured memory_bytes: 4876
#include <algorithm>
#include <boost/optional.hpp>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <functional>
#include <iostream>
#include <limits>
#include <list>
#include <numeric>
#include <queue>
#include <sstream>
#include <string>
#include <tuple>
#include <type_traits>
#include <utility>
#include <vector>

#define REP(i, n) for(int i = 0, i##_MACRO = (n); i < i##_MACRO; i++)
#define RANGE(i, a, b) for(int i = (a), i##_MACRO = (b); i < i##_MACRO; i++)
#define EACH(e, a) for(auto&& e : a)
#define ALL(a) (a).begin(), (a).end()
#define AALL(a, n) (a), ((a) + (n))
#define FILL(a, n) memset((a), n, sizeof(a))
#define FILLZ(a) FILL(a, 0)
#define MODNUM (static_cast<int>(1e9 + 7))
#define MOD(x) ((x) % MODNUM)

using namespace std;

using ll = long long;
using VI = vector<int>;
using VI2D = vector<vector<int>>;

const int INF = 2e9;
const double EPS = 1e-10;
const double PI = acos(-1.0);

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

template <typename T>
int sign(T x) {
	return x < 0 ? -1 : x > 0 ? 1 : 0;
}

template <>
int sign(double x) {
	return x < -EPS ? -1 : x > EPS ? 1 : 0;
}

template <typename T>
T square(T x) {
	return x * x;
}

inline int toInt(string s) {
	int v;
	istringstream sin(s);
	sin >> v;
	return v;
}

int main() {
	int n, m;
	scanf("%d %d", &n, &m);
	VI wa(n, 0);
	VI ac(n, 0);
	REP(i, m) {
		int problem;
		char status[3];
		scanf("%d %s", &problem, status);
		problem--;
		if(status[0] == 'A') { // AC
			ac[problem] = 1;
		} else { // WA
			if(ac[problem] == 0) {
				wa[problem]++;
			}
		}
	}
	int cac = 0;
	int cwa = 0;
	REP(i, n) {
		cac += ac[i];
		if(ac[i] == 1) {
			cwa += wa[i];
		}
	}
	printf("%d %d\n", cac, cwa);
	return 0;
}

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

using namespace std;

int main()
{
    int a;
    cin >> a;
    
    int b = a/100;
    int c = (a/10)%10;
    int d = a%10;
    
    if(b == 9)
    {
        b = 1;
    }
    else
    {
        b = 9;
    }
    if(c==1)
    {
        c = 9;
    }
    else
    {
        c= 1;
    }
    if(d==9)
    {
        d= 1;
    }
    else 
    {
        d = 9;
    }
    
    cout << b*100 + c*10 + d;
}


Measured memory_bytes: 3184
using System;

namespace A
{
    class Program
    {
        static void Main(string[] args)
        {
            string[] AB = Console.ReadLine().Split(' ');
            int A = int.Parse(AB[0]);int B = int.Parse(AB[1]);
            int C = A - (B * 2);
            if (C < 0)
            {
                Console.WriteLine("0");
            }
            else
            {
                Console.WriteLine(C);
            }
        }
    }
}


Measured memory_bytes: 27452
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < n; i++)
#define FOR(i, m, n) for (int i = m; i < n; i++)
#define ll long long int
const int INF = 2147483647;
const ll MOD = 1000000007;

using namespace std;

int main() {
  vector<ll> a;
  string s;
  cin >> s;
  int n = s.length();
  char init = s[0], last = s[n - 1];
  ll count = 1;
  FOR(i, 1, n) {
    if (s[i] == s[i - 1]) {
      count++;
    } else {
      a.push_back(count);
      count = 1;
    }
  }
  a.push_back(count);

  ll ans = 0;
  if (init == '>') {
    ans += a[0] * (a[0] + 1) / 2;
    a.erase(a.begin());
    if (a.empty()) {
      cout << ans << endl;
      return 0;
    }
  }
  REP(i, a.size() - 1) {
    if (i % 2 != 0)
      continue;
    ll mi = min(a[i], a[i + 1]);
    ll ma = max(a[i], a[i + 1]);
    ans += mi * (mi - 1) / 2;
    ans += ma * (ma + 1) / 2;
  }
  if (last == '<') {
    ans += a[a.size() - 1] * (a[a.size() - 1] + 1) / 2;
  }
  cout << ans << endl;
}


Measured memory_bytes: 3068
N=int(input())
A=list()
B=list()
for i in range(N):
  a,b=map(int,input().split())
  A.append(a)
  B.append(b)
A.sort()
B.sort()

if N%2==1:
  print(B[int((N-1)/2+0.5)]-A[int((N-1)/2+0.5)]+1)
else:
  print((B[int(N/2+0.5)-1]+B[int(N/2+0.5)])-(A[int(N/2+0.5)-1]+A[int(N/2+0.5)])+1)

Measured memory_bytes: 25476
#include<bits/stdc++.h>
using namespace std;
#define int long long int
#define double long double
#define fast ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define mod 1000000007
#define endl "\n"
 
 
int pow1(int n, int p)
{
	if(p==0)	return 1;
	int x=pow1(n, p/2);
	x=(x*x)%mod;
	if(p%2==0)
		return x;
	else
		return (x*n)%mod;
}
 
int32_t main()
{
	fast;

	int h;
	cin>>h;
	int c=0;
	int a=1;
	while(h>0)
	{
		c+=a;
		h/=2;
		a*=2;
	}
	cout<<c<<endl;

	return 0;
}

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

int s1[26], s2[26];

int main(){
	int n;
	string str;
	cin >> n >> str;
	for(int i = 0;i<str.size();i++)
		s1[str[i]-'a']++;
		
	for(int i = 0;i<n-1;i++){
		cin >> str;
		for(int j = 0;j<str.size();j++){
			int d = str[j]-'a';
			s2[d]++;
		}
		
		for(int j= 0;j<26;j++){
			s1[j] = min(s1[j],s2[j]);
		}
		memset(s2,0,sizeof(s2));
	}
	for(int i = 0;i<26;i++){
		for(int j = 0;j<s1[i];j++){
			cout<<(char)('a'+i);
			
		}
	}
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const int mod = 1e9 + 7;
const int inf = (1 << 30) - 1;
const ll infll = (1LL << 61) - 1;

template <typename T>
struct edge
{
    int src, to;
    T cost;

    edge(int to, T cost) : src(-1), to(to), cost(cost) {}

    edge(int src, int to, T cost) : src(src), to(to), cost(cost) {}

    edge &operator=(const int &x)
    {
        to = x;
        return *this;
    }

    operator int() const { return to; }
};

//Weighted edge set
template <typename T>
using Edges = vector<edge<T>>;

//Weighted graph
template <typename T>
using WeightedGraph = vector<Edges<T>>;

//Unweighted graph (adjacency matrix)
//Initialize : vector<vector<int>>(N, vector<int>(N, 0))
template <typename T>
using UnweightedGraph = vector<vector<T>>;

//distance matrix
template <typename T>
using Matrix = vector<vector<T>>;

int N, Q;
vector<int> weight, visited;
UnweightedGraph<int> G;

void bfs()
{
    queue<int> pq;
    pq.push(0);
    while (!pq.empty())
    {
        int v = pq.front();
        pq.pop();
        visited[v] = true;
        for (auto &u : G[v])
        {
            if (visited[u] == false)
            {
                weight[u] += weight[v];
                pq.push(u);
            }
        }
    }
    return;
}

int main()
{
    cin >> N >> Q;
    G = UnweightedGraph<int>(N);
    weight = vector<int>(N);
    visited = vector<int>(N);
    for (int i = 1; i < N; i++)
    {
        int a, b;
        cin >> a >> b;
        a--, b--;
        G[a].push_back(b);
        G[b].push_back(a);
    }

    for (int i = 0; i < Q; i++)
    {
        int p, x;
        cin >> p >> x;
        p--;
        weight[p] += x;
    }

    bfs();

    for (int i = 0; i < N; i++)
    {
        cout << weight[i] << " ";
    }
    cout << endl;
}

Measured memory_bytes: 16372
#include <stdio.h>

int main(void)
{
    char s[10], t[10];
    scanf("%s%s", s, t);
    if (s[0] != t[2] || s[1] != t[1] || s[2] != t[0]) printf ("NO\n");
    else printf ("YES\n");
    return (0);
}


Measured memory_bytes: 128
S = input()
S = list(S)
str_list =  {"A","C","G","T"}
str_max = 0
#print(S)
#print(len(S))
for start in range(len(S)):
    for end in range(start+1, len(S)+1):
        S_list = S[start:end]

        if str_list | set(S_list) == str_list:
            str_max = max(str_max, len((S_list)))
           # print(str(S_list)+'はオッケーでした，記録は'+str(len(set(S_list))))
        #else:
           # print(str(S_list)+'はダメでした')

print(str_max)

Measured memory_bytes: 3060
#include<cstdio> 
#include<cstring>
#include<cmath>

long long k, a, b, c; 

long long read(){
	long long x = 0, f = 1; 
	char ch = getchar(); 
	while (ch < '0' || ch > '9') {
		if (ch == '-') {
			f = -1; 
		}
		ch = getchar(); 
	}
	while (ch >= '0' && ch <= '9') {
		x = (x << 3) + (x << 1) + ch - '0'; 
		ch = getchar(); 
	}
	return x * f; 
}

int main(){
	a = read(); 
	b = read(); 
	c = read(); 
	k = read(); 
	if (k & 1) {
		if (std::abs(b - a) >= 1e18) {
			printf("Unfair\n"); 
			return 0; 
		}
		printf("%lld\n", b - a); 
	}
	else {
		if (std::abs(b - a) >= 1e18) {
			printf("Unfair\n"); 
			return 0; 
		}
		printf("%lld\n", a - b); 
	}
	return 0; 
}

Measured memory_bytes: 128
#include<bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(n);i++)
#define M 1005
#define N 51
using namespace std;
int r,c,m,gy,gx,tim,ans;
int cost[3][N][N];
bool used[N][N];
string s[N];
int dy[4]={-1,0,1,0};
int dx[4]={0,1,0,-1};
int d[N][N];

void update(int y,int x,int t){
  if(d[y][x]==-1)ans+=cost[1][y][x]+cost[2][y][x];
  else ans+=min((t-d[y][x])*cost[0][y][x],
		cost[1][y][x]+cost[2][y][x]);
  d[y][x]=t;
}

bool dfs(int y,int x,int t){
  if(used[y][x])return false;
  used[y][x]=true;
  if(y==gy&&x==gx){
    update(y,x,t);
    tim=t;
    return true;
  }
  bool res=false;
  rep(i,4){
    int ny=y+dy[i],nx=x+dx[i];
    if(ny<0||nx<0||r<=ny||c<=nx)continue;
    if(s[ny][nx]=='#')continue;
    res|=dfs(ny,nx,t+1);
  }
  if(res)update(y,x,t);
  return res;
}

int y[M],x[M];

int main(){
  cin>>r>>c>>m;
  rep(i,r)cin>>s[i];
  
  rep(i,3)
    rep(j,r)
      rep(k,c)cin>>cost[i][j][k];
  
  rep(i,m)cin>>y[i]>>x[i];
  
  memset(d,-1,sizeof(d));

  rep(i,m-1){
    gy=y[i+1],gx=x[i+1];
    memset(used,0,sizeof(used));
    dfs(y[i],x[i],tim);
  }
  
  cout<<ans<<endl;
  return 0;
}

Measured memory_bytes: 3372
#include <stdio.h>
#include <stdlib.h>

typedef struct {
	long days;
	long reward;
} S_JOB;

int cmp(const void * n1, const void * n2)
{
	if (((S_JOB *)n1)->days > ((S_JOB *)n2)->days)
	{
		return -1;
	}
	else if (((S_JOB *)n1)->days < ((S_JOB *)n2)->days)
	{
		return 1;
	}
	else
	{
    if (((S_JOB *)n1)->reward > ((S_JOB *)n2)->reward)
  	{
  		return -1;
  	}
  	else if (((S_JOB *)n1)->reward < ((S_JOB *)n2)->reward)
  	{
  		return 1;
  	} else
    {
      return 0;
    }
	}
}

int main(void) {

  long n,m;
  scanf("%ld %ld", &n, &m);
  S_JOB jobs[n];
  for (long i = 0; i < n; i++) {
    scanf("%ld %ld", &jobs[i].days, &jobs[i].reward);
  }
  qsort(jobs, n, sizeof(S_JOB), cmp);
  long list[m];
  long list_size = 0;
  long sum = 0;
  long cur,child,child1,parent;
  for (long i = 0; i < n; i++) {
    if (jobs[i].days > m) {
      continue;
    }
    if (list_size+jobs[i].days <= m) {
      sum += jobs[i].reward;
      list[list_size] = jobs[i].reward;
      cur = list_size;
      list_size++;
      while (cur > 0) {
        parent = (cur-1)/2;
        if (jobs[i].reward < list[parent]) {
          list[cur] = list[parent];
          list[parent] = jobs[i].reward;
          cur = parent;
        } else {
          break;
        }
      }
    } else if (jobs[i].reward > list[0]) {
      sum += jobs[i].reward-list[0];
      list[0] = list[list_size-1];
      cur = 0;
      while (1) {
        child = cur*2+1;
        if (child >= list_size-1) {
          break;
        }
        if (child < list_size-2) {
          child1 = child+1;
          if (list[child1] < list[child]) {
            child = child1;
          }
        }
        if (list[list_size-1] > list[child]) {
          list[cur] = list[child];
          list[child] = list[list_size-1];
          cur = child;
        } else {
          break;
        }
      }
      list[list_size-1] = jobs[i].reward;
      cur = list_size-1;
      while (cur > 0) {
        parent = (cur-1)/2;
        if (jobs[i].reward < list[parent]) {
          list[cur] = list[parent];
          list[parent] = jobs[i].reward;
          cur = parent;
        } else {
          break;
        }
      }
    }
  }
  printf("%ld\n", sum);

  return 0;
}

Measured memory_bytes: 3324
#include <bits/stdc++.h>
using namespace std;
using Int = long long;

const int MAX = 200001;
const int MOD = 1000000007;
long long fac[MAX], finv[MAX], inv[MAX];
void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}
long long COM(int n, int k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

int main()
{
    COMinit();
    Int B, W; cin >> B >> W;
    Int bmax = 0, norm = 1, wmax = 0, demo = inv[2];
    for (int i = 0; i < B + W; i++) {
        Int b = COM(i, B);
        Int w = COM(i, W);
        cout << (norm - b + w + wmax * 2 + MOD) % MOD * demo % MOD << '\n';
        bmax = (bmax * 2 + b) % MOD;
        norm = (norm * 2 - b - w + MOD + MOD) % MOD;
        wmax = (wmax * 2 + w) % MOD;
        demo = demo * inv[2] % MOD;
    }
    return 0;
}

Measured memory_bytes: 6912
#include <stdio.h>

int main(void) {
  int i, j, k, n, ans = 0;
  scanf("%d", &n);
  char s[n][n + 10];
  for(i = 0; i < n; ++i) scanf("%s", s[i]);
  for(i = 0; i < n; ++i) {
    bool b = true;
    for(j = 0; j < n; ++j) for(k = 0; k < n; ++k) if(s[k][(i + j) % n] != s[j][(i + k) % n]) b = false;
    if(b) ans += n;
  }
  printf("%d", ans);
  return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define inf 1e18
#define IOS ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define pb push_back
#define ff first
#define ss second
#define vll vector<ll>
#define pii pair<ll,ll>
#define sz(v) (v).size()
#define srt(v) sort(v.begin(),v.end())
#define ull unsigned long long
#define tell(a) cout<<a<<" "
#define el cout<<endl
#define rev(v) reverse(v.begin(),v.end())
#define rep(i,a,n) for(int i=a;i<n;i++)
#define M 1000000007
ll power(ll x, ll y, ll p){ll res = 1;x = x % p;while (y > 0){   if (y & 1)res = (res*x) % p;y = y>>1;
x = (x*x) % p;}return res;}
ll pow(ll x,ll y)
{
	ll ans=1;
	for(int i=0;i<y;i++)
	ans=ans*x;
	return ans;
}
int main()
{
	IOS;
	ll x;
	cin>>x;
	for(int i=-300;i<=300;i++)
	{
		for(int j=-300;j<=300;j++)
		{
			ll p=(ll)pow(i,5),q=(ll)pow(j,5);
//			tell(p);tell(q);
			if(p-q==x)
			return cout<<i<<" "<<j,0;
			else if(q-p==x)
			return cout<<j<<" "<<i,0;
		}
	}
}



Measured memory_bytes: 4080
#include<bits/stdc++.h>
using namespace std;
const int maxn=5005;
const int maxm=205;
int za,zb,la,lb;

bool check(int z,int a,int b,int pat)
{
    a-=z;b-=z;
    za=a/(pat-1)+(a%(pat-1)!=0);
    zb=b/(pat-1)+(b%(pat-1)!=0);
    if(za+zb>z+1) return 1;
    return 0;

}
int main()
{
    int q;
    scanf("%d",&q);
    while(q--)
    {
        int a,b,c,d;
        scanf("%d%d",&a,&b);
        scanf("%d%d",&c,&d);
        //c=1;
        //d=a+b;
        int pat,num;
        if(a>b){
            pat=a/(b+1)+(a%(b+1)!=0);
            num=a/pat+(a%pat!=0);
            if(b<num){
                for(int i=c;i<=d;i++)
                {
                    printf("%c",i%(pat+1)==0?'B':'A');
                }
                printf("\n");
                continue;
            }
        }
        else if(a<b) {
            pat=b/(a+1)+(b%(a+1)!=0);
            num=b/pat+(b%pat!=0);
            if(a<num){
                for(int i=c;i<=d;i++)
                {
                    printf("%c",(a+b+1-i)%(pat+1)==0?'A':'B');
                }
                printf("\n");
                continue;
            }
        }
        else{
            for(int i=c;i<=d;i++)
                printf("%c",i&1?'A':'B');
            printf("\n");
            continue;
        }
        int l=1,r=min(a,b),ans;
        while(l<=r)
        {
            int mid=(l+r)>>1;
            int t=check(mid,a,b,pat);
            //printf("%d %d\n",mid,(int)t);
            if(t){
                l=mid+1;
            }
            else{
                ans=mid;
                r=mid-1;
            }
        }
        check(3,a,b,pat);
        int ta=a,tb=b;
        a-=ans;b-=ans;
        int tmpa=a/(pat-1)*(pat+1)+a%(pat-1)+(a%(pat-1)!=0);
        int tmpb=b/(pat-1)*(pat+1)+b%(pat-1)+(b%(pat-1)!=0);
        //printf("%d %d %d %d\n",ans,pat,tmpa,tmpb);
        for(int i=c;i<=d;i++)
        {
            char s;
            if(i<=tmpa)
                printf("%c",i%(pat+1)==0?'B':'A');
            else if((ta+tb+1-i)<=tmpb)
                printf("%c",(ta+tb+1-i)%(pat+1)==0?'A':'B');
            else
                printf("%c",((i-tmpa+(a%(pat-1)==0))&1)?'B':'A');
        }
        printf("\n");
    }
    return 0;
}


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

using ll=long long;
struct Edge{
    int from,to;
    ll cost;
};
using Graph=vector<vector<Edge>>;
int main(){
    int n;
    cin>>n;
    Graph g(n);
    for(int i=0;i+1<n;i++){
        int a,b;
        ll c;
        cin>>a>>b>>c;
        a--,b--;
        g[a].push_back(Edge{a,b,c});
        g[b].push_back(Edge{b,a,c});
    }
    int cent=-1;
    int cent2=-1;
    function<int(int,int)> dfs=[&](int v,int pre){
        int res=1;
        bool isok=true;
        for(auto e:g[v]){
            if(e.to!=pre){
                int sz=dfs(e.to,v);
                isok=isok&&(sz<=(n/2));
                res+=sz;
            }
        }
        isok=isok&&(n-res<=(n/2));
        if(isok){
            if(cent==-1)cent=v;
            else cent2=v;
        }

        return res;
    };
    dfs(0,-1);
    vector<ll> dists;
    function<void(int,int,ll)> dfs2=[&](int v,int pre,ll d){
        if(pre!=-1) dists.push_back(d);
        for(auto e:g[v]){
            if(e.to!=pre){
                dfs2(e.to,v,d+e.cost);
            }
        }
    };
    if(cent2==-1){
        dfs2(cent,-1,0);
        ll m=*min_element(dists.begin(),dists.end());
        ll sum=accumulate(dists.begin(),dists.end(),0LL);
        cout<<2*sum-m<<endl;
    }
    else{
        dfs2(cent,cent2,0);
        dfs2(cent2,cent,0);
        ll res=2*accumulate(dists.begin(),dists.end(),0LL);
        for(auto e:g[cent]) if(e.to==cent2) res+=(e.cost)*(n-1);
        cout<<res<<endl;
    }
    return 0;
}

Measured memory_bytes: 17920
#include <iostream>

using namespace std;

int fib(int n);

int main() {
    int n;
    int dp[45];

    //?????????
    /* ??????3-1 */
    dp[0]=1;
    /* ??????3-2 */
    dp[1]=1;
    //??\???
    cin >> n;

    //DP
    for (int i = 2; i <= n; i++) {
        /* ??????3-3 */
      dp[i]=dp[i-1]+dp[i-2];
    }

    //??????
    cout << dp[n] << endl;

    return 0;
}

Measured memory_bytes: 3080