akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;
#define MAXN	20
#define MAXS	65536
#define P	1000000007
template <typename T> void read(T &x) {
	x = 0; int f = 1;
	char c = getchar();
	for (; !isdigit(c); c = getchar()) if (c == '-') f = -f;
	for (; isdigit(c); c = getchar()) x = x * 10 + c - '0';
	x *= f;
}
vector <int> a[MAXN];
long long ans[MAXS];
long long f[MAXN][MAXS], g[MAXN][MAXS];
void update(long long &x, long long y) {
	x = (x + y) % P;
}
int main() {
	int n, m;
	read(n), read(m);
	for (int i = 1; i <= m; i++) {
		int x, y;
		read(x), read(y);
		a[x].push_back(y);
	}
	int goal = (1 << n) - 1;
	for (int s = 0; s <= goal; s++)
	for (int i = 1; i <= n; i++) {
		int tmp = 0;
		for (unsigned j = 0; j < a[i].size(); j++) {
			int tj = 1 << a[i][j] - 1;
			if (tj & s) tmp++;
		}
		f[i][s] = 1 << tmp;
		g[i][s] = f[i][s] - 1;
	}
	ans[0] = 1;
	for (int s = 1; s <= goal; s++) {
		if ((s & 1) != ((s & 2) >> 1)) continue;
		for (int t = s, b = 0; t != 0; t = (t - 1) & s, b = s ^ t) {
			if ((t & 1) != ((t & 2) >> 1)) continue;
			long long tmp = ans[b];
			for (int i = 1, j = 1; i <= n; i++, j <<= 1) {
				if (j & t) tmp = tmp * f[i][b] % P;
				if (j & b) tmp = tmp * g[i][t] % P;
			}
			update(ans[s], tmp);
		}
	}
	long long finalans = 1;
	for (int i = 1; i <= m; i++)
		finalans = finalans * 2 % P;
	finalans = (finalans - ans[goal] + P) % P;
	cout << finalans << endl;
	return 0;
}

Measured memory_bytes: 15616
#include<stdio.h>                                                 
                                                                  
int main(void){                                                   
   int N,X,T;                                                     
   int sumTime;                                                   
   scanf("%d %d %d",&N,&X,&T);                                    
                                                                  
   if(N <= X){                                                    
      sumTime = T;                                                
   } else {                                                       
      if(N % X == 0){                                             
         sumTime = (N / X)*T;                                     
      }else if(N % X != 0){                                       
         sumTime = (N/X)*T+T;                                     
      }                                                           
   }                                                              
   printf("%d",sumTime);                                          
   return 0;                                                      
} 

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

int V, E;

void dfs(vector<vector<int>> &G, int p, int u, int d, vector<int> &depth, vector<int> &lowlink, vector<bool> &visited){
    visited[u] = true;
    depth[u] = lowlink[u] = d;
    
    for(auto v: G[u]) if(v != p){
        if(!visited[v]){
            dfs(G, u, v, d+1, depth, lowlink, visited);
            lowlink[u] = min(lowlink[u], lowlink[v]);
        }else{
            lowlink[u] = min(lowlink[u], depth[v]);
        }
    }
}

int main(){
    cin >> V >> E;
    
    vector<vector<int>> G(V);
    for(int i=0; i<E; i++){
        int s, t; cin >> s >> t;
        G[s].push_back(t);
        G[t].push_back(s);
    }
    for(int i=0; i<V; i++)
        sort(G[i].begin(), G[i].end());
    
    vector<int> depth(V, -1), lowlink(V, -1);
    vector<bool> visited(V, false);
    dfs(G, -1, 0, 0, depth, lowlink, visited);
    
    for(int s=0; s<V; s++){
        for(auto t: G[s]) if(s<t && (depth[s]<lowlink[t]||depth[t]<lowlink[s])){
            cout << s << " " << t << endl;
        }
    }
    
    return 0;
}

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


ll gcd(ll x, ll y)
{
    ll temp;
    while (y != 0) {
        temp = y;
        y = x % y;
        x = temp;
    }
    return (x);
}

ll lcm( ll m, ll n )
{
	// 引数に０がある場合は０を返す
	if ( ( 0 == m ) || ( 0 == n ) )
		return 0;
	
	return ((m / gcd(m, n)) * n); // lcm = m * n / gcd(m,n)
}//lcm


int main() {
  int n,k;
  cin >> n >> k;
  int a[n];
  FOR(i,0,n-1) cin >> a[i];

  int gcdnum;
  int maxnum = 1;

  FOR(i,0,n-1){
    if(i==0) gcdnum = a[i];
    gcdnum = gcd(gcdnum,a[i]);
    chmax(maxnum,a[i]);
  }

  if(k%gcdnum==0 && k<=maxnum) cout << "POSSIBLE" << endl;
  else cout << "IMPOSSIBLE" << endl;

}



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

#define int long long
using namespace std;
#define vi vector<int>
int pa(int n){
	return n*(n+1) / 2;
}
main(){
	int n,k;
	cin >> n >> k;
	vi a(n);
	for(int &x : a ) cin >> x;
	vi qnt(n);
	vi qnta(n);
	for(int i=0;i<n;i++){
		for(int j=i+1;j<n;j++){
			if(a[j] < a[i]) qnt[i]++;
		}
		for(int j=i-1;j>=0;j--){
			if(a[j] < a[i]) qnta[i]++;
		}
	}
	int ans = 0;
	const int M = 1e9 + 7;
	int val = (k*k - pa(k-1))%M;
	int val2 = ((k-1)*k - pa(k-1)) %M;
	for(int i=0;i<n;i++){
		ans = (ans + val * qnt[i])%M;
		ans = (ans + val2 * qnta[i])%M;
	}
	cout << ans << endl;
}

Measured memory_bytes: 256
#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <fstream>
#include <sstream>
#include <set>
#include <map>
#include <vector>
#include <list>
#include <algorithm>
#include <cstring>
#include <cmath>
#include <string>
#include <stack>
#include <queue>
#include <bitset>     //UWAGA - w czasie kompilacji musi byc znany rozmiar wektora - nie mozna go zmienic
#include <cassert>
#include <iomanip>        //do setprecision
#include <ctime>
#include <complex>
using namespace std;

#define FOR(i,b,e) for(int i=(b);i<(e);++i)
#define FORQ(i,b,e) for(int i=(b);i<=(e);++i)
#define FORD(i,b,e) for(int i=(b)-1;i>=(e);--i)
#define REP(x, n) for(int x = 0; x < (n); ++x)

#define ST first
#define ND second
#define PB push_back
#define PF push_front
#define MP make_pair
#define LL long long
#define ULL unsigned LL
#define LD long double
#define pii pair<int,int>
#define pll pair<LL,LL>
#define vi vector<int>
#define vii vector<vi>

const double pi = 3.14159265358979323846264;
const int mod=1000000007;

int main(){
	 //cin.tie(0);
	//ios::sync_with_stdio(false);
	//std::cout << std::fixed;
	//std::cout << std::setprecision(12);
	//std::cout << std::defaultfloat;
	string s;
	cin>>s;
	int c=1;
	int l=s.length();
	s="A"+s+"A";
	vector<vector<LL>> dp(l+10,vector<LL>(2,0));
	dp[0][0]=1;
	FOR(i,0,l){
		dp[i+2][1]=max(dp[i+2][1],max(dp[i][0],dp[i][1])+1);
		if(s[i]!=s[i+1]){
			dp[i+1][0]=max(max(dp[i][0],dp[i][1])+1,dp[i+1][0]);
		}else{
			dp[i+1][0]=max(dp[i][1]+1,dp[i+1][0]);
		}
	}
	cout<<max(dp[l][0],dp[l][1])-1<<endl;

	return 0;
}


Measured memory_bytes: 11328
#include<iostream>
#include<cstdio>
#include<cstring>
#include <cstdlib>  
#include <cmath>   
#include<cctype>
#include<string>
#include<set>
#include <map>
#include<algorithm>
#include <functional>
#include<vector>
#include<climits>
#include<stack>
#include<queue>
#include <deque>
#include <typeinfo>
#include <utility> 
#define all(x) (x).begin(),(x).end()
#define rep(i,m,n) for(int i = m;i < n;++i)
using namespace std;
using ll = long long;
using R = double;
const ll inf = 1LL << 50;
const ll MOD = 1e9 + 7;

string s;


int main() {
	cin >> s;
	char last = s[s.size() - 1];
	char first = s[0];


	if (last != first) {
		if (s.size() % 2 == 0) {
			cout << "Second" << endl;
		}
		else {
			cout << "First" << endl;
		}
	}
	else {
		if (s.size() % 2 == 0) {
			cout << "First" << endl;
		}
		else {
			cout << "Second" << endl;
		}

	}


	return 0;
}

Measured memory_bytes: 512
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>

using namespace std;

int main() {
	int d;
	cin >> d;
	int x, y;
	cin >> x;
	vector<int> d1;
	string s;
	int ss;
	for (int i = 0; i < x; i++) {
		cin >> s >> ss;
		if (s == "D") {
			d1.push_back(ss);
		}
	}
	cin >> y;
	vector<int> d2;
	for (int i = 0; i < y; i++) {
		cin >> s >> ss;
		if (s == "DD") {
			d2.push_back(ss);
		}
	}
	sort(d1.begin(), d1.end(), greater<int>());
	sort(d2.begin(), d2.end(), greater<int>());
	int a, b, al, bl;
	a = b = 0;
	al = d1.size();
	bl = d2.size();
	int sum = 0;
	while (d > 0) {
		if (d >= 2) {
			if (b < bl) {
				if (a+1 < al) {
					if (d2[b] >= d1[a]+d1[a+1]) {
						sum += d2[b];
						b++;
						d -= 2;
					} else {
						sum += d1[a];
						a++;
						d--;
					}
				} else if (a < al) {
					if (d2[b] > d1[a]) {
						sum += d2[b];
						b++;
						d -= 2;
					} else {
						sum += d1[a];
						a++;
						d--;
					}
				} else {
					sum += d2[b];
					b++;
					d -= 2;
				}
			} else {
				if (a < al) {
					sum += d1[a];
					a++;
					d--;
				} else {
					break;
				}
			}
		} else {
			if (a < al) {
				sum += d1[a];
				a++;
				d--;
			} else {
				break;
			}
		}
	}
	cout << sum << endl;
	return 0;
}

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

const char* judge_right_triangle(int, int, int);

int main(void)
{
    int a, b, c, n;
    cin >> n;
    for (int i = 0; i < n; i++ ) {
        cin >> a >> b >> c;
        cout << judge_right_triangle(a, b, c) << endl;
    }
    return 0;
}

const char* judge_right_triangle(int a, int b, int c)
{
    if ((a * a + b * b == c * c || b * b + c * c == a * a) || c * c + a * a == b * b) {
        return "YES";
    } else {
        return "NO";
    }
}

Measured memory_bytes: 1156
package main

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

var (
	readString func() string
	stdout     *bufio.Writer
)

func init() {
	readString = newReadString(os.Stdin)
	stdout = bufio.NewWriter(os.Stdout)
}

func newReadString(ior io.Reader) func() string {
	r := bufio.NewScanner(ior)
	r.Buffer(make([]byte, 1024), int(1e+11))
	r.Split(bufio.ScanWords)

	return func() string {
		if !r.Scan() {
			panic("Scan failed")
		}
		return r.Text()
	}
}

func readInt() int {
	return int(readInt64())
}

func readInt64() int64 {
	i, err := strconv.ParseInt(readString(), 0, 64)
	if err != nil {
		panic(err.Error())
	}
	return i
}

func readIntSlice(n int) []int {
	b := make([]int, n)
	for i := 0; i < n; i++ {
		b[i] = readInt()
	}
	return b
}

func readLengthAndSlice() []int {
	n := readInt()
	return readIntSlice(n)
}

func printf(f string, args ...interface{}) (int, error) {
	return fmt.Fprintf(stdout, f, args...)
}

func println(args ...interface{}) (int, error) {
	return fmt.Fprintln(stdout, args...)
}

func minInt(a, b int) int {
	if a < b {
		return a
	}
	return b
}

func minUint(a, b uint) uint {
	if a < b {
		return a
	}
	return b
}

func minInt64(a, b int64) int64 {
	if a < b {
		return a
	}
	return b
}

func minUint64(a, b uint64) uint64 {
	if a < b {
		return a
	}
	return b
}

func maxInt(a, b int) int {
	if a < b {
		return b
	}
	return a
}

func maxUint(a, b uint) uint {
	if a < b {
		return b
	}
	return a
}
func maxInt64(a, b int64) int64 {
	if a < b {
		return b
	}
	return a
}

func maxUint64(a, b uint64) uint64 {
	if a < b {
		return b
	}
	return a
}

func absInt(a int) int {
	if a < 0 {
		return -a
	}
	return a
}

func absInt64(a int64) int64 {
	if a < 0 {
		return -a
	}
	return a
}

// readString() string
// readInt() int
// readIntSlice(n int) []int
// readLengthAndSlice() []int
func main() {
	defer stdout.Flush()

	S := readString()
	m := make(map[rune]bool)
	ans := "yes"
	for _, r := range S {
		if m[r] {
			ans = "no"
		}
		m[r] = true
	}
	println(ans)
}


Measured memory_bytes: 640
#include <iostream>
#include <vector>
#include <cstdio>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <cmath>
#include <set>
#include <algorithm>

using namespace std;

typedef long long ll;

int main() {
	ios_base::sync_with_stdio(0); cin.tie(0);
	int N;
	cin >> N;
	set<int> A = {2, 4, 5, 7, 9};
	if (N%10 == 3){
		cout << "bon" << endl;
	}else if(A.find(N%10) != A.end()){
		cout << "hon" << endl;
	}else{
		cout << "pon" << endl;
	}
	return 0;
}


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

using namespace std;
using ll =long long;

#define SORT(a) sort((a).begin(),(a).end())
#define rSORT(a) reverse((a).begin(),(a).end())
#define For(i, a, b)    for(int i = (a) ; i < (b) ; ++i)
#define rep(i, n)       For(i, 0, n)
#define debug(x)  cout << #x << " = " << (x) << endl;
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
bool coY() {cout <<"Yes"<<endl;}
bool coN(){cout <<"No"<<endl;}

const ll INF = 1LL << 60;

ll n,m;
string s;
//Write From this Line

const int mod = 1e9+7;
int main()
{
	cin >> n >> m;
	int a[n];
	rep(i,n) cin >> a[i];
	priority_queue<pair<int,int>> q;
	rep(i,n){
		q.push(make_pair(a[i],1));
	}
	int b[m] ,c[m];
	rep(i,m){
		cin >>b[i] >> c[i] ;
	}
	rep(i,m){
		q.push(make_pair(c[i],b[i]));
	}
	ll ans = 0 ;
	rep(i,n){
		auto p = q.top();
		q.pop();
		ans += p.first ;
		if(p.second > 1){
			p.second -- ;
			q.push(p);
		}
	}
	cout << ans << endl;

}


Measured memory_bytes: 3572
import java.util.Scanner;
public class Main {
	static Scanner scan=new Scanner(System.in);
	static int gcd (int a, int b) {return b>0?gcd(b,a%b):a;}
	static long lcm (int a, int b) {return a*b/gcd(a,b);}
	static int max(int a,int b) {return a>b?a:b;}
	static int min(int a,int b) {return a<b?a:b;}
	static long factorial(int i) {return i==1?1:i*factorial(i-1);}
	static int lower_bound(int a[],int key) {
		int low=0,high=a.length;
		while(low<high) {
			int mid=((high-low)/2)+low;
			if(a[mid]<=key)low=mid+1;
			else high=mid;
		}
		return high;
		}
	static int upper_bound(int a[],int key) {
		int low=0,high=a.length;
		while(low<high) {
			int mid=((high-low)/2)+low;
			if(a[mid]<key)low=mid+1;
			else high=mid;
		}
		return high;
		}
	static boolean isPrime (int n) {
		if (n==2) return true;
		if (n<2 || n%2==0) return false;
		double d = Math.sqrt(n);
		for (int i=3; i<=d; i+=2)if(n%i==0){return false;}
		return true;
	}
		public static void main(String[] args) {
			String str=scan.next();
			char ch1=str.charAt(0);
			char ch2=str.charAt(1);
			char ch3=str.charAt(2);
			char ch4=str.charAt(3);
			if(ch1==ch2&&ch1==ch3&&ch1==ch4) {
				System.out.println("No");
				return;
			}
			if(ch1==ch2) {
				if(ch3==ch4) {
					System.out.println("Yes");
					return;
				}
			}
			else if(ch1==ch3) {
				if(ch2==ch4) {
					System.out.println("Yes");
					return;
				}
			}
			else if(ch1==ch4) {
				if(ch2==ch3) {
					System.out.println("Yes");
					return;
				}
			}
			else if(ch2==ch3) {
				if(ch1==ch4) {
					System.out.println("Yes");
					return;
				}
			}
			else if(ch2==ch4) {
				if(ch1==ch3) {
					System.out.println("Yes");
					return;
				}
			}
			else if(ch3==ch4) { 
				if(ch1==ch2) {
					System.out.println("Yes");
					return;
				}
			}
			System.out.println("No");
		}
}


Measured memory_bytes: 21716
#include <iostream>
#include <cmath>
#include <algorithm>
#include <vector>
using namespace std;
typedef long long ll;
typedef vector<ll> vll;
typedef pair<ll, ll> pll;
typedef vector<pll> vpll;

int main () {
	ll N, K;
    cin >> N >> K;
    vpll vp;
    for(int i = 0; i < N; i++)
    {
        ll a,b;
        cin >> a >> b;
        vp.push_back(make_pair(a, b));
    }
    sort(vp.begin(), vp.end());
    vll s = {0LL};
    for(int i = 0; i < N; i++) {
        s.push_back(s[i] + vp[i].second);
    }
    // 二分探索
    ll arg = distance(s.begin(), upper_bound(s.begin(), s.end(), K - 1)) - 1;
    cout << vp[arg].first << endl;
}

Measured memory_bytes: 3568
#include <bits/stdc++.h>
using namespace std;
#define F first
#define S second
#define R cin>>
#define Z class
#define ll long long
#define ln cout<<'\n'
#define in(a) insert(a)
#define pb(a) push_back(a)
#define pd(a) printf("%.10f\n",a)
#define mem(a) memset(a,0,sizeof(a))
#define all(c) (c).begin(),(c).end()
#define iter(c) __typeof((c).begin())
#define rrep(i,n) for(ll i=(ll)(n)-1;i>=0;i--)
#define REP(i,m,n) for(ll i=(ll)(m);i<(ll)(n);i++)
#define rep(i,n) REP(i,0,n)
#define tr(it,c) for(iter(c) it=(c).begin();it!=(c).end();it++)
template<Z A>void pr(A a){cout<<a;ln;}
template<Z A,Z B>void pr(A a,B b){cout<<a<<' ';pr(b);}
template<Z A,Z B,Z C>void pr(A a,B b,C c){cout<<a<<' ';pr(b,c);}
template<Z A,Z B,Z C,Z D>void pr(A a,B b,C c,D d){cout<<a<<' ';pr(b,c,d);}
template<Z A>void PR(A a,ll n){rep(i,n){if(i)cout<<' ';cout<<a[i];}ln;}
ll check(ll n,ll m,ll x,ll y){return x>=0&&x<n&&y>=0&&y<m;}
const ll MAX=1e9+7,MAXL=1LL<<61,dx[4]={-1,0,1,0},dy[4]={0,1,0,-1};
typedef pair<int,int> P;

void Main() {
  ll n;
  R n;
  ll a[n];
  rep(i,n) R a[i];
  sort(a,a+n);
  double m=(double)a[n-1]/2;
  ll k=lower_bound(a,a+n,m)-a;
  ll x=-1;
  double ans=MAX;
  if(k!=n-1) {
    x=a[k];
    ans=fabs(m-x);
  }
  k--;
  if(0<=k) {
    if(fabs(m-a[k])<ans) x=a[k];
  }
  pr(a[n-1],x);
}

int main(){ios::sync_with_stdio(0);cin.tie(0);Main();return 0;}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define P pair<int,int>
using ll=int64_t;
using namespace std;
#define ketasuu(n) fixed<<setprecision(n)
#define btoe(p) p.begin(),p.end()
#define etob(p) p.rbegin(),p.rend()




int main(){
    int n,k;
    cin>>n>>k;
    string s;
    cin>>s;
    char a=s[k-1];
    if(a=='A') s[k-1]='a';
    if(a=='B') s[k-1]='b';
    if(a=='C') s[k-1]='c';
    cout<<s<<endl;
}

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

#define MAX 1000

char X[MAX], Y[MAX];

int LCS() {
	int i, j;
	int m = strlen(X);
	int n = strlen(Y);
	int c[m + 1][n + 1];

	for (i = 1; i <= m; i++) c[i][0] = 0;
	for (j = 0; j <= n; j++) c[0][j] = 0;

	for (i = 1; i <= m; i++) {
		for (j = 1; j <= n; j++) {
			if (X[i - 1] == Y[j - 1]) {
				c[i][j] = c[i - 1][j - 1] + 1;
			} else if (c[i - 1][j] >= c[i][j - 1]) {
				c[i][j] = c[i - 1][j];
			} else {
				c[i][j] = c[i][j - 1];
			}
		}
	}

	return c[m][n];
}

main() {
	int n, i;

	scanf("%d", &n);
	for (i = 0; i < n; i++) {
		scanf("%s%s", X, Y);
		printf("%d\n", LCS());
	}

	return 0;
}

Measured memory_bytes: 4512
import sys
sys.setrecursionlimit(1 << 25)
readline = sys.stdin.buffer.readline
read = sys.stdin.readline  # 文字列読み込む時はこっち
ra = range
enu = enumerate


def exit(*argv, **kwarg):
    print(*argv, **kwarg)
    sys.exit()


def mina(*argv, sub=1): return list(map(lambda x: x - sub, argv))
# 受け渡されたすべての要素からsubだけ引く.リストを*をつけて展開しておくこと


def a_int(): return int(readline())


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


def read_col(H):
    '''H is number of rows
    A列、B列が与えられるようなとき
    ex1)A,B=read_col(H)    ex2) A,=read_col(H) #一列の場合'''
    ret = []
    for _ in range(H):
        ret.append(list(map(int, readline().split())))
    return tuple(map(list, zip(*ret)))


def read_tuple(H):
    '''H is number of rows'''
    ret = []
    for _ in range(H):
        ret.append(tuple(map(int, readline().split())))
    return ret


def read_matrix(H):
    '''H is number of rows'''
    ret = []
    for _ in range(H):
        ret.append(list(map(int, readline().split())))
    return ret
    # return [list(map(int, read().split())) for _ in range(H)] # 内包表記はpypyでは遅いため


MOD = 10**9 + 7
INF = 2**31  # 2147483648 > 10**9
# default import
from collections import defaultdict, Counter, deque
from operator import itemgetter, xor, add
from itertools import product, permutations, combinations
from bisect import bisect_left, bisect_right  # , insort_left, insort_right
from functools import reduce
from math import gcd


def lcm(a, b):
    # 最小公倍数
    g = gcd(a, b)
    return a // g * b


N = a_int()
X = read()[:-1]
tmp = X.count('1')  # Xの1の数
X = list(map(int, list(X[::-1])))


# オリジナルをpop(X)+-1で割ったものを作っておく
Xmodpop = [0, 0, 0]
for i, x in enumerate(X):
    if x:
        Xmodpop[1] += pow(2, i, tmp + 1)
        if tmp != 1:
            Xmodpop[-1] += pow(2, i, tmp - 1)
Xmodpop[1] %= tmp + 1
if tmp != 1:
    Xmodpop[-1] %= tmp - 1

X_nex = []  # 一度操作したあとの値
for i in range(N):
    if X[i] == 1:
        if tmp == 1:
            X_nex.append(-1)
            continue
        X_nex.append((Xmodpop[-1] - pow(2, i, tmp - 1)) % (tmp - 1))
    else:
        X_nex.append((Xmodpop[1] + pow(2, i, tmp + 1)) % (tmp + 1))

# 愚直に操作
ans = []
for i in range(N):
    n = X_nex[i]
    if n == -1:
        ans.append(0)
        continue
    cnt = 1
    while n:
        popc = bin(n).count('1')
        n %= popc
        cnt += 1
    ans.append(cnt)

print(*ans[::-1], sep='\n')


Measured memory_bytes: 125776
import java.util.Scanner;
public class Main {

	public static void main(String[] args) {

    Scanner in =new Scanner(System.in);
     int a =in.nextInt();
     int b =in.nextInt();
     int c =in.nextInt();
     int d =a+b;
     int e =a+c;
     int f =b+c;
     if(d>=e) {
    	 if(e>=f) {
    		 System.out.println(f);
    		 }
          else {
    			 System.out.println(e);

    		    }

     }
     else  {
    	 if(d>=f) {
    		 System.out.println(f);

    	 }
    	 else {
    		 System.out.println(d);
    	 }
     }


      }





}


Measured memory_bytes: 21716
using System;
using System.Collections.Generic;
using System.Linq;

namespace ConsoleApp1
{
	class Program
	{
		static void Main(string[] args)
		{
			var inputs = Console.ReadLine().Split(' ').Select(input => int.Parse(input)).ToArray();
			var n = inputs[0];
			var m = inputs[1];
			var x = inputs[2];
			var y = inputs[3];
			var xMax = Console.ReadLine().Split(' ').Select(input => int.Parse(input)).Concat(new[] { x }).Max();
			var yMin = Console.ReadLine().Split(' ').Select(input => int.Parse(input)).Concat(new[] { y }).Min();

			Console.WriteLine(xMax < yMin ? "No War" : "War");
		}
	}

}


Measured memory_bytes: 13396
#include <bits/stdc++.h>
#define LL long long
#define PII pair<int, int>
#define f first
#define s second 
using namespace std;

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

	LL n, mod;
	cin >> n >> mod;
	vector<vector<LL>> dp(3 * n + 1, vector<LL>(3 * n + 1));
	
	dp[0][0] = 1;
	for (int i = 1; i <= 3 * n; i++) {
		for (int j = 0; j <= i; j++) {
			dp[i][j] = dp[i - 1][j];
			if (i >= 2 && j > 0) {
				dp[i][j] += dp[i - 2][j - 1] * (i - 1) % mod;
			}
			if (i >= 3 && j > 0) {
				dp[i][j] += dp[i - 3][j - 1] * (i - 1) % mod * (i - 2) % mod;
			}
			dp[i][j] %= mod;
//			cout << i << ' ' << j << " -> " << dp[i][j] << '\n';
		}
	}
	
	LL ans = 0;
	for (int i = 0; i <= n; i++) {
		ans = (ans + dp[3 * n][i]) % mod;
	}
	
	cout << ans << '\n';

	return 0;
}

Measured memory_bytes: 281856
# Here your code !
a, b, c, de, e ,f = gets.chomp.split.map &:to_i
t = Array.new(30, 0)
t[0] = 1
max = 0
i = 0
while true
  (li = i + a)
  t[li] = 1 if(li < 30 and t[i] == 1)
  (li = i + b)
  t[li] = 1 if(li< 30 and t[i] == 1)
  i += 1
  break if(i == 30)
end
tt = Array.new(3001, 0)
i = 0
tt[0] = 1
while true
  (li = i + c)
  tt[li] = 1 if(li < 3001 and tt[i] == 1)
  (li = i + de)
  tt[li] = 1 if(li < 3001 and tt[i] == 1)
  i += 1
  break if(i == 3001)
end
ans = [a*100, 0]
i = 0
at = []
tt.each.with_index do |d, i|
  if(d == 1)
    at.push(i)
  end
end
aat = []
t.each.with_index do |d, i|
  if(d == 1)
    aat.push(i)
  end
end
ni = 0
aat.delete(0)
at.each do |d|
  dd = aat[ni] * e
  while(dd < d)
    if(ni >= aat.size - 1)
      puts "#{ans[0]} #{ans[1]}"
      exit
    end
    ni += 1
    dd = aat[ni] * e
  end
  if(aat[ni]*100 + d <= f and d  <= dd)
    if(max <= d/(aat[ni].to_f * 100 + d))
      ans = [aat[ni]*100 + d, d]
      (max = d/(aat[ni].to_f * 100 + d))
    end
  end
end
puts "#{ans[0]} #{ans[1]}"


Measured memory_bytes: 1916
#include <iostream>
#include <cstdint>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <cctype>
#include <cassert>
#include <climits>
#include <string>
#include <bitset>
#include <cfloat>
#include <unordered_set>
#pragma GCC optimize("Ofast")
using namespace std;
typedef long double ld;
typedef long long int ll;
typedef unsigned long long int ull;
typedef vector<int> vi;
typedef vector<char> vc;
typedef vector<bool> vb;
typedef vector<double> vd;
typedef vector<string> vs;
typedef vector<ll> vll;
typedef vector<pair<int, int>> vpii;
typedef vector<vector<int>> vvi;
typedef vector<vector<char>> vvc;
typedef vector<vector<string>> vvs;
typedef vector<vector<ll>> vvll;

#define rep(i, n) for (ll i = 0; i < (n); ++i)
#define rrep(i, n) for (ll i = 1; i <= (n); ++i)
#define irep(it, stl) for (auto it = stl.begin(); it != stl.end(); it++)
#define drep(i, n) for (ll i = (n)-1; i >= 0; --i)
#define mes(a) cout << (a) << endl
#define dmes(a, b) cout << (a) << " " << (b) << endl
#define re0 return 0
#define mp(p, q) make_pair(p, q)
#define pb(n) push_back(n)
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define Sort(a) sort(a.begin(), a.end())
#define rSort(a) sort(a.rbegin(), a.rend())
#define Rev(a) reverse(a.begin(), a.end())
#define MATHPI acos(-1)
#define itn int
int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};
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;
}
struct io
{
    io()
    {
        ios::sync_with_stdio(false);
        cin.tie(0);
    }
};
const int INF = INT_MAX;
const ll LLINF = 1LL << 60;
const ll MOD = 1000000007;
const double EPS = 1e-19;


signed main() {
    ll n;
    cin >> n;
    
    vll v(n);
    vll c(n);
    
    ll r = 0;
    
    
    rep(i, n) {
        cin >> v[i];
    }
    rep(i, n) {
        cin >> c[i];
        if (v[i] - c[i] >= 0) r += v[i] - c[i];
    }
    
    mes(r);
    
    
    
}

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

int main() {
  string s;
  cin >> s;
  rep(i,0,s.size()-8) cout << s[i];
  cout << "" << endl;
}

Measured memory_bytes: 3576
#include <bits/stdc++.h>
#define int long long
#define mod (int)(1e9+7)
#define inf (int)(3e18+7)
#define rep(i,n) for(int i=0;i<n;i++)
#define REP(i,n) for(int i=1;i<n;i++)
#define P pair<int,int>
#define PiP pair<int,pair<int,int>>
#define all(v) v.begin(),v.end()
#define mkp make_pair
#define mkt make_tuple
#define prique(T) priority_queue<T,vector<T>,greater<T>>
#define vecunique(vec) sort(vec.begin(), vec.end());decltype(vec)::iterator result = std::unique(vec.begin(), vec.end());vec.erase(result, vec.end())
using namespace std;

bool prime(int x) {
	for (int i = 2; i * i <= x; i++) {
		if (x % i == 0)return false;
	}
	return x > 1;
}
int gcd(int x, int y) {
	if (y == 0)return x;
	return gcd(y, x % y);
}
int lcm(int x, int y) {
	return x / gcd(x, y) * y;
}
int kai(int x, int y) {
	int res = 1;
	for (int i = x - y + 1; i <= x; i++) {
		res *= i; res %= mod;
	}
	return res;
}
int mod_pow(int x, int y) {
	int res = 1;
	while (y > 0) {
		if (y & 1) {
			res = res * x % mod;
		}
		x = x * x % mod;
		y >>= 1;
	}
	return res;
}
int comb(int x, int y) {
	if (y > x)return 0;
	return kai(x, y) * mod_pow(kai(y, y), mod - 2) % mod;
}
/*--------Library Zone!--------*/


signed main() {
	int n, m; cin >> n >> m;
	if (m > (n - 1) * (n - 2) / 2) {
		cout << -1 << endl; return 0;
	}
	vector<P>con;
	for (int i = 2; i <= n; i++) {
		for (int j = i + 1; j <= n; j++)con.push_back({ i,j });
	}
	vector<P>edge;
	for (int i = 2; i <= n; i++) {
		edge.push_back({ 1,i });
	}
	int memo = (n - 1) * (n - 2) / 2 - m;
	rep(i, memo) {
		edge.push_back(con[i]);
	}
	cout << edge.size() << endl;
	rep(i, edge.size()) {
		cout << edge[i].first << " " << edge[i].second << endl;
	}
}

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

int main(){
  ll n, x, m;
  cin >> n >> x >> m;
  vector<bool> mgp(m, false);
  mgp.at(x) = true;
  int loop_find = -1;
  ll ans = x;
  for(ll i = 1; i < n; i++){
    x = (x*x) % m;
    if(mgp.at(x) == true){
      loop_find = x;
      n -= i;
      break;
    }else{
      mgp.at(x) = true;
      ans += x;
    }
  }
  if(loop_find == -1){
    cout << ans << endl;
    return 0;
  }

  ll looptot = -1;
  int sz = 0;
  x = loop_find;
  while(!(looptot != -1 && x == loop_find)){
    if(looptot == -1) looptot = 0;
    looptot += x;
    x = (x*x) % m;
    sz++;
  }
  ans += n/sz*looptot;
  n %= sz;
  rep(i, n){
    ans += x;
    x = (x*x) % m;
  }
  cout << ans << endl;

  return 0;
}

Measured memory_bytes: 3636
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
int n,w;
void copy(ll *arr1,ll *arr2){
    arr2[0]=0;
    for(int i=0;i<=w;i++)arr1[i]=arr2[i];
}
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cin>>n>>w;
    int weight[n],value[n];
    ll dp1[w+1],dp2[w+1];
    for(int i=0;i<=w;i++)dp1[i]=0;
    for(int i=0;i<n;i++){
        int x,y;
        cin>>x>>y;
        bool visited[w+1];
        memset(visited,false,sizeof(visited));
        for(int j=0;j<=w;j++){
            if(j+x>w){
                if(visited[j]==false)dp2[j]=dp1[j];
                continue;
            }
            if(j!=0&&dp1[j]==0){
                if(visited[j]==false)dp2[j]=0;
                continue;
            }
            visited[j+x]=true;
            dp2[j+x]=max(max(dp1[j+x],dp1[j]+y),dp1[j]);
        }
        copy(dp1,dp2);
    }
    ll ans=0;
    for(int i=1;i<=w;i++)ans=max(ans,dp1[i]);
    cout<<ans;
    return 0;
}

Measured memory_bytes: 1920
#include<bits/stdc++.h>
using namespace std;
typedef  long long ll;
using vll=vector<ll>;
using vvll=vector<vll>;
using vi=vector<int>;
using vvi=vector<vector<int>>;
using vb=vector<bool>;
using pii=pair<int,int>;
using vpii=vector<pair<int,int>>;
using plli=pair<ll,int>;
using vplli=vector<pair<ll,int>>;
using pllll=pair<ll,ll>;
using vpllll=vector<pair<ll,ll>>;

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

//pow(llpow,modpow)
template<class T> ll llpow(ll x,T n){ll ans=1;if(x==0)ans=0;while(n){if(n&1)ans*=x;x*=x;n>>=1;}return ans;}
long long modpow(long long a, long long n, long long mod) {long long res = 1;while (n > 0) {if (n & 1) res = res * a % mod;a = a * a % mod;n >>= 1;}return res;}
//最大公約数
template<class T> inline T gcd(T x,T y){if(y==0)return x; else {return gcd(y,x%y);}}
//最小公倍数
template<class T> inline T lcm(T x,T y){return x/gcd(x,y)*y;}
//逆元
long long modinv(long long a, long long m) {long long b = m, u = 1, v = 0;while (b) {long long t = a / b;a -= t * b; swap(a, b);u -= t * v; swap(u, v);}u %= m;if (u < 0) u += m;return u;}

#define rep(i, begin_i, end_i) for (ll i = (ll)begin_i; i < (ll)end_i; i++)
//試験導入
#define irep(i, end_i, begin_i) for (ll i = (ll)begin_i-1; i >= (ll)end_i; i--)

long long INF = 1LL<<60;
ll f(ll b,ll n){
    ll res=0;
    if(b<2)return -1;
    while(n){
        res+=n%b;
        n/=b;
    }
    return res;
}
int main( ){
    ll N,S;
    cin>>N>>S;
    if(N<S){
        cout<<-1<<endl;
        return 0;
    }
    if(N==S){
        cout<<N+1<<endl;
        return 0;
    }
    for(ll b=2;b*b<=N;b++){
        if(f(b,N)==S){
            cout<<b<<endl;
            return 0;
        }
    }
    vll ans;
    for(ll x=1;x*x<=N;x++){
        ll b=(N-S)/x+1;
        if(f(b,N)==S){
            ans.push_back(b);
        }
    }
    if(ans.empty())
        cout<<-1<<endl;
    else {
        sort(ans.begin(),ans.end());
        cout<<ans[0]<<endl;
    }
    return 0;
}




Measured memory_bytes: 3568
#ifndef _GLIBCXX_NO_ASSERT
#include <cassert>
#endif
#include <cctype>
#include <cerrno>
#include <cfloat>
#include <ciso646>
#include <climits>
#include <clocale>
#include <cmath>
#include <csetjmp>
#include <csignal>
#include <cstdarg>
#include <cstddef>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>

#if __cplusplus >= 201103L
#include <ccomplex>
#include <cfenv>
#include <cinttypes>
#include <cstdbool>
#include <cstdint>
#include <ctgmath>
#include <cwchar>
#include <cwctype>
#endif

// C++
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>

#if __cplusplus >= 201103L
#include <array>
#include <atomic>
#include <chrono>
#include <condition_variable>
#include <forward_list>
#include <future>
#include <initializer_list>
#include <mutex>
#include <random>
#include <ratio>
#include <regex>
#include <scoped_allocator>
#include <system_error>
#include <thread>
#include <tuple>
#include <typeindex>
#include <type_traits>
#include <unordered_map>
#include <unordered_set>
#endif


using namespace std;
using ll = long long;

const ll MOD = 1000000007;
const ll INF = 1e18;
const double pi = acos(-1);
const int dx4[4] = {1, 0, -1, 0};
const int dy4[4] = {0, 1, 0, -1};
const int dx8[8] = {1,1,0,-1,-1,-1,0,1};
const int dy8[8] = {0,1,1,1,0,-1,-1,-1};


#define rng(i,a,b) for(int i=int(a);i<int(b);i++)
#define rep(i,b) rng(i,0,b)
#define gnr(i,a,b) for(int i=int(b)-1;i>=int(a);i--)
#define per(i,b) gnr(i,0,b)
#define ALL(obj) (obj).begin(), (obj).end()
#define rALL(obj) (obj).rbegin(), (obj).rend()


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





void solve(){
    
    // remove the bottom 3 lines when you submit this code.
    std::ifstream in("sample.txt");
    std::cin.rdbuf(in.rdbuf());

    cin.tie(0);
    ios::sync_with_stdio(false);
    
    string s; cin >> s;
    ll cw  = 0;
    ll ans = 0;
    for (int i = 0; i < s.size(); i++) {
        if(s[i]=='W') ans += (i+1)-cw-1;
        if(s[i]=='W') cw++;
    }
    cout << ans << endl;
    
    
    
}



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



Measured memory_bytes: 720
#include<iostream>
#include<cstring>
#include<cstdio>
#include<algorithm> 
#include<string>
using namespace std;
int n,v[200010],ev[200010],lv[200010],e[200010],p[200010];

int main(){
    cin >> n;
    int at=0;
    int et=0;
    for(int i=1; i<=n; i++ ){
       scanf("%d",&v[i]);
       if(i%2==1){
	     if(lv[v[i]]==0){
       	 	p[++at]=v[i];
		 }
		 lv[v[i]]++;
	   }
       if(i%2==0){
	     if(ev[v[i]]==0){
       	 	e[++et]=v[i];
		 }
		 ev[v[i]]++;
       	 
	   }
	}
	int tmp;
	int tmd;
	tmp=0;
	for(int i=1; i<=at; i++){
		if(lv[p[i]]>tmp){
		  tmp=lv[p[i]];
		  tmd=p[i];
		}
	}
	int tmi;
	int tmy;
	tmi=0;
    for(int i=1; i<=et; i++){
		if(ev[e[i]]>tmi && e[i]!=tmd){
		  tmi=ev[e[i]];
		  tmy=e[i];
		}
	}	
	int ans=(n/2-tmp)+(n/2-tmi);
	tmi=0;
	tmy=0;
    for(int i=1; i<=et; i++){
		if(ev[e[i]]>tmi ){
		  tmi=ev[e[i]];
		  tmy=e[i];
		}
	}
	tmd=0;
	tmp=0;
	for(int i=1; i<=at; i++){
		if(lv[p[i]]>tmp && p[i]!=tmy){
		  tmp=lv[p[i]];
		  tmd=p[i];
		}
	}
	ans=min(ans,(n/2-tmp)+(n/2-tmi));
	cout << ans;
	return 0;
}

Measured memory_bytes: 1792
#include <cstdio>
using namespace std;
int a, b, k;
int main() {
	scanf("%2d%2d", &a, &b);
	if(a>=1 && a<=12) k += 2;
	if(b>=1 && b<=12) k += 1;
	if(k==0) puts("NA");
	else if(k==1) puts("YYMM");
	else if(k==2) puts("MMYY");
	else puts("AMBIGUOUS");
	return 0;
}

Measured memory_bytes: 128
use std::io;


fn main() {
    let (a, b, c) = {
        let i = read::<usize>();
        (i[0], i[1], i[2])
    };
    if a < b && b < c { println!("Yes"); }
    else { println!("No"); }
}


#[allow(dead_code)]
fn read<T>() -> Vec<T>
where T:
std::str::FromStr,
T::Err: std::fmt::Debug {

    let mut buf = String::new();
    io::stdin().read_line(&mut buf).unwrap();
    buf.split_whitespace()
        .map(|s| s.trim().parse().unwrap())
        .collect()
}

#[allow(dead_code)]
fn read_one<T>() -> T
where T:
std::str::FromStr,
T::Err: std::fmt::Debug {

    let mut buf = String::new();
    io::stdin().read_line(&mut buf).unwrap();
    buf.trim().parse().unwrap()
}


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


int main() {
    string S;
    cin >> S;
    if(S.size() % 2 == 1){
        cout << "No" << endl;
        return 0;
    }
    int n = S.size()/2;
    for(int i = 1; i <= n; i++){
        if(S[i * 2 - 2] != 'h' || S[i * 2 - 1] != 'i'){
            cout << "No" <<endl;
            return 0;
        }
    }
    cout << "Yes" << endl;
    return 0;
}


Measured memory_bytes: 256
use std::io::*;
use std::str::FromStr;

#[allow(dead_code)]
fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let stdin = stdin.lock();
    let token: String = stdin
        .bytes()
        .map(|c| c.expect("failed to read char") as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().expect("failed to parse token")
}

fn main() {
    let n = read::<usize>();
    let mut aseq = vec![0; n];
    for i in 0..n {
        aseq[i] = read::<usize>() - 1;
    }
    let mut pos = 0;
    for i in 0..n {
        pos = aseq[pos];
        if pos == 1 {
            println!("{}", i + 1);
            return;
        }
    }
    println!("-1");
}


Measured memory_bytes: 4352
#include <iostream>
#include <sstream>
#include <algorithm>
#include <string>
#include <cmath>
#include <iomanip>
using namespace std;

int main()
{
	double a;
	cin >> a;
	cout << setprecision(8) << pow(a/3+0.0000000001, 3);
}



Measured memory_bytes: 4292
var ii = 0;
function read()
{
  return Number(input[ii++]);
}
var input = "";
process.stdin.resume();
process.stdin.setEncoding('utf8');
process.stdin.on('data', function(chunk){input += chunk});
process.stdin.on('end', function()
{
  input = input.split('\n');
  while(1)
  {
    n = read();
    if(n == 0)
      break;
    var a = -10000000, d = -1000000;
    for(var i = 0; i < n; i++)
    {
      m = read();
      d = Math.max(d + m, m);
      a = Math.max(a, d);
    }
    console.log(a);
  }
});

Measured memory_bytes: 8916
<?php
list($x, $k, $d) = ints();
$t = intdiv(abs($x), $d);
if ($k <= $t) {
    echo abs($x) - $k * $d;
    exit();
}
echo ($k - $t) % 2 ? $d - abs($x) % $d : abs($x) % $d;
function ints()
{
    return array_map('intval', explode(' ', trim(fgets(STDIN))));
}


Measured memory_bytes: 16240
#if !defined(__clang__) && defined(__GNUC__)
#include <bits/stdc++.h>
#else
#include <cstdlib>
#include <climits>
#include <iostream>
#include <cstdint>
#include <vector>
#include <string>
#include <complex>
#include <bitset>
#include <queue>
#include <deque>
#include <stack>
#include <utility>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <regex>
#endif //  !defined(__clang__) && defined(__GNUG__)
#include <boost/lexical_cast.hpp>
#include <boost/algorithm/string.hpp>
#include <boost/multi_array.hpp>
#include <boost/optional.hpp>
#include <boost/math/common_factor_rt.hpp>

using namespace std;

template<typename T>
T absi(T x) {
    if (x < static_cast<T>(0)) {
        x *= static_cast<T>(-1);
    }
    return x;
}


int main()
{
    int64_t N;
    std::cin >> N;

    struct Pos {
        int64_t t;
        int64_t x;
        int64_t y;
    };

    std::vector<Pos> P;

    P.push_back({0, 0, 0});

    for (decltype(N) i = 0; i < N; ++i) {
        Pos t;
        std::cin >> t.t >> t.x >> t.y;
        P.push_back(t);
    }


    for (int64_t i = 1; i < P.size(); ++i) {
        auto diff_t = P[i].t - P[i-1].t;
        auto diff_x = absi(P[i].x - P[i-1].x);
        auto diff_y = absi(P[i].y - P[i-1].y);

        if (diff_t < diff_x + diff_y) {
            std::cout << "No" << std::endl;
            return 0;
        }
        auto rem = diff_t - (diff_x + diff_y);
        if (rem % 2 != 0) {
            std::cout << "No" << std::endl;
            return 0;
        }
    }
    std::cout << "Yes" << std::endl;

    return 0;
}


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

int main(){
  int n,c,k; cin >>n >>c >>k;
  vector<int> t(n);
  rep(i,n) cin >>t[i];
  sort(t.begin(), t.end());
  int ans = 0;
  for(int i = 0; i<n;){
    ans++;
    int j = i;
    while(i-j<c && t[i]-t[j]<=k && i<n){
      i++;
    }
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 3752
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n)for(int i=0;i<(n);i++)
#define ALL(a) (a).begin(), (a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define pb push_back
using ll = long long;
using P = pair<int, int>;


signed main(){
    int N; cin >> N;
    vector<int> ans(N + 1);
    for(int i = 1; i * i<= N; i++){
        for(int j = 1; j * j <= N; j++){
            for(int k = 1; k * k <= N; k++){
                int sum = i * i + j * j + k * k + i * j + i * k + k * j;
                if(sum <= N) ans[sum]++; 
            }
        }
    }
    for(int i = 1; i <= N; i++) cout << ans[i] << endl;
}

Measured memory_bytes: 3632
#!/usr/bin/env python3
import sys
import numpy as np


def solve(C: str):
    print(chr(ord(C)+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()
    C = next(tokens)  # type: str
    solve(C)

if __name__ == '__main__':
    main()


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

int ans[100001];

int main()
{
    int n;
    cin >> n;
    int a[n],b[n];
    for(int i=0; i<n; i++){
        cin >> a[i];
        b[i] = a[i];
    }

    sort(b,b+n,greater<int>());
    for(int i=0; i<n; i++){
        if(a[i] == b[0]) cout << b[1] << endl;
        else cout << b[0] << endl;
    }
    return 0;
}

Measured memory_bytes: 3200
#include <map>
#include <string>
#include <iostream>
#include<vector>
#include <set>
#include <cstdio>
#include<algorithm>

using namespace std;

int main()
{
	int w, n, num[31];
	int a, b, temp;
	
	for (int i=1; i<=30; i++)
		num[i] = i;
	
	cin >> w >> n;
	
	for (int i=0; i<n; i++)
	{
		scanf("%d,%d", &a, &b);
		temp = num[a];
		num[a] = num[b];
		num[b] = temp;
	}
	
	for (int i=1; i<=w; i++)
	{
		cout << num[i] << endl;
	}
}

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

using namespace std;

int days_cout(int Y, int M, int D){
  Y--; M--; D--;
  int days = (int)(Y / 3) * 590 + Y % 3 * 195;
  if((Y + 1)  % 3 == 0) days += M * 20;
  else days += (int)(M / 2) * 39 + M % 2 * 20;
  days += D;
  return days;
}

int main() {
  int n, Days, Y, M, D;
  cin >> n;
  Days = days_cout(1000, 1, 1);
  while(n--) {
    cin >> Y >> M >> D;
    cout << Days - days_cout(Y, M, D) << endl;
  }
}
    

    

Measured memory_bytes: 1160
#!/usr/bin/env python3
import sys
input = sys.stdin.readline
def INT(): return int(input())
def MAP(): return map(int,input().split())
def LI(): return list(map(int,input().split()))

def main():
    N = INT()
    A = LI()

    minus = [0]*N
    plus = [0]*N

    for i in range(N):
        minus[i] = i+1-A[i]
        plus[i] = i+1+A[i]
    from collections import defaultdict
    count = defaultdict(int)

    plus_pointer = 0
    minus_pointer = 1
    answer = 0
    while minus_pointer < N:
        count[plus[plus_pointer]] += 1
        answer += count[minus[minus_pointer]]
        plus_pointer += 1
        minus_pointer += 1
    
    print(answer)
    return
if __name__ == '__main__':
    main()


Measured memory_bytes: 65808
import java.util.*;

class Main{
  static long repow(long b,long p){
    long res=1;
    long a=b;
    while(p>0){
      if((p&1)==1){
        res*=a;
      }
      a*=a;
      p/=2;
    }
    return res;
  }
  public static void main(String[] args){
    Scanner sc=new Scanner(System.in);
    int n=sc.nextInt();
    int m=sc.nextInt();
    long t=100*n+1800*m;
    System.out.println(t*repow(2,m));
  }
}

Measured memory_bytes: 22996
#include "bits/stdc++.h"
#include<unordered_map>
#include<unordered_set>
#pragma warning(disable:4996)
using namespace std;
using ld = long double;
const ld eps = 1e-9;

//// < "d:\d_download\visual studio 2015\projects\programing_contest_c++\debug\a.txt" > "d:\d_download\visual studio 2015\projects\programing_contest_c++\debug\b.txt"


int main() {
	while (true) {
		int N,M;cin>>N>>M;
		if(!N)break;
		int ans=-1;

		//fst: time    snd: dif
		pair<int,int>pre(1e9,1e9);
		bool sameflag = false;
		for (int i = 0; i < N; ++i) {
			int mydif;cin>>mydif;
			bool ok=false;
			int mytime=-1;
			for (int j = 0; j < 2000; ++j) {
				mytime=j*mydif;
				if (mytime > M) {
					mytime -= mydif;
					break;
				}
				if (pre > make_pair(mytime, mydif)) {
				}
				else if (pre == make_pair(mytime, mydif)) {
				}
				else {
					break;
				}
			}
			if (pre < make_pair(mytime, mydif)) {

			}
			else if (pre == make_pair(mytime, mydif)) {
				sameflag=true;
			}
			else {
				sameflag=false;
				pre=make_pair(mytime,mydif);
				ans=i;
			}
		}
		if(sameflag)ans=N-1;
		cout<<ans+1<<endl;
	}
	return 0;
}

Measured memory_bytes: 2984
#include<cstdio>
#include<cstring>
#include<iostream>
using namespace std;
const int maxn=1000010;
int a[maxn];
int main()
{
	int n;
	cin>>n;
	memset(a,0,sizeof(a));
	int t,an;
	t=n;
	an=1;
	a[t]++;
	while(a[t]!=2){
		
		if(t%2==0)
			t/=2;
		else
			t=t*3+1;
		//cout<<t<<endl;
		a[t]++;
		an++;
	}
	cout<<an;
	return 0;
}

Measured memory_bytes: 4096