akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <vector>
#include <deque>
#include <algorithm>
#include <numeric>
#include <string>
#include <cstring>
#include <list>
#include <unordered_set>
#include <tuple>
#include <cmath>
#include <limits>
#include <type_traits>
#include <iomanip>
#include <map>
#include <unordered_map>
#include <queue>
#include <stack>
#include <set>
#include <bitset>
#include <regex>
#include <random>
#include<bits/stdc++.h>

using namespace std;

typedef long long ll;
#define rep(i,n)for(ll i=0;i<n;++i)
#define exout(x) printf("%.10f\n", x)
const double pi = acos(-1.0);
const ll MOD = 1000000007;
const ll INF = 1e18;
const ll MAX_N = 201010;

//組み合わせの余りを求める
ll fac[MAX_N], finv[MAX_N], inv[MAX_N];
void COMinit() {
	fac[0] = fac[1] = 1;
	finv[0] = finv[1] = 1;
	inv[1] = 1;
	for (int i = 2; i < MAX_N; i++) {
		fac[i] = fac[i - 1] * i % MOD;
		inv[i] = MOD - inv[MOD % i] * (MOD / i) % MOD;
		finv[i] = finv[i - 1] * inv[i] % MOD;
	}
}

// 二項係数計算
long long COM(ll n, ll k) {
	if (n < k) return 0;
	if (n < 0 || k < 0) return 0;
	return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

//最大公約数
ll gcd(ll x, ll y) {
	return y ? gcd(y, x % y) : x;
}

ll lcm(ll x, ll y) {
	if (x == 0 || y == 0)return 0;
	return (x / gcd(x, y) * y);
}

ll dx[4] = { 0,0,-1,1 };
ll dy[4] = { -1,1,0,0 };
char notes[110][10];
ll treasure[3030][3030];
ll dp[3030][3030][4];

//long longしか使わない
//素数は1より大きい
//lower_boundは指定したkey以上の要素の一番左のイテレータをかえす
//upper_boundは指定したkeyより大きい要素の一番左のイテレータをかえす
int main() {
	ll n;
	cin >> n;
	map<ll, ll>mp;
	for (ll i = 1;i <= sqrt(n) + 1;++i) {
		if (n % i == 0) {
			mp[i]++;
			mp[n / i]++;
		}
	}
	ll ans = 0;
	for (auto p: mp) {
		ll x = p.first - 1;
		if (x == 0)continue;
		if (n / x == n % x) {
			ans += x;
		}
	}
	cout << ans << endl;
	return 0;
}


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

#define MAX 100000
#define REP(i,n) for (int i = 0; i < n; i++)

main() {
  int min, min_n, N, A[MAX] = {0}, B[MAX] = {0};
  int ans, even_n;

  cin >> N;
  REP(i, N) cin >> A[i];
  sort(A, A + N);

  min_n = -1;
  min = -1;
  REP(i, N) {
    if (min == A[i]) {
      B[min_n]++;
    } else {
      min = A[i];
      B[++min_n] = 1;
    }
  }
  even_n = 0;
  REP(i, min_n + 1) {
    if (B[i] % 2) {
      B[i] = 1;
    } else {
      B[i] = 2;
      even_n++;
    }
  }
  ans = min_n + 1;
  if (even_n % 2) ans--;

  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 1024
#include <iostream>
#include <algorithm>
#include <cstdio>
#include <cstdlib>
#include <cctype>
#include <cmath>
#include <climits>
#include <cstring>
#include <string>
#include <map>
#include <set>
#include <vector>
#include <queue>


using namespace std;
#define INF 0x3f3f3f3f3f
#define ll long long
#define pr(x) (cerr << #x << ' ' << x << ' ')
#define prln(x) (cerr << #x << ' ' << x << endl)
const int maxn = 55;
int a[maxn];
int cnt;

bool dfs(int sum) {
    if (sum == 0) return true;
    else if (sum < 0) return false;
    else {
        return dfs(sum - 4) || dfs(sum - 7);
    }
}



int main()
{
    #ifdef LOCAL
        freopen("in.txt", "r", stdin);
    #endif // LOCAL
    int n;
    scanf("%d", &n);
    if (dfs(n)) {
        puts("Yes");
    }else {
        puts("No");
    }
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <vector>
#include <list>
#include <algorithm>
#include <cmath>
#include <stack>
#include <map>
#include <numeric>
#include <sstream>
#include <queue>
using namespace std;

#define REP(i,n) for(int (i)=0; (i)<(n); (i)++)
#define FOR(i,a,b) for(int (i)=(a); (i)<(b); (i)++)
#define PUSH(n,v) for(int i=0; i<(n); i++) {int j; cin >> j; v.push_back(j);}
#define ALL(v) v.begin(), v.end()
#define print(s) cout << (s) << endl

void solve73(int x, int h) {
    double hypo = sqrt(h*h + x*x/4.0);
    printf("%.6f\n", hypo*x*2 + x*x);
}

int main() {
    int x,h;
    while(cin >> x >> h, x + h) {
        solve73(x,h);
    }
    return 0;
}

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

using namespace std;
using ll = long long;

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

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

  if (a <= 9 && b <= 9)
    cout << a * b << endl;
  else
    cout << -1 << endl;
  return 0;
}


Measured memory_bytes: 256
public class Main {
	public static void main(String[] args) {
		var sc = new java.util.Scanner(System.in);
		var x = sc.nextInt();
		var n = sc.nextInt();
		var p = new int[n];
		for (int i = 0; i < n; i++) {
			p[i] = sc.nextInt();
		}
		var used = new boolean[102];
		for (int i = 0; i < used.length; i++) {
			used[i] = false;
		}
		for (int i = 0; i < p.length; i++) {
			used[p[i]] = true;
		}
		var minabs = 1000;
		var minid = x;
		for (int i = 0; i < used.length; i++) {
			if (!used[i]) {
				var abs = Math.abs(x - i);
				if (abs < minabs) {
					minid = i;
					minabs = abs;
				}
			}
		}
		System.out.println(minid);

	}
}


Measured memory_bytes: 35852
#include <iostream>
#include <vector>
#include <list>
#include <set>
#include <queue>
#include <map>
#include <algorithm>
#include <functional>
#include <string>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <tuple>
using namespace std;

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

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

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

    if (N == 1)
    {
        cout << 1 << endl;

        return 0;
    }

    vector<pll> ps(N);
    for (auto& p : ps) { cin >> p.first >> p.second; }

    ll ans = 1000;

    for (ll i=0;i<N;++i)
    for (ll j=i+1;j<N;++j)
    {
        const auto& pi = ps[i];
        const auto& pj = ps[j];

        const auto dx = pi.first  - pj.first;
        const auto dy = pi.second - pj.second;

        ll n1 = 0, n2 = 0;

        for (ll s=0;s<N;++s)
        for (ll t=0;t<N;++t)
        {
            const auto& p1 = ps[s];
            const auto& p2 = ps[t];

            const auto x1 = p1.first  - p2.first;
            const auto y1 = p1.second - p2.second;

            const auto x2 = -(p1.first  - p2.first);
            const auto y2 = -(p1.second - p2.second);

            if (x1 == dx && y1 == dy) { ++n1; }
            if (x2 == dx && y2 == dy) { ++n2; }
        }

        ans = min(ans, N - n1);
        ans = min(ans, N - n2);
    }

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 256
N = int(input())
a = [0] + list(map(int, input().split()))

if 1 not in a:
    ans = -1
    print(ans)
else:
    broken = []
    survived = []
    latest = 1
    for i in range(1,N+1):
        if a[i] != latest:
            broken.append(a[i])
        else:
            latest += 1
            survived.append(a[i])
    print(len(broken))
    


Measured memory_bytes: 86864
// Math = ♥️

#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;

#define ll long long
#define ld long double
typedef pair<ll, ll> ii;
typedef vector<ll> vi;
typedef vector<vi> vvi;
typedef vector<ii> vii;
typedef vector<vii> vvii;
#define pq priority_queue
#define ff first
#define ss second
#define pb push_back
#define mp make_pair
#define all(c) (c).begin(), (c).end()
#define ordered_set                            \
    tree<ll, null_type, less<ll>, rb_tree_tag, \
         tree_order_statistics_node_update>

int main(void) {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);

    ll n, k;
    cin >> n >> k;

    n %= k;

    cout << min(n, llabs(n - k)) << "\n";
}


Measured memory_bytes: 256
# code-festival-2017-qualaC - Palindromic Matrix
from collections import Counter


def main():
    H, W, *A = open(0).read().split()
    H, W, C = int(H), int(W), Counter("".join(A)).values()
    single = H & W & 1
    double = (H >> 1 if W & 1 else 0) + (W >> 1 if H & 1 else 0)
    C_mod4, C_div4 = zip(*[(i % 4, i // 4) for i in C])
    flg = C_mod4.count(1) + C_mod4.count(3) <= single and C_mod4.count(2) <= double
    print("Yes" if flg else "No")


if __name__ == "__main__":
    main()

Measured memory_bytes: 3700
#include<iostream>
using namespace std;
int main(){
	int a,b,c,d;
	cin>>a>>b>>c>>d;
	int A1=a*b;
	int A2=c*d;
	if(A1>A2)
	cout<<A1;
	else if(A2>A1)
	cout<<A2;
	else
	cout<<A1;
	return 0;
}

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

struct Node {
	int key;
	Node *right, *left, *parent;
};

Node *root, *NIL;

void insert(int k) {
	Node *y = NIL;
	Node *x = root;
	Node *z;
	
	z = (Node *)malloc(sizeof(Node));
	z->key   = k;
	z->left  = NIL;
	z->right = NIL;
	
	while(x != NIL) {
		y = x;
		if(z->key < x->key) {
			x = x->left;
		} else {
			x = x->right;
		}
	}
	
	z->parent = y;
	if(y == NIL) {
		root = z;
	} else {
		if( z->key < y->key) {
			y->left = z;
		} else {
			y->right = z;
		}
	}
}

void inorder(Node *u) {
	if(u == NIL) return;
	inorder(u->left);
	printf(" %d",u->key);
	inorder(u->right);
}
void preorder(Node *u) {
	if(u == NIL) return;
	printf(" %d",u->key);
	preorder(u->left);
	preorder(u->right);
}
	
int main(void) {
	int n, i, x;
	string com;
	scanf("%d",&n);
	
	for(i=0;i<n;i++) {
		cin >> com;
		if(com == "insert") {
			scanf("%d",&x);
			insert(x);
		} else if(com == "print") {
			inorder(root);
			printf("\n");
			preorder(root);
			printf("\n");
		}
	}

	return 0;
}


Measured memory_bytes: 26632
/*
x1, y1, x2, y2 （実数）が空白区切りで与えられます。
*/

#include <stdio.h>
#include <stdlib.h>
#include <math.h>

int main(void) {
    double x1, x2, y1, y2;
    
    fscanf(stdin, "%lf %lf %lf %lf", &x1, &x2, &y1, &y2);
    
    printf("%.10f\n", sqrt((y1 - x1) * (y1 - x1) + (y2 - x2) * (y2 - x2)));
    
    return 0;
}


Measured memory_bytes: 2104
#include <bits/stdc++.h>
using namespace std;
long long euclid( long long a, long long b )
{
    long long temp;

    if( a < b ) { temp = a; a = b; b = temp; }
    if( b < 1 ) return -1;

    if( a % b == 0 ) return b;
    return euclid( b, a % b );
}


int main(){
	long long A,B,C,D;
	cin >>A>>B>>C>>D;
	long long N=B-A+1;
    long long p=C*D/euclid(C,D);
	long long ac;
	long long ad;
	long long acd;
	if(A%C==0){ac=A;}
	else{ac=A+(C-A%C);}

	if(A%D==0){ad=A;}
	else{ad=A+(D-A%D);}

	if(A%p==0){acd=A;}
	else{acd=A+(p-A%p);}
  
	long long bc=B-B%C;
	long long bd=B-B%D;
	long long bcd=B-B%p;
	long long x=bc/C-ac/C+1;
	long long y=bd/D-ad/D+1;
	long long z=bcd/p-acd/p+1;
	long long ans=N-(x+y-z);
	if(A==B){
		if(A%C!=0&&A%D!=0){ans=1;}
		else{ans=0;}
	}
	if(C==D){ans=N-x;}
  
cout <<ans<<endl;
 // cout <<ac<<" "<<ad<<" "<<acd<<" "<<bc<<" "<<bd<<" "<<bcd<<endl;
}


Measured memory_bytes: 256
/*
  AtCoder Beginner Contest 091
  B - Two Colors Card Game 
*/

#include<iostream>
#include<string>
#include<map>
using namespace std;

int N, M;
map<string,int> st;

int main() {
  string buffer;

  scanf("%d", &N);
  for (int i = 0; i < N; ++i) {
    cin >> buffer;
    if (st.find(buffer) == st.end()) st[buffer] = 1;
    else st[buffer] += 1;
  }

  scanf("%d", &M);
  for (int i = 0; i < M; ++i) {
    cin >> buffer;
    if (st.find(buffer) == st.end()) st[buffer] = -1;
    else st[buffer] -= 1;
  }

  int maxval = 0;
  for (auto itr = st.begin(); itr != st.end(); ++itr) {
    if (itr->second > maxval) maxval = itr->second;
  }

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

Measured memory_bytes: 256
n = gets.chomp.to_i
$coins = [1]
INF = 1 << 40

def make_multiplier(x, n)
    tmp = x
    while tmp <= n
        $coins << tmp
        tmp = tmp * x
    end
end

make_multiplier(6, n)
make_multiplier(9, n)
$coins.sort!

dp = Array.new(n+1, INF)
dp[0] = 0
m = $coins.size

m.times do |i|
    j = 0
    while j + $coins[i] <= n
        dp[j + $coins[i]] = [dp[j + $coins[i]], dp[j] + 1].min
        j += 1
    end
end

puts dp[n]

Measured memory_bytes: 2556
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef vector<vector<pair<int, int> > > vvp;
typedef vector<pair<int, int> > vp;
typedef vector<vector<int> > vvi;
typedef vector<int> vi;
typedef vector<vector<ll> > vvl;
typedef vector<ll> vl;
typedef vector<vector<bool> > vvb;
typedef vector<bool> vb;
typedef vector<string> vs;
typedef pair<string, int> psi;
typedef pair<int, int> pii;
#define rep(i,s,n) for(int i = (s); i < (n); i++)
#define all(x) (x).begin(), (x).end()
#define yn(f) (f?"yes":"no")
#define YN(f) (f?"YES":"NO")
#define Yn(f) (f?"Yes":"No")
#define puts(s) cout<<(s)<<endl
#define inf (1000000007)
#define nil -1
class disjoint_set {
public:
	vi p, rank;
	disjoint_set(int size) {
		p.resize(size, 0);
		rank.resize(size, 0);
		for (int i = 0; i < size; i++)makeSet(i);
	}
	void makeSet(int x) {
		p[x] = x;
		rank[x] = 0;
	}
	bool same(int x, int y) {
		return findSet(x) == findSet(y);
	}
	void unite(int x, int y) {
		link(findSet(x), findSet(y));
	}
	void link(int x, int y) {
		if (rank[x] < rank[y]) {
			p[x] = y;
		}
		else {
			p[y] = x;
			if (rank[x] == rank[y]) {
				rank[x]++;
			}
		}
	}
	int findSet(int x) {
		if (x != p[x]) {
			p[x] = findSet(p[x]);
		}
		return p[x];
	}
};

struct node {
	int p = -1;
	int count = 0;
	int num = 0;
	vi c;
};
void o(int u,int num,vector<node>& A) {
	num += A[u].num;
	A[u].count += num;
	rep(i, 0, A[u].c.size()) {
		o(A[u].c[i],num,A);
	}
}
int main() {
	int n,q; cin >> n>>q;
	vector<node> A(n+1);
	rep(i, 0, n-1) {
		int a, b;
		cin >> a >> b;
		A[min(a, b)].c.push_back(max(a, b));
		A[max(a, b)].p = min(a, b);
	}
	rep(i, 0, q) {
		int p, x;
		cin >> p >> x;
		A[p].num += x;
	}
	o(1,0,A);
	rep(i, 1, n + 1) {
		if (i >1) {
			cout << " ";
		}
		cout << A[i].count;
	}
	cout << endl;
}


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

int main(){
 int i=0;
 int num[100];
 char stack[100];

 while( scanf("%s", stack) != EOF ){
  if ( stack[0] == '+' ){
   num[i-2]=num[i-2]+num[i-1];
   i--;
   } else if ( stack[0] == '-' ){
    num[i-2]=num[i-2]-num[i-1];
   i--;
  } else if ( stack[0] == '*' ){
   num[i-2]=num[i-2]*num[i-1];
   i--;
  } else {
   num[i] = atoi(stack);
   i++;
  }

 }
 printf("%d\n",num[0]);

 return 0;
}

Measured memory_bytes: 548
#include <bits/stdc++.h>
using namespace std;
#define ALL(obj) obj.begin(),obj.end()
#define pb(obj) push_back(obj)
#define REP(i,N) for(ll i=0;i<N;i++)
typedef long long ll;

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N;
    cin>>N;
    vector<int>D(N);
    int d;
    for(int i=0;i<N;i++){
        cin>>d;
        D[i]=d;
    }
    if(D[0]!=0){cout<<0<<endl;exit(0);}
    sort(ALL(D));
    int now=0;
    vector<int>num;
    num.pb(1);
    for(int i=1;i<N;i++){
        if(D[i]==now)num[now]++;
        else if(D[i]==now+1){
            num.pb(1);
            now++;
        }
        else{cout<<0<<endl;exit(0);}
    }
    if(num[0]!=1){cout<<0<<endl;exit(0);}

    ll sub=1;
    const ll MOD=998244353;
    ll c;
    for(int i=1;i<num.size();i++){
        c=1;
        for(int j=0;j<num[i];j++){
            c*=num[i-1];
            c%=MOD;
        }
        c%=MOD;
        sub*=c;
        sub%=MOD;
    }
    cout<<sub<<endl;
}

Measured memory_bytes: 1276
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <string>

using namespace std;

bool comp(const vector<int> &a, const vector<int> &b){
    return (a[1] < b[1]);
}

int main() {
    int N, M, p, y;
    cin >> N >> M;
    vector<vector<vector<int>>> cities;
    for (int i=0; i<N; i++){
        cities.push_back(vector<vector<int>>());
    }
    for (int i=0; i<M; i++){
        cin >> p >> y;
        cities[p - 1].push_back(vector<int>{i, y});
    }
    for (int i=0; i<N; i++){
        sort(cities[i].begin(), cities[i].end(), comp);
    }
    string id[M];
    string name_b, name_f;
    for (int i=0; i<M; i++) id[i] = "unknown";
    for (int i=0; i<N; i++){
        for (int j=0; j<cities[i].size(); j++){
            name_b = string((unsigned long)(5 - floor((log10(j+1)))), '0');
            name_b += to_string(j+1);
            name_f = string((unsigned long)(5 - floor((log10(i+1)))), '0');
            name_f += to_string(i+1);
            id[cities[i][j][0]] = name_f + name_b;
        }
    }

    for (int i=0; i<M; i++){
        cout << id[i] << endl;
    }



    return 0;

}

Measured memory_bytes: 16368
import java.util.Scanner;

public class Main {
    public static void main(String [] args) {
        Scanner scanner = new Scanner(System.in);
        int n = scanner.nextInt();
        int k = scanner.nextInt();
        String s = scanner.next();
        for (int i = 0; i < n; ++i) {
            if (i == k - 1) {
                System.out.print((char)(s.charAt(i) - 'A' + 'a'));
            } else {
                System.out.print(s.charAt(i));
            }
        }
        System.out.println();
    }
}


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

ans = 1
inc = False
dec = False
before = A[0]
for a in A:
    if not inc and not dec:
        if a > before:
            inc = True
        if a < before:
            dec = True
    elif inc:
        if a < before:
            ans += 1
            inc = False
    elif dec:
        if a > before:
            ans += 1
            dec = False
    before = a
print(ans)

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

#define mp make_pair
#define eb emplace_back
#define ff first
#define ss second

using namespace std;

typedef long long ll;
typedef unsigned long long ull;

#ifdef ONPC
mt19937 rnd(228);
#else
mt19937 rnd(chrono::steady_clock::now().time_since_epoch().count());
#endif


const int MAXN = 100;
//#define int long long
const int INF = 1e9;

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

	int a, b, c, d;
	cin >> a >> b >> c >> d;

	int dp[c + 1][d + 1];
	memset(dp, 0, sizeof dp);
	//a+b
	auto add = [](int a, int b){
		return (a + b) % 998244353;
	};
	//a*b
	auto mult = [](int a, int b){
		return ((ll)a * (ll)b) % 998244353LL;
	};
	//a-b
	auto sub = [](int a, int b){
		return ((a - b) % 998244353 + 998244353) % 998244353;
	};

	dp[a][b] = 1;
	for (int i = a; i <= c; i++){
		for (int j = b; j <= d; j++){
			//dp[i][j][0] = add(add(dp[i-1][j][0], dp[i-1][j][1]), j);
			//dp[i][j][1] = add(add(dp[i][j-1][0], dp[i][j-1][1]), i);
		    if (i == a && j == b) continue;
			dp[i][j] = sub(add(mult(dp[i][j - 1], i), mult(dp[i - 1][j], j)), mult(mult(dp[i - 1][j - 1], i - 1), j - 1));
		}
	}

	cout << dp[c][d] << '\n';

    return 0;
}


Measured memory_bytes: 38712
local n = io.read("*n")
local hn = n // 2

local function get(x)
  local r = 0
  while 0 < x do
    r = r + x % 10
    x = x // 10
  end
  return r
end
local mmi = math.min
local ret = get(1) + get(n - 1)
for i = 2, hn do
  ret = mmi(ret, get(i) + get(n - i))
end
print(ret)


Measured memory_bytes: 256
#include <cstdio>

int main()
{
    int a;
    scanf("%d", &a);
    if (a < 1200)
    {
        printf("ABC");
    }
    
    else if (1200 <= a and a < 2800)
    {
        printf("ARC");
    }
    
    else if (a >= 2800)
    {
        printf("AGC");
    }
}

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

using VI = vector<int>;
using VVI = vector<VI>;
using PII = pair<int, int>;
using LL = long long;
using VL = vector<LL>;
using VVL = vector<VL>;
using PLL = pair<LL, LL>;
using VS = vector<string>;

#define ALL(a)  begin((a)),end((a))
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define EB emplace_back
#define MP make_pair
#define SZ(a) int((a).size())
#define SORT(c) sort(ALL((c)))
#define RSORT(c) sort(RALL((c)))
#define UNIQ(c) (c).erase(unique(ALL((c))), end((c)))

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

#define FF first
#define SS second
template<class S, class T>
istream& operator>>(istream& is, pair<S,T>& p){
  return is >> p.FF >> p.SS;
}
template<class S, class T>
ostream& operator<<(ostream& os, const pair<S,T>& p){
  return os << p.FF << " " << p.SS;
}
template<class T>
void maxi(T& x, T y){
  if(x < y) x = y;
}
template<class T>
void mini(T& x, T y){
  if(x > y) x = y;
}


const double EPS = 1e-10;
const double PI  = acos(-1.0);
const LL MOD = 1e9+7;

const int MX = 3500;
LL dp[110][MX];

LL powm(LL x, LL y){
  if(y == 0)
	return 1;
  return powm(x*x%MOD, y/2) * (y%2?x:1) % MOD;
}
LL inv(LL x){
  return powm(x, MOD-2);
}

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

  LL N, K;
  cin >> N >> K;

  dp[N+1][0] = 1;
  for(int i=N;i>=1;--i){
	for(int k=0;k<=K;++k){
	  if(i < k){
		for(int t=0;t<MX;++t){
		  (dp[i][t] += dp[i+1][t]) %= MOD;
		}
	  }
	  else{
		for(int t=0;t+(k+t)/i<MX;++t){
		  LL t_ = (k + t) / i;
		  (dp[i][t+t_] += dp[i+1][t]) %= MOD;
		}
	  }
	}
  }
  LL ans = K * powm(K+1, N) % MOD * inv(2) % MOD * N % MOD;
  REP(t,MX) (ans += MOD - dp[1][t] * t % MOD) %= MOD;
  
  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 2944
#include<iostream>

using namespace std;

int main(int argc, char const *argv[])
{
    int r,g,b;
    cin>>r>>g>>b;
    int ans=r*100+g*10+b;

    if(ans%4==0){
        cout<<"YES"<<endl;
    }else{
        cout<<"NO"<<endl;
    }
    
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
//#define int long long
#define M 1000000007
#define INF ((1LL<<62LL) - 1)

const int N = 1005;
int n,m,sx,sy,ex,ey;
int conn = 0;
int total;

char a[N][N];
bool vis[N][N];
int number[N][N];

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

void dfs(int x, int y){
    vis[x][y] = true;
    number[x][y] = conn;

    for(int i=0;i<4;i++){
        int nx = x + dx[i];
        int ny = y + dy[i];
        if(!vis[nx][ny] && nx>=1 && nx<=n && ny>=1 && ny<=m && a[nx][ny] == '.'){
            dfs(nx, ny);
        }
    }
}

signed main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);

    cin >> n >> m >> sx >> sy >> ex >> ey;

    for(int i=1;i<=n;i++){
        for(int j=1;j<=m;j++){
            cin >> a[i][j];
        }
    }

    for(int i=1;i<=n;i++){
        for(int j=1;j<=m;j++){
            if(!vis[i][j] && a[i][j] == '.'){
                conn++;
                dfs(i, j);
            }
        }
    }

    total = conn;

    set<int> g[total + 1];

    if(number[sx][sy] == number[ex][ey]){
        cout << "0\n";
        return 0;
    } else {
        for(int i=1;i<=n;i++){
            for(int j=1;j<=m;j++){
                if(a[i][j] == '.') {
                    for (int ii = -2; ii <= 2; ii++) {
                        for (int jj = -2; jj <= 2; jj++) {
                            int nx = i + ii;
                            int ny = j + jj;
                            if (nx >= 1 && nx <= n && ny >= 1 && ny <= m && a[nx][ny] == '.' && number[nx][ny] != number[i][j]) {
                                g[number[i][j]].insert(number[nx][ny]);
                                g[number[nx][ny]].insert(number[i][j]);
                            }
                        }
                    }
                }
            }
        }
    }

    int start = number[sx][sy];
    int end = number[ex][ey];

    queue<pair<int,int> > q;
    vector<bool> visi(total + 1, false);

    q.push({start, 0});
    visi[start] = true;

    while(!q.empty()){
        pair<int,int> p = q.front();
        q.pop();

        for(int x : g[p.first]){
            if(!visi[x]){
                if(x == end){
                    cout << p.second + 1 << "\n";
                    return 0;
                }
                q.push({x, p.second + 1});
                visi[x] = true;
            }
        }
    }


    cout << "-1\n";

}


Measured memory_bytes: 33760
/******************************************************************************

                              Online C++ Compiler.
               Code, Compile, Run and Debug C++ program online.
Write your code in this editor and press "Run" button to compile and execute it.

*******************************************************************************/

#include <iostream>
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define pb push_back
#define mod 1000000007
int dp[100001];

int path_length(int node,vector<vector<int>> &graph)
{
    int temp=0;
    for(auto child:graph[node])
    {
        temp=max(temp,(1+(dp[child]!=-1?dp[child]:path_length(child,graph))));
    }
    return dp[node]=temp;
}

int solve(vector<vector<int>> &graph,int n)
{
    memset(dp,-1,sizeof(dp));
    for(int i=1;i<=n;i++)
    {
        if(dp[i]==-1)
           path_length(i,graph); // this will return the length of the longest path starting from 
           // node i......if uska koi child nhi hai tu in taht case length will be zero..
    }
    int ans=0;
    for(int i=1;i<=n;i++)
    {
        ans=max(ans,dp[i]);
    }
    return ans;
}

int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    
    int n,m;
    cin>>n>>m;
    vector<vector<int>> graph(n+1);
    for(int i=0;i<m;i++)
    {
        int a,b;
        cin>>a>>b;
        graph[a].pb(b);  // directed graph hai...
    }
    cout<<solve(graph,n);
    

    return 0;
}







Measured memory_bytes: 11812
from collections import deque


def main():
    k = int(input())
    if k <= 9:
        print(k)
    else:
        queue = deque()
        for i in range(1, 10):
            queue.append(i)
        flag = 1
        cnt_lunlun = 9
        while flag:
            first_element = queue.popleft()
            lunlun_nums = extend_lunlun(first_element)
            for n in lunlun_nums:
                queue.append(n)
                cnt_lunlun += 1
                if cnt_lunlun == k:
                    flag -= 1
                    break
        print(queue.pop())


def extend_lunlun(num):
    last_digit = int(str(num)[-1])
    if last_digit == 0:
        return int(str(num)+"0"), int(str(num)+"1")
    elif last_digit == 9:
        return int(str(num) + "8"), int(str(num) + "9")
    else:
        return (
            int(str(num) + str(last_digit - 1)),
            int(str(num) + str(last_digit)),
            int(str(num) + str(last_digit + 1))
        )


if __name__ == "__main__":
    main()

Measured memory_bytes: 5952
#include <bits/stdc++.h>
using namespace std;
int main(){
	string s,t;
	cin>>s>>t;
	int n=s.size();
	char c;
	for(int i=0;i<=n;i++){
		c=s[n-1];
		for(int j=n-1;j>0;j--){
			s[j]=s[j-1];
		}
		s[0]=c;
		if(s==t){
			cout<<"Yes"<<endl;
			return 0;
		}
	}
	cout<<"No"<<endl;
	return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
 
#pragma comment(linker, "/stack:200000000")
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
 
#define start_routine() int begtime = clock();
#define end_routine() int endtime = clock(); cerr << endl << "Time elapsed: " << (endtime - begtime)*1000/CLOCKS_PER_SEC << " ms"; return 0
#define speed() cin.tie(0), cout.tie(0), ios_base::sync_with_stdio(false)
// #define exit(a, b) return cout << a, b;
 
// debugger
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
    cout << name << " : " << arg1 << endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
    const char* comma = strchr(names + 1, ',');cout.write(names, comma - names) << " : " << arg1<<" | ";__f(comma+1, args...);
}
#define debug(stuff) cout << #stuff << ": " << stuff <<endl
#define debugc(stuff) cout << #stuff << ": "; for(auto x: stuff) cout << x << " "; cout << endl;
// 
 
#define loop(i,a,b) for(ll i=a;i<b;i++)
#define all(v) v.begin(), v.end() 
 
#define print(stuff) cout << stuff << endl
#define printc(stuff) for(auto x: stuff) cout << x << " "; cout << endl;
#define printPrec(stuff) cout << fixed << setprecision(15) << stuff << endl;
#define len length
#define ret0 return 0
#define ret return 
 
 
#define ll long long
#define ld long double
#define fi first
#define endl '\n'
#define se second
#define pb push_back
#define mp make_pair
#define lb lower_bound
#define ub upper_bound
#define fill(ar, x) memset(ar, x, sizeof ar)
 
#define vl vector<ll> 
#define sl set<ll>
#define pll pair<ll, ll>
#define mll map<ll, ll> 
#define pq priority_queue<ll>
 
// typedef tree<ll,null_type,less<ll>,rb_tree_tag,
// tree_order_statistics_node_update> indexed_set;
 
#define inf (long long int) 1e18
#define eps 0.000001
#define mod 1000000007
#define mod1 998244353
#define MAXN (ll)2e5+5
#define N (1ll<<10)


ll palindrome(string s){
    ll l = 0;
    ll h = s.length() - 1;
    while (h > l){
        if (s[l++] != s[h--]){
            return 0;
        }
    }
    return 1;
}

void solve(){
    string s;
    cin>>s;
    ll n = s.length();
    string t(s, 0, n/2);
    string z(s, n/2+1, n/2);
    if(palindrome(s) && palindrome(t) && palindrome(z)){
        print("Yes");
    }
    else print("No");
}
 
int main(){
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
  
 
    ll t = 1;
    // cin>>t;
    while(t--){
        solve();
    }
   
}


Measured memory_bytes: 256
def main():
    import sys
    input = sys.stdin.readline
    sys.setrecursionlimit(10000000)
    from collections import Counter, deque
    #from collections import defaultdict
    from itertools import combinations, permutations, accumulate
    #from itertools import product
    from bisect import bisect_left,bisect_right
    import heapq
    from math import floor, ceil
    #from operator import itemgetter

    #inf = 10**17
    #mod = 10**9 + 7

    N,K = map(int, input().split())
    a = list(map(int, input().split()))
    dp = [0]*(K+1)
    for i in range(1, K+1):
        for j in a:
            if i-j < 0:
                continue
            if dp[i-j] == 0:
                dp[i] = 1
                break
    if dp[K]:
        print('First')
    else:
        print('Second')

if __name__ == '__main__':
    main()

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

int main(){
		int a,b,c;
		int ans=0;
		scanf("%d %d %d",&a,&b,&c);
		ans=a+b;
		ans=min(ans,a+c);
		ans=min(ans,b+c);
		printf("%d\n",ans);
		return 0;
}


Measured memory_bytes: 888
import math

K = int(input())

ans = 0
for i in range(1, K+1):
    for j in range(i, K+1):
        for k in range(j, K+1):
            if i==j and i==k: g = i
            elif (i==j and i!=k):
                g = math.gcd(i,math.gcd(j,k))*3
            elif (i==k and i!=j):
                g = math.gcd(i,math.gcd(j,k))*3
            elif (j==k and i!=j):
                g = math.gcd(i,math.gcd(j,k))*3
            else : g = math.gcd(i,math.gcd(j,k))*6
            ans += g
print(ans)


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

#define trace(...) __f( #__VA_ARGS__ , __VA_ARGS__ )
template <typename Arg1>
void __f( const char* name , Arg1&& arg1 ) {
        cerr << name << " : " << arg1 << "\n";
}
template <typename Arg1, typename... Args>
void __f( const char* na , Arg1&& arg1 , Args&&... args ) {
        const char* c = strchr( na + 1 , ',' );
        cerr.write( na , c - na ) << " : " << arg1 << " , ";
        __f( c + 1 , args... );
}
#define endl "\n"
#define all(V) V.begin(),V.end()
#define Unique(V) sort(all(V)),V.erase(unique(all(V)),V.end())
#define IO ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
typedef long long int LL;
typedef pair <int,int> pii;
const int MOD = 1e9 + 7;
const int inf = 1e9;
const double EPS = 1e-9;
const double PI = acos(-1.0);
const long long INF = 1e18;
const int N = 1e5 + 5;

string s;
int len;
LL dp[ N ][ 20 ];

LL solve( int idx , int rem ) {
        if( idx >= len ) return rem%13 == 5;
        if( dp[idx][rem] != -1 ) return dp[idx][rem];
        LL ret = 0;
        if( s[idx] != '?' ) {
                ret = ( ret%MOD + solve( idx + 1 , ( rem%13*10%13 + (s[idx]-'0')%13 )%13 )%MOD )%MOD;
        }
        else {
                for( int i = 0; i <= 9; i++ ) {
                      ret = ( ret%MOD + solve( idx + 1 , ( rem%13*10%13 + i%13 )%13 )%MOD )%MOD;
                }
        }
        return dp[idx][rem] = ret;
}
int main( ) {
        IO;
        #ifdef LOCAL
            //freopen( "input.txt" , "r" , stdin );
        #endif // LOCAL
        cin >> s;
        len = s.size();
        LL ans = 0;
        memset( dp , -1 , sizeof( dp ) );
        if( s[0] == '?' ) {
                for( int i = 0; i <= 9; i++ ) {
                      ans = ( ans%MOD + solve( 1 , i )%MOD )%MOD;
                }
        }
        else ans = ( ans%MOD + solve( 1 , s[0] - '0' )%MOD )%MOD;
        cout << ans%MOD << endl;
        return 0;
}









Measured memory_bytes: 23888
#include<bits/stdc++.h>
using namespace std;
int main(){
  int n,a,b,p=0,q=0;
  cin >> n >> a >> b;
  char s[n+1];
  for(int i=0;i<n;i++){
    cin >> s[i];
    if(s[i]=='a'){
      if(p<a+b){
        cout << "Yes" << endl;
        p++;
      }
      else cout << "No" << endl;
    }
    else if(s[i]=='b'){
      q++;
      if(p<a+b){
        if(q<=b){
          cout << "Yes" << endl;
          p++;
        }
        else cout << "No" << endl;
      }
      else cout << "No" << endl;
    }
    else cout << "No" << endl;
  }
}


Measured memory_bytes: 768
import numpy as np
N = int(input())
ABC = np.zeros([N, 3])
for i in range(N):
    ABC[i] = list(map(int, input().split()))

dp = np.zeros([N, 3])
dp[0] = ABC[0]
for i in range(N-1):
    dp[i+1, 0] = max(dp[i, 1], dp[i, 2]) + ABC[i+1, 0]
    dp[i+1, 1] = max(dp[i, 0], dp[i, 2]) + ABC[i+1, 1]
    dp[i+1, 2] = max(dp[i, 0], dp[i, 1]) + ABC[i+1, 2]

print(int(max(dp[N-1])))

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

int main()
{
    int n;
    vector<string> s;
    vector<int> p;
    vector<int> ranking;
    cin >> n;
    s.resize(n);
    p.resize(n);
    ranking.resize(n);
    for (int i = 0; i < n; i++)
    {
        cin >> s[i] >> p[i];
    }
    for (int i = 0; i < n; i++)
    {
        int rank = 0;
        for (int j = 0; j < n; j++)
        {
            if (i == j)
                continue;
            else if (s[i] == s[j])
            {
                if (p[i] < p[j])
                    rank++;
            }
            else if (s[i] > s[j])
                rank++;
            // cout << " " << s[i] << p[i] << s[j] << p[j] << " " << rank << endl;
        }
        ranking[rank] = i;
    }
    for (int i = 0; i < n; i++)
    {
        cout << ranking[i] + 1 << endl;
    }
    return 0;
}


Measured memory_bytes: 256
x1, y1, x2, y2 = list(map(int, input().split()))

route1 = ["R"] * (x2 - x1) + ["U"] * (y2 - y1)
route2 = ["L"] * (x2 - x1) + ["D"] * (y2 - y1)
route3 = ["D"] + ["R"] * (x2 - x1 + 1) + ["U"] * (y2 - y1 + 1) + ["L"]
route4 = ["U"] + ["L"] * (x2 - x1 + 1) + ["D"] * (y2 - y1 + 1) + ["R"]
route = route1 + route2 + route3 + route4
print("".join(route))

Measured memory_bytes: 3444
#include <memory.h>

#include <algorithm>
#include <bitset>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <deque>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <utility>
#include <vector>

using namespace std;

#define mod 1000000007

int main() {
	int n;
	cin >> n;
	vector<int> b(n);
	for (int i = 0; i < n; i++) {
		cin >> b[i];
		b[i]--;
	}
	vector<int> ans;
	while (!b.empty()) {
		for (int i = b.size() - 1; i >= 0; i--) {
			if (i == b[i]) {
				ans.push_back(b[i] + 1);
				b.erase(b.begin() + i);
				break;
			} else if (i == 0) {
				cout << -1 << endl;
				return 0;
			}
		}
	}
	for (int i = ans.size() - 1; i >= 0; i--) {
		cout << ans[i] << endl;
	}
}

Measured memory_bytes: 256
n = int(input())
h = list(map(int, input().split()))
INF = 10 ** 9
dp = [INF] * n
dp[0] = 0
for i in range(1, n):
    tmp = dp[i - 1] + abs(h[i] - h[i - 1])
    if dp[i] > tmp:
        dp[i] = tmp
    if i > 1:
        tmp = dp[i - 2] + abs(h[i] - h[i - 2])
        if dp[i] > tmp:
            dp[i] = tmp
print(dp[-1])


Measured memory_bytes: 20500
n = int(input())

def main():
    ans = [0]*(n+1)
    for x in range(1, 101):
        for y in range(1, 101):
            for z in range(1, 101):
                fn = x**2 + y**2 + z**2 + x*y + y*z + z*x
                if fn > n:
                    break
                else:
                    ans[fn] += 1

    for i in range(1, n+1):
        print(ans[i])

if __name__ == '__main__':
    main()

Measured memory_bytes: 9004
#include<iostream>
#include<algorithm>
#include<vector>
#include<stack>
#include<map>
#include<set>
#include<queue>
#include<cstdio>
#include<climits>
#include<cmath>
#include<cstring>
#include<string>
#include<sstream>
#include<numeric>
#include<cassert>

#define f first
#define s second
#define mp make_pair

#define REP(i,n) for(int i=0; i<(int)(n); i++)
#define rep(i,s,n) for(int i=(s); i<(int)(n); i++)
#define FOR(i,c) for(__typeof((c).begin()) i=(c).begin(); i!=(c).end(); i++)
#define ALL(c) (c).begin(), (c).end()
#define IN(x,s,g) ((x) >= (s) && (x) < (g))
#define ISIN(x,y,w,h) (IN((x),0,(w)) && IN((y),0,(h)))
#define print(x) printf("%d\n",x)

using namespace std;

typedef unsigned int uint;
typedef long long ll;

const int _dx[] = {0,1,0,-1};
const int _dy[] = {-1,0,1,0};

int b[25][25];

int getInt(){
  int ret = 0,c;
  c = getchar();
  while(!isdigit(c)) c = getchar();
  while(isdigit(c)){
    ret *= 10;
    ret += c - '0';
    c = getchar();
  }
  return ret;
}

int main(){
  int n = getInt();
  while( n --> 0 ){
    int ans = 0;
    REP(i,5) REP(j,5) b[i][j] = getInt();
    for(int x1 = 0; x1 < 5; x1++){
      for(int y1 = 0; y1 < 5; y1++){
        for(int x2 = x1; x2 < 5; x2++){
          for(int y2 = y1; y2 < 5; y2++){
            bool ok = true;
            int lect = (x2 - x1 + 1) * (y2 - y1 + 1);
            if(lect <= ans) continue;
            for(int y = y1; y <= y2; y++){
              for(int x = x1; x <= x2; x++){
                if(b[y][x] == 0){
                  ok = false;
                  goto end;
                }
              }
            }
          end:
            if(ok){
              ans = lect;
            }
          }
        }
      }
    }
    print(ans);
  }
  return 0;
}

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

typedef pair<int, int> pi;
typedef vector<vector<int>> vv;

int32_t main() 
{ 
	int n, m;
	cin >> n >> m;

	if(n == m){
		cout << "Yes" << endl;
	}else{
		cout << "No" << endl;
	}
}

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

class P{
public:
  int tID;
  bool solve[12];
  int penalty;
  int ac;
  int wa[12];

  P(){}

  bool operator<(const P &p)const{
    if(ac == p.ac){
      if(penalty == p.penalty){
        return tID < p.tID;
      }
      return penalty < p.penalty;
    }
    return ac > p.ac;
  }
};

P t[102];

int main(){
  int T, P, R;

  while(cin >> T >> P >> R, T || P || R){
    memset(t, 0, sizeof(t));

    for(int i = 0; i < T; i++){
      t[i].tID = i;
    }

    for(int i = 0; i < R; i++){
      int tID, pID, tm;
      string mes;

      cin >> tID >> pID >> tm >> mes;
      tID--;

      if(t[tID].solve[pID]){
        continue;
      }

      if(mes == "CORRECT"){
        t[tID].solve[pID] = true;
        t[tID].ac++;
        t[tID].penalty += tm + t[tID].wa[pID] * 1200;
      }
      else{
        t[tID].wa[pID]++;
      }
    }

    sort(t, t + T);

    for(int i = 0; i < T; i++){
      cout << t[i].tID + 1 << " " << t[i].ac << " " << t[i].penalty << endl;
    }
  }
}

Measured memory_bytes: 932
#include<stdio.h>
#include<cstdio>
using namespace std;

int main() {
  int N, K;
  scanf("%d%d", &N, &K);
  int A[N];
  int minidx = 0;
  for (int i = 0 ; i < N ; i++) {
    scanf("%d", &A[i]);
  }
  int res = 0;
  int g = 1;
  while (true) {
    if (N <= K + (K-1)*(g-1)) break;
    else g++;
  }
  
  printf("%d\n", g);
}

Measured memory_bytes: 512
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using Graph = vector<vector<int>>;
#define ALL(x) (x).begin(), (x).end()
#define REP(i ,n) for(int i = 0; i < (int)(n); i++)
#define pb push_back
typedef vector<int>vint;
typedef vector<ll>vll;
template<typename T> istream &operator>>(istream &is, vector<T> &vec){ for (auto &v : vec) is >> v; return is; }
template<typename A,typename B>inline void chmin(A &a,B b){if(a>b)a=b;}
template<typename A,typename B>inline void chmax(A &a,B b){if(a<b)a=b;}

int main()
{
  int N;
  cin >> N;
  vector<pair<int,int>> A;
  REP(i,N){
  	int a;
    cin >> a;
    a--;
    A.pb(make_pair(a,i));
  }
  
  sort(A.begin(), A.end());
  
  for(auto a : A){
    cout << a.second+1 << " ";
  }
  cout << endl;
}

Measured memory_bytes: 1780
#include <bits/stdc++.h>
#define rep(i, m, n) for(int i = m; i < (n); i++)
#define print(x) cout << (x) << endl;
#define printv(x) for(int i = 0; i < x.size(); i++){ cout << (x[i]) << " "; } cout << endl; 
#define printa(x,n) for(int i = 0; i < n; i++){ cout << (x[i]) << " ";} cout << endl;
#define printaa(x) for(int i = 0; i < (sizeof(x)/sizeof(x[0])); i++){ for(int j = 0; j < (sizeof(x[0])/sizeof(x[0][0])); j++){ cout << x[i][j] << " ";} cout << endl;}
#define INF (1e9)
typedef long long ll;
typedef struct{
    int x;
    int y;
} P;

using namespace std;

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    string S;
    cin >> S;
    int n = S.size();
    int count = 0;
    int s = 2;
    int g = n - 2;
    if(S[0] == 'A'){
        rep(i,s,g+1){

            if(S[i] == 'C'){
                count++;
            }
        }
        int count2 = 0;
        if(count == 1){
            rep(i,0,n){
                if(S[i] - 'a' < 0){
                    count2++;
                }
            }
            if(count2 == 2){
                print("AC");
                return 0;
            }
        }
    }
    print("WA");
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ll long long
#define pb push_back
#define fi first
#define se second
#define mp make_pair
#define endl '\n'
#define rep(i,l,r) for(int i=l;i<=r;i++)
#define per(i,r,l) for(int i=r;i>=l;i--)
const int MX=2e6+7;
const int mod=998244353;
const double pi=3.1415926535897932384;
double isp=1e-13;
using namespace std;
ll qpow(ll a,ll b,ll MOD=mod){for(ll ans=1;;a=a*a%MOD,b>>=1){if(b&1)ans=ans*a%MOD;if(!b)return ans;}}
ll inv(ll a,ll MOD=mod){return qpow(a,MOD-2,MOD);}//要求MOD为质数
ll exgcd(ll a,ll b,ll &x,ll &y){if(b==0){x=1,y=0;return a;}ll ret=exgcd(b,a%b,y,x);y-=a/b*x;return ret;}
ll getInv(int a,int mod){ll x,y;ll d=exgcd(a,mod,x,y);return d==1?(x%mod+mod)%mod:-1;}//求a在mod下的逆元，不存在逆元返回-1，不要求MOD为质数
int main()
{
  ios::sync_with_stdio(0),cin.tie(0);
  ll n,s;
  cin>>n>>s;
  ll m=sqrt(n);
  if(n==s)
  {
      cout<<n+1<<endl;
      return 0;
  }
  for(int i=2;i<=m;i++)
  {
      ll cnt=0;
      ll k=n;
      while(k)
      {
          cnt+=k%i;
          k/=i;
      }
      if(cnt==s)
      {
          cout<<i<<endl;
          return 0;
      }
  }
  for(ll k=m;k>=1;k--)
  {
      if((n-s)%k==0&&k<(n-s)/k+1&&n-k*((n-s)/k+1)<(n-s)/k+1&&n-k*((n-s)/k+1)>=0)
      {
          cout<<(n-s)/k+1<<endl;
          return 0;
      }
  }
  cout<<-1<<endl;
  return 0;
}



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

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

	int ans = 1;
	if( N == 1 ) {
	}
	else {
		long long last = A[0];
		int dir = 0;
		if( A[1] < last ) dir = -1;
		if( A[1] > last ) dir = 1;
		for( int i = 1; i < N; i++ ) {
			if( dir < 0 ) {
				if( A[i] > last ) {
					ans++;
					dir = 0;
					if( i + 1 < N ) {
						 if( A[i + 1] < A[i] ) dir = -1;
						 if( A[i + 1] > A[i] ) dir = 1;
					}
				}
			}
			else if( dir > 0 ) {
				if( A[i] < last ) {
					ans++;
					dir = 0;
					if( i + 1 < N ) {
						 if( A[i + 1] < A[i] ) dir = -1;
						 if( A[i + 1] > A[i] ) dir = 1;
					}
				}
			}
			else {
				if( A[i] > last ) dir = 1;
				if( A[i] < last ) dir = -1;
			}
			last = A[i];
		}
	}

	cout << ans << endl;
}


Measured memory_bytes: 1024
import java.util.Scanner;


public class Main {


    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int N = Integer.parseInt(sc.next());
        int A = Integer.parseInt(sc.next());
        
        int M = N % 500;
        if(M > A){
            System.out.println("No");
        }else{
            System.out.println("Yes");
        }
    }
}

Measured memory_bytes: 21844
#include<bits/stdc++.h>
using namespace std;
const long long INF = 1e7 + 1;
const long long MOD = 1000000007;
const long double PI = 3.1415926;
#define FOR(i,r,n) for(ll i = (ll)(r); i < (ll)(n); i++)
#define RFOR(i,r,n) for(ll i=(ll)(n-1);i>=r;i--)
#define REP(i,n) FOR(i,0,n)
#define RREP(i,n) RFOR(i,0,n)
#define ALL(x) x.begin(),x.end()
#define RALL(x) x.rbegin(),x.rend()
typedef long long int ll;
typedef vector<ll> vi;
typedef vector < pair<ll, ll > > vp;
typedef vector <string> vs;
typedef vector <char> vc;
typedef list <ll> lst;
 
ll n, m, k, ans = 0, sum = 0, cnt = 0;
string s;
char c;
 
#define Endl endl
 
map<string, string> mp, mpg,mpa;
 
/*--------------------template--------------------*/
 
int main()
{
	cin >> s;
	REP(i, s.size())
	{
 
		if (s[i] == 'A') {
			if (i != s.size() - 1 && s[i + 1] == 'C') {
				cout << "Yes" << endl;
				return 0;
			}
		}
	}
	cout << "No" << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <string>
#include <ctime>
#include <algorithm>
#define N 101
#define PLL pair<ll, ll>
#define MP make_pair
typedef long long ll;
template<typename T> inline void read(T &x) {
  x = 0; char c = getchar();
  while (!isdigit(c)) c = getchar();
  while (isdigit(c)) { x = (x << 1) + (x << 3) + (c ^ 48); c = getchar(); }
}
using namespace std;
const int P = 1e9 + 7;
int ftot;
ll f[N];
PLL pr[N][N];
inline void work() {
  ll n, m, res = 0; read(n), read(m);
  if (n > m)  swap(n, m);
  if (n == 1) {
    printf("1 %lld\n", m % P);
    return ;
  }
 
  int p;
  p = upper_bound(f + 1, f + 1 + ftot, n) - f - 1;
  if (f[p + 1] > m) --p;
  printf("%d ", p);
  if (p == 1) res = n % P;
  for (int i = 1; i <= p; ++i)
    if (pr[p][i].first <= n && pr[p][i].second <= m)
      res = (res + (m - pr[p][i].second) / pr[p][i].first + 1) % P;
  swap(n, m);
  for (int i = 1; i <= p; ++i)
    if (pr[p][i].first <= n && pr[p][i].second <= m)
      res = (res + (m - pr[p][i].second) / pr[p][i].first + 1) % P;
  printf("%lld\n", (res % P + P) % P);
}
int main() {
  f[0] = f[1] = 1;
  for (int i = 2; f[i - 1] <= 3e18; ++i)  f[i] = f[i - 1] + f[i - 2], ftot = i;
  pr[1][1] = MP(1, 2);
  for (int i = 2; i <= 91; ++i) {
    for (int j = 1; j < i; ++j) pr[i][j] = MP(pr[i - 1][j].second, pr[i - 1][j].first + pr[i - 1][j].second);
    ll a = pr[i - 1][1].first, b = pr[i - 1][1].second;
    pr[i][i] = MP(a + b, a + a + b);
    for (int j = 1; j <= i; ++j) {
    	if (pr[i][j].first > 2e18)	pr[i][j].first = 2e18;
    	if (pr[i][j].second > 2e18)	pr[i][j].second = 2e18;
    }
  }
  int _; read(_);
  while (_--)
    work();
  return 0;
}

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

using namespace std;
typedef long long ll;
typedef unsigned long long ull;

int main() {
    ios::sync_with_stdio(0);
    cin.tie(0);
    ll n, m;
    cin >> n >> m;
    vector<int> a(n);
    ll sum = 0;
    for(auto& el : a){
        cin >> el;
        sum += el;
    }
    double k = 1;
    k /= 4*m;
    k *= sum;
    sort(begin(a), end(a), [](int a, int b){ return b < a;});
    bool res = true;
    for(int i = 0; i < m; ++i){
        if((double)a[i] < k){
            res = false;
        }
    }
    if(!res){
        cout << "No" << endl;
    }else{
        cout << "Yes" << endl;
    }

}

Measured memory_bytes: 256