akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;

int parity(int n){
  if(n*n*n*n%10 == 1)
    return 1;
  else
    return 0;
}

long long power(int x, int y){
  if(y < 0)
    return 0;
  else{
    int64_t n = 1ll;
    for(int i = 0; i < y; i++)
      n *= x;
    return n;
  }
}
int digit(int x, int y){
  return x%power(10,y+1)/power(10,y);
}
int card(int n){
  int cnt = 0;
  while(n > 0){
    int n0 = n%10;
    n /= 10;
    if(n0 <= 3 && n%10 == 1){
      cnt++;
      n /= 10;
    }
  }
  return cnt;
}

long long bnps(int n, int a, int d){
  long long an = 0;
  for(int i = 0; i < d; i++){
    an += a%power(n,i+1)/power(n,i)*power(10,i);
  }
  return an;
}

int left(vector<int> vec, int k){
  int a = 0;
  int b = vec.size()-1;
  if(vec.at(a) > k)
    return 0;
  else if(vec.at(a) == k)
    return a;
  else if(vec.at(b) < k)
    return -1;
  else{
    bool bk = true;
    while(bk){
      int c = (a+b)/2;
      if(vec.at(c-1) < k && vec.at(c) == k){
        return c;
        bk = false;
      }
      else if(vec.at(c-1) >= k)
        b = c;
      else if(vec.at(c) < k)
        a = c;
      else{
        return c;
        bk = false;
      }
    }
  }
}

int right(vector<int> vec, int k){
  int a = 0;
  int b = vec.size()-1;
  if(vec.at(a) > k)
    return -1;
  else if(vec.at(b) == k)
    return b;
  else if(vec.at(b) < k)
    return b;
  else{
    bool bk = true;
    while(bk){
      int c = (a+b)/2;
      if(vec.at(c) == k && vec.at(c+1) > k){
        return c;
        bk = false;
      }
      else if(vec.at(c+1) <= k)
        a = c;
      else if(vec.at(c) > k)
        b = c;
      else{
        return c;
        bk = false;
      }
    }
  }
}
int main() {
  int n;
  cin >> n;
  vector<int>l(n);
  for(int i = 0; i < n; i++)
    cin >> l.at(i);
  sort(l.begin(),l.end());
  int cnt = 0;
  for(int i = 2; i < n; i++){
    for(int j = 1; j < i; j++){
      if(l.at(i) >= 2*l.at(j))
        continue;
      cnt += (j-1)-left(l,l.at(i)-l.at(j)+1)+1;
    }
  }
  cout << cnt << endl;
}

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

int main() {
  int n,ans;
  cin >> n;
  ans = n;
  vector<long>data(n);
  for(int i = 0;i < n;i++) cin >> data[i];
  sort(data.begin(),data.end());
  for(int i = 0;i < n-1;i++){
    if(data[i] == data[i+1]){
      ans -= 2;
      i++;
    }
  }
  cout << ans << endl;
}


Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define pb push_back
#define mp make_pair
#define vi vector<int>
#define vl vaector<long>
#define vll vector<long long int>
#define vC  vector<char>
#define FastIO ios::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define db(...) ZZ(#__VA_ARGS__, __VA_ARGS__)
ll pow(ll x, ll y,ll m) { ll res = 1;x=x%m; while (y > 0) { if (y & 1) res = ((res%m) * (x%m))%m; y = y >> 1; x = ((x%m) * (x%m))%m; } return res%m; }
template <typename Arg1> void ZZ(const char* name, Arg1&& arg1){std::cerr << name << " = " << arg1 << endl;}
template <typename Arg1, typename... Args>void ZZ(const char* names, Arg1&& arg1, Args&&... args)
{
	const char* comma = strchr(names + 1, ',');
	std::cerr.write(names, comma - names) << " = " << arg1;
	ZZ(comma, args...);
}
const ll INF = 0xFFFFFFFFFFFFFFFL;
clock_t time_p=clock();
void abhigyan10()
{time_p=clock()-time_p;cerr<<"Time Taken : "<<(float)(time_p)/CLOCKS_PER_SEC<<"\n";}
ll seed;
mt19937 rng(seed=chrono::steady_clock::now().time_since_epoch().count());
inline ll rnd(ll l=0,ll r=INF){return uniform_int_distribution<ll>(l,r)(rng);}
#define clrbuf cin.ignore(numeric_limits<streamsize>::max(),'\n');
#define preciset(x) cout<<setprecision(x)<<fixed;
const ll mod =1000000007;
int main()
{
        FastIO

        int a,b,c,d;
        cin>>a>>b>>c>>d;
        int i=0;
        while(a>0 &&c>0)
        {
        	i++;
        	if(i&1)
        		c-=b;

        	else
        		a-=d;

        }
        if(a<=0)
        	cout<<"No";
        else
        	cout<<"Yes";
        return 0;

    }


Measured memory_bytes: 3632
l,r = map(int,input().split())
num2019 = r//2019 - l//2019
ans = 9999999999
if num2019>=1 or l == 0 or l%2019 ==0:
    ans = 0
else:
    modr = r%2019
    modl = l%2019
    for a in range(l,r+1):
        for b in range(a+1,r+1):
            tmp = (a*b)%2019
            ans = min(ans,tmp)
print(ans)

Measured memory_bytes: 3060
#include<iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <cmath>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
int Manhattan(int a, int b, int x, int y){
	int xaxis = abs(a - x);
	int yaxis = abs(b - y);

	return xaxis + yaxis;
}
int main(){
	int N, M;
	cin >> N >> M;

	P stu[N];
	P check[M];

	for(int i=0;i<N;i++){
		int a, b;
		cin >> a >> b;
		stu[i] = make_pair(a,b);
	}
	for(int i=0;i<M;i++){
		int a, b;
		cin >> a >> b;
		check[i] = make_pair(a,b);
	}

	for(int i=0;i<N;i++){
		int ans = 0;
		int dis = 1000000000;
		for(int j=0;j<M;j++){
			int tmp = Manhattan(stu[i].first, stu[i].second, 
				check[j].first, check[j].second);

			if(tmp < dis){
				dis = tmp;
				ans = j+1; 
			}
		}
		cout << ans <<endl;
	}
	
	return 0;
}

Measured memory_bytes: 256
from collections import Counter

N = int(input())

charList = Counter(input())

for _ in range(N - 1):
    countS = Counter(input())
    for char, num in charList.items():
        if char in countS:
            charList[char] = min(num, countS[char])
        else:
            charList[char] = 0

intersectChar = []
for char, num in charList.items():
    for i in range(num):
        intersectChar.append(char)

intersectChar.sort()
print(''.join(intersectChar))

Measured memory_bytes: 3316
#include <bits/stdc++.h>
using namespace std;
typedef long long lint;
typedef pair<int, int> pi;
const int mod = (441 << 21) + 1;

lint ipow(lint x, lint p){
	lint ret = 1, piv = x % mod;
	while(p){
		if(p&1) ret *= piv;
		piv *= piv;
		ret %= mod;
		piv %= mod;
		p >>= 1;
	}
	return ret % mod;
}

namespace nt_fft{
	const int prr = 5;
	void fft(vector<int> &v, bool inv){
		vector<int> w(v.size());
		for(int i=2; i<=v.size(); i<<=1){
			int bsz = v.size() / i;
			int ang = ipow(prr, (mod - 1) / i);
			if(inv) ang = ipow(ang, mod-2);
			for(int j=0; j<bsz; j++){
				for(int k=0; k<i; k++){
					w[k] = v[j + k * bsz];
				}
				lint cur = 1;
				for(int k=0; k<i/2; k++){
					lint a = w[2*k], b = cur * w[2*k+1] % mod;
					v[j + k * bsz] = (a + b) % mod;
					v[j + k * bsz + v.size()/2] = (a - b + mod) % mod;
					cur = (cur * ang) % mod;
				}
			}
		}
		if(inv){
			lint mul = ipow(v.size(), mod-2);
			for(int i=0; i<v.size(); i++){
				v[i] = (mul * v[i]) % mod;
			}
		}
	}
	vector<int> multiply(vector<int> a, vector<int> b){
		int w = 1;
		while(w < max(a.size(), b.size())) w <<= 1;
		w <<= 1;
		a.resize(w);
		b.resize(w);
		fft(a, 0); 
		fft(b, 0);
		for(int i=0; i<w; i++) a[i] = (1ll * a[i] * b[i]) % mod;
		fft(a, 1);
		return a;
	}
	vector<int> power(vector<int> a){
		int w = 1;
		while(w < a.size()) w <<= 1;
		w <<= 1;
		a.resize(w);
		fft(a, 0);
		for(int i=0; i<w; i++) a[i] = (1ll * a[i] * a[i]) % mod;
		fft(a, 1);
		return a;
	}
}

int n, k, sz[200005];
vector<int> gph[200005];
int cnt[200005];

void dfs(int x, int p){
	sz[x] = 1;
	cnt[n]++;
	for(auto &i : gph[x]){
		if(i == p) continue;
		dfs(i, x);
		cnt[sz[i]]--;
		sz[x] += sz[i];
	}
	cnt[n - sz[x]]--;
}

lint fact[200005], invf[200005];

int main(){
	cin >> n;
	for(int i=1; i<n; i++){
		int s, e;
		scanf("%d %d",&s,&e);
		gph[s].push_back(e);
		gph[e].push_back(s);
	}
	fact[0] = invf[0] = 1;
	for(int i=1; i<=n; i++){
		fact[i] = fact[i-1] * i % mod;
		invf[i] = ipow(fact[i], mod-2);
	}
	dfs(1, 0);
	for(int i=1; i<=n; i++){
		cnt[i] = fact[i] * (cnt[i] + mod) % mod;
	}
	vector<int> p1(n+1), p2(n+1);
	for(int i=0; i<=n; i++){
		p1[i] = invf[n-i];
		p2[i] = cnt[i]; 
	}
	auto w = nt_fft::multiply(p1, p2);
	for(int i=1; i<=n; i++){
		printf("%lld\n", 1ll * w[n+i] * invf[i] % mod);
	}
}



Measured memory_bytes: 31584
N, M = map(int, input().split())
ball_cnt = [1] * N
exist_red = [False] * N
exist_red[0] = True
for _ in range(M):
    x, y = map(int, input().split())
    x -= 1
    y -= 1
    ball_cnt[x] -= 1
    ball_cnt[y] += 1
    if exist_red[x]:
        exist_red[y] = True
    if ball_cnt[x] == 0:
        exist_red[x] = False
print(exist_red.count(True))


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

int main(void){
	int n;
	while(cin >> n,n){
		int vote[110];
		rep(i,26) vote[i]=0;

		char seq[110];
		rep(i,n) cin >> seq[i];

		bool finish = false;

		rep(i,n){
			const int idx = seq[i]-'A';
			vote[idx]++;	
			int rest = n - 1 - i;
			int best = 0;
			rep(j,26) if(vote[best] < vote[j]) best=j;
			
			bool ok = true;
			rep(j,26) if(j!=best and vote[j]+rest >= vote[best]) ok=false;
			if(ok){
				finish = true;
				cout << char(best+'A') << " " <<  i+1  << endl;
				break;
			}
		}

		if(finish==false){
			cout << "TIE" << endl;
		}

	}
	return 0;
}

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

int main() {
    int64_t a, b, c, x, y;
    cin >> a >> b >> c >> x >> y;
    cout << min(x, y) * min(2 * c, a + b) + abs(x - y) * min(2 * c, x > y ? a : b) << endl;
}


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

using namespace std;
using ll = long long;

#define rep(i, a) for (int i = 0; (i) < (int) (a); (i)++)
#define reps(i, a, b) for (int i = (int) (a); (i) < (int) (b); (i)++)
#define rrep(i, a) for (int i = (int) a-1; (i) >= 0; (i)--)
#define rreps(i, a, b) for (int i = (int) (a)-1; (i) >= (int) (b); (i)--)
#define MP(a, b) make_pair((a), (b))
#define PB(a) push_back((a))
#define all(v) (v).begin(), (v).end()
#define PERM(v) next_permutation(all(v))
#define UNIQUE(v) sort(all(v));(v).erase(unique(all(v)), v.end())
#define CIN(type, x) type x;cin >> x
#define TRUE__  "Yes"
#define FALSE__ "No"
#define PRINT(f) if((f)){cout << (TRUE__) << endl;}else{cout << FALSE__ << endl;}
#define RS(N) resize(N)
#define CINV(v, N) do {\
	v.RS(N);\
	rep(i, N) cin >> v[i];\
} while (0);
#define RCINV(v, N) do {\
	v.RS(N);\
	rrep(i, N) cin >> v[i];\
} while (0);

#define MOD 1000000007

void init();
void solve();

signed main()
{
	init();
	solve();
}

ll n, s;

void init()
{
	cin >> n >> s;
}

bool ch(ll b)
{
	ll res = 0;
	ll t = n;
	if (b <= 1) return false;
	while (t) {
		res += t % b;
		t /= b;
	}
	return res == s;
}

void solve()
{
	if (s == n) {
		cout << n+1 << endl;
		return;
	}
	for (ll b = 2; b * b <= n; b++) {
		if (ch(b)) {
			cout << b << endl;
			return;
		}
	}
	ll res = 4e18;
	for (ll x = 1; x * x <= n; x++) {
		if ((n - s) % x) continue;
		ll b = (n - s) / x + 1;
		if (ch(b)) res = min(res, b);
	}
	if (res != 4e18) cout << res << endl;
	else cout << -1 << endl;
}


Measured memory_bytes: 256
// Aizu Vol-1 0139: Snakes
// 2017.8.3

#include <stdio.h>
#include <stdlib.h>

char *gets(char *);
char buf[300], *p;

int main()
{
	int i, n, k1, k2;

// A >'======#======~
// B >^Q=Q=Q=Q=Q=Q=Q=Q=Q=~~
	gets(buf), n = atoi(buf);
	for (i = 0; i < n; i++) {
		gets(p = buf);
		if (*p++ != '>') goto NA;
		if (*p == '\'') {	// A
			k1 = k2 = 0, p++;
			while (*p == '=') k1++, p++;
			if (k1 < 1) goto NA;
			if (*p++ != '#') goto NA;
			while (*p == '=') k2++, p++;
			if (k1 != k2) goto NA;
			if (*p++ != '~') goto NA;
			if (*p) goto NA;
			puts("A");
		}
		else if (*p == '^') {	// B
			p++;
			if (*p++ != 'Q' || *p++ != '=') goto NA;
			while (*p == 'Q' && *(p + 1) == '=') p += 2;
			if (*p++ != '~' || *p++ != '~' || *p) goto NA;
			puts("B");
		}
		else {
NA:			puts("NA");
		}
	}
	return 0;
}

Measured memory_bytes: 524
using System.Collections.Generic;
using System.Linq;
using System;

public class Hello
{
    public static void Main()
    {
        var n = int.Parse(Console.ReadLine().Trim());
        string[] line = ("0 " + Console.ReadLine().Trim()).Split(' ');
        var a = Array.ConvertAll(line, int.Parse);
        getAns(a, n);

    }
    static void getAns(int[] a, int n)
    {
        var b = new int[n + 1];
        var ans = new List<int>();
        for (int i = n; i >= 1; i--)
        {
            if (a[i] != getSum(b, n, i) % 2) { b[i] = 1; ans.Add(i); }
        }
        var ansc = ans.Count();
        Console.WriteLine(ansc);
        if (ansc != 0)
        {
            var ans2 = ans.ToArray();
            Array.Reverse(ans2);
            Console.WriteLine(string.Join(" ", ans2));
        }
    }
    static int getSum(int[] b, int n, int t)
    {
        var sum = 0;
        var t2 = t;
        var p = 2;
        while (t2 <= n)
        {
            sum += b[t2];
            t2 = t * p++;
        }
        return sum;
    }
}


Measured memory_bytes: 35672
#include <iostream>
using namespace std ;
int main (){
	//freopen("input.txt","r",stdin);
long long a , b , k ;
 cin >> a >> b >> k ;

if ( k <= a ){
 cout << a - k <<" "<< b << endl ;
} else if ( k <= a + b ){
cout << 0 <<" " << b - ( k - a ) << endl ;
} else {
cout << 0<<" "<< 0 << endl ;
}
}

Measured memory_bytes: 256
#include<iostream>
using namespace std;
int main(){
    int a;
    int b;
    int c;
    cin >> a >> b >> c;
    if (a < b) {
        if (b < c) {
            cout << "Yes" << endl;
        } else {
            cout << "No" << endl;
        }
    } else {
        cout << "No" << endl;
    }
return 0;
}


Measured memory_bytes: 3084
#include <atcoder/lazysegtree>

#include <bits/stdc++.h>
using namespace std;
using namespace atcoder;
#define ll long long
#define endl '\n'
#define mod 998244353
#define pb push_back
#define ff first
#define ss second
#define con continue
#define ub upper_bound
#define lb lower_bound
#define sum(a)     ( accumulate ((a).begin(), (a).end(), 0ll))
#define mine(a)    (*min_element((a).begin(), (a).end()))
#define maxe(a)    (*max_element((a).begin(), (a).end()))
#define mini(a)    ( min_element((a).begin(), (a).end()) - (a).begin())
#define maxi(a)    ( max_element((a).begin(), (a).end()) - (a).begin())
#define lowb(a, x) ( lower_bound((a).begin(), (a).end(), (x)) - (a).begin())
#define uppb(a, x) ( upper_bound((a).begin(), (a).end(), (x)) - (a).begin())

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

const int dx8[] = { -1, 0, 1, 0,1,1,-1,-1 };
const int dy8[] = { 0, -1, 0, 1,1,-1,1,-1 };
vector<ll> arr, ones;
ll n, q;
struct S
{
    ll sum, size;
};
S op(S a, S b)
{
    assert(b.size <= n);
    return S{((arr[b.size] % mod * a.sum % mod) % mod + b.sum % mod)%mod,a.size+b.size};
}

S e()
{
    return  S{ 0,0 };
}

struct F
{
    ll x;
};
S mapping(F a, S b)
{
    if (a.x == -1) return b;
    assert(b.size <= n);
    return S{ (ones[b.size]%mod*a.x % mod)%mod,b.size };
}
F composition(F a, F b)
{
    if (a.x == -1) return b;
    return a;
}
F id()
{
    return F{-1};
}
void solve()
{
    arr.clear();
    ones.clear();
   

    cin >> n >> q;
    
   
    arr.push_back(1);
    ones.pb(1);
    ones.push_back(1);
    for (ll i = 0; i <= n; i++)
        ones.push_back((ones.back() % mod * 10+1) % mod);
    for (ll i = 0; i <= n; i++)
        arr.push_back((arr.back() % mod * 10) % mod);
    vector<S> arr1(n, S{1,1});

  
    lazy_segtree<S,op,e,F,mapping,composition,id> seg(arr1);
    
    while (q--)
    {
        ll a, b, c; 
        cin >> a >> b >> c;
        --a;
        seg.apply(a, b, F{ c });
        cout << seg.prod(0, n).sum%mod << endl;
       
    }
}




int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int t;
    solve(); 
}



Measured memory_bytes: 19800
from itertools import permutations

N, M = map(int, input().split())
root = [[0] * N for _ in range(N)]
for i in range(M):
    a, b = map(int, input().split())
    root[a-1][b-1] = 1
    root[b-1][a-1] = 1

ans = 0
for r in permutations(range(N)):
    if r[0] != 0: break
    factor = 1
    for i in range(len(r)-1):
        factor *= root[r[i]][r[i+1]]
    ans += factor
print(ans)


Measured memory_bytes: 67852
#include <stack>
#include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <cmath>
#include <array>
#include <iomanip>
#include <string>
using namespace std;
int gcd(int a, int b)
{
   if (a%b == 0)
   {
       return(b);
   }
   else
   {
       return(gcd(b, a%b));
   }
}
int mod = 1000000000 + 7;

int main(){
    //std::stack<int> stack;
    string s;
    cin >> s;
    string ans = "";
    for(int i = 0; i < s.size(); i++){
        if(s[i] == '?'){
            ans += 'D';
        }else{
            ans += s[i];
        }
    }
    cout << ans << endl;
     return 0;
}





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

int main() {
  int N;
  cin >> N;
  vector<int> street(N);
  for(int i = 0; i < N; i++){
    cin >> street.at(i);
  }
  sort(street.begin(), street.end());
  cout << street.at(N - 1) - street.at(0) <<endl;
}

Measured memory_bytes: 256
#include <stdio.h>

int main(){
    int i;
    int x;
    
    scanf( "%d", &x );
    for(int i=3;i<=x;i++){
        int x=i;
        if(i%3==0){
            printf(" %d",i);
        }else{
            do{
                if(x%10==3){
                    printf(" %d",i);
                    break;
                }
                x/=10;
            }
            while(x);
        }
    }
    printf( "\n" );
    return 0;
}

Measured memory_bytes: 1816
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <cstring>
#include <sstream>
#include <map>
#include <set>
#include <cmath>
#include <queue>
#include <stack>
#include <list>
#include <numeric>
#include <bitset>
#include <ext/algorithm>
#include <ext/numeric>
#define ffor(_a,_f,_t) for(int _a=(_f),__t=(_t);_a<__t;_a++)
#define all(_v) (_v).begin() , (_v).end()
#define sz size()
#define pb push_back
#define SET(__set, val) memset(__set, val, sizeof(__set))
#define FOR(__i, __n) ffor (__i, 0, __n)
typedef long long LL; using namespace std;

priority_queue<pair<int, int> > heap;

bool done[1000000];

vector<int> closest[1000000];

int main() {
	vector<pair<int, int> > p;
	vector<pair<int, int > > x, y;
	int N;
	cin >> N;
	int a, b;
	FOR (i, N) {
		cin >> a >> b;
		p.pb(make_pair(a, b));
		x.pb(make_pair(a, i));
		y.pb(make_pair(b, i));
		closest[i].clear();
	}
	sort(all(x));
	sort(all(y));
	SET(done, 0);
	FOR (i, x.sz) {
		int idx = x[i].second;
		if (i)
			closest[idx].pb(x[i - 1].second);
		if (i < x.sz - 1)
			closest[idx].pb(x[i + 1].second);
	}

	FOR (i, y.sz) {
		int idx = y[i].second;
		if (i)
			closest[idx].pb(y[i - 1].second);
		if (i < y.sz - 1)
			closest[idx].pb(y[i + 1].second);
	}
	
	LL ret = 0LL;
	heap.push(make_pair(0, 0));
	while (!heap.empty()) {
		pair<int, int> el = heap.top();
		heap.pop();
		int idx = el.second, dist = el.first;
		if (done[idx])
			continue;
		done[idx] = true;
		ret -= dist;
		FOR (i, closest[idx].sz) {
			int w = closest[idx][i];
			if (done[w])
				continue;
			LL d = min(abs(p[idx].first - p[w].first), abs(p[idx].second - p[w].second));
			heap.push(make_pair(-d, w));
		}
	}
	cout << ret << endl;
	return 0;
}

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


using namespace std;

int main() {

    int x,a,b;
    cin>>x>>a>>b;
    if(abs(x-a)<=abs(x-b)) {
        cout<<"A"<<endl;
    }
    else {
        cout<<"B"<<endl;
    }




   return 0;

}


Measured memory_bytes: 256
//g++ -std=c++14 test.cpp -o test.out
//問題URL
//https://atcoder.jp/contests/panasonic2020/tasks/panasonic2020_e
//参考
//https://misteer.hatenablog.com/entry/ABC116
#include <string.h>
#include <stdlib.h>
#include <math.h>
#include <cassert>
#include <algorithm>
#include <functional>
#include <iostream>
#include <iomanip>
#include <vector>
#include <queue>
#include <map> 
#include <utility>
#include <limits.h>
#include <bitset>
#include <set>
using namespace std;
 
#define LL long long int
const LL INF = (LL)(1e18)+1;
const int INF_INT = 2147483647-1e6;
const LL mod = 1000000007ll;
const int mod_int = 1000000007;

LL N,K;
vector<priority_queue<LL>> dish;//種類iの美味しさを持つ寿司の集合をdish[i]とおく

LL ans = 0;

void solve(){
    priority_queue<LL> best, remain;
    // best: 各種類で一番美味しいやつを集めたもの
    // remain : bestの余り
    for (int i = 0; i < N; ++i) {//種類iの寿司の集合を見ていく
        if (!dish[i].empty()) {//種類iの寿司がまだ1個以上あるなら
            best.push(dish[i].top());//種類iで一番美味しい寿司は優先度付きキューの頭にある
            dish[i].pop();

            while (!dish[i].empty()) {//残りは全部remain行き
                remain.push(dish[i].top());
                dish[i].pop();
            }
        }
    }
    //best,remainはpriority_queueなので勝手に降順にソートされる

    vector<LL> bsum = {0};
    // bestの累積和 (bsum[i] = bestの先頭からi個の総和)
    while (!best.empty()) {
        bsum.push_back(bsum.back() + best.top());
        best.pop();
    }

    vector<LL> rsum = {0};
    // remainの累積和
    while (!remain.empty()) {
        rsum.push_back(rsum.back() + remain.top());
        remain.pop();
    }

    //前者から、美味しい順にx個食べる。 (x種類の確保)
	//後者から、美味しい順にK−x個食べる。
	//この時点で、取った寿司の種類数はx以上K以下
    for (LL x = 1; x <= K; ++x) {
        // 種類が多すぎるケース
        if (x >= bsum.size()) break;

        // 種類が少なすぎて、余り物が足りないケース
        if (K - x >= rsum.size()) continue;

        // bestからx個、remainからK-x個貪欲に美味しい方から選ぶ
        ans = max(ans, bsum[x] + rsum[K - x] + x * x);
    }

}
 
int main(){
	cin >> N >> K;
	dish = vector<priority_queue<LL>>(N);
	for(int i=0;i<N;i++){
		int t,d;
		cin >> t >> d;
		t--;
		dish[t].push(d);
	}
 
	solve();

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

Measured memory_bytes: 8820
N = int(input())
a = list(map(int, input().split()))

sum_a = sum(a)
mean_a = sum_a / N

for i in range(N):
    a[i] = abs(a[i] - mean_a)
thum = min(a)

for i in range(N):
    if a[i] == thum:
        print(i)
        break

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

int main(){
    int sx, sy, tx, ty, i;
    cin >> sx >> sy >> tx >> ty;
    for(i=0; i<tx-sx; i++){
        cout << 'R';
    }
    for(i=0; i<ty-sy; i++){
        cout << 'U';
    }
    for(i=0; i<tx-sx; i++){
        cout << 'L';
    }
    for(i=0; i<ty-sy; i++){
        cout << 'D';
    }
    cout << 'D';
    for(i=0; i<=tx-sx; i++){
        cout << 'R';
    }
    for(i=0; i<=ty-sy; i++){
        cout << 'U';
    }
    cout << 'L' << 'U';
    for(i=0; i<=tx-sx; i++){
        cout << 'L';
    }
    for(i=0; i<=ty-sy; i++){
        cout << 'D';
    }
    cout << 'R';
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <utility>
#include <cstdlib>
#include <map>
#include <stack>
#define ll long long
using namespace std;

  int cnt = 0;
 vector <int> high(0,0); // 1 indexed 両端０で初期化

void sink(int left,int right);
bool allzero(int left,int right);

int main(){
// cout<<123<<endl;
  int N;
  cin>>N;
   high.push_back(0);
  for(int i=0;i<N;i++){
    int h;
    cin>>h;
    high.push_back(h);
  }
  high.push_back(0);
  for(;;){
    
  
  stack <pair <int,int>> divide;
  int left0=0;int right0 ;
  for(int i=0;i<=N+1;i++){
    
    if(left0==i) continue;
    if(high[i]==0 and high[i-1]==0) {left0=i; continue;}
    if(high[i]==0 and high[i-1]!=0){
      right0=i;
      divide.push(make_pair(left0, right0));
      left0=right0;
    }
  }
  
  for(int i=0;i<=N+1;i++){
    if(high[i]==0){
      continue;
    } else {
      high[i] = high[i]-1;
    }
  }
  
  cnt += divide.size();
 
  if ( allzero(0, N+1)) break;
  }
  
  cout<<cnt<<endl;
  return 0;
}


bool allzero(int left,int right){
 
  for(int i=left;i<=right;i++){
    if(high[i] != 0) return false;
  }
  return true;
}



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

namespace mondai0047
{
	class Program
	{
		static void Main(string[] args)
		{
			var	ball	= new bool[ 3 ];
			ball[ 0 ]	= true;
		
			while( true ) {
				var	s	= Console.ReadLine();
				if( s == null) {
					break;
				}
				int	a	= s[ 0 ] - 'A';
				int	b	= s[ 2 ] - 'A';
				var	w		= ball[ a ];
				ball[ a ]	= ball[ b ];
				ball[ b ]	= w;
			}

			for( int i = 0; i < 3; i++ ) {
				if( ball[ i ] ) {
					Console.WriteLine( (char)(i + 'A') );
					break;
				}
			}
		}
	}
}

Measured memory_bytes: 5268
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cctype>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstring>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <tuple>
#include <unordered_map>
#include <vector>
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
#define show(x) cout << #x << " = " << (x) << endl;
using namespace std;
using ll = long long;
using pii = pair<int,int>;
int cost(pii a,pii b){
    return abs(a.first-b.first) + abs(a.second-b.second);
}
int main(){
    int h,w,d;
    cin >> h >> w >> d;
    vector<pii>pos(h*w+1);
    rep(i,h){
        rep(j,w){
            int a;
            cin >> a;
            pos[a] = pii(i,j);
        }
    }
    vector<int>dp(h*w+1);
    rep(i,dp.size()){
        if(i-d>=1)dp[i] = dp[i-d] + cost(pos[i],pos[i-d]);
    }
    int q;
    cin >> q;
    while(q--){
        int a,b;
        cin >> a >> b;
        cout << dp[b] - dp[a] << endl;
    }
}

Measured memory_bytes: 2176
#include <bits/stdc++.h>
using namespace std;
#define db(x) cerr << #x << "=" << x << endl
#define db2(x, y) cerr << #x << "=" << x << "," << #y << "=" << y << endl
#define db3(x, y, z) cerr << #x << "=" << x << "," << #y << "=" << y << "," << #z << "=" << z << endl
#define dbv(v) cerr << #v << "="; for (auto _x : v) cerr << _x << ", "; cerr << endl
#define dba(a, n) cerr << #a << "="; for (int _i = 0; _i < (n); ++_i) cerr << a[_i] << ", "; cerr << endl
typedef long long ll;
typedef long double ld;
const int MX = 80;
ll dp[MX][MX][MX];
ll ndp[MX][MX][MX];
int MOD;
void add(ll& x, ll y) {
	x += y;
	if (x >= MOD) x -= MOD;
}
ll solve(int n, int k) {
	// max k white things
	vector<ll> dp(n + 1);
	dp[0] = 1;
	for (int i = 1; i <= n; ++i) {
		for (int j = 0; j <= k; ++j) {
			if (i - j - 1 >= 0) add(dp[i], dp[i - j - 1]);
		}
	}
	ll ans = 0;
	for (int i = 0; i <= n; ++i)
		if (n - i <= k) add(ans, dp[i]);
	return ans;
}
int main() {
	int n, k;
	scanf("%d%d%d", &n, &k, &MOD);
	if (k % 2 == 0) {
		ll ans = solve(n / 2, k / 2) * solve(n - n / 2, k / 2) % MOD;
		printf("%lld\n", ans);
		return 0;
	}
	dp[0][0][MX - 1] = 1;
	for (int i = 0; i < n; ++i) {
		memset(ndp, 0, sizeof(ndp));
		for (int x = 0; x < MX; ++x)
			for (int y = 0; y < MX; ++y)
				for (int z = 0; z < MX; ++z) {
					if (z <= max(x, y)) continue;
					if (!dp[x][y][z]) continue;
					int xx = y, yy = x, zz = MX - 1;
					if (x > y) zz = z;
					add(ndp[0][x][zz], dp[x][y][z]);
					++xx;
					assert(xx < MX);
					zz = z;
					if (yy >= (k + 1) / 2 && xx <= (k + 1) / 2) {
						zz = min(zz, yy + (k + 1) / 2 - xx + 1);
					}
					add(ndp[xx][yy][zz], dp[x][y][z]);
				}
		swap(dp, ndp);
	}
	ll ans = 0;
	for (int x = 0; x < MX; ++x)
		for (int y = 0; y < MX; ++y)
			for (int z = 0; z < MX; ++z) {
				if (z <= max(x, y)) continue;
				add(ans, dp[x][y][z]);
			}
	printf("%lld\n", ans);
}


Measured memory_bytes: 8320
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <cstdio>
#include <cstring>
#include <cmath>
using namespace std;

using I = int64_t;
template <class F>
I lower_bound(I i0, I i1, F f) {
    while (i0 < i1) {
        I i = (i0 + i1) / 2;
        if (f(i)) i1 = i; else i0 = i + 1;
    }
    return i0;
}

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

    int k;
    cin >> k;

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

    I i0 = lower_bound(0, (int64_t)1 << 60, [&](I i) {
        int64_t r = i;
        for (int j = 0; j < k; j++) {
            int64_t t = r / a[j];
            int64_t s = r % a[j];
            r = t * a[j];
            if (r < 2) break;
        }
        return r >= 2; // iが大きくなるほど満たされやすくなる条件
    });
    I i1 = lower_bound(0, (int64_t)1 << 60, [&](I i) {
        int64_t r = i;
        for (int j = 0; j < k; j++) {
            int64_t t = r / a[j];
            int64_t s = r % a[j];
            r = t * a[j];
            if (r < 2) break;
        }
        return r > 2; // iが大きくなるほど満たされやすくなる条件
    });

    if (i0 >= i1) {
        cout << -1 << endl;
        return 0;
    }

    cout << i0 << ' ' << i1 - 1 << endl;

    return 0;
}

Measured memory_bytes: 640
#pragma GCC optimize("O3")
#pragma GCC optimize ("unroll-loops")
#pragma GCC target ("avx")
#include <bits/stdc++.h>
constexpr int INF = 2147483647;
constexpr long long int INF_LL = 9223372036854775807;
constexpr int MOD = 1000000007;
using namespace std;
typedef long long int ll;
typedef unsigned long long int ull;


int main() {
	ll N;
	cin >> N;
	ll ans = 0;
	if (N % 2 == 1) {
		cout << 0 << endl;
		return 0;
	}
	for (ll i = 5; i <= N; i *= 5) {
		ans += N / (i*2);
	}
	cout << ans << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <algorithm>
using namespace std;
long long h[300000],temp=0;
int main() {
    int n,k;
    cin >> n >> k;
    for (int i=0; i<n; i++) {
        cin >> h[i];
    }
    sort(h,h+n);
    for (int i=0; i<(n-k); i++) {
        temp+=h[i];
    }
    cout << temp << endl;
    return 0;
}


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

#define int long long
using namespace std;
#define rep(i, n) for(int i=0;i<(n);++i)
typedef pair<int, int> pii;
const int INF = 1l << 60;
#define u_b upper_bound
#define l_b lower_bound

int N;
vector<int> G[200200];
int dist0[200200];
int distu[200200];

void dfs0(int v, int par, int dist) {
    dist0[v] = dist;
    for (int to:G[v]) {
        if (to == par)continue;
        dfs0(to, v, dist + 1);
    }
}

void dfsu(int v, int par, int dist) {
    distu[v] = dist;
    for (int to:G[v]) {
        if (to == par)continue;
        dfsu(to, v, dist + 1);
    }
}

signed main() {
    cin >> N;
    rep(i, N - 1) {
        int a, b;
        cin >> a >> b;
        --a, --b;
        G[a].push_back(b);
        G[b].push_back(a);
    }
    dfs0(0, -1, 0);
    int u = 0;
    rep(i, N) {
        if (dist0[i] > dist0[u])u = i;
    }
    dfsu(u, -1, 0);
    int v = u;
    rep(i, N) {
        if (distu[i] > distu[v])v = i;
    }
    int diameter = distu[v];
    if (diameter % 3 == 1) {
        cout << "Second" << endl;
    } else {
        cout << "First" << endl;
    }
    return 0;
}


Measured memory_bytes: 23680
// ================
// Himanshu Lal
// MNIT Jaipur
// ================
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
#define TEZ ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define f(i,a,b) for(ll i=a;i<b;i++)
#define rf(i,a,b) for(ll i=a;i>=b;i--)
#define pb push_back
#define INF 1e18
#define vi vector<pair<ll,ll>>
#define ff first
#define ss second
#define mp map<ll,ll>
#define test ll tp; cin>>tp; while(tp--)
#define srt(v) sort(v.begin(),v.end())
double pi=acos(-1);
void OJ(){
	#ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    #endif
}
int main(){
    TEZ;
    ll n;
    cin>>n;
    if(n>=30)
        cout<<"Yes\n";
    else
        cout<<"No\n";
}

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

using namespace std;
#define ll long long
#define ld long double

int main()
{
    ios_base::sync_with_stdio(0),cin.tie(NULL),cout.tie(NULL);
    int n, t;
    cin >> n >> t;
    vector<pair<int, int>> v(n);
    for(int i=0;i<n;i++) {
        int a, b;
        cin >> a >> b;
        v[i] = {a, b};
    }
    sort(v.begin(), v.end());
    vector<int> dp(t + 1, 0);
    for(int i=0;i<n;i++) {
        for(int j=t-1;j>=0;j--) {
            dp[min(t, j + v[i].first)] = max(dp[min(t, j + v[i].first)], dp[j] + v[i].second);
        }
    }
    cout << dp[t] << endl;
}


Measured memory_bytes: 256
def solve():
    for i in range(1, 10):
        print("? {}".format(10**i))
        ans = input()
        if ans == "N":
            solve2(i)
            return
    solve1()

def solve2(i):
    '''10**(i-1) + 1 <= 10**i - 1 の範囲で解を求める。
    通常の二分探索で、末尾に0を付して探索していく。
    '''
    lower = 10**(i - 1)
    upper = 10**i - 1
    while (upper - lower > 1):
        mid = (lower + upper)//2
        print("? {}0".format(mid))
        ans = input()
        if ans == "Y":
            upper = mid
        else:
            lower = mid
    print("! {}".format(upper))

def solve1():
    '''1, 10, 100, ... 10**9 の中から正解を探す。
    '''
    for i in range(10):
        print("? {}".format(2 * 10**i))
        ans = input()
        if ans == "Y":
            print("! {}".format(10**i))
            return

solve()


Measured memory_bytes: 3404
#include <iostream>
using namespace std;
#define ll long long
const ll N = 1001;
ll h,w,k1,x,y,i,j,black,op,p,p1,s[20],s1[20],b[N][N],c[N][N];
char a[10][10],tampon[10][10];
void backtracking(int pas,int k)
{
    if (pas==k+1)
    {
        p++;
        b[p][0]=k;
        for (int i=1; i<=k; ++i)
            b[p][i]=s[i];
        return;
    }
    for (int i=s[pas-1]+1; i<=h; ++i)
    {
        s[pas]=i;
        backtracking(pas+1,k);
    }
}
void backtracking1(int pas,int k)
{
    if (pas==k+1)
    {
        p1++;
        c[p1][0]=k;
        for (int i=1; i<=k; ++i)
            c[p1][i]=s1[i];
        return;
    }
    for (int i=s1[pas-1]+1; i<=w; ++i)
    {
        s1[pas]=i;
        backtracking1(pas+1,k);
    }
}
int check_black()
{
    int black=0;
    for (int i=1; i<=h; ++i)
    {
        for (int j=1; j<=w; ++j)
            if (tampon[i][j]=='#')
                black++;
    }
    if (black==k1)
        return 1;
    else
        return 0;
}
void get_back()
{
    for (int i=1; i<=h; ++i)
    {
        for (int j=1; j<=w; ++j)
            tampon[i][j]=a[i][j];
    }
}
int main ()
{
    cin>>h>>w>>k1;
    for (i=1; i<=h; ++i)
    {
        for (j=1; j<=w; ++j)
        {
            cin>>a[i][j];
            tampon[i][j]=a[i][j];
        }
    }
    for (i=1; i<=h; ++i)
        backtracking(1,i);
    for (i=1; i<=w; ++i)
        backtracking1(1,i);
    for (i=0; i<=p; ++i)
    {
        for (j=0; j<=p1; ++j)
        {
            for (y=1; y<=b[i][0]; ++y)
                for (x=1; x<=w; ++x)
                    tampon[b[i][y]][x]='.';

            for (y=1; y<=c[j][0]; ++y)
                for (x=1; x<=h; ++x)
                    tampon[x][c[j][y]]='.';

            if (check_black())
                op++;
            get_back();
        }
    }
    cout<<op<<"\n";
}


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

int main()
{
    int r, g, b, N;
    cin >> r >> g >> b;

    N = r * 100 + g * 10 + b;

    if (N % 4 == 0)
    {
        cout << "YES";
    }
    else
    {
        cout << "NO";
    }

    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define rep(i,a,b) for(int i=a;i<b;i++)
#define rrep(i,a,b) for(int i=a;i>=b;i--)
#define erep(i,a,n) for(int i = a;i<=n;i++)
typedef long long ll;
#define int long long
#define vint vector<int>
#define vvint vector<vector<int>>
#define vstring vector<string>
#define vdouble vector<double>
#define vll vector<ll>:
#define vbool vector<bool>
#define INF 1101010101010101010
#define MOD 1000000007
#define P pair<int,int>
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a = b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a = b; return 1; } return 0; }

signed main(){
  int n,t;
  cin >> n >> t;
  vint A(n);
  rep(i,0,n) cin >> A[i];
  vint MAX(n);
  int nowmax = 0;
  rrep(i,n-1,0){
    nowmax = max(nowmax,A[i]);
    MAX[i] = nowmax;
  }
  vint dist(n);
  rep(i,0,n){
    dist[i] = MAX[i] - A[i];
  }
  // rep(i,0,n) cout << dist[i] << endl;
  sort(dist.begin(),dist.end());
  int ans = 1;
  rrep(i,n-1,1){
    if(dist[i] == dist[i-1]) ans++;
    else break;
  }
  cout << ans << endl;
}

Measured memory_bytes: 2560
#include <bits/stdc++.h>
using namespace std;
int main() {
int K,X;
    cin>>K>>X;
    vector<int> st(2*K-1,0);
    for(int i=0;i<2*K-1;i++){
        st[i]=X-K+i+1;
        cout<<st[i]<<" ";
    }
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
template<class t> inline t read(t &x){
	char c=getchar();bool f=0;x=0;
	while(!isdigit(c)) f|=c=='-',c=getchar();
	while(isdigit(c)) x=(x<<1)+(x<<3)+(c^48),c=getchar();
	if(f) x=-x;return x;
}
template<class t> inline void write(t x){
	if(x<0) putchar('-'),write(-x);
	else{if(x>9) write(x/10);putchar('0'+x%10);}
}

#define pii pair<int,int>
#define x first
#define y second

const int N=25;
const int dx[4]={-1,1,0,0},dy[4]={0,0,-1,1};
int cur,d[N][N],ans,n,m;
char s[N][N];

void bfs(int x,int y){
	queue<pii> q;
	q.push(pii(x,y));
	while(!q.empty()){
		pii x=q.front();
		cur=max(cur,d[x.x][x.y]);
		q.pop();
		for(int i=0;i<4;i++){
			int nx=x.x+dx[i],ny=x.y+dy[i];
			if(nx<0||ny<0||nx>n||ny>m) continue;
			if(d[nx][ny]!=-1) continue;
			if(s[nx][ny]=='#') continue;
			d[nx][ny]=d[x.x][x.y]+1;
			q.push(pii(nx,ny));
		}
	}
}

signed main(){
	read(n);read(m);
	for(int i=1;i<=n;i++)
		scanf("%s",s[i]+1);
	for(int i=1;i<=n;i++)
		for(int j=1;j<=m;j++) if(s[i][j]=='.'){
			for(int i=1;i<=n;i++)
				for(int j=1;j<=m;j++)
					d[i][j]=-1;
			d[i][j]=cur=0;
			bfs(i,j);
			ans=max(ans,cur);
		}
	write(ans);
}


Measured memory_bytes: 256
from heapq import heappush, heappop
n, k = map(int, input().split())
a = list(map(int, input().split()))
f = list(map(int, input().split()))

a.sort(reverse=True)
f.sort()


def check(x):
    red = 0
    for i in range(n):
        if a[i] * f[i] > x:
            red += a[i] - x // f[i]

    return (red <= k)


lb = -1  # false
ub = max([a[i] * f[i] for i in range(n)])  # true
while ub - lb > 1:
    mid = (ub + lb) // 2
    if check(mid):
        ub = mid
    else:
        lb = mid

print(ub)


Measured memory_bytes: 120908
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <string>
#include <cstring>
#include <utility>
#include <set>
#include <stack>
#include <climits>
#include <cmath>

#define rep(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define rep1(i,n) for(int i=1, i##_len=(n); i<=i##_len; ++i)
#define reps(i,s,n) for(int i=s, i##_len=(n); i<i##_len; ++i)
#define all(x) (x).begin(),(x).end()
#define MEMSET(v, h) memset((v), h, sizeof(v))
typedef long long ll;
const char sp = ' ';


using namespace std;

int main(void){
    string A;
    cin>>A;
    ll co[26];
    MEMSET(co, 0);
    ll ans=1;
    rep(i, A.size()){
        ans+=i-co[A[i]-'a'];
        co[A[i]-'a']++;
        //cout<<ans<<endl;
    }
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 640
H, W = map(int, input().split(' '))
S = [list(input()) for _ in range(H)]

def p(i, j):
    if S[i][j] == '#':
        return 1
    return 0

for i in range(H):
    for j in range(W):
        if S[i][j] == '#':
            continue
        
        cnt = 0
        if i != 0:
            if j != 0:
                cnt += p(i-1,j-1)
            cnt += p(i-1,j)
            if j != W-1:
                cnt += p(i-1,j+1)

        if j != 0:
            cnt += p(i,j-1)
        if j != W-1:
            cnt += p(i,j+1)
        
        if i != H-1:
            if j != 0:
                cnt += p(i+1,j-1)
            cnt += p(i+1,j)
            if j != W-1:
                cnt += p(i+1,j+1)
        
        S[i][j] = str(cnt)

print('\n'.join([''.join(S[i]) for i in range(H)]))

Measured memory_bytes: 41324
#include "bits/stdc++.h"
using namespace std;

/*第二引数で第一引数を割ったときの切り上げの計算*/
long long int maxtime(long long int x, long long int y) {
	return(x + y - 1) / y;

}
/*最大公約数*/
long long int lcm(long long int number1, long long int number2) {
	long long int m = number1;
	long long int n = number2;

	if (number2 > number1) {
		m = number2;
		n = number1;
	}
	long long int s = -1;
	while (s != 0) {
		s = m % n;
		m = n;
		n = s;
	}
	return m;
}
/*最大公倍数*/
long long int gcd(long long int number1, long long int number2) {
	long long int m = number1;
	long long int n = number2;
	return m / lcm(m, n) * n;
}
int main() {
	string S;
	cin >> S;
	int s = 0;
	for (int i = 0; i < S.size(); i++) {
		if (i % 2 != 0) {
			if (S[i] == 'L' || S[i] == 'U' || S[i] == 'D') {
				s++;
			}
		}
		else {
			if (S[i] == 'R' || S[i] == 'U' || S[i] == 'D') {
				s++;
			}
		}
	}
	if (s == S.size()) {
		cout << "Yes";
	}
	else {
		cout << "No";
	}
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define pb push_back
#define ll long long
#define f first
#define s second
using namespace std;
 
int main(){
    ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    #ifdef debug
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
    #endif
    int n; cin >> n;
    if(n == 1)cout << "Hello World" << endl;
    else{
        int a, b; cin >> a>> b; cout <<a+b << endl;
    }
    return 0;
}

Measured memory_bytes: 3604
using System;
using System.Linq;
using System.Collections.Generic;
using static System.Console;
using System.Text;
using System.IO;
using static System.Math;
namespace AtCoder
{
    class Program
    {
        static public long[] Sarray() { return ReadLine().Split().Select(long.Parse).ToArray(); }
        static public List<long> Slist() { return ReadLine().Split().Select(long.Parse).ToList(); }
        static long Mod = (long)998244353;
        static void Main(string[] args)
        {
            //SetOut(new StreamWriter(OpenStandardOutput()) { AutoFlush = false });
            Solve();
            Read();
            //Out.Flush();
        }
        static void Solve()
        {
            var NK = Sarray();
            var N = NK[0];
            var K = NK[1];
            var Ai = Sarray();
            var next = 0L;
            var count = new long[N];
            var nums = new List<long>();
            for (var i = 0; i < K; ++i)
            {
                next = Ai[next] - 1;
                ++count[next];
                if (2 == count[next])
                    nums.Add(next);
                if (3 == count[next])
                {
                    next = nums[(int)((K - 1 - i) % nums.Count)];
                    break;
                }
            }
            WriteLine(next + 1);
        }
    }
}

Measured memory_bytes: 46788
#include<iostream>
#include<algorithm>
using namespace std;
long long int tree[800000];
void update_tree(int node,int idx,long long int val,int b,int e){
	if(idx<b||e<idx)
	return;
	if(b==idx&&b==e){
		tree[node]=val;
		return;
	}
	int m=b+(e-b)/2;
	update_tree(2*node+1,idx,val,b,m);
	update_tree(2*node+2,idx,val,m+1,e);
	tree[node]=max(tree[2*node+1],tree[2*node+2]);
}
long long int query(int node,int l,int r,int b,int e){
	if(r<b||e<l)
	return 0;
	if(l<=b&&e<=r)
	return tree[node];
	int m=b+(e-b)/2;
	long long int m1=query(2*node+1,l,r,b,m);
	long long int m2=query(2*node+2,l,r,m+1,e);
	return max(m1,m2);
}
void dp(int n,int a[][2]){
	for(int i=0;i<4*n;i++)
	tree[i]=0;
	for(int i=0;i<n;i++){
		long long int m=query(0,0,a[i][0]-2,0,n-1);
		update_tree(0,a[i][0]-1,m+a[i][1],0,n-1);
	}
	//for(int i=0;i<4*n;i++)
	//cout<<tree[i]<<endl;
	cout<<tree[0]<<endl;
}
int main(){
	int n;cin>>n;
	int a[n][2];
	for(int i=0;i<n;i++)
	cin>>a[i][0];
	for(int i=0;i<n;i++)
	cin>>a[i][1];
	dp(n,a);
}

Measured memory_bytes: 8064
#include <stdio.h>

int main(int argc, const char * argv[]) {
    int i,j,h,w;
    while(1){
        scanf("%d %d\n",&h,&w);
        
        if(h == 0 && w == 0){
            break;
        }
        else{
            for(i=1;i<=h;i++){
                for(j=1;j<=w;j++){
                    printf("#");
                }
                printf("\n");
            }
            printf("\n");
        }
    }
    return 0;
}


Measured memory_bytes: 2028
#include <iostream>
#include <cstdio>
#include <string>

using namespace std;

string a;
long long n[30], s, br;

int main () {
	cin >> a;
	s = a.size();
	for (int i = 0; i < s; i++) {
		n[a[i] - 'a']++;
	}
	for (int i = 0; i < 26 ; i++) {
		br += (n[i] * (n[i] - 1)) / 2;
	}
	cout << s * (s - 1) / 2 + 1 - br;
	return 0;
}

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



void partition(vector<int> &A, int l, int r, int &x) {
    int i = l - 1; //境界のインデックス
    // partition
    rep2(j,l,r) {
        if (A[j] <= A[r]) {
            i++;
            swap(A[i],A[j]);
        }
    }
    i++;
    swap(A[i], A[r]);
    x = i;
}

signed main() {

    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    
    int n; cin >> n;
    vector<int> A(n);
    rep(i,n) cin >> A[i];
    int x;
    partition(A, 0, n - 1, x);
    rep(i,n) {
        if (i == 0) cout << A[0];
        else if (i == x) cout << " " << "[" << A[i] << "]";
        else cout << " " << A[i];
    }
    cout << endl;
    return 0;
}


Measured memory_bytes: 3368
#include <algorithm>
#include <cfloat>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <functional>
#include <iostream>
#include <map>
#include <memory>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>

using namespace std;

typedef long long ll;

#define sz size()
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define all(c) (c).begin(), (c).end()
#define rep(i,a,b) for(ll i=(a);i<(b);++i)
#define per(i,a,b) for(ll i=b-1LL;i>=(a);--i)
#define clr(a, b) memset((a), (b) ,sizeof(a))
#define ctos(c) string(1,c)
#define print(x) cout<<#x<<" = "<<x<<endl;

#define MOD 1000000007

ll d[1010];

int main() {
  clr(d,0);
  ll n,k;
  cin>>n>>k;
  vector<ll> v;
  rep(i,0,n){
    ll a;
    cin>>a;
    v.pb(a);
  }
  rep(i,1,n+1){
    d[i] += d[i-1]+v[i-1];
  }
  vector<ll> v1;
  rep(i,1,n+1){
    rep(j,i,n+1){
      v1.pb(d[j]-d[i-1]);
    }
  }
  ll ans = 0;
  per(i,0,43){
    vector<ll> v2;
    rep(j,0,v1.sz){
      if(((v1[j]>>i)&1)==1){
        v2.pb(v1[j]);
      }
    }
    if(v2.sz>=k){
      v1 = v2;
      ans += 1LL<<i;
    }
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 6268
#include <iostream>
#include <cstdio>
#include <string>
#include <vector>
#include <stack>
#include <deque>
#include <queue>
#include <set>
#include <cmath>
#include <algorithm>
#include <map>

using namespace std;

#define MAX 1024
typedef pair<int, int> C;

int main(void) {
	while(1) {
		set<C> comp[MAX];
		int n, m, a;
		int h, p, q;
		int now, highest = 0;

		scanf("%d %d %d", &n, &m, &a);
		if(!n && !m && !a) break;
		now = a;

		for(int i = 0; i < m; i++) {
			scanf("%d %d %d", &h, &p, &q);
			comp[h].insert(C(p, q));
			if(h > highest) highest = h;
		}

		for(int i = highest; i > 0; i--) {
			if(comp[i].find(C(now, now+1)) != comp[i].end()) {
				now++;
				continue;
			}
			if(comp[i].find(C(now-1, now)) != comp[i].end()) {
				now--;
			}
		}
		printf("%d\n", now);
	}
	return 0;
}

Measured memory_bytes: 1280
#include <iostream>
#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()
using ll = long long;
using ld = long double;
using Pint = pair<int, int>;
const ll mod = 1e9+7;

int main(int argc, char const* argv[])
{
  ll h;
  cin >> h;

  ll ans = 1;
  while(h) {
    h>>=1ll;
    ans *= 2;
  }
  ans--;

  cout << ans << endl;

  return 0;
}

Measured memory_bytes: 256
N, M = map(int, input().split())
a = []
for i in range(M):
    a.append(list(map(int, input().split())))
L = []
R = []
for j in range(M):
    L.append(a[j][0])
    R.append(a[j][1])
if max(L) <= min(R):
  print(min(R) - max(L) +1)
else:
  print(0)

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

int n,m,k;
int tot,tot2,hd[100009],hd2[100009];
struct line{int b,nxt;} ln[200009],ln2[200009];
int top[100009],sz[100009];
int ans[100009];

void Addln(int a,int b)
{
	ln[++tot] = (line){b,hd[a]};
	hd[a] = tot;
}
void Addln2(int a,int b)
{
	ln2[++tot2] = (line){b,hd2[a]};
	hd2[a] = tot2;
}

int findtop(int x){return top[x]==x?x:top[x] = findtop(top[x]);}
void Unite(int x,int y)
{
	if(findtop(x)!=findtop(y))
	{
		sz[top[y]] += sz[top[x]];
		top[top[x]] = y;
		
	}
}

int main()
{
	cin >> n >> m >> k;
	for(int i = 1;i<=n;i++)top[i] = i,sz[i] = 1;
	for(int i = 0,a,b;i<m;i++)
	{
		cin >> a >> b;
		Addln(a,b);
		Addln(b,a);
		Unite(a,b);
	}
	for(int i = 0,a,b;i<k;i++)
	{
		cin >> a >> b;
		Addln2(a,b);
		Addln2(b,a);
	}
	for(int i = 1;i<=n;i++)
	{
		ans[i] = sz[findtop(i)]-1;
		//cout << "sz_top[" << i << "]=" << sz[top[i]] << endl;//
		for(int h = hd[i];h;h = ln[h].nxt)ans[i]--;
		for(int h = hd2[i];h;h = ln2[h].nxt)if(top[i]==findtop(ln2[h].b))ans[i]--;
	}
	for(int i = 1;i<=n-1;i++)cout << ans[i] << " ";
	cout << ans[n];
	return 0;
}

Measured memory_bytes: 6528