akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
#define ll long long
#define f first
#define s second
#define pb push_back
#define mp make_pair
#define pii pair<int,int>
#define pll pair<ll,ll>
#define vii vector<pii>
#define vll vector<pll>
#define all(v) v.begin(),v.end()
#define mem(v,x) memset(v,x,sizeof(v))
#define N 100005

using namespace std;

int main(){
	ios_base::sync_with_stdio(0);
	cin.tie(NULL);
	int n;
	cin>>n;
	ll a[n+1];
	ll pre[n+1] = {0};
	for(int i=1;i<=n;i++){
        cin>>a[i];
        pre[i] = pre[i-1] + a[i];
	}
	ll dp[n+1][n+1];
	mem(dp,0);
	for(int i=1;i<n;i++){
        for(int j=1;j+i<=n;j++){
            ll val = LLONG_MAX;
            for(int k=j;k<i+j;k++){
                val = min(val, dp[j][k] + dp[k+1][i+j] + pre[i+j]-pre[j-1]);
            }
            dp[j][i+j] = val;
        }
	}
	cout<<dp[1][n];
	return 0;
}


Measured memory_bytes: 1536
#include <algorithm>
#include <iostream>
#include <cstdlib>
#include <cstring>
#include <cstdio>
#include <cmath>
#define RG register
#define il inline
#define iter iterator
#define Max(a,b) ((a)>(b)?(a):(b))
#define Min(a,b) ((a)<(b)?(a):(b))
using namespace std;
typedef long long ll;
const int N=100005;
int n,a[N],head[N],nxt[N<<1],to[N<<1],num=0;bool v[N],flag=1,mark[N];
il void link(int x,int y){nxt[++num]=head[x];to[num]=y;head[x]=num;}
il void dfs(int x,int last){
	if(mark[x] && (v[x]^(a[x]&1))){flag=0;return ;}
	for(int i=head[x];i;i=nxt[i]){
		int u=to[i];if(u==last)continue;
		v[u]=v[x]^1;dfs(u,x);
	}
}

int L[N],R[N];
il void dfs2(int x,int last){
	if(mark[x])L[x]=R[x]=a[x];
	else L[x]=-2e8,R[x]=2e8;
	for(int i=head[x];i;i=nxt[i]){
		int u=to[i];if(u==last)continue;
		dfs2(u,x);
		L[x]=Max(L[x],L[u]-1);
		R[x]=Min(R[x],R[u]+1);
	}
	if(L[x]>R[x])flag=0;
}

il void dfs3(int x,int last){
	for(int i=head[x];i;i=nxt[i]){
		int u=to[i];if(u==last)continue;
		a[u]=a[x]+(a[x]+1<=R[u]?1:-1);
		dfs3(u,x);
	}
}

void work()
{
	int x,y;
	scanf("%d",&n);
	for(int i=1;i<n;i++){
		scanf("%d%d",&x,&y);
		link(x,y);link(y,x);
	}
	int Q;cin>>Q;
	for(int i=1;i<=Q;i++){
		scanf("%d%d",&x,&y);
		a[x]=y;mark[x]=1;
	}
	for(int i=1;i<=n;i++){
		if(!mark[i])continue;
		v[i]=a[i]&1;dfs(i,i);
		break;
	}
	if(!flag){puts("No");return ;}
	dfs2(1,1);
	if(!flag){puts("No");return ;}
	L[1]+=((L[1]&1)^v[1]);
	a[1]=L[1];
	dfs3(1,1);
	puts("Yes");
	for(int i=1;i<=n;i++)printf("%d\n",a[i]);
}

int main()
{
	work();
	return 0;
}


Measured memory_bytes: 7040
#include <iostream>
#include <algorithm>
#include <vector>
#include <math.h>
#include <stdio.h>
#include <functional>
#include <string>
#include <cstdlib>
#include <numeric>
#include <cstdbool>
#include <map> 
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; }

const long long INF = 1LL << 60;
int main()
{
	int N, a, b;cin >> N >> a >> b;
	string name;
	int i = 0;
	for (i = 1;i<1000;i++) {
		if (i % 2 == 1) {
			a++;
			if (a == b) {
				name = "Borys";
				break;
			}
		}
		else {
			b--;
			if (a == b) {
				name = "Alice";
				break;
			}
		}
		if (a == b) {
			break;
		}
	}
	cout << name << endl;
}


Measured memory_bytes: 256
n,q = map(int, input().split())
s = input()
td=[list(map(str,input().split())) for i in range(q)]

def solve(ind):
    for tmp in td:
        if tmp[0] == s[ind]:
            if tmp[1]=="R":
                ind+=1
            else:
                ind-=1
            if ind < 0: # fall left
                return -1
            if len(s) <= ind : # fall right
                return 1
    return 0 # dont fall

l=0
r=len(s)
while r-l>1:
    mid=(l+r)//2

    if solve(mid)>=0:
        r=mid
    else:
        l=mid
ans=r

l=0
r=len(s)
while r-l>1:
    mid=(l+r)//2

    if solve(mid)<=0:
        l=mid
    else:
        r=mid
ans+=(len(s)-r)
print(n-ans)

Measured memory_bytes: 93388
#include <bits/stdc++.h>
using namespace std;
#define int long long
//using lint =long long;

signed main(){
	int h,w,n;cin>>h>>w>>n;
	map<pair<int,int>,int>cnt;
	for(int i=0;i<n;i++){
		int x,y;
		cin >>x>>y;	
	for(int j=0;j<3;j++){
	for(int k=0;k<3;k++){
		int x0,y0;
		x0=x-j;y0=y-k;
		if(1<=x0 && x0+2<=h && 1<=y0 && y0+2<=w)
        {pair<int,int> z=make_pair(x0,y0);
        cnt[z]++;}
      
	}
	}
	}
	vector<int>ans(10,0);
	for(auto&& w:cnt){
		ans[w.second]++;
	}
	
	int tmp=accumulate(begin(ans),end(ans),0ll);
	ans[0]=(h-2)*(w-2)-tmp;
	for(auto&& w:ans)cout<<w<<endl;

}


Measured memory_bytes: 56448
"use strict";
function main(input) {
    const args = input.split(" ");

    const A = parseInt(args[0]);
    const B = parseInt(args[1]);
    const T = parseInt(args[2]);

    const count = Math.floor(T/A);

    console.log(count * B);
}
main(require("fs").readFileSync("/dev/stdin", "utf8"));


Measured memory_bytes: 22076
#include <bits/stdc++.h>
using namespace std;
#define ff first
#define ss second
using ll = long long; using ld = long double; const char nl = '\n';
/* -*- -*- -*- -*- -*- -*- -*- -*- -*- -*- -*- -*- -*- -*- -*- -*- -*- -*- -*- -*- -*- -*- -*- */

#include <bits/extc++.h>
namespace pbds =  __gnu_pbds;
template <typename key, typename val=pbds::null_type, typename comp=less<key>>
using ostree=pbds::tree<key,val,comp,pbds::rb_tree_tag,pbds::tree_order_statistics_node_update>;
using vi = vector< int >; using vll = vector< ll >;
#define all(x) std::begin(x), std::end(x)
mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());
template <typename...Args, template<typename...> typename T> string to_string(T<Args...> const&);
string to_string(string const&s){return '"'+s+'"';}
string to_string(char const &c) {return to_string(string(1,c));}
string to_string(char const *c) {return to_string(string(c));}
string to_string(bool const &b) {return (b ? "T" : "F");}
template<typename... Args> string to_string(pair<Args...> const&p)
{return "("+to_string(p.first)+", "+to_string(p.second)+")";}
template <typename...Args, template<typename...> typename T> string to_string(T<Args...> const&S)
{string s = "{"; for(auto const& e: S)s+=" "+to_string(e);s+=" }"; return s;}
template<typename Tail> void debug_out(Tail t) {cerr<<" "<<to_string(t)<<" ]"<<endl;}
template<typename Head, typename... Tail> void debug_out(Head h, Tail... t)
{cerr << " " << to_string(h) << ","; debug_out(t...);}
#define pr(...) cerr<<"["<<(#__VA_ARGS__)<<"] : [", debug_out(__VA_ARGS__)
template <typename T> void dbr(T lb, T ub)
{cerr<<'{';for(auto it=lb; it!=ub; it++)cerr<<' '<<to_string(*it); cerr<<" }"<<endl;}
template<typename T, typename Comp=less<T>> bool smin(T &mem, T const&v, Comp const&cmp=Comp())
{return cmp(v, mem) ? mem = v, true : false;}
template<typename T, typename Comp=less<T>> bool smax(T &mem, T const&v, Comp const&cmp=Comp())
{return cmp(mem, v) ? mem = v, true : false;}
/* -*- -*- -*- -*- -*- -*- -*- -*- -*- -*- -*- -*- -*- -*- -*- -*- -*- -*- -*- -*- -*- -*- -*- */

string s, t;
int a[26][100100], n, m;

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

  cin >> s >> t;
  {
    set<char> S;
    for(char c:s) S.emplace(c);
    for(char c:t)
      if( S.find(c) == S.end() ) {
	cout << -1 << endl;
	return 0;
      }
  }

  n = s.length(), m = t.length();

  for(int z=0; z<2; z++) {
    for(int i=n-1; i>=0; i--) {
      for(char c='a'; c<='z'; c++) {
	a[c-'a'][i] = a[c-'a'][(i+1) % n];
      }
      a[s[i]-'a'][i] = i;
    }
  }

  ll pos = 0, cur = 0;
  for(; ;) {
    for(; cur<m and t[cur] == s[pos%n]; cur++, pos++);
    if( cur == m ) break;
    char c = t[cur];
    int npos = a[c-'a'][ pos % n ];
    if( npos > (pos%n) ) pos += npos - (pos%n);
    else pos += (n-(pos%n)+npos);
  }
  cout << pos << endl;

}


Measured memory_bytes: 10704
#include<bits/stdc++.h>
#define ll          long long int
#define lld          long double
#define pb          push_back
#define pii         pair<ll,ll>
#define mi          map<ll,ll>
#define vec         vector<ll>
#define all(a)     (a).begin(),(a).end()
#define F           first
#define S           second
#define mod         1000000007
#define rep(i,a,b)	for(ll  i=a;i<b;i++)
#define repi(i,a,b)	for(ll  i=a;i<=b;i++)
#define per(i,a,b)  for(ll i=a;i>=b;i--)
#define mp          make_pair
#define mit         map<ll,ll>::iterator
#define sit         set<ll>::iterator
#define pit         pair<ll,ll>::iterator
#define tr(container, it) for(__typeof(container.begin()) it = container.begin(); it != container.end(); it++)
using namespace std;
ll xo(ll x, ll y) 
{ 
   return (x | y) & (~x | ~y); 
}  
ll bin_Expo(ll x,ll n)
{
		if(x==0)
		return 0;
    if(n==0)
        return 1;
    else if(n%2 == 0)        //n is even
        return bin_Expo(x*x,n/2);
    else                             //n is odd
        return x*bin_Expo(x*x,(n-1)/2);
}
ll mod_Expo(ll x,ll n,ll M)
{
		if(x==0)
		return 0;
    if(n==0)
        return 1;
    else if(n%2 == 0)        //n is even
        return mod_Expo((x*x)%M,n/2,M);
    else                             //n is odd
        return (x*mod_Expo((x*x)%M,(n-1)/2,M))%M;
 
}
ll NcR(int n, int r) 
{ 
    ll p = 1, k = 1; 
    if (n - r < r) 
        r = n - r; 
  
    if (r != 0) { 
        while (r) { 
            p *= n; 
            k *= r; 
            ll m=__gcd(p, k); 
            p /= m; 
            k /= m; 
            n--; 
            r--; 
        } 
    } 
    else
        p = 1; 
    return p;
}
bool prime_check(ll x)
{
    bool prime = (x >= 2);
    for (ll i = 2; i * i <= x; i++) 
    {
        if (x % i == 0) 
        {
            prime = false;
            break;
        }
    }
    return prime;
}
ll logg(ll base,ll x)
{
    return (ll)(log(x)/log(base));
}

int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	int TESTS=1;
//	cin>>TESTS;
    while(TESTS--)
    {
    	ll i,j,l,m,k,n,x,y,y1,y2,c,cost,ans, mn;
    	string s;
    	cin>>s;
    	l=0;
    	rep(i,0,3) if(s[i]=='R') l++;
    	if(l==0 || l==3 || l==1) cout<<l;
    	else{
    		if(s[1]=='S')l--;
    		cout<<l;
		}
    	
    	
    } 
	return 0;
}













Measured memory_bytes: 3696
N = int(input())
all_str = []
dic_s = {}
dic_t = {}
for i in range(N):
  s = input()
  all_str.append(s)
  if(s in dic_s):
    dic_s[s] += 1
  else:
    dic_s[s] = 1
    dic_t[s] = 0

M = int(input())
for i in range(M):
  t = input()
  if(t in dic_t):
    dic_t[t] += 1
  else:
    dic_t[t] = 1
  if(t in dic_s):
    dummy = 0
  else:
    dic_s[t] = 0
    all_str.append(t)
 
point = []
for i in range(len(all_str)):
  point.append(dic_s[all_str[i]] - dic_t[all_str[i]])
if(max(point)<=0):
  print(0)
else:
  print(max(point))

Measured memory_bytes: 3188
#include <cstdio>

using namespace std;

int h, w;
char s[11][11];

int main(void) {
  scanf("%d%d", &h, &w);
  for (int i = 0; i < h; i++) scanf("%s", s[i]);

  int x, y; x=y=0;
  while (x!=w-1 || y!=h-1) {
    if (s[y][x] != '#') break;
    s[y][x] = '.';
    if (x+1 < w && s[y][x+1] == '#') x++;
    else if(y+1 < h && s[y+1][x] == '#') y++;
    else break;
  }
  s[y][x] = '.';
  bool ok = true;
  if (x == w-1 && y == h-1) {
    for (int i = 0; i < h; i++) {
      for (int j = 0; j < w; j++) ok &= s[i][j] == '.';
    }
  } else {
    ok = false;
  }
  puts(ok ? "Possible" : "Impossible");
  return 0;
}


Measured memory_bytes: 128
#include<bits/stdc++.h>
using namespace std;
#define int long long
int N,M;
int A[300000],B[300000],C[300000],sum[300000];

signed main(){
    scanf("%lld",&N);
    for(int i=0;i<N;i++)scanf("%lld",&A[i]);
    scanf("%lld",&M);
    for(int i=0;i<M;i++)scanf("%lld",&B[i]);
    for(int i=0;i<M;i++)scanf("%lld",&C[i]);

    sort(A,A+N);

    for(int i=0;i<N;i++){
        sum[i]=A[i]+(i?sum[i-1]:0);
    }


    for(int i=0;i<M;i++){
        int lb=-1,ub=N;
        while(ub-lb>1){
            int mid=(ub+lb)/2;
            if(A[mid]<=B[i])lb=mid;
            else ub=mid;
        }
        int val;
        if(lb==-1)val=0;
        else val=sum[lb];
        if(C[i]<=val)puts("Yes");
        else puts("No");
    }
    return 0;
}

Measured memory_bytes: 10544
import sys

sys.setrecursionlimit(10**7)

stdin = sys.stdin

ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
ns = lambda: stdin.readline().rstrip()  # ignore trailing spaces

s = input()
if s == 'ABC':
    print('ARC')
else:
    print('ABC')

Measured memory_bytes: 8976
#include <algorithm>
#include <cmath>
#include <deque>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <utility>
#include <vector>
using namespace std;
using ll = long long;
#define rep(i, n) for (int i = 0; i < n; i++)
#define repk(i, k, n) for (int i = k; i < n; i++)
#define MOD 1000000007
#define INF 1e9
#define PIE 3.14159265358979323

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;
}
template <class T>
T GCD(T a, T b) {
    if (b == 0)
        return a;
    else
        return GCD(b, a % b);
}
template <class T>
inline T LCM(T a, T b) {
    return (a * b) / GCD(a, b);
}

int main() {
    int n;
    cin >> n;
    vector<int> a(n);
    rep(i, n) cin >> a[i];
    vector<int> gcd_left(n + 1);
    vector<int> gcd_right(n + 1);
    gcd_left[1] = a[0];
    for (int i = 1; i < n; i++) {
        gcd_left[i + 1] = GCD(gcd_left[i], a[i]);
    }
    gcd_right[n] = a[n - 1];
    for (int i = n; i > 1; i--) {
        gcd_right[i - 1] = GCD(gcd_right[i], a[i - 2]);
    }
    int res = 0;
    for (int i = 1; i <= n; i++) {
        if (i == 1)
            res = max(gcd_right[2], res);
        else if (i == n)
            res = max(gcd_left[n - 1], res);
        else
            res = max(GCD(gcd_left[i - 1], gcd_right[i + 1]), res);
    }
    cout << res << endl;
    return 0;
}

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

using namespace std;

#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REP(i,n) FOR(i,0,n)
#define ALL(v) (v).begin(),(v).end()

template<typename A, typename B> inline bool chmax(A &a, B b) { if (a<b) { a=b; return 1; } return 0; }
template<typename A, typename B> inline bool chmin(A &a, B b) { if (a>b) { a=b; return 1; } return 0; }

typedef unsigned long long ull;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<int, pii> P;

const ll INF = 1ll<<29;
const ll MOD = 1000000007;
const double EPS  = 1e-10;

int main() {
	int n;
	int a[112345];
	
	cin >> n;
	REP(i, n) scanf("%d", a + i);
	
	int ans = 1;
	int f = -1;
	
	REP(i, n - 1) {
		if (f == -1) {
			if (a[i] == a[i + 1]) f = 2;
			else f = a[i] < a[i + 1];
		}
		
		if (a[i] > a[i + 1]) {
			if (f == 2) {
				f = 0;
			}
			if (f == 1) {
				f = -1;
				ans++;
			}
		}
		
		if (a[i] < a[i + 1]) {
			if (f == 2) {
				f = 1;
			}
			if (f == 0) {
				f = -1;
				ans++;
			}
		}
	}
	
	cout << ans << endl;
	
	return 0;
}


Measured memory_bytes: 640
package main

import (
	"fmt"
)

func main() {
	var a string
	fmt.Scanf("%s", &a)

	var res int

	if a[0:1] == "1" {
		res = res + 1
	}

	if a[1:2] == "1" {
		res = res + 1
	}

	if a[2:3] == "1" {
		res = res + 1
	}

	fmt.Printf("%d\n", res)
}


Measured memory_bytes: 512
import java.io.*;

public class Main {

	/**
	 * @param args
	 * @throws IOException 
	 */
	public static void main(String[] args) throws IOException {
		// TODO Auto-generated method stub
		BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
		String input = in.readLine();
		String numbers[] = input.split(" ");
		Integer a = Integer.parseInt(numbers[0]);
		Integer b = Integer.parseInt(numbers[1]);
		Integer c = Integer.parseInt(numbers[2]);
		Integer result[] = {a, b, c};
		if(result[0] > result[1]){
			Integer first = result[0];
			Integer second = result[1];
			result[0] = second;
			result[1] = first;
		}

		if(result[1] > result[2]){
			Integer first = result[1];
			Integer second = result[2];
			result[1] = second;
			result[2] = first;
		}

		if(result[0] > result[1]){
			Integer first = result[0];
			Integer second = result[1];
			result[0] = second;
			result[1] = first;
		}
		
		System.out.println(result[0] + " " + result[1] + " " + result[2]);

	}

}

Measured memory_bytes: 16900
#include<iostream>
#include<vector>
#include<cstdio>
#include<string>
#include<cmath>
#include<math.h>
#include<algorithm>
#include<string.h>
#include <iomanip>
#include <sstream>
using namespace std;

int main() {
  long long N;

  cin >> N;

  //各桁確認
  long long ksum = 0;
  long long  ketaN = N;
  int keta = 0;
  while(ketaN > 0){
    ksum = ksum + (ketaN%10);
    ketaN = ketaN/10;
    keta++;
  }

  if(N%ksum == 0){
    cout  << "Yes" << endl;
  }else {
    cout  << "No" << endl;
  }

}


Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
using lint=int64_t;
using namespace std;

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

	if(A>=13)
		cout << B;
	else if(A>=6)
		cout << B/2;
	else
		cout << 0;
	cout << endl;
	return 0;
}



Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<vector>
#include<cmath>

using namespace std;

int main(){
  int N;
  vector<int> vec1,vec2;
  for(int i=0;i<=sqrt(151200/2);i++){
    vec1.push_back(i*i*i);
    vec2.push_back(i*(i+1)*(i+2)/6);
  }

 
  int ans;
  while(cin >> N && N){
    ans = 0;
    for(int i=0;i<vec1.size() && vec1[i] <= N;i++){
      if(N-vec1[i]>=0 &&N-ans > N-vec1[i])ans = vec1[i];
    }
    for(int i=0;i<vec2.size() && vec2[i] <= N;i++){
      if(N-vec2[i]>=0 && N-ans > N-vec2[i])ans = vec2[i];
    }
    for(int i=0;i<vec1.size() && vec1[i] <= N;i++){
      for(int j=0;j<vec2.size() && vec2[j] <= N;j++){
	if(N-vec1[i]-vec2[j] >= 0 && N-ans > N-vec1[i]-vec2[j])ans = vec1[i]+vec2[j];
      }
    }
    cout << ans << endl;
  }
  return 0;
}

Measured memory_bytes: 1224
/******************************************************************************

                              Online C++ Compiler.
               Code, Compile, Run and Debug C++ program online.
Write your code in this editor and press "Run" button to compile and execute it.

*******************************************************************************/

#include <iostream>

using namespace std;

int main()
{
    long long x;
    cin>>x;
    cout<<(x^1);

    return 0;
}


Measured memory_bytes: 3620
//Happy Birthday!
#include <bits/stdc++.h>
using namespace std;
int main(void){
    int A,B;
    cin>>A>>B;
    vector<char>cake(16);
    bool flg=true;
    int idx=0;
    for(int i=0;i<cake.size()/2;i++){
        if(A>0){
            cake.at(idx)='a';
            A--;
            idx++;
        }else{
            if(B>0){
                cake.at(idx)='b';
                B--;
                idx++;                
            }else{
                cake.at(idx)='x';
                idx++;
            }            
        }        
        if(B>0){
            cake.at(idx)='b';
            B--;
            idx++;
        }else{
            if(A>0){
                cake.at(idx)='a';
                A--;
                idx++;                
            }else{
                cake.at(idx)='x';
                idx++;
            }            
        }
    }
    int posi_x=16;
    for(int i=0;i<cake.size();i++){
        if(cake.at(i)=='x'){
            posi_x=i;
            break;
        }
    }
    for(int i=1;i<posi_x-2;i++){
        if(cake.at(i-1)!=cake.at(i)&&cake.at(i)!=cake.at(i+1))flg=true;
        else {
            flg=false;
            break;
        }
    }
    /*for(int i=0;i<cake.size();i++){
        cout<<cake.at(i);
    }*/
    cout<<( flg? "Yay!":":(")<<endl;
    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<string>
#include<cstring>
#include<cstdio>
#include<cstdlib>
#include<vector>
#include<queue>
#include<stack>
#include<complex>
#include<utility>
#include<cmath>
#define loop(i,a,b) for(int i=a;i<b;i++)
#define rep(i,a) loop(i,0,a)
#define pi acos(-1)
#define all(v) v.begin(),v.end()
using namespace std;

const double eps = 1e-8;
const double INF = 1e8;

typedef pair<int,int> P;
typedef double Real;
typedef complex<Real> Point;
typedef vector<Point> G;

double cross(const Point& a,const Point& b){//calculate ad-bc(vector product)
	return imag(conj(a)*b);
}

struct L:public vector<Point>{//line data
	L(const Point &a,const Point &b){
		push_back(a);
		push_back(b);
	}
};

int main(){
	int a,b,c,t;
	int n,m,q;
	while(cin>>n>>m,n||m){
		int cost[m+1][m+1];
		int ti[m+1][m+1];
		rep(i,m+1)rep(j,m+1){
			cost[i][j]=ti[i][j]=INF;
		}
		rep(i,n){
			cin>>a>>b>>c>>t;
			cost[a][b]=cost[b][a]=c;
			ti[a][b]=ti[b][a]=t;
		}
		rep(k,m+1)rep(i,m+1)rep(j,m+1){cost[i][j]=min(cost[i][j],cost[i][k]+cost[k][j]);ti[i][j]=min(ti[i][j],ti[i][k]+ti[k][j]);}
		cin>>q;
		int check;
		rep(i,q){
			cin>>a>>b>>check;
			if(!check)cout<<cost[a][b]<<endl;
			else cout<<ti[a][b]<<endl;
		}
	}
	return 0;
}

Measured memory_bytes: 1236
/* Don't try to copy it!
                    nhi too,
                         goli maar ke cheed bana dunga...;););)
 
                 
    _/﹋\_
    (҂`_´)
    <,︻╦╤─҉- - - - - - - - => - => - =>
    _/﹋\_
                
*/
 
#include "bits/stdc++.h"
#define faster ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define ll long long int
#define pb push_back
#define f(a) for(ll i = 0;i<a;i++)
#define rep(i,a,b) for(ll i = a;i<b;i++)
#define rrep(i,a,b) for(ll i = a;i>b;i--)
#define vll vector<ll>
#define T ll t; cin>>t; while(t--)
#define freeopen freopen("input.txt","r",stdin);
#define freeclose freopen("output.txt","w",stdout);
#define MOD 1000000007
using namespace std;
ll gcd(ll a,ll b) { return b?gcd(b,a%b):a;}
ll lcm(ll a, ll b) { return a * (b / gcd(a, b)); }


double dp[3002][3002],P[3002];
ll vis[3002][3002],N;

double solve(ll pos,ll heads){
    
    if(heads < 0) return 0.0;

    if(pos == 0){
        return (heads == 0);
    }

    if(vis[pos][heads]) return dp[pos][heads];
    vis[pos][heads] = 1;

    return dp[pos][heads] =  (P[pos])*solve(pos-1,heads-1) + (1.0 - P[pos])*solve(pos-1,heads);

}

main(){

    cin >> N;
    for(int i = 1;i<=N;i++){
        cin >> P[i];
    }

    double tot = 0;
    for(ll heads = 0;heads<=N;heads++){
        ll tails = N - heads;
        if(heads > tails) tot += solve(N,heads);
    }

    printf("%.9lf\n",tot);

    
}

Measured memory_bytes: 136940
h,w = map(int, input().split())
# W: 一行の文字列
# H: 行数

glid = [list(input()) for i in range(h)]
ans = [[0] * w for i in range(h) ]

#print("{},{}".format(w, h))

for i in range(h):
    for j in range(w):
        # 各文字に対し探索を行う
        if glid[i][j] == '#':
            ans[i][j] = '#'
            continue
            
        count = 0
        for k in range(-1,2):
            if i+k < 0 or i+k >= h:
                continue
            for l in range(-1,2):
                if j+l < 0 or j+l >= w:
                    continue
                #print("{},{}".format(i+k, j+l))
                if glid[i+k][j+l] == '#':
                    count += 1
        ans[i][j] = count

for i in range(h):
  #print(ans[i])
  print(''.join(map(str, ans[i])))  
  #print("\n")

Measured memory_bytes: 3064
using System;
using System.Linq;
using System.Collections.Generic;

namespace ABC
{
    class ProgramA
    {
        static void Main(string[] args)
        {
            var a = long.Parse(Console.ReadLine());
            var result = a % 2 == 0 ? a : 2 * a;
            Console.WriteLine(result);
        }
    }
}


Measured memory_bytes: 27512
from collections import deque


def main():
    N, K = map(int, input().split())
    sushis = [None] * N
    for i in range(N):
        t, d = map(int, input().split())
        sushis[i] = (t, d)
    sushis.sort(key=lambda a: (-a[1], a[0]))
    tmp = 0
    types = set()
    stack = deque()
    ans = 0
    for i in range(len(sushis)):
        t, d = sushis[i]
        if i < K:
            if t in types:
                stack.append(d)
            types.add(t)
            tmp += d
        else:
            if t not in types and len(stack):
                types.add(t)
                tmp += d
                tmp -= stack.pop()
        ans = max(ans, tmp + len(types)**2)
    print(ans)


if __name__ == "__main__":
    main()


Measured memory_bytes: 60248
/* kadai4_3
   Saikyo_Kazune
*/
#include <stdio.h>
//プロトタイプ宣言
int snow_depth(int west_height_seen,int east_height_seen);
 
int main(void){
   
   //int型　雪上に見えている等の高さを格納する変数を宣言
   int west_height_seen,east_height_seen;
   //標準入力から受け取り
   scanf("%d %d",&west_height_seen,&east_height_seen);
   //関数により雪の深さを求めて出力
   printf("%d\n", snow_depth(west_height_seen,east_height_seen));
   return 0;
}
//雪の深さを求める関数を定義
int snow_depth(int west_height_seen,int east_height_seen){
    //西側の塔の本来の高さを格納する変数 int west_heightを宣言
    int west_height=0;
    //雪の上に見えている東側の塔の高さから西側の等の高さを引いた数がnのとき、西側の塔本来のたかさが0からn-1までの和であるから
    for(int i=0;i<(east_height_seen-west_height_seen);i++){
        west_height+=i;
    }
    //西側の塔の本来の高さから雪上に見える高さを引いたものが雪の深さ
    return west_height-west_height_seen;
}

Measured memory_bytes: 128
#define _CRT_SECURE_NO_WARNINGS
#define _USE_MATH_DEFINES

#include <bits/stdc++.h>
using namespace std;
using i32 = int32_t; using i64 = int64_t; using f64 = double_t; using str = string;
template <typename T> using vec = vector<T>;
template <typename T> using heap = priority_queue<T, vec<T>, greater<T>>;
#define times(n, i) for (i32 i = 0; i < (n); ++i)
#define range(n, m, i) for (i32 i = (n); i < (m); ++i)
#define upto(n, m, i) for (i32 i = (n); i <= (m); ++i)
#define downto(n, m, i) for (i32 i = (n); i >= (m); --i)
#define foreach(xs, x) for (auto &x : (xs))
#define all(xs) (xs).begin(), (xs).end()
#define sortall(xs) sort(all(xs))
#define reverseall(xs) reverse(all(xs))
#define uniqueall(xs) (xs).erase(unique(all(xs)), (xs).end())
#define maximum(xs) (*max_element(all(xs)))
#define minimum(xs) (*min_element(all(xs)))
#define even(x) (((x) & 1) == 0)
#define odd(x) (((x) & 1) == 1)
#define append emplace_back
const i64 MOD = 1000000007;

i32 n, a[200000], p[200001];

i32 main()
{
    cin >> n;
    times(n, i) {
        cin >> a[i];
        p[a[i]] = i;
    }
    set<i32> s;
    i64 ans = 0;
    upto(1, n, x) {
        i32 i = p[x];
        s.insert(i);
        auto it = s.find(i);
        i64 l = 0, r = n-1;
        if (it != s.begin()) {
            l = *(--it) + 1;
            it++;
        }
        if (it != --s.end()) {
            r = *(++it) - 1;
            it--;
        }
        ans += (i-l+1) * (r-i+1) * x;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 11136
#!/usr/bin/python3
# -*- coding: utf-8 -*-
x, k, d = map(int, input().split())
if x < 0:
    x *= -1
t1 = x % d
t2 = t1 - d
n = (x - t1) // d
if k == n:
    print(t1)
elif k < n:
    print(x - k * d)
else:
    n = k - n
    if n % 2 == 0:
        print(t1)
    else:
        print(-t2)

Measured memory_bytes: 9184
import sys
read = sys.stdin.read
readlines = sys.stdin.readlines
from itertools import accumulate
from bisect import bisect
def main():
    n, m, k = map(int, input().split())
    a = tuple(map(int, input().split()))
    b = tuple(map(int, input().split()))

    aa = [0] + list(accumulate(a))
    ba = [0] + list(accumulate(b))
    r = 0
    for i1, aae in enumerate(aa):
        if aae > k:
            break
        else:
            time_remain = k - aae
            b_num = bisect(ba, time_remain)
            r = max(r, i1 + b_num - 1)
    print(r)

if __name__ == '__main__':
    main()

Measured memory_bytes: 146216
#include<stdio.h>
#define N 100000

int S[N];

int main(){
  int n,i,q,key,result;
  int sum = 0;

  scanf("%d",&n);
  for(i=0; i<n; i++){
    scanf("%d",&S[i]);
  }

  scanf("%d",&q);
  for(i=0; i<q; i++){
    scanf("%d",&key);
    result = binarySearch(key, n);
    if(result == 1){
      sum++;
    }
  }

  printf("%d\n",sum);

  return 0;
  
  
}

int binarySearch(int key, int n){
  int left = 0;
  int right = n;
  int mid;
  while(left < right){
    mid = (left + right) / 2;
    if(S[mid] == key)
      return 1;
    else if(key < S[mid]){
      right = mid;
    }else{
      left = mid + 1;
    }
  }
  return 0; //Not Found
}



Measured memory_bytes: 2104
using System;
using System.Collections.Generic;
using System.Linq;

namespace AC
{
    class Program
    {
        static void Main(string[] args)
        {
            var S = Read();

            Console.WriteLine(S[0] == S[1] && S[0] == S[2] ? "No" : "Yes");
            Console.ReadKey();
        }

        static string Read() { return Console.ReadLine(); }
        static int ReadInt() { return int.Parse(Read()); }
        static long ReadLong() { return long.Parse(Read()); }
        static int[] ReadArrayInt() { return Read().Split(' ').Select(s => int.Parse(s)).ToArray(); }
        static long[] ReadArrayLong() { return Read().Split(' ').Select(s => long.Parse(s)).ToArray(); }
    }
}

Measured memory_bytes: 11220
#include <iostream>
#include <vector>
#include <cstdio>

using namespace std;

void printmtx(const vector<vector<int> > &v) {
    for(int y = 0; y < v.size(); ++y) {
        for(int x = 0; x < v[y].size(); ++x)
            printf("%3d", v[y][x]);
        printf("\n");
    }
    puts("");
}


int main() {
    while(true) {
        int N, M;
        cin >> N >> M;
        if(!N && !M) break;

        vector<vector<int> > photo(N, vector<int>(N, -1));
        vector<vector<vector<int> > > piece(4, vector<vector<int> >(M, vector<int>(M, -1)));

        for(int y = 0; y < N; ++y)
            for(int x = 0; x < N; ++x)
                cin >> photo[y][x];

        for(int y = 0; y < M; ++y)
            for(int x = 0; x < M; ++x)
                cin >> piece[0][y][x];

        for(int m = 1; m < 4; ++m) {
            for(int y = 0; y < M; ++y)
                for(int x = 0; x < M; ++x)
                    piece[m][x][M-y-1] = piece[m-1][y][x];
        }

        int ax = -1, ay = -1;
        for(int y = 0; y <= N-M; ++y) {
            for(int x = 0; x <= N-M; ++x) {
                for(int m = 0; m < 4; ++m) {
                    for(int py = 0; py < M; ++py) {
                        for(int px = 0; px < M; ++px) {
                            if(piece[m][py][px] == -1) continue;
                            if(piece[m][py][px] != photo[y+py][x+px]) {
                                goto nextpos;
                            }
                        }
                    }
                    for(int py = 0; py < M; ++py) {
                        for(int px = 0; px < M; ++px) {
                            if(piece[m][py][px] != -1) {
                                ax = px+x+1;
                                ay = py+y+1;
                                goto endloop;
                            }
                        }
                    }
nextpos:
                    ;
                }
            }
        }
endloop:
        if(ax != -1) cout << ax << ' ' << ay << endl;
        else cout << "NA" << endl;
    }
    return 0;
}

Measured memory_bytes: 980
fun main(args: Array<String>) {
  val N = readInt()
  for (i in 0..20) {
    val d = (N - 4 * i)
    if (d < 0) break
    if (d % 7 == 0) {
      println("Yes")
      return
    }
  }
  println("No")
}

fun gcd(a: Int, b: Int): Int = if (a < b) gcd(b, a) else if (b == 0) a else gcd(b, a % b)
fun gcd(a: Long, b: Long): Long = if (a < b) gcd(b, a) else if (b == 0L) a else gcd(b, a % b)
fun lcm(a: Int, b: Int): Int = (a * b) / gcd(a, b)
fun lcm(a: Long, b: Long): Long = (a * b) / gcd(a, b)

fun readString() = readLine()!!
fun readInt() = readLine()!!.toInt()
fun readInts() = readLine()!!.split(" ").map { it.toInt() }
fun readLongs() = readLine()!!.split(" ").map { it.toLong() }


Measured memory_bytes: 33724
import itertools
n=int(input())
list1=list(itertools.permutations(range(1,n+1)))
p=tuple(map(int,input().split()))
q=tuple(map(int,input().split()))
ansp=-1
ansq=-1
for i in range(len(list1)):
    if list1[i]==p[:]:
        ansp=i+1
    if list1[i]==q[:]:
        ansq=i+1
print(abs(ansp-ansq))


Measured memory_bytes: 8052
/* monkukui 競技プログラミング用のテンプレート  (ここから) */
#include <iostream>
#include <cstdio>
#include <string>
#include <cstring>
#include <deque>
#include <list>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <complex>
#include <cmath>
#include <limits>
#include <climits>
#include <ctime>
#include <cassert>
#include <numeric>
#include <functional>
#include <bitset>

using namespace std;
using lint = long long int;
using ll = long long int;
using lnt = long long int;
using graph = vector<vector<int>>;
using wgraph = vector<vector<pair<int, long long int>>>;
long long int INF = 1001001001001001LL;
int inf = 100100100;
long long int MOD = 1000000007LL;
double PI = 3.1415926535897932;
long long int di[] = {-1, 0, 1, 0, -1, 1, 1, -1};
long long int dj[] = {0, 1, 0, -1, 1, 1, -1, -1};

template<typename T1,typename T2> inline void chmin(T1 &a,T2 b){if(a>b) a=b;}
template<typename T1,typename T2> inline void chmax(T1 &a,T2 b){if(a<b) a=b;}
inline void yes(){ cout << "yes" << endl; }
inline void Yes(){ cout << "Yes" << endl; }
inline void YES(){ cout << "YES" << endl; }
inline void no(){ cout << "no" << endl; }
inline void No(){ cout << "No" << endl; }
inline void NO(){ cout << "NO" << endl; }
inline void possible(){ cout << "possible" << endl; }
inline void Possible(){ cout << "Possible" << endl; }
inline void POSSIBLE(){ cout << "POSSIBLE" << endl; }
inline void impossible(){ cout << "impossible" << endl; }
inline void Impossible(){ cout << "Impossible" << endl; }
inline void IMPOSSIBLE(){ cout << "IMPOSSIBLE" << endl; }

#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 srep(i,s,t) for(int i = s; i < t; i++)
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define pb push_back

/* monkukui 競技プログラミング用のテンプレート (ここまで)*/

int main(){
   
  set<pair<int, int>> st;
  map<pair<int, int>, int> m;
  for(int i = 1; i <= 1000; i++) {
    for(int j = i + 1; j < 1000; j++) {
      st.insert({i * i + j * j, i});
      m[{i * i + j * j, i}] = j;
    }
  }

  while(1) {
    int h, w; cin >> h >> w;
    if(h == 0) break;
    auto itr = st.find({h * h + w * w, h});
    itr++;
    int a = (*itr).first;
    int b = (*itr).second;
    cout << b << " " << m[{a, b}] << endl;
  }

  return 0;
}



Measured memory_bytes: 57604
#include <vector>
#include <map>
#include <set>
#include <stack>
#include <queue>
#include <algorithm>
#include <numeric>
#include <sstream>
#include <iostream>
#include <iomanip>
#define _USE_MATH_DEFINES
#include <cmath>
#include <climits>
#include <cstdlib>
#include <cstring>
#include <cfloat>
#include <cmath>
#include <ctime>
#include <cstdio>
#include <cassert>
using namespace std;

#define EPS 1e-12
#define ull unsigned long long
#define ll long long
#define VI vector<ll>
#define PII pair<ll, ll> 
#define VVI vector<vector<ll> >
#define REP(i,n) for(int i=0,_n=(n);(i)<(int)_n;++i)
#define RANGE(i,a,b) for(int i=(int)a,_b=(int)(b);(i)<_b;++i)
#define FOR(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)
#define ALL(c) (c).begin(), (c).end()
#define ALLR(c) (c).rbegin(), (c).rend()
#define PB push_back
#define MP(a, b) make_pair(a, b)
#define POPCOUNT __builtin_popcount
#define POPCOUNTLL __builtin_popcountll
#define CLEAR(table, v) memset(table, v, sizeof(table));
#define PRINT1(table, D0) REP(d0, D0) cout<<table[d0]<<" "; cout<<"\n";
#define PRINT2(table, D0, D1) REP(d0, D0) { REP(d1, D1) cout<<table[d0][d1]<<" "; cout<<"\n"; }
#define PRINT3(table, D0, D1, D2) REP(d0, D0) { REP(d1, D1) { REP(d2, D2) cout<<table[d0][d1][d2]<<" "; cout<<"\n"; } cout<<"\n"; }
#define UNIFORM_DOUBLE(a, b) (((b-a)*(double)rand()/RAND_MAX)+a) // [a, b) 
#define UNIFORM_LL(a, b) (ll)UNIFORM_DOUBLE(a, b) // [a, b) 
#define IN(v, lo, hi) ((lo)<=(v) && (v)<(hi))
#define DD(v) cout<<#v<<": "<<v<<endl
template <typename T0, typename T1> std::ostream& operator<<(std::ostream& os, const map<T0, T1>& v) { for( typename map<T0, T1>::const_iterator p = v.begin(); p!=v.end(); p++ ){os << p->first << ": " << p->second << " ";} return os; }
template <typename T0, typename T1> std::ostream& operator<<(std::ostream& os, const pair<T0, T1>& v) { os << v.first << ": " << v.second << " "; return os; }
template <typename T> std::ostream& operator<<(std::ostream& os, const vector<T>& v) { for( int i = 0; i < (int)v.size(); i++ ) { os << v[i] << " "; } return os; }
template <typename T> std::ostream& operator<<(std::ostream& os, const vector<vector<T> >& v) { for( int i = 0; i < (int)v.size(); i++ ) { os << v[i] << endl; } return os; }
template <typename T> std::ostream& operator<<(std::ostream& os, const set<T>& v) { vector<T> tmp(v.begin(), v.end()); os << tmp; return os; }
template <typename T> std::ostream& operator<<(std::ostream& os, const deque<T>& v) { vector<T> tmp(v.begin(), v.end()); os << tmp; return os; }

#define MOD 1000000007LL
#define INF (1LL<<60)

int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	ll Q,H,S,D,N;
	while(cin>>Q>>H>>S>>D>>N) {
		ll two = min({Q*8, H*4, S*2, D});
		ll one = min({Q*4, H*2, S});
		ll ans = (N/2 * two) + (N%2 * one);
		
		cout<<ans<<endl;
	}
	
	return 0;
}


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

int main()
{
	string s1,s2;
	cin>>s1>>s2;
	int l1=s1.length();
	int l2=s2.length();
	int f=0;
	if(l2==l1+1)
	{
		int ct=0;
		for(int i=0;i<l1;++i)
			if(s1[i]==s2[i])
				ct++;
		if(ct==l1)
		f=1;
		//cout<<"Yes"<<"\n";
	}
	if(f)
	cout<<"Yes"<<"\n";
	else
	cout<<"No"<<"\n";
}

Measured memory_bytes: 3620
#define _GLIBCXX_DEBUG
#include<bits/stdc++.h>
#include<algorithm>//next_permutation
#define rep(i,n) for (int i = 0;i < (n);i++)
#define all(v) v.begin(),v.end()
#define dec(n) cout << fixed << setprecision(n);
#define large "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
#define small "abcdefghijklmnopqrstuvwxyz"
using namespace std;
using ll = long long;
using P = pair<ll,ll>;
using vl = vector<ll>;
using vvl = vector<vl>;

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

const ll MOD = 1000000007;
const ll MAX = 2000001;

ll mod(ll a){
  return a % MOD;
}

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


struct UnionFind {
    //自身が親であれば、その集合に属する頂点数に-1を掛けたもの
    //そうでなければ親のid
    vector<int> r;
 
    UnionFind(int N) {
        r = vector<int>(N, -1);
    }
 
    int root(int x) {
        if (r[x] < 0) return x;
        return r[x] = root(r[x]);
    }
 
    bool unite(int x, int y) {
        x = root(x);
        y = root(y);
        if (x == y) return false;
        if (r[x] > r[y]) swap(x, y);
        r[x] += r[y];
        r[y] = x;
        return true;
    }
 
    int size(int x) {
        return -r[root(x)];
    }
  
};




int main(){
  ll n; cin >> n;
  
  rep(i,n){
    cout << "ACL";
  }
  
  cout << endl;
  
  
}

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

#define REP(i, n) for (int i = 0; i < (n); i++)
#define FOR(i, init, n) for(int i = init; i < (n); i++)
#define ALL(obj) (obj).begin(), (obj).end()
#define fi first
#define se second

using namespace std;
using ll = long long int;
using P = pair<int, int>;
using T = tuple<int, int, int>;
using edge = struct
{
    int to, cost;
};

const int MOD = 1e9 + 7;
const int iINF = 1e9;
const long long int llINF = 1e18;
const double PI = acos(-1.0);

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

int dp[1024][8];

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

    int N;
    cin >> N;
    string S;
    cin >> S;

    vector<int> sch(N);

    REP(i, N)
    {
        if(S[i] == 'J')
        {
            sch[i] = 1;
        }
        else if(S[i] == 'O')
        {
            sch[i] = 2;
        }
        else
        {
            sch[i] = 4;
        }
    }

    dp[0][1] = 1;

    REP(i, N)
    {
        REP(j, 8)
        {
            if(!(sch[i] & j)) continue;

            REP(k, 8)
            {
                if(!(j & k)) continue;

                dp[i + 1][j] += dp[i][k];

                dp[i + 1][j] %= 10007;
            }
        }
    }

    ll ans = 0;

    REP(i, 8)
    {
        ans += dp[N][i];
        ans %= 10007;
    }

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 3256
import sys
MAX = 2*10**5
SENTINEL = 2*10**9
L = [0]*(MAX//2 + 2)
R = [0]*(MAX//2 + 2)

def Merge(A,n,left,mid,right):
    cnt = 0
    n1 = mid - left
    n2 = right - mid
    for i in range(n1):
        L[i] = A[left + i]
    for i in range(n2):
        R[i] = A[mid + i]
    
    L[n1] = SENTINEL
    R[n2] = SENTINEL
    i,j = 0,0
    for k in range(left,right):
        if L[i] <= R[j]:
            A[k] = L[i]
            i+=1
        else:
            A[k] = R[j]
            j+=1
            cnt += n1 - i
    return cnt

def MergeSort(A,n,left,right):
    if left + 1 < right:
        mid = (left + right)//2
        v1 = MergeSort(A,n,left,mid)
        v2 = MergeSort(A,n,mid,right)
        v3 = Merge(A,n,left,mid,right)
        return v1 + v2 + v3
    else:
        return 0

if __name__ == "__main__":
    n = int(input())
    A = list(map(int,input().split()))
    ans = MergeSort(A,n,0,n)
    print(ans)



Measured memory_bytes: 29916
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef pair<int,int> pii;
 
#define mem(dp,a)       memset(dp,a,sizeof dp)
#define ninja           ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define pb(x)           push_back(x)
#define mp(x,y)         make_pair(x,y)
#define all(c)          c.begin(), c.end()
#define ff              first
#define ss              second
#define nl              '\n'
#define inf             1e9+7
 
int main()
{
	ninja
	int a,p;
	cin>>a>>p;
	int pi=a*3 +p;

	cout<<pi/2;
}


Measured memory_bytes: 256
#include<iostream>
using namespace std;
int J[1000][1000]={0};
int O[1000][1000]={0};
int I[1000][1000]={0};
char maps[1000][1000];
main(){
  int m,n,k;
  int a,b,c,d;
  cin>>m>>n>>k;
  for(int i=1;i<=m;i++){
    for(int j=1;j<=n;j++){
      cin>>maps[i][j];
      J[i][j]=J[i][j-1];
      O[i][j]=O[i][j-1];
      I[i][j]=I[i][j-1];
      if(maps[i][j]=='J'){
	J[i][j]=J[i][j]+1;
      }
      else if(maps[i][j]=='O'){
	O[i][j]=O[i][j]+1;
      }
      else{
	I[i][j]=I[i][j]+1;
      }
    }
  }
  for(int i=0;i<k;i++){
    cin>>a>>b>>c>>d;
    int jcount=0;
    int ocount=0;
    int icount=0;
    for(int j=a;j<=c;j++){
      jcount=jcount+J[j][d]-J[j][b];
      ocount=ocount+O[j][d]-O[j][b];
      icount=icount+I[j][d]-I[j][b];
      if(maps[j][b]=='J'){
	jcount++;
      }
      else if(maps[j][b]=='O'){
	ocount++;
      }
      else{
	icount++;
      }
    }
    cout<<jcount<<" "<<ocount<<" "<<icount<<endl;
  }
}

Measured memory_bytes: 13812
#include <iostream>
using namespace std;
int main(void){
    // Your code here!
    int long long a,b,c,n;
    int long long ans=0;
    cin >> a >> b >> c >> n;
    for(int i=0;i<n+1;i++){
        for(int j=0;j<n+1;j++){
            if((n-i*a-j*b)%c==0 && n-i*a-j*b>=0){
                ans++;
            }
        }
    }
    cout << ans << endl;
    return 0;
}

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

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

using namespace std ;
typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;




int main()
{
  int x, a, b ;
  cin >> x >> a >> b ;
  
  cout <<(x-a)%b<<endl ;

    return 0 ;
}

/*　吾輩はやれば出来る子である。 
　　　　∩∩ 
　　　（´･ω･） 
　　 ＿|　⊃／(＿＿_ 
　／　└-(＿＿＿_／ 
　￣￣￣￣￣￣￣ 
　やる気はまだない 

　　 ⊂⌒／ヽ-、＿_ 
　／⊂_/＿＿＿＿ ／ 
　￣￣￣￣￣￣￣　　*/

Measured memory_bytes: 256
# AOJ CGL_4_A Convex Hull
# Python3 2018.6.22 bal4u

def cross(a, b):
	return a.real*b.imag - a.imag*b.real
	
# 凸包　入力: 座標リスト　リターン:凸包を構成する座標リスト
def convex_hull(p):
	pp = sorted(p, key=lambda x:(x.imag,x.real))  # y座標を優先して昇順、同じならx座標で昇順
	n = len(pp)
	ans, j = [0]*(n+1), 0
	for i in range(n):
		while j > 1 and cross(ans[j-1]-ans[j-2], pp[i]-ans[j-1]) < 0: j -= 1
		ans[j] = pp[i]
		j += 1
	k = j
	for i in range(n-2, -1, -1):
		while j > k and cross(ans[j-1]-ans[j-2], pp[i]-ans[j-1]) < 0: j -= 1
		ans[j] = pp[i]
		j += 1
	return ans[0:j-1]

n = int(input())
p = []
for i in range(n):
	x, y = list(map(int, input().split()))
	p.append(complex(x, y))
ans = convex_hull(p)
print(len(ans))
for i in ans: print(int(i.real), int(i.imag))	



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

using namespace std;

#define rep(i, n) for(int i = 0; i < (int)n; ++i)
#define FOR(i, a, b) for(int i = a; i < (int)b; ++i)

typedef long long ll;

const int Inf = 1e9;
const double EPS = 1e-9;

int gcd(int a, int b) {
    if (b == 0) {
        return a;
    } else {
        return gcd(b, a % b);
    }
}

int lcm(int a, int b) {
    return a * b / gcd(a, b);
}

int bitCount(long bits) {
    bits = (bits & 0x55555555) + (bits >> 1 & 0x55555555);
    bits = (bits & 0x33333333) + (bits >> 2 & 0x33333333);
    bits = (bits & 0x0f0f0f0f) + (bits >> 4 & 0x0f0f0f0f);
    bits = (bits & 0x00ff00ff) + (bits >> 8 & 0x00ff00ff);
    return (bits & 0x0000ffff) + (bits >>16 & 0x0000ffff);
}

int main() {
    int n, w;
    cin >> n >> w;
    vector<int> weight(n), value(n);
    rep (i, n) {
        cin >> weight[i] >> value[i];
    }
    ll dp[n + 1][w + 1];
    rep (i, n + 1) {
        rep (j, w + 1) {
            if (i != n) dp[i][j] = -Inf;
            else dp[i][j] = 0;
        }
    } 

    for (int i = n - 1; i >= 0; --i) {
        rep (j, w + 1) {
            if (j < weight[i]) dp[i][j] = dp[i + 1][j];
            else dp[i][j] = max(dp[i + 1][j], dp[i + 1][j - weight[i]] + value[i]);
        }
    }
    cout << dp[0][w] << endl;

    return 0;
}


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

#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp> 
using namespace __gnu_pbds; 
  
#define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update> 

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    int N;
    cin>>N;
    long double p[N];
    for (int i=0;i<N;i++) cin>>p[i];
    long double dp[N+1][N+1];
    for (int i=0;i<=N;i++){
        if(i==0) dp[0][i]=1;
        else dp[0][i]=0;
    }
    for (int i=1;i<=N;i++){
        dp[i][0]=dp[i-1][0]*(1-p[i-1]);
        for (int j=1;j<=N;j++)
            dp[i][j]=dp[i-1][j-1]*p[i-1]+dp[i-1][j]*(1-p[i-1]);
    }
    long double ans=0;
    for (int i=N/2+1;i<=N;i++)
        ans+=dp[N][i];
    cout << fixed << setprecision(10) << ans <<"\n";    
	return 0;
}

Measured memory_bytes: 140928
using System;
using System.Collections.Generic;
using System.Text;

namespace ALDS1_4_C {
    class Program {
        static void Main(string[] args) {
            int n = int.Parse(Console.ReadLine());
            HashSet<string> hs = new HashSet<string>();
            StringBuilder sb = new StringBuilder();
            for(int i = 0; i < n; i++) {
                string[] input = Console.ReadLine().Split(' ');
                if (input[0] == "insert")
                    hs.Add(input[1]);
                else
                    sb.AppendLine(hs.Contains(input[1]) ? "yes" : "no");
            }
            Console.Write(sb);
        }
    }
}

Measured memory_bytes: 47172
package main
import (
  "fmt"
)

func main() {
  var N, K, unhappy, edge_unhappy int
  fmt.Scan(&N, &K)
  var S string
  fmt.Scan(&S)
  arr := make([]bool, N+2)
  for i, s := range S {
    if s == 'L'{
      arr[i+1] = true
    } else {
      arr[i+1] = false
    }
  }
  arr[0] = false
  arr[N+1] = true
  for i := 0; i < N+1; i++ {
    if !arr[i] && arr[i+1] {
      //fmt.Println("u", i)
      if i == 0 || i == N {
        edge_unhappy++
      } else {
        unhappy++
      }
    }
  }
  for unhappy > 0 && K > 0 {
    unhappy--
    K--
  }

  for edge_unhappy > 1 && K > 0 {
    edge_unhappy--
    K--
  }

  // replace to edge unhappy
  //fmt.Println(unhappy, edge_unhappy)
  ans := N - unhappy * 2 - edge_unhappy
  if ans > N - 1 {
    ans = N - 1
  }
  fmt.Println(ans)
}


Measured memory_bytes: 1408
#include<bits/stdc++.h>
 
using namespace std;
const int maxn=1e5+100;
int dp[maxn],a[maxn];

int main()
{
    int n,i;
	scanf("%d",&n);
        for(i=1;i<=n;i++)
        {
            scanf("%d",&a[i]);
        }
        int ans=0,maxx=0;
       	for(int i=1;i<n;i++){
       		if(a[i]>=a[i+1]){
       			ans++;	
       			maxx=max(ans,maxx);
			}else{
				ans=0;
			}
		}
		cout<<maxx<<endl; 
    return 0;
}

Measured memory_bytes: 640
a=int(input())
b=int(input())
c=int(input())
d=int(input())
e=int(input())
k=int(input())
if abs(a-b)>k or abs(a-c)>k or abs(a-d)>k or abs(a-e)>k or abs(b-c)>k or abs(b-d)>k or abs(b-e)>k or abs(c-d)>k or abs(c-e)>k or abs(d-e)>k:
    print(':(')
else:
    print('Yay!')

Measured memory_bytes: 3064