akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
using namespace std;

#define ordered_set tree<ll, null_type,less<ll>, rb_tree_tag,tree_order_statistics_node_update>
#define ll long long
#define ull unsigned long long
#define N 100005
#define mod 1000000007
//#defint mod 1e18
#define boost ios_base::sync_with_stdio(false);cin.tie(0)
#define prec(n) fixed<<setprecision(n)

#define mii unordered_map<int,int>
#define mll unordered_map<ll,ll>
#define pii pair<int,int>
#define pll pair<ll,ll>
#define fi  first

#define se second
#define pb push_back
#define mp make_pair
#define pp pop_back
#define vii vector<int>
#define vll vector<ll>
#define vpp vector<pii>
#define all(c) c.begin(),c.end()
#define tr(it,c) for(it = c.begin() ; it!=c.end() ; it++)
int inf = INT_MAX ;
ll modulo(ll num,ll MOD=mod){ return ((num%MOD)+MOD)%MOD;} // for negative integer
ll power(ll b,ll e,ll MOD=mod){ll ans=1; while(e){if(e%2) ans=(ans*b)%MOD; b=(b*b)%MOD; e/=2;} return ans;}
ll inv(ll num,ll MOD=mod){ return power(modulo(num),MOD-2,MOD); }
ll gcd(ll a,ll b){ return ((b==0) ? a:gcd(b,a%b));}
int dp[N];

int main(){
	boost;
	
	int n,k;
	cin>>n>>k;
	int arr[n];
	for(int i = 0;i<n;i++){
		cin>>arr[i];
	}
	
	for(int i = 1;i<=k;i++){
		int flag = 0;
		if(i==1){
			for(int j = 0;j<n;j++){
				if(arr[j] == i)
					flag++;
			}
		}else{
			for(int j = 0;j<n;j++){
				if(arr[j] == i){
					flag++;
				}else if(i>arr[j]){
					if(dp[i-arr[j]]==0)
						flag++;
				}
			}
		}
		
		if(flag>0){
			dp[i] = 1;
		}else{
			dp[i] = 0;
		}
	}
	
	
	if(dp[k]==1)
		cout<<"First";
	else
		cout<<"Second";
	return 0;
}

//Total solved problems:- 13



Measured memory_bytes: 640
#include <string>
#include <vector>
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cstdlib>
#include<sstream>
#include<functional>
#include<map>
#include<set>
#include<cmath>

using namespace std;

int main(){

	int n;
	cin >> n;

	int a[n*(n-1)/2][4];
	for(int i=0;i<n*(n-1)/2;i++)
	cin >> a[i][0] >> a[i][1] >> a[i][2] >> a[i][3];

	vector<int>v(n,0);

    for(int i=0;i<n*(n-1)/2;i++){
	if(a[i][2]>a[i][3]) v[a[i][0]-1]+=3;
	if(a[i][2]==a[i][3]){ v[a[i][0]-1]+=1; v[a[i][1]-1]+=1; }
	if(a[i][2]<a[i][3]) v[a[i][1]-1]+=3;
    }

	vector<int>u;  u=v;

	sort(v.begin(),v.end(),greater<int>());

	for(int i=0;i<n;i++){
	for(int j=0;j<n;j++){
	if(u[i]==v[j]){ cout << j+1 << endl; break; }
 	}
	}

    return 0;

}

Measured memory_bytes: 1292
import sys
def input(): return sys.stdin.readline().rstrip()
def main():
    n=int(input())
    H=list(map(int,input().split()))
    dp=[-1]*n #足湯iに着くまでに支払うコストの総和の最小値
    dp[0]=0
    for i in range(n):
        for j in (1,2):
            ni=i+j
            if ni>=n:continue
            if dp[ni]==-1:
                dp[ni]=dp[i]+abs(H[ni]-H[i])
            else:
                dp[ni]=min(dp[ni],dp[i]+abs(H[ni]-H[i]))
    print(dp[n-1])


if __name__=='__main__':
    main()

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

int main() {
 UL N; cin>>N;
 UL ans[4]={};
 string vd[4]={"AC","WA","TLE","RE"};
 rep(i,N){
  string S; cin>>S;
  rep(j,4) if(S==vd[j]) ans[j]++;
 }
 rep(i,4){
  cout<<vd[i]<<" x "<<ans[i]<<endl;
 }
 return 0;
}



Measured memory_bytes: 3620
import java.util.Scanner;


public class Main {

	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ
		
		Scanner sc = new Scanner(System.in);
		
		while (sc.hasNext()) {

			int num = sc.nextInt();
			int prime_count = 0;
			
			int [] array = new int[num+1];
			
			for(int i=2; i<=num; i++){
				array[i] = 0;
			}
	
			for(int i=2; i<=num; i++){
				if(array[i] == 1) ;
				else{
					for(int j=i+i; j<=num; j=j+i){
						array[j] = 1;
					}
				}
			}
		
			for(int i=2; i<=num; i++){
				if(array[i] == 0) prime_count++;
			}
			System.out.println(prime_count);	
		}
	}
}

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

using namespace std;

int main()
{

    int n, v;
    cin >> n;

    int a[10050] = {0};

    for (size_t i = 1; i <= 104; i++)
    {
        for (size_t j = 1; j <= 104; j++)
        {
            for (size_t k = 1; k <= 104; k++)
            {
                v = i*i + j*j + k*k + i*j + j*k + i*k;
                if(v < 10050)
                    a[v]++;
            }
        }
    }

    for (size_t i = 0; i < n; i++)
    {
        cout << a[i + 1] << "\n";
    }
    
    return 0;
}

Measured memory_bytes: 3660
N = int(input())
TXY = [tuple(map(int,input().split())) for i in range(N)]

ct = cx = cy = 0
for t,x,y in TXY:
    dt = t-ct
    d = abs(cx-x)+abs(cy-y)
    if dt < d or dt%2 != d%2:
        print('No')
        exit()
    ct,cx,cy = t,x,y
print('Yes')

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

int main() {
	
	ll h; cin >> h;
	ll tmp = h;
	ll cnt = 0;
	while (0 < tmp ) {
		tmp /= 2;
		cnt++;
	}
	ll ans = 1;
	while (cnt--) {
		ans *= 2;
	}
	ans -= 1;
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
 
#define rep(i,n) for(int i=0;i<(n);i++)
#define reps(i,n) for(int i=1;i<=(n);i++)
#define lol long long
#define SUM(n) ((n)+1)*(n)/2 //1〜nまでの総和を求める式
#define mp make_pair
#define fi first
#define se second
#define pu push_back
#define SYOU(x) fixed<<setprecision(x+1) //小数点桁数を指定する
#define abs(x,y) max(x,y)-min(x,y)
#define all(v) v.begin(),v.end()
#define UPDight(a,b) (a+b-1)/b //小数点切り上げ 
const int INF = 0x3f3f3f3f;
const long long LINF = 0x3f3f3f3f3f3f3f3fLL;
const int MOD=int(1e9)+7; 
using namespace std;
using pii = pair<int, int>;
typedef vector<int> vit;

//最大公約数
lol gcd(lol x, lol y){
  if(x < y) swap(x, y);
  lol r = x % y;
  while(r != 0){
    x = y;
    y = r;
    r = x % y;
  }
  return y;
}

//最小公倍数
lol lcm(lol x, lol y){
  lol a = x * y;
  return (a / gcd(x, y));
}

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

  int a, b, ans = 0;
  cin >> a >> b;
  for(int i = a;i <= b;i ++){
    int memo = i;
    if(memo % 10 == memo / 10000 && memo % 10000 / 1000 == memo / 10 % 10){
      //cout << i << " ";
      ans ++;
    }
  }
  cout << ans << '\n';
  return 0;
}


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



int main() {
    int a,b,c,d;
    cin >> a >> b >> c >>d;
    if(min(b,d)-max(a,c)>=0){
    cout << min(b,d)-max(a,c) << endl;}
    else cout << 0 << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <tuple>
#include <map>
#include<set>
#include <cmath>
#include <stack>
using namespace std;


int main() {
    stack<int> st;
    string c;
    int a, b;
    while (cin >> c) {
        if (c == "+") {
            a = st.top();st.pop();
            b = st.top();st.pop();
            st.push(a + b);
        }
        else if (c == "-") {
            a = st.top();st.pop();
            b = st.top();st.pop();
            st.push(b - a);
        }
        else if (c == "*") {
            a = st.top();st.pop();
            b = st.top();st.pop();
            st.push(a * b);
        }
        else {
            st.push(stoi(c));
        }
    }
    cout << st.top() << endl;
}


Measured memory_bytes: 3160
nn = int(input())
aa = list(map(int, input().split()))
bb = [0]*(nn-1)
mysum = 0
for i in range(nn):
    mysum += aa[i] % (10**9 + 7)
mydiff = 0

for i in range(1,nn):
    mydiff += aa[i - 1]
    tete = mysum - mydiff
    if tete >= 0:
        bb[i-1] = tete
    else:
        bb[i-1] = tete + 10**9+7

finalsum = 0
for i in range(nn-1):
        finalsum += aa[i]*bb[i]
        finalsum = finalsum % (10**9 + 7)

print(finalsum)

Measured memory_bytes: 105444
#include<bits/stdc++.h>
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<cmath>
#define ll long long
#define PB push_back
#define POP pop_back()
#define PII pair<int,int>
#define FI first
#define SE second
#define ULL unsigned long long
#define endl '\n'
using namespace std;
const int INF=0x3f3f3f3f;
const double pi=acos(-1),eps=1e-8;

int main()
{
//	ios::sync_with_stdio(false);
//	cin.tie(0);cout.tie(0);
	
	int a,b;
	cin>>a>>b;
	cout<<a*b<<endl; 
 	return 0;
}







Measured memory_bytes: 3624
#include <bits/stdc++.h>
#define REP(i, s, n) for (int i = s; i < n; i++)
#define ALL(a) a.begin(), a.end()
#define MOD 1000000007
using namespace std;
typedef long long ll;

int main() {
    string S; cin >> S;

    int ans = 0;
    REP(i, 1, S.size() / 2) {
        bool ok = true;
        REP(j, 0, i) {
            if (S[j] != S[i + j]) ok = false;
        }
        if (ok) ans = i * 2;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

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

		int cnt = 0;
		for (int i = 0; i < s.length(); i++) {
			if (s.charAt(i) == '1') {
				cnt++;
			}
		}
		System.out.println(cnt);
	}
}


Measured memory_bytes: 22996
def main():
    import sys
    # import math
    # import decimal
    input = sys.stdin.readline
    a, b, c = map(int, input().split())

    if a+b < c:
        if (c-a-b)**2 > 4*a*b:
            print('Yes')
        else:
            print('No')
    else:
        print('No')


if __name__ == '__main__':
    main()


Measured memory_bytes: 2940
#include<stdio.h>
int main(){
  int w,h,x,y,r;
  scanf("%d %d %d %d %d",&w,&h,&x,&y,&r);
  if(w-x-r<0 || h-y-r<0){
    printf("No\n");
  }
  else if(x-r<0 || y-r<0){
    printf("No\n");
  }
  else{
    printf("Yes\n");
  }
  return(0);
}

Measured memory_bytes: 584
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define FORR(i,a,b) for(int i=(a);i>=(b);i--)
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define pcnt __builtin_popcount
#define sz(x) (int)(x).size()
#define maxs(x,y) x=max(x,y)
#define mins(x,y) x=min(x,y)
#define show(x) cout<<#x<<" = "<<x<<endl;
#define all(a) (a.begin()),(a.end())
#define each(it,c) for(__typeof((c).begin()) it=(c).begin();it!=(c).end();it++)
#define perm(c) sort(all(c));for(bool c##p=1;c##p;c##p=next_permutation(all(c)))
#define bit(n) (1LL<<(n))
#define randInt(l,r) (uniform_int_distribution<ll>(l,r)(rnd))
#define randDouble(l,r) (uniform_real_distribution<double>(l,r)(rnd))

typedef long long ll;
typedef __int128_t lll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
template<class T>using V=vector<T>;
template<class T>using VV=V<V<T>>;
template<class T,class Y>ostream& operator<<(ostream& o,const pair<T,Y>& p){return o<<"("<<p.fi<<", "<<p.se<<")";}
template<typename A,size_t N,typename T>void Fill(A (&array)[N],const T&v){fill((T*)array,(T*)(array+N),v);}
lll gcd(lll a,lll b,lll &x,lll &y){if(!b){x=1;y=0;return a;}lll d=gcd(b,a%b,y,x);y-=a/b*x;return d;}
ll gcd(ll a,ll b){lll x=0,y=0;return gcd(a,b,x,y);}
ll modPow(lll a,lll n,ll m){if(!a)return a;lll p=1;for(;n>0;n>>=1,a=a*a%m)if(n&1)p=p*a%m;return(ll)p;}
bool isPrime(ll n){if(n<2||n%2==0)return n==2;lll t=n-1,d=t/(t&-t);for(lll a:{2,325,9375,28178,450775,9780504,1795265022})if(a%n){for(t=d,a=modPow(a,t,n);t!=n-1&&a!=1&&a!=n-1;a=a*a%n,t=t*2%n);if(a!=n-1&&t%2==0)return 0;}return 1;}
void dout(double d){printf("%.12f\n",d);}
const int IINF = 1e9+6;
const ll LINF = 1e18;
const int MOD = 1e9+7;
const double PI = acos(-1);
const double EPS = 1e-10;
static random_device rd;
static mt19937 rnd(rd());

const int N = 1e5;
int a[3];
main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  FOR(i, 0, 3) cin >> a[i];
  sort(a, a+3);
  cout << a[0] * a[1] / 2 << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <queue>
#include <algorithm>
#include <cmath>
#include <bitset>
#include <iomanip>
#include <stack>
#include <list>
#include <map>
#include <unordered_map>
#include <chrono>
#include <numeric>
using namespace std;
using ll = long long;
const ll INF = (ll)1e18+1;
const ll DIV = 1000000007;
//#define TEST
int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
#ifdef TEST
    chrono::system_clock::time_point start, end;
    start = chrono::system_clock::now();
#endif
    long N;
    cin >> N;
    string S, T;
    cin >> S >> T;
    for(size_t i=0;i<N; i++)
    {
        cout << S[i] << T[i];
    }
    cout << endl;
#ifdef TEST
    end = chrono::system_clock::now();
    cerr << static_cast<double>(chrono::duration_cast<chrono::microseconds>(end - start).count() / 1000.0) << "[ms]" << endl;
#endif
    return 0;
}

Measured memory_bytes: 3636
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
#define fo(i,n) for(ll i=0;i<n;i++)
#define fok(i,k,n) for(ll i=k;i<n;i++)
#define ci(x) cin>>x
#define ci2(x,y) cin>>x>>y
#define co(x) cout<<x<<"\n"
#define co2(x,y) cout<<x<<" "<<y<<"\n"
#define pb push_back
#define pf push_front
#define mp make_pair
#define fi first
#define se second
#define PI 3.1415926535897932384626
#define deb1(x) cout<<#x<<" "<<x<<endl
#define deb2(x,y) cout<<#x<<" "<<x<<" "<<#y<<" "<<y<<"\n"
#define deb3(x,y,z) cout<<#x<<" "<<x<<" "<<#y<<" "<<y<<" "<<#z<<" "<<z<<"\n"
typedef pair<int, int>	pii;
typedef pair<ll, ll>	pll;
typedef vector<int>		vi;
typedef vector<ll>		vl;
typedef vector<pii>		vpii;
typedef vector<pll>		vpll;
typedef vector<vi>		vvi;
typedef vector<vl>		vvl;
const int mod = 1000000007;	
int gcd(int a, int b){ if(a==0) return b; return gcd(b%a, a);}

int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	int t=1;
	//ci(t);
	while(t--){
		int n;
		ci(n);
		vi h(n);
		fo(i,n){
			ci(h[i]);
		}
		int cnt =0;
		fo(i,n-2){
			fok(j,i+1,n-1){
				fok(k,j+1,n){
					if( h[i]!=h[j] && h[j]!=h[k] && h[k]!=h[i] &&					
					h[i]+h[j]>h[k] 
					&& h[k]+h[j]>h[i] 
					&& h[i]+h[k]>h[j] ){
						cnt++;
					}
				}
			}
		}
		co(cnt);
		
	}
	return 0;
}



Measured memory_bytes: 3620
import collections
N = int(input())
s_lis = []
for _ in range(N):
    s_lis.append(input())
dic = {}
counts = 0
for s in s_lis:
    c = collections.Counter(s)
    tmp = str()
    for i in sorted(c.keys()):
        tmp += i+str(c[i])
    if tmp in dic.keys():
        dic[tmp] += 1
    else:
        dic[tmp] = 1
for i in dic:
    counts += dic[i]*(dic[i]-1)//2
print(counts)

Measured memory_bytes: 25932
S = input()
N = len(S)

ans = [1]*N

for i,s in enumerate(S):
    if s=="R":
        s2 = S[i+1]
        if s2 == "R":
            ans[i+2] += ans[i]
            ans[i] = 0

for i in range(N-1,-1,-1):
    s = S[i]
    if s=="L":
        s2 = S[i-1]
        if s2 == "L":
            ans[i-2] += ans[i]
            ans[i] = 0

print(*ans)

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

int main() {
  int h,w;
  cin>>h>>w;
  vector<vector<char>>ans(h+2,vector<char>(w+2));
  for(int i=0;i<h+2;i++){
    for(int j=0;j<w+2;j++) ans[i][j]='#';
  }
  vector<vector<char>>a(h,vector<char>(w));
  for(int i=0;i<h;i++){
    for(int j=0;j<w;j++) {
      cin>>a[i][j];
      ans[i+1][j+1]=a[i][j];
    }
  }
  for(int i=0;i<h+2;i++){
    for(int j=0;j<w+2;j++){
      cout<<ans[i][j];
      if(j==w+1) cout<<endl;
    }
  }
}


Measured memory_bytes: 256
import sys
from itertools import accumulate
from bisect import bisect_left

read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines
sys.setrecursionlimit(10 ** 9)
INF = 1 << 60
MOD = 1000000007


def main():
    N, H, *AB = map(int, read().split())
    A = AB[::2]
    B = AB[1::2]

    Amax = max(A)
    B = [b for b in B if b >= Amax]
    B.sort(reverse=True)
    B = list(accumulate(B))

    i = bisect_left(B, H)
    if i < len(B):
        ans = i + 1
    else:
        ans = len(B) + (H - B[-1] + Amax - 1) // Amax

    print(ans)
    return


if __name__ == '__main__':
    main()


Measured memory_bytes: 110332
import java.util.*;
public class Main {
    public static void main(String [] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int [] S = new int[n];
        for(int i=0;i<n;i++) S[i] = sc.nextInt();
        int q = sc.nextInt();
        int cnt = 0;
        for(int i=0;i<q;i++){
            int t = sc.nextInt();
            int left = 0, right = n;
            while(left<right){
                int mid = (left+right)/2;
                if(S[mid]==t){
                    cnt++;
                    break;
                }
                else if(S[mid]>t) right = mid;
                else left = mid+1;
            }
        }
        System.out.println(cnt);
    }
}


Measured memory_bytes: 68948
def main():
    n, k = map(int, input().split())
    if n - k > k:
        n_k = (n-k) // k
        minv = n - k * n_k
    else:
        minv = n

    def min_x(x):
        minv = x
        for _ in range(3):
            if abs(minv - k) < abs(minv):
                minv = abs(minv - k)
            else:
                print(minv)
                exit()
        print(minv)
        
    min_x(minv)


if __name__ == '__main__':
    main()

Measured memory_bytes: 9204
from itertools import combinations
from collections import defaultdict
n,x,y=map(int,input().split())
x-=1
y-=1
cnt=defaultdict(int)
for i,j in combinations(range(n),2):
  cnt[min(abs(j-i),abs(j-y)+1+abs(i-x),abs(j-x)+1+abs(i-y))]+=1
for k in range(1,n):
  print(cnt[k])

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

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

#define For(i, a, b) for(int i = (a); i < (b); i++)
#define Rep(i, n) For(i, 0, (n))
#define Rrep(i, n) for(int i = (n - 1); i >= 0; i--)
#define Itr(i, c) for(typeof(c.begin()) i = c.begin(); i != c.end(); i++)
#define pb push_back

const int inf = 999999999;
const int mod = 1000000007;

int main(){
	int n; cin >> n;
	string s[n];
	bool flag = true;
	Rep(i, n){
		cin >> s[i];
		if(i != 0){
			if(s[i][0] != s[i-1][s[i-1].length()-1]){
				flag = false;
			}
		}
		Rep(j, i){
			if(s[j] == s[i]){
				flag = false;
			}
		}
	}
	if(flag){
		cout << "Yes" << endl;
	}else{
		cout << "No" << endl;
	}
	return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#include <time.h>

int main(){
  char s[20];
  int n;
  memset(s, '\0', sizeof(s));
  srand((unsigned int)time(NULL));
  scanf("%s",s);
  //printf("%s",s);
  n = rand() % 18;

  while(s[n+2]=='\0')
    n = rand() % 18;
  printf("%c%c%c\n",s[n],s[n+1],s[n+2]);

  return 0;
}

Measured memory_bytes: 1728
w, h, n = gets.chomp.split.map(&:to_i)
arr = []
n.times{
    x, y, a = gets.chomp.split.map(&:to_i)
    case a
    when 1 then arr[0] = x if arr[0].nil? || arr[0] < x
    when 2 then arr[1] = x if arr[1].nil? || arr[1] > x
    when 3 then arr[2] = y if arr[2].nil? || arr[2] < y
    when 4 then arr[3] = y if arr[3].nil? || arr[3] > y
    end
}

map = Array.new(h){"W" * w}
arr.each_with_index{|z, i|
    next if z.nil?
    case i
    when 0
        h.times{|y2| map[y2][0, z] = "B" * z} if z > 0
    when 1
        h.times{|y2| map[y2][z, w - z] = "B" * (w - z)} if z < w
    when 2
        0.upto(z - 1){|z2| map[z2] = "B" * w}
    when 3
        z.upto(h - 1){|z2| map[z2] = "B" * w}
    end
}

sum = 0
map.each{|m| sum += m.count("W")}
puts sum

Measured memory_bytes: 1788
import java.io.*;

public class Main {
    public static void main(String[] args) throws IOException {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        int n = Integer.parseInt(br.readLine());
        long power = 1;
        for(int i = 1; i <= n; i ++) {
            power = (int)((power * i) % (Math.pow(10, 9) + 7));
        }
        System.out.println(power);
    }
}

Measured memory_bytes: 21332
#pragma comment(linker, "/STACK:256000000")

#include <stdio.h>
#include <stdlib.h>
#include <string>
#include <vector>
#include <map>
#include <string>
#include <algorithm>
#include <iostream>
#include <memory.h>
#include <assert.h>
#include <functional>
#include <vector>
#include <string>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <queue>
#include <map>
#include <set>
#include <deque>
#define _USE_MATH_DEFINES
#include <math.h>
#include <bitset>
#include <list>
#include <iomanip>      // std::setprecision
#include <random>
#include <array>

typedef std::mt19937 rng_type;
std::uniform_int_distribution<rng_type::result_type> udist(0, 1);

rng_type rng;

using namespace std;

FILE * in, *out;

#define fo(a,b,c) for(int a = ( b ); a < ( c ); ++ a )
#define fr(a,b) fo( a, 0, ( b ) )
#define fi(a) fr( i, ( a ) )
#define fj(a) fr( j, ( a ) )
#define fk(a) fr( k, ( a ) )
#define mp make_pair
#define pb push_back
#define all(v) (v).begin( ), (v).end( )
#define _(a,b) memset( a, b, sizeof( a ) )

#define LL long long

int ri() { int a; fscanf(in, "%d", &a); return a; }
double rf() { double a; fscanf(in, "%lf", &a); return a; }
char sbuf[100005];
string rstr()
{
	//fscanf(in, "%lf", sbuf); 
	char c;
	char * b = sbuf;
	while(c = fgetc(in))
	{
		if(c == '\n' || c == 255) break;
		*b++ = c;
	}
	*b = 0;
	return sbuf;
}


long long nod(long long a, long long b)
{
	if(a == 1 || b == 1) return 1;
	if(a == 0) return b;
	if(b == 0) return a;

	return nod(b%a, a);
}

vector<int> primes;
void calculatePrimes()
{
	primes.push_back(2);
	for(int i = 3; i < 100000; i += 2)
	{
		bool bFound = false;
		int m = (int)sqrt((float)i);
		for(int j = 1; j < primes.size() && !bFound && primes[j] <= m; j++)
			bFound = ((i%primes[j]) == 0);
		if(!bFound)
			primes.push_back(i);
	}
}

bool isPrime(int p)
{
	for(int i : primes)
		if(p != i && (p%i) == 0) return false;
	return true;
}


//	std::cout.setf(std::ios_base::fixed, std::ios_base::floatfield);
//	std::cout.precision(7);


void egcd(int a, int b, int &g, int &x, int &y)
{
	if(a == 0)
	{
		g = b;
		x = 0;
		y = 1;
		return;
	}
	egcd(b%a, a, g, y, x);
	x = x - (b / a)*y;
}

int modinv(int a, int m)
{
	int g = 0, x = 0, y = 0;
	egcd(a, m, g, x, y);
	return (x+m)%m;
}

long long modpow(int a, long long n, int p)
{
	long long res = 1;
	long long curp = (a%p);
	while(n)
	{
		if(n&1)
		{
			res = (res*curp)%p;
		}
		curp = (curp*curp)%p;
		n /= 2;
	}
	return res;
}


#define MODP  998244353 //1000000007
long long nf(int n)
{
	if(n == 1) return 1;
	return (n*nf(n-1))%MODP;
}

long long intpowmod(long long base, long long exp)
{
	if(exp == 0) return 1;
	if(exp == 1) return base;
	if((exp & 1) != 0) return (base * intpowmod((base * base)%MODP, exp / 2))%MODP;
	return intpowmod((base * base)%MODP, exp / 2);
}

#ifdef _WIN32
#define LOCAL_TEST
#endif

int main()
{
	long long n;
	cin >> n;
	vector<int> v(n);
	vector<int> p(n);
	vector<int> l(n);
	fi(n)
	{
		cin >> v[i];
		v[i]--;
		p[v[i]] = i;
	}

	int max = 0;
	for(int i = n-2; i >=0; i--)
	{
		if(p[i] < p[i+1])
			l[i] = l[i+1]+1;
		else
			l[i] = 0;
		if(l[i] > max) max = l[i];
	}
	cout << n-max-1;
}


Measured memory_bytes: 2560
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<int, int>;
#define rep(i, n) for(int i=0;i<(int)n;i++)
#define PI acos(-1)
#define fast_io ios_base::sync_with_stdio(false) ; cin.tie(0); cout.tie(0);
ll mod=1e9+7;
ll gcd(ll a, ll b){if(b==0) return a; return gcd(b, a%b);}

struct Edge{int to, id;};

vector<vector<Edge>> g;
vector<int> ans;

void dfs(int v, int  c=-1, int p=-1){
    int k=1;
    //vの周りを塗りたい
    rep(i, g[v].size()){
        int u = g[v][i].to, ei=g[v][i].id;
        if(u == p) continue;
        if(k == c) ++k;
        ans[ei] = k;
        ++k;
        //子方向へ行くときにちょうどたどってる辺の色を渡す。
        dfs(u, ans[ei], v);
    }
}

int main(){
    fast_io

    int n;
    cin>>n;
    g.resize(n);
    ans = vector<int>(n-1);
    
    for(int i=0;i<n-1;i++){
        int a, b;
        cin>>a>>b;
        a--;b--;
        g[a].push_back((Edge){b, i});
        g[b].push_back((Edge){a, i});
    }
    dfs(0);

    int mx = 0;
    rep(i,n){
        mx = max(mx, int(g[i].size()));
    }
    cout<<mx<<endl;
    rep(i,n-1){
        cout<<ans[i]<<endl;
    }
    return 0;
}

Measured memory_bytes: 8320
#include <iostream>
#include <cmath>
#include <vector>
#include <algorithm>

using namespace std;

double EPS = 1e-10;

double add (double a, double b) {
	if (abs(a + b) < EPS * (abs(a) + abs(b))) {
		return 0;
	}
	return a + b;
}

struct P {
	double x, y;
	P() {}
	P (double x, double y) : x(x), y(y) {
	}
	P operator + (P p) {
		return P(add(x, p.x), add(y, p.y));
	}
	P operator - (P p) {
		return P(add(x, -p.x), add(y, -p.y));
	}
	P operator * (double d) {
		return P(x * d, y * d);
	}
	double dot(P p) {
		return add(x * p.x, y * p.y);
	}
	double det(P p) {
		return add(x * p.y, -y * p.x);
	}
};

bool cmp_x(const P& p, const P& q) {
	if(p.x != q.x) {
		return p.x < q.x;
	}
	return p.y < q.y;
}

vector<P> convex_hell(P* ps, int n) {
	sort(ps, ps + n, cmp_x);
	int k = 0;
	vector<P> qs(n * 2);
	for (int i = 0; i < n; i++) {
		while (k > 1 && (qs[k - 1] - qs[k - 2]).det(ps[i] - qs[k - 1]) <= 0) {
			k--;
		}
		qs[k++] = ps[i];
	}
	for (int i = n - 2, t = k; i >= 0; i--) {
		while (k > t && (qs[k - 1] - qs[k - 2]).det(ps[i] - qs[k - 1]) <= 0) {
			k--;
		}
		qs[k++] = ps[i];
	}
	qs.resize(k - 1);
	return qs;
}

int main() {
	int n;
	while (cin >> n) {
		if (n == 0) {
			break;
		}
		char c;
		P ps[110];
		for (int i = 0; i < n; i++) {
			cin >> ps[i].x >> c >> ps[i].y;
		}
		vector<P> qs = convex_hell(ps, n);
		cout << n - qs.size() << endl;
	}
	return 0;
}

Measured memory_bytes: 1236
#include<bits/stdc++.h>
using namespace std;
int main(){
  long long a,z,x=0;
  string s;
  cin >> s;
  for(int i=0;i<s.size();i++){
    if(x==0&&s[i]=='A'){
      a=i;
      x++;
    }
  }
  x=0;
  for(int i=s.size()-1;i>=0;i--){
    if(x==0&&s[i]=='Z'){
      z=i;
      x++;
    }
  }
  cout << z-a+1 << endl;
  return 0;
}

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

#define REP(i, a, b) for(int i = a; i <= b; i ++)
#define REPG(i, x) for(int i = head[x]; i; i = g[i].nxt)

#define clr(x, y) memset(x, y, sizeof(x));

using namespace std;

typedef long long LL;
typedef double LF;

LL Max(LL a, LL b){return a > b ? a : b;}
LL Min(LL a, LL b){return a < b ? a : b;}
LL abs(LL x){return x > 0 ? x : -x;}

inline int read(){
	int r = 0, z = 1; char ch = getchar();
	while(ch < '0' || ch > '9'){if(ch == '-') z = -1; ch = getchar();}
	while(ch >= '0' && ch <= '9'){r = r * 10 + ch - '0'; ch = getchar();}
	return r * z;
}

void work(){
	int a = read(), b = read(); char ch[1015];
	scanf("%s", ch + 1); bool flag = 0;
	if(ch[a + 1] == '-') flag = 1;
	for(int i = 1; i <= a + b + 1; i ++){
		if(i == a + 1) continue;
		if(ch[i] < '0' || ch[i] > '9') flag = 0;
	}
	if(flag) printf("Yes\n");
	else printf("No\n");
}

int main(){
	work();
	return 0;
}


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

namespace Atcoder
{
    class Program
    {
        public static void Main(string[] args)
        {
            int[] input1 = Console.ReadLine().Split(" ").Select(i => int.Parse(i)).ToArray();
            int[] input2 = { 0 };
            if (input1[1] != 0)
            {
                input2 = Console.ReadLine().Split(" ").Select(i => int.Parse(i)).ToArray();
                var plusList = new List<long>();
                var minusList = new List<long>();
                foreach (var num in input2)
                {
                    var a = input1[0] - num;
                    if (a >= 0)
                        plusList.Add(a);
                    else
                    {
                        minusList.Add(a);
                    }
                };
                plusList.Sort();
                minusList.Sort();
                minusList.Reverse();
                int b = 0;
                foreach (var num in plusList)
                {
                    if (num != b)
                        break;
                    b++;
                }
                var ansa = input1[0] - b;
                int c = -1;
                foreach (var num in minusList)
                {
                    if (num != c)
                        break;
                    c--;
                }
                var ansb = input1[0] - c;

                if (Math.Abs(input1[0] - ansa) > Math.Abs(input1[0] - ansb))
                    Console.Write(ansb);
                else
                    Console.Write(ansa);
            }
            else
                Console.Write(input1[0]);
        }
    }
}


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

using namespace std;

const int mxn = 2e5;
int main()
{
	int n;
	cin >> n;
	int arr[mxn];
	int m = 2e5;
	
	for (int i = 0; i < n; i++)
	{
		cin >> arr[i];
	}
	
	int count = 0;
	for (int i = 0; i < n ; i++)
	{
		if (arr[i] <= m)
		{
			count++;
		}
		m = min(m, arr[i]);
	}
	
	cout << count;
	return 0;
}




Measured memory_bytes: 1152
#include <bits/stdc++.h>
using namespace std;
 
using ll=long long;
 
#define rng(i,a,b) for(int i=int(a);i<int(b);i++)
#define rep(i,b) rng(i,0,b)
#define gnr(i,a,b) for(int i=int(b)-1;i>=int(a);i--)
#define per(i,b) gnr(i,0,b)
#define pb push_back
#define eb emplace_back
#define bg begin()
#define ed end()
#define all(x) x.bg,x.ed
const ll MOD = 1e9 + 7;



int main() {
    int n;  cin >> n;
    vector<pair<int, int>> nodes(n+1), queries;
    rep(i, n) {
        int v,w;
        cin >> v >> w;
        nodes[i+1] = {v,w};
    }
    int q; cin >> q;
    int lmax = 0;
    rep(i, q) {
        int v,l;
        cin >> v >> l;
        lmax = max(l, lmax);
        queries.emplace_back(v,l);
    }
    const int n1 = (1 << 10)- 1;
    vector<vector<int>> dps(n1+1, vector<int>(lmax+1, 0)); 
    rng(i, 1, min(n1, n)+1) {
        int v = nodes[i].first;
        int w = nodes[i].second;
        rep(k, lmax+1) {
            dps[i][k] = dps[i/2][k];
            if (k >= w) dps[i][k] = max(dps[i][k], dps[i/2][k - w] + v);
        }
    }
    vector<int> ans(q, 0);
    rep(i, q) {
        int v = queries[i].first;
        int l = queries[i].second;
        if (n1 < v) {
            int lv = v, cnt = 0;
            while (lv > n1) {
                lv /= 2;
                cnt++;
            }
            rep(j, 1 << cnt) {
                int b = j, ltv = v;
                int tv = 0, tw = 0;
                rep(k, cnt) {
                    if (b & 1) {
                        tv += nodes[ltv].first;
                        tw += nodes[ltv].second; 
                    } 
                    b >>= 1;
                    ltv /= 2;
                }
                if (tw <= l) ans[i] = max(ans[i], tv + dps[lv][l-tw]);
            }
        } else {
            ans[i] = dps[v][l];
        }
    }
    for(int a : ans) cout << a << endl;
    return 0;
}

Measured memory_bytes: 406584
import java.io.*;
import java.util.*;
import java.math.*;
/*
 連立方程式ax+b=c,dx+e=fの解を求める
 2013.6.8
*/
class Main {
    public static void main(String[] a) throws IOException{
	String output = new String();//出力の文字列
	BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
	String str;
	//Enterが押されるまで処理を反復実行
	while  ((str= br.readLine())!=null){
	    double[] coeff = new double[6];//aからfまでの係数
	    int i;
	    StringTokenizer strCoeff = new StringTokenizer(str," ");//空白文字で分割
	    i = 0;
	    while(i<6)
		{
		    coeff[i] = Double.parseDouble(strCoeff.nextToken());
		    i++;
		}
	    double x,y,p,q;//y=p/q, p=af-cd, q=ae-bd, x=(cq-bp)/(aq)
	    p = coeff[0]*coeff[5]-coeff[2]*coeff[3];
	    q = coeff[0]*coeff[4]-coeff[1]*coeff[3];
	    if(coeff[0] != 0 && q != 0)
		{
		    x = (coeff[2]*q-coeff[1]*p)/(coeff[0]*q);
		    y = p/q;
		    BigDecimal bd1 = new BigDecimal(x);
		    BigDecimal bd2 = new BigDecimal(y);
		    BigDecimal bd1_hp = bd1.setScale(3,BigDecimal.ROUND_HALF_UP);
		    BigDecimal bd2_hp = bd2.setScale(3,BigDecimal.ROUND_HALF_UP);
		    output =  bd1_hp + " " + bd2_hp + "\n";
		    System.out.print(output);
		}
	    else
		{
		    output += "No answer\n";
		}
	}
    }
}

Measured memory_bytes: 17052
using System;

namespace B
{
    class B
    {
        static void Main(string[] args)
        {
            int n, q, i, nowtime=0, j=0, head=0, tail;
            int[] time = new int[1000000];
            int[] time2 = new int[100000];
            string[] input = new string[2];
            string[] name = new string[100000];
            string[] name2 = new string[100000];

            //入力
            input = Console.ReadLine().Split(' ');
            n = int.Parse(input[0]);
            tail = n;
            q = int.Parse(input[1]);
            for (i=0; i<n; i++)
            {
                input = Console.ReadLine().Split(' ');
                name[i] = input[0];
                time[i] = int.Parse(input[1]);
    
            }

            //キューの処理
            while (true)
            {
                if ((time[head]-q)>0)
                {
                    nowtime += q;
                    time[tail] = time[head]-q;
                    name[tail] = name[head];
                    if (tail==n)
                    {
                        tail = 0;
                    }
                    else
                    {
                        tail++;
                    }
                    if (head==n)
                    {
                        head = 0;
                    }
                    else
                    {
                        head++;
                    }
                }
                else
                {
                    nowtime += time[head];
                    time2[j] = nowtime;
                    name2[j] = name[head];
                    j++;
                    if (head==n)
                    {
                        head = 0;
                    }
                    else
                    {
                        head++;
                    }
                }
                if (j==n)
                {
                    break;
                }
            }
            
            
            //表示
            for (i=0; i<n; i++)
            {
                Console.WriteLine(name2[i] + " " + time2[i]);
            }
        }
    }
}



Measured memory_bytes: 21556
def calc(n,x):
  if x==1:
    if n==0:
      ans=1
    else:
      ans=0
  elif 1 < x < (num[n]+1)//2:
    ans= calc(n-1,x-1)
  elif x== (num[n]+1)//2:
    ans= pat[n-1]+1
  elif (num[n]+1)//2 < x <num[n]:
    ans= pat[n-1]+1+ calc(n-1, x- (num[n]+1)//2)
  else:   # x=num[n]
    ans= pat[n]
  return ans


N,X=map(int,input().split())
num= [1]
pat= [1]
for i in range(1,N+1):
  num.append(num[-1]*2+3)
  pat.append(pat[-1]*2+1)

print(calc(N,X))

Measured memory_bytes: 3064
from collections import deque
N = int(input())
A = input().split()
que = deque([A[0]])
for i in range(1,N):
    if i%2 == 0:
        que.append(A[i])
    else:
        que.appendleft(A[i])
if N%2 == 1:
    que.reverse()
for i in range(N):
    print(que[i],end = " ")

Measured memory_bytes: 21316
all_cards = int(input())
cards = {'S':[0]*13, 'H':[0]*13, 'C':[0]*13, 'D':[0]*13}
for i in range(all_cards):
    mark, num_cards = input().split()
    cards[mark][ int(num_cards) - 1] = 1
for i in ["S", "H", "C", "D"]:
    for j in range(13):
        if cards[i][j] == 0:
            print(i, j + 1)

Measured memory_bytes: 7660
w, h, x, y = list(map(int, input().split()))
ans = 0

if ((x, y) == (w / 2, h / 2)):
    print("{s} {mul}".format(s=(w * h / 2), mul=1))
else:
    print("{s} {mul}".format(s=(w * h / 2), mul=0))


Measured memory_bytes: 38256
import java.util.*;import java.math.*;public class Main{class P{double x;double y;P(double x,double y){this.x=x;this.y=y;}P add(P a){return new P(x+a.x,y+a.y);}P mul(double a){return new P(x*a,y*a);}double abs(){return Math.sqrt(x*x+y*y);}}Scanner sc=new Scanner(System.in);void run(){for(;;){P[]p=new P[3];double v=0;for (int i=0;i<3;i++){p[i]=new P(sc.nextDouble(),sc.nextDouble());v+=Math.abs(p[i].x)+Math.abs(p[i].y);}if(v<1){break;}P[]t=new P[3];double len[]=new double[3];for (int i=0;i<3;i++){P p1=p[(i+1)%3].add(p[i].mul(-1));P p2=p[(i+2)%3].add(p[i].mul(-1));double p1l=p1.abs();double p2l=p2.abs();P np1=p1.mul(1/p1l);P np2=p2.mul(1 / p2l);P tt=np1.add(np2);t[i]=tt.mul(1/tt.abs());len[i]=Math.min(p1.abs(),p2.abs());}double min=0;double max=len[0];P a[]=new P[3];double r[]=new double[3];for(;;){if(Math.abs(min-max)<1e-6) {break;}double p0=(min+max)/2;a[0]=t[0].mul(p0).add(p[0]);{P org=p[0].mul(-1);P a0=a[0].add(org);P p1 = p[1].add(org);
					double lp1 = p1.abs();
					P p1v = p1.mul(1 / lp1);

					double dot = a0.x * p1v.x + a0.y * p1v.y;

					r[0] = Math.sqrt(p0 * p0 - dot * dot);
				}

				double min1 = 0;
				double max1 = len[1];
				for (;;) {if (Math.abs(min1 - max1) < 1e-6) {
break;}
		double p1 = (min1 + max1) / 2;
					a[1] = t[1].mul(p1).add(p[1]);

					{
						P org = p[1].mul(-1);

						P a0 = a[1].add(org);
						P p2 = p[0].add(org);
						double lp1 = p2.abs();
						P p1v = p2.mul(1 / lp1);

						double dot = a0.x * p1v.x + a0.y * p1v.y;

						r[1] = Math.sqrt(p1 * p1 - dot * dot);
					}


					double diff = a[1].mul(-1).add(a[0]).abs();

					if (diff < r[1] + r[0]) {
						max1 = p1;
					} else {
						min1 = p1;
					}
				}

				double min2 = 0;
				double max2 = len[2];
				for (;;) {
					if (Math.abs(min2 - max2) < 1e-6) {
						break;
					}
					double p1 = (min2 + max2) / 2;
					a[2] = t[2].mul(p1).add(p[2]);

					{
						P org = p[2].mul(-1);

						P a0 = a[2].add(org);
						P p2 = p[0].add(org);
						double lp1 = p2.abs();
						P p1v = p2.mul(1 / lp1);

						double dot = a0.x * p1v.x + a0.y * p1v.y;

						r[2] = Math.sqrt(p1 * p1 - dot * dot);
					}

					double diff = a[2].mul(-1).add(a[0]).abs();

					if (diff < r[2] + r[0]) {
						max2 = p1;
					} else {
						min2 = p1;
					}
				}


				double diff = a[2].mul(-1).add(a[1]).abs();
				if (diff > r[2] + r[1]) {
					max = p0;
					// System.out.println(" < "+r[0]);
				} else {
					min = p0;
					// System.out.println(" > "+r[0]);
				}

			}
			System.out.println(r[0] + " " + r[1] + " " + r[2]);
		}

	}

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

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

int sv[110];
pair<int,int> dp[2][50010];
bool cmp(pair<int,int> &A, pair<int,int> &B) { 
    return ( A.first < B.first ) || (A.first == B.first && A.second > B.second); 
}
// first := 500円玉の枚数（多いほどいい）
// second := 消費金額（少ないほどいい）
int n;

bool solve()
{

    cin >> n;
    if(n == 0) return false;
    for(int i = 0; i < n; ++i) {
        cin >> sv[i];
    }

    int MAX_K = 500*n;
    for(int i = 0; i < 2; ++i) {
        for(int j = 0; j < MAX_K; ++j) {
            dp[i][j].first = -1;
            dp[i][j].second = 0;
        }
    }
    
    dp[0][0].first = 0;
    for(int i = 0; i < n; ++i) {
        int prv = i%2;
        int nxt = 1 - prv;
        for(int j = 0; j < MAX_K; ++j) {
            dp[nxt][j] = dp[prv][j];
        }

        int add = (1000 - sv[i]%1000)%1000; // 1000円札だけだしてもらえるおつり
        int need = (sv[i] + 500)%1000;      // 小銭も出して500円玉を得る場合に必要な金額
        //cout << "add: " << add << " need: " << need << endl;
        for(int j = 0; j < MAX_K; ++j) {
            if(dp[prv][j].first == -1) continue;

            int num = dp[prv][j].first;
            int money = dp[prv][j].second;

            if(add >= 500) {
                // 1000円札だけ出して小銭と500円玉もらう方がいい
                if(j + add - 500 >= MAX_K) continue;
                pair<int,int> X = make_pair(num + 1, money + sv[i]);
                if(cmp(dp[nxt][j + add - 500], X)) dp[nxt][j + add - 500] = X; 
                continue;
            }

            // 小銭も出して500円玉をもらう
            if(j - need >= 0) {
                pair<int,int> X = make_pair(num + 1, money + sv[i]);
                if(cmp(dp[nxt][j - need], X)) dp[nxt][j - need] = X;
            }

            // 500円玉を諦め、1000円札だけ出して小銭を得る
            if(j + add < MAX_K) {
                pair<int,int> X = make_pair(num, money + sv[i]);
                if(cmp(dp[nxt][j + add], X)) dp[nxt][j + add] = X;
            }

        }

        // デバッグ
        /*
        for(int j = 0; j < MAX_K; ++j) {
            if(dp[nxt][j].first != -1) {
                cout << "j:" << j << " (" << dp[nxt][j].first << ", " << dp[nxt][j].second << ")" << endl;
            }
        }
        */
    }
    
    int num = 0, money = 1000000009;
    int r = n%2;
    for(int i = 0; i < MAX_K; ++i) {
        if(dp[r][i].first == -1) continue;
        if(num < dp[r][i].first) {
            num = dp[r][i].first, money = dp[r][i].second;
        }
        else if(num == dp[r][i].first) {
            money = min(money, dp[r][i].second);
        }
    }

    cout << num << " " << money << endl;
    return true;
}

int main() {
    while(solve());
    return 0;
}


Measured memory_bytes: 3836
#include <iostream>
#include <array>
#include <numeric>
#include <cstdint>

int main()
{
	std::array<std::uint32_t, 10> length;
	while (std::cin >> length[0]) {
		char comma;
		for (std::uint32_t i = 1; i < length.size(); ++i) {
			std::cin >> comma >> length[i];
		}
		double v1, v2;
		std::cin >> comma >> v1 >> comma >> v2;

		std::uint32_t const total_len = std::accumulate(length.begin(), length.end(), 0u);
		double const pos = v1 * total_len / (v1 + v2);

		std::uint32_t len = 0u;
		for (std::uint32_t i = 0; i < length.size(); ++i) {
			len += length[i];
			if (pos <= len) {
				std::cout << i + 1 << std::endl;
				break;
			}
		}
	}

	return 0;
}

Measured memory_bytes: 1224
#include <bits/stdc++.h>
#include <numeric>
#define REP(i, s, n) for (int i = s; i < n; ++i)
#define rep(i, n) REP(i, 0, n)
#define SORT(c) sort((c).begin(), (c).end())
#define SORT_INV(c) sort((c).begin(), (c).end(), greater<int>())

#define IINF INT_MAX
#define LLINF LLONG_MAX
#define DEBUG false
#define LL long long
#define Dev 1000000007

// sort(a.begin(), a.end(), std::greater<int>());
using namespace std;

int main()
{
    int prime[] = {2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59, 61, 67, 71, 73, 79, 83, 89, 97};
    int n;
    cin >> n;
    map<int, int> dic;
    REP(i, 2, n + 1)
    {
        int num = i;
        int j = 0;
        while (num != 1)
        {
            if (num % prime[j] == 0)
            {
                dic[j]++;
                num /= prime[j];
            }
            else
            {
                j++;
            }
        }
    }
    int ans = 0;
    //0075のケース
    for (auto i = dic.begin(); i != dic.end(); ++i)
    {
        if (i->second + 1 >= 75)
            ans++;
    }
    for (auto i = dic.begin(); i != dic.end(); ++i)
    {
        for (auto j = dic.begin(); j != dic.end(); ++j)
        {
            if (i == j)
                continue;
            if (i->second + 1 >= 3 && j->second + 1 >= 25)
                ans++;
            if (i->second + 1 >= 5 && j->second + 1 >= 15)
                ans++;
        }
    }
    for (auto i = dic.begin(); i != dic.end(); ++i)
    {
        for (auto j = next(i); j != dic.end(); ++j)
        {
            for (auto k = next(j); k != dic.end(); ++k)
            {
                if (i->second + 1 >= 3 && j->second + 1 >= 5 && k->second + 1 >= 5)
                    ans++;
                if (i->second + 1 >= 5 && j->second + 1 >= 3 && k->second + 1 >= 5)
                    ans++;
                if (i->second + 1 >= 5 && j->second + 1 >= 5 && k->second + 1 >= 3)
                    ans++;
            }
        }
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
#include "bits/stdc++.h"
// Begin Header {{{
#define all(x)          (x).begin(), (x).end()
#define rep(i, s, n)    for (i64 i = (s), i##_limit = (n); i < i##_limit; ++i)
#define repr(i, s, t)   for (i64 i = (s), i##_limit = (t); i >= i##_limit; --i)
#define var(type, ...)  type __VA_ARGS__; read(__VA_ARGS__);
#ifndef DBG
#define dump(...)
#endif
using namespace std;
using i64 = int_fast64_t;
using pii = pair<i64, i64>;
template <class T, class U> inline bool chmax(T &a, const U &b) { return b > a && (a = b, true); }
template <class T, class U> inline bool chmin(T &a, const U &b) { return b < a && (a = b, true); }
constexpr int INF  = 0x3f3f3f3f;
constexpr i64 LINF = 0x3f3f3f3f3f3f3f3fLL;

template <class T>
inline vector<T> makeV(const T &initValue, size_t sz) {
    return vector<T>(sz, initValue);
}

template <class T, class... Args>
inline auto makeV(const T &initValue, size_t sz, Args... args) {
    return vector<decltype(makeV<T>(initValue, args...))>(sz, makeV<T>(initValue, args...));
}

template <class T>
inline istream& operator>> (istream &is, vector<T> &vec) {
    for (auto &e : vec) is >> e;
    return is;
}

inline void read() {}

template <class Head, class... Tail>
inline void read(Head &head, Tail&... tail) { cin >> head; read(tail...); }

inline void print() { cout << "\n"; }

template <class Head, class... Tail>
inline void print(Head &&head, Tail&&... tail) {
    cout << head;
    if (sizeof...(tail)) cout << ' ';
    print(forward<Tail>(tail)...);
}

template <class T>
inline ostream& operator<< (ostream &os, const vector<T> &vec) {
    static constexpr const char *delim[] = { " ", "" };
    for (const auto &e : vec) os << e << delim[&e == &vec.back()];
    return os;
}

template <class Container>
struct Rev {
    Container &x_;
    inline Rev(Container &x): x_(x) {}
    inline auto begin() { return rbegin(x_); }
    inline auto end() { return rend(x_); }
};
// }}} End Header

struct UnionFind { // {{{
    vector<int> u;
    explicit UnionFind(int n): u(n+5, -1) {}
    int  size(int x)        { return -u[root(x)]; }
    int  root(int x)        { return (u[x] < 0)? x : (u[x] = root(u[x])); }
    bool same(int x, int y) { return (root(x) == root(y)); }
    bool unite(int x, int y){ return (x=root(x)) == (y=root(y))? false : (u[x]+=u[y], u[y]=x, true); }
}; // }}}

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

    var(int, N, M);

    vector<int> a(N + 1);
    vector<int> pos(N + 1);
    for (int i = 1; i <= N; ++i) {
        read(a[i]);
        pos[a[i]] = i;
    }

    UnionFind uf(N + 1);
    rep(i, 0, M) {
        var(int, x, y);
        uf.unite(x, y);
    }

    i64 ans = 0;
    for (int n = 1; n <= N; ++n) {
        if (uf.same(n, pos[n])) {
            ++ans;
        }
    }

    print(ans);

    return 0;
}


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

typedef long long ll;
const int N = 2000006;

int a[N];

int main(){
	ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
	
	int n,k;
	cin>>n>>k;
	for(int i=0;i<n;i++){
		int x;
		cin>>x;
	}
	cout<<(1 + (n-2)/(k-1))<<endl;
	
	return 0;
}


Measured memory_bytes: 3592
#include <algorithm>
#include <iostream>
#include <vector>
#include <math.h>
#include <set>
#include <map>
#include <string>
#include <stack>
#include <queue>
#include <iomanip>
#include <numeric>
#include <tuple>
#include <bitset>
#include <complex>
#include <unistd.h>
#include <cassert>
#include <cctype>
#include <random>
#include <time.h>
#define _USE_MATH_DEFINES
#define _GLIBCXX_DEBUG
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> plglg;
typedef pair<double, ll> pdlg;
typedef tuple<int, int, int> tiii;
typedef tuple<ll, ll, ll> tlglglg;
typedef tuple<double, double, double> tddd;
typedef complex<double> xy_t;
typedef vector<ll> vll;
typedef vector< vector<ll> > matrix;
#define REP(i, x, y) for(ll i = (ll)x; i < (ll)y; i++)
#define DREP(i, x, y, d) for(ll i = (ll)x; i < (ll)y; i += (ll)d)
#define PER(i, x, y) for(ll i = (ll)x; i > (ll)y; i--)
#define DPER(i, x, y, d) for(ll i = (ll)x; i > (ll)y; i -= (ll)d)
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};
double pi = 3.141592653589793;
ll mod = 1000000007;
int intmax = 2147483647;
int intmin = -2147483648;
ll llmax = 9223372036854775807;
ll llmin = -9223372036854775807;
int iinf = intmax / 8;
ll inf = llmax / 8;
double eps = 1e-12;

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    string S;
    cin >> S;
    ll len = S.size();
    ll lose = 0;
    REP(i, 0, len) {
        if (S[i] == 'x') {
            lose++;
        }
    }
    if (lose >= 8) {
        cout << "NO" << endl;
    } else {
        cout << "YES" << endl;
    }
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define MOD 1000000007
#define INF 1e9
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(void){
    int P,R,Q;
    cin>>P>>R>>Q;
    int ans=min({P+R,R+Q,Q+P});

    cout<<ans<<endl;
}

Measured memory_bytes: 256