akhauriyash/Code-Regression huggingface dataset:
class Dice:
    def __init__(self, x):
        self.top = x[0]
        self.front = x[1]
        self.right = x[2]
        self.left = x[3]
        self.back = x[4]
        self.bottom = x[5]

    def N(self):
        self.top, self.front, self.bottom, self.back = self.front, self.bottom, self.back, self.top

    def E(self):
        self.top, self.right, self.bottom, self.left = self.left, self.top, self.right, self.bottom

    def S(self):
        self.top, self.front, self.bottom, self.back = self.back, self.top, self.front, self.bottom

    def W(self):
        self.top, self.right, self.bottom, self.left = self.right, self.bottom, self.left, self.top

    def up_front_to_right(self, top, front):
        if (top, front) in [(self.top, self.front), (self.front, self.bottom), (self.bottom, self.back), (self.back, self.top)]:
            return self.right
        elif (top, front) in [(self.front, self.top), (self.bottom, self.front), (self.back, self.bottom), (self.top, self.back)]:
            return self.left
        elif (top, front) in [(self.left, self.front), (self.front, self.right), (self.right, self.back), (self.back, self.left)]:
            return self.top
        elif (top, front) in [(self.front, self.left), (self.right, self.front), (self.back, self.right), (self.left, self.back)]:
            return self.bottom
        elif (top, front) in [(self.top, self.left), (self.left, self.bottom), (self.bottom, self.right), (self.right, self.top)]:
            return self.front
        elif (top, front) in [(self.left, self.top), (self.bottom, self.left), (self.right, self.bottom), (self.top, self.right)]:
            return self.back
        else:
            return -1
            
    def inverse(self,a):
        if a==self.top:
            return self.bottom
        elif a==self.front:
            return self.back
        elif a==self.right:
            return self.left
        elif a==self.left:
            return self.right
        elif a==self.back:
            return self.front
        elif a==self.front:
            return self.back
        else:
            return -1
            
*x,=map(int,input().split())
*y,=map(int,input().split())
dice0=Dice(x)
dice1=Dice(y)
for i in x:
    for j in x:
        if i!=j and i!=dice0.inverse(j):
            a=dice0.up_front_to_right(i,j)
            b=dice1.up_front_to_right(i,j)
            if a!=b:
                print('No')
                exit()
print('Yes')
            


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

const ll MOD=1000000007;

int main(){
    string S;
    cin>>S;
    if(S=="ABC"){
        cout<<"ARC"<<endl;
    }
    if(S=="ARC"){
        cout<<"ABC"<<endl;
    }
}

Measured memory_bytes: 3624
N = int(input())
list = [1,2,3,4,5,6,7,8,9,10,12,14,16,18,15,21,24,27,20,28,32,36,25,35,40,45,30,42,48,54,49,56,63,64,72,81]
if N in list:
  print("Yes")
else:
  print("No")


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


def main():

    result = ''

    for i in range(1, len(S)):
        s = S[0:len(S) - i]

        if len(s) % 2 == 0 and s[0:len(s)//2] == s[len(s)//2:]:
            result = len(s)
            break

    print(result)


if __name__ == '__main__':
    S = input()
    main()

Measured memory_bytes: 3060
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time

sys.setrecursionlimit(10**7)
inf = 10**20
mod = 10**9 + 7

stdin = sys.stdin

ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
ns = lambda: stdin.readline().rstrip()  # ignore trailing spaces

n, q = na()
s = input()
ct = [0] * n
for i in range(n-1):
    if s[i:i+2] == 'AC':
        ct[i+1] = 1
for i in range(n-1):
    ct[i+1] += ct[i]
for i in range(q):
    l, r = na()
    l -= 1
    r -= 1
    print(ct[r] - ct[l])

Measured memory_bytes: 10388
#include <iostream>
using namespace std;
typedef long long ll;
int n;
ll p=1e9+7, d[10000];
ll f(int x, int y, int z, int w){
    if(w==0)return 1;
    if(x!=-1&&d[(x*16+y*4+z)*100+w-1]>=0)return d[(x*16+y*4+z)*100+w-1];
    ll r=0;
    if(!(y==0&&z==2)&&!(x==0&&z==2)&&!(y==2&&z==0)&&!(x==0&&y==2)){
        r+=f(y, z, 1, w-1);
    }
    if(!(y==0&&z==1)){
        r+=f(y, z, 2, w-1);
    }
    r+=f(y, z, 0, w-1);
    r+=f(y, z, 3, w-1);
    r%=p;
    if(x!=-1){
        return d[(x*16+y*4+z)*100+w-1]=r;
    }
    return r;
}

int main(void){
    cin>>n;
    fill(d, d+10000, -1);
    ll ans=f(-1, -1, -1, n);
    cout<<ans<<endl;
}


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



int main()
{ios_base::sync_with_stdio(false);
    cin.tie(NULL);
   	int x,a;
   	cin>>x>>a;
   	if(x<a)
   	{
   		cout<<"0"<<endl;
   	}
   	else
   	{
   		cout<<"10"<<endl;
   	}
	return 0;

}

Measured memory_bytes: 3604
#include <bits/stdc++.h>
#define fr(i,n) for(int i=0;i<n;i++)
#define pb push_back
typedef long long ll;
typedef long double la;
using namespace std;

int main(){
    int h,a,i=0;
    cin >> h >> a;
    while(1){
        if(h<=0){
            break;
        }
        if(h>0){
            i++;
            h = h - a;
        }
    }
    cout << i << endl;
}

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

string S, T;

int main(){
  cin >> S;
  cin >> T;
  int count = 0;
  for(int i = 0; i<3; i++){
    if(S.at(i) == T.at(i)){
      count++;
    }
  }
  cout << count <<endl;
}


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

// 総数を1000000007で割った余り
const long long mod = 1e9 + 7;

using ll  = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
#define ull unsigned long long
#define ld long double
#define vi vector<int>
#define vll vector<ll>
#define vc vector<char>
#define vs vector<string>
#define vpii vector<pii>
#define vpll vector<pll>

#define rep(i, n) for (int i = 0, i##_len = (n); i < i##_len; i++)
#define rep1(i, n) for (int i = 1, i##_len = (n); i <= i##_len; i++)
#define repr(i, n) for (int i = ((int)(n)-1); i >= 0; i--)
#define rep1r(i, n) for (int i = ((int)(n)); i >= 1; i--)

#define sz(x) ((int)(x).size())
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()

#define SORT(v, n) sort(v, v + n);
#define VSORT(v) sort(v.begin(), v.end());
#define RSORT(x) sort(rall(x));
#define pb push_back
#define mp make_pair

#define INF (1e9)
#define PI (acos(-1))
#define EPS (1e-7)

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

void func(long long n, long long m, std::vector<long long> l,
          std::vector<long long> r) {
    int left  = 1;
    int right = n;
    rep(i, m) {
        left  = max((int)l[i], left);
        right = min((int)r[i], right);
    }

    cout << max(right - left + 1, 0) << endl;
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    // cout << fixed << setprecision(5);

    long long N;
    scanf("%lld", &N);
    long long M;
    scanf("%lld", &M);
    std::vector<long long> L(M);
    std::vector<long long> R(M);
    for (int i = 0; i < M; i++) {
        scanf("%lld", &L[i]);
        scanf("%lld", &R[i]);
    }
    func(N, M, std::move(L), std::move(R));
    return 0;
}


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

using namespace std;

const int N = 1e5 + 5;
int _w;

struct Seg {
  int l , r;
  Seg() {} Seg( int l , int r ):l( l ) , r( r ) {}
  bool operator < ( const Seg & rhs ) const { return l < rhs.l; }
  Seg operator ^ ( const Seg & rhs ) const { return Seg( max( l , rhs.l ) , min( r , rhs.r ) ); }
  int length( void ) { return max( 0 , r - l + 1 ); }
} dat[N] , pre[N] , suf[N];

int n , ans;

int main( void ) {
  _w = scanf("%d",&n);
  for( int i = 1 ; i <= n ; ++i )
    _w = scanf("%d%d",&dat[i].l,&dat[i].r);
  sort( dat + 1 , dat + 1 + n );
  pre[0] = suf[n + 1] = Seg( 0 , 1e9 );
  for( int i = 1 ; i <= n ; ++i ) pre[i] = pre[i - 1] ^ dat[i];
  for( int i = n ; i ; --i ) suf[i] = suf[i + 1] ^ dat[i];
  for( int i = 1 ; i <= n ; ++i )
    ans = max( ans , ( pre[i - 1] ^ suf[i + 1] ).length() + dat[i].length() );
  for( int i = 1 ; i < n ; ++i )
    ans = max( ans , pre[i].length() + suf[i + 1].length() );
  cout << ans;
  return 0;
}


Measured memory_bytes: 2560
#include "bits/stdc++.h"
#define rep(i,a,n) for(int i = a;i < n;i++)
typedef unsigned long long ull;
typedef long long ll;
using namespace std;

int main(){
    ll n,deff = 0,memo1,memo2,sum = 0,cnt = 0;
    cin >> n;
    ll a[n];
    double maxi = 0;
    
    rep(i,0,n){
        cin >> a[i];
    }
    
    sort(a,a+n);
    
    rep(i,1,n){
        deff = a[i] - a[i-1];
        memo1 = i;
        memo2 = i-1;
        sum = 0; cnt = 0;
        rep(j,0,n){
            if(!(memo1 == n-j-1 || memo2 == n-j-1) && cnt < 2){
                sum += a[n-j-1];
                cnt++;
            }
            else if(cnt >= 2){
                break;
            }
        }
        
        maxi = max(maxi,(double)sum/(double)deff);
    }
    
    
    cout << setprecision(20) << maxi << endl;
    return 0;
}


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


int main(void){
    char s[100];
    scanf("%s", s);

    int end=0;
    while(s[end]!='\0'){
        end++;
    }
    int i=0;
    int ans=0;
    for(i=0;i<end;i++){
        if(s[i]!=s[end-1]){
            ans++;
        }
        end--;
    }
    printf("%d", ans);

    return 0;
}

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

int main() {
    ll X;
    cin >> X;
    ll sum = 0;
    for (int i = 1; i <= X; ++i) {
        sum += i;
        if(sum >= X){
            cout << i << endl;
            break;
        }
    }
    return 0;
}

Measured memory_bytes: 384
#include <iostream>
#include <ccomplex>
#include <vector>
#include <cassert>
#include <utility>
#include <algorithm>
#include <string>
#include <deque>
#include <queue>
#include <functional>
#include <cmath>
#include <iomanip>
#include <map>
#include <numeric>
#include <list>
#include <assert.h>
#include <math.h>
#include <valarray>
#include <stdio.h>
#include <algorithm>
#include <set>
#include <complex>
#include <list>
#include <time.h>
#include <stack>
#include <locale>
#include <clocale>
#include <ctype.h>
#include <wchar.h>
#include <random>
#include <vector>
#include <unordered_map>
#include <bitset>

using namespace std;
typedef long long int LL;
typedef long long int ll;
typedef pair<long long int, long long int> pii;
typedef pair<double, double> pdd;

#define SORT(c) sort((c).begin(),(c).end())
#define BACKSORT(c) sort((c).begin(),(c).end(),std::greater<LL>())
#define FOR(i,a,b) for(LL i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)

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

  string s;
  cin >> s;
  if(s[0]=='A'){
    cout << "T" << endl;
  }
  if(s[0]=='T'){
    cout << "A" << endl;
  }
  if(s[0]=='G'){
    cout << "C" << endl;
  }
  if(s[0]=='C'){
    cout << "G" << endl;
  }
}


Measured memory_bytes: 256
N,K = [int(i) for i in input().split()]
S   = input()

Z =[]
last=1
cnt =0
n = len(S)

for i,s in enumerate(S):
    if s =="0" and i==n-1:
        if last==0:
            right = i
            Z.append((left, right))
            cnt += 1    #else:
        else:
            Z.append((i,i))
            cnt += 1
    elif last==1 and s=="0":
        left = i
        last = 0
    elif last==0 and s =="1":
        right = i-1
        last  = 1
        Z.append((left, right))
        cnt += 1

    #    pass

#print(cnt)
#print(n)

if K>=cnt:
    print(N)
else:
    #n=len(Z)
    len_z=len(Z)
    rem = cnt - K
    #print(n)
    #print(rem)
    kouho = []
    _, right = Z[rem-1]
    kouho.append(n-1-right)

    left, _ =Z[len_z-rem]
    kouho.append(left)

    for i in range(rem-1):
        L = Z[i]
        R = Z[len_z-rem+i+1]
        _,right = L
        left,_  = R
        kouho.append(left-right-1)

    print(max(kouho))


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

vector<string> BubbleSort(vector<string> A)
{
	for (int i = 0; i < N - 1; i++)
	{
		for (int j = N - 1; j >= i + 1; j--)
		{
			if (A.at(j - 1).at(1) > A.at(j).at(1))
			{
				swap(A.at(j - 1), A.at(j));
			}
		}
	}
	return A;
}

vector<string> SelectionSort(vector<string> A)
{
	for (int i = 0; i < N; i++)
	{
		int minj = i;
		for (int j = i + 1; j < N; j++)
		{
			if (A.at(j).at(1) < A.at(minj).at(1))
			{
				minj = j;
			}
		}
		swap(A.at(i), A.at(minj));
	}
	return A;
}

void output(vector<string> A)
{
	for (int i = 0; i < N; i++)
	{
		if (i != N - 1)
		{
			cout << A.at(i) << ' ';
		}
		else
		{
			cout << A.at(i) << endl;
		}
	}
}

int main()
{
	cin >> N;
	vector<string> A(N);
	for (int i = 0; i < N; i++)
	{
		cin >> A.at(i);
	}
	vector<string> bsA = BubbleSort(A);
	output(bsA);
	cout << "Stable" << endl;
	vector<string> ssA = SelectionSort(A);
	output(ssA);
	bool stable = 1;
	for (int i = 0; i < N; i++)
	{
		if (bsA.at(i) != ssA.at(i))
		{
			stable = 0;
			break;
		}
	}
	if (stable)
		cout << "Stable" << endl;
	else
		cout << "Not stable" << endl;
}


Measured memory_bytes: 3184
A = int(input())
B = int(input())
C = int(input())
X = int(input())
cnt = 0
for a in range(A + 1):
    for b in range(B + 1):
        for c in range(C + 1):
            if 500 * a + 100 * b + 50 * c == X:
                cnt += 1
print(cnt)

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

#define int long long
#define xxx int32_t
#define fuck_u return 0;
const int inf = 1e18L+5;

xxx main() {
    int n, w;
    scanf("%lld %lld", &n, &w);
	vector<int> weight(n), value(n);
    for(int i=0; i<n; ++i) {
		scanf("%lld %lld", &weight[i], &value[i]);
	}
	int sum_val = 0;
	for(int i: value) {
		sum_val += i;
	}
	vector<int> dp(sum_val+1, inf);
	//int dp[sum_val+1];
	//memset(dp, inf, sizeof(dp));
	dp[0] = 0;
	for(int i=0; i<n; ++i) {
		for(int j=sum_val-value[i]; j>=0; --j) {
			dp[value[i]+j] = min(dp[value[i]+j], dp[j]+weight[i]);
		}
	}
	int result = 0;
	for(int i=0; i<sum_val+1; ++i) {
		if(dp[i]<=w)
			result = i;
	}
    printf("%lld\n", result);
	fuck_u
}


Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i = 0;i<n;i++)
#define rep1(i,n) for(int i = 1;i<n;i++)
typedef long long ll;
#define vint vector<int>
#define vstring vector<string>
#define vll vector<ll>

int gcm(int a,int b);

int main(){
  int a,b;
  cin >> a >> b;
  string c;
  cin >> c;
  vint countnum(a);
  countnum[0] = 0;
  int count = 0;
  rep(i,a-1){
    if(c[i] == 'A' && c[i+1] == 'C'){
      count++;
    }
    countnum[i+1] = count;
  }
  //rep(i,a-1) cout << countnum[i] << endl;
  rep(i,b){
    int d,e;
    cin >> d >> e;
    cout << countnum[e-1] - countnum[d-1] << endl;
  }
}

int gcm(int a,int b){
  if(a < b) swap(a,b);
  if(b == 0) return a;
  return gcm(a%b,b);
}

//i番目までにはいくつ入ってる、っていう配列を作って
//それを参照するようにしたらいけそう

Measured memory_bytes: 1408
#include <bits/stdc++.h>
#define fo(i,a,b) for(int i=a;i<=b;i++)
#define fod(i,a,b) for(int i=a;i>=b;i--)
#define me0(a) memset(a,0,sizeof(a))
#define me1(a) memset(a,-1,sizeof(a))
#define op freopen("in.txt", "r", stdin)
#define op1 freopen("C:\\acm\\Cproj\\in.txt","r",stdin);
#define pr freopen("C:\\acm\\Cproj\\out.txt","w",stdout)
#define pr2 freopen("C:\\acm\\Cproj\\std.txt","w",stdout)
#define pii pair<int,int>
using namespace std;
const int INF = 0x3f3f3f3f;
typedef long long LL;
template <class T>
void read(T &val) { T x = 0; T bz = 1; char c; for (c = getchar(); (c<'0' || c>'9') && c != '-'; c = getchar()); if (c == '-') { bz = -1; c = getchar(); }for (; c >= '0' && c <= '9'; c = getchar()) x = x * 10 + c - 48; val = x * bz; }
const int maxn = 1e6 + 11;
const int mod=1e9+7;
int n,m,x,y,t;
int a[maxn];


vector<int>v[maxn];

void init(){
    for(int i=2;i<maxn;i++){
        for(int j = i;j<maxn;j+=i){
            v[j].push_back(i);
        }
    }
}

int num[maxn];
int main(){
//    op;
    init();
    read(n);
    int flag1 = 1;
    fo(i,1,n) read(a[i]);
    int gc = a[1];
    fo(i,2,n) gc = __gcd(gc,a[i]);

    if(gc>1) {
        puts("not coprime");
        return 0;
    }
    fo(i,1,n){
        for(auto to:v[a[i]]) {
            if(num[to]) flag1=0;
            num[to]++;
        }
    }
    if(flag1) puts("pairwise coprime");
    else puts("setwise coprime");

    return 0;
}

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

#define pb(s) push_back(s)
#define ALL(v) v.begin(), v.end()
#define ALLA(arr, sz) arr, arr + sz
#define SORT(v) sort(ALL(v))
#define REVERSE(v) reverse(ALL(v))
#define SORTA(arr, sz) sort(ALLA(arr, sz))
#define REVERSEA(arr, sz) reverse(ALLA(arr, sz))
#define PI 3.14159265358979323846264338327950L


typedef long long ll;

string divide[4] = {"dream", "dreamer", "erase", "eraser"};

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

    string str;
    cin>>str;
    REVERSE(str);
    for(int i=0;i<4;++i){
        REVERSE(divide[i]);
    }
    bool flag=1;
    for(int i=0;i<str.size();){
        bool flag2=0;
        for(int j=0;j<4;++j){
            if(str.substr(i,divide[j].size())==divide[j]){
                flag2=1;
                i+=divide[j].size();
            }
        }
        if(!flag2){
            cout<<"NO";
            return 0;
        }
    }
    cout<<"YES";
    return 0;
}



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

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int a = sc.nextInt();
		int b = sc.nextInt();
		int c = sc.nextInt();
		int k = sc.nextInt();
		sc.close();
		int[] list = new int[] {a,b,c};
		Arrays.sort(list);
		for(int i=0;i<k;i++) {
			list[2] *= 2;
		}
		System.out.println(list[0]+list[1]+list[2]);
	}
}

Measured memory_bytes: 20948
#include<bits/stdc++.h>
using namespace std;
#define fi(a) scanf("%d",&a);
#define fli(a) scanf("%ld",&a);
#define fll(a) scanf("%lld",&a);
#define pi(a) printf("%d\n",a);
#define ppi(i,a) printf("Case %d: %d\n",i,a);
#define ll long long
#define fast ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);

int main()
{
    fast
    int n;
    cin >> n;
    n=n%10;
    if(n==2 || n==4 || n==5 || n==7 || n==9) cout << "hon\n";
    else if(n==3) cout << "bon\n";
    else cout << "pon\n";
    return 0;
}



Measured memory_bytes: 3660
#include <bits/stdc++.h>
using namespace std;
using ull = unsigned long long;
using i64 = int64_t;
using u64 = uint64_t;
using u32 = uint32_t;

#define CPP_STR(x) CPP_STR_I(x)
#define CPP_CAT(x,y) CPP_CAT_I(x,y)
#define CPP_STR_I(args...) #args
#define CPP_CAT_I(x,y) x ## y

constexpr int64_t MOD = 1000000007LL;

#define FOR(i, start, end) for(i64 i = (start), CPP_CAT(i,xxxx_end)=(end); i < CPP_CAT(i,xxxx_end); ++i)
#define REP(i, n) FOR(i, 0, n)    

template<class T>
std::tuple<T> input() {
    T x; std::cin >> x;
    return std::make_tuple(x);
}

template<class T, class U, class... Args>
std::tuple<T, U, Args...> input() {
    auto first = input<T>();
    auto rest = input<U, Args...>();
    return std::tuple_cat(first, rest);
}

template<class T>
std::vector<T> input_vec(std::size_t size) {
    std::vector<T> vec(size);
    for (std::size_t i=0; i<size; i++)
        cin >> vec[i];
    return vec;
}

template<class T>
std::vector<T> input_vec(std::size_t size, T fill_value) {
    std::vector<T> vec(size, fill_value);
    for (std::size_t i=0; i<size; i++)
        cin >> vec[i];
    return vec;
}

/******************************************************/

void solve()
{
    auto [N, K] = input<int, int>();
    vector<int> A = input_vec<int>(N);
    FOR(i, K, N) {
        if (A[i-K] < A[i]) cout << "Yes\n";
        else cout << "No\n";
    }
}

int main() {
    solve();
    return 0;
}

Measured memory_bytes: 4044
#include<bits/stdc++.h>
using namespace std;
const int maxn=3e5+9;
const double ep=1e-2;
const int mod=1e9+7;
const double pi=acos(-1);
const int INF=0x3f3f3f3f;
#define debug1 puts("?");
#define debug(x) cout<<"##"<<(x)<<endl;
#define mk make_pair
#define PII pair<int,int>
#define PIII pair<PII,int>
#define PIL pair<int,ll>
#define PLI pair<ll,int>
#define eb emplace_back
#define fi first
#define se second
#define rep(i,a,b) for(register int i=(a);i<=(b);++i)
#define sd(x) scanf("%d",&(x))
#define slld(x) scanf("%lld",&(x))
#define sdd(x,y) scanf("%d%d",&(x),&(y))
#define sc(s) scanf("%s",(s))
#define pd(x) printf("%d\n",(x))
#define plld(x) printf("%lld\n",(x))
#define pdk(x) printf("%d ",(x))
typedef long long ll;
map<PII,bool>mp;
int h,w,m,res,r[maxn],c[maxn];
int a[maxn],b[maxn];
bool cmp1(int a,int b)
{
	return r[a]>r[b];
}
bool cmp2(int a,int b)
{
	return c[a]>c[b];
}
void solve()
{
	scanf("%d%d%d",&h,&w,&m);
	rep(i,1,max(h,w))a[i]=b[i]=i;
	rep(i,1,m)
	{
		int u,v;
		sdd(u,v);
		mp[mk(u,v)]=1;
		r[u]++;c[v]++;
	}
	sort(a+1,a+1+h,cmp1);
	sort(b+1,b+1+w,cmp2);
	res=r[a[1]]+c[b[1]];
	if(mp[mk(a[1],b[1])])res--;
	else
	{
		pd(res);return;
	}
	r[a[0]]=r[a[1]];c[b[0]]=c[b[1]];
	bool ju=0;
	rep(i,1,h)
	{
		if(!r[a[i]])break;
		if(r[a[i]]!=r[a[i-1]])break;
		rep(j,1,w)
		{
			if(!c[b[j]])break;
			if(c[b[j]]!=c[b[j-1]])break;
			if(!mp[mk(a[i],b[j])])
			{
				res++;ju=1;break;
			}
		}	
		if(ju)break;
	}
	pd(res);
}
int main()
{
	int T=1;
//	sd(T);
	while(T--)solve();
}

Measured memory_bytes: 27268
#!/usr/bin/env python
# coding: utf-8

def ri():
    return int(input())

def rl():
    return list(input().split())

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

def main():
    a, b = rli()
    print(max(0, a-2*b))


if __name__ == '__main__':
    main()


Measured memory_bytes: 2940
#include<bits/stdc++.h>
using namespace std;
int n,m;
int a[105];
int t[105];

void solve(int x){
  for(int i=1;i<=n-1;i++){
    if( a[i]%x > a[i+1]%x ){
      swap(a[i],a[i+1]);
    }
  }
}

int main(){
  cin>>n>>m;
  for(int i=1;i<=n;i++){
    cin>>a[i];
  }
  for(int i=1;i<=m;i++){
    solve(i);
  }
  for(int i=1;i<=n;i++){
    cout<<a[i]<<endl;
  }
  return 0;
}

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

using namespace std; 

typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef vector<PII> VPII;
typedef long long LL;
typedef vector<LL> VL;
typedef vector<VL> VVL;
typedef pair<LL, LL> PLL;
typedef vector<PLL> VPLL;
typedef priority_queue<int> PQ_DESC;
typedef priority_queue<int, vector<int>, greater<int>> PQ_ASC;
typedef priority_queue<PII> PQ_DESC_PII;
typedef priority_queue<PII, vector<PII>, greater<PII>> PQ_ASC_PII;

#define ALL(c) (c).begin(),(c).end()
#define PB push_back
#define MP make_pair
#define SORT_ASC(c) sort(ALL(c))
//#define SORT_DESC(c) sort(ALL(c), greater<typeof(*((c).begin()))>())
#define SORT_DESC(c) sort((c).rbegin(),(c).rend())
#define REV(c) reverse((c).begin(), (c).end())
#define SIZE(a) int((a).size())

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define ROF(i,a,b) for(int i=(b-1);i>=(a);--i)
#define REP(i,n) FOR(i,0,n)
#define PER(i,n) ROF(i,0,n)

const double EPS = 1e-10;
const double PI  = acos(-1.0);
const int LARGE_INT = 1e9+100;
const int INF = 2e9+100;
const LL INF_LL = (LL)INF * 300 * 300;
const int MOD = 1e9+7;

//debug
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

LL modpow(LL a, LL n) {
    LL res = 1;
    while (n > 0) {
        if (n & 1) res = res * a % MOD;
        a = a * a % MOD;
        n >>= 1;
    }
    return res;
}

void Main()
{
    LL n,t;cin>>n>>t;

    VL a(n);
    REP(i,n){
        cin>>a[i];
    }

    LL result = t;
    REP(i,n-1){
        result += min(t,a[i+1]-a[i]);
    }
    cout<<result<<endl;
	return;
}

int main()
{
	cin.tie(nullptr);
	ios_base::sync_with_stdio(false);
	cout << fixed << setprecision(15);
	Main();
    return 0;
}

Measured memory_bytes: 1792
#include <iostream>

using namespace std;

int main()
{
    int n;
    while(cin >> n){
        int r = 0;
        for(int a = 0; a <= 9; ++a){
            for(int b = 0; b <= 9; ++b){
                for(int c = 0; c <= 9; ++c){
                    for(int d = 0; d <= 9; ++d){
                        if( (a + b + c + d) == n ){
//                            cout << ' ' << a
//                                 << ' ' << b
//                                 << ' ' << c
//                                 << ' ' << d
//                                 << endl;
                            ++r;
                        }
                    }
                }
            }
        }
        cout << r << endl;
    }
    return 0;
}

Measured memory_bytes: 1160
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define fi first
#define se second
vector<ll> finddivisor(ll x){//整数xの約数が入ったvectorを返すよ(xを含む)  
    vector<ll> divisor;
    for(ll i=1; (i*i)<=x ;i++)
    {
        if(x%i==0){
            divisor.push_back(i);
            if(i*i!=x){
                divisor.push_back(x/i);
            }//約数はペアを持つことを利用

        }
    }
    sort(divisor.begin(),divisor.end());
    //divisor.push_back(x);
    return divisor;
}
int main(){
    ll n,ans=1;
    cin >> n;
    vector<ll> v(n),a,b;
    for(ll i=0;i < n;i++)
    {
        cin >> v.at(i);
    }
    a=finddivisor(v.at(0));
    b=finddivisor(v.at(1));

    for(int i=0;i < a.size();i++)
    {
        ll cnt=0;
        for(int j=0;j < n;j++)
        {
            if(v.at(j)%a.at(i)!=0){
                cnt++;
            }
            if(cnt>=2){
                break;
            }
        }
        if(cnt<2){
            ans=max(ans,a.at(i));
        }
    }
    for(int i=0;i < b.size();i++)
    {
        ll cnt=0;
        for(int j=0;j < n;j++)
        {
            if(v.at(j)%b.at(i)!=0){
                cnt++;
            }
            if(cnt>=2){
                break;
            }
        }
        if(cnt<2){
            ans=max(ans,b.at(i));
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 1024
#include <iostream>

using namespace std;

int main() {
	
	int a, b;
	
	while (true) {
		cin >> a >> b;

		if (a == 0 || b == 0) break;

		for (int i = 0; i < a; i++)	{
			for (int j = 0; j < b; j++)	{
				
				if (i == 0 || i == a - 1) 
					cout << '#';
				else {
					if (j == 0 || j == b - 1)	cout << '#';
					else cout << '.';
				}
			}
			cout << endl;
		}
		cout << endl;
	}

	return 0;
}


Measured memory_bytes: 3088
# include <algorithm>
# include <cassert>
# include <cctype>
# include <cstdio>
# include <cstdlib>
# include <cstring>
# include <cmath>
# include <iostream>
# include <map>
# include <queue>
# include <set>
# include <sstream>
# include <stack>
# include <string>
# include <vector>
# include <iomanip>

# define rep(i, n) for (int i = 0; i < (int)(n); i++)
# define irep(i, n) for (int i = int(n) - 1; i >= 0; i--)
# define FOR(i, m, n) for (int i = int(m); i < (int)(n); i++)

using namespace std;


int main() {
  int n;

  while (cin >> n) {
    if (!n) break;

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

    int  sum = 0;
    int _max = scr[0];
    int _min = scr[0];

    for (int s : scr) {
      sum  += s;
      _min = min(_min, s);
      _max = max(_max, s);
    }

    sum -= _max;
    sum -= _min;

    cout << sum / (n-2) << endl;
  }

  return 0;
}

Measured memory_bytes: 2976
#pragma GCC optimize("O3")
#pragma comment(linker, "/stack:200000000")
#pragma GCC optimize("unroll-loops")

#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
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define all(v) (v).begin(),(v).end()
#define rall(v) (v).rbegin(),(v).rend()
#define f first
#define s second
#define sz(x) (int)x.size()
#define endl "\n"
#define forn(i,n) for(int i=0;i<n;++i)
#define fore(i,l,r) for(int i=int(l);i<=int(r);++i)
#define rep(i,begin,end) for(__typeof(end) i=(begin);i!=(end);i++)
#define fill(a,value) memset(a,value,sizeof(a));
#define gcd(a,b) __gcd((a),(b))
#define watch1(x) cout<<(x)<<endl
#define watch2(x,y) cout<<(x)<<" "<<(y)<<endl
#define watch3(x,y,z) cout<<(x)<<" "<<(y)<<" "<<(z)<<endl
#define fastio ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);

typedef long long ll;
typedef long double ld; 
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<pii> vpii;
typedef tree<pii,null_type,less<pii>,rb_tree_tag,tree_order_statistics_node_update> oset;

const int INF = 9e18;
const int mod = 998244353;
const int N = 2e5 + 5;

int i,n,m,k,fact[N],ifact[N];

int power(int x,int y){
    int res=1;
    x%=mod;
    while(y>0){
        if(y&1){
            res*=x;
            res%=mod;
        }
        y>>=1;
        x*=x;
        x%=mod;
    }
    return res;
}
 
int modinv(int n){
    return power(n,mod-2);
}
 
int add(int a,int b){
	a%=mod,b%=mod;
	return a+b>=mod?a+b-mod:a+b;
}

int mul(int a,int b){
	a%=mod,b%=mod;
	return (a*b)%mod;
}

int C(int n,int r){
    return mul(fact[n],mul(ifact[r],ifact[n-r]));
}

void precompute(){
    fact[0]=1;
    ifact[0]=1;
    for(int i=1;i<N;++i){
        fact[i]=mul(fact[i-1],i);
        ifact[i]=mul(ifact[i-1],modinv(i));
    }
}

void solve(){
    precompute();
    cin>>n>>m>>k;
    int ans=0;
    for(i=0;i<=k;++i){
        int res=m;
        res*=C(n-1,n-1-i);
        res%=mod;
        res*=power(m-1,n-1-i);
        res%=mod;
        ans+=res;
        ans%=mod;
    }
    cout<<ans;
}

signed main(){
    fastio;
    int t;
    //cin>>t;
    t=1;
    while(t--){
        solve();
    }
    return 0;
}

Measured memory_bytes: 6764
#include <bits/stdc++.h>
#define _overload3(_1, _2, _3, name, ...) name
#define _rep(i, n) repi(i, 0, n)
#define repi(i, a, b) for (int i = (a); i < (b); ++i)
#define rep(...) _overload3(__VA_ARGS__, repi, _rep, )(__VA_ARGS__)
#define ll long long
#define lld long double
#define ALL(x) x.begin(), x.end()
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
using namespace std;
using VI = vector<int>;
using VVI = vector<VI>;
using VL = vector<ll>;
using VVL = vector<VL>;
using PII = pair<int, int>;

const int IINF = 1 << 30;
const ll INF = 1ll << 60;
const ll MOD = 1e9 + 7;
int main(int argc, char const *argv[])
{
    string s, t;
    cin >> s >> t;
    int h = s.size();
    int w = t.size();
    VVI dp(h + 1, VI(w + 1, 0));
    string ans;
    rep(i, h) rep(j, w)
    {

        chmax(dp[i + 1][j + 1], dp[i][j + 1]);
        chmax(dp[i + 1][j + 1], dp[i + 1][j]);
        if (s[i] == t[j])
        {
            chmax(dp[i + 1][j + 1], dp[i][j] + 1);
        }
    }
    int cur = dp[h][w];
    int y = h;
    int x = w;
    while (cur != 0)
    {
        //  cerr << y << " " << x << endl;
        if (dp[y - 1][x - 1] == dp[y][x] - 1 && dp[y][x - 1] == dp[y][x] - 1 && dp[y - 1][x] == dp[y][x] - 1)
        {
            ans += t[x - 1];
            x--;
            y--;
            cur = dp[y][x];
        }
        else if (dp[y][x - 1] == dp[y][x])
        {
            x--;
        }
        else
        {
            y--;
        }
    }

    reverse(ALL(ans));
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 35584
#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  cin >> n;
  int button[n];
  for (int i=0; i<n; i++) {
    cin >> button[i];
  }
  int x = 0;
  for (int i=0; i<n+1; i++) {
    if (button[x] == 2) {
      cout << i+1 << endl;
      break;
    }
    x = button[x]-1;
    if (i == n) {
      cout << "-1" << endl;
    }
  }
}

Measured memory_bytes: 640
import java.io.*;
import java.math.*;
import java.util.*;
public class Main { //CASH MONEY
 
	public static void main(String[] args) { //Ball out dawg
		FastScanner I = new FastScanner(); //Input
		OutPut O = new OutPut(); //Output
		long N = I.nextLong();
		long Y = I.nextLong();
		long x = -1;
		long y = -1;
		long z = -1;
		boolean good=false;
		for (long a = 0; a<=2000; a++) {
			for (long b = 0; b <= 2000; b++) {
				long cur = a*1000+b*5000;
				if (Y-cur>=0) {
					long diff = Y-cur;
					if ((N-a-b)*10000==diff) {
						x=a;
						y=b;
						z=N-a-b;
						good=true;
						break;
					}
				}
			}
			if (good) break;
		} 
		O.p(z+" "+y+" "+x);
	}
	public static long ceil(long num, long den) {long ans = num/den; if (num%den!=0) 
	ans++; return ans;}
	public static long GCD(long a, long b) {
		if (a==0||b==0) return Math.max(a,b);
		return GCD(Math.min(a, b),Math.max(a, b)%Math.min(a, b));
	}
	public static long FastExp(long base, long exp, long mod) {
		long ans=1;
		while (exp>0) {
			if (exp%2==1) ans*=base;
			exp/=2;
			base*=base;
			base%=mod;
			ans%=mod;
		}
		return ans;
	}
	public static long ModInv(long num,long mod) {return FastExp(num,mod-2,mod);}
	static class FastScanner {
		BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
		StringTokenizer st=new StringTokenizer("");
		String next() {
			while (!st.hasMoreTokens())
				try {
					st=new StringTokenizer(br.readLine());
				} catch (IOException e) {
					e.printStackTrace();
				}
			return st.nextToken();
		}
		int nextInt() {return Integer.parseInt(next());}
		long nextLong() {return Long.parseLong(next());};
	}
	static class OutPut{
		PrintWriter w = new PrintWriter(System.out);
		void pln(int x) {w.println(x);w.flush();}
		void pln(long x) {w.println(x);w.flush();}
		void pln(String x) {w.println(x);w.flush();}
		void pln(char x) {w.println(x);w.flush();}
		void pln(StringBuilder x) {w.println(x);w.flush();}
		void p(int x) {w.print(x);w.flush();}
		void p(long x) {w.print(x);w.flush();}
		void p(String x) {w.print(x);w.flush();}
		void p(char x) {w.print(x);w.flush();}
		void p(StringBuilder x) {w.print(x);w.flush();}
	}
}

Measured memory_bytes: 25992
import java.util.*;


public class Main{

  public static void main(String... args){
    Scanner sc = new Scanner(System.in);
    int n = sc.nextInt();
    long[] arr = new long[n];
    for(int i=0;i<n;i++){
      arr[i] = sc.nextLong() - (i+1);
    }
    Arrays.sort(arr);
    long b, ans1 = 0, ans2 = 0;
    if (n % 2 == 1){
      b = arr[n/2];
      for(int i=0;i<n;i++){
        ans1 += Math.abs(arr[i]-b);
      }
      System.out.println(ans1);
    }else{
      b = arr[n/2-1];
      for(int i=0;i<n;i++){
        ans1 += Math.abs(arr[i]-b);
      }
      b = arr[n/2];
      for(int i=0;i<n;i++){
        ans2 += Math.abs(arr[i]-b);
      }
      System.out.println(Math.min(ans1, ans2));
    }
  }
}

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

using namespace std;

#define int long long
#define all(v) begin(v), end(v)
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define reps(i, s, n) for(int i = (int)(s); i < (int)(n); i++)
#define min(...) min({__VA_ARGS__})
#define max(...) max({__VA_ARGS__})

template<class T1, class T2> void chmin(T1 &a, T2 b){if(a>b)a=b;}
template<class T1, class T2> void chmax(T1 &a, T2 b){if(a<b)a=b;}

using pint = pair<int, int>;
using tint = tuple<int, int, int>;
using vint = vector<int>;

const int inf = 1LL << 55;
const int mod = 1e9 + 7;

struct SegmentTree {
  vector<int> sum, lazy;
  int sz;
  SegmentTree(int n) {
    sz = 1; while(sz < n) sz *= 2;
    sum.resize(2*sz-1, 0);
    lazy.resize(2*sz-1, 0);
  }
  void push(int k, int l, int r) {
    if(lazy[k]) {
      sum[k] += lazy[k] * (r - l);
      if(r - l > 1) {
	lazy[2*k+1] += lazy[k];
	lazy[2*k+2] += lazy[k];
      }
      lazy[k] = 0;
    }
  }
  void update(int a, int b, int x, int k, int l, int r) {
    push(k, l, r);
    if(r <= a || b <= l) return;
    if(a <= l && r <= b) {
      lazy[k] += x;
      push(k, l, r);
      return;
    }
    update(a, b, x, 2*k+1, l, (l+r)/2);
    update(a, b, x, 2*k+2, (l+r)/2, r);
    sum[k] = sum[2*k+1] + sum[2*k+2];
  }
  void update(int a, int b, int x) {
    update(a, b, x, 0, 0, sz);
  }
  int query(int a, int b, int k, int l, int r) {
    push(k, l, r);
    if(r <= a || b <= l) return 0;
    if(a <= l && r <= b) return sum[k];
    return query(a, b, 2*k+1, l, (l+r)/2) + query(a, b, 2*k+2, (l+r)/2, r);
  }
  int query(int a, int b) {
    return query(a, b, 0, 0, sz);
  }
};

signed main()
{
  cin.tie(0);
  ios_base::sync_with_stdio(0);
  cout << fixed << setprecision(12);

  int n, q;
  cin >> n >> q;
  SegmentTree seg(n);
  rep(i, q) {
    int com, s, t, x;
    cin >> com >> s >> t;
    if(com == 0) cin >> x, seg.update(s-1, t, x);
    else cout << seg.query(s-1, t) << endl;
  }

  return 0;
}

Measured memory_bytes: 7036
#include<cmath>
#include<math.h>
#include<ctype.h>
#include<algorithm>
#include<bitset>
#include<cassert>
#include<cctype>
#include<cerrno>
#include<cfloat>
#include<ciso646>
#include<climits>
#include<clocale>
#include<complex>
#include<csetjmp>
#include<csignal>
#include<cstdarg>
#include<cstddef>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<ctime>
#include<cwchar>
#include<cwctype>
#include<deque>
#include<exception>
#include<fstream>
#include<functional>
#include<iomanip>
#include<ios>
#include<iosfwd>
#include<iostream>
#include<istream>
#include<iterator>
#include<limits>
#include<list>
#include<locale>
#include<map>
#include<memory>
#include<new>
#include<numeric>
#include<ostream>
#include<queue>
#include<set>
#include<sstream>
#include<stack>
#include<stdexcept>
#include<streambuf>
#include<string>
#include<typeinfo>
#include<utility>
#include<valarray>
#include<vector>
#include<string.h>
#include<stdlib.h>
#include<stdio.h>
using namespace std;
const long long Mod=924844033;
long long n,pw5[800010],pwinv5[800010];
long long pw(long long x,long long y)
{
	long long res=1;
	while (y)
	{
		if (y&1)
		{
			res=res*x%Mod;
		}
		x=x*x%Mod;
		y>>=1;
	}
	return res;
}
void pre()
{
	long long inv5=pw(5,Mod-2);
	for (int i=1;i<=n;i<<=1)
	{
		pw5[i]=pw(5,(Mod-1)/i);
		pwinv5[i]=pw(inv5,(Mod-1)/i);
	}
}
void rader(long long *a)
{
	for (int i=0,j=0;i<n;i++)
	{
		if (i>j)
		{
			swap(a[i],a[j]);
		}
		int k=n;
		do
		{
			k>>=1;
			j^=k;
		}while (j<k);
	}
}
void ntt(long long *a,long long f)
{
	rader(a);
	for (int i=2;i<=n;i<<=1)
	{
		int m=i>>1;
		for (int j=0;j<n;j+=i)
		{
			long long w=1,wn=pw5[i];
			if (f==-1)
			{
				wn=pwinv5[i];
			}
			for (int k=0;k<m;k++)
			{
				long long x=a[j+k+m]*w%Mod;
				a[j+k+m]=(a[j+k]-x+Mod)%Mod;
				a[j+k]=(a[j+k]+x)%Mod;
				w=w*wn%Mod;
			}
		}
	}
	if (f==-1)
	{
		long long inv=pw(n,Mod-2);
		for (int i=0;i<n;i++)
		{
			a[i]=a[i]*inv%Mod;
		}
	}
}
void conv(long long *a,long long *b)
{
	ntt(a,1);
	ntt(b,1);
	for (int i=0;i<n;i++)
	{
		a[i]=a[i]*b[i]%Mod;
	}
	ntt(a,-1);
}
int N,size[200010];
long long fac[200010],inv[200010],a[800010],b[800010];
int cnt,head[200010],to[400010],nxt[400010];
void add(int x,int y)
{
	cnt++;
	to[cnt]=y;
	nxt[cnt]=head[x];
	head[x]=cnt;
}
void dfs(int x,int fa)
{
	size[x]=1;
	for (int i=head[x];i;i=nxt[i])
	{
		int y=to[i];
		if (y==fa)
		{
			continue;
		}
		dfs(y,x);
		size[x]+=size[y];
		a[size[y]]--;
	}
	a[N-size[x]]--;
}
int main()
{
	scanf("%d",&N);
	fac[0]=1;
	for (int i=1;i<=N;i++)
	{
		fac[i]=fac[i-1]*i%Mod;
	}
	inv[N]=pw(fac[N],Mod-2);
	for (int i=N-1;i>=0;i--)
	{
		inv[i]=inv[i+1]*(i+1)%Mod;
	}
	for (int i=1;i<N;i++)
	{
		int x,y;
		scanf("%d%d",&x,&y);
		add(x,y);
		add(y,x);
	}
	dfs(1,0);
	a[N]=N;
	for (int i=1;i<=N;i++)
	{
		a[i]=(a[i]+Mod)%Mod;
		a[i]=a[i]*fac[i]%Mod;
		a[i-1]=a[i]; 
	}
	for (int i=0,j=N-1;i<j;i++,j--)
	{
		swap(a[i],a[j]);
	}
	a[N]=0;
	for (int i=0;i<=N;i++)
	{
		b[i]=inv[i];
	}
	n=1;
	while (n<=N+N)
	{
		n<<=1;
	}
	pre();
	conv(a,b);
	for (int i=1;i<=N;i++)
	{
		long long x=a[N-i];
		x=x*inv[i]%Mod;
		printf("%lld\n",x);
	}
    return 0;
}
//闻君有两意，故来相决绝。
//——卓文君《白头吟》

Measured memory_bytes: 38784
//2632.Dense Amidakuji.
#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;

#define MAX_N 300000
#define INF 1145141919

int h, w, k, x, y;

vector<int>pos[MAX_N * 2], neg[MAX_N * 2];//-_,/

int amidakuji(int p) {
	int H = 1, W = p, q = INF;
	while (H <= h) {
		//(H+W)%2==0-->pos.
		if ((H + W) % 2 == 0) {
			if (W == w) {
				H++;
				goto F;
			}
			q = INF;
			for (int j = 0; j < pos[MAX_N + H - W].size(); j++) {
				if (pos[MAX_N + H - W][j] >= H) {
					q = min(q, pos[MAX_N + H - W][j]);
				}
			}
			if (q == INF) {
				H += (w - W) + 1;
				W = w;
			}
			else {
				W += (q - H);
				H = q + 1;
			}
			if (H > h + 1) {
				W -= (H - h) - 2;
			}
		F:;
		}
		//(H+W)%2==1-->neg.
		else {
			if (W == 1) {
				H++;
				goto G;
			}
			q = INF;
			for (int j = 0; j < neg[H + W].size(); j++) {
				if (neg[H + W][j] >= H) {
					q = min(q, neg[H + W][j]);
				}
			}
			if (q == INF) {
				H += (W - 1) + 1;
				W = 1;
			}
			else {
				W -= (q - H);
				H = q + 1;
			}
			if (H > h + 1) {
				W += (H - h) - 2;
			}
		G:;
		}
	}
	return W;
}

int main() {
	cin >> h >> w >> k;
	for (int i = 0; i < k; i++) {
		cin >> x >> y;
		pos[MAX_N + x - y].push_back(x);
		neg[x + y + 1].push_back(x);
	}
	for (int i = 1; i <= w; i++) {
		cout << amidakuji(i) << endl;
	}
	return 0;
}

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

int main(){
  int a,b;
  while(cin >> a,a ){
    cin >> b;
    int cnt = 0;
    for(int i = a ; i <= b ; i++ ){
      int c = i;
      while(c%2 == 0)c/=2;
      while(c%3 == 0)c/=3;
      while(c%5 == 0)c/=5;
      if(c==1)cnt++;
    }
    cout << cnt << endl;
  }
}

Measured memory_bytes: 1160
n, m, k = gets.split.map(&:to_i)
a = gets.split.map(&:to_i)
b = gets.split.map(&:to_i)

aa = [0]
bb = [0]
a.size.times{|i| aa << a[i] + aa.last }
b.size.times{|i| bb << b[i] + bb.last }

i = 0
j = b.size
mx = 0
while i < aa.size && j >= 0
  if aa[i] + bb[j] <= k
    mx = i+j if mx < i+j
    i += 1
  else
    j -= 1
  end
end
puts mx

Measured memory_bytes: 45112
<?php
list($H, $W, $K) = ints();
for($i = 0; $i < $H; $i++){
  foreach(str_split(trim(fgets(STDIN))) as $v){
    $map[$i][] = boolval($v); 
  }
}
$min = 10**10;
for($i = 0, $I = 2**($H-1); $i < $I; $i++){
  $over = 0;
  $line[0] = 0;
  $ii = $i;
  for($j = 1; $j < $H; $j++){
    $line[$j] = $line[$j-1] + ($ii & 1);
    $ii >>= 1;
  }
  $counts = array_fill(0, $line[$H-1]+1, 0);
  $fromJ = 0;
  for($j = 0; $j < $W; ++$j){
    for($k = 0; $k < $H; ++$k){
      if($map[$k][$j])$counts[$line[$k]]++;
    }
    if(max($counts) > $K){
      $counts = array_fill(0, $line[$H-1]+1, 0);
      if($fromJ == $j)continue 2;
      $fromJ = $j;
      $over++;
      $j--;
    }
  }
  chmin($min, $over + popcount($i));
}
echo $min;
function ints(){
  return array_map("intval", explode(" ", trim(fgets(STDIN))));
}
function chmin(&$a,$b){if($a>$b){$a=$b;return 1;}return 0;}
function popcount($x){
    $con = 0;
    while ($x) {
        $x &= $x-1;
        ++$con;
    }
    return $con;
}


Measured memory_bytes: 4728
#include <iostream>
#include <cstdio>
#include <string>
#include <cmath>
#include <cctype>
#include <cstdlib>
#include <stack>
#include <queue>
#include <vector>
#include <algorithm>
#include <list>
using namespace std;

int main() {
    int a, b,ans=0;
    cin >> a >> b;
    for (int i = 1; i < b - a; i++) {
        ans += i;
    }
    cout << ans-a << endl;
}



Measured memory_bytes: 256
#include <algorithm>
#include <bits/stdc++.h>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
using namespace std;

#define rep(X, Y) for (int(X) = 0; (X) < (Y); ++(X))
#define rrep(X, Y) for (int(X) = (Y)-1; (X) >= 0; --(X))
#define all(X) (X).begin(), (X).end()
#define pb push_back
#define mp make_pair
#define fi first
#define sc second
#define print(x) cout << x << endl

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
const int dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};

void solve(long long N) {
  vector<ll> ans;
  for (ll i = 1; i < (ll)sqrt(N) + 1; i++) {
    if (N % i == 0) {
      ll j = N / i - 1;
      if (j > i) {
        ans.push_back(j);
      }
    }
  }

  ll sum = 0;
  for (ll i : ans) {
    sum += i;
  }
  print(sum);
}

int main() {
  long long N;
  scanf("%lld", &N);
  solve(N);
  return 0;
}


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

using std::cin;
using std::cout;
using std::endl;
using std::string;
using std::vector;
using std::bitset;

#define rep(i,n)    for(int i=0; i<(int)n; i++)
#define reps(i,s,e) for(int i=s; i<(int)e; i++)
#define coutd(i) cout << std::fixed << std::setprecision(i)
typedef long double ld;
typedef long long ll;
typedef vector<int> vint;
typedef vector<ll> vll;
typedef std::pair<int, int> pii;
typedef std::pair<ll, ll> pll;

template<class T>
using Set = std::set<T>;
template<class T, class U>
using Map = std::map<T, U>;

template<class T>
using Graph = vector<vector<T>>;

const int INT_BIG = 1<<28;

int main() {
    long unsigned int K;
    string s;
    cin >> K >> s;
    if (s.length() <= K) {
        cout << s << endl;
    } else {
        cout << s.substr(0, K) << "..." << endl;
    }
}

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

int main() {
  string s;
  cin >> s;
  int len = s.size();
  string ans;
  for(int i = 0; i < len; i++) {
    char s1 = s[i];
  	if(s1 == '0') ans += "0";
  	if(s1 == '1') ans += "1";
  	if(s1 == 'B' && ans.size()) ans.erase(ans.size()-1);
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
using namespace std;
int main() {
  vector<char> c(9);
  for (int i=0; i<9; i++) {
    cin >> c[i];
  }
  cout << c[0] << c[4] << c[8] << endl;
}

Measured memory_bytes: 256
C = input()

alpha = ["a","b","c","d","e","f","g","h","i","j","k","l","m","n","o","p","q","r","s","t","u","v","w","x","y","z"]

j = 0
for i in alpha:
    if i == C:
        print(alpha[j+1])
    j += 1

Measured memory_bytes: 9048
#include<iostream>
using namespace std;
int main()
{
   int n,k,q;
   cin>>n>>k>>q;
   int players[n];
   for(int i = 0 ; i <  n; i++){
      players[i]=k-q;
   }

   for(int i = 0 ; i < q ; i++){
      int whichplayer;
      cin>>whichplayer;
      players[whichplayer-1]++;
   }
   for(int i = 0 ; i < n ; i++){
      if(players[i]>0)cout<<"Yes"<<endl;
      else cout<<"No"<<endl;
   }
   return 0;

}


Measured memory_bytes: 1024
#include <iostream>

 

using namespace std;

 

int main()
{
   int a, b, temp, i;
   for(i=1; i<=3000; i++)
   {
      cin >> a >> b;
      
      if(a== 0 && b== 0)
      break;
      
      if(a > b)
      {
        temp = a;
        a = b;
        b = temp;
     
    }
    
    
 

   cout << a << " " << b << endl;
}

}


Measured memory_bytes: 3108
N = int(input())
S = input()
r = S.count('R')
g = S.count('G')
b = S.count('B')
ans = r * g * b

for i in range(N - 2):
    for j in range(i + 1, N - 1):
        k = 2 * j - i
        if k >= N:
            break
        if S[i] != S[j] and S[j] != S[k] and S[k] != S[i]:
            ans -= 1
print(ans)


Measured memory_bytes: 9188
#include <iostream>

int main() {
int n;
std::cin >> n;
int* a = new int[n];

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

for(int j = 0; j < n / 2; j++){
int put = a[j];
a[j] = a[n-1-j];
a[n-1-j] = put;
}

for(int l = 0; l < n; l++){
std::cout << a[l];
if(l != n-1){
std::cout << ' ';
}
}
std::cout << std::endl;
}

Measured memory_bytes: 3076
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <string>
#include <sstream>
#include <complex>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>

using namespace std;

#define REP(i,n) for(int i=0;i<n;i++)
#define all(x) (x).begin(),(x).end()
#define pb(a) push_back(a)
#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))

typedef long long unsigned int ll;
typedef pair<ll, ll> P;

int main(){
	int r,d,x;
	cin >>r>>d>>x;
	REP(i,10){
		x = r*x-d;
		cout << x <<endl;
	}
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, m, n) for (int i = m; i < n; ++i)
#define rem(i, m, n) for (int i = m; i >= n; --i)
typedef long long ll;
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 h[101010], dp[101010];
int main(){
  int N, K;
  cin >> N >> K;
  rep(i, 0, N) cin >> h[i];
  rep(i, 1, N) dp[i] = 1e9 + 1;
  rep(i, 0, N) {
    rep(j, 1, K + 1) {
      if(i + j == N) break;
      chmin(dp[i + j], dp[i] + abs(h[i] - h[i + j]));
    }
  }
  cout << dp[N - 1] << endl;
  return 0;
}


Measured memory_bytes: 1024