akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <iomanip>
#include <vector>
#include <set>
#include <string>
#include <queue>
#include <algorithm>
#include <map>
#include <cmath>
#include <numeric>
#include <list>
#include <stack>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <tuple>

#define rep(i, n) for (int i = 0; i < (n); i++)
#define rep1(i, n) for (int i = 1; i <= (n); i++)
#define show(a, n) rep(i,n) {cout<<a[i]<<' ';} cout<<endl
#define show2(a, n, m) rep(i, n) { rep(j, m) {cout << a[i][j] << ' ';} cout << endl;} 
#define chmin(a, b) a = min(a, b)
#define chmax(a, b) a = max(a, b)

using namespace std;
typedef vector<int> vi;
typedef pair<int, int> pii;
typedef long long ll;
typedef vector<ll> vll;
typedef pair<long long, long long> pll;
typedef long double ld;

const int INF = 1 << 30;
const long long INFL = 1LL << 60;
const int MOD = 1000000007;
const int MAX = 100000;
const int N = 100010;

struct mint {
	ll x;
	mint(ll x=0):x((x%MOD+MOD)%MOD){}
	mint operator-() const { return mint(-x);}
	mint& operator+=(const mint a) {if ((x+=a.x)>=MOD) x-=MOD; return *this;}
	mint& operator-=(const mint a) {if ((x+=MOD-a.x)>=MOD) x-=MOD; return *this;}
	mint& operator*=(const mint a) {(x*=a.x)%=MOD; return *this;}
	mint operator+(const mint a) const {mint res(*this); return res+=a;}
	mint operator-(const mint a) const {mint res(*this); return res-=a;}
	mint operator*(const mint a) const {mint res(*this); return res*=a;}
	mint pow(ll t) const {
		if (!t) return 1;
		mint a = pow(t>>1);
		a *= a;
		if (t&1) a *= *this;
 		return a;
	}

	// for prime mod
	mint inv() const { return pow(MOD-2);}
	mint& operator/=(const mint a) { return (*this) *= a.inv();}
	mint operator/(const mint a) const {mint res(*this); return res/=a;}
};

int main() {
//	cout << fixed << setprecision(15);
	ll n, k;
	cin >> n >> k;
	mint ans(0);
	for(int i = k; i <= n + 1; i++) {
		ans += i * (n - i + 1) + 1;
	}
	cout << ans.x << endl;
}


Measured memory_bytes: 3640
import java.util.*;
public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		long A = sc.nextLong() - 1;
		long B = sc.nextLong();
		long C = sc.nextLong();
		long D = sc.nextLong();
		long LCM = C * D / gcd(C, D);
		long ans = B - A;
		ans -= B / C + B / D;
		ans += B / LCM;
		ans += A / C + A / D;
		ans -= A / LCM;
		System.out.println(ans);
	}
	public static long gcd(long a, long b) {
		return b == 0 ? a : gcd(b, a % b);
	}
}

Measured memory_bytes: 21972
#include <iostream>

using namespace std;

int main()
{


// 1. change comma seperations into spaces : problem A.

string s;
cin>>s;
for(int i=0;i<s.length();++i){
    if(s[i] == ','){
        s[i]=' ';
    }
}

cout<<s<<endl;
return 0;
}

Measured memory_bytes: 256
// Author: 23forever
#include <iostream>
#include <cstdio>
#include <cmath>
#include <cstring>
#include <vector>
#include <queue>
#define mp make_pair
#define fi first
#define se second
#define pii pair<int, int>
typedef long long LL;
const int MAXN = 1000000;
using namespace std;

inline void enableFileIO() {
  freopen("test.in", "r", stdin);
  freopen("test.out", "w", stdout);
}

inline int read() {
  int x = 0, w = 1;
  char c = ' ';

  while (c < '0' || c > '9') {
    c = getchar();
    if (c == '-') w = -1;
  }
  while (c >= '0' && c <= '9') {
    x = (x << 1) + (x << 3) + (c ^ 48);
    c = getchar();
  }

  return x * w;
}

pii dp[MAXN + 5];
int a[MAXN + 5];
int n, len;

void init() {
  //enableFileIO();

  n = read();
  len = (1 << n);
  for (int i = 0; i < len; ++i) {
    a[i] = read();
    dp[i] = mp(a[i], -1);
  }
}

void upd(pii &a, int b) {
  if (b > a.se) {
    a.se = b;
    if (a.se > a.fi) swap(a.fi, a.se);
  }
}

int main() {
  init();

  for (int k = 0; k < n; ++k) {
    for (int i = 0; i < len; ++i) {
      if (!(i & (1 << k))) {
        int nxt_state = i | (1 << k);
        upd(dp[nxt_state], dp[i].fi);
        upd(dp[nxt_state], dp[i].se);
      }
    }
  }
 
  int ans = -1;
  for (int k = 1; k < len; ++k) {
    ans = max(ans, dp[k].fi + dp[k].se);
    printf("%d\n", ans);
  }
  return 0;
}

Measured memory_bytes: 8192
#include<iostream>
#include<vector>
#include<string>
#include<cmath>
#include<algorithm>
#include<numeric>
#include<map>
#include<unordered_map>
#include<queue>
#include<deque>
 
using namespace std;
using ll=long long;
#define rep(i,n)  for(ll i=0;i<n;++i)
#define all_map(itr,mp) for(auto itr=mp.begin();itr!=mp.end();itr++)
#define ALL(a) (a).begin(),(a).end()
 
 
int main(){
    ll n;
    cin >> n;

    vector<vector<ll>> g(n+1);

    vector<ll> ord;
    rep(i, n-1){
        ll a, b;
        cin >> a >> b;
        a--, b--;
        g[a].push_back(b);
        g[b].push_back(a);
        ord.push_back(max(a, b));
    }

    ll color[n];
    vector<pair<ll, ll>> p(n-1);

    queue<ll> que;
    que.push(0);
    color[0] = 0;
    
    bool visited[n];
    rep(i, n)visited[i] = false;
    visited[0] = true;

    ll ans = 1;

    while(!que.empty()){
        ll pos = que.front();
        que.pop();
        ll col = 1;
        rep(i, g[pos].size()){
            ll chil = g[pos][i];
            if(visited[chil])continue;
            if(col == color[pos])col++;
            visited[chil] = true;
            que.push(chil);
            color[chil] = col;
            ans = max(ans, col);
            col++;
        }
    }

    cout << ans << endl;
    rep(i, n-1)cout << color[ord[i]] << endl;
    


}

Measured memory_bytes: 9844
#include <bits/stdc++.h>
using namespace std;
 
int main(){
string S;
  cin >> S;
  if(S.at(0) == S.at(1) && S.at(0) == S.at(2) &&S.at(0) == S.at(3))
    cout << "No" << endl;
  else if(S.at(0) == S.at(1) && S.at(2) == S.at(3)) 
    cout << "Yes" << endl;
    else if(S.at(0) == S.at(2) && S.at(1) == S.at(3))
	cout << "Yes" << endl;
	else if(S.at(0) == S.at(3) && S.at(1) == S.at(2))
	cout << "Yes" << endl;
  else 
    cout << "No" << endl;
}

Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main() {
  int R;
  cin >> R;
  string ans;
  if (R < 1200){
    ans = "ABC";
  } else if (R < 2800) {
    ans = "ARC";
  } else {
    ans = "AGC";
  }
  cout << ans << endl;
}

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

int main() {
  double a,b,x;
  cin>>a>>b>>x;
  double c=2*x/(a*a)-b;
  double ans;
  if (c<0) {
    c=x*2/(a*b);
    ans=atan(b/c)/M_PI*180;;
  }
  else {
    if (b-c==0) ans=0.0;
  	ans=atan((b-c)/a)/M_PI*180;
  }
  printf("%.10lf\n",ans);
  return 0;
}

Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ProgramingStudying2
{
    class Program
    {

        static void Main(string[] args)
        {
            var n = int.Parse(Console.ReadLine());
            var L = Console.ReadLine().Split().Select(int.Parse).ToList();
            L.Sort();

            var ans = 0;

            for(int i = 0; i < n - 2; i++)
            {
                for (int j = i + 1; j < n - 1; j++)
                {
                    if(L[i] + L[j] <= L[j + 1])
                    {
                        continue;
                    }
                    if(L[i] + L[j] > L[n - 1])
                    {
                        ans += n - 1 - j;
                        continue;
                    }

                    var ub = n - 1;
                    var lb = j + 1;
                    while(ub - lb > 1)
                    {
                        var mid = (ub + lb) / 2;
                        if(L[i] + L[j] > L[mid])
                        {
                            lb = mid;
                        }
                        else
                        {
                            ub = mid;
                        }
                    }
                    ans += lb - j;
                }
            }
            Console.WriteLine(ans);
        }
    }
}

Measured memory_bytes: 28696
A=[]
for i in range(3):
    P=list(map(int,input().split()))
    A.append(P)
N=int(input())
b=[]
for i in range(N):
    p=int(input())
    b.append(p)
    
for i in range(N):
    for j in range(3):
        if b[i] in  A[j]:
            q= A[j].index(b[i])
            A[j][q]='O'

if A[0].count('O')==3:
    print('Yes')
elif A[1].count('O')==3:
    print('Yes')
elif A[2].count('O')==3:
    print('Yes')
elif A[0][0]==A[1][0] and A[1][0]==A[2][0]:
    print('Yes')
elif A[0][1]==A[1][1] and A[1][1]==A[2][1]:
    print('Yes')
elif A[0][2]==A[1][2] and A[1][2]==A[2][2]:
    print('Yes')
elif A[0][0]==A[1][1] and A[1][1]==A[2][2]:
    print('Yes')
elif A[0][2]==A[1][1] and A[1][1]==A[2][0]:
    print('Yes')
else:
    print('No')

Measured memory_bytes: 9316
#include<bits/stdc++.h>
#define Fail puts("NO"),exit(0);
#define eps 1e-10
#define maxn 1010
#define maxm 100010
#define inf 1000000007
#define mod 998244353
#define pi acos(-1)
#define mp(x,y) make_pair(x,y)
#define fi first
#define se second
using namespace std;
typedef long long ll;
typedef unsigned int uint;
typedef unsigned long long ull;
typedef pair<int,int>pii;
typedef bitset<maxn> bit;
int read()
{
    int x=0,f=1;
    char ch=getchar();
    while(ch-'0'<0||ch-'0'>9){if(ch=='-') f=-1;ch=getchar();}
    while(ch-'0'>=0&&ch-'0'<=9){x=x*10+ch-'0';ch=getchar();}
    return x*f;
}
int n,p1,p2,p3,p4,s,t;
int head[maxn*2],nxt[maxn*20],to[maxn*20],c[maxn*20],v[maxn*20],tot=1;
void add(int x,int y,int z,int u)
{
    ++tot;
    nxt[tot]=head[x];
    head[x]=tot;
    to[tot]=y;
    c[tot]=z;
    v[tot]=u;
}
void addx(int x,int y,int z,int u)
{
    add(x,y,z,u);
    add(y,x,0,-u);
}
ll ans;
ll dis[maxn*2];
int pre[maxn*2],pre_num[maxn*2],vis[maxn*2];
queue<int>q;
int spfa()
{
    for(int i=1;i<=t;i++)  dis[i]=-1e16;
    q.push(s);dis[s]=0;vis[s]=1;
    while(q.size())
    {
        int now=q.front();q.pop();vis[now]=0;
        for(int i=head[now];i;i=nxt[i])
        {
            if(dis[to[i]]<dis[now]+v[i]&&c[i])
            {
                dis[to[i]]=dis[now]+v[i];
                pre[to[i]]=now;
                pre_num[to[i]]=i;
                if(!vis[to[i]])  q.push(to[i]),vis[to[i]]=1;
            }
        }
    }
    if(dis[t]==-1e16)  return 0;
    int di=inf;
    for(int i=t;i!=s;i=pre[i])  di=min(di,c[pre_num[i]]);
    for(int i=t;i!=s;i=pre[i])  c[pre_num[i]]-=di,c[pre_num[i]^1]+=di;
    ans+=dis[t]*di;
    return di;
}
int main()
{
    n=read();p1=2*n+1;p2=p1+1;p3=p2+1;p4=p3+1;s=p4+1;t=s+1;
    for(int i=1;i<=n;i++)
    {
        int x=read(),y=read(),z=read();
        addx(s,i,z,0);
        addx(i,p1,inf,x+y);
        addx(i,p2,inf,x-y);
        addx(i,p3,inf,-x+y);
        addx(i,p4,inf,-x-y);
    }
    for(int i=1;i<=n;i++)
    {
        int x=read(),y=read(),z=read();
        addx(i+n,t,z,0);
        addx(p1,i+n,inf,-x-y);
        addx(p2,i+n,inf,-x+y);
        addx(p3,i+n,inf,x-y);
        addx(p4,i+n,inf,x+y);
    }
    while(spfa()){};
    printf("%lld\n",ans);
    return 0;
}

Measured memory_bytes: 640
#CODE FESTIVAL 2016 Final-C
"""
グラフが連結であるかどうかを判定せよ？
距離が2以下になっているか判定せよかと思ったが、つながってればいいっぽい？
dfsで全部回れば良い
"""
import sys
from collections import deque
readline = sys.stdin.buffer.readline
def even(n): return 1 if n%2==0 else 0
n,m = map(int,readline().split())
g = [[] for i in range(m)] #その言語を誰が使えるか
h = [] #誰がどの言語を使えるか
for i in range(n):
    lst1 = list(map(int,readline().split()))
    lst1 = lst1[1:]
    for j in lst1:
        g[j-1].append(i)
    h.append(lst1)


check = [0]*n
language = [0]*m
root = 0
check[root] = 1
deq = deque([root])
while deq:
    fr = deq.pop()
    for i in h[fr]:
        if language[i-1]:
            continue
        language[i-1] = 1
        for j in g[i-1]:
            if check[j]:
                continue
            deq.append(j)
            check[j] = 1


if all(i==1 for i in check):
    print("YES")
else:
    print("NO")

Measured memory_bytes: 94948
#include <bits/stdc++.h>
using namespace std;
#define F first
#define S second
#define pi M_PI
#define R cin>>
#define Z class
#define ll long long
#define ln cout<<'\n'
#define in(a) insert(a)
#define pb(a) push_back(a)
#define pd(a) printf("%.10f\n",a)
#define mem(a) memset(a,0,sizeof(a))
#define all(c) (c).begin(),(c).end()
#define iter(c) __typeof((c).begin())
#define rrep(i,n) for(int i=(int)(n)-1;i>=0;i--)
#define REP(i,m,n) for(int i=(int)(m);i<(int)(n);i++)
#define rep(i,n) REP(i,0,n)
#define tr(it,c) for(iter(c) it=(c).begin();it!=(c).end();it++)
template<Z A>void pr(A a){cout<<a;ln;}
template<Z A,Z B>void pr(A a,B b){cout<<a<<' ';pr(b);}
template<Z A,Z B,Z C>void pr(A a,B b,C c){cout<<a<<' ';pr(b,c);}
template<Z A,Z B,Z C,Z D>void pr(A a,B b,C c,D d){cout<<a<<' ';pr(b,c,d);}
template<Z A>void PR(A a,ll n){rep(i,n){if(i)cout<<' ';cout<<a[i];}ln;}
ll check(ll n,ll m,ll x,ll y){return x>=0&&x<n&&y>=0&&y<m;}
const ll MAX=1000000007,MAXL=1LL<<61,dx[4]={-1,0,1,0},dy[4]={0,1,0,-1};
typedef pair<int,int> P;

void Main() {
  ll n,m;
  cin >> n >> m;
  ll a[n];
  rep(i,n) R a[i];
  ll d[n+1];mem(d);
  rep(i,n) d[i+1]+=d[i]+a[i];
  ll x=0;
  rep(i,n) {
    if(a[i]>=0) x+=a[i];
  }
  for(int i=0; i<m; i++) {
    if(a[i]>=0) x-=a[i];
  }
  ll ans=max(x,x+d[m]);
  for(int i=0; i+m<n; i++) {
    if(a[i]>=0) x+=a[i];
    if(a[i+m]>=0) x-=a[i+m];
    ans=max(ans,max(x,x+d[i+m+1]-d[i+1]));
  }
  pr(ans);
}

int main(){ios::sync_with_stdio(0);cin.tie(0);Main();return 0;}


Measured memory_bytes: 1792
#include<bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < n; i++)
#define all(x)(x).begin(), (x).end() // 昇順ソート
#define rall(v)(v).rbegin(), (v).rend() // 降順ソート
#define INF 1LL << 60
typedef long long int LL;
typedef long long int ll;
#define pll pair < ll, ll >
#define F first
#define S second
const int MOD = 1000000007;
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; }
// 任意のlogは　対数の底の変換を使う    log(N) / log(任意の底)

int main() {
    string S,T;cin >> S >> T;
    sort(all(S));
    sort(rall(T));

    if(T > S)cout << "Yes" << endl;
    else cout << "No" << endl;
}

Measured memory_bytes: 256
N, K = map(int, input().split())
A = list(map(int, input().split()))

one_cnt = 0

for i in range(N):
    for j in range(i+1, N):
        if A[i] > A[j]:
            one_cnt+=1
two_cnt = 0
B = A*2

for i in range(N):
    for j in range(N, 2*N):
        if B[i] > B[j]: two_cnt+=1


one_cnt = one_cnt % 1000000007
two_cnt = two_cnt % 1000000007
ans = one_cnt * K + two_cnt * (K-1)*K//2

print(ans%1000000007)


Measured memory_bytes: 43552
#include<bits/stdc++.h>
using namespace std;
#define ll long long
void solve(){
    int N;cin>>N;
    vector<pair<pair<int,int>,int>>v(N+1);
    int dp[N+1][4];int a,b,c;
    for(int i=1;i<=N;i++){
        cin>>a>>b>>c;
        v[i]={{a,b},c};
    }
    dp[1][1]=v[1].first.first;
    dp[1][2]=v[1].first.second;
    dp[1][3]=v[1].second;
    //cout<<dp[1][1]<<" "<<dp[1][2]<<" "<<dp[1][3];
    for(int i=2;i<=N;i++){
        dp[i][1]=max(dp[i-1][2],dp[i-1][3])+v[i].first.first;
        dp[i][2]=max(dp[i-1][1],dp[i-1][3])+v[i].first.second;
        dp[i][3]=max(dp[i-1][1],dp[i-1][2])+v[i].second;
    }
    cout<<max({dp[N][1],dp[N][2],dp[N][3]});
}
int main(){
		ios_base::sync_with_stdio(false);
		cin.tie(NULL);
		int t=1;
		//cin>>t;
		while(t--){
		    solve();
		}
		return 0;
	}


Measured memory_bytes: 2944
#include<bits/stdc++.h>
#define ll long long
#define loop(n) for(ll i = 0; i<n; i++)
#define sort(a) sort(a.rbegin(), a.rend())
using namespace std;

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

    int k; cin>>k;
    int g[k+1][k+1];
    for(int i = 1; i<=k; i++){
        for(int j = 1; j<=k; j++) g[i][j] = __gcd(i, j);
    }

    ll ans = 0;
    for(int p = 1; p<=k; p++){
        for(int i = 1; i<=k; i++){
            for(int j = 1; j<=k; j++){
                if(p==1 || i==1 || j==1){
                    ans ++;
                    continue;
                }
                ans += __gcd(p, g[i][j]);
            }
        }
    }

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

Measured memory_bytes: 3804
using System;

namespace ITP1_1_D
{
    class Program
    {
        static void Main(string[] args)
        {
            var s = int.Parse(Console.ReadLine());
            var ts = new TimeSpan(0, 0, s);
            Console.WriteLine("{0}:{1}:{2}", ts.Hours, ts.Minutes, ts.Seconds);
        }
    }
}

Measured memory_bytes: 9164
# -*- coding: utf-8 -*-
n = int(input())
s = [0] * n
for i in range(n):
    s[i] = input()
m = int(input())
t = [0] * m
for i in range(m):
    t[i] = input()

money = [0] * n

for i in range(n):
    money[i] += 1
    for j in range(i+1,n):
        if s[i] == s[j]:
            money[i] += 1
    for j in range(m):
        if s[i] == t[j]:
            money[i] -= 1

money.sort()

print(max(0,money[-1]))


Measured memory_bytes: 3064
#include<iostream>
#include<cstdio>
#include<algorithm>
using namespace std;
#define MOD 1000000007
#define MAX 18
inline int read()
{
	int x=0;bool t=false;char ch=getchar();
	while((ch<'0'||ch>'9')&&ch!='-')ch=getchar();
	if(ch=='-')t=true,ch=getchar();
	while(ch<='9'&&ch>='0')x=x*10+ch-48,ch=getchar();
	return t?-x:x;
}
void add(int &x,int y){x+=y;if(x>=MOD)x-=MOD;}
int bin[MAX],jc[1<<MAX],inv[1<<MAX],jv[1<<MAX];
int C(int n,int m){if(n<m)return 0;return 1ll*jc[n]*jv[m]%MOD*jv[n-m]%MOD;}
int a[MAX],n,m,ans,f[MAX][1<<MAX],cnt[1<<MAX];
int main()
{
	n=read();m=read();cnt[0]=jc[0]=bin[0]=jv[0]=inv[0]=inv[1]=1;
	for(int i=1;i<=n;++i)bin[i]=bin[i-1]<<1;
	for(int i=1;i<=bin[n];++i)jc[i]=1ll*jc[i-1]*i%MOD;
	for(int i=2;i<=bin[n];++i)inv[i]=1ll*inv[MOD%i]*(MOD-MOD/i)%MOD;
	for(int i=1;i<=bin[n];++i)jv[i]=1ll*jv[i-1]*inv[i]%MOD;
	for(int i=1;i<=bin[n];++i)cnt[i]=(i&1)?MOD-cnt[i>>1]:cnt[i>>1];
	for(int i=1;i<=m;++i)a[i]=read();sort(&a[1],&a[m+1]);
	f[m+1][0]=1;
	for(int i=m;i;--i)
		for(int t=0;t<bin[n];++t)
			if(f[i+1][t])
			{
				add(f[i][t],f[i+1][t]);
				int p=bin[n]-1-t;
				for(int j=0;j<n;++j)
					if(!(t&(1<<j)))
						add(f[i][t|(1<<j)],1ll*C(p-a[i]+1,(1<<j)-1)*f[i+1][t]%MOD*jc[1<<j]%MOD);
			}
	for(int i=0;i<bin[n];++i)
		add(ans,1ll*f[1][i]*jc[bin[n]-1-i]%MOD*cnt[i]%MOD);
	ans=1ll*ans*bin[n]%MOD;
	printf("%d\n",ans);
	return 0;
}


Measured memory_bytes: 20992
n,m=map(int,input().split())
ab=[[int(j) for j in input().split()] for i in range(n)]
cd=[[int(j) for j in input().split()] for i in range(m)]

for a,b in ab:
  l=[abs(a-c)+abs(b-d) for c,d in cd]
  print(l.index(min(l))+1)

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

const int INF = 1e9;

struct Edge {
    int from, to, cost;
};

int main() {
    int V, E;
    cin >> V >> E;
    vector<Edge> edge(E);
    vector<vector<int>> dist(V, vector<int>(V, INF));
    for (int i = 0; i < E; i++) {
        int a, b, c;
        cin >> a >> b >> c;
        a--;
        b--;
        edge[i].from = a;
        edge[i].to = b;
        edge[i].cost = c;
        dist[a][b] = min(dist[a][b], c);
        dist[b][a] = min(dist[b][a], c);
    }

    for (int i = 0; i < V; i++) {
        for (int j = 0; j < V; j++) {
            for (int k = 0; k < V; k++) {
                dist[j][k] = min(dist[j][k], dist[j][i] + dist[i][k]);
            }
        }
    }

    int ans = 0;
    for (Edge e: edge) {
        if (dist[e.from][e.to] < e.cost) {
            ans++;
        }
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
n = int(input())
check = set()
p = ''
for i in range(n):
  now = input()
  if i == 0:
    p = now
    check.add(now)
    continue
  if p[-1] != now[0] or now in check:
    print('No')
    exit()
  check.add(now)
  p = now
print('Yes')


Measured memory_bytes: 2940
#include <cstdio>
#include <cstring>
#define M 5070721
#define NIL (-1)
#define L 14
typedef long long ll;
char H[M][L];

int getChar(char ch){
	if(ch=='A')return 1;
	else if(ch=='C')return 2;
	else if(ch=='G')return 3;
	else if(ch=='T')return 4;
	else return 0;
}

ll getKey(char str[]){
	ll sum=0,p=1,i;
	int len=strlen(str);
	for(i=0;i<len;i++){
		sum+=p*(getChar(str[i]));
		p*=5;
	}
	return sum;
}

int h1(int key){
	return key%M;
}

int h2(int key){
	return 1+(key%(M-1));
}

int find(char str[]){
	ll key,i,h;
	key=getKey(str);
	for(i=0;;i++){
		h=(h1(key)+i*h2(key))%M;
		if(strcmp(H[h],str)==0)return 1;
		else if(strlen(H[h])==0)return 0;
	}
	return 0;
}

int insert(char str[]){
	ll key,i,h;
	key=getKey(str);
	for(i=0;;i++){
		h=(h1(key)+i*h2(key))%M;
		if(strcmp(H[h],str)==0)return 1;
		else if(strlen(H[h])==0){
			strcpy(H[h],str);
			return 0;
		}
	}
	return 0;
}


int main(void){
	int n;
	char str[L],com[9];
	for(int i=0;i<M;i++){
		H[i][0]='\0';
	}
	scanf("%d",&n);
	for(int i=0;i<n;i++){
		scanf("%s %s",com,str);
		if(com[0]=='i'){
			insert(str);
		}else{
			if(find(str)){
				printf("yes\n");
			}else{
				printf("no\n");
			}
		}
	}
	return 0;
}



Measured memory_bytes: 72084
"use strict";
const Main = (input) =>{
   let xs = input.trim().split(' ').map(v=>parseInt(v,10));
   let N = xs[0];
   let K = xs[1];
   let ans = N.toString(K);
   console.log(ans.length);
}
Main(require('fs').readFileSync('/dev/stdin','utf8'));

Measured memory_bytes: 7372
#include<iostream>
#include<cmath>
#include<stack>
#include<vector>
#include<cstring>
#include<algorithm>
#include<set>
#include<queue>
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <complex>
#include <sstream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <cassert>
using namespace std;
typedef long long ll;
const ll inf =1e17;
#define scn(a) scanf("%d",&a)
#define scd(a) scanf("%lf",&a)
#define scl(a) scanf("%lld",&a)
#define ptf(a) printf("%d\n",&a)
#define mes(a,b) memset(a,b,sizeof(a))
#define fon(s,n) for(int i=s;i<=n;i++)
#define range(i,a,b) for(int i=a;i<=b;++i)
#define rerange(i,a,b) for(int i=a;i>=b;--i)
//#define N 100010
const int S=20;
ll gcd(ll a,ll b) { return b>0 ? gcd(b,a%b):a;}
ll lcm(ll a,ll b){return a*b/gcd(a,b);}
ll q_pow(ll a,ll b,ll mod)
{
	ll ans=1,res=a;
	while(b){
		if(b&1) ans=ans*res%mod;
		res=res*res%mod;
		b>>=1;
	}
	return ans%mod;
}
 bool cmp(const pair<string,int> &p1, const pair<string,int> &p2) {
    return p1.second > p2.second;
}

int main()
{
    ll x,ans=0,temp=100;
    ll ret=100;
    scanf("%lld",&x);
    while(temp<x){
        temp+=temp/ret;
        ans++;
    }
    printf("%d",ans);
    return 0;
}

Measured memory_bytes: 3836
#include <bits/stdc++.h>
using namespace std;
using i64 = long long;
#define rep(i,s,e) for(i64 (i) = (s);(i) < (e);(i)++)
#define rev(i,s,e) for(i64 (i) = (s);(i) --> (e);)
#define all(x) x.begin(),x.end()

int main() {
  string s;
  cin >> s;
  vector<string> str { "SUN", "MON", "TUE", "WED", "THU", "FRI", "SAT" };
  i64 i = find(begin(str), end(str), s) - begin(str);
  cout << 7 - i << endl;
}


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

#define MOD 1000000007
#define ll long long int
#define vi vector<int>
#define vii vector< vector<int> >
#define PI 3.1415926535897932384626433832795
#define INF 9223372036854775807LL

int main() {
	ios::sync_with_stdio(false);
	cin.tie(NULL);
	int n,m;
	cin >> n;
	vi d(n);
	for(int i = 0; i < n; i++) {
		cin >> d[i];
	}
	sort(d.begin(),d.end());
	int ind = 0;
	cin >> m;
	vi t(m);
	for(int i = 0; i < m; i++) {
		cin >> t[i];
	}
	sort(t.begin(),t.end());
	for(int i = 0; i < m; i++) {
		while(ind < n && d[ind] < t[i]) {
			ind++;
		}
		if(ind == n || d[ind] > t[i]) {
			cout << "NO";
			return 0;
		}
		ind++;
	}
	cout << "YES";
	return 0;
}



Measured memory_bytes: 1920
package main

import "fmt"

func main() {
	var A, B, C, X, r int
	fmt.Scan(&A, &B, &C, &X)
	for i := 0; i <= A; i++ {
		for j := 0; j <= B; j++ {
			for k := 0; k <= C; k++ {
				if 500*i+100*j+50*k == X {
					r++
				}
			}
		}
	}
	fmt.Println(r)
}

Measured memory_bytes: 512
#include <bits/stdc++.h>
#define ll long long int
#define yorn(f) cout<<((f)?"Yes":"No")<<endl;
#define YORN(f) cout<<((f)?"YES":"NO")<<endl;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define repi(i, n) for (int i = 1; i < (int)(n); i++)
#define all(x) (x).begin(), (x).end()
#define put(x) cout << x << endl;
#define println(x) cout << x << endl;
using namespace std;
int main()
{
    int n, m;
    cin >> n >> m;
    vector<int> p(m);
    vector<string> s(m);
    rep(i, m) cin >> p[i] >> s[i];
    
    vector<int> wa(n);
    vector<int> ac(n);
    rep(i, m) {
        if (s[i] == "WA" && ac[p[i]-1] <= 0) {
            wa[p[i]-1]++;
        }
        else if (s[i] == "AC" && ac[p[i]-1] <= 0) {
            ac[p[i]-1]++;
        }
    }

    int pen = 0;
    rep(i, n) {
        if (ac[i] >= 1) pen += wa[i];
    }
    cout << accumulate(all(ac), 0) << " " << pen << endl;   

    return 0;
}

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

using namespace std;

#define mod1 1000000007
#define mod2 998244353
#define int long long int
#define pii pair<int,int>
#define vpii vector<pii>
#define vi vector<int>
#define fi first
#define se second
#define psb push_back
#define ppb pop_back
#define fio ios_base::sync_with_stdio(0); cin.tie(NULL); cout.tie(NULL)
#define all(x) x.begin(),x.end()
// #define endl "\n"

const int maxn=1e4+5;

int ans[maxn];

int f(int i,int j,int k)
{
	return i*i+j*j+k*k+i*j+i*k+j*k;
}

void solve()
{
	int n;
	cin>>n;
	for(int i=0;i<maxn;i++)
		ans[i]=0;
	for(int i=1;i<=200;i++)
		for(int j=1;j<=200;j++)
			for(int k=1;k<=200;k++)
				if(f(i,j,k)<maxn)
					ans[f(i,j,k)]++;
	for(int i=1;i<=n;i++)
		cout<<ans[i]<<endl;

}

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

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

int main(){

  ll n, a, b;
  cin >> n >> a >> b;
  ll ans = 0;
  ans = (n/(a+b))*a + min(a, (n%(a+b)));

  cout << ans << endl;

  return 0;
}

Measured memory_bytes: 256
N = int(input())
a = list(map(int, input().split()))
num_cnt = {}
for i in range(N):
    if a[i] in num_cnt:
        num_cnt[a[i]] += 1
    else:
        num_cnt[a[i]] = 1
cnt = 0
for i, j in num_cnt.items():
    if j >= i:
        cnt += j - i
    else:
        cnt += j
print(cnt)

Measured memory_bytes: 17780
#include <cmath>
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <set>
#include <map>
#include <list>
#include <time.h>
#include <math.h>
#include <random>
#include <deque>
#include <queue>
#include <cassert>
#include <unordered_map>
#include <iomanip>

using namespace std;

typedef long long ll;

mt19937 rnd(228);

int main()
{
#ifdef ONPC
    freopen("a.in", "r", stdin);
#endif
    int n;
    scanf("%d", &n);
    vector <int> p(n);
    vector <int> a;
    for (int i = 0; i < n; i++)
    {
        scanf("%d", &p[i]);
        p[i]--;
        if (p[i] == i)
        {
            a.push_back(i);
        }
    }
    int m = (int) a.size();
    if (m == 0)
    {
        puts("0");
        return 0;
    }
    vector <int> dp(m);
    for (int i = 0; i < m; i++)
    {
        if (i)
        {
            dp[i] = dp[i - 1] + 1;
            if (abs(a[i] - a[i - 1]) == 1)
            {
                if (i > 1)
                {
                    dp[i] = min(dp[i], dp[i - 2] + 1);
                }
                else
                {
                    dp[i] = 1;
                }
            }
        }
        else
        {
            dp[i] = 1;
        }
    }
    printf("%d\n", dp[m - 1]);
}


Measured memory_bytes: 1528
#include <iostream>
#include <algorithm>
#include <vector>
#include <map>
#include <string>
#include <cmath>
#include <iomanip>
#include <numeric>

using namespace std;

#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define REP(i, n) FOR(i, 0, n)
#define SORT(c) sort((c).begin(), (c).end())
#define INF (ll)1e18
#define MOD (int)1e9 + 7

typedef long long ll;
typedef pair<int, int> P;
typedef vector<int> V;
typedef map<int, int> M;

int main()
{
    int n;
    ll ans;
    V p;

    REP(i, 1000)
    p.push_back(i + 1);

    p.erase(p.begin());

    FOR(i, 2, 40)
    {
        int j = 0;
        while (j < p.size())
        {
            if (p[j] % i == 0 && p[j] > i)
            {
                p.erase(p.begin() + j);
                continue;
            }

            j++;
        }
    }

    V num(p.size());
    cin >> n;

    ans = 1;
    FOR(i, 2, n + 1)
    {
        int i_ = i;
        REP(j, p.size())
        {
            while (i_ % p[j] == 0)
                i_ /= p[j], num[j]++;
        }
    }

    REP(i, num.size())
    {
        ans *= num[i] + 1;
        ans %= MOD;
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256
#include <algorithm>
#include <cassert>
#include <cmath>
#include <deque>
#include <iomanip>
#include <iostream>
#include <list>
#include <numeric>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>

using namespace std;

#define int long long int
#define rep(i, n) for (int i = 0; i < n; ++i)
#define all(x) (x).begin(), (x).end()
#define capi(x) int x;cin>>x
#define fastio ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);

using vi = vector<int>;

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

#define P (1'000'000'007)

int dp[1001][(1 << 12) + 1];

signed main() {
    int n, m;
    cin >> n >> m;

    rep(i, 1001) {
        rep(j, (1 << 12) + 1) {
            dp[i][j] = INT_MAX;
        }
    }

    vector<pair<int, int>> vk;

    rep(i, m) {
        int a, b;
        cin >> a >> b;

        int x = 0;
        rep(j, b) {
            capi(c); --c;
            x += 1 << c;
        }
        vk.push_back(make_pair(x, a));
    }

    dp[0][0] = 0;

    rep(i, m) {
        rep(j, 1 << n) {
            chmin(dp[i + 1][j | vk[i].first], dp[i][j] + vk[i].second);
            chmin(dp[i + 1][j], dp[i][j]);
        }
    }

   //  for(int i=0;i<(1 << n) + 1;++i){for(int j=0;j<m+1;++j){cout<<"|"<<dp[j][i];}cout<<"|"<<endl;}

    if (dp[m][(1 << n) - 1] >= INT_MAX) {
        cout << -1;
    } else {
        cout << dp[m][(1 << n) - 1];
    }

    return 0;
}

Measured memory_bytes: 35220
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
using namespace std;

int main() {
	cin.tie(0); cout.tie(0); ios_base::sync_with_stdio(0);
	int n; cin>>n;
	vector <int> p(n); 
	for (int i=0; i<n; i++)
		cin>>p[i];
	int ret=0;
	for (int i=0; i<n; i++) { 
		if (p[i]!=i+1) ret++;
	}
	cout<<(ret<=2?"YES":"NO")<<"\n"; 
	return 0;
}


Measured memory_bytes: 256
N,X = [int(i) for i in input().split()]
W = []
for j in input().split():
    W.append(j)

count = 1
Sum = 0
while Sum <= X and count < N + 2:
    if count < N + 1:
        Sum += int(W.pop(0))
    count += 1
print(count-1)

Measured memory_bytes: 3064
N = int(input())
A = 0
for i in range(1,N+1):
    if i%3 == 0 and i%3 == 5:
        i = "FizzBuzz"
    elif i%3 == 0:
        i = "Fizz"
    elif i%5 == 0:
        i = "Buzz"
    else:
        A += i
print(A)

Measured memory_bytes: 9160
#include <cstdio>
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <map>

using namespace std;

int main() {
	long long A, B;
	char op;
	cin >> A >>op>> B;

	if (op == '+') cout << A + B << endl;
	else cout << A - B << endl;

	return 0;
}

Measured memory_bytes: 764
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
using namespace std;
#define rep(i,n) for (int i=0; i<(int)(n); i++)
#define ct(string) cout << string << endl

int main() {
    int a, b, c;
    cin >> a >> b >>c;
    ct(a+b+c-max(max(a, b), c));
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n) FOR(i,0,n)
#define repr(i,n) for(int i=(n)-1;0<=i;--i)
#define each(e,v) for(auto&& e:(v))
#define all(v) begin(v),end(v)
#define dump(x) cerr<<#x<<": "<<(x)<<endl
#define INF 100000000
#define IINF 9999999999999;
using vint = std::vector<int>;
using ll = long long;
using vll = std::vector<ll>;
template <class T> void chmin(T& a, const T& b) { a = std::min(a, b); }
template <class T> void chmax(T& a, const T& b) { a = std::max(a, b); }

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

    int answer = 0;
    rep(i, B.length()) {
        if(B[i] == '1') ++answer;
    }

    cout << answer << endl;
}

Measured memory_bytes: 256
/*
 ALLAH is Almighty....
*/
#include <bits/stdc++.h>

#define ll  long long
using namespace std;

const ll mx = 10e5 + 9;
ll n;
ll ar[ mx ];
ll dp[ mx ];

void solve( )
{
    cin >> n;
    for ( ll i = 0; i < n; ++i )
        cin >> ar[ i ];

    dp[ 1 ] = abs( ar[ 1 ] - ar[ 0 ] );

    for ( ll i = 2; i < n; ++i )
        dp[ i ] = min( dp[ i - 2 ] + abs( ar[ i ] - ar[ i - 2 ] ), dp[ i - 1 ] + abs( ar[ i ] - ar[ i - 1 ] ) );

    cout << dp[ n - 1 ] << "\n";
}

int main()         // Md. Inzamam-ul Haque
{
    solve();
}



Measured memory_bytes: 5100
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef pair<ll,ll> pl;
typedef vector<pl> vp;
#define fore(i,a,b) for(ll i=(ll)(a);i<=(ll)(b);++i)
#define rep(i,n) fore(i,0,(n)-1)
#define rfore(i,a,b) for(ll i=(ll)(b);i>=(ll)(a);--i)
#define rrep(i,n) rfore(i,0,(n)-1)
#define all(x) (x).begin(),(x).end()
const ll INF=1001001001;
const ll LINF=1001001001001001001;
const ll D4[]={0,1,0,-1,0};
const ll D8[]={0,1,1,0,-1,-1,1,-1,0};
template<class T>
bool chmax(T &a,const T &b){if(a<b){a=b;return 1;}return 0;}
template<class T>
bool chmin(T &a,const T &b){if(b<a){a=b;return 1;}return 0;}

ll par[100005];
ll find(ll x){
    if(par[x]<0)return x;
    return par[x]=find(par[x]);
}
void unite(ll x,ll y){
    x=find(x),y=find(y);
    if(x==y)return;
    par[x]+=par[y];
    par[y]=x;
}
ll size(ll x){
    ll root=find(x);
    return -par[root];
}
void solve(){
    ll n,m;cin>>n>>m;
    vl a(m),b(m);
    rep(i,m){
        cin>>a[i]>>b[i];
        a[i]--,b[i]--;
    }
    ll ans=0;
    rep(i,m){
        memset(par,-1,sizeof(par));
        rep(j,m){
            if(j==i)continue;
            unite(a[j],b[j]);
        }
        if(size(0)!=n)ans++;
    }
    cout<<ans<<endl;
}

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


Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
long long int ara[100005];
long long int iforward[100005];
//long long int iback[100005];
int main()
{
    long long int i,j,m,n,t,ans=0,sum=0,sum1=0;
    cin>>n;
    for(i=0;i<n;i++)
        cin>>ara[i];
    iforward[n-1]=0;
    iforward[n-2]=abs(ara[n-2]-ara[n-1]);
    for(i=n-3;i>=0;i--){
    if(abs(ara[i]-ara[i+1])+iforward[i+1]>abs(ara[i]-ara[i+2])+iforward[i+2])
        iforward[i]=abs(ara[i]-ara[i+2])+iforward[i+2];
    else
    iforward[i]=abs(ara[i]-ara[i+1])+iforward[i+1];
}
//for(i=0;i<n;i++)
cout<<iforward[0]<<endl;
}


Measured memory_bytes: 1792
#include<stdio.h>

int a[100001],n,k;
int solve(int x){
	int i=0,j=0,cur=0;
	while(i<n && j<k){
		if(a[i]+cur<=x){
			cur+=a[i];
			i++;
		}
		else{
			cur=0;
			j++;
		}
	}
	return (j<k);
}

int find(){
	int r=1000000000,l=0;
	int m;
	while(l<r){
		m=(r+l)/2;
		if(solve(m)){
			r=m;
		}
		else l=m+1;
	}
	return r;
}

int main(){
	scanf("%d %d",&n,&k);
	for(int i=0;i<n;i++) scanf("%d",&a[i]);
	printf("%d\n",find());
} 


Measured memory_bytes: 3144
# -*- coding: utf-8 -*-
# モジュールのインポート
import numpy as np


def get_input() -> tuple:
    """標準入力の取得

    Returns:
        tuple -- 標準入力
    """
    N, M, X = list(map(int, input().split()))
    C = []
    A = []
    for n in range(N):
        line = list(map(int, input().split()))
        C.append(line[0])
        A.append(line[1:])

    return N, M, X, C, A


def main(N: int, M: int, X: int, C: list, A: list) -> None:
    """求解処理.\n
    bit全探索を行う.

    Arguments:\n
        N {int} -- 参考書の数
        M {int} -- 学びたいアルゴリズムの数
        X {int} -- 目標とする理解度
        C {list} -- 参考書の値段
        A {list} -- 各参考書によるアルゴリズムの理解度
    """
    # 計算を簡単にするため、numpy配列にしておく
    C = np.array(C)
    A = np.array(A)

    # bit全探索
    result = sum(C)
    canAchieve = False
    for i in range(2**N):
        cost = 0
        skill = np.zeros(M)
        for j in range(N):
            if ((i >> j) & 1):
                cost += C[j]
                skill += A[j]

        if min(skill) >= X:
            result = min(result, cost)
            canAchieve = True

    if not canAchieve:
        result = -1

    # 結果出力
    print(result)


if __name__ == "__main__":
    N, M, X, C, A = get_input()
    main(N, M, X, C, A)


Measured memory_bytes: 27116
#include <bits/stdc++.h>
using namespace std;
int main()
{
    int n;
    scanf("%d", &n);
    vector<int> b;
    for (int i = 0; i < n; i++)
    {
        int a;
        cin >> a;
        if (i % 2 == 0)
        {
            b.insert(b.begin(), a);
        }
        else
        {
            b.push_back(a);
        }
    }
    if (n % 2 == 0)
    {
        for (auto it = b.rbegin(); it != b.rend(); it++)
        {
            cout << *it << " ";
        }
    }
    else
    {
        for (auto it = b.begin(); it != b.end(); it++)
        {
            cout << *it << " ";
        }
    }
    cout << endl;
}
/*
int main()
{
    int n;
    int b[n];
    scanf("%d", &n);
    int r = n / 2;
    int l = r - 1;
    for (int i = 0; i < n; i++)
    {
        int a;
        cin >> a;
        if (i % 2 == 0)
        {
            b[r++] = a;
        }
        else
        {
            b[l--] = a;
        }
    }
    if (n % 2 != 0)
    {
        for (int i = n - 1; i >= 0; i--)
        {
            cout << b[i] << " ";
        }
    }
    else
    {
        for (int i = 0; i < n; i++)
        {
            cout << b[i] << " ";
        }
    }
    cout << endl;
}
*/

Measured memory_bytes: 3060
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < n; i++)
#define REPR(i, n) for (int i = n; i >= 0; i--)
#define FOR(i, m, n) for (int i = m; i < n; i++)
#define FORR(i, m, n) for (int i = m; i >= n; i--)
#define SORT(v, n) sort(v, v + n);
#define VSORT(v) sort(v.begin(), v.end());
#define ll long long
#define ull unsigned long long
#define pb(a) push_back(a)
#define INF 999999999
using namespace std;
typedef pair<int, int> P;
typedef pair<ll, ll> LP;
typedef pair<int, P> PP;
typedef pair<ll, LP> LPP;

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

int main()
{
    char c;
    cin >> c;
    char b = c + 1;
    cout << b << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <queue>
#include <string>
#include <map>
#include <set>
#include <tuple>
#include <deque>
#include <numeric>
#include <bitset>
#include <iomanip>
#include <cassert>
#include <chrono>
#include <random>
#include <limits>
#include <iterator>
#include <functional>
#include <sstream>
using namespace std;

typedef long long ll;
typedef pair<int, int> P;
typedef pair<int, double> Pid;
typedef pair<double, int> Pdi;
typedef pair<ll, int> Pl;
const double PI = 3.1415926535897932;   // acos(-1)
const double EPS = 1e-15;
const int INF = 1001001001;
const ll mod = 1e+9 + 7;

#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
#define chadd(x, y) x = (x + y) % mod

set<int> cyclic[30];
bool used[30];

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

    string s, t;
    cin >> s >> t;
    int n = s.length();
    vector<int> table_s(30, -1), table_t(30, -1);
    for(int i = 0; i < n; ++i){
        int ns = s[i] - 'a', nt = t[i] - 'a';
        if(table_s[ns] != -1){
            if(table_s[ns] != nt){
                cout << "No\n";
                return 0;
            }
        }
        if(table_t[nt] != -1){
            if(table_t[nt] != ns){
                cout << "No\n";
                return 0;
            }
        }
        if(table_s[ns] == -1) table_s[ns] = nt;
        if(table_t[nt] == -1) table_t[nt] = ns;
    }

    cout << "Yes\n";
}

Measured memory_bytes: 916
#include <stdio.h>

int main(void){
  int n,m,h[100001],j[100001],ans=0,a,b,i;
  scanf("%d",&n);
  scanf("%d",&m);
  for(i=1;i<=n;i++){
    scanf("%d",&h[i]);
    j[i]=1;
  }
  for(i=0;i<m;i++){
    scanf("%d",&a);
    scanf("%d",&b);
    if(h[a]<=h[b]){
      j[a]=0;
    }
    if(h[b]<=h[a]){
      j[b]=0;
    }
  }
  for(i=1;i<=n;i++){
    ans+=j[i];
  }
  printf("%d",ans);
  return 0;
}
  

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

int main() {
  int a,b;
  cin >>a>>b;
  int c =10;
  int f =a;
  for(int i=0;i<b-1;i++){
    f+=+a*c;
    c*=10;
  }
  int d=10;
  int g=b;
  for(int i=0;i<a-1;i++){
    g+=+b*d;
    d*=10;
  }
  if(a<b){
  cout << f << endl;
  }
  else {
    cout << g << endl;
  }
}
  

Measured memory_bytes: 256
#include <cstdio>
#include <vector>
#include <map>
#define repi(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,a) repi(i,0,a)
#define all(a) (a).begin(), (a).end()

using ll = long long;

class UnionFind {
public:
    std::vector <ll> par; // 各元の親を表す配列
    std::vector <ll> siz; // 素集合のサイズを表す配列(1 で初期化)

    // Constructor
    UnionFind(ll sz_): par(sz_), siz(sz_, 1LL) {
        for (ll i = 0; i < sz_; ++i) par[i] = i; // 初期では親は自分自身
    }
    void init(ll sz_) {
        par.resize(sz_);
        siz.assign(sz_, 1LL);  // resize だとなぜか初期化されなかった
        for (ll i = 0; i < sz_; ++i) par[i] = i; // 初期では親は自分自身
    }

    // Member Function
    // Find
    ll root(ll x) { // 根の検索
        while (par[x] != x) {
            x = par[x] = par[par[x]]; // x の親の親を x の親とする
        }
        return x;
    }

    // Union(Unite, Merge)
    bool merge(ll x, ll y) {
        x = root(x);
        y = root(y);
        if (x == y) return false;
        // merge technique（データ構造をマージするテク．小を大にくっつける）
        if (siz[x] < siz[y]) std::swap(x, y);
        siz[x] += siz[y];
        par[y] = x;
        return true;
    }

    bool issame(ll x, ll y) { // 連結判定
        return root(x) == root(y);
    }

    ll size(ll x) { // 素集合のサイズ
        return siz[root(x)];
    }
};

using P = std::pair<int, int>;

int N, M, K;
std::map<int, int> mp, fmp;

int main()
{
  scanf( "%d%d%d", &N, &M, &K );

  UnionFind uf( N+1 );

  rep( i, M )
  {
    int A, B;
    scanf( "%d%d", &A, &B );

    uf.merge( A, B );

    ++fmp[A];
    ++fmp[B];
  }

  rep( i, K )
  {
    int C, D;
    scanf( "%d%d", &C, &D );

    if( uf.issame( C, D ) )
    {
      ++mp[C];
      ++mp[D];
    }
  }

  rep( i, N )
  {
    int ans = -1;
    ans += uf.size( i+1 );
    ans -= mp[i+1];
    ans -= fmp[i+1];

    printf( "%d%c", ans, i==N-1?'\n':' ' );
  }

  return 0;
}

Measured memory_bytes: 11776
#include <stdio.h>


int main(void)
{
  int a, b;
  scanf("%d %d", &a, &b);
  int c, d, e;
  c = a + b;
  d = a - b;
  e = a * b;
  if(c > d){
    if(c > e){
      printf("%d\n", c);
    }
    else{
      printf("%d\n", e);
    }
  }
  else{
    if(d > e){
      printf("%d\n", d);
    }
    else{
      printf("%d\n", e);
    }
  }
  return 0;
}


Measured memory_bytes: 128
# -*- coding: utf-8 -*-
import fractions
A, B, C, D = map(int, input().split())

def lcm(x, y):
    return (x * y) //fractions.gcd(x, y)

lcm_CD = lcm(C, D)

div_AB_C = (B // C) - ((A - 1) // C)
div_AB_D = (B // D) - ((A - 1) // D)
div_AB_CD = (B // lcm_CD) - ((A - 1) // lcm_CD)
print(B - A + 1 - (div_AB_C + div_AB_D - div_AB_CD))

Measured memory_bytes: 5048
#include"bits/stdc++.h"
using namespace std;
typedef long long ll;
const ll MOD = (ll)(1e9+7);
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(), (x).end()
#define rep(i, n) for(int (i)=0; (i)<(int)(n); (i)++)
#ifdef LOCAL
#define debug(x) cerr << #x << ": " << x << endl
#else
#define debug(x)
#endif
int dx[4]={ 1,0,-1,0 };
int dy[4]={ 0,1,0,-1 };

int N, P[200000];

signed main(){
	cin >> N;
	rep(i, N){
		cin >> P[i];
		P[i]--;
	}

	int m = INT_MAX;
	int ans = 0;
	rep(i, N){
		m = min(m, P[i]);
		if(m >= P[i]) ans++;
	}
	cout << ans << endl;
}


Measured memory_bytes: 1024
import sys

LEN_D = 31
CONST = 2**LEN_D - 1

N = int(input())
XYs = [tuple(map(int, input().split())) for _ in range(N)]

parities = [(X+Y) % 2 for X, Y in XYs]
if len(set(parities)) != 1:
    print(-1)
    sys.exit()

if parities[0]:
    m = LEN_D
    ds = [2**i for i in range(LEN_D)]
else:
    m = LEN_D + 1
    ds = [1] + [2**i for i in range(LEN_D)]
print(m)
print(*ds)

for X, Y in XYs:
    ws = []
    if (X+Y) % 2 == 0:
        X -= 1
        ws.append('R')
    u = ((X+Y) + CONST) // 2
    v = ((X-Y) + CONST) // 2
    for i in range(LEN_D):
        ws.append('LDUR'[((u>>i) & 1) * 2 + ((v>>i) & 1)])
    print(''.join(ws))


Measured memory_bytes: 3188
import math
K = int(input())


ans = 0
memo=[]

for i in range(K):
    memo.append([])
    for j in range(K):
        memo[i].append(math.gcd(i+1,j+1))

for i in range(K):
    for j in range(K):
            ans+=sum(memo[memo[i][j]-1])
print(ans)




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

const int64_t mod = 1e+09 + 7;

int main(){
    int N;
    cin >> N;
    vector<int64_t> A(N);
    for ( int64_t i = 0; i < N; ++i){
        cin >> A.at(i);
    }
    
    int64_t res = 0;
    for ( int64_t i = 0; i < 61; ++i ){
        int64_t n0 = 0, n1 = 0;
        for ( int64_t j = 0; j < N; ++j){
            if ( ( A.at(j) >> i ) & 1 ){
                n1 += 1;
            } else {
                n0 += 1;
            }
        }
        int64_t tmp = (1ll << i) % mod;
        int64_t n = n0 * n1 % mod;
        
        tmp = tmp * n % mod;
        
        res = ( res + tmp ) % mod;
        
    }
    
    cout << res << endl;
    
    return 0;
}


Measured memory_bytes: 2560
n,A,B,C = map(int,input().split())
l = [int(input()) for i in range(n)]
ans = abs(l[0]-A)+abs(l[1]-B)+abs(l[2]-C)
for i in range(4**n):
    a = []
    b = []
    c = []
    for j in range(n):
        if i%4 == 0:
            a.append(l[j])
        if i%4 == 1:
            b.append(l[j])
        if i%4 == 2:
            c.append(l[j])
        i = int(i/4)
    if all([a,b,c]):
        mp = abs(sum(a)-A)+abs(sum(b)-B)+abs(sum(c)-C)+10*(len(a)+len(b)+len(c)-3)
        ans = min(ans,mp)
print(ans)

Measured memory_bytes: 3064
function main()
  
  n = parse(Int, readline())
  As = map(x -> parse(Int, x), split(readline()))
  
  ans = 0
  for i in 2:n
    if As[i] <= As[i-1]
      ans += As[i-1] - As[i]
      As[i] = As[i-1]
    end
  end
  
  println(ans)
  
end

main()

Measured memory_bytes: 190588
#include <iostream>
#include <string>
#include <vector>
#include <stdio.h>
#include <algorithm>
#define _USE_MATH_DEFINES
#include <cmath>
#include <numeric>
#include <iomanip>
#include <deque>
#include <tuple>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <unordered_map>
#include <sstream>
#include <stdexcept>
#include <boost/multiprecision/cpp_int.hpp>
#include <boost/multiprecision/cpp_dec_float.hpp>

#define rep(i, x) for (int i = 0; i < (int)(x); i++)
#define FOR(i, a, done) for (int i = (a); i < (done); ++i)
#define all(a) (a).begin(), (a).end()
#define x first
#define y second
#define debug(a) cout << (a) << endl
namespace mp = boost::multiprecision;
using cpp_int = mp::cpp_int;
using ll = long long;
using namespace std;
template <class T>
bool chmax(T &a, const T &b)
{
	if (a < b)
	{
		a = b;
		return 1;
	}
	return 0;
}
template <class T>
bool chmin(T &a, const T &b)
{
	if (a > b)
	{
		a = b;
		return 1;
	}
	return 0;
}

ll M = 1000000007;

void solve()
{
	int x;
	cin>>x;
	if(x){
		cout<<0<<endl;
	}else{
		cout<<1<<endl;
	}
}

int main()
{
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
	solve();
	return 0;
}


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

int main(){
    int k;
    scanf("%d", &k);
    int cur = 0;
    for (int i = 0; i < 2000000; ++ i){
        cur = (10 * cur + 7) % k;
        if (cur == 0){
            printf("%d\n", i + 1);
            return 0;
        }
    }
    puts("-1");
    return 0;
}

Measured memory_bytes: 3824