akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const double pi = acos(-1);
#define FOR(i,a,b) for (ll i=(a),__last_##i=(b);i<__last_##i;i++)
#define RFOR(i,a,b) for (ll i=(b)-1,__last_##i=(a);i>=__last_##i;i--)
#define REP(i,n) FOR(i,0,n)
#define RREP(i,n) RFOR(i,0,n)
#define __GET_MACRO3(_1, _2, _3, NAME, ...) NAME
#define rep(...) __GET_MACRO3(__VA_ARGS__, FOR, REP)(__VA_ARGS__)
#define rrep(...) __GET_MACRO3(__VA_ARGS__, RFOR, RREP)(__VA_ARGS__)
template<typename T> ostream& operator<<(ostream& os, const vector<T>& v) {
REP(i,v.size()){if(i)os<<" ";os<<v[i];}return os;}
template<typename T> ostream& operator<<(ostream& os, const vector<vector<T>>& v) {
REP(i,v.size()){if(i)os<<endl;os<<v[i];}return os;}

int main() {
    int n,x;cin >> n >> x;
    while(true){
        int count=0;
        rep(i,1,n+1){
            rep(j,1,n+1){
                rep(k,1,n+1){
                    if(i+j+k==x){
                        if(i<j && j<k){
                            count++;
                        }
                    }
                    
                }
            
            }
            
        }
        cout << count << endl;
        cin >> n >> x;
        if(n==0&&x==0){
            break;
        }
    }
}



Measured memory_bytes: 3068
#include<iostream>
#include<vector>
#include<map>
#include<set>
#include<string>
#include<utility>
#include<algorithm>
#include<cstdio>
#include<iomanip>
#include<queue>
#include<stack>

#define ll int64_t
#define Rep(i, n) for (ll i = 0; i < n; i++)

using namespace std;

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

    ll N;
    cin >> N;
    vector<ll> d(N);
    Rep (i, N) cin >> d[i];

    sort(d.begin(), d.end());

    cout << d[N/2] - d[N/2-1] << "\n";

}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < n; i++)
using namespace std;
typedef long long ll;
//typedef pair<int,int> P;
const int MAX_N = 200005;
int P[MAX_N],Q[MAX_N];

int main()
{
	int N;
	cin >> N;
	rep(i,N)
	{
		cin >> P[i];
		Q[P[i]-1] = i;
	}
	int cnt = 1, temp = Q[0], res = 1;
	rep(i,N-1)
	{
		if (temp < Q[i+1])
		{
			cnt++;
			res = max(res,cnt);
		}
		else
		{
			cnt = 1;
		}
		temp = Q[i+1];
		//cout << cnt << " " << res << endl;
	}
	cout << N-res << endl;
	return 0;
}

Measured memory_bytes: 5168
#include<bits/stdc++.h>
#define V vector
#define VI vector<int>
#define VVI vector<vector<int>>
#define REP(i,n) for(ll i=0;i<(n);i++)
#define REPR(i,n) for(ll i=n;i>=0;i--)
#define FOR(i,m,n) for(ll i=m;i<n;i++)
#define MOD 1000000007
#define INF 1e9
#define F first
#define S second
#define All(x) (x).begin(),(x).end()
typedef long long ll;
const double PI = acos(-1);
using namespace std;



int main(void){
    string s;
    cin>>s;
    int cnt=0;
    REP(i,int(s.size()/2)){
        if(s[i]!=s[s.size()-1-i]){
            cnt++;
        }
    }
    cout<<cnt<<endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
///Welcome to Nasif's Code
#define bug printf("bug\n");
#define bug2(var) cout<<#var<<" "<<var<<endl;
#define co(q) cout<<q<<endl;
#define all(q) (q).begin(),(q).end()
typedef long long int ll;
typedef unsigned long long int ull;
const int MOD = (int)1e9+7;
const int MAX = 1e6;
#define pi acos(-1)
#define inf 1000000000000000LL
#define FastRead    ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);

int main()
{
    FastRead
    //freopen("output.txt", "w", stdout);
    string x,y;
    cin>>x>>y;
    int mx=0,l1=x.length(),l2=y.length();
    if(l1<l2)
        cout<<"UNRESTORABLE"<<endl;
    else
    {
        int pos=-1,mx=0;
        for(int i=0; i<=l1-l2; i++)
        {
            int cnt=0,f=1;
            for(int j=0; j<l2; j++)
            {
                if(x[i+j]==y[j])
                {
                    cnt++;
                }
                else if(x[i+j]!='?')
                {
                    f=0;
                    break;
                }
            }
            if(f)
            {
                if(mx!=l2)
                {
                    pos=i;
                    mx=cnt;
                }

            }
        }
        if(pos==-1)
            cout<<"UNRESTORABLE"<<endl;
        else
        {
            for(int i=pos,j=0; j<l2; j++,i++)
                x[i]=y[j];
            for(int i=0; i<l1; i++)
                if(x[i]=='?')
                    x[i]='a';
            cout<<x<<endl;
        }
    }



    return 0;
}


Measured memory_bytes: 3656
#include <bits/stdc++.h>
#include <math.h>
#include <cmath>

using namespace std;
using ll =long long;
using vi = vector<int>; 
using vvi = vector<vi>; 
using vl = vector<ll>; 
using vvl = vector<vl>; 
using vs = vector<string>;
using vvs = vector<vs>; 
using vc = vector<char>;
using vvc = vector<vc>; 
using vb = vector<bool>;
using vvb = vector<vb>; 

template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
const long long INF = 1LL << 60;
typedef pair<int, int> PR;

#define rep(i,n) ;for( int i =0; i < n ; i ++)
#define all(a) a.begin(),a.end()
#define pb(a) push_back(a)
#define pd(a) printf("%.10f\n",a)
#define mem(a) memset(a,0,sizeof(a))
#define fr(i,a,b) for(int i=a;i<b;i++)
#define pri(a)  printf("%.14lf\n",a);
#define MOD 1000000007
bool is_int_lround(double x){
  return std::lround(x)==x;
}
ll keta(ll x){
  ll n=0;
  while(x>0){
    x /=10 ;
    n ++;
  }
  return n;
}

ll conbi(int n,int m){
  
  cin>>n>>m;
  vector<ll> a(100);
  a[0] =1;
  for(int i=0;i<14;i++){
    a[i+1]=a[i]*(i+1);
  }
  return a[n] /(a[m] *a[n-m]);
}

long long modpow(long long a, long long n, long long mod) {
    long long res = 1;//繰り返し二乗法
    while (n > 0) {
        if (n & 1) res = res * a % mod;
        a = a * a % mod;
        n >>= 1;
    }
    return res;
}
ll kaijo(ll x){
  ll z=1;
  if(x==0){
    return 1;
  }
  while(x>0){
    z *=x;
    z %=MOD;
    x--;
  }
  return z;
}
ll yakusu_num(ll n){
  vl yakusu(n+1,1);
  for(ll i=2;i*i<=n;i++){ 
    while(n%i==0){
      n /=i;
      yakusu[i]++;
    }
  }
  if(n!=1)yakusu[n]++;
  ll num=1;
  for(ll i=0;i <=n;i++){
    num*=yakusu[i];
  }
  return num;
}
//cout<<""<<endl;

int main(){
 ll N;cin>>N;
  ll X,M;cin>>X>>M;
  vl s(M+1);
  rep(i,M+1)s[i]=-1;
  vl a(M+10);
  a[0]=X%M;
  s[a[0]]=0;
  ll cnt=0;
  ll in=0;
  ll z=-1;
  rep(i,M+9){
    a[i+1]=(a[i]*a[i])%M;
    if(a[i+1]!=0){
       if(s[a[i+1]]!=-1){
        cnt=i;
        in =s[a[i+1]];
        break;
        }
      else s[a[i+1]]=i+1;
    }
    else{
      z=i;
      break;
    }
  }
  vl wa(M+10);
  wa[0]=a[0];
  rep(i,M+9){
    wa[i+1]=wa[i]+a[i+1];
  }
  ll ans=0;
  if(cnt==in){
    if(z!=-1)ans=wa[z];
    else if(in!=0)ans=wa[in-1]+(N-in)*a[in];
    else ans=N*a[in];
  }
 else{
   if(z!=-1)ans=wa[z];
  else{
    if(in==0)ans=(wa[cnt])*(N/(cnt+1))+wa[N%(cnt+1)-1];
    else ans=(wa[cnt]-wa[in-1])*((N-in)/(cnt-in+1))+wa[in-1+(N-in)%(cnt-in+1)];
  }
 }
 
  cout<<ans<<endl;
}



Measured memory_bytes: 5616
X,Y = map(int,input().split())

found = False
# if (X == 1) :
#     if (Y == 2 or Y == 4) :
#         found = True

for i in range(X+1) :
    kame_legs = 4 * i
    tsuru_legs = 2 * (X-i)
    if (Y == kame_legs + tsuru_legs) :
        # print("tsuru", tsuru_legs, "kame", kame_legs)
        found = True
        break

if (found) :
    print("Yes")
else :
    print("No")

Measured memory_bytes: 9180
#include <iostream>
#include <cstdio>
#include <algorithm>
#define mem(i,a) memset(i,a,sizeof(i))
#define PI acos(-1.0)
#define DMAX 200005
#define MOD 20190823
#define eps 1e-8
#define bl bool
#define INF 1e+9
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef double db;
template<class T> inline void read(T &f){
	f=0;
    T x=1;
    char ch=getchar();
    while(ch<48 || ch>57) {
        if(ch=='-') {
            x=-1;
        }
        ch=getchar();
    }
    while(ch<=57 && ch>=48) {
        f=f*10+ch-'0';
        ch=getchar();
    }
    f*=x;
}
struct node{
	ll num,pos;
};
node a[DMAX];
bool Cmp(const node &x,const node &y){
	if(x.num==y.num){
		return x.pos<y.pos;
	}
	return x.num>y.num;
}
int main(){
	ll n;
	read(n);
	for(ll i=1;i<=n;i++){
		read(a[i].num);
		a[i].pos=i;
	}
	sort(a+1,a+n+1,Cmp);
	ll ans1=a[1].num;
	ll ans2=a[2].num;
	ll ansp=a[1].pos;
	for(ll i=1;i<=n;i++){
		if(i!=ansp){
			cout<<ans1<<endl;
		}
		else{
			cout<<ans2<<endl;
		}
	}
	return 0;
}

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

#define MAX_V 1010

const int INF = 1e9;

struct edge{ int to, cap, rev; };
vector<edge> G[MAX_V];
bool used[MAX_V];

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

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

int max_flow(int s, int t){
  int flow = 0;
  for(; ;){
    memset(used, 0, sizeof(used));
    int f = dfs(s, t, INF);
    if(f == 0) return flow;
    flow += f;
  }
}

void init(){
  for(int i = 0 ; i < MAX_V ; i++) G[i].clear();
  memset(used, 0, sizeof(used));
}

bool ok(int a, int b){
  return __gcd(a, b) != 1;
}

int main(){
  int N, M;
  while(cin >> N >> M, N|M){
    init();
    
    int source = M+N;
    int tink = source + 1;
    
    vector<int> A(N), B(M);
    for(int i = 0 ; i < N ; i++) cin >> A[i];
    for(int i = 0 ; i < M ; i++) cin >> B[i];
    
    for(int i = 0 ; i < N ; i++){
      for(int j = 0 ; j < M ; j++){
	if( ok(A[i], B[j]) ) add_edge(i, N+j, 1);
      }
    }
    
    for(int i = 0 ; i < N ; i++) add_edge(source, i, 1);
    for(int i = 0 ; i < M ; i++) add_edge(N+i, tink, 1);
    
    cout << max_flow(source, tink) << endl;
  }
  
  return 0;
}

Measured memory_bytes: 7604
import sys
input = sys.stdin.readline


def main():
    N, M = map(int, input().split())
    E = []
    for _ in range(M):
        l, r, c = map(int, input().split())
        E.append((l-1, r-1, c))

    dp = [float("inf")]*N
    dp[0] = 0

    for l, r, c in sorted(E):
        for i in range(r, l, -1):
            if dp[i] > dp[l] + c:
                dp[i] = dp[l] + c
            else:
                break
    print(-1 if dp[-1] == float("inf") else dp[-1])


if __name__ == '__main__':
    main()


Measured memory_bytes: 71132
#include<cstdio>
#include<algorithm>
using namespace std;

int n;
double a[100],ans;

int main()
{
	scanf("%d",&n);
	for (int i=1; i<=n; i++) scanf("%lf",&a[i]);
	sort(a+1,a+1+n);
	ans=a[1];
	for (int i=2; i<=n; i++)
		ans=(a[i]+ans)/2;
	printf("%lf",ans);
	return 0;
}

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

int main() {
  string s, t, u;
  int a, b;
  cin >> s >> t >> a >> b >> u;
  if (u == s) {
    cout << a - 1 << " " << b << endl;
  }
  else {
    cout << a << " " << b - 1 << endl;
  }
}


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

int n,k;
ll T[MAX];
int check(ll p){
    int i=0;
    for(int j=0;j<k;j++){
        ll s=0;
        while(s+T[i]<=p){
            s+=T[i];
            i++;
            if(i==n)return n;
        }
    }
    return i;
}

int solve(){
    ll left=0;
    ll right=100000*10000;
    ll mid;
    while(right-left>1){
        mid=(left+right)/2;
        int v=check(mid);
        if(v>=n)right=mid;
        else left=mid;
    }
    return right;
}

main(){
    cin>>n>>k;
    for(int i=0;i<n;i++)cin>>T[i];
    ll ans=solve();
    cout<<ans<<endl;
}


Measured memory_bytes: 3888
#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 n,m; cin>>n>>m;
	int a ,b;
	if(n<=1)
		a=0;
	else
		a = (n*(n-1))/2;
	if(m<=1)
		b=0;
	else
		b = (m*(m-1))/2;
	cout<<a+b;
}


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

int main()
{
    //ios_base::sync_with_stdio(false);
    //cin.tie(NULL);
    string s ;
    cin >> s ;
    int c=0 , ans =0;
    for(int i=0;i< s.length();)
    {
        if(s[i]=='R')
        {
            c=0;
            while(s[i]=='R')
            {
                c++;
                i++;
            }
            ans = max(c, ans);
        }
        i++;
    }
    cout << ans << '\n';
}





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

const int INF = 1e9+7;

int main() {
	long long n,a,b;
	cin >> n >> a >> b;
	vector<long long> x(n);
	for(int i=0; i<n; i++){
		cin >> x.at(i);
	}
	long long ans = 0;
	for(int i=0; i<n-1; i++){
		ans += min((x.at(i+1)-x.at(i))*a, b);
	}
	cout << ans << endl;

}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
#define fo(i,a,b) for(int i=a;i<=b;i++)
#define fod(i,a,b) for(int i=a;i>=b;i--)
#define me0(a) memset(a,0,sizeof(a))
#define me1(a) memset(a,-1,sizeof(a))
#define op freopen("in.txt", "r", stdin)
#define pii pair<int,int>
#define mp(x,y) make_pair(x,y)
using namespace std;
const int INF = 0x3f3f3f3f;
typedef long long LL;
void read(int& val) { int x = 0; int bz = 1; char c; for (c = getchar(); (c<'0' || c>'9') && c != '-'; c = getchar()); if (c == '-') { bz = -1; c = getchar(); }for (; c >= '0' && c <= '9'; c = getchar()) x = x * 10 + c - 48; val = x * bz; }
const int mod=1e9+7;
const int maxn = 2e6+1000;


int n,a[maxn],k;

LL ksm(LL a,LL b){
    LL res = 1;
    while(b){
        if(b&1){
            res = res*a%mod;
        }
        a=a*a%mod;b>>=1;
    }
    return res;
}
bool cmp1(int a,int b){
    return abs(a)>abs(b);
}
bool cmp2(int a,int b){
    return abs(a)<abs(b);
}

int main(){
//    op;
    read(n);read(k);
    int num1=0,num0=0,num2=0;
    fo(i,1,n) {
        read(a[i]);
        if(a[i]>0) num2++;
        else if(a[i]==0) num0++;
        else num1++;
    }
    LL ans =1;
    if(num0>n-k){
        puts("0");return 0;
    }
    if(k==n){
        fo(i,1,n) ans = ans*a[i]%mod;
    }
    else if(num2==0&&(k&1)){
        sort(a+1,a+1+n,cmp2);
        fo(i,1,k) ans = ans*a[i]%mod;
    }
    else{
        int cnt1=0;
        sort(a+1,a+1+n,cmp1);
        fo(i,1,k){
            if(a[i]<0) cnt1++;
            ans=ans*a[i]%mod;
        }
        if(cnt1&1){
            if(cnt1==k){
                ans = ans*ksm(a[k],mod-2)%mod;
                fo(i,k+1,n){
                   if(a[i]>=0){
                       ans=ans*a[i]%mod;break;
                   }
               }
            }
            else {
                LL t1 = 1, t2 = 1, flag1 = 1, flag2 = 1;
                fo(i, 1, k) {
                    if (a[i] < 0) t1 = a[i];
                    else t2 = a[i];
                }

                ans = ans*ksm(t1*t2%mod,mod-2)%mod;

                fo(i, k + 1, n) {
                    if(flag1&&a[i]<0){
                        t1*=a[i];flag1=0;
                    }
                    else if(flag2&&a[i]>=0){
                        t2*=a[i];flag2=0;
                    }
                }
                ans =ans*(max(t1,t2)%mod)%mod;
            }
        }
    }
    ans = (ans%mod+mod)%mod;
    printf("%lld\n",ans);

    return 0;
}

Measured memory_bytes: 4508
import java.util.Arrays;
import java.util.Scanner;

public class Main {
	public static void main(String args[]) {
		Scanner sc = new Scanner(System.in);
		int a = sc.nextInt();
		int b = sc.nextInt();
		if(a<0) {
			if(b<0) {
				if((a+b)%2 == 0) {
					System.out.println("Negative");
				} else {
					System.out.println("Positive");
				}
			} else {
				System.out.println("Zero");
			}
		} else if(a == 0) {
			System.out.println("Zero");
		} else {
			System.out.println("Positive");
		}
	}
}


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

using namespace std;
using ll = long long;
const int maxn = 1e5+7;

int n, a, b;
ll h[maxn];
bool check(ll x){
	ll sum=0;
	ll sub=a-b;
	for(int i=1; i<=n; ++i){
		if(x*b<h[i]){
			ll tmp=h[i]-x*b;
			sum += (tmp-1)/sub+1;
		}
	}
	return sum<=x;
}
int main()
{
	ios::sync_with_stdio(false);
	cin.tie(0);
	cin >> n >> a >> b;
	for(int i=1; i<=n; ++i){
		cin >> h[i];
	}
	sort(h+1, h+1+n);
	ll l=1, r=1e9+7;
	while(l<r){
		ll mid = l+r>>1;
		if(check(mid)){
			r=mid;
		}else{
			l=mid+1;
		}
	}
	cout << r;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
#define mod 1000000007
int main(){
	int n;
	int x[100100];
	long long ans = 1;
	scanf("%d",&n);
	for (int i = 0; i < n; ++i)
	{
		scanf("%d",&x[i]);
	}
	//一個でもゴールできないものができると
	//その後ろは全員ゴールできない

	//ロボットのとりうる最高順位をkとする
	//ロボットは自分より前にいるロボットの最高順位kを超えることはできない。

	//ロボットの取りうる最高順位は変化するか？->変化しない
	
	//ゴールできる=マップ上のロボットがWの距離までにW/2+1個以下しかない
	//後ろのやつがゴールした後の状態だとそれより前のやつは全員ゴールできる

	//それぞれのロボットに関して最高順位kを求める


	int tmpk = 1;
	for (int i = 0; i < n; ++i)
	{
		//iは自分より前にいるロボットの個数
		ans *= tmpk;
		ans %= mod;
		//ロボットが抜かせれる個数tmpkとする
		if(x[i]>(tmpk-1)*2){
		  tmpk++;
		  //とれる最高順位 i-tmpk
		}
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 640
/* ***********************************************
Author        :dasinlsb
Created Time  :2018/6/12 18:23:43
File Name     :C:\dasin\mine.cpp
************************************************ */

#include<cstdio>
#include<algorithm>
#include<cmath>
#include<cstring>
#include<cassert>
#include<vector>
using namespace std;
typedef long long ll;
typedef vector<int> VI;
typedef pair<int,int> pii;
#define pb push_back
#define fi first
#define se second
#define SZ(x) ((int)((x).size()))
const int N=200005;
const int mod=1000*1000*1000+7;
int n,ans,a[N],g[N],f[N],T[N],S[N],rs[N];
int pw(int x,int y){
  int t=1;
  for(;y;y>>=1,x=(ll)x*x%mod){
    if(y&1)t=(ll)t*x%mod;
  }
  return t;
}
struct Node{
  int x,y;
  Node(){}Node(int _x,int _y){x=_x,y=_y;}
  Node operator*(Node t){return Node((ll)x*t.x%mod,y+t.y);}
  Node operator/(Node t){return Node((ll)x*pw(t.x,mod-2)%mod,y-t.y);}
}h[N];
void add(int a[],int x,int y){for(x=n-x+1;x<=n;x+=x&-x)a[x]=(a[x]+y)%mod;}
int ask(int a[],int x){int t=0;for(x=n-x+1;x>0;x-=x&-x)t=(t+a[x])%mod;return t;}
int main(){
 // freopen("C:/dasin/aa.in","r",stdin);
  //freopen("C:/dasin/mine.out","w",stdout);
  int i,j;
  scanf("%d",&n);
  for(i=1;i<=n;++i)scanf("%d",a+i);
  for(i=1;i<=n;++i)g[a[i]]++;
  for(i=n;i;--i)g[i]+=g[i+1];
  for(i=1;i<=n;++i){
    f[i]=g[i]-n+i;
    if(f[i]<1)return puts("0"),0;
    h[i]=f[i]==1?Node(1,1):Node((ll)(f[i]-1)*pw(f[i],mod-2)%mod,0);
  }
  rs[n]=n;
  for(i=n-1;i;--i)rs[i]=f[i+1]==1?i:rs[i+1];
  //for(i=1;i<=n;++i)printf("rs %d %d\n",i,rs[i]);
  for(i=2;i<=n;++i){
    h[i]=h[i]*h[i-1];
    //printf("pre h %d %d %d\n",i,h[i].x,h[i].y);
    //printf("h %d %d %d\n",i,h[i].x,h[i].y);
    f[i]=(ll)f[i]*f[i-1]%mod;
  }
  int inv2=pw(2,mod-2);
  for(j=i=n;i;--i){
    int res=(ll)f[n]*inv2%mod*(ask(T,a[i])-ask(T,rs[a[i]]+1)+mod)%mod*pw(h[a[i]].x,mod-2)%mod;
    //printf("%d %d %d %d\n",i,f[n],ask(a[i]),h[i].x);
    //printf("res1 %d %d\n",i,res);
    ans=(ans+res)%mod;
    add(T,a[i],h[a[i]].x);
  }
  for(i=1;i<=n;++i)T[i]=0;
  for(j=i=1;i<=n;++i){
    int res=((ll)f[n]*ask(S,a[i]+1)%mod-(ll)f[n]*inv2%mod*(ask(T,a[i]+1)-ask(T,rs[a[i]]+1)+mod)%mod*pw(h[a[i]].x,mod-2)%mod)%mod;
    ans=(ans+res)%mod;
    add(T,a[i],h[a[i]].x);
    add(S,a[i],1);
  }
  if(ans<0)ans+=mod;
  printf("%d\n",ans);
  return 0;
}


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

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n;
    string s;
    cin >> n >> s;
    string ans = s;
    int cnt = 0;
    for(int i = 0; i < n; i++){
        if(s[i] == '(') cnt++;
        else{
            if(cnt > 0) cnt--;
            else ans = '(' + ans;
        }
    }
    cnt = 0;
    for(int i = n-1; i >= 0; i--){
        if(s[i] == ')') cnt++;
        else{
            if(cnt > 0) cnt--;
            else ans = ans + ')';
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
using System;
using System.Linq;
using System.Numerics;

   class Program
    {
        static void Main()
        {
            var INF = int.MaxValue;
            var line1 = Console.ReadLine().Split().Select(int.Parse).ToArray();
            var N = line1[0];
            var K = line1[1];
            var steps = Console.ReadLine().Split().Select(int.Parse).ToArray();
            var dp = Enumerable.Repeat((int)INF, N + 1).ToArray();
            dp[0] = 0;
            dp[1] = Math.Abs(steps[1] - steps[0]);
            for (int i = 1; i < N; i++)
            {
                for (int j = 1; (i - j) >= 0 && j <= K; j++)
                {
                    dp[i] = Math.Min(dp[i - j] + Math.Abs(steps[i] - steps[i - j]), dp[i]);
                }
            }
            Console.WriteLine(dp[N - 1]);
        }
    }

Measured memory_bytes: 36548
#include <bits/stdc++.h>
using namespace std;
 
int main() {
 
  int a, b, ans;
  cin >> a >> b;
  ans = a*b;
  if(ans%2 == 0){
  	cout << "Even"<< endl;
  }
  else{
  	cout << "Odd"<< endl;
  }
  
   
}

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

int main(){
    vector<int> a(3);
    for(int i=0;i<3;i++)cin>>a[i];
    sort(a.begin(),a.end());
    cout<<(a[1]-a[0])+(a[2]-a[1])<<endl;
    return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        // 整数の入力
        int N = sc.nextInt();
        int[] A = new int[N];
        int[] B = new int[50];
        int[] C = new int[50];
        for(int i=0;i<N;i++){
            A[i] = sc.nextInt()-1;
        }
        for(int i=0;i<N;i++){
            B[i] = sc.nextInt();
        }
        for(int i=0;i<N-1;i++){
            C[i] = sc.nextInt();
        }
        int manzoku=0;
        int bef = A[0];
        manzoku += B[A[0]];
        for(int i=1;i<N;i++){
            //eat A[i];
            int eat = A[i];
            manzoku += B[eat];
            if(eat ==  bef+1){
                manzoku += C[bef];
            }
            bef = eat;
        }
        System.out.println(manzoku);
    }
}


Measured memory_bytes: 23892
import collections
n = int(input())
s = list()
for i in range(n):
    s.append(input())
l = collections.Counter(s)
count = list(l.items())
count.sort(key=lambda x: x[1], reverse=True)
ind, x = 0, count[0][1]
for i in range(len(count)):
    if count[i][1] != x:
        ind = i-1
        break
    else:
        ind = i
x = count[:ind+1]
x.sort()
for i in range(ind+1):
    print(x[i][0])


Measured memory_bytes: 47668
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#define ll long long
#define endl '\n'
using namespace std;
using namespace __gnu_pbds;
template<typename T>
using ordered_set =
tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
int memo[100001][3],a,arr[101],k;
int solve(int s,int r){
    int &cur=memo[s][r];
    if(cur!=-1)
        return cur;
    if(r==1)
        cur=0;
    else
        cur=1;
    for(int i=0;i<a;i++){
        if(r==1){
            if(s-arr[i]>=0){
                cur|=solve(s-arr[i],2);
            }
        }
        else{
            if(s-arr[i]>=0) {
                cur &= solve(s - arr[i], 1);
            }
        }
    }
    return cur;
}
int main() {
    ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    memset(memo,-1,sizeof(memo));
    cin>>a>>k;
    for(int i=0;i<a;i++)
        cin>>arr[i];
    if(solve(k,1)){
        cout<<"First"<<endl;
    }
    else{
        cout<<"Second"<<endl;
    }
}

Measured memory_bytes: 9216
n=int(input())
A=[int(i) for i in input().split()]
A=[A[i]-i for i in range(n)]
A.sort()
if n%2==0:
    mid2=A[n//2]+A[n//2-1]
else:
    mid2=A[n//2]*2

B=[i*2 for i in A]
ans=0
for i in range(n):
    ans+=abs(B[i]-mid2)
print(ans//2)
    

Measured memory_bytes: 30820
#include <iostream>
#include <cstdio>
#include <vector>
#include <list>
#include <algorithm>
#include <cmath>
#include <stack>
#include <map>
using namespace std;

#define REP(i,n) for(int (i)=0; (i)<(n); (i)++)
#define FOR(i,a,b) for(int (i)=(a); (i)<(b); (i)++)
#define PUSH(n,v) for(int i=0; i<(n); i++) {int j; cin >> j; v.push_back(j);}
#define ALL(v) v.begin(), v.end()
#define print(s) cout << (s) << endl

int AA;
int BB;
int AB;
int OO;

int main() {
    int n;
    char c;
    string s;
    while(cin >> n >> c >> s) {
        if (s == "A") {
            AA++;
        }else if (s == "B") {
            BB++;
        }else if (s == "O") {
            OO++;
        }else {
            AB++;
        }
    }
    print(AA);
    print(BB);
    print(AB);
    print(OO);
    return 0;
}

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

using namespace std;

const int MOD = 1000000007;

int main(){
    int N;
    while(cin >> N){
        vector<long long> C(N);
        for(auto& t : C) cin >> t;
        sort(C.begin(), C.end());
        long long d2 = 1;
        for(int i=0;i<2*(N-1);i++) d2 = (2*d2)%MOD;
        long long d3 = (2*d2)%MOD;
        long long sum = 0;
        for(int i=0;i<N;i++){
            sum += (d2 * (N-1-i) + d3) % MOD * C[i];
            sum %= MOD;
        }
        cout << sum << endl;
    }
}

Measured memory_bytes: 1792
#include<cstdio>
#include<cstring>
#include<cmath>
#include<algorithm>
using namespace std;
int a, b;
int main(){
  scanf("%1d%1d", &a, &b);
  if(a == 9 || b == 9) printf("Yes\n");
  else printf("No\n");
  return 0;
}

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

int main()
{
	int h, w;
	
	cin >> h >> w;
	
	while ((h!=0)&&(w!=0)) {
		for (int i=0; i < h; i++) {
			for ( int j=0; j < w ; j++)
				if((i+j)%2)
					cout << '.';
				else
					cout << '#';
			cout << endl;
		}
		cout << endl;
		cin >> h >> w;
	}
	return 0;
}

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

public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);

		// 入力
		int n = sc.nextInt();// 列数

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

		// 計算
		int maxCandies = 0;

		for(int m = 0; m < n; m++){
			int temp = 0;
			for(int k = 0; k <= m; k++){
				temp = temp + a[0][k];
			}
			for(int k = m; k < n; k++){
				temp = temp + a[1][k];
			}
			maxCandies = max(maxCandies, temp);
		}
		// 出力
		System.out.println(maxCandies);
	}
}




Measured memory_bytes: 23764
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <vector>
#include <queue>
#include <stack>
#include <cmath>

using namespace std;

const int MAXN = 100000 + 1000;
const long long INF = 0x1f1f1f1f1f1f1f1fll;

typedef pair<int, int> pii;

int n, x, y, z;
pii s[MAXN];
long long f[MAXN], g[MAXN];

bool cmp(const pii &x, const pii &y)
{
	return x.first - x.second > y.first - y.second;
}

void calc1()
{
	priority_queue<int, vector<int>, greater<int> > heap;
	long long sum = 0;
	for(int i = 1; i <= n; i++)
	{
		sum += s[i].first;
		heap.push(s[i].first);
		while(heap.size() > x)
			sum -= heap.top(), heap.pop();
		f[i] = sum;
	}
}

void calc2()
{
	priority_queue<int, vector<int>, greater<int> > heap;
	long long sum = 0;
	for(int i = n; i >= 1; i--)
	{
		sum += s[i].second;
		heap.push(s[i].second);
		while(heap.size() > y)
			sum -= heap.top(), heap.pop();
		g[i] = sum;
	}
}

int main()
{
	ios::sync_with_stdio(false);
	// freopen("1.in", "r", stdin);
	// freopen("1.out", "w", stdout);

	cin >> x >> y >> z;
	n = x + y + z;
	long long sum = 0;
	for(int i = 1; i <= n; i++)
	{
		int a, b, c;
		cin >> a >> b >> c;
		sum += c;
		s[i] = make_pair(a - c, b - c);
	}

	sort(s + 1, s + n + 1, cmp);

	calc1();
	calc2();


	long long ans = -INF;
	for(int i = x; i <= x + z; i++)
		ans = max(ans, f[i] + g[i + 1]);
	ans += sum;
	cout << ans << endl;

	return 0;
}


Measured memory_bytes: 3064
#include <iostream>

using namespace std;

typedef long long ll;

ll nwd(ll a, ll b)
{
    ll c;
    while (b != 0)
    {
        c = a % b;
        a = b;
        b = c;
    }
    return a;
}

ll nww(ll a, ll b)
{
    ll d = nwd(a, b);
    a /= d;
    b /= d;
    return a * b * d;
}

int main()
{
    ios_base::sync_with_stdio(0);
    int n;
    cin >> n;
    ll d;
    for (int i = 0; i < n; ++i)
    {
        ll x;
        cin >> x;
        if (i == 0)
            d = x;
        else
            d = nww(x, d);
    }
    cout << d;
    return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
int main(void)
{
  int n,i,j,k;
  int b,f,r,v;
  scanf("%d",&n);
  int room[4][3][10]={0};
  for(i=0;i<n;i++)
  {
    scanf("%d %d %d %d",&b,&f,&r,&v);
    room[b-1][f-1][r-1]+=v;
  }
  for(i=0;i<4;i++)
  {
    for(j=0;j<3;j++)
    {
      for(k=0;k<10;k++)
      {
        printf(" %d",room[i][j][k]);
      }
      printf("\n");
    }
    if(i!=3)
      printf("####################\n");
  }
  return 0;
}



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

namespace ABC083C
{
    class Program
    {
        static void Main(string[] args)
        {
            var XY = Console.ReadLine().Split().Select(long.Parse).ToArray();

            var remain = XY[1] / XY[0];
            int ans = 0;
            for(int i=0; remain > 0; i++)
            {
                remain /= 2;
                ans++;
            }

            Console.WriteLine(ans);
            Console.ReadKey();
        }
    }
}


Measured memory_bytes: 13396
#include <bits/stdc++.h>
#define int long long
const int INF = 1e18L + 5;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep2(i, s, n) for (int i = (s); i < (int)(n); i++)
using namespace std;

int Expected_value(int n) {
    return n+1;
} //↑2で割るのを最後に変えたのでその名残

signed main() {

    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout << fixed << setprecision(15);
  
    int n, k; cin >> n >> k;
    vector<int> a(n);
    rep(i,n) cin >> a[i];
    int sum = 0;
    int mx = 0;
    rep(i,n) {
        if (i <= k-1) {
            sum += Expected_value(a[i]);
            mx = sum;
        }
        else {
            sum = sum + Expected_value(a[i]) - Expected_value(a[i-k]);
            mx = max(mx,sum);
        }
    } 
    
    cout << mx/2.0000000000000 << endl;
    return 0;
}

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

int main( void )
{
  int N, Y;
  cin >> N >> Y;
  int res10000 = -1, res5000 = -1, res1000 = -1;

  for( int i = 0; i <= N; i++ ) {
    for( int j = 0; i + j <= N; j++ ) {
      int k = N - i - j;
      if( 10000 * i + 5000 * j + 1000 * k == Y ) {
	res10000 = i;
	res5000 = j;
	res1000 = k;
      }
    }
  }

  cout << res10000 << " " << res5000 << " " << res1000 << endl;
}
      

Measured memory_bytes: 3648
n = int(input())
a = []
for i in range(n):
  x,y,h = map(int,input().split())
  a.append([x,y,h])
a.sort(key=lambda x:  -x[2])
def test(t,b,c):
  for k in a:
    if c - (abs(t - k[0]) + abs(b-k[1])) != k[2]:
      if (c - (abs(t - k[0]) + abs(b-k[1])) < 0 and k[2] == 0):
        continue
      else:
        return False
  return True
for i in range(101):
  for j in range(101):
    h = abs(i-a[0][0]) + abs(j - a[0][1]) + a[0][2]
    if test(i,j,h):
      print(i,j,h)
      exit()

Measured memory_bytes: 3188
#include<stdio.h>
#include<stdlib.h>
int main()
{
    int X,Y;
    scanf("%d%d",&X,&Y);
    int a,b;
    a = (4*X - Y);//X=m+n Y=2m+4n n=X-m Y=2m+4(X-m)=4X-2m m=(4x-y/2) n=(y-2x )
    b = (Y-2*X);
    if(a/2>=0 && b/2>=0 && a%2==0 && b%2==0)
    {
        printf("Yes\n");
    } 
    else
    {
        printf("No\n");
    }
    return 0;   
}

Measured memory_bytes: 1640
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <math.h>
#include <functional>
#include <iomanip>
#include <bitset>
#include <numeric>
#include <queue>
#include <map>
#include <cstdint>
using namespace std;
#define rep(i, n) for (int i = 0; i < n; i++)
const long long mod = 1000000007;
typedef long long int ll;
typedef pair<ll, ll> P;
const vector<int> di = { -1, 0, 1, 0 };
const vector<int> dj = { 0, 1, 0, -1 };
const double PI = 3.14159265358979323846;

int main() {

	int n, k;
	cin >> n >> k;
	vector<int> l(n);
	rep(i, n) cin >> l.at(i);

	sort(l.begin(), l.end());
	reverse(l.begin(), l.end());
	int sum = 0;
	rep(i, k) {
		sum += l.at(i);
	}
	cout << sum << endl;
	return 0;
	
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(){
	int n,m,k;
	cin>>n>>m;
	for(int i=1;i<=m;i++){
		cin>>k;
		n-=k;
	}
	if(n<0) cout<<-1<<endl;
	else cout<<n<<endl;
	return 0;
}

Measured memory_bytes: 3632
import java.util.*;

public class Main{
    public static void main(String args[]){
        Scanner sn = new Scanner(System.in);
        int N = sn.nextInt();
        int result = 0;
        int a = 0;

        for(int i=1; i<=N; i++){
            for(int j=1; j<=N; j++){
                a =gcd(i, j);
                for(int k=1; k<=N; k++){
                    result += gcd(a, k);
                }
            }
        }
        System.out.println(result);
    }

    public static int gcd(int p, int q){
        if(p % q == 0){
            return q;
        }
        return gcd(q, p%q);
    }
}

Measured memory_bytes: 35768
N = int(input())
W_list = list(map(int, input().split()))

W_list_sum = sum(W_list)
tmp_sum = 0
tmp_result = 100000
for w in W_list:
    tmp_sum += w
    W_list_sum -= w
    tmp_result = min(abs(tmp_sum - W_list_sum), tmp_result)

print(tmp_result)

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

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

    int ans = 0;
    for (int i = 0; i < s.size(); i++) {
        s[i] == '+' ? ans++ : ans--;
    }

    cout << ans << endl;

    return 0;
}


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


int main() {
    ios_base::sync_with_stdio(false); cin.tie(NULL);
    int n, k;
    cin >> n >> k;
    long long v[n], dp[n];
    for(long long &i: dp) {
        i = 1e18;
    }
    for(long long &i: v) {
        cin >> i;
    }
    dp[n-1] = 0;
    for(int i=n-2; i>=0; i--) {
        for(int j=i+1; j < n && j-i <= k; j++)
            dp[i] = min(dp[i], abs(v[j]-v[i]) + dp[j]);
    }
    cout << dp[0] << '\n';
    return 0;
}

Measured memory_bytes: 1792
#include <bits/stdc++.h> 
typedef long long ll;
using namespace std;
int main() { 
  cin.tie(0);
  ios::sync_with_stdio(false);
  int a,b,c,k;
  cin>>a>>b>>c>>k; 	 
  while(a>=b && k>0){
    b*=2;
    k--;
  }
  while(b>=c && k>0){
    c*=2;
    k--;
  }
  if(a<b && b<c){
    cout<<"Yes"<<endl;
    }else{
    cout<<"No"<<endl;
    }
return 0; 
}

Measured memory_bytes: 3652
import math
N = 10**5
Q = int(input())

# 素数のリストを作る
sosus = {2: 0, 3: 0}
for i in range(5, N, 2):
    isSosu = True
    for j in range(3, int(math.sqrt(i))+1, 2):
        if i % j == 0:
            isSosu = False
            break
    if isSosu:
        sosus[i] = 0

#print(sosus)

# その数までに2017的な数が何個あるか管理する配列
ans = [0 for i in range(N)]
count = 0
for i in range(N):
    if i % 2 != 0:
        if i in sosus and (i+1)//2 in sosus:
            count += 1

    ans[i] = count


#print(ans[:15])

for _ in range(Q):
    l, r = map(int, input().split())
    print(ans[r]-ans[l-1])


Measured memory_bytes: 10428
def main():
    N = int(input())
    A = list(map(int, input().split()))

    if 0 in A:
        print(0)
        return

    ans = 1
    for a in A:
        ans *= a
        if ans > 1000000000000000000:
            print(-1)
            return

    print(ans)

main()


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

typedef long long ll;
const int INF = 1e9;
const int MOD = 1e9 + 7;
const ll LINF = 1e18;
#define y0 y3487465
#define y1 y8687969
#define j0 j1347829
#define j1 j234892
#define next asdnext
#define prev asdprev
#define dump(x)  cout << #x << " = " << (x) << endl;	//debug
#define SZ(x) ((int)(x).size())
#define REP(i, n) for(ll i = 0; i < (n); i++)
#define REPR(i, n) for (ll i = (n); i >= 0; i--)
#define FOR(i, a, b) for (ll i = (a); i <= (b); i++)
#define RFOR(i, a, b) for (ll i = (a); i >= (b); i--)
#define ps(s) cout << #s << endl;
#define pv(v) cout << (v) << endl;
#define pvd(v) cout << setprecision(16) << res << endl;
#define ALL(a)  (a).begin(),(a).end()
#define RANGE(a, l, r)  (a).begin()+(l),(a).begin()+(r)


int main() {
	int n;
	cin >> n;
	vector<vector<pair<int, bool>>> info(n + 1);
	FOR(i, 1, n) {
		int a;
		cin >> a;
		FOR(j, 1, a) {
			int x;
			bool y;
			cin >> x >> y;
			info[i].push_back(make_pair(x, y));
		}
	}
	
	int res = 0;
	for (int bit = 0; bit < (1 << (n)); bit++) {
		vector<bool> memo(n+1,false);
		bool isok = true;
		FOR(digit, 1, n) {
			if (bit&(1 << (digit - 1))) {
				memo[digit] = true;
			}
		}
		FOR(digit, 1, n) {
			if (bit&(1 << (digit - 1))) {
				FOR(i, 0, SZ(info[digit]) - 1) {
					if (memo[info[digit][i].first]!= info[digit][i].second) {
						isok = false;
					}
				}
			}
		}

		if (!isok) {
			continue;
		}

		int cnt = 0;
		FOR(i, 1, n) {
			if (memo[i]) {
				cnt++;
			}
		}
		res = max(res, cnt);
	}
	pv(res)
	return(0);
}

Measured memory_bytes: 256
#include<cstdio>
#include<cctype>
using namespace std;
const int N=5e5+5;
int a[N],d[N],f[N];
inline int read()
{
    int X=0,w=0; char ch=0;
    while(!isdigit(ch)) w|=ch=='-',ch=getchar();
    while(isdigit(ch)) X=(X<<3)+(X<<1)+(ch^48),ch=getchar();
    return w?-X:X;
}
inline int min(int x,int y)
{
	return x<y?x:y;
}
inline int abs(int x)
{
	return x<0?-x:x;
}
int main()
{
	int n=read();
	a[0]=read();
	for(int i=1;i<=n;i++)
	{
		d[i]=read();
		a[i]=min(a[i-1],abs(a[i-1]-d[i]));
	}
	f[n+1]=1;
	for(int i=n;i;i--)
	{
		f[i]=f[i+1];
		if(d[i]<f[i]<<1) f[i]+=d[i];
	}
	int q=read();
	while(q--)
	{
		int x=read();
		puts(a[x-1]>=f[x+1]?"YES":"NO");
	}
	return 0;
}

Measured memory_bytes: 7680
#include<iostream>
#include<algorithm>
#include<vector>
#include<queue>
#include<stack>
#include<list>
#include<set>
#include<string>
using namespace std;
int gcd(int a, int b) {
	int c = a % b;
	while (c != 0) {
		a = b;
		b = c;
		c = a % b;
	}
	return b;
}
struct UnionFind {
	vector<int> par; // par[i]:iの親の番号　(例) par[3] = 2 : 3の親が2

	UnionFind(int N) : par(N) { //最初は全てが根であるとして初期化
		for (int i = 0; i < N; i++) par[i] = i;
	}

	int root(int x) { // データxが属する木の根を再帰で得る：root(x) = {xの木の根}
		if (par[x] == x) return x;
		return par[x] = root(par[x]);
	}

	void unite(int x, int y) { // xとyの木を併合
		int rx = root(x); //xの根をrx
		int ry = root(y); //yの根をry
		if (rx == ry) return; //xとyの根が同じ(=同じ木にある)時はそのまま
		par[rx] = ry; //xとyの根が同じでない(=同じ木にない)時：xの根rxをyの根ryにつける
	}

	bool same(int x, int y) { // 2つのデータx, yが属する木が同じならtrueを返す
		int rx = root(x);
		int ry = root(y);
		return rx == ry;
	}
};
typedef long long ll;

ll M = 1000000007;

vector<ll> fac(300001); //n!(mod M)
vector<ll> ifac(300001); //k!^{M-2} (mod M)

ll mpow(ll x, ll n) {
	ll ans = 1;
	while (n != 0) {
		if (n & 1) ans = ans * x % M;
		x = x * x % M;
		n = n >> 1;
	}
	return ans;
}
ll comb(ll a, ll b) {
	if (a == 0 && b == 0)return 1;
	if (a < b || a < 0)return 0;
	ll tmp = ifac[a - b] * ifac[b] % M;
	return tmp * fac[a] % M;
}
// mod. m での a の逆元 a^{-1} を計算する
long long modinv(long long a) {
	long long b = M, u = 1, v = 0;
	while (b) {
		long long t = a / b;
		a -= t * b; swap(a, b);
		u -= t * v; swap(u, v);
	}
	u %= M;
	if (u < 0) u += M;
	return u;
}
vector<vector<ll>> mul(vector<vector<ll>> a, vector<vector<ll>> b, int n) {
	int i, j, k, t;
	vector<vector<ll>> c(n);
	for (i = 0; i < n; i++) {
		for (j = 0; j < n; j++) {
			t = 0;
			for (k = 0; k < n; k++)
				t = (t + a[i][k] * b[k][j] % M) % M;
			c[i].push_back(t);
		}
	}
	return c;
}

template< typename Monoid >
struct SegmentTree {

	int sz;
	vector< Monoid > seg;

	const Monoid M1;

	SegmentTree(int n, const Monoid &M1) : M1(M1) {
		sz = 1;
		while (sz < n) sz <<= 1;
		seg.assign(2 * sz, M1);
	}

	void set(int k, const Monoid &x) {
		seg[k + sz] = x;
	}

	void build() {
		for (int k = sz - 1; k > 0; k--) {
			seg[k] = f(seg[2 * k + 0], seg[2 * k + 1]);
		}
	}

	void update(int k, const Monoid &x) {
		k += sz;
		seg[k] = x;
		while (k >>= 1) {
			seg[k] = f(seg[2 * k + 0], seg[2 * k + 1]);
		}
	}

	Monoid query(int a, int b) {
		Monoid L = M1, R = M1;
		for (a += sz, b += sz; a < b; a >>= 1, b >>= 1) {
			if (a & 1) L = f(L, seg[a++]);
			if (b & 1) R = f(seg[--b], R);
		}
		return f(L, R);
	}

	Monoid value(const int &k) const {
		return seg[k + sz];
	}

	Monoid f(Monoid a, Monoid b) {
		return a + b;
	}
};

int main() {
	ll n, i, ans = 1;
	cin >> n;
	for (i = 1; i <= n; i++)
		ans = ans * i%M;
	cout << ans << endl;
}

Measured memory_bytes: 4992
#include<bits/stdc++.h>
#define mo 1000000007
#define pi 3.1415926535898
#define eps 1e-9 
using namespace std;
long long read(){
    long long xx=0,flagg=1;
    char ch=getchar();
    while((ch<'0'||ch>'9')&&ch!='-')
        ch=getchar();
    if(ch=='-'){
        flagg=-1;
        ch=getchar();
    }
    while(ch>='0'&&ch<='9'){
        xx=xx*10+ch-'0';
        ch=getchar();
    }
    return xx*flagg;
}
void pus(long long xx,long long flagg){
    if(xx<0){
        putchar('-');
        xx=-xx;
    }
    if(xx>=10)
        pus(xx/10,0);
    putchar(xx%10+'0');
    if(flagg==1)
        putchar(' ');
    if(flagg==2)
        putchar('\n');
    return;
}
int n,m,i,j,k,l,r,x,maxj,minj,maxk,mink,f[305][305][305],ans;
int top,qu[305],nex[305],to[305],fir[305];
int add(int u,int v){
	return u+v>=mo?u+v-mo:u+v;
}
void lj(int u,int v,int w){
	top++;
	nex[top]=fir[u];
	fir[u]=top;
	to[top]=v;
	qu[top]=w;
}
int main(){
	//freopen("a.in","r",stdin);
	//freopen("a.out","w",stdout);
	n=read();m=read();
	for(i=1;i<=m;i++){
		l=read();r=read();x=read();
		lj(r,l,x);
	}
	f[0][0][0]=1;
	for(i=0;i<=n;i++){
		mink=0;
		maxk=i;
		minj=0;
		maxj=i;
		for(int top1=fir[i];top1;top1=nex[top1]){
			if(qu[top1]==1)
				maxj=min(maxj,to[top1]-1);
			if(qu[top1]==2){
				minj=max(minj,to[top1]);
				maxk=min(maxk,to[top1]-1);
			}
			if(qu[top1]==3)
				mink=max(mink,to[top1]);
		}
		if(i!=n){
			for(j=minj;j<=maxj;j++)
				for(k=mink;k<=maxk;k++){
					f[i+1][j][k]=add(f[i][j][k],f[i+1][j][k]);
					f[i+1][i][k]=add(f[i][j][k],f[i+1][i][k]);
					f[i+1][i][j]=add(f[i][j][k],f[i+1][i][j]);
				}
		}
		else{
			for(j=minj;j<=maxj;j++)
				for(k=mink;k<=maxk;k++)
					ans=add(ans,f[i][j][k]);
		}
	}
	pus(ans,2);
	return 0;
}

Measured memory_bytes: 108800
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<iostream>
#include<string>
#include<vector>
#include<stack>
#include<bitset>
#include<cstdlib>
#include<cmath>
#include<set>
#include<list>
#include<deque>
#include<map>
#include<queue>
using namespace std;
typedef long long ll;

int main(){
    ll n,a[100],m=1000,s=0;
    cin>>n;
    for(int i=1;i<=n;i++){
        cin>>a[i];
        if(i>1){
            if(a[i]>a[i-1]){
                s+=m/a[i-1];
                m%=a[i-1];
            }else{
                m+=s*a[i-1];
                s=0;
            }
        }
    }
    m+=s*a[n];
    cout<<m<<endl;
    return 0;
}

Measured memory_bytes: 3144
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		int a = scan.nextInt();
		int b = scan.nextInt();
		String message = ":(";
		if(a <= 8 && b <= 8) {
			message = "Yay!";
		}
		System.out.println(message);
	}
}

Measured memory_bytes: 23124
import sys

input = sys.stdin.readline
MOD = 1000000007

N = int(input())

a = list(map(int,input().split()))

a.sort(reverse=True)


res = 0

cnt = 0
i = 1
while (cnt < len(a)//3)  :
    res += a[i]
    i += 2
    cnt+=1

print(res)

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

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int a, b, c, d;
  long long n;
  cin >> n;
  long long ans = 0;
  ans+= n/500 * 1000 + (n%500)/5 * 5;
  cout << ans << endl;
}

Measured memory_bytes: 256
import collections
class UnionFind:
    def __init__(self,n):
        super().__init__()
        self.par = [-1]*n
        self.rank = [0]*n
        self.tsize = [1]*n

    
    def root(self,x):
        if self.par[x] == -1:
            return x 
        else:
            self.par[x] = self.root(self.par[x])
            return self.par[x]

    def unite(self, x, y):
        x_r = self.root(x)
        y_r = self.root(y)
        
        if self.rank[x_r]>self.rank[y_r]:
            self.par[y_r] = x_r

        elif self.rank[x_r]<self.rank[y_r]:
            self.par[x_r] = y_r

        elif x_r != y_r:
            self.par[y_r] = x_r
            self.rank[x_r] += 1

        if x_r != y_r:
            size = self.tsize[x_r]+self.tsize[y_r]
            self.tsize[x_r] = size
            self.tsize[y_r] = size

    def isSame(self,x,y):
        return self.root(x) == self.root(y)

    def size(self,x):
        return self.tsize[self.root(x)]

def main():
    n,k,l = tuple([int(t)for t in input().split()])

    uf_k = UnionFind(n)
    uf_l = UnionFind(n)


    pq = [[int(t)-1 for t in input().split()]for _ in [0]*k]
    for p,q in pq:
        uf_k.unite(p,q)

    rs = [[int(t)-1 for t in input().split()]for _ in [0]*l]
    for r,s in rs:
        uf_l.unite(r,s)

    pair = []
    for i in range(n):
        pair.append((uf_k.root(i),uf_l.root(i)))
    counter = collections.Counter(pair)
    
    ans = []
    for a in pair:
        ans.append(counter[a])
    print(*ans)
    
if __name__ == "__main__":
    main()


Measured memory_bytes: 137144
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <vector>
#include <cstring>
#include <cmath>
#include <queue>
#include <functional>
#include <set>
#include <map>
#include <deque>
#define SIZE 1005
#define DINF 1e15
#define EPS 1e-12

using namespace std;
typedef long long int ll;
typedef pair <double,int> P;

double dist[SIZE][SIZE];
int X[SIZE],Y[SIZE],R[SIZE];
double dp[SIZE];

double gt(P p,P q)
{
	ll dx=p.first-q.first,dy=p.second-q.second;
	return sqrt((double) (dx*dx+dy*dy));
}
int main()
{
	scanf("%d %d %d %d",&X[0],&Y[0],&X[1],&Y[1]);
	R[0]=R[1]=0;
	int n;
	scanf("%d",&n);n+=2;
	for(int i=2;i<n;i++)
	{
		scanf("%d %d %d",&X[i],&Y[i],&R[i]);
	}
	for(int i=0;i<n;i++)
	{
		for(int j=0;j<n;j++)
		{
			dist[i][j]=gt(P(X[i],Y[i]),P(X[j],Y[j]))-R[i]-R[j];
			dist[i][j]=max(dist[i][j],0.0);
		}
	}
	priority_queue <P,vector <P>,greater <P> > que;
	for(int i=0;i<n;i++) dp[i]=DINF;
	dp[0]=0;
	que.push(P(0.0,0));
	while(!que.empty())
	{
		P p=que.top();que.pop();
		int v=p.second;
		if(dp[v]+EPS<p.first) continue;
		for(int i=0;i<n;i++)
		{
			if(dp[i]>dp[v]+dist[v][i]+EPS)
			{
				dp[i]=dp[v]+dist[v][i];
				que.push(P(dp[i],i));
			}
		}
	}
	printf("%.10f\n",dp[1]);
	return 0;
}


Measured memory_bytes: 12400