akhauriyash/Code-Regression huggingface dataset:
#include<stdio.h>
#include<math.h>
#include<string.h>

typedef struct dice{
	int e[7]; /*Dice Eyes 1～6*/
}dice_t;

/*縦奥回転*/
void DiceRoll_N(dice_t* pDice){
	pDice->e[0] = pDice->e[1];
	pDice->e[1] = pDice->e[2];
	pDice->e[2] = pDice->e[6];
	pDice->e[6] = pDice->e[5];
	pDice->e[5] = pDice->e[0];
	return ;
}
void DiceRoll_S(dice_t* pDice){
	pDice->e[0] = pDice->e[1];
	pDice->e[1] = pDice->e[5];
	pDice->e[5] = pDice->e[6];
	pDice->e[6] = pDice->e[2];
	pDice->e[2] = pDice->e[0];
	return ;
}
/*時計回り回転*/
void DiceRoll_E(dice_t* pDice){
	pDice->e[0] = pDice->e[1];
	pDice->e[1] = pDice->e[4];
	pDice->e[4] = pDice->e[6];
	pDice->e[6] = pDice->e[3];
	pDice->e[3] = pDice->e[0];
	return ;
}
void DiceRoll_W(dice_t* pDice){
	pDice->e[0] = pDice->e[1];
	pDice->e[1] = pDice->e[3];
	pDice->e[3] = pDice->e[6];
	pDice->e[6] = pDice->e[4];
	pDice->e[4] = pDice->e[0];
	return ;
}
/*左回りのスピン*/
void DiceRoll_Spin(dice_t* pDice){
	pDice->e[0] = pDice->e[2];
	pDice->e[2] = pDice->e[4];
	pDice->e[4] = pDice->e[5];
	pDice->e[5] = pDice->e[3];
	pDice->e[3] = pDice->e[0];
	return ;
}


int main(){
	int i,j;
	dice_t dice, dice2;
	dice_t* pDice = &dice;
	dice_t* pDice2 = &dice2;
	int ok_cnt;
	
	ok_cnt = 0;
	
	for(i=1; i<7; i++)	scanf("%d", &dice.e[i]);
	for(i=1; i<7; i++)	scanf("%d", &dice2.e[i]);
	
	for(i=0; i<7; i++){
		/*1～6面までそれぞれを上面にした場合の一致を確認するためにダイス１を回す(目の数が同じ面の場合に対応するため)*/
		if(i>0 && i<4){
			DiceRoll_N( pDice );	/*1面は回さず、2~4面を回しながら確認*/
		}else if(i==4){
			DiceRoll_E( pDice );	/*横倒しにして5面を頂点に*/
		}else{
			DiceRoll_E( pDice );	/*横倒し×２で5面の裏面を頂点に*/
			DiceRoll_E( pDice );
		}
		/*ダイス１と２の比較を開始*/
		for(j=0; j<3; j++){
			if( dice.e[1] == dice2.e[1] )	break;
			DiceRoll_N( pDice2 );
		}
		if( dice.e[1] != dice2.e[1] ){	/*縦回しで見つからない→側面を捜索*/
			if( dice.e[1] == dice2.e[3] ){
				DiceRoll_E( pDice2 );
			}else if( dice.e[1] == dice2.e[4] ){
				DiceRoll_W( pDice2 );
			}else{
				break;
			}
		}
		for(j=0; j<3; j++){
			if( dice.e[2] == dice2.e[2] )	break;
			DiceRoll_Spin( pDice2 );
		}
		for(j=3; j<7; j++)	if( dice.e[j] != dice2.e[j] )	break;
		if( j == 7){
			ok_cnt++;
		}else{
			;
		}
			
	}
	if( ok_cnt == 0){
		printf("No\n");
	}else{
		printf("Yes\n");
	}
	
	
	return 0;
}




Measured memory_bytes: 2144
if __name__ == '__main__':
    import sys
    input = sys.stdin.readline
    n = int(input())
    ns = [0]*n
    for i in range(n):
        a,b = map(int, input().split())
        ns[i] = [a,b,a+b]
    ns.sort(key=lambda x: x[2], reverse=True)
    count = 0
    for i in ns[::2]:
        count+=i[0]
    for i in ns[1::2]:
        count-=i[1]
    print(count)


Measured memory_bytes: 24412
#include <bits/stdc++.h>
using namespace std;
int main() {
  int n,a=0;
  double d,x,y;
  cin>>n>>d;
  for(;n--;){
    cin>>x>>y;
    if(d>=sqrt(x*x+y*y)) a++;
  }
  cout<<a;
}

Measured memory_bytes: 3800
package main
import . "fmt"
func main() {
  var s,n int
  set := make(map[int]struct{})
  Scan(&s)
  n = 1
  for ;; {
    if _,ok := set[s];ok {
      break
    } else {
      set[s] = struct{}{}
      s = f(s)
      n++
    }
  }
  Println(n)
}
func f(n int) int {
  if n%2 == 0 {
    return n/2
  } else {
    return 3*n + 1
  }
}

Measured memory_bytes: 512
import java.util.HashMap;
import java.util.Scanner;

class Main{

	static Scanner scanner = new Scanner(System.in);
	static HashMap<Integer, Integer> map;

	public static void main(String args[]){
		while(true){
			int n = scanner.nextInt();
			if(n == 0) break;
			map = new HashMap<Integer, Integer>();
			System.out.println(solve(n));
		}
	}

	static String solve(int n){
		int i = 0;
		Integer m;
		Integer num;
		String result = "NO COLOR";
		for(i = 0; i < n; i++){
			m = scanner.nextInt();
			num = map.get(m);
			if(num != null){
				num++;
				map.put(m, num);
				if(num > n/2) result = m + "";
			}else{
				map.put(m, 1);
				num = 1;
				if(num > n/2) result = m + "";
			}
			if(i % 200000 == 0) System.gc();
		}
		return result;
	}
}

Measured memory_bytes: 189252
# 参考url: https://beta.atcoder.jp/contests/abc045/submissions/2365068

from collections import Counter, defaultdict

H, W, N = map(int, input().split())

squares = defaultdict(int)
for i in range(N):
    h, w = map(int, input().split())
    for hh in range(3):
        for ww in range(3):
            th, tw = h-hh, w-ww
            # th, twを左上とする3×3の正方形は与えられたグリッドに収まるか
            if 1 <= th <= H-2 and 1 <= tw <= W-2:
                squares[(th, tw)] += 1

ans = [0] * 10
for v in squares.values():
    ans[v] += 1

# 黒マスが0 = 正方形の総数-黒マスが1個以上の正方形
ans[0] = (H-2)*(W-2) - sum(ans)

print(*ans, sep="\n")

Measured memory_bytes: 181732
void solve(){
}
void main(){
	string s = instr();
	int head = s[0..2].to!int();
	int tail = s[2..4].to!int();
	int stat;
	if(1<=head && head<=12){
		stat = stat|1;
	}
	if(1<=tail && tail<=12 ){
		stat = stat|2;
	}
	switch(stat){
		case 1:
			writeln("MMYY"); break;
		case 2:
			writeln("YYMM"); break;
		case 3:
			writeln("AMBIGUOUS"); break;
		default:
			writeln("NA");
	}

}
     
import std.stdio, std.conv, std.algorithm, std.numeric, std.string, std.math, std.range;
const long mod = 10^^9+7;
alias instr = () => readln().chomp();
T inelm(T= int)(){ return to!(T)( readln().chomp() ); }
T[] inary(T = int)(){ return readln().chomp().split().to!(T[])(); }



Measured memory_bytes: 2720
//https://atcoder.jp/contests/abc142/tasks/abc142_a
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define ll long long
int main(){
    int n;
    cin >> n;

    if(n%2 ==0){
        double a;
        a = n/2;
        cout <<fixed << setprecision(7) << a/n<< endl;
    }
    else{
        double a;
        a = n/2 +1;
        cout << fixed << setprecision(7) << a/n << endl;
    }

}

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

long BIG = 1000000007;

long long modpow(long long a, long long n, long long mod) {
  long long res = 1;
  while (n > 0) {
    if (n & 1) res = res * a % mod;
    a = a * a % mod;
    n >>= 1;
  }
  return res;
}

int main() {
  long N, K;
  long long ans = 0;
  cin >> N >> K;

  vector<long> vec(K + 10, -1);
  for (int i = K; i > 0; i--) {
    vec[i] = modpow(K / i, N, BIG);
    for (int j = i * 2; j <= K; j += i) {
      vec[i] = (vec[i] - vec[j] + BIG) % BIG;
    }
    ans = (ans % BIG + vec[i] * i % BIG) % BIG;
    // cout << ans << endl;
  }
  cout << ans << endl;
}

Measured memory_bytes: 4020
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define mp make_pair
#define pb push_back
#define rep(i,n) for(int i=0;i<n;i++)
#define rep1(i,n) for(int i=1;i<=(int)(n);i++)



template< int mod >
struct ModInt {
  int x;

  ModInt() : x(0) {}

  ModInt(int64_t y) : x(y >= 0 ? y % mod : (mod - (-y) % mod) % mod) {}

  ModInt &operator+=(const ModInt &p) {
    if((x += p.x) >= mod) x -= mod;
    return *this;
  }

  ModInt &operator-=(const ModInt &p) {
    if((x += mod - p.x) >= mod) x -= mod;
    return *this;
  }

  ModInt &operator*=(const ModInt &p) {
    x = (int) (1LL * x * p.x % mod);
    return *this;
  }

  ModInt &operator/=(const ModInt &p) {
    *this *= p.inverse();
    return *this;
  }

  ModInt operator-() const { return ModInt(-x); }

  ModInt operator+(const ModInt &p) const { return ModInt(*this) += p; }

  ModInt operator-(const ModInt &p) const { return ModInt(*this) -= p; }

  ModInt operator*(const ModInt &p) const { return ModInt(*this) *= p; }

  ModInt operator/(const ModInt &p) const { return ModInt(*this) /= p; }

  bool operator==(const ModInt &p) const { return x == p.x; }

  bool operator!=(const ModInt &p) const { return x != p.x; }

  ModInt inverse() const {
    int a = x, b = mod, u = 1, v = 0, t;
    while(b > 0) {
      t = a / b;
      swap(a -= t * b, b);
      swap(u -= t * v, v);
    }
    return ModInt(u);
  }

  ModInt pow(int64_t n) const {
    ModInt ret(1), mul(x);
    while(n > 0) {
      if(n & 1) ret *= mul;
      mul *= mul;
      n >>= 1;
    }
    return ret;
  }

  friend ostream &operator<<(ostream &os, const ModInt &p) {
    return os << p.x;
  }

  friend istream &operator>>(istream &is, ModInt &a) {
    int64_t t;
    is >> t;
    a = ModInt< mod >(t);
    return (is);
  }

  static int get_mod() { return mod; }
};
const int mod=1e9+7;
using modint = ModInt< mod >;

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

  int h,w,n;
  cin >> h >> w >> n;
  vector<pair<int, int> > cor(n);
  rep(i,n){
    int r,c;
    cin >> r >> c;
    --r;--c;
    cor[i]=mp(r,c);
  }
  sort(cor.begin(), cor.end());
  const int n_max=h+w+10;
  vector<modint> kai(n_max);
  kai[0]=1;
  rep1(i,n_max-1) kai[i]=kai[i-1]*((modint)i );
  vector<vector<modint> > dp(n, vector<modint>(2));
  rep(i,n) dp[i][0]=0;
  rep(i,n){
    int r=cor[i].first;
    int c=cor[i].second;
    dp[i][1]=kai[r+c]/kai[r]/kai[c];
  }
  modint ans=kai[h+w-2]/kai[h-1]/kai[w-1];
  rep(i,n){
    int ci=cor[i].second;
    int ri=cor[i].first;
    rep(j,i){
      int cj=cor[j].second;
      if(ci >= cj){
	int rj=cor[j].first;
	modint fac=kai[ri-rj+ci-cj]/kai[ri-rj]/kai[ci-cj];
	dp[i][0] += dp[j][1]*fac;
	dp[i][1] += dp[j][0]*fac;
      }
    }
    ans +=(dp[i][0] - dp[i][1])*kai[h-1-ri+w-1-ci]/kai[h-1-ri]/kai[w-1-ci];
  }

  cout << ans << endl;
  return 0;
    

}


Measured memory_bytes: 1408
#include<iostream>
#include<algorithm>
#include<string>
#include<vector>
#include<queue>
#include<map>
using namespace std;
#define REP(i, limit) for(int i=0; i< limit; ++i)
#define LL long long


int main(){
  int N;
  cin>>N;
  LL t[N], a[N];
  REP(i, N){
    cin>>t[i]>>a[i];
  }

  LL A=a[0], T=t[0];
  LL work;
  for(int i=1; i<N; ++i){
    if(a[i]==a[i-1]&&t[i]==t[i-1]) continue;
    work=max((A-1)/a[i]+1, (T-1)/t[i]+1);
    A=a[i]*work;
    T=t[i]*work;
  }
  cout<<A+T<<endl;


  return 0;
}


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

int abs( int a )
{
    return a < 0 ? -a : a;
}

int min( int a, int b )
{
    return a < b ? a : b;
}

int dp[100001];
// void calcMin( int* a, int n, int k )
// {
//     dp[1] = fabs( a[0] - a[1] );

//     for( int i = 2; i < n; i++ )
//     {
//         int min = 10000;
//         for( int j = i - 1; j >= 0 && j >= i - k; j-- )
//         {
//             int b = dp[j] + fabs( a[j] - a[i] );
//             if( b < min )
//                 min = b; 
//         }
//         dp[i] = min;
//     }
// }

void calcMin2( int* a, int n, int k )
{
    for( int i = 0; i < n; i++ )
        for( int j = i + 1; j < n && j <= i + k; j++ )
            dp[j] = min( dp[j], dp[i] + abs( a[j] - a[i] ) );
}


int main()
{
    int n, k;

    cin >> n >> k;

    int a[n];

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

    for( int i = 1; i < 100001; i++ )
        dp[i] = 2000000000;

    calcMin2( a, n, k );
    cout << dp[n-1] << endl;
    // for( int i = 0; i < n; i++ )
    //     cout << dp[i] << " ";
    // cout << endl;

    return 0;
}

Measured memory_bytes: 1024
/*
 * aoj/dpl_5_j/main.cpp
 */

// C++ 14
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <cstring> // memset
#include <cassert>
using namespace std;
#define ll long long
#define loop(__x, __start, __end) for(int __x = __start; __x < __end; __x++)
template <class T> ostream & operator << (ostream & out, vector<T> const & v) {
  for (auto &&a: v) out << a << " "; out << endl; return out;
}
template <class T> void dump(T &a) { cout << a << endl; }
template <class T> bool chmin(T &a, T b) { if (a > b) {a = b; return true; } return false; }
template <class T> bool chmax(T &a, T b) { if (a < b) {a = b; return true; } return false; }
/* Mod */
#define MOD 1000000007
struct mint {
  ll x;
  mint():x(0){}
  mint(ll x):x((x%MOD+MOD)%MOD){}
  // mint(ll x):x(x){}
  mint& fix() { x = (x%MOD+MOD)%MOD; return *this;}
  mint operator-() const { return mint(0) - *this;}
  mint& operator+=(const mint& a){ if((x+=a.x)>=MOD) x-=MOD; return *this;}
  mint& operator-=(const mint& a){ if((x+=MOD-a.x)>=MOD) x-=MOD; return *this;}
  mint& operator*=(const mint& a){ (x*=a.x)%=MOD; return *this;}
  mint operator+(const mint& a)const{ return mint(*this) += a;}
  mint operator-(const mint& a)const{ return mint(*this) -= a;}
  mint operator*(const mint& a)const{ return mint(*this) *= a;}
  bool operator<(const mint& a)const{ return x < a.x;}
  bool operator==(const mint& a)const{ return x == a.x;}
};
ostream & operator << (ostream & out, mint const & v) {
  out << v.x;
  return out;
}

// P(n, k) = P(n-k, k) + P(n, k-1) (n, k>=0)
// P(0, k) = 1
int N, K;
mint P[1010][1010];
void solve() {
  cin >> N >> K;
  loop(k,0,K+1) P[0][k] = 1;
  for (int n=1; n<=N; n++) {
    for (int k=1; k<=K; k++) {
      P[n][k] = (n-k>=0 ? P[n-k][k] : 0) + P[n][k-1];
    }
  }
  cout << P[N][K] << endl;
}
int main() {
  // cout.precision(15); cout << fixed;

  solve();

  return 0;
}



Measured memory_bytes: 11076
// template version 1.13
using namespace std;
#include <bits/stdc++.h>

// varibable settings
#define infile "../test/sample-1.in"
#define int long long //{{{
const int INF=1e18;
const int MOD=1e9+7; //}}}

// define basic macro {{{
#define _overload3(_1,_2,_3,name,...) name
#define _rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(int i=(int)(a);i<(int)(b);++i)
#define rep(...) _overload3(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)
#define _rrep(i,n) rrepi(i,0,n)
#define rrepi(i,a,b) for(int i=(int)((b)-1);i>=(int)(a);--i)
#define rrep(...) _overload3(__VA_ARGS__,rrepi,_rrep,)(__VA_ARGS__)
#define each(i,a) for (auto&& i : a)
#define all(x) (x).begin(),(x).end()
#define sz(x) ((int)(x).size())
#define pb(a) push_back(a)
#define mp(a, b) make_pair(a, b)
#define mt(a, b, c) make_tuple(a, b, c)
#define ceil(a,b) ((a)+(b)-1)/(b)
#define is_in(x, a, b) ((a)<=(x) && (x)<(b))
#define uni(x) sort(all(x));x.erase(unique(all(x)),x.end())
#define ub upper_bound
#define lb lower_bound
#define posl(A, x) (lower_bound(all(A), x)-A.begin())
#define posu(A, x) (upper_bound(all(A),x)-A.begin())
template<class T> inline void chmax(T &a, const T &b) { if((a) < (b)) (a) = (b); }
template<class T> inline void chmin(T &a, const T &b) { if((a) > (b)) (a) = (b); }

typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef long double ld;
typedef pair<int,int> pii;
typedef tuple<int,int,int> iii;

template<typename T> using PQ = priority_queue<T, vector<T>, greater<T>>;
struct Fast { Fast(){ std::cin.tie(0); ios::sync_with_stdio(false); } } fast;

#if defined(PCM) || defined(LOCAL)
  #include "lib/dump.hpp"
#else
  #define dump(...) 42
  #define dump_1d(...) 42
  #define dump_2d(...) 42
#endif
//}}}

int solve(){
  int n;cin>>n;
  vector<int> a(n);
  int s = 0;
  rep(i, n) {
    cin>>a[i];
    s += a[i];
  }
  vi b = vi(a);
  rep(i, 1, n){
    b[i] += b[i-1];
  }
  dump(a);
  dump(b);
  dump(s/2);

  int ans = INF;
  rep(i, n-1){
    int x = b[i];
    int y = s-b[i];
    dump(x,y);
    chmin(ans, abs(x-y));
  }
  cout << ans << endl;

  return 0;
}

signed main() { //{{{
#ifdef INPUT_FROM_FILE
  std::ifstream in(infile);
  std::cin.rdbuf(in.rdbuf());
#endif
  solve();
  return 0;
} //}}}


Measured memory_bytes: 3456
#include <bits/stdc++.h>
#define tt this->
#define ll long long
using namespace std;
int main ()
{
int ar[5];
for (int i=0 ; i<5;i++)
{
    cin>>ar[i];
}

for (int i=0 ; i<5 ; i++)
{
    if(ar[i]==0) {
        cout<<i+1<<endl;
    break;
    }
}

    return 0;
}

/*
▀█████████▄     ▄████████    ▄████████    ▄████████
  ███    ███   ███    ███   ███    ███   ███    ███
  ███    ███   ███    ███   ███    ███   ███    ███
 ▄███▄▄▄██▀    ███    ███  ▄███▄▄▄▄██▀   ███    ███
▀▀███▀▀▀██▄  ▀███████████ ▀▀███▀▀▀▀▀   ▀███████████
  ███    ██▄   ███    ███ ▀███████████   ███    ███
  ███    ███   ███    ███   ███    ███   ███    ███
▄█████████▀    ███    █▀    ███    ███   ███    █▀
                            ███    ███

*/


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

int main()
{
	ll int n,k;
	cin>>n>>k;
	if (n>=k)
	{
		if(n%k==0)
		{
			cout<<0<<endl;
		}
		else
		{
			cout<<(n/k+1)*k-n<<endl;
		}
	
	}
	else
	{
		cout<<min(n,k-n)<<endl;
		
	}
}





Measured memory_bytes: 256
#include <iostream>
#include <vector>
using namespace std;
int main(){
    int N;
    cin >> N;
    vector<int> a(N);
    for(int i = 0; i < N; i++) {
        cin >> a[i];
    }
    int cnt = 0;
    for(int i = 0; i < N; i++){
        if(a[i] == cnt + 1){
            cnt++;
        }
    }
    if(cnt == 0){
        cout << -1 << endl;
        return 0;
    }
    cout << N - cnt << endl;
}

Measured memory_bytes: 4052
#include <bits/stdc++.h>
#include <cassert>
typedef long long int ll;
using namespace std;

// @@ !! LIM()

int main(int argc, char *argv[]) {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
  cout << setprecision(20);

  ll N; cin >> N;
  vector<ll> A(N);
  for (ll i = 0; i < N; i++) cin >> A.at(i);
  sort(A.begin(), A.end());
  if (N % 2 == 1) {
    ll m = N / 2;
    ll ml = m - 1;
    ll mr = m + 1;
    ll ans = 0;
    for (ll i = 0; i < N; i++) {
      if (i < ml) ans -= 2 * A.at(i);
      else if (i > mr) ans += 2 * A.at(i);
    }
    ll case1 = -2 * A.at(ml) + A.at(m) + A.at(mr);
    ll case2 = - A.at(ml) - A.at(m) + 2 * A.at(mr);
    ll add = max(case1, case2);
    cout << ans + add << endl;
  }else {
    ll ans = 0;
    for (ll i = 0; i < N; i++) {
      if (i < N/2 - 1) ans -= 2 * A.at(i);
      else if (i == N/2 - 1) ans -= A.at(i);
      else if (i == N/2) ans += A.at(i);
      else ans += 2 * A.at(i);
    }
    cout << ans << endl;
  }

  return 0;
}



Measured memory_bytes: 3988
A_one = [int(i) for i in input().split()]
A_two = [int(i) for i in input().split()]
A_three = [int(i) for i in input().split()]

X = [0, 0, 0]
Y = [0, 0, 0]
Z = [0, 0, 0]
res = False
N = int(input())
for i in range(N):
    j = int(input())
    try:
        a = A_one.index(j)
    except:
        pass
    else:
        X[a] = 1
    
    try:
        a = A_two.index(j)
    except:
        pass
    else:
        Y[a] = 1

    try:
        a = A_three.index(j)
    except:
        pass
    else:
        Z[a] = 1

if sum(X) == 3: 
    res = True

if sum(Y) == 3: 
    res = True

if sum(Z) == 3: 
    res = True

if X[0] + Y[1] + Z[2] == 3:
    res = True

if X[2] + Y[1] + Z[0] == 3:
    res = True

if X[0] + Y[0] + Z[0] == 3:
    res = True

if X[1] + Y[1] + Z[1] == 3:
    res = True

if X[2] + Y[2] + Z[2] == 3:
    res = True

if res:
    print('Yes')
else:
    print('No')

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

using namespace std;

typedef long long ll;

int main(){
    string s,t;
    cin >> s >> t;
    int ans = 0;
    for (int i = 0;i < (int)s.length();i++){
        if (s[i] != t[i]) ans++;
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 3920
#include<cstdio>
#include<iostream>
using namespace std;
int l[1010],r[1100];
int a[1010];
int n,ans;
int main()
{
	scanf("%d",&n);
	for (int i=1;i<=n;++i)
		scanf("%d",&a[i]),l[i]=l[i-1]+a[i];
	for (int i=1;i<=n;++i)
		scanf("%d",&a[i]);
	for (int i=n;i>=1;--i)
		r[i]=r[i+1]+a[i];
	for (int i=1;i<=n;++i)
		ans=max(ans,l[i]+r[i]);
	printf("%d\n",ans);
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
#include <cmath>
#include <cstdlib>
#include <vector>
#include <map>
#include <queue> 
#include <stack>
#include <set>
#include <list>

using namespace std;
typedef long long ll;
#define rep(i, s, e) for (int(i) = (s); (i) <= (e); ++(i))
#define all(x) x.begin(),x.end()


int main()
{
	int n; cin >> n;
	vector<int> h(n);
	int ans = 0;
	rep(i, 0, n - 1)cin >> h[i];
	rep(i, 0, n - 2)
	{
		int tmp = 0;
		while (i < n - 1 && h[i] >= h[i + 1])
		{
			++tmp;
			++i;
		}
		ans = max(ans, tmp);
	}
	cout << ans << endl;
}


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

using namespace std;

int main()
{
    int i,n,arr[200005],mx=0,cnt=0;
    cin>>n;
    for(i=0;i<n;i++)cin>>arr[i];
    for(i=0;i<n-1;i++){
        if(arr[i]<arr[i+1]){
            mx = max(mx,cnt);
            cnt = 0;
        }
        else cnt++;
    }
    mx = max(mx,cnt);
    cout<<mx<<'\n';
    return 0;
}


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

#include "bits/stdc++.h"

using namespace std;
#define int long long
#define FOR(i, a, b) for(int i=(int)(a);i<(int)(b);++i)
#define REP(i, n)  FOR(i,0,(n))
#define ITR(itr, mp) for(auto itr = (mp).begin(); itr != (mp).end(); ++itr)


class BMaximumSum {
public:
    void solve(std::istream &in, std::ostream &out) {
      multiset<int, greater<int>> m;
      int a, b, c, k;
      in >> a >> b >> c >> k;
      m.insert(a);
      m.insert(b);
      m.insert(c);
      REP(i, k) {
        int t = *m.begin();
        m.erase(m.begin());
        t *= 2;
        m.insert(t);
      }
      int ans = 0;
      ITR(itr, m) {
        ans += *itr;
      }
      out << ans << endl;
    }
};


signed main() {
  ios::sync_with_stdio(false);
  cout.tie(0);
  cout << fixed;
  BMaximumSum solver;
  std::istream &in(std::cin);
  std::ostream &out(std::cout);
  solver.solve(in, out);
  return 0;
}


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

#define rep(i,n) for(int i = 0; i < n; i++)
#define REP(i,n) for(int i = 1; i < n; i++)
#define repll(i,n) for(ll i = 0; i < n; i++)
#define REPll(i,n) for(ll i = 1; i < n; i++)
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()
#define yesorno(a) printf(a ? "yes\n" : "no\n")
#define YesorNo(a) printf(a ? "Yes\n" : "No\n")
#define YESorNO(a) printf(a ? "YES\n" : "NO\n") 
#define endl "\n"
using ll = long long;
using P = pair<int,int>;
using Pl = pair<ll,ll>;
using vi = vector<int>;
using vii = vector<vi>;
using vl = vector<ll>;
using vll = vector<vl>;
const int dx[] = {0,1,0,-1,1,1,-1,-1};
const int dy[] = {1,0,-1,0,1,-1,-1,1};
const int inf = (1<<30)-1;
const ll infll = (1LL<<62)-1;
ll ceil(const ll a, const ll b){return ((a)+(b)-1)/b;}


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

  int n;
  cin >> n;
  deque<int> b;
  rep(i,n){
    int a;
    cin >> a;
    if(i % 2 == 0) b.push_back(a);
    else b.push_front(a);
  }
  if(n % 2 == 1) reverse(all(b));

  rep(i,n){
    cout << b.front() << " ";
    b.pop_front();
  }
  cout << endl;
}

Measured memory_bytes: 3072
while True:
    a = list(map(int, input().split()))
    if a[0] == a[1] == 0:
        break
    sharp1 = '#' * a[1]
    sharp2 = '#' + '.' * (a[1] -2) + '#'
    print(sharp1)
    for i in range(a[0] -2):
        print(sharp2)
    print(sharp1)
    print()

Measured memory_bytes: 5616
#include <bits/stdc++.h>
using namespace std;
#define FOR(i, j, k) for(int i=j; i<=k; i++)
#define FFOR(i, j, k) for(int i=j; i<k; i++)
#define DFOR(i, j, k) for(int i=j; i>=k; i--)
#define bug(x) cerr<<#x<<" = "<<x<<'\n'
#define pb push_back
#define mp make_pair
typedef long long ll;
typedef long double ld;
template <typename T> inline void read(T &x){
    char c;
    bool nega=0;
    while((!isdigit(c=getchar()))&&(c!='-'));
    if(c=='-'){
        nega=1;
        c=getchar();
    }
    x=c-48;
    while(isdigit(c=getchar())) x=x*10+c-48;
    if(nega) x=-x;
}
template <typename T> inline void writep(T x){
    if(x>9) writep(x/10);
    putchar(x%10+48);
}
template <typename T> inline void write(T x){
    if(x<0){
        putchar('-');
        x=-x;
    }
    writep(x);
}
template <typename T> inline void writeln(T x){
    write(x);
    putchar('\n');
}
#define taskname "D"
int c[10][10];
int n, m, x;
ll ans=0;
int main(){
    #ifdef Megumin
        if(fopen(taskname".inp", "r"))
            freopen(taskname".inp", "r", stdin);
    #endif // Megumin
    cin>>n>>m;
    FFOR(i, 0, 10) FFOR(j, 0, 10) cin>>c[i][j];
    FFOR(k, 0, 10) FFOR(i, 0, 10) FFOR(j, 0, 10) c[i][j]=min(c[i][j], c[i][k]+c[k][j]);
    FOR(i, 1, n) FOR(j, 1, m){
        cin>>x;
        if(x>=0) ans+=c[x][1];
    }
    writeln(ans);
}

Measured memory_bytes: 256
#define _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <limits.h>

int main(void) {
	int H, W, i, j;
	while (1){
		scanf("%d %d", &H, &W);
		if (H == 0 && W == 0) break;
		for (i = 0; i < H; ++i){
			for (j = 0; j < W; ++j){
				if (i==0 || i==H-1 || j == 0 || j == W - 1) printf("#");
				else printf(".");
			}
			printf("\n");
		}
		printf("\n");
	}
	return 0;
}

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

int N, K, S;

class cube{
    public:
    int x, y, z;
    int cp(int a, int b){
        if(abs(a-b)>=S)return 0;
        return S - abs(a-b);
    }
    int compare(cube c){
        int xx = cp(x, c.x);
        int yy = cp(y, c.y);
        int zz = cp(z, c.z);
        if(xx==0 || yy==0 || zz==0)return 0;
        return xx * yy * 2 + xx * zz * 2 + yy * zz * 2;
    }
};

int main(){

    for(;cin>>N>>K>>S, N;){
        vector<cube>cubes(N);
        for(int i=0;i<N;i++){
            cin>>cubes[i].x;
            cin>>cubes[i].y;
            cin>>cubes[i].z;
        }
        if(K==1){
            cout<<S*S*6<<endl;
            continue;
        }
        int ans = 100*100*6*2000;
        vector<int>link[N];
        for(int i=0;i<N;i++){
            for(int j=i+1;j<N;j++){
                if(cubes[i].compare(cubes[j])){
                    link[i].push_back(j);
                    link[j].push_back(i);
                }
            }
        }
        for(int i=0;i<N;i++){
            for(int j=0;j<link[i].size();j++){
                int k=1;
                int score = S*S*6;
                int lst = -1;
                int now = i;
                int nxt = link[i][j];
                for(;;){
                    if(k==K){
                        int f = 0;
                        for(int l=0;l<link[now].size();l++){
                            if(link[now][l]==i)f=1;
                        }
                        if(lst==i)f=0;
                        if(f)score -= cubes[i].compare(cubes[now]);
                        ans = min(ans, score);
                        break;
                    }
                    if(nxt==-1)break;
                    int tmp = -1;
                    for(int l=0;l<link[nxt].size();l++){
                        if(link[nxt][l]==i || link[nxt][l]==now)continue;
                        tmp = link[nxt][l];
                    }
                    score += S*S*6 - cubes[now].compare(cubes[nxt]);
                    int f = 0;
                    lst = now;
                    now = nxt;
                    nxt = tmp;
                    k++;
                }
            }
        }
        if(ans==100*100*6*2000)cout<<-1<<endl;
        else cout<<ans<<endl;
    }

    return 0;
}


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

const int MOD = 1000000007;

int solve(int n)
{
    int num = n;
    vector<int> x(n + 1);

    for (int i = 2; i <= n; i++)
    {
        while (num % i == 0)
        {
            x.at(i)++;
            num /= i;
        }     
    }
    int ans = 1;
    for (int i = 2; i <= n; i++)
    {
        ans *= x.at(i) + 1;
    }
    return ans;
}

int main()
{
    int n,ans=0;
    cin >> n;
    for (int i = 1; i <= n;i+=2)
    {
        if(solve(i) == 8)
            ans++;
    }
    cout << ans;
}

Measured memory_bytes: 256
#include<stdio.h>
#include<string.h>
int main(){
	char s[1001],t[1001];
	scanf("%s",s);
	scanf("%s",t);
	int l,ans=0,m,i,j,n;
	n=strlen(s);
	l=strlen(t);
	for(i=0;i<=n-l;i++)
	{
		j=0;
		m=0;
		while(t[j]!='\0')
		{
			if(s[i+j]==t[j])
			m++;
			j++;
		}
		if(m>ans)
		ans=m;
	}
	printf("%d\n",l-ans);
	return 0;
}

Measured memory_bytes: 1708
import java.util.Scanner;

public class Main{

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

		int A = sc.nextInt();
		int B = sc.nextInt();
		int C = sc.nextInt();

		if(A == 5&&A == B){
			if(C == 7){
				System.out.println("YES");
			}
		}else if(A == 5 && A == C){
			if(B == 7){
				System.out.println("YES");
			}
		}else if(B == 5&&B == C){
			if(A == 7){
				System.out.println("YES");
			}
		}else{
			System.out.println("NO");
		}
	}
}

Measured memory_bytes: 9428
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>

#include <iostream>
#include <string>

#include <algorithm>
#include <deque>
#include <map>
#include <queue>
#include <set>
#include <vector>

#define PB push_back
#define MP make_pair

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

#define ALL(v) (v).begin(),(v).end()

using namespace std;

typedef long long LL;
typedef unsigned long long ULL;

typedef pair<int, int> PII;

typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef vector<PII> VPII;

const int MOD = 1000000007;
const int INF = 1e9;

const double EPS = 1e-9;
const double PI = acos(-1.0);

LL gcd(LL a, LL b) { return b ? gcd(b, a % b) : a; }
LL lcm(LL a, LL b) { return a / gcd(a, b) * b; }

LL N, A[100002], B[100001];

int main() {
    cin >> N;
    REP (i, N + 1) {
        cin >> A[i];
    }
    REP (i, N) {
        cin >> B[i];
    }
    LL S = 0;
    REP (i, N) {
        REP (j, 2) {
            if (A[N - (i + j)] < B[N - (i + 1)]) {
                B[N - (i + 1)] -= A[N - (i + j)];
                S += A[N - (i + j)];
                A[N - (i + j)] = 0;
            }
            else {
                A[N - (i + j)] -= B[N - (i + 1)];
                S += B[N - (i + 1)];
                B[N - (i + 1)] = 0;
            }
        }
    }
    cout << S << endl;
    return 0;
}


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

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

    vector<int> num(N);
    for (int i = 0; i < N; ++i) {
        cin >> num[i];
    }

    vector<int>::iterator result = unique(num.begin(), num.end());
    num.erase(result, num.end());

    for (int i = 0; i < num.size(); ++i) {
        cout << num.at(i);
        if (i < num.size() - 1) {
            cout << " ";
        }
    }
    cout << endl;

    return 0;
}


Measured memory_bytes: 3096
#include <bits/stdc++.h>
#include<iostream>
typedef long long ll;
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REP(i,a) FOR(i,0,a)
	
using namespace std;
const int MAX_N=50;
int N,a[MAX_N];
int main(){
	cin>>N;
	int ma=0;
	REP(i,N){
		cin>>a[i];
		if (abs(a[i])>abs(a[ma])){
			ma=i;
		}
	}
	int f;
	if (a[ma]>=0){
		f=1;
	}else{
		f=-1;
	}
	cout<<2*(N-1)<<endl;
	REP(i,N){
		if (i!=ma){
			cout<<ma+1<<" "<<i+1<<endl;
		}
	}
	REP(i,N-1){
		if (f==1){
			cout<<i+1<<" "<<i+2<<endl;
		}else{
			cout<<N-i<<" "<<N-i-1<<endl;
		}
	}
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <set>
#include <queue>
#include <stack>
#include <map>
#include <algorithm>
#include <math.h>
#include <cassert>
#define rep(i,n) for(int i = 0; i < n; ++i )
using namespace std;
using ll = long long;
using P = pair<int,int>;

int main() {
  int x,y;
  cin >> x >> y;
  rep(i,x+1){
    int c = i*2 + (x-i)*4;
    if(c==y){
      cout << "Yes" << endl;
      return 0;
    }
  }
  cout << "No" << endl;
}


Measured memory_bytes: 3588
#include<bits/stdc++.h>
using namespace std;
int main(){
  while(1){
    long long n;
    long long p[65009],q[65009];
    long long sum=0,ans=0;
    cin>>n;
    if(n==0)break;
    for(long long i=0;i<n;i++){
      cin>>p[i];
      sum+=p[i];
    }
    for(long long i=0;i<n-1;i++)cin>>q[i];
    sort(q,q+n-1);
    reverse(q,q+n-1);
    for(long long i=-1;i<n-1;i++){
      if(i==-1){
	ans=max(ans,sum*n);
	//cout<<ans<<endl;
      }
      else{
	sum+=q[i];
	ans=max(ans,sum*(n-i-1));
	//cout<<sum*(n-i-1)<<endl;
      }
    }
    cout<<ans<<endl;
  }
  return(0);
}



Measured memory_bytes: 4052
#include "bits/stdc++.h"

using namespace std;

using ll = long long;
using ld = long double;
using P = pair<int, int>;
constexpr ld EPS = 1e-12;
constexpr int INF = numeric_limits<int>::max() / 2;
constexpr int MOD = 1e9 + 7;

template <typename T>
void printv(const vector<T> &v)
{
    int sz = v.size();
    for (int i = 0; i < sz; i++)
    {
        cout << v[i] << " \n"[i == sz - 1];
    }
}

class LowLink
{
    using Graph = std::vector<std::vector<int>>;
    using P = std::pair<int, int>;
    Graph G;
    std::vector<int> order;
    int next = 0;
    std::set<P> bridges;

    void add(int a, int b)
    {
        bridges.insert(P(std::min(a, b), std::max(a, b)));
    }
    int dfs(int cur, int pre)
    {
        int res = order[cur] = next++;
        for (const auto &to : G[cur])
        {
            if (to == pre)
                continue;
            if (order[to] >= 0)
                res = std::min(res, order[to]);
            else
            {
                int low = dfs(to, cur);
                if (low > order[cur])
                    add(cur, to);
                res = std::min(res, low);
            }
        }
        return res;
    }

  public:
    LowLink(int _v) : G(_v, std::vector<int>()), order(_v, -1) {}
    void addEdge(int s, int t)
    {
        G[s].push_back(t);
    }
    std::set<P> bridge()
    {
        // 連結であることを想定
        dfs(0, -1);
        // 非連結の場合
        // for(int i = 0;i < (int)order.size(); i++) if(order[i] == -1) dfs(i, -1);
        return bridges;
    }
};

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

    int n, m;
    cin >> n >> m;
    LowLink g2(n);
    vector<vector<int>> g(n);
    vector<int> deg(n, 0);
    for (int i = 0; i < m; i++)
    {
        int a, b;
        cin >> a >> b;
        a--;
        b--;
        g2.addEdge(a, b);
        g2.addEdge(b, a);
        deg[a]++;
        deg[b]++;
        g[a].push_back(b);
        g[b].push_back(a);
    }
    auto bridge = g2.bridge();
    bool even = true;
    for (int i = 0; i < n; i++)
        if (deg[i] % 2)
            even = false;
    int one = 0, two = 0;
    vector<int> used(n, 0);
    for (int i = 0; i < n; i++)
    {
        if (deg[i] > 2 || used[i])
            continue;
        queue<int> que;
        que.push(i);
        used[i] = 1;
        set<int> st;
        while (!que.empty())
        {
            int cur = que.front();
            que.pop();
            for (auto v : g[cur])
            {
                if (used[v])
                    continue;
                if (deg[v] > 2)
                {
                    st.insert(v);
                    continue;
                }
                que.push(v);
                used[v] = 1;
            }
        }
        if (st.size() == 1)
            one++;
        else
            two++;
    }
    if (m - n < 2 || bridge.size() != 0 || !even)
    {
        cout << "No" << endl;
    }
    else if (one + two / 2 < 3)
    {
        cout << "No" << endl;
    }
    else
    {
        cout << "Yes" << endl;
    }
}


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

const int N = 200010;

char s[N];
int pre[N], pre1[N];

int main(){
    int n;
    scanf("%d%s", &n, s + 1);
    for (int i = 1; i <= n; ++ i){
        pre[i] = pre[i - 1] + (s[i] == 'R');
        pre1[i] = pre1[i - 1] + (s[i] == 'W');
    }
    int ans = INT_MAX;
    for (int i = 0; i <= n; ++ i){
        int x1 = pre1[i];
        int x2 = pre[n] - pre[i];
        ans = std::min(ans, x1 + x2 - std::min(x1, x2));
    }
    printf("%d\n", ans);
    return 0;
}

Measured memory_bytes: 5532
#include<cstdio>
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>

using namespace std;

int main()
{
	int n;
	cin >> n;
	
	if (n == 1)cout << 1 << endl;
	else if (n <= 3)cout << 2 << endl;
	else if (n <= 7)cout << 4 << endl;
	else if (n <= 15)cout << 8 << endl;
	else if (n <= 31)cout << 16 << endl;
	else if (n <= 63)cout << 32 << endl;
	else if (n <= 100)cout << 64 << endl;

	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <cmath>
#define lli long long int
#define fio ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)
using namespace std;
lli dp[101][100001],n,w;
lli result (lli *arr,lli *brr,lli i,lli sum)
{
    if (sum>w)
    {
        return -brr[i-1];
    }
    if (i>=n)
    {
        return 0;
    }
    if (dp[i][sum]!=-1)
    {
        return dp[i][sum];
    }
    if (dp[i][sum]==-1)
    {
        lli t,u;
        t=result(arr,brr,i+1,sum+arr[i])+brr[i];
        u=result(arr,brr,i+1,sum);
        dp[i][sum]=max(t,u);
        return dp[i][sum];
    }
}
int main()                                  
{
    cin>>n>>w;
    lli arr[n],brr[n];
    for (int i=0;i<n;i++)
    cin>>arr[i]>>brr[i];
    for (int i=0;i<101;i++)
    {
        for (int j=0;j<100001;j++)
        dp[i][j]=-1;
    }
    cout<<result(arr,brr,0,0); 
	return 0;
}

Measured memory_bytes: 79104
d={"1": ('.', ',', '!', '?', ' '), "2": ('a', 'b', 'c'), "3": ('d', 'e', 'f'), \
"4": ('g', 'h', 'i'), "5": ('j', 'k', 'l'), "6": ('m', 'n', 'o'), "7": ('p', 'q\
', 'r', 's'), "8": ('t', 'u', 'v'), "9": ('w', 'x', 'y', 'z')}
n=input()
for j in range(n):
    s=raw_input().split('0')
    print "".join([d[i[0]][(len(i)-1)%len(d[i[0]])] for i in s if i!=""])

Measured memory_bytes: 4264
/* template.cpp {{{ */
#include <bits/stdc++.h>
using namespace std;
#define get_macro(a, b, c, d, name, ...) name
#define rep(...) get_macro(__VA_ARGS__, rep4, rep3, rep2, rep1)(__VA_ARGS__)
#define rrep(...) get_macro(__VA_ARGS__, rrep4, rrep3, rrep2, rrep1)(__VA_ARGS__)
#define rep1(n) rep2(i_, n)
#define rep2(i, n) rep3(i, 0, n)
#define rep3(i, a, b) rep4(i, a, b, 1)
#define rep4(i, a, b, s) for (ll i = (a); i < (ll)(b); i += (ll)(s))
#define rrep1(n) rrep2(i_, n)
#define rrep2(i, n) rrep3(i, 0, n)
#define rrep3(i, a, b) rrep4(i, a, b, 1)
#define rrep4(i, a, b, s) for (ll i = (ll)(b) - 1; i >= (ll)(a); i -= (ll)(s))
#define each(x, c) for (auto &&x : c)
#define fs first
#define sc second
#define all(c) begin(c), end(c)
using ui = unsigned;
using ll = long long;
using ul = unsigned long long;
using ld = long double;
const int inf = 1e9 + 10;
const ll inf_ll = (ll)1e18 + 10;
const ll mod = 1e9 + 7;
const ll mod9 = 1e9 + 9;
const int dx[]{-1, 0, 1, 0, -1, 1, 1, -1};
const int dy[]{0, -1, 0, 1, -1, -1, 1, 1};
template<class T, class U> void chmin(T &x, const U &y){ x = min<T>(x, y); }
template<class T, class U> void chmax(T &x, const U &y){ x = max<T>(x, y); }
struct prepare_ { prepare_(){ cin.tie(nullptr); ios::sync_with_stdio(false); cout << fixed << setprecision(12); } } prepare__;
/* }}} */

int n;
int a[26];

int main(){
  while (cin >> n, n){
    memset(a, 0, sizeof(a));
    string res = "TIE";
    rep(i, n){
      char c;
      cin >> c;
      a[c - 'A']++;
      rep(j, 26){
        int mx = -inf;
        rep(k, 26){
          if (j != k) chmax(mx, a[k]);
        }
        if (res == "TIE" && a[j] > mx + n - i - 1){
          stringstream ss;
          ss << (char)('A' + j) << " " << i + 1;
          res = ss.str();
        }
      }
    }
    cout << res << endl;
  }
}

Measured memory_bytes: 3176
#include <algorithm>
#include <iostream>
#include <vector>

using namespace std;

typedef long long ll;

template<class T>
inline bool chmax(T &a, T b) {
    if(a < b) {
        a = b;
        return true;
    }
    return false;
}

template<class T>
inline bool chmin(T &a, T b) {
    if(a > b) {
        a = b;
        return true;
    }
    return false;
}

/*
 * ref. [Union-Find](https://www.slideshare.net/chokudai/union-find-49066733)
 * ref. [AtCoder ABC 157 - AtCoder Live](https://www.youtube.com/watch?v=TdR816rqc3s)
 */
class UnionFind {
    public:
        UnionFind(int n = 0): d(n, -1) {}

        // 0-index, [0, n) in other words
        // Time complexity: O(a(n)) (a = inverse Achkermann function)
        int find(int x) {
            if (d[x] < 0) return x;
            return d[x] = find(d[x]);
        }

        // Return false if x and y are alreday in the same group, otherwise return true.
        // 0-index, [0, n) in other words
        // Time complexity: O(a(n)) (a = inverse Achkermann function)
        bool unite(int x, int y) {
            x = find(x);
            y = find(y);
            if (x == y) return false;
            if (d[x] > d[y]) swap(x, y);
            d[x] += d[y];
            d[y] = x;
            return true;
        }

        // 0-index, [0, n) in other words
        // Time complexity: O(a(n)) (a = inverse Achkermann function)
        bool same(int x, int y) {
            return find(x) == find(y);
        }

        // 0-index, [0, n) in other words
        // Time complexity: O(1)
        int size(int x) {
            return -d[find(x)];
        }

    private:
        vector<int> d;
};

struct Edge {
    pair<int, int> e;
    bool is_available;
};

vector<struct Edge> edges;

bool check(const int N) {
    UnionFind uf(N);
    for (auto &edge : edges) {
        if (!edge.is_available) {
            continue;
        }
        uf.unite(edge.e.first, edge.e.second);
    }
    return uf.size(0) != N;
}

int main(void) {
    int N, M;
    cin >> N >> M;

    edges.resize(M);
    for (int i = 0; i < M; i++) {
        int a, b;
        cin >> a >> b;
        a--;
        b--;
        edges[i].e = {a, b};
        edges[i].is_available = true;
    }

    int res = 0;
    for (int i = 0; i < M; i++) {
        struct Edge &edge = edges[i];
        edge.is_available = false;
        if (check(N)) {
            res++;
        }
        edge.is_available = true;
    }

    cout << res << endl;

    return 0;
}


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

class Main{
    public static void main(String[] args){
        FastScanner fsc=new FastScanner();
        int x=fsc.nextInt(), y=fsc.nextInt();
        fsc.close();
        int ans=0;
        if(x==1) ans+=300000;
        if(x==2) ans+=200000;
        if(x==3) ans+=100000;
        if(y==1) ans+=300000;
        if(y==2) ans+=200000;
        if(y==3) ans+=100000;
        if(x==1 && y==1) ans+=400000;
        System.out.println(ans);
    }
    static class FastScanner {
        private final InputStream in = System.in;
        private final byte[] buffer = new byte[1024];
        private int ptr = 0;
        private int buflen = 0;
        private boolean hasNextByte(){
            if(ptr<buflen) return true;
            else{
                ptr = 0;
                try{
                    buflen = in.read(buffer);
                }
                catch(IOException e){
                    e.printStackTrace();
                }
                if(buflen<=0) return false;
            }
        return true;
        }
        private int readByte() { if (hasNextByte()) return buffer[ptr++]; else return -1;}
        private static boolean isPrintableChar(int c) { return 33 <= c && c <= 126;}
        public boolean hasNext() { while(hasNextByte() && !isPrintableChar(buffer[ptr])) ptr++; return hasNextByte();}
        public String next() {
            if (!hasNext()) throw new NoSuchElementException();
            StringBuilder sb = new StringBuilder();
            int b = readByte();
            while(isPrintableChar(b)) {
                sb.appendCodePoint(b);
                b = readByte();
            }
            return sb.toString();
        }
        public long nextLong() {
            if (!hasNext()) throw new NoSuchElementException();
            long n = 0;
            boolean minus = false;
            int b = readByte();
            if (b == '-') {
                minus = true;
                b = readByte();
            }
            if (b < '0' || '9' < b) throw new NumberFormatException();
            while(true){
                if ('0' <= b && b <= '9') {
                    n *= 10;
                    n += b - '0';
                }
                else if(b == -1 || !isPrintableChar(b)) return minus ? -n : n;
                else throw new NumberFormatException();
                b = readByte();
            }
        }
        public int nextInt() {
            long nl = nextLong();
            if (nl < Integer.MIN_VALUE || nl > Integer.MAX_VALUE) throw new NumberFormatException();
            return (int) nl;
        }
        public double nextDouble() { return Double.parseDouble(next());}
        public void close(){
            try{in.close();}
            catch(IOException e){e.printStackTrace();}
        }
    }
}

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

string N;
int main(){
    cin >> N;
    int ans = 0;
    for(auto i : N){
        ans += (int)i - 48;
    }

    //cout << ans << endl;
    if(ans%9==0 || ans==0){
        cout << "Yes" << endl;
    }
    else{
        cout << "No" << endl;
    }
    return 0;
}

Measured memory_bytes: 3768
#include<bits/stdc++.h>
typedef long long int lli;
#define INF 1000000000000000000
using namespace std;

int n,w;
int weight[105],value[105];
int sum_value;



int main(){
	cin>>n>>w;
	sum_value = 0;
	for(int i = 1;i<=n;i++){
		cin>>weight[i]>>value[i];
		sum_value += value[i];
	}

	vector<lli> dp(sum_value+1,INF);
	dp[0] = 0;

	for(int i=1;i<=n;i++){
		for(int j = sum_value-value[i];j>=0;j--){
			dp[j + value[i]] = min(dp[j + value[i]],dp[j] + weight[i]);
		}
	}

	lli ans = -1;
	for(int i = 0;i<=sum_value;i++){
		if(dp[i] <= w){
			ans = max(ans,(lli)i);
		}
	}

	cout<<ans<<endl;

}

Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
int N,ans;
string X;

int main(void){
    cin>>N>>X;
    bitset<2*100000>b(X);
    int p=b.count();
    


    int mod[2][N+10],t=1;
    for(int i=0;i<N+10;i++){
        mod[0][i]=t;
        t<<=1;
        t%=p+1;
    }
    t=1;
    if(p!=1){
        for(int i=0;i<N+10;i++){
            mod[1][i]=t;
            t<<=1;
            t%=p-1;
        }
    }
    

    reverse(X.begin(),X.end());

    int mp=0,mm=0;
    for(int i=0;i<N;i++){
        //cout<<X[i]<<endl;
        if(X[i]=='1')mp+=mod[0][i];
        mp%=p+1;
    }
    if(p!=1){
        for(int i=0;i<N;i++){
            //cout<<X[i]<<endl;
            if(X[i]=='1')mm+=mod[1][i];
            mm%=p-1;
        }
    }

    for(int i=N-1;i>=0;i--){
        int tmp;
        if(X[i]=='0'){
            tmp=mp;
            tmp+=mod[0][i];
            tmp%=p+1;
        }
        else{
            if(p==1){cout<<0<<endl;continue;}
            tmp=mm;
            tmp-=mod[1][i];
            while(tmp<0)tmp+=(p-1);
            tmp%=p-1;
        }
        int ret;
        for(ret=1;tmp!=0;ret++){
            tmp=tmp%(__builtin_popcount(tmp));
        }
        cout<<ret<<endl;
    }
    return 0;
}

Measured memory_bytes: 5316
#include<iostream>
#include<cstdio>
#include<algorithm>
using namespace std;
int n;
int a[100001],b[100001];
long long suma,sumb;
long long sum[100001];
int c[200001],cnt;
int main()
{
	scanf("%d",&n);
	for(int i=1;i<=n;i++)
	{
		scanf("%d%d",&a[i],&b[i]);
		c[++cnt]=a[i],c[++cnt]=b[i];
		suma+=a[i],sumb+=b[i];
	}
	sort(c+1,c+cnt+1);
	for(int i=1;i<=n;i++)
		sum[i]=sum[i-1]+c[i];
	long long ans=min(suma,sumb);
	for(int i=1;i<=n;i++)
	{
		long long x=a[i],y=b[i];
		if(x>y) swap(x,y);
		if(lower_bound(c+1,c+cnt+1,x)-c<=n-2)
  		{
   			if(lower_bound(c+1,c+cnt+1,y)-c<=n-1) ans=min(ans,sum[n]);
   			else ans=min(ans,y+sum[n-1]);
  		}
  		else ans=min(ans,x+y+sum[n-2]);
	}
	printf("%lld",ans);
	return 0;
}

Measured memory_bytes: 2560
n = int(input())
x = [int(i) for i in input().split()]

A = x.copy()
A.sort()
a1 = A[int(len(x)/2)]
a2 = A[int(len(x)/2)-1]
for i in range(n):
    if x[i] < a1:
        print(a1)
    else:
        print(a2)

Measured memory_bytes: 26356
n,x=map(int,input().split())
m=list(map(lambda y:int(y)-x,input().split()))
if 0 in m:
  m.remove(0)
ans=abs(m[0])
for i in m:
  i=abs(i)
  while 1:
    ans%=i
    ans,i=i,ans
    if i==0:
      break
print(ans)

Measured memory_bytes: 14252
#include <bits/stdc++.h>
using namespace std;
typedef long long lint;
typedef pair<int, int> pi;

lint gcd(lint x, lint y){
	return y ? gcd(y, x%y) : x;
}

lint n, a[100005], p[100005], s[100005];

int main(){
	scanf("%lld",&n);
	for(int i=1; i<=n; i++) scanf("%lld",&a[i]);
	if(n == 1){
		puts("Second");
		return 0;
	}
	if(n == 2){
puts("First");
		return 0;
	}
	bool turn = 0;
	while(1){
		lint sum = 0;
		for(int i=1; i<=n; i++){
			sum += a[i];
		}
		sum = (sum - n) % 2;
		if(sum == 1){
			puts(turn ? "Second" : "First");
			return 0;
		}
		else{
			for(int i=1; i<=n; i++){
				p[i] = gcd(p[i-1], a[i]);
			}
			for(int i=n; i; i--){
				s[i] = gcd(s[i+1], a[i]);
			}
			lint that = -1;
			for(int i=1; i<=n; i++){
				if(a[i] > 1 && gcd(p[i-1], gcd(a[i] - 1, s[i+1])) != 1){
					a[i]--;
					that = gcd(p[i-1], gcd(a[i], s[i+1]));
					break;
				}
			}
			if(that == -1){
				puts(turn ? "First" : "Second");
				return 0;
			}
			turn ^= 1;
			for(int i=1; i<=n; i++){
				a[i] /= that;
			}
		}
	}
}


Measured memory_bytes: 2560