akhauriyash/Code-Regression huggingface dataset:
#include <algorithm>
#include <array>
#include <vector>
#include <iostream>
#include <fstream>
#include <string>
#include <cmath>
#include <functional>
#include <queue>

using namespace std;

void Show(vector<vector<int>> S) {
	for (int i = 0; i < S.size(); i++) {
		for (int j = 0; j < S[i].size(); j++) {
			cout << "[" << i << "," << j << "]" << S[i][j] << endl;
		}
	}
}

int main() {
	int N, M, Q;
	cin >> N >> M >> Q;
	vector<vector<int>> Table;//Table[i][j]=i駅から距離jの区間を行く電車の総数
	Table.resize(N);
	vector<vector<int>> Sums;//Sums[i][j]=i駅からj駅に完全に含まれる区間を行く電車の総数
	Sums.resize(N);
	for (int i = 0; i < N; i++) {
		Table[i].resize(N);
		Sums[i].resize(N);
	}
	int L, R;
	for (int j = 0; j < M; j++) {
		cin >> L >> R;
		Table[L - 1][R - L]++;
	}
	for (int i = 0; i < N; i++) {
		for (int j = i; j < N; j++) {
			if (j == i) {
				Sums[i][j] = Table[i][0];
			} else {
				Sums[i][j] = Sums[i][j - 1];
				for (int t = 0; t <= j - i; t++) {
					Sums[i][j] += Table[i + t][j - i - t];
				}
			}
		}
	}

	for (int q = 0; q < Q; q++) {
		cin >> L >> R;
		cout <<Sums[L - 1][R - 1] << endl;
	}
}

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

int main () {
long long N,A,B;
  cin >> N >> A >> B;
  long long x,r;
  x = N / (A + B);
  r = N % (A + B);
  if (r < A) {
  cout << A * x + r << endl;
  }
  else {
  cout << A * x + A << endl;
  }
}




Measured memory_bytes: 256
from math import gcd
n=int(input())
a=list(map(int,input().split()))
x=[-1]*(10**6+5)
x[0]=0
x[1]=1
i=2
while i<=10**6+1:
    j=2*i
    if x[i]==-1:
        x[i]=i
        while j<=10**6+1:
            x[j]=i
            j+=i
    i+=1

z=[0]*(10**6+5)

g=gcd(a[0],a[0])
for i in range(n):
    g=gcd(g,a[i])
if g!=1:
    print("not coprime")
else:
    f=0
    for i in range(n):
        p=1
        while a[i]>=2:
            if p==x[a[i]]:
                a[i]=a[i]//p
                continue
            else:
                p=x[a[i]]
                z[p]+=1
                a[i]=a[i]//p

    for i in range(10**6+1):
        if z[i]>=2:
            f=1
    print("pairwise coprime" if f==0 else "setwise coprime")


Measured memory_bytes: 189056
#include<stdio.h>
#include<iostream>
#include<list>
#include<map>
#include<vector>
#include<algorithm>
#include<string.h>
#include<iomanip>
#define range(i,a,b) for(int i = (a); i < (b); i++)
#define rep(i,b) range(i,0,b)
#define debug(x) cout << x << endl;
using namespace std;

int main(){
    double a;
    double ans;
    while(cin >> a){
        ans = a;
        range(i,2,11){
            if(i % 2 == 0){
                a *= 2;
            }else{
                a /= 3;
            }
            ans += a;
        }
        cout << setprecision(10) <<ans << endl;
    }
}

Measured memory_bytes: 1276
#include<iostream>
#include<math.h>
#include<vector>
#include<algorithm>
#include<cstdio>
#include<cstring>
using namespace std;

int main(){
    char l[6][6]={{0}};
    for(int i=0;i<5;i++){
        for(int j=0;j<5;j++)
            l[i][j]='a'+i*5+j;
    }
    strcpy(l[5],"z.?! ");
 
    char str[256];
    while(scanf("%s",str)!=EOF){
        if(strlen(str)&1){
            puts("NA");
            continue;
        }
        bool flag=true;
        char ans[128]={0};
        for(int i=0;str[i];i+=2){
            int v1=str[i]-'0'-1,v2=str[i+1]-'0'-1;
            if(v1<0||v1>=6||v2<0||v2>=5){
                puts("NA");
                flag=false;
                break;
            }
            ans[i/2]=l[v1][v2];
        }
        if(flag)printf("%s\n",ans);
    }
    return 0;
}


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

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

int main()
{
    long long int a,b,lcm,x,y;
    cin>>a>>b;
    x=a;
    y=b;
    lcm=x*y/gcd(a,b);
    cout<<lcm<<endl;

    return 0;
}

Measured memory_bytes: 256
using System;
using System.Linq;
class Abc
{
    static void Main()
    {
        int c = int.Parse(Console.ReadLine());
        int[] p = new int[c];
        for (int i = 0; i < c; i++)
        {
            p[i] = int.Parse(Console.ReadLine());
        }
        Array.Sort(p);
        Array.Reverse(p);
        int O = p.Sum();
        O -= p[0] / 2;
        Console.WriteLine(O);
    }
}

Measured memory_bytes: 13268
#include <bits/stdc++.h>
typedef long long ll;
#define all(x) x.begin(),x.end()
#define pb push_back
#define mp make_pair
#define eb emplace_back
#define mod 1000000007
#define all(x) x.begin(),x.end()
#define deb(x) cout<<#x<<" "<<x<<"\n";
#define cr7 ios_base::sync_with_stdio(false);cin.tie(NULL);
using namespace std;
int main() {
	cr7
	ll r;
	cin >> r;
	double d = 6.28318530717958623200/2.00;
	cout.precision(20+floor(log10(2*r) + 1));
	cout << 2*(d)*r<<"\n";
}

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

using namespace std;
inline void prep ()
{
  cin.tie (0);
  cin.sync_with_stdio (0);
};
const double pi = acos(-1.);
//printf(%.12lf\n,mid);
// __builtin_popcount(int) count 1's in binary
// get decimal part of number
/*
double intpart;
double thiss = modf((double)(n*m)/(double)k, &intpart);
*/
// round = (int)(num+.5)
int mod = 20437;

long long mymod(long long num){
  if (num< 0 && !(num%mod == 0)){
    if (mod == 1){
      return 0;
    }
    return mod-abs(num)%mod;
  }else{
    return num%mod;
  }
}

/*string sentence = And I feel fine...;
    istringstream iss(sentence);
*/  

double eps = .000000001;


int main ()
{
  prep();
  string s;
  cin >> s;
  if (s == "Sunny"){
      cout << "Cloudy";
  }else if (s == "Rainy"){
      cout << "Sunny";
  }else{
      cout << "Rainy";
  }
  return 0; 
}
  

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
bool h(string k)
{
	string s = k;
	reverse(k.begin(),k.end());
	return (s == k);
}
int main()
{
	string s;
	cin>>s;
	string sm = s.substr(0,(s.size()-1)/2);
	string bi = s.substr(((s.size()+3)/2-1));
	if(h(s)&&h(sm)&&h(bi))
	{
		cout<<"Yes\n";
	}
	else
	{
		cout<<"No\n";
	}
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
  int h,w;
  cin >> h >> w;
  int i,j;
  long minn = 999999999;
  long tmp = 0;
  if(h%3==0||w%3==0)cout << 0 << endl;
  else{
    for(i=max(1,w/3-100);i<=min(w-1,w/3+100);i++){
      for(j=max(1,h/2-100);j<=min(h-1,h/2+100);j++){
        tmp = max(h*i,max((w-i)*j,(w-i)*(h-j)))-min(h*i,min((w-i)*j,(w-i)*(h-j)));
        if(minn>tmp)minn = tmp;
      }
    }
    for(i=max(1,h/3-100);i<=min(h-1,h/3+100);i++){
      for(j=max(1,w/2-100);j<=min(w-1,w/2+100);j++){
        tmp = max(w*i,max((h-i)*j,(h-i)*(w-j)))-min(w*i,min((h-i)*j,(h-i)*(w-j)));
        if(minn>tmp)minn = tmp;
      }
    }
    if(min(w,h)<minn)minn=min(w,h);
    cout << minn << endl;
  }

}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define FOR(i,a,b) for(ll i=(a);i<(b);++i)
#define rep(i,n) FOR(i,0,n)
#define all(x) (x).begin(),(x).end()
#define PRINT(V) cout << V << "\n"
#define SORT(V) sort((V).begin(),(V).end())
#define RSORT(V) sort((V).rbegin(), (V).rend())
using namespace std;
using ll = long long;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
const ll INF = 1e13;
typedef pair<ll,ll> P;

int main(){
    int n;
    cin >> n;
    string s;
    cin >> s;
    int c = 0;
    int cnt = 0;
    string k;
    rep(i,1000){
        if (i < 10){
            k = "00" + to_string(i);
        }
        else if (i < 100){
            k = "0" + to_string(i);
        }
        else{
            k = to_string(i);
        }
        rep(i,n){
            if (s[i] == k[c]) c++;
            if (c == 3) break;
        }
        if (c >= 3) cnt++;
        c = 0;
    }
    PRINT(cnt);
}

Measured memory_bytes: 256
#!/usr/bin/env python3
import sys

def conv2num(c):
    if c == "A":
        return 1
    elif c == "D":
        return 2
    elif c == "B":
        return 3
    else:
        return 4

def solve(s: str):

    res = 0
    s = s.replace("BC","D")
    s = [ conv2num(c) for c in s ]

    acnt = 0
    for i,c in enumerate(s):
        if c == 1:
            acnt += 1
        elif c == 2:
            res += acnt
        else:
            acnt = 0


    print(res)

    return


# Generated by 1.1.4 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    s = next(tokens)  # type: str
    solve(s)

if __name__ == '__main__':
    main()


Measured memory_bytes: 5172
#include<iostream>
#include<cstring>
#include<cstdio>
#include<vector>
#include<algorithm>

using namespace std;

#define LL long long
#define fgx cerr<<"--------------"<<endl;
#define dgx cerr<<"=============="<<endl;

inline LL read(){
	LL x=0,f=1;char c=getchar();
	for(;!isdigit(c);c=getchar()) if(c=='-') f=-1;
	for(;isdigit(c);c=getchar()) x=x*10+c-'0';
	return x*f;
}
const LL MAXN = 100010;
const LL INF = 2147483600;
const LL Mod = 1e9+7;

LL N,M;

struct dat{
	LL u,v,w;
}ed[MAXN+1];
bool cmpw(dat a,dat b){
	return a.w<b.w;
} LL fa[MAXN+1]; LL Pw[MAXN+1],fs[MAXN+1];
inline LL find(LL u){ return (u==fa[u]?u:(fa[u]=find(fa[u]))); }
inline void merge(LL u,LL v){ fa[find(u)]=find(v); }
inline LL GetSum(){
	LL sum=0;
	for(LL i=1;i<=M;i++){
		if(find(ed[i].u)!=find(ed[i].v)){
			merge(ed[i].u,ed[i].v);
			sum+=ed[i].w;
		}
	} return sum;
} LL cnt; LL W;
bool vis[MAXN+1]; LL ans=0;

int main(){
	//freopen(".in","r",stdin);
	//freopen(".out","w",stdout);
	N=read(),M=read(); W=read(); Pw[0]=1;
	for(LL i=1;i<=M+N;i++) Pw[i]=Pw[i-1]*2%Mod;
	for(LL i=1;i<=M;i++){
		LL u=read(),v=read(),w=read();
		ed[++cnt].u=u; ed[cnt].v=v; ed[cnt].w=w;
	} sort(ed+1,ed+cnt+1,cmpw); LL Wt=0;
	for(LL i=1;i<=N;i++) fa[i]=i;
	for(LL i=1;i<=M;i++){
		if(find(ed[i].u)!=find(ed[i].v)){
			merge(ed[i].u,ed[i].v);
			vis[i]=1; Wt+=ed[i].w;
		}
	} if(Wt==W) ans+=(Pw[N-1]-2+Mod)%Mod*Pw[M-(N-1)]%Mod;
	ans%=Mod;
	int pos=0,top=0;
	for(LL i=1;i<=M;i++){
		if(vis[i]) continue;
		for(LL j=1;j<=N;j++) fa[j]=j;
		merge(ed[i].u,ed[i].v);
		fs[++top]=GetSum()+ed[i].w; 
	} sort(fs+1,fs+top+1);
	for(int i=1;i<=top;i++)	if(fs[i]==W) (ans+=2*Pw[M-(N-1)-i]%Mod)%=Mod;
	printf("%lld\n",ans%Mod);
	return 0;
}




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

using namespace std;
typedef long long ll;
const int MAXN = 100010;
int _w;

int n, m;

namespace Graph {
	int head[MAXN], nxt[MAXN<<1], to[MAXN<<1], eidx;
	void init() {
		memset(head, -1, sizeof head);
	}
	void adde( int u, int v ) {
		to[eidx] = v, nxt[eidx] = head[u], head[u] = eidx++;
		to[eidx] = u, nxt[eidx] = head[v], head[v] = eidx++;
	}
}

int c[MAXN];
queue<int> q;
bool bipartite() {
	using namespace Graph;
	q.push(1), c[1] = 1;
	while( !q.empty() ) {
		int u = q.front();
		q.pop();
		for( int i = head[u]; ~i; i = nxt[i] ) {
			int v = to[i];
			if( c[v] == c[u] ) return false;
			if( c[v] == 3 - c[u] ) continue;
			c[v] = 3 - c[u];
			q.push(v);
		}
	}
	return true;
}

int main() {
	_w = scanf( "%d%d", &n, &m );
	Graph::init();
	for( int i = 0; i < m; ++i ) {
		int u, v;
		_w = scanf( "%d%d", &u, &v );
		Graph::adde(u, v);
	}
	if( bipartite() ) {
		int cnt1 = 0, cnt2 = 0;
		for( int i = 1; i <= n; ++i )
			if( c[i] == 1 ) ++cnt1;
			else ++cnt2;
		printf( "%lld\n", (ll)cnt1 * cnt2 - m );
	} else {
		printf( "%lld\n", (ll)n*(n-1)/2 - m );
	}
	return 0;
}


Measured memory_bytes: 2816
// ====================================
//   author: M_sea
//   website: https://m-sea-blog.com/
// ====================================
#include <bits/stdc++.h>
#define file(x) freopen(#x".in","r",stdin); freopen(#x".out","w",stdout)
#define debug(...) fprintf(stderr,__VA_ARGS__)
using namespace std;
typedef long long ll;

int read() {
	int X=0,w=1; char c=getchar();
	while (c<'0'||c>'9') { if (c=='-') w=-1; c=getchar(); }
	while (c>='0'&&c<='9') X=X*10+c-'0',c=getchar();
	return X*w;
}

const int N=100000+10;

int n,x,a[N];

int main() {
	n=read(),x=read();
	for (int i=1;i<=n;++i) a[i]=read();
	ll ans=0;
	for (int i=2;i<=n;++i) {
		if (a[i-1]+a[i]>=x) {
			int dlt=a[i-1]+a[i]-x; ans+=dlt;
			if (a[i]>=dlt) a[i]-=dlt;
			else a[i]=0,a[i-1]-=dlt-a[i];
		}
	}
	printf("%lld\n",ans);
	return 0;
}

Measured memory_bytes: 4124
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n; i >= 0; i--)
#define FOR(i, m, n) for (int i = m; i < n; i++)
#define INF 2e9
#define ALL(v) v.begin(), v.end()
using namespace std;
typedef long long ll;
typedef vector<ll> vll;
typedef vector<vll> vvll;


int main()
{
    ll k, s;
    cin >> k >> s;
    
    ll counter = 0;
    for (ll x = 0; x <= k; x++) {
        for (ll y = 0; y <= k; y++) {
            ll z = s - x - y;
            if (0 <= z && z <= k) counter++; 
        }
    }
    cout << counter << endl;
}

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

int h, w, k;
char s[11][1011];
int ans;

void proc(vector<int> v) {
	int sz = v.size();
	int res = sz-1;
	
	int last[11];
	memset(last, 0, sizeof last);
	int cnt[11];
	memset(cnt, 0, sizeof cnt);
	
	for(int j=0;j<w;j++) {
		int it = 0;
		bool chk = true;
		for(int i=0;i<sz;i++) {
			cnt[i] = 0;
			for(int x=0;x<v[i];x++, it++)
				if(s[it][j]=='1')cnt[i]++;
			if(cnt[i]>k) return;
			if(last[i] + cnt[i] > k) chk = false;
		}
		
		if(chk)
			for(int i=0;i<sz;i++) last[i] += cnt[i];
		else {
			res++;
			for(int i=0;i<sz;i++) last[i] = cnt[i];
		}
	}
	
	ans = min(ans, res);
}

void dfs(int id, vector<int> v, int cur) {
	if(id==h) {
		v.push_back(cur);
		proc(v);
		return;
	}
	dfs(id+1, v, cur+1);
	v.push_back(cur);
	dfs(id+1, v, 1);
}

int main() {
	scanf("%d%d%d", &h, &w, &k);
	for(int i=0;i<h;i++) scanf("%s", s[i]);
	
	vector<int> v(0);
	ans = h+w-2;
	dfs(1, v, 1);
	
	printf("%d\n", ans);
	
	return 0;
}

Measured memory_bytes: 256
def I(): return int(input())
def MI(): return map(int, input().split())
def LI(): return list(map(int, input().split()))

def main():
    mod=10**9+7
    x=0
    N=I()
    S=input()
    
    ans=0
    for i in range(N):
        if S[i]=="I":
            x+=1
        else:
            x-=1
            
        ans=max(ans,x)
        
    print(ans)

main()


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

typedef long long ll;
typedef pair<int, int> P;
typedef tuple<int, int, int> T;

int MOD=1e9+7;
ll INF=1e18;

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

int main(){
    int n; cin>>n;
    vector<int> a(n), b(n);
    for(int i=0; i<n; i++){
        a[i]=n*(i+1);
        b[i]=n*(n-i);
    }

    for(int i=0; i<n; i++){
        int p; cin>>p;
        p--;
        a[p]+=i;
    }

    for(int i=0; i<n; i++){
        if(i!=n-1) cout << a[i] << " ";
        else cout << a[i] << endl;
    }
    for(int i=0; i<n; i++){
        if(i!=n-1) cout << b[i] << " ";
        else cout << b[i] << endl;
    }
}

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

int main(){
	map<int, int> m, r;
	//map<int, int> r;
	int a[6], n, x, y;
	int d[6][6]={{0,3,5,2,4,0},{4,0,1,6,0,3},{2,6,0,0,1,5},
		{5,1,0,0,6,2},{3,0,6,1,0,4},{0,4,2,5,3,0}};
	for(int i = 0;i < 6;i++){cin >> a[i];m[a[i]] = i;r[i] = a[i];}
	cin >> n;
	for(int i = 0;i < n;i++){
		cin >> x >> y;
		int tmp = d[m[x]][m[y]];
		cout << r[tmp-1] << endl;
	}
	
	return 0;
}

Measured memory_bytes: 3128
n, k = map(int, input().split())
l = [0 for _ in range(n)]
ans = 0

for i in range(k):
    d = int(input())
    a = map(int, input().split())
    for j in a:
        l[j-1] += 1

for i in range(n):
    if l[i] == 0:
        ans += 1

print(ans)


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

using namespace std;

struct Swimmer {
  int v, lap, next;
  Swimmer(){}
  Swimmer(int v, int lap, int next):v(v), lap(lap), next(next){}
  bool operator < (const Swimmer& s) const {
    return v < s.v;
  }
};

int N;
vector<Swimmer> swimmer;
queue<Swimmer> lane[2];

int main() {
  while(cin >> N, N) {
    swimmer.clear();
    for(int i = 0; i < N; i++) {
      int t, c;
      cin >> t >> c;
      swimmer.emplace_back(t, c, t);
    }
    sort(begin(swimmer), end(swimmer));
    for(auto&& s : swimmer) lane[0].push(s);
    int ans = 0;
    while(!lane[0].empty() || !lane[1].empty()) {
      bool id = lane[0].empty();
      if(!id && !lane[1].empty()) id = lane[1].front().next < lane[0].front().next;
      vector<Swimmer> vec;
      vec.push_back(lane[id].front());
      int tmp = vec[0].next;
      lane[id].pop();
      while(!lane[id].empty() && tmp >= lane[id].front().next) {
	vec.push_back(lane[id].front());
	lane[id].pop();
      }
      for(auto&& s : vec) {
	s.next = tmp+s.v;
	s.lap -= id;
	if(s.lap == 0) ans = max(ans, tmp);
      }
      sort(begin(vec), end(vec));
      for(auto&& s : vec) {
	if(s.lap > 0) lane[1-id].push(s);
      }
    }
    cout << ans << endl;
  }

  return 0;
}

Measured memory_bytes: 3112
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace atcoder
{
	class Program
	{
		static int In => int.Parse(Console.ReadLine());
		static int[] Ins => Console.ReadLine().Split(' ').Select(int.Parse).ToArray();
		static void Out(bool b) => Console.WriteLine(b ? "Yes" : "No");

		static void Main(string[] args)
		{
			var N = In;
			var A = In;
			Out(N % 500 <= A);
		}	
	}
}


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

int main() {
    int N, ans = 0, tmp = 0;
    cin >> N;
    int V[N], C[N];
    for(int i=0; i<N; i++) cin >> V[i];
    for(int i=0; i<N; i++) cin >> C[i];
    for(int i=0; i<N; i++) {
        tmp = V[i] - C[i];
        if(tmp > 0) ans += tmp;
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
#include <algorithm>
#include <cmath>
#include <climits>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <fstream>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
#include <cassert>
#include <functional>

using namespace std;

#define LOG(...) printf(__VA_ARGS__)
//#define LOG(...)
#define FOR(i,a,b) for(int i=(int)(a);i<(int)(b);++i)
#define REP(i,n) for(int i=0;i<(int)(n);++i)
#define ALL(a) (a).begin(),(a).end()
#define RALL(a) (a).rbegin(),(a).rend()
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())
#define RSORT(c) sort((c).rbegin(),(c).rend())
#define CLR(a) memset((a), 0 ,sizeof(a))

typedef long long ll;
typedef unsigned long long ull;
typedef vector<bool> vb;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<vb> vvb;
typedef vector<vi> vvi;
typedef vector<vll> vvll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

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

struct UnionFind {
	vector<int> v;
	UnionFind(int n) : v(n) { for (int i = 0; i < n; i++) v[i] = i; }
	int  find(int x) { return v[x] == x ? x : v[x] = find(v[x]); }
	void unite(int x, int y) { v[find(x)] = find(y); }
};
pair<double, double> nor(pair<double, double> a){
	double dist = hypot(a.first,a.second);
	return {a.first/dist,a.second/dist};
}
double dis(pair<double, double> a, pair<double, double> b) {
	return sqrt((a.first - b.first)*(a.first - b.first) + (a.second - b.second)*(a.second - b.second));
}

pair<double, double> sum(pair<double, double> a, pair<double, double> b) {
	return{ a.first + b.first,a.second + b.second };
}

pair<double, double> sub(pair<double, double> a, pair<double, double> b) {
	return{ a.first - b.first,a.second - b.second };
}

pair<double, double> mal(pair<double, double> a, double b) {
	return{ a.first *b,a.second *b };
}
int main() {
	int n;
	while (cin >> n, n) {
		vector<pair<double, double>> point(n);
		REP(i, n)
			cin >> point[i].first >> point[i].second;
		int ans = 1;
		REP(i, n)
			FOR(j, i + 1, n) {
			double d = dis(point[i], point[j]);
			if (d <2.0) {
				int cnt = 2;
				pair<double, double> ba = sub(point[i], point[j]);
				pair<double, double> vba = { -ba.second,ba.first };
				pair<double, double> cen1 = sum(point[j], sum(mal(ba, 0.5), mal(nor(vba), sqrt(1-d*d/4))));
				REP(k, n) {
					if (i == k || j == k)
						continue;
					if (dis(cen1, point[k]) <= 1.0)
						cnt++;
				}
				ans = max(ans, cnt);
				cnt = 2;
				pair<double, double> cen2 = sum(point[j], sum(mal(ba, 0.5), mal(nor(vba), -sqrt(1 - d*d / 4))));
				REP(k, n) {
					if (i == k || j == k)
						continue;
					if (dis(cen2, point[k]) <= 1.0)
						cnt++;
				}

				ans = max(ans, cnt);
			}
		}
		cout << ans << endl;
	}
}

Measured memory_bytes: 3296
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0;i< (n);i++)
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<ll, int> pli;
typedef pair<int, ll> pil;
//long long ccw(const Point& A, const Point& B, const Point& C) {
//	return 1LL * (B.x - A.x)*(C.y - A.y) - 1LL * (B.y - A.y)*(C.x - A.x);
//}
int main() {
	ios_base::sync_with_stdio(false); cin.tie(NULL); /*cout.tie(NULL);*/
	int a, b; cin >> a >> b;
	if (a <= 5) {

		cout << 0 << '\n';
	}
	else if (a <= 12) {

		cout << b/2 << '\n';
	}
	else {
		cout << b << '\n';
	}
	







}


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

int main(){
  int a,b;
  cin >> a >> b;
  
  if(a!=b){
    cout << max(a,b)+(max(a,b)-1) << endl;
  }else{
    cout << max(a,b)*2 << endl;
  }
}


Measured memory_bytes: 256
#include<iostream>
using namespace std;
int main(){
  int h,w;
  cin >> h >> w;
  while(h!=0){
    int i,j;
    for(i=0;i<h;i++){
      for(j=0;j<w;j++){
	if(i==0||i==h-1||j==0||j==w-1)
	  cout << "#";
	else cout << ".";
      }
      cout << endl;
    }
    cout << endl;
    cin >> h >> w;
  }
  return 0;
}



Measured memory_bytes: 3108
#define _USE_MATH_DEFINES
 
#include <bits/stdc++.h>
 
using namespace std;
 
using ll = long long;
 
constexpr ll MOD = 1000000007;
 
#ifndef ONLINE_JUDGE
template <class T, class U>ostream &operator<<(ostream &o, const map<T, U>&obj) {o << "{"; for (auto &x : obj) o << " (" << x.first << " : " << x.second << ")" << ","; o << " }"; return o;}
template <class T>ostream &operator<<(ostream &o, const set<T>&obj) {o << "{"; for (auto itr = obj.begin(); itr != obj.end(); ++itr) o << (itr != obj.begin() ? ", " : "") << *itr; o << "}"; return o;}
template <class T>ostream &operator<<(ostream &o, const multiset<T>&obj) {o << "{"; for (auto itr = obj.begin(); itr != obj.end(); ++itr) o << (itr != obj.begin() ? ", " : "") << *itr; o << "}"; return o;}
template <class T>ostream &operator<<(ostream &o, const vector<T>&obj) {o << "["; for (int i = 0; i < (int)obj.size(); ++i)o << (i > 0 ? ", " : "") << obj[i]; o << "]"; return o;}
template <class T, class U>ostream &operator<<(ostream &o, const pair<T, U>&obj) {o << "(" << obj.first << ", " << obj.second << ")"; return o;}
template <template <class tmp>  class T, class U> ostream &operator<<(ostream &o, const T<U> &obj) {o << "{"; for (auto itr = obj.begin(); itr != obj.end(); ++itr)o << (itr != obj.begin() ? ", " : "") << *itr; o << "}"; return o;}
void print_sim_py(void) {cout << endl;}
template <class Head> void print_sim_py(Head&& head) {cout << head;print_sim_py();}
template <class Head, class... Tail> void print_sim_py(Head&& head, Tail&&... tail) {cout << head << " ";print_sim_py(forward<Tail>(tail)...);}
 
#define print(...) print_sim_py(__VA_ARGS__);
#else
#define print(...);
#endif


int main(void){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
 
    ll n;
    ll ans=0;

    cin >> n;

    vector<ll> a(n);

    for(auto&& x : a){ cin >> x; }

    ll base = a[0];

    for(ll i=0; i<n; i++){
        if(base<a[i])
            base = a[i];
        ll f = base - a[i];
        ans += f;
    }
    
    cout << ans << endl;
 
    return 0;
}



Measured memory_bytes: 4756
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cfloat>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <memory>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <sstream>
#include <deque>
#include <complex>
#include <stack>
#include <queue>
#include <cstdio>
#include <cctype>
#include <cstring>
#include <ctime>
#include <iterator>
#include <bitset>
#include <numeric>
#include <list>
#include <iomanip>
#include <cassert>
#include <array>
#include <tuple>
#include <initializer_list>
#include <unordered_set>
#include <unordered_map>
#include <forward_list>
using namespace std;
using ll = long long;
#define rep(j,k) for (int j = 0; j < (int)(k); j++)


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

    ll n, d;
    while (cin >> n >> d) {
        ll x = d - 1;
        ll y = n - x;
        ll ans = y*(y - 1) / 2 + max(0LL, x - 1) + (x >= 1 ? max(0LL, y - 1) : 0);
        cout << ans << endl;
    }
}

Measured memory_bytes: 3168
#include <iostream>
#include <algorithm>
#include <utility>
#include <string>
#include <vector>
#include <set>
#include <stack>
#include <queue>
#include <map>
#include <math.h>
#include <string.h>
#include <iomanip>
#include <numeric>
#include <cstdlib>
#include <cstdint>
#include <cmath>
#include <functional>
#include <limits>
#include <cassert>

using namespace std;

/* template */

using ll = long long;
using pll = pair<ll, ll>;
using vl = vector<ll>;
using vll = vector<vl>;
using vpll = vector<pll>;

void debug_out() { std::cout << endl; }
 
template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
  cout << H << " ";
  debug_out(T...);
}

#ifdef LOCAL
#define debug(...) cout << "debug: "; debug_out(__VA_ARGS__)
#else
#define debug(...) 
#endif

#define rep(i, a, n) for (int i = (int)(a); i < (int)(n); i++)
#define rrep(i, a, n) for (int i = ((int)(n)-1); i >= (int)(a); i--)
#define Rep(i, a, n) for (long long i = (long long)(a); i< (long long)(n); i++)
#define RRep(i, a, n) for (long long i = ((long long)(n)-1); i>=(long long)(a); i--)
#define all(v) (v).begin(),(v).end()
#define rall(v) (v).rbegin(),(v).rend()

template <typename T>
std::ostream& operator<<(std::ostream& os, std::vector<T> vec) {
  for (std::size_t i = 0; i < vec.size(); i++)os << vec[i] << (i + 1 == vec.size() ? "" : " ");
  return os;
}

struct Edge{
    int to;
    int weight;
    Edge(int t, int w) : to(t), weight(w){ }
};

struct edge{
    int from;
    int to;
    int weight;
    edge(int f,int t,int w) : from(f), to(t), weight(w){ }
};


using Graph = vector<vector<Edge>>;
using graph = vector<vector<int>>;
using edges = vector<edge>;

template <class T>
inline bool chmin(T &a, T b){
    if (a > b){
        a = b;
        return true;
    }
    return false;
}

template <class T>
inline bool chmax(T &a, T b){
    if (a < b){
        a = b;
        return true;
    }
    return false;
}

template <class T>
T lcm(T a, T b){
    return (a*b)/gcd(a,b);
}

bool isPalindrome(string s){
    string t = s;
    reverse(all(t));
    return s==t;
}

constexpr ll INF = 1e9+7;

vector<int> dx = {-1,0,1,0};
vector<int> dy = {0,-1,0,1};

/* template */

int main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    ll k; cin >> k;
    ll n = 50;
    cout << n << endl;
    vector<ll> a(n);
    ll c = k%n;
    ll t = k/n;
    rep(i,0,n){
        a[i] = i+t;
    }
    rep(i,0,c){
        a[i] += n;
        rep(j,0,n){
            if(i==j) continue;
            a[j]--;
        }
    }
    cout << a << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define all(x) x.begin(),x.end()

int const N = 5001;
int n, a[N], b[N], c[N];


int main(){
    scanf("%d",&n);
    for(int i = 0; i<n; ++i){scanf("%d",a+i);--a[i];}
    for(int i = 0; i<n; ++i)scanf("%d",b+i);
    for(int i = 0; i<n-1; ++i){
        scanf("%d", c+i);
    }
    ll an = b[a[0]];
    int prv = a[0];
    for(int i = 1; i<n; ++i){
        an += b[a[i]];
        if(prv+1 == a[i])an += c[prv];
        prv = a[i];
    }
    printf("%lld\n",an);
}

Measured memory_bytes: 256
# 解説の方法

from itertools import accumulate

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

acc = list(accumulate(a))

l = 0
r = 2

ans = float('inf')

for y in range(1,n-2):
    for x in range(l,y-1):
        if abs(acc[y]-acc[x]*2)>=abs(acc[y]-acc[x+1]*2):
            l = x+1
            continue
        else:
            break
    r = max(y+1,r)
    for z in range(r,n-2):
        if abs(acc[n-1]-acc[z]*2+acc[y])>=abs(acc[n-1]-acc[z+1]*2+acc[y]):
            r = z+1
            continue
        else:
            break
    P = acc[l]
    Q = acc[y] - acc[l]
    R = acc[r] - acc[y]
    S = acc[n-1] - acc[r]
    ans = min(ans, max(P,Q,R,S)-min(P,Q,R,S))

print(ans)


Measured memory_bytes: 108920
#include<cstdio>
#include<iostream>
#include<cstdlib>
#include<cmath>
#include<vector>
#include<list>
#include<map>
#include<algorithm>

using namespace std;

long long f(int N, long long X, vector<long long>&a, vector<long long>&p)
{
    if (N == 0) {
        return 1;
    }
    if (X == 1) {
        return 0;
    } else if (X <= 1 + a[N - 1]) {
        return f(N - 1, X - 1, a, p);
    } else if (X == 2 + a[N - 1]) {
        return p[N - 1] + 1;
    } else if (X <= 2 + 2 * a[N - 1]) {
        return p[N - 1] + 1 + f(N - 1, X - 1 - a[N - 1] - 1, a, p);
    } else {
        return 2 * p[N - 1] + 1;
    }

}

int main()
{
    int N;
    long long X;
    cin >> N >> X;

    vector<long long> a;
    vector<long long> p;

    a.push_back(1);
    p.push_back(1);

    for (int i = 1; i <= N; i++) {
        a.push_back(2 * a[i - 1] + 3);
        p.push_back(2 * p[i - 1] + 1);
    }

    cout << f(N, X, a, p) << endl;

    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
    #define forn(i,a,b) for(int i = a; i < b; i++)
    #define all(a) a.begin(),a.end()
    using ll = long long;
    using namespace std;
     
    int N, i;
    int main() {
        cin>>N;
        vector<int> a; a.resize(N);
        forn(i, 0, N) scanf("%i", &a[i]); 
        sort(all(a), greater<int>());
     
        int n = a[0];
     
        int res = INT_MAX;
        int found = a[0];
        forn(i,0,N) {
    	int hf = n/2;
    	int diff =  abs(n-a[i] -hf);
    	if(diff <= res) {
    	    res = diff;
    	    found = a[i];
    	}
        }
     
        cout << n << " " << found << endl;
     
        
    }

Measured memory_bytes: 640
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define maxn 200005
const ll inf=1e9+7;
#define pb push_back
#define PI 3.14159265
#define watch(x) cerr << (#x) << " is " << (x) << endl;
void solve();
void sieve();
int main()
{
	//sieve();
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout<<fixed;
	cout<<setprecision(10);
	
	ll t=1;
	//cin>>t;
	
	while(t--)
	solve();
	return 0;
}
ll pr[1001];
vector<ll> prime;
void sieve()
{
	pr[0]=-1;
	pr[1]=-1;
	ll i,j;
	for(i=2;i<1001;i++)
	{
		if(pr[i]!=-1)
		{
			pr[i]=1;
			for(j=2;j<1001/i+1;j++)
			{
				if(i*j<1001)
				pr[i*j]=-1;
			}
		}
	}
	for(i=2;i<1001;i++)
	{
		if(pr[i]==1)
		prime.pb(i);
	}
}
		
bool pal(string s)
{
	string t=s;
	reverse(s.begin(),s.end());
	return (t==s);
}
ll countdig(ll x)
{
	ll c=0;
	if(x==0)
	return 1;
	
	while(x!=0)
	{
		c++;
		x/=10;
	}
	return c;
}
bool isprime(ll x)
{
	bool flag=true;
	for(ll i=2;i<=sqrt(x)+1;i++)
	{
		if(x%i==0)
		{
			flag=false;
			break;
		}
	}
	if(x==1)
	flag=false;
	
	return flag;
}
void swap(ll& a,ll& b)
{
	ll t=a;
	a=b;
	b=t;
}
class matrix 
{
	public:
	vector<vector<ll>> v;
	ll row;
	ll col;
	matrix(vector<vector<ll>> mat)
	{
		v.assign(mat.begin(),mat.end());
		row=mat.size();
		col=mat[0].size();
	}
	vector<vector<ll>> I(ll n)
	{
		vector<vector<ll>> mat(n,vector<ll>(n,0));
		for(ll i=0;i<n;i++)
		mat[i][i]=1;
		return mat;
	}
	matrix operator * (matrix& u)
	{
		ll r=this->row;
		ll c=u.col;
		assert(this->col==u.row);
		vector<vector<ll>> res(r,vector<ll>(c,0));
		for(ll i=0;i<r;i++)
		{
			for(ll j=0;j<c;j++)
			{
				for(ll k=0;k<this->col;k++)
				res[i][j]+=v[i][k]*u.v[k][j];
			}
		}
		return matrix(res);
	}
	matrix fastexpo(matrix m,ll p)
	{
		assert(m.row==m.col);
		matrix res(I(m.row));
		
		while(p)
		{
			if(p&1)
			res=res*m;
			m=m*m;
			p=p>>1;
		}
		return res;
	}
};
bool comp(ll a,ll b)
{
	return a>b;
}
struct route
{
	ll fir;
	ll tim;
};
void solve()
{
	ll a;
	cin>>a;
	cout<<a+a*a+a*a*a;
}
	
	
	
	
	
	


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

namespace ConsoleApp2
{
	class Program
	{
		static void Main(string[] args)
		{
			var num = int.Parse(Console.ReadLine());
			var w = Console.ReadLine().Split(' ');
			var waightList = new List<int>(num);
			int totalWaight = 0;
			for(int i = 0; i < num; i++)
			{
				int waight = int.Parse(w[i]);
				totalWaight += waight;
				waightList.Add(waight);
			}
			int half = totalWaight / 2;

			int indexS1 = 0;
			int sum = 0;
			for (int i = 0; i < num; i++)
			{
				sum += waightList[i];
				if (half <= sum)
				{
					indexS1 = i;
					break;
				}
			}
			int previousSum = sum - waightList[indexS1];
			if (half - previousSum < sum - half)
			{
				int s1 = previousSum;
				int s2 = totalWaight - previousSum;
				Console.WriteLine(Math.Abs(s1 - s2));
			}
			else
			{
				int s1 = sum;
				int s2 = totalWaight - sum;
				Console.WriteLine(Math.Abs(s1 - s2));
			}
		}
	}
}


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

int main(void){

  long long  a,b,c,d;
  cin>>a>>b>>c>>d;
  long long x1 = (a*c);
  long long x2 = (a*d);
  long long x3 = (b*c);
  long long x4 = (b*d);

  long long ans;
  ans = max(x1,x2);
  ans = max(ans,x3);
  ans = max(ans,x4);

  cout<<ans<<endl;
}


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

using namespace std;

typedef long long ll;
typedef long double ld;
typedef pair<int  ,int > pii;

mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

const ll maxn  = 3e6;
const ll mod =1e9+7;
const ld PI = acos((ld)-1);

#define pb(x) push_back(x);
#define endl '\n'
#define dokme(x) cout << x ;  return(0);
#define migmig ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define ms(x , y) memset(x , y , sizeof x);
#define file_init freopen("input.txt", "r+", stdin); freopen("output.txt", "w+", stdout);
ll pw(ll a, ll b, ll md = mod){ll res = 1;while(b){if(b&1){res=(a*res)%md;}a=(a*a)%md;b>>=1;}return(res);}

int n , x , y;
int dist[3000][3000];
int cnt[maxn];

int main(){
    migmig
    cin >> n >> x >> y;
    ms(dist , 63);
    for(int i = 1 ; i <= n ; i ++){
        for(int j = i ; j <= n ; j ++){
            dist[i][j] = j - i;
        }
    }
    for(int i = 1 ; i <= n ; i ++){
        for(int j = i+1 ; j <= n ; j ++){
            dist[i][j] = min(dist[i][j] , dist[i][x] + dist[y][j] + 1);
            dist[i][j] = min(dist[i][j] , dist[x][i] + dist[y][j] + 1);
            dist[i][j] = min(dist[i][j] , dist[i][x] + dist[j][y] + 1);
            dist[i][j] = min(dist[i][j] , dist[x][i] + dist[j][y] + 1);
            dist[i][j] = min(dist[i][j] , dist[i][y] + dist[x][j] + 1);
            dist[i][j] = min(dist[i][j] , dist[i][y] + dist[j][x] + 1);
            dist[i][j] = min(dist[i][j] , dist[y][i] + dist[x][j] + 1);
            dist[i][j] = min(dist[i][j] , dist[y][i] + dist[j][x] + 1);
            cnt[dist[i][j]]++;
        }
    }
    for(int i = 1 ; i < n ; i ++){
        cout << cnt[i] << endl;
    }

    return(0);
}

//When we hit our lowest point, we are open to the greatest change.
//If I try, I fail. If I don't try, I'm NEVER GOING TO GET IT.
//Sometimes, life is like this dark tunnel. You can't always see the light at the end of the tunnel. But if you just keep moving... you will come to a better place.
//It is important to draw wisdom from diffrent places. If you take it from only one place it becomes rigid and stale.
//kuxtal jach uts chuchul u u páajtal máak jach táaj meyajilo'ob le castigadas tumen ch'aik descansos.


Measured memory_bytes: 36992
#include<bits/stdc++.h>
using namespace std;
#define sc scanf
#define pr printf
#define pb push_back
#define ll long long int
#define rp
int main()
{
   int n;
   cin>>n;
   if(n%2)
    cout<<n*2<<endl;
   else
    cout<<n<<endl;
    return 0;

}

Measured memory_bytes: 256
import java.util.Comparator;
import java.util.Map;
import java.util.Scanner;
import java.util.Set;
import java.util.TreeMap;
import java.util.TreeSet;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		String[] town = new String[N];
		Set<String> town2 = new TreeSet<>();
		int[] point = new int[N];
		for(int i=0;i<N;i++) {
			town[i]=sc.next();
			town2.add(town[i]);
			point[i]=sc.nextInt();
		}

		for(String s: town2) {
			Map<Integer,Integer> nums = new TreeMap<>(Comparator.reverseOrder());
			for(int i=0;i<N;i++) {
				if(s.equals(town[i])) {
					nums.put(point[i],i+1);
				}
			}

			for(Integer n : nums.keySet()) {
				System.out.println(nums.get(n));
			}
		}

	}
}

Measured memory_bytes: 23124
import java.util.*;
public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        String line = sc.nextLine();
        String[] line1 = line.split(" ");
        int p = Integer.parseInt(line1[0]);
        int q = Integer.parseInt(line1[1]);
        int r = Integer.parseInt(line1[2]);
        int min = p + q;
        if(p + r < min)
        min = p + r;
        if(q + r < min)
        min = q + r;
        System.out.println(min);
    }
}

Measured memory_bytes: 21844
#include<bits/stdc++.h>
#define M 100005
using namespace std;
int n,A[M];
multiset<int>S;
multiset<int>::iterator it;
int main(){
	scanf("%d",&n);
	for(int i=1;i<=n;i++)scanf("%d",&A[i]);
	int ans=0;
	for(int i=1;i<=n;i++){
		it=S.lower_bound(A[i]);
		if(S.size()&&it!=S.begin())S.erase(--it);
		else ans++;
		S.insert(A[i]);
	}
	printf("%d\n",ans);
	return 0;
}

Measured memory_bytes: 5376
import java.util.*;
import static java.lang.System.*;
import java.math.*;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int a = sc.nextInt();
		int b = sc.nextInt();
		if ( a < 1 || b < 1 || a > 9 || b > 9)
			out.println(-1);
		else
			out.print(a * b);
		
	}
}


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

int main() {
  int N;
  cin >> N;
  map<int,int> MD;
  for (int i = 0; i < N; i++) {
    int x;
    cin >> x;
    MD[x] += 1;
  }
  
  int M;
  cin >> M;
  for (int i = 0; i < M; i++) {
    int x;
    cin >> x;
    MD[x] -= 1;
  }
  
  for (auto m : MD) {
    if (MD[m.first] < 0) {
      cout << "NO" << endl;
      return 0;
    }
  }
  cout << "YES" << endl;
}


Measured memory_bytes: 9600
import java.util.Scanner;

public class Main {
	public static void main(String[] args) throws Exception {
		Scanner sc = new Scanner(System.in);
		long a = sc.nextLong();
		long b = sc.nextLong();
		long k = sc.nextLong();
		sc.close();

		long aa = a - k;
		if (aa < 0) aa = 0;
		k -= a;
		if (k > 0) {
			b -= k;
			if (b < 0) b = 0;
		}
		System.out.println(aa + " " + b);
	}
}


Measured memory_bytes: 22608
import itertools

N, M, Q = map(int, input().split())
abcd_list = [ list(map(int, input().split())) for _ in range(Q) ]

com_list = list(itertools.combinations_with_replacement(range(M), N))
ans = 0
for com in com_list:
    tmp = 0
    for abcd in abcd_list:
        if (com[abcd[1]-1] - com[abcd[0]-1]) == abcd[2]:
            tmp += abcd[3]
    ans = max(ans, tmp)
print(ans)

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

using namespace std;

typedef long long ll;

int N, K;
vector<int> a;
vector<bool> dp;

bool p1_win(int k) {
    for (int x : a)
        if (x <= k && !dp[k - x])
            return true;
    return false;
}

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    cin >> N >> K;
    a.resize(N);
    for (int i = 0; i < N; i++)
        cin >> a[i];
    dp.resize(K + 1);
    for (int k = 0; k <= K; k++)
        dp[k] = p1_win(k);
    cout << (dp[K] ? "First" : "Second") << endl;
}


Measured memory_bytes: 256
#include<stdio.h>

int main(){
   int N,M;
   scanf("%d %d",&N,&M);
   int sum;
   int x,y;
   x=N*(N-1)/2;
   y=M*(M-1)/2;

   sum=x+y;

   printf("%d\n",sum);
   return 0;
}


Measured memory_bytes: 1732
#include <cstdio>
#include <vector>
using namespace std;
const int MAXV = 1e4 + 7, MAXE = 1e5 + 7;
int anspos;
bool vis[MAXV];
int ans[MAXE];
vector <int> G[MAXV];
void dfs(int cur) {
	vis[cur] = true;
	for (int i = 0; i < G[cur].size(); i++) {
		if (!vis[G[cur][i]]) dfs(G[cur][i]);
	}
	ans[--anspos] = cur;
}
int main() {
    int v, e;
    scanf("%d%d", &v, &e);
    anspos = v;
    while (e--) {
    	int s, t;
    	scanf("%d%d", &s, &t);
    	G[s].push_back(t);
	}
	for (int i = 0; i < v; i++) {
		if (!vis[i]) dfs(i);
	}
	for (int i = 0; i < v; i++) {
		printf("%d\n", ans[i]);
	}
	return 0;
}


Measured memory_bytes: 3312
# -*- coding: utf-8 -*-
"""
AtCoder A
"""

import sys, math, random
import numpy as np

# N = int(input())
# A = list(map(int,input().split())) # N row 1 column
# A = [int(input()) for _ in range(N)] # 1 row N column
# S = str(input()) # str(input()) == input() -> 'abc'
# S = list(input()) # abc -> ['a','b','c']
# S.replace('ABC','X') # "testABCABC" -> "testXX"

inf = 10**20
eps = 1.0 / 10**10
mod = 10**9+7
dd = [(-1,0),(0,1),(1,0),(0,-1)]
ddn = [(-1,0),(-1,1),(0,1),(1,1),(1,0),(1,-1),(0,-1),(-1,-1)]

def LI(): return list(map(int, sys.stdin.readline().split()))
def LLI(): return [list(map(int, l.split())) for l in sys.stdin.readlines()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def S(): return input()


def main():
    N=I()
    print(int(N*(N-1)//2))

if __name__ == "__main__":
    main()

Measured memory_bytes: 13464
import java.util.Arrays;
import java.util.Scanner;

public class Main {

    long MAX = (long)1e15;

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

        int n = sc.nextInt();
        int k = sc.nextInt();
        long[] ar = new long[n + k + 10];
        long[] dp = new long[k + 1];

        for (int i = 0; i < n; i++) {
            ar[i] = sc.nextLong();
        }

        Arrays.fill(dp, MAX);
        dp[0] = 0;

        for (int i = 0; i < n - 1; i++) {
            int idx = i % (k + 1);
            for (int j = 1; j <= k; j++) {
                int next  = (idx + j) % (k + 1);
                dp[next]  = Math.min(dp[next], dp[idx] + Math.abs(ar[i] - ar[i + j]));
            }
            dp[idx] = MAX;
        }
//        debug(dp);
        System.out.println(dp[(n - 1) % (k + 1)]);
    }

    void debug(Object... os) {
        System.err.println(Arrays.deepToString(os));
    }

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


Measured memory_bytes: 60948
#include<iostream>
#include<map>
#include<vector>
#include<algorithm>
#include<cstdint>
#include<cstdlib>
#include<string>
template<typename T>
void fin(T const& t){ std::cout << t << std::endl; exit(0); }

int main() {
  int N; std::cin >> N;
  std::vector<std::pair<int64_t, int64_t>> pls, mis;
  int64_t sum = 0;
  for(int i = 0; i < N; ++i) {
    int mi = 0, cur = 0;
    std::string S; std::cin >> S;
    for(auto s: S) {
      if(s == ')') --cur; else ++cur;
      mi = std::min(mi, cur);
    }
    if(mi != 0 || cur != 0) {
      if(cur >= 0) pls.emplace_back(mi, cur);
      else         mis.emplace_back(mi, cur);
    }
    sum += cur;
  }
  if(sum != 0) fin("No");

  std::sort(pls.begin(), pls.end(),
    [&](auto const& l, auto const& r)->bool { return l.first > r.first; });
  for(auto p: pls) {
    if(sum + p.first < 0) fin("No");
    sum += p.second;
  }
  std::sort(mis.begin(), mis.end(),
    [&](auto const& l, auto const& r)->bool { return l.first-l.second < r.first-r.second; });
  for(auto p: mis) {
    if(sum + p.first < 0) fin("No");
    sum += p.second;
  }
  fin("Yes");
  return 0;
}


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

void reg(int& x,int m){
  x%=m;
  x+=m;
  x%=m;
  return;
}

int main(){
  int h,w;
  while(cin>>h>>w,h){
    vector<string> s(h);
    for(int i=0;i<h;i++) cin>>s[i];
    vector<int> dh={1,-1,0,0,1,1,-1,-1};
    vector<int> dw={0,0,1,-1,1,-1,1,-1};
    map<string,int> dic;
    for(int i=0;i<h;i++){
      for(int j=0;j<w;j++){
	for(int dir=0;dir<8;dir++){
	  string st="";
	  for(int k=0;;k++){
	    int ih=i+dh[dir]*k;
	    reg(ih,h);
	    int jw=j+dw[dir]*k;
	    reg(jw,w);
	    if(k!=0 && i==ih && j==jw) break;
	    st+=s[ih][jw];
	    if(k==0) continue;
	    dic[st]++;
	  }
	}
      }
    }
    string res="";
    for(auto it=dic.begin();it!=dic.end();it++){
      string st=it->first;
      int cnt=it->second;
      if(cnt>1){
	if(st.size()>res.size()){
	  res=st;
	}
	else if(st.size()==res.size()){
	  res=min(res,st);
	}
      }
    }

    cout<<(res!="" ? res : "0")<<endl;
  }
  return 0;

}

Measured memory_bytes: 38036
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define pi 3.141592653589793238
#define fast ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define MOD 1000000007
int main()
{
	fast;
	ll h,w,ans=0;
	cin>>h>>w;
	char val[h+3][w+3];
	for(int i=1;i<=h;i++)
		for(int j=1;j<=w;j++)
			cin>>val[i][j];
	ll l[h+3][w+3]{};
	ll r[h+3][w+3]{};
	ll u[h+3][w+3]{};
	ll d[h+3][w+3]{};
	for(int i=1;i<=h;i++)
		for(int j=1;j<=w;j++)
			if(val[i][j]=='.')
				l[i][j]=l[i][j-1]+1;
	for(int i=1;i<=h;i++)
		for(int j=w;j>=1;j--)
			if(val[i][j]=='.')
				r[i][j]=r[i][j+1]+1;
	for(int j=1;j<=w;j++)
		for(int i=1;i<=h;i++)
			if(val[i][j]=='.')
				d[i][j]=d[i-1][j]+1;
	for(int j=w;j>=1;j--)
		for(int i=h;i>=1;i--)
			if(val[i][j]=='.')
				u[i][j]=u[i+1][j]+1;
	for(int i=1;i<=h;i++)
		for(int j=1;j<=w;j++)
			if(val[i][j]=='.')
				ans=max(ans,l[i][j]+r[i][j]+u[i][j]+d[i][j]-3);
	cout<<ans;
	return 0;
}


Measured memory_bytes: 132948