akhauriyash/Code-Regression huggingface dataset:
//Bombs Chain
#include<bits/stdc++.h>
using namespace std;

vector<string> mp;
int dir[4][2]={{-1,0}, {0,1}, {1,0}, {0,-1}};

void bomb(int x, int y){
  if(x<0||8<=x||y<0||8<=y)return;
  if(mp[x][y]=='0')return;
  mp[x][y]='0';
  for(int i=0; i<4; i++){
    for(int j=1; j<=3; j++){
      bomb(x+dir[i][0]*j, y+dir[i][1]*j);
    }
  }
}

int main(){
  string s;
  int n;
  cin>>n;
  for(int i=1; i<=n; i++){
    mp.clear();
    do{
      cin>>s;
    }while(s=="");
    mp.push_back(s);
    for(int j=0; j<7; j++){
      cin>>s;
      mp.push_back(s);
    }
    int x, y;
    cin>>x;
    cin>>y;
    bomb(y-1, x-1);
    cout<<"Data "<<i<<":"<<endl;
    for(int j=0; j<8; j++)cout<<mp[j]<<endl;
  }
  return 0;
}

Measured memory_bytes: 1216
#!/usr/bin/env python3


def solve(n, a, b, c, l):

    target = [a, b, c]

    INF = 10 ** 4
    ans = INF
    for i in range(2 ** (2 * n)):
        counts = [0] * 3
        lengths = [0] * 3
        x = i
        for j in range(n):
            g = x % 4
            if g < 3:
                counts[g] += 1
                lengths[g] += l[j]
            x = x // 4
        r = 0
        for g in range(3):
            if counts[g] == 0:
                r = INF
                break
            r += abs(target[g] - lengths[g])
        r += (sum(counts) - 3) * 10
        ans = min(ans, r)

    return ans


def main():
    n, a, b, c = input().split()
    n = int(n)
    a = int(a)
    b = int(b)
    c = int(c)
    l = []
    for _ in range(n):
        li = input()
        li = int(li)
        l.append(li)

    print(solve(n, a, b, c, l))


if __name__ == '__main__':
    main()



Measured memory_bytes: 3064
import java.util.Scanner;
public class Main{
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
         int S = sc.nextInt();
         int h = S/3600;
         int m = S%3600/60;
         int s = S%60;
         System.out.println(""+h+":"+m+":"+s+"");
         sc.close();
    }
}


Measured memory_bytes: 26304
#include <stdio.h>

int main(void)
{
	int lon,hor,dia;
	int rec = 0,seb = 0;
	
	while(scanf("%d,%d,%d", &lon, &hor, &dia) != EOF){
		
		if(lon*lon + hor*hor == dia*dia)rec++;
		if(lon == hor)seb++;
	}
	
	printf("%d\n%d\n", rec, seb);
	
	return(0);
}

Measured memory_bytes: 596
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
//#define maxn 20050
//#include<bits/stdc++.h>
#include<bits/stdc++.h>
using namespace std;
#define ll long long
const int maxn = 3000 + 10;
inline ll fpow(ll a, ll n, ll mod) {
	ll res = 1;
	for (; n; n >>= 1, a = a*a%mod)
	if (n & 1ll)
		res = res*a%mod;
	return res;
}
ll c[maxn][maxn];
ll g[maxn][maxn];
int main() {
	ll n, mod;
	scanf("%lld%lld", &n, &mod);
	for (int i = 1; i <= n; i++) {
		c[i][0] = 1;
		c[i][i] = 1;
		for (int j = 1; j<i; j++)
			c[i][j] = (c[i - 1][j - 1] + c[i - 1][j]) % mod;
	}
	for (int i = 0; i <= n; i++) {
		g[i][0] = 1;
		for (int j = 1; j <= i; j++)
			g[i][j] = (g[i - 1][j - 1] + g[i - 1][j] * (j + 1) % mod) % mod;
	}
	ll ans = 0;
	for (int i = 0; i <= n; i++) {
		ll k = c[n][i];
		if (i & 1)
			k = (mod - k) % mod;
		ll kind = fpow(2, n - i, mod);
		ll x = fpow(2, n - i, mod - 1);
		x = fpow(2, x, mod);
		ll cnt = 0, y = 1;
		for (int j = 0; j <= i; j++) {
			cnt = (cnt + (g[i][j] * y%mod)) % mod;
			y = kind*y%mod;
		}
		ans = (ans + (k*cnt%mod*x%mod)) % mod;
	}
	printf("%lld\n", ans);
	return 0;
}

Measured memory_bytes: 139904
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define float long double
#define IOS ios_base::sync_with_stdio(false), cin.tie(NULL)
const int mod = 1000000007;

int32_t main()
{
   int a,b,c;
   cin>>a>>b>>c;
   if(c>=(a+b))
   	cout<<0<<" "<<0<<endl;
   else
   {
   		if(c<a)
   			cout<<a-c<<" "<<b<<endl;
   		else if(c==a)
   			cout<<0<<" "<<b<<endl;
   		else
   			cout<<0<<" "<<b-(c-a)<<endl;
   }
}

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

using namespace std;
#define  ll long long
#define ld long double
#define f first
#define s second

bool vis[144];

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

    for(int i=1; i<=k; i++)
    {
        int d;
        cin >> d;
        for(int j=1; j<=d; j++)
        {
            int x;
            cin >> x;
            vis[x] = 1;
        }
    }

    int ans=0;
    for(int i=1; i<=n; i++)
    {
        if (!vis[i]) ans++;
    }

    cout << ans;

    return 0;
}

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

class Problem0004
{
    static void Main(string[] args)
    {
        var xyPairs =
            GetInputLines()
            .Select(line => line.Split().Select(word => double.Parse(word)).ToArray())
            .Select(abcdef => Solve(abcdef));
        foreach (double[] xy in xyPairs)
        {
            Console.WriteLine(xy[0].ToString("F3") + " " + xy[1].ToString("F3"));
        }
    }

    static double[] Solve(double[] abcdef)
    {
        double a = abcdef[0];
        double b = abcdef[1];
        double c = abcdef[2];
        double d = abcdef[3];
        double e = abcdef[4];
        double f = abcdef[5];
        double x = (c * e - b * f) / (a * e - b * d);
        double y = (c * d - a * f) / (b * d - a * e);
        return new double[] { x, y };
    }

    static IEnumerable<string> GetInputLines()
    {
        string line;
        while (!string.IsNullOrEmpty(line = System.Console.ReadLine()))
        {
            yield return line;
        }
    }
}

Measured memory_bytes: 9788
#include <bits/stdc++.h>
 
using namespace std;
 
#define FOR(i,k,n) for(int i = (k); i < (n); ++i)
#define REP(i,n) FOR(i,0,n)
#define INF 114514810
#define ELEM(array) (sizeof (array)/sizeof *(array))
#define MAX_N 100005
#define SAFE_FREE(ptr) if( ptr != NULL ){ free(ptr); ptr = NULL; }
typedef unsigned int UINT;
typedef long long  ll;
typedef pair<int, int> P;
 
int pow(ll x, ll n, ll mod)
{
    ll res = 1;
    while (n>0)
    {
        if (n & 1)res = res*x%mod;
        x = x*x%mod;
        n >>= 1;
    }
    return res;
}
 
int main()
{
    int m, n; 
    cin >> m >> n;
    cout << pow(m, n, 1000000007) << endl;
    return 0;
}

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

int N;

int main(){
	int one = 0, two = 0, four = 0;
	scanf("%d", &N);
	for(int i = 0; i < N; i++){
		int var;
		scanf("%d", &var);
		if(var % 4 == 0) four++;
		else if(var % 2 == 0) two++;
		else one++;
	}
	two %= 2;
	one += two;
	one -= four;
	if(one <= 1) printf("Yes\n");
	else printf("No\n");
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(n);i++)
using namespace std;
using ll = long long;
int main(void){
  int A,B;
  cin>>A>>B;
  
  int sum=0;
  rep(i,2){
     if(A>B){
         sum+=A;
         A--;
     }
     else{
         sum+=B;
         B--;
     }
  }
  cout<<sum<<endl;
  
}

Measured memory_bytes: 3532
#include <stdlib.h>
#include <cmath>
#include <cstdio>
#include <cstdint>
#include <string>
#include <iostream>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
using namespace std;

int main(){
  int A,B;
  cin >> A >> B;
  int s=int(A/0.1)-1;
  int e=int(B/0.08)+1;
  for(int i=0;i<=1000;i++){
    if(int(0.08*i)!=A) continue;
    if(int(0.1*i)!=B) continue;
    cout << i << endl;
    return 0;
  }
  cout << -1 << endl;
  return 0;
}


Measured memory_bytes: 256
N = int(input())
X = list(map(int,input().split()))
newX = []
for i in range(N):
  newX.append((X[i],i))
newX.sort()
ans = [0]*N
f = N//2-1
l = N//2
for i in range(N):
  num, ind = newX[i]
  if i < l:
    ans[ind] = newX[l][0]
  else:
    ans[ind] = newX[f][0]
for j in ans:
  print(j)




Measured memory_bytes: 110252
#include<algorithm>
#include<iostream>
#include<stdio.h>
#include<iostream>
#include<stdio.h>
#include<vector>
#include<set>
#include<string>
#include<iomanip>
#include<queue>
#include<functional>
#include<cmath>
#include<map>
#include<tuple>
#include <numeric>
#define rep(i,n) for(int i=0; i<(int)n; i++)//n回繰り返す
#define rrep(i,n)for(int i=n-1;i>=0;i--)
#define REP(i,n) for (int i = 1; i <= (int)n; i++)//i=1からi=nまで
#define RREP(i,n)for(int i=n;i>=1;i--)
using namespace std;
using ll = long long;
using P = pair<int, int>;
using graph = vector<vector<int>>;
const ll mod = pow(10, 9) + 7;
const int INF = 1e9;
const ll LINF = 1e18;
const double pi = 3.14159265358979323846;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

int main() {
    int N, M, K; cin >> N >> M >> K;
    vector<ll> A(N + 1), B(M + 1);
    ll f, ans = 0;
    f = 0;
    A[0] = 0, B[0] = 0;
    REP(i, N) {
        int a;
        cin >> a;
        A[i] = A[i - 1] + a;
    }
    REP(i, M) {
        int b;
        cin >> b;
        B[i] = B[i - 1] + b;
        if (K >= B[i]) {
            f = i;
        }
    }
    rep(i, N+1) {
        if (A[i] + B[0] > K)break;
        while (A[i] + B[f] > K) {
            f--;

        }
        ans = max(ans, i + f);
    }
    cout << ans << endl;
}


    


    





















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


int main(int argc, char const *argv[])
{
	
	 int a,b;
	 int ans;

	 cin>>a>>b;
	 if(a>=13)
	 	ans=b;
	 else if(a>=6)
	 	ans=b/2;
	 else
	 	ans=0;

	 cout<<ans;

	return 0;
}

Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
const long long MOD = 1e9+7, MAX = 1e18, larg = 1e5, INF = -1e9;
long long A,B,C,D,E,F,G,H,I,J,K,L,N,M,O,P,Q,R,S,T,U,V,W,X,Y,Z;
long long max_value = INF, max_index = -1;
long long min_value = MAX, min_index = -1;

typedef long long ll;
typedef pair<ll, ll> Pa;

int main() {
    cin >> X;
    int low = (X%100)/5;
    if(X%5 != 0) low++;
    if(X/100 < low) cout << 0;
    else cout << 1;
}


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

int main(){
    
    // 1. 入力情報.
    int N, sum = 0;
    scanf("%d", &N);
    map<string, int> m;
    rep(i, N){
        char c[111];
        int t;
        scanf("%s %d", c, &t);
        string s(c);
        sum += t;
        m[s] = sum;
    }
    
    // 2. ニワンゴ君が寝ている間に曲が再生された時間が何秒あったか.
    char c[111];
    scanf("%s", c);
    string X(c);
    int ans = sum;
    ans -= m[X];
    
    // 3. 出力.
    printf("%d\n", ans);
    return 0;
    
}

Measured memory_bytes: 256
/*
*
* author: ian macleod
*
*/

#include <bits/stdc++.h>

using namespace std;

typedef long long int ll;
typedef vector<long long int> vll;

#define IO                 \
    ios::sync_with_stdio(0); \
    cin.tie(0);              \
    cout.tie(0);
 
#define f(i,a,b) for(ll i=a;i<b;i++)
#define fo(i,a,b) for(ll i = a; i<=b;i+=1)
#define rf(i,a,b) for(ll i=a;i>=b;i--)

ll power(ll x, ll y) {
    ll res = 1;     // Initialize result
    x = x ;
    if (y==0)return 1;
    if(x==0)return 0;
    while (y > 0) {
        if (y & 1)
            res = (res*x);
        y = y>>1; // y = y/2
        x = (x*x);  // Change x to x^2
    }
    return res;
}


void solve() {
    
    ll a, b;
    cin >> a >> b;
    char c;
    cin >> c;
    int d; 
    cin >> d; 
    b *= 100;
    b += d;
    cout << a * b / 100 << endl;
    return ;
}



int main() {
    solve();
}



Measured memory_bytes: 3620
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

using namespace std;
using namespace __gnu_pbds;
 
#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define fbo find_by_order
#define ook order_of_key
 
typedef long long ll;
typedef pair<ll,ll> ii;
typedef vector<ll> vi;
typedef long double ld; 
typedef tree<ll, null_type, less<ll>, rb_tree_tag, tree_order_statistics_node_update> pbds;

ll dp[40][222222];

bool cmp(ii a, ii b)
{
	return ((b.fi)*1LL*a.se<(a.fi)*1LL*b.se);
}

int main()
{
	ios_base::sync_with_stdio(0); cin.tie(0);
	int n,t; cin>>n>>t; t++;
	vector<int> zero;
	vector<ii> vec;
	for(int i=0;i<n;i++)
	{
		int a,b; cin>>a>>b;
		b++;
		if(a==0) zero.pb(b);
		else vec.pb({a,b});
	}
	sort(zero.begin(),zero.end());
	sort(vec.begin(),vec.end(),cmp);
	for(int i=0;i<vec.size();i++)
	{
		dp[0][i]=1;
	}
	for(int i=0;i<vec.size();i++)
	{
		dp[1][i]=vec[i].fi+vec[i].se+1;
	}
	for(int j=2;j<=39;j++)
	{
		ll best = ll(1e18);
		for(int i=0;i<vec.size();i++)
		{
			if(best<=ll(1e9)+7)
			{
				dp[j][i]=best*(vec[i].fi+1)+vec[i].se;
			}
			else dp[j][i]=0;
			if(dp[j-1][i]>0) best=min(best,dp[j-1][i]);
		}
	}
	int ans=0; 
	for(int j=0;j<=39;j++)
	{
		ll res = ll(1e18);
		for(int i=0;i<vec.size();i++)
		{
			if(dp[j][i]!=0) res=min(res,dp[j][i]);
		}
		if(vec.empty()&&j==0) res=1;
		if(res<=t)
		{
			int cnt=0;
			ll remtime = t - res;
			while(cnt<zero.size()&&remtime>=zero[cnt])
			{
				remtime-=zero[cnt];
				cnt++;
			}
			ans=max(ans,j+cnt);
		}
	}
	cout<<ans<<'\n';
}


Measured memory_bytes: 73432
#include <bits/stdc++.h>
using namespace std;
using ll = long long; 
using vpii = vector<pair<int, int>>;
#define rep(i, n) for (int i = 0; i < (int)n; i++)
#define rep1(i, n) for (int i = 1; i < (int)n; i++)
ll mod = 1e9+7;
ll inf = 1e10;

ll gcd(ll a, ll b){
  return (b != 0) ? gcd(b, a%b) : a;
}

ll lcm(ll a, ll b){
  return (a/gcd(a,b))*b;
}

template<class T>
bool contain(const string& s, const T& v){
  return s.find(v) != std::string::npos;
}

int main(){
  cin.tie(0);
  ios_base::sync_with_stdio(false);
  ll a, b;
  cin >> a >> b;
  ll n = gcd(a, b);
  ll ans = 1;
  for(int i = 2; i <= sqrt(n); ++i){
    if(n%i != 0) continue;
    while(n%i == 0) n /= i;
    ++ans;
  }
  if(n > 1) ++ans;
  cout << ans << "\n";
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#pragma GCC optimize("Ofast")
typedef long long lint;
typedef unsigned int uint;
typedef pair<int, int> pii;
typedef pair<lint, lint> pll;
typedef unsigned long long ulint;
#define endl '\n'
#define fst first
#define sed second
#define pb push_back
#define rint register int
#define SZ(x) (int((x).size()))
#define all(x) (x).begin(), (x).end()
#define reveal(x) cerr << #x << " = " << (x) << endl
#define rep(it, f, e) for (rint it = (f); it <= (e); ++it)
#define per(it, f, e) for (rint it = (f); it >= (e); --it)
#define repe(it, x) for (auto it = (x).begin(); it != (x).end(); ++it)
const int MAXN = 1e5 + 20;
vector<pii> edge[MAXN];
vector<pii> graph[MAXN * 5];
map<pii, int> mp;
int dis[MAXN * 5];
int Hash[MAXN * 5], cnt = 0;
deque<int> que;
int main() {
	ios::sync_with_stdio(false);
	cin.tie(NULL), cout.tie(NULL);
	int n, m;
	cin >> n >> m;
	rep (i, 1, m) {
		int u, v, c;
		cin >> u >> v >> c;
		edge[u].pb(pii(v, c));
		edge[v].pb(pii(u, c));
		if (mp.count(pii(u, c)) == 0) {
			mp[pii(u, c)] = cnt++;
		}
		if (mp.count(pii(v, c)) == 0) {
			mp[pii(v, c)] = cnt++;
		}
	}
	rep (i, 1, n) {
		mp[pii(i, 0)] = cnt++;
	}
	rep (i, 1, n) {
		for (auto v : edge[i]) {
			int a = mp[pii(i, v.sed)];
			int b = mp[pii(v.fst, v.sed)];
			graph[a].pb(pii(b, 0)); 
			if (Hash[a] == 0) {
				Hash[a] = 1;
				graph[a].pb(pii(mp[pii(i, 0)], 1));
				graph[mp[pii(i, 0)]].pb(pii(a, 1));
			}
		}
	}
	memset(dis, -1, sizeof(dis));
	que.push_back(mp[pii(1, 0)]);
	dis[que[0]] = 0;
	while (SZ(que)) {
		int u = que.front();
		que.pop_front();
		for (auto v : graph[u]) {
			if (dis[v.fst] == -1) {
				dis[v.fst] = dis[u] + v.sed;
				if (v.sed) que.push_back(v.fst);
				else que.push_front(v.fst);
			}
		}
	}
	if (~dis[mp[pii(n, 0)]]) {
		cout << dis[mp[pii(n, 0)]] / 2 << endl;
	} else cout << -1 << endl;
	return 0;
}

Measured memory_bytes: 73216
#include <bits/stdc++.h>
#define rep(i, a, n) for (int i = (int)(a); i <= (int)(n); ++i)
#define rrep(i, a, n) for (int i = (int)(a); i >= (int)(n); --i)
#define debug(x) cerr << #x << " = " << x << "\n"
#define debugv(x) \
  rep(f, 0, (x.size() - 1)) cerr << x[f] << (f == (x.size() - 1) ? "\n" : " ")
#define all(x) x.begin(), x.end()
#define int long long
using namespace std;
typedef pair<int, int> pii;
typedef vector<int> vi;
const int MX = 1e5 + 5, INF = 5 << 28, MOD = 1e9 + 7;

int N, M, K;
vi A, B;
string S, T;

void input() {
  cin >> N >> K;
  A.resize(N);
  rep(i, 0, N - 1) { cin >> A[i]; }
}
void solve() {
  sort(all(A));
  reverse(all(A));

  int ans = 0;
  rep(i, 0, K - 1) { ans += A[i]; };
  cout << ans << endl;
  ;
}
signed main() {
  input();
  solve();
  return 0;
}

Measured memory_bytes: 256
s = input()
t = input()

a = len(s)
b = len(t)
ans = []
if a-b+1 < 0:
    print("UNRESTORABLE")
    exit()

for i in range(a-b+1):
    p = 0
    for j in range(b):
        if s[i+j] != t[j] and s[i+j] != "?":
            p = 1
            break
    if p == 0:
        kar = s[:i] + t + s[i+b:]
        kar = kar.replace("?","a")
        ans.append(kar)
if len(ans) == 0:
    print("UNRESTORABLE")
else:
    ans.sort()
    print(ans[0])

Measured memory_bytes: 3064
import heapq

N, M = map(int, input().split())
A = list(map(int, input().split()))
A = [-n for n in A]
heapq.heapify(A)

for _ in range(M):
    high = -heapq.heappop(A)
    heapq.heappush(A, -(high//2))

print(-sum(A))

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

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

const int INF=1e9;
const int MOD=1e9+7;

int main(){
    int N,K; cin >> N >> K;
    ll a[N];
    for(int i=0;i<N;i++){
        cin >> a[i];
    }
    ll sum[N+1]={};
    vector<ll> su;
    for(int i=0;i<N;i++){
        sum[i+1]=sum[i]+a[i];
    }
    for(int i=1;i<=N;i++){
        for(int j=i;j<=N;j++){
            su.push_back(sum[j]-sum[i-1]);
        }
    }
    for(int i=45;i>=0;i--){
        vector<ll> tmp;
        for(int j=0;j<su.size();j++){
            if(su[j]&(1LL<<i)) tmp.push_back(su[j]);
        }
        if(tmp.size()>=K){
            su=tmp;
        }
    }
    ll ans=su[0];
    for(int i=1;i<K;i++){
        ans=ans&su[i];
    }
    cout << ans << endl;
}

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

int main() {
  int n,m;cin>>n>>m;
  vector<vector<int>> s(m);
  rep(i,m){
    int k;cin>>k;
    rep(j,k){
      int a;cin>>a;
      a--;
      s[i].push_back(a);
    }
  }
  vector<int> p(m);
  rep(i,m)cin>>p[i];
  int ans=0;
  rep(bit,1<<n){
    //スイッチのon,offを全通り試す
    bool ok=true;
    rep(i,m){
      //それぞれの電球に対してonの個数を調べる
      int cnt=0;
      for(auto x:s[i]){
        if(bit&(1<<x))cnt++;
      }
      if(cnt%2!=p[i])ok=false;
    }
    if(ok)ans++;
  }
  cout<<ans<<endl;
}


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

namespace b120A {
    class Program {
        static void Main(string[] args) {
            var input = Console.ReadLine().Split(' ').Select(int.Parse).ToArray();
            var a = input[0];
            var b = input[1];
            var c = input[2];
            Console.WriteLine(Math.Min(c,b/a));
        }
    }
}

Measured memory_bytes: 11348
#define _GLIBCXX_DEBUG
#include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <utility>
#include <string>
#include <map>
using namespace std;
typedef long long ll;
#define ALL(v) (v).begin(), (v).end()
const int inf = 1e9;
const int mod = 1e9+7;

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

    sort(A, A+N);

    int num = A[0];
    int cnt = 1, sum = 0;
    for (int i = 1; i < N; i++) {
        if (num == A[i]) {
            cnt++;
            if (i == N-1) sum += (cnt-1);
        } else {
            sum += (cnt-1);
            num = A[i];
            cnt = 1;
        }
    }

    if (sum % 2) {
        cout << N- (sum + 1) << endl;
    } else {
        cout << N - sum << endl;
    }
    return 0;
}


Measured memory_bytes: 640
class Tree:
    root = None

    def insert(self, node):
        y = None
        x = self.root
        while x:
            y = x
            x = x.left if node.key < x.key else x.right

        if not y:
            self.root = node
        elif node.key < y.key:
            y.left = node
        else:
            y.right = node

    def print(self):
        print(' ', end='')
        print(*self.root.print_in())
        print(' ', end='')
        print(*self.root.print_pre())

    def find(self, node):
        y = None
        x = self.root
        while x:
            y = x
            if node.key == x.key:
              break
            elif node.key < x.key:
              x = x.left
            else:
              x = x.right
            
        
        if not y:
            print("no")
        elif node.key == y.key:
            print("yes")
        else:
            print("no")


class Node:
    def __init__(self, key):
        self.left = None
        self.right = None
        self.key = key

    def print_pre(self):
        yield self.key
        if self.left:
            for k in self.left.print_pre(): yield k
        if self.right:
            for k in self.right.print_pre(): yield k

    def print_in(self):
        if self.left:
            for k in self.left.print_in(): yield k
        yield self.key
        if self.right:
            for k in self.right.print_in(): yield k


tree = Tree()
m = int(input())

while m:
    l = input().split()
    if len(l) == 2 and l[0] == "insert":
       tree.insert(Node(int(l[1])))
    elif len(l) == 2 and l[0] == "find":
       tree.find(Node(int(l[1])))
    else:
       tree.print()
    m -= 1


Measured memory_bytes: 91236
//#define NDEBUG
 
#include <bits/stdc++.h>
 
#define StarBurstStream ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define iter(a) a.begin(), a.end()
#define riter(a) a.rbegin(), a.rend()
#define lsort(a) sort(iter(a))
#define gsort(a) sort(riter(a))
#define mp(a, b) make_pair(a, b)
#define pb(a) push_back(a)
#define pf(a) push_front(a)
#define pob pop_back()
#define pof pop_front()
#define F first
#define S second
#define printv(a, b) {bool pvaspace=false; \
for(auto pva : a){ \
    if(pvaspace) b << " "; pvaspace=true;\
    b << pva;\
}\
b << "\n";}
#define pii pair<int, int>
#define pll pair<ll, ll>
#define modadd(a, b) (((a % MOD) + (b % MOD)) % MOD)
#define modtimes(a, b) (((a % MOD) * (b % MOD)) % MOD)
 
//#define TEST
 
typedef long long ll;
typedef unsigned long long ull;
 
using namespace std;
 
const ll MOD = 1000000007;
const ll MAX = 2147483647;

int main(){
    StarBurstStream

    int a, b;
    cin >> a>> b;

    int now = 1;
    int ans = 0;
    while(now < b){
        now = now - 1 + a;
        ans++;
    }
    cout << ans << "\n";

    return 0;
}

Measured memory_bytes: 256
def check(first, second, third, num_list):
    first_flag = False
    second_flag = False
    third_flag = False
    for num in num_list:
        if first_flag:
            if second_flag:
                if third_flag:
                    return True
                else:
                    if str(num) == third:
                        third_flag = True
            else:
                if str(num) == second:
                    second_flag = True
        else:
            if str(num) == first:
                first_flag = True
        if first_flag and second_flag and third_flag:
            return True
    return False

n = int(input())
s = input()
sl = list(s)

ans = 0

for i in range(1000):
    if i < 10:
        flag = check('0', '0', str(i), sl)
    elif i < 100:
        flag = check('0', str(i//10), str(i%10), sl)
    else:
        flag = check(str(i//100), str((i%100)//10), str(i%10), sl)
        
    if flag:
        ans += 1

print(ans)

Measured memory_bytes: 42988
#include <bits/stdc++.h>
using namespace std;
int main(){
	
	int H,W;
	for(;;){
		
		cin>>H>>W;
		
		if(H==0&&W==0)break;
		
		for(int i=0;i<H;i++){
			for(int j=0;j<W;j++){
				if(i==0||i==H-1||j==0||j==W-1){
					cout<<"#";
				}
				else
				    cout<<".";	
			}
			cout<<"\n";
		}
		cout<<endl;
	}
	return 0;
}

Measured memory_bytes: 3084
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <iomanip>
typedef long long ll;

using namespace std;

int main() {
    vector<int> v(2);
    cin >> v[0] >> v[1];
    
    vector<bool> flag(3, false);
    for(int i = 0; i < 2; i++) {
        flag[v[i] - 1] = true;
    }
    
    for(int i = 0; i < 3; i++) {
        if(!flag[i]) {
            cout << i + 1 << endl;
        }
    }
    
    return 0;
}


Measured memory_bytes: 256
#[allow(unused_macros)]
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}
 
#[allow(unused_macros)]
macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};
 
    ($next:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
}
 
#[allow(unused_macros)]
macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };
 
    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };
 
    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };
 
    ($next:expr, bytes) => {
        read_value!($next, String).into_bytes()
    };
 
    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
    };
 
    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}
 
use std::cmp::Ordering;
 
use std::cmp;
use std::cmp::min;
use std::collections::BTreeMap;
use std::process;
use std::cmp::Ord;
use std::collections::HashMap;
use std::collections::HashSet;
use std::collections::VecDeque;
use std::collections::BTreeSet;
use std::mem;
 
use std::ops::{Deref, DerefMut, Index, IndexMut};
use std::any::{Any, TypeId};

fn main(){
    input!{
        n:usize,
    }
    let mut dp = vec![vec![vec![-1;5];5];77];
    let MOD = 1000000007;
    fn dfs(d:i64, xm:usize, am:usize, dp:&mut Vec<Vec<Vec<i64>>>, n:usize, MOD:i64)->i64{
        if d<0{return 1;}
        if dp[d as usize][xm][am] != -1{return dp[d as usize][xm][am];}
        let mut res = 0;
        if n>>d&1 == 1{
            res += dfs(d-1, 1, cmp::min(2, am*2+1), dp, n, MOD);
        }
        else{
            res += dfs(d-1, xm,cmp::min(2, am*2), dp, n, MOD);
        }
        if n>>d&1 == 1{
            res += dfs(d-1, xm, cmp::min(2, am*2), dp, n, MOD);
        }
        else{
            if am != 0 && xm != 0{
                res += dfs(d-1, xm,cmp::min(2, am*2 - 1), dp, n, MOD);
            }
        }
        if am!=0{
            if n>>d&1==1{
                res += dfs(d-1, 1, cmp::min(2, am*2 -1), dp, n, MOD);
            }
            else{
                res += dfs(d-1, xm, cmp::min(2, am*2 - 2), dp, n, MOD);
            }
        }
        dp[d as usize][xm][am] = res%MOD;
        dp[d as usize][xm][am]

    }
    println!("{}", dfs(60, 0, 0, &mut dp, n, MOD));

}



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

int main() {
  int A,B,k;
  cin >> A >> B >> k;
  int m = min(A,B);
  int count = 0;
  for(int i = m ; i >=1 ; i--){
  	if(A % i == 0 && B % i == 0){
    	count++;
    }
    if(count == k){
    	cout << i << endl;
      	break;
    }
  }
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int MOD=1000000007;
#define INF 1LL<<30
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define all(x) (x).begin(),(x).end()

vector<vector<int>> p(26);

int main(){
    string s,t;
    cin>>s>>t;

    int n=s.size();
    int m=t.size();
    rep(i,n){
        p[s[i]-'a'].push_back(i);
    }

    /*
    rep(i,26){
        if(p[i].size()==0) continue;
        rep(j,p[i].size()) cout<<p[i][j]<<" ";
        cout<<endl;
    }*/

    rep(i,m){
        if(p[t[i]-'a'].size()==0){
            cout<<-1<<endl;
            return 0;
        }
    }

    ll ans=0;
    int po=-1;
    rep(i,m){
        int x=t[i]-'a';
        int ind=upper_bound(all(p[x]),po)-p[x].begin();
        //cout<<ind<<" "<<po<<endl;
        if(ind==p[x].size()){
            ans+=n;
            po=p[x][0];
        }
        else{
            po=p[x][ind];
        }
    }
    ans+=po;

    cout<<ans+1<<endl;
}




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

#if DEBUG && !ONLINE_JUDGE
  #include "header.h"
#else
  #define debug(args...)
#endif

typedef vector<int> vi;
typedef pair<int,int> ii;
typedef long long lli;
typedef long double ld;

#define pb push_back
#define all(x) x.begin(),x.end()
#define SZ(x) (int)(x).size()
#define fi first
#define se second
#define lb lower_bound
#define ub upper_bound
#define rep(i,a,b) for(auto i=(a);i<b;i++)

#define INF (int)1e9
#define EPS 1e-9
#define MOD 1000000007
void preprocess(void) {
  return;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.precision(20);
  preprocess();
  lli n, a, b;
  cin>>n>>a>>b;
  cout<<min(n%(a+b),a)+(n/(a+b))*a<<endl;
}



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

int main(){
    long long h, n;
    cin >> h >> n;

    vector<pair<long long, long long> > ab(n);
    
    
    for(long long i = 0; i < n; i++) cin >> ab[i].first >> ab[i].second;

    vector<long long> dp(h+1, 1e9);
    dp[0] = 0;

    for(long long i = 0; i <= h; i++){
        for(long long j = 0; j < n; j++){
            if(i <= ab[j].first) dp[i] = min(dp[i], ab[j].second);
            else dp[i] = min(dp[i], dp[i-ab[j].first] + ab[j].second);
        }
    }
    cout << dp[h] << endl;
    return 0;
}

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

int main(){
   int n;
   cin >> n;
   int f[100][10];
   int p[100][11];
   for (int i = 0; i < n; i++){
     for (int j = 0; j < 10; j++){
       scanf("%d", &f[i][j]);
     }
   }
   for (int i = 0; i < n; i++){
     for (int j = 0; j < 11; j++){
       scanf("%d", &p[i][j]);
     }
   }

   int t[10];
   int c;
   int m = -1e9-10;
   for (int i = 1; i < 1024; i++){
     int u = i;
     for (int k = 0; k < 10; k++){
       t[k] = u % 2;
       u /= 2;
     }
     int v = 0;
     for (int k = 0; k < n; k++){
       c = 0;
       for (int j = 0; j < 10; j++){
         if (t[j] == 1 && f[k][j] == 1) c++;
       }
       v += p[k][c];
     }
     m = max(m, v);
   }
   cout << m << "\n";
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <boost/multiprecision/cpp_int.hpp>

// increment
#define rep_n(_1, _2, _3, NAME, ...) NAME
#define rep_2(i, n) for (int(i) = 0; (i) < (int)(n); ++(i))
#define rep_3(i, initial, n) for (int(i) = (int)(initial); (i) < (int)(n); ++(i))
#define rep(...) rep_n(__VA_ARGS__, rep_3, rep_2, rep_1)(__VA_ARGS__)
// decrement
#define rep_r_n(_1, _2, _3, NAME, ...) NAME
#define rep_r_2(i, n) for (int(i) = (int)(n); (i) > 0; (i)--)
#define rep_r_3(i, initial, n) for (int(i) = (int)(initial); (i) > (int)(n); (i)--)
#define rep_r(...) rep_r_n(__VA_ARGS__, rep_r_3, rep_r_2)(__VA_ARGS__)
// define type definition
using namespace std;
typedef long long ll;
using mpint = boost::multiprecision::cpp_int; // 多倍長整数（任意精度）
typedef pair<int, int> P;

// define construct variable
const double EPS = numeric_limits<double>::epsilon();
// 10^9 + 7
const ll MOD = ll(1e9) + 7;
const ll INF = ll(1e10);
const string ALPHABET = "abcdefghijklmnopqrstuvwxyz";
const double PI = acos(-1);

// define methods
// 最大公約数
ll gcd(const ll a, const ll b) { return b ? gcd(b, a % b) : a; }
// 最小公倍数
ll lcm(const ll a, const ll b) { return a / gcd(a, b) * b; }
// char -> int
int ctoi(char c) { return (int)(c - '0'); }
// 素因数分解
vector< pair<ll, ll> > prime_factorize(ll n)
{
	vector<pair<ll, ll>> p;
	for (ll i = 2; i * i <= n; i++)
	{
		if ((n % i) != 0)
			continue;
		pair<ll, ll> a = make_pair(i, 0);
		while ((n % i) == 0)
		{
			n /= i;
			a.second += 1;
		}
		p.push_back(a);
	}

	if (n != 1)
		p.push_back(make_pair(n, 1));
	return p;
}
// 組み合わせの整合性を保つ（後ほど解析する）
ll modinv(ll a)
{
	ll b = MOD, u = 1, v = 0;
	while (b)
	{
		ll t = a / b;
		a -= t * b;
		swap(a, b);
		u -= t * v;
		swap(u, v);
	}
	u %= MOD;
	if (u < 0)
	{
		u += MOD;
	}
	return u;
}
// 順列
ll permutation(const ll n, const ll m)
{
	ll result = 1;
	for (ll i = n; i > n - m; i--)
	{
		result = (result * i) % MOD;
	}
	return result;
}

// 繰り返し n 乗法
ll repeat_square(const ll n, const ll x)
{
	if (x == 0)
		return 1;
	ll res = repeat_square(n, x / 2);
	res = res * res % MOD;
	if ((x % 2) == 1)
		res = res * n % MOD;
	return res;
}
// 組み合わせ nCm
ll combination(ll n, ll m)
{
	ll p = permutation(n, m);
	ll div = 1;
	for (ll i = 2; i <= m; i++)
	{
		div = (div * i) % MOD;
	}
	return (p * modinv(div)) % MOD;
}

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

	vector<ll> a(N);
	ll total = 0;
	rep(i, N) {
		cin >> a[i];
		total += a[i];
	}

	ll x = 0, ans = 1000000000000000000LL;

	rep(i, N) {
		x += a[i];
		if(i+1 < N) ans = min(ans, abs(total-2*x));
	}

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


Measured memory_bytes: 1792
#pragma GCC optimize("Ofast", "unroll-loops")

#include <bits/stdc++.h>

using namespace std;

#define ll long long
#define ld long double

int main(void){
    int N; cin >> N;
    vector<int> A(N);
    int all_xor = 0;
    for (int i = 0; i < N; ++i){
        cin >> A[i];
        all_xor ^= A[i];
    }
    for (auto ai : A)
        cout << (ai ^ all_xor) << " ";
    cout << endl;
    return 0;
}

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

int main(){
  int n;
  cin >> n;
  vector<int> motis(n);
  for (int i=0; i<n; i++){
    cin >> motis.at(i);
  }
  sort(motis.begin(), motis.end());
  reverse(motis.begin(), motis.end());
  
  int result = 0;
  int tmp;
  for (int i=0; i<n; i++){
    if (i==0){
      result++;
    } else {
      if (tmp>motis.at(i)){
        result++;
      }
    }
    tmp = motis.at(i);
  }
  cout << result << endl;
}

Measured memory_bytes: 256
#include<algorithm>//sort,二分探索,など
#include<bitset>//固定長bit集合
#include<cmath>//pow,logなど
#include<complex>//複素数
#include<deque>//両端アクセスのキュー
#include<functional>//sortのgreater
#include<iomanip>//setprecision(浮動小数点の出力の誤差)
#include<iostream>//入出力
#include<iterator>//集合演算(積集合,和集合,差集合など)
#include<map>//map(辞書)
#include<numeric>//iota(整数列の生成),gcdとlcm(c++17)
#include<queue>//キュー
#include<set>//集合
#include<stack>//スタック
#include<string>//文字列
#include<unordered_map>//イテレータあるけど順序保持しないmap
#include<unordered_set>//イテレータあるけど順序保持しないset
#include<utility>//pair
#include<vector>//可変長配列

using namespace std;
using ll = long long;
// typedef vector<int> v;
template <class T>ostream &operator<<(ostream &o,const vector<T>&v){o<<"{";for(int i=0;i<(int)v.size();i++)o<<(i>0?", ":"")<<v[i];o<<"}";return o;}
#define debug(v) {cerr<<"\033[1;36m[debug]\033[m "<<#v<<" : "<<v<<endl;}
#define rep(i, c) for(int i = 0; i < int(c); i++)
#define ALL(x) (x).begin(), (x).end() //sort(ALL(obj))みたいな
#define SIZE(x) ((ll)(x).size()) //sizeをsize_tからllに直しておく
#define MAX(x) *max_element(ALL(x)) //最大値
#define pb push_back //
// const int MOD = 1000000007;



int main() {
  int s, w;
  cin >> s >> w;
  if (s <= w) cout << "unsafe" << endl;
  else cout << "safe" << endl;

}


Measured memory_bytes: 3128
// #define _GLIBCXX_DEBUG
// #pragma GCC optimize("Ofast")
#pragma GCC diagnostic ignored "-Wsign-compare"
#include <bits/stdc++.h>
// #include <atcoder/all>
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
#define reps(i, s, n) for (int i = s; i < (int)(n); ++i)
using namespace std;
using ll = long long;
template <class T> using V = vector<T>;
template <class T> using VV = V<V<T>>;
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;
}
constexpr int INF = 1e9 + 7;
constexpr ll LINF = 1LL << 60;

int calc(int a) {
    int ret = 0;
    while (a > 0) {
        ret += a % 10;
        a /= 10;
    }
    return ret;
}

void solve() {
    int n;
    cin >> n;
    int ans = 0;
    ans = 1000000;
    for (int i = 1; i + i <= n; i++) {
        int b = n - i;
        int cur = calc(i) + calc(b);
        ans = min(ans, cur);
    }
    cout << ans << "\n";
}
int main() {
    cin.tie(nullptr);
    // ios_base::sync_with_stdio(false);
    // cout << fixed << setprecision(15);
    solve();
}

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

int prime(double a){

  int b;
  b = (int)sqrt(a);

  for (int i = b; i > 0; i--) {

    if (0 == ((int)a % i)) {
      if (1 == i) {
        return 0;
      }else{
        return 1;
        break;
      }
    }else{
      
    }

  }

}

int main(int argc, char const *argv[]) {

  double X, Y;
  scanf("%lf", &X);

  if (0 == ((int)X % 2)) {
    if (2 == (int)X) {
      printf("%.0f\n", X);
      return 0;
    }else{
      X += 1;
    }
  }

  int r = 1;

  while (1 == r) {
    r = prime(X);
    X += 1;
  }
  
  printf("%.0f\n", (X - 1));
  
  return 0;

}


Measured memory_bytes: 128
a, b = map(int, input().split())
# a, bに何種類共通の素因数があるかを調べればよい.
# 試し割り法で、どちらも素因数だと判断されればOK.10^6まで調べればいい.
ans = 1 # 1の分
chk_a = a
chk_b = b
if((a % 2) == 0 and (b % 2) == 0):
    ans += 1
while chk_a % 2 == 0:
    chk_a //= 2
while chk_b % 2 == 0:
    chk_b //= 2
f = 3
checker = max(a, b)
while f * f <= checker:
    if( (chk_a % f) == 0 and (chk_b % f) == 0):
        ans += 1
    while chk_a % f == 0:
        chk_a //= f
    while chk_b % f == 0:
        chk_b //= f
    f += 2
check_min = min(chk_a,chk_b)
if((chk_a % check_min) == 0 and (chk_b % check_min) == 0 and check_min > 1):
    ans += 1
print(ans)


Measured memory_bytes: 38896
#include <stdio.h>
#include<bits/stdc++.h>
using namespace std ;
int main()
{
    int N;
    cin >>N;
        int x;
        int y ;
     x = N *800 ;
     y = ((N/15)*200) ;
    if ( N>15)
    cout <<x-y ;
     if (N==15)
    cout << x -200 ;
    if (N< 15)  
cout << x ;
    return 0;
}

Measured memory_bytes: 256
x, n = map(int, input().split())
if n != 0:
    ppp = list(map(int, input().split()))

    if x not in ppp:
        print(x)
    else:
        for i in range(120):
            if x - i not in ppp:
                print(x-i)
                break
            if x + i not in ppp:
                print(x+i)
                break
else:
    print(x)


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

int n,m;

int main(void){
	scanf("%d%d",&n,&m);
	double per=pow(0.5,m);
	double rest=1.0;
	double ans=0.0;
	double cnt=1.0;
	int all=1900*m+(n-m)*100;
	double miss=1.0-per;
	double res=(double)all/(1.0-miss);
	printf("%d\n",(int)res);
	return 0;
}

Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
const int maxn = 3005;
long long n, k;
long long a[maxn];
long long dp[105][100050], sum[105][100050];
const int MOD = 1e9 + 7;
long long SUM(int i, int l, int r){
    if(l <= 0) return sum[i][r];
    else return sum[i][r] - sum[i][l-1];
}
int main()
{
    cin>>n>>k;
    for(int i = 1; i <= n; i++) cin>>a[i];
    dp[0][0] = 1;
    for(int j = 0; j <= k; j++) sum[0][j] = 1;
    for(int i = 1; i <= n; i++){
        for(int j = 0; j <= k; j++){
            (dp[i][j] += SUM(i-1, j-a[i],j)) %= MOD;
            /*for(int p = 0; p <= j && p <= a[i]; p++){
                (dp[i][j] += dp[i-1][j-p]) %= MOD;
            }*/
        }
        sum[i][0] = dp[i][0];
        for(int j = 1; j <= k; j++) sum[i][j] = sum[i][j-1] + dp[i][j];
    }
    cout<<dp[n][k]<<endl;
}


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

int main(){
  int n;
  cin >> n;
  int a[n];
  rep(i,n)cin >> a[i];
  bool ok = 0;
  rep(i,n)if(a[i]%2==1)ok = 1;
  if(ok)cout << "first" << endl;
  else cout << "second" << endl;
  return 0;
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
 
int main() {
	string s,t;
	cin >> s >> t;
	sort(s.begin(), s.end());
	sort(t.begin(), t.end());
	reverse(t.begin(), t.end());
	
	if (s < t) cout << "Yes" << endl;
	else cout << "No" << endl;
}

Measured memory_bytes: 256
import Control.Applicative
import Control.Monad
import Data.Function
import Data.List
import Data.Ord

factors m = sub m (2:[3,5..])
  where
    sub 1 _ = []
    sub n pa@(p:ps)
      | q < p = [n]
      | r == 0 = p : sub q pa
      | otherwise = sub n ps
      where
        (q, r) = divMod n p

ffc m = map length $ group $ sort $ concat $ map factors [1..m]

solve n =
    lenn 74 + 
    lenn 24 * (lenn 2 - 1) +
    lenn 14 * (lenn 4 - 1) + 
    lenn 4 * (lenn 4 - 1) * (lenn 2 - 2) `div` 2
  where
    fc = ffc n
    lenn t = length $ takeWhile (>=t) fc

main = readLn >>= print . solve

Measured memory_bytes: 636
#include<stdio.h>
#include<vector>
#include<algorithm>
#include<map>
using namespace std;
typedef pair<int, int> P;

const int MOD = 998244353;

const int M = 1 << 20;
int seg[M * 2 - 1];

void init() {    
    for(int i = 0; i < M * 2 - 1; i++) seg[i] = 0;
}

void add(int p, int k, int l, int r) {
    if(r - l == 1) seg[k] += 1;
    else {
        int m = (l + r) / 2;
        if(p < m) add(p, k * 2 + 1, l, m);
        else add(p, k * 2 + 2, m, r);
        seg[k] = seg[k * 2 + 1] + seg[k * 2 + 2];
    }
}

int sum(int a, int b, int k, int l, int r) {
    if(a <= l && r <= b) return seg[k];
    else {
        int m = (l + r) / 2;
        int s = 0;
        if (a < m) s += sum(a, b, k * 2 + 1, l, m);
        if (m < b) s += sum(a, b, k * 2 + 2, m, r);
        return s;
    }
}

P p[200000];
vector<int> xcomp;
vector<int> ycomp;

long long LU[200000];
long long LD[200000];
long long RU[200000];
long long RD[200000];

long long pow[200001];

int main() {
    int n, i;
    scanf("%d", &n);

    xcomp.clear();
    ycomp.clear();
    for(int i = 0; i < n; i++) {
        int x, y;
        scanf("%d %d", &x, &y);
        p[i] = P(x, y);
        xcomp.push_back(x);
        ycomp.push_back(y);
    }

    sort(xcomp.begin(), xcomp.end());
    sort(ycomp.begin(), ycomp.end());
    for(int i = 0; i < n; i++) {
        p[i] = P(
            lower_bound(xcomp.begin(), xcomp.end(), p[i].first) - xcomp.begin(),
            lower_bound(ycomp.begin(), ycomp.end(), p[i].second) - ycomp.begin()
        );
    }

    init();
    sort(p, p + n);
    for(int i = 0; i < n; i++) {
        int y = p[i].second;
        LU[i] = sum(0, y, 0, 0, M);
        LD[i] = sum(y, M, 0, 0, M);
        add(y, 0, 0, M);
    }

    init();
    for(int i = n - 1; i >= 0; i--) {
        int y = p[i].second;
        RU[i] = sum(0, y, 0, 0, M);
        RD[i] = sum(y, M, 0, 0, M);
        add(y, 0, 0, M);
    }

    pow[0] = 0;
    for(int i = 1; i <= n; i++) pow[i] = (pow[i - 1] * 2 + 1) % MOD;

    long long ans = (n * pow[n]) % MOD;
    for(int i = 0; i < n; i++) {
        ans -= pow[LU[i] + RU[i]] + pow[RU[i] + RD[i]]
                + pow[RD[i] + LD[i]] + pow[LD[i] + LU[i]];
        ans += pow[LU[i]] + pow[RU[i]] + pow[RD[i]] + pow[LD[i]];
        ans %= MOD;
    }

    printf("%lld\n", (ans + MOD) % MOD);
    return 0;
}

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

int H,W;
int i,j;

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


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

#define rep(i, n) for(int i = 0; i < (n); i++)
#define repp(i, l, r) for(int i = (l); i < (r); i++)
#define per(i, n) for(int i = ((n)-1); i >= 0; i--)
#define perr(i, l, r) for(int i = ((r)-1); i >= (l); i--)
#define all(x) (x).begin(),(x).end()
#define MOD 1000000007
#define IINF 1000000000
#define LINF 1000000000000000000
#define SP <<" "<<
#define CYES cout<<"Yes"<<endl
#define CNO cout<<"No"<<endl
#define CFS cin.tie(0);ios::sync_with_stdio(false)

typedef long long LL;
typedef long double LD;

int main(){
  while(1){
    int n;
    cin >> n;
    if(n==0) return 0;
    vector<int> a(n);
    string s;
    rep(i,n){
      cin >> s;
      if(s=="x") a[i]=MOD;
      else a[i]=stoi(s);
    }
    int l=-MOD,r=MOD;
    bool ok=true;
    rep(i,n){
      if(i%2){ // v
        if(a[i]==MOD){
          if(i>0) if(a[i-1]!=MOD) l=max(l,a[i-1]+1); else ok=false;
          if(i<n-1) if(a[i+1]!=MOD) l=max(l,a[i+1]+1); else ok=false;
        }else{
          if(i>0) if(a[i-1]!=MOD) if(a[i]<=a[i-1]) ok=false;
          if(i<n-1) if(a[i+1]!=MOD) if(a[i]<=a[i+1]) ok=false;
        }
      }else{ // ^
        if(a[i]==MOD){
          if(i>0) if(a[i-1]!=MOD) r=min(r,a[i-1]-1); else ok=false;
          if(i<n-1) if(a[i+1]!=MOD) r=min(r,a[i+1]-1); else ok=false;
        }else{
          if(i>0) if(a[i-1]!=MOD) if(a[i]>=a[i-1]) ok=false;
          if(i<n-1) if(a[i+1]!=MOD) if(a[i]>=a[i+1]) ok=false;
        }
      }
    }
    if(!ok||r<l) cout << "none" << endl;
    else if(l<r) cout << "ambiguous" << endl;
    else cout << l << endl;
  }
  return 0;
}



Measured memory_bytes: 3056
// #pragma GCC optimize("Ofast")
// #pragma GCC optimize ("unroll-loops")
// #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#include <bits/stdc++.h>
using namespace std;
#ifdef BOI
#include "debug.h"
#else
#define debug(args...)
#endif
#define all(x) begin(x), end(x)
#define sz(x) (int) x.size()
#define eps 1e-7
#define inf 0x3f3f3f3f
typedef long long ll;
typedef long double ld;
#define endl '\n'

int main() {
    cin.tie(0)->sync_with_stdio(0), cin.exceptions(cin.failbit);
#ifdef BOI
    freopen("in.txt", "r", stdin);
    freopen("out.txt", "w", stdout);
#endif
    int a, b; cin >> a >> b;
    int x = log10(b) + 1;
    a *= (int) pow(10, x);
    a += b;
    int temp = sqrt(a);
    if (temp * temp == a) {
        cout << "Yes";
    } else cout << "No";
}


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

using namespace std;

int N, T;
int A[100000];

int main()
{
    scanf("%d%d", &N, &T);
    for(int i=0; i<N; i++)
        scanf("%d", A+i);
    int maxi=0, maxd=0;
    for(int i=N-1; i>=0; i--)
    {
        maxi=max(maxi, A[i]);
        maxd=max(maxd, maxi-A[i]);
    }
    maxi=0;
    int ans=0;
    for(int i=N-1; i>=0; i--)
    {
        maxi=max(maxi, A[i]);
        if(maxd==maxi-A[i])
            ans++;
    }
    printf("%d\n", ans);
    return 0;
}


Measured memory_bytes: 640
import java.util.*;
public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		// 整数の入力
                int n = sc.nextInt();
		int[] a = new int[n];
                for (int i=0; i<n; i++) {
                      a[i] = sc.nextInt();
                }
                Arrays.sort(a);
                System.out.println(a[n-1]-a[0]);
	}
}

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

int main() {

  int x1, x2, x3, x4, x5;
  cin >> x1 >> x2 >> x3 >> x4 >> x5;

  int ans = 1 + 2 + 3 + 4 + 5 - x1 - x2 - x3 - x4 - x5;
  
  cout << ans << endl;
  
  return 0;
  
}

Measured memory_bytes: 3576