akhauriyash/Code-Regression huggingface dataset:
#include<stdio.h>
#include<math.h>
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<complex>

#define rep(i,n) for(int i=0; i<n; i++)
#define rep1(i,n) for(int i = 1; i<n+1; i++)
typedef long long ll;

using namespace std;
const int V = 100005;
int INF = 1000000000;

int x,y;
int n;
int a[1000];
string bcards[36];
string scards[36];


int main(){
  cin >> n;
  rep(i,n){
    cin >> scards[i];
    bcards[i] = scards[i];
  }


  //bubble sort
  rep(i,n){
    for(int j = 0; j < n-1; j++){
      if (bcards[j][1] > bcards[j+1][1]){
        string tmp;
        tmp = bcards[j];
        bcards[j] = bcards[j+1];
        bcards[j+1] = tmp;
      }
    }
  }

  //selection sort
  rep(i,n){
    int m = 100;
    int pos = 0;
    string mstr;
    for(int j = i; j < n; j++) {
      if (m > int(scards[j][1])){
        pos = j;
        m = int(scards[j][1]);
        mstr = scards[j];
      }
    }
    scards[pos] = scards[i];
    scards[i] = mstr;
  }


  rep(i,n){
    cout << bcards[i];
    if (i == n-1) break;
    cout << ' ';
  }
  cout << endl;
  cout << "Stable" << endl;

  rep(i,n){
    cout << scards[i];
    if (i == n-1) break;
    cout << ' ';
  }
  cout << endl;
  rep(i,n){
    if (scards[i] != bcards[i]){
      cout << "Not stable" << endl;
      return 0;
    }
  }
  cout << "Stable" << endl;

  return 0;

}



Measured memory_bytes: 3216
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int X = scanner.nextInt();
        int Y = scanner.nextInt();

        String ans = "No";

        for (int a = 0; a < X+1; a++) {
            int b = X - a;
            if (2*a + 4*b == Y) {
                ans = "Yes";
            }
        }

        System.out.println(ans);
    }
}


Measured memory_bytes: 27016
def inpl(): return list(map(int, input().split()))

W, H, N = inpl()
l, r, d, u = 0, W, 0, H

for _ in range(N):
    x, y, a = inpl()
    if a == 1:
        l = max(l, x)
    elif a == 2:
        r = min(r, x)
    elif a == 3:
        d = max(d, y)
    else:
        assert a == 4
        u = min(u, y)
print(max((r-l), 0)*max((u-d), 0))

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
int main(){
  int N,S,a,dp[3002][3002],ans=0,MOD=998244353;
  cin>>N>>S;
  dp[0][0]=1;
  for(int i=1;i<=N;i++){
    cin>>a;
    for(int j=0;j<=S;j++){
      dp[i][j]=dp[i-1][j];
      if(j>=a)dp[i][j]+=dp[i-1][j-a];
      dp[i][j]%=MOD;
    }
    dp[i][0]++;
    ans+=dp[i][S];
    ans%=MOD;
  }
  cout<<ans<<endl;
}


Measured memory_bytes: 38764
import java.util.Scanner;
import java.util.HashSet;
public class Main{
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		int n=sc.nextInt();
		int m=sc.nextInt();
		long mod=1000000007;
		HashSet<Integer> a=new HashSet<>();
		HashSet<Integer> b=new HashSet<>();
		for(int i=0; i<n; i++){
			a.add(sc.nextInt());
		}
		for(int i=0; i<m; i++){
			b.add(sc.nextInt());
		}
		long ans=1;
		int row=0;
		int col=0;
		for(int i=n*m; i>=1; i--){
			if(a.contains(i) && b.contains(i)){
				row++;
				col++;
			}else if(a.contains(i)){
				ans*=col;
				row++;
			}else if(b.contains(i)){
				ans*=row;
				col++;
			}else{
				ans*=row*col-n*m+i;
			}
			ans%=mod;
		}
		System.out.println(ans);
	}
}


Measured memory_bytes: 43432
import java.io.PrintWriter;
import java.util.*;

public class Main {

    static String br = System.getProperty("line.separator");
    static Scanner sc  = new Scanner(System.in);

    public static void main(String[] args){
        int N = nextInt();

        int a[] = new int[N];
        for(int i=0; i<N; i++){
            a[i] = sc.nextInt();
        }

        int count = 0;
        for(int i=0; i<N-1; i++){
            int now = a[i];
            int next = a[i+1];

            if(now == next){
                a[i+1] = -1;
                count++;
            }
        }

        println(count);

    }

    //最大公約数gcd
    static long gcd (long a, long b) {
        long temp;
        while((temp = a%b)!=0) {
            a = b;
            b = temp;
        }
        return b;
    }
    //最小公倍数lcm
    static long lcm (long a, long b) {
        long temp;
        long c = a;
        c *= b;
        while((temp = a%b)!=0) {
            a = b;
            b = temp;
        }
        return (c/b);
    }
    static int nextInt(){
        return Integer.parseInt(next());
    }
    static Long nextLong(){
        return Long.parseLong(next());
    }
    static String next(){
        return sc.next();
    }
    static void println(Object o){
        PrintWriter out = new PrintWriter(System.out);
        out.println(o);
        out.flush();
    }
   static void print(Object o){
       PrintWriter out = new PrintWriter(System.out);
       out.print(o);
       out.flush();
    }
}


Measured memory_bytes: 21716
#include <bits/stdc++.h>
using namespace  std;
int main()
{
    int n;
    cin>>n;
    map<string , double > mp;
    for (int i=0 ; i<n ; i++){
        double x; string p;
        cin>>x>>p;
        mp[p]+=x;
    }

    double ans=0.00;
    for (auto it = mp.begin() ; it!=mp.end()  ; it++){
        if(it->first=="BTC"){
            ans += (it->second*(380000*1.0));
        }
        else ans+=it->second;
    }
    cout<<fixed << setprecision(10)<<ans<<endl;
    return 0;
}


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

const int INF = (1LL<<31)-1;

class RMQ{
private:
    int N;
    vector<int> data;
    
    int find(int a, int b, int k, int l, int r){
        if(r <= a || b <= l)
            return INF;
        if(a <= l && r <= b)
            return data[k];
        int x1 = find(a, b, 2*k+1, l, (l+r)/2);
        int x2 = find(a, b, 2*k+2, (l+r)/2, r);
        return min(x1, x2);
    }

public:
    RMQ(int N_){
        N = 1;
        while(N < N_)
            N <<= 1;
        data.assign(2*N-1, INF);
    }
    
    void update(int x, int a){
        x += N-1;
        data[x] = a;
        while(x){
            x = (x-1)/2;
            data[x] = min(data[2*x+1], data[2*x+2]);
        }
    }
    int find(int a, int b){
        return find(a, b, 0, 0, N);
    }
};

int main(){
    int N, Q;
    cin >> N >> Q;
    
    RMQ rmq(N);
    
    for(int i=0; i<Q; i++){
        int com, x, y;
        cin >> com >> x >> y;
        if(com == 0){
            rmq.update(x, y);
        }
        if(com == 1){
            cout << rmq.find(x, y+1) << endl;
        }
    }
    
    return 0;
}

Measured memory_bytes: 3784
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cmath>
#include<math.h>
#include<string>
#include<string.h>
#include<stack>
#include<queue>
#include<vector>
#include<utility>
#include<set>
#include<map>
#include<stdlib.h>
#include<iomanip>

using namespace std;

#define ll long long
#define ld long double
#define EPS 0.0000000001
#define INF 1e9
#define rep(i,n) for(i=0;i<n;i++)
#define loop(i,a,n) for(i=a;i<n;i++)
#define all(in) in.begin(),in.end()
#define shosu(x) fixed<<setprecision(x)

typedef vector<int> vi;
typedef pair<int,int> pii;

int main(void) {
  int i,j;
  int n;
  while(1){
    cin>>n;
    if(n==0)break;
    vi v(n);
    rep(i,n)
      cin>>v[i];
    int ans=0;
    rep(i,n)rep(j,n-i-1)
      if(v[j]>v[j+1]){
        ans++;
        swap(v[j],v[j+1]);
      }
    cout<<ans<<endl;

  }
}

Measured memory_bytes: 3064
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
int main()
{
	int n;
	scanf("%d",&n);
	int a[200];
	int i;
	for(i=0;i<n;i++)
	scanf("%d",&a[i]);
	int k=0;
	for(i=0;i<n;i++)
	if(a[i]%2==0)
	{
		if(a[i]%3!=0&&a[i]%5!=0)
		k=1;
	}
	if(k==0)
	printf("APPROVED");
	else
	printf("DENIED");
	return 0;
}


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

#define REP(i,s,n) for(int i=s;i<n;++i)
#define rep(i,n) REP(i,0,n)
#define EPS (1e-8)
#define equals(a,b) (fabs((a)-(b))<EPS)
#define ALL(x) x.begin(),x.end()

using namespace std;

typedef long long ll;

bool LT(double a,double b) { return !equals(a,b) && a < b; }
bool LTE(double a,double b) { return equals(a,b) || a < b; }

int H,W;
vector<ll> A, B;

struct Data {
  bool type;
  ll len;
  bool operator < ( const Data &data ) const {
    if( len != data.len ) return len < data.len;
    return type < data.type;
  }
};

void compute() {
  vector<Data> vec;
  rep(i,H) vec.push_back((Data){false,A[i]});
  rep(i,W) vec.push_back((Data){true,B[i]});
  sort(ALL(vec));
  ll ans = 0;
  rep(i,(int)vec.size()) {
    if( vec[i].type == false ) { // H
      ans += ( vec[i].len * W );
      --H;
    } else { // W
      ans += ( vec[i].len * H );
      --W;
    }
  }
  cout << ans << endl;
}

int main() {
  cin >> H >> W;
  A.resize(H), B.resize(W);
  rep(i,H) cin >> A[i];
  rep(i,W) cin >> B[i];
  compute();
  return 0;
}



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

using namespace std;

#define INF 100000000
#define YJ 1145141919
#define INF_INT_MAX 2147483647
#define INF_LL 9223372036854775
#define INF_LL_MAX 9223372036854775807
#define EPS 1e-10
#define MOD 1000000007
#define MOD9 998244353
#define Pi acos(-1)
#define LL long long
#define ULL unsigned long long
#define LD long double

#define int long long

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) FOR(i,0,n)
#define ALL(a)  begin((a)), end((a))
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())

const int MAX_N = 305;
int N;
int A[4];

double dp[MAX_N][MAX_N][MAX_N];

double solve(int i, int j, int k)
{
  if(dp[i][j][k] >= 0) {
    return dp[i][j][k];
  }

  if(i+j+k==0){
    return 0.0;
  }

  double ret = 0;
  if(i>0) ret += solve(i-1,j,k)*i;
  if(j>0) ret += solve(i+1,j-1,k)*j;
  if(k>0) ret += solve(i,j+1,k-1)*k;

  ret += N;
  ret *= 1.0/(i+j+k);


  return dp[i][j][k] = ret;
}

signed main()
{
  cin >> N;
  REP(n,N) {
    int a; cin >> a;
    A[a]++;
  }

  memset(dp,-1,sizeof(dp));

  printf("%.15f\n", solve(A[1], A[2], A[3]));

  return 0;
}

Measured memory_bytes: 222080
s = input()
t = input()

maxcount = 0
for i in range(len(s) - len(t) + 1):
  ss = s[i:len(t) + i]
  count = 0
  for j in range(len(t)):
    if t[j] == ss[j]:
      count += 1
  
  if count > maxcount:
    maxcount = count

print(len(t) - maxcount)
  

Measured memory_bytes: 9092
import java.io.*;
import java.nio.CharBuffer;
import java.util.NoSuchElementException;

public class Main {

    public static void main(String[] args) {
        SimpleScanner scanner = new SimpleScanner(System.in);
        PrintWriter writer = new PrintWriter(System.out);

        char[] s = scanner.next().toCharArray();
        int n = s.length;
        int[][] f = new int[n][2];
        f[0][0] = 1;
        f[0][1] = -1;
        if (n > 1) {
            f[1][0] = s[0] == s[1] ? -1 : 2;
            f[1][1] = 1;
        }
        for (int i = 2; i < n; ++i) {

            f[i][0] = f[i - 1][1] + 1;
            if (s[i] != s[i - 1])
                f[i][0] = Math.max(f[i - 1][0] + 1, f[i][0]);

            f[i][1] = f[i - 2][0] + 1;
            if (i >= 3 && s[i - 3] != s[i - 1] || s[i - 2] != s[i])
                f[i][1] = Math.max(f[i - 2][1], f[i][1]);
        }
        writer.println(Math.max(f[n - 1][0], f[n - 1][1]));

        writer.close();
    }

    private static class SimpleScanner {

        private static final int BUFFER_SIZE = 10240;

        private Readable in;
        private CharBuffer buffer;
        private boolean eof;

        SimpleScanner(InputStream in) {
            this.in = new BufferedReader(new InputStreamReader(in));
            buffer = CharBuffer.allocate(BUFFER_SIZE);
            buffer.limit(0);
            eof = false;
        }


        private char read() {
            if (!buffer.hasRemaining()) {
                buffer.clear();
                int n;
                try {
                    n = in.read(buffer);
                } catch (IOException e) {
                    n = -1;
                }
                if (n <= 0) {
                    eof = true;
                    return '\0';
                }
                buffer.flip();
            }
            return buffer.get();
        }

        private void checkEof() {
            if (eof)
                throw new NoSuchElementException();
        }

        private char nextChar() {
            checkEof();
            char b = read();
            checkEof();
            return b;
        }

        private String next() {
            char b;
            do {
                b = read();
                checkEof();
            } while (Character.isWhitespace(b));
            StringBuilder sb = new StringBuilder();
            do {
                sb.append(b);
                b = read();
            } while (!eof && !Character.isWhitespace(b));
            return sb.toString();
        }

        private int nextInt() {
            return Integer.valueOf(next());
        }

        private long nextLong() {
            return Long.valueOf(next());
        }

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

Measured memory_bytes: 31060
#include<stdio.h>

int main(){
	int H,W;
	scanf("%d%d",&H,&W);
	int c[10][10];
	for(int i=0;i<10;i++){
		for(int j=0;j<10;j++)scanf("%d",&c[i][j]);
	}
	
	for(int k=0;k<10;k++){
		for(int i=0;i<10;i++){
			for(int j=0;j<10;j++){
				if(c[i][j]>c[i][k]+c[k][j])c[i][j]=c[i][k]+c[k][j];
			}
		}
	}
	int ans=0;
	for(int i=0;i<H*W;i++){
		int tmp;
		scanf("%d",&tmp);
		if(tmp!=-1)ans+=c[tmp][1];
	}
	printf("%d\n",ans);
	return 0;
}

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

using namespace std;
typedef long long ll;

char gc(){
	static const int L=(1<<19)+1;
	static char ibuf[L],*iS,*iT;
	if(iS==iT){
		iT=(iS=ibuf)+fread(ibuf,1,L,stdin);
		return iS==iT?EOF:*iS++;
	}
	return*iS++;
}
template<class I>void gi(I&x){
	static char c;static int f;
	for(f=1,c=gc();c<'0'||c>'9';c=gc())if(c=='-')f=-1;
	for(x=0;c<='9'&&c>='0';c=gc())x=x*10+(c&15);x*=f;
}

const int N=5005,M=205,K=13;
const ll inf=1e14;
int n,m,st[K][N][M],lg2[N];
ll D[N],ans;

inline void Max(int*a,int*b,int*c){for(int i=1;i<=m;i++)c[i]=max(a[i],b[i]);}
inline ll Sum(int*a,int*b){ll s=0;for(int i=1;i<=m;i++)s+=max(a[i],b[i]);return s;}
inline ll Get(int l,int r){int t=lg2[r-l+1];return Sum(st[t][l],st[t][r-(1<<t)+1]);}

void solve(int l,int r,int s,int t){
	if(l>r)return;
	int m=(l+r)>>1;
	ll best=-inf;int p;
	for(int i=s;i<=m&&i<=t;i++){
		ll cur=Get(i,m)-D[m]+D[i];
		if(cur>best)best=cur,p=i;
	}
	ans=max(ans,best);
	solve(l,m-1,s,p),solve(m+1,r,p,t);
}

int main(){
	gi(n),gi(m);
	for(int i=2;i<=n;i++)gi(D[i]),D[i]+=D[i-1];
	for(int i=1;i<=n;i++)for(int j=1;j<=m;j++)gi(st[0][i][j]);
	for(int i=2;i<=n;i++)lg2[i]=lg2[i-1]+!(i&(i-1));
	for(int i=1,l=2;l<=n;i++,l<<=1)for(int j=1;j+l-1<=n;j++)Max(st[i-1][j],st[i-1][j+(l>>1)],st[i][j]);
	solve(1,n,1,n);
	printf("%lld\n",ans);
	return 0;
}

Measured memory_bytes: 49920
it = iter(open(0).read().split())
def reads(v):
    r = []
    for i in range(v):
        r.append(next(it).strip())
    return r
def read():
    return next(it).strip()


while 1:
    M, N = map(int, reads(2))
    if M == N == 0:
        break
    S = [1]*M; rest = M
    k = 0
    for i in range(1, N+1):
        s = read()
        if rest == 1:
            continue
        ok = 1
        if i % 15 == 0:
            if s != "FizzBuzz":
                ok = 0
        elif i % 3 == 0:
            if s != "Fizz":
                ok = 0
        elif i % 5 == 0:
            if s != "Buzz":
                ok = 0
        else:
            if s != str(i):
                ok = 0
        if not ok:
            S[k] = 0
            rest -= 1
        k = (k + 1) % M
        while not S[k]:
            k = (k + 1) % M
    print(*[i+1 for i in range(M) if S[i]])


Measured memory_bytes: 15816
#include <bits/stdc++.h>
#define rep(i, n) for(int i=0; i<(n); ++i)
#define chmin(x,y) x = min(x,y)
#define chmax(x,y) x = max(x,y)
using namespace std;
using Graph = vector<vector<int>>;
typedef long long ll;
typedef pair<int, int> P;
const int inf = 1<<21;
const ll INF = 1LL << 60;
const ll mod = 1e9+7;

int x, y;
int dx[2] = {1, 2}, dy[2] = {2, 1};

const int MAX = 999999;
const int MOD = 1000000007;

long long fac[MAX], finv[MAX], inv[MAX];

// テーブルを作る前処理
void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}
// 二項係数計算
long long COM(int n, int k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

int main() {
    COMinit();
    cin >> x >> y;
    if((x+y)%3!=0){
        cout << 0 << endl;
        return 0;
    }
    if(x>y) swap(x, y);
    ll a = y-x;
    y -= a*2;
    x -= a;
    ll c = (x)/3;
    ll ans = COM(2*c+a, c);
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 23680
#include <iostream>
#include <string>
#include <cstring>
#include <vector>
#include <numeric>
#include <cstdlib>
#include <map>
#include <set>
#include <algorithm>
#include <math.h>

using namespace std;

int main(){
    int H,W;

    cin >> H >> W;

    vector<string> S;

    for(int i = 0; i < H; i++){
        string s;
        cin >> s;

        S.push_back(s);
    }

    vector<int> h;
    vector<int> w;

    for(int i = 0; i < W; i++){
        bool flag = false;
        for(int j = 0; j < H; j++){
            if(S[j][i] == '#'){
                flag = true;
            }
        }

        if(flag){
            w.push_back(i);
        }
    }

    for(int i = 0; i < H; i++){
        bool flag = false;
        for(int j = 0; j < W; j++){
            if(S[i][j] == '#'){
                flag = true;
            }
        }

        if(flag){
            h.push_back(i);
        }
    }

    for(int i = 0; i < h.size(); i++){
        for(int j = 0; j < w.size(); j++){
            cout << S[h[i]][w[j]];
        }
        cout << endl;
    }
 
    return 0;
}

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

int ans,x[10],y[10],z[10],dis[300][300];
int n,m,r; 

void check(){
	int sum=0;
	for(int i=2;i<=r;i++)
		sum+=dis[x[y[i-1]]][x[y[i]]];
	ans=min(ans,sum);
}

void dfs(int a){
	if (a==r+1){check(); return;}
	for(int i=1;i<=r;i++){
		if (z[i]==1) continue;
		z[i]=1; y[a]=i;
		dfs(a+1);
		z[i]=0;
	}
}

int main(){
	cin>>n>>m>>r;
	for(int i=1;i<=r;i++) cin>>x[i];
	for(int i=1;i<=n;i++)
		for(int j=1;j<=n;j++)
			dis[i][j]=1000000000;
	for(int i=1;i<=m;i++){
		int a,b,c; cin>>a>>b>>c;
		dis[a][b]=c;
		dis[b][a]=c;
	}
	for(int i=1;i<=n;i++) dis[i][i]=0;
	for(int k=1;k<=n;k++)
		for(int i=1;i<=n;i++)
			for(int j=1;j<=n;j++)
				dis[i][j]=min(dis[i][j],dis[i][k]+dis[k][j]);
	memset(z,0,sizeof(z));
	ans=1000000000;
	dfs(1);
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
#define rep(i,m,n) for(int i=m;i<n;i++)
ll mod=1e9+7;

int main(){
  int x,y,z;
  cin>>x>>y>>z;
  cout<<z<<" "<<x<<" "<<y<<endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define Int int64_t
#define dump(x) cout << (x) << endl
#define fi first
#define se second
Int mod = 1e9+7;
//Int mod = 998244353;
Int INF = 1e18;
double EPS = 0.00000001;

Int n;
vector<Int> G[100001];
 
Int dfs(Int x) {
    //cout << "pro" << " " << x << endl;
    if (G[x].empty()) {
        return 0;
    }
    vector<Int> v;
    for (Int i = 0; i < (Int)G[x].size(); i++) {
        v.push_back(dfs(G[x][i]));
    }
    Int ma = -1;
    sort(v.begin(), v.end(), greater<Int>());
    for (Int i = 0; i < (Int)v.size(); i++) {
        ma = max(ma, v[i] + i + 1);
    }
    //cout << x << " " << ma << endl;
    return ma;
}

int main() {
    cin >> n;
    for (Int i = 2; i <= n; i++) {
        Int x;
        cin >> x;
        G[x].push_back(i);
    }
    dump(dfs(1));
    return 0;
}

Measured memory_bytes: 13568
#include <iostream>
#include <bits/stdc++.h>
#define ll long long

using namespace std;
const ll Mod = 1e9 + 7;

void add_self(ll &x , ll y){
    x = (x + y)%Mod;
}
vector < pair < ll , ll > > v;
ll n,k,dp[110][100100],pre[100100];


int main()
{
    cin >> n >> k;
    for(ll i = 1;i<=n;i++){
        ll curr = n/i;
        ll Start = i , End = n , Res;
        while(Start <= End){
            ll mid = (Start + End)/2;
            if(n/mid == curr)  Res = mid , Start = mid + 1;
            else  End = mid - 1;
        }
        v.push_back({curr , Res - i + 1});
        i+=(Res - i);
    }
    for(ll i = 0;i<=v.size();i++)  dp[k][i] = 1 , pre[i] = (i == 0 ? v[i].second : (pre[i - 1] + v[i].second)%Mod);
    for(ll i = k - 1;i>=0;i--){
        for(ll j = 0;j<v.size();j++){
            if(i == 0)  add_self(dp[i][j] , pre[v.size() - 1]);
            else {
                ll start = 0 , End = v.size() - 1 , idx = 0;
                while(start <= End){
                    ll mid = (start + End)/2;
                    if((n/v[mid].first) * (n/v[j].first) <= n)  idx = mid , start = mid + 1;
                    else  End = mid - 1;
                }
                add_self(dp[i][j] , pre[idx]);
            }
        }
        for(ll j = 0;j<v.size();j++)  pre[j] = (j == 0 ? (v[j].second * dp[i][j])%Mod : (pre[j - 1] + v[j].second * dp[i][j])%Mod);
    }
    cout << dp[0][0];
    return 0;
}


Measured memory_bytes: 80628
#include<bits/stdc++.h>
using namespace std;
#define rep(i,a,b) for(int i=a;i<b;i++)



double r1, r2;
//-----------------------------------------------------------------
int main() {
	cin >> r1 >> r2;
	double ans = 1.0 / (1.0 / r1 + 1.0 / r2);
	printf("%.10f\n", ans);
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int k,t,a[105];
int main() {
	ios::sync_with_stdio(false);
	cin >> k >> t;
	for(int i = 1; i <= t; i++)
		cin >> a[i];
	sort(a + 1,a + t + 1);
	if(a[t] <= k / 2)
		cout << "0\n";
	else
		cout << 2 * a[t] - k - 1 << endl;
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cmath>
#include <vector>
using namespace std;
#define PI 3.14159265
#define rep(i,n) for(int i=0;i<n;i++)
struct P{double x,y;};

double dist(P a , P b){
	a.x-=b.x , a.y-=b.y;
	return sqrt(a.x * a.x + a.y * a.y);
}

double heron(P a , P b , P c){
	double l[3] = {dist(a,b),dist(b,c),dist(a,c)};
	double z = (l[0]+l[1]+l[2]) / 2.0;
	return sqrt( z*(z-l[0])*(z-l[1])*(z-l[2]) );
}
int main(){
	P t;
	vector<P> d;
	while(~scanf("%lf,%lf",&t.x,&t.y))d.push_back(t);
	double sum = 0;
	int n = d.size();
	for(int i=1;i+1<n;i++)sum += heron(d[0],d[i],d[i+1]);
	cout << sum << endl;
}

Measured memory_bytes: 0
main :: IO()
main = do
 [a,b,c] <- map read . words <$> getLine :: IO [Integer]
 let rightHand = (c - a - b) * (c - a - b)
 let leftHand = 4 * a * b
 putStr $ if (leftHand < rightHand) && ((c - a - b) > 0) then "Yes" else "No"

Measured memory_bytes: 3936
#include <iostream>
using namespace std;
int main(){
  int a, b, req;
  char op;
  while(true){
    cin >> a >> op >> b;
    if(op == '?'){
      break;
    }
    if(op == '+'){
      req = a + b;
    } else if(op == '-'){
      req = a - b;
    } else if(op == '*'){
      req = a * b;
    } else if(op == '/'){
      req = a / b;
    }
    cout << req << endl;
  }
}


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

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
 
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define rep1(i, n) for (ll i = 1; i <= (ll)(n); i++)
#define INF 10000000000
#define MOD 1000000007
using ll = long long;
using pint = pair<int,int>;
using pll = pair<ll,ll>;
using Graph = vector<vector<int>>;

void output(pint P){
    int p = P.first, y = P.second;
    string sp = to_string(p), sy = to_string(y);
    while(sp.size()!=6){
        sp = '0' + sp;
    }
    while(sy.size()!=6){
        sy = '0' + sy;
    }
    cout<<sp<<sy<<endl;
}

int main(){
    int N,M; cin>>N>>M;
    vector<pll> Y;//y,ind
    vector<int> P(M);
    rep(i,M){
        cin>>P[i];
        ll y; cin>>y;
        Y.push_back({y,i});
    }
    sort(Y.begin(),Y.end());
    vector<pint> R(M); // P/jyunn
    vector<int> C(N,0);
    rep(i,M){
        ll ind = Y[i].second;
        ll p = P[ind];
        int c = C[p]+1;
        C[p]++;
        R[ind] = {p,c};
    }
    rep(i,M) output(R[i]);
}


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

using ll = long long;

#define rep(i, n) for (int i = 0; i < (n); ++i)
#define rrep(i, n) for (int i = 1; i <= (n); ++i)
#define drep(i, n) for (int i = (n)-1; i >= 0; --i)
#define ddrep(i, n) for (int i = n; i > 0; --i)
#define srep(i, s, t) for (int i = s; i < t; ++i)
#define ssrep(i, s, t) for (int i = s; i <= t; ++i)

#define rng(a) a.begin(), a.end()
#define pb push_back
#define eb emplace_back
#define fi first
#define se second

#define chmax(x, y) (x = max(x, y))
#define chmin(x, y) (x = min(x, y))

using pi = pair<int, int>;
using vi = vector<int>;
using vvi = vector<vi>;
using vl = vector<ll>;
using vvl = vector<vl>;
using ld = long double;

template <class T, class U>
ostream &operator<<(ostream &os, const pair<T, U> &p) {
  os << "(" << p.first << "," << p.second << ")";
  return os;
}

template <class T> ostream &operator<<(ostream &os, const vector<T> &v) {
  os << "{";
  rep(i, (int)v.size()) {
    if (i)
      os << ",";
    os << v[i];
  }
  os << "}";
  return os;
}

template <typename T, size_t S> void printArray(const T (&array)[S]) {
  for (auto val : array)
    std::cout << val << ", ";
  std::cout << "\n";
}

const int mod = 1e9 + 7;
const int inf = 1e9 + 5;

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << std::setprecision(10);

  int n, m; std::cin >> n >> m;
  vi flags(m);
  rep(i, m) {
    int k; std::cin >> k;
    rep(j, k) {
      int s; std::cin >> s;
      flags[i] += 1 << (s-1);
    }
  }
  vi p(m); rep(i, m) std::cin >> p[i];
  int ans = 0;
  srep(i, 0, (1 << n)) {
    bool ok = true;
    rep(j, m) {
      int light = flags[j] & i;
      int cnt = 0;
      while (light) cnt += light % 2, light /= 2;
      if (cnt % 2 != p[j]) ok = false;
    }
    if (ok) ans++;
  }
  std::cout << ans << "\n";
}


Measured memory_bytes: 256
/* ＵＴＦ－８ */
#include <iostream>
#include <string>
#include <vector>
#include <deque>
#include <list>
#include <set>
#include <unordered_set>
#include <map>
#include <unordered_map>
#include <array>
#include <queue>
#include <stack>
#include <algorithm>
#include <tuple>
#include <numeric>
#include <type_traits>
#include <limits>

#include <stdio.h>
#include <unistd.h>
#include <fcntl.h>
#include <string.h>

#define USE_COLORED 1

#ifdef USE_COLORED
static const char stdout_pre[]  = "\033[1m"; // bold black
static const char stderr_pre[]  = "\033[31;1m"; // bold red
static const char stdxxx_post[] = "\033[m";

// 当然ながら GCC(g++)/libstdc++ 依存
#include <ext/stdio_filebuf.h>
using stdio_filebuf = __gnu_cxx::stdio_filebuf<char>;
class colored_stdio_filebuf : public stdio_filebuf {
private:
	const char* const pre_;
	const char* const post_;

public:
	colored_stdio_filebuf(FILE* fp, const char* pre, const char* post) : stdio_filebuf(fp, std::ios_base::out), pre_(pre), post_(post)
	{
	}

protected:
	std::streamsize xsputn(const char* s, std::streamsize count) override
	{
		stdio_filebuf::xsputn(pre_, strlen(pre_));
		auto ret = stdio_filebuf::xsputn(s, count);
		stdio_filebuf::xsputn(post_, strlen(post_));
		return ret;
	}
};
#endif

int main()
{
#ifdef USE_COLORED
	if (getenv("DEBUG")) {
		std::cout.rdbuf(new colored_stdio_filebuf(stdout, stdout_pre, stdxxx_post));
		std::cerr.rdbuf(new colored_stdio_filebuf(stderr, stderr_pre, stdxxx_post));
	} else
#endif
	{
		int fd = open("/dev/null", O_WRONLY);
		dup2(fd, 2);
		close(fd);
	}
	
	int X, t;
	std::cin >> X >> t;
	std::cout << std::max(X-t, 0) << "\n";
}


Measured memory_bytes: 512
#include<bits/stdc++.h>
using namespace std;
#define ios ios_base::sync_with_stdio(0);cin.tie(NULL);cout.tie(NULL)
#define ll long long
int main()
{
    ios;
    ll a,b,c,k,sum=0;
    cin>>a>>b>>c>>k;
    if(k>=a)
    {
        sum+=a;
        k-=a;
        if(k>0)
            k-=b;
        if(k>0)
        {
            while(c&&k)
            {
                k--;
                sum--;
                c--;
            }
        }
    }
    else
    {
        sum+=k;
        k-=k;
    }
    cout<<sum<<endl;
}



Measured memory_bytes: 3608
var
	N,A,B,C,D,i:Longint;
	S:String;
begin
	readln(N,A,B,C,D);
	readln(S);
	for i:=A to C-1 do if(S[i]='#')and(S[i+1]='#')then begin
		writeln('No');
		exit;
	end;
	for i:=B to D-1 do if(S[i]='#')and(S[i+1]='#')then begin
		writeln('No');
		exit;
	end;
	if C<D then writeln('Yes')else begin
		for i:=B-1 to D-1 do if(S[i]='.')and(S[i+1]='.')and(S[i+2]='.')then begin
			writeln('Yes');
			exit;
		end;
		writeln('No');
	end;
end.


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

int main(){
  string s;
  cin >> s;
  if(s=="zyxwvutsrqponmlkjihgfedcba"){
    cout << -1 << endl;
  }else if(s.size()==26){
    int i=24,j;
    while(s.at(i)>s.at(i+1)){
      i--;
    }
    char m='z';
    for(j=i+1;j<26;j++){
      if(s.at(j)>s.at(i)){
        m=min(m,s.at(j));
      }
    }
    string t="";
    for(j=0;j<i;j++){
      t += s.at(j);
    }
    t += m;
    cout << t << endl;
  }else{
    vector<int> a(26,0);
    int i;
    for(i=0;i<s.size();i++){
      a.at(s.at(i)-'a')++;
    }
    i=0;
    while(a.at(i)==1){
      i++;
    }
    char m='a'+i;
    cout << s << m << endl;
  }
}

Measured memory_bytes: 3640
#include<stdio.h>
#include<string.h>
#include<stdlib.h>

int J(int, int, int, int, int);

int main(void)
{
	int x, y, px, py, n, h;
	char I[9];
	
	while(scanf("%d %d",&x, &y) && x > 0)
	{
		px = 1; py = 1;
		h = 1;
		while(scanf("%s",&I) && strcmp(I,"STOP") != 0)
		{
			if(strcmp(I,"FORWARD") == 0 || strcmp(I,"BACKWARD") == 0)
			{
				scanf("%d",&n);
				if(strcmp(I,"FORWARD") == 0)
				{
					//北
					if(h == 1)
						py = J(py, n, y, y, py+n);
					//東
					else if(h == 2)
						px = J(px, n, x, x, px+n);
					//南
					else if(h == 3)
						py = J(py, -n, 1, py-n, 1);
					//西
					else
						px = J(px, -n, 1, px-n, 1);
				}
				else
				{
					//北
					if(h == 1)
						py = J(py, -n, 1, py-n, 1);
					//東
					else if(h == 2)
						px = J(px, -n, 1, px-n, 1);
					//南
					else if(h == 3)
						py = J(py, n, y, y, py+n);
					//西
					else
						px = J(px, n, x, x, px+n);
				}
			}
			else if(strcmp(I,"LEFT") == 0)
			{
				if(h == 1)
					h = 4;
				else if(h == 2)
					h = 1;
				else if(h == 3)
					h = 2;
				else
					h = 3;
			}
			else
			{
				if(h == 1)
					h = 2;
				else if(h == 2)
					h = 3;
				else if(h == 3)
					h = 4;
				else
					h = 1;
			}
		}
		printf("%d %d\n",px,py);
	}
	return 0;
}

int J(int a, int b, int k, int l, int l2)
{
	if(a + b >= k)
		return l;
	else
		return l2;
}

Measured memory_bytes: 0
S = list(input())
Q = int(input())

from collections import deque

S = deque(S)

tfc = [[] for _ in range(Q)]

swich = 0
for i in range(Q):
    tfc[i] = input().split()
    
    if int(tfc[i][0])==1:
        swich += 1
    else:
        if swich%2==0:
            if int(tfc[i][1])==1:
                S.appendleft(tfc[i][2])
            else:
                S.append(tfc[i][2])
        else:
            if int(tfc[i][1])==1:
                S.append(tfc[i][2])
            else:
                S.appendleft(tfc[i][2])

if swich%2==1:
    S = reversed(S)
    print("".join(S))
else:
    print("".join(S))




Measured memory_bytes: 114748
#include <bits/stdc++.h>
using namespace std;
//freopen("input.txt", "r", stdin);
//freopen("output.txt", "w", stdout);
 
typedef long long ll;
#define FIN ios::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define forr(i, a, b) for(int i = (a); i < (int) (b); i++)
#define forn(i, n) forr(i, 0, n)
#define pb push_back
#define mp make_pair
#define all(c) (c).begin(),(c).end()
#define DBG(x) cerr << #x << " = " << (x) << endl
#define DBGV(v,n) forn(i,n) cout << v[i] << " "; cout << endl
#define esta(x,c) ((c).find(x) != (c).end())
#define RAYA cerr << "===============================" << endl
#define MAXN 2005


int main()
{ 
	FIN;
	
	#ifdef input
		//freopen("test1.txt", "r", stdin);
	#endif
	
	ll suma = 0;
	int n;
	cin >> n;
	vector <ll> v(n);
	forn(i,n) cin >> v[i];
	forn(i,n) suma+=v[i];
	vector <int> cont (200005,0);
	forn(i,n) cont[v[i]]++;
	int q;
	cin >> q;
	while(q--)
	{
		ll a, b;
		cin >> a >> b;
		suma+=(b-a)*cont[a];
		cout << suma << "\n";
		int aux = cont[a];
		cont[a]=0;
		cont[b]+=aux;
	}
		
		
	
	return 0;
}


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

using namespace std;

typedef long long ll;

const int INF = 1e9;
const ll LLINF = 1e18;
const ll MOD = (ll)1e9 + 7;

int main()
{
  int N, D, X; scanf("%d %d %d", &N, &D, &X);
  int ans = 0;
  vector<int> A(N);
  for (int i = 0; i < N; ++i) {
    scanf("%d", &A[i]);
  }
  for (int i = 0; i < N; ++i) {
    for (int d = 1; d <= D; d += A[i]) {
      ++ans;
    }
  }
  ans += X;
  printf("%d\n", ans);
  return 0;
}


Measured memory_bytes: 256
#include <stdio.h>

int main(void) {
  
  int a, b, c, d, e, k;
  scanf("%d\n%d\n%d\n%d\n%d\n%d\n", &a, &b, &c, &d, &e, &k);
  
  (e - a > k || d - a > k || c - a > k || b - a > k)  ? puts(":(") : puts("Yay!");
  
  return 0; 
  
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
const int INF = 1e9;
const int MOD = 1e9+7;
const long long LINF = 1e18;
#define dump(x)  cout << 'x' << ' = ' << (x) << ` `;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) for(int i=0;i<(n);++i)
#define REPR(i,n) for(int i=n;i>=0;i--)
#define FOREACH(x,a) for(auto& (x) : (a) )
typedef long long ll;
using namespace std;
typedef pair<ll, ll> P;

int main(int argc, char const *argv[]) {
    int x,a;
    cin >> x >> a;

    if (x < a) cout << 0 << endl;
    else cout << 10 << endl;
    return 0;
}

Measured memory_bytes: 256
// Author : ps41

#include <bits/stdc++.h>
using namespace std;
#define ll int64_t
const int M = 1e9 + 7, N = 1e6 + 5;

int main()
{
    ios::sync_with_stdio(false), cin.tie(nullptr);
    int k;
    cin >> k;
    ll a = 7;
    for (int i = 0; i < 1000004; i++)
    {
        a %= k;
        if (a == 0) cout << i + 1, exit(0);
        a = a * 10 + 7;
    }
    cout << -1;
}

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

int main() {
  int n, x = 0, m, k;
  scanf("%d", &n);
  while (n--) {
    scanf("%d%d", &m, &k);
    while (m % k && m >= k) {
      m -= ((m - m / k * k - 1) / (m / k + 1) + 1) * (m / k + 1);
    }
    x ^= m / k;
  }
  puts(x ? "Takahashi" : "Aoki");
}


Measured memory_bytes: 384
n = int(input())
a = [0 for _ in range(n+2)]
a[1:-1] = list(map(int, input().split()))
total = 0
for i in range(n + 1):
    total += abs(a[i+1]-a[i])

for i in range(1, n + 1):
    print(total-abs(a[i]-a[i-1])-abs(a[i+1]-a[i])+abs(a[i+1]-a[i-1]))


Measured memory_bytes: 14852
def solver(a, b, c, d, e, f)
  if a * b * d * e != 0
    return ((c - f * (b / e)) / (a - d * (b / e))), ((c - f * (a / d)) / (b - e * (a / d)))
  else
    if a == 0
      return ((f - e * (c / b)) / d), (c / b)
    elsif b == 0
      return (c / a), ((f - d * (c / a)) / e)
    elsif d == 0
      return ((c - b * (f / e)) / a), (f / e)
    else
      return (f / d), ((c - a * (f / d)) / b)
    end
  end
end
def in_triangle?(a, b, c, d, e, f, g, h)
  x, y = solver(h - b, a - g, a * h - b * g, f - d, c - e, c * f - d * e)
  if (e < x and x < c) or (c < x and x < e) or (d < y and y < f) or (f < y and y < d)
    return true
  else
    return false
  end
end
while arg = gets
  a, b, c, d, e, f, g, h = arg.split(" ").map(&:to_f)
  if in_triangle?(a, b, c, d, e, f, g, h) and in_triangle?(c, d, a, b, e, f, g, h)
    puts "YES"
  else
    puts "NO"
  end
end

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

#define endl '\n'

using namespace std;

long long n, k;
void read()
{
    cin >> n >> k;
}

void solve()
{
    long long r = n % k;
    cout << min(r, k-r) << endl;
}

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

    read();
    solve();
}


Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include <cassert>
#include<string>
#include<vector>
#include <utility>
#include <math.h>
#include<cmath>
#define INF 1000000009;
using namespace std;
vector<pair<long long, long long>>juice;
int gcd(int a, int b) {
	while (a % b != 0) {
		int c = 0;
		c = a % b;
		a = b;
		b = c;
	}
	return  b;
}
vector<int> SWITCH[11];
int main() {
	int N = 0, M = 0;
	cin >>N>>M;
	int a=0,b=0;
	int ans=0;
	int CHECK[11] = { 0 };
	for (int i = 0; i < M; i++) {
		cin >> a;
		for (int j = 0; j < a; j++) {
			cin >> b;
			SWITCH[i].push_back(b);
		}
	}
	for (int i = 0; i < M; i++) {
		cin >> CHECK[i];
	}
	for (int bit = 0; bit < (1 << N); bit++) {
		bool RIGHT[11] = { false };
		for (int i = 0; i < N; i++) {
			if (bit & 1 << i) {
				RIGHT[i] = true;
				//cout << i<< endl;
			}
		}
		//cout << RIGHT[0]<<endl;
		int counto = 0;
		for (int i = 0; i < M; i++) {
			int mod = 0;
			for (int j = 0; j < SWITCH[i].size(); j++) {
				if (RIGHT[SWITCH[i][j]-1] == true) {
					mod++;
				}
				//cout << SWITCH[i][j]<<' '<< RIGHT[SWITCH[i][j]] << endl;
			}
			//cout << SWITCH[i].size() << endl;
			//cout << "A=" << mod << endl;
			if ((mod % 2) == CHECK[i]) {
				counto++;
			}
		}
		if (counto == M) {
			ans++;
		}
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
 
int main() {
    int  a,b,co,ans;
    ans=1;
    cin>>a>>b;
    co=a;
    if(b==1){
      cout<<0<<endl;
    }
    else if(a>=b){
        cout<<1<<endl;
    }else{
    for(int i=0;i<40;i++){
        co=co+a-1;
        ans++;
        if(co>=b){
            break;
        }
    }
    cout<<ans<<endl;
    }
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int n,c[100005],f[100005],s[100005],rez[100005];
int lcnow,tmnow;

int main(){
	cin>>n;
	for(int i=1;i<n;i++)  cin >> c[i] >> s[i] >> f[i];
	rez[n]=0;
	for(int j=1;j<=n-1;j++){
	    for(int i=j;i<=n-1;i++){
		    if(tmnow<=s[i]) {tmnow=s[i]+c[i]; continue;}
		    if(tmnow%f[i]==0){ tmnow+=c[i]; continue;}
           tmnow=tmnow+f[i]-(tmnow%f[i])+c[i];

	    }
	    rez[j]=tmnow;
	    tmnow=0;
	
	}
	for(int i=1;i<=n-1;i++) cout<<rez[i]<<"\n";
	cout<<"0";
	
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<algorithm>
#include<math.h>
using namespace std;
int main(){
    int N;
    cin >> N;
    for(int i = 1;i <= 9;i++){
        for(int j = 1;j <= 9;j++)
        if(N == i * j){cout << "Yes";return 0;}
    }
    cout << "No";
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i,n) for(ll i=0;i<ll(n);i++)
int main() {
    int n;
    cin >> n;
    vector<int> a(n);
    rep(i, n) cin >> a[i];
    sort(a.begin(), a.end());
    vector<int> v(1e6 + 1, 0);
    rep(i, n) {
        if (v[a[i]] >= 1) {
            v[a[i]]++;
            continue;
        }
        for (int j = a[i]; j <= 1e6; j+=a[i]) {
            v[j]++;
        }
    }
    int ans = 0;
    rep(i, n) {
        if (v[a[i]] <= 1) {
            ans++;
            //cout << a[i] << ' ';
        }
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 7924
import numpy as np

def ii():
    return int(input())


def lii():
    return list(map(int, input().split(' ')))


def lvi(N):
    l = []
    for _ in range(N):
        l.append(ii())
    return l


def lv(N):
    l = []
    for _ in range(N):
        l.append(input())
    return l


N = ii()
P = []
for _ in range(N):
    p = ii()
    P.append(p-1)

Q = [0 for i in range(N)]
for i in range(N):
    Q[P[i]] = i

maxcnt = 1
cnt = 1
for i in range(1, N):
    if Q[i] > Q[i-1]:
        cnt += 1
    else:
        cnt = 1

    maxcnt = max(maxcnt, cnt)

print(N - maxcnt)

Measured memory_bytes: 37796
#include<stdio.h>
int main(){
  int i,tmp,num;
  scanf("%d",&num);
  int sort[num];
  for(i=0;i<num;i++){
    scanf("%d",&tmp);
    sort[tmp-1] = i+1;
  }
  for(i=0;i<num;i++){
    if(i==num-1)
      printf("%d",sort[i]);
    else
      printf("%d ",sort[i]);
  }
  return 0;
}

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

typedef ostringstream OSS;
typedef istringstream ISS;

typedef long long LL;
typedef pair<int, int> PII;

typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<LL> VLL;
typedef vector<VLL> VVLL;
typedef vector<string> VS;
typedef vector<VS> VVS;
typedef vector<bool> VB;
typedef vector<VB> VVB;
typedef vector<PII> VPII;

#define fst first
#define snd second
#define MP make_pair
#define PB push_back
#define EB emplace_back 
#define ALL(x) (x).begin(),(x).end()
#define RANGE(x,y,maxX,maxY) (0 <= (x) && 0 <= (y) && (x) < (maxX) && (y) < (maxY))
#define DUMP( x ) cerr << #x << " = " << ( x ) << endl

template < typename T > inline T fromString(const string &s) { T res; ISS iss(s); iss >> res; return res; };
template < typename T > inline string toString(const T &a) { OSS oss; oss << a; return oss.str(); };

const int INF = 0x3f3f3f3f;
const LL INFL = 0x3f3f3f3f3f3f3f3fLL;
const int DX[]={1,0,-1,0},DY[]={0,-1,0,1};

class FordFulkerson{
public:
	struct edge {
		edge(int t, int c, int r) : to(t), cap(c), rev(r) { };
		int to, cap, rev;
	};

	int V;
	
	vector< vector<edge> > G;
	vector<bool> used;

	FordFulkerson(int v) {
		this->V = v;
		G = vector< vector<edge> >(v);
		used = vector<bool>(v);
	}

	void addEdge(int from, int to, int cap) {
		G[from].push_back( edge(to, cap, G[to].size()) );
		G[to].push_back( edge(from, 0, G[from].size() - 1) );
	}

	int dfs(int v, int t, int f) {
		if (v == t) return f;

		used[v] = true;

		for (int i = 0; i < (int)G[v].size(); i++) {
			edge &e = G[v][i];
			if (!used[e.to] && e.cap > 0) {
				int d = dfs(e.to, t, min(f, e.cap));
				if (d > 0) {
					e.cap -= d;
					G[e.to][e.rev].cap += d;
					return d;
				}
			}
		}

		return 0;
	}

	int maxFlow(int s, int t) {
		int flow = 0;
		while (true) {
			used = vector<bool>(V, 0);
			int f = dfs(s, t, INT_MAX);
			if (f == 0) return flow;
			flow += f;
		}
	}
};

int solve(int bn, int rn, VI &bs, VI &rs) {
	const int v = bn + rn + 2;
	const int s = 0, t = 1;
	const int offset_b = 2;
	const int offset_r = 2 + bn;

	FordFulkerson ff(v);

	// s -> bs[i]
	for (int i = 0; i < bn; i++) {
		ff.addEdge(s, i + offset_b, 1);
	}

	// rs[i] -> t
	for (int i = 0; i < rn; i++) {
		ff.addEdge(i + offset_r, t, 1);
	}

	// bs[i] -> rs[j]
	for (int i = 0; i < bn; i++) {
		for (int j = 0; j < rn; j++) {
			if (__gcd(bs[i], rs[j]) != 1) {
				ff.addEdge(i + offset_b, j + offset_r, 1);
			}
		}
	}

	return ff.maxFlow(s, t);
}

int main(void) {
	int bn, rn;
	while (cin >> bn >> rn, bn) {
		VI bs(bn), rs(rn);
		for (auto &b : bs) cin >> b;
		for (auto &r : rs) cin >> r;
		cout << solve(bn, rn, bs, rs) << endl;
	}

	return 0;
}

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

#define watch(x) cerr << (#x) << ": " << (x) << endl

int32_t main() {

    int n; cin >> n;
    vector<int> w(n);
    for(int i = 0; i < n; ++i) cin >> w[i];

    int sum = 0;
    for(int ww : w) sum += ww;

    int low = 0;
    int ans = sum;

    for(int i = 0; i < n; ++i) {
        low += w[i];
        sum -= w[i];
        ans = min(ans, abs(sum-low));
    }

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


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

using namespace std;
#define rep(i, n) for(int i = 0; i < signed(n); i++)
#define REP(i, s, n) for(int i = (s); i < signed(n); i++)
#define rrep(i, n) for(int i = signed(n) - 1; i >= 0; i--)
#define all(co) co.begin(), co.end()
typedef pair<int, int> P;
typedef long long LL;
typedef pair<P, int> PI;
typedef pair<int, P> IP;
const int INF = 1 << 29;
const LL LINF = 1ll << 62ll;

struct edge{ int from, to, cost; };

int dr[] = { -1, 0, 1, 0 };
int dc[] = { 0, 1, 0, -1 };

template<typename T = int>
vector<vector<T>> vvector(int h, int w, T def = T()){ return move(vector<vector<T>>(h, vector<T>(w, def))); }
class range {
private: struct I{ int x; int operator*(){ return x; }bool operator!=(I& lhs){ return x < lhs.x; }void operator++(){ ++x; } }; I i, n;
public:range(int n) :i({ 0 }), n({ n }){}range(int i, int n) :i({ i }), n({ n }){}I& begin(){ return i; }I& end(){ return n; }
};

const int MOD = 10000;
signed main()
{
	int W, H;
	while (cin >> H >> W && H)
	{
		vector<string> stage(H);
		vector<string> monsho(2);
		rep(i, H) cin >> stage[i];
		cin >> monsho[0] >> monsho[1];

		int base = 0;
		auto isMonsho = [&](int i, int j){
			return  i >= 0 && j >= 0 && i + 1 < H && j + 1 < W
				&& stage[i][j] == monsho[0][0]
				&& stage[i][j + 1] == monsho[0][1]
				&& stage[i + 1][j] == monsho[1][0]
				&& stage[i + 1][j + 1] == monsho[1][1];
		};

		rep(i, H - 1) rep(j, W - 1) if (isMonsho(i, j))
			base++;

		int ans = base;
		string str = "JOI";
		int dr[] = { 0, 0, -1, -1 };
		int dc[] = { 0, -1, -1, 0 };
		rep(r, H) rep(c, W)
		{
			int baseSur = 0;
			rep(i, 4) if (isMonsho(r + dr[i], c + dc[i])) baseSur++;

			rep(i, 3)
			{
				char buf = stage[r][c];
				stage[r][c] = str[i];
				int nextSur = 0;
				rep(i, 4) if (isMonsho(r + dr[i], c + dc[i])) nextSur++;
				stage[r][c] = buf;

				ans = max(ans, base - baseSur + nextSur);
			}
		}
		cout << ans << endl;
	}
	return 0;
}

Measured memory_bytes: 2052
#include <stdio.h>
#include <string.h>
 
#define N 25
 
typedef struct{
  int left, right;
}Node;
 
Node tree[N];
int n;
char root[N];
 
void visit_pre(int p){
  printf(" %d", p);
  if(tree[p].left != -1) visit_pre(tree[p].left);
  if(tree[p].right != -1) visit_pre(tree[p].right);
}
 
void visit_in(int p){
  if(tree[p].left != -1) visit_in(tree[p].left);
  printf(" %d", p);
  if(tree[p].right != -1) visit_in(tree[p].right);
}
 
void visit_post(int p){
  if(tree[p].left != -1) visit_post(tree[p].left);
  if(tree[p].right != -1) visit_post(tree[p].right);
  printf(" %d", p);
}
 
main(){
  int i, r;
  scanf("%d", &n);
  memset(root, 1, n);
  for(i=0;i<n;i++) tree[i].left = tree[i].right = -1;
  for(i=0;i<n;i++){
    int idx, l, r;
    scanf("%d %d %d", &idx, &l, &r);
    tree[idx].left = l;
    tree[idx].right = r;
    root[l] = root[r] = 0;
  }
  for(i=0;i<n;i++) if(root[i]) r = i;
  printf("Preorder\n");
  visit_pre(r);
  printf("\n");
  printf("Inorder\n");
  visit_in(r);
  printf("\n");
  printf("Postorder\n");
  visit_post(r);
  printf("\n");
  return 0;
}


Measured memory_bytes: 2072
/*
 ********************************************************************************
 *  Author: ThoseBygones
 *  Version: V1.0
 *  Date: 2018-07-01
 *  Subject: ACM-ICPC
 *  Language: C/C++11
 *  OJ: AOJ
 *  Algorithm:
 ********************************************************************************
 *  Algo-Description:
 ********************************************************************************
 */

//#include <bits/stdc++.h>  //For CodeForces only

//#pragma comment(linker,"/STACK:102400000,102400000")
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cassert>
#include <climits>
#include <ctime>
#include <numeric>
#include <vector>
#include <algorithm>
#include <bitset>
#include <cmath>
#include <cstring>
#include <iomanip>
#include <complex>
#include <deque>
#include <functional>
#include <list>
#include <map>
#include <string>
#include <sstream>
#include <set>
#include <stack>
#include <queue>
using namespace std;
template<class T> inline T sqr(T x)
{
    return x * x;
}
typedef long long LL;
typedef unsigned long long ULL;
typedef long double LD;
typedef pair<int, int> PII;
typedef pair<PII, int> PIII;
typedef pair<LL, LL> PLL;
typedef pair<LL, int> PLI;
typedef pair<LD, LD> PDD;
#define MP make_pair
#define PB push_back
#define sz(x) ((int)(x).size())
#define clr(ar,val) memset(ar, val, sizeof(ar))
#define istr stringstream
#define FOR(i,n) for(int i=0;i<(n);++i)
#define forIt(mp,it) for(__typeof(mp.begin()) it = mp.begin();it!=mp.end();it++)
const double EPS = 1e-6;
const int INF = 0x3fffffff;
const LL LINF = INF * 1ll * INF;
const double PI = acos(-1.0);

#define lson l,mid,rt<<1
#define rson mid+1,r,rt<<1|1
#define lowbit(u) (u&(-u))


int main()
{
    int a,b;
    scanf("%d%d",&a,&b);
    printf("%d\n",__gcd(a,b));
    return 0;
}



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

int main(){
	int a[10],k;
	cin>>a[0]>>a[1]>>a[2];
	cin>>k;
	sort(a,a+3);
	for(int i=0; i<k; i++)a[2]*=2;
	cout<<a[0]+a[1]+a[2]<<endl;
}


Measured memory_bytes: 256