akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>

using namespace std;

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
  
    int n;
    string s;
    cin >> n >> s;
    
    vector<vector<int>> colours(2); //0: R, 1: G
    set<int> blue;
    for (int i = 0; i < n; i++) {
        if (s[i] == 'R') colours[0].push_back(i);
        else if (s[i] == 'G') colours[1].push_back(i);
        else blue.insert(i);
    }
    
    long long cnt = 0;
    for (int i = 0; i < (int) colours[0].size(); i++) {
        for (int j = 0; (int) j < colours[1].size(); j++) {
            int larger = max(colours[0][i], colours[1][j]);
            int smaller = min(colours[0][i], colours[1][j]);
            int diff = larger - smaller;
            if (blue.count(larger + diff)) cnt--;
            if (blue.count(smaller - diff)) cnt--;
            if (diff % 2 == 0 && blue.count(smaller + diff / 2)) cnt--;
            cnt += blue.size();
        }
    }
    cout << cnt << endl;
    return 0;
}


Measured memory_bytes: 3716
from sys import stdin
input = stdin.readline

n = int(input())
nums = []
for _ in range(n):
    a, b = map(int, input().split())
    nums.append([b+a, a, b])
nums.sort(reverse = True)

if n % 2 == 1:
    nums.append([0, 0, 0])
    
A = 0
B = 0
for i in range(0, n, 2):
    A += nums[i][1]
    B += nums[i+1][2]
    
print(A - B)

Measured memory_bytes: 24868
// template version 1.14
using namespace std;
#include <bits/stdc++.h>

// varibable settings
#define int long long
const int INF=1e18;
const int MOD=1e9+7;

// define basic macro {{{
#define _overload3(_1,_2,_3,name,...) name
#define _rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(int i=(int)(a);i<(int)(b);++i)
#define rep(...) _overload3(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)
#define _rrep(i,n) rrepi(i,0,n)
#define rrepi(i,a,b) for(int i=(int)((b)-1);i>=(int)(a);--i)
#define rrep(...) _overload3(__VA_ARGS__,rrepi,_rrep,)(__VA_ARGS__)
#define each(i,a) for (auto&& i : a)
#define all(x) (x).begin(),(x).end()
#define sz(x) ((int)(x).size())
#define pb(a) push_back(a)
#define mp(a, b) make_pair(a, b)
#define mt(a, b, c) make_tuple(a, b, c)
#define ceil(a,b) ((a)+(b)-1)/(b)
#define is_in(x, a, b) ((a)<=(x) && (x)<(b))
#define uni(x) sort(all(x));x.erase(unique(all(x)),x.end())
#define ub upper_bound
#define lb lower_bound
#define posl(A, x) (lower_bound(all(A), x)-A.begin())
#define posu(A, x) (upper_bound(all(A),x)-A.begin())
template<class T> inline void chmax(T &a, const T &b) { if((a) < (b)) (a) = (b); }
template<class T> inline void chmin(T &a, const T &b) { if((a) > (b)) (a) = (b); }

typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef long double ld;
typedef pair<int,int> pii;
typedef tuple<int,int,int> iii;

template<typename T> using PQ = priority_queue<T, vector<T>, greater<T>>;
struct Fast { Fast(){ std::cin.tie(0); ios::sync_with_stdio(false); } } fast;

#if defined(PCM) || defined(LOCAL)
  #include "lib/dump.hpp"
#else
  #define dump(...) 42
  #define dump_1d(...) 42
  #define dump_2d(...) 42
#endif
//}}}

signed main() {
  int n,a,b;cin>>n>>a>>b;
  if (a>b) swap(a,b);
  int d = abs(a-b);
  if (d%2==0){
    cout << d/2 << endl;
  }
  else{
    int x = a + ((b-a)-1)/2;
    swap(a, b);
    int y = (n-b+1) + (n-(a+n-b+1))/2;
    cout << min(x,y) << endl;
  }
  return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
#include<stdlib.h>
int comp(const void *a,const void *b){
    int c=*(int *)a;
    int d=*(int *)b;
    if(c<d) return -1;
    else return 1;
}
int main(void){
    while(1){
        int n; int array[100]={0};
        scanf("%d",&n);
        if(n==0) break;
        for(int i=0;i<n;i++) scanf("%d",&array[i]);
        qsort(array,n,sizeof(int),comp);
        //for(int i=0;i<n;i++) printf("%d ",array[i]); puts("");
        int sum=0;
        for(int i=1;i<n-1;i++) sum+=array[i];
        printf("%d\n",sum/(n-2));
    }
}



Measured memory_bytes: 2048
#include<stdio.h>
int main()
{
int W,H,x,y,r;
scanf("%d %d %d %d %d",&W,&H,&x,&y,&r);
if(W-r>=x&&H-r>=y&&r<=x&&r<=y)
{
printf("Yes\n");
}
else
{
printf("No\n");
}
return 0;
}

Measured memory_bytes: 1012
#define FOR(i, begin, end) for(int i=(begin);i<(end);i++)
#define REP(i, n) FOR(i,0,n)
#define SORT(a) sort(a.begin(), a.end())
#define SORTD(a) sort(a.rbegin(), a.rend());
#define UNIQUE(a) unique(a.begin(), a.end())
#define ll long long
#define INF 1000000000000000000
#define INT_MAX 2147483647

#include <iostream>
#include <string>
#include <vector>
#include <cmath>
#include <cctype>
#include <numeric>
#include <algorithm>
#include <queue>
#include <set>
#include <utility>
#include <ios>
#include <iomanip>
#include <sstream>
#include <map>

using namespace std;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using vi = vector<int>;
using vl = vector<ll>;

const ll mod = 1e9+7;

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

	if (k > ( n * (n - 1) / 2 - (n - 1) ) ) {
		cout << "-1" << endl;
	}
	else {
		vector<pii> e;
		FOR(i, 2, n+1) {
			e.push_back(make_pair(1, i));
		}

		int r = n * (n - 1) / 2 - (n - 1) - k;

		FOR(i, 2, n + 1) {
			FOR(j, i+1, n + 1) {
				if (r != 0) {
					e.push_back(make_pair(i, j));
					r--;
				}
				else {
					break;
				}
			}
			if (r == 0) {
				break;
			}
		}
		cout << e.size() << endl;
		REP(i, e.size()) {
			cout << e[i].first << " " << e[i].second << endl;
		}
	}
}

Measured memory_bytes: 384
while True:
    n=int(input())
    s=1
    if n==0:
        break
    else:
        for i in range(n):
            s*=(i+1)
    
    t=0
    while True:
        if s%10!=0:
            break
        else:
            s=s//10
            t+=1
    print(t)


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

int main(){
    int n;
    cin >> n;
    vector<int> s(n);
    for (int i = 0; i < n; i++) {
        int t;
        cin >> t;
        s[t - 1] = i;
    }
    int res = 0, cnt = 0;
    for (int i = 0; i < n; i++) {
        cnt = i == 0 ? 1 : s[i] > s[i - 1] ? cnt + 1 : 1;
        res = max(res, cnt);
    }
    cout << n - res << endl;

}


Measured memory_bytes: 1024
import bisect
import sys
import math
from collections import deque
from heapq import heappush, heappop

def sRaw():
    return input().rstrip("\r")


def iRaw():
    return int(input())


def ssRaw():
    return input().split()


def isRaw():
    return list(map(int, ssRaw()))


INF = 1 << 29

DIV = (10**9) + 7
#DIV = 998244353

def mod_inv_prime(a, mod=DIV):
    return pow(a, mod-2, mod)


def mod_inv(a, b):
    r = a
    w = b
    u = 1
    v = 0
    while w != 0:
        t = r//w
        r -= t*w
        r, w = w, r
        u -= t*v
        u, v = v, u
    return (u % b+b) % b


def CONV_TBL(max, mod=DIV):
    fac, finv, inv = [0]*max, [0]*max, [0]*max
    fac[0] = fac[1] = 1
    finv[0] = finv[1] = 1
    inv[1] = 1
    for i in range(2, max):
        fac[i] = fac[i-1]*i % mod
        inv[i] = mod - inv[mod % i] * (mod//i) % mod
        finv[i] = finv[i-1]*inv[i] % mod

    class CONV:
        def __init__(self):
            self.fac = fac
            self.finv = finv
            pass

        def ncr(self, n, k):
            if(n < k):
                return 0
            if(n < 0 or k < 0):
                return 0
            return fac[n]*(finv[k]*finv[n-k] % DIV) % DIV

    return CONV()


def cumsum(As):
    s = 0
    for a in As:
        s += a
        yield s


sys.setrecursionlimit(200005)


def dijkstra(G,start=0):
    heap = []
    cost = [INF]*len(G)
    heappush(heap,(0,start))
    while len(heap)!=0:
        c,n = heappop(heap)
        if cost[n] !=INF:
            continue
        cost[n]=c
        for e in G[n]:
            ec,v = e
            if cost[v]!=INF:
                continue
            heappush(heap,(ec+c,v))
    return cost


def main():
    N =iRaw()
    ans = [0]*(N+1)
    for x in range(1,101):
        for y in range(1,101):
            for z in range(1,101):
                n = x*x+y*y+z*z+x*y+y*z+z*x
                if n<=N:
                    ans[n]+=1
    for i in range(1,N+1):
        print(ans[i])
main()


Measured memory_bytes: 70032
#include <iostream>
#include<math.h>
using namespace std;
long long int kaisuu[100000];
long long int IC[100000];
long long int kippu[100000];
long long int untin[100000];
void func(int p,int u){
	if(p>u){
		for(int j=u-1;j<p-1;j++){kaisuu[j]++;}
	}
	else{
		for(int j=p-1;j<u-1;j++){kaisuu[j]++;}
	}
}
int main() {
int n,m;
cin>>n>>m;
int a,b;
cin>>a>>b;
for(int i=0;i<100000;i++){
	kaisuu[i]=0;
}
func(a,b);
for(int i=2;i<m;i++){
	a=b;
	cin>>b;
	func(a,b);
}
long long int ans=0;
for(int i=0;i<n;i++){
	cin>>kippu[i]>>untin[i]>>IC[i];
}
for(int i=0;i<n;i++){
	ans+=min(kaisuu[i]*kippu[i],(kaisuu[i]*untin[i])+IC[i]);
}
cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 4288
#include <bits/stdc++.h>
#include<algorithm>
#define int long long
using namespace std;
typedef pair<int,int> P;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define INF 1000000000000

int MOD=1000000007;
int modpow(int a,int x){
  if(a<0)a+=MOD;
  int ans=1;
  while(x>0){
    if(x&1) ans=ans*a%MOD;
      a=a*a%MOD;
      x>>=1;
  }
  return ans;
}
int gyaku(int n){
    return modpow(n,MOD-2);
}
signed main() {
  int r,g,b,n;
  cin>>r>>g>>b>>n;
  int ans=0;
  for(int i=0;i<=n;i++){
    for(int j=0;j<=n;j++){
      if(n-r*i-g*j>=0&&(n-r*i-g*j)%b==0){
        ans++;
      }
    }
  }
  cout<<ans<<endl;
}


Measured memory_bytes: 3608
#include <iostream>
#include <vector>


using namespace std;

int main() {
    string str = "";
    cin >> str;
    int len = str.length();
    int flag = 0;
    int yn = 0;

    for(int i = 0; i < len; i++) {
        if (str[i] == 'C') {
            flag = 1;
        }
        if(str[i] == 'F' && flag == 1) {
            yn = 1;
            //cout << "yes" << endl;
            //return 0;
        }
    }

    if(yn == 0)
        cout << "No" << endl;
    else
        cout << "Yes" << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep1(i, n) for (int i = 1; i <= (int)(n); i++)
typedef int64_t Int;
typedef pair<int,int> p;

const int INF = 1e9;

int main() {
  int n;
  string s;
  cin >> n >> s;

  if (n % 2 == 1) cout << "No" << endl;
  else {
    bool flag = true;
    rep(i, n/2) {
      if (s[i] != s[n/2 + i]) flag = false;
    }
    if (flag) cout << "Yes" << endl;
    else cout << "No" << endl;
  }
}


Measured memory_bytes: 256
#pragma comment(linker, "/stack:20000000")
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx")

#include <iostream>
#include <fstream>
#include <string>
#include <algorithm>
#include <vector>
#include <array>

using namespace std;

#define TT1T2 template<class T1, class T2>
TT1T2 void debug_print_array(const T1 &a, T2 sz, T2 beg = 0){ for (T2 i = beg; i<sz; i++) cerr << a[i] << (i + 1 != sz ? "," : ""); cout << endl; }
#define DBN1(a)           cerr<<#a<<"="<<(a)<<"\n"
#define DBN2(a,b)         cerr<<#a<<"="<<(a)<<", "<<#b<<"="<<(b)<<"\n"
#define DBN3(a,b,c)       cerr<<#a<<"="<<(a)<<", "<<#b<<"="<<(b)<<", "<<#c<<"="<<(c)<<"\n"
#define DA(a,n) cerr<<#a<<"=["; debug_print_array(a,n); cerr<<"]\n"
double __begin;
#define DTIME(ccc) __begin = clock(); ccc; cerr<<"Time of work = "<<(clock()-__begin)/CLOCKS_PER_SEC<<endl;
using ll = long long;
using ld = long double;
using ull = unsigned long long;
template <typename T, const int N> using Graph = vector <T> [N];

const int MAXN = 2e5 + 1234;
array <int, MAXN> ar;

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.precision(20);
#ifdef LOCAL
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#endif

    int n;
    cin >> n;


    for (int i = 0; i < 2 * n; i++) {
        cin >> ar.at(i);
    }

    sort(ar.begin(), ar.begin() + 2 * n);

    int sum = 0;
    for (int i = 0; i < 2 * n; i += 2) {
        sum += ar.at(i);
    }

    cout << sum << endl;

    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int main(){
  string a, b, c, ans;
  char x = 'A' - 'a';
    cin >> a >> b >> c;
    printf("%c%c%c\n", a[0]+x, b[0]+x, c[0]+x);
}

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

typedef long long ll;
//const int INF = 2e9;
//const ll INF = 9e18;


int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    int K, T;
    cin >> K >> T;
    vector<int> a(T);
    for (int i=0;i<T;i++) cin >> a[i];
    sort(a.rbegin(),a.rend());
    int ans = max(a[0] - 1 - (K - a[0]), 0);
    cout << ans << "\n";
}

Measured memory_bytes: 256
/* 
 * Project: AtCoder Beginners Contest 168 C - : (Colon)
 * Author: toms74209200 <https://github.com/toms74209200>
 *
 * Created on 2020/05/17
 * Copyright (c) 2020 toms74209200
 * 
 * This software is released under the MIT License.
 * http://opensource.org/licenses/mit-license.php
 */
#include <iostream>
#include <numeric>
#include <cstdio>
#include <cmath>
#include <iomanip>
#include <limits>
#include <cstring>
using namespace std;

int a, b, h, m;

long double deg_a, deg_b, deg_c;

long double get_deg_c(int ta, int tb) {
    return M_PI * (60 * ta - 11 * tb) / 360;
}

long double get_c(int a, int b, double deg_c) {
    return sqrtl(a*a + b*b - 2 * a * b * cosl(deg_c) );
}

void solve() {

    long double c = 0;
    long double deg_c = get_deg_c(h, m);
    c = get_c(a, b, deg_c); 
    cout << fixed << setprecision(9) << c << endl;
    return;

}

int main() {

    scanf("%d", &a);
    scanf("%d", &b);
    scanf("%d", &h);
    scanf("%d", &m);

    solve();
}

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

int main() {
	int A, B, count{ 0 };
	cin >> A >> B;
	string ss, rs;
	for (int n = A; n <= B; ++n) {
		ss = to_string(n);
		reverse(ss.begin(), ss.end());
		if (to_string(n) == ss) {
			++count;
		}
	}
	cout << count;
}

Measured memory_bytes: 256
#include<stdio.h>
#define AMAX 2000
#define MMAX 2000
int main(){
  int i,j,n,q,num,sequence[MMAX+1]={0};
  scanf("%d",&n);
  for(i=0;i<n;i++){
    scanf("%d",&num);
    for(j=MMAX-num;0<j;j--){
      if(sequence[j]){
        sequence[j+num]= 1;
      }
    }
    sequence[num]=1;
  }
  scanf("%d",&q);
  for(i=0;i<q;i++){
    scanf("%d",&num);
    if(sequence[num]){
      printf("yes\n");
    }
    else printf("no\n");
  }
  return 0;
}



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

using namespace std;

#define LOG(...) fprintf(stderr,__VA_ARGS__)
//#define LOG(...)
#define FOR(i,a,b) for(int i=(int)(a);i<(int)(b);++i)
#define RFOR(i,a,b) for(int i=(int)(b-1);i>=(int)(a);--i)
#define REP(i,n) for(int i=0;i<(int)(n);++i)
#define RREP(i,n) for(int i=(int)(n-1);i>=0;--i)
#define ALL(a) (a).begin(),(a).end()
#define RALL(a) (a).rbegin(),(a).rend()
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort(ALL(c))
#define RSORT(c) sort(RALL(c))
#define SZ(a) ((int)(a).size())
#define BIT(x, i) (((x) >> (i)) & 1)
#define SQ(x) ((x)*(x))

typedef long long ll;
typedef unsigned long long ull;
typedef vector<bool> vb;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<vb> vvb;
typedef vector<vi> vvi;
typedef vector<vll> vvll;
typedef vector<char> vc;
typedef vector<vc> vvc;
typedef vector<string> vs;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;

int main() {
    int x, y, s;
    while (cin >> x >> y >> s, x|y|s) {
        int ma = 0;
        FOR(a, 1, 1000) {
            FOR(b, 1, 1000) {
                if (floor(a*(100+x)/100.0) + floor(b*(100+x)/100.0) == s) {
                    ma = max(ma, (int)(floor(a*(100+y)/100.0) + floor(b*(100+y)/100.0)));
                }
            }
        }
        cout << ma << endl;
    }
}

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

using namespace std;

int main(void){
  long long N;
  long long ind;
  long long A[200010];
  for(int i=0;i<200010;i++){
    A[i]=0;
  }
  cin >> N;
  for(long long i=2;i<=N;i++){
    scanf("%lld",&ind);
    A[ind]++;
  }
  for(int i=1;i<=N;i++){
    printf("%lld\n",A[i]);
  }
  return 0;
}

Measured memory_bytes: 5376
#include <bits/stdc++.h>
using namespace std;
typedef long long lint;

const lint INF = 1e15;

lint dsum(lint a, lint b){
    lint res = 0;
    while(a){res += a % b; a /= b;}
    return res;
}

int main(){
    lint n, s; cin >> n >> s;
    
    if(n == s) {cout << n + 1 << endl; return 0;}
    if(n < s) {cout << -1 << endl; return 0;}

    for(lint i=2;i*i<=n;i++) if(dsum(n, i) == s) {cout << i << endl; return 0;}

    lint ans = INF, v;
    for(lint i=1;i*i<=n-s;i++){
        if((n-s) % i == 0){
            if(v = dsum(n, (n-s)/i+1) == s) ans = min(ans, (n-s)/i+1);
            if(v = dsum(n, i+1) == s) ans = min(ans, i+1);
        }
    }

    if(ans == INF) cout << -1 << endl;
    else cout << ans << endl;
    return 0;
}

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

int num;
vector < int > s;

int solve(){
    int mr=0,ans=0;
    for(int i=1;i<=num;++i){
        if(s[i]>mr){
            mr=i;
            ans+=1;
        }else{
            ;
        }
    }
    return ans;
}

void _solve(){
    cout<<solve()<<endl;
}

void _prepare(){
    int n;
    cin>>num>>n;
    s.resize(num+1,0);
    for(int i=0;i<n;++i){
        int l,r;cin>>l>>r;r-=1;
        if(l>s[r])s[r]=l;
    }
}

int _main_prog(){
    ios::sync_with_stdio(0);
    _prepare();
    _solve();
    return 0;
}

int main(){
    #define uSe_FiLE9
    #ifdef uSe_FiLE
    freopen("task.in","r",stdin);
    freoepn("task.out","w",stdout);
    int r=_main_prog();
    fclose(stdin);fclose(stdout);
    return r;
    #else
    return _main_prog();
    #endif
}



Measured memory_bytes: 640
#include <iostream>
#include <vector>
#include <string>

using namespace std;


int main() {
	int h, w;
	cin >> h >> w;

	vector<string> data(h);


	for (int i = 0; i < h; i++) {
			cin >> data[i];		
	}


	vector<bool> row(h, false);
	vector<bool> col(w, false);

	for (int i = 0; i < h; i++) {
		for (int j = 0; j < w; j++) {
			if (data[i][j] == '#') {
				row[i] = true;
				col[j] = true;
			}
		}
	}


	for (int i = 0; i < h; i++) {
		if (row[i]) {
			for (int j = 0; j < w; j++) {
				if (col[j]) {
					cout << data[i][j];
				}
			}
		}

		cout << endl;
	}
}

Measured memory_bytes: 256
n = gets.chomp.to_i
a_arr = gets.chomp.split(" ").map(&:to_i)

count = []
a_arr.each do |a|
  count[a] = count[a].to_i + 1
end

1.step(n, 1) do |i|
  if count[i].nil?
    puts '0'
  else
    puts count[i]
  end
end


Measured memory_bytes: 35776
import scala.io.StdIn.{readLine,readInt}
import scala.collection.mutable.ArrayBuffer

case class Dice(var d:Array[String]) {
  private val s = Array(4,0,2,3,5,1)
  private val w = Array(2,1,5,0,4,3)
  private val h = Array(0,2,4,1,3,5)
  private val all = Array.ofDim[Array[String]](24)

  def rotateAll() = {
    all(0) = d
    all(1) = s.map(d)
    all(2) = s.map(all(1))
    all(3) = s.map(all(2))
    all(4) = w.map(d)
    all(5) = w.map(w).map(all(4))
    (0 to 17).foreach { s => all(s+6) = h.map(all(s)) }
  }

  def getAll = all

  override def toString() = d(0)
}

object Main extends App {
  val faces = readLine.split(" ")
  val n = readInt
  val dice = Dice(faces)

  dice.rotateAll()
  (0 until n).foreach { s =>
    val l =  readLine.split(" ")
    println(dice.getAll.find(t => t(0) == l(0) && t(1) == l(1)).get(2))
  }
}

Measured memory_bytes: 44108
#include<bits/stdc++.h>
using namespace std;
int main(){
    int a,b,c;
    cin>>a>>b>>c;
    if(a>=b&&a>=c&&b>=c)cout<<a*10+b+c;
    else if(a>=b&&a>=c&&c>=b)cout<<a*10+b+c;
    else if(b>=a&&b>=c&&a>=c)cout<<b*10+a+c;
    else if(b>=a&&b>=c&&c>=a)cout<<b*10+a+c;
    else if(c>=b&&c>=a&&a>=b)cout<<c*10+b+a;
    else if(c>=b&&c>=a&&b>=a)cout<<c*10+b+a;
return 0;
}


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

int main()
{
    int k;
    cin >> k;
    int x = 7 % k;
    for (int i = 1; i < 1000005; i++)
    {
        if (x == 0)
        {
            cout << i << endl;
            return 0;
        }
        x = (x * 10 + 7) % k;
    }
    cout << -1 << endl;
}

Measured memory_bytes: 3600
#include<iostream>
#include<string>
using namespace std;
string s;
int main()
{
	cin>>s;
	for(int i=0;i<s.size();i++)
	{
		if(s[i]=='C')
		{
			for(int j=i+1;j<s.size();j++)
			{
				if(s[j]=='F')
				{
					cout<<"Yes";return 0;
				}
			}
		}
	}
	cout<<"No";
	return 0;
}

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



int main(){
	int n; cin >> n;
	vector<ll> A(n + 1, 0), greedy(n + 1, 0), dp(n + 1, 0);
	
	for(int i = 1; i <= n; i ++) cin >> A[i];
	greedy[1] = A[1];
	for(int i = 3; i <= n; i += 2){
		greedy[i] = greedy[i - 2] + A[i];
	}
	for(int i = 2; i <= n; i ++){
		if(i & 1){
			dp[i] = max(dp[i - 1], dp[i - 2] + A[i]);
		}
		else{
			dp[i] = max(dp[i - 2] + A[i], greedy[i - 1]);
		}
	}
	cout << dp[n] << endl;
}

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

int main() {
  
  int N;
  cin >> N;
  for (int i = 0; i < N; i++){
    string s;
    cin >> s;
  if(i < N-1 && s != "Y")
    continue;
    else if(s == "Y"){
      cout << "Four" <<endl;
      break;
    }
    else
      cout << "Three" <<endl;
  }
}

Measured memory_bytes: 256
import sys
from bisect import *
from heapq import *
from collections import *
from itertools import *
from functools import *
from math import *
from fractions import *

sys.setrecursionlimit(100000000)
input = lambda: sys.stdin.readline().rstrip()

def main():
    N = int(input())
    while len(Counter(str(N))) != 1:
        N += 1
    print(N)


main()


Measured memory_bytes: 64108
#include <stdio.h>
#include <stdlib.h>
int right=0;
int threaten(int first_x,int second_x,int first_y,int second_y)
{
    if(first_x+second_x==first_y+second_y||first_x-second_x==first_y-second_y||first_x==first_y||second_x==second_y)
    {
        return 1;
    }else
        return 0;
}

int queen(int n,int array[8][8],int a,int b)
{
    int i,j,k;
    if(n==0)
    {
        right=1;
        print(array);
        return 0;
    }
    if(a==8)
        return 0;
    if (array[a][b]!=0)
    {
        if (b==7)
            return queen(n,array,a+1,0);
        else
            return queen(n,array,a,b+1);
    }
    if(right==0)
    {
        for (i=0;i<8;i++)
        {
            for (j=0;j<8;j++)
            {
                if(array[i][j]==1&&threaten(a,b,i,j)==1)
                {
                    if (b==7)
                        return queen(n,array,a+1,0);
                    else
                        return queen(n,array,a,b+1);
                }
            }
        }
        array[a][b]=1;
        if (b==7)
            queen(n-1,array,a+1,0);
        else
            queen(n-1,array,a,b+1);
        array[a][b]=0;
        if (b==7)
            queen(n,array,a+1,0);
        else
            queen(n,array,a,b+1);

    }
    return 0;
}
int print(int array[8][8])
{
    int i,j;
    for (i=0;i<8;i++)
    {
        for (j=0;j<8;j++)
        {
            if(array[i][j]==1)
                printf("Q");
            else
                printf(".");
        }
        printf("\n");
    }
}
int main()
{
    int array[8][8];
    int i,j;
    for (i=0;i<8;i++)
    {
        for (j=0;j<8;j++)
        {
            array[i][j]=0;
        }
    }
    int k;
    scanf("%d",&k);
    int a,b;
    for (i=0;i<k;i++)
    {
        scanf("%d %d",&a,&b);
        array[a][b]=1;
    }
    queen(8-k,array,0,0);
}

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

ll gcf(ll a, ll b){
    if(b == 0) return a;
    return gcf(b,a%b);
}

int main(){
    int N,M; cin >> N >> M;
    vector<int> X(M,0); for(int i = 0; i < M; i++) cin >> X.at(i);
    
    sort(X.begin(),X.end());
    vector<ll> dis(M-1,0); for(int i = 0; i < M-1; i++) dis.at(i) = X[i+1]-X[i];
    sort(dis.begin(),dis.end());
    
    ll ans = 0;
    for(int i = 0; i < M - N; i++){
        ans += dis.at(i);
    }
    cout << ans << endl;
}



Measured memory_bytes: 1408
n = int(input())
x = range(n)
P =[]
n = 0
for _ in x:P += [[int(i) for i in input().split()]]
P+=[P[0]]
for j in x:n += P[j][0]*P[j+1][1] - P[j][1]*P[j+1][0]
print(n*0.5)

Measured memory_bytes: 7728
import sys
sys.setrecursionlimit(10**6) #再帰関数の上限
import math
from copy import copy, deepcopy
from operator import itemgetter

from bisect import bisect_left, bisect, bisect_right#2分探索
#bisect_left(l,x), bisect(l,x)#aはソート済みである必要あり。aの中からx未満の要素数を返す。rightだと以下
from collections import deque 
#deque(l), pop(), append(x), popleft(), appendleft(x)
##listでqueの代用をするとO(N)の計算量がかかってしまうので注意
#dequeを使うときはpython3を使う、pypyはダメ
from collections import Counter#文字列を個数カウント辞書に、
#S=Counter(l),S.most_common(x),S.keys(),S.values(),S.items()
from itertools import accumulate#累積和
#list(accumulate(l))
from heapq import heapify,heappop,heappush
#heapify(q),heappush(q,a),heappop(q) #q=heapify(q)としないこと、返り値はNone

def input(): return sys.stdin.readline()[:-1]
def printl(li): print(*li, sep="\n")
def argsort(s, return_sorted=False): 
    inds=sorted(range(len(s)), key=lambda k: s[k])
    if return_sorted: return inds, [s[i] for i in inds]
    return inds

#mod = 10**9+7
#w.sort(key=itemgetter(1),reversed=True)  #二個目の要素で降順並び替え

#N = int(input())
N, S = map(int, input().split())
#L = [int(input()) for i in range(N)]
A = list(map(int, input().split()))
#S = [list(map(int, input().split())) for i in range(N)]
mod=998244353

ans=0
dp=[0]*(S+1)
for a in A:
    dp[0]+=1
    for i in reversed(range(a,S+1)):
        dp[i]+=dp[i-a]
        dp[i]%=mod
    ans+=dp[-1]
    ans%=mod
    #print(dp)

print(ans)


Measured memory_bytes: 75152
#include<bits/stdc++.h>
using namespace std;
using ll=long long;
using ld=long double;
using P=pair<ll,ll>;
#define MOD 1000000007ll
#define INF 1000000000ll
#define EPS 1e-10
#define FOR(i,n,m) for(ll i=n;i<(ll)m;i++)
#define REP(i,n) FOR(i,0,n)
#define DUMP(a) REP(d,a.size()){cout<<a[d];if(d!=a.size()-1)cout<<" ";else cout<<endl;}
#define ALL(v) v.begin(),v.end()
#define UNIQUE(v) sort(v.begin(),v.end());v.erase(unique(v.begin(),v.end()),v.end());
#define pb push_back

ll n;
vector<string> s;
vector<vector<ll>> g(26);
vector<bool> sorted;

bool dfs(ll k) {
	bool upd=false;
	bool ret=true;
	REP(i,n-1) {
		if(!sorted[i]&&s[i].size()>k&&s[i+1].size()==k) ret=false;
		if(s[i].size()<=k||s[i+1].size()<=k) continue;
		upd=true;
		if(!sorted[i]&&s[i][k]!=s[i+1][k]) {
			sorted[i]=true;
			g[s[i][k]-'a'].pb(s[i+1][k]-'a');
		}
	}
	if(upd) ret=ret&dfs(k+1);
	return ret;
}

bool dfs2(ll p, ll par, ll tgt, vector<bool>& used) {
	used[p]=true;
	bool ret=true;
	REP(i,g[p].size()) {
		if(g[p][i]==tgt) return false;
		if(g[p][i]==par) continue;
		if(used[g[p][i]]) continue;
		else ret=ret&dfs2(g[p][i],p,tgt,used);
	}
	return ret;
}

bool is_dag() {
	REP(i,26) {
		if(g[i].empty()) continue;
		sort(ALL(g[i]));
		g[i].erase(unique(ALL(g[i])),g[i].end());
	}
	REP(i,26) {
		vector<bool> used(26,false);
		if(!dfs2(i,-1,i,used)) return false;
	}
	return true;
}

string solve() {
	s.assign(n,"");
	g.assign(26,vector<ll>(0));
	sorted.assign(n-1,false);
	REP(i,n) cin>>s[i];
	if(!dfs(0)) return "no";
	if(is_dag()) return "yes";
	else return "no";
}

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	while(1) {
		cin>>n;
		if(n==0) break;
		cout<<solve()<<endl;
	}
}



Measured memory_bytes: 3112
using System;
using System.Linq;//リストの使用
using System.Collections.Generic;
using System.Text;//テキストの高速出力に必要
class Program
{
	static void Main()
	{
		string s = Console.ReadLine();
    int n = s.Length;
    int d = int.Parse(Console.ReadLine());
		long mod = 1000000007;
    long[,,] dp = new long[n+1,d,2];//見た桁、余り、他の数字を使用済みかどうか
    dp[0,0,0] = 1;

    for(int i = 1; i <= n; i++)
    {
      for(int j = 0; j < d; j++)
      {
        for(int k = 0; k <= 9; k++)
        {
          if(k == s[i-1]-'0')
          {
            dp[i,(j+k)%d,0] += dp[i-1,j,0];
            dp[i,(j+k)%d,0] %= mod;
          }else if(k < s[i-1]-'0')
          {
            dp[i,(j+k)%d,1] += dp[i-1,j,0];
            dp[i,(j+k)%d,1] %= mod;
          }

          dp[i,(j+k)%d,1] += dp[i-1,j,1];
          dp[i,(j+k)%d,1] %= mod;
        }
        //Console.WriteLine(i+" "+j+" "+dp[i,j,0]+" "+dp[i,j,1]);
      }
    }

    long answer = (dp[n,0,0]+dp[n,0,1]+mod-1)%mod;
		Console.WriteLine(answer);
	}
}

Measured memory_bytes: 26592
#include <iostream>
#include <iomanip>
#include <stdio.h>
#include <set>
#include <vector>
#include <map>
#include <cmath>
#include <algorithm>
#include <memory.h>
#include <string>
#include <sstream>
#include <cstdlib>
#include <ctime>
#include <cassert>

using namespace std;

typedef long long LL;
typedef pair<int,int> PII;

typedef pair<int,PII> PIII;

#define MP make_pair
#define PB push_back
#define FF first
#define SS second

#define FORN(i, n) for (int i = 0; i <  (int)(n); i++)
#define FOR1(i, n) for (int i = 1; i <= (int)(n); i++)
#define FORD(i, n) for (int i = (int)(n) - 1; i >= 0; i--)

#define DEBUG(X) { cout << #X << " = " << (X) << endl; }
#define PR0(A,n) { cout << #A << " = "; FORN(_,n) cout << A[_] << ' '; cout << endl; }

#define MOD 1000000007
#define INF 2000000005

int GLL(LL& x) {
    return scanf("%lld", &x);
}

int GI(int& x) {
    return scanf("%d", &x);
}

const int MAXN = 305;
int sp[MAXN][MAXN], d[MAXN][MAXN];

int n;

vector<PIII> wij;

int main() {
    GI(n);

    FOR1(i, n) {
        FOR1(j, n) {
            GI(sp[i][j]);
        }
    }

    LL res = 0;

    FOR1(i, n) {
        FOR1(j, n) if (i < j) {
            int ikj = INF + 5;

            FOR1(k, n) if (k != i && k != j) {
                ikj = min(ikj, sp[i][k] + sp[k][j]);
            }

            if (ikj < sp[i][j]) {
                printf("-1\n");
                return 0;
            }
            else if (ikj > sp[i][j]) {
                res += sp[i][j];
            }
        }
    }

    cout << res << "\n";

    return 0;
}

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


int main() {
  int n,m;
  cin >> n>>m;
  vector<vector<char>>x(n,vector<char>(n));
  vector<vector<char>>y(m,vector<char>(m));
  rep(i,n){
    string s;
    cin>>s;
    rep(j,n){
      x.at(i).at(j)=s.at(j);
    }
  }
  rep(i,m){
    string s;
    cin>>s;
    rep(j,m){
      y.at(i).at(j)=s.at(j);
    }
  }
  bool ex=false;
  rep(a,n-m+1){
    rep(b,n-m+1){
      bool ch=true;
      rep(i,m){
        rep(j,m){
          if(y.at(i).at(j)!=x.at(a+i).at(b+j)){
            ch=false;
          }
        }
      }
      if(ch){
        ex=true;
      }
    }
  }
  if(ex){
    cout<<"Yes"<<endl;
  }
  else{
    cout<<"No"<<endl;
  }
  
}

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

int main() {
  int K, N;
  cin >> K >> N;
  vector<int> A(N);
  vector<int> d(N);
  rep(i, N) { cin >> A.at(i); }
  int maxd = 0;
  rep(i, N - 1) {
    d.at(i) = A.at(i + 1) - A.at(i);
    maxd = max(maxd, d.at(i));
  }
  maxd = max(A.at(0) + K - A.at(N - 1), maxd);
  cout << K - maxd << endl;

  return 0;
}


Measured memory_bytes: 1792
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define mp make_pair
#define F first
#define S second
//-std=c++11
#define print(x) printf("%.12f",x);
#define sz(x) (int)x.size()
#define all(x) (x).begin(), (x).end()
#define Red ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define rep(i, n) for(int i =0 ; i < n; ++i)
#define repr(i, n) for(int i=n-1;i>=0;i--)
#define Rep(i,a,b) for(int i=a;i<=b;i++)
#define Repr(i,a,b) for(int i=a;i>=b;i--)
#define pii pair < int, int >
#define iter ::iterator
#define forit(a) for(it=a.begin();it!=a.end();it++)
typedef vector<int> vi;
typedef  long long ll;
const int inf = int(1e9);
const int mod = 998244353;
const int N = (int)2e5 + 5;

void solve(){
	int n,a,b;
	cin>>n>>a>>b;
	if(a+b+n>=22)cout<<"bust";
	else cout<<"win";
}


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

Measured memory_bytes: 256
#![allow(unused_macros)]
#![allow(dead_code)]
#![allow(unused_imports)]

use itertools::Itertools;
use proconio::*;
use text_io::*;

const U_INF: usize = 1 << 60;
const I_INF: isize = 1 << 60;

fn main() {
    input! {
        n:usize,
        mut x:usize,
        m:[usize;n],
    }

    x -= m.iter().sum::<usize>();
    let mut ans = n;

    let min = m.iter().min().unwrap();
    ans += x / min;

    println!("{}", ans);
}


Measured memory_bytes: 2184
#pragma optimization_level 3
#pragma GCC optimize("Ofast,no-stack-protector,unroll-loops,fast-math,O3")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
//#pragma GCC target("avx,avx2,fma")
#include<bits/stdc++.h>
#define F first
#define S second
#define vec vector
#define ms multiset
#define pb push_back
#define pll pair<ll,ll>
#define pdd pair<ld, ld>
#define pq priority_queue
#define umap unordered_map
#define uset unordered_set
#define pii pair<int, int>
#define pnn pair<Node*, Node*>
#define uid uniform_int_distribution
#define FILE ifstream in("sumsqr.in");ofstream out("sumsqr.out");
#define fast cin.tie(0);cout.tie(0);cin.sync_with_stdio(0);cout.sync_with_stdio(0);
using namespace std;
typedef string str;
typedef long long ll;
typedef long double ld;
typedef unsigned int uint;
mt19937 rnd(chrono::steady_clock::now().time_since_epoch().count());

int z,i=0;
vec<int> m, o, zp;

void NO(){
    cout<<"No";
    exit(0);
}

void printANS(){
    cout<<"Yes\n";
    for(int u : o) cout<<(char)('A'+u)<<endl;
    exit(0);
}

void medium(){
    int zer = (m[0]==0) + (m[1]==0) + (m[2]==0);
    assert(zer<=1);
    m[0] = min(1, m[0]);
    m[1] = min(1, m[1]);
    m[2] = min(1, m[2]);
    for(; i<z; i++){
        int x = 0, y = 1;
        if(zp[i]==0) x = 2;
        else if(zp[i]==1) y = 2;
        if(m[x] > m[y]) swap(x,y);
        if(m[x]==m[y] && i+1<z && zp[i+1]!=zp[i]) {
            int kyda = 3 - zp[i] - zp[i + 1];
            if (x != kyda) swap(x, y);
            assert(x == kyda);
        }
        o.pb(x);
        m[x]++, m[y]--;
    }
    printANS();
}

int main() {
    fast;
    m = vec<int>(3);
    cin>>z>>m[0]>>m[1]>>m[2];
    zp = vec<int>(z);
    for(int q=0; q<z; q++){
        str t; cin>>t;
        zp[q] = t=="AB" ? 2 : t=="AC" ? 1 : 0;
    }
    int zer = (m[0]==0) + (m[1]==0) + (m[2]==0);
    if(zer<=1) medium();
    for(; i<z; i++){
        zer = (m[0]==0) + (m[1]==0) + (m[2]==0);
        if(zer==1) medium();

        int x = 0, y = 1;
        if(zp[i]==0) x = 2;
        else if(zp[i]==1) y = 2;
        if(m[x] > m[y]) swap(x,y);
        if(m[x]+m[y]==0) NO();
        o.pb(x);
        m[x]++, m[y]--;
    }
    printANS();
}

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

// typedef
//------------------------------------------
typedef pair<int, int> PII;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef vector<PII> VP;

// rep
//------------------------------------------
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, n) FOR(i, 0, n)
#define ALL(x) (x).begin(), (x).end()
#define DEBUG(x) cerr << #x << ": " << x << '\n'

int n;
VI a(20);
VI b(20);
VI c(20);

signed main()
{
    cin >> n;

    REP(i, n){
        cin >> a[i];
    }
    REP(i, n){
        cin >> b[i];
    }
    REP(i, n-1){
        cin >> c[i];
    }

    a.resize(n);
    b.resize(n);
    c.resize(n-1);
    
    int cnt = 0;
    int before = -100;
    REP(i, n){
        int index = a[i] - 1;

        cnt += b[i];
        if (before+1 == index){
            cnt += c[index-1];
        }
        before = index;
    }
    cout << cnt << endl;

    return 0;
}

Measured memory_bytes: 256
#include<algorithm>
#include<iostream>
#include<functional>
#include<cmath>
#include<iomanip>
using namespace std;
int main(){
  string r="CODEFESTIVAL2016";
  string n;
  int count=0;
  cin>>n;
  for(int i=0;i<r.size();i++){
    if(r[i]!=n[i])
      count++;
  }
  cout<<count<<endl;
}

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

#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define rep3(i,m,n) for(int (i)=m;(i)<=(n);(i)++)
#define rep3rev(i,m,n) for(int (i)=m;(i)>=(n);(i)--)
#define all(a) (a.begin()),(a.end())
#define rall(a) (a.rbegin()),(a.rend())
#define fi first
#define se second
#define pb push_back
#define eb emplace_back
#define mp make_pair

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

void Main(){
	int h, w;
	cin >> h >> w;
	vvi a(h, vi(w));
	rep(i,h){
		rep(j,w){
			cin >> a[i][j];
			a[i][j] %= 2;
		}      
	}

	// rep(i,h) rep(j,w) cout << a[i][j] << " ";  
	pii now;
	bool flag = false;
	vi ans;

	rep(i,h){
		if(i%2==0){
			// 左から見る
			rep(j,w){
				if(!flag && a[i][j]==1){
					now = mp(i,j);
					flag = true;
				}else if(flag && a[i][j]==0){
					ans.pb(now.fi);
					ans.pb(now.se);
					ans.pb(i);
					ans.pb(j);
					now = mp(i,j);
				}else if(flag && a[i][j]==1){
					ans.pb(now.fi);
					ans.pb(now.se);
					ans.pb(i);
					ans.pb(j);
					flag = false;   
				}
			}
		}else{
			// 右から見る
			rep3rev(j,w-1,0){
				if(!flag && a[i][j]==1){
					now = mp(i,j);
					flag = true;
				}else if(flag && a[i][j]==0){
					ans.pb(now.fi);
					ans.pb(now.se);
					ans.pb(i);
					ans.pb(j);
					now = mp(i,j);
                }else if(flag && a[i][j]==1){
					ans.pb(now.fi);
					ans.pb(now.se);
					ans.pb(i);
					ans.pb(j);
					flag = false;   
				}				
			}
		}
	}
  
	cout << ans.size()/4 << endl;  
	rep(i,ans.size()){
		cout << ans[i]+1;
		if(i%4!=3) cout << " ";
		else cout << endl;
	}
	return;
}

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

Measured memory_bytes: 5236
from operator import itemgetter

N, K = [int(x) for x in input().split()]
Array = list()
A = list()
count = 0
ans = 0
for i in range(N):
	A.append([int(x) for x in input().split()])

A.sort(key=itemgetter(0))
for i in range(N):
	count += A[i][1]
	if count >= K:
		ans = A[i][0]
		break
		
print(ans)

Measured memory_bytes: 22952
#include <stdio.h>

int n, A[50];

// 入力値のMから選んだ要素を引いていく再帰関数
int solve(int i, int m) {
    if(m==0) return 1;
    if(i>=n) return 0;
    int res = solve(i+1,m) || solve(i+1,m-A[i]);
    return res;
}

int main(void) {
    int q, M, i;

    scanf("%d", &n);
    for(i=0;i<n;i++) scanf("%d",&A[i]);
    scanf("%d",&q);
    for(i=0;i<q;i++) {
        scanf("%d", &M);
        if(solve(0,M)) printf("yes\n");
        else printf("no\n");
    }
    return 0;
}


Measured memory_bytes: 2040
#include <iostream>
#include <algorithm>
#include <string>
typedef long long ll;

using namespace std;

int main(){
    int H, W;
    cin >> H >> W;
    string s[55];
    for (size_t i = 1; i <= H; i++){
	cin >> s[i];
    }
    for (size_t j = 0; j < W; j++){
	s[0][j] = '.';
	s[H+1][j] = '.';
    }

    bool can = true;
    int nx[4] = {1, 0, -1, 0};
    int ny[4] = {0, -1, 0, 1};
    for (size_t i = 1; i <= H; i++){
	for (size_t j = 0; j < W; j++){
	    if (s[i][j] == '#'){
		bool can2 = false;
		if (j == 0){
		    for (size_t k = 0; k < 4; k++){
			if (k == 2) continue;
			if (s[i+ny[k]][j+nx[k]] == '#'){
			    can2 = true;
			}
		    }
		} else if (j == W-1){
		    for (size_t k = 0; k < 4; k++){
			if (k == 0) continue;
			if (s[i+ny[k]][j+nx[k]] == '#'){
			    can2 = true;
			}
		    }
		} else {
		    for (size_t k = 0; k < 4; k++){
			if (s[i+ny[k]][j+nx[k]] == '#'){
			    can2 = true;
			}
		    }
		}

		if (!can2){
		    can = false;
		}
	    }
	}
    }

    if (can) cout << "Yes" << endl;
    else cout<< "No" << endl;

    return 0;
}


Measured memory_bytes: 256
main=do
 s<-getLine
 let c=sum[if i<'a' then if i=='C' then 1 else 2 else 0|i<-tail s]
 putStr$if c/=1||(s!!0)/='A'||(s!!1)<'a'||(last s)<'a' then "WA" else "AC"


Measured memory_bytes: 380
using System;
class ProgramC
    {
        static void Main(string[] args)
        {
            
            string input = Console.ReadLine();
            int n = int.Parse(input);

            
            string[] input_b = Console.ReadLine().Split(' ');
            long[] b = new long[n];
            for(int i = 0;i < n - 1;i++)
                b[i] = long.Parse(input_b[i]);
            
            long sum = 0;

            sum += b[0];

            for(int i = 1;i < n - 1;i++)
                sum += Math.Min(b[i-1], b[i]);

            sum += b[n - 2];

            Console.WriteLine(sum);
        }
    }

Measured memory_bytes: 13140
//C++14 (Clang 3.8.0)

#include <vector>
#include <list>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <string>
#define rp(i,a,b) for(int (i)=(int)(a);i<(int)(b);++i)

typedef long long ll;


using namespace std;


int main(){
    int x,c=0;
    while(1) {cin>>x;
        if(x==0) break;
        c++;
        cout<<"Case "<<c<<": "<<x<<endl;
    }
    return 0;
};

Measured memory_bytes: 3068
#include <bits/stdc++.h>
using namespace std;
const long long mod = pow(10, 9) + 7;
const long long INF = 1LL << 60;
template <class T> bool chmin(T& a, T b){if (a > b) {a = b; return true;} return false;}
template <class T> bool chmax(T& a, T b){if (a < b) {a = b; return true;} return false;}
int divCeil(int A, int B) {return (A + (B - 1)) / B;}
long long divCeil(long long A, int B) {return (A + (B - 1)) / B;}
long long divCeil(int A, long long B) {return (A + (B - 1)) / B;}
long long divCeil(long long A, long long B) {return (A + (B - 1)) / B;}

int main()
{
  int a, b;
  cin >> a >> b;
  
  char ans = 'x';
  if (a + b == 15) ans = '+';
  else if (a * b == 15) ans = '*';
  
  cout << ans << endl;
}

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

using namespace std;

const int maxn = 100100;

typedef long long ll;

int n, num[maxn];

struct BIT {
	#define lowbit(x) (x & (-x))
	ll tr[maxn << 1];
	void clear() {
		memset(tr, 0, sizeof(tr));
	}
	void add(int x, ll num) {
		for(; x < maxn; x += lowbit(x)) tr[x] += num;
	}
	int query(int x) {
		int ret = 0;
		for(; x; x -= lowbit(x)) ret += tr[x];
		return ret;
	}
}bit;

ll work(int flag) {
	bit.clear(); ll ret = 0;
	for(int i = 1; i <= n; i++) bit.add(i, num[i]);
	for(int i = 1; i <= n; i++) {
		if(flag == 0) {
			int u = bit.query(i);
			if(u <= 0) ret += -u + 1, bit.add(i, -u + 1);
		} else {
			int u = bit.query(i);
			if(u >= 0) ret += u + 1, bit.add(i, -u - 1);
		}

		flag ^= 1;
	}
	return ret;
}

int main() {
	scanf("%d", &n);
	for(int i = 1; i <= n; i++) scanf("%d", &num[i]);
	for(int i = 1; i <= n; i++) bit.add(i, num[i]);

	ll ans = min(work(0), work(1));
	printf("%lld\n", ans);

	return 0;
}

Measured memory_bytes: 2176
#include <bits/stdc++.h>
// #include <vector>
// #include <limits>
// #include <iostream>
// #include <queue>
using namespace std;
#define rep(i,n) for (int (i)=(0);(i)<(int)(n);++(i))
using ll = long long;
using P = pair<int, int>;
using namespace std;

template<class T> void vin(vector<T>& v, int n) {
    v.resize(n);
    for (int i = 0; i < n; ++i) {
        cin >> v[i];
    }
}

template<class T>
class Dinic {
private:

    struct edge {
        T to, cap, rev;
        edge(T to, T cap, T rev) :to(to), cap(cap), rev(rev) {}
    };

    T V;
    vector<vector<edge>> g;
    vector<T> level;      // sourceからの距離
    vector<T> itr;        // どこまで調べ終わったか

public:
    Dinic(T V) :V(V), g(V, vector<edge>()) {}

    void add_edge(T from, T to, T cap) {
        g[from].emplace_back(to, cap, g[to].size());
        g[to].emplace_back(from, 0, g[from].size()-1);
    }

    // sourceからの最短路を幅優先で探索
    void bfs(T s) {
        level = vector<T>(V, -1);
        queue<T> que;
        que.push(s);
        level[s] = 0;
        while (que.size()) {
            int v = que.front(); que.pop();
            for (edge &e : g[v]) {
                if (e.cap > 0 and level[e.to] < 0) {
                    level[e.to] = level[v] + 1;
                    que.push(e.to);
                }
            }
        }
    }

    // v->tの増加路を探す
    T dfs(T v, T t, T f) {
        if (v == t) return f;
        for (T& i = itr[v]; i < g[v].size(); ++i) {
            edge& e = g[v][i];
            if (e.cap > 0 and level[v] < level[e.to]) {
                int d = dfs(e.to, t, min(f, e.cap));
                if (d > 0) {
                    e.cap -= d;
                    g[e.to][e.rev].cap += d;
                    return d;
                }
            }
        }
        return 0;
    }

    T max_flow(T s, T t) {
        T flow = 0, f;
        while (true) {
            bfs(s);
            if (level[t] < 0) return flow;
            itr = vector<T>(V, 0);
            while ((f = dfs(s, t, numeric_limits<T>::max())) > 0) {
                flow += f;
            }
        }
    }
};

// http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=GRL_6_A
void grl_6_a() {
    int V, E;
    cin >> V >> E;
    // Ford_fulkerson flow;
    Dinic<int> flow(V);
    for (int i = 0; i < E; ++i) {
        int from, to, cap;
        cin >> from >> to >> cap;
        flow.add_edge(from, to, cap);
    }
    cout << flow.max_flow(0, V-1) << endl;
    return;
}


int main() {
    grl_6_a();
}



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

int main() {
	int x;
	cin >> x;
	x %= 10;
	if(x == 2 || x == 4 || x == 5 || x == 7 || x == 9) cout << "hon" << endl;
	if(x == 0 || x == 1 || x == 6 || x == 8) cout << "pon" << endl;
	if(x == 3) cout << "bon" << endl;
}

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

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

using namespace std;


int main() {

    ll tmp[9];
    ll sum = 0;


    rep(i,9){
        cin >> tmp[i];
        sum += tmp[i];
    }
    if(tmp[0] + tmp[4] + tmp[8] != tmp[2] + tmp[4] + tmp[6]) cout << "No";
    else cout << ((sum%3 == 0)?"Yes":"No");

    return 0;
}











Measured memory_bytes: 3616
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define INF (1e9)
ll N, M;
vector<ll> A;
ll sum[105000];

ll f(ll x) {
    ll ret = 0;
    int j = N - 1;
    for(int i = 0; i < N; i++) {
        while( j >= 0 && A[i] + A[j] >= x) j--;
        ret += N - j - 1;
    }
    return ret;
}

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    cin >> N >> M;
    A.resize(N);
    for(int i = 0; i < N; i++) {
        cin >> A[i];
    }
    // sort
    sort(A.begin(), A.end());
    // compute prefix sums
    for(int i = 0; i < N; i++) {
        sum[i+1] = sum[i] + A[i];
    }
    ll ok = 0;
    ll ng = 2e5 + 1;
    while(abs(ok - ng) > 1) {
        ll mid = (ok + ng) / 2;
        if(f(mid) >= M) {
            ok = mid;
        } else {
            ng = mid;
        }
    }
    ll ans = 0;
    // cerr << ok << endl;
    int j = N - 1;
    for(int i = 0; i < N; i++) {
        while (j >= 0 && A[i] + A[j] >= ok) j--;
        ans += (N-j-1) * A[i] + (sum[N] - sum[j+1]);
        /*
        auto itr = lower_bound(A.begin(), A.end(), ok - A[i]);
        int index = distance(A.begin(), itr);
        ans += distance(itr, A.end()) * A[i];
        ans += sum[N] - sum[index];
        */
    }
    ans -= (f(ok) - M) * ok;
    cout << ans << endl;
    return 0;
}



Measured memory_bytes: 1792