akhauriyash/Code-Regression huggingface dataset:
using System;
using System.Linq;
    class Program
    {
        static void Main()
        {
            char[] ch = Console.ReadLine().ToCharArray();
            int a = int.Parse(Console.ReadLine());
            for (int i = 0; i < a; i++)
            {
                string str = Console.ReadLine();
                string com = str.Split(' ')[0];
                if (com == "print")
                {
                    int b = int.Parse(str.Split(' ')[1]);
                    int c = int.Parse(str.Split(' ')[2]);
                    for (int j = b; j <= c; j++)
                    {
                        Console.Write(ch[j]);
                    }
                    Console.WriteLine();
                }
                if (com == "replace")
                {
                    int b = int.Parse(str.Split(' ')[1]);
                    int c = int.Parse(str.Split(' ')[2]);
                    string str2 = str.Split(' ')[3];
                    for (int j = b; j <= c; j++)
                    {
                        ch[j] = str2[j - b];
                    }                }
                if (com == "reverse")
                {
                    int b = int.Parse(str.Split(' ')[1]);
                    int c = int.Parse(str.Split(' ')[2]);
                    for (int j = b; j <b+((c-b)/2)+1; j++)
                    {
                        char tmp =ch[j];
                        ch[j] = ch[b + c - j];
                        ch[b + c - j] = tmp;
                    }
                }
            }
        }
    }

Measured memory_bytes: 5484
#include<iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <math.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < n; i++)

int main()
{
	int h, w;
	cin >> h >> w;
	vector <string> str(h);

	int dh[] = { 1, 1, 1, 0, 0, -1, -1, -1 };
	int dw[] = { 1, 0, -1, 1, -1, 1, 0, -1 };
	
	rep(i, h) {
		cin >> str.at(i);
	}
	rep(i, h) {
		rep(k, w) {
			int cnt = 0;
			if (str.at(i).at(k) == '#') continue;
			rep(t, 8) {
				int x = i + dh[t];
				int y = k + dw[t];
				if (x >= 0 && x < h && y >= 0 && y < w) {
					if (str.at(x).at(y) == '#') cnt++;
				}
				str.at(i).at(k) = '0' + cnt;
			}
		}
	}
	rep(i, h) {
		cout << str.at(i) << endl;
	}

	
	return 0;
}

Measured memory_bytes: 256
#pragma GCC optimize("Ofast")
#include<bits/stdc++.h>
#define fi first
#define se second
#define pb push_back
#define SZ(x) ((int)x.size())
#define L(i,u) for (register int i=head[u]; i; i=nxt[i])
#define rep(i,a,b) for (register int i=(a); i<=(b); i++)
#define per(i,a,b) for (register int i=(a); i>=(b); i--)
using namespace std;
typedef long long ll;
typedef unsigned int ui;
typedef pair<int,int> Pii;
typedef vector<int> Vi;
template<class T> inline void read(T &x){
	x=0; char c=getchar(); int f=1;
	while (!isdigit(c)) {if (c=='-') f=-1; c=getchar();}
	while (isdigit(c)) {x=x*10+c-'0'; c=getchar();} x*=f;
}
const int N = 1505, inf = 0x3f3f3f3f;
int n;short l[N][N],r[N][N];
int dfn[N][N],pos[N][N];char s[N][N];
ll f[N][N],res;
#define umax(a,b) (a=a>b?a:b)
#define umin(a,b) (a=a<b?a:b)
int main() {
	memset(s,'#',sizeof(s));read(n);rep(i,1,n)scanf("%s",s[i]+1);
	memset(l,inf,sizeof(l));
	per(i,n,1){
		rep(j,1,n){
			if(s[i][j]!='#')l[i][j]=r[i][j]=j;else l[i][j]=inf,r[i][j]=0;
			l[i+1][j]=inf,r[i+1][j]=0;
		}
		per(j,i,1){
		short *R=r[j+1],*L=l[j+1];
		if(j<i)memcpy(r[j],r[j+1],sizeof(r[j+1])),memcpy(l[j],l[j+1],sizeof(l[j+1]));
		per(k,n,1)if(s[j][k]=='#')l[j][k]=inf,r[j][k]=0;
		else{
		//	if(j<i){r[j][k]=max(r[j][k+1],R[k]);l[j][k]=min(l[j][k+1],L[k]);}
		//	else
			{umax(r[j][k],r[j][k+1]);umin(l[j][k],l[j][k+1]);}
			if(dfn[j][k]==i+1&&R[k]<pos[j][k])f[j][k]-=f[i+1][pos[j][k]];
			if(R[k]>=l[j][k+1])dfn[j][k]=i,pos[j][k]=l[j][k+1];
		}
		}
		per(j,n,1)if(s[i][j]!='#'){
		//	printf("%d %d:%lld %lld\n",i,j,f[i][j],f[i+1][j]+f[i][j+1]+f[i][j]);
			f[i][j]+=f[i+1][j]+f[i][j+1];ll c=s[i][j]-'0';
			res+=c*f[i][j];f[i][j]+=c;
		}
	}
	cout<<res;return 0;
}


Measured memory_bytes: 27648
# http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=ALDS1_1_A
def insertion_sort a
  a.each_with_index do |key, i|
    j = i - 1
    while j >= 0 && a[j] > key
      a[j + 1] = a[j]
      j -= 1
    end
    a[j + 1] = key
    puts a.join(' ')
  end
end

n = gets.to_i
a = gets.split.map(&:to_i)

insertion_sort a

Measured memory_bytes: 6104
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<ll, ll>;
const string ln = "\n";
constexpr int INF = 1001001001;
constexpr int MOD = 1000000007;

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

  string s;
  cin >> s;

  set<char> st;
  for (int i = 0; i < 3; i++) {
    st.insert(s[i]);
  }

  string ans = "No";
  if (st.size() == 2) {
    ans = "Yes";
  }

  cout << ans << endl;

  return 0;
}

Measured memory_bytes: 256
import sys

N=int(input())
A = list(map(int,input().split()))
 
import math
from functools import reduce

def gcd(*numbers):
    return reduce(math.gcd, numbers)

def gcd_list(numbers):
    return reduce(math.gcd, numbers)

if gcd_list(A) > 1:
    print("not coprime")
    sys.exit()

D = [i for i in range(max(A)+1)] #iを割り切る最小の素数を格納
p = 2
 
while(p*p<=max(A)):
    if D[p]==p:
        for i in range(2*p,max(A)+1,p):
            if D[i]==i:
                D[i]=p
 
    p+=1
    
prime = set()
for a in A:
    tmp=D[a]
    L=set()
    while(a>1):
        a=a//tmp
        L.add(tmp)
        tmp=D[a]

    for l in L:
        if l in prime:
            print("setwise coprime")
            sys.exit()
        else:
            prime.add(l)

print("pairwise coprime")

Measured memory_bytes: 217992
import heapq

H = []

#heappop???pop????????????heap??????????°????????´??????????
#????????§?????????????????´???????¬??????????????????????????????????

while True:
    line = input().split()

    if line[0] == 'insert':
        heapq.heappush(H,-int(line[1]))
    elif line[0] == 'extract':
        print(-heapq.heappop(H))
    else:
        break

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

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    int n, w, c = 0;
    cin >> n;
    vector<int> v(n);
    rep(i, n) {
        cin >> w;
        v.at(i) = w;
    }
    w = 1;
    rep(i, n) {
        c++;
        w = v.at(w-1);
        if(w == 2) break;
    }
    if(w == 2) cout << c << endl;
    else cout << -1 << endl;
}

Measured memory_bytes: 768
#include<bits/stdc++.h>
#include<string>
#include<cmath>

using namespace std;

#define ll long long int
#define loop(i, n) for (int i = 0; i < n; i++)
#define loops(i, s, n) for (int i = s; i < n; i++)
#define pb push_back
#define mp make_pair
#define all(v) v.begin(),v.end()
#define MOD 1000000007

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

    string s;
    cin>>s;
    int n = (int)s.size();
    
    reverse(all(s));
    ll p = 1;
    ll curr = 0;
    vector<ll> cnt(2020,0);
    cnt[0]++;
    for(int i = 0; i<n; i++){
        curr = curr+(s[i]-'0')*p;
        p = p*10 %2019;
        curr%=2019;
        cnt[curr]++;
    }
    ll ans =0;
    for(int i= 0; i<cnt.size(); i++){
        ans+= ((cnt[i]*(cnt[i]-1))/2);
    }
    cout<<ans<<"\n";
}

Measured memory_bytes: 3704
#include <iostream>
using namespace std;
int main(void){
    // Your code here!
    string s;
    std::cin >> s;
    for (int i = 1; i < s.length(); i++) {
        if((s.length()-i)%2!=1){
            int mid=(s.length()-i)/2;
            string a=s.substr(0,mid);
            string b=s.substr(mid,mid);
            if(a==b){
                std::cout << s.length()-i << std::endl;
                return 0;
            }
        }
    }
    std::cout << "error" << std::endl;
}


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

int main(){
	int N; cin >> N;
	vector<int> A, cntVec;

	for(int i = 0; i < N; ++i){
		int Ai; cin >> Ai;
		A.push_back(Ai);
	}

	for(int i = 0; i < N; ++i){
		int cnt = 0;
		while(1){
			if(A[i] % 2 == 1) break;
			cnt++;
			A[i] /= 2;
		}
		cntVec.push_back(cnt);
	}

	cout << *min_element(cntVec.begin(), cntVec.end()) << endl;	

	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for (int i=0;i<n;i++)
#define all(cont) cont.begin(), cont.end()
#define unique(a)  sort(all(a)) , (a).erase(unique((a).begin(), (a).end()),(a).end())
#define rall(cont) cont.rbegin(), cont.rend()
#define sz(x) (int)(x).size()
#define fastio          ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define PB push_back
#define endl "\n"
#define f first
#define s second
#define mset(m,v) memset(m,v,sizeof(m))
#define mod 1000000007
const int N = 2e5 + 5, INF = 1E9 + 7;
#define PI acos(-1.0)
long double EPS = 1e-9;
typedef long long ll;
#define int long long
typedef long double ld;
typedef vector<int> vi;
typedef pair<int, int> pii;
typedef vector<pair<int, int>> vpii;
#define pqll_max priority_queue<ll> // max heap. push(),pop(),top(),size(),empty()
#define pqll_min priority_queue<ll,vector<ll>,greater<ll> >
#define lb(v,val)   lower_bound(v.begin(),v.end(),val) //first equal to or lower than [------------
#define ub(v,val)   upper_bound(v.begin(),v.end(),val) //first greater than ------------)
#define bs(v,x) binary_search(v.begin(),v.end(),x)
inline ll add(ll x, ll y) { x += y; if (x >= mod) x -= mod; return x; }
inline ll sub(int x, int y) { x -= y; if (x < 0) x += mod; return x; }
inline ll mul(ll x, ll y) { return (x%mod * 1ll * y%mod) % mod; }
inline ll pwr(ll a, ll b) { ll x = 1 % mod; while (b) { if (b & 1) x = mul(x, a); a = mul(a, a); b >>= 1; }return x % mod; }
inline ll inv(ll a) { return pwr(a, mod - 2) % mod; }
ll gcd(ll a, ll b) { if (!a)return b % mod; return gcd(b%a, a) % mod; }
#define debug(x) cout << #x << " = " << x << endl;
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1) {
	cout << name << " : " << arg1 << endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args) {
	const char* comma = strchr(names + 1, ','); cout.write(names, comma - names) << " : " << arg1 << " | "; __f(comma + 1, args...);
}
#define in(container) for (auto &it : container) cin>>it;
#define out(container) for (auto it : container) cout << it << " "; cout << endl;
void solve() {
	int n, k;
	cin >> n >> k;
	vi v(n);
	in(v);
	sort(all(v));
	cout << accumulate(v.begin(), v.begin() + k, 0LL);
}
signed main()
{
	fastio;
	//cout<<fixed<<setprecision(15);
	//clock_t begin = clock();
	int tc;
	tc = 1;
	//cin >> tc;
	while (tc--) {
		solve();
	}
	//clock_t end = clock();double elapsed_secs = double(end - begin) / CLOCKS_PER_SEC;cerr << elapsed_secs;
}


//Error?
// clear lists for every test case
// print new line for each tc
// check for int or ll
// check if problem can be solved without any heavy DS like priority_queue or map



Measured memory_bytes: 3608
#include <algorithm>
#include <cassert>
// #include <chrono>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <iostream>
#include <map>
#include <memory>
#include <queue>
// #include <random>
#include <set>
#include <stack>
#include <string>
#include <utility>
#include <vector>

/*
unsigned seed1 = std::chrono::system_clock::now().time_since_epoch().count();
mt19937 g1.seed(seed1);
*/
using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef pair<pii, pii> ppiipii;
typedef pair<int, ppiipii> pippiipii;
typedef pair<int, pii> pipii;
typedef pair<pii, int> ppiii;
typedef pair<int, ppiii> pippiii;
typedef pair<int, ll> pill;
typedef pair<int, double> pid;
// note to self, the below two triggers someone
typedef pair<ll, ll> pll;
typedef pair<ll, int> plli;
typedef long double ld;

int n;
int l[100000];
int to[20][100000];

void solve() {
  int qq;
  scanf("%d", &qq);
  while(qq--) {
    int a, b;
    scanf("%d %d", &a, &b);
    if(a > b) {
      a ^= b;
      b ^= a;
      a ^= b;
    }
    a--;
    b--;
    int r = 0;
    for(int d = 19; d > 0; d--) {
      if(to[d][a] < b) {
        r += 1 << d;
        a = to[d][a];
      }
    }
    while(a < b) {
      r++;
      a = to[0][a];
    }
    printf("%d\n", r);
  }
}

void init() {
  scanf("%d", &n);
  for(int i = 0; i < n; i++) {
    scanf("%d", &l[i]);
  }
  int d;
  scanf("%d", &d);
  int j = 0;
  for(int i = 0; i < n; i++) {
    while(j < n && l[j] - l[i] <= d) {
      j++;
    }
    to[0][i] = j-1;
  }
  for(int d = 1; d < 20; d++) {
    for(int i = 0; i < n; i++) {
      to[d][i] = to[d-1][to[d-1][i]];
    }
  }
}

int main() {
  init();
  solve();
}


Measured memory_bytes: 9088
#include<bits/stdc++.h>
 
using namespace std;
int main(){
    int n,T,A;
    int a[1000+5];
    float b[1000+5];
    cin>>n>>T>>A;
    int flag = 0;
    for(int i = 1;i <= n;i++){
        cin>>a[i];
        b[i] = T-a[i]*0.006;
    }
    float minx = 0x3f3f3f3f;
    for(int i = 1;i <=n ;i++){
        if(minx > fabs(A-b[i])){
            minx = fabs(A-b[i]);
                flag = i;
        }
    }
    cout<<flag;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using pii=pair<int,int>;
using ll=long long;

#define fi first
#define se second
#define pb push_back
#define rep(i,n) for(int i=0; i<(int)(n); i++)

template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }

int main() {
	int a,b;
	cin >> a >> b;
	cout << max({a+b,a-b,a*b}) << endl;

  return 0;
}


Measured memory_bytes: 256
from math import factorial as fact
import math
import sys
import itertools
import numpy as np
from collections import Counter
import datetime
from collections import deque

#入力:N(int:整数)
def input1():
	return int(input())

#入力:N,M(int:整数)
def input2():
	return map(int,input().split())

#入力:[n1,n2,...nk](int:整数配列)
def input_array():
	return list(map(int,input().split()))

def keta(N):
	return len(str(N))


def input_daytime(input_time):
	time,distance=input_time.split()
	t=time.split(":")
	se=str(t[-1]).split(".")
	dt1 = datetime.timedelta(hours=int(t[0]),minutes=int(t[1]),seconds=int(se[0]),milliseconds=int(se[1]))
	return dt1

def combinations(n,r):
	return list(itertools.combinations(range(n),r))



def all_sets(num_list):
	subsets=[]
	for i in range(2,len(num_list) + 1):
		for c in combinations(num_list, i):
			subsets.append(c) 
	return subsets

#公約数の列挙
def ch(x1):
	cf=[]
	for i in range(2,math.sqrt(x1)+1):
		if x1 % i==0:
			cf.append(i)
	return cf

def CountOneRoots(x,y):
	#x:縦，y:横
	return fact(x+y)/fact(x)/fact(y)

# 素因数分解
def prime_factorize(n):
    a = []
    while n % 2 == 0:
        a.append(2)
        n //= 2
    f = 3
    while f * f <= n:
        if n % f == 0:
            a.append(f)
            n //= f
        else:
            f += 2
    if n != 1:
        a.append(n)
    return a
	
def count_str(m):
	tmp={}
	for i in range(10):
		if i in tmp:
			tmp[i]=1
		else:
			tmp[i]+=1
	return tmp
		


a,b,c,k=input2()


count=0
if k<a:
	count=k
elif k>=a and k<b:
	count=a
else:
	count=a-(k-a-b)
print(count)



















Measured memory_bytes: 27032
#include<iostream>
#include<algorithm>
#include<utility>
#include<vector>

using namespace std;

int w,h;
char g[60][11];
bool u[60][10];
const double eps=1e-9;

bool valid(int y,int x){
  return 0<=y&&y<h&&0<=x&&x<w;
}

pair<double,int> dfs(int y,int x){
  int color=g[y][x];
  vector<pair<int,int> > q{{y,x}};
  vector<pair<int,int> > c;
  int xsum=0;
  while(!q.empty()){
    auto cc=q.back();
    q.pop_back();
    if(valid(cc.first,cc.second)&&g[cc.first][cc.second]==color&&!u[cc.first][cc.second]){
      u[cc.first][cc.second]=true;
      c.push_back(cc);
      xsum+=cc.second;
      for(int i=0;i<4;i++){
	static int d[]={0,1,0,-1,0};
	q.emplace_back(cc.first+d[i],cc.second+d[i+1]);
      }
    }
  }
  pair<double,int> cent(xsum /4.+.5,4);
  int l=100,r=-1;
  for(auto e:c){
    int uy=e.first-1;
    if(valid(uy,e.second)&&g[uy][e.second]!=color&&g[uy][e.second]!='.'&&!u[uy][e.second]){
      auto ucent=dfs(uy,e.second);
      int wsum=cent.second+ucent.second;
      cent=make_pair((cent.first*cent.second+ucent.first*ucent.second)/wsum,wsum);
    }
    int ly=e.first+1;
    if(ly==h||(g[ly][e.second]!='.'&&g[ly][e.second]!=color)){
      l=min(l,e.second);
      r=max(r,e.second+1);
    }
  }
  if(cent.first<=l+eps||r<=cent.first+eps){
    throw 0;
  }
  return cent;
}

int main(){
  while(cin>>w>>h,w){
    for(int i=0;i<h;i++){
      cin>>g[i];
    }
    fill(u[0],u[60],false);
    bool f=false;
    try{
      for(int i=0;;i++){
	if(g[h-1][i]!='.'){
	  dfs(h-1,i);
	  break;
	}
      }
    }catch(...){
      f=true;
    }
    cout<<(f?"UNSTABLE":"STABLE")<<endl;
  }
}

Measured memory_bytes: 1276
n,t=map(int,input().split())
l=list(map(int,input().split()))
mi=l[0]
ri=0
t=0
ans=0
for i in l[1:]:
    mi=min(mi,i)
    ma=i 
    if ri<ma-mi:
        ri=ma-mi
        ans=1
    elif ri==ma-mi:
        if t:
            ans+=1
            t=0
    else:
        t=1
print(ans)

Measured memory_bytes: 62960
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <cmath>
#include <iomanip>
#include <stack>
#include <queue>
#include <numeric>
#include <map>
#include <unordered_map>
#include <set>
#include <fstream>
#include <chrono>
#include <random>
#include <bitset>
#define rep(i,n) for(int i=0;i<(n);i++)
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define sz(x) ((int)(x).size())
#define pb push_back
using ll = long long;
using namespace std;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
ll gcd(ll a, ll b) {return b?gcd(b,a%b):a;}
ll lcm(ll a, ll b) {return a/gcd(a,b)*b;}

int main(){
  int N; cin >> N;
  vector<ll> A(N); rep(i,N) cin >> A[i];
  vector<ll> ss(N+1,0);
  rep(i,N) ss[i+1] = ss[i] + A[i];
  vector<ll> xs(N+1,0);
  rep(i,N) xs[i+1] = xs[i] ^ A[i];

  ll ans = 0;
  int r=1;
  for(int l=0;l<N;l++){
    ll p = ss[r]-ss[l];
    ll x = xs[r]^xs[l];
    //cout << l << " " << r << " " << p << " " << x << endl;
    for(;r<=N;r++){
      if(r==N){
        ll w = r-l;
        ans += w;
        break;
      }
      p += A[r];
      x ^= A[r];
      if(p!=x){
        ll w = r-l;
        ans += w;
        break;
      }
    }
  }
  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 8028
#include<iostream>
#include<algorithm>
#include <vector>
using namespace std;
int main() {
	int A, B, C;
	cin >> A >> B >> C;
	int ans;
	ans = -A + B + C;
		if (ans <= 0) {
			cout << 0 << endl;
		}
		else {
			cout << ans << endl;
		}
}

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

#define mx 1000005
#define md 1000000007
using namespace std;

int n, h[105], ans;
bool c = true;

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

	while(c){
		c = false;
		for(int i = 0; i < n; i++){
			if(h[i]) c = true;
			if(h[i] > 0 && h[i+1] == 0) ans++;
			if(h[i]) h[i]--;
		}
	}
	printf("%d\n", ans);
}


Measured memory_bytes: 256
use strict;
use warnings;
use utf8;

my $n = int(<STDIN>);
my $s = <STDIN>;
my @ss = ($s =~ m/[RGB]/g);

my $r = () = $s =~ m/R/g;
my $g = () = $s =~ m/G/g;
my $b = () = $s =~ m/B/g;

my $ans = $r * $g * $b;

for my $i (0..($n - 2)) {
    for my $j (($i + 1)..($n - 1)) {
        my $k = $j*2 - $i;
        if($k >= $n) {
            next;
        }
        if($ss[$i] ne $ss[$j] && $ss[$i] ne $ss[$k] && $ss[$j] ne $ss[$k]) {
            $ans--;
        }
    }
}

print $ans;

Measured memory_bytes: 5540
class UF():
  def __init__(self, N):
    self._parent=[n for n in range(0, N)]
    self._size=[1] * N

  def find_root(self, x):
    if self._parent[x]==x:return x
    self._parent[x]=self.find_root(self._parent[x])
    return self._parent[x]

  def unite(self, x, y):
    gx=self.find_root(x)
    gy=self.find_root(y)
    if gx==gy:return

    if self._size[gx]<self._size[gy]:
      self._parent[gx]=gy
      self._size[gy]+=self._size[gx]
    else:
      self._parent[gy]=gx
      self._size[gx]+=self._size[gy]

  def size(self, x):
    return self._size[self.find_root(x)]

  def samegroup(self, x, y):
    return self.find_root(x)==self.find_root(y)

  def groupnum(self):
    N=len(self._parent)
    ans=0
    for i in range(N):
      if self.find_root(i)==i:
        ans+=1
    return ans

n,m=map(int,input().split())
UF=UF(n)
p=list(map(int,input().split()))
for i in range(m):
  x,y=map(int,input().split())
  UF.unite(x-1,y-1)

ct=0
for i in range(n):
  if UF.find_root(i)==UF.find_root(p[i]-1):ct+=1
print(ct)

Measured memory_bytes: 18608
#include<bits/stdc++.h>
#include<unordered_map>
using namespace std;
using Graph = vector<vector<int>>;
#define ll long long
#define all(x) (x).begin(),(x).end()
#define rep(i, n) for(ll i = 0; i < n; i++)
const ll INF = 1LL << 60;

bool my_compare(tuple<string, int, int> a, tuple<string, int, int> b){
    if(get<0>(a) != get<0>(b)){
        return get<0>(a) < get<0>(b);
    }
    return get<1>(a) > get<1>(b);
}

int main(){
    int N; cin >> N;
    vector<tuple<string, int, int>> t;
    rep(i, N){
        string str;
        int point;
        cin >> str >> point;
        t.emplace_back( str, point, i + 1);
    }
    sort(all(t), my_compare);
    for(auto x: t){
        cout << get<2>(x) << endl;
    }
}

Measured memory_bytes: 3644
import sys

def debug(x, table):
    for name, val in table.items():
        if x is val:
            print('DEBUG:{} -> {}'.format(name, val), file=sys.stderr)
            return None

def solve():
    s = input()
    stack = []

    for c in s:
        if c == 'B':
            if stack:
                stack.pop()
            else:
                pass
        else:
            stack.append(c)

    print(''.join(stack))


if __name__ == '__main__':
    solve()

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

using namespace std;

#define boost ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define ll long long int
#define v(d_type) vector<d_type>
#define loop(i, s, n) for(int i = s; i < n; i++)
#define print_vec(X) loop(i, 0, X.size()) cout << X[i] << "\n"
#define nl "\n"
#define fat 1000000007

int main()
{
    boost;
    int n;
    cin >> n;

    ll max_jump = 0;

    int prev = 0;

    int h, j = 0;
    loop(i, 0, n)
    {
        cin >> h;
        if(prev >= h)
            j++;
        else
            j = 0;

        prev = h;
        if(j > max_jump)
            max_jump = j;
    }

    cout << max_jump << nl;
    return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
int main() {
	int a;
	int frenum = 0;
	int data[101] = { 0 };
	int i;
	while (scanf("%d", &a) != EOF) {
		data[a]++;
		if (data[a] > frenum) {
			frenum = data[a];
		}
	}
	for (i = 1;i <= 100;i++) {
		if (data[i] == frenum) {
			printf("%d\n", i);
		}
	}
	return 0;
}

Measured memory_bytes: 596
data = [tuple(map(int, input().split())) for _ in range(int(input()))]
o = None
for i in data:
    if i[2] > 0:
        o = i
        break
hs = {}

for cx in range(101):
    for cy in range(101):
        H = o[2] + abs(o[0] - cx) + abs(o[1] - cy)
        ok = True
        for d in data:
            h = max(H - abs(d[0] - cx) - abs(d[1] - cy), 0)
            if h != d[2]:
                ok = False
                break
        if ok:
            print(cx,cy,H)
            exit(0)


Measured memory_bytes: 3064
n=int(input())
ab = []
for _ in range(n):
    a, b = (int(x) for x in input().split())
    ab.append([a, b])
cd = []
for _ in range(n):
    c, d = (int(x) for x in input().split())
    cd.append([c, d])
ab = sorted(ab, key=lambda x: -x[0])
cd = sorted(cd, key=lambda x: x[1])

count = 0

for a, b in ab:
    index = -1
    for i, cda in enumerate(cd):
        if a < cda[0] and b < cda[1] :
            index = i
            break
    if index != -1:
        cd.pop(index)
        count += 1
print(count)

Measured memory_bytes: 39152
#define _CRT_SECURE_NO_DEPRECATE
#pragma GCC optimize("O3")
#pragma GCC target("sse4")
#include<bits/stdc++.h>
//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
//using namespace __gnu_pbds;
#define int long long int
#define SYNC std::ios_base::sync_with_stdio(0);cin.tie(NULL);cout.tie(NULL);
#define FRE freopen("input.txt","r",stdin);freopen("output.txt","w",stdout);
typedef long double ld;
typedef pair<int,int> ii;
typedef pair<int,ii> iii;
typedef vector<int> vi;
typedef vector<ii>   vii;
//typedef tree<int, null_type, less<int>, rb_tree_tag, 
//             tree_order_statistics_node_update> 
//    ost;
#define rep(i,l,r)   for (int i = (l); i < (r); i++)
#define here cout << " Hey!!\n";
#define  pb push_back
#define  F  first
#define  S  second
#define all(v) (v).begin(),(v).end()
#define sz(a) (int)((a).size())
#define sq(x) ((x)*(x))
template <typename T>
void etch(T V) {
	for (auto x : V)	cout << x << ' ' ;
	cout << '\n';
}
vector<string> vec_splitter(string s) {
	s += ',';
	vector<string> res;
	while(!s.empty()) {
		res.push_back(s.substr(0, s.find(',')));
		s = s.substr(s.find(',') + 1);
	}
	return res;
}
void debug_out(
vector<string> __attribute__ ((unused)) args,
__attribute__ ((unused)) int idx, 
__attribute__ ((unused)) int LINE_NUM) { cerr << endl; } 
template <typename Head, typename... Tail>
void debug_out(vector<string> args, int idx, int LINE_NUM, Head H, Tail... T) {
	if(idx > 0) cerr << ", "; else cerr << "Line(" << LINE_NUM << ") ";
	stringstream ss; ss << H;
	cerr << args[idx] << " = " << ss.str();
	debug_out(args, idx + 1, LINE_NUM, T...);
}
#ifndef ONLINE_JUDGE
#define debug(...) debug_out(vec_splitter(#__VA_ARGS__), 0, __LINE__, __VA_ARGS__)
#else
#define debug(...) 42
#endif
const int MOD = 1e9+7;
const int MOD1 = 998244353;
const int N = 2e5+5;
const int INF = 1000111000111000111LL;
const ld EPS = 1e-12;
const ld PI = 3.141592653589793116;

int32_t main()
{
	SYNC
	int l, r, d;
	cin >> l >> r >> d;
	l--;
	cout << (r/d - l/d);
	return 0;
}

Measured memory_bytes: 3612
from collections import Counter
a=[]
n=int(input())
for i in range(n):
    a.append(input())


c=Counter(a)

print("AC x {}".format(c["AC"]))

print("WA x {}".format(c["WA"]))
print("TLE x {}".format(c["TLE"]))
print("RE x {}".format(c["RE"]))

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

namespace AtTest.C_Challenge
{
    class ABC_046
    {
        static void Main(string[] args)
        {
            Method(args);
            Console.ReadLine();
        }

        static void Method(string[] args)
        {
            int n = int.Parse(Console.ReadLine());
            var ta = new long[n, 2];
            for (int i = 0; i < n; i++)
            {
                string[] input = Console.ReadLine().Split(' ');
                ta[i, 0] = int.Parse(input[0]);
                ta[i, 1] = int.Parse(input[1]);
            }

            long takahashi = ta[0,0];
            long aoki = ta[0, 1];
            for(int i = 1; i < n; i++)
            {
                long rateT = 0, rateA = 0;
                rateT= takahashi / ta[i, 0];
                if (takahashi % ta[i, 0] > 0) rateT++;

                rateA = aoki / ta[i, 1];
                if (aoki % ta[i, 1] > 0) rateA++;

                if (ta[i, 1] * rateT < aoki)
                {
                    takahashi = ta[i, 0] * rateA;
                    aoki = ta[i, 1] * rateA;
                }
                else if(ta[i, 0] * rateA < takahashi)
                {
                    takahashi = ta[i, 0] * rateT;
                    aoki = ta[i, 1] * rateT;
                }
                else
                {
                    long rate = rateA < rateT ? rateA : rateT;
                    takahashi = ta[i, 0] * rate;
                    aoki = ta[i, 1] * rate;
                }
            }

            Console.WriteLine(takahashi + aoki);
        }

        static long GCD(long a, long b)
        {
            long c = b;
            do
            {
                c = a % b;
                a = b;
                b = c;
            } while (c > 0);
            return a;
        }

        static long LCM(long a, long b)
        {
            long c = GCD(a, b);
            return a * b / c;
        }
    }
}


Measured memory_bytes: 13140
#include "bits/stdc++.h"
#include "string"
using namespace std;

int main(){
	long long N;
	long long p[100001] = {};
	cin >> N;
	for (long long i=0;i<N;i++){
	int a;
	cin>>a;
	a++;
	p[a-1]++;
	p[a]++;
	p[a+1]++;
	}
	long long ans=-1;
	for (int j=0;j<100001;j++){
	ans = max(ans,p[j]);
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 1024
import math


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

    pos = A.index(1)
    l = math.ceil(pos / (K - 1))
    r = math.ceil((N - 1 - l * (K - 1)) / (K - 1))
    print(int(l + r))


if __name__ == "__main__":
    main()


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

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int teiin = sc.nextInt();
		int angryTime = sc.nextInt();
		int[] customerInfo = new int[n];
		for(int i =0;i <n;i++) {
			customerInfo[i] = sc.nextInt();
		}
		Arrays.sort(customerInfo);
		int answer = 0;
		int joshaSu = 0;
		int firstJoshaTime = 0;
		for(int i = 0;i <n;i++) {
			if(joshaSu == 0) {
				firstJoshaTime = customerInfo[i];
			}
			if(joshaSu < teiin && customerInfo[i] -firstJoshaTime <= angryTime) {
				joshaSu++;
			}else {
				answer++;
				joshaSu = 1;
				firstJoshaTime = customerInfo[i];
			}

			if(i == n-1) {
				answer++;
			}
		}
		System.out.println(answer);
	}
}

Measured memory_bytes: 48508
#include<iostream>
#include<stdio.h>
#include<algorithm>
#include<vector>
#include<string.h>
#include<math.h>
#include<map>
#include<iomanip>

const long long INF = 1e17+7;
const long long MOD = 1e9+7;
const double PI=acos(-1);

using namespace std;

int main(){
	int n;
	cin >> n;
	vector<long long> a(n);
	
	long long sum=0;
	for(int i=0;i<n;i++){
		cin >> a[i];
		sum+=a[i];
	}
	
	long long ans=INF,sum_2=0;
	
	for(int i=0;i<n-1;i++){
		sum_2+=a[i];
		sum-=a[i];
		ans=min(ans,abs(sum-sum_2));
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 1920
#include<cstdio>
#include<cstring>
#include<cmath>
#include<cstdlib>
#include<ctime>
#include<algorithm>
#include<queue>
#include<vector>
#define ll long long
#define max(a,b) (a>b?a:b)
#define min(a,b) (a<b?a:b)
#define inf 0x3f3f3f3f
#define mod 1000000007
#define eps 1e-18
inline ll read()
{
    ll tmp=0; char c=getchar(),f=1;
    for(;c<'0'||'9'<c;c=getchar())if(c=='-')f=-1;
    for(;'0'<=c&&c<='9';c=getchar())tmp=(tmp<<3)+(tmp<<1)+c-'0';
    return tmp*f;
}
using namespace std;
ll a[200010],b[200010];
ll tmp[200010];
int n;
ll find(ll k)
{
	int l=1,r=n+1;
	while(l<r){
		//printf("%d %d\n",l,r);
		int mid=(l+r)>>1;
		if(tmp[mid]>=k)r=mid;else l=mid+1;
	}
	//printf("%lld : %d\n",k,l);
	return l;
}
int main()
{
	int i,k;
	n=read();
	for(i=1;i<=n;i++)a[i]=read();
	for(i=1;i<=n;i++)b[i]=read();
	ll ans=0;
	for(k=1;k<=29;k++){
		//printf("*** %d\n",k);
		ll base=(1<<k)-1;
		for(i=1;i<=n;i++)tmp[i]=b[i]&base;
		sort(tmp+1,tmp+n+1);
		//for(i=1;i<=n;i++)printf("%lld ",a[i]&base); printf("\n");
		//for(i=1;i<=n;i++)printf("%lld ",tmp[i]); printf("\n");
		ll cnt=0; 
		for(i=1;i<=n;i++)
			cnt+=n-find((1<<(k-1))-(a[i]&base))+1;
		for(i=1;i<=n;i++)
			cnt-=find((1<<k)+(1<<(k-1))-(a[i]&base))-find((1<<k)-(a[i]&base));
		//printf("%lld\n",cnt);
		if(cnt&1)ans+=(1<<(k-1));
	}
	printf("%lld\n",ans);
}

Measured memory_bytes: 4864
#include "bits/stdc++.h"
using namespace std;

#define FAST ios_base::sync_with_stdio(false); cin.tie(0);
#define pb push_back
#define eb emplace_back
#define ins insert
#define ph push
#define f first
#define s second
#define cbr cerr << "hi\n"
#define mmst(x, v) memset((x), v, sizeof ((x)))
#define siz(x) ll(x.size())
#define all(x) (x).begin(), (x).end()
#define lbd(x, y) lower_bound(all(x), y)
#define ubd(x, y) upper_bound(all(x), y)
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());    //can be used by calling rng() or shuffle(A, A+n, rng)
inline long long rand(long long x, long long y) { return (rng() % (y+1-x)) + x; } //inclusivesss
string inline to_string(char c) {string s(1,c);return s;} template<typename T> inline T gcd(T a,T b){ return a==0?llabs(b):gcd(b%a,a); }

typedef long long ll; 
typedef long double ld;
#define FOR(i,s,e) for(ll i=s;i<=ll(e);++i)
#define DEC(i,s,e) for(ll i=s;i>=ll(e);--i)
typedef pair<ll,ll>pi; typedef pair<ll,pi>spi; typedef pair<pi,pi>dpi;

#define LLINF ((long long) 1e18)//1234567890987654321
#define INF 1234567890ll
// #define cerr if(0)cout
#define MAXN (2006)
ll n, dp[MAXN][2], sz[MAXN]; // dp(i, 0) = low, dp(i, 1) = high, observation is that high and low have the same parity
bool A[MAXN];
vector<int> v[MAXN];
int low=0, high=1;
void dfs(int x,int p) {
	sz[x] = A[x];
	for(auto i:v[x]) if(i^p) dfs(i, x), sz[x]+=sz[i];
	// dp(x,0) = max(summation{dp(i,0)}&1, max{dp(i)[low,high,2]}*2 - summation{dp(i)[low,high,2]})
	pi mx = pi(-LLINF, -LLINF);
	for(auto i:v[x]) if(i^p) {
		dp[x][high] += dp[i][high] + sz[i];
		mx = max(mx, pi(dp[i][high]+sz[i], dp[i][low]+sz[i]));
	}
	if(mx.s > dp[x][high] - mx.f) {
		dp[x][low]=mx.s-(dp[x][high]-mx.f);
	} else {
		dp[x][low]=dp[x][high]&1;
	}
}
int main()
{
	cin>>n;
	FOR(i,1,n) { char ch; cin>>ch; if(ch=='1') A[i]=1; }
	FOR(i,1,n-1) {
		ll a,b;cin>>a>>b;
		v[a].eb(b),v[b].eb(a);
	}
	ll ans = LLINF;
	FOR(r,1,n) {
		mmst(dp,0), mmst(sz,0);
		dfs(r, r);
		if(dp[r][low]==0) ans=min(ans, dp[r][high]>>1);
	}
	if(ans==LLINF) ans=-1;
	cout<<ans<<'\n';
}


Measured memory_bytes: 640
S_list= list(range(1, 14))
H_list= list(range(1, 14))
C_list= list(range(1, 14))
D_list= list(range(1, 14))
a = int(input())
for i in range(a):
    x,y = map(str,input().split())
    if x == 'S':
        S_list.remove(int(y))
    elif x == 'H':
        H_list.remove(int(y))
    elif x == 'C':
        C_list.remove(int(y))
    elif x == 'D':
        D_list.remove(int(y))

for item in S_list:
    print('S '+str(item))
for item in H_list:
    print('H '+str(item))
for item in C_list:
    print('C '+str(item))
for item in D_list:
    print('D '+str(item))

    


Measured memory_bytes: 5596
n = input()
lst = [int(x) for x in input().split()]
ret = 0
for idx, n in enumerate(lst[0:-2]):
    a, b, c = lst[idx], lst[idx + 1], lst[idx + 2]
    if b != min(a, b, c) and b != max(a, b, c):
        ret += 1
print(ret)

Measured memory_bytes: 3060
#include<stdio.h>
#include<stdlib.h>
int main()
{
   double a,b,c,d,e,f,x,y,h;
    while(scanf("%lf%lf%lf%lf%lf%lf",&a,&b,&c,&d,&e,&f)!=EOF){
        h=(a*e)-(b*d);
    x=((c*e)-(b*f))/h;
    y=((a*f)-(c*d))/h;
    if(x==0){
        x=abs(x);
    }
    if(y==0){
        y=abs(y);
    }
    printf("%0.3lf %0.3lf\n",x,y);
    }
    return 0;
}

Measured memory_bytes: 1688
#!/usr/bin/env python3
import sys
class BinaryIndexedTree:
    def __init__(self, size):
        """
        :param int size:
        """
        self.bit = [0 for _ in range(size)]
        self.size = size
 
    def add(self, i, w):
        """
        i番目にwを加える
        :param int i:
        :param int w:
        :return:
        """
        x = i + 1
        while x <= self.size:
            self.bit[x - 1] += w
            x += x & -x
        return
 
    def sum(self, i):
        """
        [0,i]の合計
        :param int i:
        :return:
        """
        res = 0
        x = i + 1
        while x > 0:
            res += self.bit[x - 1]
            x -= x & -x
        return res
 
    def search(self, x):
        """
        二分探索。和がx以上となる最小のインデックス(>= 1)を返す
        :param int x:
        :return :
        """
        i = 1
        s = 0
        step = 1 << (self.size.bit_length() - 1)
        while step:
            if i + step <= self.size and s + self.bit[i + step - 1] < x:
                i += step
                s += self.bit[i - 1]
            step >>= 1
        return i

n, q = map(int, sys.stdin.readline().split())
c = list(map(int, sys.stdin.readline().split()))
lr = [list(map(int, sys.stdin.readline().split())) + [i] for i in range(q)]
lr.sort(key=lambda x:x[1])
BIT = BinaryIndexedTree(n+1)
LastAppeared = [-1] * (n+1)
ans = [0] * q
R = 0
for l, r, i in lr:
    while R < r:
        if LastAppeared[c[R]] != -1:
            BIT.add(LastAppeared[c[R]], -1)
        LastAppeared[c[R]] = R+1
        BIT.add(R+1, 1)
        R += 1
    ans[i] = BIT.sum(r) - BIT.sum(l-1)

for i in ans:
    print(i)

Measured memory_bytes: 253872
#include <stdio.h>

int main(){
    long long a, b;
    scanf("%lld %lld", &a, &b);
      
    long long x = a*b;
    long long tmp;

    if(a < b){
        tmp = a;
        a = b;
        b = tmp;
    }
    
    long long r = a % b;
    
    while(r != 0){
        a = b;
        b = r;
        r = a % b;
    }
    
    printf("%lld", x/b);
    return 0;
}


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

int main()
{
    unsigned long long ullNumA = 0;
    unsigned long long ullNumB = 0;
    unsigned long long ullD = 0;
    unsigned long long ullR = 0;
    double dF = 0.0;
    
    cin >> ullNumA >> ullNumB;
    
    ullD = ullNumA / ullNumB;
    ullR = ullNumA % ullNumB;
    dF = (double)ullNumA / ullNumB;
    
    cout << ullD << " " << ullR << " " << setiosflags(ios::fixed) << setprecision(5) << dF << endl;
    
    return 0;
}


Measured memory_bytes: 3272
from sys import stdin, stdout

def main():
	N, K = (int(x) for x in stdin.readline().split())
	health = [int(x) for x in stdin.readline().split()]
	health.sort()
	for _ in range(min(len(health), K)):
		health.pop()
	stdout.write(str(sum(health)))

if __name__ == "__main__":
	main()

Measured memory_bytes: 25744
#include <stdio.h>
#include <stdlib.h>

typedef struct data *node;
struct data {
  int key;
  node p;
  node l;
  node r;
};

node root,NIL;

void insert(int k)
{
  node y = NIL;
  node x = root;
  node z;

  z = (node)malloc(sizeof(struct data));

  z->l = NIL;
  z->r = NIL;
  z->key = k;

  while(x != NIL){
    y = x;
    if(z->key < x->key) x = x->l;
    else x = x->r;
  }

  z->p = y;

  if(y == NIL) root = z;
  else{
    if(z->key < y->key) y->l = z;
    else y->r = z;
  }
}

void InOrder(node u)
{
  if(u == NIL) return;
  InOrder(u->l);
  printf(" %d",u->key);
  InOrder(u->r);
}

void Preorder(node u)
{
  if(u == NIL) return;
  printf(" %d",u->key);
  Preorder(u->l);
  Preorder(u->r);
}

int main()
{
  int n,i,a;
  char str[10];

  scanf("%d",&n);

  for(i=0;i<n;i++){
    scanf("%s",str);
    if(str[0] == 'i'){
      scanf("%d",&a);
      insert(a);
   	}
    else if(str[0]=='p'){
      InOrder(root);
			printf("\n");
			Preorder(root);
			printf("\n");
		}
	}

  return 0;
}



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

using namespace std;

#define N 1
typedef long long LL;
LL x, y;

int main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cin >> x >> y;
    int cnt = 1;
    while (x <= y)
        cnt++, x <<= 1;
    cout << cnt - 1 << endl;
    return 0;
}


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

#define LINE_BUF_SIZE 256

int main(){

    int i,j,k;
    int sx,sy,tx,ty;
    char line[LINE_BUF_SIZE];

    fgets(line,sizeof(line),stdin);
    sscanf(line,"%d %d %d %d", &sx,&sy,&tx,&ty);

    /*１往復目*/

    for(i=0;i<tx-sx;i++){
        printf("R");
    }

    for(i=0;i<ty-sy;i++){
        printf("U");
    }

    for(i=0;i<tx-sx;i++){
        printf("L");
    }

    for(i=0;i<ty-sy;i++){
        printf("D");
    }

    /*２往復目*/    

    printf("D");

    for(i=0;i<tx-sx+1;i++){
        printf("R");
    }

    for(i=0;i<ty-sy+1;i++){
        printf("U");
    }

    printf("LU");

    for(i=0;i<tx-sx+1;i++){
        printf("L");
    }

    for(i=0;i<ty-sy+1;i++){
        printf("D");
    }

    printf("R");

}

Measured memory_bytes: 128
def main():
    R, C, K = map(int, input().split())
    matrix = [[0] * (C+1) for i in range(R+1)]
    for k in range(K):
        ri, ci, vi = map(int, input().split())
        matrix[ri][ci] = vi
    # print(matrix)
    dp0 = [[0] * (C+1) for _ in range(R+1)]
    dp1 = [[0] * (C+1) for _ in range(R+1)]
    dp2 = [[0] * (C+1) for _ in range(R+1)]
    dp3 = [[0] * (C+1) for _ in range(R+1)]
    
    for r in range(1, R + 1):
        for c in range(1, C + 1):
            tmp = matrix[r][c]
            if tmp == 0:
                dp0[r][c] = max(dp0[r][c-1], dp0[r-1][c], dp1[r-1][c], dp2[r-1][c], dp3[r-1][c])
                dp1[r][c] = dp1[r][c-1]
                dp2[r][c] = dp2[r][c-1]
                dp3[r][c] = dp3[r][c-1]
            else:
                dp0[r][c] = max(dp0[r][c-1], dp0[r-1][c], dp1[r-1][c], dp2[r-1][c], dp3[r-1][c])
                dp1[r][c] = max(dp0[r][c-1] + tmp, dp1[r][c-1], 
                                dp0[r-1][c] + tmp, dp1[r-1][c] + tmp, dp2[r-1][c] + tmp, dp3[r-1][c] + tmp)
                dp2[r][c] = max(dp1[r][c-1] + tmp, dp2[r][c-1])
                dp3[r][c] = max(dp2[r][c-1] + tmp, dp3[r][c-1])

    print(max(dp0[R][C], dp1[R][C], dp2[R][C], dp3[R][C]))
    
main()


Measured memory_bytes: 430052
/* AtCoder Beginner Contest abc130
 * Problem A
 * Au: SJoshua
 */
#include <cstdio>
#include <vector>
#include <string>
#include <iostream>

using namespace std;

int main(void) {
	int a, b;
	cin >> a >> b;
	if (a < b) {
		cout << 0 << endl;
	} else {
		cout << 10 << endl;
	}
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define fast ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define test int t;cin>>t;while(t--)
typedef long long int ll;
#define REP(i,n) for (int i = 1; i <= n; i++)
#define mod 1000000007
#define pb push_back
#define ff first
#define ss second
#define ii pair<int,int>
#define vi vector<int>
#define vii vector<ii>
#define lli long long int
#define INF 1000000000
const double pi = 3.14159265358979323846;


void solve()
{
	int i=0,j=0,n=0,m=0,flag=0;
	long double prod=1;
    cin>>n;
    while(n--)
    {
        long double y;
        cin>>y;
        if(y==0)
        {
            cout<<0;
            return;
        }
        if((log10(prod))+(log10(y))>18 or prod*y>1e18)
        {
            flag=1;
        }
        prod*=y;
    }
    if(flag==0)
    cout<<ll(prod);
    else cout<<-1;
    
}

int main() {
    fast
    //test
    {
        
        solve();
		
		      
    }
    return 0;
}


Measured memory_bytes: 3812
# -*- coding: utf-8 -*-


def binarySearch(A, key):
    left = 0
    right = len(A)
    while left < right:
        mid = (left + right) // 2
        if A[mid] == key:
            return mid
        elif key < A[mid]:
            right = mid
        else:
            left = mid + 1

    return "NOT_FOUND"


if __name__ == '__main__':

    n = int(input())
    S = [int(s) for s in input().split(" ")]
    q = int(input())
    T = [int(t) for t in input().split(" ")]

    count = 0
    for t in T:
        if binarySearch(S, t) != "NOT_FOUND":
            count += 1

    print(count)



Measured memory_bytes: 16896
#include <stdio.h>

/** Application main entry point. */
int main (
  int     argc,
  char  * argv[ ]
  )
{
  for ( ; ; )
  {
    int r, c;

    scanf ( "%d%d", &r, &c );
    if ( !( r | c ) ) break ;

    puts ( r % 2 && c % 2
         ? "no"
         : "yes" );
  }

  return ( 0 );
}

Measured memory_bytes: 0
#include <bits/stdc++.h>
using namespace std;
int mx=-1;
vector<int> adj[200000];
int visit[200000];

int dfs(int s)
{
    if(!visit[s])
    {
        int x=0;
        for(int i=0;i<adj[s].size();++i)
        x=max(x,dfs(adj[s][i]));
        visit[s]=x+1;
        mx=max(mx,visit[s]);
        return visit[s];
    }
    return visit[s];
}

int main() {
    memset(visit,0,sizeof visit);
    int n,m;
    cin>>n>>m;
    for(int i=0;i<m;++i)
    {
        int x,y;
        cin>>x>>y;
        adj[x].push_back(y);
    }
    
    for(int i=0;i<=n;++i)
    if(visit[i]==0)
    dfs(i);
    cout<<mx-1;
    
	return 0;
}


Measured memory_bytes: 10880
#include<stdio.h>
#include<stdlib.h>
#define gc() getchar()
typedef unsigned long long ull;
int in() {   // 非負整数の入力
	int n = 0; int c;
	c = gc();
	do n = 10 * n + (c & 0xf); while ((c = gc()) >= '0');
	return n;
}
int comp(const void* a, const void* b)//用来做比较的函数。
{
	return *(int*)a - *(int*)b;
}
int a[100];
int main()
{
	int n, m,i,k=0,flag=0;
	double sum=0;
	n = in(), m = in();
	for (i = 0; i < n; i++) a[i] = in(),sum+=a[i];
	sum = sum / (4 * m);
	for (i = 0; i < n; i++)
	{
		if (a[i] >= sum) k++;
		if (k == m) { flag = 1; break; }
	}
	/*printf("%d\n", sum);*/
	if (flag == 1) printf("Yes\n");
	else printf("No\n");

}

Measured memory_bytes: 128
#define FASTIO ios::sync_with_stdio(false), cin.tie(0), cout.tie(0);
//#define BZ
//#define PBDS
//#define POINT

#ifndef BZ
#pragma GCC optimize ("Ofast")
#pragma GCC optimize ("unroll-loops")
#pragma GCC optimize ("no-stack-protector")
#pragma GCC target ("tune=native")
//#pragma GCC target ("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
//#pragma GCC optimize ("conserve-stack")
//#pragma GCC optimize ("no-stack-limit")
#endif

#include <bits/stdc++.h>

using namespace std;
using ll = long long;
using ld = long double;
using ull = unsigned long long;
using str = string;
using pll = pair<ll, ll>;

#ifdef POINT
using point = complex<ll>;
#define x real
#define y imag
#endif

#ifdef PBDS
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
//using namespace __gnu_pbds::detail;
template <class T>
using indexed_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
#endif

#define INF 0x7fffffffffffffffLL
#define BASE 1000000007LL // 3 * 10**9 + 19 // 998244353 - rev == pow(n + m, BASE - 2)
#define MAX(type) std::numeric_limits<type>::max()
#define MIN(type) std::numeric_limits<type>::min()

#define LOG(v) cout << #v << " " << v << "\n";

#define pb push_back
#define eb emplace_back
//#define all(c) c.begin(), c.end()
//#define rall(c) c.rbegin(), c.rend()
#define F first
#define S second
#define forEach(c) for (auto &it : c)
#define loop while (true)
#define mp make_pair
#define mt make_tuple

template<class T>
void chMax(T &a, T b) {
	if (a < b) a = b;
}

template<class T>
void chMin(T &a, T b) {
	if (b < a) a = b;
}

inline ll divUp(ll a, ll b) {
	return (a + b - 1)/b;
}

void solve() {
	ll n;
	cin >> n;
	for (ll i = 1; i < 10; i++) {
		if (n % i == 0 && n / i < 10) {
			cout << "Yes\n";
			return;
		}
	}
	cout << "No\n";
}

//#define LOCAL

int main() {
	FASTIO
#ifdef LOCAL
	auto start = std::chrono::system_clock::now();
#endif
	solve();
#ifdef LOCAL
	auto end = std::chrono::system_clock::now();
	std::chrono::duration<ld> elapsed_seconds = end - start;
	cerr << "\ntime: " << elapsed_seconds.count() << " s\n";
#endif
	return 0;
}


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

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

	int vn, g, en;
	while(cin >> vn >> g >> en, vn) {
		int v[4], e[51] = { 0 }, a[51];

		for(int i = 0; i < vn; i++) {
			cin >> v[i];
		}
		for(int i = 0; i < en; i++) {
			int n;
			cin >> n;
			cin >> e[n] >> a[n];
		}

		double dp[51][5010] = { 0 };
		dp[0][0] = 1.0;

		for(int i = 0; i < g; i++) {
			for(int j = 0; j <= 5000; j++) {
				if(dp[i][j] == 0) continue;

				for(int k = 0; k < vn; k++) {
					int ni = min(i + v[k], g), nj = j;
					if(e[ni] == 1) {
						ni = min(ni + a[ni], g);
					}
					else if(e[ni] == 2) {
						nj += a[ni];
					}
					else if(e[ni] == 3) {
						nj = max(nj - a[ni], 0);
					}
					dp[ni][nj] += dp[i][j] / vn;
				}
			}
		}
		double ans = 0;
		for(int j = 0; j <= 5000; j++) {
			ans += j * dp[g][j];
		}
		cout << int(ans) << endl;
	}
}

Measured memory_bytes: 5168
data = raw_input()
while data.count('-1') < 3:
	m,f,r = map(int,data.split(" "))
	if m+f < 30 or m == -1 or f == -1:
		print 'F'
	elif m+f >=80:
		print 'A'
	elif m+f >= 65:
		print 'B'
	elif m+f >= 50 or (m+f >=30 and r>= 50):
		print 'C'
	elif m+f >= 30:
		print 'D'
	elif m+f <30:
		print 'F'
	data = raw_input()

Measured memory_bytes: 4220