akhauriyash/Code-Regression huggingface dataset:
#include "bits/stdc++.h"

#define MOD 1000000007
#define rep(i, n) for(ll i=0; i < (n); i++)
#define ALL(v) v.begin(),v.end()
#define FOR(i, j, k) for(ll i=j;i<k;i++)
#define DUMP(i, v)for(ll i=0;i<v.size();i++)cout<<v[i]<<" "

using namespace std;
typedef long long int ll;
typedef vector<ll> llvec;
typedef vector<double> dvec;
typedef pair<ll, ll> P;
typedef long double ld;
struct Edge{ll from, to, cost;};
struct node{ll cost, to;
  bool friend operator>(node a, node b){
    return a.cost>b.cost;
  }
};

ll mod(ll a, ll mod){
  ll res = a%mod;
  if(res<0)res=res + mod;
  return res;
}

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

ll modinv(ll a, ll mod){
  return modpow(a, mod-2, mod);
}

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

bool is_prime(ll n){
  ll i = 2;
  if(n==1)return false;
  if(n==2)return true;
  bool res = true;
  while(i*i <n){
    if(n%i==0){
      res = false;
    }
    i = i+1;
  }

  //if(i==1)res = false;
  if(n%i==0)res=false;
  return res;
}

ll fact[100100];
ll ifact[100100];

void genfact(ll n){
  fact[0]=1;
  ifact[0]=1;
  FOR(i, 1, n+1){
    fact[i] = mod(fact[i-1]*i, MOD);
    ifact[i] = modinv(fact[i], MOD);
  }
}

ll comb(ll n, ll k){
  if(k<0)return 0;
  if(n<0)return 0;
  if(k>n){
    return 0;
  }else{
    ll ans = fact[n];
    ans = mod(ans*ifact[k], MOD);
    ans = mod(ans*ifact[n-k], MOD);
    return ans;
  }
}
/**************************************
** A main function starts from here  **
***************************************/
int main(){
  ll N;
  cin >> N;
  set<ll> nums;
  llvec a(N+1,0);
  ll dup;
  ll l, r;
  rep(i, N+1){
    cin >> a[i];
    if(nums.count(a[i])>0){
      dup=a[i];
      r=i;
    }
    nums.insert(a[i]);
  }
  
  genfact(N+1);
  FOR(i,0, N+2){
    if(a[i]==dup){
      l=i;
      break;
    }
  }

  r = N-r;
  FOR(k, 1, N+2){
    cout << mod(comb(N+1, k) - comb(l+r, k-1),MOD)<<endl;
  }
  return 0;
}


Measured memory_bytes: 8832
#!/usr/bin/env python

def f(n):
    if n % 2 == 0:
        return n // 2
    return 3 * n + 1


def main():
    s = int(input())

    res = set()

    m = 1

    while True:
        if s in res:
            print(m)
            return
        res.add(s)
        m += 1
        s = f(s)


if __name__ == '__main__':
    main()


Measured memory_bytes: 2940
A, B, C, X, Y = map(int, input().split())

if Y - X > 0:
    ans_1 = min(X, Y) * C * 2 + (Y - X) * B
else:
    ans_1 = min(X, Y) * C * 2 + (X - Y) * A

ans_2 = max(Y, X) * C * 2

ans_3 = X * A + Y * B

print(min(ans_1, ans_2, ans_3))

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

#define int long long 
#define put(n) cout<<(n)<<"\n"
#define FOR(i,num,N) for(int(i)=(num);(i)<(N);(i)++)
#define RFOR(i,num,N) for(int (i)=(num);(i)>(N);(i)--)
#define all(v) (v).begin() , (v).end()
#define rall(v) (v).rbegin() , (v).rend()

signed main(){
    int N;
    cin>>N;
    vector<pair<int,int>> red(N);
    vector<pair<int,int>> blue(N);

    FOR(i,0,N) cin>>red[i].second>>red[i].first;
    FOR(i,0,N) cin>>blue[i].first>>blue[i].second;

    sort(rall(red));
    sort(all(blue));
    
    vector<bool> chum(N,false);

    FOR(i,0,N){
        FOR(j,0,N){
            if((blue[i].first > red[j].second) && (blue[i].second > red[j].first) && !chum[j]){
                chum[j] = true;
                break;
            }
        }
    }

    int ans = 0;
    FOR(i,0,N){
        if(chum[i]) ++ans;
    }

    put(ans);

}




Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <math.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
typedef long long ll;
 
 
int main() {
	int n; cin >> n;
	int w[n];
	int ans = 100000;
	rep(i,n) cin >> w[i];
	rep(t,n) {
		int left = 0;
		int right = 0;
		rep(j,t){
			left += w[j];
		}
		for(int k = t; k < n; k++){
			right += w[k];
		}
		ans = min(abs(left - right),ans);
	}
	cout << ans << endl;
}

Measured memory_bytes: 256
import heapq

n, m = map(int, input().split())
lis = []

for i in input().split():
  heapq.heappush(lis, -int(i))

for j in range(m):
  tmp = -heapq.heappop(lis)
  heapq.heappush(lis, -int((tmp/2)))

print(-sum(lis))

Measured memory_bytes: 14380
#include<iostream>
using namespace std;
int main()
{
	int n;
	cin >> n;
	for(int i=0;i<n;++i){
		int k,p,kati;
		cin >> k >> p;
		while(1){
			for(int j=1;j<=p;++j){
				k--;
				kati=j;
				if(k==0)break;
			}
			if(k==0)break;
		}
		cout << kati << endl;
	}
	return 0;
}

Measured memory_bytes: 1160
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ConsoleApp15
{
    class Class39
    {
        static void Main()
        {
            var nab = Console.ReadLine().Split().Select(int.Parse).ToArray();
            int n = nab[0], a = nab[1], b = nab[2];
            int sum = 0;
            int temp;
            for(int i = 0; i <= n; i++)
            {
                temp = 0;
                for (int j = 0; j < i.ToString().Length; j++)
                    temp += int.Parse(i.ToString()[j].ToString());

                if (a <= temp && temp <= b)
                    sum += i;
            }
            Console.WriteLine(sum);
        }
    }
}


Measured memory_bytes: 15444
// (c) 2020, redotter

// Roses are red
// The Tardis is blue
// The Doctor once said
// Rose Tyler...

#pragma GCC optimize("O3", "unroll-loops")
#pragma GCC target("avx2")
#include <bits/stdc++.h>
using namespace std;
#ifndef ONLINE_JUDGE
#pragma comment(linker, "/stack:500000000")
#endif

#define pb push_back
#define the(a) (a).begin(), (a).end()
#define ft first
#define sd second
#define endl "\n"
#define forn(i, n) for (int i = 0; i < (n); i++)
#define forr(i, s, n) for (int i = (s); i < (n); i++)

using i64 = long long;
using i32 = int;
using f64 = long double;

template <class T> using vec = vector<T>;
using str = string; using p64 = pair<i64, i64>;
using v64 = vec<i64>; using vv64 = vec<v64>;
using s64 = set<i64>; using m64 = map<i64, i64>;
template <size_t Size1> using a64 = array<i64, Size1>;
template <size_t Size1, size_t Size2> using aa64 = array<a64<Size2>, Size1>;
template <class T> using hash_set = unordered_set<T>;
template <class T, class U> using hash_map = unordered_map<T, U>;

mt19937 gen(998244353);
const i64 inf = numeric_limits<i64>::max() / 2;

template <class T> inline i64 len(const T& a) { return (i64)(a.size()); }
inline void fast() { ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0); }
template <class T, class S>
inline bool check_min(T& a, S b) { if (a > b) return a = b, 1; return 0; }
template <class T, class S>
inline bool check_max(T& a, S b) { if (a < b) return a = b, 1; return 0; }

void read() {}
template<class T, class ...U>
void read(T& a, U& ...b) { cin >> a; read(b...); }
void print() {}
template<class T, class ...U>
void print(const T& a, const U& ...b) { cout << a << " "; print(b...); }
void println() { cout << "\n"; }
template<class T, class ...U>
void println(const T& a, const U& ...b) { cout << a << " "; println(b...); }

struct Problem {
	void files(str in, str out) {
#ifdef ONLINE_JUDGE
		freopen(in.c_str(), "r", stdin), freopen(out.c_str(), "w", stdout);
#endif
	}
	void solve(), input();
	void many() { i32 t; cin >> t; while (t--) input(), solve(); }
	void make(bool mt = 0) { if (mt) many(); else input(), solve(); }
} problem;

signed main() {
	fast();
	problem.make();
#ifdef _DEBUG
	println(); println("[finished]"); system("pause > nul");
#endif
	return 0;
}

i64 n, k;
v64 a;

v64 dp;
i64 calc(i64 x) {
	if (dp[x] != -1) {
		return dp[x];
	}
	i64& ans = dp[x];
	ans = 0;
	forn(i, n) {
		if (a[i] <= x) {
			if (!calc(x - a[i])) {
				return ans = 1;
			}
		}
	}
	return ans = 0;
}

void Problem::solve() {
	dp.assign(k + 1, -1);
	i64 ans = calc(k);
	if (ans) println("First");
	else     println("Second");
}

void Problem::input() {
	read(n, k);
	a.resize(n);
	forn(i, n) {
		read(a[i]);
	}
}


Measured memory_bytes: 8640
import java.util.Scanner;

/**
 * @author kawakami
 *
 */
class Main {

	/**
	 * @param args
	 */
	public static void main(String[] args) {
		// TODO Auto-generated method stub
		Scanner as = new Scanner(System.in);
		
		int H,W;
		
		
		
		while(true){
			H = as.nextInt();
			W = as.nextInt();
			
			if(H==0 && W==0){
				
				break;
				
			}
			
			for(int i=0;i<H;i++){
				
				if(i==0 || i==H-1){
					
					for(int j=0;j<W;j++){
						
						System.out.print("#");
						
					}
					
				}
				
				else{
					
					for(int j=0;j<W;j++){
					
						if(j==0 || j==W-1){
							
							System.out.print("#");
							
						}
						
						else{
							
							System.out.print(".");
							
						}
						
					}
					
				}
				
				System.out.println();
				
			}
			
			System.out.println();
		}
		
		

	}

}

Measured memory_bytes: 34500
#include<iostream>
#include<algorithm>
#include<utility>
using namespace std;
char s[300005];
int main()
{
    int mini=2000000000,i,j,k,n;
    cin>>n;

    cin>>s;
    pair<int,int>p[n];
    if(s[0]=='W') p[0].first=1;
    else p[0].first=0;
    if(s[n-1]=='E') p[n-1].second=1;
    else p[n-1].second=0;
    for(i=1;i<n;i++){
        if(s[i]=='W'){
            p[i].first=p[i-1].first+1;
        }
        else{
            p[i].first=p[i-1].first;
        }
    }
    for(i=n-2;i>=0;i--){
        if(s[i]=='E'){
            p[i].second=p[i+1].second+1;
        }
        else{
            p[i].second=p[i+1].second;
        }
    }
//    for(i=0;i<n;i++){
//        cout<<p[i].first<<" "<<p[i].second<<endl;
//    }
    int sum=0;
    for(i=0;i<n;i++){
        if(s[i]=='W'){
            if(p[i].first>0) sum=(p[i].first+p[i].second-1);
        }
        else if(s[i]=='E'){
            if(p[i].second>0) sum=(p[i].first+p[i].second-1);
        }
        mini=min(mini,sum);
    }
    cout<<mini<<endl;
}


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

#define d(x) cerr << #x ":" << x << endl;
#define dd(x, y) cerr << "(" #x "," #y "):(" << x << "," << y << ")" << endl
#define rep(i, n) for (int i = (int)(0); i < (int)(n); i++)
#define repp(i, a, b) for (int i = (int)(a); i < (int)(b); i++)
#define all(v) v.begin(), v.end()
#define dump(v)                  \
    cerr << #v ":[ ";            \
    for (auto macro_vi : v) {    \
        cerr << macro_vi << " "; \
    }                            \
    cerr << "]" << endl;
#define ddump(v)                           \
    cerr << #v ":" << endl;                \
    for (auto macro_row : v) {             \
        cerr << "[";                       \
        for (auto macro__vi : macro_row) { \
            cerr << macro__vi << " ";      \
        }                                  \
        cerr << "]" << endl;               \
    }
using lint       = long long;
const int INF    = 1e9;
const lint LINF  = 1e18;
const lint MOD   = 1e9 + 7;
const double EPS = 1e-10;

int main() {
    lint x;
    cin >> x;
    if (400 <= x && x < 600) { cout << 8 << endl; }
    if (600 <= x && x < 800) { cout << 7 << endl; }
    if (800 <= x && x < 1000) { cout << 6 << endl; }
    if (1000 <= x && x < 1200) { cout << 5 << endl; }
    if (1200 <= x && x < 1400) { cout << 4 << endl; }
    if (1400 <= x && x < 1600) { cout << 3 << endl; }
    if (1600 <= x && x < 1800) { cout << 2 << endl; }
    if (1800 <= x && x < 2000) { cout << 1 << endl; }
    return 0;
}

Measured memory_bytes: 3628
#include <map>
#include <set>
#include <list>
#include <cmath>
#include <queue>
#include <stack>
#include <cstdio>
#include <string>
#include <vector>
#include <complex>
#include <cstdlib>
#include <cstring>
#include <numeric>
#include <sstream>
#include <iostream>
#include <algorithm>
#include <functional>
  
#define mp       make_pair
#define pb       push_back
#define all(x)   (x).begin(),(x).end()
#define rep(i,n) for(int i=0;i<(n);i++)
  
using namespace std;
  
typedef    long long          ll;
typedef    unsigned long long ull;
typedef    vector<bool>       vb;
typedef    vector<int>        vi;
typedef    vector<vb>         vvb;
typedef    vector<vi>         vvi;
typedef    pair<int,int>      pii;
  
const int INF=1<<29;
const double EPS=1e-9;
  
const int dx[]={1,0,-1,0,1,1,-1,-1},dy[]={0,-1,0,1,1,-1,-1,1};


int main() {
  string s;
  cin >> s;
  int N = s.size();
  int p = 0;
  for (int i = 0; i < N; i++) {
    if (s[i] == 'p') p++;
  }
  cout << N / 2 - p << endl;
  return 0;
}

Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
/* typedef */
typedef long long ll;
typedef pair<int, int> pii;
/* constant */
const int INF = 1 << 30;
const ll LINF = 1LL << 50;
const int NIL = -1;
const int MAX = 10000;
const int mod = 1000000007;
const double pi = 3.141592653589;
/* global variables */
/* function */
/* main */
int main(){
    string s, t;
    cin >> s >> t;
    sort(s.begin(), s.end());
    sort(t.begin(), t.end());
    reverse(t.begin(), t.end());
    if (s < t) cout << "Yes" << '\n';
    else cout << "No" << '\n';
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define N 100005
#define M 65540
using namespace std;
int n,s[N],S,ans,f[M],inf,sum[20];
int dfs(int S)
{
  if(!S)return 0; 
  if(f[S]<inf)return f[S];
  for(int i=0;i<16;i++)if((S>>i)&1)
    for(int j=0;j<16;j++)if(i!=j&&(S>>j)&1)
    {
      int p=i^j,x=S^(1<<i)^(1<<j)^(1<<p);
      if(S>>p&1)f[S]=min(f[S],dfs(x)+2);
      else f[S]=min(f[S],dfs(x)+1);
    }
  return f[S];
}

int main()
{
  int a,b,c;
  scanf("%d",&n);
  for(int i=1;i<n;i++)
    scanf("%d%d%d",&a,&b,&c),s[a]^=c,s[b]^=c;
  for(int i=0;i<n;i++)sum[s[i]]++;
  for(int i=1;i<16;i++)
    ans+=(sum[i]>>1),S+=(1<<i)*(sum[i]&1);
  memset(f,127,sizeof(f));inf=f[0];
  printf("%d\n",ans+dfs(S));
  return 0;
} 

Measured memory_bytes: 896
#include <bits/stdc++.h>
#include <atcoder/all>
#define ll long long int
#define MOD 1000000007
#define P pair<ll,ll>
#define INF 1000000000000000000

using namespace atcoder;
using namespace std;

int main(void){
  ll n, d;
  cin >> n >> d;
  
  vector<ll> x(n), y(n);
  for (int i = 0; i < n; i++){
    cin >> x[i] >> y[i];
  }
  two_sat ts(2*n);
  
  for (int i = 0; i < n; i++){
    ts.add_clause(2*i, true, 2*i+1, true);
    ts.add_clause(2*i, false, 2*i+1, false);
  }

  for (int i = 0; i < n; i++){
    for (int j = i+1; j < n; j++){
      if (abs(x[i]-x[j]) < d){
        ts.add_clause(2*i, false, 2*j, false);
      }
      if (abs(x[i]-y[j]) < d){
        ts.add_clause(2*i, false, 2*j+1, false);
      }
      if (abs(y[i]-x[j]) < d){
        ts.add_clause(2*i+1, false, 2*j, false);
      }
      if (abs(y[i]-y[j]) < d){
        ts.add_clause(2*i+1, false, 2*j+1, false);
      }
    }
  }

  bool ok = ts.satisfiable();

  if(ok){
    cout << "Yes" << endl;
    
    vector<bool> wariate = ts.answer();
    for (int i = 0; i < n; i++){
      if (wariate[2*i]){
        cout << x[i] << endl;
      }
      else
        cout << y[i] << endl;
    }
  }
  else
    cout << "No" << endl;
    


  return 0;
}


Measured memory_bytes: 3788
#include<bits/stdc++.h>
#define MOD 1000000007
#define INF 0x3f3f3f3f
#define INFL 0x3f3f3f3f3f3f3f3f
#define EPS (1e-10)
#define rep(i,n)for(int i=0;i<(n);i++)
using namespace std;
typedef long long ll;
typedef pair<int, int>P;

int a[50], b[50], c[50], d[50];
signed main() {
	int n, m; scanf("%d%d", &n, &m);
	rep(i, n)scanf("%d%d", &a[i], &b[i]);
	rep(i, m)scanf("%d%d", &c[i], &d[i]);
	rep(i, n) {
		int Min = INT_MAX, id;
		rep(j, m) {
			if (Min > abs(a[i] - c[j]) + abs(b[i] - d[j])) {
				Min = abs(a[i] - c[j]) + abs(b[i] - d[j]);
				id = j;
			}
		}
		printf("%d\n", id + 1);
	}
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
vector<int> CONST(6, 0);
int eval(string &S, int &p){
  if (S[p] == '0'){
    p++;
    return CONST[0];
  } else if (S[p] == '1'){
    p++;
    return CONST[1];
  } else if (S[p] == 'a'){
    p++;
    return CONST[2];
  } else if (S[p] == 'b'){
    p++;
    return CONST[3];
  } else if (S[p] == 'c'){
    p++;
    return CONST[4];
  } else if (S[p] == 'd'){
    p++;
    return CONST[5];
  } else if (S[p] == '-'){
    p++;
    return 65535 - eval(S, p);
  } else {
    p++;
    int E1 = eval(S, p);
    char c = S[p];
    p++;
    int E2 = eval(S, p);
    p++;
    if (c == '^'){
      return E1 ^ E2;
    } else {
      return E1 & E2;
    }
  }
}
int main(){
  vector<int> s(65536, -1);
  priority_queue<pair<int, int>, vector<pair<int, int>>, greater<pair<int, int>>> pq;
  for (int i = 0; i < 16; i++){
    CONST[1] += 1 << i;
    for (int j = 0; j < 4; j++){
      if (i >> j & 1){
        CONST[j + 2] += 1 << i;
      }
    }
  }
  for (int i = 0; i < 6; i++){
    pq.push(make_pair(1, CONST[i]));
  }
  set<pair<int, int>> st;
  while (!pq.empty()){
    int L = pq.top().first;
    int E = pq.top().second;
    pq.pop();
    if (s[E] == -1){
      s[E] = L;
      if (L <= 7){
        st.insert(make_pair(E, L));
      }
      if (L + 1 <= 16){
        int tmp1 = 65535 - E;
        if (s[tmp1] == -1){
          pq.push(make_pair(L + 1, tmp1));
        }
      }
      for (auto P : st){
        int E2 = P.first;
        int L2 = P.second;
        int L3 = L + L2 + 3;
        if (L3 <= 16){
          int tmp2 = E ^ E2;
          if (s[tmp2] == -1){
            pq.push(make_pair(L3, tmp2));
          }
          int tmp3 = E & E2;
          if (s[tmp3] == -1){
            pq.push(make_pair(L3, tmp3));
          }
        }
      }
    }
  }
  while (1){
    string S;
    cin >> S;
    if (S == "."){
      break;
    }
    int p = 0;
    int E = eval(S, p);
    assert(s[E] != -1);
    cout << s[E] << endl;
  }
}


Measured memory_bytes: 3196
#include <bits/stdc++.h>
#define ll long long
#define rep(i,l,r) for(ll i =(l);(i)<(r);(i)++)
using namespace std;

int main(){
    ll k;
    cin>>k;
    ll ans=0;
    rep(i,0,k){
        rep(j,0,k){
            rep(m,0,k){
                ans+=gcd(i+1,gcd(j+1,m+1));
            }
        }
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 3552
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0; i<(n); i++)
#define reps(i,s,n) for(int i=(s); i<(n); i++)
#define all(v) v.begin(),v.end()
#define outve(v) for(auto i : v) cout << i << " ";cout << endl
#define outmat(v) for(auto i : v){for(auto j : i) cout << j << " ";cout << endl;}
#define in(n,v) for(int i=0; i<(n); i++){cin >> v[i];}
#define out(n) cout << (n) << endl
#define fi first
#define se second
#define pb push_back
#define mod 1000000007
#define infi 1900000000
#define infl 1100000000000000000
#define cyes cout << "Yes" << endl
#define cno cout << "No" << endl
#define csp << " " <<
#define outset(n) cout << fixed << setprecision(n);
using namespace std;
using ll = long long;
using ld = long double;
using vi = vector<int>;
using vvi = vector<vector<int>>;
using vl = vector<ll>;
using vvl = vector<vector<ll>>;
using pii = pair<int,int>;
using pll = pair<ll,ll>;
template<typename T> using ve = vector<T>;
template<typename T> using pq2 = priority_queue<T>;
template<typename T> using pq1 = priority_queue<T,vector<T>,greater<T>>;
template<typename T> bool chmax(T &a, T b) {if(a < b) {a = b;return 1;}return 0;}
template<typename T> bool chmin(T &a, T b) {if(a > b) {a = b;return 1;}return 0;}




int main(){
    
    int N,M;
    cin >> N >> M;
    vvi G(N);
    vi dp(N,0);
    vi deg(N,0);
    
    rep(i,M){
        int a,b;
        cin >> a >> b;
        a--,b--;
        G[a].pb(b);
        deg[b]++;
    }
    
    queue<int> que;
    rep(i,N) if(deg[i] == 0) que.push(i);
    
    while (!que.empty()) {
        int v = que.front();
        que.pop();
        
        for (int p : G[v]) {
            deg[p]--;
            
            if(deg[p] == 0){
                que.push(p);
                chmax(dp[p],dp[v]+1);
            }
        }
    }
    
    
    int res = 0;
    rep(i,N) chmax(res,dp[i]);
    cout << res << endl;
    
    

    
    
    
    

    return 0;
}


Measured memory_bytes: 6528
#include<bits/stdc++.h>
using namespace std;
#define f(i,a,b) for(i=a;i<b;i++)
#define rep(i,n) f(i,0,n)
#define fd(i,a,b) for(i=a;i>=b;i--)
#define pb push_back
#define mp make_pair
#define vi vector< int >
#define vl vector< ll >
#define ss second
#define ff first
#define ll long long
#define ull unsigned long long
#define pii pair< int,int >
#define pll pair< ll,ll >
#define sz(a) a.size()
#define inf (1000*1000*1000+5)
#define all(a) a.begin(),a.end()
#define tri pair<int,pii>
#define vii vector<pii>
#define vll vector<pll>
#define viii vector<tri>
#define pi acosl(-1)
#define sqr(x) ((x)*(x))
#define mod (1000*1000*1000+7)
#define pdd pair<double,double>
#define MEMS(x) memset(x,-1,sizeof(x))
#define MEM(x) memset(x,0,sizeof(x))
template <typename T>
string NumberToString(T pNumber)
{
     ostringstream oOStrStream;
     oOStrStream << pNumber;
     return oOStrStream.str();
}
ll StringToNumber(string s)
{
    stringstream geek(s);
    ll x=0;
    geek>>x;
    return x;
}
ll modPow(ll x,ll n,ll m)
{
    if(n==0)
    return 1%m;
    ull u = modPow(x,n/2,m);
    u=u*u%m;
    if(n%2==1)
    u=u*x%m;
    return u;
}
ll gcd(ll a,ll b)
{
    if(b==0)
    return a;
    return gcd(b,a%b);
}
ll seive[1000000];
void seiveForm()
{
    ll i,j;
    seive[0]=seive[1]=1;
    f(i,2,100000)
    {
        if(seive[i]==0)
            for(j=i*i;j<1000000;j+=i)
                seive[j]=1;
    }
}
bool isPerfectSquare(ll num)
{
    double n = sqrt(num);
    return n==(ll)n?true:false;
}
ll countSetbits(ll num)
{
    ull temp=0;
    while(num){
        num=num&(num-1);
        temp++;
    }
    return temp;
}
bool isPowerOfTwo(ll n)
{
   if(n==0)
   return false;
   return (ceil(log2(n)) == floor(log2(n)));
}
ll power(ll x, ll y)
{
    ll res = 1;
    while (y > 0)
    {
        if (y & 1)
            res = res*x;
        y = y>>1;
        x = x*x;
    }
    return res;
}
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    ll n,i,x=0,ans=0;
    string s;
    cin>>n>>s;
    rep(i,n)
    {
        if(s[i]=='I')
            x+=1;
        else
            x-=1;
        ans=max(x,ans);
    }
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 3668
using System;
using System.Linq;
using System.Collections.Generic;
using System.Text.RegularExpressions;

class ConsoleApp1
{
    public static void Main(string[] args)
    {
        Console.ReadLine();
        var lists = Console.ReadLine()
            .Split(new[] { " " }, StringSplitOptions.RemoveEmptyEntries)
            .ToList()
            .OrderByDescending(x => int.Parse(x));
        bool isAlice = true;
        int alice; int ken; ken = alice = 0;
        foreach (var item in lists)
        {
            if (isAlice)
            {
                alice += int.Parse(item);
            }
            else
                ken += int.Parse(item);
            isAlice = !isAlice;
        }
        Console.WriteLine(alice-ken);
    }
}

Measured memory_bytes: 13396
//#include <fstream>
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>

using namespace std;

//ifstream cin("x.in"); ofstream cout("x.out");

string s;

bool ok (long long x) {
    if (x == 0) return 0;

    cout << "? " << x << "\n"; cout.flush();

    cin >> s;
    if (s == "Y") return 1;
    else          return 0;
}

int main() {
    long long p10 = 1, p9 = 9;
    long long ans = 0;

    int nrcif = 0;
    for (int i = 0; i <= 9; ++ i) {
        if (!ok(p10)) {
            nrcif = i; break;
        }
        p10 *= 10;
    }

    if (nrcif == 0) { // rasp e 10^x
        ans = 1;
        for (int i = 1; i <= 9; ++ i) {
            if (ok(p9)) {
                break;
            }
            ans *= 10;
            p9 = p9 * 10 + 9;
        }
    } else {
        for (int i = 1; i < nrcif; ++ i) {
            int sol = 0;
            ans *= 10;
            for (int step = 8; step > 0; step >>= 1) {
                if (sol + step < 10 && ok(ans + sol + step)) {
                    sol += step;
                }
            }
            ans += sol;
        }

        // ptr ultima cifra
        int sol = 9;
        ans *= 10;
        for (int step = 8; step > 0; step >>= 1) {
            if (sol - step >= 0 && ok((ans + sol - step) * 10)) {
                sol -= step;
            }
        }
        ans += sol;
    }

    cout << "! " << ans << "\n"; cout.flush();
    return 0;
}


Measured memory_bytes: 684
From0 = ['0','1']*(10**6)
From1 = ['1','0']*(10**6)
s = list(input())
F0 = From0[:len(s)]
F1 = From1[:len(s)]
count_0 = 0
count_1 = 0
for i in range(len(s)):
  if s[i] != F0[i]:
    count_0 += 1
for i in range(len(s)):
  if s[i] != F1[i]:
    count_1 += 1
print(min(count_0,count_1))


Measured memory_bytes: 36776
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<bitset>
#include<map>
#include<stack>
#include<queue>
#include<iomanip>
using namespace std;

#define repr(i, a, b) for (int i = (int)(a); i < (int)(b); i++)
#define rep(i, n) repr(i, 0, n)
#define INF 2e9
#define MOD 1e9+7
#define LINF (long long)4e18



int main(){
  int A,B;
  cin >> A >> B;
  int ans = 0;
  if(A >= 13)ans = B;
  else if(A <= 5)ans = 0;
  else ans = B/2;
  cout << ans <<endl;
}
  


  


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

int main(){
	ios::sync_with_stdio(false);
	cin.tie(0);  
	int n, a, b, c;
	while(cin >> n >> a >> b >> c) {
		cout << n - (a + b - c) << endl;
	}
	return 0;	
}



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

int n;
int a[100001],b[100000];
long long int ans;

int main(){
    cin>>n;
    for (int i=0; i<n+1; i++){
        scanf("%d",&a[i]);
    }
    int temp=0;
    ans=0;
    for (int i=0; i<n; i++){
        scanf("%d", &b[i]);
        ans+=min(temp,a[i]);
        a[i]-=temp;
        a[i]=max(a[i],0);
        ans+=min(a[i],b[i]);
        temp=max(0, b[i]-a[i]);
        //cout<<i<<" : "<<temp<<" : "<<ans<<endl;
    }
    ans+=min(temp,a[n]);
    //cout<<min(temp,a[n]);
    cout<<ans<<endl;
    return 0;
}

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

int main(){
	char S[10];
	char *A="Sunny";
	char *B="Cloudy";
	char *C="Rainy";
	scanf("%s",&S);
	if(strcmp(S,A)==0){
		printf("%s",B);
	}else if(strcmp(S,B)==0){
		printf("%s",C);
	}else if(strcmp(S,C)==0){
		printf("%s",A);
	}else{
		printf("error");
	}
	return 0;
}

Measured memory_bytes: 128
# 2019/07/09
# AtCoder Beginner Contest 058 - C

# Init
clist = ["a","b","c","d","e","f","g","h","i","j","k","l","m","n","o","p","q","r","s","t","u","v","w","x","y","z"]
sdict = dict()

for i in range(len(clist)):
    sdict[clist[i]] = 51

# Input
n = int(input())
for i in range(n):
    s = input()
    for j in range(len(clist)):
        ccnt = 0
        for k in range(len(s)):
            if clist[j] == s[k]:
                ccnt += 1
        sdict[clist[j]] = min(sdict[clist[j]], ccnt)

# Make string
ans = ""
for i in range(len(clist)):
    for j in range(sdict[clist[i]]):
        ans = ans + clist[i]

# Output
print(ans)

    

Measured memory_bytes: 3064
#include <stdio.h>
int main(){
 int i,j,n,temp,min,count=0;
 int num[100];
 scanf("%d",&n);
 for(i=0;i<n;i++) scanf("%d",&num[i]);

 for(i=0;i<n;i++){
  min=i;
  for(j=i;j<n;j++){
   if(num[min]>num[j]) min=j;
  }
  if(i!=min){
  temp=num[min];
  num[min]=num[i];
  num[i]=temp;
  count++;
  }
 }
 for(i=0;i<n-1;i++)printf("%d ",num[i]);
 printf("%d\n",num[n-1]);
 printf("%d\n",count);
 return 0;
}

Measured memory_bytes: 600
#include "bits/stdc++.h"
#define vi vector<int>
#define vb vector<bool>
#define lli long long int
#define vvi vector<vector<int>>
#define loop(n) for (int i = 0; i < n; i++)
using namespace std;

auto SpeedUp = []() {
#ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#endif
    std::ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);
    return 0;
}();

int solve()
{
    string str;
    cin >> str;
    int ans = 0, count = 0;
    for (int i = 0; i < 3; i++)
    {
        if (str[i] == 'R')
            count++;
        else
            count = 0;
        ans = max(ans, count);
    }
    return ans;
}

int main()
{

    cout << solve() << '\n';
    return 0;
}

Measured memory_bytes: 3644
import math
n = int(input())

def factorize_rec(n, factor):
    for i in range(2, math.floor(math.sqrt(n)) + 1):
        if n % i == 0:
            factor.append(i)
            return factorize_rec(n/i, factor)
    factor.append(int(n))
    return factor

def factorize(n):
    return factorize_rec(n, [])

print(str(n) +":", end=" ")
# for i in factorize(n):
#     print(i, end=" ")
print(*factorize(n), sep=' ')

Measured memory_bytes: 7780
#include<stdio.h>
main(){
  double a,b,c,d,e,f,x,y;
  int x5,y5;
  while(scanf("%lf %lf %lf %lf %lf %lf",&a,&b,&c,&d,&e,&f)!=EOF){
    x=(c*e-f*b)/(a*e-d*b);
    y=(a*f-d*c)/(a*e-d*b);

    /* x5=x*10000;
    y5=y*10000;

    x5%=10;
    y5%=10;

    if(x5>=5){
      x+=0.001;
    }
    if(y5>=5){
      y+=0.001;
    }
    */
    printf("%.3f %.3f\n",x+0,y);
  }
  return 0;
}

Measured memory_bytes: 0
people, foods = input().split()
people, foods = int(people), int(foods)

all_like = []
for i in range(people):
  a = input().split()
  num = int(a[0])
  like_str = a[1:]
  like = [int(j) for j in like_str]
  all_like += like
 
output = 0
for food in range(foods):
  if all_like.count(food+1) == people:
    output += 1
print(output)

Measured memory_bytes: 3064
#include <bits/stdc++.h>
#include <chrono>
#include <random>
#define ll long long int
#define ull unsigned long long int
#define pb push_back
#define mp make_pair
#define mod 1000000007
#define rep(i,n) for(ll i=0;i<n;i++)
#define loop(i,a,b) for(ll i=a;i<=b;i++)
#define vi vector <int>
#define vs vector <string>
#define vc vector <char>
#define vl vector <ll>
#define all(c) (c).begin(),(c).end()
#define max3(a,b,c) max(max(a,b),c)
#define min3(a,b,c) min(min(a,b),c)
using namespace std;
ll power(ll a,ll b) {ll res=1;a%=mod; assert(b>=0); for(;b;b>>=1){if(b&1)res=res*a%mod;a=a*a%mod;}return res;}
ll modInverse(ll a){return power(a,mod-2);}
const int N=500001;
vi adj[N];
bool vis[N];
ll gcd(ll a, ll b) { if (a == 0) return b; return gcd(b % a, a); } 
ll lcm(ll a, ll b){return a*b/gcd(a, b);}
#define pi 3.14159265358979323846264338

void solve()
{  
    int x;
    cin>>x;

    cout<<360/gcd(x, 360)<<endl;
}

int main()
{
    #ifndef ONLINE_JUDGE
        // for getting input from input.txt
        freopen("input.txt", "r", stdin);
        // for writing output to output.txt
        freopen("output.txt", "w", stdout);
    #endif

    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int T=1;
    // cin>>T;
    int t=0;
    while(t++<T)
    {
        // cout<<"Case #"<<t<<":"<<' ';
        solve();
        //cout<<'\n';
    }

    cerr << "Time : " << 1000 * ((double)clock()) / (double)CLOCKS_PER_SEC << "ms\n";
}

Measured memory_bytes: 15524
#include <iostream>

#include <vector>

#include <algorithm>

#include <string>


using namespace std;

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

    for(const auto& c : s)
    {
        if(c == '7')
        {
            cout << "Yes\n";
            return 0;
        }
    }

    cout << "No\n";
    return 0;
}

Measured memory_bytes: 3624
#include<iostream>
#include<string>
#include<algorithm>
#include<cstdio>
#include<queue>

using namespace std;
static const int N = 100;
static const int INFTY = (1 << 21);

int n, M[N][N];
int d[N];

void bfs(int s) {
	queue<int> q;
	q.push(s);
	for (int i = 0; i < n; i++)d[i] = INFTY;
	d[s] = 0;
	int u;
	while (!q.empty()) {
		u = q.front();
		q.pop();
		for (int v = 0; v < n; v++) {
			if (M[u][v] == 0)continue;
			if (d[v] != INFTY)continue;
			d[v] = d[u] + 1;
			q.push(v);
		}
	}
	for (int i = 0; i < n; i++) {
		printf("%d ", i + 1);
		if (d[i] == INFTY)
			printf("-1\n");
		else
			printf("%d\n", d[i]);
	}
}

int main(void) {
	int u, v, k;

	scanf("%d", &n);
	for (int i = 0; i < n; i++) {
		for (int j = 0; j < n; j++) {
			M[i][j] = 0;
		}
	}

	for (int i = 0; i < n; i++) {
		scanf("%d%d", &u, &k);
		u--;
		for (int j = 0; j < k; j++) {
			scanf("%d", &v);
			v--;
			M[u][v] = 1;
		}
	}

	bfs(0);
	return 0;
}


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

int main() {

	int n;
	cin >> n;
	int arr[n];
	for (int i=0; i<n; i++) cin >> arr[i];
	
	int diff = INT_MAX;
	
	for (int i=0; i<n+1; i++) {
	
		int l = 0;
		for (int j=0; j<i; j++) {
			l += arr[j];
		}  
		int r = 0;
		for (int j=i; j<n; j++) {
			r += arr[j];
		}
		
		diff = min(diff, abs(l-r));
	
	}
	
	cout << diff;

}


Measured memory_bytes: 256
def main():
    import sys
    from collections import deque
    input = sys.stdin.readline

    H, W = map(int, input().split())
    grid = []
    for _ in range(H):
        grid.append(input().rstrip('\n'))

    d = [(1, 0), (0, 1)]
    que = deque()
    que.append((0, 0))
    seen = [[-1] * W for _ in range(H)]
    if grid[0][0] == '#':
        seen[0][0] = 1
    else:
        seen[0][0] = 0
    while que:
        h, w = que.popleft()
        for dh, dw in d:
            h_new, w_new = h+dh, w+dw
            if 0 <= h_new < H and 0 <= w_new < W:
                if seen[h_new][w_new] == -1:
                    if grid[h_new][w_new] == grid[h][w]:
                        seen[h_new][w_new] = seen[h][w]
                        que.appendleft((h_new, w_new))
                    else:
                        if grid[h_new][w_new] == '#':
                            seen[h_new][w_new] = seen[h][w] + 1
                        else:
                            seen[h_new][w_new] = seen[h][w]
                        que.append((h_new, w_new))
    print(seen[-1][-1])
    #[print(seen[h]) for h in range(H)]


if __name__ == '__main__':
    main()


Measured memory_bytes: 40816
#include<iostream>
using namespace std;
const int N=110;
int n,b[N],p[N],Ans[N];
int main()
{
	cin>>n;
	for(int i=1;i<=n;i++) cin>>b[i];
	for(int i=1;i<=n;i++)
	{
		if(b[i]>i) return puts("-1"),0;
		for(int j=1;j<i;j++) if(p[j]>=b[i]) p[j]++;
		p[i]=b[i];
	}
	for(int i=1;i<=n;i++) Ans[p[i]]=b[i];
	for(int i=1;i<=n;i++) printf("%d\n",Ans[i]);
	return 0;
}


Measured memory_bytes: 256
#include<iostream>
using namespace std;
#define MAX 100000
#define NILL 0
struct Node {
	long long parent,node,key,left, right;
};
Node *T;
void print(int u) {
	cout << "node " << T[u].node << ": ";
	cout << "key = " << T[u].key << ", ";
	if(T[u].parent!=NILL)cout << "parent key = " << T[u].parent << ", ";
	if (T[u].left!=NILL)cout << "left key = " << T[u].left << ", ";
	if (T[u].right!=NILL)cout << "right key = " << T[u].right << ", ";
	cout << endl;
}

int main() {
	int n;
	long long id;
	cin >> n;
	T=new Node[n];
	for (int i = 0; i < n; i++){ 
		T[i].parent = T[i].left = T[i].right = NILL;
	}
    for (int i = 0; i < n; i++) {
		cin >> id;
		T[i].key = id;
		T[i].node = i+1;
    }
	for (int i = 0; i < n; i++) {
		T[i].left = T[2 * i + 1].key;
	    T[2 * i + 1].parent=T[i].key;
		T[i].right = T[2 * i + 2].key;
		T[2 * i + 2].parent = T[i].key;;
	}
	for (int i = 0; i < n; i++) {
		print(i);
	}
}


Measured memory_bytes: 3120
#include <iostream>
#include <utility>
#include <map>
#include <vector>
#include <algorithm>
#include <queue>
#include <math.h>
#include <stack>
#include <set>
#include <deque>
#include <cmath>

using namespace std;
typedef long long ll;
ll mod = 1e9+7;
//ll mod = 998244353;
#define rep(i,n) for(int i = 0; i < (n); ++i)

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


Measured memory_bytes: 3628
#include <cstdio>
#include <bits/stdc++.h>
#include <algorithm>
#include <iostream>
#include <string>
#include <cmath>
#include <functional>
#include <vector>
#include <stack>
#include <queue>
#include <map>
#define rep(i,n) for (int i=0;i<n;i++)
using ll = long long;
using namespace std;

void solve(){

}
int main (){
    ios::sync_with_stdio(0);
    cin.tie(0);
    int n;
    cin>> n;
    int m=0;
    int k=n;
    while(k>0){
        m+=(k%10);
        k/=10;
    }

    // cout << n << m <<endl101;
    if(n%m==0){
        cout << "Yes" ;
    }
    else{
        cout << "No";
    }


    return 0;
}

Measured memory_bytes: 256
import scala.io.{StdIn => in}
import scala.collection.{mutable => mu}
// import java.util.ArrayDeque

object Main extends App {
  val n = in.readInt

  case class edge(v:Int, d:Int)
  val tree = Array.fill(n)(mu.ListBuffer.empty[edge])

  Iterator.continually(in.readLine)
    .take(n-1)
    .map(_.split(" ").map(_.toInt))
    .foreach { case Array(v, u, d) =>
      new edge(u-1, d) +=: tree(v-1)
      new edge(v-1, d) +=: tree(u-1)
    }

  val colors = Array.ofDim[Int](n)
  val visit = Array.ofDim[Boolean](n)

  def dfs(v:Int, d:Int):Unit = {
    val stk = mu.Stack.empty[edge]
    // val stk = new ArrayDeque[edge]
    stk.push(new edge(v, d))

    while(!stk.isEmpty) {
      val v = stk.pop
      if(!visit(v.v)) {
        visit(v.v) = true
        colors(v.v) = v.d
        for(nv <- tree(v.v) if !visit(nv.v)){
          val d = (v.d + nv.d) % 2
          stk.push(new edge(nv.v, d))
        }
      }
    }
  }

  dfs(0,0)
  // println(colors.mkString("\n"))
  val out = new java.io.PrintWriter(System.out)
  colors.foreach(out.println)
  out.flush
}

Measured memory_bytes: 80324
#include<cstdio>
#include<algorithm> 
#include<cstring>
#define LL long long
using namespace std;
const int N=5e5+5; 
int n;
char s[N];
bool flag;
int read()
{
	int x=0,f=1;char c=getchar();
	while(c<'0'||c>'9'){if(c=='-')f=-1;c=getchar();}
	while(c>='0'&&c<='9'){x=x*10+c-'0';c=getchar();}
	return x*f;
}
int main()
{
	scanf("%s",s);n=strlen(s);
	for(int i=0;i<n;i++)if(s[i]!='0')flag=true;
	if(!flag){printf("%d",n);return 0;}
	for(int i=n/2+(n&1);i<n;i++)
		if(s[i]!=s[n-i-1]||s[i]!=s[i-1])
			{printf("%d",i);return 0;} 
	printf("%d",n);
	return 0;
}

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

int main() {
    int height[10];
    for (int i = 0; i < 10; ++i) cin >> height[i];
    sort(height, height + 10, greater<int>());

    cout << height[0] << endl << height[1] << endl << height[2] << endl;
    
    return 0;
}


Measured memory_bytes: 3116
num = gets.to_i
array = []
lcm_array = []
num.times do |i|
  array.push gets.split(" ").map!{|i|i.to_i}
end
array.reverse!
count = 0
bef_count = 0
array.each do |row|
  row[0] += bef_count
  if row[0] == 0
    next
  elsif row[0] < row[1]
    count += row[1] - row[0]
    bef_count += row[1] - row[0]
  elsif row[0] % row[1] == 0
    next
  else
    count += row[1] * (row[0] / row[1] + 1) - row[0]
    bef_count += row[1] * (row[0] / row[1] + 1) - row[0]
  end
end
puts count

Measured memory_bytes: 9596
#include <bits/stdc++.h>
using namespace std;
int main()
{
  long long X, Y;
  cin >> X >> Y;
  long long A = X;
  long long ans = 0;
  while(A <= Y)
  {
    A *= 2;
    ++ans;
  }
  cout << ans << endl;
  return 0;
}

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

    public static void main(String args[]){
        Scanner scanner = new Scanner(System.in);
        int H = scanner.nextInt();
        int W = scanner.nextInt();
        int K = scanner.nextInt();
        String[] S = new String[H];
        for (int i = 0; i < H; i++) {
            S[i] = scanner.next();
        }
        int ans = Integer.MAX_VALUE;
        for(int div=0; div<(1<<(H-1)); div++){
            int g = 0;
            int[] id = new int[H];
            for(int i=0; i<H; i++){
                id[i] = g;
                if(((div>>i)&1) == 1){
                    g++;
                }
            }
            g++;
            int[][] c = new int[g][W];
            for(int i=0; i<H; i++){
                for(int j=0; j<W; j++){
                    c[id[i]][j] += (S[i].charAt(j) - '0'); 
                }
            }
            
            int num = g-1;
            int[] now = new int[g];
            for(int i=0; i<W; i++){
                boolean isok = true;
                for(int j=0; j<g; j++){
                    if(now[j] + c[j][i] > K){
                        isok = false;
                    }
                }
                if(!isok){
                    num++;
                    now = new int[g];
                }
                for (int j = 0; j < g ; j++) {
                    now[j] += c[j][i];
                    if(now[j] > K){
                        num = Integer.MAX_VALUE;
                        break;
                    }
                }
            }
            ans = Math.min(ans,num);
        }
        System.out.println(ans);
    }
}

Measured memory_bytes: 42296
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int a, b;
  cin >> a >> b;
  if(a%2 == 0){
    cout << "Even" << endl;
  }else if(b%2 == 0){
    cout << "Even" << endl;
  }else{
    cout << "Odd" << endl;
  }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for (ll i = 0; i < (n); ++i)
#define All(v) (v).begin(),(v).end()
#define rall(v) (v).rbegin(),(v).rend()   //reverse
#define strall(v) (v).cbegin(),(v).cend() //const_itterator
#define IN(a, b, x) (a<=x&&x<b)
using namespace std;
using ll = long long;
using P = pair<int,int>;
using Graph = vector<vector<ll>>;
template<typename T> using min_priority_queue = priority_queue<T, vector<T>, greater<T>>;
template<typename t, typename u, typename Comp=less<>>
bool chmax(t& xmax, const u& x, Comp comp={}) { if(comp(xmax, x)) { xmax = x; return true; } return false;}
template<typename t, typename u, typename Comp=less<>>
bool chmin(t& xmin, const u& x, Comp comp={}) { if(comp(x, xmin)) { xmin = x; return true;} return false;}
const int INF = 1e9;
const ll infl = ll(1e18)+5;
/*
*ios::sync_with_stdio(false);
*cin.tie(0);
*/

int main(){
  ll N,M;cin >> N >> M;
  ll ans = 0;
  if(N >= (M/2)) ans = M/2;
  else{
    ans+=N;
    M-=2*N;
    ans+=((ll)M/4);
  } 
  cout << ans << endl;
}

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

int main(){
  string s, t;
  cin >> s >> t;
  map<char, vector<int> > mp;
  for ( int i = 0; i < s.length(); i++){
    mp[s[i]].push_back(i+1);
  }

  long long ans, loop = 0;
  int prevIdx, pos;
  for ( int i = 0; i < t.length(); i++){
    if ( mp[t[i]].size() == 0){
      cout << -1 << endl;
      return 0;
    }

    if ( i == 0){ prevIdx = mp[t[i]][0]; continue;}

    pos = upper_bound(mp[t[i]].begin(), mp[t[i]].end(), prevIdx) - mp[t[i]].begin();
    if ( pos < mp[t[i]].size()){
      prevIdx = mp[t[i]][pos];
    } else {
      prevIdx = mp[t[i]][0];
      loop++;
    }
  }

  cout << s.length() * loop +  prevIdx << endl;

  return 0;
}

Measured memory_bytes: 1216
#include <iostream>
using namespace std;
 
int main(){
    int a, b, p, n;
    int ct = 0;
    int err1 = 0, err2 = 0;
    int errIndex1 = -1, errIndex2 = -1;

	cin >> n;

    for(int i=0;i<n;i++){
        cin >> p;
        if(p != i+1){
            ct += 1;

            if(err1 == 0){
                err1 = p;
                errIndex1 = i;
            }
            else{
                err2 = p;
                errIndex2 = i;
            }
        }
                
    }
    
    if(ct == 0){
        cout << "YES" << endl;
        return 0;
    }
        
    if(ct == 2){
        if(err1 == errIndex2+1 && err2 == errIndex1+1){
            cout << "YES" << endl;
            return 0;
        }
    }

    cout << "NO" << endl;
}

Measured memory_bytes: 256
#pragma GCC optimize("O3")
#include<bits/stdc++.h> 
using namespace std;
using ll=long long;
using P=pair<int,int>;
template<class T> using V=vector<T>; 
#define fi first
#define se second
#define all(v) (v).begin(),(v).end()
const ll inf=(1e18);
const ll mod=1000000007;
ll gcd(ll a,ll b) {return b ? gcd(b,a%b):a;}
ll lcm(ll c,ll d){return c/gcd(c,d)*d;}
struct __INIT{__INIT(){cin.tie(0);ios::sync_with_stdio(false);cout<<fixed<<setprecision(15);}} __init;
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 (a>b) { a=b; return 1; } return 0; }
void factorize(ll x){
	for(ll i=2;i*i<=x;i++){
		while(x%i==0){
			x/=i;
            cout<<" "<<i;
		}
	}
	if(x!=1)cout<<" "<<x<<"\n";
    else cout<<"\n";
}
int main(){
    ll n;
    cin>>n;
    cout<<n<<':';
    factorize(n);
}



Measured memory_bytes: 3232
#include <stdio.h>
#include <stdlib.h>

#include <iostream>
#include <iomanip>
#include <sstream>
#include <fstream>
#include <stdint.h>
#include <string.h>

//#define _USE_MATH_DEFINES
//#include <math.h>

#include <vector>
#include <list>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <queue>
#include <stack>
#include <deque>
#include <string>

#include <algorithm>
#include <functional>
#include <bitset>
#include <functional>
#include <chrono>
#include <random>
#define sqr(x) (x) * (x)

typedef unsigned int u32;
typedef int i32;
typedef unsigned long long int u64;
typedef long long int i64;
typedef uint16_t u16;
typedef int16_t i16;
typedef uint8_t u8;
typedef int8_t i8;

using namespace std;
using namespace std::chrono;

const i64 mod = 1000000007ll;
const i64 smod = 998244353ll;
const i64 inf = 10000000000000007ll;

const double eps = 1e-10;


const i64 MAXN = 300004;

i64 n, h;
i64 a[MAXN];

i64 solve(i64 h) {
    if (h == 1) {
        return 1;
    }
    else {
        return 1 + 2 * solve(h / 2);
    }
}

int main(int argc, char* argv[]) {
    ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); cout.precision(15); cout.setf(ios::fixed);
    cin >> h;

    cout << solve(h) << endl;
    return 0;
}

Measured memory_bytes: 256
R,C,K = map(int,input().split())

item = [[0] * (C + 1) for _ in range(R + 1)]
for i in range(K):
    r,c,v = map(int,input().split())
    item[r][c] = v

dp = [[[0]*(C+1) for _ in range(R+1)] for _ in range(4)]

for h in range(R+1):
    for w in range(C+1):
        for k in range(4):
            position = dp[k][h][w]
            if h+1 <= R:
                # 移動先のアイテムを取らない場合
                dp[0][h+1][w] = max(dp[0][h+1][w], position)
                 # 移動先のアイテムを取る場合
                dp[1][h+1][w] = max(dp[1][h+1][w], position+item[h+1][w])
            if w+1 <= C:
                # 移動先のアイテムを取らない場合
                dp[k][h][w+1] = max(dp[k][h][w+1], position)
                # 現在のkが3未満のときのみ, 移動先のアイテムを取ることが可能
                if k < 3:
                    dp[k+1][h][w+1] = max(dp[k+1][h][w+1], position+item[h][w+1])

ans = 0
for k in range(4):
    ans = max(ans, dp[k][-1][-1])

print(ans)

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

int main() {
    int N; // 組数
    int people = 0;
    cin >> N;

    for (int i = 0; i < N; i++) {
        int L;  // 左端席 
        int R;  // 右端席
        cin >> L >> R;

        people += R - L + 1;

    }

    cout << people << endl;

}

Measured memory_bytes: 3540
use std::io;
use std::cmp;
use std::collections::BinaryHeap;
use std::collections::HashMap;
use std::collections::HashSet;
use std::collections::VecDeque;
use std::f64::consts::PI;

fn read_line() -> String {
    let mut buf = String::new();
    io::stdin().read_line(&mut buf).ok();
    buf
}

const dx: [i32; 4] = [-1,0,0,1];
const dy: [i32; 4] = [0,-1,1,0];

fn func(map: &Vec<Vec<bool>>, x: usize, y: usize) -> usize {
    let mut que = VecDeque::new();
    que.push_back((x,y, 0));
    let mut visited = vec![vec![false; map[0].len()]; map.len()];
    let mut ans = 0;

    while !que.is_empty() {
        let tar = que.pop_front().unwrap();
        let tx = tar.0;
        let ty = tar.1;

        if visited[tx][ty] {
            continue;
        }
        ans = cmp::max(tar.2, ans);
        visited[tx][ty] = true;
        for i in 0..4 {
            let nx = (tx as i32 + dx[i]) as usize;
            let ny = (ty as i32 + dy[i]) as usize;
            if !map[nx][ny] {
                que.push_back((nx, ny, tar.2 + 1));
            }
        }
    }
    ans
}


fn main() {
    let line: Vec<usize> = read_line().split_whitespace().map(|s| s.parse().unwrap()).collect();

    let h = line[0];
    let w = line[1];

    let mut map = vec![vec![true; w + 2]; h + 2];
    for i in 0..h {
        let mut s: Vec<char> = read_line().chars().collect();
        for j in 0..w {
            map[i+1][j+1] = match s[j] {
                '.' => false,
                _ => true,
            }
        }
    }

    let mut ans = 0;
    for i in 0..h {
        for j in 0..w {
            if !map[i+1][j+1] {
                ans = cmp::max(ans, func(&map, i+1, j+1));
            }
        }
    }
    println!("{}", ans);
}


Measured memory_bytes: 4352