akhauriyash/Code-Regression huggingface dataset:
import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int[] way = new int[6];
        int[] set = new int[4];
        for (int i = 0; i < 6; i++) {
            way[i] = sc.nextInt();
            set[way[i] - 1]++;
        }
        boolean ans = true;
        int flag = 0;
        sc.close();
        for (int i = 0; i < 4; i++) {
            if (set[i] == 0) {
                ans = false;
            }
            if (set[i] == 1) {
                flag++;
            }
            if (flag > 2) {
                ans = false;
            }
        }
        System.out.println(ans ? "YES" : "NO");
    }
}


Measured memory_bytes: 21844
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < n; i++)
#define rep2(i, x, n) for(int i = x; i <= n; i++)
#define rep3(i, x, n) for(int i = x; i >= n; i--)
#define elif else if
#define sp(x) fixed << setprecision(x)
#define pb push_back
#define eb emplace_back
#define all(x) x.begin(), x.end()
#define sz(x) (int)x.size()
using ll = long long;
using ld = long double;
using pii = pair<int, int>;
using pil = pair<int, ll>;
using pli = pair<ll, int>;
using pll = pair<ll, ll>;
const ll MOD = 1e9+7;
//const ll MOD = 998244353;
const int inf = (1<<30)-1;
const ll INF = (1LL<<60)-1;
const ld EPS = 1e-10;
template<typename T> bool chmax(T &x, const T &y) {return (x < y)? (x = y, true) : false;};
template<typename T> bool chmin(T &x, const T &y) {return (x > y)? (x = y, true) : false;};

int main(){
    int N; ll K;
    cin >> N >> K;
    int p[60][N];
    rep(i, N) {cin >> p[0][i]; p[0][i]--;}
    rep2(i, 1, 59){
        rep(j, N){
            p[i][j] = p[i-1][p[i-1][j]];
        }
    }
    int now = 0;
    rep(j, 60){
        if(K & (1LL << j)) now = p[j][now];
    }
    cout << now+1 << endl;
}

Measured memory_bytes: 50508
#include<bits/stdc++.h>
const int N=101000;
using namespace std;
long long D[N];
int w[N],n,k;
int main(){
	cin>>n>>k;
	for (int i=1;i<=n;i++) {
		cin>>w[i];
	}
	for(int i=2;i<=n;i++){
		D[i]=1e18;
		for(int j=i-1;j>=i-k&&j>=1;j--) {
			D[i]=min(D[i],D[j]+abs(w[j]-w[i]));
		}
	}
	cout<<D[n];
}


Measured memory_bytes: 1408
#include <bits/stdc++.h>
using namespace std;
int main()
{
    int n,x,count=0;
    cin>>n>>x;
    string s;
    cin>>s;
    for(int i=1; i<n-2; i++)
    {
        if(s[i]=='R' && s[i+1]=='L')
        {
            count++;
        }
    }
    int up=count*2;
    int side =2*(s[0]=='R' && s[1]=='L') + 2*(s[n-2]=='R' && s[n-1]=='L');
    int sin=(s[0]=='L')+(s[n-1]=='R');
    up+=(side+sin);

    if(x>=up)cout<<n-1<<endl;
    else
    {
        if(x<=count)cout<<n-(up-x*2)<<endl;
        else
        {
            int ans=n-(up-count*2-side*2-sin);
            if(ans>=n)ans=n-1;
            cout<<ans<<endl;
        }
    }
    return 0;
}


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

int main(){

  string S;
  cin >> S;
  
  int sol = 0;
  int count = 0;
  
  for (int i=0; i<S.size(); i++){
  
    if (S.at(i) == 'A' || S.at(i) == 'G' || S.at(i) == 'C' || S.at(i) == 'T')
      count++;
    else{
      sol = max(sol,count);
      count = 0;
    }

  }

  sol = max(sol,count);
  cout << sol << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define rep(i,x,y) for(int i=x;i<y;i++)
#define range(a) (a).begin(),(a).end()
#define print(A,x,n) rep(i,0,n){cout<<(i ? " ":"")<<A[i]x;}cout<<endl;
#define pprint(A,y,m,n) rep(j,0,m){print(A[j],y,n);}
const long mod=1e9+7;
const int siz=1e5;
const long inf=1e18;
int main(){
	long N; cin>>N;
	long M = N;
	int ans = 0;
	for(long i = 2; i * i <= N; i++){
		int cnt = 0;
		while(M % i == 0){
			M /= i;
			cnt++;
		}
		int j = 0;
		while(j * (j + 1) / 2 <= cnt) j++;
		ans += j - 1;
	}cout<<ans + (M > 1)<<endl;
}

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

int main() {
  int N, Alice = 0, Bob = 0;
  cin >> N;

  vector<int> card(N);
  for (int i = 0; i < N; i++) {
    cin >> card.at(i);
  }
  sort(card.begin(), card.end());
  reverse(card.begin(), card.end());
  
  for (int i = 0; i < N; i++) {
    if (i % 2 == 0) {
      Alice += card.at(i);
    }
    else {
      Bob += card.at(i);
    }
  }
  

  cout << Alice - Bob << endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<iomanip>
#include<string>
#include<algorithm>
#include<functional>
#include<vector>
#include<math.h>
#define L(_i,_N) for(int _i=0;_i<_N;_i++)
#define C(_Dis) cout<<_Dis<<endl;
typedef long long int lli;
using namespace std;

int main() {
	double a, b, c, d, e, f;
	double x,y;
	while (cin >> a >> b >> c >> d >> e >> f) {
		y = (double)((a*f - c*d) / (a*e - b*d));
		x = (double)((c*e - b*f) / (a*e - b*d));
		if (x == 0) x = 0;
		if (y == 0) y = 0;
		cout << fixed << setprecision(3) << x << " " << y << endl;
	}
	return 0;
}

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

using Vertex = int;
using Weight = long long;
struct Edge{Vertex from, to; Weight weight;};
using Graph = vector<vector<Edge>>;

vector<Vertex> centroid(const Graph& G) {
  vector<Vertex> V;
  vector<int> size(G.size(), 1);
  function<int(Vertex, Vertex)> dfs = [&](Vertex cur, Vertex pre) {
    auto ok = true;
    for(auto e: G[cur]) if(e.to != pre) {
      size[cur] += dfs(e.to, e.from);
      if(G.size() / 2 < size[e.to]) ok = false;
    }
    if(G.size() / 2 < G.size() - size[cur]) ok = false;
    if(ok) V.emplace_back(cur);
    return size[cur];
  };
  dfs(0, 0);
  return V;
}

Weight cost(const auto& G, auto c, auto p) {
  Weight res = 0;
  vector<int> size(G.size(), 1);
  function<int(Vertex, Vertex)> dfs = [&](Vertex cur, Vertex pre) {
    for(auto e: G[cur]) if(e.to != pre) {
      size[cur] += dfs(e.to, e.from);
      res += 2 * size[e.to] * e.weight;
    }
    return size[cur];
  };
  dfs(c, p);
  return res;
}

Weight solve(const auto& G, auto root) {
  Weight w = 1e9;
  for(auto e: G[root]) w = min(w, e.weight);
  return cost(G, root, root) - w;
}

Weight solve(const auto& G, auto u, auto v) {
  for(auto e: G[u]) if(e.to == v) return cost(G, u, v) + cost(G, v, u) + e.weight * (G.size() - 1);
}

int main() {
  int N;
  cin >> N;

  Graph G(N);
  for(auto i = 1; i < N; ++i) {
    Vertex A, B; Weight C;
    cin >> A >> B >> C;
    --A; --B;
    G[A].push_back({A, B, C});
    G[B].push_back({B, A, C});
  }

  auto V = centroid(G);
  if(V.size() == 1) cout << solve(G, V.front()) << endl;
  else              cout << solve(G, V.front(), V.back()) << endl;
}


Measured memory_bytes: 14968
#include<stdio.h>
int main(void)
{
	int n,k;
	int a,b;
	int i,j;
	int c[5],min;
	
	scanf("%d",&n);
	scanf("%d",&k);
	for(i=0;i<k;i++){
		scanf("%d %d",&a,&b);
		c[1]=n-a;
		c[2]=n-(c[1]+1);
		c[3]=n-b;
		c[4]=n-(c[3]+1);
		min=c[1];
		for(j=2;j<=4;j++){
			if(min>c[j]){
				min=c[j];
			}
		}
		min=min%3;
		if(min==1){
			printf("2\n");
		}
		else if(min==2){
			printf("3\n");
		}
		else {
			printf("1\n");
		}
	}
	return 0;
}

Measured memory_bytes: 1008
// 失敗するからこそ そこから立ち向かって行く強さがあってそんな強さが本当の強さだと私は思うから
// ぜったいあきらめない
#include<bits/stdc++.h>
using namespace std;

#if defined(DAIJOBU)
#include "/home/ichigo/debug.hpp"
#define deb(x...) cerr << "[" << #x << "] = ["; _print(x)
#else
#define deb(x...)
#endif
#define FIO {ios::sync_with_stdio(0);cin.tie(nullptr);cout.tie(nullptr);}

map<char, int> cnt;

int main(){
	FIO
	
	string s, res;
	while(getline(cin, s))res += s;
	for(auto i:res)cnt[tolower(i)]++;
	for(char i = 'a'; i <= 'z'; i++){
		cout << i << " : " << cnt[i] << '\n';
	}
	return 0;
}



Measured memory_bytes: 3224
#include <cstdio>
#include <algorithm>
#include <string>
#include <cstring>
#include <map>
#define N 105
#define fi(a, b, c) for(int a = (b); a < (c); a++)
#define FI(a, b, c) for(int a = (b); a <= (c); a++)
using namespace std;

int n;
map<int, int> cnt;

int main(){
	scanf("%d", &n);
	fi(i, 0, n){
		int x;
		scanf("%d", &x);
		cnt[x]++;
	}

	scanf("%d", &n);
	fi(i, 0, n){
		int x;
		scanf("%d", &x);
		if(!cnt[x]){
			puts("NO");
			return 0;
		}
		cnt[x]--;
	}
	
	puts("YES");
}

Measured memory_bytes: 9600
#include <iostream>

int main(){
    int a, b;
    std::cin >> a >> b;

    if(1 == a){
        a = 14;
    }

    if(1 == b){
        b = 14;
    }

    if(a > b){
        std::cout << "Alice" << std::endl;
    }else if(b > a){
        std::cout << "Bob" << std::endl;
    }else{
        std::cout << "Draw" << std::endl;
    }

    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define fi first
#define se second
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
#define srep(i,s,t) for (int i = s; i < t; ++i)
#define rng(a) a.begin(),a.end()
#define rrng(a) a.rbegin(),a.rend()
#define maxs(x,y) (x = max(x,y))
#define mins(x,y) (x = min(x,y))
#define limit(x,l,r) max(l,min(x,r))
#define lims(x,l,r) (x = max(l,min(x,r)))
#define isin(x,l,r) ((l) <= (x) && (x) < (r))
#define pb push_back
#define eb emplace_back
#define sz(x) (int)(x).size()
#define pcnt __builtin_popcountll
#define uni(x) x.erase(unique(rng(x)),x.end())
#define show(x) cout<<#x<<" = "<<x<<endl;
#define print(x)cout<<x<<endl;
#define PQ(T) priority_queue<T,v(T),greater<T> >
#define bn(x) ((1<<x)-1)
#define dup(x,y) (((x)+(y)-1)/(y))
#define newline puts("")
#define v(T) vector<T>
#define vv(T) v(v(T))
using namespace std;
typedef long long int ll;
typedef unsigned uint;
typedef unsigned long long ull;
typedef pair<int,int> P;
typedef tuple<int,int,int> T;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<P> vp;
typedef vector<T> vt;

int f(int x){
	if(x == 0)return 0;
	int pc = __builtin_popcount(x);
	return f(x%pc)+1;
}
int main() {
	int n;
	string s;
	cin >> n;
	cin >> s;
	int num = 0;
	vi x(n);
	rep(i,n){
		num+= (s[i] == '1');
		x[i] =(s[i] == '1');
	}
	vi ans(n,0);

	rep(b,2){
		int npc = num;
		if(b) npc--;
		else npc++;
		if(npc<=0)continue;
		int r0 = 0;
		rep(i,n){
			r0 = (r0*2)%npc;
			r0+=x[i];
		}
		int k = 1;
		for(int i = n-1;i>=0;i--){
			int r = r0;
			if(x[i] == b){
			if(b) r = (r-k+npc)%npc;
			else r = (r+k+npc)%npc;
			ans[i] = f(r)+1;
			}
			k = (k*2)%npc;
		}
	}
	for(auto x : ans)cout<<x<<endl;
	return 0;
}

Measured memory_bytes: 5152
import java.util.Scanner;

public class Main {
	public static void main(String[] args) throws Exception {
		Scanner sc = new Scanner(System.in);
		char[] s = sc.next().toCharArray();
		sc.close();

		int ans = 0;
		for (int i = 1; i < s.length; i++) {
			if (s[i - 1] != s[i]) {
				ans++;
			}
		}
		System.out.println(ans);
	}
}


Measured memory_bytes: 27220
#include<iostream>
#include<vector>
#include<algorithm>
#include<cstring>
#include<cstdio>
#include<cmath>
#include<cstdlib>
#include<ctime>
#include<queue>
#include<set>
#include<map>
#include<stack>
#include<bitset>
using namespace std;
typedef long long LL;
const int N=2e5+100;
//这题太神!
int gi() {
	int w=0;bool q=1;char c=getchar();
	while ((c<'0'||c>'9') && c!='-') c=getchar();
	if (c=='-') q=0,c=getchar();
	while (c>='0'&&c <= '9') w=w*10+c-'0',c=getchar();
	return q? w:-w;
}
int L[N],R[N],x[N];
int e[N<<2];
LL f[N],g[N];
#define lc (i<<1)
#define rc (lc|1)
inline void build(int i,int l,int r,int t) {
	e[i]=t;
	if (l!=r) {
		int mid=(l+r)>>1;
		build(lc,l,mid,t);
		build(rc,mid+1,r,t);
	}
}
inline void modify(int i,int l,int r,int L,int R,int k) {
	if (L<=l&&r<=R) e[i]=k;
	else {
		int mid=(l+r)>>1;
		if (L<=mid) modify(lc,l,mid,L,R,k);
		if (mid<R) modify(rc,mid+1,r,L,R,k);
	}
}
inline int query(int i,int l,int r,int k) {
	if (l==r) return e[i];
	int mid=(l+r)>>1;
	return min(e[i],k<=mid?query(lc,l,mid,k):query(rc,mid+1,r,k));
}
inline void add(int i,int l,int r,int L,int R) {
	if (L<=l&&r<=R) e[i]++;
	else {
		int mid=(l+r)>>1;
		if (L<=mid) add(lc,l,mid,L,R);
		if (mid<R) add(rc,mid+1,r,L,R);
	}
}
inline int Sum(int i,int l,int r,int k) {
	if (l==r) return e[i];
	int mid=(l+r)>>1;
	return e[i]+(k<=mid?Sum(lc,l,mid,k):Sum(rc,mid+1,r,k));
}
int main()
{
	int n=gi(),m=gi(),i,a,k,tp,sum=0,len=0;
	LL ans=1LL<<60,S=0;
	for (i=1;i<=n;i++) {
		a=gi(),tp=gi();S+=a<<1;
		if (tp==1&&a*2>m) return puts("-1"),0;
		if (tp==2) L[i]=0,R[i]=m-1;
		else L[i]=sum,R[i]=(sum-a*2%m+m)%m;
		sum=(sum-a*2%m+m)%m;
		x[++len]=L[i];
		x[++len]=R[i];
	}
	sort(x+1,x+1+len);
	len=unique(x+1,x+1+len)-x-1;
	build(1,1,len,n+1);
	for (i=n;i;i--) {
		L[i]=lower_bound(x+1,x+1+len,L[i])-x;
		R[i]=lower_bound(x+1,x+1+len,R[i])-x;

		k=query(1,1,len,L[i]);
		if (k!=n+1) f[i]=f[k]+(x[L[k]]-x[L[i]]+m)%m;
		k=query(1,1,len,R[i]);
		if (k!=n+1) g[i]=f[k]+(x[L[k]]-x[R[i]]+m)%m;

		if (L[i]<=R[i]) {
			if (R[i]<len) modify(1,1,len,R[i]+1,len,i);
			if (L[i]>1) modify(1,1,len,1,L[i]-1,i);
		} else if (R[i]+1<L[i]) modify(1,1,len,R[i]+1,L[i]-1,i);
	}
	build(1,1,len,0);
	for (i=1;i<=n;i++) {
		//if (Sum(1,1,len,L[i])==i-1)
		//	ans=min(ans,f[i]);
		if (Sum(1,1,len,R[i])==i-1)
			ans=min(ans,g[i]);
		if (L[i]<=R[i]) add(1,1,len,L[i],R[i]);
		else add(1,1,len,L[i],len),add(1,1,len,1,R[i]);
	}
	cout<<ans+S<<endl;
	return 0;
}


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

int main(){
  int N;
  cin >> N;

  vector<int> order(N);
  vector<int> point(N);
  vector<int> bonus(N - 1);

  for (int i = 0; i < N; i++) cin >> order.at(i);
  for (int i = 0; i < N; i++) cin >> point.at(i);
  for (int i = 0; i < N - 1; i++) cin >> bonus.at(i);

  int sum = 0;
  int before = -999;

  for (int i = 0; i < N; i++){
    sum += point.at(order.at(i) - 1);

    if (before == order.at(i) - 1) sum += bonus.at(order.at(i) - 2);

    before = order.at(i);
  }

  cout << sum << endl;
}

Measured memory_bytes: 3572
x=range(int(input()))
P=[]
for _ in x:P+=[[int(i) for i in input().split()]]
_=0
P+=[P[0]]
for j in x:
    k = j+1
    _+=P[j][0]*P[k][1]-P[j][1]*P[k][0]
print(_*0.5)

Measured memory_bytes: 7716
S = input()

bool_list = []
if S[0] == 'A':
    bool_list.append(True)
    if S[2: -1].count('C') == 1:
        bool_list.append(True)
        C_index = S.index('C')
        if 'a' + S[1:C_index] + 'c' + S[C_index + 1:] == S.lower():
            bool_list.append(True)
        else:
            bool_list.append(False)
    else:
        bool_list.append(False)
else:
    bool_list.append(False)

if all(bool_list) is True:
    print('AC')
else:
    print('WA')


Measured memory_bytes: 3060
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.PriorityQueue;
import java.util.Scanner;

public class Main {
	static String[] w = { "SUN", "MON", "TUE", "WED", "THU", "FRI", "SAT" };

	public static void main(String[] args) {
		Scanner in = new Scanner(new BufferedReader(new InputStreamReader(System.in)));
		String s = in.next();
		int i = 0;
		for (; i < w.length; i++)
			if (s.equals(w[i]))
				break;
		System.out.println(7 - i);
	}
}

Measured memory_bytes: 21716
#include<stdio.h>
int main(void){
  int n,i,x;

  scanf("%d",&n);

	for(i = 1;i <= n;i++){ 
		if(i % 3 == 0){
		printf(" %d",i);
		}else{
			for(x = i;x;x /= 10){
			if(x % 10 == 3){
				printf(" %d",i);break;
				}
			}
		}
  }
  printf("\n");
  return 0;
}

Measured memory_bytes: 600
#include<bits/stdc++.h>
using namespace std;
int find(int x);
int same(int x,int y);
void unite(int x,int y);
priority_queue<int,vector<int>,greater<int> >pq[100009];
priority_queue<int,vector<int>,greater<int> >all;
int p[100009];

int main(){
  int n,m;
  int a[100009];
  cin>>n>>m;
  for(int i=0;i<n;i++){
    cin>>a[i];
    p[i]=i;
  }
  for(int i=0;i<m;i++){
    int x,y;
    cin>>x>>y;
    unite(x,y);
  }
  for(int i=0;i<n;i++){
    p[i]=find(p[i]);
    pq[p[i]].push(a[i]);
  }
  int cnt=0;
  long long ans=0;
  for(int i=0;i<n;i++){
    if(!pq[i].empty()){
      int now=pq[i].top();pq[i].pop();
      ans+=now;
      while(!pq[i].empty()){
        int t=pq[i].top();pq[i].pop();
        all.push(t);
      }
      cnt++;
    }
  }
  if(cnt==1){
    cout<<0<<endl;
    return(0);
  }
  for(int i=0;i<cnt-2;i++){
    if(all.empty()){
      cout<<"Impossible"<<endl;
      return(0);
    }
    int now=all.top();all.pop();
    ans+=now;
  }
  cout<<ans<<endl;
  return(0);
}

int find(int x){
  if(p[x]==x)return x;
  return p[x]=find(p[x]);
}

int same(int x,int y){
  if(find(x)==find(y))return 1;
  return 0;
}

void unite(int x,int y){
  x=find(x);
  y=find(y);
  p[x]=y;
}


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

using namespace std;

#define REP(i, N) for (int i = 0; i < (int)N; i++)
#define RREP(i, N) for (int i =(int)N-1; i >= 0; i--)
#define FOR(i, a, b) for (int i = a; i < (int)b; i++)
#define ALL(x) (x).begin(), (x).end()
#define INF (1 << 30)
#define LLINF (1LL << 62)
#define DEBUG(...) debug(__LINE__, ":" __VA_ARGS__)

typedef long long ll;
typedef pair<int, int> Pii;
typedef pair<ll, ll> Pll;
typedef pair<string,int>Psi;

int main(){
  ll r,d,x;
  cin>>r>>d>>x;
  REP(i,10){
    x=x*r-d;
    cout<<x<<endl;
  }

}


Measured memory_bytes: 256
#!/usr/bin/env python
# coding: utf-8

import itertools

def ri():
    return int(input())

def rl():
    return list(input().split())

def rli():
    return list(map(int, input().split()))

def main():
    n = ri()
    lp = rli()
    lq = rli()
    seq = list(range(1, n+1))
    ll = list(itertools.permutations(seq))
    a = None
    for i, l in enumerate(ll):
        if list(l) == lp:
            a = i
        if list(l) == lq:
            b = i
    print(abs(a-b))


if __name__ == '__main__':
    main()


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

int main()
{
    int t, h, s;

    int sum1 = 0, sum2 = 0;

    while( cin >> t >> h >> s )
    {
        if( t == -1 && h == -1 && s == -1 )
            break;
        
        sum1 = 120 * 60 - t * 3600 - h * 60 - s;
        sum2 = sum1 * 3;

        t = sum1 / 3600;
        h = ( sum1 % 3600 ) / 60;
        s = ( sum1 % 3600 ) % 60;

        if( t < 10 )
            cout << 0 << t << ":";
        else
            cout << t << ":";
        if( h < 10 )
            cout << 0 << h << ":";
        else
            cout << h << ":";
        if( s < 10 )
            cout << 0 << s << endl;
        else
            cout << s << endl;

        t = sum2 / 3600;
        h = ( sum2 % 3600 ) / 60;
        s = ( sum2 % 3600 ) % 60;

        if( t < 10 )
            cout << 0 << t << ":";
        else
            cout << t << ":";
        if( h < 10 )
            cout << 0 << h << ":";
        else
            cout << h << ":";
        if( s < 10 )
            cout << 0 << s << endl;
        else
            cout << s << endl;
    }
    return 0;
}


Measured memory_bytes: 3084
/*Bismllahir Rahmanir Rahim*/
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int a,i,j,k;
    cin>>a>>i;
    if(a==1 && i==3)
        cout<<"2"<<endl;
    else if(a==1 && i==2)
        cout<<"3"<<endl;
    else if(a==2 && i==1)
        cout<<"3"<<endl;
    else if(a==2 && i==3)
        cout<<"1"<<endl;
    else if(a==2 && i==3)
        cout<<"1"<<endl;
    else if(a==3 && i==1)
        cout<<"2"<<endl;
    else if(a==3 && i==2)
        cout<<"1"<<endl;

    return 0;
}


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

#define INF 1e18
#define int long long
const int MOD = 1000000007;

signed main() {
    int n; cin >> n;
    string s; cin >> s;
    vector<int> cnt(26, 1);

    for(int i = 0; i < n; i++) {
        cnt[s[i] - 'a']++;
    }

    int ans = 1;
    for(int i = 0; i < 26; i++) {
        ans = (ans * cnt[i]) % MOD;
    }

    cout << (ans - 1) % MOD << endl;
    return 0;
}


Measured memory_bytes: 512
function Main(s){
  s = s.split("\n");
  var n = +s[0];
  var a = s[1].split(" ").map(a=>+a);
  var ans = 0;
  var x = a[0]
  var t = 1;
  for(var i = 1; i < n; i++){
    if(x !== a[i]){
      ans += t >> 1;
      x = a[i]; t = 1;
      }
    else t++;
  }
  ans += t >> 1;
  console.log(ans);
}
Main(require("fs").readFileSync("/dev/stdin","utf8"));

Measured memory_bytes: 21064
#include<stdio.h>

int main()
{
	double a,b[10],sum=0.0;
	int i;

	while(scanf("%lf",&a)!=EOF)
	{
		sum=a;
		b[0]=a;
		for(i=1;i<10;i++)
		{
			if(!(i%2))
				b[i]=b[i-1]/3.0;
			else
				b[i]=b[i-1]*2.0;
			sum+=b[i];
		}
		printf("%.7f\n",sum);
	}
	return 0;
}

Measured memory_bytes: 652
#include<bits/stdc++.h>
using namespace std;
 
#define pb push_back
#define ll long long
#define maxn 1000005
#define fr(i,j,k) for(int i=j;i<k;i++)
#define f(n) fr(i,0,n)
#define f1(n) fr(i,1,n+1)
#define ms(i) memset(i,0,sizeof(i));
#define ms1(i) memset(i,-1,sizeof(i));
#define F first
#define S second
#define all(x) x.begin(), x.end()
const int mod = 998244353;

int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    int n, m, k;
    cin >> n >> m >> k;
    int pre[n + 5] = {};
    int suf[n + 5] = {};
    int pf[n + 5] = {};
    string s;
    cin >> s;
    s = " " + s;
    pf[0] = -1e9;
    f1(n) {
        pre[i] = pre[i-1];
        pf[i] = pf[i-1];
        if (s[i] == 'o') {
            if (pre[i] == 0) {
                pf[i] = i;
            }
            pre[i] = max(pre[i], 1);
        }
        if (s[i] == 'o' && i > k) {
            if (pre[i - k - 1 + 1] > pre[i]) {
                pf[i] = i;
            }
            pre[i] = max(pre[i], pre[i - k - 1] + 1);
        }
    }
    for (int i = n ; i >= 1 ; i--) {
        suf[i] = suf[i + 1];
        if(s[i] == 'o') {
            suf[i] = max(suf[i], 1);
        }
        if (s[i] == 'o') {
            suf[i] = max(suf[i], suf[i + k + 1] + 1);
        }
    }
    f1(n) {
        if (s[i] == 'x') {
            continue;
        }
        int pos = pf[i - 1];
        int nd = m - pre[i-1];
        int npos = max(pos + k + 1, i + 1);
        //cout << npos << endl;
        //cout << pre[i - 1] << ' '<<suf[npos]<<endl;
        if (suf[npos] < nd) {
            cout << i << '\n';
        }
    }
    
}


Measured memory_bytes: 4176
//   __________________
//  | ________________ |
//  ||          ____  ||
//  ||   /\    |      ||
//  ||  /__\   |      ||
//  || /    \  |____  ||
//  ||________________||
//  |__________________|
//  \###################\
//   \###################\
//    \        ____       \
//     \_______\___\_______\
// An AC a day keeps the doctor away.

#pragma GCC optimize("Ofast")
#pragma loop_opt(on)
#include <bits/extc++.h>
#ifdef local
#define safe std::cerr<<__PRETTY_FUNCTION__<<" line "<<__LINE__<<" safe\n"
#define debug(...) qqbx(#__VA_ARGS__,  __VA_ARGS__)
template <typename H, typename ...T> constexpr void qqbx(const char *s, const H &h, T &&...args) {
    for(; *s && *s != ','; ++s) if(*s != ' ') std::cerr << *s;
    std::cerr << " = " << h << (sizeof...(T) ? ", " : "\n");
    if constexpr(sizeof...(T)) qqbx(++s, args...); // C++ 17!
}
#else
#include <bits/stdc++.h>
#define debug(...) ((void)0)
#define safe ((void)0)
#endif // local
#define all(v) begin(v),end(v)
#define get_pos(v,x) (lower_bound(begin(v),end(v),x)-begin(v))
#define sort_uni(v) sort(begin(v),end(v)),v.erase(unique(begin(v),end(v)),end(v))
#define pb emplace_back
#define ff first
#define ss second
#define mem(v,x) memset(v,x,sizeof v)

using namespace std;
using namespace __gnu_pbds;
typedef int64_t ll;
typedef long double ld;
typedef pair<ll,ll> pll;
typedef pair<ld,ld> pld;
template <typename T> using max_heap = std::priority_queue<T,vector<T>,less<T> >;
template <typename T> using min_heap = std::priority_queue<T,vector<T>,greater<T> >;
template <typename T> using rbt = tree<T,null_type,less<T>,rb_tree_tag,tree_order_statistics_node_update>;
constexpr ld PI = acos(-1), eps = 1e-7;
constexpr ll N = 200025, INF = 1e18, MOD = 1000000007, K = 357, inf = 1e9;
constexpr inline ll cdiv(ll x, ll m) { return x/m + ((x<0 ^ m>0) && (x%m)); } // ceiling divide
constexpr inline ll modpow(ll e,ll p,ll m=MOD) { ll r=1; for(e%=m;p;p>>=1,e=e*e%m) if(p&1) r=r*e%m; return r; }

signed main() {
    ios_base::sync_with_stdio(0), cin.tie(0);
    int n;
    cin >> n;
    vector<int> v(n+2);
    for(int i = 1; i <= n; i++) cin >> v[i];
    int ans = 0;
    for(int i = 1; i <= n+1; i++) ans += abs(v[i]-v[i-1]);
    for(int i = 1; i <= n; i++) cout << ans - abs(v[i]-v[i-1])-abs(v[i]-v[i+1])+abs(v[i-1]-v[i+1]) << '\n';
}



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


int main (){
  int a, b;
  string s;
  cin >> a >> b;;
  if (a <  b) s = '<';
  if (a >  b) s = '>';
  if (a == b) s = "==";
  cout << 'a' << ' ' << s << ' ' << 'b' << '\n';
}

Measured memory_bytes: 3148
import Data.List (sort)

solve :: [Int] -> Int
solve (_:p)  = 
    v2 - v1
    where 
        l = length p
        (p1,p2) = splitAt (div l 2) $ sort p
        v1 = maximum p1
        v2 = minimum p2
    
main = interact $ show.solve.map read.words


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

using namespace std;

string s, t;
int a[105], b[105];

int main()
{
    cin >> s >> t;
    int S = s.size();
    int T = t.size();
    for (int i = 0; i < S; i++)
        a[i+1] = s[i] - 'a';
    for (int i = 0; i < T; i++)
        b[i+1] = t[i] - 'a';
    sort (a+1, a+S+1);
    sort (b+1, b+T+1);
    for (int i = 1; i <= T/2; i++)
        swap(b[i], b[T+1-i]);
    for (int i = 1; i <= min(S,T); i++)
    {
        if (a[i]<b[i])
        {
            cout << "Yes";
            return 0;
        }
        if (a[i]>b[i])
        {
            cout << "No";
            return 0;
        }
    }
    if (S<T) cout << "Yes";
    else cout << "No";
}


Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<queue>
using namespace std;
const int N=200005;
int n;
int a[N],b[N];
priority_queue<pair<int,int>,vector<pair<int,int> > >q;
int main()
{
	scanf("%d",&n);
	for(int i=1;i<=n;i++)
		scanf("%d",&a[i]);
	for(int i=1;i<=n;i++)
		scanf("%d",&b[i]);
	for(int i=1;i<=n;i++)
		q.push(make_pair(b[i],i));
	a[0]=a[n],b[0]=b[n];
	a[n+1]=a[1],b[n+1]=b[1];
	long long ans=0;
	while(!q.empty())
	{
		int u=q.top().second;
		q.pop();
		if(a[u]==b[u]) continue;
		int x=b[u-1]+b[u+1];
		if(a[u]>b[u])
		{
			printf("-1");
			return 0;
		}
		if(b[u]-a[u]<x)
		{
			printf("-1");
			return 0;
		}
		int t=(b[u]-a[u])/x;
		ans+=t;
		b[u]-=t*x;
		if(u==1) b[n+1]=b[1];
		if(u==n) b[0]=b[n];
		if(a[u]!=b[u]) q.push(make_pair(b[u],u));
	}
	printf("%lld",ans);
	return 0;
}

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

#define IOS ios_base::sync_with_stdio(false);cin.tie(nullptr);cout.tie(nullptr);
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define I insert
#define endl '\n'
#define all(x) x.begin(), x.end()

#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
template<class T> using oset=tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
 
using vvll = vector< vector<ll> >;
using vll = vector<ll> ;
using vb = vector<bool> ;
using pll = pair<ll, ll> ;

const ll maxs = 1e6+5;
const ll lmaxs = 20;
ll mod = 1e9+7;
ll oo = 1e15;

ll fast(ll x,ll y){
    ll res=1;
    while(y){
        if(y&1)
            res = (res*x)%mod;
        x = (x*x)%mod;
        y >>= 1;
    }
    return res;
}

ll inv(ll n){
    return fast(n,mod-2);
}


void pre(){



}


void solve(){

    ll n;
    cin >> n;
    map<ll,ll> mp;
    ll ans=0;
    for(ll i=1;i<=n;i++){
        ll val;
        cin >> val; 
        mp[val]=i;
        if(mp.lower_bound(val) == mp.begin()){
            ans++;
        }
    }
    cout << ans;

}

int main(){
    // #ifndef ONLINE_JUDGE
    // freopen("input00.txt","r",stdin);
    // #endif
    IOS;
    pre();
    ll T = 1;
    //cin>>T;
    while(T--){
        solve();   
    }
    return 0;
}

Measured memory_bytes: 16028
#include<iostream>
#include<string>
#include<cmath>
#include<algorithm>
#define value( x ) cout<< "value of "<< #x << " is "<< x<<endl;
long long max( long long x, long long y) {if(x>y) return x;else return y;}
using namespace std;
int main()
{
    string a[200];
    int n, l;
    cin>>n>>l;
    for(int i=0;i<n;i++) cin>>a[i];
    sort(a, a+n);
	for(int i=0;i<n;i++) cout<<a[i];
   

return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
 
using namespace std;
 
typedef long long ll;
typedef vector<ll> vi;
typedef pair<ll,ll> ii;

#define M 1000000 
#define pb push_back
#define ppb pop_back
#define mp make_pair
#define all(x) x.begin(),x.end()
#define sz(x) (ll)x.size()
#define fill(a,x) memset(a,x,sizeof(a))
#define F first
#define S second
#define FOR(i,a,b) for(ll i = a; i<=b; ++i)
#define NFOR(i,a,b) for(ll i = a; i>=b; --i)
#define fast ios_base::sync_with_stdio(false),cin.tie(0),cout.tie(0)
const ll INF = 1e18;
const ll mod = 1e9+7;
const ll N = 1e5 + 10;
inline ll add(ll x,ll y){
  x += y;
  if(x >= mod) x -= mod;
  return x;
}
inline ll mul(ll x,ll y){
  x = (1LL * x * y) % mod;
  return x;
}


int main()
{
	fast;

	int n;cin>>n;
	vector<string>v;
	char prev = '-';
	set<string>st;
	FOR(i,1,n){
		string s;cin>>s;
		if(st.find(s)!=st.end()){
			cout << "No";return 0;
		}
		else st.insert(s);
		if(prev!='-' && s[0]!=prev){
			cout << "No";return 0;
		}
		else prev = s[s.length()-1];
	}
	cout << "Yes";

	return 0;
}

Measured memory_bytes: 256
import sys
import numpy as np
#import math
#import itertools
#import re
#from functools import lru_cache

read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline

def main():
    a, b, h, m = list(map(int, input().split()))
    rad = abs(6*m-(h*60+m)/2)
    print(np.sqrt(a**2+b**2-2*a*b*np.cos(rad/180*np.pi)))


if __name__ == '__main__':
    main()


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

int main(){
    int n; ll k; cin>>n>>k;
    map<int, ll> list;
    for(int i=0; i<n; i++){
        int a; ll b; cin>>a>>b;
        if(list.count(a)) list[a]+=b;
        else list[a]=b;
    }
    ll num = 0;
    auto begin = list.begin(), end = list.end();
    int l;
    for(auto iter = begin; iter!=end; iter++){
        num += iter->second;
        l = iter->first;
        if (num >=k)break;
    }
    cout << l << endl;
}

Measured memory_bytes: 7476
#include <bits/stdc++.h>
#include <boost/multiprecision/cpp_int.hpp>

#define int long long

#define override_rep(i, l, r, mes, ...) mes
#define rep1(i, n) for (int i = 0; i < n; i++)
#define rep2(i, l, r) for (int i = l; i < r; i++)
#define rep(...) override_rep(__VA_ARGS__, rep2, rep1)(__VA_ARGS__)

using namespace std;

using P = std::pair<int, int>;
using ll = long long;
using ld = double;

using bint = boost::multiprecision::cpp_int;


template<typename T, typename U>
std::istream& operator>>(std::istream& in, std::pair<T, U>& p) {
    in >> p.first >> p.second;
    return in;
}

const int MOD = 1e9 + 7;

// https://twitter.com/vane11ope ←フォローしましょう
// (ノ)>◡<(ヾ)ﾓﾁﾓﾁ
signed main(signed argc, char* argv[]) {
    std::cin.tie(nullptr);
    std::ios::sync_with_stdio(false);

    int n;
    cin>>n;
    int cnt=0;
    rep(i,n){
        int a,b;
        cin>>a>>b;
        if(a==b){
            cnt++;
        }
        else{
            cnt=0;
        }
        if(cnt>=3){
            cout<<"Yes"<<endl;
            return 0;
        }
    }
    cout<<"No"<<endl;

}


Measured memory_bytes: 3660
#include<algorithm>
#include<bitset>
#include<climits>
#include<cmath>
#include<cstdlib>
#include<functional>
#include<iomanip>
#include<iostream>
#include<map>
#include<numeric>
#include<queue>
#include<set>
#include<stack>
#include<string>
#include<time.h>
#include<tuple>
#include<utility>
#include<vector>

using namespace std;

int main() {

	long N; cin >> N;
	long res = INT_MAX;
	vector<long> A(N); for (int i = 0; i < N; i++) cin >> A[i];
	vector<long> accA(N); accA[0] = A[0];
	for (int i = 1; i < N; i++) accA[i] = accA[i - 1] + A[i];

	for (int i = 0; i < N - 1; i++) {
		// i と i + 1の切れ目で分ける場合
		res = min(res, abs(accA[i] - (accA[N - 1] - accA[i])));

	}

	cout << res << endl;
}

Measured memory_bytes: 3328
#include <iostream>
#include <algorithm>

using namespace std;

int main()
{
  int data[100] = {};
  int n, m = 0;
  while(cin >> n)
    data[n - 1]++;
  for(int i = 1; i <= 100; i++)
    m = max(m, data[i - 1]);
  for(int i = 1; i <= 100; i++)
    if(m == data[i - 1])
      cout << i << endl;
  
  return 0;
}

Measured memory_bytes: 1160
from collections import defaultdict
class BIT():
    def __init__(self,size):
        self.size=size
        self.node=[0]*(size+1)

    def sum(self,idx):
        ret=0
        while idx>0:
            ret+=self.node[idx]
            idx-=idx&(-idx)
        return ret

    def add(self,idx,x):
        while idx<=self.size:
            self.node[idx]+=x
            idx+=idx&(-idx)

n=int(raw_input())
a=map(int,raw_input().split())
check=[]
d=defaultdict(int)
li=set([])
now=0
for i in xrange(n):
    if now<a[i]:
        now=a[i]
        check.append(i)
    d[a[i]]+=1
    li.add(a[i])
li=sorted(list(li))
b=[0]*(n+5)
i=0
idx=dict()
for key in li:
    b[i]=d[key]
    idx[key]=i
    i+=1
ans=[0]*(n+1)
for i in xrange(len(check)-2,-1,-1):
    cnt=0
    for j in xrange(idx[a[check[i]]]+1,idx[a[check[i+1]]]+1):
        ans[check[i+1]]+=b[j]*(li[j]-a[check[i]])
        cnt+=b[j]
    b[idx[a[check[i]]]]+=cnt
for i in xrange(1,n):
    if a[0]<a[i]:
        a[i]=a[0]
ans[0]=sum(a)
for i in xrange(n):
    print ans[i]


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


int main(void){
    int N;
    scanf("%d", &N);
    long *L = (long*)malloc(100 * sizeof(long));
    L[0] = (long)2;
    L[1] = (long)1;
    int i;
    
    for(i=2; i<=N; i++){
        L[i] = L[i-1] + L[i-2];
    }
    
    printf("%ld\n", L[N]);
    return 0;
}

Measured memory_bytes: 128
/*
    AUTHOR:shivam51
    IIESTS
*/
  #include<bits/stdc++.h>
  using namespace std;
  //
  #define add accumulate
  #define ll long long int
  #define ff first
  #define ss second
  #define pb push_back
  #define mp make_pair
  #define vll vector<ll>
  #define lb lower_bound
  #define ub upper_bound
  #define pll pair<ll,ll>
  #define vpll vector<pll>
  #define all(v) v.begin(), v.end()
  #define rep(i,k,n) for(int i=k;i<n;i++)
  #define hs ios_base::sync_with_stdio(false);cin.tie(NULL);
  const int md=1e8;
  const int MAX=1e5+1;
  //
  //
  int main(){
  	ll n;
  	cin>>n;
  	vector<pair<string,ll>> vec(n),ad(n);
  	string str;
  	ll k;
  	rep(i,0,n){
  		cin>>str>>k;
  		vec[i].ff=str;
  		vec[i].ss=k*-1;
  	}
  	ad=vec;
  	sort(all(vec));
  	rep(i,0,n){
  		rep(j,0,n){
  			if(ad[j]==vec[i]){
  				cout<<j+1<<'\n';
  				break;
  			}
  		}
  	}
  	return 0;
  }

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ff first
#define ss second
#define len(x) (int)(x.size())
#define all(vs) vs.begin(), vs.end()
using ii = pair<int, int>;
using ll = long long;

int32_t main(){
	ios::sync_with_stdio(0);	
	int n, m;
	cin >> n >> m;
	if(m==n)
		cout << "Yes\n";
	else 
		cout << "No\n";
}


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


int main(){


    int a, b, k, i;

    int n = 0;


    cin >> a >> b >> k;


    vector<int> v;


    for( i = 1 ; i <= a && i <= b ; i = i + 1 ){

         if( ( a % i == 0 ) && ( b % i == 0 ) ){

             v.push_back(i);

             n += 1;

             }

         }


    cout << v.at(n - k) << endl;

    return 0;

    }


Measured memory_bytes: 256
import java.util.*;
import java.io.*;
import java.lang.*;
//import java.util.Scanner;
//import java.io.InputStream;
//import java.io.IOException;
//import java.util.NoSuchElementException;
//import java.io.PrintWriter;
//import java.lang.Math;
//import java.io.BufferedReader;
//import java.io.InputStreamReader;
//import java.util.StringTokenizer;

public class Main
{
	public static void main(String[] args)
	{
		StringBuilder sb = new StringBuilder();
		
//		Scanner sc = new Scanner(System.in);
		FastScanner sc = new FastScanner();
		Util39 util = new Util39();
//		int n = sc.nextInt();
//		String s = sc.next();
//		int a[] = new int[3];
//		for (int ii = 0; ii < 3; ii++) a[ii] = sc.nextInt();
		
		
		
		int a = sc.nextInt();
		int b = sc.nextInt();
		int c = (a + b + 2 - 1) / 2;
		sb.append(c);
		
		
		
//		System.out.println(sb.toString());
		PrintWriter out = new PrintWriter(System.out);
		out.println(sb.toString());
		out.flush();
	}
}

class FastScanner {
    private final InputStream in = System.in;
    private final byte[] buffer = new byte[1024];
    private int ptr = 0;
    private int buflen = 0;
    private boolean hasNextByte() {
        if (ptr < buflen) {
            return true;
        }else{
            ptr = 0;
            try {
                buflen = in.read(buffer);
            } catch (IOException e) {
                e.printStackTrace();
            }
            if (buflen <= 0) {
                return false;
            }
        }
        return true;
    }
    private int readByte() { if (hasNextByte()) return buffer[ptr++]; else return -1;}
    private static boolean isPrintableChar(int c) { return 33 <= c && c <= 126;}
    public boolean hasNext() { while(hasNextByte() && !isPrintableChar(buffer[ptr])) ptr++; return hasNextByte();}
    public String next() {
        if (!hasNext()) throw new NoSuchElementException();
        StringBuilder sb = new StringBuilder();
        int b = readByte();
        while(isPrintableChar(b)) {
            sb.appendCodePoint(b);
            b = readByte();
        }
        return sb.toString();
    }
    public long nextLong() {
        if (!hasNext()) throw new NoSuchElementException();
        long n = 0;
        boolean minus = false;
        int b = readByte();
        if (b == '-') {
            minus = true;
            b = readByte();
        }
        if (b < '0' || '9' < b) {
            throw new NumberFormatException();
        }
        while(true){
            if ('0' <= b && b <= '9') {
                n *= 10;
                n += b - '0';
            }else if(b == -1 || !isPrintableChar(b)){
                return minus ? -n : n;
            }else{
                throw new NumberFormatException();
            }
            b = readByte();
        }
    }
    public int nextInt() {
        long nl = nextLong();
        if (nl < Integer.MIN_VALUE || nl > Integer.MAX_VALUE) throw new NumberFormatException();
        return (int) nl;
    }
    public double nextDouble() { return Double.parseDouble(next());}
}

class Util39 {
	public int pow(int a, int b)
	{
		int r = 1;
		for (int i = 0; i < b; i++) r *= a;
		return r;
	}
}


Measured memory_bytes: 21460
package main

import (
	"bufio"
	"fmt"
	"io"
	"math"
	"os"
	"strconv"
	"strings"

)


func main() {
	solve(os.Stdin, os.Stdout)
}

type ReaderEx struct {
	baseScanner *bufio.Scanner
	words       []string
	nextWordIdx func() int
	initWordIdx func(int)
}

func NewScannerEx(stdin io.Reader) *ReaderEx {
	var this ReaderEx
	var idx int
	var wordsCnt int
	this.baseScanner = bufio.NewScanner(stdin)
	this.baseScanner.Buffer(make([]byte, 0), 1E+11)
	this.nextWordIdx = func() int {
		cur := idx
		idx = (idx + 1) % wordsCnt
		return cur
	}
	this.initWordIdx = func(wc int) {
		idx = 0
		wordsCnt = wc
	}
	return &this
}

func (me *ReaderEx) Scan(doSplit bool) (isScanned bool) {
	isScanned = me.baseScanner.Scan()
	if doSplit {
		me.words = strings.Fields(me.baseScanner.Text())
	} else {
		me.words = []string{me.baseScanner.Text()}
	}
	me.initWordIdx(len(me.words))
	return
}

func (me *ReaderEx) nextBytes() []byte {
	return []byte(me.words[me.nextWordIdx()])
}
func (me *ReaderEx) nextString() string {
	return me.words[me.nextWordIdx()]
}

type StringArray []string

func (me *ReaderEx) nextStringArray() StringArray {
	return me.words[me.nextWordIdx():]
}

func (me StringArray) toStrings() []string {
	return me
}

func (me StringArray) toInts() []int {
	strValues := me.toStrings()
	values := make([]int, len(strValues))
	for i, v := range strValues {
		n, err := strconv.Atoi(v)
		if err != nil {
			panic(err)
		}
		values[i] = n
	}
	return values
}
func (me *ReaderEx) nextInt() int {
	n, err := strconv.Atoi(me.words[me.nextWordIdx()])

	defer func() {
		if err != nil {
			panic(fmt.Sprintf("getInt(%d)", n))
		}
	}()
	return n
}

func pow(x, y, mod int) (ans int) {

	ans = 1
	for bit := 1 << uint(math.Floor(math.Log2(float64(y)))); ; bit >>= 1 {
		if y&bit != 0 {
			ans *= x
			if mod > 0 {
				ans %= mod
			}
		}
		if bit <= 1 {
			return
		}
		ans *= ans
		if mod > 0 {
			ans %= mod
		}
	}
}

type factType struct {
	prime int
	count int
}

func fact(n int) (facts []*factType) {

	for i := 2; i*i <= n; i++ {
		if n%i == 0 {
			fa := factType{prime: i}
			for n%fa.prime == 0 {
				n /= fa.prime
				fa.count++
			}
			facts = append(facts, &fa)
		}
	}
	if n > 1 {
		facts = append(facts, &factType{prime: n, count: 1})
	}
	return facts
}
func dec2bin(n int) (ret []bool) {
	for bit := 1 << uint(math.Floor(math.Log2(float64(n)))); ; bit >>= 1 {
		ret = append(ret, n&bit != 0)

		if bit <= 1 {
			return
		}
	}

}

func abs(v int) int {
	if v < 0 {
		v = -v
	}
	return v
}

func b2i(b bool) (i int) {
	if b {
		i = 1
	} else {
		i = 0
	}
	return
}

func solve(stdin io.Reader, stdout io.Writer) {

	r := NewScannerEx(stdin)
	r.Scan(true)
	a, b, c, d := r.nextInt(), r.nextInt(), r.nextInt(), r.nextInt()

	maxInt := func(a int, vs ...int) int {
		for i := range vs {
			v := &vs[i]
			if a < *v {
				a = *v
			}
		}
		return a
	}
	fmt.Fprintln(stdout, maxInt(a*c, a*d, b*c, b*d))
}


Measured memory_bytes: 1744
import Control.Applicative

main :: IO ()
main = do
  n <- readLn
  [a, b] <- f
  [c, d] <- f
  print $ solve n (a-1) (b-1) (c-1) (d-1)
  where
    f = map read <$> words <$> getLine

solve :: Int -> Int -> Int -> Int -> Int -> Int
solve n a b c d = minimum $ map f [1 .. n]
  where
    f w = let (xa, ya) = divMod a w
              (xb, yb) = divMod b w
              (xc, yc) = divMod c w
              (xd, yd) = divMod d w
          in abs (xa - xb) + abs (ya - yb) + abs (xc - xd) + abs (yc - yd)



Measured memory_bytes: 3804
require"prime"
p2017=Prime.each(10**5).to_a
p2017.select!{|a|((a+1)/2).prime?}
gets.to_i.times{
  l,r=gets.split.map(&:to_i)
  lidx=p2017.bsearch_index{|a|l<=a}
  unless lidx
    puts 0
    next
  end
  ridx=p2017.bsearch_index{|a|r<a}
  puts ridx ? ridx-lidx : p2017.size-lidx
}

Measured memory_bytes: 3508
n = int(input())
array =list(map(int, input().split()))

min_index = 0
count = 0
for i in range(n):
    min_index = i
    for j in range(i+1, n):
        if array[min_index] > array[j]:
            min_index = j
    if array[i] != array[min_index]:
        array[i], array[min_index] = array[min_index], array[i]
        count += 1
print(' '.join(map(str, array)))
print(count)


Measured memory_bytes: 5600
def main():
    n, a, b = map(int, input().split())
    x = list(map(int, input().split()))
    cnt=0
    for i in range(n-1):
        if (x[i + 1] - x[i]) * a > b:
            cnt += b
        else:
            cnt += (x[i + 1] - x[i]) * a
    print(cnt)
main()

Measured memory_bytes: 14252
//----------------------------------------------------------------
//H

#include <iostream>
#include <vector>
#include <string>
using namespace std;

// MOD
const int MOD = 1000000007;

// 入力
int H, W;
vector<string> a;

// DP テーブル
int dp[1100][1100] = {0};

// add
void add(int &a, int b) {
    a += b;
    if (a >= MOD) a -= MOD;
}

int main() {
    cin >> H >> W;
    a.resize(H);
    for (int i = 0; i < H; ++i) cin >> a[i];

    // DP 初期化: すでに配列全体が 0 に初期化されているので OK

    // DP 初期条件
    dp[0][0] = 1;

    // DP ループ
    for (int i = 0; i < H; ++i) {
        for (int j = 0; j < W; ++j) {
            if (i+1 < H && a[i+1][j] == '.') add(dp[i+1][j], dp[i][j]);
            if (j+1 < W && a[i][j+1] == '.') add(dp[i][j+1], dp[i][j]);
        }
    }
    cout << dp[H-1][W-1] << endl;
}

Measured memory_bytes: 9824
#include<stdio.h>

int main(void)
{
    int N;
    int a[100];
    int ans=0;

    scanf("%d", &N);

    for (int i=0; N>i; i++) {
        scanf("%d", &a[i]);
    }
    for (int i=0; N>i; i++) {
        for (int j=N-1; j>i; j--) {
            if (a[j] < a[j-1]) {
                int tmp;
                tmp = a[j];
                a[j] = a[j-1];
                a[j-1] = tmp;
            }
        }
    }
    for (int i=N-1;0<i; i=i-2) {
        ans += a[i] - a[i-1];
    }
    if (1==N%2) {
        ans += a[0];
    }
    printf("%d\n", ans);
    return 0;
}

Measured memory_bytes: 128
#include <iostream>
#include <algorithm>
#include <string>
#include <cctype>
using namespace std;
int main()
{
    int n;
    cin >> n;
    int st = 0,sh = 0;
    for(int i = 0;i < n;i++)
    {
        string t,h;
        cin >> t >> h;
        if(t > h)
        {
            st +=3;
        }
        else if(t < h)
        {
            sh += 3;
        }
        else
        {
            st++;
            sh++;
        }
    }
    cout << st << " " << sh << endl;
}

Measured memory_bytes: 1212
// Last Change: 04/27/2019 21:58:46.
#include <algorithm>
#include <array>
#include <bitset>
#include <cmath>
#include <cstdlib>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <memory>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>

using namespace std;
using ll = long long;

namespace NS {
void LoopUntilZeroInpput() {
  int hogegegege = 0;
  while (cin >> hogegegege && hogegegege != 0) {
  }
}
} // namespace NS

int main() {
  ll N;
  cin >> N;
  vector<ll> A(N);
  for (auto &&e : A) {
    cin >> e;
  }

  vector<pair<ll, ll>> dp(N); // f:stay, s:reverse;
  dp[N - 2].first = A[N - 1] + A[N - 2];
  dp[N - 2].second = -1 * dp[N - 2].first;

  for (ll i = N - 3; i >= 0; --i) {
    dp[i].first = A[i] + max(dp[i + 1].first, dp[i + 1].second);
    dp[i].second =
        -1 * A[i]
        + max(dp[i + 1].first - 2 * A[i + 1], dp[i + 1].second + 2 * A[i + 1]);
  }

  cout << max(dp[0].first, dp[0].second) << endl;

  //NS::LoopUntilZeroInpput();
}


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

#define REP(i, n) for(int i = 0;i < n;i++)
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define ALL(a) (a).begin(), (a).end()

using namespace std;

int main()
{
    unsigned long long K; cin >> K;

    int N = 50;

    cout << N << endl;
    REP(i, N)
    {
        int mod = K % N;

        cout << i + K / N + (50 - mod <= i ? 1 : 0) << " ";
    }

    cout << endl;

    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define fast ios_base::sync_with_stdio(0); cin.tie(0)
#define int int64_t
#define ii pair<int, int>
#define endl '\n'
#define vi vector<int>
#define vii vector<ii>
#define vvi vector<vi>
#define vvii vector<vii>
#define F first
#define S second
#define pb push_back
#define FOR(i,l,r) for(int i=l; i<r; ++i)
#define ROF(i,r,l) for(int i=r; i>l; --i)
#define all(x) x.begin(), x.end()
#define amin(a,b) a = min(a,b)
#define amax(a,b) a = max(a,b)
#define test int t; cin >> t; while(t--) solve();

using namespace std;
typedef long long ll;

const int MAXN = 200005;
const int MAXINT = 2147483098;
const int MAXLL = 9223372036854775258LL;
const int MOD = 1e9 + 7;
//const int MOD = 998244353;



int p[MAXN], sz[MAXN];


void make_set(int a){
    p[a] = a;
    sz[a] = 1;
}

int find_set(int a){
    if (a==p[a]) return a;
    return p[a] = find_set(p[a]);
}


int unite(int a, int b){
    a = find_set(a);
    b = find_set(b);
    if (a==b) return sz[a];

    if (sz[a]>sz[b]) swap(a,b);
    sz[b] = sz[a]+sz[b];
    p[a] = b;
    return sz[b];
}

int32_t main()
{
    //freopen("holiday.in", "r", stdin);
    fast;
    //test;

   int n,m;
   cin >> n >> m;
   int ans = 1;
   FOR(i,1,n+1) make_set(i);
   FOR(i,0,m){
   int a,b;
   cin >> a >> b;
   ans = max(ans, unite(a,b));
   }
   cout << ans;

   return 0;
}


Measured memory_bytes: 6776
ab = []
for _ in range(3):
    a, b, c = (int(x) for x in input().split())
    ab.append([a, b, c])
dp = [[0 for i in range(3)] for j in range(3)] 
n=int(input())
#print(ab)
for _ in range(n):
    t=int(input())
    for i in range(3):
        for j in range(3):
            if ab[i][j] == t:
                dp[i][j] = 1

for i in range(3):
    if 0 not in dp[i]:
        print('Yes')
        exit()

for i in range(3):
    if dp[0][i] == 1 and dp[1][i] == 1 and dp[2][i] == 1:
        print('Yes')
        exit()
if dp[0][0] == 1 and dp[1][1] == 1 and dp[2][2] == 1:
    print('Yes')
    exit()
elif dp[0][2] == 1 and dp[1][1] == 1 and dp[0][2] == 1:
    print('Yes')
    exit()
else:
    print('No')

Measured memory_bytes: 38384