akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
#define LL long long
#define ull unsigned long long
#define sc(a) scanf("%d",&a)
#define sc2(a,b) scanf("%d%d",&a,&b)
#define ss(a) scanf("%s",a)
#define mem(a,b) memset(a,b,sizeof(a))
#define PII pair<int,int>
const double pi = acos(-1.0);
using namespace std;
const int maxn = 1e6 + 5;
const int mod = 1e9 + 7;
int main(){
	string a,b;
	cin >> a >> b;
	int ans = 0,cnt;
	int i = 0;
	while(i + b.size() - 1 < a.size()){
		int cnt = 0;
		for(int j = 0; j < b.size(); j++){
			if(a[i + j] == b[j])cnt ++;
		}
		ans = max (ans, cnt);
		i ++;
	}
	cout <<b.size() - ans << endl;
	return 0;
}

Measured memory_bytes: 3612
#include <iostream>
#include <string>
#include <algorithm>
#include <functional>
#include <vector>
#include <utility>
#include <cstring>
#include <iomanip>
#include <numeric>
#include <cmath>
#include <cassert>
using namespace std;
using ll = long long;
const int INF = 1<<30;
const int MOD = 1e9 + 7;
string s;
bool check(int left, int right)
{
    bool res = true;
    int cnt = 0;
    for(int i = left; i <= right; i++)
    {
        if(s[i] == '#') cnt++;
        else cnt = 0;
        if(cnt == 2) res = false;
    }
    return res;
}
signed main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n; cin >> n;
    int A, B, C, D; cin >> A >> B >> C >> D;
    A--, B--, C--, D--;
    cin >> s;
    bool ok = true;
    if(C < D)
    {
        if(not check(B, D)) ok = false;
        if(not check(A, C)) ok = false;
    }
    else
    {
        bool over = false;
        int cnt = 0;
        for(int i = B - 1; i <= D; i++)
        {
            if(s[i] == '.') cnt++;
            else cnt = 0;
            if(cnt == 3) over = true;
        }
        ok = false;
        if(check(B, D))
        {
            s[D] = '#';
            if(check(A, C)) ok = true;
            s[D] = '.';
        }
        if(over)
        {
            if(check(A, C) and check(B, D)) ok = true;
        }
    }
    cout << (ok ? "Yes" : "No") << endl;
    return 0;
}



Measured memory_bytes: 592
#include <iostream>
#include <cmath>
#include <algorithm>

using namespace std;

#define M 1000000007

long long int f(long long int n) {
	if (n == 1) {
		return 1;
	}
	else {
		return n*f(n - 1) % M;
	}
}

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

	if (abs(n - m) <= 1) {
		long long int fn, fm;
		fn = fm = 1;
		for (long long int i = 1; i <= n; i++) {
			fn *= i;
			fn %= M;
		}
		for (long long int j = 1; j <= m; j++) {
			fm *= j;
			fm %= M;
		}
		if (n == m) {
			cout << fn*fm * 2 % M << endl;
		}
		else {
			cout << fn*fm % M << endl;
		}
	}
	else {
		cout << 0 << endl;
	}
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
using namespace std;
  
int main(){
	long N, M;
	cin >> N >> M;
	if(abs(N - M) <= 1){
		long ans = 2 - abs(N - M);
		for(long i = 1; i <= N; i++){
			ans *= i;
			ans %= 1000000007;
		}
		for(long i = 1; i <= M; i++){
			ans *= i;
			ans %= 1000000007;
		}
		cout << ans << endl;
	}else{
		cout << 0 << endl;
	}
}

Measured memory_bytes: 256
#include <iostream>
#include <memory.h>
using namespace std;
const int N = 1e9+7 ;
long long dp[1010][1010];
char a[1010][1010]; 
int r, c ; 
long long solve (int x , int y)
{
	if (x>=r || y>=c || a[x][y]=='#') return 0 ; 
	if (dp[x][y]!=-1) return dp[x][y]; 
	
	if(x==r-1 && y==c-1) return 1 ; 
	
	long long a = solve (x+1,y)%N;
	long long b = solve (x,y+1)%N; 
	return dp[x][y]=(a%N+b%N)%N; 
}
int main() {
	
	memset (dp ,-1, sizeof dp);
	cin>>r>>c ;
	for (int i=0 ; i<r ; ++i)
	for (int j=0 ; j<c ; ++j)
	cin>>a[i][j]; 
	
	long long ans = solve (0,0)%N;
	cout<<ans ; 
	return 0;
}

Measured memory_bytes: 9344
#include<bits/stdc++.h>
#pragma GCC optimize ("-O3")
using namespace std;
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define endl "\n"
#define int long long
using namespace std;
int32_t main()
{
    IOS;
    int n,x,t;
    cin >> n >> x >> t;
    cout << ((n+x-1)/x)*t << "\n";
    return 0;
}

Measured memory_bytes: 3604
import Foundation

var num = readLine()!.split(separator: " ").map{Int($0)!}
var p = 0
if(num[0] >= num[3]){
  p += num[3]
  num[3] = 0
}else{
  p += num[0]
  num[3] -= num[0] + num[1]
}
if(num[3] > 0){
  p -= num[3]
}
print(p)

Measured memory_bytes: 13652
import sys
from itertools import permutations
int1 = lambda x: int(x) - 1

read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(500000)
 
n = int(readline())
p = tuple(map(int1, readline().split()))
q = tuple(map(int1, readline().split()))
 
l = list(permutations(list(range(n))))
 
print(abs(l.index(q) - l.index(p)))

Measured memory_bytes: 8052
def main():
    n, k = map(int, input().split())
    lr = [list(map(int, input().split())) for _ in range(k)]
    dp = [0] * (n + 1)
    dp[1] = 1
    dpsum = [0] * (n + 1)
    dpsum[1] = 1
    mod = 998244353

    for i in range(2, n + 1):
        for j in range(k):
            li = max(i - lr[j][1], 1)
            ri = i - lr[j][0]
            if ri < 0:
                continue
            dp[i] = (dp[i] + dpsum[ri] - dpsum[li - 1]) % mod
        dpsum[i] = dpsum[i - 1] + dp[i]

    print(dp[-1] % mod)


if __name__ == "__main__":
    main()


Measured memory_bytes: 76608
#include <string>
#include <vector>
#include <sstream>
#include <iostream>
#include <algorithm>
#include <map>
#include <list>
#include <set>
#include <numeric>
#include <queue>
#include <stack>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <cstring>
#include <climits>
#include <cfloat>
#include <ctime>
#include <complex>
#include <cassert>
#include <array>
#include <bitset> 
#include <unordered_map>
using namespace std;
typedef long long LL;
typedef pair<LL,LL> P;

const string YES = "YES";
const string NO = "NO";

void solve(long long N, std::vector<long long> A){
	sort(A.begin(),A.end());
	if(unique(A.begin(),A.end())==A.end())
	{
		cout << YES << endl;
	}
	else{
		cout << NO << endl;
	}

}

int main(){
    long long N;
    scanf("%lld",&N);
    std::vector<long long> A(N);
    for(int i = 0 ; i < N ; i++){
        scanf("%lld",&A[i]);
    }
    solve(N, std::move(A));
    return 0;
}


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

int main() {
    int x, y;
    cin >> x >> y;
    vector<int> A = {0, 1, 3, 1, 2, 1, 2, 1, 1, 2, 1, 2, 1};
    cout << (A[x] == A[y] ? "Yes" : "No") << endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <deque>
#define range(i, r) for(int i=0;i<r;i++)
#define ranges(i, l, r) for(int i=l;i<r;i++)
#define vv(a, b, c, d) vector<vector<d> >(a, vector<d>(b, c))
#define vvi std::vector<std::vector<int> >
#define vvl std::vector<std::vector<ll> >
#define MODs 1000000007;
#define MODn 1000000009;
typedef long long int ll;
using namespace std;

int main(int argc, char const *argv[]) {
  int K;
  std::cin >> K;
  std::cout << K/2 * (K/2+K%2) << '\n';
  return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<algorithm>
#include<iomanip>
#include<stack>
#include<queue>
#include<string>
#include<set>
#include<map>
using namespace std;
#define rep(i,n) for(int i=0;(i)<(n);(i)++)
#define FOR(i,m,n) for(int i=(m);(i)<(n);(i)++)
typedef long long ll;

vector<vector<int> > G;

void dfs(int v,int p,vector<int>& depth){
    if(depth[v]!=-1)return;
    if(p!=-1)depth[v]=depth[p]+1;
    else depth[v]=0;
    for(auto x:G[v]){
        dfs(x,v,depth);
    }
}

int main(){
    int N;cin >> N;
    vector<int> d1(N,-1),d2(N,-1);
    G.resize(N);
    rep(i,N-1){
        int a,b;cin >> a >> b;
        a--;b--;
        G[a].push_back(b);
        G[b].push_back(a);
    }
    dfs(0,-1,d1);
    dfs(N-1,-1,d2);
    
    int fe=0,sn=0;
    for(int i=0;i<N;i++){
        if(d1[i]<=d2[i])fe++;
        else sn++;
    }
    /*
    cout << endl;
    cout << fe << " " << sn << endl;
    cout << "dist" << endl;
    rep(i,N){
        cout << d1[i] << " " << d2[i];
        cout << endl;
    }
    */
    if(fe>sn)cout << "Fennec" << endl;
    else cout << "Snuke" << endl;

    return 0;
}

Measured memory_bytes: 11136
#include<iostream>

struct Card{
	char suit = '\0';
	int value = 0;
};
class Stable{
public:

	void bubble_sort(Card *card, int N){
		for(int i = 0; i < N; ++i){
			for(int j = N-1; j > i; --j){
				if(card[j-1].value > card[j].value){
					Card tmp = card[j];
					card[j] = card[j-1];
					card[j-1] = tmp;
				}
			}
		}
		return;
	}

	void selection_sort(Card *card, int N){
		for(int i = 0; i < N; ++i){
			int minj = i;
			for(int j = i; j < N; ++j){
				minj = (card[minj].value > card[j].value) ? j : minj;
			}
			if(i != minj){
				Card tmp = card[i];
				card[i] = card[minj];
				card[minj] = tmp;
			}
		}
		return;
	}

	void isStable(Card *A, Card *B, int N){
		for(int i = 0; i < N; ++i){
			if(A[i].suit != B[i].suit){
				std::cout << "Not stable" << std::endl;
				return;
			}
		}
		std::cout << "Stable" << std::endl;
	}
	void output(Card *card, int N){
		for(int i = 0; i < N; ++i){
			if(i > 0) std::cout << " ";
			std::cout << card[i].suit << card[i].value;
		}
		std::cout << std::endl;
		return;
	}
};

int main(){
	int N;
	Card c_bubble[40];
	Card c_selection[40];
	Stable s;

	std::cin >> N;
	for(int i = 0; i < N; ++i){
		std::cin >> c_bubble[i].suit >> c_bubble[i].value;
		c_selection[i].suit = c_bubble[i].suit;
		c_selection[i].value = c_bubble[i].value;
	}
	s.bubble_sort(c_bubble, N);
	s.output(c_bubble, N);
	std::cout << "Stable" << std::endl;
	s.selection_sort(c_selection, N);
	s.output(c_selection, N);
	s.isStable(c_bubble, c_selection, N);

}



Measured memory_bytes: 3112
// Created by Nandu Vinodan
#include <bits/stdc++.h>

#define db1(x) cout<<#x<<"="<<x<<'\n'
#define db2(x,y) cout<<#x<<"="<<x<<","<<#y<<"="<<y<<'\n'
#define db3(x,y,z) cout<<#x<<"="<<x<<","<<#y<<"="<<y<<","<<#z<<"="<<z<<'\n'
#define rep(i,a,n) for(int i=a;i<=(n);++i)
#define repD(i,a,n) for(int i=a;i>=(n);--i)
#define pb(a) push_back(a)
#define eb(a) emplace_back(a)
#define vi vector<int>
#define pi pair<int, int>
#define INF INT_MAX
#define _INF INT_MIN
#define TC 0

using namespace std;
using ll = long long;

void testcase() {
    ll ans = 0;
    int n; cin >> n;

    rep (i, 1, n) {
    	if (i % 3 == 0 || i%5 == 0) continue;

    	ans = (ans + (ll)i);
    }
    cout << ans;
}

int main() {
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    int t=1;
    if (TC)
        cin>>t;
    while(t--) {
        testcase();
    }
    return 0;
}

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

using namespace std;

int main() {
    int n, t, ans = 0, as;
    cin >> n >> t;
    long long arr[n], sum = 0;
    for (int i = 0; i < n; ++ i) cin >> arr[i];
    sort(arr, arr + n);
    for (int i = 0; i < n - t; ++ i) sum += arr[i];
    cout << sum;
}


Measured memory_bytes: 1792
from collections import Counter

n = int(input())
a_array = [int(x) for x in input().split()]
d = Counter(a_array)
res = 0
for key, value in d.items():
    res += key * value
q = int(input())
bc_array = [[int(x) for x in input().split()] for y in range(q)]
for b, c in bc_array:
    d.setdefault(b, 0)
    res -= b * d[b]
    res += c * d[b]
    print(res)
    d[c] += d[b]
    d[b] = 0

Measured memory_bytes: 38056
#include "bits/stdc++.h"
using namespace std;
using ll = long long;
const int N = 1e5 + 5;
int main(){
  int n;  cin >> n;
  vector<int>v;
  int x;  cin >> x;v.push_back(x);
  for(int i = 0; i < n; i++){
    cin >> x; v.push_back(x);
  }
  sort(v.begin(),v.end());
  int g = v[1] - v[0];
  for(int i = 2; i < v.size(); i++)
    g = __gcd(g, v[i] - v[i-1]);

  cout << g << '\n';

  return 0;
}


Measured memory_bytes: 892
#!/usr/bin/python3

import math
import os
import sys


def main():
    N = read_int()
    A = [tuple(read_ints()) for _ in range(N)]
    print(solve(N, A))


def fact(x):
    f = 1
    while x > 1:
        f *= x
        x -= 1
    return f


def solve(N, A):
    s = 0.0
    f = fact(N)
    e = f * (N - 1) // (N * (N - 1) // 2)
    for i in range(N):
        for j in range(i + 1, N):
            s += math.sqrt((A[j][0] - A[i][0]) ** 2 + (A[j][1] - A[i][1]) ** 2)
    dprint(s, e, f)
    return (e * s) / f


###############################################################################

DEBUG = 'DEBUG' in os.environ


def inp():
    return sys.stdin.readline().rstrip()


def read_int():
    return int(inp())


def read_ints():
    return [int(e) for e in inp().split()]


def dprint(*value, sep=' ', end='\n'):
    if DEBUG:
        print(*value, sep=sep, end=end)


if __name__ == '__main__':
    main()


Measured memory_bytes: 38340
import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner scan = new Scanner(System.in);
        int N, X;
        N = scan.nextInt();
        X = scan.nextInt();
        int [] dif = new int[N];
        for (int i = 0; i < N; i++) {
            dif[i] = Math.abs(scan.nextInt() - X);
        }
        
        int ans = N == 1 ? dif[0] : gcd(dif[1], dif[0]);
        for (int i = 2; i < N; i++) {
            ans = gcd(dif[i], ans);
        }
        System.out.println(ans);
    }
    
    public static int gcd(int a, int b) {
        if (b > 0) {
            return gcd(b, a % b);
        }
        else {
            return a;
        }
    }
}

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

int main (){
	int n,i;
	int a[100005];
	bool zero=true,three=true;
	cin >> n;
	for(i=0;i<n;i++) {
		cin >> a[i];
		if(a[i]!=0) zero=false;
	}
	if(zero){
		cout << "Yes" << endl;
		return 0;
	}
	if(n%3!=0){
		cout << "No" << endl;
		return 0;
	}
	sort(a,a+n);
	for(i=1;i<n;i++){
		if(i!=n/3&&i!=n*2/3){
			if(a[i-1]!=a[i]) three=false;
		}
	}
	int b=(a[0]^a[n/3]);
	if(three&&(b==a[n*2/3])) cout << "Yes" << endl;
	else cout << "No" << endl;
	return 0;
}

Measured memory_bytes: 640
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <vector>
#include <map>
#include <queue>
#include <set>
#include <cmath>
#include <list>
#include <chrono>
#include <thread>

using namespace std;


const bool debug = false;

#ifndef M_PI
    const double M_PI = acos(-1.0);
#endif // M_PI

#define y1 roman_kaban
#define rank oryshych_konb
#define ull unsigned long long
//#define ll long long
const int mod = int(1e9) + 7;
const int inf = 1e9;
//const long long infLL = 1e11;
//const int MX2 = 10100500; //  e7
//const long long INF = 1e18 + 0.5;
const int MX = 200500; //       e5
const int SZ = 1100;
//const int delta = 1 << 19;

int main()
{
    ios_base::sync_with_stdio(false);
    //if(debug)
    //freopen("/Users/ozzy/Documents/in.txt","r", stdin);
    vector<long long> a(3);
    long long s = 0;
    for(int i = 0; i < 3; i++){
        cin >> a[i];
        s += a[i];
    }
    set<vector<long long>> z;
    sort(a.begin(), a.end());
    int cnt = 0;
    while((a[0] & 1) + (a[1] & 1) == 0){
        for(int i = 0; i < 3; i++){
            a[i] = (s - a[i]) / 2;
        }
        sort(a.begin(), a.end());

        if(z.find(a) != z.end()){cout << -1 << endl; return 0;}
        z.insert(a);
        cnt++;
    }
    cout << cnt << endl;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep1(i, n) for (int i = 1; i <= (int)(n); i++)
typedef int64_t Int;

int main(){
    string S; cin >> S;

    if(S[2] == S[3] && S[4]== S[5]){
        cout << "Yes" << endl;
    } else {
        cout << "No" << endl;
    }
}

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

int main(){
  int k;
  int a,b;
  cin>>k;
  cin>>a>>b;
  int flag=0;
  for(int i=a;i<b+1;i++){
    if(i%k==0)flag=1;
  }
  if(flag==0)cout<<"NG"<<endl;
  else cout<<"OK"<<endl;
}


Measured memory_bytes: 3624
#include <bits/stdc++.h>
#include <cmath>
using namespace std;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define REP(i, n) for(int i = 1; i <= (int)(n); i++)
const long long INF = 1LL << 60;
const double PI=3.14159265358979323846;
int main() 
{
    int n;
    cin >> n;

    long long a[1000010],b[1000010];
    rep(i,1000000){
        a[i]=0;
        b[i]=0;
    }

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

    long long sum=0;
    rep(i,1000000){
        sum+=b[i]*(b[i]-1)/2;
    }
    rep(i,n){
        cout << sum-b[a[i]]+1  << endl;
    }

}

Measured memory_bytes: 18176
#include<stdio.h>
#include<string.h>
int MAX(int a,int b){return a<b?b:a;}
//int P[1010],L[1010],R[1010],H[1010],C=1;
int P[4][1010],C=1,H[1010];
//int hyouka(int i,int x){return N[i]<=x?N[i]<x?-1:0:1;}
char N[1010][110];
int hyouka(int i,char *s){return strcmp(N[i],s);}
int h(int a){return H[P[2][a]]-H[P[1][a]];}
void rot(int a,int t){
  int b=P[t][a],r=P[0][a];
  P[t][r]==a?(P[1][r]=b):(P[2][r]=b);
  if(P[3-t][b])P[0][P[3-t][b]]=a;
  P[t][a]=P[3-t][b];
  P[3-t][b]=P[0][b];
  P[0][b]=P[0][a];
  P[0][a]=b;
  H[a]=MAX(H[P[1][a]],H[P[2][a]])+1;
  H[b]=MAX(H[P[1][b]],H[P[2][b]])+1;
}
void make(int p,int t,char *s){
  P[t][p]=C;
  P[0][C++]=p;
  strcpy(N[C],s);
  H[p]=MAX(1,H[p]);
}
int mfind(char *x){
  int i,j,r,n,t;
  if(C==1){
    make(0,1,x);
    return 1;
  }
  for(i=1;r=hyouka(i,x);i=n){
    if(r<0)t=1;
    else   t=2;
    if(P[t][i]==0)make(i,t,x);
    n=P[t][i];
  }//printf("%d\n",i);
  for(j=P[0][i];j;j=P[0][j]){
    if(h(j)<-1){
      if(h(P[1][j])>0)rot(P[1][j],1);
      rot(j,2);
      //break;
    }
    if(h(j)>1){
      if(h(P[2][j])<0)rot(P[2][j],2);
      rot(j,1);
      //break;
    }
    if(h(j)==0)break;
  }//printf("%d\n",i);
  return i;
}      
int main(){
  int i,l,max=0,mj=1,r,a[1010]={};
  char *c,*mi,s[1020];
  fgets(s,1010,stdin);
  mi=strtok(s," \n");
  a[mj=mfind(mi)]++;
  max=strlen(mi);
  // printf("%s\n",mi);
  while(c=strtok(NULL," \n")){
    //printf("%s\n",c);
    a[r=mfind(c)]++;
    //printf("%d\n",r);
    l=strlen(c);//printf("%s %d\n",mi,l);
    if(max<l){
      max=l;
      strcpy(mi,c);
    }//printf("a\n");
    if(a[r]>a[mj])mj=r;//printf("a\n");
  }
  //printf("%s %d\n",mi,mj);
  printf("%s %s\n",N[mj],mi);
  return 0;
}

Measured memory_bytes: 568
package main

import (
	"fmt"
	"strings"
)

func main() {
	var n string
	fmt.Scanf("%s", &n)
	slice := strings.Split(n, "")
	n1 := slice[len(n)-1]
	if n1 == "2" || n1 == "4" || n1 == "5" || n1 == "7" || n1 == "9" {
		fmt.Println("hon")
	} else if n1 == "0" || n1 == "1" || n1 == "6" || n1 == "8" {
		fmt.Println("pon")
	} else {
		fmt.Println("bon")
	}
}


Measured memory_bytes: 1820
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <map>
#include <unordered_map>
#include <set>
#include <queue>
using namespace std;
#define ALL(x) (x).begin(),(x).end()
#define SZ(x) int((x).size())
#define OUT(x) cout << (x) << endl
typedef long long ll;
typedef vector<int> V;
typedef vector<vector<int>> VV;
typedef pair<int, int> P;
typedef map<string, int> M;
typedef unordered_map<int, int> HM;
typedef set<int> S;
typedef multiset<int> MS;
typedef queue<int> Q;

int main(){
    double w,h,x,y; cin>>w>>h>>x>>y;
    if(x+x == w && y+y == h){
        cout << w*h/2 << " " << 1 <<endl;
    }
    else cout << w*h/2 << " " << 0 << endl;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>

int main(){
  int *A;
  int i, v, j, k, e, n, count=0;

  while(1){
    scanf("%d",&n);
    if(n >= 0 && n <= 1000){
      break;
    }
  }

  A = (int *)malloc(n*sizeof(int));
  
    for(i = 0; i < n; i++){
      scanf("%d",&e);
      A[i] = e;
      if(i == n-1) printf("%d",A[i]);
      else printf("%d ",A[i]);
    }

    printf("\n");

    for(i=1; i<n; i++){
      v = A[i];
      j= i-1;
      while(j >=0 && A[j] > v){
	A[j+1] = A[j];
	j--;
      }
      A[j+1] = v;
      for(k = 0; k < n; k++){
	if(k == n-1) printf("%d",A[k]);
	else printf("%d ",A[k]);
      }
      printf("\n");
      count++;
      if(count > 100) break;
    }
    return 0;
}

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

int main() {
  int N,M,X,i,j,ans=-1;
  cin>>N>>M>>X;
  vector<vector<int>> A(N,vector<int>(M+1));
  for(i=0;i<N;i++){
    cin>>A[i][M];//金額
    for(j=0;j<M;j++)cin>>A[i][j];
  }
  for(int tmp=0;tmp<(1<<N);tmp++){
    bitset<12> b(tmp);//買うかどうか
    int nedan=0;
    vector<int> check(M);
    for(i=0;i<N;i++){
      if(b.test(i)){
        nedan+=A[i][M];
        for(j=0;j<M;j++)check[j]+=A[i][j];
      }
    }
    int flag=1;
    for(i=0;i<M;i++)if(check[i]<X){flag=0;break;}
    if(flag){
      if(ans==-1)ans=nedan;
      else ans=min(ans,nedan);
    }
  }
  cout<<ans<<endl;
}


Measured memory_bytes: 3636
#include <iostream>
#include <string>
using namespace std;
int main() {
	int A,B,C,D;
	int E;
	cin >> A  >> B >> C >> D;
	if(A>=B){
		E = B;
	}else{
		E = A;
	}
	if(C<=D){
		E += C;
	}else{
		E += D;
	}
	cout << E << endl;
}



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

int root(int arr[],int i){
    while(arr[i]!=i){
         arr[i]=arr[arr[i]];
        i=arr[i];
    }
    return i;
}
void Union(int arr[],int Size[],int a,int b){
int rootA=root(arr,a);
int rootB=root(arr,b);
if(Size[rootA]<Size[rootB]){
    arr[rootA]=arr[rootB];
    Size[rootB]+=Size[rootA];
}else{
arr[rootB]=arr[rootA];
Size[rootA]+=Size[rootB];
}
}
bool findRoot(int a,int b,int arr[]){
 if(root(arr,a)==root(arr,b))return true;
 else return false;
}
 vector<vector<int> >adj(105);
bool nCyc=false;
/*void dijkstra(int v,long long dis[]){
dis[v]=0;
multiset<pair<int,int> >s;
s.insert({0,v});
while(!s.empty()){
    pair<int,int>p= *s.begin();
    s.erase(s.begin());
    int x=p.second;
  if(vis[x])continue;
    vis[x]=1;
    for(int i=0;i<adj[x].size();i++){
        int e=adj[x][i].first,w=adj[x][i].second;
      //  cout<<dis[e]<<" "<<dis[x]+w<<endl;
        if(dis[e]>dis[x]+w){
            dis[e]=dis[x]+w;
            s.insert(make_pair(dis[e],e));
        }
    }
}
}*/
/*void bfs(int s){
    queue<int>q;
    q.push(s);
    while(!q.empty()){
        int v=q.front();
        q.pop();
        for(int i=0;i<adj[v].size();i++){
            if(!vis[adj[v][i]]){
                 q.push(adj[v][i]);
                 vis[adj[v][i]]=1;
            }
        }
    }
}*/
int vis[55][55];
int dx[4]={1,-1,0,0};
int dy[4]={0,0,1,-1};
/*bool isVal(int i,int j){
      if(i<0 || j<0 || j>=m || i>=n)return false;
      return true;
}*/
/*void dfs(int i,int j) {

    if(!isVal(i,j) || vis[i][j] || arr[i][j]=='#')return;
      vis[i][j]=1;
	  if(arr[i][j]=='G'){
	  check++;
	  }
	  if(arr[i][j]=='B'){
        b=1;
        return;
	  }
	for(int k=0;k<4;k++){
     int pos1=i+dx[k],pos2=j+dy[k];
   //  cout<<pos1<<" "<<pos2<<endl;
     if( isVal(pos1,pos2) && (arr[pos1][pos2]=='#'))continue;
               dfs(pos1,pos2);
	}
}
void dfs2(int i,int j){
 if(isVal(i,j)==false || arr[i][j]!='.')return;
  arr[i][j]='#';
}*/
/*
double prim(int x){
    priority_queue<pair<double,int>,vector<pair<double,int> >,greater<pair<double,int> > >q;
    double min_cost=0.0;
    pair<double,int>p;
     q.push(make_pair(0.0,x));
     while(!q.empty()){
      p=q.top();
      q.pop();
      x=p.second;
      if(vis[x])continue;
      min_cost+=p.first;
      vis[x]=1;
      for(int i=0;i<adj[x].size();i++){
         int y=adj[x][i].second;
         if(!vis[y]){
            q.push(adj[x][i]);
        }
      }
     }
   return min_cost;
}*/
int n,m;
char arr[1005][1005];
int dp[1005][1005];
int solve(int i,int j){
    if(arr[i][j]=='#' || i==n || j==m)return 0;
    if(i==n-1 && j==m-1)return 1;
    if(dp[i][j]!=-1)return dp[i][j];
    int ans=solve(i,j+1)%1000000007;
    ans+=solve(i+1,j)%1000000007;
    return dp[i][j]=ans%1000000007;
}
int freq[200005],check[100005];
int main()
{
    cin>>n>>m;
    memset(dp,-1,sizeof dp);
    for(int i=0;i<n;i++)
        for(int j=0;j<m;j++)
           cin>>arr[i][j];
    cout<<solve(0,0);
return 0;
}


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

template <long long MOD>
struct ModInt {
  using M = ModInt;
  long long v;
  ModInt(long long _v = 0) : v(_v % MOD + MOD) { norm(); }
  M& norm() {
    v = (v < MOD) ? v : v - MOD;
    return *this;
  }
  M operator+(const M& x) const { return M(v + x.v); }
  M operator-(const M& x) const { return M(v + MOD - x.v); }
  M operator*(const M& x) const { return M(v * x.v % MOD); }
  M operator/(const M& x) const { return M(v * x.inv()); }
  M& operator+=(const M& x) { return *this = *this + x; }
  M& operator-=(const M& x) { return *this = *this - x; }
  M& operator*=(const M& x) { return *this = *this * x; }
  M& operator/=(const M& x) { return *this = *this / x; }
  friend istream& operator>>(istream& input, M& x) {
    input >> x.v, x.norm();
    return input;
  }
  friend ostream& operator<<(ostream& output, const M& x) {
    return output << x.v;
  }
  M pow(long long n) const {
    M x(v), res(1);
    while (n) {
      if (n & 1) res *= x;
      x *= x;
      n >>= 1;
    }
    return res;
  }
  M inv() const { return this->pow(MOD - 2); }

  static vector<M> fact, finv;
  static void build(int n) {
    fact.assign(n + 1, 1);
    finv.assign(n + 1, 1);
    for (int i = 1; i < n + 1; i++) fact[i] = fact[i - 1] * M(i);
    for (int i = 0; i < n + 1; i++) finv[i] = fact[i].inv();
  }
  static M comb(int n, int k) {
    if (n < k || k < 0) return M(0);
    return fact[n] * finv[n - k] * finv[k];
  }
};
template <long long MOD>
vector<ModInt<MOD>> ModInt<MOD>::fact = vector<ModInt<MOD>>();
template <long long MOD>
vector<ModInt<MOD>> ModInt<MOD>::finv = vector<ModInt<MOD>>();
using mint = ModInt<(long long)(1e9 + 7)>;

int main() {
  mint m;
  int n;
  cin >> m >> n;
  cout << m.pow(n) << endl;
}



Measured memory_bytes: 3108
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cctype>
#include <climits>
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <string>
#include <sstream>
#include <vector>
#include <map>
#include <set>
#include <complex>
#include <functional>
#include <utility>
#include <iterator>

#define REP(i, n) for(int i = 0; i < (int)(n); ++i)
#define FOR(i, m, n) for(int i = (m); i < (int)(n); ++i)
#define ALL(x) (x).begin(), (x).end()
#define INF 2000000000

#ifdef LOCAL
  #define dprintf(...) fprintf(stdout, __VA_ARGS__)
#else
  #define dprintf(...) 0
#endif

using namespace std;

typedef long long LL;
typedef unsigned long long ULL;
typedef unsigned int uint;

//const double PI = 3.1415926535897932384626433832795;

int main() {
  ULL a;
  string b_str;
  cin >> a >> b_str;
  b_str.erase(1, 1);
  int b100 = stoi(b_str);
  ULL ans = a * b100 / 100;
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 3608
#include<iostream>
using namespace std;
int main()
{
    int x,y,c,t;
    cin>>x>>y;
    c=(4*x-y)/2;
    t=(y-2*x)/2;
    if(y%2!=0||x*4<y||x*2>y)
    {
        cout<<"No";
    }
    else{
        cout<<"Yes";
    }
    return 0;
}


Measured memory_bytes: 3128
#!python3

iim = lambda: map(int, input().rstrip().split())

def resolve():
    A, B, C = iim()

    ans = (A == B) + (B == C) + (C == A)

    if ans == 3 or ans == 0:
        print("No")
    else:
        print("Yes")

if __name__ == "__main__":
    resolve()


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

namespace AtCorder
{
	public class Program
	{
		static void Main(string[] args)
		{
			Scanner cin = new Scanner();
			int n = cin.Int();
			int[] h = cin.ArrayInt(n);
			int ans = 0;
			int cnt = 0;
			for (int i = 1; i < n; i++) {
				if (h[i] <= h[i - 1]) {
					++cnt;
				} else {
					ans = Math.Max(ans, cnt);
					cnt = 0;
				}
			}

			ans = Math.Max(ans, cnt);
			Console.WriteLine(ans);
		}
	}

	public class Scanner
	{
		private readonly char[] delimiter_ = new char[] { ' ' };
		private string[] buf_;
		private int index_;

		public Scanner()
		{
			buf_ = new string[0];
			index_ = 0;
		}

		public string Next()
		{
			if (index_ < buf_.Length) {
				return buf_[index_++];
			}

			string st = Console.ReadLine();
			while (st == "") {
				st = Console.ReadLine();
			}

			buf_ = st.Split(delimiter_, StringSplitOptions.RemoveEmptyEntries);
			if (buf_.Length == 0) {
				return Next();
			}

			index_ = 0;
			return buf_[index_++];
		}

		public int Int()
		{
			return int.Parse(Next());
		}
		public int[] ArrayInt(int N, int add = 0)
		{
			int[] Array = new int[N];
			for (int i = 0; i < N; i++) {
				Array[i] = Int() + add;
			}
			return Array;
		}

		public long Long()
		{
			return long.Parse(Next());
		}

		public long[] ArrayLong(int N, long add = 0)
		{
			long[] Array = new long[N];
			for (int i = 0; i < N; i++) {
				Array[i] = Long() + add;
			}
			return Array;
		}

		public double Double()
		{
			return double.Parse(Next());
		}

		public double[] ArrayDouble(int N, double add = 0)
		{
			double[] Array = new double[N];
			for (int i = 0; i < N; i++) {
				Array[i] = Double() + add;
			}
			return Array;
		}
	}
}

Measured memory_bytes: 29152
#include<bits/stdc++.h>
using ll=long long;
using namespace std;
#define rep(i, n) for(ll i=0; i<n; i++)
#define Rep(i, j, n) for(ll i=j; i<n; i++)
#define all(vec) vec.begin(), vec.end()
template<class T> inline bool chmin(T& a, T b) {if(a > b) {a = b; return true;} return false;}
template<class T> inline bool chmax(T& a, T b) {if(a < b) {a = b; return true;} return false;}
int dh[4] = {-1, 0, 0, 1};
int dw[4] = {0, -1, 1, 0}; 
using P = pair<int, int>;
const double pi = acos(-1.0);

int main(){
  int a,b;
  cin>>a>>b;
  int ans;
  ans=10*b;
  Rep(i,ans,ans+10){
    if(i*8/100==a){cout<<i<<endl;return 0;}
  }
  cout<<-1<<endl;
    
    
  return 0;
}


Measured memory_bytes: 3604
#include <iostream>

using namespace std;

int main()
{
   int n,count_1=0,count_2=0;
   cin >> n;
   //cout << n;
   //cout << count_1<<endl;
   //cout << count_2<<endl;
   count_1 = n/500;
   //cout << count_1<<endl;
   n = n%500;
   //cout << n<<endl;
   count_2 = n/5;
   //cout << count_2<<endl;
   cout << count_1*1000 + count_2*5;
   
   return 0;
}

Measured memory_bytes: 256
// https://atcoder.jp/contests/agc032/tasks/agc032_b
#include <bits/stdc++.h>
using namespace std;
using pii = pair<int, int>;

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n;
    cin >> n;
    vector<pii> v;
    if (n % 2 == 1) {
        // 五角形のノード 5 は「全部」
        for (int i = 1; i < n; i++) {
            v.push_back({i, n});
        }
    }
    for (int i = 1; i <= (n / 2 * 2); i++) {
        for (int j = i + 1; j <= (n / 2 * 2); j++) {
            // 四角形のノード 1 は「4 以外」
            // 五角形のノード 1 は「4 以外」
            if (i + j != n + (n + 1) % 2) {
                v.push_back({i, j});
            }
        }
    }
    cout << v.size() << "\n";
    for (auto &x : v) {
        cout << x.first << " " << x.second << "\n";
    }

    return 0;
}


Measured memory_bytes: 384
#include <cstdint>
#include <iostream>

using namespace std;

uint64_t gcd(uint64_t a, uint64_t b)
{
  if (b == 0) {
    return a;
  }

  return gcd(b, a % b);
}

int32_t main()
{
  uint64_t N;
  cin >> N;

  uint64_t l = 1;
  for (uint64_t i = 0; i < N; i++) {
    uint64_t val;
    cin >> val;
    l = l / gcd(l, val) * val;
  }

  cout << l << endl;

  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#include<math.h>
using namespace std;
int main()
{
  int k=0;
  cin>>k;
  string a="ACL"; 
   string c=a+a;
  for(int i=0;i<k;i++){
c=c+a;
cout<<a;
  }
  
  return 0;
}

Measured memory_bytes: 3624
from collections import defaultdict
from collections import deque
import itertools
import math

def readInt():
  return int(input())
def readInts():
  return list(map(int, input().split()))
def readChar():
  return input()
def readChars():
  return input().split()

n,a,b = readInts()
print(max(0,(b-a)*(n-2)+1))

Measured memory_bytes: 9372
N,C,K = map(int,input().split())
T = [int(input()) for i in range(N)]
T.sort()
s = 0
e = T[0]+K
p = 0
ans = 0
for i in range(N):
    if p == C or e < T[i]:
        ans += 1
        s = T[i]
        e = T[i]+K
        p = 0
    s = max(s,T[i])
    e = min(e,T[i]+K)
    p += 1
print(ans+1)



Measured memory_bytes: 7488
#include <bits/stdc++.h>
using namespace std;
int calc(int x) {
  int count = 0;
  while(x%100 == 0) {
	x /= 100;
	count++;
  }
  return count;
}
int main() {
	int d,n;
	cin >> d >> n;
	int count=0,t=0;
	while(count < n) {
      t++;
	  if(calc(t) == d) {
        count++;
      }
	}
	cout << t << endl;
	return 0;
}

Measured memory_bytes: 256
#include<iomanip>
#include<limits>
#include<thread>
#include<utility>
#include<iostream>
#include<string>
#include<algorithm>
#include<set>
#include<map>
#include<vector>
#include<stack>
#include<queue>
#include<cmath>
#include<numeric>
#include<cassert>
#include<random>
#include<chrono>
#include<unordered_set>
#include<unordered_map>
#include<fstream>
#include<list>
#include<functional>
#include<bitset>
#include<complex>
#include<tuple>
using namespace std;
typedef unsigned long long int ull;
typedef long long int ll;
typedef pair<ll,ll> pll;
typedef long double D;
#define F first
#define S second
const ll E=1e18+7;
const ll MOD=1000000007;


template<typename T,typename U>istream & operator >> (istream &i,pair<T,U> &A){i>>A.F>>A.S; return i;}
template<typename T>istream & operator >> (istream &i,vector<T> &A){for(auto &I:A){i>>I;} return i;}
template<typename T,typename U>ostream & operator << (ostream &o,pair<T,U> &A){o<<A.F<<" "<<A.S; return o;}
template<typename T>ostream & operator << (ostream &o,vector<T> &A){ll i=A.size(); for(auto &I:A){o<<I<<(--i?" ":"");} return o;}
template<typename T>vector<T> & cset(vector<T> &A,T e=T()){for(auto &I:A){I=e;} return A;}




int main(){
    ll n,m;
    cin>>n>>m;
    vector<vector<ll>> edge(n);
    vector<pair<pll,ll>> A(m);
    vector<ll> cost(m,E);
    vector<pair<bool,bool>> used(m,{false,false});
    cin>>A;
    for(int i=0;i<m;i++){
        auto &I=A[i];
        I.F.F--; I.F.S--;
        edge[I.F.F].push_back(i);
        edge[I.F.S].push_back(i);
    }
    for(auto &I:edge){sort(I.begin(),I.end(),[&](ll a,ll b){return A[a].S<A[b].S;});}
    deque<pll> D;
    vector<ll> dp(n,E);
    dp[0]=0;
    D.push_back({0,dp[0]});
    
    auto func=[&](ll w,ll e){
        auto I=lower_bound(edge[w].begin(),edge[w].end(),e,[&](ll a,ll b){return A[a].S<A[b].S;});
        while(I!=edge[w].end() && A[*I].S==A[e].S){
            if(cost[*I]>cost[e]){
                cost[*I]=cost[e];
                D.push_front({n+*I,cost[e]});
            }
            if(A[*I].F.F==w){used[*I].F=true;}
            if(A[*I].F.S==w){used[*I].S=true;}
            ++I;
        }
    };
    
    while(!D.empty()){
        pll W=D.front(); D.pop_front();
        ll w=W.F;
        //cout<<w<<endl;
        if(w<n){
            if(dp[w]!=W.S){continue;}
            for(auto &I:edge[w]){
                if(cost[I]>dp[w]+1){cost[I]=dp[w]+1; D.push_back({n+I,dp[w]+1});}
            }
        }
        else{
            w-=n;
            if(cost[w]!=W.S){continue;}
            if(dp[A[w].F.F]>cost[w]){
                dp[A[w].F.F]=cost[w];
                D.push_front({A[w].F.F,dp[A[w].F.F]});
            }
            if(dp[A[w].F.S]>cost[w]){
                dp[A[w].F.S]=cost[w];
                D.push_front({A[w].F.S,dp[A[w].F.S]});
            }
            if(!used[w].F){
                func(A[w].F.F,w);
            }
            if(!used[w].S){
                func(A[w].F.S,w);
            }
        }
    }
    //cout<<dp<<endl<<cost<<endl;
    cout<<(dp.back()==E?-1LL:dp.back())<<endl;
    
    
    return 0;
}


Measured memory_bytes: 18560
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import accumulate, permutations, combinations, product
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left
from fractions import gcd
from heapq import heappush, heappop
from functools import reduce
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def ZIP(n): return zip(*(MAP() for _ in range(n)))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7

N = INT()
lim = N+10  # 必要そうな階乗の限界を入れる
fact = [1] * (lim+1)
fact_inv = [1] * (lim+1)
for n in range(1, lim+1):
    fact[n] = (fact[n-1] * n) % mod
fact_inv[lim] = pow(fact[lim], mod-2, mod)
for n in range(lim, 0, -1):
    fact_inv[n-1] = (n * fact_inv[n]) % mod

tree = [[] for _ in range(N+1)]  # 1-indexed
for _ in range(N-1):
	a, b = MAP()
	tree[a].append(b)
	tree[b].append(a)

root = 1
parent = [0]*(N+1)
order = []
stack = [root]
while stack:
    x = stack.pop()
    order.append(x)
    for y in tree[x]:
        if y == parent[x]:
            continue
        parent[y] = x
        stack.append(y)

size_d = [0]*(N+1)
dp_d = [1]*(N+1)

for v in order[::-1]:  # 根に遠いほうから(down方向のボトムアップ)
    dp_d[v] *= fact[size_d[v]]
    dp_d[v] %= mod
    p = parent[v]
    s = size_d[v] + 1
    size_d[p] += s
    dp_d[p] *= fact_inv[s] * dp_d[v]
    dp_d[p] %= mod

size_u = [N-1-x for x in size_d]
dp_u = [1]*(N+1)

def merge(p1, p2):
    den_inv1, v1 = p1
    den_inv2, v2 = p2
    return den_inv1*den_inv2%mod, v1*v2%mod

for v in order:
    p = parent[v]
    arr = [(fact_inv[size_d[node]+1], dp_d[node]) if node != p else (fact_inv[size_u[v]], dp_u[v]) for node in tree[v]]
    left = [(1, 1)] + list(accumulate(arr, merge))[:-1]
    right = list(accumulate(arr[::-1], merge))[-2::-1] + [(1, 1)]
    contrib = [merge(x, y) for x, y in zip(left, right)]
    for node, c in zip(tree[v], contrib):
        if node != p:
            dp_u[node] = (c[0]*c[1]*fact[size_u[node]-1])%mod
# print(dp_u)
for xd, xu, sd, su in zip(dp_d[1:], dp_u[1:], size_d[1:], size_u[1:]):
    x = xd * xu * fact[sd + su] * fact_inv[sd] * fact_inv[su] % mod
    print(x)


Measured memory_bytes: 140272
N = int(input())
S = input()
c = S.count("E") - S.startswith("E")
ans = c
for i in range(N-1):#リーダーをsの右のヤツに変える
    s = S[i]
    if i<N-1 and S[i+1] == "E":
        c -= 1
    if s == "W":
        c += 1
    ans = min(c,ans)
print(ans)

Measured memory_bytes: 43120
//fault: valL + valR is overcounting, only do valL or valR

//my idea is, find nearest left position(x) of smaller value from i, then value[i]+=valueLeft[x], value[i]+=valueRight[i], and
//value[i]+=(posRight[i]-posLeft[i]-1)*i;
//implementation error
#include<bits/stdc++.h>
#define ll long long
#define F first
#define S second
#define mod 1000000007
using namespace std;
typedef pair<ll,ll> ii;

ll valR[200010];
ll valL[200010];
ll val[200010];
ll pos[200010];
ll a[200010];
ll cntTwice[200010];
set<ii> s;
set<ii>::iterator it;
set<ii>::iterator it1;
set<ii>::iterator it2;

int main()
{
    ll i,j,k,l;
    ll n;
    cin>>n;
    for(i=1;i<=n;i++)
    {
        cin>>a[i];
        pos[a[i]]=i;
    }

    for(i=1;i<=n;i++)
    {
        ll x,y;
        ii z={pos[i],i};
        s.insert(z);
        it=s.find(z);
        if(it==s.begin())
        {
            valL[i]=pos[i]*i;
        }
        else
        {
            it1=it;it1--;
            valL[i]=i*(pos[i]-it1->F) + valL[it1->S];
        }

//        it2=it;
//        it2++;
//        if(it2==s.end())
//        {
//            valR[i]=(n-pos[i]+1)*i;
//        }
//        else
//        {
//            valR[i]=i*(n-pos[i]) + valR[it2->S];
//        }

    }

    ll ans=0;
    for(i=1;i<=n;i++)
    {
        ans+=valL[i];
//        ans+=valL[i]+valR[i]-i;
//        cout<<valL[i]<<' '<<valR[i]<<' '<<'\n';
    }

    cout<<ans;
}




//3
//2 1 3



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

using namespace std;

typedef long long int ll;
typedef unsigned long long int ull;
typedef vector<int> vii;
typedef vector<ll> vll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;

#define pb push_back
#define odd(x) ((x)&1)
#define even(x) (!odd(x))
#define ff it->first
#define ss it->second
#define all(v) (v).begin(),(v).end()
#define rep(i,n) for(auto i=0;i<n;++i)
#define LOOP_IT(it,s) for(auto it=(s).begin();it!=(s).end();++it)
#define FASTIO ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define TEST_CASE int tc;cin>>tc;while(tc--)


#ifdef LOCAL
#define cerr cout
#else
#endif

#define TRACE

#ifdef TRACE
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
    cerr << name << " : " << arg1 << std::endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
    const char* comma = strchr(names + 1, ',');cerr.write(names, comma - names) << " : " << arg1<<" | ";__f(comma+1, args...);
}
#else
#define trace(...)
#endif


void __print(int x) {cerr << x;}
void __print(long x) {cerr << x;}
void __print(long long x) {cerr << x;}
void __print(unsigned x) {cerr << x;}
void __print(unsigned long x) {cerr << x;}
void __print(unsigned long long x) {cerr << x;}
void __print(float x) {cerr << x;}
void __print(double x) {cerr << x;}
void __print(long double x) {cerr << x;}
void __print(char x) {cerr << '\'' << x << '\'';}
void __print(const char *x) {cerr << '\"' << x << '\"';}
void __print(const string &x) {cerr << '\"' << x << '\"';}
void __print(bool x) {cerr << (x ? "true" : "false");}


template<typename T, typename V>
void __print(const pair<T, V> &x) {cerr << '{'; __print(x.first); cerr << ','; __print(x.second); cerr << '}';}
template<typename T>
void __print(const T &x) {int f = 0; cerr << '{'; for (auto &i: x) cerr << (f++ ? "," : ""), __print(i); cerr << "}";}
void _print() {cerr << "]\n";}
template <typename T, typename... V>
void _print(T t, V... v) {__print(t); if (sizeof...(v)) cerr << ", "; _print(v...);}
#ifndef ONLINE_JUDGE
#define debug(x...) cerr << "[" << #x << "] = ["; _print(x)
#else
#define debug(x...)
#endif



int main(int argv, char* argc[])
{
    FASTIO

    int mp[200]={};
    int x,n;
    cin>>x>>n;
    vii v(n);
    rep(i,n)
    {cin>>v[i];mp[v[i]]=1;}
    int d = 2e9,ind;

    for(int i=-1;i<300;++i)
    {
        if(mp[i]) continue;
        if(abs(i-x)<d)
        {
            d = abs(i-x);
            ind = i;
        }
    }

    cout<<ind;




    return 0;
}


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

int main(){
    int n, t;
    cin >> n >> t;
    int s[n];
    int ans = t;
    rep(i,n){
        cin >> s[i];
        if(i >= 1){
            if(s[i] - s[i-1] <= t) ans += s[i] - s[i-1]; 
            else ans += t; 
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 1024
from scipy.misc import comb
N, A, B = map(int, input().split())
V = sorted(list(map(int, input().split())), reverse=True)

ans1 = sum(V[:A]) / A
ans2 = 0

V_Ath = V[A - 1]
V_Ath_CNT = V.count(V_Ath)
V_than_Ath_CNT = len([v for v in V if v > V_Ath])

if max(V) == V_Ath:
    for n in range(A, B + 1):
        ans2 += comb(V_Ath_CNT, n, 1)
else:
    ans2 = comb(V_Ath_CNT, A - V_than_Ath_CNT, 1)

print(ans1)
print(ans2)


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

int main () {
    int n, k;
    cin >> n >> k;
    int h, count = 0;
    for (int i=0; i<n; i++) {
        cin >> h;
        if (h >= k) {
            count += 1;
        }
    }
    cout << count << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#include<vector>
#include<list>
#include<stack>
#include<queue>
#include<algorithm>
using namespace std;

/**
 * vector<int>ar(3);
 * for(auto&e:ar){
 *     scanf("%d",&e);
 * }
 * sort(ar.begin(),ar.end())
 * int sum=accumulate(ar.begin(),ar.end(),0);
 **/


int insertionSort(int l[],int x){
    for (int i=0;i<x;i++){
        int v=l[i];
        int j=i-1;
        while (j>=0 && l[j]>v) {
            l[j+1]=l[j];
            j--;
        }
        l[j+1]=v;
        for (int p=0;p<x-1;p++) {
            printf("%d ",l[p]);
        }
        printf("%d\n",l[x-1]);
    }
    return 0;
}


int main(){
    int mod=1000000007;
    int n;
    scanf("%d",&n);
    int a[n];
    for (int i=0;i<n;i++) {
        scanf("%d ",&a[i]);
    }
    insertionSort(a,n);
    return 0;
}

Measured memory_bytes: 3208
N=int(input())
L={}
cnt = 0
for i in range(2, N+1):
    X=i
    f = 0
    while f == 0:
        for j in range(2, X+1):
            if X % j == 0:
                if j in L:
                    L[j]=L[j]+1
                else:
                    L[j]=1
                X=int(X/j)
                if X==1:
                    f = 1
                break

C75 = 0
C25 = 0
C15 = 0
C5 = 0
C3 = 0
for i in L.values():
    if i >= 74:
        C75 += 1
    if i >= 24:
        C25 += 1
    if i >= 14:
        C15 += 1
    if i >= 4:
        C5 += 1
    if i >= 2:
        C3 += 1
cnt = C75
cnt += C25 * (C3-1)
cnt += C15 * (C5-1)
cnt += int(C5 * (C5-1) / 2 * (C3-2))
print(cnt)
# 3 5 15 25 75
# 3 * 5 * 5


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


void swap ( int *x, int *y){
  int temp;

  temp = *x;
  *x = *y;
  *y = temp;
}

int partition ( int array[], int left, int right) {
  int i, j, pivot;

  i = left;
  j = right + 1;
  pivot = left;


  do {
    do { i++; } while (array[i] < array[pivot]);
    do { j--; } while (array[pivot] < array[j]);

    if (i < j) {swap(&array[i], &array[j]);}

  }while( i < j);

  swap(&array[pivot], &array[j]);

  return j;
}

void quick_sort (int array[], int left, int right) {
  int pivot;
  if ( left < right) {
    pivot = partition(array, left, right);
    quick_sort(array, left, pivot - 1);
    quick_sort(array, pivot + 1, right);
  }
}
int main( void ) {
  int number;
  int middle_number;
  int d[100000];

  cin >> number;
  for (int i = 0; i < number; ++i) cin >> d[i];
  quick_sort(d, 0, number);
  middle_number = number / 2;
  cout << d[middle_number + 1] - d[middle_number] << endl;
}

Measured memory_bytes: 640
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;

/**
 * @author yoshizaki
 *
 */
public class Main {
    public static void main(String[] args) {
        Scanner scanner= new Scanner(System.in);
        int people = Integer.parseInt(scanner.nextLine());
        List<Integer> position = new ArrayList<Integer>();
        for(int i = 0; i < people; i++) {
            position.add(scanner.nextInt());
        }
        long venue = Math.round(Double.valueOf(position.stream().mapToInt(m -> m.intValue()).average().getAsDouble()));
        long stamina = 0;
        for(long i: position) {
            stamina = stamina + (i-venue)*(i-venue);
        }
        System.out.println(stamina);
    }
}


Measured memory_bytes: 28884
import java.util.*;

public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		int H = sc.nextInt();
		int W = sc.nextInt();
		char[][] weater = new char[H][W];
		int[][] area = new int[H][W];
		int i, j, time;
		for(i=0; i<H; i++)weater[i] = sc.next().toCharArray();
		for(i=0; i<H; i++){
			time = -1;
			for(j=0; j<W; j++){
				if(weater[i][j] == 'c'){
					time = 0;
					area[i][j] = time;
					time++;
				}
				else if(time >= 0){
					area[i][j] = time;
					time++;
				}
				else if(time < 0)area[i][j] = time;
			}
		}
		for(i=0; i<H; i++){
			for(j=0; j<W; j++){
				if(j == W-1)System.out.println(area[i][j]);
				else System.out.print(area[i][j]+" ");
			}
		}
	}

}

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

#undef _P
#define _P(...) (void)printf(__VA_ARGS__)
#define FOR(x,to) for(x=0;x<(to);x++)
#define FORR(x,arr) for(auto& x:arr)
#define ITR(x,c) for(__typeof(c.begin()) x=c.begin();x!=c.end();x++)
#define ALL(a) (a.begin()),(a.end())
#define ZERO(a) memset(a,0,sizeof(a))
#define MINUS(a) memset(a,0xff,sizeof(a))
//-------------------------------------------------------


int K,Q;
int D[5050],E[5050];
ll N,X,M,S;

void solve() {
	int i,j,k,l,r,x,y; string s;
	
	cin>>K>>Q;
	FOR(i,K) cin>>D[i];
	while(Q--) {
		cin>>N>>X>>M;
		ll S=0;
		ll num0=0;
		FOR(i,K) {
			E[i]=D[i]%M;
			S+=E[i];
			if(E[i]==0) num0++;
		}
		ll Y=X+(N-1)/K*S;
		num0*=(N-1)/K;
		FOR(i,(N-1)%K) {
			Y+=E[i];
			if(E[i]==0) num0++;
		}
		ll rev=(Y/M-X/M);
		cout<<N-1-rev-num0<<endl;
		
	}
}


int main(int argc,char** argv){
	string s;int i;
	if(argc==1) ios::sync_with_stdio(false), cin.tie(0);
	FOR(i,argc-1) s+=argv[i+1],s+='\n'; FOR(i,s.size()) ungetc(s[s.size()-1-i],stdin);
	cout.tie(0); solve(); return 0;
}


Measured memory_bytes: 384