akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <vector>
#include <utility>
#include <map>
#include <algorithm>
#include <queue>
#include <cmath>

using namespace std;

int main() {
	long long n,k,q;
	cin >> n >> k >> q;
	vector<long long> a(q);
	vector<long long> cnt(n,k);
	vector<string> ans(n, "No");

	for (long long i=0; i<q; i++)
		cin >> a[i];

	for (long long i=0; i<n; i++) 
		cnt[i] = cnt[i] - q;

	for (long long i=0; i<q; i++)
		cnt[a[i]-1]++;

	for (long long i=0; i<n; i++)
		if (cnt[i] > 0 )
			ans[i] = "Yes";

	for (long long i=0; i<n; i++)
		cout << ans[i] << endl;

	return 0;
}

Measured memory_bytes: 4480
import static java.lang.Integer.parseInt;

public class Main {
    public static void main (String[] args) {
        String line = new java.util.Scanner ( System.in ).nextLine();
        String[] number = line.split(" ", 0);
        int[] numbers;
        numbers = new int[3];

        // ???????????????
        for (int i = 0;i <= 2; i++ ) {
            numbers[i] = Integer.parseInt(number[i]);
        }
        int[] ans = Sort (numbers);
        
        System.out.println(ans[0] + " " + ans[1] + " " + ans[2]);
    }
    public static int[] Sort(int[] number) {
        int c;
        for (int i = 0; i < 2 ;i++) {
            for (int x = 1; x <= 2 ;x++) {
                if (number[i] > number[x]) {
                    c = number[i];
                    number[i] = number[x];
                    number[x] = c;
                }
            }
        }
        return number;
    }
}

Measured memory_bytes: 26008
//JI SRI KRISHNA.//
#include<iostream>
#include<algorithm>
using namespace std;
int main()
{
    int n,m,i;
    cin>>n>>m;
    string s[n];
    for(i=0;i<n;i++)
        cin>>s[i];
    sort(s,s+n);
    for(i=0;i<n;i++)
        cout<<s[i];
    cout<<endl;
}


Measured memory_bytes: 3636
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
typedef pair<int,int> P;
#define height first
#define position second

int p[1000];
P tmp[100000];
P info[200000];
int next[100000];
int dir[100000];
int prev[1000];
int fst[1000];
int u[1000];
int dp[2*100000];

int f(int pos){
	//cout << pos << " " << info[pos].position << " " << info[pos].height << endl;
	if(dp[pos] != -1) return dp[pos];
	if(next[pos^1] == -1) return info[pos^1].position;
	return dp[pos] = f(next[pos^1]);
}
int main(){
	int n,m,h,k;
	while(cin >> n >> m >> h >> k && n){
		for(int i = 0 ; i < n ; i++) cin >> p[i];
		for(int i = 0 ; i < m ; i++){
			int a,b;
			cin >> a >> b;
			a--;
			tmp[i] = P(b,a);
		}
		
		for(int i = 0 ; i < n ; i++) prev[i] = -1 , u[i] = 0;
		for(int i = 0 ; i < 2*m ; i++) next[i] = dp[i] = -1;
		sort(tmp,tmp+m);
		for(int i = 0 ; i < m ; i++){
			//cout << info[i].first << endl;
			info[i*2] = tmp[i];
			info[i*2+1] = tmp[i];
			info[i*2+1].second++;
		}

		for(int i = 0 ; i < 2*m ; i++){
			int p = info[i].second;
			//cout << i << " : " << info[i].first << " " << info[i].second << "<" << " " << prev[p] << " " << info[prev[p]].second << endl;
			if(prev[p] != -1) next[prev[p]] = i , prev[p] = i; else fst[p] = i , prev[p] = i;
		}
		int sum = 0;
		for(int i = 0 ; i < k ; i++) if(fst[i] != -1) sum += p[f(fst[i])] , u[f(fst[i])] = true ; else sum += p[i] , u[i] = true; 
		int minimum = sum;
		
		for(int i = 0 ; i < m ; i++){
			int X = f(i*2);
			int Y = f(i*2+1);
			if(u[X]^u[Y]){
				minimum = min( minimum , sum + p[X]*(u[X]?-1:1) + p[Y]*(u[Y]?-1:1) ); 
			}
		}
		cout << minimum << endl;
		
	}
	
}

Measured memory_bytes: 4792
#include<cstdio>
#include<vector>
#include<algorithm>
using namespace std;

int N; char str[1 << 8 | 1];
vector < int > pot;
vector < int > operator +(vector < int > p , vector < int > q){p.insert(p.end() , q.begin() , q.end()); return p;}

vector < int > build(int id , int x){
	if(id < (1 << (x + 1))) return vector < int >{x + 1 , -x - 1};
	vector < int > tmp = build(id , x + 1);
	if(!(id >> x & 1)) return vector < int >{x + 1} + tmp + vector < int >{x + 1};
	vector < int > rev = tmp; reverse(rev.begin() , rev.end());
	return vector < int >{x + 1} + tmp + vector < int >{x + 1} + vector < int >{-x - 1} + rev + vector < int >{-x - 1};
}

int main(){
	scanf("%d %s" , &N , str);
	for(int i = 0 ; i < 1 << N ; ++i)
		if(str[i] == '1')
			for(int j = 0 ; j < N ; ++j)
				if((i >> j & 1) && str[i ^ (1 << j)] != '1'){
					puts("Impossible"); return 0;
				}
	for(int i = 0 ; i < 1 << N ; ++i)
		if(str[i] == '0'){
			bool flg = 1;
			for(int j = 0 ; j < N ; ++j)
				if((i >> j & 1) && str[i ^ (1 << j)] == '0')
					flg = 0;
			if(flg) pot = pot + build(i , 0);
		}
	puts("Possible"); vector < pair < int , int > > node;
	int curx = 0 , cury = 0; node.push_back(make_pair(0 , 0));
	for(int i = 0 ; i < pot.size() ; ++i){
		if(pot[i] < 0 && cury == 1) node.push_back(make_pair(curx , cury = 0));
		if(pot[i] > 0 && cury == 0) node.push_back(make_pair(curx , cury = 1));
		int t = abs(pot[i]) - 1;
		if(curx == t) node.push_back(make_pair(++curx , cury));
		else node.push_back(make_pair(--curx , cury));
	}
	if(cury) node.push_back(make_pair(0 , 0));
	printf("%d\n" , node.size() - 1);
	for(auto t : node) printf("%d %d\n" , t.first , t.second);
	return 0;
}


Measured memory_bytes: 512
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
string s;
int n;
vector<pair<string,string> >va,vb;
ll sol;
int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);cout.tie(NULL);
	cin>>n>>s;
	for(int i=0;i<(1<<n);i++){
		string p,q;
		for(int j=0;j<n;j++){
			if(i&(1<<j)){
				p+=s[j];
			}
		}
		for(int j=n-1;j>=0;j--){
			if(i&(1<<j)) continue;
			q+=s[j];
		}
		va.push_back(make_pair(p,q));
	}
	for(int i=0;i<(1<<n);i++){
		string p,q;
		for(int j=0;j<n;j++){
			if(i&(1<<j)){
				p+=s[n+j];
			}
		}
		for(int j=n-1;j>=0;j--){
			if(i&(1<<j)) continue;
			q+=s[n+j];
		}
		vb.push_back(make_pair(q,p));
	}
	sort(va.begin(),va.end());
	sort(vb.begin(),vb.end());
	for(int i=0;i<va.size();i++){
		int a=lower_bound(vb.begin(),vb.end(),va[i])-vb.begin();
		int b=upper_bound(vb.begin(),vb.end(),va[i])-vb.begin();
		if(a<vb.size()&&vb[a]==va[i]){
			sol+=b-a;
		}
	}
	cout<<sol<<"\n";
	return 0;
}

Measured memory_bytes: 69356
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define mod 1000000007

int main(){
	
	string s;
	cin >> s;
	int count = 0, mx = 0;
	for(int i = 0; i < 3; ++i){
		if(s[i] == 'R'){
			count++;
		}
		else{
			mx = max(count, mx);
			count = 0;
		}
	}
	mx = max(count, mx);
	cout << mx << '\n';
	return 0;
}

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

int main(){
  int A ,B ,C , D;
  cin >> A >> B >> C >> D;
  int left, right;
  left = A + B;
  right = C + D;
  if(left > right)
    cout << "Left" <<  endl;
  else if(left < right)
    cout << "Right" << endl;
  else
    cout << "Balanced" << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
using namespace std;
#define rep(i, a, n) for (int i = a; i < n; i++)
#define per(i, a, n) for (int i = n - 1; i >= a; i--)
#define mp make_pair
#define fi first
#define se second
#define SZ(x) ((int)(x).size())
#define lli long long int
#define pii pair<int, int>
#define vii vector<pii>
#define pb push_back
#define eb emplace_back
#define em emplace
#define all(v) v.begin(), v.end()
#define mod 1000000007
#define vi vector<int>
#define vl vector<lli>
#define vll vector<pair<lli, lli>>
#define pll pair<lli, lli>
#define vvi vector<vector<int>>
#define vvl vector<vector<lli>>
#define error(args...)                           \
	{                                            \
		string _s = #args;                       \
		replace(_s.begin(), _s.end(), ',', ' '); \
		stringstream _ss(_s);                    \
		istream_iterator<string> _it(_ss);       \
		err(_it, args);                          \
	}
#define tk(args...) take(args);
#define posLSB(X) __builtin_ctz(X)
#define num1bit(X) __builtin_popcount(X)
#define numlead0(X) __builtin_clz(X)
#define umreserve(X)  \
	X.reserve(32768); \
	X.max_load_factor(0.25);
void err(istream_iterator<string> it)
{
}
template <typename T, typename... Args>
void err(istream_iterator<string> it, T a, Args... args)
{
	cout << *it << " = " << a << "\n";
	err(++it, args...);
}
void take() {}
template <typename T, typename... Args>
void take(T &a, Args &... args)
{
	cin >> a;
	take(args...);
}
template <class T>
void printvec(vector<T> &a)
{
	for (T &x : a)
	{
		cout << x << " ";
	}
	cout << endl;
}
template <class T>
void printarr(T a[], lli n)
{
	for (lli i = 0; i < n; i++)
	{
		cout << a[i] << " ";
	}
	cout << endl;
}
struct HASH
{
	size_t operator()(const pair<int, int> &x) const
	{
		return (size_t)x.first * 37U + (size_t)x.second;
	}
};

#define endl "\n"

lli add(lli a, lli b)
{
	a += b;
	if (a >= mod)
		a -= mod;
	return a;
}

lli mul(lli a, lli b)
{
	return a * 1ll * b % mod;
}

inline bool setmin(lli &x, lli y) { return (y < x) ? x = y, 1 : 0; }
inline bool setmax(lli &x, lli y) { return (y > x) ? x = y, 1 : 0; }

lli power_mod(lli a, lli x)
{
	if (x == 0)
		return 1;
	lli y = power_mod(a, x / 2);
	lli ans = (y * y) % mod;
	if (x % 2)
		ans = (ans * a) % mod;
	return ans;
}
lli inv(lli a) { return power_mod(a, mod - 2); }
lli power(lli a, lli x)
{
	if (x == 0)
		return 1;
	lli y = power(a, x / 2);
	lli ans = (y * y);
	if (x % 2)
		ans *= a;
	return ans;
}

int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	lli n,W;
	cin>>n>>W;
	vector<lli> w(n),v(n);
	for(lli i=0;i<n;i++)cin>>w[i]>>v[i];
	vector<vector<lli>> dp(n,vector<lli>(1e5+5,INT_MAX));
	dp[0][v[0]]=w[0];
	dp[0][0]=0;
	for(lli i=1;i<n;i++){
		for(lli j=0;j<1e5+5;j++){
			lli jj=j-v[i];
			dp[i][j]=dp[i-1][j];
			if(jj>=0&&dp[i-1][jj]!=INT_MAX)
				dp[i][j]=min(dp[i-1][j],dp[i-1][jj]+w[i]);
			
		}
	}
	for(lli val=1e5+4;val>=0;val--){
		if(dp[n-1][val]<=W){
			cout<<val<<endl;
			return 0;
		}
	}


}

Measured memory_bytes: 79488
from collections import Counter
import sys
input = sys.stdin.readline

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

c = Counter(a)

if c[0] == n:
    print("Yes")
elif len(c) == 2 and c[0]*3 == n:
    print("Yes")
elif len(c) == 3 and len(set(c.values())) == 1:
    a, b, c = c.keys()
    if (a ^ b ^ c) == 0:
        print("Yes")
    else:
        print("No")
else:
    print("No")


Measured memory_bytes: 20356
#include<iostream>
#include<cmath>
#include<cstdlib>
#include<string>
#include<cstring>
#include<algorithm>
#include<vector>
#include<bitset>

using namespace std;

int main() {
   int N;
   cin >> N;
   int A[N];
   int sum = 0;
   bitset <4000001> dp;
   dp[0] = 1;
   for (int i = 0; i < N; i++) {
      cin >> A[i];
      sum += A[i];
      dp |= (dp << A[i]);
   }
   
   for (int i = (sum + 1) / 2; i <= sum; i++) {
      if (dp[i]) {
         cout << i << endl; 
         return 0;
      }
   }
}


Measured memory_bytes: 1664
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        // 入力受付
        Scanner scan = new Scanner(System.in);
        int n = scan.nextInt();

        for (int i = 1; i <= 9; i++) {
            for (int j = 1; j <= 9; j++) {
                if (i * j == n) {
                    System.out.println("Yes");
                    return;
                }
            }
        }

        System.out.println("No");

    }

}


Measured memory_bytes: 23892
#include <iostream>
#include <vector>
#include <queue>
#include <map>
#include<numeric>
using namespace std;
#define rep(i,n) for(int i=0; i<(n);i++)
typedef long long ll;


int main(){
    int a, b; cin >> a >> b;
    cout << a*b << ' ' << 2*a + 2*b << endl;
	return 0;
}



Measured memory_bytes: 3084
#include<bits/stdc++.h>
using namespace std;
int main(){
    int n,m;
    cin >> n >> m;
    int x[m];
    int y[m];
    vector<bool>red(n+1,false);
    red[1] = true;
    vector<int>balls(n+1,1);
    for(int i=0;i<m;i++){
        cin >> x[i] >> y[i];
    }
    for(int i=0;i<m;i++){
        balls[x[i]]--;
        balls[y[i]]++;;
        if(red[x[i]])red[y[i]] = true;
        if(balls[x[i]]==0)red[x[i]]=false;
    }
    int ans = 0;
    for(int i=1;i<=n;i++)if(red[i])ans++;
    cout << ans << endl;
}

Measured memory_bytes: 1408
import java.util.Scanner;

class Main{



	public static void main(String[] args) {


		Scanner sc = new Scanner(System.in);			//文字の入力
		int N = sc.nextInt();
		int ans = 0;
		int numans = 0;

		for(int i = 1;i <= N;i++){
			int sum = counttwo(i);
			ans = Math.max(ans, sum);
			if(sum == ans){
				numans = i;
			}

		}

		System.out.println(numans);


	}

	static int counttwo(int num){					//2で割れる回数をカウント
		int count = 0;
		while(num % 2 == 0){
			count++;
			num /= 2;

		}
		return count;
	}

}




Measured memory_bytes: 21716
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
#define INF (1<<30)
#define INFLL (1ll<<60)
typedef pair<int, int> P;
typedef pair<int, P> E;
#define gt first
#define gc second.first
#define gr second.second
#define MOD (1000000007ll)
#define l_ength size
#define PI 3.14159265358979

void mul_mod(ll& a, ll b){
	a *= b;
	a %= MOD;
}

void add_mod(ll& a, ll b){
	b += MOD;
	a += b;
	a %= MOD;
}

int ufr[2][225816],ufp[2][225816];

void ufinit(int n, int t){
	int i;
	for(i=0; i<n; ++i){
		ufr[t][i] = 0;
		ufp[t][i] = i;
	}
}

int ufind(int x, int t){
	if(x == ufp[t][x]){
		return x;
	}
	ufp[t][x] = ufind(ufp[t][x],t);
	return ufp[t][x];
}

void unionf(int x, int y, int t){
	x = ufind(x, t);
	y = ufind(y, t);
	if(ufr[t][x] < ufr[t][y]){
		ufp[t][x] = y;
	}else{
		ufp[t][y] = x;
	}
	if(ufr[t][x] == ufr[t][y]){
		++ufr[t][x];
	}
}

vector<ll> v;
ll g[225816];

int main(void){
	int k[2],i,j,n,p,q;
	cin >> n >> k[0] >> k[1];
	for(j=0; j<2; ++j){
		ufinit(n,j);
		for(i=0; i<k[j]; ++i){
			cin >> p >> q;
			--p; --q;
			unionf(p,q,j);
		}
	}
	for(i=0; i<n; ++i){
		g[i] = (ll)(ufind(i,0))*(ll)(n)+(ll)(ufind(i,1));
		v.push_back(g[i]);
	}
	sort(v.begin(),v.end());
	for(i=0; i<n; ++i){
		cout << ((i)?" ":"") << ((int)(upper_bound(v.begin(),v.end(),g[i])-lower_bound(v.begin(),v.end(),g[i])));
	}
	cout << endl;
	return 0;
}


Measured memory_bytes: 7280
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <string>
#include <set>
#include <utility>
#include <cstdlib>
#include <queue>

using namespace std;


int max_value = -1000007;

int main(){
    int n,k;
    cin >> n >> k;
    vector<int> v(n);
    for(int i = 0; i < n; i++) cin >> v[i];
    int ans = 0;

    for(int l = 0; l <= k; l++){
        if (l > n) break;
        vector<int> v1;
        int sum1 = 0;
        for(int i = 0; i < l; i++){
            sum1 += v[i];
            if(v[i] < 0) v1.push_back(v[i]);
        }
        for(int r = 0; r <= k; r++){
            if(l+r > k || r > n || n - l < r) break;
            vector<int> v2;
            int sum2 = sum1;
            for(int i = n-1; i >= n-r; i--){
                sum2 += v[i];
                if(v[i] < 0) v2.push_back(v[i]);
            }
            copy(v1.begin(), v1.end(), back_inserter(v2));
            sort(v2.begin(), v2.end());
            for(int i = 0; i < k - l - r && i < v2.size(); i++){
                sum2 += -v2[i];
            }
            ans = max(ans, sum2);
        }
    }

    cout << ans << endl;

    return 0;
}



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

string s;
long long a[6][100010];
int n;
long long ans;
long long mod = 1e9+7;

long long memo[100010];

long long func(long long t){
	if(t == 0) return memo[t] = 1;
	if(memo[t] > 0) return memo[t];
	return memo[t] = (3 * func(t-1)) % mod;
}

int main(){
//	cin.tie(0);
//	ios::sync_with_stdio(false);
	cin >> s;
	n = s.size();
	for(int i=0; i<n; ++i){
		if(s[i] == 'A'){
			++a[0][i+1];
			++a[1][i+1];
		}else if(s[i] == 'C'){
			++a[2][i+1];
			++a[3][i+1];
		}else if(s[i] == '?'){
			++a[4][i+1];
			++a[5][i+1];
		}
	}
	for(int i=0; i<3; ++i)
		for(int j=1; j<=n; ++j)
			a[2*i][j+1] += a[2*i][j];
	for(int i=0; i<3; ++i)
		for(int j=n; j>=1; --j)
			a[2*i+1][j] += a[2*i+1][j+1];
//	for(int i=0; i<6; ++i)
//		for(int j=0; j<n+2; ++j)
//			cout << a[i][j] << (j==n+1?"\n":" ");
	for(int i=0; i<n; ++i)
		if(s[i] == 'B' || s[i] == '?'){
			long long l = 0, r = 0;
			if(a[4][i] > 0) l += a[4][i] * func(a[4][i]-1);
			l %= mod;
			l += a[0][i] * func(a[4][i]);
			l %= mod;
			if(a[5][i+2] > 0) r += a[5][i+2] * func(a[5][i+2]-1);
			r %= mod;
			r += a[3][i+2] * func(a[5][i+2]);
			r %= mod;
			ans += (l * r) % mod;
			ans %= mod;
		}
	cout << ans << "\n";
}

Measured memory_bytes: 7552
#!/usr/bin/ruby

M = 400

gets.to_i.times do |_|
  n = gets.to_i
  e = gets.chomp.split(" ").map {|x| x.to_i}

  dp = Array.new n
  n.times {|i| dp[i] = Array.new M,0 }

  dp[0][0] = e[0]
  for i in 1...n
    dp[i][e[i-1]] = e[i]
  end

  for i in 2...n
    for b in 0...M
      c = dp[i-1][b]
      dp[i][c] = [dp[i][c], e[i]].max
      if c > 0
        dp[i][c-1] = [ dp[i][c-1], b + e[i] ].max
      end
    end
  end

  puts dp[n-1].max

end

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

using lint = long long;
template <typename T> using V = vector<T>;
template <typename T> using VV = vector<vector<T>>;
#define rep(i, n) for(int i = 0; i < int(n); i++)
#define repu(i, a, b, s) for(int i = int(a); i < int(b); i += int(s))
#define repd(i, a, b, s) for(int i = int(a); i > int(b); i += int(s))
#define endl "\n"
constexpr lint INF = 2e18;
constexpr lint MOD = 1e9 + 7;

lint grid[10000][10000];
lint dp[3001][3001][4];

void solve() {
    lint R, C, K;
    cin >> R >> C >> K;

    rep(i, R) {
        rep(j, C) { grid[i][j] = -1; }
    }

    rep(i, K) {
        lint r, c, v;
        cin >> r >> c >> v;
        r--;
        c--;
        grid[r][c] = v;
    }

    rep(y, R) {
        rep(x, C) {
            rep(i, 4) { dp[y][x][i] = 0; }
        }
    }

    if(grid[0][0] != -1)
        dp[0][0][1] = grid[0][0];

    rep(y, R) {
        rep(x, C) {

            // 選ばない
            if(0 <= y - 1) {
                rep(i, 4) { dp[y][x][0] = max(dp[y][x][0], dp[y - 1][x][i]); }
            }
            if(0 <= x - 1) {
                rep(i, 4) { dp[y][x][i] = max(dp[y][x][i], dp[y][x - 1][i]); }
            }

            // 選ぶ
            if(grid[y][x] != -1) {
                if(0 <= y - 1) {
                    rep(i, 4) {
                        dp[y][x][1] =
                            max(dp[y][x][1], dp[y - 1][x][i] + grid[y][x]);
                    }
                }
            }
            if(0 <= x - 1) {
                repu(i, 1, 4, 1) {
                    dp[y][x][i] =
                        max(dp[y][x][i], dp[y][x - 1][i - 1] + grid[y][x]);
                }
            }
        }
    }

    lint ans = -INF;
    rep(i, 4) { ans = max(ans, dp[R - 1][C - 1][i]); }
    cout << ans << endl;
}

int main() {
    std::cin.tie(nullptr);
    std::ios_base::sync_with_stdio(false);
    std::cout << std::fixed << std::setprecision(15);
    solve();
    return 0;
}


Measured memory_bytes: 366964
#include<stdio.h>
#include<iostream>
#include<algorithm>
#include<string>
#include<string.h>
#include<math.h>
#include<stdlib.h>
#include<vector>
#include<queue>
#include<map>
#include<tuple>
#define rep(index,num) for(int index=0;index<num;index++)
#define rep1(index,num) for(int index=1;index<=num;index++)
#define scan(argument) cin>>argument
#define prin(argument) cout<<argument<<endl
#define kaigyo cout<<endl
#define eps 1e-15
#define mp(a1,a2) make_pair(a1,a2)
typedef long long ll;
using namespace std;
typedef pair<ll,ll> pll;
typedef pair<int,int> pint;
typedef vector<int> vint;
typedef vector<ll> vll;
typedef vector<pint> vpint;
typedef vector<pll> vpll;
ll INFl=1e+18+1;
int INF=1e+9+1;
ll gcd(ll x, ll y)
{
    ll r;

    if(x == 0 || y == 0)
    {
        return 0;
    }
    while((r = x % y) != 0)
    {
        x = y;
        y = r;
    }
    return y;
}
int main(){
	int N,X;
	int x[100001];
	int kyori[100001];
	scan(N);scan(X);
	rep(i,N){
		scan(x[i]);
		kyori[i]=abs(X-x[i]);
	}
	ll maxD=kyori[0];
	rep1(i,N-1){
		maxD=gcd(maxD,(ll)kyori[i]);
	}
	prin(maxD);

	return 0;
}


Measured memory_bytes: 1024
import sys
input = sys.stdin.readline
ri = lambda: int(input())
rl = lambda: [int(x) if x.isdecimal() else x for x in input().split()]
rl = lambda: [int(x) for x in input().split()]
rr = lambda N: [list(l) for l in zip(*[rl() for _ in range(N)])]
YN = lambda b: print('YES') if b else print('NO')
yn = lambda b: print('Yes') if b else print('No')
OE = lambda x: print('Odd') if x%2 else print('Even')
INF = 10**18
MOD = 10**9+7


N,Q=rl()
TT = []
now = set()
for _ in range(N):
    s,t,x = rl()
    TT.append((s-x-0.5,1,x))
    TT.append((t-x-0.5,-1,x))
for i in range(Q):
    d = ri()
    TT.append((d,0,i))


TT.sort()
mx = INF
mx_f = False
ans = [-1]*Q
for st,w,x in TT:
    if w > 0:
        now.add(x)
        if mx > x:
            mx = x
            mx_f = True
    elif w < 0:
        now.remove(x)
        if mx == x:
            mx_f = False
    elif len(now) > 0:
        if not mx_f:
            mx = min(now)
            mx_f = True
        ans[x] = mx
print(*ans,sep='\n')

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

int main(void) {
    int N, M;
    cin >> N >> M;
    vector< int > A(N);
    for (int i = 0; i < N; i++) {
        cin >> A[i];
    }
    int count = 0, sum = 0;
    for (int i = 0; i < N; i++) {
        sum += A[i];
    }
    for (int i = 0; i < N; i++) {
        if (4 * M * A[i] >= sum) {
            ++count;
        }
    }
    if (count >= M) {
        printf("Yes\n");
    } else {
        printf("No\n");
    }
    return 0;
}


Measured memory_bytes: 256
#!usr/bin/env python3
from collections import defaultdict
from collections import deque
from heapq import heappush, heappop
import sys
import math
import bisect
import random
def LI(): return list(map(int, sys.stdin.readline().split()))
def I(): return int(sys.stdin.readline())
def LS():return list(map(list, sys.stdin.readline().split()))
def S(): return list(sys.stdin.readline())[:-1]
def IR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = I()
    return l
def LIR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = LI()
    return l
def SR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = S()
    return l
def LSR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = LS()
    return l
sys.setrecursionlimit(1000000)
mod = 1000000007

#A
def A():
    e = LI()
    d = defaultdict(int)
    for i in e:
        d[i] += 1
    for i in d.values():
        if i != 2:
            print("no")
            break
    else:
        print("yes")
    return

#B
def B():
    return

#C
def C():
    return

#D
def D():
    return

#E
def E():
    return

#F
def F():
    return

#G
def G():
    return

#H
def H():
    return

#I
def I_():
    return

#J
def J():
    return

#Solve
if __name__ == "__main__":
    A()



Measured memory_bytes: 8240
package main

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

var bufin *bufio.Reader
var bufout *bufio.Writer

func max(a, b int) int {
	if a < b {
		return b
	}
	return a
}
func main() {
	bufin = bufio.NewReader(os.Stdin)
	bufout = bufio.NewWriter(os.Stdout)
	defer bufout.Flush()
	var W, H, N int
	fmt.Fscanf(bufin, "%d %d %d\n", &W, &H, &N)
	var X = []int{0, W}
	var Y = []int{0, H}
	for i := 0; i < N; i++ {
		var x, y, a int
		fmt.Fscanf(bufin, "%d %d %d\n", &x, &y, &a)
		switch a {
		case 1:
			if X[0] < x {
				X[0] = x
			}
		case 2:
			if X[1] > x {
				X[1] = x
			}
		case 3:
			if Y[0] < y {
				Y[0] = y
			}
		case 4:
			if Y[1] > y {
				Y[1] = y
			}
		}
	}
	var ans = max(X[1]-X[0], 0) * max(Y[1]-Y[0], 0)
	fmt.Fprintf(bufout, "%d\n", ans)
}


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

int main(){
    int a, b;
    cin >> a >> b;
    if(a - (b * 2) > 0){
        cout << a - (b * 2) << endl;
    }else{
        cout << 0 << endl;
    }
    return 0;
}

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

constexpr int inf = 0x3f3f3f3f;
constexpr ll linf = 0x3f3f3f3f3f3f3f3fLL;

template <ll mod>
class modint
{
public:
    constexpr modint(ll value = 0) : _value(value >= 0 ? value % mod : (value % mod) + mod) {}

    constexpr modint operator+() const { return *this; }
    constexpr modint operator-() const { return modint(-_value); }

    constexpr modint &operator+=(const modint &rhs) {
        if ((_value += rhs._value) >= mod) _value -= mod;
        return *this;
    }
    constexpr modint &operator-=(const modint &rhs) {
        if ((_value += mod - rhs._value) >= mod) _value -= mod;
        return *this;
    }
    constexpr modint &operator*=(const modint &rhs) {
        (_value *= rhs._value) %= mod;
        return *this;
    }
    constexpr modint &operator/=(const modint &rhs) {
        *this *= rhs.inv();
        return *this;
    }
    constexpr modint operator+(const modint &rhs) const { return modint(*this) += rhs; }
    constexpr modint operator-(const modint &rhs) const { return modint(*this) -= rhs; }
    constexpr modint operator*(const modint &rhs) const { return modint(*this) *= rhs; }
    constexpr modint operator/(const modint &rhs) const { return modint(*this) /= rhs; }

    constexpr modint operator++() { *this += 1; return *this; }
    constexpr modint operator--() { *this -= 1; return *this; }
    constexpr modint operator++(int) { modint tmp = *this; ++*this; return tmp; }
    constexpr modint operator--(int) { modint tmp = *this; --*this; return tmp; }

    constexpr bool operator==(const modint &rhs) const { return _value == rhs._value; }
    constexpr bool operator!=(const modint &rhs) const { return _value != rhs._value; }

    constexpr modint inv() const {
        ll a = _value, b = mod, u = 1LL, v = 0LL;
        while (b > 0) {
            ll tmp = a / b;
            a -= tmp * b; swap(a, b);
            u -= tmp * v; swap(u, v);
        }
        return modint(u);
    }

    constexpr modint pow(ll n) const {
        modint e = *this, res = 1;
        while (n) {
            if (n & 1) res *= e;
            e *= e, n >>= 1;
        }
        return res;
    }

    friend ostream &operator<<(ostream &os, const modint &m) {
        os << m._value;
        return os;
    }

    friend istream &operator>>(istream &is, modint &m) {
        ll in;
        is >> in;
        m = modint(in);
        return is;
    }

private:
    ll _value;
};
using mint = modint<1000000007>;

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

    int s; cin >> s;

    int n = s / 3;
    vector<vector<mint>> dp(n + 1, vector<mint>(s + 1, 0));
    dp[0][0] = 1;

    for (int i = 0; i < n; i++) {
        for (int j = 0; j < s - 2; j++) {
            dp[i + 1][j + 3] += dp[i][j];
        }
        for (int j = 0; j < s; j++) {
            dp[i + 1][j + 1] += dp[i + 1][j];
        }
    }

    mint ans = 0;
    for (int i = 1; i <= n; i++) {
        ans += dp[i][s];
    }

    cout << ans << endl;

    return 0;
}


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

int ctoi(char c) {
  switch (c) {
    case '0': return 0;
    case '1': return 1;
    case '2': return 2;
    case '3': return 3;
    case '4': return 4;
    case '5': return 5;
    case '6': return 6;
    case '7': return 7;
    case '8': return 8;
    case '9': return 9;
    default: return 0;
  }
}     

int main() {

  string N, n;
  cin >> N;
  
  int P = std::stoi(N);  // string型 => int型
  int Q = 0, M = 0;
  
  for (int i = 0; i < N.size(); i++) {

    Q = ctoi(N.at(i));
    M += Q;
  }
  
  if (P % M == 0) {
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }
}

Measured memory_bytes: 256
import java.util.Scanner;
import java.util.List;
import java.util.ArrayList;
import java.util.Comparator;
import java.util.Arrays;
import java.util.Collections;
import java.util.*;
class Main{
  public static void main(String[] args){
    Scanner scan = new Scanner(System.in);
    String a = scan.next();
    String[] al = {"a","b","c","d","e","f","g","h","i","j","k","l","m","n","o","p","q","r","s","t","u","v","w","x","y","z"};
    for (int i = 0;i < 26;i++) {
      if (a.equals(al[i])) {
        System.out.println("a");
        return;
      }  
    }
    System.out.println("A");
  }
}


Measured memory_bytes: 35644
#include "bits/stdc++.h"
using namespace std;
#define ll long long int
#define rep(i,n) for( int i = 0; i < n; i++ )
#define rrep(i,n) for( int i = n; i >= 0; i-- )
#define REP(i,s,t) for( int i = s; i <= t; i++ )
#define RREP(i,s,t) for( int i = s; i >= t; i-- )
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define INF 2000000000
#define mod 1000000007
#define INF2 1000000000000000000

bool dp[100010][4][4][4];
string S[100010];
int N, A, B, C;
bool calc(int x, int a, int b, int c) {
    //cout << x << " " << a << " " << b << " " << c << endl;
    if(x >= N) return dp[x][a][b][c] = true;
    if(S[x] == "AB") {
        if(a > 0) if(calc(x + 1, a - 1, b + 1, c)) return dp[x][a][b][c] = true;
        if(b > 0) if(calc(x + 1, a + 1, b - 1, c)) return dp[x][a][b][c] = true;
    }else if (S[x] == "BC") {
        if(b > 0) if(calc(x + 1, a, b - 1, c + 1)) return dp[x][a][b][c] = true;
        if(c > 0) if(calc(x + 1, a, b + 1, c - 1)) return dp[x][a][b][c] = true;
    } else if(S[x] == "AC") {
        if(c > 0) if(calc(x + 1, a + 1, b, c - 1)) return dp[x][a][b][c] = true;
        if(a > 0) if(calc(x + 1, a - 1, b, c + 1)) return dp[x][a][b][c] = true;
    }
    return false;
}

void calc2(int x, int a, int b, int c) {
    if (x >= N) return;
    if(S[x] == "AB") {
        if(a > 0) if(dp[x + 1][a - 1][b + 1][c]) {
            cout << "B" << endl;
            calc2(x + 1, a - 1, b + 1, c);
            return;
        } 
        if(b > 0) if(dp[x + 1][a + 1][b - 1][c]) {
            cout << "A" << endl;
            calc2(x + 1, a + 1, b - 1, c);
            return;
        } 
    }else if (S[x] == "BC") {
        if(b > 0) if(dp[x + 1][a][b - 1][c + 1]) {
            cout << "C" << endl;
            calc2(x + 1, a, b - 1, c + 1);
            return;
        } 
        if(c > 0) if(dp[x + 1][a][b + 1][c - 1]) {
            cout << "B" << endl;
            calc2(x + 1, a, b + 1, c - 1);
            return;
        } 
    } else if(S[x] == "AC") {
        if(c > 0) if(dp[x + 1][a + 1][b][c - 1]) {
            cout << "A" << endl;
            calc2(x + 1, a + 1, b, c - 1);
            return;
        } 
        if(a > 0) if(dp[x + 1][a - 1][b][c + 1]) {
            cout << "C" << endl;
            calc2(x + 1, a - 1, b, c + 1);
            return;
        } 
    }
}

signed main(void)
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    cin >> N >> A >> B >> C;
    rep(i, N) cin >> S[i];
    A = min(3, A);
    B = min(3, B);
    C = min(3, C);
    if(calc(0, A, B, C)) {
        cout << "Yes" << endl;
        calc2(0, A, B, C);
    } else {
        cout << "No" << endl;
    }



    return 0;
}


Measured memory_bytes: 19268
#include<bits/stdc++.h> 
using namespace std;
int main(int args, char** argv){
  vector<int>arr(3);
  for(int i=0;i<3;i++){
    cin>>arr[i];
  }
  int li=0;
  int hi=arr.size()-1;
  int temp=arr[li];
  arr[li]=arr[hi];
  arr[hi]=arr[1];
  arr[1]=temp;
  for(int val:arr){
    cout<<val<<" ";  
  }
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <vector>
#include <functional>

/*The function calculates vegetables which you purchase.*/
int purchase_price(const int n,const int m) {

	//The price of purchased vegetables
	std::vector<int> purchase;

	//input
	for (int i = 0; i < n; ++i){
		int tmp;
		std::cin >> tmp;
		purchase.push_back(tmp);
	}

	//descending sort (higher price)
	std::sort(purchase.begin(), purchase.end(), std::greater<int>());

	int sum = 0;

	//surplus eqals to (m-1) is free
	for (int i = 0; i < n; ++i){
		if (i%m != m-1) {
			sum += purchase.at(i);
		}
	}

	return sum;

}


int main() {

	//n:the number of purchase vegetables
	//m:the number of you can stuff vegetables
	int n, m;
	//sum of price
	int sum;

	while (true) {

		std::cin >> n >> m;

		//case of input is (n,m)=(0,0)
		if (n == 0 && m == 0) {
			break;
		}

		sum = purchase_price(n, m);
		std::cout << sum << std::endl;
	}

	return 0;
}

Measured memory_bytes: 3084
#include<iostream>
using namespace std;
int main(){
  int n;
  int array[200005]={0};
  cin>>n;
  for(int i=0;i<n-1;i++){
    int num;
    cin>>num;
    array[num-1]++;
  }
  for(int i=0;i<n;i++){
    cout<<array[i]<<endl;
  }
  return(0);
}

Measured memory_bytes: 4408
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace std;
using namespace __gnu_pbds;
 
#define int long long
#define ll long long
#define vi vector <int>
#define vii vector <pair<int,int> >
#define rep(i,a,b) for (int i=a;i<b;i++)
#define repD(i,a,b) for (int i=a;i>b;i--)
#define pb push_back
#define pii pair <int,int>
#define ff first
#define ss second
#define all(a) a.begin(),a.end()
#define MOD 1000000007
#define PI 3.14159265359

typedef tree<int,null_type,less<int>,rb_tree_tag, tree_order_statistics_node_update> ordered_set;
///*X.find_by_order("index")
///X.order_of_key("key")
 
#define deb(x) {x}
#ifndef local
	#define deb(x) ;
#endif
 
 
///----------------------------------------------------------------------------------

int n,m;
vi adj[5005];
int vis[5005];
map<int,vi> cycles;
vi result;

void bfs(int so)
{
	int par[5005];
	memset(par,-1,sizeof par);
	
	
	queue<int> Q;
	Q.push(so);
	
	while(!Q.empty())
	{
		int te=Q.front();Q.pop();
		
		for (auto x:adj[te])
		{
			if (x == so)
			{
				int cur = te;
				while(cur != -1)
				{
					result.pb(cur);
					cur = par[cur];
				}
				
				return;
			}
			if (vis[x])continue;
			par[x] = te;
			vis[x]++;
			Q.push(x);
		}
	}
}

void solve()
{
	cin>>n>>m;
	int u,v;
	rep(i,0,m)cin>>u>>v,adj[u-1].pb(v-1);
	
	rep(i,0,n)
	{
		memset(vis,0,sizeof vis);
		result.clear();
		bfs(i);
		
		if (result.size())cycles[result.size()] = result;
	}
	
	if (cycles.empty())cout<<-1;
	else 
	{
		cout<<cycles.begin()->ff<<"\n";
		for (auto x:cycles.begin()->ss)cout<<x+1<<"\n";
	}
	
}



signed main()
{
	ios_base::sync_with_stdio(false);cin.tie(NULL);
 	
 	#ifdef local
	//freopen("input.txt","r",stdin);
	//freopen("output.txt","w",stdout);
	clock_t qwertyuiop = clock();
	#endif
 
	int t=1;
//	cin>>t;
    
	rep(a,0,t)
	{
		///cout<<"Case #"<<a+1<<": ";
		solve();
	}
	
	#ifdef local
	{qwertyuiop = clock() - qwertyuiop;double time_taken = ((double)qwertyuiop)/CLOCKS_PER_SEC;cerr<<fixed<<setprecision(5)<<"\n\nTime Taken : "<<time_taken<<" seconds\n";}
	#endif
}

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

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

using namespace std;

int main() {
  set<char> s1{'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j',
               'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't',
               'u', 'v', 'w', 'x', 'y', 'z'};
  string s;
  cin >> s;

  rep(i, s.length()) {
    if (s1.count(s[i]) > 0) {
      s1.erase(s[i]);
    }
  }

  for (char c : s1) {
    cout << c << endl;
    return 0;
  }
  cout << "None" << endl;
  return 0;
}

Measured memory_bytes: 512
/*
AizuOnline A0259
Title All Numbers Lead to 6174
@kankichi573
*/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
char buf[5];
char buf2[5];
//
int compare_char(const void *a, const void *b)
{
        return *(char*)a - *(char*)b;
}
int compare_char_r(const void *a, const void *b)
{
    return *(char*)b - *(char*)a;
}

void calc(char * dst,char * src)
{
        char buf3[5];
        char buf4[5];

        strcpy(buf3,src);
        qsort(buf3,4,1,compare_char);
        strcpy(buf4,src);
        qsort(buf4,4,1,compare_char_r);
        sprintf(dst,"%04d\0",atoi(buf4)-atoi(buf3));
}
main()
{
        int cnt;
        while(EOF!=scanf("%s",buf) && strcmp(buf,"0000"))
        {
                cnt=0;
                if((atoi(buf) % 1111)==0)
                        printf("NA\n");
                else
                {
                        while(strcmp(buf,"6174"))
                        {
                                calc(buf2,buf);
                                strcpy(buf,buf2);
                                cnt++;
                                //printf("%s\n",buf);
                        }
                        printf("%d\n",cnt);
                }
        }
return(0);
}

Measured memory_bytes: 592
#include <stdio.h>

void input_card(int cards[][14]);
void display(int cards[][14]); 

int main(void){
  int cards[4][14]={0};

  input_card(cards);
   display(cards); 

  return 0;
}

void input_card(int cards[][14]){
  int n,m,i,j,VA;
  char va;

  scanf("%d",&n);
  for(i=0;i<n;i++){
    scanf(" %c %d",&va,&m);
    if(va=='S'){
      VA=0;
    }
    if(va=='H'){
      VA=1;
    }
    if(va=='C'){
      VA=2;
    }
    if(va=='D'){
      VA=3;
    }
    cards[VA][m]=1;
  }

  return;
}


void display(int cards[][14]){
  int i,j;

  for(i=0;i<4;i++){
    for(j=0;j<13;j++){
      if(cards[i][j+1]!=1){
	if(i==0) printf("S %d\n",j+1);
	if(i==1) printf("H %d\n",j+1);
	if(i==2) printf("C %d\n",j+1);
	if(i==3) printf("D %d\n",j+1);
      }
    }
  }

  return;
}

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

int main()
{
	double a,b,c,d,e,f,x,y;

	while(cin>>a>>b>>c>>d>>e>>f)
	{
		x=(e*c-b*f)/(a*e-b*d);
		y=(c*d-a*f)/(b*d-a*e);
		if(x==-0)x=0;
		if(y==-0)y=0;

		printf("%.3lf %.3lf\n",x,y);
	}
}

//大文字を小文字に変換
/*
for(int i=0;i<inp.size();i++)
if(inp[i]>='A' && inp[i]<='Z')
inp[i]+='a'-'A';
*/

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

int main() {
  ll n;
  vl a(3), b(3);
  cin >> n;
  rep(i, 3) cin >> a[i];
  rep(i, 3) cin >> b[i];
  rep(_, 2) {
    vl dp(n + 1, 0);
    rep(i, 3) rep(j, n) {
      ll nj = j + a[i];
      if(nj <= n) dp[nj] = max(dp[nj], dp[j] + b[i]);
    }
    ll mx = n;
    rep(j, n + 1) mx = max(mx, n - j + dp[j]);
    swap(a, b);
    n = mx;
  }
  cout << n << endl;
}

Measured memory_bytes: 198616
#define _CRT_SECURE_NO_WARNINGS
#include <cstdio>
#include <vector>

using namespace std;

template<class T> void gc(T &x)
{
    int s, k, m = 0;
    x = 0;

    k = getchar_unlocked();

    if (k == '-') s = 1;
    else if ('0' <= k && k <= '9')  x = k - '0';

    while (true)
    {
        k = getchar_unlocked();

        if (k < '0' || k > '9') break;
        x = x * 10 + k - '0';
    }

    if (m) x = -x;
}

int main()
{
    int N, M;

    gc(N);
    gc(M);

    vector<int> num;
    vector<bool> red;

    for (int i = 0; i < N; i++)
    {
        num.push_back(1);
        red.push_back(false);
    }

    red[0] = true;

    for (int i = 0; i < M; i++)
    {
        int x, y;

        gc(x);
        gc(y);

        if (red[x - 1]) red[y - 1] = true;
        num[x - 1]--;
        num[y - 1]++;
        if (!num[x - 1]) red[x - 1] = false;
    }

    int ans = 0;
    for (int i = 0; i < N; i++)
    {
        if (red[i]) ans++;
    }

    printf("%d\n", ans);
    return 0;
}


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

int main(void){
  string s;
  cin >> s;
  int cnt;
  for(int i=0;i<4;++i){
    cnt = 0;
    for(int j=0;j<4;++j){
      if(s[i]==s[j])++cnt;
    }
    if(cnt != 2){
      cout << "No\n";
      return 0;
    }
  }
  cout << "Yes\n";
}

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

public class Main {
    public static void main(String[] args) {
        Main main = new Main();
        main.solve();
    }
    public void solve() {
        Scanner scan = new Scanner(new BufferedReader(new InputStreamReader(System.in)));
        int X = scan.nextInt();
        int A = scan.nextInt();
        int remain = X - A;
        int B = scan.nextInt();
        int count = remain / B;
        int answer = remain - B * count;
        System.out.println(answer);
    }
}


Measured memory_bytes: 21460
#include <iostream>
#include <cmath>
#include <cstdio>
#include <algorithm>
#include <random>
#include <string>
#include <bitset>
#include <map>
#include <vector>
#include <stack>
#include <queue>
#include <list>
#include <set>
#include <cstring>
#include <cstdlib>
#include <cctype>

#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define FORR(i, m, n) for(int i = m; i >= n; i--)
#define SORT(v, n) sort(v, v + n);
#define VSORT(v) sort(v.begin(), v.end());
#define llong long long
#define pb(a) push_back(a)
#define INF 999999999

using namespace std;

typedef pair<int, int> P;
typedef pair<llong, llong> LP;
typedef pair<int, P> PP;
typedef pair<llong, LP> LPP;

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

llong pow(int x, int n){
    llong ans = x;
    if (n == 0) return 1;

    for(int i = 0; i < n - 1; i++) {
        ans *= x;
    }

    return ans;
}

template <typename T> struct BIT { // 1-indexed
private:
    vector<T> array;
    const int n;

public:
    // 初期化
    BIT(int _n) : array(_n + 1, 0), n(_n) {}

    // 1番目からi番目までの累積和を求める
    T sum(int i) {
        T s = 0;
        while(i > 0) {
            s += array[i];
            i -= i & -i; // LSB減算
        }

        return s;
    }

    // [i, j]の要素の総和
    T sum(int i, int j) {
        T ret_i = sum(i - 1);
        T ret_j = sum(j);

        return ret_j - ret_i;
    }

    // i番目に要素xを追加
    void add(int i, T x) {
        while (i <= n) {
            array[i] += x;
            i += i & -i; // LSB加算
        }
    }
};

template <typename T> struct BIT2 { // 1-indexed
private:
    vector<vector<T> > array;
    const int n;
    const int m;

public:
    // 初期化
    BIT2(int _n, int _m) : array(_n + 1, vector<T>(_m + 1, 0)), n(_n), m(_m) {}

    // (1, 1)から(x, y)までの累積和を求める
    T sum(int x, int y) {
        T s = 0;
        for (int i = x; i > 0; i -= i & (-i)) {
            for (int j = y; j > 0; j -= j & (-j)) {
                s += array[i][j];
            }
        }

        return s;
    }

    // [(x1, y1), (x2, y2)]の要素の総和
    T sum(int x1, int y1, int x2, int y2) {
        return sum(x2, y2) - sum(x1 - 1, y2) - sum(x2, y1 - 1) + sum(x1 - 1, y1 - 1);
    }

    // (x, y)に要素kを追加
    void add(int x, int y, T k) {
        for (int i = x; i <= n; i += i & (-i)) {
            for (int j = y; j <= m; j += j & (-j)) {
                array[i][j] += k;
            }
        }
    }
};

void swap(int *X, int *Y){
    int t = *X; *X = *Y; *Y = t;
}

string toUpper(string s) {
    string t = s;
    REP(i, s.size()) {
        t[i] = toupper(s[i]);
    }
    return t;
}

string toLower(string s) {
    string t = s;
    REP(i, s.size()) {
        t[i] = tolower(s[i]);
    }
    return t;
}

int main() {
    int x1, y1, x2, y2;
    cin >> x1 >> y1 >> x2 >> y2;
    int x = x2 - x1;
    int y = y2 - y1;
    cout << (x2 - y) << " " << (y2 + x) << " " << (x1 - y) << " " <<  (y1 + x) << endl;

    return 0;
}

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

using namespace std;

int n, d1, d2;

vector<pair<int, int>> salam[4];

int main()
{
	ios::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	cin >> n >> d1 >> d2;
	int L1 = 0;
	while (!(d1 & 1))
	{
		L1++;
		d1 >>= 1;
	}
	int L2 = 0;
	while (!(d2 & 1))
	{
		L2++;
		d2 >>= 1;
	}

	for (int i = 0; i < 2 * n; i++)
	{
		for (int j = 0; j < 2 * n; j++)
		{
			int color = 0;
			if (L1 & 1) {
				int l1 = L1 / 2;
				if (i & (1 << l1))
					color += 1;
			}
			else {
				int l1 = L1 / 2;
				if ((i & (1 << l1)) ^ (j & (1 << l1)))
					color += 1;
			}
			if (L2 & 1) {
				int l2 = L2 / 2;
				if (i & (1 << l2))
					color += 2;
			}
			else {
				int l2 = L2 / 2;
				if ((i & (1 << l2)) ^ (j & (1 << l2)))
					color += 2;
			}
			salam[color].push_back({i, j});
		}
	}
	for (int i = 0; i < 4; i++)
		if ((int)salam[i].size() >= (n * n))
		{
			for (int j = 0; j < n * n; j++)
			{
				cout << salam[i][j].first << ' ' << salam[i][j].second << '\n';
			}
			break;
		}
	return 0;
}

Measured memory_bytes: 4840
#!usr/bin/env python3
from collections import defaultdict,deque
from heapq import heappush, heappop
from itertools import permutations
import sys
import math
import bisect
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def I(): return int(sys.stdin.readline())
def LS():return [list(x) for x in sys.stdin.readline().split()]
def S():
    res = list(sys.stdin.readline())
    if res[-1] == "\n":
        return res[:-1]
    return res
def IR(n):
    return [I() for i in range(n)]
def LIR(n):
    return [LI() for i in range(n)]
def SR(n):
    return [S() for i in range(n)]
def LSR(n):
    return [LS() for i in range(n)]

sys.setrecursionlimit(1000000)
mod = 1000000007
import operator
class SegmentTree:
    def __init__(self, size, default, op = operator.or_):
        self.size = 2**size.bit_length()
        self.dat = [default]*(self.size*2)
        self.op = op

    def update(self, i, x):
        i += self.size
        self.dat[i] = x
        while i > 0:
            i >>= 1
            self.dat[i] = self.op(self.dat[i*2], self.dat[i*2+1])

    def add(self, i, x):
        i += self.size
        self.dat[i] = self.op(self.dat[i], x)
        while i > 0:
            i >>= 1
            self.dat[i] = self.op(self.dat[i], x)

    def get(self, a, b = None):
        if b is None:
            b = a + 1
        l, r = a + self.size, b + self.size
        res = None
        while l < r:
            if l & 1:
                if res is None:
                    res = self.dat[l]
                else:
                    res = self.op(res, self.dat[l])
                l += 1

            if r & 1:
                r -= 1
                if res is None:
                    res = self.dat[r]
                else:
                    res = self.op(res, self.dat[r])
            l >>= 1
            r >>= 1
        return res
def solve():
    n = I()
    S = list(input())
    m = ord("z")-ord("a")+1
    s = SegmentTree(n,0)
    for i in range(n):
        k = ord(S[i])-ord("a")
        k = 1 << k
        s.update(i,k)
    Q = I()
    for _ in range(Q):
        q = input().split()
        if q[0] == "1":
            i = int(q[1])-1
            if S[i] == q[2]:
                continue
            s.update(i,0)
            k = ord(q[2])-ord("a")
            k = 1 << k
            s.update(i,k)
            S[i] = q[2]
        else:
            l,r = q[1:]
            l = int(l)
            r = int(r)
            print(bin(s.get(l-1,r)).count("1"))
    return

#Solve
if __name__ == "__main__":
    solve()


Measured memory_bytes: 101876