akhauriyash/Code-Regression huggingface dataset:
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

import numpy as np

N = int(readline())
A = np.array(readline().split(), np.int32)
B = np.array(readline().split(), np.int32)

idx = B.argsort(); B = B[idx]; A = A[idx]

Asorted = np.msort(A)
if any(Asorted > B):
    print('No')
    exit()
if any(Asorted[1:] <= B[:-1]):
    print('Yes')
    exit()

perm = A.argsort().tolist()
x = 0
period = 0
while True:
    period += 1
    x = perm[x]
    if x == 0:
        break

print('Yes' if period != N else 'No')

Measured memory_bytes: 18832
#include <iostream>
#include <algorithm>

using namespace std;

int main(){
    int n,a,b;
    while(cin >> n >> a >> b){
        if((n|a|b)==0) break;
        bool countable[n+10];
        int ret=0;
        fill((bool *)countable, (bool *)countable + n + 1, false);
        countable[0] = true;
        for(int i=0;i<n+1;i++){
            if(countable[i] == true){
                if(i+a <= n) countable[i+a] = true;
                if(i+b <= n) countable[i+b] = true;
            }else{
                ret++;
            }
        }
        cout << ret << endl;
    }
}

Measured memory_bytes: 0
from collections import defaultdict,deque
import sys,heapq,bisect,math,itertools,string,queue,copy,time
sys.setrecursionlimit(10**8)
INF = float('inf')
mod = 10**9+7
eps = 10**-7
def inp(): return int(input())
def inpl(): return list(map(int, input().split()))
def inpl_str(): return list(input().split())

N,D = inpl()
print((N-1)//(D*2+1)+1)


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

void calc(long long a, long long b){
    if(a > b) swap(a,b);
    if(a == b || a + 1 == b){
        cout << 2*(a-1) << endl;
    }else{
        long long c = sqrtl(a*b);
        if(c*c == a*b) c--;
        if (c*(c+1) < a*b ){
			cout << 2*c-1 << endl;
		}
		else {
            cout << 2*c-2 << endl;
		}
    }
}

int main()
{
    long long a, b, q;
    cin >> q;
    while(q--){
        cin >> a >> b;
        calc(a,b);
    }
    return 0;
}

Measured memory_bytes: 256
fn read<T: std::str::FromStr>() -> T {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().parse().ok().unwrap()
}


fn f(n: usize) -> (usize, usize) {
    let mut n = n;
    let b = n % 10;
    let mut a = b;
    while n > 0 {
        a = n % 10;
        n /= 10;
    }
    (a, b)
}

fn main() {
    let n = read::<usize>();

    let mut c: Vec<Vec<usize>> = vec![];
    for i in 0..10 {
        c.push(vec![]);
        for j in 0..10 {
            c[i].push(0);
            for x in 1..n+1 {
                let (a, b) = f(x);
                if a == i && b == j {
                    c[i][j] += 1;
                }
            }
        }
    }
    let mut ans = 0;
    for i in 0..10 {
        for j in 0..10 {
            ans += c[i][j] * c[j][i];
        }
    }
    println!("{}", ans);
}

Measured memory_bytes: 4476
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <cmath>
#include <string>
#include <cstring>
#include <vector>
#include <numeric>

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

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

constexpr ull mod = 1e9+7;
constexpr int N = 13;
ull dp[100010][N];

ll myPower(int a, int n) { // aのn乗の計算
	ll x = 1;
	while (n > 0) { // 全てのbitが捨てられるまで
		if ( n & 1) { // 一番右のbitが１のとき
			x *= a;
		}
		a *= a;
		n >>= 1; // bit全体を右に1つシフトして一番右を捨てる
	}
	return x;
}

int main() {
	ll n, k;
	cin >> n >> k;
	ll ans = 0;
	if (n != 1) {
		ans = k * myPower(k - 1, n-1);
		cout << ans << endl;
	} else {
		cout << k << endl;
	}
	return 0;
}

Measured memory_bytes: 256
// READ & UNDERSTAND
// ll, int overflow, array bounds, memset(0)
// special cases (n=1?), n+1 (1-index)
// do smth instead of nothing & stay organized
// WRITE STUFF DOWN

#include <bits/stdc++.h>

using namespace std;

#define fi first
#define se second
#define pb push_back
#define all(x) (x).begin(), (x).end() 
#define MOD 1000000007

typedef long long ll;
typedef pair <int, int> ii;
typedef pair <ll, ll> pll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef long double ld;

ll INF=LLONG_MAX;

int main()
{
    ios_base::sync_with_stdio(0); cin.tie(0);
    //freopen("input.txt","r",stdin); freopen("output.txt","w",stdout);
	string a,b;
	cin >> a >> b;
	int n=a.length();
	if(b.substr(0,n)==a)cout << "Yes" << endl;
	else cout << "No" << endl;
}	


Measured memory_bytes: 3652
#n,k,*a=map(int,open(0).read().split())
n, k = [int(i) for i in input().split()]
a = [int(i) for i in input().split()]
a.sort()
mod=10**9+7
ans=1
i=0
j=-1
kk=k
while kk>1:
    if a[i]*a[i+1]>a[j]*a[j-1]:
        ans=ans*a[i]*a[i+1]%mod
        i+=2
        kk-=2
    else:
        ans=ans*a[j]%mod
        j-=1
        kk-=1
if kk==1:
    ans=ans*a[j]%mod

if a[-1]<0 and k%2==1:
    ans=1
    for i in a[n-k:]:
        ans=ans*i%mod
print(ans)


Measured memory_bytes: 31752
//=template===================================================================//
// include
#include <vector>
#include <list>
#include <algorithm>
#include <sstream>
#include <iostream>
#include <cstdio>
#include <cmath>
#include <string>
#include <map>

// namespace
using namespace std;

// define
#define FOR(i,a,b) for(int (i)=(a); (i)<(b); (i)++)
#define REP(i,n) FOR(i,0,n)
#define MIN_V(v) *min_element(v.begin(), v.end())
#define MAX_V(v) *max_element(v.begin(), v.end())

// typedef
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<long> VL;
typedef vector<VL> VVL;
typedef vector<string> VS;
typedef long long LL;
typedef unsigned long long ULL;
typedef struct {
  LL cost;
  bool done;
} node_t;

// conversion
inline int
toInt(string s)
{
  int v;
  istringstream sin(s);
  sin >> v;
  return v;
}
inline int countChar(string s, char c) {int cnt,i; cnt=0; REP (i,s.size()) {if (s[i]==c) cnt++;} return cnt;}
template<class T> inline string toString(T x) {ostringstream sout; sout<<x; return sout.str();}
//============================================================================//

//============================================================================//
int main(void)
{
  // Scan begin.
  int n, i;
  VI a(100000+2);
  cin >> n;
  REP(i, n) {
    int temp;
    cin >> temp;
    a[temp]++;
    a[temp + 1]++;
    a[temp + 2]++;
  }
  // Scan done.

  // Code begin.
  int max = 0;
  int x = 0;
  REP(i, 100000+2)
  {
    if (max < a[i]) {
      max = a[i];
      x = i - 1;
    }
  }
  // Code done.

  cout << max << endl;

  return 0;
}

Measured memory_bytes: 640
#include <iostream>
#include <bits/stdc++.h>
using namespace std;
#define fo(i, a, b) for (int i=a; i<(b); i++)
#define forev(i, b, a) for (int i = (b)-1; i >= a; i--)
typedef long long int 	lli;
typedef long double 	ld;
#define mp 				make_pair
#define pb 				push_back
#define ff 				first
#define ss 				second
#define lb 				lower_bound
#define ub 				upper_bound
#define all(x) x.begin(), x.end()
#define sortall(x) sort(all(x))
#define endl 			"\n"
#define fast 			ios_base::sync_with_stdio(0); cin.tie(0);
// #define PI 3.1415926535897932384626
// const int MOD = 1000000007;
// const ll INF = 1e18;
// const int MX = 100001;
//==================================================================================

int main() {
	fast;
	// int t; cin >> t; while (t--)
	int ans = 0;
	int arr[5]; fo(i, 0, 5) {
		cin >> arr[i];
		if (arr[i] == 0) {
			ans = i;
			break;
		}
	}

	cout << ans + 1;

	return 0;
}

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

template <class T> struct Deque {
  vector<T> l, r;
  void build(vector<T> v) {
    l = {rend(v) - v.size() / 2, rend(v)};
    r = {begin(v) + v.size() / 2, end(v)};
  }
  void push_front(T a) { l.push_back(a); }
  void push_back(T a) { r.push_back(a); }
  void pop_front() {
    if (l.empty()) build({++begin(r), end(r)});
    else l.pop_back();
  }
  void pop_back() {
    if (r.empty()) build({rbegin(l), --rend(l)});
    else r.pop_back();
  }
  size_t size() const { return l.size() + r.size(); }
  T& operator[](size_t i) {
    return i < l.size() ? l[l.size() - i - 1] : r[i - l.size()];
  }
  T& front() { return (*this)[0]; }
  T& back() { return (*this)[size() - 1]; }
  friend string to_string(Deque d) {
    string res = "{";
    for (size_t i = 0; i < d.size(); ++i) res += to_string(d[i]) + ", ";
    return res += "}";
  }
};

constexpr int inf = 0x3f3f3f3f;

int main() {
  cin.tie(nullptr);
  ios::sync_with_stdio(false);
  int x, y, z, n, m, s, t;
  cin >> x >> y >> z >> n >> m >> s >> t;
  --s, --t;
  struct Edge {
    int to, w;
  };
  vector< vector<Edge> > g(n + m + x + y + z);
  for (int i = 0; i < n; ++i) {
    int a, b;
    cin >> a >> b;
    --a, --b;
    g[i].emplace_back(Edge{n + m + a, 1});
    g[i].emplace_back(Edge{n + m + x + b, 1});
    g[n + m + a].emplace_back(Edge{i, 0});
    g[n + m + x + b].emplace_back(Edge{i, 0});
  }
  for (int j = 0; j < m; ++j) {
    int c, d;
    cin >> c >> d;
    --c, --d;
    g[n + j].emplace_back(Edge{n + m + x + c, 1});
    g[n + j].emplace_back(Edge{n + m + x + y + d, 1});
    g[n + m + x + c].emplace_back(Edge{n + j, 0});
    g[n + m + x + y + d].emplace_back(Edge{n + j, 0});
  }
  vector<int> dist(n + m + x + y + z, inf);
  Deque<int> deq;
  dist[s] = 0;
  deq.push_back(s);
  while (deq.size()) {
    int v = deq.front();
    deq.pop_front();
    for (auto e : g[v]) {
      if (dist[v] + e.w < dist[e.to]) {
        dist[e.to] = dist[v] + e.w;
        if (e.w) {
          deq.push_back(e.to);
        } else {
          deq.push_front(e.to);
        }
      }
    }
  }
  if (dist[n + t] == inf) {
    cout << -1 << '\n';
  } else {
    cout << dist[n + t] << '\n';
  }
}



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

template<typename T_char>
T_char ToUpper(T_char cX){return toupper(cX);}

int main(){
  int d, t, s;
  cin >> d >> t >>s;

  int res = t*s;
  if(res < d) cout << "No" << endl;
  else cout <<  "Yes" <<endl;
}


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

int main() {
	string s;
	cin >> s;
	for (int i = 0; i < s.length(); i++) {
		if (s.length() % 2 == 1) {
			cout << "No" << endl;
			return 0;
		}
		if (s[i] != (i % 2 == 0 ? 'h' : 'i')) {
			cout << "No" << endl;
			return 0;
		}
	}
	cout << "Yes" << endl;
	return 0;
}

Measured memory_bytes: 256
n, m = readline.split(' ').map(&:to_i)
h = readline.split(' ').map(&:to_i)
roads = (0..(n - 1)).to_h { |i| [i, []] }

m.times do
  a, b =  readline.split(' ').map(&:to_i)
  roads[a - 1].append(b - 1)
  roads[b - 1].append(a - 1)
end

r = 0

roads.each do |number, way|
  is_better_towers = way.map do |another|
    h[another] < h[number]
  end

  is_better_towers.append(true)

  r += 1 if is_better_towers.uniq == [true]
end

puts r


Measured memory_bytes: 37964
/*BISMILLAH
THE WHITE WOLF
NO DREAM IS TOO BIG AND NO DREAMER IS TOO SMALL*/

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<long long> vll;
typedef vector<int> vi;

#define io ios_base::sync_with_stdio(false)
#define pb push_back

#define eb emplace_back
#define mod   1000000007
#define PI 2*acos(0.0)
#define all(r)(r).begin(),(r).end()
#define dbg(a) cout<<#a<<" ->->->-> "<<a<<"\n"
#define inf 1000000000000000000
#define N 5000000
int dirx[] = {1, -1,0, 0, 1, 1, -1, -1}, diry[] = {0, 0, 1, -1, 1, -1, 1, -1};



//=============================================ASIFAZAD==============================================//


int32_t main()
{
    io;
    int k;
    cin>>k;
    string ans = "";
    for(int i = 0; i< k ;i++)
        ans += "ACL";
    cout<<ans;
    return 0;
}


Measured memory_bytes: 3648
#include <iostream>
#include <algorithm>
#include <numeric>
#include <vector>
#include <map>
using namespace std;
int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    map<int, int> mp;
    int A, B, C, D;
    for (int i = 0, tmp; i < 4; i++)
    {
        cin >> tmp;
        mp[tmp] = 1;
    }
    if (mp[1] == 1 && mp[4] && mp[7] == 1 && mp[9] == 1)
    {
        cout << "YES" << endl;
    }
    else
    {
        cout << "NO" << endl;
    }

    return 0;
}

Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main {

	public static void main(String[] args) throws IOException {
		BufferedReader input =new BufferedReader (new InputStreamReader (System.in));
		String str = input.readLine( );
		int n = Integer.parseInt(str);
		int answer = 0;
		answer = n*800 - (n/15)*200;
		System.out.println(answer);
	}

}


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

int N,M;
vector<int> H;

int main() {
    cin>>N>>M;
    H.resize(N);
    for (int i=0; i<N; i++) cin>>H[i];
    vector<bool> flag(N,true);
    for (int i=0; i<M; i++) {
        int temp1,temp2; cin>>temp1>>temp2; temp1--; temp2--;
        if (H[temp1]>H[temp2]) flag[temp2]=false;
        else if (H[temp1]<H[temp2]) flag[temp1]=false;
        else flag[temp1]=false,flag[temp2]=false;
    }
    int ans=0;
    for (int i=0; i<N; i++){
        if (flag[i]) ans++;
    }
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 3784
#include <iostream>

int main()
{

    int N;
    std::cin >> N;

    double inv = 0;
    for (size_t i = 0; i < N; ++i) {
        double A;
        std::cin >> A;
        inv += 1.0 / A;
    }

    std::cout << 1.0 / inv << std::endl;

    return 0;
}


Measured memory_bytes: 256
import sys
input = sys.stdin.readline
N = int(input())
a = [int(i) for i in input().split()]
aa = a[:]
aaa = a[:]
for i in range(N) :
    aa[i] -=1
for i in range(N) :
    aaa[i] += 1
A = a + aa + aaa
import collections
c = collections.Counter(A)
li = list(c.values())
li.sort()
print(li[-1])

Measured memory_bytes: 26836
#include<iostream>
#include<iomanip>
#include<cstdlib>
#include<cmath>
#include<string>
#include<algorithm>
#include<vector>
using namespace std;

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




Measured memory_bytes: 3568
#include <iostream>
using namespace std;
int main()
{
	int c,t,total=0,ans,k=0,minv=1000000000;
	cin>>c>>t;
	int a[c+1],b[c+1],d[c];
	for (int i=1;i<=c;i++)  cin>>a[i]>>b[i];
	for (int i=1;i<=c;i++)
	{
		if (b[i]<=t)
		{
			k++;
			total++;
			d[k]=a[i];
		}
	}
	if (total==0)
	{		
	  cout<<"TLE"<<endl;
	  return 0;	
	}
	for (int i=1;i<=k;i++)
	{
		if (d[i]<minv)  minv=d[i]; 
	}
	cout<<minv<<endl;
	return 0;
}

Measured memory_bytes: 256
def main():
    string = "_" + input()
    last_index = 0
    gather_index = 0
    answer = [0] * (len(string) - 1)
    for i in range(1, len(string)):
        if i < len(string) - 1:
            if string[i] == "R" and string[i + 1] == "L":
                gather_index = i
            elif string[i] == "L" and string[i + 1] == "R":
                answer[gather_index] = (gather_index - last_index) // 2 + (i - gather_index + 1) // 2
                answer[gather_index - 1] = (i - last_index) - answer[gather_index]
                last_index = i
        else:
            answer[gather_index] = (gather_index - last_index) // 2 + (i - gather_index + 1) // 2
            answer[gather_index - 1] = (len(string) - last_index - 1) - answer[gather_index]
    print(" ".join(map(str, answer)))


if __name__ == '__main__':
    main()



Measured memory_bytes: 10660
import fractions
def myAnswer(N:int,A:list) -> int:
   A.sort()
   pre = A.pop(0)
   ans = 10**10
   for a in A:
      ans = min(fractions.gcd(pre,a),ans)
      pre = a
   return ans

def modelAnswer():
   return
def main():
   N = int(input())
   A = list(map(int,input().split()))
   print(myAnswer(N,A[:]))
if __name__ == '__main__':
   main()

Measured memory_bytes: 16276
#include<iostream>
#include<cstring>
#include<cstdio>
#include<vector>
#include<queue>
using namespace std;
const int maxn = 10000 + 50;
const int INE = 100000010;
int n,m,d[maxn],head[maxn],ip,cost[maxn];
struct Edge
{
    int to,w,c,next;
} e[maxn * 2000];
void addEdge(int a,int b,int c,int d1)
{
    e[ip].to = b;
    e[ip].w = c;
    e[ip].c = d1;
    e[ip].next = head[a];
    head[a] = ip++;
}
bool vis[maxn];
void spfa(int s)
{
    queue<int>q;
    fill(cost,cost + n + 1,INE);
    fill(d,d + n + 1,INE);
    memset(vis,false,sizeof(vis));
    d[s] = 0;
    cost[s] = 0;
    vis[s] = true;
    q.push(s);
    while(!q.empty()){
        int u = q.front();q.pop();
        vis[u] = false;
        for(int i = head[u]; i != -1; i = e[i].next){
            int to = e[i].to;
            if(d[to] > d[u] + e[i].w || (d[to] ==
            d[u] + e[i].w && cost[to] > e[i].c)){
                d[to] = d[u] + e[i].w;
                cost[to] = e[i].c;
                if(!vis[to]){
                    q.push(to);
                    vis[to] = true;
                }
            }
        }
    }
}
int main()
{
    while(scanf("%d%d",&n,&m) == 2)
    {
        if(n == 0 && m == 0)break;
        int a,b,c,d1;
        memset(head,-1,sizeof(head));
        ip = 0;
        for(int i = 0; i < m; ++i)
        {
            scanf("%d%d%d%d",&a,&b,&c,&d1);
            addEdge(a,b,c,d1);
            addEdge(b,a,c,d1);
        }
        spfa(1);
        int ans = 0;
        for(int i = 1; i <= n; ++i)
            ans += cost[i];
        printf("%d\n",ans);
    }
    return 0;
}



Measured memory_bytes: 4012
#include<bits/stdc++.h>
using namespace std;
int dp[100099],n,k,a[100009];
int bt(int x)
{
    if(x<0)return 1;
    if(dp[x]!=-1)return dp[x];
    dp[x]=0;
    for(int i=0;i<n;i++)
    {
        dp[x]=max(dp[x],1-bt(x-a[i]));
    }
    return dp[x];
}
int main()
{
    cin>>n>>k;
    for(int i=0;i<n;i++)
    {
        cin>>a[i];
    }
    memset(dp,-1,sizeof(dp));
    dp[0]=0;
    if(bt(k))cout<<"First";
    else cout<<"Second";
}


Measured memory_bytes: 5376
#include <iostream>
using namespace std;
int main(){
  long long n, d, a, b;
  int cnt = 0;
  cin >> n >> d;
  d *= d;
  while(n--){
  	cin >> a >> b;
    if(d >= (a*a + b*b)) ++cnt;
  }
  cout << cnt;
  return 0;
}


Measured memory_bytes: 3220
#include <iostream>
#include <vector>
#include <utility>
using namespace std;


int main(){
    int n,m;
    vector<pair<int,int> > vc;
    while(true){
        cin>>n>>m;
        if(n==0&&m==0)
            break;
        vc.push_back(std::make_pair(n,m));
        
    }

    for(auto a:vc){
        if(a.first<=a.second)
            cout<<a.first<<" "<<a.second<<'\n';
        if(a.first>a.second)
            cout<<a.second<<" "<<a.first<<'\n';
        
    }
}



Measured memory_bytes: 3108
#include <iostream>

using namespace std;
 
int main()
{
    int room[8] = {0, 1, 2, 3, 5, 7, 8, 9}, n;
    int newroom[10], i;
     
    while (cin >> n, n) {
        for (i = 0; ;i++) {
            int nn = n / 8;
            newroom[i] = n % 8;
            n = nn;
            if (!n) break;
        }    
        for (int j = i; j >= 0; j--) {
            cout << room[newroom[j]];
        }
        cout << endl;
    }    
    return 0;
}

Measured memory_bytes: 3008
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const int inf = 1e9 + 7;
const ll longinf = 5LL << 60;
const ll mod = 1e9 + 7;

int main() {
	ll N;
	cin >> N;

	ll ans = 0;
	for(ll a = 1; a < N; a++) {
		ans += (N - 1) / a;
	}
	cout << ans << "\n";
	return 0;
}

Measured memory_bytes: 3632
#include<bits/stdc++.h>
#include<math.h>
#define si(a) scanf("%d",&a)
#define sl(a) scanf("%lld",&a)
#define sd(a) scanf("%lf",&a)
#define ss(a) scanf("%s",a)
#define ms(a) memset(a,0,sizeof(a))
#define repi(i,a,b) for(register int i=a;i<=b;++i)
#define repd(i,a,b) for(register int i=a;i>=b;--i)
#define reps(s) for(int i=head[s];i;i=e[i].nxt)
#define ce(i,r) i==r?'\n':' '
#define pb push_back 
#define fi first
#define se second
#define pr(x) cout<<#x<<": "<<x<<endl

using namespace std;
typedef long long ll;

double pi = acos(-1);
int r;

int main(){
	cin>>r;
	cout<<2 * r * pi;
	return 0;
} 

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

using ll = long long;
using P = pair<ll, ll>;

const ll MOD = 1e9+7;
// const ll MOD = 998244353;
const ll INF = 1ll<<60;

#define FOR(i,a,b) for (ll i=(a);i<(ll)(b);++i)
#define REP(i,n) FOR(i,0,n)
#define ALL(v) (v).begin(),(v).end()
#define DEBUG(x) ;
#define DEBUG(x) std::cerr << #x << " : " << (x) << std::endl;

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



int main(int argc, char **argv)
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	ll a, b; cin >> a >> b;
	if (a + b >= 10 )
		std::cout << "error "<< std::endl;
	else
		std::cout << a + b<< std::endl;
	
	return 0;
}


Measured memory_bytes: 3656
import java.util.*;
import java.lang.*;
import java.math.*;
import java.io.*;
import static java.lang.Math.*;
import static java.util.Arrays.*;
import static java.util.Collections.*;

public class Main{
	Scanner sc=new Scanner(System.in);

	int INF=1<<28;
	double EPS=1e-12;

	int caze;
	int n;
	int[] c;

	void run(){
		for(caze=1;; caze++){
			n=sc.nextInt();
			if(n==0){
				break;
			}
			c=new int[n];
			for(int i=0; i<n; i++){
				c[i]=sc.nextInt();
			}
			solve();
		}
	}

	void solve(){
		String ans;
		sort(c);
		if(c[0]!=1){
			ans="Cannot pay some amount";
		}else{
			int n=c.length;
			for(int i=0; i<n/2; i++){
				int t=c[i];
				c[i]=c[n-1-i];
				c[n-1-i]=t;
			}

			int minW=-1;
			int[] minMw=null;
			for(int i=1; i<n; i++){
				int x=c[i-1]-1;
				int[] gi=new int[n];
				for(int k=0; k<n; k++){
					gi[k]=x/c[k];
					x%=c[k];
				}
				for(int j=i; j<n; j++){
					int[] mw=new int[n];
					int mwSum=0;
					int w=0;
					for(int k=0; k<n; k++){
						if(k<j)
							mw[k]=gi[k];
						else if(k==j)
							mw[k]=gi[k]+1;
						else
							mw[k]=0;
						w+=mw[k]*c[k];
						mwSum+=mw[k];
					}
					int[] gw=new int[n];
					int gwSum=0;
					int t=w;
					for(int k=0; k<n; k++){
						gw[k]=t/c[k];
						t%=c[k];
						gwSum+=gw[k];
					}
					if(mwSum<gwSum){
						// debug("w", w, "mw", mw, "gw", gw);
					}
					if(mwSum<gwSum&&(minW==-1||w<minW)){
						minW=w;
						minMw=mw.clone();
					}
				}
			}
			if(minW>=0){
				ans="Cannot use greedy algorithm";
			}else{
				ans="OK";
			}
		}
		println("Case #"+caze+": "+ans);
	}

	void debug(Object... os){
		System.err.println(Arrays.deepToString(os));
	}

	void print(String s){
		System.out.print(s);
	}

	void println(String s){
		System.out.println(s);
	}

	public static void main(String[] args){
		// System.setOut(new PrintStream(new BufferedOutputStream(System.out)));
		new Main().run();
	}
}

Measured memory_bytes: 12000
#include <algorithm>
#include <iostream>
#include <vector>
#include <string>
#include <map>
#include <cmath>

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

constexpr ll LLINF {1001002003004005006};//ll = 9*LLINF
constexpr int INTINF {1000000000};//int = 2*INTINF

#define  rep(i,n)   for(int i = 0; i < (n); ++i)
#define rrep(i,n)   for(int i = 1; i <= (n); ++i)
#define drep(i,n)   for(int i = (n)-1; i >= 0; --i)
#define srep(i,s,t) for(int i = s; i < t;  ++i)

template<typename T>
void maxs(T& x, T&& y) {
  x=std::max(x,y);
}
template<typename T>
void maxs(T& x, T& y) {
  x=std::max(x,y);
}

template<typename T>
void mins(T& x, T&& y) {
  x=std::min(x,y);
}
template<typename T>
void mins(T& x, T& y) {
  x=std::min(x,y);
}

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

  vector<int> x(5);
  rep(i, 5) cin >> x[i];

  int ans {1};
  rep(i, 5) {
    if (x[i] == 0) {
      break;
    }
    ++ans;
  }
  cout << ans << '\n';
}


Measured memory_bytes: 3652
#include<iostream>
using namespace std;
int main(){
    int n,i;
    cin>>n;
    int a[n];
    for(i=0; i<n; i++){
    cin>>a[i];
    }
  int count =0, max =0;
    for(i=1; i<n; i++)
    {
      if(a[i]<=a[i-1]){
        count ++;}
      if(count> max){
        max= count;
      }
      if(a[i]> a[i-1]){
        count =0;}
    }
      
    cout<<max;
}

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

using namespace std;

int main(void)
{
	int n;
	cin>>n;
	vector<string> s;
	string w;
	for(int i = 0; i < n; i++){
		cin>>w;
		s.push_back(w);
	}
	sort(s.begin(),s.end());
	
	w = s[0];
	int count = 1;
	int max = 0;
	for(int i = 1; i < n; i++){
		if(w == s[i]) count++;
		else{
			if(count > max) max = count;
			count = 1;
			w = s[i];
		}
	}
	
	//cout<<"\n"<<endl;
	//for(int i = 0; i < n; i++) cout<<s[i]<<endl;
	if(count > max) max = count;
	//cout<<"\n"<<endl;
	for(int i = 0; i < n-max+1; i++){
		if(s[i] == s[i+max-1]){
			cout<<s[i]<<endl;
		}
	}
	
	//cout<<"max = "<<max<<endl;
	return 0;
}



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

int main(void){
  int a[4],temp;
  for(int i = 0; i < 4; i++)a[i] = 0;
  for(int i = 0; i < 6; i++){
    cin >> temp;
    a[temp - 1]++;
  }
  for(int i = 0; i < 4; i++){
    if(a[i] == 3){
      cout << "NO\n";
      break;
    }
    if(i == 3)cout << "YES\n";
  }

  return 0;
}

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

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

using namespace std;

template <class T, class U> void amax(T& x, U y) {if (x < y) x = y;}

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

    int N;
    cin >> N;
    map<string, int> m;
    int max_cnt = 0;
    REP(_, N) {
        string S;
        cin >> S;
        amax(max_cnt, ++m[S]);
    }
    for (auto kv: m) {
        string S;
        int cnt;
        tie(S, cnt) = kv;
        if (cnt == max_cnt) {
            cout << S << '\n';
        }
    }
    cout << flush;
    return 0;
}


Measured memory_bytes: 23808
#!/usr/bin/env python3
# Generated by https://github.com/kyuridenamida/atcoder-tools
from typing import *
import itertools
import math
import sys

INF = float('inf')


def solve(A: int, B: int):
    return A*B


def main():

    sys.setrecursionlimit(10 ** 6)

    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    A = int(next(tokens))  # type: int
    B = int(next(tokens))  # type: int
    print(solve(A, B))


if __name__ == '__main__':
    main()


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

#define REP(i, n) for (int i = 0; i < n; i++)
#define FOR(i, a, b) for (int i = a; i < b; i++)
#define ALL(v) v.begin(), v.end()
#define IN(v, val) find(ALL(v), val) != v.end()
#define MAX(v) *max_element(ALL(v))
#define MIN(v) *min_element(ALL(v))
#define SORT(v) sort(ALL(v))
#define SORTR(v)         \
    {                    \
        sort(ALL(v));    \
        reverse(ALL(v)); \
    }

using namespace std;
typedef long long ll;

int main(int argc, char const *argv[])
{
    int N;
    cin >> N;
    vector<int> a(N);
    int alice = 0;
    int bob = 0;
    REP(i, N)
    {
        cin >> a[i];
    }
    SORTR(a);
    REP(i, N)
    {
        if (i % 2 == 0)
        {
            alice += a[i];
        }
        else
        {
            bob += a[i];
        }
    }
    cout << abs(alice - bob) << endl;
    return 0;
}


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

using namespace std;

int main()
{
    int n;
    vector<vector<long long int>> f;
    vector<vector<long long int>> p;
    long long int max=-pow(10,15);
    cin>>n;
    f.resize(n);
    p.resize(n);
    for(auto&m:f){
        m.resize(10);
        for(auto&j:m)cin>>j;
    }
    for(auto&m:p){
        m.resize(11);
        for(auto&j:m)cin>>j;
    }
    int num=1;
    while(1){
        bitset<10>bit(num);
        vector<long long int> fsum;
        fsum.resize(n);
        for(int i=0;i<10;++i){
            for(int m=0;m<n;++m)if(bit[i]&&f.at(m).at(i)==1)++fsum.at(m);
        }
        int s=0;
        for(int m=0;m<n;++m){
      //      cout<<fsum.at(m)<<endl;
            s+=p.at(m).at(fsum.at(m));
        }
        if(max<s)max=s;
        if(bit.all())break;
        ++num;
    }
    cout<<max<<endl;
    return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		String s = sc.nextLine();
//		int potential = 0;
		int abs = Integer.MAX_VALUE;
		for(int i = 0; i < s.length() - 2; i++){
			int num = Integer.parseInt(s.substring(i, i + 3));
//			System.out.println(num);
			if(Math.abs(num-753) < abs){
				abs = Math.abs(num-753);
			}
		}
		System.out.println(abs);
		
	}


}


Measured memory_bytes: 23252
#include <iostream>
#include <map>
#include <vector>
#include <string>
#include <algorithm>

using namespace std;
using ll = long long;
using ld = long double;
const ll mod = 1000000007;


int main() {

    ll N, M;
    vector<ll> A, B;
    cin >> N >> M;
    for (int i = 0; i < N; ++i) {
        ll a;
        cin >> a;
        A.push_back(a);
    }
    for (int i = 0; i < M; ++i) {
        ll b;
        cin >> b;
        B.push_back(b);
    }
    sort(A.begin(), A.end(), greater<ll>());
    sort(B.begin(), B.end(), greater<ll>());


    int a = 0;
    int b = 0;

    ll result = 1;
    for (int i = N * M; i >= 1; --i) {
        if (i == A[a] && i == B[b]) {
            a++;
            b++;
        } else if (i == A[a]) {
            result = result * b % mod;
            a++;
        } else if (i == B[b]) {
            result = result * a % mod;
            b++;
        } else {
            ll t = a * b - (N * M - i);
            if (t <= 0) {
                cout << 0 << endl;
                return 0;
            }
            result = result * t % mod;
        }
    }

    cout << result << endl;

    return 0;
}

Measured memory_bytes: 256
#include<stdio.h>

int main(void)
{
  int n,x;
  scanf("%d%d",&n,&x);

  int min=1000;
  int m=0;
  int count = 0;
  for(int i=0; i<n; i++){
    scanf("%d",&m);
    x -= m;
    if(min>m)min=m;
    count++;
  }
    printf("%d",count+x/min);
    return 0;

}


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

int main() {
    string s; 
    cin>>s;
    if(s[2] == s[3] && s[4] == s[5]) cout << "Yes";
    else cout << "No";
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#define rep(i, a, b) for(int i = (a); i < (b); i++)
using namespace std;

int main() {
  int n, m, s = 0;
  cin >> n >> m;
  vector<int> v(n);
  rep(i, 0, n) {
    cin >> v[i];
    s += v[i];
  }
  sort(v.begin(), v.end());
  if(v[n-m] < s / (4.0 * m)) {
    cout << "No";
  } else {
    cout << "Yes";
  }
}

Measured memory_bytes: 256
//↓template↓

#include "bits/stdc++.h"
using namespace std;
#define Would
#define you
#define all(n)  n.begin(),n.end()
const long long INF = 1e18;
const long long MOD = 1e9 + 7;
const double pi = acos(-1);
const int SIZE = 1 << 17;
int dx[] = { 1,0 }, dy[] = { 0,1 }, alp[30];
long long fac[200005], finv[200005], inv[200005];
vector<long long>dij;
struct edge { long long to, cost; };
vector<vector<edge> >G;

long long mod_pow(long long a, long long b) {
	long long res = 1, mul = a;
	for (int i = 0; i < 31; ++i) {
		if (b >> i & 1) {
			res *= mul;
			res %= MOD;
		}
		mul = (mul * mul) % MOD;
	}

	return res;
}

void addedge(int from, int to, int cost) {
	G[from].push_back({ to,cost });
	G[to].push_back({ from,cost });
}

//↑template↑

int a, b, c, ans;
int main() {
	cin >> a >> b >> c;
	for (int i = a; i <= b; ++i) {
		if (c%i == 0) { ++ans; }
	}
	cout << ans << endl;
}



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

int dp[3005][3005];

int main(){
    string s,t; cin>>s>>t;

    for(int i=0;i<s.length();i++){
        for(int j=0;j<t.length();j++){
            if(s[i]==t[j]) dp[i+1][j+1]=dp[i][j]+1;
            else dp[i+1][j+1]=max(dp[i][j+1],dp[i+1][j]);
        }
    }
    string ans;
    int i=s.length(),j=t.length();
    while(!(i==0||j==0)){
        if(dp[i][j]==dp[i-1][j]) i--;
        else if(dp[i][j]==dp[i][j-1]) j--;
        else if(dp[i][j]==dp[i-1][j-1]+1){
            ans+=s[i-1];
            i--;
            j--;
        }
    }
    reverse(ans.begin(),ans.end());
    cout<<ans<<endl;
}

Measured memory_bytes: 35456
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <vector>

using namespace std;

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<double, int> pdi;

int l[105];
void solve() {
  int n;
  cin >> n;
  for(int i = 1; i <= n; i++) {
    cin >> l[i];
    l[i] += l[i-1];
  }
  int ret = l[n];
  for(int i = 1; i < n; i++) {
    ret = min(ret, abs(2*l[i] - l[n]));
  }
  cout << ret << endl;
}

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL); cout.tie(NULL);
  solve();
  /*
  int t;
  cin >> t;
  for(int i = 1; i <= t; i++) {
    cout << "Case #" << i << ": ";
    solve();
  }
  */
}


Measured memory_bytes: 256
#include<iostream>
#include<string>
using namespace std;
int main(){
	
	int a, b;
	cin >> a >> b;
	if (b%a == 0){
		cout << a + b << endl;
	}
	else{
		cout << b - a << endl;
	}

	system("pause");
	return 0;
}

Measured memory_bytes: 504
while True:
    n=int(input())
    if(n==0):
        break
    
    a=[]
    
    for i in range(1, n):
        a.append(i)
    k=0
    
    for i in range(n-2):
        for j in range(i+2, n):
            if(sum(a[i:j])==n):
                k+=1
            if(sum(a[i:j])>n):
                break
    print(k)


Measured memory_bytes: 5600
#include <iostream>
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <queue>
#include <stack>
#include <vector>
#include <algorithm>
#include <map>
#include <unordered_map>
#include <set>
#include <deque>

int gcd(int n, int m){
  int maxvalue = std::max(n, m);
  int minvalue = std::min(n, m);
  if (minvalue==0) return n;
  return gcd(minvalue, maxvalue%minvalue);
}
int main(){
  int A, B, C, D, E, F;
  scanf("%d", &A);
  scanf("%d", &B);
  scanf("%d", &C);
  scanf("%d", &D);
  scanf("%d", &E);
  scanf("%d", &F);
  double density_max = -1.0;
  int water_ans, sugar_ans;
  std::vector<bool > water_enable(F+4, false);
  std::vector<bool > sugar_enable(F+4, false);
  for (int a=0; a<=3000; a++){
    for (int b=0; b<=3000; b++){
      //printf("=====================\n");
      //printf("a=%d, b=%d\n", a, b);
      int sum_water = 100*A*a+100*B*b;
      //printf("sum_water=%d\n", sum_water);
      if (sum_water>F) continue;
      water_enable[sum_water]=true;
    }
  }
  for (int c=0; c<=3000; c++){
    for (int d=0; d<=3000; d++){
      //printf("=====================\n");
      //printf("c=%d, d=%d\n", c, d);
      int sum_sugar = C*c+D*d;
      //printf("sum_sugar=%d\n", sum_sugar);
      if (sum_sugar>F) continue;
      sugar_enable[sum_sugar]=true;
    }
  }
  for (int i=0; i<=3000; i++){
    if (!water_enable[i]) continue;
    for (int j=0; j<=3000; j++){
      if (!sugar_enable[j]) continue;
      if (i+j>F) continue;
      if (i*E/100 < j) continue;
      if ((double)j/(double)(i+j)>density_max){
	density_max = (double)j/(double)(i+j);
	water_ans = i;
	sugar_ans = j;
      }
    }
  }
  std::cout << water_ans+sugar_ans << " " << sugar_ans << std::endl; 
  return 0;
}

Measured memory_bytes: 888
def main():
    n = int(input())
    phrase = [tuple(map(int,input().split()))for _ in range(n)]
    m = int(input())
    ans = []
    flag = 1
    dp = [0]*(394)
    for w in range(393):
        for i in range(n):
            t = phrase[i]
            s,l,p = t
            if w+s <= 393:
                dp[w+s] = max(dp[w+s],dp[w]+p)
            if w+l < 393:
                dp[w+l] = max(dp[w+l],dp[w]+p)
            elif w+l >= 393 and w+s < 393:
                dp[393] = max(dp[393],dp[w]+p)
    for _ in range(m):
        w = int(input())
        if not flag:
            continue
        if dp[w]:
            ans.append(dp[w])
        else:
            flag = 0
    if flag:
        for a in ans:
            print(a)
    else:
        print(-1)

if __name__ == "__main__":
    main()
        


Measured memory_bytes: 5684
#include <algorithm>
#include <iostream>


int main() {
  int n;
  std::cin >> n;
  int a, b, c;
  std::cin >> a >> b >> c;
  int bestA = a, bestB = b, bestC = c;
  for(int i = 1; i < n; i++) {
    std::cin >> a >> b >> c;
    a = std::max(bestB + a, bestC + a);
    b = std::max(bestA + b, bestC + b);
    c = std::max(bestA + c, bestB + c);
    bestA = a; bestB = b; bestC = c;
  }
  std::cout << std::max(bestA, std::max(bestB, bestC)) << "\n";
}


Measured memory_bytes: 3144
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <climits>
#include <cmath>
#include <map>
#include <queue>
#include <iomanip>
#include <set>
using namespace std;

#define rep(i,n) for(int (i)=0;(i)<(n);(i)++ )
#define repf(i,m,n) for(int (i)=m;(i)<n;(i)++)
#define all(v) (v).begin(), (v).end()
#define ll long long
#define vec(name,num) vector<ll> name((num),0);
#define op(i) cout<<(i)<<endl;
#define opf(i) cout<<fixed<<setprecision(10)<<(i)<<endl;
#define ip(i) cin>>(i);
#define opN cout<<"No"<<endl;
#define opY cout<<"Yes"<<endl;
#define opP cout<<"Possible"<<endl;
#define opI cout<<"Impossible"<<endl;
#define mat(name,fnum,snum); vector<vector<ll>> name((fnum),vector<ll>((snum),0));
#define matC(name,fnum,snum); vector<vector<char>> name((fnum),vector<char>((snum),0));
#define debugP int debug_point; cin>>debug_point;
#define FI first
#define SE second
const ll MOD= 1e9 + 7;

const string YES = "Yes";
const string NO = "No";


void solve(long long N, std::vector<long long> A, std::vector<long long> B,vector<pair<ll,ll>> T){
    sort(all(T));
    ll limit=T[N-1].FI-T[N-1].SE;
    if(limit<0){
            cout<< NO<<endl;
            return;
    }
    repf(i,1,N){
        
        if(limit>T[N-1-i].FI)limit=T[N-1-i].FI;
        limit-=T[N-1-i].SE;
        if(limit<0){
            cout<< NO<<endl;
            return;
        }
    }
    op(YES)
}

// Generated by 1.1.4 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
int main(){
    long long N;
    scanf("%lld",&N);
    std::vector<long long> A(N);
    std::vector<long long> B(N);
    vector<pair<ll,ll>> T(N);
    for(int i = 0 ; i < N ; i++){
        scanf("%lld",&A[i]);
        scanf("%lld",&B[i]);
        T[i].FI=B[i];T[i].SE=A[i];
    }

    solve(N, std::move(A), std::move(B), move(T));
    return 0;
}


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

using namespace std;

typedef long long int ll;
typedef pair<ll, ll> pll;

#define FOR(i, n, m) for(ll (i)=(m);(i)<(n);++(i))
#define REP(i, n) FOR(i,n,0)
#define OF64 std::setprecision(10)

const ll MOD = 1000000007;
const ll INF = (ll) 1e15;

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll N, T;
    cin >> N >> T;
    ll ans = INF;
    REP(i, N) {
        ll c, t;
        cin >> c >> t;
        if (t <= T)
            ans = std::min(ans, c);
    }

    if (ans == INF)
        cout << "TLE" << endl;
    else
        cout << ans << endl;
    return 0;
}

Measured memory_bytes: 384
#include<stdio.h>
#define MOD 1000000007
#define modadd(rhs,lhs) (((rhs)+(lhs)) % MOD)

int main(void){
    register int i,j,k,l,m;
    int n;
    scanf("%d",&n);
    static long dp[101][4][4][4]; //0:A 1:G 2:C 3:T
    for(i = 0;i < 4;i++)for(j = 0;j < 4;j++)for(k = 0;k < 4;k++)dp[3][i][j][k] = 1;
    dp[3][0][1][2] = 0;     dp[3][0][2][1] = 0;     dp[3][1][0][2] = 0;

    for(i = 3;i < n;i++)for(j = 0;j < 4;j++)for(k = 0;k < 4;k++)for(l = 0;l < 4;l++)for(m = 0;m < 4;m++){
        if(k == 0 && l == 1 && m == 2)continue;
        if(k == 0 && l == 2 && m == 1)continue;
        if(k == 1 && l == 0 && m == 2)continue;
        if(j == 0 && k == 1 && m == 2)continue;
        if(j == 0 && l == 1 && m == 2)continue;
        dp[i+1][k][l][m] = modadd(dp[i+1][k][l][m],dp[i][j][k][l]);
    }
    long ans = 0;
    for(i = 0;i < 4;i++)for(j = 0;j < 4;j++)for(k = 0;k < 4;k++)ans = modadd(ans,dp[n][i][j][k]);
    printf("%ld",ans);
    return 0; 
}

Measured memory_bytes: 256
import sys

readline = sys.stdin.readline
W, H, N = map(int, readline().split())
XYA = [tuple(map(int, readline().split())) for _ in range(N)]


def f(i, j, xya):
    x, y, a = xya
    if ((a == 1 and i > x) or
        (a == 2 and i <= x) or 
        (a == 3 and j > y) or
        (a == 4 and j <= y)):
        return True
    else:
        return False

ans = 0
for i in range(1, W+1):
    for j in range(1, H+1):
        if all(f(i, j, xya) for xya in XYA):
            ans += 1
print(ans)


Measured memory_bytes: 3064
#include<iostream>
#include<cstdio>
#include<cmath>
#include<vector>
#include<queue>
#include<map>
#include<algorithm>
#include<set>
#include<complex>
#include<string>
#include<cstring>
using namespace std;
#define rep2(x,from,to) for(long long x=(from);(x)<(to);(x)++)
#define rep(x,to) rep2(x,0,to)
#define INF 100000000
#define debug(x) cout<<#x<<": "<<x<<endl

#define all(x) x.begin(),x.end()
typedef pair<long long,long long> P;
typedef pair<long long,P> PP;
#define MAX_N 10000000
long long par[MAX_N];
long long rrank[MAX_N];
long long ren[100006];
void init(long long n)
{
	rep(i,n)
	{
		par[i]=i;
		rrank[i]=0;
		ren[i]=1;
	}
}
long long find(long long x)
{
	if(par[x]==x)return x;
	else return par[x]=find(par[x]);
}
void unite(long long x,long long y)
{
	x=find(x);y=find(y);
	if(x==y) return;
	if(rrank[x]<rrank[y])
	{
		par[x]=y;
		ren[y]+=ren[x];
	}
	else
	{
		par[y]=x;
		ren[x]+=ren[y];
		if(rrank[x]==rrank[y])rrank[x]++;
	}
}
bool same(long long x,long long y)
{
	return find(x)==find(y);
}
long long findren(long long x)
{
	x=find(x);
	return ren[x];
}
long long n,m;
long long a[100006];
long long b[100006];
long long ans[100006];
long long fans;
long long aa,bb;
int main()
{
	cin>>n>>m;
	rep(i,m)cin>>a[i]>>b[i];
	//rep(i,n)ren[i]=1;
	fans=n*(n-1)/2;
	ans[m-1]=fans;
	init(n);
	for(long long i=m-1;i>=1;i--)
	{
		aa=a[i];
		bb=b[i];
		if(same(aa,bb))
		{
			//cout<<"j"<<i<<endl;
			ans[i-1]=ans[i];
		}
		else
		{
			//cout<<"i"<<i<<endl;
			ans[i-1]=ans[i]-findren(aa)*findren(bb);
			//cout<<"find(aa)"<<findren(aa)<<"find(bb)"<<findren(bb)<<endl;
			unite(aa,bb);
		}
	}
	rep(i,m)
	{
		cout<<ans[i]<<endl;
	}
	return 0;
}

Measured memory_bytes: 9472
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define endl '\n'
#define rep(i, n)    for(ll i = 0; i < (n); ++i)
#define repA(i, a, n)  for(ll i = a; i <= (n); ++i)
#define repD(i, a, n)  for(ll i = a; i >= (n); --i)
#define trav(a, x) for(auto& a : x)
#define all(x) x.begin(), x.end()
#define sz(x) (ll)(x).size()
#define unique_sort(x) (sort(x.begin(), x.end()), x.resize(distance(x.begin(), unique(x.begin(), x.end()))))
#define fill(a)  memset(a, 0, sizeof (a))
#define ff first
#define ss second
#define mp make_pair
#define pb push_back
typedef long double ld;
typedef pair<ll,ll> pll;
typedef vector<ll> vll;
const ll mod = 1e9+7;

int main()
{
    ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
    ll tt=1;
        // cin >> tt;
    while((tt)--){
       string s; cin >> s;
       ll q; cin >> q;
        bool rev = 0;
        vector<char> v[2];
       while(q--){
            ll t; cin >> t;
            if(t==1){
                rev = !rev;
            }
            else{
                ll f; char c;
                cin >> f >> c;
                f--;
                v[f^rev].pb(c);
            }

       }
       string ans ;
      repD(i,sz(v[0])-1,0){
            ans +=v[0][i];
      }
      ans +=s;
      trav(i,v[1]){
         ans +=i;
      }
      if(rev) reverse(all(ans));
      cout << ans << endl;
    }
}


Measured memory_bytes: 1448
// clang-format off
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define stoi stoll
using pii = pair<int,int>;
using vi = vector<int>;
using vvi = vector<vi>;
#define all(c) begin(c), end(c)
#define rall(c) rbegin(c), rend(c)
#define fore(x, c) for(auto &&x : c)
#define rep(i, a, n) for(int i = a, i##len = (int)(n); i < i##len; ++i)
#define rrep(i, a, n) for(int i = (int)(n - 1); i >= a; --i)
#define sz(c) ((int)c.size())
#define contains(c, x) (c.find(x) != end(c))
#define inseg(l, x, r) ((l) <= (x) && (x) < (r))
#define dump(...)
#define pb push_back
#define eb emplace_back
#define _ 0
const signed INF_ = 1001001001; const long long INF = 1001001001001001001LL;
const int DX[9] = {0,1,0,-1,1,1,-1,-1,0}, DY[9] = {-1,0,1,0,-1,1,1,-1,0};
template<class T> ostream& operator<<(ostream &os, const vector<T> &v) {
  for (auto i = begin(v); i != end(v); i++) os<<*i<<(i==end(v)-1?"":" ");return os;}
template<class T> istream& operator>>(istream &is, vector<T> &v) {
  for (auto i = begin(v); i != end(v); i++) is>>*i;return is;}
template<class T,class U> istream& operator>>(istream &is, pair<T,U> &p) {
  is>>p.first>>p.second;return is;}
template<class T, class U> bool chmax(T &a, const U &b){return a<b?a=b,1:0;}
template<class T, class U> bool chmin(T &a, const U &b){return a>b?a=b,1:0;}
template <class T> void psum(T& c) {partial_sum(begin(c), end(c), begin(c));}
template<class T> using heap = priority_queue<T, deque<T>, greater<T>>;
struct before_main_function {
  before_main_function() {
      cin.tie(nullptr); ios::sync_with_stdio(0);
      cout << setprecision(15) << fixed;
  }
} before_main_function;
// clang-format on
//------------------8<------------------------------------8<--------------------

signed main() {
  int N;
  cin >> N;
  vi A(N);
  cin >> A;
  rep(i, 0, N) { A[i] -= i + 1; }
  sort(all(A));

  auto f = [&](int b) {
    int ret = 0;
    rep(i, 0, N) ret += abs(A[i] - b);
    return ret;
  };

  if (N % 2) {
    cout << f(A[N / 2]) << endl;
  } else {
    cout << min(f(A[N / 2 - 1]), f(A[N / 2])) << endl;
  }
  return (0 ^ _ ^ 0);
}



Measured memory_bytes: 1792
#include<iostream>
        #include<vector>
        #include<string>
        #include<math.h>
        #include<algorithm>
        #include<cstring>//memset needs this head
        using namespace std;
        int canReach[2][16001];
        bool DP(vector<int> v,int t,int start){//v is the step vector of each axis
            memset(canReach,0,sizeof(canReach));
                canReach[0][8000+start]=1;//the initial place
            if(v.size()==0)
                return canReach[0][8000+t];
            int i;
            for(i=1;i<=v.size();i++){
                for(int j=0;j<=16000;j++){
                    canReach[i%2][j]=((j+v[i-1])>16000?0:canReach[(i-1)%2][j+v[i-1]])||((j-v[i-1])<0?0:canReach[(i-1)%2][j-v[i-1]]);
                }
            }
            return canReach[(i-1)%2][8000+t];
        }
        int main(){
            string S;
            int tx,ty;
            cin>>S>>tx>>ty;
            bool whichAxis=0;//the initial axis is x,1 is y;
            vector<int> vx;
            vector<int> vy;
            int count=0;
            for(auto c:S){
                if(c=='T'){
                    ((whichAxis==0)?vx:vy).push_back(count);
                    count=0;
                    whichAxis=!whichAxis;
                }
                else{
                    count++;
                }
            }
            ((whichAxis==0)?vx:vy).push_back(count);//that is important,the last several T's
           // tx-=vx[0];//the first several step in x have decided direction.That is an error
            int start=vx[0];
            vx.erase(vx.begin());
            if(DP(vx,tx,start)&&DP(vy,ty,0))
                cout<<"Yes"<<endl;
            else
                cout<<"No"<<endl;
            return 0;

        }


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

int main() {
  int H, W;
  cin >> H >> W;
  vector<char> v(W);
  
  for(int i=0;i < W+2;i++)
    cout << '#';
  cout << endl;
  
  for(int i=0;i < H;i++){
    cout << '#';
    for(int j=0;j < W;j++){
      cin >> v.at(j);
      cout << v.at(j);
    }
    cout << '#' << endl;
  }
  
  for(int i=0;i < W+2;i++)
    cout << '#';
  cout << endl;
  
}


Measured memory_bytes: 3600