akhauriyash/Code-Regression huggingface dataset:
#include<stdio.h>
#include<iostream>
#include<string.h>
#include<algorithm>

using namespace std;

int a[1000][1000];

int main(){
	
	int n,d,i,j,k;
	scanf("%d",&n);
	for(d=1;d*d<=n+n;d++)
		if(d*(d+1)==n*2)break;
	if(d*(d+1)!=n+n){
		puts("No");
		return 0;
	}
	puts("Yes");
	d++;
	printf("%d\n",d);
	k=1;
	for(i=1;i<=d&&k<=n;i++)
		for(j=i;j<d&&k<=n;j++)
			a[i][j]=a[j+1][i]=k++;
	for(i=1;i<=d;i++){
		printf("%d ",d-1);
		for(j=1;j<d;j++)
			printf("%d ",a[i][j]);
		putchar(10);
	}
	return 0;
}
	
	

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

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        int x = sc.nextInt();
        int[] a = new int[N];
        for (int i = 0; i < N; i++) {
            a[i] = sc.nextInt();
        }
        Arrays.sort(a);
        int count = 0;
        for (int i = 0; i < N; i++) {
            if (a[i] > x)
                break;
            if (i == N - 1 && a[i] == x) {
                count++;
                break;
            } else if (i == N - 1) {
                break;
            } else {
                x = x - a[i];
                count++;
            }
        }
        System.out.println(count);
    }
}

Measured memory_bytes: 23252
//#define LOCAL

#include <fstream>
#include <iostream>
#include <cmath>
#include <algorithm>
#include <map>

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

using namespace std;



int main()
{
#ifdef LOCAL
    ifstream in("input.txt");
    cin.rdbuf(in.rdbuf());
#endif

    int n;
    typedef pair<int, int> P;
    P mx_w[30];

    while (true) {
        cin >> n;
        if (n == 0) break;

        rep(i,n) {
            int w, mx;
            cin >> w >> mx;
            mx_w[i] = P(mx, w);
        }

        sort(mx_w, mx_w + n);

        int now_w = 0;
        bool ans = true;
        rep(i,n) {
            now_w += mx_w[i].second;
            if (now_w > mx_w[i].first) {
                ans = false;
                break;
            }
        }

        if (ans) {
            cout << "Yes" << endl;
        } else {
            cout << "No" << endl;
        }
    }
}

Measured memory_bytes: 2984
#C問題
N = int(input())
H = list(map(int,input().split()))

flag = 0
for i in range(N):
    if i == 0:
        H[i]-=1
    elif i == 1:
        if H[i] > H[i-1]:
            H[i]-=1
        elif H[i] == H[i-1]:
            pass
        else:
            flag = 1
            break
    else:
        if H[i] >= H[i-1]:
            if H[i]>H[i-1]:
                H[i]-=1
        else:
            flag = 1
            break
            
if flag == 0:
    print("Yes")
else:
    print("No")

Measured memory_bytes: 14224
// E - Sum of gcd of Tuples (Hard)
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define irp(i,s,e) for(int i=(s);i>(e);--i)
#define MOD 1000000007
// a^n mod m を計算する(繰り返し二乗法,二分累乗法:O(logn)) (再帰版)
ll modpow(ll a,ll n){return n?modpow(a*a%MOD,n/2)*(n%2?a:1)%MOD:1;}

ll cnt_gcd[100001]; // [gcd:[1,K]] gcd 毎の個数

int main(){
	int N,K; cin>>N>>K;
	ll ans = 0;
	irp(g, K, 1-1){ // g:[K,1,-1] gcd を固定
		cnt_gcd[g] = modpow(K/g, N); // g の倍数の個数
		for(int n=2; n*g<=K; ++n) cnt_gcd[g] -= cnt_gcd[n*g]; // g*1 以外を除去
		ans = (ans + (cnt_gcd[g] * g % MOD)) % MOD;
	}
	cout<< (ans<0? ans+MOD: ans) <<endl; // 負数の修正
}

Measured memory_bytes: 4400
#include <stdio.h>
#include <stdlib.h>
#include <iostream>
#include <iomanip>
#include <vector>
#include <string.h>
#include <math.h>
#include <algorithm>
#include <map>
#include <queue>
#define rep(i,n) for (int i=0;i<(n);i++)

using namespace std;

int main() {
	int n;
	cin >> n;
	vector<long long> a(n);
	map<long long,long long> m;

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

	long long sum = 0;

	for (auto x : m) {
		if (m[x.first] > 1) {
			sum += m[x.first] * (m[x.first] - 1) / 2;
		}	
	}

	for (int i = 0;i < n;i++) {
		long long ans = sum;
		if (m[a[i]] > 1) {
			ans -= m[a[i]] - 1;
		}
		cout << ans << endl;
	}

	return 0;
}

//CCCCCCCCCCCCCC
//int main() {
//	double l;
//	cin >> l;
//
//	long double ans = pow(l / 3, 3);
//
//	printf("%.7llf", ans);
//
//	return 0;
//}

//BBBBBBBBBBBBBB
//int main() {
//	string s;
//	cin >> s;
//	int n = s.length();
//	string s1 = s.substr(0, (n - 1) / 2);
//	string _s = s;
//	string _s1 = s1;
//
//	reverse(_s.begin(), _s.end());
//	reverse(_s1.begin(), _s1.end());
//
//	if (s == _s && s1 == _s1) {
//		cout << "Yes" << endl;
//	}
//	else {
//		cout << "No" << endl;
//	}
//
//	return 0;
//}


//AAAAAAAAAAAAAAA
//int main() {
//	int n, m;
//	cin >> n >> m;
//	int ans = 0;
//	if (n >= 2)ans += n * (n - 1) / 2;
//	if (m >= 2)ans += m * (m - 1) / 2;
//	cout << ans << endl;
//
//	return 0;
//}

Measured memory_bytes: 12688
// AtCoder Beginner Contest 152

// Task B

// Coded by kintak

#include <bits/stdc++.h>

using namespace std;

int main() {
	long long i, a, b;
	cin >> a >> b;
	if (b <= a) for (i = 1; i <= a; i++) cout << b;
	else for (i = 1; i <= b; i++) cout << a;
}

Measured memory_bytes: 256
nm_list = input().split()
n = int(nm_list[0])
m = int(nm_list[1])
a_list = input().split()
a = [int(item) for item in a_list]
a.sort(reverse=True)

if a[m-1] < sum(a)/(4*m): print('No')
else: print('Yes')


Measured memory_bytes: 3060
n = int(input())
a = [int(i) for i in input().split()]

b = [i%4 for i in a]

b4 = b.count(0)
b2 = b.count(2)
b1 = n - b4 - b2

if b2 == 0:
  if b4 >= b1-1:
    print('Yes')
  else:
    print('No')
else:
  if b4 >= b1:
    print('Yes')
  else:
    print('No')

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

int main() {
    int a,b,k;
    cin >> a >> b >> k;
    int count = 0;
    for(int i=min(a,b); i>=1; i--){
        if(a%i==0 && b%i==0){
            count++;
        }
        if(count == k){
            cout << i << endl;
            break;
        }
    }
}

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

int main() {
  int N,a;
  cin>>N;
  vector<int> b(N);
  for(int i=0;i<N;i++){
    cin>>a;
    if(i%2==0){b.at(N/2+i/2)=a;}
    else{b.at(N/2-1-i/2)=a;}
  }
  if(N%2==1){reverse(b.begin(),b.end());}
  for(int i=0;i<N;i++){
    if(i==0){cout<<b.at(i);}
    else{cout<<' '<<b.at(i);}
  }
  cout<<endl;
}

Measured memory_bytes: 2944
import sys
input = sys.stdin.readline

n = int(input())
l = list(map(int,input().split()))

l.sort()
c = 0

import bisect

for i in range(n):
    for j in range(i+1,n):
        ind = bisect.bisect_left(l,l[i]+l[j])
        c += max((ind-j)-1 , 0)
        
print(c)

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

#define mod 1000000007

using namespace std;
 
int main(void){
	
	int N, sum = 0;
	vector<pair<int, int>> tasks;
	bool isyes = true;
	
	cin >> N;
	
	for(int i=0; i<N; i++){
		int a, b;
		cin >> a >> b;
		tasks.emplace_back(b, a);
	}
	
	sort(tasks.begin(), tasks.end());
	
	for(auto v : tasks){
		sum += v.second;
		if(sum > v.first){
			isyes = false;
			break;
		}
	}
	
	cout << (isyes ? "Yes" : "No");
	
	return 0;
}

Measured memory_bytes: 2420
#define _CRT_SECURE_NO_WARNINGS
#include<stdio.h>
#include<vector>
#include<functional>
#include<algorithm>
#include<stdlib.h>
#include<string>
#include<string.h>
#define _USE_MATH_DEFINES
#include<math.h>
#include<deque>
#include<set>
#include<map>
#include<queue>
#include<list>
#include<iostream>
#include <bitset>
using namespace std;
typedef long long ll;
#define rep(i,a,b) for(auto i=a;i<b;i++)
#define all(_x) _x.begin(), _x.end()
#define r_sort(_x) sort(_x.begin(), _x.end(), std::greater<int>())
#define vec_cnt(_a, _n) (upper_bound(all(_a), _n) - lower_bound(all(_a), _n))
#define vec_unique(_a) _a.erase(std::unique(all(_a)), _a.end());
ll gcd(ll a, ll b) { return a % b == 0 ? b : gcd(b, a % b); }
//ll lcm(ll a, ll b) { return (a / gcd(a, b)) * b; }
#define INF 1 << 30
const int mod = 1000000007;
int main() {
	int n, v;
	cin >> n;
	vector<int> f(n);
	vector<vector<int>>p(n, vector<int>(11));
	rep(i, 0, n) {
		rep(i2, 0, 10) {
			cin >> v;
			f[i] <<= 1;
			f[i] |= v;
		}
	}
	rep(i, 0, n) {
		rep(i2, 0, 11) {
			cin >> p[i][i2];
		}
	}
	int M = -INF, t;
	rep(i, 1, 1 << 10) {
		t = -INF;
		rep(i2, 0, n) {
			if (t == -INF)t = 0;
			t += p[i2][bitset<32>(f[i2] & i).count()];
		}
		M = max(t, M);
	}
	printf("%d\n", M);
	return 0;
}


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

#define rep(i,n) for(long long i = 0; i < (long long)(n); i++)
#define repi(i,a,b) for(long long i = (long long)(a); i < (long long)(b); i++)
#define pb push_back
#define all(x) (x).begin(), (x).end()
#define fi first
#define se second
#define mt make_tuple
#define mp make_pair
template<class T1, class T2> bool chmin(T1 &a, T2 b) { return b < a && (a = b, true); }
template<class T1, class T2> bool chmax(T1 &a, T2 b) { return a < b && (a = b, true); }

using ll = long long; using vll = vector<ll>; using vvll = vector<vll>; using P = pair<ll, ll>;
using ld = long double;  using vld = vector<ld>; 

int main(void) {
	
	string s; cin >>s;
	cout << "2018/01/" << s[8]<<s[9]  <<endl;
	
    return 0;
}

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

int main(){
    vector<int> v(3);
    for(int i=0;i<3;i++) cin>>v[i];
    
    sort(v.begin(),v.end());
    int ans=0;
    while(1){
        if(v[0]==v[1]&&v[1]==v[2]) break;
        if(v[2]==v[1]){
            v[0]+=2;
            ans++;
        }else{
            v[0]++;
            v[1]++;
            ans++;
        }
        sort(v.begin(),v.end());
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <cmath>
#include <algorithm>
#include <iomanip>
#include <cstring>
#include <map>
#define rep(i, N) for (int i = 0; i < (int)N; i++)
using namespace std;
typedef long long ll;
const ll LLINF = 9223372036854775807;
const int MOD = 1000000007;

int main() {
  int N; cin >> N;
  string S; cin >> S;

  int result = 0;
  rep(x, N) {
    string tmp_s = S.substr(x,N-x);
    int Z[N]= {};
    int i = 1, j = 0;
    while (i<N-x) {
      while (i+j<N && tmp_s[j]==tmp_s[i+j]) j++;
      Z[i] = j;
      if (j==0) { i++; continue; }
      int k = 1;
      while (k+Z[k]<j) { Z[i+k]=Z[k]; k++; }
      i += k; j -= k;
    }
    rep(i,N-x) result = max(result, min(i, Z[i]));
  }
  cout << result << endl;
  return 0;
}

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

int main() {
    int x, y;
    scanf("%d %d", &x, &y);
    bool ok = 0;
    for (int i = 0; i <= x; i++) {
        if (i * 2 + (x - i) * 4 == y) ok = 1;
    }
    if (ok) printf("Yes\n");
    else printf("No\n");
}

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


int main() {
  int a,b;
  
  cin >> a >> b;
  
  int dis = abs(a-b);
  
  
  
  if(dis%2 == 0)
    cout << (a+b)/2;
  
  else{
    cout << "IMPOSSIBLE";
    return 0;
  }
    
  
}


Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
const ll MOD = 1e9 + 7;
const ll INF = 1LL << 60;

int main() {
	int N;
	cin >> N;
	int ans = 0;
	for (int i = 1; i <= N; i++) {
		int x = i;
		int d = 0;
		while (x) {
			x /= 10;
			d++;
		}
		if (d % 2) ans++;
	}
	cout << ans << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <climits>
#include <cmath>
#include <map>
#include <queue>
#include <iomanip>
#include <set>
using namespace std;

#define rep(i,n) for(ll (i)=0;(i)<(n);(i)++ )
#define repf(i,m,n) for(ll (i)=m;(i)<n;(i)++)
#define all(v) (v).begin(), (v).end()
#define ll long long
#define vec(name,num) vector<ll> name((num),0);
#define op(i) cout<<(i)<<endl;
#define opf(i) cout<<fixed<<setprecision(10)<<(i)<<endl;
#define ip(i) cin>>(i);
#define opN cout<<"No"<<endl;
#define opY cout<<"Yes"<<endl;
#define opP cout<<"Possible"<<endl;
#define opI cout<<"Impossible"<<endl;
#define mat(name,fnum,snum); vector<vector<ll>> name((fnum),vector<ll>((snum),0));
#define matC(name,fnum,snum); vector<vector<char>> name((fnum),vector<char>((snum),0));
#define debugP int debug_point; cin>>debug_point;
#define FI first
#define SE second
const ll MOD= 1e9 + 7;

//
void solve(long long r){
  op(3*r*r)
}

// Generated by 1.1.4 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
int main(){
    long long r;
    scanf("%lld",&r);
    solve(r);
    return 0;
}


Measured memory_bytes: 256
import java.util.*;

public class Main{

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int a[] = new int[n];
		int b[] = new int[n];
		for(int i = 0; i < n; ++i) 
			a[i] = sc.nextInt();
		for(int i = 0; i < n; ++i)
			b[i] = sc.nextInt();
		sc.close();
		String ans[] = {"Yes", "No"};
		int an = 0;
		long tmp = 0, tmp3 = 0;
		for(int i = 0; i < n; ++i) {
			int tmp2 = b[i] - a[i];
			tmp += (long)tmp2;
			if(tmp2 < 0)tmp2 = 0;
			tmp3 += (long)((tmp2 + 1)/ 2);
		}
		if(tmp < 0)an = 1;
		else {
			if(tmp < tmp3)an = 1;
		}
		System.out.println(ans[an]);
	}

}


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

#ifdef LOCAL
#define debug(var) cerr << (#var) << " = " << (var) << endl;
#else
#define debug(var)
#endif

void init() {
    ios_base::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);
}

void solve() {
    int n, d, x; scanf("%d%d%d", &n, &d, &x);
    int ans = 0;
    for (int i = 0; i < n; ++i) {
        int a; scanf("%d", &a);
        for (int j = 0; j < d; ++j) {
            if (j%a) continue;
            ++ans;
        }
    }
    printf("%d", ans+x);
}

int main() {
    init();
    int t = 1; //scanf("%d", &t);
    while (t--) {
        solve();
    }
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
const int INF = 1000000007;
 
int main(){
  cin.tie(nullptr);
  ios::sync_with_stdio(false);

  int64_t N;
  cin >> N;
  vector<int64_t> A(N), B(N), C(N);
  for(int i=0;i<N;i++){
    cin >> A[i];
  }
  for(int i=0;i<N;i++){
    cin >> B[i];
  }
  for(int i=0;i<N;i++){
    cin >> C[i];
  }
  int64_t ans = 0;
  sort(A.begin(), A.end());
  sort(B.begin(), B.end());
  sort(C.begin(), C.end());
  for(int i=0;i<N;i++){
    int64_t ab = lower_bound(A.begin(), A.end(), B[i]) - A.begin();
    int64_t bc = C.end() - upper_bound(C.begin(), C.end(), B[i]);
    ans += ab * bc;
  }
  cout << ans << endl;
}

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

int main(){
    
    int N,K;cin>>N>>K;
    vector<int> A(N),sum(N+1,0);
    vector<pair<int,int>> B(N+1);
    for(int i=0;i<N;i++){
        cin>>A[i];
        A[i]=(A[i]-1)%K;
        //cout<<A[i]<<" ";
    }
    for(int i=1;i<N+1;i++){
        sum[i]=(sum[i-1]+A[i-1])%K;
    }
    
    for(int i=0;i<N+1;i++){
        B[i]={sum[i],i};
    }
    
    sort(all(B));
    
    ll ans=0;
    
    for(int i=0;i<N+1;i++){
        auto left=lower_bound(all(B),make_pair(B[i].first,B[i].second));
        auto right=lower_bound(all(B),make_pair(B[i].first,B[i].second+K));
        ans+=right-left-1;
    }
    
    cout<<ans<<endl;
}



Measured memory_bytes: 3328
from heapq import *
n, m = (int(i) for i in input().split())
a = [int(i) for i in input().split()]
bc = [[int(i) for i in input().split()] for i in range(m)]
heapify(a)
bc.sort(key=lambda x:x[1],reverse=True)
maxlength = bc[0][0]
maxnumber = bc[0][1]
newbc = [[maxlength,maxnumber]]
for k,l in bc:
    if k > maxlength:
        newbc.append([k-maxlength,l])
        maxlength = k
 
for remain,number in bc:
    while remain > 0:
        temp = heappop(a)
        if number > temp:
            heappush(a,number)
            remain -= 1
        else:
            heappush(a,temp)
            remain = 0
print(sum(a))

Measured memory_bytes: 100888
var input = '';
var readable = process.stdin;
readable.resume();
readable.setEncoding( 'utf-8' );
readable.on( 'data', function( chunk ) {
  input += chunk;
});

readable.on( 'end', function() {
  var data = input.split( '\n' );
  var output = [];
  for( var index=0; index<data.length; index++ ) {
    var nums = data[index].split( ' ' ).map( Number );
    var n = nums[0];
    var x = nums[1];
    if( 0 == n && 0 == x ) { break; }

    var cnt = 0;
    for( var i=1; i<n; i++ ) {
      for( var j=i+1; j<=n; j++ ) {
        var k = x-i-j;
        if( j < k && k <= n ) { cnt++; }
      }
    }
    output.push( cnt );
  }
  console.log( output.join( '\n' ) );
});
 

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

typedef long long ll;

int main() {
    ll N, B = 1, C = 1e18;
    cin >> N;
    vector<ll> A(N);
    rep(i, N) cin >> A[i];
    rep(i, N) {
        if (A[i] == 0) {
            cout << "0\n";
            return 0;
        }
    }
    rep(i, N) {
        ll D = B * A[i];
        if (D > C || D < B) {
            cout << "-1\n";
            return 0;
        }
        B = D;
    }
    cout << B << "\n";
}

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

int main() {
	int n, m, x,a[100],y=0,z=0;
	cin >> n >> m >> x;
	for (int i = 0; i < m; i++) {
		cin >> a[i];
	}

	for (int i = 0; i < m; i++) {
		if (x > a[i])y++;
		if (x < a[i])z++;
	}
	if (y > z) {
		y = z;
	}
	cout << y << endl;
}

Measured memory_bytes: 256
#include <stdio.h>

#define Mod 998244353

long long div_mod(long long x, long long y, long long z)
{
	if (x % y == 0) return x / y;
	else return (div_mod((1 + x / y) * y - x, (z % y), y) * z + x) / y;
}

long long combination(int n, int k)
{
	if (k == 0 || n == k) return 1;
	
	static long long ans[301][301] = {};
	if (ans[n][k] != 0) return ans[n][k];
	
	int i;
	long long x, y;
	for (i = n, x = 1; i >= n - k + 1; i--) x = x * i % Mod;
	for (i = 2, y = 1; i <= k; i++) y = y * i % Mod;
	ans[n][k] = div_mod(x, y, Mod);
	return ans[n][k];
}

int main()
{
	char S[301] = {};
	scanf("%s", S);

	int i, j, k, l, m, count[301][2] = {};
	for (i = 0; S[i] != 0; i++) {
		count[i+1][S[i] - '0'] = count[i][S[i] - '0'] + 1;
		count[i+1][1 - S[i] + '0'] = count[i][1 - S[i] + '0'];
	}
	if (i == 1) {
		printf("1\n");
		fflush(stdout);
		return 0;
	}
	
	int dis[301][301];
	for (i = 0; S[i] != 0; i++) {
		for (j = 0; S[j] != 0; j++) dis[i][j] = -1;
	}
	if (S[0] != S[1]) {
		dis[0][1] = 1;
		dis[1][0] = 1;
	} else if (S[0] == '0') dis[1][0] = 1;
	else dis[0][1] = 1;
	for (i = 2; S[i] != 0; i++) {
		for (j = 0; j <= count[i][0]; j++) {
			for (k = 0; k <= count[i][1]; k++) {
				if ((S[i] == '0' || S[i-1] == '0') && dis[j+1][k] < dis[j][k] + 2 && dis[j][k] == i - 2) dis[j+1][k] = dis[j][k] + 2;
				if ((S[i] == '0' || count[i][0] > j) && dis[j+1][k] < dis[j][k] + 1 && dis[j][k] == i - 1) dis[j+1][k] = dis[j][k] + 1;
				if ((S[i] == '1' || S[i-1] == '1') && dis[j][k+1] < dis[j][k] + 2 && dis[j][k] == i - 2) dis[j][k+1] = dis[j][k] + 2;
				if ((S[i] == '1' || count[i][1] > k) && dis[j][k+1] < dis[j][k] + 1 && dis[j][k] == i - 1) dis[j][k+1] = dis[j][k] + 1;
			}
		}
	}
	for (j = 0; j <= count[i][0]; j++) {
		for (k = 0; k <= count[i][1]; k++) {
			if (dis[j][k] == i - 1) {
				for (l = j + 1; l <= count[i][0]; l++) dis[l][k] = i - 1;
				for (l = k + 1; l <= count[i][1]; l++) dis[j][l] = i - 1;
			}
		}
	}
	
	long long dp[301][301][301] = {};
	for (j = 0; j <= i; j++) {
		for (k = 0; k <= i - j; k++) dp[0][j][k] = combination(j + k, j);
	}
	for (l = 1; l <= i; l++) {
		for (j = 1; j <= l; j++) {
			for (k = 0; k <= l - j; k++) {
				dp[j][k][l-j-k] = dp[j-1][k][l-j-k];
				if (k > 0 && S[i-j] == '1') dp[j][k][l-j-k] += dp[j][k-1][l-j-k];
				else if (l - j - k > 0 && S[i-j] == '0') dp[j][k][l-j-k] += dp[j][k][l-j-k-1];
				dp[j][k][l-j-k] %= Mod;
			}
		}
	}
	
	long long ans = 0;
	for (j = 0; j <= count[i][0]; j++) {
		for (k = 0; k <= count[i][1]; k++) {
			if (dis[j][k] != -1) ans = (ans + dp[i-dis[j][k]-1][count[dis[j][k]+1][0]-j][count[dis[j][k]+1][1]-k]) % Mod;
		}
	}
	
	printf("%lld\n", ans);
	fflush(stdout);
	return 0;
}

Measured memory_bytes: 215824
N, K = map(int,input().split())
X = list(map(int,input().split()))

M = []
P = [0]
Z_flag = False
for x in X:
    if x < 0:
        M.append(-x)
    elif x > 0:
        P.append(x)
    else:
        Z_flag = True
M.reverse()
M.insert(0, 0)

if Z_flag:
    K -= 1

ans = 10 ** 9
len_m = len(M)
len_p = len(P)
for i in range(K+1):
    if i < len_m and 0 <= K-i < len_p:
        tmp = M[i] + P[K-i] + min(M[i], P[K-i])
        ans = min(ans, tmp)
print(ans)


Measured memory_bytes: 14252
N,X,M = map(int,input().split())

ans = 0

dic = {}

roopCounter = 0
tmp = X
dic[tmp]=0
consump=0

while True:
    ans += tmp
    tmp = pow(tmp,2,M)
    roopCounter += 1
    if tmp in dic:
        consump = roopCounter
        roopCounter = roopCounter-dic[tmp]
        rooper = tmp
        break
    else:
        dic[tmp]=roopCounter

new_dic = {}
tmp = rooper
new_dic[tmp]=0
while True:
    tmp = pow(tmp,2,M)
    if tmp in new_dic:
        break
    else:
        new_dic[tmp]=0
once = 0
for i in new_dic:
    once+=i

ans += once*((N-consump)//roopCounter)

tmp = rooper
for i in range(0,(N-consump)%roopCounter):
    ans += tmp
    tmp = pow(tmp,2,M)

print(ans)

Measured memory_bytes: 83220
/*------------------------------------
........Bismillahir Rahmanir Rahim....
..........created by Abdul Aziz.......
------------------------------------*/
#include <iostream>
#include <algorithm>
#include <stdio.h>
#include <cmath>
#include <vector>
#include <set>
#include <list>
#include <stack>
#include <map>
#include <cstring>
#include <unordered_map>
#include <queue>
#define   mod  998244353
#define   int  long long 
#define   ld   long double
#define   pb   push_back
#define   vi  vector<int> 
#define   dbg(x)  cerr << #x << " = " << x << '\n'
#define   sz(x)  (int)x.size()
#define   all(a) (a.begin(),a.end())
#define   ff   first
#define   ss   second
#define   pii  pair<int,int> 
#define   lcm(a,b) (a*b)/__gcd(a,b) 
using namespace std;

int dp[13][100005];

inline void solve(){
    int yen; cin>>yen; 
    int a[13]={0,1,6,9,36,81,216,729,1296,6561,7776,46656,59049};
    fill(dp[0]+1,dp[0]+100005,1e9);
    for (int i=1;i<=12;i++){
    	for(int j=1;j<=yen;j++){
    		if (a[i]>j) dp[i][j] = dp[i-1][j] ; 
    		else dp[i][j] = min(dp[i-1][j],dp[i][j-a[i]]+1);
    	}
    }
    cout << dp[12][yen] << endl;
}

signed main()
{
    int n=1; // cin>>n;
    while (n--) solve();
    return 0;
}


Measured memory_bytes: 13756
#include <iostream>
using namespace std;
int main() {
    int n, t, max = -1, min = 1001;
    cin >> n;
    for (int i = 0; i < n; ++i) {
        cin >> t;
        if (t > max)
            max = t;
        if (t < min)
            min = t;
    }
    cout << max - min;
}

Measured memory_bytes: 256
//abc137_e.cpp
//Sun Oct 27 18:09:19 2019

#include <iostream>
#include <string>
#include <queue>
#include <map>
#include <unordered_map>
#include <vector>
#include <algorithm>
#include <math.h>
#include <set>
#define INTINF 2147483647
#define LLINF 9223372036854775807
using namespace std;
using ll=long long;
typedef pair<int,int> P;

struct edge {ll from, to, cost;};

edge es[5000];
ll d[2503];
int v,e;
int flag = 0;
int reachable[2503];

void shortest_path(int s){
	//始点sから最短距離の配列を初期化
	for (int i=0;i<v;i++){
		d[i] = -LLINF;
		reachable[i] = -1;
	}
	//始点sから始点への最短距離は当然0
	d[s] = 0;
	reachable[v-1] = 1;
	for (int j=0;j<2*v;j++){
		bool update = false;
		for (int i=0;i<e;i++){
			edge e = es[i];
			//eの始点が初期値でなかったら、eの終点への距離更新を考慮
			if (d[e.from] != -LLINF && d[e.to] < d[e.from] + e.cost){
				d[e.to] = d[e.from] + e.cost;
				if (reachable[e.to]==1){
					reachable[e.from] = 1;
				}
				update = true;
//				if (e.to==v-1 && j>=v-1){
				if (reachable[e.to]==1 && j>=v-1){
					flag = 1;
				}
//			}else if (d[e.to] != INF && d[e.from] > d[e.to] + e.cost){
//				d[e.from] = d[e.to] + e.cost;
//				update = true;
			}
		}
		//最短距離が全く更新されなくなったらループ抜けて終了
		if (!update){
			break;
		}
	}
}


int main(){
	int p;
	cin >> v >> e >> p;

	for (int i=0;i<e;i++){
		ll a,b,c;
		cin >> a >> b >> c;
		a--;b--;
		es[i].from = a;
		es[i].to = b;
		es[i].cost = c-p;
	}

	shortest_path(0);

	if (flag == 1){
		cout << -1 << endl;
	}else if (d[v-1]<=0){
		cout << 0 << endl;
	}else {
		cout << d[v-1] << endl;
	}
//	printf("%.4f\n",ans);
}

Measured memory_bytes: 384
n = int(input())
array = list(map(int, input().split()))
status = 0
past = 0
tail = 0
count = 1
for i in range(1, n):
    past = status
    if(array[i-1] < array[i]):
        if(status == 0):
            past = 1
        status = 1
    elif(array[i-1] > array[i]):
        if (status == 0):
            past = 2
        status = 2

    if(status != past):
        count += 1
        i += 2
        past = 0
        status = 0
        continue




print(count)

Measured memory_bytes: 14252
n = int(input())
prime = (2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37)
factor = {}
for i in prime:
    factor[i] = 0

for i in range(n):
    test = i+1
    for j in prime:
        while test%j == 0:
            factor[j] += 1
            test //= j
    if test != 1:
        if test not in factor:
            factor[test] = 1
        else:
            factor[test] += 1

ans, MOD = 1, 10**9+7
for i in factor:
    ans *= factor[i]+1
    ans %= MOD
print(ans)

Measured memory_bytes: 3064
#include<stdio.h>
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<string.h>

//#ifdef LOCAL
//#define eprintf(...) fprintf(stderr, __VA_ARGS__)
//#else
//#define NDEBUG
//#define eprintf(...) do {} while (0)
//#endif
#include<cassert>

using namespace std;

typedef long long LL;
typedef vector<int> VI;

#define REP(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define EACH(i,c) for(__typeof((c).begin()) i=(c).begin(),i##_end=(c).end();i!=i##_end;++i)

template<class T> inline void amin(T &x, const T &y) { if (y<x) x=y; }
template<class T> inline void amax(T &x, const T &y) { if (x<y) x=y; }
template<class Iter> void rprintf(const char *fmt, Iter begin, Iter end) {
    for (bool sp=0; begin!=end; ++begin) { if (sp) putchar(' '); else sp = true; printf(fmt, *begin); }
    putchar('\n');
}

int N;
VI G[100011];
VI ord;
int par[100011];
int dp[100011];
VI t, st;

bool ok(int mid) {
    REP (i_, N) {
	int v = ord[N-1-i_];
	t.clear();
	EACH (e, G[v]) if (*e != par[v]) {
	    if (dp[*e]+1 > mid) return false;
	    t.push_back(dp[*e]+1);
	}

	if (v == 0) {
	    int m = t.size()/2;
	    sort(t.begin(), t.end());
	    REP (j, m) if (t[j] + t[m*2-1-j] > mid) return false;
	    return true;
	} else {
	    if (t.size() % 2 == 0) t.push_back(0);
	    sort(t.begin(), t.end());
	    st.clear();
	    int pos = 0;
	    dp[v] = -1;
	    for (int j=t.size()-1; j>=0; j--) {
		int c = t[j];
		if (c == -1) break;
		while (pos < j && t[pos] + c <= mid) {
		    st.push_back(t[pos]);
		    t[pos] = -1;
		    pos++;
		}
		if (st.empty()) {
		    if (dp[v] == -1) dp[v] = c;
		    else return false;
		} else {
		    st.pop_back();
		}
	    }

	    if (dp[v] == -1) {
		dp[v] = st[0];
	    }
	}
    }

    assert(false);
}

void MAIN() {
    scanf("%d", &N);
    REP (i, N-1) {
	int x, y;
	scanf("%d%d", &x, &y);
	x--; y--;
	G[x].push_back(y);
	G[y].push_back(x);
    }

    ord.reserve(N);
    ord.push_back(0);
    REP (i, N) {
	int v = ord[i];
	EACH (e, G[v]) if (*e != par[v]) {
	    par[*e] = v;
	    ord.push_back(*e);
	}
    }

    int A = 1;
    REP (i, N) {
	A += ((int)G[i].size() - 1) / 2;
    }

    int lo = 0, hi = N-1;
    while (hi - lo > 1) {
	int mid = (lo + hi) / 2;
	(ok(mid)? hi: lo) = mid;
    }
    printf("%d %d\n", A, hi);
}

int main() {
    int TC = 1;
//    scanf("%d", &TC);
    REP (tc, TC) MAIN();
    return 0;
}



Measured memory_bytes: 8440
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#define min(a,b) ((a)<(b)?(a):(b))
#define abs(a) ((a)>(0)?(a):-(a))
int main(){
  char a[12];
  scanf("%s",a);
  int l=strlen(a);
  int ans=999,num,i;
  for(i=0;i<l-2;i++){
    num=0;
    num+=((int)a[i]-48)*100;
    num+=((int)a[i+1]-48)*10;
    num+=(int)a[i+2]-48;
    ans=min(ans,abs(753-num));
  }
  printf("%d",ans);
}

Measured memory_bytes: 128
#include <string>
#include <queue>
#include <stack>
#include <vector>
#include <sstream>
#include <algorithm>
#include <deque>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <list>
#include <cstdio>
#include <iostream>
#include <cmath>
#include <climits>
#include <bitset>
#include <functional>
#include <numeric>
#include <ctime>
#include <cassert>
#include <cstring>
#include <fstream>

#define FOR(i, a, b) for(int (i)=(a); (i)<(b); (i)++)
#define IFOR(i, a, b) for(int (i)=(a);(i)<=(b);(i)++)
#define RFOR(i, a, b) for(int (i)=(a);(i)>=(b);(i)--)

using namespace std;

int main() {
    int n, m;
    cin >> n >> m;
    vector<int> num(n, 0);
    FOR(i, 0, m) {
        int a, b;
        cin >> a >> b;
        a--, b--;
        num[a]++, num[b]++;
    }
    for (auto t : num)
        cout << t << endl;
    return 0;
}

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

int main(){
	string s;
	cin >> s;
	long long sum = 0;
	long long len = s.size();
	for(long long i=0;i<len;i++){
			long long  t = i,js1=0,js2=0;
			while(1){
				if(t == len-1){if(s[t] == '<')
						js1++;else
						js2++; 
					break;
				}if(s[t] == '>' && s[t + 1]  == '<'){
					js2++;
					break;
				}
				if(s[t] == '>')js2++;else if(s[t] == '<')js1++;t++;
			}
			i = t;
			if(js1 <= js2){
				long long  ss1 = 0;
				sum += (ss1 + (js1-1)) * js1 / 2;
				long long  ss2 = 1;
				sum += (ss2 + js2) * js2 / 2; 
			}
			else{
				long long  ss1 = 1;
				sum += (ss1 + js1) * js1 / 2;
				long long  ss2 = 0;
				sum += (ss2 + (js2-1)) * js2 / 2;
			}
	} 
	printf("%lld\n",sum);
	return 0; 
}

Measured memory_bytes: 900
#include <bits/stdc++.h>
#define REP(i, a, n) for (long long i = (a); i < (long long)(n); ++i)
#define REPC(i, a, n) for (long long i = (a); i <= (long long)(n); ++i)
#define ALL(t) t.begin(), t.end()
#define RALL(t) t.rbegin(), t.rend()
#define MATINIT(type, row, col, init)                                          \
  vector<vector<type>>(row, vector<type>(col, init));
#define Yes(cond) cout << (cond ? "Yes" : "No") << endl;
#define YES(cond) cout << (cond ? "YES" : "NO") << endl;
using namespace std;
using LL = long long;
using ULL = unsigned long long;
template <class T> using VEC = std::vector<T>;
template <class T> using MAT = std::vector<std::vector<T>>;
void DUMP() { cerr << endl; }
template <class Head, class... Tail> void DUMP(Head &&head, Tail &&... tail) {
  cerr << head << ", ";
  DUMP(std::move(tail)...);
}
template <typename T> ostream &operator<<(ostream &os, vector<T> &vec) {
  os << "{";
  for (auto v : vec)
    os << v << ",";
  os << "}";
  return os;
}
template <typename T> ostream &operator<<(ostream &os, set<T> &s) {
  os << "{";
  for (auto p : s)
    os << p << ",";
  os << "}";
  return os;
}
template <typename T1, typename T2>
ostream &operator<<(ostream &os, map<T1, T2> &m) {
  os << "{";
  for (auto p : m)
    os << p << ",";
  os << "}";
  return os;
}
template <typename T1, typename T2>
ostream &operator<<(ostream &os, pair<T1, T2> p) {
  os << "[" << p.first << " " << p.second << "]";
  return os;
}

int main() {
  string S;
  cin>>S;
  Yes(S[2]==S[3] && S[4]==S[5]);

  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int cnt1[100005], cnt2[100005], a[100005];
int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	int n;
	cin>>n;
	for(int i=1;i<=n;i++){
		cin>>a[i];
	}
	memset(cnt1, 0, sizeof cnt1);
	memset(cnt2, 0, sizeof cnt2);
	for(int i=1;i<=n;i+=2){
		cnt1[a[i]]++;
	}
	for(int i=2;i<=n;i+=2){
		cnt2[a[i]]++;
	}
	int o1=0, o2=0, e1=0, e2=0;
	for(int i=1;i<=100000;i++){
		if(cnt1[i]>cnt1[o1]){
			o1=i;
		}
	}
	for(int i=1;i<=100000;i++){
		if(i==o1) continue; 
		if(cnt1[i]>cnt1[o2]){
			o2=i;
		}
	}
	for(int i=1;i<=100000;i++){
		if(cnt2[i]>cnt2[e1]){
			e1=i;
		}
	}
	for(int i=1;i<=100000;i++){
		if(i==e1) continue; 
		if(cnt2[i]>cnt2[e2]){
			e2=i;
		}
	}
	//cout<<o1<<" "<<e1<<endl;
	if(o1!=e1){
		cout<<n-cnt1[o1]-cnt2[e1];
	}
	else{
		int x=INT_MAX;
		if(o1!=e2) x=min(x, n-cnt1[o1]-cnt2[e2]);
		if(o2!=e1) x=min(x, n-cnt1[o2]-cnt2[e1]);
		cout<<x;
	}
}

Measured memory_bytes: 1408
#include <bits/stdc++.h>
using namespace std;
 
#define rep(i, n) for (int i = (int)(0); i < (int)(n); ++i)
#define reps(i, n) for (int i = (int)(1); i <= (int)(n); ++i)
#define rrep(i, n) for (int i = ((int)(n)-1); i >= 0; i--)
#define rreps(i, n) for (int i = ((int)(n)); i > 0; i--)
#define irep(i, m, n) for (int i = (int)(m); i < (int)(n); ++i)
#define ireps(i, m, n) for (int i = (int)(m); i <= (int)(n); ++i)
#define FOR(e, c) for (auto &e : c)
#define SORT(v, n) sort(v, v + n);
#define vsort(v) sort(v.begin(), v.end());
#define rvisort(v) sort(v.begin(), v.end(), greater<int>());
#define all(v) v.begin(), v.end()
#define mp(n, m) make_pair(n, m);
#define cout(d) cout<<d<<endl;
#define coutd(d) cout<<std::setprecision(10)<<d<<endl;
#define cinline(n) getline(cin,n);
 
using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vll = vector<ll>;
using vvll = vector<vll>;
using pii = pair<int, int>;
using vpii = vector<pii>;
using vs = vector<string>;
using vd = vector<double>;
using ul = unsigned long;
 
template<class T, class C> void chmax(T& a, C b){ a>b?:a=b; }
template<class T, class C> void chmin(T& a, C b){ a<b?:a=b; }
 
const int mod=1e9+7;
 
struct mint {
  ll x;
  mint(ll x=0):x(x%mod){}
  mint& operator+=(const mint a) {
    if ((x += a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator-=(const mint a) {
    if ((x += mod-a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator*=(const mint a) {
    (x *= a.x) %= mod;
    return *this;
  }
  mint operator+(const mint a) const {
    mint res(*this);
    return res+=a;
  }
  mint operator-(const mint a) const {
    mint res(*this);
    return res-=a;
  }
  mint operator*(const mint a) const {
    mint res(*this);
    return res*=a;
  }
};
 
mint c[4005][4005];
void init() {
  c[0][0] = 1;
  for (int i = 0; i <= 4000; i++) {
    for (int j = 0; j <= i; j++) {
      c[i+1][j] += c[i][j];
      c[i+1][j+1] += c[i][j];
    }
  }
}
mint comb(int n, int k) {
  return c[n][k];
}
 
bool IsPrime(int num)
{
    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;
}
 
map<ll, ll> primeFact(ll n) {
  map<ll, ll> res;
  for (ll i = 2; i * i <= n; i++) {
    while (n % i == 0) {
      res[i]++;
      n /= i;
    }
  }
  if (n != 1) res[n]++;
  return res;
}
 
void printv(vi& v){
  rep(i,v.size()) cout << v[i] << " ";
  cout << endl;
}
void printv(vll& v){
  rep(i,v.size()) cout << v[i] << " ";
  cout << endl;
}
int vtotal(vi& v){
  int total=0;
  rep(i,v.size()) total+=v[i];
  return total;
}
 
int main()
{
  //init(); // mint初期化
  cin.tie( 0 );
  ios::sync_with_stdio( false );
  int x,a,b;
  cin>>x>>a>>b;
  int ans=(x-a)%b;
  cout(ans);
  return 0;
}

Measured memory_bytes: 125568
#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,sum=0; cin>>n;
    vector<ll> a(n,0),p(100001,0);
    rep(i,n){
        cin>>a[i]; p[a[i]]++;
        sum+=a[i];
    }
    ll q; cin>>q;
    rep(i,q){
        ll b,c; cin>>b>>c;
        sum+=p[b]*(c-b);
        p[c]+=p[b]; p[b]=0;
        printf("%lld\n",sum);
    }
}

Measured memory_bytes: 4768
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10**6)

MAX = 2*10**5+100
fact = [0]*MAX
inv = [0]*MAX
finv = [0]*MAX
MOD = 10**9+7
 
def C_init():
    fact[0] = 1
    fact[1] = 1
    finv[0] = 1
    finv[1] = 1
    inv[1] = 1
    
    for i in range(2, MAX):
        fact[i] = fact[i-1]*i%MOD
        inv[i] = MOD-inv[MOD%i]*(MOD//i)%MOD
        finv[i] = finv[i-1]*inv[i]%MOD
 
def C(n, r):
    if n<r:
        return 0
    if n<0 or r<0:
        return 0
    return fact[n]*(finv[r]*finv[n-r]%MOD)%MOD
    
def dfs1(v, pv):
    nums = []
    res = 1
    
    for nv in G[v]:
        if nv==pv:
            continue
        
        num, chi_res = dfs1(nv, v)
        nums.append(num)
        res *= chi_res
        res %= MOD
    
    M = sum(nums)
    A1[v] = M+1
    
    for num in nums:
        res *= C(M, num)
        res %= MOD
        M -= num
    
    A2[v] = res
    
    return A1[v], A2[v]
    
def dfs2(v, pv):
    res = A3[pv]*pow(C(N-1, A1[v])*A2[v], MOD-2, MOD)%MOD
    M = N-1
    res *= C(M, N-A1[v])
    M -= N-A1[v]
    
    for nv in G[v]:
        if nv==pv:
            continue
        
        res *= A2[nv]
        res *= C(M, A1[nv])
        M -= A1[nv]
        res %= MOD
    
    A3[v] = res
    
    for nv in G[v]:
        if nv==pv:
            continue
        
        dfs2(nv, v)
    
N = int(input())
G = [[] for _ in range(N)]

for _ in range(N-1):
    a, b = map(int, input().split())
    G[a-1].append(b-1)
    G[b-1].append(a-1)

C_init()
A1 = [-1]*N
A2 = [-1]*N
A3 = [-1]*N
dfs1(0, -1)
A3[0] = A2[0]

for nv in G[0]:
    dfs2(nv, 0)

for A3i in A3:
    print(A3i)

Measured memory_bytes: 153196
#include<stdio.h>
int main()
{
	int a,b,c,d,l,s,k,r;
	scanf("%d%d%d%d%d",&l,&a,&b,&c,&d);
	k=a/c;
	s=b/d;
	if(a%c!=0){
		k++;
	}
	if(b%d!=0){
		s++;
	}
	if(k>s){
		r=l-k;
	}else{
		r=l-s;
	}
	printf("%d\n",r);
	return 0;
}

Measured memory_bytes: 2676
#include <iostream>
#include <vector>
#include <string>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <algorithm>	// require sort next_permutation count __gcd reverse etc.
#include <cstdlib>	// require abs exit atof atoi 
#include <cstdio>		// require scanf printf
#include <functional>
#include <numeric>	// require accumulate
#include <cmath>		// require fabs
#include <climits>
#include <limits>
#include <cfloat>
#include <iomanip>	// require setw
#include <sstream>	// require stringstream 
#include <cstring>	// require memset
#include <cctype>		// require tolower, toupper
#include <fstream>	// require freopen
#include <ctime>		// require srand
#define rep(i,n) for(int i=0;i<(n);i++)
#define ALL(A) A.begin(), A.end()

using namespace std;

typedef long long ll;
typedef pair<int, int> P;

int main()
{
	ios_base::sync_with_stdio(0);
	int N, K, M;
	while (cin >> N >> K >> M, N ){
		vector<int> s; s.clear();
		for (int i = 1; i <= N; i++ ){
			s.push_back (i );
		} // end for
		int p = M - 1;

		while (s.size() > 1 ){
			s.erase (s.begin() + p );
			p--;
			p = (p + K ) % s.size();
		} // end while
		cout << s[0] << endl;
	} // end while
		
	return 0;
}

Measured memory_bytes: 1328
#include <bits/stdc++.h>
using namespace std;
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;
}
#define DEBUG
#ifdef DEBUG
template <class T, class U>
ostream &operator<<(ostream &os, const pair<T, U> &p) {
    os << '(' << p.first << ',' << p.second << ')';
    return os;
}
template <class T> ostream &operator<<(ostream &os, const vector<T> &v) {
    os << '{';
    for(int i = 0; i < (int)v.size(); i++) {
        if(i) {
            os << ',';
        }
        os << v[i];
    }
    os << '}';
    return os;
}
void debugg() { cerr << endl; }
template <class T, class... Args>
void debugg(const T &x, const Args &... args) {
    cerr << " " << x;
    debugg(args...);
}
#define debug(...)                                                             \
    cerr << __LINE__ << " [" << #__VA_ARGS__ << "]:", debugg(__VA_ARGS__)
#define dump(x) cerr << __LINE__ << " " << #x << " = " << (x) << endl
#else
#define debug(...) (void(0))
#define dump(x) (void(0))
#endif

struct Setup {
    Setup() {
        cin.tie(0);
        ios::sync_with_stdio(false);
        cout << fixed << setprecision(15);
    }
} __Setup;

using ll = long long;
#define ALL(v) (v).begin(), (v).end()
#define RALL(v) (v).rbegin(), (v).rend()
const double EPS = 1e-7;
const int INF = 1 << 30;
const ll LLINF = 1LL << 60;
constexpr int MOD = 1000000007;
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};

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

int f(int n) {
    string s = to_string(n);
    int res = 0;
    for(int i = 0; i < s.size(); i++) {
        res += s[i] - '0';
    }
    return res;
}

int main() {
    int n;
    cin >> n;
    int ans = INF;
    for(int i = 1; i < n; i++) {
        chmin(ans, f(i) + f(n - i));
    }
    cout << ans << endl;
}

Measured memory_bytes: 3788
#include <iostream>
#include <algorithm>
#include <cmath>
#include <set>
#include <string>
#include <map>
#include <deque>
#include <vector>
#include <assert.h>
#include <cstdio>
#include <iomanip>
#include <stack>
#include <bitset>
#include <queue>
#include <stdio.h>


using namespace std;



#define mp make_pair
#define pb push_back
#define ll long long
#define fi first
#define sc second
#define y1 stupid_cmath



ll  n,k,d,x,y,r, cnt, a[1001001], p[1001001], F[1001000];
ll const INF = 100000001;
vector<ll> v1,v2;

int main(){
    //ios_base::sync_with_stdio(0);cout.tie(0);cin.tie(0);
    cin>>n>>k;
    if(n - k >= 0){
        cout<<n - k;
    }
    else
        cout<<0;
    return 0;
}
/*
5
1 3 7 12 32
40
*/


Measured memory_bytes: 256
#include <algorithm>
#include <iostream>
#include <vector>
#include <functional>
#include <string>
#include <cmath>  //sqrt 
#include <iomanip> //setprecision
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define ll long long
#define begin begin()
#define end end()

void _main(){
    int n;
    string s ;
    cin >> n >> s;
    if(s.size() <= n) {
        cout << s << endl;
        return;
    }else{
        cout << s.substr(0,n) << "..." << endl;
        return;
    }
}
int main() {
    _main();
    return 0;
}
    

Measured memory_bytes: 3100
#include <algorithm>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <iostream>
#include <map>
#include <queue>
#include <deque>
#include <string>
#include <stack>
#include <vector>
#include <set>
#include <tuple>
#include <utility>
#include <functional>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
typedef tuple<int,int,int> T;
const int INF = 1000000000;
const int MOD = 1000000007;
int main(){
	int n;
	cin >> n;
	map<char,int> mp;
	string s;
	cin >> s;
	for(int i = 0;i < n;i++){
		mp[s[i]]++;
	}

	ll ans = 1;
	for(auto p:mp){
		ans *= p.second + 1; 
		ans %= MOD;
	}

	cout << (ans-1+MOD) % MOD << endl;
}


Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
int main(){
	ios::sync_with_stdio(false);
	int x,y;
	cin>>x>>y;
	vector<pair<int,int> > vec1,vec2;
	pair<int,int> temp;
	//cout<<"adasdsadass\n";
	for(int i=0;i<x;i++){
		int a,b;
		cin>>a>>b;
		
		temp=make_pair(a,b);
		vec1.push_back(temp);
	}//cout<<"adasdsadass\n";
	for(int i=0;i<y;i++){
		int a,b;
		cin>>a>>b;
		temp=make_pair(a,b);
		vec2.push_back(temp);
	}
	//sort(vec2.begin(),vec2.end(),func);
	int index;
	//cout<<"adasdsadass\n";
	for(int i=0;i<x;i++){
		int ans=1000000000;
		for(int j=0;j<y;j++){
			int temp=abs(vec1[i].first-vec2[j].first)+abs(vec1[i].second-vec2[j].second);
			if(temp<ans){
				ans=temp;
				index=j;
				//cout<<"daadadas "<<ans<<endl;;
			}
		}
		cout<<index+1<<endl;
	}
	
	return 0;
}

Measured memory_bytes: 256
<?php
# スペース区切りの整数の入力
fscanf(STDIN, "%d %d", $b, $c);
# 出力

$str = strval($b) . strval($c);
$val = intval($str);

for ($i=1; $i <= 1000; $i++) {
    if($i * $i == $val){
        echo('Yes');
        break;
    } elseif($i == 1000){
        echo('No');
        break;
    }
}
?>

Measured memory_bytes: 16004
package main

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

var sc = bufio.NewScanner(os.Stdin)

func init() {
	sc.Split(bufio.ScanWords)
}

func nextInt() int {
	sc.Scan()
	i, e := strconv.Atoi(sc.Text())
	if e != nil {
		panic(e)
	}
	return i
}

func main() {
	var n int
	var s, t string
	fmt.Scanf("%d", &n)
	fmt.Scanf("%s %s", &s, &t)

	for i := 0; i< n; i++ {
		fmt.Printf("%s%s", string(s[i]), string(t[i]))
	}
}


Measured memory_bytes: 640
#include<iostream> 
#include<iomanip> 
#include<vector> 
#include<map> 
#include<set> 
#include<algorithm> 
#include<numeric> 
#include<limits> 
#include<bitset> 
#include<functional> 
#include<type_traits> 
#include<queue> 
#include<stack> 
#include<array> 
#include<random> 
#include<utility> 
#include<cstdlib> 
#include<ctime>
#define INT_MAX 2147483647
#define _LIBCPP_DEBUG 0
#define _GLIBCXX_DEBUG
#define rep(i,n) for (int i = 0; i < (n); ++i)	
using namespace std;



int max(int a,int b) {
	int max;
	if (a > b) max = a;
	else max = b;
	return max;
}
int min(int a, int b) {
	int min;
	if (a < b) min = a;
	else min = b;
	return min;
}


int main() {
	int k,s;
	int x = 0, y = 0, z = 0;

	cin >> k >> s;

	int count = 0;
	rep(i, k+1) {
		rep(j, k+1) {
			z = s - i - j;
			if (0 <= z && z <= k) {
				++count;
			}
		}
	}
	cout << count << endl;
	
}

Measured memory_bytes: 256
#include <algorithm>
#include <iostream>
#include <cstring>
#include <cstdio>
#include <vector>
#include <string>
#include <queue>
#include <stack>

int n, m, cnt;
int vis[100010];
std::vector <int> rela[100010];

void dfs(int x)
{
    vis[x] = 1;
    for (auto i : rela[x])
    {
        if (!vis[i])
            dfs(i);
    }
}

int main()
{
    std::ios::sync_with_stdio(0), std::cin.tie(0), std::cout.tie(0);
    std::cin >> n >> m;
    for (int i = 1; i <= m; ++i)
    {
        int x = 0, y = 0, z = 0;
        std::cin >> x >> y >> z;
        rela[x].push_back(y), rela[y].push_back(x);
    }
    int ans = 0;
    for (int i = 1; i <= n; ++i)
    {
        if (!vis[i])
        {
            if (rela[i].size())
                ++ans, dfs(i);
            else
                ++ans;
        }
    }
    std::cout << ans << std::endl;
    return 0;
}

Measured memory_bytes: 9216
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10**7)

N = int(input())
A = [list(map(lambda n: int(n)-1, input().split())) for i in range(N)]
cur = [0 for i in range(N)]
que = [i for i in range(N)]
ans = 0
while len(que) > 0:
    done = set()
    que2 = []
    for n in que:
        if n in done: continue
        pair = A[n][cur[n]]
        if pair in done: continue
        if n == A[pair][cur[pair]]:
            cur[n] += 1
            cur[pair] += 1
            done.add(n)
            done.add(pair)
            if cur[n] < N-1: que2.append(n)
            if cur[pair] < N-1: que2.append(pair)
    if len(done) > 0: ans += 1
    que = que2
ok = True
for i in range(N):
    if cur[i] < N-1: ok = False
if ok: print(ans)
else: print(-1)


Measured memory_bytes: 35060