akhauriyash/Code-Regression huggingface dataset:
//#include <bits/stdc++.h>
#include <iostream>
#include <algorithm>
using namespace std;
typedef  long long ll ;
const int maxn = 1e3+2,mod=1e9+7;
ll dp[maxn][maxn];
int main() {
    int n,m;
    cin>>n>>m;
    string s[n];
    for(int i=0;i<n;i++)cin>>s[i];
    bool b=1;
    for(int i=0;i<m;i++)
        if(b)
        {
            if(s[0][i]=='.')dp[0][i]=1;
            else b=0;
        }
    b=1;
    for(int i=0;i<n;i++)
        if(b)
        {
            if(s[i][0]=='.')dp[i][0]=1;
            else b=0;
        }
    //
    for(int i=1;i<n;i++)
        for(int j=1;j<m;j++)if(s[i][j]!='#')dp[i][j]=(dp[i-1][j]+dp[i][j-1])%mod;
        cout<<dp[n-1][m-1];
    return 0;
}

Measured memory_bytes: 9088
#include <iostream>
#include <algorithm>
#include <climits>
#include <numeric>
#include <iomanip>
#include <cmath>
#include <vector>
#include <set>
#include <unordered_set>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <unordered_map>
 
#define barsik ios::sync_with_stdio(false)
#define all(x) begin(x), end(x)
#define rall(x) rbegin(x), rend(x)
typedef long long ll;
typedef std::vector<int> vi;
typedef std::pair <int, int> pii;
typedef std::unordered_set <int> u_si;
const double PI = acos(-1);
const long double EPS = 1e-9;
using namespace std;

void solve(){
    int k, s;
    cin >> k >> s;
    int cnt = 0;
    for(int i = 0; i <= k; i++){
        for(int j = 0; j <= k; j++){
            int z = s - i - j;
            cnt += (z >= 0 && z <= k);
        }
    }
    cout << cnt;
}

 
int main() {
    barsik;
    int q = 1;
    //cin >> q;
    while(q--) solve();
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using vi = vector<int>;
using vvi = vector<vector<int>>;
using vl = vector<ll>;
using vvl = vector<vector<ll>>;
#define all(x) x.begin(),x.end()
#define rep(i,j,n) for (long long i = j; i < (long long)(n); i++)
#define _GLIBCXX_DEBUG
#define MOD 1000000007
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; }
//name[i][j]-> vvl name(i,vl(j))
//map<int,int>mp
//余りを切り上げる =>  (a + b - 1) / b 

signed main(){
	vector<char> a(26),b(26);
	rep(i,0,26){
		a[i]='a'+i;
		b[i]='A'+i;
	}
	string ans="";
	vector<string> s(3);
	rep(i,0,3) cin>>s[i];
	rep(i,0,3){
		rep(j,0,26){
			if(a[j]==s[i][0]){
				ans.push_back(b[j]);
			}
		}
	}
	cout<<ans<<endl;
	
	return 0;
}

Measured memory_bytes: 3600
n, m = gets.chomp.split(' ').map{|i| i.to_i }

a = []
b = []
# starts with 1
g = [[]]
m.times{|i|
  a[i], b[i] = gets.chomp.split(' ').map{|j| j.to_i }
  g[a[i]] = [] if g[a[i]].nil?
  g[a[i]].push(b[i])
  g[b[i]] = [] if g[b[i]].nil?
  g[b[i]].push(a[i])
}

# starts with 1
note = [nil, 0]
queue = [1]

while queue.length != 0 do
  nextqueue = []
  queue.each{|from|
    g[from].each{|to|
      # p [from, to, note[from], queue, nextqueue]
      if note[to].nil?
        note[to] = from
        nextqueue.push(to)
      end
    }
  }
  queue = nextqueue
end

puts 'Yes'
(n - 1).times{|i|
  puts note[i + 2]
}


Measured memory_bytes: 34588
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
string s;
ll k;
int main(){
	ios::sync_with_stdio(false);
	cin >> s >> k;
	ll duh=0;
	char c=0;
	ll ans=0;
	for(int i=0; i<s.size() ;i++){
		if(s[i]!=c) duh=0;
		c=s[i];
		duh++;
		ans+=(duh-1)%2*k; 
	}
	int p=0,q=0;
	for(int i=0; i<s.size() ;i++){
		if(s[i]!=s[0]) break;
		duh++;
		p++;
	}
	reverse(s.begin(),s.end());
	for(int i=0; i<s.size() ;i++){
		if(s[i]!=s[0]) break;
		duh++;
		q++;
	}
	if(p==s.size()) ans=s.size()*k/2;
	else if(s[0]==s[s.size()-1]) ans+=(p%2 && q%2)*(k-1);
	cout << ans << endl;
}

Measured memory_bytes: 256
package main

import (
	"fmt"
)

const str = "abcdefghijklmn"

func main() {
	var N int
	fmt.Scanf("%d\n", &N)
	rec("", 0, N)

}

func rec(s string, pos int, max int) {
	if len(s) == max {
		fmt.Println(s)
		return
	}
	for i := 0; i < pos + 1; i ++ {
      	s := s + string([]rune(str)[i])
      if i == pos {
		rec(s, pos+1, max)
      } else {
        rec(s, pos, max)
      }
	}
}

Measured memory_bytes: 6016
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int m = sc.nextInt();
		int n = m % 10;
		if (n == 2 || n == 4 || n == 5 || n == 7 || n == 9) {
			System.out.println("hon");
		} else if (n == 0 || n == 1 || n == 6 || n == 8) {
			System.out.println("pon");
		} else {
			System.out.println("bon");
		}

	}

}

Measured memory_bytes: 27028
def main():
    N, M = map(int, input().split())
    A = list(map(int, input().split()))
    t = A[0] % M
    d = {}
    d[t] = 1
    for i in A[1:]:
        t += i
        t %= M
        if t in d:
            d[t] += 1
        else:
            d[t] = 1
    r = 0
    for i in d:
        r += (d[i] * (d[i] - 1)) // 2
    if 0 in d:
        r += d[0]
    return r
print(main())


Measured memory_bytes: 15020
#include<bits/stdc++.h>
#define sz(x) x.size()
#define all(x) x.begin(),x.end()
#define f(i,a,b) for(int i=a;i<=b;i++)

using namespace std;
typedef unsigned long long ull;
typedef vector<int>vi;
typedef pair<int,int> pii;
typedef map<int,int> mii;
typedef set<int> si;


int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(0);cout.tie(0);
	vector<int>v;
	int g;
	f(i,0,2){
		cin >> g;
		v.push_back(g);
	}
	sort(all(v), greater<int>());
	cout << (v[0] * 10 + v[1] + v[2]) << endl;
	return 0;
	
}


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

const int mod = 998244353;

int arr[maxn], l[maxn], r[maxn], dp[maxn];
int n, k;

int32_t main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    cin >> n >> k;
    for(int i = 0; i < k; i++) {
        cin >> l[i] >> r[i];
    }
    dp[1] = 1;
    for(int i = 2; i <= n; i++) {
        for(int j = 0; j < k; j++) {
            int L = i - r[j];
            int R = i - l[j];
            L = max(1LL, L);
            R = max(0LL, R);
            dp[i] = (dp[i] + dp[R] - dp[L - 1] + mod) % mod;
        }
        if(i != n) dp[i] = (dp[i - 1] + dp[i]) % mod;
    }
    cout << dp[n] << '\n';
    return 0;
}


Measured memory_bytes: 5176
use std::io;

fn main() {
    let seconds = input();

    let hour = seconds / 60 / 60;
    let minute = (seconds - hour * 60 * 60) / 60;
    let second = seconds - hour * 60 * 60 - minute * 60;

    println!("{}:{}:{}", hour, minute, second);
}

fn input() -> i32 {
    let mut s = String::new();
    io::stdin().read_line(&mut s).expect("");

    s.trim().parse().unwrap()
}



Measured memory_bytes: 5036
#include <iostream>
#include <string>
using namespace std;
int main() {
  ios::sync_with_stdio(false);
  string S;
  cin >> S;
  if (S[0] == '7' || S[1] == '7' || S[2] == '7') {
    cout << "Yes"<< endl;
  } else {
    cout << "No"<< endl;
  }
}

Measured memory_bytes: 3652
// 解説、見ました

#include <iostream>
#include <queue>
#include <vector>
#include <cmath>
#include <algorithm>
#include <map>

using namespace std;
using ll = long long;
const ll INF = 1e9;

int N;
ll A, B;
vector<ll> H;

bool decide(ll v) {
    ll sum = 0;
    for (int i = 0; i < N; i++) {
        if (H[i] < B * v) continue;
        sum += ceil((H[i] - B*v) / (double)(A-B));
    }

    return sum <= v;
}

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

    ll l = 0;
    ll r = 1e9;
    while (r - l > 1) {
        ll mid = (l + r) / 2;
        if (decide(mid)) {
            r = mid;
        } else {
            l = mid;
        }
    }

    cout << r << endl;

    return 0;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
#define ll long long

using namespace std;

double p[3030];
double Dp[3030][3030];

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

    for(ll i=0;i<n;i++) scanf("%lf",p+i);

    for(ll H=0;H<=n;H++)
        if(H>n-H)
            Dp[n][H] = 1.0;

    for(ll i=n-1;i>=0;i--)
        for(ll H=0;H<=i;H++)
            Dp[i][H] = p[i]*Dp[i+1][H+1] + (1.0-p[i])*Dp[i+1][H];

    printf("%.10f",Dp[0][0]);
}


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

int main(){
 int A, B, C;
 cin >> A >> B >> C;
  
 if (A == B){
  
  if (B != C){
   cout << "Yes" << endl;
  }
  else{
   cout << "No" << endl;
  }
 }
  
 if (B == C){

  if (C != A){
   cout << "Yes" << endl;
  }
 }

 if (C == A){

  if (A != B){
   cout << "Yes" << endl;
  }
 }
 
 if (A != B && B != C && C != A){
  cout << "No" << endl;
 }
}

Measured memory_bytes: 256
import java.util.*;
import java.io.*;
import static java.util.Arrays.*;
import static java.util.Collections.*;
import static java.lang.Math.*;

public class Main {

	int INF = 1 << 28;
	//long INF = 1L << 62;
	double EPS = 1e-10;
	int[] p, t;
	void run() {
		Scanner sc = new Scanner(System.in);
		for(;;) {
			int n = sc.nextInt();
			if(n == 0) break;
			p = new int[n+1]; t = new int[n+1];
			for(int i=1;i<=n;i++) {p[i] = sc.nextInt(); t[i] = sc.nextInt();}
			
			int[][] dp = new int[n+1][4];
			for(int[] a: dp) fill(a, INF);
			dp[0][0] = 0;
			int i;
			for(i=1;i<=n;i++) {
				for(int j=0;j<4;j++) dp[i][1] = min(dp[i][1], dp[i-1][j] + ( p[i-1] * (j+1) + p[i] <= t[i] - t[i-1]? p[i-1] + p[i]: INF) );
				for(int j=2;j<4;j++) dp[i][j] = min(dp[i][j], dp[i-1][j-1] + (abs(p[i]-p[i-1]) * j <= t[i] - t[i-1]? abs(p[i]-p[i-1]): INF));
				boolean flg = true;
				for(int j=0;j<4;j++) flg &= dp[i][j] == INF;
				if(flg) break;
			}
		
			if(i != n+1) {
				System.out.println("NG " + i);
				continue;
			}
			int ans = INF;
			for(i=0;i<4;i++) ans = min( dp[n][i], ans);
			ans += p[n];
			System.out.println("OK " + ans);
		}
	}

	void debug(Object... os) {
		System.err.println(Arrays.deepToString(os));
	}

	public static void main(String[] args) {
		new Main().run();
	}
}

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

//repetition
#define FOR(i,a,b) for(ll i=(a);i<(b);++i)
#define rep(i, n) for(ll i = 0; i < (ll)(n); i++)

//container util
#define all(x) (x).begin(),(x).end()

//typedef
typedef long long ll;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<ll> VLL;
typedef vector<VLL> VVLL;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef pair<ll, ll> PLL;


//conversion
inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
inline ll toLL(string s) {ll v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}

bool checked[3010][3010];
ll dp[3010][3010];

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n;
    cin >> n;
    VI a(n);
    rep(i,n) cin >> a[i];
    //DP
    FOR(len,1,n+1){
        for(int i = 0; i + len <= n; i++){
            int j = i + len;

            if((n-len) % 2 == 0){
                dp[i][j] = max(dp[i+1][j] + a[i], dp[i][j-1] + a[j-1]);
            }
            else{
                dp[i][j] = min(dp[i+1][j] - a[i], dp[i][j-1] - a[j-1]);
            }
        }
    }
    cout << dp[0][n] << endl;
    //    cout << f(0,n-1) << endl;
    return 0;
}


Measured memory_bytes: 71936
import sys
from collections import deque
#import numpy as np
import math
#sys.setrecursionlimit(10**6)
def S(): return sys.stdin.readline().rstrip()
def SL(): return map(str,sys.stdin.readline().rstrip().split())
def I(): return int(sys.stdin.readline().rstrip())
def IL(): return map(int,sys.stdin.readline().rstrip().split())

def solve():
    exclude = set()
    prime = set()
    for i in range(2,int(math.sqrt(x))+1):
        if i in exclude:
            continue
        prime.add(i)
        j = i
        while j<=math.sqrt(x):
            exclude.add(j)
            j += i
    current = x
    while True:
        for rep in prime:
            if current%rep==0:
                break
        else:
            print(current)
            return
        current += 1
    return

if __name__=='__main__':
    x = I()
    solve()

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

map<int,int> d;

int b[100010],bl=0,ans;

int main(){
	int a,n; cin>>n;
	for(int i=0;i<n;i++){
		cin>>a; int ok=1;
		if(d[a]==0) b[bl++]=a,d[a]++;
		else d[a]++;
	}
	for(int i=0;i<bl;i++){
		if(d[b[i]]>b[i]) ans+=d[b[i]]-b[i];
		else if(d[b[i]]<b[i]) ans+=d[b[i]];
	}
	cout<<ans<<endl;
	return 0;
} 

Measured memory_bytes: 5120
#include<bits/stdc++.h>
using namespace std;
int main()
{
	//code
	int n,m,s=0;
	cin>>n>>m;
	int arr[m];
	
	for(int i=0;i<m;i++)
	{
		cin>>arr[i];
		s+=arr[i];
	}
	if(s>n)
		cout<<-1<<endl;
	else
		cout<<n-s<<endl;
 	return 0;
}



Measured memory_bytes: 3616
#include<bits/stdc++.h>
using namespace std;
const int maxn=300030,mod=998244353;
#define lson o<<1,l,mid
#define rson o<<1|1,mid+1,r
#define FOR(i,a,b) for(int i=(a);i<=(b);i++)
#define ROF(i,a,b) for(int i=(a);i>=(b);i--)
#define MEM(x,v) memset(x,v,sizeof(x))
inline int read(){
	int x=0,f=0;char ch=getchar();
	while(ch<'0' || ch>'9') f|=ch=='-',ch=getchar();
	while(ch>='0' && ch<='9') x=x*10+ch-'0',ch=getchar();
	return f?-x:x;
}
int n,ans=1,cnt[6];
char s[maxn];
int main(){
	n=read();
	scanf("%s",s+1);
	FOR(i,1,3*n) if(s[i]=='R'){
		if(cnt[5]) ans=1ll*ans*cnt[5]%mod,cnt[5]--;
		else if(cnt[1]) ans=1ll*ans*cnt[1]%mod,cnt[1]--,cnt[3]++;
		else if(cnt[2]) ans=1ll*ans*cnt[2]%mod,cnt[2]--,cnt[4]++;
		else cnt[0]++;
	}
	else if(s[i]=='G'){
		if(cnt[4]) ans=1ll*ans*cnt[4]%mod,cnt[4]--;
		else if(cnt[0]) ans=1ll*ans*cnt[0]%mod,cnt[0]--,cnt[3]++;
		else if(cnt[2]) ans=1ll*ans*cnt[2]%mod,cnt[2]--,cnt[5]++;
		else cnt[1]++;
	}
	else if(s[i]=='B'){
		if(cnt[3]) ans=1ll*ans*cnt[3]%mod,cnt[3]--;
		else if(cnt[0]) ans=1ll*ans*cnt[0]%mod,cnt[0]--,cnt[4]++;
		else if(cnt[1]) ans=1ll*ans*cnt[1]%mod,cnt[1]--,cnt[5]++;
		else cnt[2]++;
	}
	FOR(i,1,n) ans=1ll*ans*i%mod;
	printf("%d\n",ans);
}

Measured memory_bytes: 512
//Code by: Nikhil Shukla, MMMUT GKP
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define V vector
#define pb push_back
#define all x x.begin(),x.end()
#define fast() ios_base::sync_with_stdio(false); cin.tie(NULL);
#define tc ll t; cin>>t; while(t--)
#define tc1 ll tt=1; while(tt--)
#define fir first
#define sec second
#define mod 1000000007
#define out1(x) cout<<x<<"\n";
#define out2(x,y) cout<<x<<" "<<y<<"\n";
#define debug() cout<<"I am in\n";
#define Vll vector<long long>
#define FOR(i,x,n) for(ll i=x;i<n;i++)
#define RFOR(i,x,n) for(ll i=x;i>=n;i--)
////////////////////////////////////////////////////////////////////////////////////////
/*vector<ll>graph[100001];
vector<ll>temp;
vector<bool>visited(100001,false);
//long long count=0;
void dfs(long long node,ll dp[])
{
        visited[node]=1;
        for(ll i=0;i<graph[node].size();i++)
        {
            if(!visited[graph[node][i]])
            dfs(graph[node][i],dp);
            dp[node]=max(dp[node],1+dp[graph[node][i]]);
        }
}*/


void solve(ll a[],ll n,ll k)
{
    bool dp[k+1];
    FOR(i,0,k+1)
    dp[i]=false;
    FOR(i,0,k+1)
    {
        FOR(j,0,n)
        {
            if(i-a[j]<0)
            break;
            ll idx=i-a[j];
            if(dp[idx]==false)
            {
                dp[i]=true;
                break;
            }
        }
    }
    if(dp[k]==true)
    cout<<"First\n";
    else
    cout<<"Second\n";
}
int main()
{
    fast()
    tc1
    {
        ll n,k;
        cin>>n>>k;
        ll arr[n];
        FOR(i,0,n)
        cin>>arr[i];
        solve(arr,n,k);
    }
    
    return 0;
}


Measured memory_bytes: 3696
#include<iostream>

using namespace std;

int main() {
	int N;
	cin >> N;
	int a[100000];
	for (int i = 0; i < N; i++)cin >> a[i];
	int tmp = a[0];
	for (int i = 1; i < N; i++) {
		tmp ^= a[i];
	}
	if (tmp == 0)cout << "Yes" << endl;
	else cout << "No" << endl;
	return 0;
}

Measured memory_bytes: 640
#include<iostream>
#include<cstdio>
using namespace std;
int main(){
  int a,b,c;
  while(cin >>a>>b>>c){
    if(a == -1 && b == -1 && c == -1) break;
    int ans=c+b*60+a*60*60,x=2*60*60;
    int r=x-ans;
    printf("%02d:%02d:%02d\n",r/3600,(r/60)%60,r%60);
    r*=3;
    printf("%02d:%02d:%02d\n",r/3600,(r/60)%60,r%60);
  }
  return 0;
}

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

#define repd(i, a, b) for (ll i = (a); i < (b); i++)
#define repb(i, n) for (ll i = (n)-1; i >= 0; i--)
#define rep(i, n) repd(i, 0, n)

using namespace std;

using ll = long long;
using ul = unsigned long long;
ll mod = 1000000007;

void prime_map(map<ll, ll> &m, ll num) {
    for (ll i = 2; i * i <= num; i++) {
        while (num % i == 0) {
            m[i]++;
            num /= i;
        }
    }
    if (num != 1) {
        m[num] = 1;
    }
    return;
}

ll doubling(ll a, ll b) {
    // return a^b
    ll ans = 1;
    ll base = a;
    while (b != 0) {
        if (b & 1) {
            ans *= base;
            ans %= mod;
        }
        base *= base;
        base %= mod;
        b >>= 1;
    }
    return ans;
}

ll mod_inv(ll a, ll m) { return doubling(a, m - 2); }

int main() {
source:
    ll n;
    cin >> n;
    ll a[n];
    rep(i, n) { cin >> a[i]; }
    vector<map<ll, ll>> v(n);
    rep(i, n) { prime_map(v[i], a[i]); }

    map<ll, ll> m;
    rep(i, n) {
        for (auto iter = v[i].begin(); iter != v[i].end(); iter++) {
            m[iter->first] = max(m[iter->first], iter->second);
        }
    }

    ll lcm_mod = 1;
    for (auto iter = m.begin(); iter != m.end(); iter++) {
        rep(i, iter->second) {
            lcm_mod *= iter->first;
            lcm_mod %= mod;
        }
    }

    ll ans = 0;
    rep(i, n) {
        ll temp = lcm_mod * mod_inv(a[i], mod);
        ans += temp;
        ans %= mod;
    }

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



Measured memory_bytes: 3968
import java.util.Scanner;

public class Main{
    public static void main(String args[]){
        Scanner input = new Scanner(System.in);
        int max = input.nextInt();
        output(max);
    }
    
    public static void output(int max){
        String num;
        for(int i = 3; i <= max; i ++){
            num = Integer.toString(i);
            if(i % 3 == 0 || num.contains("3")){
                System.out.print(" " + i);
            }
        }
        System.out.println();
    }
}


Measured memory_bytes: 29444
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
using namespace std;
signed main() {
  ios::sync_with_stdio(false); cin.tie(0);
  int n;
  cin >> n;
  vector<int> in(n), a;
  for (int i = 0; i < n; i++) {
    cin >> in[i];
  }
  a = in;
  sort(a.begin(), a.end());
  int s = a[n / 2 - 1], t = a[n / 2];
  for (int i = 0; i < n; i++) {
    if (in[i] <= s) {
      cout << t << endl;
    } else {
      cout << s << endl;
    }
  }
  return 0;
}

Measured memory_bytes: 3840
#include<stdio.h>
#include<string.h>

int main(void)
{
	
	int n,time;
	char l[50][21];
	int p[50],a[50],b[50],c[50],d[50],e[50],f[50],s[50],m[50];
	double perf[50];
	int rank[50];
	int i,j,tmp;
	
	while(1)
	{
		scanf("%d ",&n);
		if(n==0)break;
		for(i=0;i<n;i++){
			scanf(" %s %d %d %d %d %d %d %d %d %d ",l[i],&p[i],&a[i],&b[i],&c[i],&d[i],&e[i],&f[i],&s[i],&m[i]);
		}
		
		for(i=0;i<n;i++){
			time = a[i] + b[i] + c[i];
			for(j=0;j<m[i];j++){
				time += d[i] + e[i];
			}
			perf[i] = (double)(f[i] * m[i] * s[i] - p[i]) / time;
			rank[i] = i;
		}
		
		for(i=0;i<n-1;i++){
			for(j=n-2;j>=i;j--){
				if(perf[rank[j]]<perf[rank[j+1]]){
					tmp = rank[j];
					rank[j] = rank[j+1];
					rank[j+1] = tmp;
				}else if(perf[rank[j]]==perf[rank[j+1]]){
					if(strcmp(l[rank[j]],l[rank[j+1]]) > 0){
						tmp = rank[j];
						rank[j] = rank[j+1];
						rank[j+1] = tmp;
					}
				}
			}
		}
		
		for(i=0;i<n;i++){
			printf("%s\n",l[rank[i]]);
		}
		printf("#\n");
	}
	return 0;
}

Measured memory_bytes: 0
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <stack>
#include <queue>
#include <list>
#include <set>
#include <map>
#include <numeric>
#include <regex>
#include <tuple>
#include <iomanip>
#include <cmath>
using namespace std;

typedef long long ll;
typedef pair<int, int> P;
#define MOD 1000000007 // 10^9 + 7
#define INF 1000000000 // 10^9
#define LLINF 1LL<<60

vector<vector<int>> G(100009);
bool isfound[100009];

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

	ll N, K; cin >> N >> K;
	for (int i = 0; i < N - 1; i++) {
		int tmp1, tmp2; cin >> tmp1 >> tmp2;
		G[tmp1].push_back(tmp2);
		G[tmp2].push_back(tmp1);
	}

	
	if (N == 1) cout << K << endl;
	else {
		int start = -1;
		queue<int> S; S.push(1);
		isfound[1] = true;
		// スタート地点を探す
		while (start == -1) {
			int cur = S.front();
			S.pop();
			bool flag = false;
			for (int i = 0; i < G[cur].size(); i++) {
				int nxt = G[cur][i];
				if (!isfound[nxt]) { // 未探索なら
					S.push(nxt);
					isfound[nxt] = true;
					flag = true;
				}
			}
			if (!flag) start = cur;
		}


		//cout << "ok1" << endl;
		//cout << "start : " << start << endl;

		for (int i = 1; i <= N; i++) isfound[i] = false;
		ll ans = K * (K - 1);
		ans %= MOD;
		isfound[start] = isfound[G[start][0]] = true;
		queue<int> Q;
		Q.push(G[start][0]);

		//cout << "ok2" << endl;

		while (!Q.empty()) {
			int cur = Q.front();
			Q.pop();
			int cnt = 0; // 次のノードの数

			for (int i = 0; i < G[cur].size(); i++) {
				int nxt = G[cur][i];
				if (!isfound[nxt]) {
					isfound[nxt] = true;
					cnt++;
					Q.push(nxt);
				}
			}

			for (ll i = 1; i <= cnt; i++) {
				ans *= (K - 1 - i);
				ans %= MOD;
			}
		}

		cout << ans << endl;
	}

	return 0;
}

Measured memory_bytes: 7032
package main

import (
	"bufio"
	"fmt"
	"os"
)

const (
	Sunny =  "Sunny"
)
func main() {
	Weather := []string{"Sunny","Cloudy","Rainy"}

	var sc = bufio.NewScanner(os.Stdin)
	sc.Scan()
	inp := sc.Text()

	for i,v := range Weather {
		if inp == v && i != 2{
			fmt.Println(Weather[i+1])
		} else if inp == v && i == 2{
			fmt.Println(Sunny)
		}

	}
}


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

int h, w;
vector<string> mineSweeper;
int countBomAround(int i, int j) {
    int ans = 0;
    for(int di = -1; di < 2; di++) {
        for(int dj = -1; dj < 2; dj++) {

            if(i + di < 0 || i + di >= h)
                continue;
            if(j + dj < 0 || j + dj >= w)
                continue;
            if(mineSweeper[i + di][j + dj] == '#') {
                ans++;
            }
        }
    }
    return ans;
}

int main() {
    // 制約見て！！！デカかったらlong longにすること！
    cin >> h >> w;
    mineSweeper.resize(h);
    rep(i, h) {
        string str;
        cin >> str;
        mineSweeper[i] = str;
    }
    rep(i, h) {
        rep(j, w) {
            if(mineSweeper[i][j] == '#') {
                cout << '#';
            } else {
                cout << countBomAround(i, j);
            }
        }
        cout << endl;
    }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0; i < n; i++)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define ll long long
#define MOD 1000000007
#define MAX 100010
#define aout(a) REP(i,sizeof(a)) cout << a[i] << " "; cout << endl;
#define vout(v) REP(i,v,size()) cout << v[i] << " "; cout << endl;
using namespace std;
using Graph = vector<vector<int>>;
 
int main(){
  ll N; cin>>N;
  string c; cin>>c;
  ll ans = 0;
  bool flag = false;
  int j = N-1;
  REP(i,N){
    if(flag) break;
    if(c[i] == 'R') continue;
    else{
      while(i < j){
        if(c[j] == 'R'){
          ans++;
          //cout<<i<<" "<<j<<endl;
          c[j] = 'W';
          break;
        }
        j--;
        if(i==j) flag = true;
      }
    }
  }
  
  cout<<ans;
}

Measured memory_bytes: 3752
import java.util.*;
 
public class Main{
  public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int M = sc.nextInt();
		double num = 0;
		double total = 0;
		int count = 0;
		int[] number = new int[N];
		for(int i = 0;i < N;i++) {
			int A = sc.nextInt();
			number[i] += A;
			num += A;
			if(i == N-1 && M > 0) {
				total = num / (4 * M);
				for(int j = 0;j < N;j++) {
					if(number[j] >= total) {
						count++;
					}
				}
			}
		}
		if(count >= M && M > 0 ) {
			System.out.println("Yes");
		}else {
			System.out.println("No");
		}
		
	}
}

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

int main() {
  int a,b;
  cin >> a >> b;
  
  int tasu = a + b;
  
  int hiku = a - b;
  
  int kake = a * b;
  
  vector<int> vec;
  vec = {tasu, hiku, kake};
  
  sort(vec.begin(), vec.end());
  reverse(vec.begin(), vec.end());
  
  cout << vec.at(0) << endl;
  
  
}

Measured memory_bytes: 256
fun main(arr:Array<String>) {
    val (n,m) = readLine()!!.split(" ").map { it.toLong() }.sorted()
    if(Math.abs(n-m) >= 2) {
        println(0)
        return
    }
    var ans = 1L
    val md = 1000000000 + 7
    for(i in (0 until n)) {
        ans *= (m-i)
        ans %= md
        ans *= (n-i)
        ans %= md
    }
    if(n == m) {
        ans *= 2
        ans %= md
    }
    println(ans)
}

Measured memory_bytes: 37468
#include <iostream>
#include <vector>
using namespace std;
int ans,used[1000010];
typedef pair<int,int> P;
vector<P>in[1000010];
int n,m;

void check(int pos){
  if(used[pos])return;
  used[pos]=1;
  for(int i=0;i<in[pos].size();i++){
    int nx=in[pos][i].first,idx=in[pos][i].second;
    if(used[nx])continue;
    in[pos].erase(in[pos].begin()+i);
    in[nx].erase(in[nx].begin()+idx);
    check(nx);
    i=-1;
  }
}

int main(){
  while(1){
    cin>>n>>m;
    if(!n&&!m)break;
    for(int i=0;i<1000010;i++)in[i].clear(),used[i]=0;

    ans=0;
    for(int i=0,a,b;i<m;i++){
      cin>>a>>b;
      in[a].push_back(P(b,in[b].size()));
      in[b].push_back(P(a,in[a].size()-1));
      if(in[a].size()>=3||in[b].size()>=3) ans=1;
    }

 
    for(int i=1;i<=n;i++) check(i);
    for(int i=0;i<=n;i++) ans=max(ans,(int)in[i].size());
    cout <<(!ans? "yes":"no")<<endl;
  }
  return 0;
}

Measured memory_bytes: 35612
#include <iostream>
#include <string>
using namespace std;
 
string name[1001];
int eby[1001], wy[1001];
 
int main(){
	name[0] = "Unknown";
	int n, q;
	while(cin >> n >> q, n){
		for(int i = 0; i < n; ++i){
			cin >> name[i] >> eby[i] >> wy[i];
		}
		for(int i = 0; i < q; ++i){
			int ans = -1, x;
			cin >> x;
			for(int j = 0; j < n; ++j){
				if(x <= wy[j] && x > wy[j] - eby[j]){
					ans = j;
					break;
				}
			}
			if(ans == -1){
				cout << "Unknown\n";
			}
			else{
				cout << name[ans] << ' ' << x - wy[ans] + eby[ans] << '\n';
			}
		}
	}
}

Measured memory_bytes: 1308
#include <algorithm>
#include <complex>
#include <cstdlib>
#include <ctime>
#include <time.h>
#include <iomanip>
#include <iostream>
#include <map>
#include <math.h>
#include <queue>
#include <random>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>

using namespace std;
#define SAY_YES cout << "YES" << endl;
#define SAY_Yes cout << "Yes" << endl;
#define SAY_NO cout << "NO" << endl;
#define SAY_No cout << "No" << endl;
#define IFYES(TRUE_OR_FALSE)   \
    if (TRUE_OR_FALSE)         \
    {                          \
        cout << "YES" << endl; \
    }                          \
    else                       \
    {                          \
        cout << "NO" << endl;  \
    }
#define IFYes(TRUE_OR_FALSE)   \
    if (TRUE_OR_FALSE)         \
    {                          \
        cout << "Yes" << endl; \
    }                          \
    else                       \
    {                          \
        cout << "No" << endl;  \
    }
#define IFyes(TRUE_OR_FALSE)   \
    if (TRUE_OR_FALSE)         \
    {                          \
        cout << "yes" << endl; \
    }                          \
    else                       \
    {                          \
        cout << "no" << endl;  \
    }
#define DEBUG_OUTPUT_ARRAY(XXX, ONE)                            \
    for (int i = 0; i < (ONE); i++)                             \
    {                                                           \
        cout << "DEBUG: i = " << i << " -> " << XXX[i] << endl; \
    }
#define DEBUG_OUTPUT_ARRAY2(XXX, ONE, TWO)                             \
    for (int i = 0; i < (ONE); i++)                                    \
    {                                                                  \
        cout << "<<< i = " << i << " >>>" << endl;                     \
        for (int j = 0; j < (TWO); j++)                                \
        {                                                              \
            cout << "DEBUG: j = " << j << " -> " << XXX[i][j] << endl; \
        }                                                              \
    }
#define DEBUG_OUTPUT_ARRAY2_BOX(XXX, ONE, TWO) \
    for (int i = 0; i < (ONE); i++)            \
    {                                          \
        cout << i << "  ";                     \
        for (int j = 0; j < (TWO); j++)        \
        {                                      \
            cout << XXX[i][j] << " ";          \
        }                                      \
        cout << endl;                          \
    }

typedef pair<long long int, long long int> pll;


const long long int mod = 1000000007;
const long long int INF = 99999999999999999;



long long int N,M,K,H,W,A[35]={1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51};

int main()
{
    cout << fixed << setprecision(18);
    cin>>H>>W;
    if(H==1||W==1){
        cout<<1<<endl;
    }else{
    cout<<(H*W+1)/2<<endl;
    }
}


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

using namespace std;

int main() {
  int n, k;
  cin >> n >> k;
  if (k == 1) {
    puts("0");
    return 0;
  }
  int low = 1, high = n - (k-1);
  printf("%d\n",high - low);
  return 0;
}


Measured memory_bytes: 256
#ABC127_C
N,M=map(int,input().split())

L=[]
R=[]

for i in range(M):
    l,m=map(int,input().split())
    L.append(l)
    R.append(m)

if min(R)<max(L):
    print(0)
else:
    print(min(R)-max(L)+1)

Measured memory_bytes: 10996
n    = gets.to_i
ary  = gets.split.map(&:to_i)
aryC = Array.new(1E5 + 10, 0)
max  = 0

ary.each do |i|
  aryC[i] += 1
  max = [max, i].max
end

ans  = 0

for i in 0 .. max
  ans = [ans, aryC[i] + aryC[i + 1] + aryC[i + 2]].max
end

puts ans


Measured memory_bytes: 11524
#include "bits/stdc++.h"
using namespace std;
typedef long long LL;
LL W[100000];
struct UnionFind {
	int *par;
	int *rank;
	vector<vector<int>> group;
	UnionFind(int n) {
		par = new int[n];
		rank = new int[n];
		group = vector<vector<int>>(n, vector<int>());
		for (int i = 0; i < n; i++) {
			group[i].push_back(i);
			par[i] = i;
			rank[i] = 0;
		}
	}
	int find(int x) {
		if (x == par[x]) return x;
		return par[x] = find(par[x]);
	}
	void unite(int x, int y) {
		x = find(x);
		y = find(y);
		if (x == y) return;
		if (rank[x] < rank[y]) {
			par[x] = y;
			for (int i = 0; i < group[x].size(); i++) {
				group[y].push_back(group[x][i]);
			}
			group[x].clear();
		}
		else {
			par[y] = x;
			for (int i = 0; i < group[y].size(); i++) {
				group[x].push_back(group[y][i]);
			}
			group[y].clear();
			if (rank[x] == rank[y]) rank[x]++;
		}
	}
	bool same(int x, int y) {
		return find(x) == find(y);
	}
	int count(int x) {
		return group[find(x)].size();
	}
};
int main() {
	int N, M;
	while (cin >> N >> M, N) {
		UnionFind U(N);
		fill(W, W + N, 0);
		for (int i = 0; i < M; i++) {
			char type[2];
			int a, b, w;
			cin >> type;
			if (type[0] == '?') {
				cin >> a >> b;
				a--; b--;
				if (!U.same(a, b)) {
					cout << "UNKNOWN" << endl;
					continue;
				}
				cout << W[b] - W[a] << endl;
			}
			else {
				cin >> a >> b >> w;
				a--; b--;
				if (U.same(a, b)) continue;
				if (U.count(a) <= U.count(b)) {
					LL diff = (W[b] - w) - W[a];
					a = U.find(a);
					for (int j = 0; j < U.group[a].size(); j++) {
						W[U.group[a][j]] += diff;
					}
				}
				else {
					LL diff = (W[a] + w) - W[b];
					b = U.find(b);
					for (int j = 0; j < U.group[b].size(); j++) {
						W[U.group[b][j]] += diff;
					}
				}
				U.unite(a, b);
			}
		}
	}
}


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

int main()
{
    int N, K, X, Y;
    cin >> N;
    cin >> K;
    cin >> X;
    cin >> Y;

    int ans = 0;
    if (N > K)
    {
        ans = K * X + (N - K) * Y;
    }
    else
    {
        ans = N * X;
    }
    cout << ans << endl;
    return 0;
}

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

int main(){
    int N;cin>>N;
    vector<int> b(N-1);
    for(int i=0;i<N-1;i++){
        cin>>b.at(i);
    }

    vector<int> a(N);
    a.at(0)=b.at(0);
    a.at(N-1)=b.at(N-2);
    for(int i=1;i<N-1;i++){
        a.at(i)=min(b.at(i-1),b.at(i));
    }

    int ans=accumulate(a.begin(),a.end(),0);
    cout<<ans<<endl;
    
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = int64_t;
#define rep(i,n) for(int i = 0; i < ((int)(n)); i++)   // 0-indexed昇順

int main() {
    string X; cin >> X;
    ll res = 0;
    rep(i,X.size()) res += X[i] - '0';
    if (res % 9 == 0) {
        cout << "Yes" << endl;
    } else {
        cout << "No" << endl;    
    }
}


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

using namespace std;
using namespace boost::multiprecision;

#define REP(i, n) for (int i = 0; i < (int)(n); i++)
#define ALL(x) (x).begin(),(x).end()
inline cpp_int between(cpp_int n, cpp_int x) {
  if(n >= 0)
    return (n/x)+1;
  else
    return 0;
}

int main () {
  cpp_int a, b, x;
  cin >> a >> b >> x;
  if(a == 0) cout << between(b,x) << endl;
  else {
    cout << between(b,x) - between(a-1,x) << endl;
  }
  return 0;
}


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

int main(){
  	int H, W;
  	vector<vector<char>> image;
  	char temp;
  
  	cin >> H >> W;
  
  	for(int i = 0;i < H; i++){
      	image.push_back({});
		for(int j = 0;j < W; j++){
          	cin >> temp;
          	image.at(i).push_back(temp);
        }
    }
  
  	for(int i = 0;i < H+2; i++){
      	for(int j = 0;j < W+2; j++){
          	if(i == 0 || i == H+1 || j == 0 || j == W+1){
              	cout << '#';
            }
          	else{
              	cout << image.at(i-1).at(j-1);
            }
        }
      	cout << endl;
    }
}

Measured memory_bytes: 256
N = int(input())
A = sorted(list(map(int, input().split())))
Amax = max(A)

ans = [False] * (Amax + 1)
for x in A:
    for j in range(x, Amax + 1, x):
        ans[j] += 1

print(sum(ans[i] == 1 for i in A))


Measured memory_bytes: 32252
O = input()
E = input()
ans = ''
if len(O) > len(E):
    ans += O[0]
    O = O[1:]
    for o, e in zip(O, E):
        ans += (e + o)
else:
    for o, e in zip(O, E):
        ans += (o + e)
print(ans)

Measured memory_bytes: 3060
def Round(ip, dg):  # ip???dg?????§?????¨?????\????????¢??°
    ip = ip / 10**dg
    if(ip-int(ip) != 0):
        return (int(ip) + 1)*10**dg
    else:
        return int(ip)*10**dg


n=int(input())
sum=100000
for i in range(0, n):
    sum=Round(sum*1.05, 3)
print(sum)

Measured memory_bytes: 7780
#include <bits/stdc++.h>
#define max(x, y) ((x) > (y) ? (x) : (y))
#define min(x, y) ((x) < (y) ? (x) : (y))
#define rep(i,a,m) for((i) = (a) ; (i) < (m) ; ++(i))
#define REP(i,n) for((i)=0;(i)<(int)(n);(i)++)
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define all(x) x.begin(),x.end()
#define rall(x) x.end(),x.begin()
#define sz(x) ((int)x.size())
using namespace std;
/*
#ifdef JUDGE
#include <fstream>
std::ifstream cin("input.txt");
std::ofstream cout("output.txt");
#else
#include <iostream>
using std::cin;
using std::cout;
#endif
*/
typedef unsigned long long ull;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vi> vvi;
typedef vector<vl> vvl;
typedef pair<int,int> pi;
int a, b, c, i, j, k;
long long ans = 0LL;
long double eps = 1.0E-14;
long long MOD = 1000000007;
int main ()
{
	ios::sync_with_stdio(0);
	cin.tie(0);
	int t,T;
    string str;
	cin >> str;	
    if (find(all(str), '7') != str.end()) {
        cout << "Yes\n";
    } else {
        cout << "No\n";
    }
	
	return 0;
}

Measured memory_bytes: 3672
#include <stdio.h>

int main(){
	int m,d;
	int date[12]={31,29,31,30,31,30,31,31,30,31,30,31};
	while(scanf("%d %d",&m,&d)!=EOF){
		int i,sum=-1;
		if(m==0) break;
		for(i=0;i<m-1;i++) sum += date[i];
		sum+=d;
		int r = sum%7;
		char *day;
		switch(r){
		case 0:
			day = "Thursday";
		break;
		case 1:
			day = "Friday";
		break;
		case 2:
			day = "Saturday";
		break;
		case 3:
			day = "Sunday";
		break;
		case 4:
			day = "Monday";
		break;
		case 5:
			day = "Tuesday";
		break;
		case 6:
			day = "Wednesday";
		break;
		}
		printf("%s\n",day);
	}
	return 0;
}

Measured memory_bytes: 580
#include <bits/stdc++.h>
using namespace std;
long sum(long x,long y){
    return (x+y)*(x-y+1)/2;
}
int main(void){
    long total = 0;
    long a; cin >> a;
    for(long i=1;i<(long)(a/2)+1;i++){
        long b = a/i;
        total += i*(b*(b+1)/2);
     }
    total += sum(a,(long)(a/2)+1);
    cout << total << endl;
}

Measured memory_bytes: 3636
import java.util.*;
 
public class Main {
	static Scanner scanner = new Scanner(System.in);
 
	public static void main(String[]$) {
		long k = scanner.nextLong();
		long ans = 0;
		long add = 1;
		for (int i = 0; i < k; i++) {
			long next = ans + add * 10;
			ans += add;
			if (ans * sum(next) > next * sum(ans)) {
				ans = next;
				add *= 10;
			}
			System.out.println(ans);
		}
	}

	static int sum(long n) {
		int sum = 0;
		while (n != 0) {
			sum += n % 10;
			n /= 10;
		}
		return sum;
	}
}

Measured memory_bytes: 21716
#include <cstdio>
#include <cstdlib>
#include <cstring>

using namespace std;

struct Node
{
	int key;
	Node *prev, *next;
};

Node *nil;

void init()
{
	nil = (Node *)malloc(sizeof(Node));
	nil->next = nil;
	nil->prev = nil;
}

void insert(int key)
{
	Node *x = (Node *)malloc(sizeof(Node));
	x->key = key;
	x->next = nil->next;
	nil->next->prev = x;
	nil->next = x;
	x->prev = nil;
}

Node* listsearch(int key)
{
	Node *cur = nil->next;
	while(cur != nil && cur->key != key)
	{
		cur = cur->next;
	}
	return cur;
}

void deleteNode(Node *t)
{
	if(t == nil)
	{
		return ;
	}
	t->next->prev = t->prev;
	t->prev->next = t->next;
	free(t);
}

void deleteFirst()
{
	deleteNode(nil->next);
}

void deleteLast()
{
	deleteNode(nil->prev);
}

void deleteKey(int key)
{
	deleteNode(listsearch(key));
}

void print()
{
	int j = 0;
	Node *cur = nil->next;
	while(1)
	{
		if(cur == nil)
		{
			break;
		}
		if(j++ > 0)
		{
			printf(" ");
		}
		printf("%d", cur->key);
		cur = cur->next;
	}
	putchar('\n');
}

int main()
{
	char com[20];
	int n, i, key;
	init();
	scanf("%d", &n);
	for(i = 0; i < n; i++)
	{
		scanf("%s %d", com, &key);
		if(com[0] == 'i')
		{
			insert(key);
		}
		else
		{
			if(com[6] == 'L')
			{
				deleteLast();
			}
			else if(com[6] == 'F')
			{
				deleteFirst(); 
			}
			else
			{
				deleteKey(key);
			}
		}
	}
	print();
	
	return 0;
}


Measured memory_bytes: 33820
#![allow(unused_imports)]
#![allow(dead_code)]

use std::collections::*;

fn main() {
    let (r, w) = (std::io::stdin(), std::io::stdout());
    let mut sc = IO::new(r.lock(), w.lock());
    let n: usize = sc.read();
    let a: usize = sc.read();
    let x: Vec<usize> = sc.vec(n);
    let init = (0..n + 1)
        .map(|i| {
            (0..2501)
                .map(|j| if i == 0 && j == 0 { 1 } else { 0 })
                .collect()
        })
        .collect::<Vec<Vec<usize>>>();
    let dp = x.iter().fold(init, |acc, &x| {
        (0..n + 1)
            .map(|num_cards| {
                (0..2501)
                    .map(|sum| {
                        if num_cards == 0 || sum < x {
                            acc[num_cards][sum]
                        } else {
                            acc[num_cards][sum] + acc[num_cards - 1][sum - x]
                        }
                    })
                    .collect()
            })
            .collect::<Vec<Vec<usize>>>()
    });
    let mut ans = 0;
    for i in 1..n + 1 {
        for j in 0..2501 {
            if i * a == j {
                ans += dp[i][j];
            }
        }
    }
    println!("{}", ans);
}

pub struct IO<R, W: std::io::Write>(R, std::io::BufWriter<W>);

impl<R: std::io::Read, W: std::io::Write> IO<R, W> {
    pub fn new(r: R, w: W) -> IO<R, W> {
        IO(r, std::io::BufWriter::new(w))
    }
    pub fn write<S: ToString>(&mut self, s: S) {
        use std::io::Write;
        self.1.write(s.to_string().as_bytes()).unwrap();
    }
    pub fn read<T: std::str::FromStr>(&mut self) -> T {
        use std::io::Read;
        let buf = self
            .0
            .by_ref()
            .bytes()
            .map(|b| b.unwrap())
            .skip_while(|&b| b == b' ' || b == b'\n' || b == b'\r' || b == b'\t')
            .take_while(|&b| b != b' ' && b != b'\n' && b != b'\r' && b != b'\t')
            .collect::<Vec<_>>();
        unsafe { std::str::from_utf8_unchecked(&buf) }
            .parse()
            .ok()
            .expect("Parse error.")
    }
    pub fn vec<T: std::str::FromStr>(&mut self, n: usize) -> Vec<T> {
        (0..n).map(|_| self.read()).collect()
    }
    pub fn chars(&mut self) -> Vec<char> {
        self.read::<String>().chars().collect()
    }
}

Measured memory_bytes: 6396
n = int(input())
a = map(int,input().split())
two = 0
one = 0
for i in a :
    if i % 4 == 0:
        two += 1
    elif i % 2 == 0:
        one += 1
zero = n - one - two
if one % 2 == 1:
    one -= 1
    zero += 1
if two+1 >= zero:
    ans = "Yes"
else:
    ans = "No"
print (ans)

Measured memory_bytes: 12176
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <cstdio>
#include <complex>
#include <numeric>
#include <string.h>
#include <random>
#define rep(i,n) for (int i = 0; i < (int)n; i++)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pi;
typedef pair<pi, pi> pp;
typedef pair<ll, ll> pl;
double PI = 3.141592653589793238462643383279;
const double EPS = 1e-9;
const ll MOD = 1000000007;
const int inf = 1 << 30;
const ll linf = 1LL << 60;

ll N, K;
int A[200000];
int F[200000];

int main() {
    cin >> N >> K;
    rep(i,N) cin >> A[i];
    rep(i,N) cin >> F[i];
    sort(A, A+N);
    sort(F, F+N, greater<ll>());
    ll st = -1, en = linf;
    while (en-st > 1) {
        ll mid = (st+en) / 2;
        ll c = 0;
        rep(i,N) {
            ll t = mid / F[i];
            c += max(0LL, A[i]-t);
        }
        if (c > K) st = mid;
        else en = mid;
    }
    cout << en << endl;
}

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

using namespace std;

int n;

int main() {
	//freopen("input.txt", "r", stdin);
	//freopen("output.txt", "w", stdout);

	cin >> n;
	cout << (n % 1000 == 0 ? 0 : 1000 - (n % 1000)) << endl;
}


Measured memory_bytes: 3632
import sys
def input(): return sys.stdin.readline().rstrip()

def main():
    k, x = map(int, input().split())
    ans = [x]
    for i in range(1, k):
        ans.append(x+i)
        ans.append(x-i)
    ans = filter(lambda x: -1000000 <= x <= 1000000, ans)
    print(*sorted(ans))

if __name__ == '__main__':
    main()

Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
using ll= long long;
using vi= vector<int>;
using vvi= vector<vi>;
using vd= vector<double>;
#define REP(i,x,n) for(int i=x; i<n; i++)
#define rep(i,n) REP(i,0,n)
#define all(x) x.begin(), x.end()

int main(){
  int n;
  cin >> n;
  vd v(n);
  rep(i,n)  cin >> v[i];

  sort(all(v));

  REP(i,1,n){
    v[i]= (v[i-1]+v[i])/2;
  }
  cout << v[n-1] << endl;
}

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

int main() {
  int n, wlimit;
  cin >> n >> wlimit;
  vector<int> w(n), v(n);
  for (int i = 0; i < n; i++) cin >> w.at(i) >> v.at(i);
  vector<vector<long>> dp(n + 1, vector<long>(100001, wlimit + 1));
  dp.at(0).at(0) = 0;
  for (int i = 0; i < n; i++) {
    for (int j = 0; j <= 100000; j++) {
      if (j >= v.at(i)) {
        dp.at(i + 1).at(j) = min(dp.at(i).at(j), dp.at(i).at(j - v.at(i)) + w.at(i));
      } else {
        dp.at(i + 1).at(j) = dp.at(i).at(j);
      }
    }
  }
  for (int i = 100000; i >= 0; i--) {
    if (dp.at(n).at(i) <= wlimit) {
      cout << i << endl;
      return 0;
    }
  }
}


Measured memory_bytes: 80256
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <iostream>
#include <iterator>
#include <map>
#include <set>
#include <stack>
#include <string>
#include <tuple>
#include <vector>

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


ull E = 1000000007;
ull e = 10007;
const double pi = 3.14159265359;


int main() {
    int N, M;
    cin >> N >> M;
    map<int, int> cnt;
    for (int i = 0; i < N; ++i) {
        int K;
        cin >> K;
        for (int j = 0; j < K; ++j) {
            int a;
            cin >> a;
            ++cnt[a];
        }
    }
    int ans = 0;
    for (auto&& it : cnt) {
        if (it.second == N) {
            ++ans;
        }
    }
    cout << ans << endl;
}


Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>
#include <string>
#include <iostream>
#include <utility>
#include <algorithm>
#include <vector>
#include <list>
#include <stack>
#include <queue>
#include <unordered_map>
#include <map>
#include <set>
#include <tuple>
#include <cassert>
using namespace std;
using ll = long long;
const int mod = 1e9 + 7;

//通行可能をtrueとする
constexpr char WallCharacter = '#';
vector<vector<bool>> read_grid_map(ll H, ll W)
{
    vector<vector<bool>> grid(H, vector<bool>(W));
    char c;
    scanf("%c", &c);
    for (ll i = 0; i < H; i++)
    {
        char c;
        for (ll j = 0; j < W; j++)
        {
            scanf("%c", &c);
            grid[i][j] = (c != WallCharacter);
        }
        scanf("%c", &c);
    }
    return grid;
}

struct movable_grid
{
    ll cost;
    pair<ll, ll> relative;
};

vector<vector<ll>> bfs_grid_shotest_path(vector<vector<bool>> gridmap, pair<ll, ll> start, list<movable_grid> searchgrid)
{
    const ll first_edge = gridmap.size();
    const ll second_edge = gridmap[0].size();

    priority_queue<pair<ll, pair<ll, ll>>, vector<pair<ll, pair<ll, ll>>>, greater<pair<ll, pair<ll, ll>>>> nexts;
    nexts.push({0, {start.first, start.second}});
    vector<vector<ll>> mincostmap(first_edge, vector<ll>(second_edge, __LONG_LONG_MAX__));
    while (!nexts.empty())
    {
        auto current = nexts.top();
        nexts.pop();
        for (auto &&grid : searchgrid)
        {
            pair<ll, ll> currentpos = current.second;
            currentpos.first += grid.relative.first;
            currentpos.second += grid.relative.second;
            ll cost = current.first;
            if (currentpos.first < 0 || currentpos.second < 0 || currentpos.first >= first_edge || currentpos.second >= second_edge)
                continue;

            if (!gridmap[currentpos.first][currentpos.second])
                continue;

            cost += grid.cost;
            if (mincostmap[currentpos.first][currentpos.second] > cost)
            {
                mincostmap[currentpos.first][currentpos.second] = cost;
                nexts.push({cost, {currentpos.first, currentpos.second}});
            }
        }
    }

    return mincostmap;
}

int main()
{
    ll H, W;
    ll CH, CW;
    ll DH, DW;
    scanf("%lld", &H);
    scanf("%lld", &W);
    scanf("%lld", &CH);
    scanf("%lld", &CW);
    scanf("%lld", &DH);
    scanf("%lld", &DW);
    CH--;
    CW--;
    DH--;
    DW--;

    vector<vector<bool>> mazemap = read_grid_map(H, W);

    ll ans = 127;
    if (!mazemap[CH][CW])
    {
        ans = -1;
        printf("%lld\n", ans);
        return 0;
    }

    list<movable_grid> movable;
    for (ll i = -2; i < 3; i++)
    {
        for (ll j = -2; j < 3; j++)
        {
            ll cost;
            if (abs(i) > 1 || abs(j) > 1 || abs(i) == abs(j))
                cost = 1;
            else
                cost = 0;
            movable.push_back({cost, {i, j}});
        }
    }

    vector<vector<ll>> depthmap = bfs_grid_shotest_path(mazemap, {CH, CW}, movable);
    ans = depthmap[DH][DW];
    if (ans == __LONG_LONG_MAX__)
        ans = -1;
    printf("%lld\n", ans);
}


Measured memory_bytes: 12084