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

int a1(string &a,string &b,string &c){
    if (a.size()==0){
        cout << "A";
        return 0;
    }
    else {
        if (a[0]== 'a'){
            a.erase(a.begin());
            return 1;
        }
        else if (a[0]== 'b'){
            a.erase(a.begin());
            return 2;
        }
        else {
            a.erase(a.begin());
            return 3;
        }
    }
}
int b1(string &a,string &b,string &c){
    if (b.size()==0){
        cout << "B";
        return 0;
    }
    else {
        if (b[0]== 'a'){
            b.erase(b.begin());
            return 1;
        }
        else if (b[0]== 'b'){
            b.erase(b.begin());
            return 2;
        }
        else {
            b.erase(b.begin());
            return 3;
        }
    }
}
int c1(string &a,string &b,string &c){
    if (c.size()==0){
        cout << "C";
        return 0;
    }
    else {
        if (c[0]== 'a'){
            c.erase(c.begin());
            return 1;
        }
        else if (c[0]== 'b'){
            c.erase(c.begin());
            return 2;
        }
        else {
            c.erase(c.begin());
            return 3;
        }
    }
}

int main() {
    string a,b,c;
    cin >> a >> b >> c;
    int r = a.size() + b.size() + c.size();
    int which=1;
    for (int t=0;t<=r;t++){
        if (which==1){
            which=a1(a,b,c);
        }
        else if (which==2){
            which=b1(a,b,c);
        }
        else if (which==3){
            which=c1(a,b,c);
        }
        else {
            return 0;
        }
    }
    // cout << a << b << c;
    
}

Measured memory_bytes: 3564
#include <iostream>
#include <queue>

typedef struct _masu {
  int i;
  int j;
} Masu;

int main(void) {
  int h = 0, w = 0;
  int map[22][22] = {0};
  
  std::cin >> h;
  std::cin >> w;
  
  // outer edges of map are #
  for(int i = 0; i < h+2; i++) {
    map[i][0] = -1;
    map[i][w+1] = -1;
  }
  for(int j = 0; j < w+2; j++) {
    map[0][j] = -1;
    map[h+1][j] = -1;
  }
  for(int i = 1; i < h+1; i++) {
    for(int j = 1; j < w+1; j++) {
      map[i][j] = 0;
    }
  }
  
  // read stdin
  for(int i = 1; i < h+1; i++) {
    for(int j = 1; j < w+1; j++) {
      char ch;
      std::cin >> ch;
      if(ch == '.') map[i][j] = 0;
      else if(ch == '#') map[i][j] = -1;
      else printf("error: wrong input %c at %d %d\n", ch, i, j);
    }
    scanf(" ");
  }
  
  int max_of_step = 0;
  
  // BFS for each (i, j)
  for(int i = 1; i < h+1; i++) {
    for(int j = 1; j < w+1; j++) {
      if(map[i][j] == -1) continue;
      int bfs_map[22][22];
      
      // init
      for(int i = 0; i < h+2; i++) {
        for(int j = 0; j < w+2; j++) {
          bfs_map[i][j] = -1;
        }
      }
      
      std::queue<Masu> que;
      
      que.push(Masu{i, j});
      bfs_map[i][j] = 0;
      
      while(!que.empty()) {
        Masu m = que.front();
        que.pop();
        if(map[m.i-1][m.j] == 0 && bfs_map[m.i-1][m.j] == -1) {
          bfs_map[m.i-1][m.j] = bfs_map[m.i][m.j]+1;
          if(bfs_map[m.i-1][m.j] > max_of_step) max_of_step = bfs_map[m.i-1][m.j];
          que.push(Masu{m.i-1, m.j});
        }
        if(map[m.i+1][m.j] == 0 && bfs_map[m.i+1][m.j] == -1) {
          bfs_map[m.i+1][m.j] = bfs_map[m.i][m.j]+1;
          if(bfs_map[m.i+1][m.j] > max_of_step) max_of_step = bfs_map[m.i+1][m.j];
          que.push(Masu{m.i+1, m.j});
        }
        if(map[m.i][m.j-1] == 0 && bfs_map[m.i][m.j-1] == -1) {
          bfs_map[m.i][m.j-1] = bfs_map[m.i][m.j]+1;
          if(bfs_map[m.i][m.j-1] > max_of_step) max_of_step = bfs_map[m.i][m.j-1];
          que.push(Masu{m.i, m.j-1});
        }
        if(map[m.i][m.j+1] == 0 && bfs_map[m.i][m.j+1] == -1) {
          bfs_map[m.i][m.j+1] = bfs_map[m.i][m.j]+1;
          if(bfs_map[m.i][m.j+1] > max_of_step) max_of_step = bfs_map[m.i][m.j+1];
          que.push(Masu{m.i, m.j+1});
        }
      }
    }
  }
  
  printf("%d\n", max_of_step);
  
  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define pb push_back
#define all(v) v.begin(),v.end()
#define mem(arr) memset(arr, 0, sizeof(arr))
#define ff first
#define ss second
#define int long long int
const int MOD = 1e9 + 7;
const int INF = 1e18;
const int N = 1e6 + 20;
vector<int> g[N];
vector<int> vis(N);
int32_t main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    int tc = 1;
    while(tc--){
        string s;
        cin >> s;
        set<char> st;
        for(auto i : s){
            st.insert(i);
        }
        if(st.size() == 2){
            cout << "Yes\n";
        }else{
            cout << "No\n";
        }
    }
}

Measured memory_bytes: 31488
import sys
N,M =map(int, input().split())
q = list()

for i in range(M):
  q.append(list(map(int, input().split()))) #q[0]はqのlength
p = list(map(int, input().split())) #スイッチの偶奇正解を示す

ans = 0

for s in range(2**N):  #sは各スイッチ
  judge = True
  for i in range(M):
    cnt = 0
    for j in range(1, len(q[i])): #range(1,x)は2番目から(K+1)-1番目まで
      w = q[i][j] #i番目のスイッチ,j番目の電球
      if s >> (w-1) & 1 == 1: # 右シフト
        cnt += 1
    if cnt % 2 != p[i]:
      judge = False
  if judge:
    ans += 1
print(ans)

Measured memory_bytes: 9112
package main

import(
	"bufio"
	"os"
	"strings"
	"fmt"
	"strconv"
)

func main() {
	sc := bufio.NewScanner(os.Stdin)
	sc.Scan()
	num := strings.Split(sc.Text(), " ")
	a,_ := strconv.Atoi(num[0])
	b,_ := strconv.Atoi(num[1])
	plus := a + b
	minus := a - b
	kaker := a * b
	list := []int{plus, minus, kaker}
	for i := 0;i < 3;i++ {
		for j := 2; j > 0;j-- {
			if list[j] > list[i] {
				t := list[j]
				list[j] = list[i]
				list[i] = t
			}
		}
	}
	fmt.Printf(strconv.Itoa(list[0]))
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
typedef long long ll;
#define pb push_back
using namespace std;
typedef pair<ll,ll> pll;


ll n;
string s;
ll a[200005];
ll b[200005];
const ll mod = 1e9 + 7;
ll ans;
ll suf[200005];
int main()
{
        ios_base::sync_with_stdio(false);
        cin.tie(NULL); cout.tie(NULL);
        cin >> n; n+=n;
        cin >> s;
        if(s[0] == 'W' || s[n-1] == 'W'){
                cout << "0\n"; return 0;
        }
        a[0]=1;
        ll cnt = 1;
        ll tc=1;
        b[0]=1;
        ll L = 1;
        ll R = 0;
        for(ll i=1;i<n;i++) {
                if(s[i] == s[i-1]){
                        b[i] =1-b[i-1];
                }else b[i] = b[i-1];
                if(b[i]) L++;
                else R++;
        }
        if(L != R){
                cout << "0\n"; return 0;
        }
        ans=1LL;
        for(ll i=n-1;i>=0;i--) {
                suf[i] = suf[i+1] + b[i];
        }
        ll l=0;
        ll r=0;
        for(ll i=0;i<n;i++) {
                if(b[i] == 0){
                        ans = (ans * (l-r))%mod;
                        r++;
                }else l++;
        }
        for(ll i=1;i<=(n/2);i++) ans = (ans * i)%mod;
        cout << ans << endl;
        return 0;
}


Measured memory_bytes: 4688
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
int main()
{
    int n;
    int c1=0,c2=0,c3=0,c4=0;
    cin>>n;
    while(n--)
    {
        string str;
        cin>>str;
        if(str=="AC") c1++;
        else 
        if(str=="WA") c2++;
         else 
        if(str=="TLE") c3++;
         else 
        if(str=="RE") c4++;
    }
    cout<<"AC x "<<c1<<endl;
     cout<<"WA x "<<c2<<endl;
      cout<<"TLE x "<<c3<<endl;
       cout<<"RE x "<<c4<<endl;

}

Measured memory_bytes: 3640
#include<stdio.h>
int main()
{
    int a,b,c;
    scanf("%d%d",&a,&b);
    if((a+b)==15){
        printf("+\n");
    }
    else if((a*b)==15){
        printf("*\n");
    }
    else {
        printf("x\n");
    }

    return 0;
}


Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> l_l;
typedef pair<int, int> i_i;
template<class T>
inline bool chmax(T &a, T b) {
    if(a < b) {
        a = b;
        return true;
    }
    return false;
}

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

#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
//const ll mod = 1000000007;
int N, M;
int s[5];
int c[5];

void input() {
    cin >> N >> M;
    for(int i = 0; i < M; i++) {
        cin >> s[i] >> c[i];
    }
}

void solve() {
    int ANS = -1;
    for(int now = 1000; now >= 0; now--) {
        string S = to_string(now);
        bool ok = true;
        if(S.size() != N) ok = false;
        for(int i = 0; i < M; i++) {
            if(S[s[i]-1] != (char)('0' + c[i])) ok = false;
        }
        if(ok) ANS = now;
    }
    cout << ANS << endl;
    return;
}

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

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

int main(){
  int i,sum,k;
  string s;
  i=0;
  sum=0;
  while(cin>>s){
    
    k=1;
    for(int j=s.size()-1;j>=0;j--){
      if('0'<=s[j]&&s[j]<='9'){
	sum+=k*(s[j]-'0');
	k*=10;
      }else k=1;
    }
    
  }
  cout<<sum<<endl;
    return 0;
}

Measured memory_bytes: 3216
N = int(input())
list = []
for i in range(N):
  list.append(input())

a = 0
w = 0
t = 0
r = 0
for i in range(N):
  if list[i] == "AC":
    a = a + 1
  elif list[i] == "WA":
    w = w + 1
  elif list[i] == "TLE":
    t = t + 1
  elif list[i] == "RE":
    r = r + 1

print("AC x " + str(a))
print("WA x " + str(w))
print("TLE x " + str(t))
print("RE x " + str(r))
  

Measured memory_bytes: 16136
N, A, B = map(int, input().split())
S = input()

A_count = B_count = 0
for i, s in enumerate(S):
    if s == 'a' and A_count + B_count < A + B:
        print('Yes')
        A_count += 1
    elif s == 'b' and A_count + B_count < A + B and B_count < B:
        print('Yes')
        B_count += 1
    else:
        print('No')



Measured memory_bytes: 54872
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <numeric>
#include <utility>
#include <sys/time.h>
#include <cmath>
#include <tuple>
#include <queue>

using namespace std;

vector<int> b(1e5+1, 0);

void solve(int n, vector<int> a) {
    for (int i = 0; i < a.size(); i++) {
        b[a[i]]++;
        b[a[i]+1]++;
        b[a[i]+2]++;
    }
    int ret = *max_element(b.begin(), b.end());
    std::cout << ret << std::endl;
}

int main() {
    struct timeval start,end;
    long long span;
    int n;

    gettimeofday(&start,NULL);

    std::cin >> n;
    vector<int> a(n);
    for (int i = 0; i < n; i++) {
        std::cin >> a[i];
    }
    solve(n, a);

    gettimeofday(&end,NULL);
    span = (end.tv_sec -start.tv_sec)*1000000LL + (end.tv_usec - start.tv_usec);
    std::cerr << "--Total Time: " << span/1000 << "ms" << endl;
    return 0;
}


Measured memory_bytes: 1408
//apc_1f
#include<cstdio>
#include<iostream>
#include<cstring>
#include<algorithm>
using namespace std;
int val[100504],bot[25];
int f[32770];
int getone(int k){
	int res=0;
	while(k)res+=(k&1),k>>=1;
	return res;
}
#define maxS 32768
#define pii pair<int,int>
#define fst first
#define sec second
pii s[32770];
int main(){
	int n;
	scanf("%d",&n);
	for(int i=1;i<n;i++){
		int x,y,a;
		scanf("%d%d%d",&x,&y,&a);
		val[x]^=a,val[y]^=a;
	}
	//for(int i=0;i<n;i++)cout<<val[i]<<' ';cout<<endl;
	
	for(int i=0;i<n;i++)bot[val[i]]++;
	int ans=0;
	for(int i=1;i<=15;i++){
		ans+=bot[i]/2;
		bot[i]=(bot[i]&1);
	}
	int st=0;
	for(int i=1;i<=15;i++)st|=(bot[i]<<(i-1));
	
	memset(f,0x3f,sizeof(f));
	f[st]=0;
	for(int i=0;i<=st;i++)s[i].fst=getone(i),s[i].sec=i;
	sort(s,s+st+1,greater<pii>());
	//for(int i=0;i<=st;i++)cout<<s[i].sec<<' ';cout<<endl;
	//cout<<st<<endl;
	
	for(int i=0;i<=st;i++){
		int e=s[i].sec;
		for(int j=1,_j=1;j<=e;j<<=1,_j++){
			for(int k=1,_k=1;k<=e;k<<=1,_k++){
				if(j==k||(e&j)==0||(e&k)==0)continue;
				int a=(e^j^k),b=(1<<((_j^_k)-1) );
				if(!(a&b))f[a|b]=min(f[a|b],f[e]+1);
				else f[a^b]=min(f[a^b],f[e]+2);
			}
		}
	}
	//for(int i=0;i<=st;i++)cout<<f[i]<<' ';cout<<endl;
	printf("%d\n",f[0]+ans);
	return 0;
}

Measured memory_bytes: 4588
#include<bits/stdc++.h>
using namespace std;
const int maxn=5010,mod=1000000007;
inline void Add(int &a,int b){a=a+b>=mod?a+b-mod:a+b;}
inline int ksm(int a,int b)
{
	int res=1;
	for(;b;b>>=1,a=1ll*a*a%mod) if(b&1) res=1ll*res*a%mod;
	return res;
}
int N,A,B,f[5010][2],F[5010][2],ans;
inline int getv(int x){return x<=2?1:(f[x-2][0]+f[x-2][1])%mod;}
int main()
{
	cin>>N>>A>>B;if(A>B) swap(A,B);f[0][0]=f[0][1]=1;
	for(int i=0;i<N;i++) for(int j=i+1;j<=N;j++)
	{
		Add(f[j][0],f[i][1]);
		if(j-i>=A) Add(f[j][1],f[i][0]);
	}
	for(int i=1;i<N;i++)
	{
		if(i<A) Add(F[i][0],1);
		if(i<B) Add(F[i][1],getv(i+1));
		for(int j=1;j<min(i,A);j++) Add(F[i][0],F[i-j][1]);
		for(int j=1;j<min(i,B);j++) Add(F[i][1],1ll*F[i-j][0]*getv(j)%mod);
		if(N-i<A) Add(ans,F[i][1]);
		if(N-i<B) Add(ans,1ll*F[i][0]*getv(N-i+1)%mod);
	}
	cout<<(ksm(2,N)-ans+mod)%mod<<endl;
}

Measured memory_bytes: 3668
#include<bits/stdc++.h>
#define REP(i,n) for(int i = 0; i < (n); ++i)
using namespace std;
typedef long long int ll;
const ll MOD = 1000000007;

int main() {
  string s;
  cin >> s;
  if (s.length() == 3) {
    reverse(s.begin(), s.end());
  }
  cout << s << endl;
  return 0;
}

Measured memory_bytes: 256
H, W = map(int, input().split())

S = [input() for _ in range(H)]
vis = [[-1 for i in range(W)] for j in range(H)]

for v in range(H):
  for h in range(W):
    if v==0:
      if h==0:
        if S[v][h]=="#":
          vis[v][h]=1
        else:
          vis[v][h]=0
      else:
        if S[v][h-1]=="." and S[v][h]=="#":
          vis[v][h] = vis[v][h-1] + 1
        else:
          vis[v][h] = vis[v][h-1]
    else:
      if h==0:
        if S[v-1][h]=="." and S[v][h]=="#":
          vis[v][h] = vis[v-1][h] + 1
        else:
          vis[v][h] = vis[v-1][h]
      else:
        if S[v-1][h]=="." and S[v][h]=="#":
          bufv = vis[v-1][h] + 1
        else:
          bufv = vis[v-1][h]
        if S[v][h-1]=="." and S[v][h]=="#":
          bufh = vis[v][h-1] + 1
        else:
          bufh = vis[v][h-1]
        vis[v][h] = min(bufv, bufh)
    
    #print(vis)
        
print(vis[H-1][W-1])

Measured memory_bytes: 3188
#include <bits/stdc++.h>
typedef long long ll;
typedef long double ld;
const int INF=1e9,MOD=1e9+7,ohara=1e6+10;
const ll LINF=1e18;
using namespace std;

#define rep(i,n) for(int (i)=0;(i)<(int)(n);(i)++)
#define rrep(i,a,b) for(int i=(a);i<(b);i++)
#define rrrep(i,a,b) for(int i=(a);i>=(b);i--)
#define all(v) (v).begin(), (v).end()
#define Size(n) (n).size()
#define Cout(x) cout<<(x)<<endl
#define doublecout(a) cout<<fixed<<setprecision(15)<<a<<endl;
#define Cerr(x) cerr<<(x)<<endl
#define fi first
#define se second
#define P pair<ll,ll> 
#define m_p make_pair
#define V vector<ll> 

ll n,cnt,ans,a[ohara],b,c,d,tmp,tmpp,m,h,w,x,y,sum,pos,k;
ld doua;
int dy[]={1,0,-1,0};
int dx[]={0,1,0,-1};
//int dy[]={-1,0,1,-1,1,-1,0,1};
//int dx[]={-1,-1,-1,0,0,1,1,1};
string alph("abcdefghijklmnopqrstuvwxyz"),s;
bool fl;
struct edge{int to,cost;};
map<ll,ll> mp;

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

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

    cin>>n;
    rep(i,n){
        cin>>a[i];
        mp[a[i]]++;
    }
    rep(i,n){
        if(mp[a[i]]%2==1){
            ans++;
            mp[a[i]]=0;
        }
    }
    Cout(ans);
    return 0;
}


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

int main()
{
    int a, b, c, d;
    cin>>a>>b>>c>>d;
    bool flag=true;
    while(a>0 && c>0)
    {
        if(flag)
        {
            c-=b;
            flag=false;
        }
        else
        {
            a-=d;
            flag=true;
        }
    }
    if(flag)
        cout<<"No";
    else
        cout<<"Yes";
}

Measured memory_bytes: 3620
#include <iostream>
#include <string>
#define mod 1000003
using namespace std;
int n,m[1000004],ch[1<<8];
int h(int num,int i){return (num%mod+i*(1+num%(mod-1)))%mod;}

void insert(string str){
  int i=0,num=0;
  while(str[i])num=num*5+ch[str[i++]];
  int idx=0;i=0;
  while(m[(idx=h(num,i++))]!=0);
  m[idx]=num;
}

bool find(string str){
  int i=0,num=0;
  while(str[i])num=num*5+ch[str[i++]];
  int idx=0;i=0;
  while(i<mod&&(m[(idx=h(num,i++))]!=0&&m[idx]!=num));
  return m[idx]==num;
}

int main(){
  ch['A']=1,ch['C']=2,ch['G']=3,ch['T']=4;
  cin>>n;
  while(n--){
    string str,key;
    cin>>str>>key;
    if(str[0]=='i')insert(key);
    if(str[0]=='f') cout<<(find(key)?"yes":"no")<<endl;
  }

}

Measured memory_bytes: 5112
#include <iostream>
using namespace std;
int main() {
    int a, b, c, temp;
    cin>>a>>b>>c;
    temp = b;
    b = a;
    a = temp;
    temp = c;
    c = a;
    a = temp;
    cout<<a<<" "<<b<<" "<<c; 
  return 0;
}


Measured memory_bytes: 3592
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
typedef long long ll;

ll N,X;
ll B[100010],L[100010],U[100010];
ll Usum[100010],Lsum[100010] = {};

int main(){
    cin >> N >> X;
    vector<pair<ll,int>> v;
    v.push_back({1e9,1e9});
    for(int i=1;i<=N;i++){
        cin >> B[i] >> L[i] >> U[i];
        v.push_back({(X-B[i])*U[i]+B[i]*L[i],i});
    }
    sort(v.begin()+1,v.end(),greater<pair<ll,int>>());
    for(int i=1;i<=N;i++){
        int id = v[i].second;
        Usum[i] = Usum[i-1]+(X-B[id])*U[id];
        Lsum[i] = Lsum[i-1]-B[id]*L[id];
    }
    ll l = -1,r = X*N;
    while(l+1<r){
        ll m = (l+r)/2;
        ll x = m/X,y = m%X;
        bool ok = false;
        for(ll i=1;i<=N;i++){
            ll value = 0;
            ll res = x;
            value += Usum[min(i-1,res)];
            value += Lsum[i-1]-Lsum[min(i-1,res)];
            res -= min(i-1,res);
            value += Usum[i+res]-Usum[i];
            value += Lsum[N]-Lsum[i+res];
            int id = v[i].second;
            if(y-B[id]>=0) value += U[id]*(y-B[id]);
            else value -= L[id]*(B[id]-y);
            if(value>=0) ok = true;
        }
//        cerr << "m:" << m << " x:" << x << " y:" << y << " ok:" << ok << endl;
        if(ok) r = m;
        else l = m;
    }
    cout << r << endl;
}

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

int main(){
  int N;cin >> N;
  string S;cin >> S;
  int Bsum = 0;
  vector<int> B(N,0);
  if(S[0]=='#'){
    B[0]=1;
    Bsum ++;
  }
  for(int i=1;i<N;i++){
    if(S[i]=='#'){
      B[i] = B[i-1] + 1;
      Bsum ++;
    }else{
      B[i] = B[i-1];
    }
  }
  int ans = N - Bsum;
  for(int i=0;i<N;i++){
    ans = min(ans,B[i]+N-i-1-(Bsum-B[i]));
  }
  ans = min(ans,Bsum);
  cout << ans << endl;
}

Measured memory_bytes: 4416
#include <bits/stdc++.h>
#define REV(v) reverse(v.begin(), v.end());
#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, start, stop) for (int i = start; i < stop; i++)
#define FORR(i, start, stop) for (int i = start; i > stop; i--)
#define SORT(v, n) sort(v, v + n);
#define SORTR(v, n) sort(v, v + n,greater<int>());
#define VSORT(v) sort(v.begin(), v.end());
#define VSORTR(v) sort(v.begin(), v.end(),greater<int>());
#define REMOVE(v,n) remove(vector<int> v,v+v.size(),int n)
#define ll long long
#define ull unsigned long long
#define pb(a) push_back(a)
#define INF 999999999
#define V(v,i,j) vector(v.begin() + i, v.begin() + j)
#define INSERT(va,vb) va.insert(va.end(), vb.begin(), vb.end())
using namespace std;
typedef vector<int> vint;
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};
int dx[] = {1, -1, 0, 0};
const int MOD = 1000000007;

//vector< vector<int> > v (size1, vector<int>(size2) );
const int MAX = 510000;

long long fac[MAX], finv[MAX], inv[MAX];

// テーブルを作る前処理
void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}

// 二項係数計算
long long COM(int n, int k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

int main(){
    COMinit();
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n,k;
    cin>>n>>k;
    FOR(i,0,k){
        cout<<COM(k-1,i)*COM(n-k+1,i+1)%MOD<<endl;
    }
}


Measured memory_bytes: 12160
import Data.List
import qualified Data.IntMap as IM
main=interact$show.f.map(read.filter(/=' ')).lines
f[n,p,q]=abs$(m IM.! p)-(m IM.! q)where
  m=IM.fromList$zip k[0..]
  k=sort.map(foldl(\x y->x*10+y)0)$permutations[1..n]

Measured memory_bytes: 13864
import java.util.*;
import java.io.*;
import java.awt.geom.*;
import java.math.*;

public class Main implements Runnable {

	static final Scanner in = new Scanner(System.in);
	static final PrintWriter out = new PrintWriter(System.out,false);
	static boolean debug = false;

	static int[] depth;
	static int[][] parents;

	static void initLca(int[][][] g, int r) {
		int n = g.length;
		int[] parent = new int[n];
		depth = new int[n]; // todo global
		dfsLca(g, parent, depth, r, -1, 0);

		parents = parents(parent); // todo global
	}

	static void dfsLca(int[][][] g, int[] parent, int[] depth, int cur, int prev, int d) {
		parent[cur] = prev;
		depth[cur] = d;

		for (int[] to : g[cur]) {
			if (to[0] == prev) continue;
			dfsLca(g, parent, depth, to[0], cur, d+1);
		}
	}

	static int[][] parents(int[] parent) {
		int n = parent.length;
		int logN = Integer.numberOfTrailingZeros(Integer.highestOneBit(n-1))+1;

		int[][] res = new int[logN][n];
		res[0] = parent;

		for (int k=0; k<logN-1; k++) {
			for (int i=0; i<n; i++) {
				if (res[k][i] < 0) res[k+1][i] = -1;
				else res[k+1][i] = res[k][res[k][i]];
			}
		}

		return res;
	}

	static int lca(int u, int v, int[][] parents, int[] depth) {
		if (depth[u] > depth[v]) {
			int t = u; u = v; v = t;
		}

		int logN = parents.length;
		int n = parents[0].length;

		for (int k=0; k<logN; k++) {
			if (((depth[v] - depth[u])>>k&1) == 1) {
				v = parents[k][v];
			}
		}
		if (u == v) return u;

		for (int k=logN-1; k>=0; k--) {
			if (parents[k][u] != parents[k][v]) {
				u = parents[k][u];
				v = parents[k][v];
			}
		}

		return parents[0][u];
	}

	static int[][][] undirectedGraph(int n, int[] v1, int[] v2, int[] cost) {
		int[] cnt = new int[n];
		for (int i : v1) cnt[i]++;
		for (int i : v2) cnt[i]++;

		int[][][] g = new int[n][][];
		for (int i=0; i<n; i++) g[i] = new int[cnt[i]][2];
		for (int i=0; i<v1.length; i++) {
			int s = v1[i];
			int t = v2[i];

			g[s][--cnt[s]][0] = t;
			g[s][cnt[s]][1] = cost[i];

			g[t][--cnt[t]][0] = s;
			g[t][cnt[t]][1] = cost[i];
		}

		return g;
	}

	public void run() {
		int n = in.nextInt();
		int r = -1;

		ArrayList<int[]> list = new ArrayList<>();
		boolean[] refed = new boolean[n];
		for (int i=0; i<n; i++) {
			int k = in.nextInt();
			for (int j=0; j<k; j++) {
				int c = in.nextInt();
				list.add(new int[]{i, c});
				refed[c] = true;
			}
		}

		for (int i=0; i<n; i++) {
			if (!refed[i]) {
				r = i;
			}
		}

		int e = list.size();
		int[] s = new int[e];
		int[] t = new int[e];
		int[] c = new int[e];
		for (int i=0; i<e; i++) {
			s[i] = list.get(i)[0];
			t[i] = list.get(i)[1];
			c[i] = 0;
		}

		int[][][] g = undirectedGraph(n, s, t, c);
		initLca(g, r);

		int q = in.nextInt();
		while (q-- > 0) {
			int u = in.nextInt();
			int v = in.nextInt();
			out.println(lca(u, v, parents, depth));
		}

		out.flush();
		in.close();
		out.close();
	}

	public static void main(String[] args) {
		debug = args.length > 0;
		new Thread(null, new Main(), "", 16 * 1024 * 1024).start();
	}

	static void dump(Object... o) { if (debug) System.err.println(Arrays.deepToString(o)); }
}

Measured memory_bytes: 162260
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int max_n=300005;
int n,a[max_n];
ll l[max_n],r[max_n];
int main(){
    scanf("%d",&n);
    for(int i=1;i<=n*3;i++)scanf("%d",a+i);
    priority_queue<int,vector<int>,greater<int>> que;
    ll cur=0;
    for(int i=1;i<=n*3;i++){
        if(que.size()<n)que.push(a[i]),cur+=a[i];
        else{
            int x=que.top();
            if(x<a[i]){
                que.pop(),que.push(a[i]);
                cur-=x,cur+=a[i];
            }
        }
        l[i]=cur;
    }
    for(int i=1;i<=n*3;i++)a[i]=-a[i];
    while(!que.empty())que.pop();
    cur=0;
    for(int i=n*3;i>=1;i--){
        if(que.size()<n)que.push(a[i]),cur+=a[i];
        else{
            int x=que.top();
            if(x<a[i]){
                que.pop(),que.push(a[i]);
                cur-=x,cur+=a[i];
            }
        }
        r[i]=cur;
    }
    ll ans=-1e18;
    for(int i=n;i<=2*n;i++)ans=max(ans,l[i]+r[i+1]);
    printf("%lld\n",ans);
    return 0;
}

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

int main(){
  int n,a=100000000,h=0;
  int count = 0;
  cin >> n;
  int n_new = n;
  
  while(count<9){
    h += n_new/a;
    n_new -= (n_new/a)*a;
    a /= 10;
    count ++;
  }
  
  if(h == 0){
    cout << "No" << endl;
  }else{
    int check=0;
    check = n % h;
  	if(check == 0){
    	cout << "Yes" <<endl;
  	}else{
    	cout << "No" << endl;
  	}
  }
}

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

using namespace std;

//typedef pair<int,int> P;

int main(){
	int N;
	long long A[200000];
	A[0] = 0;
	scanf("%d", &N);
	for(int i=1;i<=N;i++){
		scanf("%lld", &A[i]);
	}
	for(int i=1;i<=N;i++){
		A[i] += A[i-1];
	}

	sort(A,A+(N+1));
	//for(int i=0;i<=N;i++) printf("%lld ", A[i]);

	long long ans = 0;
	for(int i=0;i<N;i++){
		int tmp;
		for(int j=i;j<=N;j++){
			if(A[i]!=A[j]){
				tmp = j-1;
				break;
			}
			if(j==N) tmp = N;
		}
		long long num = tmp-i+1;
		if(num>1){
			ans += num*(num-1)/2;
		}
		i = tmp;
	}

	printf("%lld\n", ans);

	return 0;
}


Measured memory_bytes: 1792
#pragma once
#include <stdio.h>
#include <sstream>
#include <string>
#include <string.h>
#include <vector>
#include <map>
#include <algorithm>
#include <iostream>
#include <utility>
#include <set>
#include <cctype>
#include <queue>
#include <stack>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <deque>
#include <limits>
#include <iomanip>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
#define bit(x,v) ((ll)x << v)

const ll INF = 1000000007;
const int MAX = 210000;
const int MOD = 1000000007;

long long fac[MAX], finv[MAX], inv[MAX];
void COMinit() {
	fac[0] = fac[1] = 1;
	finv[0] = finv[1] = 1;
	inv[1] = 1;
	for (int i = 2; i < MAX; i++) {
		fac[i] = fac[i - 1] * i % MOD;
		inv[i] = MOD - inv[MOD % i] * (MOD / i) % MOD;
		finv[i] = finv[i - 1] * inv[i] % MOD;
	}
}

// 二項係数計算
long long COM(int n, int k) {
	if (n < k) return 0;
	if (n < 0 || k < 0) return 0;
	return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

ll gcd(ll a, ll b) {
	if (b == 0) return a;
	return gcd(b, a % b);
}
int pr[100010];
void uini(int n) {
	for (size_t i = 0; i <= n; i++)
	{
		pr[i] = i;
	}
}

int parent(int x) {
	if (x == pr[x]) return x;
	return pr[x] = parent(pr[x]);
}

bool unit(int x, int y) {
	int px = parent(x);
	int py = parent(y);

	if (px == py) return false;
	if (px < py) {
		pr[py] = px;
	}
	else {
		pr[px] = py;
	}
	return true;
}

// res[i][c] := i 文字目以降で最初に文字 c が登場する index (存在しないときは n)
vector<vector<int> > calcNext(const string & S) {
	int n = (int)S.size();
	vector<vector<int> > res(n + 1, vector<int>(26, n));
	for (int i = n - 1; i >= 0; --i) {
		for (int j = 0; j < 26; ++j) res[i][j] = res[i + 1][j];
		res[i][S[i] - 'a'] = i;
	}
	return res;
}
// mod 1000000007 の世界で a += b する関数
void add(long long& a, long long b) {
	a += b;
	if (a >= MOD) a -= MOD;
}

ll f(ll b, ll n) {
	if (b > n) return n;
	return f(b, n / b) + (n % b);
}
ll x[35], y[35];
ll memo[35][35][35][35];
int n;
ll calc(int x1, int y1, int x2, int y2) {

	ll &res = memo[x1][y1][x2][y2];
	if (~res) return res;
	res = 0;
	ll xl = x[x1];
	ll yu = y[y1];
	ll xr = x[x2];
	ll yd = y[y2];
	for (size_t i = 0; i < n; i++)
	{
		if (x[i] <= xl || xr <= x[i] || y[i] <= yu || yd <= y[i]) continue;
		ll sum = (xr - xl - 1) + (yd - yu - 1) - 1;
		sum += calc(x1, y1, i, i);
		sum += calc(i, y1,x2,i);
		sum += calc(x1, i, i, y2);
		sum += calc(i, i, x2, y2);
		res = max(res, sum);
	}
	return res;
}
void solv() {

	int n;
	cin >> n;
	ll x[55], y[55];
	for (size_t i = 0; i < n; i++)
	{
		cin >> x[i] >> y[i];
	}

	map<vector<int>, int> p;
	int m = 0;
	for (size_t i = 0; i < n; i++)
	{
		for (size_t j = i + 1; j < n; j++)
		{
			int p1 = x[i] - x[j];
			int p2 = y[i] - y[j];
			if (p1 == 0 && p2 == 0) continue;
			p[{p1, p2}]++;
			m = max(p[{p1, p2}], m);
			p[{-p1, -p2}]++;
			m = max(p[{-p1, -p2}], m);
		}
	}
	int res = 1 + ((n - 1) - m);
	cout << res << endl;
}

int main() {
//	COMinit();
	solv();

	return 0;
}


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

#define ALL(a) (a).begin(), (a).end()
#define FOR(i, s, n) for (int i = (s); i < (n); i++)
#define rep(i, n) FOR(i, 0, n)
#define repi(i, n) FOR(i, 1, n + 1)
#define pp(v) cerr << #v "=" << (v) << endl;
#define ppa(v) cerr << "- " << #v << endl; rep(i,v.size()) cerr << #v << "[" << i << "] = " << v[i] << endl;
#define div_ceil(a,b) ((a) + ((b) - 1)) / (b)
#define UNIQUE(v) v.erase( unique(ALL(v)), v.end() );
#define INF 0x3f3f3f3f
#define LLINF 1000111000111000111LL
#define MOD 1000000007
#define TIME system("date +%M:%S.%N")
using Graph = vector<vector<int>>;
using ll = long long;
template<class T> T gcd(const T &a, const T &b) { return a < b ? gcd(b, a) : b ? gcd(b, a % b) : a; }
template<class T> T lcm(const T &a, const T &b) { return a / gcd(a, b) * b; }

int main() {
  int n;cin>>n;
  vector<int> a(n+2,0);
  repi(i,n)cin>>a[i];
  int d = 0;
  rep(i,n+2) d += abs(a[i+1] - a[i]);
  repi(i,n) {
    int ans = d - abs(a[i]-a[i-1]) - abs(a[i+1]-a[i]) + abs(a[i+1]-a[i-1]);
    cout << ans << endl;
  }
}


Measured memory_bytes: 1664
#include<iostream>
#include<algorithm>
#include<string>
#include<iomanip>
#include<cmath>
using namespace std;

int main() {
	int n;
	cin >> n;
	n = n % 10;
	if (n == 2 || n == 4 || n == 5 || n == 7 || n == 9)cout << "hon";
	else if (n == 0 || n == 1 || n == 6 || n == 8)cout << "pon";
	else cout << "bon";
}


Measured memory_bytes: 3612
#include <cstdio>
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
typedef long long int_;
inline int readint() {
	int a = 0; char c = getchar(), f = 1;
	for(; c<'0' or c>'9'; c=getchar())
		if(c == '-') f = -f;
	for(; '0'<=c and c<='9'; c=getchar())
		a = (a<<3)+(a<<1)+(c^48);
	return a*f;
}
void writeint(int_ x){
	if(x < 0) putchar('-'), x = -x;
	if(x > 9) writeint(x/10);
	putchar((x%10)^48);
}
# define MB template < typename T >
MB void getMax(T &a,const T &b){ if(a < b) a = b; }
MB void getMin(T &a,const T &b){ if(b < a) a = b; }
# define FOR(i,n) for(int i=0; i<(n); ++i)

int main(){
	int k = readint(), a = readint(), b = readint();
	if(a <= b/k*k) puts("OK"); else puts("NG");
	return 0;
}

Measured memory_bytes: 3580
#include <stdio.h>
int main(void){
    int n;
    scanf("%d",&n);
    for(int i=0;i<n;i++){
        int k,p,x;
        scanf("%d %d",&k,&p);
        if(k%p==0) x=p;
        else x=k%p;
        printf("%d\n",x);
    }
}



Measured memory_bytes: 2052
#!python3

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

def resolve():
    N, K = iim()
    mod = 10**9 + 7

    dp = [[0]*(K+1) for i in range(2)]

    dp0, dp1 = dp
    dp0[0] = 1
    for i in range(1, N+1):
        for j in range(1, K+1):
            dp1[j] = (dp0[j-1] + dp0[j]*j) % mod
        dp1[0] = 0
        dp0, dp1 = dp1, dp0
    print(dp0[K] % mod)
if __name__ == "__main__":
    resolve()



Measured memory_bytes: 5608
#include <iostream>
#include <algorithm>
#include <bitset>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <utility>
#include <vector>
#include <complex>
#include <string.h>
#include <numeric>
using namespace std;

//#define int long long
#define reps(i,s,n) for(int (i)=(s);(i)<(n);++(i))
#define rep(i,n) reps(i,0,n)
#define rept(i,n) rep(i,(n)+1)
#define repst(i,s,n) reps(i,s,(n)+1)
#define reprt(i,n,t) for(int (i)=(n);(i)>=(t);--(i))
#define repr(i,n) reprt(i,n,0)
#define each(i,v) for(auto &(i):(v))
#define eachr(i,v) for(auto &(i)=(v).rbegin();(i)!=(v).rend();(i)++)
#define all(c) (c).begin(),(c).end()
#define rall(c) (c).rbegin(),(c).rend()
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define tmax(x,y,z) max(x,max(y,z))
#define tmin(x,y,z) min(x,min(y,z))
#define chmin(x,y) x=min(x,y)
#define chmax(x,y) x=max(x,y)
#define ln '\n'
#define bln(i,n) (((i)==(n)-1)?'\n':' ')
#define dbg(x) cout<<#x" = "<<(x)<<ln<<flush
#define dbga(x,n) {cout<<#x" : ";for(int (i)=0;i<(n);++i){cout<<((x)[i])<<(i==((n)-1)?'\n':' ')<<flush;}}
#define zero(a) memset(a,0,sizeof(a))
#define unq(a) sort(all(a)),a.erase(unique(all(a)),a.end())
#define endl "\n"

//typedef complex<double> P;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<string> vst;
typedef vector<pii> vpii;
typedef vector<pll> vpll;
typedef vector<vector<int> > mat;

const ll inf = (ll)1e9+10;
const ll linf = (ll)1e18+10;
const ll mod = (ll)(1e9+7);
const int dx[] = {0, 1, 0, -1};
const int dy[] = {1, 0, -1, 0};
const int ddx[] = {0, 1, 1, 1, 0, -1, -1, -1};
const int ddy[] = {1, 1, 0, -1, -1, -1, 0, 1};
const double eps = 1e-10;

ll mop(ll a,ll b=mod-2,ll m=mod) {ll r=1;a%=m;for(;b;b>>=1){if(b&1)r=r*a%m;a=a*a%m;}return r;}
ll gcd(ll a,ll b) {return b?gcd(b,a%b):a;}
ll lcm(ll a,ll b) {return a/gcd(a,b)*b;}
bool ool(int x,int y,int h,int w) {return((x<0)||(h<=x)||(y<0)||(w<=y));}
bool deq(double a,double b) {return abs(a-b)<eps;}

struct oreno_initializer {
    oreno_initializer() {
        cin.tie(0);
        ios::sync_with_stdio(0);
    }
} oreno_initializer;



int n;
vector<int> a, res;

signed main() {
    cin >> n;
    a.resize(n);
    rep(i,n) cin >> a[i];
    rep(i,n) {
        bool ng = 1;
        repr(j,n-1-i) if (a[j]==j+1) {
            ng = 0;
            res.push_back(a[j]);
            a.erase(a.begin()+j);
            break;
        }
        if (ng) return cout << -1 << endl, 0;
    }
    repr(i,n-1) cout << res[i] << endl;
}

Measured memory_bytes: 256
import java.util.*;

public class Main{
  public static void main(String[]args){
    Scanner sc=new Scanner(System.in);
    String s=sc.next();
    String k[]=s.split(",");
    for(int i=0;i<k.length;i++){
      System.out.print(k[i]+" ");
    }
    System.out.println("");
    
  }
}

Measured memory_bytes: 21460
#include <iostream>
#include <complex>
#include <stdio.h>

using namespace std;

const double EPS = 1e-12;

typedef complex<double> P;
struct L{ P p, q; L(P p, P q) : p(p), q(q) {} };

double cross(P a, P b) { return imag(conj(a)*b); }

double lpDist(L l, P p){
	return abs(cross(l.q-l.p,p-l.p))/abs(l.q-l.p);
}

P crossPoint(L l, L m){
	double A = cross(l.q-l.p, m.q-m.p);
	double B = cross(l.q-l.p, l.q-m.p);
	return m.p + B/A*(m.q-m.p);
}

int main(){
	int x1, y1, x2, y2, x3, y3;
	while(cin >> x1 >> y1 >> x2 >> y2 >> x3 >> y3){
		if(!(x1||y1||x2||y2||x3||y3)) break;
		P p1 = P(x1,y1), p2 = P(x2,y2), p3 = P(x3,y3);
		P dirA = (p2-p1)/abs(p2-p1)+(p3-p1)/abs(p3-p1);
		P dirB = (p1-p2)/abs(p1-p2)+(p3-p2)/abs(p3-p2);
		P c = crossPoint(L(p1,p1+dirA),L(p2,p2+dirB));
		double rA, rB, rC;
		double leftA = 0.0, rightA = 1.0, leftB, rightB, leftC, rightC;
		while(true){
			double midA = (leftA+rightA)/2;
			P cA = p1 + (c-p1)*midA, cB, cC;
			rA = lpDist(L(p1,p2), cA);
			leftB = 0.0, rightB = 1.0, leftC = 0.0, rightC = 1.0;
			while(rightB-leftB>EPS){
				double midB = (leftB+rightB)/2;
				cB = p2 + (c-p2)*midB;
				rB = lpDist(L(p2,p3), cB);
				if(rA+rB < abs(cB-cA)) leftB  = midB;
				else                   rightB = midB;
			}
			while(rightC-leftC>EPS){
				double midC = (leftC+rightC)/2;
				cC = p3 + (c-p3)*midC;
				rC = lpDist(L(p3,p1), cC);
				if(rA+rC < abs(cC-cA)) leftC  = midC;
				else                   rightC = midC;
			}
			if(rB+rC > abs(cB-cC)) leftA  = midA;
			else                   rightA = midA;
			if(rightA-leftA < EPS){
				printf("%.6lf %.6lf %.6lf\n", rA, rB, rC);
				break;
			}
		}
	}
}

Measured memory_bytes: 944
#include "bits/stdc++.h"
using namespace std;
#define MOD 1000000007
#define FOR(i,a,b) for(long long i=(a);i<(b);i++)
#define REP(i,n)  FOR(i,0,n)
#define ITR(itr,mp) for(auto itr = (mp).begin(); itr != (mp).end(); ++itr)
#define dump(x)  cout << #x << " = " << (x) << endl;
#define debug(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;
typedef long long ll;
typedef pair<ll,ll> P;
typedef vector<vector<P>> Graph;


int main(){

  int n;
  cin >> n;
  
  cout << "ABC" << n << endl;


 return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <atcoder/all>

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

using namespace std;
using namespace atcoder;
using ll = long long;

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

    int n, m;
    cin >> n >> m;
    int a, b;
    dsu d(n);
    rep(i, m) {
        cin >> a >> b;
        a--; b--;
        d.merge(a, b);
    }

    printf("%d\n", d.groups().size() - 1);

    return 0;
}

Measured memory_bytes: 8980
#include <iostream>
#include <string.h>
#include <vector>
#include <map>
#include <algorithm>
using namespace std;
int main(void){
   int N;
   cin>>N;
   int a[N];
   for(int i=0;i<N;i++){
       cin>>a[i];
   }
   int check[N];
   for(int i=0;i<N;i++){
       check[i]=0;
   }
   for(int i=0;i<N;i++){
       check[a[i]]++;
   }
   int count=0; bool judge=true;
   for(int i=0;i<N;i++){
       if(check[i]==2) {count++;}
       if(check[i]>2) {judge=false; }
       
   }
   
   if(N%2==1&&check[0]>1) {judge=false; }
   if(!judge) {cout<<0;}
   else {int sum=1;
   for(int i=1;i<=count;i++){
      sum=(sum*2)%1000000007;
   }
   cout<<sum;}
   return 0;
}


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

using namespace std;

#define REP(i, a, b) for (int i = (a), i##_end_ = (b); i < i##_end_; ++i)
#define debug(...) fprintf(stderr, __VA_ARGS__)
#define mp make_pair
#define x first
#define y second
#define pb push_back
#define SZ(x) (int((x).size()))
#define ALL(x) (x).begin(), (x).end()

template<typename T> inline bool chkmin(T &a, const T &b) { return a > b ? a = b, 1 : 0; }
template<typename T> inline bool chkmax(T &a, const T &b) { return a < b ? a = b, 1 : 0; }

typedef long long LL;

const int oo = 0x3f3f3f3f;
const LL OO = 0x3f3f3f3f3f3f3f3fLL;

const int maxn = 500100;

int n, A, B, C, D;

bool solve()
{
	REP(i, 0, n + 1)
	{
		LL l = A + (LL)C * i - (LL)D * (n - i);
		LL r = A + (LL)D * i - (LL)C * (n - i);
		if (l <= B && B <= r) return 1;
	}
	return 0;
}

int main()
{
#ifdef matthew99
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif
	scanf("%d%d%d%d%d", &n, &A, &B, &C, &D), --n;
	puts(solve() ? "YES" : "NO");
	return 0;
}


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

void merge_sort(long long x[], int n)
{
	static long long y[100001] = {};
	if (n <= 1) return;
	merge_sort(&(x[0]), n/2);
	merge_sort(&(x[n/2]), (n+1)/2);
	
	int i, p, q;
	for (i = 0, p = 0, q = n/2; i < n; i++) {
		if (p >= n/2) y[i] = x[q++];
		else if (q >= n) y[i] = x[p++];
		else y[i] = (x[p] > x[q])? x[p++]: x[q++];
	}
	for (i = 0; i < n; i++) x[i] = y[i];
}

int is_feasible(int n, int m, int* A[], int b[])
{
	int i, j, k, l, *p = (int*)malloc(sizeof(int) * (n + 1));
	for (i = 1; i <= n; i++) p[i] = i;
	
	for (j = 1, k = 1; j <= m && k <= n; j++) {
		for (i = k; i <= n; i++) if (A[p[i]][j] == 1) break;
		if (i > n) continue;
		if (i != k) {
			p[i] ^= p[k];
			p[k] ^= p[i];
			p[i] ^= p[k];
		}
		for (i = k + 1; i <= n; i++) {
			if (A[p[i]][j] == 1) {
				for (l = j; l <= m; l++) A[p[i]][l] ^= A[p[k]][l];
				b[p[i]] ^= b[p[k]];
			}
		}
		k++;
	}
	
	int ans = 0;
	for (i = 1; i < k; i++) if (b[p[i]] == 1) break;
	if (i < k) {
		for (i = k; i <= n; i++) if (b[p[i]] == 1) break;
		if (i > n) ans = 1;
	}
	free(p);
	return ans;
}

int main ()
{
	int i, N;
	long long a[100001];
	scanf("%d", &N);
	for (i = 0; i < N; i++) scanf("%lld", &(a[i]));
	merge_sort(a, N);
	
	long long bit[61];
	for (i = 1, bit[0] = 1; i <= 60; i++) bit[i] = bit[i-1] << 1;
	
	int j, k, l, m, n, *A[61], b[61], ans[61] = {}, count;
	for (i = 1; i <= 60; i++) A[i] = (int*)malloc(sizeof(int) * (N + 1));
	for (i = 59; i >= 0; i--) {
		for (j = 0, count = 0; j < N && a[j] >= bit[i]; j++) if ((a[j] & bit[i]) != 0) count++;
		if (count == 0) continue;
		else if (count % 2 == 1) {
			ans[i] = 1;
			continue;
		}
		
		for (k = 59, n = 0; k >= i; k--) {
			if (ans[k] == 2 || k == i) b[++n] = 1;
			else continue;
			for (l = 0; l < j; l++) {
				if ((a[l] & bit[k]) != 0) A[n][l+1] = 1;
				else A[n][l+1] = 0;
			}
		}
		if (is_feasible(n, j, A, b) == 1) ans[i] = 2;
	}
	
	long long tmp = 0;
	for (i = 0; i <= 59; i++) tmp += bit[i] * ans[i];
	printf("%lld\n", tmp);
	fflush(stdout);
	return 0;
}

Measured memory_bytes: 26744
using System;

namespace A___Can_you_get_AC
{
    class Program
    {
        static void Main (string[] args)
        {
            var s = Console.ReadLine ();
            for (var i = 1; i < s.Length; i++)
            {
                if (s[i - 1] == 'A' && s[i] == 'C')
                {
                    Console.WriteLine ("Yes");
                    return;
                }
            }
            Console.WriteLine ("No");
        }
    }
}

Measured memory_bytes: 11092
// https://atcoder.jp/contests/abc146/tasks/abc146_d
#include <bits/stdc++.h>
#define REP(i, n) FOR(i, 0, n)
#define REPR(i, n) for (int i = n - 1; i >= 0; i--)
#define FOR(i, s, n) for (int i = (s), i##_len = (n); i < i##_len; ++i)
#define ALL(obj) (obj).begin(), (obj).end()
#define ALLR(obj) (obj).rbegin(), (obj).rend()
#define DIV(a, b) ((a - 1) / b + 1)
#define int long long
using namespace std;
using Graph = vector<vector<int>>;

// 繋がっている頂点
Graph G;
// 繋がっている頂点に対する辺番号
map<pair<int, int>, int> mp;
// 各辺の色番号
vector<int> color;

// 現在の頂点番号、前の頂点番号、前の色
void dfs(int now, int pre, int pre_c) {
    // 色番号
    int cnt = 1;
    for (auto next : G[now]) {
        // 現在の頂点に対して前後が同じならスキップ
        if (next == pre)
            continue;
        // 直前の色とかぶらないようにする
        if (cnt == pre_c) {
            cnt++;
        }
        // mp[key]だと見つからなかった場合に例外が出ないので
        // mp.at(key)にする
        int idx = mp.at({now, next});
        color[idx] = cnt;
        dfs(next, now, color[idx]);
        cnt++;
    }
}

signed main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    int N;
    cin >> N;
    G.resize(N);
    color.resize(N - 1);

    REP(i, N - 1) {
        int a, b;
        cin >> a >> b;
        a--, b--;
        G[a].push_back(b);
        G[b].push_back(a);
        mp[{a, b}] = i;
        mp[{b, a}] = i;
    }
    // 色の最大数は最大の辺の数
    int maxv = 0;
    for (auto &x : G) {
        maxv = max(maxv, (int)x.size());
    }
    // 0番目の頂点からDFSする（前の頂点番号と色なし）
    dfs(0, -1, -1);
    cout << maxv << "\n";
    REP(i, N - 1) { cout << color[i] << "\n"; }

    return 0;
}

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

int main(){
    int h, w;
    cin >> h >> w;
    auto s = vector<vector<bool>>(h, vector<bool>(w, false));
    auto adj = vector<vector<int>>(h*w, vector<int>(h*w, 999999));
    auto d = vector<vector<int>>(h*w, vector<int>(h*w, 999999));
    REP(i, h){
        string temp;
        cin >> temp;
        REP(j, w){
            if(temp[j] == '#'){
                s[i][j] = true;
                // cout << i << j << endl;
            }
            // cout << temp[j] << endl;
        }
    }

    REP(i, h){
        REP(j, w - 1){
            if(s[i][j] == false && s[i][j+1] == false){
                d[j + i*w][(j+1) + i*w] = 1;
                d[(j+1) + i*w][j + i*w] = 1;
            }
        }
    }
    REP(j, w){
        REP(i, h - 1){
            if(s[i][j] == false && s[i+1][j] == false){
                d[j + i*w][j + (i+1)*w] = 1;
                d[j + (i+1)*w][j + i*w] = 1;
            }
        }
    }

    REP(i, h){
        REP(j, w){
            d[j + i*w][j + i*w] = 0;
        }
    }

    REP(k, h*w){
        REP(i, h*w){
            REP(j, h*w){
                d[i][j] = min(d[i][j], d[i][k] + d[k][j]);
            }
        }
    }

    REP(i, h*w){
        REP(j, h*w){
            if(d[i][j] == 999999){
                d[i][j] = 0;
            }
        }
    }

    int m = 0;
    REP(i, h*w){
        REP(j, h*w){
            m = max(m, d[i][j]);
        }
    }

    cout << m << endl;

}

Measured memory_bytes: 1536
#include <stdio.h>
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <vector>
#include <string.h>
#include <stdlib.h>
#include <limits>
#include <iomanip>
using namespace std;

int main(){

    string C;
    cin >> C;

    string abc = "abcdefghijklmnopqrstuvwxyz";

    for( int i = 0 ; i < abc.size() ; i++ ){
        if( abc[i] == C[0] ) cout << abc[i+1] << endl;
    }


}

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

int main(){
  int n,m ;
  cin >>n>>m;
  vector<int> vec(m);
  vector<int> vec2(m-1);
  for(int i = 0; i<m;i++){
    cin >> vec[i];
  }
  sort(vec.begin(), vec.end());
  for(int i=0;i<m-1;i++){
    vec2[i]= vec[i+1] - vec[i];
  }
  sort(vec2.begin(), vec2.end());
  int r=0;
  for(int i=0;i<m-1-(n-1);i++){
    r+=vec2[i];
  }
  cout<< r<< endl;
  return 0;
}

Measured memory_bytes: 1024
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<cstdlib>
#include<climits>
#include<iostream>
#include<sstream>
#include<utility>
#include<map>
#include<vector>
#include<queue>
#include<algorithm>
#include<set>
#include<stack>
#include<functional>
#include<ios>
#include<iomanip>

using namespace std;
typedef long long ll;
typedef pair<int,int>P;
vector<int>B,NB;

int main()
{
	int N,K;
	cin>>N>>K;
	for(int i=0;i<N;i++)
	{
		int t;
		cin>>t;
		B.push_back(t);
	}
	sort(B.begin(),B.end());
	unique(B.begin(),B.end());
	B.erase(std::unique(B.begin(), B.end()), B.end());
	int mp=B[0];
	for(;;)
	{
		NB=B;
		for(int i=1;i<B.size();i++)
		{
			
			NB.push_back(B[i]-B[i-1]);
		}
		B=NB;
		sort(B.begin(),B.end());
		unique(B.begin(),B.end());
		B.erase(std::unique(B.begin(), B.end()), B.end());
		if(mp==B[0])break;
		mp=B[0];
	}
	for(int i=B.size()-1;i>=0;i--)
	{
		if(B[i]<K)break;
		int x=B[i]-K;

		for(int j=i;j>=0;j--)
		{
			if(x>B[j])
			{
				x%=B[j];
			}
		}
		if(x==0)
		{
			cout<<"POSSIBLE"<<endl;
			return 0;
		}
	}
	cout<<"IMPOSSIBLE"<<endl;

}

Measured memory_bytes: 8896