akhauriyash/Code-Regression huggingface dataset:
#include <stdio.h>
#include <stdlib.h>

void InsSort(int num[ ], int n) ;
void ShowData(int num[ ], int n);
int main(void);

void InsSort(int num[ ], int n)
{
    int i, j, temp;

    for (i = 1; i < n; i++) {
        temp = num[i];
        for (j = i; j > 0 && num[j-1] > temp; j--)
            num[j] = num[j -1];

        num[j] = temp;
        ShowData(num, n);
    }
}

/* n 個のデータを表示 */
void ShowData(int num[ ], int n)
{
  while (n--){
    if(n == 0)
      printf("%d", *num++);
    else
      printf("%d ", *num++);
  }
  printf("\n");
}

int main(void)
{
  int NUM_DATA,i;
  int *num;

  while(1){
 scanf("%d",&NUM_DATA);
  if(NUM_DATA >= 0 || NUM_DATA <= 100)break;
  }

  num = (int *)malloc(sizeof(int) * NUM_DATA);

  for(i = 0; i < NUM_DATA; i++){
    while(1){
    scanf("%d",&num[i]);
    if(num[i] >= 0 || num[i] <= 1000) break;
    }
  }



  for(i = 0;i<NUM_DATA;i++){
    if(i < NUM_DATA-1)
      printf("%d ",num[i]);
    else
      printf("%d",num[i]);
  }
  printf("\n");

    InsSort(num, NUM_DATA);

    for(i = 0; i++; i < NUM_DATA){
      free(num);
    }

    return 0;
}




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

#define rep(i, n) for (int i = 0; i < int(n); i++)
#define rrep(i, n) for (int i = int(n) - 1; i >= 0; i--)
#define reps(i, n) for (int i = 1; i <= int(n); i++)
#define rreps(i, n) for (int i = int(n); i >= 1; i--)
#define repc(i, n) for (int i = 0; i <= int(n); i++)
#define rrepc(i, n) for (int i = int(n); i >= 0; i--)
#define repi(i, a, b) for (int i = int(a); i < int(b); i++)
#define repic(i, a, b) for (int i = int(a); i <= int(b); i++)
#define each(x, y) for (auto &x : y)
#define all(a) (a).begin(), (a).end()
#define bit32(x) (1 << (x))
#define bit64(x) (1ll << (x))
#define sz(v) ((int) v.size())

using namespace std;

using i64 = long long;
using f80 = long double;
using vi32 = vector<int>;
using vi64 = vector<i64>;
using vf80 = vector<f80>;
using vstr = vector<string>;

inline void yes() { cout << "Yes" << endl; exit(0); }
inline void no() { cout << "No" << endl; exit(0); }
template <typename T> class pqasc : public priority_queue<T, vector<T>, greater<T>> {};
template <typename T> class pqdesc : public priority_queue<T, vector<T>, less<T>> {};
template <typename T> inline void amax(T &x, T y) { x = max(x, y); }
template <typename T> inline void amin(T &x, T y) { x = min(x, y); }
template <typename T> inline T exp(T x, i64 n, T e = 1) { T r = e; while (n > 0) { if (n & 1) r *= x; x *= x; n >>= 1; } return r; }
template <typename T> istream& operator>>(istream &is, vector<T> &v) { each(x, v) is >> x; return is; }
template <typename T> ostream& operator<<(ostream &os, vector<T> &v) { rep(i, v.size()) { if (i) os << ' '; os << v[i]; } return os; }
void solve(); int main() { ios::sync_with_stdio(0); cin.tie(0); cout << fixed << setprecision(16); solve(); return 0; }

void solve() {
  int n, x, y;
  cin >> n >> x >> y;
  x--, y--;
  vi32 ans(n);
  rep(i, n - 1) repi(j, i + 1, n) {
    int dist = j - i;
    amin(dist, abs(i - x) + 1 + abs(y - j));
    ans[dist]++;
  }
  reps(i, n - 1) {
    cout << ans[i] << endl;
  }
}

Measured memory_bytes: 256
#include <iostream>
#include<map>
#define REPD(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, n) REPD(i, 0, n)

using namespace std;
#define fin(ans) cout << (ans) << '\n'
int main()
{
    int A,B;
    cin >> A >> B;
    if((A+B)%2) fin("IMPOSSIBLE");
    else fin((A+B)/2);
    return 0;
}

Measured memory_bytes: 3180
def main():
  N = int(input())
  S = input()
  M = 0

  for i in range(1, N):
    s1 = set(list(S[:i]))
    s2 = set(list(S[i:]))

    M = max(M, len(s1.intersection(s2)))

  print(M)


if __name__ == "__main__":
  main()


Measured memory_bytes: 3060
#include<bits/stdc++.h>
#define For(i,j,k) for(int i=j;i<=k;++i)
#define Forr(i,j,k) for(int i=j;i>=k;--i)
#define ll long long 
using namespace std;
const int N = 17, INF = 0x3f3f3f3f, S = 1 << N, Mod = 1e9 + 7;
template<class T>void read(T &x){
	x=0;char c=getchar();
	while(!isdigit(c))c=getchar();
	while( isdigit(c))x=x*10+c-48,c=getchar();
}
inline void file(){
	freopen("test.in","r",stdin);
	freopen("test.out","w",stdout);
}
int n, F[1 << N], A[N], m, fac[S + 10], ifac[S + 10];
ll qpow(ll a, ll b){
	ll ret = 1;
	for(;b;b>>=1,a=a*a%Mod)if(b&1)ret=ret*a%Mod;
	return ret;
}
void init(){
	read(n), read(m);
	For(i, 1, m)read(A[i]);
	sort(A + 1, A + m + 1);
	reverse(A + 1, A + m + 1);
	fac[0] = 1;
	For(i, 1, S)fac[i] = 1ll * fac[i - 1] * i % Mod;
	ifac[S] = qpow(fac[S], Mod - 2);
	Forr(i, S, 1)ifac[i - 1] = ifac[i] * 1ll * i % Mod;
}
inline ll C(int a, int b){
	if(a < 0 || b < 0 || a < b)return 0;
	return fac[a] * 1ll * ifac[b] % Mod * ifac[a - b] % Mod;
}
int cnt[S + 10];
inline void add(int &a, int b){a = (a + b) % Mod;}
void solve(){
	int all = (1 << n);
	For(i, 1, all - 1)
		cnt[i] = cnt[i >> 1] + (i & 1);
	F[0] = 1;
	For(i, 1, m)
		Forr(s, all - 1, 0)if(cnt[s] < i)
			For(j, 0, n - 1)if(!((s >> j) & 1))
				add(F[s | (1 << j)], C(all - s - A[i], (1 << j) - 1) * F[s] % Mod * fac[1 << j] % Mod);
	int ans = 0;
	For(i, 0, all - 1){
		int cur = 1ll * F[i] * fac[all - 1 - i] % Mod;
		if(cnt[i] & 1)ans = (ans + Mod - cur) % Mod;
		else ans = (ans + cur) % Mod;
	}
	ans = 1ll * ans * all % Mod;
	printf("%d\n", ans);
}
int main(){
	//file();
	init();
	solve();
	return 0;
}


Measured memory_bytes: 1792
import java.util.*;
public class Main {
        static Scanner sc = new Scanner(System.in);
        static void myout(Object t){System.out.println(t);}//standard output
        static void myerr(Object t){System.err.println(t);}//standard error
        static String getStr(){return sc.next();}
        static int getInt(){return Integer.parseInt(getStr());}
        static long getLong(){return Long.parseLong(getStr());}
        static boolean hasNext(){return sc.hasNext();}
        static char[] mySplit(String str){return str.toCharArray();}
        static String toKaigyo(String[] list){return String.join("\n",list);}
        static String toHanSp(String[] list){return String.join(" ",list);}
        public static void main(String[] args){
          int N = getInt();
          int M = getInt();
          UnionFind uf = new UnionFind(N);
          ArrayList[] langList = new ArrayList[M];
          for(int i = 0; i < N; i++){
            int K = getInt();
            for(int j = 0; j < K; j++){
              int useLang = getInt() - 1;
              if(langList[useLang] == null){
                langList[useLang] = new ArrayList<Integer>();
              }
              langList[useLang].add(i);
            }
          }
          for(int i = 0; i < M; i++){
            ArrayList<Integer> tmpList = langList[i];
            if(tmpList == null){
              continue;
            }
            if(tmpList.size() > 1){
              int first = tmpList.get(0);
              for(int j = 1; j < tmpList.size(); j++){
                uf.doUnion(first,tmpList.get(j));
              }
            }
          }
          String output = "NO";
          for(int i = 0; i < N; i++){
            if(uf.getSize(i) == N){
              output = "YES";
              break;
            }
          }
          myout(output);
        }
        //Method addition frame start
public static class UnionFind{
  public int[] list;
  UnionFind(int size){
    list = new int[size];
    for(int i = 0; i < size; i++){
      list[i] = -1;
    }
  }
  public boolean isSame(int mae, int ato){
    return this.getRootIndex(mae) == this.getRootIndex(ato);
  }
  public int getRootIndex(int index){
    if(this.list[index] < 0){
      return index;
    }else{
      list[index] = this.getRootIndex(list[index]);
      return list[index];
    }
  }
  public void doUnion(int mae, int ato){
    int maeRoot = this.getRootIndex(mae);
    int atoRoot = this.getRootIndex(ato);
    if(!isSame(maeRoot, atoRoot)){
      if(maeRoot >= atoRoot){
        list[maeRoot] += list[atoRoot];
        list[atoRoot] = maeRoot;
      }else{
        list[atoRoot] += list[maeRoot];
        list[maeRoot] = atoRoot;
      }
    }
  }
  public int getSize(int index){
    return -list[this.getRootIndex(index)];
  }
}
        //Method addition frame end
}


Measured memory_bytes: 62508
/*
ID: yzshang1
LANG: C++11
TASK:
*/
#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
#define pb push_back
#define mp make_pair
#define lsh(i) (1 << (i))
#define lshll(i) (1LL << (i))
#define repn(i, n) for (int (i) = 1; (i) <= (int)n; (i)++)
#define rep(i, n) for (int (i) = 0; (i) < (int)n; (i)++)
const int INF = 0x3f3f3f3f;
const long double EPS = 1e-6;
const int N = 10010, MOD = 1e9 + 7;
long long a[N], n;
const int M = 1000010;
int f[M];
LL qpow(LL a, LL b = MOD - 2, LL p = MOD) {
	LL ans = 1;
	for (; b; b >>= 1) {
		if (b & 1) ans = ans * a % p;
		a = a * a % p;
	}
	return ans;
}
void debugPrint(map <int, int> m) {
	for (auto i:m) {
		cout << "{" << i.first << "," << i.second << "} ";
	}
	cout << endl;
} 
void fact(int id, LL x) {
	LL y = x;
	for (int i = 2; i * i <= y; i++) {
		int cnt = 0;
		while (x % i == 0) {
			x /= i;
			cnt++;
		}
		if (cnt) f[i] = max(f[i], cnt);
	}
	if (x != 1) f[x] = max(f[x], 1);
}

int main() {
	cin >> n;
	repn(i, n) cin >> a[i], fact(i, a[i]);
	LL ans = 0, res = 0;
//	debugPrint(F);
	LL lcm = 1;
	repn(i, 1000000) while (f[i]--) lcm = lcm * i % MOD;
	repn(i, n) {
		ans = (ans + lcm * qpow(a[i])) % MOD;
	}
//	cerr << endl;
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 4224
import java.util.Scanner;

public class Main {
	public static void main(String[] args) throws Exception {
		Scanner sc = new Scanner(System.in);
		String s = sc.next();
		sc.close();

		if ("Sunny".equals(s)) {
			System.out.println("Cloudy");
		} else if ("Cloudy".equals(s)) {
			System.out.println("Rainy");
		} else {
			System.out.println("Sunny");
		}
	}
}


Measured memory_bytes: 22228
import sys
S = input()
als = ["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"]

for i in range(len(S)):
    if S[i] in als:
        als.remove(S[i])
    if als ==[]:
        print("None")
        sys.exit()
print(als[0]) 

Measured memory_bytes: 3188
#include <bits/stdc++.h>
using namespace std;
#define rep(i, s, n) for (int i = (s); i < (n); ++i)
#define rem(i, s, n) for (int i = (s); i >= (n); --i)
using ll = long long;
const int MOD = 1e9 + 7;

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

    int ans = 0;
    rep(i, 0, n - 2){
        if(s[i] == 'A' && s[i+1] == 'B' && s[i+2] == 'C'){
            ans++;
            i += 2;
        }
    }

    cout << ans << endl;
    
    return 0;
}

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

#define Omar45 ios_base::sync_with_stdio(false); cin.tie(NULL);
#define ll long long
#define pb push_back
#define F first
#define S second
#define endl '\n'
#define mod 1e9 + 7
const ll maxN = 1e5 + 5;
const int INF = 0x3f3f3f3f;

int main() {
	Omar45
    int n, k; cin >> n >> k;
    int arr[n];
    for (int i=0; i<n; i++) cin >> arr[i];
    bool dp[k+1] = {0};
    for (int s=0; s<=k; s++){
        for (int it: arr){
            if (s >= it && !dp[s-it])
                dp[s] = 1;
        }
    }
    string ans = dp[k] ? "First" : "Second";
    cout << ans << endl;
}


Measured memory_bytes: 384
import java.io.*;
public class Main{  
    public static void main(String[] args){
        try{
            BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
			String[] score = reader.readLine().split(" ");
			String txt1 = score[0];
			String txt2 = score[1];
			int a = Integer.parseInt(txt1);
			int b = Integer.parseInt(txt2);
			int num;
			int sum;
			num = a * b;
			sum = (a * 2) + (b * 2);
			System.out.println(num + " " + sum);
        }catch(IOException e){
            System.out.println(e);
        }
    }
}

Measured memory_bytes: 24016
from bisect import *

n = int(input())
l = sorted(list(map(int, input().split())))

cnt = 0

for i in range(n):
    a = l[i]
    for j in range(i+1, n):
        b = l[j]
        k = bisect_left(l, a+b)
        cnt += k-(j+1)
print(cnt)

Measured memory_bytes: 9200
#Skill Up
n,m,x = map(int, input().split())

#ca = [map(int, input().split()) for _ in range(n)]
#ca = [input().split() for l in range(n)]
import sys
ca = [[int(c) for c in l.split()] for l in sys.stdin]
#c, a = [list(i) for i in zip(*ca)]
#print(ca)
#print(ca[0][0])
c=[]
for l in range(n):
    c.append(ca[l][0])
#print(c)

for l in range(n):
    del ca[l][0]
#print(ca)

INF = float('INF')
min_cost = INF
 
def dfs(i, cost, learn):
    if i == n:
        if min(learn) >= x:
            return cost
        else:
            return INF
    else:
        new_learn = [X + Y for (X, Y) in zip(ca[i], learn)]
        cost = min(dfs(i + 1, cost, learn), dfs(i + 1, cost + c[i], new_learn))
        return cost
 
min_cost = dfs(0, 0, [0] * m)
 
if min_cost == INF:
    print(-1)
else:
    print(min_cost)

Measured memory_bytes: 9244
N,M = map(int,input().split())
A = [input() for i in range(N)]
B = [input() for i in range(M)]



for i in range(N-M+1):
    for j in range(N-M+1):
        result = True
        for k in range(M):
            for l in range(M):
                if A[i+k][j+l] != B[k][l]:
                    result = False
        if result:
            print("Yes")
            exit()




print("No")

Measured memory_bytes: 3064
#include <iostream>
int main() {
    int a, b, c;
    std::cin >> a >> b >> c;
    int result = 0;
    for (int i = a; i <= b; i++) {
        if (c % i == 0) {
            result += 1;
        }
    }
    std::cout << result << std::endl;
}


Measured memory_bytes: 3128
//#pragma GCC optimize("Ofast,no-stack-protector,unroll-loops")
//#pragma GCC target("avx,avx2")
//#pragma GCC target("avx2")
//#pragma GCC optimize("O3")

//# include <x86intrin.h>
# include <bits/stdc++.h>

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

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

#define _USE_MATH_DEFINES_
#define ll long long
#define ld long double
#define Accepted 0
#define pb push_back
#define mp make_pair
#define sz(x) (int)(x.size())
#define every(x) x.begin(),x.end()
#define F first
#define S second
#define lb lower_bound
#define ub upper_bound
#define For(i,x,y)  for (ll i = x; i <= y; i ++) 
#define FOr(i,x,y)  for (ll i = x; i >= y; i --)
#define SpeedForce ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0)
// ROAD to...                                                                                                                                                                                                                Red

void setIn(string s) { freopen(s.c_str(),"r",stdin); }
void setOut(string s) { freopen(s.c_str(),"w",stdout); }
void setIO(string s = "") {
	// cin.exceptions(cin.failbit); 
	// throws exception when do smth illegal
	// ex. try to read letter into int
	if (sz(s)) { setIn(s+".in"), setOut(s+".out"); } // for USACO
}

const double eps = 0.000001;
const ld pi = acos(-1);
const int maxn = 1e7 + 9;
const int mod = 1e9 + 7;
const ll MOD = 1e18 + 9;
const ll INF = 1e18 + 123;
const int inf = 2e9 + 11;
const int mxn = 1e6 + 9;
const int N = 6e5 + 123;                                          
const int M = 22;
const int pri = 997;
const int Magic = 2101;

const int dx[] = {-1, 0, 1, 0};
const int dy[] = {0, -1, 0, 1};
mt19937 gen(chrono::steady_clock::now().time_since_epoch().count());
 
int rnd (int l, int r) {
	return uniform_int_distribution<int> (l, r)(gen);
}
 
int n, m, k;
int cnt[N];
string s;
int a[N];
vector < int > g[N];
int u[N];
int ans, res;
int cur;



int main () {
	SpeedForce;
	setIO();
	char s;
	cin >> s;
	if(isupper(s)) cout << 'A';
	else cout << 'a';

	return Accepted;
}

// B...a

Measured memory_bytes: 17684
#include <bits/stdc++.h>
using namespace std;
int main(){
    int n;
    cin>>n;
    vector<int> v(n);
    vector<int> c(n);
    for(int j=0;j<n;j++){
        cin>>v.at(j);
    }
    for(int j=0;j<n;j++){
        cin>>c.at(j);
    }
    vector<int> a(n);
    for(int j=0;j<n;j++){
        a.at(j)=v.at(j)-c.at(j);
    }
    int ans=0;
    for(int i=0;i<n;i++){
        if(a.at(i)>0){
            ans+=a.at(i);
        }
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 256
#include <cstring>
#include <map>
#include <unordered_map>
#include <string>
#include <list>
#include <vector>
#include <algorithm>
#include <queue>
#include <stack>
#include <cstdio>
#include <iostream>
#include <set>
#include <unordered_set>
using namespace std;

#define MAX(a,b) (a>b?a:b)
#define MIN(a,b) (a<b?a:b)
typedef long long ll;
typedef unsigned long long ull;
typedef unsigned int ui;
typedef pair<int, int> pii;

int gi() {
    int a;
    scanf("%d", &a);
    return a;
}

ll gli() {
    ll a;
    scanf("%lld", &a);
    return a;
}
int a[200000];
int p[200000];

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int n = gi();
    ll k = gli();
    for (int i = 0; i < n; i++)
        a[i] = gi()-1;

    int x = 0;
    if (k > 300000) {
        memset(p, -1, sizeof(p));
        p[0] = 0;
        int t = 0;
        while (1) {
            x = a[x];
            t++;
            if (p[x] != -1) {
                k -= t;
                k %= (t-p[x]);
                break;
            }
            p[x] = t;
        }
    }

    while (k--)
        x = a[x];
    printf("%d\n", x+1);

    return 0;
}


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

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

    if (a >= b && b >= c) {
        string sa,sb,sc;
        sa = to_string(a);
        sb = to_string(b);
        sc = sa + sb;
        int id = stoi(sc);

        cout << id + c << endl; 
    }else if (a >= c && c >= b) {
        string sa,sb,sc,sd;
        sa = to_string(a);
        sb = to_string(b);
        sc = to_string(c);
        sd = sa + sc;
        int id = stoi(sd);
        
        cout << id + b << endl;
    }else if (b >= c && c >= a) {
        string sa,sb,sc,sd;
        sa = to_string(a);
        sb = to_string(b);
        sc = to_string(c);
        sd = sb + sc;
        int id = stoi(sd);

        cout << id + a << endl;
    }else if (b >= a && a >= c) {
        string sa,sb,sc,sd;
        sa = to_string(a);
        sb = to_string(b);
        sc = to_string(c);
        sd = sb + sa;
        int id = stoi(sd);

        cout << id + c << endl;
    }else if (c >= a && a >= b) {
        string sa,sb,sc,sd;
        sa = to_string(a);
        sb = to_string(b);
        sc = to_string(c);
        sd = sc + sa;
        int id = stoi(sd);

        cout << id + b << endl;
    }else if (c >= b && b >= a) {
        string sa,sb,sc,sd;
        sa = to_string(a);
        sb = to_string(b);
        sc = to_string(c);
        sd = sc + sb;
        int id = stoi(sd);

        cout << id + a << endl;
    }

    return 0;
}


Measured memory_bytes: 256
#include <sstream>
#include <string>
#include <vector>
#include <map>
#include <algorithm>
#include <iostream>
#include <utility>
#include <set>
#include <cctype>
#include <queue>
#include <stack>
#include <cstdio>
#include <cstdlib>
#include <cmath>
using namespace std;
typedef long long ll;
int main(void) {
    ll a, b, A, B;
    while (cin >> a >> b) {
        A = a; B = b;
        if (a < b) swap(a, b);
        ll r = b;
        while (r) {
            r = a % b;
            a = b;
            b = r;
        }
        cout << a << " " << (A/a) * B << endl;
    }
    return 0;
}

Measured memory_bytes: 1156
#include <bits/stdc++.h>
using namespace std;
int main(){
  int N,M;
  struct node{
    int s;
    int e;
    bool operator<( const node& tmp ) const {
      return e<tmp.e;
    };
  };
  cin>>N>>M;
  int a[M],b[M];
  node n[M];
  for(int i=0;i<M;i++){
    cin>>a[i]>>b[i];
    node t={a[i],b[i]};
    n[i]=t;
  }
  sort(n,n+M);
  //for(int i=0;i<M;i++)cout<<n[i].d<<endl;
  int ans=0,l=-1;
  for(int i=0;i<M;i++){
    if(n[i].s<=l and l<n[i].e) continue;
    ans++;
    l=n[i].e-1;
  }

  cout<<ans<<endl;
}


Measured memory_bytes: 1792
import java.util.Scanner;
class Main{
  public static void main(String[] args){
    Scanner scan=new Scanner(System.in);
    int num=scan.nextInt();
    int max=scan.nextInt();
    int Ans=0;
    boolean flag=true;
    while(flag){
      if(num*Ans-(Ans-1)>=max){
        flag=false;
        System.out.println(Ans);
      }
      Ans++;
    }
  }
}

Measured memory_bytes: 23764
#include <iostream>
#include <fstream>
#include <vector>
#include <utility>
#include <map>
#include <set>
#include <list>
#include <deque>
#include <queue>
#include <stack>
#include <forward_list>
#include <unordered_set>
#include <unordered_map>
#include <algorithm>
#include <string>
#include <bitset>
#include <memory>
#include <chrono>
#include <cmath>
#include <cstdio>
#include <ctime>
#include <cstring>
#include <cstdlib>
#include <cstdint>
#include <iomanip>
#include <tuple>
#include <random>

typedef unsigned long long int ull;
typedef long long int ll;

using namespace std;

int main(void) {
    int a,b,c,x,ret = 0;
    cin >> a >> b >> c >> x;
    for(int i = 0;i <= a && x >= 500*i;i++)
        for(int ii = 0;ii <= b && x >= 500*i + 100*ii;ii++)
            if((x - (500*i + 100*ii)) / 50 <= c)
                ret++;
    cout << ret << endl;
}


Measured memory_bytes: 256
import java.util.Arrays;
import java.util.List;
import java.util.ArrayList;
import java.util.Scanner;

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>[] edge = new ArrayList[n];

        for (int i=0; i<n; i++) edge[i] = new ArrayList<>();

        for (int i=0; i<m; i++){
            int s = sc.nextInt()-1;
            int t = sc.nextInt()-1;
            edge[s].add(t);
        }

        double[] dp = new double[n];

        double ans = Double.MAX_VALUE;
        for (int i=0; i<n-1; i++){
            Arrays.fill(dp, 0.0);
            for (int j=n-2; j>=0; j--){
                double sum = 0;
                double max = 0;
                for (int e: edge[j]){
                    sum += dp[e];
                    max = Math.max(max, dp[e]);
                }
                dp[j] = sum / edge[j].size() + 1;
                if (j==i && edge[j].size() > 1){
                    dp[j] = (sum-max) / (edge[j].size()-1) + 1;
                }
            }
            ans = Math.min(ans, dp[0]);
        }
        System.out.println(ans);
    }
}

Measured memory_bytes: 96860
#include <algorithm>
#include <cassert>
#include <cstdio>
#include <cmath>
#include <queue>
#include <set>
#include <string>
#include <vector>

#define FOR(i,n) for(int i=0;i<(n);++i)
#define FORU(i,j,k) for(int i=(j);i<=(k);++i)
#define FORD(i,j,k) for(int i=(j);i>=(k);--i)

#define RDI(n) scanf("%d", &(n));
#define RDL(n) scanf("%lld", &(n));

using namespace std;

using lli = long long int;
using pll = pair<lli, lli>;

const long long int oo = 1000*1000*1000;

struct Coord
{
	int x, y;
	Coord(int x = 0, int y = 0) : x(x), y(y) {}
	Coord operator + (const Coord& droite) const
	{
		return Coord(x + droite.x, y + droite.y);
	}
};

struct AB
{
	int k;
	vector<lli> arbre;
	AB(int _k = 20, lli def = 0)
	{
		k = _k;
		FOR(i, 1 << k)
			arbre.push_back(i < (1 << (k-1)) ? 0LL : def);
		FORD(i, ((1 << (k-1)) - 1), 1)
			arbre[i] = arbre[i << 1] + arbre[(i << 1) ^ 1];
	}
	void set(int i, lli x)
	{
		int feuille = i + (1 << (k-1));
		arbre[feuille] = x;
		iset(feuille >> 1);
	}
	void iset(int noeud)
	{
		if(noeud)
		{
			arbre[noeud] = arbre[noeud << 1] + arbre[(noeud << 1)  ^ 1];
			iset(noeud >> 1);
		}
	}
	lli sum(int deb, int fin, int noeud = 1, int p = 0, int q = -1)
	{
		if(q < p)
			q = 1 << (k-1);
		if(deb <= p && q <= fin)
			return arbre[noeud];
		if(deb >= q || fin <= p)
			return 0LL;
		int mil = (p + q) / 2;
		return sum(deb, fin, noeud << 1, p, mil) + sum(deb, fin, (noeud << 1) ^ 1, mil, q);
	}
};

struct Int
{
	int v;
	int i;
	Int(int v = 0, int i = 0) : v(v), i(i) {}
	bool operator < (const Int& droite) const
	{
		if(v != droite.v)
			return v < droite.v;
		return i < droite.i;
	}
};

const int MAX_N = 500+42;

Int pos[MAX_N];
int amount[MAX_N];
int seq[MAX_N * MAX_N];
int left[MAX_N];

int main()
{
	int n;
	scanf("%d", &n);
	FOR(i, n)
	{
		amount[i+1] = i;
		left[i+1] = n;
		int tmp;
		scanf("%d", &tmp);
		pos[i] = Int(tmp, i+1);
	}
	sort(pos, pos + n);
	int cur = 0;
	int next = 0;
	int fin = 0;
	FOR(i, n*n)
	{
		if(cur < n && pos[cur].v == i+1)
		{
			if(amount[pos[cur].i])
			{
				printf("No\n");
				return 0;
			}
			seq[i] = pos[cur].i;
			++cur;
		}
		else
		{
			while(next < n && amount[pos[next].i] <= 0)
				++next;
			if(next < n)
				seq[i] = pos[next].i;
			else
			{
				while(fin < n && left[pos[fin].i] == 0)
					++fin;
				assert(left[pos[fin].i] > 0);
				seq[i] = pos[fin].i;
			}
		}
		--left[seq[i]];
		--amount[seq[i]];
		//printf("%d %d %d\n", seq[i], cur, next);
	}
	printf("Yes\n");
	FOR(i, n*n)
		printf("%d ", seq[i]);
	printf("\n");
	return 0;
}


Measured memory_bytes: 2048
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i = 0;i<((int)(n));i++)
#define reg(i,a,b) for(int i = ((int)(a));i<=((int)(b));i++)
#define irep(i,n) for(int i = ((int)(n)-1);i>=0;i--)
#define ireg(i,a,b) for(int i = ((int)(b));i>=((int)(a));i--)
typedef long long ll;

/*
*/

string s;
bool ok=true,before=false;
ll n,a,b,c,d;

void init(){
	cin>>n>>a>>b>>c>>d>>s;
	s="."+s+".";
}

int main(void){
	init();
	if(c<d){
		//bを先に移動させても損はしない。
		reg(i,b,d){
			if(s[i]=='#'){
				if(before){
					ok=false;
				}else{
					before=true;
				}
			}else{
				before=false;
			}
		}
		reg(i,a,c){
			if(s[i]=='#'){
				if(before){
					ok=false;
				}else{
					before=true;
				}
			}else{
				before=false;
			}
		}
	}else{
		//途中でbを追い越す必要あり
		bool done=false;
		reg(i,b,d){
			if(s[i-1]=='.' && s[i]=='.' && s[i+1]=='.'){
				s[i]='#';
				done=true;
				break;
			}
		}
		if(!done)ok=false;
		reg(i,a,c){
			if(s[i]=='#'){
				if(before){
					ok=false;
				}else{
					before=true;
				}
			}else{
				before=false;
			}
		}
	}
	cout<<(ok?"Yes":"No")<<endl;
	return 0;
}

Measured memory_bytes: 772
import java.io.*;
// import java.math.*;
// import java.util.*;
// import java.util.Map.*;
// import java.util.stream.*;

public class Main {
    public static void main (String[] args) throws Exception {
        BufferedReader reader =
            new BufferedReader (new InputStreamReader (System.in));
        String[] arr = reader.readLine().split (" ");
        int A, B;
        A = Integer.parseInt (arr[0]);
        B = Integer.parseInt (arr[1]);
        System.out.println (Math.max (A + B, Math.max (A - B, A * B)));
        return;
    }
}

Measured memory_bytes: 32168
import numpy as np

L, A, B, M = map(int, input().split())

def dot(A, B, mod):
    r = len(A)
    c = len(B[0])
    m = len(A[0])
    res = [[0] * c for _ in range(r)]
    
    for i in range(r):
        for j in range(c):
            for k in range(m):
                res[i][j] += A[i][k] * B[k][j] % mod
                res[i][j] %= mod
    
    return res

def rec_pow(k, n, mod):
    if n == 1:
        return k
    
    k2 = dot(k, k, mod)
    if n % 2 ==0:
        return rec_pow(k2, n//2, mod)
    else:
        return dot(rec_pow(k2, n//2, mod), k, mod)

s = [[0, A%M, 1]]

for d in range(1, 19):
    n1 = min(max(0, (10**d-1-A)//B+1), L)
    n0 = min(max(0, (10**(d-1)-1-A)//B+1), L)
    n = n1 - n0
    if n == 0:
        continue
        
    k = [[pow(10, d, M), 0, 0], [1, 1, 0], [0, B%M, 1]]
    
    s = dot(s, rec_pow(k, n, M), M)
    
    if n1 >= L:
        break
        
print(s[0][0])

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

using namespace std;
typedef long long ll;

struct Edge {
    long long to;
    long long cost;
};
using Graph = vector<vector<Edge>>;
using P = pair<long, int>;
const long long INF = 1LL << 60;

void dijkstra(const Graph &G, int s, vector<ll> &dis, vector<int> &prev) {
    int N = G.size();
    dis.resize(N, INF);
    prev.resize(N, -1); // 初期化
    priority_queue<P, vector<P>, greater<P>> pq; 
    dis[s] = 0;
    pq.emplace(dis[s], s);
    while (!pq.empty()) {
        P p = pq.top();
        pq.pop();
        int v = p.second;
        if (dis[v] < p.first) {
            continue;
        }
        for (auto &e : G[v]) {
            if (dis[e.to] > dis[v] + e.cost) {
                dis[e.to] = dis[v] + e.cost;
                prev[e.to] = v; // 頂点 v を通って e.to にたどり着いた
                pq.emplace(dis[e.to], e.to);
            }
        }
    }
}

int main(){
  ll N, M;
  cin >> N >> M;
  Graph G;
  G.resize(N);
  
  for(ll i=0; i<M; i++){
    ll A, B;
    cin >> A >> B;
    --A; --B;
    Edge edge1 = {B, 1};
    Edge edge2 = {A, 1};
    G[A].emplace_back(edge1);
    G[B].emplace_back(edge2);
  }
  
  vector<int> prev;
  vector<ll>  dis;
  dijkstra(G, 0, dis, prev);
  
  cout << "Yes" << endl;
  for(ll i=1; i<N; i++) cout << prev[i]+1 << endl;
  
  return 0;
}

Measured memory_bytes: 19148
#if 1
  #include <bits/stdc++.h>
#else
  #include "../../../../bits/stdc++.h"
#endif

#define FOR(i,a,b) for(int i = (a);i < (b);i++)
#define RFOR(i,a,b) for(int i = (b)-1;i >= (a);i--)
#define REP(i,n) FOR(i,0,(n))
#define RREP(i,n) RFOR(i,0,(n))

using namespace std;

typedef pair<int, int> P;
#define pb push_back
#define mp make_pair
#define ft first
#define sd second

int main(){
  cin.tie(0);
  
  int A, B;
  cin>>A>>B;
  if(A%3==0||B%3==0||(A+B)%3==0)cout<<"Possible"<<endl;
  else cout<<"Impossible"<<endl;

  return 0;
}


Measured memory_bytes: 256
using System;
using System.Linq;

namespace B
{
    class Program
    {
        static void Main(string[] args)
        {
            var NK = Array.ConvertAll(Console.ReadLine().Split(' '), int.Parse);
            var h = Array.ConvertAll(Console.ReadLine().Split(' '), int.Parse);
            Console.WriteLine(h.Count(i => i >= NK[1]));
        }
    }
}


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

using namespace std;
typedef long long LL;
typedef double ld;
int cal(int x){
	int num = 0,a = 1;
	while(a < x){
		a = a*2;
		num++;
	}
	return num;
}
int qpow(int a,int x){
	int res = 1;
	while(x){
		if(x&1) res = res * a;
		x >>= 1;
		a = a*a;
	}
	return res;
}
int main(){
	int n,k;
	cin >> n >> k;
	int lcm = cal(k);
	LL sum = 1;
	for(int i = 2;i <= n; ++i){
		int x = cal((int)ceil(k*1.0/i));
		sum += qpow(2,lcm-x);
	}
	printf("%.11f",sum*1.0/(1LL*n*qpow(2,lcm)));
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <unistd.h>
#include <sys/time.h>
#include <stdlib.h>
 
using namespace std;
 
typedef long long ll;
typedef pair<ll,ll> P;
typedef pair<P, ll> T;
 
long long int INF = 1e18;
const ll fact_table = 800008;
double Pi = 3.1415926535897932384626;

priority_queue <ll> pql;
priority_queue <P> pqp;
priority_queue <P> bag;
//big priority queue
priority_queue <ll,vector<ll>,greater<ll> > pqls;
priority_queue <P,vector<P>,greater<P> > pqps;
//small priority queue
//top pop
 
ll dx[8]={1,0,-1,0,1,1,-1,-1};
ll dy[8]={0,1,0,-1,1,-1,-1,1};
char dir[] = "DRUL";
//↓,→,↑,←
 
 
#define p(x) cout<<x<<"\n";
#define el cout<<endl;
#define pe(x) cout<<(x)<<" ";
#define ps(x) cout<<fixed<<setprecision(25)<<x<<endl;
#define pu(x) cout<<(x);
#define pb push_back
// #define lb lower_bound
#define ub upper_bound
#define CLEAR(a) a = decltype(a)(); 
#define pc(x) cout << x << ",";
 
 
// ll mod = 998244353;
 ll mod = 1000000007;
  
ll mypow(ll number1,ll number2, ll mod){
 
    if(number2 == 0){
        return 1;
    }else{
        ll number3 = mypow(number1,number2 / 2, mod);
        number3 *= number3;
        number3 %= mod;
        if(number2%2==1){
            number3 *= number1;
            number3 %= mod;
        }
        return number3;
    }
}
ll rui(ll number1,ll number2){
 
    if(number2 == 0){
        return 1;
    }else{
        ll number3 = rui(number1,number2 / 2);
        number3 *= number3;
        number3 %= mod;
        if(number2%2==1){
            number3 *= number1;
            number3 %= mod;
        }
        return number3;
    }
}
ll gcd(ll number1,ll number2){
 
    if(number1 > number2){
        swap(number1,number2);
    }
    if(number1 == 0 || number1 == number2){
        return number2;
    }else{
        return gcd(number2 % number1,number1);
    }
}
void YES(bool condition){
 
    if(condition){
        p("YES");
    }else{
        p("NO");
    }
    return;
}
void Yes(bool condition){
 
    if(condition){
        p("Yes");
    }else{
        p("No");
    }
    return;
}
 
/*
ll fact[fact_table + 5],rfact[fact_table + 5];
 
 
void c3_init(){
    fact[0] = rfact[0] = 1;
    for(ll i=1; i<=fact_table; i++){
        fact[i] = (fact[i-1]*i) % mod;
    }
    rfact[fact_table] = rui(fact[fact_table],mod - 2);
    for(ll i=fact_table; i>=1; i--){
       rfact[i-1] = rfact[i] * i;
       rfact[i-1] %= mod;
    }
    return;}
ll c3(ll n,ll r){
    return (((fact[n] * rfact[r]) % mod ) * rfact[n-r]) % mod;}
*/
bool multicase = false;

ll n,m,num,sum,a,b,c,d,e,h,q;
ll w, ans;
ll k;
char s[500005], t[500005];

void solve(){
    cin >> n >> a >> b;
    ll ans = 0;
    ll set, rem;
    set = n / (a + b);
    rem = n % (a + b);
    ans = set * a;
    if(rem >= a){
        ans += a;
    }else{
        ans += rem;
    }
    p(ans);
    return;
}

int main(){
    // init();
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    ll q;
    if(multicase){
        cin >> q;
    }else{
        q = 1;
    }
    while(q--){
        solve();
    }
    return 0;

}


















Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {

		Scanner sc = new Scanner(System.in);

		long a = sc.nextLong();
		long v = sc.nextLong();
		long b = sc.nextLong();
		long w = sc.nextLong();
		long t = sc.nextLong();

		double resultab = Math.abs(b - a) * 1.0;
		double resultvw = (v - w) * 1.0;
		double resultvwab;
		resultvwab = resultab / resultvw;

		String s;

		if (resultvwab <= 0) {
			s = "NO";
		} else {
			if (resultvwab <= t) {
				s = "YES";
			} else {
				s = "NO";
			}
		}

		System.out.println(s);

	}

}


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

struct edge{
	int to;
	int cost;
};
int n;
vector<edge> to[100005];
vector<int> color(100005);

void dfs(int v, int p, int d){
	if(d % 2 == 0){
		color[v] = 0;
	}else{
		color[v] = 1;
	}
	for (auto nextv: to[v]){
		if(nextv.to == p) continue;
		dfs(nextv.to, v, d + nextv.cost);
	}
	return;
}

int main(){
	cin >> n;
	
	rep(i,n-1){
		int u,v,w;
		cin >> u >> v >> w;
		u--,v--;
		to[u].push_back(edge{v,w});
		to[v].push_back(edge{u,w});
	}
	
	dfs(0,-1,0);
	
	rep(i,n){
		cout << color[i] << endl;
	}
	
    return 0;
}



Measured memory_bytes: 8448
#include <bits/stdc++.h>
using namespace std;
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define FRE freopen("input.txt","r",stdin);freopen("output.txt","w",stdout);
#define all(v) (v).begin(),(v).end()
#define endl "\n"
#define int long long
#define rep(i,a,b) for(int i=a;i<b;i++)
#define per(i,a,b) for(int i=a;i>b;i--)
#define vi vector<int>
#define pii pair<int,int>
#define mii map<int,int>
#define SET(A,VAL) memset(A, VAL, sizeof(A))
#define ff first
#define ss second
#define pb push_back
#define eb emplace_back
#define trace1(x)                cerr<<#x<<": "<<x<<endl
#define trace2(x, y)             cerr<<#x<<": "<<x<<" | "<<#y<<": "<<y<<endl
#define trace3(x, y, z)          cerr<<#x<<":" <<x<<" | "<<#y<<": "<<y<<" | "<<#z<<": "<<z<<endl
#define trace4(a, b, c, d)       cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<endl
#define trace5(a, b, c, d, e)    cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<" | "<<#e<< ": "<<e<<endl
#define trace6(a, b, c, d, e, f) cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<" | "<<#e<< ": "<<e<<" | "<<#f<<": "<<f<<endl
const int MAX = 1e6 + 8;
const int MOD = 1e9 + 7;
const int sz = 1e5 + 5;
void f_io(){
    IOS;
    // #ifndef ONLINE_JUDGE
    // FRE
    // #endif
}


int32_t main(){
    f_io();
    int tc = 1;
    //cin>>tc;
    while(tc--){
        int n, m, k; cin >> n >> m >> k;
        char mat[n][m];
        for(int i = 0; i < n; i++){
            for(int j = 0; j < m; j++){
                cin >> mat[i][j];
            }
        }
        int ans = 0;
        for(int i = 0; i < (1 << (n)); i++){
            for(int j = 0; j < (1 << (m)); j++){
                int cnt = 0;
                for(int p = 0; p < n; p++){
                    for(int q = 0; q < m; q++){
                        if(!((i >> p) & 1) && !((j >> q) & 1) && mat[p][q] == '#') cnt++;
                    }
                }
                if(cnt == k) ans++;
            }
        }
        cout << ans << endl;
    }
}


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

#define REP(i, x) REPI(i, 0, x)
#define REPI(i, a, b) for (int i = int(a); i < int(b); ++i)
#define ALL(x) (x).begin(), (x).end()

typedef long long ll;
using namespace std;

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

  int N, L;
  cin >> N >> L;
  string s;
  vector<string> S;
  REP(i, N) {
    cin >> s;
    S.push_back(s);
  }

  sort(S.begin(), S.end());
  REP(i, N) { cout << S.at(i); }
  cout << endl;

  return 0;
}


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

string a,b="CF"; 
int al,bl;

int main(){
    getline(cin,a);
    al=a.length();
    for(int i=0;i<al;i++)
        if(a[i]==b[bl]){ 
            bl++;
            if(bl==2) 
                break;
        }
    if(bl==2) cout<<"Yes"; 
    else cout<<"No";
    cout<<endl;
    return 0;
}

Measured memory_bytes: 256
#include<cstdio>
#include<cstring>
#include<cctype>
#include<cmath>
#include<climits>
#include<algorithm>
#include<vector>
#include<valarray>
#include<string>
#include<set>
#include<map>
#include<stack>
#include<queue>
#include<iostream>
#include<iomanip>
using namespace std;


#define rep(i,n) for(int i=0;i<n;i++)
#define REP(i,n) for(int i=1;i<=n;i++)
#define drep(i,n) for(int i=n-1;i>=0;i--)
#define DREP(i,n) for(int i=n;i>0;i--)
#define Rep(i,m,n) for(int i=m;i<n;i++)
#define ReP(i,m,n) for(int i=m;i<=n;i++)
#define scani(a) scanf("%d",&a)
#define scand(a) scanf("%lf",&a)
#define scans(s) scanf("%s",s)
#define readi(a) int a;scanf("%d",&a)
#define printi(a) printf("%d",a)
#define prints(s) printf("%s",s)
#define even(n) (((n)+1)%2)
#define odd(n) ((n)%2)
#define sg(x) ((x)?1:0)
#define LF printf("\n")
#define SPACE printf(" ")
#define pb push_back
#define mp make_pair
#define bs binary_search
#define all(a) (a).begin(),(a).end()
#define forall(itr,a) for(auto itr=(a).begin();itr!=(a).end();++itr)

typedef long long LL;
typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef pair<double,double> pdd;
typedef pair<int,int> pii;

const double pi = acos(-1.0);
double rad(double t){return t*pi/180.0;}
double deg(double d){return d*180.0/pi;}
template<typename T>T GCD(T x,T y){return y?GCD(y,x%y):x;}
template<typename T>T LCM(T x,T y){return x/GCD(x,y)*y;}
template<class T>ostream& operator<<(ostream& os,const set<T>& s){os<<"{";for(auto itr=s.begin();s.end() != itr;++itr){if(itr!=s.begin())os<<',';os<<*itr;}os<<"}";return os;}
template<class S,class T>ostream& operator<<(ostream& os,const pair<S,T>& p){os<<'('<<p.first<<','<<p.second<<')';return os;}
const int MOD = (int)pow(10,9) +7;


//begin global variable
//


//
//end   global variable

int main(){
  ios::sync_with_stdio(false);
  //begin main()
  //
  set<int> s;
  int a,b,c;
  cin >> a >> b >> c;
  s.insert(a);
  s.insert(b);
  s.insert(c);

  cout << s.size() << endl;
  //
  //end   main()
  return 0;
}


Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
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; }
 
/* attention
    long longのシフト演算には気をつけよう
    タイポした時のデバッグが死ぬほどきつくなるので変数名は最低3字くらい使った方がいいかも
    sizeは(int)とキャストしよう
    ごちゃごちゃ場合分けを考える前に全探索は考えましたか？
*/

int main(){
    int N, M; cin >> N >> M;
    vector<string> a(N), b(M);
    for(int i=0; i<N; ++i) cin >> a[i];
    for(int i=0; i<M; ++i) cin >> b[i];

    bool flg = false;
    for(int i=0; i<N+1-M; ++i){
        for(int j=0; j<N+1-M; ++j){
            bool ok = true;
            for(int k=0; k<M; ++k){
                for(int l=0; l<M; ++l){
                    if(a[i+k][j+l] != b[k][l]) ok = false;
                }
            }
            if(ok) flg = true;
        }
    }

    if(flg) cout << "Yes" << endl;
    else cout << "No" << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define fi first
#define se second
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
#define srep(i,s,t) for (int i = s; i < t; ++i)
#define rng(a) a.begin(),a.end()
#define rrng(a) a.rbegin(),a.rend()
#define isin(x,l,r) ((l) <= (x) && (x) < (r))
#define pb push_back
#define eb emplace_back
#define sz(x) (int)(x).size()
#define pcnt __builtin_popcountll
#define uni(x) x.erase(unique(rng(x)),x.end())
#define snuke srand((unsigned)clock()+(unsigned)time(NULL));
#define show(x) cerr<<#x<<" = "<<x<<endl;
#define PQ(T) priority_queue<T,v(T),greater<T> >
#define bn(x) ((1<<x)-1)
#define dup(x,y) (((x)+(y)-1)/(y))
#define newline puts("")
#define v(T) vector<T>
#define vv(T) v(v(T))
using namespace std;
typedef long long int ll;
typedef unsigned uint;
typedef unsigned long long ull;
typedef pair<int,int> P;
typedef tuple<int,int,int> T;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<P> vp;
typedef vector<T> vt;
int getInt(){int x;scanf("%d",&x);return x;}
template<typename T>istream& operator>>(istream&i,v(T)&v){rep(j,sz(v))i>>v[j];return i;}
template<typename T>string join(const v(T)&v){stringstream s;rep(i,sz(v))s<<' '<<v[i];return s.str().substr(1);}
template<typename T>ostream& operator<<(ostream&o,const v(T)&v){if(sz(v))o<<join(v);return o;}
template<typename T1,typename T2>istream& operator>>(istream&i,pair<T1,T2>&v){return i>>v.fi>>v.se;}
template<typename T1,typename T2>ostream& operator<<(ostream&o,const pair<T1,T2>&v){return o<<v.fi<<","<<v.se;}
template<typename T>bool mins(T& x,const T&y){if(x>y){x=y;return true;}else return false;}
template<typename T>bool maxs(T& x,const T&y){if(x<y){x=y;return true;}else return false;}
template<typename T>ll suma(const v(T)&a){ll res(0);for(auto&&x:a)res+=x;return res;}
const double eps = 1e-10;
const ll LINF = 1001002003004005006ll;
const int INF = 1001001001;
#define dame { puts("-1"); return 0;}
#define yn {puts("Yes");}else{puts("No");}
const int MX = 200005;



int main() {
  ll n;
  cin>>n;
  int x,m;
  scanf("%d%d",&x,&m);
  map<int,int> mp;
  vi a;
  int cnt = 0;
  ll tot = 0;
  while (mp.count(x) == 0) {
    a.pb(x);
    tot += x;
    mp[x] = cnt;
    ++cnt;
    x = (ll)x*x%m;
  }
  if (n <= cnt) {
    ll ans = 0;
    rep(i,n) ans += a[i];
    cout<<ans<<endl;
    return 0;
  }
  ll c = 0;
  int s = cnt-mp[x];
  srep(i,mp[x],cnt) c += a[i];
  ll ans = tot;
  n -= cnt;
  ans += n/s*c;
  n %= s;
  int si = mp[x];
  rep(i,n) ans += a[si+i];
  cout<<ans<<endl;
  return 0;
}






















Measured memory_bytes: 6008
#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);
#define replace_all(s, b, a) replace(s.begin(),s.end(), b, a);
// #define int long long
#define PI (acos(-1))
#define FILL(v, n, x) fill(v, v + n, x);
#define sz(x) int(x.size())

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 ul = unsigned long;

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 GCD(int a, int b) { return b ? GCD(b, a%b) : a; }
int LCM(int a, int b) { return a * b / GCD(a, b); }

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

inline bool inside(int y, int x, int H, int W) {
    return (y >= 0 && x >= 0 && y < H && x < W);
}

const int INF = 1e9;
const int MOD = 1e9+7;
const ll LINF = 1e18;

ll dp[305][305];

signed main()
{
  int n,k; cin>>n>>k;
  int m=n-k;
  vi h(n);
  rep(i,n) cin>>h[i];
  h.insert(h.begin(),0);
  rep(i,n+1) rep(j,m+1) dp[i][j]=LINF;
  dp[0][0]=0;
  for(int i=1; i<=n; i++) rep(j,m){
    ll now=LINF;
    rep(k,i){
      chmin(now,dp[k][j]+max(0,h[i]-h[k]));
    }
    dp[i][j+1]=now;
  }
  ll ans=LINF;
  rep(i,n+1) chmin(ans, dp[i][m]);
  cout<<ans<<endl;
}


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

string s;
int k;
map<char, int> m;
vector<char> v;
map<string, int> ans;

int main(){
    cin >> s >> k;
    for (int i = 0; i < s.size(); i++) m[s[i]]++;
    map<char, int>::iterator it;
    int sl = 0;
    for (it = m.begin(); it != m.end(); it++){
        if (it->second > 0) v.push_back(it->first);
        sl += it->second;
        if (sl >= k) break;
    }
    
    for (int i = 0; i < v.size(); i++){
        int vt = 0;
        while (m[v[i]] > 0){
            int dem = 0;
            int t = s.find(v[i],vt);
            m[v[i]]--;
            string ss = "";
            for (int j = t; j < s.size(); j++){
                ss += s[j];
                //cout << ss << endl;
                ans[ss]++;
                dem++;
                if (dem >= k) break;
            }
            vt = t + 1;
        }
        
    }
    int c = 0;
    map<string, int>::iterator it2;
    for (it2 = ans.begin(); it2 != ans.end(); it2++){
        c++;
        if (c == k){
            cout << it2->first ;
            break;
        }
    }
}

Measured memory_bytes: 384