akhauriyash/Code-Regression huggingface dataset:
class UnionFind:
    def __init__(self,n):
        self.n=n
        self.parent=[i for i in range(n)]
        self.rank=[1]*n#木の高さ
        self.size=[1]*n#size[i]はiを根とするグループのサイズ

    def find(self,x):#ｘの根（親）を返す
        if self.parent[x]==x:
            return x
        else:
            self.parent[x]=self.find(self.parent[x])#経路圧縮
            return self.parent[x]

    def unite(self,x,y):#ｘ、ｙの集合の統合
        x=self.find(x)
        y=self.find(y)
        if x!=y:
            if self.rank[x]<self.rank[y]:#ランクの比較
                self.parent[x]=y
                self.size[y]+=self.size[x]
            else:
                self.parent[y]=x
                self.size[x]+=self.size[y]
                if self.rank[x]==self.rank[y]:
                    self.rank[x]+=1
    def group_size(self,x):#ｘが属する集合の大きさ
        return self.size[self.find(x)]
    def is_same(self,x,y):#ｘ、ｙが同じ集合に属するかを判定する
        return self.find(x)==self.find(y)

n,m,k=map(int,input().split())

uf=UnionFind(n)
ans = [0] * n
for i in range(m):
    a, b = map(int, input().split())
    uf.unite(a-1,b-1)
    ans[a - 1] -= 1
    ans[b - 1] -= 1
for i in range(k):
    c, d = map(int, input().split())
    if uf.is_same(c-1,d-1):
        ans[c-1]-=1
        ans[d-1]-=1

for i in range(n):
    ans[i]+=uf.group_size(i)-1
    print(ans[i])


Measured memory_bytes: 18452
n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))

if sum(a) < sum(b):
    print('-1')
    exit()

c = []
t = 0
ans = 0
for x, y in zip(a, b):
    if x < y:
        t += y - x
        ans += 1
    else:
        c.append(x - y)

if ans == 0:
    print('0')
    exit()

c.sort(reverse=True)
for p in c:
    t -= p
    ans += 1
    if t < 0:
        break
print(ans)


Measured memory_bytes: 18708
#include <bits/stdc++.h>
#define fi first
#define se second
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
#define srep(i,s,t) for (int i = s; i < t; ++i)
#define rng(a) a.begin(),a.end()
#define sz(x) (int)(x).size()
#define uni(x) x.erase(unique(rng(x)),x.end())
#define show(x) cout<<#x<<" = "<<x<<endl;
#define PQ(T) priority_queue<T,v(T),greater<T> >
#define newline puts("")
#define v(T) vector<T>
#define vv(T) v(v(T))
#define chmin(x,y) x=min(x,y)
#define chmax(x,y) x=max(x,y)
#define EPS (1e-10)
#define equals(a, b) (fabs((a)-(b)) < EPS)
using namespace std;
typedef long long int ll;
typedef pair<int,int> P;
typedef set<int> S;
typedef queue<int> Q;
typedef queue<P> QP;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<P> vp;
const ll LINF = 1001002003004005006ll;
const int INF = 1001001001;
const int MOD = 1000000007;

map<ll,int> primefact(ll num) {
    map<ll,int> res;
    for (ll i = 2; i * i <= num; i++) {
        int cnt = 0;
        while (num % i == 0) {
            cnt++;
            num /= i;
        }
        if (cnt) res[i] = cnt;
    }
    if (num != 1) res[num] = 1;
    return res;
}

vector<bool> sieve_of_eratosthenes(int n) {
  vector<bool> is_prime(n + 1, true);
  is_prime[0] = is_prime[1] = false;
  for (int i = 2; i * i <= n; ++i)
    if (is_prime[i])
      for (int k = 2 * i; k <= n; k += i)
        is_prime[k] = false;
  return is_prime;
}

int calc(int k) {
  auto r = primefact(k);
  int res = 1;
  for(auto x:r) {
    res *= x.second+1;
  }
  return res;
}
  
int main() {
  int N;
  cin >> N;
  vl fk(N+1,0);
  ll ans = 0;
  srep(k,1,N+1) {
    for(int x=k;x<=N;x+=k) {
      fk[x]++;
    }
    ans += k*fk[k];
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 81380
#include <bits/stdc++.h>
#define r(i,n) for(int i=0;i<n;i++)
#define int long long
using namespace std;
typedef pair<int,int>P;
#define fi first
#define se second


signed main(){
  int n,m;
  int A=0,B=0;
  cin>>n>>m;
  r(i,n){
    int a;
    cin>>a;
    A+=a;
  }
  r(i,m){
    int a;
    cin>>a;
    B+=a;
  }
  cout<<A*B<<endl;
}




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

int main(){
  int n; cin>>n;
  
  for(int i=0;i<n;++i){
    vector<int> edges(3);
    for(int j=0;j<3;++j)cin>>edges[j];
    sort(edges.begin(),edges.end());
    edges[2]*edges[2] == edges[0]*edges[0] + edges[1]*edges[1] ? cout<<"YES"<<endl : cout<<"NO"<<endl;
  }

  return EXIT_SUCCESS;
}

Measured memory_bytes: 1204
#include<stdio.h>

int main(){
	int N;
	scanf("%d",&N);
	
	long long int a[N];
	int i;
	for(i=0;i<N;i++){
		scanf("%lld",&a[i]);
	}
	
	long long int min=1000000001,max=0;
	
	for(i=0;i<N;i++){
		if(a[i]<min) min=a[i];
		if(a[i]>max) max=a[i];
	}
	
	printf("%lld\n",max-min);
	
	return 0;
}

Measured memory_bytes: 128
from bisect import bisect

S = input()
T = input()
N = len(S)
# Sにおいてある文字が出てくる位置を調べる
idxs_S = [[] for _ in range(26)] # a~zの分
for i, c in enumerate(S):
    idx = ord(c) - ord("a")
    idxs_S[idx].append(i)

# Tに出てくる文字がSになければ無理
for c in set(T):
    if len(idxs_S[ord(c) - ord("a")]) == 0:
        print(-1)
        exit()

cnt_all_S = 0
idx_c = -1
for c in T:
    tmp = ord(c) - ord("a")
    idx = bisect(idxs_S[tmp], idx_c)
    if idx == len(idxs_S[tmp]): # 現行のSにこれ以上使えるcがない場合、新たにSを連結してその中からcを取り出す
        idx_c = idxs_S[tmp][0] # Sの中の初めのcの位置まで
        cnt_all_S += 1
    else:
        idx_c = idxs_S[tmp][idx]

print(N*cnt_all_S + idx_c + 1)

Measured memory_bytes: 7668
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
#define mod 100000
int dp[50][3001];
int main(){
        int n,m,s;
        while(scanf("%d%d%d",&n,&m,&s),(n|m|s)){

                for(int i = 0; i < n*n+1; i++){
                        for(int j = 0; j < s+1; j++){
                                dp[i][j] = 0;
                        }
                }

                dp[0][0] = 1;

                for(int i = 1; i < m+1; i++){
                        for(int j = n*n;j > 0; j--){
                                for(int k = i; k < s+1; k++){
                                        dp[j][k] += dp[j-1][k-i];
                                        dp[j][k] %= mod;
                                }
                        }
                }

                /*for(int i = 0; i < n*n+1; i++){
                        for(int j = 0; j < s+1;j++){
                                printf("%3d",dp[i][j]);
                        }
                        puts("");
                }*/

                printf("%d\n",dp[n*n][s]);
        }
        return 0;
}

Measured memory_bytes: 1612
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main{

    static int[] height;
    static int[] minHeight;

    static void min(int i){
        if(i==0){
            minHeight[0] = 0;

        }
        else if(i==1){
            int a = height[0];
            int b = height[1];
            int c = a-b;
            if(c<0){
                c = -c;
            }
            minHeight[1] = c;
        }
        else {
            int d = height[i];
            int a = height[i - 1];
            int b = height[i - 2];

            a = a - d;
            b = b - d;

            if (a < 0) {
                a = -a;
            }
            if (b < 0) {
                b = -b;
            }

            a = minHeight[i-1] + a;
            b = minHeight[i-2] + b;

            int c = a;
            if (a > b) {
                c = b;
            }
            minHeight[i] = c;
        }
    }
    public static void main(String[] args) throws IOException {

        BufferedReader inp = new BufferedReader(new InputStreamReader(System.in));
        String sz = inp.readLine();
        int size = Integer.parseInt(sz);

        String[] given = inp.readLine().split(" ");
        height = new int[size];
        minHeight = new int[size];

        for(int i=0;i<size;i++){
            height[i] = Integer.parseInt(given[i]);
        }

        int ans = 0;

        for (int i=0;i<size;i++){
             min(i);
        }

        System.out.println(minHeight[size-1]);


    }
}


Measured memory_bytes: 33108
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<iomanip>
#include<math.h>
#include<complex>
#include<queue>
#include<deque>
#include<stack>
#include<map>
#include<set>
#include<bitset>
#include<memory.h>
using namespace std;
#define REP(i,m,n) for(int i=(int)m ; i < (int) n ; ++i )
#define rep(i,n) REP(i,0,n)
typedef long long ll;
typedef pair<int,int> P;
typedef pair<ll,int> pli;
const int inf=1e9+7;
const ll longinf=1LL<<60 ;
const ll mod=1e9+7 ;

int main(){
  int n;
  cin >> n;
  ll a[n];
  ll ans=0;
  ll b[n];
  rep(i,n){
    cin >> a[i];
    a[i]--;
    b[a[i]]=i;
  }
  set<ll> se;
  se.insert(-1);
  se.insert(n);
  rep(i,n){
    auto x=se.upper_bound(b[i]);
    ll right=*x;
    x--;
    ll left=*x;
    se.insert(b[i]);
    ans+=(i+1)*((b[i]-left-1)*(right-b[i]-1)+right-left-1);
  }
  cout << ans << endl;
return 0;}


Measured memory_bytes: 12800
#include <iostream>
#include <algorithm>
#include <functional>
#include <string>
#include <vector>
#include <set>
#include <queue>
#include <stack>
#include <numeric>
#include <bitset>
#include <map>
#include <set>
#include <list>
#include <unordered_set>
#include <unordered_map>
#include <stdlib.h>

using namespace std;
 
typedef long long ll;
typedef pair<int, int> P;
static const int INF = 1000010000;
static const int MOD = 1000000007;
 
#define FOR(i, a, b) for(int i = (a); i < (b); ++i)
#define REP(i, n) for(int i = 0; i < (n); ++i)
#define SORT(v) sort(v.begin(), v.end());
#define pb push_back
#define mp make_pair
#define np next_permutation
#define pq priority_queue

//int dx4[4] = {0,1,0,-1}, dy4[4] = {-1,0,1,0};
//int dx5[5] = {-1,0,0,0,1}, dy5[5] = {0,-1,0,1,0};
//int dx8[8] = {-1,0,1,1,1,0,-1,-1}, dy8[8] = {1,1,1,0,-1,-1,-1,0};
//int dx9[9] = {-1,0,1,1,1,0,-1,-1,0}, dy9[9] = {1,1,1,0,-1,-1,-1,0,0};

//-----end of template-----//

int main(){
    int a, b;
    cin >> a >> b;
    if(a * b % 2 == 1) cout << "Yes" << endl;
    else cout << "No" << endl;
}

Measured memory_bytes: 256
import math
N, H = map(int, input().split())

A = []
B = []
for i in range(N):
  a, b = map(int, input().split())
  A.append(a)
  B.append(b)
A = sorted(A, reverse = True)
B = sorted(B, reverse = True)

while B[-1] < A[0]:
  B.pop()
S = 0
if sum(B) >= H:
  for i in range(N):
    S += B[i]
    if S >= H:
      print (i+1)
      break
else:
  H -= sum(B)
  print (math.ceil(H / A[0]) + len(B))

Measured memory_bytes: 12160
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<cmath>
#include<climits>
#include<map>
#include<set>
#include<queue>
#include<stack>
#include<bitset>
#include<iomanip>
using namespace std;

#define rep(i,j,n) for(int i=(j);i<(n);i++)
#define rep2(i,j,n) for(int i=(j);i<=(n);i++)
#define all(i) i.begin(),i.end()

typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef vector<string> vs;
typedef vector<vector<string>> vvs;
typedef pair<int, int> pi;
typedef long long i64;

int main() {
	i64 x, y;
	cin >> x >> y;
	i64 a = x;
	int cou = 0;
	while (a <= y) {
		a *= 2;
		cou++;
	}
	cout << cou << endl;
}

Measured memory_bytes: 256
import java.util.Scanner;


public class Main {
    static   Scanner scan = new Scanner(System.in);
 
    public static void main(String[] args) {
       int x,y;
        while(true){
            x=scan.nextInt(); y=scan.nextInt();
            if(x==0 && y==0){
                break;
            }
           
            for(int i=0; i<x;i++){
                for(int j=0; j<y; j++){
                   if (i % 2 == 0) {
                        if (j % 2 == 0) {
                            System.out.print("#");
                        }else{
                            System.out.print(".");
                       }
                    }else{
                        if(j%2==0){
                            System.out.print(".");
                        }else{
                            System.out.print("#");
                        }
                    }
                }
                System.out.println();
            }
            System.out.println();
        }
        }
}


Measured memory_bytes: 35860
import java.io.IOException;
import java.io.InputStream;
import java.util.NoSuchElementException;
import java.lang.Math;

public class Main {
	public static void main(String[] args) {
		FS reader = new FS();
		// write reader
      int N = reader.nextInt();
      double[] a = new double[N];
      double sum = 0.0;
      for (int i=0; i<N; i++) {
        a[i] = (double)reader.nextInt();
        sum += a[i];
      }
      double ave   = sum/(double)N;
      double min   = Double.MAX_VALUE;
      int minId = -1;
      for (int i=0; i<N; i++) {
        double tmp = Math.abs(a[i]-ave);
        if (tmp < min) {
          min = tmp;
          minId = i;
        }
      }
      System.out.println(minId);
	}
	
	public static void solver() {
		// write logic
	}
	
	// Read Class
	static class FS {
		private final InputStream in = System.in;
		private final byte[] buffer = new byte[1024];
		private int ptr = 0;
		private int buflen = 0;
		private boolean hasNextByte() {
			if (ptr < buflen) {
				return true;
			} else {
				ptr = 0;
				try {
					buflen = in.read(buffer);
				} catch (IOException e) {
					e.printStackTrace();
				}
				if (buflen <= 0) {
					return false;
				}
			}
			return true;
		}
	
		private int readByte() { return hasNextByte() ? buffer[ptr++] : -1;}
		private boolean isPrintableChar(int c) {return 33 <= c && c <= 126;}
		private void skipUnprintable() {while(hasNextByte() && !isPrintableChar(buffer[ptr])) ptr++;}
	
		public boolean hasNext() { skipUnprintable(); return hasNextByte();}
		public String next() {
			if (!hasNext()) throw new NoSuchElementException();
			StringBuilder sb = new StringBuilder();
			int b = readByte();
			while(isPrintableChar(b)) {
				sb.appendCodePoint(b);
				b = readByte();
			}
			return sb.toString();
		}
		public int nextInt() {
			return (int)nextLong();
		}
		public long nextLong() {
			if (!hasNext()) throw new NoSuchElementException();
			long n = 0;
			boolean minus = false;
			int b = readByte();
			if (b == '-') {
				minus = true;
				b = readByte();
			}
			if (b < '0' || '9' < b) {
				throw new NumberFormatException();
			}
			while(true) {
				if ('0' <= b && b <= '9') {
					n *= 10;
					n += b - '0';
				} else if(b == -1 || !isPrintableChar(b)) {
					return minus ? -n : n;
				} else {
					throw new NumberFormatException();
				}
				b = readByte();
			}
		}
	}
}


Measured memory_bytes: 22484
import sys

input = sys.stdin.readline
sys.setrecursionlimit(1000000)


def getN():
    return int(input())


def getList():
    return list(map(int, input().split()))


import math

ans = 0
m, d = getList()

for i in range(1, m+1):
    for j in range(1, d+1):
        if j <= 21:
            pass
        else:
            if (j % 10) * (j // 10) == i:
                if (j % 10) >= 2:
                    # print(i, j)
                    ans += 1

print(ans)

Measured memory_bytes: 38768
import java.util.*;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int numOfSheets = sc.nextInt();
		int[] numArray = new int[numOfSheets];
		for(int i = 0; i < numOfSheets; i++) {
			numArray[i] = sc.nextInt();
		}
		int[] sortArray = new int[numArray.length];
		int Alice = 0;
		int Bob = 0;
		for (int i = 0; i < numArray.length; i++) {
			int placeNum = 0;
			sortArray[i] = 0;
			for (int j = 0; j < sortArray.length; j++) {
				if(sortArray[i] < numArray[j]) {
					sortArray[i] = numArray[j];
					placeNum = j;
				}
			}
			numArray[placeNum] = 0;
			if(i % 2 == 0) {
				Alice += sortArray[i];
			}else {
				Bob += sortArray[i];
			}
		}
		System.out.print(Alice - Bob);
	}
}


Measured memory_bytes: 36100
#include<bits/stdc++.h>
#define ll long long 
#define clr(c) memset(c,0,sizeof(c))
#define inf 0x7fffffff
const int mod=1e9+7;
const int M=4e5+5;
const int N=2e5+10;
using namespace std;
inline ll read()
{
	ll sum=0,b=1;char c=getchar();
	while(!isdigit(c)){if(c=='-') b=-1; c=getchar();}
	while(isdigit(c)){sum=sum*10+c-'0';c=getchar();}
	return b*sum;
}
ll t,n,m,k;
int a[200];
ll ans;
int main()
{
	int i,j;
    n=read(); m=read();
    if(n==1||m==1){printf("1"); return 0;}
    if(m%2==0){
        ans=(n/2+(n+1)/2)*m/2;
    } 
    else {
        ans=(n/2+(n+1)/2)*(m/2)+(n+1)/2;
    }

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

Measured memory_bytes: 256
#include <iostream>
#include <fstream>
#include <vector>
#include <cstring>
#include <algorithm>

#define REP(i, n) for (long long i = 0; i < (n); i++) 
#define ll long long
const ll MOD = 1000000007;

using namespace std;

int main()
{
    //    std::ifstream in("input.txt");
//    std::cin.rdbuf(in.rdbuf());
    ll N,M,res;
    cin >> N;

    vector <ll> l(N);

    int tmp;
    REP(i,N)
    {
        cin >> l[i];
    }

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

    ll beforeNum;
    ll ren = 1;
    ll cnt = 0;

    beforeNum = l[0];
    for(ll i = 1; i < N; i++)
    {
        if(beforeNum == l[i])ren++;
        else
        {
            if(ren % 2 == 1)cnt++;
            beforeNum = l[i];
            ren = 1;
        }
    }
    //末尾の処理
    if(ren % 2 == 1)cnt++;

    cout << cnt << endl;

    return 0;
}



Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int a,b,c,d;
  cin >> a >> b >> c >> d;
  while(a > 0 && c > 0){
    a -= d;
    c -= b;
  }
  if(a > 0){
    cout << "Yes";
  }else if(a <=0 && c <= 0){
    cout << "Yes";
  }else{
    cout << "No";
  }
}

Measured memory_bytes: 3640
s = input()
for i in range(len(s)):
  if i%2 == 0:
    if s[i] == "L":
      print("No")
      break
  if i%2 == 1:
    if s[i]=="R":
      print("No")
      break
  if i==len(s)-1:
    print("Yes")

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

typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef vector<double> vd;
typedef vector<ll> vl;
typedef vector<vi> vvi;
typedef vector<vl> vvl;
typedef pair<int,int> pii;
typedef pair<double, double> pdd;
typedef pair<ll, ll> pll;
typedef vector<pii> vii;
typedef vector<pll> vll;
typedef vector<pdd> vdd;

#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define mem(a,b) memset(a, b, sizeof(a) )
#define all(x) (x).begin(),(x).end()
#define INF 1000000000000
#define MOD 1000000007
#define PB push_back
#define MP make_pair
#define F first
#define S second

inline void normal(ll &a) { a %= MOD; (a < 0) && (a += MOD); }
inline ll modMul(ll a, ll b) { a %= MOD, b %= MOD; normal(a), normal(b); return (a*b)%MOD; }
inline ll modAdd(ll a, ll b) { a %= MOD, b %= MOD; normal(a), normal(b); return (a+b)%MOD; }
inline ll modSub(ll a, ll b) { a %= MOD, b %= MOD; normal(a), normal(b); a -= b; normal(a); return a; }
inline ll modPow(ll b, ll p) { ll r = 1; while(p) { if(p&1) r = modMul(r, b); b = modMul(b, b); p >>= 1; } return r; }
inline ll modInverse(ll a) { return modPow(a, MOD-2); }
inline ll modDiv(ll a, ll b) { return modMul(a, modInverse(b)); }

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

int ctoi(char c) {
	if (c >= '0' && c <= '9') {
		return c - '0';
	}
	return 0;
}

int main(){
	string s;cin>>s;
	sort(all(s));
	s.erase(unique(all(s)),s.end());
	char f='a';
	rep(i,s.size()){
		if(f==s[i]){
			f++;
		}
		else{
			cout<<f<<endl;
			return 0;
		}
	}
	if(f!='{')cout<<f<<endl;
	else cout<<"None"<<endl;
}


Measured memory_bytes: 512
#include <bits/stdc++.h>
const int INF = 1e9;
const int MOD = 1e9+7;
const long long LINF = 1e18;
#define dump(x)  cout << 'x' << ' = ' << (x) << ` `;
#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>=0;i--)
#define FOREACH(x,a) for(auto& (x) : (a) )
typedef long long ll;
using namespace std;
typedef pair<ll, ll> P;

template<typename T>
void print(const vector<T> &x) {
    int n = x.size();
    rep(i,n) {
        cout << x[i];
        if (i!=n-1) cout<<" ";
        else cout << endl;
    }
}

template<typename T>
void print(const vector<vector<T>> &x) {
    int n = x.size();
    rep(i,n) {
        rep(j,x[i].size()) {
            cout << x[i][j] << " ";
        }
        cout << endl;
    }
}

template<typename T>
void print(const vector<T> &x, int n) {
    rep(i,n) {
        cout << x[i];
        if (i!=n-1) cout<<" ";
        else cout << endl;
    }
}

template<typename T>
void print(const vector<vector<T>> &x, int n, int m) {
    rep(i,n) {
        rep(j,m) {
            cout << x[i][j] << " ";
        }
        cout << endl;
    }
}

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; }

void input_init() {
    cin.tie(0); ios::sync_with_stdio(false);
}

int main(int argc, char const *argv[]) {
    int n; cin>>n;
    int m = n*(n-1)/2;
    vector<vector<int>> g(n*(n-1)/2);
    vector<int> h(m);
    map<P,int> node;
    int cnt = 0;
    rep(i,n) {
        vector<int> to(n-1);
        rep(j,n-1) {
            cin>>to[j];
            --to[j];
        }
        rep(j,n-2) {
            int u,v;
            int a = i; int b = to[j];
            if (a>b) swap(a,b);
            if (!node.count(P(a,b))) {
                u = cnt;
                node[P(a,b)] = cnt;
                cnt++;
            }
            else  {
                u = node[P(a,b)];
            }
            // cout << a+1 << "-" << b+1 << " -> ";
            a = i; b = to[j+1];
            if (a>b) swap(a,b);
            if (!node.count(P(a,b))) {
                node[P(a,b)] = cnt;
                v = cnt;
                cnt++;
            }
            else {
                v = node[P(a,b)];
            }
            g[u].push_back(v);
            // cout << a+1 << "-" << b+1 << '\n';
            // cout << u << " -> " << v << '\n';
            h[v]++;
        }
    }

    

    stack<int> st;
    vector<int> topo;
    rep(i,m) if (h[i]==0) {
        st.push(i);
    }

    while (st.size()) {
        int v = st.top(); st.pop();
        topo.push_back(v);
        for (auto&& e: g[v]) {
            h[e]--;
            if (h[e]==0) st.push(e);
        }
    }
    if (topo.size() != m) {
        cout << -1 << '\n';
        return 0;
    }

    vector<int> dp(m);
    int ans = 0;
    for (auto &&e: topo) {
        for (auto &&f: g[e]) {
            chmax(dp[f], dp[e]+1);
        }
    }

    rep(i,m) chmax(ans,dp[i]);

    cout << ans+1 << '\n';
    return 0;
}

Measured memory_bytes: 64752
#include<cstdio>

using namespace std;

inline int read()
{
	int x=0;int f=1;
	int c=getchar();
	while(c<'0'||c>'9')
	{
		if(c=='0')f=-1;
		c=getchar();
	}
	while(c>='0'&&c<='9')
	{
		x=(x<<1)+(x<<3)+(c^48);
		c=getchar();
	}
	return x*f;
} 

int n;
double ans;

int main()
{
	n=read();
	if(n&1)
	{
		double temp=(double)n;
		n=n/2+1;
		ans=n/temp;
		printf("%lf",ans);
		return 0;
	}
	ans=(double)1/2;
	printf("%lf",ans);
	return 0;
}

Measured memory_bytes: 128
#include <iostream>
#include <vector>
#include <cmath>
#include <algorithm>
#include <utility>
#include <string>
#include <stack>
#include <regex>
 
#define REP(i, n) for (int i = 0; i < n; i++)
#define ALL(v) (v).begin(), (v).end()
 
using namespace std;
 
typedef long long ll;

int main(int argc, char const *argv[])
{
  ll a,p;
  cin >> a >> p;
  a = a*3+p;
  cout << a/2 << endl;
  return 0;
}


Measured memory_bytes: 256
import java.io.*;
public class Main{
    public static void main(String[] args) throws IOException{
        BufferedReader bf = 
            new BufferedReader(new InputStreamReader(System.in));
        int N = Integer.parseInt(bf.readLine());
        String S = bf.readLine();
        int K = Integer.parseInt(bf.readLine());
        String s = S.substring(K-1, K);
        for(int i = 0; i < N; i++){
            String ss = S.substring(i, i+1);
            if(!ss.equals(s)){
                S = S.replace(ss, "*");
            }
        }
        System.out.println(S);
    }
}

Measured memory_bytes: 21332
def solve(string):
    n, *a = map(int, string.split())
    a = [_a % 2 == 1 or _a % 6 == 0 or _a % 10 == 0 for _a in a]
    return "APPROVED" if all(a) else "DENIED"


if __name__ == '__main__':
    import sys
    print(solve(sys.stdin.read().strip()))


Measured memory_bytes: 2940
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <stdbool.h>
#include <math.h>

int main()
{
    int n, a[100];
    scanf("%d", &n);
    int i;
    int max = 0, min = 1000000001;
    for (i=0; i<n; i++)
    {
        scanf("%d", &a[i]);
        if (a[i] > max) max = a[i];
        if (a[i] < min) min = a[i];
    }
    printf("%d\n", max - min);
    return 0;
}


Measured memory_bytes: 128
#include <bits/stdc++.h>
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, n) for (int i = 0, i##_len = (n); i < i##_len; ++i)
#define REPR(i, n) for (int i = n; i >= 0; i--)
#define INF 1145141919
int dy[] = {0, 0, 1, -1};
int dx[] = {1, -1, 0, 0};
int ny, nx;
typedef long long int ll;
using namespace std;

ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }

ll lcm(ll m, ll n)
{
    if ((0 == m) || (0 == n))
        return 0;
    return ((m / gcd(m, n)) * n);
}

ll llpow(ll x, ll y)
{
    ll ans = 1;
    REP(i, y)
    ans *= x;
    return ans;
}

int ctoi(char c)
{
    if (c >= '0' && c <= '9')
    {
        return c - '0';
    }
    return 0;
}

template <class T>
inline bool chmin(T &a, T b)
{
    if (a > b)
    {
        a = b;
        return true;
    }
    return false;
}

template <class T>
inline bool chmax(T &a, T b)
{
    if (a < b)
    {
        a = b;
        return true;
    }
    return false;
}

ll a[100010][3];
ll dp[100010][3];

////////////////////////////////////////////////////////////////////
int main()
{

    int N; cin >> N;
    REP(i,N){
        REP(j,3) cin >> a[i][j];
    }

    REP(i,N){
        REP(j,3){
            REP(k,3){
                if(j==k) continue;
                chmax(dp[i+1][k], dp[i][j]+a[i][k]);
            }
        }
    }

    ll ans=0;

    REP(i,3) chmax(ans,dp[N][i]);
    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 4992
#include <bits/stdc++.h>
#define FOR(i, a, b) for(int i=(a); i<(b); i++)
#define REP(i, n) FOR(i, 0, n)
#define all(x) (x).begin(), (x).end()
#define bit(x) (1L << (x))
using ll = long long;
using namespace std;

template<typename T>
vector<T> make_v(size_t a,T b){return vector<T>(a,b);}
 
template<typename... Ts>
auto make_v(size_t a,Ts... ts){
    return vector<decltype(make_v(ts...))>(a,make_v(ts...));
}

int main() {
    int h, w, k; cin >> h >> w >> k;
    auto g = make_v(h, w, '0');
    REP(i, h)REP(j, w) cin >> g[i][j];

    auto ans = make_v(h, w, 0);

    bool f = false;
    int bd = -1, d = -1;
    int cnt = 1;

    REP(j, w) {
        REP(i, h) {
            if (g[i][j] == '#') {
                d = j;
                f = true;
            }
        }

        if (f) {
            bool first = true;
            REP(ni, h) {
                FOR(nj, bd+1, d+1) {
                    if (g[ni][nj] == '#') {
                        if (first) {
                            first = false;
                        } else {
                            cnt++;
                        }
                    }
                }

                FOR(nj, bd+1, d+1) {
                    ans[ni][nj] = cnt;
                }
            }
            
            cnt++;

            bd = d;
            f = false;
        }

        else if (cnt == k + 1) {
            REP(i, h) ans[i][j] = ans[i][j-1];
        }
    }

    REP(i, h) {
        REP(j, w) cout << ans[i][j] << " ";
        cout << endl;
    }

    return 0;
}


Measured memory_bytes: 1280
#include <bits/stdc++.h>
#define rep(i, f, n) for (ll i = (f); i < (ll)(n); i++)
#define repe(i, f, n) for (ll i = (f); i <= (ll)(n); i++)
using namespace std;
using ll = long long;
using pint = pair<int, int>;

int main() {
  string O, E;
  cin >> O >> E;
  bool eq = O.size() == E.size();
  int mi = min(O.size(), E.size());

  rep(i, 0, mi) {
    cout << O[i];
    cout << E[i];
  }

  if (!eq) cout << O[O.size() - 1];
  cout << endl;

  return 0;
}


Measured memory_bytes: 3608
using System;

namespace aoj4a
{
    class Program
    {
        static void Main(string[] args)
        {
            int n = int.Parse(Console.ReadLine());              //1???????????´??°?????????????????????
            string[] str = (Console.ReadLine()).Split(' ');     //2???????????´??°???????????????

            int tmp = 0 ;
            long sum = 0 ;
            int max = int.Parse(str[0]);
            int min = int.Parse(str[0]);

            for (int i = 0; i < n ; i++)
            {
                tmp = int.Parse(str[i]);
                if( tmp > max )
                {
                    max = tmp ;
                }
                if( tmp < min )
                {
                    min = tmp ;
                }

                sum += tmp ;
            }

            Console.WriteLine( min + " " + max + " " + sum );
        }
    }
}

Measured memory_bytes: 9816
#include<bits/stdc++.h>
using namespace std;
#define ll long long
int main(){
    int a,b,c,x,d=0; cin>>a>>b>>c>>x;
    for(int i=0;i<=a;i++){
        for(int j=0;j<=b;j++){
            for(int k=0;k<=c;k++){
                if(i*500+j*100+k*50==x){d++;}
            }
        }
    }
    cout<<d;
}


Measured memory_bytes: 3640
#include <iostream>
#include <string>

using namespace std;

int main(int argc, char* argv[]) {
  int N, A, B;
  cin >> N >> A >> B;

  int ret = 0;
  for (int i = 1; i <= N; ++i) {
    string s = to_string(i);
    int tmp = 0;
    for (int j = 0; j < s.size(); ++j) {
      tmp += s[j] - '0';
    }
    if (tmp >= A && tmp <= B)
      ret += i;
  }

  cout << ret << endl;

  return 0;
}

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

int main()
{
	int64_t n, wlim;
	cin >> n >> wlim;
	vector<int64_t> ws(n), vs(n);
	for (int i = 0; i < n; i++)
	{
		cin >> ws[i] >> vs[i];
	}
	vector<vector<int64_t>> dp(n, vector<int64_t>(100001, 1LL << 60));
	dp[0][0] = 0;
	dp[0][vs[0]] = ws[0];
	for (int i = 1; i < n; i++)
	{
		for (int j = 0; j <= 100000; j++)
		{
			dp[i][j] = min(dp[i][j], dp[i - 1][j]);
			if (j + vs[i] <= 100000)
			{
				dp[i][j + vs[i]] = min(dp[i][j + vs[i]], dp[i - 1][j] + ws[i]);
			}
		}
	}
	int64_t ans = -1;
	for (int64_t j = 100000; 0 <= j; j--)
	{
		if (dp[n - 1][j] <= wlim)
		{
			ans = max(ans, j);
		}
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 79488
#define  _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
#include <algorithm>
#include <utility>
#include <functional>
#include <cstring>
#include <queue>
#include <stack>
#include <math.h>
#include <iterator>
#include <vector>
#include <string>
#include <set>
#include <math.h>
#include <iostream>
#include <random>
#include<map>
#include <iomanip>
#include <time.h>
#include <stdlib.h>
#include <list>
#include <typeinfo>
#include <list>
#include <set>
#include <cassert>
#include<fstream>
#include <unordered_map>
#include <cstdlib>
#include <complex>
using namespace std;
#define Ma_PI 3.141592653589793
#define eps 0.00000001
#define LONG_INF 3000000000000000000
#define GOLD 1.61803398874989484820458
#define MAX_MOD 1000000007
#define MOD 998244353
#define REP(i,n) for(long long i = 0;i < n;++i)    
#define seg_size 524288
double dot(complex<double> a, complex<double> b) {
	return a.real() * b.real() + a.imag() * b.imag();
}
double gyaku_dot(complex<double> a, complex<double> b) {
	return a.real() * b.imag() - a.imag() * b.real();
}
double leng(complex<double> a) {
	return sqrt(a.real() * a.real() + a.imag() * a.imag());
}
double angles(complex<double> a, complex<double> b) {
	double cosine = dot(a, b) / (leng(a) * leng(b));
	double sine = gyaku_dot(a, b) / (leng(a) * leng(b));
	double kaku = acos(cosine);
	if (sine <= 0) {
		kaku = 2 * Ma_PI - kaku;
	}
	return kaku;
}
vector<int> convex_hull(vector<complex<double>> a) {
	vector<int> ans;
	double now_minnest = a[0].real();
	int now_itr = 0;
	REP(i, a.size()) {
		if (now_minnest > a[i].real()) {
			now_minnest = a[i].real();
			now_itr = i;
		}
	}
	ans.push_back(now_itr);
	complex<double> ba(0, 1);
	while (true) {
		int now_go = 0;
		double now_min = 0;
		int starter = ans[ans.size() - 1];
		for (int i = 0; i < a.size(); ++i) {
			if (i != starter) {
				double goa = angles(ba, a[i] - a[starter]);
				if (goa > now_min) {
					now_min = goa;
					now_go = i;
				}
			}
		}
		if (now_go == ans[0]) break;
		ans.push_back(now_go);
		ba = complex<double>(a[now_go] - a[starter]);
	}
	return ans;
}
long long gcd(long long a, long long b) {
	if (b == 0) return a;
	return gcd(b, a % b);
}
int main(){
	int n, x;
	cin >> n >> x;
	int ans = 1;
	REP(i, n) {
		int tmp;
		cin >> tmp;
		x -= tmp;
		if (x >= 0)ans++;
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define f first
#define s second
#define mp make_pair
#define pb push_back
#define lp(i,a,n) for(int i=(a);i<=(int)(n);++i)
#define lpd(i,a,n) for(int i=(a);i>=(int)(n);--i)
#define mem(a,b) memset(a,b,sizeof a)
#define all(v) v.begin(),v.end()
#define println(a) cout <<(a) <<endl
#define sz(x) ((int)(x).size())
#define readi(x) scanf("%d",&x)
#define read2i(x,y) scanf("%d%d",&x,&y)
#define read3i(x,y,z) scanf("%d%d%d",&x,&y,&z)
#define readll(x) scanf("%I64d",&x)
#define mod 1000000007
#define eps 1e-6
#define infi 1000000000
#define infll 1000000000000000000ll
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vll;
typedef set<int> si;
typedef map<int,int> mii;

const int N = 100002;
int n,a[N],duplicate,f[N];
ll fact[N],revFac[N];

ll comb(int n, int k){
    if(n < k) return 0;
    if(n == k or !k) return 1;
    return fact[n] * revFac[n-k] %mod * revFac[k] %mod;
}

ll power(ll b, ll p) {
    if(p == 0)	return 1;
    ll sq = power(b, p/2);
    sq = sq*sq%mod;
    if(p&1) sq = sq*b%mod;
    return sq;
}

void computeFact(){
    fact [0] = fact[1] = 1;
    revFac[0] = revFac[1] = 1;
    lp(i,1,N-1){
        fact[i] = fact[i-1] * i % mod;
        revFac[i] = power(fact[i], mod-2);
    }
}

int main(){
    computeFact();

    readi(n);
    lp(i,1,n+1){
        readi(a[i]);
        ++f[a[i]];
        if(f[a[i]] == 2) duplicate = a[i];
    }

    int x = 1;
    while(a[x] != duplicate) ++x;
    --x;

    int y = n+1;
    while(a[y] != duplicate) --y;
    y = n + 1 - y;

    lp(k,1,n+1) println((comb(n+1, k) - comb(x+y, k-1) + mod) % mod);
}

//freopen("input.txt","r",stdin);
//freopen("output.txt","w",stdout);
//ios::sync_with_stdio(0);cin.tie(0);


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

int main() {
  char c;
  cin >> c;
  if(c == 'a' || c == 'i' || c == 'u' || c == 'e' || c == 'o') {
    cout << "vowel" << endl;
  }
  else {
    cout << "consonant" << endl;
  }
}

Measured memory_bytes: 3604
#include <iostream>
#include <sstream>
#include <vector>
#include <string>
#include <cmath>
#include <algorithm>
#include <map>
#include <stdio.h>

using namespace std;

//typedefリスト
typedef long long llint;
typedef vector<long long int> vint;
typedef vector< vector<int> > vvint;
typedef vector<string> vstr;


int main(void) {
	int N, M, ss, num, ans;
	ans = 0;
	num = 0;
	cin >> N >> M;
	vint K(M), P(M);
	vvint s(M);
	for (int i = 0; i < M; i++) {
		cin >> K[i];
		for (int j = 0; j < K[i]; j++) {
			cin >> ss;
			s[i].push_back(ss);

		}
	}
	for (int i = 0; i < M; i++)cin >> P[i];

	for (int i = 0; i < pow(2, N); i++) {
		int num = 0;
		if (i == 0) {
			for (int j = 0; j < M; j++) {
				if (P[j] == 0)num++;
			}
		}
		else {
			for (int k = 0; k < M; k++) {
				int cou = 0;
			    for (int j = 0; j < N; j++) {
				    if (i&(1 << j)) {
					
						for (int l = 0; l < K[k]; l++) {
							if (s[k][l] == j+1)cou++;
						}
						
					}
				}
				if (P[k] == cou % 2)num++;
			}
		}
		if (num == M)ans++;
	}
	cout << ans << endl;
}


Measured memory_bytes: 512
#include<iostream>
using namespace std;
int main(){
    int r,c,sum,total;
    cin>>r>>c;
    total=0;
    int lst[r][c];
    for (int a=0;a<r;a++){
        sum=0;
        for (int b=0;b<c;b++){
            int num;
            cin>>num;
            lst[a][b]=num;
            cout<<num<<" ";
            sum=sum+num;
        }
        cout<<sum<<endl;
    }for(int d=0;d<c;d++){
        sum=0;
        for (int e=0;e<r;e++){
            sum=sum+lst[e][d];
            total=total+lst[e][d];
        }cout<<sum<<" ";
    }cout<<total<<endl;
}


Measured memory_bytes: 3084
#include<bits/stdc++.h>
#ifdef LOCAL
    #define _GLIBCXX_DEBUG
    #define dbg(x) cerr << #x << " = " << x << char(10);
#else
    #define dbg(x) ;
    #define cerr if(0) cerr
    #pragma GCC optimize("Ofast,no-stack-protector,unroll-loops,fast-math")
    #pragma GCC target("sse,sse2,sse3,ssse3,sse4.1,sse4.2,avx,avx2,popcnt,tune=native")
#endif
#define forn(i, n) for (int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(), (x).end()
#define pb push_back
#define mkt make_tuple
using namespace std;
using ld = long double;
using ll = long long;
using vi = vector<int>;
using vll = vector<ll>;
const ld eps = 1e-8l;
const int INF = 1e9 + 10;
const ll INFL = 9 * 1e18;
const ll MOD = 1e9 + 7;
const ld Pi = acosl(-1.0l);

int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.precision(9);
    cout << fixed;
    #ifdef LOCAL
        assert(freopen("in", "r", stdin));
        assert(freopen("out", "w", stdout));
        assert(freopen("err", "w", stderr));
    #endif

    int n;
    cin >> n;
    vi v(2 * n);
    for(int& i: v)
        cin >> i;
    sort(all(v));
    int ans = 0;
    forn(i, 2 * n)
        if(!(i & 1))
        {
            dbg(i);
            ans += v[i];
        }
    cout << ans;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
 
using namespace std;
 
typedef long long int       lint;
typedef vector<int>         vi;
typedef vector<lint>        vl;
typedef pair<int, int>      pii;
typedef vector<pii>         vii;
typedef set<int>            si;
typedef map<string, int>    msi;
 
#define pb(n)           push_back(n)
#define ALL(n)          (n.begin(), n.end())
#define db(a)           cout<<#a<<" = "<<a<<endl;
#define FIN             freopen("in.txt","r",stdin);
#define FOUT            freopen("out.txt","w",stdout);
#define M               10000000
#define MOD             10000007
#define INF             1e9+7
#define REP(i,a,b)      for(int i = int(a); i <= int(b); i++)
#define REPL(i,a,b)     for(lint i = lint(a); i <= lint(b); i++)
#define fastIO()        ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);

int main()
{
    lint dr, inr, con;
    cin>>con>>dr;

    if(con >= 10) cout<<dr<<endl;
    else cout<<dr + (100 * (10 - con))<<endl;

    return 0;
}


Measured memory_bytes: 256
def main():
    n,k = map(int, input().split())

    l = []

    for i in range(n):
        h = int(input())
        l.append(h)

    l.sort()

    m = 10**10
    for i in range(n-k+1):
        if l[i+k-1] - l[i] < m:
            m = l[i+k-1] - l[i] 
    print(m)

if __name__ == "__main__":
    main()

Measured memory_bytes: 7384
fun main(args: Array<String>) {
    val (N, M) = readLine()!!.split(" ").map { it.toInt() }

    var xs = (0 until M).map { i ->
        val l = readLine()!!.split(" ").map { it.toInt() }
        Triple(i, l[0], l[1])
    }.sortedBy { it.third }

    val memo = Array(N) { 0 }
    val ans = Array(M) { "" }
    for (city in xs) {
        val no = city.first
        val p = city.second
        val n = ++memo[p - 1]

        ans[city.first] = city.second.toString().padStart(6, '0') + n.toString().padStart(6, '0')
    }

    ans.forEach { println(it) }
}

Measured memory_bytes: 95044
N = int(input(""))
a = input("").split(" ")
a = [int(aa) for aa in a]
ap = 0
bp = 0
temp = 0
for c in range(len(a)):
    if c % 2 == 0:
        temp = a.pop(a.index(max(a)))
        ap += temp
    else:
        temp = a.pop(a.index(max(a)))
        bp += temp
print(str(abs(ap-bp)))

Measured memory_bytes: 9144
using System.Linq;
using System;
using static System.Math;
using static System.Console;

class E { static void Main() => new J(); }
class J
{
	const int Mod = 1000000007;
	int[] G() => ReadLine().Split(new char[] { ' ', '\t' }, StringSplitOptions.RemoveEmptyEntries).Select(int.Parse).ToArray();
	public J()
	{
		WriteLine(Calc());
	}
	long[,] next;
	void Add(int x, int y, long z) { next[x, y] = (next[x, y] + z) % Mod; }
	void Add(ref long x, long z) { x = (x + z) % Mod; }
	bool IsOK(int[] q, int x, int y) => q[0] > x && x >= q[1] && q[2] > y && y >= q[3];
	long Calc()
	{
		var I = G();
		int N = I[0], M = I[1];
		var qs = new int[N][];
		for (var i = 0; i < N; i++) qs[i] = new int[] { N + 10, -10, N + 10, -10 };
		for (var i = 0; i < M; i++)
		{
			I = G();
			if (I[0] != I[1])
			{
				int l = I[0] - 1, r = I[1] - 1;
				switch (I[2])
				{
					case 1: qs[r][0] = Min(qs[r][0], l); break;
					case 2: qs[r][1] = Max(qs[r][1], l); qs[r][2] = Min(qs[r][2], l); break;
					case 3: qs[r][3] = Max(qs[r][3], l); break;
					default: break;
				}
			}
			else if (I[2] != 1) return 0;
		}
		var dp = new long[N, N];
		dp[N - 1, N - 1] = 3;
		if (qs[0][1] >= 0 || qs[0][2] <= N || qs[0][3] >= 0) return 0;
		for (var n = 0; n < N - 1; n++)
		{
			next = new long[N, N];
			for (var x = 0; x < n; x++)
				for (var y = 0; y < x; y++)
				{
					Add(x, y, dp[x, y]);
					Add(n, y, dp[x, y]);
					Add(n, x, dp[x, y]);
				}
			Add(N - 1, N - 1, dp[N - 1, N - 1]);
			Add(n, N - 1, 2 * dp[N - 1, N - 1]);
			for (var x = 0; x < n; x++)
			{
				Add(x, N - 1, dp[x, N - 1]);
				Add(n, N - 1, dp[x, N - 1]);
				Add(n, x, dp[x, N - 1]);
			}
			for (var x = 0; x <= n; x++) for (var y = 0; y < x; y++) if (!IsOK(qs[n + 1], x, y)) next[x, y] = 0;
			for (var x = 0; x <= n; x++) if (!IsOK(qs[n + 1], x, -1)) next[x, N - 1] = 0;
			if (!IsOK(qs[n + 1], -1, -2)) next[N - 1, N - 1] = 0;
			dp = next;
		}
		var ans = 0L;
		for (var x = 0; x < N; x++) for (var y = 0; y < N; y++) Add(ref ans, dp[x, y]);
		return ans;
	}
}

Measured memory_bytes: 31088
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <cmath>
#include <vector>
using namespace std;
string s1,s2,s;
int main()
{
	s1="ABC"; s2="ARC";
	cin>>s;
	if (s==s1) cout<<s2;else cout<<s1;
return 0;
}

Measured memory_bytes: 3592
#include<bits/stdc++.h> 
using namespace std;
int main(){
	string s;
	cin>>s;
	int n = (int)s.length();
	int cnt = 0;
	for(int i=0;i<n/2;++i){
		if(s[i]!=s[n-i-1]){
			++cnt;
			break;
		}
	}
	for(int i=0;i<n/2;++i){
		if(s[i]!=s[n/2-i-1]){
			++cnt;
			break;
		}
	}
	for(int i=(n+3)/2-1;i<n;++i){
		if(s[i]!=s[n-i-1]){
			++cnt;
			break;
		}
	}
	cout<<(cnt ? "No" : "Yes")<<'\n';
	return 0;
}

Measured memory_bytes: 256
def f():
    return map(int, input().split())


def main():
    N, Q = f()
    S = input()
    t = []
    flag = False
    n = 0
    for i, s in enumerate(S):
        if s == 'A':
            flag = True
        elif flag and s == 'C':
            n += 1
            flag = False
        else:
            flag = False
        t.append(n)

    for i in range(Q):
        l, r = f()
        print(t[r-1]-t[l-1])


if __name__ == '__main__':
    main()


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

x=list(map(int, input().split()))
y=list(map(int, input().split()))

p1=p2=p3=p4=0
for i in range(n):
    if x[i]>y[i]:
        k=x[i]-y[i]
        p1+=k
        p2+=k**2
        p3+=k**3
        p4=max(p4,k)
        
    else:
        k=y[i]-x[i]
        p1+=k
        p2+=k**2
        p3+=k**3
        p4=max(p4,k)

p2=p2**(1/2)
p3=p3**(1/3)

print(p1,p2,p3,p4, sep="\n")


Measured memory_bytes: 5644
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define pb push_back
#define fi first
#define se second
typedef pair<ll, ll> P;
using VP = vector<P>;
using VVP = vector<VP>;
using VI = vector<ll>;
using VVI = vector<VI>;
using VVVI = vector<VVI>;
const int inf = 1e9 + 7;
const ll INF = 1LL << 61;
const ll mod = 1e9 + 7;

template <class T> inline bool chmax(T &a, T b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}

template <class T> inline bool chmin(T &a, T b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    ll i, j;
    set<P> s;
    set<P> v;
    ll h, w, n;
    cin >> h >> w >> n;
    for (int k = 0; k < n; k++) {
        ll a, b;
        cin >> a >> b;
        a--;
        b--;
        s.insert(P(a, b));
        for (i = -1; i <= 1; i++) {
            for (j = -1; j <= 1; j++) {
                if (a + i >= 1 && a + i < h - 1 && b + j >= 1 && b + j < w - 1) {
                    v.insert(P(a + i, b + j));
                }
            }
        }
    }
    VI ans(10, 0);
    ans[0] = (h - 2) * (w - 2) ;
    for (auto it = v.begin(); it != v.end(); ++it) {
        int cnt = 0;
        for (i = -1; i <= 1; i++) {
            for (int j = -1; j <= 1; j++) {
                cnt += s.count(P(it->first + i, it->second + j));
            }
        }
        ans[0]--;
        ans[cnt]++;
    }
    for (i = 0; i <= 9; i++) cout << ans[i] << endl;
}

Measured memory_bytes: 66092
//include
//------------------------------------------
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <queue>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>

using namespace std;

#define SORT(c) sort((c).begin(),(c).end())
#define ANS(ans) cout<<(ans)<<endl;
typedef vector<int> VI;


//repetition
//------------------------------------------
#define FOR(i,a,b) for(int i=(a);i<=(b);++i)
#define REP(i,n)  for (int i = 0; i < (n); ++i)



int main() {
	int a, b, c, d, e, f;
	cin >> a >> b >> c >> d >> e >> f;

	VI water(0);
	VI sugar(0);

	int i = 0, j = 0;

	while (a * 100 * i <= 3000) {
		j = 0;
		while (true) {
			if (a * 100 * i + b * 100 * j > 3000) {
				break;
			}
			water.push_back(a * 100 * i + b * 100 * j);
			j++;
		}
		i++;
	}
	i = 0;
	j = 0;
	while (c * i <= 3000) {
		j = 0;
		while (true) {
			if (c * i + d * j > 3000) {
				break;
			}
			sugar.push_back(c * i + d * j);
			j++;
		}
		i++;
	}

	SORT(water);
	SORT(sugar);

	water.erase(unique(water.begin(), water.end()), water.end());
	sugar.erase(unique(sugar.begin(), sugar.end()), sugar.end());

	double max_noudo = 0.0;
	int max_water=0;
	int max_sugar=0;
	double temp;

	REP(i, water.size()) {
		REP(j, sugar.size()) {
			if (water[i] + sugar[j] <= f) {
				temp = sugar[j] * 1.0 / (water[i] + sugar[j]);
				if (temp <= e*1.0 / (100 + e) && temp > max_noudo) {
					max_noudo = temp;
					max_water = water[i];
					max_sugar = sugar[j];
				}
			}
		}
	}
	if (max_water == 0) {
		max_water = a*100;
	}

	cout << max_water + max_sugar << " " << max_sugar << endl;

	return 0;
}



Measured memory_bytes: 18284