akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include<cstdio>
#include<cstring>
#include<string>
#define NIL -1
#define MAX 610005
#define REP(i,s,n) for(int i=s;i<n;i++)
#define rep(i,n) REP(i,0,n)
using namespace std;
int n;
int root;
int *p = new int[MAX];       //    p---|  Unit
int *left2 = new  int[MAX]; // left2 --|--------> T
int *right2 = new int[MAX]; //right2---|
int *key = new int[MAX];     // key----|
 
  
void Init(){
  rep(i,MAX){
    p[i]=left2[i]=right2[i]=key[i]=NIL;
  }
}
 
int TREE_MINIMUM(int x){
  while(left2[x] != NIL){
    x = left2[x];
  }
  return x;
}
 
 
int TREE_SUCCESSOR(int x){
  if(right2[x] != NIL)return TREE_MINIMUM(right2[x]);
  int y = p[x];
  while(y != NIL && x == right2[y]){
    x = y;
    y = p[y];
  }
  return y;
}
  
void TREE_DELETE(int z){
  int y,x;
  if(left2[z] == NIL || right2[z] == NIL)y = z;
  else y = TREE_SUCCESSOR(z);
 
  if(left2[y] != NIL)x = left2[y];
  else x = right2[y];
 
  if(x != NIL)p[x]=p[y];
  if(p[y] == NIL)root = x;
  else if(y == left2[p[y]])left2[p[y]] = x;
  else right2[p[y]] = x;
 
  if(y != z)key[z] = key[y];
 
}
 
 
bool SEARCH(int x,int k){
  if(k == key[x])return true;
  if(x == NIL)return false;
  if(k < key[x])return SEARCH(left2[x],k);
  else return SEARCH(right2[x],k);
}
 
  
void TREE_INSERT(int z){
  int y = NIL; 
  int x = root;
  
  while(x != NIL){
    y = x;
    if(key[z] < key[x]){
      x = left2[x];
    }
    else x = right2[x];
  }
  p[z]=y;
  if(y == NIL){
    root = z;
  }
  else if(key[z] < key[y]){
    left2[y] = z;
  }else{
    right2[y] = z;
  }
  
}
 
int IndexSearch(int x){
  for(int i=0;i<MAX;i++){
    if(key[i] == x)return i;
  }
  return -1;
}
 
 
void InorderTreeWalk(int x){
  if(x != NIL){
    InorderTreeWalk(left2[x]);
    printf(" %d",key[x]);
    InorderTreeWalk(right2[x]);
  }
}
  
void PreorderTreeWalk(int x){
  if(x != NIL){
    printf(" %d",key[x]);
    PreorderTreeWalk(left2[x]);
    PreorderTreeWalk(right2[x]);
  }
}
  
  
int main(){
  int val;
  string op;
  long long zr;                    
 
  
  scanf("%d",&n);
  Init(); 
  root = -1;
  zr=0;
  while(n-- > 0){
    cin >> op;
    if(op == "insert"){
      scanf("%d",&val);
      key[zr]=val;        
      TREE_INSERT(zr);
      zr++;
    }else if(op == "print"){
      InorderTreeWalk(root);
      printf("\n");
      PreorderTreeWalk(root);
      printf("\n");
    }
    else if(op == "find"){
      scanf("%d",&val);
      if(SEARCH(root,val)){
    printf("yes\n");
      }else{
    printf("no\n");
      }
        
  
    }
    else if(op == "delete"){
      scanf("%d",&val);
      int inthis = IndexSearch(val);
      if(inthis != -1){
      TREE_DELETE(inthis);
      }
    }
 
  }
  
  delete [] p;
  delete [] left2;
  delete [] right2;
  delete [] key;
 
  return 0;
}

Measured memory_bytes: 10000
import java.util.*;
public class Main{
    static Scanner kbd = new Scanner(System.in);
    public static void main(String[] args){
	while(kbd.hasNext()){
	    int n = kbd.nextInt();
	    if(n != 0){
		int change = 1000 - n;
		int cnt = 0;
		while(change >= 500){
		    change -= 500;
		    cnt++;
		}
		while(change >= 100){
		    change -= 100;
		    cnt++;
		}
		while(change >= 50){
		    change -= 50;
		    cnt++;
		}
		while(change >= 10){
		    change -= 10;
		    cnt++;
		}
		while(change >= 5){
		    change -= 5;
		    cnt++;
		}
		while(change >= 1){
		    change -= 1;
		    cnt++;
		}
		System.out.println(cnt);
	    }
	}
    }
}

Measured memory_bytes: 17164
#include <bits/stdc++.h>
 
using namespace std;
 
#define int long long 
#define INF 1e9
#define LINF 1e18
 
typedef unsigned long long ull;
typedef pair<int, int> P;
typedef pair<int, P> Pi;
typedef pair<P, P> PP;
 
const int MOD = 1e9 + 7;
const int dy[] = { 0, 0, 1, -1 };
const int dx[] = { 1, -1, 0, 0 };
 
template <class T> void chmin(T& a, const T& b) { a = min(a, b); }
template <class T> void chmax(T& a, const T& b) { a = max(a, b); }

int dp[101][4][4][4];

signed main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    int N;
    cin >> N;
    for(int i = 0; i < 4; ++i) {
        for(int j = 0; j < 4; ++j) {
            for(int k = 0; k < 4; ++k) {
                if(i == 0 && j == 1 && k == 2) continue;
                if(i == 1 && j == 0 && k == 2) continue;
                if(i == 0 && j == 2 && k == 1) continue;
                dp[3][i][j][k] = 1;
            }
        }
    }
    for(int i = 3; i < N; ++i) {
        for(int j = 0; j < 4; ++j) for(int k = 0; k < 4; ++k) {
            for(int l = 0; l < 4; ++l) for(int m = 0; m < 4; ++m) {
                if(k == 0 && l == 1 && m == 2) continue;
                if(k == 1 && l == 0 && m == 2) continue;
                if(k == 0 && l == 2 && m == 1) continue;
                if(j == 0 && l == 1 && m == 2) continue;
                if(j == 0 && k == 1 && m == 2) continue;
                dp[i + 1][k][l][m] += dp[i][j][k][l];
                dp[i + 1][k][l][m] %= MOD;
            }
        }
    }
    int res = 0;
    for(int i = 0; i < 4; ++i) {
        for(int j = 0; j < 4; ++j) {
            for(int k = 0; k < 4; ++k) {
                res += dp[N][i][j][k];
                res %= MOD;
            }
        }
    }
    cout << res << endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main(){
	int num[10001]={0};
	int i=1;
	int x;

	while(i!=0){
		cin>>x;
		if(x==0){
			break;
		}
		cout<<"Case "<<i<<": "<<x<<endl;
		i++;

	}

	return 0;
}

Measured memory_bytes: 2988
#include <iostream>
#include <string>
#include <cstdlib>
#include <cstdio>
#include <queue>
#include <stack>
#include <list>
#include <utility>
#include <vector>
#include <set>
#include <algorithm>
#include <cmath>
#include <climits>
#include <map>
#include <unordered_map>
#include <string.h>
#include<iomanip>
#include <iterator>
#include <locale>

#define all(a) a.begin(),a.end()
#define VV(T) vector<vector< T > >
#define rep(i,N) for(int i = 0; i <N; i++)
#define repsg(i,s,g) for(int i = s; i <g; i++)
#define name(x) #x
using namespace std;


const int INF = 10000000;
const long long INFL = (1LL<<40);
const int MOD = pow(10,9)+7;
int dy[]={0, 0, 1, -1, 0};
int dx[]={1, -1, 0, 0, 0};

typedef long long ll,LL;
typedef vector<int> vint;
typedef vector<vector<int> > vvint;
typedef vector<long long> vll, vLL;
typedef vector<vector<long long> > vvll, vvLL;
typedef pair<int,int> pii;
typedef pair<LL, LL> pLL;


// vector入力
template<typename T>
istream& operator >> (istream& is, vector<T>& vec){
    for(T& x: vec) is >> x;
    return is;
}
// vector出力
template<typename T>
ostream& operator << (ostream& os, vector<T>& vec){
    for(int i=0; i<vec.size(); i++){
        os << vec[i] << ( i+1 == vec.size() ? "" : " " );
    }
    return os;
}

template< typename T >
struct edge{
    int src, to;T cost;
    edge(int to,T cost) :src(-1),to(to),cost(cost){}
    edge(int src, int to, T cost) :src(src),to(to),cost(cost){}edge
    &operator=(const int &x){
        to =x;
        return *this;
    }
    operator int() const{ return to;}
};

double dist (double a, double b,  double c, double d){
    
    return sqrt((a-c)*(a-c) + (b-d)*(b-d));
    
}

bool check(int x,int y,vector<string> a,vector<string> b ){
    for(auto i = 0; i<b.size();i++){
        for(auto j =0; j<b.size();j++){
            if(a[x+i][y+j]!= b[i][j]) return false;
        }
    }
    return true;
}

int main() {
    int n,m;cin>>n>>m;
    vector<string>a(n),b(m);
    for(auto i = 0; i<n;i++)cin>>a[i];
    for(auto i = 0; i<m;i++)cin>>b[i];
    
    for(auto x=0;x+m-1<n;x++){
        for(auto y=0;y+m-1<n;y++){
            if(check(x,y,a,b)){cout<<"Yes"<<endl;return 0;}
        }
    }
    cout<<"No" << endl;
    return 0;
}







Measured memory_bytes: 256
#define _CRT_SECURE_NO_WARNINGS
#include<iostream>
#include<sstream>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<climits>
#include<cmath>
#include<string>
#include<vector>
#include<set>
#include<map>
#include<queue>
#include<numeric>
#include<functional>
#include<algorithm>
#include<bitset>
#include<tuple>
#include<unordered_set>
#include<unordered_map>
#include<random>
#include<array>
#include<cassert>
using namespace std;
#define INF (1<<29)
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define all(v) v.begin(),v.end()
#define uniq(v) v.erase(unique(all(v)),v.end())





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

	int n;
	cin >> n;
	map<string, int> freq;
	int ma = 0;
	rep(i,n) {
		string s;
		cin >> s;
		ma = max(ma, ++freq[s]);
	}
	for (const auto &p : freq) {
		if (p.second == ma) {
			cout << p.first << endl;
		}
	}



	return 0;
}

Measured memory_bytes: 23808
S = input()

if S == "SUN":
    print(7)
elif S == "SAT":
    print(1)
elif S == "FRI":
    print(2)
elif S == "THU":
    print(3)
elif S == "WED":
    print(4)
elif S == "TUE":
    print(5)
elif S == "MON":
    print(6)

Measured memory_bytes: 3060
from collections import deque
import copy, sys

input = sys.stdin.readline
n = int(input())
a = [deque(map(lambda x: int(x) - 1, input().split())) for _ in range(n)]
q = deque()
pre_q = deque()
day = 0

def check(p, q):
    if not len(a[p]):
        return
    o = a[p][0]
    if p == a[o][0]:
        if p > o: p, o = o, p
        if not (p, o) in q:
            q.append((p, o))

fin = []
for p in range(n):
    if not p in fin:
        o = a[p][0]
        if p == a[o][0]:
            q.append((p, o))
            fin += [p, o]

while q:
    day += 1
    pre_q = copy.copy(q)
    q.clear()
    for (p, o) in pre_q:
        a[p].popleft()
        a[o].popleft()
        check(p, q)
        check(o, q)

if all(map(len, a)):
    print(-1)
else:
    print(day)


Measured memory_bytes: 90716
#define _CRT_SECURE_NO_WARNINGS
#include <algorithm>
#include <array>
#include <cstdio>

using namespace std;

int main()
{
    int N;
    if (scanf("%d", &N) < 1) return 0;

    array<int, 50> a;

    for (int i = 0; i < N; i++) if (scanf("%d", &a[i]) < 1) return 0;

    auto mxit = max_element(a.begin(), a.begin() + N);
    int mxidx = distance(a.begin(), mxit);
    int mx = abs(*mxit);

    auto mnit = min_element(a.begin(), a.begin() + N);
    int mnidx = distance(a.begin(), mnit);
    int mn = abs(*mnit);

    printf("%d\n", 2 * N - 1);

    if (mn <= mx)
    {
        for (int i = 1; i <= N; i++)
        {
            printf("%d %d\n", mxidx + 1, i);
        }

        for (int i = 1; i < N; i++)
        {
            printf("%d %d\n", i, i + 1);
        }
    }
    else
    {
        for (int i = N; 0 < i; i--)
        {
            printf("%d %d\n", mnidx + 1, i);
        }

        for (int i = N - 1; 0 < i; i--)
        {
            printf("%d %d\n", i + 1, i);
        }
    }

    return 0;
}


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

#define _GLIBCXX_DEBUG
#define all(v) (v).begin(),(v).end()

using namespace std;

using ll=long long;
using pii=pair<int, int>;
using vi=vector<int>;

const ll INF=1LL<<60;
const int MOD=1e9+7;

int main(){
    vector<ll> fib(45);
    fib[0]=fib[1]=1;
    for(int i=2; i<45; i++){
        fib[i]=fib[i-1]+fib[i-2];
    }
    int n; cin >> n;
    cout << fib[n] << endl;
    return 0;
}


Measured memory_bytes: 3128
#include <algorithm>
#include <cassert>
#include <cstring>
#include <iostream>
#include <vector>
using namespace std;
typedef long long ll;

template<int mod>
struct ModInt {
  int val;
  ModInt inv() const{
    int tmp,a=val,b=mod,x=1,y=0;
    while(b)tmp=a/b,a-=tmp*b,swap(a,b),x-=tmp*y,swap(x,y);
    return ModInt(x);
  }
  ModInt():val(0){}
  ModInt(ll x){if((val=x%mod)<0)val+=mod;}
  ModInt pow(ll t){ModInt res=1,b=*this; while(t){if(t&1)res*=b;b*=b;t>>=1;}return res;}
  ModInt& operator+=(const ModInt& x){if((val+=x.val)>=mod)val-=mod;return *this;}
  ModInt& operator-=(const ModInt& x){if((val+=mod-x.val)>=mod)val-=mod; return *this;}
  ModInt& operator*=(const ModInt& x){val=(ll)val*x.val%mod; return *this;}
  ModInt& operator/=(const ModInt& x){return *this*=x.inv();}
  bool operator==(const ModInt& x) const{return val==x.val;}
  bool operator!=(const ModInt& x) const{return val!=x.val;}
  bool operator<(const ModInt& x) const{return val<x.val;}
  bool operator<=(const ModInt& x) const{return val<=x.val;}
  bool operator>(const ModInt& x) const{return val>x.val;}
  bool operator>=(const ModInt& x) const{return val>=x.val;}
  ModInt operator+(const ModInt& x) const{return ModInt(*this)+=x;}
  ModInt operator-(const ModInt& x) const{return ModInt(*this)-=x;}
  ModInt operator*(const ModInt& x) const{return ModInt(*this)*=x;}
  ModInt operator/(const ModInt& x) const{return ModInt(*this)/=x;}
  static int get_mod() { return mod; }
};

using modint = ModInt<1000000007>;

template <int mod>
struct Factorial {
  using mint = ModInt<mod>;
  vector<modint> Fact, Finv;
public:
  Factorial(int _n): Fact(_n+1), Finv(_n+1) {
      Fact[0]=mint(1); for (int i = 0; i < _n; ++i) Fact[i+1]=Fact[i]*(i+1);
      Finv[_n]=mint(1)/Fact[_n]; for (int i = _n; i > 0; --i) Finv[i-1]=Finv[i]*i;
  }
  mint fact(int n,bool inv=0) { if (inv) return Finv[n]; else return Fact[n]; }
  mint nPr(int n,int r){ if (n<0||n<r||r<0) return mint(0); else return Fact[n]*Finv[n-r]; }
  mint nCr(int n,int r){ if (n<0||n<r||r<0) return mint(0); else return Fact[n]*Finv[r]*Finv[n-r]; }
};

using factorial = Factorial<1000000007>;

int main() {
  int n, k;
  cin >> n >> k;
  factorial fact(5000);
  for (int i = 1; i <= k; ++i) { 
    modint ans = fact.nCr(n-k+1, i);
    ans *= fact.nCr(k-1, i-1);
    cout << ans.val << endl;
  }
}


Measured memory_bytes: 256
K, N = map(int, input().split())
A = list(map(int, input().split()))

maxLen = 0
A.sort()
for i in range(len(A)-1):
    l = A[i+1] - A[i]
    if l > maxLen:
        maxLen = l 
l = (A[0]+K) - A[i+1]
if l > maxLen:
    maxLen = l 

print(K-maxLen)

Measured memory_bytes: 25836
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <numeric>

using namespace std;
typedef long long ll;
bool IsPrime(int num)
{
    if (num < 2) return false;
    else if (num == 2) return true;
    else if (num % 2 == 0) return false; 

    double sqrtNum = sqrt(num);
    for (int i = 3; i <= sqrtNum; i += 2)
    {
        if (num % i == 0)
        {
            return false;
        }
    }
    return true;
}

int main(){
  int X;
  cin >> X;
  if(X%2==0 && X>2) X=X+1;
  int ans=0;
  for(int i=X;i<200000;i += 2){
    if(IsPrime(i)){
      ans = i;
      break;
    }
  }
  cout << ans << endl;
}


Measured memory_bytes: 3168
$FB = []
def fizzbuzzmaker(n)
  ($FB.size+1..n).each{|x|a=[[:Fizz][x%3],[:Buzz][x%5]]*'';a==''? $FB<<x.to_s: $FB<<a}
end
loop do
  m, n = gets.split.map(&:to_i)
  break if m == 0
  fizzbuzzmaker(n)
  pos = []
  ret = Array.new(m){|i|i+1}
  $FB[0,n].zip(n.times.map{gets.chomp}).map.with_index{|(a,b),i| i if a!=b}.compact[0,m-1].unshift(0).each_cons(2).with_index{|(a,b),i| pos << (b-a)%(m-i)}
  pos.reduce(0){|s,t| ret.slice!(t=(s+t)%ret.size); t-1}
  puts ret.join(' ')
end

Measured memory_bytes: 11240
import std.stdio, std.algorithm, std.conv, std.array, std.string, std.math, std.typecons, std.numeric;

void main()
{
    auto N = readln.chomp.to!int;
    auto AS = readln.split.to!(ulong[]);
    ulong x;
    size_t i, j;
    long r;
    while (j < N) {
        if (j < N && !(x&AS[j])) {
            x |= AS[j];
            r += j-i+1;
            ++j;
        } else {
            do {
                x ^= AS[i++];
            } while (i < N && x&AS[j]);
            x |= AS[j];
            r += j-i+1;
            ++j;
        }
    }
    writeln(r);
}

Measured memory_bytes: 10536
#include <cstdio>
#include <iostream>
#include <vector>
#include <set>
#include <map>
#include <memory>
#include <algorithm>
#include <cstring>

#define ll long long

using namespace std;


int main() {
    int n, l;
    cin >> n >> l;
    int sum = n * l + n * (n - 1) / 2;
    int min = 6666666;
    for (int i = 1; i <= n; ++i) {
        int x = (l + i - 1);
        if (abs(min) > abs(x))
            min = x;
    }
    cout << sum - min;

    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <stdio.h>
using namespace std;  //これで"std::cout"が"cout"と書ける

//MACRO
typedef long long ll;                  //64bit以上を表現可能な型
#define INF 100000000                  //ほぼ無限
#define itn int                        //タイポ対策
#define ALL(x) (x).begin(), (x).end()  //sort(all(x))などとする
#define SZ(x) ((int)(x).size())        //size()簡略化
//repetition
#define FOR(i, p, b) for (int i = (p); i < (b); ++i)
#define rep(i, n) FOR(i, 0, n)
#define repR(i, n) for (int i = n; i >= 0; i--)
//debug
#define dump(x) cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" \<< " " << __FILE__ << endl;
template <class T>
bool chMAX(T &a, const T &b) {  //aよりbが大きければaに代入(参照渡し)
    if (a < b) {
        a = b;
        return 1;
    }
    return 0;
}
template <class T>
bool chMIN(T &a, const T &b) {  //aよりbが小さければaに代入//参照渡し
    if (b < a) {
        a = b;
        return 1;
    }
    return 0;
}

int ctoi(const char c) {  //CtoI(int) charを渡すとintに変換する、数字以外だと-1を返す
    if ('0' <= c && c <= '9') return (c - '0');
    return -1;
}

//
//
//

int main() {
    char s[5];

    rep(i, 4) {
        cin >> s[i];
    }

    int a = ctoi(s[0]), b = ctoi(s[1]), c = ctoi(s[2]), d = ctoi(s[3]);

    if (a + b + c + d == 7) {
        cout << a << "+" << b << "+" << c << "+" << d << "=7" << endl;
    } else if (a + b + c - d == 7) {
        cout << a << "+" << b << "+" << c << "-" << d << "=7" << endl;
    } else if (a + b - c + d == 7) {
        cout << a << "+" << b << "-" << c << "+" << d << "=7" << endl;
    } else if (a - b + c + d == 7) {
        cout << a << "-" << b << "+" << c << "+" << d << "=7" << endl;
    } else if (a + b - c - d == 7) {
        cout << a << "+" << b << "-" << c << "-" << d << "=7" << endl;
    } else if (a - b + c - d == 7) {
        cout << a << "-" << b << "+" << c << "-" << d << "=7" << endl;
    } else if (a - b - c + d == 7) {
        cout << a << "-" << b << "-" << c << "+" << d << "=7" << endl;
    } else if (a - b - c - d == 7) {
        cout << a << "-" << b << "-" << c << "-" << d << "=7" << endl;
    }

}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < n; ++i)
#define rep2(i,s,n) for (int i = s; i < n; ++i)
#define all(a) a.begin(),a.end()
using namespace std;

int main() {
    int a,b,h;
    cin >> a >> b >> h;
    cout << (a+b)*h/2 << endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<vector>
#include<map>
using namespace std;
int M,N;
map<vector<int>,int>memo;
int f(int pre,const vector<int>&now)
{
	if(now.size()<=1)return 0;
	if(memo.find(now)!=memo.end())return memo[now];
	int ret=114514;
	for(int k=0;k<M;k++)
	{
		if(pre>>k&1)continue;
		vector<int>A[2];
		for(int v:now)A[v>>k&1].push_back(v);
		for(int i=0;i<2;i++)sort(A[i].begin(),A[i].end());
		int nxt=pre|1<<k;
		ret=min(ret,1+max(f(nxt,A[0]),f(nxt,A[1])));
	}
	return memo[now]=ret;
}
main()
{
	while(cin>>M>>N,M)
	{
		vector<int>now(N,0);
		for(int i=0;i<N;i++)
		{
			string s;cin>>s;
			for(int j=0;j<M;j++)now[i]=now[i]*2+s[j]-'0';
		}
		memo.clear();
		cout<<f(0,now)<<endl;
	}
}



Measured memory_bytes: 5284
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
template<class T = int> using V = vector<T>;
template<class T = int> using VV = V< V<T> >;
#define REP(i,n) for(int (i)=0;(i)<(n);(i)++)
#define ALL(v) (v).begin(),(v).end()
 
int main() {
	int X; cin >> X;
	V<bool> dp(X+1, false);
	dp[0] = true;
	dp[100] = true;
	dp[101] = true;
	dp[102] = true;
	dp[103] = true;
	dp[104] = true;
	dp[105] = true;
	for(int i=106; i<=X; i++)
		dp[i] = dp[i-100] || dp[i-101] || dp[i-102] || dp[i-103] || dp[i-104] || dp[i-105];

	cout << dp[X] << endl;
}

Measured memory_bytes: 256
a,b,c = map(int, input().split())
val = 0
if a == b == c and a%2 == 0 and b%2 == 0 and c%2 == 0:
  print(-1)
else:
  while a%2 == 0 and b%2 == 0 and c%2 == 0:
    a,b,c = int((b+c)/2), int((a+c)/2), int((a+b)/2)
    val += 1
  print(val)

Measured memory_bytes: 9184
N=int(input())
A = list(map(int, input().split())) 
B = list(map(int, input().split())) 
C = list(map(int, input().split())) 
ans=0
for i in range(N):
    ans+=B[A[i]-1]
    if i>=1:
        if (A[i]-A[i-1])==1:
            ans+=C[A[i-1]-1]
print(ans)  

Measured memory_bytes: 3064
s = input()
for i in range(len(s)):
    if (i+1) % 2 == 0 and s[i] == 'R':
        print('No')
        exit(0)
    if (i+1) % 2 == 1 and s[i] == 'L':
        print('No')
        exit(0)
print('Yes')
        

Measured memory_bytes: 9000
// AOJ 2425: A Holiday of Miss Brute Force
// 2017.12.30 bal4u@uu

#include <stdio.h>
#include <string.h>
 
#define QMAX 10000
typedef struct { int t, x, y, s; } QUE;
QUE que[QMAX]; int qsize;

#define PARENT(i) ((i)>>1)
#define LEFT(i)   ((i)<<1)
#define RIGHT(i)  (((i)<<1)+1)

void min_heapify(int i)
{
	int l, r, min;
	QUE qt;

	l = LEFT(i), r = RIGHT(i);
	if (l < qsize && que[l].t < que[i].t) min = l; else min = i;
	if (r < qsize && que[r].t < que[min].t) min = r;
	if (min != i) {
		qt = que[i], que[i] = que[min], que[min] = qt;
		min_heapify(min);
	}
}

void deq()
{
	que[0] = que[--qsize];
	min_heapify(0);
}

void enq(int x, int y, int s, int t)
{
	int i, min;
	QUE qt;

	i = qsize++;
	que[i].x = x, que[i].y = y, que[i].s = s, que[i].t = t;
	while (i > 0 && que[min = PARENT(i)].t > que[i].t) {
		qt = que[i], que[i] = que[min], que[min] = qt;
		i = min;
	}
}

#define INF 0x30303030
#define BASE 100

char map[202][202];
int dist[202][202][6];

int mv[2][6][2] = {{{1,0},{0,1},{-1,1},{-1,0},{-1,-1},{0,-1}},
				   {{1,0},{1,1},{ 0,1},{-1,0},{ 0,-1},{1,-1}}};
int tr[6];

char buf[30], *p;

int in()
{
	int n = 0;
	if (*p == '-') { p++; while (*p >= '0') n = 10*n + (*p++ & 0xf); n = -n; }
	else while (*p >= '0') n = 10*n + (*p++ & 0xf);
	p++;
	return n;
}

int dijkstra(int sx, int sy, int gx, int gy, int lx, int ly)
{
	int i, x, y, t, e, x2, y2, t2, e2, d;
	int xmin = BASE-lx, xmax = BASE+lx;
	int ymin = BASE-ly, ymax = BASE+ly;

	memset(dist, INF, sizeof(dist));
	dist[sy][sx][0] = 0;
	qsize = 0;
	enq(sx, sy, 0, 0);

	while (qsize) {
		x = que[0].x, y = que[0].y, t = que[0].s, e = que[0].t, deq();

		if (x == gx && y == gy) return e;

		d = (x-BASE)*(y-BASE)*t; if (d < 0) d = -d;	d %= 6;
		t2 = tr[t];

		// ????????´????????????
		if (dist[y][x][t2] > e+1) {
			dist[y][x][t2] = e+1;
			enq(x, y, t2, e+1);
		}

		// ?????????????§??????????
		for (i = 0; i < 6; i++) {
			x2 = x + mv[x&1][i][1], y2 = y + mv[x&1][i][0];
			e2 = e + (i!=d);
			if (x2 < xmin || x2 > xmax || y2 < ymin || y2 > ymax || map[y2][x2])
				continue;
			if (dist[y2][x2][t2] > e2) {
				dist[y2][x2][t2] = e2;
				enq(x2, y2, t2, e2);
			}
		}
	}
	return -1;
}

int main()
{
	int sx, sy, gx, gy, n, lx, ly, x, y;

	tr[5] = 0; for (n = 0; n < 5; n++) tr[n] = n+1;

	fgets(p=buf, 30, stdin);
	sx = BASE+in(), sy = BASE+in(), gx = BASE+in(), gy = BASE+in();

	fgets(p=buf, 10, stdin), n = in();
	while (n--) {
		fgets(p=buf, 15, stdin), x = BASE+in(), y = BASE+in();
		map[y][x] = 1;
	}

	fgets(p=buf, 15, stdin), lx = in(), ly = in();

	printf("%d\n", dijkstra(sx, sy, gx, gy, lx, ly));
	return 0;
}

Measured memory_bytes: 2920
#include <bits/stdc++.h>
#define REP(i, n, s) for (int i = (s); i < (n); i++)
using namespace std;
typedef long long int LL;
typedef long double LD;

const int MAXN = 1e5 + 1;
const int LOGV = 17;

int dp[LOGV][MAXN], X[MAXN];

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

	int N, L, i, j, Q, logV;

//	cin >> N;
	scanf("%d", &N);
	for (i = 1; i <= N; i++) {
//		cin >> X[i];
		scanf("%d", X+i);
	}
	for (logV = 1; (1 << (logV + 1)) <= N; logV++);
//	cin >> L;
	scanf("%d", &L);
	for (i = 1, j = 1; i <= N; i++) {
		while (j <= N && X[j] - X[i] <= L) j++;
		dp[0][i] = j - 1;
	}
	for (i = 1; i <= logV; i++) {
		for (j = 1; j + (1<<i)-1 <= N; j++) {
			dp[i][j] = dp[i-1][dp[i-1][j]];
		}
	}
//	cin >> Q;
	scanf("%d", &Q);
	int a, b;
	while (Q--) {
//		cin >> a >> b;
		scanf("%d%d", &a, &b);
		if (a > b) a ^= b ^= a ^= b;
		int step = 0;
		for (i = logV; i >= 0; i--) {
			if (dp[i][a] && dp[i][a] < b) {
				step += 1 << i;
				a = dp[i][a];
			}
		}
//		cout << step + 1 << endl;
		printf("%d\n", step + 1);
	}
	return 0;
}

Measured memory_bytes: 7424
#include <bits/stdc++.h>
#define mp make_pair
#define all(vec) vec.begin(), vec.end()
using namespace std;
using ll = long long;
using P = pair<ll, ll>;
const ll INF = 1LL << 30;
const ll LINF = 1LL << 60;
const double eps = 1e-9;
const ll MOD = 1000000007LL;
int main() {
    int n;cin>>n;
    vector<int> b(n);
    for(int i=0;i<n;i++)cin>>b[i];
    vector<int> ans;
    for(int i=0;i<n;i++){
        bool f=true;
        for(int j=n-1;j>=0;j--){
            int co=1;
            for(int k=0;k<j;k++){
                if(b[k]>0)co++;
            }
            if(b[j]==co){
                f=false;
                ans.push_back(co);
                b[j]=-1;
                break;
            }
        }
        if(f){
            cout<<-1<<endl;
            return 0;
        }
    }
    reverse(all(ans));
    for(int i=0;i<n;i++)cout<<ans[i]<<endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std; 
int main(){
	int n,number=0;
	cin>>n;
	int a[n];
	for(int i=0;i<n;i++) 
	cin>>a[i];
	sort(a,a+n);
	for(int i =0;i<n-2;i++){
		for(int j=i+1;j<n-1;j++){
			for(int k=j+1;k<n;k++){
				if(a[i]>=a[j]+a[k]||a[j]>=a[i]+a[k]||a[k]>=a[i]+a[j]) 
				break;
				number++;
			}
		}
	}
	cout<<number;
    return 0;
}


Measured memory_bytes: 256
using System;

namespace _0158
{
    class Program
    {
        static void Main(string[] args)
        {
            while(true)
            {
                int N = int.Parse(Console.ReadLine());
                if(N==0)
                {
                    break;
                }
                int output = 0;
                while(N!=1)
                {
                    if(N%2==0)
                    {
                        N = N / 2;
                        output++;
                    }
                    else
                    {
                        N = N * 3 + 1;
                        output++;
                    }
                }
                Console.WriteLine(output);
            }
        }
    }
}

Measured memory_bytes: 9000
#include <bits/stdc++.h>
#define BIT(n) (1LL << (n))
#define REP(i, n) for (int i = 0; i < n; i++)
#define REPB(i, n) for (int i = 0; i < BIT(n); i++)
#define REPS(i, x) for (int i = 1; i <= (int)(x); i++)
#define REPR(i, n) for (int i = n; i >= 0; i--)
#define FOR(i, m, n) for (int i = m; i < n; i++)
#define FORA(i, n) for (auto &&i : n)
#define FORS(i, m, n) for (int i = m; i <= n; i++)
#define DEBUG(x) cerr << #x << ": " << x << "\n"
#define DEBUG2(x, y) cerr << #x << ": " << x << " " << #y << ": " << y << "\n"
#define DEBUG3(x, y, z) cerr << #x << ": " << x << " " << #y << ": " << y << " " << #z << ": " << z << "\n"
#define PRINTALL(V)    \
  for (auto v : (V)) { \
    cerr << v << " ";  \
  }                    \
  cerr << "\n";
#define ALL(v) v.begin(), v.end()
#define fst first
#define snd second
#define mp make_pair
#define pb push_back
#define epb emplace_back
#define int long long
#define pint pair<int, int>
#define ld long double
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 (a > b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T> using vec = std::vector<T>;
template <class T> void print(const T &x) { cout << x << "\n"; }
const int MOD = 1000000007, INF = 1061109567, INF2 = INF * INF;
const double EPS = 1e-10, PI = acos(-1.0);
const int dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};
const int CALCSIZE = 5010;
int C[CALCSIZE][CALCSIZE];

void init() {
  for (int i = 0; i < CALCSIZE; ++i) {
    C[i][i] = C[i][0] = 1;
    for (int j = 1; j < i; ++j) {
      C[i][j] = (C[i - 1][j - 1] + C[i - 1][j]) % MOD;
    }
  }
}
signed main() {
  cin.tie(0), ios::sync_with_stdio(false);
  cout << fixed << setprecision(10);
  init();
  int N, P;
  cin >> N >> P;
  int cnt = 0;
  REP(i, N) {
    int q;
    cin >> q;
    cnt += q % 2 == 1;
  }
  /*  int val = 0;
    FORS(i, 0, cnt) {
      if (i % 2 == P) val += C[cnt][i];
    }

    print(BIT(N - cnt) * val);*/
  if (cnt == 0) {
    print(P == 0 ? BIT(N) : 0);
  } else {
    print(BIT(N - 1));
  }
}
/*
 */

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

typedef long long int ll;
typedef long double ld;

#define Pb push_back
#define Mp make_pair

#define ff first
#define ss second

#define Max(x,y,z) max(x,max(y,z))
#define Min(x,y,z) min(x,min(y,z))

#define INF LONG_LONG_MAX
#define MINF LONG_LONG_MIN

#define endl "\n"
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0)

#define db1(x) cout<<#x<<" : "<<x<<endl;
#define db2(x,y) cout<<#x<<" : "<<x<<"\t"<<#y<<" : "<<y<<endl;
#define db3(x,y,z) cout<<#x<<" : "<<x<<"\t"<<#y<<" : "<<y<<"\t"<<#z<<" : "<<z<<endl;


void solve()
{
  ll a,b,c,k;
  cin >> a >> b >> c >> k;
  ll sum = min(k,a);
  k-=min(k,a);
  if(k>0)
  {
    k-=min(k,b);
  }
  if(k>0)
  {
    sum-=min(c,k);
  }
  cout << sum;
}

signed main()
{
  IOS;
  //freopen("input.txt", "rt", stdin);
  //freopen("output.txt", "wt", stdout);
  int t=1;
  //cin >> t;
  while(t--)
  {
    solve();
  }
  return 0;
}
/*==============================================================================================================================================================*/


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

#define db1(x) cout<<#x<<"="<<x<<'\n'
#define db2(x,y) cout<<#x<<"="<<x<<","<<#y<<"="<<y<<'\n'
#define db3(x,y,z) cout<<#x<<"="<<x<<","<<#y<<"="<<y<<","<<#z<<"="<<z<<'\n'
#define rep(i,n) for(int i=0;i<(n);++i)
#define repA(i,a,n) for(int i=a;i<=(n);++i)
#define repD(i,a,n) for(int i=a;i>=(n);--i)

using namespace std;
using ll = long long;

int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    int n;
    cin>>n;
    int dp[3] = {0};
    rep(i,n)
    {
    	int vals[3] = {0};
    	rep(i,3) cin>>vals[i];
    	int n_dp[3] = {0};
    	rep(j,3)
		{
			
			rep(k,3)
			{
				if(j != k)
				{
					n_dp[k] = max(n_dp[k],vals[k] + dp[j]);
				}
			}
			
		}
    	rep(l,3) dp[l] = n_dp[l];
    }
	cout<<max({dp[0],dp[1],dp[2]});    
    return 0;
}

Measured memory_bytes: 256
n, q = map(int, input().split())
g = [[] for _ in range(n)]
for _ in range(n-1):
    a, b = map(int, input().split())
    a, b = a-1, b-1
    g[a].append(b)
    g[b].append(a)
l = [0]*n
for i in range(q):
    p, x = map(int, input().split())
    p = p-1
    l[p] += x

from collections import deque
s = deque()
s.append(0)
visit = [False]*n
visit[0] = True

while s:
    x = s.pop()
    for new_x in g[x]:
        if visit[new_x] == True:
            continue
        l[new_x] += l[x]
        s.append(new_x)
        visit[new_x] = True

print(*l)


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

int main()
{
	long long a, b;
	
	cin >> a >> b;
	long long dif = b - a;
	long long mdig1 = pow(2, 40);
	long long mdig2 = pow(2, 40);
	vector<int> at(41);
	vector<int> bt(41);

	for (int i = 0; i < 41; i++) {
		if (a < mdig1) {
			at[40 - i] = 0;
		}
		else {
			at[40 - i] = 1;
			a = a - mdig1;
		}
		mdig1 = mdig1 / 2;
	}
	for (int i = 0; i < 41; i++) {
		if (b < mdig2) {
			bt[40 - i] = 0;
		}
		else {
			bt[40 - i] = 1;
			b = b - mdig2;
		}
		mdig2 = mdig2 / 2;
	}
	vector<bool> ab(41);
	vector<bool> bb(41);

	for (int i = 0; i < 40; i++) {
		if (at[40 - i] == 0 || at[0] == 0) {
			ab[40 - i] = true;
		}
		else {
			ab[40 - i] = false;
		}
	}
	for (int i = 0; i < 40; i++) {
		if (bt[40 - i] == 0 || bt[0] == 1) {
			bb[40 - i] = true;
		}
		else {
			bb[40 - i] = false;
		}
	}

	vector<bool> ans(41);
	for (int i = 0; i < 40; i++) {
		if (ab[40-i] == bb[40-i]) {
			ans[40 - i] = false;
		}
		else {
			ans[40 - i] = true;
		}
	}

	if (at[0] == 0) {
		int r = dif % 4;
		if (r == 0 || r == 3) {
			ans[0] = false;
		}
		else {
			ans[0] = true;
		}

		
	}
	else {
		int r = dif % 4;
		if (r == 2 || r == 3) {
			ans[0] = false;
		}
		else {
			ans[0] = true;
		}
	}
		
	long long answer = 0;
	long long twotime = 1;
	for (int i = 0;i < 41; i++) {
		if (ans[i]) {
			answer = answer + twotime;
		}
		twotime = twotime * 2;
	}

	cout << answer << endl;
	return 0;

}


Measured memory_bytes: 256
#include "bits/stdc++.h"
#include <math.h>
#define   LF      '\n'
#define   ALL(x)  x.begin(), x.end()
#define   iostreamBooster()  do{cin.tie(nullptr);ios::sync_with_stdio(false);}while(0)
using namespace std;
typedef int64_t i64;
typedef pair<int,int> pii;
template<class A, class B>inline bool chmax(A &a, const B &b){return b>a ? a=b,1 : 0;}
template<class A, class B>inline bool chmin(A &a, const B &b){return b<a ? a=b,1 : 0;}
const int INF = 0x3f3f3f3f;


signed main()
{
  int N;
  int T, A;
  int h[1005];
  double t[1005];

  cin >> N >> T >> A;

  for (int i = 0; i < N; ++i) {
    cin >> h[i];
    t[i] = (double)T - h[i] * 0.006;
  }

  int p = 0;
  double v = INF;

  for (int i = 0; i < N; ++i) {
    double d = fabs(A - t[i]);
    if (d < v) {
      p = i;
      v = d;
    }
  }

  cout << p+1 << endl;

  return 0;
}



Measured memory_bytes: 256
import java.math.*;
import java.io.*;
import java.util.*;
 
class Main{
    public static void main(String[] args) throws Exception{
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        
        String t1 = br.readLine();
        String t2 = br.readLine();

        if(t1.length() > t2.length()){
            System.out.println(lcs(t2, t1));
        }else{
            System.out.println(lcs(t1, t2));
        }
        
    }

    public static String lcs(String s1, String s2){
        int[][] dp = new int[s1.length() + 1][s2.length() + 1];
        for(int i = 1; i < dp.length; i++){
            for(int j = 1; j < dp[i].length; j++){
                if(s1.charAt(i - 1) == s2.charAt(j - 1)){
                    dp[i][j] = dp[i - 1][j - 1] + 1;
                }else{
                    dp[i][j] = Math.max(dp[i -1][j], dp[i][j - 1]);
                }
            }
        }

        int m = s1.length(), n = s2.length();
        StringBuilder sb = new StringBuilder();

        while(m > 0 && n > 0){
            if(dp[m][n] == dp[m - 1][n]){
                m--;
            }else if(dp[m][n] == dp[m][n - 1]){
                n--;
            }else{
                sb.append(s1.charAt(m - 1));
                m--;
                n--;
            }
        }
        return sb.reverse().toString();
    }

}

Measured memory_bytes: 79316
def examC():
    N, Y = LI()
    ans = [-1, -1, -1]
    for i in range(N+1):
        for j in range(N-i+1):
            cur = 10000*i + 5000*j + 1000*(N-i-j)
            if Y==cur:
                ans = [i,j,(N-i-j)]
                break
    print(" ".join(map(str,ans)))

import sys,copy,bisect,itertools,heapq,math
from heapq import heappop,heappush,heapify
from collections import Counter,defaultdict,deque
def I(): return int(sys.stdin.readline())
def LI(): return list(map(int,sys.stdin.readline().split()))
def LS(): return sys.stdin.readline().split()
def S(): return sys.stdin.readline().strip()
mod = 10**9 + 7
inf = float('inf')

examC()


Measured memory_bytes: 38768
import itertools
N,M,Q=map(int,input().split())
a=[]
for _ in range(Q):
    b=list(map(int,input().split()))
    a.append(b)
s=[]
for i in range(1,M+1):
    s.append(i)
alist=list(itertools.combinations_with_replacement(s, r=N+1))


tmp=0
for j in alist:
    s=0
    for i in range(Q):
        j=list(j)
        if j[a[i][1]]-j[a[i][0]]==a[i][2]:
            s+=a[i][3]
    tmp=max(tmp,s)
print(tmp)

Measured memory_bytes: 94008
#define dbg(fmt,...) fprintf(stderr,fmt,__VA_ARGS__)
#define dpri(x) dbg(#x ": %d\n", x)
#define dprs(x) dbg(#x ": %s\n", x)
#include <stdio.h>
#include <string.h>
typedef long long ll;
const int INF = 1e9+7;

int main(int argc, char **argv)
{
	int n, taro, hanako, res;
	char tcard[128], hcard[128];

	taro = hanako = 0;
	scanf("%d", &n);
	while (n--) {
		scanf("%s %s", tcard, hcard);
		res = strcmp(tcard, hcard);
		if (res > 0) {
			taro += 3;
		} else if (res < 0) {
			hanako += 3;
		} else {
			taro += 1;
			hanako += 1;
		}
	}
	printf("%d %d\n", taro, hanako);
	return 0;
}

Measured memory_bytes: 604
#include <string>
#include <iostream>
#include <stack>
#include <queue> // priority_queue も入ってる
#include <set>   // 要素数は size() で取得 multisetもある
#include <map>
#include <array> // sizeはコンパイル時定数で固定
#include <vector>
#include <numeric>   // accumulate, gcd
#include <algorithm> // count_ifに必要
#include <iomanip>   // cout << setprecision(15) << x で小数の出力精度を指定
#include <tuple>
#include <utility> //pair
#include <cmath>

using namespace std;
// 問題が起こるまでintは使用禁止2020-04-13
using ll = long long;

#define rep(i, n) for (int i = 0; i < (n); ++i)

template <class InputIterator, class T>
bool contains_itr(InputIterator iterator, const T &value)
{
    if (find(iterator.begin(), iterator.end(), value) == iterator.end())
        return false;
    else
        return true;
}

template <class T>
bool contains_set(set<T> st, const T &value)
{
    if (st.find(value) == st.end())
    {
        return false;
    }
    else
    {
        return true;
    }
}

template <class InputIterator>
auto sum(InputIterator iterator)
{
    return accumulate(iterator.begin(), iterator.end(), 0);
}

// endは排他的(exclusive)なので注意
vector<ll> range(ll begin, ll end)
{
    vector<ll> result;
    for (ll i = begin; i < end; ++i)
    {
        result.push_back(i);
    }
    return result;
}

// =========ここまでテンプレ============

int main()
{
    ll n;
    cin >> n;
    vector<ll> a(n);
    rep(i, n) cin >> a[i];
    ll stocks = 0;
    ll money = 1000;
    rep(i, n)
    {
        if (i < n - 1 && ((i == 0 && a[i] <= a[i + 1]) || (a[i - 1] >= a[i] && a[i] < a[i + 1])))
        {
            stocks += money / a[i];
            money = money % a[i];
        }
        else if (0 < i && ((a[i - 1] <= a[i] && a[i] > a[i + 1]) || (i == n - 1)))
        {
            money += stocks * a[i];
            stocks = 0;
        }
    }
    cout << money << endl;
}

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

ll INF = 1LL<<60;

const int n = 26;
int main(){
	ll d;
	cin >> d;
	vector<vector<ll>> s(d+1, vector<ll>(n+1,0));
	vector<ll> c(n+1); //満足度低下
	REP(i,n) cin >> c[i];
	REP(i,d){
		REP(j,n){
			cin >> s[i][j];
		}
	}
	vector<ll> schedule(d+1);
	vector<ll> score(d+1);
	vector<ll> last(n+1,0);
	//ll total_score = 0;
	REP(i,d){
		ll d_score = -INF;
		REP(j,n){
			ll temp = 0;
			temp += s[i][j];
			REP(k,n){
				if(k == j) continue;
				temp -= c[k]*(i - last[k]);
			}
			if(d_score < temp){
				d_score = temp;
				schedule[i] = j;
			}
		}
	//	total_score += d_score;
		last[schedule[i]] = i;
	}
	//  cout << total_score << endl;
	REP(i,d){
		cout << schedule[i] << endl;
	}
	return 0;
}



Measured memory_bytes: 3728
#include <stdio.h>
#include <string.h>

int main(void) {
	int sum, n, i,buf[6],cs[6] = {1,5,6,2,3,4}, ci[6];
	char way[6]; 
	while(scanf("%d",&n)){
		if(n == 0)break;
		sum = 1;
		memcpy(ci, cs, sizeof(ci));
	for(i = 0; n > i; i++){
		scanf("%s",way);
		if(!strcmp(way, "North")){
			buf[0] = ci[3];
			buf[1] = ci[0];
			buf[2] = ci[1];
			buf[3] = ci[2];
			buf[4] = ci[4];
			buf[5] = ci[5];
		}
		else if(!strcmp(way, "East")){
			buf[0] = ci[5];
			buf[1] = ci[1];
			buf[2] = ci[4];
			buf[3] = ci[3];
			buf[4] = ci[0];
			buf[5] = ci[2];
		}
		else if(!strcmp(way, "South")){
			buf[0] = ci[1];
			buf[1] = ci[2];
			buf[2] = ci[3];
			buf[3] = ci[0];
			buf[4] = ci[4];
			buf[5] = ci[5];
		}
		else if(!strcmp(way, "West")){
			buf[0] = ci[4];
			buf[1] = ci[1];
			buf[2] = ci[5];
			buf[3] = ci[3];
			buf[4] = ci[2];
			buf[5] = ci[0];
		}
		else if(!strcmp(way, "Right")){
			buf[0] = ci[0];
			buf[1] = ci[5];
			buf[2] = ci[2];
			buf[3] = ci[4];
			buf[4] = ci[1];
			buf[5] = ci[3];
		}
		else if(!strcmp(way, "Left")){
			buf[0] = ci[0];
			buf[1] = ci[4];
			buf[2] = ci[2];
			buf[3] = ci[5];
			buf[4] = ci[3];
			buf[5] = ci[1];
		}
		sum += buf[0];
		memcpy(ci, buf, sizeof(ci));
	}
	printf("%d\n",sum);
	}
	return 0;
}

Measured memory_bytes: 1032
s = gets.chomp.bytes.sort
t = gets.chomp.bytes.sort.reverse
ans = 'No'
[s.size, t.size].max.times do |i|
  if s[i].nil?
    ans = 'Yes'
    break
  elsif t[i].nil?
    ans = 'No'
    break
  elsif s[i] < t[i]
    ans = 'Yes'
    break
  elsif s[i] > t[i]
    ans = 'No'
    break
  end
end
puts ans

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

int main(){
  int n;
  cin >> n;
  vector<vector<int>> v(3, vector<int>(n));
  rep(i,n) cin >> v[0][i] >> v[1][i] >> v[2][i];
  vector<int> dp(3, 0);
  for (int i = 0; i < n; i++) {
    vector<int> dp2(3, 0);
    for (int j = 0; j < 3; j++) {
      dp2[j] = max(dp[(j + 1) % 3], dp[(j + 2) % 3]) + v[j][i];
    }
    dp = dp2;
  }
  int res = 0;
  rep(i, 3) res = max(dp[i], res);
  cout << res << endl;
}

Measured memory_bytes: 1792
#include <iostream>

using namespace std;

int getNext(int n,int m,int maxrank){
  int max;
  int min = 0;
  int nums[6];
  int insmaxrank = maxrank;
  int minrank = 1;
  int num;
  max = n;
  for(int i=0;i<m;i++){
    nums[i] = max % 10;
    max /= 10;
  }

  max = 0;
  for(int i=0;i<m;i++){
    int insmax = 0;
    int index;
    for(int j=0;j<m;j++){
      if(insmax < nums[j]){
        insmax = nums[j];
        index = j;
      }
    }
    nums[index] = 0;
    max += insmax*insmaxrank;
    insmaxrank /= 10;
  }
  num = max;
  for(int i=0;i<m;i++){
    min += (num%10)*maxrank;
    maxrank /= 10;
    minrank *= 10;
    num /= 10;
  }
  return max - min;
}

int getAns(int ans[],int n){
  for(int i=0;i<20;i++){
    if(ans[i] == n) return i;
  }
  return -1;
}

int main(){
  int n,m;
  cin >> n >> m;
  do{
    int ans[20];
    for(int i=0;i<20;i++) ans[i] = -1;
    int maxrank = 1;
    int next = n;
    int count=0;
    for(int i=0;i<m-1;i++) maxrank *= 10;
    while(getAns(ans,next) == -1){
      if(count < 20) ans[count] = next;
      next = getNext(next,m,maxrank);
      count++;
    }
    cout << getAns(ans,next) << " " << next << " " << count - getAns(ans,next) << endl;
    cin >> n >> m;
  }while(n != m && m != 0);
}

Measured memory_bytes: 1160
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<math.h>
#define FOR(n) for(int i=0;i<n;i++)
#define FORJ(n) for(int j=0;j<n;j++)
#define PRN(n) printf("%d\n",n)
#define PRF(n) printf("%lf\n",n)
#define PRL(n) printf("%lld\n",n)
#define PRS(s) printf("%s\n",s)
#define PRC(c) printf("%c",c)
#define mod 1000000007
typedef long long int ll;
ll dp[100001];
int u(const void *a, const void *b){
    return *(ll*)a-*(ll*)b;
}
int d(const void *a, const void *b){
    return *(ll*)b-*(ll*)a;
}
int min(int a,int b){
  if(a>b)return b;
  return a;
}
int max(int a,int b){
  if(a>b)return a;
  return b;
}
int gcd(int a,int b){
  if(!b)return a;
  return gcd(b,a%b);
}
int main(void) {
  int n,ans;
  scanf("%d",&n);
  int a[n];
  FOR(n)scanf("%d",&a[i]);
  qsort(a,n,sizeof(int),d);
  FOR(n)if(a[i]>i)ans=i+1;
  PRN(ans);
  return 0;
}


Measured memory_bytes: 2140
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define REP(i,n) for(int i=0;i<n;++i)
#define REP1(i,n) for(int i=1;i<=n;++i)
#define SZ(i) int(i.size())
#ifdef tmd
#define IOS()
#define debug(...) fprintf(stderr,"#%d: %s = ",__LINE__,#__VA_ARGS__),_do(__VA_ARGS__);
template<typename T> void _do(T &&x){cerr<<x<<endl;}
template<typename T, typename ...S> void _do(T &&x, S &&...y){cerr<<x<<", ";_do(y...);}
template<typename It> ostream& _printRng(ostream &os,It bg,It ed)
{
    os<<"{";
    for(It it=bg;it!=ed;it++) {
        os<<(it==bg?"":",")<<*it;
    }
    os<<"}";
    return os;
}
template<typename T> ostream &operator << (ostream &os,vector<T> &v){return _printRng(os,v.begin(), v.end());}
template<typename T> void pary(T bg, T ed){_printRng(cerr,bg,ed);cerr<<endl;}
#else
#define IOS() ios_base::sync_with_stdio(0);cin.tie(0);
#define endl '\n'
#define debug(...)
#define pary(...)
#endif


const ll MOD = 1000000007;
const ll INF = 0x3f3f3f3f3f3f3f3f;
const int MAXN = 81;
bool dp[MAXN][MAXN][MAXN*MAXN*4];
const int hf = MAXN*MAXN*2;

int h, w, a[MAXN][MAXN], b[MAXN][MAXN];

/*********************GoodLuck***********************/
int main () {
    IOS();
    cin >> h >> w;
    REP (i, h) {
        REP (j, w) {
            cin >> a[i][j];
        }
    }
    REP (i, h) {
        REP (j, w) {
            cin >> b[i][j];
        }
    }

    dp[0][0][hf+a[0][0]-b[0][0]] = true;
    REP (i, h) {
        REP (j, w) {
            REP (u, 2) {
                swap(a[i][j], b[i][j]);
                int cur = a[i][j] - b[i][j];
                for (int k=0;k<MAXN*MAXN*4;k++) {
                    if (k-cur<0 || k-cur >= MAXN*MAXN*4) {
                        continue;
                    }
                    if (i > 0) {
                        dp[i][j][k] |= dp[i-1][j][k-cur];
                    }
                    if (j > 0) {
                        dp[i][j][k] |= dp[i][j-1][k-cur];
                    }
                }
            }
        }
    }

    int ans = 0x3f3f3f3f;
    REP (i, MAXN*MAXN*4) {
        if (dp[h-1][w-1][i]) {
            ans = min(ans, abs(i-hf));
        }
    }

    cout << ans << endl;
}


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

typedef long long int ll;

int main(){
    int d,n;
    scanf("%d %d",&d,&n);
    if(n==100) n++;
    if(d==0) printf("%d\n",n);
    else if(d==1) printf("%d\n",n*100);
    else printf("%d\n",n*100*100);
    return 0;
}


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

using namespace std;

#define loop(i, n) for(int i = 0;i < int(n);i++)
#define rloop(i, n) for(int i = int(n);i >= 0;i--)
#define range(i, a, b) for(int i = int(a);i <= int(b);i++)
#define SZ(c) int(c.size())
#define ALL(c) c.begin(), c.end()
#define RALL(c) c.rbegin(), c.rend()
#define PI acos(-1)
#define pb push_back
#define mp make_pair
#define fr first
#define sc second
#define sfi1(v) scanf("%d",&v)
#define sfi2(v1, v2) scanf("%d %d",&v1,&v2)
#define sfi3(v1, v2, v3) scanf("%d %d %d",&v1,&v2,&v3)
#define sfll1(v) scanf("%I64d",&v);
#define sfll2(v1, v2) scanf("%I64d %I64d",&v1,&v2)
#define sfll3(v1, v2, v3) scanf("%I64d %I64d %I64d",&v1,&v2,&v3)
#define endl '\n'

typedef vector<int> vi;
typedef vector<pair<int, int> > vii;
typedef long long ll;
typedef pair<int, int> pii;

const int N = 2505;
const int M = N * 3;
int at[N], vis[N], t;
bool can[N];
ll dp[N][M];
ll c[N];
vii adj[N];
vi radj[N];
int n, m, p;

ll solve(int u, int len) {
    if (len == 0 && u == n)return 0;
    if (len == 0)return -1e15;
    ll &ret = dp[u][len];
    if (~ret)return ret;
    ret = -1e15;
    for (auto nxt : adj[u]) {
        ret = max(ret, solve(nxt.fr, len - 1) + nxt.sc);
    }
    return ret;
}

void dfs(int u) {
    if (can[u])return;
    can[u] = true;
    for (int nxt : radj[u]) {
        dfs(nxt);
    }
}

void cycle(int u, ll sum, int lvl) {
    c[u] = sum;
    at[u] = lvl;
    vis[u] = 1;

    for (auto nxt : adj[u]) {
        if (vis[nxt.fr] == 1) {
            int len = lvl - at[nxt.fr] + 1;
            ll total = sum - c[nxt.fr] + nxt.sc;
            if (total - 1LL * len * p > 0 && can[u]) {
                cout << -1 << endl;
                exit(0);
            }
        } else if (vis[nxt.fr] == 0) {
            cycle(nxt.fr, sum + nxt.sc, lvl + 1);
        }
    }

    vis[u] = 2;
}

int main() {

#ifndef ONLINE_JUDGE
    //freopen("in.in", "r", stdin);
    //freopen("out.in", "w", stdout);
#endif
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    int a, b, c;
    memset(dp, -1, sizeof dp);
    cin >> n >> m >> p;
    loop(i, m) {
        cin >> a >> b >> c;
        adj[a].pb({b, c});
        radj[b].pb(a);
    }

    dfs(n);

    long long mx = 0;
    range(i, 1, n - 1) {
        mx = max(mx, solve(1, i) - 1LL * p * i);
    }

    range(i, n, n + n + n) {
        if (solve(1, i) - 1LL * p * i > mx) {
            cout << -1 << endl;
            return 0;
        }
    }

    cycle(1, 0, 0);

    cout << mx << endl;

    return 0;
}

Measured memory_bytes: 147840