akhauriyash/Code-Regression huggingface dataset:
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cfloat>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <memory>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <sstream>
#include <complex>
#include <stack>
#include <queue>
#include <cstring>
#include <iomanip>

using namespace std;

int main(){
   int N;
   cin >> N;
   int A[N];
   for(int i =0;i<N;i++)cin>>A[i];
   long long dp[N+1][4];
   for(int i = 0 ; i <= N ; i ++){
      for(int j =0; j < 4; j++){
         dp[i][j]=LLONG_MAX/-2;
      }
   } 
   dp[1][0]=A[0];
   dp[1][1]=0;
   for(int i = 1 ; i < N; i++){
      for(int j = 0 ; j <= 1+(N%2) ; j++){
         // つぎに使うかどうか…(i+j)%2==0
         //cout << dp[i][j] <<" ";
         if((i+j)%2==0){
            // あえて使わない
            dp[i+1][j+1]=max(dp[i][j],dp[i+1][j+1]);
            // 普通につかう
            dp[i+1][j]=max(dp[i][j]+A[i],dp[i+1][j]);
         }
         else{
            // 使わない以外の選択肢がない
            dp[i+1][j]=max(dp[i+1][j],dp[i][j]);
         }
      }
      //cout << endl;
   }
   long long ans = LLONG_MAX/-2;
   for(int i = (N%2); i <= 1+(N%2); i++){
      ans = max(dp[N][i],ans);
   }
   cout << ans << endl;
   return 0;
}


Measured memory_bytes: 10620
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
//typedef pair<ll, ll> p_ll;
//typedef vector<pair<ll, ll>> vec_p;

/*const ll MOD = pow(10, 9) + 7;
const ll LLINF = pow(2, 61) - 1;
const int INF = pow(2, 30) - 1;*/


int main()
{
    ll N;

    cin >> N;

    cout << N * N * N << endl;
}


Measured memory_bytes: 3092
#include<iostream>
#include<iomanip>
#include<cmath>
#include<string>
#include<cstring>
#include<vector>
#include<list>
#include<algorithm>
#include<map>
#include<set>
#include<queue>
#include<stack>
using namespace std;
typedef long long ll;
#define fi first
#define se second
#define mp make_pair
#define mt make_tuple
#define pqueue priority_queue
const int inf=1e9+7;
const ll mod=1e9+7;
const ll mod1=998244353;
const ll big=1e18;
const double PI=2*asin(1);

int main() {
  int N;
  cin>>N;
  string S;
  cin>>S;
  string tmp1, tmp2;
  set<char> st1, st2;
  int ans = 0;
  int tmpans;
  for(int i=0;i<=N;++i) {
    tmp1.clear();
    tmp2.clear();
    for(int j=0;j<N;++j) {
      if(j<i) tmp1.push_back(S[j]);
      else tmp2.push_back(S[j]);
    }
    map<char, int> amap;
    tmpans = 0;
    for(int j=0;j<tmp1.size();++j) amap[tmp1[j]]++;
    for(int j=0;j<tmp2.size();++j) {
      if(amap[tmp2[j]]>0) {
        tmpans++;
        amap[tmp2[j]] = 0;
      }
    }
    ans = max(ans, tmpans);
  }
  cout<<ans<<endl;
}



Measured memory_bytes: 3596
N = int(input())
Q = [[int(x) for x in input().split()] for _ in range(N)]
for i in range(N):
  a,b = Q[i]
  if a==b:
    print((a-1)*2)
    continue
  c = int((a*b)**0.5)
  if a>c and b>c:
    if c*(c+1)<a*b:
      print(c*2)
    else:
      print(c*2-1)
  else:
    if c*(c+1)<a*b:
      print(c*2-1)
    else:
      if c**2==a*b:
      	print(c*2-3)
      else:
        print(c*2-2)
        
    

Measured memory_bytes: 3064
#include <bits/stdc++.h>
#define SORT(a) sort(a.begin(), a.end())
#define RSORT(a) sort(a.rbegin(), a.rend())
#define REP(i, n) for (int i = 0; i < n; i++)
#define RREP(i, n) for (int i = n; 0 <= i; i--)
#define FOR(i, start, end) for (int i = start; i < end; i++)
#define RFOR(i, start, end) for (int i = start; end <= i; i--)
#define ALL(a) a.begin(), a.end()
#define MOD(a) a %= 1'000'000'007
#define INF32 1'050'000'000
#define INF64 4'000'000'000'000'000'000
using ll = long long;
using namespace std;
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;
}

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

    ll a, b, c, k;
    cin >> a >> b >> c >> k;
    ll ans = b - a;
    if (k % 2 == 0)
        std::cout << -ans << '\n';
    else
        std::cout << b - a << '\n';

    return 0;
}

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

using namespace std;

int main()
{
    int A, B;
    cin >> A >> B;
    vector<int> a(A), b(B);
    for (int i = 0; i < A; i++) {
        cin >> a[i];
    }
    for (int i = 0; i < B; i++) {
        cin >> b[i];
    }

    int res = 0;
    for (int i = 0; i < B; i++) {
        int p = i;
        for (int j = 0; j < A; j++) {
            if (b[p] == a[j]) {
                p++;
            }
        }
        res = max(res, p - i);
    }
    cout << res << endl;
    return 0;
}

Measured memory_bytes: 3152
#include "bits/stdc++.h"
 
typedef long long ll;
#define int ll
#define fi first
#define se second
#define SORT(a) sort(a.begin(),a.end())
#define rep(i,n) for(int i = 0;i < (n) ; i++) 
#define REP(i,n) for(int i = 0;i < (n) ; i++) 
#define MP(a,b) make_pair(a,b)
#define pb(a) push_back(a)
#define INF LLONG_MAX/2

using namespace std;
int MOD = 1000000007;

signed main(){
    int n;
    cin >> n;
    
    int a[100001];
    int s = 0;
    rep(i,n){
        cin >> a[i];
        s += a[i];
    }
    if(s%(n*(n+1)/2) != 0){
        cout << "NO" << endl;
        return 0;
    }
    int x = s/(n*(n+1)/2);
    int sum_sa = 0;
    for(int i = 0;i < n;i++){
        int sa = a[(i+1)%n] - a[i];
        sum_sa += sa;
        if((x-sa)%n == 0 && (x-sa)/n >= 0 && (x-sa)/n <= x){

        }else{
            cout << "NO" << endl;
            return 0;
        }
    }
    if(sum_sa != 0){
        cout << "NO" << endl;
        return 0;
    }
    cout << "YES" << endl;



    return 0;   
}
// g++ -std=c++14 code1.cpp
// rm -r -f test;oj dl https://ddcc2019-final.contest.atcoder.jp/tasks/ddcc2019_final_a
// rm -r -f test;oj dl http://arc060.contest.atcoder.jp/tasks/arc060_a

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

int n,m,ans;

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    while(cin >> n >> m,n){
        vector<int> a(n);
        for (int i=0;i<n;++i) cin >> a[i];
        ans=0;
        for (int i=0;i<n;++i)
            for (int j=i+1;j<n;++j)
                ans=max(ans,(a[i]+a[j]<=m?a[i]+a[j]:0));
        if (ans) cout << ans << endl;
        else cout << "NONE" << endl;
    }
}


Measured memory_bytes: 3224
#include<iostream>
#include<string.h>
#include<vector>
#include<list>
#include<stdio.h>
#include<math.h>
#include<iomanip>
#include<map>
#include<stack>
#include<queue>
#define range(i,a,b) for(int i = (a); i < (b); i++)
#define rep(i,b) range(i,0,b)
#define debug(x) cout << "debug " << x << endl;
using namespace std;

int main(){
    int input;
    stack<int> cars;
    while(cin >> input){
        if(input > 0){
            cars.push(input);
        }else{
            cout << cars.top() << endl;
            cars.pop();
        }
    }
}

Measured memory_bytes: 1200
import sys

sys.setrecursionlimit(10 ** 6)
int1 = lambda x: int(x) - 1
p2D = lambda x: print(*x, sep="\n")
def II(): return int(sys.stdin.readline())
def MI(): return map(int, sys.stdin.readline().split())
def LI(): return list(map(int, sys.stdin.readline().split()))
def LLI(rows_number): return [LI() for _ in range(rows_number)]
def SI(): return sys.stdin.readline()[:-1]

if II()>=30:print("Yes")
else:print("No")



Measured memory_bytes: 61792
#include<iostream>
#include<string>
#include<sstream>
#include<algorithm>
#include<vector>
#include<iomanip>
#include<cmath>
#include<complex>
#include<queue>
#include<deque>
#include<stack>
#include<map>
#include<set>
#include<bitset>
#include<functional>
#include<numeric>
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; }
using namespace std;
#define REP(i,m,n) for(int i=(int)(m) ; i < (int) (n) ; ++i )
#define rep(i,n) REP(i,0,n)
using ll = long long;
const int inf=1e9+7;
const ll longinf=1LL<<60 ;
const ll mod=1e9+7 ;
int dx[4] = {1,0,-1,0}, dy[4] = {0,1,0,-1};

int main()
{

    int a,b;
    cin >> a >> b;
    if(a+b==3) cout << 3 << endl;
    else if(a+b==4) cout << 2 << endl;
    else cout << 1 << endl;

    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<cstdint>

int main() {
  std::cin.tie(0); std::ios::sync_with_stdio(false);
  int r, D, x; std::cin >> r >> D >> x;
  for(int i = 0; i < 10; ++i) {
    x = r*x - D;
    std::cout << x << "\n";
  }
  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>

using namespace std;

typedef long long ll;

const ll M = 4e18;
ll n, x, y;
ll d[405][405];

int main()
{
    scanf("%lld%lld%lld", &n, &x, &y);
    for(ll i = 0; i <= 400; i++)
    {
        for(ll j = 0; j <= 400; j++)
        {
            d[i][j] = M;
        }
    }
    d[0][0] = 0;
    for(ll i = 0; i < n; i++)
    {
        ll t1, t2, t3;
        scanf("%lld%lld%lld", &t1, &t2, &t3);
        for(ll j = 400; j >= t1; j--)
        {
            for(ll k = 400; k >= t2; k--)
            {
                d[j][k] = min(d[j][k], d[j - t1][k - t2] + t3);
            }
        }
    }
    ll ans = M;
    for(ll i = x, j = y; i <= 400 && j <= 400; i += x, j += y)
    {
        ans = min(ans, d[i][j]);
    }
    if(ans == M) printf("-1\n");
    else printf("%lld\n", ans);
    return 0;
}


Measured memory_bytes: 1536
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int,int> P;
typedef pair<ll, ll> Pll;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define repn(i, n) for (int i = 0; i <= (int)(n); i++)
#define srep(i, l, n) for (int i = l; i < (int)(n); i++)
#define srepn(i, l, n) for (int i = l; i <= (int)(n); i++)
#define pb push_back 
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }

const int MOD = 1000000007;
const int INF = 1e9;
#define PI 3.14159265369;
int dx[4] = {1,-1,0,0};
int dy[4] = {0,0,1,-1};
int ddx[8] = {1,1,1,-1,-1,-1,0,0};
int ddy[8] = {0,1,-1,0,1,-1,1,-1};


int main(){
	string s, t;
	cin >> s >> t;
	if(s==t.substr(0,s.length())) cout << "Yes";
	else cout << "No";
}

Measured memory_bytes: 3624
#include<iostream>
#include<algorithm>
#include<cmath>
#include<string>
#include<cstring>
int main()
{
	int a = 0, b = 0, c = 0, d = 0, e = 0, mi = 0, ma = 0, ansa = 0, ansb = 0, count = 0, crowdy[101] = {};
	char hairetu[200] = {};
	using namespace std;
	int x = 0, y = 0, z = 0, play[200] = {};
	std::string str, strt, str_s;
	bool acheck = false;
	bool ccheck = false;
	bool candccheck = false;
	bool allsmall = true;



	cin >> str;
	x = str.size() - 1;

	for (int i = 0; i < str.size(); i++) {
		hairetu[i] = str[i];

	}
	if (hairetu[0] == 'A') {
		acheck = true;
	}
	for (int i = 2; i < x; i++) {



		if (ccheck == true) {
			if (hairetu[i] == 'C') {
				candccheck = true;
			}


		}
		if (str[i] == 'C') {
			ccheck = true;

		}




	}
	for (int i = 1; i < str.size() ; i++) {
		
		if (hairetu[i] != 'A'&&hairetu[i] != 'C' && (hairetu[i] >= 'A') && (hairetu[i] <= 'Z')) {
			allsmall = false;
		}
	}
	if (!candccheck) {

		if (acheck) {

			if (ccheck) {
				if (allsmall) {
					cout << "AC" << endl;
				}
				else {
					cout << "WA" << endl;
				}
			}
			else {
				cout << "WA" << endl;
			}
		}
		else {
			cout << "WA" << endl;
		}
	}
	else {
		cout << "WA" << endl;
	}

}





Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<vector>
#include<queue>
#include<algorithm>
#include<map>
#include<set>
#include<cmath>
#include<iomanip>
#include<stack>
#include<string.h>
typedef long long ll;
#define rep(i,n) for(int i=0;i<(n);i++)
#define pb push_back
#define sz(a) (int)a.size()
using namespace std;

int main() {
	int n;
	cin >> n;
	int a = n / 200;
	cout << 10 - a << endl;
}

Measured memory_bytes: 3592
#include<algorithm>     //sort,二分探索,など
#include<bitset>        //固定長bit集合
#include<cmath>         //pow,logなど
#include<complex>       //複素数
#include<deque>         //両端アクセスのキュー
#include<fstream>       //ファイルストリーム（標準入力変更用）
#include<functional>    //sortのgreater
#include<iomanip>       //setprecision(浮動小数点の出力の誤差)
#include<iostream>      //入出力
#include<iterator>      //集合演算(積集合,和集合,差集合など)
#include<map>           //map(辞書)
#include<numeric>       //iota(整数列の生成),gcdとlcm(c++17)
#include<queue>         //キュー
#include<set>           //集合
#include<stack>         //スタック
#include<string>        //文字列
#include<unordered_map> //イテレータあるけど順序保持しないmap
#include<unordered_set> //イテレータあるけど順序保持しないset
#include<utility>       //pair
#include<vector>        //可変長配列

//名前
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef map<string, int> msi;
typedef map<string, ll> msll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pllll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<string> vs;
typedef vector<bool> vb;
typedef vector<vector<int>> vvi;
typedef vector<vector<ll>> vvll;
typedef vector<vector<string>> vvs;
typedef vector<vector<bool>> vvb;

//定数
const ll MOD = 1000000007;
const ll INF = 1000000000000000000;

//マクロ
#define rep(i,n) for(int i=0;i<n;i++)
#define reps(i,s,e) for(int i=s;i<e;i++)
#define repse(i,s,e) for(int i=s;i<=e;i++)
#define rrep(i,n) for(int i=n-1;i>=0;i--)
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
#define in1(x1) cin >> x1
#define in2(x1, x2) cin >> x1 >> x2
#define in3(x1, x2, x3) cin >> x1 >> x2 >> x3
#define inN(x, N) rep(i, N) in1(x[i])
#define outl(x) cout << x << endl
#define out2l(x, y) cout << x << " " << y << endl 

//よく使う関数
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; }

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

    //標準入力をファイルに変更
    //std::ifstream in("input.txt");
    //std::cin.rdbuf(in.rdbuf());

    int N;
    in1(N);

    vll h(N);
    inN(h, N);

    ll ans = h[0];

    reps(i, 1, N)
    {
        ans += h[i] > h[i - 1] ? h[i] - h[i - 1] : 0;
    }

    outl(ans);

    return 0;
}


Measured memory_bytes: 3656
import java.util.Arrays;
import java.util.Scanner;

public class Main{
		static long mod = (long)1e9+7;

	public static void main(String[]args) {
		try(Scanner scan = new Scanner(System.in)){
			
			int N = scan.nextInt();
			int[]A = new int [N];
			int[]C = new int [N];
			for(int i = 0;i<N;i++) {
				A[i] = scan.nextInt();
				C[i] = A[i];
			}
			
			Arrays.sort(C);
			
			if(N%2==1) {//奇数
				if(C[0]!=0) {
					System.out.println(0);
					System.exit(0);
				}
				
				for(int i = 1;i<N;i =i+2) {
					if(C[i]!=i+1||C[i+1]!=i+1) {
						System.out.println(0);
						System.exit(0);
						}
					}
					
					int k = N/2;
					
					System.out.println(mod_pow(2,k,mod));
					
				
				
			}else{//偶数
				for(int i = 0;i<N;i =i+2) {
					if(C[i]!=i+1||C[i+1]!=i+1) {
						System.out.println(0);
						System.exit(0);
						}
					}
				
				int k = N/2;
				
				
				System.out.println(mod_pow(2,k,mod));
				
				
				
				
			}
			
			
			
			
			
			
		}
		
		
		
		
		
	}
	
	
	
	private static long mod_pow(long x, long n ,long mod) {//Xのn乗を二分累乗法(繰り返し２乗法)で計算modもあり大きくしない
		long res = 1;
		    while(n > 0){
		        if((n&1)==1) {
		        	res = res*x%mod;
		        }
		        x = x*x%mod;
		        n >>= 1;
		    }
		    return res;
	}
	
		

}


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

using namespace std;

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

    vector<int> p(3,0), t(3,0);

    int n;
    cin >> n;

    while(n--)
    {
        int a,b,c;
        cin >> a >> b >> c;

        t[0] = max(a + p[1], a + p[2]);
        t[1] = max(b + p[0], b + p[2]);
        t[2] = max(c + p[0], c + p[1]);

        p = t;
    }

    cout << max(t[0], max(t[1], t[2]));
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
const int N=2e5+5;
int n,tot,ans[N],head[N],nex[N<<1],to[N<<1];
void add(int u,int v){to[++tot]=v;nex[tot]=head[u];head[u]=tot;}
vector<int>v[3],s[2];
int get(int x)
{
    int ans=v[x].back();v[x].pop_back();return ans;
}
bool vis[N];
void dfs(int u,int dep)
{
    s[dep].push_back(u);
    vis[u]=true;
    for(int i=head[u];i;i=nex[i])
    {
        int v=to[i];if(vis[v]) continue;
        dfs(v,dep^1);
    }
}
int main()
{
    scanf("%d",&n);
    for(int i=1;i<=n;i++)
        v[i%3].push_back(i);
    for(int i=1;i<n;i++)
    {
        int u,v;scanf("%d%d",&u,&v);add(u,v);add(v,u);
    }
    dfs(1,0);
    if(s[0].size()<=v[0].size())
    {
        for(int x:s[0])
        {
            ans[x]=get(0);
        }
        for(int x:s[1])
        {
            if(v[0].size()) ans[x]=get(0);
            else if(v[1].size()) ans[x]=get(1);
            else ans[x]=get(2);
        }
    }
    else if(s[1].size()<=v[0].size())
    {
        for(int x:s[1])
        {
            ans[x]=get(0);
        }
        for(int x:s[0])
        {
            if(v[0].size()) ans[x]=get(0);
            else if(v[1].size()) ans[x]=get(1);
            else ans[x]=get(2);
        }
    }
    else if(s[0].size()>=v[1].size()&&s[1].size()>=v[2].size())
    {
        for(int x:s[0])
        {
            if(v[1].size()) ans[x]=get(1);
            else ans[x]=get(0);
        }
        for(int x:s[1])
        {
            if(v[2].size()) ans[x]=get(2);
            else ans[x]=get(0);
        }
    }
    else
    {
        for(int x:s[1])
        {
            if(v[1].size()) ans[x]=get(1);
            else ans[x]=get(0);
        }
        for(int x:s[2])
        {
            if(v[2].size()) ans[x]=get(2);
            else ans[x]=get(0);
        }
    }
    for(int i=1;i<=n;i++)
        printf(i==n?"%d\n":"%d ",ans[i]);
}


Measured memory_bytes: 14104
n = int(input())
L = [None]+list(input().split())
even = []
odd = []
if n % 2 == 0:
    for i in range(1,1+n):
        if i % 2 == 0:
            even.append(L[i])
        else:
            odd.append(L[i])
    ans = even[::-1] + odd
else:
    for i in range(1,1+n):
        if i % 2 == 0:
            even.append(L[i])
        else:
            odd.append(L[i])
    ans = odd[::-1] + even
for i in range(n-1):
    print(ans[i],end=' ')
print(ans[n-1])


Measured memory_bytes: 106780
#include <algorithm>
#include <iostream>
#include <cstdlib>
#include <cstdio>
#include <string>
#include <vector>
#include <cmath>
#include <map>
#include <set>

using namespace std;

int main() {
    string n;
    cin >> n;
    if(n[0] == '9' || n[1] == '9'){
        cout << "Yes" << endl;
    }
    else{
        cout << "No" << endl;
    }
    return 0;
}


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

#define DEBUG(x) cerr << #x << ": " << x << endl;
#define ll long long

int main() {
    int n;
    cin >> n;
    vector<ll> v(n);
    for (ll& x : v) {
        cin >> x;
    }

    vector<ll> r1 = v;
    for (ll i = 1; i < n; i++) {
        // r1[i] = r1[i-1] + r1[i];
        r1[i] += r1[i-1];
    }
    vector<ll> r2 = v;
    for (ll i = n-2; i >= 0; i--) {
        // r2[i] = r2[i+1] + r2[i];
        r2[i] += r2[i+1];
    }

    ll Min = abs(r1[0] - r2[1]);
    for (int i = 0; i < n-1; i++) {
        Min = min(Min, abs(r1[i] - r2[i+1]));
    }

    cout << Min << endl;

    return 0;
}

Measured memory_bytes: 4992
import sys
sys.setrecursionlimit(10 ** 7)
 
class UnionFind():
	def __init__(self, size):
		self.table = [-1 for _ in range(size)]
		self.size = [1 for _ in range(size)]
 
	def find(self, x):
		if self.table[x] < 0:
			return x
		else:
			self.table[x] = self.find(self.table[x])
			return self.table[x]
 
	def union(self, x, y):
		s1 = self.find(x)
		s2 = self.find(y)
		if s1 != s2:
			if self.table[s1] > self.table[s2]:
				self.table[s2] = s1
				self.table[s1] -= 1
				self.size[s1] += self.size[s2]
				self.size[s2] = 0
			else:
				self.table[s1] = s2
				self.table[s2] -= 1
				self.size[s2] += self.size[s1]
				self.size[s1] = 0
 
		return
 
n, m = map(int, input().split())
brs = [list(map(int, input().split())) for _ in range(m)]
 
uf = UnionFind(n)
ans = [n*(n-1)//2]
for i in range(m-1, 0, -1):
	a, b = brs[i][0], brs[i][1]
	a, b = a-1, b-1
	s1, s2 = uf.find(a), uf.find(b)
	if s1 != s2:
		ans.append(ans[-1] - uf.size[s1]*uf.size[s2])
	else:
		ans.append(ans[-1])
	uf.union(s1, s2)
print(*list(reversed(ans)), sep="\n")

Measured memory_bytes: 62628
#include<iostream>
#include<cstdio>
#include<bits/stdc++.h>
#include<iomanip>
#include<queue>
#include<string>
#include<vector>
#include<utility>
#include<set>
#include<map>
#include<algorithm>
#include<functional>	//for "greater<type>"
#include<cmath>
using namespace std;
#define pb push_back
#define fi first
#define sc second
#define mp make_pair
#define is insert	//?????????

#define BIT_MAX_N 100000 

int n;
long long bit[BIT_MAX_N+1];

void update(int k,long long a){
	while(k<=n){
		bit[k]=max(a,bit[k]);
		k=(k|(k-1))+1;
	}
}

long long s(int k){
	long long z=0;
	while(k>0){
		z=max(z,bit[k]);
		k=k&(k-1);
	}
	return z;
}

int main(){
	cin>>n;
	fill(bit,bit+n+1,0);
	for(int i=0;i<n;++i){
		int x;
		cin>>x;
		update(x,s(x-1)+x);
	}
	cout<<((long long)n*(n+1))/2-s(n)<<endl;;
}

Measured memory_bytes: 3856
#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()
{
    ll x;
    cin >> x;
    ll ans;
    ans = x / 11LL;
    x -= ans * 11LL;
    ans *= 2LL;
    if (x != 0) ans++;
    if (x - 6 > 0) ans++;

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

Measured memory_bytes: 256
import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {
            // 入力
            Scanner         sc = new Scanner(System.in);
            int             n = Integer.parseInt(sc.next());
            // 1オリジンで処理する
            int[]           A = new int[n + 1];
            for (int i = 0; i < n; i++) {
                A[i + 1] = Integer.parseInt(sc.next());
            }
            sc.close();

            // 計数ソート
            int[]           B = new int[n + 1];
            countingSort(A, B, 10000);

            // 出力
            StringBuilder   builder = new StringBuilder();
            builder.append(B[1]);
            for (int i = 2; i <= n; i++) {
                builder.append(' ').append(B[i]);
            }
            System.out.println(builder);
    }

    /**
     * 
     * @param A
     * @param B     Aをソートした結果を返す
     * @param k     Aの要素の最大値
     */
    static void countingSort(int[] A,int[] B, int k) {
        int[]       C = new int[k];

        // C[i]に出現数を記録する、A配列の要素の値が添字になる
        for (int j = 1; j < A.length; j++) {
            C[A[j]]++;
        }

        // C[i]にi以下の出現数を記録する
        // 例えばC[5]にはC[4]以前の出現数の合計が記録される
        for (int i = 1; i < k; i++) {
            C[i] = C[i] + C[i - 1];
        }

        // 後ろから選んでいくと安定なソートになる
        for (int j = A.length - 1; j > 0; j--) {
            B[C[A[j]]] = A[j];
            // 要素をコピーしたら、1減らす。同じ値の要素があるため
            C[A[j]]--;
        }
    }
}



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

typedef long long ll;

int n, m, l;
string s;

int main(){
    cin >> s;
	reverse(s.begin(),s.end());
	ll res=0;
	int jw=0;
	s+='0';
	for(int i = 0;i < (int)s.size(); i++) {
		int k = s[i]-'0';
		res+=min(k,10-k);
		if(k>5) s[i+1]++;
		else if(k==5&&s[i+1]>='5') s[i+1]++;
	}
	cout<<res<<'\n';

    return 0;
}


Measured memory_bytes: 1412
#include <iostream>
 
using namespace std;
 
int main()
{
    int n, s, t, c, p, f;
    cin >> n;
     
    while(n--)
    {
        s = f = t = 0;
        for(int i = 0; i < 10; i++)
          {
            cin >> p;
            if(p < s && p < t){
                f = 1;
            }
                else if(p > s){
                s = p;
            } 
                else if(p > t){
                t = p;
            }  
                else {
                f = 1;
            }
        }
        if(f == 0){
            cout << "YES" << endl;
        } 
            else {
            cout << "NO" << endl;
        }
    }
     
    return 0;
}

Measured memory_bytes: 1152
import sys
input = sys.stdin.readline


# 約数を列挙 (ex. 6 => [1,2,3,6])
def make_divisors(n):
    divisors = []
    for i in range(1, int(n**0.5)+1):
        if n % i == 0:
            divisors.append(i)
            if i != n // i:
                divisors.append(n//i)
    return divisors


def main():
    N = int(input())
    D = make_divisors(N)
    ans = 0
    for a in D:
        if a == 1:
            continue
        d, m = divmod(N, a-1)
        if d == m:
            ans += a-1
    print(ans)


if __name__ == '__main__':
    main()


Measured memory_bytes: 3272
#include<bits/stdc++.h>
#include <iterator>
#include <iostream>
#include <numeric>
#include <math.h>
#define ll long long
#define ull long
#define mpa make_pair
#define pb push_back
#define ff first
#define pii pair<ll,ll>
#define dd long long
#define trace(x) cerr << #x << " : " << x << endl
#define ss second
#define boost ios_base::sync_with_stdio(0)
#define forp(i,a,b) for(ll i=a;i<=b;i++)
#define rep(i,n)    for(ll i=0;i<n;++i)
#define ren(i,n)    for(ll i=n-1;i>=0;i--)
#define forn(i,a,b) for(ll i=a;i>=b;i--)
#define all(c) (c).begin(),(c).end()
#define tr(c,i) for(typeof((c).begin()) i = (c).begin(); i != (c).end();
#define sc(x) scanf("%lld",&x)
#define clr(x,val) memset(x,val,sizeof(x))
#define pr(x) printf("%lld\n",x) 
#define gc getchar
#define pdd pair<dd,dd>
#define prec(x) cout<<fixed<<setprecision(x)
#define fre freopen("input.txt","r",stdin),freopen("output.txt","w",stdout)
#define ar array 
using namespace std;
ll a[100005];

int main(){
  ll n,x,m;
  cin>>n>>x>>m;
  map<ll,ll> help;
  help[x]=1;
  ll ans=x;
  ll len=n-1;
  ll c=1;
  a[1]=x;
  while(len){
  	
  	x=(x*x)%m;
  	c++;
  	if(help[x]){
  		break;
	}
	else{
		
		help[x]=c;
		a[c]=x;
		len--;
		ans+=x;
	}
  }
  
  if(len){
  
  ll cyc_len=c-help[x];
  ll sum=0;
  ll part_sum=len%cyc_len;
  ll no_time=len/cyc_len;
  
  ll st=help[x];
  ll en=c-1;
  
  ll su=0;
  
  for(ll i=st;i<=en;i++)su+=a[i];
  
  ans+=su*no_time;
  
  for(ll i=st;i<st+part_sum;i++)ans+=a[i];
  }
  
  cout<<ans<<endl;
  
  
  
  
  
  
  
  
    
    
    
    
    
    
	
   
}
  

Measured memory_bytes: 7048
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int n = Integer.parseInt(scanner.next());

        int s = n % 60;
        int tmpM = n / 60;
        int h = tmpM / 60;
        int m = tmpM % 60;

        System.out.println(h + ":" + m + ":" + s);
    }
}

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

using namespace std;
typedef long long ll;
#define int ll

#define REP(i,n) for(int i=0;i<n;++i)
#define ALL(name) name.begin(),name.end()
#define SORT(name) sort(name.begin(), name.end())
#define ZERO(p) memset(p, 0, sizeof(p))
#define MINUS(p) memset(p, -1, sizeof(p))
#if 1
#  define DBG(fmt, ...) printf(fmt, ##__VA_ARGS__)
#else
#  define DBG(fmt, ...)
#endif

const ll LLINF = (1LL<<60);
const int INF = (1LL<<30);
const double DINF = std::numeric_limits<double>::infinity();
const int MOD = 1000000007;
#define MAX_N 100010

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

    int M1, M2, D1, D2;
    cin >> M1 >> D1 >> M2 >> D2;
    int ans = 0;
    if(M1 != M2) { ans = 1; }
    printf("%lld\n", ans);

    return 0;
}


Measured memory_bytes: 256
def gcdf(a):
    a.sort()
    a0=a[0]
    a=[int(x%a0) for x in a if x%a0 != 0]
    if len(a)==0:
        return a0
    else:
        a.append(a0)
        a0=min(a)
        return gcdf(a) 

n=int(input())
a=list(map(int,input().split()))

if n==2:
    print(max(a))
elif n<2**8:
    gcdv=0
    for i in range(n):
        acpy=list(a)
        del acpy[i]
        gcdx=gcdf(acpy)
        if gcdx>gcdv:
            gcdv=gcdx
    print(gcdv)
else:
    m=int(n**(2/3))
    ns=int(n/m)
    rgcd=[]
    for mi in range(m):
        ms=ns*mi
        if mi==m-1:
            am=a[ms:n]
        else:
            am=a[ms:ms+ns]
        gcdm=gcdf(am)
        rgcd.append(gcdm)
    gcdv=0

    for mi in range(m):
        rgcd1=list(rgcd)
        del rgcd1[mi]
        gcdrg1=gcdf(rgcd1)
        ms=ns*mi
        if mi==m-1:
            am=a[ms:n]
        else:
            am=a[ms:ms+ns]
#        print(mi,gcdf(am),len(am),gcdf(rgcd1))
        for i in range(len(am)):
            acpy=list(am)
#            del acpy[i]
#            acpy.append(gcdrg1)
            acpy[i]=gcdrg1
            gcdx=gcdf(acpy)
            if gcdx>gcdv:
                gcdv=gcdx
    print(gcdv)


Measured memory_bytes: 14084
n = [list(map(int, s.split())) for s in open(0)][0]

x = 0
y = 0
if n[0] >= 1:
    x = n[0] * (n[0] - 1) / 2
if n[1] >= 1:
    y = n[1] * (n[1] - 1) / 2
print(int(x + y))



Measured memory_bytes: 2940
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
#define ordered_set tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update>
#define ll long long
#define f first
#define sc second

void solve() {
    int x;
    cin >> x;
    int g = __gcd(360, x);
    int val = 360/g;
    cout << val << "\n";
    return;
}
int main() {
    ios_base::sync_with_stdio(0);cin.tie(0);
    int t = 1;
    //cin >> t;
    while(t--) {
        solve();
    }
}


Measured memory_bytes: 3648
class Solver(object):
    def __init__(self):
        self.n, self.t = list(map(int, input().split(" ")))

    def solve(self):
        min_cost = 1001
        for _ in range(self.n):
            c, t = list(map(int, input().split(" ")))
            if t <= self.t:
                if c < min_cost:
                    min_cost = c
            min_cost
        if min_cost < 1001:
            print(min_cost)
        else:
            print("TLE")


if __name__ == "__main__":
    s = Solver()
    s.solve()

Measured memory_bytes: 3060
// 全事象から奇数事象を引く解法
#include <bits/stdc++.h>
using namespace std;

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

    int all = 1, odd = 1;
    for (int i = 0; i < n; i++) {
        int x;
        cin >> x;
        all *= 3;
        if (x % 2 == 0) odd *= 2;
    }

    cout << all - odd << endl;

    return 0;
}

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

int main() {
    int n;
    cin>>n;
    vector<char> c(n);
    vector<int> num(n+1);
    int w=0;
    int r=0;
    rep(i,n){
        cin>>c[i];
        if(c[i]=='W') w++;
    }
    rep(i,n+1){
        num[i]=max(w,r);
        if(i<n){
            if(c[n-i-1]=='W') w--;
            else r++;
        }
    }
    sort(num.begin(),num.end());
    cout<<num[0]<<endl;
}

Measured memory_bytes: 4220
import java.util.Scanner;

public class Main{

	static Scanner s=new Scanner(System.in);

	public static void main(String __[]){
		while(true) {
			input();
			if((n|x)==0)
				break;
			solve();
		}
	}

	static int n,x;
	private static void input(){
		n=s.nextInt();
		x=s.nextInt();
	}
	private static void solve(){
		long count=0;
		for(int i=1;i<=n;i++) {
			for(int j=i+1;j<=n;j++) {
				for(int k=j+1;k<=n;k++) {
					if(i+j+k==x)
						count++;
				}
			}
		}
		System.out.println(count);
	}
}

Measured memory_bytes: 26716
#include <stdio.h>
#include <string.h>
char s[101];
int main(void){
    int i,j=0,n;
    scanf("%s",s);
    n=strlen(s);
    for(i=0;i<n;i++){
        if(s[i]!=s[n-1-i])j++;
    }
    printf("%d\n",j/2);
    return 0;
}

Measured memory_bytes: 128
#JMD
#Nagendra Jha-4096

 
import sys
import math

#import fractions
#import numpy
 
###File Operations###
fileoperation=0
if(fileoperation):
    orig_stdout = sys.stdout
    orig_stdin = sys.stdin
    inputfile = open('W:/Competitive Programming/input.txt', 'r')
    outputfile = open('W:/Competitive Programming/output.txt', 'w')
    sys.stdin = inputfile
    sys.stdout = outputfile

###Defines...###
mod=1000000007
 
###FUF's...###
def nospace(l):
    ans=''.join(str(i) for i in l)
    return ans
 
 
 
##### Main ####
t=1
for tt in range(t):
    #n=int(input())
    a,b= map(int, sys.stdin.readline().split(' '))
    print(a*b)
    #a=list(map(int,sys.stdin.readline().split(' ')))
    
    
#####File Operations#####
if(fileoperation):
    sys.stdout = orig_stdout
    sys.stdin = orig_stdin
    inputfile.close()
    outputfile.close()

Measured memory_bytes: 9204
#include<bits/stdc++.h>
using namespace std;
int main(void)
{
    int n,a;
    cin>>n>>a;

    if((n%500)==0)
    {
      cout<<"Yes"<<endl;
    }
    else if((n%500)<=a)
    {
        cout<<"Yes"<<endl;   
    }
    else
    {
       cout<<"No"<<endl; 
    }
    

}

Measured memory_bytes: 3624
#include "bits/stdc++.h"
using namespace std;
typedef long long li;

const li mod = 1e9 + 7;

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

    int n = s.size();

    bool ok = false;
    for (int i = 0; i < n; ++i) {
        for (int j = i; j < n; ++j) {
            string trimmed = s.substr(0, i) + s.substr(j);
            ok |= trimmed == "keyence";
        }
    }
    cout << (ok ? "YES" : "NO") << endl;

    return 0;
}


Measured memory_bytes: 256
#include<iostream>
using namespace std;
int main(){
  int n,a[1001]={};
  while(1){
    int min=1000000;
    cin>>n;
    if(n==0)break;
    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++)
	if(a[i]-a[j]>=0){
	  if(min>a[i]-a[j])min=a[i]-a[j];
	}
	else{ 
	  if(min>a[j]-a[i])min=a[j]-a[i];
	}

    cout<<min<<endl;
  }
  return 0;
}

Measured memory_bytes: 3044
sa = input().strip()
sb = input().strip()
sc = input().strip()
cura = 0
curb = 0
curc = 0
next_s = "a"
while True:
    if next_s=="a":
        if cura==len(sa):
            win = "A"
            break
        next_s = sa[cura]
        cura += 1
    elif next_s=="b":
        if curb==len(sb):
            win = "B"
            break
        next_s = sb[curb]
        curb += 1
    else:
        if curc==len(sc):
            win = "C"
            break
        next_s = sc[curc]
        curc += 1
print(win)

Measured memory_bytes: 38384
#include <math.h>
#include <stdlib.h>
#include <string.h>
#include <algorithm>
#include <array>
#include <iomanip>
#include <iostream>
#include <limits>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
#include<numeric>

using namespace std;

int main() {
    int A,B,K,g,ans;
    cin>>A>>B>>K;
    while(A!=B){
    if(A>B)A=A-B;
    if(A<B)B=B-A;
    }
    g=A;
    for(int i=g;i>0;i--){
        if(g%i==0){
            K=K-1;
            if(K==0)ans=i;
        }
    }
    cout<<ans<<endl;
    return 0;
}

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

using namespace std ; 

int main ( ) 
{
	int x , y ; 
	cin >> x >> y ; 
	if ( (x+y )<= 23)
	cout << x+y ; 
	else 
	cout << (x+y ) - 24 ; 
		return 0 ; 
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
const int MAX = 100000;
const int MOD =1000000007;

long long fac[MAX], finv[MAX], inv[MAX];

void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}
long long COM(int n, int k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

int main(){
  COMinit(); 
  int n,k,ans=0;
  cin>>n>>k;
  vector<int>a(n);
  for(int i=0;i<n;i++){
 	 cin>>a[i];
  }
  sort(a.begin(),a.end());
  for(int i=0;i<n;i++){
      ans=(ans+a[i]*(COM(i,k-1)-COM(n-i-1,k-1)))%MOD;
      
  }
  cout<<ans;
}  

Measured memory_bytes: 2944
#include <cstdio>
#include <cstdlib>
#include <string>
#include <iostream>
#include <vector>
using namespace std;

#define MAX 10000

struct Node {
	int key;
	Node *parent, *left, *right;
};

Node *root, *NIL;

#if LOCAL
// Split Function
vector<int> split_int(string input,char del){
    vector<int> output;
    string substr;
    for(const char c : input){
        if(c == del){
          output.push_back(atoi(substr.c_str()));
          substr.clear();
        } else {
          substr += c;
        }
    }
    output.push_back(atoi(substr.c_str()));
    return output;
}

vector<string> split_str(string input,char del){
    vector<string> output;
    string substr;
    for(const char c : input){
        if(c == del){
          output.push_back(substr);
          substr.clear();
        } else {
          substr += c;
        }
    }
    output.push_back(substr);
    return output;
}
#endif // for local test

void inorder(Node *u)
{
	if (u == NIL) {
        return;
    }
    inorder(u->left);
    printf(" %d", u->key);
    inorder(u->right);
}

void preorder(Node *u)
{
    if (u == NIL) {
        return;
    }
    printf(" %d", u->key);
    preorder(u->left);
    preorder(u->right);
}

void insert_bst(int i_key)
{
    Node *y = NIL; // parent of x
    Node *x = root; // 検索対象, 初期値をrootとする
    // Node for insert
    Node *z;
    z = (Node*) malloc(sizeof(Node));
    z->key = i_key;
    z->left = NIL;
    z->right = NIL;

    while(x != NIL) {
        y = x;
        if (z->key < x->key) {
            x = x->left;
        } else {
            x = x->right;
        }
    }
    z->parent = y;
    if (y == NIL) {
        root = z;
    } else {
        if (z->key < y->key){
            y->left = z;
        } else {
            y->right = z;
        }
    }
}

int main() {
	int n_node, i_key;
	scanf("%d", &n_node);

#if LOCAL // for local test
	vector<string> input = {"insert 30", "insert 88", "insert 12",
	 						"insert 1", "insert 20", "insert 17",
							"insert 25", "print"};
	// input for local test
	vector<string> vec_tmp;
    for (int i = 0; i < n_node; i++) {
        vec_tmp = split_str(input[i], ' ');
        if (vec_tmp[0] == "insert") {
            i_key = atoi(vec_tmp[1].c_str());
            insert_bst(i_key);
        } else if (vec_tmp[1] == "print") {
            inorder(root);
            cout << "\n";
            preorder(root);
            cout << "\n";
        }
    }
#else // for online test
    string com;
    for (int i = 0; i < n_node; i++) {
        cin >> com;
        if (com == "insert") {
            scanf("%d", &i_key);
            insert_bst(i_key);
        } else if (com == "print") {
            inorder(root);
            cout << "\n";
            preorder(root);
            cout << "\n";
        }
    }
#endif // for online test

    return 0;
}



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

int main() {
  int A, B, C, D, E, F;
  cin >> A >> B >> C >> D >> E >> F;

  int mass = 0;
  int suger = 0;
  double prev = 0;
  for (int a = 0; a <= F; a += 100 * A) {
    for (int b = 0; a + b <= F; b += 100 * B) {
      if (a == 0 && b == 0)
        continue;
      for (int c = 0; a + b + c <= F; c += C) {
        for (int d = 0; a + b + c + d <= F; d += D) {
          if (c == 0 && d == 0)
            continue;
          if (c + d > (a + b) / 100 * E)
            continue;
          int n = a + b;
          int m = c + d;
          double l = double(100) * m / (n + m);
          if (l >= prev) {
            mass = n + m;
            suger = m;
            prev = l;
          }
        }
      }
    }
  }

  if (mass == 0)
    mass = 100 * A;
  cout << mass << " " << suger << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
	int n;
  	scanf("%d",&n);
  	int ok = 0;
  	while(n > 0){
      if(n % 10 == 7){ok = 1;break;}
      n = n/10;
    }
  	(ok == 1) ? puts("Yes") : puts("No");
  	
}

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

char CtoN[3];
string in;
string cp;

bool input(){
  cin>>in;
  if(in==".")return false;
  return true;
}

char Not(char c){
  switch(c){
    case '0':
      return '2';
    case '1':
      return '1';
    case '2':
      return '0';
  }
}
char Lpro(char a,char b){
  return min(a,b);
}

char Lsum(char a,char b){
  return max(a,b);
}

char Clac(string str){
  if(str[0]=='('){
    int count=1;
    for(int i=1;i<str.size();i++){
      if(str[i]=='('){
        count++;
      }else if(str[i]==')'){
        count--;
      }else if(count==1&&(str[i]=='+' || str[i]=='*')){
        string str1 = str.substr(1,i-1);
        string str2 = str.substr(i+1,str.size()-(i+1)-1);
        if(str[i]=='+'){
          return Lsum(Clac(str1),Clac(str2));
        }else{
          return Lpro(Clac(str1),Clac(str2));
        }
      }
    }
  }else if(str[0]=='-'){
    return Not(Clac(str.substr(1)));
  }else{
    return str[0];
  }
}

char conv(char c){
  switch(c){
    case 'P':
      return CtoN[0];
    case 'Q':
      return CtoN[1];
    case 'R':
      return CtoN[2];
    default:
      return c;
  }
}

void mkcp(){
  cp="";
  for(int i=0;i<in.size();i++){
    cp+=conv(in[i]);
  }
}


int solve(){
  int ans=0;

  for(int i=0;i<3;i++){
    for(int j=0;j<3;j++){
      for(int k=0;k<3;k++){
        CtoN[0]=CtoN[1]=CtoN[2]='0';
        CtoN[0]+=i;
        CtoN[1]+=j;
        CtoN[2]+=k;
        mkcp();
        if(Clac(cp)=='2'){
          ans++;
        }
      }
    }
  }
  return ans;
}


int main(){
  while(input()){
    cout<<solve()<<endl;
  } 
}

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

const double PI=3.14159265358979323846;

int main(){
	double a, b, x;
	cin >> a >> b >> x;
	double ans;
	double h = 2*(a*a*b - x)/(a*a);
	if(h <= b){
        printf("%.6f\n", 180*asin(h/sqrt(a*a + h*h))/PI);
	}else{
	    h = 2*x/(b*a);
	    printf("%.6f\n", 90 - 180*asin(h/sqrt(b*b + h*h))/PI);
	}

}


Measured memory_bytes: 256
import sys


def input():
    return sys.stdin.readline().strip()


sys.setrecursionlimit(20000000)


def main():
    A, B, C, K = map(int, input().split())
    answer = 0
    if K >= A:
        answer += A
        K -= A
        if K >= B:
            K -= B
            if K > 0:
                answer -= K
    else:
        answer += K
    print(answer)


if __name__ == "__main__":
    main()


Measured memory_bytes: 9192
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cmath>
#include<string>
#include<cstring>

using namespace std;
int n,a,b,c;
int main()
{
	cin>>n;
	for(int i=1;i<=n;i++)
	{
		cin>>a>>b>>c;
		if(a<b+c||(a-b-c)%2==1){cout<<"No";return 0;}
	}
	cout<<"Yes";
	
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ll long long
using namespace std;
struct aaa{
	ll x,y,op;
}a[200010];
ll n,m,M,ans,flag,fa[200010],mn,mx,sz;
ll find(ll x){
	if(x==fa[x])return x;
	return fa[x]=find(fa[x]);
}
int main(){
	ll x,y,i;
	scanf("%lld%lld%lld",&n,&M,&m);
	for(i=1;i<=n;i++)fa[i]=i;
	for(i=1;i<=m;i++){
		scanf("%lld%lld%lld",&a[i].x,&a[i].y,&a[i].op);a[i].x++;a[i].y++;
		if(a[i].op==0){
			x=find(a[i].x);y=find(a[i].y);
			if(x!=y)ans++,fa[x]=y;
		}
	}
	for(i=1;i<=m;i++)if(a[i].op==1){
		flag=1;if(find(a[i].x)==find(a[i].y))return puts("No"),0;
   }
   for(i=1;i<=n;i++)if(find(i)==i)sz++;
   if(flag&&sz<3)return puts("No"),0;
   mn=ans+sz;
   if(!flag)mn--;
   mx=ans+sz*(sz-1)/2;
   if(mn<=M&&M<=mx)puts("Yes");
    else puts("No");
}

Measured memory_bytes: 3584
#pragma GCC optimize("Ofast")

#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>

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

    int n;
    cin >> n;
    uint64_t comfort[200000] = {};
    for (int i = 0; i < n; ++i){
        cin >> comfort[i];
    }
    sort(comfort, comfort + n);
    uint64_t output = 0;
    for(int i=1; i < n; ++i){
        output += comfort[n-1-i/2];
    }
    cout << output << "\n";
}

Measured memory_bytes: 5224
n,k=map(int,input().split())
tmp=[int(input()) for i in range(n)]
 
left=max(tmp)-1
right=sum(tmp)
while left+1 < right:
    mid=(left+right)//2
    count=1
    now=0
    for i in tmp:
        if mid<now+i:
            now=i
            count+=1
        else:
            now+=i
 
    if count<=k:
        right=mid
    else:
        left=mid
print(right)


Measured memory_bytes: 9556
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
template <class T> int size(const T &x) { return x.size(); }
#define rep(i,a,b) for(int i = (a); i < (b); i++)
#define iter(it,c) for(auto it = (c).begin(); it != (c).end();++it)
#define pb push_back
#define fs first
#define sc second
typedef pair<int,int> ii;
typedef vector<int> vi;
typedef vector<ii> vii;

const int INF = ~(1<<31);
const double pi = acos(-1);
const double EPS = 1e-9;

int main() {
    cin.sync_with_stdio(false);
	double a,b;
	cin >> a >> b;
	cout << ceil((a+b)/2) << endl;
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ff                first
#define ss                second
#define int               long long
#define pb                push_back
#define mp                make_pair
#define li                list<int>
#define pii               pair<int,int>
#define vi                vector<int>
#define mii               map<int ,int>
#define setbits(x)        _builtin_popcountll(x)
#define zrobits(x)        _builtin_ctzll(x)
#define mod               1000000007
#define inf               1e18
#define ps(x,y)           fixed<<setprecision(y)<<x
#define mk(arr,n,type)    type *arr=new type(n);
#define w(x)              int x; cin>>x; while(x--)
#define all(x)            (x).begin(), (x).end()
#define PI                3.14159265358979
void c_p_c()
{
#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("ou.txt", "w", stdout);
#endif
}
void printString(int n)
{
	char str[50];
	int i = 0;

	while (n > 0) {
		int rem = n % 26;
		if (rem == 0) {
			str[i++] = 'z';
			n = (n / 26) - 1;
		}
		else
		{
			str[i++] = (rem - 1) + 'a';
			n = n / 26;
		}
	}
	str[i] = '\0';
	reverse(str, str + strlen(str));
	cout << str << endl;

	return;
}

void solve()
{

	int n; cin >> n;
	printString(n);
}
int32_t main()
{
	c_p_c();
	solve();
}

Measured memory_bytes: 3620
#include <bits/stdc++.h>
using namespace std;
#define MOD 1000000007
#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 show(x) {for(auto i: x){cout << i << " ";} cout<<endl;}
#define showm(m) {for(auto i: m){cout << m.x << " ";} cout<<endl;}
typedef long long ll;
typedef pair<int, int> P;
ll gcd(int x, int y){ return y?gcd(y, x%y):x;}
ll lcm(ll x, ll y){ return (x*y)/gcd(x,y);}


vector<vector<int>> dp(1050, vector<int>(10500, MOD));
int main()
{
    int h,n;
    cin >> h>> n;
    vector<P> ab(n);
    rep(i, n){ cin >> ab[i].first >> ab[i].second;}

    dp[0][0] = 0;
    rep(i,n){
        rep(j,h+1){
            dp[i+1][j] = min(dp[i][j], dp[i+1][max(0, j-ab[i].first)] + ab[i].second); 
        }
    }
    cout << dp[n][h] << endl;
}



Measured memory_bytes: 43392
n, m = map(int, input().split())

score = [0] * 1000000
countWA = 0
countAC = 0

for i in range(m):
    pi, si = input().split()
    pi = int(pi)
    if score[pi] == -1:
        continue
    if si == "WA":
        score[pi] += 1
    if si == "AC":
        countWA += score[pi]
        countAC += 1
        score[pi] = -1

print(countAC, countWA)

Measured memory_bytes: 57560