akhauriyash/Code-Regression huggingface dataset:
#include <algorithm>
#include <iostream>
#include <vector>

using namespace std;

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

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

int main() {
  int n, k;
  cin >> n >> k;
  ll v[n];
  REP(i, n) cin >> v[i];
  ll ans = 0;
  for (int a = 0; a <= min(n, k); ++a) {
    for (int b = 0; b <= min(n, k) - a; ++b) {
      vector<ll> vc;
      REP(i, a) vc.push_back(v[i]);
      REP(i, b) vc.push_back(v[n - 1 - i]);
      sort(ALL(vc));
      int sub = k - (a + b);
      REP(i, vc.size()) {
        if (vc[i] < 0 && sub) {
          vc[i] = 0;
          sub--;
        }
      }
      ll tmp = 0;
      REP(i, vc.size()) tmp += vc[i];
      ans = max(ans, tmp);
    }
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
  static Scanner sc = new Scanner(System.in);

  public static void main(String[] args) {
    int N = sc.nextInt();
    int K = sc.nextInt();
    long[] A = new long[N];
    long[] sum = new long[N + 1];
    long[] sumPosi = new long[N + 1];
    for (int i = 0; i < N; i++) {
      A[i] = sc.nextInt();
      sum[i + 1] = sum[i] + A[i];
      sumPosi[i + 1] = sumPosi[i] + Math.max(A[i], 0);
    }
    long ans = 0;
    for (int i = 0; i <= N - K; i++) {
      long s = sumPosi[N] - sumPosi[i + K] + sumPosi[i] + Math.max(sum[i + K] - sum[i], 0);
      ans = Math.max(ans, s);
    }
    System.out.println(ans);
  }

}


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

int main(void){
    int n,asum=0;
    cin>>n;
    int a[n] = {};
    for(int i=0;i<n;i++){
        cin>>a[i];
        asum += a[i];
    }
    int y;
    if(asum>0) y = ( asum + n/2.0)/n;
    else y = ( asum - n/2.0)/n;
    int ans = 0;
    for(int i=0;i<n;i++) ans += (a[i]-y)*(a[i]-y);
    cout<<ans<<endl;

}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define FOR(i,a,b) for(int i=a;i<=b;i++)
#define FORD(i,a,b) for(int i=a;i>=b;i--)
#define FORL(i,x) for(int i=head[x];i;i=nxt[i])
#define ALL(a)  (a).begin(),(a).end()
#define SZ(a) int((a).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())
#define PB push_back
#define MP make_pair
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

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

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

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

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

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

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


int main() {
    // input(sunippets: inpv, inpn, inps)
    ll N, M,A,B,C;
    cin >> N >> M;
    UnionFind uf(N);

    // calculation
    FOR(i,0,M-1){
        cin >> A >> B >> C;
        --A; --B;
        uf.merge(A, B);
    }

    set<int> s;

    FOR(i,0,N-1){
      s.insert(uf.root(i));
    }

    cout << s.size() << endl;

    return 0;
}



Measured memory_bytes: 6528
#include <iostream>
#include <vector>
#include <set>
#include <algorithm>
#include <math.h>

using namespace std;

int main()
{
  long long int N;
  cin >> N;
  vector <long long int> t(N), a(N);
  for(int i=0;i<N;i++){
    cin >> t[i] >> a[i];
  }
  long long int anst=1, ansa=1;
  for(int i=0;i<N;i++){
    long long int tmp = max((anst-1)/t[i]+1,(ansa-1)/a[i]+1);
    anst=t[i]*tmp;
    ansa=a[i]*tmp;
  }
  
  cout<< anst+ansa  <<endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define INF 1000000007
#define maxk 100000
vector < vector<ll>> memo;
int a[100];
int N;
ll dp(ll i, ll j)
{
    if (j == 0)
        return 1;
    if (j < 0)
        return 0;
    if (i == -1)
        return 0;
    if (memo[i][j] != -1)
        return memo[i][j];
    return memo[i][j] = ((dp(i - 1, j) + dp(i, j - 1)) % INF - dp(i - 1, j - a[i] - 1) + INF) % INF;
}
int main()
{
    int K;
    cin >> N >> K;
    for (int i = 0; i < N; i++)
    {
        cin >> a[i];
    }
    memo.resize(N);
    for (int i = 0; i < memo.size(); i++)
    {
        memo[i].resize(K + 1, -1);
    }
    cout << dp(N - 1, K) << endl;
}


Measured memory_bytes: 84864
#include <iostream>
#include <deque>
#include <string>

int main()
{
  std::cin.tie(nullptr);
  std::ios::sync_with_stdio(false);
  
  int64_t N;
  std::cin>>N;
  
  int64_t n=N;
  std::deque<char> r;
  const int Base=26;
  for(;;)
  {
    n--;
    
    int64_t a=n%Base;
        
    r.push_front(a+'a');
    
    n/=Base;
    
    if(n==0)
      break;
  }
  
  std::string result(r.begin(),r.end());
  
  std::cout<<result<<std::endl;
  
  return 0;
}

Measured memory_bytes: 3660
ni = lambda: int(input())
nm = lambda: map(int, input().split())
nl = lambda: list(map(int, input().split()))

n=ni()


cnt=[0]*(n+1)

for x in range(1,n+1):
  if x**2+x>n:
    break
  for y in range(x,n+1):
    if x**2+y**2+x*y+x+y>n:
      break
    for z in range(y,n+1):
      num = x**2+y**2+z**2+x*y+y*z+x*z
      if num > n:
        break
      if x==y==z:
        cnt[num]+=1
      elif x==y:
        cnt[num]+=3
      elif y==z:
        cnt[num]+=3
      elif x==z:
        cnt[num]+=3
      else:
        cnt[num]+=6

for i in range(1,n+1):
  print(cnt[i])


Measured memory_bytes: 68996
#include<bits/stdc++.h>
typedef long long LL;
using namespace std;
const int maxn=1e6+10;
const LL mod=1e4+7;
const double pi=acos(-1.0);
inline LL read()
{
	LL X=0; bool flag=1; char ch=getchar();
	while(ch<'0'||ch>'9') {if(ch=='-') flag=0; ch=getchar();}
	while(ch>='0'&&ch<='9') {X=(X<<1)+(X<<3)+ch-'0'; ch=getchar();}
	if(flag) return X;
	return ~(X-1);
}
string ko(LL x)
{
    string s;s.clear();
    while(x>0){
        LL m=x%26;
        if(m==0)m=26;
        s=(char)(m+96)+s;
        x=(x-m)/26;
    }
    return s;
}
int main()
{
    LL n;
    cin>>n;
    cout<<ko(n)<<endl;
    return 0;
}


Measured memory_bytes: 3628
#include<stdio.h>
#include<iostream>
#include<bits/stdc++.h>
using namespace std;
int main()
{	
	int n;
	cin>>n;
	if(n >= 3)
	{
		int ar[n];
		for (int i = 0; i < n; i++ )
			cin>>ar[i];
		int count =0;
		for(int i=0 ; i < n; i++) {	
			for (int j = i+1; j < n; j++)	{
				for (int k = j+1; k < n; k++)	{
					if( ar[i] != ar[j] && ar[j] != ar[k] && ar[k] != ar[i])
					if( ar[i] + ar[j] > ar[k] && ar[j] + ar[k] > ar[i] && ar[i] + ar[k] > ar[j])
						{		
							count++;
						}
					}
			}
		}
	cout<<count<<"\n";
	}
	else cout<<"0"<<"\n";	
	return 0;
}

Measured memory_bytes: 3628
#include <iostream>
#include <cmath>
#include <climits>
#include <algorithm>
#include <vector>
#include <unordered_map>
#include <unordered_set>
#include <stack>
#include <list>
#include <map>
#include <set>
#include <stack>
#include <queue>
#include <string.h>
#include <iomanip>
#include <ctype.h>

#define ll          long long int
#define ull         unsigned long long int
#define pb          push_back
#define pii         pair<int,int>
#define F           first
#define S           second
#define vi          vector<int>
#define vli          vector<ll>
#define vii         vector<pii>
#define mi          map<int,int>
#define mii         map<pii,int>
#define M_PI        3.14159265358979323846
#define mp          make_pair
#define sz(x)       (int)x.size()
//#define hell        1000000007
#define matrix      vector<vector<ll>>
#define forn(i,a,b)  for(int i=a;i<b;i++)
#define eps 0.000000001
#define all(a)      (a).begin(),(a).end()
const long long INF = (long long) 1e7+1;
const long long mod = (long long) 998244353;
const long long hell = (long long) 1000000007;

using namespace std;
#include <stdio.h>
ll m;
ll power(ll x,ll y)
{
  ll res=1;
  while(y>0)
  {
    if(y%2) res=(x*res);
    x=(x*x);
    y=y/2;
  }
  return res;
}

ll modinv(ll x){
  return power(x,hell-2);
}

void solve();


void fastIO() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
}

int main(){
   fastIO();
    solve();
}
//void sieve();
ll pw(ll k,ll x);
ll gcd(ll x,ll y);

/*
  For freq or prime factors

for(auto pri:prime){
  while(k%pri==0){
    pcnt[pri]++;
    k/=pri;
  }
}*/

bool issafe(int x,int y,int n,int m){
  return (x>=0 && y>=0 && x<n && y<m);
}
vector<int> gr[101];
int f,mx;

void dfs(int v,int p,int d){
    if(d>mx){
        mx=d;
        f=v;
    }
    for(auto u:gr[v]){
        if(u!=p){
            dfs(u,v,d+1);
        }
    }
}

void solve(){
  int test;
  //cin>>test;
  test=1;
  
  while(test--){
        int n,m;
        cin>>n>>m;
        
        int x;
        cin>>x;
        
        if(n<m)
        swap(n,m);
        
        cout<<((x+n-1)/n);
  }    
}    

    




///Before submit=>
///    *check for integer overflow,array bounds
///    *check for n=1

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


ll pw(ll k,ll x){
  if(x==0)
  return 1;
  if(x&1)
  return ((pw(k,x-1))*k);
  else
  return ((pw(k,x/2))*(pw(k,x/2)));
}


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

int main(){
  long long a,b,c;
  cin >> a >> b >> c;
  if(a%2==0 || b%2==0 || c%2==0)cout << 0 << endl;
  else {
    long long mid = a+b+c-max({a,b,c})-min({a,b,c});
    cout << min({a,b,c}) * mid << endl;
  }
  return 0;
}


Measured memory_bytes: 256
// #include <bits/stdc++.h>
#include<climits>
#include<cmath>
#include<cstdio>
#include<deque>
#include<map>
#include<set>
#include<vector>
#include<iostream>
#include<sstream>
#include<algorithm>
#include<numeric>
#include<string>
#include<tuple>
using namespace std;
// #include <boost/multiprecision/cpp_int.hpp>
// using namespace boost::multiprecision;
#define BEGIN ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define END return EXIT_SUCCESS
#define rep(I,N) for(auto I=0;I<(N);++I)
#define up(I,A,B) for(auto I=(A);I<=(B);++I)
#define dw(I,A,B) for(auto I=(A);I>=(B);--I)
#define all(C) (C).begin(),(C).end()
#define rall(C) (C).rbegin(),(C).rend()
#define ft first
#define sd second
#define mp make_pair
#define mt make_tuple
#define pf push_front
#define pb push_back
#define pt pop_front
#define pk pop_back
#define lb lower_bound
#define ub upper_bound
#define rs resize
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;}
template<class T>inline void                             in(T &p){cin>>p;}
template<class T1,class T2>inline void                   in(T1 &p1,T2 &p2){cin>>p1>>p2;}
template<class T1,class T2,class T3>inline void          in(T1 &p1,T2 &p2,T3 &p3){cin>>p1>>p2>>p3;}
template<class T1,class T2,class T3,class T4>inline void in(T1 &p1,T2 &p2,T3 &p3,T4 &p4){cin>>p1>>p2>>p3>>p4;}
template<class T>inline void                             ins(T &p){for_each(all(p),in<decltype(p[0])>);}
template<class T>inline void                             out(T p){cout<<p<<endl;}
template<class T1,class T2>inline void                   out(T1 p1,T2 p2){cout<<p1<<" "<<p2<<endl;}
template<class T1,class T2,class T3>inline void          out(T1 p1,T2 p2,T3 p3){cout<<p1<<" "<<p2<<" "<<p3<<endl;}
template<class T1,class T2,class T3,class T4>inline void out(T1 p1,T2 p2,T3 p3,T4 p4){cout<<p1<<" "<<p2<<" "<<p3<<" "<<p4<<endl;}
template<class T>inline void                             outs(T p){for_each(all(p),out<decltype(p[0])>);}
long N,H,W;
inline void solve(void){
  in(N,H,W);
  out((N-H+1)*(N-W+1));
}
int main(int argc,char**argv){
  BEGIN;
  solve();
  END;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define loop(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n)  loop(i,0,n)
#define all(c) c.begin(),c.end()
#define rall(c) c.rbegin(),c.rend()
#define vi vector<int>
#define vl vector<ll>
#define pll pair<ll,ll>
#define vpll vector<pll>

int main(){
  int n,m;
  cin>>n>>m;
  int s[m];
  int c[m];
  rep(i,m)cin>>s[i]>>c[i];
  int max_s=0;
  max_s=n;
  int ans[max_s];
  rep(i,max_s)ans[i]=-1;

  rep(i,m){
    if(ans[s[i]-1]!=-1 && ans[s[i]-1]!=c[i]){
      cout<<-1<<endl;
      return 0;
    }
    ans[s[i]-1]=c[i];
  }

  if(ans[0]==0 && max_s>1){
    cout<<-1<<endl;
    return 0;
  }

  if(ans[0]==-1 && max_s>1)ans[0]=1;
  if(ans[0]==-1 && max_s==1)ans[0]=0;
  rep(i,max_s){
    if(ans[i]==-1)ans[i]=0;
  }

  ll int a=0;
  rep(i,max_s){
    a+=ans[i]*pow(10,max_s-i-1);
  }

  cout<<a<<endl;

}




Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define rrep(ri,n) for(int ri = (int)(n-1); ri >= 0; ri--)
#define rep2(i,x,n) for(int i = (int)(x); i < (int)(n); i++)
#define repit(itr,x) for(auto itr = x.begin(); itr != x.end(); itr++)
#define rrepit(ritr,x) for(auto ritr = x.rbegin(); ritr != x.rend(); ritr++)
#define ALL(n) begin(n), end(n)
using ll = long long;
using namespace std;

int main(){
  int n;
  cin >> n;
  vector<vector<int>> gr(n, vector<int>(n,0));
  rep(i, n){
    int nn;
    cin >> nn;
    int num;
    cin >> num;
    rep(j, num){
      int a;
      cin >> a;
      a--;
      gr.at(i).at(a)++;
    }
  }
  rep(i, n){
    rep(j, n){
      if(j != 0) cout << " ";
      cout << gr.at(i).at(j);
    }
    cout << endl;
  }
  return 0;
}


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

void swap(int *a, int *b) {
    int tmp = *a;
    *a = *b;
    *b = tmp;
}

int main() {
    int N, ans = 0;
    std::cin >> N;

    std::vector<int> L(N);
    for(int i = 0; i < N; i++) {
        std::cin >> L.at(i);
    }

    for(int i = 0; i < N - 2; i++) {
        for(int j = i + 1; j < N - 1; j++) {
            for(int k = j + 1; k < N; k++) {
                
                if(L.at(i) != L.at(j) && L.at(i) != L.at(k) && L.at(j) != L.at(k)) {
                    int a = L.at(i), b = L.at(j), c = L.at(k);

                    if(a > c) {
                        swap(&a, &c);
                    }
                    if(b > c) {
                        swap(&b, &c);
                    }

                    if(a + b > c) {
                        ans++;
                    }
                }
                
            }
        }
    }

    std::cout << ans << std::endl;

}


Measured memory_bytes: 3640
#include <iostream>
#include <algorithm>
#include <vector>
#define debug(x) cout << #x << "==" << x << endl;

using namespace std;

//??\???
#define MAX_N 44
int N;
int dp[MAX_N];

int main() {
  ios::sync_with_stdio(false);

  cin >> N;

  // dp[0] = dp[1] = 1;
  // for(int i = 2; i <= N; i++) {
  //   dp[i] = dp[i-1] + dp[i-2];
  // }

  int now = 1;
  int prev1 = 1, prev2 = 1;
  for(int i = 2; i <= N; i++) {
    now = prev1 + prev2;
    prev2 = prev1;
    prev1 = now;
  }

  cout << now << endl;

  return 0;
}

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

int main(void)
{
	int a,b,ans;
	while(scanf("%d %d",&a,&b) != EOF){
		ans = 0;
		a += b;
		while(a){
			a /= 10;
			ans++;
		}
		printf("%d\n",ans);
	}
	return 0;
}

Measured memory_bytes: 600
n,m=map(int,input().split())
student=[]
for _ in range(n):
    a,b=map(int,input().split())
    student.append((a,b))

point=[]
for _ in range(m):
    a,b=map(int,input().split())
    point.append((a,b))

# 生徒単位でチェック
for sx,sy in student:
    dist=2*10**10
    pnum=0
    for i, p in enumerate(point):
        px,py=p[0],p[1]
        pdist=abs(sx-px)+abs(sy-py)
        if pdist<dist:
            dist=pdist
            pnum=i+1
    print(pnum)

Measured memory_bytes: 3064
// #define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(v) v.begin(), v.end()
#define Graph vector<vector<int>>
typedef long long ll;
typedef pair<int, int> P;
const int INF = 1000000007;

// #include <boost/multiprecision/cpp_dec_float.hpp>
// #include <boost/multiprecision/cpp_int.hpp>
// namespace mp = boost::multiprecision;
// using Bint = mp::cpp_int;
// using Real = mp::number<mp::cpp_dec_float<1024>>;

int main(){
    int N;
    cin >> N;
    vector<int> A(N);
    map<int, ll> M;
    rep(i, N){
        int a;
        cin >> a;
        A[i] = a;
        M[a]++;
    }

    ll ans = 0;

    for(auto i : M){
        ans += i.second * (i.second - 1) / 2;
    }

    rep(i, N){
        int tmp = M[A[i]];
        cout << ans - tmp + 1 << endl;
    }
}

Measured memory_bytes: 10240
#include<bits/stdc++.h>
#define REP(i,n) for(int i=0,i##_len=int(n);i<i##_len;++i)
#define rep(i,a,b) for(int i=int(a);i<int(b);++i)
#define All(x) (x).begin(),(x).end()
#define rAll(x) (x).rbegin(),(x).rend()
using namespace std;
using ll = long long;

int main(){
    int X;cin>>X;
    if(X==3||X==5||X==7) cout<<"YES"<<endl;
    else cout<<"NO"<<endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define mk make_pair
#define fs first
#define sc second
using namespace std;
typedef long long ll;
typedef long double ld;
ll a[301], n, k;
ll comp[333], mp1[333];
ll mem[301][302][301];
ll dp(int x, int pr, int kk){
    if(x>=n){
        return 0;
    }
    if(mem[x][pr][kk]!=-1)
        return mem[x][pr][kk];
    ll res=0;
    res=max(0ll, (a[x]-comp[pr]))+dp(x+1, mp1[x], kk);
    if(kk<k){
        res=min(res, dp(x+1, pr, kk+1));
    }
    mem[x][pr][kk]=res;
    return res;
}
map<int, int> mp;
int main(){
    while(cin>>n>>k){
        ll ans=0;
        set<int> s;
        for(int i=0; i<n; ++i){
            scanf("%lld",a+i);
            s.insert(a[i]);
        }
        s.insert(0);
        int cnt=0;
        for(auto it:s){
            mp[it]=cnt;
            comp[cnt]=it;
            ++cnt;
        }
        for(int i=0; i<n; ++i){
            mp1[i]=mp[a[i]];
        }
        memset(mem, -1, sizeof mem);
        ans=dp(0, 0, 0);
        cout<<ans<<endl;
    }
  return 0;
}




Measured memory_bytes: 214016
//************************************JAI SAI RAM*************************************** 
// ED ROUND 85 DIV 2 PROBLEM D HARD TO THINK OF and hard TO IMPLEMENT .
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
#define endl "\n";
#define pair pair<ll,ll> 
ll MAX=LLONG_MAX;
ll MIN=LLONG_MIN;
ll P=1000000007;
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    ll i,j,k,l,m,n,o,p,q,r,s,t,x,a[500],tt=0;
    cin>>n;
    s=0;
    for(i=1;i<=n;i++)
    {
        for(j=1;j<=n;j++)
        {
            for(k=1;k<=n;k++)
            {
                s+=(__gcd(i,__gcd(j,k)));
            }
        }
    }
    cout<<s<<endl;
    return 0;
}  
    


Measured memory_bytes: 3608
N,K=map(int,input().split())
A=list(map(int,input().split()))
Key=A[0]
for i in range(1,N-K+1):
  key=A[K+i-1]
  if key>Key:
    print('Yes')
    Key=A[i]
  else:
    print('No')
    Key=A[i]

Measured memory_bytes: 31672
def main():
    X, K, D = map(int, input().split())
    if X < 0:
        X *= (-1)
    i = min(X // D, K)
    out = X - i * D
    if (K - i) % 2 == 0 or K < X//D:
        print(out)
    else:
        print(min(abs(out - D), abs(out + D)))


if __name__ == '__main__':
    main()


Measured memory_bytes: 9180
#include <bits/stdc++.h>
#define ll long long int
#define pb push_back
#define se second
#define fi first
#define rep(i, l, r) for (ll i = (ll)(l); i < (ll)(r); i++)
#define print(v) for (const auto itr : v){cout << itr << ' ';} cout << endl;
#define mod 1000000007
#define inf 1e18
using namespace std;
const ll INF = 1e18L + 5;
const ll maxn = 1e5*2+5, maxn1=202;
ll ceel(ll a, ll b)
{
   if (a % b == 0)
       return a / b;
   return a / b + 1;
}
ll modneg(ll a,ll m)
{
    a = a % m;
    if(a<0)
        a=a+m;
    return a;
}
ll powermod(ll x, unsigned ll y, ll p){ll res = 1;x = x % p;while (y > 0){if (y & 1){res = (res*x) % p;}y = y>>1; x = (x*x) % p;}return res;}
ll lcm(ll a, ll b) { return (a * b) / __gcd(a, b); };

int main()
{

ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
ll n,i,j,temp;
map <ll,ll> mp;
cin>>n;
rep(i,1,n)
{
    cin>>temp;
    mp[temp]++;
}
for(i=1;i<=n;i++)
{
    cout<<mp[i]<<endl;
}
return 0;
}

Measured memory_bytes: 16164
#include <cstdio>
#include <algorithm>
using namespace std;
typedef long long ll;
struct Point{
   ll x,y;
   Point (ll x=0, ll y=0):x(x),y(y){}
};
 
typedef Point Vector;
 
Vector operator +(Vector A,Vector B) { return Vector(A.x+B.x,A.y+B.y); }
Vector operator -(Vector A,Vector B) { return Vector(A.x-B.x,A.y-B.y); }
Vector operator *(Vector A,double p) { return Vector(A.x*p,A.y*p); }
 
ll Dot(Vector A,Vector B) { return A.x*B.x+A.y*B.y; }
ll Cross(Vector A,Vector B) { return A.x*B.y-A.y*B.x; }
ll Length(Vector A) { return Dot(A,A); }
 
const int maxn = 2e5+10;
Point p[maxn],sol[maxn];
ll n,m;
 
bool cmp(Point a, Point b){
   ll ans = Cross(a-p[0],b-p[0]);
   return ans>0 || ans==0 && Length(a-p[0])<Length(b-p[0]);
}
 
ll ConvexHull(Point *p,Point *ch){
    sort(p+1,p+n,cmp);
    ll m = 0;
    for (ll i=0; i<n; i++) {
        while (m>1 && Cross(ch[m-1]-ch[m-2],p[i]-ch[m-2])<=0) m--;
        ch[m++] = p[i];
    }
 
    ll k = m;
    for (ll i=n-2; i>=0; i--){
        while (m>k && Cross(ch[m-1]-ch[m-2],p[i]-ch[m-2])<=0) m--;
        ch[m++] = p[i];
    }
 
    if (n>1) m--;
    return m;
}
ll f(Point A,Point B){
	return abs(A.x-B.x)+abs(A.y-B.y);
}
ll Rotate_calipers(Point* ch, int n){
    ll q=1;
    ll ans = 0;
    ch[n] = ch[0];
    for (ll i=0; i<n; i++) {
        while ( Cross(ch[q+1]-ch[i],ch[q+1]-ch[i+1])>Cross(ch[q]-ch[i],ch[q]-ch[i+1]) ) q = (q+1)%n;
        ans = max( ans,max( f(ch[i],ch[q]),f(ch[i+1],ch[q+1]) ) );
    
    }
    return ans;
}
 
int main(){
    while (scanf("%lld",&n)==1){
        ll x,y;
        for (ll i=0; i<n; i++) {
            scanf("%lld%lld",&x,&y);
            p[i] = Point(x,y);
        }
 
        if (n==2) {
            printf("%lld\n",f(p[0],p[1]));
            continue;
        }
 
        for (ll i=1; i<n; i++) {
            if (p[i].x<p[0].x || p[i].x==p[0].x && p[i].y<p[0].y) swap(p[i],p[0]);
        }
 
  
 
        m = ConvexHull(p,sol);
  
        printf("%lld\n",Rotate_calipers(sol,m));
 
    }
    return 0;
}


Measured memory_bytes: 7984
def get_popcount(n):
    ret = 0
    while n > 0:
        if n & 1 == 1:
            ret += 1
        n >>= 1
    return ret


def main():
    N = int(input())
    X = input()
    ans = [0] * N
    # (1) 最初の1ステップ(n <- n % popconut(n))を行う
    X_popcount = len([x for x in X if x == '1'])
    popcounts = [X_popcount] * N
    for i, x in enumerate(X):
        if x == '1':
            popcounts[i] -= 1
        else:
            popcounts[i] += 1
    # X % popcount(X_i)を計算 (popcount(X_i)は2パターン)
    X_nexts = [0, 0]  # [X % (popcount(X) - 1), X % (popcount(X) + 1)]
    pows = [1, 1]
    for x in X[::-1]:
        if x == '1':
            if X_popcount - 1 > 0:
                X_nexts[0] += pows[0]
                X_nexts[0] %= X_popcount - 1
            X_nexts[1] += pows[1]
            X_nexts[1] %= X_popcount + 1
        if X_popcount - 1 > 0:
            pows[0] *= 2
            pows[0] %= X_popcount - 1
        pows[1] *= 2
        pows[1] %= X_popcount + 1
    # X % popcount(X_i) に要素を足し引きして X_i % popcount(X_i) を求める
    xs = [0] * N
    pows = [1, 1]
    for j, x in enumerate(X[::-1]):
        i = N - 1 - j
        if x == '1':
            if X_popcount - 1 > 0:
                xs[i] = X_nexts[0] - pows[0]
                xs[i] %= X_popcount - 1
                ans[i] += 1
        else:
            xs[i] = X_nexts[1] + pows[1]
            xs[i] %= X_popcount + 1
            ans[i] += 1
        if X_popcount - 1 > 0:
            pows[0] *= 2
            pows[0] %= X_popcount - 1
        pows[1] *= 2
        pows[1] %= X_popcount + 1
    # (2) 以降繰り返し(popcounts, xsを利用)
    while sum(xs) > 0:
        for i, x in enumerate(xs):
            if x == 0:
                continue
            xs[i] = x % get_popcount(x)
            ans[i] += 1
    # 答え
    for a in ans:
        print(a)


if __name__ == '__main__':
    main()


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

#define name ""
#define ini freopen(name".inp","r",stdin); freopen(name".out","w",stdout)
#define foe(it,c) for (__typeof(c.begin()) it = c.begin(); it != c.end(); it++)
#define long long long 
#define db double 
#define pii pair <int, int>
#define pll pair <long, long>
#define all(c) c.begin(), c.end()
#define fastio ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0)

const int INF = 1e9+7;
const int MOD = 1e9+7;
const int dx[4] = {0,0,-1,1};
const int dy[4] = {-1,1,0,0};

int main()
{
  fastio;
  vector <int> a(3);
  for (int &x : a) cin >> x;
  sort(all(a));
  if (a[0] == a[1] && a[1] != a[2]) return cout << "Yes", 0;
  if (a[0] != a[1] && a[1] == a[2]) return cout << "Yes", 0;
  cout << "No";
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0; i<n; i++)
#define REP(i,m,n) for(ll i=(ll)(m);i<(ll)(n);i++)
long long mo = 1e9 + 7;
typedef long long ll;
typedef long double ld;
typedef pair<int,int> Pii;
typedef pair<ll,ll> Pll;
template<class T, class S> void cmin(T &a, const S &b) { if (a > b)a = b; }
template<class T, class S> void cmax(T &a, const S &b) { if (a < b)a = b; }
template<class A>void PR(A a,ll n){rep(i,n){if(i)cout<<' ';cout<<a[i];}cout << "\n";}
ld PI=3.14159265358979323846;

int main(){
    ll N;
    string S;
    cin >> S;
    N = S.size();
    vector<ll> dp(N+10),dec(N+10);
    ll t = 1;
    rep(i,N){
        dec[N-1-i] = t;
        t *= 10;
        t %= 2019;
    }
    ll cur = 0;
    dp[N] = 0;
    rep(i,N){
        ll c = S[N-1-i] - '0';
        cur += c*dec[N-1-i];
        cur %= 2019;
        //if(!(cur)){
        //    dp[N-1-i] = ;//dp[N-i] + 1;
        //}else{
        dp[N-1-i] = cur;//dp[N-i];
        //cout << cur << endl;
        //}
    }
    ll sum = 0;
    map<ll,ll>mp;
    rep(i,N+1){
        mp[dp[i]]++;
    }
    ll ans = 0;
    for(auto& e:mp){
        //cout << e.second << endl;
        ans += e.second*(e.second-1)/2;
    }
    cout << ans << endl;
}

Measured memory_bytes: 6744
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;

namespace AtCoder.A
{
    internal static class CR
    {
        public static string GetText() { return Console.ReadLine(); }
        public static List<string> GetTexts() { return Console.ReadLine().Split(' ').ToList(); }
        public static long GetLong() { return long.Parse(Console.ReadLine()); }
        public static List<long> GetLongs() { return Console.ReadLine().Split(' ').Select(x => long.Parse(x)).ToList(); }
    }

    public class Program
    {
        public static void Main() { var r = GetResult(); Debug.WriteLine(r); Console.Write(r); }

        private static object GetResult()
        {
            var inputs = CR.GetLongs();
            return inputs[2] + " " + inputs[0] + " " + inputs[1];
        }
    }
}


Measured memory_bytes: 11348
#!/usr/bin/env python3
import sys
INF = float("inf")


def solve(N: int, K: int, S: str):

    comp = [0]
    for pre, curr in zip(S[0]+S, S):
        if pre == curr:
            comp[-1] += 1
        else:
            comp.append(1)

    print(sum(comp)-max(len(comp)-2*K, 1))
    return


def main():

    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    K = int(next(tokens))  # type: int
    S = next(tokens)  # type: str
    solve(N, K, S)


if __name__ == '__main__':
    main()


Measured memory_bytes: 46192
def solve():
  y,m,d = map(int, input().split("/"))
  if y < 2019: 
    return "Heisei"
  elif y > 2019: 
    return "TBD"
    
  if m < 4: 
    return "Heisei"
  elif m > 4: 
    return "TBD"
    
  if d > 30: 
    return "TBD"
  return "Heisei"

print(solve())

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

int main(){
  int n;
  cin >> n;
  vector<pair<int,int> >blue(n);
  vector<pair<int,int> >red(n);

  vector<bool>blueChk(n,true);
  vector<bool>redChk(n,true);

  int i,j;
  for(i=0;i<n;i++){
    cin >> red[i].first >> red[i].second;
  }
  for(i=0;i<n;i++){
    cin >> blue[i].first >> blue[i].second;
  }
  sort(red.begin(),red.end());
  sort(blue.begin(),blue.end());
  int ans = 0;
  for(i=0;i<n;i++){
    if(blueChk[i]){
      int tmpY = -1;
      int tmp = -1;
      for(j=n-1;j>=0;j--){
        if(redChk[j] && red[j].first<blue[i].first && red[j].second<blue[i].second){
          if(tmpY < red[j].second){
            tmpY = red[j].second;
            tmp = j;
          }
        }
      }
      if(tmp!=-1){
        ans++;
        redChk[tmp]=false;
      }
    }
  }
  cout<<ans<<endl;
}


Measured memory_bytes: 256
#include <iostream>

using namespace std;

const int SIZE = 2e5+5;
int a[SIZE];

int main(int argc, char const *argv[])
{
	int n;
	while(~scanf("%d", &n))
	{
		for (int i = 0; i < n; ++i)
		{
			scanf("%d", &a[i]);
		}
		int minv = a[0];
		int maxv = -1e9-5;
		for (int i = 1; i < n; ++i)
		{
			maxv = max(maxv, a[i]-minv);
			minv = min(minv, a[i]);
		}
		printf("%d\n", maxv);
	}
	return 0;
}

Measured memory_bytes: 3964
#include <iostream>
#include <string>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <utility>
#include <stack>
#include <numeric>
#include <algorithm>
#include <tuple>
#include <stdio.h>
#include <bitset>
#include <limits.h>
#include <complex>
#include <deque>
#include <iomanip>
#include <list>
#include <cstring>
using namespace std;
#define pi pair<int,int>
#define pl pair<long long,long long>
#define chmax(a,b) (a<b ? a=b:0)
#define chmin(a,b) (a>b ? a=b:0)
#define en cout << endl //セミコロンつけろ
//#define MM 1000000000
//#define MOD MM+7
typedef long long ll;
const int MM = 1e9;
const int MOD = MM+7;
const long double PI = acos(-1);
const long long INF = 1e15;
int dx[8] = {-1,0,1,0,-1,-1,1,1};
int dy[8] = {0,-1,0,1,-1,1,1,-1};
// 'A' = 65, 'Z' = 90, 'a' = 97, 'z' = 122
template<typename T>
T GCD(T u,T v){
    return v ? GCD(v,u%v) : u;
}
template<typename T>
T LCM(T x,T y){
    T gc = GCD(x,y);
    return x*y/gc;
}
struct edge {
    ll to,cost;
};
/*
const int COM_MAX = 500500;
long long fac[COM_MAX],finv[COM_MAX],inv[COM_MAX];
void init(){
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for(int i = 2; i < COM_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 || n < 0 || k < 0) return 0;
    return fac[n]*(finv[k]*finv[n-k]%MOD)%MOD;
}
*/
int main(){
    while(true){
        int N; cin >> N;
        if (N == 0){
            break;
        }
        int sum = 0;
        for (int i = 0; i < N/4; i++){
            int a; cin >> a;
            sum += a;
        }
        cout << sum << endl;
    }

}


Measured memory_bytes: 2988
#include<algorithm>
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<map>
#include<cstdio>
#include<iomanip>
#include<cmath>
using namespace std;

long long modinv(long long a, long long m) {
    long long b = m, u = 1, v = 0;
    while (b) {
        long long t = a / b;
        a -= t * b; swap(a, b);
        u -= t * v; swap(u, v);
    }
    u %= m;
    if (u < 0) u += m;
    return u;
}

int main(){
//    cout << fixed << setprecision(10);
    int K;
    string s;
    cin >> K >> s;
    
    for (int i = 0; i < s.size(); i++) {
        if (i == K) {
            break;
        }
        cout << s[i];
    }
    
    if (K < s.size()) {
        cout << "...";
    }

    return 0;
}


Measured memory_bytes: 3624
using System;
//using System.Collections.Generic;
//using System.Linq;
//using System.Text;
//using System.Threading;
using System.IO;
using System.Text;

//============================================================================
namespace Sweet
{
    class Program
    {
        static StreamWriter writer = null;
        //============================================================================
        static void setstdio(string[] args)
        {
            if (0 < args.Length)
            {
                // Redirect standard input from the console to the input file.
                Console.SetIn(new StreamReader(args[0]));
                if (args.Length == 2)
                {
                    // Attempt to open output file.
                    writer = new StreamWriter(args[1]);
                    // Redirect standard output from the console to the output file.
                    Console.SetOut(writer);
                }
            }
        }
        //============================================================================
        static int Swing()
        {
            int sum;
            StringBuilder builder = new StringBuilder(Console.ReadLine());
            for (int i = sum = 0; i < builder.Length; i++)
                sum += builder[i] & 0xf;
            if (sum!=0)
                Console.WriteLine(sum);
            return sum;
        }
        //============================================================================
        static void Main(string[] args)
        {
            setstdio(args);

            while(Swing()!=0);
            if (writer != null)
                writer.Close();
            //Console.ReadLine();
        }
        //============================================================================
    }
}

Measured memory_bytes: 9028
a = input()
b = 'hi'
c = 'hihi'
d = 'hihihi'
e = 'hihihihi'
f = 'hihihihihi'

if (a == b) or (a == c) or (a == d) or (a == e) or (a == f):
  print('Yes')
else:
  print('No')

Measured memory_bytes: 3060
import java.util.Scanner;

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

        if (s.equals(t)) {
            System.out.println("Yes");
            return;
        }

        int len = s.length();
        for (int i = 0; i < len-1; i++) {
            s = s.substring(len-1, len) + s.substring(0, len-1);
            if (s.equals(t)) {
                System.out.println("Yes");
                return;
            }
        }
        System.out.println("No");
    }
}


Measured memory_bytes: 23124
import sys
sys.setrecursionlimit(1000000000)
ii = lambda: int(input())
mis = lambda: map(int, input().split())
lmis = lambda: list(mis())

def main():
    N = ii()
    A = lmis()
    A = [(i+1, a) for i, a in enumerate(A)]
    A.sort(key=lambda x: x[1])
    for a in A:
        print(a[0], end=' ')


main()


Measured memory_bytes: 19248
#include <bits/stdc++.h>
#define MOD 1000000007LL
using namespace std;
typedef long long ll;
typedef pair<int,int> P;

string str[51];
int fie[61][61];

int main(void){
	int h,w;
	string str;
	scanf("%d%d",&h,&w);
	for(int i=0;i<h;i++){
		cin >> str;
		for(int j=0;j<w;j++){
			if(str[j]=='#'){
				fie[i+1][j+1]=-1000;
				for(int k=-1;k<=1;k++){
					for(int l=-1;l<=1;l++){
						fie[i+1+k][j+1+l]++;
					}
				}
			}
		}
	}
	for(int i=0;i<h;i++){
		for(int j=0;j<w;j++){
			printf("%c",fie[i+1][j+1]>=0?('0'+fie[i+1][j+1]):'#');
		}
		printf("\n");
	}
	return 0;
}

Measured memory_bytes: 256
#include <cstdio>
#include <vector>
#include <algorithm>
#include <cstdlib>
using namespace std;

int w, h, n;
typedef pair<int, int> P;
vector<P> v;
vector<int> x;
vector<int> y;

int main(){
	scanf("%d %d %d", &w, &h, &n);
	for(int i=0; i<n; ++i){
		int a, b;
		scanf("%d %d", &a, &b);
		v.push_back(P(a, b));
		x.push_back(a);
		y.push_back(b);
	}
	sort(x.begin(), x.end());
	sort(y.begin(), y.end());
	int mx[2], my[2];
	if(n % 2 == 1){
		mx[0] = mx[1] = x[(n-1)/2];
		my[0] = my[1] = y[(n-1)/2];
	}else{
		mx[0] = x[n/2-1];
		mx[1] = x[n/2];
		my[0] = y[n/2-1];
		my[1] = y[n/2];
	}
	long long int ans;
	for(int i=0; i<n; ++i){
		ans += abs(x[i] - mx[0]);
		ans += abs(y[i] - my[0]);
	}
	ans *= 2;
	int ma = -1, ax, ay;
	for(int i=0; i<2; ++i)
		for(int j=0; j<2; ++j)
			for(int k=0; k<n; ++k){
				int d = abs(v[k].first - mx[i]) + abs(v[k].second - my[j]);
				if(ma < d){
					ma = d;
					ax = mx[i];
					ay = my[j];
				}
			}
	ans -= ma;
	printf("%lld\n%d %d\n", ans, ax, ay);
}

Measured memory_bytes: 4292
H, W, N, *a = map(int, open(0).read().split())
ans = []
for i in range(N):
  ans.extend([i+1 for _ in range(a[i])])
ans = [ans[i:i+W] for i in range(0, H*W, W)]
for i in range(1, H, 2):
  ans[i] = reversed(ans[i])
for r in ans:
  print(' '.join(map(str,r)))


Measured memory_bytes: 3572
import java.util.Scanner;
 
class Main {
        public static void main(String args[]) {
                Scanner sc = new Scanner(System.in);
                int A = sc.nextInt(), B = sc.nextInt(), C = sc.nextInt(), D = sc.nextInt(), E = sc.nextInt();
                System.out.println(A - Math.max((B - 1) / D + 1, (C - 1) / E + 1));
        }
}


Measured memory_bytes: 26168
object Main extends App {
  val sc = new java.util.Scanner(System.in)
  val n = sc.nextInt()
  val s = sc.next()
  val q = sc.nextInt()
  val seg = new SegmentTree()
  seg.init(n)
  for (i <- 0 until n) {
    seg.update(i, 1 << (s(i) - 'a'))
  }
  for (i <- 0 until q) {
    val t = sc.nextInt()
    if (t == 1) {
      val i = sc.nextInt() - 1
      val c = sc.next()(0)
      seg.update(i, 1 << (c - 'a'))
    } else {
      val l, r = sc.nextInt() - 1
      println(bitCount(seg.query(l, r + 1, 0, 0, seg.n)))
    }
  }
  def bitCount(n: Int): Int = {
    var i = n
    i = i - ((i >>> 1) & 0x55555555)
    i = (i & 0x33333333) + ((i >>> 2) & 0x33333333)
    i = (i + (i >>> 4)) & 0x0f0f0f0f
    i = i + (i >>> 8)
    i = i + (i >>> 16)
    i & 0x3f
  }
  class SegmentTree {
    var n = 1
    val id = 0;
    var node = Array[Int]()
    def init(sz: Int) {
      n = 1;
      while (n < sz) n *= 2;
      node = Array.fill(2 * n - 1)(id);
    }
    def update(i: Int, k: Int) = {
      var x = i + n - 1;
      node(x) = k;
      while (x > 0) {
        x = (x - 1) / 2;
        node(x) = node(2 * x + 1) | node(2 * x + 2);
      }
    }
    def query(a: Int, b: Int, k: Int, l: Int, r: Int): Int = {
      if (r <= a || b <= l) {
        id;
      } else if (a <= l && r <= b) {
        node(k);
      } else {
        val lv = query(a, b, 2 * k + 1, l, (l + r) / 2);
        val rv = query(a, b, 2 * k + 2, (l + r) / 2, r);
        (lv | rv)
      }
    }
  };
}


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

int main() {
    int N, H; cin >> N >> H;
    int a, b;
    int m = 0;
    vector<int> vec(N);
    for (int i = 0; i < N; i++) {
        cin >> a >> b;
        m = max(m, a);
        vec[i] = b;
    }
    sort(vec.begin(), vec.end());
    int ans = 0;
    for (int i = N-1; i >= 0; i--) {
        if (vec[i] > m) {
            ans++;
            H -= vec[i];
            if (H <= 0) {
                cout << ans << endl;
                return 0;
            }
        }
        else break;
    }
    ans += H / m;
    if (H%m) ans++;
    cout << ans << endl;
}


Measured memory_bytes: 640
import sys
input = lambda: sys.stdin.readline().rstrip()

def main():
    S = input()
    ans = 0
    if S[0] == 'R' and S[1] == 'R' and S[2] == 'R':
        ans = 3
    elif (S[0] == 'R' and S[1] == 'R') or S[1] == 'R' and S[2] == 'R':
        ans = 2
    elif 'R' in S:
        ans = 1
    else:
        ans = 0
    print(ans)

if __name__ == '__main__':
    main()


Measured memory_bytes: 61888
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int a,b;
    cin>>a>>b;
    if(a==1 && b==2)
        cout<<"3"<<endl;
    else if(a==2 && b==1)
        cout<<"3"<<endl;
        else if(a==1 && b==3)
        cout<<"2"<<endl;
        else if(a==3 && b==1)
        cout<<"2"<<endl;
        else if(a==2 && b==3)
        cout<<"1"<<endl;
        else
        cout<<"1"<<endl;
}


Measured memory_bytes: 256
#pragma GCC optimize("O3")
#include <bits/stdc++.h>
using namespace std;
#define boost ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0)
#define rando mt19937 rng(chrono::steady_clock::now().time_since_epoch().count())
#define fi first
#define se second
#define debug(x) cerr << " - " << #x << ": " << x << endl;
#define debugs(x, y) cerr << " - " << #x << ": " << x << " " << #y << ": " << y << endl;
#define debugii(x) cerr << " - " << #x << ": " << x.fi<<","<<x.se << endl;
#define sep() cerr << "--------------------" << endl;
#define all(x) (x).begin(),(x).end()
#define sz(x) (ll)x.size()
#define ld long double
#define ll long long
#define int ll
#define ii pair<int,int>
#define v vector<int>
#define vii vector<ii>
#define vv vector<vector<int> >
#define mp make_pair
#define INF 1000000000
#define pb push_back
#define EPS 1e-9
const int MOD = 1000000007; // 998244353
v vec;
set<int> myset;
int p[20];
void solve(int idx,int last,int sum){
	//debug(sz(myset));
	//if(sz(myset))
	if(idx==10)return;
	if(!idx)
		for (int i = 0; i <= 9; ++i){
			if(i)myset.insert(sum+p[idx]*i);
			solve(idx+1,i,sum+p[idx]*i);
		}
	else{
		for (int i = -1; i <= 1; ++i)
		{
			if((i+last)>=0&&(i+last)<=9){
				if(i+last)myset.insert(sum+p[idx]*(i+last));
				solve(idx+1,i+last,sum+p[idx]*(i+last));
			}
		}
	}
}
int32_t main(){
	boost;
	//freopen(".in","r",stdin);
	int k;
	cin>>k;
	p[0]=1;
	for (int i = 1; i < 12; ++i)
		p[i]=p[i-1]*10LL;
	solve(0,0,0);
	//debug(sz(myset));
	int c=1;
	for(auto it:myset){
		if(c==k){
			cout<<it;return 0;
		}
		//debug(it);
		c++;
	}
	return 0;
}
//long long
//array bounds
//special cases
//binary search

Measured memory_bytes: 9600
import java.util.*;

public class Main {

    // クイックソートのメソッド
    public static int[] quickSort(int[] input) {
    	return quick(input, 0, input.length - 1);
    }

    private static int[] quick(int[] input, int left, int right) {
    	int[] array = input;
    	int currentLeft = left;
    	int currentRight = right;

    	// 要素数が1以下のときは、何もせず返却する
    	if (array.length < 2)
    		return array;

    	// クイックソートの場合、軸の選び方は色々あるが、このメソッドでは
    	// 軸は、currentLeftとcurrentRightの真ん中にある要素とする。
    	int pivot = array[(currentLeft + currentRight) / 2];

    	do {
    		while (array[currentLeft] < pivot) {
    			currentLeft++;
    		}

    		while (array[currentRight] > pivot) {
    			currentRight--;
    		}
    		if (currentLeft <= currentRight) {
    			int index1 = currentLeft++;
    			int index2 = currentRight--;
    			int temp = array[index1];
    			array[index1] = array[index2];
    			array[index2] = temp;
    		}
    	} while (currentLeft <= currentRight);

    	if (left < currentRight)
    		quick(array, left, currentRight);

    	if (currentLeft < right)
    		quick(array, currentLeft, right);
    	return array;
    }

    public static int maxBArg(int[] b, boolean[] lost, int N) {
        int arg = 0;
        int max = 0;
        for (int i = 0; i < N; i++) {
            if (lost[i] == false && max < b[i]) {
                max = b[i];
                arg = i;
            }
        }
        return arg;
    }

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        int H = sc.nextInt();
        int[] a = new int[N];
        int[] b = new int[N];
        int damage = 0;
        int count = 0;
        int needB = N;
        boolean[] lost = new boolean[N];
        //値の入力とaの最大値の発見
        int a_max = 0;
        int a_max_arg = 0;
        for (int i = 0; i < N; i++) {
            a[i] = sc.nextInt();
            b[i] = sc.nextInt();
            if (a_max < a[i]) {
                a_max = a[i];
                a_max_arg = i;
            }
        }
        //Bをソート
        b = quickSort(b);
        //aの最大値とbの比較
        int base = 0;
        for (int i = 0; i < N; i++) {
            if (b[i] >= a_max) {
                base = i;
                break;
            }
        }
        //bのみで撃破
        for (int i = N - 1; i >= base; i--) {
            damage += b[i];
            count++;
            if (damage >= H) {
                System.out.println(count);
                return;
            }
        }
        while (true) {
            damage += a_max;
            count++;
            if (damage >= H) {
                break;
            }
        }
        System.out.println(count);
    }

}


Measured memory_bytes: 86768
N, M, V, P = map(int, input().split())
A = sorted(map(int, input().split()))[::-1]
ans, s = P, A[P-1]
for i in range(P, N):
    if A[i]+M>=A[P-1]:
        ans += ((V+i+1-N-P)*M<=(i-P+1)*(A[i]+M)-s)
        s += A[i]
print(ans)


Measured memory_bytes: 16320
import java.util.*;

class Main
{
  public static void main(String args[])
  {
    Scanner sc=new Scanner(System.in);
    int n=sc.nextInt();
    int[] arr=new int[n];
    int xor=0;
    for(int i=0;i<n;i++)
    {
      arr[i]=sc.nextInt();
      xor^=arr[i];
    }
  	for(int i=0;i<n;i++)
    {
      arr[i]^=xor;
      System.out.print(arr[i]+" ");
    }
  }
}

Measured memory_bytes: 61692
n = int(input())
t = [0] * n
x = [0] * n
y = [0] * n
breaker = 0
for i in range(n):
    t[i], x[i], y[i] = map(int, input().split())
for i in range(n):
    if i == 0:
        if x[i]+y[i] <= t[i] and (x[i]+y[i]+t[i])%2 == 0:
            pass
        else:
            breaker = 1
            break
    else:
        if x[i]+y[i] <= t[i] and (x[i]+y[i]+t[i])%2 == 0 and x[i]-x[i-1]+y[i]-y[i-1] <= t[i]-t[i-1]:
            pass
        else:
            breaker = 1
            break
if breaker == 0:
    print("Yes")
else:
    print("No")

Measured memory_bytes: 11636
#include <iostream>
#include <vector>
using namespace std;
using ll = long long;

ll Array[1001];
void soinsu_(int);

void soinsu_(int x){
	int count = 0;
	int X = x;
	for(int i=2;i<=X;){
		if(x % i == 0){
			count++;
			x = x / i;
		}else{
			Array[i] += count;
			count = 0;
			i++;
		}
	}
}

int main(){
	int N;
	ll answer = 1;
	
	cin >> N;
	
	for(int i=0;i<1001;i++){
		Array[i] = 0;
	}
	for(int i=1;i<=N;i++){
		soinsu_(i);
	}
	
	for(int i=0;i<1001;i++){
		answer = answer * (Array[i]+1) % 1000000007;
	}
	
	cout << answer << endl;
	return 0;
}


Measured memory_bytes: 256
n=int(input())
x=list(map(int,input().split()))
mod=pow(10,9)+7

def cmb(n,r,mod):
  if (r<0 or r>n):
    return 0
  r=min(r,n-r)
  return g1[n]*g2[r]*g2[n-r]%mod
g1=[1,1] # g1[i]=i! % mod　:階乗
g2=[1,1] # g2[i]=(i!)^(-1) % mod　:階乗の逆元
inverse=[0,1]
for i in range(2,n+1):
  g1.append((g1[-1]*i)%mod)
  inverse.append((-inverse[mod%i]*(mod//i))%mod)
  g2.append((g2[-1]*inverse[-1])%mod)
ans=0
for i in range(n-1):
  ans+=(x[n-1]-x[i])*g1[n-1]*pow(i+1,mod-2,mod)
  ans%=mod
print(ans)


Measured memory_bytes: 25956
#include <bits/stdc++.h>
using namespace std;
# define MOD 1000000007
long long dp[2][1000001];
long long util(vector<int> adj[], int n, int u, bool vis[], int flag){
    if(dp[flag][u] != -1) return dp[flag][u];
    vis[u] = 1;
    long long white = 1;
    for(int i=0;i<adj[u].size();i++){
        int v = adj[u][i];
        if(vis[v] == 0) white = (white*util(adj, n, v, vis, 0))%MOD;
    }
    long long res = white;
    if(flag == 0){
        long long black = 1;
        for(int i=0;i<adj[u].size();i++){
            int v = adj[u][i];
            if(vis[v] == 0) black = (black*util(adj, n, v, vis, 1))%MOD;
        }
        res = (res + black)%MOD;
    }
    vis[u] = 0;
    return dp[flag][u] = res;
}
int main(){
	int n;
	cin>>n;
    vector<int> adj[n];
    for(int i=0;i<n-1;i++){
        int xi, yi;
        cin>>xi>>yi;
        adj[xi-1].push_back(yi-1);
        adj[yi-1].push_back(xi-1);
    }
    bool vis[n] = {};
    memset(dp, -1, sizeof(dp));
    cout<<util(adj, n, 0, vis, 0);
	return 0;
}

Measured memory_bytes: 29824