akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using vl = vector<ll>;
template<class T> using vc = vector<T>;
template<class T> using vvc = vector<vector<T>>;

#define eb emplace_back
#define all(x) (x).begin(), (x).end()
#define rep(i, n) for (ll i = 0; i < (n); i++)
#define repr(i, n) for (ll i = (n)-1; i >= 0; i--)
#define repe(i, l, r) for (ll i = (l); i < (r); i++)
#define reper(i, l, r) for (ll i = (r)-1; i >= (l); i--)
#define repa(i,n) for (auto& i: n)

template<class T> inline bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T> inline bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
void init() {cin.tie(0);ios::sync_with_stdio(false);cout << fixed << setprecision(15);}

#ifdef DEBUG
template <class T, class N> void verr(const T& a, const N& n) { rep(i, n) cerr << a[i] << " "; cerr << "\n" << flush; }
ll dbgt = 1; void err() { cerr << "passed " << dbgt++ << "\n" << flush; }
template<class H, class... T> void err(H&& h,T&&... t){ cerr<< h << (sizeof...(t)?" ":"\n") << flush; if(sizeof...(t)>0) err(forward<T>(t)...); }
#endif

const ll INF = 5e18;
const ld EPS = 1e-11;
const ld PI = acos(-1.0L);
const ll MOD = 1e9 + 7;
// const ll MOD = 998244353;
//--------------------------------------------------------------------------------//
ll A[200000];
int main(){
    init();
    ll N, K;
    cin >> N >> K;
    rep(i, N) cin >> A[i];
    ll ans = 1;

    set<ll> st;
    rep(i, K) st.emplace(A[i]);

    ll cnt = 0, ai = 0;
    repe(i, 1, N){
        if(A[i]<A[i-1]){
            if (i - ai >= K) cnt++;
            ai = i;
        }
    }
    if (N - ai >= K) cnt++;
    if (cnt > 1) ans -= cnt - 1;

    ll m = *st.begin(), M = *st.rbegin();
    
    repe(i, K, N){
        ll si = i - K;
        // 変化なし
        // err(m, M, A[i]);
        if(m == A[si] and A[i] > M){
            st.erase(st.begin());
            st.emplace(A[i]);
            M = A[i];
            m = *st.begin();
        }
        else{
            st.emplace(A[i]);
            st.erase(st.lower_bound(A[si]));
            m = *st.begin();
            M = *st.rbegin();
            ans++;
        }
    }

    cout << ans << endl;
}

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

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

#define F 						first
#define PB 						push_back
#define MP 						make_pair
#define f(i,a,b) 				for(ll i=a; i<b; i++)
#define rep(i,n) 				f(i,0,n)
#define w(t)					ll t; cin>>t; while(t--)
#define epsilon					1e-9

constexpr ll int_pow(ll b, ll e) {
    return (e == 0) ? 1 : b * int_pow(b, e - 1);
}

void doublade() {
	ios::sync_with_stdio(false); cin.tie(0); cout.precision(10);
	#ifndef ONLINE_JUDGE
		freopen("input.txt", "r", stdin);
		freopen("output.txt", "w", stdout);
	#endif
}

int main()
{
	doublade();
	// w(t) {
		ll n;
		cin >> n;		
		ll ans[4] = {0};
		string s;
		rep(i, n) {
			cin>>s;
			if(s=="AC") ans[0] += 1;
			else if(s=="WA") ans[1] += 1;
			else if(s=="TLE") ans[2] += 1;
			else ans[3] += 1;	// s=="RE"
		}
		cout<<"AC x "<<ans[0]<<"\n";
		cout<<"WA x "<<ans[1]<<"\n";
		cout<<"TLE x "<<ans[2]<<"\n";
		cout<<"RE x "<<ans[3]<<"\n";
	// }
	return 0;
}

Measured memory_bytes: 3644
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  long long int n,x;
  cin>>n>>x;
  long long int a[n];
  for(int i=0;i<n;i++)
    cin>>a[i];
  
  int ans=0;
  sort(a,a+n);
  long long int sum=0;
  for(int i=0;i<n;i++){
    x-=a[i];
      ans++;
    if(x<0){
      ans--;
      break;
    }
  }
  if(x>0)
    ans--;
  cout<<ans;
  
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#define fastio() ios_base::sync_with_stdio(false);
#define rmod(x, y) ((((x)%(y))+(y))%(y))
using namespace std;
using namespace __gnu_pbds;
typedef long long ll;
typedef long double ld;
template<typename T, typename R = null_type, typename C = less<T>>
tree<T, R, C, rb_tree_tag, tree_order_statistics_node_update> ordered_set(){
	return tree<T, R, C, rb_tree_tag, tree_order_statistics_node_update>();
}


const int maxn = 1e5+5, mod = 1e9+7;

int add(int a, int b){return (a+b)%mod;}
int mul(ll a, ll b){return (a*b)%mod;}
int n, x, y, dp[maxn][2];
vector<int> vs[maxn];

int dfs(int v, int p, bool col){
	if (dp[v][col] != -1) return dp[v][col];
	int ret = dp[v][col];
	ret = 1;
	for(int e: vs[v]) if (e != p){
		int t = dfs(e, v, 1);
		if (col) t = add(t, dfs(e, v, 0));
		ret = mul(ret, t);
	}
	return dp[v][col] = ret;
}

int main(){
	memset(dp,-1, sizeof(dp));
	scanf("%d", &n);
	for(int i = 0; i<n-1; i++){
		scanf("%d %d", &x, &y);
		vs[--x].push_back(--y);
		vs[y].push_back(x);
	}
	dfs(0, -1, 1);
	dfs(0, -1, 0);
	printf("%d\n", add(dp[0][0], dp[0][1]));
	return 0;
}


Measured memory_bytes: 14848
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
using vi=vector<int>;
using P = pair<int,int>;
using Graph = vector<vector<int>>;
template<typename T> void ndarray(vector<T> &vec, int len) { vec.resize(len); }
template<typename T, typename... Args> void ndarray(vector<T> &vec, int len, Args... args) { vec.resize(len); for (auto &v : vec) ndarray(v, args...); }

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n;
    cin >> n;
    map<ll,ll> a;
    ll s=0;
    rep(i,n){
        int x; cin >> x;
        ++a[x];
    }
    for(auto p:a){
        s+=p.first*p.second;
    }
    int q;
    cin >> q;
    vector<ll> b(q);
    vector<ll> c(q);
    rep(i,q) cin >> b[i] >> c[i];
    rep(i,q) {
        s=s-a[b[i]]*(b[i]-c[i]);
        cout << s << "\n";
        a[c[i]]+=a[b[i]];
        a[b[i]]=0;
    }
    return 0;
}

Measured memory_bytes: 10728
N = int(input())
A = list(map(int,input().split()))
B = list(map(int,input().split()))
C = list(map(int,input().split()))

m = 0
for i in range(0,N-1):
    m += B[A[i]-1]
    if (A[i+1] - A[i]) == 1:
        m += C[A[i]-1]

m += B[A[N-1]-1]
print(m)


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

#define FOR(i, m, n) for(int i = m;i < n;i++)
#define ll long long

ll digitSum(ll i){
	ll sum = 0;
	while (i>0){
		sum += i%10;
		i /= 10;
	}
	return sum;
}

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	ll n, a, b;
	cin >> n >> a >> b;
	ll cnt = 0;
	FOR(i, 1, n+1){
		ll tmp = digitSum(i);
		if (a<=tmp && tmp<=b){
			cnt += i;
		}
	}
	cout << cnt << endl;
}


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

int main() {
	// your code goes here
	
	
	unsigned long long int n,k;
	cin >> n >>k;
	
	
	unsigned long long int minSum, maxSum; 
	unsigned long long ans = 0;
	for(unsigned long long int i = k; i <= n + 1; i++)
	{
		minSum = (i - 1) * i / 2;
		maxSum = ((n * (n + 1)) /2) - (((n - i) * (n - i + 1)) / 2);
		ans += ((((maxSum - minSum)%1000000007) + 1) % 1000000007);
		ans =ans % 1000000007;		
	}
	
	cout << ans;
	
	return 0;
}


Measured memory_bytes: 3644
#include <bits/stdc++.h>
using namespace std;
int main()
{
	int a,b,c;
	cin>>a>>b>>c;
	if(a==b && a!=c)
		cout<<"Yes";
	else if(b==c && a!=b)
	    cout<<"Yes";
    else if(a==c && b!=c)
        cout<<"Yes";
    else
        cout<<"No";
}

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

int N, M;
int mod = 1e9 + 7;

int main() {
    cin >> N;
    vector<int> C(N), S(N), F(N);
    for (int i = 0; i < N - 1; i++) {
        cin >> C[i] >> S[i] >> F[i];
    }
    for (int i = 0; i < N - 1; i++) {
        int start = 0, arrive = 0;
        for (int j = i; j < N - 1; j++) {
            start = max(S[j], (arrive + F[j] - 1) / F[j] * F[j]);
            arrive = start + C[j];
        }
        cout << arrive << endl;
    }
    cout << 0 << endl;
}

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

#define H 50
#define W 50

int h, w;
char s[H][W];
char ss[H][W];

int count( int i, int j )
{
	int dir[8][2] = { { -1, -1 }, { -1, 0 }, { -1, 1 }, { 0, -1 }, { 0, 1 }, { 1, -1 }, { 1, 0 }, { 1, 1 }, };
	int c = 0;
	if( i > 0 ) {
		if( j > 0 ) {
			if(s[i + dir[0][0] ][j + dir[0][1] ] == '#' ) {
				c++;
			}
		}
		if(s[i + dir[1][0] ][j + dir[1][1] ] == '#' ) {
			c++;
		}
		if( j < w-1 ) {
			if(s[i + dir[2][0] ][j + dir[2][1] ] == '#' ) {
				c++;
			}
		}
	}
	if( j > 0 ) {
		if(s[i + dir[3][0] ][j + dir[3][1] ] == '#' ) {
			c++;
		}
	}
	if( j < w-1 ) {
		if(s[i + dir[4][0] ][j + dir[4][1] ] == '#' ) {
			c++;
		}
	}
	if( i < h-1 ) {
		if( j > 0 ) {
			if(s[i + dir[5][0] ][j + dir[5][1] ] == '#' ) {
				c++;
			}
		}
		if(s[i + dir[6][0] ][j + dir[6][1] ] == '#' ) {
			c++;
		}
		if( j < w-1 ) {
			if(s[i + dir[7][0] ][j + dir[7][1] ] == '#' ) {
				c++;
			}
		}
	}
	return c;
}

int main()
{
	cin >> h >> w;
	for( int i = 0; i < h; i++ ) {
		for( int j = 0; j < w; j++ ) {
			cin >> s[i][j];
		}
	}

	for( int i = 0; i < h; i++ ) {
		for( int j = 0; j < w; j++ ) {
			if( s[i][j] == '.' ) {
				ss[i][j] = (char)(count( i, j ) + 0x30);
			}
			else {
				ss[i][j] = '#';
			}
		}
	}

	for( int i = 0; i < h; i++ ) {
		for( int j = 0; j < w; j++ ) {
			cout << ss[i][j];
		}
		cout << endl;
	}

	return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		try{
			Scanner sc = new Scanner(System.in);
			int N = sc.nextInt();
			int M = sc.nextInt();
			int[] a = new int[N];
			int[] b = new int[N];
			for(int i = 0; i < M; i++){
				int F = sc.nextInt();
				int S = sc.nextInt();
				if(Math.min(F, S) == 1){
					a[Math.max(F, S)] = 1;
				}
				if(Math.max(F, S) == N){
					b[Math.min(F, S)] = 1;
				}
			}
			String result = "IMPOSSIBLE";
			for(int i = 1; i < N; i++){
				if(a[i] == 1 && b[i] == 1){
					result = "POSSIBLE";
				}
			}
			System.out.println(result);
		}catch(Exception e){
			e.printStackTrace();
		}
	}
}

Measured memory_bytes: 95584
N = int(input())

maxN = int(N**(1/2))
for i in range(1,maxN+1):
    if N % i == 0:
        m1 = i

m2 = N//m1
m1 = str(m1)
m2 = str(m2)
print(max(len(str(m1)),len(str(m2))))

Measured memory_bytes: 3060
#include<iostream>
#include<iomanip>
#include<cmath>
#include<string>
#include<cstring>
#include<vector>
#include<list>
#include<algorithm>
#include<map>
#include<set>
#include<queue>
#include<stack>
using namespace std;
typedef long long ll;
#define fi first
#define se second
#define mp make_pair
#define mt make_tuple
#define pqueue priority_queue
const int inf=1e9+7;
const ll mod=1e9+7;
const ll mod1=998244353;
const ll big=1e18;
const double PI=2*asin(1);

int main() {
  int N;
  cin>>N;
  ll A;
  int num=0;
  ll ans = 0;
  for(int i=0;i<N;++i) {
    cin>>A;
    if(A==0) {
      num = 0;
    }
    else {
      if(num==1) {
        ans += 1;
        A--;
        ans += A/2;
        num = A%2;
      }
      else {
        ans += A/2;
        num = A%2;
      }
    }
  }
  cout<<ans<<endl;
}


Measured memory_bytes: 3612
s = list(input())
if s[0] == s[1] == s[2] == 'R':
    print(3)
elif s[0] == s[1] == 'R' or s[1] == s[2] == 'R':
    print(2)
elif s[0] == 'R' or s[1] == 'R' or s[2] == 'R':
    print(1)
else:
    print(0)
    

Measured memory_bytes: 9104
n = int(input())
#i　こうひ　j 

def sums(t,i):
    return int(0.5 * (n // i) * (i * 2 + i * ((n // i) -1)))

print(sums(n,1) - sums(n,3) -sums(n,5) + sums(n,15))

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

#define rep(i, n) REP(i, 0, n)
#define REP(i, k, n) for(auto i = k; i != n; i++)
#define rrep(i, n) RREP(i, n, 0)
#define RREP(i, n, k) for(auto i = n; i != k; i--)
#define ALL(x) (x).begin(), (x).end()
#define debug(x) cerr << #x << " " << x << endl
#define in(x, data) data.find(x) != data.end()

typedef long long ll;

int C[500], S[500], F[500];
int ans[500];

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

    int N; cin >> N;
    REP(i,1,N) cin >> C[i] >> S[i] >> F[i];

    ans[N] = 0;
    REP(i,1,N) {
        REP(j,i,N) {
            if(ans[i] < S[j]) ans[i] = S[j];
            else if (ans[i]%F[j] != 0) ans[i] = ans[i] +F[j] -ans[i]%F[j];
            ans[i] += C[j];
        }
    }

    REP(i,1,N+1) cout << ans[i] << endl;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp> 
using namespace std;
using namespace __gnu_pbds;

#define ordered_set tree<int, null_type,less_equal<int>, rb_tree_tag,tree_order_statistics_node_update>
#define pb push_back
#define ff first
#define ss second
#define endl '\n'
#define fast ios::sync_with_stdio(false); cin.tie(NULL);
const double eps = 1e-6;

/////////////////////////////////////////////

void __print(int x) {cerr << x;}
void __print(long x) {cerr << x;}
void __print(long long x) {cerr << x;}
void __print(unsigned x) {cerr << x;}
void __print(unsigned long x) {cerr << x;}
void __print(unsigned long long x) {cerr << x;}
void __print(float x) {cerr << x;}
void __print(double x) {cerr << x;}
void __print(long double x) {cerr << x;}
void __print(char x) {cerr << '\'' << x << '\'';}
void __print(const char *x) {cerr << '\"' << x << '\"';}
void __print(const string &x) {cerr << '\"' << x << '\"';}
void __print(bool x) {cerr << (x ? "true" : "false");}

template<typename T, typename V>
void __print(const pair<T, V> &x) {cerr << '{'; __print(x.first); cerr << ','; __print(x.second); cerr << '}';}
template<typename T>
void __print(const T &x) {int f = 0; cerr << '{'; for (auto &i: x) cerr << (f++ ? "," : ""), __print(i); cerr << "}";}
void _print() {cerr << "]\n";}
template <typename T, typename... V>
void _print(T t, V... v) {__print(t); if (sizeof...(v)) cerr << ", "; _print(v...);}
#ifndef ONLINE_JUDGE
#define debug(x...) cerr << "[" << #x << "] = ["; _print(x)
#else
#define debug(x...)
#endif

////////////////////////////////

#define int long long
const int N  = 5e5 + 5;
set<int> st[26];
void solve(){

	int n;
	cin>>n;
	string s;
	cin>>s;
	int q;
	cin>>q;

	for(int i = 0 ; i < n ; ++i){

		st[s[i]-'a'].insert(i);
	}

	while(q--){

		int x;
		cin>>x;
		if(x==1){

			int id;
			char c;
			cin>>id>>c;

			--id;
			st[s[id]-'a'].erase(id);
			s[id] = c;
			st[s[id]-'a'].insert(id);
		}
		else{

			int l , r;
			cin>>l>>r;
			--l , --r;

			int ans = 0;

			for(int i = 0  ;i  < 26 ; ++i){

				auto it = st[i].lower_bound(l);

				if(it==st[i].end())
					continue;
				int val = *it;
				if(val >= l && val <= r)
					++ans;
			}
			cout<<ans<<endl;
		}
	}

}

signed main(){

    fast;
    int t = 1;
    //cin>>t;
    for(int i = 1 ; i <= t; ++i){

    	solve();
    }
}


Measured memory_bytes: 24220
n,m=map(int,input().split())
a=[None]*n
g=[[] for _ in range(n)]
for _ in range(m):
    l,r,d=map(int,input().split())
    g[l-1].append((r-1,d))
    g[r-1].append((l-1,-d))
for i in range(n):
    if a[i]==None:
        a[i]=0
        q=[i]
    while q:
        j=q.pop()
        for x,e in g[j]:
            if a[x]==None:
                a[x]=a[j]+e
                q.append(x)
            elif a[x]!=a[j]+e:
                print("No")
                exit()
                
print("Yes")

Measured memory_bytes: 82208
n = int(input())
k = int(input())
a = [1]
for i in range(n):
    if a[i] < k:
        a[i] = 2*a[i]
        a.append(a[i])
    else:
        a[i] = a[i] + k
        a.append(a[i])
print(a[n-1])

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

int main(){
    string a, b, c;
    cin >> a >> b >> c;
    if(a.back()==b.front() && b.back()==c.front()){
        cout << "YES" << endl;
    }else{
        cout << "NO" << endl;
    }

    return 0;
}

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

public class Main {

	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		long sum = 0;
		long x = 0;
		long min = (long)Math.pow(10, 15);
		int N = scan.nextInt();
		Long[] a = new Long[N];
		for(int i = 0; i < N; i++) {
			a[i] = scan.nextLong();
			sum += a[i];
		}
		for(int i = 0; i < N - 1; i++) {
			x += a[i];
			min = (long)Math.min(min, (long)Math.abs(sum - 2 * x));
		}
		System.out.println(min);
		scan.close();

	}

}


Measured memory_bytes: 53724
import java.util.Scanner;
public class Main {
	public static void main(String[] args) {
		Scanner sc=new Scanner(System.in);
		int a,b,c;
		a=sc.nextInt();
		b=sc.nextInt();
		c=sc.nextInt();
		if(a+b>=c)
			System.out.println("Yes");
		else
			System.out.println("No");
	}
}

Measured memory_bytes: 22612
#include <iostream>
using namespace std;
int main() {
    int a, b;
    cin >> a >> b;
    auto val = 0;
    if (a > b) {
        val += a;
        a--;
    } else {
        val += b;
        b--;
    }
    if (a > b) {
        val += a;
        a--;
    } else {
        val += b;
        b--;
    }
    cout << val;
}


Measured memory_bytes: 888
#include <iostream>
#include <vector>
#include <string>
#include <utility>
#include <queue>
#include <algorithm>
using namespace std;

#define ll long long

ll MAX(ll a, ll b) {

	if (a > b)return a;
	else return b;

}
ll MIN(ll a, ll b) {

	if (a < b)return a;
	else return b;

}

int main() {

	int cnt[10];
	string S;

	for (int i = 0; i < 10; i++)cnt[i] = 0;

	cin >> S;
	for (int i = 0; i < S.size(); i++) {

		cnt[S[i] - '0']++;

	}
	if (cnt[0] == S.size() - 1 && cnt[1] == 1) {

		cout << 10 << endl;

	}
	else {

		int ans = 0;
		for (int i = 0; i < 10; i++) {

			//cout << cnt[i] << endl;
			ans += cnt[i] * i;

		}
		cout << ans << endl;

	}

	return 0;
}

Measured memory_bytes: 256
dxy = [[1,0],[-1,0],[0,1],[0,-1]]
n=0
def rec(x,y):
    global n
    if (x<0 or x>=h or y<0 or y>=w) or (visited[x][y] or tile[x][y]!='.'):
        return 0
    visited[x][y] = True
    n += 1
    for (dx,dy) in dxy:
        x2 = x + dx
        y2 = y + dy
        rec(x2,y2)
    return 0

w,h=map(int,input().split())
ans = []
while((w,h)!=(0,0)):
    n=0
    tile = []
    for _ in range(h):
        tile.append(list(input()))
    visited = [[False] * w for _ in range(h)]
    for a in range(h):
        for b in range(w):
            if(tile[a][b]=='@'):
                pos_x = a
                pos_y = b
                tile[a][b]='.'
    rec(pos_x, pos_y)
    ans.append(n)
    w,h=map(int,input().split())
for a in ans:
    print(a)


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

#define SPEED ios::sync_with_stdio(false); cin.tie(0); cout.tie(0)
#define read()          freopen("in.txt","r",stdin)
#define write()         freopen("out.txt","w",stdout)
#define sf(n)           scanf("%d",&n)
#define sfd(n)          scanf("%lf",&n)
#define sl(x)           scanf("%I64d",&x)
#define sfl(n)          scanf("%lld", &n)
#define sfc(n)          scanf(" %c",&n)
#define sful(n)         scanf("%llu",&n)
#define ull             unsigned long long
#define endll           pf("\n")
#define pf              printf
#define PI              acos(-1.0)
#define eps             1e-12
#define mem(a,b)        memset(a,b,sizeof(a))
#define pb              push_back
#define xx              first
#define yy              second
#define pii             pair<int, int>
#define pll             pair<ll, ll>
#define MP make_pair
#define ll              long long
#define uniq(a)      a.erase(unique(a.begin(), a.end()), a.end())
#define cnd tree[idx]
#define lnd tree[idx<<1]
#define rnd tree[(idx<<1)+1]
#define lndp (idx<<1),(b),((b+e)>>1)
#define rndp ((idx<<1)+1),(((b+e)>>1)+1),(e)
#define inf 1999999999
#define MOD  998244353
#define mod1 1000000009
#define var    int n,m,i,j,c=0,t,l,r,mid,z=0,k,x,y
#define aloc(n,t) ((t*)malloc((n)*sizeof(t)))

int dx[8]={0,0,1,1,-1,-1,1,-1};  //8 direction
int dy[8]={1,-1,1,-1,1,-1,0,0};
//int dx[4]={1,-1,0,0};  //4 direction
//int dy[4]={0,0,1,-1};

ll n,m,a[200005],b[200005],x;
vector<ll> v;
int main()
{
    sfl(n);sfl(x);sfl(m);
    a[x] = 1;
    b[x] = 1;
    ll c = x;
    v.pb(x);
    ll l = n+1,j=0;
    for(int i=2;i<=n;i++)
    {
        c*=c;c%=m;
        if(a[c])
        {
            i--;
            j = i;
            l = a[c]-1;
            break;
        }
        b[c]++;
        a[c] = i;
        v.pb(c);
    }
    if(l!=n+1)
    {
       // cout<<j<<" "<<l<<endl;
        n-=j;
        ll sz = v.size();
        ll extra = n%(sz-l);
        for(int i=l;i<sz;i++)
        {
            if(extra>0)
            {
                extra--;
                b[v[i]]++;
            }
            b[v[i]]+=(n/(sz-l));
        }
    }
    ll ans =0;
    for(int i=0;i<m;i++)
    {
        ans += (b[i]*i);
    }
    cout<<ans<<endl;
}


Measured memory_bytes: 5396
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <map>
#include <bitset>
#include <stack>
#include <queue>
#include <list>
#include <iomanip>
#include <numeric>

using namespace std;
typedef long long ll;
ll mod = 1000000007;
const int INF = 1001001001;

template<class Type>
Type modpow(Type a, Type n, Type mod)
{
	Type res = 1;
	while (0 < n) {
		if (n & 1) {
			res = res * a % mod;
		}
		a = a * a % mod;
		n >>= 1;
	}
	return res;
}

template<class Type>
Type gcd(Type x, Type y)
{
	Type r;
	if (x < y) swap(x, y);

	while (0 < y) {
		r = x % y;
		x = y;
		y = r;
	}
	return x;
}

template<class Type>
Type lcm(Type x, Type y)
{
	return x * y / gcd(x, y);
}

template<class Type>
bool is_prime(Type x)
{
	if (x == 2) return true;
	if (x < 2 || x % 2 == 0) return false;

	for (Type i = 3; i <= sqrt(x); i += 2) {
		if (x % i == 0) return false;
	}
	return true;
}

template<class Type>
vector<bool> eratos(Type n)
{
	vector<bool> isPrime(n + 1, true);
	isPrime[0] = isPrime[1] = false;
	for (Type i = 2; i <= n; i++) {
		if (isPrime[i]) {
			Type j = i + i;
			while (j <= n) {
				isPrime[j] = false;
				j = j + i;
			}
		}
	}
	return isPrime;
}

bool binary_search_judge(vector<int> a, int index, int key)
{
	if (key <= a[index]) return true;
	else return false;
}

int binary_search(vector<int> a, int key)
{
	int ng = -1;
	int ok = a.size();
	while (1 < abs(ng - ok)) {
		int mid = (ng + ok) / 2;
		if (binary_search_judge(a, mid, key)) ok = mid;
		else ng = mid;
	}
	return a[ok] == key;
}

int main()
{
	int n, w;
	cin >> n >> w;
	vector<int> weight(n), value(n);
	for (int i = 0; i < n; i++) cin >> weight[i] >> value[i];
	int v_max = *max_element(value.begin(), value.end());

	vector<vector<int>> dp(n, vector<int>(n * v_max + 1, INF));
	dp[0][0] = 0;
	for (int j = 1; j <= value[0]; j++) dp[0][j] = weight[0];

	for (int i = 1; i < n; i++) {
		for (int j = 0; j <= n * v_max; j++) {
			dp[i][j] = dp[i - 1][j];
			if (0 <= j - value[i]) dp[i][j] = min(dp[i][j], dp[i - 1][j - value[i]] + weight[i]);
		}
	}

	int ans = 0;
	for (int j = 0; j <= n * v_max; j++) {
		if (dp[n - 1][j] <= w) ans = j;
	}
	cout << ans << endl;
}

Measured memory_bytes: 39808
package main

import "fmt"

func main() {
	var N int
	fmt.Scanf("%d", &N)
	X := make([]int, N)
	for i := 0; i < N; i++ {
		fmt.Scanf("%d", &X[i])
	}
	// ave = ave / 2
	// tairyoku := 0
	// for i := 0; i < N; i++ {
	// 	tairyoku += (X[i] - ave) * (X[i] - ave)
	// }
	// fmt.Println(tairyoku)
	min := 1000000000

	for i := 1; i <= 100; i++ {

		sum := 0
		for j := 0; j < N; j++ {
			sum += (X[j] - i) * (X[j] - i)
		}
		if min > sum {
			min = sum
		}
	}
	fmt.Println(min)

}


Measured memory_bytes: 512
# coding: utf-8
N = int(input())
lst = []
for i in range(N):
    SP = list(map(str, input().split()))
    SP.append(i+1)
    lst.append(SP)

lst.sort(key=lambda x:(x[0],-int(x[1])))

for i in range(N):
    print(lst[i][2])

Measured memory_bytes: 3060
s = gets.chomp
b = []
for a in 0..s.length - 1
  b << s[a, 1]
end
b.sort!
c = ""
for a in 0..s.length - 1
  c = c + b[a]
end
if c == "abc"
  puts "Yes"
  exit
end
puts "No"


Measured memory_bytes: 1788
def root(x,rt):
    if rt[x] == x:
        return x
    else:
        while rt[x] != x:
            rt[x] = root(rt[x],rt)
            return rt[x]
def union(x,y,rt,rank):
    rootx = root(x,rt)
    rooty = root(y,rt)
    if rootx == rooty:
        return 0
    else:
        if rank[rootx] < rank[rooty]:
            rt[rootx] = rooty
        else:
            rt[rooty] = rootx
            if rank[rootx] == rank[rooty]:
                rank[rootx] += 1

def issame(x,y,rt):
    return root(x,rt) == root(y,rt)

length,query = (int(n) for n in input().split(" "))
rootlist = [n for n in range(length)]
rank = [0 for n in range(length)]

for q in range(query):
    #print(root)
    com,x,y = (int(n) for n in input().split(" "))
    if com == 0:
        union(x,y,rootlist,rank)
    else:
        print(1 if issame(x,y,rootlist) else 0)

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

int main() {
  int N,L;
  cin >> N >> L;
  vector<string> bemiho(N);
  for (int i = 0; i < N; i++) {
    cin >> bemiho.at(i);
  }
  sort(bemiho.begin(), bemiho.end());
  vector<string> katoshi(N);
  for (int i = 0; i < N; i++) {
    for (int j = 0; j < N; j++) {
      katoshi.at(i) += bemiho.at(j);
    }
  }
  cout << katoshi.at(0) << endl;
}

Measured memory_bytes: 1792
#include<cmath>
#include<cstdio>
#include<vector>
using namespace std;

const int MAX_N = 1e5;
int n;
int p[MAX_N];
vector<int> v;

int main() {
    scanf("%d", &n);
    for (int i = 0; i < n; i++) scanf("%d", &p[i]);
    int cnt = 0;
    for (int i = 0; i < n; i++) {
        if (p[i] == i + 1) cnt++;
        else {
            if (cnt > 0) v.push_back(cnt);
            cnt = 0;
        }
    }
    if (cnt > 0) v.push_back(cnt);
    
    int ans = 0;
    for (auto &i : v) ans += ceil(static_cast<double>(i) / 2);
    printf("%d\n", ans);
    return 0;
}


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

using LL = long long;

#define ALL(a) begin((a)), end((a))
#define FOR(i, a, b) for (int(i) = (a); (i) < (b); (i)++)
#define RFOR(i, a, b) for (int(i) = (a); (i) > (b); (i)--)
#define debug(x) cout << #x << " : " << x << '\n'

const int INF = 1e9;

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

  LL ans;
  int r, D;
  LL x;
  cin >> r >> D >> x;

  FOR(i, 0, 10) {
    x = r * x - D;
    ans = x;
    cout << ans << '\n';
  }

  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#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 INF 2e9
#define ALL(v) v.begin(), v.end()
using namespace std;
typedef long long ll;

string S;

int main()
{
    cin >> S;
    S[0]='2';
    S[1]='0';
    S[2]='1';
    S[3]='8';
    cout << S;
    return 0;

}

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

using namespace std;
#define int long long
#define x first
#define y second
typedef long long ll;
typedef double ld;
typedef pair<int, int> pii;

mt19937 rand1(chrono::high_resolution_clock::now().time_since_epoch().count());
int randlr(int l, int r) {
    return rand1() % (r - l + 1) + l;
}

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

    int n;
    cin >> n;

    vector<int> a(n);
    vector<int> not0(n, -1);

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

    for (int i = 1; i < n; i ++) {
        if (a[i - 1] != 0) {
            not0[i] = i - 1;
        }

        else {
            not0[i] = not0[i - 1];
        }
    }

    int answ = 0;
    for (int i = 0; i < n; i ++) {
        int j = not0[i];
        answ += (i - j);
        int curr = a[i];
        int sum = a[i];
        while (j != -1) {
            sum += a[j];
            curr ^= a[j];
            //cout << i << ' ' << j << ' ' << sum << ' ' << curr << ' ' << a[j] << endl;
            if (sum != curr) break;
            answ += (j - not0[j]);
            j = not0[j];
        }
    }

    cout << answ;

    return 0;
}


Measured memory_bytes: 3456
#include <iostream>
#include <vector>

using namespace std;

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

    bool prime[100004];

    for(int i = 2; i < 100004; i++){
        prime[i] = true;
    }

    for(int i = 2; i < 100004; i++){
        if(prime[i]){
            //cout << prime[i] << endl;
            for(int j = 2; i < 100004; j++){
                if(i * j >= 100004) break;
                prime[i * j] = false;
            }
        }
    }

    int ans = 0;
    for(int i = n; i < 100004; i++){
        if(prime[i]){
            ans = i;
            break;
        }
    }

    /*
    vector<int> prime_num;
    for(int i = 2; i < 100004; i++){
        prime_num.push_back(i);
    }

    for(vector<int>::iterator i = prime_num.begin(); i != prime_num.end() ; i++){
        //cout << *i << endl;
        for(vector<int>::iterator j = i+1; j != prime_num.end() ; j++){
            //cout << *j << endl;
            if(*j % *i == 0){
                prime_num.erase(j);
            }
        }
    }

    int ans = 0;
    for(vector<int>::iterator i = prime_num.begin(); i != prime_num.end() ; i++){
        ans = *i;
        if(ans >= n) break;
    }
    */

    cout << ans << endl;

    return 0;
}

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

int main()
{
  int n;
  cin >> n;
  vector<int> prime = {2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47};
  int m = prime.size();
  vector<int> p(m);
  for(int i = 0; i < m; i++)
  {
    int x = prime[i];
    for(int j = x; j <= n; j *= x)
    {
      p[i] += n / j;
    }
  }
  
  //rep(i, m) cout << p[i] << " "; cout << endl;
  
  int res = 0;
  for(int x : p) if(x >= 74) res++;
  //cout << res << endl;
  
  
  for(int i = 0; i < m; i++)
  {
    for(int j = i + 1; j < m; j++)
    {
      if(p[i] >= 24 && p[j] >= 2) res++;
      if(p[i] >= 2 && p[j] >= 24) res++;
      if(p[i] >= 14 && p[j] >= 4) res++;
      if(p[i] >= 4 && p[j] >= 14) res++;
    }
  }
  //cout << res << endl;
  
  for(int i = 0; i < m; i++)
  {
    for(int j = i + 1; j < m; j++)
    {
      for(int k = j + 1; k < m; k++)
      {
        if(p[i] >= 2 && p[j] >= 4 && p[k] >= 4) res++;
        if(p[i] >= 4 && p[j] >= 2 && p[k] >= 4) res++;
        if(p[i] >= 4 && p[j] >= 4 && p[k] >= 2) res++;
      }
    }
  }
  cout << res << endl;
  
  
  return 0;
}

Measured memory_bytes: 256
/* by Natsu Kinmoe */
#include <bits/stdc++.h>
using namespace std;
#define SZ(x)               ((int)(x).size())
#define all(x)              (x).begin(), (x).end()
#define loop(i, n)          for(int i = 0; i < (n); i++)
#define cont(i, n)          for(int i = 1; i <= (n); i++)
#define circ(i, a, b)       for(int i = (a); i <= (b); i++)
#define range(i, a, b, c)   for(int i = (a); ((c) > 0 ? i <= (b) : i >= (b)); i += (c))
#define foreach(it, v)      for(__typeof((v).begin()) it = (v).begin(); it != (v).end(); it++)
#define y0          y0O0OO00OO0OO0OO0OOO00OO0OO0O0O000OO0
#define y1          y1II11II11III11I1III11II111IIII1II1I1
#define pub         push_back
#define pob         pop_back
#define mak         make_pair
typedef long long   ll;
typedef long double lf;
const int   Inf = 0x3f3f3f3f;
const ll    INF = 0x3f3f3f3f3f3f3f3fll;
/* Source code starts here */

int dp[2005][2005], mx[2005], nmx[2005], ndp[2005][2005];
int a[6005], n, jar, Mx, NMx;
map<pair<int, int>, int> zh;

int inline val(int i, int j) {
	return dp[i][j];
}

void inline zy(int i, int j, int v) {
	ndp[i][j] = max(ndp[i][j], v);
	ndp[j][i] = max(ndp[j][i], v);
	nmx[i] = max(nmx[i], v);
	nmx[j] = max(nmx[j], v);
	NMx = max(NMx, v);
}

int main() {
	scanf("%d", &n);
	cont(i, 3 * n) scanf("%d", a + i);
	cont(i, n) cont(j, n) dp[i][j] = -Inf;
	cont(i, n) mx[i] = -Inf;
	mx[a[1]] = mx[a[2]] = 0;
	Mx = 0;
	dp[a[1]][a[2]] = 0;
	memset(ndp, -1, sizeof(ndp));
	range(i, 3, 3 * n - 1, 3) {
		cont(j, n) nmx[j] = -Inf;
		NMx = -Inf; zh.clear();
		int p = a[i], q = a[i + 1], r = a[i + 2];
		if(p == q && q == r) {
			jar++; continue;
		}
		cont(j, n) {
			ndp[j][p] = dp[j][p]; ndp[j][q] = dp[j][q]; ndp[j][r] = dp[j][r];
			ndp[p][j] = dp[p][j]; ndp[q][j] = dp[q][j]; ndp[r][j] = dp[r][j];
		}
		if(p == q || q == r || p == r) {
			int Q = p ^ q ^ r, P = (p + q + r - Q) >> 1;
			cont(j, n) zy(j, Q, val(j, P) + 1);
		}
		zy(q, r, val(p, p) + 1);
		zy(p, r, val(q, q) + 1);
		zy(p, q, val(r, r) + 1);
		zy(q, r, Mx); zy(p, r, Mx); zy(p, q, Mx);
		cont(j, n) {
			zy(j, p, mx[j]);
			zy(j, q, mx[j]);
			zy(j, r, mx[j]);
		}
		cont(j, n) mx[j] = nmx[j];
		cont(j, n) {
			dp[j][p] = ndp[j][p]; dp[j][q] = ndp[j][q]; dp[j][r] = ndp[j][r];
			dp[p][j] = ndp[p][j]; dp[q][j] = ndp[q][j]; dp[r][j] = ndp[r][j];
		}
		cont(j, n) {
			ndp[j][p] = ndp[j][q] = ndp[j][r] = -1;
			ndp[p][j] = ndp[q][j] = ndp[r][j] = -1;
		}
		Mx = NMx;
	}
	int res = dp[a[3 * n]][a[3 * n]] + 1;
	cont(i, n) cont(j, n) res = max(res, dp[i][j]);
	printf("%d\n", res + jar);
	return 0;
}


Measured memory_bytes: 35192
from collections import Counter

N, K, Q = map(int, input().split())
A = [int(input()) for _ in range(Q)]
Ans = [K - Q] * N

AC = Counter(A)

for key, value in AC.items():
    Ans[key-1] = K - Q + value

for ans in Ans:
    if ans > 0:
        print('Yes')
    else:
        print('No')


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

using namespace std;

static const int INF = 1e9 + 7;

template<typename T>
using Vec = vector<T>;

template<typename T, typename T2>
using P = pair<T, T2>;

template<typename... Args>
using Tup = tuple<Args...>;

template<typename T>
using qp = priority_queue<T, Vec<T>, greater<T> >;

template<typename T>
using pq = priority_queue<T>;

using llong = long long;
using ullong = unsigned long long;
using uint = unsigned int;

int gcd(int x, int y)
{
	return y ? gcd(y, x % y) : x;
}

void hawawa()
{
	int x, a, b;
	cin >> x >> a >> b;
	cout << (x - a) % b << "\n";
}

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


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

const int MAXN = 100010;
void bye() { std::cout << "No" << std::endl; exit(0); }
struct info {
	int l, r, typ;
	info operator + (info b) {
		if (typ != b.typ) return (info) {0, 0, -233};
		return (info) {std::max(l, b.l), std::min(r, b.r), typ};
	}
	info ex() { return (info) {l - 1, r + 1, typ ^ 1}; }
	bool none() { return typ < 0 || l > r; }
} val[MAXN];
struct edge {
	int nxt, to;
} es[MAXN << 1];
int head[MAXN], tot;
void adde(int b, int e) {
	es[++tot] = (edge) {head[b], e}; head[b] = tot;
	es[++tot] = (edge) {head[e], b}; head[e] = tot;
}
int fa[MAXN], dfn[MAXN], idx, dep[MAXN];
void dfs(int u) {
	dfn[++idx] = u; dep[u] = dep[fa[u]] + 1;
	for (int i = head[u]; i; i = es[i].nxt)
		if (es[i].to != fa[u])
			fa[es[i].to] = u, dfs(es[i].to);
}

int main() {
	std::ios_base::sync_with_stdio(false), std::cin.tie(0);
	int n; std::cin >> n;
	for (int i = 1, b, e; i < n; ++i)
		std::cin >> b >> e, adde(b, e);
	dfs(1);
	int K; std::cin >> K; int coe = -1;
	memset(val, -1, sizeof val);
	for (int i = 1, u, v; i <= K; ++i) {
		std::cin >> u >> v;
		if (i == 1) coe = (dep[u] ^ v) & 1;
		if ((dep[u] ^ v) % 2 != coe) bye();
		val[u] = (info) {v, v, v & 1};
	}
	for (int i = 1; i <= n; ++i) if (val[i].typ == -1) {
		if ((dep[i] ^ coe) & 1)
			val[i] = {-1234577, 1234577, 1};
		else val[i] = {-1234566, 1234566, 0};
	}
	for (int i = n; i; --i) {
		const int u = dfn[i];
		if (val[u].none()) bye();
		val[fa[u]] = val[fa[u]] + val[u].ex();
	}
	for (int i = 1; i <= n; ++i) {
		const int u = dfn[i];
		if (val[u].none()) bye();
		if (fa[u]) val[u] = val[u] + val[fa[u]].ex();
		val[u].r = val[u].l;
	}
	std::cout << "Yes\n";
	for (int i = 1; i <= n; ++i) std::cout << val[i].l << '\n';
	return 0;
}


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

bool isprime[50010];
int ans[50010];

int main(){
	for(int i = 2; i <= 50000; ++i){
		isprime[i] = true;
	}
	for(int i = 2; i < 300; ++i){
		if(isprime[i]){
			for(int j = i * i; j <= 50000; j += i){
				isprime[j] = false;
			}
		}
	}

	vector<int> primes;
	for(int i = 2; i <= 50000; ++i){
		if(isprime[i]) primes.push_back(i);
	}

	int n;
	while(scanf("%d", &n), n){
		int c = 0;
		for(int i = 0; primes[i] * 2 <= n; ++i){
			if(isprime[n - primes[i]]) ++c;
		}
		printf("%d\n", c);
	}
}

Measured memory_bytes: 1160
#include <stdio.h>
#include <stdlib.h>
#define int long long

signed main(){
	int N, k, i, j;
	scanf("%lld", &N);
	for(k = 1; (k * (k + 1)) / 2 <= N; k++){
		if((k * (k + 1)) / 2 == N){
			printf("Yes\n");
			printf("%lld\n", k + 1);
			int **A = (int **)malloc(sizeof(int *) * (k + 1));
			for(i = 0; i <= k; i++){
				A[i] = (int *)malloc(sizeof(int) * (N + 1));
				for(j = 0; j <= N; j++){
					A[i][j] = 0;
				}
			}
			for(i = 1; i <= k; i++){
				for(j = 1; j <= i; j++){
//					printf("(i, j) = (%lld, %lld)\n", i, j);
					A[j - 1][(i * (i - 1)) / 2 + j] = 1;
					A[i][(i * (i - 1)) / 2 + j] = 1;
				}
			}
			for(i = 0; i <= k; i++){
				printf("%lld ", k);
				for(j = 1; j <= N; j++){
					if(A[i][j] == 1){
						printf("%lld ", j);
					}
				}
				printf("\n");
			}
			return 0;
		}
	}
	printf("No\n");
	return 0;
}

Measured memory_bytes: 349952
#include<iostream>
#include<string>
int main(){
    int A, B;
    std::cin >> A >> B;
    std::string S;
    std::cin >> S;
    for(int i = 0; i < A; i++){
        if('0' <= S[i] && S[i] <= '9') continue;
        else{
            std::cout << "No" << std::endl;
            return 0;
        }
    }
    if(S[A] != '-'){
        std::cout << "No" << std::endl;
        return 0;
    }
    for(int i = A + 1; i < A + B + 1; i++){
        if('0' <= S[i] && S[i] <= '9') continue;
        else{
            std::cout << "No" << std::endl;
            return 0;
        }
    }

    std::cout << "Yes" << std::endl;
    return 0;
}


Measured memory_bytes: 256
#include <iostream>

int main()
{
    int X;
    std::cin >> X;
    int kyu;
    if(X >= 400 && X <=599){
        kyu = 8;
    }else if(X>=600 && X<=799){
        kyu = 7;
    }else if(X>=800&&X<=999){
        kyu = 6;
    }else if(X>=1000&&X<=1199){
        kyu = 5;
    }else if(X>=1200&&X<=1399){
        kyu = 4;
    }else if(X>=1400&&X<=1599){
        kyu = 3;
    }else if(X>=1600&&X<=1799){
        kyu = 2;
    }else if(X>=1800&&X<=1999){
        kyu = 1;
    }

    std::cout << kyu << std::endl;
    //int end;
    //std::cin >> end;
    return 0;
}

Measured memory_bytes: 3596
from collections import deque

N, D, A = map(int, input().split())
XH = [list(map(int, input().split())) for i in range(N)]

XH.sort(key=lambda x:x[0])

q = deque()

s = 0
ans = 0

for i in range(N):
  x = XH[i][0]
  h = XH[i][1]
  while len(q) > 0:
    elm = q.popleft()
    if x <= elm[0]:
      q.appendleft(elm)
      break
    else:
      s -= elm[1]
  h -= s
  c = max(0, (h + A - 1) // A)
  ans += c
  s += c * A
  q.append((x + 2*D, c*A))
  
print(ans)

Measured memory_bytes: 98776
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <map>
#include <set>
#include <unordered_map>
#include <unordered_set>
#include <queue>
#include <iomanip>
#include <bitset>
#include <cassert>
#include <cmath>
#include <cstring>
#include <climits>

using namespace std;

#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define REP(i, n) FOR(i, 0, n)
#define SORT(c) sort((c).begin(), (c).end())

typedef long long ll;
typedef pair<int, int> P;
typedef vector<int> V;
typedef map<int, int> M;

constexpr ll INF = 1e18;
constexpr ll MOD = 1e9 + 7;
constexpr double PI = 3.14159265358979323846;
constexpr int di[] = {0, 0, 1, -1};
constexpr int dj[] = {1, -1, 0, 0};

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

    ll a, b;

    cin >> a >> b;

    ll res = 0;

    b++;

    for (ll i = a - (a % 4) + 1; i <= a; i++)
        res ^= i - 1;

    for (ll i = b - (b % 4) + 1; i <= b; i++)
        res ^= i - 1;

    cout << res << endl;

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define fi first
#define se second
#define all(x) (x).begin(), (x).end()
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define repp(i, a, b) for (int i = a; i <= (b); ++i)
#define repr(i, a, b) for (int i = a; i >= (b); --i)
typedef long long ll;
const int INF = 1001001001;
const ll LINF = 1001001001001001001ll;
const int MOD = 1000000007;

template <class T>
inline bool chmin(T& a, T b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}

template <class T>
inline bool chmax(T& a, T b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}

int main() {
  int a, b, c;
  cin >> a >> b >> c;
  cout << a + b + c - max({a, b, c}) << endl;
}

Measured memory_bytes: 256
// #define _CRT_SECURE_NO_WARNINGS
// #define _USE_MATH_DEFINES	// M_PI=3.1415...
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <stack>
#include <cmath>
#include <cstdlib>
#include <functional>
#include <locale>
#include <cctype>
#include <sstream>
#include <iomanip>	// 20桁出力 cout << setprecision(20) << double;
#include <queue>
#include <bitset>	// bitset<8> bs1(131uL); // 10000011 bs1[0]は1 01stringからビット集合生成可
#include <numeric>
#include <random>
using namespace std;

typedef long long LL;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<LL> VL;
typedef vector<pair<LL, LL> > VP;
typedef vector<string> VS;
typedef map<int, int> MAPII;
typedef multimap<int, char, greater<int> > MuMAPIC;
typedef multimap<int, string, greater<int> > MuMIS;
typedef pair<int, int> P;
typedef pair<int, pair<P, P> > PP;

#define INF 999999999999999997;
#define MP make_pair
#define FAST_IO  cin.tie(0); ios::sync_with_stdio(false);
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define FORL(i,a,b) for(LL i=(a);i<(b);i++)
#define FOR_REV(i,a,b) for(int i=(a);i>=(b);i--)
#define foreach_it(type,it,c) for(type::iterator it=c.begin(),c_end=c.end();it!=c_end;++it)
#define FOR_ITR(d) for(auto itr=d.begin(),d_end=d.end();itr!=d_end;++itr)	// C++11
#define O(s) cout<<s<<endl;

#define DUMP_VVI(b) FOR(i,0,b.size()){FOR(j,0,b[i].size())printf("%d ",b[i][j]);puts("");}
#define D_OUT(str,value) if(dbgF){cout<<str<<" : "<<value<<endl;}

template<class T>T IN() { T d; cin >> d; return d; }

LL gcd(LL a, LL b) { return (b > 0) ? gcd(b, a%b) : a; } // 最大公約数（Greatest Common Divisor）
LL lcm(LL a, LL b) { return a / gcd(a, b) * b; } // 最小公倍数（Least Common Multiple）
bool uruu(LL Y) { return (((Y % 4 == 0 && Y % 100 != 0) || Y % 400 == 0) ? true : false); } // うるう年判定

int dx[4] = { 0,1,0,-1 };
int dy[4] = { 1,0,-1,0 };
int dxx[8] = { 0,1,1,1,0,-1,-1,-1 };
int dyy[8] = { 1,1,0,-1,-1,-1,0,1 };

// vector注意
// vec[i][j]の形に入力を入れるとき、vecは初期化してある必要がある.

// ------------------- include, typedef, define END. -------------------

int main() {
	FAST_IO;
	bool dbgF = true; // for D_OUT(str, value)  ... cout<< str <<" : "<< value <<endl;

	LL n, a;
	cin >> n >> a;

	n %= 500;
	if (n <= a) {
		O("Yes");
	}
	else {
		O("No");
	}

	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h> 
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
using namespace std;
typedef long long ll;
typedef long double ld;
typedef vector<ll> vl;
typedef pair<ll,ll> pll;
#define MOD 1000000007
#define INF 1000000000
#define mp make_pair
#define pb push_back
#define ss second
#define ff first
#define endl '\n'
#define pl cout<<endl;
void fast() { ios_base::sync_with_stdio(false); cin.tie(NULL);cout.tie(NULL); }
const long long INFll=1ll*INF*INF;
const long double PI=3.141592653589793238462643383279502884197169399375105820974944;
#define all(v) v.begin(),v.end()
#define rall(v) v.rbegin(),v.rend()
#define gcd(a,b) __gcd((a),(b))
#define lcm(a,b) ((a)*(b))/gcd((a),(b))
#define debug(x) cout << x << endl;
#define sz(a) int((a).size())
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
struct custom_hash {
    static uint64_t splitmix64(uint64_t x) {
        // http://xorshift.di.unimi.it/splitmix64.c
        x += 0x9e3779b97f4a7c15;
        x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9;
        x = (x ^ (x >> 27)) * 0x94d049bb133111eb;
        return x ^ (x >> 31);
    }
 
    size_t operator()(uint64_t x) const {
        static const uint64_t FIXED_RANDOM = chrono::steady_clock::now().time_since_epoch().count();
        return splitmix64(x + FIXED_RANDOM);
    }
};
long long genrand(long long L,long long R)
{
	return uniform_int_distribution<long long>(L, R)(rng);
}
//use brackets before operations if taking MOD
//use map only when necessary
//give long long to arrays and variables properly
int mul(int a, int b,int mod = MOD) {
	return int(a * 1ll * b % mod);
}
int norm(int a,int mod = MOD) {
	while(a >= mod) a -= mod;
	while(a < 0) a += mod;
	//a = (a%mod+mod)%mod;
	return a;
}
int powmod(int x,int y,int mod = MOD){
	int res = 1;
	while(y>0)
	{
		if(y&1)
			res = mul(res,x,mod);
		x = mul(x,x,mod);
		y=y>>1;
	}
	return res;
}
int inv(int a,int mod = MOD) {
	return powmod(a, mod - 2);
}
int main() {
	fast();

	string s; cin>>s;
	if(s[2]==s[3] && s[4]==s[5]){
		cout<<"Yes";
	}
	else{
		cout<<"No";
	}

	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define SORT(x) sort((x).begin(),(x).end())
#define ALL(x) (x).begin(),(x).end()
#define rep(i, n) for(int i = 0; i < n; i++)
#define reps(i, m, n) for(ll i = m; i < n; i++)
#define repr(i, m, n) for(int i = m; i >= n; i--)
template<class T>bool maxi(T &a,const T &b){if(a<b){ a=b; return 1;} return 0;}
template<class T>bool mini(T &a,const T &b){if(b<a){ a=b; return 1;} return 0;}
#define y0 y3487465 //j0
#define j1 j1347829 //j1
#define INF2 4000000000000000037
#define INF 1000000007
#define PI (acos(-1))
#define MOD 1000000007
using namespace std;
typedef long long ll;

const int MAX = 200010;
ll fac[MAX], finv[MAX], inv[MAX];
void cinit() { // O(nlogn)
  fac[0] = fac[1] = 1;
  finv[0] = finv[1] = 1;
  inv[1] = 1;
  reps(i, 2, MAX){
    fac[i] = fac[i - 1] * i % MOD;
    inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
    finv[i] = finv[i - 1] * inv[i] % MOD;
  }
}
ll c(int n, int k){ // 二項係数計算
  if (n < k) return 0;
  if (n < 0 || k < 0) return 0;
  return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

void Main(){

  cinit();

  ll N,M,K; cin>>N>>M>>K;

  ll ans=0;

  ans=(c(N*M-2,K-2));

  ll temp=0;

  reps(d,1,M){
    temp=(temp+(d*(M-d)%MOD)*(N*N%MOD))%MOD;
  }
  reps(d,1,N){
    temp=(temp+(d*(N-d)%MOD)*(M*M%MOD))%MOD;
  }

  cout<< ans*temp%MOD <<"\n";

}

//-----------------------------------
int main(){
  cin.tie(nullptr);
  ios_base::sync_with_stdio(false);
  cout << fixed << setprecision(15);
  Main();
}
//-----------------------------------


Measured memory_bytes: 4992
#include <algorithm>
#include <complex>
#include <iomanip>
#include <iostream>
#include <queue>
#include <set>
#include <string>
#include <utility>
#include <vector>

using std::cin;
using std::cout;
using std::endl;

using std::string;
using std::to_string;
using std::vector;
using std::set;
using std::queue;
using std::priority_queue;

using std::min;
using std::max;
using std::sort;
using std::abs;
using std::upper_bound;
using std::lower_bound;
using std::binary_search;

int main(void) {
    int n, m;
    cin >> n >> m;

    vector<int> fst;
    vector<int> sec;
    for (int i = 0; i < m; i++) {
        int a, b;
        cin >> a >> b;
        if(a == 1){
            fst.push_back(b);
        }else if(b == n){
            sec.push_back(a);
        }
    }

    sort(fst.begin(), fst.end());

    bool ans = false;
    for(int s : sec){
        if(binary_search(fst.begin(), fst.end(), s)){
            ans = true;
        }
    }

    cout << (ans ? "POSSIBLE" : "IMPOSSIBLE") << endl;

    return 0;
}


Measured memory_bytes: 1276
include Math
def rad_to_deg(rad)
    rad * 360  / (2 * PI)
end

a, b, x  = gets.split.map(&:to_f)
if a * a * b / 2 >= x
    p 90 -  rad_to_deg(atan(2 * x / (a * b * b)))
else
    p rad_to_deg(atan(2 * (b / a - x / a ** 3)))
end


Measured memory_bytes: 1788
#include <bits/stdc++.h>
using namespace std;
#define int long long

int memo[105][100005];

int knapsack(int weight[],int value[],int total,int n)
{
      if(memo[n][total]!=-1)
         return memo[n][total];

      int res;
      if(n==0 || total==0)
      {           
            return 0;
      }
      if(weight[n-1]>total)
      {
            res= knapsack(weight,value,total,n-1);
      }
      else
      {
            res= max(value[n-1]+knapsack(weight,value,total-weight[n-1],n-1),knapsack(weight,value,total,n-1));
      }

      memo[n][total] = res;
      return res;
}
#undef int
int main()
{
#define int long long
      int n,total;
      cin >> n >> total;
      int weight[n],value[n];
      for(int i=0;i<n;i++)
      {
            cin >> weight[i] >> value[i];
      }
      memset(memo,-1,sizeof(memo));
      cout << knapsack(weight,value,total,n) << endl;      
}

Measured memory_bytes: 82304