akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
using namespace std;
int main(void){
    // Your code here!
    int a=0;
    string s;
    getline(cin,s);
    
        for(int i=0; i<s.size(); i++){
        char c = s[i];
        if('A'<=c && c<='Z'){
            c=c+32;
        }
        else if('a'<= c && c<='z'){
            c=c-32;
        }
        cout<<c;
    }
    cout<<endl;
}


Measured memory_bytes: 3116
// C++ code to find number of distinct numbers 
// in a subarray 
#include<bits/stdc++.h> 
using namespace std; 

#define forn(i,e) for(int i=0;i<e;++i)
#define forsn(i,s,e) for(int i=s;i<e;++i)
#define rforn(i,s) for(int i=s;i>=0;--i)
  
const int MAX = 1000001; 
  
// structure to store queries 
struct Query 
{ 
    int l, r, idx; 
}; 
  
// cmp function to sort queries according to r 
bool cmp(Query x, Query y) 
{ 
    return x.r < y.r; 
} 
  
// updating the bit array 
void update(int idx, int val, int bit[], int n) 
{ 
    for (; idx <= n; idx += idx&-idx) 
        bit[idx] += val; 
} 
  
// querying the bit array 
int query(int idx, int bit[], int n) 
{ 
    int sum = 0; 
    for (; idx>0; idx-=idx&-idx) 
        sum += bit[idx]; 
    return sum; 
} 
  
void answeringQueries(int arr[], int n, Query queries[], int q) 
{ 
    // initialising bit array 
    int bit[n+1]; 
    memset(bit, 0, sizeof(bit)); 
  
    // holds the rightmost index of any number 
    // as numbers of a[i] are less than or equal to 10^6 
    int last_visit[MAX]; 
    memset(last_visit, -1, sizeof(last_visit)); 
  
    // answer for each query 
    int ans[q]; 
    int query_counter = 0; 
    for (int i=0; i<n; i++) 
    { 
        // If last visit is not -1 update -1 at the 
        // idx equal to last_visit[arr[i]] 
        if (last_visit[arr[i]] !=-1) 
            update (last_visit[arr[i]] + 1, -1, bit, n); 
  
        // Setting last_visit[arr[i]] as i and updating 
        // the bit array accordingly 
        last_visit[arr[i]] = i; 
        update(i + 1, 1, bit, n); 
  
        // If i is equal to r of any query  store answer 
        // for that query in ans[] 
        while (query_counter < q && queries[query_counter].r == i) 
        { 
            ans[queries[query_counter].idx] = 
                     query(queries[query_counter].r + 1, bit, n)- 
                     query(queries[query_counter].l, bit, n); 
            query_counter++; 
        } 
    } 
  
    // print answer for each query 
    for (int i=0; i<q; i++) 
        cout << ans[i] << endl; 
} 
  
// driver code 
int main() 
{ 
    int n,q; cin>>n>>q;
    int a[n]; forn(i,n) cin>>a[i];
    Query queries[q];
    forn(i,q){
        cin>>queries[i].l>>queries[i].r;
        queries[i].l--;
        queries[i].r--;
        queries[i].idx = i;
    }  
    sort(queries, queries+q, cmp); 
    answeringQueries(a, n, queries, q); 
    return 0; 
} 

Measured memory_bytes: 19332
N,M=map(int,input().split())
A=[ list(input()) for i in range(N)]
B=[ list(input()) for i in range(M)]
def match(x,y):
    for i in range(M):
        for j in range(M):
            if A[x+i][y+j]!=B[i][j]:
                return False
    return True
found=False
for i in range(N-M+1):
    for j in range(N-M+1):
        if match(i,j):
            found=True
            break
if found:
    print('Yes')
else:
    print('No')

Measured memory_bytes: 3064
#pragma GCC optimize("Ofast,unroll-loops,no-stack-protector,fast-math")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
//#pragma comment(linker, "/stack:200000000")
 
#include <bits/stdc++.h>
 
using namespace std;
 
typedef long long ll;
typedef unsigned long long ull;
typedef double ld;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef pair<ld,ld> pdd;
 
#define X first
#define Y second
 
//#include <boost/unordered_map.hpp>
//using namespace boost;
 
/*
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> rbtree;
rbtree T;
*/
 
using i32 = int;
using i64 = long long;
using u8 = unsigned char;
using u32 = unsigned;
using u64 = unsigned long long;
using f64 = double;
using f80 = long double;
//using i128 = __int128_t;
//using u128 = __uint128_t;
//using i128 = i64;
//using u128 = u64;
 
ll power(ll a, ll b, ll p)
{
	if (!b) return 1;
	ll t = power(a, b/2, p);
	t = t*t%p;
	if (b&1) t = t*a%p;
	return t;
}
 
ll exgcd(ll a, ll b, ll &x, ll &y)
{
	if (b == 0)
	{
		x = 1;
		y = 0;
		return a;
	}
	ll px, py;
	ll d = exgcd(b, a%b, px, py);
	x = py;
	y = px-a/b*py;
	return d;
}

ll gcd(ll a, ll b)
{
	return b ? gcd(b, a%b) : a;
}
 
template<class T>
inline void freshmin(T &a, const T &b)
{
	if (a > b) a = b;
}
 
template<class T>
inline void freshmax(T &a, const T &b)
{
	if (a < b) a = b;
}

template<class T>
void print(const T &a)
{
	for (auto x : a) printf("%d ", x); puts("");
}

const int MAXN = 1010;
const int MAXM = 30*30*16*16+10;
const int MAXK = 19;
const i64 INF = 1000000000000000000LL;
//const int INF = 1000000000;
//const int MOD = 998244353;
//const int MOD = 1000000007;
//const int INV2 = (MOD+1)/2;
const ld pi = 3.1415926535897932384626433;

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

int H, W, A, B;
int f[MAXN];

void solve(int X, int Y)
{
	for (int i = 1; i <= W; ++ i)
		f[i] = (i <= Y) ? B : H-B;
	for (int i = 1; i <= H; ++ i)
	{
		int has = (i <= X) ? A : W-A;
		for (int j = 1; j <= W; ++ j)
		{
			if (has && f[j])
			{
				f[j] --;
				has --;
				putchar('1');
			}
			else
				putchar('0');
		}
		puts("");
	}
}

void solve()
{
	cin >> H >> W >> A >> B;
	for (int X = 0; X <= H; ++ X)
		for (int Y = 0; Y <= W; ++ Y)
			if (X*A+(H-X)*(W-A) == Y*B+(W-Y)*(H-B))
			{
				solve(X, Y);
				return;
			}
	puts("-1");
}

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


Measured memory_bytes: 1280
#include <iostream>
#include <vector>
#include <array>
#include <algorithm>

using namespace std;

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

    vector<array<int, 2>> red, blue, sub = {{0, 10000}};
    array<int, 2> buf;
    for(int i = 0; i < n; i++) {
        cin >> buf[0] >> buf[1];
        red.push_back(buf);
    }

    for(int i = 0; i < n; i++) {
        cin >> buf[0] >> buf[1];
        blue.push_back(buf);
    }

    sort(red.begin(), red.end(), [](auto& x, auto& y) {return x[0] < y[0];});
    sort(blue.begin(), blue.end(), [](auto& x, auto& y) {return x[0] < y[0];});

    for(auto a : blue) {
        while(!red.empty() && red[0][0] < a[0]) {
            sub.push_back(red[0]);
            red.erase(red.begin());
        }

        sort(sub.begin(), sub.end(), [](auto& x, auto& y) {return x[1] < y[1];});
        auto it = lower_bound(sub.begin(), sub.end(), a, [](auto x, auto y) {return x[1] < y[1];});
        if(it != sub.begin()) sub.erase(it - 1);
    }

    cout << n - sub.size() - red.size() + 1 << endl;
}

Measured memory_bytes: 3176
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef set<int> si;
typedef pair<int,int> pii;
#define rep(i,a,b) for(int i=(a); i<(b); ++i)
#define per(i,a,b) for(int i=(b)-1; i>=(a); --i)
#define all(x) (x).begin(),(x).end()
#define sz(x) (int)(x).size()
#define mp make_pair
#define pb push_back
#define F first
#define S second
const int INF = 987654321;
const ll MOD = 1000000007;
//const long double PI = (acos(-1));
//const long double EPS = 0.0000000001;
int dy[2] = {0, 0};
int dx[2] = {-1, 1};

struct DJset {
	vi parent, rank, size;

	DJset(int n) : parent(n), rank(n, 1), size(n, 1) {
		rep(i,0,n) {
			parent[i] = i;
		}
	}

	int find(int i) {
		if(i == parent[i]) return i;
		return parent[i] = find(parent[i]);
	}

	void merge(int u, int v) {
		u = find(u); v = find(v);
		if(u == v) return;
		if(rank[u] > rank[v]) swap(u, v);
		parent[u] = v;
		if(rank[u] == rank[v]) ++rank[v];
		size[v] += size[u];
	}
};

int main(void) {
	ios_base::sync_with_stdio(false); 
	cin.tie(NULL); 
	cout.tie(NULL);
	//freopen("in.txt", "r", stdin);
	int n;
	string s;
	cin >> n >> s;
	int M = 'A'+0;
	rep(i,0,sz(s)) {
		s[i] = s[i]+n;
		if(s[i] > 'Z') {
			s[i] -= 26;
		}
	}
	cout << s << endl;
	return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
int main()
{
    long int i, n, m, arr[10005], sum=0, a;
    scanf("%ld %ld", &n, &m);
    for(i=0; i<m; i++)
    {
        scanf("%ld", &arr[i]);
        sum+=arr[i];
    }
    if(sum>n)
    {
        printf("-1");
    }
    else
    {
        a=n-sum;
        printf("%ld", a);
    }
    return 0;
}

Measured memory_bytes: 1756
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define repr(i,n) for(int i = (int)(n); i >= 0; i--)
#define all(v) v.begin(),v.end()
typedef long long ll;

int main(){
    ll N;
    cin >> N;
    vector<ll> vec(N);
    rep(i,N){
        cin >> vec[i];
    }
    ll ans = 0;
    rep(i,N){
        ans = ans ^ vec[i];
    }
    rep(i,N){
        ll sub_ans = ans ^ vec[i];
        cout << sub_ans;
        cout << " ";
    }
    cout << endl;
}


Measured memory_bytes: 4756
import copy
n=input()
mylist=[]
for i in range(n):
   mylist.append(raw_input().split())
mylistn=[]
for i in range(n):
    mylistn.append([i+1, mylist[i][0],int(mylist[i][1])])
mylistnn=sorted(mylistn,key=lambda x:(x[1],-x[2]))
for i in range(n):
    print(mylistnn[i][0])

Measured memory_bytes: 2692
#include <iostream>
#include <sstream>
#include <algorithm>
#include <cstdio>
#include <string>
#include <vector>
#include <cmath>

//AOJ0078
#define rep(x,to) for(int x=0;x<to;x++)
#define rep2(x,from,to) for(int x=from;x<to;x++)

using namespace std;

double sanka(double x1,double y1,double x2,double y2,double x3,double y3){
	double s12 = sqrt((x1-x2)*(x1-x2)+(y1-y2)*(y1-y2));
	double s23 = sqrt((x2-x3)*(x2-x3)+(y2-y3)*(y2-y3));
	double s13 = sqrt((x1-x3)*(x1-x3)+(y1-y3)*(y1-y3));
	double z = (s12 + s23 + s13)/2;
	return sqrt(z*(z-s12)*(z-s23)*(z-s13));
}

int main(void){

double pt[21][2];
int z=0;
char k;
	
	while(!cin.eof()){

		cin >> pt[z][0] >> k >> pt[z][1];
		if(cin.eof()) break;
		z++;
	}
	double dx=0, dy=0;
	rep(i,z){
		dx += pt[i][0];
		dy += pt[i][1];
	}
	dx = dx / z; dy = dy / z;
//	printf("%d %f %f\n", z,dx,dy);
	double ans=0;
	
	rep(i,z-1){
		ans += sanka(dx,dy,pt[i][0],pt[i][1],pt[i+1][0],pt[i+1][1]);
	}
	ans += sanka(dx,dy,pt[0][0],pt[0][1],pt[z-1][0],pt[z-1][1]);
	printf("%.8f\n",ans);
	
	return 0;
	
}

Measured memory_bytes: 1240
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair < int, int >;

void solve() {
	int n;
	string s;
	cin >> n >> s;
	int ans = 0;
	for (int i = 0; i < n - 2; i++) {
		if (s[i] == 'A' && s[i + 1] == 'B' && s[i + 2] == 'C') {
			ans++;
		}
	}
	cout << ans << endl;
}

int main() {
	ios::sync_with_stdio (false);
	int t;
	t = 1;
	//cin >> t;
	while (t--) {
		solve();
	}
	return 0;
}



Measured memory_bytes: 256
#include <iostream>
#include <numeric>
#define SIZE_OF_ARRAY(array) (sizeof(array)/sizeof(array[0]))
using namespace std;

int main() {
  int n, i;
  int t, s1, s2, diff, minDiff = 10000;
  // input
  cin >> n;
  int w[n];
  for (i=0; i<n; i++) {
    cin >> w[i];
  }

  // calc
  for (int t=1; t<n; t++) {
    // cout << t << "\t";
    s1 = accumulate(w, w+t, 0);
    s2 = accumulate(w+t, w+n, 0);
    diff = abs(s1-s2);
    // cout << s1 << "\t" << s2 << "\t" << diff << endl;
    if (minDiff > diff) {
      minDiff = diff;
    }
  }

  // output
  cout << minDiff << endl;
  return 0;
}


Measured memory_bytes: 256
#include <algorithm>
#include <deque>
#include <iostream>
#include <map>
#include <math.h>
#include <string.h>
#include <vector>

using namespace std;
int main() {
    string S;
    int ans=700;
    cin >> S;
    for(char i : S){
        if(i == 'o') {
            ans+=100;
        }
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
	public static Scanner sc = new Scanner(System.in);
	public static void main(String[] args) {
		int A = sc.nextInt();
		int B = sc.nextInt();
		if(A % 2 == 1 && B % 2 == 1){
			System.out.println("Yes");
		}else{
			System.out.println("No");
		}
	}

}


Measured memory_bytes: 23764
#include<bits/stdc++.h>
using namespace std;
#define optimize() ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define nl '\n'
int main()
{
    optimize();
    int n,i;
    cin>>n;
    map<int,int>cnt;
    for(i=0;i<n;i++)
    {
        int a;
        cin>>a;
        cnt[a]++;
    }
    int ans=0;
    for(auto u:cnt)
    {
        if(u.second>=u.first) ans+=(u.second-u.first);
        else ans+=u.second;
    }
    cout<<ans<<nl;
}



Measured memory_bytes: 8112
#include "bits/stdc++.h"
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
#define all(s) s.begin(), s.end()
using namespace std;
typedef long long int ll;
typedef pair<int,int> P;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<P> vp;
typedef vector<string> vs;
const int MX = 100005, INF = 1001001001;
const ll LINF = 1e18;
const double eps = 1e-10;
const int DIV = 1e9+7;

int n;
vi row1, row2;

int main()
{
    cin >> n;
    row1.resize(n); row2.resize(n);
    rep(i, n){
        int in; cin >> in;
        if(i == 0) row1[i] = in;
        else row1[i] = row1[i - 1] + in;
    }
    vi buf(n); rep(i, n) cin >> buf[i];
    drep(i, n){
        if(i == n - 1) row2[i] = buf[i];
        else row2[i] = row2[i + 1] + buf[i];
    }


    int ans = -1;
    rep(i, n){
        int val = row1[i] + row2[i];
        ans = max(ans, val);
    }
    cout << ans << endl;

    return 0;

}

Measured memory_bytes: 256
#include <iostream>
using namespace std;
 
int main(){
    int R;
    scanf("%d", &R);
    if (R < 1200){
        cout << "ABC" << endl;
    }else if (R < 2800){
        cout << "ARC" << endl;
    }else {
        cout << "AGC" << endl;
    }
    return 0;
}

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

using namespace std;

#define INPUT_OUTPUT { \
    freopen("input.txt", "r", stdin); \
    freopen("output.txt", "w", stdout); \
}

int main()
{
    // INPUT_OUTPUT;
    int a, b, c;
    scanf("%d %d %d", &a, &b, &c);
    int v = a-b;
    int ans = c-v;
    if(ans >= 0) printf("%d\n", ans);
    else printf("0\n");
    return 0;
}


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

int main()
{
	int n;
	cin >> n;
	map<int, int> mp;
	for (int i = 0; i < n; i++) {
		int a;
		cin >> a;
		if (mp.count(a)) mp[a]++;
		else mp[a] = 1;
	}

	vector<pair<int, int>> length_count;
	for (const auto& item : mp) length_count.push_back(make_pair(item.first, item.second));
	sort(length_count.begin(), length_count.end(), greater<pair<int, int>>());

	vector<ll> side;
	int count = 0;
	for (const auto& item : length_count) {
		if (4 <= item.second) {
			side.push_back(item.first);
			side.push_back(item.first);
			count += 2;
		}
		else if (2 <= item.second) {
			side.push_back(item.first);
			count++;
		}
		if (count == 2) break;
	}
	if (count < 2) cout << 0 << endl;
	else cout << side[0] * side[1] << endl;
}


Measured memory_bytes: 6136
#include <iostream>
#include <vector>
#include <set>
#include <queue>
#include <stack>
#include <map>
#include <limits>
#include <string>
#include <algorithm>
#include <bitset>
#include <unordered_set>
#include <unordered_map>
#include <map>
#include "math.h"
#include "assert.h"

using namespace std;

#define ll long long

#define BUFF ios::sync_with_stdio(false)
#define epsilon 1e-07
#define pi 2 * acos(0.0);
#define mod 1000000007   // 1e9+7
#define cerr if(false)cerr
#define watch(x) cerr << #x << " = " << x << endl;

#define inf std::numeric_limits<int>().max();

int main() {
	int n;
	cin >> n;
	vector<int> v(n);
	for(int i=0; i<n; i++) {
		cin >> v[i]; 
	}
	int sum = 0;
	for(int i=0; i<n; i++) {
		for(int j=i+1; j<n; j++) {
			sum += v[i]*v[j];
		}
	}
	cout << sum << endl;
}


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

int main(){
    int s;
    cin>>s;
    int hour,min,sec;
    hour=s/3600;
    min=(s%3600)/60;
    sec=(s%3600)%60;
    cout<<hour<<":"<<min<<":"<<sec<<endl;
    
    return 0;
}


Measured memory_bytes: 3096
package main

import (
        "fmt"
)

func main() {
        a := 0
        b := 0
        c := 0
        x := 0
        fmt.Scan(&a, &b, &c, &x)
        cnt := 0
        for ii := 0; ii <= a; ii++ {
                for jj := 0; jj <= b; jj++ {
                        for kk := 0; kk <= c; kk++ {
                                sum := 500*ii + 100*jj + 50*kk
                                if sum == x {
                                        cnt++
                                }
                        }
                }
        }
        fmt.Println(cnt)
}

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

int main()
{
	int k;
	scanf("%d",&k);
	printf("%d\n",(k/2)*(k%2?(k/2+1):(k/2)));
}


Measured memory_bytes: 256
from sys import stdin
from math import sqrt
from collections import defaultdict

MOD = 1000000007
def is_prime(x):
    if x == 2:
        return True

    if x < 2 or x % 2 == 0:
        return False

    i = 3
    while i <= sqrt(x):
        if x % i == 0:
            return False
        i = i + 2
    
    return True


N = int(stdin.readline().rstrip())
primes = []
for i in range(2, N+1):
    if is_prime(i):
        primes.append(i)

dic = defaultdict()
for i in primes:
    dic[i] = 0

for i in range(2, N+1):
    for j in primes:
        while i % j == 0:
            i /= j
            dic[j] += 1

ans = 1
for i in primes:
    ans *= (1+dic[i])

print(ans % MOD)

Measured memory_bytes: 3316
#pragma GCC optimize ("O3")
#pragma GCC optimize("unroll-loops")
#pragma GCC target("sse4")
#include"bits/stdc++.h"
using namespace std;
typedef long long ll;
#define int ll
#define sz(x) (int)(x).size();
#define all(x) x.begin(), x.end()
#define trav(i,a) for(auto &i:a) 
inline int in(){int x;scanf("%lld",&x);return x;}
const int mod=1e9+7;
int f[2][64];
int modp(int a,int b)
{
	if(b==0)return 1;
	int u=modp(a,b/2);
	u=(u*u)%mod;
	if(b&1)return (a*u)%mod;
	return u;
}
int32_t main()
{
	int n=in();int x;
	
	for(int i=0;i<n;i++)
	{
		x=in();
		for(int j=0;j<64;j++)
		{
			f[(x>>j)&1][j]++;
		}
	}
	int ans=0;
	for(int i=0;i<64;i++)
	{
		x=(f[0][i]*f[1][i])%mod;
		x*=modp(2,i);
		x%=mod;
		ans+=x;ans%=mod;		
	}
	cout<<ans;
	
	
	
}

Measured memory_bytes: 3728
N = int(input())
A = list(map(int, input().split()))
free = 0
color = set()
for i in range(N):
    if A[i]<3200:
        color.add(A[i]//400)
    else:
        free += 1
c = len(color)
if c>0:
    print(c,c+free)
else:
    print(1,free)

Measured memory_bytes: 3064
#include <bits/stdc++.h>
#define For(i, a, b) for(int (i)=(int)(a); (i)<(int)(b); ++(i))
#define rFor(i, a, b) for(int (i)=(int)(a)-1; (i)>=(int)(b); --(i))
#define rep(i, n) For((i), 0, (n))
#define rrep(i, n) rFor((i), (n), 0)
#define fi first
#define se second
using namespace std;
typedef long long lint;
typedef unsigned long long ulint;
typedef pair<int, int> pii;
typedef pair<int, lint> pil;
typedef pair<lint, lint> pll;
template<class T> bool chmax(T &a, const T &b){if(a<b){a=b; return true;} return false;}
template<class T> bool chmin(T &a, const T &b){if(a>b){a=b; return true;} return false;}
template<class T> T div_floor(const T a, const T b){return a>=0 ? a/b : (a+1)/b-1;}
template<class T> T div_ceil(const T a, const T b){return a>=0 ? (a-1)/b+1 : a/b;}

constexpr lint mod = 1e9+7;
constexpr lint INF = mod*mod;
constexpr int MAX = 100010;

int main(){
    int n;
    scanf("%d", &n);
    vector<int> s(MAX, 0);
    s[0] = 1;
    s[MAX-1] = -1;
    rep(i, n){
        int a, b;
        scanf("%d%d", &a, &b);
        ++s[a];
        --s[b+1];
    }
    partial_sum(s.begin(), s.end(), s.begin());
    int ans = 0;
    rep(i, MAX)if(i <= s[i]) ans = i-1;
    printf("%d\n", ans);
}


Measured memory_bytes: 3420
def main():

    tmp=list(map(int,input().split()))
    X = tmp[2]
    Y = tmp[3]
    xl = max(list(map(int,input().split())))
    yl = min(list(map(int,input().split())))

    for i in range(X+2,Y+1):
        if xl < i and i <= yl:
            print("No War")
            exit()

    print("War")
        
    
if __name__== "__main__":
    main() 


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

using namespace std;

void init(bool t[])
{
	for (int i = 1; i <= 13; i++) {
		t[i] = false;
	}
}

void print(string n, bool t[])
{
	for (int i = 1; i <= 13; i++) {
		if (t[i] == false) {
			cout << n << " " << i << endl;
		}
	}
}


int main()
{
	int n;
	string s;
	int v;
	bool S[14], H[14], D[14], C[14];

	init(S);
	init(H);
	init(C);
	init(D);

	cin >> n;

	for (int i = 0; i < n; i++) {
		cin >> s >> v;
		if (s == "S") {
			S[v] = 1;
		} else if (s == "H") {
			H[v] = 1;
		} else if (s == "C") {
			C[v] = 1;
		} else if (s == "D") {
			D[v] = 1;
		}
	}
	print("S", S);
	print("H", H);
	print("C", C);
	print("D", D);

	return 0;
}



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

int fib(int n, int a, int b);

int main()
{
	int n;
	cin >> n;
	cout << fib(n - 1, 1, 1) << endl;
	return (0);
}


int fib(int n, int a, int b){
	int f;
	f = a;
	if (n >= 1){
		return(fib(n - 1, a + b, a));
  }
	else {
	  return (f);
	}
}

Measured memory_bytes: 1160
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n)for(int i=0;i<(n);i++)
#define ALL(a) (a).begin(), (a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define pb push_back
using ll = long long;
using P = pair<int, int>;

void chmin(ll &a, ll b) {if(a > b) a = b;}
const ll INF = 1LL<<59;

int main(){
    int a, b, q; cin >> a >> b >> q;
    vector<ll> s(a), t(b);
    rep(i,a) cin >> s[i];
    rep(i,b) cin >> t[i];
    s.push_back(-INF); s.push_back(INF); sort(ALL(s));
    t.push_back(-INF); t.push_back(INF); sort(ALL(t));
    rep(i,q){
        ll x; cin >> x;
        ll ans = INF;
        int si = lower_bound(ALL(s), x) - s.begin();
        int ti = lower_bound(ALL(t), x) - t.begin();
        for(int j = si-1; j <= si; ++j){//-INF,INFで配列外参照がない
            for(int k = ti-1; k<=ti; ++k){
                ll S = s[j];
                ll T = t[k];
                chmin(ans, abs(x - S) + abs(S - T));
                chmin(ans, abs(x - T) + abs(T - S));
            }
        }
        cout << ans << endl;
    }
}

Measured memory_bytes: 2912
/**
 * code generated by JHelper
 * More info: https://github.com/AlexeyDmitriev/JHelper
 * @author aryssoncf
 */

#include <bits/stdc++.h>
//
// Created by aryssoncf on 28/10/2019.
//

#include <type_traits>


#include <iterator>
#include <utility>

template<typename T>
constexpr auto hasBegin(int) -> decltype(std::begin(std::declval<T>()), true) {
    return true;
}

constexpr bool hasBegin(...) {
    return false;
}

template<typename T>
using IsContainer = std::integral_constant<bool, hasBegin<T>(0)>;


#ifndef JHELPER_EXAMPLE_PROJECT_IO_HPP
#define JHELPER_EXAMPLE_PROJECT_IO_HPP

#endif //JHELPER_EXAMPLE_PROJECT_IO_HPP

template<typename T>
std::istream &operator>>(std::istream &is, std::vector<T> &vec) {
    for (T &element: vec) {
        is >> element;
    }
    return is;
}

template<typename T, typename U>
std::istream &operator>>(std::istream &is, std::pair<T, U> &p) {
    is >> p.first;
    is >> p.second;
    return is;
}

template<class X, class Y>
std::ostream &operator<<(std::ostream &os, std::pair<X, Y> const &p) {
    return os << p.first << " " << p.second;
}

template<class Ch, class Tr, class Container>
std::basic_ostream<Ch, Tr> &operator<<(std::basic_ostream<Ch, Tr> &os, Container const &x) {
    bool first = true;
    for (auto &y : x) {
        if (first) {
            first = false;
        } else {
            os << " ";
        }
        os << y;
    }
    return os;
}


#include <vector>
#include <cstddef>

bool isPrime(int n) {
    for (int i = 2; i * i <= n; ++i) {
        if (n % i == 0) {
            return false;
        }
    }
    return n >= 2;
}

bool isPrime(int64_t n) {
    for (int64_t i = 2; i * i <= n; ++i) {
        if (n % i == 0) {
            return false;
        }
    }
    return n >= 2;
}

std::vector<bool> primeMap(std::size_t maxN) {
    std::vector<bool> prime(maxN + 1, true);

    prime[0] = false;
    prime[1] = false;

    for (std::size_t i = 2; i * i <= maxN; ++i) {
        if (prime[i]) {
            if (i * 1ULL * i <= maxN) {
                for (std::size_t j = i * i; j <= maxN; j += i) {
                    prime[j] = false;
                }
            }
        }
    }
    return prime;
}

std::vector<int> allPrimes(int maxN) {
    std::vector<int> result;
    result.reserve(maxN);
    std::vector<bool> map = primeMap(maxN);
    for (int i = 0; i <= maxN; i++) {
        if (map[i]) {
            result.push_back(i);
        }
    }
    return result;
}

int nextPrime(int n) {
    while (!isPrime(n)) {
        ++n;
    }
    return n;
}


using namespace std;

/*
PROG:
LANG: C++
*/

class C {
public:
    void solve(std::istream &in, std::ostream &out) {
        int x;
        in >> x;
        int res = nextPrime(x);
        out << res << "\n";
    }

    void setup() {}
};


int main() {
    std::ios_base::sync_with_stdio(false);
    C solver;
    solver.setup();
    std::istream &in(std::cin);
    std::ostream &out(std::cout);
    in.tie(nullptr);
    out << std::fixed;
    out.precision(20);
    solver.solve(in, out);
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
using namespace std;
int main(){
	int a, b;
	cin >> a >> b;
	if (a % 3 == 0 || b % 3 == 0 || (a + b) % 3 == 0){ cout << "Possible" << endl; }
	else{ cout << "Impossible" << endl; }
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
using P = pair<int, int>;
const int mod = 1000000007;
struct mint
{
  ll x; // typedef long long ll;
  mint(ll x = 0) : x((x % mod + mod) % mod) {}
  mint operator-() const { return mint(-x); }
  mint &operator+=(const mint a)
  {
    if ((x += a.x) >= mod)
      x -= mod;
    return *this;
  }
  mint &operator-=(const mint a)
  {
    if ((x += mod - a.x) >= mod)
      x -= mod;
    return *this;
  }
  mint &operator*=(const mint a)
  {
    (x *= a.x) %= mod;
    return *this;
  }
  mint operator+(const mint a) const
  {
    mint res(*this);
    return res += a;
  }
  mint operator-(const mint a) const
  {
    mint res(*this);
    return res -= a;
  }
  mint operator*(const mint a) const
  {
    mint res(*this);
    return res *= a;
  }
  mint pow(ll t) const
  {
    if (!t)
      return 1;
    mint a = pow(t >> 1);
    a *= a;
    if (t & 1)
      a *= *this;
    return a;
  }

  // for prime mod
  mint inv() const
  {
    return pow(mod - 2);
  }
  mint &operator/=(const mint a)
  {
    return (*this) *= a.inv();
  }
  mint operator/(const mint a) const
  {
    mint res(*this);
    return res /= a;
  }
};

mint f(int n)
{
  if (n == 0)
    return 1;
  mint x = f(n / 2);
  x *= x;
  if (n % 2 == 1)
    x *= 2;
  return x;
}

mint choose(int n, int a)
{
  mint x = 1, y = 1;
  rep(i, a)
  {
    x *= n - i;
    y *= i + 1;
  }
  return x / y;
}
struct combination {
  vector<mint> fact, ifact;
  combination(int n):fact(n+1),ifact(n+1) {
    assert(n < mod);
    fact[0] = 1;
    for (int i = 1; i <= n; ++i) fact[i] = fact[i-1]*i;
    ifact[n] = fact[n].inv();
    for (int i = n; i >= 1; --i) ifact[i-1] = ifact[i]*i;
  }
  mint operator()(int n, int k) {
    if (k < 0 || k > n) return 0;
    return fact[n]*ifact[k]*ifact[n-k];
  }
};

int main(){
  int x, y;
  int n;
  mint ans = 0;
  cin >> x >> y;
  if ((x + y) % 3 != 0){
    cout << 0 << endl;
    return 0;
  }
  n = (x + y) / 3;
  x -= n, y -= n;
  if (x < 0 || y < 0){
    cout << 0 << endl;
    return 0;
  }
  combination c(x + y);
  ans = c(x + y, x);
  cout << ans.x << endl;
  return 0;
}

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

using namespace std;

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

using ll = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;

template<class T>
void print_container(T &container, string delim=" ") {
    bool first = true;
    for(auto &t: container){
        if(!first){
            cout << delim;
        }
        first = false;
        cout << t;
    }
    cout << endl;
}

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

    int cnt = 1;
    REP(i, n){
        if(i > 0 && s[i] != s[i-1])
            cnt++;
    }
    cout << cnt << endl;
    return 0;
}

Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
typedef long long int lli;
typedef vector <int> vi;
typedef vector <vi> vvi;
typedef pair <int,int> pr;
#define fr(i, n) for(int i = 0; i < n; i++)
#define sz(a) int((a).size())
#define pb push_back
#define all(c)(c).begin(), (c).end()
#define tr(c, i) for (typeof ((c).begin() i = (c).begin(); i != (c).end(); i++)
#define present(c, x)((c).find(x) != (c).end())
#define cpresent(c, x)(find(all(c), x) != (c).end())
// for mod power a^b%m use power<lli> (a,b,m)
template < class mytype >
mytype power(mytype a, mytype b, mytype m){if (b == 1) return a % m;if (b == 0) return 1;
lli root = power < lli > (a, b / 2, m);lli ans = (root * root) % m;if (b % 2) ans = (ans * a) % m;
return ans;
}
// for gcd use gcd<int> (a,b)
template < class type >type gcd(type a, type b){if (a == 0) return b;else return gcd(b % a, a);}
template < class type >type mod_inv(type a, type p) {return power(a, p - 2, p);}

// use from here bitches
int n;
vector<int> height(100002) , values(100002 , -1);
int dp(int x){
if(values[x] != -1) return values[x];
if(x >= n-1) return 0;
if(x >= n-2) return values[x] = abs(height[x+1] - height[x]);
else return values[x] = min(abs(height[x+1] - height[x]) + dp(x+1) , abs(height[x+2] - height[x]) + dp(x+2));
}


int main()
{    
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cin >> n;
	fr(i , n){
		cin >> height[i];
	}
	cout << dp(0);
		

	


    return 0;
	
}


Measured memory_bytes: 3328
a,b,m = map(int,input().split())
a = list(map(int,input().split()))
b = list(map(int,input().split()))
ls = []
ans = min(a)+min(b)
for i in range(m):
    x,y,c = list(map(int,input().split()))
    ans = min(ans,(a[x-1]+b[y-1]-c))

print(ans)

Measured memory_bytes: 18736
#include <bits/stdc++.h>
#define fst first
#define snd second
#define fore(i,a,b) for(int i=a,ThxDem=b;i<ThxDem;++i)
#define pb push_back
#define ALL(s) s.begin(),s.end()
#define FIN ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define SZ(s) int(s.size())
using namespace std;
typedef long long ll;
typedef pair<int,int> ii;

const int MAXN=1e6+10;
int am[MAXN],val[MAXN];

int main(){FIN;
	int n,ans=0; cin>>n;
	vector<int> a(n);
	fore(i,0,n){
		cin>>a[i];
		am[a[i]]++;
	}
	fore(i,1,MAXN) for(int j=i;j<MAXN;j+=i) val[j]+=am[i];
	
	fore(i,0,n){
		ans+=val[a[i]]==1;
	}
	cout<<ans<<"\n";
}

Measured memory_bytes: 11756
#include<iostream>
#include<string>
#include<vector>

using namespace std;

int main(){
    int n;
    while(1){
        cin >> n;
        if (n==0) return 0;
        string tmp;
        int cnt=0,state=0; //1??????:????¶? 2??????:????¶?
        int ud = 0; //??????????????????????????????
        for(int i=0; i<n; i++) {
            cin >> tmp;
            if (tmp == "lu") {
                if (state == 0) state = 2;
                else if (state == 1) {
                    state = 3;
                    if (ud == 0) cnt++; ud=1;
                }
            } else if (tmp == "ru") {
                if (state == 0) state = 1;
                else if (state == 2) {
                    state = 3;
                    if (ud == 0) cnt++; ud=1;
                }
            } else if (tmp == "ld") {
                if (state == 3) state = 1;
                else if (state == 2) {
                    state = 0;
                    if (ud == 1) cnt++; ud=0;
                }
            } else if (tmp == "rd") {
                if (state == 3) state = 2;
                else if (state == 1) {
                    state = 0;
                    if (ud == 1) cnt++; ud=0;
                }
            }
        } 
        cout << cnt << endl;
    }
}

Measured memory_bytes: 3160
package main

import (
	"fmt"
)

func main() {
	var n, k, x, y int
	fmt.Scan(&n)
	fmt.Scan(&k)
	fmt.Scan(&x)
	fmt.Scan(&y)

	if n > k {
		fmt.Println(x*k + y*(n-k))
	} else {
		fmt.Println(x*n)
	}
}


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

int main(void){
    string w;
    cin>>w;
    bool flag =true;
    sort(w.begin(),w.end());
    if (w.size()==1){
        goto end;
    }
    for(int i=0;i<w.size()-1;i++){
        if(w.at(i)!=w.at(i+1)&&i%2==0){
            flag = false;
        }
    }
    if (flag){
        cout<<"Yes"<<endl;
    }else{
        end:
        cout<<"No"<<endl;
    }
}


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

using Pii = pair<int, int>;
using Pll = pair<ll, ll>;

#define REP(i, l, n) for(int i=(l), i##_len=(n); i<i##_len; ++i)
#define ALL(x) (x).begin(),(x).end()
#define pb push_back

int main(){
    ll n, m; cin >> n >> m;
    ll ans = 0;
    vector<vector<ll> > lis(n, vector<ll>(3));
    REP(i, 0, n){
        cin >> lis[i][0] >> lis[i][1] >> lis[i][2];
    }
    REP(i, 0, (1<<3)){
        vector<ll> ch(n, 0);
        REP(l, 0, n){
            ll tmp = 0;
            int c = i;
            REP(k, 0, 3){
                if(c & 1 == 1){
                    tmp += lis[l][k];
                }else{
                    tmp += (-1 * lis[l][k]);
                }
                c/=2;
            }
            ch[l] = tmp;
        }
        sort(ALL(ch), greater<>());
        ll sum = 0;
        REP(l, 0, m){
            sum += ch[l];
        }
        ans = max(ans, sum);
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
# Python3 function to  
# calculate nCr % p 
def ncr(n, r, p): 
    # initialize numerator 
    # and denominator 
    num = den = 1 
    for i in range(r): 
        num = (num * (n - i)) % p 
        den = (den * (i + 1)) % p 
    return (num * pow(den,  
            p - 2, p)) % p 


x, y = map(int,input().split())

if not((x + y) % 3 == 0):
    print(0)
elif (x > 2*y) or (y > 2 * x):
    print(0)
else:
    k = (x + y) // 3
    i = x - k
    print(ncr(k, i, 10 ** 9 + 7))

Measured memory_bytes: 38512
#include <bits/stdc++.h>
#define rep(i,N) for (int i = 0; i < (N); ++i)
#define all(v) v.begin(), v.end()
using namespace std;
using ll = long long;
using P = pair<int, int>;
int main(void){
  int r;
  cin >> r;

  cout << 2 * 3.141 * r << endl;
}


Measured memory_bytes: 3780
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
int main(){
    ll A,N,T;
    vector<ll>V,V1;
    while(cin>>N){
        ll cnt;
        if(N%2){
          cnt=(N/2)+1;
        }
        else{
            cnt=N/2;
        }
        cout << fixed << showpoint;
        cout << setprecision(6);
        cout<<(double)((cnt)/(N*1.00))<<endl;
    }
    return 0;
}


Measured memory_bytes: 256
#入力部
n,k = map(int,input().split())
h = list(map(int,input().split()))

#攻撃:hを1減らす　必殺技:hをすべて減らす制限　k回
#hを降順にソート
h.sort(reverse = True)
#nがkより小さい時全部に必殺技が使えるから0
if n <= k:
    print(0)
#体力が多い順に必殺技を使用して残った体力の合計を出力
else:
    for i in range(k):
        h[i] = 0
    print(sum(h))

Measured memory_bytes: 26764
import sys
sys.setrecursionlimit(10000)
input = sys.stdin.readline

def chkprint(a):
	a_name = ''
	for k, v in globals().items():
		if id(v) == id(a):
			a_name = k
			break
	print(a_name+' = '+str(a), file=sys.stderr)

def mt(f):
	import time
	def wrap(*args, **kwargs):
		s = time.time()
		ret = f(*args, **kwargs)
		e = time.time()
		print(e - s, 'sec', file=sys.stderr)
		return ret
	return wrap

A, B = [int(i) for i in input().split()]
if B // A == B / A:
	print(A + B)
else:
	print(B-A)


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

template <typename T> T gcd(T x, T y) {
  if (y == 0)
    return x;
  return gcd(y, x % y);
}

template <typename T> T lcm(T x, T y) {
  if (x == 0 || y == 0)
    return 0;
  return x / gcd(x, y) * y;
}

int ctoi(char c) {
  if (c >= '0' && c <= '9') {
    return c - '0';
  }
  return 0;
}

vector<int> p;
vector<int> r;

void init(int n) {
  p.reserve(n);
  r.reserve(n);
  for (int i = 0; i < n; i++) {
    p[i] = i;
    r[i] = 0;
  }
}

int root(int x) { return p[x] == x ? x : p[x] = root(p[x]); }

bool same(int x, int y) { return root(x) == root(y); }

void unite(int x, int y) {
  x = root(x);
  y = root(y);
  if (x == y)
    return;

  if (r[x] < r[y])
    p[x] = y;
  else {
    p[y] = x;
    if (r[x] == r[y])
      r[x]++;
  }
}

int main() {
  int a, b;
  cin >> a >> b;
  if (a + b == 15) {
    cout << '+' << endl;
  } else if (a * b == 15) {
    cout << '*' << endl;
  } else {
    cout << 'x' << endl;
  }
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <iostream>
#include <algorithm>
#include <vector>
#include <cmath>
#include <string>
#include <functional>
#include <queue>
#include <map>
#define REP(i,n) for(int i=0;i<n;i++)
using namespace std;
typedef long long ll;
typedef pair<ll, ll> l_l;
typedef pair<int, int> i_i;

const int INF = 100000000;

int main(){
    int n;
    cin >> n;
    vector<ll> a(n);
    REP(i, n){
        cin >> a[i];
    }

    ll sum = 0;
    REP(i, n){
        sum += a[i];
    }

    ll tmp = 0;
    for(int i = 1; i < n - 1; i+=2){
        tmp += a[i];
    }
    vector<ll> x(n);
    x[0] = sum - 2 * tmp;
    for(int i = 1; i < n; i++){
        x[i] = 2 * a[i - 1] - x[i - 1];
    }
    REP(i, n){
        cout << x[i] << endl;
    }
}

Measured memory_bytes: 2944
#include <bits/stdc++.h>  // clang-format off
using Int = long long;
#define REP_(i, a_, b_, a, b, ...) for (Int i = (a), lim##i = (b); i < lim##i; i++)
#define REP(i, ...) REP_(i, __VA_ARGS__, __VA_ARGS__, 0, __VA_ARGS__)
struct SetupIO { SetupIO() { std::cin.tie(nullptr), std::ios::sync_with_stdio(false), std::cout << std::fixed << std::setprecision(13); } } setup_io;
#ifndef dump
#define dump(...)
#endif  // clang-format on

/**
 *    author:  knshnb
 *    created: Sat May 23 21:24:48 JST 2020
 **/

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

void solve() {
    Int n, A, B, C, D;
    std::cin >> n >> A >> B >> C >> D;
    std::unordered_map<Int, Int> mp;
    auto solve = [&](auto f, Int x) -> Int {
        if (mp.count(x)) return mp[x];
        Int mi = std::min<__int128_t>(__int128_t(D) * x, 4e18);
        REP(y, std::max(1LL, x - 10), x + 10 + 1) {
            if (y % 2 == 0 && y / 2 < x) {
                chmin(mi, f(f, y / 2) + D * std::abs(y - x) + A);
            }
            if (y % 3 == 0 && y / 3 < x) {
                chmin(mi, f(f, y / 3) + D * std::abs(y - x) + B);
            }
            if (y % 5 == 0 && y / 5 < x) {
                chmin(mi, f(f, y / 5) + D * std::abs(y - x) + C);
            }
        }
        return mp[x] = mi;
    };
    Int ans = std::min<__int128_t>(__int128_t(n) * D, solve(solve, n));
    std::cout << ans << std::endl;
}

signed main() {
    Int T;
    std::cin >> T;
    while (T--) solve();
}


Measured memory_bytes: 8096
#include <iostream>                                                             
using namespace std;
 
#define MAX(a,b) a>b?a:b 
#define MIN(a,b) a>b?b:a
int main()
{
    int a, b, c, max, min;
    cin >> a >> b >> c;
    max = MAX((MAX(a,b)),c);
    min = MIN((MIN(a,b)),c);
    b = a+b+c-max-min;
    a = min;
    c = max;
    cout << a << " " <<  b <<  " " << c << endl;
    return 0;
}



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

using namespace std;

typedef long long ll;
typedef complex<double> point;
#define mapii map<int, int>
#define debug(a) cout << #a << ": " << a << endl
#define debuga1(a, l, r) fto(i, l, r) cout << a[i] << " "; cout << endl
#define fdto(i, r, l) for(int i = (r); i >= (l); --i)
#define fto(i, l, r) for(int i = (l); i <= (r); ++i)
#define forit(it, var) for(__typeof(var.begin()) it = var.begin(); it != var.end(); it++)
#define forrit(rit, var) for(__typeof(var.rbegin()) rit = var.rbegin(); rit != var.rend(); rit++)
#define ii pair<int, int>
#define iii pair<int, ii>
#define ff first
#define ss second
#define mp make_pair
#define pb push_back
#define maxN 1000005
#define MOD 1000000007
#define oo 1000000000000000007LL
#define sz(a) (int)a.size()

const double PI = acos(-1.0);

double fRand(double fMin, double fMax)
{
    double f = (double)rand() / RAND_MAX;
    return fMin + f * (fMax - fMin);
}

template <class T>
T min(T a, T b, T c) {
    return min(a, min(b, c));
}

template <class T>
T max(T a, T b, T c) {
    return max(a, max(b, c));
}

struct Graph {
private:
    vector<vector<int> > g;
    vector<int> comp;
    int n, id;
public:
    Graph(int n): n(n) {
        g.assign(n+1, vector<int>());
    }

    void addEdge(int u, int v) {
        g[u].pb(v); g[v].pb(u);
    }

    void DFS(int u) {
        comp[u] = id;
        for(int v: g[u]) {
            if (!comp[v]) DFS(v);
        }
    }

    vector<int> getComp() {
        comp.assign(n+1, 0);
        id = 0;
        fto(u, 1, n) {
            if (!comp[u]) {
                ++id;
                DFS(u);
            }
        }
        return comp;
    }
};

int main () {
    int n, m, l;
    scanf("%d%d%d", &n, &m, &l);

    Graph g1(n), g2(n);
    fto(i, 1, m) {
        int u, v;
        scanf("%d%d", &u, &v);
        g1.addEdge(u, v);
    }
    fto(i, 1, l) {
        int u, v;
        scanf("%d%d", &u, &v);
        g2.addEdge(u, v);
    }

    vector<int> comp1 = g1.getComp(), comp2 = g2.getComp();

    map<ii, int> ma;
    fto(i, 1, n) ma[mp(comp1[i], comp2[i])]++;

    fto(i, 1, n) printf("%d ", ma[mp(comp1[i], comp2[i])]);

    return 0;
}


Measured memory_bytes: 29312
import java.util.*;

public class Main{
  public static void main(String[] args) {
    Scanner in = new Scanner(System.in);
    int numa = in.nextInt();
    int numb = in.nextInt();
    int capa = in.nextInt();
    int capb = in.nextInt();
    int bora = capa;
    int borb = capb;
    for (int i = 0; i < numa; i++) {
      int num = in.nextInt();
      bora = bora < num ? num : bora;
    }
    for (int i = 0; i < numb; i++) {
      int num = in.nextInt();
      borb = num < borb ? num : borb;
    }
    String ans = bora < borb ? "No " : "";
    System.out.println(ans + "War");
  }
}

Measured memory_bytes: 21844
#include <bits/stdc++.h>
    using namespace std;
     
    int main(){
    ios::sync_with_stdio(false);
        int n, m;
        cin>>n>>m;
        set<int> st,st1;
        for(int i = 1; i <= m; i ++) {
            int x, y;
            cin >> x >> y;
            if(x == 1) st.insert(y);
            if(y == 1) st.insert(x);
            if(x == n) st1.insert(y);
            if(y == n) st1.insert(x);
        }
        set<int>::iterator it;
        for(it = st.begin(); it != st.end(); it ++) {
            if(st1.count((*it))){
                return 0*printf("POSSIBLE\n");
            }
        }
        printf("IMPOSSIBLE\n");
        return 0;
    }

Measured memory_bytes: 9600
#include <iostream>
#include <math.h>
#include <algorithm>
#include <vector>
#include <cstring>
#define ll long long int
#define REP(i, n) for(ll i = 0; i < n; i++)
#define REPR(i, n) for(ll i = n; i >= 0; i--)
#define FOR(i, m, n) for(ll i = m; i < n; i++)
#define INF 2e9
#define ALL(v) v.begin(), v.end()
#define PI 3.141592653589793
using namespace std;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }

// dp[ i + 1 ][ j ] 
//    := i 日目までの活動履歴のうち、最終日である i 日目には活動 j (0: A, 1: B, 2: C) を選んだ場合の、得られる幸福度の最大値
/*
遷移先
dp[ i ][ 0 ] から dp[ i + 1 ][ 1 ] への遷移
dp[ i ][ 0 ] から dp[ i + 1 ][ 2 ] への遷移
dp[ i ][ 1 ] から dp[ i + 1 ][ 0 ] への遷移
dp[ i ][ 1 ] から dp[ i + 1 ][ 2 ] への遷移
dp[ i ][ 2 ] から dp[ i + 1 ][ 0 ] への遷移
dp[ i ][ 2 ] から dp[ i + 1 ][ 1 ] への遷移

遷移式
各 j (= 0, 1, 2) と各 k (= 0, 1, 2) に対して、j ≠≠ k ならば
chmax(dp[ i + 1 ][ k ], dp[ i ][ j ] + a[ i ][ k ])
 // i := i-1日目までで得られる幸福度の最大値 列j-> 活動の選択を把握するため
 // i+1 := i日目までで得られる幸福度の最大値
*/

int main() {
    ll N,ans=0;

    cin >> N;
    ll a[100010][3]; // a,b,c
    // ll dp[1000010][3];
    ll dp[2][3];
    for (int i = 0; i < N; ++i) for (int j = 0; j < 3; ++j) cin >> a[i][j];
    
    for (int i = 0; i < N; ++i) 
        for (int j = 0; j < 3; ++j)
            for (int k = 0; k < 3; ++k) {
                if(j == k) continue;
                chmax(dp[(i+1)%2][k], dp[i%2][j] + a[i][k]);
            }

    for(int j = 0; j < 3; ++j) chmax(ans, dp[N%2][j]);
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 2560
#include<stdio.h>
#include<algorithm>
#include<array>

int main() {
	int n, k, ans = 0;
	std::array<int, 200000> a = { 0 };
	scanf("%d %d", &n, &k);
	for (int i = 0; i < n; ++i) {
		int x;
		scanf("%d", &x);
		++a[x];
	}
	int norma = 0;
	for (auto&& x : a) {
		if (x > 0) ++norma;
	}
	norma -= k;
	std::sort(a.begin(), a.end());
	for (int i = 0; norma > 0; ++i) {
		if (a[i] > 0) {
			--norma;
			ans += a[i];
		}
	}
	printf("%d", ans);
}

Measured memory_bytes: 896
import sys

read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline

in_n = lambda: int(readline())
in_nn = lambda: map(int, readline().split())
in_nl = lambda: list(map(int, readline().split()))
in_na = lambda: map(int, read().split())
in_s = lambda: readline().rstrip().decode('utf-8')


def main():
    N, X = in_nn()
    A = in_nl()

    ans = 0
    for i in range(N):
        if A[i] > X:
            ans += A[i] - X
            A[i] = X

    for i in range(1, N):
        if A[i - 1] + A[i] > X:
            ans += A[i] - (X - A[i - 1])
            A[i] = X - A[i - 1]

    # print(A)
    print(ans)


if __name__ == '__main__':
    main()


Measured memory_bytes: 18348
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cmath>
#include<vector>
#include<utility>
#include<queue>
#include<deque>
#include<stack>
#include<set>
#include<map>
#include<bitset>
#include<climits>
#define MOD 1000000007
typedef long long ll;
using namespace std;

ll dp[100005][13];

int main(){
  string s; cin >> s;
  int n = s.size();
  dp[0][0] = 1;
  for(int i=0;i<n;i++){
    int c;
    if(s[i] == '?') c = -1;
    else c = s[i] - '0';

    for(int j=0;j<10;j++){
      if(c != -1 && c != j) continue;
      for(int k=0;k<13;k++){
        dp[i+1][(k*10+j) % 13] += dp[i][k];
      }
    }
    for(int k=0;k<13;k++) dp[i+1][k] %= MOD;
  }
  cout << dp[n][5] << endl;
  return 0;
}

Measured memory_bytes: 10624