akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include<string>
#include<vector>
#include<utility>
#include<algorithm>
#include<map>
#include<cstdlib>
#include<cmath>
#include<numeric>
#include<iomanip>
#include<functional>
#define rep(i,n)for(int i=0;i<(n);i++)
using namespace std;
using ll =long long;
//const int mod = 1000000007;
//class mint {
//	long long x;
//public:
//	mint(long long x = 0) : x((x% mod + mod) % mod) {}
//	mint operator-() const {
//		return mint(-x);
//	}
//	mint& operator+=(const mint & a) {
//		if ((x += a.x) >= mod) x -= mod;
//		return *this;
//	}
//	mint & operator-=(const mint & a) {
//		if ((x += mod - a.x) >= mod) x -= mod;
//		return *this;
//	}
//	mint & operator*=(const  mint & a) {
//		(x *= a.x) %= mod;
//		return *this;
//	}
//	mint operator+(const mint & a) const {
//		mint res(*this);
//		return res += a;
//	}
//	mint operator-(const mint & a) const {
//		mint res(*this);
//		return res -= a;
//	}
//	mint operator*(const mint & a) const {
//		mint res(*this);
//		return res *= a;
//	}
//	mint pow(ll t) const {
//		if (!t) return 1;
//		mint a = pow(t >> 1);
//		a *= a;
//		if (t & 1) a *= *this;
//		return a;
//	}
//	// for prime mod
//	mint inv() const {
//		return pow(mod - 2);
//	}
//	mint& operator/=(const mint & a) {
//		return (*this) *= a.inv();
//	}
//	mint operator/(const mint & a) const {
//		mint res(*this);
//		return res /= a;
//	}
//
//	friend ostream& operator<<(ostream & os, const mint & m) {
//		os << m.x;
//		return os;
//	}
//};
char num[5]{ 'M','A','R','C','H' };
void recursive_comb(vector<int> indexes, int s, int rest, std::function<void(vector<int>)> f) {
	if (rest == 0) {
		f(indexes);
	}
	else {
		if (s < 0) return;
		recursive_comb(indexes, s - 1, rest, f);
		indexes[rest - 1] = s;
		recursive_comb(indexes, s - 1, rest - 1, f);
	}
}

// nCkの組み合わせに対して処理を実行する
void foreach_comb(int n, int k, std::function<void(vector<int>)> f) {
	 vector<int>indexes(k);
	recursive_comb(indexes, n - 1, k, f);
}
ll ans = 0;
map<char, ll>a;
int main() {
	int N;
	cin >> N;
	vector<string>s(N);
	rep(i, N)cin >> s[i];
	
	rep(i, N) {
		a[s[i][0]]++;
	}
	
	foreach_comb(5, 3, [](vector<int> indexes) {
		ans += a[num[indexes[0]]] * a[num[indexes[1]]] * a[num[indexes[2]]];

		});
	cout << ans;
}



Measured memory_bytes: 6144
#include <stdio.h>
#include <stdlib.h>

struct node {
  struct node *right;
  struct node *left;
  struct node *parent;
  int key;
};
typedef struct node * Node;
#define NIL NULL

Node root;

Node treeMinimum(Node x) {
  while(x -> left != NIL) {
    x = x -> left;
  }
  return x;
}

Node treeSearch(Node u, int k) {
  if(u == NIL || k == u -> key) {
    return u;
  }
  if(k < u -> key) {
    return treeSearch(u -> left, k);
  }
  else {
    return treeSearch(u -> right, k);
  }
}

Node treeSuccessor(Node x) {
  Node y;
  if(x -> right != NIL) {
    return treeMinimum(x -> right);
  }
  y = x -> parent;
  while(y != NIL && x == y -> right) {
    x = y;
    y = y -> parent;
  }
  return y;
}

void treeDelete(Node z) {
  Node y;
  Node x;
} 

void insert(int k) {
  Node y = NIL;
  Node x = root;
  Node z;
  
  z = malloc(sizeof(struct node));
  z -> key = k;
  z -> left = NIL;
  z -> right = NIL;
  
  while(x != NIL) {
    y = x;
    if(z -> key < x -> key) {
      x = x -> left;
    }
    else {
      x = x -> right;
    }
  }
  z -> parent = y;
  if(y == NIL) {
    root = z;
  }
  else if(z -> key < y -> key) {
    y -> left = z;
  }
  else {
    y -> right = z;
  }
}

void inorder(Node u) {
  if(u != NIL) {
    inorder(u -> left);
    printf(" %d", u -> key);
    inorder(u -> right);
  }
}

void preorder(Node u) {
  printf(" %d", u -> key);
  if(u != NIL) {
    if(u -> left != NIL) preorder(u -> left);
    if(u -> right != NIL) preorder(u -> right);
  }
}

main() {
  int n, i, x;
  char com[20];
  scanf("%d", &n);

  for(i = 0; i < n; i++) {
    scanf("%s", com);
    if(com[0] == 'f') {
      scanf("%d", &x);
      Node t = treeSearch(root, x);
      if(t != NIL) printf("yes\n");
      else printf("no\n");
    }
    else if(com[0] == 'i') {
      scanf("%d", &x);
      insert(x);
    }
    else if(com[0] == 'p') {
      inorder(root);
      printf("\n");
      preorder(root);
      printf("\n");
    }
    else if(com[0] == 'd') {
      scanf("%d", &x);
      treeDelete(treeSearch(root, x));
    }
  }
  return 0;
}

Measured memory_bytes: 24036
n = int(input())
a = list(map(int, input().split(' ')))

ok = 0
f = 1
for i in range(n):
    if a[i] - 1 != i:
        f = 0
if f:
    ok = 1
for i in range(n):
    for j in range(i + 1, n):
        a[i], a[j] = a[j], a[i]
        f = 1
        for k in range(n):
            if a[k] - 1 != k:
                f = 0
        if f:
            ok = 1
        a[i], a[j] = a[j], a[i]
print('YES' if ok else 'NO')

Measured memory_bytes: 9044
from collections import Counter

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

MOD = 10 ** 9 + 7

c = Counter(a)

if n % 2 == 0:
    temp = 1
    for _ in range(n // 2):
        if c[temp] != 2:
            print(0)
            exit()
        temp += 2
    print(2 ** (n // 2) % MOD)
else:
    if c[0] != 1:
        print(0)
        exit()
    temp = 2
    for _ in range(n // 2):
        if c[temp] != 2:
            print(0)
            exit()
        temp += 2
    print(2 ** (n // 2) % MOD)

Measured memory_bytes: 14820
#include <iostream>
#include <algorithm>

using namespace std;

int main(){
  int n; cin >> n;
  int a[n+1];
  for(int i=1;i<=n;i++) cin >> a[i];
  //odd sum is positive
  long long sum=0;
  long long o_cnt=0;
  for(int i=1;i<=n;i++){
    sum=sum+a[i];
    if(i%2==1 && sum<=0){
      o_cnt=o_cnt+(1-sum);
      sum=1;
    }
    if(i%2==0 && sum>=0){
      o_cnt=o_cnt+(sum+1);
      sum=-1;
    }
  }
  //even sum is positive
  sum=0;
  long long e_cnt=0;
  for(int i=1;i<=n;i++){
    sum=sum+a[i];
    if(i%2==0 && sum<=0){
      e_cnt=e_cnt+(1-sum);
      sum=1;
    }
    if(i%2==1 && sum>=0){
      e_cnt=e_cnt+(sum+1);
      sum=-1;
    }
  }
  cout << min(o_cnt,e_cnt) << endl;
}

Measured memory_bytes: 640
import std.algorithm;
import std.array;
import std.conv;
import std.math;
import std.range;
import std.stdio;
import std.string;
import std.typecons;

T read(T)() { return readln.chomp.to!T; }
T[] reads(T)() { return readln.split.to!(T[]); }
alias readint = read!int;
alias readints = reads!int;

int calc(int a, int b, int c, int x) {
    if (x % 100 == 50) {
        return c == 0 ? 0 : calc(a, b, c - 1, x - 50);
    }

    assert(x % 100 == 0); // x は 100 の倍数で考える
    int ans = 0;

    // 500 円の枚数を固定
    for (int i = 0; i <= a; i++) {
        int m = x - 500 * i;
        if (m < 0) break;

        int t = m / 100;
        if (b + c/2 < t) continue; // b, c で m 円払えない

        // 100 円の枚数を最小化する
        int lo = t - min(t, c / 2);
        // 100 円の枚数を最大化する
        int hi = min(t, b);
        ans += hi - lo + 1;
    }
    return ans;
}

void main() {
    int a = readint;
    int b = readint;
    int c = readint;
    int x = readint;

    writeln(calc(a, b, c, x));
}


Measured memory_bytes: 256
# include "bits/stdc++.h"
using namespace std;
using LL = long long;
using ULL = unsigned long long;
const double PI = acos(-1);
template<class T>constexpr T INF() { return ::std::numeric_limits<T>::max(); }
template<class T>constexpr T HINF() { return INF<T>() / 2; }
template <typename T_char>T_char TL(T_char cX) { return tolower(cX); };
template <typename T_char>T_char TU(T_char cX) { return toupper(cX); };
const int vy[] = { -1, -1, -1, 0, 1, 1, 1, 0 }, vx[] = { -1, 0, 1, 1, 1, 0, -1, -1 };
const int dx[4] = { 0,1,0,-1 }, dy[4] = { 1,0,-1,0 };
int popcnt(unsigned long long n) { int cnt = 0; for (int i = 0; i < 64; i++)if ((n >> i) & 1)cnt++; return cnt; }
int d_sum(LL n) { int ret = 0; while (n > 0) { ret += n % 10; n /= 10; }return ret; }
int d_cnt(LL n) { int ret = 0; while (n > 0) { ret++; n /= 10; }return ret; }
LL gcd(LL a, LL b) { if (b == 0)return a; return gcd(b, a%b); };
LL lcm(LL a, LL b) { LL g = gcd(a, b); return a / g*b; };
# define ALL(qpqpq)           (qpqpq).begin(),(qpqpq).end()
# define UNIQUE(wpwpw)        sort(ALL((wpwpw)));(wpwpw).erase(unique(ALL((wpwpw))),(wpwpw).end())
# define LOWER(epepe)         transform(ALL((epepe)),(epepe).begin(),TL<char>)
# define UPPER(rprpr)         transform(ALL((rprpr)),(rprpr).begin(),TU<char>)
# define FOR(i,tptpt,ypypy)   for(LL i=(tptpt);i<(ypypy);i++)
# define REP(i,upupu)         FOR(i,0,upupu)

struct INIT{
    INIT(){
        std::ios::sync_with_stdio(false);
        std::cin.tie(0);
        cout << fixed << setprecision(13);
    }
}INIT;

LL h, n;
LL a[101010];

int main(){
    cin >> h >> n;
    LL sum = 0;
    REP(i, n){
        cin >> a[i];
        sum += a[i];
    }
    cout << (h <= sum ? "Yes" : "No") << endl;
}

Measured memory_bytes: 1024
#include <iostream>
#include <array>
#include <algorithm>

int main(){

	int a1, a2, a3, a4, b1, b2, b3, b4;

	while(std::cin >> a1 >> a2 >> a3 >> a4){
		
		std::cin >> b1 >> b2 >> b3 >> b4;
		
		std::array<int, 4> A = {a1, a2, a3, a4};
		std::array<int, 4> B = {b1, b2, b3, b4};
		
		int hit = 0;
		int blow = 0;

		for(int i = 0; i < 4; ++i){
			
			if(A[i] == B[i])
				++hit;
			
	                else
			blow += std::count(A.begin(), A.end(), B[i]);

		}

		std::cout << hit << " " << blow << std::endl;
	}

		return 0;

}

Measured memory_bytes: 1160
#include <algorithm>
#include <iostream>
#include<string>
using namespace std;


int main()
{
	int A, B,C;
	cin  >> A >> B;
	C =  A + B;
	if (C  <10) {
		cout << C << endl;
	}
	else {
		cout << "error" << endl;
	}
	
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <string>
#include <algorithm>
#include <utility>
#include <cmath>
#include <vector>
#include <queue>
#include <set>
#include <map>
#define rep(i, n) for(int i = 0; i < n; i++)
using namespace std;
typedef long long ll;
const ll mod = 1000000007;

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

    vector<pair<pair<string, int>, int>> book(n);
    rep(i, n) {
        string s;
        int p;
        cin >> s >> p;
        book[i] = make_pair(make_pair(s, -p), i+1);
    }
    sort(book.begin(), book.end());

    rep(i, n) {
        cout << book[i].second << "\n";
    }
    
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define FORR(i, m, n) for(int i = m; i >= n; i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define ll long long
#define pb(a) push_back(a)

int main(){
  int a, b;
  cin >> a >> b;
  if(a <= 8 && b <= 8) cout << "Yay!";
  else cout << ":(";
}


Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<vector>
#include<string>
#include<functional>
#include<queue>
#include <iomanip>
#include<map>
#include<limits>
#include<cmath>
#include<algorithm>
#include<bitset>
#include<utility>
#include<complex>
#include<cstdlib>
#include<set>
#include<cctype>

#define DBG cerr << '!' << endl;
#define REP(i,n) for(int (i) = (0);(i) < (n);++i)
#define rep(i,s,g) for(int (i) = (s);(i) < (g);++i)
#define rrep(i,s,g) for(int (i) = (s);i >= (g);--(i))
#define PB push_back
#define MP make_pair
#define FI first
#define SE second
#define SHOW1d(v,n) {for(int i = 0;i < (n);i++)cerr << v[i] << ' ';cerr << endl << endl;}
#define SHOW2d(v,i,j) {for(int aaa = 0;aaa < i;aaa++){for(int bbb = 0;bbb < j;bbb++)cerr << v[aaa][bbb] << ' ';cerr << endl;}cerr << endl;}
#define ALL(v) v.begin(),v.end()

using namespace std;

typedef long long ll;
typedef vector<int> iv;
typedef vector<iv> iiv;
typedef vector<string> sv;

struct UF
{
	vector<ll> par; // ???
	// ?????????
	UF(int n):par(n) {
		for(int i = 0; i < n; i++){
			par[i] = i;
		}
	}
	// ??¨??????????±???????
	int find(int x) {
		if (par[x] == x) return x;
		else return par[x] = find(par[x]);
	}
	// x??¨y????±??????????????????????
	void unite(int x, int y) {
		x = find(x); y = find(y);
		if (x == y) return;
		// ??¨??????????????????????????£??¨??????????????????
		par[x] = y;
	}
	// x??¨y?????????????????????true
	bool same(int x, int y) { return find(x) == find(y); }
};

struct node
{
	int par;
	vector<int> chi;
};


int main()
{
	int n,q;
	while(cin >> n >> q,n|q)
	{
		bool me[100100] = {};
		UF uf(n+1);
		
		vector<node> v(n+1);
		v[1].par = 1;me[1] = true;
		
		
		REP(i,n-1)
		{
			int tmp;cin >> tmp;
			v[tmp].chi.PB(i+2);
			v[i+2].par = tmp;
		}
		
		vector<pair<char,int> > p;
		
		REP(i,q)
		{
			char c;int num;
			cin >> c >> num;
			if(c == 'M')
			{
				if(me[num])continue;
				me[num] = true;
			}
			p.PB(MP(c,num));
		}
		
		for(int i = 1;i <= n;i++)
		{
			if(me[i])
			{
				queue<int> Q;
				Q.push(i);
				while(!Q.empty())
				{
					int tmp = Q.front();Q.pop();
					
					REP(j,v[tmp].chi.size())
					{
						if(me[v[tmp].chi[j]])continue;
						uf.unite(v[tmp].chi[j],i);
						Q.push(v[tmp].chi[j]);
					}
				}
			}
		}
		
		
		ll ans = 0;
		
		for(int i = p.size()-1;i >= 0;--i)
		{
			if(p[i].FI == 'Q')
			{
				ans += uf.find(p[i].SE);
			}
			else
			{
				uf.unite(p[i].SE,v[p[i].SE].par);
			}
		}
	
		cout << ans << endl;
	}
	return 0;
}

Measured memory_bytes: 11668
import queue
import copy
import math
from collections import deque
import bisect

# 2つの入力を空白で分割し、数値化
s, t = map(str, input().split())

n1, n2 = map(int, input().split())

color = input()

dict = {}
dict[s] = int(n1)
dict[t] = int(n2)

dict[color] = dict[color] - 1

print(str(dict[s]) + " " + str(dict[t]))

Measured memory_bytes: 4464
n=int(input())
a=list(map(int,input().split()))
b=list(map(int,input().split()))
sm=sum(a)

cnt=0
rest=0

for i in range(n):
    a[i]=max(0,a[i]-rest)
    rest=0
    rest=max(0,b[i]-a[i])
    a[i]=max(0,a[i]-b[i])
a[n]=max(0,a[n]-rest)

print(sm-sum(a))


Measured memory_bytes: 18624
#include<bits/stdc++.h>
using namespace std;
int main()
{
  string s;
  cin>>s;
  if(s.compare("SUN")==0)
  cout<<7<<endl;
  else if(s.compare("MON")==0)
  cout<<6<<endl;
  else if(s.compare("TUE")==0)
  cout<<5<<endl;
  else if(s.compare("WED")==0)
  cout<<4<<endl;
  else if(s.compare("THU")==0)
  cout<<3<<endl;
  else if(s.compare("FRI")==0)
  cout<<2<<endl;
  else if(s.compare("SAT")==0)
  cout<<1<<endl;

}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define sz 100002
#define pb push_back
#define ff first
#define ss second
#define ll long long
#define pi pair<int,int>
#define PQ priority_queue<double, vector<double>, greater<double> >q
#define _sort(v) sort(v.begin(),v.end())
#define MP map<ll int,ll int>mp
#define MEM(x) memset(x,0,sizeof(x))
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define vec() vector<ll int>v1,v2
#define VEC(n) ll int x; vector<ll int>v;for(int i=0;i<n;i++){cin>>x;v.pb(x);}
#define TEST() int test;cin>>test; while(test--)
#define FAST() ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
using namespace std;
//Upper_bound   auto x=upper_bound(v[a].begin(),v[a].end(),les);les=*x; if(x==v[a].end())break;
//ll int LCM(ll int a,ll int b) { ll int gcd=__gcd(a,b);ll int lcm=a*b/gcd;return lcm;}
//ll int bigmod(ll int b, ll int p, ll int m){if(p==0)return 1;if(p%2!=0) return b%m*fun(b,p-1,m)%m;if(p%2==0){ ll int res=fun(b,p/2,m);return (res%m*res%m)%m;}}
//ll mod_inverse(ll a, ll mod){return bigmod(a,mod-2,mod);}
//void seive() { prime[np++]=2;for(i=3; i<=sz; i+=2){if(mark[i]==0){ prime[np++]=i;for(j=i*i; j<=sz; j+=i) mark[j]=1; } }}
//string add(string s1,string s2) {string s;int j=s1.size()-1,c=0,m; for(int i=s2.size()-1; i>=0; i--) {if(j>=0)m=s2[i]-'0'+s1[j]-'0'+c;else m=s2[i]-'0'+c; if(m>9) { s+=m%10+'0';c=m/10; } else {  c=0;s+=m+'0'; }j--; } if(c!=0) {s+=c+'0'; }reverse(s.begin(),s.end());return s;}
//int pos;string mul(int n) {string s;for(int i=0; i<pos; i++) { s+="0"; }pos++;int c=0,m; for(int i=s1.size()-1; i>=0; i--) { m=(s1[i]-'0')*n+c;if(m>9) { s+=m%10+'0';c=m/10;} else { c=0; s+=m+'0';} }while(c!=0) { s+=c%10+'0';c=c/10;}    reverse(s.begin(),s.end());return s;}

vector<int>v[2*sz];
int vis[2*sz],cnt=0;
void bfs(int x)
{
    queue<int>q;
    q.push(x);


    while(!q.empty())
    {
        x=q.front();
        q.pop();
        for(int i=0; i<v[x].size(); i++)
        {
            vis[x]++;
            vis[v[x][i]]++;

            if(vis[v[x][i]]==1)
            {

                q.push(v[x][i]);
            }
        }
    }


}


int main()
{
    int n,m,a,b;
    cin>>n>>m;
    for(int i=0; i<m; i++)
    {
        cin>>a>>b;
        v[a].pb(b);
        v[b].pb(a);
    }
    for(int i=1; i<=n; i++)
    {
        if(vis[i]==0)
        {
            cnt++;
            bfs(i);
        }

    }
    cout<<cnt-1<<endl;



    return 0;
}



Measured memory_bytes: 11532
#include<stdio.h>

int main(){
  int M, D;
  scanf("%d %d",&M,&D);
  
  int ans;
  for(int day=0;day<D+1;day++){
    for(int month=0;month<M+1;month++){
      int d1, d2;
  		d2 = day / 10;
  		d1 = day % 10;
        if(d1 * d2 == month && d1>=2 && d2>=2) ans++;
    }
  }
  
  printf("%d\n",ans);
  
  return 0; 
}

Measured memory_bytes: 128
#include <iostream>
#include <cstdio>
using namespace std;
int a,b,c,d,roll;

struct Dice{
	int d1;
	int d2;
	int d3;
	int d4;
	int d5;
	int d6;
};

void N(struct Dice *std){
	a=(*std).d1;
	b=(*std).d2;
	c=(*std).d6;
	d=(*std).d5;
	(*std).d1=b;
	(*std).d2=c;
	(*std).d6=d;
	(*std).d5=a;
}
void S(struct Dice *std){
	a=(*std).d1;
	b=(*std).d2;
	c=(*std).d6;
	d=(*std).d5;
	(*std).d1=d;
	(*std).d2=a;
	(*std).d6=b;
	(*std).d5=c;
}
void W(struct Dice *std){
	a=(*std).d1;
	b=(*std).d4;
	c=(*std).d6;
	d=(*std).d3;
	(*std).d1=d;
	(*std).d4=a;
	(*std).d6=b;
	(*std).d3=c;
}
void E(struct Dice *std){
	a=(*std).d1;
	b=(*std).d4;
	c=(*std).d6;
	d=(*std).d3;
	(*std).d1=b;
	(*std).d4=c;
	(*std).d6=d;
	(*std).d3=a;
}

int main(){
	struct Dice da;
	char s;
	cin >> da.d1 >> da.d2 >> da.d3 >> da.d4 >> da.d5 >> da.d6;
	while(scanf("%c",&s)!=EOF){
		if(s=='N'){
			N(&da);
		}else if(s=='S'){
			S(&da);
		}else if(s=='W'){
			W(&da);
		}else if(s=='E'){
			E(&da);
		}
	}
	cout << da.d1 << endl;
	return 0;
}

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

int main() {

string s,t;
  cin>>s>>t;
  sort(s.begin(),s.end());
  sort(t.begin(),t.end(),greater<int>());

  for(int i=0; i<min(s.size(),t.size());i++){
    if(s.at(i)<t.at(i)){cout<<"Yes"<<endl;break;}
    else if(s.at(i)==t.at(i)){if(i!=min(s.size(),t.size())-1){continue;}}
    else if(s.at(i)>t.at(i)){cout<<"No"<<endl;break;}
    if(i==min(s.size(),t.size())-1){
      if(s.size()<t.size()){cout<<"Yes"<<endl;}
     else{ cout<<"No"<<endl;}}
}
}


Measured memory_bytes: 256
//satyaki3794
#include <bits/stdc++.h>
#define ff first
#define ss second
#define pb push_back
#define MOD (1000000007LL)
#define LEFT(n) (2*(n))
#define RIGHT(n) (2*(n)+1)
 
using namespace std;
typedef long long ll;
typedef pair<int, int> ii;
typedef pair<int, ii> iii;
 
ll pwr(ll base, ll p, ll mod=MOD){
ll ans = 1;while(p){if(p&1)ans=(ans*base)%mod;base=(base*base)%mod;p/=2;}return ans;
}
 
 
ll gcd(ll a, ll b){
    if(b == 0)  return a;
    return gcd(b, a%b);
}


const int N = 200005;
int n, root1, root2, ans[N];
vector<int> tree1[N], tree2[N];
set<int> adj[N];

void add_edge(int a, int b){
// cout<<"added edge "<<a<<" "<<b<<endl;
	adj[a].insert(b);
	adj[b].insert(a);
}

void hierholzer(int v){
	if(adj[v].empty())	return;
// cout<<"hierholzer at "<<v<<endl;
	int vv = (*adj[v].begin());
	adj[v].erase(vv);	adj[vv].erase(v);
	if(vv == v+n){
		ans[v] = 1;
// cout<<"set ans["<<v<<"] to "<<1<<endl;
	}
	else if(vv == v-n){
// cout<<"set ans["<<vv<<"] to "<<-1<<endl;
		ans[vv] = -1;
	}
	hierholzer(vv);
}


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

    cin>>n;
    for(int i=1;i<=n;i++){
    	int par;
    	cin>>par;
    	if(par == -1)	root1 = i;
    	else	tree1[par].pb(i);
    }
    for(int i=1;i<=n;i++){
    	int par;
    	cin>>par;
    	if(par == -1)	root2 = i;
    	else	tree2[par].pb(i);
    }

    for(int i=1;i<=n;i++)
    	if((int)tree1[i].size() % 2 != (int)tree2[i].size() % 2){
    		cout<<"IMPOSSIBLE";
    		return 0;
    	}

    add_edge(0, root1);
    add_edge(0, n+root2);
    for(int i=1;i<=n;i++){
    	for(auto it : tree1[i])
    		add_edge(i, it);
    	for(auto it : tree2[i])
    		add_edge(n+i, n+it);
    	if((int)tree1[i].size() % 2 == 0)
    		add_edge(i, n+i);
    }

    for(int i=0;i<=n+n;i++)
    	hierholzer(i);
    cout<<"POSSIBLE"<<endl;
    for(int i=1;i<=n;i++)
    	cout<<ans[i]<<" ";
    return 0;
}




 




Measured memory_bytes: 61440
N = int(input())
x = list(map(int, input().split()))
import numpy as np
x = np.array(x)
E = 10**9 #総和がこの値を超えることはない
for i in range(1, 101):
  e_tem = np.sum((x-i)**2)
  if e_tem < E:
    E = e_tem
print(E)

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

long long n, k;

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

    cin >> n >> k;
    n %= k;

    cout << min(n, k - n) << "\n";

    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define REP(i, n) for(int i=0; i<(int)(n); i++)
#define REP1(i,a,b) for(int i=a; i<=(int)(b); i++)
#define ALL(x) begin(x),end(x)
#define PB push_back
using namespace std;
typedef int64_t LL;
typedef vector<int> VI;
typedef pair<int,int> PII;

template<class T> inline bool chmax( T &a, const T &b ) { return b>a ? a=b,true : false; }
template<class T> inline bool chmin( T &a, const T &b ) { return b<a ? a=b,true : false; }
template<class T> using MaxHeap = priority_queue<T>;
template<class T> using MinHeap = priority_queue<T, vector<T>, greater<T>>;
template<class T, class F=less<T>> void sort_uniq( vector<T> &v, F f=F() ) {
    sort(begin(v),end(v),f);
    v.resize(unique(begin(v),end(v))-begin(v));
}

const int N=105;
int n, m;
int dist[N][N];
vector<string> grid;
int main() {
    ios::sync_with_stdio(0);
    cin.tie(0);
    cin >> n >> m;
    grid.resize(n);
    REP(i,n) cin >> grid[i];
    
    REP(i,n)REP(j,m) dist[i][j]=1e9;

    deque<pair<int,int>> que;
    que.PB(make_pair(0,0));
    dist[0][0]=(grid[0][0]=='#');

    while(que.size()) {
        int a=que.front().first, b=que.front().second;
        que.pop_front();
        if ( a+1<n ) {
            int change=( grid[a+1][b]=='#' && grid[a][b]!=grid[a+1][b] );
            int d=dist[a][b]+change;
            if ( d<dist[a+1][b] ) {
                dist[a+1][b]=d;
                if ( change ) que.push_back({a+1, b});
                else que.push_front({a+1, b});
            }
        }
        if ( b+1<m ) {
            int change=( grid[a][b+1]=='#' && grid[a][b]!=grid[a][b+1] );
            int d=dist[a][b]+change;
            if ( d<dist[a][b+1] ) {
                dist[a][b+1]=d;
                if ( change ) que.push_back({a, b+1});
                else que.push_front({a, b+1});
            }
        }
    }
    cout << dist[n-1][m-1] << '\n';
    return 0;
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define pb push_back
#define pii pair<int,int>
#define fi first
#define se second
int read(){
	int x=0,f=1;
	char ch=getchar();
	while (ch<'0'||ch>'9'){f=ch=='-'?-f:f;ch=getchar();}
	while (ch>='0'&&ch<='9'){x=x*10+ch-48;ch=getchar();}
	return x*f;
}
int i,j,k,n,m,x,y,t,a[101];
int main(){
	scanf("%d%d",&n,&m);
	for (i=1;i<=n;i++)scanf("%d",&a[i]);
	sort(a+1,a+1+n);
	int ans=0;for (i=1;i<=n;i++)if (m<a[i]){m=0;break;}else ans++,m-=a[i];
	if (m)ans--;
	printf("%d\n",ans);
	return 0;
}

Measured memory_bytes: 256
#include <cstdio>
#include <algorithm>
#define m (s + e) / 2
using namespace std;
typedef pair<int, int> ii;
const int INF = 1000000000;
struct segnode {
	int s, e;
	ii v;
	segnode *l, *r;
	segnode(int _s, int _e) {
		s = _s;
		e = _e;
		v = ii(INF, s);
		if (s != e) {
			l = new segnode(s, m);
			r = new segnode(m + 1, e);
		}
	}
	void update(int i, int nv) {
		if (s == e) {
			v = ii(nv, i);
			return;
		} else if (i > m) r -> update(i, nv);
		else l -> update(i, nv);
		v = min(l -> v, r -> v);
	}
	ii query(int a, int b) {
		if (s == a && e == b) return v;
		if (a > m) return r -> query(a, b);
		if (b <= m) return l -> query(a, b);
		return min(l -> query(a, m), r -> query(m + 1, b));
	}
} *root;
int main() {
	int N, M;
	scanf("%d %d", &N, &M);
	char squares[N + 1];
	for (int i = 0; i <= N; ++i) scanf(" %c", &squares[i]);
	ii dptable[N + 1];
	dptable[N] = ii(0, -1);
	root = new segnode(0, N);
	root -> update(N, 0);
	for (int i = N - 1; i >= 0; --i) {
		if (squares[i] == '1') {
			dptable[i] = ii(INF, -1);
			continue;
		}
		ii ans = root -> query(i + 1, min(N, i + M));
		dptable[i] = ii(ans.first + 1, ans.second);
		root -> update(i, ans.first + 1);
	}
	if (dptable[0].first >= INF) {
		printf("-1");
		return 0;
	}
	for (int i = 0; dptable[i].second != -1; i = dptable[i].second) printf("%d ", dptable[i].second - i);
	return 0;
}

Measured memory_bytes: 10624
import bisect
mod = 10**9+7
def main():
    n,k=map(int,input().split(' '))
    a = list(map(int,input().split(' ')))
    a_fall= 0
    a_rev = sorted(a,reverse=True)
    u_cnt = 0
    for i in range(n-1):
        a_sorted = sorted(a[i+1:])
        a_fall += bisect.bisect_left(a_sorted,a[i])
        a_fall %=mod
    a_sorted = sorted(a)
    for i in a:
        u_cnt += bisect.bisect_left(a_sorted,i)
    ans = a_fall*k+u_cnt*(k-1)*k//2
    ans %= mod
    print(ans)

if __name__ == '__main__':
    main()

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

using namespace std;

int n,x,y,i,ans;
vector<int> edge[100007];

int DFS(int pos, int par) {
    int tmp = 0;
    
    for (int i = 0; i < edge[pos].size(); i++) if (edge[pos][i] != par) {
        tmp ^= (1 + DFS(edge[pos][i],pos));
    }
    
    return tmp;
}

int main() {
    scanf("%d",&n);
    for (i=0 ; i<n-1 ; i++) {
        scanf("%d%d",&x,&y);
        edge[x].push_back(y);
        edge[y].push_back(x);
    }
    
    ans = DFS(1,-1);
    //printf("%d\n",ans);
    if (ans == 0) printf("Bob\n"); else printf("Alice\n");
}

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

#define repi(i,a,b) for(int i=(a);i<(b);i++)
#define rep(i,n) for(int i=0;i<(n);i++)

int main() {
	ios::sync_with_stdio(false);
	
	int s, a;
	while(cin>>s,s) {
		rep(i, 9) {
			cin>>a;
			s-=a;
		}
		cout << s << endl;
	}
	
	return 0;
}

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

using namespace std;

const int N = 3e5 + 3;

int n, k;
int t[N * 4];

void upd(int pos, int val, int v = 1, int tl = 1, int tr = N - 1) {
    if (tl == tr) {
        t[v] = max(val, t[v]);
    } else {
        int tm = (tl + tr) >> 1;
        if (pos <= tm)
            upd(pos, val, v << 1, tl, tm);
        else
            upd(pos, val, v << 1 | 1, tm + 1, tr);
        t[v] = max(t[v << 1], t[v << 1 | 1]);
    }
}

int get(int l, int r, int v = 1, int tl = 1, int tr = N - 1) {
    if (tl > r || l > tr) return 0;
    if (l <= tl && tr <= r) return t[v];
    int tm = (tl + tr) >> 1;
    return max(get(l, r, v << 1, tl, tm),
        get(l, r, v << 1 | 1, tm + 1, tr));
}

int main() {
    ios::sync_with_stdio(false);
    cin >> n >> k;
    for (int i = 1; i <= n; i++) {
        int x;
        cin >> x;
        x++;
        int cur = max(get(max(x - k, 1), x), get(x, min(x + k, N - 1)));
        upd(x, cur + 1);
    }
    cout << t[1] << endl;
}

Measured memory_bytes: 7752
#define _CRT_SECURE_NO_WARNINGS
#include <cstdio>
#include <iostream>
#include <algorithm>
#include <cstdlib>
#include <vector>
#include <string>
#include <utility>
#include <queue>

using namespace std;

typedef pair<string, int> process;

int main() {
	int n, q, sumTime = 0;
	queue<process> que;
	cin >> n >> q;
	for (int i = 0; i < n; i++) {
		process p;
		cin >> p.first;
		cin >> p.second;
		que.push(p);
	}

	while (!que.empty()) {
		process p = que.front();
		que.pop();
		if (p.second <= q) {
			sumTime += p.second;
			cout << p.first << " " << sumTime << "\n";
		}
		else {
			sumTime += q;
			p.second -= q;
			que.push(p);
		}
	}

	return 0;
}

Measured memory_bytes: 6344
#include <iostream>
#include <cassert>
#include <limits>
#include <cmath>
#include <algorithm>
#include <vector>
#include <unordered_map>
#include <unordered_set>
#include <string>
#include <array>
#include <map>
#include <set>
#include <deque>
#include <list>
#include <sstream>
#include <iomanip>
#include <numeric>
#include <climits>
#include <cstring>
#include <bitset>
#include <stack>
#include <queue>

#define MOD (1e9 + 7);
#define PI (3.14159265358979323846)

using ll = int64_t;
using ull = uint64_t;

using namespace std;

[[maybe_unused]] static auto __x = [](){ios_base::sync_with_stdio(0); cin.tie(0);};

int main() {
    int a, b, c, d;
    cin >> a >> b >> c >> d;

    for (;;) {
        c -= b;
        if (c <= 0) break;
        a -= d;
        if (a <= 0) break;
    }
    cout << (a > 0 ? "Yes" : "No");

    return 0;
}


Measured memory_bytes: 3636
#include<stdio.h>

int main(void)
{
    int Cards[4][14] = {{}};
    int i, j, n, Num;
    char Mark; 

    scanf("%d", &n);

    for(i = 0; i < 2 * n; i++)
    {
        scanf("%c ", &Mark);
        scanf("%d", &Num);
        
        if(Mark == 'S')
        {
            Cards[0][Num - 1] = 1;
        }

        else if(Mark == 'H')
        {
            Cards[1][Num - 1] = 1;
        }

        else if(Mark == 'C')
        {
            Cards[2][Num - 1] = 1;
        }

        else if(Mark == 'D')
        {
            Cards[3][Num - 1] = 1;
        }
    }

    for(j = 1; j < 14; j++)
    {
        if(Cards[0][j - 1] != 1)
        {
            printf("S %d\n", j);
        }
    }

    for(j = 1; j < 14; j++)
    {
        if(Cards[1][j - 1] != 1)
        {
            printf("H %d\n", j);
        }
    }

    for(j = 1; j < 14; j++)
    {
        if(Cards[2][j - 1] != 1)
        {
            printf("C %d\n", j);
        }
    }

    for(j = 1; j < 14; j++)
    {
        if(Cards[3][j - 1] != 1)
        {
            printf("D %d\n", j);
        }
    }
    
    return 0;
}


Measured memory_bytes: 2044
#include <iostream>
#include <stdlib.h>
using namespace std;

int main() {
  int n, m;
  cin >> n;
  cin >> m;
  long a = 1;
  if( abs(n-m) > 1) {
    cout << 0 << endl;
    return 0;
  }
  int v = min(n, m);
  for(long b = 1; b <= n; b++) {
    a *= b;
    a %= 1000000007;
  }
  for(long b = 1; b <= m; b++) {
    a *= b;
    a %= 1000000007;
  }
  if(abs(n-m) < 1) {
   a *= 2; 
  }
  cout << a%1000000007 << endl;
  return 0;
}


Measured memory_bytes: 256
#include <time.h>

#include <stdlib.h>
#include <cstdint>
#include <cassert>
#include <algorithm>
#include <functional>
#include <iostream>
#include <limits>
#include <cstdint>
#include <cassert>
#include <algorithm>
#include <functional>
#include <iostream>
#include <limits>
#include <vector>
#include <map>
#include <set>
#include <iomanip>
#include <numeric>
#include <cmath>
#include <bitset>
#include <iterator>
#include <deque>
#include <string>
#include <queue>
#include <omp.h>
#include <fstream>   // ifstream, ofstream
typedef int64_t ll;
using namespace std;
const ll INF=1e10;

int main(){
	ll a,p;
	cin>>a>>p;
	cout<<(3*a+p)/2<<endl;
}


Measured memory_bytes: 256
A, B = map(int, input().split())


def prime_factor(n):
    d = set()
    for i in range(2, n + 1):
        if i * i > n:
            break
        while n % i == 0:
            d.add(i)
            n //= i
            
    if n != 1:
        d.add(n)
    return d

a = prime_factor(A)
b = prime_factor(B)
print(len(set(a) & set(b)) + 1)


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

#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REP(i,j) FOR(i,0,j)
#define mp std::make_pair

const int INF = 1 << 24;
const int dx[8] = {0, 0, 1, -1, 1, 1, -1, -1}, dy[8] = {1, -1, 0, 0, 1, -1, 1, -1};

typedef unsigned long long ull;
typedef std::pair<int,int> P;

int main(){
    int N, K;
    while(std::cin >> N >> K, N){
        int S[100];
        REP(i, K){
            std::cin >> S[i];
        }

        bool canHave = true;
        REP(i, N){
            REP(j, K){
                int b;
                std::cin >> b;
                S[j] -= b;
                if(S[j] < 0){canHave = false;}
            }
        }

        if(canHave){puts("Yes");}
        else{puts("No");}
    }
}

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

using namespace std;

typedef long long ll;
typedef vector<int> vi; 
typedef vector<vi> vvi;
typedef vector<string> vs;
typedef pair<int, int> pii;

#define sz(a) int((a).size())
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define all(c) (c).begin(),(c).end()
#define rall(c) (c).rbegin(),(c).rend()
#define ini(a, i) memset(a, i, sizeof(a))
#define contains(c, i) ((c).find(i) != (c).end())
#define present(i, c) (find(all(c), i) != (c).end())

#define rep(i, n) for(int i = 0; i < n; i++)
#define repa(i, b, e) for(int i = (b)-((b)>(e)); i != (e)-((b)>(e)); i += 1-2*((b)>(e)))

#define dbg(x) cerr << #x << " = " << x << endl;
#define dbgall(x) cerr << #x << " = "; for(auto i_ : x) cerr << i_ << " "; cerr << endl;
#define debug(args...) { string s_(#args); replace(all(s_), ',', ' '); stringstream ss_(s_); istream_iterator<string> it_(ss_); cerr_(it_, args); }
void cerr_(istream_iterator<string> it) { (void) it; }
template<class T, class... Args> void cerr_(istream_iterator<string> it, T a, Args... args) { cerr << *it << " = " << a << endl; cerr_(++it, args...); }

template<class T, class S>  ostream& operator<<(ostream& os, const pair<T, S>& p) { os << "(" << p.first << ", " << p.second << ")"; return os; }
template<class T> ostream& operator<<(ostream &os, const vector<T> &v) { os << '{'; string sep; for (const auto &x : v) os << sep << x, sep = ", "; return os << '}'; }
template<class T> ostream& operator<<(ostream &os, const set<T> &s) { os << '{'; string sep; for (const auto &x : s) os << sep << x, sep = ", "; return os << '}'; }
template<class T, class S> ostream& operator<<(ostream &os, const map<T, S> &m) { os << '{'; string sep; for (const auto &x : m) os << sep << x, sep = ", "; return os << '}'; }
template<class T, size_t size> ostream& operator<<(ostream &os, const array<T, size> &arr) { os << '{'; string sep; for (const auto &x : arr) os << sep << x, sep = ", "; return os << '}'; }

//=========================

const int MOD = (int) 1e9 + 7;

int sum(int a, int b) {
    return (((ll) a + b) * ((ll) b - a + 1LL) / 2LL) % MOD;
}

int get_cnt(int n, int k) {
    int mn = sum(0, k - 1);
    int mx = sum(n - k + 1, n);
    int ans = mx - mn + 1;
    if(ans < 0) ans += MOD;
    return ans;
}

void run_test() {
	int n, k; cin >> n >> k;
    int ans = 0;
    for(int x = k; x <= n+1; x++) {
        ans = (ans + get_cnt(n, x)) % MOD;
    }
    cout << ans << endl;
}

//=========================

int main() {
	ios::sync_with_stdio(false); cin.tie(nullptr);
	//int t_ = 1, t__; cin >> t__; while(t_ <= t__) { cout << "Case #" << t_++ << ": "; run_test(); }
	// int t_; cin >> t_; while(t_--) run_test();
	run_test();
	return 0;	
}


Measured memory_bytes: 3572
#include <bits/stdc++.h>
#define len(x) (int) (x.size())
using namespace std;
typedef long long ll;

int main(){
    ll n, k;
    cin >> n >> k;

    ll rest = n % k;
    ll subans = abs(rest-k);

    if(subans < rest) {
        cout << subans << '\n';
    }
    else {
        cout << rest << '\n';
    }
}

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

int main()
{
	ll n,k;
	cin >> n >> k;
	int edge[n+1][n+1];
	for (int q = 1; q <= n; q++)
	{
		for (int w = 1; w <= n; w++)
		{
			cin >> edge[q][w];
		}
	}
	ll binpaths[n+1][n+1][62];
	for (int q = 1; q <= n; q++)
	{
		for (int w = 1; w <= n; w++)
		{
			if (edge[q][w] == 1)
			{
				binpaths[q][w][0] = 1;
			}
			else
			{
				binpaths[q][w][0] = 0;
			}
		}
	}
	for (int r = 1; r < 62; r++)
	{
		for (int q = 1; q <= n; q++)
		{
			for (int w = 1; w <= n; w++)
			{
				binpaths[q][w][r] = 0;
				for (int e = 1; e <= n; e++)
				{
					binpaths[q][w][r] = (binpaths[q][w][r] + ((binpaths[q][e][r-1] * binpaths[e][w][r-1]) % md)) % md;
				}
			}
		}
	}
	ll dp[n+1][n+1][62];
	int cur = 0;
	while (true)
	{
		if (((1LL << cur) & k) > 0)
		{
			break;
		}
		cur++;
	}
	for (int q = 1; q <= n; q++)
	{
		for (int w = 1; w <= n; w++)
		{
			dp[q][w][cur] = binpaths[q][w][cur];
		}
	}
	cur++;
	while ((1LL << cur) <= k)
	{
		if (((1LL << cur) & k) > 0)
		{
			for (int q = 1; q <= n; q++)
			{
				for (int w = 1; w <= n; w++)
				{
					dp[q][w][cur] = 0;
					for (int e = 1; e <= n; e++)
					{
						dp[q][w][cur] = (dp[q][w][cur] + ((dp[q][e][cur-1] * binpaths[e][w][cur]) % md)) % md;
					}
				}
			}
		}
		else
		{
			for (int q = 1; q <= n; q++)
			{
				for (int w = 1; w <= n; w++)
				{
					dp[q][w][cur] = dp[q][w][cur-1];
				}
			}
		}
		cur++;
	}
	ll tot = 0;
	for (int q = 1; q <= n; q++)
	{
		for (int w = 1; w <= n; w++)
		{
			tot = (tot + dp[q][w][cur-1]) % md;
		}
	}
	cout << tot << "\n";
	return 0;
}


Measured memory_bytes: 2688
import java.io.*;

class Main{
	public static void main(String args[]) throws IOException{
		BufferedReader buf = new BufferedReader(new InputStreamReader(System.in));
		int n = Integer.parseInt(buf.readLine());
		String[] str;
		int tarou=0;
		int hanako=0;
		for(int i=0; i<n; i++){
			str = buf.readLine().split(" ");
			if(str[0].compareTo(str[1]) > 0)
				tarou += 3;
			else if(str[0].compareTo(str[1]) < 0)
				hanako += 3;
			else {
				tarou++;
				hanako++;
			}
		}
		System.out.println(tarou + " " + hanako);
	}
}

Measured memory_bytes: 25108
import fractions
A, B, C, D = map(int, input().split())
CD = C * D // fractions.gcd(C, D)
A = A - 1

c_BC = B // C *(C - 1) + B % C
c_BD = B // D * (D - 1) + B % D
c_BCD = B // CD * (CD - 1) + B % CD
c_AC = A // C * (C - 1) + A % C
c_AD = A // D * (D - 1)+ A % D
c_ACD = A // CD * (CD - 1) + A % CD

ans = c_BC + c_BD - c_BCD - (c_AC + c_AD - c_ACD)
print(int(ans))

Measured memory_bytes: 5344
#include <algorithm>
#include <iostream>
#include <vector>
#include <cstdio>
#include <map>
using namespace std;
typedef long long LL;
const int N=2e5+5;
LL n, k;
LL a[N], c[N*4];
map<LL,int> M;
vector<LL> V;
void add(int x, int y){
    for(;x<=n;x+=x&(-x))c[x]+=y;
}
LL ask(int y){
	if(y<=0) return 0; 
    LL ans=0;
    for(int x=y;x;x-=x&(-x)) ans+=c[x];
    return ans;
}

int main()
{
    int x;
    scanf("%d%d", &n,&k);
    for(int i=1;i<=n;i++) scanf("%d",&x), a[i]=x;
    LL sum = 0;
    for(int i=1; i<= n;i++) {
        sum+=a[i];
        sum-=k;
        V.push_back(sum);
    }
    sort(V.begin(),V.end());
    for(int i=0;i<V.size();i++) M[V[i]]=i+1;
    sum=0;
    LL ans=0;
    for(int i=1;i<=n;i++){
        sum+=a[i];
        sum-=k;
        // cout << M[sum] << endl;
        ans+=ask(M[sum]);
        if(sum>=0) ans++;
        add(M[sum],1);
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 18160
import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        Integer[] nums = new Integer[n];
        for (int i = 0; i < n; i++) {
            nums[i] = sc.nextInt();
        }
        Arrays.sort(nums, Collections.reverseOrder());
        int aliceSum = 0;
        int bobSum = 0;
        for (int i = 0; i < n; i++) {
            if (i % 2 == 0) {
                aliceSum += nums[i];
            } else {
                bobSum += nums[i];
            }
        }
        System.out.println(aliceSum - bobSum);
    }
}

Measured memory_bytes: 21332
// --------------
// Tejas Pandey  |
// 01 - 12 - 19  |
// SUMOMITO PC'19|
// --------------

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

#define mod 1000000007
#define vi vector<int>
typedef long long int ll;

int main (void)
{
	//freopen("in.txt","r",stdin);
	//freopen("out.txt","w",stdout);
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	int t = 1;
	//cin >> t;
	int a[100007];
	memset(a,0,sizeof(a));
	a[0] = 1;
	int cur = 100;
	for(int j = 0;j < 6;j++){
	for(int i = 100;i < 100007;i++){
		if(i - cur > -1)
			a[i] |= a[i - cur];
	}
	cur++;
	}
	while(t--)
	{
		//cout << "Case #" << c-t << ": ";
		int n;
		cin >> n;
		cout << a[n];
	}
	return 0;
}

Measured memory_bytes: 640
#include<stdio.h>
#include<math.h> //math.h?????????????????????????????????????????????????????¨??????-lm???????????§???\\
??????????????????????????????

int main(void){
  double x1,y1,x2,y2;
  scanf("%lf %lf %lf %lf",&x1,&y1,&x2,&y2);
  double l;
  l = sqrt(pow(x2-x1,2) + pow(y2-y1,2));
  printf("%lf\n",l);
  return 0;
}

Measured memory_bytes: 652
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
#define setbits(x) __builtin_popcount(x)
#define setbitsll(x) __builtin_popcountll(x)
#define endl '\n'
#define all(x) (x).begin(), (x).end()
#define pb push_back
#define se second
#define fi first
#define pai acos(-1)
#define fn(i,x) for(i=0;i<x;i++)
#define fs(i,s,x) for(i=s;i<x;i++)
#define fr(i,x,s) for(i=x;i>=s;i--)
#define fit(itr,s) for(itr=s.begin();itr!=s.end();itr++)
#define W while
#define pp pair<ll,ll>
#define ppi pair<int,int>
#define vl vector<ll>
#define vll vector<pp >
#define vi vector<int>
#define vii vector<ppi>
#define max3(a,b,c) max(a,max(b,c))
#define min3(a,b,c) min(a,min(b,c))
#define debug(x) cerr<<#x<<" :: "<<x<<endl;
#define debug2(x,y) cerr<<#x<<" :: "<<x<<"\t"<<#y<<" :: "<<y<<endl;
#define debug3(x,y,z) cerr<<#x<<" :: "<<x<<"\t"<<#y<<" :: "<<y<<"\t"<<#z<<" :: "<<z<<endl;
#define debug4(x,y,z,w) cerr<<#x<<" :: "<<x<<"\t"<<#y<<" :: "<<y<<"\t"<<#z<<" :: "<<z<<"\t"<<#w<<" :: "<<w<<endl;
#define boost  ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL)
const ll MAX=1e16;
const ll MM=1e18;
const ll mod=998244353;
int dx[]={-1,0,1,0};
int dy[]={0,1,0,-1};

ll expo(ll x,ll n,ll M=mod)
{
    ll ans=1;
    while(n>0)
    {
        if(n&1){ans=(ans*x)%M;}
                x=(x*x)%M;
                n>>=1;
    }
    return ans;
}
const ll MaxSize = 3e5;
ll facts[MaxSize], invFacts[MaxSize];

void preproc() {
  facts[0] = 1;
  for (int i = 1; i < MaxSize; i++) {
    facts[i] = ((ll)facts[i - 1] * i) % mod;
  }
  invFacts[MaxSize - 1] = expo(facts[MaxSize - 1], mod - 2,mod);

  for (int i = MaxSize - 2; i >= 0; i--) {
    invFacts[i] = ((ll)invFacts[i + 1] * (i + 1)) % mod;
  }
}

ll combination(ll n, ll k) {
  if(n<k) return 0;
  ll res = facts[n];
  res = ((ll)res * invFacts[k]) % mod;
  return ((ll)res * invFacts[n - k]) % mod;
}

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


void solve()
{
    
    int n, k;
    cin >> n >>  k;
    
     set<int> s;
    while(k--) {
        int d;
        cin >> d;
        for(int m = 0; m < d; m++) {
            int snaks;
            cin >> snaks;
             s.insert(snaks);
        }
        
        
    }
    
    cout << n - s.size()  << endl;
}
int main()
{
  boost;
  int m;
  //cin >> m;
  int t=1;
  //cin>>t;
  while(t--)
  {
      solve();
  }
}



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

static const int MAX = 200000;

int main() {
  ll a,b,k;
  cin >> a >> b >> k;
  if (a >= k) {
    a -= k;
  } else {
    k -= a;
    a = 0;
    if (b >= k) {
      b -= k;
    } else {
      k -= b;
      b = 0;
    }
  }
  cout << a << " " << b << endl;
}


Measured memory_bytes: 3616
#include<bits/stdc++.h>
//#pragma GCC optimize("Ofast","no-stack-protector","unroll-loops")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,sse4.2,popcnt,abm,mmx,avx")
//#include<bits/extc++.h>
//using namespace __gnu_pbds;
using namespace std;
#define int long long
#define F(i,L,R) for(int i=L;i<R;++i)
#define FE(i,L,R) for(int i=L;i<=R;++i)
#define getI(a) scanf("%lld",&a)
#define getII(a,b) scanf("%lld%lld",&a,&b)
#define getIII(a,b,c) scanf("%lld%lld%lld",&a,&b,&c)
#define VgetI(n) int (n); scanf("%lld",&(n))
#define VgetII(n,m) int (n),(m); scanf("%lld%lld",&(n),&(m))
#define VgetIII(n,m,k) int (n),(m),(k); scanf("%lld%lld%lld",&(n),&(m),&(k))
#define debug(x) cout<<(#x)<<"="<<x<<"\n";
#define qq cout<<"QQ\n";
#define pb push_back
#define pii pair<int,int>
#define mp make_pair
#define f first
#define s second
#define INF 2000000000
char s[200005],t[200005];
main(){
	while(~scanf("%s%s",s,t)){
		int cnt=0,l=strlen(s);
		F(i,0,l) cnt+=s[i]!=t[i];
		printf("%lld\n",cnt);
	}
}

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

#define COUT(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << endl
template<class T1, class T2> ostream& operator << (ostream &s, pair<T1,T2> P)
{ return s << '<' << P.first << ", " << P.second << '>'; }
template<class T> ostream& operator << (ostream &s, vector<T> P)
{ for (int i = 0; i < P.size(); ++i) { if (i > 0) { s << " "; } s << P[i]; } return s; }
template<class T> ostream& operator << (ostream &s, vector<vector<T> > P)
{ for (int i = 0; i < P.size(); ++i) { s << endl << P[i]; } return s << endl; }
template<class T> ostream& operator << (ostream &s, set<T> P)
{ for(auto it : P) { s << "<" << it << "> "; } return s << endl; }
template<class T1, class T2> ostream& operator << (ostream &s, map<T1,T2> P)
{ for(auto it : P) { s << "<" << it.first << "->" << it.second << "> "; } return s << endl; }

#define rep(i, n) for (int i = 0; i < (n); ++i)
#define rrep(i, n) for (int i = 1; i <= (n); ++i)
#define drep(i, n) for (int i = (n)-1; i >= 0; --i)
#define ddrep(i, n) for (int i = n; i > 0; --i)
#define srep(i, s, t) for (int i = s; i < t; ++i)
#define ssrep(i, s, t) for (int i = s; i <= t; ++i)

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

using ll = long long;
using pi = pair<int, int>;
using vi = vector<int>;
using vvi = vector<vi>;
using vl = vector<ll>;
using vvl = vector<vl>;
using ld = long double;
using str = string;

#define rng(a) a.begin(), a.end()
#define rrng(a) a.rbegin(), a.rend()
#define pb push_back
#define eb emplace_back
#define fi first
#define se second

long int M = 1e+9+7;
int inf = 1e+9;

int n;
int solve(){
    int alice=0,bob=0;

    vi a(n);
    rep(i,n){
        cin >> a[i];
    }
    sort(rrng(a));
    bool turn = true;
    rep(i,n){
        if(turn) alice+=a[i];
        else bob+=a[i];
        turn ^= 1;
    }

    return alice-bob;
}

int main(void){
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << std::setprecision(10);

    while(cin >> n){
        int ans = 0;
        cout << solve() << endl;
        //cout << ans << endl;
    }
    return 0;
}

Measured memory_bytes: 256
N = input()
H = list(map(int, input().split()))

steps = 0
ans = 0

Hlast = 0

for h in H:
    if h <= Hlast:
        steps += 1
    else:
        ans = max(steps, ans)
        steps = 0

    Hlast = h

ans = max(steps, ans)

print(ans)


Measured memory_bytes: 14252
object Main extends App{
    val Array(n, m) = io.StdIn.readLine().split(' ').map(_.toInt)
    val all = Iterator.continually(io.StdIn.readLine().split(' ')).take(m).foldLeft(Map.empty[String, (Int, Int)]) {
        case (acc, Array(p, s)) if s == "AC" && acc.getOrElse(p, (0, 0))._1 != -1 =>
            acc + (p -> (acc.getOrElse(p, (0, 0)) match {
                case (acu, _) => (-1, acu)
            }))
        case (acc, Array(p, s)) if acc.getOrElse(p, (0, 0))._1 != -1 =>
            acc + (p -> (acc.getOrElse(p, (0, 0)) match {
                case (acu, ans) => (acu + 1, ans)
            }))
        case (acc, _) => acc
    }
    
    val answer = all.filter {
        case (_, (acc, _)) => acc == -1
    }
    println(s"${answer.size} ${if (answer.isEmpty) 0 else answer.map(_._2._2).sum}")
    
}


Measured memory_bytes: 88968
#include<iostream>
using namespace std;
int main(){
  int h,w,four,two,one,i,al[26] = {};char a;cin >> h >> w;bool ok = true;
  while(cin >> a){
    al[int(a)-int('a')] += 1;
  }
  one = (h%2==1)*(w%2==1);
  four = (h/2)*(w/2)*4;
  two = h*w-one-four;
  for(i=0;i<26;i++){
    while(al[i] != 0){
      if(al[i] >= 4 && four > 0){
        four -= 4;
        al[i] -= 4;
      } else if(al[i] >= 2 and two > 0){
        two -= 2;
        al[i] -= 2;
      } else if(al[i] == 1 and one > 0){
        one -= 1;
        al[i] -= 1;
      } else {
        ok = false;break;
      }
    }
  }
  cout << ((ok) ? "Yes":"No") << endl;
}

Measured memory_bytes: 256