akhauriyash/Code-Regression huggingface dataset:
#include<stdio.h>
#include<cstdio>
#include<iostream>
#include<algorithm>
#include<queue>
#include<cstring>
using namespace std;
const int maxn=100;
int a[maxn][maxn],n,m,k,g[maxn][maxn];
char ss[maxn];
bool f[maxn];
long long ans;
bool judge()
{
	int cnt=0;
	for(int i=1;i<=n;++i)
	{
		if(f[i])continue;
		for(int j=1;j<=m;++j)
		{
			if(f[j+n])continue;
			if(a[i][j])cnt++;
		}
	}
	if(cnt==k)return 1;
	return 0;
}
void dfs(int x)
{
	if(x==n+m+1)
	{
		if(judge())ans++;
		return;
	}
	f[x]=1;
	dfs(x+1);
	f[x]=0;
	dfs(x+1);
}
int main()
{
	scanf("%d%d%d",&n,&m,&k);
	for(int i=1;i<=n;++i)
	{
		scanf("%s",ss);
		for(int j=1;j<=m;++j)
		{
			if(ss[j-1]=='.')a[i][j]=0;
			else a[i][j]=1;
			g[i][j]=a[i][j];
		}
	}
	dfs(1);
	printf("%lld\n",ans);
	return 0;
}


Measured memory_bytes: 3832
#include<cstdio>
#include<string>

int main(void){
    int ch;
    while(1){
        scanf("%c",&ch);
        if(islower(ch)) ch=toupper(ch);
        else if(isupper(ch)) ch=tolower(ch);
        printf("%c",ch);
        if(ch=='\n') break;
    }
    return 0;
}

Measured memory_bytes: 2688
#include<bits/stdc++.h>
using namespace std;
int main()
{
	int a,b,c;
	scanf("%d%d%d",&a,&b,&c);
	a=a-b;
	if(c<a)
	{
		printf("0");
	}
	else
	{
		printf("%d",c-a);
	}
}

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

template<typename T_char>
T_char ToUpper(T_char cX){return toupper(cX);}

int main(){
  int n, a, b;
  string s;
  cin >> n >> a >> b >> s;
  
  int res = 0, res1 = 0;
  for(int i=0; i<s.size(); ++i){
    if(s[i]=='a'){
      if(res<a+b){
        ++res; 
        cout << "Yes" << endl;
      }
      else cout << "No" << endl;
    }
    else if(s[i]=='b'){
      if(res<a+b && res1<b){
        ++res;
        ++res1; 
        cout << "Yes" <<endl;
      }
      else cout << "No" << endl;
    }
    else cout << "No" << endl;
  }

  return 0;
}

Measured memory_bytes: 896
#include<bits/stdc++.h>
using namespace std;
 
const int MaxS = 105, MaxN = 5050;
 
int f[MaxN][MaxN], px[MaxS][MaxS], py[MaxS][MaxS], h, w, Ex, Ey, qx[MaxS][MaxS], qy[MaxS][MaxS];
char ma[MaxS][MaxS];
 
/*
	l
	
u		d
 
	r
*/
 
int calcx (int x, int l, int r, int cl, int cr) {
	if (x < cl || x > cr) return 0;
	if (l > r)
	puts("A");
	return qx[x][r] - qx[x][l - 1];
}
 
int calcy (int x, int l, int r, int cl, int cr) {
	if (x < cl || x > cr) return 0;
	if (l > r)
	puts("A");
	return qy[x][r] - qy[x][l - 1];
}
 
int dp (int l, int r, int u, int d) {
//	if (px[l][r] == -1 || py[u][d] == -1) return 0;
	if (l == r && u == d) return 0;
	if (~f[px[l][r]][py[u][d]]) return f[px[l][r]][py[u][d]];
	int &re = f[px[l][r]][py[u][d]]; ++re;
	int qlx = max((d - Ey) + 1, u), qrx = min(w - (Ey - u), d);
	int qly = max((r - Ex) + 1, l), qry = min(h - (Ex - l), r);
	if (~px[l + 1][r]) re = max(re, dp(l + 1, r, u, d) + calcx(l, qlx, qrx, qly, qry));
	if (~px[l][r - 1]) re = max(re, dp(l, r - 1, u, d) + calcx(r, qlx, qrx, qly, qry));
	if (~py[u + 1][d]) re = max(re, dp(l, r, u + 1, d) + calcy(u, qly, qry, qlx, qrx));
	if (~py[u][d - 1]) re = max(re, dp(l, r, u, d - 1) + calcy(d, qly, qry, qlx, qrx));
	return re;
}
 
int main () {
	memset(f, -1, sizeof f);
	memset(py, -1, sizeof py);
	memset(px, -1, sizeof px);
	scanf("%d%d", &h, &w);
	for (int i = 1; i <= h; ++i) {
		scanf("%s", ma[i] + 1);
		for (int j = 1; j <= w; ++j) {
			if (ma[i][j] == 'E') Ex = i, Ey = j;
			qx[i][j] = qx[i][j - 1] + (ma[i][j] == 'o');
			qy[j][i] = qy[j][i - 1] + (ma[i][j] == 'o');
		}
	}
	for (int i = 1, c = 0; i <= Ex; ++i) for (int j = Ex; j <= h; ++j) px[i][j] = c++;
	for (int i = 1, c = 0; i <= Ey; ++i) for (int j = Ey; j <= w; ++j) py[i][j] = c++;
	printf("%d\n", dp(1, h, 1, w));
	return 0;
}

Measured memory_bytes: 100096
#include <bits/stdc++.h>
using namespace std;
#define rep(i,a,n) for (int i=a;i<n;i++)
#define per(i,a,n) for (int i=n-1;i>=a;i--)
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define fi first
#define se second
#define SZ(x) ((int)(x).size())
typedef vector<int> VI;
typedef long long ll;
typedef pair<int,int> PII;
typedef double db;
mt19937 mrand(random_device{}()); 
const ll mod=1000000007;
int rnd(int x) { return mrand() % x;}
ll powmod(ll a,ll b) {ll res=1;a%=mod; assert(b>=0); for(;b;b>>=1){if(b&1)res=res*a%mod;a=a*a%mod;}return res;}
ll gcd(ll a,ll b) { return b?gcd(b,a%b):a;}
// head

ll inv(ll q,ll m) {
	q%=m;if (q<0) q+=m;
	if (q==0) return 0;
	ll a1=m,b1=0,a2=q,b2=1,a3=0,b3=0,t=0;
	while (a2!=1) {	t=a1/a2,a3=a1-t*a2,b3=b1-t*b2%m,
		a1=a2,a2=a3,b1=b2,b2=b3;if (b2<0) b2+=m;}
	return b2;
}

ll ceil(ll n, ll m) { return (n+m-1)/m; }

ll calc(ll A, ll M, ll L, ll R) // minimum nonnegative integer x s.t. L <= Ax mod M <= R
{
	if (R==0) return M;
	if(L==0) return 0;
	if(2*A>M) { swap(L,R); A=M-A; L=M-L; R=M-R; }
	ll cc_1=ceil(L,A);
	if(A*cc_1<=R) return cc_1;
	ll cc_2=calc(A-M%A,A,L%A,R%A);
	return ceil(L+M*cc_2,A);
}

bool sol_ex(ll A, ll M, ll L, ll R) // Existence of x s.t. L <= Ax mod M <= R
{
	if(L==0) return true;
	ll g=gcd(A,M);
	if((L-1)/g==R/g) return false;
	return true;
}

void solve() {
	ll a,x,b,y,c;
	scanf("%lld%lld%lld%lld%lld",&a,&x,&b,&y,&c);
	a%=c; b%=c;
	while (gcd(a,c)>1||gcd(b,c)>1) {
		ll d=gcd(gcd(a,b),c);
		a/=d; b/=d; c/=d;
		if (gcd(a,c)==1) swap(a,b),swap(x,y);
		d=gcd(a,c);
		ll dd=d/gcd(d,b);
		b=b*dd%c; y=y/dd;
		a/=d; b/=d; c/=d;
		if (a==0&&b==0) {
			printf("%lld\n",x+y);
			return;
		}
	}
	b=a*inv(c-b,c)%c;
	PII px(0,c);
	vector<VI> g;
	while (px.se>0) {
		int p=calc(b,c,1,px.se-1);
		int q=(ll)p*b%c;
		int dx=p-px.fi,dy=px.se-q;
		int cnt=px.se/dy;
		PII py(px.fi+cnt*dx,px.se-cnt*dy);
		g.pb({px.fi,px.se,py.fi,py.se,dx,-dy});
		px=py;
	}
	ll l=0,r=1ll<<33;
	while (l+1<r) {
		ll md=(l+r)>>1;
		bool valid=0;
		for (auto p:g) {
			ll x1=p[0]*md,x2=p[2]*md;
			if (x1<=x&&x<=x2) {
				ll cc=p[1]*md+((x-x1)/p[4])*p[5];
				if (y>=cc) valid=1;
			}
		}
		if (g.back()[2]*md<=x) valid=1;
		if (valid) l=md; else r=md;
	}
	printf("%lld\n",l);
}

int main() {
	int _;
	for (scanf("%d",&_);_;_--) {
		solve();
	}
}

Measured memory_bytes: 3804
//何階から落とす？
#include<cstdio>

using namespace std;

int main(void){
	double in,y,h,t;	//y=必要な高さ,in=最低速度,t=必要な時間
	int ans;	//必要な階

	while(scanf("%lf",&in)==1){
		t=in/9.8;
		y=4.9*(t*t);
		for(ans=1;ans<1000;ans++){
			h=5*ans-5;
			if(y<=h){
				printf("%d\n",ans);
				break;
			}
		}
	}

	return 0;
}

Measured memory_bytes: 0
#include<iostream>
#include<string>
#include<cstdio>
#include<algorithm>
#include<stack>
#include<queue>
#include<vector>
#include<cmath>
#include<utility>
#include<set>
#include<complex>
#define vi vector<int>
#define vvi vector<vector<int> >
#define ll long long int
#define vl vector<ll>
#define vvl vector<vector<ll>>
#define vb vector<bool>
#define vc vector<char>
#define vs vector<string>
#define ld long double
#define INF 1e9
#define EPS 0.0000000001
#define rep(i,n) for(int i=0;i<n;i++)
#define CC puts("-------ok--------");
#define all(in) in.begin(), in.end()
#define bv vector<bool>
using namespace std;
typedef pair<int, int>PA;
using namespace std;
#define MAX 1000
int main(){
        string s;
    while(cin>>s){
            string temp;
            rep(i,s.size()){
                if(s[i]=='@'){
                    rep(j,s[i+1]-48)
                    temp.push_back(s[i+2]);
                    i+=2;
                }
                else
                    temp.push_back(s[i]);
                
                    }
            cout<<temp<<endl;
        }
}

Measured memory_bytes: 3156
#include <iostream>
#include <cstdio>
#include <cmath>
#include <ctime>
#include <cstdlib>
#include <cassert>
#include <vector>
#include <list>
#include <stack>
#include <queue>
#include <deque>
#include <map>
#include <set>
#include <bitset>
#include <string>
#include <algorithm>
#include <utility>
#define llint long long
#define inf 1e18
#define rep(x, s, t) for(llint (x) = (s); (x) < (t); (x)++)
#define Rep(x, s, t) for(llint (x) = (s); (x) <= (t); (x)++)
#define chmin(x, y) (x) = min((x), (y))
#define chmax(x, y) (x) = max((x), (y))

using namespace std;
typedef pair<llint, llint> P;

llint n, x, y;
vector<llint> G[2005];
llint dist[2005][2005];
llint ans[2005];

void bfs(int S, llint dist[])
{
	queue<int> Q;
	Q.push(S);
	for(int i = 1; i <= n; i++) dist[i] = inf;
	dist[S] = 0;
	
	while(Q.size()){
		int v = Q.front();
		Q.pop();
		for(int i = 0; i < G[v].size(); i++){
			if(dist[G[v][i]] < inf/2) continue;
			Q.push(G[v][i]);
			dist[G[v][i]] = dist[v] + 1;
		}
	}
}

int main(void)
{
	ios::sync_with_stdio(0);
	cin.tie(0);
	
	cin >> n >> x >> y;
	for(int i = 1; i < n; i++){
		G[i].push_back(i+1);
		G[i+1].push_back(i);
	}
	G[x].push_back(y);
	G[y].push_back(x);
	
	for(int i = 1; i <= n; i++){
		bfs(i, dist[i]);
	}
	for(int i = 1; i <= n; i++){
		for(int j = 1; j <= n; j++){
			if(i >= j)continue;
			ans[dist[i][j]]++;
		}
	}
	for(int i = 1; i < n; i++) cout << ans[i] << endl;
	
	return 0;
}

Measured memory_bytes: 31744
# -*- coding: utf-8 -*-
import sys
from operator import itemgetter
from fractions import gcd
from math import ceil, floor, sqrt
from copy import deepcopy
from collections import Counter, deque
import heapq
from functools import reduce
sys.setrecursionlimit(200000)
# local only
# if not __debug__:
#     fin = open('in_1.txt', 'r')
#     sys.stdin = fin
# local only
input = sys.stdin.readline
def ii(): return int(input())
def mi(): return map(int, input().rstrip().split())
def lmi(): return list(map(int, input().rstrip().split()))
def li(): return list(input().rstrip())
def debug(*args, sep=" ", end="\n"): print("debug:", *args, file=sys.stderr, sep=sep, end=end) if not __debug__ else None
def exit(*arg): print(*arg); sys.exit()
# template

def isPrime(n):
    i = 2
    while i * i <= n:
        if n % i == 0:
            return False
        i += 1
    return True

from copy import deepcopy
class CumulativeSum():
    def __init__(self, arr: list):
        self.data = deepcopy(arr)
        for i in range(1, len(self.data)):
            self.data[i] += self.data[i - 1]

    def _query(self, k: int) -> int:
        """[0,k]の和"""
        if k < 0:
            return 0
        else:
            return self.data[min(k, len(self.data) - 1)]

    def query(self, l: int, r: int) -> int:
        """[l,r)の和"""
        if l > r:
            return 0
        else:
            return self._query(r - 1) - self._query(l - 1)

    def __str__(self):
        return str(self.data)
    def __getitem__(self, k):
        return self.data[k]

def isOK(n):
    return n > 2 and isPrime(n) and isPrime((n + 1) / 2)

def main():
    Q = ii()
    v = [0] * 100001
    for i in range(100000 + 1):
        if isOK(i):
            v[i] = 1
    c = CumulativeSum(v)
    for i in range(Q):
        l, r = mi()
        print(c.query(l, r + 1))
    return


if __name__ == '__main__':
    main()


Measured memory_bytes: 80600
#include <bits/stdc++.h>
#include <iostream>
#include <string>
using namespace std;
 
int main() {
    int l,r,d;
    cin>>l>>r>>d;
    int count=0;
    for(int i=l;i<=r;i++){
      if(i%d==0) count++;
    }
    cout<<count<<endl;
}

Measured memory_bytes: 3616
#include <algorithm>
#include <cmath>
#include <iostream>
#include <string>
using namespace std;

const int maxn = 2e5 + 10;

int main()
{
    int n;
    double ans = 0;
    cin >> n;
    for (double i = 1.0; i <= n; i++)
        ans += (i / 2) * floor(n / i) * floor(1 + n / i);
    cout << static_cast<long long>(ans) << endl;
    return 0;
}

Measured memory_bytes: 3632
#include<iostream>
using namespace std;
int main()
{
  int n,k,i,sum=0;
  cin>>n;
  int a[n];
  for(i=0;i<n;i++)
  {
      cin>>a[i];
   
  }
  for(i=0;i<n;i++)
  {
      for(int j=i+1;j<n;j++)
      {
       sum=sum+a[i]*a[j];   
      }
  }
  //cout<<sum;
  //sum=sum+a[0]*a[i-1];
  cout<<sum;
  return 0;
}

Measured memory_bytes: 256
n = gets.to_i
matches = []
n.times { matches << gets.split.map(&:to_i) }
queue = (1..n).to_a
delete_list = []
day = 0

until queue.empty?
  until queue.empty?
    me = queue.shift
    # 対戦相手の最初の対戦相手が自分自身なら、それぞれ削除リストに入れる
    # 自分自身のみを入れると、前回対戦しなかった人はキューに入っていないため抜け漏れる
    if opponent = matches[me - 1].first
      if matches[opponent - 1].first == me
        delete_list << me
        delete_list << opponent
      end
    end
  end
  unless delete_list.empty?
    day += 1
    delete_list.uniq!
    until delete_list.empty?
      d = delete_list.shift
      matches[d - 1].shift
      # 対戦した人のみキューに入れる（しなかった人同士のマッチングは発生しないため）
      queue << d
    end
  end
end
puts matches.flatten.empty? ? day : -1


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

const int maxn = 55;

int H,W;
string grid[maxn];

int main() {

  ios_base::sync_with_stdio(false);
  cin.tie(0); cout.tie(0);

  cin >> H >> W;
  for (int i = 1; i <= H; i++) cin >> grid[i];

  for (int i = 1; i <= H; i++) {
    for (int j = 0; j < W; j++) {
      if (grid[i][j] == '#') {
	if (i-1 >= 1 && grid[i-1][j] == '#') continue;
	else if (j-1 >= 0 && grid[i][j-1] == '#') continue;
	else if (i+1 <= H && grid[i+1][j] == '#') continue;
	else if (j+1 < W && grid[i][j+1] == '#') continue;
	else {
	  cout << "No" << endl;
	  return 0;
	}
      }
    }
  }
  
  cout << "Yes" << endl;
  
  return 0;
}


Measured memory_bytes: 256
N = int(input())
T,A = [],[]
for i in range(N):
    t,a = map(int,input().split())
    T.append(t); A.append(a)
x,y = T[0],A[0]
for i in range(1,N):
    p = x//T[i] if x%T[i]==0 else x//T[i]+1
    q = y//A[i] if y%A[i]==0 else y//A[i]+1
    p = max(p,q)
    x = p*T[i]
    y = p*A[i]
print(x+y)

Measured memory_bytes: 3064
#include<bits/stdc++.h>
#define ll long long
#define ld long double
#define pi acos(-1)
#define mod 1000000007
#define all(x) x.begin(), x.end()
using namespace std;

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

    int x, y;
    cin >> x >> y;
    bool f = false;
    for(int i = 0; i <= x; i++){
        if(y == (x - i) * 2 + i * 4){
            f = true;
        }
    }
    cout << (f == true ? "Yes" : "No");
}



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

#define PII pair<int, int>
#define VI vector<int>
#define VPII vector<PII>
#define LL long long
#define LD long double
#define f first
#define s second
#define MP make_pair
#define PB push_back
#define endl '\n'
#define ALL(c) (c).begin(), (c).end()
#define SIZ(c) (int)(c).size()
#define REP(i, n) for (int i = 0; i < (int)(n); i++)
#define FOR(i, b, e) for (int i = (b); i <= (int)(e); i++)
#define FORD(i, b, e) for (int i = (b); i >= (int)(e); i--)
#define ll long long
#define st f
#define nd s
#define pb PB
#define eb emplace_back
#define mp make_pair				
#define siz(c) SIZ(c)
const int inf = 1e9 + 7;
const LL INF = 1e18L + 7;
 
#define sim template<class n
sim, class s> ostream & operator << (ostream &p, pair<n, s> x)
{return p << "<" << x.f << ", " << x.s << ">";}
sim> auto operator << (ostream &p, n y) ->
typename enable_if<!is_same<n, string>::value, decltype(y.begin(), p)>::type
{int o = 0; p << "{"; for (auto c : y) {if (o++) p << ", "; p << c;} return p << "}";}
void dor() {cerr << endl;}
sim, class...s> void dor(n p, s...y) {cerr << p << " "; dor(y...);}
sim, class s> void mini(n &p, s y) {if (p > y) p = y;}
sim, class s> void maxi(n &p, s y) {if (p < y) p = y;}

#ifdef DEB
#define debug(...) dor(__FUNCTION__, ":", __LINE__, ": ", __VA_ARGS__)
#else
#define debug(...)
#endif

#define I(x) #x " = ", (x), " "
#define A(a, i) #a "[" #i " = ", i, "] = ", a[i], " "

#ifndef LOCAL
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

using namespace __gnu_pbds;

template <typename T>
using ordered_set =
	tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

#else
#include</Users/dawid/algo/mac/ordered_set>
#endif

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

	int a, b, ans = 0;
	cin >> a >> b;

	if(a<=3)
		ans += 4-a;

	if(b<=3)
		ans += 4-b;

	if(a==1 && b==1)
		ans += 4;

	cout << ans * 100000 << endl;
}


Measured memory_bytes: 892
import sys

def I(): return int(sys.stdin.readline())
def MI(): return map(int, sys.stdin.readline().split())
def LI(): return list(map(int, sys.stdin.readline().split()))
def main():
    n = I()
    A =LI()
    A.sort(reverse=True)
    ans = A[0] + sum(A[1:n//2])*2
    if n%2:
        ans += A[n//2]
    print(ans)

if __name__ == '__main__':
    main()

Measured memory_bytes: 31272
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.*;

public class Main {

    static Parser parser = new Parser();

    public static void main(String[] args) throws IOException {

        int K = parser.parseInt();
        int[] dp = new int[K];
        Arrays.fill(dp, Integer.MAX_VALUE);

        Deque<Integer> deque = new ArrayDeque<>();

        dp[1] = 1;
        deque.add(1);
        while(!deque.isEmpty()){
            int curr = deque.poll();
            int v1 = (curr + 1) % K;
            int v2 = (curr * 10) % K;

            if(dp[v1] > dp[curr] + 1){
                deque.addFirst(v1);
                dp[v1] = dp[curr] + 1;
            }

            if(dp[v2] > dp[curr]){
                deque.addLast(v2);
                dp[v2] = dp[curr];
            }
        }

        System.out.println(dp[0]);

    }

}

class Parser {
    private static final BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
    private static final Iterator<String> stringIterator = br.lines().iterator();
    private static final Deque<String> inputs = new ArrayDeque<>();

    void fill() throws IOException {
        if(inputs.isEmpty()){
            if(!stringIterator.hasNext()) throw new IOException();
            inputs.addAll(Arrays.asList(stringIterator.next().split(" ")));
        }
    }

    Integer parseInt() throws IOException {
        fill();
        if(!inputs.isEmpty()) {
            return Integer.parseInt(inputs.pollFirst());
        }
        throw new IOException();
    }

    Long parseLong() throws IOException {
        fill();
        if(!inputs.isEmpty()) {
            return Long.parseLong(inputs.pollFirst());
        }
        throw new IOException();
    }

    Double parseDouble() throws IOException {
        fill();
        if(!inputs.isEmpty()) {
            return Double.parseDouble(inputs.pollFirst());
        }
        throw new IOException();
    }

    String parseString() throws IOException {
        fill();
        return inputs.pollFirst();
    }

}

Measured memory_bytes: 39736
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef pair<ll,ll> ii;
typedef vector<ii> vii;



main(){
    int n,k;
    cin>>n>>k;
    bool dp[k+1];
    int a[n];
    for(int i=0;i<n;i++) cin>>a[i];
    memset(dp,false,sizeof(dp));
    for(int i=1;i<=k;i++){
        for(int x : a){
            if(!dp[i-x] && (i-x)>=0) dp[i] = true;
        }
    }
    cout<<(dp[k] == true ? "First" : "Second");
}

Measured memory_bytes: 3680
#include <bits/stdc++.h>
#include <algorithm>
#include <stdio.h>
#include <math.h>
using namespace std;

#define INF 1.1e9
#define LINF 1.1e18
#define FOR(i,a,b) for (int i = (a); i < (b); ++i)
#define REP(i,n) FOR(i,0,n)
#define ALL(v) (v).begin(), (v).end()
#define pb push_back
#define pf push_front
#define fi first
#define se second
#define BIT(x,n) bitset<n>(x)

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

struct edge {
	int to,cost;
	edge(int t,ll c):to(t),cost(c) {}
};

int dx[]={1,-1,0,0},dy[]={0,0,1,-1};
int ddx[]={1,1,1,0,-1,-1,-1,0},ddy[]={1,0,-1,-1,-1,0,1,1};

ll mypow(ll x,ll n,ll m) {
	if(n==0) return 1;
	if(n%2==0) return mypow(x*x%m,n/2,m);
	else return x*mypow(x,n-1,m)%m;
}

//-----------------------------------------------------------------------------

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

	int n,k;
	vector<int> v;
	cin>>n>>k;
	REP(i,n) {
		int l;cin>>l;v.pb(l);
	}
	sort(ALL(v));
	reverse(ALL(v));
	int sum=0;
	REP(i,k) sum+=v[i];
	cout<<sum<<endl;

	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <string>
#include <algorithm>
#include <utility>
#include <cmath>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <functional>
using namespace std;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
typedef pair<ll, ll> P;
typedef vector<vector<P>> vvP;
#define rep(i, n) for(ll i = 0; i < n; i++)
#define exrep(i, a, b) for(ll i = a; i <= b; i++)
#define out(x) cout << x << endl
#define exout(x) printf("%.10f\n", x)
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define pb push_back
#define re0 return 0
const ll mod = 1000000007;
const ll INF = 1e16;
const ll MAX_N = 100010;

int main() {
    ll x, a, b;
    cin >> x >> a >> b;

    ll y = b-a;
    if(y <= 0) {
        out("delicious");
    }
    else if(y <= x) {
        out("safe");
    }
    else {
        out("dangerous");
    }

    re0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define REP(i,a) for(int i = 0; i < (a); i++)
#define ALL(a) (a).begin(),(a).end()
typedef long long ll;
typedef pair<int, int> P;
const int INF = 1e9;
const int MOD = 1e9 + 7;

#define MAX_N 100000

int dp[MAX_N][3];

signed main(){
	int n;
	cin >> n;
	int a[n],b[n],c[n];
	REP(i,n){
		cin >> a[i] >> b[i] >> c[i];
	}
	dp[0][0] = a[0];
	dp[0][1] = b[0];
	dp[0][2] = c[0];
	for(int i = 1; i < n; i++){
		dp[i][0] = max(dp[i - 1][1] + a[i], dp[i - 1][2] + a[i]);
		dp[i][1] = max(dp[i - 1][0] + b[i], dp[i - 1][2] + b[i]);
		dp[i][2] = max(dp[i - 1][0] + c[i], dp[i - 1][1] + c[i]);
	}
	cout << max({dp[n - 1][0], dp[n - 1][1], dp[n - 1][2]}) << endl;
	return 0;
}

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

int main() {

  int H,W,N; 
  cin >> H >> W >> N;
  
  int HWmax = max(H,W);
  int ans = N / HWmax;
  if((N % HWmax) == 0){
    ans = N / HWmax;
  }
  else{
    ans = N / HWmax + 1;
  }
  
  cout << ans << endl;

}


Measured memory_bytes: 256
#include<cstdio>
#include<iostream>
#include<algorithm>
#include<cstring>
#include<cmath>
#include<vector>
#include<string>
#include<queue>
#include<stack>
#include<set>
#include<map>
#include<sstream>
#include<bitset>
using namespace std;
#define pii pair<int,int>
#define pdd pair<double,double>
#define mp make_pair
#define pb push_back
#define ALL(x)	x.begin(),x.end()
#define fst first
#define sec second
#define PQ priority_queue
typedef long long ll;
const double eps = 1e-6;
const int maxn=1e6+10;;
const int inf=0x3f3f3f3f;
const ll mod=1e9+7;
const double pi=acos(-1.0);
ll gcd(ll a,ll b) { return b?gcd(b,a%b):a;} 
ll vis[maxn];
int main() {
    ll n,t=0,x=0,tem=0;
    cin>>n;    
    ll lim=sqrt(n);
    ll ans=0;
    for(ll i=1;i<=lim;++i)
    {
      if(n%i==0&&vis[i]==0)
      {
        t=i;
        x=n/i;
        vis[t]=1;
        if(t>1&&n%(t-1)!=0)
        {
           if(n/(t-1)==n%(t-1)) ans+=(t-1);
           //vis[t]=1;
           
        }
        if(x>1&&n%(x-1))
        {
            if(n/(x-1)==n%(x-1)) ans+=(x-1);
            //vis[x]=1;
        }
        else continue;
      }
      else continue;
      
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 6784
#include<bits/stdc++.h>
#define rep(i, l, r) for(int i = (l), i##end = (r);i <= i##end;++i)
using std::cin; using std::cout;
const int maxn = 500;
typedef long long ll;
const int mod = 1e9 + 7;
inline ll pow(ll a,int b,int ans = 1) {
	for(;b;b >>= 1,a = a * a % mod) if(b & 1)
		ans = ans * a % mod;
	return ans;
}
inline ll inverse(int x){ return pow(x, mod - 2); }
int pre[maxn][maxn];
int dp[maxn][maxn];
int a[maxn], b[maxn];
int n, c;
int main() {
	std::ios::sync_with_stdio(false), cin.tie(0), cout.tie(0);
	rep(i, 0, maxn - 1) rep(j, 0, maxn - 1) {
		pre[i][j] = ((j ? pre[i][j - 1] : 0) + pow(j, i)) % mod;
	}
	cin >> n >> c;
	dp[0][0] = 1;
	rep(i, 1, n) cin >> a[i];
	rep(i, 1, n) cin >> b[i];
	rep(i, 1, n) {
		rep(j, 0, c) rep(k, 0, j) {
			dp[i][j] = (dp[i][j] + (ll) dp[i - 1][j - k] * (pre[k][b[i]] - pre[k][a[i] - 1] + mod)) % mod;
		}
	}
	cout << dp[n][c] << '\n';
}


Measured memory_bytes: 2048
#include "bits/stdc++.h"
using namespace std;
using ll = long long;
#define rep(i, begin, n) for (int i = begin; i < n; i++)
#define repe(i, begin, n) for (int i = begin; i <= n; i++)
#define repr(i, begin, n) for (int i = begin; i > begin - n; i--)
#define repre(i, begin, end) for (int i = begin; i >= end; i--)

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

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

const int inf = 1000000007;
const int MOD = 1000000007;
const long long INF = 1000000000000000007;

const double pi = 3.141592653589793;
// -------------------------------------------------------

ll N;
ll T[200];

long long gcd(long long a, long long b) {
  if (b == 0) return a;

  return gcd(b, a % b);
}

long long lcm(long long a, long long b) { return a / gcd(a, b) * b; }

int main() {
  cin >> N;
  ll ans = 1;
  rep(i, 0, N) {
    cin >> T[i];
    ans = lcm(ans, T[i]);
  }
  cout << ans << endl;
}


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

int main(){
  int num,i,j;
  int sum[4]={0};
  char s1[3],tenn;
  while(scanf("%d",&num)!=EOF){
    scanf("%c%s",&tenn,s1);
    if(s1[0]=='A'){
     if(s1[1]=='\0'){
	sum[0]++;
     }else if(s1[1]=='B'){
	sum[2]++;
     }
    } else if(s1[0]=='B'){
      sum[1]++;
    } else if(s1[0]=='O'){
      sum[3]++;
    }
  }
  for(i=0;i<4;i++){
    printf("%d\n",sum[i]);
  }
  return(0);
}

Measured memory_bytes: 1024
#pragma GCC optimize(2)
#pragma GCC optimize(3)   
#pragma GCC optimize("Ofast,no-stack-protector,unroll-loops,fast-math,O3")
#pragma GCC target("avx,avx2,fma")
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector < ll > vl;
typedef vector < vl > vvl;
typedef pair < ll, ll > pll;
typedef vector < pair < ll, ll > > vpll;
#define kill freopen("input.txt", "r", stdin);freopen("output.txt", "w", stdout);
#define pb push_back
#define fo(i,n) for(ll i=0;i<n;i++)
#define rev(i,n) for(ll i=n-1;i>=0;i--)
#define all(c) c.begin(), c.end()
#define go(c,it) for(auto it=(c).begin(); it!=(c).end(); it++)
#define back(c,it) for(auto it=(c).rbegin(); it!=(c).rend(); it++)
#define fi first
#define se second
#define MOD 998244353
#define Boost() ios_base::sync_with_stdio(false);cin.tie(NULL)
#define MOD1 1000000007
ll power(ll a, ll b){ll res=1;a=a%MOD;while(b>0){if(b&1){res=(res*a)%MOD;}a=(a*a)%MOD;b>>=1;}return res;}
ll fermat_inv(ll y){return power(y,MOD-2);}
ll gcd(ll a, ll b){return (b==0)?a:gcd(b,a%b);}
#define oo LLONG_MAX
const ll N = 1e5;

void solve(){
    ll n;
    cin>>n;
    ll a[n];
    fo(i,n)cin>>a[i];
    ll ans = 0;
    fo(i,n){
        if(a[i]%2==1&&i%2==0)ans++;
    }
    cout<<ans;
}

int main(){
    Boost();
    #ifndef ONLINE_JUDGE 
    kill
    #endif
    ll T = 1;
    //cin>>T;
    while(T--){
        solve();
    }
    return 0;
}
 
 
 
 
 

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

using namespace std;

int main()
{
    long long i,r,n,x;
    scanf("%lld%lld%lld",&r,&n,&x);
    for(i=1;i<=10;i++)
    {
        x=r*x-n;
        printf("%lld\n",x);
    }
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <cmath>

using namespace std;

void solve()
{
	int q;
	while(cin >> q, q != -1)
	{
		double eps = 0.00001 * q;
		double x = q / 2.0;
		while(fabs(x * x * x - q) > eps)
		{
			x = x - (x * x * x - q) / (3 * x * x);
		}
		printf("%.6f\n", x);
	}
}

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

Measured memory_bytes: 0
#include <cstdio>

template <class T>
T abs(T a) { return a > 0 ? a : -a; }

int main() {
    long long a, b, c, ret = 0;
    scanf("%lld%lld%lld", &a, &b, &c);

    auto k = abs(a - b), l = abs(b - c), m = abs(c - a);
    if (k == 0 && l == 0 && m == 0 && a % 2 == 0 && b % 2 == 0 && c % 2 == 0) ret = -1;
    else if (a % 2 || b % 2 || c % 2) ret = 0;
    else {
        for (; ; ret++) {
            if ((k & 1) || (l & 1) || (m & 1)) break;
            k >>= 1; l >>= 1; m >>= 1;
        }
    }

    printf("%lld\n", ret);

    return 0;
}

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

int main(){

  int A[1001] = {0}, N, key, j;

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

  for(int s = 0; s < N; s++){
    cout << A[s];
    if(s != N-1) cout << " ";
    else if(s == N-1)cout << endl;
  }

  for(int i = 1; i < N; i++){
    key = A[i];
    j = i - 1;

    while(j >= 0 && A[j] > key){
      
      A[j+1] = A[j];
      j--;
      A[j+1] = key;
    }
    for(int s = 0; s < N; s++){
      cout << A[s];
      if(s != N-1) cout << " ";
      else if(s == N-1)cout << endl;
    }
  }



}

Measured memory_bytes: 1164
class RSQ:
    def __init__(self,n_):
        self.n_ = n_
        self.n = 1
        while self.n < n_: self.n*=2
        self.st = [0]*(2*self.n-1)
    
    def update(self,k,x):
        k+=(self.n-1)
        self.st[k] += x
        while k >0:
            k = (k-1)//2
            self.st[k] = self.st[2*k+1]+self.st[2*k+2]

    def search(self,a,b,k,l,r):
        if r<=a or b<=l :return 0
        if a<=l and r<=b:return self.st[k]
        L = self.search(a,b,k*2+1,l,(l+r)//2)
        R = self.search(a,b,k*2+2,(l+r)//2,r)
        return L+R

    def query(self,a,b):
        return self.search(a,b,0,0,self.n)

def main():
    n,q = map(int,input().split())
    ST = RSQ(n)
    for _ in range(q):
        a,b,c = map(int,input().split())
        if a == 0:ST.update(b-1,c)
        else     :print (ST.query(b-1,c))

if __name__ == '__main__':
    main()




Measured memory_bytes: 10748
#include<iostream>
#include<cstdio>

#include<vector>
#include<string>

#include<algorithm>
#include<cmath>

using namespace std;
typedef long long ll;
const ll INF = 1e9+1;
template <class T> inline bool chmax(T& a, T b) {if (a < b) {a = b; return 1;} return 0;}
template <class T> inline bool chmin(T& a, T b) {if (a > b) {a = b; return 1;} return 0;}

int N;

int main() {
    cin >> N;
    vector<int> X(N);
    for (int i = 0; i < N; i++) cin >> X[i];

    vector<int> Y = X;
    sort(Y.begin(),Y.end());
    int s = Y[N/2-1], b = Y[N/2];
    for (int i = 0; i < N; i++) {
        if (X[i] <= s) {
            cout << b << endl;
        } else {
            cout << s << endl;
        }
    } 
}


Measured memory_bytes: 3712
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
typedef tuple<ll,ll,ll> PP;
typedef vector<ll> vi;
typedef vector<vi> vvi;
#define rep(i,n) for(ll i=0;i<(ll)(n);i++)
#define REP(i,k,n) for(ll i=(ll)(k);i<(ll)(n);i++)
#define all(v) v.begin(),v.end()
#define lb(v,k) (lower_bound(all(v),k)-v.begin())
#define pb push_back
#define eb emplace_back
#define fi first
#define se second
const int mod=1e9+7;
const ll inf=1001001001001001;
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;}
template<class T> void out(T a){cout<<a<<'\n';}
template<class T> void outv(T v){rep(i,v.size()){if(i)cout<<' ';cout<<v[i];}cout<<'\n';}
template<class T> void outvv(T v){rep(i,v.size())outv(v[i]);}

int main(){
    vi cost={0,2,5,5,4,5,6,3,7,6};
    ll n,m;cin>>n>>m;
    vector<bool> ok(10,false);
    rep(i,m){
        int a;cin>>a;ok[a]=true;
    }
    vi dp(n+1,-inf);
    dp[0]=0;
    REP(i,1,n+1){
        rep(j,10)if(ok[j])if(i>=cost[j])chmax(dp[i],dp[i-cost[j]]+1);
    }
    int s=dp[n],w=n;
    vi ans(s);
    rep(i,s){
        for(int j=9;j>0;j--){
            if(!ok[j])continue;
            if(w-cost[j]<0)continue;
            if(dp[w-cost[j]]==s-i-1){
                w-=cost[j];
                ans[i]=j;
                break;
            }
        }
    }
    rep(i,s)cout<<ans[i];
    cout<<'\n';
}

Measured memory_bytes: 384
#include <cstdio>

typedef long long LL;
const int MN = 41;

int N, A[MN][MN];
LL f[MN][MN][MN], g[MN][MN][MN], Ans;

int main() {
	scanf("%d", &N), N <<= 1;
	for (int i = 1; i <= N; ++i)
		for (int j = 1; j <= N; ++j)
			scanf("%1d", &A[i][j]);
	for (int i = 1; i < N; ++i) {
		f[i][i][i] = 1;
		for (int j = i + 1; j < N; ++j) g[i][i][j] = A[j][i];
	}
	for (int z = 3; z < N; z += 2)
		for (int i = 1; i <= N - z; ++i) {
			int j = i + z - 1;
			for (int p = i; p < j; p += 2)
				for (int q = j; q > p; q -= 2) {
					LL sum = 0;
					for (int k = q; k <= j; ++k)
						sum += g[i][p][k] * f[q][j][k];
					for (int k = p + 1; k < q; ++k)
						f[i][j][k] += sum * f[p + 1][q - 1][k];
				}
			for (int w = i; w <= j; ++w)
				for (int k = j + 1; k < N; ++k)
					g[i][j][k] += f[i][j][w] * A[k][w];
		}
	for (int i = 1; i < N; ++i) if (A[N][i]) Ans += f[1][N - 1][i];
	printf("%lld\n", Ans);
	return 0;
}

Measured memory_bytes: 896
#include <bits/stdc++.h>
 
using namespace std;
 
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define all(a) a.begin(), a.end()
#define rep(i, st, n) for (int i = (st); i < (n); ++i)
#define debug(x) std::cout << #x << ": " << x << endl
 
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef long double ld;
 
template <typename T1, typename T2> bool chkmin(T1 &x, T2 y) { return y < x ? (x = y, true) : false; }
template <typename T1, typename T2> bool chkmax(T1 &x, T2 y) { return y > x ? (x = y, true) : false; }

const int MOD = 1e9 + 7;
int add(int x, int y)
{
    x += y;
    if (x >= MOD)
        x -= MOD;
    return x;
}
int mult(int x, int y)
{
    return x * (ll)y % MOD;
}
int bpow(int x, ll y)
{
    int r = 1;
    for (; y; y >>= 1)
    {
        if (y & 1)
            r = mult(r, x);
        x = mult(x, x);
    }
    return r;
}
int rev(int x)
{
    return bpow(x, MOD - 2);
}

signed main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
#ifdef DEBUG
    freopen("in", "r", stdin);
#endif

    int X, Y;
    cin >> X >> Y;
    if ((X + Y) % 3 != 0)
    {
        cout << "0\n";
        return 0;
    }
    int n = (X + Y) / 3;
    int f = X - n;
    if (Y != 2 * n - f)
    {
        cout << "0\n";
        return 0;
    }
    int fact[1000006], rfact[1000006];
    fact[0] = rfact[0] = 1;
    fact[1] = rfact[1] = 1;
    for (int x = 2; x <= n; ++x)
    {
        fact[x] = mult(fact[x - 1], x);
        rfact[x] = rev(fact[x]);
    }
    cout << mult(fact[n], mult(rfact[f], rfact[n - f]));

    return 0;
}





Measured memory_bytes: 8064
use std::io;
use std::str::FromStr;

macro_rules! scan {
  ($e:expr; $t:ty) => {
    $e.get::<$t>()
  };
  ($e:expr; $($t:ty), *) => {
    ($($e.get::<$t>(),)*)
  }
}

struct Scanner {
  iter: std::vec::IntoIter<String>
}

impl Scanner {
  fn new() -> Scanner {
    Scanner { iter: vec![String::new()].into_iter() }
  }
  fn new_line(&mut self) {
    let mut line = String::new();
    io::stdin().read_line(&mut line).ok().unwrap();
    self.iter = line.trim().split_whitespace().map(|s| s.to_string()).collect::<Vec<String>>().into_iter();
  }
  fn get<T: FromStr>(&mut self) -> T {
    self.iter.next().unwrap().parse().ok().unwrap()
  }
}

fn main() {
  let mut scanner = Scanner::new();
  let grade = vec!["A", "B", "C", "D", "F"];
  loop {
    scanner.new_line();
    let (m, f, r) = scan!(scanner; i64, i64, i64);
    if m == -1 && f == -1 && r == -1 {
      break;
    }
    let mut g = 4;
    if m != -1 && f != -1 {
      g = match m + f {
        n if n >= 80 => 0,
        n if n >= 65 => 1,
        n if n >= 50 => 2,
        n if n >= 30 => {
          if r >= 50 { 2 } else { 3 }
        }
        _ => 4
      }
    }
    println!("{}", grade[g]);
  }
}



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


int main(){
    string s;
    cin >> s;
    if(s == "RRR") cout << 3 <<"\n";
    else if(s == "RRS" || s == "SRR") cout << 2 <<"\n";
    else if(s == "SSS") cout <<0  <<"\n";
    else cout << 1<<"\n";
	return 0;
}

Measured memory_bytes: 3632
// https://atcoder.jp/contests/abc112/tasks/abc112_b

#include <bits/stdc++.h>
#define REP(i, n) for (int(i) = 0; (i) < (n); (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 INF 1e9
#define ALL(v) (v).begin(), (v).end()
using namespace std;
typedef long long ll;

int main()
{
  /* Magic word */
  // cin.tie(0);
  // ios::sync_with_stdio(false);
  /* ---------- */

  int n, t;

  cin >> n >> t;

  int m = INF;
  REP(i, n)
  {
    int ci, ti;
    cin >> ci >> ti;
    if (ti <= t)
      m = min(m, ci);
  }

  string r = m == INF ? "TLE" : to_string(m);

  cout << r << '\n';

  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <cmath>
#include <map>
#include <vector>
#include <queue>
#include <functional>
#include <string>
#include <stack>
#include <set>
using namespace std;
using ll = long long;
typedef unsigned long long ull;
typedef pair<ll, ll> P;
typedef pair<ll, pair<ll, ll>> PP;

const ll MOD = 1e9 + 7;
const ll MOD2 = 998244353;
const ll INF = 1 << 30;
const ll INF2 = 9e18;
const double INF3 = 9e14;
const int dx[4] = { 1,0,-1,0 }, dy[4] = { 0,1,0,-1 };
const int tx[8] = { -1,0,1,-1,1,-1,0,1 }, ty[8] = { -1,-1,-1,0,0,1,1,1 };
#define ALL(x) (x).begin(),(x).end()
#define pb push_back
#define fr first
#define sc second



int main() {
	int n, a, b, ans = 0;
	cin >> n >> a >> b;
	for (int i = 1; i <= n; i++) {
		int j = i, cnt = 0;
		while (true) {
			if (j == 0)break;
			cnt += j % 10;
			j /= 10;
		}
		if (a <= cnt && cnt <= b)ans += i;
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <cstdint>
#include <vector>

int main() {
  std::int_fast64_t n, m;
  std::cin >> n >> m;
  std::vector<std::vector<char>> a(n, std::vector<char>(n)), b(m, std::vector<char>(m));
  for (std::vector<char>& a_i : a) {
    for (char& a_ij : a_i) {
      std::cin >> a_ij;
    }
    std::cin.get();
  }
  for (std::vector<char>& b_i : b) {
    for (char& b_ij : b_i) {
      std::cin >> b_ij;
    }
    std::cin.get();
  }

  for (std::int_fast64_t base_y = 0; base_y <= n - m; ++base_y) {
    for (std::int_fast64_t base_x = 0; base_x <= n - m; ++base_x) {
      for (std::int_fast64_t by = 0; by < m; ++by) {
        for (std::int_fast64_t bx = 0; bx < m; ++bx) {
          const std::int_fast64_t ay = base_y + by;
          const std::int_fast64_t ax = base_x + bx;
          if (a[ay][ax] != b[by][bx]) {
            goto NEXT_LOOP;
          }
        }
      }
      std::cout << "Yes" << std::endl;
      return 0;
    NEXT_LOOP:
      ;
    }
  }
  std::cout << "No" << std::endl;
  return 0;
}

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

using namespace std;

struct all {
	int a, b, c;
	all(int a, int b, int c) :
	a(a), b(b), c(c) {}
};

queue<all> q;
bool vis[500][500][500];

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

  q.push(all(a, b, c));
  vis[a][b][c] = true;

  int cost = 0, size;
  while(!q.empty()) {
  	size = q.size();

  	while(size-- != 0) {
  		all fr = q.front();
  		q.pop();

  		if(fr.a == fr.b && fr.b == fr.c) {
  			cout << cost << endl;
  			return 0;
  		}

  		if(!vis[fr.a + 1][fr.b + 1][fr.c]) {
  			vis[fr.a + 1][fr.b + 1][fr.c] = true;
  			q.push(all(fr.a + 1, fr.b + 1, fr.c));
  		}

  		if(!vis[fr.a + 1][fr.b][fr.c + 1]) {
  			vis[fr.a + 1][fr.b][fr.c + 1] = true;
  			q.push(all(fr.a + 1, fr.b, fr.c + 1));
  		}

  		if(!vis[fr.a][fr.b + 1][fr.c + 1]) {
  			vis[fr.a][fr.b + 1][fr.c + 1] = true;
  			q.push(all(fr.a, fr.b + 1, fr.c + 1));
  		}

  		if(!vis[fr.a + 2][fr.b][fr.c]) {
  			vis[fr.a + 2][fr.b][fr.c] = true;
  			q.push(all(fr.a + 2, fr.b, fr.c));
  		}

  		if(!vis[fr.a][fr.b + 2][fr.c]) {
  			vis[fr.a][fr.b + 2][fr.c] = true;
  			q.push(all(fr.a, fr.b + 2, fr.c));
  		}

  		if(!vis[fr.a][fr.b][fr.c + 2]) {
  			vis[fr.a][fr.b][fr.c + 2] = true;
  			q.push(all(fr.a, fr.b, fr.c + 2));
  		}
  	}

  	++cost;
  }

  cout << cost << endl;

  return 0;
}


Measured memory_bytes: 23296
#include <bits/stdc++.h>
using namespace std;
#define REP(i,n) for (int i=0;i<(n);++i)
int n;
int a[100]; 
int main(){
    cin >> n;
    int sum = 0;
    REP(i,n){
        cin >> a[i];
        sum += a[i];
    }
    int diff =(sum >= 0 ? (sum + (n/2))/n : (sum - (n/2))/n);
    int ans = 0;
    REP(i,n) ans += (a[i] - diff) * (a[i] - diff);
    cout << ans << endl;
}

Measured memory_bytes: 256
#include <algorithm>
#include <cmath>
#include <vector>
#include <functional>
#include <cstdlib>
#include <map>
#include <set>
#include <iostream>
#include <string>
#include <ctype.h>
#include <climits>
#include <queue>
#include <iomanip>
using namespace std;
typedef long long ll;
#define REP(i, n) for(ll i = 0; i < (ll)(n); ++i)
template<class T> inline bool chmax(T& a, T b) { if(a < b){ a=b; return 1; } return 0;}
template<class T> inline bool chmin(T& a, T b) { if(a > b){ a=b; return 1; } return 0;}

int main(){
	int n;
	cin >> n;
	vector<vector<int>> F(n,vector<int>(10));
	vector<vector<int>> P(n,vector<int>(11));
	REP(i,n) REP(j,10) cin >> F[i][j];
	REP(i,n) REP(j,11) cin >> P[i][j];
	
	ll ans = -1*(1LL<<60);
	for(int bit=1; bit<(1<<10); bit++){
		ll sum=0;
		vector<int> a(n,0);
		
		REP(i,n){
			REP(j,10){
				if((bit&(1<<j)) && (F[i][j])) a[i]++; 
			}
			sum += P[i][a[i]];
		}
		chmax(ans, sum);
	}
	
	cout << ans << endl;
	
	
	return 0;
}

Measured memory_bytes: 3644
H,W = map(int, input().split())
A = []
for i in range(0,H):
	A.append(input())
B = []
B.append('#' * (W+2))
for i in range(0,H):
	B.append('#' + A[i] + '#')
B.append('#' * (W+2))
for i in range(0,H+2):
	print(B[i])
	

Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int n;
  cin >> n;
  vector<int> a(n);
  for(int i=0;i<n;i++)
    cin >> a.at(i);
  
  int x=1;
  int k=0;
  
  for(int i=0;x!=2;i++){
    
    x=a.at(x-1);
    k++;
    
    if(i>n){
      k=-1;
      break;
    }
  }
  cout << k << endl;
}

Measured memory_bytes: 640
#
# File    : B.rb
# Author  : Kazune Takahashi
# Created : 3/3/2019, 9:02:17 PM
# Powered by Visual Studio Code
#

a, b, k = gets.chomp.split(" ").map{|i| i.to_i}

for j in 0..[a, b].min
  i = [a, b].min - j
  if a % i == 0 && b % i == 0
    k -= 1
  end
  if k == 0
    puts i
    exit
  end
end

Measured memory_bytes: 1788
import java.util.Scanner;

public class Main {

	/**
	 * @param args
	 */
	public static void main(String[] args) {
		Scanner cin = new Scanner(System.in);
		for(;;){
			String s = cin.next();
			if(s.equals("#END"))break;
			String ans="";
			for(int i=1;i<s.length();i++){
				String s1=s.substring(0,i);
				String s2=s.substring(i);
				String s3=lcs(s1,s2);
				if(ans.length()<s3.length()){
					ans=s3;
				}

			}
			System.out.println(ans);
			System.gc();
		}
	}
	public static String lcs(String a, String b){
		int na = a.length(), nb = b.length();
		int dp[][] = new int[na+1][nb+1];
		for(int i=1;i<=na;i++)for(int j=1;j<=nb;j++){
			if(a.charAt(i-1)==b.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]);
		}
		char[] r = new char[dp[na][nb]];
		int i = na, j = nb;
		while(0<i&&0<j){
			if(dp[i][j]==dp[i-1][j])i--;
			else if(dp[i][j]==dp[i][j-1])j--;
			else{
				r[dp[i-1][j-1]] = a.charAt(i-1);
				i--; j--;
			}
		}
		return new String(r);
	}
}

Measured memory_bytes: 49380
#include<bits/stdc++.h>
using namespace std;
#define int long long
int n;
int n2;
char s[200010];
int nxt[200010];
void kmp(){
	int j=0;
	for(int i=2;i<=n;++i){
		while(s[j+1]!=s[i]&&j)j=nxt[j];
		if(s[i]==s[j+1])j++;
		nxt[i]=j;
	}
}
int sum[200010][50];
int l,r;
int len[200010];
int up;
int ans[200010];
void solve(int x,int f){
    for(int i=up;i>=0;i--)
        if(x>=len[i]){
            for(int j=0;j<26;j++)
                ans[j]+=f*sum[i][j];
            x-=len[i];
        }
    for(int i=1;i<=x;i++)ans[s[i]-'a']+=f;
}
signed main(){
	scanf("%s%lld%lld",s+1,&l,&r);
	n=strlen(s+1);
	n>>=1;
	kmp();
	n2=nxt[n];
	//cout<<n2<<endl;
	for(int i=1;i<=n;++i){
		sum[0][s[i]-'a']++;
		sum[1][s[i]-'a']++;
	}
	len[0]=n;
	for(int i=1;i<=n-n2;++i){
		sum[1][s[i]-'a']++;
	}
	len[1]=2*n-n2;
	for(int i=2;i<=200000;++i){
		for(int j=0;j<26;++j){
			sum[i][j]=sum[i-1][j]+sum[i-2][j];
		}
		len[i]=len[i-1]+len[i-2];
		if(len[i]>r){
			up=i;
			break;
		}
	}
	solve(l-1,-1),solve(r,1);
	for(int i=0;i<26;++i){
		printf("%lld ",ans[i]);
	}
	puts(""); 
}

Measured memory_bytes: 4768
#include<iostream>
#include<algorithm>
#include<math.h>
#include<vector>
#include<map>
#include<set>
#include<iomanip>

using namespace std;
using ll = long long;
using P = pair<int, int>;

const int MOD = 1e9 + 7;
const int MAX = 1e9;
const ll LLMAX = 1e18;
const int INF = numeric_limits<int>::max();
const ll LLINF = numeric_limits<ll>::max();
const double PI = acos(-1.0);

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

int main() {
    char c; cin >> c;

    if (c - 'A' <= 25) cout << "A" << endl;
    else cout << "a" << endl;
    
    return 0;
}


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

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

using namespace std;

#define all(x) begin(x), end(x)

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

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

    int n;
    cin >> n;
    vector<array<int, 3>> h(n);
    for (int i = 0; i < n; ++i) {
        for (int j = 0; j < 3; ++j) {
            cin >> h[i][j];
        }
    }

    vector<array<ll, 3>> dp(n);
    for (int j = 0; j < 3; ++j) {
        dp[0][j] = h[0][j];
    }
    
    for (int i = 1; i < n; ++i) {
        for (int j = 0; j < 3; ++j) {
            dp[i][j] = 0;
            for (int k = 0; k < 3; ++k) {
                if (j == k) continue;
                dp[i][j] = max(dp[i][j], h[i][j] + dp[i - 1][k]);
            }
        }
    }

    cout << max(dp[n - 1][0], max(dp[n - 1][1], dp[n - 1][2])) << '\n';
    
    return 0;
}


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

using namespace std;

bool isPalindrome(string s){
  int n = s.length();
  for(int i=0; i<n/2; i++){
    if(s[i] != s[n-1-i]){
      return false;
    }
  }
  return true;
}

int main() {
  string s;
  cin>>s;
  int n = s.length();
  string s1=s.substr(0, (n-1)/2);
  string s2=s.substr(((n+3)/2)-1, (n-1)/2);
  if(isPalindrome(s) && isPalindrome(s1) && isPalindrome(s2)){
    cout<<"Yes"<<endl;
  }
  else{
    cout<<"No"<<endl;
  }
}

Measured memory_bytes: 256
#include<stdio.h>

int main(void)
{
  int a,b;
  scanf("%d %d",&a,&b);
  if(a<=9&&1<=a&&b<=9&&1<=b){
    printf("%d",a*b);
  }else{
    printf("%d",-1);
  }
  return 0;
}
  

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int N,ar[109],i,j;
    scanf("%d",&N);
    for(i=0;i<N;i++)
        scanf("%d",&ar[i]);
    sort(ar,ar+N);
    printf("%d\n",ar[N-1]-ar[0]);
    return 0;
}



Measured memory_bytes: 256