akhauriyash/Code-Regression huggingface dataset:
#include <stdio.h>
#include <vector>
#include <algorithm>
#include <math.h>
#include <queue>

using namespace std;

//I imitated Ant Book version 1: P.84.

int n,q,com,x,y;
int rank[10000],parent[10000];

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

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

void unite(int x,int y){
	x = find(x);
	y = find(y);

	if(x == y)return;

	if(rank[x] < rank[y]){
		parent[x] = y;
	}else{
		parent[y] = x;
		if(rank[x] == rank[y])rank[x]++;
	}
}

int main(){

	scanf("%d %d",&n,&q);

	for(int i = 0; i < n; i++){
		rank[i] = 0;
		parent[i] = i;
	}

	for(int i = 0; i < q; i++){
		scanf("%d %d %d",&com,&x,&y);

		if(com == 1){
			if(isSame(x,y))printf("1\n");
			else{
				printf("0\n");
			}
		}else{
			if(isSame(x,y))continue;

			unite(x,y);
		}
	}

	return 0;
}



Measured memory_bytes: 2700
#include<bits/stdc++.h>
using namespace std;
#define int long long
const int mod=1e9+7;
const int maxn=1e6+10;
int dp[maxn][2][2];
signed main()
{
	int n;
	cin>>n;
	if(n==1)
	{
		cout<<0<<endl;
		return 0;
	}
	dp[0][0][0]=1;
	for(int i=1;i<=n;i++)
	{
		dp[i][0][0]=dp[i-1][0][0]*8%mod;
		dp[i][0][1]=(dp[i-1][0][0]+dp[i-1][0][1]*9%mod)%mod;
		dp[i][1][0]=(dp[i-1][0][0]+dp[i-1][1][0]*9%mod)%mod;
		dp[i][1][1]=(dp[i-1][0][1]+dp[i-1][1][0]+dp[i-1][1][1]*10%mod)%mod;
	}
	cout<<dp[n][1][1]<<endl;
	return 0;
}

Measured memory_bytes: 34836
#include<stdio.h>

int main(void) {

  int i;
  int h1,m1,s1;
  int h2,m2,s2;
  int sum;

  for(i=0; i<3; i++) {
    scanf("%d %d %d",&h1,&m1,&s1);
    scanf("%d %d %d",&h2,&m2,&s2);

    sum = (h2-h1)*3600 + (m2-m1)*60 + (s2-s1); 

    printf("%d ",sum/3600);
    sum %= 3600;
    printf("%d ",sum/60);
    sum %= 60;
    printf("%d\n",sum);

  }

  return 0;
}

Measured memory_bytes: 600
fun main(args: Array<String>){
    val line: String = readLine() as String
    val abc=line.split(" ")
    val a = abc[0].toInt()
    val b = abc[1].toInt()
    val c = abc[2].toInt()
    if (a+b>=c){
        print("Yes")
    }else{
        print("No")
    }
}


Measured memory_bytes: 36076
#include <bits/stdc++.h>
using namespace std;
using ll = int64_t;
#define rep(i,n) for(int i = 0; i < ((int)(n)); i++)   // 0-indexed昇順

int main() {
    ll D[3];
    rep(i,3) cin >> D[i];
    sort(D, D+3);
    ll mi = INT64_MAX;
    do {
        ll A = D[0] / 2;
        ll B = D[0] - A;
        ll diff = abs(A - B) * D[1] * D[2];
        if (mi > diff) mi = diff;
    } while(next_permutation(D, D+3));
    cout << mi << endl;
}


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

int main() {
  int A, B;
  cin >> A >> B;
  int sum = A+B;
  int dif = B-A;
  if (B % A == 0){
    cout << sum << endl;
  }
  else{
    cout << dif << endl;
  }
}



Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int n,q,x[200005],y[200005];
char s[200005];
bool judge1(int m)
{
    int i=1;
    while(m>0&&i<=q)
    {
        if(x[i]==s[m]-'A')
        {
            if(y[i]==0) m--;
            else m++;
        }
        i++;
        if(m==n+1) return false;
    }
    if(m==0)
        return true;
    return false;
}
bool judge2(int m)
{
    int i=1;
    while(m<n+1&&i<=q)
    {
        if(x[i]==s[m]-'A')
        {
            if(y[i]==0) m--;
            else m++;
        }
        i++;
        if(m==0) return false;
    }
    if(m==n+1)
        return true;
    return false;
}
int main()
{
    scanf("%d%d",&n,&q);
    scanf("%s",s+1);
    for(int i=1;i<=q;i++)
    {
        char a[5],b[5];
        scanf("%s%s",a,b);
        x[i]=a[0]-'A';
        if(b[0]=='R') y[i]=1;
    }
    int l=1,r=n,ll=0,rr=n+1;
    while(l<=r)
    {
        int m=l+r>>1;
        if(judge1(m)) ll=m,l=m+1;
        else r=m-1;
    }
    l=1,r=n;
    while(l<=r)
    {
        int m=l+r>>1;
        if(judge2(m)) rr=m,r=m-1;
        else l=m+1;
    }
    printf("%d\n",max(0,rr-ll-1));
}


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

const int N=2e+5+5;
long long int cou[N],a[N],conti[N],ans;
int n;

int main()
{
    cin>>n;
    for(int i=1;i<=n;i++)
    {
        cin>>a[i];
        cou[a[i]]++;
    }    
    for(int i=1;i<=n;i++)
    {
        conti[i]=(cou[i]*(cou[i]-1))/2;
        ans+=conti[i];
    }
    for(int i=1;i<=n;i++)
    {
        long long int cans=ans-conti[a[i]];
        cans+=((cou[a[i]]-1)*(cou[a[i]]-2))/2;
        cout<<cans<<"\n";
    }
}

Measured memory_bytes: 6784
#include <bits/stdc++.h>
#pragma comment(linker, "/stack:200000000")
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
using namespace std;

#define ll long long
#define ld long double
#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define eb emplace_back
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define rep(i, x, n) for (ll i = x; i < n; i++)
#define fastio() ios_base::sync_with_stdio(NULL); cin.tie(0); cout.tie(0)
#define endl '\n'

typedef vector<int> vi;
typedef vector<vector<int> > vvi;
typedef pair<int, int> ii;
typedef vector<pair<int, int> > vii;

template <class T> inline T RD(T &a) {T x; cin >> x; return a = x;}
template <class T> T gcd(T a, T b) {if (b) return gcd(b, a % b); else return a;}
template <class T> T lcm(T a, T b) {return (a * b) / gcd(a,b);}

const int maxw = 1e5 + 10, maxn = 101;

ll dp[maxn][maxw];

signed main()
{
//	freopen("test.inp", "r", stdin); //freopen("TEXT.out", "w", stdout);
	fastio();

    ll W, n; cin >> n >> W;
    vector<ll> w(n), val(n);

    memset(dp, 0, sizeof(dp));

    for (int i = 0; i < n; i++) cin >> w[i] >> val[i];

    for (int i = 0; i <= n; i++) {
        for (int j = 0; j <= W; j++) {
            if (i == 0 || j == 0) dp[i][j] = 0;
            else if (w[i - 1] <= j) dp[i][j] = max(dp[i - 1][j], dp[i - 1][j - w[i - 1]] + val[i - 1]);
            else dp[i][j] = dp[i - 1][j];
        }
    }
    cout << dp[n][W];
}


Measured memory_bytes: 82564
#include <iostream>
#include <string>
#include <vector>
using namespace std;
int main(void){
    string s;
    vector<int> result;
    result.clear();
    cin>>s;
    for(int i=0;i<s.size();i++){
        if(s[i]=='0') result.push_back(0);
        else if(s[i]=='1') result.push_back(1);
        else if(s[i]=='B'){
            if(!result.empty())result.pop_back();
        }
    }
    for(int i=0;i<result.size();i++){
        cout<<result[i];
    }
    cout<<endl;
    return 0;
}


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

using namespace std;

int main(){

    int cnt = 0;
    string s;

    cin>>s;

    for(int i=0;i<s.size() - 1;i++){
        if(s[i] != s[i + 1]) cnt++;
        
    }

    cout<<cnt<<endl;



    return 0;
}


Measured memory_bytes: 512
#include <stdio.h>
#include <string.h>


#define MAX 5

int main()
{
	int n;
	char s[MAX];
	int data[MAX] = { 0 };

	scanf("%d", &n);

	for (int i = 0; i < n; i++) {
		scanf("%s", s);
		if (strcmp(s, "AC") == 0)
			data[0]++;
		else if (strcmp(s, "WA") == 0)
			data[1]++;
		else if (strcmp(s, "TLE") == 0)
			data[2]++;
		else
			data[3]++;
	}

	printf("AC x %d\n", data[0]);
	printf("WA x %d\n", data[1]);
	printf("TLE x %d\n", data[2]);
	printf("RE x %d\n", data[3]);

	return 0;
}

Measured memory_bytes: 1728
package main

import (
	"fmt"
	"strings"
	"sort"
)

func main() { 
	var n int
	fmt.Scan(&n)
	stringList := make([]string, n)
	for i:=0; i < n; i++{
		var s string
		fmt.Scan(&s)
		k := strings.Split(s, "")
		sort.Strings(k)
		stringList[i] = strings.Join(k, "")
	}
	m := map[string]int{}
	ans := 0
	for _, sList:=range stringList {
		ans += m[sList]
		m[sList]++
	}
	fmt.Println(ans)
}

Measured memory_bytes: 13440
#include<bits/stdc++.h>
#define L long long
#define vi vector<int>
#define pb push_back
#define pi pair<int,int>
#define pii pair<pi,int>
#define aa first
#define bb second
#define xx aa.aa
#define yy aa.bb
#define zz bb
#define mp make_pair
#define mpp(a,b,c) mp(mp(a,b),c)
using namespace std;
const int q=1000000007;
int n,m,p,l[30][30],r[30][30],f[1050000],g[1050000],h[1050000][25];
inline void add(int &a,int b)
{
	a=(a+b)%q;
}
int main()
{
	//freopen(".in","r",stdin);
	//freopen(".out","w",stdout);
	int i,j,k,u;
	scanf("%d%d%d",&n,&m,&p);
	n--;
	for(i=1;i<=m;i++)
	  for(j=0;j<n;j++)
	    r[i][j]=1;
	while(p--)
	  {
	   scanf("%d%d%d",&i,&j,&k);
	   l[i][j-1]=r[i][j-1]=k;
	  }
	for(i=0;i<(1<<n);i++)
	  for(j=0;j<n;j++)
	    {
		 for(k=j+1;k<n;k++)
		   if(i&(1<<k))
		     break;
		 h[i][j]=(k==n?i:(i^(1<<k)))^(1<<j);
		}
	f[0]=1;
	for(i=1;i<=m;i++)
	  for(j=0;j<n;j++)
	    {
		 memset(g,0,sizeof(g));
		 for(k=0;k<(1<<n);k++)
		   for(u=l[i][j];u<=r[i][j];u++)
		     if(u>=((k>>j)&1))
		       add(g[(u==((k>>j)&1))?k:h[k][j]],f[k]);
		 memcpy(f,g,sizeof(f));
		}
	for(i=0,k=0;i<(1<<n);i++)
	  add(k,f[i]);
	printf("%d\n",k);
	return 0;
}


Measured memory_bytes: 61824
#include <stdio.h>

int main(void)
{
	long n;
	long i;
	long e,o;
	
	e=0;
	o=0;
	
	scanf("%ld",&n);
		
	//printf("%ld\n",n);
	e = n / 2;
	o = n - e;
	
	//printf("%ld %ld\n",e,o);

	
	printf("%f\n",(float)o/(float)n);

	return 0;
}



Measured memory_bytes: 128
# coding: utf-8
# Your code here!

class Dice:
    def __init__(self,lst):
        self.face=lst
    
    def roll(self,x):
        tmp=self.face
        if x=="E":
            self.face=[tmp[3],tmp[1],tmp[0],tmp[5],tmp[4],tmp[2]]
        if x=="W":
            self.face=[tmp[2],tmp[1],tmp[5],tmp[0],tmp[4],tmp[3]]
        if x=="N":
            self.face=[tmp[1],tmp[5],tmp[2],tmp[3],tmp[0],tmp[4]]
        if x=="S":
            self.face=[tmp[4],tmp[0],tmp[2],tmp[3],tmp[5],tmp[1]]
    
    def showDown(self):
        return self.face[0]
    
dice=Dice(list(map(int,input().split(" "))))
rolling=list(input())
for i in rolling:
    dice.roll(i)
print(dice.showDown())


Measured memory_bytes: 5612
import qualified Data.Vector.Unboxed as U
import qualified Data.Vector as V
import qualified Data.ByteString.Char8 as C
import qualified Data.Array.IO as A
import Debug.Trace
import Data.List
import Control.Monad


r' :: IO [Int]
r'  =   unfoldr    (C.readInt . C.dropWhile (==' ')) <$> C.getLine

main :: IO ()
main = do
    [a,b] <- r'
    if even (a+b) then print (div (a+b) 2) else putStrLn "IMPOSSIBLE"


Measured memory_bytes: 380
#include <iostream>
#include <vector>
#include <numeric>
#include <cmath>
#include <algorithm>
#include <string>
#define myfor(i,N) for(i=0;i<N;i++)
#define myforFL(i,f,l) for(i=f;i<l;i++)

using namespace std;

int main(void){
	int S,W;
	cin >> S >> W;
	if(S <= W) cout << "unsafe" << endl;
	else cout << "safe" << endl;
	return 0;
}


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

int main() {
  int h1, h2, k1, k2; cin >> h1 >> h2 >> k1 >> k2;
  int a, b, c, d; cin >> a >> b >> c >> d;

  auto calc = [&](int h, int k) {
                int score = h * a + k * b;
                score += c * (h / 10);
                score += d * (k / 20); 
                // fprintf(stderr, "score = %d\n", score);
                return score;
              };

  int va = calc(h1, h2), vb = calc(k1, k2);
  if(va == vb) cout << "even" << endl;
  else if(va > vb) cout << "hiroshi" << endl;
  else cout << "kenjiro" << endl;
  return 0;
}



Measured memory_bytes: 3100
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int[] h = new int[n];
        for (int i = 0; i < n; i++) {
            h[i] = sc.nextInt();
        }
        int ans = 0;
        while(true) {
            boolean flg = true;
            int count = 0;
            for (int i = 0; i < n; i++) {
                if(h[i] != 0 && flg) {
                    ans++;
                    flg = false;
                } else if(h[i] == 0){
                    flg = true;
                    count++;
                }
                if(h[i] > 0) {
                    h[i]--;
                }
                if(count == n) {
                    System.out.println(ans);
                    return;
                }
            }
        }
    }
}

Measured memory_bytes: 35924
#include<bits/stdc++.h>
using namespace std;
 
int main(){
  int n;string s;
  cin>>n>>s;
  if(n&1)cout<<"No";
  else{
    string ans="Yes";
    for(int i=0;i<n/2;i++){
      if(s[i]!=s[i+n/2]){
        ans="No";
        break;
      }
    }
    cout<<ans;
  }
}


Measured memory_bytes: 256
#pragma GCC optimize ("Ofast")
#include<bits/stdc++.h>
using namespace std;
template<class S, class T> inline S min_L(S a,T b){
  return a<=b?a:b;
}
inline void rd(int &x){
  int k, m=0;
  x=0;
  for(;;){
    k = getchar_unlocked();
    if(k=='-'){
      m=1;
      break;
    }
    if('0'<=k&&k<='9'){
      x=k-'0';
      break;
    }
  }
  for(;;){
    k = getchar_unlocked();
    if(k<'0'||k>'9'){
      break;
    }
    x=x*10+k-'0';
  }
  if(m){
    x=-x;
  }
}
inline void wt_L(char a){
  putchar_unlocked(a);
}
inline void wt_L(long long x){
  char f[20];
  int m=0, s=0;
  if(x<0){
    m=1;
    x=-x;
  }
  while(x){
    f[s++]=x%10;
    x/=10;
  }
  if(!s){
    f[s++]=0;
  }
  if(m){
    putchar_unlocked('-');
  }
  while(s--){
    putchar_unlocked(f[s]+'0');
  }
}
int N;
int A;
int B;
int X[100000];
int main(){
  int i;
  long long res=0;
  rd(N);
  rd(A);
  rd(B);
  {
    int Lj4PdHRW;
    for(Lj4PdHRW=0;Lj4PdHRW<(N);Lj4PdHRW++){
      rd(X[Lj4PdHRW]);
    }
  }
  for(i=(1);i<(N);i++){
    res +=min_L((long long)A*(X[i]-X[i-1]), B);
  }
  wt_L(res);
  wt_L('\n');
  return 0;
}
// cLay varsion 20190902-1

// --- original code ---
// int N, A, B, X[1d5];
// {
//   ll res = 0;
//   rd(N,A,B,X(N));
//   rep(i,1,N) res += min((ll)A*(X[i]-X[i-1]), B);
//   wt(res);
// }


Measured memory_bytes: 640
#include<stdio.h>
int main()
{
    int a,b;
    while(scanf("%d%d",&a,&b)==2)
    {
        if(a>=13)
        {
            printf("%d\n",b);
        }
        else if(a>=6 && a<=12)
        {
            printf("%d\n",b/2);
        }
        else if(a>=0 && a<=5)
        {
            printf("%d\n",0);
        }
    }
    return 0;
}

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

int main()
{
  string S;
  cin >>S;
  if(S=="Sunny"){
    cout <<"Cloudy"<<endl;
  }else if(S=="Cloudy"){
    cout <<"Rainy"<<endl;
  }else if(S=="Rainy"){
    cout <<"Sunny"<<endl;
  }
}




Measured memory_bytes: 256
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
using namespace std;
gp_hash_table<int, int> table;
typedef tree < int,  null_type,  less<int>,  rb_tree_tag,  tree_order_statistics_node_update > ordered_set;
typedef long long ll;
#define pb push_back
#define pi (acos(-1))
#define ull  unsigned long long
#define ld long double
#define all(v) v.begin(), v.end()
///freopen("input.txt","r",stdin);
///freopen("output.txt","w",stdout);
ll LCM(ll a, ll b)
{
    ll g = __gcd(a,b);
    return (a/g)*b ;
}
string numtostr(ll n)
{
    ostringstream str1 ;
    str1 << n ;
    return str1.str();
}
ll strtonum(string s)
{
    ll x ;
    stringstream str1(s);
    str1 >> x ;
    return x ;
}
int a;
int main(void)
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
   cin>>a;
   cout<<a+a*a+a*a*a;
    return 0;
}


Measured memory_bytes: 3628
#pragma GCC optimize(2,3)
#include<cstdio>
#include<iostream>
#include<cstring>
#include<algorithm>
#include<map>
#define re register
using namespace std;
map <string,int> mp;

int n,m,k;
inline int read(){
	re int t=0;
	re char v=getchar();
	while(v<'0')v=getchar();
	while(v>='0'){
	t=(t<<3)+(t<<1)+v-48;
	v=getchar();}
	return t;
}
string s[200002];
signed main(){
n=read();
for(re int i=1;i<=n;++i){
	cin>>s[i];
	++mp[s[i]];
}
sort(s+1,s+n+1);
for(re int i=1;i<=n;++i){
	if(mp[s[i]]>k)k=mp[s[i]];
}
for(re int i=1;i<=n;++i){
	if(mp[s[i]]==k){cout<<s[i]<<endl;--mp[s[i]];
	}
}
}

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

int main() {
  int A, B, ans;

  cin >> A >> B;
  ans = 0;
  for (int i = A; i < B + 1; i++) {
    int s, t, u, v;
    s = i / 10000 % 10;
    t = i % 10;
    u = i / 1000 % 10;
    v = i / 10 % 10;
    if (s == t && u == v) {
      ans += 1;
    }
  }
  cout << ans <<endl;
}


Measured memory_bytes: 256
A=int(input())
B=int(input())
C=int(input())
X=int(input())
count=0
for i in range(A+1) :
  for j in range(B+1) :
    for k in range(C+1) :
      if 500*i+100*j+50*k==X :
        count+=1
print(count)

Measured memory_bytes: 9188
import java.util.*;

class Main{
    public static void main(String args[]) {
        Scanner sc = new Scanner(System.in);
        int a = sc.nextInt();
        int b = sc.nextInt();
        int m = sc.nextInt();
        int[] ap = new int[a];
        int[] bp = new int[b];
        int min_a = 10000000;
        int min_b = 10000000;
        for(int i=0;i<a;i++){
            int tmp = sc.nextInt();
            ap[i] = tmp;
            min_a = Math.min(min_a, tmp);
        }
        for(int i=0;i<b;i++){
            int tmp = sc.nextInt();
            bp[i] = tmp;
            min_b = Math.min(min_b, tmp);
        }

        int res = min_a+min_b;
        for(int i=0;i<m;i++){
            int x = sc.nextInt();
            int y = sc.nextInt();
            int c = sc.nextInt();
            int sum = ap[x-1] + bp[y-1] - c;
            res = Math.min(sum, res);
        }

        System.out.println(res);
    }
}


Measured memory_bytes: 132860
//“Make it work, make it right, make it fast.” – Kent Beck
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double dd;
const int siz = 1e6 + 5;
const int MOD = 1e9 + 7;
#define endl '\n'
#define deb(x) cout << #x << " = " << x << endl;

void solve(){
  ll n;
  cin >> n;
  ll a[n];
  ll x = 0;
  for(ll &i : a) cin >> i, x^=i;
  for(ll i = 0; i < n; i++){
    cout << (x ^ a[i]) << ' ';
  }
  cout << endl;
}

int main(){
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  int t = 1;
  // cin >> t;
  while(t--){
    //tt++;
    //cout << "Case #" << tt << ": ";
    solve();
  }
  return 0;
}  

Measured memory_bytes: 5208
/**
 * code generated by JHelper
 * More info: https://github.com/AlexeyDmitriev/JHelper
 * @author shadowreaper810
 */

#include <iostream>
#include <fstream>

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

#define int long long
#define pb push_back
#define mp make_pair

const int MOD = 1000000007;

class CVacation {
public:
    void solve(std::istream& in, std::ostream& out) {
        int n;
        in>>n;
        int a[n+1],b[n+1],c[n+1];
        for(int i=1;i<=n;i++)
            in>>a[i]>>b[i]>>c[i];

        int dp[3][n+1];
        dp[0][1]=a[1];
        dp[1][1]=b[1];
        dp[2][1]=c[1];

        for(int i=2;i<=n;i++)
        {
            dp[0][i]=max(dp[1][i-1]+a[i], dp[2][i-1]+a[i]);
            dp[1][i]=max(dp[0][i-1]+b[i], dp[2][i-1]+b[i]);
            dp[2][i]=max(dp[0][i-1]+c[i], dp[1][i-1]+c[i]);
        }
        out<<max(dp[0][n],max(dp[1][n],dp[2][n]));
    }
};

int32_t main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0);

    CVacation solver;
    std::istream& in(std::cin);
    std::ostream& out(std::cout);
    solver.solve(in, out);
    return 0;
}

Measured memory_bytes: 4992
#include <iostream>

#include <vector>
#include <map>
#include <algorithm>
#include <fstream>
#include<cstdio>
#include<iomanip>
#include<stack>
#include<queue>

#define REP(i, n) for(int i=0;i<n;i++)
#define REP2(i, s, n) for(int i=s;i<n;i++)
#define REP_1(i, n) for(int i=1;i<n+1;i++)
#define bitSearch(bit, n) for(int bit = 0; bit < (1 << N); bit++)
using namespace std;

void printAns(long long a) { cout << a << endl; }

void yesno(bool a) { if (a)cout << "Yes" << endl; else cout << "No" << endl; }

void YESNO(bool a) { if (a)cout << "YES" << endl; else cout << "NO" << endl; }

typedef long long ll;
typedef unsigned long ul;
typedef long double ld;

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

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

//ll INF = 10000000;
//ll mod = 1000000007;//10^9+7

using Graph = vector<vector<pair<int, int>>>;

int color[100100];
Graph G(100100);

void dfs(int v, ll dis) {
    color[v] = dis % 2;
    for (auto next_v:G[v]) {
        if(color[next_v.first]==-1)
            dfs(next_v.first, dis + next_v.second);
    }
}



//番号ズレ注意！！
int main() {
    int N;
    cin >> N;
    REP(i, N - 1) {
        int from, to, length;
        cin >> from >> to >> length;
        G[from].push_back(make_pair(to, length));
        G[to].push_back(make_pair(from, length));
    }
    REP(i,N+1){
        color[i]=-1;
    }
    dfs(1, 0);
    REP_1(i, N) {
        cout << color[i] << endl;
    }
}


Measured memory_bytes: 7552
#include<cstdio>
using namespace std;
long long n,a,b;
int main()
{
  scanf("%lld%lld%lld",&n,&a,&b);
  if(n==1)  
  {
    if(a==b)  printf("1");
    else  printf("0");
  }
  else if(a>b)  printf("0");
  else  printf("%lld",(n-2)*b-(n-2)*a+1);
  return 0;
}

Measured memory_bytes: 128
#include <iostream>
#include <string>

using namespace std;

typedef long long ll;

int main()
{
  ll N;

  cin >> N;

  int tmp = N;
  int s = 0;

  while(tmp > 0 ) {
    s += tmp%10;
    tmp /= 10;
  }

  if ( N%s ) cout << "No\n";
  else cout << "Yes\n";
}


Measured memory_bytes: 3596
#include<bits/stdc++.h>
#define ll long long
using namespace std;
int main(){
	int t=1;
	//cin >> t;
	while(t--){
		vector<ll int> arr;
      	ll int i=0,n=0,z=0;
      cin >> n;
      	for(i=0;i<n;i++){
        	cin >> z;
          	arr.push_back(z);
        }
      //sort(arr.begin(),arr.end());
      z=0;
      for(i=0;i<n;i++){
        //if(arr[i]==arr[i-1]){continue;}
      	for(int j=i+1;j<n;j++){
          //if(arr[j]==arr[j-1]){continue;}
        	for(int k=j+1;k<n;k++){
              //if(arr[k]==arr[k-1]){continue;}
              	ll int p = min(arr[i],arr[j]);
              	p = min(p,arr[k]);
              	ll int q = max(arr[i],arr[j]);
              	q = max(q,arr[k]);
            	if(arr[i]+arr[j]+arr[k]-q>q&&arr[i]!=arr[j]&&arr[i]!=arr[k]&&arr[j]!=arr[k]){z++;}
            }
        }
      }
      cout << z << endl;
	}
}

Measured memory_bytes: 3628
#include <bits/stdc++.h>
using namespace std;
struct P
{
    //string r;
    int x,y,z;

    bool operator<(const P &a)const{
       // if(y!=a.y)
       // return y>a.y;
       return x>a.x;
//        return z>a.z;
    }
};

vector<int> v[55];
//bitset<4001000> b;
int a,c,i,b,k,n,m;//dy[15]={0,1,0,-1,-1,1,-1,1},dx[15]={1,0,-1,0,1,1,-1,-1};//
int l[1010];
int o[301000];
int dx[10]={0,1,0,-1,1,1,-1,-1},dy[10]={1,0,-1,0,-1,1,-1,1},dz[10]={0,0,0,0,1,-1};

long long x,y,z,mod=1000000007;
P u[1130],u1[1111];
int j[10];
stack<int> s;
//queue<int> q;
priority_queue<P> q;
//'1'==49;
//'A'==65;
//'a'==97;
//unordered_
//map<int,int > p;
//list<int> l;
string r,r2;
//char r[10];


bool as(P a,P b)
{
   // if(a.x!=b.x)
        return a.x<b.x;
    //return a.y>b.y;
}

int main()
{
    scanf("%d",&a);
    for(int t=1;t<=a;t++)
    {
        scanf("%d %d",&n,&m);
        q.push({n,m,0});
    }
        //scanf("%d %d",&u[t].x,&u[t].y);
    for(int t=1;t<=a;t++)
    {
        scanf("%d %d",&n,&m);
        q.push({n,m,1});
    }
    for(;q.size();q.pop())
    {
        //printf("%d ",q.top().x);
        if(q.top().z)
        {
            for(int t=q.top().y;t>=0;t--)
                if(o[t])
                {
                    o[t]--,k++;
                    break;
                }
        }
        else
        {
            o[q.top().y]=1;
        }
    }
    printf("%d",k);
        //scanf("%d %d",&u1[t].x,&u1[t].y);
    //sort(u+1,u+a+1,as);
    //sort(u1+1,u1+a+1,as);

}


Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <vector>

using namespace std;

typedef long long ll;

const ll M = 100000;
ll n;
vector<ll> ve[200005];
ll ans;
bool v[200005];
ll x, y;

void dfs(ll p)
{
    if(v[p]) return;
    v[p] = true;
    if(p > M) y++;
    else x++;
    for(ll i = 0; i < ve[p].size(); i++)
    {
        dfs(ve[p][i]);
    }
}

int main()
{
    scanf("%lld", &n);
    for(ll i = 0; i < n; i++)
    {
        ll t1, t2;
        scanf("%lld%lld", &t1, &t2);
        t2 += M;
        ve[t1].push_back(t2);
        ve[t2].push_back(t1);
    }
    for(ll i = 1; i <= 2 * M; i++)
    {
        if(!v[i]) x = y = 0, dfs(i), ans += x * y;
    }
    cout<<ans - n<<endl;
    return 0;
}


Measured memory_bytes: 10240
import java.util.Scanner;
import java.util.Arrays;
import java.util.TreeMap;
public class Main{
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int m = sc.nextInt();
		long[] a = new long[n];
		TreeMap<Long,Integer> map=new TreeMap<>();
		for(int i=0; i<n; i++){
			a[i]= sc.nextLong();
		}
		Arrays.sort(a);
		for(int i=0; i<m; i++){
			int b = sc.nextInt();
			long c = -sc.nextLong();
			if(map.containsKey(c)){
				map.put(c,b+map.get(c));
			}else{
				map.put(c,b);
			}
		}
		long ans=0;
		int i=0;
		for(long k:map.keySet()){
			int count=map.get(k);
			for(;i<n; i++){
				if(a[i]<-k){
					count--;
					a[i]=-k;
				}
				if(count==0){
					break;
				}
			}
		}
		for(i=0; i<n; i++){
			ans+=a[i];
		}
		System.out.println(ans);
	}
}


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

using namespace std;


int64_t func(int64_t hp)
{
    if(hp > 1){
        return 2*func(hp/2)+1;
    }
    else{
        return 1;
    }
}

int main(void)
{
    int64_t h;
    cin >> h;
    cout << func(h) << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#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(x) (x).begin(),(x).end()
#define rrng(x) (x).rbegin(),(x).rend()
#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 show(x) cout << #x << " = " << (x) << endl
#define show2(x,y) cout << #x << " = " << (x) << ", " << #y << " = " << (y) << endl
#define show3(x,y,z) cout << #x << " = " << (x) << ", " << #y << " = " << (y) <<  ", " << #z << " = " << (z) << endl
#define showv(v) rep(i,v.size()) printf("%d%c", v[i], i==v.size()-1?'\n':' ')
#define showv2(v) rep(j,v.size()) showv(v[j])
#define showt(t,n) rep(i,n) printf("%d%c", t[i], i==n-1?'\n':' ')
#define showt2(t,r,c) rep(j,r) showt(t[j],c)
#define showvp(p) rep(i,p.size()) printf("%d %d\n", p[i].first, p[i].second);
#define printv(v) rep(i,v.size()) printf("%d\n", v[i])
#define printt(t,n) rep(i,n) printf("%d\n", t[i])
#define incl(v,x) find(rng(v),x)!=v.end()
#define incls(s,c) s.find(c)!=string::npos
#define fi first
#define se second
#define pb push_back
#define eb emplace_back
#define sz(x) (int)(x).size()
#define pcnt __builtin_popcountll
#define bit(n,k) ((n>>k)&1) // nのk bit目
#define bn(x) ((1<<x)-1)
#define dup(x,y) (((x)+(y)-1)/(y))
#define newline puts("")
#define uni(x) x.erase(unique(rng(x)),x.end())
#define SP << " " <<
#define v(T) vector<T>
#define vv(T) v(v(T))
using namespace std;
using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vl = vector<ll>;
using vs = vector<string>;
using P = pair<int, int>;
using T = tuple<int, int, int>;
using vp = vector<P>;
using vt = vector<T>;
const int mod = 1000000007;
const double EPS = 1e-9;
//const long double EPS = 1e-14;
const int INF = (1<<30)-1;
const ll LINF = (1LL<<62)-1;
#define dame { puts("No"); return 0;}
#define yn {puts("Yes");}else{puts("No");}
inline int in() { int x; scanf("%d",&x); return x;}
//template<class T = int> inline T in() { T x; cin >> x; return (x);}
template<typename T>inline ll suma(const v(T)& a) { ll res(0); for (auto&& x : a) res += x; return res;}
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; }
char itoa(int n) { return n + '0';}
ll gcd(ll a, ll b) { return b ? gcd(b,a%b) : a;}
ll lcm(ll a, ll b) { return a/gcd(a,b)*b;}

int main () {
  while(1) {
    int a, b;
    char op;
    cin >> a >> op >> b;
    if (op == '?') break;
    if (op == '+') printf("%d\n", a+b);
    if (op == '-') printf("%d\n", a-b);
    if (op == '*') printf("%d\n", a*b);
    if (op == '/') printf("%d\n", a/b);
  }
  return 0;
}


Measured memory_bytes: 3216
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int N, K;
  string S;
  cin >> N >> K >> S;
  
  string result = "";
  for(int i = 0; i < N; i++){
    if(i == K - 1){
      char lowStr = S[i] + 0x20;
      
      result = result + lowStr;
    }
    else{
      result = result + S[i];
    }
  }
  
  cout << result << endl;
}

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

#define MP make_pair
#define PB push_back
#define ALL(x)      (x).begin(),(x).end()
#define REP(i,n)    for(int i=0;i<(n);i++)
#define REP1(i,n)   for(int i=1;i<(n);i++)
#define REP2(i,d,n) for(int i=(d);i<(n);i++)
#define RREP(i,n)   for(int i=(n);i>=0;i--)
#define CLR(a)      memset((a),0,sizeof(a))
#define MCLR(a)     memset((a),-1,sizeof(a))
#define RANGE(x,y,maxX,maxY) (0 <= (x) && 0 <= (y) && (x) < (maxX) && (y) < (maxY))

typedef long long LL;
typedef unsigned long long ULL;
typedef vector<int> VI;
typedef vector<VI > VVI;
typedef vector<string> VS;
typedef vector<LL> VLL;
typedef pair<int,int> PII;

const int INF = 0x3f3f3f3f;
const LL INFL = 0x3f3f3f3f3f3f3f3fLL;
const double EPS = 1e-9;

const int DX[]={1,0,-1,0},DY[]={0,-1,0,1};


void solve(long long A, long long B){
    cout << (A <= B+B ? 0 : A - B - B) << endl;
}

int main(){
    long long A;
    scanf("%lld",&A);
    long long B;
    scanf("%lld",&B);
    solve(A, B);
    return 0;
}


Measured memory_bytes: 256
import sys
import math


inint = lambda: int(sys.stdin.readline())
inintm = lambda: map(int, sys.stdin.readline().split())
inintl = lambda: list(inintm())
instr = lambda: sys.stdin.readline()
instrm = lambda: map(str, sys.stdin.readline().split())
instrl = lambda: list(instrm())

x = inint()

def isPrime(n):
    if n == 1:
        return False
    if n == 2:
        return True
    if n % 2 == 0:
        return False
    m = math.floor(math.sqrt(n)) + 1
    for p in range(3, m, 2):
        if n % p == 0:
            return False
    return True


for i in range(1,10**6):
    bool = isPrime(i)
    if bool and i >= x:
        print(i)
        break


Measured memory_bytes: 74444
import java.util.List;
import java.util.Scanner;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Set;
import java.util.Map;
import java.util.HashMap;
import javax.swing.text.DefaultStyledDocument.ElementSpec;

import java.util.HashSet;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int count = 0;
        int n = sc.nextInt();
        System.out.println((int) Math.pow(n, 3));
    }
}

Measured memory_bytes: 23380
/*
  Author : Vikram Singh
  Goal   : Want to become RED on codeforces
  from   : Bharat
*/

#include<bits/stdc++.h>

using namespace std;


typedef long long ll;
typedef long double ld;
typedef complex<ld> cd;

typedef pair<int, int> pi;
typedef pair<ll, ll> pl;
typedef pair<ld, ld> pd;

typedef vector<int> vi;
typedef vector<ld > vd;
typedef vector<ll > vl;
typedef vector<pi >  vpi;
typedef vector<pl > vpl;
typedef vector<cd > vcd;


#define FOR(i, a, b) for(int i = (a); i< (b);i++)
#define F0R(i, a)    for(int i=0;i<(a);i++)
#define FORd(i, a, b) for(int i = (b) - 1; i>=(a);--i)
#define F0Rd(i, a)   for(int i = (a) - 1;i>=0;--i)
#define trav(p, x)  for(auto& p : x)

#define mp make_pair
#define pb push_back
#define fi first
#define se second
#define lb lower_bound
#define ub upper_bound

#define sz(x) (int)x.size()
#define beg(x) x.begin()
#define en(x) x.end()
#define all(x) beg(x), en(x)
#define resz resize

const int MOD = 1000000007;
const ll INF = 1e18;
const int MX = 205;
const int MAX = 500 * 1000 + 11; 
const ld PI = 4*atan((ld)1);


int main(){
	ios::sync_with_stdio(false);
    cin.tie(0);
    int n,k;
    cin>>n>>k;
    string s;
    cin>>s;
    
    int z = 0,o = 0;
    int ans = 0;
    vector<pair<int, int> >a;
    for(int i=0;i<n;i++){
    	if(s[i] == '0') z++;
    	else o++;
    	
    	if(z != 0 && o != 0){
    		if(s[i-1] == '0'){
    			a.push_back({z,0});
    		}
    		else{
    			a.push_back({o,1});
    			ans = max(ans, o);
    		}
    		z = o = 0;
    		--i;
    	}
    }
    if(z != 0) a.push_back({z, 0});
    if(o != 0) a.push_back({o, 1});
    ans = max(ans, o);
     
    // cout<<"print the array :"<<"\n";
    // for(int i=0;i<a.size();i++){
    // 	cout<<a[i].fi<<" "<<a[i].se<<"\n";
    	
    // }
    //cout<<endl;
    
    vector<int >zero;
    for(int i=0;i<a.size();i++){
    	if(a[i].se == 0) zero.push_back(i);
    }
    //cout<<"print all zero : \n";
    //for(int i=0;i<zero.size();i++) cout<<zero[i]<<" ";
    //cout<<endl;
    for(int i=0;i<zero.size();i++){
    	int start  = zero[i];
    	int end;
    	if(i+k-1 > zero.size()-1) end = zero[zero.size()-1];
    	else end = zero[i+k-1];
    	if(start > 0) start--;
    	if(end < (int)a.size()-1) end++;
    //	cout<<"start and end is : "<<start <<" "<<end<<"\n";
    	int cnt = 0;
    	for(int j = start; j<=end;j++) cnt+=a[j].fi;
    	ans = max(ans, cnt);
    }
    
    cout<<ans<<"\n";
	return 0;
}

Measured memory_bytes: 1604
#include <bits/stdc++.h>
using namespace std;
#define MOD 1000000007
#define INF 10000000000000009
//#define INF 9223372036854775807
typedef long long ll;
#define REP(i,n) for(int i=0;i<(n);++i)
#define OREP(i,n) for(int i=1;i<=(n);++i)
#define ORREP(i,n) for(int i=(n);i>=1;--i)
#define ZREP(i,n) for(int i=1;i<(n);++i)
#define RREP(i,n) for(int i=(n)-1;i>=0;--i)
#define rollcall cout<<"I'm Sucu."<<endl;
#define YES(s) s?cout << "YES" << endl:cout << "NO" << endl
#define Yes(s) s?cout << "Yes" << endl:cout << "No" << endl
#define Taka(s) s?cout << "Takahashi" << endl:cout << "Aoki" << endl
#define out(s,t,u) s?cout << t << endl:cout << u << endl
#define int ll
#define Endl endl


signed main(){
    int A,B;
    cin >> A >> B;
    if(B%A==0){
        cout << A+B << endl;
    }else{
        cout << B-A << endl;
    }
    return 0;
}

Measured memory_bytes: 764
nCombination [n, s] = length . filter (sumEq s) $ combinations n [0..9]
  where sumEq s ls = s == sum ls

main = do
  s <- getLine
  if s == "0 0"
     then return ()
     else do print . nCombination . map read . words $ s
             main

-- all combinations of distinct n elements of list xs.
-- cited from: http://www.geocities.jp/m_hiroi/func/haskell06.html
combinations :: Int -> [a] -> [[a]]
combinations n xs = comb n (length xs) xs
  where
    comb r n (y : ys)
      | r == 0    = [[]]
      | r >= n    = [y : ys]
      | otherwise = map (y :) (comb (r - 1) (n - 1) ys) ++ comb r (n - 1) ys

Measured memory_bytes: 3980
#include <iostream>
#include <algorithm>
#include <string>
#include <cstring>
#include <map>
#include <set>
#include <deque>
#include <queue>
#include <vector>
#include <cstdio>
#include <cstdlib>
#include <bits/stdc++.h>
#define PI acos(-1)
#define fs first
#define sc second
#define debug freopen("1.in","r",stdin),freopen("1.out","w",stdout);
#define ios ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
const ll maxn = 1e6 + 10;
const ll mod = 998244353;

int n, arr[maxn];
ll ans = 1;
ll mul(ll x,ll y,ll z)
{
    return x * y % z;
}
ll qpow(ll m, ll k, ll p){
    ll res = 1 % p;
    while (k){
        if (k&1) res = res * m % p;
        m = m * m % p;
        k >>= 1;
    }
    return res;
}

int main(){
    ios;
    cin >> n;
    cin >> arr[1];
    if (arr[1] != 0){
        cout << 0;
        return 0;
    }
    for (int i = 2; i <= n; i ++){
        cin >> arr[i];
        if (arr[i] == 0){
            cout << 0;
            return 0;
        }
    }
    sort(arr + 1, arr + 1 + n);
    ll tmp = 1, tmpp = 1;
    for (int i = 2 ; i <= n; i ++){
        if (arr[i] - arr[i - 1] != 1 && arr[i] - arr[i - 1] != 0){
            cout << 0;
            return 0;
        }
        if (arr[i] == arr[i + 1])
            tmpp ++;
        else{
            ans = mul(ans, qpow(tmp, tmpp, mod), mod);
            tmp = tmpp;
            tmpp = 1;
        }
    }
    cout << ans;

    return 0;
}

Measured memory_bytes: 640
#include<iostream>
using namespace std;
int u[16][16];
int r[16][16];
int mp[16][16];
int gx,gy;
int rec(int x,int y){
  if(mp[x][y]!=-1)return mp[x][y];
  if(x==0){
    mp[x][y]=u[x][y-1]*rec(x,y-1);
  }else if(y==0){
    mp[x][y]=r[x-1][y]*rec(x-1,y);
  }else{
    mp[x][y]=u[x][y-1]*rec(x,y-1)+r[x-1][y]*rec(x-1,y);
  }
  return mp[x][y];
}
int main(){
  int t;
  cin>>t;
  while(t--){
    for(int i=0;i<16;i++){
      for(int j=0;j<16;j++){
        u[i][j]=1;r[i][j]=1;
        mp[i][j]=-1;
      }
    }
    mp[0][0]=1;
    cin>>gx>>gy;
    double p;
    cin>>p;
    while(p--){
      int a,b,c,d;
      cin>>a>>b>>c>>d;
      if(a==c){
        u[a][min(b,d)]=0;
      }else{
        r[min(a,c)][b]=0;
      }
    }
    if(rec(gx,gy)!=0){
      cout<<rec(gx,gy)<<endl;
    }else{
      cout<<"Miserable Hokusai!"<<endl;
    }
  }
}

Measured memory_bytes: 1232
#include<bits/stdc++.h>
#define rep(i,m) for(long long i=0; i<m; i++)
#define per(i,m) for(long long i=m-1; i>=0; i--)
#define FOR(i,n,m) for(long long i=n; i<m; i++)
#define ROF(i,n,m) for(long long i=n-1; i>=m; i--)
#define all(x) (x).begin(),(x).end()
#define EPS (1e-7)
#define INF (1e18)
#define PI (acos(-1))
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;
using namespace std;
typedef long long ll;
const ll MOD = 1000000007;
typedef pair<ll, ll> LP;

ll POW(ll x,ll n){
  if(n==0)return 1;
  if(n%2==0)return POW(x*x%MOD,n/2);
  return x*POW(x,n-1)%MOD;
}

ll gcd(ll u, ll v) {
  ll r;
  while (0 != v) {
    r = u % v; u = v; v = r;
  }
  return u;
}
 
ll KAI(ll m)
{
  if(m<0) return 0;
  if(m==0) return 1;
  return m*KAI(m-1)%MOD;
}
 
ll extGCD(ll a, ll b, ll &x, ll &y) {
    if (b == 0) {
        x = 1;
        y = 0;
        return a;
    }
    ll d = extGCD(b, a%b, y, x);
    y -= a / b * x;
    return d;
}
 
inline ll mod(ll a, ll m) {
    return (a % m + m) % m;
}
 
ll modinv(ll a) {
    ll x, y;
    extGCD(a, MOD, x, y);
    return mod(x, MOD);
}
 
ll COM(ll m,ll n)
{
  if(m<n) return 0;
  if(n<0) return 0;
  if(n==0) return 1;
  if(m==n) return 1;
  return KAI(m)%MOD*modinv(KAI(n)%MOD*KAI(m-n)%MOD)%MOD;
}

ll DEC(ll x,ll m,ll n)
{
  return x%POW(m,n+1)/POW(m,n);
}

ll keta(ll x,ll n)
{
  if(x==0)return 0;
  return keta(x/n,n)+1;
}

ll DIV(ll x,ll n)
{
  if(x==0)return 0;
  return x/n+DIV(x/n,n);
}


int main()
{
  ll a,ans;
  cin >> a;
  ans=0;
  if(a==1||a==2)printf("4");
  else{
  while(a>0)
  {
    if(a==4)break;
    if(a%2==1){a=a*3+1;
               ans++;
              }
    else {a/=2;
          ans++;
         }
  }
  printf("%lld",ans+4);
  }
}


Measured memory_bytes: 256
s = list(input())
if s[0] == s[1] and s[2] == s[3] and s[0] != s[2]:
  print('Yes')
elif s[0] == s[3] and s[1] == s[2] and s[0] != s[1]:
  print('Yes')
elif s[0] == s[2] and s[1] == s[3] and s[0] != s[1]:
  print('Yes')
else:
  print('No')

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

using namespace std;

#define countof(a) (sizeof(a)/sizeof(*a))

#define vi vector<int>
#define vvi vector<vector<int> >
#define vpi vector<pi >
#define pi pair<int,int>
#define mp make_pair
#define fi first
#define se second
#define all(n) n.begin(), n.end()

#define FROMTO(var, from, to) for (register int var = (from), var##down = ((int)(to)) < ((int)(from));var##down ? (var >= (int)(to)) : (var <= (int)(to));var##down ? var-- : var++)
#define UPTO(var, from, to)   for (register int var = (from); var <= ((int)to); var++)
#define DOWNTO(var, from, to) for (register int var = (from); var >= ((int)to); var--)
#define FOR(var, to)          UPTO(var, 0, (to)-1)
#define DOWN(var, from)       DOWNTO(var, (from)-1, 0) 

#define INIT(var, val) FOR(i,countof(var)) var[i] = val
#define INPUT(var) FOR(i,countof(var)) cin >> var[i]
#define INPUT1(var) FOR(i,countof(var)) cin >> var[i], var[i]--

#define SORT(v) qsort(v,countof(v),sizeof(*v),int_less)
#define SORTT(v) qsort(v,countof(v),sizeof(*v),int_greater)
#define QSORT(v,b) qsort(v,countof(v),sizeof(*v),b)

#define MOD 1000000007
#define INF ((1 << 30)-1)
#define LINF ((1LL << 62)-1)

typedef uint8_t u8;
typedef uint16_t u16;
typedef uint32_t u32;
typedef uint64_t u64;
typedef int8_t s8;
typedef int16_t s16;
typedef int32_t s32;
typedef int64_t s64;

struct Comb {
    vector<vector<s64> > data;
    Comb(int n) { // O(n^2)
        data = vector<vector<s64> >(n+1,vector<s64>(n+1,1));
        UPTO(i,1,n) {
            FOR(j,i+1) {
                if (!j || j == i) data[i][j] = 1;
                else data[i][j] = data[i-1][j-1] + data[i-1][j];
            }
        }
    }
    
    s64 ncr(int n, int r) {
        return data[n][r];
    }
};

static inline int ri() {
  int a;
  scanf("%d", &a);
  return a;
}

int int_less(const void *a, const void *b) {
  return (*((const int*)a) - *((const int*)b));
}
int int_greater(const void *a, const void *b) {
  return (*((const int*)b) - *((const int*)a));
}

int main() {
    int n = ri();
	int a[n];
	INPUT(a);
	bool res = true;
	FOR(i,n) if (a[i]%2) res = false;
	cout << (!res ? "first" : "second") << endl;
    return 0;
}


Measured memory_bytes: 640
def main():
    S = input()
    u = 0
    H = [0] * 2019
    H[0] = 1
    m = 1
    r = 0
    for s in reversed(S):
        u = (u + m * int(s)) % 2019
        r += H[u]
        H[u] += 1
        m = (m * 10) % 2019
    return r


print(main())


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

#define all(A) begin(A), end(A)
#define sz(A) int(A.size())

using namespace std;

typedef long long ll;

const int MOD = 1e9 + 7, MAX_N = 110;

inline int add (ll a, ll b) { return (a + b) % MOD; }
inline int mul (ll a, ll b) { return (a * b) % MOD; }

int n;
int dp[MAX_N][7][7][7];

const int A = 1;
const int C = 2;
const int G = 3;
const int T = 4;
int rec (int pos, int c1, int c2, int c3) {
  if (pos == n) return 1;
  int& ret = dp[pos][c1][c2][c3];
  if (ret != -1) return ret;
  ret = 0;
  for (int c: {1, 2, 3, 4}) {
    if (c2 == A and c3 == G and c == C) continue; 
    if (c2 == A and c3 == C and c == G) continue;
    if (c2 == G and c3 == A and c == C) continue;
    if (c1 == A and c2 == G and c == C) continue;
    if (c1 == A and c3 == G and c == C) continue;
    ret = add(ret, rec(pos + 1, c2, c3, c));
  }
  return ret;
}

int main () {
  ios::sync_with_stdio(false); cin.tie(0);
  cin >> n;
  memset(dp, -1, sizeof dp);
  cout << rec(0, 0, 0, 0) << endl;
  return (0);
}


Measured memory_bytes: 384
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <ctime>
#include <cassert>
#include <iostream>
#include <cctype>
#include <sstream>
#include <string>
#include <list>
#include <vector>
#include <queue>
#include <set>
#include <stack>
#include <map>
#include <utility>
#include <numeric>
#include <algorithm>
#include <iterator>
#include <bitset>
#include <complex>
#include <fstream>
using namespace std;
typedef long long ll;
const double EPS = 1e-9;
typedef vector<int> vint;
typedef pair<int, int> pint;
#define rep(i, n) REP(i, 0, n)
#define ALL(v) v.begin(), v.end()
#define MSG(a) cout << #a << " " << a << endl;
#define REP(i, x, n) for(int i = x; i < n; i++)
template<class T> T RoundOff(T a){ return int(a+.5-(a<0)); }
template<class T, class C> void chmax(T& a, C b){ if(a < b) a = b; }
template<class T, class C> void chmin(T& a, C b){ if(b < a) a = b; }
template<class T, class C> pair<T, C> mp(T a, C b){ return make_pair(a, b); }

typedef complex<double> P;
struct Circle
{
	P p;
	double r;
};

// OÏ
double cross(P a, P b)
{	return a.real() * b.imag() - b.real() * a.imag();	}

// àÏ
double dot(P a, P b)
{	return a.real() * b.real() + a.imag() * b.imag();	}

// _ÆüªÌ£
double dist(P a, P b, P c)
{
	if(dot(b - a, c - a) < EPS) return abs(c - a);
	if(dot(a - b, c - b) < EPS) return abs(c - b);
	
	return abs(cross(b - a, c - a)) / abs(b - a);
}

bool Hit(Circle c, P a, P b)
{
	return dist(a, b, c.p) <= c.r;
}

bool isInCircle(Circle c, P x)
{
	return abs(c.p - x) < c.r;
}

int main()
{
    int n, m;
	while(cin >> n && n)
	{		
		vector<Circle> circle(n);
		rep(i, n) cin >> circle[i].p.real() >> circle[i].p.imag() >> circle[i].r;
		
		cin >> m;
		while(m--)
		{
			P t, s;
			cin >> t.real() >> t.imag() >> s.real() >> s.imag();
			
			rep(i, n)
			{
				if(Hit(circle[i], t, s) && !(isInCircle(circle[i], t) && isInCircle(circle[i], s)))
				{
					cout << "Safe" << endl;
					break;
				}
				else if(i + 1 == n)
				{
					cout << "Danger" << endl;
				}
			}
		}
	}
}

Measured memory_bytes: 0
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i = 0; i < (n);i++)
#define sz(x) int(x.size())
typedef long long ll;
typedef long double ld;
typedef pair<int,int> P;
constexpr int INF = 2e9;
constexpr int mod = 1e9 + 7;

int main(){ 
  int h, w, k;
  cin >> h >> w >> k;
  vector<string> s(h);
  rep(i,h) cin >> s[i];
  int res = 0;

  for (int bit1 = 0; bit1 < (1 << h); bit1++) {

    for (int bit2 = 0; bit2 < (1 << w); bit2++) {

      auto tmp = s;

      for (int i = 0; i < h; i++) {
        if (bit1 & (1 << i)) {
          for (int j = 0; j < w; j++) tmp[i][j] = 'x';
        }
      }

      for (int i = 0; i < w; i++) {
        if (bit2 & (1 << i)) {
          for (int j = 0; j < h; j++) tmp[j][i] = 'x';
        }
      }

      int ret = 0;

      for (int i = 0; i < h; i++) {
        for (int j = 0; j < w; j++) ret += (tmp[i][j] == '#');
      }

      if (ret == k) res++;
    }
  }

  cout << res << endl;
  return 0;
} 

Measured memory_bytes: 3636
import java.util.*;
 
public class Main {
    public static void main(String[] args) throws Exception {    
    Scanner scanner = new Scanner(System.in);
    
    int a = scanner.nextInt();
    int b = scanner.nextInt();
      
    if (a*b%2 == 0){
      System.out.println("Even");
    } else {
      System.out.println("Odd");
    }
    
    scanner.close();
    
  }
}

Measured memory_bytes: 23764
import scala.math._

// longでrangeの作り方

object Main extends App {

  val YES = "YES"
  val Yes = "Yes"
  val NO = "NO"
  val No = "No"
  ///////////////////////////////////////////

  val sc = new java.util.Scanner(System.in)
  val a, b = sc.next
//  val list = List.fill(3)(sc.next)

  val ans = if ((a == "H" && b == "H") || a == "D" && b == "D") "H" else "D"

  println(ans)


  ///////////////////////////////////////////

  def bigIterator(start: BigInt, end: BigInt, step: BigInt = 1) =
    Iterator.iterate(start)(_ + step).takeWhile(_ <= end)

  def lcm(a :Int, b :Int): Int =
    a / gcd(a, b) * b

  def lcm(a :Long, b :Long): Long =
    a / gcd(a, b) * b

  def gcd(a: Int, b: Int): Int =
    if (b == 0) a else gcd(b, a % b)

  def gcd(a: Long, b: Long): Long =
    if (b == 0) a else gcd(b, a % b)

  def setOrUpdated[A, B](a: Map[A, B], key: A, value: B, f: (B, B) => B) =
    a.get(key) match {
      case Some(v) => a.updated(key, f(value, v))
      case _ => a + (key -> value)
    }
}

Measured memory_bytes: 25404
#include<bits/stdc++.h>
#define FIO ios_base::sync_with_stdio(false);cin.tie(NULL);
typedef long long ll;

using namespace std;

int solve(int arr[],int n)
{
	int i,j,ans;
    int dp[n];
    memset(dp,0,sizeof(dp));
    dp[1]=abs(arr[1]-arr[0]);
    for(i=2;i<n+1;i++)
    {
        dp[i]=min(dp[i-1]+abs(arr[i]-arr[i-1]),dp[i-2]+abs(arr[i]-arr[i-2]));
    }
   
    return dp[n-1];
}

int main()
{
	FIO
	
		int n;
		cin>>n;
        int arr[n];
        for(int i=0;i<n;i++)cin>>arr[i];
		cout<<solve(arr,n);
	

}

Measured memory_bytes: 4356
#include<stdio.h>

int n, A[20];

int solve(i, m){
    int res;
    if(m == 0){
        return 1;
    }
    if(i >= n){
        return 0;
    }
    res = solve(i + 1, m) || solve(i + 1, m - A[i]);   /*いづれかが1をとると終了*/
}

int main(){
    int i, q, m[200];
    
    scanf("%d", &n);
    for (i = 0; i < n; i++){
        scanf("%d", &A[i]);
    }
    scanf("%d", &q);
    for (i = 0; i < q; i++){
        scanf("%d", &m[i]);
    }
    for (i = 0; i < q; i++){
        if(solve(0, m[i]) == 1){
            printf("yes\n");
        } else {
            printf("no\n");
        }
    }
    
    return 0;
}


Measured memory_bytes: 1928