akhauriyash/Code-Regression huggingface dataset:
N = int(input())
 
D = {}
for i in range(N):
    s = ''.join(sorted(input()))
    D.setdefault(s, 0)
    D[s] += 1
    
ans = 0
for v in D.values():
    if v > 1:
        for i in range(v):
            ans += i
    
print(ans)

Measured memory_bytes: 17852
#include <iostream>
#include <algorithm>
#include <vector>
#include <cstdio>
#include <string>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <cmath>
#include <functional>
#include <numeric>
#include <iomanip>
#define fi first
#define se second
#define fcout(n) cout<<fixed<<setprecision((n))
#define cinl(str) getline(cin,(str))
using namespace std;
bool value(int y,int x,int R,int C){return 0<=y&&y<R&&0<=x&&x<C;}
typedef pair<int,int> pii;
typedef long long ll;
typedef vector<int> vi;
typedef vector<long long > vll;
typedef vector< vi > vvi;
double pie=acos(-1);
int INF=1000000007;
int dx[4] = { 0,-1,0,1 };
int dy[4] = { -1,0,1,0 };


int main() {
	double r0,w0,c,r;
	int ans=0;
	while(true){
		ans=0;
		cin>>r0>>w0>>c>>r;
		if(w0+r0+c+r==0) return 0;
		while(r0/w0<c){
			ans++;
			r0 += r;
		}
		cout<<ans<<endl;
	}
}

Measured memory_bytes: 3156
function Main(input) {
    const NA = input.split('\n');
    const N = parseInt(NA[0]);
    const A = NA[1].split(' ').map(n => parseInt(n));
    const B = A.map((n, i) => n-(i+1)).sort((a, b) => a-b);
    const b1 = B[parseInt(N/2)];
    const b2 = b1 + 1;
    const min1 = A.reduce((res, n, i) => res += Math.abs(n - (b1+i+1)), 0);
    const min2 = A.reduce((res, n, i) => res += Math.abs(n - (b2+i+1)), 0)
    
    if (min1 < min2) console.log(min1);
    else console.log(min2);
}
Main(require("fs").readFileSync("/dev/stdin", "utf8"));

Measured memory_bytes: 37056
#include <iostream>
#include <iomanip>
#include <string>
#include <vector>
#include <algorithm>
#include <numeric>
#include <utility>
#include <cmath>
#include <tuple>
#include <queue>
#include <bitset>
#include <set>
#include <map>
#include <list>

using ll = long long;
using ld = long double;
using namespace std;
const int INF = 1e9+100;
const ll INF64 = 7e18l;
const int mod = 1000000007;
#define rep(i,a,b) for(int i=(a);i<(b);i++)
#define ALL(a) (a).begin(), (a).end()
#define FIN ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);


int main(){
    FIN;
    int n; cin >> n;
    vector<int> v(n),c(n);
    rep(i,0,n) cin >> v[i];
    rep(i,0,n) cin >> c[i];

    int ans = 0;
    for(int bit=0;bit < (1<<n); bit++){
        int value = 0;  int cost = 0;
        for(int i=0;i<n;i++){
            if(bit & (1<<i)){
                value += v[i];
                cost += c[i];
            }
        }
        ans = max(ans,value-cost);
    }

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

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


int main() {
	int k[110][110];
int n,l,a,b;
cin>>n;
for(int j=0;j<n;j++){
	cin>>l>>a;
	for(int i=0;i<a;i++){
		cin>>b;
		k[j][b-1]=1;
	}
}
int q[105];
for(int j=0;j<n;j++){
	q[j]=-1;
	if(k[0][j]==1){
		q[j]=1;
	}
}
q[0]=0;
int u=1;
int m=1;
while(m<=n){

	for(int d=0;d<n;d++){
		if(q[d]==m){
			for(int h=0;h<n;h++){
				if(k[d][h]==1 &&q[h]==-1){
					q[h]=m+1;
				}
			}
		}
	}
m=m+1;	
}
for(int y=0;y<n;y++){
	cout<<y+1<<" "<<q[y]<<endl;
}

	return 0;
}

Measured memory_bytes: 1208
#include <stdio.h>
#include <math.h>
#include <string.h>

int gcd(int a,int b){
    if(a<b){
        int now=a;
        a=b;
        b=a;
    }

    int r=a%b;
    while(r!=0){
        a=b;
        b=r;
        r=a%b;
    }

    return b;
}



/* 値を入れ替える関数 */
void swap (int *x, int *y) {
  int temp;    // 値を一時保存する変数

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

/***
* pivotを決め、
* 全データをpivotを境目に振り分け、
* pivotの添え字を返す
***/
int partition (int array[], int left, int right) {
  int i, j, pivot;
  i = left;
  j = right + 1;
  pivot = left;   // 先頭要素をpivotとする

  do {
    do { i++; } while (array[i] < array[pivot]);
    do { j--; } while (array[pivot] < array[j]);
    // pivotより小さいものを左へ、大きいものを右へ
    if (i < j) { swap(&array[i], &array[j]); }
  } while (i < j);

  swap(&array[pivot], &array[j]);   //pivotを更新

  return j;
}

/* クイックソート */
void quick_sort (int array[], int left, int right) {
  int pivot;

  if (left < right) {
    pivot = partition(array, left, right);
    quick_sort(array, left, pivot-1);   // pivotを境に再帰的にクイックソート
    quick_sort(array, pivot+1, right);
  }
}



int main(void){
    int n;
    scanf("%d",&n);
    long int A[200000];

    int i;
    long int all=0;
    for(i=0;i<n;i++){
        int now;
        scanf("%d",&now);
        A[now]++;
        all+=now;
    }

    int q;
    scanf("%d",&q);
    while(q--){
        long int b,c;
        scanf("%ld%ld",&b,&c);

        all-=b*A[b];
        all+=c*A[b];
        A[c]+=A[b];
        A[b]=0;
        printf("%ld\n",all);
    }
}

Measured memory_bytes: 2448
import math
N = int(input())
X = []
for _ in range(N):
    x, y = map(int, input().split())
    X.append((math.atan2(x, y), x, y))

X = sorted(X) * 2
ma = 0
for i in range(N):
    sx = sy = 0
    for j in range(i, i + N):
        sx += X[j][1]; sy += X[j][2]
        d = sx ** 2 + sy ** 2
        ma = max(ma, d)

print(ma**0.5)

Measured memory_bytes: 3316
#include<bits/stdc++.h>
using namespace std;
int main(){
  string s;
  cin >> s;
  s[3] = '8';
  cout << s << endl;
  return 0;
}
// cLay varsion 20170910-1

// --- original code ---
// {
//   string s;
//   cin >> s;
//   s[3] = '8';
//   cout << s << endl;
// }

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

using namespace std;

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

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

  int64_t min_ans = INT64_MAX;
  for (int s = -1; s < 2; s += 2) {
    int64_t ans = 0LLU;
    int64_t sum = 0LLU;
    int sign;
    for (int i = 0, sign = s; i < n; ++i, sign *= -1) {
      sum += a[i];
      // cout << i << "| sign: " << sign << " sum: " << sum << "\n";
      if (sum * sign <= 0) {
        ans += abs(sign - sum);
        sum = sign;
      }
    }
    min_ans = min(min_ans, ans);
  }
  cout << min_ans << "\n";
}


Measured memory_bytes: 640
//written by: rishav2416
#include <bits/stdc++.h>
#define ll long  long
#define lli long long int
#define ld long double
#define mod 1000000007
#define max_char 128
#define pb push_back
#define ff first
#define ss second
#define mp make_pair
#define lbd lower_bound
#define ubd upper_bound
#define PI 3.141592653589793238
#define pf push_front
#define all(x) x.begin(),x.end()
#define input(arr,n) for(ll c1=0;c1<n;c1++)cin>>arr[c1];
#define arrinit(arr,n,k) for(ll c1=0;c1<n;c1++) arr[i]=k;
#define rep(i,a,n) for( ll i=a ; i<n ; i++)
#define revrep(i,a,n) for(ll i=a; i>=n ; i--)
#define mems(x, y) memset(x, y, sizeof(x))
#define fastio ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
using namespace std;
#define INF 1e18a



ll power(ll base,ll pow, ll mo)
{
   ll res=1;
   while(pow)
   {
        if (pow%2!=0)  res=(res*base)%mo;
        base=(base*base)%mo;
        pow/=2;
   }
   return res;
}


std::string str="All Good Till Here";

/////////////////////////////////////////////////////////////////////////////////

int32_t main()
{
    fastio
	ll tt,i,j,x;
	//cin>>tt;
  tt=1;
	while(tt--)
	{
    string str;
    cin>>str;
    if(str=="ABC")cout<<"ARC\n";
    else cout<<"ABC\n";
	}
    return 0;
}


Measured memory_bytes: 3648
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstring>
#define ll long long
using namespace std;
const int maxn=100050;
int n;
int a[maxn],pre[maxn];
ll tr[maxn*10];
inline int lowbit(int x){
	return x&(-x);
}
inline void add(int x){
	for(register int i=x;i<=2*maxn;i+=lowbit(i)){
		tr[i]++;
	}
}
inline ll query(int x){
	ll ans=0;
	for(register int i=x;i>0;i-=lowbit(i)){
		ans+=tr[i];
	}
	return ans;
}
inline bool judge(int x){
	for(register int i=0;i<=2*maxn;i++)tr[i]=0;
	pre[0]=0;
	for(register int i=1;i<=n;i++){
		pre[i]=pre[i-1];
		if(a[i]>=x)pre[i]++;
		else pre[i]--;
	}
	ll cnt=0;
	for(register int i=0;i<=n;i++){
		cnt+=query(pre[i]+maxn);
		add(pre[i]+maxn);
	}
	if(cnt>=(ll)n*(n+1)/4)return 1;
	return 0;
}
int main(){
	int l=0,r=0;
	scanf("%d",&n);
	for(register int i=1;i<=n;i++){
		scanf("%d",&a[i]);
		r=max(a[i],r);
	}
	while(l<=r){
		int m=(l+r)>>1;
		if(judge(m))l=m+1;
		else r=m-1;
	}
	cout<<r<<endl;
}

Measured memory_bytes: 4224
#include <iostream>
#include <string>
#include <vector>
#include <queue>
#include <map>
#include <unordered_map>
#include <utility>
#include <algorithm>
#include <cmath>
#include <array>
#include <bitset>
using namespace std;

typedef long long ll;
const ll mod=1000000007;
#define rep(i,n) for(int i=0;i<n;i++)
#define Rep(i,n) for(int i=1;i<n+1;i++)
int main(){
    ll X,Y;
    cin>>X>>Y;
    int Z=X%3-Y%3+3;
    if(Z%3==0){
        if(X==Y) cout<<"Brown"<<endl;
        else cout<<"Alice"<<endl;
    }else if(Z%3==1){
        if(X==Y+1) cout<<"Brown"<<endl;
        else cout<<"Alice"<<endl;
    }else{
        if(Y==X+1) cout<<"Brown"<<endl;
        else cout<<"Alice"<<endl;
    }
    return 0;
}

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

int main(){
    char s[11];
    int flag = 0;
    int n;
    
    scanf("%s",s);
    n = strlen(s);
    
    if(n % 2 == 1){ //文字数が奇数の場合不可能
        printf("No\n");
        return 0;
    }
    
    for(int i = 0 ; i < n ; i++){
        if(i % 2 == 0 && s[i] != 'h'){
            flag = 1;
            break;
        }
        if(i % 2 == 1 && s[i] != 'i'){
            flag = 1;
            break;
        }
    }
//    printf("%d\n",n);
    if(flag == 0) printf("Yes\n");
    else printf("No\n");
    return 0;
}


Measured memory_bytes: 128
#include<cstdio>
#include<iostream>
#include<cstring>
#define in inline
#define re register
using namespace std;
in int read(){
	re int t=0;
	re char v=getchar();
	while(v<'0'||v>'9')v=getchar();
	while(v>='0'&&v<='9'){
		t=(t<<3)+(t<<1)+(v^48);
		v=getchar();
	}
	return t;
}
int un[22][22],kd[22][22],n,t,cnt[22],cnt1[22],tr[22],ut[22],ans;
inline void dfs(re int x,re int y){
	if(x==t+1){
		if(y>ans)ans=y;
		return;
	}
	if(!tr[x])++ut[x],dfs(x+1,y),--ut[x];
	if(!ut[x]){
		++tr[x];
		for(re int i=1;i<=cnt[x];++i){
			if(ut[kd[x][i]]){--tr[x];return;
			}
		}
		for(re int i=1;i<=cnt1[x];++i){
			if(tr[un[x][i]]){--tr[x];return;
			}
		}
		for(re int i=1;i<=cnt[x];++i)++tr[kd[x][i]];
		for(re int i=1;i<=cnt1[x];++i)++ut[un[x][i]];
		dfs(x+1,y+1);
		for(re int i=1;i<=cnt[x];++i)--tr[kd[x][i]];
		for(re int i=1;i<=cnt1[x];++i)--ut[un[x][i]];
		--tr[x];
	}
	
}
int main(){
	t=read();
	for(re int i=1;i<=t;++i){
		n=read();
		for(re int j=1;j<=n;++j){
			int x=read(),y=read();
			if(y==1)kd[i][++cnt[i]]=x;
			else un[i][++cnt1[i]]=x;
		}
	}
	dfs(1,0);
	cout<<ans;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <cstring>
#include <fstream>
#include <cmath>
#include <iomanip>
#include <cstdlib>
#include <algorithm>
#include <vector>
#include <map>
#include <deque>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <list>
#include <unordered_map>
#include <bitset>
#include <sstream>

typedef  long long ll;
#define mop 1000000007
using namespace std;

struct item{
    ll w,v;
};

static const ll MAX = 101;
vector <ll> values[4];

int main() {
    
    ll n,w;
    cin >> n >> w;
    ll w0;
    for (ll i=0;i<n;i++){
        item p;
        cin >> p.w >> p.v;
        if(!i){
            w0 = p.w;
        }
        values[p.w - w0].push_back(p.v);
    }
    for (ll i=0;i<4;i++){
        values[i].push_back(0);
        sort(values[i].begin(), values[i].end());
        reverse(values[i].begin()+1, values[i].end());
        ll sumv = 0;
        for (ll j = 0;j<values[i].size();j++){
            sumv += values[i][j];
            values[i][j] = sumv;
        }
    }
    ll ansv = 0;
    ll answ = 0;
    ll ans = 0;
    for (ll a=0;a<values[0].size();a++){
        for (ll b = 0;b<values[1].size();b++){
            for (ll c = 0;c<values[2].size();c++){
                for (ll d = 0;d<values[3].size();d++){
                    ansv = values[0][a] + values[1][b] + values[2][c] + values[3][d];
//                    cout << a << " " << b << " " << c << " " << d << " " << ansv << endl;
                    answ = w0*(a) + (w0+1)*(b) + (w0+2)*(c) + (w0+3)*(d);
                    if(answ > w){
                        continue;
                    }
                    if(ans < ansv){
                        ans = ansv;
                    }
                }
            }
        }
    }
    cout << ans << endl;

}




Measured memory_bytes: 256
package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
)

const inf = 1 << 60

func main() {
	n := getInt()
	maxW := getInt()
	_ = maxW

	ws := make([]int, n)
	vs := make([]int, n)
	for i := 0; i < n; i++ {
		ws[i] = getInt()
		vs[i] = getInt()
	}

	dp := make([][]int, n+1)
	for i := range dp {
		dp[i] = make([]int, 100010)
		for j := range dp[i] {
			dp[i][j] = inf
		}
	}
	dp[0][0] = 0

	for i := 1; i < n+1; i++ {
		for j := range dp[i-1] {
			dp[i][j] = min(dp[i][j], dp[i-1][j])
			if j-vs[i-1] >= 0 {
				dp[i][j] = min(dp[i][j], dp[i-1][j-vs[i-1]]+ws[i-1])
			}
		}
	}

	ans := -1
	for i := len(dp[n]) - 1; i >= 0; i-- {
		if dp[n][i] <= maxW {
			ans = i
			break
		}
	}

	fmt.Println(ans)
}

func min(a, b int) int {
	if a < b {
		return a
	}
	return b
}

// -----------------------------------------

var scanner = wordScanner()

func wordScanner() *bufio.Scanner {
	sc := bufio.NewScanner(os.Stdin)
	sc.Split(bufio.ScanWords)
	return sc
}

func getInt() int {
	scanner.Scan()
	i, err := strconv.Atoi(scanner.Text())
	if err != nil {
		panic(err)
	}
	return i
}

func getIntSlice(n int) []int {
	is := make([]int, n)
	for i := range is {
		is[i] = getInt()
	}
	return is
}

func getString() string {
	scanner.Scan()
	s := scanner.Text()
	return s
}


Measured memory_bytes: 82432
n =  int(input())

s = []
for _ in range(n):
    s.append(''.join(sorted(input())))

d = {}

for e in s:
    if e in d:
        d[e] += 1
    else:
        d[e] = 1

ans = 0
for k, v in d.items():
    ans += int(v * (v - 1) / 2)

print(ans)



Measured memory_bytes: 19404
import math

class Point:
    def __init__(self, x, y):
        self.x = x
        self.y = y


def koch(n, a, b):
    if n == 0:
        return

    th = math.pi * 60 / 180
    s = Point((2*a.x + b.x) / 3, (2*a.y + b.y) / 3)
    t = Point((a.x + 2*b.x) / 3, (a.y + 2*b.y) / 3)
    u = Point((t.x-s.x) * math.cos(th) - (t.y-s.y) * math.sin(th) + s.x,
              (t.x-s.x) * math.sin(th) + (t.y-s.y) * math.cos(th) + s.y)

    koch(n-1, a, s)
    print('{0:.8f} {1:.8f}'.format(s.x, s.y))
    koch(n-1, s, u)
    print('{0:.8f} {1:.8f}'.format(u.x, u.y))
    koch(n-1, u, t)
    print('{0:.8f} {1:.8f}'.format(t.x, t.y))
    koch(n-1, t, b)

n = int(input())
a = Point(0, 0)
b = Point(100, 0)

print('{0:.8f} {1:.8f}'.format(a.x, a.y))
koch(n, a, b)
print('{0:.8f} {1:.8f}'.format(b.x, b.y))


Measured memory_bytes: 5764
N=int(input())
S = [input() for i in range(N)]
S.sort()
import itertools
gr = itertools.groupby(S)
ans=[]
n=0
for key, group in gr:
  a=len(list(group))
  if a>n:
    ans=[]
    n=a
    ans.append(key)
  elif a==n:
    ans.append(key)
for a in ans:
  print(a)



Measured memory_bytes: 21448
// Why am I so dumb? :c
#include<bits/stdc++.h>

#define pb push_back
#define mp make_pair

#define all(x) (x).begin(), (x).end()

#define fi first
#define se second

using namespace std;

typedef long long ll;

char s[200005];

int cnt[26];

ll ans;

int n;

ll f(int x) {
    return x * (x - 1ll) / 2;
}

void solve() {
    scanf("%s", s);

    for (n = 0; s[n]; ++n) {
        ++cnt[s[n] - 'a'];
    }

    ans = f(n) + 1;

    for (int i = 0; i < 26; ++i) {
        ans -= f(cnt[i]);
    }

    printf("%lld\n", ans);
}

int main() {
    int tt = 1;

    while (tt--) {
        solve();
    }

    return 0;
}

Measured memory_bytes: 384
from operator import itemgetter
N,M = map(int,input().split())
AB = [list(map(int,input().split())) for _ in range(N)]
AB.sort(key = itemgetter(0))
#print(AB)
ans = 0
for i in range(N):
  if AB[i][1] >= M:
    ans += AB[i][0] * M
    print(ans)
    exit()
  else:
    M -= AB[i][1]
    ans += AB[i][0] * AB[i][1]

Measured memory_bytes: 28968
//  Created by conan1024hao in 2019.
//  Copyright © 2019 conan1024hao. All rights reserved.
//  専用ライブラリです、自由にコピーして構いません。
//  感谢看我的代码！Wechat:conan1024hao Twitter/QQ:810396815
#pragma GCC optimize ("O3")
#include <iostream>
#include <iomanip>
#include <istream>
#include <ostream>
#include <sstream>
#include <iterator>
#include <vector>
#include <algorithm>
#include <queue>
#include <deque>
#include <list>
#include <stack>
#include <map>
#include <unordered_map>
#include <set>
#include <utility>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <string>
#include <ctime>
#include <cctype>
#include <cstdlib>
#define IINF 10e8
#define INF 10e16
#define MOD 1000000007
#define mod 1000000007
#define rep(i, a, n) for (ll i = a; i < (ll)(n); i++)
#define Endl endl
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define eb emplace_back
#define mmax(x,y)(x>y?x:y)
#define mmin(x,y)(x<y?x:y)
#define chmax(x,y) x=mmax(x,y)
#define chmin(x,y) x=mmin(x,y)
#define all(x) (x).begin(),(x).end()
#define siz(x) (ll)(x).size()
#define PI acos(-1.0)
using namespace std;
//using Int=int_fast64_t;
typedef long long int ll;
typedef long long int LL;
typedef pair<ll,ll>Pll;
typedef pair<int,int>Pin;
long long GCD(long long a, long long b) { return b ? GCD(b, a%b) : a; }
long long LCM(long long a, long long b)  {return a/GCD(a,b)*b;}
int dx[8]={-1,0,1,0,1,1,-1,-1};
int dy[8]={0,-1,0,1,1,-1,1,-1};
char dir[4]={'u','l','d','r'};
ll cmp1(pair<ll,string>a,pair<ll,string> b){
        if(a.fi!=b.fi)
        return a.fi<b.fi;
        else
        return a.se<b.se;
}

//---------------------------------------------------------------------------

//---------------------------------------------------------------------------
int main(){//問題をちゃんと見ろ!!!!!!!!!!!!!!!!!      llか??????????统一类型        memset()!!!!!!!!!!!!       ペナを減らせ!!!!!!!!!!!!!
    cin.tie(0);
    ios::sync_with_stdio(false);
    //-------------------------------
    ll h,n;cin>>h>>n;
    vector<ll>a(n+1),b(n+1);
    ll amax=0;
    for(ll i=1;i<=n;i++){
        cin>>a[i]>>b[i];
        chmax(amax,a[i]);
    }
    ll dp1[100001];ll ans=INF;
    for(ll i=0;i<=10000+amax;i++)dp1[i]=INF;
    dp1[0]=0;
    for(ll i=1;i<=n;i++){
        for(ll j=a[i];j<=h+10000;j++){
            chmin(dp1[j],dp1[j-a[i]]+b[i]);
        }
    }
    for(ll i=h;i<=h+amax;i++)
        chmin(ans,dp1[i]);
    cout<<ans<<endl;
    //-------------------------------
    return 0;
}
//---------------------------------------------------------------------------









Measured memory_bytes: 384
#include <bits/stdc++.h>
#define lsb(x) (x & (-x))
#define ll long long
#define ull unsigned long long
// 217
// 44

using namespace std;

const int MAXN = (int) 1e5;

int x[MAXN + 1];
ll p[MAXN + 1];

int s;

ll solve(int l, int r) {
    if(x[l] > s) {
        ll ans = x[r] - s;
        s = x[r];
        return ans;
    }
    if(x[r] < s) {
        ll ans = s - x[l];
        s = x[l];
        return ans;
    }
    if(p[l] >= p[r]) {
        p[l] += p[r];
        ll ans = solve(l, r - 1) + llabs(x[r] - s);
        s = x[r];
        return ans;
    }
    else {
        p[r] += p[l];
        ll ans = solve(l + 1, r) + llabs(x[l] - s);
        s = x[l];
        return ans;
    }
}

int main() {
    //ifstream cin("A.in");
    //ofstream cout("A.out");
    int i, n;
    ios::sync_with_stdio(false);
    cin >> n >> s;
    for(i = 1; i <= n; i++) {
        cin >> x[i] >> p[i];
    }
    cout << solve(1, n);
    //cin.close();
    //cout.close();
    return 0;
}


Measured memory_bytes: 3968
e1,e2,e3,e4=map(int,input().split())
if e1==e2==e3==e4:
    print('yes')
elif e1==e2 and e3==e4:
    print('yes')
elif e1==e3 and e2==e4:
    print('yes')
elif e1==e4 and e2==e3:
    print('yes')
else:
    print('no')



Measured memory_bytes: 5596
#include <bits/stdc++.h>
using namespace std;
int main(void){
    int N;
    cin >> N;
    string S;
    cin >> S;
    map<char,int> mp;
    for(int i = 0; i < N; i++){
        mp[S[i]]++;
    }
    long long ans=1;
     ans *= mp['R'];
     ans *= mp['G'];
     ans *= mp['B'];
    long long Notans = 0;
    for(int k = 2; k < N; k++){
        for(int j = 1; j < k; j++){
            int i = 2*j - k;
            if(0 <= i && i < j){
                    if(S[i] != S[j] && S[j] != S[k] && S[k] != S[i]) Notans++; 
            }
        }
    }
    cout << ans - Notans << endl;
}


Measured memory_bytes: 3628
#encoding:utf-8 No.0045 2014.10.5
sum = 0
average = 0.0
count = 0.0

while gets
  count += 1.0
  data = $_.chomp.split(/,/).map{|item| item = item.to_i}
  sum += data[0]*data[1]
  average += data[1].to_f
end

puts sum
puts (average/count).round

Measured memory_bytes: 6112
using System;


class Program
{
    static void Main(string[] args)
    {
        String[] tmp = Console.ReadLine().Split(' ');
        int X = int.Parse(tmp[0]);
        int A = int.Parse(tmp[1]);

        if (X < A)
        {
            Console.WriteLine(0);
        }
        else
        {
            Console.WriteLine(10);
        }

        //System.Threading.Thread.Sleep(5000);
    }
}


Measured memory_bytes: 11092
import java.io.*;
import java.util.*;

public class Main extends PrintWriter {
	Main() { super(System.out, true); }
	Scanner sc = new Scanner(System.in);
	public static void main(String[] $) {
		Main o = new Main(); o.main(); o.flush();
	}

	void main() {
		long n = sc.nextLong();
		long a = sc.nextLong();
		long b = sc.nextLong();
		println(n / (a + b) * a + Math.min(n % (a + b), a));
	}
}


Measured memory_bytes: 21844
#include <bits/stdc++.h>
#define REP(i,n) for(int i=0;i<n;i++)
using namespace std;
int n,pos;
vector<int> pre,in,post;
void rec(int l,int r){
  if(l>=r) return;
  int root=pre[pos++];
  int m=distance(in.begin(),find(in.begin(),in.end(),root));
  rec(l,m);
  rec(m+1,r);
  post.push_back(root);
}
void solve(){
  pos=0;
  rec(0,pre.size());
  REP(i,n){
    if(i) printf(" ");
    printf("%d",post[i]);
  }
  printf("\n");
}
int main(){
  int k;
  scanf("%d",&n);
  REP(i,n) {scanf("%d",&k);pre.push_back(k);}
  REP(i,n) {scanf("%d",&k);in.push_back(k);}
  solve();
  return 0;
}

Measured memory_bytes: 3248
/*  ex7_1
    supercomputerjoi    */

#include <stdio.h>

typedef struct point{
    int x_elem;
    int y_elem;
}point;

point move(point coor, int x, int y);

int main(void){

    point coor1, coor2, coor3, coor4;
    
    // input x1 y1
    scanf("%d %d", &coor1.x_elem, &coor1.y_elem);
    // input x2 y2
    scanf("%d %d", &coor2.x_elem, &coor2.y_elem);

    // calculate x3 y3
    coor3 = move(coor2, coor1.y_elem - coor2.y_elem, coor2.x_elem - coor1.x_elem);

    // calculate x4 y4
    coor4 = move(coor3, coor2.y_elem - coor3.y_elem, coor3.x_elem - coor2.x_elem);

    // output answer
    printf("%d %d %d %d\n", coor3.x_elem, coor3.y_elem, coor4.x_elem, coor4.y_elem);

    return 0;
}

point move(point coor, int x, int y){

    // add x_elem x
    coor.x_elem += x;
    // add y_elem y
    coor.y_elem += y;

    return coor;
}

Measured memory_bytes: 1712
#include <iostream>
#define rep(i, n) for(int i=0; i<n; i++)
using namespace std;

int main(){
  int N, K;
  cin >> N >> K;
  int D[K];
  rep(i, K)
    cin >> D[i];
  //ここまで入力

  int n = N, tmp;
  int i;
  //Nから順に見ていく
  while(1){
    tmp = n;
    //Nの各桁を見るループ
    while(tmp != 0){
      //嫌いな数字を見るループ
      for(i=0; i<K; i++)
	//嫌いな数字が見つかれば次の数字へ
	if(tmp%10 == D[i])
	  goto next;
      tmp /= 10;
    }
  next :
    //嫌いな数字が見つからなければループ終了
    if(i == K)
      break;
    //次の数字へ
    n++;
  }

  //解答
  cout << n << endl;
  
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); i++)
const long double PI = (acos(-1));
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
int ctoi(char c)
{
    switch (c)
    {
    case '0':
        return 0;
    case '1':
        return 1;
    case '2':
        return 2;
    case '3':
        return 3;
    case '4':
        return 4;
    case '5':
        return 5;
    case '6':
        return 6;
    case '7':
        return 7;
    case '8':
        return 8;
    case '9':
        return 9;
    default:
        return 0;
    }
}
int main()
{
    int n;
    cin >> n;
    int i = 1;
    while (i <= n)
    {
        i *= 2;
    }
    cout << i / 2 << endl;
}

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

int main() {
	ios::sync_with_stdio(false);
	cin.tie(0); 
	
	string s;
	cin >> s;
	int k;
	cin >> k;
	int n = s.size();
	set<string> st;
	for(int i = 0; i < n; i++) {
		string t;
		for(int j = i; j < n; j++) {
			if(t.size() > k) break;
			t += s[j];
			st.insert(t);
		}
	}
	int cnt = 1;
	for(auto i : st) {
		if(cnt == k) {
			cout << i << endl;
			return 0;
		}
		cnt++;
	}
	return 0;
}


Measured memory_bytes: 2176
import numpy as np
N,K = map(int,input().split())
a = np.array(input().split(),np.int64)
a = np.sort(a)
zero = a[a==0]
pos = a[a>0]
neg = a[a<0]

def f(x):
    count = 0
    c = x // pos
    count += np.searchsorted(a, c, side='right').sum()
    count += N*len(zero) if x >= 0 else 0
    c = -(-x // neg)
    count += (N - np.searchsorted(a, c, side='left')).sum()
    count -= a[a*a <= x].size
    count //= 2
    return count

right = 10**18
left = -10**18
while right-left>1:
    mid = (right + left)//2
    if f(mid)<K:
        left = mid
    else:
        right = mid
        
print(right)

Measured memory_bytes: 34648
# -*- coding: utf-8 -*-
"""
Created on Tue Sep  8 20:37:12 2020

@author: liang
"""
import math
X = int(input())
N = int(math.sqrt(X))
lis = list(range(2,N+1))
#print(N)
#print(lis)
ans = X 

while True:
    if all(ans%i != 0 for i in lis):
        print(ans)
        break
    #print(ans)
    ans += 1

Measured memory_bytes: 9084
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0; i < (n); i++)
#define rep1(i, n) for(int i = 1; i <= (n); i++)
#define co(x) cout << (x) << "\n"
#define cosp(x) cout << (x) << " "
#define ce(x) cerr << (x) << "\n"
#define cesp(x) cerr << (x) << " "
#define pb push_back
#define mp make_pair
#define Would
#define you
#define please

//試してて御免

const int cm = 1 << 15;
char ci[cm];
char *cn = ci + cm;
inline char getcha() { 
	if (cn - ci == cm) { fread(ci, 1, cm, stdin); cn = ci; }
	char ret = *cn;
	cn++;
	return ret;
}
inline char getcha2() {
	char ret = *cn;
	cn++;
	return ret;
}

inline int getint() {
	if (cn - ci + 25 > cm) {
		char C = getcha();
		int A = C - '0';
		while (isdigit(C = getcha())) A = A * 10 + C - '0';
		return A;
	}
	else {
		char C = getcha2();
		int A = C - '0';
		while (isdigit(C = getcha2())) A = A * 10 + C - '0';
		return A;
	}
}

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


	int N, X;
	N = getint();
	X = getint();

	int A = 0;
	ll kotae = 0;
	rep(i, N) {
		int B = getint();
		if (A + B > X) {
			kotae += A + B - X;
			B = X - A;
		}
		A = B;
	}
	co(kotae);

	Would you please return 0;
}

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

int A, B, C, D, E, F;
vector<int> Ww, Ws;

int main() {
	cin >> A >> B >> C >> D >> E >> F;
	for (int i = 0; 100*A*i <= F; i++) {
		for (int j = 0; 100*A*i + 100*B*j <= F; j++) {
			Ww.push_back(100 * A*i + 100 * B*j);
		}
	}
	for (int i = 0; C*i <= F; i++) {
		for (int j = 0; C*i + D*j <= F; j++) {
			Ws.push_back(C*i + D*j);
		}
	}

	sort(Ww.begin(), Ww.end());
	sort(Ws.begin(), Ws.end());

	double dmax = 100.0 * E / (100.0 + E);
	double d = 0;
	int w, s;
	bool over = false;
	for (int i = 0; i < Ww.size(); i++) {
		for (int j = 0; j < Ws.size(); j++) {
			if (Ww[i] + Ws[j] > F) break;

			double dn = 100.0 * Ws[j] / (Ww[i] + Ws[j]);
			if (dn <= dmax && max(dn, d) == dn) {
				d = dn;
				w = i;
				s = j;
			}
		}
	}
	
	cout << Ww[w] + Ws[s] << " " << Ws[s] << endl;
}


Measured memory_bytes: 1400
#include <iostream>
#include <math.h>
#include <string>
#include <algorithm>
#include <ctype.h>
#include <vector>
using namespace std;

#define ll long long int

int main()
{
    int n, m, x, a;
    int l = 0, r = 0;

    cin >> n >> m >> x;
    for (int i = 0; i < m; i++)
    {
        cin >> a;
        if (a < x)
            l++;
        else
            r++;
    }
    cout << min(l, r) << endl;
}


Measured memory_bytes: 256
n = int(input())
a,b = map(int,input().split())
p = [int(x) for x in input().split()]

p.sort()

p1 = [i for i in p if i<=a]
p2 = [j for j in p if a<j<=b]
p3 = [k for k in p if b<k]

print(min([len(p1),len(p2),len(p3)]))


Measured memory_bytes: 38512
//                             In The Name Of Allah                                           
//                             	Mohammad Hosseini
#include <bits/stdc++.h>
#define	ss second
#define ff first
#define use_fast ios::sync_with_stdio(false), cin.tie(0), cout.tie(0)
#define ret(n) return cout << n, 0
#define se(n) cout << setprecision(n) << fixed
#define pb push_back
#define int long long
#define ld long double
#pragma GCC optimize("Ofast,no-stack-protector,unroll-loops")
#pragma GCC optimize("no-stack-protector,fast-math")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
using namespace std; 

const int N = 1e5 + 100, OO = 100, T = 10, M = 100, P = 6151, SQ = 280, lg = 30;
typedef pair <int, int> pii;
vector <int> v[N];
int n, m, col[N], C[2];
bool bi;

void dfs(int x, bool c) {
	col[x] = c; 
	++C[c];
	for (int u : v[x]) {
		if (col[u] == -1) 
			dfs(u, !c);
		else if(col[x] == col[u])
			bi = false;
	}
}

int32_t main() {
	use_fast;
	int n, m;
	cin >> n >> m;
	for(int i = 0; i < m; i++) {
		int x, y;
		cin >> x >> y;
		v[x].pb(y);
		v[y].pb(x);
	}
	for(int i = 1; i <= n; i++) 
		col[i] = -1;
	int d0 = 0, d1 = 0, d2 = 0;
	for(int i = 1; i <= n; i++) {
		if(col[i] == -1) {
			C[0] = C[1] = 0; 
			bi = true;
			dfs(i, 0);
			if(bi) {
				if(C[1]) 
					d2++;
				else 
					d0++;
			} 
			else d1++;
		}
	}
	cout << 2 * d0 * n - d0 * d0 + 2 * d2 * d1 + d1 * d1 + 2 * d2 * d2 << endl; 
 	return 0;
}
/*
be carefull :
1- if not solve after 20 min, read again twice
2- after submit read the code again
3- fun with contest
4- uploaded by ubuntu 20.04 
5- ...
*/



Measured memory_bytes: 16676
#include <bits/stdc++.h>
using namespace std;
using lint = long long;
template<class T = int> using V = vector<T>;
template<class T = int> using VV = V< V<T> >;

int main() {
  cin.tie(nullptr); ios::sync_with_stdio(false);
  string s; cin >> s;
  cout << (s[0] != s[1] and s[1] != s[2] and s[2] != s[3] ? "Good" : "Bad") << '\n';
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
ull B=5575777;
ull getHash(vector<int> &v){
  ull res=0;
  for(int i=0;i<v.size();i++)
    res=res*B+(v[i]+1);
  return res;
}

ll mod=1e9+7;

int N,X,Y,Z;


bool check(vector<int> &v){

  int mini=0;
  int size=v.size();

  for(int i=0;i<size;i++){
    int sum=0;
    bool fx=false,fy=false,fz=false;
    bool ok=true;
    for(int j=i;j<size;j++){
      sum+=v[j];
      if(X==sum)fx=true;
      if(fx==false && X<sum)ok=false;
      
      if(X+Y==sum)fy=true;
      if(fy==false&&X+Y<sum)ok=false;
      
      if(X+Y+Z==sum)fz=true;
      if(fz==false&&X+Y+Z<sum)ok=false;
    }
    
    if(mini==i&&ok==false)mini=i+1;
    if(fx&&fy&&fz)return true;
  }

  /*
  if(v.size()==2&&v[0]==5){
    for(int i=0;i<v.size();i++)
      cout<<v[i]<<' ';
    cout<<mini<<endl;
  }
  */
  v.erase( v.begin(), v.begin()+mini);
  /*
  if(v.size()==2&&v[0]==5){
    for(int i=0;i<v.size();i++)
      cout<<v[i]<<' ';
    cout<<endl;
  }
  */
  return false;
}

ll mpow[100];


unordered_map< ull , ll > mp[41];

ll rec(int p,vector<int> v){

  if(p==N)return 0;
  ull vkey=getHash(v);
  
  if(mp[p].count(vkey))
    return mp[p][vkey];
  
  ll res=0;

  for(int i=1;i<=10;i++){
    vector<int> next=v;
    next.push_back(i);
    if(check(next)){
      res+=mpow[N-1-p];
      if(res>mod)res-=mod;
      continue;
    }
    res+=rec(p+1,next);
    if(res>mod)res-=mod;
  }
  
  return mp[p][vkey]=res;
}

int main(){
  mpow[0]=1;
  for(int i=1;i<100;i++)
    mpow[i]=mpow[i-1]*10%mod;
  
  cin>>N>>X>>Y>>Z;

  if(X==5&&Y==7&&Z==5){
    if(N==40){cout<<562805100<<endl;
    
      return 0;
    }
  }

  vector<int> vec;
  cout<< rec(0,vec) <<endl;
  return 0;
}


Measured memory_bytes: 23168
#include <bits/stdc++.h>
#define rep(i,a,b) for(ll i=ll(a);i<ll(b);i++)
#define irep(i,a,b) for(ll i=ll(a);i>=ll(b);i--)
#define pb push_back
#define mp make_pair
#define pll pair<ll,ll>
#define endl "\n"
using ll=long long;
using ld=long double;
using namespace std;
const ll mod= 1e9+7;
const ll INF = 1LL<<60;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
ll GCD(ll a, ll b) { return b ? GCD(b, a%b) : a; }


ll a[1100],b[1100];
vector<vector<ll>> dp(1100,vector<ll>(11000,INF));
main(){
  ll h,n,ans=0;
  cin>>h>>n;
  rep(i,0,n)cin>>a[i]>>b[i];
  dp[0][h]=0;
  rep(i,0,n){
    irep(j,h,0){
      dp[i+1][j]=min(dp[i+1][j],dp[i][j]);
      dp[i][max(j-a[i],(ll)0)]=min(dp[i][max(j-a[i],(ll)0)],dp[i][j]+b[i]);
    }
  }
  cout<<dp[n][0];
}


Measured memory_bytes: 94976
n = int(input())
lis = list(map(int,input().split()))
lis[0]-=1

for i in range(n-1):
  if lis[i] < lis[i+1]:
    lis[i+1] -= 1
  elif lis[i] > lis[i+1]:
    print("No")
    exit()
print("Yes")

Measured memory_bytes: 15020
#include<string>
#include<string.h>
#include<map>
#include<set>
#include<vector>
#include<stdio.h>
#include<math.h>
#include<iostream>
#include<algorithm>
#include<queue>
using namespace std;
int x,a,b;
int main(){
cin>>x>>a>>b;
int c=x-a;
int sm=c%b;
cout<<sm<<endl;
return 0;
}

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

public class Main {

	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		int n = scan.nextInt();
		int a[]=new int[n];
		for(int i=0;i<n;i++) {
			a[i]=scan.nextInt();
		}
		scan.close();
		Arrays.sort(a);
		int alice=0,bob=0,check=0;
		for(int i=n-1;i>=0;i--) {
			if(check%2==0)alice+=a[i];
			else bob+=a[i];
			check++;
		}
		System.out.println(alice-bob);
	}

}

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

int main() {
  int k, n;
  cin >> k >> n;
  vector<int> a(n);
  for (int i = 0; i < n; i++) {
    cin >> a.at(i);
  }
  a.push_back(a.at(0) + k);
  int mx = 0;
  for (int i = 0; i < n; i++) {
    mx = max(mx, a.at(i + 1) - a.at(i));
  }
  cout << k - mx << endl;
  return 0;
}


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

using namespace std;

#define ff first
#define ss second
#define pb push_back
using ii = pair<long long, long long>;
using ll = long long;

int main (){
	int n;
	scanf("%d",&n);
	if(n == 4){
		printf("2 5 20 63\n");
		return 0;
	}
	else if(n == 3){
		printf("2 5 63\n");
		return 0;
	}
	set<int> s;
	for(int i = 15; i <= 30000; i += 6){
		s.insert(i);
	}
	vector<int> ans = {2, 3, 9};
	int r = 2;
	int i = 4;
	int sum1 = 2 + 3 + 9;
	// printf("%d\n",s.size() );
	for(; i <= 30000 && ans.size() < n; i += 2){
		if((n - ans.size()) % 2 == 0 && !r && s.size() >= (n - ans.size())){
			while(ans.size() < n){
				ans.pb(*s.begin());
				s.erase(s.begin());
			}
			break;
		}
		ans.pb(i);
		r = (r + i) % 3;
		sum1 += i;
	}
	// printf("%d %d %d %d\n",ans.back(),ans.size(),r,s.size() );
	while(r != 0){
		r = (r + 3 - (ans.back() % 2)) % 3;
		ans.pop_back();
	}
	if(r == 0 && (n - ans.size()) % 2 == 0 && s.size() >= (n - ans.size())){
		while(ans.size() < n){
			ans.pb(*s.begin());
			s.erase(s.begin());
		}
	} 
	while(ans.size() < n){
		if(i % 3 == 0 && i%2 == 0){
			ans.pb(i);
		}
		i++;
	}
	int sum = 0;
	int gcd = 0;
	for(int i = 0; i < n; i++){
		printf("%d ",ans[i] );
		sum += ans[i];
		// gcd = __gcd(gcd, ans[i]);
	}
	printf("\n");
	// printf("%d %d %d %d %d\n",sum, sum%3, sum%2, ans.size(), gcd );
	return 0;
}

Measured memory_bytes: 768
s = input()

l = len(s)

a = l // 2
for i in range(a):
    if s[i] != s[l - i - 1]:
        print("No")
        exit()

ll = l // 2
a = ll // 2
for i in range(a):
    if s[i] != s[ll - i - 1]:
        print("No")
        exit()

lll = (l + 3)//2
for i in range(a):
    if s[i + lll - 1] != s[l - i - 1]:
        print("No")
        exit()

print("Yes")


Measured memory_bytes: 3064
S = list(input())
former = 0
latter = 0

if int(S[0]) == 0:
    former = int(S[1])
else:
    former = int(S[0]+S[1])


if int(S[2]) == 0:
    latter = int(S[3])
else:
    latter = int(S[2] + S[3])


if former == 0 or latter == 0:
    if former == 0 and latter == 0:
        print('NA')
    elif former == 0 and latter < 13:
        print('YYMM')
    elif former < 13 and latter == 0:
        print('MMYY')
    else:
        print('NA')
else:
    if former > 12 and latter > 12:
        print('NA')
    elif former > 12 and latter < 13:
        print('YYMM')
    elif former < 13 and latter > 12:
        print('MMYY')
    elif former < 13 and latter < 13:
        print('AMBIGUOUS')


Measured memory_bytes: 3064
#include<iostream>
using namespace std; 
int main() {
	int a, b, c, x, y,cost=0;
	cin >> a >> b >> c >> x >> y;
	if ((a + b) > 2 * c) {
		if (x > y) {
			cost = 2 * c*y;
			x -= y;
			if (a > 2 * c)
				cost += 2 * c*x;
			else
				cost += x * a;

		}
		else
		{
			cost = 2 * c*x;
			y -= x;
			if (b > 2 * c)
				cost += 2 * c*y;
			else
				cost += y * b;
		}
	}
	else
		cost = a * x + b * y;
	cout << cost<<endl;
	//system("pause");
	return 0;
}

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

using namespace std;
using int64 = long long;

constexpr int DEBUG = 0;

struct Query {
  int index;
  int l, r;
};

// Supports two operations.
// - Updates a single element.
// - Returns a sum of a range.
// Verified: CF573Div1D
class BinaryIndexedTree {
 private:
  int n;
  vector<int64> xs;
 public:
  BinaryIndexedTree(int n) : n(n), xs(n) {}

  // Adds x to the i-th element.
  void Add(int i, int64 x) {
    int cur = i;
    while (cur < n) {
      xs[cur] += x;
      cur = cur | (cur + 1);
    }
  }

  // Returns a sum of a range [l, r).
  int64 SumRange(int l, int r) {
    if (l >= r) return 0;
    if (l > 0) {
      return SumRange(0, r) - SumRange(0, l);
    }
    int64 s = 0;
    int i = r - 1;
    while (i >= 0) {
      s += xs[i];
      i = (i & (i + 1)) - 1;
    }
    return s;
  }
};

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

  int n;
  int q;
  cin >> n >> q;
  vector<int> cs(n);
  for (int i = 0; i < n; i++) {
    cin >> cs[i];
    cs[i]--;
  }
  vector<vector<Query>> r_to_qs(n);
  for (int i = 0; i < q; i++) {
    int l, r;
    cin >> l >> r;
    l--;
    r--;
    r_to_qs[r].push_back({i, l, r});
  }

  vector<int> last_pos_vector(n, -1);
  
  BinaryIndexedTree tree(n);
  
  vector<int64> ans(q);
  for (int r = 0; r < n; r++) {
    int c = cs[r];
    int p = last_pos_vector[c];
    last_pos_vector[c] = r;
    if (p >= 0) {
      tree.Add(p, -1);
    }
    tree.Add(r, 1);
    for (const auto& q : r_to_qs[r]) {
      int64 v = tree.SumRange(q.l, q.r + 1);
      ans[q.index] = v;
    }
  }
  for (int i = 0; i < q; i++) {
    cout << ans[i] << "\n";
  }
}


Measured memory_bytes: 38108
//#pragma GCC target("avx2")
//#pragma GCC optimization("O3")
//#pragma GCC optimization("unroll-loops")
//assert(q==w) если q!=w --> runtime error
#include <bits/stdc++.h>

#define pb push_back
#define F first
#define S second
#define all(x) x.begin(),x.end()
#define ub upper_bound
#define lb lower_bound
#define bit __builtin_popcount
#define memset(x) memset(x,0,sizeof(x))

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef vector<vector<int>> matrix;

inline void boost(){
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
}

const ll maxn=2e5+123;
const ll inf=1e9+123;
const ll linf=1e18+123;
const ll mod=1e9+7;
const double eps=1e-9;
const double pi=acos(-1);
int dx[8]={0,1,-1,0,1,-1,1,-1};
int dy[8]={1,0,0,-1,1,1,-1,-1};
bool prime(int x){
    for(int i=2;i<=sqrt(x);i++){
        if(x%i==0){
            return 0;
        }
    }
    return 1;
}
int main(){
    boost();
    //freopen("input.txt","r",stdin);
    //freopen("output.txt","w",stdout);
    int x;
    cin>>x;
    while(prime(x)==0){
        x++;
    }
    cout<<x;
	exit(0);
}


Measured memory_bytes: 256
import sys


stdin = sys.stdin
def ns(): return stdin.readline().rstrip()
def ni(): return int(stdin.readline().rstrip())
def nm(): return map(int, stdin.readline().split())
def nl(): return list(map(int, stdin.readline().split()))


def main():
    N = list(map(int, list(ns())))
    if sum(N) % 9 == 0:
        print('Yes')
    else:
        print('No')


if __name__ == '__main__':
    main()


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

using namespace std;

#define REP(i,a,b) for(int i=a;i<(int)b;i++)
#define rep(i,n) REP(i,0,n)
#define all(c) (c).begin(), (c).end()
#define zero(a) memset(a, 0, sizeof a)
#define minus(a) memset(a, -1, sizeof a)
#define watch(a) { std::cout << #a << " = " << a << "\n"; }
template<class T1, class T2> inline bool minimize(T1 &a, T2 b) { return b < a && (a = b, 1); }
template<class T1, class T2> inline bool maximize(T1 &a, T2 b) { return a < b && (a = b, 1); }
template<class T, class V> istream& operator>> (istream& ist, pair<T, V>& p) { return ist >> p.first >> p.second; }
template<class T> ostream& operator<< (ostream& ost, pair<T, T>& p) { return ost << p.first << ", " << p.second; }
template<class T> istream& operator>> (istream& ist, vector<T>& vs) { for(auto& e: vs) ist >> e; return ist; }

typedef long long ll;
int const inf = INT_MAX / 2;

int main() {
  ll R, G, B, N; cin >> R >> G >> B >> N;
  int count = 0;
  rep(r, N + 1) rep(g, N + 1) {
    int bB = N - r * R - g * G;
    count += bB >= 0 && (bB % B == 0);
  }
  cout << count << endl;
}


Measured memory_bytes: 256
#include <iostream>

using namespace std;

char A[50][50] = {{0}};
char B[50][50] = {{0}};

bool IsSubset(int i, int j, int M) {
  for (int k = 0; k < M; ++k) {
    for (int l = 0; l < M; ++l) {
      if (A[i + k][j + l] != B[k][l]) {
        return false;
      }
    }
  }
  return true;
}

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

  int N, M;
  cin >> N >> M;
  for (int i = 0; i < N; ++i)
    for (int j = 0; j < N; ++j) cin >> A[i][j];
  for (int i = 0; i < M; ++i)
    for (int j = 0; j < M; ++j) cin >> B[i][j];

  for (int i = 0; i <= N - M; ++i) {
    for (int j = 0; j <= N - M; ++j) {
      if (IsSubset(i, j, M)) {
        cout << "Yes\n";
        return 0;
      }
    }
  }
  cout << "No\n";
  return 0;
}


Measured memory_bytes: 256
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <string>
#include <cmath>
#include <algorithm>
#include <vector>
#include <map>
#include <queue>
#include <set>
using namespace std;
typedef long long LL;
const int MaxN = 1e5;
const int Inf = 1 << 30;
const LL mod = 1e9 + 7;

int main()
{
	LL N,x;
	while(~scanf("%lld",&N)){
		x = 1LL;
		for(LL i = 2;i <= N;i++) x = x * i % mod;
		printf("%lld\n",x);
	}
    return 0;
}

Measured memory_bytes: 128
from math import gcd
k = int(input())

ans = 0

lst = [[0 for _ in range(1, k+1)] for __ in range(k+1)]
cnt = [0 for _ in range(1, k+1)]


for i in range(1, k+1):
    for j in range(1, k+1):
        tmp = gcd(i,j)
        for l in range(1,k+1):
            ans += gcd(tmp,l)
            
print(ans)


Measured memory_bytes: 71532
#include <bits/stdc++.h>//Carefully Crafted by hetp111
using namespace std;
#define int long long
#define double long double
#define all(v) (v).begin(),(v).end()
#define vi vector<int>
#define vvi vector<vi>
#define pii pair<int,int>
#define vii vector<pii>
#define MOD 1000000007
#define MOD2 998244353
#define MOD3 1000000009
#define PI acos(-1)
#define eps (1e-8)
#define INF (1e18)
#define FASTER ios_base::sync_with_stdio(0);cin.tie(0)
template<class A,class B>ostream&operator<<(ostream&out,const pair<A,B>&a){return out<<"("<<a.first<<","<<a.second<<")";}
template<class A>ostream&operator<<(ostream&out,const vector<A>&a){for(const A &it:a)out<<it<<" ";return out;}
template<class A,class B>istream&operator>>(istream&in,pair<A,B>&a){return in>>a.first>>a.second;}
template<class A>istream&operator>>(istream&in,vector<A>&a){for(A &i:a)in>>i;return in;}
//ifstream cinn("in.in");ofstream coutt("out.out");
int poww(const int &a,int b,const int &m=MOD){if(b==0)return 1;int x=poww(a,b/2,m);x=x*x%m;if(b&1)x=x*a%m;return x;}
int ceil(const int &a,const int &b){return (a+b-1)/b;}
////Read:
//Check corner cases, n==1;
//
////Some function:
//__builtin_popcountll(), 

int n,c,dp[55][55][55][55];
vi v;

int f(int i,int cnt,int mxgap,int lst){
    if(i==n){
        mxgap=max(mxgap,i-lst-1);
        if(cnt+(n-cnt-mxgap)*2<=c)return 0;
        return -INF;
    }
    int &ans=dp[i][cnt][mxgap][lst+1];
    if(ans!=-INF)return ans;
    ans=v[i]+f(i+1,cnt+1,max(mxgap,i-lst-1),i);
    ans=max(ans,f(i+1,cnt,mxgap,lst));
    return ans;
}

signed main(){
    FASTER;
    cin>>n>>c;
    v=vi(n);cin>>v;
    for(int i=0;i<55;i++){
        for(int j=0;j<55;j++){
            for(int k=0;k<55;k++){
                for(int l=0;l<55;l++){
                    dp[i][j][k][l]=-INF;
                }
            }
        }
    }
    cout<<f(0,0,0,-1);
}


Measured memory_bytes: 75116
n,m=map(int,input().split())
a=list(map(int,input().split()))
a.sort()
dic={}
for i in range(m):
  b,c=map(int,input().split())
  if c in dic:
    dic[c]+=b
  else:
    dic[c]=b
ol=sorted(dic.items(), reverse=True, key=lambda x:x[0])
index=0
loopstop=False
for li in ol:
  for i in range(li[1]):
    if li[0]>a[index]:
      a[index]=li[0]
      index+=1
      if index>=n:
        loopstop=True
        break;
    else:
      loopstop=True
      break;
  if loopstop:
    break
print(sum(a))

Measured memory_bytes: 28656
import java.util.*;
class Main{
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int h = sc.nextInt(),w=sc.nextInt();
        String[] a = new String[h];
        for(int i =0;i<h;i++){
            a[i]=sc.next();
        }
        for(int i = 0;i<w+2;i++){
            System.out.print("#");
        }
        System.out.println("");
        for(int i = 0;i<h;i++){
            System.out.print("#"+a[i]+"#");
         	System.out.println("");
        }
        for(int i = 0;i<w+2;i++){
            System.out.print("#");
        }
}
}


Measured memory_bytes: 23764
#include <iostream>
#include <algorithm>

using namespace std;

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

  int s, s_max;
  int in, out;
  s = s_max = m;

  for(int i = 0; i < n; i += 1){
    cin >> in >> out;
    s += (in - out);

    if(s < 0) {
      break;
    }

    s_max = max(s, s_max);
  }

  if(s < 0) {
    s_max = 0;
  }
  cout << s_max << endl;

  return 0;
}

Measured memory_bytes: 1164