akhauriyash/Code-Regression huggingface dataset:
// Problem : E - Red Scarf
// Contest : AtCoder - AtCoder Beginner Contest 171
// URL : https://atcoder.jp/contests/abc171/tasks/abc171_e
// Memory Limit : 1024 MB
// Time Limit : 2000 ms
// Powered by CP Editor (https://github.com/cpeditor/cpeditor)

//#pragma GCC optimize "trapv"//  WA to RE int!!
#include <bits/stdc++.h>
#define FOR(i,n) for(int i=0;i<n;i++)
#define FORR(i,n) for(int i=n;i>=0;i--)
#define pb push_back
#define vlli vector<int>
#define slli set<int>
#define mlli map<int,int>
#define int long long int 
#define test int tt1234; cin>>tt1234;while(tt1234--)
#define endl "\n"
#define all(zz) zz.begin(),zz.end()
#define rep(i, begin, end) for (__typeof(end) i = (begin) - ((begin) > (end)); i != (end) - ((begin) > (end)); i += 1 - 2 * ((begin) > (end)))
#define error(x) cerr << #x <<" is " << x << endl;
#define Error(a,b) cerr<<"( "<<#a<<" , "<<#b<<" ) = ( "<<(a)<<" , "<<(b)<<" )\n";
#define fast ios_base::sync_with_stdio(false);cin.tie(NULL);
#define fint fast;test
#define SI(a,n) int a[n];FOR(i,n) cin>>a[i];
#define input(a,n) int n;cin>>n; SI(a,n)
#define set(a,x) memset(a,x,sizeof(a))
#define L(x)	((x)<<1)
#define R(x)	(((x)<<1)+1)
#define ft first
#define se second
#define MOD 1000000007
using namespace std;

void solve(){
	input(arr,n);
	int T=0;
	FOR(i,n)T^=arr[i];
	FOR(i,n)cout<<(T^arr[i])<<" ";	
	return;	
}


int32_t main() {
    // fint{
    	fast;
    	solve();
    // }
    return 0;
}


Measured memory_bytes: 5052
#pragma GCC optimize(2)
#include <bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/hash_policy.hpp>
using namespace __gnu_pbds;
using namespace std;

int n;
string s[200010];
cc_hash_table<string,int> mp;

signed main()
{
	ios::sync_with_stdio(false);
	cin>>n;
	for(int i=1;i<=n;i++){
		cin>>s[i];
		mp[s[i]]++;
	}
	vector<pair<int,string> > v;
	for(cc_hash_table<string,int>::iterator it=mp.begin();it!=mp.end();it++){
		v.push_back(make_pair(it->second,it->first));
	}
	sort(v.begin(),v.end());
	reverse(v.begin(),v.end());
	for(int i=v.size()-1;i>=0;i--){
		if(v[i].first==v[0].first){
			cout<<v[i].second<<endl;
		}
	}
	return 0;
}

Measured memory_bytes: 29164
L = [1]
n = int(input())
x = 6
y = 9
while x <= n:
    L.append(x)
    x *= 6
while y <= n:
    L.append(y)
    y *= 9
L.sort()
dp = [float("Inf")]*(n+1)
dp[0] = 0
for i in range(n+1):
    for j in L:
        if i+j <= n:
            dp[i+j] = min(dp[i+j],dp[i]+1)
        else:
            break
print(dp[n])

Measured memory_bytes: 74596
program successive_subtraction
  implicit none
  integer :: n, i, l, r
  integer(8) :: a(100000), m, s
  a = 0_8
  read(*,*) n
  read(*,*) a(1:n)
  call quick_sort(a(1:n))
  l = 0
  do while ((l.lt.n).and.(a(l+1).lt.0))
    l = l+1
  end do
  if (l.eq.0) then
    write(*,'(i0)') sum(a(1:n))-2_8*a(1)
    m = a(1)
    do i = 2, n-1
      write(*,'(i0,x,i0)') m, a(i)
      m = m-a(i)
    end do
    write(*,'(i0,x,i0)') a(n), m
    stop
  end if
  r = n+1
  do while ((r.gt.2).and.(a(r-1).gt.0))
    r = r-1
  end do
  if (r.eq.n+1) then
    write(*,'(i0)') 2_8*a(n)-sum(a(1:n))
    m = a(n)
    do i = n-1, 1, -1
      write(*,'(i0,x,i0)') m, a(i)
      m = m-a(i)
    end do
    stop
  end if
  write(*,'(i0)') sum(a(r:n))-sum(a(1:l))
  m = a(n)
  do i = 2, r-1
    write(*,'(i0,x,i0)') m, a(i)
    m = m-a(i)
  end do
  s = a(1)
  do i = r, n-1
    write(*,'(i0,x,i0)') s, a(i)
    s = s-a(i)
  end do
  write(*,'(i0,x,i0)') m, s
  stop
contains
  recursive subroutine quick_sort(a)
    implicit none
    integer(8), intent(inout) :: a(:)
    integer(8) :: p, c
    integer :: n, l, r
    n = size(a)
    l = 1
    r = n
    p = a((l+r)/2)+a(l)+a(r)-max(a((l+r)/2),a(l),a(r))-min(a((l+r)/2),a(l),a(r))
    do
      do while (a(l).lt.p)
        l = l+1
      end do
      do while (a(r).gt.p)
        r = r-1
      end do
      if (l.ge.r) exit
      c = a(l)
      a(l) = a(r)
      a(r) = c
      l = l+1
      r = r-1
    end do
    if (l.gt.2) call quick_sort(a(1:l-1))
    if (n.gt.r+1) call quick_sort(a(r+1:n))
  end subroutine quick_sort
end program successive_subtraction

Measured memory_bytes: 3200
#include <bits/stdc++.h>
#include <iostream>
#include <cstdio>
#include <iomanip>
using namespace std;
typedef pair<int,int> P;
typedef long long ll;

#define rep(i,n) for (int i=0; i<(n); i++)
const ll INF =2*1e9+2;
const ll BIG = 1e9+7;
const double PI = 3.141592653589793;

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

Measured memory_bytes: 3616
table = []
r,c = [int(x) for x in input().split( )]
for i in range(r):
    mini_table = [int(x) for x in input().split( )]
    table.append(mini_table)
for i in table:
    i.append(sum(i))
gyou = []
for i in range(c+1):
    counter = 0
    for j in range(r):
        counter += table[j][i]
    gyou.append(counter)
table.append(gyou)
for i in table:
    print(' '.join(str(j) for j in i))



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

using namespace std;
using ll = long long;
constexpr int mod = 1e9+7;
constexpr int md = mod;

int culc(int a,int b,int c,vector<int> v,vector<int> &take){
    vector<int> d(4);
    int ret = 0;
    for(int i=0;i<(int)v.size();++i){
        if(v[i] != 3 && d[v[i]] != 0)ret += 10;
        d[v[i]] += take[i];
    }
    for(int i=0;i<3;++i){
        if(d[i] == 0) return 1<<30;
    }
    return ret + abs(d[0] - a) + abs(d[1] - b) + abs(d[2] - c);
}
int main(){
    int a,b,c,n;
    cin>>n>>a>>b>>c;
    vector<int> take(n);
    for(auto & a : take) cin>>a;
    int ret = 1<<30;
    for(int i=0;i<(1<<2*n);++i){
        vector<int> v(n);
        for(int j=0;j<n;++j){
            v[j] = (i>>(2*j))&3;
        }
        ret = min(ret,culc(a,b,c,v,take));
    }
    cout << ret << endl;
    return 0;
}



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

signed main() {
	ll n, d;
	cin >> n >> d;
	ll ans = 0;
	rep(i, n){
		ll x, y;
		cin >> x >> y;
		double long far;
		far = sqrt((x*x) + (y*y));
		if(far <= d) ans++;
	}
	cout << ans << endl;
}

Measured memory_bytes: 3672
#include <bits/stdc++.h>
 
#define rep(i,n) for(int i=0;i<(n);i++)
#define reps(i,n) for(int i=1;i<=(n);i++)
#define lol long long
#define SUM(n) ((n)+1)*(n)/2　//1〜nまでの総和を求める式
#define mp make_pair
#define fi first
#define se second
#define pu push_back
#define SYOU(x) setprecision(x+1) //小数点桁数を指定する
#define abs(x,y) (max(x,y)-min(x,y))
#define all(v) v.begin(),v.end()
#define UPDight(a,b) (a+b-1)/b //小数点切り上げ 
const int INF = 0x3f3f3f3f;
const long long LINF = 0x3f3f3f3f3f3f3f3fLL;
const int MOD=int(1e9)+7; 
using namespace std;
using pii = pair<int,int>;
typedef vector<int> vit;

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

    int n, m;
    cin >> n >> m;
    int ans = 0;
    rep(i, n){
      for(int j = i + 1;j < n;j ++){
	ans ++;
      }
    }
    rep(i, m){
      for(int j = i + 1;j < m;j ++){
	ans ++;
      }
    }
    cout << ans << '\n';
    return 0;
} 


Measured memory_bytes: 256
#import numpy as np
import heapq
import sys, math
from itertools import permutations, combinations
from collections import defaultdict, Counter, deque
from math import factorial#, gcd
from bisect import bisect_left #bisect_left(list, value)
sys.setrecursionlimit(10**7)
enu = enumerate
MOD = 10**9+7
def input(): return sys.stdin.readline()[:-1]
pl = lambda x: print(*x, sep='\n')


def dijkstra_heap(s):
    #始点sから各頂点への最短距離
    d = [float("inf")] * N
    used = [True] * N #True:未確定
    d[s] = 0
    used[s] = False
    edgelist = []
    for e in edge[s]:
        heapq.heappush(edgelist, e+[s])
    while len(edgelist):
        minedge = heapq.heappop(edgelist)
        if not used[minedge[1]]:
            continue
        v = minedge[1]
        d[v] = minedge[0]
        pn = minedge[2]
        pns[v] = pn
        used[v] = False
        for e in edge[v]:
            if used[e[1]]:
                heapq.heappush(edgelist, [e[0]+d[v], e[1], v])
    return d

N, M = map(int, input().split())
edge = [[] for i in range(N)]
for i in range(M):
    x, y = map(int, input().split())
    x, y = x-1, y-1
    edge[x].append([1, y])
    edge[y].append([1, x])

pns = [0]*N
dijkstra_heap(0)

print('Yes')
for pni in pns[1:]:
    print(pni+1)


Measured memory_bytes: 149668
#include <bits/stdc++.h>
using namespace std;
int n,m,dis[105][105],vst[105][105];
char a[105][105];
struct Thing {
	int x,y,dis;
	bool operator <(const Thing yy) const {
		return dis>yy.dis;
	}
};
int main() {
//	freopen("1.in","r",stdin);
	memset(dis,0x3f,sizeof(dis));
	cin>>n>>m;
	for(int i=1; i<=n; i++)scanf("%s",a[i]+1);
	priority_queue<Thing> q;
	dis[1][1]=(a[1][1]=='#');
	q.push({1,1,dis[1][1]});
	while(!q.empty()) {
		Thing now=q.top();
		q.pop();
		//if(now.x==1&&now.y==2)return cout<<"PP",0;
		//cout<<now.x<<' '<<now.y<<' '<<dis[now.x][now.y]<<endl;
		if(vst[now.x][now.y])continue;
		vst[now.x][now.y]=1;
		//cout<<now.x<<' '<<now.y<<' '<<dis[now.x][now.y]<<endl;
		if(now.x==n&&now.y==m) {
			return cout<<dis[n][m],0;
		}
		queue<Thing> q2;
		q2.push(now);
		int inq2[105][105]={0};
		while(!q2.empty()) {
			Thing x=q2.front();
			q2.pop();
			if(x.x<n) {
				if(a[x.x+1][x.y]==a[now.x][now.y]) {
					q.push({x.x+1,x.y,dis[now.x][now.y]});
					if(!inq2[x.x+1][x.y])q2.push({x.x+1,x.y,dis[now.x][now.y]}),inq2[x.x+1][x.y]=1;
					dis[x.x+1][x.y]=min(dis[x.x+1][x.y],dis[now.x][now.y]);
				} else {
					q.push({x.x+1,x.y,dis[now.x][now.y]+(a[now.x][now.y]=='.')});
					dis[x.x+1][x.y]=min(dis[x.x+1][x.y],dis[now.x][now.y]+(a[now.x][now.y]=='.'));
				}
			}
			if(x.y<m) {
				if(a[x.x][x.y+1]==a[now.x][now.y]) {
					q.push({x.x,x.y+1,dis[now.x][now.y]});
					if(!inq2[x.x][x.y+1])q2.push({x.x,x.y+1,dis[now.x][now.y]}),inq2[x.x][x.y+1]=1;
					dis[x.x][x.y+1]=min(dis[x.x][x.y+1],dis[now.x][now.y]); 
					//if(now.x==1&&now.y==1)cout<<x.x<<' '<<x.y+1<<' '<<"F:"<<dis[x.x][x.y+1]<<q.size()<<endl;
					//system("pause");
				} else if(x.y<m) {
					q.push({x.x,x.y+1,dis[now.x][now.y]+(a[now.x][now.y]=='.')});
					dis[x.x][x.y+1]=min(dis[x.x][x.y+1],dis[now.x][now.y]+(a[now.x][now.y]=='.'));
				}
			}
		}
	}
	return 0;
}
/*
15 15
....#.#.....#..
##.#....#...###
.#.....##..#.#.
###..#..#......
###..##..##..#.
#..#.#.#.###...
.......####.#.#
##..#.#.###.##.
##.#.##....#.##
..##.#.#.#.#..#
....#.....#....
...#.#..##.###.
.######.###....
.##....####.###
..######..#####
*/ 

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

using namespace std;

#define TEMP_T template<typename T>
TEMP_T void sort(T& v){ sort(v.begin(), v.end()); }
TEMP_T void revs(T& v){ reverse(v.begin(), v.end()); }
TEMP_T void uniq(T& v){ sort(v); v.erase(unique(v.begin(), v.end())); }
TEMP_T T    cums(T& v){ T r; r.push_back(v[0]); for(int i=1; i<v.size(); i++) r.push_back(r[i-1] + v[i]); return r; }
TEMP_T void show(T& v, char delim=' ', char end='\n'){ for(int i=0; i<v.size()-1; i++) cout << v[i] << delim; cout << v[v.size()-1] << end; }

static inline int in(){ int x; scanf("%d", &x); return x; }

struct Solver {
  Solver(){}
  int solve(){
  }
};

int main()
{
  int n;
  while (n = in()){
    vector<long long> v;
    for (int i = 0; i < n; i++) v.push_back(in());
    sort(v);
    vector<long long> cs = cums(v);
    long long sum = 0;
    for (int i = 0; i < n - 1; i++){
      sum += cs[i];
    }
    printf("%lld\n", sum);
  }

  return (0);
}

Measured memory_bytes: 1392
#include <cstdio>
#include <cstdint>
#include <cctype>
#include <cassert>
#include <vector>
#include <algorithm>
#include <string>
#include <utility>
#include <stack>
#include <map>

#define fprintf(...) void(0)

std::map<size_t, size_t> preprocess(const std::string &s, std::string &t) {
  std::stack<size_t> opened;
  std::map<size_t, size_t> paren;
  for (size_t i=0; i<s.length(); ++i) {
    char ch=s[i];
    if (ch == '~') {
      ch = s[++i];
      t += ch^0x20;
    } else if (isalpha(ch)) {
      t += ch;
    } else if (ch == '{' || ch == '[') {
      opened.emplace(t.length());
      t += ch;
    } else if (ch == '}' || ch == ']') {
      size_t opening=opened.top();
      opened.pop();
      paren[opening] = t.length();
      paren[t.length()] = opening;
      t += ch;
    } else {
      t += ch;
    }
  }
  fprintf(stderr, "t: %s\n", t.c_str());
  return paren;
}

const size_t di[]={size_t(-1), 0, 1, 0};
const size_t dj[]={0, 1, 0, size_t(-1)};
const char dc[]={'N', 'E', 'S', 'W'};

intmax_t exec(
    const std::vector<std::string> &a, const std::string &s, 
    const std::map<size_t, size_t> &paren, intmax_t max_cmd) {

  size_t ci=0, cj=0;
  for (size_t i=0; i<a.size(); ++i) {
    for (size_t j=0; j<a[i].length(); ++j) {
      if (a[i][j] == 's') {
        ci = i;
        cj = j;
        break;
      }
    }
  }

  intmax_t step=0, cmd=0;
  size_t i=0, d=0;
  while (i < s.length() && ++cmd < max_cmd) {
    fprintf(stderr, "(%zu, %zu)\n", ci, cj);
    fprintf(stderr, "s[%zu]: %c\n", i, s[i]);
    fflush(stderr);
    if (s[i] == '^') {
      if (a[ci+di[d]][cj+dj[d]] != '#') {
        ci += di[d];
        cj += dj[d];
      }
      ++step;
    } else if (s[i] == 'v') {
      if (a[ci-di[d]][cj-dj[d]] != '#') {
        ci -= di[d];
        cj -= dj[d];
      }
      ++step;
    } else if (s[i] == '<') {
      (d==0? d=3:--d);
      ++step;
    } else if (s[i] == '>') {
      (d==3? d=0:++d);
      ++step;
    } else if (s[i] == '[' || s[i] == '{') {
      size_t closing=paren.at(i);
      ++i;
      char cond=s[i];
      if (isupper(cond) && (cond == dc[d] || cond == 'T')) {
        // pass
      } else if (cond == 'C' && a[ci+di[d]][cj+dj[d]] == '#') {
        // pass
      } else if (islower(cond) && !(cond == (dc[d]|0x20) || cond == 't') && cond != 'c') {
        // pass
      } else if (cond == 'c' && a[ci+di[d]][cj+dj[d]] != '#') {
        // pass
      } else {
        i = closing;
      }
    } else if (s[i] == ']') {
      // end-if
    } else if (s[i] == '}') {
      // end-while
      i = paren.at(i)-1;
    }
    ++i;
    if (a[ci][cj] == 'g') break;
  }
  if (a[ci][cj] != 'g') return max_cmd;
  return step;
}

int main() {
  size_t H, W;
  scanf("%zu %zu", &H, &W);
  std::vector<std::string> a(H);
  for (size_t i=0; i<H; ++i) {
    char buf[64];
    scanf("%s", buf);
    a[i] = std::move(buf);
  }
  char buf[1024];
  scanf("%s", buf);
  std::string s=std::move(buf), t;
  std::map<size_t, size_t> paren=preprocess(s, t);

  intmax_t max_step=10000000;
  intmax_t step=exec(a, t, paren, max_step);
  printf("%jd\n", step<max_step? step:-1);
}



Measured memory_bytes: 2948
#include <bits/stdc++.h>
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define repi(i,a,b) for(int i=int(a);i<int(b);++i)
#define REP(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)

using namespace std;
using ll = long long;

int main()
{
    int a;
    cin >> a;
    a%=1000;
    if(a>0){
        a =1000 - a;
    }
    cout << a << endl;
    return 0;
}


Measured memory_bytes: 3620
import sys

# import re
import math
import collections
# import decimal
import bisect
import itertools
import fractions
# import functools
import copy
import heapq
import decimal
# import statistics
import queue

sys.setrecursionlimit(10000001)
INF = 10 ** 16
MOD = 10 ** 9 + 7

ni = lambda: int(sys.stdin.readline())
ns = lambda: map(int, sys.stdin.readline().split())
na = lambda: list(map(int, sys.stdin.readline().split()))


# ===CODE===


def main():
    N = ni()
    lim = 3500

    for h in range(1, lim + 1):
        for n in range(1, lim + 1):
            up = N * h * n
            down = 4 * h * n - N * n - N * h
            if down != 0:
                if up % down == 0:
                    if 0 < up // down:
                        print(h, n, up // down)
                        exit(0)


if __name__ == '__main__':
    main()


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

int main() {
  int k, t;
  cin >> k >> t;
  vector<int> a(t);
  int sum = 0, nmax = -999;
  for (int i = 0; i < t; i++) {
    cin >> a[i];
    sum += a[i];
    if (a[i] > nmax) {
      nmax = a[i];
    }
  }
  sum -= nmax;
  int ans = max(0, nmax - sum - 1);
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ull unsigned long long
ll mod=1e9+7;
#define PI 3.1415926535897932385
#define INF 100000000000000000ll
#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);
#include <string>
string char_to_str(char c){string tem(1,c);return tem;}
 
typedef pair<int, int> ii;
#define S second
#define F first
ll max(ll a,ll b){if(a>b){return a;}return b;}
ll min(ll a,ll b){if(a<b){return a;}return b;}
// string to integer stoi() Remember: it takes string not character
// string to long long stoll()
// string.substr(position,length);
// integer to string to_string();
 
// To compile--> g++ -std=c++0x -o output one.cpp
// To run--> ./output
int main() 
{
	fastio;
	// freopen("input.txt","r",stdin);
	// freopen("output.txt","w",stdout);
	int n;
	cin>>n;
	int a[n];
	for (int i = 0; i < n; ++i)
	{
		cin>>a[i];
	}
	int ans[n];
	ans[0]=0;
	ans[1] = abs(a[1]-a[0]);
    for(int i=2;i<n;++i)
    {
        ans[i]=min(ans[i-1]+abs(a[i-1]-a[i]),ans[i-2]+abs(a[i-2]-a[i]));
    }
    cout<<ans[n-1];

    return 0;
} 

Measured memory_bytes: 1024
from collections import deque

n,q=map(int,input().split())

tree=[[] for i in range(n)]
for i in range(n-1):
 i,j=map(int,input().split())
 tree[i-1].append(j-1)
 tree[j-1].append(i-1)

t_cnt=[0 for i in range(n)]
for i in range(q):
 p,x=map(int,input().split())
 t_cnt[p-1]+=x

cnt=[-1]*n
cnt[0]=t_cnt[0]

seen=set([0])

dq=deque()
dq.append(0)

while dq:
 x=dq.popleft()
 ref_v=cnt[x]
 for i in tree[x]:
#  if cnt[i]==-1:
  if i not in seen:
   seen.add(i)
   dq.append(i)
   cnt[i]=ref_v+t_cnt[i]

print(*cnt)

Measured memory_bytes: 70248
#include<cstdio>
#include<string.h>
#include<iostream>
#include<cmath>
#include<complex>
#include<string>
#include<map>
using namespace std;
typedef complex<double> xy_t;

int main(){
  while(1){
    int n;
    int m[55];
    double x[55][11],y[55][11];
    xy_t p[55][11];
    xy_t s[4][55];
    memset(m,0,sizeof(m));
    memset(x,0,sizeof(x));
    memset(y,0,sizeof(y));
    memset(p,0,sizeof(p));
    memset(s,0,sizeof(s));


    scanf("%d",&n);
    if(n==0) break;
    for(int i=0;i<=n;i++){
      scanf("%d",&m[i]);
      for(int j=0;j<m[i];j++){
        scanf("%lf%lf",&x[i][j],&y[i][j]);
        p[i][j]=(xy_t(x[i][j]-x[0][0],y[i][j]-y[0][0]));
      }
    }

    for(int i=0;i<m[0];i++){
      s[0][i]=p[0][i];
      s[1][i]=p[0][i]*(xy_t(0,1));
      s[2][i]=p[0][i]*(xy_t(-1,0));
      s[3][i]=p[0][i]*(xy_t(0,-1));
    }


    for(int j=1;j<=n;j++){
      bool flg=false;
      if(m[0]!=m[j]) continue;
      for(int i=0;i<4;i++){
        bool flg2=true;
        bool flg3=true;
        for(int u=0;u<m[0];u++){
          if(s[i][u]+p[j][0]!=p[j][u]) {flg2=false;break;}
        }
        for(int u=0;u<m[0];u++){
          if(s[i][u]+p[j][m[0]-1]!=p[j][m[0]-u-1]) {flg3=false;break;}
        }
        if(flg2==true || flg3==true) {flg=true;break;}
      }
      if(flg==true) printf("%d\n",j);
    }

    printf("+++++\n");
  }


  return 0;

}

Measured memory_bytes: 1264
#include <bits/stdc++.h>
#define ll long long
#define IOS ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define deb(x) cout<<#x<<"="<<x<<endl;
#define endl '\n'
#define M 1000000007
#define int long long
#define INF 1e18
#define max_n 1000000

using namespace std;

void solve()
{
	ll n,k;
	cin>>n>>k;
	ll a[n];
	for (int i = 0; i < n; ++i)
	{
		cin>>a[i];
	}
	sort(a,a+n);
	ll ans=0;
	for (int i = 0; i < k; ++i)
	{
		ans+=a[i];
	}
	cout<<ans<<endl;
}

int32_t main() 
{
	IOS	
	ll T=1;
	// cin>>T;
	for(ll i=1;i<=T;++i)
	{		
		// cout<<"Case #"<<i<<": ";
    	solve();
	}
	return 0;
}

Measured memory_bytes: 3652
#include <bits/stdc++.h>
using namespace std;
using lint = long long;
const lint mod = 998244353;
#define all(x) (x).begin(), (x).end()
#define bitcount(n) __builtin_popcountl((lint)(n))
#define fcout cout << fixed << setprecision(15)
#define highest(x) (63 - __builtin_clzl(x))
template<class T> inline void YES(T condition){ if(condition) cout << "YES" << endl; else cout << "NO" << endl; }
template<class T> inline void Yes(T condition){ if(condition) cout << "Yes" << endl; else cout << "No" << endl; }
template<class T = string, class U = char>int character_count(T text, U character){ int ans = 0; for(U i: text){ ans += (i == character); } return ans; }
lint power(lint base, lint exponent, lint module){ if(exponent % 2){ return power(base, exponent - 1, module) * base % module; }else if(exponent){ lint root_ans = power(base, exponent / 2, module); return root_ans * root_ans % module; }else{ return 1; }}
struct position{ int y, x; }; position mv[4] = {{0, -1}, {1, 0}, {0, 1}, {-1, 0}}; // double euclidean(position first, position second){ return sqrt((second.x - first.x) * (second.x - first.x) + (second.y - first.y) * (second.y - first.y)); }
template<class T, class U> string to_string(pair<T, U> x){ return to_string(x.first) + "," + to_string(x.second); } string to_string(string x){ return x; }
template<class itr> void array_output(itr start, itr goal){ string ans; for(auto i = start; i != goal; i++) ans += to_string(*i) + " "; if(!ans.empty()) ans.pop_back(); cout << ans << endl; }
template<class itr> void cins(itr first, itr last){ for(auto i = first; i != last; i++){ cin >> (*i); } }
template<class T> T gcd(T a, T b){ if(a && b){ return gcd(min(a, b), max(a, b) % min(a, b)); }else{ return a; }} template<class T> T lcm(T a, T b){ return a / gcd(a, b) * b; }
struct combination{ vector<lint> fact, inv; combination(int sz) : fact(sz + 1), inv(sz + 1){ fact[0] = 1; for(int i = 1; i <= sz; i++){ fact[i] = fact[i - 1] * i % mod; } inv[sz] = power(fact[sz], mod - 2, mod); for(int i = sz - 1; i >= 0; i--){ inv[i] = inv[i + 1] * (i + 1) % mod; } } lint C(int p, int q) const{ if(q < 0 || p < q) return 0; return (fact[p] * inv[q] % mod * inv[p - q] % mod); } };
template<class itr> bool next_sequence(itr first, itr last, int max_bound){ itr now = last; while(now != first){ now--; (*now)++; if((*now) == max_bound){ (*now) = 0; }else{ return true; } } return false; }

int main(){
    int N;
    cin >> N;
    map<string, lint> anagrams;
    for(int i = 0; i < N; i++){
        string s;
        cin >> s;
        sort(all(s));
        anagrams[s]++;
    }
    lint ans = 0;
    for(auto i: anagrams){
        ans += i.second * (i.second - 1) / 2;
    }
    cout << ans << endl;
}


Measured memory_bytes: 11136
#include <bits/stdc++.h>
using namespace std;
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define endl "\n"
#define mod 998244353
#define int long long
#define ll long long
#define EPS 0.000000001
#define ld long double
#define inf 5e18
#define N 305
#define K 17







int32_t main()
{
    IOS;
    #ifndef ONLINE_JUDGE
    freopen("int.txt","r",stdin);
    freopen("out.txt","w",stdout);
    #endif
    int t;
    cin >> t;
    while(t--)
    {
        int n;
        cin >> n;
        vector<int> v(n);
        vector<int> basis;

        for(int i = 0;i < n;i++)
            cin >> v[i];
        string s;
        cin >> s;

        bool ans = 0;
        for(int i  = n - 1;i >= 0;i--)
        {
            for(auto it : basis)
                if( (v[i] ^ it) < v[i])
                    v[i] ^= it;
            if(v[i])
            {
                if(s[i] == '1')
                {
                    ans = 1;
                    break;
                }
                else
                    basis.push_back(v[i]);
            }
        }
        cout << ans << endl;
    }

    
    return 0;
    
}   

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

using namespace std;
typedef long long ll;
 

int main(){
    ll a[1000000];
    ll n;
    cin>>n;
    a[0] = 2;
    a[1] = 1;
    for(ll i = 2; i < 1000000; i++){
        a[i] = a[i-1] + a[i-2];
    }
 
    cout << a[n]<< endl;
}

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

#define int long long
#define double long double
#define rep(i, n) for (int i = 0; i < (n); i++)
#define reps(i, n) for (int i = 1; i <= (n); i++)
#define all(x) (x).begin(), (x).end()
#define uniq(x) (x).erase(unique(all(x)), (x).end())
#define bit(n) (1LL << (n))
#define dump(x) cerr << #x " = " << (x) << endl
using vint=vector<int>;
using vvint=vector<vint>;
using pint=pair<int, int>;
using vpint=vector<pint>;
template<typename T> using priority_queue_rev=priority_queue<T, vector<T>, greater<T>>;
constexpr double pi = 3.1415926535897932384626433832795028L;
constexpr int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};
constexpr int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
int gcd(int a, int b) {
    while (b) { swap(a %= b, b); }
    return a;
}
int lcm(int a, int b) { return a / gcd(a, b) * b; }
template<typename T> void fin(T mes) {
    cout << mes << endl;
    exit(0);
}
template<typename T1, typename T2> bool chmax(T1 &a, const T2 &b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}
template<typename T1, typename T2> bool chmin(T1 &a, const T2 &b) {
    if (b < a) {
        a = b;
        return true;
    }
    return false;
}
template<typename T1, typename T2> ostream &operator<<(ostream &os, const pair<T1, T2> &rhs) {
    os << "(" << rhs.first << ", " << rhs.second << ")";
    return os;
}
template<typename T> ostream &operator<<(ostream &os, const vector<T> &rhs) {
    os << "{";
    for (auto itr = rhs.begin(); itr != rhs.end(); itr++) {
        os << *itr << (next(itr) != rhs.end() ? ", " : "");
    }
    os << "}";
    return os;
}
struct setup {
    static constexpr int PREC = 20;
    setup() {
        cout << fixed << setprecision(PREC);
        cerr << fixed << setprecision(PREC);
    };
} setup;

int N;
string S;
signed main() {
    cin >> N >> S;
    rep(i, S.length()) { S[i] = (S[i] - 'A' + N) % 26 + 'A'; }
    cout << S << endl;
}


Measured memory_bytes: 256
#include <stdio.h>
#include <cmath>
#include <algorithm>
#include <cfloat>
#include <stack>
#include <queue>
#include <vector>
#include <string>
#include <iostream>
#include <set>
#include <map>
typedef long long int ll;
typedef unsigned long long int ull;
#define BIG_SIZE 2000000000
#define MOD 1000000007
#define EPS 0.000000001
using namespace std;


#define SIZE 100000

vector<int> G[SIZE];
int N;
bool visited[SIZE];
int visited_order[SIZE],parent[SIZE],lowest[SIZE],number;


void dfs(int current_node,int pre_node){
	visited_order[current_node] = lowest[current_node] = number;
	number++;

	visited[current_node] = true;

	int next;

	for(int i = 0; i < G[current_node].size(); i++){
		next = G[current_node][i];
		if(!visited[next]){
			parent[next] = current_node;
			dfs(next,current_node);
			lowest[current_node] = min(lowest[current_node],lowest[next]);
		}else if(visited[next] == true && next != pre_node){
			lowest[current_node] = min(lowest[current_node],visited_order[next]);
		}
	}
}

void art_points(){

	for(int i = 0; i < N; i++)visited[i] = false;

	number = 1;
	dfs(0,-1);

	int tmp_parent,root_num = 0;

	vector<int> V;

	for(int i = 1; i < N; i++){
		tmp_parent = parent[i];
		if(tmp_parent == 0){
			root_num++;
		}else if(visited_order[tmp_parent] <= lowest[i]){
			V.push_back(tmp_parent);
		}
	}
	if(root_num >= 2){
		V.push_back(0);
	}
	sort(V.begin(),V.end());
	V.erase(unique(V.begin(),V.end()),V.end());

	for(int i = 0; i < V.size(); i++){
		printf("%d\n",V[i]);
	}
}


int main(){
	int E;

	scanf("%d %d",&N,&E);

	int from,to;

	for(int i = 0; i < E; i++){
		scanf("%d %d",&from,&to);
		G[from].push_back(to);
		G[to].push_back(from);
	}

	art_points();

	return 0;
}

Measured memory_bytes: 6980
// #define _GLIBCXX_DEBUG // for STL debug (optional)
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <string>
#include <cstring>
#include <deque>
#include <list>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <complex>
#include <cmath>
#include <limits>
#include <cfloat>
#include <climits>
#include <ctime>
#include <cassert>
#include <numeric>
#include <fstream>
#include <functional>
#include <bitset>
using namespace std;

#define debug(...) fprintf(stderr, __VA_ARGS__)
#define int long long int
 
template<typename T> void chmax(T &a, T b) {a = max(a, b);}
template<typename T> void chmin(T &a, T b) {a = min(a, b);}
template<typename T> void chadd(T &a, T b) {a = a + b;}
 
typedef pair<int, int> pii;
typedef long long ll;
 
int dx[] = {0, 0, 1, -1};
int dy[] = {1, -1, 0, 0};
const ll INF = 1001001001001001LL;
const ll MOD = 1000000007LL;

int info[10][10], ans, lim;

void get_assignment(vector< pair<int, int> > &rem, vector<int> &win, int cur) {
    if(cur == rem.size()) {
        bool ok = true;
        for(auto e : win) ok &= (e <= lim);
        if(ok) ans++;
    }
    else {
        int u, v; tie(u, v) = rem[cur];
        {
            win[u]++;
            if(win[u] <= lim) {
                get_assignment(rem, win, cur + 1);
            }
            win[u]--;
        }

        {
            win[v]++;
            if(win[v] <= lim) {
                get_assignment(rem, win, cur + 1);
            }
            win[v]--;
        }
    }
}

int solve() {
    int N; cin >> N;
    if(N == 0) return 1;
    int M; cin >> M;

    // init
    fill(info[0], info[N], -1);
    ans = 0; lim = N * (N - 1) / 2 / N;
    
    vector<int> win(N);
    for(int i=0; i<M; i++) {
        int u, v; cin >> u >> v;
        u--; v--;
        info[u][v] = 1;
        info[v][u] = 0;
        win[u]++;
    }

    vector< pair<int, int> > rem;
    for(int i=0; i<N; i++) {
        for(int j=i+1; j<N; j++) {
            if(info[i][j] < 0) {
                rem.emplace_back(i, j);
            }
        }
    }

    get_assignment(rem, win, 0);
    cout << ans << endl;
    return 0;
}
 
signed main() {
    while(!solve());
    return 0;
}



Measured memory_bytes: 3084
#include<vector>
#include<cmath>
#include<map>
#include<cstdlib>
#include<iostream>
#include<sstream>
#include<fstream>
#include<string>
#include<algorithm>
#include<cstring>
#include<cstdio>
#include<set>
#include<stack>
#include<bitset>
#include<functional>
#include<ctime>
#include<queue>
#include<deque>
#include<complex>
#include<cassert>
using namespace std;
#define pb push_back
#define pf push_front
typedef long long lint;
typedef complex<double> P;
#define mp make_pair
#define fi first
#define se second
typedef pair<int,int> pint;
#define All(s) s.begin(),s.end()
#define rAll(s) s.rbegin(),s.rend()
#define REP(i,a,b) for(int i=a;i<b;i++)
#define rep(i,n) REP(i,0,n)
int dp[110][20];
int s[110];
int main()
{
	int n,out=0;
	memset(dp,-1,sizeof(dp));dp[0][0]=0;
	cin>>n;
	rep(i,n){
		cin>>s[i];
		rep(j,10){
			if(dp[i][j]<0) continue;
			dp[i+1][j]=max(dp[i+1][j],dp[i][j]);
			dp[i+1][(j+s[i])%10]=max(dp[i+1][(j+s[i])%10],dp[i][j]+s[i]);
		}
	}
	REP(i,1,10) out=max(out,dp[n][i]);
	cout<<out<<endl;
}


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




int main() {


        int n , k ;  cin >> n >> k ;

         int Arr [n] ;
          for (int i = 0 ; i < n ; i ++ )
               cin >> Arr[i];

           int  sum = 0 ;
           sort ( Arr , Arr + n ) ;
             for ( int i = 0 ; i < k ; i ++ )
                  sum +=Arr[i];

              cout << sum << endl;
            
        return 0;
    }

Measured memory_bytes: 3644
#include <iostream>
#include <sstream>
#include <queue>
#include <map>
#include <set>
#include <vector>
#include <numeric>
#include <algorithm>
#include <string>
#include <complex>
 
#include <cassert>
#include <cstdlib>
#include <cmath>
#include <cstdio>
#include <cstring>
 
#define REP(i,e) for(int i=0;i<(int)(e);i++)
#define FOR(i,b,e) for(int i=(int)(b);i<(int)(e);i++)
#define ALL(c) (c).begin(), (c).end()
#define EACH(it,c) for(__typeof((c).begin()) it=(c).begin();it!=(c).end();++it)
#define RALL(c) (c).rbegin(), (c).rend()
#define ALLA(a,n) ((a)+0), ((a)+n)
 
using namespace std;
 
typedef long long ll;
typedef vector<int> vint;
typedef vector<long long> vll;
typedef vector<string> vstring;
typedef vector<double> vdouble;
 
template<class T>void pp(T v,int n){ REP(i,n)cout<<v[i]<< ' ' ; cout << endl; }
template<class T>void pp(T v){ EACH(it,v) cout << *it << ' ' ; cout << endl;  }
template<class T>T& ls(T& a,T b){ if(b<a) a=b; return a; }
template<class T>T& gs(T& a,T b){ if(b>a) a=b; return a; }
inline ll to_i(const string& s){ll n;sscanf(s.c_str(),"%lld",&n);return n;}
inline string to_s(ll n){char buf[32];sprintf(buf,"%lld",n);return string(buf);}

inline void write_bool(bool b, const string &tval, const string &fval) {
  cout << (b ? tval : fval) << endl;
} 
inline void YESNO(bool b) { return write_bool(b, "YES", "NO"); }
inline void YesNo(bool b) { return write_bool(b, "Yes", "No"); }
inline void yesno(bool b) { return write_bool(b, "yes", "no"); }


int main() {
  string s;
  while (cin >> s) {
    set<int> lset, rset;
    REP(i,s.length()) {
      if (s[i] == 'L') lset.insert(i);
      else rset.insert(i);
    }

    vint result(s.length());
    REP(i,s.length()) {
      if (s[i] == 'R') {
        int p = *lset.lower_bound(i);
        if ((p - i) % 2 == 0);
        else p--;
        //cout << "R" << i << " -> " << p << endl;
        result[p]++;
      } else {
        auto it = rset.lower_bound(i);
        it--;
        int p = *it;
        if ((p - i) % 2 == 0);
        else p++;
        //cout << "L" << i << " -> " << p << endl;
        result[p]++;
      }
    }
    pp(result);
  }
}


Measured memory_bytes: 6080
n = int(input())

s = input()
cnt = s.count('R') * s.count('G') * s.count('B')

for i in range(n):
    for j in range(n):
        if 0 <= i - j <= i and 0 <= i + j <= n-1:
            x1, x2, x3 = s[i - j], s[i], s[i + j]
            if x1 != x2 and x1 != x3 and x2 != x3:
                cnt -= 1
print(cnt)

Measured memory_bytes: 68400
#include <bits/stdc++.h>
using namespace std;
signed main()
{
    string s;
    cin >> s;
    
    for(int i=0 ;i<s.size() ;i++ ){
        if(s[i] == '?'){
            s[i] = 'D';
        }
    }
    
    cout << s << endl;
    return(0);
}

Measured memory_bytes: 3680
n, c = map(int, input().split())
d = [list(map(int ,input().split())) for _ in range(c)]
C = [list(map(int ,input().split())) for _ in range(n)]

grid = [[0]*c for _ in range(3)]
for i in range(n):
    for j in range(n):
        grid[(i+j)%3][C[j][i]-1] += 1

points = []
for i in range(3):
    row = []
    for color in range(1,1+c):
        x = 0
        for j,m in enumerate(grid[i]):
            x += m*d[j][color-1]
        row.append([x, color])
    points.append(row)

for i in range(3):
    points[i].sort()


ans =1000*n*n
for i in range(27):
    x = points[0][i//9]
    y = points[1][i//3%3]
    z = points[2][i%3]
    if x[1] == y[1] or y[1] == z[1] or z[1] == x[1]:
        continue
    ans = min(ans, x[0]+y[0]+z[0])
print(ans)


Measured memory_bytes: 5620
#include <iostream>
#include <fstream>
#include <set>
#include <map>
#include <string>
#include <vector>
#include <queue>
#include <deque>
#include <stack>
#include <functional>
#include <algorithm>
#include <climits>
#include <cmath>
#include <iomanip>
using namespace std;
#define ll long long int
#define rep(i,n) for( int i = 0; i < n; i++ )
#define rrep(i,n) for( int i = n; i >= 0; i-- )
#define REP(i,s,t) for( int i = s; i <= t; i++ )
#define RREP(i,s,t) for( int i = s; i >= t; i-- )
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define INF 2000000000
#define mod 1000000007
#define INF2 1000000000000000000


int main(void)
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int r; cin >> r;
    cout << r * r << endl;

    return 0;
}


Measured memory_bytes: 3628
#include<cstdio>
#include<cmath>
using namespace std;
static inline double s(double a){ return a * a; }
int main() {
	int n;
	scanf("%d",&n);
	while(n--) {
		double xa,ya,ra,xb,yb,rb;
		scanf("%lf%lf%lf%lf%lf%lf",&xa,&ya,&ra,&xb,&yb,&rb);
		double d = sqrt(s(xb-xa) + s(yb-ya));
		if(d + ra < rb) puts("-2");
		else if(d + rb < ra) puts("2");
		else if(d > ra + rb) puts("0");
		else puts("1");
	}
	return 0;
}

Measured memory_bytes: 1044
#include<stdio.h>
#include<stdlib.h>
#include<iostream>
#include<string>
#include<algorithm>
#include<vector> 
#include<limits>
#include<numeric>
#include<type_traits>
#include<math.h>
using namespace std;

#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define repi(i,a,b) for(int i = (int)(a); i < (int)(b); i++)
#define in(x) cin >> x
#define out(str) cout << str << endl

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 A,B;
string S;

int main(){
    cin>>A>>B>>S;
    rep(i,A){
        if(S[i]<48||S[i]>57){
            out("No");
            return 0;
        }
    }
    if(S[A]!='-'){
        out("No");
        return 0;
    }
    repi(i,A+1,B+A+1){
        if(S[i]<48||S[i]>57){
            out("No");
            return 0;
        }
    }
    out("Yes");
}


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

ll solve(int n, longmat m) {
	longmat dp(n, longarr(3, 0));
	for (int i = 0; i < 3; ++i) dp[0][i] = m[0][i];
	for (int i = 1; i < n; ++i) {
		for (int j = 0; j < 3; ++j) {
			dp[i][j] = m[i][j] + max(dp[i - 1][((j + 1) % 3)], dp[i - 1][((j + 2) % 3)]);
		}
	}
	// for (int i = 0; i < n; ++i) {
	// 	for (int j = 0; j < 3; ++j) {
	// 		cout << dp[i][j] << " ";
	// 	}
	// 	cout << endl;
	// }
	return max(dp[n - 1][0], max(dp[n - 1][1], dp[n - 1][2]) );

}
int main() {
//#ifndef ONLINE_JUDGE
//	freopen("input.txt", "r", stdin);
//	freopen("output.txt", "w", stdout);
// #endif
	int n;
	cin >> n;
	longmat m(n, longarr(3, 0));
	for (int i = 0; i < n; ++i) {
		for (int j = 0; j < 3; ++j) {
			cin >> m[i][j];
		}
	}
	cout << solve(n, m);

}


Measured memory_bytes: 16640
#include <iostream>

using namespace std;

int main(){
  int N;
  cin >> N;
  int C[N-1], S[N-1], F[N-1];
  for (int i = 0; i < N-1; i++){
    cin >> C[i] >> S[i] >> F[i];
  }
  int ans[N-1];

  for (int i = N - 2; i >= 0; i--){
    int tmp = S[i] + C[i];

    for (int j = i+1; j < N - 1; j++){
      if (S[j] >= tmp){
        tmp = S[j] + C[j];
      }else{
        int t = tmp - S[j];
        if (t <= F[j]){
          t = F[j] - t;
        }else{
          int f = t % F[j];
          if (f==0) {
            t = 0;
          }else{
            t = F[j] - f;
          }
        }
        tmp += C[j] + t;
      }
    }
    ans[i] = tmp;
  }
  
  for (int i = 0; i < N-1; i++){
    printf("%d\n", ans[i]);
  }
  printf("0\n");
  
}


Measured memory_bytes: 3744
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;


public class Test
{	
    public static void Main()
	{
	    char[] c = Console.ReadLine().Replace(" ", "").ToCharArray();
	    bool ok = false;
	    if(c[0] == c[1] && c[1] == c[2]) ok = true;
	    if(c[1] == c[2] && c[2] == c[3]) ok = true;
	    
	    if(ok) Console.WriteLine("Yes");
	    else Console.WriteLine("No");
	} 
}

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

int main()
{
	string s;
	cin >> s;
	int n = s.length();
	for(int i = 0; i < n-1; i++) {
		if(s[i] == s[i+1]) {
			cout << i+1 << ' ' << i+2;
			return 0;
		}
	}
	for(int i = 0; i < n-2; i++) {
		if(s[i] == s[i+2]) {
			cout << i+1 << ' ' << i+3;
			return 0;
		}
	}
	puts("-1 -1");
}


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

#include <iostream>
#include <fstream>

#include <iostream>
#include "bits/stdc++.h"

using namespace std;

typedef unsigned long long ll;
typedef int                     integer;
#define int                     long long
#define ii                      pair<int,int>
#define vii                     vector<pair<int,int>>
#define vi                      vector<int>
#define vvi                     vector<vector<int>>
#define f(a,b,c)                for(int a=b;a<c;a++)
#define s(x)                    in>>x
#define s2(x,y)                 in>>x>>y
#define s3(x,y,z)               in>>x>>y>>z
#define s4(x,y,z,w)             in>>x>>y>>z>>w
#define p(x)                    out<<x<<endl
#define p2(x,y)                 out<<x<<" "<<y<<endl
#define pl(x)                   out<<x
#define p2l(x,y)                out<<x<<" "<<y
#define p1d(a,n)                for(int ix=0;ix<n;ix++) out<<a[ix]<<" "; out<<endl
#define p2d(a,n,m)              for(int ix=0;ix<n;ix++){ for(int jx=0;jx<m;jx++) out<<a[ix][jx]<<" "; out<<endl;}
#define range(v)                v.begin(),v.end()
#define w(x)                    while(x--)
#define rst(x)                  memset(x, -1, sizeof(x))
#define UNVISITED               -1
#define VISITED                 0
#define EXPLORED                2

void ssolve(std::istream& in, std::ostream& out){
string s;
s(s);
int q;
s(q);
vector<char> beginning;
vector<char> end;
bool reversed = false;
f(i,0,q){
    int t,f;
    char c;
    s(t);
    if(t == 1){
        reversed = !reversed;
    }
    else{
        s2(f,c);
        if(f == 1){
            if(reversed) end.push_back(c);
            else beginning.push_back(c);
        }
        else{
            if(reversed) beginning.push_back(c);
            else end.push_back(c);
        }
    }
}
if(reversed){
    reverse(range(end));
    reverse(range(s));
    f(i,0,end.size()) out<<end[i];
    out<<s;
    f(i,0,beginning.size())out<<beginning[i];
}else{
    reverse(range(beginning));
    f(i,0,beginning.size()) out<<beginning[i];
    out<<s;
    f(i,0,end.size())out<<end[i];
}
out<<endl;
}

class DStringFormation {
public:
	void solve(std::istream& in, std::ostream& out) {
        int t;
        int READ = 0;
        if(READ) s(t);
        else t = 1;
        while(t--){
            ssolve(in, out);
        }
	}
};


integer main() {
	DStringFormation solver;
	std::istream& in(std::cin);
	std::ostream& out(std::cout);
	solver.solve(in, out);
}


Measured memory_bytes: 1152
# 貪欲+山登り(2点交換+1点更新)
import time
import random

d = int(input())
dd = d * (d + 1) // 2
*C, = map(int, input().split())
S = [list(map(int, input().split())) for i in range(d)]

# 貪欲法による初期解の構築
T = []
L = [-1 for j in range(26)]
for i in range(d):
    max_diff = -10**7
    arg_max = 0
    for j in range(26):
        memo = L[j]
        L[j] = i
        diff = S[i][j] - sum([C[k] * (i - L[k]) for k in range(26)])
        if diff > max_diff:
            max_diff = diff
            arg_max = j
        L[j] = memo
    T.append(arg_max)
    L[arg_max] = i


def calc_score(T):
    L = [-1 for j in range(26)]
    X = [0 for j in range(26)]
    score = 0
    for i in range(d):
        score += S[i][T[i]]
        X[T[i]] += (d - i) * (i - L[T[i]])
        L[T[i]] = i
    for j in range(26):
        score -= C[j] * (dd - X[j])
    return score


score = calc_score(T)
start = time.time()
while True:
    now = time.time()
    if now - start > 1.8:
        break
    # 1点更新
    i = random.choice(range(d))
    j = random.choice(range(26))
    memo = T[i]
    T[i] = j
    new_score = calc_score(T)
    T[i] = memo
    if new_score > score:
        T[i] = j
        score = new_score
    # 2点交換
    i0 = random.choice(range(d))
    z = random.choice(range(5))
    i1 = i0 - z if i0 > z else i0 + z
    T[i0], T[i1] = T[i1], T[i0]
    new_score = calc_score(T)
    T[i0], T[i1] = T[i1], T[i0]
    if new_score > score:
        T[i0], T[i1] = T[i1], T[i0]
        score = new_score
for t in T:
    print(t + 1)


Measured memory_bytes: 95336
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define MOD 1000000007
#define MAX_N 100000
#define MAX_P 200005
int fact[MAX_P];
int extgcd(int a,int b,int& x,int& y){
  int d=a;
  if(b!=0){
    d=extgcd(b,a%b,y,x);
    y-=(a/b)*x;
  }else{
    x=1;y=0;
  }
  return d;
}
int mod_inverse(int a,int m){
  int x,y;
  extgcd(a,m,x,y);
  return (m+x%m)%m;
}

int euler_phi(int n){
  int res=n;
  for(int i=2;i*i<=n;i++){
    if(n%i==0){
      res=res/i*(i-1);
      for(;n%i==0;n/=i);
    }
  }
  if(n!=1) res=res/n*(n-1);
  return res;
}

int euler[MAX_N];

void euler_phi2(){
  for(int i=0;i<MAX_N;i++) euler[i]=i;
  for(int i=2;i<MAX_N;i++){
    if(euler[i]==i){
      for(int j=i;j<MAX_N;j+=i) euler[j]=euler[j]/i*(i-1);
    }
  }
}

int mod_pow(int x,int n,int mod){
  int res=1;
  while(n>0){
    if(n&1) (res*=x)%=mod;
    (x*=x)%=mod;
    n>>=1;
  }
  return res;
}

void init(int p){
  fact[0]=1;
  for(int i=1;i<MAX_P;i++) fact[i]=(fact[i-1]*i)%p;
}

int mod_fact(int n,int p,int& e){
  e=0;
  if(n==0) return 1;
  int res=mod_fact(n/p,p,e);
  e+=n/p;
  if(n/p%2!=0)return res*(p-fact[n%p]) %p;
  return res*fact[n%p]%p;
} 
int mod_comb(int n,int k,int p){
  if(n==k||k==0) return 1;
  int e1,e2,e3;
  int a1=mod_fact(n,p,e1),a2=mod_fact(k,p,e2),a3=mod_fact(n-k,p,e3);
  if(e1>e2+e3) return 0;
  return a1*mod_inverse(a2*a3%p,p)%p;
}


int dp[2][5005];
signed main(){
  init(MOD);
  int n;
  cin>>n;
  string s;
  cin>>s;
  int m=s.size();
  memset(dp,0,sizeof(dp));
  dp[0][0]=1;
  for(int i=0;i<n;i++){
    bool f=i%2;
    memset(dp[!f],0,sizeof(dp[!f]));
    for(int j=0;j<=n;j++){
      (dp[!f][j+1]+=dp[f][j]*2)%=MOD;
      if(j==0)
	(dp[!f][j]+=dp[f][j])%=MOD;
      else 
	(dp[!f][j-1]+=dp[f][j])%=MOD;
    }
  }
  cout<<(dp[n%2][m]*mod_inverse(mod_pow(2,m,MOD),MOD))%MOD<<endl;
  return 0;
}


Measured memory_bytes: 1920
using System;
using System.Collections.Generic;
using System.Linq;

namespace ConsoleApp1
{
	class Program
	{
		static void Main(string[] args)
		{
			var inputA = Console.ReadLine();
			var inputB = Console.ReadLine();
			var dicA = new Dictionary<char, int>();
			var dicB = new Dictionary<char, int>();

			int count = 0;
			var changedA = inputA
				.Select(c =>
				{
					if (dicA.ContainsKey(c))
					{
						return dicA[c];
					}
					dicA.Add(c, count++);
					return dicA[c];
				}).ToArray();
			count = 0;
			var changedB = inputB
				.Select(c =>
				{
					if (dicB.ContainsKey(c))
					{
						return dicB[c];
					}
					dicB.Add(c, count++);
					return dicB[c];
				}).ToArray();

			Console.WriteLine(changedA.SequenceEqual(changedB) ? "Yes" : "No");
		}
	}
}


Measured memory_bytes: 19168
#include <stdio.h>
typedef long long ll;

int main(void) {
  ll i, j, k, n, m, a, b, ans = 0;
  scanf("%lld%lld", &n, &m);
  ll h[n];
  bool flg[n];
  for(i = 0; i < n; ++i) scanf("%lld", &h[i]), flg[i] = true;
  for(i = 0; i < m; ++i) {
    scanf("%lld%lld", &a, &b);
    if(h[--a] <= h[--b]) flg[a] = false;
    if(h[a] >= h[b]) flg[b] = false;
  }
  for(i = 0; i < n; ++i) ans += flg[i];
  printf("%lld", ans);
  return 0;
}

Measured memory_bytes: 2608
N,P = map(int,input().split())
A = list(map(int,input().split()))
n0=0
n1=0
for i in range(N):
    if A[i]%2==0:
        n0 += 1
n1 = N-n0
if P==0:
    if n1==0:
        print(2**n0)
    else:
        print(2**(n1-1)*2**n0)
else:
    if n1==0:
        print(0)
    else:
        print(2**(n1-1)*2**n0)

Measured memory_bytes: 61996
#include <bits/stdc++.h>
#define ll long long
#define pll pair<ll, ll>
using namespace std;
const ll maxn = 1e6 + 7;
const ll mod = 1e9 + 7;
const int maxx = 1005;
ll q, t, n, m, k, ans, a[maxn], b[maxn], f[maxx][maxx];
priority_queue<ll> pr;
string s, str;
char ss[maxx][maxx];
map<ll, ll> mp;
void sol()
{
    cin >> n;
    ll mx = 1e16;
    for(int i = 0; i < n; i ++)
    {
        cin >> a[i];
    }
    for(int i = n - 1; i >= 0; i--)
    {
        for(int j = i; j >= 0; j --)
        {
            if(i == n - 1)f[i][j] = (j == 0 ? a[i] : 0);
            else
                f[i][j] = min(a[i] + f[i+1][a[i] > 100 ? j + 1 : j], j > 0 ? f[i+1][j-1] : mx);
        }
    }
    cout << f[0][0];
}
void test()
{
    cin >> s;
    n = s.length();
    s = " "   + s;
    t = (n - 1) / 2;
    for(int i = 1; i <= t / 2; i ++)
    {
        if(s[i] != s[t-i+1])
        {
            cout << "No";
            //cout << i;
            return;
        }
    }
    t = (n + 3) / 2;
    for(int i = t; i <= n; i ++)
    {
        if(s[i] != s[n-i+1])
        {
            cout << "No";
            return;
        }
    }
    for(int i = 1; i <= n / 2; i ++)
    {
        if(s[i] != s[n-i+1])
        {
            cout << "No";
            return;
        }
    }
    cout << "Yes";
}
int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    test();
}


Measured memory_bytes: 256