akhauriyash/Code-Regression huggingface dataset:
import sys
from collections import deque
import itertools


def input():
    return sys.stdin.readline().rstrip()


def main():
    x,y = map(int,input().split())
    if (x+y)%3 !=0:
        print(0)
        exit()
    if x*2 <y or y *2 <x:
        print(0)
        exit()

    n = int((x+y)/3)
    #conbination y-n from N or  x-n from N


    mod = 10 ** 9 + 7  # 出力の制限
    N = 10 ** 6
    g1 = [1, 1]  # 元テーブル
    g2 = [1, 1]  # 逆元テーブル
    inverse = [0, 1]  # 逆元テーブル計算用テーブル

    def cmb(n, r, mod):
        if (r < 0 or r > n):
            return 0
        r = min(r, n - r)
        return g1[n] * g2[r] * g2[n - r] % mod
    for i in range(2, N + 1):
        g1.append((g1[-1] * i) % mod)
        inverse.append((-inverse[mod % i] * (mod // i)) % mod)
        g2.append((g2[-1] * inverse[-1]) % mod)

    a = cmb(n, x-n, mod)

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


Measured memory_bytes: 127984
#include <bits/stdc++.h>
using namespace std::literals::string_literals;
using i64 = std::int_fast64_t;
using std::cout;
using std::cerr;
using std::endl;
using std::cin;

template<typename T>
std::vector<T> make_v(size_t a){return std::vector<T>(a);}

template<typename T,typename... Ts>
auto make_v(size_t a,Ts... ts){
  return std::vector<decltype(make_v<T>(ts...))>(a,make_v<T>(ts...));
}

int main() {
	char c; cin >> c;

	if('a' <= c and c <= 'z') printf("a\n");
	else printf("A\n");
	return 0;
}



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

using namespace std;
#define BUF (1000)
#define ll long long

int k;

ll solve1(string n)
{
	int m = n.length();
	ll ans = 9 * (m - 1) + n.at(0) - 0x30;
	return ans;
}

ll solve2(string n)
{
	int top = 0;
	int m = n.length();
	int second = 1;
	while (second < m && n.at(second) == 0x30){
		second++;
	}

	ll ans=0;
	for (int i = 1; i < m; i++)
	{
		ans += 81 * (i - 1);
	}

	ans += (n.at(0) - 0x31) * (m - 1) * 9;
	if (second != m)
	{
		ans += n.at(second)-0x30;
		ans += 9*(m-second-1);
	}
	return ans;
}

ll solve3(string n)
{
	int top = 0;
	int m = n.length();
	int second = 1;
	while (second < m && n.at(second) == 0x30){
		second++;
	}

	ll ans=0;
	for (int i = 1; i < m; i++)
	{
		ans += 9 * 9 * 9 * (i - 1)*(i - 2) / 2;
	}

	ans += (n.at(0) - 0x31) * (m - 1) *(m-2)/2*9 * 9;

	string s = n.substr(second, m-second);
	if(second !=m) ans += solve2(s);

	return ans;
}

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

	ll ans;
	switch (k)
	{
	case 1:
		ans = solve1(n);
		break;
	case 2:
		ans = solve2(n);
		break;
	case 3:
		ans = solve3(n);
		break;
	}

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


Measured memory_bytes: 256
#include<stdio.h>

int main()
{
    int n,sum=0;
    scanf("%d",&n);
    int tem=n;
    while(tem>0)
    {
        sum=sum+(tem %10);
        tem=tem/10;
        if(tem==0)break;

    }
    if(n%sum==0)
    {
        printf("Yes\n");
    }
    else
        printf("No\n");

    return 0;
}


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

#define N 1010 

using namespace std;

typedef long long ll;

char *p1, *p2, buf[100000];

#define nc() (p1 == p2 && (p2 = (p1 = buf) + fread(buf, 1, 100000, stdin), p1 == p2) ? EOF : *p1 ++ )

int rd() {
    int x = 0, f = 1;
    char c = nc();
    while (c < 48) {
        if (c == '-')
            f = -1;
        c = nc();
    }
    while (c > 47) {
        x = (((x << 2) + x) << 1) + (c ^ 48), c = nc();
    }
    return x * f;
}

ll X[N], Y[N];

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

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

char output[] = {'L', 'D', 'R', 'U'};

int main() {
    int n = rd();
    X[1] = rd(), Y[1] = rd();
    bool pre = (X[1] + Y[1]) & 1;
    for (int i = 2; i <= n; i ++ ) {
        X[i] = rd(), Y[i] = rd();
        if (((X[i] + Y[i]) % 2 != 0) != pre) {
            puts("-1");
            return 0;
        }
    }

    if (!pre) {
        for (int i = 1; i <= n; i ++ ) {
            X[i] -- ;
        }
    }

    if (pre) {
        puts("31");
    }
    else {
        puts("32");
    }
    if (!pre) {
        printf("1 ");
    }
    ll tmp = 1;
    printf("1 ");
    for (int i = 1; i <= 30; i ++ ) {
        tmp <<= 1;
        printf("%lld ", tmp);
    }
    puts("");
    for (int i = 1; i <= n; i ++ ) {
        string ans = "";
        int x = X[i], y = Y[i];
        for (int j = 30; ~j; j -- ) {
            ll mdl = (1ll << j);
            for (int k = 0; k < 4; k ++ ) {
                ll x_ = x + mdl * dx[k], y_ = y + mdl * dy[k];
                if (abs(x_) + abs(y_) <= mdl - 1) {
                    x = x_, y = y_;
                    ans.push_back(output[k]);
                    break;
                }
            }
        }
        reverse(ans.begin(), ans.end());
        if (!pre) {
            putchar('R');
        }
        cout << ans << endl ;
    }
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define SIZE 305
#define MOD 998244353
using namespace std;
typedef long long int ll;
typedef pair <int,int> P;

char S[SIZE];
int vx[SIZE];
int dp[2][SIZE][SIZE];
int cur[SIZE][SIZE];
int main()
{
	scanf("%s",&S);
	int K;
	scanf("%d",&K);
	int n=strlen(S);
	int sz=0;
	for(int i=0;i<n;i++)
	{
		if(S[i]=='0')
		{
			vx[sz++]=i;
		}
	}
	if(sz==0)
	{
		puts("1");
		return 0;
	}
	int pos=0;
	for(int h=0;h<n-vx[0];h++)
	{
		dp[pos][h][0]=1;
	}
	for(int i=0;i+1<sz;i++)
	{
		pos=1-pos;
		memset(dp[pos],0,sizeof(dp[pos]));
		int f=vx[i],s=vx[i+1],d=s-f;
		for(int j=n-1;j>=0;j--)
		{
			for(int k=0;k<n;k++)
			{
				cur[j][k]=dp[1-pos][j][k];
				if(j+1<n&&k-1>=0)
				{
					cur[j][k]+=cur[j+1][k-1];
					if(cur[j][k]>=MOD) cur[j][k]-=MOD;
				}
			}
		}
		for(int k=0;k<n;k++)
		{
			int sum=0;
			for(int j=0;s+j<n;j++)
			{
				sum+=dp[1-pos][j][k];
				if(sum>=MOD) sum-=MOD;
				dp[pos][j][k]=sum;
				if(j+1<n&&k>0)
				{
					int p=cur[j+1][k-1];
					if(j+d<n&&k-d>=0)
					{
						p-=cur[j+d][k-d];
						if(p<0) p+=MOD;
					}
					dp[pos][j][k]+=p;
					if(dp[pos][j][k]>=MOD) dp[pos][j][k]-=MOD;
				}
			}
		}
	}
	int ret=0;
	for(int i=0;i<n;i++)
	{
		for(int j=0;j<n&&i+j<=K;j++)
		{
			ret+=dp[pos][i][j];
			if(ret>=MOD) ret-=MOD;
		}
	}
	printf("%d\n",ret);
}

Measured memory_bytes: 4912
//***Because people who are crazy enough to think that they can change the world are the ones who do it***
//Think different
 
#include<bits/stdc++.h>
using namespace std;
 
#define mp make_pair
#define mt make_tuple
#define fi first
#define se second
#define pb push_back
#define ll long long 
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define rep(i,n) for(i=0;i<n;i++)
#define forn(i, n) for (ll i = 0; i < (ll)(n); ++i)
#define for1(i, n) for (ll i = 1; i <= (ll)(n); ++i)
#define ford(i, n) for (ll i = (ll)(n) - 1; i >= 0; --i)
#define fore(i, a, b) for (ll i = (ll)(a); i <= (ll)(b); ++i)
#define fora(it,x) for(auto it:x)
#define PI 3.14159265
#define sync ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define endl "\n"
 
typedef pair<ll, ll> pii;
typedef vector<ll> vi;
typedef vector<pii> vpi;
typedef vector<vi> vvi;
typedef long long i64;
typedef vector<i64> vi64;
typedef vector<vi64> vvi64;
typedef pair<i64, i64> pi64;
typedef long double ld;
 
template<class T> bool uin(T &a, T b) { return a > b ? (a = b, true) : false; }
template<class T> bool uax(T &a, T b) { return a < b ? (a = b, true) : false; }

int main(){
	ll n;
	cin>>n;
	ll a=0;
	for1(i,n){
		a+=((i*(i+1))/2);
	}
	for1(i,n-1){
		ll u,v;
		cin>>u>>v;
		if(u>v) swap(u,v);
		a-=(u*(n-v+1));
	}
	cout<<a;
}

Measured memory_bytes: 3596
#include<stdio.h>
#include<math.h>
#include<algorithm>
#include<queue>
#include<deque>
#include<stack>
#include<string>
#include<string.h>
#include<vector>
#include<set>
#include<map>
#include<bitset>
#include<stdlib.h>
#include<cassert>
#include<time.h>
#include<bitset>
using namespace std;
const long long mod=1000000007;
const long long inf=mod*mod;
const long long d2=(mod+1)/2;
const long double EPS=1e-9;
const long double PI=acos(-1.0);
int ABS(int a){return max(a,-a);}
long long ABS(long long a){return max(a,-a);}
long double ABS(long double a){return max(a,-a);}
int x[1100];
int y[1100];
bool v[1100];
bool h[1100];
char in[1100];
void calc(int X,int Y,int c){
	if(c<0)return;
	//printf("%d %d %d\n",X,Y,c);
	int len=1<<(max(0,c-1));
	if(X>=len){
		calc(X-len,Y,c-1);
		in[c]='R';
	}else if(Y>=len){
		calc(X,Y-len,c-1);
		in[c]='U';
	}else if(X>Y){
		calc(len-X,Y,c-1);
		for(int i=0;i<c;i++){
			if(in[i]=='L')in[i]='R';
			else if(in[i]=='R')in[i]='L';
		}
		in[c]='R';
	}else{
		calc(X,len-Y,c-1);
		for(int i=0;i<c;i++){
			if(in[i]=='U')in[i]='D';
			else if(in[i]=='D')in[i]='U';
		}
		in[c]='U';
	}
}
int main(){
	int a;scanf("%d",&a);
	for(int i=0;i<a;i++){
		scanf("%d%d",x+i,y+i);
	}
	int V=ABS(x[0]+y[0])%2;
	for(int i=1;i<a;i++){
		if(V!=ABS(x[i]+y[i])%2){
			printf("-1\n");return 0;
		}
	}
	for(int i=0;i<a;i++)x[i]-=V;
	for(int i=0;i<a;i++){
		if(x[i]<0){
			h[i]=true;
			x[i]*=-1;
		}
		if(y[i]<0){
			v[i]=true;
			y[i]*=-1;
		}
	}
	printf("%d\n",32+V);
	if(V)printf("1 ");
	for(int i=0;i<32;i++){
		if(i)printf(" ");
		printf("%d",1<<(max(0,i-1)));
	}
	printf("\n");
	for(int i=0;i<a;i++){
		calc(x[i],y[i],31);
		if(V)printf("R");
		for(int j=0;j<32;j++){
			if(h[i]){
				if(in[j]=='L')in[j]='R';
				else if(in[j]=='R')in[j]='L';
			}
			if(v[i]){
				if(in[j]=='U')in[j]='D';
				else if(in[j]=='D')in[j]='U';
			}
		}
		printf("%s\n",in);
	}
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define INF 0x3f3f3f3f
#define rep(i,n)for(int i=0;i<(n);i++)
using namespace std;
 
int h, w, mn = INF, mx = 0, a[2000][2000];
bool ok(int t) {
	int prv = 0;
	rep(i, h) {
		int j;
		for (j = w - 1; j >= prv && a[i][j] <= mn + t; j--); j++;
		for (int k = 0; k < j; k++) {
			if (a[i][k] < mx - t)return false;
		}
		prv = j;
	}
	return true;
}
int main() {
	scanf("%d%d", &h, &w);
	rep(i, h)rep(j, w) {
		scanf("%d", &a[i][j]);
		mn = min(mn, a[i][j]); mx = max(mx, a[i][j]);
	}
	int l = 0, r = INF;
	while (l != r) {
		int t = (l + r) / 2;
		rep(k, 4) {
			if (k & 1) {
				rep(i, h)for (int j = 0; w - j - 1 > j; j++)
					swap(a[i][j], a[i][w - j - 1]);
			}
			else {
				rep(i, w)for (int j = 0; h - j - 1 > j; j++)
					swap(a[j][i], a[h - j - 1][i]);
			}
			if (ok(t)) {
				r = t; goto g;
			}
		}
		l = t + 1;
	g:;
	}
	printf("%d\n", l);
}

Measured memory_bytes: 18820
#include<iostream>
#include<algorithm>
#include<vector>
#include<string>
using namespace std;
#define LL long long
string S;
int main() {
	cin >> S;
	int N = S.size();
	if (S[N - 1] != '0'|| S[0] != '1') {
		cout << -1 << endl;
		return 0;
	}
	bool flag = true;
	for (int i = 0; i < N; i++){
		if (S[i] == '1')flag = false;
	}
	if (flag) {
		cout << -1 << endl;
		return 0;
	}
	for (int i = 0; i < N / 2; i++) {
		if (S[i] != S[N - i - 2]) {
			cout << -1 << endl;
			return 0;
		}
	}
	int root = 1;
	int node = 2;
	for (int i = 0; i < N - 1; i++) {
		if (S[i] == '1') {
			cout << root << " " << node << endl;
			root = node;
		}
		else {
			cout << root << " " << node << endl;
		}
		node++;
	}
	return 0;
}


Measured memory_bytes: 1664
# -*- coding: utf-8 -*-
import bisect
import heapq
import math
import random
from collections import Counter, defaultdict, deque
from decimal import ROUND_CEILING, ROUND_HALF_UP, Decimal
from fractions import Fraction
from functools import lru_cache, reduce
from itertools import combinations, combinations_with_replacement, product, permutations, accumulate
from operator import add, mul, sub, itemgetter, attrgetter


import sys
# sys.setrecursionlimit(10**6)
# readline = sys.stdin.buffer.readline
readline = sys.stdin.readline

INF = 1 << 60


def read_int():
    return int(readline())


def read_int_n():
    return list(map(int, readline().split()))


def read_float():
    return float(readline())


def read_float_n():
    return list(map(float, readline().split()))


def read_str():
    return readline().strip()


def read_str_n():
    return readline().strip().split()


def ep(*args):
    print(*args, file=sys.stderr)


def mt(f):
    import time

    def wrap(*args, **kwargs):
        s = time.perf_counter()
        ret = f(*args, **kwargs)
        e = time.perf_counter()

        ep(e - s, 'sec')
        return ret

    return wrap


class Mod:
    def __init__(self, m):
        self.m = m

    def add(self, a, b):
        return (a + b) % self.m

    def sub(self, a, b):
        return (a - b) % self.m

    def mul(self, a, b):
        return ((a % self.m) * (b % self.m)) % self.m

    def div(self, a, b):
        return self.mul(a, pow(b, self.m-2, self.m))

    def pow(self, a, b):
        return pow(a, b, self.m)


@mt
def slv(S):
    M = 10**9+7

    @lru_cache(maxsize=None)
    def f(n):
        if n == 0:
            return 1
        r = 0
        for v in range(3, n+1):
            r += f(n-v)
            r %= M
        return r

    return f(S)

def main():
    S = read_int()
    print(slv(S))


if __name__ == '__main__':
    main()


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

void Main()
{
  int n; cin >> n;
  vector<int> v(n);
  vector<int> odds(100000);
  vector<int> evens(100000);
  rep(i,n) {
    cin >> v[i]; v[i]--;
    if (i%2==0) odds[v[i]]++;
    else evens[v[i]]++;
  }
  int oddmax = 0;
  int evenmax = 0;
  int oddsecondmax = 0, evensecondmax = 0;
  int oddnum, evennum;
  rep(i,100000){
    if (oddmax < odds[i]){
      oddsecondmax = oddmax;
      oddmax = max(oddmax, odds[i]);
      oddnum = i;
    } else oddsecondmax = max(oddsecondmax, odds[i]);
    if (evenmax < evens[i]) {
      evensecondmax = evenmax;
      evenmax = max(evenmax, evens[i]);
      evennum = i;
    } else evensecondmax = max(evensecondmax, evens[i]);
  }
  //cout << oddmax << "," << evenmax << "," << oddsecondmax << "," << evensecondmax << endl;
  if (oddnum != evennum) cout << n-oddmax-evenmax << endl;
  else {
    cout << min(n-evenmax-oddsecondmax, n-oddmax-evensecondmax) << endl;
  }
}

int main()
{
  cin.tie(nullptr);
  ios_base::sync_with_stdio(false);
  cout << fixed << setprecision(20);
  Main();
  return 0;
}


Measured memory_bytes: 1408
#include <bits/stdc++.h>
//----***やべーやつら***----
using namespace std;
#define int long long

//----***型定義***----
using ll = long long;
using P = pair<int,int>;

//----***Like a Pythonista***----
#define REP(ii,jj,nn) for (ll ii=jj;ii<(nn);ii++)
#define RREP(ii,nn,jj) for (ll ii = nn; jj<ii;ii--)
#define each(i,...) for (auto&& i:__VA_ARGS__)
#define ALL(vec) (vec).begin(),(vec).end()
#define sum(...) accumulate(ALL(__VA_ARGS__),0LL)
#define dsum(...) accumulate(ALL(__VA_ARGS__),0.0)
#define vec(type,name,...) vector<type> name(__VA_ARGS__)
template<class T> inline auto max(const T& a){ return *max_element(ALL(a)); }
template<class T> inline auto min(const T& a){ return *min_element(ALL(a)); }
inline ll gcd(ll a,ll b){if(b == 0) return a;return  gcd(b,a%b);}
inline ll lcm(ll a,ll b){ll g = gcd(a,b);return a / g * b;}

//----***定数***----
#define MOD 1000000007
#define INF 100000000000000000
#define EPS 1e-9
const vector<vector<int>> DXY={{-1,0},{1,0},{0,-1},{0,1}};

//----***パーツ***----
#define fi first
#define se second
#define pb push_back
#define re return
#define br break

//----***入出力***---
void print() { std::cout << "\n"; }
template <class T>void print(const T &x) {std::cout << x<<"\n";}
template <class T, class... Args>void print(const T &x, const Args &... args) {std::cout << x << " ";print(args...);}
#define debug(var)  do{std::cerr << #var << " ↓ "<<"\n";view(var);}while(0);
#define dbg cerr<<"🥺🥺🥺🥺🥺🥺"<<endl;
template<typename T> void view(T e){std::cout << e << std::endl;}
template<typename T> void view(const std::vector<T>& v){for(const auto& e : v){ std::cout << e << " "; } std::cout << std::endl;}
template<typename T> void view(const std::vector<std::vector<T> >& vv){ for(const auto& v : vv){ view(v); } }

//----***初期時読み込み***----
struct initial{initial(){cin.tie(0); ios::sync_with_stdio(0); cout<<fixed<<setprecision(15);};}initial_;


signed main(){
  ll a,b,c;cin>>a>>b>>c;
  string ans;
  if(c<=a+b){
    print("No");
    re 0;
  }
  if(4*a*b<(c-a-b)*(c-a-b)){
    print("Yes");
  }
  else{
    print("No");
  }

}


Measured memory_bytes: 256
# https://beta.atcoder.jp/contests/arc082/submissions/1566776

n = gets.chomp.to_i

x = []
y = []

n.times do
  a, b = gets.chomp.split(" ").map(&:to_i)
  x << a
  y << b
end

md = 998244353

maxN = 201
pow2 = Array.new(maxN)
pow2[0] = 0
pow2[1] = 1

(2...maxN).each do |i|
  pow2[i] = (pow2[i - 1] * 2 + 1) % md
end

def line?(ix, iy, jx, jy, kx, ky)
  x1 = ix - jx
  y1 = iy - jy
  x2 = ix - kx
  y2 = iy - ky
  return (y1 * x2) == (y2 * x1)
end

ans = 0

(0...n).each do |i|
  ((i + 1)...n).each do |j|
    cnt1 = 0
    cnt2 = 0
    ((j + 1)...n).each do |k|
      cnt1 += 1
      if line?(x[i], y[i], x[j], y[j], x[k], y[k])
        cnt2 += 1
      end
    end

    ans += pow2[cnt1]
    ans -= pow2[cnt2]
    ans %= md
    ans += md
    ans %= md
  end
end
puts ans




Measured memory_bytes: 1788
#include <numeric>
#include <bits/stdc++.h>
#include <utility>
#include <iostream>
#include <algorithm>
#include <vector>
#include <cmath>
#include <math.h>
#include <string>
#define ll long long
#define ull unsigned long long
#define make(type,x) type x; cin>>x
#define make2(type,x,y) type x,y; cin>>x>>y
#define fr(x,y) for(long long x=0;x<y;x++)
#define makevec(x,y,n) vector <x> y(n); for(ll i=0;i<n;i++) cin>>y[i]
#define M (ll)1000000007
#define MM (ll) 1e8
#define INF (ll) 1e18

# define IOS ios_base::sync_with_stdio(false); cin.tie(NULL)


using namespace std;


template <typename T>
T modpow(T base, T exp, T modulus) {
  base %= modulus;
  T result = 1;
  while (exp > 0) {
    if (exp & 1) result = (result * base) % modulus;
    base = (base * base) % modulus;
    exp >>= 1;
  }
  return result;
}
bool sortbysec(const ll &a, const ll &b){
    return abs(a)>abs(b);
}

struct cmp {
	bool operator() (const pair<int, int> &a, const pair<int, int> &b) const {
		int lena = a.second - a.first + 1;
		int lenb = b.second - b.first + 1;
		if (lena == lenb) return a.first < b.first;
		return lena > lenb;
	}
};


struct c_h {
    size_t operator()(uint64_t x) const {
        static const uint64_t FIXED_RANDOM = chrono::steady_clock::now().time_since_epoch().count();
        x ^= FIXED_RANDOM;
        return x ^ (x >> 16);
    }
};

ll calcpow(ll x, ll y)
{
    ll temp;
    if(y == 0)
        return 1;
    temp = calcpow(x, y / 2);
    if (y % 2 == 0)
        return temp * temp;
    else
    {
        if(y > 0)
            return x * temp * temp;
        else
            return (temp * temp) / x;
    }
}
ll gcd(ll a, ll b){
    if(b==0) return a;
    return gcd(b,a%b);

}
ll egcd(ll a, ll b, ll &x,ll &y){
    if(b==0){
        x=1;
        y=0;
        return a;
    }
    ll x1;
    ll y1;
    ll g=egcd(b,a%b,x1,y1);
    x=y1;
    y=x1-y1*(a/b);
    return g;
}


bool isprime(ll a){
bool flag=1;
for(ll i=2;i*i<=a;i++){
    if(a%i==0) {flag=0; break;}
}
return flag;
}

ll dx8[8]={1,0,-1,0,1,-1,1,-1};
ll dy8[8]={0,1,0,-1,1,-1,-1,1};
ll dx4[4]={0,0,1,-1};
ll dy4[4]={1,-1,0,0};


int main(){
    IOS;
    make(ll,n);
    ll mx1=-INF; ll mn1=INF;
    ll mx=-INF; ll mn=INF;
    fr(i,n){
        make2(ll,x,y);
        mx=(max(x+y,mx)); mn=(min(mn,x+y));
        mx1=max(x-y,mx1); mn1=min(mn1,x-y);
    }
    cout<<max(mx1-mn1,mx-mn)<<endl;




    return 0;
}


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

int main() {

	int k, s; cin >> k >> s;
	int ans = 0;
	for (int x = 0; x <= k; x++) {
		for (int y = 0; y <= k; y++) {
			int tmp = s - x - y;
			if (0 <= tmp && tmp <= k) ans++;
		}
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 3596
#include <stdio.h>
int main(void)
{
int i;
int a[26] = {0};
char x[1201];
while ( scanf("%s", x) != EOF){
for (i=0; x[i]!='\0'; i++) {
if ('a'<=x[i] && x[i]<='z') {
a[x[i]-'a']++;
}
if ('A'<=x[i] && x[i]<='Z') {
a[x[i]-'A']++;
}
}
}
for(i=0; i<26; i++){
printf("%c : %d\n", i+'a', a[i]);
}
return 0;
}


Measured memory_bytes: 2108
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
int64_t MOD=1000000007;
const long long INF = 1LL<<60;

int main() {
  int64_t N; cin>>N;
  vector<int64_t> S(60);
  rep(i,N){
    int64_t a; cin>>a;
    bitset<60> t(a);
    rep(j,60){
      if(t.test(j)){
        S.at(59-j)++;
      }
    }
  }
  reverse(S.begin(),S.end());
  int64_t ans=0,k=1;
  rep(i,60){
    auto temp=(k*S.at(i))%MOD;
    ans+=temp*(N-S.at(i));
    ans%=MOD;
    k*=2;
    k%=MOD;
  }
  cout<<ans;
}


Measured memory_bytes: 3652
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/detail/standard_policies.hpp>
using namespace __gnu_pbds;
using namespace std;


#define LETS_GET_SCHWIFTY ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);  
#define ff              first
#define ss              second
#define int             long long
#define ll              long long
#define pb              push_back
#define pii             pair<int,int>
#define vi              vector<int>
#define mii             map<int,int>
#define pqb             priority_queue<int>
#define pqs             priority_queue<int,vi,greater<int> >
#define setbits(x)      __builtin_popcountll(x)
#define zerobits(x)      __builtin_ctzll(x)
#define mod             1000000007
#define inf             1e18
#define ps(x,y)         fixed<<setprecision(y)<<x
#define vpii            vector<pair<int,int> >
#define all(x)          x.begin(),x.end()
#define matrixprint(arr,a,b,c,d) for(int i=a;i<=c;i++){for(int j=b;j<=d;j++){cout<<arr[i][j]<<" ";}cout<<"\n";}
#define show(arr,x,y)   for(int i=x;i<=y;i++){cout<<arr[i]<<" ";}cout<<"\n"
#define sz(x)           (int)x.size()
#define db(x)           cout<<x<<"\n";

const int N = 2e5 + 5;

#define TRACE
#ifdef TRACE
#define deb(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1) {
    cout << name << " : " << arg1 << std::endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args) {
    const char* comma = strchr(names + 1, ','); cout.write(names, comma - names) << " : " << arg1 << " | "; __f(comma + 1, args...);
}
#else
#define deb(...)
#endif

	
//////////////////////////////code//////////////////////////////

int n;

vector<vi> arr;

int dp[25][(1<<21)];

int sol(int i,int mask)
{
    if(i==n)
    return 1;
    
    int &ans = dp[i][mask];
    
    if(ans!=-1)
    return ans;
    
    int a = 0;
    
    for(int k=0;k<n;k++)
    {
        if(arr[i][k] && (mask & (1<<k))==0)
        {
            a = (a + sol(i+1,(mask | (1<<k))))%mod;
        }
    }
    
    return ans = a;
}
void solve()
{
  //  cout << "-------------------" << "\n";
    
    cin>>n;
    
    arr = vector<vi>(n+1,vi(n+1));
    
    for(int i=0;i<n;i++)
     for(int j=0;j<n;j++) 
      cin>>arr[i][j];
      
      memset(dp,-1,sizeof(dp));
      
    cout<<sol(0,0)<<'\n';
    

  //  cout << "-------------------" << "\n";

}

int32_t main()
{

    LETS_GET_SCHWIFTY;

    int t = 1;
    //cin >> t;

    while (t--)
        solve();

}

// check out for following mistakes-
// if using pb operation on vector and then trying to access index..check if sizeof that vec could remain 0 only
// is using prime sieve make sure it fits
// when using factorial template or combinatorics make sure that you edit fillfac fun values and array values


Measured memory_bytes: 413260
#include <map>
#include <set>
#include <list>
#include <cstdio>
#include <cmath>
#include <deque>
#include <stack>
#include <bitset>
#include <cctype>
#include <string>
#include <vector>
#include <cstdlib>
#include <cstring>
#include <iomanip>
#include <sstream>
#include <iostream>
#include <algorithm>
#include <functional>

using namespace std;

#define fr first
#define sc second
#define mp make_pair
#define foreach(c, it) for(typeof(c) it = (c).begin(); it != (c).end(); it++)

typedef long long int64;
typedef pair< int, int > iP;
typedef pair< iP, int > iiP;

const int INF = 2 << 28;
const double EPS = 1e-10;

int main() {
    
    int N, M, s, t, e;
    cin >> N >> M;
    vector< vector< pair< int , int > > > cnt(N + 1);
    while(scanf("%d %d %d", &s, &t, &e), e)
        cnt[s].push_back(mp(t, e));
    int L;
    cin >> L;
    while(L--) {
        vector< int > sum(N + 1, 0), c(M);
        for(int i = 0; i < M; i++) scanf("%d", &c[i]);
        for(int i = 1; i <= N; i++) {
            for(int j = 0; j < cnt[i].size(); j++) {
                sum[i] += c[cnt[i][j].fr - 1] * cnt[i][j].sc;
            }
        }
        for(int i = 1; i <= N; i++) {
            printf("%d%c", sum[i], (i != N ? ' ' : '\n'));
        }
    }
}

Measured memory_bytes: 2280
#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <fstream>
#include <climits>
#include <cmath>
#include <string>
#include <vector>
#include <algorithm>
#include <queue>
#include <map>
#include <functional>
#include <set>
#include <numeric>
#include <stack>
#include <utility>
#include <time.h>
#include <iterator>
#include <random>
//#include "util.h"

using namespace std;
typedef unsigned uint;
typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vint;
typedef vector<ll> vll;
typedef vector<bool> vbool;
typedef vector<string> vstr;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

//呪文
template <typename _KTy, typename _Ty> ostream& operator << (ostream& ostr, const pair<_KTy, _Ty>& m) { cout << "{" << m.first << ", " << m.second << "}"; return ostr; }
template <typename _KTy, typename _Ty> ostream& operator << (ostream& ostr, const map<_KTy, _Ty>& m) { if (m.empty()) { cout << "{ }"; return ostr; } cout << "{" << *m.begin(); for (auto itr = ++m.begin(); itr != m.end(); itr++) { cout << ", " << *itr; } cout << "}"; return ostr; }
template <typename _Ty> ostream& operator << (ostream& ostr, const vector<_Ty>& v) { if (v.empty()) { cout << "{ }"; return ostr; }	cout << "{" << v.front(); for (auto itr = ++v.begin(); itr != v.end(); itr++) { cout << ", " << *itr; }	cout << "}"; return ostr; }
template <typename _Ty> ostream& operator << (ostream& ostr, const set<_Ty>& s) { if (s.empty()) { cout << "{ }"; return ostr; } cout << "{" << *(s.begin()); for (auto itr = ++s.begin(); itr != s.end(); itr++) { cout << ", " << *itr; }	cout << "}"; return ostr; }
template <typename _KTy, typename _Ty> istream& operator >> (istream& istr, pair<_KTy, _Ty>& m) { cin >> m.first >> m.second; return istr; }
template <typename _Ty> istream& operator >> (istream& istr, vector<_Ty>& v) { for (size_t i = 0; i < v.size(); i++) cin >> v[i]; return istr; }
ll modpow(ll n, ll p, ll m) { ll result = 1; while (p > 0) { if (p & 1) result = (result * n) % m; p >>= 1; n = (n * n) % m; } return result; }
template <typename _Ty> _Ty ipow(_Ty x, _Ty n) { _Ty ret = _Ty(1); for (_Ty i = _Ty(0); i < n; i++) ret *= x; return ret; }
#define PI 3.14159265358979323846
#define EPS 1e-8
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define all(x) (x).begin(), (x).end()
#define fake false




int main()
{
	//clock_t start, end;
	//start = clock();

	int n;
	cin >> n;

	vint vx(n), vy(n);
	cin >> vx >> vy;

	double L[4] = {}; 
	double LI = 0;
	for (int i = 0; i < n; i++) {
		double x = vx[i], y = vy[i];

		double ab = abs(x - y);
		for (int p = 1; p <= 3; p++) {
			L[p] += pow(ab, p);
		}
		LI = max(LI, ab);
	}
	for (int p = 1; p <= 3; p++) {
		L[p] = pow(L[p], 1.0 / p);
		printf("%.10f\n", L[p]);
	}
	printf("%.10f\n", LI);
	
	//end = clock();
	//printf("%d msec.\n", end - start);

	return 0;
}



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

using ll    = long long;
using ull   = unsigned long long;
using veci  = vector<int>;
using vecll = vector<ll>;
#define EPS (1e-7)
#define INF (1e9)
#define PI  (acos(-1))
#define FOR(i,a,b) for(int i = (a);i < (b); ++i)
#define REP(i,n) for(int i= 0;i<(int)(n);++i)
#define pb push_back

veci enum_div(int n){
	veci ret;
	ret.pb(1);
	for(int i=1;i*i<n;i++){
		if(n%i==0){
			ret.pb(i);
			if(i != n/i){ret.pb(n/i);}
		}
	}
	ret.pb(n);
	return ret;
}
int gcb(int a,int b){return ((b == 0)? a : gcb(b,a%b));}
int gcd(int a,int b){return (a*b) / gcb(a,b);}

int main(){
    int a,b,c;
    cin >> c;
    if(c == 2){
        cin >> a >> b;
        cout << a + b << endl;
        return 0;
    }else{
        cout << "Hello World" << endl;
        return 0;
    }

	return 0;
}



Measured memory_bytes: 256
#include<stdio.h>
    int main(){
      int a,b,c,d,e;
      scanf("%d %d %d %d",&a,&b,&c,&d);
      for(int i=0; i<a; i++){
        scanf("%d",&e);
        if(c<e){c=e;}
      }
      for(int i=0; i<b; i++){
        scanf("%d",&e);
        if(e<d){d=e;}
      }
      printf(c<d?"No War":"War");
      return 0;}

Measured memory_bytes: 128
#include <stdio.h>
#include <iostream>
#include <string>
#include <algorithm>
#include <map>
#include <math.h>
#include <iomanip>
#include <vector>
#include <queue>
#include <functional>
#include <random>
#include <time.h>
#include <cmath>
#include <cstdio>
#include <complex>
using namespace std;
typedef long long int ll;
typedef pair<ll, ll> P;
int main() {
	ll a, b;
	cin >> a >> b;
	ll n = b - a;
	cout << (n)*(n + 1) / 2 - b << endl;
	return 0;
}

Measured memory_bytes: 256
a = [1,3,5,7,8,10,12]
b = [4,6,9,11]

x,y = map(int,(input().split()))
cou1 = 0
cou2 = 0

for i in a:
    if i==x or i==y:
        cou1 += 1
for i in b:
    if i==x or i==y:
        cou2 += 1

if cou1>1 or cou2>1:
    print("Yes")
else:
    print("No")

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

int main() {
  ll s, c;
  cin >> s >> c;

  if (s > c) {
    cout << c / 2 << endl;
    return 0;
  } else if (s == c) {
    cout << c / 2 << endl;
    return 0;
  }
  ll cnt = s;
  ll n   = c - (s * 2);
  cnt += (n / 4);
  cout << cnt << endl;
}

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


using namespace std;
const long long INF = 1LL <<60;

int main(void){
  long long x,n,tmp;
  long long arr[102];
  long res_v=200,res_i=0;
  long long i,j,k;
  long long flg=0;
  cin>>x>>n;
  
  for(i=0;i<102;i++){
    arr[i]=0;
  }
  
  for(i=0;i<n;i++){
    cin>>tmp;
    arr[tmp]=1;
  }
  
  for(i=0;i<102;i++){
    if(arr[i]==0 && res_v>abs(x-i)){
      res_v=abs(x-i);
      res_i=i;
    }
  }
  
  cout<<res_i<<endl;
      
  
  return 0;
  
}    

Measured memory_bytes: 3636
import java.io.*;
import java.util.*;
import java.math.*;

public class Main {
	public void run() {
		Scanner sc = new Scanner(System.in);

		boolean[] p = new boolean[300000];
		boolean[] ms = new boolean[300000];
		for (int i = 0; i < ms.length; i++) {
			ms[i] = ((i % 7 == 1) || (i % 7 == 6));
			p[i] = ms[i];
		}
		for (int i = 2; i < ms.length; i++) {
			if (p[i]) {
				for (int j = i + i; j < ms.length; j += i) {
					p[j] = false;
				}
			}
		}

		for (;;) {
			int n = sc.nextInt();
			if (n == 1) {
				break;
			}
			System.out.print(n + ":");
			for (int i = 2; i <= n; i++) {
				if (!p[i])
					continue;
				if (n % i == 0) {
					System.out.print(" " + i);
				}
			}
			System.out.println();
		}

	}

	public static void main(String[] Aregs) {
		Main a = new Main();
		a.run();
	}
}

Measured memory_bytes: 13000
#include <bits/stdc++.h>
using namespace std;
 
#define forn(i,n) for(int i=0;i<(int)(n);i++)
#define si(c) ((int)(c).size())
#define forsn(i,s,n) for(int i = (int)(s); i<((int)n); i++)
#define dforsn(i,s,n) for(int i = (int)(n)-1; i>=((int)s); i--)
#define all(c) (c).begin(), (c).end()
#define D(a) cerr << #a << "=" << a << endl;
#define pb push_back
#define eb emplace_back
#define mp make_pair
 
typedef long long int ll;
typedef vector<int> vi;
typedef pair<int,int> pii;
 
void bad(){
    puts("-1");
    exit(0);
}

int main() {
    ios_base::sync_with_stdio(0); cin.tie(0);
    int n; cin >> n;
    vi a(n+1); for (auto &x : a) cin >> x;
    vector<ll> suf(n+2);
    dforsn(i,0,n+1) suf[i] = suf[i+1] + a[i];

    ll have = 1, ans = 0;
    forn(i,n+1) {
        ans += have;
        have -= a[i];
        if (have < 0) bad();
        ll nxt = min(2*have, suf[i+1]);
        if (nxt < have) bad();
        else have = nxt;
    }
    cout << ans;
    return 0;
}


Measured memory_bytes: 4660
#include<bits/stdc++.h>
using namespace std;
int main(){
    cout << fixed << setprecision(10);
    int n;cin>>n;
    double x[n],y[n];
    for(int i=0;i<n;i++){
        cin>>x[i]>>y[i];
    }
    vector<int> a(n);
    for(int i=0;i<n;i++)a[i]=i;
    double res=0;
    double per=1;
    for(int i=1;i<=n;i++)per*=i;
    do{
        for(int i=0;i<n-1;i++){
            int now=a[i],next=a[i+1];
            double ren=(x[now]-x[next])*(x[now]-x[next])+(y[now]-y[next])*(y[now]-y[next]);
            ren=sqrt(ren);
            res+=ren;
        }
    }while(next_permutation(a.begin(),a.end()));
    res/=per;
    cout<<res<<endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main() {
	cin.tie(0); cin.sync_with_stdio(false);
	int q;
	cin >> q;
	multiset<int> lft, rgt;
	long long ret = 0;
	while (q--) {
		int c;
		cin >> c;
		if (c == 1) {
			long long a, b;
			cin >> a >> b;
			ret += b;
			lft.insert(a);
			rgt.insert(a);
			long long l = *lft.rbegin(); lft.erase(prev(lft.end()), lft.end());
			long long r = *rgt.begin(); rgt.erase(rgt.begin(), next(rgt.begin()));
			long long d = l - r;
			if (d > 0) {
				ret += d;
				swap(l, r);
			}
			lft.insert(l);
			rgt.insert(r);
		} else {
			cout << *lft.rbegin() << " ";
			cout << ret << endl;
		}
	}
	return 0;
}

Measured memory_bytes: 19072
//#include<bits/stdc++.h>
#include <iostream>
#include <cstdio>
#include <cstring>
#include <string>
#include <vector>
#include <queue>
#include <map>
#include <algorithm>
#include <utility>
#include <climits>
#define REP(i, n) for(int i = 0; i < n; ++i)
#define FOR(i, a, b) for(int i = a; i < b; ++i)
#define F first
#define S second
#define OUT(x) cout << x << "\n"
using namespace std;
using point = pair< int,int >;
using ll = long long;

int main() {
    int a[3];
    cin >> a[0] >> a[1] >> a[2];
    sort(a, a + 3);

    OUT(a[0] + a[1]);
    return 0;
}



Measured memory_bytes: 256
s = int(input())
MOD = 10 ** 9 + 7
ans = 0
fact = [0] * 10000
fact[0], fact[1] = 1, 1
for i in range(2, 10000):
    fact[i] = (fact[i-1] * i) % MOD

def f(n, r):
    return fact[n] * pow(fact[n-r], MOD-2, MOD) * pow(fact[r], MOD-2, MOD)

for i in range(1, s//3+1):
    if i == 1:
        ans += 1
    else:
        m = s - i * 3
        ans += f(m+i-1, m)
        ans %= MOD
print(ans%MOD)

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

N = int(input())
pN = list(map(int, input().split()))

same = [False] * N
for i in range(N):
    if i+1 == pN[i]:
        same[i] = True
# 終端処理用に追加
same.append(False)

cnt = 0
for i in range(1, N+1):
    if same[i] and same[i-1]:
        same[i] = False
        same[i-1] = False
        cnt += 1
    elif not same[i] and same[i-1]:
        same[i-1] = False
        cnt += 1
print(cnt)


Measured memory_bytes: 14008
#!/usr/bin/ruby
require 'mathn'
h={2=>[[2, 1]], 3=>[[3, 1]], 4=>[[2, 2]], 5=>[[5, 1]], 6=>[[2, 1], [3, 1]], 7=>[[7, 1]], 8=>[[2, 3]], 9=>[[3, 2]], 10=>[[2, 1], [5, 1]], 11=>[[11, 1]], 12=>[[2, 2], [3, 1]], 13=>[[13, 1]], 14=>[[2, 1], [7, 1]], 15=>[[3, 1], [5, 1]], 16=>[[2, 4]], 17=>[[17, 1]], 18=>[[2, 1], [3, 2]], 19=>[[19, 1]], 20=>[[2, 2], [5, 1]], 21=>[[3, 1], [7, 1]], 22=>[[2, 1], [11, 1]], 23=>[[23, 1]], 24=>[[2, 3], [3, 1]], 25=>[[5, 2]], 26=>[[2, 1], [13, 1]], 27=>[[3, 3]], 28=>[[2, 2], [7, 1]], 29=>[[29, 1]], 30=>[[2, 1], [3, 1], [5, 1]], 31=>[[31, 1]], 32=>[[2, 5]], 33=>[[3, 1], [11, 1]], 34=>[[2, 1], [17, 1]], 35=>[[5, 1], [7, 1]], 36=>[[2, 2], [3, 2]]}
while(l=gets.chomp)!="0 0"
	l=l.split
	n=l[0].to_i;m=l[1].to_i(n)
	p h[n].map{|a,b|
		z=m;r=0
		while z>0 do r+=(z=z.div(a)) end
		r.div(b)
	}.min
end

Measured memory_bytes: 3956
N,M = map(int, input().split())
ans = [0]*N
ac = 0
p = 0

for m in range(M):
    a,b = map(str, input().split())
    a = int(a) - 1

    if ans[a] != -1 and b == 'WA':
        ans[a] += 1
    if ans[a] != -1 and b == 'AC':
        ac += 1
        p += ans[a]
        ans[a] = -1

print(ac,p)

Measured memory_bytes: 9592
#include <iostream>
#include <vector>
#include <string>
#include <unordered_set>
#include <unordered_map>
#include <sstream>
#include <algorithm>
#include <cmath>
#include <map>
#include <set>
#include <numeric>
#include <iterator>

using namespace std;

namespace {

}

int main()
{
	int A = 0, B = 0;
	string S;

	cin >> A >> B;
	cin >> S;

	auto pos  = S.find('-');
	//split(S.begin(), S.end(), '_');

	if (pos == A) {
		auto pos2 = S.find('-', pos + 1);
		if (pos2 != string::npos) {
			cout << "No" << endl;
			return 0;
		}
		if (S.size() == A + B + 1
			&& pos == A)
		{
			cout << "Yes" << endl;
			return 0;
		}
	}
	
	cout << "No" << endl;

	return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
using namespace std;
#define INF 100000000

int N;
int t[20][20];
int dp[111111];
void bitDP();

int main(){
	while(cin >> N , N){
		for(int i=0;i<N;i++){
			for(int j=0;j<N+1;j++){
				cin >> t[i][j];
			}
			//cout << "C" << endl;
		}
		//cout << "B" << endl;
		bitDP();
		//cout << "A" << endl;
	}
}

void bitDP(){
	int leng = (1 << N);
	for(int i=0;i<leng+2;i++){
		dp[i] = INF;
	}
	dp[0] = 0;
	for(int i=0;i<leng;i++){
		if(dp[i] == INF) continue;
		for(int next=0;next<N;next++){
			if((i & (1 << next)) != 0) continue;
			int cost = t[next][0];
			for(int j=0;j<N;j++){
				if((i & (1 << j)) != 0){
					cost = min(cost,t[next][j+1]);
				}
			}
			int bit = (i | (1 << next));
			dp[bit] = min(dp[bit],dp[i]+cost);
		}
	}
	cout << dp[leng-1] << endl;
}

Measured memory_bytes: 1424
#include <stdio.h>

int ar[100001] = {0};
int br[100001] = {0};

int main()
{
    int t;
    scanf("%d", &t);
    int i, n, max=0, max2=0, idx=-1, idx2=-1, c[t+5], ans=0, ans2=0;
    for (i=0; i<t; i++)
    {
        scanf("%d", &c[i]);
        if(i%2)
            ar[c[i]]++;
        else
            br[c[i]]++;
    }
    for (i=0; i<t; i++)
    {
        if(ar[c[i]] > max)
        {
            max = ar[c[i]];
            idx = c[i];
        }
        if(br[c[i]] > max2)
        {
            max2 = br[c[i]];
            idx2 = c[i];
        }
    }

    if (idx != idx2)
        ans = ((t/2)-max)+((t/2)-max2);
    else
    {
       n = idx2;
       max2=0;
       for (i=0; i<t; i++)
        {
            if(c[i] == n)
                continue;
            if(br[c[i]] > max2)
            {
                max2 = br[c[i]];
                idx2 = c[i];
            }
        }
        ans = ((t/2)-max)+((t/2)-max2);
    }
    for (i=0; i<t; i++)
    {
        if(br[c[i]] > max)
        {
            max = br[c[i]];
            idx = c[i];
        }
        if(ar[c[i]] > max2)
        {
            max2 = ar[c[i]];
            idx2 = c[i];
        }
    }

    if (idx != idx2)
        ans2 = ((t/2)-max)+((t/2)-max2);
    else
    {
       n = idx2;
       max2=0;
       for (i=0; i<t; i++)
        {
            if(c[i] == n)
                continue;
            if(ar[c[i]] > max2)
            {
                max2 = ar[c[i]];
                idx2 = c[i];
            }
        }
        ans2 = ((t/2)-max)+((t/2)-max2);
    }
    if (ans < ans2)
    	printf("%d", ans);
    else
    	printf("%d", ans2);
    return 0;
}


Measured memory_bytes: 1280
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep1(i, n) for (int i = 1; i <= (int)(n); i++)
using P = pair<int,int>;
using pq = priority_queue<int>;
typedef long long ll;
typedef long double ld;

template <class T, class U>
bool contain(const std::basic_string<T>& s, const U& v)
{
	return s.find(v) != std::basic_string<T>::npos;
}

int  main()
{
	int n; cin >> n;
	vector <string> s(n);
	int min_len = INT_MAX;
	int m = 0;
	rep(i, n)
	{
		cin >> s[i];
		if (min_len > s[i].size())
		{
			min_len = s[i].size();
			m = i;
		}
	}
	string ans;
	rep(i, s[m].size())
	{
		int cnt = 0;
		rep(j, n)
		{
			if (contain(s[j], s[m][i]))
			{
				cnt++;
				if (j != m)
					s[j].erase(s[j].find(s[m][i]), 1);
			}
		}
		if (cnt == n)
			ans.push_back(s[m][i]);
	}
	sort(ans.begin(), ans.end());
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ll long long int
#define pb push_back
#define mp make_pair
#define deb(x) cout<< #x << " " << x << "\n";
#define MAX 9223372036854775807
#define MIN -9223372036854775807
#define PI 3.141592653589
#define setbits(n) __builtin_popcountll(n)
const ll mod=1e9+7;

const int N=1e5+1;
bool dp[N][2],vis[N][2];
vector<int> a(N);
ll n,k;

bool go(int left, int mov){
    if(left<0) return true;
    if(vis[left][mov]==true)
        return dp[left][mov];
    //cerr<<left<<"\n";
    bool win=false;
    for(int i=0;i<n;i++)
        win|=(!go(left-a[i],mov^1));
    vis[left][mov]=true;
    return dp[left][mov]=win;
}

int main() {
    
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    ll T=clock();
    
    cin>>n>>k;
    memset(vis,false,sizeof(vis));
    for(ll i=0;i<n;i++)
        cin>>a[i];
    if(go(k,0))
        cout<<"First";
    else
        cout<<"Second";

    

    cerr<<"\n\nTIME: "<<(double)(clock()-T)/CLOCKS_PER_SEC<<" sec\n";
    T = clock();
    return 0;
}

Measured memory_bytes: 10444
#include<iostream>
#include<math.h>
//#include<map>                                                                                                        
using namespace std;

int main()
{
    // 整数の入力                                                                                                      
    int N;
    cin >> N;

    // 出力                                                                                                            
    cout << pow(N,3) << endl;
    return 0;
}

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

int main(void){
  int a, b;
  cin >> a >> b;
  cout << 6-a-b << endl;
  return 0;
}

Measured memory_bytes: 3572
#include <iostream>
#include <iomanip>
#include <algorithm>
using namespace std;
#include <cstdio>
#include <tuple>
#include <string>
#include <vector> 
#include <set>
#include <string.h>
#include <map>
#include <cmath>
#include <deque>
using ll = long long;
using Graph = vector<vector<int>>;
#include <queue>
#include <stack>

int main(){
    
    string s;
    cin >> s;
    
    vector<ll> a(s.size() + 1,0LL);//0で初期化

    //左から
    for(int i=0;i < s.size();i++) if(s[i] =='<') a[i + 1] = max(a[i + 1],a[i]+1);

    //右から
    for(int i=s.size() -1;i >= 0;i--) if(s[i] =='>')a[i] = max(a[i],a[i+1]+1);
    
    ll sum =0LL;
    for(int i=0;i <= s.size();i++){
        sum += a[i];
        //cout <<a[i] << " ";

    }

    cout << sum << endl;

    return 0;
}

Measured memory_bytes: 4740
#include <bits/stdc++.h>
using namespace std;
typedef pair<int, int> P;
int N, M, Q;
vector<int> a, b, c, d;
long long ans;
long long res, res2;
vector<int> num;
long long dfs(int i, int u){
    long long t2 = 0;
    if(u == N){
        long long t = 0;
        for(int j = 0; j < Q; j++){
            if(num[b[j] -1] -  num[a[j] - 1] == c[j]) t += d[j];
        }
        return t;
    }
    num[u] = i;
    for(int j = 0; j  + i <= M; j++){
        t2 = max(t2, dfs(i+j, u + 1));
    }
    return t2;
}
int main(){
    cin >> N >> M >> Q;
    a.resize(Q);
    b.resize(Q);
    c.resize(Q);
    d.resize(Q);
    for(int i = 0; i < Q; i++) {
        cin >> a[i] >> b[i] >> c[i] >> d[i];
    }
    ans = 0;
    for(int i = 1; i <= M; i++){
        num.resize(N);
        ans = max(ans, dfs(i, 0));
    }
    cout << ans << endl;
}

Measured memory_bytes: 3628
def log_2(n):
    t = 0
    while n:
        if n % 2 == 1:
            break
        t += 1
        n //= 2
    return t


def solve(A, B, C)->int:

    s = A+B+C
    odd = min(log_2(s-A), log_2(s-B), log_2(s-C))
    even = min(log_2(s+A), log_2(s+B), log_2(s+C))

    if odd == even:
        return odd
    else:
        return odd+1


A, B, C = map(int, input().split())

ans = 0
if A % 2 == 1 or B % 2 == 1 or C % 2 == 1:
    ans = 0
elif A == B == C:
    ans = -1
else:
    ans = solve(A, B, C)
print(ans)


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

const int N_MAX = 1e5;
vector<bool> prime_list(N_MAX + 1, true);

void prime_l(int N) {
  
  prime_list[0] = false;
  prime_list[1] = false;
  prime_list[2] = true;
  for(int i = 3; i <= N; i++){
    for(int j = 2; j <= sqrt(i) + 1; j ++){
      if(i % j == 0) {
         prime_list[i] = false;
        break;
      }
    }
  }
}

int main(){
  prime_l(N_MAX);
  vector<int> res2017(N_MAX+1, 0);
  for(int i = 3; i <= N_MAX; i++){
    if(prime_list[i] && prime_list[(i + 1) / 2]){
      res2017[i] = res2017[i-1]+1;
    }else{
      res2017[i] = res2017[i-1];
    }
  }
  
  int Q; cin >> Q;
  for(int i = 0; i < Q; i++){
    int l, r; cin >> l >> r;
    cout << res2017[r] - res2017[l-1] << endl;
  }
  
}

Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for (int i=0; i<(int)(n); i++)
#define all(vec) vec.begin(),vec.end()
#define MOD 1000000007
#define int long long

signed main(){
    int a,b,c,d;cin>>a>>b>>c>>d;
    if(d>=abs(a-c)||(d>=abs(a-b)&&d>=abs(b-c)))cout<<"Yes"<<endl;
    else cout<<"No"<<endl;
}

Measured memory_bytes: 256
/// 一开始题意就理解错了
#include <bits/stdc++.h>
using namespace std;
const int maxn = 100000 + 10,MOD = 1e9 + 7;
typedef long long LL;
int cnt[26];
char str[maxn];
LL mut(LL a,LL b){
	return (a%MOD)*(b%MOD) %MOD;
}
int main(){
	int N;
	scanf("%d%s",&N,str);
	for(int i = 0 ; i < N; ++i) ++cnt[str[i] - 'a'];
	LL ans = 1;
	for(int i = 0 ; i < 26 ; ++i){
		ans = mut(cnt[i]+1,ans);
	}
	cout<<ans-1<<endl;
	return 0;
}

Measured memory_bytes: 384
package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
)

func configure(scanner *bufio.Scanner) {
	scanner.Split(bufio.ScanWords)
	scanner.Buffer(make([]byte, 1000005), 1000005)
}
func getNextString(scanner *bufio.Scanner) string {
	scanned := scanner.Scan()
	if !scanned {
		panic("scan failed")
	}
	return scanner.Text()
}
func getNextInt(scanner *bufio.Scanner) int {
	i, _ := strconv.Atoi(getNextString(scanner))
	return i
}
func getNextInt64(scanner *bufio.Scanner) int64 {
	i, _ := strconv.ParseInt(getNextString(scanner), 10, 64)
	return i
}
func getNextFloat64(scanner *bufio.Scanner) float64 {
	i, _ := strconv.ParseFloat(getNextString(scanner), 64)
	return i
}
func main() {
	fp := os.Stdin
	wfp := os.Stdout
	extra := 0
	if os.Getenv("I") == "IronMan" {
		fp, _ = os.Open(os.Getenv("END_GAME"))
		extra = 100
	}
	scanner := bufio.NewScanner(fp)
	configure(scanner)
	writer := bufio.NewWriter(wfp)
	defer func() {
		r := recover()
		if r != nil {
			fmt.Fprintln(writer, r)
		}
		writer.Flush()
	}()
	solve(scanner, writer)
	for i := 0; i < extra; i++ {
		fmt.Fprintln(writer, "-----------------------------------")
		solve(scanner, writer)
	}
}
func solve(scanner *bufio.Scanner, writer *bufio.Writer) {
	n := getNextInt(scanner)
	k := getNextInt(scanner)

	var ans mint
	ans = mint(k)
	for i := 1; i < n; i++ {
		ans.mulAs(mint(k - i))
	}
	fmt.Fprintln(writer, ans)
}

type mint int64

func (mt mint) mod() mint {
	m := mint(1e9 + 7)
	mt %= m
	if mt < 0 {
		return mt + m
	}
	return mt
}
func (mt mint) inv() mint {
	return mt.pow(mint(0).sub(2))
}
func (mt mint) pow(n mint) mint {
	p := mint(1)
	for n > 0 {
		if n%2 == 1 {
			p.mulAs(mt)
		}
		mt.mulAs(mt)
		n >>= 1
	}
	return p
}
func (mt mint) add(x mint) mint {
	return (mt + x).mod()
}
func (mt mint) sub(x mint) mint {
	return (mt - x).mod()
}
func (mt mint) mul(x mint) mint {
	return (mt * x).mod()
}
func (mt mint) div(x mint) mint {
	return mt.mul(x.inv())
}
func (mt *mint) addAs(x mint) *mint {
	*mt = mt.add(x)
	return mt
}
func (mt *mint) subAs(x mint) *mint {
	*mt = mt.sub(x)
	return mt
}
func (mt *mint) mulAs(x mint) *mint {
	*mt = mt.mul(x)
	return mt
}
func (mt *mint) divAs(x mint) *mint {
	*mt = mt.div(x)
	return mt
}



Measured memory_bytes: 1232