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

int main(){
    int K;
    cin>>K;
    int A,B;
    cin>>A>>B;
    int k=K;
    for(;B>=K;K=K+k){
        if(K>=A&&K<=B){
            cout<<"OK"<<endl;
            return 0;

        }else{
            ;
        }
    }
    cout<<"NG"<<endl;
}

Measured memory_bytes: 3636
#include <iostream>
#include <string>
#include <map>
#include <algorithm>
#define f first
#define s second
#define R PP(1,0,0)
#define C PP(0,1,0)
#define S PP(0,0,1)
using namespace std;
typedef pair <int,int> P;
typedef pair <int,P> iP;
int p,q;
string str[2][11];
map<iP,int> M;
iP PP(int a,int b,int c){return iP(a,P(b,c));}
iP E[]={R,C,S};

int gcd(int a,int b,int c,int d){
  a= a&&b? __gcd(a,b):max(a,b);
  c= c&&d? __gcd(c,d):max(c,d);
  a= a&&c? __gcd(a,c):max(a,c);
  return max(1,a);
}

void solve(){
  if(M.size()==2&&M.count(PP(1,1,1))) M[R]=M[C]=M[S]=M[PP(1,1,1)]/3;

  map<iP,int> ::iterator i,j;
  for(int k=0;k<3;k++){
    for(i=M.begin();i!=M.end();i++)
      for(j=M.begin();j!=M.end();j++){
	int A[]={i->f.f,i->f.s.f,i->f.s.s,i->s};
	int X[]={j->f.f,j->f.s.f,j->f.s.s,j->s};
	int D,l=A[k],r=X[k],f=1;
	D=gcd(l,r,0,0);
	for(int m=0;m<4;m++) if((A[m]=(A[m]*(r/D)-X[m]*(l/D)))<0)f=0;
	D=gcd(A[0],A[1],A[2],A[3]);
	for(int m=0;m<4;m++) A[m]/=D;
	if(f&&!M.count(PP(A[0],A[1],A[2])))M[PP(A[0],A[1],A[2])]=A[3];
      }
  }
}


int cal(int a,int b,int c){
  int d=gcd(a,b,c,0);
  a/=d,b/=d,c/=d;
  if(M.count(PP(a,b,c))) return M[PP(a,b,c)]*d;
  int fa=M.count(R),fb=M.count(C),fc=M.count(S),abc=fa+fb+fc;
  if(abc/3||(abc/2&&!a==!fa&&!b==!fb&&!c==!fc)) return (M[R]*a+M[C]*b+M[S]*c)*d;
  return -1;
}

void in(){
  M.clear();
  int cnt[3]={},d;
  for(int i=0;i<p;i++)
    for(int j=0,f=1,dot=0;j<str[0][i].size();j++){
      char ch=str[0][i][j];
      if(ch=='.')dot++;
      else if(f)f=0,d=gcd(cnt[0],cnt[1],cnt[2],dot),M[PP(cnt[0]/d,cnt[1]/d,cnt[2]/d)]=dot/d;
      if(ch=='('||ch=='['||ch=='{')cnt[ch/50]++;
      if(ch==')'||ch==']'||ch=='}')cnt[ch/50]--;
    }
}

void out(){
  int cnt[3]={},e[3];
  for(int i=0;i<3;i++)e[i]= M.count(E[i])? M[E[i]]:-1;

  for(int i=0;i<q;i++){
    for(int j=0;j<3;j++){
      M.erase(E[j]);
      if(e[j]!=-1)M[E[j]]=e[j];
    }
    if(i)cout <<" ";
    cout <<cal(cnt[0],cnt[1],cnt[2]);
    for(int j=0;j<str[1][i].size();j++){
      char ch=str[1][i][j];
      if(ch=='('||ch=='['||ch=='{')cnt[ch/50]++;
      if(ch==')'||ch==']'||ch=='}')cnt[ch/50]--;
    }
  }
  cout <<endl;
}

int main(){
  while(1){
    cin>>p>>q;
    if(!p&&!q) break;
    for(int i=0;i<p;i++)cin>>str[0][i];
    for(int i=0;i<q;i++)cin>>str[1][i];
    in();
    solve();
    out();
  }
  return 0;
}

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

int main() {
    ll N, M;
    cin >> N >> M;
    vector<int> a(N + 1);
    rep(i, M) {
        int tmp;
        cin >> tmp;
        a[tmp] = 1;
    }
    vector<ll> dp(N + 2);
    dp[N] = 1;
    dp[N + 1] = 0;
    for (int i = N - 1; i >= 0; i--) {
        if (a[i]) {
            dp[i] = 0;
            continue;
        }
        dp[i] = (dp[i + 1] + dp[i + 2]) % 1'000'000'007;
    }
    cout << dp[0] << endl;
    return 0;
}

Measured memory_bytes: 1408
dic_ref = {k:[k-1,k,k+1] for k in range(10)}
dic_ref = {str(k):''.join([str(x) for x in v if -1<x<10]) for k,v in dic_ref.items()}
k = int(input())
lst = list('123456789')

def generate(lst):
    res = []
    for i in lst:
        for j in dic_ref[i[-1]]:
            res.append(i + j)
    return res
            
while True:
    if k <= len(lst):
        print(int(lst[k-1]))
        break
    else:
        k -= len(lst)
        lst = generate(lst)

Measured memory_bytes: 15636
#include<stdio.h>
#define rep(i,n) for(int i=0;(i)<(n);(i)++)
int x[10][10];
int digit_e(int a,int b,int c,int d){
    return x[x[x[x[0][a]][b]][c]][d];
}
int check(int a,int b,int c,int d,int e){
    return x[x[x[x[x[0][a]][b]][c]][d]][e];
}
int cal(){
    int a,b,c,d,e,x;
    int flag,ans=0;
    rep(a,10) rep(b,10) rep(c,10) rep(d,10){
        e=digit_e(a,b,c,d);
        flag=0;
        rep(x,9){
            if(check((a+x+1)%10,b,c,d,e)==0) {flag=1; ans++; break;}
        }if(flag==1) continue;
        rep(x,9){
            if(check(a,(b+x+1)%10,c,d,e)==0) {flag=1; ans++; break;}
        }if(flag==1) continue;
        rep(x,9){
            if(check(a,b,(c+x+1)%10,d,e)==0) {flag=1; ans++; break;}
        }if(flag==1) continue;
        rep(x,9){
            if(check(a,b,c,(d+x+1)%10,e)==0) {flag=1; ans++; break;}
        }if(flag==1) continue;
        rep(x,9){
            if(check(a,b,c,d,(e+x+1)%10)==0) {flag=1; ans++; break;}
        }if(flag==1) continue;
        
        if(check(b,a,c,d,e)==0 && a!=b) {ans++;}
        else if(check(a,c,b,d,e)==0 && b!=c) {ans++;}
        else if(check(a,b,d,c,e)==0 && c!=d) {ans++;}
        else if(check(a,b,c,e,d)==0 && d!=e) {ans++;}
    }
    return ans;
}
int main(void){
    rep(i,10){
        rep(j,10){
            scanf("%d",&x[i][j]);
        }
    }
    printf("%d\n",cal());
    return 0;
}



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

using ll = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;

int main() {
    vector<string> s(3);
    for(int i = 0; i < 3; ++i) {
        cin >> s[i];
    }
    cout << s[0][0] << s[1][1] << s[2][2] << endl;
}


Measured memory_bytes: 256
#include<stdio.h>
#include<iostream>
#include<algorithm>
#include<stdlib.h>
#include<string.h>
#include<queue>
#define LL long long
using namespace std;
inline LL read( )
{
  LL sum=0;char c=getchar( );bool f=0;
  while(c<'0'||c>'9') {if(c=='-') f=1;c=getchar( );}
  while(c>='0'&&c<='9') {sum=sum*10+c-'0';c=getchar( );}
  if(f) return -sum;
  return sum;
}
const int N=100005;
int n,Q;LL t[N*4],cov[N*4],add[N*4];
inline void _cov(int p,LL v,int len)
{
  t[p]=v*len;
  add[p]=0;cov[p]=v;
}
inline void _add(int p,LL v,int len)
{
  t[p]+=v*len;
  if(cov[p]==-1) add[p]+=v;
  else cov[p]+=v;
}
inline void push(int p,int l,int r)
{
  LL u;int L=p<<1,R=L|1,mid=(l+r)>>1;
  if((u=add[p])) _add(L,u,mid-l+1),_add(R,u,r-mid),add[p]=0;
  if((u=cov[p])!=-1) _cov(L,u,mid-l+1),_cov(R,u,r-mid),cov[p]=-1;
}
LL v;
inline void build(int p,int l,int r)
{
  cov[p]=-1;if(l==r) return;
  int mid=(l+r)>>1;build(p<<1,l,mid);build(p<<1|1,mid+1,r);
}
inline void ch(int p,int l,int r,int L,int R)
{
  if(l==L&&r==R) {_cov(p,v,r-l+1);return;}
  push(p,l,r);
  int mid=(l+r)>>1;
  if(R<=mid) ch(p<<1,l,mid,L,R);
  else if(L>mid) ch(p<<1|1,mid+1,r,L,R);
  else ch(p<<1,l,mid,L,mid),ch(p<<1|1,mid+1,r,mid+1,R);
  t[p]=t[p<<1]+t[p<<1|1];
}
inline void up(int p,int l,int r,int L,int R)
{
  if(l==L&&r==R) {_add(p,v,r-l+1);return;}
  push(p,l,r);
  int mid=(l+r)>>1;
  if(R<=mid) up(p<<1,l,mid,L,R);
  else if(L>mid) up(p<<1|1,mid+1,r,L,R);
  else up(p<<1,l,mid,L,mid),up(p<<1|1,mid+1,r,mid+1,R);
  t[p]=t[p<<1]+t[p<<1|1];
}
inline LL ask(int p,int l,int r,int L,int R)
{
  if(l==L&&r==R) return t[p];
  push(p,l,r);
  int mid=(l+r)>>1;
  if(R<=mid) return ask(p<<1,l,mid,L,R);
  else if(L>mid) return ask(p<<1|1,mid+1,r,L,R);
  else return ask(p<<1,l,mid,L,mid)+ask(p<<1|1,mid+1,r,mid+1,R);
}
inline void DFS(int p,int l,int r)
{
  if(l==r) {printf("%lld\n",t[p]);return;}
  push(p,l,r);
  int mid=(l+r)>>1;
  DFS(p<<1,l,mid);
  DFS(p<<1|1,mid+1,r);
}
int main( )
{
  int a,l,r,mid,L,len;LL b,t;
  n=read( );Q=read( );
  build(1,1,n);
  while(Q--)
    {
      a=read( );b=read( );
      if(a==1) {v=b;up(1,1,n,1,1);continue;} //q[0]=inf
      if(ask(1,1,n,a-1,a-1)-ask(1,1,n,a,a)>=b) {v=b;up(1,1,n,a,a);continue;}
      l=2;r=a;
      while(l<=r)
	{
	  mid=(l+r)>>1;
	  if(ask(1,1,n,mid-1,mid-1)*(a-mid+1)-ask(1,1,n,mid,a)<=b) r=mid-1;
	  else l=mid+1;
	}
      L=l-1;t=ask(1,1,n,L,L);
      //printf("%d\n",L);
      b-=t*(a-r+1)-ask(1,1,n,r,a);
      //cout<<b<<endl;
      v=t;ch(1,1,n,L+1,a);
      //DFS(1,1,n);puts("");
      len=a-L+1;
      v=b/len;
      if(v) up(1,1,n,L,a);//,printf("%d %d %lld\n",L,a,v);
      b%=len;
      if(b) v=1,up(1,1,n,L,L+b-1);//,printf("%d %lld\n",L,L+b-1);
      //DFS(1,1,n);puts("");
    }
  DFS(1,1,n);
  return 0;
}


Measured memory_bytes: 9856
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;i++)
#define FOR(i,start,end) for(int i=start;i<=end;i++)
const int INF = 1001001001;
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define Sort(a) sort(a.begin(), a.end())
#define Rort(a) sort(a.rbegin(), a.rend())
typedef long long ll;
const ll MOD=1000000007;
using namespace std;
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; }
template<class T>auto MAX(const T& a) { return *max_element(a.begin(),a.end()); }
template<class T>auto MIN(const T& a) { return *min_element(a.begin(),a.end()); }
template<class T, class U>U SUM(const T& a, const U& v) { return accumulate(a.begin(),a.end(), v); }
template<class T, class U>U COUNT(const T& a, const U& v) { return count(a.begin(),a.end(), v); }
template<class T, class U>int LOWER(const T& a, const U& v) { return lower_bound(a.begin(),a.end(), v) - a.begin(); }
template<class T, class U>int UPPER(const T& a, const U& v) { return upper_bound(a.begin(),a.end(), v) - a.begin(); }
int GCD(int a, int b) { return b ? GCD(b, a%b) : a; }
int LCM(int a, int b) { int g = GCD(a, b); return a / g * b; }
typedef long double ld;
typedef unsigned long long int ull;
typedef pair<int,int> P;
typedef vector<int> vi;
typedef vector<char> vc;
typedef vector<bool> vb;
typedef vector<double> vd;
typedef vector<string> vs;
typedef vector<ll> vll;
typedef vector<pair<int, int>> vpii;
typedef vector<pair<ll, ll>> vpll;
typedef vector<vi> vvi;
typedef vector<vvi> vvvi;
typedef vector<vc> vvc;
typedef vector<vs> vvs;
typedef vector<vll> vvll;
typedef map<int, int> mii;
typedef set<int> si;
//---------------------------------------------------------------------------------------------------

int main(void){
    // Your code here!
    string  n; cin >> n;
    int sz = n.size();
    rep(i,sz) {
        if (i != 0 && n[i] != '9') {
            cout << n[0] - '0' + 9*(sz-1) - 1 << endl;
            return 0;
        }
    }
    cout << n[0] - '0' + 9*(sz-1) << endl;
}


Measured memory_bytes: 3632
import std.stdio;
import std.ascii;
import std.conv;
import std.string;
import std.algorithm;
import std.range;
import std.functional;
import std.math;
import core.bitop;
import std.numeric;

T lread(T = long)()
{
    return readln.chomp.to!T();
}

T[] aryread(T = long)()
{
    return readln.split.to!(T[])();
}

void main()
{
    auto nmxy = aryread;
    auto X = aryread;
    auto Y = aryread;
    X.sort();
    Y.sort();
    bool a = X[$ - 1] < Y[0];
    bool b = nmxy[2] < Y[0];
    bool c = Y[0] <= nmxy[3];
    // writeln(a, b, c);
    if (a && b && c)
    {
        writeln("No War");
    }
    else
    {
        writeln("War");
    }
}


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

N = int(input())
D = list(map(int, input().split()))
mod = 998244353

if 0 in D[1:] or D[0] != 0:
    print(0)
    exit(0)
else:
    num = [0]*max(D)
    for i in range(1, N):
        if D[i] > 0:
            num[D[i]-1] += 1

    ans = 1
    for i in range(1, len(num)):
        ans *= (num[i-1]**num[i]) % mod

    print(ans % mod)


Measured memory_bytes: 13636
#include <iostream>
#include <algorithm>
#include <numeric>
#include <cmath>
#include <vector>
#include <stack>
#include <queue>
#include <list>
#include <set>
using namespace std;

int main(){

    int n; cin >> n;

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

    int pmax = 0;
    int itmp = 0;

    for(int i=0; i<n; i++){
        if(pmax < p[i]){
            pmax = p[i];
            itmp = i;
        }
    }

    cout << accumulate(p, p+n, 0) - pmax/2;

    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdlib>
#include <cstdio>
using namespace std;
int main(){
	while(1){
		char c;
		scanf("%c",&c);
		int a = atoi(&c);
		if(a==0) return 0;
		while(1){
			scanf("%c",&c);
			if(c=='\n'){ cout << a << endl; break;}
			a += atoi(&c);
		}
	}
}

Measured memory_bytes: 1164
#include <algorithm>
#include <climits>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <limits>
#include <map>
#include <memory>
#include <numeric>
#include <queue>
#include <set>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <vector>

//std::cout << std::fixed << std::setprecision(10)
constexpr long long MOD = 1000000007;

int main()
{
  int N;
  std::cin >> N;
  std::vector<int> A(N);
  for (auto& val: A)
    std::cin >> val;
  auto solve = [&]()
  {
    std::multiset<int> tails;
    tails.insert(A[0]);
    for (int i = 1; i < A.size(); ++i)
    {
      auto val = A[i];
      auto it = tails.lower_bound(val);
      if (it == tails.begin())
      {
        tails.insert(val);
      }
      else
      {
        --it;
        tails.erase(it);
        tails.insert(val);
      }
    }
    return tails.size();
  };
  std::cout << solve() << std::endl;
  return 0;
}



Measured memory_bytes: 5376
#include <vector>
#include <list>
#include <map>
#include <set>
#include <unordered_set>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <queue>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>
#include <fstream>
#include <stdio.h>
#include <complex>
#include <cstdint>
#include <tuple>

#define M_PI       3.14159265358979323846

using namespace std;

//conversion
//------------------------------------------
inline int toInt(string s) { int v; istringstream sin(s); sin >> v; return v; }
template<class T> inline string toString(T x) { ostringstream sout; sout << x; return sout.str(); }
inline int readInt() { int x; scanf("%d", &x); return x; }

//typedef
//------------------------------------------
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef pair<int, PII> TIII;
typedef long long LL;
typedef unsigned long long ULL;
typedef vector<LL> VLL;
typedef vector<VLL> VVLL;

//container util

//------------------------------------------
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define SQ(a) ((a)*(a))
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())

//repetition
//------------------------------------------
#define FOR(i,s,n) for(int i=s;i<(int)n;++i)
#define REP(i,n) FOR(i,0,n)
#define MOD 1000000007

struct UnionFind {
	vector<int> data;
	UnionFind(int size) : data(size, -1) { }
	LL unionSet(int x, int y) {
		x = root(x); y = root(y);
		LL ret = 0;
		if (x != y) {
			if (data[y] < data[x]) swap(x, y);
			ret = (LL)data[x] * (LL)data[y];
			data[x] += data[y]; data[y] = x;
		}
		return ret;
	}
	bool findSet(int x, int y) {
		return root(x) == root(y);
	}
	int root(int x) {
		return data[x] < 0 ? x : data[x] = root(data[x]);
	}
	int size(int x) {
		return -data[root(x)];
	}
};

int main() {
	int n, m;
	scanf("%d%d", &n, &m);
	vector<PII> edges(m);
	REP(i, m) {
		int a, b;
		scanf("%d%d", &a, &b);
		edges[i] = MP(a-1, b-1);
	}
	reverse(ALL(edges));
	vector<LL> ans(m);
	LL tmp_ans = (n*(n - 1LL)) / 2;
	UnionFind uf(n);
	REP(i, m) {
		ans[i] = tmp_ans;
		tmp_ans -= uf.unionSet(edges[i].first, edges[i].second);
	}
	reverse(ALL(ans));
	REP(i, m)printf("%lld\n", ans[i]);

	return 0;
}

Measured memory_bytes: 3328
#include <iostream>
#include <string>
#include <vector>
#include <stdio.h>
#include <algorithm>
#define _USE_MATH_DEFINES
#include <cmath>
#include <numeric>
#include <iomanip>
#include <deque>
#include <tuple>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <unordered_map>
#include <sstream>

#define rep(i, x) for (int i = 0; i < (int)(x); i++)
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define all(a) (a).begin(), (a).end()
#define F first
#define S second
#define pb push_back
#define pf push_front

using ll = long long;
using namespace std;

ll M = 1000000007;
typedef pair<int, int> P;

int main()
{
    int n;
    cin>>n;
    vector<int>l(n);
    rep(i,n){
        cin>>l[i];
    }
    sort(all(l));
    int ans=0;
    rep(i,n){
        FOR(j,i+1,n){
            int a=l[i];
            int b=l[j];
            int ab=a+b;
            int dis=max(a-b,b-a);
            int iteb=lower_bound(l.begin()+j+1,l.end(),ab)-l.begin()-j;
            int itel=upper_bound(l.begin()+j+1,l.end(),dis)-l.begin()-j;
            int cnt=iteb-itel;
            //cout<<cnt<<" "<<a<<" "<<b<<endl;
            ans+=cnt;
        }
    }
    cout<<ans<<endl;


}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
int main(void){
        using namespace std;
        int N, c = 0, max = 0;
        cin >> N;
        vector<int> h(N);
        for(int i = 0; i < N; i++)
                cin >> h[i];
        for(int i = 0; i < N; i++){
                if( h[i] >= max){
                        c++;
                        max = h[i];
                }
        }
        cout << c << endl;
}


Measured memory_bytes: 256
/*why so serious?*/
#include<bits/stdc++.h>
using namespace std;
#define   int      long long
#define   fast()   ios_base::sync_with_stdio(0);cin.tie(0)
#define   all(x)   x.begin(),x.end()
#define   pb       push_back
#define   F        first
#define   S        second

int32_t main()
{int n,i,j,cnt,f;
 string s,str;
 fast();
 cin>>s;
 n=s.length();
 cnt=0;
 for(i=0;i<n;++i)
 {for(j=i;j<n;++j)
  {str=s.substr(i,j-i+1);
   //cout<<str<<"\n";
   f=1;
   for(auto x:str)
   {if((x=='A')||(x=='T')||(x=='C')||(x=='G'))
    ;
    else
    {f=0;break;}
   }
   if(f)
   cnt=max(cnt,(int)str.length());
  }
 }
 cout<<cnt;
 return 0;
}

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

int main(){
  int a, b, c, x, y;
  cin >> a >> b >> c >> x >> y;

  int a1, a2, a3;

  a1 = a*x + b*y;
  a2 = 2*c * max(x, y);

  if (x >= y){
    a3 = 2*c * y + a * ( x - y );
  } else {
    a3 = 2*c * x + b * ( y - x);
  }

  cout << min({a1, a2, a3}) << endl;
  
	return 0;
}


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

#define int long long

#define ii pair<int,int>
#define fi first
#define sc second
#define lwb lower_bound
#define upb upper_bound
#define all(x) (x).begin(),(x).end()

signed main() {
#ifdef _DEBUG
  // freopen("in", "r", stdin);
#endif
  ios::sync_with_stdio(0); cin.tie(0);
  double x, n = 100;
  cin >> x;
  int cnt = 0;
  while (n < x) n = trunc(n * 1.01), cnt++;
  cout << cnt << '\n';
}


Measured memory_bytes: 3720
#include <bits/stdc++.h>
#define endl "\n"
using namespace std;
typedef long long int lli;
int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);
    lli n;
    cin>>n;
    lli i, x, y, ans = 0;
    
    // max possible component 
    for(i=1;i<=n;i++) ans += i * (n - i + 1);
    
    // remove
    for(i=0;i<n-1;i++)
    {
        cin>>x>>y;
        
        if(x > y) swap(x, y);
        
        ans -= x * (n - y + 1);
    }
    cout<<ans;
    return 0;
}

Measured memory_bytes: 3664
#include <bits/stdc++.h>
#define int long long
#define IOS ios::sync_with_stdio(false);cin.tie(0);cout.tie(0)

using namespace std;

int32_t main(){IOS;
	
	
	int a[5];
	int k ;
	for(int& i : a ) cin >> i ;
	cin >> k ;
	bool flag = (a[4]-a[0] <= k);
	if(flag) cout << "Yay!" << endl;
	else cout << ":(" << endl;
	return 0;
}


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

// macro
#define rep(i,n) for(i=0;i<n;i++)
#define ll long long
#define all(v) v.begin(), v.end()

// code starts
#define MOD 1000000007

ll mod_inv(ll a)
{
	ll ret=1;
	ll ks=a;
	ll left=MOD-2;
	while(left>0)
	{
		if(left%2==1)
		{
			ret=ret*ks%MOD;
		}
		ks=ks*ks%MOD;
		left/=2;
	}
	return ret;
}

int main()
{
	int n,k;cin>>n>>k;
	vector<int> a(n);
	int i,j;
	rep(i,n)cin>>a[i];
	ll ans0=0;
	ll ans1=0;
	rep(i,n)
	{
		for(j=i+1;j<n;j++)
		{
			if(a[i]>a[j])ans0++;
		}
	}
	rep(i,n)
	{
		rep(j,n)
		{
			if(a[i]>a[j])ans1++;
		}
	}
	ans0=(ans0*k)%MOD;
	ans1=(ans1*k)%MOD;
	ans1=(ans1*(k-1))%MOD;
	ans1=(ans1*mod_inv(2))%MOD;
	cout<<(ans0+ans1)%MOD<<endl;
}


Measured memory_bytes: 256
'use strict'

function main(s) {

  s = s.split('\n')[0].split(' ').map(n => Number(n));

  const A = s[1];
  const B = s[2];

  const ans = ((A - B) % 2 === 0) ? 'Alice' : 'Borys';
  console.log(ans);
}

main(require("fs").readFileSync("/dev/stdin", "utf8"));


Measured memory_bytes: 11468
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <vector>

using namespace std;

typedef long long ll;

ll n, a, b, cnt;
vector<ll> ve[300005], ans, ve2;

int main()
{
    scanf("%lld%lld%lld", &n, &a, &b);
    cnt = n;
    if(n > a * b || n < a + b - 1)
    {
        printf("-1\n");
        return 0;
    }
    for(ll i = 1; i <= a; i++)
    {
        ve[i].push_back(i * b);
        cnt--;
    }
    for(ll i = 1; i <= a; i++)
    {
        for(ll j = 0; j < min(cnt, b - 1); j++)
        {
            ve[i].push_back(ve[i].back() - 1);
        }
        cnt -= min(cnt, b - 1);
    }
    for(ll i = 1; i <= a; i++) for(ll j = 0; j < ve[i].size(); j++) ans.push_back(ve[i][j]), ve2.push_back(ve[i][j]);
    sort(ve2.begin(), ve2.end());
    for(ll i = 0; i < ans.size(); i++)
    {
        printf("%lld ", (ll)(lower_bound(ve2.begin(), ve2.end(), ans[i]) - ve2.begin()) + 1);
    }
    return 0;
}


Measured memory_bytes: 25964
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vl = vector<ll>;
using vvl = vector<vl>;
using vb = vector<bool>;
using vs = vector<string>;
using msi = map<string, int>;
using mii = map<int, int>;
using psi = pair<string, int>;
using pii = pair<int, int>;
using tii = tuple<int, int>;
using vlai = valarray<int>;
#define rep(i,n) for(int i=0;i<n;i++)
#define range(i,s,n) for(int i=s;i<n;i++)
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define fs first
#define sc second
#define INF 1E9
#define LINF 1E18*5
#define EPS 1E-9
#define MOD 1000000007
#define PI 3.1415926535897932384

template<class S, class T>ostream& operator<<(ostream&os, pair<S, T>p) { os << "[" << p.first << ", " << p.second << "]"; return os; };
template<class S>auto&operator<<(ostream&os, vector<S>t) { bool a = 1; for (auto s : t) { os << (a ? "" : " ") << s; a = 0; } return os; }

//int dx[]={1,1,1,0,-1,-1,-1,0},dy[8]={1,0,-1,-1,-1,0,1,1,1};
//
constexpr ll gcd(ll a, ll b) { return b ? gcd(b, a%b) : a; }

class compare {
public:
	bool operator()(tuple<int, int> a, tuple<int, int> b) {
		return (get<1>(a) < get<1>(b));
	}
};
class rcompare {
public:
	bool operator()(tuple<int, int> a, tuple<int, int> b) {
		return (get<0>(a) < get<0>(b));
	}
};
int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	ll n, ans = 0;
	cin >> n;
	vl v(n);
	rep(i, n) {
		int a;
		cin >> a;
		v[a - 1] = i;
	}
	set<ll> s{ -1, n};
	rep(i, n) {
		auto itr = s.lower_bound(v[i]);
		ans += (*itr - v[i])*(v[i] - *(--itr))*(i+1);
		s.insert(v[i]);

	}
	cout << ans  << endl;

}

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

using namespace std;

int main(){
    int n, l, x, y;
    cin>>n>>l;
    int arr[n+1];
    bool posible = false;
    for (int i=1; i<=n; i++){
        cin>>arr[i];
    }
    for (int i=2; i<=n; i++){
        if (arr[i-1] + arr[i] >= l){
            posible = true;
            x = i-1, y = i;
        }
    }
    if (posible == false){
        cout<<"Impossible";
    }
    else{
        cout<<"Possible"<<endl;;
        for (int i=n-1; i>=y; i--){
            cout<<i<<endl;
        }
        for (int i=1; i<x; i++){
            cout<<i<<endl;
        }
        cout<<x<<endl;
    }
}

Measured memory_bytes: 1152
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define INF 2e9
#define ALL(v) v.begin(), v.end()
using namespace std;
typedef long long ll;
int main()
{
  int N;
  double D; cin >> N >> D;
  int ans=0;
  long X,Y;
  REP(i,N){
    cin >> X >> Y;
    if(D >= sqrt(X * X + Y * Y))
      ans++;
  }
  cout << ans << endl;
}

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

int main() {
    int N;
    int K;

    cin >> N >> K;

    int out = 1;

    for (int i = 0; i < N; i++) {
        if (out * 2 - out < K) {
            out *= 2;
        } else {
            out += K;
        }
    } 
    cout << out << endl; 
}

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

using namespace std;

int main(){
  int n,m;
  cin >> n >> m;
  priority_queue<long long int> a;

  rep(i,n) {
    int j;
    cin >> j;
    a.push(j);
  }
  rep(i,m){
    int k = a.top();
    k /= 2;
    a.pop();
    a.push(k);
  }

  long long int sum = 0;

  rep(i,n){

    sum += a.top();
    a.pop();
  }

  cout << sum << endl;
  return 0;

}


Measured memory_bytes: 1400
#include <bits/stdc++.h>
#define rep(i,n) for ( int i = 0; i < (n); ++i )
#define all(v) v.begin(), v.end()
using namespace std;
using ll = long long int;
const long long int INF = 1001001001001001LL;
const int inf = 1000000007;
long long int MOD = 1000000007LL;
double PI = 3.1415926535897932;


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

    int n, p, m, cnt = 0;
    cin >> n;
    m = n+1;
    rep(i,n) {
        cin >> p;
        if( p <= m ) {
            m = min( m, p );
            cnt++;
        }
    }
    cout << cnt << endl;

    return 0;
}

Measured memory_bytes: 256
n = int(input())
alphabet = 'abcdefghijk'

def ans(n):
    if n == 1:
        return ['a']
    ret = []
    pre = ans(n-1)
    for s in pre:
        l = len(set(s))
        for i in range(l+1):
            ret.append(s + alphabet[i])
    return ret

for s in ans(n):
    print(s)

Measured memory_bytes: 12992
#include <bits/stdc++.h>
using namespace std;
const int N=550;
int n,m,h,w,a[N][N];
int main(){
    cin>>n>>m>>h>>w;
    if (n%h==0&&m%w==0) puts("No");
    else{
	puts("Yes");
	for (int i=1; i<=n; ++i){
	    for (int j=1; j<=m; ++j){
		if (i%h==0&&j%w==0)
		    a[i][j]=-(h*w-1)*2000-1;
		else
		    a[i][j]=2000;
		printf("%d ",a[i][j]);
	    }
	    printf("\n");
	}
    }
    return 0;
}


Measured memory_bytes: 2688
while 1:
    n=int(input())
    if n==0: break
    for _ in range(n):
        a=list(map(int,input().split()))
        c=sum(a)
        if sum(a[:2])/2>=90 or c/3>=80 or 100 in a: b='A'
        elif c/3>=70 or (c/3>=50 and (a[0]>=80 or a[1]>=80)): b='B'
        else: b='C'
        print(b)

Measured memory_bytes: 7596
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <string>
#include <sstream>
#include <complex>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
#include <numeric>
using namespace std;
typedef long long int ll;
typedef vector<int> VI;
typedef vector<VI> VVI;
#define EPS (1e-7)
#define INF (1e9 + 10)
#define PI (acos(-1))
#define MOD (1000000007)
#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 ALL(x) (x).begin(),(x).end()
#define debug(x) cout<<#x<<": "<<x<<endl
template<class T>string watch(T &v){string res="";for(auto f:v)res+=(to_string(f)+" ");return res;}
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }

int main() {
    ll N, K;cin >> N >> K;
    ll ans = 0;
    if (K==0) ans = N*N;
    else {
        REPS(i, N) {
            int group = (N+1)/i;
            if (i > K) ans += group*(i-K);
            int remain = (N+1)%i;
            if (remain-1 >= K) ans += remain-K;
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
import math
def combinations_count(n, r):
  return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))

MOD = 10**9+7
N, K = list(map(int, input().split()))

for i in range(K):
  if K-1 >= i and N-K+1 >= i+1:
    blue = combinations_count(K-1, i)
    red = combinations_count(N-K+1, i+1)
    print(blue*red%MOD)
  else:
    print(0)

Measured memory_bytes: 3316
#include<stdio.h>
int main()
{
    int N,R;
    scanf("%d %d",&N,&R);
    if(N>=10)
    {
     printf("%d",R);
    }

    else
        {
            R=R+100*(10-N);
    printf("%d",R);
        }
    return 0;
}


Measured memory_bytes: 128
#include<bits/stdc++.h> 
using namespace std;
typedef long long ll;
template<typename T1,typename T2> bool chmin(T1 &a,T2 b){if(a<=b)return 0; a=b; return 1;}
template<typename T1,typename T2> bool chmax(T1 &a,T2 b){if(a>=b)return 0; a=b; return 1;}
ll dx[4]={0,1,-1,0};
ll dy[4]={1,0,0,-1};



signed main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout << fixed << setprecision(20);

    ll n,x,mod;
    cin>>n>>x>>mod;
    ll ans = 0;
    ll cnt[mod+1]={};
    ll now = 1;
    while(!cnt[x] && n){
        n--;
        cnt[x] = now;
        now++;
        ans += x;
        x = (x*x)%mod;
    }
    if(n==0){
        cout << ans << endl;
        return 0;
    }
    ll c = now - cnt[x];
    ll d = 0;
    for(ll i=0;i<=mod;i++){
        if(cnt[i] >= cnt[x])d += i;
    }
    ll t = n/c;
    ans += t * d;
    ll rem = n % c;
    while(rem){
        rem--;
        ans += x;
        x = (x*x)%mod;
    }
    cout << ans << endl;

}

Measured memory_bytes: 4428
# -*- coding: utf-8 -*-

import sys


n = int(sys.stdin.readline())
v = [int(x) for x in sys.stdin.readline().strip().split(" ")]

v = sorted(v)[::-1]
for _ in range(len(v) - 1):
    v1 = v.pop()
    v2 = v.pop()
    v3 = (v1 + v2) / 2
    v.append(v3)

print(v[0])


Measured memory_bytes: 2940
import java.util.Scanner;
public class Main
{
	public static void main(String arg[])
	{
		Scanner in = new Scanner(System.in);
		int M=in.nextInt();
		int N=in.nextInt();
		int ans=0;
		int max=0;
		for(int i=0;i<M;i++)
		{
			 max=0;
			for(int j=0;j<N;j++)
				if(in.nextInt()==1)
					max++;
			ans=Math.max(max, ans);
		}
		System.out.println(ans);
	}
}

Measured memory_bytes: 12000
# pragma GCC optimize("O3")
# include <bits/stdc++.h>
std::pair<int,int> DR[] = {{-1,0},{0,1},{1,0},{0,-1},{-1,1},{-1,-1},{1,1},{1,-1}};
# define ll long long
# define clock (clock() * 1000.0 / CLOCKS_PER_SEC)
# define rc(s) return cout << s,0
# define rcg(s) cout << s;exit(0)
# define _ ios_base::sync_with_stdio(false);cin.tie(0);cerr.tie(0);cout.tie(0);
# define db(x) cerr << #x << " = " << x << '\n'
# define pb push_back
# define mp make_pair
# define all(s) s.begin(),s.end()
# define sz(x) (int)((x).size())
# define int ll
using namespace std;

int h,w,ans[1005][1005];
char a[1005][1005];

const int mod = 1e9 + 7;

int32_t main(){_
    //freopen("in","r",stdin);
	cin >> h >> w;
	ans[1][1] = 1;
	for(int i = 1;i <= h;i++)
	{
		for(int j = 1;j <= w;j++)
		{
			cin >> a[i][j];
			if(a[i][j] == '.')
			{
				ans[i][j] += (ans[i - 1][j] + ans[i][j - 1]) % mod;
			}
		}
	}
	rc(ans[h][w]);
}

Measured memory_bytes: 9088
#include <iostream>
#include <vector>
#include <cmath>

using namespace std;
int m, n;
int ans;

bool f(int mid, const vector<int>& page)
{
	int need = 1;
	int s = 0;
	for(int i = 0; i < n; ++i)
	{
		if(page[i] > mid)
		{
			return(false);
		}
		if(s + page[i] > mid)
		{
			++need;
			s = 0;
		}
		s += page[i];
	}
	return (need <= m);
}

void solve()
{
	while(cin >> m >> n, m || n)
	{
		vector<int> page(n);
		for(int i = 0; i < n; ++i)
		{
			cin >> page[i];
		}
		int right = 1500000;
		int left = 1;
		while(right - left > 1)
		{
			int mid = (left + right) / 2;
			if(f(mid, page))
			{
				right = mid;
			}
			else
			{
				left = mid;
			}
		}
		if(f(left, page))
		{
			cout << left << endl;
		}
		else
		{
			cout << right << endl;
		}
	}
}

int main()
{
	solve();
	return(0);
}

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

int main( int argc, char *argv[] )
{
int i;
int j;
int n;
int iMax;
int iPos;
char S[60][60];
int iCnt[ 30 ];
int iMinCnt[ 30 ];
char C;
char lpOut[ 60 ];

	// 入力
	cin >> n;
	for( i = 0; i < n; i++ )
	{
		cin >> S[i];
	}

	// 初期化
	for( i = 0; i < 26; i++ )
	{
		iCnt[i] = 0;
		iMinCnt[i] = 0;
	}

	// 個々の文字列における各文字の数をチェック
	j = 0;
	do
	{
		C = S[ 0 ][ j ];
		iCnt[ C - 'a' ]++;
		iMinCnt[ C - 'a' ]++;
		j++;
	}
	while( C != '\0' );

	// 共通する文字の数をカウント
	for( i = 1; i < n; i++ )
	{
		// 初期化
		for( j = 0; j < 26; j++ )
		{
			iCnt[j] = 0;
		}

		// 個々の文字列における各文字の数をチェック
		j = 0;
		do
		{
			 C = S[i][j];
			 iCnt[ C - 'a' ]++;
			 j++;
		}
		while( C != '\0' );

		// 最小値に更新
		for( j = 0; j < 26; j++ )
		{
			if( iMinCnt[ j ] > iCnt[ j ] )
				iMinCnt[ j ] = iCnt[ j ];
		}
	}

	// 出力
	//cout << ( A + B ) % 24 << endl;
	iPos = 0;
	for( i = 0; i < 26; i++ )
	{
		iMax = iMinCnt[ i ];
		for( j = 0; j < iMax; j++ )
		{
			lpOut[ iPos + j ] = 'a' + i;
		}

		iPos += iMax;
	}

	// 出力
	lpOut[ iPos ] = '\0';
	cout << lpOut << endl;

	return 0;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
#define pb push_back
#define mp make_pair
#define OP ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define F first
#define S second
#define sz(x) (int)x.size()
#define all(x) (x).begin(), (x).end()
#define rep(i, n) for(int i = 0; i < n; ++i)
#define repr(i,n) for(int i = n - 1; i >= 0; --i)
#define Rep(i, a, n) for(int i = (a); i <=(n); ++i)
#define repst(i, n) for(auto it = n.begin(); it != n.end(); ++it)
#define Repr(i, a, n) for(int i = (n); i >= (a); --i)
typedef long long ll;
typedef std::vector<int> vi;
typedef std::pair<int, int> pii;
const int inf = int(1e9);
const int mod = inf + 7;
const double PI = acos(-1.0);
using namespace std;
const int N = 1e5 + 155;
 
void solve(){
  int n, a, b;
  cin >> n >> a >> b;
  cout << min(n * a, b);
}
 
int main(){
    OP
    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);
    int t = 1;
    while(t--)
    solve();
    return 0;
}

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

#define INF 1000000000;

int main()
{
    int n, m;
    cin >> n >> m;
    int coins[n + 5];
    for (int i = 1; i <= m; i++)
    {
        cin >> coins[i];
    }

    int dp[m + 5][n + 5];
    for (int i = 0; i <= m; i++)
    {
        for (int j = 0; j <= n; j++)
        {
            dp[i][j] = INF;
        }
    }

    dp[0][0] = 0;

    for (int i = 1; i <= m; i++)
    {
        for (int j = 0; j <= n; j++)
        {
            if (coins[i] <= j)
            {
                dp[i][j] = min(dp[i - 1][j], dp[i][j - coins[i]] + 1);
            }
            else
            {
                dp[i][j] = dp[i - 1][j];
            }
        }
    }

    cout << dp[m][n] << endl;
    return 0;
}



Measured memory_bytes: 7232
#include <bits/stdc++.h>
using namespace std;
using pii=pair<int,int>;
using ll=long long;

#define fi first
#define se second
#define pb push_back
#define rep(i,n) for(int i=0; i<(int)(n); i++)

template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }

int main() {
	int n,m;
	cin >> n >> m;
	priority_queue<ll> a;
	ll at;
	rep(i,n) {
		cin >> at;
		a.push(at);
	}
	rep(i,m) {
		ll b = a.top();
		a.pop();
		b /= 2;
		a.push(b);
	}
	ll ans=0;
	rep(i,n) {
		ans += a.top();
		a.pop();
	}
	cout << ans << endl;

  return 0;
}


Measured memory_bytes: 1400
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <vector>
#include <queue>
#include <map>
#include <set>
#include <string>
#include <cstring>
#include <cmath>
#include <iomanip>

#define DEBUG 0
#define fi first
#define se second
#define pb push_back
#define INF 1000000000
#define fore(i,a,b) for (int i = (a), _b = (b); i < (_b); ++i)
#define fort(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)

using namespace std;

typedef long long LL;
typedef pair<int, int> ii;
typedef vector<ii> vii;
typedef vector<vii> vvii;
typedef vector<int> vi;
typedef vector<vi> vvi;

int main() {
    if (DEBUG) {
        freopen("CP.inp", "r", stdin);
        //freopen("CP.out", "w", stdout);
    }
    ios_base::sync_with_stdio(false); cin.tie(0);
    int n, W; cin >> n >> W;
    vi w(n), v(n);
    int maxV = 0;
    fore(i, 0, n) {
        cin >> w[i] >> v[i];
        maxV += v[i];
    }
    vector<LL> f(maxV + 1, INF);
    f[0] = 0;
    fore(i, 0, n) ford(j, maxV - v[i], 0) {
        f[j + v[i]] = min(f[j + v[i]], f[j] + w[i]);
    }
    int res = 0;
    fort(i, 0, maxV) if (f[i] <= W) res = max(res, i);
    cout << res << '\n';
    return 0;
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep1(i, n) for (int i = 1; i <= (int)(n); i++)
#define rev(i, n) for(int i = (int)(n - 1); i >= 0; i--)
#define rev1(i, n) for(int i = (int)(n); i > 0; i--)
#define pb push_back
#define all(v) (v).begin(), (v).end()
#define resort(v) sort((v).rbegin(), (v).rend())
#define vi vector<int>
#define vvi vector<vector<int>>
#define vc vector<char>
#define vvc vector<vector<char>>
#define vb vector<bool>
#define vvb vector<vector<bool>>
using ll = long long;
using P = pair<int, int>;
/* ----------------よく使う数字や配列----------------- */
int dx[] = {1,0,-1,0};
int dy[] = {0,1,0,-1};
constexpr ll mod = 1e9+7;
constexpr ll inf = INT32_MAX/2;
constexpr ll INF = LLONG_MAX/2;
constexpr long double eps = DBL_EPSILON;
constexpr long double pi = 3.141592653589793238462643383279;
/* ----------------------end----------------------- */

/* --------------------ライブラリ-------------------- */
ll fact(int i) {       //階乗
    if (i == 0) return 1;
    return (fact(i - 1)) * i;
}
ll gcd(ll a, ll b) {        //最大公約数
    if(b == 0) return a;
    return gcd(b, a % b); 
}
ll lcm(ll a, ll b) {      //最小公倍数
    return a * b / gcd(a, b);
}
int keta(ll n) {        //桁数を求める
    if(n == 0) return 1;
    int count = 0;
    while(n != 0) {
        n /= 10;
        count++;
    }
    return count;
}
ll ketasum(ll n) {    //各桁の和
    ll sum = 0;
    while(n != 0) {
        sum += n % 10;
        n /= 10;
    }
    return sum;
}
/* ----------------------end----------------------- */
int main() {
    ll n,m;cin >> n >> m;
    vector<pair<ll,ll>> v(n);
    rep(i, n) {
        ll a,b;cin >> a >> b;
        v[i] = P(a,b);
    }
    sort(all(v));
    ll k = m;
    ll money = 0;
    rep(i, n) {
        pair<ll,ll> p = v[i];
        if(p.second<k) {
            money+=p.first*p.second;
            k-=p.second;
        }
        else if(p.second>=k) {
            money+=p.first*k;
            cout << money << endl;
            return 0;
        }
    }
    return 0;
}

Measured memory_bytes: 4784
#pragma GCC optimize("O3")

#define _GLIBCXX_DEBUG
#include <iostream>
#include <vector>
#include <string>
#include <string_view>
#include <algorithm>
#include <cmath>
#include <iomanip>
#include <cassert>
#include <list>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <stack>
using namespace std;

/*----------macros----------*/

//output================
#define endl '\n'
#define fcout(a) cout << fixed << setprecision((int)(a))

//typedef===============
typedef long long       ll;
typedef long double     ld;
typedef pair<int, int>  Pii;
typedef pair<ll, ll>    Pll;

//const number==========
constexpr ll INF9   = (ll)1e9 + 1;
constexpr ll INF18  = (ll)1e18 + 1;
constexpr ll MOD    = 1000000007;
constexpr ll MOD2   = 998244353;
constexpr ld PI     = 3.141592653589793L;

//member================
#define pb push_back
#define eb emplace_back
#define pf push_front
#define mp make_pair
#define fi first
#define se second

//others================
#define all(x)          (x).begin(), (x).end()
#define rall(x)         (x).rbegin(), (x).rend()
#define rep(i, n)       for(int i = 0; (i) < (n); ++(i))
#define reps(i, n)      for(int i = 1; (i) <= (n); ++(i))
#define rrep(i, n)      for(int i = n - 1; (i) >= 0 ; --(i))
#define repbit(bit, n)  for(int bit = 0; (bit) < (1 << (n)); ++(bit))
#define ifbit(bit, i)   if((bit) & (1 << (i)))
#define CtoI(c)         int((c)) - int('0')
#define ItoC(c)         char((c) + '0')

//functions=============
template<typename T1, typename T2>
inline bool chmax(T1 &a, T2 b) { return a < b && (a = b, true); }

template<typename T1, typename T2>
inline bool chmin(T1 &a, T2 b) { return a > b && (a = b, true); }

//vector<int> dx = {1, 0, -1, 0}, dy = {0, 1, 0, -1};
//vector<int> dx2 = { 1,1,0,-1,-1,-1,0,1 }, dy2 = { 0,1,1,1,0,-1,-1,-1 };

/*--------additional--------*/

int n, m, q;
vector<int> a(100), b(100), c(100), d(100);
ll ans = 0;

void dfs(vector<int> _v, int _cnt, int _init){
    if(_cnt == n){
        int res = 0;
        rep(i, q){
            if(_v[b[i]] - _v[a[i]] == c[i]) res += d[i];
        }
        chmax(ans, res);
    }
    else{
        for(int i = _init; i <= m; ++i){
            vector<int> _nv = _v; _nv.pb(i);
            dfs(_nv, _cnt+1, i);
        }
    }
}

/*----------main------------*/

int main() {
/*----------fastio----------*/
    std::cin.tie(nullptr);
    std::cout.tie(nullptr);
    std::ios::sync_with_stdio(false);
/*----------solve-----------*/

    cin >> n >> m >> q;
    rep(i, q){
        cin >> a[i] >> b[i] >> c[i] >> d[i];
        --a[i], --b[i];
    }

    vector<int> v;

    dfs(v, 0, 1);

    cout << ans << endl;

return 0;
}

Measured memory_bytes: 3596
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cmath>
#include<cctype>
#include<math.h>
#include<string>
#include<string.h>
#include<stack>
#include<queue>
#include<vector>
#include<utility>
#include<set>
#include<map>
#include<stdlib.h>
#include<iomanip>

using namespace std;

#define ll long long
#define ld long double
#define EPS 0.0000000001
#define INF 1e9
#define LINF (ll)INF*INF
#define MOD 1000000007
#define rep(i,n) for(int i=0;i<(n);i++)
#define loop(i,a,n) for(int i=a;i<(n);i++)
#define all(in) in.begin(),in.end()
#define shosu(x) fixed<<setprecision(x)

#define int ll //!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

typedef vector<int> vi;
typedef vector<string> vs;
typedef pair<int,int> pii;
typedef vector<pii> vp;

int gcd(int a, int b){
    if(b==0) return a;
    return gcd(b,a%b);
}
int lcm(int a, int b){
    return a/gcd(a,b)*b;
}


signed main(void) {
    int a,b,k;
    cin >> a >> b >> k;
    for(int i = min(a,b); i > 0; i--)if(a%i == 0 && b%i == 0){
        k--;
        if(k == 0){
            cout << i << endl;
            return 0;
        }
    }
}


Measured memory_bytes: 256
use std::io::*;
use std::str::FromStr;

pub fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let stdin = stdin.lock();
    let token: String = stdin
        .bytes()
        .map(|c| c.expect("failed to read char") as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().expect("failed to parse token")
}


fn main() {
    let n = read::<i64>();

    for i in 0..50001 {
        if (i as f64*1.08) as i64 == n {
            println!("{}", i);
            return;
        }
    }
    println!(":(")
}



Measured memory_bytes: 4352
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <string>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <iomanip>
#include <utility>
#include <tuple>
#include <functional>
#include <bitset>
#include <cassert>
#include <time.h>
#define int long long
#define endl '\n'
#define INF 1000000000000000000
#define EPS 1e-10
#define all(a) a.begin(),a.end()
#define rep(i, n) for (int i = 0; i < (n); i++)
#define fi first
#define se second
#define pb push_back
#define double long double
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
typedef pair<ll, P> PP;
template<class T, class S> bool chmax(T &a, const S &b) { if (a < b) { a = b; return 1; } return 0; }
template<class T, class S> bool chmin(T &a, const S &b) { if (a > b) { a = b; return 1; } return 0; }
ll gcd(ll n, ll m) { return (m ? gcd(m, n%m) : n); }
ll lcm(ll n, ll m) { return n / gcd(n, m)*m; }

vector<vector<int>> graph(100010, vector<int>());
int x, y;

void dfs(int n, vector<bool> &vis) {
	vis[n] = true;
	for (int i : graph[n]) {
		if (i == x || vis[i]) continue;
		dfs(i, vis);
	}
}

signed main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	cout << fixed << setprecision(20);
	//modcalc();

	int n, m;
	cin >> n >> m;
	vector<int> a(m), b(m);
	vector<int> deg(n);
	rep(i, m) {
		cin >> a[i] >> b[i];
		a[i]--; b[i]--;
		deg[a[i]]++; deg[b[i]]++;
		graph[a[i]].pb(b[i]);
		graph[b[i]].pb(a[i]);
	}
	bool ans = true;
	int cnt6 = 0, cnt4 = 0;
	vector<int> p;
	rep(i, n) {
		if (deg[i] % 2) ans = false;
		if (deg[i] >= 6) cnt6++;
		if (deg[i] >= 4) {
			cnt4++;
			p.pb(i);
		}
	}
	if (cnt6 < 1 && cnt4 < 3) ans = false;
	if (!ans&&cnt4 == 2) {
		x = p[0], y = p[1];
		bool ch = false;
		for (int i : graph[x]) {
			vector<bool> g(n);
			dfs(i, g);
			if (!g[y]) ch = true;
		}
		if (ch) ans = true;
	}
	cout << (ans ? "Yes" : "No") << endl;
}


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

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

Measured memory_bytes: 256
#include<stdio.h>

int main(){
	int a,b,c,d;
	
	scanf("%1d",&a);
	scanf("%1d",&b);
	scanf("%1d",&c);
	scanf("%1d",&d);
	if(a==b&&b==c||(b==c&&c==d))printf("Yes\n");
	else printf("No\n");
}

Measured memory_bytes: 128
#include <algorithm>
#include <bits/stdc++.h>
#include<iostream>
#include<string>
using namespace std;
#define rep(i, n) for (int i = 0; i <(int)(n); i++)
#define all(x) (x).begin(), (x).end()
#define ll long long
int main(){
    int a,b,c;cin>>a>>b>>c;
    int sum=a+b+c;
    int count=0;
    int Max=max({a,b,c});
    while(sum%3!=0||sum/3<Max){
        sum+=2;
        count++;
    }
    cout<<count<<endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<queue>
#include<algorithm>
#include<cstring>
#include<cmath>
using namespace std;
int a[10];
int ans;
int main()
{
	int n;
	scanf("%d",&n);
	for(int i=1;i<=4;i++)
	{
		if(n%10==2)
			ans++;
		n=n/10;
	}
	cout<<ans;
}

Measured memory_bytes: 256
def handstand2(n):
    c = 0
    c_list = [[0 for j in range(10)] for i in range(10)]

    for k in range(n):
        c_list[int(str(k+1)[0])][int(str(k+1)[-1])] += 1

    for i, _ in enumerate(c_list):
        for j, c_i_j in enumerate(_):
            c += c_i_j*c_list[j][i]
    return c

n = int(input())

print(handstand2(n))

Measured memory_bytes: 40556
#include <bits/stdc++.h>
using namespace std;
#define _GLIBCXX_DEBUG
using ll = long long;
#define all(x) (x).begin(),(x).end()
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
#define repp(i, m, n) for (int i = (int)(m); i < (int)(n); ++i)


int main() {
  int n, cnt=0;  cin >> n;
  rep (i, n) {
    int x, y;  cin >> x >> y;
    if (x == y) ++cnt;
    else cnt = 0;
    
    if (cnt == 3) break;
  }

  if (cnt >= 3) cout << "Yes" << endl;
  else cout << "No" << endl;
}

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

int main() {
    int N;
    cin >> N;
    cout << 800*N - 200*(N/15) << endl;
}


Measured memory_bytes: 256