akhauriyash/Code-Regression huggingface dataset:
/*{{{*/
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<string>
#include<iostream>
#include<sstream>
#include<set>
#include<map>
#include<queue>
#include<bitset>
#include<vector>
#include<limits.h>
#include<assert.h>
#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 REPP(I, A, B) for (int I = (A); I < (B); ++I)
#define FOR(I, A, B) for (int I = (A); I <= (B); ++I)
#define FORS(I, S) for (int I = 0; S[I]; ++I)
#define RS(X) scanf("%s", (X))
#define SORT_UNIQUE(c) (sort(c.begin(),c.end()), c.resize(distance(c.begin(),unique(c.begin(),c.end()))))
#define GET_POS(c,x) (lower_bound(c.begin(),c.end(),x)-c.begin())
#define CASET int ___T; scanf("%d", &___T); for(int cs=1;cs<=___T;cs++)
#define MP make_pair
#define PB push_back
#define MS0(X) memset((X), 0, sizeof((X)))
#define MS1(X) memset((X), -1, sizeof((X)))
#define LEN(X) strlen(X)
#define F first
#define S second
using namespace std;
typedef long long LL;
typedef unsigned long long ULL;
typedef long double LD;
typedef pair<int,int> PII;
typedef vector<int> VI;
typedef vector<LL> VL;
typedef vector<PII> VPII;
typedef pair<LL,LL> PLL;
typedef vector<PLL> VPLL;
template<class T> void _R(T &x) { cin >> x; }
void _R(int &x) { scanf("%d", &x); }
void _R(LL &x) { scanf("%lld", &x); }
void _R(double &x) { scanf("%lf", &x); }
void _R(char &x) { scanf(" %c", &x); }
void _R(char *x) { scanf("%s", x); }
void R() {}
template<class T, class... U> void R(T &head, U &... tail) { _R(head); R(tail...); }
template<class T> void _W(const T &x) { cout << x; }
void _W(const int &x) { printf("%d", x); }
void _W(const LL &x) { printf("%lld", x); }
void _W(const double &x) { printf("%.16f", x); }
void _W(const char &x) { putchar(x); }
void _W(const char *x) { printf("%s", x); }
template<class T,class U> void _W(const pair<T,U> &x) {_W(x.F); putchar(' '); _W(x.S);}
template<class T> void _W(const vector<T> &x) { for (auto i = x.begin(); i != x.end(); _W(*i++)) if (i != x.cbegin()) putchar(' '); }
void W() {}
template<class T, class... U> void W(const T &head, const U &... tail) { _W(head); putchar(sizeof...(tail) ? ' ' : '\n'); W(tail...); }
#ifdef HOME
 #define DEBUG(...) {printf("# ");printf(__VA_ARGS__);puts("");}
#else
 #define DEBUG(...)
#endif
int MOD = 1e9+7;
void ADD(LL& x,LL v){x=(x+v)%MOD;if(x<0)x+=MOD;}
/*}}}*/
const int SIZE = 1e6+10;
int N,A,B,C;
int l[SIZE];
int an=1e9;
void dfs(int id,int a,int b,int c,int merge_time){
    if(id==N){
        if(!a||!b||!c)return;
        an=min(an,merge_time*10+abs(a-A)+abs(b-B)+abs(c-C));
        return;
    }
    dfs(id+1,a+l[id],b,c,merge_time+(a!=0));
    dfs(id+1,a,b+l[id],c,merge_time+(b!=0));
    dfs(id+1,a,b,c+l[id],merge_time+(c!=0));
    dfs(id+1,a,b,c,merge_time);
}
int main(){
    R(N,A,B,C);
    REP(i,N)R(l[i]);
    dfs(0,0,0,0,0);
    W(an);
    return 0;
}


Measured memory_bytes: 256
import queue

class pair:
    def __init__(self, x, y):
        self.x = x
        self.y = y

    def getter(self):
        return [self.x, self.y]

def solvmaiz(maze, x ,y):
    dx = [1,0,-1,0]
    dy = [0,1,0,-1]
    q = queue.Queue()
    INF = 10**5
    d = [[INF for x in range(W)]for y in range(H)]
    q.put(pair(x,y))
    d[y][x] = 0
    goal = [0, 0]
    while(not q.empty()):
        p = q.get().getter()
        for i in range(4):
            nx = p[0] + dx[i]
            ny = p[1] + dy[i]
            if nx >= 0 and nx < W and ny >= 0 and ny < H and d[ny][nx] == INF and maze[ny][nx] != '#':
                q.put(pair(nx,ny))
                d[ny][nx] = d[p[1]][p[0]] + 1
        goal[0] = p[1]
        goal[1] = p[0]

    return d[goal[0]][goal[1]]

if __name__ == "__main__":
    H, W = map(int, input().split())
    maze =[]
    for i in range(H):
        j = input()
        maze.append([])
        for k in j:
            maze[i].append(k)
    ans = 0
    for y in range(H):
        for x in range(W):
            if maze[y][x] == '#':
                continue
            ans = max(ans, solvmaiz(maze, x, y))
    print(ans)

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

int i,j,k;
int ans1,ans2,a;

int main(){
	ans1=ans2=0;
	for(i=0;i<4;i++)scanf("%d",&a),ans1+=a;
	for(i=0;i<4;i++)scanf("%d",&a),ans2+=a;
	printf("%d\n",(ans1>=ans2)?(ans1):(ans2));
	
	return 0;
}

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

template<typename T>
T get_value(std::istream& is);

int main() {
  std::ios_base::sync_with_stdio(false);
  std::cin.tie(nullptr);

  int K, X;
  cin >> K >> X;

  cout << (500 * K >= X ? "Yes" : "No") << '\n';

  return 0;
}

template<typename T>
inline T get_value(std::istream& is)
{
  T v;
  is >> v;
  return v;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
//型に気を付けよう
//a=61
#define rep(i,n) for(int i=2;i<=n;i++)
typedef long long  ll;
typedef long double  ld;
typedef pair<int,int> pairii;
const double pi=3.1415926535;
const ll  mod=1000000007;
//桁数指定　cout << fixed << setprecision(2)
int main() {
  ll l[90];
  int n;
  cin>>n;
  l[0]=2;
  l[1]=1;
  rep(i,86){
    l[i]=l[i-1]+l[i-2];
  }
  cout<<l[n];
}

Measured memory_bytes: 256
# AtCoder Beginner Contest 145
# C - Average Length
# https://atcoder.jp/contests/abc145/tasks/abc145_c
from itertools import permutations

N, *A = map(int, open(0).read().split())
X = A[0::2]
Y = A[1::2]

def distance(a, b):
    return ((X[a]-X[b])**2 + (Y[a]-Y[b])**2)**0.5


length = 0
cnt = 0
for P in permutations(range(N)):
    cnt += 1
    prev = P[0]
    for i in P[1:]:
        length += distance(prev, i)
        prev = i

print(length/cnt)


Measured memory_bytes: 3064
import java.util.Scanner;
public class Main {
	
	static char[] k = {'a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z'};
	

	public static void main(String[] args) {
		Scanner stdIn = new Scanner(System.in);
		String str = stdIn.next();
		int q = stdIn.nextInt();
		for(int i = 0; i < q; i++) {
			String stt = stdIn.next();
			if(stt.equals("print")) {
				int a = stdIn.nextInt();
				int b = stdIn.nextInt();
				String tmp = str.substring(a, b+1);
				System.out.println(tmp);
			}
			else if(stt.equals("reverse")) {
				int a = stdIn.nextInt();
				int b = stdIn.nextInt();
				String tmp = str.substring(a,b+1);
				String tmp2 = "";
				for(int j = tmp.length()-1; j >= 0; j--) {
					tmp2 += String.valueOf(tmp.charAt(j));
				}
				String ck1 = str.substring(0, a);
				String ck2 = str.substring(b+1,str.length());
				str = ck1 + tmp2 + ck2;
			}
			else if(stt.equals("replace")) {
				int a = stdIn.nextInt();
				int b = stdIn.nextInt();
				String p = stdIn.next();
				String ck1 = str.substring(0, a);
				String ck2 = str.substring(b+1,str.length());
				str = ck1 + p + ck2;
				
			}
		}
	}
}

Measured memory_bytes: 41144
import java.io.*;

public class Main {
  public static void main(String[] args) throws IOException {
    BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
    
    String[] data = br.readLine().split(" ");
    int x = Integer.parseInt(data[0]);
    int y = Integer.parseInt(data[1]);
    int z = Integer.parseInt(data[2]);
    
    System.out.println(z + " " + x + " " + y);
  }
}

Measured memory_bytes: 21072
n=int(input())
a=[int(i) for i in input().split()]
suf=[0]*n
for i in range(n-2,-1,-1):
    if(a[i]>=a[i+1]):
        suf[i]=suf[i+1]+1
    else:
        suf[i]=0
print(max(suf))


Measured memory_bytes: 14224
#include <bits/stdc++.h>
using namespace std;
int main(void){
    string s;
    cin>>s;
    if (s!="keyence") {
        for (int i=0;i+1<s.size();i++) {
            for (int j=i+1;j<s.size();j++) {
                string tmp=s;
                tmp.erase(i,j-i);
                if (tmp=="keyence") {
                    cout<<"YES"<<endl;
                    return 0;
                }
            }
        }
        cout<<"NO"<<endl;
    } else {
        cout<<"YES"<<endl;
    }
}

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

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

    if (x == 3 || x == 5 || x == 7) cout << "YES" << endl;
    else cout << "NO" << endl;
    return 0;
}


Measured memory_bytes: 256
def main():
    h, w, k = map(int, input().split())
    grid = ["."*(w+2)]+["."+input()+"." for _ in [0]*h]+["."*(w+2)]
    visit = [[False]*(w+2) for _ in [0]*(h+2)]
    for i in range(h+2):
        for j in range(w+2):
            if grid[i][j] == "S":
                start = (i, j)
                break
    visit[start[0]][start[1]] = True
    q = [start]
    for i in range(k):
        q2 = []
        while q:
            x, y = q.pop()
            if x-1 >= 0:
                if grid[x-1][y] == "." and visit[x-1][y] is False:
                    q2.append((x-1, y))
                    visit[x-1][y] = True
            if x+1 <= h+1:
                if grid[x+1][y] == "." and visit[x+1][y] is False:
                    q2.append((x+1, y))
                    visit[x+1][y] = True
            if y-1 >= 0:
                if grid[x][y-1] == "." and visit[x][y-1] is False:
                    q2.append((x, y-1))
                    visit[x][y-1] = True
            if y+1 <= w+1:
                if grid[x][y+1] == "." and visit[x][y+1] is False:
                    q2.append((x, y+1))
                    visit[x][y+1] = True
        q = q2
    dist = 10**9
    for i in range(h+2):
        for j in range(w+2):
            if visit[i][j]:
                dist = min([dist, i, h+1-i, j, w+1-j])
    print((max(dist-1, 0)-1)//k+2)


main()

Measured memory_bytes: 72540
#include <iostream>
#include <string>
#include <vector>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <algorithm>
#include <functional>
#include <cstdio>
#include <climits>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;

int main() {
    int N;
    cin >> N;
    vector<int> X(N);
    vector<int> Y(N);
    for (int i = 0; i < N; i++) {
        cin >> X[i];
        Y[i] = X[i];
    }
    sort(Y.begin(), Y.end());
    int a = Y[N/2 - 2];
    int b = Y[N/2 - 1];
    int c = Y[N/2];

    for (int i = 1; i <= N; i++) {
        int x = X[i - 1];
        int ans;
        if (x >= c) {
            cout << b << endl;
        } else {
            cout << c << endl;
        }
    }

    return 0;
}


Measured memory_bytes: 3712
#include <bits/stdc++.h>
#define MOD 1000000007
 
using namespace std;
 
typedef long long ll;
typedef pair<int,int> ii;

string s;
int dp[100001][13];

int rek(int cd, int rem) {
    if (cd >= s.length())
        return rem == 5;
    if (dp[cd][rem] == -1) {
        int rez = 0;
        if (s[cd] == '?') {
            for (int ctr1 = 0; ctr1 < 10; ++ctr1) {
                rez = (rez + rek(cd + 1,((10 * rem) + ctr1) % 13)) % MOD;
            }
        } else {
            rez = rek(cd + 1, ((10 * rem) + s[cd] - '0') % 13);
        }
        dp[cd][rem] = rez;
    }
    return dp[cd][rem];
}
 
int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    memset(dp, -1, sizeof(dp));

    cin >> s;
    cout << rek(0, 0);
    
    return 0;
}

Measured memory_bytes: 13392
#include <bits/stdc++.h>
#define ll long long int
#define yorn(f) cout<<((f)?"Yes":"No")<<endl
#define YORN(f) cout<<((f)?"YES":"NO")<<endl
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using namespace std;
int main()
{
    int n;
    cin >> n;
    yorn(n == (100 * (n % 10) + 10 * ((n/10) % 10) + n / 100)); {

    }
    return 0;
}

Measured memory_bytes: 3624
#include <bits/stdc++.h>
using namespace std;
#define rep(i,a,b) for(int i=(a);i<=(b);i++)
#define ll long long
#define pll pair<ll, ll>
#define pii pair<int,int>
#define pb push_back
#define F first
#define S second
#define mod 1000000007
#define maxn 100005
#define inf 1e18
#define boost ios::sync_with_stdio(false);cin.tie(0)
#define fr freopen("source.txt","r",stdin),freopen("output.txt","w",stdout)
#define SET(a,b) memset(a,b,sizeof(a))
vector<ll>adj[maxn];
ll n,m;
ll dp[maxn];
ll dfs(ll i){
    ll &ans=dp[i];
    if(ans!=-1) return ans;
    ans=0;
    for(auto p:adj[i]) ans=max(ans,dfs(p));
    ans++;
    return ans;
}
int main()
{
    boost;
    ll i,a,b;
    cin>>n>>m;
    for(i=0;i<m;i++){
        cin>>a>>b;
        adj[a].pb(b);
    }
    SET(dp,-1);
    ll ans=0;
    for(i=1;i<=n;i++){
        ans=max(ans,dfs(i));
    }
    cout<<ans-1;
}


Measured memory_bytes: 7936
#include <algorithm>
#include <cstring>
#include <deque>
#include <functional>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <vector>
using namespace std;
using ll = long long;

int main() {
  int N;
  while (cin >> N) {
    vector<pair<int, int>> X(N);
    for (int i = 0; i < N; i++) {
      int x;
      cin >> x;
      X[i] = make_pair(x, i);
    }
    sort(X.begin(), X.end());
    vector<int> ans(N);
    for (int i = 0; i < N; i++) {
      if ((N - 1) / 2 < i) {
        ans[X[i].second] = X[(N - 1) / 2].first;
      } else {
        ans[X[i].second] = X[(N - 1) / 2 + 1].first;
      }
    }
    for (int x : ans) {
      cout << x << endl;
    }
  }
  return 0;
}


Measured memory_bytes: 4480
#include<bits/stdc++.h>
#define ll long long
#define fast_i_o ios_base::sync_with_stdio(false);cin.tie(NULL);
using namespace std;
int main()
{
    ll a,b,c,k,sum=0;
    cin>>a>>b>>c>>k;
    if((k-a)>0)
    {
        sum+=a;
        k-=a;
    }
    else
    {
        sum+=k;
        k=0;
    }
    if((k-b)>0)
    {
        k-=b;
    }
    else
    {
        k=0;
    }
    if((k-c)>0)
    {
        sum-=c;
        k-=c;
    }
    else
    {
        sum-=k;
        k=0;
    }
   cout<<sum<<"\n";
}


Measured memory_bytes: 3588
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <bitset>
#include <math.h>
#include <iomanip>
#include <queue>
#define inp(X) cin >> X
#define out(X) cout << X << endl
#define rep(i,n) for(int i=0;i<n;i++ )
#define rep2(i,f,n) for(int i=f;i<n;i++ )
#define MAX(A) *max_element(A.begin(),A.end())
#define MIN(A) *min_element(A.begin(),A.end())
#define SORT(A) sort(A.begin(),A.end())
using namespace std;

typedef long long int ll;
#define MOD 1000000007
#define INF 1000000001

ll gcd(ll x, ll y){
	if(y==0) return x;
	return gcd(y,x%y);
}

bool bfs(vector<vector<int>> g, vector<int> &dist, int sv)
{
	queue<int> q;
	q.push(sv);
	dist[sv]=0;
	while(!q.empty()){
		int now = q.front(); q.pop();
		for(auto v : g[now]){
			if(dist[v]!=-1) continue;
			dist[v] = dist[now]+1;
			q.push(v);
		}
	}
}

int main(void) {
	int n; cin >> n;
	vector<int> p(n);
	vector<pair<int,int>> swp;
	rep(i,n){
		cin >> p[i];
		if(p[i]!=i+1) swp.emplace_back(i+1,p[i]);
	}
	if(swp.size()==0) out("YES");
	else if(swp.size()==2 && swp[0].first == swp[1].second) out("YES");
	else out("NO");
}




Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define mp make_pair
#define pb push_back
#define all(x) x.begin(), x.end()
#define fi first
#define se second
#define print(x,y) (cout << (x) << (y))
#define inf INT_MAX
#define sz(x) (ll)x.size()
#define boost ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef vector<int> vi;
typedef pair<int,int> pii;
typedef pair< int , pii> piii;
typedef pair<int,bool> pib;
typedef vector<pii> vii;
typedef vector<pib> vib;
typedef vector<vi> vvi;
typedef vector<vii> vvii;
typedef vector<string> vs;
typedef vector<ll> vll;
typedef pair<string,string> pss;
typedef vector<pss> vss;
const int MOD = 1e9 + 7; //998244353;


int main(){
    int n , k;
    cin >> n >> k;
    int dp[n];
    vi a(n);
    for(int &i : a) cin >> i;
    fill(dp , dp + n , inf);
    dp[0] = 0;
    for(int i = 1;i<n;i++){
        for(int j = max(0 , i-k);j<i;j++){
            dp[i] = min(dp[i] , dp[j] + abs(a[i] - a[j]));
        }
    }
    cout << dp[n-1];
}





Measured memory_bytes: 1024
#include<stdio.h>
int main()
{
    int N,M,i,sum;
    scanf("%d%d",&N,&M);
    int a[M];
    sum=0;
    for(i=0;i<M;i++){
        scanf("%d",&a[i]);
        sum+=a[i];
    }
    if(sum>N)
       printf("-1\n");
    else
        printf("%d\n",N-sum);
    return 0;
}


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

int main(){
    int N;
    cin >> N;
    int64_t count = 0;
    vector<int> vec(N);
    for (int i = 0; i < N; i++){
        cin >> vec.at(i);
    }
    for(int i = 0; i < N - 1; i++){
        if(vec.at(i) > vec.at(i + 1)){
            count += vec.at(i) - vec.at(i + 1);
            vec.at(i + 1) = vec.at(i);
        }
    }
  cout << count << endl;
}



Measured memory_bytes: 4052
//
//  main.cpp
//  CoderProj
//
//  Created by Minoru Hayashi on 2020/05/02.
//  Copyright © 2020 Minoru Hayashi. All rights reserved.
//
//  ABC165
//
//

#include <bits/stdc++.h>
using namespace std;

#define REP(i,n) for (int i=0; i<(n); i++)
#define REP2(i,x,n) for (int i=x; i<(n); i++)
#define ALL(n) begin(n), end(n)

using ll = long long;

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

// const ll INF = 1LL<<60;
// const int INF = 1<<29;
// const int MOD = 1000000007;
//#define __DBG__

int N, M, Q;
vector<int> a(55);
vector<int> b(55);
vector<int> c(55);
vector<int> d(55);
int A[11];

ll ans = 0;

void dfs(int p, int n){  
  // term
  if(p>=N){
    ll tmp = 0;
    REP(i,Q){
      if(A[b[i]]-A[a[i]]==c[i]){
        tmp += d[i];
      }
    }
//    REP(i,N){cout << A[i];}
//    cout << ":" << tmp << endl;
    chmax(ans, tmp);
    return;
  }
  A[p] = n;
  p++;
  REP2(i,n,M+1){
    dfs(p, i);
  }
  return;
}



void solve(void){
  
  cin >> N >> M >> Q;

  REP(i,Q){
    cin >> a[i] >> b[i] >> c[i] >> d[i];
    a[i]--;
    b[i]--;
  }
    
  dfs(0,1);
  cout << ans << endl;
  
  return;
}



#define TESTCASES 1

int main() {

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

    REP(i,TESTCASES){
      solve();
    }
 
    return 0;
}




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

int main()
{
	int n, m;
	cin >> n >> m;
	//(ai,bi)をペアとして入力
	vector<pair<int, int>> k;
	int a, b;
	for (int i = 0; i < m; i++)
	{
		cin >> a >> b;
		k.push_back({ a,b });
	}
	//並び変え
	sort(k.begin(), k.end());

	

	int start,ans;
	ans = 0;
	start = n;
	for (int i = m-1; i>=0 ; i--)
	{
		if (start >= k[i].second)
		{
			ans++;
			start = k[i].first;
		}

	}

	cout << ans;

	return 0;
}

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

int main(){
    int A,B;
    cin >> A >> B;A --;B --;
    bool b[50][100],w[50][100];
    fill(b[0],b[50],false);
    fill(w[0],w[50],false);
    for(int j = 0;j < 50;j += 2){
        for(int i = 0;i < 100;i += 2){
            if(A==0&&B==0) break;
            if(B>0){b[j][i]=true;B --;}
            if(A>0){w[j+1][i]=true;A --;} 
        }
        if(A==0&&B==0) break;
    }
    cout << 100 << " " << 100 << endl;
    for(int j = 0;j < 50;j ++){
        for(int i = 0;i < 100;i ++){
            if(b[j][i]) cout << '#';
            else cout << '.';
        }
        cout << endl;
    }
    for(int j = 0;j < 50;j ++){
        for(int i = 0;i < 100;i ++){
            if(w[j][i]) cout << '.';
            else cout << '#';
        }
        cout << endl;
    }
    return 0;
}

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

int main() {
  int a, b, c, d;
  
  cin >> a >> b >> c >> d;
  
  int left = a + b;
  int right = c + d;
  
  if (left > right)
    cout << "Left" << endl;
  else if (left == right)
    cout << "Balanced" << endl;
  else 
    cout << "Right" << endl;
}

Measured memory_bytes: 256
n , m = map(int,input().split())
arr = list(map(int,input().split()))
add = sum(arr)
miniVotes = add/(4*m)
cnt = 0
for i in range(len(arr)):
	if arr[i]>=miniVotes:
		cnt+=1
if(cnt>=m):
	print("Yes")
else:
	print("No")

Measured memory_bytes: 38256
a, b, c, x = 4.times.map { gets.to_i }
cnt = 0
(0..a).each do |i|
    (0..b).each do |j|
        (0..c).each do |k|
            cnt += 1 if i * 500 + j * 100 + k * 50 == x
        end
    end
end

puts cnt

Measured memory_bytes: 1916
#include <iostream>
#include <algorithm>
#include <set>

using namespace std;
using ll = long long;

const ll INF = 1LL << 50;

int main() {
    int A, B, Q;
    cin >> A >> B >> Q;

    set<ll> s = {-INF, INF}, t = {-INF, INF};
    for (int i = 0; i < A; ++i) {
        ll a;
        cin >> a;
        s.insert(a);
    }
    for (int i = 0; i < B; ++i) {
        ll a;
        cin >> a;
        t.insert(a);
    }

    for (int q = 0; q < Q; ++q) {
        ll x;
        cin >> x;
        auto sitr = s.upper_bound(x);
        ll sr = *sitr, sl = *(--sitr);
        auto titr = t.upper_bound(x);
        ll tr = *titr, tl = *(--titr);

        cout << min({
                    min(sr - x, x - tl) + (sr - tl),
                    min(tr - x, x - sl) + (tr - sl),
                    max(sr, tr) - x,
                    x - min(sl, tl),
                })
             << endl;
    }
    return 0;
}


Measured memory_bytes: 10752
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cmath>
#include<cstring>
#include<cstdlib>
#include<cctype>
#include<string>
#include<vector>
#include<queue>
#include<deque>
#include<map>
#include<set>
#include<stack>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;
typedef pair<int,int> PII;
typedef vector<int> VI;
#define fast ios::sync_with_stdio(0),cin.tie(0)
#define fi first
#define se second
#define pb push_back
#define mk make_pair
#define ls (rt<<1)
#define rs (rt<<1|1)
#define All(a) (a).begin(),(a).end()
#define clr(a) memset((a),0,sizeof(a))
#define FOR(i,a,b) for(int i=(a);i<=(b);++i)
#define REP(i,a,b) for(int i=(a);i>=(b);--i)
#define FOR_edge(i,u)  for(int i=hd[u];i;i=e[i].nxt)
const int inf=0x3f3f3f3f;
const ll INF=0x3f3f3f3f3f3f3f3f;
const int dx[]={1,-1,0,0};
const int dy[]={0,0,-1,1};

inline char in() {
	static char buf[10001],*p1=buf,*p2=buf;
	return p1==p2&&(p2=(p1=buf)+fread(buf,1,10000,stdin),p1==p2)?EOF:*p1++;
}
template <class Tp> inline void read(register Tp &s) {
	s=0;
	register bool neg=0;
	register char c;
	while(!isdigit(c=in())) if(c=='-') neg=1;
	while(s=(s<<3)+(s<<1)+c-48,isdigit(c=in()));
	s=(neg?-s:s);
}
template <class Tp> inline void write(register Tp x) {
	if(x<0) putchar('-'),x=-x;
	if(x>9) write(x/10);
	putchar(x%10+'0');
}
template <class Tp> inline void print(const Tp &x,const char &end) {write(x); putchar(end);}
template <class Tp> inline Tp pow(register Tp x,register Tp p,const Tp &mod) {
	register Tp res=1;
	for(;p;p>>=1,x=(x*x)%mod) if(p&1) res=(res*x)%mod;
	return res;
}
inline int comp(const double &x,const double &y) {
	const double d=x-y,eps=1e-8;
	return (d<=eps&&d>=-eps)?0:(d>eps?1:-1);
}
template <class Tp> inline Tp sqr(const Tp &x) {return x*x;}
template <class Tp> inline Tp gcd(const Tp &x,const Tp &y) {return(y==0?x:gcd(y,x%y));}
template <class Tp> inline Tp inv(const Tp &x,const Tp &MOD) {return POW(x,MOD-2,MOD);}
template <class Tp> inline Tp lowbit(const Tp &x) {return x&-x;}


int n,a[3005];
int main() {
	scanf("%d",&n);
	int ans=0;
	FOR(i,1,n) scanf("%d",&a[i]),ans+=a[i];
	printf("%d",ans-n);
	return 0;
}

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

int findNumOfDigit(long int x);
int max(int x, int y);
int f(long int a, long int b);


int main()
{
    long int n;
    long int b;
    int minF;
    int tempF;

    scanf("%ld", &n);
    minF = findNumOfDigit(n); // dummy
    for (int i = 1; i <= sqrt(n); i++)
    {
	b = n / i;
	if (n == i * b)
	{
	    tempF = f(i, b);
	    if (tempF < minF)
	    {
		minF = tempF;
	    }
	}
    }

    printf("%d\n", minF);
    
    return 0;
}

int findNumOfDigit(long int x)
{
    return log10(x) + 1;
}

int max(int x, int y)
{
    if (x > y)
    {
	return x;
    }
    else
    {
	return y;
    }
}

int f(long int a, long int b)
{
    return max(findNumOfDigit(a), findNumOfDigit(b));
}


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

int main(){
    
    int64_t X;
    cin >> X;

    int64_t money=100;
    int64_t year=0;

    while (money<X){
        money *= 1.01;
        year++;
    }

    cout << year << endl;
    return 0;
}

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

using namespace std;

int main(void)
{
    string S;
    cin >> S;

    long long int sum = 0;

    for (int i = 0; i < 1 << S.length() - 1; i++)
    {
        vector<int> value;
        for (int j = 0; j < S.length() - 1; j++)
        {
            if (!(i & 1 << j))
                continue;
            value.push_back(j);
        }

        int index = 0;
        for (int i = 0; i < value.size(); index = value[i] + 1, i++)
        {
            sum += atoll(S.substr(index, value[i] + 1 - index).c_str());
        }
        sum += atoll(S.substr(index).c_str());

        if (value.size() == S.size() - 1)
            break;
    }

    cout << sum << endl;

    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
int main(void){

    int H,W,i,j;
    while(1){
    
        scanf("%d %d",&H,&W);
        if(H == 0 && W == 0)break;
        else{
          for(i=1;i<=H;i++){
              for(j=1;j<=W;j++){
                  if((i+j) % 2 == 0) putchar('#');
                  else putchar('.');
              }
            printf("\n"); 
          }
        }
        printf("\n");
    }
    return 0;
}

Measured memory_bytes: 576
#!/usr/bin/env python3
import collections
import itertools as it
import math
#import numpy as np
 
#  = input()
#  = int(input())
a, b, c, d  = map(int, input().split())
#  = list(map(int, input().split()))
#  = [int(input()) for i in range(N)]
#
# c = collections.Counter()

def gcd(a, b):
    while b:
        a, b = b, a % b
    return a

#a,bの最小公倍数
def lcm(a, b):
    return a * b // gcd (a, b)

nlcmc = b // c
nlcmd = b // d
nlcmcd = b // lcm(c, d)
nb = b - (nlcmc + nlcmd - nlcmcd)

a -= 1
nlcmc = a // c
nlcmd = a // d
nlcmcd = a // lcm(c, d)
na = a - (nlcmc + nlcmd - nlcmcd)

print(nb - na)


Measured memory_bytes: 3316
#include <bits/stdc++.h>
#include <math.h>
#include <cmath>

using namespace std;
using ll =long long;
using vi = vector<int>; 
using vvi = vector<vi>; 
using vl = vector<ll>; 
using vvl = vector<vl>; 
using vs = vector<string>;
using vvs = vector<vs>; 
using vc = vector<char>;
using vvc = vector<vc>; 
using vb = vector<bool>;
using vvb = vector<vb>; 

#define rep(i,n) ;for( int i =0; i < n ; i ++)
#define all(a) a.begin(),a.end()
#define pb(a) push_back(a)
#define pd(a) printf("%.10f\n",a)
#define mem(a) memset(a,0,sizeof(a))
#define f(i,a,b) for(int i=a;i<b;i++)
#define pri(a)  printf("%.14lf\n",a);
#define MOD 1000000007
bool is_int_lround(double x){
  return std::lround(x)==x;
}
ll keta(ll x){
  ll n=0;
  while(x>0){
    x /=10 ;
    n ++;
  }
  return n;
}

ll conbi(int n,int m){
  
  cin>>n>>m;
  vector<ll> a(100);
  a[0] =1;
  for(int i=0;i<14;i++){
    a[i+1]=a[i]*(i+1);
  }
  return a[n] /(a[m] *a[n-m]);
}

long long modpow(long long a, long long n, long long mod) {
    long long res = 1;//繰り返し二乗法
    while (n > 0) {
        if (n & 1) res = res * a % mod;
        a = a * a % mod;
        n >>= 1;
    }
    return res;
}
ll kaijoMOD(ll x){
  ll z=1;
  if(x==0){
    return 1;
  }
  while(x>0){
    z *=x;
    z %=MOD;
    x--;
  }
  return z;
}
ll yakusu_num(ll n){
  vl yakusu(n+1,1);
  for(ll i=2;i*i<=n;i++){ 
    while(n%i==0){
      n /=i;
      yakusu[i]++;
    }
  }
  if(n!=1)yakusu[n]++;
  ll num=1;
  for(ll i=0;i<=n;i++){
    num*=yakusu[i];
  }
  return num;
}

int H,W;
vs s(50);
vi dv ={-1,0,1,0};vi du={0,-1,0,1};
int cnt=1;
int dfs(int u,int v){
  s[u][v]='.';
  
  rep(i,4){
   
      int nu =u +du[i],nv=v+dv[i];
      if(nu<0||nu>=H||nv<0||nv>=W)continue;
      if(s[nu][nv]=='.')continue;
      cnt ++;
      dfs(nu,nv);
    
  }
  return cnt;

}
int keta_wa(int x){
  int tot=0;
  while(x>0){
    tot +=x%10;
    x/=10;
  }
  return tot;
}

//vc alp ={'a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z'};
//vc Alp ={'A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z'};
//cout<<""<<endl;
int main(){
  ll X;cin>>X;
  ll tot=0;
  for(ll i=0;i<100000000000;i++){
    tot +=i+1;
    if(tot>=X){
      tot =tot-i-1;
      tot =tot-i;
      cout<<i+1<<endl;
      break;
    }
  }
}
   





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

int main(void){
	int n, k, i;
	int x[100000];
	scanf("%d%d", &n, &k);
	for(i=0; i<n; i++){
		scanf("%d", x+i);
	}
	int l=n-k+1;
	int min=INT_MAX;
	for(i=0; i<l; i++){
		int now;
		if(x[i]>=0){
			now = x[i+k-1];
		}else if(x[i+k-1]<=0){
			now = -x[i];
		}else if(-x[i]<=x[i+k-1]){
			now = -x[i]*2 + x[i+k-1];
		}else{
			now = x[i+k-1]*2 - x[i];
		}
		if(now<min) min=now;
	}
	printf("%d\n", min);
}


Measured memory_bytes: 512
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii =  pair<int, int>;
using pll =  pair<long long, long long>;
constexpr char ln =  '\n';
constexpr long long MOD = 1000000007LL;
constexpr long long INF = 1000000009LL;
#define all(x) (x).begin(),(x).end()
#define rep(i,n) for(int i=0;i<(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<int> A(n); rep(i, n) cin >> A[i];

    ll no = 1;
    for(int a: A){
        if(a%2==0) no *= 2; 
    }
    ll res = pow(3, n) - no;
    cout << res << ln;
}


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

int main(){
    LL N;
    cin >> N;
    vector<LL>  a(N+1), b(N+1), d(N+1, 0);
    for(int i = 1;i <= N;i++)    cin >> a[i];
    for(int i = 1;i <= N;i++)    cin >> b[i];
    for(int i = 1;i <= N;i++)    d[i] = a[i]-b[i];
    sort(d.begin()+1, d.end());
    LL lsum = 0;
    LL rsum = 0;
    int lid = 0, rid = 0;
    for(int i = 1;i <= N;i++){
        if(d[i] < 0){
            lsum += d[i];
            lid = i;
        }
    }
    for(int i = N;i >= 0;i--){
        if(rsum >= -lsum){
            rid = i+1;
            break;
        }
        rsum += d[i];
    }
    if(rid == 0)   cout << -1 << endl;
    else    cout << (N+1)-rid+lid << endl;
}

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

int main()
{
  int N, ans;
  double T, A;
  cin >> N >> T >> A;
  double temp = 1e9 + 7;

  for (int i = 0; i < N; i++)
  {
    double H;
    cin >> H;
    double buf = abs(A - (T - (H * 0.006)));
    if (temp >= buf)
    {
      ans = i + 1;
      temp = buf;
    }
  }
  cout << ans << endl;
}


Measured memory_bytes: 3740
#include <iostream>
#include <string>
#include <sstream>
#include <algorithm>
#include <vector>
#include <utility>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <ctime>
#include <cstdlib>
#include <map>
#include <set>
#include <stack>
#include <queue>
 
using namespace std;
 
#define pb(n)	push_back(n)
#define mp(n,m) make_pair(n,m)
#define fi 	first
#define se 	second
#define all(r) (r).begin(),(r).end()
 
#define REP(i,s,e)	for(int i=(s); i<(e); i++)
#define rep(i,n)	REP(i,0,n)
#define REPE(i,s,e)	for(int i=s; i>e; i--)
#define repe(i,n)	REPE(i,n,-1)


typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
 
typedef vector<vi> vvi;
 
const int IMAX=((1<<30)-1)*2+1;
const int INF=100000000;
const double EPS=1e-10;
//int mod=1000000007
 


int main(){
	string s;
	cin>>s;
	rep(i,s.size()){
		s[i]=(s[i]-'A'+26-3)%26+'A';
	}
	cout<<s<<endl;
}

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

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

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int a, b, c;
  cin >> a >> b >> c;
  if ((a - b) <= c) {
    cout << c - (a - b) << endl;
  } else {
    cout << 0 << endl;
  }
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n - 1; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define FORR(i, m, n) for(int i = m; i >= n; i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define ll long long
#define pb(a) push_back(a)

ll mod = 1e09;

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

  string s;
  cin >> s;

  REP(i, s.size()){
    if(i % 2 == 0) cout << s[i];
  }
  return 0;
}


Measured memory_bytes: 592
#include <iostream>
#include <vector>
#include <set>
#include <algorithm>
using namespace std;

int main() {
  
  
    int array[101];
  
    int a;
    int b;
    int c;
    int d;
 
  for (int i = 0; i < 101; ++i) {
    
     array[i] = 0;
  }
  
   cin >> a >> b >> c >> d;
  
  for (int i = a; i < b+1; ++i) {
    
    array[i] = 1;
    
    
    
  }
  
   for (int i = c; i < d+1; ++i) {
    
    array[i] = array[i] + 1;
     
   
    
  }
  
   int ans = 0;
  
   for (int i = 0; i < 101; ++i) {
    
      if (array[i]==2){
        
        ans = ans + 1;
        
      }
     
   
  }
  
    if (ans != 0){
      cout << ans - 1 << endl;
    }else{
       cout << ans << endl;
    }
    

  
  return 0;
}

Measured memory_bytes: 256
import numpy as np

n,s=map(int,input().split())
a=list(map(int,input().split()))

dp=[np.zeros(s+1,dtype=np.int64) for _ in range(n+1)]
for i in range(n+1):
    dp[i][0]=1
ans=0

for i,w in enumerate(a):
    dp[i]+=dp[i-1]
    dp[i][w:]+=dp[i-1][:-w]
    dp[i]%=998244353
    ans+=dp[i][-1]
    ans%=998244353

print(ans)

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

// iterator
#define REP(i,init, n) for(lli i=init;i<n;i++)
#define REPE(i,init, n) for(lli i=init;i<=n;i++)
#define REPIT(it,container) for(auto it = container.begin(); it != container.end(); it++)
#define REPIT_R(it,container) for(auto it = container.rbegin(); it != container.rend(); it++)

// input
#define cin1(x)             cin >> x
#define cin2(x, y)          cin >> x >> y
#define cin3(x, y, z)       cin >> x >> y >> z
#define ncin1(n, x)         REP(i, 0, n) {cin1(x[i]);}
#define ncin2(n, x, y)      REP(i, 0, n) {cin2(x[i], y[i]);}
#define ncin3(n, x, y, z)   REP(i, 0, n) {cin3(x[i], y[i], z[i]);}

// output
#define cout1(x)         cout << #x << ": " << x << endl;
#define cout2(x, y)      cout << #x << ": " << x << ", " << #y << ": " << y << endl;
#define cout3(x, y, z)   cout << #x << ": " << x << ", " << #y << ": " << y << ", " << #z << ": " << z << endl;;
#define ncout1(n, x)     REP(i, 0, n) {cout << #x << "[" << i << "]: "<< x[i] << endl;}

#define coutp(p)         cout << #p << ":" <<  " (" << p.first << ", " << p.second << ")" << endl;

// sort
#define sort_r(x, y)        sort(x, y, greater<lli>()); // 降順(5,4,3,,,)

#define ARRAY_LENGTH(array) (sizeof(array) / sizeof(array[0]))

typedef long long int lli;
typedef pair<lli, lli> P;
typedef tuple<lli, lli, lli> tup;

int main() {
    string s;
    cin1(s);
    if (s == "Sunny")
        cout << "Cloudy" << endl;
    else if (s == "Cloudy")
        cout << "Rainy" << endl;
    else
        cout << "Sunny" << endl;

}


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

using namespace std;
typedef long long ll;

ll d[100000], sabun[100000];
ll N;

int main() {
	cin >> N;
	ll goukei = 0;
	for (int i = 0; i < N; i++) {
		cin >> d[i];
		goukei += d[i];
	}
	ll kaisuu = goukei / (N * (N + 1) / 2);
	if (goukei % (N * (N + 1) / 2) != 0) {
		cout << "NO" << endl;
		return 0;
	}
	//差分取り
	for (int i = 0; i < N - 1; i++) {
		sabun[i] = d[i + 1] - d[i] - kaisuu;
	}
	ll ans = 0;
	sabun[N - 1] = d[0] - d[N - 1] - kaisuu;
	for (int i = 0; i < N; i++) {
		if (abs(sabun[i]) % N != 0) {
			cout << "NO" << endl;
			return 0;
		}
		ans += abs(sabun[i] / N);
	}
	if(ans == kaisuu)cout << "YES" << endl;
	else cout << "NO" << endl;
	return 0;
}

Measured memory_bytes: 1792
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using VI = vector<int>;
using VL = vector<ll>;
template<class T> using PQ = priority_queue<T, vector<T>, greater<T>>;
#define FOR(i,a,n) for(int (i)=(a);(i)<(n);++(i))
#define eFOR(i,a,n) for(int (i)=(a);(i)<=(n);++(i))
#define rFOR(i,a,n) for(int (i)=(n)-1;(i)>=(a);--(i))
#define erFOR(i,a,n) for(int (i)=(n);(i)>=(a);--(i))
#define each(i, a) for(auto &i : a)
#define SORT(i) sort((i).begin(),(i).end())
#define rSORT(i,a) sort((i).begin(),(i).end(),(a))
#define all(i) (i).begin(),(i).end()
#define out(y,x) ((y) < 0 || h <= (y) || (x) < 0 || w <= (x))
#define line cout << "------------------------\n" 
#define ENDL(i,n) ((i) == (n) - 1 ? "\n" : " ")
#define stop system("pause") //comment out this on AOJ.
constexpr ll INF = 1000000000;
constexpr ll LLINF = 1LL << 60;
constexpr ll mod = 1000000007;
constexpr ll MOD = 998244353;
constexpr ld eps = 1e-10; //1e-9?
constexpr ld pi = 3.1415926535897932;
template<class T>inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; }return false; }
template<class T>inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; }return false; }
inline void init() { cin.tie(nullptr); cout.tie(nullptr); ios::sync_with_stdio(false); cout << fixed << setprecision(15); }
template<class T>inline istream& operator>>(istream& is, vector<T>& v) { for (auto& elemnt : v)is >> elemnt; return is; }
template<class T, class U>inline istream& operator>>(istream& is, pair<T, U>& p) { is >> p.first >> p.second; return is; }
template<class T>inline vector<T> vec(size_t a) { return vector<T>(a); }
template<class T>inline vector<T> defvec(T def, size_t a) { return vector<T>(a, def); }
template<class T, class... Ts>inline auto vec(size_t a, Ts... ts) { return vector<decltype(vec<T>(ts...))>(a, vec<T>(ts...)); }
template<class T, class... Ts>inline auto defvec(T def, size_t a, Ts... ts) { return vector<decltype(defvec<T>(def, ts...))>(a, defvec<T>(def, ts...)); }

int main() {
    init();

    int a, b; cin >> a >> b;
    cout << (b <= a * 500 ? "Yes\n" : "No\n");
}

Measured memory_bytes: 384
#include<bits/stdc++.h>
using namespace std;
#define FOR(i,r,n) for(ll i = (ll)(r); i < (ll)(n); i++)
#define RFOR(i,r,n) for(ll i=(ll)(n-1);i>=r;i--)
#define REP(i,n) FOR(i,0,n)
#define RREP(i,n) RFOR(i,0,n)
#define ALL(x) x.begin(),x.end()
#define RALL(x) x.rbegin(),x.rend()
typedef long long int ll;
typedef vector<ll> vi;
typedef vector<pair<ll, ll> > vp;
typedef vector<string> vs;
typedef vector<char> vc;
typedef list<ll> lst;
typedef pair<ll, ll> P;
const long long INF = numeric_limits<ll>::max();
const long long MOD = 1000000007;
const long double PI = 3.1415926;
template <class T> T &chmin(T &a, const T &b) { return a = min(a, b); }
template <class T> T &chmax(T &a, const T &b) { return a = max(a, b); }
 
ll n, m, k, ans = 0, sum = 0, cnt = 0;
string s;
//char c;
 
#define Endl endl
 
/*--------------------template--------------------*/

int main() {
    int N, C;
    cin >> N >> C;
    int d[C][C];
    int a[3][C];
    FOR(i, 0, 3) {
        FOR(j, 0, C) {
            a[i][j] = 0;
        }
    }      
    FOR(i, 0, C) {
        FOR(j, 0, C) {
            cin >> d[i][j];
        }
    }

    FOR(i, 0, N) {
        FOR(j, 0, N) {
            int c;
            cin >> c;
            FOR(k, 0, C) {
                a[(i + 1 + j + 1) % 3][k] += d[c-1][k];
            }
        }
    }
    
    ans = -1;
    FOR(i, 0, C) {
        FOR(j, 0, C) {
            FOR(k, 0, C) {
                if (i == j || j == k || k == i) continue;
                ll test = a[0][i] + a[1][j] + a[2][k];
                if (ans < 0 || test < ans) ans = test;
            }
        }
    }
    
    cout << ans;
    
    return 0;
}

Measured memory_bytes: 256
import Control.Monad
import Text.Printf
import Control.Applicative
import Data.List as L

getInts :: IO [Int]
getInts = map read . words <$> getLine

main :: IO()
main = do
  [x] <- getInts
  let a = [2^y | y <- [2..9]]
      b = [y^2 | y <- [1..31]]
      c = [y^3 | y <- [1..10]]
      d = [y^4 | y <- [1..5]]
      e = [y^5 | y <- [1..3]]
      f = [y^6 | y <- [1..3]]
  printf "%d" $ head $dropWhile (> x) $ sortBy (flip compare) (concat [a, b, c, d, e, f])

Measured memory_bytes: 508
#include<stdio.h>

int main(void)
{
  int card[4][13];
  int x,i,j;
  int num,y;
  int false,true;
  char a;
  false = 0 ;
  true = 1;

  for( i = 0; i < 4; i++){
    for( j = 0; j < 13; j++){
      card[i][j] = false;
	}
  }


     scanf(" %d",&x);

  for( y = 0; y < x; y++){
    scanf(" %c %d", &a, &num);

    switch(a){
    case 'S':
      card[0][num-1] = true;
      break;
    case 'H':
      card[1][num-1] = true;
      break;
    case 'C':
      card[2][num-1] = true;
      break;
    case 'D':
      card[3][num-1] = true;
      break;
    }
  }

  for(i = 0;i < 4;i++){
    for(j = 0;j < 13;j++){
      if (card[i][j] == false){	
	if(i == 0){
	  printf("S %d\n", j+1);
	}
	else if(i == 1){
	  printf("H %d\n", j+1);
	}
	else if(i == 2){
	  printf("C %d\n", j+1);
	}
	else if(i == 3){
	  printf("D %d\n", j+1);
	}
      }
    }
  }


  return 0;
}

Measured memory_bytes: 596
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;

#define ll long long
#define ull unsigned long long
#define db long double
#define pb push_back
#define ppb pop_back
#define F first
#define S second
#define mp make_pair
#define all(x) (x).begin(), (x).end()

#define int long long

mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
typedef pair <int, int> pii;
typedef pair <ll, ll> pll;
typedef vector <int> vi;
typedef vector <ll> vll;

typedef tree <pii, null_type, less <pii>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;

int n, x, d;

ll f(ll x) {
	return x * (x - 1) / 2;
}

signed main() {
	ios_base::sync_with_stdio(false), cin.tie(NULL);
	#ifdef LOCAL
		freopen("input.txt", "r", stdin);
	#endif
	
	cin >> n >> x >> d;
	if (d == 0) {
		if (x == 0) {
			cout << 1;
		}	else {
			cout << n + 1;
		}
		return 0;
	}
	int g = __gcd(abs(x), abs(d));
	x /= g;
	d /= g;
	if (d < 0) {
		d *= -1;
		x *= -1;
	}
	vector <pll> p;
	ll ans = 0;
	for (int i = 0; i < d; i++) {
		p.clear();
		int cur = 0;
		for (int j = i; j <= n; j += d) {
			ll C = (ll)(j / d) * x;
			p.pb({f(j) + C, 0});
			p.pb({f(n) - f(n - j) + C, 1});
		}
		sort(all(p));
		ll last = 0;
		for (int j = 0; j < (int)p.size(); j++) {
			if (p[j].S == 0) {
				cur++;
			}	else {
				cur--;
			}
			if (cur == 0) {
				ans += p[j].F - last + 1;
			}
			if (cur == 1 && p[j].S == 0) {
				last = p[j].F;
			}
		}
	}
	cout << ans;
}


Measured memory_bytes: 10604
import java.util.*;
import java.util.stream.Collectors;

public class Main {
    public static void main(String args[]){
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        int M = sc.nextInt();
        List<Integer> A = new ArrayList<>(N);
        for(int i=0;i<N;i++){
            A.add(sc.nextInt());
        }
        final int sum = A.stream().collect(Collectors.summingInt(p->p));
        boolean yn = A.stream().filter(ai-> sum <= ai*4*M).count() >= M;
        if(yn){
            System.out.println("Yes");
        }else{
            System.out.println("No");
        }
    }

}


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

ll modulo(ll a, ll b){
  ll res = 1;
  while(b>0){
    if(b%2==1){
      res*=a;
      res%=mod;
    }
    a*=a;
    a%=mod;
    b/=2;
  }
  return res;
}

ll inversemod(ll a){
  return modulo(a,mod-2);
}

ll comb(ll n, ll a){
  ll num = 1, den = 1;
  for(ll i=0;i<=a-1;i++){
    num*=(n-i);
    num%=mod;
  }
  for(ll i=1;i<=a;i++){
    den*=i;
    den%=mod;
  }
  return num*inversemod(den)%mod;
}


int main(){
  ll n,a,b;
  cin >> n >> a >> b;
  ll res = modulo(2,n)-1;
  res = (res-comb(n,a))%mod;
  res = (res-comb(n,b))%mod;
  res = (res+mod)%mod;
  cout<<res<<endl;
}


Measured memory_bytes: 256
from statistics import mean, median,variance,stdev
import numpy as np
import sys
import math
import fractions
import itertools

def j(q):
    if q==1: print("Yes")
    else:print("No")
    exit(0)


def ct(x,y):
    if (x>y):print("")
    elif (x<y): print("")
    else: print("")

def ip():
    return int(input())

def swap(s,pos):
    s[pos]-=1
    s[pos+1]+=1
    print(s)
    if pos == n-2: return s
    if s[pos+2] == 0: swap(s,pos+1)
    return s


n = ip()                              #入力整数1つ
#left,n= (int(i) for i in input().split())      #入力整数横2つ
#n,x,y = (int(i) for i in input().split())    #入力整数横3つ
#n,m,x,y= (int(i) for i in input().split())  #入力整数横4つ
#a = [int(i) for i in input().split()]        #入力整数配列
#a = input()                                  #入力文字列
#a = input().split()                          #入力文字配列
#n = ip()                      #入力セット(整数改行あり)(1/2)
#a=[ip() for i in range(n)]    #入力セット(整数改行あり)(2/2)

k = ip()

#jの変数はしようできないので注意
#全足しにsum変数使用はsum関数使用できないので注意
s =1
for i in range(n):
    s = min(s*2,s+k)
print(s)


Measured memory_bytes: 13848
#include<bits/stdc++.h>
using namespace std;
int main(){
     int n,a;cin>>n;
     a = 0;
     vector<pair<int,int>> p(n);
     for(int i=0;i<n;i++){
         cin>>p.at(i).first;
         p.at(i).second = i+1;
         if(p.at(i).first!=p.at(i).second){
             a++;
         }
     }
     if(a>2){
         cout<<"NO"<<endl;
     }
     else cout <<"YES"<<endl;
}

Measured memory_bytes: 256
#include <algorithm>
#include <iostream>
#include <math.h>
#include <stdio.h>
#include <string>
#include <sstream>
#include <vector>
#include <set>
#include <map>
#include <cmath>
#define rep(i, n) for(int i = 0; i < (int)(n); i++)

using namespace std;

bool dsc(const int& left,const int &right){
	return left > right;
}

int main()
{
	int N,M;
	cin>>N>>M;
	int *A = new int[N];
	double sum = 0;
	double limit = 0;
	for(int i = 0; i < N; i++){
		cin>>A[i];
		sum += A[i];
	}
	limit = sum / (4 * M) ;
	sort(A,A+N,dsc);
	if( A[M-1] >= limit){
		cout<<"Yes"<<endl;
	}else{
		cout<<"No"<<endl;
	}
	return 0;
}



Measured memory_bytes: 256
package main

import (
	"bufio"
	"fmt"
	"os"
	"sort"
	"strconv"
)

func newScanner() *bufio.Scanner {
	scanner := bufio.NewScanner(os.Stdin)
	scanner.Split(bufio.ScanWords)
	return scanner
}

var sc = newScanner()

func scanInt() int {
	sc.Scan()
	v, _ := strconv.Atoi(sc.Text())
	return v
}

func scanInts(n int) []int {
	a := make([]int, n)
	for i := 0; i < n; i++ {
		a[i] = scanInt()
	}
	return a
}

func scanString() string {
	if sc.Scan() {
		return sc.Text()
	}
	panic(sc.Err())
}

func main() {
	n := scanInt()
	v := scanInts(n)
	answer := maxValue(n, v)
	fmt.Println(answer)
}

func debug(a ...interface{}) {
	fmt.Println(a...)
}

func maxValue(n int, v []int) float64 {
	sort.Ints(v)
	value := float64(v[0])

	for i := 1; i < n; i++ {
		value += float64(v[i])
		value /= 2.0
	}
	return value
}


Measured memory_bytes: 640