akhauriyash/Code-Regression huggingface dataset:
using System;
using System.Numerics;

namespace B
{
    class Program
    {
        static void Main(string[] args)
        {
            Console.ReadLine();
            String[] strAs = Console.ReadLine().Split(' ');
            BigInteger  ans = 1;
            for(int i = 0; i < strAs.Length; i++) {
                if(strAs[i] == "0") {
                    Console.WriteLine("0");
                    return;
                }
            }

            for(int i = 0; i < strAs.Length; i++) {
                ans = ans * BigInteger .Parse(strAs[i]);
                if(ans > 1000000000000000000) {
                    Console.WriteLine("-1");
                    return;
                }
            }
            
            Console.WriteLine(ans.ToString());
        }
    }
}


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

#define rep(i,n) for(int i=0;i<(n);++i)
#define loop(i,b,n) for(int i=b;i<(n);++i)
#define each(e,v) for(auto &&e : v)

#define all(v) (v).begin(),(v).end()
#define sz(v) (int)v.size()

using uint = unsigned int;
using ll = long long;
using ull = unsigned long long;

const int INF = 1001001001;
const ll LINF = 1001001001001001001ll;
const double EPS = 1e-9;
const ll MOD = 1000000007;

template<typename A,typename B> inline void chmin(A &a,B b){ if(a>b) a=b; }
template<typename A,typename B> inline void chmax(A &a,B b){ if(a<b) a=b; }
template <typename T> inline void print(const T& x) { cout << x << endl; }

int count_black(int h, int mh, int w, int mw, const vector<string> &f){
    int count = 0;
    for(int i=0; i<h; ++i){
        if(((1<<i) & mh) == 0) continue;
        for(int j=0; j<w; ++j){
            if(((1<<j) & mw) == 0) continue;
            if(f[i][j] == '#') ++count;
        }
    }

    return count;
}

int main() {
    int h,w,k;
    cin >> h >> w >> k;

    vector<string> f(h,"");

    for(int i=0; i<h; ++i){
        cin >> f[i];
    }

    int ph = pow(2,h);
    int pw = pow(2,w);

    int count = 0;
    for(int mh=0; mh<ph; ++mh){
        for(int mw=0; mw<pw; ++mw){
            if(count_black(h,mh,w,mw,f)==k) ++count;
        }
    }
    print(count);
    return 0;
}


Measured memory_bytes: 4068
#include<iostream>
 #include<stdio.h>
 #include<string>
 #include<math.h>
 #include<iomanip>
 #include<algorithm>
 #include<string.h>
 #include<cctype>
 #include<map>
 #include<set>
 #include<vector>
 #include<sstream>
 #include<stack>
 #include<queue>
 
 using namespace std;
 
 int main()
 {
   int price,num;
   int sum=0;
   int total_sum=0;
   int count=0;
   char temp;
   while(cin>>price>>temp>>num)
   {
     sum+=price*num;         
     total_sum+=num;
     count++;  
   }
   double ave=1.0*total_sum/count;
   printf("%d\n%d\n",sum,(int)(ave+0.5));
   //while(1);
   return 0;
 }

 
 

Measured memory_bytes: 3084
#include<stdio.h>
#include<iostream>
#include<algorithm> // sort(ALL())
#include<string>
#include<string.h>
#include<math.h>
#include<stdlib.h>
#include<vector>
#include<queue> // push(), front(), pop() 先入れ先出し
#include<map> // 連想配列 map<string, int>
#include<iomanip>
#include<set>
#include<utility>
using namespace std;
#define FOR(i, a, b) for(int i=(a); i<(b);  i++)
#define REP(i, n)    for(int i=0;   i<(n);  i++)
#define REP1(i, n)   for(int i=1;   i<=(n); i++)
#define pb push_back
#define mp make_pair
#define scan(argument) cin>>argument
#define prin(argument) cout<<argument<<endl
#define kaigyo cout<<endl
#define EPS 1e-7
#define ALL(obj) (obj).begin(), (obj).end()
using ul    = unsigned long;
using ll    = long long;
using ld    = long double;
using vint  = vector<int>;
using vll   = vector<ll>;
using pint  = pair<int, int>;
using pll   = pair<ll, ll>;
using vpint = vector<pint>;
using vpll  = vector<pll>;
//const int INF = (int)1e9 + 1;
//const int MOD = (int)1e9 + 7;
#define INT(argu) (int)(argu+EPS)

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

  int n;
  scan(n);
  n /= 2;
  vint a, b;
  int x, y;
  REP(i, n){
    cin >> x >> y;
    a.pb(x); b.pb(y);
  }

  sort(ALL(a)); sort(ALL(b));

  int n_maxa = 0, n_maxb = 0;
  int i_maxa = 0, i_maxb = 0;
  int n_a = 1, n_b = 1;
  vint vec_na, vec_nb;
  int fa = -1, fb = -1;

  REP(i, n-1){
    if(a[i]==a[i+1]) n_a++;
    else{
      vec_na.pb(n_a);
      if(n_maxa < n_a){
        n_maxa = n_a;
        i_maxa = i; // a[maxa-n_a+1] ~ a[maxa]
        fa = -1;
      }else if(n_maxa == n_a){
        fa = i;
      }
      n_a = 1;
    }
  }
  vec_na.pb(n_a);
  if(n_maxa < n_a){
    n_maxa = n_a;
    i_maxa = n-1;
    fa = -1;
  }else if(n_maxa == n_a){
    fa = n-1;
  }
  sort(ALL(vec_na));

  REP(i, n-1){
    if(b[i]==b[i+1]) n_b++;
    else{
      vec_nb.pb(n_b);
      if(n_maxb < n_b){
        n_maxb = n_b;
        i_maxb = i; // b[maxb-n_b+1] ~ b[maxb]
        fb = -1;
      }else if(n_maxb == n_b){
        fb = i;
      }
      n_b = 1;
    }
  }
  vec_nb.pb(n_b);
  if(n_maxb < n_b){
    n_maxb = n_b;
    i_maxb = n-1;
    fb = -1;
  }else if(n_maxb == n_b){
    fb = n-1;
  }
  sort(ALL(vec_nb));

cerr << a[i_maxa] << " " << b[i_maxb] << endl;
cerr << fa << " " << fb << endl;
cerr << vec_na.size() << " " << vec_nb.size() << endl;
cerr << n_maxa << " " << n_maxb << endl;

  if(a[i_maxa]==b[i_maxb]){ // 最頻値が同じ
    if(fa!=-1 || fb!=-1){
      cout << n*2 - n_maxa - n_maxb << endl; // koko??
    }else{ // fa==-1 && fb==-1 // 最頻値が同数のものが無い
      if(a[i_maxa]==b[i_maxb] && (fa==-1 && fb==-1) && vec_na.size()>1 && vec_nb.size()>1){
        cout << n*2 - max(n_maxb + vec_na[vec_na.size()-2], n_maxa + vec_nb[vec_nb.size()-2]) << endl; // koko?
      }else if(vec_na.size()==1 && vec_nb.size()==1){ // １種類
        cout << n << endl;
      }else if(vec_na.size()>1){ // aだけ複数種類
        cout << n - vec_na[vec_na.size()-2] << endl;
      }else if(vec_nb.size()>1){ // bだけ複数種類
        cout << n - vec_nb[vec_nb.size()-2] << endl;
      }
    }
  }else{
    cout << n*2 - n_maxa - n_maxb << endl; // maru
  }

  return 0;
}


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

inline int read()
{
	int ret=0; char c=getchar();
	while(c<48||c>57)c=getchar();
	while(c>=48 && c<=57)ret=ret*10+c-48,c=getchar();
	return ret;
}
#define N 200093
long long k;
int T,f[N],g[N],u,v,st[N],t,n,a[N],h[N],tt,hh[N];
int main()
{
	n=read(); cin >> k;
	for(int i=1;i<=n;++i) a[i]=read();
	for(int i=1;i<=n;++i) {
		if(!h[a[i]])h[a[i]]=i;
	}
	for(int i=n;i;--i){
		if(!g[a[i]])f[i]=h[a[i]]; else f[i]=g[a[i]];
		g[a[i]]=i;
	}

	T=1,u=1;
	while(1){
		if(f[u]<=u)++T;
		u=f[u]+1;
		if(u==n+1)break;
	}

	k=k%T;
	if(!k)return 0;

	u=1;
	while(1){
		if(k==1)break;
		if(f[u]<=u)--k;
		u=f[u]%n+1;
	}
	while(u<=n){
		if(f[u]>u)u=f[u]; else printf("%d ",a[u]);
		++u;
	}
}


Measured memory_bytes: 5376
from collections import deque

N = int(input())

graph = [[] for _ in range(N+1)]
cost = [[] for _ in range(N+1)]
ans = [-1] * (N+1)

for query in range(N-1):
    u, v, w = map(int, input().split())
    graph[u].append(v)
    cost[u].append(w % 2)
    graph[v].append(u)
    cost[v].append(w % 2)
#print('input')

que = deque()

ans[1] = 0
que.append(1)

while que:
    now = que.popleft()
    #print(graph[now])
    for index in range(len(graph[now])):
        nextg = graph[now][index]
        nextc = cost[now][index]
        #print(ans[nextg])
        if ans[nextg] != -1:
            #print('continued')
            continue
        que.append(nextg)

        #print(nextc)
        if nextc == 1:
            ans[nextg] = (ans[now] + 1) % 2
        else:
            ans[nextg] = ans[now]
    #print(que)
    #print(ans)

#print(ans)

for i in range(1, N+1):
    print(ans[i])

Measured memory_bytes: 37488
#include<iostream>
#include<vector>
#include<algorithm>
#include<cstring>
#include<cstdio>
#include<cmath>
#include<cstdlib>
#include<ctime>
#include<queue>
#include<set>
#include<map>
#include<stack>
#include<bitset>
using namespace std;
typedef long long LL;
int gi() {
	int w=0;bool q=1;char c=getchar();
	while ((c<'0'||c>'9') && c!='-') c=getchar();
	if (c=='-') q=0,c=getchar();
	while (c>='0'&&c <= '9') w=w*10+c-'0',c=getchar();
	return q? w:-w;
}
int a[100001],b[100001];
bool G[401][401];
bool can[401];
int main()
{
	int n=gi(),m=gi(),i,j,k;bool *f;
	int ans=0;
	for (i=1;i<=m;i++) a[i]=gi(),b[i]=gi();
	for (k=1;k<=n;k++) {
		f=G[k];f[k]=1;
		can[k]=true;
		for (i=m;i;i--)
			if (f[a[i]]&&f[b[i]]) { can[k]=false; break; }
			else if (f[a[i]]) f[b[i]]=true;
			else if (f[b[i]]) f[a[i]]=true;
	}
	for (i=1;i<n;i++)
		if (can[i])
			for (j=i+1;j<=n;j++)
				if (can[j]) {
					for (k=1;k<=n;k++)
						if (G[i][k]&&G[j][k]) break;
					ans+=k>n;
				}
	cout<<ans<<endl;
	return 0;
}


Measured memory_bytes: 1152
n=int(input())
s=len(bin(n))-2
if 2**(s-1)==n:
  print("No")
elif n==3:
  print("Yes")
  for i in range(1,6):
    print(i,i+1)
else:
  print("Yes")
  print(2**(s-1)-1,1+n)
  for i in range(1,2**(s-1)-1):
    print(i,i+1)
    print(i+n,i+n+1)
  print(2**(s-1),2**(s-1)+1)
  print(2**(s-1)+1+n,1)
  print(2**(s-1),1)
  print(2**(s-1)+n,2**(s-1)+1+n)
  for i in range(2**(s-1)+2,n+1):
    print(i,i-1+n)
    print(i+n,i-2**(s-1))
    
      


Measured memory_bytes: 5764
import java.util.*;
public class Main {
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        String s = sc.next();
        String t = sc.next();
        sc.close();
        s += t.charAt(t.length() - 1);
        if(s.equals(t)){
            System.out.println("Yes");
        }else{
            System.out.println("No");
        }
    }
}

Measured memory_bytes: 38856
#include <iostream>
#include <algorithm>
#define ll long long
using namespace std;

int main(){
	int n;
	ll t[100100];
	ll a[100100];
	cin >> n;
	for (int i = 0; i < n; ++i)
	{
		cin >> t[i] >> a[i];
	}

	for (int i = 1; i < n; ++i)
	 {
	 	if(t[i-1] > t[i] || a[i-1] > a[i]){
	 		ll tmp_mul = max( (t[i-1] - 1)/ t[i] + 1, (a[i-1] - 1) / a[i] + 1);
	 		t[i] *= tmp_mul;
	 		a[i] *= tmp_mul;
	 	}

	 }

	 cout << t[n-1] + a[n-1] << endl;

}


Measured memory_bytes: 256
N = int(input())
str_unions = sorted([tuple(sorted(input())) for _ in range(N)])
count_dict = {}
ret = 0

for s in str_unions:
    if s not in count_dict:
        count_dict[s] = 1
    else: count_dict[s] += 1

sum_n = lambda n: n*(n+1)//2
print(sum(map(lambda x:sum_n(x-1), count_dict.values())))

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

#define int long long
#define double long double
#define rep(i,n) for(int i=0;i<n;i++)
#define mod 1000000007 // 10^9+7
#define INF 99999999999 //10^12-1
#define dev 998244353 //tenka1
#define P pair<int,int>
#define F first
#define S second
int n,a,b,c,d;
string s;
bool ans=true;
signed main(){
    cin>>n>>a>>b>>c>>d>>s;
    if(c<d){
        for(int i=a;i<d-1;i++){
            if(s[i]=='#'&&s[i+1]=='#')ans=false;
        }
    }
    else{
        for(int i=a;i<c-1;i++){
            if(s[i]=='#'&&s[i+1]=='#')ans=false;
        }
        bool tri=false;
        for(int i=b;i<=d;i++){
            if(s.substr(i-2,3)=="...")tri=true;
        }
        if(tri==false)ans=false;
    }
    if(ans)puts("Yes");
    else puts("No");
    return 0;
}


Measured memory_bytes: 640
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <string>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <iomanip>
#include <utility>
#include <tuple>
#include <functional>
#include <bitset>
#include <cassert>
#include <complex>
#include <stdio.h>
#include <time.h>
#define int long long
#define endl '\n'
#define INF 1000000000000000000
#define EPS 1e-10
#define PI 3.141592653589793238
#define all(a) a.begin(),a.end()
#define rep(i, n) for (int i = 0; i < (n); i++)
#define pb push_back
#define double long double
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
typedef pair<P, ll> PP;
typedef complex<double> com;
template<class T, class S> bool chmax(T &a, const S &b) { if (a < b) { a = b; return 1; } return 0; }
template<class T, class S> bool chmin(T &a, const S &b) { if (a > b) { a = b; return 1; } return 0; }
ll gcd(ll n, ll m) { return (m ? gcd(m, n%m) : n); }
ll lcm(ll n, ll m) { return n / gcd(n, m)*m; }


signed main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	cout << fixed << setprecision(20);
	//modcalc();

	int n, m;
	cin >> n >> m;
	vector<P> p(n);
	rep(i, n) cin >> p[i].first >> p[i].second;
	sort(all(p));
	priority_queue<P> que;
	int ans = 0; int idx = 0;
	for (int i = 1; i <= m; i++) {
		while (idx < n&&p[idx].first == i) {
			que.push(P(p[idx].second, p[idx].first));
			idx++;
		}
		if (!que.empty()) {
			P t = que.top(); que.pop();
			ans += t.first;
		}
	}
	cout << ans << endl;
}

Measured memory_bytes: 3956
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <ctime>
#include <cassert>
#include <iostream>
#include <cctype>
#include <sstream>
#include <string>
#include <list>
#include <vector>
#include <queue>
#include <set>
#include <stack>
#include <map>
#include <utility>
#include <numeric>
#include <algorithm>
#include <iterator>
#include <bitset>
#include <complex>
#include <fstream>
#include <iomanip>
using namespace std;
typedef long long ll;
const double EPS = 1e-9;
typedef vector<int> vint;
typedef pair<int, int> pint;
#define rep(i, n) REP(i, 0, n)
#define ALL(v) v.begin(), v.end()
#define MSG(a) cout << #a << " " << a << endl;
#define REP(i, x, n) for(int i = x; i < n; i++)
template<class T, class C> void chmax(T& a, C b){ if(a < b) a = b; }
template<class T, class C> void chmin(T& a, C b){ if(b < a) a = b; }
template<class T, class C> pair<T, C> mp(T a, C b){ return make_pair(a, b); }

int main()
{
	string str;
	int num;

	map<string, set<int> > dic;
	
	while(cin >> str >> num)
		dic[str].insert(num);

	for(map<string, set<int> >::iterator it = dic.begin(); it != dic.end(); it++)
	{
		cout << it->first << endl;
		for(set<int>::iterator itt = it->second.begin(); itt != it->second.end(); itt++)
			cout << (itt != it->second.begin() ? " " : "") << (*itt);
		cout << endl;
	}
}

Measured memory_bytes: 0
import java.util.*

fun main(args: Array<String>) {
    val scan = Scanner(System.`in`)
    var kotlin=scan.nextLine()

    var ans = 0
    var total = 0
    for(x in kotlin)
    {
        total+=Character.getNumericValue(x);
        total = (total - 9*((total-1)/9))
    }
    if(total==9 || total==0)
        println("Yes")
    else
        println("No")

}


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

int main(){
  int n;
  ll ans = 1;
  cin >> n;
  for (int i = 1; i <= n; i++){
    ans = (ans * i%inf)%inf;
  }
  if(!n) cout << 0 << endl;
  else cout << ans << endl;
  
}

Measured memory_bytes: 256
fn read<T: std::str::FromStr>() -> T {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().parse().ok().unwrap()
}

fn read_vec<T: std::str::FromStr>() -> Vec<T> {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().split_whitespace()
        .map(|e| e.parse().ok().unwrap()).collect()
}

fn main() {
    let N: i32 = read();
    let Vs: Vec<i32> = read_vec();
    let Cs: Vec<i32> = read_vec();
    let r: i32 = Vs.iter().zip(Cs.iter())
        .map(|(v, c)| v -c)
        .filter(|v| *v > 0)
        .sum();
    println!("{}", r);
}

Measured memory_bytes: 4352
#include<bits/stdc++.h>
using namespace std;
#define N 100000
long long n;
int fir[100010],nxt[200010],to[200010];
long long w[200010],z;
int cnt;
int x,y;
int a[100010];

void dfs(int x,int f,long long vi){
    if(vi%2==0) a[x]=0;
    else a[x]=1;
    for(int i=fir[x];i;i=nxt[i]){
        if(to[i]==f) continue;
        dfs(to[i],x,vi+w[i]);
    }
}

int main(){
    cin >> n;
    for(int i=1;i<n;i++){
        scanf("%d %d %lld",&x,&y,&z);
        to[++cnt]=y,nxt[cnt]=fir[x],fir[x]=cnt,w[cnt]=z;
        to[++cnt]=x,nxt[cnt]=fir[y],fir[y]=cnt,w[cnt]=z;
    }
    dfs(1,0,0);
    for(int i=1;i<=n;i++){
        printf("%d\n",a[i]);
    }

    return 0;
}


Measured memory_bytes: 6400
#! /usr/bin/env python3.4
import sys

N = int(sys.stdin.readline())
ans = []
for i in range(N):
    tri = sys.stdin.readline()[:-1].split(' ', 3)
    newlist = []
    for n in tri:
        newlist.append(int(n))
    newlist.sort()
    if newlist[0]*newlist[0] + newlist[1]*newlist[1] == newlist[2]*newlist[2]:
        ans.append("YES")
    else:
        ans.append("NO")
for a in ans:
    print(a)
    

Measured memory_bytes: 7636
/**
 * @Author:      G_bg
 * @DateTime:    2019-09-28 20:22:27
 * @Description: 
 */
#include<bits/stdc++.h>
using namespace std;
typedef long long LL;
const double PI = 3.1415926535898;
const double E = 2.718281828459;
const int INF = 0x7fffffff;
const int mod = 1e9+7;
const int maxn = 1e5+10;
LL gcd(LL a,LL b){
    return b == 0?a:gcd(b,a%b);
}
int prime[maxn],m;
void decompose(LL n){
    for(LL i = 2;i*i <= n;i++){
        if(n%i == 0){//i一定是素数
            prime[++m] = i;
            while(n%i == 0) n /= i;
        }
    }
    if(n > 1) prime[++m] = n;//n是质数
}
int main(int argc, const char *argv[]) {
    ios::sync_with_stdio(0);cin.tie(0);
    LL a,b;cin >> a >> b;
    LL g = gcd(a,b);
    decompose(g);
    cout << m+1 << endl;
    return 0;
}

Measured memory_bytes: 256
from sys import stdin
import statistics
N = int(stdin.readline().rstrip())
A = [int(x) for x in stdin.readline().rstrip().split()]
data = [0] * len(A)

for ind, i in enumerate(A):
    data[ind] = i - (ind+1)

med = statistics.median(data)

ans = 0

for  j in data:
    ans += abs(j - med)
    
print(int(ans))

Measured memory_bytes: 27240
#include <iostream>
#include <cstring>
#include <string>    
#include <vector>
#include <queue>
#include <map>
#include <algorithm>
#include <cmath>
using namespace std;
typedef long long ll;
ll n, ab[30];
string s;
ll MOD = 1e9+7;

ll cal(ll n){
	ll r = 1;
	for(ll i = 1; i <= n; i++){
		r *= 2;
		r %= MOD;
	}
	return r;
}

int main(){
	cin >> n >> s;
	
	memset(ab, 0, sizeof(ab));
	
	for(ll i = 0; i < n; i++){
		int c = s[i]-'a';
		ab[c]++;
	}
	
	ll ans = 1;
	for(ll i = 0; i < 26; i++){
		ans *= ab[i]+1;
		ans %= MOD;
	}
	
	cout << ans-1 << endl;
	return 0;
}

Measured memory_bytes: 512
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,m,n) for(int i=(m);i<(n);++i)
#define REP(i,n) FOR(i,0,n)
#define ALL(v) (v).begin(),(v).end()
using ll = long long;
const int INF = 0x3f3f3f3f;
const ll LINF = 0x3f3f3f3f3f3f3f3fLL;
const double EPS = 1e-8;
const int MOD = 1000000007;
// const int MOD = 998244353;
const int dy[] = {1, 0, -1, 0}, dx[] = {0, -1, 0, 1};
const int dy8[] = {1, 1, 0, -1, -1, -1, 0, 1}, dx8[] = {0, -1, -1, -1, 0, 1, 1, 1};
template <typename T, typename U> inline bool chmax(T &a, U b) { return a < b ? (a = b, true) : false; }
template <typename T, typename U> inline bool chmin(T &a, U b) { return a > b ? (a = b, true) : false; }
struct IOSetup {
  IOSetup() {
    cin.tie(nullptr);
    ios_base::sync_with_stdio(false);
    cout << fixed << setprecision(20);
  }
} iosetup;

int main() {
  int n, a, b; cin >> n >> a >> b;
  if (a > b) swap(a, b);
  vector dp0(n + 1, vector(b + 1, 0)), dp1(n + 1, vector(b + 1, 0));
  dp1[0][0] = 1;
  REP(i, n) REP(j, b + 1) {
    // 1 -> 0
    (dp0[i + 1][j == b ? b : 0] += dp1[i][j]) %= MOD;
    if (i + a <= n) {
      (dp0[i + a][min(j + a, b)] += dp1[i][j]) %= MOD;
      (dp0[i + a][j == b ? b : 0] += MOD - dp1[i][j]) %= MOD;
    }
    // 0 -> 0
    if (j >= a) {
      (dp0[i + 1][min(j + 1, b)] += dp0[i][j]) %= MOD;
    } else {
      (dp0[i + 1][j == b ? b : 0] += dp0[i][j]) %= MOD;
    }
    // 0 -> 1
    (dp1[i + 1][min(j + 1, b)] += dp0[i][j]) %= MOD;
    // 1 -> 1
    (dp1[i + 1][min(j + 1, b)] += dp1[i][j]) %= MOD;
  }
  cout << (dp0[n][b] + dp1[n][b]) % MOD << '\n';
  return 0;
}


Measured memory_bytes: 199036
#include <stdio.h>
#include <string.h>

// 32 - 
const char *c2b[] = {
    "101", "", "", "", "", "", "", "000000", "", "", "", "",
    "000011", "10010001", "010001", "", "", "", "", "", "", "", "", "", 
    "", "", "", "", "", "", "", "000001", "", "100101", 
    "10011010", "0101", "0001", "110", "01001", "10011011",
    "010000", "0111", "10011000", "0110", "00100", "10011001",
    "10011110", "00101", "111", "10011111", "1000", "00110",
    "00111", "10011100", "10011101", "000010", "10010010",
    "10010011", "10010000"
};

const char b2c[] = {
    'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H',
    'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 
    'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X',
    'Y', 'Z', ' ', '.', ',', '-', '\'', '?'
};

void print_char(const char *code) {
    int i, v = 0;
    for (i = 0; i < 5; i++) {
        v <<= 1;
        v += code[i] == '1';
    }
    putc(b2c[v], stdout);
}

int main(void) {
    int c, codelen, bpos;
    const char *bcode, *cur;
    char codebuf[6];

    codelen = 0;
    bpos = 0;
    cur = c2b[1];
    while (1) {
        c = getc(stdin);
        if (c == '\n' || c == EOF) {
            if (codelen > 0) {
                for (; bpos < 5; bpos++) {
                    if (*cur == '\0') {
                        codebuf[bpos] = '0';
                    }
                    else {
                        codebuf[bpos]= *cur++;
                    }
                }
                print_char(codebuf);
                codelen = 0;
                bpos = 0;
            }
            if (c == EOF) return 0;
            putc(c, stdout);
            continue;
        }

        bcode = c2b[c - 32];
        codelen += strlen(bcode);
        for (; bpos < 5; bpos++) {
            if (*cur == '\0') {
                if (bcode != NULL) {
                    cur = bcode;
                    bcode = NULL;
                }
                else {
                    break;
                }
            }
            codebuf[bpos] = *cur++;
        }
        while (codelen >= 5) {
            for (; bpos < 5; bpos++, cur++) {
                codebuf[bpos] = *cur;
            }
            print_char(codebuf);
            bpos = 0;
            codelen -= 5;
        }
    }
    return 0;
}

Measured memory_bytes: 524
#include <iostream>
#include <algorithm>
#include <vector>
using namespace std;
 
int main(){
  int n,k;
  cin >> n >> k;
  vector<int> v(n);
  for(int i=0;i<n;i++){
    cin >> v[i];
  }
  sort(v.begin(),v.end());
  reverse(v.begin(),v.end());
  int ret = 0;
  for(int i=0;i<k;i++){
    ret+=v[i];
  }
  cout << ret << endl;
  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cmath>
using namespace std;
long long int a,b,X;
int main()
{
    cin>>X;
    for(b=-120;b<=120;b++)
    {
        for(a=-120;a<=120;a++)
        {
        if(a*a*a*a*a==X+b*b*b*b*b)
        {
            cout<<a<<" "<<b;
            return 0;
        }
        }
    }
}

Measured memory_bytes: 3548
#pragma region template
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ull = unsigned long long;
using ld = long double;
using vi = vector<int>;
using vvi = vector<vi>;
using vvvi = vector<vvi>;
using vll = vector<ll>;
using vvll = vector<vll>;
using vvvll = vector<vvll>;
using vld = vector<ld>;
using vvld = vector<vld>;
using vvvld = vector<vvld>;
using vs = vector<string>;
using pll = pair<ll, ll>;
using vp = vector<pll>;
template <typename T>
using pqrev = priority_queue<T, vector<T>, greater<T>>;
#define rep(i, n) for (ll i = 0, i##_end = (n); i < i##_end; i++)
#define repb(i, n) for (ll i = (n)-1; i >= 0; i--)
#define repr(i, a, b) for (ll i = (a), i##_end = (b); i < i##_end; i++)
#define reprb(i, a, b) for (ll i = (b)-1, i##_end = (a); i >= i##_end; i--)
#define ALL(a) (a).begin(), (a).end()
#define SZ(x) ((ll)(x).size())
//*
constexpr ll MOD = 1e9 + 7;
/*/
constexpr ll MOD = 998244353;
//*/
constexpr ll INF = 1e+18;
constexpr ld EPS = 1e-12L;
constexpr ld PI = 3.14159265358979323846L;
constexpr ll GCD(ll a, ll b) { return b ? GCD(b, a % b) : a; }
constexpr ll LCM(ll a, ll b) { return a / GCD(a, b) * b; }
template <typename S, typename T>
inline bool chmax(S &a, const T &b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <typename S, typename T>
inline bool chmin(S &a, const T &b) {
  if (b < a) {
    a = b;
    return 1;
  }
  return 0;
}
#ifdef OJ_LOCAL
#include "dump.hpp"
#else
#define dump(...) ((void)0)
#endif
template <typename T>
bool print_(const T &a) {
  cout << a;
  return true;
}
template <typename T>
bool print_(const vector<T> &vec) {
  for (auto &a : vec) {
    cout << a;
    if (&a != &vec.back()) {
      cout << " ";
    }
  }
  return false;
}
template <typename T>
bool print_(const vector<vector<T>> &vv) {
  for (auto &v : vv) {
    for (auto &a : v) {
      cout << a;
      if (&a != &v.back()) {
        cout << " ";
      }
    }
    if (&v != &vv.back()) {
      cout << "\n";
    }
  }
  return false;
}
void print() { cout << "\n"; }
template <typename Head, typename... Tail>
void print(Head &&head, Tail &&... tail) {
  bool f = print_(head);
  if (sizeof...(tail) != 0) {
    cout << (f ? " " : "\n");
  }
  print(forward<Tail>(tail)...);
}
#pragma endregion

using pss = pair<string, string>;

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << fixed << setprecision(20);
  ll n;
  cin >> n;
  string s;
  cin >> s;
  map<pss, ll> mp;
  ll bitN = 1LL << n;
  rep(i, bitN){
    string a, b;
    rep(j, n){
      if((i >> j) & 1){
        a += s[j];
      }else{
        b += s[j];
      }
    }
    mp[pss(a, b)]++;
  }
  ll ans = 0;
  rep(i, bitN){
    string a, b;
    rep(j, n){
      if((i >> j) & 1){
        a += s[n+j];
      }else{
        b += s[n+j];
      }
    }
    reverse(ALL(a));
    reverse(ALL(b));
    if(mp.count(pss(b, a))){
      ans += mp[pss(b, a)];
    }
  }
  print(ans);
}


Measured memory_bytes: 46080
#include <iostream>
#include <algorithm>
#include <cmath>
#include <vector>
#include <string>
#include <map>
#include <queue>
using ll = long long;
using graph = std::vector<std::vector<ll>>;

using namespace std;

int main() {
    ll N,A,B;
    cin >> N >> A >> B;

    ll dif = abs(A-B);
    ll sum = 0;
    if(dif % 2 == 1){
        ll edge = min(A - 1,N - B);
        //cout << edge << endl;
        ll count = edge * 2 + dif + 1;
        cout << count / 2 << endl;

    }else{
        cout << dif / 2 << endl;
    }
}


Measured memory_bytes: 384
// Original: https://github.com/tanakh/competitive-rs
#[allow(unused_macros)]
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

#[allow(unused_macros)]
macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

    ($next:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };

    ($next:expr, mut $var:ident : $t:tt $($r:tt)*) => {
        let mut $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
}

#[allow(unused_macros)]
macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };

    ($next:expr, [ $t:tt ]) => {
        {
            let len = read_value!($next, usize);
            (0..len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
        }
    };

    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };

    ($next:expr, bytes) => {
        read_value!($next, String).into_bytes()
    };

    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
    };

    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}

mod util {
    #[allow(dead_code)]
    pub fn chmin<T>(x: &mut T, y: T) -> bool
    where
        T: PartialOrd + Copy,
    {
        *x > y && {
            *x = y;
            true
        }
    }

    #[allow(dead_code)]
    pub fn chmax<T>(x: &mut T, y: T) -> bool
    where
        T: PartialOrd + Copy,
    {
        *x < y && {
            *x = y;
            true
        }
    }

    /// 整数除算切り上げ
    #[allow(dead_code)]
    pub fn roundup(a: i64, b: i64) -> i64 {
        (a + b - 1) / b
    }

    #[allow(dead_code)]
    pub fn ctoi(c: char) -> i64 {
        c as i64 - 48
    }
}

#[allow(unused_imports)]
use util::*;

#[allow(unused_imports)]
use std::cmp::{max, min};
#[allow(unused_imports)]
use std::collections::{BTreeMap, BTreeSet, BinaryHeap, VecDeque};

fn main() {
    input! {
        n:usize,m:usize,
        ass:[i64;n]
    }

    let mut heap = BinaryHeap::new();
    for &a in ass.iter() {
        heap.push(a);
    }

    // 最も高額の商品の値段を半分にする。これをm回繰り返す。
    for _ in 0..m {
        if let Some(price) = heap.pop() {
            let price = price / 2;
            heap.push(price);
        }
    }

    let ans = heap.iter().sum::<i64>();
    println!("{}", ans);
}


Measured memory_bytes: 6396
n = int(input())
f = n//3
s_f = 3*f*(f+1)/2
b = n//5
s_b = 5*b*(b+1)/2
fb = n//15
s_fb = 15*fb*(fb+1)/2
print(int(n*(n+1)/2-s_f-s_b+s_fb))

Measured memory_bytes: 9160
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <cctype>
#include <queue>
#include <map>
#include <set> 
#include <bitset>
#include <cmath>
using namespace std;
typedef long long ll;
#define REP(i,n) for(int i=0;i<n;i++)

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

    if(n <= 999) {
        cout << "ABC" << endl;
    } else {
        cout << "ABD" << endl;
    } 
    
    return 0;
}



Measured memory_bytes: 384
package main

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

const (
	initialBufSize = 100000
	maxBufSize     = 10000000
)

var (
	sc = bufio.NewScanner(os.Stdin)
	wt = bufio.NewWriter(os.Stdout)
)

func next() string {
	sc.Scan()
	return sc.Text()
}

func nextInt() int {
	i, _ := strconv.Atoi(next())
	return i
}

func puts(a ...interface{}) {
	fmt.Fprintln(wt, a...)
}

const COMMAX int64 = 1000000
const MOD int64 = 1000000007

var fac [COMMAX]int64
var finv [COMMAX]int64
var inv [COMMAX]int64

// テーブル作成
func COMinit() {
	fac[0] = 1
	fac[1] = 1
	finv[0] = 1
	finv[1] = 1
	inv[1] = 1
	for i := int64(2); i < COMMAX; i++ {
		fac[i] = fac[i-1] * i % MOD
		inv[i] = MOD - inv[MOD%i]*(MOD/i)%MOD
		finv[i] = finv[i-1] * inv[i] % MOD
	}
}

// 二項係数nCk
func COM(n, k int64) int64 {
	if n < k {
		return 0
	}
	if n < 0 || k < 0 {
		return 0
	}
	return fac[n] * (finv[k] * finv[n-k] % MOD) % MOD
}

func min(nums ...int64) int64 {
	ret := nums[0]
	for _, v := range nums {
		if v < ret {
			ret = v
		}
	}
	return ret
}

func main() {
	sc.Split(bufio.ScanWords)
	sc.Buffer(make([]byte, initialBufSize), maxBufSize)
	defer wt.Flush()

	COMinit()

	n, k := int64(nextInt()), int64(nextInt())

	ans := int64(0)
	for i := int64(0); i <= min(k, n-1); i++ {
		add := (COM(n, i) * COM(n-1, n-1-i)) % MOD
		ans += add
		ans %= MOD
	}

	puts(ans)
}


Measured memory_bytes: 25240
from itertools import accumulate

N, *L = map(int, open(0).read().split())

A = [0] * (2 * 10 ** 3 + 7)
for l in L:
    A[l] += 1

S = list(accumulate(A))

ans = 0
for i in range(N):
    b = L[i]
    for j in range(i + 1, N):
        c = L[j]
        l, r = abs(b - c), b + c
        ans += S[r - 1] - S[l] - (l < b < r) - (l < c < r)

print(ans // 3)


Measured memory_bytes: 3188
#include <bits/stdc++.h>
using namespace std;
int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int n, m; cin >> n >> m;
  long long cnt = 0;
  priority_queue<pair<int, int>> pq;
  for (int i = 0; i < n; i++) {
  	int x, y;
	cin >> x >> y;
    pq.push(pair<int, int>(-x, -y));
  }
  while (m) {
    long long v = -pq.top().first;
    long long k = -pq.top().second;
    pq.pop();
    if (k < m) {
      cnt += v * k;
      m = m - k;
    }
    else {
      cnt += v * m;
      m = 0;
    }
  }
  cout << cnt << endl;
  return 0;
}


Measured memory_bytes: 1400
#include <bits/stdc++.h>
using namespace std;
typedef vector<int> vi;
typedef pair<int,int> pii;
typedef long long ll;
const long long MOD=1e09+7;



#define rep(i,n) for(int i=0;i<n;i++)
#define rep2(i,m,n) for(int i=m;i<n;i++)




int main(){
  
  ll n,m;
  cin>>n>>m;
  
  vector<ll> data(n);
  rep(i,n){
    ll tmp;
    cin>>tmp;
    data.at(i)=tmp;
  }
  
  vector<pair<ll,ll>> operations(m);
  rep(i,m){
    ll b,c;
    cin>>b>>c;
    auto tmp=make_pair(c,b);
    operations.at(i)=tmp;
  }
  
  sort(operations.begin(),operations.end());
  reverse(operations.begin(),operations.end());
  

  sort(data.begin(),data.end());
  
  
  vector<ll> lesscount(m);
  rep(i,m){
    ll ci=operations.at(i).first;
    ll dis=distance(data.begin(),lower_bound(data.begin(),data.end(),ci));
    lesscount.at(i)=dis;
  }
  
  
  
  ll changetimes=0;
  
  rep(i,m){
    if (lesscount.at(i)>changetimes){    
      ll change=min(lesscount.at(i)-changetimes,operations.at(i).second);
      for (ll j=changetimes;j<changetimes+change;j++){
        data.at(j)=operations.at(i).first;
      }
      changetimes+=change;
    }
    else {
      break;
    }
  }

  ll answer=0;

  rep(i,n){
    answer+=data.at(i);
  }
  
  cout<<answer<<endl;
   

}










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

#define ALICE 0
#define BORYS 1

int move(int A,int B,int N,int T){
    int M;
    if(T==ALICE){
        M=A<B?1:-1;
        if(A+M==B){
            if(A-M<1 || A-M>N) return BORYS;
            else return move(A-M,B,N,BORYS);
        }else{
            return move(A+M,B,N,BORYS);
        }
    }else{
        M=B<A?1:-1;
        if(B+M==A){
            if(B-M<1 || B-M>N) return ALICE;
            else return move(A,B-M,N,ALICE);
        }else{
            return move(A,B+M,N,ALICE);
        }
    }
}

int main(){
    int N,A,B;
    cin >> N >> A >> B;

    if(move(A,B,N,ALICE)==ALICE) cout << "Alice" << endl;
    else cout << "Borys" << endl;

    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>                          
using namespace std;    
string s;
int ans=1005,x,z;
int main(){
	cin>>s;
	for(int i=0;i<s.size()-2;i++)
	{
		x=0;
		for(int j=i;j<=i+2;j++)
		    x=x*10+s[j]-48;
		z=abs(x-753);
		ans=min(ans,z);
	}
	cout<<ans;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define REP(i,n)   for(int i=0;i<(n);++i)
#define ALL(v)     (v).begin(),(v).end()
#define debug(x)   cerr<<#x<<": "<<(x)<<endl
using namespace std;
using llong = long long;
using vi    = vector<int>;
using vvi   = vector<vi >;
using vvvi  = vector<vvi >;
using pii   = pair<int,int>;
constexpr int    INF=1e9;
constexpr double EPS=1e-9;
constexpr int    MOD=1e9+7;
template<class Type>
void line(const Type &a){int cnt=0;for(const auto &elem:a){cerr<<(cnt++?' ':'>');cerr<<elem;}cerr<<endl;}

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

	vi x(n),y(n);
	REP(i,n) cin>>x[i]>>y[i];
	
	vi sum(n),summ(n);
	REP(i,n){
		sum[i]=x[i]+y[i];
		summ[i]=x[i]-y[i];
	}
	sort(ALL(sum)), sort(ALL(summ));
	
	int ans=max(sum[n-1]-sum[0],summ[n-1]-summ[0]);
	cout<<ans<<endl;
}

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

typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
#define FOR(i, a, b) for (int i=a; i<(b); i++)
#define range(a) a.begin(), a.end()
#define endl "\n"
#define Yes() cout << "Yes" << endl
#define No() cout << "No" << endl
const unsigned long long mod = 1e9 + 7;
const long long INF = 1LL<<60;
void chmin(long long &a, long long b) { if (a > b) a = b; }
void chmax(long long &a, long long b) { if (a < b) a = b; }

int main(void){
	ios::sync_with_stdio(0);
	cin.tie(0);
	ll N,P,count=0,m=INF;	cin>>N;
	FOR(i,0,N){
		cin>>P;
		chmin(m,P);
		if(P==m)	count++;
	}
	
	cout<<count<<endl;

    return 0;
}





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

using namespace std;


ifstream fin("date.in");
ofstream fout("date.out");

const int Nmax = 1e6 + 50;

int main()
{
    char x, y;

    cin >> x >> y;

    if(x < y) {
      cout << "<";
      return 0;
    }
    else if (x > y) {
      cout << ">";
      return 0;
    }
    else {
      cout << "=";
      return 0;
    }

  return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<ll> vec;
typedef vector<vec> mat;
typedef pair<ll,ll> pll;
const ll mod=1e9+7;
//const ll mod=998244353;
const ll inf=1LL<<61;

ll gcd(ll a,ll b) {
  if(b==0) {
    return a;
  }
  else {
    return gcd(b,a%b);
  }
}

ll mpow(ll x, ll n) {
  ll ans=1;
  while(n>0) {
    if(n&1) {
      ans=ans*x%mod;
    }
    x=x*x%mod;
    n>>=1;
  }
  return ans;
}

vec tfact(1e7+1);
void fact(ll n) {
  for(ll i=0;i<=n;i++) {
    if(i==0) {
      tfact[i]=1;
    }
    else {
      tfact[i]=tfact[i-1]*i%mod;
    }
  }
}

ll comb(ll n, ll k) {
  return tfact.at(n)*mpow(tfact.at(k),mod-2)%mod*mpow(tfact.at(n-k),mod-2)%mod;
}

int main() {
  ll n;
  cin >> n;
  fact(n);
  map<pll,ll> cnt1,cnt2;
  ll zn=0,za=0,zb=0;
  for(ll i=0;i<n;i++) {
    ll a,b;
    cin >> a >> b;
    if(a==0&&b==0) {
      zn++;
    }
    else if(a==0) {
      za++;
    }
    else if(b==0) {
      zb++;
    }
    else {
      ll g=gcd(a,b);
      a/=g;
      b/=g;
      if(a*b>0) {
        a=abs(a);
        b=abs(b);
      }
      else {
        a=abs(a);
        b=-abs(b);
      }
      cnt1[{a,b}]++;
      if(b<0) {
        b*=-1;
        a*=-1;
      }
      cnt2[{b,-a}]++;
    }
  }
  ll ans=1;
  set<pll> al;
  for(auto p:cnt1) {
    if(al.count(p.first)) continue;
    ll a=p.first.first;
    ll b=p.first.second;
    al.insert({a,b});
    ans=ans*(mpow(2,p.second)+mpow(2,cnt2[p.first])-1+mod)%mod;
    if(b<0) {
      b*=-1;
      a*=-1;
    }
    al.insert({b,-a});
  }
  ans=ans*(mpow(2,za)+mpow(2,zb)-1+mod)%mod;
  ans=(ans+zn-1+mod)%mod;
  cout << ans << endl;
}

Measured memory_bytes: 143880
#include <stdio.h>

int main(void)
{
	int n,q,num,fish,i,j,vic=0,max=0,get[1000000];
	
	scanf("%d %d",&n,&q);
	
	for(i=1;i<=n;i++){
		get[i]=0;
	}
	for(i=0;i<q;i++){
		scanf("%d %d",&num,&fish);
		get[num]+=fish;
		if(fish<0 && num==vic){
			max=0;
			for(j=n;j>0;j--){
				if(max<=get[j]){
					max=get[j];
					vic=j;
				}
			}
		}else if(get[num]>max || (get[num]==max && vic>num)){
			max=get[num];
			vic=num;
		}
		printf("%d %d\n",vic,get[vic]);
	}
	
	return 0;
}

Measured memory_bytes: 4504
n, m = [int(i) for i in input().split()]
dp_prev = [float("inf") for i in range(2**n)]
dp_next = [float("inf") for i in range(2**n)]
dp_prev[0] = 0

for i in range(m):
    a, _ = [int(_) for _ in input().split()]
    c = sum([2**(int(_)-1) for _ in input().split()])

    for j in range(2**n):
        dp_next[j|c] = min(dp_prev[j|c], dp_prev[j] + a, dp_next[j|c])
        dp_next[j] = min(dp_prev[j], dp_next[j])
    dp_prev = dp_next[:]


print([dp_next[-1], -1][dp_next[-1] == float("inf")])


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

int main(){
	int n;
	cin>>n;
	vector<pair<int,int>> b(n);
	int tx,ty;
	for (int i = 0; i < n; i++) {
		cin>>tx>>ty;
		b[i]=make_pair(tx,ty);
	}
	int p,q;
	int dx,dy;
	int ans=n;
	int temp;
	for (int i = 0; i < n-1; i++) {
		for (int j = i+1; j < n; j++) {
			p=b[i].first-b[j].first;
			q=b[i].second-b[j].second;
			temp=n;
			for (int k = 0; k < n-1; k++) {
				for (int l = k+1; l < n; l++) {
					dx=b[k].first-b[l].first;
					dy=b[k].second-b[l].second;
					if ((dx==p&&dy==q)||(dx==-p&&dy==-q)) {
						temp--;
					}
				}
			}
			ans=min(ans,temp);
		}
	}
	cout<<ans<<endl;
}

Measured memory_bytes: 256
#include<cstdio>
#define sev en
using namespace std;
#define N 100010

int a[N],cnt[2],n;

int gcd(int a,int b){
	if(b == 0)
		return a;
	return gcd(b,a % b);
}

int dg(){
	for(int i = 1;i <= n;i++)
		if(a[i] & 1)
			a[i]--;
	cnt[0] = cnt[1] = 0;
	int w = a[1];
	for(int i = 2;i <= n;i++)
		w = gcd(w,a[i]);
	for(int i = 1;i <= n;i++)
		cnt[(a[i] /= w) & 1]++;
	if(cnt[0] & 1)
	return 1;
	else if(cnt[1] > 1)
	return 0;
	else{
		for(int i = 1;i <= n;i++)
		if(a[i] == 1)
		return cnt[0] & 1 ? 1 : 0;
		return dg() ^ 1;
	}
}

int main(){
	scanf("%d",&n);
	for(int i = 1;i <= n;i++){ 
		scanf("%d",&a[i]);
		cnt[a[i] & 1]++;
	}
	if(cnt[0] & 1)
	printf("First");
	else if(cnt[1] > 1)
	printf("Second");
	else{
		for(int i = 1;i <= n;i++)
		if(a[i] == 1){
			printf(cnt[0] & 1 ? "First" : "Second");
			return 0;
		}
		if(dg() ^ 1)
		printf("First");
		else
		printf("Second");
	}
	return 0;
}

Measured memory_bytes: 512
#include <iostream>
#include <string>
#include <array>
#include <vector>
#include <deque>
#include <list>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <algorithm>
#include <cstdio>
#include <cstring>
#include <utility>
#include <cstdlib>
#include <cmath>
#define INF 987654321
#define INT_MAX 2147483647
#define MIN(a, b) ((a) < (b) ? a : b)
#define MAX(a, b) ((a) > (b) ? a : b)
 
using namespace std;
 
 
 
int main() {
    long int X, K, D;
    cin >> X >> K >> D;
    X = abs(X);

    if(K <= X / D) {
        cout << X - K * D;
    }
    else {
        int i = X / D;
        if((K - i)%2 == 0) cout << X - i * D;
        else cout << abs(X - i * D - D);
    }
}

Measured memory_bytes: 3192
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <string>
#include <numeric>
#include <cstdint>
#include <iomanip>
using ll = long long;
#define fast_io(); std::ios_base::sync_with_stdio(0); std::cin.tie(0); std::cout.tie(0);

int main(){
    std::string s; std::cin >> s;

    std::vector<ll> v(s.size()+1,0);
    for(ll i=0; i<v.size(); i++){
        if(s[i]=='<') v[i+1] = v[i] + 1;
    }
    for(ll i=v.size()-1; i>=0; i--){
        if(s[i]=='>') v[i] = std::max(v[i], v[i+1]+1);
    }
    std::cout << std::accumulate(v.begin(),v.end(),0LL) << "\n";
    return 0;
}


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

int main() {
    int n;
    string s;
    
    cin >> n;
    
    for (int i = 0; i < n; i++) {
        cin >> s;
        if (s == "Y") {
            cout << "Four" << endl;
            return 0;
        }
    }
    
    cout << "Three" << endl;
}
  


Measured memory_bytes: 3620
/*
ID: jerrywcy
LINK: https://atcoder.jp/contests/abc127/tasks/abc127_c
LANG: C++
STATUS:
*/
#include <bits/stdc++.h>

#define init(array,x) memset(array,x,sizeof(array))

using namespace std;

const int inf=0x3f3f3f3f;
const int maxn=1e5+10;

int n,m;
int l,r=inf;

int main()
{
	ios::sync_with_stdio(false);
    cin>>n>>m;
    for (int i=1;i<=m;i++){
        int a,b;
        cin>>a>>b;
        l=max(l,a);
        r=min(r,b);
    }
    int ans=r-l+1;
    ans=max(ans,0);
    ans=min(ans,n);
    cout<<ans<<endl;

	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <queue>
#include <cstring>

using namespace std;

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

struct Location {
	int x, y, dir, score;
	Location(int _x, int _y, int _dir, int _s) :
		x(_x), y(_y), dir(_dir), score(_s)
	{ }
};
struct LocationComparator {
	bool operator()(const Location &a, const Location &b) const {
		return a.score > b.score;
	}
};

int main(){
	while(true){
		int w, h;
		cin >> w >> h;
		if(w == 0 && h == 0){ break; }
		vector< vector<int> > s(h, vector<int>(w));
		for(int i = 0; i < h; ++i){
			for(int j = 0; j < w; ++j){ cin >> s[i][j]; }
		}
		int c[4];
		cin >> c[0] >> c[1] >> c[2] >> c[3];
		memset(cost, -1, sizeof(cost));
		priority_queue<Location, vector<Location>, LocationComparator> pq;
		cost[0][0][0] = 0;
		pq.push(Location(0, 0, 0, 0));
		int answer = -1;
		while(!pq.empty()){
			Location loc = pq.top();
			if(loc.x == w - 1 && loc.y == h - 1){
				answer = cost[loc.x][loc.y][loc.dir];
				break;
			}
			pq.pop();
			for(int i = 0; i < 4; ++i){
				int next = cost[loc.x][loc.y][loc.dir];
				if(i != s[loc.y][loc.x]){ next += c[i]; }
				int dir = (loc.dir + i) % 4;
				int x = loc.x + dx[dir], y = loc.y + dy[dir];
				if(x < 0 || x >= w || y < 0 || y >= h){ continue; }
				if(cost[x][y][dir] < 0 || next < cost[x][y][dir]){
					cost[x][y][dir] = next;
					pq.push(Location(x, y, dir, next));
				}
			}
		}
		cout << answer << endl;
	}
	return 0;
}

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

int main(){
    int a,b,c,d,e,k;
    cin >> a>>b>>c>>d>>e>> k ;
    if(e-a<=k){
        cout << "Yay!" <<endl;
    }else{
        cout << ":(" <<endl;
    }
    return 0;
}


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

using namespace std;
const int N=105,NN=N<<1,M=N*N;
const LL inf=1ll<<55;
LL rd()
{
    LL x=0,w=1;char ch=0;
    while(ch<'0'||ch>'9'){if(ch=='-') w=-1;ch=getchar();}
    while(ch>='0'&&ch<='9'){x=x*10+(ch^48);ch=getchar();}
    return x*w;
}
struct node
{
	LL x,y;
	node(LL nx=0,LL ny=0){x=nx,y=ny;}
	bool operator < (const node &bb) const {return x!=bb.x?x<bb.x:y<bb.y;}
	node operator + (const node &bb) const {return (node){x+bb.x,y+bb.y};}
}w[M],di[NN];
int to[M],nt[M],c[M],hd[NN],tot=1,ps,pt,fw[NN],pr[NN],v[NN];
LL s1,s2,ans;
void adde(int x,int y,int z,LL z1,LL z2)
{
	++tot,to[tot]=y,nt[tot]=hd[x],c[tot]=z,w[tot]=(node){+z1,+z2},hd[x]=tot;
	++tot,to[tot]=x,nt[tot]=hd[y],c[tot]=0,w[tot]=(node){-z1,-z2},hd[y]=tot;
	s1-=z*z1;
}
void csfl()
{
	queue<int> q;
	while(1)
	{
		for(int i=1;i<=pt;++i) di[i]=(node){-inf,-inf};
		di[ps]=(node){0,0},fw[ps]=1<<30,v[ps]=1,q.push(ps);
		fw[pt]=0;
		while(!q.empty())
		{
			int x=q.front();
			q.pop();
			for(int i=hd[x];i;i=nt[i])
			{
				int y=to[i];
				if(c[i]>0&&di[y]<di[x]+w[i])
				{
					di[y]=di[x]+w[i];
					pr[y]=i,fw[y]=min(fw[x],c[i]);
					if(!v[y]) v[y]=1,q.push(y);
				}
			}
			v[x]=0;
		}
		if(!fw[pt]) return;
		s1+=di[pt].x*fw[pt],s2+=di[pt].y*fw[pt];
		int x=pt;
		while(x!=ps)
		{
			int i=pr[x];
			c[i]-=fw[pt],c[i^1]+=fw[pt];
			x=to[i^1];
		}
	}
}
int n,m,t=100;
char cc[2];
LL a[N][3],b[N<<2][3],px[N][2],py[N][2];
map<char,int> id;

int main()
{
/////
	id['L']=0,id['R']=1,id['D']=2,id['U']=3;
	n=rd();
	for(int i=1;i<=n;++i)
		for(int j=0;j<=2;++j)
			a[i][j]=rd();
	m=rd();
	for(int i=1;i<=m;++i)
	{
		scanf("%s",cc),b[i][0]=id[cc[0]];
		b[i][1]=rd(),b[i][2]=rd();
	}
	ps=0,pt=203;
	int yyb=201,zsy=202;
	for(int h=1;h<=n;++h)
	{
		memset(hd,0,sizeof(int)*(pt+1)),tot=1,s1=s2=0;
		for(int i=1;i<=t;++i) px[i][0]=0,px[i][1]=1<<30;
		for(int i=1;i<=t;++i) py[i][0]=0,py[i][1]=1<<30;
		for(int i=1;i<=m;++i)
		{
			if(b[i][0]==0) px[b[i][1]][1]=min(px[b[i][1]][1],b[i][2]);
			if(b[i][0]==1) px[b[i][1]-1][0]=max(px[b[i][1]-1][0],h-b[i][2]);
			if(b[i][0]==2) py[b[i][1]][1]=min(py[b[i][1]][1],b[i][2]);
			if(b[i][0]==3) py[b[i][1]-1][0]=max(py[b[i][1]-1][0],h-b[i][2]);
		}
		adde(ps,yyb,h,1,0);
		bool o=1;
		int np=yyb;
		for(int i=t;i;--i)
		{
			if(px[i][0]>px[i][1]){o=0;break;}
			adde(np,i,px[i][0],1,0),adde(np,i,px[i][1]-px[i][0],0,0);
			np=i;
		}
		np=zsy;
		for(int i=t;i;--i)
		{
			if(py[i][0]>py[i][1]){o=0;break;}
			adde(i+t,np,py[i][0],1,0),adde(i+t,np,py[i][1]-py[i][0],0,0);
			np=i+t;
		}
		adde(zsy,pt,h,1,0);
		if(!o) continue;
		for(int i=1;i<=n;++i) adde(a[i][0],a[i][1]+t,1,0,a[i][2]);
		csfl();
		if(s1>=0) ans=max(ans,s2);
	}
	printf("%lld\n",ans);
    return 0;
}


Measured memory_bytes: 640