akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <fstream>
#include <cstdio>
#include <cmath>
#include <vector>
#include <string>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <deque>
#include <bitset>
#include <algorithm>
#include <complex>
#include <array>
#include <functional>
using namespace std;

#define REP(i,n) for(int i=0; i<n; ++i)
#define FOR(i,a,b) for(int i=a; i<=b; ++i)
#define FORR(i,a,b) for (int i=a; i>=b; --i)
#define ALL(c) (c).begin(), (c).end()

typedef long long ll;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef vector<double> VD;
typedef vector<VI> VVI;
typedef vector<VL> VVL;
typedef vector<VD> VVD;
typedef pair<int,int> P;
typedef pair<ll,ll> PL;

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

int in() { int x; scanf("%d", &x); return x; }
ll lin() { ll x; scanf("%lld", &x); return x; }

bool gauss_elimination(VVI A, VI B){
    int n = A.size(), m = A[0].size();

    int r = 0;
    REP(j,m){
        FOR(i,r,n-1){
            if (A[i][j]){
                swap(A[r], A[i]);
                swap(B[r], B[i]);
                break;
            }
        }
        if (A[r][j] == 0) continue;
        FOR(i,r+1,n-1){
            if (A[i][j] == 0) continue;
            FOR(jj,j,m-1){
                A[i][jj] ^= A[r][jj];
            }
            B[i] ^= B[r];
        }
        r++;
        if (r == n) break;
    }
    int p = 0;
    REP(j,B.size()) if (B[j]) p = j + 1;
    return r >= p;
}

int solve(){
    int n, m = 64;
    cin >> n;
    VL a(n);
    REP(i,n) cin >> a[i];
    string s;
    cin >> s;
    VVI A(m);
    FORR(i,n-1,0){
        if (s[i] == '0'){
            ll x = a[i];
            REP(j,m){
                A[j].push_back(x % 2);
                x /= 2;
            }
        }else{
            if (A[0].empty()) return 1;
            VI b(m);
            ll x = a[i];
            REP(j,m){
                b[j] = x % 2;
                x /= 2;
            }
            if (!gauss_elimination(A, b)) return 1;
        }
    }
    return 0;
}

int main(void){
    int t;
    cin >> t;
    while (t--){
        cout << solve() << endl;
    }
    return 0;
}


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

int main() {
  int g[15][15];
  int n; cin >> n;
  rep(i,n) rep(j,n) g[i][j] = -1;

  rep(i,n) {
    int m; cin >> m;
    rep(j,m) {
      int x,y;
      cin >> x >> y;
      x--;
      g[i][x] = y;
    }
  }

  int ans = 0;
  rep(i,1<<n) {
    std::vector<int> d(n);
    rep(j,n) {
      if (i>>j&1) {
        d[j] = 1;
      }
    }

    bool ok = true;
    rep(j,n) {
      if(d[j]) {
        rep(k,n) {
          if (g[j][k] == -1) continue;
          if (g[j][k] != d[k]) ok = false;
        }
      }
    }
    if (ok) ans = max(ans, __builtin_popcount(i));
  }
  cout << ans << endl;
}


Measured memory_bytes: 3608
//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define pp pair<int,int>
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define ld long double
#define al(a) (a).begin(),(a).end()
#define mk make_pair
#define check cout<<"?"<<endl;

ll MOD=1000000007;
ll mod=998244353;
int inf=1000001000;
ll INF=1e18+5;

int main(){
    ll n,suma=0,sumb=0,r=0; cin>>n;
    vector<ll> a(n,0),b(n,0),ov;
    ll cnt=0;
    rep(i,n){
        cin>>a[i]; suma+=a[i];
    }
    rep(i,n){
        cin>>b[i]; sumb+=b[i];
        if(a[i]<b[i]){
            r+=b[i]-a[i]; cnt++;
        }
        else ov.push_back(a[i]-b[i]);
    }
    sort(al(ov)); reverse(al(ov));
    if(suma<sumb){
        cout<<-1<<endl;
        return 0;
    }
    ll ind=0;
    while(r>0){
        r-=ov[ind]; ind++;
    }
    cout<<cnt+ind<<endl;
}


Measured memory_bytes: 2936
#include<iostream>
#include<cstdlib>
#include<cmath>
using namespace std;

int main()
{
	int N;
	int a[110];
	int sum, minim;

	cin >> N;
	sum = 0;
	for (int i = 0; i < N; i++) {
		cin >> a[i];
		sum += a[i];
	}
	//ave = sum / N;
	minim = 1000 * N;
	for (int i = 0; i < N; i++) {
		if (minim > abs(sum - a[i] * N)) {
			minim = abs(sum - a[i] * N);
		}
	}
	
	for (int i = 0; i < N; i++) {
		if (minim == abs(sum - a[i] * N)) {
			cout << i << endl;
			//system("pause");
			return 0;
		}
	}

    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
 
#define FASTIO ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
using namespace std;
using ll = long long;
 
int main() {
	FASTIO
	ll k;
	cin >> k;
	ll y = 7 % k ;
	ll z = 10 % k;
	int c = 1;
	vector<bool> m( k + 1);
	while(y){
		y = y * z + 7;
//		clog << y << endl;
		y %= k;
		c++;
		if(m[y]){
			return cout << -1 << endl,0;
		}
		m[y] = 1;
	}
	cout << c << endl;
 
}

Measured memory_bytes: 3708
#include <stdio.h>
#include <math.h>
#include <iostream>
using namespace std;

#define EPS (1e-10)
#define equals(a, b) (fabs(a - b) < EPS)

class Point{
public:
    double x, y;

    Point(double x_ = 0, double y_ = 0){
        x = x_;
        y = y_;
    }

    Point operator+ (Point p){
        return Point(x + p.x, y + p.y);
    };

    Point operator- (Point p){
        return Point(x - p.x, y - p.y);
    };

    Point operator* (double k){
        return Point(x * k, y * k);
    }

    Point operator/ (double k){
        return Point(x / k, y / k);
    }

    double norm(){
        return x * x + y * y;
    }

    double abs(){
        return sqrt(norm());
    }

    bool operator == (const Point &p) const{
        return fabs(x - p.x) < EPS && fabs(y - p.y) < EPS;
    }
};

typedef Point Vector;

double dot(Vector a, Vector b){
    return a.x * b.x + a.y * b.y;
}

double cross(Vector a, Vector b){
    return a.x * b.y - a.y * b.x;
}

bool isParallel(Vector a, Vector b){
    return equals(cross(a, b), 0.0);
}

bool isOrthogonal(Vector a, Vector b){
    return equals(dot(a, b), 0.0);
}
;
double getCos(Vector a, Vector b){
    return dot(a, b) / (a.abs() * b.abs());
}

double dist(Point p1, Point p2){
    return sqrt(pow((p1.x - p2.x), 2) + pow((p1.y - p2.y), 2));
}

Point projection(Point p1, Point p2, Point p0){
    if(p1 == p0){
        return p0;
    }
    if(p2 == p0){
        return p0;
    }
    return p1 + (p2 - p1) / (p2 - p1).abs() * (p0 - p1).abs() * getCos(p2 - p1, p0 - p1);
}

Point reflection(Point p1, Point p2, Point p0){
    Point p = projection(p1, p2, p0);
    return p0 + (p - p0) * 2;
}

int main(){
    int xp1, yp1, xp2, yp2;
    scanf("%d", &xp1);
    scanf("%d", &yp1);
    scanf("%d", &xp2);
    scanf("%d", &yp2);

    Point p1 = Point(xp1, yp1);
    Point p2 = Point(xp2, yp2);

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

    for(int i = 0; i < q; i++){
        int xp0, yp0;
        scanf("%d", &xp0);
        scanf("%d", &yp0);

        Point p = reflection(p1, p2, Point(xp0, yp0));
        printf("%.10f %.10f\n", p.x, p.y);
    }
}




Measured memory_bytes: 3224
object Main extends App {
	val sc = new java.util.Scanner(System.in)
	val n  = sc.nextInt
	val as = Array.fill(n)(sc.nextLong)
	
	val MOD = 1000000007
	
	println((0 until 60).map(d => as.map(a => (a >> d) & 1L).sum).map(m => (n - m) * m % MOD)
						.zipWithIndex.map {case (m, d) => (m * ((1L << d) % MOD)) % MOD }
						.reduce((a, b) => (a + b) % MOD))
}

Measured memory_bytes: 143240
(let* ((n (read))
       (k (read))
       (p (make-array `(,(1+ n))))
       (c (make-array `(,(1+ n))))
       (s (make-array `(,(1+ n) ,(1+ n)) :initial-element 0))
       (sp (make-array `(,(1+ n) ,(1+ n)) :initial-element 0))
       (ans -1000000001))
  (loop :for i :from 1 :to n
        :do (setf (aref p i) (read)))
  (loop :for i :from 1 :to n
        :do (setf (aref c i) (read)))
  ;;
  (loop :for i :from 1 :to n
        :for j := i
        :do (loop :named inner
                  :for _ :from 1 :to n
                  :do (setf j (aref p j))
                  :do (setf (aref s i _) (+ (aref c j) (aref s i (1- _))))
                  :do (setf (aref sp i _) (if (or (<= 0 (aref sp i (1- _)) (aref s i _)) (= _ 1))
                                              (aref s i _)
                                              (aref sp i (1- _))))
                  :if (= j i)
                  :do (progn
                        (if (<= k _)
                            (setf ans (max ans (aref sp i k)))
                            (multiple-value-bind (x y) (floor k _)
                              (when (= y 0)
                                (setf y _)
                                (setf x (1- x)))
                              (setf ans (max ans (max (aref sp i _) (+ (* x (aref s i _)) (aref sp i y)))))))
                        (return-from inner))))
  ;;
  (format t "~A~%" ans))


Measured memory_bytes: 420776
#include <iostream>
#include <vector>
#include <set>
#include <map>
#include <sstream>
#include <string>
#include <cstdio>
#include <stack>
#include <queue>
#include <algorithm>
#include <numeric>
#include <functional>
#include <cstring>
#include <tuple>
#include <utility>
#include <list>
#include <cmath>

using namespace std;

typedef long long LL;
typedef vector<int> Array;
typedef pair<int, int> P;

const LL LINF = 1LL << 60;
const LL MOD = 100000;
#define rep(i,n) for(int i=0;i<(int)n;++i)
#define all(c) (c).begin(), (c).end()

struct edge{ LL to, cost; edge(int t, LL c) :to(t), cost(c){} };

int main()
{
	int n;
	while (cin >> n && n)
	{
		vector<P> points(n);
		set<P> exists;
		rep(i, n)
		{
			cin >> points[i].first >> points[i].second;
			exists.insert(points[i]);
		}
		sort(all(points));
		function<P(P&)> rotate = [](P& p) { return P(-p.second, p.first); };
		function<P(P&, P&)> subtract = [](P& p1, P& p2) { return P(p1.first - p2.first, p1.second - p2.second); };
		function<P(P&, P&)> add = [](P& p1, P& p2) {return P(p1.first + p2.first, p1.second + p2.second); };

		int ans = 0;
		rep(i, n)
		{
			P p1 = points[i];
			for (int j = i + 1; j < n; j++)
			{
				P p2 = points[j];
				P vec = subtract(p2, p1);
				P r = rotate(vec);
				P p3 = add(p1, r);
				if (!exists.count(p3)) continue;

				P nvec = subtract(p1, p3);
				P nr = rotate(nvec);
				P p4 = add(p3, nr);
				if (!exists.count(p4)) continue;

				ans = max(ans, (vec.first * vec.first + vec.second * vec.second));
			}
		}

		cout << ans << endl;
	}
	return 0;
}

Measured memory_bytes: 1360
#define _CRT_SECURE_NO_WARNINGS
#include <stdio.h>

int n;

int main(void) {
	char str[20] = { 0, }, copy[20] = { 0, }, max[20] = { 0, };
	scanf("%d", &n);
	if (n == 1) {
		printf("a");
		return 0;
	}

	for (int i = 0; i < n; i++) {
		str[i] = 'a';
	}
	
	//for (int i = 1; i < n; i++) {
		while (1) {
			printf("%s\n", str);
			if (str[n - 1] == 'a' + n - 1) break;

			max[0] = str[0];
			for (int j = 1; j < n; j++) {
				if (max[j - 1] > str[j]) max[j] = max[j - 1];
				else max[j] = str[j];
			}

			str[n-1] ++;
			int t = n-1;
			for (int j = 0; j < n; j++)
				copy[j] = str[j];

			while (str[t] == max[t-1]+2) {
				str[t] = 'a';
				str[t - 1] ++;
				t = t - 1;
			}

/*			if (str[i - 1] == i + 'a') {
				for (int j = 0; j < n; j++)
					str[j] = copy[j];
				break;
			}
			
			*/
		} 
//	}


	return 0;
}

Measured memory_bytes: 1408
//#include <bits/stdc++.h>
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstdlib>
#include <string>
#include <vector>
#include <map>
#include <queue>

using namespace std;

typedef long long ll;
typedef vector<int> vint;
typedef vector<vector<int> > vvint;
typedef vector<long long> vll, vLL;
typedef vector<vector<long long> > vvll, vvLL;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) for(int i=0;i<n;++i)
#define mod (ll)(1e9+7)
#define FIX(a) ((a)%mod+mod)%mod
#define ALL(obj) (obj).begin(), (obj).end()
#define rALL(obj) (obj).rbegin(), (obj).rend()
#define INF 1000000000 //1e9
#define LLINF 2000000000000000000LL //2e18
#define fi first
#define se second
#define pb push_back
int dy[]={0, 0, 1, -1};
int dx[]={1, -1, 0, 0};

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll a,b,c;
    cin >> a >> b >> c;
    if(c-a-b>0){
        ll x = c-a-b;
        if(x*x>4*a*b){
            cout << "Yes" << endl;
            return 0;
        }
    }
    cout << "No"  << endl;
    return 0;

    return 0;
}

Measured memory_bytes: 256
import sys
import heapq
import math
import fractions
import bisect
import itertools
from collections import Counter
from collections import deque
from operator import itemgetter
def input(): return sys.stdin.readline().strip()
def mp(): return map(int,input().split())
def lmp(): return list(map(int,input().split()))

n=int(input())
a,b,c,d=0,0,0,0
for i in range(n):
    s=input()
    if s=="AC":
        a+=1
    elif s=="WA":
        b+=1
    elif s=="TLE":
        c+=1
    else:
        d+=1
print("AC x",a)
print("WA x",b)
print("TLE x",c)
print("RE x",d)

Measured memory_bytes: 73200
import sys
import numpy as np
a, b, c = [int(i) for i in sys.stdin.readline().split()]
ls = np.array([a, b, c])
arr = np.array([[0, 0.5, 0.5],
                [0.5, 0, 0.5],
                [0.5, 0.5, 0]])
cnt = 0
while sum(ls % 2) == 0:
    if ls[0] == ls[1] == ls[2]:
        cnt = -1
        break
    ls = ls.dot(arr)
    cnt += 1
print(cnt)

Measured memory_bytes: 12640
#include <bits/stdc++.h>
#define F(i, l, r) for(int i = (l), _end_ = (int)(r); i <= _end_; ++i)
#define f(i, r, l) for(int i = (r), _end_ = (int)(l); i >= _end_; --i)
#define Set(a, v) memset(a, v, sizeof(a))
#define file(a) freopen(a".in","r",stdin),freopen(a".out","w",stdout)
using namespace std;

template<typename T>bool chkmax(T &a,T b){return (a<b)?a=b,1:0;}
template<typename T>bool chkmin(T &a,T b){return (a>b)?a=b,1:0;}

inline int read() {
 int x = 0, fh = 1; char ch = getchar();
    for (; !isdigit(ch); ch = getchar() ) if (ch == '-') fh = -1;
    for (; isdigit(ch); ch = getchar() ) x = (x<<1) + (x<<3) + (ch ^ '0');
    return x * fh;
}
int n;
int a[100005];
int b[100005];
int main () {
#ifndef ONLINE_JUDGE
//file("agc003c");
#endif
    n=read();
	F(i,1,n)a[i]=b[i]=read();
	sort(b+1,b+n+1);
	int ans=0;
	F(i,1,n){
	  a[i]=lower_bound(b+1,b+n+1,a[i])-b;
	  a[i]=abs(i-a[i]);
	  if(a[i]%2==1)ans++;
	}
	printf("%d\n",ans/2);
    return 0;
}

Measured memory_bytes: 1024
#include<stdio.h>
#include<stdlib.h>
struct node{
  struct node *right,*left,*parent;
  int key;
};

typedef struct node * Node;
Node root, NIL;
int max;
void insert(int);
void inorder(Node );
void preorder(Node );

int main(){
  int n, i, x;
  char com[20];
  scanf("%d", &n);
  max = 0;
  for ( i = 0; i < n; i++ ){
    scanf("%s", com);
    if ( strcmp(com, "insert") == 0 ){
      scanf("%d", &x);
      insert(x);
    }
    else if ( strcmp(com, "print") == 0 ){
      inorder(root);
      printf("\n");
      preorder(root);
      printf("\n");
    }
  }
  return 0;
}

void insert(int k){
  int H;
  Node y=NIL,x=root,z;
  z = malloc(sizeof(struct node));
  z->key = k;
  z->left = NIL;
  z->right = NIL;
  while( x != NIL ){   
    y = x;
    if ( z->key < x->key ){ 
      x = x->left; 
    }
    else {
      x = x->right; 
    }
  } 
  z->parent = y; 
  if ( y == NIL ){  
    root = z;
  }   
  else {
    if (z->key < y->key) { 
      y->left = z; 
    }
    else { 
      y->right = z; 
    }
  }
}
 
void inorder(Node u){   
  if ( u == NIL ) return; 
  inorder(u->left); 
  printf(" %d", u->key);
  inorder(u->right); 
}

void preorder(Node u){
  if ( u == NIL ) return;
  printf(" %d", u->key);
  preorder(u->left);
  preorder(u->right);
 
}

Measured memory_bytes: 24040
import java.io.*;
import java.util.*;

public class Main {

    private static FastReader in = new FastReader(System.in);
    private static PrintWriter out = new PrintWriter(System.out);

    private static final long MOD = (long) 1e9 + 7;

    public static void main(String[] args) {
        solve();
        out.flush();
    }

    private static void solve() {
        int n = in.nextInt();
        int w = in.nextInt();
        int[] weights = new int[n];
        long[] values = new long[n];
        for (int i = 0; i < n; i++) {
            weights[i] = in.nextInt();
            values[i] = in.nextInt();
        }

        long[] maxValue = new long[w + 1];
        for (int i = 0; i < n; i++) {
            for (int j = w - weights[i]; j >= 0; j--) {
                maxValue[j + weights[i]] = Math.max(maxValue[j + weights[i]], maxValue[j] + values[i]);
            }
        }

        out.println(maxValue[w]);
    }

    // https://www.geeksforgeeks.org/fast-io-in-java-in-competitive-programming/
    static class FastReader {
        BufferedReader br;
        StringTokenizer st;

        FastReader(InputStream inputStream) {
            br = new BufferedReader(new
                    InputStreamReader(inputStream));
        }

        String next() {
            while (st == null || !st.hasMoreElements()) {
                try {
                    st = new StringTokenizer(br.readLine());
                } catch (IOException  e) {
                    e.printStackTrace();
                }
            }
            return st.nextToken();
        }

        int nextInt() {
            return Integer.parseInt(next());
        }

        long nextLong() {
            return Long.parseLong(next());
        }

        double nextDouble() {
            return Double.parseDouble(next());
        }

        String nextLine() {
            String str = "";
            try {
                str = br.readLine();
            } catch (IOException e) {
                e.printStackTrace();
            }
            return str;
        }

        // https://qiita.com/masakinpo/items/5f77f2a879578a85a0bb
        public int[] nextIntArray(int n) {
            int[] a = new int[n];
            for (int i = 0; i < n; i++)
                a[i] = nextInt();
            return a;
        }

        public long[] nextLongArray(int n) {
            long[] a = new long[n];
            for (int i = 0; i < n; i++)
                a[i] = nextLong();
            return a;
        }
    }
}


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

int main() {
  int N, K;
  cin >> N >> K;
  vector<char> D(K);
  for (int i = 0; i < K; i++) cin >> D.at(i);
  
  int cost = N;
  string cost_str;
  while (cost < 100000) {
    cost_str = to_string(cost);
    bool isBreak = false;
    for (int i = 0; i < cost_str.size(); i++) {
      if (isBreak) break;
      for (int j = 0; j < D.size(); j++) {
        if (cost_str.at(i) == D.at(j)) {
          isBreak = true;
          break;
        }
        if (i == cost_str.size() - 1 && j == D.size() - 1) {
          cout << cost_str << endl;
          return 0;
        }
      }
    }
    cost++;
  }
}

Measured memory_bytes: 256
from collections import deque
n = int(input())
Ps = list(map(int, input().split()))
Ps = [p-1 for p in Ps]
fs = [0] * (n**2)

## フロアフィールドを作る
for x in range(n**2):
    i,j = divmod(x,n)
    x = min(i,n-1-i)
    y = min(j,n-1-j)
    fs[i*n+j] = min(x,y)

ans = 0
mvs = [1, -1, n, -n]
occupied = [1] * (n**2)
for p in Ps:
    ans += fs[p]
    occupied[p] = 0
    q = deque([])
    q.append(p)
    while len(q) > 0: #pを起点にBFS
        p_ = q.popleft()
        dist = fs[p_]
        for mv in mvs:
            if 0 <= p_+mv < n**2:
                p_next = p_ + mv
                # ある位置h,wが
                # occupiedなら、隣接マス+1で到達
                # vacantなら、隣接マス+0で到達
                if dist+occupied[p_] < fs[p_next]:
                    q.append(p_next)
                    fs[p_next] = dist + occupied[p_]

print(ans)
    
    

Measured memory_bytes: 172408
/**In the name of Allah, the Most Merciful, the Most Merciful.**/
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
#define INF 9223372036854775806
#define pb push_back
#define mp make_pair
#define MOD 1000000007
#define PI 2*acos(0.0)
#define EPS 1e-9
ll max(ll a,ll b) {if(a>b) return a; else return b;}
ll min(ll a,ll b) {if(a<b) return a; else return b;}

int main()
{
    ll n,x,m;
    cin>>n>>x>>m;
    ll sum=x;
    vector<ll> v;
    map<ll,ll> mark;
    v.pb(sum);
    mark[sum]=1;
    ll len=1;
    for(ll i=2;i<=min(n,m);i++){
        ll cur=sum;
        sum=sum*sum;
        sum=(sum%m);
        if(mark.find(sum)!=mark.end()){
            len=mark[sum];
            //v.pb(sum);
            break;
        }
        else{
            mark[sum]=i;
            v.pb(sum);
        }
    }

    //for(ll i:v) cout<<i<<" "; cout<<endl;
    len--;
    //cout<<len<<endl;
    //for(ll i:pat) cout<<i<<" "; cout<<endl;

    n-=(len);

    ll d=n/(v.size()-len);
    ll r=n%(v.size()-len);

    //cout<<d<<" "<<r<<endl;

    ll res=0;
    for(ll i=0;i<len;i++) res+=v[i];

    for(ll i=len;i<v.size();i++) res=(res+v[i]*d);
    for(int i=len;i<len+r;i++) res+=v[i];

    cout<<res<<endl;


    return 0;
}




Measured memory_bytes: 6536
ary = [1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14,
       1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51]

k = int(input())
print(ary[k - 1])


Measured memory_bytes: 2940
n, maxw = list(map(int, input().split()))
v_lis, w_lis = [], []   # in order, list for values, and for weights

# set data
for _ in range(n):
    v, c = list(map(int, input().split()))
    v_lis.append(v)
    w_lis.append(c)

# ?????´???????????????????????´????????§?¨±????????¨??????
# (Outer is for index of products, inner is maximum allowable amount)
dp = [[0 for _ in range(maxw+1)] for _ in range(n+1)]

for i in range(1, n+1):
    for j in range(1, maxw+1):
        if j>=w_lis[i-1]:
            dp[i][j] = max(dp[i-1][j], dp[i-1][j-w_lis[i-1]]+v_lis[i-1])
        else:
            dp[i][j] = dp[i-1][j]

print(dp[-1][-1])

Measured memory_bytes: 28100
#include <stdio.h>


int main(){

	int n, i, j;
	int A[101], tmp, mini;
	int count=0;

	scanf( "%d", &n );

	for( i=0; i<n; i++ )
		scanf( "%d", &A[i] );

	for( i=0; i<n; i++ ){
		mini = i;
		for( j=i; j<n; j++ )
			if( A[j] < A[mini] ) mini = j;
		
		//
		tmp = A[i];
		A[i] = A[mini];
		A[mini] = tmp;	
		if(i!=mini)count++; 

	}

	for( i=0; i<n; i++ )
		printf( "%d%c", A[i], i!=(n-1)?' ':'\n' );

	printf( "%d\n", count );



	return 0;
}

Measured memory_bytes: 600
#include <bits/stdc++.h>
#define F first
#define S second
#define PB push_back
#define MP make_pair
#define all(x) x.begin(), x.end()

using namespace std;

typedef vector<int> vi;
typedef pair<int,int> pi;
typedef vector<pi> vpi;
typedef long long ll;

template <typename T> void max_self(T& a, T b){
  a = max(a,b);
}

template <typename T> void min_self(T& a, T b){
  a = min(a,b);
}

void solve(){	
  int ans = 0;
  string s,t;
  cin>>s>>t;
  for(int i=0;i<s.size();i++)
    if(s[i] != t[i])ans++;

  cout<<ans<<endl;
}

int main(){
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  //int t; cin >> t;
  //while(t--) solve();
  //
  solve();
  return 0;
}


Measured memory_bytes: 3784
#include<iostream>
#include<vector>
#include<algorithm>

using namespace std;

int main(){
    int n,cnt;
    vector<int> v,w;
    cin>>n;
    v.resize(n);
    w.resize(n);
    for(int i=0; i<n; i++){
        cin>>v[i];
        w[i]=v[i];
    }
    sort(v.begin(),v.end());
    cnt=0;
    for(int i=0; i<n; i++){
        if(v[i]!=w[i]){
            cnt++;
        }
    }
 
    if(cnt<3){
        cout<<"YES"<<endl;
    }else{
        cout<<"NO"<<endl;
    }
    return 0;
}


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

int main(){
 cout<<fixed<<setprecision(5);
 int a,b;
 cin >>a>>b;
 
 cout<<a/b<<endl;
 cout<<a%b<<endl;
 cout<<(double)a/b<<endl;

}


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

int main(){
    int sx,sy,tx,ty;
    cin >> sx >> sy >> tx >> ty;
    for(int i=0; i<tx-sx; i++) cout << "R";
    for(int i=0; i<ty-sy; i++) cout << "U";
    for(int i=0; i<tx-sx; i++) cout << "L";
    for(int i=0; i<ty-sy+1; i++) cout << "D";
    for(int i=0; i<tx-sx+1; i++) cout << "R";
    for(int i=0; i<ty-sy+1; i++) cout << "U";
    cout << "L" << "U";
    for(int i=0; i<tx-sx+1; i++) cout << "L";
    for(int i=0; i<ty-sy+1; i++) cout << "D";
    cout << "R" << endl;

    return 0;
}

Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.ArrayDeque;

class Main {

	public static void main(String[] args) throws Exception {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		ArrayDeque<Process> queue = new ArrayDeque<Process>();
		String[] str01 = br.readLine().split(" ");
		int n = Integer.parseInt(str01[0]);
		int point = Integer.parseInt(str01[1]);
		int sumTime = 0;
		

		for (int i = 0; i < n; i++) {
			String[] str02 = br.readLine().split(" ");
			Process process = new Process(str02[0], Integer.parseInt(str02[1]));
			queue.add(process);
		}
		int i = 0;
		while (true) {
			Process temp = queue.poll();
			if (temp.time <= point) {
				sumTime = sumTime + temp.time;
				temp.time = sumTime;
				System.out.println(temp.name + " " + temp.time);
				i++;
				if(i == n){
					break;
				}
			} else {
				temp.time = temp.time - point;
				queue.add(temp);
				sumTime = sumTime + point;
			}
		}
	}
}

class Process {
	String name;
	int time;

	Process(String name, int time) {
		this.name = name;
		this.time = time;
	}
}

Measured memory_bytes: 60692
#include<bits/stdc++.h>
using namespace std;
///Welcome to Nasif's Code
#define bug printf("bug\n");
#define bug2(var) cout<<#var<<" "<<var<<endl;
#define co(q) cout<<q<<endl;
#define all(q) (q).begin(),(q).end()
typedef long long int ll;
typedef unsigned long long int ull;
const int MOD = (int)1e9+7;
const int MAX = 1e6;
#define pi acos(-1)
#define inf 1000000000000000LL
#define FastRead    ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
int arr[MAX];
int main()
{
    FastRead
    //freopen("output.txt", "w", stdout);
    int n,mx=0;
    cin>>n;
    for(int i=0;i<n;i++)
    {
        cin>>arr[i];
        mx+=arr[i];
    }
    cout<<(mx-n)<<endl;


    return 0;
}


Measured memory_bytes: 3640
#include <iostream>
#include <string>
#define rep(i,n) for(int i=0;i<(n);i++)
using namespace std;
int A[3];
int c1=0;
int c2=0;
string ans;
void solve()
{  
    rep(i,3)
    {
        if(A[i]==5)
        {
            c1++;
        }
        if(A[i]==7)
        {
            c2++;
        }
    }
    if(c1==2 && c2==1)
    {
        ans = "YES";
    }
    else
    {
        ans = "NO";
    }
}
int main()
{
    rep(i,3) 
    {
        cin >> A[i];
    }
    solve();
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
import sys
inputs = sys.stdin.readlines()

h, n = map(int, inputs[0].split())
AB = []
for s in inputs[1:]:
    a, b = map(int, s.split())
    AB.append((a, b))
AB.sort(key=lambda ab:ab[1])

dp = [10 ** 9] * (h+1)
dp[0] = 0
 
for i in range(h):
    for a, b in AB:
        k = min(i + a, h)
        dp[k] = min(dp[k], dp[i] + b)
print(dp[h])

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

using namespace std;
#define ll long long
#define pb push_back
#define vi vector<int>
#define vp vector<pair<int, int>>
#define vll vector<long long>
#define inf 1000000100
#define infll 1LL << 50

int main()
{
    int n;
    cin >> n;
    int c = 0;
    int ans = 1;
    for(int i = 1; i <= n; ++i)
    {
        int curr = 0;
        int j = i;
        while(j%2 == 0)
        {
            ++curr;
            j /= 2;
        }
        if(curr > c)
        {
            c = curr;
            ans = i;
        }
    }

    cout << ans << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define FOR(i,a,b) for (int i = (a); i < (b); ++i)
#define rep(i,n) for (int i = (0); i < (n); ++i)
#define rng(x) (x).begin(),(x).end()
#define rrng(x) (x).rbegin(),(x).rend()
#define show(x) cout << #x << " = " << (x) << endl;
#define show2(x,y) cout << #x << " = " << (x) << ", " << #y << " = " << (y) << endl;
#define show3(x,y,z) cout << #x << " = " << (x) << ", " << #y << " = " << (y) <<  ", " << #z << " = " << (z) << endl;
#define showv(v) rep(i,v.size()) printf("%d%c", v[i], i==v.size()-1?'\n':' ');
#define fi first
#define se second
#define pb push_back
#define eb emplace_back
#define sz(x) (int)(x).size()
#define bn(x) ((1<<x)-1)
#define dup(x,y) (((x)+(y)-1)/(y))
#define uni(x) x.erase(unique(rng(x)),x.end())
#define SP << " " <<
using namespace std;
using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vll = vector<ll>;
using pii = pair<int, int>;
using tiii = tuple<int, int, int>;
const int mod = 1000000007;
const double EPS = 1e-9;
const int INF = 1<<30;
const ll INFLL = 1LL<<60;
//cout << fixed << setprecision(10);

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

  auto f = [&](ll n) {
    if (n == -1) return 0LL;
    return n/x + 1;
  };

  ll ans = f(b) - f(a-1);
  cout << ans << endl;
  return 0;
}

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

using namespace std;

int main() {
    long long int n, m, x, c[13]={}, a[13][13], i, j, ma=10000000, ok=0, imsi, abil[13], gaza, k, gap;
    cin>>n>>m>>x;
    for(i=1;i<=n;i++)
    {
        cin>>c[i];
        for(j=1;j<=m;j++)
        cin>>a[i][j];
    }
    for(i=0;i<(1<<n);i++)
    {
        imsi=i;
        gap=0;
        for(j=1;j<=m;j++)
        abil[j]=0;
        for(j=1;j<=n;j++)
        {
            if(imsi%2)
            {
                gap+=c[j];
                for(k=1;k<=m;k++)
                abil[k]+=a[j][k];
            }
            
            
            imsi/=2;
        }
        gaza=0;
        for(j=1;j<=m;j++)
        gaza+=(abil[j]>=x);
        if(gaza==m)
        {
        ok=1;
        if(gap<ma)
        ma=gap;
        }
    }
    
    if(ok)
        cout<<ma;
    else
        cout<<"-1";
    
    return 0;
}

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

public class Main {

    public static void main(String[] args) {
        try {
            BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
            String[] strArray = br.readLine().split("\\s");
            Integer[] intArray = new Integer[3];
            for (int i = 0; i < strArray.length; i++) {
                intArray[i] = Integer.valueOf(strArray[i]);
            }
            for (int i = 0; i < intArray.length - 1; i++) {
                for (int j = intArray.length - 1; j > i; j--) {
                    if (intArray[j] < intArray[j - 1]) {
                        int t = intArray[j];
                        intArray[j] = intArray[j - 1];
                        intArray[j - 1] = t;
                    }
                }
            }
            System.out.println(intArray[0]+" "+intArray[1]+" "+intArray[2]);
        } catch (IOException e) {
            System.err.println(e);
        }

    }
}

Measured memory_bytes: 17044
#include<bits/stdc++.h>
#include<iostream>
#include<string>
#include<cmath>
#include<cstdio>
#include<cctype>
#include<cstring>
#include<iomanip>
#include<cstdlib>
#include<ctime>
#include<set>
#include<map>
#include<utility>
#include<queue>
#include<vector>
#include<stack>
#include<sstream>
#include<algorithm>
/************************************************/
#define rep(i,n) for(int i=0;i<n;i++)
#define m_p make_pair
#define pb push_back
#define fr first
#define se second
#define forn(i,a,n) for(int i=a;i<n;i++)
#define foreach(i,c) for(__typeof(c.begin())i=(c.begin());i!=(c).end();i++)
#define pii pair<int,int>
#define vi vector<int>
#define ll long long
#define sz(s) s.size()
#define all(s) s.begin(),s.end()
#define zero(x) memset(x,0,sizeof(x))
#define vii vector<pair<int,int> >
#define mpis map<int,string>
#define mpii map<int,int>
#define mpsi map<string,int>
#define re return
#define mod 1000000007
/************************************************/
using namespace std;

long long get(){
	char c=getchar();
	long long x=0LL;
	while(c<'0'||c>'9')
	c=getchar();
	while(c>='0'&&c<='9'){
		x*=10LL;
		x+=(c-'0');
		c=getchar();
	}
	return x;
}
int n;
int a[301][301],edge[301][301];
bool flag;
int main(){
	ios::sync_with_stdio(0);
	cin>>n;
	rep(i,n)
	rep(j,n)
	cin>>a[i][j];
	rep(k,n)
	rep(i,n)
	rep(j,n){
		if(i==j||i==k||j==k)
		continue;
		if(a[i][j]==a[i][k]+a[k][j])
        edge[i][j]=1; 
        if(a[i][j]>a[i][k]+a[k][j])
        flag=1;
	} 
	if(flag){
		cout<<-1<<endl;
		re 0;
	}
	ll ans=0;
	rep(i,n)
	rep(j,n)
	if(!edge[i][j])
	ans+=a[i][j];
	cout<<ans/2;		
	re 0;
}


Measured memory_bytes: 1024
import java.util.Arrays;
import java.util.Scanner;


public class Main {

	public static void main(String[] args) {
		// TODO Auto-generated method stub
		Scanner sc = new Scanner(System.in);
		Result [] resultArray = new Result[24];
		for(int i = 0; i < 24; i++) {
			int n = sc.nextInt();
			String str = sc.next(); 
			resultArray[i] = new Result(n, str);
		}
		Arrays.sort(resultArray, 0, 8);
		Arrays.sort(resultArray, 8, 16);
		Arrays.sort(resultArray, 16, 24);
		for(int i = 0; i < 3; i++) {
			System.out.println(resultArray[i * 8].num + " " + resultArray[i * 8].time);
			System.out.println(resultArray[i * 8 + 1].num + " " + resultArray[i * 8 + 1].time);
			resultArray[i * 8].time = "aaaa";
			resultArray[i * 8 + 1].time = "aaaa";
		}
		Arrays.sort(resultArray);
		System.out.println(resultArray[0].num + " " + resultArray[0].time);
		System.out.println(resultArray[1].num + " " + resultArray[1].time);
	}
	
}
class Result implements Comparable<Result> {
	int num;
	String time;
	Result(int num, String time) {
		this.num = num;
		this.time = time;
	}
	@Override
	public int compareTo(Result r) {
		return time.compareTo(r.time);
	}
}	

Measured memory_bytes: 26036
s = str(input())

rslt = s[::-1]

count = 0

if len(s)%2==0:

    for i in range(len(s)//2):

        if s[i] != rslt[i]:
            count += 1
else:
     for i in range(len(s)//2):

        if s[i] != rslt[i]:
            count += 1

           



print(count)

Measured memory_bytes: 3060
#include<algorithm>
#include<iostream>
#include<cstring>
#include<cstdio>
using namespace std;
const int MAXN=100+10;
int len;
char s[MAXN];
int main()
{
	scanf("%s",s);
	len=strlen(s);
	printf("%c%d%c",s[0],len-2,s[len-1]);
	return 0;
}

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

int main() {
    int n; cin >> n;
    vector<string> s(n);
    for (auto &si: s) cin >> si;
    if ((int)set<string>(s.begin(), s.end()).size() != n) {
        return !(cout << "No" << endl);
    }
    for (int i = 0; i + 1 < n; i++) if (s[i].back() != s[i + 1].front()) {
        return !(cout << "No" << endl);
    }
    cout << "Yes" << endl;
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
	int n;
	cin>>n;
	string s;
	cin>>s;
	int l = s.length();
	if(l<=n)
	cout<<s<<endl;
	else
	{
		for(int i=0;i<n;i++)
		cout<<s[i];
		cout<<"...\n";
	}
	return 0;
}

Measured memory_bytes: 3640
#include <iostream>
#include <string>
#include <vector>
#include <list>
#include <map>
#include <queue>
#include <stack>
#include <algorithm>
#include <fstream>
#include <sstream>
#include <iomanip>

using namespace std;

long long MOD = 1000000007;

int main(){
    string S;
    cin >> S;
    map<string, int> m;
    m["SUN"]=7;
    m["MON"]=6;
    m["TUE"]=5;
    m["WED"]=4;
    m["THU"]=3;
    m["FRI"]=2;
    m["SAT"]=1;
    cout << m[S] << endl;
}

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

int main(){
  int A, B, C, X, i, j, num=0;
  scanf("%d %d %d %d", &A, &B, &C, &X);
  for(i=0;i<=A;i++){
    if(i*500>X)break;
    for(j=0;j<=B;j++){
      if(i*500+j*100>X)break;
      if((X-(i*500+j*100))/50<=C)num++;
    }
  }
  printf("%d\n", num);
}


Measured memory_bytes: 128
def numBuses(people, cap, wait):
	buses = 0
	currentCap = 0
	departTime = -1
	for person in people:
		if departTime == -1 or currentCap == cap or departTime - person > wait:
			departTime = person
			buses += 1
			currentCap = 1
		else:
			currentCap += 1
	return buses

[n, cap, wait] = list(map(lambda x: int(x), input().split()))
people = []
for i in range(n):
	people.append(int(input()))
print(numBuses(sorted(people, reverse=True), cap, wait))

Measured memory_bytes: 8280
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const double EPS = 1e-9;
typedef vector<int> vint;
typedef pair<int, int> pint;
#define rep(i, n) REP(i, 0, n)
#define ALL(v) v.begin() , v.end()
#define REP(i, x, n) for(int i = x; i < n; i++)


int main(){
    string s; cin >> s;
    cout << s.substr(0, 4) << " " << s.substr(4, 8) << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <limits.h>
#include <vector>
#include <algorithm>
#include <cstring>
using namespace std;

int main() {
    int n, d, x, a[110];
    cin >> n;
    cin >> d >> x;
    for (int i = 1; i <= n; i++) {
        cin >> a[i];
        if (d % a[i] == 0) x = x + d / a[i];
      	else x = x + d / a[i] + 1;
    }
    cout << x;
    return 0;
}

Measured memory_bytes: 256
Som=list(str(input()))
S=[]
for i in Som:
    S.append(int(i))
if len(S)>=3:
    nums=0
    for x in range(len(S)):
        if x==0:
            nums+=S[0]*(10**(len(S)-1))
        else:
            nums+=S[x]*(10**(len(S)-1-x))*(2**(x-1))
    for y in range(len(S)-1):
        nums+=(sum(S[:len(S)-y]))*(10**y)*(2**(len(S)-2-y))
    print(nums)
if len(S)==2:
    print(11*S[0]+2*S[1])

if len(S)==1:
    print(S[0])

Measured memory_bytes: 3064
#include <algorithm>
#include <bitset>
#include <tuple>
#include <cstdint>
#include <cstdio>
#include <cctype>
#include <assert.h>
#include <stdlib.h>
#include <stdio.h>
#include <cassert>
#include <cfloat>
#include <climits>
#include <cmath>
#include <complex>
#include <ctime>
#include <deque>
#include <fstream>
#include <functional>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <list>
#include <limits>
#include <map>
#include <memory>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>
#include <math.h>

// ===============================================================

using namespace std;
using ll = long long;
using vl = vector<long long>;
using vll = vector<vector<long long>>;
using vs = vector<string>;
using vc = vector<char>;
using vcc = vector<vector<char>>;
using vm = vector<short>;
using vmm = vector<vector<short>>;
using pii = pair<int, int>;
using psi = pair<string, int>;
using ld = long double;
using ull = unsigned long long;

// ===============================================================

ll gcd(ll a, ll b) //最大公約数
{
	if (a % b == 0)
	{
		return(b);
	}
	else
	{
		return(gcd(b, a % b));
	}
}

ll lcm(ll a, ll b) //最小公倍数
{
	return a * b / gcd(a, b);
}

ll box(double a) //doubleの切り捨て
{
	ll b = a;
	return b;
}

ll fff(double a) //doubleの四捨五入
{
	ll b = a + 0.5;
	return b;
}

ll sum(ll n) { //整数sまでの合計
	if (n == 0) {
		return 0;
	}

	int s = sum(n - 1);
	return s + n;
}

bool prime(ll num)//素数判定、primeならtrue,違うならfalse
{
	if (num < 2) return false;
	else if (num == 2) return true;
	else if (num % 2 == 0) return false;
	double sqrtNum = sqrt(num);
	for (int i = 3; i <= sqrtNum; i += 2)
	{
		if (num % i == 0)
		{
			return false;
		}
	}

	// 素数である
	return true;
}

// ===============================================================

int main() {
	ll a;
	cin >> a;
	if (a % 2 == 0) {
		cout << 0.5 << endl;
	}
	else {
		double b = a;
		ll d = a / 2;
		cout << fixed << setprecision(16);
		cout << (b - d) / b << endl;
	}
}

Measured memory_bytes: 3856
#include <stdio.h>
#include <iostream>
using namespace std;

int main(void)
{	
	int a, b;
	cin >> a >> b;
	
	cout << "a ";
	
	if (a < b) cout << "<";
	else if (a > b) cout << ">";
	else cout << "==";
	
	cout << " b" << endl;
	
	return 0;
}

Measured memory_bytes: 3100
import java.util.*;
public class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    int x = sc.nextInt();
    int count = 0;
    while(count != 1){
      count = 0;
      for(int i = 2;i<=x;i++){
        if(x%i==0)count++;
      }
      x++;
    }
    x--;
    System.out.println(x);
  }
}


Measured memory_bytes: 35684
#include<bits/stdc++.h>
#define ll long long
#define debug(x) cout<<#x<<'='<<x<<endl
#define set0(x) memset(x,0,sizeof(x))
using namespace std;
const int inf=0x3f3f3f3f;
const int maxn=2e6+10;
double a[maxn];
int main()
{
   int n,m;
   cin>>n>>m;
   double sum=0;
   for(int i=1;i<=n;i++) cin>>a[i],sum+=a[i];
    sum=sum/(4.0*m);
    int cnt=0;
    for(int i=1;i<=n;i++)
    {
        if(a[i]>=sum) cnt++;
    }
    if(cnt>=m) puts("Yes");
    else puts("No");
   //system("pause");
   return 0;
}


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

int main()
{
    string s;
    cin >> s;
    int n = stoi(s);
    long mnum = 0, anum = 0, rnum = 0, cnum = 0, hnum = 0;
    for (int i = 0; i < n; i++)
    {
        cin >> s;
        if (s[0] == 'M')
        {
            mnum += 1;
        }
        else if (s[0] == 'A')
        {
            anum += 1;
        }
        else if (s[0] == 'R')
        {
            rnum += 1;
        }
        else if (s[0] == 'C')
        {
            cnum += 1;
        }
        else if (s[0] == 'H')
        {
            hnum += 1;
        }
    }
    long res = mnum * anum * rnum + mnum * anum * cnum + mnum * anum * hnum
            + mnum * rnum * cnum + mnum * rnum * hnum + mnum * cnum * hnum
            + anum * rnum * cnum + anum * rnum * hnum
            + anum * cnum * hnum
            + rnum * cnum * hnum;
    cout << res << endl;
    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<vector>
#include<string>
#include<utility>
#include<map>
#include<set>
#include<queue>
#include<math.h>
using namespace std;
#define mod (1000000000+7)
#define N (10007)
#define INF 1e16
typedef long long ll;
typedef pair<ll,ll> P;


int main(void){
	int n,p;
	while(true){
		cin>>n>>p;
		if(n==0 && p==0)break;
		set<int>per;
		vector<int>a(n);
		int index=0;
		int num=p;
		while(true){
			if(p!=0){
				a[index]++;
				p--;
				if(p==0){
					if(per.size()==1&&a[index]==num){
						cout<<index<<endl;
						break;
					}
					else per.insert(index);
				}
				else per.insert(index);
			}
			else{
				if(a[index]!=0){
					p+=a[index];
					a[index]=0;
					per.erase(index);
				}
			}
			//for(int i=0;i<n;i++)cout<<a[i]<<" ";
			//cout<<per.size()<<" "<<endl;
			index=(index+1)%n;
		}
	}
    return 0;
}


Measured memory_bytes: 3088
#include <iostream>
#include <math.h>
#include <algorithm>
#include <string>
using namespace std;

int main(void)
{
    long long a, b, c, d;
    long long e[4], max;
    int i = 0;
    cin >> a >> b >> c >> d;
    e[0] = a * c;
    e[1] = a * d;
    e[2] = b * c;
    e[3] = b * d;
    max = e[0];
    for (i = 1; i < 4; i++)
    {
        if (max < e[i])
        {
            max = e[i];
        }
    }
    cout << max << endl;
    return 0;
}

Measured memory_bytes: 3584
# AOJ 0133 Rotation of a Pattern
# Python3 2018.6.19 bal4u

a = [[[0 for c in range(8)] for r in range(8)] for k in range(4)]
title = ["0", "90", "180", "270"]

for r in range(8):
	a[0][r] = list(input())
for k in range(1, 4):
	print(title[k])
	for r in range(8):
		for c in range(8):
			a[k][c][7-r] = a[k-1][r][c]
	for r in range(8): print(*a[k][r], sep='')


Measured memory_bytes: 5588
#include <stdio.h>
int a[4][13];
int main(void){
    int i,j,k,n;
    char ch;
    scanf("%d",&n);
    for(k=0;k<4;k++){
        for(j=0;j<13;j++){
            a[k][j]=j+1;
        }
    }
    for(i=0;i<n;i++){
        scanf("%c", &ch);
        scanf("%c %d",&ch,&j);
        if(ch=='S') a[0][j-1]=0;
        if(ch=='H') a[1][j-1]=0;
        if(ch=='C') a[2][j-1]=0;
        if(ch=='D') a[3][j-1]=0;
    }
    for(k=0;k<4;k++){
        for(j=0;j<13;j++){
            if(a[k][j]!=0){
            if(k==0) printf("S %d\n",a[k][j]);
            if(k==1) printf("H %d\n",a[k][j]);
            if(k==2) printf("C %d\n",a[k][j]);
            if(k==3) printf("D %d\n",a[k][j]);
            }
        }
    }
    return 0;
}


Measured memory_bytes: 2600
import sys, math
from itertools import permutations, combinations
from collections import defaultdict, Counter, deque
from math import factorial#, gcd
from bisect import bisect_left #bisect_left(list, value)
sys.setrecursionlimit(10**7)
enu = enumerate
MOD = 10**9+7
def input(): return sys.stdin.readline()[:-1]
def pri(x): print('\n'.join(map(str, x)))

N = int(input())

fb = []
for i in range(1, N+1):
    if i%3==0 or i%5==0:
        fb.append(0)
    else:
        fb.append(i)
print(sum(fb))




Measured memory_bytes: 34068
k = int(input())
nums = set()


def rec(past: int, num: int):
    nums.add(num)
    if num > 10**10:
        return
    if past > 0:
        rec(past - 1, num * 10 + past - 1)
    rec(past, num * 10 + past)
    if past < 9:
        rec(past + 1, num * 10 + past + 1)


for i in range(1, 10):
    rec(i, i)
ans = sorted(nums)
print(ans[k - 1])

Measured memory_bytes: 157012
#pragma region Macros
#include <bits/stdc++.h>

using namespace std;
using ll = long long;

#define REP2(i, n) for (int i = 0, i##_len = (int)(n); i < i##_len; ++i)
#define REP3(i, l, r) for (int i = (l), i##_len = (int)(r); i < i##_len; ++i)
#define GET_MACRO_REP(_1, _2, _3, NAME, ...) NAME
#define REP(...) GET_MACRO_REP(__VA_ARGS__, REP3, REP2) (__VA_ARGS__)
#define RREP2(i, n) for (int i = (n - 1); i >= 0; --i)
#define RREP3(i, l, r) for (int i = (r - 1), i##_len = (l); i >= i##_len; --i)
#define GET_MACRO_RREP(_1, _2, _3, NAME, ...) NAME
#define RREP(...) GET_MACRO_REP(__VA_ARGS__, RREP3, RREP2) (__VA_ARGS__)
#define IN(type, n) type n; cin >> n
#define INALL(type, v) REP(i, v.size()) { IN(type, _tmp); v.at(i) = _tmp; }
#define ALL(x) (x).begin(), (x).end()
#define SZ(x) ((int)(x).size())

#ifdef _DEBUG
#define DEBUG(x) cout << #x << ": " << x << endl
#else
#define DEBUG(x)
#endif

template<class T>bool chmax(T &a, const T &b) { if (a < b) { a = b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b < a) { a = b; return 1; } return 0; }
#pragma endregion

int main() {
  IN(int, N);
  int count = 0;
  if (N < 105) {
    cout << "0" << endl;
    return 0;
  } else {
    REP(i, 105, (N + 1)) {
      int tmp_count = 0;
      REP(j, 1, ceil(sqrt(i))) {
        if (i % j == 0) tmp_count += 2;
      }
      if (tmp_count == 8) count++;
      i++;
    }
  }
  cout << count << endl;

  return 0;
}


Measured memory_bytes: 3632
def serch target, arr
  result = []
  arr.each{|x| result = x if x[0] == target}
  return result
end

def recipe_search target, recipes, items
  price = 0
  recipe = []
  recipe = serch(target, recipes)
  if recipe.size > 0
    recipe[2..-1].each do |x|
      price += recipe_search(x, recipes, items)
    end
    item = []
    item = serch(target, items)
    if item.size > 0 and price > item[1].to_i
      price = item[1].to_i 
    end
  else
    price = serch(target, items)[1].to_i
  end

  return price.to_i
end

while 0 < n = gets.chomp.to_i
  items=[]
  n.times{items << gets.chomp.split(' ')}

  recipes = []
  gets.chomp.to_i.times {recipes << gets.chomp.split(' ')}

  o = gets.chomp

  puts recipe_search(o, recipes, items)
end

Measured memory_bytes: 6120
import math
N, M = map(int, input().split())
mod = 10**9 + 7
answer = 0
if abs(N - M) == 0:
    answer = 2 * math.factorial(N)**2
elif abs(N - M) == 1:
    answer = math.factorial(max(N, M)) * math.factorial(min(N, M))

print(answer % mod)

Measured memory_bytes: 5180
#include <iostream>
#include <cstring>
#include <algorithm>

using namespace std;

#define ll long long

int main()
{
    ios_base::sync_with_stdio(false);
    string s,t;
    cin>>s>>t;
    char s_[s.length()],t_[t.length()];
    for(int i=0;i<s.length();i++)
        s_[i]=s[i];
    for(int i=0;i<t.length();i++)
        t_[i]=t[i];
    sort(s_,s_+s.length());
    sort(t_,t_+t.length(),greater<int>());
    string a="",b="";
    for(int i=0;i<s.length();i++)
        a+=s_[i];
    for(int i=0;i<t.length();i++)
        b+=t_[i];
//    cout<<a<<endl<<b;
    if(a<b)
        cout<<"Yes";
    else
        cout<<"No";
    cout<<endl;
    return 0;
}


Measured memory_bytes: 384