akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;

typedef long long ll;
typedef unsigned int ui;
typedef unsigned long ul;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int,int> ii;
typedef vector<ii> vii;
const int inf = int (1e9) + int (1e5);
const ll infl = ll (2e18) + ll (1e10);
const ui M=1E9+7;
const double eps = 1e-9;

int main()
{
    std::ios_base::sync_with_stdio (false);
   // freopen ("in.txt", "r", stdin); /// indica que se lee desde stdin

    int n;
    cin >> n;
    ll a[n];
    vector<ll> s(n);
    for (int i=0;i<n;i++){
        cin >> a[i];
        if (i>0)
            s[i] = s[i-1] + a[i];
        else
            s[0]=a[0];
    }
    ll n2=s[n-1]/2;
    ll m=infl;
    int imin=0;
    for (int i=0;i<n-1;i++){
        if (abs(s[i]-n2)<m){
            m=abs(s[i]-n2);
            imin=i;
        }
    }
    cout << abs(s[imin] - (s[n-1]-s[imin]));

    return 0;
}


Measured memory_bytes: 3328
from itertools import accumulate
n,k = map(int,input().split())
a = list(map(int,input().split()))
suma = 0
for i in range(k,n):
  suma += max(0,a[i])
acca = [0]+list(accumulate(a))
ans = [max(suma,suma+acca[k])]
for i in range(1,n-k+1):
  suma += max(0,a[i-1])
  suma -= max(0,a[i+k-1])
  ans.append(max(suma,suma+acca[i+k]-acca[i]))
print(max(ans))

Measured memory_bytes: 16064
#include <iostream>

const int N = 1000 + 7;

int m, n;
int a[N][N];

int main() {
//	freopen("code.in", "r", stdin);
//	freopen("code.out", "w", stdout);

	scanf("%d", &m), n = std::min(m, 500);
	printf("%d\n", n);
	for (int i = 0; i < n; ++i) {
		for (int j = 0, k = i, l = 1; j != n; ++j, k = (k + 1) % n, l ^= 1)
			a[j][k] = (m > n && l ? m : i + 1);
		if (m > n) --m;
	}
	for (int i = 0; i < n; ++i) {
		for (int j = 0; j < n; ++j) printf("%d ", a[i][j]);
		printf("\n");
	}
	return 0;
}


Measured memory_bytes: 3200
#include<bits/stdc++.h>
using namespace std;
int N;
int solve() {
    vector<int>a(N);
    for(int i=0;i<N;i++){
    cin >>a.at(i);
    }
    sort(a.begin(),a.end());
    int sum=0;
    for(int i=1;i<N-1;i++) {
        sum +=a.at(i);
    }
    return sum/(N-2);
}
int main(){
    while(cin >> N && N>0) {
        cout << solve() << endl;
    }
}


Measured memory_bytes: 3100
#include<bits/stdc++.h>
using namespace std;
#define N 100005
int cnt[2],a[N];
bool b[N];
int n,m,x,y;
bool flag=1;
vector<int> v[N];
void dfs(int now)
{
	int top=v[now].size();
	b[now]=1,cnt[a[now]]++;
	for(int i=0;i<top&&flag;i++)
	{
		int to=v[now][i];
		if(!b[to]) a[to]=a[now]^1,dfs(to);
		else if(a[to]==a[now]){flag=0;return;}
	}
}
int main()
{
	scanf("%d%d",&n,&m);
	for(int i=1;i<=m;i++)
	  scanf("%d%d",&x,&y),v[x].push_back(y),v[y].push_back(x);
	dfs(1);
	if(!flag) printf("%lld",((1ll*n*(n-1))>>1)-m);
	else printf("%lld",1ll*cnt[0]*cnt[1]-m);
	return 0;
}

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

int a, b, c;

int main() {
    cin >> a >> b >> c;
    
    if (a <= b && a <= c) {
        cout << a << " ";
        if (b <= c) {
            cout << b << " " << c << endl;
        } else {
            cout << c << " " << b << endl;
        }
    } else if (b <= c && b <= a) {
        cout << b << " ";
        if (a <= c) {
            cout << a << " " << c << endl;
        } else {
            cout << c << " " << a << endl;
        }
    } else {
        cout << c << " ";
        if (a <= b){
            cout << a << " " << b << endl;
        } else {
            cout << b << " " << a << endl;
        }
    }
    return 0;
}


Measured memory_bytes: 3092
#include <iostream>

using namespace std;

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



Measured memory_bytes: 3032
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int h = sc.nextInt();
        int w = sc.nextInt();

        for (int i = 0; i < w + 2; i++) {
            System.out.print('#');
        }
        System.out.println();

        for (int i = 0; i < h; i++) {
            System.out.print('#');

            String s = sc.next();
            System.out.print(s);
            
            System.out.print('#');
            System.out.println();
        }

        for (int i = 0; i < w + 2; i++) {
            System.out.print('#');
        }
    }
}


Measured memory_bytes: 23764
#include<iostream>
#include<string>
#include<cstdio>
#include<vector>
#include<cmath>
#include<algorithm>
#include<functional>
#include<iomanip>
#include<queue>
#include<ciso646>
#include<random>
#include<map>
#include<set>
#include<complex>
#include<bitset>
#include<stack>
#include<unordered_map>
#include<utility>
using namespace std;
typedef long long ll;
typedef unsigned int ui;
const ll mod = 1000000007;
const ll INF = (ll)1000000007 * 1000000007;
typedef pair<int, int> P;
#define stop char nyaa;cin>>nyaa;
#define rep(i,n) for(int i=0;i<n;i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define per1(i,n) for(int i=n;i>=1;i--)
#define Rep1(i,sta,n) for(int i=sta;i<=n;i++)
typedef long double ld;
typedef complex<ld> Point;
const ld eps = 1e-2;
const ld pi = acos(-1.0);
typedef pair<ll, ll> LP;

int n, m;
bitset<400> b[400];
bool ok[400];
int main() {
	cin >> n >> m;
	fill(ok, ok + n, true);
	rep(i, m) {
		int x, y; cin >> x >> y; x--; y--;
		if (ok[x]) {
			if (b[x][y]||!ok[y]) {
				ok[x] = false;
			}
			else {
				b[x][y] = true;
			}
		}
		if (ok[y]) {
			if (b[y][x]||!ok[x]) {
				ok[y] = false;
			}
			else {
				b[y][x] = true;
			}
		}
		rep(j, n) {
			if (j == x || j == y)continue;
			if (b[j][x])b[j][y] =b[y][j]= true;
			if (b[j][y])b[j][x] =b[x][j]= true;
		}
	}
	int cnt = 0;
	rep(i, n) {
		Rep(j, i + 1, n) {
			if (!ok[i])continue;
			if (!ok[j])continue;
			if (b[i][j]||b[j][i])continue;
			cnt++;
		}
	}
	cout << cnt << endl;
	//stop
	return 0;
}

Measured memory_bytes: 256
package main

import (
	"fmt"
)

func main() {
	var s []byte
	var zCount, oCount int
	var zero byte
	fmt.Scan(&s)
	zero = '0'

	for i := range s {
		if s[i] == zero {
			zCount++
		} else {
			oCount++
		}
	}

	if zCount < oCount {
		fmt.Println(zCount * 2)
	} else {
		fmt.Println(oCount * 2)
	}

}


Measured memory_bytes: 1408
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
const ll INF=1LL<<60;
const double EPS = 1e-10;
const ll mod=1000000007;

ll a[200100];

int main(void){
    ll n,k,zero=0,plus=0,mainasu=0;
    cin>>n>>k;
    for(int i=0;i<n;i++){
        cin>>a[i];
        if(a[i]==0) zero++;
        else if(a[i]>0) plus++;
        else mainasu++;
    }
    ll ans=1;
    sort(a,a+n);
    reverse(a,a+n);
    ll L=0,R=n-1;
    for(int i=1;i<=k;){
        if(i==k){
            ans*=a[L];
            ans%=mod;
            i++;
            L++;
        }
        else if(a[L]*a[L+1]>a[R]*a[R-1]){
            ans*=a[L];
            ans%=mod;
            L++;
            i++;
        }
        else{
            ans*=a[R];
            ans%=mod;
            R--;
            ans*=a[R];
            ans%=mod;
            R--;
            i+=2;
        }
    }
    if(plus==0){
        ans=1;
        if(k%2==0){
            for(int i=0;i<k;i++){
            ans*=a[n-1-i];
            ans%=mod;
            }
        }
        else if(zero>0) ans=0;
        else{
            for(int i=0;i<k;i++){
            ans*=a[i];
            ans%=mod;
        }
        }
    }
    ans+=mod;
    ans%=mod;
    cout<<ans<<endl;
}

Measured memory_bytes: 5180
// lcmとか__builtin_popcountとかはg++ -std=c++17 default.cppみたいなかんじで

#include <bits/stdc++.h>
#define mod 1000000007
#define INF LLONG_MAX
#define ll long long
#define ln cout<<endl
#define Yes cout<<"Yes"<<endl
#define NO cout<<"NO"<<endl
#define YES cout<<"YES"<<endl
#define No cout<<"No"<<endl
#define REP(i,m,n) for(ll i=(ll)(m);i<(ll)(n);i++)
#define rep(i,n) REP(i,0,n)
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
using namespace std;
ll dx[4]={1,0,-1,0};
ll dy[4]={0,1,0,-1};

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

    ll  a,b,c,d,e,n,k,maxi=0,f=0,mini=INF,sum=0,q;
	string str,stra,straa;
    ll x,y,z;
    char ca,cb,cc;
    cin>>n;
    vector<ll> v(n);
    set<ll> s;
    rep(i,n) cin>>v[i];
    rep(i,n) s.insert(v[i]);

    if(v.size()==s.size()) YES;
    else NO;
    return 0;
}


Measured memory_bytes: 14276
import java.io.*;
import java.util.*;
import java.util.Map.Entry;
import java.util.stream.Collectors;

@SuppressWarnings("unused")
public class Main {
	String fileName = "input.txt";
	final boolean isDebug = false;
	//final boolean isDebug = true;
	FastScanner in = new FastScanner(System.in);
	PrintWriter out = new PrintWriter(System.out);
	final int MOD = (int)1e9+7;
	final long INF = Long.MAX_VALUE / 2;
	//final int INF = Integer.MAX_VALUE / 2;
	
	void solve() throws Exception{
		int N = in.nextInt(), K = in.nextInt();
		
		if(K == 0){
			System.out.println((long)N*N);
		}else{
			long ans = 0;
			for(int b = K + 1; b <= N; b++){
				long num = N / b;
				int q = N % b;
				ans += num * (b - K);
				if(q >= K) ans += (q - K + 1);
			}
			System.out.println(ans);
		}
	}
	
	/* end solve */
	
	/* main */
	public static void main(String[] args) throws Exception {
		new Main().m();
	}
	
	void m() throws Exception {
		if(isDebug) in = new FastScanner(new FileInputStream(fileName));
		solve();
		out.flush();
	}
	/* end main */
}
/* end Main */

class FastScanner {
	Reader input;

	FastScanner() {this(System.in);}
	FastScanner(InputStream stream) {this.input = new BufferedReader(new InputStreamReader(stream));}
	
	int nextInt() {return (int) nextLong();}

	long nextLong() {
		try {
			int sign = 1;
			int b = input.read();
			while ((b < '0' || '9' < b) && b != '-' && b != '+') {
				b = input.read();
			}
			if (b == '-') {
				sign = -1;
				b = input.read();
			} else if (b == '+') {
				b = input.read();
			}
			long ret = b - '0';
			while (true) {
				b = input.read();
				if (b < '0' || '9' < b) return ret * sign;
				ret *= 10;
				ret += b - '0';
			}
		} catch (IOException e) {
			e.printStackTrace();
			return -1;
		}
	}

	double nextDouble() {
		try {
			double sign = 1;
			int b = input.read();
			while ((b < '0' || '9' < b) && b != '-' && b != '+') {
				b = input.read();
			}
			if (b == '-') {
				sign = -1;
				b = input.read();
			} else if (b == '+') {
				b = input.read();
			}
			double ret = b - '0';
			while (true) {
				b = input.read();
				if (b < '0' || '9' < b) break;
				ret *= 10;
				ret += b - '0';
			}
			if (b != '.') return sign * ret;
			double div = 1;
			b = input.read();
			while ('0' <= b && b <= '9') {
				ret *= 10;
				ret += b - '0';
				div *= 10;
				b = input.read();
			}
			return sign * ret / div;
		} catch (IOException e) {
			e.printStackTrace();
			return Double.NaN;
		}
	}

	char nextChar() {
		try {
			int b = input.read();
			while (Character.isWhitespace(b)) {
				b = input.read();
			}
			return (char) b;
		} catch (IOException e) {
			e.printStackTrace();
			return 0;
		}
	}

	String nextStr() {
		try {
			StringBuilder sb = new StringBuilder();
			int b = input.read();
			while (Character.isWhitespace(b)) {
				b = input.read();
			}
			while (b != -1 && !Character.isWhitespace(b)) {
				sb.append((char) b);
				b = input.read();
			}
			return sb.toString();
		} catch (IOException e) {
			e.printStackTrace();
			return "";
		}
	}
}

Measured memory_bytes: 21076
n,k=map(int,input().split())
mod=10**9+7
left=0
right=0
ans=[]
ans.append(n+1)
for i in range(1,n+2):
  left+=((i-1)%mod)
  right+=((n-i+1)%mod)
  ans.append(right-left+1)

print(sum(ans[k:])%mod)

Measured memory_bytes: 21412
#include <bits/stdc++.h>
#define ll long long
#define vi vector <int>
#define vll vector<ll>
#define ii pair<ll,ll>
#define vii vector<ii>
#define F first
#define S second
#define INF 1000000000000000000
#define pi atan(1)*4
#define MOD 1000000000+7L
#define eps 0.0000006
#define MAX_V 10000
 
using namespace std;
 
int main() {
	ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);
	int a,b;
	cin >> a >> b;
	cout << max(0,a-(b*2)) << '\n';
	return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<queue>
#include<fstream>
using namespace std;
typedef pair<int,int> P;
struct edge{int from; int to; int cost;};
int V,E,r;
int a,b,c;
int u,v;
long int d[100000];
int dflag[100000];
long int inf=1<<30;
vector<edge> G[100000];
priority_queue<P,vector<P>,greater<P>> q;

int main(){
    edge e,ee;
    cin >> V >> E >> r;
    for(int i=0;i<E;i++){
        cin >> a >> b >> c;
        ee.from = a;
        ee.to = b;
        ee.cost = c;
        G[a].push_back(ee);
        G[b].push_back(ee);
    }
    //cout << G[0].size() << endl;
    fill(d,d+V,inf);
    
    q.push(P(0,r));
    d[r] = 0;
    while(!q.empty()){
        P p = q.top();q.pop();
        int v = p.second; 
        if(dflag[v] == 1){
            //cout << "hit" << endl;
            continue;
        }
        for(int i=0;i<G[v].size();i++){
            edge e = G[v][i];
            if(d[e.to] > p.first + e.cost){
                d[e.to] = p.first + e.cost;
                q.push(P(d[e.to],e.to));
                //cout << d[e.to] << " " << e.to << endl;
            }
        }
        dflag[v] = 1;
    }

    ofstream outputfile("kakomon56.text");

    for(int i=0;i<V;i++){
        if(d[i] >= inf){
            cout << "INF" << endl;
            outputfile << "INF\n"; 
            continue;
        }
        cout << d[i] << endl;
        outputfile << d[i] << endl;
    }
    outputfile.close();
    return 0;
}


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

typedef long long ll;
const ll INF = 1e18;
const ll MOD = 1e9 + 7;
const int BIG = 1e9 + 555;
const int maxN = 2000 + 555;

int n, m;
int s[maxN], t[maxN];

ll memo[maxN][maxN];
ll memop[maxN][maxN];

void update(int r){
	for(int i = 0; i <= m; i++){
		memop[r + 1][i + 1] = (memop[r + 1][i] + memo[r][i]) % MOD;
	}
	for(int i = 0; i <= m; i++){
		memop[r + 1][i + 1] = (memop[r][i + 1] + memop[r + 1][i + 1]) % MOD;
		//cerr << r + 1 << ' ' << i + 1 << ' ' << memop[r + 1][i + 1] << '\n';
	}
}

ll range(int x, int y, int u, int v){
	x++;	y++;	u++;	v++;
	return ((memop[u][v] - memop[x - 1][v] - memop[u][y - 1] + memop[x - 1][y - 1]) % MOD + MOD) % MOD;
}

int main(){
	ios::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	
	cin >> n >> m;
	
	for(int i = 1; i <= n; i++){
		cin >> s[i];
	}

	for(int j = 1; j <= m; j++){
		cin >> t[j];
	}

	memo[0][0] = 1;
	update(0);
	
	ll fRes = 0;
	for(int i = 1; i <= n; i++){
		for(int j = 1; j <= m; j++){
			if(s[i] != t[j]){
				continue;
			}
			//for(int ii = 0; ii < i; ii++){
			//	for(int jj = 0; jj < j; jj++){
			//		memo[i][j] += memo[ii][jj];
			//	}
			//}
			memo[i][j] = range(0, 0, i - 1, j - 1);
			fRes = (fRes + memo[i][j]) % MOD;
		}

		update(i);
	}

	cout << (fRes + 1) % MOD << '\n';

	return 0;
}

Measured memory_bytes: 84224
x, y = map(int, input().split())
a = (4 * x - y) / 2
b = (y - 2 * x) / 2
if ((a >= 0) & (b >= 0) & (a.is_integer() == True) & (b.is_integer() == True)):
  print('Yes')
else:
  print('No')

Measured memory_bytes: 9176
inp_st = input()
n = int(inp_st)
s_dictionary = {}
for i in range(n):
    inp_st = input()
    split_input = inp_st.split()
    s = split_input[0]
    p = int(split_input[1])
    if s in s_dictionary:
        p_dictionary = s_dictionary[s]
        p_dictionary[p] = i + 1
    else:
        p_dictionary = {}
        p_dictionary[p] = i + 1
        s_dictionary[s] = p_dictionary

s_list = sorted(s_dictionary.keys())
for k_s in s_list:
    p_dictionary = s_dictionary[k_s]
    p_list = sorted(p_dictionary.keys())
    for k_p in reversed(p_list):
        print(p_dictionary[k_p])


Measured memory_bytes: 3064
#include <cstdio>
#include <cctype>
#include <algorithm>
#include <vector>
#include <random>
#include <ctime>
using namespace std;
using ll = long long;

namespace io {
#define File(s) freopen(s".in", "r", stdin), freopen(s".out", "w", stdout)
  const int SIZE = (1 << 21) + 1;
  char ibuf[SIZE], *iS, *iT, obuf[SIZE], *oS = obuf, *oT = oS + SIZE - 1;
  inline char getc () {return (iS == iT ? (iT = (iS = ibuf) + fread (ibuf, 1, SIZE, stdin), (iS == iT ? EOF : *iS ++)) : *iS ++);}
  inline void flush () {fwrite (obuf, 1, oS - obuf, stdout); oS = obuf;}
  inline void putc (char x) {*oS ++ = x; if (oS == oT) flush ();}
  template<class T>
  inline void read(T &x) {
    char ch; int f = 1;
    x = 0;
    while(isspace(ch = getc()));
    if(ch == '-') ch = getc(), f = -1;
    do x = x * 10 + ch - '0'; while(isdigit(ch = getc()));
    x *= f;
  }
  template<class T, class ...Args>
  inline void read(T &x, Args&... args) {read(x); read(args...);}
  template<class T>
  inline void write(T x) {
    static char stk[128];
    int top = 0;
    if(x == 0) {putc('0'); return;}
    if(x < 0) putc('-'), x = -x;
    while(x) stk[top++] = x % 10, x /= 10;
    while(top) putc(stk[--top] + '0');
  }
  inline void write(const char *s) {for(; *s; ++s) putc(*s);}
  template<class T, class ...Args>
  inline void write(T x, Args... args) {write(x); putc(' '); write(args...);}
  inline void space() {putc(' ');}
  inline void endl() {putc('\n');}
  struct _flush {~_flush() {flush();}} __flush;
};
using io::read; using io::write; using io::flush; using io::space; using io::endl; using io::getc; using io::putc;

const int N = 200005;
int a[N], b[N];
int ca[N], cb[N], cc[N];

void dec_a(int x) {
  --cc[ca[x] + cb[x]];
  --ca[x];
  ++cc[ca[x] + cb[x]];
}
void dec_b(int x) {
  --cc[ca[x] + cb[x]];
  --cb[x];
  ++cc[ca[x] + cb[x]];
}

mt19937 rnd(time(0));
int randint(int l, int r) {
  return rnd() % (r - l + 1) + l;
}

int main() {
  int n;
  read(n);
  for (int i = 1; i <= n; ++i) read(a[i]), ++ca[a[i]];
  for (int i = 1; i <= n; ++i) read(b[i]), ++cb[b[i]];
  for (int i = 1; i <= n; ++i) {
    if (ca[i] + cb[i] > n) {
      write("No\n");
      return 0;
    }
    ++cc[ca[i] + cb[i]];
  }
  write("Yes\n");
  for (int i = 1; i <= n; ++i) {
    if (cc[n - i + 1]) {
      int mode = 0;
      for (int v = 1; v <= n; ++v)
        if (ca[v] + cb[v] == n - i + 1) {
          mode = v;
          break;
        }
      static int nonM[N];
      int cnt = 0;
      for (int j = i; j <= n; ++j)
        if (b[j] != mode)
          nonM[++cnt] = b[j];
      for (int j = i; j <= n; ++j)
        if (a[j] == mode) b[j] = nonM[cnt--];
        else b[j] = mode;
      break;
    }
    if (a[i] == b[i]) {
      int q = randint(i, n);
      while (a[i] == b[q]) q = randint(i, n);
      swap(b[i], b[q]);
    }
    dec_a(a[i]), dec_b(b[i]);
  }
  for (int i = 1; i <= n; ++i)
    write(b[i]), space();
  endl();
  return 0;
}

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

public class Main {

	private static Scanner in;
	private static int n;
	private static int k;
	private static int[] h;
	private static long[] dp;
	
	public static void main(String[] args) {
		in = new Scanner(System.in);
		n = in.nextInt();
		k = in.nextInt();
		h = new int[n];
		
		for(int i=0; i<n; i++) {
			h[i] = in.nextInt();
		}
		dp = new long[n+1];
		
		Arrays.fill(dp, -1);
		
		System.out.println(solve(0));
		

	}
	
	private static long solve(int i) {
		if (i==n-1) return 0;
		
		if (dp[i]!=-1) return dp[i];
		
		long ans = (long)1e15;
		
		for(int j=i+1; j<=i+k && j<n; j++) {
			ans = Math.min(ans, Math.abs(h[i]-h[j])+solve(j));
		}
		
		return dp[i]=ans;
	}

}


Measured memory_bytes: 64844
s = input()

if s[0:1] == s[len(s)-1:len(s)]:
    if len(s) % 2 == 1:
        print("Second")
    else:
        print("First")
else:
    if len(s) % 2 == 1:
        print("First")
    else:
        print("Second")

Measured memory_bytes: 3316
#include<cstdio>
#include<cstring>
#include<cmath>
#include<algorithm>
using namespace std;
const int md=1000000007;
int n,m,i,j,k,l,x,g[305][305],h[305][305],cnt[305],f[305][305][305];
int main()
{
	scanf("%d%d",&n,&m);
	for(i=1;i<=m;++i)
	{
		scanf("%d%d%d",&j,&k,&x);
		++cnt[k];
		g[k][cnt[k]]=j,h[k][cnt[k]]=x;
		if(k==1&&x>1)
		{
			printf("0");
			return 0;
		}
	}
	f[1][0][0]=1;
	for(i=1;i<n;++i)
	{
		for(j=0;j<i;++j)
			for(k=0;k<i;++k)
				if(f[i][j][k])
				{
					f[i+1][j][i]=(f[i+1][j][i]+f[i][j][k])%md;
					f[i+1][k][i]=(f[i+1][k][i]+f[i][j][k])%md;
					f[i+1][j][k]=(f[i+1][j][k]+f[i][j][k])%md;
				}
		for(j=0;j<=i;++j)
			for(k=0;k<=i;++k)
			if(f[i+1][j][k])
			{
				for(x=1;x<=cnt[i+1];++x)
					if((j>=g[i+1][x])+(k>=g[i+1][x])+(i+1>=g[i+1][x])!=h[i+1][x])
					{
						f[i+1][j][k]=0;
						break;
					}
			}
		/*for(j=0;j<=i+1;++j)
			for(k=0;k<=i+1;++k)
				if(f[i+1][j][k])
					printf("%d %d %d %d\n",i+1,j,k,f[i+1][j][k]);*/
	}
	x=0;
	for(j=0;j<=n;++j)
		for(k=0;k<=n;++k)
			x=(x+f[n][j][k])%md;
	printf("%lld",x*3ll%md);
	return 0;
}


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

int main (){
  int N, M;
  cin >> N >> M;
  
  const int NMMAX = 50;
  //int A[NMMAX], B[NMMAX];
  vector<int> A(NMMAX), B(NMMAX);
  for(int i=0; i<M; ++i) {
//	cin >> A[i] >> B[i];
    cin >> A.at(i) >> B.at(i);
  }
  
//  int road[NMMAX];
  vector<int> road(NMMAX);
  for(int i=0; i<N; ++i) {
//    road[i]=0;
      road.at(i) = 0;
  }
  for(int i=0; i<M; ++i) {
/*	road[A[i]-1] += 1;
	road[B[i]-1] += 1;  */
	road.at(A.at(i) -1) +=1;
	road.at(B.at(i) -1) +=1;
  }
  for(int i=0;i<N;i++) {
//    cout << road[i] <<endl;
    cout << road.at(i) <<endl;
  }
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {

		Scanner sc = new Scanner(System.in);
		int number = sc.nextInt();
		sc.close();

		long result = 0;
		for (int i = 1; i <= number; i++) {
			if (i % 3 == 0 && i % 5 == 0) {
				continue;
			} else if (i % 3 == 0) {
				continue;
			} else if (i % 5 == 0) {
				continue;
			}
			result += i;
		}

		System.out.print(result);
	}

}


Measured memory_bytes: 35812
#pragma GCC optimize "O3"

#define ALL(x) x.begin(), x.end()

#include<bits/stdc++.h>

using namespace std;

constexpr int N = 26;

typedef long long LL;

int m;
char tab[3][3010];

vector<LL> cls;

inline bool dfs(const int& lev, LL st) {
  if(st & (st >> N))
    return false;
  if(lev == (int)cls.size()) {
    vector<char> ans;
    for(int i = 0; i < N; ++i)
      if(st & (1LL << i))
        ans.push_back('A' + i);
    printf("%lu", ans.size());
    for(char c : ans)
      printf(" %c", c);
    puts("");
    return true;
  }
  LL cl = cls[lev];
  if(st & cl) return dfs(lev + 1, st);
  while(cl) {
    LL lb = (cl & (-cl));
    cl -= lb;
    if(dfs(lev + 1, st | lb))
      return true;
    lb = (lb < (1LL << N) ? (lb << N) : (lb >> N));
    st |= lb;
  }
  return false;
}
inline void solve() {
  cls.clear();
  for(int i = 0; i < 3; ++i)
    scanf("%s", tab[i]);
  for(int i = 0; i < m; ++i)
    for(int j = 0; j < 8; ++j) {
      LL var = 0;
      for(int k = 0; k < 3; ++k) {
        char c = tab[k][3 * i + 1 + ((j >> k) & 1)];
        var |= (1LL << (islower(c) ? (c - 'a') : (c - 'A' + N)));
      }
      if((var & (var >> N)) == 0)
        cls.push_back(var);
    }
  sort(ALL(cls));
  cls.resize(unique(ALL(cls)) - cls.begin());
  if(!dfs(0, 0))
    puts("-1");
}
int main() {
  while(scanf("%d", &m) && m)
    solve();
  return 0;
}

Measured memory_bytes: 4172
#include<iostream>
using namespace std;
int a,b,x[101];
int main()
{
    cin>>a;
    cin>>b;
    int i;
    for(i=1;i<=a;i++)
        cin>>x[i];
    int s=0;
    i=0;
    while(x[i]+s<=b)
    {
        i++;
        s=s+x[i-1];
    }
    cout<<i;
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <iomanip>
#include <string>
#include <cmath>
using namespace std;
int main(){
	long long a,n,max;
	long long goukei = 0;
	long long min = 999999999;
	long long array[1000000];
	cin>>n;
	for(;;){
		for(a=0; a<n; a++) cin>>array[a];
		int max = array[0];
		for(a=0; a<n; a++) if(array[a] > max)max = array[a];
		for(a=0; a<n; a++) if(array[a] < min)min = array[a];
		for(a=0; a<n; a++) goukei += array[a];
		
	cout<<min<<" "<<max<<" "<<goukei<<endl;
	break;
}

		return 0;
}

Measured memory_bytes: 1248
#include <iostream>
#include <algorithm>
#include <cmath>
#include <limits>
#include <vector>
#include <cstdio>
#include <bits/stdc++.h>
#include <set>
#include <map>
#include <stdio.h>
#include <stack>
#include <queue>
#include <deque>
using namespace std;
using ll = long long;
map <int ,int> mpa,mpb;
typedef pair<ll, ll> P;
priority_queue<P, vector<P>, greater<P>> pque;

int main(){
  ios::sync_with_stdio(false);
  cin.tie(NULL);
  ll N;
  cin >> N;
  deque<int> deq;
  int t;
  int cnt=0;
  if(N%2==0){
    cnt=1;
  }
  for(int i=0;i<N;i++){
    cin >> t;
    if(i%2==cnt){
      deq.push_front(t);
    }else{
      deq.push_back(t);
    }
  }
  while(!deq.empty()){
    printf("%d ",deq.front());
    deq.pop_front();
  }
  return 0;
}

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

using namespace std;
int main(){
	double W,H,x,y;
	cin>>W>>H>>x>>y;
	double ans=(W*H)/2;
	if(x==W/2&&y==H/2){
		printf("%.10lf 1\n",ans);
	}
	else{
		printf("%.10lf 0\n",ans);
	}
	return 0;
}

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

using namespace std;
const int MAXN = 305;
double dp[MAXN][MAXN][MAXN];

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

	int N;
	cin >> N;
	int x, c1=0, c2=0, c3=0;
	for(int i=0; i<N; i++){
		cin >> x;
		if(x == 1) c1++;
		if(x == 2) c2++;
		if(x == 3) c3++;
	}

	for(int x=0; x<MAXN; x++){
		for(int j=0; j+x<MAXN; j++){
			for(int i=0; i+j+x<MAXN; i++){
				if(i==0 && j==0 && x==0 || x+j+i > MAXN) continue;

				double tmp = 1.0 * N / (i + j + x);
				double k1 = 1.0 * i / (i + j + x);
				double k2 = 1.0 * j / (i + j + x);
				double k3 = 1.0 * x / (i + j + x);

				if(i) dp[i][j][x] += dp[i-1][j][x] * k1;
				if(j) dp[i][j][x] += dp[i+1][j-1][x] * k2;
				if(x) dp[i][j][x] += dp[i][j+1][x-1] * k3;

				dp[i][j][x] += tmp;
			}
		}
	}
	cout << setprecision(12)  << dp[c1][c2][c3];
}


Measured memory_bytes: 221440
import java.util.*;
class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int m = 0;
        int l=0;
        for (int i = 1; i <= n; i++) {
            for (int j = 1; j <= n / i; j++) {
                m = n - (j * i);
                if (m != 0) {
                    l++;
                }
            }
        }
        System.out.println(l);
    }
}


Measured memory_bytes: 35712
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, srt, end) for (long long i = (srt); i < (long long)(end); i++)

int main(){
    string s;
    cin >> s;
    ll ans = 0;
    ll hd = 0, bk = s.size()-1;
    while(bk - hd > 0){
        if(s[hd] == s[bk]){
            hd++;
            bk--;
        }else{
            if(s[hd] != 'x' && s[bk] != 'x'){
                cout << -1 << endl;
                return 0;
            }
            if(s[hd] == 'x'){
                ans++;
                hd++;
            }
            if(s[bk] == 'x'){
                ans++;
                bk--;
            }
        }
    }
    cout << ans << endl;
    return 0;
}

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

template <class T> inline int size(const T& x) { return x.size(); }

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

  int n, k;
  while (cin >> n >> k, n | k) {
    vector<int> cards(k);
    for (int i = 0; i < k; ++i)
      cin >> cards[i];
    sort(cards.begin(), cards.end());

    bool hakushi = false;
    if (cards[0] == 0) {
      hakushi = true;
      cards.erase(cards.begin());
    }

    int ans = 0, prev = -1000, prevLength = 0;
    for (int i = 0; i < size(cards); ) {
      int head = i;
      for (++i; i < size(cards); ++i) {
        if (cards[i] != cards[i-1] + 1)
          break;
      }
      int tail = i - 1;
      int length = tail - head + 1;
      if (hakushi && prev + 2 == cards[head])
        ans = max(ans, prevLength + 1 + length);
      else if (hakushi && (1 < cards[head] || cards[tail] < k))
        ans = max(ans, length + 1);
      else
        ans = max(ans, length);
      prev = cards[tail];
      prevLength = length;
    }

    cout << ans << endl;
  }
}

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

struct WeightedUnionFind{
  int n;
  vector<int>r,p;
  vector<int>ws;
  WeightedUnionFind(int sz):n(sz),ws(n,0),r(n,0),p(n,0){iota(p.begin(),p.end(),0);}
  int find(int x){
    if(x==p[x])return x;
    else{
      int t=find(p[x]);
      ws[x]+=ws[p[x]];
      return p[x]=t;
    }
  }
  int weight(int x){
    find(x);
    return ws[x];
  }
  bool same(int x,int y){
    return find(x)==find(y);
  }
  void unite(int x,int y,int w){
    w+=weight(x);
    w-=weight(y);
    x=find(x);
    y=find(y);
    if(x==y)return;
    if(r[x]<r[y])swap(x,y),w=-w;
    r[x]+=r[y];
    p[y]=x;
    ws[y]=w;
  }
  int diff(int x,int y){
    return weight(y)-weight(x);
  }
};

signed main(){
  int n,m;
  while(cin>>n>>m,n||m){
    WeightedUnionFind U(n+1);
    while(m--){
      char c;
      int x,y,z;
      cin>>c>>x>>y;
      if(c=='!'){
        cin>>z;
        U.unite(x,y,z);
      }
      else{
        if(!U.same(x,y))cout<<"UNKNOWN"<<endl;
        else cout<<U.diff(x,y)<<endl;
      }
    }
  }
}


Measured memory_bytes: 4892
from collections import defaultdict
n = int(input())
al = list(map(int, input().split()))
ans = sum(al)
d = defaultdict(lambda: 0)
for a in al:
    d[a] += 1
q = int(input())
for _ in range(q):
    b, c = list(map(int, input().split()))
    d[c] += d[b]
    ans += (c-b)*d[b]
    d[b] = 0
    print(ans)


Measured memory_bytes: 94504
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
using namespace std;
 
int main() {
	int N, K;
	cin >> N >> K;
	string S;
	cin >> S;
 
	vector<int> Nums;
	int now = 1;
	int cnt = 0;
	for (int i = 0; i < N; i++)
	{
		if (S[i] == (char)('0' + now)) cnt++;
		else {
			Nums.push_back(cnt);
			now = 1 - now;
			cnt = 1;
		}
	}
	if (cnt != 0) Nums.push_back(cnt);

	if (Nums.size() % 2 == 0) Nums.push_back(0);
 
	vector<int> sum(Nums.size() + 1);
	for (int i = 0; i < Nums.size(); i++)
	{
		sum[i + 1] = sum[i] + Nums[i];
	}

	int Add = 2 * K + 1;
	int ans = 0;
 
	for (int i = 0; i < Nums.size(); i += 2)
	{
		int tmp = 0;
 
		int left = i;
		int right = min(i + Add, (int)Nums.size());

        
		for (int j = left; j < right; j++)
		{
			tmp += Nums[j];
		}
        

		//tmp = sum[right] - sum[left];

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

Measured memory_bytes: 1272
#include <stdio.h>

int main(void){
    // Your code here!
    int N,M,sum=0;
    int T[100],P,X;
    
    scanf("%d",&N);
    for(int i = 0; i < N; i++)
    {
        scanf("%d",&T[i]);
        sum += T[i];
    }
    scanf("%d",&M);
    for(int i = 0; i < M; i++)
    {
        scanf("%d %d",&P,&X);
        printf("%d\n",sum-T[P-1]+X);
    }
    
    //printf("%d\n",(op == '+')? a+b:a-b);
    
}


Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define mod 1000000007
#define s(x, n) memset(x, n, sizeof(x));
#define pb(x) push_back(x)
#define NIL -1
#define MIN 1e-9
#define MAXN 3001
#define double long double

double dp[MAXN][MAXN];
double arr[MAXN];
double p(int n)
{
    s(dp, (double)0.0);
    dp[0][0] = (double)1.0;
    for (int i = 1; i <= n; i += 1)
    {
        for (int j = 0; j <= i; j += 1)
        {
            if (j == 0)
                dp[i][j] = dp[i - 1][j] * ((double)1.0 - arr[i]);
            else
                dp[i][j] = dp[i - 1][j] * ((double)1.0 - arr[i]) + dp[i - 1][j - 1] * arr[i];
        }
    }
    double ans = 0.0;
    for (int i = (n + 1) / 2; i <= n; i += 1)
        ans += dp[n][i];

    return ans;
}
void solve()
{
    int n;
    cin >> n;
    for (int i = 1; i <= n; i++)
        cin >> arr[i];
    double ans = p(n);
    cout << fixed << setprecision(10);
    cout << ans << "\n";
}
int main()
{
#ifdef WIN32
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#endif

#ifndef WIN32
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
#endif
    int t;
    t = 1;
    /// cin >> t;
    for (int I = 1; I <= t; I++)
    {
        solve();
    }
    return 0;
}

Measured memory_bytes: 144580
# ARC100C - Linear Approximation (ABC102C)
def main():
    n = int(input())
    A = tuple(map(int, input().rstrip().split()))
    A = sorted(j - i for i, j in enumerate(A, start=1))
    b = A[n // 2]
    ans = sum(abs(a - b) for a in A)
    print(ans)


if __name__ == "__main__":
    main()

Measured memory_bytes: 25412
#include <bits/stdc++.h>
using namespace std;
template <class T> inline bool chmax(T &a, T b) {
    if(a < b) {
        a = b;
        return 1;
    }
    return 0;
}
template <class T> inline bool chmin(T &a, T b) {
    if(a > b) {
        a = b;
        return 1;
    }
    return 0;
}
typedef long long int ll;

#define ALL(v) (v).begin(), (v).end()
#define RALL(v) (v).rbegin(), (v).rend()
#define endl "\n"
const double EPS = 1e-7;
const int INF = 1 << 30;
const ll LLINF = 1LL << 60;
const double PI = acos(-1);
const int MOD = 1000000007;
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};

//-------------------------------------

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

ll LCM(ll a, ll b) { return a * b / GCD(a, b); }

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n;
    cin >> n;
    ll ans = 0;
    for(int i = 0; i < n; i++) {
        ll a;
        cin >> a;
        ans = GCD(ans, a);
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
 
using namespace std;
 
typedef long long ll;
typedef long double ld;
 
typedef pair<pair<int, int>, int> p;

#define MOD 1000000007

long long modpow(long long a, long long n, long long mod) {
    long long res = 1;
    while (n > 0) {
        if (n & 1) res = res * a % mod;
        a = a * a % mod;
        n >>= 1;
    }
    return res;
}

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

    ll mod = pow(10, 9) + 7;

    ll N, M;
    cin >> N >> M;

    map<ll, ll> a;

    for(ll i = 2LL; i * i <= M; i++) {
        while(M % i == 0) {
            a[i]++;
            M /= i;
        }
    }

    if(M != 1) a[M]++;

    ll ans = 1LL;

    for(auto i = begin(a); i != a.end(); i++) {
        ll c = 1LL;
        for(ll j = 0LL; j < i -> second; j++) {
            c *= (N + j) % mod;
            c %= mod;
            c *= modpow(j + 1LL, mod - 2LL, mod) % mod;
            c %= mod;
        }
        ans *= c;
        ans %= mod;
    }

    cout << ans % mod << endl;
}

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

using namespace std;

const int Nmax = 1e5 + 1;
int N,X;

struct el
{
    int student,poz;
} a[Nmax];

inline bool cmp(el a, el b)
{
    return a.student < b.student;
}

int main()
{
    cin >> N;
    for(int i = 1; i <= N; ++i)
    {
        cin >> X;
        a[i].poz = i,a[i].student = X;
    }
    sort(a + 1, a + N + 1,cmp);
    for(int i = 1; i <= N; ++i)
        cout << a[i].poz << " ";
    return 0;
}


Measured memory_bytes: 1536
#include<iostream>
#include<algorithm>
#include<string>
#include<functional>
#include<utility>
#include<stack>
#include<queue>
#include<cmath>
#include<list>
#include<cstdint>
#include<vector>
#include<map>
#define rep(i,rept)	for(ll i = 0; i<rept;i++)
typedef long long ll;
using namespace std;

long long int a = 0, b = 0, c = 1, x = 0, y = 0, z = 0, maxy = -1, mini = 9999, counter = 0,startp=0,endp=0,checker=0;
std::vector<unsigned long long int> vec{}, vecsec{};
int iremono[100001];
std::vector<long long int>kinds{}, ans{}, kaku{};

bool okada = false,okada2=false;
std::string output, output2, input, one, two;
char cutcount[201];
int kakunou2[50][50] = {};

int ctoi(const char c) {
	if ('0' <= c && c <= '9') return (c - '0');
	return -1;
}
unsigned long long int LCM(unsigned long long int a, unsigned long long int b) {
	unsigned long long int i, j;
	i = a; j = b;
	while (true) {

		c = i % j;
		i = j;
		if (c != 0) {

			j = c;

		}
		else {
			break;
		}
	}
	return j * (a / j) * (b / j);
}
int main()
{
	cin >> a;
	cout << a / 3 << endl;
	
}

	
	





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

bool aa(string x){
  string y(x.rbegin(),x.rend());
  return x==y;
}

int main(){
  string s;
  cin>>s;
  int n=(int)s.size();
  if(aa(s) && aa(s.substr(0,(n-1)/2)) && aa(s.substr((n+1)/2))){
    cout<<"Yes"<<endl;
  }else{
    cout<<"No"<<endl;
  }
  
}

Measured memory_bytes: 256
//submitted by Himj
  #include<bits/stdc++.h>
  #define ll long long
  #define mod 1000000007
  #define pb push_back
  #define fi first
  #define se second
  #define fr(i,s,e) for(i=s;i<e;i++)
  #define ms(arr,val) memset(arr,val,sizeof(arr))
  using namespace std;

  const ll mxn=2e5+1;
  ll arr[mxn],n,bit=0;
  ll solve(ll mask)
  {
    ll sum=0,i=0;
    bit=-1;
    while(mask)
    {
      if(mask&1)
      {
        sum+=arr[i];
        bit++;
      }
      i++;
      mask>>=1;
    }
    return sum;
  }
  int main(){
      ios_base::sync_with_stdio(false);
      cin.tie(0);
      cout.tie(0);
  
    ll t=1;
    //cin>>t;
      while(t--){
        ll a,b,c,i,ans=1e9,j,k;
        cin>>n>>a>>b>>c;
        ll mask=1ll<<n;
        fr(i,0,n)
        cin>>arr[i];
        fr(i,1,mask)
        {
          ll total=0;
          ll sa=solve(i);
          ll ta=10*bit+abs(sa-a);
          fr(j,1,mask)
          {
            if(i&j)
              continue;
            ll sb=solve(j);
            ll tb=10*bit+abs(sb-b);
            fr(k,1,mask)
            {
              if((i&k) or (j&k))
                continue;
              ll sc=solve(k);
              ll tc=bit*10+abs(sc-c);
              ans=min(ans,ta+tb+tc);
            }
          }
        }
        cout<<ans;
        
         
      }
    return 0;
    }



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

int main()
{
    //freopen("Knapsack2.inp","r",stdin);
    long long int n, W, i, j, T=0;
    cin>>n>>W;
    long long int w[n+1], v[n+1];
    for(i=1; i<=n; i++) { cin>>w[i]>>v[i]; T+=v[i]; }

    long long int f[T+1];
    f[0]=0; //f[v[i]]=w[1];
    for(i=1; i<=T; i++) f[i]=1000000000;

    for(i=1; i<=n; i++)
    {
        for(j=T; j>=v[i]; j--) f[j]=min(w[i]+f[j-v[i]], f[j]);
    }

//    int m=T;
//    while(f[m]>W && m>=v[1]) m--;
//    cout<<m;
    for(i=T; i>=1; i--) { if(f[i]<=W) { cout<<i; return 0; } }
    return 0;
}


Measured memory_bytes: 1024
import java.util.*;

public class Main {

    static class BinarySearch {

        public static int lowerBound(int[] array, int value) {
            int left = -1;
            int right = array.length;
            while (right - left > 1) {
                int middle = (right + left) / 2;
                if (array[middle] >= value) {
                    right = middle;
                } else {
                    left = middle;
                }
            }
            return right;
        }

        public static int upperBound(int[] array, int value) {
            int left = -1;
            int right = array.length;
            while (right - left > 1) {
                int middle = (right + left) / 2;
                if (array[middle] > value) {
                    right = middle;
                } else {
                    left = middle;
                }
            }
            return right;
        }

    }



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

        int n = sc.nextInt();
        int[] aArr = new int[n];
        int[] bArr = new int[n];
        int[] cArr = new int[n];

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

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

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

        Arrays.sort(aArr);
        Arrays.sort(bArr);
        Arrays.sort(cArr);

        long ans = 0;
        for (int i = 0; i < n; i++) {
            int target = bArr[i];
            long aCount = BinarySearch.lowerBound(aArr, target);
            long cCount = n - BinarySearch.upperBound(cArr, target);
            ans += aCount * cCount;
        }

        System.out.println(ans);
    }

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

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



Measured memory_bytes: 92364
S = input()
accept = False

if S[0] == "A" and S[2:-1].count("C") == 1:
    i =  S.index("C")
    S = S[1:i] + S[i+1:]
    if S.islower():
        accept = True

if accept:
    print("AC")

else:
    print("WA")

Measured memory_bytes: 3060
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.NoSuchElementException;

public class Main {
	int N;
	int[] T,A;
	public void solve() {
		N = nextInt();
		T = new int[N];
		A = new int[N];
		for(int i = 0;i < N;i++){
			T[i] = nextInt();
			A[i] = nextInt();
		}

		long a = 1;
		long b = 1;

		for(int i = 0;i < N;i++){
			long x = (long)Math.max((a + T[i] - 1) / T[i],(b + A[i] - 1)/ A[i]);
			a = T[i] * x;
			b = A[i] * x;
		}
		out.println(a + b);
	}

    public static void main(String[] args) {
        out.flush();
        new Main().solve();
        out.close();
    }

    /* Input */
    private static final InputStream in = System.in;
    private static final PrintWriter out = new PrintWriter(System.out);
    private final byte[] buffer = new byte[2048];
    private int p = 0;
    private int buflen = 0;

    private boolean hasNextByte() {
        if (p < buflen)
            return true;
        p = 0;
        try {
            buflen = in.read(buffer);
        } catch (IOException e) {
            e.printStackTrace();
        }
        if (buflen <= 0)
            return false;
        return true;
    }

    public boolean hasNext() {
        while (hasNextByte() && !isPrint(buffer[p])) {
            p++;
        }
        return hasNextByte();
    }

    private boolean isPrint(int ch) {
        if (ch >= '!' && ch <= '~')
            return true;
        return false;
    }

    private int nextByte() {
        if (!hasNextByte())
            return -1;
        return buffer[p++];
    }

    public String next() {
        if (!hasNext())
            throw new NoSuchElementException();
        StringBuilder sb = new StringBuilder();
        int b = -1;
        while (isPrint((b = nextByte()))) {
            sb.appendCodePoint(b);
        }
        return sb.toString();
    }

    public int nextInt() {
        return Integer.parseInt(next());
    }

    public long nextLong() {
        return Long.parseLong(next());
    }

    public double nextDouble() {
        return Double.parseDouble(next());
    }
}

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

using namespace std;

const int L = 128;
const int Q = 850;
int cnt = 0;

int query(const string &s) {
	cnt++;
	assert(cnt <= Q);
	printf("? %s\n", s.c_str()); fflush(stdout);
	int ans;
	scanf("%d", &ans);
	return ans;
}

int tot;
priority_queue<pair<int, string>> pq;
void prec(char c) {
	string s(L, c);
	int len = L - query(s);
	if(len > 0) {
		s.resize(len);
		tot += len;
		pq.emplace(-len, s);
	}
}

void merge(string a, string b) {
	if(a.size() < b.size()) swap(a, b);

	for(int i = (int)a.size(); i >= 0 and !b.empty(); i--) {
		while(!b.empty()) {
			string tmp = a.substr(0, i) + b.back();
			if(i < (int)a.size()) tmp += a.substr(i);
			if(query(tmp) == tot - (int)tmp.size()) {
				a = tmp;
				b.pop_back();
			}
			else break;
		}
	}
	pq.emplace(-(int)a.size(), a);
}

int main() {

	for(char c = 'a'; c <= 'z'; c++) prec(c);
	for(char c = 'A'; c <= 'Z'; c++) prec(c);
	for(char c = '0'; c <= '9'; c++) prec(c);

	while(pq.size() > 1) {
		string a = pq.top().second; pq.pop();
		string b = pq.top().second; pq.pop();
		merge(a, b);
	}

	string ans = pq.top().second;

	assert(query(ans) == 0);

	printf("! %s\n", ans.c_str());
	fflush(stdout);
}



Measured memory_bytes: 3788
from math import log2
# python template for atcoder1
import sys
sys.setrecursionlimit(10**9)
input = sys.stdin.readline

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


ans = 0
while True:
    if all(a % 2 == 0 for a in A):
        A = list(map(lambda x: x/2, A))
        ans += 1
    else:
        break
print(ans)


Measured memory_bytes: 3060
from collections import defaultdict
from string import ascii_uppercase
import sys, bisect, math
stdin = sys.stdin
read_int = lambda : list(map(int,stdin.readline().split()))
read_str = lambda : stdin.readline().rstrip()

N,K = read_int()

def solve():
    ans = N - K + 1
    return ans

if __name__ == "__main__":
    print(solve())


Measured memory_bytes: 3760
#include <bits/stdc++.h>
using namespace std;
typedef pair<int,int> P;
typedef long long ll;
typedef long double ld;
const int inf=1e9+7;
const ll longinf=1LL<<60;
#define REP(i,m,n) for(int i=(int)(m) ; i < (int) (n) ; ++i )
#define rep(i,n) REP(i,0,n)
#define F first
#define S second
 
const int mx=100010;
const ll mod=1e9+7;


int main(){
  int d,g;
  cin >> d >> g;
  vector<ll> p(d), c(d);
  rep(i,d){
    cin >> p[i] >> c[i];
  }
  vector<ll> dp(1010,0);
  rep(i,d)for(int j=1000; j>=1; j--) for(int k=1; k<=p[i]&&k<=j; k++){
    dp[j] = max(dp[j], dp[j-k] + (i+1)*100*k + (k==p[i]?c[i]:0));
  }
  rep(i,1001)if(dp[i]>=g){
    cout << i << endl; break;
  }
  return 0;
}

Measured memory_bytes: 256
n, m = map(int, input().split())
a = list(map(int, input().split()))
l = []
for i in range(m):
    b, c = map(int, input().split())
    l.append((b, c))
for i in a:
    l.append((1, i))
l.sort(key=lambda x: x[1], reverse=True)
#print(l)
count = n
ans = 0
for item in l:
    b, c = item
    ans += c*min(b, count)
    count -= b
    if count <= 0:
        break
print(ans)

Measured memory_bytes: 84376
n = int(input())
x = 0
for i in range(n):
  d1, d2 = map(int, input().split())
  if d1 == d2:
    x += 1
  if x > 0 and d1 != d2:
    if x == 3:
      break
    x = 0
if x >= 3:
  print("Yes")
else:
  print("No")
  

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

typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> ii;
typedef tuple<ll, ll, ll> iii;
typedef vector<ll> vi;
typedef vector<ii> vii;
typedef vector<iii> viii;
typedef vector<vi> vvi;
typedef vector<vii> vvii;
#define REP(i,n) for (ll i = 0; i < n; ++i)
#define REPR(i,n) for (ll i = n-1; i >= 0; --i)
#define FOR(i,m,n) for (ll i = m; i < n; ++i)
#define FORR(i,m,n) for (ll i = n-1; i >= m; --i)
#define FORE(x,xs) for (const auto& x : xs)
#define ALL(v) v.begin(), v.end()
#define CHMIN(x,y) x = min(x, y)
#define CHMAX(x,y) x = max(x, y)

int N, X, Y;

vi solve() {
    vi ans(N-1);
    FOR (a, 1, N) FOR (b, a+1, N+1) {
        int res = min(b - a, abs(a-X) + abs(b-Y) + 1);
        ans[res-1]++;
    }
    return ans;
}

int main() {
    cin >> N >> X >> Y;
    FORE (x, solve()) cout << x << endl;
}

Measured memory_bytes: 256