akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
template<class T,class U> using P = pair<T,U>;
template<class T> using vec = vector<T>;
template<class T> using vvec = vector<vec<T>>;
template<class T> using vvvec = vector<vvec<T>>;

constexpr ll mod = 1e9+7;
struct mint {
    ll x;
    mint(ll x=0):x((x%mod+mod)%mod){}
    
    friend ostream &operator<<(ostream& os,const mint& a){
        return os << a.x;
    }

    friend istream &operator>>(istream& is,mint& a){
        ll t;
        is >> t;
        a = mint(t);
        return (is);
    }

    mint& operator+=(const mint a) {
        if ((x += a.x) >= mod) x -= mod;
        return *this;
    }
    mint& operator-=(const mint a) {
        if ((x += mod-a.x) >= mod) x -= mod;
        return *this;
    }
    mint& operator*=(const mint a) {
        (x *= a.x) %= mod;
        return *this;
    }
    mint operator+(const mint a) const {
        mint res(*this);
        return res+=a;
    }
    mint operator-(const mint a) const {
        mint res(*this);
        return res-=a;
    }
    mint operator*(const mint a) const {
        mint res(*this);
        return res*=a;
    }
    mint pow(ll t) const {
        if (!t) return 1;
        mint a = pow(t>>1);
        a *= a;
        if (t&1) a *= *this;
        return a;
    }
    // for prime mod
    mint inv() const {
        return pow(mod-2);
    }
    mint& operator/=(const mint a) {
        return (*this) *= a.inv();
    }
    mint operator/(const mint a) const {
        mint res(*this);
        return res/=a;
    }
};

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N;
    cin >> N;
    vvec<int> g(N);
    for(int i=0;i<N-1;i++){
        int a,b;
        cin >> a >> b;
        a--; b--;
        g[a].push_back(b);
        g[b].push_back(a);
    }
    vvvec<mint> dp(N,vvec<mint>(2,vec<mint>(N+1,0)));
    vec<mint> matching(N+1,0);
    matching[0] = 1;
    for(ll i=2;i<=N;i+=2) matching[i] = matching[i-2]*(i-1);
    vec<int> s(N,1);
    auto dfs = [&](auto&& self,int cur,int par)->void{
        dp[cur][0][1] = 1;
        vvec<mint> merge(2,vec<mint>(N+1,0));
        for(auto& to:g[cur]) if(to!=par){
            self(self,to,cur);
            for(int i=0;i<=s[cur];i++) for(int j=0;j<=s[to];j++){
                for(int k=0;k<2;k++){
                    for(int l=0;l<2;l++){
                        //cutしない
                        merge[(k+l)&1][i+j] += dp[cur][k][i]*dp[to][l][j];
                        //cutする
                        merge[(k+l+1)&1][i] += dp[cur][k][i]*dp[to][l][j]*matching[j];
                    }
                }
            }
            dp[cur] = merge;
            s[cur] += s[to];
            for(int i=0;i<2;i++) fill(merge[i].begin(),merge[i].end(),0);
        }
    };

    dfs(dfs,0,-1);
    mint ans = 0;
    for(int i=0;i<=N;i++){
        ans += (dp[0][0][i]-dp[0][1][i])*matching[i];
    }
    cout << ans << endl;
}

Measured memory_bytes: 711808
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

using namespace __gnu_pbds;
#define ordered_set tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update>

using namespace std;

#define int long long
#define endl '\n'
#define maxn 100010
const int MOD = 1000000007;

void solve() {
    int k;
    cin >> k;
    string s;
    cin >> s;

    if(s.size() <= k)cout << s;
    else {
        cout << s.substr(0, k);
        cout <<"...";
    }
}

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

    int t = 1;
//    cin >> t;

    while (t--)
        solve();
    return 0;
}


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

int main(void){
   int N,M;
   cin>>N>>M;
   vector<int> a(M),b(M);
   for(int i=0;i<M;i++){
      cin>>a[i]>>b[i];
   }
   map<int,int> result;
   for(int i=0;i<M;i++){
      result[a[i]]++;
      result[b[i]]++;
   }
   for(int i=1;i<=N;i++){
      cout<<result[i]<<endl;
   }
   return 0;
}



Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long
const ll INF = 1e18L+5;
void solve(){
    ll n, W; cin >> n >> W;
    vector<ll> weight(n), value(n);
    int sum_value = 0;

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

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

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

    ll answer = 0;
    for(int i = 0; i <= sum_value; i++){
        if(dp[i] <= W){
            answer = max(answer, (ll) i);
        }
    }

    cout << answer << endl;
}

int main(){
    int t;// cin >> t;
    t = 1;
    while(t--){
        solve();
    }
}

Measured memory_bytes: 1024
# 2020/05/10
# AtCoder Beginner Contest 065 - B

# Input
n = int(input())
a = list()
a.append(0)
for i in range(n):
    a.append(int(input()))

doflg = True
idx = 1
cnt = 1
while(doflg):
    if a[idx] == -1:
        ans = -1
        doflg = False
    elif a[idx] == 2:
        ans = cnt
        doflg = False
    else:
        cnt = cnt + 1
        sav_idx = idx
        idx = a[idx]
        a[sav_idx] = -1

# Output
print(ans)


Measured memory_bytes: 7084
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
#define ll  long long
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define vi vector<int>
#define br cout <<"\n";
#define all(x)  (x).begin(),(x).end()
#define tr(c,i) for(auto i : c)
#define pii pair< int,int >
#define Fast_IO() ios_base::sync_with_stdio(false);cin.tie(nullptr)
#define pq priority_queue< pair<ll,pii> ,vector<pair<ll,pii>>,greater <pair<ll,pii>> >p;//container adapter makes ascending q
#define er(x) cout << x << " "
#define err(x,y) cout << x << " "<<y
using namespace std;
clock_t time_p = clock();
void dem()
{

        time_p=clock()-time_p;
        cerr<<"Time Taken : "<<(float)(time_p)/CLOCKS_PER_SEC<<"\n";
}
using namespace std ;
const ll MAX =  1000 * 1000 ;
const int dx[] = { 1, -1 , 0 , 0  };
const int dy [] = { 0 ,0 , 1 , -1  };
const int MOD = 1000 * 1000 * 1000 + 9 ;
const int N = 301 ;
const int INF = INT_MAX ;
const int M = 200005;
const double EPS = 1e-9 ;

int main (){
  ll r ;
  cin >> r ;
   cout << (1ll* r * r ) ;



    return 0 ;
}




Measured memory_bytes: 256
a,b,m = map(int,input().split())
A = list(map(int,input().split()))
B = list(map(int,input().split()))
ans = []
l = min(A)+min(B)
ans.append(l)
for i in range(m):
    x,y,c = map(int,input().split())
    p = A[x-1] + B[y-1] - c
    ans.append(p)
print(min(ans))

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

using namespace std;

int main() {
#ifdef LOCAL
  freopen("input.txt", "r", stdin);
#endif
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n;
  cin >> n;
  vector<int> x(n), y(n);
  bool type;
  for (int i = 0; i < n; ++i) {
    cin >> x[i] >> y[i];
    bool odd = (x[i] + y[i]) & 1;
    if (!i) {
      type = odd;
    } else if (type != odd) {
      cout << -1 << "\n";
      return 0;
    }
  }
  if (!type) {
    for (int i = 0; i < n; ++i) {
      ++x[i];
    }
  }
  vector<int> d(31);
  for (int i = 0; i < 31; ++i) {
    d[i] = 1 << i;
  }
  vector<string> ans(n, string(31, '.'));
  for (int i = 0; i < n; ++i) {
    for (int j = 30; ~j; --j) {
      if (abs(x[i] + d[j]) < (1 << j) - abs(y[i])) {
        ans[i][j] = 'L';
        x[i] += d[j];
      } else if (abs(x[i] - d[j]) < (1 << j) - abs(y[i])) {
        ans[i][j] = 'R';
        x[i] -= d[j];
      } else if (abs(y[i] + d[j]) < (1 << j) - abs(x[i])) {
        ans[i][j] = 'D';
        y[i] += d[j];
      } else {
        ans[i][j] = 'U';
        y[i] -= d[j];
      }
    }
  }
  if (!type) {
    d.push_back(1);
    for (int i = 0; i < n; ++i) {
      ans[i].push_back('L');
    }
  }
  cout << d.size() << "\n";
  for (int i = 0; i < (int) d.size(); ++i) {
    if (i) {
      cout << " ";
    }
    cout << d[i];
  }
  cout << "\n";
  for (int i = 0; i < n; ++i) {
    cout << ans[i] << "\n";
  }
  return 0;
}


Measured memory_bytes: 384
#include<stdio.h>

#define SIZE 100001

int main(){
    int a, b;
    scanf("%d", &a);
    scanf("%d", &b);

    printf("%d\n", a+b/2);


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

    return 0;
}


Measured memory_bytes: 128
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <map>
#include <list>
#include <utility>
#include <tuple>
#include <cstdio>
#include <set>
#include <queue>
#include <stack>
#include <deque>
#include <unordered_map>
#include <unordered_set>
#include <bitset>
#include <cctype>
#include <cmath>
#include <limits>
#include <iomanip>
#define _GLIBCXX_DEBUG
#define rep(i,n) for(int i=0;i<(n);++i)
using namespace std;
const long long INF = 1LL << 60;
typedef long long ll;
int main() {
    int N;
    cin >> N;
    vector<int> A(N);
    for(int i=0;i<N;i++){
        cin >> A[i];
    }
    sort(A.begin(),A.end());
    int cnt=0;
    int num=0;
    for(int i=0;i<N;i++){
        if(i!=0){
            if(A[i-1]!=A[i]){
                if(num%2==1){
                    cnt++;
                    num=1;
                }
                else{
                    num=1;
                }
            }
            else{
                num++;
            }
        }
        else{
            num=1;
        }
    }
    if(num%2==1){
        cnt++;
    }
    cout<< cnt<< endl;

}

Measured memory_bytes: 3748
#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()

using namespace std;
typedef long long int ll;
typedef vector<ll> llvec;
typedef vector<double> dvec;
typedef pair<int, int> P;


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);
}

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;
}

vector<int> fact(int n){
  vector<int> ans;
  rep(i, sqrt(n)+1){
    if(n%i==0){
      ans.push_back(i);
    }
  }
  return ans;
}

int N;
int a[300000];
int answer[300000];
int cum[300000];

/******************************************
** A main function is start from here  ****
*******************************************/
int main(){
  cin >> N;
  rep(i, N){
    cin >> a[i+1];
  }
  
  int M=0;
  for(int n=N;n>=1;n--){
    if(cum[n]==a[n]){//already satisfied
      answer[n]=0;//do nothing
    }else{//unsatisfied
      answer[n]=1;//put a ball
      M++;
      for(int i=1;i<=sqrt(n)&& i<n; i++){
        if(n%i==0){
          //cout << i  << " ";
          cum[i]+=1;
          cum[i]=cum[i]%2;
          if(n/i!=i){
            cum[n/i] +=1;
            cum[n/i] %=2;
          }
        }
      }
      //cout << endl;
    }
    //cout << "n="<<n << " cum[n]=" << cum[n] << " answer[n]=" << answer[n] << endl;
  }
  //cout << endl;
  cout << M << endl;
  rep(ii, N){
    int i=ii+1;
    if(answer[i]==1){
      cout << i << " ";
    }
  }
  
  return 0;
}


Measured memory_bytes: 3200
#include <bits/stdc++.h>
using namespace std;
#define ll          long long int
#define pb          push_back
#define pll         pair<ll,ll>
#define speed_up    ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define mod         1000000007
#define inf         1000000000000000000LL
#define vl          vector<ll>
#define F           first
#define S           second
#define ld          long double
#define sz(x)       (ll)x.size()
#define fix(n)      cout<<fixed<<setprecision(n)
#define rep(i,a,b)  for(ll i=a;i<b;i++)
#define all(x)      x.begin(),x.end()
#define pi          3.14159265358979323



void solve()
{
       ll a,p;
       cin>>a>>p;
       ll n=3*a+p;
       ll an = n/2;
       cout<<an<<endl;
}

int main()
{
       speed_up;
       //pre();
       ll T=1;
       //cin>>T;
       while(T--) solve();
	return 0;
}


Measured memory_bytes: 256
#include <string>
#include <algorithm>
#include <stdio.h>
#include <vector>
#include <math.h>
using namespace std;

int main(void) {
	int n, d, tmp, sum, cnt = 0;
	vector<int> D;

	scanf("%d%d", &n, &d);
	

	for (int i = 0; i < n; i++) {
		for (int j = 0; j < d; j++) {
			scanf("%d",&tmp);
			D.push_back(tmp);
		}
	}
	
	for (int i = 0; i < n -1; i++) {
		for (int j = i + 1; j < n; j++) {
			sum = 0;
			for (int k = 0; k < d; k++) {
				tmp = D.at(i*d+k) - D.at((j*d)+k);
				sum += (tmp * tmp);
			}
			double t = sqrt((double)sum);
			if (ceil(t) == floor(t)) {
				cnt++;
			}
		}
	}

	printf("%d", cnt);

	return 0;
}

Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main(){
        unsigned int N;
        cin>>N;
        unsigned long long int a;
        unsigned long long int re = 0;
        for (int i=0;i<N;i++){
                cin>>a;
                while(a%2==0){
                        a/=2;
                        re++;
                }
        }
        cout<<re<<endl;
        return 0;
}

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

int main() {
  int A,B,C;
  cin >> A >> B >> C;
  int count = 0;
  for(int i = 1;i < 101;i++){
    if(i * C >= A && i * C <= B){
      count++;
    }
  }
  cout << count << endl;
    
}


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

#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
typedef long long ll;
using p = pair<int, int>;

    int main(){
        int n;
        std::cin >> n;
        map<string, int> mp;
        rep(i, n){
            string s;
            std::cin >> s;
            mp[s]++;
        }
        int mx = 0;
        for(auto p : mp) mx = max(mx, p.second);
        for(auto p : mp) {
            if (p.second != mx) continue;
            std::cout << p.first << "\n";/* code */
        }
        return 0;
    }
    


Measured memory_bytes: 25216
#include<bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i=0; i<n; i++)
#define rep1(i, n) for(int i=1; i<=n; i++)
#define repr(i, n) for(int i=n-1; i>=0; i--)
#define repr1(i, n) for(int i=n; i>=1; i--)
#define all(v) v.begin(),v.end()
using ll = long long;
using pii = pair<int, int>;
using pil = pair<int, ll>;
using pli = pair<ll, int>;
using pll = pair<ll, ll>;
const int INF = 1e9;
const ll LLINF = 1e18;
const ll MOD = 1e9+7;
const double EPS = 1e-10;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

int main() {
    int n, m; cin >> n >> m;
    int a = n * (n-1) / 2;
    int b = m * (m-1) / 2;
    cout << a+b << endl;
}


Measured memory_bytes: 764
import java.io.IOException;
import java.util.*;

/**
 */
class Main {
	final static int N = 10;
	public static void main(String[] args) throws IOException {
		Scanner in = new Scanner(System.in);

		int[][] paper = new int[N][N];
		while(in.hasNext()) {
			String str = in.nextLine();
			String[] split = str.split(",");
			int x = Integer.parseInt(""+split[0]);
			int y = Integer.parseInt(""+split[1]);
			int s = Integer.parseInt(""+split[2]);

			switch (s) {
				case 1:
					fillSmall(paper, x, y);
					break;
				case 2:
					fillMid(paper, x, y);
					break;
				case 3:
					fillLarge(paper, x, y);
					break;
				default:
					if (!false) throw new AssertionError();
			}
		}

		int numOfZero = 0;
		int maxVal = 0;
		for(int i=0;i<N;i++) {
			for(int j=0;j<N;j++) {
				if(paper[i][j] == 0) {
					numOfZero++;
				}
				maxVal = Math.max(maxVal, paper[i][j]);
			}
		}
		System.out.println(numOfZero);
		System.out.println(maxVal);
	}

	public static boolean checkOk(int x, int y) {
		return (0 <= x && x < N && 0 <= y && y < N);
	}

	public static void fillSmall(int[][] paper, int cx, int cy) {
		int[] tx = {0,-1,0,1,0};
		int[] ty = {-1,0,0,0,1};
		for(int i=0;i<5;i++) {
			int x = cx + tx[i];
			int y = cy + ty[i];
			if(checkOk(x, y) == false) continue;
			paper[x][y] += 1;
		}
	}

	public static void fillMid(int[][] paper, int cx, int cy) {
		for(int i=0;i<3;i++) {
			for(int j=0;j<3;j++) {
				int x = (cx - 1) + j;
				int y = (cy - 1) + i;
				if(checkOk(x,y) == false) continue;
				paper[x][y] += 1;
			}
		}
	}

	public static void fillLarge(int[][] paper, int cx, int cy) {
		int[] tx =
			{0,
				-1,0,1,
				-2,-1,0,1,2,
				-1,0,1,
				0};
		int[] ty =
				{
						-2,
						-1,-1,-1,
						0,0,0,0,0,
						1,1,1,
						2
				};
		for(int i=0;i<13;i++) {
			int x = cx + tx[i];
			int y = cy + ty[i];
			if(checkOk(x,y) == false) continue;
			paper[x][y] += 1;
		}
	}
}

Measured memory_bytes: 26244
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <queue>
#include <cstring>
#include <vector>
#include <map>
#include <algorithm>
#include <cctype>
#include <cmath>
#include <bitset>
#include <set>
#include <cassert>
using namespace std;

#define REP(i,n) for(int i=0;i<(int)(n);i++)
#define RREP(i,n) for(int i=n-1;i>=0;i--)
#define FOR(i,k,n) for(int i=(k);i<(int)(n);i++)
#define all(i,n) (i),(i+n)

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

typedef pair<int, int> P;
typedef pair<string, int> SP;
typedef long long ll;
typedef pair<ll, ll> PLL;

const int INF = 1e9;
const ll LLINF = 1e18;
const int MAX_V = 1e6+1;
// const ll mod = 1000000007;

// auto mod int
// https://youtu.be/L8grWxBlIZ4?t=9858
// https://youtu.be/ERZuLAxZffQ?t=4807 : optimize
// https://youtu.be/8uowVvQ_-Mo?t=1329 : division
const int mod = 998244353;
struct mint {
  ll x; // typedef long long ll;
  mint(ll x=0):x((x%mod+mod)%mod){}
  mint operator-() const { return mint(-x);}
  mint& operator+=(const mint a) {
    if ((x += a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator-=(const mint a) {
    if ((x += mod-a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator*=(const mint a) { (x *= a.x) %= mod; return *this;}
  mint operator+(const mint a) const { return mint(*this) += a;}
  mint operator-(const mint a) const { return mint(*this) -= a;}
  mint operator*(const mint a) const { return mint(*this) *= a;}
  mint pow(ll t) const {
    if (!t) return 1;
    mint a = pow(t>>1);
    a *= a;
    if (t&1) a *= *this;
    return a;
  }

  // for prime mod
  mint inv() const { return pow(mod-2);}
  mint& operator/=(const mint a) { return *this *= a.inv();}
  mint operator/(const mint a) const { return mint(*this) /= a;}
};
istream& operator>>(istream& is, const mint& a) { return is >> a.x;}
ostream& operator<<(ostream& os, const mint& a) { return os << a.x;}
struct combination {
  vector<mint> fact, ifact;
  combination(int n):fact(n+1),ifact(n+1) {
    assert(n < mod);
    fact[0] = 1;
    for (int i = 1; i <= n; ++i) fact[i] = fact[i-1]*i;
    ifact[n] = fact[n].inv();
    for (int i = n; i >= 1; --i) ifact[i-1] = ifact[i]*i;
  }
  mint operator()(int n, int k) {
    if (k < 0 || k > n) return 0;
    return fact[n]*ifact[k]*ifact[n-k];
  }
} c(200005);
// --------------------------------------
int n, m, k;
int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);

  cin >> n >> m >> k;
  mint ans = 0;
  mint col = m;
  RREP(i, n) {
    mint now = col;
    now *= c(n - 1, i);
    if(i <= k) ans += now;
    col *= m - 1;
  }

  cout << ans << endl;
}


Measured memory_bytes: 6184
#include <iostream>

int main() {
  int K, N, i;
  std::cin >> K >> N;
  
  int A[N], d = 0;
  for (i = 0; i < N; i++) {
    std::cin >> A[i];
  }
  
  for (i = 0; i < N-1; i++) {
    if (d < A[i+1] - A[i]) {
      d = A[i+1] - A[i];
    }
  }
  
  if (d < K + A[0] - A[N-1]) {
    d = K + A[0] - A[N-1];
  }
  
  std::cout << K-d << std::endl;
}

Measured memory_bytes: 1024
from sys import stdin
import math

n, k = [int(x) for x in stdin.readline().rstrip().split()]
h = [int(x) for x in stdin.readline().rstrip().split()]

list.sort(h, reverse=True)

cnt = 0
for i in h:
    if k > 0:
        k -= 1
        continue
    cnt += i

print(cnt)

Measured memory_bytes: 25740
#include<iostream>
#include<cstring>
using namespace std;
using ll = long long;

int main (){
    int x,y;
    cin >> x >> y;
    for (int i = 0; i <= x; i++){
        for (int j = 0; j <= x; j++){
            if (2 * i + 4 * j == y && i + j == x){
                cout << "Yes" << endl;
                return 0;
            }
        }
    }
    cout << "No" << endl;
    return 0;
}

Measured memory_bytes: 3132
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef unsigned int uint;
typedef unsigned char uchar;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;

#define REP(i,x) for(int i=0;i<(int)(x);i++)
#define REPS(i,x) for(int i=1;i<=(int)(x);i++)
#define RREP(i,x) for(int i=((int)(x)-1);i>=0;i--)
#define RREPS(i,x) for(int i=((int)(x));i>0;i--)
#define FOR(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();i++)
#define RFOR(i,c) for(__typeof((c).rbegin())i=(c).rbegin();i!=(c).rend();i++)
#define ALL(container) (container).begin(), (container).end()
#define RALL(container) (container).rbegin(), (container).rend()
#define SZ(container) ((int)container.size())
#define mp(a,b) make_pair(a, b)
#define pb push_back
#define eb emplace_back
#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() );
#define __builtin_popcount __builtin_popcountll

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; }
template<class T> ostream& operator<<(ostream &os, const vector<T> &t) {
    os<<"["; FOR(it,t) {if(it!=t.begin()) os<<","; os<<*it;} os<<"]"; return os;
}
template<class T> ostream& operator<<(ostream &os, const set<T> &t) {
    os<<"{"; FOR(it,t) {if(it!=t.begin()) os<<","; os<<*it;} os<<"}"; return os;
}
template<class S, class T> ostream& operator<<(ostream &os, const map<S, T> &t) {
    os<<"{"; FOR(it,t) {if(it!=t.begin()) os<<","; os<<*it;} os<<"}"; return os;
}
template<class S, class T> ostream& operator<<(ostream &os, const pair<S,T> &t) { return os<<"("<<t.first<<","<<t.second<<")";}
template<class S, class T> pair<S,T> operator+(const pair<S,T> &s, const pair<S,T> &t){ return pair<S,T>(s.first+t.first, s.second+t.second);}
template<class S, class T> pair<S,T> operator-(const pair<S,T> &s, const pair<S,T> &t){ return pair<S,T>(s.first-t.first, s.second-t.second);}

const int INF = 1<<28;
const double EPS = 1e-8;
const int MOD = 1000000007;


int T, n, m;
ll dp[401][401];
int main(int argc, char *argv[]){
    ios::sync_with_stdio(false);
    while(cin >> n){
        vi a(n);
        vector<ll> v(n + 1);
        vector<vector<ll>> dp(n + 1, vector<ll>(n + 1, 1ll << 60));
        REP(i, n) {
            cin >> v[i + 1];
            dp[i][i + 1] = 0;
            v[i + 1] += v[i];
        }
        for (int w = 2;w <= n; w ++) {
            for (int l = 0; l + w <= n; l ++) {
                int r = l + w;
                for (int m = l + 1; m < r; m ++) {
                    chmin(dp[l][r], (dp[l][m] + dp[m][r]) + v[r] - v[l]);
                }
            }
        }
        cout << dp[0][n] << endl;
    }
    return 0;
}


Measured memory_bytes: 1664
#include <bits/stdc++.h>
using namespace std;
#define mod 1000000007
#define N 100005
#define ll long long
#define ull unsigned long long
#define loop1(i, j, k, step) for (int i = j; i < k; i += step)
#define loop(i, j, k) for (int i = j; i < k; i++)
#define rloop1(i, j, k, step) for (int i = j; i >= k; i -= step)
#define rloop(i, j, k) for (int i = j; i >= k; i--)
#define rep(i, k) for (int i = (0); i < (k); i++)
#define rrep(i, k) for (int i = k - 1; i >= 0; i--)
#define forall(it, l) for (auto it = l.begin(); it != l.end(); it++)
#define mp make_pair
#define pb push_back
#define pop pop_back
#define F first
#define S second
#define sz(x) (int)(x).size()
#define lin "\n"
#define Max (int)INT_MAX
#define Min (int)INT_MIN
#define MEM(a, b) memset(a, (b), sizeof(a))
#define fast_io ios_base::sync_with_stdio(0), cin.tie(NULL), cout.tie(0)
#define PI 2 * acos(0.0)
typedef vector<int> vi;
typedef pair<int, int> pi;
typedef vector<ll> vl;
typedef pair<ll, ll> pll;
// vector<pair<int, int>> v;
// bool sortinrev(const pair<int, int> &a,
//                const pair<int, int> &b)
// {
//     return (a.second < b.second);
// }

void solve()
{
    int n, m;
    cin >> n >> m;
    cout << (n * (n - 1) / 2) + (m * (m - 1) / 2) << lin;
}

int main()
{
    auto start = clock();
    fast_io;
    //freopen("test.txt", "r", stdin);
    int t;
    t = 1;
    // cin >> t;
    while (t--)
    {
        solve();
    }
    auto stop = clock();
    cerr << "time taken:" << double(stop - start) / double(CLOCKS_PER_SEC) << " s" << endl;
    return 0;
}


Measured memory_bytes: 256
program agc014
      implicit none
      integer(8)::a,b,c
      integer(8)::aa,bb,cc
      integer(8)::count
      
         read *, a,b,c
         
         if (a==b .and. b==c .and. c==a) then
            if (mod(a,2)==0) then
               print *, '-1'
            else
               print *, '0'
            end if
            stop
         end if
            
         aa=a;bb=b;cc=c
         count=0
         do while (mod(a,2)==0 .and. mod(b,2)==0 .and. mod(c,2)==0)
            a=a+bb/2+cc/2
            b=b+cc/2+aa/2
            c=c+aa/2+bb/2
            count=count+1
            aa=a;bb=b;cc=c
         end do
         
         print *, count

   end program agc014


Measured memory_bytes: 256
from collections import defaultdict, deque, Counter
from heapq import heappush, heappop, heapify
import math
import bisect
import random
from itertools import permutations, accumulate, combinations, product
import sys
import string
from bisect import bisect_left, bisect_right
from math import factorial, ceil, floor
from operator import mul
from functools import reduce


INF = float('inf')
def LI(): return list(map(int, sys.stdin.readline().split()))
def I(): return int(sys.stdin.readline())
def LS(): return sys.stdin.readline().split()
def S(): return sys.stdin.readline().strip()
def IR(n): return [I() for i in range(n)]
def LIR(n): return [LI() for i in range(n)]
def SR(n): return [S() for i in range(n)]
def LSR(n): return [LS() for i in range(n)]
def SRL(n): return [list(S()) for i in range(n)]
def MSRL(n): return [[int(j) for j in list(S())] for i in range(n)]
mod = 1000000007


def gcd(a, b):
    while b:
        a, b = b, a % b
    return a




class SegmentTree:
    def __init__(self, init_val, ide_ele, op):
        n = len(init_val)
        self.num = 2 ** (n - 1).bit_length()
        self.seg = [ide_ele] * 2 * self.num
        self.ide_ele = ide_ele
        self.op = op
        for i in range(n):
            self.seg[i + self.num - 1] = init_val[i]
            # built
        for i in range(self.num - 2, -1, -1):
            self.seg[i] = self.op(self.seg[2 * i + 1], self.seg[2 * i + 2])


    def update(self, k, x):
        k += self.num - 1
        self.seg[k] = x
        while k + 1:
            k = (k - 1) // 2
            self.seg[k] = self.op(self.seg[k * 2 + 1], self.seg[k * 2 + 2])


    def query(self, p, q):
        if q <= p:
            return self.ide_ele
        p += self.num - 1
        q += self.num - 2
        res = self.ide_ele
        while q - p > 1:
            if p & 1 == 0:
                res = self.op(res, self.seg[p])
            if q & 1 == 1:
                res = self.op(res, self.seg[q])
            p = p // 2
            q = (q - 2) // 2
        if p == q:
            res = self.op(res, self.seg[p])
        else:
            res = self.op(self.seg[p], self.op(res, self.seg[q]))
        return res



n = I()
L = LI()
ST = SegmentTree(L, 0, gcd)
print(max([gcd(ST.query(0, i), ST.query(i + 1, n)) for i in range(n)]))

Measured memory_bytes: 68068
def triangle():
    # 直角三角形の成立条件
    if length[0]**2 == length[1]**2 + length[2]**2:
        n[0] += 1; n[1] += 1
    # 鋭角三角形の成立条件
    elif length[0]**2 < length[1]**2 + length[2]**2:
        n[0] += 1; n[2] += 1
    # 鈍角三角形の成立条件
    elif length[0]**2 > length[1]**2 + length[2]**2:
        n[0] += 1; n[3] += 1
    
    return n

def print_n():
    for i, num in enumerate(n):
        if i == len(n) - 1:
            print(num)
        else:
            print(num, end=' ')

n = [0, 0, 0, 0]
while True:
    length = sorted(list(map(int, input().split())), reverse=True)
    # 三角形の成立条件
    if length[0] < length[1] + length[2]\
    and length[1] < length[0] + length[2]\
    and length[2] < length[1] + length[0]:
        n = triangle()
    else:
        break
print_n()



Measured memory_bytes: 5608
#include<cstdio>
#include<iostream>
#include<algorithm>
#include<vector>
#include<set>
#include<map>
#include<string>
#include<functional>
#include<queue>
#include<stack>
#include<math.h>
#define INF 1000000001
#define EPS 1.0e-6

using namespace std;

typedef long long ll;

int a, b, c, d, e;

int main()
{
	cin >> a >> b >> c >> d >> e;

	int kokugo, sansu;
	if (b%d == 0)kokugo = b / d;
	else kokugo = b / d + 1;
	if (c%e == 0)sansu = c / e;
	else sansu = c / e + 1;

	int shukudai = max(kokugo, sansu);

	if (a > shukudai)cout << a - shukudai << endl;
	else cout << 0 << endl;

	return 0;
}

Measured memory_bytes: 3084
#include<cstdio>    
#include<cstring>    
#include<algorithm>    
#include<iostream>  
#include<cmath>  
#include<map>  
#include<queue>  
using namespace std;    
struct node  
{  
    int mp[2][4];  
    int dis;  
    int x,y;  
}f,t;  
int FLAG;  
int dx[]={-1,1,0,0};  
int dy[]={0,0,-1,1};  
bool isok(int x,int y)  
{  
    return x>=0&&x<2&&y>=0&&y<4;  
}  
int ca[]={1,1,2,6,24,120,720,5040,40320,362880};   
int ANS[1000007];  
int cantor(node &t)    
{    
    int sum=0,cnt=0;    
    int s[9];  
    for(int i=0;i<2;i++)  
    {  
        for(int j=0;j<4;j++)  
        {  
            s[cnt++]=t.mp[i][j];  
        }  
    }  
    for(int i=0;i<8;i++)    
    {    
     int num=0;    
        for(int j=i+1;j<8;j++)    
          if(s[j]<s[i]) num++;    
        sum+=(num*ca[8-i-1]);    
    }    
    return sum+1;    
}    
const int MAXN=1000007;  
int Hash[MAXN];  
const int END=1;  
bool HashInsert(int value,int dis)  //就是?里 ，无?它  
{  
      int v=value%MAXN;  
      while(Hash[v]!=-1&&Hash[v]!=value){  
          v+=10;  
          v%=MAXN;  
      }  
      if(Hash[v]==-1){  
          ANS[v]=dis;  
          Hash[v]=value;  
         return true;  
      }  
      return false;  
  }  
bool isvis(node &t,int dis)  
{  
    int val=cantor(t);  
    if(val==END) FLAG=1;  
    return HashInsert(val,dis);  
}  
bool over(node &t)  
{  
    int cro=0;  
    for(int i=0;i<2;i++)  
    {  
        for(int j=0;j<4;j++)  
        {  
            if(t.mp[i][j]!=cro) return false;  
            cro++;  
        }  
    }  
    return true;  
}  
void bfs()  
{  
    FLAG=0;  
      
    queue<node> q;  
    q.push(f);  
    while(!q.empty())  
    {  
        f=q.front();q.pop();  
        for(int d=0;d<4;d++)  
        {  
            t=f;  
            t.x=f.x+dx[d];  
            t.y=f.y+dy[d];  
            if(isok(t.x,t.y))  
            {  
                t.dis++;  
                swap(t.mp[f.x][f.y],t.mp[t.x][t.y]);  
                if(isvis(t,t.dis))  //??   
                {  
                    q.push(t);  
                }  
            }  
        }  
    }  
}  
int main()  
{memset(Hash,-1,sizeof(Hash));  
    f.dis=0;  
    int cnt=0;  
    for(int i=0;i<2;i++)  
        {  
            for(int j=0;j<4;j++)  
            {  
                f.mp[i][j]=cnt++;  
            }  
        }  
    f.x=0;  
    f.y=0;  
    Hash[1]=1;  
    ANS[1]=0;  
    bfs();  
    while(~scanf("%d",&f.mp[0][0]))  
    {  
        f.dis=0;  
        for(int i=1;i<=3;i++) scanf("%d",&f.mp[0][i]);  
        for(int i=0;i<=3;i++) scanf("%d",&f.mp[1][i]);  
        printf("%d\n",ANS[cantor(f)]);  
    }  
    return 0;  
}  

Measured memory_bytes: 5400
#include<iostream>
#include<string>
#include<unordered_map>
#include<algorithm>
int main(){
    int n,m;
    std::string s;
    std::cin >> n;
    std::unordered_map<std::string,int> mp;
    for(int i=0;i<n;i++){
        std::cin >> s;
        if(mp.count(s)==0)mp[s]=1;
        else mp[s]++;
    }
    std::cin >> m;
    for(int i=0;i<m;i++){
        std::cin >> s;
        if(mp.count(s)==0)mp[s]=-1;
        else mp[s]--;
    }
    int ans=0;
    for(auto itr=mp.begin();itr!=mp.end();itr++){
        ans=std::max(ans,(*itr).second);
    }
    printf("%d",ans);
    return 0;
}

Measured memory_bytes: 256
import math
from functools import reduce
from collections import deque
import sys
sys.setrecursionlimit(10**7)

# スペース区切りの入力を読み込んで数値リストにして返します。
def get_nums_l():
    return [ int(s) for s in input().split(" ")]

# 改行区切りの入力をn行読み込んで数値リストにして返します。
def get_nums_n(n):
    return [ int(input()) for _ in range(n)]

# 改行またはスペース区切りの入力をすべて読み込んでイテレータを返します。
def get_all_int():
    return map(int, open(0).read().split())

def log(*args):
    print("DEBUG:", *args, file=sys.stderr)

dates = ["SUN","MON","TUE","WED","THU","FRI","SAT"]

s = input()

print((7 - dates.index(s)))


Measured memory_bytes: 38384
// N
// d1,d2,d3,d4,d5,,,,,,dn


//inputに入力データ全体が入る
function Main(input) {
	// 1行目がinput[0], 2行目がinput[1], …に入る
	input = input.split("\n");
	
	//文字列から10進数に変換するときはparseIntを使います
	var n = parseInt(input[0], 10);
		

 
   var d=[];
     d = input[1].split(" ").map(Number);   //横並びの数字を配列にする
 
 
//  console.log(d);
  
  tl=0;                                           //2重ループ
  for(i=0;i<n;i++){
   for(j=i+1;j<n;j++){//console.log(d[i],d[j],tl);
                tl = tl+ d[i]*d[j];}
   }
  console.log(tl);
}
//*この行以降は編集しないでください（標準入出力から一度に読み込み、Mainを呼び出します）
Main(require("fs").readFileSync("/dev/stdin", "utf8"));

Measured memory_bytes: 7372
#include<bits/stdc++.h>
using namespace std;
int main(){
int n;
cin>>n;
string s;
vector<int> v(n,0);
for(int i=0;i<n;i++){
cin>>s;
if(s=="AC")
    v[0]++;
else if(s=="WA")
    v[1]++;
else if(s=="TLE")
    v[2]++;
else
    v[3]++;
}

cout<<"AC "<<"x "<<v[0]<<endl;
cout<<"WA "<<"x "<<v[1]<<endl;
cout<<"TLE "<<"x "<<v[2]<<endl;
cout<<"RE "<<"x "<<v[3]<<endl;
return 0;
}


Measured memory_bytes: 3768
#include <sstream>
#include <string>
#include <vector>
#include <map>
#include <algorithm>
#include <iostream>
#include <utility>
#include <set>
#include <cctype>
#include <queue>
#include <stack>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <climits>
using namespace std;
#define INF 100000000
#define MAXH 52
#define MAXW 52

typedef long long ll;
const int dx[] = {1, 0, -1, 0};
const int dy[] = {0, 1, 0, -1};

int w, h;
char field_r[MAXH][MAXW];
char field_l[MAXH][MAXW];

struct state {
    int xl, yl, xr, yr;
};

int main(void) {
    while (1) {
        cin >> w >> h;
        if (w == 0 && h == 0) break;
        vector<string> roomr(h), rooml(h);
        for (int i = 0; i < h; i++) {
            cin >> rooml[i] >> roomr[i];
        }
        int sxl, syl, sxr, syr;
        bool done[MAXH][MAXW][MAXH][MAXW] = {false};
        for (int i = 0; i < h; i++) {
            for (int j = 0; j < w; j++) {
                if (rooml[i][j] == 'L') {
                    sxl = j; syl = i;
                }
                if (roomr[i][j] == 'R') {
                    sxr = j; syr = i;
                }
            }
        }
        state s;
        s.xl = sxl; s.yl = syl; s.xr = sxr; s.yr = syr;
        queue<state> que;
        que.push(s);
        bool ok = false;
        done[sxl][syl][sxr][syr] = true;
        while (!que.empty()) {
            state now = que.front(); que.pop();
            if (rooml[now.yl][now.xl] == '%' && roomr[now.yr][now.xr] == '%') {
                cout << "Yes" << endl;
                ok = true;
                break;
            }
            if (rooml[now.yl][now.xl] == '%' && roomr[now.yr][now.xr] != '%') continue;
            if (rooml[now.yl][now.xl] != '%' && roomr[now.yr][now.xr] == '%') continue;
            for (int i = 0; i < 4; i++) {
                int nxl = now.xl + dx[i];
                int nyl = now.yl + dy[i];
                int nxr = now.xr - dx[i];
                int nyr = now.yr + dy[i];
                if (nxl < 0 || nxl >= w || nyl < 0 || nyl >= h || rooml[nyl][nxl] == '#') {
                    nxl = now.xl; nyl = now.yl;
                }
                if (nxr < 0 || nxr >= w || nyr < 0 || nyr >= h || roomr[nyr][nxr] == '#') {
                    nxr = now.xr; nyr = now.yr;
                }
                if (done[nxl][nyl][nxr][nyr]) continue;
                done[nxl][nyl][nxr][nyr] = true;
                state st;
                st.xl = nxl; st.yl = nyl; st.xr = nxr; st.yr = nyr;
                que.push(st);
            }
        }
        if (!ok) cout << "No" << endl;
    }
    return 0;
}

Measured memory_bytes: 9312
const main = (input) => {
  input = input.trim().split('\n')
  const n = parseInt(input[0], 10)
  const logs = input[1].split(' ').map(Number).sort((a, b) => a - b)

  let ans = 0

  const r = (idx, arr) => {
    if (arr.length === 3) {
      if (arr.length !== Array.from(new Set(arr)).length) return null
      if (arr[2] >= arr[0] + arr[1]) return null

      ans++
      return null
    }

    if (idx > logs.length-1) return null

    r(idx+1, arr)
    r(idx+1, [...arr, logs[idx]])
  }
  r(0, [])

  return console.log(ans)
}

process.env.MYTEST ? test() : main(require('fs').readFileSync('/dev/stdin', 'utf8'))

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

using namespace std;
map<int, bool> q;
int main()
{
    int n, f, cnt=0;
    cin >> n;
    while(n--)
    {
        cin>>f;
        if(f<=399) q[399]=true;
        else if(f<=799) q[799]=true;
        else if(f<=1199) q[1199]=true;
        else if(f<=1599) q[1599]=true;
        else if(f<=1999) q[1999]=true;
        else if(f<=2399) q[2399]=true;
        else if(f<=2799) q[2799]=true;
        else if(f<=3199) q[3199]=true;
        else cnt++;
    }n=q.size();
    printf("%d %d\n",n?n:1,n+cnt);
    return 0;
}


Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
#define ll long long int
#define rep(i,n) for( int i = 0; i < n; i++ )
#define rrep(i,n) for( int i = n; i >= 0; i-- )
#define REP(i,s,t) for( int i = s; i <= t; i++ )
#define RREP(i,s,t) for( int i = s; i >= t; i-- )
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define INF 2000000000
#define mod 1000000007
#define INF2 1000000000000000000


int main(void)
{
    cin.tie(0);
    ios::sync_with_stdio(false);
	string S; cin >> S;
	int ans = 0;
	rep(i, 4) {
		if (S[i] == '+') ans++;
		else ans--;
	}
	cout << ans << endl;

    return 0;
}


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

typedef unsigned long long ull;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<double, double> pdd;
const ull mod = 1e9 + 7;
#define REP(i,n) for(int i=0;i<(int)n;++i)

//debug
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

template<class S, class T> ostream& operator << (ostream& os, const pair<S, T> v){
  os << "(" << v.first << ", " << v.second << ")"; return os;
}
template<class T> ostream& operator << (ostream& os, const vector<T> v){
  for(int i = 0; i < v.size(); i++){if(i > 0){os << " ";} os << v[i];} return os;
}
template<class T> ostream& operator << (ostream& os, const vector<vector<T>> v){
  for(int i = 0; i < v.size(); i++){if(i > 0){os << endl;} os << v[i];} return os;
}

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

    ll N, K;
    cin >> N >> K;
    vector<ll> A(N);
    REP(i, N) cin >> A[i];

    vector<ll> B(N+1, 0);
    REP(i, N) B[i+1] = B[i] + A[i];

    vector<ll> C;
    REP(i, N){
    	for(int j=i+1;j<N+1;j++){
    		C.push_back(B[j]-B[i]);
    	}
    }
    //cout << C << endl;
    ll res = 0;
    for(ll k=60;k>=0;k--){
    	sort(C.begin(), C.end());
    	ll tmp = (1ll << k);
    	ll kosu = C.end() - lower_bound(C.begin(), C.end(), tmp);
    	//dump(tmp)
    	//cout << C << endl;
    	//dump(kosu)
    	if(kosu >= K){
    		res += tmp;
    		REP(j, C.size()){
    			C[j] -= tmp;
    		}
    	}else{
    		REP(j, C.size()){
    			if(C[j] >= tmp) C[j] -= tmp;
    		}
    	}
    }
    cout << res << endl;
    return 0;
}

Measured memory_bytes: 6000
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define per(i, n) for (int i = (int)(n-1); i >= 0; i--)
#define sz(x) int(x.size())
#define all(x) (x).begin(), (x).end()
#define INF 2e9
#define LINF 1e18
template<class T> inline bool chmax(T &a, const T &b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T &a, const T &b) { if (a > b) { a = b; return 1; } return 0; }
typedef long long ll;
typedef pair<int, int> P;

int main() {
    int n, k; cin >> n >> k;
    vector<int> a(n);
    rep(i, n) cin >> a[i];
    int left, right;
    rep(i, n) {
        if (a[i] == 1) {
            left = i;
            right = n-i-1;
        }
    }
    int ans = 0;
    if ((n-1)%(k-1) == 0) ans = (n-1)/(k-1);
    else ans = (n-1)/(k-1) + 1;

    cout << ans << endl;

}


Measured memory_bytes: 640
#include <iostream>
#include <sstream>
#include <string>
#include <algorithm>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <cassert>

using namespace std;

#define FOR(i,k,n) for(int i=(k); i<(int)(n); ++i)
#define REP(i,n) FOR(i,0,n)
#define FORIT(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)

template<class T> void debug(T begin, T end){ for(T i = begin; i != end; ++i) cerr<<*i<<" "; cerr<<endl; }
inline bool valid(int x, int y, int W, int H){ return (x >= 0 && y >= 0 && x < W && y < H); }

typedef long long ll;
const int INF = 100000000;
const double EPS = 1e-8;
const int MOD = 1000000007;
int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};

int main(){
  int T;
  while(cin>>T && T){
    int t[30];
    REP(i, T) cin>>t[i];
    int start[100] = {};
    fill(start, start + 100, 24);
    int N;
    cin>>N;
    REP(i, N){
      int D, M;
      cin>>D>>M;
      start[D - 1] = min(start[D - 1], M);
    }
    int dp[101][30] = {};
    REP(i, 101)REP(j, 30) dp[i][j] = INF;
    dp[0][T - 1] = 0;
    REP(i, 100){
      REP(from, T){
        int to = (from + 1) % T;
        if(t[to] <= start[i]){
          dp[i + 1][to] = min(dp[i + 1][to], dp[i][from]);
        }
        dp[i + 1][0] = min(dp[i + 1][0], dp[i][from] + 1);
      }
    }
    int ans = INF;
    REP(i, T) ans = min(ans, dp[100][i]);
    cout<<ans<<endl;
  }
  return 0;
}

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

//template
#define rep(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define ALL(v) (v).begin(),(v).end()
typedef long long int ll;
const int inf = 0x3fffffff; const ll INF = 0x1fffffffffffffff; const double eps=1e-12;
template<typename T>inline bool chmax(T& a,T b){if(a<b){a=b;return 1;}return 0;}
template<typename T>inline bool chmin(T& a,T b){if(a>b){a=b;return 1;}return 0;}
//end

#include <atcoder/all>
using namespace atcoder;

int main(){
   int n,q; cin>>n>>q;
   dsu uni(n);
   rep(i,0,q){
      int t,u,v; cin>>t>>u>>v;
      if(t)cout<<uni.same(u,v)<<endl;
      else uni.merge(u,v);
   }
   return 0;
}

Measured memory_bytes: 3928
k,s = map(int, input().split())
count = 0
for x in range(k+1):
    for y in range(x, k+1):
        z=s-x-y
        if y <= z <= k:
            if x==y and y==z:
                count += 1
            elif x==y or y==z or z==x:
                count += 3
            else:
                count += 6
        
print(count)
print("\n")



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

int main(){
  long long N; cin >> N;
  if(N==1){
    cout << 0 << endl;
    return 0;
  }
  
  long long d=2;
  map<long long,int> f;
  
  long long NN=N;
  while(d<=sqrt(NN)){
    if(NN%d==0){
      if(f.count(d)==0){
        f[d]=1;
      }else{
        f[d]++;
      }
      NN/=d;
    }else{
      d++;
    }
  }
  if(NN>1){
    if(f.count(NN)==0){
      f[NN]=1;
    }else{
      f[NN]++;
    }
  }
  
  int result=0;
  for(auto k:f){
    int n=k.second;
    int i=1;
    while(i<=n){
      result++;
      n-=i;
      i++;
    }
  }
  cout << result << endl;
}

Measured memory_bytes: 3728
#include <bits/stdc++.h>
using namespace std;
int main(){
  string a,b,c;
  int A,B;
  cin>>a>>b>>c;
  A=a.size()-1;
  B=b.size()-1;
  if(a.at(A)==b.at(0)&&b.at(B)==c.at(0)){
    cout<<"YES"<<endl;
  }else{
    cout<<"NO"<<endl;
  }
}

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

const long long mod = 1e9 + 7;

using ll = long long;
using pii  = pair<int, int>;
using pll = pair<ll, ll>;
#define ull unsigned long long
#define ld long double
#define vi vector<int>
#define vll vector<ll>
#define vc vector<char>
#define vs vector<string>
#define vpii vector<pii>
#define vpll vector<pll>

#define rep(i, n) for (int i = 0, i##_len = (n); i < i##_len; i++)
#define rep1(i, n) for (int i = 1, i##_len = (n); i <= i##_len; i++)
#define repr(i, n) for (int i = ((int)(n)-1); i >= 0; i--)
#define rep1r(i, n) for (int i = ((int)(n)); i >= 1; i--)

#define sz(x) ((int)(x).size())
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()

#define SORT(v, n) sort(v, v + n);
#define VSORT(v) sort(v.begin(), v.end());
#define RSORT(x) sort(rall(x));
#define pb push_back
#define mp make_pair

#define INF (1e9)
#define PI (acos(-1))
#define EPS (1e-7)

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

const string YES = "Yes";
const string NO = "No";

int main(){
    string s;
    cin >> s;
    int n = sz(s);
    map<char, int> cnt;
    rep(i, n) cnt[s[i]]++;
    if (((cnt['N']!=0||cnt['S']!=0)&&!(cnt['N']!=0&&cnt['S']!=0)) || ((cnt['W']!=0||cnt['E']!=0)&&!(cnt['W']!=0&&cnt['E']!=0))) {
        cout << NO << endl;
    }
    else {
        cout << YES << endl;
    }
    return 0;
}


Measured memory_bytes: 3636
from itertools import permutations
n=int(input())
P=list(input().split())
Q=list(input().split())
A=[]
for i in list(permutations(P)):
   A.append(int("".join(i)))
A.sort()
print(abs(A.index(int("".join(P)))-A.index(int("".join(Q)))))

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

#define pb push_back
#define all(x) (x).begin(),(x).end()
#define SZ(x) ((int)(x).size())
#define REP(i,n) for(int _n=n, i=0;i<_n;++i)
#define FOR(i,a,b) for(int i=(a),_b=(b);i<=_b;++i)
#define FORD(i,a,b) for(int i=(a),_b=(b);i>=_b;--i)
#define trav(a, x) for (auto& a : x)
using ull = uint64_t;
using ll = int64_t;
using PII = pair<int, int>;
using VI = vector<int>;
#define INF (1ll<<60)

string to_string(string s) { return '"' + s + '"'; }
string to_string(const char* s) { return to_string((string) s); }
string to_string(bool b) { return (b ? "true" : "false"); }
template <typename A, typename B> string to_string(pair<A, B> p) {
  return "(" + to_string(p.first) + ", " + to_string(p.second) + ")"; }
template <typename A> string to_string(A v) {
bool first = true; string res = "{";
for (const auto &x : v) { if (!first) { res += ", "; } first = false; res += to_string(x); }
res += "}"; return res; }
void debug_out() { cerr << endl; }
template <typename Head, typename... Tail> void debug_out(Head H, Tail... T) {
  cerr << " " << to_string(H); debug_out(T...); }
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)

int main() {
    ios::sync_with_stdio(false), cin.tie(0);
    int X, Y, Z, K;
    cin >> X >> Y >> Z >> K;
    vector<ll> x(X), y(Y), z(Z);
    REP(i, X) cin >> x[i];
    REP(i, Y) cin >> y[i];
    REP(i, Z) cin >> z[i];
    vector<ll> A;
    REP(i, X) {
        REP(j, Y) {
            A.pb(x[i] + y[j]);
        }
    }
    sort(all(A), greater<ll>());
    VI foo(Z, 0);
    while (K--) {
        ll mx = 0;
        int idx = 0;
        REP(i, Z) {
            if (foo[i] >= SZ(A)) continue;
            ll a = z[i] + A[foo[i]];
            if (a > mx) {
                mx = a;
                idx = i;
            }
        }
        foo[idx]++;
        cout << mx << '\n';
    }
}

Measured memory_bytes: 10480