akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;

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

    queue<pair<int, int> > que;

    if(n % 2 == 1){
        for(int i = 1;i < n;i++){
            que.push(make_pair(i, n));
        }

        for(int i = 1;i < n/2;i++){
            for(int j = n-i-1;j > i;j--){
                que.push(make_pair(i, j));
            }
        }

        for(int i = n-1;i >(n+1)/2;i--){
            for(int j = n-i+1;j < i;j++){
                que.push(make_pair(i, j));
            }
        }

    }else{
        for(int i = 2;i < n;i++){
            que.push(make_pair(i, n));
            que.push(make_pair(1, i));
        }

        for(int i = 2;i < n/2;i++){
            for(int j = n-i;j > i;j--){
                que.push(make_pair(i, j));
            }
        }

        for(int i = n-1;i > n/2+1;i--){
            for(int j = n-i+2;j < i;j++){
                que.push(make_pair(i, j));
            }
        }
    }

    cout << que.size() << endl;
    while(!que.empty()){
        cout << que.front().first << " " << que.front().second << endl;
        que.pop();
    }

    return 0;
}


Measured memory_bytes: 384
#include<bits/stdc++.h>
using namespace std;
#define int long long int
#define fast ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define mod 1000000007
#define endl "\n"

int32_t main()
{
	fast;
	int n;
	cin>>n;
	// string s;
	// cin>>s;
	vector<string> v;
	unordered_map<string, int> m;
	for(int i=0;i<n;i++)
	{
		string s;
		cin>>s;
		sort(s.begin(), s.end());
		m[s]++;
		if(m[s]==1)
			v.push_back(s);
	}
	int c=0;
	for(int i=0;i<v.size();i++)
	{
		int x=m[v[i]];
		c+=(x*(x-1))/2;
	}
	cout<<c<<endl;
	return 0;
}

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

using namespace std;

const int maxn = 20;
const int INF = 1e9 + 100;


int main() {
    //freopen("input", "r", stdin);
    //freopen("output", "w", stdout);

    ios_base::sync_with_stdio(false);
    cin.tie(0);

    string s;
    cin >> s;

    if (s.size() < 4) {
        cout << "No\n";
        return 0;
    }

    if (s[0] == 'Y' && s[1] == 'A' && s[2] == 'K' && s[3] == 'I') {
        cout << "Yes\n";
        return 0;
    }

    cout << "No\n";


    return 0;
}


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

template<typename T>
ostream& operator<<(ostream &os, vector<T> &v){
	string sep = " ";
	if(v.size()) os << v[0];
	for(int i=1; i<v.size(); i++) os << sep << v[i];
	return os;
}

template<typename T>
istream& operator>>(istream &is, vector<T> &v){
	for(int i=0; i<v.size(); i++) is >> v[i];
	return is;
}

#ifdef DBG
void debug_(){ cout << endl; }
template<typename T, typename... Args>
void debug_(T&& x, Args&&... xs){
	cout << x << " "; debug_(forward<Args>(xs)...);
}
#define dbg(...) debug_(__VA_ARGS__)
#else
#define dbg(...)
#endif

int main() {
	ios_base::sync_with_stdio(false);
	cout << setprecision(20) << fixed;

	ll n, d; cin >> n >> d;
	vector<ll> x(n), y(n);
	for(int i=0; i<n; i++) cin >> x[i] >> y[i];

	int ans = 0;
	for(int i=0; i<n; i++){
		if(x[i]*x[i]+y[i]*y[i]<=d*d) ans++;
	}
	cout << ans << endl;

	return 0;
}


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

using namespace std;


int main()
{

   int n;
   cin >> n;
   int ai = 0,bi = 0;
   for (int i=0;i<n;i++)
   {
       int z;
       cin >> z;
       if (z % 2 == 0)ai++;
       else bi++;
   }
   if (bi % 2 == 0)return cout << "YES",0;
   else cout << "NO";
   return 0;
}


Measured memory_bytes: 384
#include<bits/stdc++.h>
#define int long long
using namespace std;
signed main()
{
	char s[100];
	int n,count=0,i;
	cin>>n;
	cin>>s;
	for(i=0;i<n-2;i++)
	{
		if(s[i]=='A'&&s[i+1]=='B'&&s[i+2]=='C')
			count++;
	}
	cout<<count<<endl;
	return 0;
}

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

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


Measured memory_bytes: 3672
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using V = vector<ll>;
#define _GLIBCXX_DEBUG
#define rep(i, a, b) for(int i = a; i < b; i++)
#define ALL(v) v.begin(), v.end()

int main(){
    string a,b,c;
    cin>>a>>b>>c;
    cout<<a[0]<<b[0]<<c[0]<<endl;
}


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

int main(){
  int n;
  ll d;
  string s;
  cin >> n >> d;
  int ans = 0;
  
  rep(i,n){
    ll a,b;
    cin >> a >> b;
    if (a*a + b*b <= d*d) ans++;
  }
  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 3636
#include<stdio.h>
#include<math.h>
#include<algorithm>
#include<queue>
#include<deque>
#include<stack>
#include<string>
#include<string.h>
#include<vector>
#include<set>
#include<map>
#include<bitset>
#include<stdlib.h>
#include<cassert>
#include<time.h>
#include<bitset>
#include<numeric>
#include<unordered_set>
using namespace std;
const long long mod=1000000007;
const long long inf=mod*mod;
const long long d2=(mod+1)/2;
const double EPS=1e-10;
const double INF=1e+10;
const double PI=acos(-1.0);
const int C_SIZE = 3121000;
namespace{
	long long fact[C_SIZE];
	long long finv[C_SIZE];
	long long inv[C_SIZE];
	long long Comb(int a,int b){
	 	if(a<b||b<0)return 0;
	 	return fact[a]*finv[b]%mod*finv[a-b]%mod;
	}
	void init_C(int n){
		fact[0]=finv[0]=inv[1]=1;
		for(int i=2;i<n;i++){
			inv[i]=(mod-(mod/i)*inv[mod%i]%mod)%mod;
		}
		for(int i=1;i<n;i++){
			fact[i]=fact[i-1]*i%mod;
			finv[i]=finv[i-1]*inv[i]%mod;
		}
	}
	long long pw(long long a,long long b){
		if(a<0LL)return 0;
		if(b<0LL)return 0;
		long long ret=1;
		while(b){
			if(b%2)ret=ret*a%mod;
			a=a*a%mod;
			b/=2;
		}
		return ret;
	}
	int ABS(int a){return max(a,-a);}
	long long ABS(long long a){return max(a,-a);}
	double ABS(double a){return max(a,-a);}
	int sig(double r) { return (r < -EPS) ? -1 : (r > +EPS) ? +1 : 0; }
}
// ここから編集しろ
int UF[710000];
int FIND(int a){
	if(UF[a]<0)return a;return UF[a]=FIND(UF[a]);
}
void UNION(int a,int b){
	a=FIND(a);b=FIND(b);if(a==b)return;UF[a]+=UF[b];UF[b]=a;
}
int gcd(int a,int b){while(a){b%=a;swap(a,b);}return b;}
int lcm(int a,int b){return a/gcd(a,b)*b;}
int p[110000];
int main(){
	long long a;
	int b,c;scanf("%lld%d%d",&a,&b,&c);
	for(int i=0;i<c;i++){
		int t;scanf("%d",&t);
		p[t]=1;
	}
	for(int i=0;i<710000;i++)UF[i]=-1;
	int S=lcm(b,7);
	
	for(int i=0;i<S;i++){
		if(p[i%b])continue;
		if(i%7<6&&!p[(i+1)%b])UNION(i,i+1);
		if(i+7<S&&!p[(i+7)%b])UNION(i,i+7);
	}
	int sh=0;
	int sz=0;
	for(int i=0;i<S;i++)if(!p[i%b]&&UF[i]<0)sz++;
	set<pair<int,int > >s;
	for(int i=0;i<7;i++){
		if(p[i%b])continue;
		if(p[(S-7+i)%b])continue;
		s.insert(make_pair(FIND(i),FIND(S-7+i)));
	}
	sh=s.size();
	long long ret=sz+(long long)(sz-sh)*(a*7/S-1);
	printf("%lld\n",ret);
}



Measured memory_bytes: 3456
#include<iostream>
#include<algorithm>
#include<vector>
#include<string>
#include<map>
using namespace std;
#define int long long
#define inf 1000000007

int g[301][301];
int ng[301][301];

signed main() {
	int n;
		cin >> n;
		for (int i = 0; i < n; i++)
			for (int j = 0; j < n; j++) {
				cin >> g[i][j]; ng[i][j] = g[i][j];
			}

	for (int i = 0; i < n; i++)
		for (int k = 0; k < n; k++)
			for (int j = 0; j < n; j++)ng[j][k] = min(ng[j][k], ng[j][i] + ng[i][k]);

	int dif = 0;
	for (int i = 0; i < n; i++) {
		for (int j = 0; j < n; j++) {
			if (ng[i][j] != g[i][j])dif++;
		}
	}
	if (dif) {
		cout << -1 << endl;
		return 0;
	}

	for (int i = 0; i < n; i++) {
		for (int j = 0; j < n; j++) {
			for (int k = 0; k < n; k++) {
				if (ng[j][k] == ng[j][i] + ng[i][k]) {
					if (ng[j][i] && ng[i][k]) {
						ng[j][k] = inf;
						ng[k][j] = inf;
					}
				}
			}
		}
	}
	int ans = 0;
	for (int i = 0; i < n; i++) {
		for (int j = 0; j < n; j++) {
			if (ng[i][j] != inf)ans += ng[i][j];
		}
	}
	cout << ans/2 << endl;
}

Measured memory_bytes: 1664
#include <bits/stdc++.h>
#define rep(i,a,b) for(int i=int(a);i<int(b);++i)
#define SIZE 200005
#define INF 1000000005LL
#define MOD 1000000007

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

int N,c;
vector<int> C;

ll A[SIZE];

int main(){
  cin >> N;
  int t = 0;
  rep(i,0,N){
    cin >> c;
    if(t != c){
      C.push_back(c);
      t = c;
    }
  }

  ll ans = 1;

  for(auto u : C){
    //uより右の列で、uを使わない方法数
    ll tmp = ans;
    ans += A[u];
    ans %= MOD;
    A[u] += tmp;
    A[u] %= MOD;
  }
  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 2676
#include <iostream>
#include <iomanip>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <algorithm>
#include <cstdio>
#include <utility>
#include <string>
#include <cmath>
#include <cstdlib>
#include <cstring>

using namespace std;

typedef uint64_t u64;
typedef int64_t s64;
typedef uint32_t u32;
typedef int32_t s32;

const double PI=3.14159265358979323846;

#define MAX(x, y) ((x) < (y) ? (y) : (x))
#define MIN(x, y) ((x) > (y) ? (y) : (x))

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

#define CEIL(x, y) (((x) + (y) - 1) / (y))
#define MOD 1000000007ULL

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

    s64 A, B, C, K;
    cin >> A >> B >> C >> K;

    cout << ((K & 1) ? B - A : A - B) << "\n";
    return 0;
}



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

int main(int argc, char **argv)
{
    int N, K;
    std::cin >> N >> K;

    std::vector<int> l(N);
        
    for(int i = 0; i < N; i++){
        std::cin >> l.at(i);
    }

    std::sort(l.begin(), l.end(), std::greater<int>());

    int sum = 0;
    for(int i = 0; i < K; i++){
        sum += l.at(i);
    }

    std::cout << sum << std::endl;
    
}


Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<cstdio>
#include<vector>
#include<cmath>
#include<algorithm>
#include<functional>
#include<iomanip>
#include<queue>
#include<ciso646>
#include<random>
#include<map>
#include<set>
#include<complex>
#include<bitset>
#include<stack>
#include<unordered_map>
#include<utility>
using namespace std;
typedef long long ll;
typedef unsigned int ui;
const ll mod = 1000000007;
const ll INF = (ll)1000000007 * 1000000007;
typedef pair<int, int> P;
#define stop char nyaa;cin>>nyaa;
#define rep(i,n) for(int i=0;i<n;i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define per1(i,n) for(int i=n;i>=1;i--)
#define Rep1(i,sta,n) for(int i=sta;i<=n;i++)
//#define revstr(s) reverse(s.begin(),s.end())
typedef long double ld;
typedef complex<ld> Point;
const ld eps = 1e-8;
const ld pi = acos(-1.0);
typedef pair<ll, ll> LP;
typedef pair<ld, ld> LDP;
typedef unsigned long long ul;


int main() {
	int n; cin >> n;
	int a[1 << 17];
	rep(i, n)cin >> a[i];
	bool exi = false;
	rep(i, n)if (a[i] % 2)exi = true;
	if (!exi)cout << "second" << endl;
	else cout << "first" << endl;
	return 0;
}

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

int bubbleSort(int A[], int N)
{
  int sw = 0;
  bool flag = 1;
  for (int i = 0; flag; i++)
  {
    flag = 0;
    for (int j = N - 1; j >= i + 1; j--)
    {
      if (A[j] < A[j - 1])
      {
        swap(A[j], A[j - 1]);
        flag = 1;
        sw++;
      }
    }
  }
  return sw;
}

int main()
{
  int A[100], N, sw;
  cin >> N;
  for (int i = 0; i < N; i++)
    cin >> A[i];

  sw = bubbleSort(A, N);

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


Measured memory_bytes: 3104
#
# 　　  ⋀_⋀　 
#　　  (･ω･)  
# .／ Ｕ ∽ Ｕ＼
#  │＊　合　＊│
#  │＊　格　＊│ 
#  │＊　祈　＊│ 
#  │＊　願　＊│ 
#  │＊　　　＊│ 
#      ￣
#
import sys
sys.setrecursionlimit(10**6)
input=sys.stdin.readline
from math import floor,ceil,sqrt,factorial,log #log2ないｙｐ
from heapq import heappop, heappush, heappushpop
from collections import Counter,defaultdict,deque
from itertools import accumulate,permutations,combinations,product,combinations_with_replacement
from bisect import bisect_left,bisect_right
from copy import deepcopy
inf=float('inf')
mod = 10**9+7
def pprint(*A): 
    for a in A:     print(*a,sep='\n')
def INT_(n): return int(n)-1
def MI(): return map(int,input().split())
def MF(): return map(float, input().split())
def MI_(): return map(INT_,input().split())
def LI(): return list(MI())
def LI_(): return [int(x) - 1 for x in input().split()]
def LF(): return list(MF())
def LIN(n:int): return [I() for _ in range(n)]
def LLIN(n: int): return [LI() for _ in range(n)]
def LLIN_(n: int): return [LI_() for _ in range(n)]
def LLI(): return [list(map(int, l.split() )) for l in input()]
def I(): return int(input())
def F(): return float(input())
def ST(): return input().replace('\n', '')
def main():
    A,B = MI()
    S=ST()
    for i,s in enumerate(S):
        ok = True
        if i < A:
            if s=="-":
                ok = False
        elif i==A:
            if s!="-":
                ok = False
        else:
            if s=="-":
                ok = False
        if not ok:
            print("No")
            exit()
    print("Yes")
if __name__ == '__main__':
    main()

Measured memory_bytes: 38384
from collections import defaultdict

n = int(input())
a = list(map(int, input().split()))
d = defaultdict(int)
if True:
    for i in a[1:]:
      d[i] += 1
    now1,now2 = a[0],0
    for i in a[1:]:
      xor = now1^i
      d[i] -= 1
      d[xor] -= 1
      if d[xor] >= 0:
        now1, now2 = i, xor
        break
      d[i] += 1
      d[xor] += 1        
    else:
      print("No")
      exit()
    for i in range(n-3):
      xor = now1^now2
      d[xor] -= 1
      if d[xor] >= 0:
        now1, now2 = now2, xor
      else:
        print("No")
        exit()
    else:
      if now1^now2 == a[0]:
        print("Yes")
      else:
        print("No")
      exit()


Measured memory_bytes: 17312
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define INF 2e9
#define ALL(v) v.begin(), v.end()
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef vector<string> vs;
int main()
{
    ios::sync_with_stdio(false);
    cin.tie(nullptr);


    string s;
    cin >> s;

    string ans;

    ans = "Yes";
    REP(i, s.size())
    {
        if(i % 2 == 0)
        {
            if(s[i] != 'R' && s[i] != 'U' && s[i] != 'D' )
            {
                ans = "No";
                break;
            }
        }else
        {
            if(s[i] != 'L' && s[i] != 'U' && s[i] != 'D' )
            {
                ans = "No";
                break;
            }
        }
    }

    cout << ans << endl;
    
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#define REP(i,k,n) for(int(i)=(k);(i)<(n);++(i))
using namespace std;

const int N_MAX = int(2e5);
const int INF = int(1e9);
int N;
// int a[N_MAX];
// a の逆像
vector<int> b[N_MAX];

int search(int i, int cnt)
{
  // ループの場合、
  // この判定で良いか？
  if (cnt > N) return INF;

  if (i == 1) return cnt;
  // minimum
  int m = INF;
  REP(j,0, b[i].size()) {
    int k = search(b[i][j], cnt + 1);
    if (k > 0 && k < m) m = k;
  }
  // if (m == INF) return -1;
  // ここで m が INF もあり得る
  return m;

}

int main()
{
  cin >> N;
  // REP(i,1,N+1) cin >> a[i];

  // 遡るために、逆に記憶する
  REP(i,1,N+1) {
    int k;
    cin >> k;
    // k から i に遡ることができる。
    b[k].push_back(i);
  }

  int res = search(2,0);
  if (res < INF) cout << res << endl;
  // INF を -1 に
  else cout << -1 << endl;

  return 0;
}


Measured memory_bytes: 12800
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define INF 100
int main(){
  int dst[4][4];
  int a,b;

  for(int i = 0; i < 4; i++) {
    for(int j = 0; j < 4; j++) {
      dst[i][j] = INF;
      if(i == j) dst[i][j] = 0;
    }
  }
  for(int i = 0; i < 3; i++) {
    cin >> a >> b;
    a--;
    b--;
    dst[a][b] = 1;
    dst[b][a] = 1;
  }
  for(int k = 0; k < 4; k++) {
    for(int i = 0; i < 4; i++) {
      for(int j = 0; j < 4; j++) {
        if(dst[i][j] > dst[i][k] + dst[k][j]){
          dst[i][j] = dst[i][k] + dst[k][j];
        }
      }
    }
  }
  for(int i = 0; i < 4; i++) {
    for(int j = 0; j < 4; j++) {
      if(dst[i][j] == 3){
        cout << "YES" << endl;
        return 0;
      }
    }
  }
  cout << "NO" <<endl;
  return 0;
}

Measured memory_bytes: 256
#include <stdio.h>

int main(void) {
  int count = 0,pool,n,A[100];

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

  int flag = 1;
  while (flag) {
    flag = 0;
    for (int j = n-1; j > 0; j--) {
      if (A[j] < A[j-1]) {
        pool = A[j];
        A[j] = A[j-1];
        A[j-1] = pool;
        count++;
        flag = 1;
      }
    }
  }

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



Measured memory_bytes: 2116
#include<bits/stdc++.h>
using namespace std;
using ll = long long int;
const int mod=1e9+7;
ll n,k;
class M {
    public:
    vector <vector <int> > v;
    M() {
        v = vector <vector <int> >(n,vector <int>(n,0));
    }
    M operator*(M const &M2) {
        M tmp;
        for(int i=0;i<n;i++)
        {
            for(int j=0;j<n;j++)
            {
                tmp.v[i][j]=0;
                for(int k=0;k<n;k++)
                    tmp.v[i][j] = (tmp.v[i][j]+1LL*v[i][k]*M2.v[k][j])%mod;
            }
        }
        return tmp;
    }
};
int main()
{
//    cin>>n;
//    M a;
//    for(int i=0;i<n;i++)
//        for(int j=0;j<n;j++)
//        cin>>a.v[i][j];
//    M b;
//    for(int i=0;i<n;i++)
//        for(int j=0;j<n;j++)
//        cin>>b.v[i][j];
//    a = a*b;
//    for(int i=0;i<n;i++)
//    for(int j=0;j<n;j++)
//        cout<<a.v[i][j]<<" \n"[j==n-1];
    cin>>n>>k;
    vector <vector<int> > mat(n,vector<int>(n,0));
    for(int i=0;i<n;i++)
    {
        for(int j=0;j<n;j++)
            cin>>mat[i][j];
    }
    M x;
    x.v = mat;
    M res;
    for(int i=0;i<n;i++)
        res.v[i][i] = 1;
    while(k)
    {
        if(k&1)
            res = res*x;
        k>>=1;
        x = x*x;
    }
    ll ans = 0;
    for(int i=0;i<n;i++)
    {
        for(int j=0;j<n;j++)
            ans = (ans+res.v[i][j])%mod;
    }
    cout<<ans<<endl;
}
//2
//1 2
//3 4
//2 0
//1 2


Measured memory_bytes: 256
/**
 * code generated by JHelper
 * More info: https://github.com/AlexeyDmitriev/JHelper
 * @author tatsumack
 */

#include <iostream>
#include <fstream>

#include <iostream>
#include <limits.h>
#include <algorithm>
#include <bitset>
#include <cctype>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <functional>
#include <iomanip>

#include <list>
#include <map>
#include <numeric>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>
#include <queue>
#include <unordered_map>
#include <unordered_set>

#define int long long
#define REP(i, n) for (int i = 0, i##_len = (n); i < i##_len; ++i)
#define REPS(i, n) for (int i = 1, i##_len = (n); i <= i##_len; ++i)
#define FOR(i, a, b) for (int i = (a), i##_len = (b); i <= i##_len; ++i)
#define REV(i, a, b) for (int i = (a); i >= (b); --i)
#define CLR(a, b) memset((a), (b), sizeof(a))
#define DUMP(x) cout << #x << " = " << (x) << endl;
#define INF 1001001001001001001ll
#define fcout cout << fixed << setprecision(12)

using namespace std;

typedef pair<int, int> P;

class DPairCards {
public:
    static constexpr int kStressIterations = 0;

    static void generateTest(std::ostream& test) {
    }

    void solve(std::istream& cin, std::ostream& cout) {
        int N, M;
        cin >> N >> M;

        vector<int> X(N);
        REP(i, N) cin >> X[i];
        sort(X.begin(), X.end());

        vector<vector<int>> d(M);
        REP(i, N) {
            d[X[i] % M].push_back(X[i]);
        }

        int res = 0;
        for (int i = 0; i <= M / 2; i++) {
            auto& l = d[i];
            auto& r = d[M - i];

            if (i == 0 || i + i == M) {
                res += l.size() / 2;
                continue;
            }

            if (l.size() < r.size()) {
                swap(l, r);
            }

            int cur = l.size();
            int prev = -1;
            sort(l.begin(), l.end());
            REP(j, l.size()) {
                if (cur <= r.size() + 1) break;
                if (l[j] == prev) {
                    res += 1;
                    cur -= 2;
                    prev = -1;
                    continue;
                }
                prev = l[j];
            }
            res += r.size();
        }
        cout << res << endl;
    }
};


signed main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);
    std::istream& in(std::cin);
    std::ostream& out(std::cout);

    DPairCards solver;
    solver.solve(in, out);
    return 0;
}


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

typedef long long ll;
#define int ll
#define fi first
#define se second
#define SORT(a) sort(a.begin(),a.end())
#define REP(i,n) for (int i = 0;i < (n) ; i++) 
#define MP(a,b) make_pair(a,b)
#define pb(a) push_back(a)

using namespace std;

signed main(){
    
    int n,m;
    cin >> n >> m;

    set<int> s;
    for(int i = 1; i*i <= m ;i++){
        if(m%i == 0){
            s.insert(i);
            s.insert(m/i);
        }
    }
    
    for(auto i:s){
        if(m % i == 0 && i >= n){
            cout << m/i << endl;
            break;
        }
    }

    return 0;
}

Measured memory_bytes: 256
#[allow(unused_macros)]
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

#[allow(unused_macros)]
macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

    ($next:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
}

#[allow(unused_macros)]
macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };

    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };

    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
    };

    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}

#[allow(unused_macros)]
macro_rules! debug {
    ($($a:expr),*) => {
        #[cfg(debug_assertions)]
        writeln!(&mut std::io::stderr(), concat!("[DEBUG] ", $(stringify!($a), "={:?} "),*), $($a),*);
    }
}

#[allow(unused_imports)]
use std::cmp::{min, max};

#[allow(unused_imports)]
use std::io::Write;

fn solve(mut s: Vec<char>, c: char) -> usize {
    let mut cnt = 0;
    loop {
        let ok = s.iter().fold(true, |acc, ci| acc && *ci == c);
        if ok {
            // debug!(c, cnt, s);
            return cnt;
        }
        cnt += 1;

        for i in 0..s.len()-1 {
            if s[i+1] == c {
                s[i] = c;
            }
        }
        s.pop();
    }
}

fn main() {
    input!{
      s: String
    }
    let mut ans = 101;
    let s: Vec<char> = s.chars().collect();
    for &c in s.iter() {
        ans = min(ans, solve(s.clone(), c));
    }
    println!("{}", ans);
}


Measured memory_bytes: 4352
#include <bits/stdc++.h>
#define be(v) (v).begin(),(v).end()
#define pb(q) push_back(q)
typedef long long ll;
using namespace std;
const ll mod=1000000007;
#define doublecout(a) cout<<fixed<<setprecision(10)<<a<<endl;

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    string s;
    cin>>s;
    string t;
    bool maki=false;
    for(int i=0;i<16;i++){
    	t="";
    	if(i&1)t+='A';
    	t+="KIH";
    	if(i&2)t+='A';
    	t+='B';
    	if(i&4)t+='A';
    	t+='R';
    	if(i&8)t+='A';
    	if(t==s)maki=true;
    }
    cout<<((maki)?"YES":"NO")<<endl;
    return 0;
}


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

using ll = long long;
using ull = unsigned long long;
using st = string;
using ch = char;
using db = double;
using bl = bool;
using vll = vector<long long>;
using vdb = vector<db>;
using vvll = vector<vll>;
using vst = vector<st>;
using vch = vector<char>;
using pll = pair<ll, ll>;
using vpll = vector<pll>;
using vvpll = vector<vpll>;
#define rep(i, m, n) for (ll i = (ll)(m); i < (ll)(n); i++)
#define vrep(i, vec) for(auto& i : vec)
#define vin(vec) for(auto& i : vec) cin >> i
#define all(v) v.begin(), v.end()
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;}
const ll mod = 1000000007;
const ll inf = 1LL << 60;
const db pi = acos(-1.0L);

int main(){
  ll k, a, b;
  cin >> k >> a >> b;
  cout << ((a - 1) / k < b / k ? "OK" : "NG") << endl;
}

Measured memory_bytes: 3632
#include <bits/stdc++.h>
 #include <string> 
 #include <math.h>
 #include <bitset>
 #include <numeric>
 #include <stdio.h>
 #include <algorithm>

 using namespace std;

 int main(){
    string S;
    int S_size;
    cin >> S;
    S_size = S.size();
   
    if(S[S_size-1]=='s')
        cout << S << "es" << endl;
    else
        cout << S << 's' << endl;

    return 0;
 }
 



Measured memory_bytes: 3620
N,W = map(int,input().split())
w_v = [list(map(int,input().split())) for _ in range(N)]
dp = [[0]*W for _ in range(N)]

for i in range(0,N):
  if i == 0:
    if W>=w_v[0][0]:
      for j in range(w_v[0][0]-1,W):
        dp[i][j] = w_v[0][1]
  else:
    for j in range(W):
      if j-w_v[i][0]>=0:
        dp[i][j] = max(dp[i-1][j],dp[i-1][j-w_v[i][0]]+w_v[i][1])
      else:
        dp[i][j] = dp[i-1][j]

print(max(dp[-1]))

Measured memory_bytes: 119660
/*
 * Note: This template uses some c++11 functions , so you have to compile it with c++11 flag.
 *       Example:-   $ g++ -std=c++11 c++Template.cpp
 *
 * Author : Denzil Bernard  / Edgar Monis
 * Handle: 1_mn_RMY / the_king_in_the_north
 *
 */

// C
#ifndef _GLIBCXX_NO_ASSERT
#include <cassert>
#endif
#include <cctype>
#include <cerrno>
#include <cfloat>
#include <ciso646>
#include <climits>
#include <clocale>
#include <cmath>
#include <csetjmp>
#include <csignal>
#include <cstdarg>
#include <cstddef>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>

#if __cplusplus >= 201103L
#include <ccomplex>
#include <cfenv>
#include <cinttypes>
//#include <cstdalign>
#include <cstdbool>
#include <cstdint>
#include <ctgmath>
#include <cwchar>
#include <cwctype>
#endif

// C++
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>

#if __cplusplus >= 201103L
#include <array>
#include <atomic>
#include <chrono>
#include <condition_variable>
#include <forward_list>
#include <future>
#include <initializer_list>
#include <mutex>
#include <random>
#include <ratio>
#include <regex>
#include <scoped_allocator>
#include <system_error>
#include <thread>
#include <tuple>
#include <typeindex>
#include <type_traits>
#include <unordered_map>
#include <unordered_set>
#endif

using namespace std;

/*******  All Required define Pre-Processors and typedef Constants *******/
#define FOR(i, j, k, in) for (int i=j ; i<k ; i+=in)
#define RFOR(i, j, k, in) for (int i=j ; i>=k ; i-=in)
#define REP(i, j) FOR(i, 0, j, 1)
#define RREP(i, j) RFOR(i, j, 0, 1)
#define all(cont) cont.begin(), cont.end()
#define rall(cont) cont.end(), cont.begin()
#define FOREACH(it, l) for (auto it = l.begin(); it != l.end(); it++)
#define IN(A, B, C) assert( B <= A && A <= C)
#define MP make_pair
#define PB push_back
#define MOD 1000000007
#define read(type) readInt<type>()
#define ll long long
typedef pair< ll, ll> PII;
typedef vector<ll> VI;
typedef vector<PII> VII;
typedef vector<VI> VVI;
typedef map<ll,ll> MPII;
typedef set<ll> SETI;
typedef multiset<ll> MSETI;

ll SI(){
    ll x;
    cin>>x;
    return x;
}


ll mod(ll a){
	return a<0?-a:a;
}


/********** Main()  function **********/
int main()
{
    ll t = SI();
    ll x = 0;
    while(t--){
        x^=SI();
    }
    if(x==0){
    	cout<<"Yes\n";
    }
    else{
    	cout<<"No\n";	
    }
    
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int n,s1,s2,s3,a[303];
double f[303][303][303];
int main()
{
	cin>>n;
	for(int i=0;i<n;i++)
	{
		cin>>a[i];
		if(a[i]==1)
			s1++;
		if(a[i]==2)
			s2++;
		if(a[i]==3)
			s3++;
	}
	f[0][0][0]=0;
	for(int i=0;i<=n;i++)
	{
		for(int j=0;j<=n;j++)
		{
			for(int k=0;k<=n;k++)
			{
				if(i)
					f[i][j][k]+=(f[i-1][j+1][k])*i/(i+j+k);
				if(j)
					f[i][j][k]+=(f[i][j-1][k+1])*j/(i+j+k);
				if(k)
					f[i][j][k]+=(f[i][j][k-1])*k/(i+j+k);
				if(i || j || k)
					f[i][j][k]+=(double)n/(i+j+k);
			}
		}
	}
	cout<<fixed<<setprecision(14)<<f[s3][s2][s1]<<endl;
	return 0;
}

Measured memory_bytes: 217344
#include<bits/stdc++.h>
#define ll long long
#define rep(i, n) for(int i=0; i<n; i++)
#define REP(i, n) for(int i=0; i<=n; i++)
#define repr(i, n) for(int i=n; i>0; i--)
#define REPR(i, n) for(int i=n; i>=0; i--)
const ll INF = 1LL<<60;
const int INT_INF = 1e9;
const ll MOD = 1e9+7;
template<class T> void puts(T x) { std::cout << x << std::endl; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
using namespace std;

int a, b, c, x, y;

int main() {
    cin >> a >> b >> c >> x >> y;
    int ans = INT_INF;
    // ABピザをi枚買う
    for (int i = 0; i <= 2 * max(x, y); i++) {
        int tmp = 2 * c * i + a * max(0, x - i) + b * max(0, y - i);
        if (tmp < ans) ans = tmp;
    }
    cout << ans << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <math.h>
using namespace std;
typedef long long ll;
typedef long double ld;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
const ll mod = 1000000007;
const ll INF = 1001001001;
const ll LINF = 1001001001001001001;

void prvec(vector<ll> vec){
    ll n = vec.size();
    rep(i,n) cout << "i" << " " << vec.at(i) << "\n";
}

void pr2d(vector<vector<ll>> vvec){
    ll h = vvec.size();
    ll w = vvec.at(0).size();
    rep(i,h){
        rep(j,w){
            cout << vvec.at(i).at(j) << " ";
        }
        cout << "\n";
    }
}

int main(){
    ll n ; cin >> n;
    ll prev ; cin >> prev;
    bool NG = false;
    if(prev!=0) NG = true;
    ll ans = 0;
    rep(i,n-1){
        ll x ; cin >> x;
        if(x == prev + 1){
            ans++;
        }else if(x>prev+1){
            NG = true;
        }else{
            ans+=x;
        }
        prev = x;
    }
    if(NG){
        cout << -1 << endl;
    }else{
        cout << ans << endl;
    }
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ll long long
#define pb push_back
#define mod 1000000007
#define ff first
#define ss second
using namespace std;
/*ll power(ll x,ll y)
{
    ll res=1;
    while(y>0)
    {
        if(y%2==1)
            res=(res*x)%mod;
        x=(x*x)%mod;
        y=y/2;
    }
    return res;
}*/
int main()
{
ll a;
string s;
cin>>a;
cin>>s;
if(a>=3200)
    cout<<s;
else
    cout<<"red"<<endl;
}













































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































Measured memory_bytes: 256
N = int(input())
H = list(map(int, input().split()))

for i in range(len(H)-1, 0, -1):
    if H[i-1] == H[i] + 1:
        H[i-1] -= 1
    elif H[i-1] > H[i]:
        print('No')
        break
else:
    print('Yes')


Measured memory_bytes: 14224
#include <iostream>
#include <iomanip>
#include <cstring>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <algorithm>
#include <queue>
#include <deque>
#include <time.h>
#define int long long
using namespace std;
int n,m,c,sum,ans;
int b[110],a[110][110];
signed main()
{
	scanf("%lld%lld%lld",&n,&m,&c);
	for(int i=1;i<=m;i++)
	{
		scanf("%lld",&b[i]);
	}
	for(int i=1;i<=n;i++)
	{
		sum=0;
		for(int j=1;j<=m;j++)
		{
			scanf("%lld",&a[i][j]);
			sum+=a[i][j]*b[j];
		}
		sum+=c;
		if(sum>0)
			ans++;
	}
	printf("%lld",ans);
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define maxn 200005
using namespace std;
inline int read(){
	int x=0,f=1;char c=getchar();
	while(c<'0'||c>'9'){
		if(c=='-') f=-1;
		c=getchar();
	}
	while(c>='0'&&c<='9'){
		x=x*10+c-'0';
		c=getchar();
	}
	return x*f;
}
int n,a[maxn],f[maxn];
int main(){
	n=read();
	for(int i=1;i<=n;i++) a[i]=read();
	for(int i=1;i<=n;i++){
		f[a[i]]=f[a[i]-1]+1;//求最长连续子序列 
	}
	int ans=0;
	for(int i=1;i<=n;i++) if(f[i]>ans) ans=f[i];
	printf("%d",n-ans);
	
	return 0;
}

Measured memory_bytes: 1792
#include<iostream>
#include<vector>
#include<cstring>
#include<algorithm>
#include<cmath>
#include<queue>
#include<deque>
#include<map>
#include<bitset>

using namespace std;
using ll = long long;

#define rep(i, n) for(int i = 0;i < (n);i++)
#define repr(i, n) for(int i = (n);i >= 0;i--)
#define repf(i, m, n) for(int i = (m);i < (n);i++)

template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1;} return 0;}
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1;} return 0;}
int dx[] = {0, 1, 0, -1}, dy[] = {1, 0, -1, 0};
//////////////////////////////////////////////////

int n, K;
int a[110];
bool memo[100010];

bool rec(int k) {
    if (memo[k])
        return memo[k];
    bool wins = false;
    rep(i, n) {
        if (a[i] && k >= a[i]) {
            wins |= !rec(k - a[i]);
        }
    }
    memo[k] = wins;
    return wins;
}

int main() {
    cin >> n >> K;
    rep(i, n) cin >> a[i];
    cout << (rec(K) ? "First" : "Second") << endl;
    return 0;
}


Measured memory_bytes: 4992
#include<cstring>
#include<iostream>
using namespace std;
// KIH B R {...}
//AKIHABARA{...}
string a="AKIHABARA";
string b="AKIHABAR";
string c="AKIHABR";
string d="AKIHBR";
string e="AKIHBR";
string f="KIHABARA";
string g="KIHBARA";
string h="KIHBRA";
string i="KIHABAR";
string j="KIHBAR";
string k="KIHABR";
string l="KIHBR";
int main()
{
	string st="";
	cin>>st;
	if(st==a){printf("YES");return 0;}
	if(st==b){printf("YES");return 0;}
	if(st==c){printf("YES");return 0;}
	if(st==d){printf("YES");return 0;}
	if(st==e){printf("YES");return 0;}
	if(st==f){printf("YES");return 0;}
	if(st==g){printf("YES");return 0;}
	if(st==h){printf("YES");return 0;}
	if(st==i){printf("YES");return 0;}
	if(st==j){printf("YES");return 0;}
	if(st==k){printf("YES");return 0;}
	if(st==l){printf("YES");return 0;}
	printf("NO");
	return 0;
}

Measured memory_bytes: 256
# -*- coding: utf-8 -*-


def main():
    """Function."""
    n = int(input())
    k = int(input())
    x = int(input())
    y = int(input())

    if n > k:
        print(x*k+y*(n-k))
    else:
        print(x*n)


if __name__ == "__main__":
    main()


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

using namespace std;

#define range(i, m, n) for(int i = m; i < n; i++)
#define husk(i, m, n) for(int i = m; i > n; i--)

long long a, b, c, k;

int main() {
  cin >> a >> b >> c >> k;
  k &= 1;
  if(k) {
    a = -a;
    b = -b;
  }
  cout << a - b;
  return 0;
}


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

using namespace std;

typedef long long ll;

int main(){
  ll N,M; cin >> N >> M;
  vector<ll> x(N); vector<ll>y(N);  vector<ll> z(N);
  
  for(ll i = 0; i < N; i++){ cin >> x[i] >> y[i] >> z[i];}
  
  vector<vector<ll>> sum(8,vector<ll>(N));

  for(ll  i = 0; i < 8; i++){
    for(ll j = 0; j < N; j++){
    if(i >> 0 & 1){ sum[i][j] += x[j];}
      else{ sum[i][j] -= x[j];}
    if(i >> 1 & 1){ sum[i][j] += y[j];}
      else{ sum[i][j] -= y[j];}
    if(i >> 2 & 1){ sum[i][j] += z[j];}
      else{ sum[i][j] -= z[j];} } }
  
  ll max_sum = 0;
  
  for(ll i = 0; i < 8; i++){
    sort(sum[i].begin(),sum[i].end()); reverse(sum[i].begin(),sum[i].end());
    ll summary = 0;
    for(ll j = 0; j < M; j++){
      summary += sum[i][j];}
    max_sum = max(max_sum,summary);}
    
                    
                         cout << max_sum << endl; return 0;}


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

typedef unsigned long long ull;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<double, double> pdd;
const ull mod = 1e9 + 7;
#define REP(i,n) for(int i=0;i<(int)n;++i)

int main(){
	int A, B, C, D, E, F;
	cin >> A >> B >> C >> D >> E >> F;
	vector<int> water, sugar;
	REP(a, 30)REP(b, 30){
		int w = 100*A*a+100*B*b;
		if (w<=F) water.push_back(w);
	}
	REP(c, 3000)REP(d, 3000){
		int s = C*c+D*d;
		if (s<=F) sugar.push_back(s);
	}
	sort(sugar.begin(), sugar.end());

	double res = -1;
	int res_sw, res_s;
	REP(i, water.size()){
		int w = water[i];
		int tmp = min(w*E/100, F-w);
		int l = -1;
		int u = sugar.size();

		while(u-l > 1){
			int m = (l+u)/2;
			if(sugar[m]<=tmp){
				l = m;
			}else{
				u = m;
			}
		}
		int place = u-1;
		if (place!=-1){
			int max_sugar = sugar[place];
			if(res < (double)max_sugar/(w+max_sugar)){
				res_sw = max_sugar + w;
				res_s = max_sugar;
				res = (double)max_sugar/(w+max_sugar);
			}
		}
	}
	cout << res_sw << " " << res_s << endl; 
    return 0;
}

Measured memory_bytes: 1400
/**
 * Mob Pro
 * 20200120
 **/
#include<iostream>
#include<vector>
#include<algorithm>

using namespace std;

int main() {
    int n; cin >> n;
    vector<int> h(n);
    for(int i=0; i<n; i++) cin >> h[i];
    reverse(h.begin(), h.end());
    for(int i=0; i<n-1; i++) {
        if(h[i] < h[i+1]) {
            h[i+1] -= 1; 
        }
        if(h[i]<h[i+1]) {
            cout << "No" << endl;
            return 0;
        }
    }
    cout << "Yes" << endl;
    return 0;
}

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

int main(){
    int N,X;
    cin >> N >> X;

    int m[110000];
    for(int i = 0; i < N; i++) {
        cin >> m[i];
    }

    int count = N; //initial value

   std::sort(m, m+N);

    for(int i = 0; i< N; i++) {
       X = X - m[i];
    }

    while (X >= m[0]) {
        X = X - m[0];
        count++;
    }
    
    cout << count << endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <vector>
#define ll long long
using namespace std;

int main() {
  	ll x, k, d;
  	cin >> x >> k >> d;
  	ll c = min(1LL*(abs(x) / d), k);
  	if(x > 0)
  		x -= c*d;
  	else
  		x += c*d;
  	k -= c;
  	if(k == 0) {
  		cout << abs(x);
  		return 0;
  	}
  	if(x < 0) {
  		if((k & 1) == 0)
  			cout << min(abs(x), x + 2*d);
  		else
  			cout << min(x+d, abs(x - d));
  	}
  	else if(x > 0) {
  		if((k & 1) == 0)
  			cout << min(x, abs(x - 2*d));
  		else
  			cout << min(x + d, abs(x - d));
  	}
  	else {
  		if((k & 1) == 0)
  			cout << x;
  		else
  			cout << min(x+d, abs(x-d));
  	}
	return 0;
}


Measured memory_bytes: 3620
using namespace std;
#include <iostream>
//#include <algorithm>
//#include <string>
//#include <vector>
#include <deque>

int main()
{
	int q;
	deque <int> deq;
	int a0, a1, a2;

	cin >> q;
	for (int i = 0; i < q; i++) {
		cin >> a0 >> a1;

		switch (a0) {
		case 0:
			cin >> a2;
			if (a1 == 0)
				deq.push_front(a2);
			else if (a1 == 1)
				deq.push_back(a2);
			break;

		case 1:
			cout << deq[a1] << endl;
			break;

		case 2:
			if (a1 == 0)
				deq.pop_front();
			else if (a1 == 1)
				deq.pop_back();
			break;
		}
	}
}



Measured memory_bytes: 4684
function count(x,y){
   if(xy[x][y]==-1)return;
   var dx=[0,-1];
   var dy=[-1,0];
   var sum=0;
   for(var i=0;i<2;i++){
      var xx=x+dx[i];
      var yy=y+dy[i];
      if(xx<0 || yy<0 || xy[xx][yy]==-1)continue;
      sum+=xy[xx][yy];
   }
   xy[x][y]=sum;
}
var input = require('fs').readFileSync('/dev/stdin', 'utf8');
var Arr=(input.trim()).split("\n");
while(true){
   var ab=Arr.shift();
   if(ab=="0 0")break;
   ab=ab.split(" ").map(Number);
   var a=ab[0];
   var b=ab[1];
   var n=Arr.shift()-0;
   var xy=[];
   for(var i=0;i<a;i++){
      xy[i]=[];
      for(var j=0;j<b;j++){
         xy[i][j]=0;
      }
   }
   xy[0][0]=1;
   for(var i=0;i<n;i++){
      var ab=(Arr.shift()).split(" ").map(Number);
      xy[ab[0]-1][ab[1]-1]=-1;
   }
   for(var i=0;i<a;i++){
      for(var j=0;j<b;j++){
         if(i==0 && j==0)continue;
         count(i,j);
      }
   }
   console.log(xy[a-1][b-1]);
}

Measured memory_bytes: 8696
import sys
sys.setrecursionlimit(2147483647)
INF=float("inf")
MOD=10**9+7
input=lambda :sys.stdin.readline().rstrip()
def resolve():
    n,W=map(int,input().split())
    WV=[tuple(map(int,input().split())) for _ in range(n)]

    V=100000
    dp=[INF]*(V+1)
    dp[0]=0

    for w,v in WV:
        for x in range(V,-1,-1):
            if(x+v<=V):
                dp[x+v]=min(dp[x+v],dp[x]+w)

    for x in range(V,-1,-1):
        if(dp[x]<=W):
            print(x)
            return
resolve()

Measured memory_bytes: 70988
n=int(input())
c=[int(input())for i in range(n)]
d=0
p=0
for i in range(n-1,0,-1):
    if c[i]-c[i-1]>1:
        print(-1)
        break
    else:
        if d!=c[i]:
            p+=c[i]
            d=c[i]
    d-=1
else:
    print(-1if c[0]>0else p)

Measured memory_bytes: 11052
import java.util.Scanner;

class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    long N=sc.nextLong();
    long Ts[]=new long[5];
    Ts[1]=sc.nextLong();
    Ts[0]=sc.nextLong();
    Ts[2]=sc.nextLong();
    Ts[3]=sc.nextLong();
    Ts[4]=sc.nextLong();

    long mi=Ts[0];
    for(int i=0;i<5;i++){
    if(Ts[i]<mi){mi=Ts[i];}
  }


    System.out.println((N + mi - 1)/mi+4);
  }
}


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

using namespace std;
typedef long long ll;
struct edge{
	int to, nxt;
}e[100005];
int h[100005], cnt; 
void addedge(int x, int y){
	cnt++; e[cnt].to = y; e[cnt].nxt = h[x]; h[x] = cnt;
	cnt++; e[cnt].to = x; e[cnt].nxt = h[y]; h[y] = cnt;
}
int dep[100005], mx[100005], m1;
void dfs(int x, int fa){
	dep[x] = dep[fa] + 1; m1 = max(m1, dep[x]);
	int ct = 0;
	for(int i = h[x]; i; i = e[i].nxt){
		if(e[i].to == fa) continue;
		ct ++;
		dfs(e[i].to, x);
	}
	mx[dep[x]] = max(mx[dep[x]], ct);
}

void dfs(int x, int cc, int fa){
	dep[x] = dep[fa] + 1; m1 = max(m1, dep[x]);
	int ct = 0;
	for(int i = h[x]; i; i = e[i].nxt){
		if(e[i].to == fa || e[i].to == cc) continue;
		ct ++;
		dfs(e[i].to, cc, x);
	}
	mx[dep[x]] = max(mx[dep[x]], ct);
}

int n;
int a1 = 9999999; ll ans;
int main(){
	scanf("%d", &n);
	for(int i = 1; i < n; i ++){
		int x, y; scanf("%d%d", &x, &y); addedge(x, y);
	}
	for(int i = 1; i <= n; i ++){
		m1 = 0; for(int k = 1; k <= n; k ++) mx[k] = 0;
		dfs(i, 0);
		ll res = 1;
		for(int k = 1; k < m1; k ++){
	//		printf("%d ", mx[k]);
			res = res * mx[k];
		}
	//	printf("\n");
		if(m1 < a1 || (m1 == a1 && res < ans)){
			a1 = m1; ans = res;
		}
	}
	for(int i = 1; i <= n; i ++){
		for(int j = h[i]; j; j = e[j].nxt){
			m1 = 0; for(int k = 1; k <= n; k ++) mx[k] = 0;
			dfs(i, e[j].to, 0);
			dfs(e[j].to, i, 0);
			ll res = 1;
			for(int k = 1; k < m1; k ++){
		//		printf("%d ", mx[k]);
				res = res * mx[k];
			}
		//	printf("case %d %d\n", i, e[j].to);
			res = res * 2;
			if(m1 < a1 || (m1 == a1 && res < ans)){
				a1 = m1; ans = res;
			}
		}
	}
	printf("%d %lld\n", a1, ans);
	
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main() {
    int a[3], k = 0, l = 0;
    for (int i = 0; i < 3; ++i)
    {
        cin >> a[i];
        if (a[i] == 5)
            k++;
        else if (a[i] == 7)
            l++;
    }
    if (k == 2 && l == 1)
        cout << "YES";
    else
        cout << "NO";
}

Measured memory_bytes: 3600
#include <bits/stdc++.h>
#include <string.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define FOR(i, m, n) for(int i = m; i < n; i++) 
typedef long long int ll;
int main(){
    int A,B,C;
    cin>>A>>B>>C;
    if((A==B&&A!=C)||(A==C&&A!=B)||(B==C&&B!=A)){
        cout<<"Yes"<<endl;
    }else{
        cout<<"No"<<endl;
    }


    return 0;
}

Measured memory_bytes: 256
s = input()
n = len(s)

ans = 0

for bit in range(1 << (n - 1)):
    # 各場合で式 f を生成する
    f = s[0]

    for i in range(n - 1):
        if bit & (1 << i):
            # フラグが立っているならば "+" を式の末尾に追加する
            f += "+"
        f += s[i + 1]

    ans += sum(map(int, f.split("+")))

print(ans)


Measured memory_bytes: 3060
#include<iostream>
#include<cmath>
#include<string>
#include<cctype>
#include<vector>
#include<algorithm>
using namespace std;
int main(){
        int a,b;
        scanf("%d %d",&a,&b);
        printf("%d %d\n",a*b,a*2+b*2);
        return 0;
}

Measured memory_bytes: 1172
#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for (int i = 0; i < (n); ++i)
#define FOR(i, n, m) for (int i = m; i < n; i++)
#define INF 1e9
#define ALL(v) v.begin(), v.end()

typedef long long ll;

/**
 * 不安なら ll を使う.
 * 小数は double を忘れない.
 * nC2の求め方 (1/2)*n*(n-1)
 * vector<型> 変数名(要素数, 初期値)
 * pair<型, 型> 変数名
 * map<型, 型> 変数名  // 連想配列
 * priority_queue<型> 変数名  // 最大値から出てくるヒープ
 * 比較するときは型まで注意
 * 区間の計算は累積和
*/

/* ===== コーナーケースに気をつけろ ===== */

int main()
{
    int N, M;
    cin >> N >> M;
    cout << N * (N - 1) / 2 + M * (M - 1) / 2 << endl;
    return 0;
}

Measured memory_bytes: 256
# でつoO(YOU PLAY WITH THE CARDS YOU'RE DEALT..)
import sys
def main(N, W, items):
    w1 = items[0][0]
    dp = [[[0] * (3 * N + 1) for _ in range(N + 1)] for __ in range(N + 1)]
    dp[0][0][0] = 0
    for i in range(N):
        iw, iv = items[i]
        iw -= w1
        for j in range(N + 1):
            for w in range(3 * N + 1):
                if j * w1 + w > W: break
                if w >= iw and j >= 1:
                    dp[i + 1][j][w] = max(dp[i][j][w], dp[i][j - 1][w - iw] + iv)
                else:
                    dp[i + 1][j][w] = dp[i][j][w]
    ans = 0
    for j in range(N + 1):
        for w in range(3 * N + 1):
            ans = max(ans, dp[N][j][w])
    print(ans)

if __name__ == '__main__':
    input = sys.stdin.readline
    N, W = map(int, input().split())
    items = [tuple(map(int, input().split())) for _ in range(N)]
    main(N, W, items)


Measured memory_bytes: 98864