akhauriyash/Code-Regression huggingface dataset:
#include<cstdio>
#include<cstring>
#include<cmath>
#include<algorithm>
using namespace std;
const int N=101101;
char S[N],T[N],s[N];
int check(){
	int n=strlen(S),m=strlen(s);
	if (n!=m)	return 0;
	for (int i=0; i<n; i++)
		if (S[i]!=s[i])	return 0;	
	return 1;	
}

int main(){
	int n,m;
	scanf("%s%s",S,T);
	scanf("%d%d",&n,&m);
	scanf("%s",s);
	if (check())	n--;
	else m--;
	printf("%d %d\n",n,m);
	return 0;
}

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

using namespace std;

#define LL long long
#define N 320000
#define INF 0x3f3f3f3f3f3fLL

LL n,m,x,y,a[N],f[N],g[N],h[N],pre[N],ff[N],dp[N],stk[N];

inline double calc(LL x,LL y){return 1.0*(ff[x]-ff[y])/(x-y);}

void dp1(LL a[],LL f[]){
	pre[0]=a[0]; for (LL i=1;i<=n;++i) pre[i]=pre[i-1]+a[i];
	f[0]=0; ff[0]=2*pre[0]; stk[1]=0;
	for (LL i=1,tp=1;i<=n+1;++i){
		for (;tp>1&&calc(stk[tp-1],stk[tp])<i*2;--tp);
		f[i]=-2*pre[i-1]+i*i-i+ff[stk[tp]]-2*i*stk[tp];
		ff[i]=f[i]+i*i+i+2*pre[i];
		for (;tp>1&&calc(stk[tp-1],stk[tp])<calc(stk[tp],i);--tp);
		stk[++tp]=i;
	}
}

void solve(LL l,LL r){
	if (l==r){h[l]=max(h[l],f[l-1]+g[l+1]+2-a[l]*2); return;}
	LL mid=(l+r)>>1,tp=0;
	for (LL i=l;i<=mid;++i){
		ff[i]=f[i-1]+i*i-3*i+2*pre[i-1];
		for (;tp>1&&calc(stk[tp-1],stk[tp])<calc(stk[tp],i);--tp);
		stk[++tp]=i;
	}
	for (LL i=mid+1;i<=r;++i){
		for (;tp>1&&calc(stk[tp-1],stk[tp])<i*2;--tp);
		dp[i]=ff[stk[tp]]+g[i+1]+i*i+3*i-2*pre[i]+2-2*i*stk[tp];
	}
	dp[r+1]=-INF;
	for (LL i=r;i>mid;--i) h[i]=max(h[i],dp[i]=max(dp[i],dp[i+1]));
	tp=0;
	for (LL i=mid+1;i<=r;++i){
		ff[i]=g[i+1]+i*i+3*i-2*pre[i];
		for (;tp>1&&calc(stk[tp-1],stk[tp])<calc(stk[tp],i);--tp);
		stk[++tp]=i;
	}
	for (LL i=l;i<=mid;++i){
		for (;tp>1&&calc(stk[tp-1],stk[tp])<i*2;--tp);
		dp[i]=ff[stk[tp]]+f[i-1]+i*i-3*i+2*pre[i-1]+2-2*i*stk[tp];
	}
	dp[l-1]=-INF;
	for (LL i=l;i<=mid;++i) h[i]=max(h[i],dp[i]=max(dp[i],dp[i-1]));
	solve(l,mid); solve(mid+1,r);
}

int main(){
	scanf("%lld",&n);
	a[0]=a[n+1]=INF; for (LL i=1;i<=n;++i) scanf("%lld",a+i);
	dp1(a,f);
	reverse(a,a+n+2);
	dp1(a,g);
	reverse(g,g+n+2); reverse(a,a+n+2);
	pre[0]=a[0]; for (LL i=1;i<=n;++i) pre[i]=pre[i-1]+a[i];
	memset(h,0xcf,sizeof h);
	solve(1,n);
	scanf("%lld",&m);
	while (m--){
		scanf("%lld%lld",&x,&y);
		printf("%lld\n",max(f[x]+g[x],h[x]+a[x]*2-y*2)/2);
	}
	
	return 0;
}
			

Measured memory_bytes: 20352
#include <iostream>
#include <map>
#include <vector>
#include <algorithm>
#include <queue>
#include <math.h>
#include <stack>

using namespace std;
typedef long long ll;
ll mod = 1e9+7;
#define rep(i,n) for(int i = 0; i < (n); ++i)

int main(){
    int n;
    cin >> n;
    n *= 3;
    vector<ll> a(n);
    rep(i, n) cin >> a[i];
    sort(a.begin(), a.end());
    ll ans = 0;
    ll idx = n - 2;
    while(1) {
        if ( n == 0 ) break;
        ans += a[idx];
        idx -= 2;
        n -= 3;
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 2560
#include <iostream>
#include <queue>
#include <vector>
#include <algorithm>
using namespace std;
int main(){
	int n;
	long long int m;
	while( cin >> n >> m && n ){
		//vector<int> list;
		int a[11] = {};
		for( int i = 0; i < n; i++ ){
			int d, p;
			cin >> d >> p;
			a[p] += d;
		}
		int result = 0;
		for( int i = 10; i > 0 && m; i-- ){
			while( m ){
				if( a[i] > 0 ){
					a[i]--;
					m--;
				}else{
					break;
				}
				//cout << m << endl;
			}
		}
		/*for( int i = 0; i < 11; i++ ){
			cout << a[i] << endl;
		}*/
		for( int i = 1; i <= 10; i++ ){
			result += a[i] * i;
		}
		/*
		sort( list.begin(), list.end() );
		reverse( list.begin(), list.end() );
		vector<int>::iterator it = list.begin();
		while( m-- > 0 ){
			it++;
		}
		for( ; it != list.end(); it++ ){
			result += *it;
		}*/
		cout << result << endl;
		//list.clear();
	}
}

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

A,B,M=map(int,input().split())
A=list(map(int,input().split()))
B=list(map(int,input().split()))
W=[tuple(map(int,input().split())) for i in range(M)]

ANS=min(A)+min(B)
for x,y,c in W:
    ANS=min(ANS,A[x-1]+B[y-1]-c)
print(ANS)


Measured memory_bytes: 29504
#include<bits/stdc++.h>
using namespace std;
const int N=105;
int n,x,a[N];
int main()
{
    scanf("%d%d",&n,&x);
    for(int i=1;i<=n;i++) scanf("%d",&a[i]);
    sort(a+1,a+1+n);
    int ans=0;
    for(int i=1;i<=n;i++)
        if(x>=a[i])
    {
        ans++;x-=a[i];
    }
    else break;
    if(x>0&&ans==n) ans--;
    printf("%d\n",ans);
}


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


int main()
{
  int N;
  int a = 0, b = 0;
  int max = -1;
  cin >> N;
  vector<int> cards(N, 0);
  for(int i=0;i<N;i++) {
      cin >> cards.at(i);
  }

  for(int i=0;i<N;i++) {
    int j=0;
    int max = 0;
    int max_index = -1;
    for(j=0;j<N;j++) {
      if (cards.at(j) > max) {
        max = cards.at(j);
        max_index = j;
      }
    }
    cards.at(max_index) *= -1; 
    if (i%2==0) a += max;
    else b += max;
//cout << "+++ " << cards.at(i) << endl;
    
  }
  cout << a - b << endl;
}


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

using namespace std;

int N;
int A[100000];

int main()
{
    cin>>N;
    for(int i=0; i<N; i++)
        cin>>A[i], A[i]--;
    int ans=0;
    for(int i=0; i<N; i++) if(A[A[i]]==i)
        ans++;
    printf("%d\n", ans/2);
    return 0;
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
#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)
using namespace std;
typedef long long int ll;
typedef pair<int,int> P;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<P> vp;
#define dame { puts("-1"); return 0;}
#define yn {puts("Yes");}else{puts("No");}

int main() {
    int n;
    cin >> n;
    vp v;
    rep(i,n){
        P p;
        cin >> p.second >> p.first;
        v.push_back(p);
    }
    sort(v.begin(),v.end());

    int now = 0;
    rep(i,n){
        now += v[i].second;
        if(v[i].first<now){
            cout << "No" << endl;
            return 0;
        }
    }
    cout << "Yes" << endl;
    return 0;
}
 
 


Measured memory_bytes: 2420
import java.util.Scanner;

public class Main{
	static int H, W;
	static int[][] field=new int[51][51];
	static void dfs(int w, int h) {
		if(w>=0 && w<W && h>=0 && h<H) {
		
		if(field[h][w]==1) {
			field[h][w]=2;
			dfs(w+1, h);
			dfs(w-1, h);
			dfs(w, h+1);
			dfs(w, h-1);
			dfs(w+1, h+1);
			dfs(w+1, h-1);
			dfs(w-1, h+1);
			dfs(w-1, h-1);
		}
		}
	}
	public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        while(sc.hasNext()) {
        W = sc.nextInt();
        H = sc.nextInt();
        if(W==0 && H==0) {
        	break;
        }
        int num=0;
        for(int i=0; i<H; i++) {
        	for(int j=0; j<W; j++) {
        		field[i][j]=sc.nextInt();
        	}
        }
        for(int i=0; i<H; i++) {
        	for(int j=0; j<W; j++) {
        		if(field[i][j]==1) {
        			dfs(j, i);
        			num++;
        		}
        	}
        }
        System.out.println(num);
        }
	}
}


Measured memory_bytes: 44884
n = int(input())
s = input()
cnt = 0
abc = ""
for c in s:
    # print(c, abc)
    if c == "A":
        abc = "A"
    elif c == "B" and abc == "A":
        abc ="B"
    elif c == "C" and abc == "B":
        cnt += 1
        abc = ""
    else:
        abc = ""
print(cnt)


Measured memory_bytes: 2940
package main

import (
	"bufio"
	"fmt"
	"io"
	"os"
)

type contest struct {
	in  io.Reader
	out io.Writer
}

func (con *contest) Scan(a ...interface{}) (int, error) {
	return fmt.Fscan(con.in, a...)
}
func (con *contest) Scanln(a ...interface{}) (int, error) {
	return fmt.Fscanln(con.in, a...)
}
func (con *contest) Scanf(f string, a ...interface{}) (int, error) {
	return fmt.Fscanf(con.in, f, a...)
}
func (con *contest) Print(a ...interface{}) (int, error) {
	return fmt.Fprint(con.out, a...)
}
func (con *contest) Println(a ...interface{}) (int, error) {
	return fmt.Fprintln(con.out, a...)
}
func (con *contest) Printf(f string, a ...interface{}) (int, error) {
	return fmt.Fprintf(con.out, f, a...)
}
func main() {
	in := bufio.NewReader(os.Stdin)
	out := bufio.NewWriter(os.Stdout)
	defer out.Flush()
	con := &contest{in: in, out: out}
	con.main()
}

func (con *contest) main() error {
	var n int
	con.Scan(&n)
	min := n
	for i := 1; i*i <= n; i++ {
		if n%i == 0 {
			x := n / i
			if x < i {
				x = i
			}
			if x < min {
				min = x
			}
		}
	}
	d := 0
	for min > 0 {
		d++
		min /= 10
	}
	con.Println(d)
	return nil
}


Measured memory_bytes: 640
#include <vector>
#include <stdio.h>
#include <utility>
#include <bitset>
using namespace std;
typedef pair<int,int> pi;
#define F first
#define S second
#define PB push_back
const int N=20+10;
vector<pi> graph[N];
bitset<N>went;
int temp,top;
int max(int a,int b){return a>b?a:b;}
int min(int a,int b){return a>b?b:a;}
bool dfs(int now,int dep){
    went[now]=true;
    bool f=false;
    for(pi i:graph[now])if(!went[i.F]){
        if(dfs(i.F,dep+i.S))temp+=i.S*2;
        f=true;
    }
    if(f)top=max(top,dep);
    return f;
}
int main(){
    int n,l,r,c;
    while(true){
        scanf("%d",&n);
        if(n==0)return 0;
        for(int i=1;i<=n;i++)graph[i].clear();
        for(int i=1;i<n;i++){
            scanf("%d%d%d",&l,&r,&c);
            graph[l].PB({r,c});
            graph[r].PB({l,c});
        }
        went.reset();
        temp=top=0;
        dfs(1,0);
        printf("%d\n",temp-top);
    }
}


Measured memory_bytes: 2580
import sys

readline = sys.stdin.readline
MOD = 10 ** 9 + 7
INF = float('INF')
sys.setrecursionlimit(10 ** 5)


def main():
    def dfs(cur):
        if not edge[cur]:
            return 0
        else:
            for i, nx in enumerate(edge[cur]):
                dp[nx] = dfs(nx)
            m = []
            for nx in edge[cur]:
                m.append(dp[nx])
            m.sort(reverse=True)
            for i, x in enumerate(m):
                m[i] = x + i + 1
            return max(m)

    from collections import defaultdict
    n = int(readline())
    edge = defaultdict(list)
    dp = [-1] * (n + 1)

    for i in range(2, n + 1):
        a = int(readline())
        edge[a].append(i)

    ans = dfs(1)
    print(ans)


if __name__ == '__main__':
    main()


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

using namespace std;

int main()
{
  long long int N, Y;

  cin >> N >> Y;

  long long int x, y, z;
  x = Y / 10000;
  y = Y / 5000;
  z = Y / 1000;

  for(int i = 0; i <= x; i++) {
    for(int j = 0; j <= y; j++) {
      for(int k = 0; k <= N - i - j; k++) {
	if(i + j + k == N && i * 10000 + j * 5000 + k * 1000 == Y) {
	  cout << i << " " << j << " " << k << endl;
	  return 0;
	}
      }
    }
  }

  cout << "-1 -1 -1" << endl;

  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
	int r,c;
	cin >> r >> c;
	int a[r+1][c+1];
	for(int i=0;i<r+1;i++){
		for(int j=0;j<c+1;j++){
			a[i][j]=0;
		}
	}
	for(int i=0;i<r;i++){
		for(int j=0;j<c;j++){
			cin >> a[i][j];
		}
	}
	for(int i=0;i<r;i++){
		for(int j=0;j<c;j++){
			a[i][c]+=a[i][j];
		}
	}
	for(int j=0;j<c+1;j++){
		for(int i=0;i<r;i++){
			a[r][j]+=a[i][j];
		}
	}
	for(int i=0;i<r+1;i++){
		for(int j=0;j<c+1;j++){
			if(j==c){
				cout << a[i][j];
			}else{
			        cout << a[i][j] << ' ';
			}
		}
		cout << endl;
	}
}




Measured memory_bytes: 3128
program main
  implicit none
  integer :: n
  integer(16), allocatable :: an(:)
  integer :: i
  integer(16) :: threshold, ans
  logical :: flag
  threshold = 1

  do i = 1, 18
    threshold = threshold * 10
  enddo

  read *, n
  allocate(an(n))
  read *, an(1:n)

  if (minval(an) == 0)then
    print "(i0)", 0
  else

    flag = .true.
    ans = 1
    do i = 1, n
      ans = ans * an(i)
      if (ans > threshold)then
        flag = .false.
        exit
      endif
    enddo

    if (flag)then
      print "(i0)", ans
    else
      print "(i0)", -1
    endif
  endif
end program

Measured memory_bytes: 4500
#include <iostream>
#include <vector>
#include <string>
#include <cstring>
#include <map>
#include <list>
#include <set>
#include <stack>
#include <deque>
#include <queue>
#include <cmath>
#include <algorithm>
#include <utility>
#include <functional>
#include <random>
#include <fstream>
#include <sstream>
#include <time.h>
// #define int long long
#define debug(x) cerr << #x << " = " << x << endl
#define FOR(i,a,b) for(int i = (a); i < (b); i++)
#define rep(i,n) for(int i = 0; i < (n); i++)
#define repr(i,n) for(int i = (n); i > -1; i--)
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
const int MOD = 1e9+7;
const ll LINF = 1e18;
const double EPS = 1e-9;


signed main(int argc, char *argv[]) {
  cin.tie(0);
  ios::sync_with_stdio(false);

  ll n;
  cin>>n;
  string s[n];
  map<string, int> st;
  rep(i,n) {
    char c[10];
    rep(j,10) {
      cin>>c[j];
    }
    sort(c, c + 10);
    string s = "";
    rep(j,10) {
      s += c[j];
    }
    // debug(s);
    st[s]++;
  }
  ll ans = 0;
  for(auto a : st) {
    // debug(a.first);
    ll cnt = a.second;
    ans += cnt * (cnt - 1) / 2;
  }
  cout << ans << endl;


  return 0;
}


Measured memory_bytes: 13568
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
const ll MOD = 1e9 + 7;
const ll INF = 1LL << 60;
const double PI = 3.141592653589793238;
const double EPS = 1e-10;
typedef pair<int, int> P;
typedef pair<ll, P> PP;
int main() {
	int N, M;
	cin >> N >> M;
	map<P, vector<PP>> G;
	map<P, ll> dist;
	for (int i = 0; i < M; i++) {
		int p, q;
		ll c;
		cin >> p >> q >> c;
		p--; q--;
		G[P(p, 0)].emplace_back(1, P(p, c));
		G[P(p, c)].emplace_back(0, P(p, 0));
		G[P(q, 0)].emplace_back(1, P(q, c));
		G[P(q, c)].emplace_back(0, P(q, 0));
		G[P(p, c)].emplace_back(0, P(q, c));
		G[P(q, c)].emplace_back(0, P(p, c));
	}
	priority_queue<PP, vector<PP>, greater<PP>> Q;
	dist[P(0, 0)] = 0;
	Q.push(PP(0, P(0, 0)));
	while (!Q.empty()) {
		PP now = Q.top(); Q.pop();
		if (dist[now.second] < now.first) continue;
		for (auto e : G[now.second]) {
			if (dist.find(e.second) == dist.end() || dist[e.second] > now.first + e.first) {
				dist[e.second] = now.first + e.first;
				Q.push(PP(dist[e.second], e.second));
			}
		}
	}
	if (dist.find(P(N - 1, 0)) == dist.end()) {
		cout << -1 << endl;
		return 0;
	}
	cout << dist[P(N - 1, 0)] << endl;
}


Measured memory_bytes: 101232
#include<cstdio>
#include<iostream>

#define rep(i,a,b) for(int (i)=(a);(i)<(b);(i)++)
using namespace std;



int main(){
	int N = 0,M=0,K=0;
	cin >> N;
	while (N != 0){
		int data[101][101] = { 0 };
		int st[101];
		rep(i, 0, N){
			cin >> M;
			rep(j, 0, M){
				int temp;
				cin >> temp;
				data[i][temp - 1] = 1;
			}
		}
		cin >> K;
		rep(i, 0, K){
			int temp;
			cin >> temp;
			st[i] = temp-1;
		}
		rep(k, 0, K)
			rep(i,0,N)
		if (data[i][0] >= 0){
			if (!(data[i][st[k]] & 1))
				data[i][0] = -1;
		}
		int count = 0;
		int member = 0;
		rep(i, 0, N)if (data[i][0] >= 0)count++, member = i;
		if (count == 1)cout << member+1<<endl;
		else cout << -1<<endl;


		cin >> N;
	}






	return(0);
}

Measured memory_bytes: 1208
// Ver19.03
#include <math.h>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#define INF 1 << 29
#define LLINF 4545454545454545454
#define MOD 1000000007
#define ll long long
#define ull unsigned long long
#define MAX(a, b) ((a) > (b) ? (a) : (b))
#define MIN(a, b) ((a) < (b) ? (a) : (b))
int upll(const void *a, const void *b) { return *(ll *)a < *(ll *)b ? -1 : *(ll *)a > *(ll *)b ? 1 : 0; }
int downll(const void *a, const void *b) { return *(ll *)a < *(ll *)b ? 1 : *(ll *)a > *(ll *)b ? -1 : 0; }
void sortup(ll *a, int n) { qsort(a, n, sizeof(ll), upll); }
void sortdown(ll *a, int n) { qsort(a, n, sizeof(ll), downll); }

ll ryuca(ll n)
{
  ll a = 2, b = 1;
  if (n == 1)
    return 1;
  for (int i = 0; i < n / 2; i++)
  {
    a += b;
    b += a;
  }
  return (n % 2 == 0 ? a : b);
};

int main()
{
  ll n;
  scanf("%lld", &n);
  printf("%lld\n", ryuca(n));
  return 0;
}

Measured memory_bytes: 128
#include <stdio.h>
#include <math.h>

int main( void ) {
	int e, ee, y, z, min;

	for ( ; scanf( "%d", &e ), min = e; printf( "%d\n", min ) )
		for ( z = 0; y = sqrt( ee = e - z * z * z ), ee >= 0; z++ )
			if ( ee - y * y + y + z < min )
				min = ee - y * y + y + z;

	return 0;
}

Measured memory_bytes: 608
var input = require('fs').readFileSync('/dev/stdin', 'utf8');
var lines = input.trim().split('\n');
 
var lm = [];
var line;
while (line = lines.shift()) {
    lm.push(line.split(',')[0]);
}

var tm = [];
while (line = lines.shift()) {
    tm.push(line.split(',')[0]);
}

lm.sort(function(a,b){return a-b;});

lm.filter(function(e,i,a){return a.indexOf(e) == i}).forEach(function(c) {
    var cnt = tm.filter(function(n){return n == c;}).length;
    if (cnt > 0) {
        var tcnt = lm.filter(function(n){return n == c}).length;
        console.log(c, cnt + tcnt);
    }
});

Measured memory_bytes: 7640
#include <iostream>
#include <string>
#include <algorithm>

using namespace std;
int main(void){
  int n, a, b;
  int ans = 0;
  int t=0;
  int nn=0;
  cin >> n >> a >> b;

  for(int i=1; i<=n; i++){
    t=0;
    nn=i;
    do{
      t+=nn % 10;
      nn/=10;
    }while(nn!=0);
    if(a<=t && t<=b){
      ans += i;
    }
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>                                           
 
#define int long long
//#pragma GCC optimize("Ofast")
//#pragma comment(linker, "/stack:200000000")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4")
 
 
#define file(s) freopen(s".in","r",stdin); freopen(s".out","w",stdout);
#define forev(i, b, a) for(int i = (b); i >= (a); --i)
#define forn(i, a, b) for(int i = (a); i <= (b); ++i)
#define all(x) x.begin(), x.end()
#define sz(s) (int)s.size()
#define pb push_back
#define ppb pop_back
#define s second
#define f first
 
 
using namespace std;
 
 
typedef pair < long long, long long > pll;    
typedef pair < int, int > pii;
typedef unsigned long long ull;         
typedef vector < pii > vpii;
typedef vector < int > vi;
typedef long double ldb;  
typedef long long ll;  
typedef double db;                      
 
 
const int inf = 1e9, maxn = 4e5 + 148, mod = 1e9 + 7, N = 411;
const int dx[] = {1, -1, 0, 0}, dy[] = {0, 0, 1, -1}, block = 555;
const pii base = {1171, 3307}, Mod = {1e9 + 7, 1e9 + 9};
const db eps = 1e-12, pi = 3.14159265359;
const ll INF = 1e18;


int n, a[N], dp[N][N];

int get (int l, int r) {
	return a[r] - a[l - 1];
}

int rec (int l, int r) {
	if (r == l)	
		return 0;
	if (dp[l][r] != -1)
		return dp[l][r];

	dp[l][r] = INF;

	forn (L, l, r - 1) 
		dp[l][r] = min(dp[l][r], rec(l, L) + rec(L + 1, r) + get(l, L) + get(L + 1, r));		

	return dp[l][r];	
}


main () {
	cin >> n;
	forn (i, 1, n) {
		cin >> a[i]; 
		a[i] += a[i - 1];
	}

	memset(dp, -1, sizeof(dp));
	cout << rec(1, n) << endl;
}

    

Measured memory_bytes: 1536
#include<iostream>
#include<algorithm>
#include<cmath>
#include<cstring>
#include<cstdlib>
#include<ctime>
#include<cstdio>
#include<string>
//#include<string>
//#include<sstream>
using namespace std;

int main()
{
	char a[100010];
	int flag=0,n,i;
	scanf("%s",a);
	n=strlen(a);
	if(a[0]==a[n-1]){
		int num=n-3;
		if(num%2==1){
			printf("First\n");
		}
		else{
			printf("Second\n");
		}
	}
	else{
		int num=n-2;
		if(num%2==1){
			printf("First\n");
		}
		else printf("Second\n");
	}
}

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

#define int long long

#define rep(i,s,n) for(int i = (s);i<(n);i++)
#define repe(i,s,n) for(int i = (s);i<=(n);i++)
#define pb push_back
#define all(v) (v).begin(),(v).end()
typedef long long ll;
typedef pair<int,int>pint;
typedef vector<int>vint;
const ll MOD=1000000007,INF=1e18;

int n,ans=0;
int l[200010];

signed main(){
    cin>>n;
    rep(i,0,n*2){
        cin>>l[i];
    }
    sort(l,l+n*2);
    rep(i,0,n*2){
        ans+=l[i];
        i++;
    }
    
    cout<<ans<<endl;
    
    
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define F(i, j, k) for(register ll i = j; i <= k; ++i)
#define D(i, j, k) for(register ll i = j; i >= k; --i)
#define random(x) (rand() % (x)) + 1
#define pb push_back
#define fi first
#define se second
#define pp pair<ll, ll>
#define mp make_pair
#define error(x) cerr << #x << "=" << x << endl
//***********var defination*********
const ll maxn = 2e5+5;
ll n, m, x, y, z;
ll a[maxn];
//**********Code by Gengchen********
//WA RE TLE MLE 10 pts
//Always look up the code afeter programming
//Keep Calm
//by GengChen================
int main() {
    cin >> n;
    ll i;
    for(i = 0; i * i <= n; i++);
    i--;
    cout << i * i;
    return 0;
}



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

int main(void){
    int a,b;
    scanf("%d %d",&a,&b);
    if(b >= a){
        printf("%d\n",a);
    }
    else{
        printf("%d\n",a-1);
    }
    return 0;
}

Measured memory_bytes: 128
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef double db;
#define Check system("pause")
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define IOS ios::sync_with_stdio(false); cin.tie(0); cout.tie(0)



int main()
{
	ios::sync_with_stdio(false);
	int a,b;
	cin>>a>>b;
	cout<<a*b;
	return 0;
}




Measured memory_bytes: 3652
package main 

import (
        "fmt"
        "unicode/utf8"
)

func main () {
        var a,t string
        fmt.Scan(&a)
        ka := utf8.RuneCountInString(a)
        for i:= 0 ; i < ka ; i +=2{
                ii := i + 1
                t = t + a[i:ii]
        }
        fmt.Println(t)
}


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

int main() {
  int a, b;
  cin >> a >> b;
  if (a <= 5) {
    cout << 0 << endl;
  }
  else if (a >= 13) {
    cout << b << endl;
  }
  else {
    cout << b / 2 << endl;
  }
}


Measured memory_bytes: 256
#if 1
#include <iostream>
#include <fstream>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <unordered_map>
#include <unordered_set>
#include <queue>
#include <stack>
#include <array>
#include <deque>
#include <algorithm>
#include <utility>
#include <cstdint>
#include <functional>
#include <iomanip>
#include <numeric>
#include <assert.h>
#include <bitset>
#include <list>
#include <cmath>

auto& in = std::cin;
auto& out = std::cout;
#define all_range(C) std::begin(C), std::end(C)
const double PI = 3.141592653589793238462643383279502884197169399375105820974944;


template<typename T, typename U>
std::enable_if_t<std::rank<T>::value == 0> fill_all(T& arr, const U& v) {
	arr = v;
}
template<typename ARR, typename U>
std::enable_if_t<std::rank<ARR>::value != 0> fill_all(ARR& arr, const U& v) {
	for (auto& i : arr) {
		fill_all(i, v);
	}
}

int32_t N;
int32_t v[400100];
int32_t t[400100];
int32_t Vmax[400100];

int main()
{
	using std::endl;
	in.sync_with_stdio(false);
	out.sync_with_stdio(false);
	in.tie(nullptr);
	out.tie(nullptr);

	fill_all(Vmax, 400100);
	in >> N;
	for (int i = 0; i < N; i++)
	{
		in >> t[i];
	}
	for (int i = 0; i < N; i++)
	{
		in >> v[i];
	}

	auto iter = Vmax;
	Vmax[0] = 0;
	for (int i = 0; i < N; i++)
	{
		*iter = std::min(*iter, 2 * v[i]);
		for (int j = 0; j < 2*t[i]; j++)
		{
			++iter;
			*iter = std::min(*iter, 2 * v[i]);
		}
	}
	*iter = 0;
	int T2MAX = iter - Vmax + 1;
	for (int i = 1; i < T2MAX; i++)
	{
		Vmax[i] = std::min(Vmax[i - 1] + 1, Vmax[i]);
	}
	for (int i = T2MAX-2; i >= 0; i--)
	{
		Vmax[i] = std::min(Vmax[i + 1] + 1, Vmax[i]);
	}

	int64_t sum = 0;
	for (int i = 0; i < T2MAX; i++)
	{
		sum += Vmax[i];
	}
	out 
		<< std::fixed << std::setprecision(9)
		<< sum / 4.0 << endl;


	return 0;
}
#endif


Measured memory_bytes: 3840
#include<iostream>
#include<iomanip>
using namespace std;
int main()
{
    int n, c=0, i;
    double d;
    cin>>n;
    for(i=1;i<=n;i++)
    {
        if(i%2!=0)
            c++;
    }
    d=static_cast<double>(c) / (double)(n);

    cout<<fixed<<setprecision(10)<<d<<endl;

     return 0;
}


Measured memory_bytes: 3724
//INCLUDE
//------------------------------------------
#include <bits/stdc++.h>
//DEFINE
//------------------------------------------
#define ll long long
#define ld long double
#define ALLv(a)  (a).begin(),(a).end()
#define ALL(a,n)  (a),(a)+n
#define vi vector<long long>
#define vd vector<long double>
#define vs vector<string>
//CONST
//------------------------------------------
#define INF 1010000000000000017LL
#define MOD 1000000007LL
#define EPS 1e-12
#define PI 3.14159265358979323846
//REPEAT
//------------------------------------------
#define   FOR(i,m,n) for(ll (i)=(m);   (i)<(n);  (i)++)
#define   REP(i,n)   for(ll (i)=0;     (i)<(n);  (i)++)
#define  REPS(i,x)   for(ll (i)=1;     (i)<=(x); (i)++)
#define  RREP(i,x)   for(ll (i)=(x)-1; (i)>=0;   (i)--)
#define RREPS(i,x)   for(ll (i)=(x);   (i)> 0;   (i)--)
#define  WREP(i,in,j,jn) REP(i,in)REP(j,jn)
//-----------------------------------------
#define ifYN(x) cout<<(x?"Yes":"No")<<"\n" 
#define dcml(n) fixed<<setprecision(n)

 
ll GCD(ll a,ll b) { return b ? GCD(b,a%b) : a; } 
ll LCM(ll a,ll b) { return a/GCD(a,b)*b; } 
ll Factorial(ll n){ ll m=1;while(n>=1)m*=n--;return m; } 
ll modPow(ll x,ll n,ll mod=MOD){ 
    return (!n?1:!n%2?modPow(x*x,n/2,mod)%mod:x%mod*modPow(x,n-1,mod)%mod); 
} 
ll GetDigit(ll num){ 
    ll digit=0; 
    while(num!=0){num/=10;digit++;} 
    return digit; 
} 


using namespace std;
//-------------------------------------------

int main(void){
  cin.tie(0);
  ios::sync_with_stdio(false);
  
  ll X;cin>>X;
  ll x1=X/500;
  ll x2=(X-(500*x1))/5;
  cout<<(x1*1000+x2*5);
  return 0;
}


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

string s;

bool cek(string x)
{
	for(int i=1;i<x.size();i++)
	{
		if(x[i]!='9') return 0;
	}
	return 1;
}

int main()
{
	cin >> s;
	int pan=s.size();
	//cout << pan << endl;
	if(pan==1) printf("%d\n",s[0]-'0');
	else if(cek(s)) printf("%d\n",(pan-1)*9+s[0]-'0');
	else printf("%d\n",(pan-1)*9+s[0]-'0'-1);
 	return 0;
}


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

using namespace std;
typedef long long ll;
typedef long double ld;
ll gcd(ll a, ll b) { return b == 0 ? a : gcd(b, a % b); }
ll lcm(ll a, ll b) { return a * (b / gcd(a, b)); }


const int q = 1e9+9;

string f(ll n){
    if(n == 0) return "";
    if(n & 1){
        return f((n-1)/-2) + "1";
    }
    else return f(n/-2) + "0";
}

int main()
{
    ll n;
    cin>>n;
    if(n == 0) {
        cout<<"0"<<endl;
        return 0;
    }
    cout<<f(n)<<endl;


    return 0;
}
// gotcha;


Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<algorithm>
#include<math.h>
#include<string>

using namespace std;

int main(){
  int c, d;
  int n,m;
  string s,t;

  cin >> n>> m >>c;
  int b[20] = {0};
  int a[20][20] = {{0}};
  for(int i = 0 ; i < m; i++){
    cin >> b[i];
  }
  int ans = 0;
  for(int i = 0; i < n ; i++){
    int d = 0;
    for(int j = 0 ; j < m; j++ ){
      cin >> a[i][j];
      d += a[i][j]*b[j];
    }
    if(d + c > 0){
      ans++;
    }
  }

  cout << ans << endl;;
}


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

using namespace std;
//vector<long long> factors;
#define ll long long

#define pii pair<int,int>
#define pll pair<ll,ll>
#define _ <<'\n'
#define __ << ' '
#define all(x) (x).begin(), (x).end()
#define gcd __gcd
int IT_MAX = 1 << 17;
int MOD = 998244353;
const int INF = 0x3f3f3f3f;
const ll LL_INF = 0x0f3f3f3f3f3f3f3f;
const double PI = acos(-1);
const double ERR = 1e-10;
#define szz(x) (int)(x).size()
#define IOS ios_base::sync_with_stdio(false); cout.tie(0); cin.tie(0);
#define flush fflush(stdout)

ll mod(ll a, ll m) { return (a + (abs(a) / m) * m + m) % m; }

//****************************don't use int!!!!!!!****************************//
//***************************code starts here!!!!!****************************//

ll bp(ll osn, ll n) {
    if (n == 0) {
        return 1ll;
    } else if (n % 2 == 0) {
        ll temp = bp(osn, n / 2);
        return (temp * temp) % MOD;
    } else {
        ll temp = bp(osn, n / 2);
        return (((osn * temp) % MOD) * temp) % MOD;
    }
}

int main() {
    IOS

    ll n;
    cin >> n;
    vector<ll> d(n);
    unordered_map<ll, ll> mp;
    ll cnt_0 = 0;
    ll mx = -1;
    for (int i = 0; i < n; ++i) {
        cin >> d[i];
        if (d[i] == 0) {
            ++cnt_0;
        }
        if (d[i] > mx) {
            mx = d[i];
        }
        mp[d[i]]++;
    }
    ll ans = 1;
    if (cnt_0 == 1 && d[0] == 0) {
        for (int i = 0; i < mx; ++i) {
            ll prev = mp[i];
            ll cur = mp[i + 1];
            if (prev == 0) {
                cout << 0;
                return 0;
            }
            ans *= bp(prev, cur);
            ans %= MOD;
        }
        cout << ans;
        return 0;
    } else {
        cout << 0;
        return 0;
    }

    return 0;
}

Measured memory_bytes: 5156
fn getline() -> String {
    let mut __ret = String::new();
    std::io::stdin().read_line(&mut __ret).ok();
    return __ret;
}

fn main() {
    let s = getline();
    let list: Vec<_> = s.trim().split(' ').collect();
    let a: i32 = list[0].parse().unwrap();
    let b: i32 = list[1].parse().unwrap();
    let c: i32 = list[2].parse().unwrap();
    let d: i32 = list[3].parse().unwrap();

    if (a - b).abs() <= d && (b - c).abs() <= d {
        println!("Yes");
    } else if (a - c).abs() <= d {
        println!("Yes");
    } else {
        println!("No");
    }
}


Measured memory_bytes: 4352
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <string>
#include <vector>
#include <limits>
#include <algorithm>
#include <utility>
#include <sstream>
#include <numeric>
#include <iterator>
#include <set>

using namespace std;

#define repd(i,a,b) for (int i=(a);i<(b);++i)
#define rep(i,n) repd(i,0,n)
typedef long long ll;
typedef pair<int, int> P;

int main(int argc, const char * argv[]) {
  string s;
  cin >> s;
  int q;
  cin >> q;
  bool reverse = false;
  // set<char> end_s, start_c;
  vector<char> end_c, start_c;
  rep(i, q){
    int type;
    cin >> type;
    if(type == 1){
      reverse = !(reverse);
    }else{
      int f;
      char c;
      cin >> f >> c;
      if(f == 1){
        if(!reverse){
          start_c.push_back(c);
        }else{
          end_c.push_back(c);
        }
      }else{
        if(!reverse){
          end_c.push_back(c);
        }else{
          start_c.push_back(c);
        }
      }
    }
  }
  
  if(!reverse){
    for(int i=start_c.size()-1;i>=0;--i){
      cout << start_c[i];
    }
    cout << s;
    for(auto a : end_c){
      cout << a;
    }
    cout << endl;
  }else{
    for(int i=end_c.size()-1;i>=0;--i){
      cout << end_c[i];
    }
    for(int i=s.size()-1;i>=0;--i){
      cout << s[i];
    }
    rep(i, start_c.size()){
      cout << start_c[i];
    }
    cout << endl;
  }
  
  return 0;
}


Measured memory_bytes: 960
package main
 
import (
	"bufio"
	"fmt"
	"os"
	"strconv"
)
 
func main() {
	fsc := NewFastScanner()
	A, B := fsc.NextInt(), fsc.NextInt()
	C, D := fsc.NextInt(), fsc.NextInt()
	res := map[int]int{}
	for i := A; i < B; i++ {
		res[i]++
	}
	for i := C; i < D; i++ {
		res[i]++
	}
	result := 0
	for _, v := range res {
		if v >= 2 {
			result++
		}
	}
	fmt.Println(result)
}
 
//template
type FastScanner struct {
	r   *bufio.Reader
	buf []byte
	p   int
}
 
func NewFastScanner() *FastScanner {
	rdr := bufio.NewReaderSize(os.Stdin, 1024)
	return &FastScanner{r: rdr}
}
func (s *FastScanner) Next() string {
	s.pre()
	start := s.p
	for ; s.p < len(s.buf); s.p++ {
		if s.buf[s.p] == ' ' {
			break
		}
	}
	result := string(s.buf[start:s.p])
	s.p++
	return result
}
func (s *FastScanner) NextLine() string {
	s.pre()
	start := s.p
	s.p = len(s.buf)
	return string(s.buf[start:])
}
func (s *FastScanner) NextInt() int {
	v, _ := strconv.Atoi(s.Next())
	return v
}
func (s *FastScanner) NextInt64() int64 {
	v, _ := strconv.ParseInt(s.Next(), 10, 64)
	return v
}
 
func (s *FastScanner) pre() {
	if s.p >= len(s.buf) {
		s.readLine()
		s.p = 0
	}
}
func (s *FastScanner) readLine() {
	s.buf = make([]byte, 0)
	for {
		l, p, e := s.r.ReadLine()
		if e != nil {
			panic(e)
		}
		s.buf = append(s.buf, l...)
		if !p {
			break
		}
	}
}
 
//Max,Min
func IntMax(a, b int) int {
	if a < b {
		return b
	}
	return a
}
 
func Int64Max(a, b int64) int64 {
	if a < b {
		return b
	}
	return a
}
func Float64Max(a, b float64) float64 {
	if a < b {
		return b
	}
	return a
}
 
func IntMin(a, b int) int {
	if a > b {
		return b
	}
	return a
}
 
func Int64Min(a, b int64) int64 {
	if a > b {
		return b
	}
	return a
}
func Float64Min(a, b float64) float64 {
	if a > b {
		return b
	}
	return a
}
 
//Gcd
func IntGcd(a, b int) int {
	if a < b {
		b, a = a, b
	}
	if b == 0 {
		return a
	}
	return IntGcd(b, a%b)
}
func Int64Gcd(a, b int64) int64 {
	if a < b {
		b, a = a, b
	}
	if b == 0 {
		return a
	}
	return Int64Gcd(b, a%b)
}
 
func IntAbs(a int) int {
	if a < 0 {
		a *= -1
	}
	return a
}
 
func Int64Abs(a int64) int64 {
	if a < 0 {
		a *= -1
	}
	return a
}

Measured memory_bytes: 640
#include<bits/stdc++.h>
using namespace std;
 
#define ll long long
#define pb push_back
#define printV(v) for(int i=0;i<v.size();i++){cout << v[i]<< " ";} cout << endl
#define printRev(v) for(int i=v.size()-1;i >= 0;i--){cout << v[i] << " ";} cout << endl
#define sortV(v) sort(v.begin(),v.end())
#define revV(v) reverse(v.begin(),v.end())
#define FOR(i,from,n) for(int i=from;i<n;i++)
#define FOL(i,from,n) for(int i=from;i >= n;i--)
    
    ll a,b,c,d,e,f,g,n,m,k,t,x,h,w,q;
    ll mod = 1000000007;
    
    void solve(){
        int k;
        cin >> k;
        ll sum = 0;
        for(int i=1;i<=k;i++){
            for(int j=1;j<=k;j++){
                for(int jj =1;jj<=k;jj++){
                    int curr = __gcd(__gcd(i,j),jj);
                    sum += curr;
                }
            }
        }
        cout << sum << endl;
    }
        

  
   
    int main(){
    ios_base::sync_with_stdio(false);
    //freopen("input.txt","r",stdin);
    //freopen("output.txt","w",stdout);
    int cases = 1;
    //cin >> cases;
  
    while(cases--){ 
        solve();
    }

    return 0;

    }

Measured memory_bytes: 3664
let s = read_line ()
let n, ans = String.length s, ref max_int
let _ = String.iter (fun d -> let b, c, l, cs = ref false, ref 0, ref n, Array.init n @@ fun i -> s.[i] in
  while not !b do let b2 = ref true in for i = 0 to !l - 1 do if cs.(i) <> d then b2 := false else if i > 0 then cs.(i - 1) <- cs.(i) done; decr l; b := !b2; if not !b then incr c done; ans := min !ans !c) s; Printf.printf "%d\n" !ans

Measured memory_bytes: 512
check=[99, 111, 222, 333, 444, 555, 666, 777, 888, 999]

n=int(input())

if n in check:
    print(n)
else:
    for i in range(20):
        if check[i]<n<check[i+1]:
            print(check[i+1])
            exit()

Measured memory_bytes: 3060
#include <iostream> // cout, endl, cin
#include <cmath> //sqrt pow
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower
 
#define rep(i,n) for(int i = 0; i < n; i++)
#define vi vector<int>
#define vvi vector<vi>
#define pii pair<int, int>
#define mod 1000000007
using ll = long long;
using namespace std;
int main(){
  string s;
  cin >> s;
  int n = s.size();
  vector<char> sam1(n, '0'), sam2(n, '1');
  for(int i = 0; i < n; i += 2){
    sam1[i] = '1';
    sam2[i] = '0';
  }
  int num =  0, ans = 0;
  rep(i, n) if(s[i] != sam1[i]) num++;
  ans = min(num, n - num);
  cout << ans << endl;
}

Measured memory_bytes: 512
#create date: 2020-05-02 21:10

import sys
stdin = sys.stdin

def ns(): return stdin.readline().rstrip()
def ni(): return int(ns())
def na(): return list(map(int, stdin.readline().split()))

def main():
    k = ni()
    a, b = na()
    c = a % k

    if a + (k - c) <= b or c == 0:
        print("OK")
    else:
        print("NG")

if __name__ == "__main__":
    main()

Measured memory_bytes: 9196
n,m=map(int,input().split())
A=[int(i) for i in input().split()]
R=[0]
a=0
for i in range(n):
  a+=A[i]
  a%=m
  R.append(a)
def nc2(n):
  return n*(n-1)//2
import collections
c=collections.Counter(R)
ans=0
for r in set(R):
  ans+=nc2(c[r])
print(ans)

Measured memory_bytes: 17104
import java.util.Scanner;

public class Main{

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		char[] c = sc.next().toCharArray();;
		int cnt = 0;
		String ans = "YES";
		for(int i=0;i<c.length;i++) {
			if(c[i]=='x'){
				cnt++;
			}
			if(cnt>7) {
				ans = "NO";
				break;
			}
		}
		System.out.println(ans);
	}
}

Measured memory_bytes: 23892
#include <cstdio>
#include <cstdlib>
#include <vector>
#include <map>
#include <set>
#include <algorithm>

using namespace std;

template <class T>
class bit {
    public:
    bit(int n);
    ~bit();
    void add(int x, T value);
    T get(int x) const; // [0, x]
    T get(int x, int y) const; // [x, y]
    
    private:
    int size;
    T* data;
};

template <class T> bit<T>::bit(int n) : size(n + 1) {
    data = (T *)calloc(size, sizeof(T));
}

template <class T> bit<T>::~bit() {
    free(data);
}

template <class T> void bit<T>::add(int x, T value) {
    for (x++; x < size; x += x & -x) data[x] += value;
}

template <class T> T bit<T>::get(int x) const {
    T value = 0;
    for (x++; x > 0; x -= x & -x) value += data[x];
    return value;
}

template <class T> T bit<T>::get(int x, int y) const {
    return get(y) - get(x - 1);
}

const int mod = 1000000007;
int x[100000];
int y[100000];

int main() {
    int n, m, i;
    vector <pair<int, int>> v;
    set <int> s;
    set <pair<int, int>> s2;
    set <pair<int, int>>::iterator it;
    map <int, int> mp;
    map <int, int>::iterator it2;
    
    scanf("%d %d", &n, &m);
    
    for (i = 0; i < n; i++) scanf("%d", &x[i]);
    for (i = 0; i < m; i++) scanf("%d", &y[i]);
    
    for (i = 0; i < m; i++) s.insert(y[i]);
    s.insert(-1e9);
    s.insert(1e9 + 1);
    
    for (i = 0; i < n; i++) {
        set <int>::iterator it, it2;
        
        it = s.lower_bound(x[i]);
        it2 = it;
        it2--;
        
        if (*it == 1e9 + 1 || *it2 == -1e9) continue;
        
        s2.insert(make_pair(x[i] - *it2, *it - x[i]));
    }
    
    for (it = s2.begin(); it != s2.end(); it++) v.push_back(*it);
    
    for (i = 0; i < v.size(); i++) mp[v[i].second] = 0;
    
    for (it2 = mp.begin(), i = 1; it2 != mp.end(); it2++, i++) it2->second = i;
    
    for (i = 0; i < v.size(); i++) v[i].second = mp[v[i].second];
    
    sort(v.begin(), v.end(), [](const pair<int, int>& p1, const pair<int, int>& p2) { return p1.first < p2.first || (p1.first == p2.first && p1.second > p2.second); });
    
    bit <long long> b(mp.size() + 2);
    
    b.add(0, 1);
    
    for (i = 0; i < v.size(); i++) {
        long long p = b.get(v[i].second - 1) % mod;
        b.add(v[i].second, p);
    }
    
    printf("%lld\n", b.get(mp.size() + 1) % mod);
    
    return 0;
}


Measured memory_bytes: 12792
#include <bits/stdc++.h>
#define ll long long
#define int long long
#define vl vector<ll>
#define pl pair<ll,ll>
#define FOR(i,a,b) for(ll i=a;i<b;i++)
#define rep(i,b) for(ll i=0;i<b;i++)
#define per(i,a,b) for(ll i=b-1;i>=a;i--)
#define Yes(i) cout<<(i?"Yes":"No")<<endl
#define SORT(v) sort((v).begin(), (v).end())
#define RSORT(v) sort((v).rbegin(), (v).rend())
#define all(v) (v).begin(),(v).end()
using namespace std;

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

ll n,m;
signed main() {
cin>>n>>m;vl N(n);
rep(i,m){
ll a,b;cin>>a>>b;
N.at(a-1)++;
N.at(b-1)++;
}
rep(i,n)cout<<N.at(i)<<endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <unordered_set>
#include <unordered_map>
#include <random>
using namespace std;
#define ll long long
#define fr first
#define sc second
#define pll pair<ll, ll>
#define all(v) v.begin(), v.end()

const ll mod = 1e9 + 7;

int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	int N; cin >> N;
	if (N == 1) cout << 0 << '\n';
	else {
		ll a = 1, b = 1, c = 1;
		for (int i = 0; i < N; i++) {
			a *= 10;
			c *= 9;
			b *= 8;
			a %= mod;
			b %= mod;
			c %= mod;
		}
		cout << (a - 2 * c + b + 2*mod) % mod << '\n';
	}
	return 0;
}

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

int main() {
    string s, t;
    cin >> s >> t;
    vector<char> s_arr, t_arr;
    for (int i=0; i<s.size(); i++) {
        s_arr.push_back(s[i]);
    }
    for (int i=0; i<t.size(); i++) {
        t_arr.push_back(t[i]);
    }
    sort(s_arr.begin(), s_arr.end());
    sort(t_arr.begin(), t_arr.end(), greater<char>());
    if (s_arr < t_arr) {
        cout << "Yes" << endl;
    }
    else {
        cout << "No" << endl;
    }
}

Measured memory_bytes: 256
n = int(input())
a = list(map(int, input().split()))
t = n * (n + 1) // 2
s = sum(a)
if s % t:
    print('NO')
else:
    c = s // t
    b = [0] * n
    for i in range(n):
        b[i] = a[i] - a[i - 1] - c
    for i in range(n):
        if b[i] % n or b[i] > 0:
            print('NO')
            break
    else:
        print('YES')


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

namespace B.Shiritori
{
    class Program
    {
        static void Main(string[] args)
        {
            var N = int.Parse(Console.ReadLine());
            var values = new List<string>();
            bool flg = true;

            for (int i = 0; i < N; i++)
                values.Add(Console.ReadLine());

            if (values.GroupBy(x => x).SelectMany(g => g.Skip(1)).Any())
                flg = false;


            for (int i = 1; i < values.Count; i++)
            {
                if (values[i].ToCharArray().First() != values[i - 1].ToCharArray().Last())
                {
                    flg = false;
                    break;
                }
            }

            if (flg)
                Console.WriteLine("Yes");
            else
                Console.WriteLine("No");
        }
    }
}

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

int N,K;

int gcd(int n, int m){
	if(n%m==0) return m;
	else return gcd(m,n%m);
}

int main(){
	cin >> N >> K;
	vector<int> v(N);
	for(int i=0;i<N;i++){
		cin >> v[i];
	}
	sort(v.begin(),v.end());
	int a = 0;
	if(N!=1){
		for(int i=0;i<N;i++){
			if(i==0) a = gcd(v[0],v[1]);
			else a = gcd(a,v[i]);
		}
		if(a==1 && v[N-1]>=K) cout << "POSSIBLE" << endl;
		else{
			if(gcd(a,K)!=1 && v[N-1]>=K){
				cout << "POSSIBLE" << endl;
			}
			else cout << "IMPOSSIBLE" << endl;
		}
	}else{
		if(v[0]==K) cout << "POSSIBLE" << endl;
		else cout << "IMPOSSIBLE" << endl;
	}
}

Measured memory_bytes: 640
import sys
H,W,N=map(int,input().split())
table=[10**9]*H
for i in range(N):
    x,y=map(int,input().split())
    x,y=x-1,y-1
    table[x]=min(table[x],y)
t=1
for i in range(1,H):
    y=table[i]
    if y<=t-1:
        print(i)
        sys.exit()
    elif y>=t+1:
        t+=1
    #print(t)
print(H)

Measured memory_bytes: 49240
#include <iostream>
#include <math.h> 
#include <string> 
#include <algorithm>
#include <numeric>
#include <cmath>
using namespace std;

int main() {

	long N ; cin >> N;
	string S[100009]; for (int i = 1; i <= N; i++) cin >> S[i];
	long res = 0;

	long march[10]; march[1] = 0; march[2] = 0; march[3] = 0; march[4] = 0; march[5] = 0;
	for (int i = 1; i <= N; i++) {

		if (S[i][0] == 'M') march[1]++;
		if (S[i][0] == 'A') march[2]++;
		if (S[i][0] == 'R') march[3]++;
		if (S[i][0] == 'C') march[4]++;
		if (S[i][0] == 'H') march[5]++;

	}
    
	for (int i = 1; i <= 5; i++) for (int j = i + 1; j <= 5; j++) for (int k = j + 1; k <= 5; k++) res += march[i] * march[j] * march[k];

	cout << res << endl;

}

Measured memory_bytes: 6144
n = input()
N = [int(i) for i in n]
for i in range(8):
  n = format(i, '03b')
  ans = N[0]
  msg = str(N[0])
  for j in range(3):
    if n[j] == '0':
      ans += N[j+1]
      msg += '+' + str(N[j+1])
    else:
      ans -= N[j+1]
      msg += '-' + str(N[j+1])
  if ans == 7:
    print(msg + "=7")
    break

Measured memory_bytes: 9020
#from statistics import median
#import collections
#aa = collections.Counter(a) # list to list
#from itertools import combinations # (string,3) 3回
#
#
# pythonで無理なときは、pypyでやると正解するかも！！
#
#

mod = 10**9 + 7

def readInts():
  return list(map(int,input().split()))
def main():
    n = int(input())
    B = readInts()
    ans = B[0] + B[-1]
    for i in range(1,n-1):
        ans += min(B[i],B[i-1])
    print(ans)
if __name__ == '__main__':
  main()


Measured memory_bytes: 2940
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <string>
#include <numeric>
#include <cstdint>
#include <iomanip>
using ll = long long;
#define fast_io(); std::ios_base::sync_with_stdio(0); std::cin.tie(0); std::cout.tie(0);

int main(){
    std::vector<std::vector<int>> c(3,std::vector<int>(3,0));
    for(int i=0; i<3; i++){
        for(int j=0; j<3; j++){
            std::cin >> c[i][j];
        }
    }

    std::vector<int> a(3,0), b(3,0);
    b[0] = c[0][0];
    b[1] = c[0][1];
    b[2] = c[0][2];
    a[0] = 0;
    a[1] = c[1][0] - b[0];
    a[2] = c[2][0] - b[0];

    bool flag = true;
    for(int i=0; i<3; i++){
        for(int j=0; j<3; j++){
            if( c[i][j]!=a[i]+b[j] ) flag=false;
        }
    }

    if(flag){
        std::cout << "Yes" << "\n";
    }else{
        std::cout << "No" << "\n";
    }
    return 0;
}

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

int main(){
    lint a, b, c, d;
    
    
    cin >> a >> b >> c >> d;
    lint ekok = (c*d)/__gcd(c,d);
    lint c_bolum_a = (a-1)/c;
    lint d_bolum_a = (a-1)/d;
    lint cd_bolum_a = (a-1)/ekok;
    lint c_bolum_b = b/c;
    lint d_colum_b = b/d;
    lint cd_bolum_b = b/ekok;
    
    lint res = -c_bolum_a-d_bolum_a+c_bolum_b+d_colum_b+cd_bolum_a- cd_bolum_b;
    cout << b-a+1-res;

    return 0;
}


Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main()
{
	int n;
	cin >> n;
	long long a = 0, b = 0, x, y;
	long long a1[10001], a2[10001];
	long long sum1 = 0, sum2 = 0;
	for (int i = 0; i < n; ++i)
	{
		cin >> x;
		a1[i] = x;
		sum1 += x;
	}
	for (int i = 0; i < n; ++i)
	{
		cin >> y;
		a2[i] = y;
		sum2 += y;
	}
	if (sum1 > sum2)
	{
		cout << "No";
		return 0;
	}
	for (int i = 0; i < n-1; ++i)
	{
		x = a1[i], y = a2[i];
		if (x != y)
		{
			if (x > y)
			{
				if (b >= x - y)
				{
					b -= (x - y);
				}
				else
				{
					a += (x - y - b);
					b = 0;
				}
			}
			else
			{
				long long d = (y - x) / 2;
				if (a >= d)
				{
					a -= d;
				}
				else
				{
					b += (d - a);
					a = 0;
				}
			}
		}
	}
	if (a1[n-1] + 2 * a > a2[n-1] + b)
		cout << "No";
	else
		cout << "Yes";

	return 0;
}

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

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

Measured memory_bytes: 3624
#include <bits/stdc++.h>
#define rep(i, n) for(ll i = 0; i < n; i++)
#define repr(i, n) for(ll i = n; i >= 0; i--)
#define reprr(i, m, n) for (ll i = m; i < n; i++)
#define inf 2e9
#define all(v) v.begin(), v.end()
using namespace std;
typedef long long ll;
typedef vector<ll> vll;
typedef vector<vll> vvll;
using Graph = vector<vector<pair<ll, ll>>>;


int main()
{
    ll N; cin >> N;
    set<string> st;
    rep(i, N) {
        string s; cin >> s;
        st.insert(s);
    }
    cout << st.size() << endl;
    return 0;
}

Measured memory_bytes: 19244
from math import sqrt
from collections import Counter


def main():
    N = int(input())
    A = list(map(int, input().split()))
    A.sort()

    ans = 0
    p = [0] * (10**6 + 1)
    c = Counter(A)

    for a in c.keys():
        tmp = a * 2
        while tmp <= 10**6:
            p[tmp] = 1
            tmp += a

    for a in A:
        if p[a] == 0 and c[a] == 1:
            ans += 1

    print(ans)


if __name__ == "__main__":
    main()


Measured memory_bytes: 123416