akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <string>
#include <sstream>
#include <iomanip> 
#include <math.h>
#include <stdio.h>
#include <string.h>
#include <queue>
#include <stack>
#include <vector>
#include <map>
#include <set>
#include <functional>
#include <algorithm>
#include <unordered_map>
#include <unordered_set>
#include <bitset>

using namespace std;


// Union-Find Disjoint Sets Library written in OOP manner, using both path compression and union by rank heuristics
// initialize: UnionFind UF(N)

class UnionFind {                                              // OOP style
private:
	vector<int> p, rank, setSize;
	// p = path toward the root of disjoint set; p[i] = i means it is root
	// rank = upper bound of the actual height of the tree; not reliable as accurate measure
	// setSize = size of each disjoint set

	int numSets;
public:
	UnionFind(int N) {
		setSize.assign(N, 1);
		numSets = N;
		rank.assign(N, 0);
		p.assign(N, 0);
		for (int i = 0; i < N; i++) p[i] = i;	// each belongs to its own set
	}

	int findSet(int i) {
		return (p[i] == i) ? i : (p[i] = findSet(p[i]));		// path compression: cut short of the path if possible
	}

	bool isSameSet(int i, int j) {
		return findSet(i) == findSet(j);
	}

	void unionSet(int i, int j) {
		if (!isSameSet(i, j)) {
			numSets--;
			int x = findSet(i), y = findSet(j);
			// rank is used to keep the tree short
			if (rank[x] > rank[y]) { p[y] = x; setSize[x] += setSize[y]; }
			else {
				p[x] = y; setSize[y] += setSize[x];
				if (rank[x] == rank[y]) rank[y]++;
			}
		}
	}

	int numDisjointSets() {		// # of disjoint sets
		return numSets;
	}

	int sizeOfSet(int i) {		// size of set
		return setSize[findSet(i)];
	}
};

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

	string s;
	set<char> ss;
	cin >> s;
	for (auto ch : s) ss.insert(ch);
	if (ss.size() == s.length()) cout << "yes\n";
	else cout << "no\n";

	return 0;
}


Measured memory_bytes: 256
s = input()

res = 0
c = 0
for i in range(len(s)):
  if s[i] == "A" or s[i] == "G" or s[i] == "C" or s[i] == "T":
    c += 1
  else:
    res = max(res,c)
    c = 0
res = max(res,c)
print(res)

Measured memory_bytes: 9128
#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <map>
#include <queue>
#include <functional>
#include <utility>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;

int main(){
  int N;
  cin >> N;
   
  vector<P> dict;  

  vector<vector<int>> e(N);

  for(int i = 0;i < N-1;i++){
    int a,b;
    cin >> a >> b;
    a--;
    b--;
    dict.push_back(P(a,b));
    e[a].push_back(b);
    e[b].push_back(a);
  }

  map<P,bool> used_color;
  map<P,int> color;
  map<int,bool> used;

  int K = 0;
  for(int i = 0;i < N;i++)K = max(K,(int)e[i].size());


  queue<int> que;
  que.push(0);
  used[0] = true;

  while(que.size()){
    int now = que.front();
    que.pop();
    int i = 1;

    for(int v:e[now]){
      if(!used[v]){
	if(used_color[P(now,i)])i++;	
	que.push(v);
	used_color[P(v,i)] = true; 
	used_color[P(now,i)] = true;
	color[P(v,now)] = i;
	color[P(now,v)] = i;
	i++;
	used[v] = true;
      }
    }	
  }

  cout << K << endl;
  for(P p:dict){
    cout << color[p] << endl;
  } 
	
	
}	

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

const int maxn = 100010;
int n;
char s[maxn];

int main() {
    scanf("%s", s + 1);
    int n = strlen(s + 1), ans = n;
    for (int i = 1; i < n; i++) {
        if (s[i] ^ s[i + 1]) ans = min(ans, max(i, n - i));
    }
    printf("%d\n", ans);
    return 0;
}

Measured memory_bytes: 384
import java.util.HashSet;
import java.util.Set;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.Arrays;

public class Main {
    public static void main(String[] args) throws Exception {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        String[] hw = br.readLine().split(" ");
        int h = Integer.parseInt(hw[0]);
        int w = Integer.parseInt(hw[1]);
        char[][] grid = new char[h][w];
        
        for (int i = 0; i < h; i++) {
            String raw = br.readLine();
            for (int j = 0; j < w; j++) {
                grid[i][j] = raw.charAt(j);
            }
        }
        
        //boolean tate = true;
        //boolean yoko = true;
        int h2 = h;
        int w2 = w;
        for (int i = 0; i < h; i++) {
            for (int j = 0; j < w; j++) {
                boolean tate = true;
                boolean yoko = true;
                if (grid[i][j] == '.') {
                    for (int k = 0; k < w; k++) {
                        if (grid[i][k] == '#') {
                            yoko = false;
                            break;
                        }
                    }
                    for (int l = 0; l < h; l++) {
                        if (grid[l][j] == '#') {
                            tate = false;
                            break;
                        }
                    }
                    if (yoko) {
                        for (int m = 0; m < w; m++) {
                            grid[i][m] = 'P';
                            
                        }
                        h2--;
                    }
                    if (tate) {
                        for (int n = 0; n < h; n++) {
                            grid[n][j] = 'P';
                            
                        }
                        w2--;
                    }
                }
            }
        }
        
        boolean passed = false;
        char[] ans = new char[h2*w2];
        int memo = 0;
        for (int i = 0; i < h; i++) {
            for (int j = 0; j < w; j++) {
                if (grid[i][j] == '.' || grid[i][j] == '#') {
                    ans[memo] = grid[i][j];
                    memo++;
                }
            }
        }
        
        int now = 0;
        for (int i = 0; i < h2*w2; i++) {
            System.out.print(ans[i]);
            
            if (now + 1 == w2) {
                System.out.print('\n');
                now = 0;
                continue;
            }
            now++;
        }
        //System.out.println(h2);
        
    }
}


Measured memory_bytes: 23860
#include<iostream>
using namespace std;
int main()
{
    int N,i;
    cin>>N;
    i=N/2;
    if(N%2==0)
    {
        i=i;
    }
    else
    {
        i=i+1;
    }
    cout<<i<<endl;
    return 0;
}


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

int main() {
    int N; cin>>N;
    int t;
    map<int,int> log;
    bool flag=true;
    for(int i=0;i<N;i++){
        cin>>t;
        log[t]++;
        if(log[t]==2){
            flag = false;
        }
    }
    if(flag){
        cout<<"YES"<<endl;
    }else{
        cout<<"NO"<<endl;
    }

}


Measured memory_bytes: 9600
#include<bits/stdc++.h>
using namespace std;
int c[5][5];
int main(){
    for(int i=1;i<=3;i++)
    for(int j=1;j<=3;j++)
    cin>>c[i][j];
    int b11,b12,b13,b21,b22,b23,b31,b32,b33;
    for(int a1=0;a1<=100;a1++){
        b11=c[1][1]-a1;
        b21=c[1][2]-a1;
        b31=c[1][3]-a1;
        for(int a2=0;a2<=100;a2++){
            b12=c[2][1]-a2;
            b22=c[2][2]-a2;
            b32=c[2][3]-a2;
            if(b11!=b12 || b21!=b22 || b31!=b32)continue;   
            for(int a3=0;a3<=100;a3++){
                b13=c[3][1]-a3;
                b23=c[3][2]-a3;
                b33=c[3][3]-a3;
                if(b11==b13 && b21==b23 && b31==b33){
                    cout<<"Yes";
                    return 0;
                }
            }
        }
    }
    cout<<"No";
    return 0;
}

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

#define rep(i,m,n) for(int (i)=(int)(m);i<(int)(n);++i)
#define rep2(i,m,n) for(int (i)=(int)(n)-1;i>=(int)(m);--i)
#define REP(i,n) rep(i,0,n)
#define REP2(i,n) rep2(i,0,n)
#define FOR(i,c) for(decltype((c).begin())i=(c).begin();i!=(c).end();++i)
#define all(hoge) (hoge).begin(),(hoge).end()
#define en '\n'
using ll = long long;
using ull = unsigned long long;
template <class T> using vec = vector<T>;
template <class T> using vvec = vector<vec<T>>;
typedef pair<ll, ll> P;
constexpr long long INF = 1LL << 60;
constexpr int INF_INT = 1 << 25;
constexpr long long MOD = (ll) 1e9 + 7;
//constexpr long long MOD = 998244353LL;
using ld=long double;
static const ld pi = 3.141592653589793L;
typedef vector<ll> Array;
typedef vector<Array> Matrix;


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

struct Edge {
	ll to, rev;
    long double cap;
	Edge(ll _to, long double _cap, ll _rev) {
	to = _to; cap = _cap; rev = _rev;
	}
};
using Edges = vector<Edge>;
using Graph = vector<Edges>;

void add_edge(Graph& G, ll from, ll to, long double cap, bool revFlag, long double revCap) {
	G[from].push_back(Edge(to, cap, (ll)G[to].size()));
	if (revFlag)G[to].push_back(Edge(from, revCap, (ll)G[from].size() - 1));
}

#pragma GCC target("avx2")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")

void solve(){
	int h,w,k;
	cin>>h>>w>>k;
	ll sx,sy,gx,gy;
	cin>>sy>>sx>>gy>>gx;
	sx--;sy--;gx--;gy--;

	vec<string> s(h);
	REP(i,h) cin>>s[i];

    queue<pair<int,int>> que;
	que.push({sy,sx});
    vvec<ll> d(h,vec<ll>(w,INF));
    d[sy][sx]=0;

	while(que.size()){
		auto [i,j]=que.front();que.pop();
        //down
		for(int ni=i+1;ni<=min(h-1,i+k);++ni){
            if(s[ni][j]=='@' or d[ni][j] < d[i][j]+1) break;
            if(chmin(d[ni][j],d[i][j]+1)) que.push({ni,j});
        }
        //up
		for(int ni=i-1;ni>=max(0,i-k);--ni){
            if(s[ni][j]=='@' or d[ni][j] < d[i][j]+1) break;
            if(chmin(d[ni][j],d[i][j]+1)) que.push({ni,j});
        }
        //left
		for(int nj=j+1;nj<=min(w-1,j+k);++nj){
            if(s[i][nj]=='@' or d[i][nj] < d[i][j]+1) break;
            if(chmin(d[i][nj],d[i][j]+1)) que.push({i,nj});
        }
        //up
		for(int nj=j-1;nj>=max(0,j-k);--nj){
            if(s[i][nj]=='@' or d[i][nj] < d[i][j]+1) break;
            if(chmin(d[i][nj],d[i][j]+1)) que.push({i,nj});
        }
	}
    cout<<(d[gy][gx]==INF?-1:d[gy][gx])<<en;
}

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

	solve();
	//ll t;cin>>t;REP(i,t) solve();

    return 0;
}


Measured memory_bytes: 19788
#include <algorithm>
#include <iostream>
#include <string>
using namespace std;
string L="ABCDEFGHIJKLMNOPQRSTUVWXYZ",A=" ',-.?"+L,C=L+" .,-'?";
string B[]={"101","000000","000011","10010001","010001","000001","100101","10011010",
	"0101","0001","110","01001","10011011","010000","0111","10011000",
	"0110","00100","10011001","10011110","00101","111","10011111","1000",
	"00110","00111","10011100","10011101","000010","10010010","10010011","10010000"};
int bin2dec(string s){
	int x=0,i=0;
	for(;i<s.size();i++)x=x*2+s[i]-'0';
	return x;
}
int main(){
	string s,s1;
	int i,n;
	while(getline(cin,s)){
		s1="";
		for(i=0;i<s.size();i++)s1+=B[A.find(s[i])];
		n=s1.size()%5;
		if(n!=0)s1+=string(5-n,'0');
		s="";
		for(i=0;i<s1.size();i+=5)s+=C[bin2dec(s1.substr(i, 5))];
		cout<<s<< endl;
	}
}

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

using namespace std;

int solve();

#define ss second
#define ff first
#define y1 y111
typedef long long ll;

const int MAXN = (int)2e4 + 7, INFint = (int)1e9 + 7;
const ll INFll = (ll)1e18 + 7, MOD = (ll)1e9;
const double INFfl = (double)1e18 + 7, EPS = (double)1e-8, PI = atan2(0, -1);

int main(){
	ios_base::sync_with_stdio(0);
#ifdef home
	freopen ("input.txt", "r", stdin);
	freopen ("output.txt", "w", stdout);
#else
	cin.tie(0);
	cout.tie(0);
	#ifdef TASK
		freopen (TASK".in", "r", stdin);
		freopen (TASK".out", "w", stdout);
	#endif
#endif
	solve();
	return 0;
}

string s;
ll xx, yy, x, y, l, q, p, n;
ll a[2][MAXN], b[2], sum[2];
bool dp[MAXN][MAXN];

void clear(){
	for (int i = 0; i <= n; ++i){
		for (int j = 0; j <= n; ++j)
			dp[i][j] = 0;
	}
}


int solve(){

	cin >> s;
	s += 'T';
	cin >> xx >> yy;
	n = s.size();
	while (s[q] == 'F') x++, q++;
	if (q == s.size()){
		if (xx == x && yy == y) cout << "Yes";
		else cout << "No";
		return 0;
	}
	l = 1;
	q++;
	b[0] = 1, b[1] = 1;
	for (; q < n; ++q){
		if (s[q] == 'F') a[l % 2][b[l % 2]]++;
		else sum[l % 2] += a[l % 2][b[l % 2]], b[l % 2]++, l++;
	}
/*
	for (int i = 1; i <= b[0]; ++i) cout << a[0][i] << ' ';
	cout << sum[0] << "\n";

	for (int i = 1; i <= b[1]; ++i) cout << a[1][i] << ' ';
	cout << sum[1] << "\n";
*/
	ll dx = abs(x - xx);
	if ((sum[0] - dx) % 2 != 0){
		cout << "No";
		return 0;
	}
	dx += (sum[0] - dx) / 2;
	dp[0][0] = 1;
	for (ll i = 1; i <= b[0]; ++i)
		for (ll j = 0; j <= n; ++j){
			dp[i][j] = dp[i - 1][j];
			if (j - a[0][i] >= 0) dp[i][j] |= dp[i - 1][j - a[0][i]];
		}

	if (!dp[b[0]][dx]){
		cout << "No";
		return 0;
	}

	clear();

	dx = yy;
	if ((sum[1] - dx) % 2 != 0){
		cout << "No";
		return 0;
	}
	dx += (sum[1] - dx) / 2;
	dp[0][0] = 1;
	for (ll i = 1; i <= b[1]; ++i)
		for (ll j = 0; j <= n; ++j){
			dp[i][j] = dp[i - 1][j];
			if (j - a[1][i] >= 0) dp[i][j] |= dp[i - 1][j - a[1][i]];
		}

	if (!dp[b[1]][dx]){
		cout << "No";
		return 0;
	}
	
	cout << "Yes";
	return 0;
}

Measured memory_bytes: 159232
import java.util.*;

class Main{
	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		String[] input = scan.nextLine().split(java.util.regex.Pattern.quote("."));
		//System.out.println(Arrays.toString(input));
		Stack<Integer> indentLengths = new Stack<>();
		int maxDepth = 0;
		indentLengths.push(0);
		while(scan.hasNext()) {
			String[] line = scan.nextLine().split(":");
			int indents = 0;
			for(char c : line[0].toCharArray()) if(c==' ')indents++;else break;
			line[0] = line[0].substring(indents);
			//System.out.println(Arrays.toString(line));
			//System.out.println(indentLengths.peek()+","+indents+","+indentLengths.size()+","+maxDepth);
			if(indentLengths.peek()==indents) {
				//tannsaku keizoku
			}
			else if(indentLengths.peek()<indents) {
				indentLengths.push(indents);
				//more kaisou
			}else {
				while(indentLengths.peek() != indents) {
					indentLengths.pop();
				}
				if(indentLengths.size()<=maxDepth) break;
			}
			if(input.length>indentLengths.size() && input[indentLengths.size()].equals(line[0])) {
				maxDepth++;
				if(maxDepth+1==input.length) {
					if(line.length==1) System.out.println("object");
					else System.out.println("string \""+line[1].substring(1)+"\"");
					return;
				}
			}
			//System.out.println(indentLengths.peek()+","+indents+","+indentLengths.size()+","+maxDepth);
		}
		System.out.println("no such property");
	}
}



Measured memory_bytes: 31700
#include <bits/stdc++.h>
#define ff first
#define ss second
#define endl '\n'
using namespace std;
const long long INF = (long long) 1e18;
const int mod = (int) 1e9+7;
const int MAXN = (int) 3e5+5;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
ll n;
vector<int> adj[MAXN];
ll dp[MAXN][2];

void dfs(int a, int par){
    dp[a][0] = dp[a][1] = 1;
    for(int i: adj[a]){
        if(i == par) continue;
        dfs(i, a);
        dp[a][0] = ((dp[i][0] + dp[i][1])%mod*dp[a][0])%mod;
        dp[a][1] = (dp[i][0]*dp[a][1])%mod;
    }
}

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);cout.tie(nullptr);

    #ifdef Local
        freopen("../IO/int.txt","r",stdin);
        freopen("../IO/out.txt","w",stdout);
    #endif

    cin>>n;

    for(int i = 0; i < n - 1; i++){
        int a, b;
        cin>>a>>b;
        adj[a].push_back(b);
        adj[b].push_back(a);
    }
    
    dfs(1, -1);
    cout<<(dp[1][0] + dp[1][1])%mod<<endl;
    #ifdef Local
        cout<<endl<<fixed<<setprecision(2)<<1000.0 * clock() / CLOCKS_PER_SEC<< " milliseconds ";
    #endif
}

Measured memory_bytes: 19584
#include <algorithm>
#include <bitset>
#include <cfloat>
#include <cmath>
#include <ctime>
#include <chrono>
#include <deque>
#include <iomanip>
#include <iostream>
#include <limits>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <typeindex>
#include <typeinfo>
#include <unordered_map>
#include <unordered_set>
#include <vector>

#define ALL(s) begin(s), end(s)
#define RALL(s) rbegin(s), rend(s)
#define DEBUG(x) cout << #x << ": " << x << endl
#define INFILE() freopen("input.txt", "r", stdin)
#define REP(i, a, b) for (int i = (a); i < (b); i++)
#define RREP(i, a, b) for (int i = (a); i >= (b); i--)

using namespace std;

using ll = long long;
using ull = unsigned long long;
using i_i = pair<int, int>;
using ll_ll = pair<ll, ll>;
using d_i = pair<double, int>;
using i_d = pair<int, double>;
using d_d = pair<double, double>;

static constexpr ll LL_MOD = 1000000009;
static constexpr ll LL2_MOD = 1000000007;
static constexpr ll INF = 1LL << 60;
static constexpr double EPS = numeric_limits<double>::epsilon();
static constexpr double PI = 3.14159265358979323846264338327950288;

static map<type_index, const char *const> scanType = {
  { typeid(int), "%d" }, { typeid(ll), "%lld" }, { typeid(double), "%lf" }, { typeid(char), "%c" }};

template <class T> static void scan(vector<T>& v);
static void scan(vector<string>& v, bool isWord = true);
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 dp[101][100001];

int main(int argc, char *argv[]) {
  //INFILE();

  ll n, w;
  cin >> n >> w;

  vector<ll> weights(static_cast<int>(n));
  vector<ll> values(static_cast<int>(n));
  REP(i, 0, n) {
    cin >> weights[i] >> values[i];
  }

  REP(i, 0, n) {
    REP(j, 0, w + 1) {
      if (j != 0 && dp[i][j] == 0) continue;
      chmax(dp[i + 1][j], dp[i][j]);
      if (j + weights[i] > w) continue;
      chmax(dp[i + 1][j + weights[i]], dp[i][j] + values[i]);
    }
  }

  cout << *max_element(ALL(dp[n])) << endl;
  return 0;
}

template <class T> static void scan(vector<T>& v) {
  auto tFormat = scanType[typeid(T)];
  for (T& n : v) {
    scanf(tFormat, &n);
  }
}

static void scan(vector<string>& v, bool isWord) {
  if (isWord) {
    for (auto& n : v) {
      cin >> n;
    }
    return;
  }

  int i = 0, size = v.size();
  string s;
  getline(cin, s);

  if (s.size() != 0) {
    i++;
    v[0] = s;
  }

  for (; i < size; ++i) {
    getline(cin, v[i]);
  }
}


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

#define fatherdis fd

long long ans=0,n,father[100010],size[100010],first[100010],nxt[200020],u[200020],v[200020],tot=0,tmp,fatherdis,pos,judge=0,j,root,depth[100010]={0};

struct csx
{
	long long num,dis;
}p[100010];

bool cmp(const csx a,const csx b)
{
	if (a.dis<b.dis) return true;
	else return false;
}

void add(long long from,long long to)
{
	tot++;
	nxt[tot]=first[from];
	first[from]=tot;
	u[tot]=from;
	v[tot]=to;
	return;
}

void dfs(long long point)
{
	long long k=first[point];
	while (k!=-1)
	{
		long long to=v[k];
		if (father[point]!=to)
		{
		    depth[to]=depth[point]+1;
			dfs(to);
		}
		k=nxt[k];
	}
	ans+=depth[point];
	return;
}

int main()
{
	memset(first,-1,sizeof(first));
	scanf("%lld",&n);
	for (int i=1;i<=n;i++) 
	{
		scanf("%lld",&tmp);
		size[i]=1;
	    p[i].num=i;
	    p[i].dis=tmp;
	}
	sort(p+1,p+n+1,cmp);
	root=p[1].num;
	for (int i=n;i>1;i--)
	{
		fd=p[i].dis-(n-2*size[p[i].num]);
		j=i-1;
		while (j>0&&p[j].dis!=fd) j--;
		if (!j) 
		{
			judge=1;
			break;
		}
		father[p[i].num]=p[j].num;
		size[p[j].num]+=size[p[i].num];
		add(p[j].num,p[i].num);
		add(p[i].num,p[j].num);
	}
	dfs(root);
	if (judge||ans!=p[1].dis) printf("-1");
	else for (int i=1;i<=tot/2;i++) printf("%lld %lld\n",u[i*2],v[i*2]);
	return 0;
}

Measured memory_bytes: 12288
#pragma warning(disable:4996)
#pragma comment(linker, "/STACK:336777216")
#pragma GCC optimize("Ofast")

#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <functional>

using namespace std;
using namespace __gnu_pbds;

typedef long long ll;
#define int long long int
typedef complex<long double> cd;
const long double pi=acos(-1);
typedef double db;
typedef long double ldb;
typedef pair <int, int> pii;
typedef pair <db, db> pdd;
typedef vector<int> vi;
typedef vector<vector<int> > matrix;

#define m1 make_pair
#define pb push_back
#define flush fflush(stdout)
#define IOS std::ios::sync_with_stdio(false); cin.tie(NULL);cout.tie(NULL);
#define reset(x,v) memset(x,v,sizeof(x))

#define fi first
#define se second
#define endl "\n"
#define debug(x) (cerr << #x << ": " << x << "\n")
#define setbits(x) __builtin_popcount(x)
#define setbitsll(x) __builtin_popcountll(x)
#define all(x) x.begin(),x.end()
#define pii pair<int,int>

inline ll gcd(ll a,ll b){if(a==0) return b;return gcd(b%a,a);}
inline ll power(ll a,ll n,ll m){if(n==0)return 1;ll p=power(a,n/2,m);p=(p%m*p%m)%m;if(n%2) return (p%m*a%m)%m;else return p;}
const double EPS = 1e-9;
const ll MOD =998244353;
const ll hell=1000000007;
const int INF = 1e15;
const ll LL_INF = 0x3f3f3f3f3f3f3f3f;
template<typename T>
using ordered_set=tree<T, null_type, less<T>, rb_tree_tag,tree_order_statistics_node_update>;

auto seed = chrono::high_resolution_clock::now().time_since_epoch().count();
std::mt19937 rng(seed);

double startTime;
double getCurrentTime() {
    return ((double)clock() - startTime) / CLOCKS_PER_SEC;
}

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


void solve()
{
    int n;
    cin>>n;
    int k;
    cin>>k;
    int f[k+1]={0};
    for(int i=1;i<=k;i++)
    {
        int x=k/i;
        f[i]=power(x,n,hell);
    }
    int ans=0;
    for(int i=k;i>=1;i--)
    {
        for(int j=2*i;j<=k;j+=i)
        {
            f[i]=(f[i]-f[j]+hell)%hell;
        }
        ans=(ans+(f[i]*i)%hell)%hell;
    }
    cout<<ans<<endl;
    
}


int32_t main()
{
    
    IOS;
    //FILE *fin = freopen("in","r",stdin);
    //FILE *fout = freopen("out","w",stdout);
    int t;
    t=1;
    //cin>>t;
    while(t--)
    {
        solve();
    }
    return 0;
}


Measured memory_bytes: 4376
#include <stdio.h>
#include <math.h>
#include <string.h>
#include <stdlib.h>
#define N 200001
#define MAX 100005
#define NI -1

typedef struct node{
    int l,p,r;
} node;
node T[MAX];
int n,D[MAX];
void print(int u){
    int i,c;
    printf("node %d: parent = %d, depth = %d, ",u,T[u].p,D[u]);
    if(T[u].p == NI){printf("root, ");}
    else if(T[u].l == NI){printf("leaf, ");}
    else{printf("internal node, ");}
    printf("[");

    for(i=0,c=T[u].l;c != NI;i++,c=T[c].r){
        if(i)
            printf(", ");
        printf("%d",c);
    }
    printf("]\n");
}

int rec(int u,int p){
    D[u]=p;
    if(T[u].r != NI){rec(T[u].r,p);}
    if(T[u].l != NI){rec(T[u].l,p+1);}
}


int main(void){
    int o,d,z,c,l,r,i;
    scanf("%d",&n);
    for(i=0;i<n;i++){
        T[i].p=T[i].l=T[i].r=NI;
      }
    for(i=0;i<n;i++){
        scanf("%d %d",&z,&d);
        for(o=0;o<d;o++){
            scanf("%d",&c);
            if(!o){T[z].l=c;}
            else{ T[l].r=c;}
            l=c;
            T[c].p=z;
        }
    }
    for(i=0;i<n;i++){
        if(T[i].p == NI){r=i;}
          }
    rec(r,0);
    for(i=0;i<n;i++)
        print(i);
    return 0;
}



Measured memory_bytes: 6404
#include <cstdio>

using namespace std;

int main() {
    int A, B;
    scanf("%d %d", &A, &B);

    if (A == 1) A += 13;
    if (B == 1) B += 13;

    printf("%s\n", A!=B? (A>B? "Alice":"Bob"):"Draw");
    return 0;
}


Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
ll n,l[105];
ll ans;
int main(void){
    cin>>n;
    for(int i=0;i<n;i++){
        cin>>l[i];
    }
    sort(l,l+n);
    for(int i=0;i<n;i++){
        for(int j=i+1;j<n;j++){
            for(int k=j+1;k<n;k++){
                if(l[k]<l[i]+l[j]&&l[i]!=l[j]&&l[j]!=l[k]){
                    ans++;
                }
            }
        }
    }
    cout<<ans<<endl;

}



Measured memory_bytes: 3636
# Edit: 2014/09/17
# Lang: Python3
# Time: 00.04s

from math import factorial

if __name__ == "__main__":
    r, c, ar, ac, br, bc = map(int, input().strip("\n").split(" "))
    maxans = 100000007  # 100,000,007

    # tate Row
    dr = min(abs(br - ar), r - abs(br - ar))
    if 2 * dr == r:
        gainr = 2
    else:
        gainr = 1

    # yoko Column
    dc = min(abs(bc - ac), c - abs(bc - ac))
    if 2 * dc == c:
        gainc = 2
    else:
        gainc = 1

    ans = factorial(dr + dc) // factorial(dr) // factorial(dc) * gainr * gainc

    print(ans % maxans)

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

int64_t calcDiff(std::array<int64_t, 3>);

int main()
{
	int64_t H, W;
	scanf("%lld%lld", &H, &W);
	int64_t min{1ll << 60};

	int64_t left{W / 2};
	for (int64_t i{}; i <= H; i++)
		min = std::min({min, calcDiff({(H - i) * W, i * left, i * (W - left)}), calcDiff({(H - i) * W, (i / 2) * W, (i - i / 2) * W})});
	int64_t top{H / 2};
	for (int64_t i{}; i <= W; i++)
		min = std::min({min, calcDiff({(W - i) * H, i * top, i * (H - top)}), calcDiff({(W - i) * H, (i / 2) * H, (i - i / 2) * H})});

	printf("%lld\n", min);

	return 0;
}

int64_t calcDiff(std::array<int64_t, 3> arr)
{
	std::sort(arr.begin(), arr.end());
	return arr.back() - arr.front();
}

Measured memory_bytes: 384
s = input()
if len(s) < 7:
  print("NO")
else:
  if s[:7] == "keyence" or s[-7:] == "keyence":
    print("YES")
  else:
    flag = True
    for i in range(1, 7):
      if s[:i]+s[i-7:] == "keyence":
        flag = False
        print("YES")
        break
    if flag:
      print("NO")

Measured memory_bytes: 38384
#include <iostream>
#include <iomanip>
#include <string>
#include <sstream>
#include <bitset>
#include <algorithm>
#include <cmath>
#include <numeric>
#include <utility>
#include <set>
#include <map>
#include <tuple> 
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <list>
using namespace  std;
typedef pair<long long , long long> P;
typedef long long ll;
typedef long long lint;
#define REP(i, n) for(long long (i)=0; (i)<(n); ++i)
#define FOR(i, a, b) for(long long (i)=(a); (i)<(b); ++i)
#define ALL(a) (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
const long long MOD = static_cast<long long>(1e9) + 7LL;
const long long INF = 1234567891234567890LL;
signed main(){
    string s; cin>>s;
    bool res = false;
    REP(i, s.size()-1) if(s[i]==s[i+1]) res = true;
    if(res) cout << "Bad" <<endl;
    else cout << "Good" << endl;
    return 0;

}

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

int main() {
  long long A, B;
  int K; 
  cin >> A >> B >> K;
  if(K%2 == 0) {
    for(int i = 0; i < K/2; i++) {
      if(A%2 == 1) {
        A = A - 1;
      }
      B = B + A/2;
      A = A/2;
      if(B%2 == 1) {
        B = B - 1;
      }
      A = A + B/2;
      B = B/2;
    }
  }
  else {
    for(int i = 0; i < K/2; i++) {
      if(A%2 == 1) {
        A = A - 1;
      }
      B = B + A/2;
      A = A/2;
      if(B%2 == 1) {
        B = B - 1;
      }
      A = A + B/2;
      B = B/2;
    }
      if(A%2 == 1) {
        A = A - 1;
      }
      B = B + A/2;
      A = A/2;    
  }
  cout << A << " " << B << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <stdio.h>
#include <cmath>
#include <algorithm>
#include <climits>
#include <vector>
#include <iomanip>
#include <string>
#include <queue>
#include <numeric>
#include <functional>
#include <array>
#include <map>
#include <set>

using namespace std;
using P = pair<int, int>;
using T = tuple<int, int, int>;

long long MOD = 1000000007;
long long dp[100005][4];

bool compare_by_second(pair<int, int> a, pair<int, int> b) {
	if (a.second != b.second) {
		return a.second < b.second;
	}
	else {
		return a.first < b.first;
	}
}

int main() {

	int A, B;
	cin >> A >> B;

	int currentCount = 1;
	int count = 0;
	while (currentCount<B) {
		currentCount--;
		currentCount += A;
		count++;
	}

	cout << count;
}


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

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

int main(){
	int K;
	cin >> K;
	ll sum = 0;
	for(int i = 1; i <= K; i++)
		for(int j = 1; j <= K; j++)
			for(int k = 1; k <= K; k++)
				sum += gcd(gcd(i, j), k);

	cout << sum << endl;

	return 0;	
}

Measured memory_bytes: 3624
s = input()
t = input()
s = list(s)
t = list(t)
s.sort()
t.sort()
t.reverse()
flag = False
for i in range(min(len(s),len(t))):
    if(s[i]<t[i]):
        flag = True
        break
    elif(s[i]>t[i]):
        flag = False
        break
    else:
        if(i == min(len(s),len(t))-1 and len(s)<len(t)):
            flag = True
if(flag):
    print('Yes')
else:
    print('No')


Measured memory_bytes: 3064
#include<bits/stdc++.h>
using namespace std;
#define first ff
#define second ss
#define ll long long int
int main()
{
   int n;
   cin>>n;
   int a[n+5],b[n+5],c[n+5];
   ll sum=0;
   for(int i=0;i<n;i++) cin>>a[i];
   for(int i=0;i<n;i++) cin>>b[i],sum+=b[i];
   for(int i=0;i<n-1;i++) cin>>c[i];
   for(int i=0;i<n-1;i++){
      if(a[i]+1==a[i+1]) sum+=c[a[i]-1];
   }
   cout<<sum<<endl;

}


Measured memory_bytes: 3576
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <cassert>
#include <algorithm>
#include <functional>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <tuple>
#include <vector>
#define repi(i,a,b) for(ll i=(a);i<(b);++i)
#define rep(i,a) repi(i,0,a)
#define repdi(i,a,b) for(ll i=(a)-1;i>=(b);--i)
#define repd(i,a) repdi(i,a,0)
#define itr(it,a) for( auto it = (a).begin(); it != (a).end(); ++it )
#define all(a) (a).begin(), (a).end()
#define rall(a) (a).rbegin(), (a).rend()
#define endl '\n'
#define debug(x) std::cerr << #x << " = " << (x) << endl;

using ll = long long;
using P = std::pair<ll, ll>;

constexpr ll INF = 1ll<<60;

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

template<class S, class T>
std::ostream& operator<< ( std::ostream& out, const std::pair<S,T>& a )
{ std::cout << '(' << a.first << ", " << a.second << ')'; return out; }

template<class T>
std::ostream &operator<< ( std::ostream& out, const std::vector<T>& a )
{ std::cout << '['; rep( i, a.size() ){ std::cout << a[i]; if( i != a.size()-1 ) std::cout << ", "; } std::cout << ']'; return out; }

ll N;
ll A[30], B[30], C[30];

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

  rep( i, N )
    std::cin >> A[i], --A[i];
  rep( i, N )
    std::cin >> B[i];
  rep( i, N-1 )
    std::cin >> C[i];

  ll ans = 0;
  ll prv = -1;

  rep( i, N ) {
    ans += B[A[i]];

    if( prv != -1 && prv+1 == A[i] )
      ans += C[prv];

    prv = A[i];
  }

  std::cout << ans << endl;

  return 0;
}

Measured memory_bytes: 3608
#include <bits/stdc++.h>
using namespace std;
#define fi first
#define se second
typedef long long ll;
typedef pair<int, int> pii;

template <typename T>
void read(T &x)
{
    static char ch;
    for (ch = getchar(); !isdigit(ch); ch = getchar()) ;
    for (x = 0; isdigit(ch); ch = getchar())
        x = (x<<3)+(x<<1)+ch-'0';
}

const int N = 1e5+10;

char s[N];

int main()
{
    scanf("%s", s+1);
    int n = strlen(s+1);
    for (int i = 1; i < n; ++i)
    {
        if (s[i] == s[i+1])
        {
            printf("%d %d\n", i, i+1);
            return 0;
        }
        if (s[i] == s[i+2])
        {
            printf("%d %d\n", i, i+2);
            return 0;
        }
    }
    puts("-1 -1");
}


Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define rep(i,n) for(int i=0;i<n;i++)
#define all(a) a.begin(),a.end()
#define P pair<int,int>
#define F first
#define S second
#define mod 1000000007
#define INF 9000000000000000000
signed main(void){
    int a,b,c;cin>>a>>b>>c;
    cout<<max((int)0,c-(a-b))<<endl;
    
}

Measured memory_bytes: 256
loop {
m,f,r=gets.split(" ").map(&:to_i)
break if m==-1 && f==-1 && r==-1

grade="F"
if m == -1 || f == -1

elsif (m + f) >=80 
    grade= "A"
elsif (m + f) >=65
    grade= "B"
elsif (m + f)>=50
    grade="C"
elsif (m + f)>=30
    if r >= 50
        grade= "C"
    else
        grade= "D"
    end
end

puts grade


}








Measured memory_bytes: 8900
#include<bits/stdc++.h>
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define rep2(i, m, n) for(int i = (int)(m); i < (int)(n); i++)
#define rep_inv(i, n, m) for(int i = (int)(n); i > (int)(m); i--)
using namespace std;
using ll = long long;
using vl = vector<ll>;
using vc = vector<char>;
using vvl = vector<vl>;
using vvc = vector<vc>;
using pll = pair<ll, ll>;
using vpll = vector<pll>;

ll MOD = (ll)pow(10, 9) + 7;

ll power_mod(ll bs, ll ex){
  if(ex == 0)
    return 1;
  else if(ex % 2 == 0)
    return power_mod(bs * bs % MOD, ex / 2) % MOD;
  else
    return bs * power_mod(bs, ex - 1) % MOD;
}

int main(){
  ll n, a, b;
  cin >> n >> a >> b;

  if(n == 2){
    cout << 0 << "\n";
    return 0;
  }

  vl fact(b + 1), fact_inv(b + 1);

  fact[0] = 1;
  rep2(i, 1, b + 1) fact[i] = fact[i - 1] * i % MOD;

  fact_inv[b] = power_mod(fact[b], MOD - 2);
  rep_inv(i, b - 1, -1){
    fact_inv[i] = fact_inv[i + 1] * (i + 1) % MOD;
    // cout << i << ' ' << fact[i] << ' ' << fact_inv[i] << ' ' << fact[i] * fact_inv[i] % MOD << "\n";
  }

  ll whole = power_mod(2, n) - 1;
  ll comb_a = fact_inv[a];
  ll comb_b = fact_inv[b];

  rep(i, a) comb_a = comb_a * (n - i) % MOD;
  rep(i, b) comb_b = comb_b * (n - i) % MOD;

  // cout << whole << ' ' << comb_a << ' ' << comb_b << "\n";
  
  ll ans = 0;

  if(whole >= comb_a)
    ans = whole - comb_a;
  else
    ans = whole - comb_a + MOD;

  if(ans >= comb_b)
    ans = ans - comb_b;
  else
    ans = ans - comb_b + MOD;

  cout << ans << "\n";
    
  return 0;
}


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

ll cn[100010];

int main(){
    ll n;cin>>n;
    ll a[100010];
    ll sum=0;
    rep(i,0,n){
        cin>>a[i];
        sum+=a[i];
        cn[a[i]]++;
    }
    ll q;cin>>q;
    while(q--){
        ll b,c;cin>>b>>c;
        ll d=c-b;
        sum+=cn[b]*d;
        cn[c]+=cn[b];
        cn[b]=0;
        cout<<sum<<endl;
    }
}

    









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

int main()
{
  int i,n,m,x,y;
  int kari,x_max,y_min;
  
  cin>>n>>m>>x>>y;

  x_max=x;
  y_min=y;
  
  for(i=0;i<n;i++){
      cin>>kari;
      if(kari>x_max) x_max=kari;
    }

    for(i=0;i<m;i++){
      cin>>kari;
      if(kari<y_min) y_min=kari;

    }

    if(x_max<y_min) cout<<"No War"<<endl;
    else cout<<"War"<<endl;

    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#include<string>
using namespace std;
typedef long long int ll;
#define mp make_pair
#define pb push_back
 

void solve(){
	int d,t,s;
	cin>>d>>t>>s;
	if(t*s>=d){
		cout<<"Yes";
	}
	else{
		cout<<"No";
	}
	
        
}

    
    
int main() {
 
    /*#ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
    #endif*/
    ios::sync_with_stdio(0);
    cout.tie(0);
    cin.tie(0);
    
    	
solve();
cout<<"\n";
    
    return 0;
}

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

#define rep(i,n) for(int i=0;i<(n);i++)
#define REP(i,n) for(int i=1;i<=(n);i++)
#define mp make_pair
#define pb push_back
#define fst first
#define snd second
typedef long long ll;
typedef pair<int,int> pii;

const int maxn=105;
int n,k;
char s[maxn];

int calc(int l,int r){
	int res=0;
	for(int i=l;i<=r;i++){
		int j=i;
		while(j<=r&&s[j]==s[i])j++;
		res+=(j-i)/2;
		i=j-1;
	}
	return res;
}

int main(){
	scanf("%s%d",s,&k);
	n=strlen(s);
	if(n==1){
		printf("%d\n",k/2);
		return 0;
	}
	if(s[0]!=s[n-1])printf("%lld\n",1LL*calc(0,n-1)*k);
	else{
		ll ans1=1LL*min(calc(1,n-1),calc(0,n-2))*(k-1)+k-1+calc(0,n-1);
		ll ans2=1LL*(calc(0,n-1)+calc(1,n-2)+2)*(k/2);
		if(k&1)ans2+=calc(0,n-1); 
		printf("%lld\n",min(ans1,ans2));
	}
	return 0;
}

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

#define ll          long long
#define ull         unsigned long long
#define pb          push_back
#define pii         pair<int,int>
#define pll         pair<long,long>
#define vi          vector<int>
#define vll         vector<ll>
#define vii         vector<pii>
#define Mi          map<int,int>
#define mii         map<pii,int>
#define all(a)      (a).begin(),(a).end()
#define rall(a)      (a).rbegin(),(a).rend()
#define ff           first
#define ss           second
#define sz(x)       (int)x.size()
#define endl        '\n'
#define mod        1000000007
//#define mod        998244353
#define rep(i,a,b)  for(int i=a;i<b;i++)
#define rem(i,a,b)  for(int i=a;i>b;i--)
#define mp(a,b)     make_pair(a,b)
#define INF         numeric_limits<ll>::max();
#define NINF        numeric_limits<ll>::min();
#define vvi(a,b,name)    vector<vector<int>> name(a,vector<int>(b,-1))
const long double pi=3.14159265359;

inline ll add(ll a,ll b){
    if((a+b)>=mod)return (a+b)%mod;
    return a+b;
}

inline ll mul(ll a,ll b){
    if((a*b)<mod)return a*b;
    return (a*b)%mod;
}

ll pw(ll x, ll p){
    if(!p)return 1;
    ll z=pw(x,p/2);
    z*=z;
    z%=mod;
    if(p%2==0)return z;
    z*=x;
    z%=mod;
    return z;
}


void solve(){
    ll n,k;cin>>n>>k;
    ll ans=k;
    ll cnt[k+1];
    cnt[k]=1;
    rem(i,k-1,0){
        cnt[i]=pw(k/i,n);
        for(int j=i+i;j<=k;j+=i){
            cnt[i]=cnt[i]-cnt[j]+mod;
            cnt[i]%=mod;
        }
        ans=add(ans,mul(i,cnt[i]));
    }
    cout<<ans<<endl;
}

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    long t=1;
    //cin>>t;
    while(t--){
        solve();
    }
    return 0;
}


Measured memory_bytes: 4424
#include <bits/stdc++.h>  
#define lli long long 
using namespace std; 
long long mod2=1e9+7,mod=998244353;
lli power(lli x, lli y,lli m=mod) 
{
    lli res = 1;  
   
    while (y > 0) 
    { 
        if (y & 1) 
            res = (res*x)%m; 
        y = y>>1; 
        x = (x*x)%m;  
    }
    if(res<0)
       res+=m; 
    return res; 
}
// lli fact[2000009];
// lli ncr(lli n,lli r){
//     lli ans=fact[n];
//     if(r>n)return 1;
//     if(r<0)return 0;
//     if(n<0)return 0;
//     ans=(ans*power(fact[n-r],mod-2))%mod;
//     ans=(ans*power(fact[r],mod-2))%mod;
//     return ans;
// }

int main() 
{ 
    // fact[0]=1;
    // for(int i=1;i<=2000005;i++)fact[i]=(i*fact[i-1])%mod;
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    int t=1;
    // cin>>t;
    while(t--){
        string s;cin>>s;
        if(s.back()=='s')s+="es";
        else s+="s";
        cout<<s<<"\n";
    }
    return 0; 
} 

Measured memory_bytes: 3656
#include <bits/stdc++.h>
using namespace std;
int main()
{
    int n;
    cin >> n;
    vector<int> c(n + 1);
    for (int i = 2; i <= n; ++i) {
        int x;
        cin >> x;
        c[x]++;
    }
    for (int i = 1; i <= n; ++i)
        cout << c[i] << "\n";
}


Measured memory_bytes: 4044
N = int(input())
A = [int(input()) for _ in range(N)][::-1]

if A[-1]:
    print(-1)
else:
    bef = A[0]
    c, ans = 0, 0
    for i in A:
        if bef!=i:
            if bef-i > 1:
                ans = -1
                break
            ans += bef*c
            c = 1 if bef<i else 0
        else:
            c += 1
        bef = i
    print(ans)

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

int main() {

  int n;
  
  while(1) {
    int sum = 0;
    cin >> n;
    if(n == 0) break;

    int t;
    cin >>t;
    
    for(int i=0;i<t;i++) {
    int s,f;
    cin >> s >>f;

    sum += f-s;

    }

    if(sum < n) cout << n-sum << endl;
    else cout <<"OK"<<endl;

  }

  return 0;

}


    

Measured memory_bytes: 1160
#include<bits/stdc++.h>
using namespace std;
typedef long long int lld;
int main(){
  int n,p;
  while(1){
    cin >> n >> p;
    if(n == 0 && p == 0) break;
    int stone[55]={0};
    int now = 0,np = p;
    while(1){
      if(np == 0){
	int *idx = max_element(stone,stone+n);
	if((*idx) == p){
	  cout << idx - stone << endl;
	  break;
	}
	np = stone[now];
	stone[now] = 0;
      } else {
	np--;
	stone[now]++;
      }
      now = (now + 1)%n;
    }
  }
}

Measured memory_bytes: 1160
#include<iostream>
#include<algorithm>
#include<math.h>
#include<vector>
#include<map>
#include<set>
#include<iomanip>

using namespace std;
using ll = long long;

const int MOD = 1e9 + 7;
const int INF = numeric_limits<int>::max();
const ll LLINF = numeric_limits<ll>::max();
const double PI = acos(-1.0);

#define rep(i, n) for (int i = 0; i < (n); ++i)
#define rrep(i, a, n) for (int i = a; i <= (n); ++i)

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

    int mx = max({A, B, C});

    cout << A + B + C + 9 * mx << endl;
    return 0;
}


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

int main(){
    int n,i;
    long long c1=0,c2=0;//c1=奇数番負の回数c2=偶数番負の回数
    cin >> n;
    int a[n],s[2];
//入力

    for (i=0;i<n;i++){        
cin >> a[i];
    }
//操作
//奇数番和をマイナスの値にする
    s[0]=a[0],s[1]=0;
    for (;s[0]>-1;c1++) s[0]--;
    for (i=1; i<n; i++) {
        s[1]=s[0]+a[i];
        if ((s[0]<0&&s[1]<=0)||(s[0]>0&&s[1]>=0)){
            if (s[0]<0) for (;s[1]<1;) s[1]++,c1++;//S(n-1)<0
            else for (;s[1]>-1;) s[1]--,c1++;
    }
        s[0]=s[1];
    }
    s[0]=a[0],s[1]=0;
    for (;s[0]<1;c2++) s[0]++;
    for (i=1; i<n; i++) {
        s[1]=s[0]+a[i];
        if ((s[0]<0&&s[1]<=0)||(s[0]>0&&s[1]>=0)){
            if (s[0]<0) for (;s[1]<1;) s[1]++,c2++;//S(n-1)<0
            else for (;s[1]>-1;) s[1]--,c2++;
        }
        s[0]=s[1];
    }
    
    cout<< min(c1,c2)<<endl;
    return 0;
}

Measured memory_bytes: 640
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<vector>
#include<queue>
#include<map>
#include<set>
#include<cstring>
#include<string>
#define pb push_back
#define mp make_pair
#define fir first
#define sec second
#define SZ(a) (int)((a).size())
using namespace std;
typedef long long ll;
typedef double db;
typedef pair <int, int> Pii;
typedef pair <ll, int> Pli;
typedef unsigned long long ull;
const double eps = 1e-8;
const ll infll = 0x7fffffffffffffff;
const int mod = (int)(1e9) + 7;
const int inf = 0x7fffffff;
const int maxn = (int)(2e5) + 7;
const int maxm = 300;

int K;
char s[maxn];

int main() {
	
	// freopen("in.in", "r", stdin);
	scanf("%d%s", &K, s + 1);
	int len = strlen(s + 1);
	if (len <= K) puts(s + 1);
	else {
		for (int i = 1; i <= K; i++) printf("%c", s[i]);
		puts("...");
	}

	return 0;
}		

Measured memory_bytes: 3164
#import time
S = input()
Q = int(input())
f = True
head = []
tail = []
for i in range(Q):
    query = input().split(' ')
    if len(query) == 1:
        f = not f
    else:
        if (query[1] == '1' and f) or (query[1] == '2' and not f):
            head.append(query[2])
        else:
            tail.append(query[2])

S = ''.join(head)[::-1]+S+''.join(tail)
if not f:
    S = S[::-1]
print(S)

# start = time.time()
# elapsed_time = time.time() - start
# print("elapsed_time:{0}".format(elapsed_time) + "[sec]")


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

const string YES = "Yes";
const string NO = "No";

void solve(long long K, long long X)
{
	if (K * 500 >= X)
		cout << "Yes" << endl;
	else
		cout << NO << endl;
}

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


Measured memory_bytes: 3768
#include <algorithm>
#include <cstdio>
#include <iostream>
#include <map>
#include <cmath>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
#include <stdlib.h>
#include <stdio.h>
#include <bitset>
#include <cstring>
#include <deque>
#include <iomanip>
#include <limits>
#include <fstream>
using namespace std;
#define FOR(I,A,B) for(int I = (A); I < (B); ++I)
#define CLR(mat) memset(mat, 0, sizeof(mat))
typedef long long ll;
int main()
{
  ios::sync_with_stdio(false);
  cin.tie(0);
  int N;cin>>N;
  vector<int> ans;
  if(N==3){
    cout<<"2 5 63"<<endl;
  }else if(N==4){
    cout<<"2 5 20 63"<<endl;
  }else if(N==5){
    cout<<"2 5 20 30 63"<<endl;
  }else{
    int cnt=0;
    int sum=0;
    int a,b;
    for(int i=2;i<=30001;i++){
      if(cnt<N&&(i%2==0||i%3==0)){
        sum+=i;
        cnt++;
        ans.push_back(i);
      }
      if(i%6==0)a=i;
      if(i%6==4)b=i;
    }
    if(sum%6==2)ans[4]=a;
    if(sum%6==3)ans[5]=a;
    if(sum%6==5)ans[5]=b;
    FOR(i,0,N){
      if(i)cout<<" ";
      cout<<ans[i];
    }
    cout<<endl;
  }
  return 0;
}

Measured memory_bytes: 640
open System

[<EntryPoint>]
let main argv =
  let n = Console.ReadLine() |> int in
  let xs = Console.ReadLine().Split(' ') |> Array.map int in
  let rec f x = if x % 2 = 1 then 0 else (1 + f (x / 2)) in
  xs
  |> Array.map f
  |> Array.min
  |> Console.WriteLine
  0


Measured memory_bytes: 11220
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
//const ll MOD = 1e9 + 7;
//const ll MOD = 998244353;
//const ll MOD = ;
ll mod(ll A, ll M) {return (A % M + M) % M;}
const ll INF = 1LL << 60;
template<class T> bool chmin(T& a, T b) {if (a > b) {a = b; return true;} return false;}
template<class T> bool chmax(T& a, T b) {if (a < b) {a = b; return true;} return false;}
ll divceil(ll A, ll B) {return (A + (B - 1)) / B;}
ll myctoi(char C) {return C - '0';}
char myitoc(ll N) {return '0' + N;}
#define FINALANS(A) {cout << (A) << '\n'; exit(0);}

ll quadrant(pair<ll, ll> xy)
{
  ll x = xy.first, y = xy.second;
  if (x >= 0 && y >= 0)
    return 1;
  if (x < 0 && y >= 0)
    return 2;
  if (x < 0 && y < 0)
    return 3;
  if (x >= 0 && y < 0)
    return 4;

  return 0;
}

bool comp(pair<ll, ll> xy1, pair<ll, ll> xy2)
{
  ll q1 = quadrant(xy1), q2 = quadrant(xy2);
  if (q1 != q2)
    return (q1 < q2);
  
  ll x1 = xy1.first, y1 = xy1.second;
  ll x2 = xy2.first, y2 = xy2.second;
  return (x2 * y1 < x1 * y2);
}

int main()
{
  ll N;
  cin >> N;
  vector<pair<ll, ll>> XY;
  for (ll i = 0; i < N; i++)
  {
    ll x, y;
    cin >> x >> y;
    if (!(x == 0 && y == 0))
      XY.push_back(make_pair(x, y));
  }
  N = XY.size();

  sort(XY.begin(), XY.end(), comp);

  for (ll i = 0; i < N; i++)
  {
    XY.push_back(XY.at(i));
  }

  ll ans = 0;
  for (ll i = 0; i < N; i++)
  {
    ll X = 0, Y = 0;

    for (ll j = i; j < i + N; j++)
    {
      ll x = XY.at(j).first, y = XY.at(j).second;
      X += x, Y += y;
      
      ll tmp = X * X + Y * Y;
      chmax(ans, tmp);
    }
  }
  cout << fixed << setprecision(20) << sqrt(ans) << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
using pint = pair<int,int>;
ll mod = 1000000007,mod2 = 998244353;

void chmin(long long &a, long long b) { if (a > b) a = b; }
void chmax(long long &a, long long b) { if (a < b) a = b; }
const long long INF = 1LL<<60;
ll gcd(ll a,ll b){
    if(b == 0) return a;
    else return gcd(b,a%b);
}


map<int,int> mp;
int main() {
    int n;
    cin >> n;
    int ans = 0,niko = 0,mx = 0;
    for (int i = 0; i < n; ++i) {
        int a;
        cin >> a;
        mx = max(mx,a);
        mp[a]++;
    }

    for(auto i:mp){
        if(i.second %2 == 0 && i.second >= 4){
            ans += (i.second-2);
            i.second = 2;
            niko++;
        }else if(i.second == 2) {
            niko++;
        }else if(i.second %2 == 1 && i.second >= 3){
            ans += (i.second-1);
            i.second = 1;
        }
    }

    if(niko %2 == 0) ans += niko;
    else ans += (niko+1);
    cout << n-ans << endl;
    return 0;
}

Measured memory_bytes: 4992