akhauriyash/Code-Regression huggingface dataset:
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cfloat>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <memory>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <sstream>
#include <complex>
#include <stack>
#include <queue>
#include <iomanip>
#include <array>
#include <numeric>
#include <regex>
#include <bitset>
#include <deque>
#include <cassert>

using namespace std;
using ll = long long;

#define sz(x) ((int)(x).size())
#define all(x) (x).begin(), (x).end()
#define debug(x) cout << #x << ": " << x << endl;

const ll INF = 1e15;

ll f(ll b, ll n) {
	if (b < 2) return INF;
	if (n < b)return n;
	else return f(b, n / b) + n % b;
}

int main() {
	ll n, s;
	cin >> n >> s;

	if (n == s) {
		cout << n + 1 << endl;
		return 0;
	}

	ll ans = INF;

	for (ll i = 2; i*i <= n; i++) {
		if (f(i, n) == s)ans = min(ans, i);
	}

	for (ll i = 1; i*i <= n; i++) {
		ll b = (n - s) / i + 1;
		if (f(b, n) == s)ans = min(ans, b);
	}

	if (ans == INF)cout << -1 << endl;
	else cout << ans << endl;
	

	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0; i < n; ++i)
#define REPP(i, n) for(int i = 1; i <= n; ++i)
#define REPR(i, n) for(int i = n-1; i >= 0; --i)
#define FOR(i, m, n) for(int i = m; i < n; ++i)
#define ALL(v) v.begin(), v.end()
#define UNIQUE(v) v.erase(unique(v.begin(), v.end()), v.end());
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
const ll MOD = 1000000007;
const ll INF = 1000000000;

int main() {
    int n; cin >> n;
    map<string,ll> s;
    REP(i,n) {
        string str; cin >> str;
        sort(ALL(str));
        s[str] ++;
    }
    ll ans = 0;
    for(auto x : s) {
        if(x.second == 2) ans ++;
        else if(x.second == 3) ans += 3;
        else if(x.second>3) ans += x.second + x.second*(x.second-3)/2;
    }
    cout << ans << endl;
    return 0;
}

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

int main(){
    string S;
    cin >> S;
    map<char,int> mp;
    for(auto c : S) mp[c]++;
    bool ok = true;
    if(mp.size() == 2){
        for(auto c : S) if(mp[c] != 2) ok = false;
    }
    else ok = false;

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


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

using namespace std;

using ll = long long;

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

    int x, a, b;
    cin >> x >> a >> b;
    x -= a;
    x %= b;
    cout << x << endl;

    return 0;
}


Measured memory_bytes: 256
import java.util.ArrayList;
import java.util.Collections;
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
    	
		Scanner sc = new Scanner(System.in);
		// 整数の入力
		int r = sc.nextInt();
		// 整数の入力
		int D = sc.nextInt();
		// 整数の入力
		int x = sc.nextInt();
		
		int iend = 10;
//		int ans = 0;
		
		for(int i = 0;i<iend;i++){
			x = r * x - D; 
			System.out.println(x);
		}

   		sc.close();
        return ;

    }
    
}



Measured memory_bytes: 21716
#include<stdio.h>

int main(void){
	long long s=0,d,tate;
	int i;
	
	while(scanf("%lld",&d)==1){
		for(i=1;i<600;i++){
			tate=i*d;
			if(tate>600-d)
				break;
			tate*=tate;
			s+=tate*d;
		}
		printf("%lld\n",s);
		s=0;
	}
	
	return 0;
}

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

int D;
long long G;
vector<long long> p,c;

int main(){
  cin >> D >> G;
  p.resize(D); c.resize(D);
  for(int i = 0; i < D; ++i) cin >> p[i] >> c[i];
  
  long long res = 1 << 29;
  for(int bit = 0; bit < (1<<D); ++bit){
    long long sum = 0;
    long long num = 0;
    for(int i = 0; i < D; ++i){
      if(bit & (1<<i)) sum += c[i] + p[i] * 100 * (i+1), num += p[i];
    }
    if (sum >= G) res = min(res,num);
    else {
      for(int i = D-1; i >= 0; --i){
        if(bit & (1<<i)) continue;
        for(int j = 0; j < p[i]; ++j){
          if(sum >= G) break;
          sum += 100 * (i+1);
          ++num;
        }
      }
      res = min(res,num);
    }
  }
  cout << res << endl;
}

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

int main(void) {
	char a;
	scanf("%c",&a);
	if('a' <= a&&a <= 'z'){
		a = 'a';
	}else if('A' <= a&&a <= 'Z'){
		a = 'A';
	}
	printf("%c\n",a);
}


Measured memory_bytes: 1664
using System;
using System.Collections.Generic;
using System.Globalization;
using System.Linq;
using System.Text;
using System.Diagnostics;

namespace AtCoder
{
    class Program
    {
        private static string Read() { return Console.ReadLine(); }
        private static int ReadInt() { return int.Parse(Read()); }
        private static long ReadLong() { return long.Parse(Read()); }
        private static double ReadDouble() { return double.Parse(Read()); }
        private static int[] ReadInts() { return Array.ConvertAll(Read().Split(), int.Parse); }
        private static long[] ReadLongs() { return Array.ConvertAll(Read().Split(), long.Parse); }
        private static double[] ReadDoubles() { return Array.ConvertAll(Read().Split(), double.Parse); }

        private static CompareInfo ci = new System.Globalization.CultureInfo("ja-JP").CompareInfo;
        private static int Compare(string a, string b) { return ci.Compare(a, b, System.Globalization.CompareOptions.Ordinal); }

        static void Main(string[] args)
        {
            int[] V = ReadInts();
            int H = V[0], W = V[1];
            long h1 = (H + 1) / 2;
            long h2 = (H + 0) / 2;
            long w1 = (W + 1) / 2;
            long w2 = (W + 0) / 2;
            Console.WriteLine(Math.Min(H, W) > 1 ? h1 * w1 + h2 * w2 : 1);
        }
    }
}


Measured memory_bytes: 11220
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int MAX = 1e5 + 10;



int main() {
#ifdef ACM_LOCAL
    freopen("input.in", "r", stdin);
    freopen("output.out", "w", stdout);
#endif
    int a, b, c, k; scanf("%d%d%d%d", &a, &b, &c, &k);
    int ans = 0;
    int n = min(a, k);
    ans += 1 * n; a -= n, k -= n;
    n = min(b, k);
    ans += 0 * n; b -= n, k -= n;
    n = min(c, k);
    ans += -1 * n; c -= n, k -= n;
    printf("%d\n", ans);

    return 0;
}

Measured memory_bytes: 3828
#include <iostream>
#include <map>
#include <algorithm>
#include <string>
#include <vector> 
#include <numeric>
#include <cmath>


#define CHMAX(a,b) a = std::max(a,b)
#define CHMIN(a,b) a = std::min(a,b)
#define CHABS(a) a = std::abs(a) 
#define COUT(a) std::cout << a << std::endl
#define CERR(a) std::cerr << a << std::endl

using namespace std;
using lli = long long int;

lli mod197 = 1000000007LL;

// ax + by = gcd(a,b) 最大公約数
template< typename T >
T extgcd(T a, T b, T& x, T& y) {
	T d = a;
	if (b != 0) {
		d = extgcd(b, a % b, y, x);
		y -= (a / b) * x;
	}
	else {
		x = 1;
		y = 0;
	}
	return d;
}

map<lli, int> m;
map<lli, int> nm;

int main(void) {

	lli N;
	cin >> N;
	m[3] = 1;
	m[5] = 2;
	m[7] = 4;
	for (int i = 0; i < 8; i++) {
		for (auto i = m.begin(); i != m.end(); i++) {
			nm[(*i).first] = i->second;
			if ((*i).first * 10 + 3 <= N)
				nm[(*i).first * 10 + 3] = i->second | 1;
			if ((*i).first * 10 + 5 <= N)
				nm[(*i).first * 10 + 5] = i->second | 2;
			if ((*i).first * 10 + 7 <= N)
				nm[(*i).first * 10 + 7] = i->second | 4;
		}
		swap(m, nm);
	}

	lli count = 0;

	for (auto i = m.begin(); i != m.end(); i++) {
		if (i->second == 7)
			count++;
	}

	cout << count << endl;

	return 0;
}

Measured memory_bytes: 2688
import core.bitop, std.algorithm, std.ascii, std.bigint, std.conv,
    std.functional, std.math, std.numeric, std.range, std.stdio, std.string,
    std.random, std.typecons, std.container;

ulong MAX = 1_000_100, MOD = 1_000_000_007, INF = 1_000_000_000_000;
alias sread = () => readln.chomp();
alias lread(T = long) = () => readln.chomp.to!(T);
alias aryread(T = long) = () => readln.split.to!(T[]);
alias Pair = Tuple!(long, "l    ", long, "r");
alias PQueue(T, alias less = "a<b") = BinaryHeap!(Array!T, less);

void main()
{
    auto n = lread();
    writeln(n * (n - 1) / 2);
}

void scan(TList...)(ref TList Args)
{
    auto line = readln.split();
    foreach (i, T; TList)
    {
        T val = line[i].to!(T);
        Args[i] = val;
    }
}


Measured memory_bytes: 380
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<climits>
#include<iostream>
#include<sstream>
#include<utility>
#include<map>
#include<vector>
#include<queue>
#include<algorithm>
#include<set>
#include<stack>
using namespace std;
typedef long long ll;
typedef pair<int,int>P;

int main()
{
	int r=0;
	string s;
	cin>>s;
	for(int i=0;i<s.length();i++)
		s[i]=='+'?r++:r--;
	cout<<r<<endl;
}


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

using namespace std;

const int mod = 1e9 + 7, nmax = 1e5 + 1;
vector < int > G[nmax];

inline int Mul (int a, int b) {
  return (long long)a * b % mod;
}

pair < int , int > dfs (int nod, int parent) {
  int all_white = 1, is_black = 0;
  for (int child : G[nod])
    if (child != parent) {
      pair < int , int > p = dfs (child, nod);
      int aux = all_white;
      all_white = Mul (all_white, p.second);
      is_black = (Mul (aux, p.first) + Mul (is_black, p.first + p.second)) % mod;
    }
  return make_pair (all_white, (all_white + is_black) % mod);
}

int main () {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
  cout.tie(nullptr);
  int N;
  cin >> N;
  for (int i = 0; i < N - 1; ++i) {
    int x, y;
    cin >> x >> y;
    G[x].emplace_back(y);
    G[y].emplace_back(x);
  }
  pair < int , int > p = dfs (1, -1);
  int ans = (p.first + p.second) % mod;
  cout << ans;
}


Measured memory_bytes: 15936
#include<stdio.h>
#include<algorithm>
#include<vector>
using namespace std;
char str[150][13];
int dp[180000];
int pow3[13];
int m,n;
int calc(int a){
	if(~dp[a])return dp[a];
	vector<int>c;
	int key[13];
	for(int i=0;i<m;i++)key[i]=a%pow3[i+1]/pow3[i];
	for(int i=0;i<n;i++){
		bool ok=true;
		for(int j=0;j<m;j++){
			if(key[j]&&str[i][j]-'0'+1!=key[j])ok=false;
		}
		if(ok)c.push_back(i);
	}
	if(c.size()<=1)return dp[a]=0;
	int ret=99999999;
	for(int i=0;i<m;i++){
		if(key[i])continue;
		int L=calc(a+pow3[i]);
		int R=calc(a+pow3[i]*2);
		ret=min(ret,max(L,R)+1);
	}
	return dp[a]=ret;
}
int main(){
	int a,b;
	pow3[0]=1;
	for(int i=1;i<13;i++)pow3[i]=pow3[i-1]*3;
	while(scanf("%d%d",&a,&b),a){
		n=b;
		m=a;
		for(int i=0;i<b;i++)scanf("%s",str[i]);
		for(int i=0;i<pow3[a];i++)dp[i]=-1;
		printf("%d\n",calc(0));
	}
}

Measured memory_bytes: 1756
#126
from math import ceil, log
n, k = list(map(int, input().split(' ')))
rate = 0
for i in range(1,n+1):
    x = ceil(log(k/i, 2))
    if x < 0:
        x = 0
    rate += (1/n)*pow(0.5, x)
print(rate)

Measured memory_bytes: 3060
#include<cstdio>
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
 
using namespace std;
 
#define reps(i,f,n) for(int i=f;i<n;i++)
#define rep(i,n) reps(i,0,n)
#define int long long
 
typedef long long ll;
const int N = 111111, Q  = 11111, T = 44, MOD = 1e9+7;
 
int n,q;
int p[N];
 
int l[Q];
int r[Q];
 
 
int hlen[N];
int hsum[N];
 
int ruiseki[N][T];
 
void input(){
    cin>>n>>q;
    rep(i,n)cin>>p[i];
    rep(i,q)cin>>l[i]>>r[i];
}
 
void add(int& a, int b){
    a = (a+b)%MOD;
}
 
void solve_heiro(){
    rep(i,N)hlen[i] = -1;
 
    vector<int> tmp,tmp2;
    rep(i,n)tmp.push_back(i+1);
    tmp2 = tmp;
 
    rep(i,T){
        rep(j,n){
            tmp2[p[j]-1] = tmp[j];
        }
 
        tmp = tmp2;
 
        rep(j,n){
            if(hlen[j]==-1){
                hsum[j] += tmp[j];
                if(tmp[j] == j+1) hlen[j] = i+1;
            }
        }
 
    }
}
 
void solve_ruiseki(){
    reps(i,1,n+1){
        rep(j,T){
            if(i!=0)ruiseki[i][j] = ruiseki[i-1][j];
        }
        ruiseki[i][hlen[i-1]] += hsum[i-1];
    }
}
 
ll gcd(ll a, ll b){
    if(a<b)swap(a,b);
    while(a%b!=0){
        ll c = a%b;
        a = b;
        b = c;
    }
    return b;
}
 
ll lcm(ll a, ll b){
    ll t = gcd(a,b);
 
    return a/t * (b/t) * t;
}
 
int solve(){
    solve_heiro();
    solve_ruiseki();
 
    ll m = 1;
    reps(i,1,41){
        m = lcm(m,i);
    }
 
/*
    rep(j,n+1)printf("%3d ",j);puts("");
    rep(i,10){
        rep(j,n+1){
            printf("%3d ",ruiseki[j][i]);
        }puts("");
    }
*/
 
    rep(query,q){
 
        //rep(i,3)puts("");
 
        ll t  = 1;
        int sum = 0;
 
        int num[T] = {0};
        //printf("*** %d %d  \n" ,r[query]+1, l[query]);
        rep(j,T){
            num[j] = ruiseki[r[query]][j] - ruiseki[l[query]-1][j];
            //printf("**** j=%d  %d %d\n",j,ruiseki[r[query]+1][j], ruiseki[l[query]][j]);
        }
 
        rep(j,10){
            //printf("num %d  :  %d\n", j, num[j]);
        }
 
        rep(j,T){
            if(num[j] > 0) t = lcm(t, j);
        }
 
        //cout<<"lcm "<<t<<endl;
        rep(j,T){
            if(num[j] > 0) add(sum,  (int)((ll)num[j] * (t/j%MOD) % MOD) );
        }
        cout<<sum<<endl;
    }
 
    return 0;
}
 
 
signed main(){
    input();
    solve();
}

Measured memory_bytes: 40256
#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=a;i<=b;i++)
#define repr(i,a,b) for(int i=a;i>=b;i--)
#define ll long long int
using namespace std;
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0); cout.tie(0);
    #ifndef ONLINE_JUDGE
    freopen("input.txt","r",stdin);
    freopen("output.txt","w",stdout);
    #endif
    int s,w; cin>>s>>w;
    if(w>=s)
        cout<<"unsafe\n";
    else
        cout<<"safe\n";

    return 0;
}

Measured memory_bytes: 3648
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace aizu1
{
    public class Solution
    {
        public static void Main(string[] args)
        {
            int n = int.Parse(Console.ReadLine());
            int[,] A = new int[100, 2];
            int[,] M = new int[100, 100];

            for(int i = 0; i < n; i++)
            {
                var mat = Console.ReadLine().Split(' ');
                A[i, 0] = int.Parse(mat[0]);
                A[i, 1] = int.Parse(mat[1]);
            }

            Console.WriteLine(GetMinMul(A, M,0,n-1));
        }

        public static int GetMinMul(int[,] A, int[,] M, int left, int right)
        {
            if (left == right) return 0;
            if (M[left, right] != 0) return M[left, right];
            int min = -1;
            for(int i = left; i < right; i++)
            {
                if (min == -1)
                {
                    min = GetMinMul(A, M, left, i) + GetMinMul(A, M, i + 1, right) + A[left, 0] * A[i, 1] * A[right, 1];
                }
                else
                {
                    var tmp = GetMinMul(A, M, left, i) + GetMinMul(A, M, i + 1, right) + A[left, 0] * A[i, 1] * A[right, 1];
                    min = (min < tmp) ? min : tmp;
                }
            }
            M[left, right] = min;
            return min;
        }

    }
}

Measured memory_bytes: 9044
#include<bits/stdc++.h>
using namespace std;
int main(void){
  int N;
  cin >> N;
  vector<int> X(N), Y;
  for(int i = 0; i < N; i++) cin >> X[i];
  Y = X;
  sort(Y.rbegin(), Y.rend());
  int l = Y[N / 2 - 1];
  int r = Y[N / 2];
  for(int i = 0; i < N; i++){
    if(X[i] >= l) cout << r << endl;
    else cout << l << endl;
  }
  return 0;
}


Measured memory_bytes: 3712
#include<iostream>
using namespace std;
int main()
{
int a[1000],n,max=-10000000,min=10000000;
cin>>n;
for(int i=1;i<=n;i++){
cin>>a[i];
if(a[i]>max)
max=a[i];
if(a[i]<min)
min=a[i];}
cout<<max-min;
 
return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
#include<math.h>
#include<stack>
#include<queue>
#include<vector>
#include<algorithm>
#include<string>
#include<iostream>
#include<set>
#include<map>
#include<bitset>

using namespace std;
typedef long long ll;
#define i_7 1000000007
#define i_5 1000000005

ll mod(ll a){
    ll c=a%i_7;
    if(c>=0)return c;
    else return c+i_7;
}
typedef pair<int,int> i_i;
typedef pair<ll,ll> l_l;
/*#define inf 100000000/*10^8*/
#define rep(i,l,r) for(ll i=l;i<=r;i++)

////////////////////////////////////////
ll INF=10000000000;
ll min(ll a,ll b){
    if(a<b)return a;else return b;
}
ll max(ll a,ll b){
    if(a<b)return b;else return a;
}

int main(){
    int n;cin>>n;
    ll  a[n];rep(i,0,n-1)cin>>a[i];
    vector<ll> s;
    s.push_back(a[0]);
    rep(i,1,n)s.push_back(s[i-1]+a[i]);
    ll ans=INF;
    rep(mid,1,n-3){
        ll MIN,MAX;
        if(s[mid]<=s[n-1]/2){
            vector<ll>::iterator lb = lower_bound(s.begin(), s.end(), s[mid]/2);
            ll pos=lb-s.begin();
            ll q1=min(s[pos],s[mid]-s[pos]);
            if(pos>0){
                ll q2=min(s[pos-1],s[mid]-s[pos-1]);
                q1=max(q1,q2);
            }
            MIN=q1;
            MAX=s[mid]-q1;
            
            vector<ll>::iterator rb = lower_bound(s.begin(), s.end(), (s[n-1]+s[mid])/2);
            ll po=rb-s.begin();
            q1=max(s[po]-s[mid],s[n-1]-s[po]);
            if(po>mid){
                ll q2=max(s[po-1]-s[mid],s[n-1]-s[po-1]);
                q1=min(q1,q2);
            }
            MAX=max(MAX,q1);
            MIN=min(MIN,s[n-1]-s[mid]-q1);
            ans=min(ans,MAX-MIN);
        }else{
            vector<ll>::iterator lb = lower_bound(s.begin(), s.begin()+mid, s[mid]/2);
            ll pos=lb-s.begin();
            ll q1=max(s[pos],s[mid]-s[pos]);
            if(pos>0){
                ll q2=max(s[pos-1],s[mid]-s[pos-1]);
                q1=min(q1,q2);
            }
            MAX=q1;
            MIN=s[mid]-q1;
            vector<ll>::iterator rb = lower_bound(s.begin()+mid, s.end(), (s[n-1]-s[mid])/2+s[mid]);
            pos=rb-s.begin();
            q1=min(s[pos]-s[mid],s[n-1]-s[pos]);
            if(pos>mid){
                ll q2=min(s[pos-1]-s[mid],s[n-1]-s[pos-1]);
                q1=max(q1,q2);
            }
            MIN=min(MIN,q1);
            MAX=max(MAX,s[n-1]-s[mid]-q1);
            ans=min(ans,MAX-MIN);
            }
    }
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 3956
n = int(input())
a = list(map(int, input().split()))
d = {}
total = 0

for i in a:
    if i not in d:
        d[i] = 1
    else:
        total += d[i]
        d[i] += 1

ans = [total - (d[i] - 1) for i in a]
print("\n".join(map(str,ans)))

Measured memory_bytes: 39968
// clang-format off
#include <bits/stdc++.h>

#define mp make_pair
#define fst first
#define snd second
#define forn(i,n) for (int i = 0; i < int(n); i++)
#define forn1(i,n) for (int i = 1; i <= int(n); i++)
#define popcnt __builtin_popcount
#define ffs __builtin_ffs
#define ctz __builtin_ctz
#define clz __builtin_clz
#define all(a) (a).begin(), (a).end()
 
using namespace std;

using uint = unsigned int;
using ll = long long;
using ull = unsigned long long;
using pii = pair<int,int>;
using pli = pair<ll,int>;
using pil = pair<int,ll>;
using pll = pair<ll,ll>;
template <typename T> using vec = vector<T>;
using vi = vec<int>;
using vl = vec<ll>;
template <typename T> using que = queue<T>;
template <typename T> using deq = deque<T>;

template <typename T> T id(T b) {return b;};
template <typename T> void chmax(T &x, T y) {if (x < y) x = y;}
template <typename T> void chmin(T &x, T y) {if (x > y) x = y;}
template <typename S, typename K> bool contains(S &s, K k) { return s.find(k) != s.end(); }
void fastio() { ios_base::sync_with_stdio(false); cin.tie(nullptr); }
constexpr ll TEN(int n) { if (n == 0) return 1LL; else return 10LL*TEN(n-1); }
// clang-format on

const int MAX_N = 1 << 18;
int n;
int v[MAX_N + 1], w[MAX_N + 1];
ll dp[1 << 10][100001];
bool vis[1 << 10][100001];

ll rec(int i, int j) {
    if (i == 0) return 0;
    if (vis[i][j]) return dp[i][j];

    vis[i][j] = true;

    dp[i][j] = rec(i / 2, j);

    if (j >= w[i]) {
        chmax(dp[i][j], rec(i / 2, j - w[i]) + v[i]);
    }

    return dp[i][j];
}

int main() {
    fastio();

    cin >> n;
    forn1(i, n) {
        cin >> v[i] >> w[i];
    }

    forn(i, min(n + 1, 1 << 10)) {
        forn(j, 100001) {
            rec(i, j);
        }
    }

    int q;
    cin >> q;
    while (q--) {
        int x, l;
        cin >> x >> l;

        if (x < (1 << 10)) {
            cout << dp[x][l] << "\n";
            continue;
        }

        vi nodes;
        while (x >= (1 << 10)) {
            nodes.push_back(x);
            x /= 2;
        }

        ll ans = 0;
        int m = nodes.size();
        for (int b = 0; b < (1 << m); b++) {
            ll total_w = 0;
            ll total_v = 0;
            for (int i = 0; i < m; i++) {
                if ((b >> i) & 1) {
                    total_w += w[nodes[i]];
                    total_v += v[nodes[i]];
                }
            }

            if (total_w > l) {
                continue;
            }

            chmax(ans, total_v + dp[x][l - total_w]);
        }

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

    return 0;
}

Measured memory_bytes: 904760
#include<stdio.h>
#include<string.h>
int main() {
	int a, b, k;
	scanf("%d%d%d", &a, &b, &k);
	for (int i = k / 2; i > 0; i--) {
		if (a % 2 == 1) {
			b += a / 2;
			a -= a / 2;
			a--;
		}
		else {
			b += a / 2;
			a -= a / 2;
		}
		if (b % 2 == 1) {
			a += b / 2;
			b -= b / 2;
			b--;
		}
		else {
			a += b / 2;
			b -= b / 2;
		}
	}
	if (k % 2 == 1) {
		if (a % 2 == 1) {
			b += a / 2;
			a -= a / 2;
			a--;
		}
		else {
			b += a / 2;
			a -= a / 2;
		}
	}
	printf("%d %d", a, b);
}

Measured memory_bytes: 128
#include <iostream>
#include <algorithm>
#include <cmath>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <deque>
#include <stack>
#include <stdio.h>
#include <iomanip>
using namespace std;

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

#define pb push_back
#define F first
#define S second
#define all(x) (x).begin(), (x).end()

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

bool ispr(ll x) {
	for (ll i = 2; i * i <= x; i++)
		if (x % i == 0) return false;
	return true;
}

ll a, b, ans;
vector<ll> d;

int main()
{
	cin >> a >> b;
	ll g = gcd(a, b);
	for (ll i = 1; i * i < g; i++)
		if (g % i == 0) {
			d.pb(i);
			d.pb(g / i);
		}
	ll sq = sqrt(g);
	if (sq * sq == g) d.pb(sq);
	for (ll i: d) 
		if (ispr(i)) ans++;
	cout << ans << '\n';
}


Measured memory_bytes: 384
//#include <GOD>
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define pb push_back
#define len length	
#define FAST_IO ios_base::sync_with_stdio(false); cin.tie(NULL);
#define freo freopen("output.txt","w",stdout)
#define frei freopen("input.txt","r",stdin)

const ll mod=1e9+7;
const ll maxn=1e2+10,maxa=1e3+10;

ll x;

int main(){
	FAST_IO;
	cin>>x;
	if(x){
		cout<<0<<endl;
	}else{
		cout<<1<<endl;
	}
}


Measured memory_bytes: 3600
#include <bits/stdc++.h>
using namespace std;
using Graph = vector<vector<int>>; // グラフ型
typedef long long ll;
#define _GLIBCXX_DEBUG
#define rep(i, n) for(int i = 0; i < (n); ++i)




int main() {
  string S, T;
  cin >> S >> T;
  //vector<ll> a(N);
  //vector<vector<int>> data(3, vector<int>(4));
  ll t_length = T.size();
  ll min_dif = 1001;
  
  for(ll i=0; i <= S.size() - t_length; i++){
    string temp = S.substr(i, t_length);
    ll dif = 0;

    //cout << temp.size() <<endl;
    
    for(ll j=0; j< t_length; j++){
      if(temp.at(j) != T.at(j)) dif++;
    }

    if(dif < min_dif){
      min_dif = dif;
    }

  }
  
  cout << min_dif << endl;

  return 0;
}


Measured memory_bytes: 3624
import heapq

N, M = [int(x) for x in input().split()]
data = []
for _ in range(N):
  A, B = [int(x) for x in input().split()]
  data.append((A, -B))
data = sorted(data)
heap = []
next_index = 0
ans = 0
for m in range(M):
  # print(m)
  while next_index < N and data[next_index][0] <= m+1:
    # print(data[next_index])
    heapq.heappush(heap, data[next_index][1])
    next_index += 1
  # print(heap)
  if heap:
    job = heapq.heappop(heap)
    # print(m, job)
    ans -= job
print(ans)

Measured memory_bytes: 17876
#include <iostream>
#include <string>
#include <vector>
#include <queue>
#include <stack>
#include <map>
#include <algorithm>
#include <sstream>
#include <cmath>
#include <set>
#include <iomanip>
#include <deque>
#include <stdio.h>
using namespace std;

#define REP(i,n) for(int (i)=0;(i)<(int)(n);(i)++)
#define RREP(i,n) for(int (i)=(int)(n)-1;i>=0;i--)
#define iREP(i,Itr) for(auto (i)=(Itr).begin();(i)!=(Itr).end();(i)++)
#define REMOVE(Itr,n) (Itr).erase(remove((Itr).begin(),(Itr).end(),n),(Itr).end())
#define PB_VEC(Itr1,Itr2) (Itr1).insert((Itr1).end(),(Itr2).begin(),(Itr2).end())
#define UNIQUE(Itr) sort((Itr).begin(),(Itr).end()); (Itr).erase(unique((Itr).begin(),(Itr).end()),(Itr).end())
#define LBOUND(Itr,val) lower_bound((Itr).begin(),(Itr).end(),(val))
#define UBOUND(Itr,val) upper_bound((Itr).begin(),(Itr).end(),(val))
typedef long long ll;

int main(){
    
    ll N,A,B;
    cin>>N>>A>>B;
    
    ll ans=0;
    REP(i,N){
        ll t; cin>>t;
        if(t>=A&&t<B)ans++;
    }
    
    cout<<N-ans<<endl;
    
    return 0;
}

Measured memory_bytes: 256
n=int(input())
lists=[[ [] for j in range(10)]for i in range(10)]
for i in range(1,n+1):
    a=str(i)
    lists[int(str(a[0]))][int(str(a[-1]))].append(i)
c=0
for i in range(1,10):
    for j in range(1,10):
        c+=len(lists[i][j])*len(lists[j][i])
print(c)        


Measured memory_bytes: 44380
#include <bits/stdc++.h>
#include <time.h>
using namespace std;
typedef long long ll;
typedef long double ld;
const ll MOD = 1e9 + 7/*998244353*/;
const ll INF = 1LL << 60;
ll mod_pow(ll, ll, ll); ll mod_fact(ll, ll); ll mod_inv(ll, ll); ll gcd(ll, ll); ll lcm(ll, ll);
//
int main(){
    ll n;
    cin >> n;
    vector<ll> a(n + 1);
    for(int i = 0; i < n; i++) cin >> a[i];
    ll total = 1000, cap = 0;
    int cur = 0;
    for(int i = 0; i < n - 1; i++){
        if(cur == 0){
            if(a[i] == a[i + 1]) cur = 0;
            if(a[i] < a[i + 1]) {cap = total / a[i]; total %= a[i]; cur = 1;}
            if(a[i] > a[i + 1]) cur = -1;
        }else if(cur == 1){
            if(a[i] > a[i + 1]) {total += cap * a[i]; cap = 0; cur = -1;}
        }else{
            if(a[i] < a[i + 1]) {cap = total / a[i]; total %= a[i]; cur = 1;}
        }
    }
    total += cap * a[n - 1];
    cout << total;
}

Measured memory_bytes: 3584
#include <bits/stdc++.h>
#define repr(i,from,to) for(int (i)=(from);(i)<(to);(i)++)
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
const bool debug=true;
// const bool debug=false;
#define DEBUG if(debug==true)
#define vprint(x) for(auto a:(x)) cout << x << endl;
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
const ll MOD = 1000000007;
template<class T> inline bool chmin(T& a, T b) {
    if (a > b) { a = b; return true;}
    return false;
}
template<class T> inline bool chmax(T& a, T b) {
    if (a < b) { a = b; return true;}
    return false;
}
int main(void) {
    cin.tie(0);
    ios::sync_with_stdio(false);
    double a,b,x;cin>>a>>b>>x;
    double height,a_tan;
    if (x <= a*a*b/2) {
        height = 2*x / (a*b);
        a_tan = atan(b/height) * 360;
    }else {
        height = (a*a*b-x) * 2.0 / (a*a);
        a_tan = atan(height/a) * 360;
    }
    printf("%.10lf\n", a_tan / (2 * M_PI));
    return 0;
}


Measured memory_bytes: 256
import sys
readline = sys.stdin.readline

N,M = map(int,readline().split())
A = sorted(list(map(int,readline().split())))

ok = -1
ng = (10 ** 5) * 2 + 1

# x以上の握手ペアをM回以上作れるか、でxの最大値を二分探索
import bisect
def isOk(x):
  cnt = 0
  for left in A:
    right = x - left
    ind = bisect.bisect_left(A, right)
    cnt += N - ind
  return cnt >= M
  
while abs(ng - ok) > 1:
  mid = abs(ng + ok) // 2
  if isOk(mid):
    ok = mid
  else:
    ng = mid

# okが基準とすべきxの値である

sumA = [0] + A.copy()
for i in range(1, len(sumA)):
  sumA[i] += sumA[i - 1]

ans = 0
num = 0
for left in A:
  right = ok - left
  ind = bisect.bisect_left(A, right)
  num += N - ind
  ans += (N - ind) * left + sumA[-1] - sumA[ind]
  
if num > M:
  ans -= (num - M) * ok
  
print(ans)  

Measured memory_bytes: 20704
#include <iostream>
#include <vector>
#include <algorithm>
#include <iterator>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <string>
#include <cmath>
using namespace std;
#define MOD 1000000007
#define INF 1<<30
#define LINF (ll)1<<62
#define rep(i,n) for(ll i=0; i<(n); i++)
#define REP(i,a,b) for(ll i=(a); i<(b); i++)
#define all(x) (x).begin(),(x).end()
using namespace std;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef pair<ll, ll> P;
typedef vector<pair<ll, ll>> vpl;


int main(){
    vector<string> s(3);
    rep(i,3) cin >> s[i];
    ll index[3]={0};
    char key='a';
    while(1){
        if(key == 'a'){
            if(index[0] == s[0].size()){
                cout << "A" << endl;
                break;
            }
            key = s[0][index[0]];
            index[0]++;
        }else if(key == 'b'){
            if(index[1] == s[1].size()){
                cout << "B" << endl;
                break;
            }
            key = s[1][index[1]];
            index[1]++;
        }else{
            if(index[2] == s[2].size()){
                cout << "C" << endl;
                break;
            }
            key = s[2][index[2]];
            index[2]++;
        }
    }
}

Measured memory_bytes: 256
import java.io.IOException;
import java.util.Arrays;
import java.util.List;
import java.util.Scanner;

public class Main {

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

		Scanner scan = new Scanner(System.in);

		long h, w;
		h = scan.nextLong();
		w = scan.nextLong();

		long firstRowCount;//はじめの行で行ける数

		long ans;

		if (w == 1) {
			System.out.println(1);
			return;
		}

		//一行で行ける数
		//偶数は半分、奇数は半分+1
		if (w % 2 == 0) {//偶数の時
			firstRowCount = w / 2;
		} else {
			firstRowCount = w / 2 + 1;
		}

		if (h == 1) {
			System.out.println(1);
			return;
		}

		ans = firstRowCount;

		//二行目以降で行ける範囲は列数-一行目で行ける数
		for (int i = 2; i <= h; i++) {
			if (i % 2 == 0) {
				ans += w - firstRowCount;
			} else {
				ans += firstRowCount;
			}

		}

		System.out.println(ans);
	}

	/**
	 * 余りを求める。
	 * @param a
	 * @param b
	 * @return 余り。余りがマイナスの時はプラスで返す。
	 */
	public static long myMod(long a, long b) {
		long ret = 0;

		ret = a % b;

		if (ret < 0) {
			ret += b;
		}

		return ret;
	}

	/**
	 * 乗数を求める ※mod対応
	 * @param kisu 基数
	 * @param josu 乗数
	 * @param primeNumMod_0 法 mod値 使わない場合は「0」
	 * @return
	 */
	public static long myPowWithMod(long kisu, long josu, long primeNumMod_0) {

		long ans = 1;

		//乗数が0の場合→1
		if (josu == 0)
			return 1;

		if (primeNumMod_0 == 0) {
			//modを使わないとき

			while (josu > 0) {

				if (josu % 2 == 0) {
					//累乗が偶数の時

					kisu *= kisu;
					josu = josu / 2;
				} else {
					//累乗が奇数の時
					ans *= kisu;
					josu--;
				}
			}

			return ans;

		} else {
			//modを使うとき

			//初めに桁を落とす
			kisu = myMod(kisu, primeNumMod_0);

			while (josu > 0) {

				if (josu % 2 == 0) {
					//累乗が偶数の時

					kisu *= myMod(kisu, primeNumMod_0);
					josu = josu / 2;

				} else {
					//累乗が奇数の時
					ans *= myMod(kisu, primeNumMod_0);
					josu--;

				}
			}

			return myMod(ans, primeNumMod_0);

		}

	}

}


Measured memory_bytes: 21844
#include <vector>
#include <iostream>
#include <math.h>
#include <algorithm>
 
using namespace std;
#define int long long
#define all(x) x.begin(),x.end()
#define max3(a,b,c) max(a,max(b,c))
#define min3(a,b,c) min(a,min(b,c))
#define vi vector<int>
#define vstr vector<string>
#define vbool vector<bool>
#define vvi vector<vector<int> >
#define mii map<int,int>
#define pb push_back
#define pii pair<int,int>
#define vpair vector<pii > 
#define mkp make_pair
#define scan(a,n) for(int i =0 ; i<n ; i++) cin>>a[i]
#define print(a,n) for(int i = 0 ; i < n ; i++) {cout<<a[i]<<' ';}cout<<'\n'
#define mem(a,v) memset(a,v,sizeof(a))
#define loop(i,a,b) for (int i = a; i < b; i++)
#define loope(i,a,b) for (int i = a; i <= b; i++)
#define FastIO ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define PRECISION std::cout.unsetf ( std::ios::fixed );std::cout.precision(9)
#define PI 3.14159265
#define S second
#define F first
#define CHECK cout<<"CHEDEDWB"<<endl
#define br '\n'
int mod = 1e9+7;
int inf = 1e18;
int m_inf = INT_MIN;


int32_t main()
{
	FastIO; PRECISION;
	int n;
	cin>>n;
	vi a(n),b(n);
	loop(i,0,n)
		cin>>a[i]>>b[i];
	sort(all(a));
	sort(all(b));
	int x,y;
	if(n%2==0)
	{
		x = a[n/2]+a[n/2-1];
		y = b[n/2]+b[n/2-1];
	}
	else
	{
		x = a[n/2];
		y = b[n/2];
	}
	cout<<y-x+1<<endl;
	return 0;
} 

Measured memory_bytes: 6024
typedef long long ll;
#include<bits/stdc++.h>
using namespace std;
ll maxl(ll a, ll b){ return ((a<b)?b:a);}
ll minl(ll a, ll b){ return ((a>b)?b:a);}

int main(){
    ios::sync_with_stdio(false);
    cin.tie(NULL);
    int n;
    cin >> n;
    int arr[n];
    for (int i=0;i<n;i++){
        cin >> arr[i];
    }
    vector<int> dp(n,0);
    dp[1] = abs(arr[1]-arr[0]);
    for (int i=2;i<n;i++){
        dp[i] = min(abs(arr[i]-arr[i-1])+dp[i-1],abs(arr[i]-arr[i-2])+dp[i-2]);
    }
    cout << dp[n-1] << endl;
}


Measured memory_bytes: 4008
#include <bits/stdc++.h>
typedef long long LL;
#define FOR(i,a,b) for(LL i=(a);i<(b);++i)
#define REP(i,n) FOR(i,0,n)

using namespace std;
LL p = 1000000007ll;

int main(void)
{
  LL n;
  cin >> n;
  vector<vector<LL>> nei(n+1);
  vector<LL> c(n),v(n+1),vn(n+1);
  vector<pair<LL,LL>> e;
  REP(i,n-1) {
    LL a,b;
    cin >> a >> b;
    nei[a].push_back(b);
    nei[b].push_back(a);
    ++vn[a];
    ++vn[b];
    e.emplace_back(a,b);
  }
  for(LL &x:c) cin >> x;
  sort(c.begin(),c.end());
  auto ite = c.begin();
  queue<LL> q;
  REP(i,n+1) if(vn[i]==1) q.push(i);
  while(!q.empty()) {
    LL x = q.front();
    q.pop();
    if(v[x]) continue;
    v[x] = *ite;
    ++ite;
    for(LL ne:nei[x]){
      if(--vn[ne] == 1) q.push(ne);
    }
  }
  LL answer = 0;
  for(auto p:e) answer += min(v[p.first],v[p.second]);
  cout << answer << endl;
  REP(i,n) {
    if(i) cout << " ";
    cout << v[i+1];
  }
  cout << endl;

  return 0;
}


Measured memory_bytes: 1408
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair< ll, ll > Pi;
#define rep(i,n) for(int i=0;i<(n);i++)
#define rep2(i,n) for(int i=1;i<=(n);i++)
#define rep3(i,i0,n) for(int i=i0;i<(n);i++)
#define pb push_back
#define mod 1000000007
const ll INF = 1LL << 60;
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; }
ll gcd(ll a, ll b) {return b?gcd(b,a%b):a;}
ll lcm(ll a, ll b) {return a/gcd(a,b)*b;}
#define all(x) x.begin(), x.end()
#define mp make_pair
bool compare(tuple<string,ll,ll> a, tuple<string,ll,ll> b) {
    if(get<0>(a) != get<0>(b)){
        return get<0>(a) < get<0>(b);
        
    }else{
        return get<1>(a) > get<1>(b);
    }
}


bool In_map(ll y,ll x,ll h,ll w){
    if(y<0 || x<0 || y>=h || x>=w){
        return 0;
    }else{
        return 1;
    }
}
const vector<ll> dx{1,0,-1,0};
const vector<ll> dy{0,1,0,-1};


int main() {
    ll N;
    cin >>N;
    vector<tuple<string,ll,ll>>SP(N);

    rep(i,N){
        string s;
        ll p;
        cin>>s>>p;
        SP[i]=make_tuple(s,p,i+1);
    }
    sort(all(SP),compare);

    rep(i,N){
        cout<<get<2>(SP[i])<<endl;
    }



    return 0;
    

}

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

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<ll, ll> P;

#define EACH(i,a) for (auto& i : a)
#define FOR(i,a,b) for (ll i=(a);i<(b);i++)
#define RFOR(i,a,b) for (ll i=(b)-1;i>=(a);i--)
#define REP(i,n) for (ll i=0;i<(n);i++)
#define RREP(i,n) for (ll i=(n)-1;i>=0;i--)
#define debug(x) cout<<#x<<": "<<x<<endl
#define pb push_back
#define ALL(a) (a).begin(),(a).end()

const ll linf = 1e18;
const int inf = 1e9;
const double eps = 1e-12;
const double pi = acos(-1);

template<typename T>
istream& operator>>(istream& is, vector<T>& vec) {
    EACH(x,vec) is >> x;
    return is;
}
template<typename T>
ostream& operator<<(ostream& os, vector<T>& vec) {
    REP(i,vec.size()) {
        if (i) os << " ";
        os << vec[i];
    }
    return os;
}
template<typename T>
ostream& operator<<(ostream& os, vector< vector<T> >& vec) {
    REP(i,vec.size()) {
        if (i) os << endl;
        os << vec[i];
    }
    return os;
}

ll f(ll a, ll b) {
    // cout << a << " " << b << endl;
    if (a > b) {
        ll t = (a-1)/b;
        return 2*b*t + f(a-t*b, b);
    }
    if (a < b) {
        return a + b + f(b-a, a);
    }
    if (a == b) return a + b;
}
int main() {
    std::ios::sync_with_stdio(false);
    std::cin.tie(0);
    ll L, X; cin >> L >> X;
    ll ans = X + f(X, L-X);
    cout << ans << endl;
}


Measured memory_bytes: 256
#include<iostream>
#include<iomanip>
#include<cmath>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<algorithm>
#include<set>
#include<map>
#include<queue>
#include<stack>
#include<vector>
#include<cctype>
using namespace std;
int n,m;
signed main()
{
	scanf("%d%d",&n,&m);
	printf("%d",((int)((n+m+1)>>1)));
	return putchar(10),0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ri register int
using namespace std;
typedef long long ll;
#define pb push_back
const int rlen=1<<18|1;
char buf[rlen],*ib=buf,*ob=buf;
#define gc() (((ib==ob)&&(ob=(ib=buf)+fread(buf,1,rlen,stdin)),ib==ob)?-1:*ib++)
inline int read() {
  int ans=0;
  bool f=1;
  char ch=gc();
  while(!isdigit(ch)) f^=ch=='-',ch=gc();
  while(isdigit(ch)) ans=((ans<<2)+ans<<1)+(ch^48),ch=gc();
  return f?ans:-ans;
}
const int N=3e5+5;
char s[55];
int n;
int main() {
  #ifdef ldxcaicai
  freopen("lx.in","r",stdin);
  #endif
  cin>>n;
  scanf("%s",s+1);
  int ct=0;
  for(ri i=1;i<=n-2;++i) if(s[i]=='A'&&s[i+1]=='B'&&s[i+2]=='C') ++ct;
  cout<<ct;
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define _GLIBCXX_DEBUG
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define Sort(a) sort(a.begin(), a.end())
typedef long long int ll;
typedef vector<int> vi;

int main(){
    ll x;
    cin >> x;
    ll tmp = (x%500), sum = 0;
    sum += (x/500) * 1000;
    sum +=  tmp/5 * 5;
    cout << sum << endl;
    return 0;
}

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

typedef struct{
  long long a;
  long long b;
}setab;

long cmp (const void *p,const void *q){
  return ((setab*)p)->a - ((setab*)q)->a;
}

int main(){
  setab abset[100000] = {};
  long long n = 0;
  long long m = 0;
  long long hon = 0;
  long long sum = 0;
  long long i = 0;
  scanf("%lld %lld",&n,&m);
  for(i=0;i<n;i++){
    scanf("%lld %lld",&abset[i].a,&abset[i].b);
  }
  qsort(abset,n,sizeof(setab),cmp);
  for(i=0;i<n;i++){
    if(m > hon + abset[i].b){
      sum += abset[i].a * abset[i].b;
      hon += abset[i].b;
    }else{
      sum += abset[i].a*(m-hon);
      break;
    }
  }
  printf("%lld",sum);
  return 0;
}
      

Measured memory_bytes: 3324
from collections import defaultdict,deque

N,K = map(int,input().split())
A = list(map(int,input().split()))

loop = N
pos = 0
oto = defaultdict(int)
ind = 0
tej = deque([])
for i in range(N):
    pos = A[pos] - 1
    tej.append(pos+1)
    if oto[pos] == 1:
        ind = tej.index(pos+1)
        loop = i - ind 
        break
    oto[pos] = 1
K -= 1
##print("loop",loop,"ind",ind)
##print(tej)
if K <= ind:
    print(tej[K])
else:
    print(tej[(K-ind)%loop+ind])

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

int main()
{
  int N;
  long long Y;
  cin >> N >> Y;
  
  int num_10000 = -1;
  int num_5000 = -1;
  int num_1000 = -1;
  
  for (int x = 0; x <= N; x++)
  {
    for (int y = 0; x + y <= N; y++)
    {
      int z = N - x - y;
      
      if (Y == 10000 * x + 5000 * y + 1000 * z)
      {
        num_10000 = x;
        num_5000 = y;
        num_1000 = z;
      }
    }
  }
  
  cout << num_10000 << " " << num_5000 << " " << num_1000 << endl;

  return 0;
}


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

using namespace std;
using ll = long long;
using v1 = vector<int>;
using vl = vector<long long>;
using v2 = vector<vector<int>>;
using v3 = vector<vector<char>>;

int main(){
    int n;
    cin >> n;
    vl L(n);
    rep(i, n){
        cin >> L[i];
    }
    int ans = 0;
    for(int i = 0; i< n; i++){
        for(int j = i; j < n; j++){
            for(int k = j; k<n; k++){
                if(L[i] == L[j] || L[j] == L[k]||L[i] == L[k]) continue;
                if(L[i]+L[j] <= L[k]) continue;
                if(L[k]+L[j] <= L[i]) continue;
                if(L[i]+L[k] <= L[j]) continue;
                ans++;
            }
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 3620
#include <iostream>
#include <vector>
#include <cstring>
#include <algorithm> // sort

#define REP(i, n) for (long long i = 0; i < (n); i++) 
typedef long long ll;
static const ll MOD = 1000000007;
static const ll INF = 1000000000000000000LL;

using namespace std;

//arc073 Sentou
//t[i+1] - t[i] > T ならT秒足す
//t[i+1] - t[i] <= Tなら (t[i+1] - t[i])秒足す
int main(){
  ll N,T,res;
  cin >> N >> T;

  ll t[N];

  REP(i,N)
  {
    cin >> t[i]; 
  }

  res = 0;

  for(ll i = 0; i < N-1; ++i)
  {
    if(t[i+1]-t[i] > T)
    {
      res += T;
    }
    else
    {
      res += t[i+1] - t[i];
    }
  }
  //t[N-1]
  res += T;

  cout << res << endl;


  return 0;
}


Measured memory_bytes: 1792
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main(){
	int n,x; cin>>n>>x;
	int arr[n], ans=1;
	cin>>arr[0];
	for(int i=1; i<n; i++){
		cin>>arr[i];
		arr[i]+=arr[i-1];
	}
	for (int i = 0; i<n; i++){
		if(arr[i]<=x)ans++;
	}
	cout<<ans<<endl;
}


Measured memory_bytes: 3636
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.*;

public class Main{

	public static void main(String[] args) throws IOException {
		MyScanner sc = new MyScanner(System.in);
		int n=sc.nextInt();
		int k=sc.nextInt();
		long[] a = new long[n+1];
		long[] b = new long[n+1];
		for(int i=1; i<=n; i++) a[i] = sc.nextLong();
		for(int i=1; i<=n; i++) {
			b[i]=b[i-1]+Math.max(a[i], 0);
			a[i]=a[i-1]+a[i];
		}
		long ans=0;
		for(int i=1; i+k-1<=n; i++) {
			ans=Math.max(ans, Math.max(a[i+k-1]-a[i-1],0)+b[i-1]+b[n]-b[i+k-1]);
		}
		System.out.println(ans);
		
 	}
	
	static void printArray(int[] a) {
		int n=a.length;
		for(int i=0; i<n; i++) {
			if(i==0) System.out.print(a[i]);
			else System.out.print(" "+a[i]);
		}
		System.out.println();
	}

	static class MyScanner
	{
		BufferedReader br;
		StringTokenizer st;
		public MyScanner(InputStream s) 
		{
			br=new BufferedReader(new InputStreamReader(s));
		}
		public String nextLine() throws IOException
		{
			return br.readLine();
		}
		public String next() throws IOException
		{
			while(st==null || !st.hasMoreTokens())
				st=new StringTokenizer(br.readLine());
			return st.nextToken();
		}
		public int nextInt() throws IOException
		{
			return Integer.parseInt(next());
			
		}
		public double nextDouble() throws IOException
		{
			return Double.parseDouble(next());
		}
		public boolean ready() throws IOException
		{
			return br.ready();
		}
		public long nextLong() throws IOException
		{
			return Long.parseLong(next());
		}
	}
}


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

#undef _P
#define _P(...) (void)printf(__VA_ARGS__)
#define FOR(x,to) for(x=0;x<(to);x++)
#define FORR(x,arr) for(auto& x:arr)
#define ITR(x,c) for(__typeof(c.begin()) x=c.begin();x!=c.end();x++)
#define ALL(a) (a.begin()),(a.end())
#define ZERO(a) memset(a,0,sizeof(a))
#define MINUS(a) memset(a,0xff,sizeof(a))
//-------------------------------------------------------

int X,Y,A,B,C;
vector<pair<int,int>> E;
void solve() {
	int i,j,k,l,r,x,y; string s;
	
	cin>>X>>Y>>A>>B>>C;
	FOR(i,A) cin>>x, E.push_back({x,0});
	FOR(i,B) cin>>x, E.push_back({x,1});
	FOR(i,C) cin>>x, E.push_back({x,2});
	sort(ALL(E));
	
	ll ret=0;
	FORR(e,E) {
		x=e.second;
		y=e.first;
		if(x==0) {
			if(A+C==X || (B+C==Y&&A==X) || A+B+C==X+Y) {
				X--;
				ret+=y;
			}
			A--;
		}
		else if(x==1) {
			if((A+C==X&&B==Y) || B+C==Y || A+B+C==X+Y) {
				Y--;
				ret+=y;
			}
			B--;
		}
		else {
			if(A+C==X || B+C==Y || A+B+C==X+Y) {
				if(A<X) {
					X--;
				}
				else if(Y) {
					Y--;
				}
				ret+=y;
			}
			C--;
		}
	}
	cout<<ret<<endl;
}


int main(int argc,char** argv){
	string s;int i;
	if(argc==1) ios::sync_with_stdio(false), cin.tie(0);
	FOR(i,argc-1) s+=argv[i+1],s+='\n'; FOR(i,s.size()) ungetc(s[s.size()-1-i],stdin);
	cout.tie(0); solve(); return 0;
}


Measured memory_bytes: 6512
#include <bits/stdc++.h>
using namespace std;
#define __ <<" "<<
#define ___ <<" "
#define bash push_back
#define ALL(x) x.begin(),x.end()
//#define int long long

struct IoSetup {
    IoSetup() {
        cin.tie(0);
        ios::sync_with_stdio(false);
        cout <<fixed<<setprecision(12);
        cerr <<fixed<<setprecision(12);
    }
}IoSetup;

typedef long long ll;
typedef pair < int , int >  pii;
static constexpr const signed int INF = 0x3f3f3f3f;
static constexpr const signed long long LINF = 0x3f3f3f3f3f3f3f3fLL;
static constexpr const signed int SMOD = 1000000007;
static constexpr const signed int NMOD = 998244353;
static constexpr const signed int dx[]={1,0,-1,0,1,1,-1,-1};
static constexpr const signed int dy[]={0,-1,0,1,-1,1,-1,1};

inline bool inside(int x,int y,int w,int h){return (x>=0 && y>=0 && x<w && y<h);}
template<class T>bool chmax(T &a, const T &b){return(a=max(a,b))==b;}
template<class T>bool chmin(T &a, const T &b){return(a=min(a,b))==b;}
inline int qp(int a,ll b,int mo){int ans=1;do{if(b&1)ans=1ll*ans*a%mo;a=1ll*a*a%mo;}while(b>>=1);return ans;}

int n;
vector<int> a;
deque<int> b;

signed main() {

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

    b.push_front(a[0]);

    for(int i = 1; i < n; i++) {
        auto t = lower_bound(ALL(b), a[i]) - b.begin();
        if(t)
            b[t-1] = a[i];
        else
            b.push_front(a[i]);
        
    }

    cout << b.size() << endl;
    
    return 0;
}



Measured memory_bytes: 1024
# 入力の受取
n, m = map(int, input().split())
k = [0] * (m+1)
s = [[] for _ in range(m+1)] 
for i in range(1, m+1):
    tmp = list(map(int, input().split()))
    k[i] = tmp[0]
    s[i] = tmp[1:]

p = list(map(int, input().split()))

# ビット全探索用のシーケンスを生成
seq = [0, 1]
import itertools
arr = itertools.product(seq, repeat=n)
#for v in arr:
#    print(v)

# ビット全パターンでスイッチの状態を判定
# 全て点灯の場合，ansに1を加算
ans = 0
for v in arr:
    v = [0] + list(v)
    flag = True
    # m個の電球をそれぞれ判定
    for light in range(1,m+1):
        t = s[light]
        count = 0
        for i in range(len(t)):
            count += v[t[i]]
        if count % 2 != p[light-1]:
            flag = False
    if flag:
        ans += 1


print(ans)

Measured memory_bytes: 3064
#include <stdio.h>

int main(void)
{
	int triangle[1000][3];
	int temp;
	int n;
	int i, j, k;

	scanf("%d", &n);
	for(i = 0; i < n; i++){
		scanf("%d %d %d", &triangle[i][0], &triangle[i][1], &triangle[i][2]);
	}

	for(k = 0; k < n; k++){
		for(i = 0; i < 2; i++){
			for(j = 0; j < 2; j++){
				if(triangle[k][j] < triangle[k][j+1]){
					temp = triangle[k][j];
					triangle[k][j] = triangle[k][j+1];
					triangle[k][j+1] = temp;
				}
			}
		}
	}

	for(i = 0; i < n; i++){
		if(triangle[i][0] * triangle[i][0] == triangle[i][1] * triangle[i][1] + triangle[i][2] * triangle[i][2]){
			printf("YES\n");
		}else{
			printf("NO\n");
		}
	}

	return 0;
}

Measured memory_bytes: 588
while 1:
    H, W = map(int,input().split())
    if H==0 and W==0:
        break
    for i in range(H):
        if i%2==0:
            if W%2==0:
                print('#.'*(W//2))
            else:
                print('#.'*(W//2)+'#')
        else:
            if W%2==0:
                print('.#'*(W//2))
            else:
                print('.#'*(W//2)+'.')
    print()



Measured memory_bytes: 5608