akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <vector>
using namespace std;
using ll = long long;
#define LINF 1LL << 60

int main(){
  int n, k;
  while(cin >> n >> k && n != 0){
    vector<ll> a(n);
    vector<ll> sum(n + 1, 0);
    for(int i = 0; i < n; ++i){
      cin >> a[i];
      sum[i + 1] = sum[i] + a[i];
    }

    ll ans = -LINF;
    for(int i = 0; k + i <= n; ++i){
      ll tmp = sum[k + i] - sum[i];
      if(tmp > ans)ans = tmp;
    }

    cout << ans << endl;
  }
}



Measured memory_bytes: 4420
#include <cstdio>
#include <iostream>
#include <algorithm>
#include <cstring>
#include <cmath>
using namespace std;
long long l, r, ans = 2020, a[2020];
int main(int argc, char const *argv[])
{
	scanf("%lld%lld", &l, &r);
	if (l/2019 != r/2019)
	{
		printf("0\n");
		return 0;
	}
	for (long long i = l; i <= r; ++i)
	{
		memset(a, 0, sizeof(a));
		for (long long j = i+1; j <= r; ++j)
		{
			if (a[(i*j)%2019] == 1) break;
			a[(i*j)%2019] = 1;
			ans = min(ans, (i*j)%2019);
		}
	}
	printf("%lld\n", ans);
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
typedef long long ll;
using namespace std;
//for(int i = 0; i<n; i++)
 
 
int main()
{
    int n, l;
    cin>>n>>l;
    if(l >= 0)cout<<(2*l+n-1)*n/2 - l << endl;
    else if (l + n - 1 >= 0) cout<<(2*l+n-1)*n/2 << endl;
    else cout<<(2*l+n-1)*n/2 - (n+l-1) << endl;
    return 0;
    
}

Measured memory_bytes: 256
import java.util.Scanner;
 
public class Main{
    public static void main(String[] args) {
        Scanner in=new Scanner(System.in);
        String s=in.nextLine();
        if(s.contains("ABC")){
            System.out.println("ARC");
        }else{
            System.out.println("ABC");
        }
    }
}

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

typedef pair<int, int> P;

bool compare(P a, P b){
  if(a.second != b.second){
    return a.second < b.second;
  }
  else return a.first < b.first;
}

int main(){
  int n, m;
  cin >> n >> m;
  vector<P> pairs(m);
  int a, b;
  for(int i=0; i<m; ++i){
    cin >> a >> b;
    pairs[i] = make_pair(a, b);
  }
  sort(pairs.begin(), pairs.end(), compare);

  int s = 0; //最後に破壊された地点
  int ans = 0;
  for(int i=0; i<m; ++i){
    int left = pairs[i].first;
    int right = pairs[i].second;
    if(left > s){
      s = right-1;
      ++ans;
    }
  }
  cout << ans << "\n";
}

Measured memory_bytes: 1024
import sys, os, math, bisect, itertools, collections, heapq, queue
from scipy.sparse.csgraph import csgraph_from_dense, floyd_warshall
from decimal import Decimal
from collections import defaultdict

# import fractions

sys.setrecursionlimit(10000000)

ii = lambda: int(sys.stdin.buffer.readline().rstrip())
il = lambda: list(map(int, sys.stdin.buffer.readline().split()))
fl = lambda: list(map(float, sys.stdin.buffer.readline().split()))
iln = lambda n: [int(sys.stdin.buffer.readline().rstrip()) for _ in range(n)]

iss = lambda: sys.stdin.buffer.readline().decode().rstrip()
sl = lambda: list(map(str, sys.stdin.buffer.readline().decode().split()))
isn = lambda n: [sys.stdin.buffer.readline().decode().rstrip() for _ in range(n)]

lcm = lambda x, y: (x * y) // math.gcd(x, y)
# lcm = lambda x, y: (x * y) // fractions.gcd(x, y)

MOD = 10 ** 9 + 7
MAX = float('inf')


def main():
    if os.getenv("LOCAL"):
        sys.stdin = open("input.txt", "r")

    N = ii()
    A = sorted(il())

    cnt = collections.Counter(A)
    multiple = set()
    ret = 0
    maximum = max(A)
    for a in A:
        # 約数を既に使用済みの場合はcontinue
        if a in multiple:
            continue

        # 約数がなく、
        # 同じ数字が存在しない場合には
        # 条件に一致する整数
        if cnt[a] == 1:
            ret += 1

        i = 1
        # 整数の倍数を列挙
        while a * i <= maximum:
            multiple.add(a*i)
            i += 1
    print(ret)


if __name__ == '__main__':
    main()


Measured memory_bytes: 130896
import heapq as h
n,m,s,t = map(int,input().split())
g = [dict() for _ in range(n+1)]
for _  in range(m):
  u,v,a,b = map(int,input().split())
  g[u][v] = (a,b)
  g[v][u] = (a,b)

def dijkstra(s,g,mode):
  dist = [10**15]*(n+1)
  seen = [False]*(n+1)
  dist[s] = 0
  q = [(0,s)]
  while q:
    d,v = h.heappop(q)
    if seen[v]:
      continue
    seen[v] = True
    dist[v] = d
    for x in g[v]:
      if not seen[x]:
        h.heappush(q,(dist[v]+g[v][x][mode],x))
  return dist

ou = dijkstra(s,g,0)
fuku = dijkstra(t,g,1)
rot = [(ou[i] + fuku[i],i) for i in range(n+1)]
h.heapify(rot)
for i in range(1,n+1):
  if rot[0][1] < i:
    while rot[0][1] < i:
      h.heappop(rot)
  print(10**15 - rot[0][0])

Measured memory_bytes: 84452
from collections import Counter,defaultdict,deque
from heapq import heappop,heappush,heapify
import sys,bisect,math,itertools,fractions,pprint
sys.setrecursionlimit(10**8)
mod = 10**9+7
mod2 = 998244353
INF = float('inf')
def inp(): return int(sys.stdin.readline())
def inpl(): return list(map(int, sys.stdin.readline().split()))
def inpln(n): return list(int(sys.stdin.readline()) for i in range(n))

a = inp()
b = inp()
for i in range(1,4):
    if a == i or b == i:
        continue
    print(i)


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

using namespace std;
using ll = long long;

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

const int mod = 2019;

int main() {
  string s;
  cin >> s;
  int n = s.size();
  reverse(s.begin(), s.end());

  vector<int> a(n + 1);
  int mul = 1;
  rep(i, n) {
    int x = s[i] - '0';
    x = x * mul % mod;
    a[i + 1] = (a[i] + x) % mod;
    mul = mul * 10 % mod;
  }

  vector<int> cnt(mod);
  rep(i, n + 1)++ cnt[a[i]];
  ll ans = 0;
  rep(i, 2019) { ans += (ll)cnt[i] * (cnt[i] - 1) / 2; }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 4432
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
typedef long long int lli;

int dfs(int n, vector<vector<int> > &adj, vector<bool> &used){
    if(used[n]){
        return 0;
    }
    used[n] = true;
    int ret = 1;
    for(int i=0; i<(int)adj[n].size(); i++){
        ret += dfs(adj[n][i], adj, used);
    }
    return ret;
}

int main(){
    lli n,m;
    cin >> n >> m;
    vector<vector<int> > adj(n);
    for(int i=0; i<m; i++){
        int a,b;
        cin >> a >> b;
        a--; b--;
        adj[a].push_back(b);
        adj[b].push_back(a);
    }

    vector<bool> used(n, false);
    lli c1 = dfs(0, adj, used);
    lli c2 = dfs(1, adj, used);
    if(c1 < c2) swap(c1, c2);
    c1 += n-c1-c2;
    cout << c1*(c1-1)/2 + c2*(c2-1)/2 -m << endl;
    return 0;
}


Measured memory_bytes: 10368
//Bomber 

#include<bits/stdc++.h>
using namespace std;
using ll = long long;
#define int long long
#define rep(i,x,y) for(ll i=x;i<y;i++)
#define nvarep(n,a) ll n;cin>>n;vector<ll>a(n);rep(i,0,n)cin>>a[i]
#define vecrep(n,a,type) vector<type>a(n);rep(i,0,n)cin>>a[i]
#define YN(flag) (flag?"Yes":"No")
#define lcm(a,b) (a/__gcd(a, b)*b)
#define range(a) (a).begin(),(a).end() 
#define pb push_back
#define mp make_pair
#define nnn "\n"
#define spa " "
using P = pair<ll,ll>;
using graph = vector<vector<ll>>;
const int inf = 2147483647;//2*10^9
const ll INF = 9223372036854775807;//9*10^18

signed main (){
    int h,w,m;cin>>h>>w>>m;
    vector<int>hs(h,0),ws(w,0);
    set<P>bm;
    rep(i,0,m){
        int a,b;cin>>a>>b;
        a--;b--;
        bm.insert(mp(a,b));
        hs[a]++;
        ws[b]++;
    }
    int hm=*max_element(range(hs)),wm=*max_element(range(ws));
    int ans=hm+wm-1;
    vector<int>hml,wml;
    rep(i,0,h)if(hs[i]==hm)hml.pb(i);
    rep(i,0,w)if(ws[i]==wm)wml.pb(i);
    for(auto i:hml)for(auto j:wml){
        if(bm.count(mp(i,j)))continue;
        else{
            cout<<ans+1<<nnn;
            return 0;
        };
    }
    cout<<ans<<nnn;
    return 0;
}

Measured memory_bytes: 35100
N, M = list(map(int, input().split()))

if N >= M:
  print(0)
else:
  X_list = [int(x) for x in input().split()]
  X_list.sort()

  L_list = []
  for i in range(1, M):
    L_list.append(X_list[i] - X_list[i-1])
  L_list.sort(reverse=True)
  print(sum(L_list[N-1:]))

Measured memory_bytes: 13832
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <math.h>
#include <map>
#include <set>
using namespace std;
typedef long long ll;

int main(){
    ll n;cin>>n;
    ll y;cin>>y;
    y/=1000;
    int a,b,c;
    for(int i=0;i<=min(n,y/10);i++){
        a=i;
        for(int j=0;j<=min(n-a,(y-10*a)/5);j++){
            b=j;
           c=n-b-a;
           if(y-10*a-5*b-c==0&&a+b+c==n){cout<<a<<' '<<b<<' '<<c;return 0;}
        }
    }
    cout<<-1<<' '<<-1<<' '<<-1;return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define int long long
#define pii pair<int,int>
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) FOR(i,0,n)
#define ALL(c) (c).begin(),(c).end()
#define ZERO(a) memset(a,0,sizeof(a))
#define MINUS(a) memset(a,0xff,sizeof(a))
#define MINF(a) memset(a,0x3f,sizeof(a))
#define POW(n) (1LL<<(n))
#define IN(i,a,b) (a <= i && i <= b)
using namespace std;
template <typename T> inline bool CHMIN(T& a,T b) { if(a>b) { a=b; return 1; } return 0; }
template <typename T> inline bool CHMAX(T& a,T b) { if(a<b) { a=b; return 1; } return 0; }
template <typename T> inline void SORT(T& a) { sort(ALL(a)); }
template <typename T> inline void REV(T& a) { reverse(ALL(a)); }
template <typename T> inline void UNI(T& a) { sort(ALL(a)); a.erase(unique(ALL(a)),a.end()); }
template <typename T> inline void LB(vector<T>& v, T& a) { return *lower_bound(ALL(v),a); }
template <typename T> inline void LBP(vector<T>& v, T& a) { return lower_bound(ALL(v),a) - v.begin(); }
template <typename T> inline void UB(vector<T>& v, T& a) { return *upper_bound(ALL(v),a); }
template <typename T> inline void UBP(vector<T>& v, T& a) { return upper_bound(ALL(v),a) - v.begin(); }
template <typename T1, typename T2> ostream& operator<< (ostream& os, const pair<T1,T2>& p) { os << p.first << " " << p.second; return os; }
template <typename T1, typename T2> istream& operator>> (istream& is, pair<T1,T2>& p) { is >> p.first >> p.second; return is; }
template <typename T> ostream& operator<< (ostream& os, const vector<T>& v) { REP(i,v.size()) os << v[i] << " \n"[i+1==v.size()]; return os; }
template <typename T> istream& operator>> (istream& is, vector<T>& v) { for(T& in : v) is >> in; return is; }
template <typename T = int> vector<T> make_v(size_t a) { return vector<T>(a); }
template <typename T, typename... Ts> auto make_v(size_t a, Ts... ts) { return vector<decltype(make_v<T>(ts...))>(a,make_v<T>(ts...)); }
const int MOD = 1000000007;
const int INF = 0x3f3f3f3f3f3f3f3f;
const double EPS = 1e-10;

signed main() {
  cin.tie(nullptr);
  ios::sync_with_stdio(false);
  cout << fixed << setprecision(10);

  int N;
  cin >> N;
  vector<int> A(N);
  cin >> A;
  int ans = 0;
  for (int i = N-1; i >= 0; i--) {
    if (i >= A[i]) {
      if (i == N-1) {
        ans += A[i];
      } else if (A[i] < A[i+1]-1) {
        ans = -1;
        break;
      } else if (A[i] > A[i+1]-1) {
        ans += A[i];
      }
    } else {
      ans = -1;
      break;
    }
  }
  cout << ans << endl;

  return 0;
}

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

int main() {
	int s;
	cin >> s;
	int total = 0;
	if (s != 1 && s != 2) {
		while (s != 1) {
			if (s % 2 == 0) {
				total += 1;
				s /= 2;
			}
			else {
				total += 1;
				s = 3 * s + 1;
			}
		}
		cout << total + 2 << endl;
	}
	else if (s == 1 || s == 2) {
		cout << 4 << endl;
	}
}


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

int main(){
    ll n, k; cin >> n >> k;
    vector<ll> h(n); rep(i, 0, n) cin >> h[i];

    ll ans = 0;
    sort(h.rbegin(), h.rend());
    rep(i, 0, n){
        if(i < k) continue;
        ans += h[i];
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 1792
#include<stdio.h>

int main (void){
	int a[110][110]={},r,c,i,j;
	scanf("%d %d",&r,&c);
	for(i=1;i<=r;i++){
		for(j=1;j<=c;j++){
			scanf("%d",&a[i][j]);
		}
	}
	for(i=1;i<=r;i++){
		for(j=1;j<=c;j++){
			a[i][c+1]+=a[i][j];
		}
	}
	for(j=1;j<=c+1;j++){
		for(i=1;i<=r;i++){
			a[r+1][j]+=a[i][j];
		}
	}
	for(i=1;i<=r+1;i++){
		for(j=1;j<=c;j++){
			printf("%d ",a[i][j]);
		}
		printf("%d\n",a[i][c+1]);
	}
	return 0;
}

Measured memory_bytes: 656
#include <bits/stdc++.h>
#define N 100005
#define endl "\n"
using namespace std;

int m;

int h[N];


int dp[N];


int minCost(int n)
{

	if (n == 0)
		return 0;


	if (n < 0)
		return INT_MAX - 1;



	if (dp[n] != -1)
		return dp[n];




	int one = abs(h[n] - h[n - 1]) + minCost(n - 1);

	int two = INT_MAX;

	if (n - 2 >= 0)
	{

		two = abs(h[n] - h[n - 2]) + minCost(n - 2);

	}




	return  dp[n] = min(one, two);


}


int32_t main()
{


	cin >> m;


	for (int i = 0; i < m; ++i)
		cin >> h[i];


	memset(dp, -1, sizeof(dp));


	cout << minCost(m - 1) << endl;

}

Measured memory_bytes: 9036
#include <iostream>

int main()
{
	int K, A, B = 0;
	std::cin >> K >> A >> B;

	int ans = (A / K) * K;
	if (ans >= A && B >= ans)
	{
		std::cout << "OK\n";
	}
	else
	{
		ans += K;
		if (ans >= A && B >= ans)
		{
			std::cout << "OK\n";
		}
		else
		{
			std::cout << "NG\n";
		}
	}

	return 0;
}

Measured memory_bytes: 3580
# -*- coding: utf-8 -*-
"""
A - Consecutive Integers
https://atcoder.jp/contests/diverta2019/tasks/diverta2019_a

"""
import sys


def solve(N, K):
    return N-K+1


def main(args):
    N, K = map(int, input().split())
    ans = solve(N, K)
    print(ans)


if __name__ == '__main__':
    main(sys.argv[1:])


Measured memory_bytes: 2940
#include<bits/stdc++.h>
using namespace std;
int a[100007],b[100007],deg[100007];
int ok=0;
int vis[100007];
vector<int>e[100007];
int c1,c2;
void dfs(int u,int v){
    vis[u]=1;
    for(int i=0;i<e[u].size()&&!ok;i++){
        if(e[u][i]==c2)
            return;
        else if(!vis[e[u][i]])
            dfs(e[u][i],u);
        else if(e[u][i]==c1&&c1!=v)
            ok=1;
    }
    return;
}
int main(){
    int n,m;
    scanf("%d%d",&n,&m);
    for(int i=1;i<=m;i++){
        scanf("%d%d",&a[i],&b[i]);
        e[a[i]].push_back(b[i]);
        e[b[i]].push_back(a[i]);
        deg[a[i]]++;
        deg[b[i]]++;
    }
    int cnt=0;
    int flag=0;
    for(int i=1;i<=n;i++){
        if(deg[i]&1){
            printf("No");
            return 0;
        }
        if(deg[i]>=6)
            flag=1;
        else if(deg[i]==4){
            cnt++;
            if(!c1)
                c1=i;
            else
                c2=i;
        }
        if(cnt>=3)
            flag=1;
    }
    if(cnt==2){
        dfs(c1,c2);
        if(ok==1)
            flag=1;
    }
    if(flag==1)
        printf("Yes");
    else
        printf("No");
    return 0;
}


Measured memory_bytes: 8448
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Scanner;

/*
 * TODO AtCoder Beginner Contest 102 D "Equal Cut"
 */
public class Main {

	public static void main(String[] args) {

		InputScanner in = new InputScanner(System.in);
		PrintWriter out = new PrintWriter(System.out);

		int N = in.nextInt();
		int[] A = in.nextIntArray(N);

		long[] sumA = new long[N];
		sumA[0] = A[0];
		for (int i = 1; i < N; i++) {
			sumA[i] = sumA[i - 1] + A[i];
		}

		long ans = Long.MAX_VALUE;
		int left = 0;
		int right = 2;
		for (int i = 1; i <= N - 3; i++) {

			long subL = getSubL(sumA, left, i);
			long subR = getSubR(sumA, i, right);

			for (int j = left + 1; j < i; j++) {
				long sub = getSubL(sumA, j, i);
				if (subL > sub) {
					subL = sub;
					left = j;
				} else {
					break;
				}
			}

			for (int j = right + 1; j < N; j++) {
				long sub = getSubR(sumA, i, j);
				if (subR > sub) {
					subR = sub;
					right = j;
				} else {
					break;
				}
			}

			long P = sumA[left];
			long Q = sumA[i] - sumA[left];
			long R = sumA[right] - sumA[i];
			long S = sumA[N - 1] - sumA[right];

			long max = Math.max(Math.max(P, Q), Math.max(R, S));
			long min = Math.min(Math.min(P, Q), Math.min(R, S));

			ans = Math.min(ans, max - min);
		}

		out.println(ans);

		in.close();
		out.close();

	}

	private static long getSubL(long[] sumA, int fowardIndex, int backIndex) {

		long forwardSum = sumA[fowardIndex];
		long backSum = sumA[backIndex] - sumA[fowardIndex];

		return Math.abs(forwardSum - backSum);
	}

	private static long getSubR(long[] sumA, int fowardIndex, int backIndex) {

		long forwardSum = sumA[backIndex] - sumA[fowardIndex];
		long backSum = sumA[sumA.length - 1] - sumA[backIndex];

		return Math.abs(forwardSum - backSum);
	}

	/*
	 * extends java.util.Scanner
	 */
	static class InputScanner{

		Scanner scanner;

		public InputScanner(InputStream inputStream) {
			this.scanner = new Scanner(inputStream);
		}

		public int nextInt() {
			return scanner.nextInt();
		}

		public long nextLong() {
			return scanner.nextLong();
		}

		public double nextDouble() {
			return scanner.nextDouble();
		}
		public String next() {
			return scanner.next();
		}

		public int[] nextIntArray(int n) {
			int[] ret = new int[n];
			for (int i = 0; i < n; i++) {
				ret[i] = scanner.nextInt();
			}
			return ret;
		}

		public long[] nextLongArray(int n) {
			long[] ret = new long[n];
			for (int i = 0; i < n; i++) {
				ret[i] = scanner.nextLong();
			}
			return ret;
		}

		public String[] nextStringArray(int n) {
			String[] ret = new String[n];
			for (int i = 0; i < n; i++) {
				ret[i] = scanner.next();
			}
			return ret;
		}

		public String[] nextStringArray(String splitStr) {
			String[] ret = scanner.next().split(splitStr);
			return ret;
		}

		public void close() {
			scanner.close();
		}
	}

}


Measured memory_bytes: 85736
import sys
N = int(input())
for h in range(1,3501):
    for n in range(1,3501):
        tmp = 4*h*n-N*(n+h)
        if tmp == 0:
            continue
        d,m = divmod(N*h*n, tmp)
        if m == 0 and d > 0:
            print(h,n,d)
            sys.exit()

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

int checkSign(int A){
    return (int)(A>0)-(int)(A<0);
}

int main() {
  int N;
  cin >> N;
  vector<int> a(N);
  for(int i=0;i<N;i++){
    cin >> a.at(i);
  }
  long long sum = 0;
  int sign = 1;
  long long res1 = 0;
  for(int i=0;i<N;i++){
    int tmp = a.at(i);
    if(checkSign(sum+tmp) == 0 || checkSign(sum+tmp) != sign){
      tmp = sign*(abs(sum) + 1);
      res1 += abs(tmp - a.at(i));
    }
    sum += tmp;
    sign *= -1;
  }
  sum = 0;
  sign = -1;
  long long res2 = 0;
  for(int i=0;i<N;i++){
    int tmp = a.at(i);
    if(checkSign(sum+tmp) == 0 || checkSign(sum+tmp) != sign){
      tmp = sign*(abs(sum) + 1);
      res2 += abs(tmp - a.at(i));
    }
    sum += tmp;
    sign *= -1;
  }
  cout << min(res1,res2) << endl;
  return 0;
}

Measured memory_bytes: 640
def geti; gets.to_i end
def getis; gets.split.map &:to_i end
def getin n;  n.times.map{geti}  end
def getisn n; n.times.map{getis} end
YES = "YES"; NO = "NO"; Yes = "Yes"; No = "No";

a,b,c,d=getis
puts %w(Balanced Left Right)[a+b<=>c+d]

__END__
puts (gets.sub(?\s,'').to_i**0.5)%1==0? "Yes" : "No"

a,b=getis
puts a*b%2==0? "Even" : "Odd"


Measured memory_bytes: 1788
#include <bits/stdc++.h>
using namespace std;
 
#define rep(i, n) for (int i = (int)(0); i < (int)(n); ++i)
#define reps(i, n) for (int i = (int)(1); i <= (int)(n); ++i)
#define rrep(i, n) for (int i = ((int)(n)-1); i >= 0; i--)
#define rreps(i, n) for (int i = ((int)(n)); i > 0; i--)
#define irep(i, m, n) for (int i = (int)(m); i < (int)(n); ++i)
#define ireps(i, m, n) for (int i = (int)(m); i <= (int)(n); ++i)
#define FOR(e, c) for (auto &e : c)
#define SORT(v, n) sort(v, v + n);
#define vsort(v) sort(v.begin(), v.end());
#define rvisort(v) sort(v.begin(), v.end(), greater<int>());
#define all(v) v.begin(), v.end()
#define mp(n, m) make_pair(n, m);
#define cout(d) cout<<d<<endl;
#define coutd(d) cout<<std::setprecision(10)<<d<<endl;
#define cinline(n) getline(cin,n);
 
using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vll = vector<ll>;
using vvll = vector<vll>;
using pii = pair<int, int>;
using vpii = vector<pii>;
using vs = vector<string>;
using vd = vector<double>;
using ul = unsigned long;
 
template<class T, class C> void chmax(T& a, C b){ a>b?:a=b; }
template<class T, class C> void chmin(T& a, C b){ a<b?:a=b; }
 
const int mod=1e9+7;
 
struct mint {
  ll x;
  mint(ll x=0):x(x%mod){}
  mint& operator+=(const mint a) {
    if ((x += a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator-=(const mint a) {
    if ((x += mod-a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator*=(const mint a) {
    (x *= a.x) %= mod;
    return *this;
  }
  mint operator+(const mint a) const {
    mint res(*this);
    return res+=a;
  }
  mint operator-(const mint a) const {
    mint res(*this);
    return res-=a;
  }
  mint operator*(const mint a) const {
    mint res(*this);
    return res*=a;
  }
};
 
mint c[4005][4005];
void init() {
  c[0][0] = 1;
  for (int i = 0; i <= 4000; i++) {
    for (int j = 0; j <= i; j++) {
      c[i+1][j] += c[i][j];
      c[i+1][j+1] += c[i][j];
    }
  }
}
mint comb(int n, int k) {
  return c[n][k];
}
 
bool IsPrime(int num)
{
    if (num < 2) return false;
    else if (num == 2) return true;
    else if (num % 2 == 0) return false;
 
    double sqrtNum = sqrt(num);
    for (int i = 3; i <= sqrtNum; i += 2)
    {
        if (num % i == 0)
        {
            return false;
        }
    }
 
    return true;
}
 
map<ll, ll> primeFact(ll n) {
  map<ll, ll> res;
  for (ll i = 2; i * i <= n; i++) {
    while (n % i == 0) {
      res[i]++;
      n /= i;
    }
  }
  if (n != 1) res[n]++;
  return res;
}
 
void printv(vi& v){
  rep(i,v.size()) cout << v[i] << " ";
  cout << endl;
}
void printv(vll& v){
  rep(i,v.size()) cout << v[i] << " ";
  cout << endl;
}
int vtotal(vi& v){
  int total=0;
  rep(i,v.size()) total+=v[i];
  return total;
}
 
int main()
{
  //init(); // mint初期化
  cin.tie( 0 );
  ios::sync_with_stdio( false );
 
  int s;
  cin>>s;
  vi v(100000,0);
  v[s]=1;
  int ans=0;
  int before=s;
  for(int i=2;;i++){
    int a;
    if(before%2==0)a=before/2;
    else a=3*before+1;
    if(v[a]==1){
      ans=i;
      break;
    }
    v[a]=1;
    before=a;
  }
  
  cout(ans);
 
  return 0;
}

Measured memory_bytes: 126080
#include<bits/stdc++.h>
using namespace std;
int main()
{
   long int n,q,k;
      cin>>n>>k>>q;

       int arr[q],freq[n+1]={0};
       for(int i=0;i<q;i++)
        {
           cin>>arr[i];
             freq[arr[i]]++;
          }

        int sum[n+1];
        for(int i=1;i<=n;i++)
            sum[i]=q-freq[i];

    for(int i=1;i<=n;i++)
    {
       if(k-sum[i] > 0)
       cout<<"Yes"<<endl;

       else
       cout<<"No"<<endl;
    }
}


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

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

const long long INF = 1LL << 60;

// 入力
int N;

// DP テーブル
long long int dp[160000];

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

    // 初期化 (最小化問題なので INF に初期化)
    for (int i = 0; i < 160000; ++i) dp[i] = INF;

    // 初期条件
    dp[0] = 0;

    // ループ
    for (int i = 0; i <= N; ++i) {
        chmin(dp[i+1], dp[i]+1);
        for(int j=1;j<7;j++){
          chmin(dp[i+(int)pow(6,j)], dp[i]+1);
        }
        for(int k=1;k<6;k++){
          chmin(dp[i+(int)pow(9,k)], dp[i]+1);
        }
    }

    // 答え
    cout << dp[N] << endl;
}

Measured memory_bytes: 1536
import java.util.ArrayList;
import java.util.Scanner;
class Main{


	static final int MOD = 1000000007;


	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);			//文字の入力
		int n = sc.nextInt();
		int k = sc.nextInt();
		int[] h = new int[n];
		for(int i = 0;i < n;i++){
			h[i] = sc.nextInt();
		}
		int ans = 0;
		for(int i = 0;i < n;i++){
			if(h[i] >= k){
				ans++;
			}
		}

System.out.println(ans);
				
		
		
	}




	static int upperbond(int k,int min,int[] data){		//kより小さい最大の値をdataの中から探し、返す二分探索
		int max = data.length;
//		if(min == data.length-1){
//			if(data[min] > k){
//				return min;
//			}
//		}

		while(max-min > 1){
			int mid = (max+min)/2;
			if(data[mid] >= k){
				max = mid;
			}else{
				min = mid;
			}
		}

		return max;
	}

	static int lowerbond(int k,int min,int[] data){		//kより大きい最小の値をdataの中から探し、返す二分探索
		int max = data.length;

		while(max-min > 1){
			int mid = (max+min)/2;
			if(data[mid] >= k){
				max = mid;
			}else{
				min = mid;
			}
		}
		return min;
	}



	static int gcd(int a,int b){				//最大公約数を返す
		if(b == 0){
			return a;
		}else{
			return gcd(b, a%b);
		}
	}
	static long gcd(long a,long b){
		if(b == 0){
			return a;
		}else{
			return gcd(b, a%b);
		}
	}



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




}


class Edge extends ArrayList<P>{

}

class P{
	int to;
	long cost;
	P(int to,long cost){
		this.to = to;
		this.cost = cost;
	}
}


class Pair implements Comparable{
	int from;
	int end;
	@Override
	public int compareTo(Object other) {
		Pair otherpair = (Pair)other;

		return   from- otherpair.from;
	}








}






Measured memory_bytes: 50372
def find_operation_num(word):
    count = 1
    before = word[0]
    result = 0
    for w in word[1:] + " ":
        if before == w:
            count += 1
        else:
            before = w
            result += count // 2
            count = 1
    return result


def main():
    # 等差数列を利用する
    word = input()
    repeat = int(input())
    answer = 0
    if len(set(list(word))) == 1:
        answer = len(word) * repeat // 2
    else:
        count = [find_operation_num(word * i) for i in range(1, 3)]
        answer = count[0] + (repeat - 1) * (count[1] - count[0])
    print(answer)


if __name__ == '__main__':
    main()



Measured memory_bytes: 3064
import java.util.Scanner;

public class Main {

    public static final int MOD = 1000000007;

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        long a = Long.parseLong(sc.next());
        double b = Double.parseDouble(sc.next());
        long c = Math.round(b * 100);
        System.out.println(a * c / 100);
    }
}

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

#define rep(ver,n) rep2(ver,0,n)
#define rep2(ver,m,n) for(int ver=m;ver<(n);ver++)
#define loop while(true)
#define dup(x,y) (((x)+(y)-1)/(y))
#define all(v) (v).begin(), (v).end()
#define debug(x) std::cerr<<#x<<": "<<x<<"\n"
#define debug2(x,y) std::cerr<<#x<<": "<<x<<", "<<#y<<": "<<y<<"\n"
#define debug3(x,y,z) std::cerr<<#x<<": "<<x<<", "<<#y<<": "<<y<<", "<<#z<<": "<<z<<"\n"

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

ll modinv(ll a, ll m) {
    ll b = m, u = 1, v = 0;
    while (b) {
        ll t = a / b;
        a -= t * b; swap(a, b);
        u -= t * v; swap(u, v);
    }
    u %= m;
    if (u < 0) u += m;
    return u;
}

int main(){
  ll n,mod=1000000007;
  cin>>n;
  
  ll n10=1,n9=1,n8=1;
  
  rep(i,n){
    n8*=8;
    n9*=9;
    n10*=10;
    n8%=mod;
    n9%=mod;
    n10%=mod;
  }
  
  ll ans=n10-2*n9+n8;
  
  ans=(ans+2*mod)%mod;
  
  cout<<ans;
  
  return 0;
}


Measured memory_bytes: 3632
import math
N = int(input())

listJob = []
sumAmount = 0
for i in range(N):
    amount, timelimit = map(int, input().split(' '))
    listJob.append((amount, timelimit))
    sumAmount += amount

listJob.sort(key=lambda x: x[1], reverse=True)

def code(listJob, _sumAmount):
    sumAmount = _sumAmount
    currentTime = listJob[0][1]
    for i in listJob:
        currentTime = min(currentTime, i[1])
        sumAmount -= i[0]
        currentTime -= i[0]
        if currentTime < sumAmount:
            return "No"
    return "Yes"

print(code(listJob, sumAmount))



Measured memory_bytes: 73432
#include <unordered_map>
#include <unordered_set>
#include <algorithm>
#include <iostream>
#include <iostream>
#include <fstream>
#include <numeric>
#include <cstring>
#include <cassert>
#include <string>
#include <vector>
#include <queue>
#include <deque>
#include <cmath>
#include <set>
#include <map>
#include <functional>
#include <bitset>
#include <iomanip>
#include <stack>
#include <list>
using namespace std;
#define     loop(n,i,a)     for(int i=a;i<n;i++)
#define     loopR(n,i,a)    for(int i=n-1;i>=a;i--)
#define     all(arr,n)      arr,arr+n
#define     allv(v)         (v).begin(),(v).end()
#define     rallv(v)        (v).rbegin(),(v).rend()
#define     m_p             make_pair
#define     ll              long long
#define     pii             pair<ll,ll>
#define     vi              vector<int>
#define     vll             vector<ll>
#define     vii             vector<pair<ll,ll>>
#define     sz(x)           (int)x.size()
#define     pb              push_back
#define     endl            "\n"
#define     Endl            "\n"
#define     f               first
#define     s               second
#define     mem(dp,n)       memset(dp,n,sizeof dp)
int dx[] = { 1 , 0 ,-1 , 0 ,-1 ,-1 , 1 , 1 };
int dy[] = { 0 , 1 , 0 ,-1 ,-1 , 1 ,-1 , 1 };
void fast(){
    std::ios_base::sync_with_stdio(0);
    cin.tie(NULL);
    cout.tie(NULL);
}
vector<string> vec_splitter(string s) {
    s += ',';
    vector<string> res;
    while(!s.empty()) {
        res.push_back(s.substr(0, s.find(',')));
        s = s.substr(s.find(',') + 1);
    }
    return res;
}
void debug_out(
        vector<string> __attribute__ ((unused)) args,
        __attribute__ ((unused)) int idx,
        __attribute__ ((unused)) int LINE_NUM) { cerr << endl; }
template <typename Head, typename... Tail>
void debug_out(vector<string> args, int idx, int LINE_NUM, Head H, Tail... T) {
    if(idx > 0) cerr << ", "; else cerr << "Line(" << LINE_NUM << ") ";
    stringstream ss; ss << H;
    cerr << args[idx] << " = " << ss.str();
    debug_out(args, idx + 1, LINE_NUM, T...);
}
#define debug(...) debug_out(vec_splitter(#__VA_ARGS__), 0, __LINE__, __VA_ARGS__)
const ll mxN=2e6+10,oo=0x3f3f3f3f,MOD=998244353;
const double PI = acos(-1);

void solve(){
    int n;
    cin>>n;
    map<string,int>mp;
    string all[]={"AC","WA","TLE","RE"};
    loop(n,i,0){
        string x;
        cin>>x;
        mp[x]++;
    }
    loop(4,i,0)
        cout<<all[i]<<" x "<<mp[all[i]]<<Endl;
}
int main() {
#ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#endif
    fast();
    solve();
}

Measured memory_bytes: 3608
def pre_combi1(n, p):
    fact = [1]*(n+1)  # fact[n] = (n! mod p)
    factinv = [1]*(n+1)  # factinv[n] = ((n!)^(-1) mod p)
    inv = [0]*(n+1)  # factinv 計算用
    inv[1] = 1
    # 前処理
    for i in range(2, n + 1):
        fact[i]= fact[i-1] * i % p
        inv[i]= -inv[p % i] * (p // i) % p
        factinv[i]= factinv[i-1] * inv[i] % p
    return fact, factinv

def combi1(n, r, p, fact, factinv):
    """
    k<n<10**7でpが素数のときのnCr % pを求める
    """
    # 本処理
    if r < 0 or n < r:
        return 0
    r = min(r, n-r)
    return fact[n] * factinv[r] * factinv[n-r] % p

p=998244353
fact,finv=pre_combi1(2*10**5+1,p)
n,m,k=map(int,input().split())
ans=0
dup=[0] * n
dup[0] = 1
for j in range(1,n):
  dup[j]=dup[j-1]*(m-1) % p
for i in range(k+1):
  ans += m*combi1(n-1,i,p,fact,finv)*dup[n-i-1]
  ans %= p
print(ans)

Measured memory_bytes: 82088
A = list(map(int, input().split()))

A.sort()
a_max = A[2]
a_middle = A[1]
a_min = A[0]
ans = 0

if sum(A)%2 != (3*a_max)%2: #偶奇が等しいならば
    ans += 1
    a_max += 1
    a_middle += 1

ans += a_max-a_middle
ans += (a_max-(a_min+(a_max-a_middle)))//2

print(ans)

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

int main() {
  int n, m;
  cin >> n >> m;
  vector<string> a(n), b(m);
  rep(i, n) cin >> a[i];
  rep(i, m) cin >> b[i];

  bool ok = false;

  for (int i = 0; i + m - 1 < n; ++i) {
    for (int j = 0; j + m - 1 < n; ++j) {
      bool contained = true;
      rep(k, m) rep(l, m) if (a[i+k][j+l] != b[k][l]) contained = false;
      if (contained) ok = true;
    }
  }
  if (ok) cout << "Yes" << endl;
  else cout << "No" << endl;
  return 0;
}

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

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

    for(int i = 0; i < n; i++){
        string str;
        cin >> str;
        if(str == "print"){
            int a, b;
            cin >> a >> b;
            for(int j = a; j <= b; j++){
       		 cout << s[j];
       		 if(j == b){
            cout << endl;
       		 }
  			}
        }
        else if(str == "reverse"){
            int a, b;
            cin >> a >> b;
            string t;
    		for(int j = a; j <= b; j++){
        		t.push_back(s[j]);
   			 }
  			reverse(t.begin(), t.end());
            for(int j = a; j <= b; j++){
        		s[j] = t[j - a];
            }
        }
        else if(str == "replace"){
            int a, b;
            cin >> a >> b;
            string t;
            cin >> t;
            for(int j = a; j <= b; j++){
        	s[j] = t[j - a];
    		}
        }
    }
}


Measured memory_bytes: 3204
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, begin, end) for (int i = begin; i < (int)(end); i++)
#define all(v) v.begin(), v.end()
const int MOD = 1000000007;

int main()
{
    int N, M;
    cin >> N >> M;
    vector<pair<ll, ll>> A;
    rep(i, 0, N)
    {
        int a;
        cin >> a;
        pair<ll, ll> p(a, 1);
        A.push_back(p);
    }
    rep(i, 0, M)
    {
        int b, c;
        cin >> b >> c;
        pair<ll, ll> p(c, b);
        A.push_back(p);
    }
    sort(all(A));
    reverse(all(A));
    ll ans = 0;
    int count = 0;
    int i = 0;
    while (count < N)
    {
        if (count + A.at(i).second > N)
        {
            ans += A.at(i).first * (N - count);
            count = N;
        }
        else
        {
            ans += A.at(i).first * A.at(i).second;
            count += A.at(i).second;
            i++;
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 6384
#include<iostream>
#include<vector>
#include<set>
#include<map>
#include<string>
#include<algorithm>
using namespace std;
using ll = long long;

int main(){
	ll X, Y, Z, K;
	cin >> X >> Y >> Z >> K;
	vector<ll> A(X),B(Y),C(Z);
	for(int i = 0; i < X;++i)
		cin >> A[i];
	for(int i = 0; i < Y;++i)
		cin >> B[i];
	for(int i = 0; i < Z;++i)
		cin >> C[i];
	
	sort(A.begin(), A.end(),greater<ll>());
	sort(B.begin(), B.end(),greater<ll>());
	sort(C.begin(), C.end(),greater<ll>());

	vector<ll> ans;
	for(int i = 0;i < X;++i){
		for(int j = 0;j < Y; ++j){
			for(int k = 0; k < Z; ++k){
				if (i*j*k<K)
					ans.push_back(A[i]+B[j]+C[k]);
			}
		}
	}
	sort(ans.begin(), ans.end(), greater<ll>());
	for(int i = 0; i < K; ++i)
		cout << ans[i] << endl;
}

Measured memory_bytes: 35176
from heapq import*
i=input
for _ in'_'*int(i()):
 n,s,x,*y=int(i()),0,[]
 for _ in'_'*n:k,l,r=t=[*map(int,i().split())];x+=[t]*(l>r);y+=[(n-k,r,l)]*(l<=r)
 for x in x,y:
  x.sort();n,*h=len(x),
  while n:
   n-=1
   while x and x[-1][0]>n:k,l,r=x.pop();heappush(h,(r-l,l,r))
   if h:s+=heappop(h)[1]
  for*_,r in x+h:s+=r
 print(s)

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

int main()
{
    string n;
    cin >> n;
    int ns=n.size();
    bool res = false;
    if(ns%2==0)
    {
        for(int i=0;i<ns/2;++i)
        {
            if(n[i]==n[ns-i-1]){
                res = true;
            }
            else{
                res = false;
            }
        
        }
    }
    
    else if(ns%2==1)
    {
        for(int i=0;i<(ns-1)/2;++i)
        {
            if(n[i]==n[ns-i-1]){
                res = true;
            }
            else{
                res = false;
            }
            
        }
    }
    
    if(res == true){
        cout <<"Yes" << endl;
    }
    else{
        cout <<"No"<<endl;
    }
    return 0;
    
}

Measured memory_bytes: 256
N, maxW = map(int, input().split())
V, W = [], []
for i in range(N):
    v, w = map(int, input().split())
    V.append(v); W.append(w)
dp = [[0]*(maxW+1) for _ in range(N+1)]
for i in range(N):
    for j in range(maxW+1):
        if j < W[i]:
            dp[i+1][j] = dp[i][j]
        else:
            dp[i+1][j] = max(dp[i][j], dp[i][j-W[i]] + V[i])
print(dp[N][maxW])

Measured memory_bytes: 26504
// in the name of god
// author : esoheil84

#include <bits/stdc++.h>

using namespace std;

const int N = 1e4 + 1;

int ans[N];

int main() {
	int n;
	cin >> n;
	for (int x = 1; x <= 105; x++) {
		for (int z = 1; z <= 105; z++) {
			for (int y = 1; y <= 105; y++) {
				int v = x * x + y * y + z * z + z * y + y * x + z * x;
				if (v < 1e4 + 1) ans[v]++;
			}
		}
	}
	for (int i = 1; i <= n; i++) cout << ans[i] << '\n';
}


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

#undef _P
#define _P(...) (void)printf(__VA_ARGS__)
#define FOR(x,to) for(x=0;x<(to);x++)
#define FORR(x,arr) for(auto& x:arr)
#define ITR(x,c) for(__typeof(c.begin()) x=c.begin();x!=c.end();x++)
#define ALL(a) (a.begin()),(a.end())
#define ZERO(a) memset(a,0,sizeof(a))
#define MINUS(a) memset(a,0xff,sizeof(a))
//-------------------------------------------------------


void solve() {
    int i,j,k,l,r; string s;
    bool exit = false;
    int N;
    cin>>N;
    vector <int> x(N);
    vector <int> y(N);
    vector <int> h(N);
    FOR(i,N){
        cin>>x[i]>>y[i]>>h[i];
    }
    int ansX=-1,ansY=-1;
    int needH,posX,posY;
    FOR(posX,101){
        FOR(posY,101){
            exit=false;
            //needH=-1 => unknown
            //needH=-2 => ng 
            needH = -1;
            FOR(i,N){
                if(h[i] != 0){
                    if(needH==-1){
                        needH=abs(x[i]-posX)+abs(y[i]-posY)+h[i];
                    }else{
                        if(needH != abs(x[i]-posX)+abs(y[i]-posY)+h[i]){
                            needH=-2;
                            break;
                        }
                    }
                }
            }
            if(needH==-2)
                continue;
            FOR(i,N){
                if(h[i] == 0){
                    if(needH - abs(x[i]-posX) - abs(y[i]-posY) > 0){
                        needH=-2;
                        break;
                    }
                }
            }
            if(needH==-2)
                 continue;
            ansX=posX;
            ansY=posY;
            exit=true;
            break;  
        }
        if(exit){
            break;
        }
    }
    cout<<ansX<<" "<<ansY<<" "<<needH<<endl;
    /*cin>>N;
    vector<ll> V((N+1)*(N+1));
    FOR(x,N+1) {
            FOR(y,N+1) {
                    ll ret=1;
                    FOR(i,x) ret*=2;
                    FOR(i,y) ret*=5;
                    V.push_back(ret);
            }
    }
    sort(ALL(V));
    FORR(v,V) cout<<v<<endl;*/
}


int main(int argc,char** argv){
	string s;int i;
	if(argc==1) ios::sync_with_stdio(false), cin.tie(0);
	FOR(i,argc-1) s+=argv[i+1],s+='\n'; FOR(i,s.size()) ungetc(s[s.size()-1-i],stdin);
	cout.tie(0); solve(); return 0;
}



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

int a[100010][3];
int dp[100010][3];

int main(){
	int n;
	scanf("%d", &n);
	for (int i = 1; i <= n; i++){
		scanf("%d%d%d", &a[i][0], &a[i][1], &a[i][2]);
	}
	for (int i = 1; i <= n; i++){
		for (int j = 0; j < 3; j++){
			for (int k = 0; k < 3; k++){
				if (j == k) continue;
				dp[i][j] = max(dp[i][j], dp[i - 1][k] + a[i][j]);
			}
		}
	}
	printf("%d\n", max(dp[n][0], max(dp[n][1], dp[n][2])));
	return 0;
}


Measured memory_bytes: 2560
#include <iostream>
#include <string>
using namespace std;
int main(){
  string s, w[]={"SAT", "FRI", "THU", "WED", "TUE", "MON", "SUN"};
  cin >> s;
  for(int i=0; i<7; i++){
    if(s==w[i]) {cout << i+1; return 0;}
  }
  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstring>
#include <cstdio>
#include <cstdlib>
using namespace std;

int main()
{
    char input[3][4];
    for(int i=1;i<=2;i++){
        for(int j=1;j<=3;j++){
            cin>>input[i][j];
        }
    }
    
    if(input[1][1]==input[2][3]&&input[1][2]==input[2][2]&&input[1][3]==input[2][1]){
        cout<<"YES"<<endl;
    }else{
        cout<<"NO"<<endl;
    }
    
    return 0;
}

Measured memory_bytes: 256
def resolve():
    a = int(input())
    b = int(input())
    c = int(input())
    x = int(input())
    count = 0
    n = 0
    for i in range(a+1):
        ni = 500*i
        if ni > x:
            continue
        for j in range(b+1):
            nj = ni + 100*j
            if nj > x:
                continue
            for k in range(c+1):
                nk = nj + 50*k
                if nk != x:
                    continue
                elif nk == x:
                    count += 1
    print(count)
resolve()

Measured memory_bytes: 9180
//AnkitCode99 here....
//every ups and downs matter!

#include<bits/stdc++.h>

#define endl "\n"
typedef long long int ll;
#define MOD 1000000007
#define pll pair<ll,ll>
#define pb push_back
//max xor btw range of two numbers..
#define max_XOR(a,b) (1 << int(log2(a ^ b) + 1)) - 1
#define vl vector<ll>
#define inf ll(1e18)
#define all(v) v.begin(),v.end()
#define Ryuga ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define rep(i,a,b) for(long long int i=a;i<b;i++)
#define nrep(i,a,b) for(long long int i=a;i>=b;i--)
#define ceil(a,b) a/b+((a%b ==0 )?0:1)

using namespace std;

const ll sz=100005;
const ll szz=1000006;

int main()
{
    Ryuga;
    
   

    ll n;
    cin>>n;
    ll sum=0;
    rep(i,1,n+1)
    {
        if(!(i%3==0 or i%5==0))
            sum+=i;
    }
    cout<<sum<<endl;

    
}//Goodbye...

Measured memory_bytes: 3664
#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 lli long long int
#define llu unsigned long long int
#define pb push_back
#define rt return 0
#define endln "\n"
#define all(x) x.begin(), x.end()
#define sz(x) (lli)(x.size())
const lli MOD = 1e9 + 7;
const double PI = 3.14159265358979323846264338;
// cout << fixed << setprecision(0) << pi <<endl;
// typedef tree<int, null_type, less<int>, rb_tree_tag,
//              tree_order_statistics_node_update>
//     new_data_set;
// for multiset
// typedef tree<int, null_type, less_equal<int>, rb_tree_tag,
//              tree_order_statistics_node_update>
//     new_data_set;
// order_of_key(val): returns the number of values less than val
// find_by_order(k): returns an iterator to the kth largest element (0-based)

void solve() {
    lli n, a;
    string s, t;
    cin >> s;
    cin >> t;
    lli cnt = 0;
    for (lli i = 0; i < s.length(); i++) {
        if (s[i] != t[i]) {
            cnt++;
        }
    }
    cout << cnt << endl;
}

int main(void) {
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    // lli t; cin >> t; while(t--)
    solve();
    rt;
}

Measured memory_bytes: 3800
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <cmath>
#include <functional>
#include <iomanip>

#include <stack>

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

// #define rep(i,n) for(int i=0;i<(n);++i)
#define all(a) (a).begin(),(a).end()
#define _overload3(_1,_2,_3,name,...) name
#define _rep(i,n) for(int i=0;i<(n);++i)
#define repi(i,a,b) for(int i=(a);i<(b);++i)
#define rep(...) _overload3(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)
#define _fromto2(i,n) for(int i=0;i<=(n);++i)
#define _fromto3(i,a,b) for(int i=(a);i<=(b);++i)
#define fromto(...) _overload3(__VA_ARGS__,_fromto3,_fromto2,)(__VA_ARGS__)

#define rrep(i,n) for(int i=(n);i>=0;--i)
#define iter(it,v) for(auto it=v.begin();it!=v.end();++it)
const int MOD = 1e9+7;
const int INF = 1e9;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }

// debug
template<class T>ostream& operator<<(ostream& os, vector<T>& vec){os<<"{";for(int i=0;i<vec.size();++i)os<<(i?", ":"")<<vec[i];os<<"}";return os;}
template<class T1,class T2>ostream& operator<<(ostream& out,const pair<T1,T2>& rhs){out<<"("<<rhs.first<<", "<<rhs.second<<")";return out;}
#include<type_traits>
template<typename T,size_t SIZE,enable_if_t<!is_same<remove_cv_t<T>,char>::value,nullptr_t> = nullptr>ostream& operator<<(ostream& os,T(&arr)[SIZE]){os<<"{";for(size_t i=0;i<SIZE;++i)os<<(i?", ":"")<<arr[i];os<<"}";return os;}

#ifdef LOCAL
  void debug() {cerr << "\n";}
  template<class First> void debug(const First& first) {cerr<<first<<"\n";}
  template<class First, class... Rest> void debug(const First& first, const Rest&... rest) {cerr<<first<<",";debug(rest...);}
#else
  #define debug(...) 42
#endif

struct Range {
  int l, r;
  int mid;
  Range(int l, int r) : mid((l+r)/2) {};
};

const int MALE = 1, FEMALE = 2, VACANT = 3, UNKNOWN = 4;
int query(int n) {
  cout << n << endl;
  flush(cout);

  string ans;
  cin >> ans;
  if (ans == "Male") return MALE;
  if (ans == "Female") return FEMALE;
  return VACANT;
}
int main() {
  int N; cin >> N;

  int table[N];
  rep(i, N) table[i] = UNKNOWN;

  table[0] = query(0);
  if (table[0] == VACANT)
    return 0;
  table[N-1] = query(N-1);
  if (table[N-1] == VACANT)
    return 0;
  int l = 0, r = N-1;
  while (abs(l - r) >= 1) {
    int m = (l + r) / 2;
    int res = query(m);
    if (res == VACANT)
      return 0;
    table[m] = res;
    table[m-1] = (res == MALE ? FEMALE : MALE);
    if ((((m-1) - l) % 2 == 1) == (table[l] == table[m-1])) {
      r = m;
    } else
      l = m;
  }
  query(l);


  return 0;
}


// s =  [1, 0, 2, 1, 2]
// [*] i =  0 , s[i] =  1
// [*] i =  4 , s[i] =  2
// [*] i =  2 , s[i] =  2
// [*] i =  3 , s[i] =  1
// [*] i =  4 , s[i] =  2
//


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

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

	if ((b - a) == (c - b)) {
		cout << "YES" << endl;
	}
	else {
		cout << "NO" << endl;
	}


}





Measured memory_bytes: 3632
#include "bits/stdc++.h"

#define rep(i, a) for (int i = 0; i < (int)a; ++i)
#define REP(i, a, b) for (int i = (a); i < (int)b; ++i)

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

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

void Main() {
  int n;
	cin >> n;
  vector<P> ord(n);
	for (int i = 0; i < n; i++) {
		cin >> ord[i].first;
    ord[i].second = i;
	}

  vector<ll> dp(n+1, 0);
	sort(ord.begin(), ord.end());
  rep(i, n) {
    rep(l, n - i + 1) {
			int r = l + i;
			const auto &[a, pos] = ord[i];
			dp[l] = max(dp[l] + a * abs(pos - r), dp[l + 1] + a * abs(pos - l));
		}
	}

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

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


Measured memory_bytes: 3668
#include <iostream>
#include<stdio.h>
#include<algorithm>
#include<string.h>
#include<math.h>
#include<stack>
#include<queue>
#include<string>
#include<set>
#define ll long long
using namespace std;
int main()
{
   int n;
   scanf("%d",&n);
   if(n%2==0)
   printf("%d\n",n);
   else
   printf("%d\n",2*n);
	return 0;
 } 

Measured memory_bytes: 888