akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
const int N=1000005;
char s[N],stk[N];
vector<pair<int,int> >a,b,c;
int n,top;
bool cmp1( pair<int,int> &X, pair<int,int>&Y)
{
    return X.first<Y.first;
}
bool cmp2(const pair<int,int> &X,const pair<int,int>&Y)
{
    return X.second>Y.second;
}
int main()
{
    scanf("%d",&n);
    for(int i=1;i<=n;++i)
    {
        scanf("%s",s);
        top=0;
        for(int j=0;s[j];++j)
        {
            if(s[j]=='(') stk[++top]='(';
            else
            {
                if(top&&stk[top]=='(') top--;
                else stk[++top]=')';
            }
        }
        int cnt0=0,cnt1=0;
        for(int j=1;j<=top;++j)
        {
            if(stk[j]==')')++cnt0;
            else ++cnt1;
        }
        
        if(cnt0>cnt1)c.emplace_back(cnt0,cnt1);
        if(cnt0==cnt1)b.emplace_back(cnt0,cnt1);
        if(cnt0<cnt1)a.emplace_back(cnt0,cnt1);
    }
    sort(a.begin(),a.end(),cmp1);
    sort(c.begin(),c.end(),cmp2);
    
    int now=0;
    int flag=1;
    for(auto &i:a)
    {
        now-=i.first;
        if(now<0)flag=0;
        now+=i.second;
    }
    for(auto &i:b)
    {
        now-=i.first;
        if(now<0)flag=0;
        now+=i.second;
    }
    for(auto &i:c)
    {
        now-=i.first;
        if(now<0)flag=0;
        now+=i.second;
    }
    if(now)flag=0;
    if(flag)  printf("Yes\n");
    else printf("No\n");
    
}

Measured memory_bytes: 11424
import itertools
import math
import fractions
import functools
l = [0]*(10**5+10)
r = [0]*(10**5+10)

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

for i in range(n):
    if i % 2 == 0:
        l[v[i]] += 1
    else:
        r[v[i]] += 1

max_l = l.index(max(l))
max_r = r.index(max(r))
count = 0

if max_l == max_r:
    for i in range(len(r)):
        if r[i] == r[max_r]:
            r[i] = 0
        if l[i] == l[max_l]:
            l[i] = 0
if max(l) > max(r):
    max_l = l.index(max(l))
else:
    max_r = r.index(max(r))

for i in range(n):
    if i % 2 == 0 and v[i] != max_l:
        count += 1
    if i % 2 != 0 and v[i] != max_r:
        count += 1
print(count)

Measured memory_bytes: 82408
/// --- In the name of ALLAH --- ///


//#include <cmath>
#include<bits/stdc++.h>
//#include<iostream>
using namespace std;


typedef long long              ll;
typedef vector<int>            vi;
typedef vector<ll>             vl;
typedef vector<vi>             vvi;
typedef vector<vl>             vvl;
typedef pair<int,int>          pii;
typedef pair<double, double>   pdd;
typedef pair<ll, ll>           pll;
typedef vector<pii>            vii;
typedef vector<pll>            vll;
typedef double                 dl;

#define endl                   '\n'
#define PB                     push_back
#define F                      first
#define S                      second
#define all(a)                 (a).begin(),(a).end()
#define rall(a)                (a).rbegin(),(a).rend()
#define sz(x)                  (ll)x.size()
#define wt                     ll t; cin>>t; while(t--)
#define input(a,n)             for(int i=0;i<n;i++) cin>>a[i];

const double PI = acos(-1);
const double eps = 1e-9;
const int inf = 2000000000;
const ll infLL = 9000000000000000000;


#define mem(a,b) memset(a, b, sizeof(a) )
#define sqr(a) ((a) * (a))
#define mod 10000007
#define optimize() ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define fraction() cout.unsetf(ios::floatfield); cout.precision(10); cout.setf(ios::fixed,ios::floatfield);
#define file() freopen("input.txt","r",stdin);freopen("output.txt","w",stdout);

#define dbg(args...) do {cerr << #args << " : "; faltu(args); } while(0)
void faltu () {            cerr << endl;}
template < typename T, typename ... hello>void faltu( T arg, const hello &... rest) {cerr << arg << ' ';faltu(rest...);}

ll gcd ( ll a, ll b ) { return __gcd ( a, b ); }
ll lcm ( ll a, ll b ) { return a * ( b / gcd ( a, b ) ); }


const ll mx=1e9;




int main()
{
    optimize();
int n,i,c=1,j,q=0;
cin>>n;
int h[n+1];
for(i=1;i<=n;i++)
{
    q=0;
    cin>>h[i];
    if(i==1)
        continue;
    for(j=1;j<i;j++)
    {
        if(h[j]<=h[i])
            q++;
    }
    if(q==i-1)
            c++;

}
cout<<c<<endl;
    return 0;
}






























































































Measured memory_bytes: 3632
#include <iostream>
#include <string>
using namespace std;
int main(int argc, char const *argv[]) {
  string w;
  cin>>w;
  int count[26]={};
  for(char i='a';i<='z';i++){
    for(int j=0;j<w.size();j++){
      if(w[j]==i) count[(int)i-97]++;
    }
  }
  for(int i=0;i<26;i++){
    if(count[i]%2!=0){
      cout<<"No"<<endl;
      break;
    }
    if(i==25&&count[i]%2==0){
      std::cout << "Yes" << '\n';
    }
  }
  return 0;
}


Measured memory_bytes: 256
A,B,C = map(int,input().split())
K = int(input())
while A>=B:
  B *= 2
  K -= 1
if K < 0:
  print('No')
while B>=C:
  C *= 2
  K -= 1
if K<0:
  print('No')
else:
  print('Yes')

Measured memory_bytes: 9172
// include
// ------------------------------------------------
#include <bits/stdc++.h>
#include <vector>
#include <algorithm>
#include <math.h>

using namespace std;

// func
// ------------------------------------------------
int CalcSumOfDigit(int n);      // 各桁の和を計算する。
long long getDigit(long long n);      // 数字の桁数を取得する。
string upper(string str);       // 英字を大文字に変換する。
string lower(string str);       // 英字を小文字に変換する。

// define
// ------------------------------------------------
#define all(a)        (a).begin(),(a).end()
#define rall(a)       (a).rbegin(),(a).rend()
#define sz(a)         int((a).size())
#define rep(i,n)      for(int(i)=0;(i)<(n);(i)++)
#define repe(i,n)     for(int(i)=0;(i)<=(n);(i)++)
#define vsort(v)      sort((v).begin(),(v).end())
#define rvsort(v)     sort(rall((v)))
#define vi            vector<int>
#define GCD(a,b)      __gcd((a),(b))
#define LCM(a,b)      ((a)/GCD((a),(b))*(b))
#define kiriage(a,b)  ((a)+(b)-1)/(b)

const int INF = 1e9;

typedef long long ll;
typedef unsigned long long ull;

// code
// ------------------------------------------------
int main() {

  ll a,b,c,d;
  cin >> a >> b >> c >> d;

  ll taka = kiriage(c,b);
  ll ao = kiriage(a,d);

  cout << (taka <= ao ? "Yes" : "No") << endl;

  return 0;
}
// funcの実体
// ------------------------------------------------
ll getDigit(ll n)
{
  int i = 1;
  while(1)
  {
    n = n / 10;
    if(n == 0)
      break;
    i++;
  }
  return i;
}
ll CalcSumOfDigit(ll n)
{
  ll s = 0;
  while(n)
  {
    s += n % 10;
    n = n / 10;
  }
  return s;
}

string upper(string str)
{
  for(auto itr = str.begin();itr != str.end() ; itr++)
  {
    if(97 <= *itr && *itr <= 122)
    {
      *itr = *itr - 32;
    }
  }
  return str;
}

string lower(string str)
{
  for(auto itr = str.begin();itr != str.end() ; itr++)
  {
    if(65 <= *itr && *itr <= 90)
    {
      *itr = *itr + 32;
    }
  }
  return str;
}


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

int main() {
    int n;
    while (cin >> n, n) {
        vector<int> v(n+1);
        for (auto& i : v) cin >> i;

        int ans = 0;
        for (int i = 0; i < n+1; i++) {
            auto d = v;
            d.erase(d.begin() + i);
            vector<int> sub(n-1);
            for (int j = 0; j < n-1; j++) {
                sub[j] = d[j+1] - d[j];
            }
            bool flag = true;
            for (int j = 0; j < n-2; j++)
                if (sub[j+1]-sub[j]) flag = false;
            if (flag) ans = v[i];
        }

        cout << ans << endl;
    }

    return 0;
}

Measured memory_bytes: 3164
#include <iostream>
#include <algorithm>
#include <vector>
#include <iomanip>
#include <map>
#include <set>
#include <cmath>
using namespace std;

void solve(){
  vector<int> a(3);
  for(int i = 0; i < 3; i++) cin >> a[i];
  sort(a.begin(), a.end());
  cout << a[0] + a[1] << endl;
  return;
}

int main(){
  solve();
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>    
//#include <ext/pb_ds/assoc_container.hpp> 
//#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
//#pragma GCC optimize("Ofast,no-stack-protector,unroll-loops,fast-math,O3")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
//using namespace __gnu_pbds; 
#define fastio() ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define pb  push_back
#define show(x) cout<<(#x)<<" : "<<x<<endl;
#define ll  long long
#define ld  long double
#define fill(a,val) memset(a,val,sizeof(a))
#define mp  make_pair
#define ff  first
#define ss  second
#define pii pair<ll,ll>
#define sq(x) ((x)*(x))
#define all(v) v.begin(),v.end()
#define rall(v) v.rbegin(),v.rend()
#define endl "\n"
#define int long long 
#define printclock cerr<<"Time : "<<1000*(ld)clock()/(ld)CLOCKS_PER_SEC<<"ms\n";
const ll MOD     = 1000*1000*1000+7;
const ll INF     = 1ll*1000*1000*1000*1000*1000*1000 + 7;
const ll MOD2    = 998244353;
const ll N       = 1000 * 100 + 10;
const ll N2      = 70;
const ld PI  = 3.141592653589793;
//template<class T> using oset=tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
ll gcd(ll a, ll b){if(!b)return a;return gcd(b, a % b);} 
ll power(ll x,ll y,ll p = LLONG_MAX ){ll res=1;x%=p;while(y>0){if(y&1)res=(res*x)%p;y=y>>1;x=(x*x)%p;}return res;}
ll lcm(ll a , ll b){return (a*b)/gcd(a,b);}

signed main()
{
    fastio();
    //cout<<fixed<<setprecision(20);
    //CHECK for LONG LONG and LONG DOUBLE
    //*comment for all except cc/cf    
    #ifndef ONLINE_JUDGE    
           freopen("input.txt","r",stdin);
           freopen("output.txt","w",stdout);
    #endif//*/
    int n;
    cin>>n;
    if(n>=30)
        cout<<"Yes";
    else
        cout<<"No";
    printclock;
    return 0;
}


Measured memory_bytes: 3792
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <string.h>
#define mem(x,y)		(x*)malloc(sizeof(x)*(y))
#define PI 3.14159265358979

int list_sort(const void* a,const void* b)
{
	if((*(int**)a)[0] > (*(int**)b)[0])
	{
		return 1;
	}
	else if((*(int**)a)[0] == (*(int**)b)[0])
	{
		if((*(int**)a)[1] > (*(int**)b)[1])
		{
			return 1;
		}
		else if((*(int**)a)[1] == (*(int**)b)[1])
		{
			return 0;
		}
	}
	return -1;
}

void dijkstra(int** list,int*** road,int* score,int m,int n,int s)
{
	int len;
	if(s == (n-1))
	{
		len = road[0]+m-road[s];
	}
	else
	{
		len = road[s+1]-road[s];
	}
	int i;
	for(i = 0;i < len;i++)
	{
		int sc = score[road[s][i][1]];
		if(sc > score[s]+road[s][i][2] || sc == -1)
		{
			score[road[s][i][1]] = score[s]+road[s][i][2];
			dijkstra(list,road,score,m,n,road[s][i][1]);
		}
		else if(sc < score[s]-road[s][i][2])
		{
			score[s] = sc+road[s][i][2];
			i = -1;
			continue;
		}
	}
}

int main()
{
	int m,n,k;
	int** list;
	int*** road;
	int* score;
	int i,j;
	double longest;
	scanf("%d %d %d",&n,&m,&k);
	score = mem(int,n);
	road = mem(int**,n);
	for(i = 0;i < n;i++)
	{
		score[i] = -1;
	}
	list = mem(int*,2*m);
	for(i = 0;i < m;i++)
	{
		list[i] = mem(int,3);
		list[i+m] = mem(int,3);
		scanf("%d %d %d",&list[i][0],&list[i][1],&list[i][2]);
		list[i+m][0] = --list[i][1];
		list[i+m][1] = --list[i][0];
		list[i+m][2] = list[i][2];
	}
	qsort(list,m*2,sizeof(int*),list_sort);
	j = 0;
	for(i = 0;i < n;i++)
	{
		road[i] = list+j;
		while(j < m*2 && list[j][0] == i)j++;
	}
	for(i = 0;i < k;i++)
	{
		int s;
		scanf("%d",&s);
		score[s-1] = 0;
	}
	for(i = 0;i < n;i++)
	{
		if(score[i] != -1)
			dijkstra(list,road,score,2*m,n,i);
	}
	longest = 0;
	for(i = 0;i < m*2;i++)
	{
		int val = score[list[i][0]]+score[list[i][1]]+list[i][2];
		if(val > longest*2)
		{
			longest = (double)val/2.0;
		}
	}
	int num = floor(longest+0.5);
	printf("%d\n",num);
	return 0;
}

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

typedef long lint;
typedef long long llint;
typedef pair<int, int> pint;
typedef pair<long long, long long> pllint;

// static const int MAX = 1e6;
// static const int NIL = -1;
// static const llint INF = 1<<21;
// static const llint MOD = 1e9 + 7;

bool compPair(const pint& arg1, const pint& arg2) { return arg1.first > arg2.first; }
template<class T> void chmax(T& a, T b) { if (a < b) { a = b; } }
template<class T> void chmin(T& a, T b) { if (a > b) { a = b; } }

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

    vector<int> c(n-1);
    vector<int> s(n-1);
    vector<int> f(n-1);

    for(int in=0;in<n-1;in++) {
        cin >> c.at(in) >> s.at(in) >> f.at(in);
    }

    int ans;
    for(int in=0;in<n-1;in++) {
        ans = 0;
        for(int jn=in;jn<n-1;jn++) {
            ans = max(ans, s.at(jn));
            if((ans-s.at(jn))%f.at(jn)!=0) ans += f.at(jn) - (ans - s.at(jn))%f.at(jn);
            ans += c.at(jn);
        }
        cout << ans << endl;
    }
    cout << 0 << endl; 
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define rep(i,n) for(ll i=0;i<n;++i)
#define rrep(i,n) for(int i=n-1;i>=0;--i)
#define yesno(flg) if(flg){cout<<"YES"<<endl;}else{cout<<"NO"<<endl;}
#define MAX_N 1002
#define i197 1000000007

using namespace std;

typedef long long ll;
typedef pair<ll,ll> P1;
typedef pair<int,int> Pi;
typedef pair<double,Pi> Pdi;
typedef pair<ll,int>Pli;
typedef pair<P1,ll> P2;
const ll INF=100000000000000001;
struct edge{int to,cost;};
struct pos{
	int x,y,cost;
};
int dy[]={0, 0, 1, -1};
int dx[]={1, -1, 0, 0};
struct Road{double cost;int a,b;};

ll gcd(ll a2,ll b2){
	ll t;
	while(b2!=0){
		t=a2%b2;
		a2=b2;
		b2=t;
	}
	return a2;
}

ll d[2019][3]={};

int main() {

	string s;
	cin>>s;

	ll t=0;
	for(int i=0; i<s.size(); i++){
		int x;
		if(s[i]=='1')x=1;
		if(s[i]=='2')x=2;
		if(s[i]=='3')x=3;
		if(s[i]=='4')x=4;
		if(s[i]=='5')x=5;
		if(s[i]=='6')x=6;
		if(s[i]=='7')x=7;
		if(s[i]=='8')x=8;
		if(s[i]=='9')x=9;

		rep(i,2019){
			d[i][1]=d[i][2];
			d[i][2]=0;
		}
		d[x][2]++;
		for(int j=0; j<2019; j++){
			if(d[j][1]==0)continue;
			d[(j*10+x)%2019][2]+=d[j][1];
		}
		t+=d[0][2];
	}
	cout<<t<<endl;
	return 0;
}


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

//int INTMAX =100010;


int N, K;
int dp[100010];
int a[110];

int rec(int k)
{   
    for(int i = 0; i <= k; i++)
    {
        dp[i] = 0;
        int t = 1;
        for(int j = 0; j < N; j++)
        {
            if(i - a[j] >= 0)
            {
                t *= dp[i - a[j]];
            }
        }
        if (t == 0) dp[i] = 1;
    }

    return 0;
}

int main ()
{
    cin >> N >> K;
    for(int i = 0; i < N; i++)
    {
        cin >> a[i];
    }
    rec(K);

   if(dp[K] == 1) cout << "First" << endl;
   else cout << "Second" << endl;
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
int main(){
  int k; cin >> k;
  string s; cin >> s;
  if(s.size() <= k) cout << s << endl;
  else{
    for(int i=0; i<k; ++i) cout << s[i];
    cout << "...\n";
  }
  return 0;
}

Measured memory_bytes: 3612
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		StringBuilder sb = new StringBuilder();
		while (true) {
			int h = scan.nextInt();
			int w = scan.nextInt();
			if (h == 0 && w == 0) {break;}
			for (int i = 1; i <= h; i++) {
				for (int j = 1; j <= w; j++) {
					if ( (i % 2 == 1 && j % 2 == 1)
							|| (i % 2 == 0 && j % 2 == 0) ) {
						sb.append("#");
					} else {
						sb.append(".");
					}
				}
				sb.append("\n");
			}
			sb.append("\n");
		}
		System.out.print(sb);
	}
}

Measured memory_bytes: 27884
#include <bits/stdc++.h>
using namespace std;
using LL = long long;
#define repex(i, a, b, c) for(int i = a; i < b; i += c)
#define repx(i, a, b) repex(i, a, b, 1)
#define rep(i, n) repx(i, 0, n)
#define repr(i, a, b) for(int i = a; i >= b; i--)
LL a[101010], b[101010];

int main(){
    
    // 1. 入力情報.
    int N;
    scanf("%d", &N);
    rep(i, N) scanf("%lld %lld", &a[i], &b[i]);
    
    // 2. ボタン押下回数を計算.
    LL ans = 0;
    repr(i, N - 1, 0){
        LL o = a[i] + ans;
        LL q = o / b[i];
        LL r = o % b[i];
        if(r) ans += (q + 1) * b[i] - o;
    }
    
    // 3. 出力.
    printf("%lld\n", ans);
    return 0;
    
}

Measured memory_bytes: 5388
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll MOD = 1000003;

ll power(ll a, ll p){
    ll x = 1, n = p;
    while (n != 0){
        if (n % 2 == 1){
            x = (x * a) % MOD;
            n -= 1;
        }
        else{
            a = (a * a) % MOD;
            n /= 2;
        }
    }
    return x;
}

int main(){
    int q;
    ll p[2*MOD + 1] = {};
    cin >> q;
    p[0] = 1;
    for (int i = 1; i <= 2*MOD; i++)
        p[i] = (p[i - 1] * i) % MOD;
    ll x, d, n;
    for (int i = 0; i < q; i++){
        cin >> x >> d >> n;
        if(d == 0){
            cout << power(x,n) << endl;
        }else if(n > MOD){
            cout << 0 << endl;
        }else{
            ll invd = power(d, MOD-2);
            ll dn = power(d, n);
            ll xd = x * invd % MOD;
            cout << dn * p[xd + n - 1] * power(p[xd-1], MOD-2) % MOD << endl;
        }
    }
}

Measured memory_bytes: 16512
import java.util.Scanner;

public class Main {
    public static void main(String arg[]) {
        Scanner sc = new Scanner(System.in);
        
        
        for(int x = 1; x < 10000; x++) {
            
            int H = sc.nextInt();
            int W = sc.nextInt();
            
            if(printJudge(H, W)) {
            
                for(int i = 1; i < H + 1; i++) {
                    if((double)i % 2 != 0) {
                        printLine1(W);
                    }else {
                        printLine2(W);
                    }
                }
            }else {
                break;
            }
            
            System.out.print("\n");
            
        }        
    }

    public static void printLine1(int W) {
        for(int i = 1; i < W + 1; i ++) {
            if((double)i % 2 != 0) {
                System.out.print("#");
            }else {
                System.out.print(".");
            }
        }
        System.out.print("\n");
    }
    
    public static void printLine2(int W) {
        for(int i = 1; i < W + 1; i ++) {
            if((double)i % 2 != 0) {
                System.out.print(".");
            }else {
                System.out.print("#");
            }
        }
        System.out.print("\n");
    }
    
    public static boolean printJudge(int H, int W) {
        if(H < 1 || W < 1 || H > 300 || W > 300) {
            return false;
	}else if(H == 0 && W == 0) {
            return false;
            
        }else return true;
    }
}

Measured memory_bytes: 37880
#include <bits/stdc++.h>
#include <math.h>
#define rep(i, n) for(int i = 0; i < (n); i++)
#define rrep(i, n) for(int i = 0; i <= (n); i++)
using namespace std;
typedef long long ll;
 
const ll INF = 1LL<<62;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
// 多次元 vector 生成
template<class T>
vector<T> make_vec(size_t a){
    return vector<T>(a);
}
template<class T, class... Ts>
auto make_vec(size_t a, Ts... ts){
  return vector<decltype(make_vec<T>(ts...))>(a, make_vec<T>(ts...));
}

using Graph = vector<vector<int>>;

typedef pair<int, int> P;
typedef priority_queue<int, vector<int>, greater<int>> PQ;
const int MOD = 1000000007;

int main(){
    int N,M; cin >> N >> M;
    vector<int> sum(N+1,0);
    int left_max=0, right_min=N;
    rep(i,M){
        int left, right;
        cin >> left >> right;
        left_max = max(left_max, left);
        right_min = min(right_min, right);
    }

    cout << max(0, right_min - left_max + 1) << endl;

}



Measured memory_bytes: 3764
# -*- coding: utf-8 -*-
import sys

N,M,K = list(map(int, input().rstrip().split()))
#-----

if (M == 1) and (K == N-1):
    print(1)
    sys.exit()
elif (M == 1) and (K < N-1):
    print(0)
    sys.exit()


mod = 998244353

a = M * pow(M-1, N-1, mod)
inv_M1 = pow((M-1), mod-2, mod )  # inverse element

comb = 1
ans = 0

for i in range(K+1):
    ans += ( comb * a )
    ans %= mod
    
    # Calculate variables for next step
    a *= inv_M1
    a %= mod
    
    inv_i1 = pow(i+1, mod-2, mod)  # inverse element
    comb *= ( (N-1-i) * inv_i1 )
    comb %= mod


print(ans)


Measured memory_bytes: 9248
N, M, K = map(int, input().split())

canMake = set()
for i in range(N + 1):
    for j in range(M + 1):
        area = (N - i) * (M - j) + i * j
        canMake.add(area)

if K in canMake:
    print('Yes')
else:
    print('No')

Measured memory_bytes: 20892
#include<bits/stdc++.h>
#define ld long double
#define ll long long
#define st first
#define nd second
#define mp make_pair
#define pii pair<int, int>
#define vi vector<int>
#define pb push_back
using namespace std;

int main() {
	ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
	int x;
	cin>>x;
	cout<<360 / __gcd(x, 360); 	
}


Measured memory_bytes: 3552
n, k = map(int, input().split())
lis = []
for _ in range(n):
    lis.append(int(input()))
    
lis = sorted(lis)

tmp = 10000000000

for i in range(n-k+1):
    ma = lis[i+k-1]
    mi = lis[i]
    
    tmp = min(tmp, ma-mi)
    
print(tmp)

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

using namespace std;


typedef struct {
	int type;
	double nenri;
	double minus;
} pattern;

int rishi=0;

int sim(int year,int money,int type,double nenri,double minus) {
	int rishi=0;

	for (int i=0;i<year;i++) {
		if(type==0)
			rishi+=money*nenri;
		else
			money+=money*nenri;

		money-=minus;
	}


	return money+rishi;
}

int main(void) {

	int m;


	cin >> m;

	for(int j=0;j<m;j++) {
		int shikin;

		int years;
		int n;
		
		cin >> shikin;
		cin >> years;
		cin >> n;

		vector<int> money;
		for(int i=0;i<n;i++) {
			pattern tmp;

			cin >> tmp.type >> tmp.nenri >> tmp.minus;
			money.push_back(sim(years ,shikin, tmp.type ,tmp.nenri ,tmp.minus));
		}

		sort(money.begin(),money.end(),greater<int>() );
		//cout << money[money.size()-1] << endl;
		cout << money[0] << endl;

	}


	return 0;
}

Measured memory_bytes: 1260
#include <bits/stdc++.h>
using namespace std;
int main()
{
    int a, b;
    cin>>a>>b;
    if(b == 1)
    {
        cout<<0<<endl;
        return 0;
    }
    int i = 1, j = 0;
    while((a * i) - j < b)
    {
        i++;
        j++;
    }
    cout<<i<<endl;
    return 0;
}


Measured memory_bytes: 256
#include<iostream>
using namespace std;
int main(){
    bool flag=true;
    int n;
    string s;
    cin>>n>>s;
    if(n%2==0){
        for(int i=0;i<n/2;i++)if(s[i]!=s[i+n/2])flag=false;
    }
    else flag=false;
    cout<<(flag?"Yes":"No")<<endl;
    return 0;
}

Measured memory_bytes: 256
#!/usr/bin/env python
# -*- coding: utf-8 -*-

import sys  # {{{
import os
import time
import re
from pydoc import help
import string
import math
from operator import itemgetter
from collections import Counter
from collections import deque
from collections import defaultdict as dd
import fractions
from heapq import heappop, heappush, heapify
import array
from bisect import bisect_left, bisect_right, insort_left, insort_right
from copy import deepcopy as dcopy
import itertools
# }}}

# pre-defined{{{
sys.setrecursionlimit(10**7)
INF = 10**20
GOSA = 1.0 / 10**10
MOD = 10**9+7
ALPHABETS = [chr(i) for i in range(ord('a'), ord('z')+1)]  # can also use string module
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def DP(N, M, first): return [[first] * M for n in range(N)]
def DP3(N, M, L, first): return [[[first] * L for n in range(M)] for _ in range(N)]
from inspect import currentframe
# }}}

def solve():
    s = input()
    if s == "ABC":
        print("ARC")
    else:
        print("ABC")

    return 0

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

# vim: set foldmethod=marker: }}}


Measured memory_bytes: 79820
h,n=map(int,input().split())
AB=[list(map(int,input().split())) for _ in range(n)]

dp=[float('inf')]*(h+1)
dp[0]=0
for a,b in AB:
  for i in range(h):
    if i+a<h:
      dp[i+a]=min(dp[i+a],dp[i]+b)
    else:
      dp[h]=min(dp[h],dp[i]+b)
print(dp[h])

Measured memory_bytes: 51036
#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>;
using Graph = vector<vector<int>>;

int main(){
    int s, w; cin >> s >> w;
    if(w >= s) cout << "unsafe" << endl;
    else cout << "safe" << endl;
}

Measured memory_bytes: 3624
#!/usr/bin/env python3
from collections import defaultdict, Counter
from itertools import product, groupby, count, permutations, combinations
from math import pi, sqrt
from collections import deque
from bisect import bisect, bisect_left, bisect_right
from string import ascii_lowercase
from functools import lru_cache
import sys
sys.setrecursionlimit(10000)
INF = float("inf")
YES, Yes, yes, NO, No, no = "YES", "Yes", "yes", "NO", "No", "no"
dy4, dx4 = [0, 1, 0, -1], [1, 0, -1, 0]
dy8, dx8 = [0, -1, 0, 1, 1, -1, -1, 1], [1, 0, -1, 0, 1, 1, -1, -1]


def inside(y, x, H, W):
    return 0 <= y < H and 0 <= x < W


def ceil(a, b):
    return (a + b - 1) // b


def sum_of_arithmetic_progression(s, d, n):
    return n * (2 * s + (n - 1) * d) // 2


def gcd(a, b):
    if b == 0:
        return a
    return gcd(b, a % b)


def lcm(a, b):
    g = gcd(a, b)
    return a / g * b


def solve(X):
    for A in range(-500, 510):
        for B in range(-500, 510):
            if A ** 5 - B ** 5 == X:
                return A, B
    return None, None

def main():
    X = int(input())
    print(*solve(X))


if __name__ == '__main__':
    main()


Measured memory_bytes: 9984
#include<stdio.h>

int main(void){
    int x,num,res;
    scanf("%d",&x);
    num = x/100;
    res = x%100;
    //printf("%d\n",num);
    //printf("%d\n",res);
    if(num*5>=res){
        printf("1\n");
    }else{
        printf("0\n");
    }
    return 0;
}


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

#define ll long long
#define rep(A,B,C) for(A=B;A<C;++A)
#define pii pair<int,int>
#define pll pair<ll,ll>

#define fi first
#define se second
#define all(A) A.begin(),A.end()

using namespace std;

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

ll N,K;
ll P[5050], C[5050];
ll mk[5050][5050];
ll mk2[5050];

ll i, j, k;

int main(){
    scanf("%lld%lld", &N,&K);
    rep(i,0,N){
        scanf("%lld", &P[i+1]);
    }
    rep(i,0,N){
        scanf("%lld", &C[i+1]);
    }
    rep(i,1,N+1){
        j = i;
        k = 0;
        ll sco = 0;
        mk[i][0] = 0;
        do{
            j = P[j];
            sco += C[j];
            mk[i][++k] = sco;
        } while (i != j);
        mk2[i] = k;
    }
    /*
    rep(i,1,N+1){
        rep(j,0,mk2[i]+1){
            printf("%lld ", mk[i][j]);
        }
        printf("\n");
    }*/
    ll ans = -1e18;
    
    rep(i,1,N+1){
        ll a = (K - 1) / mk2[i] * mk[i][mk2[i]];
        ll c = -1e18;
        k = (K - 1) % mk2[i];
        rep(j,1,k+2){
            c = max(c, mk[i][j]);
        }
        ans = max(ans, a + c);
        //printf("%lld\n", a + c);

        c = -1e18;
        rep(j,1,min(K,mk2[i])+1){
            c = max(c, mk[i][j]);
        }
        ans = max(ans, c);
        //printf("%lld\n", c);
    }
    printf("%lld\n", ans);

    return 0;
}

Measured memory_bytes: 201172
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define REP(i,m,n) for(int i=(m);i<(n);i++)
#define rep(i,n) REP(i,0,n)
#define pb push_back
#define all(a) a.begin(),a.end()
#define rall(c) (c).rbegin(),(c).rend()
#define mp make_pair
#define endl '\n'
typedef long long ll;
typedef pair<ll,ll> pll;
typedef long double ld;
const ll inf=1e9+7;
const ll mod=1e9+7;
signed main(){
    ll d;cin>>d;
    vector<ll>c(26);
    rep(i,26)cin>>c[i];
    vector<vector<ll> >s(d,vector<ll>(26));
    rep(i,d){
        rep(j,26)cin>>s[i][j];
    }
    vector<ll>last(26);
    vector<ll>v(d);
    ll ans=0;
    rep(i,d){
        ll ma=-inf*inf;
        ll idx=0;
        rep(t,26){
            ll cn=0;
            cn+=s[i][t];
            ll m=last[t];
            last[t]=i+1;
            rep(j,26){
                cn-=c[j]*(i-last[j]+1);
            }
            last[t]=m;
            if(cn>ma){
                ma=cn;
                idx=t;
            }
        }
        ans+=ma;
        last[idx]=i+1;
        v[i]=idx+1;
    }
    ll m=100000;
    while(m){
        m--;
        ll a=((ll)rand())%d,b=rand()%26;
        ll cnt=0;
        vector<ll>la(26);
        rep(i,d){
            ll t=v[i]-1;
            if(a==i)t=b;
            cnt+=s[i][t];
            la[t]=i+1;
            rep(j,26){
                cnt-=c[j]*(i-la[j]+1);
            }
        }
        if(ans<cnt){
            cnt=ans;
            v[a]=b+1;
        }
    }
    rep(i,d){
        cout<<v[i]<<endl;
    }
}


Measured memory_bytes: 3724
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner scn = new Scanner(System.in);
		int r = scn.nextInt();
		int g = scn.nextInt();
		int b = scn.nextInt();

		int num = r * 100 + g * 10 + b;
		if(num % 4 == 0){
			System.out.println("YES");
		}else{
			System.out.println("NO");
		}
	}
}


Measured memory_bytes: 21588
#include <cstdio>
#include <cmath>

int main(void)
{
	int x, h;
	
	while (scanf("%d %d", &x, &h)){
		if (x == 0 && h == 0) break;
		
		double res = 0;
		
		res = (x * sqrt((4 * h * h) + (x * x))) + (x * x);
		
		printf("%.6lf\n", res);
	}
	
	return (0);
}

Measured memory_bytes: 0
#include <iostream> // cout, endl, cin
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower
#include <math.h>
#include <iomanip>
using namespace std;
#define int long long

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

    int n; cin >> n;
    vector<int> a(100000);
    int sum = 0;
    int i = 1;
    while(sum < n){
        a.at(i) = 1;
        sum += i;
        i ++;
    }

    int sa = sum - n;
    a.at(sa) = 0;

    for(int j = 0;j < 100000;j ++){
        if(a.at(j) == 1) cout << j << endl;
    }
}

Measured memory_bytes: 3992
from itertools import product
n, c = map(int, input().split())
color_costs = [map(int, input().split()) for _ in range(c)]
matrix = [map(int, input().split()) for _ in range(n)]
colord = {(i+1, j+1):cost for i, row in enumerate(color_costs)
                         for j, cost in enumerate(row)}
 
cellgroups = [[] for _ in range(3)]
for i, row in enumerate(matrix):
  for j, color in enumerate(row):
    cellgroups[(i+1+j+1)%3].append(color)
  
cc = [[(color, sum(colord[cellcolor, color] for cellcolor in cells))
	       									for color in range(1,c+1)]
      										for cells in cellgroups]
 
dd = [sorted(xs, key=lambda x:x[1])[:3] for xs in cc]
ee = (a[1]+b[1]+c[1] for a, b, c in product(*dd) if len(set((a[0], b[0], c[0]))) == 3)
print(min(ee))

Measured memory_bytes: 21216
a,b,m = map(int, input().split())
lst_A = list(map(int, input().split()))
lst_B = list(map(int, input().split()))
lst_x = [list(map(int, input().split())) for _ in range(m)]

cheap_price = float("inf")
for i in lst_x:
    price = lst_A[i[0]-1] + lst_B[i[1]-1] - i[2]
    if price < cheap_price:
        cheap_price = price

price_wa = min(lst_A) + min(lst_B)

if cheap_price <= price_wa:
    print(cheap_price)
elif cheap_price > price_wa:
    print(price_wa)

Measured memory_bytes: 38560
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std;
const int N = 1e6 + 5;
int read() {
	int x = 0, f = 1; char ch;
	while(! isdigit(ch = getchar())) (ch == '-') && (f = -f);
	for(x = ch ^ 48; isdigit(ch = getchar()); x = (x << 3) + (x << 1) + (ch ^ 48));
	return x * f;
}
template <class T> T Max(T a, T b) { return a > b ? a : b; }
template <class T> T Min(T a, T b) { return a < b ? a : b; }
int n, top, a[N], p[N], mn[N], sta[N];
int main() {
	n = read();
	for(int i = 1; i <= n; ++ i) p[i] = read();
	p[0] = 0; p[n + 1] = n + 1;
	for(int i = 1; i <= n; ++ i) {
		if(p[i - 1] != i - 1 && p[i] != i && p[i + 1] != i + 1) return puts("No"), 0;
		a[i] = (p[i] == i);
	}
	for(int i = 1, j; i <= n; i = j + 1) {
		for(j = i; j < n && a[j] != a[j + 1]; ++ j);
		top = 0;
		for(int k = i; k <= j; ++ k) {
			if(p[k] < i || j < p[k]) return puts("No"), 0;
			if(a[k] == 0) sta[++ top] = p[k];
		}
		mn[top] = sta[top];
		for(int k = top - 1; k >= 1; -- k) mn[k] = min(mn[k + 1], sta[k]);
		int mx = sta[1];
		for(int k = 2; k < top; ++ k) {
			mx = max(mx, sta[k]);
			if(mn[k] < sta[k] && sta[k] < mx) return puts("No"), 0;
		}
	}
	puts("Yes");
	return 0;
}


Measured memory_bytes: 13696
#include<iostream>
#include <string>
#include<algorithm>
#include <set>
#include <cmath>
#include<math.h>
using namespace std;

int main(void){
	ios::sync_with_stdio(false);
	long N, P, i, k, j, a,s;
	cin >> N >> P;
	s = (long)pow((double)(P), 1.0 / (double)(N));
	a = 0;
	if (N == 1) a = P;
	else{

		for (i = 1; i <= s + 1; i++) {
			j = (long)pow((double)(i), (double)(N));
			if (P % j == 0) a = i;
			if (P <= j) break;
		}
	}


	cout << a;
	return 0;
}


Measured memory_bytes: 256
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <algorithm>
#include <map>
using namespace std;
typedef long long LL;
const int MaxN = 1e5;
const LL MOD = 1e9 + 7;

LL n;
LL a[MaxN + 5];
LL cnt[MaxN + 5];
LL fact[MaxN + 5], rev[MaxN + 5];
LL  qwr(LL x, LL y)
{
	LL res = 1;
	while(y > 0)
	{
		if(y & 1) res = (res * x) % MOD;
		x = (x * x) % MOD;
		y = y >> 1;
	}
	return res % MOD;
}
LL C(LL n, LL m)
{
	if(n < 0 || m < 0) return 0;
	if(n < m) return 0;
	return (((fact[n] * rev[m]) % MOD) * rev[n - m]) % MOD;
}

int main()
{
	fact[0] = 1LL, rev[0] = 1LL;
	for(LL i = 1; i <= MaxN + 2; i++)
		fact[i] = (fact[i - 1] * i) % MOD;
	for(LL i = 1; i <= MaxN + 2; i++)
		rev[i] = qwr(fact[i], MOD - 2) % MOD;
	while(scanf("%lld", &n) != EOF)
	{
		LL tmp = 0;
		for(LL i = 1; i <= n + 1; i++)
		{
			scanf("%lld", &a[i]);
			cnt[a[i]]++;
			if(cnt[a[i]] > 1) tmp += n + 1 - i;
		}
		for(LL i = 1; i <= n + 1; i++)
		{
			if(cnt[a[i]] > 1) {
				tmp += i - 1; 
				//printf("a[i] = %lld i = %lld\n", a[i], i);
				break;
			}
		}
		for(LL i = 1; i <= n + 1; i++)
		{
			LL ans = (C(n + 1, i) - C(tmp, i - 1) + MOD) % MOD;
			printf("%lld\n", ans);
		}
		memset(a, 0, sizeof(a));
		memset(cnt, 0, sizeof(cnt));
	}
	return 0;
}

Measured memory_bytes: 4224
// abc085_c
#include <bits/stdc++.h>
#ifdef LOCAL
#include "../cxx-prettyprint/prettyprint.hpp"
#endif
using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> P;

#define REP(i, n) for (int (i) = 0 ; (i) < (int)(n) ; ++(i))
#define REPN(i, m, n) for (int (i) = m ; (i) < (int)(n) ; ++(i))
#define REP_REV(i, n) for (int (i) = (int)(n) - 1 ; (i) >= 0 ; --(i))
#define REPN_REV(i, m, n) for (int (i) = (int)(n) - 1 ; (i) >= m ; --(i))
#define ALL(x) x.begin(), x.end()

#define INF ((1 << 29)-1)
#define MOD (1000000007)

#define print2D(h, w, arr) REP(i, h) { REP(j, w) cout << arr[i][j] << " "; cout << endl; }
#define print_line(vec, n) {for(int i=0;i<(n-1);i++) cout << (vec)[i] << " "; cout << (vec)[(n)-1] << endl;}
template<class T> void print(const T& x){cout << x << endl;}
template<class T, class... A> void print(const T& first, const A&... rest) { cout << first << " "; print(rest...); }
struct PreMain {PreMain(){cin.tie(0);ios::sync_with_stdio(false);cout<<fixed<<setprecision(20);}} premain;

int main() {
#ifdef LOCAL
    ifstream in("../arg.txt"); cin.rdbuf(in.rdbuf());
#endif

    int N, Y;
    cin >> N >> Y;

    REP(i, N+1) REP(j, N+1){
        int k = N - i - j;
        if (k < 0) continue;

        if (i * 10000 + j * 5000 + k * 1000 == Y){
            print(i, j, k);
            return 0;
        }
    }
    print("-1 -1 -1");

    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <string>
#include <sstream>
#include <complex>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
#include <bitset>
using namespace std;
typedef long long unsigned int ll;

#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))

int countNumOfChar(char * s, int N){
    int n = 0;
    int max_var = -INF;
    for(int sep = 0; sep < N; sep++){
        map<char, int> mpl , mpu;
        for(int i = 0; i < N; i++){
            if(i <= sep){
                mpl[s[i]]++;
            }else{
                mpu[s[i]]++;
            }
        }

        int var = 0;
        for(auto l:mpl){
            for(auto u:mpu){
                if(l.first == u.first){
                    ++var;
                }
            }
        }
        max_var = max(max_var , var);
        var = 0;
 
    }
    return max_var; 
}

int main(void){

    int N;
    cin >> N;
    char S[N];
    for(int i = 0; i < N; i++) cin >> S[i];

    cout <<  countNumOfChar(S, N) << endl;

    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<string>
#include<algorithm>
#include<cstring>
#include<vector>
#include<queue>
using namespace std;
#define int(x) int x; scanf("%d",&x)
#define input(x) scanf("%d",&x)
#define rep(x,n) for(int x = 0; x < n; x++)
#define _br printf("\n")
#define INF 2000000000

vector<pair<int,int> > PathList[10000];
int d[10000];
bool complete[10000];

void dijkstra(int n,vector<pair<int,int> > PathList[]){
    priority_queue<pair<int,int> > PQ;
    
    rep(i,n){
        d[i] = INF;
        complete[i] = false;
    }
    d[0] = 0;
    PQ.push(make_pair(-d[0],0));
    int count = 0;
    
    while (count != n) {
        //select
        int mindi;
        while (1) {
            if (!complete[PQ.top().second]) {
                mindi = PQ.top().second;
                PQ.pop();
                break;
            }
            PQ.pop();
        }
        
        complete[mindi] = true;
        count++;
        
        //update
        rep(i,PathList[mindi].size()){
            if (PathList[mindi][i].second + d[mindi] < d[PathList[mindi][i].first]) {
                d[PathList[mindi][i].first] = PathList[mindi][i].second + d[mindi];
                PQ.push(make_pair(-(PathList[mindi][i].second + d[mindi]),PathList[mindi][i].first));
            }
        }
    }
}


int main(){
    int(n);
    rep(i,n){
        int(k);int(num);
        rep(j,num){
            int(s);int(t);
            PathList[i].push_back(make_pair(s,t));
        }
    }
    
    dijkstra(n,PathList);
    
    rep(i,n){
        printf("%d %d\n",i,d[i]);
    }
    
    return 0;
}

Measured memory_bytes: 6276
import java.util.*;

class Main{
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		int a, b;
		
		a = sc.nextInt();
		b = sc.nextInt();
		
		int s = a * b;
		int l = a * 2 + b * 2;
		
		System.out.println(s + " " + l);
	}
}

Measured memory_bytes: 26072
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for (ll i = 0; i < (ll)(n); ++i)
#define erep(i, n) for (ll i = 0; i <= (ll)(n); ++i)
#define FOR(i,a,b) for (ll i = (a); i < (ll)(b); ++i)
#define EFOR(i,a,b) for (ll i = (a); i <= (ll)(b); ++i)
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } }


struct Edge {
    ll to;
    ll weight;
    Edge(ll t, ll w) : to(t), weight(w) { }
};
using Graph = vector<vector<Edge>>;
using P = pair<ll, ll>;


typedef vector<vector<int> > Matrix;

const int INF = 100000000;
Matrix d;

void warshall_floyd(int n) { // nは頂点数
    for (int i = 0; i < n; i++)      // 経由する頂点
        for (int j = 0; j < n; j++)    // 開始頂点
            for (int k = 0; k < n; k++)  // 終端
                d[j][k] = min(d[j][k], d[j][i] + d[i][k]);
}

ll modnum = 1e9+7;

int main() {
    ll n; cin >> n;
    vector<ll> a(n);
    vector<ll> use(n,0);
    rep(i, n) cin >> a[i];
    rep(i, n) {
        if(a[i] == 0 && use[0] > 0) {
            cout << 0 << endl;
            return 0;
        }
        if(use[a[i]] > 1) {
            cout << 0 << endl;
            return 0;
        }
        use[a[i]]++;
    }

    ll ans = 1;
    rep(i, n/2) {
        ans *= 2;
        ans %= modnum;
    }

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



Measured memory_bytes: 1792
# -*- coding: utf-8 -*-

def get_input() -> tuple:
    """
    標準入力を取得する.

    Returns:\n
        tuple: 標準入力
    """
    N = int(input())
    A = list(map(int, input().split()))
    B = list(map(int, input().split()))
    C = list(map(int, input().split()))

    return N, A, B, C


def get_lb(l: list, key: int) -> int:
    """
    l[index] > keyとなる最小のindexを求める.

    Args:\n
        l (list): リスト
        key (int): 整数

    Returns:\n
        int: l[index] > keyとなる最小のindex
    """
    low = -1
    high = len(l)
    while 1 < high - low:
        mid = (low + high) // 2
        guess = l[mid]
        if guess > key:
            high = mid
        else:
            low = mid
    return high


def get_ub(l: list, key: int) -> int:
    """
    l[index] < keyとなる最大のindexを求める.

    Args:\n
        l (list): リスト
        key (int): 整数

    Returns:\n
        int: l[index] < keyとなる最大のindex
    """
    low = -1
    high = len(l)
    while 1 < high - low:
        mid = (low + high) // 2
        guess = l[mid]
        if guess < key:
            low = mid
        else:
            high = mid
    return low


def main(N: int, A: list, B: list, C: list) -> None:
    """
    メイン処理.

    Args:\n
        N (int): パーツの数(1 <= N <= 10**5)
        A (list): 上部のパーツのサイズ(1 <= A_i <= 10**9)
        B (list): 中部のパーツのサイズ(1 <= B_i <= 10**9)
        C (list): 下部のパーツのサイズ(1 <= C_i <= 10**9)
    """
    # 事前にリストをソートしておく
    A = sorted(A)
    B = sorted(B)
    C = sorted(C)

    # 求解処理
    ans = 0
    for i in range(N):
        B_i = B[i]
        ans += (get_ub(A, B_i) + 1) * (N - get_lb(C, B_i))

    # 結果出力
    print(ans)


if __name__ == "__main__":
    # 標準入力を取得
    N, A, B, C = get_input()

    # メイン処理
    main(N, A, B, C)


Measured memory_bytes: 28976
def buttle(a):
    alice = 0
    bob = 0

    a.sort(reverse=True)
    for i in range(len(a)):
        if i % 2 != 0:
            continue
        alice += a[i]
        if len(a) > i+1:
            bob += a[i+1]
    return alice - bob

n = int(input())
a = [int(x) for x in input().split()]
print(buttle(a))


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

#define DEBUG(x) cerr << #x << " = " << x << endl

struct Node {
    int number;
    char kind;
    int index;
};

int partition(vector<Node>& A, const int l, const int r) {
    const int pivot = A[r - 1].number;
    int head = l;
    for(int i = l; i < r; i++) {
        if(A[i].number <= pivot) {
            swap(A[head], A[i]);
            head++;
        }
    }
    return head - 1;
}

void quicksort(vector<Node>& A, const int l, const int r) {
    if(r - l > 1) {
        int g = partition(A, l, r);
#if 0
        for(int i = 0; i <= g; i++) {
            cerr << A[i].number << ' ';
        }
        cerr << "| ";
        for(int i = g + 1; i < r; i++) {
            cerr << A[i].number << ' ';
        }
        cerr << endl;
#endif
        quicksort(A, l, g);
        quicksort(A, g + 1, r);
    }
}

int main() {
    int N; cin >> N;
    vector<Node> A;
    for(int i = 0; i < N; i++) {
        int number;
        char kind;
        cin >> kind >> number;
        A.push_back((Node){ number, kind, i });
    }
    quicksort(A, 0, N);

    bool stable = true;
    for(int i = 1; i < N; i++) {
        if(A[i - 1].number == A[i].number && A[i - 1].index > A[i].index) {
            stable = false;
        }
    }
    cout << (stable ? "Stable" : "Not stable") << endl;
    for(int i = 0; i < N; i++) {
        cout << A[i].kind << ' ' << A[i].number << endl;
    }
}

Measured memory_bytes: 2724
#include<bits/stdc++.h>
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define pb push_back
using namespace std;
using ll = long long;
using vi = vector<ll>;
using pi = pair<ll, ll>;
const int maxn = 4e5 + 4433, mod = 998244353;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
#define left defnotavariable
int n;
multiset<int> left;
vi used;
void apply() {
	for(int i = used.size(); i--;) {
		auto it = left.upper_bound(used[i]-1);
		if(it==left.begin()) {cout << "No"; exit(0);}
		--it;
		used.pb(*it);
		left.erase(it);
	}
}
int main() {
	ios::sync_with_stdio(0);
	cin.tie(0);
	cin >> n;
	for(int t, i = 0; i < 1<<n; i++) cin >> t, left.insert(t);
	used.pb(*left.rbegin());
	left.erase(--left.end());
	while(left.size())
		apply();
	cout << "Yes";
}



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

int main(){
string A, B, C;
  cin >> A >> B >> C;
  
if((A.at(A.size() - 1) == B.at(0)) && (B.at(B.size() - 1) == C.at(0))) cout << "YES" << endl;
else cout << "NO" << endl;
return 0;    
  
}

Measured memory_bytes: 256
#!usr/bin/env pypy3
from collections import defaultdict, deque
from heapq import heappush, heappop
from itertools import permutations, accumulate
import sys
import math
import bisect


def LI(): return [int(x) for x in sys.stdin.readline().split()]


def I(): return int(sys.stdin.readline())


def LS(): return [list(x) for x in sys.stdin.readline().split()]


def S():
    res = list(sys.stdin.readline())
    if res[-1] == "\n":
        return res[:-1]
    return res


def IR(n):
    return [I() for i in range(n)]


def LIR(n):
    return [LI() for i in range(n)]


def SR(n):
    return [S() for i in range(n)]


def LSR(n):
    return [LS() for i in range(n)]


sys.setrecursionlimit(1000000)


def main():
    N = I()
    A = LI()

    sumxor = 0
    for ai in A:
        sumxor ^= ai

    for ai in A:
        print(sumxor ^ ai, end=" ")


main()


Measured memory_bytes: 31976