akhauriyash/Code-Regression huggingface dataset:
#include<stdio.h>
#define N 25
typedef struct{
  int left;
  int right;
  int parent;
}Tree;
Tree n[N];
void preParse(int u){
  printf(" %d",u);
  if(n[u].left!=-1) {preParse(n[u].left);}
  if(n[u].right!=-1)   {preParse(n[u].right);}
}
 
void inParse(int u){
 
  if(n[u].left!=-1)  {inParse(n[u].left);}
  printf(" %d",u);
  if(n[u].right!=-1) {inParse(n[u].right);}
}
 
void postParse(int u){
  if(n[u].left!=-1) {postParse(n[u].left);}
  if(n[u].right!=-1)  {postParse(n[u].right);}
  printf(" %d",u);
}
 
int main(){
  int i,a,id;
  scanf("%d",&a);
  for(i=0;i<a;i++) {n[i].left=n[i].right=n[i].parent=-1;}
 
  for(i=0;i<a;i++){
    scanf("%d",&id);
    scanf("%d",&n[id].left);
    scanf("%d",&n[id].right);
    
    n[n[id].right].parent=id;
    n[n[id].left].parent=id;
  }
   
 
  printf("Preorder\n");
 
  for(i=0;i<a;i++){
 
    if(n[i].parent==-1) {preParse(i);}
 
  }
 
  printf("\n");
 
  printf("Inorder\n");
 
  for(i=0;i<a;i++){
 
    if(n[i].parent==-1) {inParse(i);}
 
  }
 
  printf("\n");
 
 
  printf("Postorder\n");
 
  for(i=0;i<a;i++){
 
    if(n[i].parent==-1) {postParse(i);}
 
  }
 
  printf("\n");
 
  return 0;
}

Measured memory_bytes: 616
import math
from math import gcd
INF = float("inf")

import sys
input=sys.stdin.readline
import itertools
from collections import Counter

def main():
    n,m = map(int, input().split())
    dic = {}
    for i in range(1,n+1):
        dic[i] = 0
    ac = 0
    wa = 0
    for i in range(m):
        p,s = input().split()
        p = int(p)
        if dic[p] == 0: # その問題初めての投稿
            if s == "WA":
                dic[p] += 1
            else:
                dic[p] = "AC"
                ac += 1
        elif dic[p] == "AC":
            pass
        else: # WA状態
            if s == "WA":
                dic[p] += 1
            else:
                wa += dic[p]
                dic[p] = "AC"
                ac += 1
    print(ac,wa)



if __name__=="__main__":
    main()


Measured memory_bytes: 88180
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <map>
#include <cmath>
#include <iomanip>
using namespace std;
#define REP(i,n) for (int i=0;i<(n);++i)
#define rep(i,a,b) for(int i=a;i<(b);++i)
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;}
using ll = long long;
constexpr long long INF = 1LL << 62;
constexpr int MOD = 2019;


int main() {
    cin.tie(0); ios_base::sync_with_stdio(false);
    int n,d;cin>>n>>d;
    int x[11][11];
    REP(i,n) REP(j,d) cin >> x[i][j];

    int cnt = 0;
    for(int i=0; i < n;++i) {
        for(int j=i+1; j < n;++j) {
            int tmp = 0;
            for(int k=0;k<d;++k) {
                tmp += (x[i][k] - x[j][k]) * (x[i][k] - x[j][k]);
            }
            // 1600 * 10
            for(int i = 1; i*i <= 20000; ++i) {
                if(i*i == tmp) {
                    ++cnt;
                    break;
                }
            }
        }
    }
    cout << cnt << '\n';               


    return 0;
}

Measured memory_bytes: 256
#include <random>
#include <vector>
#include <cstdio>
#include <iostream>
#include <tuple>
#include <stdexcept>
#include <map>
#include <set>
#include <algorithm>
#include <cassert>
#include <cmath>
#include <cstring>
#include <deque>
#include <numeric>
#include <unordered_map>
#include <bitset>
#include <queue>

#define pb push_back
#define F first
#define S second
using namespace std;
typedef long long ll;
#define mod LL(1e9 + 7)
#define mp make_pair
#define pb push_back
#define sqr(xx) ((xx)*(xx))

const int sz = 2e6;

ll a[int(2e5) + 20], ans, s[int(2e5) + 20];
int n;

ll f(ll l, ll r) {
    return s[r] - s[l - 1];
}

ll get(ll a, ll b, ll c, ll d) {
    return max({a, b, c, d}) - min({a, b, c, d});
}

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cin >> n;
    for (int i = 1; i <= n; i++) {
        cin >> a[i];
        s[i] = s[i - 1] + a[i];
    }
    ans = 1e18;
    for (int i = 2; i <= n - 2; i++) {
        int l = 1, r = i;
        while (r - l > 1) {
            int m = (l + r) >> 1;
            if (f(1, m - 1) < f(m, i)) {
                l = m;
            } else r = m;
        }

        int p1 = l;

        l = i, r = n;
        while (r - l > 1) {
            int m = (l + r) >> 1;
            if (f(i + 1, m) < f(m + 1, n)) {
                l = m;
            } else r = m;
        }
        int p2 = l;

        for (int j = max(2, p1 - 15); j <= min(i, p1 + 15); j++) {
            for (int c = max(i + 1, p2 - 15); c <= min(n - 1, p2 + 15); c++) {
                ans = min(ans, get(f(1, j - 1), f(j, i), f(i + 1, c), f(c + 1, n)));
            }

        }
    }
    cout << ans;
}


Measured memory_bytes: 3328
import sys
import math


try:
    sys.stdin = open(sys.path[0] + '/input.txt', 'r')
    sys.stdout = open(sys.path[0] + '/output.txt', 'w')
except FileNotFoundError:
    pass


n = int(input())

cnt = 1 + (n // 1000)
print((1000 * cnt - n) % 1000)


Measured memory_bytes: 9052
#!/usr/bin/env python3
#ABC144 E

import sys
import math
from bisect import bisect_right as br
from bisect import bisect_left as bl
sys.setrecursionlimit(1000000)
from heapq import heappush, heappop,heappushpop
from collections import defaultdict
from itertools import accumulate
from collections import Counter
from collections import deque
from operator import itemgetter
from itertools import permutations
from itertools import product
mod = 10**9 + 7
inf = float('inf')
def I(): return int(sys.stdin.readline())
def LI(): return list(map(int,sys.stdin.readline().split()))

def f_x(x):
    s = 0
    for A,F in zip(a,f):
        s += max(0,A - x//F)
    if s <= k:
        return True
    return False


n,k = LI()
a = LI()
f = LI()
a.sort()
f.sort(reverse = True)
ok,ng = 10**12,-1
while ok - ng > 1:
    mid = (ok + ng)//2
    if f_x(mid):
        ok = mid
    else:
        ng = mid
print(ok)

Measured memory_bytes: 106956
#include <cstdio>

int a[33] = {0, 1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51};

int main() {
    int n;
    scanf("%d", &n);
    printf("%d\n", a[n]);
    return 0;
}


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

string divide[4]={"dream", "dreamer", "erase", "eraser"};

int main(){
	string S;
	cin >> S;

	reverse(S.begin(), S.end());
	for(int i=0; i<4; i++) reverse(divide[i].begin(), divide[i].end());
	
	bool can = true;
	for(int i=0; i<S.size();){
		bool can2 = false;
		for(int j=0; j<4; j++){
			string d = divide[j];
			if(S.substr(i, d.size()) == d){
				can2 = true;
				i += d.size();
			}
		}
		if(!can2){
			can = false;
			break;
		}
	}

	if(can) cout << "YES" <<endl;
	else cout << "NO" << endl;
}


Measured memory_bytes: 512
import java.util.*;
class Main{
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt(),t=sc.nextInt(),a=sc.nextInt();
        int[] h = new int[n];
        for(int i = 0;i<n;i++){
            h[i] = sc.nextInt();
        }
        int ans = 0;
        int min = 999999999;
        for(int i = 0;i<n;i++){
            int tmp = 1000*t-6*h[i];
            if(Math.abs(tmp-1000*a)<min){
                min = Math.abs(tmp-1000*a);
                ans = i+1;
            }
        }
        System.out.println(ans);
    }
}

Measured memory_bytes: 24532
#include<bits/stdc++.h>
#define ALL(v) v.begin(), v.end()
// greater<int>()
typedef long long ll;
ll GCD(ll x, ll y) { return y ? GCD(y, x % y) : x; }
ll LCM(ll x, ll y) { return x * y / GCD(x, y); }

using namespace std;
int main() {
	int n;
	cin >> n;
	
	map<string, int> m;

	for (int i = 0; i < n; i++)
	{
		string temp;
		cin >> temp;
		m[temp] += 1;
	}

	bool ans = true;
	for (auto i : m)
	{
		if (i.second > 1) {
			ans = false;
			break;
		}
	}

	if (ans) {
		cout << "YES" << endl;
	}
	else {
		cout << "NO" << endl;

	}



	

}


Measured memory_bytes: 24832
S = list(str(input()))
N = int(input())

top = []
end = []


order = []
state = True

for n in range(N):
    order = input().split()
    if order[0] == '2':
        if (order[1] == '1') == state:
            top.append(order[2])
        else:
            end.append(order[2])
    elif state:
        state = False
    else:
        state = True


if state:
    S = ''.join(S)
    top = ''.join(top[::-1])
    end = ''.join(end)
    out = top + S + end
    
else:
    S = ''.join(S[::-1])
    top = ''.join(top)
    end = ''.join(end[::-1])
    out = end + S + top

print(out)

Measured memory_bytes: 6164
#include <cstdio>
#include <iostream>
#include <string>
#include <vector>
#include <sstream>
#include <map>
#include <set>
#include <queue>
#include <algorithm>
#include <cmath>
#include <cstring>
#include <typeinfo>
#include <numeric>
#include <functional>
#include <unordered_map>
#include <bitset>
#include <stack>


using namespace std;
using ll = long long;
using ull = unsigned long long;

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

#define REP(i, n) for(ll i = 0; i < n; i++)





int main() {
    ll n, a, b, c;
    cin >> n >> a >> b >> c;
    vector<ll> l(n);
    REP(i, n){
        cin >> l[i];
    }
    ll m = round(pow(4, n));
    ll ans = INF;
    REP(i, m){
        ll aa = 0, bb = 0, cc = 0, idx = 0, cnt[4] = {};
        for(ll j = i; j > 0; j /= 4){
            ll t = j % 4;
            if(t == 1){
                aa += l[idx];
                cnt[1]++;
            }
            else if(t == 2){
                bb += l[idx];
                cnt[2]++;
            }
            else if(t == 3){
                cc += l[idx];
                cnt[3]++;
            }
            idx++;
        }
        if(aa == 0 || bb == 0 || cc == 0) continue;
        ll sum = 0;
        sum += 10 * ((cnt[1] - 1) + (cnt[2] - 1) + (cnt[3] - 1));
        sum += abs(aa - a);
        sum += abs(bb - b);
        sum += abs(cc - c);
        ans = min(ans, sum);
    }
    cout << ans << endl;
}


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

int main()
{
    int N,K,X,Y,T,a;
    scanf("%d",&N);
    scanf("%d",&K);
    scanf("%d",&X);
    scanf("%d",&Y);
    if(N<=K)
    {
        T=X*N;
        printf("%d",T);
    }
    else
    {
        a=N-K;
        T=K*X+a*Y;
        printf("%d",T);
    }
    return 0;
}


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

using namespace std;

constexpr size_t MAX_INTSTRING = 50;

struct IntString{
	string str;
  
  	IntString(){
      	str.resize(MAX_INTSTRING + 1);
		for(int i = 0; i < MAX_INTSTRING; ++ i)
			str[i] = '0';
    }
  
  	IntString operator+(IntString& src) const {
      	IntString result;
      
      	bool doKuriage = false;
     	for(int i = MAX_INTSTRING - 1; i >= 0; -- i) {
          char temp = str[i] + src.str[i] - '0'*2 + (doKuriage)? 1 : 0;
          if(temp > 9){
            temp -= 10;
            doKuriage = true;
          }
          else
            doKuriage = false;

          result.str[i] = temp + '0';
        }
      
      	return result;
    }
  
  	IntString& operator+=(IntString& src){
      	return *this = *this + src;
    }
  
  	char& operator[](size_t i){return str[i];}
};

struct Shop {
	long long value;
	int max;
  
	bool operator<(Shop& src)
	{
      	return value < src.value;
	}
};

int main(){
	int nShop, nDrink;
  	cin >> nShop >> nDrink;
  
  	vector<Shop> aShop(nShop);
  	for(int i = 0; i < nShop; ++ i){
    	cin >> aShop[i].value; 
    	cin >> aShop[i].max;
    }
  
  	sort(aShop.begin(), aShop.end());
  
  	auto Itr = aShop.begin();
  	long long result = 0;
  	while(nDrink > 0){
    	int nBuy = (nDrink >= Itr->max)? Itr->max : nDrink;
      	while(nBuy-- > 0){
        	result += Itr->value;
        	--nDrink;
        }
      	
    	++Itr;
    }
  
  	cout << result << endl;
  
	return 0; 
}


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

using ll = long long;
using ull = unsigned long long;
using st = string;
using db = double;
using vll = vector<long long>;
using vvll = vector<vll>;
using vchar = vector<char>;
#define rep(i, m, n) for (int i = (int)(m); i < (int)(n); i++)
#define vrep(vec) for(auto& i : vec)
#define vin(vec) for(auto& i : vec) cin >> i
#define all(v) v.begin(), v.end()
ll mod = 1000000007;

int main(){
  ll n;
  cin >> n;
  vll a(n);
  vin(a);
  
  bool candev = 1;
  vrep(a) if(i % 2 == 1) candev = 0;
  ll ans = 0;
  while(candev){
    ans++;
    vrep(a) i /= 2;
    vrep(a) if(i % 2 == 1) candev = 0;
  }
  cout << ans << endl;
}

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

using namespace std;

int main() {
  int N, K;
  int R, S, P;
  cin >> N >> K >> R >> S >> P;
  string T;
  cin >> T;
  vector<bool> win(N);
  int ans = 0;
  for (int i = 0; i <= N / K; i++) {
    for (int j = 0; j < K; j++) {
      int k = i * K + j;
      if (k >= N) {
        break;
      }
      if (k - K < 0 || T[k] != T[k - K] || !win[k - K]) {
        win[k] = true;
        if (T[k] == 'r') {
          ans += P;
        } else if (T[k] == 's') {
          ans += R;
        } else if (T[k] == 'p') {
          ans += S;
        }
      }
    }
  }
  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int N;
  cin >> N;
  
  vector<int> A(N);
 
  for (int i = 0; i < N; i++) {
    cin >> A.at(i);
  }
  vector<int> B(N);
 
  for (int i = 0; i < N; i++) {
    cin >> B.at(i);
  }
  vector<int> C(N-1);
 
  for (int i = 0; i < N-1; i++) {
    cin >> C.at(i);
  }
  int sum = 0;
  for (int i = 0; i< N; i++){
    sum += B.at(i);
  }
   
  for (int i = 0; i< N-1; i++){
     if(A.at(i)+1 == A.at(i+1)){
       sum += C.at(A.at(i)-1);
     }
  }
   
   
		
  cout << sum << endl;
 
}

Measured memory_bytes: 256
S = input()

t = 0
if len(S) % 2 == 0:
    for i in range(len(S) // 2):
        if S[i] == S[len(S) - i -1]:
            t = t
        else:
            t += 1
else:
    for i in range(len(S) // 2):
        if S[i] == S[len(S) - i -1]:
            t = t
        else:
            t += 1
print(t)

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

// {U}{INT,LONG,LLONG}_{MAX,MIN}
#define INF         INT_MAX/3
#define MOD         (1000000007LL)
#define inc(i, l, r)   for(long long i=(l);i<(r);i++)
#define dec(i, l, r)   for(long long i=(r)-1;i>=(l);i--)
#define se          second
#define fi          first

using LL  = long long;

int di[] = {0, -1, 0, 1};
int dj[] = {1, 0, -1, 0};
// }}}

int main() {
    std::ios::sync_with_stdio(false);
    int n;cin >> n;
    int a, b;cin >> a >> b;
    if((b-a)%2==0){
        cout << "Alice" << endl;
    }else{
        cout << "Borys" << endl;
    }
    return 0;
}


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

const i64 MOD = 1e9 + 7;

int main()
{
  i64 n;
  cin >> n;
  vector<i64> p(n);
  for (i64 i = 0; i < n; i++)
    cin >> p[i];
  set<i64> d;
  for (i64 i = 1; i < (1LL << n); i++)
  {
    i64 g = -1;
    for (i64 j = 0; j < n; j++)
      if (i & (1 << j))
      {
        if (g == -1)
          g = p[j];
        else
          g = g * p[j] / __gcd(g, p[j]);
      }
    d.insert(g);
  }
  cout << d.size() << endl;
  return 0;
}


Measured memory_bytes: 4000
#include <cstdio>

int main(){
    int a, b, c, k; scanf("%d%d%d%d", &a, &b, &c, &k);
    int cnt = 0;
    while (b <= a){
        b *= 2;
        cnt++;
    }
    while (c <= b){
        c *= 2;
        cnt++;
    }
    if (cnt <= k) puts("Yes");
    else puts("No");

    return 0;
}


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

int main(){
  string s;
  int k;
  std::cin >> s >> k;
  for (int i = 0; i < s.length(); i++) {
    if(26 - s[i] + 'a' <= k and s[i] != 'a'){
      k -= 26 - s[i] + 'a';
      s[i] = 'a';
    }
  }
  s[s.length() - 1] += (k%26);
  std::cout << s << std::endl;
  return 0;
}


Measured memory_bytes: 512
#include <bits/stdc++.h>
const int INF = 1e9;
const int MOD = 1e9+7;
const long long LINF = 1e18;
#define dump(x)  cout << 'x' << ' = ' << (x) << ` `;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n) for(int i=0;i<(n);++i)
#define REPR(i,n) for(int i=n;i>=0;i--)
#define FOREACH(x,a) for(auto& (x) : (a) )
typedef long long ll;
using namespace std;
typedef pair<ll, ll> P;

int main(int argc, char const *argv[]) {
    int k,x; cin>>k>>x;
    set<int> st;
    for (int i = x; i < x+k; ++i) st.insert(i);
    for (int i = x; i > x-k; --i) st.insert(i);
    for (auto &&e: st) {
        cout<<e<<" ";
    }
    cout<<endl;
    return 0;
}

Measured memory_bytes: 256
n = gets.to_i
as,bs = n.times.map{gets.chomp.split.map(&:to_i)}.transpose
as.sort!
bs.sort!
if n % 2 == 0
	ma = as[n/2] + as[n/2-1]
	mb = bs[n/2] + bs[n/2-1]
else
	ma = as[n/2]
	mb = bs[n/2]
end

puts mb - ma + 1

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

#define TYPE(c)   remove_reference_t<decltype(c)>
#define REP(i, n) for(TYPE(n) i = 0; i < n; i++)
#define FOR(v, c) for(TYPE(c.begin()) v = c.begin(); v != c.end(); v++)
#define ALL(c)    c.begin(), c.end()
#define SORT(c)   sort(ALL(c))
#define RSORT(c)  sort(ALL(c), greater<TYPE(c)::value_type>())
#define UNIQUE(c) c.erase(unique(ALL(c)), c.end())

using namespace std;
using ll = long long;

constexpr int MOD  = (int)1e9 + 7;
constexpr int INF  = (int)1e9 + 1;
constexpr ll  LINF = (ll)1e18 + 1;
template<typename T> constexpr bool chmax(T& a, const T& b)
{ if(a < b) { a = b; return true; } else { return false; } }
template<typename T> constexpr bool chmin(T& a, const T& b)
{ if(b < a) { a = b; return true; } else { return false; } }
template<typename S, typename T> ostream& operator<<(ostream &os, const pair<S, T>& p)
{ return os << "(" << p.first << "," << p.second << ")"; }
ostream& operator<<(ostream &os, const string& s)
{ FOR(v, s) os << *v; return os; }
template<typename T> auto operator<<(ostream& os, const T& t)
  -> typename conditional<true, ostream&, decltype(*t.begin())>::type
{ os << "["; FOR(v, t) { if(v != t.begin()) os << ","; os << *v; } os << "]"; return os; }

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

  int K;
  std::cin >> K;
  std::vector<int> dp(K + 1, 0);
  int ans = -1;
  REP(i, K + 1) {
    dp[i] = dp[i] * 10 + 7;
    dp[i + 1] = dp[i] % K;
    if(dp[i + 1] == 0) {
      ans = i + 1;
      break;
    }
  }
  std::cout << ans << std::endl;

  return 0;
}


Measured memory_bytes: 7140
x, y = map(int,input().split())
A = [1,3,5,7,8,10,12]
B = [4,6,9,11]
C = [2]

if(((x in A)and(y in A)) or ((x in B)and(y in B)) or (x == 2 and y == 2)):
  print("Yes")
else:
  print("No")

Measured memory_bytes: 3060
//
// Created by yamunaku on 2020/08/09.
//

#include <bits/stdc++.h>

using namespace std;

#define rep(i, n) for(int i = 0; i < (n); i++)
#define repl(i, l, r) for(int i = (l); i < (r); i++)
#define per(i, n) for(int i = ((n)-1); i >= 0; i--)
#define perl(i, l, r) for(int i = ((r)-1); i >= (l); i--)
#define all(x) (x).begin(),(x).end()
#define MOD9 998244353
#define MOD1 1000000007
#define IINF 1000000000
#define LINF 1000000000000000000
#define SP <<" "<<
#define CYES cout<<"Yes"<<endl
#define CNO cout<<"No"<<endl
#define CFS cin.tie(0);ios::sync_with_stdio(false)
#define CST(x) cout<<fixed<<setprecision(x)

using ll = long long;
using ld = long double;
using vi = vector<int>;
using mti = vector<vector<int>>;
using vl = vector<ll>;
using mtl = vector<vector<ll>>;
using pi = pair<int, int>;
using pl = pair<ll, ll>;
template<typename T>
using heap = priority_queue<T, vector<T>, function<bool(const T, const T)>>;

vector<string> vs;

void pls(int l, int m, int d){
    vs.push_back("+ " + to_string(m) + " " + to_string(d) + " " + to_string(l));
}

void smt(int l, int m, int d){
    vs.push_back("< " + to_string(m) + " " + to_string(d) + " " + to_string(l));
}

int main(){
    //CFS;
    vector<int> a(30, 0), b(30, 0), c(30, 0);
    rep(i, 30) a[i] = i;
    rep(i, 30) b[i] = 10000 + i;
    rep(i, 30) c[i] = 20000 + i;
    pls(a[3], a[0], a[1]);
    smt(b[0], b[0], a[3]);
    repl(i, 1, 30) pls(b[i], b[i - 1], b[i - 1]);
    repl(i, 1, 30) pls(c[i], c[i - 1], b[i - 1]);
    smt(a[3], a[3], a[3]);
    per(i, 30){
        pls(a[4], a[3], c[i]);
        smt(a[4], a[4], a[0]);
        smt(a[5], a[5], a[5]);
        per(j, 30){
            pls(a[6], a[5], c[j]);
            smt(a[6], a[6], a[1]);
            pls(a[7], a[4], a[6]);
            smt(a[7], b[0], a[7]);
            rep(t, i + j){
                pls(a[7], a[7], a[7]);
            }
            pls(a[2], a[2], a[7]);
            rep(t, j){
                pls(a[6], a[6], a[6]);
            }
            pls(a[5], a[5], a[6]);
        }
        rep(t, i){
            pls(a[4], a[4], a[4]);
        }
        pls(a[3], a[3], a[4]);
    }
    cout << vs.size() << endl;
    for(auto &s : vs){
        cout << s << endl;
    }
    return 0;
}

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

int main(void) {
  int h, w;
  cin >> h >> w;
  vector<string> grid(h);
  rep (i, h) {
    cin >> grid[i];
    grid[i] = grid[i] + '#';
  }
  string tmp_s = "";
  rep (i, 2005) tmp_s += '#';
  grid.push_back(tmp_s);


  vector<vector<int>> countH(h + 5, vector<int>(w + 5, 0)),
                      countW(h + 5, vector<int>(w + 5, 0));

  for (int i = 0; i < h; i++) {
    int cnt = 0;
    for (int j = 0; j <= w; j++) {
      if (grid[i][j] == '#') {
        for (int k = 1; k <= cnt; k++) {
          countH[i][j - k] = cnt;
        }
        cnt = 0;
        continue;
      }
      cnt++;
    }
  }

  for (int i = 0; i < w; i++) {
    int cnt = 0;
    for (int j = 0; j <= h; j++) {
      if (grid[j][i] == '#') {
        for (int k = 1; k <= cnt; k++) {
          countW[j - k][i] = cnt;
        }
        cnt = 0;
        continue;
      }
      cnt++;
    }
  }
  
  int ans = 0;
  rep (i, h) rep (j, w) {
    ans = max(ans, countH[i][j] + countW[i][j]);
  }
  
  cout << ans - 1 << endl;
  return 0;
}

Measured memory_bytes: 35840
import math
mod = 10 ** 9 + 7

def f(num):
    i = 2
    d = dict()
    while i ** 2 <= num:
        if num % i == 0:
            num //= i
            d[i] = d.get(i, 0) + 1
        else:
            i += 1
    d[num] = 1
    return d

n = int(input())

if n == 1:
    print(1)
    exit()

ans = 1
for i in f(math.factorial(n)).values():
    ans *= i+1

print(ans%mod)

Measured memory_bytes: 3064
#include<cstdio>
#include<algorithm>
using namespace std;
#define MAXN 100010
#define MAXM 200010
#define INF 1000000000
int Adj[MAXN],V[MAXM],nxt[MAXM],c;
void AddEdge(int u,int v)
{
	c++;V[c]=v,nxt[c]=Adj[u];
	Adj[u]=c;
}
int L[MAXN],R[MAXN],root,odd[MAXN];
void dfs1(int u,int p)
{
	for(int i=Adj[u];i;i=nxt[i])
	{
		int v=V[i];
		if(v==p) continue;
		dfs1(v,u);
		R[u]=min(R[v]+1,R[u]);
		L[u]=max(L[v]-1,L[u]);
		if(odd[v]!=-1)
		{
			if(odd[u]==-1) odd[u]=!odd[v];
			else if(odd[v]==odd[u])
			{
				printf("No\n");
				exit(0);
			}
		}
	}
}
void dfs2(int u,int p)
{
	if(p)
	{
		R[u]=min(R[u],R[p]+1);
		L[u]=max(L[u],L[p]-1);
		if(odd[u]==-1) odd[u]=!odd[p];
	}
	if(L[u]>R[u]||(L[u]==R[u]&&odd[u]!=(L[u]&1)))
	{
		printf("No\n");
		exit(0);
	}
	for(int i=Adj[u];i;i=nxt[i])
		if(V[i]!=p)
		{
			dfs2(V[i],u);
		}
}
int ans[MAXN];
void GetAns(int u,int p)
{
	if(!p) ans[u]=L[u];
	else
	{
		ans[u]=ans[p]-1;
		if(ans[u]<L[u]) ans[u]+=2;
	}
	for(int i=Adj[u];i;i=nxt[i])
		if(V[i]!=p)
			GetAns(V[i],u);
}
int main()
{
	int n,m,u,v;
	scanf("%d",&n);
	for(int i=1;i<n;i++)
	{
		scanf("%d%d",&u,&v);
		AddEdge(u,v);
		AddEdge(v,u);
	}
	for(int i=1;i<=n;i++)
		L[i]=-INF,R[i]=INF,odd[i]=-1;
	scanf("%d",&m);
	for(int i=0;i<m;i++)
	{
		scanf("%d%d",&u,&v);
		root=u;
		odd[u]=(v&1);
		L[u]=R[u]=v;
	}
	dfs1(root,0);
	dfs2(root,0);
	GetAns(root,0);
	printf("Yes\n");
	for(int i=1;i<=n;i++)
		printf("%d\n",ans[i]);
}

Measured memory_bytes: 9088
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)*}
    };
}

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

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

fn main(){

    input!{
        n: usize,
        p: [usize;n],
    }

    let mut cnt = 0;
    let mut min = n;

    for i in 0..n {
        if min >= p[i] {
            cnt += 1;
            min = p[i];
        }
    } 

    println!("{}", cnt);

}

Measured memory_bytes: 6396
#include <stdio.h>

int main(void)
{
  int K, N;
  scanf("%d %d", &K, &N);
  
  int A[N];
  int i;
  for(i=0; i<N; i++){
    scanf("%d", &A[i]);
  }
  
  int mx = 0;
  for(i=0; i<N-1; i++){
    if(mx < A[i+1] - A[i])
      mx = A[i+1] - A[i];
  }
  if(mx < A[0] + K - A[N-1])
    mx = A[0] + K - A[N-1];
  
  printf("%d", K - mx);
  
  return 0;
}

Measured memory_bytes: 896
#include <stdio.h>
#include <math.h>
int main(){
	int i,n;
	double x1,x2,x3,y1,y2,y3,a,b,c,d,e,f,r;
	scanf("%d",&n);
	for (i=0; i<n; i++) {
		scanf("%lf%lf%lf%lf%lf%lf",&x1,&y1,&x2,&y2,&x3,&y3);
		a=x2-x1;
		b=y2-y1;
		c=(x2*x2-x1*x1+y2*y2-y1*y1)/2.0;
		d=x3-x2;
		e=y3-y2;
		f=(x3*x3-x2*x2+y3*y3-y2*y2)/2.0;
        x1=(e*c-b*f)/(a*e-b*d);
        y1=(d*c-a*f)/(d*b-a*e);
		r=sqrt((x1-x2)*(x1-x2)+(y1-y2)*(y1-y2));
		printf("%.3f %.3f %.3f\n",x1,y1,r);
	}
	return 0;
}

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

int main(void){
    int a = 0, b = 0; 
    int ans = 0;

    scanf("%d%d", &a, &b);

    for(int i = a; i <= b; i++){
        if(i % 10 == i / 10000 && i /1000 % 10 == i /10 % 10){
            ans++;
        }
    }

    printf("%d\n", ans);
    return 0;

} 


Measured memory_bytes: 256
use std::io::*;
use std::sync::Mutex;

pub struct Scanner {
    source: Mutex<Bytes<BufReader<Stdin>>>,
}

impl Scanner {
    pub fn new() -> Scanner {
        Scanner {
            source: Mutex::new(Read::bytes(BufReader::new(stdin()))),
        }
    }
    pub fn source(&mut self) -> &Mutex<Bytes<BufReader<Stdin>>> {
        return &self.source;
    }
}

#[allow(unused_macros)]
macro_rules! rin {
    ( from $scanner:ident, $( $rep:tt )* ) => {
        let mut locked_stdin = $scanner.source().lock().unwrap();
        #[allow(unused_mut)]
        let mut buf = move || -> String {
            locked_stdin
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        rin_parse!{buf, $($rep)*}
        drop(buf);
    };
}

#[allow(unused_macros)]
macro_rules! rin_parse {
    ( $buf:expr ) => {};
    ( $buf:expr, ) => {};
    ( $buf:expr, $type:tt : $var:tt, $($r:tt)* ) => {
        rin_read!($buf, $type, $var, false);
        rin_parse!($buf, $($r)*);
    };
    ( $buf:expr, mut $type:tt : $var:tt, $($r:tt)* ) => {
        rin_read!($buf, $type, $var, true);
        rin_parse!($buf, $($r)*);
    };
}

#[allow(unused_macros)]
macro_rules! rin_read {
    ( $buf:expr, $type:tt, $var:ident, false ) => {
        let $var = read_value!($buf, $type);
    };
    ( $buf:expr, $type:tt, [$($var:ident),*], false ) => {
        $( let $var = read_value!($buf, $type); )*
    };

    ( $buf:expr, $type:tt, $var:ident, true ) => {
        let mut $var = read_value!($buf, $type);
    };
    ( $buf:expr, $type:tt, [$($r:tt)*], true ) => {
        $( let mut $var = read_value!($buf, $type); )*
    };
}

#[allow(unused_macros)]
macro_rules! read_value {
    ( $next:expr, ( $($t:tt),* ) ) => {
        ( $(read_value!($next, $t)),* )
    };
    ( $next:expr, [ $t:tt ; [$d1:expr, $d2:expr] ] ) => {
        (0..$d1).map(|_| read_value!($next, [$t; $d2])).collect::<Vec<_>>()
    };
    ( $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")
    };
}

// main function

fn main() {
    let mut sc : Scanner = Scanner::new();
    let t = 1;
    // rin!( from sc, usize : t, );
    for _ in 0..t { solve(&mut sc); }
}

fn solve(sc: &mut Scanner) {
    let out = stdout();
    let mut out = BufWriter::new(out.lock());

    rin! {
        from sc,
        usize : n,
        mut [i64; n] : a,
    }
    a.sort();
    a.reverse();

    let mut ans : i64 = 0;
    for i in 1..n {
        ans += a[i/2]
    }

    write!(out, "{}\n", ans).ok();
}

Measured memory_bytes: 4428
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
 
int main(){
  string a, b, c;
  cin >> a >> b >> c;
  if(a.at(a.size()-1)==b.at(0)&&b.at(b.size()-1)==c.at(0))cout<<"YES"<<endl;
  else{cout <<"NO" << endl;}
  return 0;
}

Measured memory_bytes: 256
n = gets.to_i
$c = Array.new(n){ Array.new }
n.times do |i|
  a = gets.split.map(&:to_i)[1..-1]
  a.each{ |j| $c[i] << j }
end
$depth = Array.new(n)
$max = (Math.log(n) / Math.log(2)).ceil
$dp = Array.new(n){ Array.new($max) }

def bfs
  arr = Array.new
  arr << [0,-1,0]
  while not arr.empty?
    a,pre,dep = arr.shift
    $depth[a] = dep
    $dp[a][0] = pre
    (1...$max).each do |i|
      if $dp[a][i-1] != -1 then $dp[a][i] = $dp[$dp[a][i-1]][i-1]
      else $dp[a][i] = -1
      end
    end
    $c[a].each do |i|
      next if i == pre
      arr << [i, a, dep+1]
    end
  end
end

def lca(a, b)
  if $depth[a] > $depth[b] then a, b = b, a 
  end
  dh = $depth[b] - $depth[a]
  i = 0
  while (1 << i) <= dh
    if (dh>>i) % 2 == 1 then b = $dp[b][i]
    end
    i += 1
  end
  return a if a == b
  ret = -1
  ($max-1).downto(0) do |i|
    if $dp[a][i] == $dp[b][i] then ret = $dp[a][i]
    else
      a = $dp[a][i]
      b = $dp[b][i]
    end
  end
  return ret
end

bfs
q = gets.to_i
q.times do
  a, b = gets.split.map(&:to_i)
  p lca(a,b)
end

Measured memory_bytes: 54388
#include <iostream>

using namespace std;

int main(void) {

	int a, b, c, d, e, k;

	cin >> a >> b >> c >> d >> e >> k;

	if (e - a > k) {
		cout << ":(" << endl;
	}
	else {
		cout << "Yay!" << endl;
	}

	//system("pause");
	return 0;
}

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

using ll=long long;
const long long LINF=1e13;

typedef pair<ll,ll> P;
typedef pair<P,ll> PI;
map<PI,ll> m;
#define THAT PI(P(A,B),bit)

ll a,b,sum;

ll solve(ll A,ll B,ll bit){
  if(B>=LINF)return LINF;
  if(!bit)return 0;
  if(m.count(THAT))return m[THAT];
  ll move=0,A2,B2=LINF;
  if((sum^A^B)&bit){//A^Bのbitとsumのbitが一致していない
    if(sum&bit){//sumのbitが立ってる時
      if(B&bit)move=A-bit+1;//両方立ってる時はAのbitが消えるまで動かす
      else move=bit-B;//両方立ってない時はBのbitが立つまで動かす
    }
    else{//sumのbitが立ってない時
      if(B&bit)return LINF;//Bのbitだけ立ってたらお手上げ
      move=min(A-bit+1,bit-B);//Aのbitだけ立ってる時はAのbitが消えるかBのbitが立つかまで動かす
    }
  }
  else{//A^Bのbitとsumのbitが一致しているので一見手を加えなくてもいい
    if((sum&bit)&&(A&bit)){//sumのbitが立っててAのbitだけ立ってる
      A2=A&~bit,B2=B&~bit;//動かさないパターン
      move=max(A-bit+1,bit-B);//Aのbitを消してBのbitを立てるパターン (A,B,sum)=(8,6,8)とかで使う
    }
  }
  if(B+move>=bit*2||(sum^(A-move)^(B+move))&bit)move=LINF;//moveがうまく行ってない場合
  return m[THAT]=min(move+solve((A-move)&~bit,(B+move)&~bit,bit>>1),solve(A2,B2,bit>>1));
}

int main(){
  int n;cin>>n;
  cin>>a>>b;
  for(int i=2;i<n;i++){ll tmp;cin>>tmp;sum^=tmp;}
  ll ans=solve(a,b,1LL<<40);
  if(ans>=a)ans=-1;
  cout<<ans<<endl;
}


Measured memory_bytes: 3604
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<functional>
#include<map>
#include<cmath>
#include<iomanip>

using namespace std;

typedef long long ll;

int gcd(int a, int b){
 if(a < b) return gcd(b, a);

 if(b == 0) return a;
 else return gcd(b, a % b);
}

int main()
{
  int N, X; cin >> N >> X;
  vector<int> x(N);
  for(int i = 0; i < N; i++) cin >> x[i];
  
  int d = 0;
  for (int i = 0; i < N; i++)
  {
    d = gcd(d, abs(X - x[i]));
  }
  
  cout << d << endl;
}


Measured memory_bytes: 640
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.UncheckedIOException;
import java.util.Arrays;
import java.util.Comparator;
import java.util.Stack;
import java.util.StringTokenizer;

class sushi {
	public int t;
	public long d;

	public sushi(int t, long d) {
		this.t = t;
		this.d = d;
	}

	public long getD() {
		return this.d;	//美味しさを返す
	}
}

public class Main {

	static SC sc=new SC(System.in);
	static Stack<Long> st = new Stack<Long>();
	static int N = sc.nextInt();
	static int K = sc.nextInt();
	static sushi[] S = new sushi[N];
	static boolean[] used = new boolean[N + 1];
	static long sum_t = 0;
	static long sum_d = 0;
	static long ans = 0;

	public static void main(String[] args) {
		for(int i = 0; i < N; i++) {
			int t = sc.nextInt();	//種類
			long d = sc.nextLong();	//美味しさ
			sushi su = new sushi(t, d);  //sushi型
			S[i] = su;		//sushiの配列に追加
		}
		show();
		Arrays.sort(S, Comparator.comparing(sushi::getD).reversed());		//美味しさの順にソートする
		for(int i = 0; i < K; i++) {
			if(used[S[i].t]) {		//新たな種類じゃないやつ
				st.push(S[i].d);
			} else {
				used[S[i].t] = true;
				sum_t++;
			}
			sum_d += S[i].d;
		}
		ans = sum_d + sum_t * sum_t;

		for(int i = K; i < N; i++) {
			if(st.empty())
				break;
			if(used[S[i].t])
				continue;
			used[S[i].t] = true;	//新しいのが出たら最も小さいものと比較
			sum_t++;
			sum_d += S[i].d - (long) st.pop();
			ans = Math.max(ans, sum_d + sum_t * sum_t);
		}

		pl(ans);
	}
	public static void pl(Object o) {
		System.out.println(o);
	}
	public static void pl() {
		System.out.println();
	}
	public static void p(Object o) {
		System.out.print(o);
	}
	static class SC {
		private BufferedReader reader = null;
		private StringTokenizer tokenizer = null;
		public SC(InputStream in) {
			reader = new BufferedReader(new InputStreamReader(in));
		}
		public String next() {
			if (tokenizer == null || !tokenizer.hasMoreTokens()) {
				try {
					tokenizer = new StringTokenizer(reader.readLine());
				} catch (IOException e) {
					throw new UncheckedIOException(e);
				}
			}
			return tokenizer.nextToken();
		}
		public int nextInt() {
			return Integer.parseInt(next());
		}
		public long nextLong() {
			return Long.parseLong(next());
		}
		public double nextDouble() {
			return Double.parseDouble(next());
		}
		public String nextLine() {
			try {
				return reader.readLine();
			} catch (IOException e) {
				throw new UncheckedIOException(e);
			}
		}
	}
	public static void show() {
		for(int i=0; i<=N; i++) {
			//pl(used[i]);
		}
	}
}


Measured memory_bytes: 67584
#include<bits/stdc++.h>
using namespace std;
#define fs first
#define sc second
#define pb push_back
#define mp make_pair
#define eb emplace_back
#define ALL(A) A.begin(),A.end()
#define RALL(A) A.rbegin(),A.rend()
typedef long long LL;
typedef pair<LL,LL> P;
const LL mod=1000000007;
const LL LINF=1LL<<60;
const int INF=1<<30;
int dx[]={1,0,-1,0};
int dy[]={0,1,0,-1};


int main(){
    int n,i;cin >> n >> i;
    cout << n - i + 1 << endl;
    return 0;
}


Measured memory_bytes: 256
n = int(input())
ab = []
for i in range(n):
    a, b = map(int, input().split())
    ab.append([a, b])

sum = 0
ab.sort(key=lambda x: x[1])
for i in range(n):
    sum += ab[i][0]
    if sum > ab[i][1]:
        print("No")
        exit()
print("Yes")

Measured memory_bytes: 38044
class UnionFind():
    def __init__(self, n):
        self.n = n
        self.parents = [-1] * n

    def find(self, x):
        if self.parents[x] < 0:
            return x
        else:
            self.parents[x] = self.find(self.parents[x])
            return self.parents[x]

    def union(self, x, y):
        x = self.find(x)
        y = self.find(y)

        if x == y:
            return

        if self.parents[x] > self.parents[y]:
            x, y = y, x

        self.parents[x] += self.parents[y]
        self.parents[y] = x

    def size(self, x):
        return -self.parents[self.find(x)]

    def same(self, x, y):
        return self.find(x) == self.find(y)

    def members(self, x):
        root = self.find(x)
        return [i for i in range(self.n) if self.find(i) == root]

    def roots(self):
        return [i for i, x in enumerate(self.parents) if x < 0]

    def group_count(self):
        return len(self.roots())

    def all_group_members(self):
        return {r: self.members(r) for r in self.roots()}

    def __str__(self):
        return '\n'.join('{}: {}'.format(r,self.members(r)) for r in self.roots())
N,K,L = map(int,input().split())
ufK = UnionFind(N)
ufL = UnionFind(N)
ans = [1]*(N)
for i in range(K):
    p,q = map(int,input().split())
    ufK.union(p-1,q-1)
for i in range(L):
    r,s = map(int,input().split())
    ufL.union(r-1,s-1)
from collections import defaultdict
ar=[(ufK.find(i),ufL.find(i)) for i in range(N)]
dic=defaultdict(int)
 
for i in ar:
    dic[i]+=1
ans=[]
for i in range(N):
    ans.append(dic[ar[i]])
print(*ans)

Measured memory_bytes: 45876
#include <iostream>
#include <string>
#include <array>
#include <vector>
#include <queue>
#include <stack>
#include <list>
#include <set>
#include <map>
#include <algorithm>
#include <cmath>
#include <iomanip>

#define FOR(i, a, b) for(decltype(b) i = (a); i < (b); ++i)
#define REP(i, n) FOR(i, 0, n)

typedef long long ll;
typedef unsigned long long ull;
typedef unsigned int uint;

using namespace std;

#ifdef INPUT
#include <sstream>
stringstream input(R"(
31 10
)");
#define cin input
#endif

int main()
{
	int a, b, q;
	cin >> a >> b >> q;

    vector<ll> s(a), t(b);

    for (ll& i : s)
        cin >> i;

    for (ll& i : t)
        cin >> i;

    vector<ll> ds(a), dt(b);

    for (int i = 0, j = 0; i < a; ++i)
    {
        ds[i] = abs(s[i] - t[j]);
        do
        {
            if (++j >= b)
                break;
            ds[i] = min(ds[i], abs(s[i] - t[j]));
        } while (t[j] < s[i]);
        --j;
    }

    for (int i = 0, j = 0; j < b; ++j)
    {
        dt[j] = abs(s[i] - t[j]);
        do
        {
            if (++i >= a)
                break;
            dt[j] = min(dt[j], abs(s[i] - t[j]));
        } while (t[j] > s[i]);
        --i;
    }

    REP (i, q)
    {
        ll x;
        cin >> x;
        auto is = lower_bound(s.begin(), s.end(), x);
        auto it = lower_bound(t.begin(), t.end(), x);
        ll r = 1ll << 62;
        if (is != s.end())
            r = min(r, ds[is - s.begin()] + abs(x - *is));
        if (it != t.end())
            r = min(r, dt[it - t.begin()] + abs(x - *it));
        if (is != s.begin())
            --is, r = min(r, ds[is - s.begin()] + abs(x - *is));
        if (it != t.begin())
            --it, r = min(r, dt[it - t.begin()] + abs(x - *it));

        cout << r << endl;
    }

	return 0;
}


Measured memory_bytes: 4480
S = input()

ans = 'AC'
c = 0

for i, s in enumerate(S):
    if i == 0:
        if s != 'A':
            ans = 'WA'
    elif i == 1:
        if s.isupper():
            ans = 'WA'
    elif i > 1 and i < len(S) - 1:
        if s == 'C':
            c += 1
        elif s.isupper():
            ans = 'WA'
    else:
        if s.isupper():
            ans = 'WA'

if c != 1:
    ans = 'WA'

print(ans)

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

int main() {
    int n,count=0;
    cin>>n;
    vector<int> p(n);
    rep(i,n) cin>>p.at(i);
    string ans="NO";
    rep(i,n) {
        if (p[i] != i+1) count++;
    }
    if (count <= 2) ans="YES";

    cout<<ans<<endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, a, b) for (int i = a; i < (int)b; i++)
#define all(v) v.begin(), v.end()
const int MOD = 1e9 + 7;
const int INF = 1e9;
//'A' = 65, 'Z' = 90, 'a' = 97, 'z' = 122

int main() {
    int n;
    cin >> n;
    int a[n][n - 1];
    int gamenum = n * (n - 1) / 2;
    vector<vector<int>> g(gamenum);
    map<pair<int, int>, int> mp;
    int cnt = 0;
    rep(i, 0, n) {
        rep(j, 0, n - 1) {
            cin >> a[i][j];
            a[i][j]--;
            int mn = min(i, a[i][j]);
            int mx = max(i, a[i][j]);
            if (mp.find(make_pair(mn, mx)) == mp.end()) {
                mp[make_pair(mn, mx)] = cnt;
                cnt++;
            }
        }
    }
    rep(i, 0, n) {
        rep(j, 0, n - 2) {
            int from = mp[make_pair(min(i, a[i][j]), max(i, a[i][j]))];
            int to = mp[make_pair(min(i, a[i][j + 1]), max(i, a[i][j + 1]))];
            g[from].push_back(to);
        }
    }

    int in[gamenum] = {};
    rep(i, 0, gamenum) {
        rep(j, 0, g[i].size()) {
            in[g[i][j]]++;
        }
    }

    vector<int> dist(gamenum, 1);
    vector<int> order;
    queue<int> que;
    rep(i, 0, gamenum) if (in[i] == 0) {
        que.push(i);
        order.push_back(i);
    }
    while (!que.empty()) {
        int v = que.front();
        que.pop();
        for (int nv : g[v]) {
            in[nv]--;
            if (in[nv] == 0) {
                que.push(nv);
                order.push_back(v);
                dist[nv] = max(dist[nv], dist[v] + 1);
            }
        }
    }

    int ans = 0;
    rep(i ,0, gamenum) ans = max(ans, dist[i]);
    if ((int)order.size() != gamenum) {
        cout << -1 << endl;
    } else {
        cout << ans << endl;
    }
    return 0;
}


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

int main(){
  int dx,dy;
  vector<int> x(4,0),y(4,0);REP(i,2) cin>>x.at(i)>>y.at(i);
  dx=x.at(1)-x.at(0);dy=y.at(1)-y.at(0);
  cout<<x.at(1)-dy<<" "<<y.at(1)+dx<<" "<<x.at(1)-dy-dx<<" "<<y.at(1)+dx-dy;
}

Measured memory_bytes: 256
#include <iostream>
#include <sstream>
#include <cmath>
#include <algorithm>
#include <utility>
#include <functional>
#include <iomanip>
#include <typeinfo>
#include <iterator>
#include <string>
#include <vector>
#include <queue>
#include <deque>
#include <tuple>
#include <map>
#include <set>
#include <numeric>
using namespace std;


typedef long long       ll;
typedef struct edge_ { ll to; ll cost; } edge;
typedef vector<int>     vi;
typedef vector<ll>      vll;
typedef vector<double>  vd;
typedef vector<bool>    vb;
typedef vector<string>  vs;
typedef vector<char>    vc;
typedef vector<edge>    ve;
typedef pair<int, int>  pii;
typedef pair<ll, ll>    pll;
typedef vector<pii>     vpii;
typedef vector<pll>     vpll;
typedef vector<vll>		vvll;
typedef vector<vi>		vvi;
typedef vector<ve>      vve;
typedef vector<vc>		vvc;

#define repr(itr, bgn, end) for (ll itr = (ll)bgn; itr < (ll)end; ++itr)
#define rep(itr, end) repr(itr, 0, end)
#define reprrev(itr, bgn, end) for (ll itr = (ll)end - 1; itr >= (ll)bgn; --i)
#define reprev(itr, end) reprrev(itr, 0, end)
#define all(container) container.begin(), container.end()
#define sortall(container) sort(all(container))
#define yn(cond) cond ? (cout << "Yes" << endl) : (cout << "No" << endl)
#define YN(cond) cond ? (cout << "YES" << endl) : (cout << "NO" << endl)

// 定数
#define LLONG_MAX numeric_limits<ll>::max()
#define INT_MAX numeric_limits<int>::max()
constexpr double PI = 3.14159265358979323846;
constexpr ll INF = 1 << 15;
constexpr ll MOD = (ll)1e9 + 7;
constexpr double EPS = 1e-7;

// よく使うもの
constexpr int dy[4] = { 0, 1, 0, -1 };
constexpr int dx[4] = { 1, 0, -1, 0 };


// vector入力
template<typename T>
istream& operator >> (istream& is, vector<T>& vec) {
	for (T& x : vec) is >> x;
	return is;
}

// vector出力
template<typename T>
ostream& operator << (ostream& os, vector<T>& vec) {
	for (T& x : vec) os << x << " ";
	return os;
}

// pair出力
template<typename S, typename T>
ostream& operator << (ostream& os, pair<S, T>& p) {
	os << p.first << " " << p.second;
	return os;
}



int main()
{
	int N;
	cin >> N;
	vll x, y, h;
	x = y = h = vll(N);
	for (int i = 0; i < N; i++) {
		cin >> x[i] >> y[i] >> h[i];
	}

	for (int X = 0; X < 101; X++) {
		for (int Y = 0; Y < 101; Y++) {
			ll count = 0;
			int idx = 0;
			for (int i = 0; i < N; i++) {
				if (h[i] > 0) {
					idx = i;
					break;
				}
			}
			ll H = h[idx] + abs(x[idx] - X) + abs(y[idx] - Y);
			H = max(H, 0ll);
			for (int i = 0; i < N; i++) {
				ll HH = H - abs(X - x[i]) - abs(Y - y[i]);
				HH = max(HH, 0ll);
				if (HH == h[i])
					count++;
			}

			if (count == N) {
				cout << X << " " << Y << " " << H << endl;
				return 0;
			}
		}
	}

	return 0;
}

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

using namespace std;

int main(){
  int N;
  cin >> N;
  int ans = 1000000;
  vector<long long> x(N);
  vector<long long> y(N);

  for(int i=0; i<N; i++){
    cin >> x[i] >> y[i];
  }
  if(N==1){
    cout << 1 << endl;
    return 0;
  }
  for(int s=0; s<N; s++){
    for(int g=0; g<N; g++){
      int preans = N;
      if(s==g) continue;
      vector<bool> b(N);
      long long p = x[g] - x[s];
      long long q = y[g] - y[s];
      for(int i=0; i<N; i++){
        for(int j=0; j<N; j++){
          if(x[j] - x[i] == p && y[j] - y[i] == q){
            preans--;
          }
        }
      }
      ans = min(ans, preans);
    }
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
N = int(input())
a = [int(input()) for _ in range(N)]
a = [0] + a
count = 0
i = 1
while i != 2:
    j = i
    i = a[i]
    a[j] = -1
    count  += 1
    if i == -1:
        count = -1
        break
print(count)

Measured memory_bytes: 50136
#include<stdio.h>
#include<string.h>
int main()
{
    int i,l;
    char str[1000];
    scanf("%s",&str);
    l=strlen(str);
    for(i=0;i<l;i++)
    {
        printf("x");
    }
    printf("\n");
    return 0;
}


Measured memory_bytes: 128
#include <bits/stdc++.h>
#define LL long long
#define INF 0x7FFFFFFF//or 0x3f3f3f3f ? -Wall
using namespace std;

template<class T> inline
void read(T& x) {
	int f = 1; x = 0;
	char ch = getchar();
	while (ch < '0' || ch > '9')   {if (ch == '-') f = -1; ch = getchar();}
	while (ch >= '0' && ch <= '9') {x = x * 10 + ch - '0'; ch = getchar();}
	x *= f;
}

/*============ Header Template ============*/

const int N = 100000 + 5;

LL n, m, k, cnt;
LL a[N], b[N], c[N], d[N], p[N];
LL vis[N], bel[N], pos[N];
vector<int> v[N];

void add(int x, int id) {
	if (vis[x]) return;
	vis[x] = 1; bel[x] = id;
	v[id].push_back(x), pos[x] = v[id].size() - 1;
	add(p[x], id);
}

int get(int x, LL k) {
	int id = bel[x];
	k %= v[id].size();
	return v[id][(pos[x] + k) % v[id].size()];
}

int main() {
	read(n);
	for (int i = 1; i <= n; i++) read(a[i]);
	read(m), read(k);
	for (int i = 1; i <= m; i++) read(b[i]);
	for (int i = 1; i < n; i++) p[i] = i, c[i] = a[i + 1] - a[i];
	for (int i = 1; i <= m; i++) swap(p[b[i] - 1], p[b[i]]);
	for (int i = 1; i < n; i++) if (!vis[i]) {add(i, ++cnt);}
	for (int i = 1; i < n; i++) {
		int x = get(i, k);
		d[i] = c[x];
	}
	LL pos = a[1]; printf("%lld.0\n", pos);
	for (int i = 1; i < n; i++) {
		pos += d[i];
		printf("%lld.0\n", pos);
	}
	return 0;
}

Measured memory_bytes: 15224
h,w=map(int,input().split())
s=[list(input()) for i in range(h)]
for i in range(h):
    for j in range(w):
        if s[i][j]=='#':
            continue
        cnt=0
        for k in [-1,0,1]:
            if i+k<0 or h<=i+k:
                continue
            for l in [-1,0,1]:
                if j+l<0 or j+l>=w:
                    continue
                cnt+=1*(s[i+k][j+l]=='#')
        s[i][j]=str(cnt)
for i in range(h):
    print("".join(s[i]))

Measured memory_bytes: 3188