akhauriyash/Code-Regression huggingface dataset:
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<map>
#include<set>
#include<vector>
using namespace std;
typedef long long ll;
#define mit map<int,int>::iterator
#define sit set<int>::iterator
#define itrm(g,x) for(mit g=x.begin();g!=x.end();g++)
#define itrs(g,x) for(sit g=x.begin();g!=x.end();g++) 
#define ltype int
#define rep(i,j,k) for(ltype (i)=(j);(i)<=(k);(i)++)
#define pii pair<int,int>
#define fi first
#define se second
#define mpr make_pair
#define pb push_back
const int inf=0x3f3f3f3f,
mod=1000000007;
const double pi=3.1415926535897932,
eps=1e-6;
int n,n2,a[200005];bool p[200005];
int mid(int a,int b,int c){
    int m=max(a,max(b,c)),k=min(a,min(b,c));
    return a+b+c-m-k;
}
bool check(int x){
    rep(i,1,n2) p[i]=a[i]>=x;
    if(p[n-1]==p[n]||p[n]==p[n+1]) return p[n];
    int l=n-1,r=n+1;
    while(l>1&&p[l-1]!=p[l]) l--;
    while(r<n2&&p[r+1]!=p[r]) r++;
    if(r-l+1==n2) return p[l];
    if(((r-l+1)&1)==1) return p[l];
    if(abs(n-l)<abs(n-r)) return p[l];
    return p[r];
}
int main()
{
    scanf("%d",&n);n2=2*n-1;
    rep(i,1,n2) scanf("%d",a+i);
    int l=1,r=n2,ans=0;
    while(l<r){
        int mid=(l+r+1)>>1;
        if(check(mid)) l=mid;
        else r=mid-1;
    }
    printf("%d\n",l);
    return 0;
}

Measured memory_bytes: 1152
import sys
sys.setrecursionlimit(10**8)

n = int(input())

def dfs(s, mx):
    if len(s) == n:
        print(s)
        return
    for i in range(ord('a'), mx + 2):
        t = s
        t += chr(i)
        mx = max(mx, i)
        dfs(t, mx)
    return


mx = ord('a')
dfs('a', mx)

Measured memory_bytes: 55896
#include <iostream> // cout, endl, cin
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower
#include <math.h>
using namespace std;
int main(){
    int h,w;
    bool p = true;
    cin >> h >> w;
    vector<vector<char>> s(h,vector<char>(w));
    for(int i=0; i<h; i++){
        for(int j=0; j<w; j++){
            cin >> s.at(i).at(j);
        }
    }
    for(int i=0; i<h; i++){
        for(int j=0; j<w; j++){
            if(s.at(i).at(j)=='#'){
                int r = 0;
                if(i!=0){
                    if(s.at(i-1).at(j)=='#') r++;
                }
                if(i!=(h-1)){
                    if(s.at(i+1).at(j)=='#') r++;
                }
                if(j!=0){
                    if(s.at(i).at(j-1)=='#') r++;
                }
                if(j!=(w-1)){
                    if(s.at(i).at(j+1)=='#') r++;
                }
                if(r==0){
                    p = false;
                    break;
                }
            }
        }
    }
    if(p){
        cout << "Yes" << endl;
    }
    else{
        cout << "No" << endl;
    }
}

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

int main(){
  int n;
  cin >> n;
  vector<int> l(n);
  for (int i = 0; i < n; i++)
  {
    cin >> l[i];
  }

  int ans = 0;
  for (int i = 0; i < n; i++)
  {
    for (int j = i+1; j < n; j++)
    {
      for (int k = j+1; k < n; k++)
      {
        if(l[i]+l[j]>l[k] && l[i]+l[k]>l[j] && l[k]+l[j]>l[i] && l[i]!=l[j] && l[j]!=l[k] && l[i]!=l[k]) ans++;
      }
    }
  }
  cout << ans << endl;
}

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

int main(){
	int size = 0, n[101] = {0}, temp, max = -1;
	while(cin >>temp){
		n[temp]++;
		if(n[temp] > max) max = n[temp];
		size++;
	}
	for(int i = 1; i <= 100; i++){
		if(n[i] >= max) cout <<i <<endl;
	}
	return 0;
}

Measured memory_bytes: 0
#include <iostream>
#include <vector>
#include <queue>
#include <algorithm>
#include <cmath>
#include <bitset>
#include <iomanip>
#include <stack>
#include <list>
#include <map>
#include <unordered_map>
#include <chrono>
#include <numeric>
using namespace std;
using ll = long long;
const ll INF = (ll)1e18+1;
const ll DIV = 1000000007;
//#define TEST
int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
#ifdef TEST
    chrono::system_clock::time_point start, end;
    start = chrono::system_clock::now();
#endif
    long N;
    cin >> N ;
    vector<long> L(N);
    long max_L = 0;
    ll total = 0;
    for(size_t i=0;i<N; i++)
    {
        cin >> L[i];
        max_L = max(max_L, L[i]);
        total += L[i];
    }
    if(total - max_L > max_L) cout << "Yes" << endl;
    else cout << "No" << endl;

#ifdef TEST
    end = chrono::system_clock::now();
    cerr << static_cast<double>(chrono::duration_cast<chrono::microseconds>(end - start).count() / 1000.0) << "[ms]" << endl;
#endif
    return 0;
}

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

#define ll long long
#define ull unsigned long long
#define met(a, x) memset(a,x,sizeof(a));
#define inf 0x3f3f3f3f
#define mp make_pair;

using namespace std;
const int mod = 1e9 + 7;
const int N = 1e6 + 10;
const int M = 1e5 + 10;
int a[M];
map<int,bool> q;
int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    int n, k;
    cin >> n >> k;
    int maxn = 0;
    for (int i = 1; i <= n; i++) {
        cin >> a[i];
        q[a[i]]=1;
        maxn = max(maxn, a[i]);
    }
    if (maxn < k) {
        cout << "IMPOSSIBLE" << endl;
    } else {
        if(q[k]==1){
            cout<<"POSSIBLE"<<endl;
            return 0;
        }
        for (int i = 1; i <= n; i++) {
            if(q[a[i]]==1&&q[k-a[i]]==1){
                cout<<"POSSIBLE"<<endl;
                return 0;
            }
        }
        cout<<"IMPOSSIBLE"<<endl;
    }
    return 0;
}



Measured memory_bytes: 5888
#include <atcoder/all>
#include<bits/stdc++.h>
#define REP(i, n) for(int i=0; i<n; i++)
#define COUT(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << endl
using namespace std;
using ll = long long;
using Graph = vector<vector<ll>>;

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;
}

int main(){
    int N, Q;
    cin >> N >> Q;
    atcoder::dsu d(N);
    for (int i = 0; i < Q; i++)
    {
        int t, u, v;
      	cin >> t >> u >> v;
        if(t==0) d.merge(u, v);
        else cout << int(d.same(u, v)) << endl;
    }
    
    
}

Measured memory_bytes: 4020
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n)   FOR(i,0,n)
#define pb emplace_back
typedef long long ll;
typedef pair<int,int> pint;

int g[100001],a[101];
int main(){
    int n,k;
    cin>>n>>k;
    rep(i,n) cin>>a[i];
    FOR(i,1,k+1){
        rep(j,n){
            if(a[j]<=i)g[i]|=!g[i-a[j]];
        }
    }
    if(g[k]) cout<<"First"<<endl;
    else cout<<"Second"<<endl;
    return 0;
}


Measured memory_bytes: 640
#include<stdio.h>

int main(){
  int n,b,f,r,v;
  int y[12][10] = {};
  scanf("%d",&n);

  for( int i=0 ; i < n ; i++ ){
    scanf("%d %d %d %d",&b,&f,&r,&v);
    y[3*(b-1)+f-1][r-1] += v;
  }

  for( int i=0 ; i < 12 ; i++ ){
    for( int j=0 ; j < 10 ; j++ ){
        printf(" ");
      printf("%d",y[i][j]);
    }
    printf("\n");
    if( (i+1) % 3 == 0 && i+1 != 12)printf("####################\n");
  }
}


Measured memory_bytes: 2108
// 時系列
// 計算量 O(n^2) のアルゴリズムを避ける
#include <algorithm>
#include <iostream>

static const int MAX = 200000;
using namespace std;

int main() {
  int n, minv, maxv;
  int R[MAX];
  cin >> n;
  for (int it = 0; it < n; ++it) {
    cin >> R[it];
  }
  minv = R[0];
  maxv = -10000000000;
  for (int it = 1; it < n; ++it) {
    maxv = max(maxv, R[it] - minv);
    minv = min(minv, R[it]);
  }
  cout << maxv << endl;
  return 0;
}


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

using namespace std;
using ll = long long;

#define REP(i,n) FOR(i, 0, n)
#define FOR(i,a,n) for(int i=(a); i<(n); i++)
#define FORR(i,a,n) for(int i=(a); i>=(n); i--)
#define REP(i,n) FOR(i, 0, n)

#define ALL(o) (o).begin(), (o).end()

template<class T> using V = vector<T>;
template<class T, class U> using P = pair<T, U>;
template<class T> using PQ = priority_queue<T>;
template<class T> using PQR = priority_queue<T, vector<T>, greater<T> >;

int main() {
	int n,tmp;
	V<int> v;

	cin >> n;

	REP(i,n) {
		cin >> tmp;
		v.push_back(tmp);
	}

	int cnt = 0;
	int ma = 0;

	FORR(i, n-2, 0) {
		if(v[i] >= v[i+1]) {
			cnt += 1;
			if(ma < cnt) {
				ma = cnt;
			}
		} else {
			cnt = 0;
		}
	}

	cout << ma << endl;
}




Measured memory_bytes: 892
#define _USE_MATH_DEFINES // for C++  
#include <cmath> 
#include <iostream>
#include <iomanip>
#include <string>
#include <vector>
#include <algorithm>
#include <array>
#include <iterator>
#include <utility>
#include <set>
#include <random>
#include <map>
#include <stack>
#include <queue>
#include <list>
#include <functional>
#include <bitset>
#define LL long long

using namespace std;

int main() {
    int h, w;
    vector<vector<char>> v(100, vector<char>(100));
    cin >> h >> w;
    for (size_t i = 0; i < h; i++)
    {
        for (size_t j = 0; j < w; j++)
        {
            cin >> v[i][j];
        }
    }

    for (size_t i = 0; i < h + 2; i++)
    {
        if (i == 0)
        {
            for (size_t j = 0; j < w + 2; j++)
            {
                cout << '#';
            }
            cout << endl;
            continue;
        }
        else if (i == h - 1 + 2)
        {
            for (size_t j = 0; j < w + 2; j++)
            {
                cout << '#';
            }
            cout << endl;
            continue;
        }
        else
        {
            cout << '#';
            for (size_t k = 0; k < w; k++)
            {
                cout << v[i - 1][k];
            }
            cout << '#';
            cout << endl;
        }

    }

}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <cassert>
#include <algorithm>
#include <functional>

using namespace std;
int main(){
    int n,m;
    cin >> n >> m;
    int max=n;
    int min=1;
    for(int i=0;i<m;i++){
        int l,r;
        cin >> l >> r;
        if(max>=r){
            max=r;
        }
        if(min<=l){
            min=l;
        }
    }
    if((max-min+1)>0){
        cout << max-min+1 <<endl;
    }else{
        cout << 0 << endl;
    }
        
    
}

Measured memory_bytes: 256
def binom(n, r):
    if (r < 0) or (n < r):
        return 0
    r = min(r, n - r)

    res = factinv[r] % p
    for i in range(r):
        res = res * (n - i) % p

    return fact[n] * factinv[r] * factinv[n-r] % p

X, Y = list(map(int, input().split()))

p = 10 ** 9 + 7

if X % 3 == 2 * Y % 3 and 2 * X % 3 == Y % 3:
    a = (2 * X - Y) // 3
    b = (2 * Y - X) // 3

    if a >= 0 and b >= 0:
        fact = [1, 1]
        factinv = [1, 1]
        inv = [0, 1]
        
        for i in range(2, a + b + 1):
            fact.append((fact[-1] * i) % p)
            inv.append((-inv[p % i] * (p // i)) % p)
            factinv.append((factinv[-1] * inv[-1]) % p)

        print(binom(a + b, a))
    else:
        print(0)
else:
    print(0)

Measured memory_bytes: 211616
#include <iostream>
#include <stdio.h>
#include <math.h>
#include <string.h>
#include <time.h>
#include <stdlib.h>
#include <string>
#include <bitset>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <algorithm>
#include <sstream>
#include <stack>
#include <iomanip>
using namespace std;
#define pb push_back
#define mp make_pair
typedef pair<int,int> pii;
typedef long long ll;
typedef double ld;
typedef vector<int> vi;
#define fi first
#define se second
#define fe first
#define FO(x) {freopen(#x".in","r",stdin);freopen(#x".out","w",stdout);}
#define Edg int M=0,fst[SZ],vb[SZ],nxt[SZ];void ad_de(int a,int b){++M;nxt[M]=fst[a];fst[a]=M;vb[M]=b;}void adde(int a,int b){ad_de(a,b);ad_de(b,a);}
#define Edgc int M=0,fst[SZ],vb[SZ],nxt[SZ],vc[SZ];void ad_de(int a,int b,int c){++M;nxt[M]=fst[a];fst[a]=M;vb[M]=b;vc[M]=c;}void adde(int a,int b,int c){ad_de(a,b,c);ad_de(b,a,c);}
#define es(x,e) (int e=fst[x];e;e=nxt[e])
#define esb(x,e,b) (int e=fst[x],b=vb[e];e;e=nxt[e],b=vb[e])
#define VIZ {printf("digraph G{\n"); for(int i=1;i<=n;i++) for es(i,e) printf("%d->%d;\n",i,vb[e]); puts("}");}
#define VIZ2 {printf("graph G{\n"); for(int i=1;i<=n;i++) for es(i,e) if(vb[e]>=i)printf("%d--%d;\n",i,vb[e]); puts("}");}
#define SZ 666666
char A[SZ],B[SZ];
int n;
ll f[10009];
#define MOD 998244353
ll fac[SZ],rfac[SZ];
ll qp(ll a,ll b)
{
	ll x=1;
	while(b)
	{
		if(b&1) x=x*a%MOD;
		a=a*a%MOD; b>>=1;
	}
	return x;
}
int main()
{
	fac[0]=1;
	for(int i=1;i<SZ;++i)
		fac[i]=fac[i-1]*i%MOD;
	rfac[SZ-1]=qp(fac[SZ-1],MOD-2);
	for(int i=SZ-1;i>=1;--i)
		rfac[i-1]=rfac[i]*i%MOD;
	scanf("%s%s",A+1,B+1); n=strlen(A+1);
	int x=0,y=0;
	for(int i=1;i<=n;++i) if(A[i]=='1')
		(B[i]=='0')?(++x):(++y);
	f[0]=1;
	for(int i=1;i<=x;++i)
		for(int j=1;j<=y;++j)
			f[j]=(f[j]+i*f[j-1])%MOD;
	ll ans=0;
	for(int j=0;j<=y;++j)
		ans=(ans+f[j]*rfac[x+j])%MOD;
	ans=ans*fac[x]%MOD*fac[x]%MOD
	*fac[y]%MOD*fac[x+y]%MOD;
	ans=(ans%MOD+MOD)%MOD;
	printf("%d\n",int(ans));
}


Measured memory_bytes: 10752
n, p = map(int, input().split())
a = list(map(int, input().split()))
cnt = [0, 0]

for i in a:
    cnt[i % 2] += 1

if cnt[1] == 0:
    print(0 if p == 1 else 2 ** n)
else:
    print(2**(n-1))


Measured memory_bytes: 9068
#include <string>
#include <vector>
#include <cstring>
#include <iostream>
#include <queue>
#include <map>
#include <set>
#include <algorithm>
#include <cstdlib>
#include <cmath>
#include <cctype>
#include <bitset>
#define vi vector < int >
#define mod 1000000007
#define inf 987654321
#define dinf -inf
#define lo long long int
#define S(n) scanf("%d",&n);
#define SL(n) scanf("%lld",&n);
#define P(n) printf("%d",n);
#define PL(n) printf("%lld",n);
#define spa printf(" ");
#define st(a,v) memset(a, v, sizeof (a))
#define nwl puts("");

using namespace std;


//string tostring(lo v) { ostringstream sout; sout << v; return sout.str(); }
#define two(x) (1ll << x)
#define contain(x, y) ( x & (two(y)))
lo ncr[100][100];
void genncr()
{
    int i, j;

    ncr[0][0]=1;
    int limncr = 80;
    for(i = 1; i <= limncr; i++)
        for(j = 0; j <= limncr; j++)
        {
            if(j > i) ncr[i][j] = 0;
            else if(j == i || j == 0) ncr[i][j] = 1;
            else ncr[i][j] = ncr[i-1][j-1] + ncr[i-1][j];
        }
}

string solve (lo n, lo p, lo m) {
    if (n==0)
        return "";
    lo ho = ncr[n-1][p];
    if (m >= ho)
        return "1" + solve (n - 1, p - 1, m - ho);
    return "0" + solve(n- 1, p, m);
}
int main ( ) {
    genncr();
    while(true) {
        lo n, m;
        cin >> n >> m;
        if(!n&&!m)break;
        m--;
        string str;
        for (int i = 0; i <= n; i++) {
            lo k = ncr[n][i];
            if (k > m) {
                str = solve (n, i, m);
                break;
            }
            m = m - k;
        }
        cout << str << endl;
    }
}

Measured memory_bytes: 1272
//2019.5.19 by ljz
#include<bits/stdc++.h>
using namespace std;
#define res register int
#define LL long long
#define inf 0x3f3f3f3f
#define eps 1e-10
#define RG register
inline int read() {
    res s=0,ch=getchar();
    while(ch<'0'||ch>'9')ch=getchar();
    while(ch>='0'&&ch<='9')s=s*10+ch-'0',ch=getchar();
    return s;
}
inline LL Read() {
    RG LL s=0;
    res ch=getchar();
    while(ch<'0'||ch>'9')ch=getchar();
    while(ch>='0'&&ch<='9')s=s*10+ch-'0',ch=getchar();
    return s;
}
inline void swap(res &x,res &y) {
    x^=y^=x^=y;
}
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
const int N=50+10;
namespace MAIN {
    int n,k;
    char str[N];
    inline void MAIN(){
        n=read(),k=read(),scanf("%s",str+1),str[k]=str[k]-'A'+'a',printf("%s\n",str+1);
    }
}
int main() {
//    srand((unsigned)time(NULL));
//    freopen("graph.in","r",stdin);
//    freopen("graph.out","w",stdout);
    MAIN::MAIN();
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < n; i++)
#define PI       3.1415926535897932384626433832795028841971
#define INF      1000000000.0
#define EPS      1e-10
#define MOD      1000000
using namespace std;
typedef long long ll;
typedef pair<double,double> P;
typedef pair<double,P> PQ;

int n, m;
ll ddp[110][4];
ll dp[110][110][3];

int main(){
    cin >> n >> m;
    swap(n,m);
    if(n == 1){
        ddp[0][1] = 1;
        ddp[0][2] = 1;
        for(int i = 0; i <= m; i++){
            ddp[i+1][1] = (ddp[i][1]+ddp[i][2])%MOD;
            ddp[i+1][2] = (ddp[i][1]+ddp[i][2])%MOD;
        }
        cout << ddp[m][2] << endl;
        return 0;
    }
    dp[0][0][0] = 1;
    for(int i = 0; i <= m; i++){
        dp[i+1][0][1] = dp[i][0][1];
        for(int j = 0; j <= i+1; j++){
            dp[i+1][j][0] = dp[i][j][0];
            dp[i+1][j][2] = dp[i][j][2];
            dp[i+1][0][1] += dp[i][j][0]+dp[i][j][2];
            dp[i+1][0][1] %= MOD;
        }
        dp[i+1][i+1][0] += dp[i][0][1];
        dp[i+1][i+1][2] += dp[i][0][1];
        for(int j = 0; j <= i+1; j++){
            dp[i+1][i+1][0] += dp[i][j][2]*(i+1-j);
            dp[i+1][i+1][2] += dp[i][j][0]*(i+1-j);
        }
        dp[i+1][i+1][0] %= MOD;
        dp[i+1][i+1][2] %= MOD;
    }
    ll ans = 0;
    rep(i,m+2) ans = (ans+dp[m+1][i][2])%MOD;
    cout << ans << endl;
}

Measured memory_bytes: 3352
def gcd(a,b):
    if b == 0:
        return a
    else:
        return gcd(b,a%b)

N, X = map(int, input().split())
x = list(map(int,input().split()))

x.append(X)
x.sort()

D = []
for n in range(N):
    D.append(x[n+1]-x[n])
    
ans = 0
for d in D:
    ans = gcd(ans,d)
        
print(ans)

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

using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
#define REP(i, n) for (int i = 0; i < (n); i++)
#define RREP(i, n) for (int i = (n) - 1; i >= 0; i--)
#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define RFOR(i, a, b) for (int i = (a); i > (b); i--)
#define ALL(a) (a).begin(), (a).end()

int main() {
    int H, W;
    string S;
    cin >> H >> W;
    REP(i, W + 2) cout << "#"; cout << endl;
    REP(i, H) {
        cin >> S;
        cout << "#" << S << "#" << endl;
    }
    REP(i, W + 2) cout << "#"; cout << endl;
    return 0;
}

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

using namespace std;

int W[103];

int main(){
	int N;
	scanf("%d", &N);
	
	int sum = 0;
	for(int i = 0; i < N; i ++){
		scanf("%d", &W[i]);
		sum += W[i];
	}

	int ans = sum;
	int temp = 0;
	for(int i = 0; i < N; i ++){
		temp += W[i];
		ans = min(ans, abs(sum-2*temp));
	}
	
	printf("%d", ans);
}



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

int main() {

	string s;
	cin >> s;

	if (s[0]==s[1] && s[1]==s[2]) {
		cout << "No" << endl;
		return 0;
	}

	cout << "Yes" << endl;
	return 0;
}

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

using namespace std;
int n,dat[100005];
bool cmp(int a,int b){return a>b;}
int main()
{
	scanf("%d",&n);
	for(int i=1;i<=n;i++) scanf("%d",&dat[i]);
	sort(dat+1,dat+n+1,cmp);
	
	int row=1,col=0;
	while(dat[row+1]>=row+1) row++;
	while(dat[row+col+1]>=row) col++;
	
	printf(!((dat[row]-row)&1)&&!(col&1)?"Second":"First");
	return 0;
}

Measured memory_bytes: 640
#!/usr/local/bin/python3
# https://atcoder.jp/contests/abc065/tasks/abc065_b

N = int(input())
a = [int(input())-1 for _ in range(N)]
ans = 0
cur = 0

visit = [-1] * N
while True:
    # print(cur, visit)
    cur = a[cur]
    ans += 1
    if visit[cur] == -1:
        visit[cur] = ans
    else:
        print(-1)
        exit()
    if cur == 1:
        print(ans)
        exit()

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

#define rep(i,n) for(int i=0;i<n;i++)
#define REP(i,s,n) for(int i=(s);i<=(n);i++)
#define repr(i,n) for(int i=n-1;i>=0;i--)
#define REPR(i,s,n) for(int i=(s);i>=(n);i--)
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
#define Eunique(v) v.erase(unique(all(v)),v.end())
#define Eback(s) s.erase(s.end()-1,s.end())
#define rev(v) reverse(all(v))
#define minvec(v) *min_element(all(v))
#define maxvec(v) *max_element(all(v))
#define sumvec(v) accumulate(all(v),0LL)
#define mapmax(v) v.rbegin()->first
#define mapmin(v) v.begin()->first
#define pb push_back
#define pf push_front
#define m_p make_pair
#define DOUBLE fixed << setprecision(15)
#define OK puts("OK")
#define OK1 puts("OK1")
#define OK2 puts("OK2")
#define SIZE(s) (int)s.size()
#define INF ((1LL<<62)-(1LL<<31))
#define zero(x,n) setw(x) << setfill('0') << n

typedef long long ll;

typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<long long> vll;
typedef vector<vll> vvll;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef vector<char> vc;
typedef vector<vc> vvc;
typedef vector<bool> vb;
typedef vector<vb> vvb;
typedef vector<string> vs;

typedef pair<ll,ll> pll;
typedef pair<int,int> pii;
typedef vector<pair<int,int>> vpii;
typedef vector<pair<ll,ll>> vpll;

const double pi = acos(-1.0);
const int mod=1000000007;
const int mod2=998244353;

template<class A, class B>
ostream& operator<<(ostream& ost, const pair<A, B>&p) {
	ost << "{" << p.first << ", " << p.second << "} ";
	return ost;
}

template<class T>
ostream& operator<<(ostream& ost, const vector<T>&v) {
	ost << "{";
	for (int i = 0; i<(int)v.size(); i++) {
		if (i)ost << " ";
		ost << v[i];
	}
	ost << "} \n";
	return ost;
}

template<class A, class B>
ostream& operator<<(ostream& ost, const map<A, B>&v) {
	ost << "{";
	for (auto p:v) {
		ost << "{" << p.first << ", " << p.second << "} ";
	}
	ost << "} ";
	return ost;
}

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

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

void YES(bool b) {cout << (b?"YES\n":"NO\n");}
void Yes(bool b) {cout << (b?"Yes\n":"No\n");}
void yes(bool b) {cout << (b?"yes\n":"no\n");}
void Yay(bool b) {cout << (b?"Yay!\n":":(\n");}

long long powmod(long long a,long long b){
    long long c=1;
    while(b>0){
        if(b&1) c=a*c%mod;
        a=a*a%mod;
        b>>=1;
    }
    return c;
}

ll gcd(ll x, ll y) {return __gcd(x,y);}
ll lcm(ll x, ll y) {return x/__gcd(x,y)*y;}

int main()
{
	ll n,ans=0;
	map<ll,ll> m;
	cin >> n;
	vll a(n);
	rep(i,n){
		cin >> a[i];
		m[i+1]=a[i];
	}
	rep(i,n){
		if(m[a[i]]==i+1) ans++;
	}
	cout << ans/2 << endl;
	return 0;
}


Measured memory_bytes: 7296
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<ll, ll>;
const string ln = "\n";
constexpr int INF = 1001001001;
constexpr int MOD = 1000000007;

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

  string s;
  cin >> s;

  ll ans = 0;
  ll b = 0;
  for (int i = 0; i < s.size(); i++) {
    if (s[i] == 'B') {
      b++;
    } else {
      ans += b;
    }
  }

  cout << ans << ln;

  return 0;
}

Measured memory_bytes: 720
string = raw_input()
num_order = int(raw_input())
for i in range(num_order):
    command = raw_input().split()
  #  print command
    a, b = map(int, command[1:3])
    if command[0] == "print":
        print string[a:b+1]
    elif command[0] == "reverse":
        string = string[:a] + string[a:b+1][::-1] + string[b+1:]
    elif command[0] == "replace":
        p = command[-1]
        string = string[:a] + p + string[b+1:]

Measured memory_bytes: 6464
#include<stdio.h>
int main(){
  int A[100],i,j,N,b,c,count=0,flag;
  flag = 1;
  scanf("%d",&N);
  for(i = 0; i < N; i++){
    scanf("%d",&A[i]);
  }
  while(flag == 1){
    flag = 0;   
    for(j = N-1; j >= 1; j--){
      if(A[j] < A[j-1]){
	c = A[j];
	b = A[j-1];
	A[j-1] = c;
	A[j] = b;
	flag = 1;
	count++;
      }
    }
  }
  for(i = 0; i < N-1; i++){
    printf("%d ",A[i]);
  }
  printf("%d\n%d\n",A[N-1],count);
  return 0;
}


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

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> P;
typedef vector<ll> V;
typedef complex<double> Point;

#define PI acos(-1.0)
#define EPS 1e-10
const ll INF = 1e16;
const ll MOD = 1e9 + 7;

#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define rep(i,N) for(int i=0;i<(N);i++)
#define ALL(s) (s).begin(),(s).end()
#define EQ(a,b) (abs((a)-(b))<EPS)
#define EQV(a,b) ( EQ((a).real(), (b).real()) && EQ((a).imag(), (b).imag()) )
#define fi first
#define se second
#define N_SIZE (1LL << 20)
#define NIL -1

ll sq(ll num) { return num*num; }
ll mod_pow(ll x, ll n) {
	if (n == 0)return 1;
	if (n == 1)return x%MOD;
	ll res = sq(mod_pow(x, n / 2));
	res %= MOD;
	if (n % 2 == 1) {
		res *= x;
		res %= MOD;
	}
	return res;
}

ll l,n;

int main(){
	cin >> n >> l;
	ll a = l;
	ll b = l+n-1;
	ll ans = 0;
	rep(i,n)ans += (l+i);
	if(a*b <= 0)cout << ans << endl;
	else if(a > 0 && b > 0)cout << ans - a << endl;
	else cout << ans - b << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(ll i=0;i<n;i++)
#define repl(i,l,r) for(ll i=(l);i<(r);i++)
#define per(i,n) for(ll i=n-1;i>=0;i--)
#define perl(i,r,l) for(ll i=r-1;i>=l;i--)
#define fi first
#define se second
#define pb push_back
#define ins insert
#define pqueue(x) priority_queue<x,vector<x>,greater<x>>
#define all(x) (x).begin(),(x).end()
#define CST(x) cout<<fixed<<setprecision(x)
#define vtpl(x,y,z) vector<tuple<x,y,z>>
#define rev(x) reverse(x);
using ll=long long;
using vl=vector<ll>;
using vvl=vector<vector<ll>>;
using pl=pair<ll,ll>;
using vpl=vector<pl>;
using vvpl=vector<vpl>;
const ll MOD=1000000007;
const ll MOD9=998244353;
const int inf=1e9+10;
const ll INF=4e18;
const ll dy[8]={1,0,-1,0,1,1,-1,-1};
const ll dx[8]={0,-1,0,1,1,-1,1,-1};
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;
}
int main(){
    ll n;cin >> n;
    map<ll,ll> mp;
    ll d=n;
    repl(i,2,(ll)sqrt(n)+1){
        while(d%i==0){
            mp[i]++;
            d/=i;
        }
    }
    if(d!=1)mp[d]++;
    ll ans=0;
    /*for(auto p:mp){
        cout << p.fi <<" " << p.se <<endl;
    }*/
    for(auto p:mp){
        ll cnt=1;
        while(p.se>=cnt){
            p.se-=cnt;
            cnt++;
            ans++;
        }
    }
    cout << ans <<endl;
}

Measured memory_bytes: 3724
#include <stdio.h>

int main() {
    long int t, ac = 0, wa = 0, tle = 0, re = 0;
    scanf("%ld", &t);
    for (int i = 0; i < t; i++) {
        char temp[4];
        scanf("%s", &temp);
        switch (temp[0]) {
            case 'A':
                ac++;
                break;
            case 'W':
                wa++;
                break;
            case 'T':
                tle++;
                break;
            case 'R':
                re++;
                break;
        }
    }
    printf("AC x %d\nWA x %d\nTLE x %d\nRE x %d", ac, wa, tle, re);
}

Measured memory_bytes: 1736
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;
#define F first
#define S second
#define endl '\n'
#define fastio ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define maxp 22
#define EPS (ld)(1e-18)
#define mod (int)(1e9+7)
#define N (int)(1e5+1)


int main (){
fastio;


ll a;
cin>>a;

ll ans=a+a*a+a*a*a;
cout<<ans;


}


Measured memory_bytes: 3644
/*input
FESTIVAL2016CODE

*/
#include <bits/stdc++.h>
#include <stdlib.h>
#include <time.h> 

using namespace std;
long long mod=1e9+7;
typedef long long int lld;
#define rep(i,a,n) for(long long int i = (a); i <= (n); ++i)
#define repI(i,a,n) for(int i = (a); i <= (n); ++i)
#define repD(i,a,n) for(long long int i = (a); i >= (n); --i)
#define repDI(i,a,n) for(int i = (a); i >= (n); --i)
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define sc(a) scanf("%lld",&a)
#define sc2(a,b) scanf("%lld%lld",&a,&b)
#define sc3(a,b,c) scanf("%lld%lld%lld",&a,&b,&c)
#define scd(a) scanf("%d",&a)
#define scd2(a,b) scanf("%d%d",&a,&b)
#define scd3(a,b,c) scanf("%d%d%d",&a,&b,&c)
#define scf(a) scanf("%lf",&a)
#define scf2(a,b) scanf("%lf%lf",&a,&b)
#define scf3(a,b,c) scanf("%lf%lf%lf",&a,&b,&c)
#define prL(a) printf("%lld\n",a)
#define prS(a) printf("%lld ",a)
#define prdL(a) printf("%d\n",a)
#define prdS(a) printf("%d ",a)
#define Error(x) cerr << #x << " = " << (x) <<endl;
#define Error2(a,b) cerr<<"( "<<#a<<" , "<<#b<<" ) = ( "<<(a)<<" , "<<(b)<<" )\n";
#define Error3(a,b,c) cerr<<"("<<#a<<" , "<<#b<<" , "<<#c<<" ) = ( "<<(a)<<" , "<<(b)<<" , "<<(c)<<")\n";
#define Error4(a,b,c,d) cerr<<"("<<#a<<" , "<<#b<<" , "<<#c<<" , "<<#d<<" ) = ( "<<(a)<<" , "<<(b)<<" , "<<(c)<<" , "<<(d)<<")\n";
#define errop(a) cerr<<#a<<" = ( "<<((a).x)<<" , "<<((a).y)<<" )\n";
#define popcount __builtin_popcountll
typedef pair<lld,lld> PA;
#define lim 1000010
#define lim2 3003
// inline lld sqr(lld x) { return x * x; }
// map<lld,lld>::iterator it;
// std::ios::sync_with_stdio(false);
// priority_queue<PA> Q;
// lld dp[1<<18];

lld A[lim],Fen[lim];

lld n,m,p,q;

lld P[lim];


lld powP(lld a,lld b){
    if(b==0) return 1%mod;
    lld k;
    k=powP(a,b/2);
    k=k*k%mod;
    if(b%2==0) return k;
    else return a*k%mod;
}


int main(){
    lld T,i,j,h,l,r,k,s,b,c,a,d,w,x,y,v,z,t,curr,prev,sum,ans,pos,val,countA,secondMin,indicator;
    string A,B;
    A="CODEFESTIVAL2016";
    cin>>B;
    countA=0;
    n=B.size();
    rep(i,0,n-1) if(A[i]!=B[i]) countA++;
    prL(countA);
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#pragma GCC target("avx")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
typedef long long ll;
typedef pair<ll,ll> pr;
typedef vector<ll> vc;
typedef unordered_map<ll,ll> umap;
#define pb emplace_back
#define rep(i,a,b) for(ll i=a;i<=b;i++)
#define repr(i,a,b) for(ll i=a;i>=b;i--)
#define reps(i,v) for(ll i=0;i<v.size();i++)
template<typename T> void chmin(T &a, const T &b) { a = min(a, b); }
template<typename T> void chmax(T &a, const T &b) { a = max(a, b); }

int main() {
    // your code goes here
    ll n, W, w[105], v[105], dp[105][100005]={0};
    cin >> n >> W;
    rep(i,1,n){
    	cin >> w[i] >> v[i];
    	rep(j,0,W){
    		if(j>=w[i]) dp[i][j]=max(dp[i-1][j], dp[i-1][j-w[i]] + v[i]);
    		else dp[i][j] = dp[i-1][j];
    	}
    }
    cout << dp[n][W] << endl;
    return 0;
}

Measured memory_bytes: 82304
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<ll> vi;
#define REP(i, n) for (ll i = 0; i < (n); ++i)
#define OUT(x) cout << (x) << endl;
#define OUTA(a, n) \
    REP(i, n) { cout << (a[i]) << (i == n - 1 ? "\n" : " "); }
#define ALL(a) (a).begin(), (a).end()
#define SORT(a) sort(ALL(a))
#define RSORT(a) \
    SORT(a);     \
    reverse(ALL(a))

const ll INF = 1e18;
const ll MOD = 1e9 + 7;

ll N, M;
vi s;
vi c;

int main()
{
    cin >> N >> M;
    s = vi(M);
    c = vi(M);
    REP(i, M)
    {
        cin >> s[i] >> c[i];
    }

    ll ans = -1;
    REP(x, 1000)
    {
        string y = to_string(x);
        if (y.size() != N)
        {
            continue;
        }
        bool ok = true;
        REP(i, M)
        {
            ok &= (y[s[i] - 1] == (c[i] + '0'));
        }
        if (ok)
        {
            ans = x;
            break;
        }
    }

    OUT(ans);
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef pair<int,int> PII;
typedef long long ll;
const ll mod = 1e9+7;

int main(void){
  int n,m;
  vector<ll> xelem;
  vector<ll> yelem;
  vector<ll> xmult;
  vector<ll> ymult;
  ll xsum = 0,ysum = 0;
  cin >> n >> m;
  --n;--m;  
  ll prev,now,mult;
  cin >> prev;
  for(int i = 0;i < n;++i){
    cin >> now;
    xelem.push_back(now-prev);
    prev = now;
  }
  xmult.resize(n);
  mult = 0;
  for(int i = 0;i < (n+1)/2;++i){
    mult += n - 2*i;
    mult %= mod;
    xmult[i] = mult;
    xmult[n-1-i] = mult;
  }
  for(int i = 0;i < n;++i){
    xsum += xelem[i]*xmult[i];
    xsum %= mod;
  }

  
  cin >> prev;
  for(int i = 0;i < m;++i){
    cin >> now;
    yelem.push_back(now-prev);
    prev = now;
  }
  ymult.resize(m);
  mult = 0;
  for(int i = 0;i < (m+1)/2;++i){
    mult += m - 2*i;
    mult %= mod;
    ymult[i] = mult;
    ymult[m-1-i] = mult;
  }
  for(int i = 0;i < m;++i){
    ysum += yelem[i]*ymult[i];
    ysum %= mod;
  }
  cout << (xsum*ysum)%mod << endl;
  return 0;
}


Measured memory_bytes: 3572
using System;
public class Hello{
    public static void Main(){
        string s = Console.ReadLine();
        for (int i = 0;i<4;i++){
            int cnt = 0;
            for (int j = 0;j<4;j++){
                if (s[j]==s[i]){
                    cnt++;
                }
            }
            if (cnt !=2){
               Console.WriteLine("No");
               Environment.Exit(0);
            }
        }
        Console.WriteLine("Yes");
    }
}


Measured memory_bytes: 11092
import java.util.*;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		while ( sc.hasNext() ) {
			int sum = 0 , x = 0 , y , d , i = 0;
			d = sc.nextInt();
			while ( i < 600 ) {
				y = x * x;
				x += d;
				sum += y * d;
				i += d;
			}
			System.out.println(sum);
		}
	}
}

Measured memory_bytes: 12000
import java.util.Scanner;

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

		int a = in.nextInt();
		int b = in.nextInt();
		int c = in.nextInt();

		int n = b - a;
		int m = c - b;

		if (n == m) {
			System.out.println("YES");
		} else {
			System.out.println("NO");
		}
	}
}

Measured memory_bytes: 21716
#include <stdio.h>
int main()
{
  int N,A[100],i,j,minj,flag,a,count=0;

  scanf("%d",&N);
  for(i=0;i<N;i++){
    scanf("%d",&A[i]);
  }


  for(i=0;i<N-1;i++){
    minj = i;
    for(j=i;j<N;j++){
      if(A[j]<A[minj]){
	minj = j;
      }
    }
    if(minj!=i){
    a = A[i];
    A[i] = A[minj];
    A[minj]=a;
    count++;
    }
  }

  for(i=0;i<N-1;i++){
    printf("%d ",A[i]);
  }
  printf("%d\n",A[i]);

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

  return 0;
}

Measured memory_bytes: 600
#include <stdlib.h>
#include <string.h>
#include <math.h>
#include <stdio.h>
int compare(const void *a,const void *b){
    if(*(long long*)a>*(long long *)b )return 1;
    return -1;
}
int main()
{   int i,j,a,b,n,m,k;
char chk[4]="BTC";
    scanf("%d",&n);
    double x[n];
    double ans=0;
    for(i=0;i<n;i++){
        char tmp[4];
        scanf("%lf",&x[i]);
        
        scanf("%s",tmp);
        if(strcmp(tmp,chk)==0){
            x[i]*=380000;
        }
        ans+=x[i];
        
    }printf("%lf",ans);

    return 0;
}


Measured memory_bytes: 128
import java.util.*;
import java.util.Scanner;

public class Main{
	
	public static void main(String[] args) {
		Scanner sc=new Scanner(System.in);
		int n=sc.nextInt();
		int[] a=new int[n+1];
		
		for(int i=1;i<=n;i++) {
			a[i]=sc.nextInt();
		}
		
		Arrays.sort(a);
		
		long ans=0;
	
		for(int i=1;i<=n-1;i++) {
			//if(i/2==0)ans+=a[n-1];
			ans+=a[n-i/2];
		}
		
	    System.out.println(ans);
	}
}


Measured memory_bytes: 60160
import numpy as np
X,N = map(int, input().split())
p = list(map(int, input().split()))
p = sorted(p)
lista = list(range(-100,200))
for i in p:
    if i in lista:
        lista.remove(i)
def getNearestValue(list, num):
    """
    概要: リストからある値に最も近い値を返却する関数
    @param list: データ配列
    @param num: 対象値
    @return 対象値に最も近い値
    """
    # リスト要素と対象値の差分を計算し最小値のインデックスを取得
    idx = np.abs(np.asarray(list) - num).argmin()
    print(list[idx])
if N == 0:
    print(X)
else:
    getNearestValue(lista, X)

Measured memory_bytes: 27260
#include <stdio.h>
#include <string.h>
char s[11];
char t[100][21];
int main()
{
  int n,l,i,c=0;
  scanf("%s",s);
  scanf("%d",&n);
  l = strlen(s);
  for(i=0;i<n;i++){
    scanf("%s",t[i]);
    strncat(t[i],t[i],l-1);
    if(strstr(t[i],s) != NULL) c++;
  }
  printf("%d\n",c);
  return 0;
}

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

using namespace std;

typedef long long ll;

const int INF = 1e9;

struct Node_t {
  int id_, left_, right_;
  Node_t() : id_(-1), left_(-1), right_(-1) {}
};

Node_t nodes[50];
int visited[50] = { 0 };

int rec(vector<int> ids, vector<int>& pre, vector<int>& in)
{
  if (ids.empty()) { return -1; }
  int root_id = -1;
  int n = ids.size(), m = pre.size();
  for (int i = 0; i < m; ++i) {
    for (int j = 0; j < n; ++j) {
      if (ids[j] == pre[i]) {
        root_id = ids[j];
        break;
      }
    }
    if (root_id != -1) { break; }
  }
  visited[root_id] = 1;
  vector<int> lsub, rsub;
  bool left_done = false;
  for (int i = 0; i < m; ++i) {
    int id = in[i];
    if (id == root_id) {
      left_done = true;
      continue;
    }
    if (visited[id]) { continue; }
    for (int j = 0; j < n; ++j) {
      if (id == ids[j]) {
        if (left_done) { rsub.push_back(id); }
        else { lsub.push_back(id); }
        break;
      }
    }
  }
  nodes[root_id].left_ = rec(lsub, pre, in);
  nodes[root_id].right_ = rec(rsub, pre, in);
  return root_id;
}

void postorder(int id, vector<int>& ids)
{
  if (id == -1) { return; }
  postorder(nodes[id].left_, ids);
  postorder(nodes[id].right_, ids);
  ids.push_back(id);
}

int main()
{
  int n = 0;
  fscanf(stdin, "%d", &n);
  vector<int> ids(n), pre(n), in(n);
  for (int i = 0; i < n; ++i) {
    fscanf(stdin, "%d", &pre[i]);
    ids[i] = i + 1;
  }
  for (int i = 0; i < n; ++i) {
    fscanf(stdin, "%d", &in[i]);
  }
  int root_id = rec(ids, pre, in);
  vector<int> post_ids;
  postorder(root_id, post_ids);
  for (int i = 0; i < n; ++i) {
    if (i) { fprintf(stdout, " "); }
    fprintf(stdout, "%d", post_ids[i]);
  }
  fprintf(stdout, "\n");
  return 0;
}

Measured memory_bytes: 1232
N = int(input())
A = list(map(int,input().split()))

neg_cnt = 0
for a in A:
  if a < 0:
    neg_cnt += 1

B = list(map(abs, A))
if neg_cnt%2 == 0:
  print(sum(B))
else:
  print(sum(B) - 2*min(B))

Measured memory_bytes: 14284
#include<bits/stdc++.h>
using namespace std;
#define F(n) for(int i=0;i<n;++i)

int main()
{
    long n;
    string s;
    cin >> n >> s;
    F(s.size()){
        s[i] = s[i]+n;
        if(s[i]>'Z') s[i]=s[i]-'Z'+'A'-1;
    }
    cout << s << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define INF 1LL<<62
#define inf 1000000007

int main() {
	string s;
	cin>>s;
	string t=s;
	reverse(s.begin(),s.end());
	ll ans=0;
	for(ll i=0;i<s.size()/2;i++){
		if(s[i]!=t[i]){
			ans++;
		}
	}
	cout << ans;
	// your code goes here
	return 0;
}

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

using namespace std;

#define pii pair<int,int>
#define ll long long
#define s second
#define f first

ll n,a;
map<ll,int> mp;
bool b=true;

int main(){
  cin >> n;
  for(int i=0;i<n;++i){
    cin >> a;
    ++mp[a];
    if(mp[a]==2){b=false;}
  }
  if(b){cout << "YES";}
  else{cout << "NO";}
  return 0;
}


Measured memory_bytes: 12800
import math
n, d = map(int,input().split())
xs = []
for _ in range(n):
  x = list(map(int, input().split()))
  xs.append(x)
ans = 0
for i in range(n-1):
  xi = xs[i]
  for j in range(i+1, n):
    xj = xs[j]
    dist = 0
    for k in range(d):
      dist += (xi[k] - xj[k])**2
    dist = math.sqrt(dist)
    if dist - int(dist) == 0.0:
      ans += 1
print(ans)


Measured memory_bytes: 3064
#include<bits/stdc++.h>
using namespace std;
#define mod 1000000007
//This is a O(n^2) implementation of the problem (Reference: Errichto's youtube video)
int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n;
    string s;
    cin>>n>>s;
    int dp[n+1][n+1];
    int pref[n];
    //dp[i][j] means how many permutations exist with n=i and last 
    //number in the perumtation ending with j
    //The main trick in this question is that, just knowing
    //Which number do you want to place at the current position
    //and all the possible numbers you could have placed in 
    //the previous position, you can find out the number of
    //ways for the numbers in the current position using the 
    //previous ones. Okay..Okay.. I didn't mean to confuse you
    //...Let me tell this straight suppose, you know what are
    //the answers for first two positions, like in the case
    //of "3 <>", for position 1, you have 1 possibility
    //1<2 (1 possiblity for position 2), now comes the trick,
    //For position 3 1<2>1 (The question is can you place one at the end?)
    //Turns out yes, you can, if the previous position was 
    //3, but you know previous position cannot be 3 because you 
    //only had 2 spots, right? There is the catch, you add
    //the number of ways for which previous spot was 2 
    //and you can (imagine) change the above relation to 2<3<1
    //for all such possiblities, basically what I am saying is
    //for every number of ways you find after solving for some
    //i positions, you only care about the previous digit that
    //is possible and for all such ways you can guarantee that
    //you can get a permutation which ends in j.
    memset(dp,0,(n+1)*sizeof(dp[0]));
    dp[1][1] = 1;
    for(int i=2;i<=n;i++){
        memset(pref,0,4*n);
        for(int j=1;j<=(i-1);j++){
            pref[j] = (pref[j-1]+dp[i-1][j])%mod;
        }
        for(int j=1;j<=i;j++){
            int l,r;
            if(s[i-2]=='>')l=j,r=i-1;
            else l=1,r=j-1;
            if(l<=r)
                dp[i][j] = (dp[i][j]+pref[r]-pref[l-1]+mod)%mod;
        }
    }
    int ans = 0;
    for(int j=1;j<=n;j++){
        ans = (ans+dp[n][j])%mod;
    }
    cout<<ans<<"\n";
    return 0;
}

Measured memory_bytes: 35456
using System;
using System.Collections.Generic;
using System.Linq;
using static System.Console;
using static System.Math;

namespace A_ABC164
{
    class MainClass
    {

        static int[] s;

        public static void Main(string[] args)
        {
            s = Array.ConvertAll(ReadLine().Split().ToArray(), int.Parse);
            if(s[0]<=s[1]){
                WriteLine("unsafe");
            }else{
                WriteLine("safe");
            }
        }
    }
}


Measured memory_bytes: 27960
#include <iostream>
#include <string>
#include <algorithm>
#include <utility>
#include <math.h>
#include <vector>
using namespace std;
typedef long long ll;

int N;
int A[100];

int main(){
	cin >> N;
	

	for(int i=0; i<N; i++){
		cin >> A[i];
	}
	
	sort(A, A+N, greater<int>());
	int alice=0, bob=0;
	for(int i=0; i<N; i++){
		if(i % 2 == 0) alice += A[i];
		if(i % 2 == 1) bob += A[i];
	}
	cout << alice - bob << endl;
	
}

Measured memory_bytes: 256
#include<stdio.h>
#include<stdlib.h>
#define PI 3.141592653589

int main()
{
  int h,w,i,j;
  while(1)
    {
      scanf("%d %d",&h,&w);
      if(h == 0 && w == 0) break;
      for(i = 0; i < h; i++)
	{
	  for(j = 0; j < w; j++)
	    {
	      if((i+j) % 2 == 0) printf("#");
	      else printf(".");
	    }
	  printf("\n");
	}
      printf("\n");
    }
  return 0;
}

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

using namespace std;
#define rep(i, n) for(int i=0;i<n;i++)
#define REP(i, n) for(int i=1;i<=n;i++)
typedef long long ll;

const int INF = 1001001001;

int main() {
	int n, l;
	cin >> n >> l;
	int sum = 0;
	REP(i, n) sum += l + i - 1;
	int m = INF;
	REP(i, n) {
		if (abs(m) > abs(l + i - 1)) m = l + i - 1;
	}
	int ans = sum - m;
	cout << ans << endl;
	return 0;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define REP(i,a,n) for(int i=(a); i<(int)(n); i++)
#define rep(i,n) REP(i,0,n)
#define FOR(it,c) for(__typeof((c).begin()) it=(c).begin(); it!=(c).end(); ++it)
#define ALLOF(c) (c).begin(), (c).end()
typedef long long ll;
typedef unsigned long long ull;

struct SummedAreaTable{
  static const int SIZE_N = 2005;
  static const int SIZE_M = 2005;
  int n, m;
  int I[SIZE_N][SIZE_M];
public:
  int table[SIZE_N][SIZE_M];
  SummedAreaTable(){
    n = SIZE_N;
    m = SIZE_M;
  }
  void init(){
    for(int y=0; y<n; y++){
      for(int x=0; x<m; x++){
        I[y][x] = table[y][x];
        if(y-1>=0) I[y][x] += I[y-1][x];
        if(x-1>=0) I[y][x] += I[y][x-1];
        if(x-1>=0 && y-1>=0) I[y][x] -= I[y-1][x-1];
      }
    }
  }
  int sum(int y, int x){
    if(y < 0 || x < 0) return 0;
    return I[y][x];
  }

  int sum(int y1, int x1, int y2, int x2){
    return sum(y2,x2) - sum(y1-1,x2) - sum(y2,x1-1) + sum(y1-1,x1-1);
  }
  
};

int field[2][2005][2005];
SummedAreaTable sat[2];



int main(){
  int N, K;
  cin >> N >> K;
  vector<int> x, y, c;
  rep(i,N){
    int xx, yy;
    string cc;
    cin >> xx >> yy >> cc;
    x.push_back(xx);
    y.push_back(yy);
    if(cc == "B") c.push_back(0);
    else c.push_back(1);
  }

  rep(i,N){
    int xx = x[i]%(2*K), yy = y[i]%(2*K);
    field[c[i]][yy][xx]++;
  }
  rep(i,2){
    rep(y,2005){
      rep(x,2005){
        sat[i].table[y][x] = field[i][y][x];
      }
    }
    sat[i].init();
  }
  

  int ret = 0;
  rep(i,K+1){
    rep(j,K+1){
      rep(col,2){
        int tmp = 0;
        tmp += sat[col].sum(0,0,i-1,j-1);
        tmp += sat[1-col].sum(0,j,i-1,j+K-1);
        tmp += sat[col].sum(0,j+K,i-1,2*K-1);
        tmp += sat[1-col].sum(i,0,i+K-1,j-1);
        tmp += sat[col].sum(i,j,i+K-1,j+K-1);
        tmp += sat[1-col].sum(i,j+K,i+K-1,2*K-1);
        tmp += sat[col].sum(i+K,0,2*K-1,j-1);
        tmp += sat[1-col].sum(i+K,j,2*K-1,j+K-1);
        tmp += sat[col].sum(i+K,j+K,2*K-1,2*K-1);
        ret = max(ret, tmp);
      }
    }
  }

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


Measured memory_bytes: 95852
#include<cstdio>
#include<set>
#include<map>
#include<algorithm>
#define mp(x,y) make_pair(x,y)
#define pi pair<int,int>
using namespace std;
inline int read(){int x=0,f=1,ch=getchar(); while(ch<'0'||ch>'9'){if(ch=='-') f=-1; ch=getchar();} while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();} return x*f;}
inline void write(int x){if (x<0) putchar('-'),x=-x; if (x>=10) write(x/10); putchar(x%10+'0');}
inline void writeln(int x){write(x); puts("");}
const int N=1e5+5;
set<int >se[N];
map<pi,int> ma;
pi q[N];
int n,h,t,fa[N];
inline int getfa(int x){
	return (fa[x]==x)?x:fa[x]=getfa(fa[x]);
}
inline void init(){
	n=read();
	for (int i=1;i<=n*2-2;i++){
		int u=read(),v=read();
		se[u].insert(v); se[v].insert(u);
		ma[mp(u,v)]++; ma[mp(v,u)]++;
		if (ma[mp(u,v)]==2) q[++t]=make_pair(u,v);
	}
}
inline void solve(){
	for (int i=1;i<=n;i++) fa[i]=i;
	set<int >::iterator it;
	while (h<t){
		int u=q[++h].first,v=q[h].second;
		u=getfa(u); v=getfa(v);
		se[u].erase(v); se[v].erase(u);
		if (se[u].size()<se[v].size()) swap(u,v);
		for (it=se[v].begin();it!=se[v].end();++it){
			int to=(*it);
			ma[mp(to,v)]=ma[mp(v,to)]=0;
			se[to].erase(v); se[to].insert(u);
			ma[mp(to,u)]++; ma[mp(u,to)]++;
			if (ma[mp(to,u)]==2) q[++t]=make_pair(to,u);
			se[u].insert(to);
		}
		fa[v]=u;
		se[v].clear();
	}
	int s=0;
	for (int i=1;i<=n;i++) s+=fa[i]==i;
	if (s==1) puts("YES"); else puts("NO");
}
int main(){
	init(); solve();
	return 0;
}

Measured memory_bytes: 58368
#include <bits/stdc++.h>
#include <chrono>
#define watch(x) cout << (#x) << " is " << (x) << endl
#define eps 1e-9
#define f first
#define s second

typedef long long ll;

using namespace std;

const int N = 1e5;
int a[N+5];

int main()

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

    int n, sum = 0, maxi = -1;

    cin >> n;

    int arr[n];

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

        cin >> arr[i];
        sum+=arr[i];
        maxi = max(maxi, arr[i]);
    }

    sum-=maxi/2;

    cout << sum;

    return 0;
}



Measured memory_bytes: 256