akhauriyash/Code-Regression huggingface dataset:
import java.util.*;
public class Main { 
	public static void main(String[] args) {
		Scanner stdIn = new Scanner(System.in);
		while(true) {
			int n = stdIn.nextInt();
			if(n == 0) break;
			Data[] list = new Data[n];
			for(int i = 0; i < n; i++) {
				String l = stdIn.next();
				int p = stdIn.nextInt();
				int ft = 0;
				int rt = 0;
				for(int j = 0; j < 3; j++) {
					ft += stdIn.nextInt();
				}
				for(int j = 0; j < 2; j++) {
					int a = stdIn.nextInt();
					ft += a;
					rt += a;
				}
				
				int f = stdIn.nextInt();
				int s = stdIn.nextInt();
				int m = stdIn.nextInt();
				
				int alltime = ft + rt*(m-1);
				int allmoney = f*s*m - p;
				
				list[i] = new Data(l,(double)allmoney/(double)alltime);
				
				
			}
			Arrays.sort(list,new MyComp());
			
			for(int i = 0; i < n; i++) {
				System.out.println(list[i].name);
			}
			System.out.println("#");
		}
	}
}
class Data {
	public String name;
	public double ef;
	public Data(String name, double ef) {
		this.name = name;
		this.ef = ef;
	}
}

class MyComp implements Comparator<Data> {

	@Override
	public int compare(Data o1, Data o2) {
		if(o1.ef < o2.ef) {
			return 1;
		}
		if(o1.ef > o2.ef) {
			return -1;
		}
		return o1.name.compareTo(o2.name);
	}
	
}

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

int main() {
  int N,X;
  cin>>N>>X;
  
  vector<int> m(N);
  for(int i=0;i<N;++i){
    cin>>m[i];
  }
  
  int min=1000000;
  for(int i=0;i<N;++i){
    if(m[i]<min)
      min=m[i];
  }
  
  int sum=0;
  for(int i=0;i<N;++i){
    sum+=m[i];
  }
  
  int ans=N+(X-sum)/min;
  
  cout<<ans<<endl;
}


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

int main() {
  string str1, str2;
  cin >> str1;
  cin >> str2;
   
  if (str1.at(2)==str2.at(2)&&str1.at(1)==str2.at(1)&&str1.at(0)==str2.at(0)) {
    cout << "3" << endl;
  }
  else if (str1.at(0)==str2.at(0)&&str1.at(1)==str2.at(1)) {
    cout << "2" << endl;
  }
  else if (str1.at(0)==str2.at(0)&&str1.at(2)==str2.at(2)) {
    cout << "2" << endl;
  }
  else if (str1.at(2)==str2.at(2)&&str1.at(1)==str2.at(1)) {
    cout << "2" << endl;
  }
 
  else if (str1.at(0)==str2.at(0)||str1.at(1)==str2.at(1)||str1.at(2)==str2.at(2)) {
    cout << "1" << endl;
  }
  else{
    cout << "0" << endl;
  }
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <unordered_map>
#include <deque>
#include <list>
#include <set>
#include <random>
#include <deque>
#include <unordered_set>

using namespace std;
using ll = long long;
const int BIG = 100000007;


int main() {
    ll d,t,s;
    cin >> d >> t >> s;
    cout << ((d > t * s) ? "No" : "Yes") << endl;
}




Measured memory_bytes: 3060
#include <bits/stdc++.h>
#define INF (int)1e9
#define endl "\n"
#define ll long long
#define ull unsigned long long

using namespace std;

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

    set<string> l;
    for (int i = 0; i < n; i++)
    {
        string s;
        cin >> s;
        l.insert(s);
    }
    cout << l.size() << endl;
}

Measured memory_bytes: 19260
let counter = ref 0

let merge (array : int array) left mid right =
  let init n p = Array.init (n+1) (fun i -> if i=n then max_int else array.(p+i)) in
  let xs = init (mid-left) left in
  let ys = init (right-mid) mid in
  let rec loop i j k =
    if k < right then
      (incr counter;
       if xs.(i) <= ys.(j) then (array.(k) <- xs.(i); loop (i+1) j (k+1))
       else (array.(k) <- ys.(j); loop i (j+1) (k+1)) )
  in loop 0 0 left

let rec msort (array : int array) left right =
  if left+1 < right then
    let mid = (left+right)/2 in
    msort array left mid;
    msort array mid right;
    merge array left mid right

let () =
  let n = read_int () in
  let (l : int array) = Array.init n (fun _ -> Scanf.scanf "%d " (fun x -> x)) in
  msort l 0 n;
  Array.iteri (fun i v -> Printf.printf (if i = n-1 then "%d\n" else "%d ") v) l;
  Printf.printf "%d\n" !counter

Measured memory_bytes: 19636
#include <algorithm>
#include <iostream>
using namespace std;
int main(void){
    int n;
    cin>>n;
    int A[n];
    for(int i=0; i<n; i++){
        cin>>A[i];
    }
    sort(A,A+n);
    cout<<A[n/2]-A[n/2-1]<<endl;
    return 0;
}


Measured memory_bytes: 640
#include<bits/stdc++.h>
using namespace std;
#define endl '\n'
#define pb push_back
#define all(x) x.begin(), x.end()
#define rep(i, n) for (int i = 0; i < n; ++i)
#define reps(i, m, n) for (int i = m; i <= n; ++i)
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
const int INF = 0x3f3f3f3f;
const ll LINF = 0x3f3f3f3f3f3f3f3fLL;

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

  int n; cin >> n;
  int minv = INF;
  int maxv = 0;
  int a;
  rep(i, n) {
    cin >> a;

    minv = min(minv, a);
    maxv = max(maxv, a);
  }

  cout << maxv - minv << endl;

  return 0;
}

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

int main(){
  ios::sync_with_stdio(false);
  cin.tie(0);
  ll n, c;
  cin >> n >> c;
  pair<ll,ll> mp[n];
  for (int i = 0; i < n; i++) {
    cin >> mp[i].first >> mp[i].second;
  }

  ll ans = 0;
  ll amt = 0;
  ll rec1[n], rec2[n];
  ll sum1[n], sum2[n];
  for (int i = 0; i < n; i++) {
    amt += mp[i].second;
    rec1[i] = amt - mp[i].first;
    sum1[i] = amt;
    ans = max(ans, rec1[i]);
  }
  amt = 0;
  for (int i = 0; i < n; i++) {
    amt += mp[n-1-i].second;
    rec2[i] = amt - (c - mp[n-1-i].first);
    sum2[i] = amt;
    ans = max(ans, rec2[i]);
  }
  for (int i = 1; i < n; i++) {
    rec1[i] = max(rec1[i], rec1[i - 1]);
    rec2[i] = max(rec2[i], rec2[i - 1]);
  }
  for (int i = 0; i < n - 1; i++) {
    ans = max(ans, sum1[i] - mp[i].first * 2LL + rec2[n - i - 2]);
  }
  for (int i = 0; i < n - 1; i++) {
    ans = max(ans, sum2[i] - (c - mp[n - i - 1].first) * 2LL + rec1[n - i - 2]);
  }
  cout << ans << endl;
  return 0;
}


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

struct Point{
    double x;
    double y;
    Point(double x_in, double y_in){
        x = x_in;
        y = y_in;
    }
    Point(){}
};

struct Segment{
    Point p1;
    Point p2;
    Segment(const Point& p1_in, const Point& p2_in){
        p1 = p1_in;
        p2 = p2_in;
    }
};

Point calc_s(const Segment& S){
    double x = (2 * S.p1.x + S.p2.x) / 3.0;
    double y = (2 * S.p1.y + S.p2.y) / 3.0;
    Point P(x, y);
    return P;
}

Point calc_t(const Segment& S){
    double x = (S.p1.x + 2 * S.p2.x) / 3.0;
    double y = (S.p1.y + 2 * S.p2.y) / 3.0;
    Point P(x, y);
    return P;
}

Point calc_u(const Point& s, const Point& t){
    double x = (t.x - s.x) * cos(M_PI / 3.0) -
               (t.y - s.y) * sin(M_PI / 3.0) + s.x;
    double y = (t.x - s.x) * sin(M_PI / 3.0) +
               (t.y - s.y) * cos(M_PI / 3.0) + s.y;
    Point ret(x, y);
    return ret;
}

void Koch(const Segment& Seg, int n){
    if (n == 0) return;
    Point s = calc_s(Seg);
    Point t = calc_t(Seg);
    Point u = calc_u(s, t);
    Segment Seg1(Seg.p1, s);
    Koch(Seg1, n - 1);
    cout << s.x << " " << s.y << endl;
    Segment Seg2(s, u);
    Koch(Seg2, n - 1);
    cout << u.x << " " << u.y << endl;
    Segment Seg3(u, t);
    Koch(Seg3, n - 1);
    cout << t.x << " " << t.y << endl;
    Segment Seg4(t, Seg.p2);
    Koch(Seg4, n - 1);
}


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

    Point p1(  0.0, 0.0);
    Point p2(100.0, 0.0);
    Segment Seg(p1, p2);
    cout << Seg.p1.x << " " << Seg.p1.y << endl;
    Koch(Seg, n);
    cout << Seg.p2.x << " " << Seg.p2.y << endl;

    return 0;
}

Measured memory_bytes: 3236
import Control.Monad
import Text.Printf
import Control.Applicative
import Data.List as L

main :: IO()
main = do
  [a, b, c] <- map read . words <$> getLine
  printf "%d\n" $ slv a b c

slv :: Int -> Int -> Int -> Int
slv a b c | even val = val `div` 2
          | otherwise = (val + 3) `div` 2
  where [aa, bb, cc] = L.sort [a, b, c]
        val = cc - aa + cc - bb

Measured memory_bytes: 508
from sys import exit

ii = lambda : int(input())
mi = lambda : map(int,input().split())
li = lambda : list(map(int,input().split()))


def main():
    n,m,v,p = mi()
    atmp = li()
    
    atmp = list(sorted(atmp))
    a = []
    ad = []

    for i in range(n):
        a.append([atmp[i],i])
        ad.append([atmp[i],i])


    # for i in range(v):
    #     a[i][0]+=m

    a = list(sorted(a, key=lambda x : x[0]))#, reverse=True))
    #print(a)


    l = 0
    r = n-1
    mid = (r-l)//2+l

    while r-l >= 2:
        mid = (r-l)//2+l
        #print(mid,l,r)

        if mid >= n-p:
            r = mid
            continue

        tmpmax = a[mid][0]+m
        tmp = m*(v-1)

        if tmpmax < a[n-p][0]:
            l = mid
            continue

        #print(tmpmax)

        flag = False
        for itmp in range(n):
            i =n-1-itmp
            if i == mid:
                continue
            if itmp <= p-2:
                tmp-=m
            else:
                if a[i][0] > tmpmax:
                    l = mid
                    flag = True
                    break
                tmp-=(min(tmpmax-a[i][0],m))
                #print(i,(min(tmpmax-a[i][0],m)))
        if flag:
            continue
        else:
            #print("tmp",tmp)
            if tmp >0:
                l = mid
            else:
                r = mid
    
    if r == 1:
        mid = 0
        tmpmax = a[mid][0]+m
        tmp = m*(v-1)

        if tmpmax < a[n-p][0]:
            l = mid

        #print(tmpmax)

        flag = False
        for itmp in range(n):
            i =n-1-itmp
            if i == mid:
                continue
            if itmp <= p-2:
                tmp-=m
            else:
                if a[i][0] > tmpmax:
                    l = mid
                    flag = True
                    break
                tmp-=(min(tmpmax-a[i][0],m))
                #print(i,(min(tmpmax-a[i][0],m)))
        else:
            #print("tmp",tmp)
            if tmp >0:
                l = mid
            else:
                r = mid




    print(n-r)



    
main()


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

#define ll long long
#define MOD 1000000007
#define vi vector<int>
#define vll vector<ll>
#define vpll vector<pair<ll,ll>>
#define vvi vector<vector<int>>
#define INF (ll)1e9
#define fora(i,a,b) for(ll i=a;i<b;i++)
#define all(x) (x).begin(),(x).end()
#define pb push_back
#define fi first
#define se second
#define si size()
#define be begin()
#define en end()
#define le length()
#define mp(x,y) make_pair(x,y)
#define mli map<ll,int>
#define mll map<ll,ll>

using namespace std;
ll cnt=0,B,h,w,k,diff;
vector<string> vs;
void check(vll r,vll c)
{
    vector<string> temp(h,string('!',w));
    ll CB=0;
    fora(i,0,r.si)
    {
        temp[r[i]-1]=vs[r[i]-1];
    }
    fora(i,0,c.si)
    {
        fora(j,0,h)
        {
            temp[j][c[i]-1]=vs[j][c[i]-1];
        }
    }
    fora(i,0,h)
    {
        fora(j,0,w)
        {
            if(temp[i][j]=='#')
            CB++;
        }
    }
    if(CB==diff)
    cnt++;
}
void generate(vll r,vll c, ll ir, ll ic)
{
    if(ir==h&&ic==w)
    {
        check(r,c);
        return;
    }
    if(ir==h)
    {
        ir--;
    }
    if(ic==w){
        ic--;
    }
    ir++;
    ic++;
    generate(r,c,ir,ic);
    r.pb(ir);
    generate(r,c,ir,ic);
    
    c.pb(ic);
    generate(r,c,ir,ic);
    r.pop_back();
    generate(r,c,ir,ic);
}

int main()
{   ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    
    string s;
    cin>>h>>w>>k;
    vector<string> v(h);
    fora(i,0,h)
    {
        cin>>s;
        v[i]=s;
        fora(j,0,w)
        {
            if(s[j]=='#')
            B++;

        }
    }
    vs = v;
    diff = B-k;
    if(diff<0)
    cout<<0<<endl;
    else
    {
        vll r,c;
        ll ir=0,ic=0;
        generate(r,c,ir,ic);
        cout<<cnt<<endl;
    }
    
    return 0;
}




Measured memory_bytes: 3644
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
int main(){
  int k,n,tmp,mx=0;
  vector<int> vec(0),dist(0);
  cin >> k >> n;
  rep(i,n){
    cin >> tmp;
    vec.push_back(tmp);
  }
  rep(i,n-1){
    dist.push_back(vec.at(i+1)-vec.at(i));
    mx=max(mx,dist.at(i));
  }
  dist.push_back(k-vec.at(n-1)+vec.at(0));
  mx=max(mx,dist.at(n-1));
  cout << k-mx << endl;
}
  

Measured memory_bytes: 2676
#include <bits/stdc++.h>
using namespace std;
typedef long long lint;
typedef long double llf;
typedef pair<int, int> pi;
const int mod = 1e9 + 7;

int n, m, a[200005];
int lvl[200005];
int l[1<<19], r[1<<19];

vector<int> dv;
int prv[19][200005], nxt[19][200005];

void solve(int *ans, int nxt[19][200005]){
	for(int i=0; i<n-1; i++){
		lvl[i] = lower_bound(dv.begin(), dv.end(), a[i+1] - a[i]) - dv.begin();
	}
	for(int i=0; i<m; i++){
		nxt[i][n-1] = n-1;
		for(int j=n-2; j>=0; j--){
			if(lvl[j] > i) nxt[i][j] = j;
			else nxt[i][j] = nxt[i][j+1];
		}
	}
	ans[0] = -1;
	for(int i=0; i<(1<<m); i++){
		for(int j=0; j<m; j++){
			if((i >> j) & 1) continue;
			int cur = nxt[j][min(n-1, ans[i] + 1)];
			ans[i | (1<<j)] = max(ans[i | (1<<j)], cur);
		}
	}
}

int dx[200005];

int main(){
	scanf("%d %d",&n,&m);
	dv.push_back(m);
	while(dv.back() >= 1){
		dv.push_back(dv.back() / 2);
	}
	sort(dv.begin(), dv.end());
	for(int i=0; i<n; i++){
		scanf("%d",&a[i]);
	}
	m = dv.size();
	solve(l, nxt);
	int s = 0;
	vector<pi> v;
	for(int i=0; i+1<n; i++){
		if(lvl[i] == dv.size()){
			v.push_back(pi(s, i));
			s = i+1;
		}
	}
	v.push_back(pi(s, n-1));
	if(v.size() > 20){
		while(n--) puts("Impossible");
		return 0;
	}
	for(int i=0; i<n; i++) a[i] *= -1;
	reverse(a, a+n);
	solve(r, prv);	
	for(int i=0; i<(1<<m); i++){
		r[i] = n - 1 - r[i];
	}
	for(int i=0; i<m; i++){
		for(int j=0; j<=n-1; j++){
			prv[i][j] = n-1-prv[i][j];
		}
		reverse(prv[i], prv[i] + n);
	//	for(int j=0; j<n; j++) printf("%d %d %d %d\n",i,j,prv[i][j],nxt[i][j]);
	}
	for(auto &i : v){
	//	printf("%d %d\n", i.first, i.second);
		for(int j=0; j<(1<<(m-1)); j++){
			int p = (1 << (m-1)) - j - 1;
			if(l[j] >= i.first - 1 && r[p] <= i.second + 1){
				dx[i.first]++;
				dx[i.second+1]--;
			}
		}
	}
	for(int i=0; i<n; i++){	

		if(i) dx[i] += dx[i-1];
		if(dx[i]>0) puts("Possible");
		else puts("Impossible");
	}
}


Measured memory_bytes: 38528
#include<iostream>

using namespace std;

int main()
{
	int n,i;
	int a[44];
	cin >> n;
	a[0]=1;
	a[1]=1;
	a[2]=2;
	for(i=2;i<=n;i++){
		a[i]=a[i-1]+a[i-2];
	}
	cout << a[n] << endl;
}

Measured memory_bytes: 3104
N, M, C = [int(i) for i in input().split(" ")]
B = [int(i) for i in input().split(" ")]
A = []
count = 0
for i in range(N):
  A.append([int(i) for i in input().split(" ")])

for i in A:
  suum = 0
  k = 0
  for j in i:
    suum += j * B[k]
    k += 1
  if suum + C > 0:
    count += 1

print(count)


Measured memory_bytes: 3064
import java.util.Scanner;	//Scannerクラス：Java標準入力を取得する

class Main{
	public static void main(String[] args) {
		try(Scanner sc = new Scanner(System.in)){
			for(;;){
				int m = sc.nextInt();
				int f = sc.nextInt();
				int r = sc.nextInt();
				if(m == -1 && f == -1 && r == -1)break;
				int sum = m + f;
				if(m == -1 || f == -1) {
					System.out.println("F");
				}else if(sum >= 80) {
					System.out.println("A");
				}else if(sum >= 65 && sum <= 80) {
					System.out.println("B");
				}else if(sum >= 50 && sum <= 65) {
					System.out.println("C");
				}else if(sum >= 30 && sum <= 50) {
					if(r >= 50) {
						System.out.println("C");
					}else
						System.out.println("D");
				}else if(sum < 30){
					System.out.println("F");
				}
			}
		}
	}
}


Measured memory_bytes: 26252
#include <cstdio>
#include <cmath>
#include <cstring>
#include <string>
#include <cstdlib>
#include <climits>
#include <ctype.h>
#include <vector>
#include <queue>
#include <deque>
#include <set>
#include <stack>
#include <map>
#include <iostream>
#include <algorithm>
using namespace std;
typedef long long LL;
const int INF=0x3f3f3f3f;
const LL mod=1e9+7;
const int MAXN=1e6+5;
const int MAXM=1e6+5;
int vis[30];
int main()
{
    string s;
    cin>>s;
    int len=s.length();
    memset(vis,0,sizeof(vis));
    for(int i=0;i<len;i++)
    {
        vis[s[i]-'a']=1;
    }
    int f=0;
    for(int i=0;i<26;i++)
    {
        if(!vis[i])
        {
            printf("%c\n",i+'a');
            f=1;
            break;
        }
    }
    if(f==0)printf("None\n");


    return 0;
}


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

// #define int long long
#define rep(i, n) for (int i = (int)(0); i < (int)(n); ++i)
#define reps(i, n) for (int i = (int)(1); i <= (int)(n); ++i)
#define rrep(i, n) for (int i = ((int)(n)-1); i >= 0; i--)
#define rreps(i, n) for (int i = ((int)(n)); i > 0; i--)
#define irep(i, m, n) for (int i = (int)(m); i < (int)(n); ++i)
#define ireps(i, m, n) for (int i = (int)(m); i <= (int)(n); ++i)
#define SORT(v, n) sort(v, v + n);
#define REVERSE(v, n) reverse(v, v+n);
#define vsort(v) sort(v.begin(), v.end());
#define all(v) v.begin(), v.end()
#define mp(n, m) make_pair(n, m);
#define cout(d) cout<<d<<endl;
#define coutd(d) cout<<std::setprecision(10)<<d<<endl;
#define cinline(n) getline(cin,n);
#define replace_all(s, b, a) replace(s.begin(),s.end(), b, a);
#define PI (acos(-1))
#define FILL(v, n, x) fill(v, v + n, x);
#define sz(x) int(x.size())

using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vll = vector<ll>;
using vvll = vector<vll>;
using pii = pair<int, int>;
using pll = pair<ll, ll>;

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; }

const ll INF = 1e15;
const int MOD = 1e9+7;
const ll LINF = 1e18;

signed main()
{
  cin.tie( 0 ); ios::sync_with_stdio( false );
  ll n,m,s,t; cin>>n>>m>>s>>t;
  s--,t--;
  vector<vector<pll>> G(2*n);
  rep(i,m){
    ll u,v,a,b; cin>>u>>v>>a>>b;
    u--,v--;
    G[u].emplace_back(v,a);
    G[v].emplace_back(u,a);
    G[n+u].emplace_back(n+v,b);
    G[n+v].emplace_back(n+u,b);
  }
  
  vll dist(2*n,LINF);
  dist[s]=0;
  dist[n+t]=0;
  priority_queue<pll, vector<pll>, greater<pll>> q;
  q.emplace(0,s);
  q.emplace(0,n+t);
  while(!q.empty()){
    pll p=q.top(); q.pop();
    ll v=p.second, c=p.first;
    if(dist[v]<c) continue;
    for(auto np: G[v]){
      ll nv=np.first, nc=np.second;
      if(chmin(dist[nv],dist[v]+nc)){
        q.emplace(dist[nv],nv);
      }
    }
  }
  
  vll ans;
  ll base=1e15;
  ll max=0;
  rrep(i,n){
    ll val=base-(dist[i]+dist[n+i]);
    chmax(max,val);
    ans.push_back(max);
  }
  rrep(i,ans.size()){
    cout<<ans[i]<<endl;
  }
}

Measured memory_bytes: 19960
#include<bits/stdc++.h>
using namespace std;
struct line
{
	int s,t;
	int next;
}a[100001];
int head[100001];
int edge;
inline void add(int s,int t)
{
	a[edge].next=head[s];
	head[s]=edge;
	a[edge].s=s;
	a[edge].t=t;
}
int deg[100001];
int fa[100001];
queue<int> Q;
int main()
{
	int n,m;
	scanf("%d%d",&n,&m);
	int i,s,t;
	for(i=1;i<=n-1+m;i++)
	{
		scanf("%d%d",&s,&t);
		deg[t]++;
		edge++;
		add(s,t);
	}
	for(i=1;i<=n;i++)
	{
		if(deg[i]==0)
			Q.push(i);
	}
	while(!Q.empty())
	{
		int d=Q.front();
		Q.pop();
		int i;
		for(i=head[d];i!=0;i=a[i].next)
		{
			int t=a[i].t;
			deg[t]--;
			if(deg[t]==0)
			{
				fa[t]=d;
				Q.push(t);
			}
		}
	}
	for(i=1;i<=n;i++)
		printf("%d\n",fa[i]);
	return 0;
}

Measured memory_bytes: 3200
N = int(input())
memo = {}
ans = 0
for i in range(N):
    si = list(input())
    si.sort()
    si = ('').join(si)
    if si not in memo:
        memo[si] = 1
    else:
        memo[si] += 1
        ans += memo[si] - 1
print(ans)

Measured memory_bytes: 17808
#include <bits/stdc++.h>
using namespace std;
    
#define int long long int
#define vi vector<int>
#define vvi vector<vi>
#define read(a)  for(int i = 0; i < n; i++) cin >> a[i];
#define print(a)  for(int i = 0; i < n; i++) cout << a[i] << " ";
#define pb push_back
#define pql priority_queue<int>
#define pqs priority_queue<int, vi, greater<int>>
#define pqlv priority_queue<vi>
#define pqsv priority_queue<vi, vvi, greater<vi>>
#define endl '\n'
#define N 10000002
#define MOD 1000000007

signed main() {
    int n, q;
    cin >> n >> q;
    string s;
    cin >> s;
    vi c(n, 0);
    for(int i = 1; i < n; i++) {
        if(s[i] == 'C' && s[i - 1] == 'A') {
            c[i] = c[i - 1] + 1;
        }
        else {
            c[i] = c[i - 1];
        }
    }
    while(q--) {
        int l, r;
        cin >> l >> r;
        l--; r--;
        cout << c[r] - c[l];
        cout << endl;
    }
}

Measured memory_bytes: 1920
#include <bits/stdc++.h>
using namespace std;
 
int main() {
    long long N;
    cin>>N;
   vector<long long>cards(N);
    long long sum=0;
    for(long long i=0;i<N;i++){
        cin>>cards.at(i);
        sum+=cards.at(i);
        
    }
    //cout<<cards.at(1)<<endl;
    long long a_sum=0;
    vector<long long>results(N-1,9999);
    for(long long i =0;i<N-1;i++){
        a_sum+=cards.at(i);
        results.at(i)=abs(2*a_sum-sum);
        
        
    }
    sort(results.begin(),results.end());
    cout<<results.at(0)<<endl;
   
}

Measured memory_bytes: 3328
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define var auto
using namespace std;
using ll = long long;
using P = pair<int, int>;
// sort(A.begin(), A.end(), cmp)
bool cmp(P a, P b) { return a.second < b.second; }
#ifdef DEBUG
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; cout << a << endl; return 1; } cout << a << endl; return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; cout << a << endl; return 1; } cout << a << endl; return 0; }
#else
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; }
#endif
const ll INF = 1LL << 60;
const int MAX_ITEM = 10e4+10; // 10^5
ll dp[1000010][2] = {0};

int main() {
  string s;
  cin >> s;
  reverse(s.begin(), s.end());
  s += '0'; // 91 とか、繰り上がりの桁が必要なことがある
  int n = s.size();
  rep(i,n+1)rep(j,2) {
    dp[i][j] = INF;
  }

  dp[0][0] = 0;

  rep(i,n) {
    int x = s[i] - '0';

    // i桁目で繰り下がりがない場合
    chmin(dp[i+1][0], dp[i][0] + x);
    chmin(dp[i+1][1], dp[i][0] + (10 - x));
    chmin(dp[i+1][0], dp[i][1] + x + 1);
    chmin(dp[i+1][1], dp[i][1] + (10 - x - 1));
  }

  cout << dp[n][0] << endl;

  return 0;
}


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

signed main() {
  int n; cin >> n;
  vector<int> a(n);
  rep(i,n) cin >> a[i];

  sort(a.rbegin(),a.rend());
  int alice = 0, bob = 0;
  rep(i,n) {
    if(i%2==0) alice+=a[i];
    else bob+=a[i];
  }
  cout << alice-bob << endl;
}

Measured memory_bytes: 3636
#include <bits/stdc++.h>
#pragma once
using namespace std;
#define repd(i,a,b) for (int i=(a);i<(b);i++)
#define rep(i,n) repd(i,0,n)
typedef long long ll;
typedef long double lb;
#define int long long
#define double long double
#define endn "\n"
typedef pair<int,int> P;
const int MOD = 1000000007;
const ll INF = 1e16;
const double EPS = 1e-10;
const double PI = 3.141592653589793;
template<class T> inline bool chmin(T& a, T b){if(a>b){a = b;return 1;}return 0;}
template<class T> inline bool chmax(T& a, T b){if(a<b){a = b;return 1;}return 0;}
const pair<int,int> fd[] = {make_pair(1,0),make_pair(-1,0),make_pair(0,1),make_pair(0,-1)}; 


////////////////////////////////////////////////////////////////////

////////////////////////////////////////////////////////////////////

signed main(){
  int x;cin>>x;
  int ans = 0;
  ans += (x/500)*1000;
  x %= 500;
  ans += (x/5)*5;
  cout << ans << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
using P = pair<int,int>;
 
int main() {
  int x, y;
  cin >> x >> y;
  for (int c = 0; c <= x; c++) {
    int t = x-c;
    int asi = c*2+t*4;
    if (asi == y) {
      cout << "Yes" << endl;
      return 0;
    }
  }
  cout << "No" << endl;
  return 0;
}

Measured memory_bytes: 3636
#include <iostream>
#include <iomanip>
#include <cmath>
#include <string>
#include <vector>
#include <queue>
#include <stack>
#include <algorithm>
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
const ll mod=1e9+7;

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

	bool flg;
	ll ans=1;
	ll r=0;
	ll N=min(A,B);
	ll M=max(A,B);
	ll Max=sqrt(N);
	for(ll i=2; i<=Max; i++){
		if(N%i==0){
			r=0;
			do{
				r++;
				N=N/i;
			}while(N%i==0);
			if(M%i==0){
				ans++;
			}
		}
	}
	if(N>Max && M%N==0){
		ans++;
	}

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

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <queue>
#include <deque>
#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
typedef long long ll;

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; }

const int maxN = 100;
const ll maxW = 1000000000;
const int maxV = 100010;

const ll INF = 1LL << 60;

ll weight[110];
ll value[110];

int main(){
  int N;
  ll W;
  cin >> N >> W;

  for(int i = 0; i <N; i++){
    cin >> weight[i] >> value[i];
  }

  ll dp[110][maxV];
  for(int i = 0 ; i < 110; i++){
    for(int j = 0; j < maxV; j++){
      dp[i][j] = INF;
    }
  }
  // i-1番目の要素まで足した時点でのv以上を集められる最小のW
  //つまり wのリスト。足すのはW
  dp[0][0] = 0;

  for(int i = 0; i < N; i++){
    for(int sum_v = 0; sum_v < maxV; sum_v++){
      if(sum_v - value[i] >= 0){
        dp[i+1][sum_v] = min(dp[i+1][sum_v], dp[i][sum_v - value[i]] + weight[i]);
      }
      dp[i+1][sum_v] = min(dp[i+1][sum_v], dp[i][sum_v]);
    }
  }

  int answer = 0;
  for(int i = 0; i < maxV; i++){
    if(dp[N][i] <= W) answer = i;
  }

  cout << answer << endl;
  return 0;
}



Measured memory_bytes: 86144
import java.util.Scanner;
class Puz{
	Puz(int a[],int space,int path,int MD) {
		this.MD=MD;
		this.path=path;
		this.space=space;
		for(int i=0;i<a.length;i++)
			pic[i]=a[i];
	}
	public int[] pic = new int[16];
	public int path,MD,space;
	public int getX() {return this.space/4;}
	public int getY() {return this.space%4;}
	public void swap(int a,int b) {
		int tmp=this.pic[a];
		this.pic[a]=this.pic[b];
		this.pic[b]=tmp;
	}
}
public class Main { 
	private static final int N=4;
	private static final int NN=16;
	private static final int LIMIT =100;
	private static int[][] MDT = new int[NN][NN];
	private static int[] dx = {0,1,0,-1};
	private static int[] dy = {1,0,-1,0};
	private static int lim;
	public static void getMD() {
		for(int i=0;i<NN;i++) {
			for(int j=0;j<NN;j++) {
				MDT[i][j]=Math.abs(i/N-j/N)+Math.abs(i%N-j%N);
			}
		}
	}
	public static boolean dfs(Puz cur,int dep,int prev){
		if(cur.MD==0) {
			System.out.println(cur.path);
			return true;
		}
		if(dep+cur.MD>lim) return false;
		int sx=cur.getX();
		int sy=cur.getY();
		for(int i=0;i<4;i++) {
			Puz tmp = new Puz(cur.pic,cur.space,cur.path,cur.MD);
			int tx=sx+dx[i];
			int ty=sy+dy[i];
			if(tx<0 || ty<0 || tx>=N || ty>=N) continue;
			if(Math.max(i,prev)-Math.min(i,prev)==2) continue;
			tmp.MD-=MDT[tx*N+ty][cur.pic[tx*N+ty]-1];
			tmp.MD+=MDT[sx*N+sy][cur.pic[tx*N+ty]-1];
			tmp.swap(sx*N+sy,tx*N+ty);
			tmp.space=tx*N+ty;
			tmp.path++;
			if(dfs(tmp,dep+1,i)){ 
				return true;
			}
		}
		return false;
	}
	public static void iterative(Puz in) {
		for(lim = in.MD;lim<=LIMIT;lim++) {
			if(dfs(in,0,-10)) return;
		}
	}
	
	public static void main(String[] args) {
		Scanner in = new Scanner(System.in);
		int space=0,sum=0;
		int org[] = new int[NN];
		getMD();
		for(int i=0;i<NN;i++) {
			org[i]=in.nextInt();
			if(org[i]==0) {
				org[i]=NN;
				space=i;
			}
			if(org[i]!=NN) sum+=MDT[i][org[i]-1];
		}
//		System.out.println(sum);
		Puz src = new Puz(org,space,0,sum);
		iterative(src);
		in.close();
	}

}



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

int main() {
	string S;
	cin >> S;
	int ans;
	if (S == "SUN") ans = 7;
	if (S == "MON") ans = 6;
	if (S == "TUE") ans = 5;
	if (S == "WED") ans = 4;
	if (S == "THU") ans = 3;
	if (S == "FRI") ans = 2;
	if (S == "SAT") ans = 1;
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 3592
import numpy as np


def exp_np(a, e, m):
    r = np.identity(a.shape[0], dtype=np.int64)
    t = a.copy()
    while e:
        if e % 2:
            r = np.dot(r, t) % m
        t = np.dot(t, t) % m
        e >>= 1
    return r


l, a, b, m = map(int, input().split())

first_d = len(str(a))
tail = a + b * (l - 1)

lo = -1
state = np.array([[0, a % m, 1]])

for d in range(first_d, 19):
    hi = min((10 ** d - 1 - a) // b, l - 1)
    cnt = hi - lo
    coe = np.array([
        [pow(10, d, m), 0, 0],
        [1, 1, 0],
        [0, b % m, 1]
    ], dtype=np.int64)

    coe = exp_np(coe, cnt, m)
    state = np.dot(state, coe) % m

    lo = hi
    if hi == l - 1:
        break

print(state[0][0])


Measured memory_bytes: 14532
import std.algorithm;
import std.conv;
import std.math;
import std.range;
import std.stdio;
import std.string;
import std.typecons;

//0 + 1 + .. + n
long s (int n) {
  return (n.to!long * (n + 1)) / 2; 
}

long f (int n, int k) {
  long minv = s (k - 1);
  long maxv = s (n) - s (n - k);
  return (maxv - minv + 1) % 1_000_000_007;
}

void main() {
  int n, k;
  readf (" %d %d", &n, &k);
  long res;
  foreach (l; k .. n + 2) {
    res += f (n, l);
  }
  writeln (res % 1_000_000_007);
}



Measured memory_bytes: 3116
#[allow(unused_imports)]
use std::io;
#[allow(unused_imports)]
use std::cmp::max;
#[allow(unused_imports)]
use std::cmp::min;

#[allow(unused_macros)]
macro_rules! get {
    ($i:ident) => {
        $i = String::new();
        io::stdin().read_line(&mut $i).ok();
    };
}

#[allow(unused_macros)]
macro_rules! to_vec {
    ($s:ident, $t:ty) => {
        $s.split_whitespace().map(|i| i.parse().ok().unwrap()).collect::<Vec<$t>>()
    }
}

#[allow(unused_macros)]
macro_rules! parse {
    ($s:ident, $t:ty) => {
        $s.trim().parse::<$t>().ok().unwrap()
    }
}

#[allow(unused_macros)]
macro_rules! max {
    ($v:ident) => {
        $v.iter().max().unwrap()
    };
}

#[allow(unused_macros)]
macro_rules! min {
    ($v:ident) => {
        $v.iter().max().unwrap()
    };
}

#[allow(unused_macros)]
macro_rules! sort {
    ($v:ident) => {
        $v.as_mut_slice().sort()
    };
}

#[allow(unused_variables)]
#[allow(unused_mut)]
fn main() {
    let mut s: String;
    get!(s);
    let n = parse!(s, usize);
    get!(s);
    let mut a = to_vec!(s, i32);
    let mut flag = true;
    let mut sum = 0;
    while flag {
        flag = false;
        for j in 0..(n - 1) {
            if a[j] > a[j + 1] {
                a.swap(j, j + 1);
                sum += 1;
                flag = true;
            }
        }
    }

    for i in 0..n {
        print!("{}", a[i]);
        if i != (n - 1) {
            print!(" ");
        } else {
            println!();
        }
    }

    println!("{}", sum);
}


Measured memory_bytes: 5040
#include <stdio.h>

int main(int argc, const char * argv[]){
    int x, y;
    while (1) {
        scanf("%d %d", &x, &y);
        if(x == 0 && y == 0){
            break;
        }
        if(x < y){
            printf("%d %d\n", x, y);
        }else{
            printf("%d %d\n",y, x);
        }
    }
    
}



Measured memory_bytes: 2140
import java.util.*;
import static java.lang.Math.*;

public class Main {
	public static void main(String[] args) throws Exception {
		Scanner sc = new Scanner(System.in);
		
		// 入力
		int n = sc.nextInt();
		
		// 計算
		long result = 0;
		for(long i = 1; i <= n; i++){
		    if(i%3 != 0 && i%5 != 0) result += i;
		}
		
		// 出力
		System.out.println(result);
	}
}



Measured memory_bytes: 27240
#define TEMPLATE_USED
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef pair<ll,ll> pl;
typedef vector<pl> vp;
const ll INF=1001001001;
const ll LINF=1001001001001001001;
const ll D4[]={0,1,0,-1,0};
const ll D8[]={0,1,1,0,-1,-1,1,-1,0};
#define _overload3(_1,_2,_3,name,...) name
#define _rep2(i,n) for(ll i=0;i<(n);++i)
#define _rep3(i,a,b) for(ll i=(ll)(a);i<(ll)(b);++i)
#define rep(...) _overload3(__VA_ARGS__,_rep3,_rep2)(__VA_ARGS__)
#define _repe2(i,n) for(ll i=0;i<=(ll)(n);++i)
#define _repe3(i,a,b) for(ll i=(ll)(a);i<=(ll)(b);++i)
#define repe(...) _overload3(__VA_ARGS__,_repe3,_repe2)(__VA_ARGS__)
#define _rrep2(i,n) for(ll i=(ll)(n)-1;i>=0;i--)
#define _rrep3(i,a,b) for(ll i=(ll)(b)-1;i>=(ll)(a);i--)
#define rrep(...) _overload3(__VA_ARGS__,_rrep3,_rrep2)(__VA_ARGS__)
#define _rrepe2(i,n) for(ll i=(ll)(n);i>=0;i--)
#define _rrepe3(i,a,b) for(ll i=(ll)(b);i>=(ll)(a);i--)
#define rrepe(...) _overload3(__VA_ARGS__,_rrepe3,_rrepe2)(__VA_ARGS__)
#define all(x) (x).begin(),(x).end()
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;}

ll N;
vl a;

void solve();

int main(){
    cin.tie(0);
    ios::sync_with_stdio(0);
    cin >> N;
    a = vl(N);
    for(int i = 0; i < N; ++i){
        cin >> a[i];
    }
    solve();
}

// 入力はすべて整数である
// 2 <= N <= 200000
// N は\textbf{偶数}
// 0 <= a_i <= 10^9
// 与えられた情報と整合するようなスカーフ上の整数の組合せが存在する

// ll N, vl a
// 1 行に N 個の整数を空白区切りで出力せよ。
// このうち左から i 番目の整数は、番号 i が振られたすぬけくんのスカーフに書かれた整数を表すものとする。
// 与えられた条件を満たす解が複数存在する場合、どれを出力しても構わない。
void solve(){
    ll sum=0;
    rep(i,N)sum^=a[i];

    rep(i,N){
        if(i>0)cout<<' ';
        cout<<(sum^a[i]);
    }
    cout<<endl;
}


Measured memory_bytes: 4668
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (int)(n); i++)
#define REP(i,n) for (int i = 1; i < (int)(n); i++)
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(),x.rend()
#define vout(x) rep(i,x.size()) cout << x[i] << " "
template<class T> bool chmin(T &a, T b) {if(a>b) {a=b;return 1;}return 0;}
template<class T> bool chmax(T &a, T b) {if(a<b) {a=b;return 1;}return 0;}
using namespace std;
using vint = vector<int>;
using vvint = vector<vector<int>>;
using ll = long long;
using vll = vector<ll>;
using vvll = vector<vector<ll>>;
using P = pair<int,int>;
const int inf = 1e9;
const ll inf_l = 1e18;
const int MAX = 1e5;

int main() {
    int n, m; cin >> n >> m;
    int s = 1900*m+(n-m)*100;
    s *= pow(2,m);
    cout << s << endl;
}

Measured memory_bytes: 384
N=int(input())
X=[0,0,0,0,0]
for I in range(N):
	L=input()
	if L[0]=='M':
		X[0]+=1
	elif L[0]=='A':
		X[1]+=1
	elif L[0]=='R':
		X[2]+=1
	elif L[0]=='C':
		X[3]+=1
	elif L[0]=='H':
		X[4]+=1
SUM=0
for J in range(3):
	for K in range(J+1,4):
		for M in range(K+1,5):
			if J!=K and K!=M and (X[J]!=0 or X[K]!=0 or X[M]!=0):
				SUM+=X[J]*X[K]*X[M]
print(SUM)

Measured memory_bytes: 3064
package main

import (
	"bufio"
	"fmt"
	"io"
	"math"
	"os"
	"strconv"
	"strings"

)


func main() {
	solve(os.Stdin, os.Stdout)
}

type ReaderEx struct {
	baseScanner *bufio.Scanner
	words       []string
	nextWordIdx func() int
	initWordIdx func(int)
}

func NewScannerEx(stdin io.Reader) *ReaderEx {
	var this ReaderEx
	var idx int
	var wordsCnt int
	this.baseScanner = bufio.NewScanner(stdin)
	this.baseScanner.Buffer(make([]byte, 0), 1E+11)
	this.nextWordIdx = func() int {
		cur := idx
		idx = (idx + 1) % wordsCnt
		return cur
	}
	this.initWordIdx = func(wc int) {
		idx = 0
		wordsCnt = wc
	}
	return &this
}

func (me *ReaderEx) Scan(doSplit bool) (isScanned bool) {
	isScanned = me.baseScanner.Scan()
	if doSplit {
		me.words = strings.Fields(me.baseScanner.Text())
	} else {
		me.words = []string{me.baseScanner.Text()}
	}
	me.initWordIdx(len(me.words))
	return
}

func (me *ReaderEx) nextBytes() []byte {
	return []byte(me.words[me.nextWordIdx()])
}
func (me *ReaderEx) nextString() string {
	return me.words[me.nextWordIdx()]
}

type StringArray []string

func (me *ReaderEx) nextStringArray() StringArray {
	return me.words[me.nextWordIdx():]
}

func (me StringArray) toStrings() []string {
	return me
}

func (me StringArray) toInts() []int {
	strValues := me.toStrings()
	values := make([]int, len(strValues))
	for i, v := range strValues {
		n, err := strconv.Atoi(v)
		if err != nil {
			panic(err)
		}
		values[i] = n
	}
	return values
}
func (me *ReaderEx) nextInt() int {
	n, err := strconv.Atoi(me.words[me.nextWordIdx()])

	defer func() {
		if err != nil {
			panic(fmt.Sprintf("getInt(%d)", n))
		}
	}()
	return n
}

func pow(x, y, mod int) (ans int) {

	ans = 1
	for bit := 1 << uint(math.Floor(math.Log2(float64(y)))); ; bit >>= 1 {
		if y&bit != 0 {
			ans *= x
			if mod > 0 {
				ans %= mod
			}
		}
		if bit <= 1 {
			return
		}
		ans *= ans
		if mod > 0 {
			ans %= mod
		}
	}
}

type factType struct {
	prime int
	count int
}

func fact(n int) (facts []*factType) {

	for i := 2; i*i <= n; i++ {
		if n%i == 0 {
			fa := factType{prime: i}
			for n%fa.prime == 0 {
				n /= fa.prime
				fa.count++
			}
			facts = append(facts, &fa)
		}
	}
	if n > 1 {
		facts = append(facts, &factType{prime: n, count: 1})
	}
	return facts
}
func dec2bin(n int) (ret []bool) {
	for bit := 1 << uint(math.Floor(math.Log2(float64(n)))); ; bit >>= 1 {
		ret = append(ret, n&bit != 0)

		if bit <= 1 {
			return
		}
	}

}

func abs(v int) int {
	if v < 0 {
		v = -v
	}
	return v
}

func b2i(b bool) (i int) {
	if b {
		i = 1
	} else {
		i = 0
	}
	return
}

func solve(stdin io.Reader, stdout io.Writer) {

	r := NewScannerEx(stdin)
	r.Scan(true)
	n, m := r.nextInt(), r.nextInt()

	nodes := make(map[int]int, n)
	for i := 0; i < m; i++ {
		r.Scan(true)
		for j := 0; j < 2; j++ {
			nodes[r.nextInt()]++
		}
	}

	ans := true
	for _, v := range nodes {
		if v&1 == 1 {
			ans = false
			break
		}
	}

	fmt.Fprintln(stdout, []string{"NO", "YES"}[b2i(ans)])
}


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

string s;

int main(){
  
  cin >> s;
  if(s[0] != 'A') {cout << "WA" << endl; return 0;}
  
  bool clr = true;
  int cnt = 0;
  for(int i = 1; i < s.size(); i++){
    if(isupper(s[i])) {
      if(i == 1 || i == s.size()-1 || s[i] != 'C'){
        clr = false;
      }
      cnt++;
    }
  }
  if(cnt != 1) clr = false;
  if(clr) cout << "AC" << endl;
  else cout << "WA" << endl;
}

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

#define INF (int)(1e9)
#define MOD (int)((int)1e9+7)

int imos[1100][1100];
int main(){
  int N;
  int x1, x2, y1, y2, ans = 0;

  cin>>N;

  for(int i = 0; i < N; i++){
   
      cin>>x1>>y1>>x2>>y2;
      //y2++;x2++;
      imos[y1][x1]++;
      imos[y2][x1]--;
      imos[y1][x2]--;
      imos[y2][x2]++;
  }
  for(int i = 0; i < 1010; i++){
    for(int j = 0; j < 1010; j++){//cout<<i<<endl;
      imos[i][j+1] += imos[i][j];
    }
  }
  for(int i = 0; i <= 1010; i++){
    for(int j = 0; j <= 1010; j++){
      imos[j+1][i] += imos[j][i];
    }
  }


  
  for(int i = 0; i <= 1000; i++){
    for(int j = 0; j <= 1000; j++){//printf("%4d",imos[i][j]);
      ans = max(imos[i][j],ans);
    }//cout<<endl;
  }

  cout<<ans<<endl;

  return 0;
}



Measured memory_bytes: 7448
#include <iostream>
#include <algorithm>
#include <iomanip>
#include <string>
#include <vector>
#include <math.h>
#include <queue>
#include <map>
const int MOD = 1e9+7;
typedef long long ll;
using namespace std;

int main(){
	int n;
	cin >> n;
	vector<int> h(n);
	for (int i = 0; i < n; i++){
		cin >> h[i];
	}
	for (int i = 0; i < n-1; i++){
		if (h[i] - h[i-1] >= 1){
			h[i]--;
		}
	}
	for (int i = 0; i < n-1; i++){
		if (h[i] > h[i+1]){
			cout << "No" << endl;
			return 0;
		}
	}
	cout << "Yes" << endl;
	return 0;
}



Measured memory_bytes: 640
#include <iostream>
#include <iomanip>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <algorithm>
#include <cstdio>
#include <utility>
#include <string>
#include <cmath>
#include <cstdlib>
#include <cstring>
#include <deque>
#include <numeric>

using namespace std;

typedef uint64_t u64;
typedef int64_t s64;
typedef uint32_t u32;
typedef int32_t s32;
typedef vector<s32> vs32;
typedef vector<u32> vu32;
typedef vector<s64> vs64;
typedef vector<u64> vu64;

const double PI=3.14159265358979323846;

#define MAX(x, y) ((x) < (y) ? (y) : (x))
#define MIN(x, y) ((x) > (y) ? (y) : (x))

#define rep(i, N) for(int i = 0; i < N; ++i)

#define CEIL(x, y) (((x) + (y) - 1) / (y))
#define MOD 1000000007ULL

#define IN(l, r, x) ((l) <= (x) && (x) < (r))

s64 num[100001];

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

    s64 n, k;
    cin >> n >> k;

    rep (i, n)
    {
        int a, b;
        cin >> a >> b;
        num[a] += b;
    }

    int ans = 1;
    s64 sum = 0;
    while (sum + num[ans] < k)
    {
        sum += num[ans++];
    }

    cout << ans << "\n";
    return 0;
}



Measured memory_bytes: 1024
#include<cstdio>
#include<algorithm>
using namespace std;
const int maxn=20;
int n,m,X,a[maxn][maxn],b[maxn],ans=2e9;
bool check(){
	for (int i=1;i<=m;i++) if(b[i]<X) return 0;
	return 1;
}
int main(){
	scanf("%d%d%d",&n,&m,&X);
	for (int i=0;i<n;i++)
	for (int j=0;j<=m;j++) scanf("%d",&a[i][j]);
	for (int s=(1<<n)-1;~s;s--){
		for (int i=0;i<=m;i++) b[i]=0;
		for (int i=0;i<n;i++) if(s&(1<<i))
		for (int j=0;j<=m;j++) b[j]+=a[i][j];
		if(check()) ans=min(ans,b[0]);
	}
	printf("%d\n",ans==2e9?-1:ans);
	return 0;
}

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

using namespace std;
using ll = long long;

const ll MOD = 1000000007;

int main() {
    int N, M;
    cin >> N >> M;

    int A[N + 1], B[M + 1];
    for (int x = 0; x < N; ++x) {
        cin >> A[x];
    }
    A[N] = 0;
    for (int y = 0; y < M; ++y) {
        cin >> B[y];
    }
    B[M] = 0;

    sort(A, A + N + 1, greater<int>());
    sort(B, B + M + 1, greater<int>());

    ll ans = 1;
    int nx = 0, ny = 0;
    for (int v = N * M; v > 0; --v) {
        if (A[nx] == v && B[ny] == v) {
            // vは(nx, ny)に入る
            ++nx, ++ny;
        } else if (A[nx] == v) {
            // vは(nx, 0)~(nx, ny-1)に入る
            ++nx;
            ans *= ny;
            ans %= MOD;
        } else if (B[ny] == v) {
            // vは(0, ny)~(nx-1, ny)に入る
            ++ny;
            ans *= nx;
            ans %= MOD;
        } else {
            // vは(0, 0)~(nx-1, ny-1)に入る
            // すでにN*M-v個埋まっている
            int unfilled = (nx * ny) - (N * M - v);
            ans *= unfilled;
            ans %= MOD;
        }
    }
    cout << ans << endl;
    return 0;
}


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

typedef long long ll;

ll arr[200010];
ll psum[200010];
int n;

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

    psum[0] = arr[n - 1];
    for (int i = 1; i < n; i++) {
        psum[i] = arr[n - i - 1] + psum[i - 1];
    }

    ll min = 1e16L;

    for (int i = 0; i < n - 1; i++) {
        ll tmp = abs(psum[n - 1] - 2 * psum[i]);
        if (tmp < min) {
            min = tmp;
        }
    }

    cout << min << endl;
}

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

int main()
{
	while(1) {
		int x, y, z;
		cin >> x >> y;
		if (x == 0 && y == 0)break;
		if (x > y) {
			z = x;
			x = y;
			y = z;
			cout << x <<" "<< y << endl;
		}
		else {
			cout << x <<" "<< y<<endl;
		}
	}
    return 0;
}

Measured memory_bytes: 1160
def main(n):
	odd = "1"
	even= "0"
	if(n[0] =="0"):
		# zero mode
		odd = "0"
		even= "1"
	a = sum((((i % 2 != 0) and n[i] == odd)) for i in range(1, len(n),2))
	b = sum((((i % 2 == 0) and n[i] == even)) for i in range(0, len(n),2))
	return a+b

print(main(input()))

Measured memory_bytes: 3188
#include <iostream>
#include <algorithm>
#include <vector>
#include <cmath>
#include <queue>
#include <map>
#include <unordered_map>
#include <stack>
#include <iomanip>
#include <queue>
#include <set>
#include <bitset>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>



#define ll long long
#define uint unsigned int
#define ull unsigned ll
#define mp make_pair
#define pb push_back
#define all(x) x.begin(), x.end()
#define allr(x) x.rbegin(), x.rend()
#define speedhack() ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define do(x) for(int i = 1; i <= x; i++){ solve(); }
#define sz(x) (int)x.size()
#define pii pair < int, int >
using namespace std;
using namespace __gnu_pbds;
#define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>
 
const ll MAXN = 1e18;
const ll SIZE = 1e6 + 2;  //are u sure?
const ll mod = 1e9+7;
ll dp[SIZE];

ll prefmax[SIZE];
ll prefmin[SIZE];

int maxlim = 0;


void solve(){
	ll n, a, b;
	cin >> n >> a >> b;
	if(a > b) swap(a, b);
	ll diff = b - a;
	if(diff % 2 == 1){
		ll left = a;
		ll right = n - b + 1;
		cout << min(left, right) + diff / 2 << endl;
	}else{
		cout << diff / 2 << endl;
	}
}


int main(){
	speedhack()
	// int it; cin >> it;
	int it = 1;
	do(it);
	return 0;
}

Measured memory_bytes: 256
import sys
import math
import collections
import itertools
import array
import inspect

# Set max recursion limit
sys.setrecursionlimit(1000000)


# Debug output
def chkprint(*args):
    names = {
        id(v): k
        for k, v in inspect.currentframe().f_back.f_locals.items()
    }
    print(', '.join(
        names.get(id(arg), '???') + ' = ' + repr(arg) for arg in args))


# Binary converter
def to_bin(x):
    return bin(x)[2:]


def li_input():
    return [int(_) for _ in input().split()]


def gcd(n, m):
    if n % m == 0:
        return m
    else:
        return gcd(m, n % m)


def gcd_list(L):
    v = L[0]

    for i in range(1, len(L)):
        v = gcd(v, L[i])

    return v


def lcm(n, m):
    return (n * m) // gcd(n, m)


def lcm_list(L):
    v = L[0]

    for i in range(1, len(L)):
        v = lcm(v, L[i])

    return v


# Width First Search (+ Distance)
def wfs_d(D, N, K):
    """
    D: 隣接行列(距離付き)
    N: ノード数
    K: 始点ノード
    """

    dfk = [-1] * (N + 1)
    dfk[K] = 0

    cps = [(K, 0)]
    r = [False] * (N + 1)
    r[K] = True
    while len(cps) != 0:
        n_cps = []
        for cp, cd in cps:
            for i, dfcp in enumerate(D[cp]):
                if dfcp != -1 and not r[i]:
                    dfk[i] = cd + dfcp
                    n_cps.append((i, cd + dfcp))
                    r[i] = True

        cps = n_cps[:]

    return dfk


# Depth First Search (+Distance)
def dfs_d(v, pre, dist):
    """
    v:  現在のノード
    pre: １つ前のノード
    dist: 現在の距離

    以下は別途用意する
    D: 隣接リスト(行列ではない)
    D_dfs_d: dfs_d関数で用いる，始点ノードから見た距離リスト
    """

    global D
    global D_dfs_d

    D_dfs_d[v] = dist

    for next_v, d in D[v]:
        if next_v != pre:
            dfs_d(next_v, v, dist + d)

    return


# --------------------------------------------

dp = None


def main():
    N = int(input())
    A = li_input()
    C = []

    tmpsum = 0
    for a in A:
        tmpsum += a
        C.append(tmpsum)

    ans = 10**100

    for i in range(len(C) - 1):
        ans = min(ans, abs((C[-1] - C[i]) - C[i]))

    print(ans)


main()


Measured memory_bytes: 26952