akhauriyash/Code-Regression huggingface dataset:
#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,ans=0;
  cin >> N;
 
  for(int i=1;i<N+1;i++){
    if(i%3!=0 && i%5 != 0) ans = ans + i;
  }

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

Measured memory_bytes: 3588
#!/usr/bin/ruby
m={"2"=>2,"3"=>3,"4"=>4,"5"=>5,"6"=>6,"7"=>7,"8"=>8,"9"=>9,"T"=>10,"J"=>10,"Q"=>10,"K"=>10,"A"=>11}
gets.to_i.times{
	s=0
	ace=false
	m['A']=11
	gets.chomp.split.each{|e|s+=m[e];if e=='A'&&m[e]==11 then ace=true;m[e]=1 end}
	a=gets.chomp.split
	if s==21 then puts 'blackjack';next end
	a.each{|e|
		if s>17||(s==17&&!ace) then break end
		s+=m[e];if e=='A'&&m[e]==11 then ace=true;m[e]=1 end
		if s>21&&ace then s-=10;ace=false end
	}
	puts s>21?'bust':s
}

Measured memory_bytes: 9868
#include <iostream>

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

using namespace std;

int pages[52];

int main()
{
	int N;
	while(cin>>N, N)
	{
		rep(i,N) cin>>pages[i];
		pages[N] = 1<<20;

		int begin = pages[0], prev = pages[0];
		bool first = true;
		for (int i = 1; i < N + 1; i++)
		{
			int p = pages[i];
			if (prev + 1 != p)
			{
				if (first) first = false;
				else cout << " ";
				cout << begin;
				if (begin < prev) cout << "-" << prev;
				begin = p;
			}
			prev = p;
		}
		cout << endl;
	}
	return 0;
}

Measured memory_bytes: 0
#!python3

import sys
from collections import defaultdict
from math import gcd

iim = lambda: map(int, input().rstrip().split())

def resolve():
    N = input()
    it = map(int, sys.stdin.read().split())
    mod = 10**9 + 7

    d1 = [defaultdict(int), defaultdict(int)]
    z0 = 0
    for ai, bi in zip(it, it):
        if ai == 0 and bi == 0:
            z0 += 1
            continue

        ci = gcd(ai, bi)
        ai, bi = ai // ci, bi // ci

        t = ai * bi < 0
        if ai < 0:
            ai, bi = -ai ,-bi
        elif ai == 0:
            bi = -1
            t = 1

        d1[t][(ai, bi)] += 1


    a1, a2 = d1
    ans = 1
    z1 = 0
    for (ai, bi), v in a1.items():
        k2 = (bi, -ai)
        if k2 in a2:
            v2 = a2[k2]
            ans *= pow(2, v, mod) + pow(2, v2, mod) - 1
            ans %= mod
        else:
            z1 += v

    for (ai, bi), v in a2.items():
        k2 = (-bi, ai)

        if k2 in a1: continue

        z1 += v
    ans *= pow(2, z1, mod)

    print((ans-1+z0) % mod)



if __name__ == "__main__":
    resolve()


Measured memory_bytes: 83176
/******************************************************************************

                              Online C++ Compiler.
               Code, Compile, Run and Debug C++ program online.
Write your code in this editor and press "Run" button to compile and execute it.

*******************************************************************************/

#include <bits/stdc++.h>
using namespace std;

typedef long long ll;

int main()
{
    string s;
    cin>>s;
    int x=0;
    for(int i=0;i<s.size();i++)
    {
        x+=stoi(s.substr(i,1));

        x=x%9;
    }
    if(x%9==0)
    cout<<"Yes";
    else
    cout<<"No";

    return 0;
}


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

using namespace std;

int main()
{
    int n;
    cin>>n;
    vector<pair<int,int>>v;
    for(int i=0;i<n;i++)
    {
        int a;
        cin>>a;
        v.push_back({a,i+1});
    }
    sort(v.begin(),v.end());
    for(int i=0;i<n;i++)
    {
        cout<<v[i].second<<' ';
    }
    cout<<endl;
return 0;
}


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

int main(){
  int N,K;
  cin >> N >> K;
  int min=1;
  for(int i=0;i<N;i++){
    if(min < K){
      min *= 2;
    }else{
      min += K;
    }
  }
  cout << min << endl;
}

Measured memory_bytes: 256
K = int(input())

def gcd(a, b): # 最大公約数
    a = abs(a)
    b = abs(b)
    while b:
        a, b = b, a % b
    return a # int
ans = 0
for i in range(1,K+1):
    for j in range(i,K+1):
        for k in range(j,K+1):
            d = gcd(gcd(i,j),k)
            if i==j==k:
                ans += d
            elif i==j or j== k or k==i:
                ans += 3*d
            else:
                ans += 6*d
print(ans)


Measured memory_bytes: 68788
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<algorithm>
#include<cmath>
#include<queue>
#include<vector>
#include<ctime>
#include<map>
#include<bitset>
#include<set>
#include<assert.h>
#include<chrono>
#include<random>
#define LL long long
#define mp(x,y) make_pair(x,y)
#define pll pair<long long,long long>
#define pii pair<int,int>
#define SZ(x) ((int)x.size())
using namespace std;
mt19937 rnd(chrono::steady_clock::now().time_since_epoch().count());
inline LL read()
{
	LL f=1,x=0;char ch=getchar();
	while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
	while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();}
	return x*f;
}
int stack[20];
template<typename T>inline void write(T x)
{
	if(x<0){putchar('-');x=-x;}
    if(!x){putchar('0');return;}
    int top=0;
    while(x)stack[++top]=x%10,x/=10;
    while(top)putchar(stack[top--]+'0');
}
template<typename T>inline void pr1(T x){write(x);putchar(' ');}
template<typename T>inline void pr2(T x){write(x);putchar('\n');}
template<typename T>inline void chkmin(T &x,T y){x=x<y?x:y;}
template<typename T>inline void chkmax(T &x,T y){x=x>y?x:y;}
const int MAXN=300005;
int a[MAXN],n;
LL pres[MAXN];
bool check(LL S)
{
	int P=0;
	for(int i=1;i<=n;i+=2)if(pres[i]-pres[P]>=S&&pres[P]>=pres[i+1])
		P=i+1;
	return pres[n]-pres[P]>=S;
}
int main()
{
	n=read();for(int i=1;i<=n;i++)a[i]=read();
	if(!(n&1))
	{
		int s1=0,s2=0;
		for(int i=1;i<=n;i++)(i&1)?(s1+=a[i]):(s2+=a[i]);
		pr1(max(s1,s2));pr2(min(s1,s2));
	}
	else
	{
		for(int i=1;i<=n;i++)pres[i]=pres[i-1]+((i&1)?a[i]:-a[i]);
		LL l=1,r=1LL*n*1000,ans=0;
		while(l<=r)
		{
			int mid=(l+r)/2;
			if(check(mid))ans=mid,l=mid+1;
			else r=mid-1;
		}
		LL s1=0,s2=0;
		for(int i=1;i<=n;i++)if(!(i&1))s1+=a[i];
		for(int i=1;i<=n;i++)s2+=a[i];
		pr1(ans+s1);pr2(s2-(ans+s1));
	}
	return 0;
}



Measured memory_bytes: 3840
#include<stdio.h>
int main(void){
  int**data;
  int n=0;
  scanf("%d",&n);
  data = new int*[2];
  data[0]=new int[n];
  data[1]=new int[n];
  for(int i=0;i<2;i++){
    for(int j=0;j<n;j++){
      scanf("%d",&data[i][j]);
    }
  }
  for(int j=n-1;j>0;j--){
    data[1][j-1]+=data[1][j];
  }
  int temp=0,max=0;
  for(int i=0;i<n;i++){
    temp+=data[0][i];
    if(max < temp+data[1][i]){
      max = temp+data[1][i];
    }
  }
  printf("%d\n",max);
  return 0;
}

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

#define ld long double
#define eps 1e-9

bool cmp(ld A , ld B){return A + eps > B && A - eps < B;}

struct vec{
	ld x , y;
	vec(ld _x = 0 , ld _y = 0) : x(_x) , y(_y){}
	friend vec operator +(vec A , vec B){return vec(A.x + B.x , A.y + B.y);}
	friend vec operator -(vec A , vec B){return vec(A.x - B.x , A.y - B.y);}
	friend ld operator *(vec A , vec B){return A.x * B.x + A.y * B.y;}
	friend ld operator %(vec A , vec B){return A.x * B.y - A.y * B.x;}
	friend vec operator *(vec A , ld B){return vec(A.x * B , A.y * B);}
	ld len(){return sqrt(x * x + y * y);}
	ld angle(){return atan2(y , x);}
};

vec getvec(){int x , y; cin >> x >> y; return vec(x , y);}

int main(){
	int Q;
	for(cin >> Q ; Q ; --Q){
		vec A = getvec() - getvec() , B = getvec() - getvec();
		puts(A % B == 0 ? "2" : (A * B == 0 ? "1" : "0"));
	}
	return 0;
}



Measured memory_bytes: 3080
#include<bits/stdc++.h>
#define ll          long long
#define pb          push_back
#define eb          emplace_back
#define c(P)        cout<<P<<"\n"
#define pii         pair<ll,ll>
#define mi          map<ll,ll>
#define mii         map<pii,ll>
#define F           first
#define S           second
#define mp(x,y)     make_pair(x,y) 
#define exit(x)     cout<<x<<"\n",return
#define mem(a,val)  memset(a,val,sizeof(a))
#define fr(i,a,n)   for(ll i=a;i<n;i++)
#define frr(i,a,n)  for(ll i=n-1;i>=a;i--)


const ll N   =  500005;
const ll mod = 1e9 + 7;

using namespace std;
ll a[N];

void solve()
{
ll T=1;
//cin>>T;
while(T--)
  {
  string s;
  ll n,m,k,x=0,y=0,c=0,q,ans=0;
  cin>>n>>q>>s;

  for (ll i = 1; i < n; ++i)
  {
      if(s[i-1]=='A' and s[i]=='C')
      {
        a[i] = a[i-1] + 1;
      }   
      else a[i] = a[i-1];
  }
  while(q--)
  {
    cin>>x>>y;
    x--;
    y--;

      ans = a[y] - a[x];
      c(ans);
    

  }


 }
}

signed main(){
    
      ios_base::sync_with_stdio(false);   
      cin.tie(NULL);
      solve();
      return 0;
    }


Measured memory_bytes: 1872
coun=0
n=int(input())
e=0
co=['G','Y','P','W']

l=input()
l=l.split(' ')
for i in range(4):
    d=l.count(co[i])
    if d==0:
        e+=1
if e==1:
    print("Three")
else :
    print("Four")
    

Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define repr(i, a, b) for(int i = a; i < b; i++)
#define  all(x) (x).begin(),(x).end()     // 昇順ソート
#define  rall(v) (v).rbegin(), (v).rend() // 降順ソート
#define  FastIO ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0)
typedef long long ll;
typedef long long int lli;
template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return true; } return false; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return true; } return false; }

int dx[] = {1, 1, 0, -1, -1, -1, 0, 1};
int dy[] = {0, 1, 1, 1, 0, -1, -1, -1};

int main(){
    int x;
    cin >> x;
    int y = 8;
    for(int i = 400; i < 2000; i += 200){
        if (i <= x && x < i+200){
            cout << y << endl;
            return 0;
        }
        y--;
    }
}

Measured memory_bytes: 3620
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<set>
#include<map>
#include<queue>
#include<cassert>
#define PB push_back
#define MP make_pair
#define sz(v) (in((v).size()))
#define forn(i,n) for(in i=0;i<(n);++i)
#define forv(i,v) forn(i,sz(v))
#define fors(i,s) for(auto i=(s).begin();i!=(s).end();++i)
#define all(v) (v).begin(),(v).end()
using namespace std;
typedef long long in;
typedef vector<in> VI;
typedef vector<VI> VVI;
VI stk;
in lf,rt;
void clr(){
  stk.clear();
  lf=0;
  rt=0;
}
void ad(in a){
  while(rt>lf && stk[rt-1]<a)
    --rt;
  if(rt==sz(stk))
    stk.PB(0);
  stk[rt]=a;
  ++rt;
}
void rm(in a){
  if(lf<rt && stk[lf]==a)
    ++lf;
}
in bst(){
  if(lf==rt)
    return -1;
  return stk[lf];
}
VI a;
VI bs[2];
int main(){
  ios::sync_with_stdio(0);
  cin.tie(0);
  in n,m,k;
  cin>>n>>m>>k;
  a.resize(n);
  forn(i,n)
    cin>>a[i];
  forn(z,2)
    bs[z].resize(n);
  in sw=1;
  in nw=0;
  bs[nw]=a;
  forn(i,n)
    bs[nw][i]*=k;
  for(in z=1;z<k;++z){
    swap(nw,sw);
    clr();
    for(in i=n-1;i>=0;--i){
      bs[nw][i]=bst();
      if(bs[nw][i]!=-1)
	bs[nw][i]+=(k-z)*a[i];
      ad(bs[sw][i]);
      if(i+m<n)
	rm(bs[sw][i+m]);
    }
  }
  in r=0;
  forn(i,n)
    r=max(r,bs[nw][i]);
  cout<<r<<endl;
  return 0;
}


Measured memory_bytes: 3196
#include<iostream>
#include<vector>
#include<cstdio>
#include<string>
#include<cmath>
#include<math.h>
#include<algorithm>
#include<string.h>
#include <iomanip>
#include <sstream>
using namespace std;

int main() {
  int H, W;
  int ans = 0;

  cin >> H >> W;

  vector<string> s(H);
  vector<vector<int>> flg(H, vector<int>(W));
  vector<vector<int>> ttl(H, vector<int>(W));
  for(int i = 0; i < H; i++){
    cin >> s[i];
  }  
  for(int i = 0; i < H; i++){
    for(int j = 0; j < W; j++){
      if(s[i][j] == '#'){
        if(i != 0){
          if(s[i-1][j] == '.'){
            flg[i][j]++;
            ttl[i][j]++;
          }else{
            ttl[i][j]++;
          }
        }
        if(i != (H-1)){
          if(s[i+1][j] == '.'){
            flg[i][j]++;
            ttl[i][j]++;
          }else{
            ttl[i][j]++;
          }          
        }
        if(j != 0){
          if(s[i][j-1] == '.'){
            flg[i][j]++;
            ttl[i][j]++;
          }else{
            ttl[i][j]++;
          }          
        }
        if(j != (W-1)){
          if(s[i][j+1] == '.'){
            flg[i][j]++;
            ttl[i][j]++;
          }else{
            ttl[i][j]++;
          }          
        }
      }
      if((ttl[i][j] == flg[i][j]) && flg[i][j] != 0){
        ans++;
      }
    }
  }
  // for(int i = 0; i < H; i++){
  //   for(int j = 0; j < W; j++){
  //     cout << "(" << flg[i][j] << ", " << ttl[i][j] << "), " ;
  //   }
  //   cout << endl;
  // }

  // int allflg = 0;
  // for(int i = 0; i < H; i++){
  //   for(int j = 0; j < W; j++){
  //     if(flg[i][j] == ttl[i][j]){
  //       if((i == 0 && j == 0) || (i == 0 && j == (W-1)) 
  //           || (i == (H-1) && j == 0) || (i == (H-1) && j == (W-1))){
            
  //       }
  //       allflg++;
  //     }
  //   }
  // }
  if(ans > 0){
    cout << "No" << endl;
  }else{
    cout << "Yes" << endl;
  }

}


Measured memory_bytes: 256
N, M = (int(x) for x in input().split())
A = [0]*N
B = [0]*N
cost = 0
remain = M
for i in range(N):
  A[i], B[i] = (int(x) for x in input().split())
A = sorted(enumerate(A), key=lambda x:x[1])
for i in range(N):
  if remain > 0:
    buy = min(B[A[i][0]], remain)
    cost += A[i][1] * buy
    remain -= buy
  else:
    break
print(cost)

Measured memory_bytes: 22912
n = int(input())
s = [input() for _ in range(n)]
m = int(input())
t = [input() for _ in range(m)]
l = []

tmp = s.copy()
tmp = set(tmp)
tmp = list(tmp)

for i in range(len(tmp)):
    S = s.count(tmp[i])
    T = t.count(tmp[i])
    l.append(S-T)

print(max(0,max(l)))


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

using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef complex<double> P;
typedef pair<int,int> pii;
#define REP(i,n) for(ll i=0;i<n;++i)
#define REPR(i,n) for(ll i=1;i<n;++i)
#define FOR(i,a,b) for(ll i=a;i<b;++i)

#define DEBUG(x) cout<<#x<<": "<<x<<endl
#define DEBUG_VEC(v) cout<<#v<<":";REP(i,v.size())cout<<" "<<v[i];cout<<endl
#define ALL(a) (a).begin(),(a).end()

#define MOD (ll)(1e9+7)
#define ADD(a,b) a=((a)+(b))%MOD
#define FIX(a) ((a)%MOD+MOD)%MOD

int h,w;
bool yoko[2000],tate[2000];
bool mp[2000][2000];
bool res[2000][2000];

int main(){
  cin>>h>>w;
  REP(i,h)REP(j,w)cin>>mp[i][j];
  REP(i,h)REP(j,w){
    if(!mp[i][j]){
      res[i][j]^=true;
      yoko[i]^=true;
      tate[j]^=true;
    }
  }
  REP(i,h){
    REP(j,w){
      cout<<(res[i][j]^yoko[i]^tate[j])<<(j==w-1?"":" ");
    }
    cout<<endl;
  }
  return 0;
}

Measured memory_bytes: 7224
n1 = [[j, 0] for j in range(100005)]
n2 = [[j, 0] for j in range(100005)]
n = int(input())
v = list(map(int, input().split()))
for i in range(n):
    if(i % 2 == 0):
        n1[v[i]][1] += 1
    else:
        n2[v[i]][1] += 1
n1 = sorted(n1, key=lambda x:x[1], reverse=True)
n2 = sorted(n2, key=lambda x:x[1], reverse=True)

if(n1[0][0] == n2[0][0]):
    ans1 = n//2 - n1[0][1] + n//2 - n2[1][1]
    ans2 = n//2 - n1[1][1] + n//2 - n2[0][1]
    ans = min(ans1, ans2)
    print(ans)
else:
    ans = n//2 - n1[0][1] + n//2 - n2[0][1]
    print(ans)



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

using cat = long long;

cat pw(cat a, cat e, cat mod) {
	if(e <= 0) return 1;
	cat x = pw(a, e/2, mod);
	x = x * x % mod;
	return (e&1) ? x * a % mod : x;
}

int main() {
	int N, A, B;
	cin >> N >> A >> B;
	if(B == 0) {
		cout << "1\n";
		return 0;
	}
	cat mod = 998244353, ans = 0;
	vector<cat> fac(N+1, 1);
	for(int i = 1; i <= N; i++) fac[i] = fac[i-1] * i % mod;
	vector<cat> inv(N+1, 1);
	vector<int> P(N+1, 1);
	for(int i = 1; i*i <= N; i++)
		for(int j = 2*i; j <= N; j += i) P[j] = i;
	for(int i = 1; i <= N; i++) {
		if(P[i] > 1) inv[i] = 1LL * inv[i/P[i]] * inv[P[i]] % mod;
		else inv[i] = pw(i, mod-2, mod);
	}
	vector<cat> inv_fac(N+1, 1);
	for(int i = 1; i <= N; i++) inv_fac[i] = inv_fac[i-1] * inv[i] % mod;
	for(int i = 0; i <= min(A, N-B-1); i++)
		ans = (ans + fac[B+i-1]*(B-i)%mod*inv_fac[i]%mod*fac[N-1-(B-A)-2*i]%mod*inv_fac[N-B-1-i]%mod*inv_fac[A-i]) % mod;
	if(N-B == A) ans = (ans + fac[N-1] * inv_fac[N-B] % mod * (2*B-N)) % mod;
	ans = ans * inv_fac[B] % mod;
	cout << ans << "\n";
}


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

vector <int> n;
 
int main(){

	ios::sync_with_stdio(false);
        cin.tie(NULL);
	string s;
	int n,ma=-1;
	map <string,int> a;
	vector <string> b,c;
	cin>>n;
	for(int i=0;i<n;i++){
		cin>>s;
		a[s]++;
		if(a[s]==1){
			b.push_back(s);
		}
		ma=max(ma,a[s]);
	}
	for(int i=0;i<b.size();i++){
		if(a[b[i]]==ma){
			c.push_back(b[i]);
		}
	}
	sort(c.begin(),c.end());
	for(int i=0;i<c.size();i++){
		cout<<c[i]<<endl;
	}
	return 0;
}

Measured memory_bytes: 37488
#include<bits/stdc++.h>
using namespace std;
const int N=100005;
int n,a[N];
int main(){
	scanf("%d",&n);
	for (int i=1;i<=n;i++)scanf("%d",&a[i]);
	sort(a+1,a+n+1);reverse(a+1,a+n+1);
	int t=0;
	for (int i=1;i<=n+1;i++)
		if (a[i]<i){
			t=i-1;
			break;
		}
	int flag=0;	
	if (a[t+1]<a[t]){
		if ((a[t]-t)&1)flag=1;
	}
	if (a[t+1]==t){
		int k=t;
		for (int j=t;j<=n;j++)
			if (a[j]==t)k=j;
		int num=k-t;
		if (num&1)flag=1;	
	}
	if (flag)puts("First");
	else puts("Second");
}

Measured memory_bytes: 640
#include <stdio.h>
int main(){

	double v,t,y;
	double N;

	while(scanf("%lf",&v)!=EOF){
		t=v/9.8;
		y=4.9*t*t;

		for(N=1.0;5.0*N-5.0<y;N=N+1.0);
		printf("%.f\n",N);

	}

	return 0;
}

Measured memory_bytes: 648
#include<iostream>
#include<string>
#include<algorithm>
#include<cmath>
#include<vector>
#include<queue>
#include<set>
#include<map>

#define INF 1000000007
#define LINF 1000000000000000007

using namespace std;

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

Int gcd(Int x, Int y){
	if(y == 0)
		return x;
	return gcd(y, x % y);
}

Int lcm(Int x, Int y){
	return x * y / gcd(x, y);
}

bool sosuu(int x){
	bool b = 1;
	if(x == 1) b = 0;
	for(int i = 2; i * i <= x; i++){
		if(x % i == 0) {
			b = 0;
			break;
		}
	}
	return b;
}

Int n, y;

int main(){
	cin >> n >>y;
	int a = n,b = 0,c =0 ;
	Int cnt = n * 10000;
	while(cnt > y && a > 0){
		a--;
		b++;
		cnt -= 5000;
	}
	if(cnt > y){
		while(cnt > y && b > 0){
			b--;
			c++;
			cnt -= 4000;
		}
	}
	if(cnt < y){
		while(cnt < y && b > 1){
			c++;
			a++;
			b-=2;
			cnt += 1000;
		}
	}
	if(cnt != y) cout << -1 << " " << -1 << " " << -1 << endl;
	else
		cout << a << " " << b << " " << c << endl;
	
	return 0;
}

Measured memory_bytes: 256
def insertion_sort(data, g):
    global cnt
    for i in range(g, len(data)):
        v, j = data[i], i - g
        while j >= 0 and data[j] > v:
            data[j + g] = data[j]
            j = j - g
            cnt += 1
        data[j + g] = v

def shell_sort(data):
    global G
    for i in range(1, 100):
        tmp = (3 ** i - 1) // 2
        if tmp > len(data):
            break
        G.append(tmp)
    for g in list(reversed(G)):
        insertion_sort(data, g)

G, cnt = [], 0
n = int(input())
data = list(int(input()) for _ in range(n))
shell_sort(data)
print(len(G))
print(' '.join(map(str, list(reversed(G)))))
print(cnt)
print('\n'.join(map(str, data)))

Measured memory_bytes: 127864
#include<bits/stdc++.h>
#define all(vc) vc.begin(),vc.end()
#define ll long long
#define MIN(a,b) ((a)<(b)) ? (a) : (b)
#define EVEN(a) (a)%2==0 ? 1 : 0
#define fi first
#define se second
#define speed ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
using namespace std;
int MOD = 1e9+7;
int inf = 1e19;
int ji[300005], ou[300005];
int brut = 100000000000000000000;
int fDig(int i)
{
   int k;
   do
   {
      k=i;
      i/=10;
   }while(i);
   return k;
}
int main()
{
  cin.tie(0);cout.tie(0);
  int a,b;
  cin >> a >> b;
  if (a < 10 && b < 10){
    cout << a * b;
  }else{
    cout << -1;
  }





  cerr << "\nTime elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " s.\n";
}


Measured memory_bytes: 256
#include <stdio.h>

int fun1(int a, int b);
int fun2(int a, int b);

int main()
{
	int a, b;
	scanf("%d %d",&a,&b);
	
	printf("%d %d\n",fun1(a,b),fun2(a,b));
	
	return 0;
}

int fun1(int a, int b)
{
	return a*b;
}

int fun2(int a, int b)
{
	return 2*a + 2*b;
}

Measured memory_bytes: 596
#include<bits/stdc++.h>
#include<iostream>
#include<algorithm>
#include<vector>
#include<stdio.h>
#include<cstring>
#include<math.h>
#include<map>
#include<bitset>
#include<iomanip>
#include<queue>
#include<functional>
#include<stack>
#include<tuple>
#include<cassert>
using namespace std;

#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
using P = pair<int, int>;

int main() {
  string N;
  cin >> N;
  rep(i, 3) {
    if(N[i] == '7') {
      cout << "Yes" << endl;
      return 0;
    }
  }
  cout << "No" << endl;
  return 0;
}

Measured memory_bytes: 3596
#include <cmath>
#include <cstdio>
#include <vector>
#include <iostream>
#include <algorithm>
#include<set>
#include<map>
using namespace std;


int main() {
    int a, b, c,  d;
    cin >> a >> b >> c >> d;
    int m1 = min(a,b), m2 = min(c,d);
    cout << m1+m2;
    cout << endl;
}


Measured memory_bytes: 256
#define _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
int main(void)
{
	int a, b, c;
	scanf("%d", &a);
	scanf("%d", &b);
	scanf("%d", &c);
	if (a + b == c) {
		printf("Yes");
	}
	else {
		if (a + c == b) {
			printf("Yes");
		}
		else {
			if (b + c == a) {
				printf("Yes");
			}
			else {
				printf("No");
			}
		}
	}
	return 0;
}

Measured memory_bytes: 128
import java.io.*;

public class Main {
  public static void main(String[] args) throws IOException {
    BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
    
    String s = br.readLine();
    System.out.println(s.replaceAll("hi", "").equals("") ? "Yes" : "No");
    
  }
}


Measured memory_bytes: 23124
import java.io.PrintWriter

fun next() = readLine()!!
fun nextInt() = next().toInt()
fun nextLong() = next().toLong()
fun nextDouble() = next().toDouble()
fun nextList() = next().split(" ")
fun nextIntList() = nextList().map(String::toInt)
fun nextLongList() = nextList().map(String::toLong)
fun nextDoubleList() = nextList().map(String::toDouble)

val pw = PrintWriter(System.out)
fun print(s: Any = "") = pw.print(s)
fun println(s: Any = "") = pw.println(s)

fun <T> Iterable<T>.join(separator: CharSequence = ", ", prefix: CharSequence = "", postfix: CharSequence = "") = joinToString(separator, prefix, postfix)

fun main(args: Array<String>) {
    main()
    pw.flush()
}

fun main() {
    val N = nextInt()
    val D = Array(N) { nextInt() }
    println(D.distinct().size)
}

Measured memory_bytes: 35576
#include <stdio.h>
#include <stdlib.h>
#define NMAX 100000
struct node {
  int id;
  struct node *next;
};
struct node *list[NMAX];
void Insert(int a, int b);
int Dfs(int v, int c, int *color);
int main(void)
{
  int i, n, m, a, b, color[NMAX] = {0};
  long long int wb[2] = {0};
  scanf("%d %d", &n, &m);
  for (i = 0; i < n; i++) list[i] = NULL;
  for (i = 0; i < m; i++) {
    scanf("%d %d", &a, &b);
    Insert(a - 1, b - 1);
  }
  for (i = 0; i < n; i++) {
    if (color[i] == 0) {
      if (!Dfs(i, 1, color)) {
        printf("%lld\n", (long long int)(n - 1) * n / 2 - m);
        return 0;
      }
    }
  }
  for (i = 0; i < n; i++) {
     wb[(color[i]+1)/2]++;
     free(list[i]);
  }
  printf("%lld\n", wb[0] * wb[1] - m);
}

void Insert(int a, int b)
{
  struct node *p = (struct node*)malloc(sizeof(struct node));
  p->id = b;
  p->next = list[a];
  list[a] = p;
  p = (struct node*)malloc(sizeof(struct node));
  p->id = a;
  p->next = list[b];
  list[b] = p;
}

int Dfs(int v, int c, int *color)
{
  struct node *n;
  color[v] = c;
  for (n = list[v]; n != NULL; n = n->next) {
    if (color[n->id] == c) return 0;
    else if (color[n->id] == 0 && !Dfs(n->id, -c, color)) return 0;
  }
  return 1;
}

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

#define LLI long long int

using namespace std;

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

	vector<vector<int> >dp(3010,vector<int>(3010,0));
	for(int i=1;i<=s.size();i++)for(int j=1;j<=t.size();j++){
		if(s[i-1]==t[j-1])
			dp[i][j]=dp[i-1][j-1]+1;
		else
			dp[i][j]=max(dp[i-1][j],dp[i][j-1]);
	}

	string ans="";
	int i=s.size(),j=t.size();
	while(dp[i][j]!=0){
		if(dp[i-1][j]==dp[i][j])
			i--;
		else if(dp[i][j-1]==dp[i][j])
			j--;
		else{
			ans+=s[i-1];
			i--;j--;
		}
	}
	reverse(ans.begin(),ans.end());
	/*
	for(int i=0;i<=s.size();i++){
		for(int j=0;j<=t.size();j++){
			cout<<dp[i][j]<<" ";
		}
		cout<<endl;
	}
	*/
	cout<<ans<<endl;

	return 0;
}



Measured memory_bytes: 35712
def c():
    n = int(input())
    arr = []
    for _ in range(n):
        line = list(map(int, input().split() ))
        arr.append(line)
    
    dp = [[0 for _ in range(3)] for _ in range(n)]

    for i in range(n):
        for j in range(3):
            if i == 0:
                dp [i][j] = arr[i][j]
            else:
                dp[i][j] = arr[i][j] + max([x for ii, x in enumerate(dp[i-1]) if ii != j])

    return max(dp[-1])


print(c())

Measured memory_bytes: 47368
#include <iostream>
#include <vector>
#include <climits>
#include <algorithm>
#include <cmath>
#include <map>
#include <set>
#include <string>
#include <bitset>
#include <utility>
#include <numeric>
#include <queue>
#include <stack>

using ll = long long;
using namespace std;

constexpr int MOD = 1e9 + 7;
constexpr ll MOD_LL = ll(1e9 + 7);

int main(void) {
	int n;
	cin >> n;
	
	vector<int> a(n), cnt(n, 0);
	for(int i = 0; i < n - 1; ++i) {
		cin >> a[i];
		a[i]--;
		cnt[a[i]]++;
	}
	
	for(int i = 0; i < n; ++i) {
		cout << cnt[i] << endl;
	}
	
	return 0;
}


Measured memory_bytes: 4740
#pragma GCC optimize("Ofast")
#pragma GCC target("avx,avx2,fma")
#pragma GCC optimization ("unroll-loops")
#include <iostream>
#include <fstream>
#include <algorithm>
#include <vector>
#include <set>
#include <stack>
#include <map>
#include <iomanip>
#include <cmath>
#include <queue>
#include <bitset>
#include <numeric>
#include <array>
#include <cstring>
#include <random>
#include <chrono>
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define make_unique(x) sort(all((x))); (x).resize(unique(all((x))) - (x).begin())
typedef long long ll;
typedef long double ld;
using namespace std;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
int main() {

  ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);

  int ans = 0, cur = 0;

  string s;

  cin >> s;

  for(int i = 0; i < s.size(); i++) {
    if(s[i] == 'R') cur++;
    else {
      ans = max(ans, cur);
      cur = 0;
    }
  }

  ans = max(ans, cur);

  cout << ans;

  return 0;
}
/*

*/


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

using namespace std;

#define int long long
const double PI = 3.14159265358979323846;
typedef vector<int> vint;
typedef pair<int, int> pint;
const int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
const int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};
// cout << fixed << setprecision(20);

int N;
int b[110], imos[110];

signed main() {
    cin >> N;
    for (int i = 1; i <= N; i++)cin >> b[i];
    vint ans;
    for (int i = 0; i < N; i++) {
        for (int j = N; j > 0; j--) {
            if (b[j] != imos[j] + 1)continue;
            ans.push_back(b[j]);
            for (int k = j; k <= N; k++)imos[k]++;
            goto nene;
        }
        cout << -1 << endl;
        return 0;
        nene:;
    }
    for (int i = 0; i < N; i++)cout << ans[i] << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define REP(i, n) for(long long i=0; i<n; i++)
#define REPR(i, n) for(long long i=n-1; i>=0; i--)
#define FOR(i, m, n) for(long long i=m; i<=n; i++)
#define FORR(i, m, n) for(long long i=m; i>=n; i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define VSORTR(v) sort(v.rbegin(), v.rend());
#define ALL(v) (v).begin(),(v).end()
#define FIN ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
using namespace std;
using ll = long long;
using vll = vector<ll>;
using vvll = vector<vector<ll>>;
using P = pair<ll, ll>;
const ll mod = 1e9+7;
const ll inf = 1e15;

ll n,m;

int main(){FIN

    cin>>n>>m;
    vll h(n); REP(i,n) cin>>h[i];
    vector<vector<ll>> v(n);
    REP(i,m){
        ll a,b; cin>>a>>b;
        a--; b--;
        v[a].push_back(b);
        v[b].push_back(a);
    }
    ll ans=0;
    REP(i,n){
        bool highest = true;
        for(auto p:v[i]){
            if (h[p]>=h[i]){
                highest = false;
            }
        }
        if (highest) ans++;
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 9796
'''
Created on 2020/08/28

@author: harurun
'''
def main():
  import sys
  pin=sys.stdin.readline
  pout=sys.stdout.write
  perr=sys.stderr.write
  
  N=int(pin())
  A=[]
  B=[]
  for _ in [0]*N:
    a,b=map(int,pin().split())
    A.append(a)
    B.append(b)
  m=0
  for j in range(1,N+1):
    t=(A[-j]+m)%B[-j]
    if t!=0:
      m+=B[-j]-t
  print(m)
  return 
main()


Measured memory_bytes: 17672
#include <stdio.h>

long long int max(long long int a, long long int b){
	if(a>b){
		return a;
	}
	return b;
}

int main(){
	int N;
	scanf("%d",&N);
	int W;
	scanf("%d",&W);
	int w[100001];
	long long int v[100001];
	int i;
	for(i=1;i<=N;i++){
		scanf("%d",&w[i]);
		scanf("%lld",&v[i]);
	}
	long long int dp[100001][101];
	for(i=0;i<=W;i++){
		dp[i][0]=0;
	}
	int j;
	for(j=1;j<=N;j++){
		dp[0][j]=0;
	}
	for(i=1;i<=W;i++){
		for(j=1;j<=N;j++){
			if(i>=w[j]){
				dp[i][j]=max(dp[i][j-1],dp[i-w[j]][j-1]+v[j]);
			}else{
				dp[i][j]=dp[i][j-1];
			}
		}
	}
	printf("%lld",dp[W][N]);
}

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

#define rep(i,x,y) for(int i=(x);i<(y);++i)
#define debug(x) #x << "=" << (x)

#ifdef DEBUG
#define _GLIBCXX_DEBUG
#define print(x) std::cerr << debug(x) << " (L:" << __LINE__ << ")" << std::endl
#else
#define print(x)
#endif

const int inf=1e9;
const int64_t inf64=1e18;
const double eps=1e-9;

template <typename T> ostream &operator<<(ostream &os, const vector<T> &vec){
    os << "[";
    for (const auto &v : vec) {
    	os << v << ",";
    }
    os << "]";
    return os;
}

using i64=int64_t;

void solve(){
    int n;
    cin >> n;
    vector<int> even,odd;
    rep(i,0,n){
        int a;
        cin >> a;
        if(i%2==0) even.push_back(a);
        else odd.push_back(a);
    }

    if(n%2==0){
        reverse(odd.begin(),odd.end());
        vector<int> ans=odd;
        ans.insert(ans.end(),even.begin(),even.end());
        rep(i,0,n){
            cout << ans[i];
            if(i==n-1) cout << endl;
            else cout << " ";
        }
    }else{
        reverse(even.begin(),even.end());
        vector<int> ans=even;
        ans.insert(ans.end(),odd.begin(),odd.end());
        rep(i,0,n){
            cout << ans[i];
            if(i==n-1) cout << endl;
            else cout << " ";
        }
    }
}

int main(){
    std::cin.tie(0);
    std::ios::sync_with_stdio(false);
    cout.setf(ios::fixed);
    cout.precision(16);
    solve();
    return 0;
}


Measured memory_bytes: 3948
import java.util.Scanner;

public class Main{
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		int[] n = new int[9];
		int[] red = new int[9];
		int[] blue = new int[9];
		int[] green = new int[9];
		int r, g, b;
		int[] numR = new int[10];
		int[] numG = new int[10];
		int[] numB = new int[10];
		char c;
		int count;
		int t = sc.nextInt();
		for(int k = 0; k < t; k++){
			r = 0;
			g = 0;
			b = 0;
			for(int i = 1; i <= 9; i++){
				numR[i] = 0;
				numG[i] = 0;
				numB[i] = 0;
			}
			count = 0;
			for(int i = 0; i < 9; i++)
				n[i] = sc.nextInt();
			for(int i = 0; i < 9; i++){
				c = sc.next().charAt(0);
				switch(c){
				case 'R':
					red[r] = n[i];
					r++;
					break;
				case 'G':
					green[g] = n[i];
					g++;
					break;
				case 'B':
					blue[b] = n[i];
					b++;
					break;
				default:
					System.out.println("Error");
					i = -1;
					break;
				}
			}
			sort(numR, red, r);
			sort(numG, green, g);
			sort(numB, blue, b);
			count += set(numR) + set(numG) + set(numB);			
			System.out.println(count == 3 ? 1 : 0);
		}
	}
	static void sort(int[] num, int[] n, int m){
		for(int i = 0; i < m; i++){
			for(int j = 1; j <= 9; j++){
				if(n[i] == j)
					num[j]++;
			}
		}
	}
	static int set(int[] num){
		int count = 0;
		for(int i = 1; i <= 9; i++){
			for(int k = 0; k < 3; k++){
				if(num[i] >= 3){
					num[i] -= 3;
					count++;
				}else
					break;
			}
		}
		for(int i = 1; i <= 7; i++){
			if(num[i] >= 1 && num[i+1] >= 1 && num[i+2] >= 1){
				num[i]--;
				num[i+1]--;
				num[i+2]--;
				count++;
				i = 0;
			}
		}
		return count;
	}
}

Measured memory_bytes: 20816
N = int(input())
A = list(map(int, input().split()))
mod = 10**9+7
def gcd(a,b):
	if b == 0:
		return a
	return gcd(b, a%b)
LCM = A[0]
for i in range(1, N):
	GCD = gcd(LCM, A[i])
	LCM *= A[i]
	LCM //= GCD
LCM %= mod
ans = 0
for i in range(N):
	t = LCM * pow(A[i], mod-2, mod)
	ans += t
	ans %= mod

print(ans)

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

// {U}{INT,LONG,LLONG}_{MAX,MIN}
#define ALPHABET    (26)
#define INF         INT_MAX
#define MOD         (1000000007LL)

using LL  = long long;
// }}}

int main() {
    std::ios::sync_with_stdio(false);
    int n, m;cin >> n >> m;
    char a[50][50], b[50][50];
    for(int i=0;i<n;i++){
        string s;cin >> s;
        for(int j=0;j<n;j++){
            a[i][j] = s[j];
        }
    }
    for(int i=0;i<m;i++){
        string s;cin >> s;
        for(int j=0;j<m;j++){
            b[i][j] = s[j];
        }
    }

    string ans = "No";
    for(int i=0;i<n-m+1;i++){
        for(int j=0;j<n-m+1;j++){
            bool flag = true;
            for(int k=0;k<m;k++){
                for(int l=0;l<m;l++){
                    if(a[i+k][j+l] != b[k][l]){
                        flag = false;
                    }
                }
            }
            if(flag){
                ans = "Yes";
            }
        }
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
/*------------------------------------
........Bismillahir Rahmanir Rahim....
..........created by Abdul Aziz.......
------------------------------------*/
#include <iostream>
#include <algorithm>
#include <stdio.h>
#include <cmath>
#include <vector>
#include <set>
#include <map>
#include <cstring>
#include <unordered_map>
#include <queue>
#define   mod  998244353
#define   int  long long 
#define   ld   long double
#define   pb   push_back
#define   vi  vector<int> 
#define   dbg(x)  cerr << #x << " = " << x << '\n'
#define   sz(x)  (int)x.size()
#define   ff   first
#define   ss   second
#define   pii  pair<int,int>
using namespace std;

inline void solve(){
    int n,m; cin>>n>>m; 
    vi pref(n+4,0);
    int cnt=m,ans=0;
    while (m--){
      int a,b;
      cin>>a>>b;
      pref[a]++;pref[b+1]--;
    }
    for (int i=1;i<=n;i++){
      pref[i] += pref[i-1];
      if (pref[i]==cnt) ans++;
    }
    cout << ans << endl;
}

signed main()
{
    int n=1; // cin>>n;
    while (n--) solve();
    return 0;
}


Measured memory_bytes: 4052
import java.util.Scanner;

public class Main{
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);

        while (in.hasNext()){
            int n = in.nextInt();
            int sum = 0;
            int max = 0;
            for (int i = 0; i < n; i++) {
                int p = in.nextInt();
                if(p > max){
                    max = p;
                }
                sum += p;
            }
            sum -= max / 2;
            System.out.println(sum);
        }
    }
}

Measured memory_bytes: 23252
use std::io::Read;

fn main() {
    let mut buf = String::new();
    std::io::stdin().read_to_string(&mut buf).unwrap();

    let answer = solve(&buf);

    println!("{}", answer);
}

fn solve(input: &str) -> String {
    let mut iterator = input.split_whitespace();

    let s: Vec<char> = iterator.next().unwrap().chars().collect();

    for i in 0..s.len() {
        if i % 2 == 0 {
            if s[i] == 'L' {
                return "No".to_string();
            }
        } else {
            if s[i] == 'R' {
                return "No".to_string();
            }
        }
    }

    return "Yes".to_string();
}


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

int main() {
  string s;
  cin >> s;
  
  if ( s.at(2) == s.at(3) && s.at(4) == s.at(5)){
    cout << "Yes" << endl;
  }
  else{
    cout << "No" << endl;
  }
}


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

typedef long long ll;
int main()
{
    string str;
    cin>>str;
    int fnd=str.find("A");
    ll sum=1,zsum=0;
    for(int i=fnd+1;i<str.size();i++)
    {
        if(str[i]=='Z')
        {
            sum++;
            zsum=sum;
        }
        else
        {
            sum++;
        }
    }
    cout<<zsum<<endl;
    return 0;
}


Measured memory_bytes: 640
n,k=map(int,input().split())
r,s,p=map(int,input().split())
t=input()
l=[1]*n
z=1
d={'r':0,'s':0,'p':0}
for i in range(n):
    if i-k>=0 and l[i]:
        if t[i]==t[i-k]:
            if i+k<n:
                l[i+k]=0
                continue
        else:
            d[t[i]]+=1
    else:
        d[t[i]]+=1   
score=d['r']*p+d['s']*r+d['p']*s
print(score)

Measured memory_bytes: 4084
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		try (Scanner sc = new Scanner(System.in)) {
			int n = sc.nextInt();

			if(n % 2 == 0) {
				System.out.println(n);
			} else {
				System.out.println(n * 2);
			}
		}
	}
}


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

int main(){
    int x,y;
    cin >> x >> y;
    while(!(x==0&&y==0)){
        if(x<y){
            cout << x << " " << y << endl;
        }else{
            cout << y << " " << x << endl;
        }
        cin >> x >> y;
    }
    return 0;
}


Measured memory_bytes: 3084
#include <bits/stdc++.h>
#define N 501
#define M 50001
#define MAX_N N
#define rank Asdfiasofsad
using namespace std;

class UF{
public:
  int par[MAX_N],rank[MAX_N];
  UF(){for(int i=0;i<MAX_N;i++)par[i]=i,rank[i]=0;}
  UF(int n){for(int i=0;i<n;i++)par[i]=i,rank[i]=0;}
  
  int find(int x){
    if(par[x]==x)return x;
    return par[x]=find(par[x]);
  }
  
  void unite(int x,int y){
    x=find(x), y=find(y);
    if(x==y)return;
    if(rank[x]<rank[y])par[x]=y;
    else{
      par[y]=x;
      if(rank[x]==rank[y])rank[x]++;
    }
  }

  bool same(int x,int y){return find(x)==find(y);}
};

typedef pair<int,int> P;
typedef pair<int,P> PP;
vector<PP> edge;
int n,m,used[M];

int kruskal(int NG){
  UF U;
  int res=0;
  for(int i=0;i<m;i++){
    int a=edge[i].second.first;
    int b=edge[i].second.second;
    int c=edge[i].first;
    if(U.same(a,b)||i==NG)continue;
    used[i]=1;
    U.unite(a,b);
    res+=c;
  }
  for(int i=0;i<n;i++)if(!U.same(0,i))return -1;
  return res;
}

int main(){
  cin>>n>>m;
  int sum=0;
  for(int i=0,a,b,c;i<m;i++){
    cin>>a>>b>>c;
    edge.push_back(PP(c,P(a-1,b-1)));
    sum+=c;
  }

  sort(edge.begin(),edge.end());
  int cnt=m,mncost=kruskal(-1);
  for(int i=0;i<m;i++)
    if(!used[i]||kruskal(i)==mncost)cnt--,sum-=edge[i].first;

  cout<<cnt<<" "<<sum<<endl;
  return 0;
}

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

struct UnionFind {
    vector<int> data;
    int __size;
    UnionFind(int size) : data(size, -1), __size(size) { }
    bool unionSet(int x, int y) {
        if ((x = root(x)) != (y = root(y))) {
            if (data[y] < data[x]) swap(x, y);
            data[x] += data[y]; data[y] = x; __size--;
        }
        return x != y;
    }
    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 size() { return __size; }
};

int main() {
    int n;
    while (cin >> n, n) {
        vector<int> out_deg(26), in_deg(26);
        UnionFind uf(26);
        while (n--) {
            string s; cin >> s;
            int a = s.front() - 'a', b = s.back() - 'a';
            out_deg[a]++, in_deg[b]++;
            uf.unionSet(a, b);
        }
        bool ok = true;
        int cnt = 0;
        for (int i = 0; i < 26; i++) if (out_deg[i] || in_deg[i]) {
            ok &= out_deg[i] == in_deg[i];
            cnt += uf.root(i) == i;
        }
        cout << (ok && cnt == 1 ? "OK" : "NG") << endl;
    }
    return 0;
}


Measured memory_bytes: 3120
#include<bits/stdc++.h>
using namespace std;
#define ALL(obj) (obj).begin(),(obj).end()
#define RALL(obj) (obj).rbegin(),(obj).rend()
#define REP(i, n) for(int i=0;i<(n);++i)
#define RANGE(i, a, b) for(int i=(a);i<(b);++i)
#define RREP(i, n) for(int i=(n)-1;i>= 0;--i)

#define endl '\n'
#define pb push_back
#define eb emplace_back
#define pque priority_queue
#define umap unordered_map
#define uset unordered_set
#define BIG 2000000000
#define VERYBIG 1000000000000000ll
#define dcout cout<<fixed<<setprecision(20)
#define Accepted_MAGIC cin.tie(0);ios::sync_with_stdio(false)

// typedef long long ll;
using Real = long double;
#define int long long

const long long dx[]={1,0,-1,0,1,1,-1,-1}, dy[]={0,-1,0,1,1,-1,1,-1};
const long long MOD = 1e9+7;
constexpr Real eps = 1e-9, pi = acos(-1);

template<typename T> inline T GCD(T a,T b){T c;while(b!=0){c=a%b;a=b;b=c;}return a;}
template<typename T> inline T LCM(T a,T b){T c=GCD(a,b);a/=c;return a*b;}
template<typename T> inline T nCr(T a,T b){T i,r=1;for(i=1;i<=b;i++){r*=(a+1-i);r/=i;}return r;}
template<typename T> inline T nHr(T a,T b){return nCr(a+b-1,b);}
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;}

typedef pair<int, int> INTP;
typedef vector<int> INTV;
struct edge2 {int to, cost;};
struct edge3 {int from, to, cost;};

signed main(void){
  Accepted_MAGIC;
  
  int H, W; cin >> H >> W;
  if(H == 1 or W == 1){
    cout << 1 << endl;
    return 0;
  }
  if((H*W) & 1){
    if(W & 1) cout << H*W/2 + 1 << endl;
    else cout << H*W/2 << endl;
  } else {
    cout << H*W/2 << endl;
  }
}

Measured memory_bytes: 256
A,B = map (int,input().split())
eight = [0] * 2000
ten = [0] * 2000
for i in range(2000):
    eight[i] =(float(i+1) * 0.08)//1
    ten[i] = (float(i+1) * 0.1)//1
ans = 0
for i in range(2000):
    if A == eight[i] and B == ten[i]:
        ans =  i + 1
        break
if ans == 0:
    print(-1)
else:
    print(ans)

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

#define rep(i,j,n) for(int i=(j);i<(n);i++)
#define rep2(i,j,n) for(int i=(j);i<=(n);i++)
#define all(i) i.begin(),i.end()
#define INF 1e9

typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef vector<string> vs;
typedef vector<vector<string>> vvs;
typedef pair<int, int> pi;
typedef long long i64;

int main() {
	int x, y;
	set<int> a{ 1,3,5,7,8,10,12 };
	set<int> b{ 4,6,9,11 };
	cin >> x >> y;
	if ((a.count(x) && a.count(y)) || (b.count(x) && b.count(y))) cout << "Yes\n";
	else cout << "No\n";
}

Measured memory_bytes: 256
/*Lucky_Glass*/
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<vector>
using namespace std;
struct Point
{
	int x,y;
}blu[105],red[105];
int n;
vector<int> lec[205];
int mat[205];bool vis[205];
bool DFS(int u)
{
	for(int i=0;i<lec[u].size();i++)
	{
		int v=lec[u][i];
		if(vis[v]) continue;
		vis[v]=true;
		if(mat[v]==-1 || DFS(mat[v]))
		{
			mat[v]=u;
			return true;
		}
	}
	return false;
}
int Solve()
{
	int ret=0;
	memset(mat,-1,sizeof mat);
	for(int u=0;u<n;u++)
	{
		memset(vis,false,sizeof vis);
		if(DFS(u)) ret++;
	}
	return ret;
}
int main()
{
	scanf("%d",&n);
	for(int i=0;i<n;i++)
		scanf("%d%d",&red[i].x,&red[i].y);
	for(int i=0;i<n;i++)
		scanf("%d%d",&blu[i].x,&blu[i].y);
	for(int i=0;i<n;i++)
		for(int j=0;j<n;j++)
			if(blu[i].x>red[j].x && blu[i].y>red[j].y)
				lec[i].push_back(j+n),lec[j+n].push_back(i);
	printf("%d\n",Solve());
	return 0;
}

Measured memory_bytes: 256
n = int(input())
lst = list(map(int, input().split()))
hlst = [0]
for h in lst:
  if hlst[-1] != h:
    hlst.append(h)
hlst.append(0)
ans = 0
l = len(hlst)
for i in range(1, l - 1):
  if hlst[i - 1] < hlst[i] and hlst[i] > hlst[i + 1]:
    ans += hlst[i]
  elif hlst[i - 1] > hlst[i] and hlst[i] < hlst[i + 1]:
    ans -= hlst[i]
print(ans)

Measured memory_bytes: 61992
#include <bits/stdc++.h>
using namespace std;
using ll = long long;

signed
main(){
		int n;
		while(cin >> n && n!=0)
		{
				vector<int> al(26,0);
				vector<char> c(n);

				bool flag = true;
				for(int i=0;i<n;i++)
				{
						cin >> c[i];
				}

				for(int i=1;i<=n;i++)
				{
						al[c[i-1]-'A']++;
						int rest = n - i;

						auto ma_itr = max_element(al.begin(),al.end());
						int tmp = *ma_itr;

						//ma_itr以外での最大値を求めたい
						*ma_itr = -100;
						auto ma2_itr = max_element(al.begin(), al.end());
						*ma_itr = tmp;

						if(*ma_itr <= *ma2_itr + rest){

						}else{
								cout << char('A'+ma_itr-al.begin()) << " " << i << endl;
								flag = false;
								break;
						}
				}
				if(flag){
						cout << "TIE" << endl;
				}
		}
}


Measured memory_bytes: 3008
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<ll> vec;
typedef vector<vec> mat;
typedef pair<ll,ll> pll;
const ll mod=1e9+7;
//const ll mod=998244353;
const ll inf=1LL<<61;

typedef pair<ll,pll> ppll;
vec idy={0,1,0,-1};
vec idx={1,0,-1,0};

int main() {
  ll h,w,k;
  cin >> h >> w >> k;
  vector<string> maze(h);
  for(ll i=0;i<h;i++) cin >> maze[i];
  mat d(h,vec(w,-1));
  priority_queue<ppll,vector<ppll>,greater<ppll>> q;
  ll sy,sx;
  for(ll i=0;i<h;i++) for(ll j=0;j<w;j++) if(maze[i][j]=='S') sy=i,sx=j;
  q.push({0,{sy,sx}});
  while(q.size()) {
    ll fy=q.top().second.first;
    ll fx=q.top().second.second;
    ll fd=q.top().first;
    q.pop();
    if(d[fy][fx]>-1) continue;
    d[fy][fx]=fd;
    for(ll i=0;i<4;i++) {
      ll ny=fy+idy[i];
      ll nx=fx+idx[i];
      ll nd=fd+1;
      if(ny>-1&&nx>-1&&ny<h&&nx<w&&nd<=k&&maze[ny][nx]!='#') {
        q.push({nd,{ny,nx}});
      }
    }
  }
  for(ll i=0;i<h;i++) {
    if(d[i][0]>-1||d[i][w-1]>-1) {
      cout << 1 << endl;
      return 0;
    }
  }
  for(ll i=0;i<w;i++) {
    if(d[0][i]>-1||d[h-1][0]>-1) {
      cout << 1 << endl;
      return 0;
    }
  }
  for(ll i=0;i<h;i++) for(ll j=0;j<w;j++) if(d[i][j]>-1) d[i][j]=-1,q.push({0,{i,j}});
  while(q.size()) {
    ll fy=q.top().second.first;
    ll fx=q.top().second.second;
    ll fd=q.top().first;
    q.pop();
    if(d[fy][fx]>-1) continue;
    d[fy][fx]=fd;
    for(ll i=0;i<4;i++) {
      ll ny=fy+idy[i];
      ll nx=fx+idx[i];
      ll nd=fd+1;
      if(ny>-1&&nx>-1&&ny<h&&nx<w) {
        q.push({nd,{ny,nx}});
      }
    }
  }
  ll mi=inf;
  for(ll i=0;i<h;i++) {
    mi=min({mi,d[i][0],d[i][w-1]});
  }
  for(ll i=0;i<w;i++) {
    mi=min({mi,d[0][i],d[h-1][i]});
  }
  cout << (mi+k-1)/k+1 << endl;
}

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

int main()
{
    int n, k;
    int count = 0;
    cin >> n >> k;
    while (n > 0)
    {
        n /= k;
        count++;
    }
    cout << count << endl;

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main() {
  string S;
  cin >> S;
  int flag = 1;
  for (int i = 0; i < S.size(); i++) {
    if (i % 2 == 0 && S.at(i) == 'L') {
      flag--;
      break;
    }
    if (i % 2 == 1 && S.at(i) == 'R') {
      flag--;
      break;
    }
  }
  if (flag) {
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }
}

Measured memory_bytes: 256