akhauriyash/Code-Regression huggingface dataset:
#include<stdio.h>
int main(void){
  int i;
  int j;
  int h[1000];
  int m[1000];
  int k[1000];
  int g[1000];
  int a[1000];
  int b[1000];
  int N;
  int M;

  

  scanf("%d",&N);
  for(i=0;i<N;i++){
    scanf("%d",&h[i]);
    scanf("%d",&m[i]);
    a[i]=100*h[i]+m[i];
  }

  scanf("%d",&M);
  for(j=0;j<M;j++){
    scanf("%d",&k[j]);
    scanf("%d",&g[j]);
    b[j]=100*k[j]+g[j];
  }

  //for(i=0;i<N;i++){
  /*   printf("%d ",a[i]); */
  /* } */
  /* printf("\n"); */
  /* for(i=0;i<M;i++){ */
  /*   printf("%d ",b[i]); */
  /* } */
  /* printf("\n"); */
  /* return 0; */
  i=0;
  j=0;
  a[N] = 10000;
  b[M] = 10000;
  while(a[i]!=10000|| b[j]!=10000){
    if(i >= N && j >= M) break;  
    if(a[i]==b[j]){
      printf("%d:%02d",a[i]/100,a[i]%100);
      i++; j++;
    }else if(a[i]<b[j]){
      printf("%d:%02d",a[i]/100,a[i]%100);
      i++;
    }else{
      printf("%d:%02d",b[j]/100,b[j]%100);
      j++;
    }
    if(a[i]!=10000 || b[j]!=10000)
      printf(" ");
  }
  printf("\n");
  return 0;
}

Measured memory_bytes: 640
// #pragma comment(linker, "/stack:200000000")
// #pragma GCC optimize("Ofast,no-stack-protector")
// #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,avx2,tune=native")
// #pragma GCC optimize("unroll-loops")

#include <bits/stdc++.h>

#ifdef PERVEEVM_LOCAL
    #define debug(x) std::cerr << (#x) << ":\t" << (x) << std::endl
#else
    #define debug(x) 238;
#endif

#define fastIO std::ios_base::sync_with_stdio(false); std::cin.tie(0); std::cout.tie(0)
#define NAME "File"

using ll = long long;
using ld = long double;

#ifdef PERVEEVM_LOCAL
    std::mt19937 rnd(238);
#else
    std::mt19937 rnd(std::chrono::high_resolution_clock::now().time_since_epoch().count());
#endif

const double PI = atan2(0.0, -1.0);
const int INF = 0x3f3f3f3f;
const ll LINF = (ll)2e18;
const int N = 10100;
const int MOD = (int)1e9 + 7;

int add(int a, int b, int mod = MOD) {
    if (a + b >= mod) {
        return a + b - mod;
    }
    return a + b;
}

int sub(int a, int b, int mod = MOD) {
    if (a - b < 0) {
        return a - b + mod;
    }
    return a - b;
}

int mul(int a, int b, int mod = MOD) {
    return (int)(1ll * a * b % mod);
}

int binpow(int a, int n, int mod = MOD) {
    if (n == 0) {
        return 1;
    }
    if (n % 2 == 0) {
        return binpow(mul(a, a, mod), n / 2, mod);
    } else {
        return mul(binpow(a, n - 1, mod), a, mod);
    }
}

int rev(int a, int mod = MOD) {
    return binpow(a, mod - 2, mod);
}

char s[N];
int dp[N][110][2];

// 0 - all equal
// 1 - has less

void run() {
    int n;
    scanf("%s\n%d", s, &n);

    dp[0][0][0] = 1;
    int l = strlen(s);
    for (int i = 1; i <= l; ++i) {
        for (int dig = 0; dig <= 9; ++dig) {
            for (int from = 0; from < n; ++from) {
                int to = (from + dig) % n;

                dp[i][to][1] = add(dp[i][to][1], dp[i - 1][from][1]);

                if (dig < s[i - 1] - '0') {
                    dp[i][to][1] = add(dp[i][to][1], dp[i - 1][from][0]);
                }
                if (dig == s[i - 1] - '0') {
                    dp[i][to][0] = add(dp[i][to][0], dp[i - 1][from][0]);
                }
            }
        }
        // for (int dig = 0; dig <= s[i - 1] - '0'; ++dig) {
        //     for (int from = 0; from < n; ++from) {
        //         int to = from + dig;
        //         if (to >= n) {
        //             to -= n;
        //         }

        //         dp[i][to] = add(dp[i][to], dp[i - 1][from]);
        //     }
        // }
    }

    printf("%d\n", sub(add(dp[l][0][0], dp[l][0][1]), 1));
}

int main(void) {
    // freopen(NAME".in", "r", stdin);
    // freopen(NAME".out", "w", stdout);

    auto start = std::chrono::high_resolution_clock::now();
    run();
    auto end = std::chrono::high_resolution_clock::now();

    #ifdef PERVEEVM_LOCAL
        std::cerr << "Execution time: "
                  << std::chrono::duration_cast<std::chrono::milliseconds>(end - start).count()
                  << " ms" << std::endl;
    #endif

    return 0;
}


Measured memory_bytes: 8832
import scala.math._

object Main {
  val sc = new java.util.Scanner(System.in)
  def main(args: Array[String]) {
    val n = sc.nextInt()
    val a = Array.ofDim[Int](3, n)
    for(i <- 0 until n; j <- 0 until 3) {
      a(j)(i) = sc.nextInt()
    }
    val p = (for(i <- 0 until 3) yield {
      val g = a(i).zipWithIndex.groupBy(x => x._1)
      (for(j <- 0 until n) yield {
        if(g(a(i)(j)).size == 1) {
          a(i)(j)
        } else {
          0
        }
      }).toArray
    }).toArray
    for(i <- 0 until n) {
      println(p(0)(i) + p(1)(i) + p(2)(i))
    }
  }
}

Measured memory_bytes: 47404
#include <stdio.h>
#include <string.h>
#include <algorithm>
#include <queue>
#include <math.h>
#define rep(i,st,ed) for (int i=st;i<=ed;++i)
#define fill(x,t) memset(x,t,sizeof(x))

typedef long long LL;
const int MOD=1000000007;
const int N=2000005;

int f[N],s[N],a[N],b[N];

int read() {
	int x=0,v=1; char ch=getchar();
	for (;ch<'0'||ch>'9';v=(ch=='-')?(-1):(v),ch=getchar());
	for (;ch<='9'&&ch>='0';x=x*10+ch-'0',ch=getchar());
	return x*v;
}

int main(void) {
	int n; scanf("%d",&n);
	rep(i,1,n) scanf("%d",&a[i]);
	for (int i=1,j;i<=n;) {
		j=i;
		while (a[j]==a[j+1]) j++;
		b[++b[0]]=a[j];
		i=j+1;
	}
	f[0]=1;
	s[b[1]]=1;
	rep(i,1,b[0]) {
		f[i]=s[b[i]];
		s[b[i+1]]=(s[b[i+1]]+f[i])%MOD;
	}
	printf("%d\n", f[b[0]]);
	return 0;
}

Measured memory_bytes: 11136
#include <algorithm>
#include <cmath>
#include <iostream>

int main() {
	int A, B, C;
	std::cin >> A >> B >> C;
	
	int K;
	std::cin >> K;

	int max = std::max(A, B);
	max = std::max(max, C);
	int newMax = max * std::pow(2, K);

	int sum = (A + B + C) - max + newMax;
	std::cout << sum << std::endl;

	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
template <typename T> void read(T &t) {
	t=0; char ch=getchar(); int f=1;
	while (ch<'0'||ch>'9') { if (ch=='-') f=-1; ch=getchar(); }
	do { (t*=10)+=ch-'0'; ch=getchar(); } while ('0'<=ch&&ch<='9'); t*=f;
}
const int maxn=(1e5)+10;
int n,a[maxn],cur;
int d[maxn],cnt[maxn];
int l[maxn],r[maxn];
bool vis[maxn];
void dfs(int x,int lst) {
	if (x>n) {
		for (int i=1;i<=n;i++)
			printf("%d ",d[i]);
		printf("\n");
		exit(0);
	}
	if (!vis[lst]&&cnt[lst]==n-x) return;
	int pos=cur;
	for (int i=1;i<=n-x+1;i++) {
		d[x]=pos;
		if (pos!=lst) {
			r[l[pos]]=r[pos];
			l[r[pos]]=l[pos];
			vis[pos]=1;
			if (pos==cur) cur=r[pos];
			cnt[a[pos]]--;
			dfs(x+1,a[pos]);
			cnt[a[pos]]++;
			if (r[pos]==cur) cur=pos;
			vis[pos]=0;
			r[l[pos]]=pos;
			l[r[pos]]=pos;
		}
		pos=r[pos];
	}
}
int main() {
	//freopen("1.txt","r",stdin);
	read(n);
	for (int i=1;i<=n;i++) read(a[i]),cnt[a[i]]++;
	for (int i=2;i<=n;i++) l[i]=i-1;
	for (int i=1;i<n;i++) r[i]=i+1;
	cur=1; dfs(1,0);	
	printf("-1\n");
	return 0;
}
/*
  REMEMBER:
  1. Think TWICE, Code ONCE!
  Are there any counterexamples to your algo?
    
  2. Be careful about the BOUNDARIES!
  N=1? P=1? Something about 0?
    
  3. Do not make STUPID MISTAKES!
  Array size? Integer overflow? Time complexity? Memory usage? Precision error?
*/

Measured memory_bytes: 10624
#include "bits/stdc++.h"
using namespace std;
using ll = long long;
using Pii = pair<int, int>;
using Pll = pair<ll, ll>;
#define rep(i, begin, n) for (int i = begin; i < n; i++)
#define repe(i, begin, n) for (int i = begin; i <= n; i++)
#define repr(i, begin, n) for (int i = begin; i > begin - n; i--)
#define repre(i, begin, end) for (int i = begin; i >= end; i--)

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;
}

const int inf = 1000000007;
const int MOD = 1000000007;
const long long INF = 1000000000000000007;

// -------------------------------------------------------

int A, B;

int main() {
  cin >> A >> B;
  if (A % 3 == 0 || B % 3 == 0 || (A + B) % 3 == 0) {
    cout << "Possible";
  } else {
    cout << "Impossible";
  }
}


Measured memory_bytes: 3536
#include<bits/stdc++.h>
#include<tr1/unordered_map>
using namespace std;
#define ll long long
#define fr first
#define se second
#define fi(i,s,e,inc) for(auto i=s; i<e; i+=inc)
#define fie(i,s,e,inc) for(auto i=s; i<=e; i+=inc)
#define fd(i,s,e,dec) for(auto i=s; i>e; i-=dec)
#define fde(i,s,e,dec) for(auto i=s; i>=e; i-=dec)
#define umap tr1::unordered_map
#define nl cout<<"\n";
#define vt vector
#define pb push_back
#define pr(x) cout<<x;
#define ps(x) cout<<x<<" ";
#define sp cout<<" ";
#define mod 1000000007
#define all(x) x.begin(),x.end()
#define rev reverse
#define tc ll t; cin>>t; while(t--)
#define pq priority_queue
ll a[100005];
ll n;
ll dp[100005];
ll solve(ll idx){
    if(idx==n-1) return 0;

    if(idx>=n) return INT_MAX;

    if(dp[idx]!=-1) return dp[idx];

    //jump one step
    ll jump_one = abs(a[idx]-a[idx+1]) + solve(idx+1);

    //jump two step
    ll jump_two = INT_MAX;
    if(idx+2<n)
        jump_two = abs(a[idx]-a[idx+2]) + solve(idx+2);

    return dp[idx] = min(jump_one,jump_two);
    
}
int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(NULL);
    cout.tie(NULL);
    cin>>n;
    fi(i,0,n,1) cin>>a[i];
    memset(dp,-1,sizeof(dp));
    pr(solve(0)) nl
    return 0;
}


Measured memory_bytes: 4992
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.StringTokenizer;

public class Main {

	public static void main(String[] args) throws IOException {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		String line = "";

		StringTokenizer st;
		StringBuilder sb = new StringBuilder();

		next: while ((line = br.readLine()) != null && !line.isEmpty()) {

			int n = Integer.parseInt(line.substring(0, line.indexOf(' ')));
			int k = Integer.parseInt(line.substring(line.indexOf(' ') + 1));
			if ((n | k) == 0) {
				break;
			}
			int[] stock = new int[k];
			int[] needs = new int[k];

			st = new StringTokenizer(br.readLine());
			for (int i = 0; i < k; i++) {
				stock[i] = Integer.parseInt(st.nextToken());
			}
			for (int i = 0; i < n; i++) {
				st = new StringTokenizer(br.readLine());
				for (int j = 0; j < k; j++) {
					needs[j] += Integer.parseInt(st.nextToken());
				}
			}
			for (int i = 0; i < k; i++) {
				if (stock[i] < needs[i]) {
					sb.append("No\n");
					continue next;
				}
			}
			sb.append("Yes\n");
		}
		System.out.print(sb.toString());
	}
}

Measured memory_bytes: 41820
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
            Scanner scanner = new Scanner(System.in);
            double r = scanner.nextDouble();
        double area = Math.PI * r * r;
        double around = 2 * Math.PI * r;
        System.out.println("" + String.format("%f", area) + " " + around);
    }
}


Measured memory_bytes: 28404
import java.util.*;

public class Main{
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int[] stop = new int[]{0,1,2,3,4,5,6,7,8,9,5,4,3,2,1};

		while(n-- > 0){
			int s = sc.nextInt();
			int g = sc.nextInt();

			int idx;
			for(idx=0;stop[idx]!=s;idx++);
			ArrayList<Integer> r1 = getRoute(stop,idx,s,g);
			for(idx=stop.length-1;stop[idx]!=s;idx--);
			ArrayList<Integer> r2 = getRoute(stop,idx,s,g);

			ArrayList<Integer> ans = r1.size() < r2.size() ? r1 : r2;
			for(int i=0;i<ans.size()-1;i++){
				System.out.print(ans.get(i) + " ");
			}
			System.out.println(ans.get(ans.size()-1));
		}
	}

	private static ArrayList<Integer> getRoute(int[] stop,int idx,int s,int g){
		ArrayList<Integer> res = new ArrayList<Integer>();
		for(int i=idx;stop[i]!=g;i=(i+1)%stop.length){
			res.add(stop[i]);
		}
		res.add(g);
		return res;
	}
}

Measured memory_bytes: 11000
import java.util.*;
public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		Map<Integer, Integer> m = new HashMap<>();
		for(int i = 1; i <= N; i++)
			m.put(i, 0);
		for(int i = 1; i < N; i++) {
			int A = sc.nextInt();
			m.put(A, m.get(A)+1);
		}
		for(int i = 1; i <= N; i++)
			System.out.println(m.get(i));
	}

}

Measured memory_bytes: 72600
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
int n;
vector<pair<int,int>> tasks;
int main() {
  cin >> n;
  for(int i =0;i<n;i++){
    int a,b;
    cin >> a >> b;
    tasks.emplace_back(b,a);
  }
  sort(tasks.begin(),tasks.end());
  int comp = 0;
  bool hantei = true;
  for(auto v : tasks){
    comp += v.second;
    if(comp > v.first){
      hantei = false;
      break;
    }
  }
  cout << (hantei? "Yes":"No") << endl;
  return 0;
}


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

using ll=int64_t;
#define int ll

#define FOR(i,a,b) for(int i=int(a);i<int(b);i++)
#define REP(i,b) FOR(i,0,b)
#define MP make_pair
#define PB push_back
#define ALL(x) x.begin(),x.end()
#ifdef MAROON_LOCAL
#define cerr (cerr<<"-- line "<<__LINE__<<" -- ")
#else
class CerrDummy{}cerrDummy;
template<class T>
CerrDummy& operator<<(CerrDummy&cd,const T&){
	return cd;
}
using charTDummy=char;
using traitsDummy=char_traits<charTDummy>;
CerrDummy& operator<<(CerrDummy&cd,basic_ostream<charTDummy,traitsDummy>&(basic_ostream<charTDummy,traitsDummy>&)){
	return cd;
}
#define cerr cerrDummy
#endif
#define REACH cerr<<"reached"<<endl
#define DMP(x) cerr<<#x<<":"<<x<<endl
#define ZERO(x) memset(x,0,sizeof(x))
#define ONE(x) memset(x,-1,sizeof(x))

using pi=pair<int,int>;
using vi=vector<int>;
using ld=long double;

template<class T,class U>
ostream& operator<<(ostream& os,const pair<T,U>& p){
	os<<"("<<p.first<<","<<p.second<<")";
	return os;
}

template<class T>
ostream& operator <<(ostream& os,const vector<T>& v){
	os<<"{";
	REP(i,(int)v.size()){
		if(i)os<<",";
		os<<v[i];
	}
	os<<"}";
	return os;
}

ll read(){
	ll i;
	scanf("%"  SCNd64,&i);
	return i;
}

void printSpace(){
	printf(" ");
}

void printEoln(){
	printf("\n");
}

void print(ll x,int suc=1){
	printf("%" PRId64,x);
	if(suc==1)
		printEoln();
	if(suc==2)
		printSpace();
}

string readString(){
	static char buf[3341000];
	scanf("%s",buf);
	return string(buf);
}

char* readCharArray(){
	static char buf[3341000];
	static int bufUsed=0;
	char* ret=buf+bufUsed;
	scanf("%s",ret);
	bufUsed+=strlen(ret)+1;
	return ret;
}

template<class T,class U>
void chmax(T& a,U b){
	if(a<b)
		a=b;
}

template<class T,class U>
void chmin(T& a,U b){
	if(b<a)
		a=b;
}

template<class T>
T Sq(const T& t){
	return t*t;
}

#define CAPITAL
void Yes(bool ex=true){
	#ifdef CAPITAL
	cout<<"YES"<<endl;
	#else
	cout<<"Yes"<<endl;
	#endif
	if(ex)exit(0);
}
void No(bool ex=true){
	#ifdef CAPITAL
	cout<<"NO"<<endl;
	#else
	cout<<"No"<<endl;
	#endif
	if(ex)exit(0);
}

const ll infLL=LLONG_MAX/3;

#ifdef int
const int inf=infLL;
#else
const int inf=INT_MAX/2-100;
#endif

signed main(){
	map<int,int> waf[2];
	int n=read();
	REP(i,n){
		int a=read();
		waf[i%2][a]++;
	}
	vector<pi> mof[2];
	REP(k,2){
		for(auto p:waf[k])
			mof[k].PB(pi(p.second,p.first));
		sort(ALL(mof[k]),greater<pi>());
		mof[k].PB(pi(0,-1));
	}
	int ans=0;
	REP(i,2)REP(j,2)if(mof[0][i].second!=mof[1][j].second)
		chmax(ans,mof[0][i].first+mof[1][j].first);
	print(n-ans);
}


Measured memory_bytes: 8824
#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for (int i = 0; i < (int)(n); i++)
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
typedef long long ll;
typedef pair<int, int> P;
const int INF = 100100100;
const int MOD = (int)1e9 + 7;
const double EPS = 1e-9;
struct Edge {
  ll to;
  ll cost;
};
int main() {
  int sx, sy, tx, ty;
  cin >> sx >> sy >> tx >> ty;
  for (int i = sy; i < ty; i++) cout << "U";
  for (int i = sx; i < tx; i++) cout << "R";
  for (int i = sy; i < ty; i++) cout << "D";
  for (int i = sx; i < tx; i++) cout << "L";
  cout << "L";
  for (int i = sy; i <= ty; i++) cout << "U";
  for (int i = sx; i <= tx; i++) cout << "R";
  cout << "D";
  cout << "R";
  for (int i = sy; i <= ty; i++) cout << "D";
  for (int i = sx; i <= tx; i++) cout << "L";
  cout << "U";
}

Measured memory_bytes: 3576
import sys
import math


stdin = sys.stdin


def ni(): return int(ns())


def na(): return list(map(int, stdin.readline().split()))


def ns(): return stdin.readline().rstrip()  # ignore trailing spaces


N = ni()

AB_array = [na() for _ in range(N)]

# print(AB_array)

plus_dic = {}
minus_dic = {}
ans = 1
fish_count = 0
mod = 10 ** 9 + 7
zero_count = 0
for ab in AB_array:
    a, b = ab
    if a == 0 and b == 0:
        zero_count += 1
        continue
    fish_count += 1
    if a == 0:
        vec = (0, 1)
        if vec in plus_dic:
            plus_dic[vec] += 1
        else:
            plus_dic[vec] = 1
        continue
    elif b == 0:
        vec = (1, 0)
        if vec in minus_dic:
            minus_dic[vec] += 1
        else:
            minus_dic[vec] = 1
        continue
    c = math.gcd(a, b)
    a = a // c
    b = b // c
    if a < 0:
        a *= -1
        b *= -1
    if b > 0:
        vec = (a, b)
        if vec in plus_dic:
            plus_dic[vec] += 1
        else:
            plus_dic[vec] = 1
    else:
        vec = (a, b)
        if vec in minus_dic:
            minus_dic[vec] += 1
        else:
            minus_dic[vec] = 1


# print(plus_dic, minus_dic, fish_count)

for k, vp in plus_dic.items():
    x, y = k
    if (y, -x) in minus_dic:
        vm = minus_dic[(y, -x)]
        ans = ans * (pow(2, vp, mod) + pow(2, vm, mod) - 1) % mod
        fish_count -= (vp + vm)

ans = ans * pow(2, fish_count, mod) % mod

print((ans - 1 + zero_count) % mod)


Measured memory_bytes: 130840
#include <iostream>
#include <algorithm>
#include <vector>
using namespace std;
int main(){
	string n;cin >> n;
	int cnt = 0;
	if(n.size() >= 2){
	cnt += 9;
		if (n.size() >= 4 ){
			cnt += 900;
			if(n.size() == 6){
				cnt += 90000;
			}else if(n.size() == 5){
				cnt += (stoi(n)/10000 - 1)*10000;
				cnt += stoi(n) % 10000;
				cnt++;
			}
		}else if (n.size() == 3){
			cnt += (stoi(n)/100 -1)*100;
			cnt += stoi(n)%100;
			cnt ++;
		}
	}else if (n.size() == 1){
		cnt += stoi(n)%10;
	}

	cout << cnt << endl;

}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <algorithm>
#include <map>
#include <cstdlib>
#include <cmath>
#define _GLIBCXX_DEBUG
#define rep(i,n) for(int i=0;i<n;i++)
using namespace std;
typedef long long ll;
int main(){
    int n;
    cin >> n;
    vector<ll> lucas(87);
    lucas[0]=2;
    lucas[1]=1;
    for(int i=2;i<87;i++){
        lucas[i]=lucas[i-1]+lucas[i-2];
    }
    ll ans=lucas[n];
    cout << ans << endl;
}


Measured memory_bytes: 256
count = int(input())
orline = input()
line = orline.split()
dri = int(input())
sum = 0
for i in range(dri):
  num = input().split()
  line[int(num[0]) - 1] = int(num[1])
  for j in range(count):
    sum += int(line[j])
  print(sum)
  sum = 0
  line[int(num[0]) -1] = orline.split()[int(num[0]) -1]

Measured memory_bytes: 3064
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <cstdio>
#include <cstring>
#include <cmath>
using namespace std;

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

    int n, c;
    cin >> n >> c;

    const int T = (int)1e5;

    vector<int> a(T);
    for (int i = 0; i < n; i++) {
        int s, t, c;
        cin >> s >> t >> c;
        c--;

        for (int j = s; j < t; j++) {
            a[j] ^= 1 << c;
        }
    }

    for (int j = 0; j < T - 1; j++) {
        a[j] ^= ~a[j] & a[j + 1];
    }

    int r = 0;
    for (int j = 0; j < T; j++) {
        int s = a[j];
        s = (s & 0x55555555) + (s >> 1 & 0x55555555);
        s = (s & 0x33333333) + (s >> 2 & 0x33333333);
        s = (s & 0x0f0f0f0f) + (s >> 4 & 0x0f0f0f0f);
        s = (s & 0x00ff00ff) + (s >> 8 & 0x00ff00ff);
        s = (s & 0x0000ffff) + (s >> 16);
        r = max(r, s);
    }

    cout << r << endl;

    return 0;
}

Measured memory_bytes: 768
#include "bits/stdc++.h"
using namespace std;
using ll = long long;
#define rep(i, begin, n) for (int i = begin; i < n; i++)
#define repe(i, begin, n) for (int i = begin; i <= n; i++)
#define repr(i, begin, n) for (int i = begin; i > begin - n; i--)
#define repre(i, begin, end) for (int i = begin; i >= end; i--)

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;
}

const int inf = 1000000007;
const int MOD = 1000000007;
const long long INF = 1000000000000000007;

// -------------------------------------------------------

int main() {
  int N;
  cin >> N;
  cout << N / 3 << endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<iomanip>
#include<math.h>
#include<complex>
#include<queue>
#include<deque>
#include<stack>
#include<map>
#include<set>
#include<bitset>
#include<functional>
using namespace std;
#define REP(i,m,n) for(int i=(int)m ; i < (int) n ; ++i )
#define rep(i,n) REP(i,0,n)
typedef long long ll;
typedef pair<int,int> pint;
typedef pair<ll,int> pli;
const int inf=1e9+7;
const ll longinf=1LL<<60 ;
const ll mod=1e9+7 ;

int main(){
    ll s;
    cin>>s;
    int ans=inf;
    while(s>=100){
        int ret=s%1000;
        ans=min(ans,abs(753-ret));
        s/=10;
    }
    cout<<ans<<endl;
    return 0;
}

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

int main(void)
{

	int i,j,k;
	int n,m;
	int x[20001],c[16];
	int *dp[20001];
	int tmp1,tmp2;
	int min;
		
	for(i=0;i<=20001;i++){
		dp[i] = (int *)malloc(sizeof(int)*256);
	}

	while(1)
	{
		scanf("%d %d ",&n,&m);
		if(n==0 && m==0)break;
		
		for(i=0;i<m;i++){
			scanf("%d ",&c[i]);
		}
		
		for(i=1;i<=n;i++){
			for(j=0;j<256;j++){
				dp[i][j] = 2000000000;
			}
		}
		
		scanf("%d ",&x[1]);
		
		for(k=0;k<m;k++){
			tmp1 = 128 + c[k];
			if(tmp1<0)tmp1=0;
			if(tmp1>255)tmp1=255;
			tmp2 = (tmp1 - x[1]) * (tmp1 - x[1]);
			dp[1][tmp1] = tmp2;
		}
		
		for(i=2;i<=n;i++){
			scanf("%d ",&x[i]);
			for(j=0;j<256;j++){
				if(dp[i-1][j] >= 0){
					for(k=0;k<m;k++){
						tmp1 = j + c[k];
						if(tmp1<0)tmp1=0;
						if(tmp1>255)tmp1=255;
						tmp2 = (tmp1 - x[i]) * (tmp1 - x[i]);
						if(dp[i][tmp1] > dp[i-1][j] + tmp2)dp[i][tmp1] = dp[i-1][j] + tmp2;
					}
				}
			}
		}
		
		min=2000000000;
		for(i=0;i<256;i++){
			if(min > dp[n][i])min = dp[n][i];
		}
		
		printf("%d\n",min);
	}
	return 0;
}

			
			

Measured memory_bytes: 20000
input = input()

if len(input) % 2:
    print("No")
    exit(0)

result = "Yes"
isHi = False
for i in range(len(input)-1):
    if isHi:
        isHi = False
        continue;

    str = input[i] + input[i+1]
    if str != "hi":
        result = "No"
        break

    isHi = True

print(result)

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

using namespace std;

const int MAX_N = 4e5 + 5;

char arr [MAX_N];

char f (char c) {
  if (c == 'A') return 'B';
  return 'A';
}

int main () {
  int n, k;
  cin >> n >> k;

  int st = 0;
  for (int i = 0; i < n; i++) {
    cin >> arr[i];
  }

  int flip = 0;
  while (k > 0) {
    if (!flip && arr[st] == 'A') {
      arr[st] = 'B';
    } else if (flip && arr[st] == 'B') {
      arr[st] = 'A';
    } else {
      flip = !flip;
      st++;
      arr[st + n - 1] = (flip ? 'B' : 'A');
    }
    k--;

    if (st == n) break;
  }

  if (k == 0) {
    if (flip) {
      for (int i = st; i < st + n; i++) {
        cout << f(arr[i]);
      }
      cout << endl;
    } else {
      for (int i = st; i < st + n; i++) {
        cout << arr[i];
      }
      cout << endl;
    }

    return 0;
  }

  if (n % 2 == 0) {
    if (flip) {
      for (int i = st; i < st + n; i++) {
        cout << f(arr[i]);
      }
      cout << endl;
    } else {
      for (int i = st; i < st + n; i++) {
        cout << arr[i];
      }
      cout << endl;
    }

    return 0;
  }

  k %= 2;
  if (k == 1) {
    if (!flip && arr[st] == 'A') {
      arr[st] = 'B';
    } else if (flip && arr[st] == 'B') {
      arr[st] = 'A';
    } else {
      flip = !flip;
      st++;
      arr[st + n - 1] = (flip ? 'B' : 'A');
    }
    k--;    
  }

  if (flip) {
    for (int i = st; i < st + n; i++) {
      cout << f(arr[i]);
    }
    cout << endl;
  } else {
    for (int i = st; i < st + n; i++) {
      cout << arr[i];
    }
    cout << endl;
  }
}


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


int main()
{
    char s[15];
    gets(s);
    int i, j, f=0, l;
    if(s[0]!='A'){
        printf("WA\n");
        return 0;
    }
    
    l=strlen(s);
    
    if((s[1]<=90 && s[1]>=65 )||( s[l-1]<=90 && s[l-1]>=65) && ((s[1]!='C' && s[1]!='A') || (s[l-1]!='C' && s[l-1]!='A')) ){
        printf("WA\n");
        return 0;
    }
    
    for(i=2; i<l-1; i++){
        if(f==0 && s[i]=='C') {
            f=1;
            continue;
        }
        if(s[i]<=90 && s[i]>=65){
            printf("WA\n");
            return 0;
        }
    }
    if(f==0){
        printf("WA\n");
        return 0;
    }
    
    printf("AC\n");
    
    return 0;
}
                
    
    


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

using namespace std;

#define pb push_back
#define mp make_pair
#define forn(i, n) for (int i = 0; i < (int)(n); ++i)
typedef long long LL;
typedef pair<int, int> PII;

LL x;

int main() {
    cin >> x;
    LL ans = 2ll * (x / 11);
    x %= 11;
    if (x > 0) {
        x -= 6;
        ++ans;
    }
    if (x > 0) {
        x -= 5;
        ++ans;
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
def main():
    n, k = map(int, input().split())
    sunu = [1] * n
    for _ in range(k):
        d = int(input())
        dl = list(map(int, input().split()))
        for edl in dl:
            sunu[edl - 1] = 0
    print(sum(sunu))

if __name__ == '__main__':
    main()


Measured memory_bytes: 9172
#include<iostream>	// 入出力
#include<stdio.h>	// 入出力
#include<math.h>	// 数学の関数
#include<vector>	// 配列
#include<string>	// 文字列
#include<map>		// 連想配列
#include<stack>		// スタック
#include<queue>		// キュー
#include<algorithm> // ソートとか


using namespace std;

using ll = long long;

const int __ = 100001;

int N;

int x[__];
int y[__];
int t[__];

int main()
{
	cin >> N;

	t[0] = 0;
	x[0] = 0;
	y[0] = 0;

	for (int i = 1; i <= N; ++i)
	{
		cin >> t[i] >> x[i] >> y[i];
	}
	

	for (int i = 1; i <= N; ++i)
	{
		int sub_t = t[i] - t[i - 1];
		int sub_p = abs(x[i] - x[i - 1]) + abs(y[i] - y[i - 1]);

		if (sub_t < sub_p|| (sub_t - sub_p) % 2 == 1)
		{
			cout << "No" << endl;

			return 0;
		}

	}

	cout << "Yes" << endl;
	
	return 0;

}

Measured memory_bytes: 1408
import sys
from collections import deque
from collections import  Counter
import statistics
import math

stdin = sys.stdin

ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
ns = lambda: stdin.readline()

n = ni()

dp = [99999999]*(n+1)
dp[0] = 0
for i in range(1, n+1):
    dp[i] = dp[i-1] + 1
    k = 6
    while i-k >= 0:
        dp[i] = min(dp[i], dp[i-k]+1)
        k *= 6
    k = 9
    while i-k >= 0:
        dp[i] = min(dp[i], dp[i-k]+1)
        k *= 9
print(dp[n])



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

int main() {
  string s,t;
  int count=0;
  cin>>s>>t;
  rep(i,s.size()){
    if(s[i]!=t[i]){
      count++;
    }
  }
  cout<<count<<endl;
}

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

int main()
{
	string S;
	string result;

	cin >> S;

	result = "";

	for (int a = 0; a < S.length(); a++) {
		result += "x";
	}
	

	cout << result<<endl;
}



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

int main() {
   int n,x,t;
   cin >> n >> x >> t;
   if(n % x == 0) {
      cout << (n / x) * t << endl;
   }else {
      cout << (n / x + 1) * t << endl;
   }


   return 0;
}

Measured memory_bytes: 3632
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define mp make_pair
#define pb push_back
#define rep(i,n) for(int i=0;i<n;i++)
#define rep1(i,n) for(int i=1;i<=(int)(n);i++)

struct UnionFind {
  vector< int > data;
 
  UnionFind(int sz) {
    data.assign(sz, -1);
  }
 
  bool unite(int x, int y) {
    x = find(x), y = find(y);
    if(x == y) return (false);
    if(data[x] > data[y]) swap(x, y);
    data[x] += data[y];
    data[y] = x;
    return (true);
  }
 
  int find(int k) {
    if(data[k] < 0) return (k);
    return (data[k] = find(data[k]));
  }
 
  int size(int k) {
    return (-data[find(k)]);
  }
};


int n,m;
const int n_max=7e2+7;
set<int> g[n_max];


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

  
  cin >> n >> m;    
  UnionFind uf(n);

  rep(i,m){
    int a,b;
    cin >> a >> b;
    --a;--b;
    g[a].insert(b);
    g[b].insert(a);
    uf.unite(a,b);
  }
  vector<int> clus;
  rep(i,n){
    if(uf.find(i)==i){
      clus.pb(uf.size(i));
    }
  }
  if(clus.size()>2){
    cout << -1 << endl;
    return 0;
  }
  if(clus.size()==2){
    int sum = clus[0]*(clus[0]-1)/2 + clus[1]*(clus[1]-1)/2;
    if(sum==m){
      cout << m << endl;
    }
    else cout << -1 << endl;
    return 0;
  }
  vector<int> color(n,-1);
  vector<pair<int,int> > group;
  int pre_z,pre_o;
  pre_z=pre_o=0;
  rep(k,n){
    if(color[k]>=0) continue;
    if(g[k].size()==n-1) continue;
    color[k]=0;
    queue<int> que;
    que.push(k);
    while(!que.empty()){
      int v=que.front();que.pop();
      int c=color[v];
      rep(j,n){
	if(j==v) continue;
	if(g[v].count(j)==0){
	  if(color[v]==color[j]){
            cout << -1 << endl;
            return 0;
          }
	  if(color[j]==-1){
	    que.push(j);
	    color[j]=((1-c)%2);
	  }
	}
      }
    }
    int z,o;
    z=o=0;
    rep(i,n){
      if(color[i]==0) z++;
      else if(color[i]==1) o++;
    }
    group.pb(mp(z-pre_z,o-pre_o));
    pre_z=z;pre_o=o;
  }
  int rest=0;
  rep(i,n){
    if(g[i].size()==n-1) rest++;
  }  
  vector<bool> dp(n-rest+10, false);
  dp[0]=true;
  rep(i,group.size()){
    vector<bool> ndp(n-rest+10, false);
    int fi=group[i].first;
    int	sec=group[i].second;
    //    cout << "culster a b  "<< fi << " " <<sec << endl;
   
    rep(j,n-rest+10){
      if(j+fi<n-rest+10) ndp[j+fi] = (dp[j] | ndp[j+fi]);
      if(j+sec<n-rest+10) ndp[j+sec] = (dp[j] | ndp[j+sec]);
    }
    rep(j,n-rest+10){
      dp[j]=ndp[j];
    }    
  }
  int ze,on;
  ze=0;
  rep(i,n-rest+10){
    if(dp[i]){
      //      cout << i << endl;
      int mid = (n-rest)/2;
      if(abs(mid - ze) > abs(mid - i)){
	ze=i;
      }
    }
  }
  on = n-rest-ze;
  //  cout << ze << " " << on << endl;
  while(rest>0){
    if(ze>on) on++;
    else ze++;
    rest--;
  }
  int ans = on*(on-1)/2+ze*(ze-1)/2;
  cout << ans << endl;
  
  return 0;
    

}


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

map<int, int> m;
int ord=0;
int loop_sta;
int loop_len=0;

void loop(vector<int> &A, int tel){
    if(m.count(tel)){
        loop_sta=tel;
        loop_len=ord-m[tel];
        return;
    }
    else{
        m[tel]=ord;
        ord++;
        loop(A, A[tel]);
    }
}

int main(){
    int N; cin >> N;
    long long K; cin >> K;
    vector<int> A(N);
    for(int i=0; i<N; i++){
        int x; cin >> x;
        x--;
        A[i]=x;
    }
    loop(A, 0);
    int res=loop_sta;
    long long R=(K-m[loop_sta])%loop_len;
    while(R > 0){
        res=A[loop_sta];
        R--;
        loop_sta=A[loop_sta];
    }
    res++;
    if(K < m[loop_sta]){
        int i=0;
        while(K > 0){
            res=A[i];
            K--;
            i=A[i];
        }
        res++;
        cout << res << endl;
    }
    else cout << res << endl;
    return 0;
}

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

using namespace std;

using ll = long long;
#define FOR(i, a, b) for(int i=(a);i<(b);++i)
#define FORE(i, a, b) for(int i=(a);i<=(b);++i)
#define FORR(i, a, b) for(int i=(b-1);i>=(a);--i)
#define FORRE(i, a, b) for(int i=(b);i>=(a);--i)
#define rep(i, n) for(int i=0;i<(n);++i)
#define repe(i, n) for(int i=0;i<=(n);++i)
#define repr(i, n) for(int i=(n-1);i>=0;--i)
#define repre(i, n) for(int i=(n);i>=0;--i)
#define ALL(v) (v).begin(),(v).end()
#define SP cout<<fixed<<setprecision(10)
typedef pair<int, int> P;
const int INF = (int) 1e9;
const int MOD = (int) 1e9 + 7;

int gcd(int a, int b) { return b ? gcd(b, a % b) : a; }

int main(void) {
	cin.tie(0);
	ios::sync_with_stdio(false);
	
	int n, l;
	cin >> n >> l;
	
	int sum = 0;
	rep(i, n) {
		sum += l + i;
	}
	
	if (l <= 0 and 0 <= l + n - 1) cout << sum << endl;
	else if (l > 0) cout << sum - l << endl;
	else cout << sum - (l + n - 1) << endl;
	
	return 0;
}

Measured memory_bytes: 256
#[allow(unused_imports)]
use std::cmp::*;
#[allow(unused_imports)]
use std::collections::*;
use std::io::{Write, BufWriter};
// https://qiita.com/tanakh/items/0ba42c7ca36cd29d0ac8
macro_rules! input {
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

    ($next:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
}

macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };

    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };

    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
    };

    ($next:expr, [ $t:tt ]) => {{
        let len = read_value!($next, usize);
        (0..len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    }};

    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}

#[allow(unused)]
macro_rules! debug {
    ($($format:tt)*) => (write!(std::io::stderr(), $($format)*).unwrap());
}
#[allow(unused)]
macro_rules! debugln {
    ($($format:tt)*) => (writeln!(std::io::stderr(), $($format)*).unwrap());
}

fn solve() {
    let out = std::io::stdout();
    let mut out = BufWriter::new(out.lock());
    macro_rules! puts {
        ($($format:tt)*) => (let _ = write!(out,$($format)*););
    }
    input!(s: i64, w: i64);
    puts!("{}\n", if w >= s { "unsafe" } else { "safe" });
}

fn main() {
    // In order to avoid potential stack overflow, spawn a new thread.
    let stack_size = 104_857_600; // 100 MB
    let thd = std::thread::Builder::new().stack_size(stack_size);
    thd.spawn(|| solve()).unwrap().join().unwrap();
}


Measured memory_bytes: 2252
/**
 * @brief AtCoder Regular Contest 061<br>
 * C- たくさんの数式 / Many Formulas
 *
 * bit全検索パターン
 * @see https://arc061.contest.atcoder.jp/tasks/arc061_a
 */
#include <iostream>
using namespace std;

constexpr unsigned BIT = 1;

int main() {
  string S; cin >> S;
  int len{static_cast<int>(S.size())};

  long total{};
  for (int i{}; i < (BIT << (len - 1)); ++i) {
    long temp = S[0] & 0xF;
    for (int j{}; j < len - 1; ++j) {
      if (i & (1 << j)) {
        total += temp;
        temp = 0;
      }
      temp *= 10;
      temp += S[j + 1] & 0xF;
    }
    total += temp;
  }

  cout << total << endl;
  return 0;
}


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

int main(){
  int n;
  cin >> n ;
  int b[n-1];
  int a[n];
  for(int i=0;i<n-1;i++){
      cin >> b[i];
      a[i]=0;
  }
  
  int max=0;
  
    for(int i=0;i<n-1;i++){
      if(i==0){
        a[i]=b[i];
        a[i+1]=b[i];
        
      }else{
        if(a[i]>b[i]){
            a[i]=b[i];
        }
        a[i+1]=b[i];
        
      }
    }
    for(int x=0;x<n;x++){
        max+=a[x];
    }
  cout << max << endl;
  
}

  
  

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main() {
	int sum=0,xsum=100000000,N;
	cin>>N;
	for(;N>0;N--){
		int A;
		cin>>A;
		sum=0;
		while(A%2==0){
		A/=2;
		sum++;
		}
		if(xsum>sum)
		xsum=sum;
 
		if(N==1)
		cout<<xsum<<endl;
	}
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define all(x) (x).begin(),(x).end()
const int mod=1000000007,MAX=200005,INF=1<<30;

int main(){
    
    std::ifstream in("text.txt");
    std::cin.rdbuf(in.rdbuf());
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    int H,W,N;cin>>H>>W>>N;
    cout<<min((N+H-1)/H,(N+W-1)/W)<<endl;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
#define rep(i,n) for (ll i = 0; i < (n); ++i)
#define vcout(v) rep(i,v.size()) cout << v[i] << " "; cout << endl
#define mcout(m) rep(j,m.size()){vcout(m[j]);}
const ll MOD = 1e9 + 7;

int mainsolve(){

	string s;
	cin >> s;
	rep(i,s.size()){
		if(s[i] == '7'){
			cout << "Yes" << endl;
			return 0;
		}
	}

	cout << "No" << endl;
	return 0;
}

int main(){

	return mainsolve();
}

Measured memory_bytes: 3628
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for(int i=a;i<=b;i++)
#define REP(i,b) FOR(i,0,b)
#define INF 1e9
#define int long long
using ll = long long;
const ll mod = LLONG_MAX;

int N,W,ans;
int w[110],v[110];

//i個見ててj個入れててw[i]-w[0]の和がk
int dp[110][110][310];

signed main(){
  cin>>N>>W;

  FOR(i,1,N)cin>>w[i]>>v[i];

  int memo=w[1];
  FOR(i,1,N){
    w[i]-=memo;
  }

  memset(dp,0,sizeof(dp));
  int ans=0;

  FOR(i,1,N)FOR(j,1,i)FOR(k,0,300){
    dp[i][j][k]=dp[i-1][j][k];

    if(k-w[i]>=0 && k+j*memo<=W){
      dp[i][j][k]=max(dp[i][j][k],dp[i-1][j-1][k-w[i]]+v[i]);
    }

    if(i==N)ans=max(ans,dp[i][j][k]);

  }
  cout<<ans<<endl;

}


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

int f(int x) {
    if (x == 0) return 0;
    return f(x % __builtin_popcount(x)) + 1;
}

int main() {
    int n;
    cin >> n;
    string s;
    cin >> s;
    vector<int> b(n, 0);
    for (int i = 0; i < n; i++) b[i] = (s[i] - '0');

    int popcnt = 0;
    for (int i = 0; i < n; i++) popcnt += b[i];

    vector<int> sgn = {1, -1};
    vector<int> ans(n, 0);
    for (int k = 0; k < 2; k++) {
        int m = popcnt + sgn[k];
        if (m == 0) continue;

        int r0 = 0;
        for (int i = 0; i < n; i++) {
            r0 = (r0 * 2 + b[i]) % m;
        }

        int p = 1;
        for (int i = n - 1; i >= 0; i--) {
            if (b[i] == k) {
                int r = r0;
                r = (sgn[k] == 1) ? (r + p) % m : (r - p + m) % m;
                ans[i] = f(r) + 1;
            }
            p = (p * 2) % m;
        }
    }

    for (int i = 0; i < n; i++) {
        cout << ans[i] << endl;
    }
}

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

#define all(x) x.begin(), x.end()
#define sz(x) (int)x.size()
#define rep(i,n) for(int i = 0; i < n; i++)
#define REP(i, k , n) for(int i = k; i <= n; i++)
typedef long long ll;

const char nl = '\n' ;
const ll MOD = 1e9 + 7;


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

   int a, b, c, x;
   cin >> a >> b >> c >> x;
   int ans = 0;
   REP(i, 0, a)
   {
      REP(j, 0, b)
      {
         REP(k,0,c)
         {
            if(i*500 + j*100 + k*50 == x)
               ans++;
         }
      }
   }
   cout << ans << nl;

   return 0;
}


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

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

    switch (n%10)
    {
    case 2:
    case 4:
    case 5:
    case 7:
    case 9: cout << "hon" << endl; break;
    case 0: 
    case 1:
    case 6:
    case 8: cout << "pon" << endl; break;
    case 3: cout << "bon" << endl; break;
    }

    return 0;
}

Measured memory_bytes: 3428
#include<iostream>
#include<cstdio>

using namespace std;

int main(void)
{
int k,n,a[5001],b[5001],c[5001],d[5001],t[5001]={0};
int cnt;
cin >> n;
k=n*(n-1)/2;
for(int i=0;i<k;i++)
cin >> a[i] >> b[i] >> c[i] >> d[i];
for(int i=0;i<k;i++){
if(c[i]>d[i])
t[a[i]]+=3;
else if(c[i]<d[i])
t[b[i]]+=3;
else{
t[a[i]]+=1;
t[b[i]]+=1;}}

for(int i=1;i<=n;i++){
cnt=1;
for(int j=1;j<=n;j++){
if(t[i]<t[j])
cnt++;}
cout << cnt << endl;
}
return 0;
}


Measured memory_bytes: 3204
import bisect
import cmath
import heapq
import itertools
import math
import operator
import os
import random
import re
import string
import sys
from collections import Counter, defaultdict, deque
from copy import deepcopy
from decimal import Decimal
from functools import lru_cache, reduce
from math import gcd
from operator import add, itemgetter, mul, xor

import numpy as np

if os.getenv("LOCAL"):
    sys.stdin = open("_in.txt", "r")

sys.setrecursionlimit(10 ** 9)
INF = float("inf")
IINF = 10 ** 18
MOD = 10 ** 9 + 7
# MOD = 998244353



N = sys.stdin.buffer.readline().decode().rstrip()
if '7' in N:
    print('Yes')
else:
    print('No')
'7' in N


Measured memory_bytes: 27200
#include "bits/stdc++.h"
using namespace std;
using ll     = long long;
using pii    = pair<int, int>;
using pll    = pair<ll, ll>;
using vi     = vector<int>;
using vl     = vector<ll>;
using vvi    = vector<vi>;
using vvl    = vector<vl>;
const ll INF = 1LL << 60;
const ll MOD = 1000000007;
template <class T>
bool chmax(T &a, const T &b) {
    return (a < b) ? (a = b, 1) : 0;
}
template <class T>
bool chmin(T &a, const T &b) {
    return (b < a) ? (a = b, 1) : 0;
}
template <class C>
void print(const C &c, std::ostream &os = std::cout) {
    std::copy(std::begin(c), std::end(c), std::ostream_iterator<typename C::value_type>(os, " "));
    os << std::endl;
}

int main() {
    ll n;
    cin >> n;
    vl a(n);
    ll tot = 0;
    for (int i = 0; i < n; ++i) {
        cin >> a[i];
        tot += a[i];
    }
    ll once = n * (n + 1) / 2;
    if (tot % once != 0) {
        cout << "NO"
             << "\n";
        return 0;
    }
    ll turns = tot / once;
    ll an    = a[0] - a[n - 1];
    for (int i = 0; i < n - 1; ++i) {
        a[i] = a[i + 1] - a[i];
    }
    a[n - 1] = an;
    ll t     = 0;
    for (int i = 0; i < n; ++i) {
        a[i] -= turns;
        a[i] *= -1;
        if (a[i] % n != 0 || a[i] < 0) {
            cout << "NO"
                 << "\n";
            return 0;
        }
        t += a[i] / n;
    }
    assert(t == turns);
    cout << "YES"
         << "\n";
    return 0;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define mp make_pair
#define pb push_back
#define rep(i,n) for(int i=0;i<n;i++)
#define rep1(i,n) for(int i=1;i<=(int)(n);i++)


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

  int a,b;
  cin >> a >> b;

  int ans;
  rep1(i,3){
    if(i!=a && i!=b) ans=i;
  }
  cout << ans << endl;
  
  
  
  return 0;
    

}


Measured memory_bytes: 256
S= input()
T= input()
SS = {}
TT = {}
for i in range(len(S)):
    s = S[i]
    t = T[i]
    if s not in SS:
        SS[s] = t
    elif SS[s] != t:
        print("No")
        break
    if t not in TT:
        TT[t] = s
    elif TT[t] != s:
        print("No")
        break
else:
    print("Yes")

Measured memory_bytes: 3632
#include "bits/stdc++.h"
 
typedef long long ll;
#define int ll
#define fi first
#define se second
#define SORT(a) sort(a.begin(),a.end())
#define rep(i,n) for(int i = 0;i < (n) ; i++) 
#define REP(i,n) for(int i = 0;i < (n) ; i++) 
#define MP(a,b) make_pair(a,b)
#define pb(a) push_back(a)
#define INF LLONG_MAX/2

using namespace std;

int MOD = 1000000007;

signed main(){
    string s;
    cin >> s ;

    int a,b,c;
    a = b = c = 0;
    rep(i,s.size()){
        if(s[i] == 'a')a++;
        if(s[i] == 'b')b++;
        if(s[i] == 'c')c++;
    }

    if(abs(a-b) <= 1 && abs(a-c) <= 1 && abs(c-b) <= 1){
        cout << "YES" << endl;
    }else{
        cout << "NO" << endl;
    }

    
    return 0;
}
// g++ -std=c++14 code1.cpp
// rm -r -f test;oj dl 

Measured memory_bytes: 512
#include "bits/stdc++.h"

#define REP(i,x,y) for(ll i=(x);i<(y);i++)
#define RREP(i,x,y) for(ll i=(y)-1;i>=(x);i--)
#define all(x) (x).begin(),(x).end()
//#define int long long

using namespace std;

// conversion
inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}

#ifdef LOCAL
#define eprintf(...) fprintf(stderr, __VA_ARGS__)
#define dump(x)  cerr << #x << " = " << (x) << endl
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl
#else
#define eprintf(...) 42
#define dump(x) 42
#define debug(x) 42
#endif

typedef long long ll;

const ll MOD = 1e9 + 7;

signed main() {
    int N;
    cin >> N;
    vector<int> A(N);
    vector<vector<pair<int, int>>> XY(N);
    REP(i,0,N) {
        cin >> A[i];
        XY[i] = vector<pair<int,int>>(A[i]);
        REP(j,0,A[i]) {
            cin >> XY[i][j].first >> XY[i][j].second;
            XY[i][j].first--;
        }
    }
    int answer = 0;
    REP(i,0,1LL << N) {
//        cout << bitset<16>(i) << "\n";
        bool flag = false;
        REP(j,0,N) {
            bool jIsHonest = (1LL << j) & i;
            if (!jIsHonest) continue;
            REP(k,0,A[j]) {
                bool kIsHonest = (1LL << XY[j][k].first) & i;
//                cout << j << " " << jIsHonest << "\n";
//                cout << XY[j][k].first << " " << kIsHonest << "\n";
//                cout << XY[j][k].second << "\n";
                if (!(jIsHonest == (kIsHonest == (bool)XY[j][k].second))) { // true true true or true false false or false true false or false false true
                    flag = true;
                    break;
                }
            }
            if(flag) break;
        }
        if (flag) continue;
        int honestNum = 0;
        REP(j,0,N) {
            if ((1LL << j) & i) honestNum++;
        }
        answer = max(answer, honestNum);
//        cout << answer << "\n";
    }
    cout << answer << "\n";

    return 0;
}



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

const int MOD = 1e9 + 7;

int n, x, y, z;
int dp[41][131100];

int main()
{
    scanf("%d", &n);
    scanf("%d%d%d", &x, &y, &z);

    dp[0][0] = 1;
    int mx_mask = (1 << (x + y + z)) - 1;
    int bad_mask = (1 << (z - 1)) | (1 << (y + z - 1)) | (1 << (x + y + z - 1));
    for(int i = 1; i <= n ; ++i){
        for(int mask = 0; mask <= mx_mask + 1 ; ++mask){
            for(int p = 1; p <= 10 ; ++p){
                if((mask & bad_mask) == bad_mask) continue ;

                int new_mask = mx_mask & ((1LL * mask << 1LL * p) | (1LL << (p - 1)));
                if((new_mask & bad_mask) == bad_mask) continue ;

                dp[i][new_mask] = dp[i][new_mask] + dp[i - 1][mask];
                if(dp[i][new_mask] >= MOD) dp[i][new_mask] -= MOD;
            }
        }
    }

    int ans = 1;
    for(int i = 1; i <= n ; ++i) ans = ans * 10LL % MOD;

    for(int mask = 0; mask <= mx_mask + 1 ; ++mask){
        ans = (ans + MOD - dp[n][mask]);
        if(ans >= MOD) ans -= MOD;
    }

    printf("%d", ans);

    return 0;
}


Measured memory_bytes: 20736
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
int n,m,k;
int dp[1000005];
int main()
{
	scanf("%d%d%d",&n,&m,&k);
	for(int i=0;i<=m;i++)
	{
		for(int j=0;j<=n;j++)
		{
			dp[i*n+j*m-2*i*j]=1;
		}
	}
	if(dp[k]==0)cout<<"No";
	else cout<<"Yes";
	return 0;
}

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


using namespace std;
const long long INF = 1LL <<60;

int main(void){
  long long tmp;
  long long i,j,k;
  for(i=0;i<5;i++){
    cin>>tmp;
	if(tmp==0){
      cout<<i+1<<endl;
      break;
    }
  }

  return 0;
  
}    

Measured memory_bytes: 3636
let main () =
  let n, x = Scanf.scanf "%d %d\n" (fun a b -> a, b) in
  let xs = ref [] in
  for i = 0 to n do
    for j = 0 to n do
      if i + j <= n then xs := (i,j, n - (i+j)) :: !xs;
    done;
  done;
  List.iter (fun (i,j,k) -> if 10000 * i + 5000 * j + 1000 * k = x then (Printf.printf "%d %d %d\n" i j k; exit 0)) !xs;
  Printf.printf "-1 -1 -1\n"

let _ = main ()


Measured memory_bytes: 120952