akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <string>
#include <cstdlib>
#include <cstdio>
#include <queue>
#include <stack>
#include <list>
#include <utility>
#include <vector>
#include <set>
#include <algorithm>
#include <cmath>
#include <climits>
#include <map>
#include <unordered_map>
#include <string.h>
#include<iomanip>
#include <iterator>
#include <locale>

#define all(a) a.begin(),a.end()
#define VV(T) vector<vector< T > >
#define rep(i,N) for(int i = 0; i <N; i++)
#define repsg(i,s,g) for(int i = s; i <g; i++)
#define name(x) #x
using namespace std;


const int INF = 10000000;
const long long INFL = (1LL<<40);
const int MOD = pow(10,9)+7;
int dy[]={0, 0, 1, -1, 0};
int dx[]={1, -1, 0, 0, 0};

typedef long long ll,LL;
typedef vector<int> vint;
typedef vector<vector<int> > vvint;
typedef vector<long long> vll, vLL;
typedef vector<vector<long long> > vvll, vvLL;
typedef pair<int,int> pii;
typedef pair<LL, LL> pLL;


// vector入力
template<typename T>
istream& operator >> (istream& is, vector<T>& vec){
    for(T& x: vec) is >> x;
    return is;
}
// vector出力
template<typename T>
ostream& operator << (ostream& os, vector<T>& vec){
    for(int i=0; i<vec.size(); i++){
        os << vec[i] << ( i+1 == vec.size() ? "" : " " );
    }
    return os;
}

template< typename T >
struct edge{
    int src, to;T cost;
    edge(int to,T cost) :src(-1),to(to),cost(cost){}
    edge(int src, int to, T cost) :src(src),to(to),cost(cost){}edge
    &operator=(const int &x){
        to =x;
        return *this;
    }
    operator int() const{ return to;}
};

double dist (double a, double b,  double c, double d){
    
    return sqrt((a-c)*(a-c) + (b-d)*(b-d));
    
}

bool check(int x,int y,vector<string> a,vector<string> b ){
    for(auto i = 0; i<b.size();i++){
        for(auto j =0; j<b.size();j++){
            if(a[x+i][y+j]!= b[i][j]) return false;
        }
    }
    return true;
}

int dist(pii a, pii b){
    return abs(a.first-b.first) + abs(a.second-b.second);
}


int main() {
    int n,k; cin>>n>>k;
    int ans = 1;
    rep(i,n) ans = min(ans*2,ans+k);
    cout<<ans<<endl;
    return 0;
}







Measured memory_bytes: 256
#include <bits/stdc++.h>
#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++)

using namespace std;

int main() {
   int n;
   cin >> n; 
   cout << (n<1000 ? "ABC" : "ABD") << endl;
}

Measured memory_bytes: 256
res = -10 ** 9
n   = int(input())
a   = int(input())
Min = int(a)

for mak in range(n - 1) :
    tem = 0
    b = int(input())
    if b < Min : Min = int(b)
    
    if   b < a : tem = b - a
    else       : tem = b - Min

    if tem > res : res = int(tem)
    a   = int(b)
print(res)

Measured memory_bytes: 7692
#include<cstdio>
#include<algorithm>
#include<cstring>

using namespace std;

int num[100100];

int main()
{
    int n,k,i;
    int a,b,q;
    long long t;
    long long total=0;
    scanf("%d",&n);
    for(i=1;i<=n;i++)
    {
        scanf("%d",&a);
        total+=a;
        num[a]++;
    }
    scanf("%d",&q);
    while(q--)
    {
        scanf("%d%d",&a,&b);
        t=num[a];
        num[a]=0;
        num[b]+=t;
        total+=t*b-t*a;
        printf("%lld\n",total);
    }
    return 0;
}


Measured memory_bytes: 2064
using System;
using System.Collections.Generic;
using System.Linq;

namespace AtCoder
{
    class Program
    {
        static void Main(string[] args)
        {
            //[summary]A - Password
            int N = int.Parse(Console.ReadLine());
            
            var ans = new List<string>();

            for(int i = 1; i <= N; i++)
            {
                for (int j = 1; j <= N; j++)
                {
                    for (int k = 1; k <= N; k++)
                    {
                        var s = i.ToString() + j.ToString() + k.ToString();
                        ans.Add(s);
                    }
                }
            }

            ans.Distinct();
            Console.WriteLine(ans.Count);
        }
    }
}

Measured memory_bytes: 11220
n=int(input())
qi=0
for i in range(1000):
    if i*(i+1) ==n*2:
        qi=i
if qi==0 : 
    print("No")
    exit()
print("Yes")
print(qi+1)
from itertools import combinations as com
A=[[] for i in range(qi+1)]
now=1
for i,j in com([i for i in range(qi+1)],2):
    A[i].append(now) ; A[j].append(now)
    now+=1

for i in range(qi+1):
    print(qi, *A[i])

Measured memory_bytes: 46812
#include<iostream>
#include<map>
using namespace std;
map<long long,long long> f;
const long long mod=1e9+7;
long long DP(long long x)
{
	if(f[x]!=0) return  f[x]%mod;
	else return f[x]=(DP(x/2)+DP((x-1)/2)+DP((x-2)/2))%mod;
 } 
int main()
{
	long long n;
	cin>>n;
	f[0]=1;
	f[1]=2;
	cout<<DP(n);
	return 0;
 } 

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

int gcm(int a, int b) {
  if (b==0) return a;
  return gcm(b, a%b);
}

int main() {
  int x,y;
  while(cin >> x >> y) {
    int a = gcm(x,y);
    cout << a << " " << x/a*y << endl;
  }
}

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

#define ll long long 
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define ar array
#define MOD 1000000007
#define all(x) (x).begin(), (x).end()
#define allr(x) (x).rbegin(), (x).rend()

ll dist(ll x, ll y) {
	return x * x + y * y;
}

int main() {
	ios::sync_with_stdio(0);
	cin.tie(0);
	
	ll n, d;
	cin >> n >> d;
	ll x, y, ans = 0;
	for (int i = 0; i < n; ++i) {
		cin >> x >> y;
		if (dist(x, y) <= d * d) {
			ans++;
		}
	}
	cout << ans << "\n";

	return 0;
}

Measured memory_bytes: 3640
if __name__ == "__main__":
  Number = int(input())

  NumList = list(map(int,input().split(" ")))

  Res = 999
  for i in range(Number-1):
    R1 = sum(NumList[0:i+1])
    R2 = sum(NumList[i+1:Number])
    if Res > abs(R1 - R2):
      Res = abs(R1 - R2)
    if Res == 0:
      break
  print(Res)

Measured memory_bytes: 3060
h,w,k=map(int,input().split())
tbl=[list(input()) for _ in range(h)]
ans=[[0]*w for _ in range(h)]
firsth=0
for i in range(h):
    if "#" in tbl[i]:
        break
    else:
        firsth+=1
c=0
for i in range(firsth,h):
    if "#" in tbl[i]:
        c+=1
        firstw=tbl[i].index("#")
        for j in range(firstw+1):
            ans[i][j]=c
        for j in range(firstw+1,w):
            if tbl[i][j]=="#":
                c+=1
            ans[i][j]=c
    else:
        for j in range(w):
            ans[i][j]=ans[i-1][j]
for i in range(firsth):
    for j in range(w):
        ans[i][j]=ans[firsth][j]
for i in range(h):
    print(*ans[i])

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

int main(){
	
	string a;
	//int n;
	int k=0;
	//cin>>n;
	while(cin>>a){
		//cin>>a;
		int f=0;
		//cout<<a.size()/2<<endl;
		for(int i=0;i<a.size()/2;i++){
			//cout<<a[i]<<a[a.size()-1-i]<<endl;
		if(a[i]!=a[a.size()-1-i])
			f=1;
		}
		if(f==0)
			k++;
		//n--;
	}
	cout<<k<<endl;
	
}

Measured memory_bytes: 1184
#include <iostream>
#include <vector>
#include <string>
#include <cstring>
#include <map>
#include <list>
#include <set>
#include <stack>
#include <deque>
#include <queue>
#include <cmath>
#include <algorithm>
#include <utility>
#include <functional>
#include <random>
#include <fstream>
#include <sstream>
#include <time.h>
// #define int long long
#define debug(x) cerr << #x << " = " << x << endl
#define FOR(i,a,b) for(int i = (a); i < (b); i++)
#define rep(i,n) for(int i = 0; i < (n); i++)
#define repr(i,n) for(int i = (n); i > -1; i--)
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
const int MOD = 1e9+7;
const ll LINF = 1e18;
const double EPS = 1e-9;


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

  // int a,b;
  // cin>>a>>b;
  // int ans;
  // if(a >= 13) {
  //   ans = b;
  // } else if(a >= 6) {
  //   ans = b / 2;
  // } else {
  //   ans = 0;
  // } 
  // cout << ans << endl;
  // ll r,d;
  // ll x[100];
  // rep(i,100) {
  //   x[i] = 0;
  // }
  // cin>>r>>d>>x[0];
  // rep(i,10) {
  //   x[i+1] = x[i] * r - d;
  //   cout << x[i+1] << endl;
  // }

  int n,m;
  cin>>n>>m;
  int l[m],r[m];
  rep(i,m) {
    cin>>l[i]>>r[i];
  }
  int lmax = 0;
  int rmin = 100000000;
  rep(i,m) {
    lmax = max(lmax, l[i]);
    rmin = min(rmin, r[i]);
  }
  int ans;
  if(lmax <= rmin) {
    cout << rmin-lmax+1 << endl;
  } else {
    cout << 0 << endl;
  }

  return 0;
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
#define REP(i, n) for (int (i) = 0; (i) < (int)(n); i++) 
#define FOR(i, a, b) for(int (i) = a; (i) < (int)b; i++)
#define RREP(i, n) for(int (i)=((int)(n)-1); (i)>=0; i--)
#define RFOR(i, a, b) for(int (i) =((int)(b)-1); (i)>=(int)a; i--)
#define ALL(v) (v).begin(),(v).end()
#define MOD 1000000007
#define NIL -1
#define FI first
#define SE second
#define MP make_pair
#define PB push_back
#define SZ(x)  (int)x.size()
#define SP(x)  setprecision((int)x)


using namespace std ;
typedef long long ll;
typedef vector<int> vint;
typedef vector<vint> vvint;
typedef vector<string> vstr;
typedef pair<int, int> pii;
const int INF = 1e9;
const ll LINF = 1e18;
const double EPS = 1e-9;
ll gcd(ll a, ll b) {return b ? gcd(b, a % b) : a;} //最大公約数
ll lcm(ll a, ll b) {return a / gcd(a, b) * b;} //最小公倍数

//-------------------------------------------------
//コピペするとこ



//-------------------------------------------------


int main()
{
  int n ;
  string s ;
  cin >> n >> s ;
  int m = SZ(s) ; 
  REP(i,m){
    int k = s.at(i) -'A' ;
    k = (k+n)%26 ;
    char kk = k+'A' ;
    cout << kk ;
  }
  cout <<endl ;
    
  return 0 ;
}

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

int main(void)
{
    int n, m, a = 0, b;
    scanf("%d %d", &n, &m);
    for (int i = 0; i < m; i++) {
        scanf("%d", &b);
        a += b;
        b = 0;
    }
    if (n >= a) {
        printf("%d", n - a);
    }
    else {
        printf("%d", -1);
    }

    return 0;
}


Measured memory_bytes: 1732
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
int dist[100005];
int arrived[100005];
int leaf[100005];
vector<int> G[100005];
int dfs(int idx, int d) {
  arrived[idx] = 1;
  dist[idx] = d;
  int f = 1;
  for (int i=0; i<G[idx].size(); i++) {
    int j = G[idx][i];
    if (arrived[j]) continue;
    f = 0;
    dfs(j, d+1);
  }
  leaf[idx] = f;
}
int dist2[100005];
int arrived2[100005];
int INF = 1 << 20;
int dfs2(int idx, int d) {
  arrived2[idx] = 1;
  if (d >= dist[idx]) d = INF;
  dist2[idx] = d;
  for (int i=0; i<G[idx].size(); i++) {
    int j = G[idx][i];
    if (arrived2[j]) continue;
    dfs2(j, d+1);
  }
}
int main() {
  ios::sync_with_stdio(false);
  int N, U, V, A, B;
  cin >> N >> U >> V;
  for (int i=0; i<N-1; i++) {
    cin >> A >> B;
    G[A].push_back(B);
    G[B].push_back(A);
  }
  dfs(V, 0);
  dfs2(U, 0);
  int ret = 0;
  for (int i=1; i<=N; i++) {
    if (dist2[i] >= INF) continue;
    if (!leaf[i]) continue;
    int d = dist[i] - 1;
    ret = max(ret, d);
  }
  cout << ret << endl;
}

Measured memory_bytes: 11520
def main():
    from math import atan, degrees
    a, b, x = (int(i) for i in input().split())
    if x/a >= a*b/2:
        tmp = (2*b - ((2*x)/(a*a))) / a
        print(degrees(atan(tmp)))
    else:
        tmp = b/((x/a)*(2/b))
        k = atan(tmp)
        print(degrees(k))


if __name__ == '__main__':
    main()


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

#define REP(i,num) for(int i=0;i<(num);++i)
#define LOOP(i) while(i--)
#define ALL(c) c.begin(),c.end()
#define PRINTALL(c) for(auto pitr=c.begin();pitr!=c.end();++pitr){cout<<*pitr;if(next(pitr,1)!=c.end())cout<<' ';}cout<<endl;
#define PAIRCOMP(c,comp) [](const pair<ll,ll>& lhs,const pair<ll,ll>& rhs){return lhs.c comp rhs.c;}

using namespace std;
using ll = long long;

constexpr ll atcoder_mod = 1e9+7;

template<typename T=int>
T in(){ T x; cin >> x; return (x); }
template<typename T=int,typename C=vector<T>>
C vecin(int N){ C x(N);REP(i,N){ x[i]=in<T>(); }return move(x); }

void vout(){ cout << endl; }
template<typename Head,typename... Tail>
void vout(Head&& h,Tail&&... t){ cout << ' ' << h;vout(forward<Tail>(t)...); }
void out(){ cout << endl; }
template<typename Head,typename... Tail>
void out(Head&& h,Tail&&... t){ cout << h;vout(forward<Tail>(t)...); }

class Data{
public:
	int A,B,C;
	Data():A(0),B(0),C(0){}
	Data(int a,int b,int c):A(a),B(b),C(c){}
};

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

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

	int N=in(),MA=in(),MB=in();
	vector<Data> D(N);
	int SA=0,SB=0;
	REP(i,N){
		D[i].A=in();
		D[i].B=in();
		D[i].C=in();

		SA+=D[i].A;
		SB+=D[i].B;
	}
	
	vector<vector<vector<int>>> dp(N+1,vector<vector<int>>(SA+1,vector<int>(SB+1,1<<30)));
	dp[0][0][0]=0;
	REP(i,N){
		REP(j,SA+1){
			REP(k,SB+1){
				chmin(dp[i+1][j][k],dp[i][j][k]);
				if(j+D[i].A<=SA && k+D[i].B<=SB) chmin(dp[i+1][j+D[i].A][k+D[i].B],dp[i][j][k]+D[i].C);
			}
		}
	}

	int minC=1<<30;
	int VA=MA,VB=MB;
	while(VA<=SA && VB<=SB){
		minC = min(minC,dp[N][VA][VB]);
		VA+=MA;
		VB+=MB;
	}
	
	out(minC>=1<<30 ? -1 : minC);
	return 0;
}


Measured memory_bytes: 9984
<?php

function dfs($first, $last) {
    if (count($last) == 0) {
        return [$first];
    }

    $res = [];
    foreach ($last as $key => $val) {
        $next_f = $first;
        $next_l = $last;

        $next_f[] = $val;
        array_splice($next_l, $key, 1);
        $res = array_merge($res, dfs($next_f, $next_l));
    }

    return $res;
}

function next_permutation($end) {
    return dfs([1], range(2, $end));
}

fscanf(STDIN, "%d %d", $n, $m);
$passes = [];
for ($i = 0; $i < $m; ++$i) {
    $passes[] = explode(' ', trim(fgets(STDIN)));
}

$perms = next_permutation($n);
$count = 0;
foreach ($perms as $perm) {
    $flg = true;
    for ($i = 0; $i < $n - 1; ++$i) {
        $tmp = [
            $perm[$i],
            $perm[$i + 1],
        ];
        $tmp2 = [
            $perm[$i + 1],
            $perm[$i],
        ];

        foreach ($passes as $pass) {
            if (
                $pass == $tmp
                || $pass == $tmp2
            ) {
                continue 2;
            }
        }

        $flg = false;
        break;
    }

    if ($flg) {
        ++$count;
    }
}

echo $count;


Measured memory_bytes: 6776
use strict;
use warnings;
package FenwickTree;
sub new{
	return bless[(0)x$_[1]],$_[0];
}
sub add{
	my$self=shift;
	my($p,$x)=@_;
	$p++;
	while($p<=@{$self}){
		$self->[$p-1]+=$x;
		$p+=$p&-$p;
	}
}
sub sum{
	my$self=shift;
	return$self->prefixsum($_[1])-$self->prefixsum($_[0]);
}
sub prefixsum{
	my$self=shift;
	my$r=shift;
	my$s=0;
	while($r>0){
		$s+=$self->[$r-1];
		$r-=$r&-$r;
	}
	return$s;
}
package main;
my($N,$Q)=split$",<>;
my$fenwicktree=FenwickTree->new($N);
my@a=split$",<>;
for(0..$#a){
	$fenwicktree->add($_,$a[$_]);
}
for(1..$Q){
	my($t,$a,$b)=split$",<>;
	if($t==0){
		$fenwicktree->add($a,$b);
	}
	else{
		print$fenwicktree->sum($a,$b),$/;
	}
}


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

#define FOR(i,n,j) for(int i=(j);i<(n);++i)
#define ssort(n) sort((n).begin(),(n).end())
#define rsort(n) sort((n).begin(),(n).end(),greater<ll>())
using ll=long long;
using ld=long double;
typedef pair<int,int> P;
typedef pair<P,int> COST;
#define repl(i,n) for(ll i=0;i<(n);++i)
#define Yes cout << "Yes" << endl
#define No cout << "No" << endl
#define YES cout << "YES" << endl
#define NO cout << "NO" << endl
using Graf=vector<vector<int>>;

Graf fr(200010);
vector<bool> flag(200010,false);

int dfs(int p){

    if(flag[p]==true){
        return 0;
    }
    flag[p]=true;
    if(fr[p].empty()){
        return 1;
    }else{
        int count=1;
        rep(i,fr[p].size()){
            count+=dfs(fr[p][i]);
        }
        return count;
    }
}
int main()
{
    int n,m;
    cin >> n >> m;
    int max_val=0;
    rep(i,m){
        int a,b;
        cin >> a >> b;
        fr[a-1].push_back(b-1);
        fr[b-1].push_back(a-1);
    }
    rep(i,n){
        if(flag[i]!=true){
            max_val=max(max_val,dfs(i));
        }
    }
    cout << max_val << endl;
}

Measured memory_bytes: 23492
#include <algorithm>
#include <iostream>
#include <string>
#include <vector>
#include <stack>
#include <cmath>
#include <functional>
#define rep(i,n) for (int i=0;i<(n);i++)

using namespace std;

int main(){
	int B, A, C;
	string str;
	vector<int> vi;

	rep(i, 3){
		int tmp;
		cin >> tmp;
		vi.push_back(tmp);
	}
	sort(vi.begin(), vi.end());

		cout << vi[0] << " " << vi[1] << " " << vi[2];

		cout << endl;
	return 0;
}

Measured memory_bytes: 1216
T = input()

mae=""
ans=""
for i in range(3):
    if i==0:
        if T[i]=="R":
            mae=T[i]
            ans+=T[i]
    elif i>0:
        if mae=="R" and T[i]=="R":
            ans+=T[i]
        elif mae!="R" and T[i]=="R":
            ans=T[i]
        mae=T[i]
print(len(ans))

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

using namespace std;

#define rep(i,n) for(int (i)=0;(i)<(int)(n);(i)++)

//-------------------------↓↓↓↓↓↓------------------------

int main(void){
    int N; cin >> N;
    char s[N + 10][N + 10];
    rep(i, N){
        rep(j, N){
            cin >> s[i][j];
        }
    }

    int ok = 0;
    rep(i, N){
        rep(j, N){
            if(s[i][j] == '#')ok = 1;
        }
    }

    if(!ok)cout << -1 << "\n";
    else{
        int line[N + 10] = {}, ans = 1e9;
        rep(i, N){
            rep(j, N){
                if(s[j][i] == '#')line[i] = 1;
            }
        }
        rep(i, N){
            int flags1 = 0;
            int flags2 = 0;
            int cnt = 0;
            rep(j, N){
                if(s[i][j] == '.'){
                    if(line[i] != 0)flags1 = 1;
                    ++cnt;
                    flags2 = 1;
                }
            }
            if(flags1 == 0)++cnt;
            if(flags2 == 0)cnt = 0;
            ans = min(ans, cnt);
        }

        rep(i, N){
            int add = 0;
            rep(j, N){
                if(s[j][i] == '.')add = 1;
            }
            if(add)++ans;
        }

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


Measured memory_bytes: 512
#include<stdio.h>
#define N 40
   
int n,pos;
int a[N],b[N];
 
void solve(int, int);
 
int main(){
   
  int i;
 
  scanf("%d",&n);
 
  for(i=0;i<n;i++){
    scanf("%d",&a[i]);
  }
 
  for(i=0;i<n;i++){
    scanf("%d",&b[i]);
  }
   
  pos=0;
 
  solve(0,n-1);
 
  printf("\n");
 
  return 0;
}
   
void solve(int l,int r){
   
  int x,i;
 
  x=a[pos];
   
  if(l>r)return;
  if(l==r){
    if(b[l]==a[0]) printf("%d",b[l]);
    else printf("%d ",b[l]);
    pos++;
    return;
  }
   
  pos++;
  for(i=l;i<=r;i++){
    if(b[i]==x)break;
  }
  solve(l,i-1);
  solve(i+1,r);
     
  if(x==a[0])printf("%d",x);
  else printf("%d ",x);
}

Measured memory_bytes: 1860
//include,namespace
 #include<bits/stdc++.h>
 #include<iostream> 
 #include <queue>
 #include <vector>
 #include <string>
 using namespace std;
//REPmacro
 #define all(x) (x).begin(),(x).end()             //ソート
 #define FOR(i,x,n)for(int i=(x);i<(n);i++)
 #define FOR_R(i,x,n) for(int i=(n-1);i>=(x);i--)
 #define REP(i, n) FOR(i, 0, n)
 #define REP_R(i, n) FOR_R(i, 0, n)
//long long(define)
 using ll = long long;
 typedef long long ll;
 typedef long long int64;
 typedef long long lint;
 typedef long long lli;

struct UnionFind {
    vector<int> par; // par[i]:iの親の番号　(例) par[3] = 2 : 3の親が2

    UnionFind(int N) : par(N) { //最初は全てが根であるとして初期化
        for(int i = 0; i < N; i++) par[i] = i;
    }

    int root(int x) { // データxが属する木の根を再帰で得る：root(x) = {xの木の根}
        if (par[x] == x) return x;
        return par[x] = root(par[x]);
    }

    void unite(int x, int y) { // xとyの木を併合
        int rx = root(x); //xの根をrx
        int ry = root(y); //yの根をry
        if (rx == ry) return; //xとyの根が同じ(=同じ木にある)時はそのまま
        par[rx] = ry; //xとyの根が同じでない(=同じ木にない)時：xの根rxをyの根ryにつける
    }

    bool same(int x, int y) { // 2つのデータx, yが属する木が同じならtrueを返す
        int rx = root(x);
        int ry = root(y);
        return rx == ry;
    }
};
////////////////いろいろあるよ//////////////////////////////////
int main(){
	long long a;
  	cin >> a;
  	long long ans = 0;
  	
  	ll one = a/500;
  	a -= (a/500)*500;
    ll two = a/5;
  	a -= (a/5)*5;
  
  	cout <<  one*1000  + two*5 << endl;
}

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

using namespace std;

typedef long long ll;
typedef pair<ll, ll> P;

#define MOD 1000000007
#define REP(i, N) for (int i = 0; i < N; ++i)
#define REP1(i, N) for (int i = 1; i <= N; ++i)
#define RREP(i, N) for (int i = N - 1; i >= 0; --i)
#define ALL(a) a.begin(), a.end()

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

int main()
{
  int N;
  cin >> N;
  vector<int> A(N + 1);
  REP1(i, N)
  cin >> A[i];
  vector<int> L(N + 2), R(N + 2);
  L[1] = R[N + 1] = 0;
  for (int i = 1; i <= N; ++i)
    L[i + 1] = gcd(L[i], A[i]);
  for (int i = N; i >= 1; --i)
    R[i] = gcd(R[i + 1], A[i]);
  int ans = 0;
  REP1(i, N)
  ans = max(ans, gcd(L[i], R[i + 1]));
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 1408
#include <bits/stdc++.h>
using namespace std;
int main(){
  long long n,a,b;
  cin>>n;
  for(int i=0;i<n;++i){
    cin>>a>>b;
    if(a==b||abs(a-b)==1){
      cout<<min(a,b)+min(a,b)-2<<endl;
    }
    else{
    long long mon=sqrt(a*b);
    if(mon*mon==a*b) --mon;
    if(mon*(mon+1)>=a*b) cout<<2*mon-2<<endl;
    else cout<<2*mon-1<<endl;
    }
  }
}

Measured memory_bytes: 256
//   _/                _/                 _/_/_/   _/
//_/_/_/_/   _/_/   _/_/_/_/   _/_/    _/       _/_/
// _/     _/    _/   _/     _/    _/  _/_/_/     _/
//_/     _/    _/   _/     _/    _/  _/    _/   _/
// _/_/   _/_/       _/_/   _/_/      _/_/     _/
#include<iostream>
#include<algorithm>
#include<cmath>
#include<iomanip>
#include<set>
#include<map>
#include<queue>
#include<vector>
using namespace std;
typedef long long ll;
const int MOD=1e9+7;
const double pi=3.14159265358979323846;
const int inf=2e9;
const ll INF=9e18;
typedef pair<int,int> P;
int main() {
  cin.tie(0),cout.tie(0);
  ios::sync_with_stdio(false);
  ll n,ans=0;
  string s;
  map<string,int> m;
  cin >> n;
  for(int i=0; i<n; i++) {
    cin >> s;
    sort(s.begin(),s.end());
    ans+=m[s];
    m[s]++;
  }
  cout << ans << endl;
}

Measured memory_bytes: 11264
#[allow(unused_imports)]
use std::cmp::{max, min, Ordering};
#[allow(unused_imports)]
use std::collections::{BTreeMap, BTreeSet, BinaryHeap, HashMap, HashSet, VecDeque};
#[allow(unused_imports)]
use std::io::{stdin, stdout, BufWriter, StdoutLock, Write};
#[allow(unused_imports)]
use std::iter::FromIterator;
#[allow(unused_macros)]
macro_rules ! input { ( source = $ s : expr , $ ( $ r : tt ) * ) => { let mut iter = $ s . split_whitespace ( ) ; let mut next = || { iter . next ( ) . unwrap ( ) } ; input_inner ! { next , $ ( $ r ) * } } ; ( $ ( $ r : tt ) * ) => { let stdin = std :: io :: stdin ( ) ; let mut bytes = std :: io :: Read :: bytes ( std :: io :: BufReader :: new ( stdin . lock ( ) ) ) ; let mut next = move || -> String { bytes . by_ref ( ) . map ( | r | r . unwrap ( ) as char ) . skip_while ( | c | c . is_whitespace ( ) ) . take_while ( | c |! c . is_whitespace ( ) ) . collect ( ) } ; input_inner ! { next , $ ( $ r ) * } } ; }
#[allow(unused_macros)]
macro_rules ! input_inner { ( $ next : expr ) => { } ; ( $ next : expr , ) => { } ; ( $ next : expr , $ var : ident : $ t : tt $ ( $ r : tt ) * ) => { let $ var = read_value ! ( $ next , $ t ) ; input_inner ! { $ next $ ( $ r ) * } } ; }
#[allow(unused_macros)]
macro_rules ! read_value { ( $ next : expr , ( $ ( $ t : tt ) ,* ) ) => { ( $ ( read_value ! ( $ next , $ t ) ) ,* ) } ; ( $ next : expr , [ $ t : tt ; $ len : expr ] ) => { ( 0 ..$ len ) . map ( | _ | read_value ! ( $ next , $ t ) ) . collect ::< Vec < _ >> ( ) } ; ( $ next : expr , chars ) => { read_value ! ( $ next , String ) . chars ( ) . collect ::< Vec < char >> ( ) } ; ( $ next : expr , bytes ) => { read_value ! ( $ next , String ) . into_bytes ( ) } ; ( $ next : expr , usize1 ) => { read_value ! ( $ next , usize ) - 1 } ; ( $ next : expr , $ t : ty ) => { $ next ( ) . parse ::<$ t > ( ) . expect ( "Parse error" ) } ; }
#[allow(dead_code)]
pub fn with_bufwriter<F: FnOnce(BufWriter<StdoutLock>) -> ()>(f: F) {
    let out = stdout();
    let writer = BufWriter::new(out.lock());
    f(writer)
}
#[allow(unused_macros)]
macro_rules ! debug { ( $ ( $ a : expr ) ,* ) => { eprintln ! ( concat ! ( $ ( stringify ! ( $ a ) , " = {:?}, " ) ,* ) , $ ( $ a ) ,* ) } ; }
#[allow(dead_code)]
fn main() {
    input!{
        n: usize,
        h: u64,
        w: u64,
        ab: [(u64, u64); n]
    }
    let mut ans = 0;
    for (a, b) in ab {
        if a >= h && b >= w {
            ans += 1;
        }
    }
    println!("{}", ans);
}

Measured memory_bytes: 4352
/*Lucky_Glass*/
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
const int N=1e5;
int n,Xor;
int num[N+3];
int main(){
	scanf("%d",&n);
	for(int i=1;i<=n;i++) scanf("%d",&num[i]),Xor^=num[i];
	printf("%s\n",Xor? "No":"Yes");
	return 0;
}

Measured memory_bytes: 512
#include<iostream>
#include <boost/multiprecision/cpp_int.hpp>
typedef boost::multiprecision::cpp_int Cint;
using namespace std;

int main(){
	Cint n,t;
	cin>>n>>t;
	Cint ans=0,x=0;
	Cint oldtime=0;
	for(Cint i=0;i<n;i++){
		cin>>x;
		if(oldtime+t>x){
			ans+=x-oldtime;
		}else{
			ans+=t;
		}		
		oldtime=x;
	}
	ans+=t;
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 256
n,m,k=map(int,input().split())
A=list(map(int,input().split()))
B=list(map(int,input().split()))

a=[0]
b=[0]
for i in range(n):
  a.append(a[i]+A[i])
for i in range(m):
  b.append(b[i]+B[i])
  
j=m
ans=0  
for i in range(n+1):
  if a[i]>k:
    break
  while b[j]>(k-a[i]):
    j-=1
  ans=max(ans,j+i)
  
print(ans)

Measured memory_bytes: 134292
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<int> VI;
ll mm=1000000000;ll MM=mm+7;
#define rep(i, n) for(int i=0;i<n;i++)
 
int main(){
  int h,w;
  cin >> h >> w ;
  vector<vector<char>> s(h,vector<char>(w));
  rep(i,h){
    rep(j,w){
		cin >> s.at(i).at(j);
    }
  }
  bool tests=true;
  rep(i,h){
    rep(j,w){
      bool a=false;
      bool b=false;
      bool c=false;
      bool d=false;
      bool test =false;
      if(i==0)a=true;
      else if(i==h-1)b=true;
      if(j==0)c=true;
      else if(j==w-1)d=true;
      if(s.at(i).at(j)=='#'){
      if(a && c){
        char A= s.at(i).at(j+1);
        char B= s.at(i+1).at(j);
        if(A=='#'||B=='#')test=true;
      }
      else if(a && d){
        char B= s.at(i+1).at(j);
         char C= s.at(i).at(j-1);
        if(B=='#'|| C=='#')test=true;
      }
      else if(c && b){
        char A= s.at(i).at(j+1);
        char D= s.at(i-1).at(j);
        if(A=='#'||D=='#')test=true;
      }
	  else if(b && d){
         char C= s.at(i).at(j-1);
        char D= s.at(i-1).at(j);
         if(C=='#'||D=='#')test=true;
      }
	  else if(a){
        char A= s.at(i).at(j+1);
        char B= s.at(i+1).at(j);
         char C= s.at(i).at(j-1);
        if(A=='#'||B=='#'||C=='#')test=true;
      }
      else if(b){
        char A= s.at(i).at(j+1);
         char C= s.at(i).at(j-1);
        char D= s.at(i-1).at(j);
        if(A=='#'||C=='#'||D=='#')test=true;
      }
      else if(c){
        char A= s.at(i).at(j+1);
        char B= s.at(i+1).at(j);
        char D= s.at(i-1).at(j);
        if(A=='#'||B=='#'||D=='#')test=true;
      }
	  else if(d){
        char B= s.at(i+1).at(j);
         char C= s.at(i).at(j-1);
        char D= s.at(i-1).at(j);
        if(B=='#'||C=='#'||D=='#')test=true;
      }
      else{
        char A= s.at(i).at(j+1);
        char B= s.at(i+1).at(j);
         char C= s.at(i).at(j-1);
        char D= s.at(i-1).at(j);
        if(A=='#'||B=='#'||C=='#'||D=='#')test=true;
      }
      }
      else{
        test=true;
      }
        if(test==0){
          tests=false;
          break;
        }
    }
    if(tests==0)break;
  }
  if(tests) cout << "Yes" << endl;
  else cout<< "No" << endl;    
}

Measured memory_bytes: 256
#include <float.h>
#include <limits.h>
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>

// 内部定数
#define D_ARRAY_MAX		200000									// 最大配列数

// 内部変数
static FILE *szpFpI;											// 入力
static int si1Array[D_ARRAY_MAX];								// 配列
static int siACnt;												// 配列数
static int siSCnt;												// 必殺技数

// 内部変数 - テスト用
#ifdef D_TEST
	static int siRes;
	static FILE *szpFpA;
	static int siTNo;
#endif

// １行出力
int
fOutLine(
	char *pcpLine				// <I> １行
)
{
	char lc1Buf[1024];

#ifdef D_TEST
	lc1Buf[0] = '\0';
	fgets(lc1Buf, sizeof(lc1Buf), szpFpA);
	if (strcmp(lc1Buf, pcpLine)) {
		siRes = -1;
	}
#else
	printf("%s", pcpLine);
#endif

	return 0;
}

// ソート関数 - int昇順
int
fSortFncIu(
	const void *pzpVal1			// <I> 値１
	, const void *pzpVal2		// <I> 値２
)
{
	int *lipVal1 = (int *)pzpVal1;
	int *lipVal2 = (int *)pzpVal2;

	// int昇順
	if (*lipVal1 > *lipVal2) {
		return 1;
	}
	else if (*lipVal1 < *lipVal2) {
		return -1;
	}

	return 0;
}

// 実行メイン
int
fMain(
)
{
	int i;
	char lc1Buf[1024];

	// 配列数・必殺技数 - 取得
	fgets(lc1Buf, sizeof(lc1Buf), szpFpI);
	sscanf(lc1Buf, "%d%d", &siACnt, &siSCnt);

	// 配列 - 取得
	for (i = 0; i < siACnt; i++) {
		fscanf(szpFpI, "%d", &si1Array[i]);
	}
	fgets(lc1Buf, sizeof(lc1Buf), szpFpI);
	qsort(si1Array, siACnt, sizeof(int), fSortFncIu);

	// 合計 - 取得
	long long llSum = 0;
	for (i = 0; i < siACnt - siSCnt; i++) {
		llSum += si1Array[i];
	}

	// 出力
	sprintf(lc1Buf, "%lld\n", llSum);
	fOutLine(lc1Buf);

	return 0;
}

// １回実行
int
fOne(
)
{
	int liRet;
	char lc1Buf[1024];

	// 入力 - セット
#ifdef D_TEST
	sprintf(lc1Buf, ".\\Test\\T%d.txt", siTNo);
	szpFpI = fopen(lc1Buf, "r");
	sprintf(lc1Buf, ".\\Test\\A%d.txt", siTNo);
	szpFpA = fopen(lc1Buf, "r");
	siRes = 0;
#else
	szpFpI = stdin;
#endif

	// 実行メイン
	liRet = fMain();

	// 残データ有無
#ifdef D_TEST
	lc1Buf[0] = '\0';
	fgets(lc1Buf, sizeof(lc1Buf), szpFpA);
	if (strcmp(lc1Buf, "")) {
		siRes = -1;
	}
#endif

	// テストファイルクローズ
#ifdef D_TEST
	fclose(szpFpI);
	fclose(szpFpA);
#endif

	// テスト結果
#ifdef D_TEST
	if (siRes == 0) {
		printf("OK %d\n", siTNo);
	}
	else {
		printf("NG %d\n", siTNo);
	}
#endif

	return 0;
}

// プログラム開始
int
main()
{

#ifdef D_TEST
	int i;
	for (i = D_TEST_SNO; i <= D_TEST_ENO; i++) {
		siTNo = i;
		fOne();
	}
#else
	fOne();
#endif

	return 0;
}



Measured memory_bytes: 1788
N = int(input())
H = list(map(int,input().split()))
hd = [H[i]-H[i+1] for i in range(0,N-1)]
c = 0
mc =[]
for i in range(N-1):
    if hd[i] >= 0:
        c +=  1
    else:
        mc.append(c)
        c = 0
mc.append(c)
print(max(mc))

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

using namespace std;

int main(int argc, const char *argv[]) {
  int a, b, c, x;
  cin >> a >> b >> c >> x;

  int ans = 0;
  for (int i = 0; i <= a; ++i) {
    for (int j = 0; j <= b; ++j) {
      for (int k = 0; k <= c; ++k) {
        int sum = 500 * i + 100 * j + 50 * k;
        if (sum == x) {
          ans++;
        }
      }
    }
  }

  cout << ans << '\n';
  return 0;
}

Measured memory_bytes: 3592
/*
 * DATE : 2017-06-03
 * Algo :
*/
#include<bits/stdc++.h>
using namespace std;
/*------- Constants---- */

#define Long                    long long
#define Ulong                   unsigned long long
#define FOR(I,A,B)              for(long long i=0; i < n ; i++ )
#define REP(i,n)                for(long long i=0; i < n ; i++ )
#define mp                      make_pair
#define pb                      push_back
#define all(x)                  (x).begin(),(x).end()
#define PI                      acos(-1.0)
#define EPS                     1e-9
#define F                       first
#define S                       second
#define lc                      ((n)<<1)
#define rc                      ((n)<<1|1)
#define db(x)                   cout << #x << " -> " << x << endl;
#define Di(x)                   int x; cin>>x
#define in(x)                   input(x)
#define in2(x,y)                input(x), input(y)
#define in3(x,y,z)              input(x), input(y),input(z)
#define ins(x)                  scanf("%s",x)
#define ind(x)                  scanf("%lf",&x)
#define ms(ara_name,value)      memset(ara_name,value,sizeof(ara_name))
#define IO                      ios_base::sync_with_stdio(0);cin.tie(0)
#define READ                    freopen("in.txt","r",stdin)
#define WRITE                   freopen("out.txt","w",stdout)

template<class T > void input(T &x){
    char c = getchar();x = 0;
    for(;(c<48 || c>57);c = getchar());
    for(;c>47 && c<58;c = getchar()) {x = (x<<1) + (x<<3) + c - 48;}
}
inline long long bigmod(long long p,long long e,long long M){
    long long ret = 1;
    for(; e > 0; e >>= 1){
        if(e & 1) ret = (ret * p) % M;
        p = (p * p) % M;
    } return ret;
}
template <class T> inline T gcd(T a,T b){if(b==0)return a;return gcd(b,a%b);}
template <class T> inline T modinverse(T a,T M){return bigmod(a,M-2,M);}

/***************************** END OF TEMPLATE *******************************/

const int N = 105;

int n;
int s[N];
int dp[N][N*N];

int main()
{

    in(n);
    int sum = 0;
    for(int i= 1;i<= n;i++){
        in(s[i]);
        sum += s[i];
    }
    dp[0][0] = 1;
    for(int i=1;i<=n;i++){
        for(int j=0;j<=sum ; j ++ ) {
            dp[i][j] = dp[i-1][j];
            if(s[i] <= j) dp[i][j] |= (dp[i-1][j-s[i]]);
        }
    }
    int ans = 0;
    for(int i=0;i<=sum;i++) {
        if(i%10==0) continue;
        if(dp[n][i]) ans = max(ans, i);
    }
    cout << ans<< endl;
    return 0;
}


Measured memory_bytes: 4608
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>	
#include<map>
#include<set>
#include<utility>
#include<cmath>
#include<cstring>
#include<queue>
#include<stack>
#include<cstdio>
#include<sstream>
#include<iomanip>
#include<assert.h>
#define loop(i,a,b) for(int i=a;i<b;i++) 
#define rep(i,a) loop(i,0,a)
#define pb push_back
#define mt make_tuple
#define all(in) in.begin(),in.end()
#define shosu(x) fixed<<setprecision(x)
using namespace std;
//kaewasuretyuui
typedef long long ll;
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<pii> vp;
typedef vector<vp> vvp;
typedef vector<string> vs;
typedef vector<double> vd;
typedef tuple<ll,ll,ll,ll> tp;
typedef vector<tp> vt;
typedef vector<vd> vvd;
typedef pair<int,pii> pip;
typedef vector<pip>vip;
const double PI=acos(-1);
const double EPS=1e-7;
const int inf=1e9;
const ll INF=2e18;
int dx[]={0,1,0,-1};
int dy[]={1,0,-1,0};
typedef ll Def;
class DIJ{
	public:
	struct edge{
		Def to,cost;
	};
	vector<vector<edge> >G;
	Def n,L;
//	vvi d;//distance
	Def d[510][50][2];
	DIJ(Def size,Def l=0){
		n=size;
		L=l;
		G=vector<vector<edge> >(n);
	}
	void add_edge(Def a,Def b,Def c){
		edge e={b,c},ee={a,c};
		G[a].pb(e);
		G[b].pb(ee);
	}
	void dij(Def a,Def b,Def c,Def D){
//		d=vvi(n,vi(L+1,inf));
		rep(i,510)rep(j,50)rep(k,2)d[i][j][k]=INF;
		d[0][D][0]=0;
//		d[s][L]=0;//now oktime ->time
		priority_queue<tp>q;
		q.push(tp(0,0,D,0));//time now v_0 n-1????????£??????
		while(!q.empty()){
			Def cost,pos,v,t;
			tie(cost,pos,v,t)=q.top();
			cost*=-1;
			q.pop();
			if(cost>d[pos][v][t])continue;
			rep(i,G[pos].size()){
				edge e=G[pos][i];
				Def to=e.to;
				Def ncost=cost+e.cost*v;
				Def nv=(a*v+b)%c;
				Def nt=t||(to==n-1);
				if(ncost<d[to][nv][nt]){
					d[to][nv][nt]=ncost;
					q.push(tp(-ncost,to,nv,nt));
				}
			}
		}
		ll out=INF;
		rep(i,50)out=min(out,d[0][i][1]);
		cout<<out<<endl;
	}
};
int main(){
	int n,m;
	cin>>n>>m;
	DIJ dij(n);
	rep(i,m){
		int a,b,c;
		cin>>a>>b>>c;
		a--;b--;
		dij.add_edge(a,b,c);
	}
	int a,b,c,d;
	cin>>d>>a>>b>>c;
	dij.dij(a,b,c,d);
}

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

int main() {
  int n, m; cin >> n >> m;
  map<int, int> road_cnt;
  
  for (int i = 0; i < m; ++i) {
    int a, b; cin >> a >> b;
    ++road_cnt[a]; ++road_cnt[b];
  }
  
  for (int i = 1; i <= n; ++i) cout << road_cnt[i] << endl;
  
  return 0;
}

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

int main()
{
  int n;
  cin >> n;
  map<string, int> polls;
  for (int i = 0; i < n; i++)
  {
    string s;
    cin >> s;
    polls[s]++;
  }
  int max_poll = 0;
  for (auto p : polls)
  {
    max_poll = max(p.second, max_poll);
  }
  for (auto p : polls)
  {
    if (p.second == max_poll)
    {
      cout << p.first << endl;
    }
  }
}


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

int main() {
  char temp1[101];
  char temp2[101];
  char temp3[101];

  cin >> temp1;
  cin >> temp2;
  cin >> temp3;

  cout << temp1[0];
  cout << temp2[0];
  cout << temp3[0];

  cout << endl;

  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
using ll=long long;
using ld=long double;
using pll=pair<ll,ll>;
using graph=vector<vector<int>>;
using wgraph=vector<vector<pll>>;

const ll MOD=1000000007;
const int dx[4]={1,0,-1,0};
const int dy[4]={0,1,0,-1};
const int ex[8]={1,1,0,-1,-1,-1,0,1};
const int ey[8]={0,1,1,1,0,-1,-1,-1};

ll abs1(ll a){
  if(a>=0)return a;
  else return -a;
}

ll pow1(ll a,ll b,ll p=LLONG_MAX){
  ll ret=1;
  while(b!=0){
    if((b&1)==1){
      ret*=a;
    }
    a*=a;
    if(a>=p)a%=p;
    b=b>>1;
  }
  return ret;
}

int digit(ll a,ll b){
  int i=0;
  while(a!=0){
    a/=b;
    i++;
  }
  return i;
}

ll gcd1(ll a,ll b){
  if(a==0 && b==0)return 0;
  ll n;
  while(a%b!=0){
    n=a%b;
    a=b;
    b=n;
  }
  return b;
}

ll solveLinear(ll n,ll m,ll c){
  if(n==0 && m==0)return 0;
  ll a[100],b[100];
  a[0]=n;b[0]=m;
  int i=1;
  while(b[i-1]!=0){
    a[i]=b[i-1];
    b[i]=a[i-1]%b[i-1];
    i++;
  }
  n=i;
  if(c%a[n-1]!=0){
    return 0;
  }
  ll x=c/a[n-1],y=0;
  for(i=1;i<n;i++){
    ll cnt=x;
    x=y;
    y=cnt-(a[n-i-1]/b[n-i-1])*y;
  }
  return x;
}

ll modRev(ll a,ll p=MOD){
  a%=p;
  ll n=solveLinear(a,p,1);
  n%=p;
  if(n<0)return n+p;
  return n;
}

ll fact(ll n,ll p=MOD){
  if(n<0)return 0;
  int i;
  ll ret=1;
  for(i=0;i<n;i++){
    ret=ret*(i+1);
    if(ret>=p)ret%=p;
  }
  return ret;
}

ll perm(ll n,ll k,ll p=MOD){
  if(n<0 || k<0 || n<k)return 0;
  int i;
  ll ret=1;
  for(i=0;i<k;i++){
    ret=ret*(n-i);
    if(ret>=p)ret%=p;
  }
  return ret;
}

ll binom(ll n,ll k,ll p=MOD){
  if(n<0 || k<0 || n<k)return 0;
  int i;
  ll ret=1,fact=1;
  for(i=0;i<k;i++){
    ret=ret*(n-i);
    fact*=i+1;
    if(ret>=p)ret%=p;
    if(fact>=p)fact%=p;
  }
  return (ret*modRev(fact))%p;
}

void pushHeap(vector<pll>& h,pll n){
  int i=h.size();
  h.push_back(n);
  while(i!=0 && h[(i-1)/2]>h[i]){
    swap(h[i],h[(i-1)/2]);
    i=(i-1)/2;
  }
  h[i]=n;
}

pll popHeap(vector<pll>& h){
  int n=h.size()-1;
  if(n==-1)return pll(0,0);
  ll i;
  pll ret=h[0];
  swap(h[0],h[n]);
  h.pop_back();
  for(i=0;i<n;){
    int j=2*i+1;
    if(j>=n)break;
    if(j!=n-1 && h[j]>h[j+1])j++;
    if(h[i]>h[j]){
      swap(h[i],h[j]);
    }
    i=j;
  }
  return ret;
}

int bis(vector<int> v,int key){
  int left=-1,right=v.size();
  while(abs1(right-left)>1){
    int mid=left+(right-left)/2;
    if(v[mid]<=key)left=mid;
    else right=mid;
  }
  return left;
}

int n;
ll x[100],y[100];

int f(ll a,ll b,ll c,ll d){
  int ret=0;
  for(int i=0;i<n;i++){
    if(a<=x[i] && x[i]<=c && b<=y[i] && y[i]<=d)ret++;
  }
  return ret;
}

int main(){
  int i,j,k,l,m,cnt=0;
  cin>>n>>k;
  for(i=0;i<n;i++)cin>>x[i]>>y[i];
  ll ans=LLONG_MAX;
  for(i=0;i<n;i++){
    for(j=0;j<n;j++){
      for(l=0;l<n;l++){
        for(m=0;m<n;m++){
          if(f(x[i],y[j],x[l],y[m])==k){
            ans=min(ans,(y[m]-y[j])*(x[l]-x[i]));
          }
        }
      }
    }
  }
  cout<<ans<<endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
//#include <atcoder/all>
#define ll long long int
#define vec vector<ll>
#define mat vector<vector<ll>>

using namespace std;
//using namespace atcoder;

const ll mod=1000000007;
const ll inf=LONG_LONG_MAX;
ll dx4[4]={1,0,-1,0};
ll dy4[4]={0,-1,0,1};
ll dx8[8]={1,0,-1,1,-1,1,0,-1};
ll dy8[8]={1,1,1,0,0,-1,-1,-1};

int main(){

  ll n;
  cin >> n;
  vec  a(n),b;
  for(ll i=0;i<n;i++)cin >> a[i];

  b=a;
  sort(b.begin(),b.end());
  b.erase(unique(b.begin(),b.end()),b.end());
  sort(a.begin(),a.end());

  ll ans=0;
  for(ll i=0;i<b.size();i++){
    ll p=b[i];
    ll c=upper_bound(a.begin(),a.end(),p)-lower_bound(a.begin(),a.end(),p);
    if(p>c)ans+=c;
    else{
      ans+=(c-p);
    }
  }

  cout << ans << endl;



  return 0;
}

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

#include <math.h>
#include <stdlib.h>


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

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

//INT_MAX	2,147,483,647 = 2*1.0e9

int main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    
    int A, B, C, K; cin >> A >> B >> C >> K;

    int M = max(max(A, B), C);

    int ans  = A + B + C - M;

    for(int i = 0; i < K; i++) M *= 2;
    ans += M;

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 256
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cstring>
#include <climits>
#include <algorithm>
#include <iostream>
#include <map>
#include <vector>
#include <set>
#include <queue>
#include <iomanip>
typedef long long LL;
using namespace std;
typedef pair<int, int> Pii;
typedef pair<LL, LL> PLL;
const int maxn = 2E5 + 5;

int main(){
	ios::sync_with_stdio(false);
	cin.tie(0); cout.tie(0);
	string S, T;
	cin >> S >> T;
	int len = S.length();
	int mp[maxn];
	bool ok = true;
	memset(mp, 0, sizeof(mp));
	for(int i = 0; i <= len - 1; i++){
		if(mp[S[i]] == 0){
			mp[S[i]] = T[i];
		}else{
			if(T[i] != mp[S[i]]){ puts("No"); return 0;}
		}
	}
	memset(mp, 0, sizeof(mp));
	for(int i = 0; i <= len - 1; i++){
		if(mp[T[i]] == 0){
			mp[T[i]] = S[i];
		}else{
			if(S[i] != mp[T[i]]){ puts("No"); return 0;}
		}
	}
	puts("Yes");
	return 0;
}

Measured memory_bytes: 1684
import sys
input = sys.stdin.buffer.readline

n, q = map(int, input().split())
g = [[] for _ in range(n)]
for i in range(n-1):
    a,b = map(int, input().split())
    a, b = a-1, b-1
    g[a].append(b)
    g[b].append(a)

X = [0]*n
for i in range(q):
    p, x = map(int, input().split())
    p = p-1
    X[p] += x

s = []
visited = [-1]*n
s.append(0)
visited[0] = 0
while s:
    v = s.pop()
    for u in g[v]:
        if visited[u] == -1:
            X[u] += X[v]
            visited[u] = 0
            s.append(u)
print(*X)


Measured memory_bytes: 89164
#include<bits/stdc++.h>
#define mp make_pair
#define ss second
#define ff first
#define ll long long int
#define tcase ll t;cin>>t;while(t--)
#define sz(a) int((a).size())
#define pb push_back
#define YES cout<<"YES\n";
#define NO cout<<"NO\n";
#define Yes cout<<"Yes\n";
#define No cout<<"No\n";
#define yes cout<<"yes\n";
#define no cout<<"no\n";
#define f(i,a,b) for(int i=a;i<b;i++)
#define in insert
#define matrix vector<vector<ll> >
#define E cout<<"\n";
#define I(x) cin>>x;
#define O(x) cout<<x;
#define all(a) a.begin(),a.end()
#define vi vector<int>
const ll M=1000000007;
const double pi=3.1415926;

using namespace std;

//ll modexpo(ll a,ll b,ll p)
//{
//    ll ans=1;
//      a=a%p;  // update a if(a>=p)
//
//        if(a==0)
//            return 0;
//
//                while(b!=0)
//                {
//                    if(b%2==1)
//                        ans=(ans*a)%p;
//
//                    a=(a*a)%M;
//                    b=b/2;
//
//                }
//                return ans;
//
//}

//ll countbit(ll n)
//{
//    ll x=0;
//    while(n!=0)
//    {
//        n=n&(n-1);
//
//        x++;
//    }
//    return x;
//}



//  vector<int> prime1;
//  int prime[10000001];
//
//void sieve(int n)
//{
//       for(long long i=2;i<=n;i++)
//       {
//         if(prime[i]==0)
//         {  prime[i]=i;
//            prime1.pb(i);
//         }
//
//            for(long long j=0;j<sz(prime1) && prime1[j]<=prime[i] && i*prime1[j]<=n;j++)
//            {
//
//                   prime[i*prime1[j]]=prime1[j];
//
//
//            }
//
//
//      }
//
// return ;
//}

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

void fastio()
{
       ios_base::sync_with_stdio(false);
   cin.tie(NULL);
   cout.tie(NULL);

}


int main()
{

     fastio();

//     tcase
//     {
//
//

     string s;
     cin>>s;
     if(s[sz(s)-1]=='s')
     {

         cout<<s+'e'+'s';
     }
     else
        cout<<s+'s';
    return 0;
}


Measured memory_bytes: 3672
#include <stdio.h>
int main(void){
    int W,H;
    char c;
    scanf("%d %d %c",&W,&H,&c);
    int a=1;
    int b=1;
    while(b<=H){
        if((a==1||a==W)&&(b==1||b==H))printf("+");
        else if(a==1||a==W)printf("|");
        else if(b==1||b==H)printf("-");
        else if(a==W/2+1&&b==H/2+1)printf("%c",c);
        else printf(".");
        if(a==W){
            b++;
            putchar('\n');
            a=0;
        }
        a++;
    }
    return 0;
}


Measured memory_bytes: 2104
// Solution by ** Abhishek Mittal **
#include<iostream>
#include<fstream>
#include<math.h>
#include<vector>
#include<string>
#include<algorithm>
#include<map>
#include<math.h>

#define FIO ios_base::sync_with_stdio(0);  cin.tie(0);
#define PI 3.14159265358979323846
#define mod 1000000007
#define ll long long
#define vll vector<long long>  

#define all(c) c.begin(), c.end()

// Used to traverse in any STL container with iterators
#define tr(container, it) for(typeof(container.begin()) it = container.begin(); it != container.end(); it++)

// Find whether element is present in given container or not
#define present(container, element) (container.find(element) != container.end())

// Finds whether element in present container is present in vector or not
#define cpresent(container, element) (find(all(container),element) != container.end())

using namespace std;

int main(){
    #ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
    freopen("error.txt", "w", stderr);
    #endif
    FIO
    
    int n;
    cin>>n;
    if(n <= 599)cout<<8<<endl;
    else if(n<=799)cout<<7<<endl;
    else if(n<=999)cout<<6<<endl;
    else if(n<=1199)cout<<5<<endl;
    else if(n<=1399)cout<<4<<endl;
    else if(n<=1599)cout<<3<<endl;
    else if(n<=1799)cout<<2<<endl;
    else if(n<=1999)cout<<1<<endl;


    return 0;

}

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

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

int main(){
    int64_t a, b, c, d;
    cin >> a >> b >> c >> d;
    //aからbの整数全部
    int64_t ans = b-a+1;
    //cで割り切れる
    int64_t tmp1 = b/c - (a-1)/c;
    //dで割り切れる
    int64_t tmp2 = b/d - (a-1)/d;
    //lcm(c, d)で割り切れる
    int64_t tmp3 = b/lcm(c,d) - (a-1)/lcm(c,d);
    
    ans = ans - tmp1 - tmp2 + tmp3;
    //cout << tmp1 << endl;
    //cout << tmp2 << endl;
    //cout << tmp3 << endl;
    cout << ans << endl;
    return 0;
}

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

using namespace std;

int main()
{
	int a,b,k,flag=1;
	scanf("%d%d%d",&a,&b,&k);
	for(int i=1;i<=k;i++)
    {
        if(flag==1)
        {
            if(a&1)
            {
                a--;
            }
            a/=2;
            b+=a;
        }
        else
        {
            if(b&1)
                b--;
                b/=2;
                a+=b;
        }
        flag=-flag;
    }
	cout<<a<<" "<<b<<endl;






    return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<math.h>

#define MAX(a, b) ((a) > (b) ? (a) : (b))
#define MIN(a, b) ((a) < (b) ? (a) : (b))

int main(void){
	int a, b, c, d;
	scanf("%d%d%d%d",&a ,&b ,&c ,&d);
	if((c-1)/b <= (a-1)/d){
		printf("Yes");
	}
	else{
		printf("No");
	}
    return 0; 
}


Measured memory_bytes: 1732
while n=gets
	n=n.to_i
	count=0
	
	a=0
	
	



	while a < 10
	b=0
		while b < 10
	c=0
			while c < 10
	d=0
				while d < 10
					if a+b+c+d == n
						count += 1
#						puts "#{a} #{b} #{c} #{d} #{count}"
					end
					d+=1
				end
				c+=1
			end
			b+=1
		end
		a+=1
	end
	puts count
end

Measured memory_bytes: 8544