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

typedef long long ll;
typedef long double ld;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef pair<ld,ld> pdd;
typedef vector<ll> vll;
typedef vector<ld> vld;
typedef vector<pll> vpl;
typedef vector<vll> vvll;

#define ALL(a) a.begin(),a.end()
#define SZ(a) ((int)a.size())
#define FI first
#define SE second
#define REP(i,n) for(int i=0;i<((int)n);i++)
#define REP1(i,n) for(int i=1;i<((int)n);i++)
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define PB push_back
#define EB emplace_back
#define MP(a,b) make_pair(a,b)
#define SORT_UNIQUE(c) (sort(c.begin(),c.end()), c.resize(distance(c.begin(),unique(c.begin(),c.end()))))
#define GET_POS(c,x) (lower_bound(c.begin(),c.end(),x)-c.begin())
#define yes cout<<"Yes"<<endl
#define YES cout<<"YES"<<endl
#define no cout<<"No"<<endl
#define NO cout<<"NO"<<endl
#define Decimal fixed<<setprecision(20)
#define INF 1000000000
#define LLINF 1000000000000000000LL

const int inf = 1e9;
const ll linf = 1LL << 50;
const double eps = 1e-10;
const int MOD = 1e9 + 7;
const int dx[4] = {-1, 0, 1, 0};
const int dy[4] = {0, -1, 0, 1};

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

  return gcd(b,a%b);
}




struct Sieve{
  ll n;
  vll table;
  Sieve(ll n):n(n), table(n+1,0){
    for(ll i = 2; i<=n; i++){
      if(table[i])
        continue;

      table[i] = i;
      for(ll j = i*i; j<=n; j+=i)
        table[j] = i;
    }
  }

  vll factorList(ll x){
    vll res;
    while(x>1){
      res.push_back(table[x]);
      x /= table[x];
    }

    return res;
  }


  vpl getFact(ll x){
    map<ll, ll> m;
    vll fa = factorList(x);
    for(auto p:fa)
      m[p] += 1;

    SORT_UNIQUE(fa);
    vpl res;
    for(auto p:fa)
      res.push_back(pll(p, m[p]));

    return res;
  }
};

int main(){
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);

  ll n;
  cin>>n;
  vll a(n);
  REP(i,n)cin>>a[i];

  bool is_pc=true;
  Sieve s(1e6+1);
  vll h(1e6+5);
  REP(i,n){
    vpl facts=s.getFact(a[i]);

    bool flag=false;
    for(auto f:facts){
      if(h[f.FI]==1){
        is_pc=false;
        flag=true;
        break;
      }
      h[f.FI]=1;
    }

    if(flag)
      break;
  }

  bool is_sc=true;
  ll now=a[0];
  for(ll i=1; i<n; i++)
    now=gcd(now,a[i]);
  if(now!=1)
    is_sc=false;


  if(is_pc)
    cout<<"pairwise coprime"<<endl;
  else if(is_sc)
    cout<<"setwise coprime"<<endl;
  else
    cout<<"not coprime"<<endl;

}



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

using namespace std;

int n, a[100000], b[100000], c[100000], dp[100000][3];

int main()
{
  cin >> n;
  for(int i = 0; i<n; i++)
    cin >> a[i] >> b[i] >> c[i];
  dp[0][0] = a[0], dp[0][1] = b[0], dp[0][2] = c[0];
  for(int i = 1; i<n; i++)
  {
    dp[i][0] = max(dp[i-1][1],dp[i-1][2])+a[i];
    dp[i][1] = max(dp[i-1][0],dp[i-1][2])+b[i];
    dp[i][2] = max(dp[i-1][0],dp[i-1][1])+c[i];
  }
  cout << max(max(dp[n-1][0],dp[n-1][1]),dp[n-1][2]) << endl;
}

Measured memory_bytes: 2560
//include
//------------------------------------------
#include <vector>
#include <list>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>
#include <fstream>
#include <complex>
#include <math.h>

using namespace std;

//conversion
//------------------------------------------
inline long toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
inline long toLong(string s) {long v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}

//math
//-------------------------------------------
template<class T> inline T sqr(T x) {return x*x;}

//typedef
//------------------------------------------
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef pair<long, long> PLL;
typedef long long LL;
//container util
//------------------------------------------
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())

//repetition
//------------------------------------------
#define FOR(i,a,b) for(long i=(a);i<(b);++i)
#define REP(i,n) FOR(i,0,n)

//constant
//--------------------------------------------

//clear memory
#define CLR(a) memset((a), 0 ,sizeof(a))

const long double EPS = 1e-20;
const long INF = 1e10;

int rnk[100];
int main(){
	int n,w;
	while(cin>>n>>w&&n){
		CLR(rnk);
		REP(i,n){
			int v;
			cin>>v;
			rnk[v/w]++;
		}
		int maxi=*max_element(rnk,rnk+100);
		int cnt=0;
		REP(i,100)if(rnk[i]!=0)cnt=i;
		long double res=0.01;
		REP(i,100)res+=(long double)((cnt-i)*rnk[i])/(cnt*maxi);
		cout<<fixed<<setprecision(8)<<res<<endl;
	}
	
	return 0;
}

Measured memory_bytes: 1236
#include<stdio.h>
#include<iostream>
#include<string.h>
#include<string>
#include<queue>
#include<vector>
#include<utility>
#include<functional>
typedef long long ll;
using namespace std;

int main(){
  ll K,A,B;
  ll ans = 1;
  cin >> K >> A >> B;
  if((B-A)<=2){
    ans += K;
  }else{
    ans = A + ( (K-A+1)/2 * (B-A) ) + (K-A+1)%2;
  }

  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
H, W = gets.chomp.split.map(&:to_i)

map = []
cell_cnt = 0

H.times do
  line = gets.chomp.chars
  map << line
  cell_cnt += line.count { |c| c == '.' }
end

queue = [[0, 0, 1]]

ans = -1

DY = [-1, 0, 1, 0]
DX = [0, 1, 0, -1]

checked = Array.new(H) { Array.new(W, false) }

until queue.empty?
  y, x, dist = queue.shift
  checked[y][x] = true

  if y == H - 1 && x == W - 1
    ans = dist
    break
  end

  4.times do |i|
    ny = y + DY[i]
    nx = x + DX[i]

    next if ny < 0 || nx < 0 || H <= ny || W <= nx
    next if map[ny][nx] == '#'
    next if checked[ny][nx]
    checked[ny][nx] = true

    queue << [ny, nx, dist + 1]
  end
end

if ans >= 0
  puts cell_cnt - ans
else
  puts -1
end


Measured memory_bytes: 2172
N,M=map(int,input().split())
N,M=max(N,M),min(N,M)
if N == 1 and M == 1:
  print(1)
elif N == 2 and M == 1:
  print(0)
elif M == 1:
  print(N-2)
elif M == 2:
  print(0)
else:
  print((N-2)*(M-2))

Measured memory_bytes: 9116
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.StringTokenizer;

public class Main {
  /**
   * Iterate through each line of input.
   */
	public static void main(String[] args) throws IOException {
		OriginScanner os = new OriginScanner();
		PrintWriter pw = new PrintWriter(System.out);
		
		int a = os.nextInt();
		int b = os.nextInt();
		int m = os.nextInt();
		
		int[] aAry = Arrays.stream(os.nextLine().split(" ")).mapToInt(i -> Integer.parseInt(i)).toArray();
		int[] bAry = Arrays.stream(os.nextLine().split(" ")).mapToInt(i -> Integer.parseInt(i)).toArray();
		
		int min = Arrays.stream(aAry).min().getAsInt() + Arrays.stream(bAry).min().getAsInt();
		
		for (int i = 0; i < m; i++) {
			String[] mAry = os.nextLine().split(" ");
			int aSel = aAry[Integer.parseInt(mAry[0]) - 1];
			int bSel = bAry[Integer.parseInt(mAry[1]) - 1];
			int diff = Integer.parseInt(mAry[2]);
			min = Math.min(min, aSel + bSel - diff);
		}
		pw.println(min);
		pw.close();
	}
	static class OriginScanner {
		private BufferedReader br;
		private StringTokenizer st;
		
		public OriginScanner() {
			br = new BufferedReader(new InputStreamReader(System.in));
		}
		String nextLine() {
			String str = null;
			try {
				str = br.readLine();
			}
			catch (IOException e) {
				System.out.println(e);
			}
			return str;
		}
		String next() {
			if (st == null || !st.hasMoreTokens()) {
				st = new StringTokenizer(nextLine());
			}
			return st.nextToken();
		}
		int nextInt() {
			return Integer.parseInt(next());
		}
		double nextDouble() {
			return Double.parseDouble(next());
		}
		long nextLong() {
			return Long.parseLong(next());
		}
	}
}

Measured memory_bytes: 58316
import java.util.*;

public class Main {
    
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int WX = sc.nextInt();
        int HY = sc.nextInt();
        int ZX = 0;
        int ZY = 0;
        int N = sc.nextInt();
        Map<Integer, int[]> map = new HashMap<>();
        for (int i = 0; i < N; i++) {
            int x = sc.nextInt();
            int y = sc.nextInt();
            int a = sc.nextInt();
            if (map.containsKey(a)) {
                int[] ar = map.get(a);
                switch (a) {
                case 1 :
                    if (ar[0] < x) {
                        int[] arr = {x, y};
                        map.put(a, arr);
                    }
                    break;
                case 2 :
                    if (ar[0] > x) {
                        int[] arr = {x, y};
                        map.put(a, arr);
                    }
                    break;
                case 3 :
                    if (ar[1] < y) {
                        int[] arr = {x, y};
                        map.put(a, arr);
                    }
                    break;
                case 4 :
                    if (ar[1] > y) {
                        int[] arr = {x, y};
                        map.put(a, arr);
                    }
                }
            } else {
                int[] ar = {x, y};
                map.put(a, ar);
            }
        }
        for (int key : map.keySet()) {
            if (key == 1) {
                ZX = map.get(key)[0];
            } else if (key == 2) {
                WX = map.get(key)[0];
            } else if (key == 3) {
                ZY = map.get(key)[1];
            } else {
                HY = map.get(key)[1];
            }
        }
        int X = (WX-ZX);
        int Y = (HY-ZY);
        System.out.println(0 < X && 0 < Y ? X*Y : 0);
    }
    
}


Measured memory_bytes: 36108
#include<iostream>
#include<algorithm>
using namespace std;
int main()
{
  int a,b,c;
cin>>a>>b>>c;
  int d[3]={a,b,c};
 sort(d,d+3);
  if(d[1]+d[0]==d[2])
    {
      cout<<"Yes"<<endl;
    }else{
    cout<<"No"<<endl;
  }
  return 0;
}

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

int main(){
    int a, b;
    
    while(true){
        cin >> a >> b;
        if(a == 0 && b == 0) break;
        for (int i = 0; i < a; i++ ){
            if(i == 0 or i == a-1){
                for (int j = 0; j < b; j++ ){
                    cout << "#";
                }
            }
            else{
                for ( int j = 0; j < b; j++ ){
                    if(j == 0 or j == b-1)cout << "#";
                    else cout << ".";
                }
            }
        cout << endl;
        }
    cout << endl;
    }
    
}


Measured memory_bytes: 3112
/*                        ______
 _______   /\     |``\   |        |  /
    |     /  \    |__/   |____    |/
    |    / _ _\   |  \   |        |\
    |   /      \  |   \  |______  |  \

            Dept. of CSE
        Comilla  University

*/
#include<bits/stdc++.h>
#define pi 2*acos(0.0)
#define ll long long
#define FIO ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define Node struct node
#define spc " "
#define  E  2.71828182845904523536
#define pb push_back
#define pp pop_back
#define valid(nx,ny) nx>=0 && nx<n && ny>=0 && ny<m
#define ee endl
#define pii pair<int,int>
#define infinity 10000000000000000
#define mod 1000000007
int fx[]={0,0,+1,-1};
int fy[]={+1,-1,0,0};

using namespace std;
///check n=1;
///check corner case;
const int maX=1e5+1;
vector<ll>Graph[maX],cost[maX];
ll visit[maX];


int main()
{
   ll n,k,i,j,cc=0,x;
   cin>>n;
   i=100;
   while(i<n){
     i+=i/100;
     cc++;
   }
   cout<<cc<<endl;
return 0;
}


Measured memory_bytes: 8308
#include<cstdio>
#include<algorithm>
using namespace std;
#define MAXN 200010
int p[MAXN],n,T[MAXN],f[MAXN];
bool check(int a,int b,int c)
{
	return (a<b&&b<c)||(b<c&&c<a)||(c<a&&a<b);
}
int main()
{
	int x;
	scanf("%d",&n);
	for(int i=1;i<=n;i++)
	{
		scanf("%d",&x);
		p[x]=i;
	}
	for(int i=n-1;i;i--)
		if(T[i+1]==0)
		{
			if(p[i]>p[i+1])
				T[i]=1,f[i]=i+1;
		}
		else
		{
			if(check(p[f[i+1]],p[i],p[i+1]))
				T[i]=T[i+1],f[i]=f[i+1];
			else T[i]=T[i+1]+1,f[i]=i+1;
		}
	printf("%d\n",T[1]);
}

Measured memory_bytes: 2560
#include <bits/stdc++.h>
using namespace std;
#define all(v) (v).begin(), (v).end()
#define P pair<int,int>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define endl '\n'
#define ll long long

signed main() {
    int N,R;
    cin >> N >> R;


    if(N >= 10) cout << R << endl;
    else {
        cout << R + 100 * (10 - N) << endl;
    }
}


Measured memory_bytes: 768
n=int(input())
l=[0]+list(map(int,input().split()))+[0]
f=lambda x,y:abs(l[x]-l[y])
s=sum(f(i+1,i) for i in range(n+1))
for i in range(n): print(s-f(i+1,i)-f(i+2,i+1)+f(i+2,i))

Measured memory_bytes: 14172
H, W = map(int, input().split())

if H == 1 and W == 1 :
    print(0)
else :
    coins = [[0 for _ in range(W)] for _ in range(H)]
    minCoin = [-1, -1, 10]

    for h in range(H) :
        A = list(map(int, input().split()))
        for w in range(W) :
            coins[h][w] = A[w]
            if A[w] < minCoin[2] :
                minCoin = [h, w, A[w]]

    ans = []

    # 最小のコインに奇数を集める
    for h in range(0, minCoin[0]) :
        for w in range(W) :
            if coins[h][w] % 2 == 1 :
                coins[h + 1][w] += 1
                ans.append([h, w, h+1, w])

    for h in range(H-1, minCoin[0], -1) :
        for w in range(W) :
            if coins[h][w] % 2 == 1 :
                coins[h - 1][w] += 1
                ans.append([h, w, h-1, w])

    for w in range(0, minCoin[1]) :
        if coins[minCoin[0]][w] % 2 == 1 :
            coins[minCoin[0]][w + 1] += 1
            ans.append([minCoin[0], w, minCoin[0], w+1])
    for w in range(W-1, minCoin[1], -1) :
        if coins[minCoin[0]][w] % 2 == 1 :
            coins[minCoin[0]][w - 1] += 1
            ans.append([minCoin[0], w, minCoin[0], w-1])

    if coins[minCoin[0]][minCoin[1]] % 2 == 1 :
        lastMoves = []
        if minCoin[0] > 0 :
            lastMoves.append([minCoin[0]-1, minCoin[1], coins[minCoin[0]-1][minCoin[1]]])
        if minCoin[0] < H - 1 :
            lastMoves.append([minCoin[0]+1, minCoin[1], coins[minCoin[0]+1][minCoin[1]]])
        if minCoin[1] > 0 :
            lastMoves.append([minCoin[0], minCoin[1]-1, coins[minCoin[0]][minCoin[1]-1]])
        if minCoin[1] < W - 1 :
            lastMoves.append([minCoin[0], minCoin[0]+1, coins[minCoin[0]][minCoin[1]+1]])
        lastMoves.sort(key=lambda A : A[2])
        toCoin = lastMoves[0]
        if toCoin[2] < coins[minCoin[0]][minCoin[1]] - 1 :
            ans.append([minCoin[0], minCoin[1]] + toCoin[0:2])

    print(len(ans))
    for a in ans :
        print(a[0]+1, a[1]+1, a[2]+1, a[3]+1)

Measured memory_bytes: 26600
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <math.h>
#include <functional>
#include <utility>
using namespace std;

int main(){
  string s;
  cin >> s;
  string t;
  cin >> t;
  int memo = -1;
  bool f = false;
  for(int i = s.size() - t.size(); i >= 0 ; i--){
    for(int j = 0; j < t.size(); j++){
      if(s[i + j] != t[j] && s[i + j] != '?'){
        break;
      }
      if(j == t.size() - 1){ memo = i; f = true; break; }
    }
    if(f){ break; }
  }

  if(memo == -1){
    cout << "UNRESTORABLE" << endl;
  }
  else{
    for(int i = memo; i < memo + t.size(); i++){
      s[i] = t[i - memo];
    }
    for(int i = 0; i < s.size(); i++){
      if(s[i] == '?'){ s[i] = 'a';}
    }
    cout << s << endl;
  }
}

Measured memory_bytes: 256
#include<iostream>
#include<iomanip>
#include<numeric>
#include<string>
#include<algorithm>
#include<vector>
#include<map>
#include<unordered_map>
#include<stack>
#include<queue>
#include<ctype.h>
#include<cstdlib>
#include<cstdio>
#include<cmath>
#include<utility>
#define For(a,b) for(int i=(a);i<(b);i++)
#define Rep(n) for(int i=0; i<(n); ++i)
int gcd(int a,int b){return b?gcd(b,a%b):a;}
int lcm(int a,int b){return a*b/gcd(a,b);}
using namespace std;
typedef long long ll;//int64
typedef unsigned long long ull;
//----------program from here----------

int main(){
    int A=0,P=0;
    cin >> A >> P;
    cout << (A*3+P)/2 << endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<stdio.h>
//#include <bits/stdc++.h>
#include<vector>
#include<float.h>
#include<iomanip>
#include<algorithm>
#include<string>
#include<cstring>
#include<math.h>
#include<cmath>
#include<sstream>
#include<set>
#include<map>
#include<queue>
#include <cassert>
#include <cmath>
#include<cstdint>

#define INF 1e9
#define rep(i,n)for(int i=0;(i)<(int)(n);i++)
#define REP(i,a,b)for(int i=(int)(a);(i)<=(int)(b);i++)
#define VEC(type, c, n) std::vector<type> c(n);for(auto& i:c)std::cin>>i;
#define vec(type,n) vector<type>(n)
#define vvec(m,n) vector<vector<int>> (int(m),vector<int>(n))
#define ALL(a)  (a).begin(),(a).end()
#define chmax(a, b) a = max(a, b)
#define chmin(a, b) a = min(a, b)


using namespace std;
using ll = long long;
using Graph = vector<vector<int>>;
using P = pair<ll, ll>;

const ll MOD = INF + 7;

ll mpow(ll x, ll n){
    ll ans = 1;
    while(n != 0){
        if(n & 1)ans = ans * x % MOD;
        x = x * x % MOD;
        n = n >> 1;
    }
    return ans;
}

int main(){
    int n, m;
    cin >> n >> m;
    string s;
    cin >> s;
    reverse(ALL(s));
    deque<int> que;
    for(int i = 0; i < n + 1; i++){
        if(i == n)break;
        bool f = true;
        for(int j = m; j > 0; j--){
            if(j + i >= s.size())continue;
            if(s[i + j] == '1')continue;
            else {
                f = false;
                que.push_back(j);
                i += j - 1;
                break;
            }
        }
        if(f){
            cout << -1 << endl;
            return 0;
        }
    }
    while(!que.empty()){
        cout << que.back() << " ";
        que.pop_back();
    }
}

Measured memory_bytes: 868
s = input()
flag = False
r = "keyence"
for i in range(len(s)):
  #print(s[:i+1], r[:i+1])
  #print(s[len(s)-len(r[i+1:]):], r[i+1:])
  if s[:i+1] == r[:i+1] and s[len(s)-len(r[i+1:]):] == r[i+1:]:
    flag = True
    break
if flag:
  print("YES")
else:
  print("NO")
    


Measured memory_bytes: 9072
n,m = map(int, input().split(" "))
hlist = list(map(int, input().split(" ")))

xlist = []

for i in range(m):
  a,b= map(int, input().split(" "))
  if hlist[a-1]>hlist[b-1]:
    xlist.append(b)
  elif hlist[a-1]<hlist[b-1]:
    xlist.append(a)
  else:
    xlist.append(a)
    xlist.append(b)

print(int(n-len(list(set(xlist)))))

Measured memory_bytes: 20116
#include <iostream>
#include <bits/stdc++.h>
#include <math.h>
using namespace std;
typedef long long int ll;
typedef long double dl;
#define PI  3.14159265358979323846
#define M  998244353
ll fast(ll n,ll a,ll m)
{
    if(n==0)
        return 1;
    else if(n==1)
        return a;
    else
    {
        ll r=fast(n/2,a,m);
        if(n%2==0)
        {
            return (((r%m)*(r%m))%m);
        }
        else
        {
            return (((((r%m)*a)%m)*r)%m);
        }

    }
}
ll lcm(ll a,ll b)
{
    ll g=__gcd(a,b);
    return ((a*b)/g);
}
int pal(string S)
{
    int n=S.length();
    int ok=1,i;
    for(i=0;i<n;i++)
    {
        if(S[i]!=S[n-i-1])
        {
            ok=0;
            break;
        }
    }
    return ok;
}
int main()
{
  string S;
  cin>>S;
  int n=S.length(),i;
  if(pal(S)==1)
  {
      string a,b;
      for(i=1;i<=((n-1)/2);i++)
      {
          a+=S[i-1];
      }
      for(i=((n+3)/2);i<=n;i++)
      {
          b+=S[i-1];
      }
      if(pal(a)==1&&pal(b)==1)
      {
          cout<<"Yes";
      }
      else
      {
          cout<<"No";
      }

  }
  else
  {
      cout<<"No";
  }

}


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


int main()
{
    ios::sync_with_stdio(false);

    long long int x, y, ans;
    cin >> x >> y;

    if (x % y == 0) {
        cout << "-1\n";
        return 0;
    }

    for (int i = 2; ; i++) {
        ans = x * i;
        if (ans % y != 0) {
            cout << ans << "\n";
            return 0;
        }
        if (ans > 1000000000000000000) {
            cout << "-1\n";
            return 0;
        }
    }

    return 0;

}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
#define MOD 1000000007
#define INF 987654321
#define PI 3.1415926535

vector<int> adj[100001];
int tvisit[100001], avisit[100001];
int parent[100001];
bool leaf[100001];

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

    int n, u, v;
    cin >> n >> u >> v;

    int a, b;
    for(int i=0; i<n-1; i++) {
        cin >> a >> b;
        adj[a].push_back(b);
        adj[b].push_back(a);
    }

    queue<int> bfs;
    bfs.push(v);
    parent[v]=0;
    while(!bfs.empty()) {
        int x=bfs.front();
        bfs.pop();
        leaf[x]=true;
        for(int y : adj[x]) {
            if(y==parent[x]) continue;
            leaf[x]=false;
            parent[y]=x;
            bfs.push(y);
        }
    }

    queue<int> qt, qa;
    qt.push(u);
    qa.push(v);
    int mx=-1;
    while(!qt.empty() || !qa.empty()) {
        int s=qt.size();
        for(int i=0; i<s; i++) {
            int cur=qt.front();
            qt.pop();
            if(cur==v || avisit[cur]) continue;
            for(int next : adj[cur]) {
                if(tvisit[next] || next==u) continue;
                tvisit[next]=tvisit[cur]+1;
                if(next==v || avisit[next]) {
                    mx=max(mx, avisit[next]);
                    continue;
                }
                qt.push(next);
            }
        }
        
        int s2=qa.size();
        for(int i=0; i<s2; i++) {
            int cur=qa.front();
            qa.pop();
            for(int next : adj[cur]) {
                if(avisit[next] || next==v) continue;
                avisit[next]=avisit[cur]+1;
                if(tvisit[next]==avisit[next]) {
                    mx=max(mx, avisit[next]);
                }
                else if(tvisit[next] || next==u) {
                    mx=max(mx, avisit[next]-1);
                }
                qa.push(next);
            }
        }
    }

    cout << mx;
}

Measured memory_bytes: 7168
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
const int mod=998244353;
inline void add(int &x,int y){(x+=y)>=mod?x-=mod:0;}
inline int kpow(int a,int b)
{
	int s=1;
	for(;b;b>>=1,a=1ll*a*a%mod)
		if(b&1)s=1ll*s*a%mod;
	return s;
}
int n,m,ans,jc[2000010],jcv[2000010];
void init()
{
	jc[0]=1;
	for(int i=1;i<=2000000;++i)jc[i]=1ll*jc[i-1]*i%mod;
	jcv[2000000]=kpow(jc[2000000],mod-2);
	for(int i=2000000;i;--i)jcv[i-1]=1ll*jcv[i]*i%mod;
}
int C(int x,int y)
{
	if(x<y||y<0)return 0;
	return 1ll*jc[x]*jcv[y]%mod*jcv[x-y]%mod;
}
int calc(int a,int b,int s)
{
	int res=C(a+b+s-1,a+b-1);
	add(res,mod-1ll*b*C(a+b+s-2-m,a+b-1)%mod);
	add(res,mod-1ll*a*C(a+b+s-1-m,a+b-1)%mod);
	return res;
}
int main()
{
	scanf("%d %d",&n,&m);
	init();
	for(int i=m;i>=0;i-=2)add(ans,1ll*C(n,i)*calc(i,n-i,(3*m-i)/2)%mod)/*,printf("%d\n",ans)*/;
	printf("%d",ans);
	return 0;
}


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

using namespace std;

using ll = long long;

ll calc(ll a, ll c, ll d) {
    return a - (a / c + a / d - a / (c / __gcd(c, d) * d));
}

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll a, b, c, d;
    cin >> a >> b >> c >> d;
    cout << calc(b, c, d) - calc(a - 1, c, d) << endl;
    return 0;
}

Measured memory_bytes: 256
/*
    Problem 79
    https://atcoder.jp/contests/abc106/tasks/abc106_d
*/
#include <bits/stdc++.h>
using namespace std;
/* typedef */
typedef long long ll;
typedef pair<int, int> pii;
/* constant */
const int INF = 1 << 30;
const ll LINF = 1LL << 50;
const int NIL = -1;
const int MAX = 10000;
const int mod = 1000000007;
const double pi = 3.141592653589;
/* global variables */
/* function */
/* main */
int main(){
    int N, M, Q;
    cin >> N >> M >> Q;
    vector<vector<int>> train(N+1, vector<int>(N+1));
    for (int i = 0; i < M; i++) {
        int l, r;
        cin >> l >> r;
        train[l][r]++;
    }
    vector<vector<int>> prefixSum(N+2, vector<int>(N+2));
    for (int i = 0; i < N+1; i++) for (int j = 0; j < N+1; j++)
        prefixSum[i+1][j+1] =
            prefixSum[i+1][j] + prefixSum[i][j+1] - prefixSum[i][j] + train[i][j];

    for (int i = 0; i < Q; i++) {
        int p, q;
        cin >> p >> q;
        q++;
        cout << prefixSum[q][q] + prefixSum[p][p] - prefixSum[p][q] - prefixSum[q][p] << '\n';
    }
}

Measured memory_bytes: 5560
#include <iostream>
#include <vector>
#include <set>

using namespace std;

signed main(void){
    cin.tie(nullptr);
    ios_base::sync_with_stdio(false);

    int N, Q;
    string S;

    cin >> N >> S >> Q;

    set<int> s[26];

    for(int i = 0; i < N; ++i){
        s[S[i]-'a'].insert(i);
    }

    for(int i = 0; i < Q; ++i){
        int com;
        cin >> com;

        if(com == 1){
            int p;
            char c;
            cin >> p >> c;
            --p;

            s[S[p]-'a'].erase(p);
            S[p] = c;
            s[c-'a'].insert(p);

        }else{
            int l, r;
            cin >> l >> r;
            --l, --r;

            int cnt = 0;
            for(int j = 0; j < 26; ++j){
                auto it = s[j].lower_bound(l);
                if(it != s[j].end() && *it <= r){
                    ++cnt;
                }
            }
            
            cout << cnt << '\n';
        }
    }

    return (0);

}

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

int main()
{
  int n,r,s;
  cin >> n;
  int a[n];
  for(int i = 0; i < n; i++) cin >> a[i];
  
  for(int i = 0; i < n; i++)
  {
    for(int j = i + 1; j < n; j++)
    {
      r += a[i]*a[j];
    }  
  }  
  cout << r;
  
  return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
using namespace std;
int main()
{
	#ifndef ONLINE_JUDGE
    	freopen("input.txt", "r", stdin);
    	freopen("output.txt", "w", stdout);
	#endif

    int n;
    cin>>n;
    long int arr[n];
    for(int i=0; i<n; i++){
    	cin>>arr[i];
    }
    long int t=0;
    long int max=arr[0];
    for (int i=0; i<n; i++){
    	if(arr[i]<max){
    		t+=max-arr[i];
    	}
    	else{
    		max=arr[i];
    	}
    	
    }
    cout<<t;

	return 0;
}

Measured memory_bytes: 5124
R,G,B,N=map(int,input().split())
counter=0
 
for r in range(N//R+1):
    for g in range((N-r*R)//G+1):
        b=(N-r*R-g*G)/B
        if b.is_integer() and b>=0:
            counter += 1
 
print(counter)

Measured memory_bytes: 2940
#include <bits/stdc++.h>
using namespace std;
#define repd(i,a,b) for (int i=(a);i<(b);i++)
#define rep(i,n) repd(i,0,n)
#define all(x) (x).begin(),(x).end()
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
typedef long long ll;
const long long INF = 1LL << 60;
int main()
{
    float N;
    cin >> N;
    int a = N;
    if (a % 2 != 0) a = a + 1;
    a /= 2;
    
    cout << fixed << setprecision(7) << (float)a / N << endl;
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
///...................................*****.................................................///
///        Author :  MD. Rakibul Islam ( mmdrakibul2912@gmail.com )                         ///
///                  Department of Computer Science                                         ///
///                  & Engineering,                                                         ///
///                  Comilla University , Bangladesh.                                       ///
///...................................*****.................................................///
using namespace std;
int main()
{

    int N;
    long ans=1;
    cin >> N;
    int A[N];
    for(int i=0; i<N; i++)
        cin >> A[i];
    sort(A, A+N);

    if(N%2==0)
    {
        for(int i=0; i<N; i++)
        {
            if(i%2!=0 && (A[i]!=i || A[i-1]!=i))
            {
                cout << "0" << endl;
                return 0;
            }
        }
        for(int i=0; i<N/2; i++)
        {
            ans *= 2;
            ans %= 1000000007;
        }
        cout << ans << endl;

    }
    else
    {

        if(A[0]!=0)
        {
            cout << "0" << endl;
            return 0;
        }

        for(int i=1; i<N; i++)
        {
            if(i%2==0 && (A[i]!=i || A[i-1]!=i))
            {
                cout << "0" << endl;
                return 0;
            }
        }
        for(int i=0; i<(N-1)/2; i++)
        {
            ans *= 2;
            ans %= 1000000007;
        }
        cout << ans << endl;
    }

    return 0;
}


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

int main()
{

        int N;
        cin >> N;

        map<string, int> m;
        for (int i = 0; i < N; ++i) {
                string tmp;
                cin >> tmp;
                m[tmp] += 1;
        }

        int mx = -1;
        for (auto i : m) {
                if (i.second > mx) {
                        mx = i.second;
                }
        }
        for (auto i : m) {
                if (i.second == mx) {
                        cout << i.first << endl;
                }
        }

}


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

int main(){
	int K,S;
	cin >> K>>S;
	int count =0;
	for(int i=0;i<=K;i++){
		for(int k=0;k<=K;k++){
			if(S-i-k>=0 &&S-i-k<=K){
				count++;
			}
		}
	}
	cout<<count<<endl;
	
}




Measured memory_bytes: 256
#include<iostream>
using namespace std;
int main(){
    int a,b;
    char c='a';
    while (c!='?'){
        cin >> a >> c >> b;
        switch(c){
            case '+':
                cout << a+b << endl;
                break;
            case '-':
                cout << a-b << endl;
                break;
            case '*':
                cout << a*b << endl;
                break;
            case '/':
                cout << a/b << endl;
                break;
        }
    }
    return 0;
}


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

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

  int ans = 0;
  for (int i = 0; i < N.size() - 1; i += 2) {
    int n = stoi(string(i + 1, '9'));
    ans += n - (int)pow(10, i) + 1;
  }

  if (N.size() % 2 != 0) {
    int n = stoi(N);
    ans += n - (int)pow(10, N.size() - 1) + 1;
  }
  cout << ans << endl;
}


Measured memory_bytes: 512
#include<bits/stdc++.h>
#define ad(x,y) (x=((x)+(y))%1000000007)
#define N 21
#define M 1050005
using namespace std;
 
int n,m,cnt,p0[N],p1[N],f[M][N],dp[M];
int main(){
	scanf("%d%d%d",&n,&m,&cnt); n--;
	int i,j,k,x,y,z;
	for (i=1; i<=cnt; i++){
		scanf("%d%d%d",&x,&y,&z);
		y=n-y;
		if (z) p1[x]|=1<<y; else p0[x]|=1<<y;
	}
	int tot=1<<n;
	for (i=0; i<tot; i++) if ((i&p1[1])==p1[1] && (i&p0[1])==0) dp[i]=1;
	for (i=0; i<tot; i++)
		for (j=0; j<n; j++){
			for (k=j-1; k>=0; k--) if (!(i>>k&1)) break;
			f[i][j]=(k<0)?i:(i|1<<k);
		}
	for (i=2; i<=m; i++){
		for (j=0; j<n; j++)
			for (k=0; k<tot; k++) if (k>>j&1) ad(dp[k],dp[f[k^(1<<j)][j]]);
		for (j=0; j<tot; j++) if ((j&p1[i])!=p1[i] || (j&p0[i])!=0) dp[j]=0;
	}
	for (j=1; j<tot; j++) ad(dp[0],dp[j]);
	printf("%d\n",dp[0]);
	return 0;
}


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

int main() {
    string s;
    int d, g;
    cin >> d >> g;
    pair<int, int> p[d];
    rep(i, d) cin >> p[i].first >> p[i].second;

    int ans = 999999;
    int n = d;
    for (int bit = 0; bit < (1 << n); bit++) {
        int sum = 0;
        int c = 0;
        for (int i = 0; i < n; i++) {
            if (bit & (1 << i)) {
                sum += 100 * (i + 1) * p[i].first + p[i].second;
                c += p[i].first;
            }
        }
        if (sum < g) {
            for (int i = n - 1; i >= 0; i--) {
                if (!(bit & (1 << i))) {
                    rep(j, p[i].first) {
                        sum += 100 * (i + 1);
                        c++;
                        if (sum >= g) {
                            break;
                        }
                    }
                }
                if (sum >= g) {
                    break;
                }
            }
        }
        ans = min(ans, c);
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 3592
n,m = gets.chomp.split(' ').map(&:to_i)
lamps = []
m.times do
  lamps << gets.chomp.split(' ').map(&:to_i)
end
p_arr = gets.chomp.split(' ').map(&:to_i)
lamps.each.with_index do |lamp,id|
  lamp << p_arr[id]
end
ans = 0
pattern = 0
while pattern < 2**n
  pattern_list = pattern.to_s(2).chars.map(&:to_i)
  k = n - pattern_list.size
  k.times do
    pattern_list.unshift(0)
  end
  pattern_list.reverse!
  count = 0
  lamps.each do |lamp|#各ランプが点灯しているかをチェック
    j = 1
    on_count = 0#Onの個数
    while j < lamp.size - 1
      if pattern_list[lamp[j]-1] == 1
        on_count += 1
      end
      j += 1
    end
    if on_count % 2 == lamp[-1]
      count += 1
    end
  end
  if count == lamps.size#全てのランプをチェックしたら点灯数チェック
    ans += 1
  end
  pattern += 1
end
puts ans

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

int main(){
  int N;
  cin >> N;
  vector<int> A(N);
  for(int i = 0; i < N; ++i) cin >> A[i];
  sort(A.begin(), A.end());
  if(A.back()-A[0] > 1){
    cout << "No" << endl;
    return 0;
  }
  if(A[0] != A.back()){
    int c = N;
    for(int i = 0; i < N; ++i){
      if(A[i] == A[0]) --c;
      else break;
    }
    if(A.back()-(N-c) <= 0) cout << "No" << endl;
    else if(c >= 2*(A.back()-(N-c))) cout << "Yes" << endl;
    else cout << "No" << endl;
    return 0;
  }
  if(A[0] == N-1 or A[0]*2 <= N) cout << "Yes" << endl;
  else cout << "No" << endl;
}


Measured memory_bytes: 640
import java.util.Scanner;
import java.util.ArrayList;
 
public class Main {
    public static void main(String[] args) {
        Scanner scan = new Scanner(System.in);
      ArrayList<String> list = new ArrayList<String>();
      int A,B,H,M;
      int i = 0;
      String an = scan.nextLine();
      String atai[] = an.split(" ",0);
      int num[] = new int[4];
      while(i < 4){
        num[i] = Integer.parseInt(atai[i]);
        i++;
      }
      A = num[0];
      B = num[1];
      H = num[2];
      M = num[3];
//      System.out.println(A+","+B+","+H+","+M);
      check(A,B,H,M);
        scan.close();
    }
  
  public static void check(int a,int b,int h,int m){
   double ang;
   double result,c; 
    ang = ((30*h + 0.5*m) - 6*m);
    ang = Math.abs(ang);
//    System.out.println(ang);
    if(ang == 180){
      result = a+b;
      System.out.println(result);
      return;
    }else if(ang > 180){
      ang = 360 -ang;
//      System.out.println(ang);
    }
    ang = Math.toRadians(ang);
    c = a*a + b*b - 2*a*b*Math.cos(ang);
    result = Math.sqrt(c);
    System.out.println(result);
    return;
  }
}

Measured memory_bytes: 36028
#include <bits/stdc++.h>
using namespace std;
#define looplt(i,x) for(i=0; i<x; ++i)
#define bsrch(v,x) binary_search(v.begin(), v.end(), x)
#define vecl vector <long long int>
#define pb(x) push_back(x)
#define MAX_INT 10e+10
typedef long long int ll;

int main()
{
    string s;
    cin >> s;
    ll max = -1, count=0;

    for(ll i=0; i<s.length(); ++i){
        if(s[i] == 'R') count++;
        else count = 0;

        if(count > max) max = count;
    }

    cout << max << endl;
}

Measured memory_bytes: 3620
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < n; i++)
using namespace std;
string s;
int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);

  cin >> s;
  int len = s.length() - 8;
  cout << s.substr(0, len) << endl;

  return 0;
}


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

int data[200005];
int pos[200005];
map<int,int> nn;

int main(){
	int ban;
	scanf("%d",&ban);
	double median=(double)(ban+1)/2;
	for(int i=1;i<=ban;i++){
		scanf("%d",&data[i]);
		pos[i]=data[i];
	}
	sort(pos+1,pos+ban+1);
	for(int i=1;i<=ban;i++){
		nn[pos[i]]=i;
	}
	for(int i=1;i<=ban;i++){
		if(nn[data[i]]<median){
			printf("%d\n",pos[(int)ceil(median)]);	
		}
		else{
			printf("%d\n",pos[(int)floor(median)]);
		} 
	}
}

Measured memory_bytes: 12928
import scala.io.Source.stdin

object Main {
  val w = List(1,2,4,8,16,32,64,128,256,512)
  def main(args:Array[String]) =
    println(stdin.getLines.map(_.toInt).map { i=>w.filter(y=>(y & i)>0).mkString(" ") }.mkString("\n"))
}

Measured memory_bytes: 43548
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<ll,ll> P;
typedef pair<int,int> Pi;
#define rep(i,n) for(ll i=0;i<n;i++)
#define FOR(i,a,b) for(ll i=a;i<b;i++)
#define fi first
#define se second
#define endl "\n"

template<typename T> inline bool chmax(T &a, T b){if(a<b){a=b;return true;}return false;}
template<typename T> inline bool chmin(T &a, T b){if(a>b){a=b;return true;}return false;}
template<typename T> ostream& operator<<(ostream& s,const complex<T>& d) {return s<<"("<<d.real()<<", "<<d.imag()<< ")";}
template<typename T1, typename T2> ostream& operator<<(ostream& s,const pair<T1,T2>& d) {return s<<"("<<d.first<<", "<<d.second<<")";}
template<typename T> ostream& operator<<(ostream& s, const vector<T>& d){int len=d.size();rep(i,len){s<<d[i];if(i<len-1) s<<" ";}return s;}
template<typename T> ostream& operator<<(ostream& s,const vector<vector<T>>& d){int len=d.size();rep(i,len){s<<d[i]<<endl;}return s;}
template<typename T> ostream& operator<<(ostream& s,const set<T>& v){s<<"{ ";for(auto itr=v.begin();itr!=v.end();++itr) {if (itr!=v.begin()) {s<< ", ";}s<<(*itr);}s<<" }";return s;}
template<typename T1, typename T2> ostream& operator<<(ostream& s,const map<T1,T2>& m){s<<"{"<<endl;for(auto itr=m.begin();itr!=m.end();++itr){s<<" "<<(*itr).first<<" : "<<(*itr).second<<endl;}s<<"}"<<endl;return s;}

const ll mod=1e9+7;
const ll inf=1e17;
const int INF=1e9;
const double PI=acos(-1);
const double EPS=1e-10;

int main(){
    cin.tie(0);ios::sync_with_stdio(false);
    int n;
    string s;
    cin>>n>>s;
    vector<int> ans(n+1,0);
    auto solve=[&](int x,int y){
        rep(i,n+1) ans[i]=0;
        ans[0]=x,ans[1]=y;
        FOR(i,1,n){
            if(s[i]=='o'){
                if(ans[i]==1) ans[i+1]=ans[i-1];
                else ans[i+1]=-ans[i-1];
            }else{
                if(ans[i]==1) ans[i+1]=-ans[i-1];
                else ans[i+1]=ans[i-1];
            }
        }
        if(ans[0]!=ans[n]) return false;
        if(s[0]=='o'){
            if(ans[0]==1) return ans[n-1]==ans[1];
            else return ans[n-1]!=ans[1];
        }else{
            if(ans[0]==1) return ans[n-1]!=ans[1];
            else return ans[n-1]==ans[1];
        }
    };
    if(solve(-1,1)){
        rep(i,n){
            if(ans[i]==1) cout<<'S';
            else cout<<'W';
        }
        cout<<endl;
    }else if(solve(1,-1)){
        rep(i,n){
            if(ans[i]==1) cout<<'S';
            else cout<<'W';
        }
        cout<<endl;
    }else if(solve(1,1)){
        rep(i,n){
            if(ans[i]==1) cout<<'S';
            else cout<<'W';
        }
        cout<<endl;
    }else if(solve(-1,-1)){
        rep(i,n){
            if(ans[i]==1) cout<<'S';
            else cout<<'W';
        }
        cout<<endl;
    }else{
        cout<<-1<<endl;
    }
}

Measured memory_bytes: 1104
#define _USE_MATH_DEFINES
#include<iostream>
#include<cstdio>
#include<vector>
#include<algorithm>
#include<string>
#include<cmath>
#include<list>
#include<stack>
#include<queue>
#include<cctype>
#include<iomanip>
#include<functional>
#include<numeric>
#include<map>
#include<set>
#include<complex>
#define EPS 1e-10
using namespace std;
typedef long long llong;
int main() {
	string s;
	int a, b;
	for (int i = 0; i < 9; i++) {
		cin >> s >> a >> b;
		cout << s << " " << a + b << " " << a * 200 + b * 300 << endl;
	}
	return 0;
}

Measured memory_bytes: 3152
import scala.io.StdIn

/**
  * AOJ
  */
object Main {

  def main(args: Array[String]): Unit = {

    val p = new Point(0,0)
    val n = StdIn.readInt()
    for(_ <- 1 to n){
      val animals = StdIn.readLine().split(" ")
      if(animals(0) > animals(1)){
        p.taro += 3
      } else if(animals(0) < animals(1)){
        p.hanako += 3
      } else {
        p.taro += 1
        p.hanako += 1
      }
    }
    println(p.taro + " " + p.hanako)
  }
  class Point(var taro:Int,var hanako:Int)
}

Measured memory_bytes: 44056
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		String N = sc.nextLine();
		String P = sc.nextLine();
		String[] PA = P.split(" ");
		int zure = 0;
		
		for(int i=1; i<=Integer.parseInt(N); i++) {
			if(Integer.parseInt(PA[i - 1]) != i) {
				zure++;
			}
		}
		
		if(zure <= 2) {
			System.out.println("YES");
		}else {
			System.out.println("NO");
		}
		
		sc.close();
	}
}

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

int main() {
  unsigned long long H, W;//縦H, 横Wマス
  cin >> H >> W;
  unsigned long long sum;
  if(H==1 || W==1){
    sum = 1;
  } else {
    sum = H*W/2;
    if(H%2==1 && W%2==1){
     sum++;
    }
  }

  cout << sum << endl;
}




Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
#include <cmath>
#include <vector>
#include <stack>
#include <queue>
using namespace std;
typedef long long ll;
int main() {
	int n, a[101][101], dp[2][101];
	cin >> n;
	for (int i = 0; i < 2; i++) {
		for (int j = 0; j < n; j++)cin >> a[i][j];
	}
	dp[0][0] = a[0][0];
	dp[1][0] = a[0][0] + a[1][0];
	for (int i = 1; i < n; i++)dp[0][i] = dp[0][i - 1] + a[0][i];
	for (int i = 1; i < n; i++) {
		dp[1][i] = max(dp[0][i] + a[1][i], dp[1][i - 1] + a[1][i]);
	}
	cout << dp[1][n - 1] << endl;
	getchar();
	getchar();
	return 0;
}


Measured memory_bytes: 256
import java.io.*;
import java.util.*;

class Main{
    public static void main(String[] args){
	BufferedReader sc=new BufferedReader(new InputStreamReader(System.in));
	try{
	    int n = Integer.valueOf(sc.readLine());
	    for(int i=0; i<n; i++){
		String[] ball = sc.readLine().split(" ");
		int[] sap = new int[10];
		for(int j=0; j<10; j++)
		    sap[j] = Integer.valueOf(ball[j]);
		int max = sap[0], min=0;
		String out = "YES";
		for(int j=1; j<10; j++){
		    if(sap[j]>max)
			max = sap[j];
		    else if(sap[j]<max)
			if(sap[j]<min){
			    out = "NO";
			    break;
			}
			else
			    min = sap[j];
		}
		System.out.println(out);
	    }
	}catch (Exception e){
	    System.out.println("Error");
	}
    }
}

Measured memory_bytes: 9328
A, B, C = map(int, raw_input().split())

num = 0

while (A != B or B != C or C != A):
    if max(A,B,C) == A and A != B and A != C:
        B += 1
        C += 1
    elif max(A,B,C) == A and A == B and A != C:
        C += 2
    elif max(A,B,C) == A and A != B and A == C:
        B += 2
    elif max(A,B,C) == B and B != A and B != C:
        A += 1
        C += 1
    elif max(A,B,C) == B and B != A and B == C:
        A += 2
    elif max(A,B,C) == B and B == A and B != C:
        C += 2
    elif max(A,B,C) == C and C != A and C != B:
        A += 1
        B += 1
    # elif max(A,B,C) == C and C != A and C == B:
    #     A += 2
    #     num += 1
    # elif max(A,B,C) == C and C == A and C != B:
    #     B += 2
    #     num += 1
    else:
        print "unexpect"

    num += 1
#    print A, B, C

print num


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

namespace AOJ.Volume0
{
    class Program0003
    {
        static void Main(string[] args)
        {
            int dataLength = int.Parse(Console.ReadLine());
            Queue<bool> results = new Queue<bool>();

            for (int i = 0; i < dataLength; i++)
            {
                string input = Console.ReadLine();
                string[] splitedInput = input.Split(' ');
                int[] pair = new int[3];

                for (int j = 0; j < 3; j++)
                {
                    pair[j] = int.Parse(splitedInput[j]);
                }

                pair = pair.OrderBy(x => x).ToArray();

                results.Enqueue(pair[0] * pair[0] + pair[1] * pair[1] == pair[2] * pair[2]);
            }

            foreach (var result in results)
            {
                Console.WriteLine("{0}", result ? "YES" : "NO");
            }
        }
    }
}

Measured memory_bytes: 6568
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> pp;
const int INF = 1e9;
const int MOD = 1000000007;
#define rep(i,n); for(int i=0;i<n;i++)

int main() {
  string s;
  int k;
  cin >> s >> k;
  int now = k;
  int i=0;
  while(now > 0 && i < s.size()){
    if(s.at(i) == 'a') ;
    else if(26 - (s.at(i)-'a') <= now){
      now -= 26 - (s.at(i) -'a');
      s.at(i) = 'a';
    }
    i++;
  }
  string alpha = "abcdefghijklmnopqrstuvwxyz";
  if(now > 0){
    now %= 26
    rep(i,26){
      if(s.at(s.size()-1) == alpha.at(i)){
        s.at(s.size()-1) = alpha.at(i+now);
        break;
      }
    }
  }
  cout << s << endl;
      
  return 0;
}




Measured memory_bytes: 512
#include <iostream>
#include <math.h>
#include <limits>
#include <iomanip>
#include <algorithm>
#include <vector>
#include <stdio.h>
#include <map>
#include <utility>
using namespace std;
#define rep(i, n) for (int i =0; i < (int)(n); i++)
typedef pair<int, string> P;




int main() {
    int  n,d;
    cin >> n>>d;
    cout << (n+d*2) / (d * 2+1) << endl;
    
}



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

ld dp[3010][3010];

int main(int argc, char **argv)
{
	ll N; cin >> N;
	vector<ld> p(N); for (ll i = 0; i < N; ++i) cin >> p[i];

	dp[0][0] = 1.f;
	for (ll i = 0; i < N; ++i)
	{
		for (ll j = 0; j <= i; ++j)
		{
			dp[i+1][j+1] += dp[i][j] * p[i];
			dp[i+1][j] += dp[i][j] * (1.0 - p[i]);
		}
	}

	ld res{0.0};
	for (ll i = (N+1)/2; i <= N; ++i) res += dp[N][i];
	std::cout << fixed << setprecision(10) << res << std::endl;
	
}


Measured memory_bytes: 139776
#pragma GCC compiler("O3")
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main(){
  //freopen("input.txt","r",stdin);
  //freopen("output.txt","w",stdout);
  ios_base::sync_with_stdio(0);
  int a,b,c;
  cin>>a>>b>>c;
  cout<<min(a*b,c)<<endl;
  return 0;
}


Measured memory_bytes: 256
n = int(input())
l = list(map(int,input().split()))
count = 0
for i in range(len(l) - 2):
    if (l[i] > l[i+1] and l[i+1] > l[i+2]) or (l[i] < l[i+1] and l[i+1] < l[i+2]) :
        count += 1
print(count)


Measured memory_bytes: 38384
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <functional>
#include <numeric>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <utility>
#include <sstream>
#include <complex>

using namespace std;

#define FOR(i,a,b) for(long long i=(a);i<(b);i++)
#define REP(i,N) for(long long i=0;i<(N);i++)
#define ALL(s) (s).begin(),(s).end()
#define fi first
#define se second

#define PI acos(-1.0)
#define INF 1000000007
#define EPS 1e-10
#define MAX_N 20000
#define MAX_M 16

typedef long long ll;
typedef pair<ll, ll> P;
typedef pair<double, double> PD;
typedef pair<string, ll> PS;
typedef vector<ll> V;
typedef pair<P, char> PC;

int e, m;

int main(){
	while (cin >> e&&e){
		int m = 1000001;
		for (int i = 0; i <= 100; i++){
			for (int j = 0; j <= 1000; j++){
				int x = e - i*i*i - j*j;
				if (x >= 0){
					m = min(m, x + i + j);
				}
			}
		}
		cout << m << endl;
	}
}

Measured memory_bytes: 1156