akhauriyash/Code-Regression huggingface dataset:
R, G, B, N = map(int,input().split())
count = 0

Q_B = N // B
for i in range(0,Q_B+1):
    Q_G = (N - B * i) // G
    for j in range(0,Q_G+1):
        if ((N - B * i - G * j) % R == 0):
            count += 1
print(count)

Measured memory_bytes: 3060
import java.util.Scanner;

public class Main {

    public static void main(String[] args){

        Scanner sc = new Scanner(System.in);
        int a = sc.nextInt();
        int b = sc.nextInt();
        int n = Math.min(a, b);
        int m = Math.max(a, b);

        long res = 0;
        if(n == 1) {
            if (m == 1) {
                res = 1;
            } else {
                res = m - 2;
            }
        } else {
            res = (long) (n - 2) * (m - 2);

        }

        System.out.println(res);
    }

}


Measured memory_bytes: 22996
def nc2(x):
    return 0 if x == 1 else x * (x - 1) // 2


N = int(input())
S = {}
for i in range(N):
    w = ''.join(sorted(input()))
    S[w] = S.get(w, 0) + 1
ans = sum(map(nc2, S.values()))
print(ans)


Measured memory_bytes: 17848
#include <bits/stdc++.h>
#define rep(i, a, n) for(int i = a; i < n; i++)
#define repb(i, a, b) for(int i = a; i >= b; i--)
#define all(a) a.begin(), a.end()
#define o(a) cout << a << endl
#define int long long
#define fi first
#define se second
using namespace std;
typedef pair<int, int> P;

int n, k;
int a[5010];


bool need(int m){
    bool dp[5010] = {};
    dp[0] = true;
    rep(j, 0, n){
        if(j == m) continue;
        repb(l, k, 0){
            if(a[j] + l > k) continue;
            dp[a[j] + l] |= dp[l];
        }
    }
    rep(i, max((int)0, k - a[m]), k) if(dp[i]) return true;
    return false;
}

signed main(){
    cin >> n >> k;
    rep(i, 0, n){
        cin >> a[i];
    }
    sort(a, a + n);
    int ng = -1, ok = n, m;
    rep(i, 0, 50){
        m = (ng + ok) / 2;
        if(!need(m)) ng = m;
        else ok = m;
    }
    // rep(i, 0, n){
    //     cout << (f(i) ? 1 : 0) << " ";
    // }
    cout << ng + 1 << endl;
}

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

const int MOD = (int)1e9+7;

int main(){
	int N;
	cin >> N;
	vector<int> a(N);
	for(int i=0;i<N;i++)	cin >> a.at(i);

	int x4=0;
	int x2=0;
	int x1=0;
	for(int i=0;i<N;i++){
		int b=a.at(i);
		if(b%4==0)	x4++;
		else if(b%2==0)	x2++;
		else	x1++;
	}
	if(x2==0){
		if(x1<=x4+1)	cout << "Yes" << endl;
		else	cout << "No" << endl;
		return 0;
	}
	if(x1>x4)	cout << "No" << endl;
	else	cout << "Yes" << endl;
	
	return 0;
}


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

int main()
{
    string a,b;
    int i,c=0;
    cin>>a;
    cin>>b;
    for(i=0;i<a.size();i++)
    {
        if(a[i]==b[i])
        {
            c++;
        }
    }
    cout<<c<<endl;
}


Measured memory_bytes: 256
import sys
from functools import lru_cache, cmp_to_key
from heapq import merge, heapify, heappop, heappush
from math import *
from collections import defaultdict as dd, deque, Counter as C
from itertools import combinations as comb, permutations as perm
from bisect import bisect_left as bl, bisect_right as br, bisect
from time import perf_counter
from fractions import Fraction
# import numpy as np
# sys.setrecursionlimit(int(pow(10,6)))
# sys.stdout = open("out.txt", "w")
mod = int(pow(10, 9) + 7)
mod2 = 998244353
def data(): return sys.stdin.readline().strip()
def out(*var, end="\n"): sys.stdout.write(' '.join(map(str, var))+end)
def L(): return list(sp())
def sl(): return list(ssp())
def sp(): return map(int, data().split())
def ssp(): return map(str, data().split())
def l1d(n, val=0): return [val for i in range(n)]
def l2d(n, m, val=0): return [l1d(n, val) for j in range(m)]

try:
    sys.stdin = open("input.txt", "r")
except:
    pass


# @lru_cache(None)
n=L()[0]
A=L()
print(sum(1 if i%2==0 and A[i]%2==1 else 0 for i in range(n)))

Measured memory_bytes: 10608
#include <string>
#include <vector>
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<stack>
#include<queue>
#include<cmath>
#include<algorithm>
#include<functional>
#include<list>
#include<deque>
#include<bitset>
#include<set>
#include<map>
#include<unordered_map>
#include<cstring>
#include<sstream>
#include<complex>
#include<iomanip>
#include<numeric>
#include<cassert>
#define X first
#define Y second
#define pb push_back
#define rep(X,Y) for (int (X) = 0;(X) < (Y);++(X))
#define reps(X,S,Y) for (int (X) = S;(X) < (Y);++(X))
#define rrep(X,Y) for (int (X) = (Y)-1;(X) >=0;--(X))
#define repe(X,Y) for ((X) = 0;(X) < (Y);++(X))
#define peat(X,Y) for (;(X) < (Y);++(X))
#define all(X) (X).begin(),(X).end()
#define rall(X) (X).rbegin(),(X).rend()
#define eb emplace_back
#define UNIQUE(X) (X).erase(unique(all(X)),(X).end())

using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
template<class T> using vv=vector<vector<T>>;
template<class T> ostream& operator<<(ostream &os, const vector<T> &t) {
os<<"{"; rep(i,t.size()) {os<<t[i]<<",";} os<<"}"<<endl; return os;}
template<class S, class T> ostream& operator<<(ostream &os, const pair<S,T> &t) { return os<<"("<<t.first<<","<<t.second<<")";}
template<class T> inline bool MX(T &l,const T &r){return l<r?l=r,1:0;}
template<class T> inline bool MN(T &l,const T &r){return l>r?l=r,1:0;}
const ll MOD=1e9+7;

int main(){
  ios_base::sync_with_stdio(false);
  cout<<fixed<<setprecision(0);
  int n;
  cin>>n;
  vector<ll> l(n),r(n);
  rep(i,n) cin>>l[i];
  rep(i,n) cin>>r[i];
  vector<ll> t(n,2e9),b(n,1);
  int pre=-1;
  rep(i,n){
    ll a,c;
    if(l[i]>pre){
      a=c=l[i];
      pre=l[i];
    }else{
      a=l[i];
      c=1;
    }
    MN(t[i],a);
    MX(b[i],c);
  }
  pre=-1;
  rrep(i,n){
    ll a,c;
    if(r[i]>pre){
      a=c=r[i];
      pre=r[i];
    }else{
      a=r[i];
      c=1;
    }
    MN(t[i],a);
    MX(b[i],c);
  }
  ll re=1;
  //cout<<t<<b;
  rep(i,n){
    (re*=max(0ll,t[i]-b[i]+1))%=MOD;
  }
  cout<<re<<endl;
  return 0;
}


Measured memory_bytes: 3456
using System;
using System.Collections.Generic;
using System.Linq;

class A
{
	static void Main()
	{
		var n = int.Parse(Console.ReadLine());
		var b = Console.ReadLine().Split().Select(int.Parse).ToList();
		var r = new List<int>();

		for (int k = 0; k < n; k++)
		{
			var j = -1;
			for (int i = b.Count - 1; i >= 0; i--) if (b[i] == i + 1) { j = i; break; }
			if (j == -1) { Console.WriteLine(-1); return; }
			b.RemoveAt(j);
			r.Insert(0, j + 1);
		}
		foreach (var x in r) Console.WriteLine(x);
	}
}


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

using namespace std;
using ll = long long;
using v1 = vector<int>;
using vl = vector<long long>;
using v2 = vector<vector<int>>;
using v3 = vector<vector<char>>;

class DisjointSet{
	public:
		vector<int> rank, p;

		DisjointSet(int size){
			rank.resize(size, 0);
			p.resize(size, 0);
			rep(i, size){
				makeset(i);
			}
		}
		void makeset(int x){
			p[x] = x;
			rank[x] = 0;
		}
		bool same(int x, int y){
			return findSet(x) == findSet(y);
		}
		void unite(int x, int y){
			link(findSet(x), findSet(y));
		}
		void link(int x, int y){
			if(rank[x] > rank[y]){
				p[y] = x;
			}else{
				p[x] = y;
				if(rank[x] = rank[y]){
					rank[y] ++;
				}
			}
		}
		int findSet(int x){
			if(x != p[x]){
				p[x] = findSet(p[x]);
			}
			return p[x];
		}
};

int main(){
	int n, q;
	cin >> n >> q;
	DisjointSet D(n);
	rep(i, q){
		int c, x, y;
		cin >> c >> x >> y;
		if(c == 0){
			D.unite(x, y);
		}else{
			if(D.same(x, y)){
				cout << 1 << endl;
			}else{
				cout << 0 << endl;
			}
		}
	}
}



Measured memory_bytes: 3240
N, K = [int(_) for _ in input().split()]
x = [int(_) for _ in input().split()]
pos_i = -1
for i in range(len(x)):
    if x[i] > 0:
        pos_i = i
        break

min_t = 300000000
if pos_i == -1:
    min_t = -x[-K]
else:
    for i in range(N-K+1):
        if i+K-1 < pos_i:
            min_t = min(min_t, -x[pos_i-K])
        elif pos_i <= i:
            min_t = min(min_t, x[pos_i+K-1])
        else:
            min_t = min(min_t, x[K+i-1]-x[i]*2, x[K+i-1]*2-x[i])

print(min_t)

Measured memory_bytes: 14480
import bisect

N,K = (int(x) for x in input().split())
x = list(map(int, input().split()))
bs = bisect.bisect_left(x,0)
ans = float('inf')
if bs == N:
    print(x[-K]*(-1))
    exit()
else:
    if x[bs] == 0:
        x.pop(bs)
        K -= 1
neg = bs
pos = N - bs
if len(x) == 0 or K == 0:
    print('0')
elif neg == 0:
    print(x[K-1])
else:
    for i in range(min(neg,K)+1):
        if i + pos < K:
                continue
        else:
            if i == 0:
                ans = min(ans,x[bs+K-1])
            elif i == K:
                ans = min(ans,x[bs-K]*(-1))
            else:
                tempn = x[bs-i] * (-1)
                tempp = x[bs+K-i-1]
                ans = min(ans,min(tempn,tempp)*2+max(tempn,tempp))
    print(ans)

Measured memory_bytes: 14384
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
constexpr int mod = 1e9 + 7;

template <typename T, T mod>
class ModuloCombination {
 private:
  std::vector<T> factrial, inverse_factrial;
  T Pow(T x, T y) {
    if (y == 0) return 1;
    if (y % 2 == 0) return Pow(x * x % mod, y / 2);
    return x * Pow(x, y - 1) % mod;
  }

 public:
  ModuloCombination(T n) : factrial(n + 1), inverse_factrial(n + 1) {
    inverse_factrial[0] = factrial[0] = 1;
    for (T i = 1; i <= n; i++) {
      factrial[i] = factrial[i - 1] * i % mod;
      inverse_factrial[i] = Pow(factrial[i], mod - 2);
    }
  }
  T operator()(T n, T k) {
    if (n < 0 || k < 0 || n < k) return 0;
    return factrial[n] * inverse_factrial[k] % mod * inverse_factrial[n - k] % mod;
  }
};

int main() {
  ll n, k;
  cin >> n >> k;
  vector<vector<int>> v(n);
  for (int i = 0; i < n - 1; i++) {
    int a, b;
    cin >> a >> b;
    v[a - 1].push_back(b - 1);
    v[b - 1].push_back(a - 1);
  }

  ModuloCombination<ll, mod> c(k - 1);
  vector<ll> f(n);
  f[0] = 1;
  for (ll i = 1; i <= n - 1; i++) f[i] = f[i - 1] * i % mod;

  function<ll(int i, int j)> dfs = [&](int i, int j) -> ll {
    ll r;
    if (i == j) {
      r = k * (c(k - 1, v[j].size()) * f[v[j].size()] % mod);
    } else {
      r = c(k - 2, v[j].size() - 1) * f[v[j].size() - 1] % mod;
    }
    r %= mod;
    for (auto e : v[j]) {
      if (e == i) continue;
      r *= dfs(j, e);
      r %= mod;
    }
    return r;
  };

  cout << dfs(0, 0) << endl;
}


Measured memory_bytes: 13568
import java.util.Scanner;
public class Main
{
	public static void main(String arg[])
	{
		Scanner in = new Scanner(System.in);
		while(in.hasNext())
		{
			int a[]=new int[5];
			boolean j[]=new boolean[5];
			int f=in.nextInt();
			if(f==0)
				return;
			a[0]=f;
			for(int i=1;i<5;i++)
			{
				a[i]=in.nextInt();
				j[i]=true;
			}
			int c=0;
			for(int i=0;i<5;i++)
			{
				if(a[i]==1&&j[1])
				{
					c++;
					j[1]=false;
				}
				if(a[i]==2&&j[2])
				{
					c++;
					j[2]=false;
				}
				if(a[i]==3&&j[3])
				{
					c++;
					j[3]=false;
				}
			}
			if(c==1||c==3)
				for(int i=0;i<5;i++)
					System.out.println(3);
			else
				if(j[3])
				{
					for(int i=0; i<5;i++)
						if(a[i]==1)
							System.out.println(1);
						else
							System.out.println(2);
				}
				else if(j[2])
				{
					for(int i=0; i<5;i++)
						if(a[i]==3)
							System.out.println(1);
						else
							System.out.println(2);
				}
				else if(j[1])
				{
					for(int i=0; i<5;i++)
						if(a[i]==2)
							System.out.println(1);
						else
							System.out.println(2);
				}
		}
	}
}

Measured memory_bytes: 12000
#include <bits/stdc++.h>
using namespace std;
/*
3 8
3 30
4 50
5 60
*/
const long long INF = 1e18L+9;
int n, W, s;
vector<int> v, w;
vector<long long> dp;
int main () {
  cin >> n >> W;
  w.resize(n);
  v.resize(n);
  for (int i=0; i<n; ++i) {
    cin >> w[i] >> v[i];
    s+=v[i];
  }
  dp.resize(s+5, INF);
  dp[0] = 0;
  for (int i=0; i<n; ++i) {
    for (int va=s-v[i]; va>=0; --va) {
      dp[va+v[i]] = min(dp[va]+w[i], dp[va+v[i]]);
    }
  }
  long long ans = 0;
  for (int i=0; i<=s; ++i) {
    if (dp[i]<=W) {
      ans = max(ans, (long long) i);
    }
  }
  cout << ans;
  return 0;
}


Measured memory_bytes: 1024
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <iomanip>
#include <math.h>
#include <complex>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
#include <bitset>
#include <functional>
#include <assert.h>
#include <numeric>

using namespace std;

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

using ll = long long;
const int inf = 1e9 + 7;
const ll longinf = 1LL << 60;
const ll mod = 1e9 + 7;

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

    string N;
    cin >> N;

    for (int i = 0; i < 3; i++)
    {
        if (N[i] == '7')
        {
            cout << "Yes\n";
            return 0;
        }
    }
    cout << "No\n";
}

Measured memory_bytes: 3648
#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for (int i = 0; i < n; i++) 
int main() {
  int n;
  cin >> n;
  vector<int> p(n);
  REP(i, n) {
    cin >> p.at(i);
  }
  vector<int> q = p;
  sort(q.begin(), q.end());
  vector<int> r;
  bool res = false;
  if (p == q) {
    res = true;
  }
  int c, d;
  REP(i, n - 1) {
    for (int j = i + 1; j < n; j++) {
      r = p;
      c = r.at(i);
      d = r.at(j);
      r.at(i) = d;
      r.at(j) = c;
      if (r == q) {
        res = true;
      }
    }
  }
  if (res) {
    cout << "YES" << endl;
  }
  else {
    cout << "NO" << endl;
  }
}  
  


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define _GLIBCXX_DEBUG
#define INF 1e8
typedef long long int ll;
const double PI = acos(-1);

using Graph = vector<vector<int>>;
int main() {
  double a, b;
  cin >> a >> b;
  for (double i = 10; i <= 1000; ++i) {
    if (floor(i * 0.08) == a && floor(i * 0.1) == b) {
      cout << i << endl;
      return 0;
    }
  }
  cout << "-1" << endl;
}


Measured memory_bytes: 3788
#pragma GCC target("avx2")
#pragma GCC optimization("O3")
#pragma GCC optimization("unroll-loops")
#include <algorithm>
#include <assert.h>
#include <bitset>
#include <cfloat>
#include <complex>
#include <deque>
#include <fstream>
#include <functional>
#include <iomanip>
#include <iostream>
#include <limits.h>
#include <list>
#include <map>
#include <math.h>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <string.h>
#include <time.h>
#include <unordered_map>
#include <unordered_set>
#include <vector>
#define rep(i,n) for(int i=0;i<n;i++)
#define REP(i,n) for(int i=1;i<=n;i++)
#define int long long
#define ll long long
#define mod (int)1000000007
#define P pair<int,int>
#define prique(T) priority_queue<T,vector<T>,greater<T>>
#define all(V) V.begin(),V.end()
#ifdef int
constexpr int INF = LLONG_MAX / 10;
#else
constexpr int INF = INT_MAX / 10;
#endif
constexpr double eps = DBL_EPSILON;
template <class T, class U>
inline bool chmax(T& lhs, const U& rhs) {
	if (lhs < rhs) {
		lhs = rhs;
		return 1;
	}
	return 0;
}
template <class T, class U>
inline bool chmin(T& lhs, const U& rhs) {
	if (lhs > rhs) {
		lhs = rhs;
		return 1;
	}
	return 0;
}
using namespace std;
inline int gcd(int a, int b) {
	while (b) {
		int c = a;
		a = b; b = c % b;
	}
	return a;
}
inline int lcm(int a, int b) {
	return a / gcd(a, b) * b;
}
bool isprime(int n) {
	if (n == 1)return false;
	for (int i = 2; i * i <= n; i++) {
		if (n % i == 0)return false;
	}
	return true;
}
int mypow(int a, int b) {
	if (!b)return 1;
	if (b & 1)return mypow(a, b - 1) * a;
	int memo = mypow(a, b >> 1);
	return memo * memo;
}
int modpow(int a, int b, int m = mod) {
	if (!b)return 1;
	if (b & 1)return modpow(a, b - 1, m) * a % m;
	int memo = modpow(a, b >> 1, m);
	return memo * memo % m;
}
int n;
vector<int> vec[100010];
bool used[100010];
int dfs(int node) {
	used[node] = true;
	int cnt = 0, grundy = 0;
	for (int i : vec[node]) {
		if (!used[i]) {
			cnt++;
			grundy ^= dfs(i) + 1;
		}
	}
	return grundy;
}
signed main() {
	cin >> n;
	rep(i, n - 1) {
		int u, v;
		cin >> u >> v;
		vec[u].push_back(v);
		vec[v].push_back(u);
	}
	if (dfs(1))puts("Alice");
	else puts("Bob");
	return 0;
}

Measured memory_bytes: 8960
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int main()
{
	ios::sync_with_stdio(false),cin.tie(0),cout.tie(0);
	int n,a,b;
	int f=0;
	cin >> n >> a >> b;
	for(int i=a;i<=b;i++){
		if(i%n==0) f=1;
	}
	if(f==1) cout << "OK" << endl;
	else cout << "NG" << endl;
	return 0;
} 

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

int main(void)
{
    int a,b,c,d;
    int x,y;
    cin >> a >> b >> c >> d;
    x = c - a; y = d - b;
    cout << c - y << " " << d + x << " " << a - y << " " << b + x;
    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>

int main(void) {
  int i, j, k, n;
  while( 1 ) {
    scanf("%d", &n);
    if(!n) break;
    int ans = 0, na = 1;
    for(i = 0; i < n; ++i) {
     scanf("%d", &k);
     if(k) ++ans;
     if(k > 1) na = 0;
    }
    if(na) printf("NA\n");
    else printf("%d\n", ans + 1);
  }
  return 0;
}


Measured memory_bytes: 2700
L = [int(input()) for _ in range(5)]
t = 0
L2 = []
for i in range(5):
  if L[i]%10 == 0:
    t += L[i]
  else:
    L2.append(L[i])
if L2 == []:
  print(t)
  exit()
min = L2[0]
for k in range(1,len(L2)):
  if min%10 > L2[k]%10:
    t += min//10*10 + 10
    min = L2[k]
  else:
    t += L2[k]//10*10 + 10
print(t+min)

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using u=unsigned long long;
u M=1000000007;
main(){u n,m,x;std::cin>>n>>m;if(n>m)std::swap(n,m);x=(m-n<2);for(u i=1;i<=n;i++)x*=i,x%=M;x=x*x%M;if(n-m)x*=m;else x*=2;std::cout<<x%M<<"\n";}

Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading.Tasks;

namespace AtCoder.Abc
{
    //問題:https://atcoder.jp/contests/abc171/tasks/abc171_a
    class A_171_αlphabet
    {
        public static void Main(string[] args)
        {
            var sw = new System.IO.StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false };
            Console.SetOut(sw);

            // 文字列の入力
            string s = Console.ReadLine();

            if (Regex.IsMatch(s,"[A-Z]") == true)
            {
                string result = "A";
                Console.WriteLine(result);
            }
           else if (Regex.IsMatch(s, "[a-z]") == true)
            {
                string result = "a";
                Console.WriteLine(result);
            }

            Console.Out.Flush();
        }
    }
}


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

int main(){
	string s,t;
	cin >> s >> t;
	int n = s.size();
	int m = t.size();
	vector<vector<int>> memo(26);
	rep(i,n) memo[s[i] - 'a'].push_back(i);
	rep(i,n) memo[s[i] - 'a'].push_back(i+n);
	int p(0);
	ll ans(0);
	rep(i,m){
		int c = t[i] - 'a';
		if(memo[c].size()==0){
			cout << -1 << endl;
			return 0;			
		}
		p = *lower_bound(memo[c].begin(),memo[c].end(),p)+1;
		if(p >= n){
			p -= n;
			ans += n;
		}
	}
	ans += p;
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 1724
using System;
using System.Numerics;
using System.Linq;
using System.Collections.Generic;
using System.Text;

namespace debug
{

    class ProgramA
    {
        static void Main(string[] args)
        {
            //入力
            string[] s = Console.ReadLine().Split(' ');
            int n = int.Parse(s[0]);
            int m = int.Parse(s[1]);
            int x = int.Parse(s[2]);

            int[,] memo = new int[n, m + 1];
            int[] rikai = new int[m];

            for (int i = 0; i < n; i++)
            {
                string[] a = Console.ReadLine().Split(' ');
                for (int j = 0; j < m + 1; j++)
                    memo[i, j] = int.Parse(a[j]);
            }
            int ans = 10000000;
            

            for(int i = 0; i < (1 << n);i++)
            {
                int count = 0;
                int flag = 0;
                for (int k = 0; k < m; k++)
                {
                    rikai[k] = 0;
                }

                for (int j = 0; j < n; j++)
                {
                    if ((i >> j & 1) == 1)
                    {
                        count += memo[j, 0];//値段を足す
                        for (int k = 0; k < m; k++)
                            rikai[k] += memo[j, k + 1];
                    }
                }

                //理解度判定
                for (int k = 0; k < m; k++)
                {
                    if (rikai[k] < x)
                        flag = 1;


                }

                if (flag == 0)
                    ans = Math.Min(ans, count);

                

            }

            if (ans == 10000000)
                Console.WriteLine("-1");
            else
                Console.WriteLine(ans);
        }
    }
}


Measured memory_bytes: 27564
D, G = [int(_) for _ in input().split()]
PC = [[int(_) for _ in input().split()] for i in range(D)]
P = [p for p, c in PC]
C = [c for p, c in PC]

from heapq import *

h = []

heappush(h, (0, 0, (0,)*D))

result = 0

ef = {}

while h:
    t, score, pat = heappop(h)
    # print(t, score, pat)
    if score >= G:
        result = t
        break

    def add(i, pat, d):
        pat1 = list(pat)
        if pat1[i] +d <= P[i]:
            pat1[i] += d
            pat1 = tuple(pat1)
            if not pat1 in ef:
                t1 = t + d
                score1 = score + (i+1)*100*d
                if pat1[i] == P[i]:
                    score1 += C[i]
                ef[pat1] = t
                heappush(h, (t1, score1, pat1))

    for i in range(D-1, -1, -1):
        if pat[i] < P[i]:
            add(i, pat, 1)
            break

    for i in range(D):
        if pat[i] + 1 < P[i]:
            add(i, pat, P[i] - pat[i])

print(result)


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

int main() {
  vector<int> X(5);
  for (int i = 0; i < 5; i++) cin >> X.at(i);
  for (int i = 0; i < 5; i++) {
    if (X.at(i) == 0) cout << i + 1 << endl;
  }
}

Measured memory_bytes: 3624
#include<iostream>
#include<string>
#include<algorithm>
using namespace std;
static const int N=1000;

int lcs(string X,string Y)
{
  int c[N+1][N+1];
  int m=X.size();
  int n=Y.size();
  int maxl=0;
  X=' '+X;
  Y=' '+Y;
  for(int i=0;i<=m;i++)
    {
      c[i][0]=0;
    }
  for(int j=1;j<=n;j++)
    {
      c[0][j]=0;
    }

  for(int i=1;i<=m;i++)
    {
      for(int j=1;j<=n;j++)
	{
	  if(X[i]==Y[j])
	    {
	      c[i][j]=c[i-1][j-1]+1;
	    }
	  else
	    {
	      c[i][j]=max(c[i-1][j],c[i][j-1]);
	    }
	  maxl=max(maxl,c[i][j]);
	}
    }

  return maxl;
}

int main()
{
  string s1,s2;
  int n; cin >> n;
  for(int i=0;i<n;i++)
    {
      cin>>s1>>s2;
      cout<<lcs(s1,s2)<<endl;
    }
  return 0;
}



Measured memory_bytes: 7068
#include <algorithm>
#include <cassert>
#include <cfloat>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <deque>
#include <iostream>
#include <limits>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <tuple>
#include <unordered_map>
#include <unordered_set>
#include <vector>
 
#define FOR(i,k,n) for (int (i)=(k); (i)<(n); ++(i))
#define rep(i,n) FOR(i,0,n)
#define all(v) begin(v), end(v)
#define debug(x) cerr<< #x <<": "<<x<<endl
#define debug2(x,y) cerr<< #x <<": "<< x <<", "<< #y <<": "<< y <<endl
 
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<vector<int> > vvi;
typedef vector<ll> vll;
typedef vector<vector<ll> > vvll;
typedef deque<bool> db;
template<class T> using vv=vector<vector< T > >;

int main() {
  int n;
  scanf("%d", &n);
  vi a(3*n);
  rep (i, 3*n) {
    scanf("%d", &a[i]);
  }
  sort(all(a));
  ll ans = 0;
  for (int i = n; i < 3*n; i += 2) {
    ans += a[i];
  }
  printf("%lld\n", ans);

  return 0;
}


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

int main() {
    int n;
    long long k;
    cin >> n >> k;
    vector<int> tele(n + 1);
    for (int i = 1; i <= n; i++) cin >> tele.at(i);
    vector<int> dis(n + 1, -1);
    dis.at(1) = 0;
    int loop, T = 0, town = 1, ans = 1;
    while(1) {
        town = tele.at(town);
        T++;
        if (dis.at(town) >= 0) {
            loop = town;
            T -= dis.at(loop);
            break;
        }
        dis.at(town) = T;
    }

    if (k < dis.at(loop)) for (int i = 0; i < k; i++) ans = tele.at(ans);
    else {
        k -= dis.at(loop);
        k %= T;
        ans = loop;
        for (int i = 0; i < k; i++) ans = tele.at(ans);
    }
    
    cout << ans << endl;
}

Measured memory_bytes: 4832
using System;
using System.Collections.Generic;
namespace 令和{
    class ABC{
        static void Main(){
            int n = int.Parse(Console.ReadLine());
            int[] u = new int[n];
            int[] v = new int[n];
            int[] w = new int[n];
            //bool[] isEven = new bool[n-1];
            List<int[]>[] tonari = new List<int[]>[n+1];
            int[] ans = new int[n+1];
            for(int i=0;i<n+1;i++){
                tonari[i] = new List<int[]>();
                ans[i] = -1;
            }
            for(int i=1;i<n;i++){
                string[] uvw = Console.ReadLine().Split();
                u[i] = int.Parse(uvw[0]);
                v[i] = int.Parse(uvw[1]);
                w[i] = int.Parse(uvw[2]);
                tonari[u[i]].Add(new int[2]{v[i],w[i]});
                tonari[v[i]].Add(new int[2]{u[i],w[i]});
                /*
                if(w[i]%2==0){
                    isEven[i] = true;
                }else{
                    isEven[i] = false;
                }
                */
            }
            Queue<int> q = new Queue<int>();
            q.Enqueue(1);
            ans[1] = 0;
            while(q.Count!=0){
                int p = q.Dequeue();
                foreach(int[] tnr in tonari[p]){
                    if(ans[tnr[0]]==-1){
                        if(tnr[1]%2==0){
                            if(ans[p]==0){
                                ans[tnr[0]] = 0;
                            }else{
                                ans[tnr[0]] = 1;
                            }
                        }else{
                            if(ans[p]==0){
                                ans[tnr[0]] = 1;
                            }else{
                                ans[tnr[0]] = 0;
                            }
                        }
                        q.Enqueue(tnr[0]);
                    }
                }
            }
            for(int i=0;i<n;i++){
                Console.WriteLine(ans[i+1]);
            }


        }
    }
}

Measured memory_bytes: 38472
#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 2e9
#define ALL(v) v.begin(), v.end()
using namespace std;
typedef long long ll;


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

  int ans = 0;
  REP(i,k+1) {
    REP(j,k+1) {
      int z = s - i -j;
      if(z >= 0 && z <= k) {
        ans++;
      }
    }
  }

  cout << ans << endl;
  
}

Measured memory_bytes: 256
#include <iostream>
#include <utility>
#include <algorithm>

using namespace std;

int gcd(int a,int b) {
	if(a % b == 0) return b;
	return gcd(b,a%b);
}

int main() {
	int n,a[100000];
	cin >> n;
	for(int i = 0;i < n;i++) cin >> a[i];
	sort(a,a+n);
	int r = a[0];
	for(int i = 0;i < n;i++) {
		r = gcd(r,a[i]);
	}
	cout << r << endl;
}


Measured memory_bytes: 640
#include<bits/stdc++.h>
using namespace std;
int main()
{
	string t;
	cin>>t;
	int ans=0;
	for(int i=0;i<t.size();i++)
		if(t[i]=='?')
			t[i]='D';
	cout<<t<<endl;
	return 0;
}

Measured memory_bytes: 3696
#include<cstdio>
#include<cstring>
#include<cmath>
#include<algorithm>
#define For(i,j,k) for(int i=j;i<=k;i++)
#define Dow(i,j,k) for(int i=j;i>=k;i--)
#define LL long long
using namespace std;

const int N = 511;
int n,m;
char s[N][N];

int main() {
	scanf("%d%d", &n, &m);
	For(i, 1, n) scanf("%s", s[i]+1);
	For(i, 1, n) {
	  For(j, 1, m) 
	    if(j == 1) putchar('.');
	    else if(j == m) putchar('#');
	    else if( i&1 ) putchar('#');
	    else if(s[i][j]=='#') putchar('#');
	    else putchar('.');
	  putchar('\n');
	}
	putchar('\n');
	For(i, 1, n) {
	  For(j, 1, m) 
	  	if(j == m) putchar('.');
	  	else if(j == 1) putchar('#');
	  	else if( !(i&1) ) putchar('#');
	  	else if(s[i][j]=='#') putchar('#');
	  	else putchar('.');
	  putchar('\n');
	}
	return 0;
}


Measured memory_bytes: 1024
#include<iostream>
#include<cstdio>
#include<vector>
#include<algorithm>
#include<bitset>
#include<deque>
#include<cstring>
#include<cassert>
#include<climits>

using namespace std;
int n,m;
string s[501];
int dp[2][1<<24];
//t=100?????????0????????¨,
//t=101?????????0??¨2????????¨
int N=-1;
bool tmp[501];
bool s2[501][501];
int s3[501];//??¬???????????¶???????????´??°?????????????????????
int dfs(int h,string t){//h????????±???,t????????¨????????¬??????
	if(h==n){	
		//cout<<t<<endl;
		int cnt=0;
		//for(int i=0;i<m;i++)tmp[i]=0;
		memset(tmp,0,sizeof tmp);

		for(int i=0;i<n;i++){
			bool f=t[i]-'0';
			if(f==1){//?????¨????????¬????????????

				for(int j=0;j<m;j++)tmp[j]=tmp[j]^s2[i][j];
			//tmp^=s2[i];
				cnt++;
			}
		}

		for(int i=0;i<m;i++)if(tmp[i])return 0;
		//for(int i=0;i<m;i++)cout<<tmp[i];cout<<" "<<t<<" "<<cnt<<endl;
		return cnt;
	}

	return max(dfs(h+1,t+"1"),dfs(h+1,t+"0"));
}

int twoToTen(string x){
	int sum=0;
	int xs=x.size();
	for(int i=xs;i>=0;i--){
		if(x[i]-'0'==1)sum+=1<<(xs-i-1);
	}
	return sum;
}


int dpp(){
	//for(int i=0;i<(1<<m);i++)
	//dp[0][i]=dp[1][i]=N;
	memset(dp[0],-1,sizeof dp[0]);
	memset(dp[1],-1,sizeof dp[1]);

		dp[0][0]=0;

	for(int i=0;i<n;i++){
		for(int j=0;j<1<<m;j++){
		if((i+1)%2==1){
			if(dp[0][j]!=N){
				//cout<<i<<" "<<j<<"A"<<endl;
				int now=twoToTen(s[i]);//????????¬????????????10????????§?????????????????????
				dp[1][j^now]=max(dp[1][j^now],dp[0][j]+1);
				dp[1][j]=max(dp[1][j],dp[0][j]);
			}

		}
		else{
				if(dp[1][j]!=N){
				//cout<<i<<" "<<j<<"A"<<endl;
				int now=twoToTen(s[i]);//????????¬????????????10????????§?????????????????????
				dp[0][j^now]=max(dp[0][j^now],dp[1][j]+1);
				dp[0][j]=max(dp[0][j],dp[1][j]);
		}
		}
	}
	}

	return dp[n%2][0];
}


int main(){
	while(cin>>n>>m,n||m){

	for(int i=0;i<n;i++)cin>>s[i];
	for(int i=0;i<n;i++){
		for(int j=0;j<m;j++)s2[i][j]=s[i][j]-'0';
	}
	//for(int i=0;i<n;i++)s3[i]=twoToTen(s[i]);

	if(n<=21)cout<<dfs(0,"")<<endl;
	else cout<<dpp()<<endl;
	}
	return 0;
}

Measured memory_bytes: 134492
import sys
sys.setrecursionlimit(2**31-1)
input = sys.stdin.readline
write = sys.stdout.write
LMIIS = lambda : list(map(int,input().split()))
II = lambda : int(input())
dbg = lambda *something : print(*something) if DEBUG is True else 0
DEBUG = True



MOD = 10**9 + 7
class ModInt:

    def __init__(self, x):
        self.x = x.x if isinstance(x, ModInt) else x % MOD

    __str__ = lambda self:str(self.x)
    __repr__ = __str__
    __int__ = lambda self: self.x
    __index__ = __int__

    __add__ = lambda self, other: ModInt(self.x + ModInt(other).x)
    __sub__ = lambda self, other: ModInt(self.x - ModInt(other).x)
    __mul__ = lambda self, other: ModInt(self.x * ModInt(other).x)
    __pow__ = lambda self, other: ModInt(pow(self.x, ModInt(other).x, MOD))
    __mod__ = lambda self, other: ModInt(self.x % ModInt(other).x)
    __truediv__ = lambda self, other: ModInt(self.x * pow(ModInt(other).x, MOD - 2, MOD))
    __floordiv__ = lambda self, other: ModInt(self.x // ModInt(other).x)
    __radd__ = lambda self, other: ModInt(other + self.x)
    __rsub__ = lambda self, other: ModInt(other - self.x)
    __rpow__ = lambda self, other: ModInt(pow(other, self.x, MOD))
    __rmod__ = lambda self, other: ModInt(other % self.x)
    __rmul__ = lambda self, other: ModInt(other * self.x)
    __rtruediv__ = lambda self, other: ModInt(other * pow(self.x, MOD - 2, MOD))
    __rfloordiv__ = lambda self, other: ModInt(other // self.x)

    __lt__ = lambda self, other: self.x < ModInt(other).x
    __gt__ = lambda self, other: self.x > ModInt(other).x
    __le__ = lambda self, other: self.x <= ModInt(other).x
    __ge__ = lambda self, other: self.x >= ModInt(other).x
    __eq__ = lambda self, other: self.x == ModInt(other).x
    __ne__ = lambda self, other: self.x != ModInt(other).x


def main():
    S = input()

    dp = [[0] * 13  for _   in range(len(S)-1)]
    dp[0] = [ModInt(0) for _ in range(13)]
    
    if S[0] == '?':
        for i in range(10):
            dp[0][i] = ModInt(1)
    else:
        dp[0][int(S[0])] = ModInt(1)

    for i in range(1,len(S)-1):
        if S[i] == '?':
            for j in range(13):
                for k in range(10):
                    dp[i][(j * 10 + k) % 13 ] += dp[i-1][j]
        else:
            for j in range(13):
                dp[i][ (j* 10 + int(S[i])) % 13 ] += dp[i-1][j]
        

    print(dp[len(S)-2][5])









    pass
if __name__ == '__main__':
    main()

Measured memory_bytes: 143428
#!/usr/bin/env ruby

N, K = gets.chomp.split.map(&:to_i)

LR = []

K.times do |i|
  LR[i] = gets.chomp.split.map(&:to_i)
end

LR.sort_by!(&:first)

ds = [0, 1]

2.upto(N) do |i|
  dpi = 0

  LR.each do |(l, r)|
    right = i - l
    break if right < 0

    left = i - r - 1
    left = 0 if left < 0

    dpi += ds[right] - ds[left]
  end

  ds[i] = (dpi + ds[i-1]) % 998244353
end

puts (ds[N] - ds[N-1]) % 998244353


Measured memory_bytes: 16312
N = int(input())
A_list = sorted(list(map(int, input().split())), reverse=True)

res = A_list[0]
cnt = 2
for i in range(1, N):
    if N - cnt >= 2:
        res += 2 * A_list[i] 
        cnt += 2
    elif N - cnt == 1:
        res += A_list[i]
        break
    else:
        break
print(res)

Measured memory_bytes: 31612
import math
N, D = map(int, input().split())
A = []
for i in range(N):
  A.append(list(map(int, input().split())))
count = 0
for i in range(N):
  for j in range(i+1,N):
    length = 0
    for d in range(D):
      length += (A[i][d]-A[j][d])**2
    length = math.sqrt(length)
    if length.is_integer():
      count += 1
print(count)

Measured memory_bytes: 3064
#include<stdio.h>
int main(){
  int n,m,x,ans=1e9+7,i,j,k,a[20][20],b[20],c[20],s;
  scanf("%d %d %d",&n,&m,&x);
  for(i=0;i<n;i++){
    scanf("%d",&c[i]);
    for(j=0;j<m;j++)scanf("%d",&a[i][j]);
  }
  for(i=0;i<(1<<n);i++){
    for(j=0;j<n;j++)b[j]=0;
    for(j=s=0;j<n;j++){
      if((i&(1<<j))==0)continue;
      s+=c[j];
      for(k=0;k<m;k++)b[k]+=a[j][k];
    }//printf("%d:",i);
    //for(j=0;j<m;j++)printf("%d ",b[j]);printf("\n");
    for(j=0;j<m;j++){
      if(b[j]<x)goto NEXT;
    }
    if(ans>s)ans=s;
  NEXT:;
  }
  printf("%d\n",ans>1e9?-1:ans);
  return 0;
}


Measured memory_bytes: 1732
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll mod=1e9+7ll;

string s;
int cnt;

int main(){

cin.tie(0);
ios::sync_with_stdio(false);

cin>>s;

if(s[0]=='1') cnt++;
if(s[1]=='1') cnt++;
if(s[2]=='1') cnt++;

cout<<cnt<<endl;

}



Measured memory_bytes: 256
import sys
import decimal # 10進法に変換，正確な計算

def input():
    return sys.stdin.readline().strip()

def main():
    n = int(input())
    s = list(input())
    al = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
    l = len(s)
    for i in range(l):
        for k in range(26):
            if s[i] == al[k]:
                if k + n > 25:
                    s[i] = al[k+n-26]
                    print(s[i], end="")
                else:
                    s[i] = al[k+n]
                    print(s[i], end="")
                break
    
    
main()

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

int ball[10];

bool solve(int i, int a, int b){
	if (i == 10) return true;
	bool ans = false;
	if (a < ball[i]) ans = solve(i + 1, ball[i], b);
	if (b < ball[i])ans = solve(i + 1, a, ball[i]);
	return ans;
}

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

	for (int i = 0; i < n; i++){
		for (int j = 0; j < 10; j++){
			cin >> ball[j];
		}
		if (solve(0, 0, 0)) cout << "YES" << endl;
		else cout << "NO" << endl;
	}

	return 0;
}
//beatmaniaIIDX 23th copula

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

int main(){
    string s,t; cin>>s>>t;
    bool flag =1;
    if(s.size()+1!=t.size()) flag = 0;
    for(int i=0; i<s.size(); i++){
        if(s[i]!=t[i]) flag=0;
    }
    cout <<(flag?"Yes":"No") << endl;
}

Measured memory_bytes: 3628
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main {

	public static void main(String[] args) throws NumberFormatException, IOException {
		// TODO 自動生成されたメソッド・スタブ
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

		while(true){
			int n = Integer.parseInt(br.readLine());

			if(n == 0){
				break;
			}

			int low = -1_000_000_003;
			int high = 1_000_000_003;
			final int x = Integer.MIN_VALUE;

			String[] tmpArray = br.readLine().split(" ");
			int input[] = new int[n];
			for(int i = 0; i < n; i++){
				if(tmpArray[i].equals("x")){
					input[i] = x;
				}
				else {
					input[i] = Integer.parseInt(tmpArray[i]);
				}
			}

			int xCount = 0;
			boolean fault = false;
			for(int i = 0; i < n; i++){
//				System.out.println(low + " "+ high);
				if(input[i] == x){
					if(i != n - 1 && input[i + 1] == x){
						fault = true;
						break;
					}

					if(i % 2 == 1){
						if(i != n - 1){
							low = Math.max(low, input[i + 1]);
						}
						low = Math.max(low, input[i - 1]);
					}
					else {
						if(i != n - 1){
							high = Math.min(high, input[i + 1]);
						}
						if(i != 0){
							high = Math.min(high, input[i - 1]);
						}
					}
//					xCount++;
					continue;
				}

				if(i % 2 == 0){
					if(i != n - 1 && input[i + 1] != x && input[i] >= input[i + 1]){
						fault = true;
						break;
					}
				}
				else {
					if(i != n - 1 && input[i + 1] != x && input[i] <= input[i + 1]){
						fault = true;
						break;
					}
				}
			}
//			System.out.println("loop has ended "+ low + " "+ high);

			if(fault){
				System.out.println("none");
			}
			else if(low + 2 == high){
				System.out.println(low + 1);
			}
			else if(high - low <= 1){
				System.out.println("none");
			}
			else {
				System.out.println("ambiguous");
			}

		}
	}

}



Measured memory_bytes: 33632
#include <bits/stdc++.h>
  
using namespace std;
  
template<class T> void ckmin(T &a, T b) { a = min(a, b); }
template<class T> void ckmax(T &a, T b) { a = max(a, b); }
  
#define pb push_back
#define mp make_pair
#define cotu cout
#define itn int
#define Red ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define F first
#define S second
#define sz(x) (int)x.size()
#define all(x) (x).begin(), (x).end()
#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, n) for(int i = (a); i <=(n); ++i)
#define repst(i, n) for(auto it = n.begin(); it != n.end(); ++it)
#define Repr(i, a, n) for(int i = (n); i >= (a); --i)
  
#define ordered_set tree<int , null_type,less<int >, rb_tree_tag,tree_order_statistics_node_update> 
  
#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp> 
using namespace __gnu_pbds; 
  
typedef long long ll;
typedef pair<ll, ll> pll;
typedef pair<int, int> pii;
  
const int inf = int(1e9);
const int mod = inf + 7;
const int N = 1e6 + 555; // TL MB
const double PI = acos(-1.0);
 
void mul(ll &x, ll y){
	x *= y;
	if(x >= mod) x %= mod;
}
 
void add(ll &x, ll y){
	x += y;
	if(x >= mod) x -= mod;
	if(x < 0) x += mod;
}
ll bp(ll a, ll n){
	ll r = 1;
	while(n){
		if(n & 1) mul(r, a);
		mul(a, a);
		n >>= 1;
	}
	return r;
}


void solve()
{
	double l;
	cin >> l;
	l /= 3;
	l = l * l * l;
	cout << fixed << setprecision(7) << l;
}


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

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
    public static void main(final String[] args) {
        final Scanner scanner = new Scanner(System.in);
        final int h = scanner.nextInt();
        final int w = scanner.nextInt();
        final int k = scanner.nextInt();

        final int[][] table = new int[h][w];
        int count = 1;
        for (int i = 0; i < h; i++) {
            final char[] array = scanner.next().toCharArray();
            for (int j = 0; j < w; j++) {
                if (array[j] == '#') {
                    table[i][j] = count++;
                }
            }
        }

        for (int i = 0; i < h; i++) {
            for (int j = 1; j < w; j++) {
                if (table[i][j] == 0 && table[i][j - 1] != 0) {
                    table[i][j] = table[i][j - 1];
                }
            }
        }

        for (int i = 0; i < h; i++) {
            for (int j = w - 2; j >= 0; j--) {
                if (table[i][j] == 0 && table[i][j + 1] != 0) {
                    table[i][j] = table[i][j + 1];
                }
            }
        }

        for (int i = 1; i < h; i++) {
            for (int j = 0; j < w; j++) {
                if (table[i][j] == 0 && table[i - 1][j] != 0) {
                    table[i][j] = table[i - 1][j];
                }
            }
        }

        for (int i = h - 2; i >= 0; i--) {
            for (int j = 0; j < w; j++) {
                if (table[i][j] == 0 && table[i + 1][j] != 0) {
                    table[i][j] = table[i + 1][j];
                }
            }
        }

        for (int i = 0; i < h; i++) {
            for (int j = 0; j < w; j++) {
                System.out.print(table[i][j] + " ");
            }
            System.out.println();
        }
    }
}


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

#define d(x) cerr << #x ":" << x << endl;
#define dd(x, y) cerr << "(" #x "," #y "):(" << x << "," << y << ")" << endl
#define rep(i, n) for (int i = (int)(0); i < (int)(n); i++)
#define repp(i, a, b) for (int i = (int)(a); i < (int)(b); i++)
#define all(v) v.begin(), v.end()
#define dump(v)                  \
    cerr << #v ":[ ";            \
    for (auto macro_vi : v) {    \
        cerr << macro_vi << " "; \
    }                            \
    cerr << "]" << endl;
using lint       = long long;
const int INF    = 1e9;
const lint LINF  = 1e18;
const lint MOD   = 1e9 + 7;
const double EPS = 1e-10;

int main() {
    char s;
    cin >> s;
    s = s + 1;
    cout << s << endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <vector>
#include <queue>
#include <cmath>
#include <algorithm>
#include <functional>
using namespace std;
#define rep(i,n) for(int i=0;i<(n);++i)
#define rep1(i,n) for(int i=1;i<=(n);++i)
#define all(c) (c).begin(),(c).end()
#define pb push_back
#define fs first
#define sc second
#define show(x) cout << #x << " = " << x << endl
int main(){
	while(true){
		int x,y,s,mx=0;
		cin>>x>>y>>s;
		if(s==0) break;
		int k[1010];
		rep(i,s+1) k[i]=i*(100+x)/100;
		rep1(i,s-1){
			int id=lower_bound(k,k+s+1,i)-k;
			if(k[id]!=i) continue;
			int id2=lower_bound(k,k+s+1,s-i)-k;
			if(k[id2]!=s-i) continue;
			mx=max(mx,id*(100+y)/100+id2*(100+y)/100);
		}
		cout<<mx<<endl;
	}
}

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

int main(){
	int n;
	cin >> n;
	vector<int> a(n+1);
	rep(i, n) cin >> a[i+1];
	vector<int> b(n+1);
	for(int i = n; i >= 1; --i){
		int sum = 0;
		for(int j = i+i; j <= n; j += i){
			sum ^= b[j];
		}
		b[i] = sum^a[i];
	}
	vector<int> ans;
	for( int i = 1; i <= n; i++ ){
		if(b[i]) ans.push_back(i);
	}
	cout << ans.size() << endl;
	rep(i, ans.size()){
		printf("%d%c", ans[i], i+1 == ans.size()?'\n':' ');
	}
	return 0;
}


Measured memory_bytes: 3064
#!/usr/bin/env python3
import sys

MOD = 1000000007  # type: int
import math
from itertools import accumulate

def mod_factorial(n):
    value = 1
    for i in range(n,0,-1):
        value*=i
        value%=MOD

    return value

def solve(N: int, x: "List[int]"):
    dif_x = []
    for i in range(1,N):
        dif_x.append(x[i]-x[i-1])

    # factmod[i] = (N-1)!/iをMODで割ったあまり
    factmod = [0]*(N)
    factmod[1] = mod_factorial(N-1)
    
    for i in range(2,N):
        factmod[i] = factmod[1]*pow(i,MOD-2,MOD)
    
    for i in range(2,N):
        factmod[i] += factmod[i-1]
        factmod[i]%=MOD
        
    answer = 0

    for i in range(N-1):
        answer += factmod[i+1]*dif_x[i]
        answer %= MOD
    
    print(answer)
    return


def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    x = [int(next(tokens)) for _ in range(N)]  # type: "List[int]"
    solve(N, x)

if __name__ == '__main__':
    main()


Measured memory_bytes: 23012
#include <bits/stdc++.h>
#pragma GCC optimize("Ofast,no-stack-protector,unroll-loops")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#define ll          long long
#define pb          push_back
#define eb 			emplace_back
#define mp 			make_pair
#define pii         pair<ll,ll>
#define vi          vector<ll>
#define vii         vector<pii>
#define mi          map<ll,ll>
#define mii         map<pii,ll>
#define all(a)      (a).begin(),(a).end()
#define fi          first
#define si          second
#define sz(x)       (ll)x.size()
#define endl        '\n'
#define checkbit(n, b) ((n >> b) & 1)
#define mod        1000000007
#define inf        1000000000000000000
#define puts(n)		cout<<n;
#define rep(i,a,b)  for(ll i=a;i<b;i++)
#define setbits(x) __builtin_popcount(x)
#define mset(m,v) memset(m,v,sizeof(m))
using namespace std;
int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	ll k;
	cin>>k;
	ll num=0,ans=0;
	bool viz[k]={},flag=true;
	while(flag){
		num = ((num*10)%k + 7)%k;
		ans++;
		if(num==0) break;
		if(viz[num]) flag=false;
		viz[num]=true;
	}
	if(flag) cout<<ans;
	else cout<<-1;
	
	
	
	return 0;
}

Measured memory_bytes: 4620
N, M, X = map(int, input().split())
A = []
INF = 1e18
for i in range(N):
    a = list(map(int, input().split()))
    A.append(a)
ans = INF
for S in range((1<<N)):
    cost = 0
    unst = [0 for i in range(M)]
    for i in range(N):
        if S & (1<<i):
            cost += A[i][0]
            for j in range(M):
                unst[j] += A[i][j+1]
    flag = 1
    for i in range(M):
        if unst[i] < X:
            flag = 0
            break
    if flag:
        if ans > cost:
            ans = cost
if ans == INF:
    print(-1)
else:
    print(ans)

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

int main()
{
	int N, D;
    cin >> N >> D;
  	int x[N], y[N];
    for(int i = 0; i < N; i++){
    	cin >> x[i] >> y[i];
    }
  	int s = 0;
  	for(int i = 0; i < N; i++){
      if(sqrt(pow(x[i], 2) + pow(y[i], 2)) <= D){
      	s++;
      }
    }
  	cout << s << endl;
  return 0;
}

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

int main() {
  string str;
  cin >> str;
  char c = str.at(2);
  char d = str.at(3);
  char e = str.at(4);
  char f = str.at(5);
  if (c != d) {
  cout << "No" << endl;
  }
  else if (e != f) {
  cout << "No" << endl;
  }
  else {
  cout << "Yes" << endl;
  }
}


Measured memory_bytes: 256
#coding:utf-8

N, W = map(int, raw_input().split(" "))
items = [tuple(map(int, raw_input().split(" "))) for _ in range(N)]
dic = {}

def search(i, j):
    if i == N:
        return 0
    if (i, j) not in dic:
        dic[(i, j)] = search(i + 1, j)
        w, v = items[i]
        if j + w <= W:
            dic[(i, j)] = max(dic[(i, j)] , search(i + 1, j + w) + v)
    return dic[(i, j)]

print search(0, 0)


Measured memory_bytes: 20284
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define mod 1000000007
signed main()
{
    int n,i,j,k;
    cin>>n;
    int ans[10001]={0};
    for(i=1;i<=100;i++)
    {
        for(j=1;j<=100;j++)
        {
            for(k=1;k<=100;k++)
            {
                int c=(i*i)+(j*j)+(k*k)+(i*j)+(j*k)+(k*i);
                if(c<=10000)
                ans[c]++;
            }
        }
    }
    for(i=1;i<=n;i++)
    cout<<ans[i]<<endl;
    return 0;
}


Measured memory_bytes: 3480