akhauriyash/Code-Regression huggingface dataset:
#define ll long long
#define pub push_back
#define pob pop_back
#define puf push_front
#define pof pop_front
#define mp make_pair
#define fo(i , n) for(ll i = 0 ; i < n ; i++)
#include<iomanip>
#include<cmath>
#include<cstdio>
#include<utility>
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<map>
#include<queue>
#include<set>
#include<assert.h>
#include<stack>
ll z = 1000000007 ;
ll gcd(ll a , ll b){ if(b > a) return gcd(b , a) ; if(b == 0) return a ; return gcd(b , a%b) ;}
ll power(ll a ,ll b){if(b <= 0) return 1 ; ll c = power(a , b/2) ; if(b%2 == 0) return ((c*c)%z) ; else return ((((c*c)%z)*a)%z) ;}
ll inverse(ll a ,ll n){return power(a , n-2) ;}
ll max(ll a , ll b){if(a > b) return a ; return b ;}
using namespace std ;


//ios_base::sync_with_stdio(0);
//cin.tie(0); cout.tie(0);

 
int main()
{
	ios_base::sync_with_stdio(0);
	cin.tie(0); cout.tie(0);
	
	ll n , d , a ;
	ll ans = 0 ;
	cin >> n >> d >> a ;
	vector<pair<ll ,ll> > v ;
	vector<ll> ind ;
	fo(i , n)
	{
		ll x , y ;
		cin >> x >> y ;
		y += (a-1) ;
		y /= a ;
		v.pub(mp(x , y)) ;
		ind.pub(x) ;
	}
	sort(ind.begin() , ind.end()) ;
	sort(v.begin() , v.end()) ;
	ll curr[n+2] ;
	fo(i , n+2)
	{
		curr[i] = 0 ;
	}
	ll val = 0 ;
	fo(i , n)
	{
		val += curr[i] ;
		v[i].second -= val ;
		if(v[i].second > 0)
		{
			curr[i+1] += v[i].second ;
			ll fin_ind = (ll)(upper_bound(ind.begin() , ind.end() , ind[i] + (2*d)) - ind.begin());
			curr[fin_ind] -= v[i].second ;
			ans += v[i].second ;
		}
	}
	cout << ans << endl ;
	return 0;
}

Measured memory_bytes: 9196
#include<stdio.h>
int bubbleSort(int A[], int N)
{
	int flag = 1;
	int j, i, t = 0;
	int index;
	for(i = 0; flag; i++)
	{
		flag = 0;
		for(j = N - 1; j > i; j--)
		{
			if(A[j] < A[j - 1])
			{
				index = A[j];
				A[j] = A[j - 1];
				A[j - 1] = index;
				flag = 1;
				t++;
			}
		}
	}
	return t;
}
int main(void)
{
	int N, i, t;
	int A[100];
	 
	scanf("%d", &N);
	for( i = 0; i < N; i++) scanf("%d",&A[i]);
	 
	t = bubbleSort(A, N);

	for( i = 0; i < N; i++ )
	{
		if( i ) printf(" ");
		printf("%d",A[i]);
	}
	printf("\n");
	printf("%d\n",t);
	 
	return 0;
}



Measured memory_bytes: 1968
def strToList(str,offset=0):
    res = [];
    for el in str.split(" "):
        if el!='':
            res.append(int(el)+offset)
    return res


[N,M,K] = strToList(input())
A = strToList(input())
B = strToList(input())

current_time = 0
current_value = 0
iA = 0
iB = 0

while iA<N:
    if current_time+A[iA]<=K:
        current_time+=A[iA]
        current_value+=1
        iA+=1
    else:
        break

max_value = current_value
iA-=1

while iA>-2 and iB<M:
    if current_time+B[iB]<=K:
        current_time+=B[iB]
        iB+=1
        current_value+=1
        if current_value>max_value:
            max_value=current_value
    else:
        current_time-=A[iA]
        iA-=1
        current_value-=1

print(max_value)


Measured memory_bytes: 41672
#include <iostream>
#include <numeric>
#include <vector>

constexpr int X = 1000000;

void solve() {
    int n;
    std::cin >> n;

    std::vector<int> cnt(X + 1, 0);
    int g = 0;
    while (n--) {
        int x;
        std::cin >> x;

        g = std::gcd(g, x);
        ++cnt[x];
    }

    if (g != 1) {
        std::cout << "not coprime\n";
        return;
    }

    for (int p = 2; p <= X; ++p) {
        int sum = 0;
        for (int x = p; x <= X; x += p) {
            sum += cnt[x];
        }
        if (sum > 1) {
            std::cout << "setwise coprime\n";
            return;
        }
    }

    std::cout << "pairwise coprime\n";
}

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

    solve();

    return 0;
}


Measured memory_bytes: 7164
#include<iostream>
using namespace std;
const int C_MAX=40*100*2;
const int AB_MAX=40*10;
const int INF=C_MAX;

int main(){
    int N, Ma, Mb;
    cin >> N >> Ma >> Mb;
    int a[N], b[N], c[N];
    int ans;

    for(int i=0; i<N; i++){
        cin >> a[i] >> b[i] >> c[i];
    }

    int dp[N+1][AB_MAX+1][AB_MAX+1];

    for(int i=0; i<N+1; i++){
        for(int ca=0; ca<=AB_MAX; ca++){
            for(int cb=0; cb<=AB_MAX; cb++){
                //cout << "i ca cb= " << i << " " << ca << " " << cb << endl;
                dp[i][ca][cb]=INF;
            }
        }
    }

    dp[0][0][0]=0;

    for(int i=0; i<N; i++){
        for(int ca=0; ca<=AB_MAX; ca++){
            for(int cb=0; cb<=AB_MAX; cb++){
                if(dp[i][ca][cb]==INF){
                    continue;
                }
                //cout << "i ca cb " << i << " " << ca << " " << cb << endl; 
                dp[i+1][ca][cb]=min(dp[i+1][ca][cb],  dp[i][ca][cb]);
                dp[i+1][ca+a[i]][cb+b[i]]=min(dp[i+1][ca+a[i]][cb+b[i]],  dp[i][ca][cb]+c[i]);
                //cout << "i+1 ca+a cb+b dp " << i+1 << " " << ca+a[i] << " " << ca+b[i] << " " << dp[i+1][ca+a[i]][cb+b[i]] << endl;
            }
        }
    }

    ans=INF;
    for(int ca=1; ca<=AB_MAX; ca++){
        for(int cb=1; cb<=AB_MAX; cb++){
            if( ca*Mb == cb*Ma ){
                    //cout << "met ca cb " << ca << " " << cb << endl;
                    ans=min(ans,dp[N][ca][cb]);
            }
        }
    }

    if( ans==INF ){
        ans=-1;
    }

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

Measured memory_bytes: 25984
#include <iostream>
#include <unordered_map>
#include <vector>
#include <map>
#include <set>
#include <string.h>
#include <algorithm>
#define ll long long
#define pr pair<int,int>
#define all vec.begin(),vec.end()
#define REP(i,a,b) for (int i = a; i < b; i++)
#define fi first
#define se second
#define pushb push_back
#define makep make_pair

using namespace std;

int main(){
	int size;
	cin >> size;
	string arr[size];
	int ch[size][26];
	memset(ch,0,sizeof(ch));
	string k;
	for(int i = 0; i < size; i++){
		cin >> k;
		for(int j = 0; j < k.size(); j++){
			ch[i][k[j] - 'a']++;
		}
	}
	for(int j = 0; j < 26; j++){
		int min = 2e9;
		REP(i,0,size){
			if(ch[i][j] < min)
				min = ch[i][j];	
		}
		REP(z,0,min)
			cout << (char)(j + 'a');
	}
	return 0;
}



Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		// TODO ?????????????????????????????????????????????
		
		Scanner sc = new Scanner(System.in);
		int a = sc.nextInt();
		int b = sc.nextInt();
		int x = a * b;
		int y = (a+b) * 2;
		
		System.out.println(x+" "+y);

	}

}

Measured memory_bytes: 26236
#include <iostream>
#include <cmath>
#include <vector>
#include <map>
#include <iomanip>
#include <algorithm>
#include <sstream>
#include <string>
#include <math.h>
#include <set>
#include <deque>
#include <queue>
#include <list>
using namespace std;
typedef long long ll;
const int mod = 1000000007;

#define for1(n) for (int i = 0 ; i < n ; i++)
#define for2(n) for (int j = 0 ; j < n ; j++)
#define for1l(n) for (ll i = 0 ; i < n ; i++)
#define for2l(n) for (ll j = 0 ; j < n ; j++)

int main() {
    ios::sync_with_stdio(false);
    int n, m, z = 0;
    cin >> n >> m;
    for (int i = 1 ; i * i <= m ; i++) {
    	if (m % i == 0) {
    		if (m / i >= n) z = max(z, i);
        	if (i >= n) z = max(z, m / i);
		}
	} 
	cout << z;
}

Measured memory_bytes: 3584
#include <iostream>
#include <vector>
#include <deque>
#include <algorithm>
#include <numeric>
#include <string>
#include <cstring>
#include <list>
#include <unordered_set>
#include <tuple>
#include <cmath>
#include <limits>
#include <type_traits>
#include <iomanip>
using namespace std;

using INT = long long;
using UINT = unsigned long long;

unsigned gcd(unsigned a, unsigned b) {
	while (1) {
		if (a < b) swap(a, b);
		if (!b) break;
		a %= b;
	}
	return a;
}

const UINT mod = 1000000007;

UINT PowMod(UINT x, UINT y)
{
	if (y == 0)
	{
		return 1;
	}
	else if (y == 1)
	{
		return x % mod;
	}
	else if (y % 2 == 0)
	{
		auto tmp = PowMod(x, y / 2);
		return tmp * tmp % mod;
	}
	else
	{
		auto tmp = PowMod(x, y / 2);
		return (tmp * tmp % mod) * x % mod;
	}
}

UINT getModInv(UINT N)
{
	return PowMod(N, mod - 2);
}

struct uf
{
	vector<INT> p;

	uf(INT n) : p(n)
	{
		for (size_t i = 0; i < n; i++)
		{
			p[i] = i;
		}
	}

	INT rt(INT n)
	{
		return p[n] == n ? n : p[n] = rt(p[n]);
	}

	void un(INT n, INT m)
	{
		p[rt(n)] = p[rt(m)];
	}

	bool eq(INT n, INT m)
	{
		return rt(n) == rt(m);
	}
};

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

	cout << min(n * a, b) << endl;
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long
#define MODV 1000000007
#define INFLL LLONG_MAX // 9223372036854775807
#define EPS 1e-9
#define rep(i, n) for(ll i=0, i##_len=(ll)(n); i<i##_len; i++)
#define repf(i, n) for(ll i=1, i##_len=(ll)(n+1); i<i##_len; i++)
#define all(v) v.begin(), v.end()
#define endl "\n"
#define vi vector<ll>
#define vvi vector<vector<ll>>
#define Yes() cout << "Yes" << endl
#define YES() cout << "YES" << endl
#define No() cout << "No" << endl
#define NO() cout << "NO" << endl
#define Init() std::ios::sync_with_stdio(false); std::cin.tie(0); std::cout<<fixed<<setprecision(15);
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; }
using namespace std;

template<int MOD> struct Fp{
    long long val;
    constexpr Fp(long long v = 0) noexcept : val(v % MOD){ if(val<0) v += MOD; }
    constexpr int getmod(){ return MOD; }
    constexpr Fp operator - () const noexcept{ return val ? MOD - val : 0; }
    constexpr Fp operator + (const Fp& r) const noexcept{ return Fp(*this) += r; }
    constexpr Fp operator - (const Fp& r) const noexcept{ return Fp(*this) -= r; }
    constexpr Fp operator * (const Fp& r) const noexcept{ return Fp(*this) *= r; }
    constexpr Fp operator / (const Fp& r) const noexcept{ return Fp(*this) /= r; }
    constexpr Fp& operator += (const Fp& r) noexcept{ val += r.val; if(val>=MOD) val -= MOD; return *this; }
    constexpr Fp& operator -= (const Fp& r) noexcept{ val -= r.val; if(val<0) val += MOD; return *this; }
    constexpr Fp& operator *= (const Fp& r) noexcept{ val = val*r.val%MOD; return *this; }
    constexpr Fp& operator /= (const Fp& r) noexcept{
        long long a = r.val, b = MOD, u = 1, v = 0;
        while (b) { long long t = a/b; a -= t*b; swap(a, b); u -= t*v; swap(u, v); }
        val = val*u%MOD; if(val<0) val += MOD; return *this; }
    constexpr bool operator == (const Fp& r) const noexcept{ return this->val == r.val; }
    constexpr bool operator != (const Fp& r) const noexcept{ return this->val != r.val; }
    friend constexpr ostream& operator << (ostream &os, const Fp<MOD>& x) noexcept{ return os << x.val; }
    friend constexpr istream& operator >> (istream &is, Fp<MOD>& x) noexcept{ return is >> x.val; }
    friend constexpr Fp<MOD> modpow(const Fp<MOD> &a, long long n) noexcept{
        if (n == 0) return 1; auto t = modpow(a, n/2); t = t*t; if(n & 1) t = t*a; return t; }
};
const int MOD = MODV;
using mint = Fp<MOD>;

long long modPow(long long x, long long n, long long mod = MODV){
    if(n == 0) return 1;
    if(n%2 == 0) return modPow(x*x%mod, n/2, mod)%mod;
    return x%mod * modPow(x%mod, n-1, mod)%mod;
}

int main(){
    Init();
    string s; cin >> s;
    mint ans = 0;
    ll cnt = 0, n = s.size();
    rep(i, n){
        if(s[i] == '0') continue;
        ans += modPow(2, cnt) * modPow(3, n-1-i);
        cnt++;
    }
    ans += modPow(2, cnt);
    cout << ans << endl;
}

Measured memory_bytes: 3724
import math
n = int(input())
c = 0

for i in range(n):
    m = int(input())
    if m == 2 or m == 3:
        c +=1
    else:
        T = 1
        for k in range(2,math.ceil(math.sqrt(m))+1):
            if m % k == 0:
                T = 0
                break
        if T == 1:
            c +=1
print(c)


Measured memory_bytes: 5676
#include <iostream>
#include <iomanip>
#include <string>
#include <vector>
#include <algorithm>
#include <queue>

using namespace std;
typedef long long ll;

//i枚のコインを投げたとき、表がj枚である確率
double dp[3000][3000];
int main()
{
	int N; cin >> N;
	vector<double> P(N + 1);
	for (int i = 0; i < N; ++i) {
		cin >> P[i];
	}
	memset(dp, 0, sizeof(0));
	dp[0][0] = 1;
	for (int i = 0; i < N; ++i) {
		for (int j = 0; j <= i; ++j) {
			//表が出る
			dp[i+1][j+1] += dp[i][j] * P[i];
			//裏が出る
			dp[i+1][j] += dp[i][j] * (1 - P[i]);
		}
	}
	double sum = 0;
	for (int i = N / 2 + 1; i <= N; ++i) {
		sum += dp[N][i];
	}
	cout << fixed << setprecision(10) << sum << endl;
	return 0;
}


Measured memory_bytes: 49348
import java.util.*;
public class Main{
  public static void main(String [] args){
    Scanner sc = new Scanner(System.in);
    String input = sc.next();
    String output;
    char [] str = input.toCharArray();
    char con;
    for(int i = 0;i < str.length / 2;i++){
      con = str[i];
      str[i] = str[str.length - 1 - i];
      str[str.length - 1 - i] = con;
    }
    System.out.println(String.valueOf(str));
  }
}

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

int main() {
  string S , T ;
  cin >> S >> T ;
  
  int count=0 ;
  
  for( int i=0 ; i<S.size() ; i++){
    if( S.at(i) != T.at(i) ){
      count++ ;
   	}
  }
   cout << count << endl;
}


Measured memory_bytes: 3884
#include<iostream>
#include<iomanip>
using namespace std;
int a, b, c, d, e, f, g;
long long remain;
int speed;
int x[10000000];
double res;
int main() {
	cin >> a >> b >> c >> d >> e >> f;
	for (int i = 0; i < a; i++) {
		cin >> g;
		x[g] = 1;
	}
	for (int i = 0; i < f; i++) {
		if (x[i] == 1) {
			if ((remain - 1) / (c * e) < b) {
				remain += c * e;
			}
			else {
				g = ((c * e) - (remain % (c * e)));
				if (g == c * e) { g = 0; }
				remain += g;
			}
		}
		if (remain > 0) {
			res += 1.0 / e;
			remain--;
		}
		else {
			res += 1.0 / d;
		}
	}
	cout << setprecision(15) << res << endl;
	return 0;
}

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

public class Main {
	static int mod = (int) 1e9 + 7;
	static int DX[] = { -1, 0, 1, 0 }, DY[] = { 0, -1, 0, 1 };

	public static void main(String[] args) {
		FastScanner fs = new FastScanner(System.in);
		long x = fs.nextLong(), y = fs.nextLong();
		if(Math.abs(x-y)<=1)System.out.println("Brown");
		else System.out.println("Alice");

	}
}

//高速なScanner
class FastScanner {
	private BufferedReader reader = null;
	private StringTokenizer tokenizer = null;

	public FastScanner(InputStream in) {
		reader = new BufferedReader(new InputStreamReader(in));
		tokenizer = null;
	}

	public String next() {
		if (tokenizer == null || !tokenizer.hasMoreTokens()) {
			try {
				tokenizer = new StringTokenizer(reader.readLine());
			} catch (IOException e) {
				throw new RuntimeException(e);
			}
		}
		return tokenizer.nextToken();
	}

	public String nextLine() {
		if (tokenizer == null || !tokenizer.hasMoreTokens()) {
			try {
				return reader.readLine();
			} catch (IOException e) {
				throw new RuntimeException(e);
			}
		}
		return tokenizer.nextToken("\n");
	}

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

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

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

	public int[] nextIntArray(int n) {
		int[] a = new int[n];
		for (int i = 0; i < n; i++)
			a[i] = nextInt();
		return a;
	}

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

Measured memory_bytes: 23124
#include<bits/stdc++.h>
using namespace std;
int main() {
	int q1, q2, q3;
	scanf("%d %d %d", &q1, &q2, &q3);
	int now = max(q1, q2);
	int ans = 0;
	if (q3 / now * now != q3) {
		ans = q3 / now + 1;
	}
	else ans = q3 / now;
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>

int main() {
	int N, X;
	std::cin >> N >> X;
	int min_ = 0x7fffffff;
	for (int i = 0; i < N; i++) {
		int m;
		std::cin >> m;
		X -= m;
		min_ = std::min(min_, m);
	}
	std::cout << N + (X / min_) << std::endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for(ll i=0;i<n;i++)
#define rep1(i,n) for(ll i=1;i<=n;i++)
#define repk(i,m,n) for(ll i=m;i<n;i++)
#define IOS ios::sync_with_stdio(false);cin.tie(0);
#define F first
#define S second
#define pb push_back
typedef long long ll;
typedef long double ld;
using namespace std;
const int MOD1=1e9+7;
const int MOD2=998244353;
const int INF=2*1e9;
map<ll,ll> m;
vector<ll> va,vb,vc;
int main()
{
    ll a,b,c,x,y,ans=0,temp;
    cin>>x>>y>>a>>b>>c;
    rep(i,a)
    {
        cin>>temp;
        va.pb(temp);
    }
    rep(i,b)
    {
        cin>>temp;
        vb.pb(temp);
    }
    rep(i,c)
    {
        cin>>temp;
        vc.pb(temp);
    }
    sort(va.begin(),va.end());
    sort(vb.begin(),vb.end());
    rep(i,x) vc.pb(va[a-i-1]);
    rep(i,y) vc.pb(vb[b-i-1]);
    sort(vc.begin(),vc.end());
    rep(i,x+y) ans+=vc[c+x+y-i-1];
    cout<<ans;
}


Measured memory_bytes: 7536
#include <stdio.h>
#define N 200000

int main(){
  int i, maxv, minv, n, r[N];

  scanf("%d", &n);

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

  maxv = r[1] - r[0];
  minv = r[0];

  for(i = 1; i < n; i++){
    if(maxv < r[i] - minv) maxv = r[i] - minv;
    if(minv > r[i]) minv = r[i];
  }

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

  return 0;
}

Measured memory_bytes: 1376
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> P;
#define fi first
#define se second
#define repl(i,a,b) for(ll i=(ll)(a);i<(ll)(b);i++)
#define rep(i,n) repl(i,0,n)
#define all(x) (x).begin(),(x).end()
#define dbg(x) cout<<x<<endl
#define mmax(x,y) (x>y?x:y)
#define mmin(x,y) (x<y?x:y)
#define maxch(x,y) x=mmax(x,y)
#define minch(x,y) x=mmin(x,y)
#define uni(x) x.erase(unique(all(x)),x.end())
#define exist(x,y) (find(all(x),y)!=x.end())
#define bcnt __builtin_popcountll
#define INF 1e16
#define mod 1000000007
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;
}
int main(){

    ll x;
    cin>>x;
    while(true){
        if(IsPrime(x)) {
            cout<<x<<endl;
            return 0;
        }
        x++;
    }
    return 0;
}

Measured memory_bytes: 256
x1,y1,x2,y2=map(int,input().split())
ans=""
ans+="U"*(y2-y1)
ans+="R"*(x2-x1)
ans+="D"*(y2-y1)
ans+="L"*(x2-x1)
ans+="L"
ans+="U"*(y2+1-y1)
ans+="R"*(x2+1-x1)
ans+="D"
ans+="R"
ans+="D"*(y2+1-y1)
ans+="L"*(x2+1-x1)
ans+="U"
print(ans)


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

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int ans = 0;
        int N = sc.nextInt();
        int M = sc.nextInt();
        int C = sc.nextInt();
        int[][] A = new int[N][M];
        int[] B = new int[M];
        for(int i = 0; i < M; i++) {
            B[i] = sc.nextInt();
        }
        for(int i = 0; i < N; i++) {
            for (int j = 0; j < M; j++) {
                A[i][j] = sc.nextInt();
            }
        }
        for(int i = 0; i < N; i++) {
            int score = 0;
            for(int j = 0; j < M; j++) {
                score += A[i][j] * B[j];
            }
            if(score + C > 0) ans++;
        }
        System.out.println(ans);
    }
}

Measured memory_bytes: 22996
object Main {
  def main(args: Array[String]): Unit = {
    Iterator.continually {
      val Array(n, x, _*) = io.StdIn.readLine().split(" ").map(_.toInt)
      (n, x)
    }.takeWhile {
      case (0, 0) => false
      case _ => true
    }.foreach { case (n, x) =>
      val count =
        (1 to n - 2).map { i =>
          val v = x - i
          (i + 1 to n.min(v / 2)).count { j =>
            val pair = v - j
            j < pair && pair <= n
          }
        }.sum

      println(count)
    }
  }
}

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

int main() {
	int a, b, k;
	cin >> a >> b >> k;
	for (int i = 0; i < k; i++) {
		if (i % 2 == 0) {
			if (a % 2 == 1) {
				a--;
			}
			a /= 2;
			b += a;
		} else {
			if (b % 2 == 1) {
				b--;
			}
			b /= 2;
			a += b;
		}
	}
	cout << a << " " << b << endl;
	return 0;
}

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

#define ARC(i, a, b) for(int i = (a); i < (b); ++i)
#define RC(i, n) ARC(i, 0, n)
#define ARCH(i, a, b) for(int i = (a) - 1; i >= (b); --i)
#define RCH(i, n) ARCH(i, n, 0)

template<class T> T ant(const T &a, const T &b){ return a > b ? a : b; }
template<class T> T ont(const T &a, const T &b){ return a < b ? a : b; }
template<class T> T rng(const T &a, const T &b){ return a > b ? a - b : b - a; }
template<class T> T &anth(T &a, const T &b){ return a = ant(a, b); }
template<class T> T &onth(T &a, const T &b){ return a = ont(a, b); }

#define ull unsigned long long

int main(){
	ull a, b;
	std::cin >> a >> b;
	++b;

	ull ans = (a & 2) != (b & 2);

	ARC(i, 1, 40){
		ull at = 0, bt = 0;
		if((a >> i) & 1) at = a & 1;
		if((b >> i) & 1) bt = b & 1;
		ans |= (at ^ bt) << i;
	}

	std::cout << ans << std::endl;
}


Measured memory_bytes: 256
//B - Bite Eating
using System;
using System.Linq;
using System.Collections.Generic;

namespace B
{
    class Program
    {
        static void Main(string[] args)
        {
            var nl = Console.ReadLine().Split().Select(int.Parse).ToArray();
            var apples = new List<int>();
            
            for(int i=0;i<nl[0];i++)
            {
                apples.Add(nl[1] + i);
            }
            
            var ans = apples.OrderBy(x => x*x).Where((x,i)=> i >0).Sum();
            Console.WriteLine(ans);
        }
    }
}


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

int main(){
	int n,t;
	cin>>n>>t;
	vector<int> arr(n);
	for(int i=0;i<n;i++){
		cin>>arr[i];
	}
	int mins = arr[0];
	vector<int> a(n);
	for(int i=0;i<n;i++){
		a[i] = arr[i] - mins;
		mins = min(mins,arr[i]);
	}

	sort(a.begin(),a.end(),greater<int>());
	int res = 1;
	for(int i=1;i<n;i++){
		if(a[0]==a[i]) res++;
		else break;
	}
	cout<<res;
}

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




int main() {
	int64_t K, N;
	cin >> K >> N;
	vector<int64_t> vec(N);
	vector<int64_t> len(N);
	
	for (int i = 0; i < N ; i++)
	{
		cin >> vec.at(i);
	}
	 int64_t ans= abs(vec.at(0) - 0) + abs(K - vec.at(N - 1));
	 for (int i = 1; i < N; i++)
	 {
		 ans = max(ans, vec.at(i) - vec.at(i - 1));
	 }
	 cout << K-ans << endl;
	
}

Measured memory_bytes: 6388
n=gets.to_i
aString=gets.chomp.chars
bString=gets.chomp.chars
cString=gets.chomp.chars
sameCharCounts=[]
n.times do |index|
  stringCount = [aString[index],bString[index],cString[index]].count(aString[index])
  stringCount = 2 if stringCount == 1 && bString[index] == cString[index]
  sameCharCounts << stringCount
end
puts sameCharCounts.count(2) + sameCharCounts.count(1) * 2

Measured memory_bytes: 1916
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define pb push_back
#define eb emplace_back
#define precision(n) cout << fixed << setprecision(n);
#define fast {ios_base::sync_with_stdio(false);cin.tie(NULL);}
int main()
{
    fast;
   string s;
   int w,p;
   cin>>s;
   for(int i=0;i<s.size();i++)
   {
       if(s[i]=='A')
       {
           p=i;
           break;
       }
   }
   for(int i=s.size()-1;i>=0;i--)
   {
       if(s[i]=='Z')
       {
           w=i;
           break;
       }
   }
   cout<<w-p+1<<endl;
    return 0;
}





Measured memory_bytes: 3776
#include <bits/stdc++.h>
#define ll long long
#define pb push_back
#define mod 1000000007
#define maxv 1e5+1
#define inf 4e18
using namespace std;
int main()
{
    ll n,W;
    cin>>n>>W;
    ll val[n+1],wt[n+1];
    vector<vector<ll>>knap(n+1,vector<ll>(maxv,inf));//2d vector with n+1 r and maxv col with value =inf
    //here the answer i.e maxvalue cant be >10^5
    for(ll i=0;i<n;i++)
        cin>>wt[i]>>val[i];
    for(ll i=0;i<n;i++)
    {
        for(ll j=0;j<maxv;j++)
        {
            if(i==0&&j==0)
                knap[i][j]=0;
            if (j<val[i])
                knap[i+1][j]=knap[i][j];
            else
                knap[i+1][j]=min(knap[i][j-val[i]] + wt[i],knap[i][j]);
        }
    }
    for(ll i=maxv-1;i>=0;i--)//max value cant be greater than maxv coz vi<=10^3 and n<=100
    {
        if(knap[n][i]<=W)
        {
            cout<<i;//max value
            break;
        }
    }
}

Measured memory_bytes: 80256
#include<stdio.h>

int strlen(char str[]){
	int len = 0;
	for(int i = 0; str[i] != '\0'; i++){
		len++;
	}
	return len;
}

int main(){
	int n;
	scanf("%d", &n);
	getchar();
	char str[n];
	char leftArr[n / 2];
	char rightArr[n / 2];
	int counter = 0;
	scanf("%s", str);
	int len = strlen(str);
	if(len % 2 != 0){
		printf("No\n");
	}
	else if(len % 2 == 0){
		int mid = len / 2;
		for(int i = 0; i < mid; i++){
			leftArr[i] = str[i];
		}
		for(int i = 0; i < mid; i++){
			rightArr[i] = str[mid + i];
		}
		for(int i = 0 ; i * 2 < len; i++){
			if(rightArr[i] == leftArr[i]){
				counter++;
			}
		}
		if(counter == len / 2){
			printf("Yes\n");
		}
		else{
			printf("No\n");
		}
	}
        return 0;
}

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

int is_prime(int n) {
  if(n==1) return 0;
  if(n==2) return 1;

  int div = 2;
  int flag = true;
  while(div*div<=n && flag) {
    if(n%div==0) flag=false;
    div++;
  }

  return flag;
}

int main() {
  int x;
  cin>>x;

  int ans = x;
  while(true) {
    if(is_prime(ans)) {
      cout<<ans<<endl;
      break;
    }
    ans++;
  }

  return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<cmath>
#include<stack>
#include<map>
#include<vector>
#include<set>
using namespace std;
const int MAX=5e5+10;
const double eps=1e-4;
const int mod=1e9+7;
#define INF 0x7fffffff
#define ll long long
#define edl putchar('\n')
#define useit  ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define FOR(i,a,b) for(int i=a;i<=b;i++)
#define ROF(i,a,b) for(int i=a;i>=b;i--)
#define mst(a) memset(a,0,sizeof(a))
#define mstn(a,n) memset(a,n,sizeof(a))
//struct point{int v,l;}a[MAX];
//double cross(point a,point b){return (a.x*b.y-a.y*b.x);}
//double dot(point a,point b){return (a.x*b.x+a.y*b.y);}

int main()
{
	int n; 
	char a,c;
	cin>>a>>c;
	if(a-'a'>c-'a')
	cout<<">"<<endl;
	else if(a-'a'==c-'a')
	cout<<"="<<endl;
	else
	cout<<"<"<<endl;
}

Measured memory_bytes: 256
#include<stdio.h>
int max(int a,int b){if(a>b){return a;}else{return b;}}
int min(int a,int b){if(a<b){return a;}else{return b;}}

int main(){
    int a,b,c,d;
    int ans = 0;

    scanf("%d %d %d %d",&a,&b,&c,&d);
    int low = max(a,c);
    int hi = min(b,d);
    if(hi-low > 0) printf("%d\n",hi-low);
    else printf("0\n");
    return 0;
}

Measured memory_bytes: 128
def merge(A,left,mid,right):
    global cnt
    L=A[left:mid]
    R=A[mid:right]
    L.append(float("inf"))
    R.append(float("inf"))
    i=0
    j=0
    for k in range(left, right):
        cnt+=1
        if L[i]<=R[j]:
            A[k]=L[i]
            i+=1
        else:
            A[k]=R[j]
            j+=1
            
def mergeSort(A,left,right):
        if left+1<right:
            mid=(left+right)//2
            mergeSort(A,left,mid)
            mergeSort(A,mid,right)
            merge(A,left,mid,right)   
            
n = int(input())
S=list(map(int,input().split()))
cnt=0

mergeSort(S,0,n)

print(" ".join(map(str,S)))
print(cnt)

Measured memory_bytes: 68848
#include <iostream>
#include <sstream>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <ctime>
#include <vector>
#include <string>
#include <map>
#include <set>
#include <deque>
#include <queue>
#include <stack>
#include <functional>
#include <algorithm>

using namespace std;

#define rep(i,j) REP((i), 0, (j))
#define REP(i,j,k) for(int i=(j);(i)<(k);++i)
#define BW(a,x,b) ((a)<=(x)&&(x)<=(b))
#define ALL(v) (v).begin(), (v).end()
#define LENGTHOF(x) (sizeof(x) / sizeof(*(x)))
#define AFILL(a, b) fill((int*)a, (int*)(a + LENGTHOF(a)), b)
#define SQ(x) ((x)*(x))
#define Mod(x, mod) (((x)+(mod)%(mod))
#define MP make_pair
#define PB push_back
#define Fi first
#define Se second
#define INF (1<<29)
#define EPS 1e-10
#define MOD 1000000007

typedef pair<int, int> pi;
typedef pair<int, pi> pii;
typedef vector<int> vi;
typedef queue<int> qi;
typedef long long ll;

int M,N,K;
int cum[4][1024][1024];
map<char, int>m;
char pl[1024][1024];

int solve(int joi, int i, int j, int k, int l){
  return cum[joi][i-1][j-1] - cum[joi][i-1][l] - cum[joi][k][j-1] + cum[joi][k][l];
}

int main(){
  m['J'] = 0; m['O'] = 1; m['I'] = 2;
  scanf("%d%d%d",&M,&N,&K);
  memset(cum,0,sizeof(cum));
  rep(i,M){
    scanf("%s", pl[i]);
    rep(j,N){
      cum[m[pl[i][j]]][i+1][j+1]++;
    }
  }

  rep(k,3){
    rep(i, M+1) rep(j,N) cum[k][i][j+1] += cum[k][i][j];
    rep(j, N+1) rep(i,M) cum[k][i+1][j] += cum[k][i][j];

  }

  rep(i,K){
    int a, b, c, d;
    scanf("%d%d%d%d", &a,&b,&c,&d);
    printf("%d %d %d\n", solve(0,a,b,c,d), solve(1,a,b,c,d), solve(2,a,b,c,d));
  }
  return 0;
}

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

#define rep(i, a, b) for(int i = (a); i < (b); ++i)
#define trav(a, x) for(auto& a : x)
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define sz(x) ((int)(x).size())
#define endl '\n'

typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<ll> vll;

const ll mod = 1000000007;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
// head

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

    ll a, b, c, d;
    cin >> a >> b >> c >> d;
    cout << max({a * c, a * d, b * c, b * d}) << endl;
    return 0;
}


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

int main(){
    int n;
    while(scanf("%d",&n),n){
        int dp[2][1010]={{0}};
        int ma=0;
        for(int i=0;i<n;i++){
            char str[1010];
            scanf("%s",str);
            for(int j=0;j<n;j++){
                if(str[j]=='*')dp[(i+1)&1][j+1]=0;
                else{
                    dp[(i+1)&1][j+1]=min(dp[i&1][j],min(dp[(i+1)&1][j],dp[i&1][j+1]))+1;
                }
                ma=max(ma,dp[(i+1)&1][j+1]);
            }
        }

        printf("%d\n",ma);
    }

    return 0;
}

Measured memory_bytes: 1200
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include <cmath>
#include <limits>
#include <utility>
#include <map>
#include <iomanip>
#include <queue>
#include <cctype>
#include <stack>
#include <random>
#include <list>
#include <numeric>
#include <chrono>
#include <set>


#define rep(i,p,q) for(ll i = p;i < q;i++)
#define ll long long

using namespace std;

vector<vector<ll>> graph;
vector<ll> query;
vector<ll> ans;
vector<ll> visited;


const long long MAX_N = 1 << 17;

long long dat[2 * MAX_N - 1];

ll ecd(ll a, ll b) {
	if (a < b) swap(a, b);
	if (b == 0) return a;
	else {
		return ecd(b, a % b);
	}
}

ll pow(ll a, ll b) {
	vector<ll> d = vector<ll>((ll)(log(b)) + 2);
	d[0] = a;
	rep(i, 1, d.size()) d[i] = d[i - 1] * d[i - 1];
	ll ret = 1;
	rep(i, 0, log(b) + 1) {
		if (b & 1 << i) ret *= d[i];
	}
	return ret;
}

vector<ll> a , b;

//145 A
int main(void) {
	ll r;
	cin >> r;
	cout << r * r << endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<utility>
#include<vector>

using namespace std;
const long mod = 1000000007;

struct UnionFind {
private:
	vector<long> prisize;//属するグラフの頂点数を返す。参照は根でよい。
public:
	vector<long> par;//親を返す
	UnionFind(long N) : prisize(N), par(N) {
		for (int i = 0; i < N; i++) par[i] = i;//全て根である状態
		for (int i = 0; i < N; i++) prisize[i] = 1;
	}

	long root(long i) {//根を返す
		if (par[i] == i) return i;
		return par[i] = root(par[i]); //根に直接繋ぎなおす
	}

	void unite(long x, long y) {//二つの木の統合(rxをryに繋ぐ)
		long rx = root(x);
		long ry = root(y);

		if (rx == ry) return;
		if (rx > ry) swap(rx, ry);
		par[rx] = ry;
		prisize[ry] += prisize[rx]; //ここ分解を想定していない & size[rx]は更新されない。
	}

	bool same(long x, long y) { return root(x) == root(y); }//根が等しいか
	long size(long i) { return prisize[root(i)]; }
};

int main() { 
	//逆から走査する(UnionFindなので)
	long N, M; cin >> N >> M;
    
	vector<long> F(M + 1);//崩落後の不便さ
	vector<pair<long, long>> bridge(M);//入力リスト
	F[M] = N * (N - 1) / 2;

	UnionFind tree(N);

	for (int i = 0; i < M; i++) {//入力
		long A, B; cin >> A >> B;
		A--; B--;
		bridge[i] = make_pair(A, B);
	}

	for (int i = M - 1; i >= 0; i--) {
		long A, B; 
		A = bridge[i].first;
		B = bridge[i].second;

		if (tree.same(A, B)) {
			F[i] = F[i + 1];
		}
		else {
			F[i] = F[i + 1] - (tree.size(A) * tree.size(B));
			tree.unite(A, B);
		}
	}

	for (int i = 1; i <= M; i++) cout << F[i] << endl;
}

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

int main() {
  ll N, D;
  cin >> N >> D;
  ll ans = 0;
  rep (i, N) {
    ll x, y;
    cin >> x >> y;
    if (sqrt(x * x + y * y) <= D) ans++;
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 3652
#include <bits/stdc++.h>
using namespace std;
#define ll long long 
#define MOD 1000000007
ll fact[200005];
#define eps 1e-9
#define INF 1e18
#define N 200005
inline ll mul(ll a,ll b){
  a=(a+MOD)%MOD;
  b=(b+MOD)%MOD;
  ll c=a*b;
  c=(c+MOD)%MOD;
  return c;
}
ll power(ll a,ll b,ll c){
  ll ans=1;
  while(b){
    if(b&1){
      ans=mul(ans,a);
    }
    a=mul(a,a);
    b=b/2;
  }
  return ans;
}
int main() {
        ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
        ll x; cin>>x;
        ll lo=1;
        ll hi=37600;
        ll res=0;
        while(lo<=hi){
        	ll mid=(lo+hi)/2;
        	ll kk=100;
        	for(int i=1;i<=mid;++i){
        		kk=kk*1.01;
        		if(kk>=x)break;
        	}
        	if(kk>=x)res=mid,hi=mid-1;
        	else lo=mid+1;
        }
        cout<<res;
        return 0;
}


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

using namespace std;

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

#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define rep2(i,n) for(int i=1;i<=(int)(n);i++)
#define rep3(i,n) for(int i=0;i<=(int)(n);i++)
#define REP(i,m,n) for(int i=m;i<(int)(n);i++)
#define repll(i,n) for(ll i=0;i<(ll)(n);i++)
#define repll2(i,n) for(ll i=1;i<=(ll)(n);i++)
#define REPLL(i,m,n) for(ll i=m;i<(ll)(n);i++)
#define INF (int)1e9  //
#define LINF (ll)4e18  //
#define MOD (int)(1e9)+7
#define MP make_pair
#define YES(n) cout << ((n) ? "YES" : "NO"  ) << endl
#define Yes(n) cout << ((n) ? "Yes" : "No"  ) << endl
#define yes(n) cout << ((n) ? "yes" : "no"  ) << endl
#define PI 3.1415926535898

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

int h, w;
string s[51];
string t[53];

int check(int x, int y) {
    int cnt = 0;
    if (t[x + 1][y + 1] == '#') cnt++;
    if (t[x + 1][y] == '#') cnt++;
    if (t[x + 1][y - 1] == '#') cnt++;

    if (t[x][y + 1] == '#') cnt++;
    if (t[x][y - 1] == '#') cnt++;

    if (t[x - 1][y + 1] == '#') cnt++;
    if (t[x - 1][y] == '#') cnt++;
    if (t[x - 1][y - 1] == '#') cnt++;

    return cnt;
}

int main() {

    cin >> h >> w;

    rep(i, h) cin >> s[i];


    t[0] = "";
    rep(i, w + 2) t[0] += ".";
    rep2(i, h) t[i] = "." + s[i - 1] + ".";
    t[h + 1] = "";
    rep(i, w + 2) t[h + 1] += ".";

    rep2(i, h) {

        rep2(j, w) {
            if (t[i][j] == '.') cout << check(i, j);
            else cout << '#';
        }
        cout << endl;
    }

    return 0;
}



Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
using namespace std;
int main(){
	int N,A[200000];
	long long int ans;
	cin>>N;
	for(int i=0;i<N;i++){cin>>A[i];A[i]*=-1;}
	sort(A,A+N);
	for(int i=0;i<N;i++)A[i]*=-1;
	
	ans=A[0];
	for(int i=2;i<N;i++){
		ans+=A[i/2];
	}
	cout<<ans;
	return 0;
}

Measured memory_bytes: 4416
#include <iostream>
#include <vector>
using namespace std;
int main(){
    int n,k;
    vector<int> a;
    cin>>n;
    a.push_back(0);
    for(int i=0;i<n;i++){
        cin>>k;
        a.push_back(k);
    }
    int m=0,b[200010]={};
    vector<int> ans;
    for(int i=n;i>0;i--){
        int sum=0;
        for(int j=i*2;j<=n;j+=i){
            sum+=b[j];
        }
        if(sum%2!=a[i]){
            m++;
            b[i]=1;
            ans.push_back(i);
        }
    }
    cout<<m<<endl;
    for(int i=m-1;i>=0;i--){
        cout<<ans[i];
        if(i) cout<<" ";
    }
    cout<<endl;
    return 0;
}

Measured memory_bytes: 3572
# https://atcoder.jp/contests/abc051/tasks/abc051_d
# 想定解法
# 最短距離の隣接行列Dが与えられたときに、edges[a, b]が最短経路に含まれるかどうか考える
# 2点s,tについて、最短距離であれば、D[s,t]=D[s,i]+edges[i,j]+D[j,t]を満たすi,jの組み合わせは最短経路辺である
# 5000*1000の探索なので間に合う

from scipy.sparse import csr_matrix  # 自分で配列を作ってからcsrに入れよう(lilに打ち込んでいくのは非常に遅い)

# ダイクストラ法 (正の単一始点最短経路) (全点間最短経路)
from scipy.sparse.csgraph import dijkstra
import sys
sys.setrecursionlimit(1 << 25)
read = sys.stdin.readline
ra = range
enu = enumerate


def read_ints():
    return list(map(int, read().split()))


N, M = read_ints()
adj_mat = [[0] * N for _ in range(N)]
INF = 10 ** 9
from collections import defaultdict
from itertools import combinations
edges = defaultdict(lambda: INF)
for _ in range(M):
    a, b, c = read_ints()
    a -= 1
    b -= 1
    adj_mat[a][b] = c
    adj_mat[b][a] = c
    edges[a, b] = c

adj_mat = csr_matrix(adj_mat, dtype='int')
D = dijkstra(adj_mat, directed=False)
# print(D)

# 最短経路じゃない辺全探索
edge_not_use = set()
# 辺を固定してs,tを全探索したほうが良さそう
# だけどこれはTLE(pythonが遅いせい)
# for (i, j), e in edges.items():
#     for s, t in combinations(range(N), 2):
#         d = D[s, t]
#         if d == D[s, i] + e + D[j, t] or d == D[t, i] + e + D[j, s]:
#             break
#     else:
#         edge_not_use.add((i, j))

# よく考えてみれば
# D[s,j]=D[s,i]+edges[i,j]のedges[i,j]は最短経路の一部になっているはず(s→jの最短経路の一部を成す)
# sを全探索するだけでいい

for (i, j), e in edges.items():
    for s in range(N):
        d = D[s, j]
        if d == D[s, i] + e or d == D[s, j] + e:
            break
    else:
        edge_not_use.add((i, j))


print(len(edge_not_use))
# print(edge_not_use)


Measured memory_bytes: 17932
#include<bits/stdc++.h>
#define reg register
#define ll long long
using namespace std;
ll x,a,b,c,ans;
int main()
{
	scanf("%lld%lld%lld%lld",&a,&b,&c,&x);
	for(reg ll i=0;i<=a;i++)
	for(reg ll j=0;j<=b;j++)
	for(reg ll k=0;k<=c;k++)
	{
		if(500*i+100*j+50*k==x)ans++;
		if(500*i+100*j+50*k>x)break;
	}
	printf("%lld\n",ans);
}

Measured memory_bytes: 256
while True:
    n, x = [int(_) for _ in input().split()]
    if n == 0 and x == 0:
        break
    ans = 0
    for i in range(1, n+1):
        for j in range(i+1, n+1):
            for k in range(j+1, n+1):
                if i+j+k == x:
                    ans += 1
    print(ans)



Measured memory_bytes: 5604
#include "iostream"
#include "climits"
#include "list"
#include "queue"
#include "stack"
#include "set"
#include "functional"
#include "algorithm"
#include "string"
#include "map"
#include "iomanip"
#include "cmath"

using namespace std;

const long long int MOD = 1000000007;

long long int N, M, K, H, W, L, R;

class CEdge {
public:
	int place;
	int f;
	int s;
	CEdge() {
		f = -1;
		s = -1;
	}
};

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

	cin >> N >> M >> H >> K;
	while (N) {
		vector<int>score(N);
		vector < int>goal(N);
		vector<vector<CEdge>>edge(H);
		for (int i = 0; i < N; i++) {
			cin >> score[i];
		}
		for (int i = 0; i < M; i++) {
			cin >> L >> R;
			CEdge e;
			e.place = L - 1;
			edge[R].push_back(e);
		}
		for (int i = 0; i < N; i++) {
			int box = i;
			for (int j = 1; j < H; j++) {
				for (auto k = edge[j].begin(); k != edge[j].end();++k) {
					if ((*k).place == box || (*k).place + 1 == box) {
						box = (*k).place * 2 + 1 - box;
						if ((*k).f == -1) {
							(*k).f = i;
						}
						else {
							(*k).s = i;
						}
					}
				}
			}
			goal[i] = box;
		}
		int ans = 0;
		for (int i = 0; i < K; i++) {
			ans += score[goal[i]];
		}
		int minus = 0;
		for (int i = 1; i < H; i++) {
			for (auto j : edge[i]) {
				if (j.s < K&&j.f >= K) {
					minus = max(minus, score[goal[j.s]] - score[goal[j.f]]);
				}
				else if (j.s >= K&&j.f < K) {
					minus = max(minus, score[goal[j.f]] - score[goal[j.s]]);
				}
			}
		}
		cout << ans - minus << endl;
		cin >> N >> M >> H >> K;
	}
	return 0;
}

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

int main() {
  string s, t;
  cin >> s;
  int n = s.length();
  int ans = t.length();
  int a, z;
  for (int i = 0; i < n; i++) {
    if (s[i] == 'A') {
      a = i;
      break;
    }
  }
  for (int i = a; i < n; i++) {
    if (s[i] == 'Z') {
      z = i;
    }
  }
  cout << z - a + 1 << endl;
}


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

ll dd[1001][11][21];



int main() {

    for (int y=1; y<=1000; ++y) {
        for (int m=1; m<=10; ++m) {
            if (m == 1) {
                dd[y][m][0] = dd[y-1][10][20];
            }
            else {
                dd[y][m][0] = dd[y][m-1][20];
            }
            for (int d=1; d<=20; ++d) {
                if (y%3 == 0 or m%2) {
                    dd[y][m][d] = dd[y][m][d-1] + 1;
                }
                else {
                    if (d < 20) {
                        dd[y][m][d] = dd[y][m][d-1] + 1;
                    }
                    else {
                        dd[y][m][d] = dd[y][m][d-1];
                    }
                }
            }
        }
    }

    int n;
    cin >> n;
    rep(i, n) {
        int y, m, d;
        cin >> y >> m >> d;
        cout << dd[1000][1][1] - dd[y][m][d] << endl;
    }

    return 0;

}

Measured memory_bytes: 4884
#include<stdio.h>
int partition(int *,int,int);
#define N 100000
int main(){ 
  int n,arr[N];
  int i,num;
  scanf("%d",&n);
  for(i = 0;i < n;i++){
    scanf("%d",&arr[i]);
  }
  num = partition(arr,0,n-1);

for(i = 0;i < n-1;i++){
    if(i == num)printf("[%d] ",arr[i]);
    else printf("%d ",arr[i]);
  }
 
  printf("%d\n",arr[i]);
 

  return 0;
}

int partition(int* A, int p, int r){
  int x,i,j,k,n;  
  x = A[r];
  i = p-1;
  for (j = p;j < r;j++){
    if (A[j] <= x){
      i = i+1;
      k = A[i];
      A[i] = A[j];
      A[j] = k;
    }
  }
  k = A[r];
  A[r] = A[i+1];
  A[i+1] = k;
  return i+1;
}

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

using namespace std;

int main()
{
  int n;
  cin >> n;
  vector<int> v(n);
  for (int i = 0; i < n; i++) {
    cin >> v.at(i);
  }
  sort(v.begin(), v.end());
  cout << v.at(v.size()/2) - v.at(v.size()/2-1) << '\n';
  return 0;
}


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

// エラトステネスの篩 (正整数 n 以下の素数を調べる)
// 計算量: O(nloglogn)
// primes: n 以下の素数が入った vector
// is_prime: 各数字が素数かどうかのサイズ n+1 の vector
void sieve(int n, vector<int> &primes, vector<bool> &is_prime) {
    primes.clear();
    is_prime.resize(n+1, true);
    is_prime[0] = is_prime[1] = false;
    for(int i=2; i<=n; i++){
        if(is_prime[i]){
            primes.push_back(i);
            for(int j=2*i; j<=n; j+=i)
                is_prime[j] = false;
        }
    }
}

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

    vector<int> primes;
    vector<bool> is_prime;

    sieve(55555, primes, is_prime);
    vector<int> v;
    for(auto p : primes)
        if(p % 5 == 1)
            v.push_back(p);

    for(int i=0; i<N; i++)
        cout << v[i] << " ";
    cout << endl;
    return 0;
}


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

vector<int> G[MAX_V], TG;
int h[MAX_V] = {}, depth[MAX_V] = {};
queue<int> q;
int V, E;

// DAG : true, otherwise : false
bool topological_sort() {
    for (int i = 0; i < V; i++) {
        if (!h[i]) {
            q.push(i);
            depth[i] = 0;
        }
    }
    while (!q.empty()) {
        int s = q.front();
        q.pop();
        TG.push_back(s);
        for (int i = 0; i < G[s].size(); i++) {
            int t = G[s][i];
            h[t]--;
            if (!h[t]) {
                q.push(t);
                depth[t] = depth[s] + 1;
            }
        }
    }
    return (TG.size() == V);
}

int main() {
    int n, cnt = 0;
    cin >> n;
    map<int, int> mp;
    for (int i = 0; i < n; i++) {
        int a = -1, prea;
        for (int j = 0; j < n - 1; j++) {
            prea = a;
            cin >> a;
            a--;
            if (prea >= 0) {
                int n0, n1;
                int i0, i1, a0, a1;
                i0 = min(i, prea), a0 = max(i, prea);
                i1 = min(i, a), a1 = max(i, a);
                if (mp.find(n * i0 + a0) != mp.end()) {
                    n0 = mp[n * i0 + a0];
                } else {
                    n0 = cnt;
                    mp[n * i0 + a0] = cnt;
                    cnt++;
                }
                if (mp.find(n * i1 + a1) != mp.end()) {
                    n1 = mp[n * i1 + a1];
                } else {
                    n1 = cnt;
                    mp[n * i1 + a1] = cnt;
                    cnt++;
                }

                G[n0].push_back(n1);
                h[n1]++;
            }
        }
    }
    V = n * (n - 1) / 2;
    if (topological_sort()) {
        int ans = 0;
        for (int i = 0; i < V; i++) {
            ans = max(ans, depth[i] + 1);
        }
        cout << ans << endl;
    } else {
        cout << -1 << endl;
    }
    return 0;
}

Measured memory_bytes: 72564
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.ParseInt(sc.Text(), 10, 64)
	if e != nil {
		panic(e)
	}
	return int(i)
}

func nextLine() string {
	sc.Scan()
	return sc.Text()
}

func main() {
	n, b := nextInt(), nextInt()

	bl := int64(b)
	red := int64(n - b)
	sel := red + 1
	bsep := bl - 1

	cominit()

	for i := 1; i <= b; i++ {
		fmt.Println(combination(int(sel), i) * combination(int(bsep), i-1) % MOD)
	}
}

const MAX = 2001
const MOD = 1000000007

var fac, finv, inv [MAX]int

func cominit() {
	fac[0], fac[1] = 1, 1
	finv[0], finv[1] = 1, 1
	inv[1] = 1
	for i := 2; i < MAX; i++ {
		fac[i] = fac[i-1] * i % MOD
		inv[i] = MOD - inv[MOD%i]*(MOD/i)%MOD
		finv[i] = finv[i-1] * inv[i] % MOD
	}
}

// nCk
func combination(n, k int) int {
	if n < k {
		return 0
	}
	if n < 0 || k < 0 {
		return 0
	}
	return fac[n] * (finv[k] * finv[n-k] % MOD) % MOD
}


Measured memory_bytes: 640
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<cmath>
#include<ctime>
#include<cstdlib>
#define cmax(a,b) (a<(b)?a=(b),1:0)
#define cmin(a,b) (a>(b)?a=(b),1:0)
#define dmin(a,b) ((a)<(b)?(a):(b))
#define dmax(a,b) ((a)>(b)?(a):(b))
#define regsiter register
#define CL fclose(stdin),fclose(stdout)
namespace io
{
	int F()
	{
		int n=0,F=1;
		char ch;
		while((ch=getchar())!='-'&&(ch<'0'||ch>'9'));
		ch=='-'?F=0:n=ch-'0';
		while((ch=getchar())>='0'&&ch<='9')n=(n<<1)+(n<<3)+ch-'0';
		return F?n:-n;
	}
	long long G()
	{
		long long n=0,F=1;
		char ch;
		while((ch=getchar())!='-'&&(ch<'0'||ch>'9'));
		ch=='-'?F=0:n=ch-'0';
		while((ch=getchar())>='0'&&ch<='9')n=(n<<1)+(n<<3)+ch-'0';
		return F?n:-n;
	}
}
int a[111111];
int main()
{
	int k=io::F();
	for(register int i=1;i<=k;++i)a[i]=io::F();
	long long l=2,r=2;
	for(register int i=k;i;--i)
	{
		long long ll=(l+a[i]-1)/a[i]*a[i],rr=r/a[i]*a[i];
		if(ll>rr){puts("-1");return 0;}
		l=ll,r=rr+a[i]-1;
	}
	printf("%lld %lld\n",l,r);
	return 0;
}




Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
//解き方をすっかり忘れていました
int main(){
  int n;
  cin>>n;
  vector<tuple<string,int,int>>a;
  for(int i=0;i<n;i++){
    string s;
    int b;
    cin>>s>>b;
    a.emplace_back( s, -1*b, i+1 );
  }
  sort(a.begin(),a.end());
  
  for(int i=0;i<n;i++){
    cout<<get<2>(a[i])<<endl;
  }
  return 0;
}

Measured memory_bytes: 3536
import java.util.Scanner;

class Main{
        public static void main(String args[]){
                Scanner scan =new Scanner(System.in);
                int val=scan.nextInt();
                int h=val/3600;
                int m=(val-h*3600)/60;
                int s=val%60;
                System.out.println(h+":"+m+":"+s);
        }
}

Measured memory_bytes: 26312