akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <string>
#include <sstream>
#include <algorithm>
#include <vector>
#include <utility>
#include <functional>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <deque>
#include <ctime>

using namespace std;

#define rep(i,n) REP(i,0,n)
#define REP(i,s,e) for(int i=(s); i<(int)(e); i++)
#define pb push_back
#define mp make_pair
#define all(r) (r).begin(),(r).end()
#define rall(r) (r).rbegin(),(r).rend()
#define fi first
#define se second
#define ARRAY_LENGTH(array) (sizeof(array) / sizeof(array[0]))


typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

const int INF = 1e9;
const ll LINF = 1e18;
const ll MOD = 1e9 + 7;
double EPS = 1e-8;
const double PI = acos(-1);

int dx[]={-1,1,0,0};
int dy[]={0,0,-1,1};

struct Pointer{
    int x,y;
};

void print(int ab, char dir){
    for(int i=0; i<ab; i++){
        cout << dir;
    }
}

int main(){

    Pointer Sxy, Txy;
    cin >> Sxy.x >> Sxy.y >> Txy.x >> Txy.y;

    int wth = Txy.x - Sxy.x;
    int hgt = Txy.y - Sxy.y;

    char dir[5] = {'U', 'D', 'R', 'L'};

    //一週目は長方形の周り
    print(wth, dir[2]);
    print(hgt, dir[0]);
    print(wth, dir[3]);
    print(hgt, dir[1]);

    //次は長方形+1おおきいところをいく
    //S -> T
    print(1, dir[3]); //一回左へ
    hgt++;
    print(hgt, dir[0]); //大きく上へ
    wth++;
    print(wth, dir[2]); //大きく右へ
    print(1, dir[1]); //下に降りる

    //T -> S
    print(1, dir[2]); //右へ
    print(hgt, dir[1]); //大きく下へ
    print(wth, dir[3]); //大きく左へ
    print(1, dir[0]);

    cout << endl;

}

Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ABC162
{
    class Program
    {
        static void Main(string[] args)
        {
            a();
        }

        public static void a()
        {
            string s = Console.ReadLine();
            if(s.Contains("7"))
            {
                Console.WriteLine("Yes");
            }
            else
            {
                Console.WriteLine("No");
            }
        }
    }
}


Measured memory_bytes: 17448
N,K=[int(s) for s in input().split()]
point=[int(s) for s in input().split()]
point=point+point
kyotai=input()
kyo=[None]*N
for i in range(N):
  if kyotai[i]=='s':
    kyo[i]=0
  elif kyotai[i]=='p':
    kyo[i]=1
  else:
    kyo[i]=2
hand=[] #出した手
score=0 #得点
##K回目までは勝つ
for i in range(K):
  hand.append(kyo[i])
  score+=point[kyo[i]]
##N-K回目までは、勝てるならかつ。勝てないなら次を見る
for i in range(K,N-K):
  if hand[i-K]!=kyo[i]:
    hand.append(kyo[i])
    score+=point[kyo[i]]
  elif hand[i-K]==kyo[i+K]:
    hand.append((kyo[i]+1)%3)
  else:
    hand.append(3-kyo[i+K]-hand[i-K])
##N-K+1回目からは、勝てるならかつ
for i in range(N-K,N):
  if hand[i-K]!=kyo[i]:
    score+=point[kyo[i]]
print(score)

Measured memory_bytes: 4980
#pragma GCC optimize (3)
#include<vector>
#include<stack>
#include<bitset>
#include<cstdlib>
#include<cmath>
#include<set>
#include<list>
#include<deque>
#include<map>
#include<queue>
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
/*#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
#include<ext/pb_ds/hash_policy.hpp>
#include<ext/pb_ds/trie_policy.hpp>
#include<ext/pb_ds/priority_queue.hpp>*/
#define PII pair<int,int>
#define ll long long
#define ull unsigned long long
#define INFI 2147483647
#define INFL 9223372036854775807
#define INFU 18446744073709551615
using namespace std;
//using namespace __gnu_pbds;
const double PI=acos(-1.0);
const double eps=1e-6;
inline int read()
{
    int x=0,f=1;
    char ch=getchar();
    while(ch<'0' || ch>'9'){
        if(ch=='-') f=-1;
        ch=getchar();
    }
    while(ch>='0' && ch<='9'){
        x=x*10+ch-'0';
        ch=getchar();
    }
    return x*f;
}
char s[1005];
int main()
{
	//ios_base::sync_with_stdio(false);
    //cin.tie(0);
    //cout.tie(0);
	int k=read();
    scanf("%s",s+1);
    int len=strlen(s+1);
    if(k>=len) printf("%s\n",s+1);
    else{
        for(int i=1;i<=k;i++) printf("%c",s[i]);
        printf("...\n");
    }
	return 0;
}


Measured memory_bytes: 3764
import java.io.IOException;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) throws IOException {

		new Main().run();
	}

	private void run() throws IOException {
		Scanner scanner = new Scanner(System.in);
		while (true) {
			int w = scanner.nextInt();
			int h = scanner.nextInt();
			if ((w | h) == 0)
				break;
			int[][] map = new int[h+1][w+1];
			boolean[][] b = new boolean[h+1][w+1];
			int n = scanner.nextInt();
			while (n-- > 0) {
				int x = scanner.nextInt();
				int y = scanner.nextInt();
				b[y][x] = true;
			}
			map[0][1] = 1;
			for (int i = 1; i <= h; i++)
				for (int j = 1; j <= w; j++) {
					if (b[i][j])
						continue;
					map[i][j] = map[i - 1][j] + map[i][j - 1];
				}

			System.out.println(map[h][w]);
		}
	}
}

Measured memory_bytes: 20204
#include <stdio.h>

int main() {
	int N,i,D1,count=0,D2,MAX=0;
	scanf("%d", &N);
	for (i = 0; i < N; i++) {
		scanf("%d %d", &D1, &D2);
		if (D1 == D2) {
			count = count + 1;
			if (MAX < count) {
				MAX = count;
			}
		}
		else {
			count = 0;
		}
	}
	if (MAX >= 3) {
		printf("Yes");
	}
	else {
		printf("No");
	}
	return 0;
}

Measured memory_bytes: 1728
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <array>
#include <queue>
#include <deque>
#include <map>
#include <set>
#include <sstream>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <list>
#include <numeric>
#include <stack>
#include <iomanip>
#include <random>
#include <complex>
#include <functional>
#include <tuple>

using namespace std;

#define Rep(i,a,b) for(int i = a; i < b; ++i)
#define rep(i,b) Rep(i,0,b)
#define allof(a) (a).begin(), (a).end()

#define Yes(q) ((q) ? "Yes" : "No")
#define YES(q) ((q) ? "YES" : "NO")
#define Possible(q) ((q) ? "Possible" : "Impossible")
#define POSSIBLE(q) ((q) ? "POSSIBLE" : "IMPOSSIBLE")

using ll = long long;

using pint = std::pair<int, int>;
using pll = std::pair<ll, ll>;


constexpr int inf = 1e9 + 7;
constexpr ll infll = 1ll << 60ll;
constexpr ll mod = 1e9 + 7;
// 0~3までは右左下上 4~7までは斜め
constexpr int dx[] = { 1, 0, -1, 0, 1, 1, -1, -1 };
constexpr int dy[] = { 0, -1, 0, 1, 1, -1, -1, 1 };

namespace {
	template<typename T> void chmax(T& a, T b) { a = std::max(a, b); }
	template<typename T> void chmin(T& a, T b) { a = std::min(a, b); }
	template<typename T> void chadd(T& a, T b) { a = a + b; }

	void Cout(long long x, const char* end = "\n") { std::cout << x << end; }
	template <typename T> void Cout(const T& x, const char* end = "\n") { std::cout << x << end; }
	template <typename T> void Cout(const std::vector<T>& x, const char* sep = " ", const char* end = "\n") { for (std::size_t i = 0, sz = x.size(); i < sz; i++) { std::cout << x[i] << (i == sz - 1 ? end : sep); } }

	void CCout(long long x, const char* end = "\n") { std::cerr << x << end; }
	template <typename T> void CCout(const T& x, const char* end = "\n") { std::cerr << x << end; }
	template <typename T> void CCout(const std::vector<T>& x, const char* sep = " ", const char* end = "\n") { for (std::size_t i = 0, sz = x.size(); i < sz; i++) { std::cerr << x[i] << (i == sz - 1 ? end : sep); } }

	// 標準入出力
	struct inp {
		std::size_t sz;
		inp(std::size_t _sz = 1) : sz(_sz) {}
		template <typename T> operator T () const { T a; std::cin >> a; return a; }
		template <typename T> operator std::vector<T>() const { vector<T> a(sz); for (std::size_t i = 0; i < sz; i++) std::cin >> a[i]; return a; }
		template <typename T, typename U> operator std::pair<T, U>() const { T f; U s; std::cin >> f >> s; return std::pair<T, U>(f, s); }
	};

	inp inp1; // input one
}

int main() {

	string l = inp1;

	// 片方が0なら必ずOK
	// 繰り上げがない場合はOK (同じ桁に1がそろわない)
	size_t n = l.length();
	// AおよびBの値の上からk桁目まで確定させ，その時点ですでにA+BがL以下であることが分かっている/いない(0/1)組の数
	vector<vector<ll>> dp(n + 1, vector<ll>(2, 0));

	dp[0][1] = 1;

	rep(i, n) {
		// L以下確定
		// 1のとき
		dp[i + 1][0] += dp[i][0];
		// 0
		dp[i + 1][0] += dp[i][0] * 2;

		// 確定していない
		int d = l[i] - '0';
		if (d == 0) {
			// 0で決まり
			dp[i + 1][1] += dp[i][1];
		}
		else {
			// 0にすると確定になる (ただし，向こう側も0なので*1)
			dp[i + 1][0] += dp[i][1];
			// 1にすると不確定のまま
			dp[i + 1][1] += dp[i][1] * 2;
		}

		dp[i + 1][0] %= mod;
		dp[i + 1][1] %= mod;

	}

	cerr << dp[n][0] << ", " << dp[n][1] << '\n';
	Cout((dp[n][0] + dp[n][1]) % mod);

	return 0;
}


Measured memory_bytes: 5760
import sys

read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines
sys.setrecursionlimit(10 ** 9)
INF = 1 << 60
MOD = 1000000007


def main():
    N = int(readline())

    n = 1
    while (n + 1) * (n + 1) <= N:
        n += 1

    print(n * n)

    return


if __name__ == '__main__':
    main()


Measured memory_bytes: 8984
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

class Main {
	public static void main(String[] args) throws IOException {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in), 1);
		String str = br.readLine();
		String[] num = str.split(" ");
		if(num.length > 3) return;
		
		int a = Integer.parseInt(num[0]);
		int b = Integer.parseInt(num[1]);
		int c = Integer.parseInt(num[2]);
		
		if(a<b && b<c) {
			System.out.println("Yes");
		}else {
			System.out.println("No");
		}
	}
}

Measured memory_bytes: 24428
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define f(i,j,n) for(int i=j;i<=n;i++)
int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int r;
    cin>>r;
    if(r<1200)
      cout<<"ABC";
    else if(r<2800 && r>=1200)
     cout<<"ARC";
    else 
    cout<<"AGC";
} 


Measured memory_bytes: 3624
#include<bits/stdc++.h>
#define ll long long
#define ull unsigned long long
#define IO ios::sync_with_stdio(false), cin.tie(0)
#define endl '\n'
#define pi acos(-1.0)
#define lowbit(x) ((x)&(-(x)))
#define debug(x) cout<<x<<'\n'
#define pii pair<ll,pair<ll,ll> >
using namespace std;
const ll INF=0x3f3f3f3f3f3f3f3f;
const int inf = 0x3f3f3f3f;
//const ll mod = 1e9+7;
ll mod;
const double eps = 1e-6;
ll gcd(ll a, ll b) {return b==0?a:gcd(b, a%b);}
ll lcm(ll a, ll b) {return a/gcd(a, b)*b;}
ll mul(ll a,ll b){ll ans=0;a%=mod,b%=mod;while(b) { if(b&1) ans = (ans+a)%mod; a = (a*2)%mod; b >>= 1; }return ans;}
ll powmod(ll a,ll b){ ll ans = 1, pow = a; while(b) { if(b&1) ans = (ans*pow)%mod; pow = (pow*pow)%mod; b >>= 1; } return ans;}
//(b/a)%p=b*a^(p-2)%p
int pr(ll num){//判素
     if(num == 1) return 0;
     if(num ==2|| num==3 ) return 1 ;
     if(num %6!= 1&&num %6!= 5) return 0 ;
     int tmp =sqrt( num);
     for(int i= 5;i <=tmp; i+=6 )
          if(num %i== 0||num %(i+ 2)==0 )return 0 ;
     return 1 ;
}
int Day(int y,int m, int d){if(m==1||m==2) { m+=12; y--; }int w=(d+2*m+3*(m+1)/5+y+y/4-y/100+y/400)%7;return w+1;}
int pri[1000005];
void getpri(){
    memset(pri,true,sizeof(pri));
    pri[0]=pri[1]=0;
    for(int i=2;i<=1000000;i++){
        if(pri[i]){
            for(int j=2*i;j<=1000000;j+=i)pri[j]=0;
        }
    }
}
inline int read() {
    int c = 0, f = 1;
    char ch = getchar();
    while (ch < '0' || ch > '9') {
        if (ch == '-') f = -1;
        ch = getchar();
    }
    while (ch >= '0' && ch <= '9') {
        c = c * 10 + ch - '0';
        ch = getchar();
    }
    return c * f;
}
//int pre[100005];
//void init(){
//    for(int i=1; i<=100005;++i) pre[i]=i;
//}
//int getf(int x){
//    if(pre[x] == x) return x;
//    else return pre[x] = getf(pre[x]);
//}
//void join(int x,int y){
//    int a = getf(x);
//    int b = getf(y);
//    if(a!=b) pre[b]=a;
//}
//大小写转换
//String s;
//Form(s.begin(),s.end(),s.begin(),::toupper);
//Form(s.begin(),s.end(),s.begin(),::tolower);
//(char)toupper('a')
//(char)tolower('B')
//#pragma comment(linker, "/STACK:1024000000,1024000000")//外挂开栈
//stable_sort 排序不处理相同元素
//map<int,int>::reverse_iterator rit;
//for(rit=mp.rbegin();rit!=mp.rend();rit++)
//vec动态二维数组
//vector<vector<int>> g(26,vector<int>(100005));
//初始化vec里面套了n个vec
//lower_bound(begin,end,num) 有序数列中返回第一个>=num的数字的地址
//upper_bound( begin,end,num) 返回第一个>num的数字的地址
const int maxn=1e5+5;
ll a[maxn];
ll maxx=1e18;
int main(){
    int n;
    cin>>n;
    for(int i=0;i<n;++i){
        cin>>a[i];
    }
    sort(a,a+n);
    if(a[0]==0) cout<<0<<endl;
    else {
        ull ans=1;
        int f=1;
        for(int i=0;i<n;++i){
            if(maxx/ans>=a[i]){
                ans*=a[i];
            }
            else{
                f=0;
                break;
            }
        }
        if(f) cout<<ans<<endl;
        else cout<<-1<<endl;
    }
    return 0;
}


Measured memory_bytes: 4408
#include <bits/stdc++.h>
#define f(i, a, b) for (int i = a; i < (b); ++i)
#define f1(i, a, b) for (int i = a; i <= (b); ++i)
#define rep(i, n) f(i, 0, n)
using namespace std;
using ll = long long;

int main(void) {
  string s, t;
  cin >> s;
  t = s;
  reverse(s.begin(), s.end());
  int ans = 0;
  rep(i, s.size() / 2) {
    if (s[i] == t[i]) continue;
    ans++;
  }
  cout << ans << '\n';
  return 0;
}

Measured memory_bytes: 3604
#include <iostream>
using namespace std;
int main()
{
	long long l, r;
	cin >> l >> r;
	long long min=2019;
	if (r-l>=2018)
		min=0;
	else
	{
		for (long long i=l; i<=r-1; i++)
		{
			for (long long j=i+1; j<=r; j++)
			{
				if (i*j%2019<min)
				{
					min=(i*j)%2019;
				}
			}
		}
	}
	cout << min << endl;
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define rep1(i,n,a)    for(int i=0;i<n;i+=a)
#define rep2(i,n,a)    for(int i=a;i<n;i++)
#define rep3(n)        for(int i=0;i<n;i++)
#define inarr(arr,n)   rep1(i,n,1)cin>>arr[i]
#define ll             long long int
#define pb             push_back
#define all(v)         v.begin(),v.end()
#define trav(a,x)      for(auto x:a)
#define endl           "\n"
#define eb             emplace_back
#define fr             first
#define sc             second
#define gcd(a,b)       __gcd(a,b)
#define pres(a,x)      a.find(x)!=a.end()
#define sz(a)         (int)a.size()
#define pii            pair<int,int>
#define psi            pair<string,int>
#define pss            pair<string,string>
#define pll            pair<ll,ll>
#define vec            vector<int>
#define IOS            ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define ret            return 0
#define pi             3.1415926536
#define hell           1000000007
#define narak          998244353
const int inf1=1e9;
const ll inf2=1e18;
const int N=100000;
using namespace std;
int dirs[4][2] ={{1,0},{-1,0},{0,1},{0,-1}};
// syntax for min priority_queue of pairs
// priority_queue<pair<ll,ll>,vector<pair<ll,int>>,greater<pair<ll,int>>> q;
int solve(){
 int n,k;cin>>n>>k;
 ll dp[n+1];
 ll arr[n+1];
 rep3(n)cin>>arr[i+1];
 dp[1]=0;
 dp[2]=abs(arr[2]-arr[1]);
 for(int i=3;i<=n;i++){ 
   dp[i]=dp[i-1]+abs(arr[i]-arr[i-1]);
   for(int j=i-1;j>=max(i-k,1);j--){
       dp[i]=min(dp[i],dp[j]+abs(arr[j]-arr[i]));
   }
 }
 //for(int i=1;i<=n;i++)cout<<dp[i]<<" ";cout<<endl;
 cout<<dp[n]<<endl;   
 ret;
}
int main(){
    IOS;
    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);
    int t=1;//cin>>t;
    while(t--){
        solve();
    }
    ret;
}
 

Measured memory_bytes: 1792
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cmath>
#include<cctype>
#include<math.h>
#include<string>
#include<string.h>
#include<stack>
#include<queue>
#include<vector>
#include<utility>
#include<set>
#include<map>
#include<stdlib.h>
#include<iomanip>

using namespace std;

#define ll long long
#define ld long double
#define EPS 0.0000000001
#define INF 1e9
#define MOD 1000000007
#define rep(i,n) for(int i=0;i<(n);i++)
#define loop(i,a,n) for(i=a;i<(n);i++)
#define all(in) in.begin(),in.end()
#define shosu(x) fixed<<setprecision(x)

#define int ll //!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

typedef vector<int> vi;
typedef vector<string> vs;
typedef pair<int,int> pii;

int gcd(int a, int b){
    if(b==0) return a;
    return gcd(b,a%b);
}
int lcm(int a, int b){
    return a*b/gcd(a,b);
}

vector<vi> g;
bool c; //is bipartite graph

vi used;
int cnt[2];

void dfs(int now){
    cnt[used[now]]++;
    rep(i,g[now].size()){
        int ne = g[now][i];
        if(used[ne] == -1){
            used[ne] = 1 - used[now];
            dfs(ne);
        }else if(used[ne] == used[now]){
            c = false;
            return;
        }
    }
}

vector<pii> p;

bool is_bipartite(int n){
    c = true;
    rep(i,n) used[i] = -1;
    rep(i,n)if(used[i]==-1){
        used[i] = 0;
        cnt[0] = cnt[1] = 0;
        dfs(i);
        if(c==false) return false;
        p.push_back(pii(cnt[0],cnt[1]));
    }

    return true;
}


signed main(void) {
    int i,j;
    int n,m;
    while(cin >> n >> m, n){
        g = vector<vi> (n);
        used = vi(n);
        p.clear();
        rep(i,m){
            int a,b;
            cin >> a >> b;
            a--,b--;
            g[a].push_back(b);
            g[b].push_back(a);
        }
        vi ans;
        if(is_bipartite(n)){
            int N = p.size();
            set<int> st;
            st.insert(0);
            rep(i,N){
                set<int> nst;
                for(auto x : st) {
                    nst.insert(x + p[i].first);
                    nst.insert(x + p[i].second);
                }
                st = nst;
            }

            for(auto x : st) {
                if(x%2 == 0)ans.push_back(x/2);
            }
        }
        sort(all(ans));
        cout << ans.size() << endl;
        rep(i,ans.size())cout << ans[i] << endl;
    }
}



Measured memory_bytes: 3284
#include <bits/stdc++.h>
using namespace std;
#define int long long

// typedef
//------------------------------------------
typedef pair<int, int> PII;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef vector<PII> VP;

// rep
//------------------------------------------
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, n) FOR(i, 0, n)
#define ALL(x) (x).begin(), (x).end()
#define DEBUG(x) cerr << #x << ": " << x << '\n'
#define DEBUGP(x) cerr << #x << ": " << x.first << " \t" << x.second << '\n'

string s;
signed main()
{
    cin >> s;
    if (s[0] == 'A'){
        cout << 'T' << endl;
    } else if (s[0] == 'T'){
        cout << 'A' << endl;
    } else if (s[0] == 'G'){
        cout << 'C' << endl;
    } else if (s[0] == 'C'){
        cout << 'G' << endl;
    }
    return 0;
}

Measured memory_bytes: 256
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <queue>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <fstream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>
using namespace std;
typedef long long ll;
const double PI = acos(-1.0);

int main()
{ 
    int n, m;
    cin >> n;
    vector<int> a(n+1, 0);
    for (int i = 0; i < n - 1; i++) {
        cin >> m;
        a[m]++;
    }
    for (int i = 1; i < n + 1; i++) {
        cout << a[i] << endl;
    }
    return 0;
}


Measured memory_bytes: 3976
N = int(input())
s = bin(N)[2:]
n = len(s)
dp = [[0] * 4 for i in range(len(s)+1)]
dp[0][0] = 1
MOD = int(1e9) + 7
for i in range(n):
    b = 1 if s[i] == '1' else 0
    for j in range(4):
        for k in range(3):
            nj = min(((j << 1) + b - k, 3))
            if 0 <= nj:
                dp[i+1][nj] += dp[i][j]
                dp[i+1][nj] %= MOD
print(sum(dp[n]) % MOD)


Measured memory_bytes: 3316
#include <cstdio>
#include <iostream>
#include <algorithm>
#include <vector>
#include <set>
#include <list>
#include <map>
#include <string>
#include <cstring>
#include <stack>
#include <queue>
#include <cmath>
#include <ctime>
#include <bitset>
#include <utility>
#include <complex>
#include <assert.h>
#include <limits.h>
//#include <bits/stdc++.h>
using namespace std;
#define rank rankk
#define mp make_pair
#define pb push_back
#define xo(a,b) ((b)&1?(a):0)
#define tm tmp

//#define LL ll
typedef unsigned long long ull;
typedef pair<int,int> pii;
typedef long long ll;
typedef pair<ll,int> pli;
typedef pair<int,ll>pil;
typedef pair<ll,ll> pll;
//const double INF=1e20;
const int INF=0x3f3f3f3f;
//const int INF= 0x7fffffff;
//const ll INF=0x3f3f3f3f3f3f3f3fll;
const ll INFF=0x3f3f3f3f3f3f3fll;
//const ll INFF=1e14+5;
const int MAX=5e5+5;
//const ll MAXN=2e8;
//const int MAX_N=MAX;
//const ll MOD=1e9+7;
const ll MOD=1e9+7;
//const long double pi=acos(-1.0);
//const double eps=0.00000001;
int gcd(int a,int b){return b?gcd(b,a%b):a;}
template<typename T>inline T abs(T a) {return a>0?a:-a;}
//#define double long double
template<class T> inline
void read(T& num) {
    bool start=false,neg=false;
    char c;
    num=0;
    while((c=getchar())!=EOF) {
        if(c=='-') start=neg=true;
        else if(c>='0' && c<='9') {
            start=true;
            num=num*10+c-'0';
        } else if(start) break;
    }
    if(neg) num=-num;
}
inline ll powMM(ll a,ll b,ll M){
    ll ret=1;
    a%=M;
//    b%=M;
    while (b){
        if (b&1) ret=ret*a%M;
        b>>=1;
        a=a*a%M;
    }
    return ret;
}
//const long double eps=-1.0;
//clock_t t1 = clock();
//fprintf(stderr, "%ld ms\n", clock() - t1);
void open()
{
    freopen("in2.txt","r",stdin);
    freopen("out2.txt","w",stdout);
}

int q;
ll a,b,c;
int main()
{
    scanf("%d",&q);
    while(q--)
    {
        scanf("%lld%lld",&a,&b);
        if(a>b)swap(a,b);
        if(a==b||a+1==b)printf("%lld\n",2LL*a-2LL);
        else
        {
            c=(ll)sqrt(a*b);
            while(c*c>=a*b)--c;
            if(c*(c+1LL)<a*b)
                printf("%lld\n",2LL*c-1);
            else printf("%lld\n",2LL*c-2);
        }
    }
}
/*

*/


Measured memory_bytes: 256
import java.util.Scanner; public class Main { public static void main(String[] args) { Scanner sc = new Scanner(System.in); int a = sc.nextInt(); int b = sc.nextInt(); String relation; if(a > b){ relation = ">"; }else if(a < b){ relation = "<"; }else{ relation = "=="; } System.out.printf("a %s b\n", relation); } } 


Measured memory_bytes: 26252
#include<bits/stdc++.h>
using namespace std;
int main(){
  int n,m,a,b,i,ans = 0;cin >> n >> m;bool ok;
  vector<int> ar(n);vector<vector<int>> k(n);
  for(i=0;i<n;i++) ar[i] = i;
  while(cin >> a >> b){
    a--;b--;
    k[a].push_back(b);
    k[b].push_back(a);
  }
  for(i=0;i<n;i++) sort(k[i].begin(),k[i].end());
  do{
    ok = true;
    for(i=1;i<n;i++){
      if(!binary_search(k[ar[i]].begin(),k[ar[i]].end(),ar[i-1])) ok = false;
    }
    ans += ok;
  } while(next_permutation(ar.begin()+1,ar.end()));
  cout << ans << endl;
}

Measured memory_bytes: 256
o[9999];m[99][99];main(x,y,d,e){
	for(e=d=0;;o[d++]=x){
		y=scanf("%d",&x);
		if(y==-1)break;
		if(!y)getchar(),scanf("%d",&x);
	}
	d=(int)sqrt(d);
	for(x=0;x<d;x++)for(y=0;y<=x;y++)m[x-y][y]=o[e++];
	for(x=d-2;~x;x--)for(y=0;y<=x;y++)m[d-1-y][d-1-(x-y)]=o[e++];
	for(x=1;x<d;x++)m[x][0]+=m[x-1][0];
	for(y=1;y<d;y++)m[0][y]+=m[0][y-1];
	for(x=1;x<d;x++)for(y=1;y<d;y++)m[x][y]+=m[x-1][y]>m[x][y-1]?m[x-1][y]:m[x][y-1];
	printf("%d\n",m[d-1][d-1]);exit(0);
}

Measured memory_bytes: 636
#include<cstdio>
#include<cstdlib>
#include<cmath>
#include<cstring>
#include<cctype>
#include<complex>
#include<iostream>
#include<sstream>
#include<algorithm>
#include<functional>
#include<vector>
#include<string>
#include<stack>
#include<queue>
#include<map>
#include<set>
#include<bitset>
using namespace std;
const int dx[] = {1,0,-1,0},dy[] = {0,1,0,-1};
#define INF 1e+8
#define EPS 1e-8
#define rep(i,j) for(int i = 0; i < (j); i++)
#define reps(i,j,k) for(int i = j; i < k; i++)
typedef long long ll;
typedef pair<int,int> Pii;
int main(){
	int q;
	scanf("%d",&q);
	rep(i,q){
		int c,a,n;
		scanf("%d%d%d",&c,&a,&n);
		int cnt = 0;
		while(true){
			if(n > 0 && a > 0 && c > 0){
				n--;
				a--;
				c--;
				cnt++;
				continue;
			}
			if(c > 1 && a > 0){
				c-=2;
				a--;
				cnt++;
				continue;
			}
			if(c > 2){
				c-=3;
				cnt++;
				continue;
			}
			break;
		}
		printf("%d\n",cnt);
	}
	return 0;
}

Measured memory_bytes: 1188
import std.algorithm;
import std.array;
import std.bitmanip;
import std.conv;
import std.stdio;
import std.string;
import std.typecons;

T diff(T)(const ref T a, const ref T b) { return a > b ? a - b : b - a; }

void main() {
    immutable ip = readln.split.to!(ulong[]);
    immutable n = ip[0], k = ip[1];

    ulong ret = k == 1 ? 0 : n-k;
    writeln(ret);
}


Measured memory_bytes: 256
package main

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

var sc = bufio.NewScanner(os.Stdin)

func main() {
    sc.Split(bufio.ScanWords)
    k, n := nextInt(), nextInt()
    a := nextIntArr(n)

    a = append(a, k+a[0])

    max := 0

    for i := 0; i < n; i++ {
        if max < a[i+1] - a[i] {
            max = a[i+1] - a[i]
        }
    }

    fmt.Println(k-max)
}




//===========================
//
// Library
//
//===========================

func gcd(x, y int) int {
    if y == 0 {
        return x
    }

    return gcd(y, x%y)
}

//====================
//  var q Queue
//  q.Enqueue(n)
//  n := q.Dequeue()
//====================
type Queue struct {
    data []int
}

func (q *Queue) Enqueue(n int) {
    q.data = append(q.data, n)
}

func (q *Queue) Dequeue() int {
    tmp := q.data[0]
    q.data = q.data[1:]
    return tmp
}

func nextLine() string {
    sc.Scan()
    return sc.Text()
}

func nextInt() int {
    sc.Scan()
    i, _ := strconv.Atoi(sc.Text())
    return i
}

func nextIntArr(n int) []int {
    var a []int
    for i := 0; i < n; i++ {
        a = append(a, nextInt())
    }
    return a
}

// 数値を桁区切りのスライスにする
func digit(n int, list []int) []int {
   if n > 0 {
       return digit(n/10, append(list, n%10))
   }
   return list
}

func sortIntsRev(list []int) {
    sort.Sort(sort.Reverse(sort.IntSlice(list)))
}

func strReverse(s string) string {
    runes := []rune(s)
    for i := 0; i < len(s)/2; i++ {
        runes[i], runes[len(s)-1-i] = runes[len(s)-1-i], runes[i]
    }
    return string(runes)
}



Measured memory_bytes: 8960
#include<stdio.h>
#include<cctype>

using namespace std;
int main(){
    char str[1200];
    scanf("%[^\n]%*c", str);
    for(int i = 0;i < 1200;i++){
        if(islower(str[i])){
            str[i] = toupper(str[i]);
        } else if(isupper(str[i])){
            str[i] = tolower(str[i]);
        } 
    }
    
    printf("%s\n",str);
}



Measured memory_bytes: 2608
#include <algorithm>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <map>
#include <set>
#include <stack>
#include <string>
#include <vector>
#include <queue>

using namespace std;

#define TRACE(x) cerr << #x << " " << x << endl
#define FOR(i, a, b) for (int i = (a); i < int(b); ++i)
#define REP(i, n) FOR(i, 0, n)
#define _ << " " <<

#define fst first
#define snd second

typedef long long llint;
typedef pair<int, int> pii;

const int B = 27397, MOD = 1e9 + 7;
const int B1 = 33941, MOD1 = 1e9 + 9;

const int MAXN = 1e5 + 10;

bool sol[MAXN];

int n;
char s[MAXN];

inline void zapeci() {
  for (int i = 0; i < n; ++i)
    if (sol[i]) printf("S"); else printf("W");
  printf("\n");
  exit(0);
}

inline bool check() {
  for (int i = 0; i < n; ++i) {
    int prev = (i - 1 + n) % n, next = (i + 1) % n;
    if ((s[i] == 'o' && sol[i] || s[i] == 'x' && !sol[i]) && sol[prev] != sol[next]) return false;
    if ((s[i] == 'o' && !sol[i] || s[i] == 'x' && sol[i]) && sol[prev] == sol[next]) return false;
  }
  return true;
}

bool solve(int x, int y) {
  sol[0] = x;
  sol[1] = y;
  for (int i = 1; i < n; ++i) {
    if (s[i] == 'o' && sol[i] || s[i] == 'x' && !sol[i])
      sol[i + 1] = sol[i - 1];
    else
      sol[i + 1] = !sol[i - 1];
  }
//  for (int i = 0; i < n; ++i)
//    printf("%d ", sol[i]);
//  printf("\n");
  return check();
}

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

  for (int i = 0; i < 2; ++i)
    for (int j = 0; j < 2; ++j)
      if (solve(i, j))
        zapeci();

  printf("-1\n");
  return 0;
}



Measured memory_bytes: 512
from collections import defaultdict
N, W = map(int, input().split())
data_list = []
for _ in range(N):
    w, v = map(int, input().split())
    data_list.append((w,v))

data = defaultdict(int)
data[0] = 0
for w, v  in data_list:
    for cw, cv in list(data.items()):
        if cw + w <= W:
            data[cw+w] = max(data[cw+w], cv + v)
print(max(data.values()))

Measured memory_bytes: 3828
#include <algorithm>
#include <cmath>
#include <cstdint>
#include <cstdio>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
using namespace std;
#define rep(i, n) for(int(i) = 0; (i) < (n); (i)++)
#define FOR(i, m, n) for(int(i) = (m); (i) < (n); (i)++)
#define All(v) (v).begin(), (v).end()
#define pb push_back
#define MP(a, b) make_pair((a), (b))
using ll = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
const int INF = 1 << 30;
const ll LINF = 1LL << 60;
const int MOD = 1e9 + 7;

//二項係数（nCk mod.p;1<=k<=n<=1e7,pは素数）
template <class T> struct Combination {
    const int MOD = 1000000007;
    vector<T> fac, finv, inv;
    Combination(const int MAX) : fac(MAX), finv(MAX), inv(MAX) {
        fac[0] = fac[1] = 1;
        finv[0] = finv[1] = 1;
        inv[1] = 1;
        for(int i = 2; i < MAX; i++) {
            fac[i] = fac[i - 1] * i % MOD;
            inv[i] = MOD - inv[MOD % i] * (MOD / i) % MOD;
            finv[i] = finv[i - 1] * inv[i] % MOD;
        }
    }
    T comb(int n, int k) {
        if(n < k)
            return 0;
        if(n < 0 || k < 0)
            return 0;
        return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
    }
};

int main() {
    ll N, K;
    cin >> N >> K;
    Combination<ll> C(200100);
    ll res = 0;
    for(int i = 0; i <= (min(N, K)); i++) {
        res = (res + ((C.comb(N, N - i) *
                       C.comb((N - (N - i)) + (N - i - 1), N - (N - i))) %
                      MOD)) %
              MOD;
    }
    cout << res << endl;
    return 0;
}

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

int main() {
  int n,m,x,p=0,q=0;
  cin>>n>>m>>x;
  rep(i,m){
    int A;
    cin>>A;
    if (A>x) {
      p+=1;
    }
    else{
      q+=1;
    }
  }
  cout<<min(p,q)<<endl;    
}



Measured memory_bytes: 256
using System.Collections.Generic;
using System.Linq;
using System;
class Program
{
	static void Main()
	{
		var countStr = Console.ReadLine();
		int count = int.Parse(countStr);
 
		var line = Console.ReadLine();
		string[] array = line.Split(' ');
 
		int fourM = 0;
		int twoM = 0;
		int notM = 0;
 
		for (int i = 0; i < count; i++)
		{
			int num = int.Parse(array[i]);
			if (num % 4 == 0)
			{
				fourM++;
			}
			else if (num % 2 == 0)
			{
				twoM++;
			}
			else
			{
				notM++;
			}
		}
 
        if (twoM > 0)
            notM++;
 
		//Console.WriteLine(fourM);
		//Console.WriteLine(twoM);
		//Console.WriteLine(notM);
 
		if (fourM >= notM - 1)
		{
			Console.WriteLine("Yes");
		}
		else
		{
			Console.WriteLine("No");
		}
	}
}

Measured memory_bytes: 20064
#include <bits/stdc++.h>
using namespace std;
int main(){
	int n;
	cin>>n;
	int ans = 0;
	for(int i=1;i<10 && i<=n;++i) ++ans;
	for(int i=100;i<1000 && i<=n;++i) ++ans;
	for(int i=10000;i<100000 && i<=n;++i) ++ans;
	cout << ans <<endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (n); i++)
#define rep2(i, x, n) for (int i = x; i < (n); i++)
#define all(n) begin(n), end(n)
struct cww
{
    cww()
    {
        ios::sync_with_stdio(false);
        cin.tie(0);
    }
} star;
const long long INF = numeric_limits<long long>::max();
typedef long long ll;
typedef vector<int> vint;
typedef vector<char> vchar;
typedef vector<vector<int>> vvint;
typedef vector<ll> vll;
typedef vector<vector<ll>> vvll;
typedef unsigned long long ull;
template <class T>
bool chmax(T &a, const T &b)
{
    if (a < b)
    {
        a = b;
        return 1;
    }
    return 0;
}
template <class T>
bool chmin(T &a, const T &b)
{
    if (b < a)
    {
        a = b;
        return 1;
    }
    return 0;
}
template <typename T>
vector<T> make_v(size_t a) { return vector<T>(a); }

template <typename T, typename... Ts>
auto make_v(size_t a, Ts... ts)
{
    return vector<decltype(make_v<T>(ts...))>(a, make_v<T>(ts...));
}
template <typename T, typename V>
typename enable_if<is_class<T>::value == 0>::type
fill_v(T &t, const V &v) { t = v; }

template <typename T, typename V>
typename enable_if<is_class<T>::value != 0>::type
fill_v(T &t, const V &v)
{
    for (auto &e : t)
        fill_v(e, v);
}
int main()
{
    int N;
    cin >> N;
    map<string, int> cnt;
    for (size_t i = 0; i < N; i++)
    {
        string s;
        cin >> s;
        cnt[s]++;
    }
    cout << cnt.size();
    return 0;
}

Measured memory_bytes: 19236
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>

#define all(a) a.begin(), a.end()
#define forn(l, r) for(int i = l; i < (r); ++i)
#define F first
#define S second
#define $ ios::sync_with_stdio(0);
///#define int long long int

using namespace std;
using namespace __gnu_pbds;
using ll = long long int;
using ii = pair<int, int>;
using li = pair<ll, int>;
using vi = vector<int>;
using graph = vector<vi>;
using ordered_set = tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update>;

mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

const ll mod =  1000000007;
const int INF = 0x3f3f3f3f;
const int MAXN = 312345;
//const double pi = 3.14159265359;
const double eps = 0.00000001;

vector<vi> g;
int pi[11];
int n, m;

int dp[11][4000];
bool seen[11][4000];

inline bool kthbit(int x, int k) {
    return (x & (1 << k)) > 0;
}

int sol (int idx, int bm) {
    bool& vis = seen[idx][bm];
    int& pd = dp[idx][bm];
    if (vis) return pd;
    if (idx == n) {
        bool ok = 1;
        forn (0, m) {
            if (pi[i] != kthbit(bm, i)) {
                ok = 0;
                break;
            }
        }
        return ok;
    }
    pd += sol (idx + 1, bm);
    for (int e : g[idx]) {
        bm ^= (1 << e);
    }
    pd += sol (idx + 1, bm);
    vis = 1;
    return pd;
}

int32_t main() {
    $

    cin >>  n >> m;

    g.assign(n, vi());

    int qtd, x;
    forn (0, m) {
        cin >> qtd;
        while (qtd--) {
            cin >> x;
            --x;
            g[x].push_back(i);
        }
    }

    forn (0, m) {
        cin >> pi[i];
    }

    cout << sol(0, 0) << endl;
}


Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
int main(){
	int a,b,c,d,an1=-1,an2=-1;
	cin>>a>>b>>c>>d;
	for(int i=0;i<=min(b,d);i++){
		if(i>=a&&i<=b&&i>=c&&i<=d&&an1==-1)an1=i;
		if(i>=a&&i<=b&&i>=c&&i<=d)an2=i;
	}
	cout<<an2-an1<<endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
struct Fast { Fast() { cin.tie(0); ios::sync_with_stdio(false); cout << fixed << setprecision(20);} } fast;

long long modpow(long long m, long long n) {
    if (n == 0) return 1;
    if (n % 2 == 0) {
        long long t = modpow(m, n / 2);
        return t / 2;
    } else {
        return modpow(m, n - 1) * m;
    }
}

int main() {
    long long n, min = 1e6, b = 0, ans = 1;
    cin >> n;
    vector<int>as(n);
    map<int, int> cnt;
    for (int i = 0; i < n; i++){
        cin >> as[i];
        cnt[as[i]]++;
        if (cnt[as[i]] > 1){
            cout << "NO" << endl;
            return 0;
        }
    }
    cout << "YES" << endl;
}

Measured memory_bytes: 10368
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int N,K;
  cin >> N >> K;
  vector<int> p(N);
  for(int i=0;i<N;i++){
    cin >> p.at(i);
  }
  
  sort(p.begin(),p.end());
  int minprice = 0;
  
  for(int i=0;i<K;i++){
    minprice+=p.at(i);
  }
  
  cout << minprice << endl;
  
}

Measured memory_bytes: 3428
#include <iostream>
#include <sstream>
#include <algorithm>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <stack>
#include <memory>
#include <complex>
#include <numeric>
#include <cstdio>
#include <iomanip>

#define REP(i,m,n) for(int i=int(m);i<int(n);i++)
#define RREP(i,m,n) for(int i=int(n)-1;i>=int(m);--i)
#define EACH(i,c) for (auto &(i): c)
#define all(c) begin(c),end(c)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort(begin(c),end(c))
#define pb emplace_back
#define MP make_pair
#define SZ(a) int((a).size())

#ifdef LOCAL
#define DEBUG(s) cout << (s) << endl
#define dump(x)  cerr << #x << " = " << (x) << endl
#define BR cout << endl;
#else
#define DEBUG(s) do{}while(0)
#define dump(x) do{}while(0)
#define BR 
#endif
using namespace std;

using UI = unsigned int;
using UL = unsigned long;
using LL = long long int;
using ULL = unsigned long long;
using VI = vector<int>;
using VVI = vector<VI>;
using VLL = vector<LL>;
using VS = vector<string>;
using PII = pair<int,int>;
using VP = vector<PII>;

//struct edge {int from, to, cost;};

constexpr double EPS = 1e-10;
constexpr double PI  = acos(-1.0);
//constexpr int INF = INT_MAX;

template<class T> inline T sqr(T x) {return x*x;}

void solve() {
    string s,t;
    cin >> s;
    t = s;
    int index = 0;
    REP(i,0,s.size()) {
        if (s[i] != 'B') t[index++] = s[i];
        else if (index > 0) --index;
    }
    cout << t.substr(0,index) << endl;
}

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

Measured memory_bytes: 256
using System;
using System.Text;
using System.Linq;
using System.Collections;
using System.Collections.Generic;
using static System.Console;
using static System.Math;

namespace AtCoder
{
    public class Program
    {
        public static void Main(string[] args)
        {
            new Program().Solve(new ConsoleInput(Console.In, ' '));
        }

        public void Solve(ConsoleInput cin)
        {
            var s = cin.Read;
          if (s != "AAA" && s != "BBB"){
            WriteLine("Yes");
          } else {
            WriteLine("No");
          }
        }
    }

    public class ConsoleInput
    {
        private readonly System.IO.TextReader _stream;
        private char _separator = ' ';
        private Queue<string> inputStream;
        public ConsoleInput(System.IO.TextReader stream, char separator = ' ')
        {
            this._separator = separator;
            this._stream = stream;
            inputStream = new Queue<string>();
        }
        public string Read
        {
            get
            {
                if (inputStream.Count != 0) return inputStream.Dequeue();
                string[] tmp = _stream.ReadLine().Split(_separator);
                for (int i = 0; i < tmp.Length; ++i)
                    inputStream.Enqueue(tmp[i]);
                return inputStream.Dequeue();
            }
        }
        public string ReadLine { get { return _stream.ReadLine(); }}
        public int ReadInt { get { return int.Parse(Read); }}
        public long ReadLong { get { return long.Parse(Read); }}
        public double ReadDouble { get { return double.Parse(Read); }}
        public string[] ReadStrArray(long N) { var ret = new string[N]; for (long i = 0; i < N; ++i) ret[i] = Read; return ret;}
        public int[] ReadIntArray(long N) { var ret = new int[N]; for (long i = 0; i < N; ++i) ret[i] = ReadInt; return ret;}
        public long[] ReadLongArray(long N) { var ret = new long[N]; for (long i = 0; i < N; ++i) ret[i] = ReadLong; return ret;}
    }
}

Measured memory_bytes: 13268
#include <bits/stdc++.h>
#define fst first
#define snd second
#define fore(i,a,b) for(int i=a,ThxDem=b;i<ThxDem;++i)
#define pb push_back
#define ALL(s) s.begin(),s.end()
#define FIN ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define SZ(s) int(s.size())
using namespace std;
typedef long long ll;
typedef pair<int,int> ii;

ll fpow(ll base, ll exp, ll MOD) {
	ll result = 1;
	while(exp){
		if(exp & 1) result = (result*base) % MOD;
		exp >>= 1;
		base = (base*base) % MOD;
	}
	return result;
}

int go(int x){
	int ans=0;
	while(x){
		ans++;
		x%=__builtin_popcount(x);
	}
	return ans;
}

int main(){FIN;
	int n; cin>>n;
	string s; cin>>s;
	int pc=0;
	for(auto x:s) pc+=x=='1';
	
	vector<int> pw1(n,1),pw2(n,1);
	fore(i,1,n){
		if(pc>1) pw1[i]=pw1[i-1]*2%(pc-1);
		pw2[i]=pw2[i-1]*2%(pc+1);
	}
	reverse(ALL(pw2));
	reverse(ALL(pw1));
	
	int ans1=0,ans2=0;
	fore(i,0,n) if(s[i]=='1'){
		if(pc>1) ans1=(ans1+pw1[i])%(pc-1);
		ans2=(ans2+pw2[i])%(pc+1);
	}
	
	fore(i,0,n){
		if(s[i]=='1'){
			int now=ans1,res=0;
			if(pc>1) now=(now-pw1[i]+(pc-1))%(pc-1),res++;
			res+=go(now);
			cout<<res<<"\n";
		}
		else{
			int now=ans2,res=0;
			now=(now+pw2[i])%(pc+1);
			res++;
			res+=go(now);
			
			cout<<res<<"\n";
		}
	}
	
	
}

Measured memory_bytes: 5192
#include<stdio.h>
int first[1000000];
int next[1000000];
int go[1000000];
int ans[1000000];
int visited[1000000];
int q[1000000];
int i,n,m,x,y,flag,re,t,l,r;

int main(){
	scanf("%d %d",&n,&m);
	for (i=1;i<=m;i++){
		scanf("%d %d",&x,&y);
		next[i]=first[x];
		first[x]=i;
		go[i]=y;
		next[i+m]=first[y];
		first[y]=i+m;
		go[i+m]=x;
	}
    l=0;r=1;
    q[1]=1;
    visited[1]=1;
    while (l<r){
    	l++;
    	re=q[l];
    	t=first[re];
    //	printf("%d\n",re);
    	while (t!=0){
    		if (visited[go[t]]==0){
    			visited[go[t]]=1;
    			r++;
    			q[r]=go[t];
    			ans[go[t]]=re;
			}
    		t=next[t];
		}
	}
    flag=0;
    for (i=2;i<=n;i++)
      if (visited[i]==0){
      	flag=1;
	  }
	if (flag==1){
		printf("No\n");
	}else{
	printf("Yes\n");
    for (i=2;i<=n;i++){
    	printf("%d\n",ans[i]);
	}
}
} 

Measured memory_bytes: 6360
#!/usr/bin/env python3
import sys

MOD = 1000000007  # type: int


def solve(H: int, W: int, a: "List[List[str]]"):
    dp = [[0] * W for _ in range(H)]
    dp[0][0] = 1
    for h in range(H):
        for w in range(W):
            if h == 0 and w == 0:
                dp[h][w] = 1
            elif h == 0:
                if a[h][0][w-1] == ".":
                    dp[h][w] = dp[h][w-1]
            elif w == 0:
                if a[h-1][0][w] == ".":
                    dp[h][w] = dp[h-1][w]
            else:
                if a[h-1][0][w] == "." and a[h][0][w-1] == ".":
                    dp[h][w] = (dp[h-1][w] + dp[h][w-1]) % MOD
                elif a[h-1][0][w] == ".":
                    dp[h][w] = dp[h-1][w]
                elif a[h][0][w-1] == ".":
                    dp[h][w] = dp[h][w-1]
    print(dp[-1][-1])
    return


# Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    H = int(next(tokens))  # type: int
    W = int(next(tokens))  # type: int
    a = [[next(tokens) for _ in range(1)]
         for _ in range(H)]  # type: "List[List[str]]"
    solve(H, W, a)


if __name__ == '__main__':
    main()


Measured memory_bytes: 51952
#include<iostream>
using namespace std;
char b;
int main(){
  cin >> b;
  if (b == 'A') cout << "T" << endl;
  else if (b == 'T') cout << "A" << endl;
  else if (b == 'G') cout << "C" << endl;
  else cout << "G" << endl;
  return 0;
}

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

int main(){
    int a, b;
    cin >> a >> b;
    if (a == b) {
        cout << "Draw" << "\n";
        return 0;
    }
    else if (a == 1 || b == 1) {
        cout << (a < b ? "Alice" : "Bob") << "\n";
    }
    else {
        cout << (a > b ? "Alice" : "Bob") << "\n";
    }
}

Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace AtCoder
{
    class E
    {
        public static void Main()
        {
            var np = Console.ReadLine().Split(' ').Select(v => int.Parse(v)).ToArray();
            int n = np[0];
            int p = np[1];

            string s = Console.ReadLine();

            long count = 0;

            if (p == 2 || p == 5)
            {
                for (int i = 0; i < s.Length; i++)
                    if ((s[i] - '0') % p == 0)
                        count += i + 1;
            }
            else
            {
                var countMod = new long[p];
                int digit = 1;
                int r = 0;
                for (int i = s.Length - 1; i >= 0; i--)
                {
                    r = (digit * (s[i] - '0') + r) % p;
                    countMod[r]++;
                    digit = digit * 10 % p;
                }

                count = countMod[0];
                for (int i = 0; i < p; i++)
                    count += countMod[i] * (countMod[i] - 1) / 2;
            }
            Console.WriteLine(count);
        }
    }
}


Measured memory_bytes: 13920
function Main(input) {
  input = input.split("\n");
  const n = parseInt(input[0],10);
  const txy = [];
  const changeInt = (n) => {
    return parseInt(n, 10);
  };
  for (var i = 0; i < n; i++) {
    txy.push(input[i+1].split(' ').map(changeInt));
  }
  console.log(travelcheck(n,txy)? "Yes":"No")
}
Main(require("fs").readFileSync("/dev/stdin", "utf8"));

function travelcheck(n,txy) {
  let dt = 0;
  let dist = 0;
  for (var t_i = 0; t_i < n; t_i++) {
    if (t_i === 0) {
      dt = txy[t_i][0];
      dist = txy[t_i][1] + txy[t_i][2];
    } else {
      dt = txy[t_i][0] - txy[t_i-1][0];
      dist = Math.abs(txy[t_i][1] - txy[t_i-1][1]) + Math.abs(txy[t_i][2] - txy[t_i-1][2]);
    }
    if (dist > dt) {
      return false;
    } else if (dist % 2 !== dt % 2) {
      return false;
    }
  }
  return true;
}


Measured memory_bytes: 62124
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <numeric>
#include <string>
#include <sstream>
#include <complex>
#include <vector>
#include <array>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
using namespace std;
typedef long long unsigned int ll;

#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))

int main(){

   int n;
   cin >> n;
   int ans=0;
   for(int i=1; i <= n; i++){
      int cnt = 0;
      if (not(i % 2 == 0)){
         for(int j=1; j <= i; j++){
            if(i % j == 0){
               cnt++;
            }
         }
      }
      if(cnt == 8){
         ans++;
      }
   }
   cout << ans << endl;

   return 0;
}

Measured memory_bytes: 888