akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define fi first
#define se second
#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)
#define rng(a) a.begin(),a.end()
#define rrng(a) a.rbegin(),a.rend()
#define maxs(x,y) (x = max(x,y))
#define mins(x,y) (x = min(x,y))
#define limit(x,l,r) max(l,min(x,r))
#define lims(x,l,r) (x = max(l,min(x,r)))
#define isin(x,l,r) ((l) <= (x) && (x) < (r))
#define pb push_back
#define eb emplace_back
#define sz(x) (int)(x).size()
#define pcnt __builtin_popcountll
#define uni(x) x.erase(unique(rng(x)),x.end())
#define show(x) cout<<#x<<" = "<<x<<endl;
#define print(x)cout<<x<<endl;
#define PQ(T) priority_queue<T,v(T),greater<T> >
#define bn(x) ((1<<x)-1)
#define dup(x,y) (((x)+(y)-1)/(y))
#define newline puts("")
#define v(T) vector<T>
#define vv(T) v(v(T))
using namespace std;
typedef long long int ll;
typedef unsigned uint;
typedef unsigned long long ull;
typedef pair<int,int> P;
typedef tuple<int,int,int> T;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<P> vp;
typedef vector<T> vt;

ll dp[3300][3300];

int main() {
  int n;
  cin >> n;
  vl a(n);
  rep(i,n)cin >> a[i];

  for(int width = 1; width<=n;width++){
    for(int l = 0;l+width<=n;l++){
      int r = l+width;
      if((n-width)%2 == 0){//tarou
        dp[l][r] = max(dp[l+1][r] + a[l], dp[l][r-1]+a[r-1]);
      }
      else{
        dp[l][r] = min(dp[l+1][r] - a[l], dp[l][r-1]-a[r-1]);
      }
    }
  }
  cout<<dp[0][n]<<endl;
  return 0;
}

Measured memory_bytes: 78080
import java.util.*;
public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		int a = sc.nextInt();
		int [] in = new int [a+1];
        in[0] = 0;
        String s = "Yes";
        for(int i=1;i<a+1;i++){
                               in[i] = sc.nextInt();
                              }
        for(int i=1;i<a+1;i++){if(in[i]<in[i-1]){s="No";break;
                                                }
                              if(in[i]>in[i-1]){in[i]--;}
                              }      
		System.out.println(s);
	}
}


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

int main(){
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
	cout.tie(nullptr);
	auto no = [] {cout<<"No\n"; exit(0);};
	auto yes = [] {cout<<"Yes\n"; exit(0);};
	int n;
	cin>>n;
	vector<pair<int,int>> a(n),b(n);
	for (int i = 0; i < n; ++i)
		cin>>a[i].first;
	for (int i = 0; i < n; ++i)
		cin>>b[i].first;
	for (int i = 0; i < n; ++i)
		a[i].second = b[i].second = i;
	sort(a.begin(), a.end());
	sort(b.begin(), b.end());
	for (int i = 0; i < n; ++i) 
		if (a[i].first > b[i].first) no();
	for (int i = 1; i < n; ++i)
		if (a[i].first <= b[i - 1].first) yes();
	vector<int> to(n);
	for (int i = 0; i < n; ++i)
		to[a[i].second] = b[i].second;
	vector<bool> vis(n, false);
	function<int(int)> dfs = [&](int x) -> int {
		if (vis[x]) return 0;
		vis[x] = true;
		return 1 + dfs(to[x]);
	};
	if (dfs(0) == n)
		no();
	else 
		yes();
	return 0;
} 

Measured memory_bytes: 5376
def main():
    k, n = map(int, input().split())
    As = list(map(int, input().split()))

    diffs = [0]*n
    for i in range(n):
        if i == n-1:
            diffs[i] = k+As[0] - As[i]
        else:
            diffs[i] = As[i+1] - As[i]
    diffs.remove(max(diffs))
    ans = sum(diffs)
    print(ans)


if __name__ == "__main__":
    main()


Measured memory_bytes: 26420
import collections

def main():
    n = int(input())
    c = search(n)
    print(c)

def search(n):
    q = collections.deque()
    q.append((0, n, []))

    while q:
        cnt, rest, lst = q.popleft()
        for c in candidates(rest):
            if c == rest:
                return cnt + 1
            elif c < rest:
                q.append((cnt + 1, rest - c, lst + [c]))

def candidates(n):
    if n < 6:
        return [1]
    elif n < 9:
        return [6, 1]
    else:
        s = []
        p = 9
        while p <= n:
            p *= 9
        s.append(p // 9)

        q = 6
        while q <= n:
            q *= 6
        s.append(q // 6)

        return s

main()

Measured memory_bytes: 9716
/*
これを入れて実行
g++ code.cpp
./a.out
 */

#include <iostream>
#include <vector>
#include <string>
#include <queue>
#include <algorithm>
#include <utility>
#include <set>
#include <map>
#include <cmath>
#include <tuple>
#include <iomanip>

using namespace std;
typedef long long ll;
typedef long double ld;

int dy4[4] = {-1, 0, +1, 0};
int dx4[4] = {0, +1, 0, -1};
int dy8[8] = {-1, -1, 0, 1, 1, 1, 0, -1};
int dx8[8] = {0, 1, 1, 1, 0, -1, -1, -1};

const long long INF = 1LL << 60;
const ll MOD = 1e9 + 7;

bool greaterSecond(const pair<int, int>& f, const pair<int, int>& s){
    return f.second > s.second;
}

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

ll lcm(ll a, ll b){
    return a / gcd(a, b) * b;
}

ll nCr(ll n, ll r){
    if(r == 0 || r == n){
        return 1;
    } else if(r == 1){
        return n;
    }
    return (nCr(n - 1, r) + nCr(n - 1, r - 1));
}

ll nPr(ll n, ll r){
    r = n - r;
    ll ret = 1;
    for (ll i = n; i >= r + 1; i--) ret *= i;
    return ret;
}

//-----------------------ここから-----------

int main(void){
    int h, w;
    cin >> h >> w;

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

    for(int i = 0; i < h; i++){
        s[i].insert(s[i].begin(), '#');
        s[i].push_back('#');
    }

    string frame = "";
    for(int i = 0; i < w + 2; i++){
        frame += "#";
    }
    s.insert(s.begin(), frame);
    s.push_back(frame);

    for(int i = 0; i < s.size(); i++){
        cout << s[i] << endl;
    }
}

Measured memory_bytes: 256
N,K=list(map(int,input().split()))
A=list(map(int,input().split()))
S=sum(A)
facts=set()
for i in range(1,int(S**0.5)+1):
    if S%i==0:
        facts.add(i)
        facts.add(S//i)
for f in sorted(facts,key=lambda x:-x):
    rs = [i%f for i in A]
    rs2=sorted(rs)
    rsr = [f-r for r in rs2]
    if f-rs2[-1]>K and rs2[-1]>K:
        continue
    cum=0
    ruiseki=[0]*(N)
    tmp=0
    for i,a in enumerate(rs2):
        cum+=a
        ruiseki[i]=cum
    for i in range(N-1):
        s_l=ruiseki[i]
        s_h = f*(N-i-1)-(ruiseki[-1]-s_l)
        if max(s_l,s_h)<=K:
            print(f)
            break
    else:
        continue
    break

Measured memory_bytes: 3188
#pragma GCC optimize("O3")
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using P = pair<ll,ll>;
using vl = vector<ll>;
using Map = map<ll,ll>;
using Tup = tuple<ll,ll,ll>;
using vvl = vector<vector<ll>>;
#define all(v) v.begin(), v.end()
#define prt(v) cout<<(v)<<"\n";
#define fl cout<<flush;
#define fi(v) get<0>(v)
#define se(v) get<1>(v)
#define th(v) get<2>(v)
#define endl '\n'
template <typename T> inline bool chmax(T &a, const T &b){if (a<b){a=b;return 1;}return 0;}
template <typename T> inline bool chmin(T &a, const T &b){if (a>b){a=b;return 1;}return 0;}
const ll INF=1LL<<60;
//const ll MOD=1e9+7;
const ll MOD=998244353;
const ld pi=3.14159265358979323846;
const ld eps=1e-10;


signed main(void){
    cin.tie(0);cout.tie(0);ios::sync_with_stdio(false);
    string S;
    cin >> S;
    ll N=S.size()+1;
    ll Min=0;
    vector<ll> A(N,0);
    vector<ll> L(N,0);
    vector<ll> R(N,0);
    for(ll i=0;i<N-1;++i){
        if(S[i]=='<'){
            L[i+1]=L[i]+1;
        }
        else L[i+1]=0;
    }
    for(ll i=N-2;i>=0;--i){
        if(S[i]=='>'){
            R[i]=R[i+1]+1;
        }
        else R[i]=0;
    }
    ll ans=0;
    for(ll i=0;i<N;++i)ans+=max(L[i],R[i]);
    prt(ans)fl

    return 0;
}


Measured memory_bytes: 12572
import java.util.*;
public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int M = sc.nextInt();
		List<Integer>[] edge = new ArrayList[N];
		for(int i = 0; i < N; i++)
		    edge[i] = new ArrayList<>();
		for (int i = 0; i < M; i++) {
		    int a = sc.nextInt()-1;
		    int b = sc.nextInt()-1;
		    edge[a].add(b);
		    edge[b].add(a);
		}
		int[] ans = new int[N];
		Queue<Integer> s = new ArrayDeque<>();
		s.offer(0);
		while(s.size() > 0) {
			int x = s.poll();
			for(int i : edge[x]) {
				if(ans[i] == 0) {
					ans[i] = x+1;
					s.add(i);					
				}
			}
		}
		System.out.println("Yes");
		for(int i = 1; i < N; i++)
			System.out.println(ans[i]);
	}

}

Measured memory_bytes: 77300
#define _USE_MATH_DEFINES
#include <array>
#include <cassert>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <string>
#include <sstream>
#include <vector>
#include <queue>
#include <stack>
#include <list>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <algorithm>
#include <complex>
#include <cmath>
#include <numeric>
#include <bitset>
#include <functional>
#include <random>
#include <ctime>

using namespace std;

#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
  cerr << name << ": " << arg1 << endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
  const char* comma = strchr(names + 1, ',');
  cerr.write(names, comma - names) << ": " << arg1 << " |";
  __f(comma + 1, args...);
}

typedef long long int64;
typedef pair<int, int> ii;
const int INF = 1 << 29;
const int MOD = 1e9 + 7;
mt19937 mrand(random_device{}());
int rnd(int x) { return mrand() % x; }

int main() {
  int n;
  scanf("%d", &n);
  vector<ii> a;
  for (int i = 0; i < n; ++i) {
    int x, len;
    scanf("%d%d", &x, &len);
    a.emplace_back(x + len, x - len);
  }
  sort(a.begin(), a.end());
  vector<int> dp(n);
  for (int i = 0; i < n; ++i) {
    dp[i] = 1;
    int k = upper_bound(a.begin(), a.begin() + i, ii{a[i].second, 2e9}) - a.begin();
    // trace(i, k);
    if (k > 0) dp[i] = 1 + dp[k - 1];
    if (i > 0) dp[i] = max(dp[i], dp[i - 1]);
  }
  printf("%d\n", dp[n - 1]);
  return 0;
}


Measured memory_bytes: 1400
#include <stdio.h>

int main()
{
  int n,s[100000],q,t[50000],i,count=0,right,left,mid;

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

  for(i=0;i < q;i++){
    left = 0;
    right = n;
    while(left < right){
      mid = (left + right) / 2;
      if(s[mid]==t[i]){
	count++;
	break;
      }
      else if(t[i] < s[mid]){
	right = mid;
      }
      else left = mid + 1;
    }
  }
  printf("%d\n",count);
  return 0;
}

Measured memory_bytes: 1184
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <stdbool.h>

#define POW_10_5 100100
#define MAX_INPUTSTR_LEN POW_10_5 // 読み込む文字列の長さの最大値
#define MAX_Q_LEN (2 * POW_10_5) // Q の最大値

// #define GBN6500_DEBUG

char *buffer, *prevPtr, *postPtr;
int Q;
bool isReversed; // 反転状態なら true

void InvertString(char *str)
{
    int len = strlen(str);
    char *tmp = (char *)malloc(len + 10);
    for (int i = 0; i < len; ++i)
        tmp[i] = str[len - i - 1];
    tmp[len] = '\0';
    strcpy(str, tmp);
    free(tmp); 
}

void Solve()
{
  int T, F;
  char C;
  for (int i = 0; i < Q; ++i){
    scanf("%d", &T);
    if (T == 1){
      isReversed = !isReversed;
    } else {
      scanf("%d %c", &F, &C);
      if (F == 1)
        if (!isReversed) *prevPtr = C, --prevPtr; // 一文で書けると思うけどよくわからないのでカンマで誤魔化した
        else *postPtr = C, ++postPtr;
      else
        if (!isReversed) *postPtr = C, ++postPtr;
        else *prevPtr = C, --prevPtr;
      }

#ifdef GBN6500_DEBUG
printf("i = %d, type = %d, isReversed = %d, ans = [%s]\n", i, T, isReversed, prevPtr + 1);
#endif

  } // end for
  *postPtr = '\0';
  char *ans = (char *)(prevPtr + 1);

  if (isReversed) InvertString(ans);

  puts(ans);
}

void Init()
{
#define ALLOC_MEM_SIZE (MAX_Q_LEN + MAX_INPUTSTR_LEN + MAX_Q_LEN)
  // 制約の最大値（＋α）でヒープにメモリーを確保
  // これだけ確保しても約 800KB なので、メモリー制限にはひっかからない（と思う）
  buffer = (char *)malloc(ALLOC_MEM_SIZE);
#ifdef GBN6500_DEBUG
memset(buffer, 0, ALLOC_MEM_SIZE); // 46行目の printfデバッグ用
#endif

  isReversed = false;

  scanf("%s %d", buffer, &Q);
  prevPtr = buffer + MAX_Q_LEN;
  postPtr = prevPtr + strlen(buffer) + 1;
  strcpy(prevPtr + 1, buffer); // buffer の前に MAX_Q ぶんのスペースを開ける。文字を前に追加する時はこのスペースを利用。
}

void Clean()
{
  free(buffer);
}

int main(){ Init(); Solve(); Clean(); return 0; }


Measured memory_bytes: 768
n, p = map(int, input().split())
a = list(map(int, input().split()))

odd = sum([item % 2 for item in a])
even = n - odd

ans = 0
if even == n:
    if p == 1:
        print(0)
    else:
        print(2 ** n)
elif n == 1 and odd == 1 and p == 0:
    print(0)
else:
    # 偶数枚入った袋は選ぶor選ばない自由
    ans += 2 ** even
    # 奇数枚入った袋は2で割って余りがPになるよう選ぶ個数を決める
    ans *= 2 ** (odd - 1)
    print(ans)

Measured memory_bytes: 38376
#include <stdio.h>
void memorec(double p_q,int beforeDenom,int prod,int count);
int ans = 0;
int p,q,a,n;

int main() {
  while(1){
    scanf("%d",&p);
    scanf("%d",&q);
    scanf("%d",&a);
    scanf("%d",&n);
    if(p == 0 && q == 0 && a == 0 && n == 0) return 0;
    memorec((double)p/(double)q,1,1,1);
    printf("%d\n",ans);
    ans = 0;
  }
}

void memorec(double p_q,int beforeDenom,int prod,int count){
  double denominator = beforeDenom;
  double result;
  while(1){
    if(prod*denominator>a) return;
    result = p_q - 1/denominator;
    if(result < 0.00000001 && result > -0.00000001){
      ans++;
      denominator++;
      continue;
    }
    if(result > 0){
      if(count+1 > n) return;
      memorec(result,denominator,prod*denominator,count+1);
    }
    denominator++;
  }
}

Measured memory_bytes: 600
#include<stdio.h>
#include<stdlib.h>
#include<string.h>

int top,S[1000];

void push(int x){
    S[++top] = x;
}

int pop(){
    top--;
    return S[top+1];
}

int main(){
    int a,b;
    top = 0;
    char s[100];
    while( scanf("%s",s) != EOF){
        if(s[0] == '+'){
            a = pop();
            b = pop();
            push(a+b);
        }else if(s[0] == '-'){
            b = pop();
            a = pop();
            push(a-b);
        }else if(s[0] == '*'){
            a = pop();
            b = pop();
            push(a * b);
        }else{
            push(atoi(s));
        }
    }
    printf("%d\n",pop());

    return 0;
}


Measured memory_bytes: 2148
#include <iostream>
#include <string>
#include <vector>
#include <stdio.h>
#include <algorithm>
#define _USE_MATH_DEFINES
#include <cmath>
#include <numeric>
#include <iomanip>
#include <deque>
#include <tuple>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <unordered_map>
#include <sstream>
#include <stdexcept>
#include <boost/multiprecision/cpp_int.hpp>
#include <boost/multiprecision/cpp_dec_float.hpp>

#define rep(i, x) for (int i = 0; i < (int)(x); i++)
#define FOR(i, a, done) for (int i = (a); i < (done); ++i)
#define all(a) (a).begin(), (a).end()
#define F first
#define S second
#define x first
#define y second
#define pb push_back
#define pf push_front
#define debug(a) cout << (a) << endl
namespace mp = boost::multiprecision;
using cpp_int = mp::cpp_int;
using ll = long long;
using namespace std;

ll M = 1000000007;


void solve()
{
	 	int n,r;
		 cin>>n>>r;
		 if(n<10){
			 cout<<r+100*(10-n)<<endl;
		 }else{
			 cout<<r<<endl;
		 }
}

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


Measured memory_bytes: 256
#[allow(unused_imports)]
use std::io;
#[allow(unused_imports)]
use std::cmp;
use std::collections::LinkedList;

#[allow(dead_code)]
fn getline() -> LinkedList<String> {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok().unwrap();
    s.split(' ').map(|x| x.trim().to_string()).collect::<LinkedList<String>>()
}

#[allow(dead_code)]
fn get<T: std::str::FromStr>(l: &mut LinkedList<String>) -> T {
    l.pop_front().and_then(|s| s.parse().ok()).unwrap()
}

fn main() {
    let mut l = getline();
    let n: usize = get(&mut l);
    let a: i64 = get(&mut l);
    let b: i64 = get(&mut l);
    let c = a - b;
    let hs: Vec<i64> = (0..n).map(|_| get(&mut getline())).collect();
    let mut l = 0i64;
    let mut r = 1e9 as i64;
    while l + 1 != r {
        let m = (l + r) / 2;
        if possible(c, b, &hs, m) {
            r = m;
        } else {
            l = m;
        }
    }
    println!("{}", r);
}

fn possible(c: i64, b: i64, hs: &Vec<i64>, m: i64) -> bool {
    let sum = hs.iter().map(|h| {
        let rem = cmp::max(0, h - m * b);
        (rem + c - 1) / c
    }).fold(0, |sum, x| sum + x);
    sum <= m
}


Measured memory_bytes: 4352
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef unsigned long long int ull;
#define IO ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
int main(){
    ll a , b , c ,d  ;
    cin>>a>>b>>c>>d;
    cout<<max({a*c,a*d,b*c,b*d})<<endl;
}

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

using namespace std;

int main() {
    string s;
    cin>>s;
    int ans=0;
    for(int i=0;i<s.size();i++){
        ans+=s[i]-48;
    }
    if(ans%9)cout<<"No\n";
    else cout<<"Yes\n";
    return 0;
}

Measured memory_bytes: 3752
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<queue>
#include<unordered_map>
#include<stack>
#include<random>
#include<set>
#include<map>
#include<functional>
using namespace std;
#define int long long
#define inf 1145141919
#define rep(i,n) for(int i=0;i<n;i++)
typedef pair<int, int>P;
typedef pair<int, P> PP;
struct edge { P to; int cost; };
const long long mod = 1000000007;
int a[114];
signed main() {
	int n; cin >> n;
	rep(i, n)cin >> a[i];
	double sum = 0;
	rep(i, n)sum += a[i];
	sum /= (double)n;
	double dif = 1145141919;
	int nm = 0;
	rep(i, n) {
		if (abs((double)a[i] - sum) < dif) {
			nm = i;
			dif = abs((double)a[i] - sum);
		}
	}
	cout << nm << endl;
}

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

int main(){
  int a, b;
  cin >> a >> b;
  
  if ((a + b) % 2 == 0){
    cout << (a + b) / 2 << endl;
  }else{
    cout << (a + b) / 2 + 1 << endl;
  }
}

Measured memory_bytes: 256
def get_i() #空白区切の入力を数値(整数)の配列で返す
  return gets.chomp.split(" ").map(&:to_i)
end
def get_f() #空白区切の入力を数値(実数)の配列で返す
  return gets.chomp.split(" ").map(&:to_f)
end
def get() #空白区切の入力を文字列の配列で返す
  return gets.chomp.split(" ")
end
def get_nsp() #入力されたものを一文字ずつに区切った文字列の配列で返す
  return gets.chomp.split("")
end
def yn_judge(bool,y="Yes",n="No") #boolに真偽を投げることで、trueならy、falseならnの値を出力する
  return bool ? y : n 
end
def array(size1,init=nil,size2=-1) #size2に二次元配列時の最初の要素数、size1に次の配列の大きさ、initに初期値を投げることでその配列を返す
  if size2==-1
    return Array.new(size1){init}
  else
    return Array.new(size2){Array.new(size1){init}}
  end
end
N,M=get_i
A=get_i.sort
bc=array(M)
M.times do|i|
    bc[i]=get_i
end
bc.sort!{|x,y| y[1]<=>x[1]}
ans=0
i=0
A.each do|a|
  if i<M and a<bc[i][1] and bc[i][0]>0
    ans+=bc[i][1]
    bc[i][0]-=1
  elsif i<M and bc[i][0].zero?
     i+=1
     if i<M and a<bc[i][1]
         ans+=bc[i][1]
         bc[i][0]-=1
     else
        ans+=a
     end 
  else
      i+=1 if i<M and a>bc[i][1]
      ans+=a
  end
end
puts ans

Measured memory_bytes: 13576
#include <algorithm>
//#include <atcoder/fenwicktree>
#include "atcoder/all"
#include <bitset>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <regex>
#include <set>
#include <stack>
#include <string>
#include <vector>

using namespace std;
using namespace atcoder;

const int MOD = 1e9 + 7;
const int iINF = 2147483647 / 2;
const long long int llINF = 9223372036854775807 / 2;

using ll = long long int;
using vl = vector<ll>;
using vvl = vector<vector<ll>>;
using vvvl = vector<vector<vector<ll>>>;

typedef pair<ll, ll> pll;
bool paircomp(const pll &a, const pll &b) {
  if (a.first == b.first)
    return a.second < b.second;
  return a.first < b.first;
}

#define REP(i, n) for (ll i = 0; i < (n); i++)
#define RREP(i, n) for (ll i = (n)-1; i >= 0; i--)
#define FOR(i, a, b) for (ll i = (a); i < (b); i++)
#define AUTO(i, m) for (auto &i : m)
#define ALL(a) (a).begin(), (a).end()
#define MAX(vec) *std::max_element(vec.begin(), vec.end())
#define MIN(vec) *std::min_element(vec.begin(), vec.end())
#define ARGMAX(vec)                                                            \
  std::distance(vec.begin(), std::max_element(vec.begin(), vec.end()))
#define ARGMIN(vec)                                                            \
  std::distance(vec.begin(), std::min_element(vec.begin(), vec.end()))
#define REV(T) greater<T>()
#define PQ(T) priority_queue<T, vector<T>, greater<T>>
#define VVL(a, b, c) vector<vector<ll>>(a, vector<ll>(b, c))
#define VV(T, a, b, c) vector<vector<T>>(a, vector<T>(b, c))
#define VVVL(a, b, c, d)                                                       \
  vector<vector<vector<ll>>>(a, vector<vector<ll>>(b, vector<ll>(c, d)))
#define VVV(T, a, b, c, d)                                                     \
  vector<vector<vector<T>>>(a, vector<vector<T>>(b, vector<T>(c, d)))
#define SP(a) fixed << setprecision(a)
#define SQRT(a) sqrt((long double)(a))
#define DPOW(a, b) pow((long double)(a), (long double)(b))
#define UNIQUE(vec)                                                            \
  do {                                                                         \
    sort(ALL((vec)));                                                          \
    (vec).erase(std::unique(ALL((vec))), (vec).end());                         \
  } while (0)

ll POW(ll n, ll m) {
  if (m == 0) {
    return 1;
  } else if (m % 2 == 0) {
    ll tmp = POW(n, m / 2);
    return (tmp * tmp);
  } else {
    return (n * POW(n, m - 1));
  }
}

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

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  ll N, Q;
  cin >> N >> Q;
  fenwick_tree<ll> fw(N);
  REP(i, N) {
    int A;
    scanf("%d", &A);
    fw.add(i, A);
  }
  REP(i, Q) {
    ll t = 0;
    cin >> t;
    ll x1, x2;
    cin >> x1 >> x2;
    if (t == 0)
      fw.add(x1, x2);
    else
      cout << fw.sum(x1, x2) << endl;
  }

  return 0;
}


Measured memory_bytes: 8236
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
ll k;
int main(void){
    string s; cin>>s;
    for(int i=0;i<s.size();i++){
        k+=(s[i]-'0');
    }
    if(k%9==0){
        cout<<"Yes"<<endl;
    }else{
        cout<<"No"<<endl;
    }

}



Measured memory_bytes: 3724
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
using P   = pair<ll, ll>;
using mat = vector<vector<ll>>;

void IOS() { ios::sync_with_stdio(false), cin.tie(0); }

const ll INF = 1e16;
const ll MOD = 1e9 + 7;
const ld EPS = 1e-12;

template <typename T> void dump(T x) { cout << x << endl; }
void dumpf(ld x, int t) { cout << setprecision(t) << fixed << x << endl; }
template <typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val) {
	fill((T *)array, (T *)(array + N), val);
}

inline ll mod(ll a, ll b) {
	if (a > 0) return a % b;
	if (a % b == 0) return 0;
	ll x = -a / b + 1;
	a += x * b;
	return a % b;
}

// ll dx[4] = {1, 0, -1, 0};
// ll dy[4] = {0, 1, 0, -1};

int main() {
	IOS();
	ll n, m;
	cin >> n >> m;
	vector<P> a(n);
	for (int i = 0; i < n; i++) {
		cin >> a[i].first >> a[i].second;
	}
	sort(a.begin(), a.end());
	ll cnt = 0;
	ll sum = 0;
	for (int i = 0; i < n; i++) {
		if (m - cnt <= a[i].second) {
			sum += (m - cnt) * a[i].first;
			break;
		} else {
			sum += a[i].first * a[i].second;
			cnt += a[i].second;
		}
	}
	dump(sum);
	return 0;
}

Measured memory_bytes: 1792
<?php
 list($n, $y) = explode(" ", fgets(STDIN));
 $max = $n;
 $man = 10000;
 $gosen = 5000;
 $sen = 1000;
 $no_flg = true;
 $ans =[];
 for($i=0; $i<=$max; $i++){
 	$test =0;
 	$test += $man * $i;
 	for($j=0; $j<=$max-$i; $j++){
 		$test2 = $test;
 		$test2 += $gosen*$j;
 		$test2 += $sen*($max-$i-$j);
 		if($test2==$y){
 			$ans =[$i, $j, $max-$i-$j];
 			$no_flg = false;
 			break; 
 		}
 	}
 }

echo ($no_flg ? "-1 -1 -1" : implode(" ", $ans)) . "\n";

 ?>

Measured memory_bytes: 4604
#include <iostream>
using namespace std;
int main(void){
    // Your code here!
    int n;
    cin>>n;
    int a[n];
    int i,s;
    for(i=0;i<n;i++)
    {
        cin>>a[i];//n個格納した
    }
    for(s=0;s<n;s++)
    {
        if(s==n-1)
        {
            cout<<a[n-s-1];
        }
        else
        {
            cout<<a[n-s-1]<<" ";
        }
    }
    cout<<endl;
    return 0;
}



Measured memory_bytes: 3072
#include <iostream>
#include <vector>
#include <algorithm>
#include <numeric>
#include <set>
#include <map>
#include <string>
#include <stack>
#include <queue>
#include <cmath>
#include <cstdio>
#include <istream>
#include <sstream>
#include <iomanip>
using namespace std;

typedef ostringstream oss;
typedef istringstream iss;

int main(void) {
	int length;
	long num;
	while (cin >> num >> length, num || length) {
		cin.ignore();
		vector<string> stk;
		
		while (true) {
			oss stream;
			stream << setw(length) << setfill('0') << num;
			string str1 = stream.str();
			string str2 = str1;
			vector<string>::iterator it = find(stk.begin(), stk.end(), str1);
			if (it != stk.end() && stk.size() != 0) {
				cout << it - stk.begin() << " " << atoi(str1.c_str()) << " "  << stk.end() - it << endl;
				break;
			}
			stk.push_back(str1);

			sort(str1.begin(), str1.end());
			sort(str2.begin(), str2.end(), greater<int>());

			num = atol(str2.c_str()) - atol(str1.c_str());
		}
	}

	return 0;
}

Measured memory_bytes: 1264
#include<bits/stdc++.h>
#define rep(i,start,lim) for(lld i=start;i<lim;i++)
#define repd(i,start,lim) for(lld i=start;i>=lim;i--)
#define scan(x) scanf("%lld",&x)
#define print(x) printf("%lld ",x)
#define f first
#define s second
#define pb push_back
#define mp make_pair
#define br printf("\n")
#define sz(a) lld((a).size())
#define YES printf("YES\n")
#define NO printf("NO\n")
#define all(c) (c).begin(),(c).end()
using namespace std;
#define INF         1011111111
#define LLINF       1000111000111000111LL
#define EPS         (double)1e-10
#define MOD         1000000007
#define PI          3.14159265358979323
using namespace std;
typedef long double ldb;
typedef long long lld;
lld powm(lld base,lld exp,lld mod=MOD) {lld ans=1;while(exp){if(exp&1) ans=(ans*base)%mod;exp>>=1,base=(base*base)%mod;}return ans;}
typedef vector<lld> vlld;
typedef pair<lld,lld> plld;
typedef map<lld,lld> mlld;
typedef set<lld> slld;
#define N 1000005
lld n,a[N];
int main()
{
	cin>>n;
	rep(i,1,n+1) cin>>a[i];
	if(n==1) {
		return cout<<a[1],0;
	}
	if(n%2==0) {
		for(lld j=n;j>=2;j-=2) cout<<a[j]<<" ";
		for(lld j=1;j<n;j+=2) cout<<a[j]<<" ";
	}
	else {
		for(lld j=n;j>=1;j-=2) cout<<a[j]<<" ";
		for(lld j=2;j<n;j+=2) cout<<a[j]<<" ";
	}
	return 0;
}

Measured memory_bytes: 3712
#include<iostream>
#include<cstring>
#include<vector>
using namespace std;
int main()
{
  int p[60000];
  memset(p,0,sizeof(p));
  for(int i=2;i<30000;i++)
    if(p[i]==0)
	for(int j=i+i;j<60000;j+=i)
	  p[j]=1;
  int n;
  for(;cin>>n,n;)
    {
      int count=0;
	  for(int i=2;i<=n/2;i++)
	    if(p[i]==0 && p[n-i]==0)
	      count++;
      cout<<count<<endl;
    }
}

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

int main(int args, char *argv[])
{

    int N;
    cin >> N;

    vector<pair<int, int>> v1;
    for (int i = 0; i < N; i++)
    {
        int a, b;
        cin >> a;
        cin >> b;
        v1.push_back({a, b});
    }

    vector<pair<int, int>> v2;
    for (int i = 0; i < N; i++)
    {
        int c, d;
        cin >> c;
        cin >> d;
        v2.push_back({c, d});
    }

    sort(v1.begin(), v1.end());
    sort(v2.begin(), v2.end());

    map<int, bool> tmp1;
    map<int, bool> tmp2;
    int ret = 0;

    for (int j = 0; j < v2.size(); j++)
    {
        int mx = -1;
        int tmp = 0;
        for (int i = v1.size() - 1; i >= 0; i--)
        {
            if (v1[i].first < v2[j].first && v1[i].second < v2[j].second)
            {
                if (!tmp1[i] && !tmp2[j])
                {
                    if (v1[i].second >= tmp)
                    {
                        mx = i;
                        tmp = v1[i].second;
                    }
                }
            }
        }

        if (mx >= 0)
        {
            tmp1[mx] = true;
            tmp2[j] = true;
            ret++;
        }
    }

    cout << ret << endl;
}


Measured memory_bytes: 256
import java.util.Scanner;

/**
 * Created by labuser on 2016/04/18.
 */
public class Main {
    public static void main(String[] args) {
        new Main().run();

    }

    private void run() {
        int a;
        int b;
        int c;

        Scanner sc = new Scanner(System.in);
        String[] input = sc.nextLine().split(" ");
        a = Integer.parseInt(input[0]);
        b = Integer.parseInt(input[1]);
        c = Integer.parseInt(input[2]);

        if ((a < b) && (b < c)) {
            System.out.println("Yes");
        } else {
            System.out.println("No");
        }
    }
}

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

#define rep(i, n) for (int i = 0; i < (n); i++)
#define REP(i, s, n) for (int i = (s); i < (n); i++)
#define all(co) begin(co), end(co)

int main() {
	int h, w;
while (cin >> h >> w && h) {
	int l = h * h + w * w;
	using t = tuple<int, int, int>;
	t ans = t(1<<29,-1,-1);
	REP(i, 1, 151) REP(j, i+1, 151) {
		int dl = (i * i + j * j);
        if(dl == l && i > h && get<0>(ans) > dl) ans = t(dl, i, j);
		if(dl > l && get<0>(ans) > dl) ans = t(dl, i, j);
	}
	cout << get<1>(ans) << " " << get<2>(ans)<< endl;
}
}

Measured memory_bytes: 3104
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
        int k = sc.nextInt();

        if (k % 2 == 0) {
        	System.out.println(k / 2 * k / 2);
        } else {
        	System.out.println((k + 1) / 2 * (k / 2));
        }
	}
}


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

int main()
{
	int n;
	cin >> n;
	string s;
	map<string, int> m;
	for (int i = 0; i < n; ++i)
	{
		cin >> s;
		m[s]++;
	}
	
	int cnt = 0;
	for (auto x : m)
	{
		if (x.second >= 1)
		{
			cnt++;
		}
	}
	
	cout << cnt << endl;
	
	return 0;
}


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

using namespace std;
#define loop(i,n) for(int i = 0; i < (n); i++)
#define loops(i,f,n) for(int i = (f); i < (n); i++)
#define INF 9999999
#define in(a) cin>>a
#define out(a) cout<<a<<endl

int main()
{
	int n;
	int y;
	cin >> n >> y;
	bool found = false;
	loop(i, n + 1)
	{
		if (found)break;
		loop(j, n + 1)
		{
			if (found)break;
			int money_tmp = 10000 * i + 5000 * j;
			if (((y - money_tmp) % 1000 == 0) && ((y - money_tmp) / 1000>=0)&&(i + j + (y - money_tmp) / 1000 == n))
			{
				cout << i << " " << j << " " << (y - money_tmp) / 1000 << endl;
				found = true;
			}
		}
	}
	if (!found)cout << "-1 -1 -1" << endl;
}


Measured memory_bytes: 256
import sys,heapq,math,resource
from collections import deque,defaultdict
printn = lambda x: sys.stdout.write(x)
inn = lambda : int(input())
inl   = lambda: list(map(int, input().split()))
inm   = lambda:      map(int, input().split())
DBG = True # and False
R = 10**9 + 7

def ddprint(x):
  if DBG:
    print(x)

def setrlim():
  sys.setrecursionlimit(250000)
  soft,hard = resource.getrlimit(RLIMIT_STACK)
  # setrlimit works on ubuntu (and atcoder), but not on WSL
  #resource.setrlimit(RLIMIT_STACK, (128*1024*1024,hard))

n = inn()
p = inl()
dif = 0
for i in range(n):
    if p[i] != i+1:
        dif += 1
print("YES" if dif <= 2 else "NO")


Measured memory_bytes: 3444
#include <bits/stdc++.h>
#define MAXN 1000007
using namespace std;
int pb[MAXN],a[MAXN];
int main()
{
	int n;
	cin>>n;
	for(int i=0;i<n;i++) pb[i]=((i&(n-1))==i)?1:0;
	string s;
	cin>>s;
	for(int i=0;i<n;i++) a[i]=s[i]-'1';
	int p=0;
	for(int i=0;i<n;i++) p+=pb[i]*a[i];
	if(p&1) {printf("1"); return 0;}
	bool sp=true;
	for(int i=0;i<n;i++) if(a[i]&1) sp=false;
	if(!sp) {printf("0"); return 0;}
	int pn=0;
	for(int i=0;i<n;i++) pn+=pb[i]*(a[i]/2);
	if(pn&1) {printf("2"); return 0;}
	printf("0");
}

Measured memory_bytes: 9220
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<cmath>
using namespace std;
int n;
long long a[200010];
long long b[200010];
long long ans,min_n=2147483647;
bool flag;
int main()
{
	cin>>n;
	for(int i=1;i<=n;i++)
	{
		cin>>a[i]>>b[i];
		ans+=a[i];
		if(a[i]>b[i]) min_n=min(min_n,b[i]);
	}
	if(min_n==2147483647)
	{
		cout<<"0"<<endl;
		return 0;
	}
	cout<<ans-min_n<<endl;
	return 0;
}

Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
#define REP(i, a, b) for (int i = (int)(a); i < (int)(b); i++)
#define rep(i, n) REP(i, 0, n)
#define rrep(i, n) for (int i = (int)(n-1); i >= 0; i--)
#define sz(x) int(x.size())
#define bitsz(x) int(__builtin_popcount(x))
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define pb(x) push_back(x)
#define INF 1e9
#define LINF 1e18
#define mod 1000000007
template<class T> inline bool chmax(T &a, const T &b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T &a, const T &b) { if (a > b) { a = b; return 1; } return 0; }
template < typename T > inline string toString( const T &a ) { ostringstream oss; oss << a; return oss.str(); };
typedef long long ll;
typedef pair<int, int> P;
typedef pair<ll, ll> LP;
const int di[4] = {1,0,-1,0};
const int dj[4] = {0,1,0,-1};


int main() {
    int n; cin >> n;
    vector<P> d(n);
    rep(i,n) {
        int a,b; cin >> a >> b;
        d[i] = P(a,b);
    }
    bool check1 = false, check2 = false, check3 = false;
    rep(i,n) {
        if (d[i].first!=d[i].second) {
            check1 = false;
            check2 = false;
            check3 = false;
            continue;
        }
        if (!check1 && d[i].first==d[i].second) {
            check1 = true;
            continue;
        }
        if (check1 && !check2 && d[i].first==d[i].second) {
            check2 = true;
            continue;
        }
        if (check1 && check2 && d[i].first==d[i].second) {
            check3 = true;
            cout << "Yes" << endl;
            return 0;
        }

    }
    cout << "No" << endl;
}

Measured memory_bytes: 3628
import java.util.*;
public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int k = sc.nextInt();
        Integer[] h = new Integer[n];
        long sum = 0;
        for (int i = 0; i < h.length; i++) {
            h[i] = sc.nextInt();
        }
        Arrays.sort(h, Collections.reverseOrder());
        for (int i = k; i < h.length; i++) {
            sum += h[i];
        }
        System.out.println(sum);
        sc.close();
    }
}

Measured memory_bytes: 94608
#include "bits/stdc++.h"
using namespace std;

typedef long long ll;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
typedef pair<ll, ll> P;
#define rep(i, n) for(ll i = 0; i < n; i++)
#define REP(i, a, b) for(ll i = a; i <= b; i++)
#define out(x) std::cout << x << '\n'
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define pb push_back
#define sz(x) ((int)(x).size())
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }
ll lcm(ll a, ll b) { ll g = gcd(a, b); return a / g * b; }
const int dx[4] = { 1, 0, -1,  0 };
const int dy[4] = { 0, 1,  0, -1 };
const int INF = INT_MAX / 2;
const ll  inf = LLONG_MAX / 2;
const int mod = 1000000007;
const int MAX_N = 101010;
const long double PI = acos(-1);

int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	cout << fixed << setprecision(10);
	/*------------------------------*/

	ll a, b;
	cin >> a >> b;

	ll l = lcm(a, b);

	out(l);

	return 0;
}

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

int main(){
  int n,i,flag=0;
  char s[110000];
  scanf("%s",s);
  n=strlen(s);
  for(i=0;i<n-2;i++){
    if(s[i]==s[i+1]){
      flag=1;
      break;
    }
    else if(s[i]==s[i+2]){
      flag=2;
      break;
    }
  }
  if(s[i]==s[i+1])
    flag=1;
  if(flag)
    printf("%d %d\n",i+1,i+1+flag);
  else
    printf("-1 -1\n");
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const int N = 105;
const ll m = (ll)1e9 + 7;
int n;
ll dp[N][5][5][5];

// 0 -> A, 1 -> C, 2 -> G, 3 -> T

ll add(ll a , ll b) {
   return ((a % m) + (b % m)) % m;
}

int cantGoTo3(int oneBefore , int twoBefore) {
   if (oneBefore == 2 && twoBefore == 0) return 1;
   else if (oneBefore == 0 && twoBefore == 2) return 1;
   else if (oneBefore == 1 && twoBefore == 0) return 2;
   else return -1;
}

int cantGoTo4(int oneBefore , int twoBefore , int threeBefore) {
   if (oneBefore == 2 && twoBefore == 0) return 1;
   else if (oneBefore == 0 && twoBefore == 2) return 1;
   else if (oneBefore == 1 && twoBefore == 0) return 2;
   else if (threeBefore == 0 && twoBefore == 3 && oneBefore == 2) return 1;
   else if (threeBefore == 0 && twoBefore == 2 && oneBefore == 2) return 1;
   else if (threeBefore == 0 && twoBefore == 1 && oneBefore == 2) return 1;
   else if (threeBefore == 0 && twoBefore == 2 && oneBefore == 0) return 1;
   else if (threeBefore == 0 && twoBefore == 2 && oneBefore == 3) return 1;
   else return -1;
}

ll f(int curr , int prv , int prv2 , int prv3) {
   if (curr > n) return 1;
   ll &sol = dp[curr][prv][prv2][prv3];
   if (sol != -1) return sol;
   sol = 0;
   if (prv == 4) {
      for (int v = 0 ; v < 4 ; v++) {
         sol = add(sol , f(curr + 1 , v , 4 , 4));
      }
   } else if (prv2 == 4) {
      for (int v = 0 ; v < 4 ; v++) {
         sol = add(sol , f(curr + 1 , v , prv , 4));
      }
   } else if (prv3 == 4) {
      int x = cantGoTo3(prv , prv2);
      for (int v = 0 ; v < 4 ; v++) {
         if (v != x) {
            sol = add(sol , f(curr + 1 , v , prv , prv2));
         }
      }
   } else {
      int x = cantGoTo4(prv , prv2 , prv3);
      for (int v = 0 ; v < 4 ; v++) {
         if (v != x) {
            sol = add(sol , f(curr + 1 , v , prv , prv2));
         }
      }
   }
   return sol;
}

int main() {
   scanf("%d" , &n);
   memset (dp , -1 , sizeof dp);
   printf("%lld\n" , f(1 , 4 , 4 , 4));
}


Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
 
#define ll long long
#define fw(p) for(int w=0;w<(p);w++)
#define fx(p) for(int x=0;x<(p);x++)
#define fy(p) for(int y=0;y<(p);y++)
#define fz(p) for(int z=0;z<(p);z++)
#define fyg(p,g) for(int y=(g);y<(p);y++)
#define fzg(p,g) for(int z=(g);z<(p);z++)
#define ce(d) cout<<d<<endl;
#define ces(d) cout<<" "<<endl;
 
int main() {
 
string A,B;
cin>>A>>B;

if(A.size()>B.size()){
	ce("GREATER");
}else if(A.size()<B.size()){
	ce("LESS");
}else{
int flag=0;
 fx(A.size()){
 	if(A.at(x)>B.at(x)){
 		flag=1;
 		break;
 	}else if(A.at(x)<B.at(x)){
 		flag=2;
 		break;
 	}
 }
 
 switch(flag){
 	case 0:ce("EQUAL");break;
 	case 1:ce("GREATER");break;
 	case 2:ce("LESS");break;
 }
}
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
 
#define A_MAX 1000000
#define A_MAX_HALF 500000
 
using namespace std;
 
int min_factor[A_MAX + 1];
int q[A_MAX + 1];
int a[A_MAX + 1];
vector<int> primes{ 2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59, 61, 67, 71, 73, 79, 83, 89, 97, 101, 103, 107, 109, 113, 127, 131, 137, 139, 149, 151, 157, 163, 167, 173, 179, 181, 191, 193, 197, 199, 211, 223, 227, 229, 233, 239, 241, 251, 257, 263, 269, 271, 277, 281, 283, 293, 307, 311, 313, 317, 331, 337, 347, 349, 353, 359, 367, 373, 379, 383, 389, 397, 401, 409, 419, 421, 431, 433, 439, 443, 449, 457, 461, 463, 467, 479, 487, 491, 499, 503, 509, 521, 523, 541, 547, 557, 563, 569, 571, 577, 587, 593, 599, 601, 607, 613, 617, 619, 631, 641, 643, 647, 653, 659, 661, 673, 677, 683, 691, 701, 709, 719, 727, 733, 739, 743, 751, 757, 761, 769, 773, 787, 797, 809, 811, 821, 823, 827, 829, 839, 853, 857, 859, 863, 877, 881, 883, 887, 907, 911, 919, 929, 937, 941, 947, 953, 967, 971, 977, 983, 991, 997 };
int N;
 
// 入力読み込みは uzzy 氏のコードを真似した
const int cm = 1 << 26;
char cn[cm], * ci = cn, ct;
inline int getint() {
    int A = 0;
    while ((ct = *ci++) >= '0') A = A * 10 + ct - '0';
    return A;
}
 
int main() {
  	fread(cn, 1, cm, stdin);
  
    for (int i = 2; i <= A_MAX_HALF; ++i) {
        if (!min_factor[i]) {
            min_factor[i] = i;
        }
        int min_factor_i = min_factor[i];
        for (int p : primes) {
            int n = i * p;
            if (n > A_MAX) {
                break;
            }
            min_factor[n] = p;
            if (p == min_factor_i) {
                q[n] = q[i];
                break;
            } else {
                q[n] = i;
            }
        }
    }
 
    N = getint();
    for (int i = 0; i < N; ++i) {
        ++a[getint()];
    }
 
    int is_pairwise_coprime = 1;
    for (int n = A_MAX; n > 1; --n) {
        int an = a[n];
        if (an) {
            if (an > 1) {
                if (an == N) {
                    printf("not coprime\n");
                    return 0;
                }
                is_pairwise_coprime = 0;
            }
            a[min_factor[n]] += an;
            a[q[n]] += an;
        }
    }
    if (is_pairwise_coprime) {
        printf("pairwise coprime\n");
    } else {
        printf("setwise coprime\n");
    }
 
    return 0;
}

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

int main(){
    ll n;
    cin>>n;
    vector<ll> in(n);
    ll sum=0;
    map<ll, ll> hm;
    for(ll i=0; i<n; i++){
        cin>>in[i];
        hm[in[i]]++;
        sum+=in[i];
    }
    ll q;
    cin>>q;
    for(ll i=0; i<q; i++){
        ll l, r;
        cin>>l>>r;
        if(l==r){
            cout<<sum<<endl;
            continue;
        }
        sum+=(hm[l]*(r-l));
        hm[r]+=hm[l];
        hm[l]=0;
        cout<<sum<<endl;
    }
}


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

class Test
{
    static void Main()
    {
        double n = double.Parse(Console.ReadLine());
        double[] x = Console.ReadLine().Split().Select(double.Parse).ToArray();
        double[] y = Console.ReadLine().Split().Select(double.Parse).ToArray();

        double D1 = 0;
        for (int i = 0; i < n; i++)
        {
            D1 += Math.Abs(x[i] - y[i]);
        }

        double D2 = 0;
        for (int i = 0; i < n; i++)
        {
            D2 += Math.Pow(x[i] - y[i], 2);
        }
        D2 = Math.Sqrt(D2);

        double D3 = 0;
        for (int i = 0; i < n; i++)
        {
            D3 += Math.Pow(Math.Abs(x[i] - y[i]), 3);
        }
        D3 = Math.Pow(D3, 1.0 / 3.0);

        double DI = 0;
        List<double> dd = new List<double>();
        for (int i = 0; i < n; i++)
        {
            dd.Add(Math.Abs(x[i] - y[i]));
            DI = dd.Max();
        }

        Console.WriteLine(D1);
        Console.WriteLine(D2);
        Console.WriteLine(D3);
        Console.WriteLine(DI);
    }
}


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

int main() {
    int n;
    cin >> n;
    vector<int> a(n), b(n);
    for (int i = 0; i < n; i++) {
        cin >> a.at(i);
        b.at(i) = a.at(i);
    }
    sort(b.begin(), b.end());
    map<int, int> m;
    for (int i = 0; i < n; i++) {
        m[b.at(i)] = i;
    }

    int cnt_shift = 0;
    for (int i = 0; i < n; i++) {
        if (m[a.at(i)] % 2 != i % 2) cnt_shift++;
    }
    cout << cnt_shift / 2 << endl;
}

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

int main(){
    int N, K, Q;
    cin >> N >> K >> Q;
    
    vector<int> A(N);
    vector<pair<int, int>> sa(N);
    for (int i = 0; i < N; i++) {
        cin >> A[i];
        sa[i] = {A[i], i};
    }
    sort(sa.begin(), sa.end());
    vector<bool> use(N+1, true);
    use[N] = false;
    int ans = sa[Q-1].first - sa[0].first;
    
    for (int i = 0; i < N; i++) {
        vector<int> cand;
        multiset<int> box;
        for (int j = 0; j <= N; j++) {
            if (use[j]){
                box.insert(A[j]);
            }
            else {
                int t = box.size();
                auto it = box.begin();
                for (int k = 0; k < t-K+1; k++) {
                    cand.push_back(*it);
                    it++;
                }
                box.clear();
            }
        }
        if ((int)cand.size() >= Q) {
            sort(cand.begin(), cand.end());
            ans = min(ans, cand[Q-1]-cand[0]);
        }else break;
        
        use[sa[i].second] = false;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 384
// <------------- Template -----------------------> //


#include<bits/stdc++.h>
using namespace std;

#define fastio 			ios::sync_with_stdio(0);	cin.tie(0); cout.tie(0);  cout<<fixed;  cout<<setprecision(2);	
#define randomINT 		mt19937 rnd(chrono::steady_clock::now().time_since_epoch().count());
#define	newl 			cout<<"\n"
#define DISP(as)		for(auto it : as) cout<<it<<" ";newl;
#define all(x)         	(x).begin(),(x).end()
#define mset(x,val)    	memset(x,val,sizeof(x))
#define newl           	cout<<"\n"
#define pb             	push_back
#define mp             	make_pair
#define f 				first
#define s 				second
#define dline          cerr<<"///REACHED///\n";
#define deb1(x)        cerr<<#x<<" = "<<x<<'\n';
#define deb2(x,y)      cerr<<'['<<#x<<','<<#y<<"] = "<<'['<<x<<','<<y<<']'<<'\n';
#define deb3(x,y,z)    cerr<<'['<<#x<<','<<#y<<','<<#z<<"] = "<<'['<<x<<','<<y<<','<<z<<']'<<'\n';

typedef long long 				ll;
typedef long double 			ld;
typedef vector<ll> 				vll;
typedef pair<ll ,ll> 			pll;
typedef pair<ld,ld> 			pld;
typedef unordered_map<ll,ll> 	um;
typedef vector<pll> 			vpll;

const ll 	MAX5 	= 	1e+5+7;
const ll 	MAX7 	= 	1e+7+7;
const ll 	MAXN 	= 	2 * 1e18;
const ll   	INF   	=  	0x7f7f7f7f7f7f7f7f;
const int  	INFi 	=  	0x7f7f7f7f;
const ll 	MOD		=  	1e+9+7;

vll adj[MAX5];ll visit[]={};

// <------------- Declare Variables Here ------------> //

ll T=1;
ll n,x,y,q;
ll s,t,d;
ll sum = 0;
vll dist[2];

// <------------- Implement Functions Here ----------> //

void dfs(ll x, ll p, ll ind, ll lv=0) {
	dist[ind][x] = lv;
	for(auto it : adj[x]) {
		if(it!=p) {
			dfs(it,x,ind,lv+1);
		}
	}
}

// <------------- Start of main() -------------------> //

void MAIN() {
	cin >> n >> x >> y;
	dist[0] = vll(n+1);
	dist[1] = vll(n+1);
	for(ll i=0;i<n-1;i++) {
		ll u,v;
		cin >> u >> v;
		adj[u].pb(v);
		adj[v].pb(u);
	}
	dfs(x,x,0);
	dfs(y,y,1);
	ll maxi = 0;
	for(ll i=1;i<=n;i++) {
		if(dist[1][i] >= dist[0][i]) {
			maxi = max(maxi,dist[1][i]);
		}
	}
	cout<<maxi-1;
}

int main() {
	fastio;randomINT;
	//cin>>T;
	while(T--) {
		MAIN();
	}
	return 0;
}


Measured memory_bytes: 15544