akhauriyash/Code-Regression huggingface dataset:
#define _GLIBCXX_DEBUG
#include"bits/stdc++.h"

using namespace std;

//loops
#define REP(i,n) for(int i=0;i<(ll)(n);i++)
#define REPD(i,n) for(int i=(ll)(n)-1;i>=0;i--)
#define OneToN(i,n) for(int i=1;i<(ll)(n+1);i++)
#define ZeroToN(i,n) for(int i=0;i<(ll)(n+1);i++)
#define FOR(i,a,b) for(int i=(a);i<=(b);i++)
#define FORD(i,a,b) for(int i=(a);i>=(b);i--)

//arrays
#define ALL(x) (x).begin(),(x).end() //sortなどの引数を省略したい
#define SIZE(x) ((ll)(x).size()) //sizeをsize_tからllに直しておく
#define add push_back

#define remove_unique(v) v.erase(unique(ALL(v)), v.end())

//pair
#define fir first
#define sec second

//types
#define ll long long
#define vec vector
//UNCOMMENT WHEN NEEDED
//#define int ll

//input
template <class T> T get(){ T s; cin >> s; return(s);}
#define gi get<int>()
#define gs get<string>()

template <class T> vector<T> getv(int n) { vec<T> v(n); REP(i, n) cin >> v[i]; return v; }
#define gim(n) getv<int>(n)
#define gsm(n) getv<string>(n)

//output
void print(int a){ cout << a << endl; }
void print(string a){ cout << a << endl; }
void print(double a, int dig){ cout << std::setprecision(dig) << a << endl; }

template <class T = int>
void print(vec<T> v){ for (T item: v) { cout << item << " "; } cout << endl; }

void YesNo1(bool i = true){ return print(i?"Yes":"No"); }
void YESNO2(bool i = true){ return print(i?"YES":"NO"); }

//debug output
#define var_name(var) #var
template <class T> void debug(T &var, int nest = 0, string before = "") { cout << string("          ", nest) << before; print(var); }

//name replacement
#define y0 y0__
#define y1 y1__
#define j0 j0__
#define j1 j1__
#define next next__
#define prev prev__

//bool lambdas
#define lamb(exp) [](auto i){return exp;}
#define isEven [](int i){return i % 2 == 0;}
#define isOdd [](int i){return i % 2 != 0;}

//constants
const ll INF = 1e18;
const int MOD = 10000007;

void Main() {
    //code here
    int n = gi;
    vec<vec<int>> map = {{0,0,0}};
    REP(i,n) {
        vec<int> input = gim(3);

        int time_d = input.front() - map.back().front();
        int x_d = abs(input.at(1) - map.back().at(1));
        int y_d = abs(input.at(2) - map.back().at(2));
        //print(x_d);
        //print(y_d);

        if (!(x_d+y_d <= time_d && (x_d+y_d-time_d)%2 == 0)) {
            print("No");
            return;
        }
        map.add(input);
    }
    print("Yes");

}

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

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

int main() {
  long long int n, x, min1 = 1000000001, min2 = 1000000001, temp, min3;
  vector<long long int> nums;
  bool skip = false;
  cin >> n >> x;
  
  for (long long int i=0; i<n; i++) {
    cin >> temp;
    nums.push_back(temp);
  }
  
  if (n==1) {
    cout << abs(x-nums[0]);
    return 0;
  }
  
  sort(nums.begin(), nums.end());
  
  temp = -999999999;
  
  for (auto i : nums) {
    if (abs(x-i)<min1) min1 = abs(x-i);
    if (abs(i-temp)<min2) min2 = abs(i-temp);
    temp = i;
  }
  
  min3 = min(min1, min2);
  for (long long int i=min3; i>1; i--) {
    skip = false;
    for (auto j : nums) {
      if (abs(x-j)%i!=0) {
        skip = true;
        break;
      }
    }
    if (skip) continue;
    cout << i;
    return 0;
  }
  cout << 1;
  return 0;
}


Measured memory_bytes: 1400
using System;
using System.Collections.Generic;

namespace AtCoder
{
	public class ProblemA
	{
		private const int mask = (1 << 10) - 1;

		public static void Main(string[] args)
		{
			string[] line = Console.ReadLine().Split(' ');
			int h = int.Parse(line[0]);
			int w = int.Parse(line[1]);

			int blacks = 0;
			int[,] panel = new int[h, w];

			for (int i = 0; i < h; i++)
			{
				string s = Console.ReadLine();
				for (int j = 0; j < w; j++)
				{
					if (s[j] == '.')
						panel[i, j] = 999;
					else
					{
						panel[i, j] = -1;
						blacks++;
					}
				}
			}

			panel[0, 0] = 0;

			Queue<int> queue = new Queue<int>();
			queue.Enqueue(0);

			int[] arrayX = new int[] { -1, 0, 1, 0 };
			int[] arrayY = new int[] { 0, -1, 0, 1 };

			while (queue.Count > 0)
			{
				int tmp = queue.Dequeue();
				int curX = (tmp >> 10) & mask;
				int curY = tmp & mask;
				int cur = panel[curY, curX];

				for (int i = 0; i < 4; i++)
				{
					int nextX = curX + arrayX[i];
					int nextY = curY + arrayY[i];
					if (nextX >= 0 && nextY >= 0 && nextX < w && nextY < h && panel[nextY, nextX] == 999)
					{
						panel[nextY, nextX] = cur + 1;
						queue.Enqueue(nextY + (nextX << 10));
					}
				}
			}

			int score = panel[h - 1, w - 1] == 999 ? -1 : w * h - blacks - (panel[h - 1, w - 1] + 1);
			Console.WriteLine(score);
		}
	}
}

Measured memory_bytes: 27896
import sys, bisect, math, itertools, string, queue, copy
# import numpy as np
# import scipy
from collections import Counter,defaultdict,deque
from itertools import permutations, combinations
from heapq import heappop, heappush
from fractions import gcd
# input = sys.stdin.readline
sys.setrecursionlimit(10**8)
mod = 10**9+7
def inp(): return int(input())
def inpm(): return map(int,input().split())
def inpl(): return list(map(int, input().split()))
def inpls(): return list(input().split())
def inplm(n): return list(int(input()) for _ in range(n))
def inplL(n): return [list(input()) for _ in range(n)]
def inplT(n): return [tuple(input()) for _ in range(n)]
def inpll(n): return [list(map(int, input().split())) for _ in range(n)]
def inplls(n): return sorted([list(map(int, input().split())) for _ in range(n)])

def main():
    n = inp()
    print((n/3)**3)
    
if __name__ == "__main__":
    main()

Measured memory_bytes: 63980
#include <iostream>
#include <stdio.h>
#include <algorithm>
#include <math.h>
#include <list>
#include <string>
#include <map>
#include <vector>
#include <stack>
#include <queue>
#include <iomanip> // setprecisionを使用するのに必要 cout << fixed << setprecision(15) << p でpを小数点以下15桁表示
using namespace std;
#define REPD(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, n) REPD(i, 0, n)
#define DIV0 1000000007
typedef long long ll;
#define fin(ans) cout << (ans) << '\n'
/*

*/
int main()
{
    ll a,b,c,d;
    cin >> a >> b >> c >> d;
    /*
    if(a >= c){
        ll temp;
        temp = a;
        a = c;
        c = temp;
        temp = b;
        b = d;
        d = temp;
    }
    ll ans;
    //並び順がa,b,c,d or a,c,b,d or a,c,d,bになった
    if(a*b < 0 && c*d < 0){
        ans = max(a*c,b*d);
    }else if(a*b > 0 && c*d >0){
        //どちらも0を跨いでいない
        if(a*c <0){
            ans = min(abs(a),abs(b))*min(abs(c),abs(d))*-1;
        }else{
            ans = max(abs(a),abs(b))*max(abs(c),abs(d));
        }
    }else{
        if(a*b >= 0 && a > 0){
            ans = d*b;
        }else if(a*b >= 0 && a <= 0){
            ans = c * a;
        }else if(a*b < 0 && c > 0){
            ans = d*b;
        }else{
            ans = c*a;
        }
    }*/
    //短い方
    ll ans = max(max(a*c,a*d),max(b*c,b*d));
    fin(ans);
    return 0;
}

Measured memory_bytes: 3196
#include<bits/stdc++.h>
//#include <boost/multiprecision/cpp_int.hpp>
#define MOD 1000000007
#define MAX 1000005
#define loop(i,a,b) for(long long int i=a;i<b;i++)
#define pb(a) push_back(a)
#define mp(a,b) make_pair(a,b)
#define debug(x) cout<<#x<<" :: "<<x<<endl;
#define debug2(x,y) cout<<#x<<" :: "<<x<<"\t"<<#y<<" :: "<<y<<endl;
#define debug3(x,y,z) cout<<#x<<" :: "<<x<<"\t"<<#y<<" :: "<<y<<"\t"<<#z<<" :: "<<z<<endl;
typedef long long int ll;

using namespace std;
//using namespace boost::multiprecision;

int prime[MAX];

ll modular_expo(ll x,ll n)
{
	ll ans = 1;
	while(n)
	{
		if(n&1)
		ans = (ans * x)%MOD;
		x = (x*x)%MOD;
		n = n>>1;
	}
	return ans%MOD;
}

void sieve()
{
	prime[1] = 1;
	for(int i=2;i*i<MAX;i++)
	if(prime[i]==0)
	for(int j=i*i;j<MAX;j+=i)
	prime[j] = 1;
}


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

ll n;
cin>>n;

string str;
cin>>str;

vector<ll> r,g,b;

loop(i,0,(ll)str.size())
{
	if(str[i]=='R')
	r.pb(i);
	else if(str[i]=='G')
	g.pb(i);
	else
	b.pb(i);
} 

ll ans=0;

loop(i,0,(ll)str.size())
{
	if(str[i]=='R')
	{
		auto it = lower_bound(g.begin(),g.end(),i);
		while(it!=g.end())
		{
			//cout<<"1\n";
			ll pos = *it;
			ll dif = pos-i;
			ll temp = b.size() - (lower_bound(b.begin(),b.end(),pos) - b.begin());
			if((pos+dif)<n && str[pos+dif]=='B')
			ans--;
			ans += temp;
			it++;
		}
		
		it = lower_bound(b.begin(),b.end(),i);
		while(it!=b.end())
		{
			//cout<<"1\n";
			ll pos = *it;
			ll dif = pos-i;
			ll temp = g.size() - (lower_bound(g.begin(),g.end(),pos) - g.begin());
			if((pos+dif)<n && str[pos+dif]=='G')
			ans--;
			ans += temp;
			it++;
		}
	}
	else if(str[i]=='G')
	{
		auto it = lower_bound(r.begin(),r.end(),i);
		while(it!=r.end())
		{
			//cout<<"3\n";
			ll pos = *it;
			ll dif = pos-i;
			ll temp = b.size() - (lower_bound(b.begin(),b.end(),pos) - b.begin());
			if((pos+dif)<n && str[pos+dif]=='B')
			ans--;
			ans += temp;
			it++;
		}
		
		it = lower_bound(b.begin(),b.end(),i);
		while(it!=b.end())
		{
			//cout<<"3\n";
			ll pos = *it;
			ll dif = pos-i;
			ll temp = r.size() - (lower_bound(r.begin(),r.end(),pos) - r.begin());
			if((pos+dif)<n && str[pos+dif]=='R')
			ans--;
			ans += temp;
			it++;
		}
	}
	else
	{
		auto it = lower_bound(g.begin(),g.end(),i);
		while(it!=g.end())
		{
			//cout<<"5\n";
			ll pos = *it;
			ll dif = pos-i;
			ll temp = r.size() - (lower_bound(r.begin(),r.end(),pos) - r.begin());
			if((pos+dif)<n && str[pos+dif]=='R')
			ans--;
			ans += temp;
			it++;
		}
		
		it = lower_bound(r.begin(),r.end(),i);
		while(it!=r.end())
		{
			//cout<<"5\n";
			ll pos = *it;
			ll dif = pos-i;
			ll temp = g.size() - (lower_bound(g.begin(),g.end(),pos) - g.begin());
			if((pos+dif)<n && str[pos+dif]=='G')
			ans--;
			ans += temp;
			it++;
		}
	}
}

cout<<ans<<"\n";

return 0;
}


Measured memory_bytes: 3660
n = int(input())
a = list(map(int, input().split()))
ans = 0
x = 0
y = abs(a[0])

for i in a:
  if i < 0:
    x += 1
    y = min(y, -i)
    ans += -i
  else:
    y = min(y, i)
    ans += i

if x % 2 == 0:
  print(ans)
else:
  print(ans - 2 * y)

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

int counter(int x) {
    if(x == 0) return 0;
    return counter(x >> 1) + (x & 1);
}

int main() {
    int n;
    int a[20];
    int x[20][20];
    int y[20][20];

    cin >> n;
    for (int i = 1; i <= n; i++) {
        cin >> a[i];
        for (int j = 1; j <= a[i]; j++) {
            cin >> x[i][j] >> y[i][j];
        }
    }

    int ans = 0;
    for(int bits = 1; bits < (1 << n); bits++) {
        bool ok = true;
        for(int i = 1; i <= n; i++) {
            if(!(bits & (1 << (i-1)))) continue;
            for(int j = 1; j <= a[i]; j++) {
                if(((bits >> (x[i][j]-1)) & 1) ^ y[i][j]) ok = false;
            }
        }
        if(ok) ans = max(ans,counter(bits));
    }

    cout << ans << endl;
}

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


int main(){
	cin.tie(nullptr);
	ios::sync_with_stdio(false);
	int n,m; cin >> n >> m;
	vector<pair<int,int>> cnt(n+1);
	for(int i=0;i<n+1;i++){
		cnt[i].second=-i;
	}
	while(m--){
		string s; cin >> s;
		int now=0;
		for(int i=1;i<=n;i++){
			if(s[i-1]=='W')now++;
			else now--;
			cnt[i].first+=now;
		}
	}
	sort(cnt.rbegin(),cnt.rend());
	cout << -cnt[0].second << " " << -cnt[0].second+1 << endl;
}


Measured memory_bytes: 3356
#include <algorithm>
#include <array>
#include <bitset>
#include <cassert>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstring>
#include <deque>
#include <functional>
#include <iomanip>
#include <locale>
#include <iostream>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <sstream>
#include <string>
#include <tuple>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>
 
#define REP(i,n) for(int i=0;i<(int)(n);i++)
#define ALL(x) (x).begin(),(x).end()
 
using namespace std;
 
using ll = long long;
using ld = long double;
 
template <typename T> T &chmin(T &a, const T &b) { return a = min(a, b); }
template <typename T> T &chmax(T &a, const T &b) { return a = max(a, b); }
template <typename T> int len(const T &x) { return x.size(); }
 
template<typename T>
vector<T> table(int n, T v) { return vector<T>(n, v); }
 
template <class... Args>
auto table(int n, Args... args) {
  auto val = table(args...);
  return vector<decltype(val)>(n, move(val));
}
 
struct yes_no : numpunct<char> {
  string_type do_truename()  const { return "YES"; }
  string_type do_falsename() const { return "NO"; }
};
 
const ld pi = acos(-1.0L);
 
using Data = int;
const Data INF = 1000000000;
 
vector<Data> lis(const vector<Data>& a) {
  const int n = a.size();
  if (n == 0) return vector<Data>(0);
  vector<Data> A(n, INF);
  vector<int> id(n);
  for (int i = 0; i < n; i++) {
    id[i] = distance(A.begin(), lower_bound(A.begin(), A.end(), a[i]));
    A[id[i]] = a[i];
  }
  int m = *max_element(id.begin(), id.end());
  vector<Data> res(m + 1);
  for (int i = n - 1; i >= 0; i--)
    if (id[i] == m) res[m--] = a[i];
  return res;
}
 
void solve(vector<ll> x, vector<ll> y, ll N, vector<ll> X, vector<ll> Y) {
  int l = min(x[0], x[1]);
  int r = max(x[0], x[1]);
  int t = min(y[0], y[1]);
  int b = max(y[0], y[1]);
  vector<pair<int,int>> point;
  REP(i,N) {
    if (l <= X[i] && X[i] <= r && t <= Y[i] && Y[i] <= b) {
      point.emplace_back(abs(X[i] - x[0]), abs(Y[i] - y[0]));
    }
  }
  sort(ALL(point));
  vector<int> ys;
  for (auto p: point) ys.push_back(p.second);
  auto v = lis(ys);
  ld res = ((r - l) + (b - t)) * 100.00L;
  if (v.empty()) { cout << res << endl; }
  else{
    int n = v.size();
    chmin(n, r - l);
    chmin(n, b - t);
    res += (5 * pi - 20) * n;
    if (r - l < int(v.size()) || b - t < int(v.size())) {
      res += 10 * pi - 20;
    }
    cout << res << endl;
  }
}
 
int main() {
  locale loc(locale(), new yes_no);
  cout << boolalpha << setprecision(15) << fixed;
  cout.imbue(loc);
	vector<ll> x(2-1+1);
	ll N;
	vector<ll> y(2-1+1);
	for (int i = 0 ; i <= 2-1 ; i++) {
	  scanf("%lld", &x[i]);
	  scanf("%lld", &y[i]);
	}
	scanf("%lld", &N);
	vector<ll> Y(N-1+1);
	vector<ll> X(N-1+1);
	for (int i = 0 ; i <= N-1 ; i++) {
	  scanf("%lld", &X[i]);
	  scanf("%lld", &Y[i]);
	}
	solve(x, y, N, X, Y);
	return 0;
}

Measured memory_bytes: 11380
#pragma region include
#include <iostream>
#include <iomanip>
#include <stdio.h>

#include <sstream>
#include <algorithm>
#include <iterator>
#include <cmath>
#include <complex>

#include <string>
#include <cstring>
#include <vector>
#include <tuple>
#include <bitset>

#include <queue>
#include <set>
#include <map>
#include <stack>
#include <list>

#include <fstream>
#include <random>
//#include <time.h>
//#include <intrin.h>
#include <ctime>
#pragma endregion //#include
/////////
#define REP(i, x, n) for(int i = x; i < n; ++i)
#define rep(i,n) REP(i,0,n)
#define ALL(X) X.begin(), X.end()
/////////
#pragma region typedef
typedef long long LL;
typedef long double LD;
typedef unsigned long long ULL;
typedef std::pair<LL,LL> PLL;//
typedef std::pair<int,int> PII;//
#pragma endregion //typedef
////定数
const int INF = (int)1e9;
const LL MOD = (LL)1e9+7;
const LL LINF = (LL)4e18+20;
const LD PI = acos(-1.0);
const double EPS = 1e-9;
/////////
using namespace::std;

void solve(){
	int n,m;
	cin>>n>>m;--n;--m;
	cout<<n*m<<endl;
}
#pragma region main
signed main(void){
	std::cin.tie(0);
	std::ios::sync_with_stdio(false);
	std::cout << std::fixed;//小数を10進数表示
	cout << setprecision(16);//小数点以下の桁数を指定//coutとcerrで別	

	solve();
}
#pragma endregion //main()

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		
		Scanner sc = new Scanner(System.in);
		long n = sc.nextLong();

		if (n<10) {
			System.out.println(n);
		}else if (n< 100) {
			System.out.println(9);
		}else if (n< 1000) {
			System.out.println(9+n-99);
		}else if (n< 10000) {
			System.out.println(909);
		}else if (n< 100000) {
			System.out.println(909+n-9999);
		}else {
			System.out.println(90909);
		}
		
		sc.close();
	}

}

Measured memory_bytes: 22996
#include <bits/stdc++.h>
#define rep(i,n)for(int i=0;i<(n);i++)
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
typedef tuple<ll,ll,ll> T;
const long long INF = 1LL<<60;
const int MOD = 998244353;
#define rev(s) (string((s).rbegin(), (s).rend()))
template < typename T > inline string toString( const T &a ) { ostringstream oss; oss << a; return oss.str(); };
// cout << fixed << setprecision(10) << ans << endl;
// *min_element(c + l, c + r) *max_element(c + l, c + r)
// int dx[8]={1,1,0,-1,-1,-1,0,1};
// int dy[8]={0,1,1,1,0,-1,-1,-1};
// int dx[4]={1,0,-1,0};
// int dy[4]={0,1,0,-1};
// struct Edge {
//   int to, id;
//   Edge(int to, int id): to(to), id(id) {}
// };

int main() {
    int N,S;cin>>N>>S;
    vector<int> pre_v(S+10,0);
    pre_v[0] = 1;
    rep(i,N) {
        int A;cin>>A;
        vector<int> new_v(S+10,0);
        rep(j,S+1) {
            new_v[j] = 2 * pre_v[j] % MOD;
            if(j - A>=0) new_v[j] = (new_v[j] + pre_v[j-A]) %MOD;
        }
        pre_v = new_v; 
    }
    cout<<pre_v[S]<<endl;
}

Measured memory_bytes: 3616
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> l_l;
typedef pair<int , int> i_i;
typedef vector<ll> vel;
typedef vector<int> vei;
typedef vector<char> vec;
typedef vector<bool> veb;
typedef vector<string> ves;
typedef vector<vector<ll>> ve_vel;
typedef vector<vector<int>> ve_vei;
typedef vector<vector<char>> ve_vec;
typedef vector<vector<bool>> ve_veb;
typedef vector<vector<string>> ve_ves;
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define rep1(i,n) for(int i=1;i<(int)(n);i++)
#define rep2(i,n) for(int i=2;i<(int)(n);i++)
#define repk(i,k,n) for(int i=k;i<(int)(n);i++)
#define fs first
#define sc second
#define pub push_back
#define puf push_front
#define pob pop_back
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define maxel(a) *max_element(all(a))
#define minel(a) *min_element(all(a))
#define acc accumulate
#define EPS (1e-7)
//#define INF (1e9)
#define PI (acos(-1))
#define mod (1000000007)
typedef long long int64;
const int64 INF = 1LL << 58;
template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return 1; } return 0; }
template<typename T> void remove(T & vector, unsigned int index){vector.erase(vector.begin() + index);}

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

    int H,W; cin >> H >> W;
    int dx[] = {0, 0, -1, 1};
    int dy[] = {1, -1, 0, 0};

    ve_vec f(H, vec(W)); rep(i,H) rep(j,W) cin >> f[i][j];

    rep(i,H) rep(j,W) {
        if(f[i][j] == '#') {
            bool flag = false;
            rep(k,4) {
                int nx = i + dx[k];
                int ny = j + dy[k];
                if(0 <= nx and nx < H and 0 <= ny and ny < W){
                    if(f[nx][ny] == '#') flag = true;
                }
            }
            if(!flag) {cout << "No" << endl; return 0;}
        }
    }
    cout << "Yes" << endl;
    return 0;


}



Measured memory_bytes: 256
<?php /*atcoder.php*/

$t = new temp();

$t->stdin(fgets(STDIN));

unset($t);

class temp{
	private $stdin = array();
	
	public function __construct(){
	}

	public function stdin($data = null){
		$this->stdin = explode(" ", $data);
		
		$s1 = $this->stdin[0] * $this->stdin[1];
		
		if(0 == ($s1 % 2)){
			echo "Even";
		}else{
			echo "Odd";
		}
	}
	
}

?>



Measured memory_bytes: 3828
import sys
sys.setrecursionlimit(1 << 25)
read = sys.stdin.readline
ra = range
enu = enumerate


def mina(*argv, sub=1): return list(map(lambda x: x - sub, argv))
# 受け渡されたすべての要素からsubだけ引く.リストを*をつけて展開しておくこと


def read_a_int(): return int(read())


def read_ints(): return list(map(int, read().split()))


def read_col(H):
    '''H is number of rows
    A列、B列が与えられるようなとき
    ex1)A,B=read_col(H)    ex2) A,=read_col(H) #一列の場合'''
    ret = []
    for _ in range(H):
        ret.append(list(map(int, read().split())))
    return tuple(map(list, zip(*ret)))


def read_tuple(H):
    '''H is number of rows'''
    ret = []
    for _ in range(H):
        ret.append(tuple(map(int, read().split())))
    return ret


def read_matrix(H):
    '''H is number of rows'''
    ret = []
    for _ in range(H):
        ret.append(list(map(int, read().split())))
    return ret
    # return [list(map(int, read().split())) for _ in range(H)] # 内包表記はpypyでは遅いため


MOD = 10**9 + 7
INF = 2**31  # 2147483648 > 10**9
# default import
from collections import defaultdict, Counter, deque
from operator import itemgetter
from itertools import product, permutations, combinations
from bisect import bisect_left, bisect_right  # , insort_left, insort_right

# https://atcoder.jp/contests/abc043/tasks/abc043_b

# 愚直にシミュレーションして良さそう

ans = 'x' * 20

for s in input():
    if s == 'B':
        ans = ans[:-1]
    else:
        ans += s
print(ans.replace('x', ''))


Measured memory_bytes: 38580
import collections
n = int(input())
v = list(map(int, input().split()))

v_even =v[0::2] 
v_odd = v[1::2]

c_v = collections.Counter(v)
c_even = collections.Counter(v_even)
c_odd = collections.Counter(v_odd)

c_even_s = sorted(c_even.items(), key=lambda x:x[1], reverse=True)
c_odd_s = sorted(c_odd.items(), key=lambda x:x[1], reverse=True)

if(len(c_v) != 1):
    if(c_even_s[0][0] != c_odd_s[0][0]):
        print(n//2-c_even_s[0][1]+n//2-c_odd_s[0][1])
    else:
        if(c_even_s[0][1] > c_odd_s[0][1]):
            ans = n//2-c_even_s[0][1]+n//2-c_odd_s[1][1]
        elif(c_even_s[0][1] == c_odd_s[0][1]):
            ans = min(n//2-c_even_s[0][1]+n//2-c_odd_s[1][1], n//2-c_even_s[1][1]+n//2-c_odd_s[0][1])
        else:
            ans = n//2-c_odd_s[0][1] + n//2-c_even_s[1][1]
        print(ans)
else:
    print(n//2)

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

public class Program
{

	static void Main(string[] args)
	{
		var N = int.Parse(Console.ReadLine());
		var array = Console.ReadLine().Split(' ').Select(int.Parse).ToArray();
		var trueArray = array.OrderBy(x => x).ToArray();
		var count = 0;

		for(int i = 0;i < N;i++)
		{
			if(array[i] != trueArray[i])
			{
				count++;
				if(count > 2)
				{
					break;
				}
			}
		}

		if(count > 2)
		{
			Console.WriteLine("NO");
		}
		else
		{
			Console.WriteLine("YES");
		}
	}
}


Measured memory_bytes: 13396
#include <stdio.h>

int main() {
	
	int n, i, j, q, x[10000], y[500], sum = 0;
	
	scanf("%d", &n);
	
	for( i = 0; i < n; i++) {
		scanf("%d", &x[i]);
	}
	
	scanf("%d", &q);
	
	for( i = 0; i < q; i++) {
		scanf("%d", &y[i]);
	}
	
	for( i = 0; i < q; i++) {
		for( j = 0; j < n; j++) {
			if( y[i]==x[j]) {
			sum = sum + 1;
			break ;
			}
		}
	}
	
	printf("%d\n", sum);
	
	return 0;
}

Measured memory_bytes: 1856
import sys

sys.setrecursionlimit(1000000)


def dfs(g: {}, v: int, seen: [], current_color: int):
    seen[v] = current_color
    for (next_v, next_w) in g[v]:
        # next_v が探索済だったらスルー
        if seen[next_v] != -1:
            if current_color == seen[next_v] and next_w % 2 == 1:
                return False
            elif current_color != seen[next_v] and next_w % 2 == 0:
                return False
            continue
        next_color = current_color if next_w % 2 == 0 else 1 - current_color
        # 再帰的に探索
        if not dfs(g, next_v, seen, next_color):
            return False
    return True


def main():
    n = int(input())

    g = {}
    for i in range(n-1):
        u, v, w = map(int, input().split())
        dic_a = g.setdefault(u-1, [])
        dic_a.append((v-1, w))
        dic_b = g.setdefault(v-1, [])
        dic_b.append((u-1, w))
    # -1:not clear, 0:white, 1:black
    seen = [-1] * n

    is_bipartite = True

    for i in range(n):
        if seen[i] != -1:
            continue
        if not dfs(g, i, seen, 0):
            is_bipartite = False
            break

    if is_bipartite:
        for i in range(n):
            print(seen[i])
    else:
        print("is not bipartite")

main()


Measured memory_bytes: 91256
K,T = map(int,input().split())
t = list(map(int,input().split()))
t1 = sorted(t,reverse=True)
b = sum(t)- t1[0]
if T == 1:
    print(K - 1)
elif b > t1[0]:
    print(0)
else:
    print(sum(t) - (b*2+1))
    

Measured memory_bytes: 2940
n = int(input())
count = 0
for ni in range(1,n+1):
    if ni%2 == 1:
        nj_count = 0
        for nj in range(1,ni+1):
            if ni%nj == 0:
                nj_count += 1
        if nj_count == 8:
            count += 1
print(count)

Measured memory_bytes: 3060
#include<iostream>
#include<string>
#include<algorithm>
#include<list>
#include<set>
#include<map>
#include<queue>
#include<stack>
#include<numeric>
#include<vector>
#define foreach(t,p) for(t::iterator it=p.begin();it!=p.end();++it)
#define all(p) p.begin(),p.end()
#define REP(i,n) for(int i=0;i<n;i++)
using namespace std;
int main()
{
    int n;
    while(cin >> n && n)
    {
        set<int> points;
        REP(i,n)
        {
            int a,b,c,d,e;
            cin >>a>>b>>c>>d>>e;
            points.insert(a+b+c+d+e);
        }
        cout << *points.rbegin() << " " << *points.begin() << endl;
    }
    return 0;
}

Measured memory_bytes: 0
#include <iostream>
#include <cmath>
#include <iomanip>
using namespace std;

class Dice{
    public:
        void set(int num[6]);
        void change_top(int num);
        int top_number();
        int right_number();
        int front_number();
        void E(), N(), S(), W(), roll_side();
    private:
    int dice_number[6];
};

int Dice::top_number(){
    return dice_number[0];
}
int Dice::right_number(){
    return dice_number[2];
}
int Dice::front_number(){
    return dice_number[1];
}

void Dice::set(int num[6]){
    for(int i = 0; i < 6; i++) dice_number[i] = num[i];
}

void Dice::change_top(int num){
    for(int i = 0; i < 6; i++){
        if(dice_number[i] == num){
            break;
        }
    }

}
void Dice::E(){
    int tmp = dice_number[0];
    dice_number[0] = dice_number[3];
    dice_number[3] = dice_number[5];
    dice_number[5] = dice_number[2];
    dice_number[2] = tmp;
}

void Dice::N(){
    int tmp = dice_number[0];
    dice_number[0] = dice_number[1];
    dice_number[1] = dice_number[5];
    dice_number[5] = dice_number[4];
    dice_number[4] = tmp;
}
void Dice::S(){
    int tmp = dice_number[0];
    dice_number[0] = dice_number[4];
    dice_number[4] = dice_number[5];
    dice_number[5] = dice_number[1];
    dice_number[1] = tmp;
}
void Dice::W(){
    int tmp = dice_number[0];
    dice_number[0] = dice_number[2];
    dice_number[2] = dice_number[5];
    dice_number[5] = dice_number[3];
    dice_number[3] = tmp;
}
void Dice::roll_side(){
    int tmp = dice_number[1];
    dice_number[1] = dice_number[2];
    dice_number[2] = dice_number[4];
    dice_number[4] = dice_number[3];
    dice_number[3] = tmp;
}

int main(){
    Dice dice1;
    int dice_num[6], q, top, front;
    char order[100];
    for (int i = 0; i < 6; i++ ) cin >> dice_num[i];
    dice1.set( dice_num );

    cin >> q;
    for(int i = 0; i < q; i++){
        cin >> top >> front;
        for (int j = 0; j < 4; j++){//4回回転させると上か正面のどちらかに当てはまる
            if(dice1.top_number() == top){
                for(int k = 0; k < 4; k++){
                    if(dice1.front_number() == front){
                        cout << dice1.right_number() << endl;
                        break;
                    }
                    dice1.roll_side();
                }
                break;
            }else if(dice1.front_number() == front){
                for(int k = 0; k < 4; k++){
                    if(dice1.top_number() == top){
                        cout << dice1.right_number() << endl;
                        break;
                    }
                    dice1.E();
                }
                break;
            }
            dice1.N();//N方向に回転
        }
    }
    return 0;
}


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

using namespace std;
string a,b;
char r1[100005],n1,n2,r2[100005];
bool cmd(char x,char y)
{
	return x>y;
}
int main()
{
	getline(cin,a);
	getline(cin,b);
	if(a<b)
	{
		cout<<"Yes"<<endl;
		return 0;
	}
	n1=a.size();
	n2=b.size();
	for(int i=0;i<n1;i++)
		r1[i]=a[i];
	for(int i=0;i<n2;i++)
		r2[i]=b[i];
	sort(r1,r1+n1);
	for(int i=0;i<n1;i++)
		a[i]=r1[i];
	sort(r2,r2+n2,cmd);
	for(int i=0;i<n2;i++)
		b[i]=r2[i];
	if(a<b)	cout<<"Yes"<<endl;
	else cout<<"No"<<endl;
	
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define endl "\n"
#define ll long long int
#define mod 1000000007
#define FIO ios_base::sync_with_stdio(false);cin.tie(NULL);

int main() {
    FIO;
    int n,i;
    cin>>n;
    int d1[n];
    int d2[n];
    for(i=0;i<n;i++)
        cin>>d1[i]>>d2[i];
    bool flag=false;
    for(i=0;i<n-2;i++){
        if(d1[i]==d2[i] && d1[i+1]==d2[i+1] && d1[i+2]==d2[i+2] )
            flag=true;
    }
    if(flag)
        cout<<"Yes"<<endl;
    else
        cout<<"No"<<endl;
    return 0;
}

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

using namespace std;
#define mp(x,y) make_pair((x),(y))
typedef pair <int, int> ii;
typedef vector <ii> vii;
const int INF = (int) 1e9;
vii adj[1234];
int n;

int main(){
    while (cin >> n && n){
	for (int i = 0; i < 1234; i++) adj[i].clear();
	vector <int> u(n-1), dist(n-1);
	for (int i = 0; i < n-1; i++) cin >> u[i];
	for (int i = 0; i < n-1; i++) cin >> dist[i];
	int tot = 0;
	for (int i = 0; i < n-1; i++){
	    int v = i + 2;
	    adj[u[i]].push_back(mp(v, dist[i]));
	    adj[v].push_back(mp(u[i], dist[i]));
	    tot += dist[i] * 3;
	}

	vector <int> valid(n + 1, 1);
	for (int i = 1; i <= n; i++){
	    if ( (int) adj[i].size() == 1 ) {
		valid[i] = 0;
		tot -= adj[i][0].second * 2;
	    }
	}
	
	int st = -1;
	for (int i = 1; i <= n; i++){
	    if (valid[i]) {
		st = i;
		break;
	    }
	}
	if (st == -1) {
	    cout << tot << endl;
	    continue;
	}
	vector <int> distance(n + 1, INF);
	queue <int> q;
	q.push(st);
	distance[st] = 0; 
	while (!q.empty()){
	    int u = q.front(); q.pop();
	    for (int i = 0 ; i < (int) adj[u].size(); i++){
		int v = adj[u][i].first;
		int d = adj[u][i].second;
		if (distance[v] == INF && valid[v]){
		    distance[v] = distance[u] + d;
		    q.push(v); 
		}
	    }
	}
	int nxt = -1; int curr = 0;
	for (int i = 1; i <= n; i++) {
	    if (distance[i] != INF && distance[i] > curr){
		curr = distance[i];
		nxt = i;
	    }
	}
	if (nxt == -1) {
	    cout << tot << endl;
	    continue;
	}
	distance.assign(n + 1, INF);
	q.push(nxt);
	distance[nxt] = 0; 
	while (!q.empty()){
	    int u = q.front(); q.pop();
	    for (int i = 0 ; i < (int) adj[u].size(); i++){
		int v = adj[u][i].first;
		int d = adj[u][i].second;
		if (distance[v] == INF && valid[v]){
		    distance[v] = distance[u] + d;
		    q.push(v);
		}
	    }
	}

	int hi = 0;
	for (int i = 1; i <= n; i++){
	    if (distance[i] != INF) hi = max(hi, distance[i]);
	}

	tot -= hi;
	cout << tot << endl;
    }
    return 0;
}

Measured memory_bytes: 1336
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i = 0; i < (n); i++)
#define ALL(v) (v).begin(),(v).end()
using ll = long long;
using P = pair<int, int>;
const int INF = 1e9;
const long long LINF = 1e18;
const long long MOD = 1e9 + 7;

signed main(){
	int n,m,c;
	cin >> n >> m >> c;
	int b[m];
	rep(i,m){
		cin >> b[i];
	}
	int a[n][m];
	rep(i,n){
		rep(j,m){
			cin >> a[i][j];
		}
	}
	int ans = 0;
	rep(i,n){
		int sum = c;
		rep(j,m){
			sum += a[i][j] * b[j];
		}
		if(sum > 0) ans++;
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cstring>
#include <sstream>
#include <algorithm>
#include <vector>
#include <cmath>
using namespace std;
#define mem(a,n) memset(a,sizeof(a),n)
typedef long long ll;
const int mod=1e9+7;
const int N=1e5+5;
const int INF=0x3f3f3f3f;
int main()
{
    int x,y,z;
    while(cin>>x>>y>>z)
    {
        x-=z;
        cout<<x/(y+z)<<endl;
    }
    return 0;
}


Measured memory_bytes: 256
#pragma GCC optimize ("O3")
#include <iostream>
#include <iomanip>
#include <istream>
#include <ostream>
#include <sstream>
#include <iterator>
#include <vector>
#include <algorithm>
#include <queue>
#include <deque>
#include <list>
#include <stack>
#include <map>
#include <unordered_map>
#include <set>
#include <bitset>
#include <utility>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <string>
#include <ctime>
#include <cctype>
#include <cstdlib>
#define IINF 10e8
#define INF 1<<30
#define MOD 1000000007
#define mod 10007
#define REP(i, a, n) for (ll i = a; i < (ll)(n); i++)
#define REPE(i, a, n) for (ll i = a; i <= (ll)(n); i++)
#define Endl endl
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define eb emplace_back
#define mmax(x,y)(x>y?x:y)
#define mmin(x,y)(x<y?x:y)
#define chmax(x,y) x=mmax(x,y)
#define chmin(x,y) x=mmin(x,y)
#define all(x) (x).begin(),(x).end()
#define siz(x) (ll)(x).size()
#define PI acos(-1.0)
using namespace std;
typedef long long int ll;
typedef unsigned long long int ull;
typedef long double ld;
typedef pair<int,int>Pin;
typedef pair<ll,ll>Pll;
template<class T> using V=vector<T>;
long long GCD(long long a, long long b) {return b?GCD(b,a%b):a;}
long long LCM(long long a, long long b) {return a/GCD(a,b)*b;}
int dx[4]={-1,0,1,0};
int dy[4]={0,-1,0,1};
int ddx[8]={-1,0,1,0,1,1,-1,-1};
int ddy[8]={0,-1,0,1,1,-1,1,-1};
ll cmp(pair<ll,ll>a,pair<ll,ll> b){
        if(a.se!=b.se)
        return a.se<b.se;
        else
        return a.fi<b.fi;
}
//----------------------------------------------------------------------

//----------------------------------------------------------------------
int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    //-------------------------------  
    //ll begin_time=clock();
    //------------------------------
    int a,b;char c;
    cin>>a>>c>>b;
    while(c!='?'){
        if(c=='+')cout<<a+b<<endl;
        else if(c=='/')cout<<a/b<<endl;
        else if(c=='-')cout<<a-b<<endl;
        else cout<<a*b<<endl;
        cin>>a>>c>>b;
    }
    //-------------------------------  
    //ll end_time=clock();cout<<"time="<<end_time-begin_time<<"ms"<<endl;
    //-------------------------------
    return 0;
}
//----------------------------------------------------------------------

































Measured memory_bytes: 3168
#include <bits/stdc++.h>
#define rep(i, n) for (ll i = 0; i < (n); i++)
using namespace std;
using ll = long long;
using P = pair<ll, ll>;
const ll INF = 1e11;
int main(){
    int n, k;
    cin >> n>> k;
    vector<ll> h(n), dp(n,INF);
    rep(i,n) cin >> h[i];
    dp[0] = 0;
    for(int j; j<n; j++){
        for(int i = 1; i<k+1; i++){
            if(j+i<n){
                dp[j+i] = min(dp[j+i], dp[j] + abs(h[j]-h[j+i]));
            }
        }
    }
    cout << dp[n-1] << endl;
    return 0;
}

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

int main()
{
    int r,d,x;
    cin>>r>>d>>x;
    for(int i = 0 ; i < 10 ; i ++)
    {
        int xx = x*r - d;
        cout<<xx<<endl;
        x = xx;
    }
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define fi first
#define se second
#define pi pair<ll,ll>
#define pii pair<ll,pi>
#define pb push_back
#define mk make_pair
int main() {

	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	vector<int>v(5);
	int p;
	for (int i = 0; i < 5; i++) {
		cin >> v[i];
		if (v[i] == 0)
			p = i;
	}
	cout << p + 1 << endl;
}

Measured memory_bytes: 3604
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]


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


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


def main():
    N = int(input())
    i = 1
    while i * i <= N:
        i += 1
    print((i - 1) * (i - 1))


if __name__ == '__main__':
    main()


Measured memory_bytes: 3956
import java.util.*;

public class Main {
    public static void main(String args[]){
	Scanner in = new Scanner(System.in);
	
	int n = in.nextInt();
	String clear = in.nextLine();
	String s = in.nextLine();
	long ans = 0;
	int i =0;
	while(i<n){
	    ans++;
	    while(i<(n-1) && s.charAt(i) == s.charAt(i+1)){
		i++;
	    }
	    ++i;
	}
	System.out.println(ans);
    }
}


Measured memory_bytes: 27588
#include<iostream>
#include<string>
#include<cstdio>
#include<algorithm>
#include<cstdlib>
#include<cmath>
#include<vector>
#include<utility>
#include<queue>
#include<stack>
#include<set>
#include<map>
#include<unordered_set>
#include<unordered_map>
#include<bitset>
#include<iomanip>
#include<list>
#include<deque>
using namespace std;
//#define MODE 1
#ifdef MODE
#define DEB(X) cout<< #X <<": "<<X<<" ";
#define DEB2(X) cout<<X<<" ";
#define END cout<<endl;
#else
#define DEB(X) {}
#define DEB2(X) {}
#define END {}
#endif
typedef long long ll;
#define int ll
#define uset unordered_set
#define umap unordered_map
//typedef std::pair<int,int> P;
struct edge{int to,cost;};
const int INF=100000000000000000;
const int INF2=9223372036854775807;
const int MOD=1000000007;
#define REP(i,n) for(int i=0;i<(int)(n);i++)
#define min(X,Y) (((int)(X)<(int)(Y))?(X):(Y))
#define max(X,Y) (((int)(X)>(int)(Y))?(X):(Y))
#define NP(X,Y) next_permutation(X,Y)
#define setdouble(X,Y) cout<<fixed<<setprecision(X)<<Y
int ceil2(int a,int b){if(a%b==0){return a/b;}else{return a/b+1;}}
int pow2(int a,int b){int r=1;for(int i=1;i<=b;i++){r*=a;}return r;}
int Log2(int a){int t=0;while(1){if(a==0||a==1){break;}a/=2;t++;}return t;}

int N;
int A[10010];
map<int,int> L;



map<int,int> dec2(int n){
	map<int,int> m;
	int a=2;
	while(n>=a*a){
		if(n%a==0){
			m[a]++;
			n/=a;
		}
		else{
			a++;
		}
	}
	m[n]++;
	return m;
}

int mod_pow(int b,int e,int m){
    if(e==0){
        return 1;
    }else{
        int sum = mod_pow(b,e/2,m);
        if(e%2==0){
            return (sum*sum)%m;
        }else{
            return (((sum*sum)%m)*b)%m;
        }
    }
}

int extgcd(int a,int b,int &x,int &y){
	int g=a;
	x=1,y=0;
	if(b!=0){
		g=extgcd(b,a%b,y,x);
		y-=(a/b)*x;
	}
	return g;
}
 
// 逆元
int mod_inverse(int a,int m){
	int x, y;
	extgcd(a,m,x,y);
	return (m+x%m)%m;
}

signed main(){
	cin>>N;
	REP(i,N){
		cin>>A[i];
	}
	REP(i,N){
		map<int,int> h=dec2(A[i]);
		for(auto x:h){
			L[x.first]=max(L[x.first],x.second);
		}
	}
	int Lcm=1;
	for(auto x:L){
		Lcm*=mod_pow(x.first,x.second,MOD);
		Lcm%=MOD;
	}
	int ans=0;
	REP(i,N){
		ans+=Lcm*mod_inverse(A[i],MOD)%MOD;
		ans%=MOD;
	}
	cout<<ans<<endl;
	return 0;
}


Measured memory_bytes: 896
#include<bits/stdc++.h>
using namespace std;
int main()
{
  int a[3];
  cin>>a[0]>>a[1]>>a[2];
  sort(a,a+3);
  if(abs(a[0]-a[1])==abs(a[1]-a[2]))
  {
    cout<<"YES";
  }
  else
    cout<<"NO";
}


Measured memory_bytes: 3584
import math,heapq,collections,sys,numpy

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 S(): return input()

a,b,c = LI()
if a == b:
    print(c)
elif b == c:
    print(a)
elif a == c:
    print(b)

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

int ri() {
	int n;
	scanf("%d", &n);
	return n;
}
int64_t rs64() {
	int64_t n;
	scanf("%" SCNd64, &n);
	return n;
}

int main() {
	int n = ri(), m = ri();
	int pe[n];
	memset(pe, 0, sizeof(pe));
	int res = 0, ac = 0;
	for (int i = 0; i < m; i++) {
		int t = ri() - 1;
		std::string s;
		std::cin >> s;
		if (s == "AC") {
			if (pe[t] != -1) res += pe[t], pe[t] = -1, ac++;
		} else {
			if (pe[t] != -1) pe[t]++;
		}
	}
	std::cout << ac << " " << res << std::endl;
	return 0;
}


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

#define EPS (1e-10)
#define rep(i, a, b) for (int i = a; i < (int)(b); ++i)
#define rrep(i, a, b) for (int i = b - 1; i >= (int)(a); --i)
#define all(a) a.begin(), a.end()

using namespace std;
using ll = long long;
using vi = vector<int>;
using vb = vector<bool>;
using vll = vector<ll>;
using vd = vector<double>;
using vvi = vector<vi>;
using vvb = vector<vb>;

constexpr int MOD = 1000000007;

struct Game {
    int i, j, date;
    Game(int i, int j, int date) : i(i), j(j), date(date) {}
};

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

    int n;
    cin >> n;

    vvi a(n, vi(n - 1));
    rep(i, 0, n) {
        rep(j, 0, n - 1) {
            int x;
            cin >> x;
            a[i][j] = x - 1;
        }
    }

    // 初日に出来る試合をスタックにプッシュ．
    queue<Game> st;
    rep(i, 0, n) {
        if (i < a[i][0] && a[a[i][0]][0] == i) { st.emplace(i, a[i][0], 1); }
    }

    // 全試合数，日数．
    int cnt = 0, date = 0;

    // 各プレイヤーの終了した試合数．
    vi done(n, 0);

    while (!st.empty()) {
        Game g = st.front();
        st.pop();

        ++cnt;
        ++done[g.i];
        ++done[g.j];
        date = max(date, g.date);

        // g.iが翌日に試合出来るかどうか．
        if (done[g.i] != n - 1) {
            int j = a[g.i][done[g.i]];
            if (a[j][done[j]] == g.i) { st.emplace(g.i, j, g.date + 1); }
        }

        // g.jが翌日に試合出来るかどうか．
        if (done[g.j] != n - 1) {
            int i = a[g.j][done[g.j]];
            if (a[i][done[i]] == g.j) { st.emplace(i, g.j, g.date + 1); }
        }
    }

    if (cnt != n * (n - 1) / 2) {
        cout << -1 << endl;
    } else {
        cout << date << endl;
    }

    return 0;
}

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

int main() {
  long long n, x; cin >> n >> x;
  long long a[n];
  long long a_sum = 0;
  for (int i = 0; i < n; ++i) {
    cin >> a[i];
    a_sum += a[i];
  }
  
  if (x > a_sum) cout << n - 1 << endl;
  else if (x == a_sum) cout << n << endl;
  else {
    int ans = 0;
    sort(a, a + n);
    for (int a_i = 0; a_i < n; ++a_i) {
      x = x - a[a_i];
      if (x >= 0) ++ans;
    }
    cout << ans << endl;
  }
  
  return 0;
}

Measured memory_bytes: 256
ans = 'AKIHABARA'.chars
list = gets.chop.chars
loop do
  if list.empty? && (ans - ['A'] ).empty?
    puts 'YES'
    exit 0
  end
  break if list.empty? || ans.empty?

  t = list.shift
  m = ans.shift
  next if t == m

  if m == 'A'
    list.unshift(t)
  else
    puts 'NO'
    exit 0
  end
end
puts 'NO'

Measured memory_bytes: 1788
a = int(input())
b = input()

b = b.split()
b = [int(x) for x in b]

b = sorted(b)
b = b[::-1]

def get(a,x):
	if a == 0:
		return 0
	x.pop(0)
	add = x.pop(0)

	return add + get((a-1),x)

print(str(get(a,b)))

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

const ll N = 104, WEI = 1e5+3;
ll n, k;
ll w[N], v[N], dp[N][WEI];

int main(){
	cin >> n >> k;
	for(ll i = 1; i <= n; i++) cin >> w[i] >> v[i];

	memset(dp, 0, sizeof dp);
	for(ll i = 1; i <= n; i++){
		for(ll b = 1; b <= k; b++){
			if(w[i] <= b)
				dp[i][b] = max(dp[i-1][b], v[i] + dp[i-1][b-w[i]]);
			else
				dp[i][b] = dp[i-1][b];
		}
	}
	cout << dp[n][k] << endl;
}

Measured memory_bytes: 81536
#include <algorithm>
#include <iostream>
#include <list>
#include <map>
#include <math.h>
#include <stack>
#include <stdio.h>
#include <string>
#include <queue>
#include <vector>
using namespace std;

int n;
int A[20];

bool search(int x, int i) {
	if (x == 0) return true;
	else if (i == n) return false;

	return search(x, i + 1) || search(x - A[i], i + 1);
}

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

	int q, x;
	cin >> q;
	for (int i = 0; i < q; i++) {
		cin >> x;
		if (search(x, 0)) cout << "yes" << endl;
		else cout << "no" << endl;
	}
}


Measured memory_bytes: 3088
#include <bits/stdc++.h>
using namespace std;
int INF = 10000000;
int main(){
  while (1){
    int N, M, L;
    cin >> N >> M >> L;
    if (N == 0 && M == 0 && L == 0){
      break;
    }
    int V = N * (L + 1);
    vector<vector<pair<int, int>>> G(V);
    for (int i = 0; i < M; i++){
      int A, B, D, E;
      cin >> A >> B >> D >> E;
      A--;
      B--;
      for (int j = 0; j <= L; j++){
        G[A * (L + 1) + j].push_back(make_pair(E, B * (L + 1) + j));
        G[B * (L + 1) + j].push_back(make_pair(E, A * (L + 1) + j));
      }
      for (int j = 0; j <= L - D; j++){
        G[A * (L + 1) + j].push_back(make_pair(0, B * (L + 1) + j + D));
        G[B * (L + 1) + j].push_back(make_pair(0, A * (L + 1) + j + D));
      }
    }
    vector<int> d(V, INF);
    priority_queue<pair<int, int>, vector<pair<int, int>>, greater<pair<int, int>>> pq;
    pq.push(make_pair(0, 0));
    while (!pq.empty()){
      int c = pq.top().first;
      int v = pq.top().second;
      pq.pop();
      if (d[v] == INF){
        d[v] = c;
        for (auto P : G[v]){
          int w = P.second;
          if (d[w] == INF){
            pq.push(make_pair(c + P.first, w));
          }
        }
      }
    }
    int ans = INF;
    for (int i = 0; i <= L; i++){
      ans = min(ans, d[(N - 1) * (L + 1) + i]);
    }
    cout << ans << endl;
  }
}


Measured memory_bytes: 11368
#include <iostream>
#include <vector>
#include <cstring>
#include <algorithm>
#include <cassert>
#include <deque>
#include <map>
#include <queue>
#include <climits>
#include <set>
#include <stack>

using namespace std;

#define ll long long
#define MAX 100000
#define MAX1 10000
#define MAX2 100000
#define inf 1000000000
#define eps 1e-12
#define MOD 1000000007

int main() {

    ios_base::sync_with_stdio(0);
    cin.tie(0);
#ifndef ONLINE_JUDGE
    freopen("in.txt", "r", stdin);
    freopen("out.txt", "w", stdout);
#endif

    int n, a, i, cnt = 0;
    cin >> n;
    for (i = 0; i < n; ++i) {
        cin >> a;
        if (i % 2 == 0 and a & 1) {
            cnt++;
        }
    }
    cout << cnt;

    return 0;
}

Measured memory_bytes: 3164
from collections import defaultdict
from itertools import product
 
H, W, K = map(int, input().split())
S = [input() for _ in range(H)]
 
C = [[int(s[i]) for s in S] for i in range(W)]#列を一括りにする

total = sum(sum(c) for c in C)#すべての値の合計を算出
 
answer = H * W
for X in product([False, True], repeat=H-1):#Hは行数
  #あるXについて一回目のfor文が回る
  ans = sum(X)#Trueの数を換算
  if ans > answer:
    continue
  M = [[0]]
  for i, x in enumerate(X):
    if x:#Trueなら実行
      M.append([])#Trueの数の配列が作成される
    M[-1].append(i+1)#一番最後にその番目をappendする
  D = [0] * len(M)#初期値を設定
  for c in C:
    for k, m in enumerate(M):
      D[k] += sum(c[i] for i in m)#k番目の要素に足していく
      #Dにどんどん代入することによってどの列まで足すことができるか算出することができる
    if any(d > K for d in D):#一つでもKを超えていたら
      ans += 1
      if ans > answer:
        break
      D = [sum(c[i] for i in m) for m in M]#Dの更新(1番最初のDに戻る)
      if any(d > K for d in D):#一つでもKを超えていたら
        ans = answer + 1#ansの更新
        break
  answer = min(answer, ans)

print(answer)

Measured memory_bytes: 3572
#include <iostream>
#include <algorithm>
#include <utility>
#include <vector>

using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define REP(i, n) for (int i = 0; i < (n); i++)
#define ALL(a) (a).begin(), (a).end()

int main() {
    int a, b;
    cin >> a >> b;
    cout << (b - a) * (b - a + 1) / 2 - b << endl;
    return 0;
}

Measured memory_bytes: 256