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

#define endl "\n"

//typedef
//------------------------------------------
typedef pair<int, int> PII;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef vector<PII> VP;

//REPEAT
//------------------------------------------
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)

//container util
//------------------------------------------
#define pb push_back
#define paired make_pair
#define ALL(a) (a).begin(),(a).end()
#define PRINT(V) for (auto v : (V)) cout << v << " "
#define SORT(V) sort((V).begin(),(V).end())
#define RSORT(V) sort((V).rbegin(), (V).rend())

//constant
//------------------------------------------
const int MOD = 1000000007;
const int INF = 1061109567;
const double EPS = 1e-10;
const double PI  = acos(-1.0);
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};

//math
//------------------------------------------
int QP(int a,int b){int ans=1;do{if(b&1)ans=1ll*ans*a%MOD;a=1ll*a*a%MOD;}while(b>>=1);return ans;}
int QP(int a,int b,int MOD){int ans=1;do{if(b&1)ans=1ll*ans*a%MOD;a=1ll*a*a%MOD;}while(b>>=1);return ans;}
int GCD(int a,int b){return b?GCD(b,a%b):a;}

//debug
//------------------------------------------
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

//grobal variable
//------------------------------------------
int N,M;
VI Vec;

//動的計画法で役に立つ関数
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; }

//最大公約数と最小公倍数
ll gcd(ll a, ll b) {
    if(b==0)return a;
    return gcd(b, a%b);
}

ll lcm(ll a, ll b) {
  ll g = gcd(a, b);
  return a/g*b;
}

int main() 
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    
    string S;
    cin >> S;
    char b = '+';
    bool is_bad = false;
    for (auto s:S)
    {
        if (s==b)
        {
            is_bad=true;
            break;
        }
        else b = s;
    }
    if (is_bad) cout << "Bad" << endl;
    else cout << "Good" << endl;
    return 0;
}



Measured memory_bytes: 256
n = int(input())
p = list(map(int,input().split()))
a = []
b = []
x = [0]*n
for i in range(n):
  x[p[i]-1] = 800000000+i
a.append(1)
b.append(x[0]-1)
for i in range(1,n):
  y = a[-1]+1
  z = b[-1]-1
  if y+z>x[i]:
    z = x[i]-y
  if y+z <x[i]:
    y = x[i]-z
  a.append(y)
  b.append(z)
print(*a)
print(*b)

Measured memory_bytes: 46212
#include<bits/stdc++.h>
using namespace std;
#define sync ios_base::sync_with_stdio(false), cin.tie(NULL)
#define F first
#define S second
#define eb emplace_back
#define pb emplace_back
#define mt make_tuple
#define gcd __gcd
// Input
#define in(a) scanf("%d",&a)
#define in2(a,b) scanf("%d%d",&a,&b)
#define in3(a,b,c) scanf("%d%d%d",&a,&b,&c)
#define llin(a) cin >> a
#define inl(a) scanf("%lld",&a)
#define read(v,i,n) for(i=0;i<n;i++)in(v[i])
#define twod(mat,i,j,n,m) rep(i,n){rep(j,m)in(mat[i][j]);}
#define sc(ch) scanf("%c",&ch)
#define sstr(str) scanf("%s",str)
// Output
#define pr(a) printf("%d ",a)
#define pr2(a,b) printf("%d %d\n",a,b);
#define pr3(a,b,c) printf("%d %d %d\n",a,b,c);
#define out(a) printf("%d\n",a)
#define outl(a) printf("%lld\n",a)
#define llpr(a) cout << a << " "
#define llout(a) cout << a << "\n"
#define yes printf("YES\n")
#define no printf("NO\n")
#define lin printf("\n")
// Iterator
#define lp(i,a,b) for(i=a;i<b;i++)
#define rep(i,n) for(i=0;i<n;i++)
#define all(vec) vec.begin(),vec.end()
#define lower(v,k) lower_bound(v.begin(),v.end(),k)-v.begin()
#define upper(v,k) upper_bound(v.begin(),v.end(),k)-v.begin()
#define tf(mytuple) get<0>(mytuple)
#define ts(mytuple) get<1>(mytuple)
#define tt(mytuple) get<2>(mytuple)
// Debug
#define dbg(v,i,n) for(i=0;i<n;i++)pr(v[i]); lin
#define what(x) cerr << #x << " : " << x << "\n";
#define ck printf("continue\n")
#define debug(args...) { string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); stringstream _ss(_s); istream_iterator<string> _it(_ss); err(_it, args); }
void err(istream_iterator<string> it) {}
template<typename T, typename... Args>
void err(istream_iterator<string> it, T a, Args... args)
{
	cerr << *it << " = " << a << "\n";
	err(++it, args...);
}
// Data Type
#define ll long long int
#define ii pair<int,int>
#define pli pair<ll,int>
#define state tuple<int,int,int>
#define vi vector<int>
#define vii vector<pair<int,int> >
#define vvi vector<vector<int> >
#define viii vector<pair<pair<int,int>,int> >
#define vvii vector<vector<pair<int,int> > >
#define M 1000000007
#define Z 505  //check the limits, man
#define N 100001
const ll INF = 1e10;
int main()
{
    ll i,j,x,n,ans;
    llin(n);
    x=sqrt(n);
    ans=n-1;
    for(i=1;i<=x;i++)
    {
        if((n%i)==0)
        {
            j=(n/i);
            ans=min(ans,i+j-2);
        }
    }
    llout(ans);
}









Measured memory_bytes: 256
#define _CRT_SECURE_NO_WARNINGS

#include<stdio.h>
#include <vector>

int a, b, c, d, e, k;

int main() {

	scanf("%d%d%d%d%d%d", &a, &b, &c, &d, &e, &k);

	if (e - a <= k) {
		printf("Yay!\n");
		return 0;
	}
	printf(":(\n");

	return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<int(n);++i)
#define maxch(res,x) res=max(res,x)
#define INF 1e9

bitset<10> f[100];
int p[100][11];

int main(void){
    int n;
    cin>>n;
    rep(i,n){
        rep(j,10) {
            bool bit;
            cin>>bit;
            f[i][j] = bit;
        }
    }
    rep(i,n)rep(j,11) cin>>p[i][j];

    int res = -INF;
    rep(mask,1<<10)if(mask){
        int sum = 0;
        rep(i,n){
            sum += p[i][(bitset<10>(mask) & f[i]).count()];
        }
        maxch(res,sum);
    }
    cout<<res<<endl;
    return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
int main(void)
{
  int H,W,i,j,k;
  for(k=0;;k++){
  scanf("%d %d",&H,&W);
    if(H==0 && W==0){break;}
  for(i=0;i<H ;i++ )
    {
      for(j=0;j<W;j++)
	{ printf("#");}
      printf("\n");
    }
  printf("\n");
  }
  return 0;
}

Measured memory_bytes: 572
var
  s1,s2:string;
  a,b:array['a'..'z']of longint;
  c:array[1..26]of boolean;
  o:boolean;
  i,j,k,p:longint;
begin
  readln(s1);
  read(s2);
  k:=length(s2);
  o:=true;
  if length(s1)<length(s2) then begin k:=length(s1); o:=false; end;
  for i:=1 to k-1 do
  begin
    inc(a[s1[i]]);
	inc(b[s2[i]]);
  end;
  if o then inc(b[s2[k]])
  else inc(a[s1[k]]);
  if o then p:=length(s1)
  else p:=length(s2);
  for i:=k to p do
  begin
  begin
     if o then inc(a[s1[i]])
	 else inc(b[s2[i]]);
  end;
  end;
  o:=true;
  for i:=1 to 26 do
  begin
     p:=a[chr(i+ord('a')-1)];
	 for j:=1 to 26 do
	 begin
	    if (c[j]=false)and(b[chr(j+ord('a')-1)]=p) then 
		begin
		   c[j]:=true;
		   break;
		end;
		if j=26 then o:=false;
     end;
	 if o=false then begin writeln('No'); halt; end;
  end;
  writeln('Yes');
end.

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


double a,b,c,d,e,f;
double x,y;//x,y座標
int main(){
  while(scanf("%lf %lf %lf %lf %lf %lf",&a,&b,&c,&d,&e,&f) !=EOF){

      x =(c*e - b*f)/(a*e - d*b);
      y =(c -a*x)/b;
    if(y > 0){
      y =floor((y+0.0005)*1000)/1000;
    }
    if(y < 0){
      y = -1*(floor((fabs(y)+0.0005)*1000)/1000);
    }
    if(x > 0){//小数第4位を四捨五入
      x =floor((x+0.0005)*1000)/1000;
    }
    if(x <0){
      x = -1*(floor((fabs(x)+0.0005)*1000)/1000);
    }
    if(x == 0){x =0.000;}
    if(y == 0){y =0.000;}
    printf("%.3f %.3f\n",x,y);
  }
  return 0;
}

Measured memory_bytes: 1232
#include <iostream>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<vector>
#include<algorithm>
#include<cstring>
#include<queue>
#include<set>
#include<map>
#include<cmath>
using namespace std;
const int maxn=2e5+10;
typedef long long LL;
const LL mod=1e9+7;
const double pi=acos(-1.0);
int n;
int in[maxn];
int main()
{
    scanf("%d",&n);
    for(int i=2;i<=n;i++){
        int pre;
        scanf("%d",&pre);
        in[pre]++;
    }
    for(int i=1;i<=n;i++){
        printf("%d\n",in[i]);
    }
    return 0;
}


Measured memory_bytes: 4548
n, k = map(int, input().split())
a = list(map(int, input().split()))

ans = 10**12
for i in range(1, 2**n, 2):
    if k != sum([i >> j & 1 for j in range(n)]):
        continue
    pre = a[0]
    cost = 0
    for j in range(1, n):
        if i >> j & 1:
            tmp = max(pre - a[j] + 1, 0)
            pre = a[j] + tmp
            cost += tmp
        else:
            pre = max(pre, a[j])
    ans = min(ans, cost)
print(ans)


Measured memory_bytes: 9192
#![allow(unused_imports)]

use proconio::{input, fastout};
use proconio::marker::*;

#[fastout]
fn main() {
    input! {
    n: usize,
    h: [usize; n]
    }
    let mut ans = 0;
    let mut t = 0;
    for i in 0..n {
        if h[i] >= t {
            t = h[i];
        } else {
            ans += t - h[i];
            t = h[i];
        }
    }
    ans += t;
    println!("{}", ans);
}



Measured memory_bytes: 2164
#include <stdio.h>
#include <algorithm>
#include <vector>
#include <tuple>
#include <functional>

#define FOR(i, a, b) for(int (i) = (a); (i) < (b); ++(i))
#define REP(i, n) FOR(i, 0, n)
using lli = long long int;
using pii = std::pair<int, int>;

std::vector<int> A;
std::vector<pii> B;

int main(void){
    int n, m; scanf("%d%d", &n, &m);
    A.resize(n); REP(i, n) scanf("%d", &A[i]);
    B.resize(m); REP(i, m) scanf("%d%d", &B[i].first, &B[i].second);
    std::sort(B.begin(), B.end(), [](pii& a, pii& b){
        if(a.second != b.second) return a.second > b.second;
        return a.second < b.second;
    });
    int append = n;
    REP(i, m){
        int usable = append > B[i].first ? B[i].first : append;
        append -= usable;
        REP(j, usable) A.push_back(B[i].second);
    }
    std::sort(A.begin(), A.end(), std::greater<int>());
    lli res = 0;
    REP(i, n) res += A[i];
    printf("%lld\n", res);
    return 0;
}


Measured memory_bytes: 1792
#include <iostream>
using namespace std;
int abs(int s){
	if(s<0) s=-s;
	return s;
}
int main(){
	int K,result;
	cin >> K;
	if(K%2==0){
		result = (K/2)*(K/2);
	}else{
		result = (K-1)/2*(K+1)/2;
	}
	cout << result << endl;
}





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

using namespace std;
using Graph = vector<vector<int>>;
using Grid= vector<vector<char>>;
using vin= vector<int>;
using ll=long long;
using vll= vector<ll>;
using vbl=vector<bool>;
using vch=vector<char>;

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define sort(x) sort(x.begin(), x.end());
#define rese(x) reverse(x.begin(), x.end());

int main() {
    int a,b;
    cin>>a>>b;
    cout<<a*b<<endl;
  

}


Measured memory_bytes: 3588
#include <stdio.h>

int main(void)
{
	char S[200001];
	char T[200001];

	int i = 0,j = 0;
	int flg = 0;
	char keep1,keep2;

	scanf("%s", S);
	scanf("%s", T);


	for (i = 0; S[i] != '\0'; i++) {
		if (S[i] != T[i]) {
			keep1 = S[i];
			keep2 = T[i];
			for (j = 0; S[j] != '\0'; j++) {
				if (keep1 == S[j]) {
					if (j < i) {
						flg = flg - (flg + 1);
						break;
					}
					S[j] = keep2;			
					flg++;
				}
				else if (keep2 == S[j]) {
					if (j < i) {
						flg = flg - (flg + 1);
						break;
					}
					S[j] = keep1;
					flg++;
				}

			}
		}
		if (flg < 0) {
			break;
		}
	
	}

if (flg < 0) {
		printf("No\n");
	}
	else {
		printf("Yes\n");
	}
	
	return 0;
}

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

public class Main {
	public static void main(String args[]) {
		FastScanner scanner = new FastScanner();
		int n=scanner.nextInt();
		int[] v=new int[n];
		int[] c=new int[n];
		for(int i=0;i<n;i++){
			v[i]=scanner.nextInt();
		}
		for(int i=0;i<n;i++){
			c[i]=scanner.nextInt();
		}
		int tmp1=0;
		int tmp2=0;
		for(int i=0;i<n;i++){
			if(v[i]>c[i]){
				tmp1+=v[i];
				tmp2+=c[i];
			}
		}
		System.out.println(tmp1-tmp2);
	}	
}

class FastScanner {
    private final InputStream in = System.in;
    private final byte[] buffer = new byte[1024];
    private int ptr = 0;
    private int buflen = 0;
    private boolean hasNextByte() {
        if (ptr < buflen) {
            return true;
        }else{
            ptr = 0;
            try {
                buflen = in.read(buffer);
            } catch (IOException e) {
                e.printStackTrace();
            }
            if (buflen <= 0) {
                return false;
            }
        }
        return true;
    }
    private int readByte() { if (hasNextByte()) return buffer[ptr++]; else return -1;}
    private static boolean isPrintableChar(int c) { return 33 <= c && c <= 126;}
    public boolean hasNext() { while(hasNextByte() && !isPrintableChar(buffer[ptr])) ptr++; return hasNextByte();}
    public String next() {
        if (!hasNext()) throw new NoSuchElementException();
        StringBuilder sb = new StringBuilder();
        int b = readByte();
        while(isPrintableChar(b)) {
            sb.appendCodePoint(b);
            b = readByte();
        }
        return sb.toString();
    }
    public long nextLong() {
        if (!hasNext()) throw new NoSuchElementException();
        long n = 0;
        boolean minus = false;
        int b = readByte();
        if (b == '-') {
            minus = true;
            b = readByte();
        }
        if (b < '0' || '9' < b) {
            throw new NumberFormatException();
        }
        while(true){
            if ('0' <= b && b <= '9') {
                n *= 10;
                n += b - '0';
            }else if(b == -1 || !isPrintableChar(b)){
                return minus ? -n : n;
            }else{
                throw new NumberFormatException();
            }
            b = readByte();
        }
    }
    public int nextInt() {
        long nl = nextLong();
        if (nl < Integer.MIN_VALUE || nl > Integer.MAX_VALUE) throw new NumberFormatException();
        return (int) nl;
    }
    public double nextDouble() { return Double.parseDouble(next());}
}


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

typedef long long ll;

int main()
{
    ll i,j;
    int n;
    cin >> n;
    vector<int> p(n);
    vector<int> q(n);
    for(i = 0;i < n;++i){
        cin >> p.at(i);
    }
    for(i = 0;i < n;++i){
        cin >> q.at(i);
    }
    vector<int> r(n);
    for(i = 0;i < n;++i){
        r.at(i) = i+1;
    }
    int a,b;
    int time = 0;
    do{
        bool flag = true;
        for(i = 0;i < n;++i){
            if(p.at(i) == r.at(i)){
                continue;
            }else{
                flag = false;
                break;
            }
        }
        if(flag){
            a = time;
            break;
        }
        ++time;
    }while(next_permutation(r.begin(), r.end()));
    for(i = 0;i < n;++i){
        r.at(i) = i+1;
    }
    time = 0;
    do{
        bool flag = true;
        for(i = 0;i < n;++i){
            if(q.at(i) == r.at(i)){
                continue;
            }else{
                flag = false;
                break;
            }
        }
        if(flag){
            b = time;
            break;
        }
        ++time;
    }while(next_permutation(r.begin(), r.end()));
    cout << abs(a-b) << endl;
    return 0;
}

Measured memory_bytes: 256
#include<cstdio>
#include<iostream>
#include<algorithm>
#include<stack>
#include<cmath>
using namespace std;
double arr[1005];
int main(){
	int n;
	int t,a;
	cin>>n;
	cin>>t>>a;
	for(int i=0;i<n;i++){
		cin>>arr[i];
		arr[i]=t-arr[i]*0.006;
		arr[i]-=a;
		arr[i]=abs(arr[i]);
	}
	stack<int>s;
	for(int i=0;i<n;i++){
		if(s.empty()||arr[s.top()]>arr[i])
			s.push(i);
	}
	printf("%d",s.top()+1);
}

Measured memory_bytes: 256
#include<cstdio>
#include<algorithm>
#define REP(i, a, b) for(int i = (a); i < (b); i++)
using namespace std;

typedef long long ll;
ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }
ll com(ll x, ll y) { return x / gcd(x, y) * y; }

int main()
{
	int n;
	ll ans = 1;
	scanf("%d", &n);
	while(n--)
	{
		ll x;
		scanf("%lld", &x);
		ans = com(x, ans);
	}
	printf("%lld\n", ans);
	return 0;
}

Measured memory_bytes: 128
#include<bits/stdc++.h>
#define ll long long
#define mp make_pair
#define pb push_back
#define F first
#define S second
#define PI 3.141592653589793238
#define mod 1000000007
#define endl '\n'
#define fastio; ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
using namespace std;
typedef vector<ll> vll;
typedef vector<int> vi;
typedef vector<bool> vb;
typedef vector<char> vc;



int main()
{
    int n,k;
    cin>>n>>k;
    vb vis(n,false);
    for(int i=1;i<=k;i++)
    {
        int d;
        cin>>d;
        while(d--)
        {
            int a;
            cin>>a;
            a--;
            vis[a]=true;
        }
    }
    int cnt=0;
    for(int i=0;i<n;i++)
        if(!vis[i]) cnt++;
    cout<<cnt<<endl;


    return 0;
}


Measured memory_bytes: 3632
#include<iostream>
#include<vector>
#include<algorithm>
#include<cmath>
#include<map>
using namespace std;
using ll = long long;

int main(){
    ll n,m,a,b,sum=0;
    cin >> n >> m;
    vector<pair<ll,ll>> p(n);
    for(ll i=0;i<n;i++){
        cin >> a >> b;
        p[i] = make_pair(a,b);
    }
    sort(p.begin(),p.end());
    ll t=0;
    for(ll i=0;i<m;i++){
        if(p[t].second==0) t++;
        p[t].second--;
        sum+=p[t].first;
    }
    cout << sum;
    return 0;
}

Measured memory_bytes: 1792
# -*- coding: utf-8 -*-
"""
https://beta.atcoder.jp/contests/abc080/tasks/abc080_d

"""
import sys
from sys import stdin
from heapq import heappop, heappush, heappushpop
input = stdin.readline


def prep_programs(programs, C):
    # 同じチャンネルで連続録画する場合はまとめる
    channels = [[] for _ in range(C+1)]
    res = []

    programs.sort()
    for s, t, c in programs:    #  チャンネルごとに録画したい番組を分ける
        channels[c].append([s, t])

    for i in range(1, C+1):      #  zipでずらして処理できるように、ダミーの番組を追加
        channels[i].append([-1, -1])

    # チャンネルごとに連続する番組があれば一つの録画枠にまとめる
    for i in range(1, C+1):
        prev_start = channels[i][0][0]
        for a, b in zip(channels[i], channels[i][1:]):
            if a[1] == b[0]:
                pass
            else:
                res.append([prev_start, a[1], i])
                prev_start = b[0]
    res.sort()
    return res                  #  まとめた録画リスト


def solve(programs, N, C):
    P = prep_programs(programs, C)

    max_used = 1                #  必要な録画機の台数
    R = []

    heappush(R, 0)
    for s, t, c in P:
        end_time = heappushpop(R, t)
        if end_time >= s:       #  番組の録画時間になった時に前の番組が終わっていない (チャンネルが違う場合は、前の録画終了と次の録画開始が同時でも2台必要)
            heappush(R, end_time)
            max_used = len(R)
    return max_used


def main(args):
    programs = []
    N, C = map(int, input().split())
    for _ in range(N):
        s, t, c = map(int, input().split())
        programs.append([s, t, c])
    ans = solve(programs, N, C)
    print(ans)


if __name__ == '__main__':
    main(sys.argv[1:])


Measured memory_bytes: 42528
class UnionFind:
    def __init__(self, n):
        # 親要素のノード番号を格納。par[x] == xの時そのノードは根
        self.par = [i for i in range(n+1)]
        # 木の高さを格納する（初期状態では0）
        self.rank = [0] * (n+1)

    # 検索
    # 根ならその番号を返す
    def find(self, x):
        if self.par[x] == x:
            return x
        else:
            # 走査していく過程で親を書き換える
            self.par[x] = self.find(self.par[x])
            return self.par[x]

    # 同じ集合に属するか判定
    def same_check(self, x, y):
        return self.find(x) == self.find(y)

    # 併合
    def union(self, x, y):
        # 根を探す
        x = self.find(x)
        y = self.find(y)
        # 木の高さを比較し、低いほうから高いほうに辺を張る
        if self.rank[x] < self.rank[y]:
            self.par[x] = y
        else:
            self.par[y] = x
            # 木の高さが同じなら片方を1増やす
            if self.rank[x] == self.rank[y]:
                self.rank[x] += 1

n,m=map(int,input().split())

g=[list(map(int,input().split())) for i in range(m)]


count=0
for i in range(m):
    uf=UnionFind(n)
    for j in range(m):
        if i == j:
            continue
        if not uf.same_check(g[j][0], g[j][1]):
            uf.union(g[j][0], g[j][1])
    
    root=uf.find(1)
    for j in range(2,n+1):
        if not root==uf.find(j):
            count+=1
            break

print(count)

Measured memory_bytes: 42604
import math
from functools import reduce

def gcd(*numbers):
    return reduce(math.gcd, numbers)

k = int(input())
sum = 0

for a in range(1, k+1):
    for b in range(1, k+1):
        for c in range(1, k+1):
            sum += gcd(a, b, c)

print(sum)


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

int main(){
  int n;
  cin >> n;
  ll ans=0;
  vector<int> a(n, 0);
  rep(i, n) cin >> a.at(i);
  rep(i, n-1){
    int now = a.at(i);
    if(now==i+1){
      a.at(i) = a.at(i+1);
      a.at(i+1)= now;
      ans++;
    }
  }
  if(a.at(n-1)==n)ans++;
  //rep(i, n) cout << a.at(i);
  cout << ans;
}

Measured memory_bytes: 3792
import sys
from pprint import pprint


class UnionFind:
    def __init__(self):
        self._parent = {}
        self._rank = {}
        self._equiv = {}
    
    def _find(self, x):
        if self._parent[x] == x:
            return self._parent[x]
        else:
            p = self._find(self._parent[x])
            self._parent[x] = p
            return p
    
    def _set_parent(self, child, parent):
        self._parent[child] = parent
        self._equiv[parent].update(self._equiv.pop(child))
    
    def _union(self, x, y):
        x = self._find(x)
        y = self._find(y)
        if x == y: return
        if self._rank[x] > self._rank[y]:
            self._set_parent(y, x)
        elif  self._rank[x] < self._rank[y]:
            self._set_parent(x, y)
        else:
            self._set_parent(x, y)
            self._rank[x] += 1
    
    def _make_set(self, x):
        self._parent[x] = x
        self._rank[x] = 0
        self._equiv[x] = {x}
    
    def unite(self, *elements):
        if not elements: return
        for x in elements:
            if x in self._parent: continue
            self._make_set(x)
        x0 = elements[0]
        for x in elements[1:]:
            self._union(x0, x)
    
    def groups(self):
        return [set(e) for e in self._equiv.values()]


def solve(ncol, nrow, rows):
    pairs = []
    # ?????????
    for x in range(ncol - 1):
        for y in range(nrow):
            pairs.append([(x, y), (x + 1, y)])

    # ?????????
    for x in range(ncol):
        for y in range(nrow - 1):
            pairs.append([(x, y), (x, y + 1)])

    # ???????????????
    for x in range(ncol - 1):
        for y in range(nrow - 1):
            pairs.append([(x, y), (x + 1, y + 1)])

    # ???????????????
    for x in range(ncol - 1):
        for y in range(1, nrow):
            pairs.append([(x, y), (x + 1, y - 1)])

    f = UnionFind()
    for x in range(ncol):
        for y in range(nrow):
            if rows[y][x]:
                f.unite((x, y))
    for (x1, y1), (x2, y2) in pairs:
        if rows[y1][x1] and rows[y2][x2]:
            f.unite((x1, y1), (x2, y2))
    return len(f.groups())


def main():
    while True:
        ncol, nrow = map(int, input().split())
        if ncol == 0 and nrow == 0:
            break
        rows = []
        for _ in range(nrow):
            row = list(map(int, input().split()))
            rows.append(row)
        # print(ncol, nrow)
        # pprint(rows)
        print(solve(ncol, nrow, rows))

main()

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

string to_string(string s) {
    return '"' + s + '"';
}

string to_string(const char* s) {
    return to_string((string) s);
}

string to_string(bool b) {
    return (b ? "true" : "false");
}

template <typename A, typename B>
string to_string(pair<A, B> p) {
    return "(" + to_string(p.first) + ", " + to_string(p.second) + ")";
}

template <typename A>
string to_string(A v) {
    bool first = true;
    string res = "{";
    for (const auto &x : v) {
        if (!first) {
            res += ", ";
        }
        first = false;
        res += to_string(x);
    }
    res += "}";
    return res;
}

void debug_out() { cerr << endl; }

template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
    cerr << " " << to_string(H);
    debug_out(T...);
}

#ifdef LOCAL
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
#else
#define debug(...) 42
#endif

void test_case() {
    int h, w, n;
    cin >> h >> w >> n;
    cout << min((n + h - 1) / h, (n + w - 1) / w) << "\n";
}

int main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    test_case();
    return 0;
}


Measured memory_bytes: 256
#include <cstdio>
 #include <cstdlib>
 #include <iostream>
 #include <fstream>
 #include <sstream>
 #include <set>
 #include <map>
 #include <vector>
 #include <list>
 #include <algorithm>
 #include <cstring>
 #include <cmath>
 #include <string>
 #include <queue>
 #include <bitset>     //UWAGA - w czasie kompilacji musi byc znany rozmiar wektora - nie mozna go zmienic
 #include <cassert>
 #include <iomanip>        //do setprecision
 #include <ctime>
 #include <complex>
 using namespace std;

 #define FOR(i,b,e) for(int i=(b);i<(e);++i)
 #define FORQ(i,b,e) for(int i=(b);i<=(e);++i)
 #define FORD(i,b,e) for(int i=(b)-1;i>=(e);--i)
 #define REP(x, n) for(int x = 0; x < (n); ++x)

 #define ST first
 #define ND second
 #define PB push_back
 #define PF push_front
 #define MP make_pair
 #define LL long long
 #define ULL unsigned LL
 #define LD long double
 #define pii pair<int,int>
 #define pll pair<LL,LL>

 const double pi = 3.141592653589793238462643383279502884197169399375105820974944592307816406286208998628034825342;
 const int mod=1000000007;

int main(){
	int n,m;
	cin>>n>>m;
	vector<int> a,b,v(n+1,0);
	vector<vector<int>> g=vector<vector<int>>(n+1,vector<int>());
	deque<int> path;
	int s=-1,t=-1;
	FOR(i,0,m){
		int aa,bb;
		cin>>aa>>bb;
		a.PB(aa);b.PB(bb);
		g[aa].PB(bb);
		g[bb].PB(aa);
		if(s==-1){
			s=aa;
			t=bb;
		}
	}
	cerr<<"test"<<endl;
	v[s]=1;v[t]=1;
	path.PF(s);
	path.PB(t);
	while(1){
		LB:
		a=a;
		for(auto x:g[s]){
			if(v[x]==0){
				s=x;
				v[x]=1;
				path.PF(x);
				goto LB;
			}
		}
		for(auto x:g[t]){
			if(v[x]==0){
				t=x;
				v[x]=1;
				path.PB(x);
				goto LB;
			}
		}
		break;
	}
	cout<<path.size()<<endl;
	while(path.size()>1){
		cout<<path.front()<<" ";
		path.pop_front();
	}
	cout<<path.front()<<endl;
	return 0;
}


Measured memory_bytes: 7920
#include <algorithm>
#include <array>
#include <bitset>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <iostream>
#include <iterator>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <tuple>
#include <utility>
#include <vector>

#define rep(i, n) for (int i = 0; i < n; i++)
#define repi(i, n, iv) for (int i = iv; i < n; i++)
#define all(v) v.begin(), v.end()

using namespace std;
typedef long long ll;

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

    int x1, x2, x3, x4, x5;
    cin >> x1 >> x2 >> x3 >> x4 >> x5;
    if (x1 == 0)
    {
        cout << 1 << endl;
    }
    else if (x2 == 0)
    {

        cout << 2 << endl;
    }
    else if (x3 == 0)
    {

        cout << 3 << endl;
    }
    else if (x4 == 0)
    {

        cout << 4 << endl;
    }
    else
    {

        cout << 5 << endl;
    }
}


Measured memory_bytes: 3192
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <cstring>
#include <vector>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <deque>
#define debug(x)  cerr << #x << " = " << x << endl
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair <ll, ll> pll;
typedef pair <int, int> pii;

const int maxN = 1e5 + 5;
const ll INF = 1e18;
const ll MOD = 1e9 + 7;

ll gcd(ll a, ll b){return !b ? a : gcd(b, a % b);}
ll modP(ll a, ll b) {return (!b ? 1 : (modP(a, b / 2) * modP(a, b / 2) * (b % 2 ? a : 1)) % MOD);}

int main(){
	ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
	int a[5], mn = 1000;
	for (int i = 0; i < 5; i++){
		cin >> a[i];
	}
	sort(a, a + 5);
	for (int i = 0; i < 120; i++){
		int sum = 0;
		for (int j = 0; j < 5; j++){
			sum = (sum / 10 + (sum % 10 > 0)) * 10;
			sum += a[j];
		}
		mn = min(mn, sum);
		next_permutation(a, a + 5);
	}
	cout << mn << endl;
	return 0;
}



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

using namespace std;

using ll = long long;
using ull = unsigned long long;
using D = double;
using ld = long double;
using ii = pair<int, int>;
using vi = vector <int>;
using vii = vector <ii>;

#define pb push_back
#define re return 
#define mp make_pair
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define fi first
#define se second
#define re return
#define sz(x) ((int) x.size())
#define rep(i, n) for (int i = 0; i < (n); i++)
#define rei(i, n) for (int i = 0; i < (n); i++) 

const int inf = 2e9;

int main() {
 	ios::sync_with_stdio(0);
 	cin.tie(NULL);
 	cout.tie(NULL);
	int n, m, k;
	cin >> n >> m >> k;
	map <int, int> an;
	for (int i = 0; i < k; i++) {
	 	int x;
	 	cin >> x;
	 	--x;
	 	an[x]++;
	}
	for (int i = 0; i < n; i++) {
	 	if (m - k + an[i] <= 0) {
	 	 	cout << "No" << '\n';
	 	}
	 	else {
	 	 	cout << "Yes" << '\n';
	 	}
	}
 	re 0;
}


Measured memory_bytes: 5376
# atcoder : python3 (3.4.3)
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10**6)
mod = 10**9+7

# main
from itertools import accumulate
N,W = map(int,input().split())
V = [[] for _ in range(4)]
w0 = None
for i in range(N):
    w,v = map(int,input().split())
    if i==0:
        w0 = w
        V[0].append(v)
    else:
        V[w-w0].append(v)

for i in range(4):
    V[i].sort(reverse=True)

S = [[] for _ in range(4)]
for i in range(4):
    S[i] = [0] + list(accumulate(V[i]))

ans = 0
for i0 in range(len(S[0])):
    for i1 in range(len(S[1])):
        for i2 in range(len(S[2])):
            for i3 in range(len(S[3])):
                if w0*i0 + (w0+1)*i1 + (w0+2)*i2 + (w0+3)*i3 <= W:
                    ans = max(ans, S[0][i0] + S[1][i1] + S[2][i2] + S[3][i3])

print(ans)

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

int main()
{
  const int mod = 1e9 + 7;
  int h, w;
  cin >> h >> w;
  vector<string> s(h);
  for (int i = 0; i < h; ++i)
    cin >> s[i];
  vector<vector<int>> dp(h, vector<int>(w));
  dp[h-1][w-1] = 1;
  for (int i = w-2; i >= 0; --i) {
    if (s[h-1][i] == '#')
      dp[h-1][i] = 0;
    else
      dp[h-1][i] = dp[h-1][i+1];
  }

  for (int i = h - 2; i >= 0; --i) {
    if (s[i][w-1] == '#')
      dp[i][w-1] = 0;
    else
      dp[i][w-1] = dp[i + 1][w-1];
  }

  for (int i = h - 2; i >= 0; --i)
  {
    for (int j = w - 2; j >= 0; --j)
    {
     if (s[i][j] == '#')
      dp[i][j] = 0;
     else
      dp[i][j] = (dp[i+1][j] + dp[i][j+1]) % mod;
    }
  }

  cout << dp[0][0] << '\n';

  return 0;
}


Measured memory_bytes: 5248
#include "bits/stdc++.h"
using namespace std;
using ll = long long;

template <typename TYPE>
void print_vec(const vector<TYPE>& v, int num=0){
  if(num == 0) num = (int)v.size();
	for(int i=0; i<num; i++){
		cout << v[i]; if(i!=num-1) cout << " ";
	}
	cout << endl;
}

template <typename TYPE>
void print_vec2(const vector<vector<TYPE>>& v){
  cout << endl; cout << "       ";
  for(int i=0; i<v[0].size(); i++) cout << i << "   "; 
  cout << endl;
	for(int i=0; i<v.size(); i++){
		cout << "i=" << i << ":   ";
		for(int j=0; j<v[i].size(); j++){
			if(v[i][j] == 0) cout << "\x1B[0m" << v[i][j] << "   ";
      else cout << "\x1B[31m" << v[i][j] << "   ";//https://stackoverrun.com/ja/q/12618775
		}
		cout << "\x1B[0m" << endl;
	}
}

template <typename T>
void SWAP(T &a, T &b){
  a = a^b;// a^b 
  b = a^b;// (a^b)^b
  a = a^b;// (a^b)^(a^b^b)
}

template <typename T>
void insertionSort(vector<T> &a, T N){
  //http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=ALDS1_1_A&lang=ja
  for(int i=0; i<N-1; i++){
    int j = i;
    while(j>=0 && a[j] > a[j+1]){
      SWAP(a[j], a[j+1]);
      j--;
    }
    print_vec(a);
  }
}
template <typename T>
void bubbleSort(vector<T> &a, int n){
  //http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=ALDS1_2_A&lang=ja
  ll num = 0;
  for(int i=0; i<n; i++){
    for(int j=n-1; j>i; j--){
      if(a[j-1] > a[j]){
        SWAP(a[j-1], a[j]);
        num++;
      }
    }
  }
  print_vec(a);
  cout << num << endl;
  return;
}
int main(){
  int n;
  cin >> n;
  vector<int> a(n);
  for(int i=0; i<n; i++) cin >> a[i];
  bubbleSort(a, n);

  return 0;
}




Measured memory_bytes: 3112
<?php
$Rectangle=trim(fgets(STDIN));
//????????§??°???????????????
$fget = explode(" ", $Rectangle);
//??°?????????????????£????????´???????¨???????????????????
if(1<=$fget[0] && $fget[0]<=10000 && 1<=$fget[1] && $fget[1]<=10000 && 1<=$fget[2] && $fget[2]<=10000){
    //??????????????????
    sort($fget);
    //????????????
    echo $fget[0]." ".$fget[1]." ".$fget[2];
}
?>

Measured memory_bytes: 15388
#include <bits/stdc++.h>
#define rep(i, a, n) for (int i = (int)(a); i <= (int)(n); ++i)
#define rrep(i, a, n) for (int i = (int)(a); i >= (int)(n); --i)
#define debug(x) cerr << #x << " = " << x << "\n"
#define debugv(x) \
  rep(f, 0, (x.size() - 1)) cerr << x[f] << (f == (x.size() - 1) ? "\n" : " ")
#define debug2(x, y)                       \
  cerr << "(" << #x << "," << #y << ") = " \
       << "(" << x << "," << y << ")\n"
#define all(x) x.begin(), x.end()
#define each(a, x) for (auto& a : (x))
#define chmin(x, y) x = min(x, y)
#define chmax(x, y) x = max(x, y)
#define int long long
using namespace std;
using pii = pair<int, int>;
using vi = vector<int>;
const int MX = 1e5 + 5, INF = 5LL << 57, MOD = 1e9 + 7;

int N, M;
string S;
vi va, vb;

void input() {
  ;
  ;
  cin >> N >> M;
  va.resize(N);
  rep(i, 0, N - 1) { cin >> va[i]; }
}
void solve() {
  int K=M;
  vector<double> vc;
  vc.resize(N);
  rep(i,0,N-1){
    vc[i] = (va[i]+1.0)/2.0;
  }
  vector<double> vd;
  vd.resize(N+1);
  vd[0] = 0.0;
  rep(i,0,N-1){
    vd[i+1] = vd[i] + vc[i];
  }

double ans = -1;
  rep(i,0,N-1){
    if (i+K <= N)
    chmax(ans, vd[i+K] - vd[i]);
  }
  printf("%10lf\n",ans);


}
signed main() {
  input();
  solve();
  return 0;
}

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

int sub(char a[1000], char b[1000]){
  int lena = strlen(a);
  int lenb = strlen(b);
  int x = 0;
  for(int i = 0; i <= lena - lenb; i++){
    int y = 0;
    for(int j = 0; j < lenb; j++){
      if(a[i + j] == b[j]) y++;
    }
    if(x < y) x = y;
  }
  return(lenb - x);
}

int main(void){
  char s[1000], t[1000];
  scanf("%s\n%s", s, t);
  printf("%d\n", sub(s, t));
}


Measured memory_bytes: 1696
#include<stdio.h>
int main(void)
{
	int d;
	int hozon=0;
	int i=0;
	int kioku=0;
	while(scanf("%d",&d)!=EOF)
	{
		hozon=0;
		kioku=0;
		for (i=1;i<=600;i++)
		{
			if (i%d==0)
			{
				hozon+=d*kioku;
				kioku=i*i;
			}
		}
		printf("%d\n",hozon);
	}
	return 0;
}

Measured memory_bytes: 596
use std::io::{stdout, Write, BufWriter};
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
    ($($r:tt)*) => {
        let mut s = {
            use std::io::Read;
            let mut s = String::new();
            std::io::stdin().read_to_string(&mut s).unwrap();
            s
        };
        let mut iter = s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
}

macro_rules! input_inner {
    ($iter:expr) => {};
    ($iter:expr, ) => {};

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

macro_rules! read_value {
    ($iter:expr, ( $($t:tt),* )) => {
        ( $(read_value!($iter, $t)),* )
    };

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

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

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

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

fn main() {
    input!{
        n: usize,
    }

    let out = stdout();
    let mut out = BufWriter::new(out.lock());

    match n {
        25 => writeln!(out, "Christmas").unwrap(),
        24 => writeln!(out, "Christmas Eve").unwrap(),
        23 => writeln!(out, "Christmas Eve Eve").unwrap(),
        22 => writeln!(out, "Christmas Eve Eve Eve").unwrap(),
        _  => writeln!(out, "Christmas").unwrap(),
    }
}

Measured memory_bytes: 4352
import java.util.Scanner;
public class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    int [] a = new int [100];
    int n = sc.nextInt();
    for(int i=0;i<n;i++){
      int A = sc.nextInt();
      a[i] = A;
    }
    for(int j=n-1;j>0;j--){
      System.out.printf("%d ",a[j]);
    }
    System.out.printf("%d\n",a[0]);
  }
}



Measured memory_bytes: 26644
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
#define all(x) x.begin(),x.end()
#define endl '\n'
#define pb push_back
#define ff first
#define ss second
#define PI 3.1415926535897932384626
#define mod 1000000007
#define modd 998244353

void io() {
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
	#endif
}

int main() {
	io();
	
	int h,w,k;
	cin>>h>>w>>k;
	int n=0;
	vector<string> row(h);
	bool vis[h][w];
	for(int i=0;i<h;i++) {
		cin>>row[i];
		for(int j=0;j<w;j++) {
			n+=(row[i][j]=='#');
		}
	}
	int ans=0;
	for(int l=0;l<(1<<h);l++) {
		for(int r=0;r<(1<<w);r++) {
			int cnt=0;
			memset(vis,false,sizeof(vis));
			for(int i=0;i<h;i++) {
				for(int j=0;j<w;j++) {
					if(((l>>i & 1)||(r>>j & 1)) && !vis[i][j]) {
						cnt+=(row[i][j]=='#');
						vis[i][j]=true;
					}
				}
			}
			if(cnt==n-k) ans++;
		}
	}
	cout<<ans;
	return 0;
}


Measured memory_bytes: 3604
#include <bits/stdc++.h>
#define rep(i, n) for(int i = 0;i < n;i++)
#define rev(i, n) for(int i = n;i >= 0;i--)
#define repeat(i, m, n) for(int i = m;i < n;i++)
#define repeatrev(i, m, n) for(int i = m;i >= n;i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define ll long long
#define pb(a) push_back(a)
#define INF 999999999
#define itn int

using namespace std;
typedef pair<int, int> P;
typedef pair<ll, ll> LP;
typedef pair<int, P> PP;
typedef pair<ll, LP> LPP;
typedef priority_queue<int> Pr;

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

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    char q;
    cin >> q;
    if(q == 'A') cout << 'T' << endl;
    else if (q == 'T') cout << 'A' << endl;
    else if (q == 'C') cout << 'G' << endl;
    else cout << 'C' << endl;

}

Measured memory_bytes: 256
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <iostream>
#include <algorithm>
#include <utility>
#include <functional>
#include <string>
#include <vector>
#include <deque>
#include <queue>
#include <stack>
#include <list>
#include <set>
#include <map>
#include <unordered_map>
#include <iomanip>
#include <numeric>
#include <complex>

using namespace std;
using ll = long long;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()
const int INF = (1<<30);
const ll INFL = (1LL<<62);
const ll MOD = 1000000007;
template<class T> bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> T gcd(T a, T b) { return b ? gcd(b, a % b) : a; }
template<class T> T lcm(T a, T b) { return a / gcd(a, b) * b; }
template<class T> ll mod_pow(ll a, ll n, T mod) { mod=(ll)mod; ll res=1, p=a%mod; while(n){ if(n&1) res=res*p%mod; p=p*p%mod; n>>=1; } return res; }


int main() {
    string s;
    cin >> s;
    string ans;
    int N = s.size();
    rep(i, N){
        int c = (26 + s[i]-'A'-3)%26;
        cout << (char)('A' + c);
    }
    cout << "\n";

    return 0;
}


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

int A , B , M , arr[2][100003];
int main(){
	cin >> A >> B >> M;
	for(int i = 1 ; i <= A ; ++i) cin >> arr[0][i];
	for(int j = 1 ; j <= B ; ++j) cin >> arr[1][j];
	int mn = 2e9;
	for(int k = 1 ; k <= M ; ++k){
		int p , q , r; cin >> p >> q >> r; mn = min(mn , arr[0][p] + arr[1][q] - r);
	}
	sort(arr[0] + 1 , arr[0] + A + 1); sort(arr[1] + 1 , arr[1] + B + 1);
	cout << min(mn , arr[0][1] + arr[1][1]);
	return 0;
}


Measured memory_bytes: 1024
#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;

int main()
{
    int n, m, num;
    vector<int> v;
    double total;

    cin >> n >> m;
    for (int i = 0; i < n; i++) {
        cin >> num;
        v.push_back(num);
        total += num;
    }

    sort(v.rbegin(), v.rend());

    for (int i = 0; i < m; i++) {
        if (v[i] < (total / (4 * m))) {
            cout << "No" << endl;
            return 0;
        }
    }
    cout << "Yes" << endl;
}

Measured memory_bytes: 256
def main():
    
    n = int(input())
    movements = [list(map(int, input().split())) for i in range(n)]
    houses = [[[0 for room in range(10)] for floor in range(3)] for building in range(4)]
    
    for move in movements:
        [b, f, r, v] = move
        houses[b-1][f-1][r-1] += v
    
    for index, building in enumerate(houses):
        for floor in building:
            print(' ' + ' '.join(map(str,floor)))
        if index != 3: print('#'*20)


main()

Measured memory_bytes: 7800
import java.io.{BufferedReader, InputStreamReader}

object Main extends App {

  val in = new BufferedReader(new InputStreamReader(System.in))
  val Array(a, b, c, d, e, f) = in.readLine.split(" ").map(_.toInt)
  // 入れる水の量 100a 100b
  // 入れる砂糖の量 c d
  // 100gあたりとける量 e
  // ビーカーに入る量 f
  // 濃度 0% の砂糖水 : water > 0 , sugar >= 0
  val water = {
    for {
      i <- 0 to f/(a*100)
      j <- 0 to f/(b*100)
      w = 100 * a * i + 100 * b * j
      if(0 < w && w <= f)
    } yield w
  }.distinct.toArray
  val sugar = {
    for {
      i <- 0 to (f-100)/c
      j <- 0 to (f-100)/d
      w = c * i + d * j
      if(0 <= w && w <= f)
    } yield w
  }.distinct.toArray

  // println(water.length + " " + sugar.length)

  val ans = {
    var max = (-1d, 0, 0)
    for {
      w <- water
      wd = w.toDouble/100d
      s <- sugar
      weight = w + s
      concent = s.toDouble / wd
      if w + s <= f && concent <= e
    } {
      if(concent > max._1) {
        // println(weight + " " + concent)
        max = (concent, weight, s)
      }
    }
    max
  }
  
  println(ans._2 + " " + ans._3)
}

Measured memory_bytes: 43628
#include <iostream>
#include <cstdio>
#include <string>
#include <algorithm>
#include <utility>
#include <cmath>
#include <vector>
#include <queue>
#include <set>
#include <map>
#define rep(i, n) for(int i = 0; i < n; i++)
using namespace std;
typedef long long ll;
const ll mod = 1000000007;

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

    int v[n], w[n];
    rep(i, n) {
        cin >> v[i] >> w[i];
    }

    int dp[n+1][m+1];  // dp[i+1][j] : i番目までの品物で重さがj以下のときの価値の総和の最大値(iは0-index)

    rep(i, n+1) {
        rep(j, m+1) {
            dp[i][j] = 0;
        }
    }

    rep(i, n) {
        rep(j, m+1) {
            if(j >= w[i]) {
                dp[i+1][j] = max(dp[i][j], dp[i][j-w[i]] + v[i]);
            }
            else {
                dp[i+1][j] = dp[i][j];
            }
        }
    }

    cout << dp[n][m] << endl;
    return 0;
}


Measured memory_bytes: 7040
#include<iostream>
#include<algorithm>
using namespace std;
#define modulus 1000000007
int main(){
	int N=0;
	cin>>N;
	int*data=new int[N];
	for(int i=0;i<N;i++){
		data[i]=0;
	}
	for(int i=0;i<N;i++){
		int a=0;
		cin>>a;
		data[a]++;
	}
	int count=0;
	for(int i=1;i<N;i++){
		if(data[i]>0){
			if((data[i]%2)!=0){
				cout<<0<<endl;
				return 0;
			}else{
				count++;
			}
		}
	}
	long long int ans=1;
	for(int i=0;i<count;i++){
		ans*=2;
		ans%=modulus;
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 640
primes = {}
N = int(input())
A = [N]
for val in A:
    p = 2
    while val >= p * p:
        if val % p == 0:
            # 割り切れるならそこから話が始まる
            cnt = 0
            while val % p == 0:
                cnt += 1
                val //= p
            if p not in primes:
                primes[p] = cnt
            else:
                primes[p] = max(cnt, primes[p])
        p += 1
    if val != 1:
        if val not in primes:
            primes[val] = 1

ans = 0
for k, v in primes.items():
    now = 1
    while v > 0:
        if v >= now:
            v -= now
            now += 1
            ans += 1
        else:
            v = 0
print(ans)


Measured memory_bytes: 9224
#include<cstdio>
#include<iostream>
#include<cstring>
#include<algorithm>
#include<vector>
#include<set>
typedef long long ll;
typedef unsigned un;
typedef std::string str;
typedef std::pair<ll,ll> pll;
ll read(){ll x=0,f=1;char c=getchar();while(c<'0'||c>'9'){if(c=='-')f=-1;c=getchar();}while(c>='0'&&c<='9'){x=x*10+c-'0';c=getchar();}return f*x;}
ll max(ll a,ll b){return a>b?a:b;}
ll min(ll a,ll b){return a<b?a:b;}
void umax(ll& a,ll t){if(t>a)a=t;}
void umin(ll& a,ll t){if(t<a)a=t;}
const ll yg=998244353;
ll Qpow(ll a,ll p=yg-2)
{
	if(p<0)return 0;
	ll res=1;
	while(p)
	{
		if(p&1)res=res*a%yg;
		a=a*a%yg,p>>=1;
	}
	return res;
}
#define MAXN 200011
std::set<ll>a[MAXN],b[MAXN];
void add(ll& x,ll y){x=(x+y)%yg;}
ll fac[MAXN],inv[MAXN];
ll C(ll n,ll m){return n<m?0:fac[n]*inv[m]%yg*inv[n-m]%yg;}
int main()
{
	ll n=read();
	if(n==1)return puts("0"),0;
	fac[0]=1,inv[0]=1;
	for(ll i=1;i<=n;++i)fac[i]=fac[i-1]*i%yg,inv[i]=Qpow(fac[i]);
	for(ll i=1;i<n;++i){ll u=read(),v=read();a[u].insert(v),a[v].insert(u);}
	for(ll i=1;i<n;++i){ll u=read(),v=read();b[u].insert(v),b[v].insert(u);}
	ll ans=0;//(V1-E1)*(V2-E2)
	for(ll i=1;i<=n;++i)
		add(ans,C(n,i)*i%yg*(n-i)),add(ans,2*(yg-(C(n-2,i)*i%yg*(n-1)%yg)));
	ll ctrb=(n<4?0:Qpow(2,n-4));
	for(ll u=1;u<=n;++u)
		for(auto v:a[u])
		{
			if(u>v)continue;
			add(ans,ctrb*(n-1-b[u].size()-b[v].size()+b[u].count(v))%yg);
		}
	for(ll i=1;i<=n;++i)ans=ans*inv[2]%yg;
	printf("%lld\n",ans);
	return 0;
}


Measured memory_bytes: 62572
#include <bits/stdc++.h>
inline long long read();
using namespace std;
int ans[6];
long long out;
int main()
{
	int n=read();string s;
	for(int i=1;i<=n;i++)
	{
		cin>>s;
		if(s[0]=='M')ans[1]++;
		if(s[0]=='A')ans[2]++;
		if(s[0]=='R')ans[3]++;
		if(s[0]=='C')ans[4]++;
		if(s[0]=='H')ans[5]++;
	}
	for(int i=1;i<4;i++)
	{
		for(int j=i+1;j<5;j++)
		{
			for(int q=j+1;q<=5;q++)
			{
				out+=(long long)ans[i]*ans[j]*ans[q];
			}
		}
	}
	cout<<out<<endl;
}
inline long long read()
{
    register long long x=0,k=1;
    char c;
    c=getchar();
    while(c<'0'||c>'9'){if(c=='-')k=-1;c=getchar();}
    while(c>='0'&&c<='9')x=x*10+c-'0',c=getchar();
    return x*k;
}


Measured memory_bytes: 256
#include <stdio.h>
#include <iostream>
#include <algorithm>
#include <vector>
#include <map>
#include <set>

using namespace std;

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

    long a[n], b[n], c[n];
    for (int i = 0; i < n; i++) cin >> a[i];
    for (int i = 0; i < n; i++) cin >> b[i];
    for (int i = 0; i < n; i++) cin >> c[i];

    sort(a, (a + n));
    sort(b, (b + n));
    sort(c, (c + n));

    long ans = 0;
    for(int i=0; i<n; i++){
        long cntA = (lower_bound(a, (a + n), b[i]) - a);
        long cntC = n - (upper_bound(c, (c + n), b[i]) - c);
        ans += cntA * cntC;
    }

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


Measured memory_bytes: 2560