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

#define ll long long
#define vi vector<int>
#define vl vector<ll>
#define pii pair<int,int>
#define pll pair<ll,ll>
// pll pp; -> (pp.first,pp.second)
// vector<vl> pp(n,vl(2)); sort(pp.begin(),pp.end(),[](vl a,vl b){return a[0]<b[0];});

#define REP(i,n) for(ll (i)=0;(i)<(n);(i)++)
#define RREP(i,n) for(ll (i)=(n)-1;(i)>=0;(i)--)
#define FOR(i,a,b) for(ll (i)=(a);(i)<(b);(i)++)
#define FORR(i,a,b) for(ll (i)=(b)-1;(i)>=(a);(i)--)
#define DEBUG(x) cout << #x << ": " << x << endl
#define CHMAX(a,b) a=max((a),(b))
#define CHMIN(a,b) a=min((a),(b))
/*}}}*/
ll MOD = 1e9+7;
int main() {
  ll x,y;
  cin >> x >> y;
  if(x>y) swap(x,y);
  if((x+y)%3!=0){
    cout << 0 << endl;
    return 0;
  }
  if(y > x*2){
    cout << 0 << endl;
    return 0;
  }
  ll n = (x+y)/3;
  ll xi = x-n;

  vl modinv(1e7);
  modinv[1] = 1;
  FOR(i,2,modinv.size()){
    modinv[i] = modinv[MOD%i]*(MOD-MOD/i)%MOD;
  }
  ll ans = 1;
  REP(i,xi){
    ans *= n-i;
    ans %= MOD;
    ans *= modinv[i+1];
    ans %= MOD;
  }
  cout << ans<< endl;
  return 0;
}


Measured memory_bytes: 78336
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,sse4,popcnt,abm,mmx")

#include <bits/stdc++.h>
#define pb push_back
#define pp pop_back()
#define mp make_pair
#define f first
#define s second
#define y1 yasfasf
#define kz ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define FILE "substring"

#define fr freopen(FILE".in", "r", stdin); freopen(FILE".out", "w", stdout);
using namespace std;
typedef pair <int, int> pii;
typedef long long ll;
typedef unsigned long long ull;
typedef unsigned int ui;
typedef struct node* treap;

const int N = 1e5 + 11, inf = 1e9;
const ll linf = 1e18, mod = 1e9 + 7;

int n, m, k;

int main(){
	cin >> n >> m >> k;
	for(int i = 0; i <= n; ++i)
	for(int j = 0; j <= m; ++j){
		if(i * m + j * n - 2 * i * j == k){
			cout << "Yes";
			return 0;
		}
	}
	cout << "No";
	return 0;
}           

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <map>
#include <queue>
#include <string>
#include <algorithm>
#include <cmath>
#include <climits>
#define REP(i, n) for(int i=0; i<(n); i++)
#define FOR(i, a, n) for(int i=(a); i<(n); i++)
using namespace std;

int main(){
    int a,b,c;cin>>a>>b>>c;string ans=c>=a&&c<=b?"Yes":"No";cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
     
int main() {
  
  int N, M, ans;
  cin >> N >> M;
  vector<int> foods(M);
  
  for (int i = 0; i < M ; i++)
    foods.at(i) = 0;
  
  
  for (int i = 0; i < N ; i++){
  
    int K;
    cin >> K;
    
    for (int j = 0; j < K ; j++){
      
      int A;
      cin >> A;
      foods.at(A - 1)++;
    
    }
  }
  
  for (x:foods){
    if (x == N)
      ans++;
  }
  
  cout << ans <<endl;
}

Measured memory_bytes: 256
#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>

using namespace std;

#define LL long long

int main()
{

    int a;
    while(~scanf("%d",&a))
    {
       int flag = 0;
        if(a>81)
        printf("No\n");
        else
        {

            for(int i=1;i<=9;i++)
            {

                if(a%i==0&&a/i<=9)
                    flag = 1;

            }
            if(flag == 1)
                printf("Yes");
            else
                printf("No\n");
        }
    }
}


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

int main() {

    int a,b;
    
    for(int i = 0; ; i++){
        cin >> a >> b;
        if(a == 0 && b == 0){
            return 0;
        }
        
        //各枠の最上列部分
        for(int i = 0;i < b ; i++){
            if(i == b-1){
                    cout << "#" << endl;
            }
            else cout << "#";
        }
        
        //中段部分
        for(int i = 1;i < a-1 ; i++){
            for(int i = 0;i < b ; i++){
                if(i == b-1){
                    cout << "#" << endl;
                }
                else if(i == 0)cout << "#";
                else cout << ".";
            }
        }
        
        //各枠の最下列部分
        for(int i = 0;i < b ; i++){
            if(i == b-1){
                    cout << "#" << endl;
            }
            else cout << "#";
        }
        cout << endl;
    }

}


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

//{ START
using namespace std;
#define int int64_t
#define rep(i, a, n) for (int i = (a); i < (n); ++i)
#define reps(i, a, n) for (int i = (a); i > (n); --i)
#define arep(i, x) for (auto &&i : (x))
#define irep(i, x) for (auto i = (x).begin(); i != (x).end(); ++i)
#define rirep(i, x) for (auto i = (x).rbegin(); i != (x).rend(); ++i)
//降順はgreater<T>()
#define all(x) (x).begin(), (x).end()
#define rv(s) reverse((s).begin(), (s).end())
// gcd lcmはそのままok
#define gcd(a, b) __gcd(a, b)
#define bits(n) (1LL << (n))
#define pcnt(x) __builtin_popcountll(x)
//配列内等要素削除
#define unique(x) (x).erase(unique((x).begin(), (x).end()), (x).end())
#define Fixed(n) fixed << setprecision(n)
//総和
#define sowa(n) ((n) * ((n) + 1)) / 2
#define pb(x, a) (x).push_back(a)
#define fb(x, a) (x).push_front(a)
#define eb(x, a) (x).emplace_back(a)
#define cauto const auto &
using P = pair<int, int>;
using Graph = vector<vector<P>>;
template <class T>  //昇順
using min_heap = priority_queue<T, vector<T>, greater<T>>;
template <class T>  //降順
using max_heap = priority_queue<T>;
template <class A, class B>
using umap = unordered_map<A, B>;
template <class A>
using uset = unordered_set<A>;
template <typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val) {  //多次元初期化
  std::fill((T *)array, (T *)(array + N), val);
}
template <class A, class B>
bool chmax(A &a, const B &b) {  //最大値更新 返り値はbool
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class A, class B>
bool chmin(A &a, const B &b) {  //最小値更新 返り値はbool
  if (b < a) {
    a = b;
    return 1;
  }
  return 0;
}
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};
constexpr int INF = 0x3f3f3f3f;
constexpr int LINF = 0x3f3f3f3f3f3f3f3fLL;
constexpr int mod1 = 1e9 + 7;
constexpr int mod2 = 998244353;
//} END

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

  int n, m, k;
  cin >> n >> m >> k;
  vector<int> x(n + 1), y(m + 1), a(m + 1);
  rep(i, 1, n + 1) cin >> x[i];
  rep(i, 1, m + 1) {
    cin >> y[i];
    a[i] += a[i - 1] + y[i];
  }

  int ans = 0, cnt = 0;

  rep(i, 0, n + 1) {
    cnt += x[i];

    int left = -1, right = m + 1;
    while (right - left > 1) {
      int mid = (left + right) / 2;

      if (cnt + a[mid] <= k)
        left = mid;
      else
        right = mid;
    }
    if (left != -1) chmax(ans, i + left);
  }

  cout << ans << '\n';
  return 0;
}

Measured memory_bytes: 7900
#include<iostream>
#include<algorithm>
#include<vector>
#include<string>
#include<list>
using namespace std;
using ll = long long;
int main() {
	string S;
	int K;
	cin >> S;
	cin >> K;
	vector<string>V;
	for (int i = 0; i < S.size(); ++i) {
		for (int j = 1; i + j <= S.size(); ++j) {
			if (j <= 5)
				V.push_back(S.substr(i, j));
		}
	}
	sort(V.begin(), V.end());
	unique(V.begin(), V.end());
	cout << V[K-1] << endl;
	return 0;
}

Measured memory_bytes: 1660
#include<stdio.h>
int main(){
    int a[1000],n, i;
    scanf("%d", &n);
    for(i = 0; i<n; i++)
    scanf("%d" ,&a[i]);
    for(i=1; i<=n; i++){
    printf("%d" ,a[n-i]);
    if(i==n)
    printf("\n");
    else
    printf(" ") ; }
    return 0;
}


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

int main() {
  int a,b;
  int c=0;
  cin>>a>>b;
  vector<int> d(a);
  for(int i=0;i<a;i++){
    cin>>d.at(i);
  }
  for(int i=0;i<a;i++){
    if(d.at(i)>=b){
      c++;
    }
  }
  cout<<c<<endl;
} 

Measured memory_bytes: 640
import bisect
n,Q,L,R = map(int,input().split())
a = list(map(int,input().split()))
a.sort()
p = []
for i in range(Q):
    p.append(tuple(map(int,input().split())))


def f(z):
    for q,x,s,t in p:
        if q == 1:
            if z >= x:
                z = t*(z+s)
        else:
            if z <= x:
                if z-s < 0:
                    z = -(abs(z-s)//t)
                else:
                    z = (z-s)//t

    return z


ng = pow(2,63)
ok = -ng

for i in range(100):
    mid = (ok+ng)//2
    if f(mid) <= R:
        ok = mid
    else:
        ng = mid

right = ok        

ok = pow(2,63)
ng = -ok
        
for i in range(100):
    mid = (ok+ng)//2
    if f(mid) >= L:
        ok = mid
    else:
        ng = mid
left = ok

k1 = bisect.bisect_left(a,left)
k2 = bisect.bisect_right(a,right)


print(k2-k1)



Measured memory_bytes: 44696
#include <bits/stdc++.h>
#define ll long long int
#define mp make_pair
#define pb push_back
#define ld long double
#define pii pair<int,int>
#define sz(x) (int)x.size()
#define piii pair<pii,pii>
#define precise cout<<fixed<<setprecision(10)
#define st first
#define nd second
#define ins insert
#define vi vector<int>
#define BOOST ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)
using namespace std;

int32_t main()
{
  BOOST;
  ll x,y;
  cin>>x>>y;
  ll start=x;
  ll ans=0;
  while (true)
  {
  	if (start>y)break;
  	ans++;
  	start*=2;
  }
  cout<<ans;
  return 0;
}


Measured memory_bytes: 256
import java.io.*;
import java.util.*;
import java.math.*;
 
public class Main {
        Scanner sc = new Scanner(System.in);
 
        void run() {
                int N = sc.nextInt();
                int M = sc.nextInt();
                double L[] = new double[N];
                double a[] = new double[N];
                double b[] = new double[N];
 
                for (int i = 0; i < N; i++) {
                        L[i] = sc.nextDouble();
                        a[i] = sc.nextDouble();
                        b[i] = sc.nextDouble();
                }
 
                double map[][] = new double[N][N];
 
                for (int i = 0; i < N; i++) {
                        for (int j = i; j < N; j++) {
                                map[i][j] = (L[i] - L[j]) * (L[i] - L[j]);
                                map[i][j] += (a[i] - a[j]) * (a[i] - a[j]);
                                map[i][j] += (b[i] - b[j]) * (b[i] - b[j]);
                                map[j][i] = map[i][j];
                        }
                }
 
                double dp[] = new double[1 << N];
                double max = 0;
                for (int i = 0; i < 1 << N; i++) {
                        // if(Integer.bitCount(i) >= M){
                        // continue;
                        // }
                        for (int j = 0; j < N; j++) {
                                int shj = 1 << j;
 
                                if ((i & shj) != 0) {
                                        continue;
                                }
                                double sum = 0;
                                for (int z = 0; z < N; z++) {
                                        int shz = 1 << z;
 
                                        if ((i & shz) == 0) {
                                                continue;
                                        }
                                        sum += map[j][z];
                                }
 
                                dp[i | shj] = Math.max(dp[i | shj], dp[i] + sum);
                                if (Integer.bitCount(i | shj) == M) {
                                        max = Math.max(dp[i | shj], max);
                                }
                        }
                }
//              System.out.println(Arrays.toString(dp));
                System.out.println(max);
        }
 
        public static void main(String[] args) {
                Main m = new Main();
                m.run();
        }
 
}
 

Measured memory_bytes: 21000
/*Points to be noted :
1)Don't be afraid to fail.
2)Never give up easily,keep trying.
3)Don't care about other ppl's progress.
4)Spend much time on each problem & keep trying. I WILL DO IT!💯*/

// Mere bas ka nahi hai
// still i'm trying
// apna time aayega
//
//        .--------------.  
//        | Try First One|
//        '--------------'
//                |     .--------------.
//                |     |              |
//                V     V              |
//              .--------------.       |
//              |      AC.     |<---.  |  
//              '--------------'    |  |
//              (True)|  |(False)   |  |
//           .--------'  |          |  |
//           |           V          |  |
//           |  .--------------.    |  |
//           |  |   Try Again  |----'  |
//           |  '--------------'       |
//           |                         |
//           |  .--------------.       |
//           '->| Try Next One |-------'
//              '--------------'                          		  
//


#include<bits/stdc++.h>
using namespace std;
//#include <boost/multiprecision/cpp_int.hpp>
//using namespace boost::multiprecision;
//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_policy.hpp>
//using namespace __gnu_pbds;
#define int long long int
#define ld long double
#define ull unsigned long long
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define r0 return 0;
#define tc int t;cin>>t;while(t--)
#define for0(i, n) for (int i = 0; i < n; i++)
#define for1(i, n) for (int i = 1; i <= n; i++)
#define loop(i,a,b) for (int i = a; i < b; i++)
#define vi vector<int>
#define vii vector<long long int>
#define SORT(v) sort(v.begin(),v.end());
#define PI 3.1415926535897932384626433832795
#define mod 1000000007
#define md 998244353
#define inf 1000000000000000 //1e15
#define gcd __gcd
#define lcm(a,b) ((a)*(b))/gcd(a,b)
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
#define crap ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define endl "\n"
int min(int a,int b){
    return (a<b)?a:b;
}
int max(int a,int b){
    return (a>b)?a:b;
}
int fp(int a,int b){
    if(b==0) return 1;
    int x=fp(a,b/2);
    x=(x*x)%mod;
    if(b&1) x=(x*a)%mod;
    return x;
}
int factorial(int n)
{
    int fact=1;
    for(int i=2;i<=n;i++)
    fact=fact*i;
    
    return fact;
}
int ncr(int n,int r)
{
    return factorial(n)/(factorial(r)*factorial(n-r));
}
void c_p_c()
{
    crap;
#ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#endif
}
void constructXOR(int A[], int n) 
{ 
    // calculate xor of array 
    int XOR = 0; 
    for (int i = 0; i < n; i++) 
        XOR ^= A[i]; 
  
    // update array 
    for (int i = 0; i < n; i++) 
        A[i] = XOR ^ A[i]; 
} 
  
signed main()
{
    c_p_c();
    int n;
    cin>>n;
    int a[n];
    for(int i=0;i<n;i++)
        cin>>a[i];
    constructXOR(a,n);
    for(int i=0;i<n;i++)
        cout<<a[i]<<" ";
    

}

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

int main() {
	int A, B;
	string op;
	
	cin >> A >> op >> B;
	
	if(op == "+"){
		cout << A + B << endl;
	}
	else if(op == "-"){
		cout << A - B << endl;
	}
}


Measured memory_bytes: 256
def main():
    N, K = map(int, input().split())
    if K%2 == 1:
        ans = (N//K)**3
        print(ans)
        return
    Kdiv2list = N//(K//2)
    Klist = N//K
    ans = Klist**3 + (Kdiv2list-Klist)**3
    print(ans)

if __name__ == "__main__":
    main()


Measured memory_bytes: 3060
#include <iostream>
#include <algorithm>
#include <cmath>
#include <map>
#include <vector>
#include <queue>
#include <functional>
#include <string>
#include <stack>
#include <set>
using namespace std;
using ll = long long;
typedef unsigned long long ull;
typedef pair<ll, ll> P;
typedef pair<ll, pair<ll, ll>> PP;

const ll MOD = 1e9 + 7;
const ll MOD2 = 998244353;
const ll INF = 1 << 30;
const ll INF2 = 9e18;
const double INF3 = 9e14;
const int dx[4] = { 1,0,-1,0 }, dy[4] = { 0,1,0,-1 };
const int tx[8] = { -1,0,1,-1,1,-1,0,1 }, ty[8] = { -1,-1,-1,0,0,1,1,1 };
#define ALL(x) (x).begin(),(x).end()
#define pb push_back
#define fr first
#define sc second



int main() {
	int n, a[100000];
	cin >> n;
	for (int i = 0; i < n; i++) {
		cin >> a[i];
	}
	int ans = n, b = 0, c = 0, d = 0, flag = 0;
	for (int i = 0; i < n; i++) {
		if (a[i] % 2 == 1) {
			b += 1;
		}
		else if (a[i] % 2 == 0) {
			if (a[i] / 2 % 2 == 1) {
				c += 1;
			}
			else {
				d += 1;
			}
		}
	}
	if (c == 0) {
		if (d + 1 >= b) {
			cout << "Yes" << endl;
		}
		else {
			cout << "No" << endl;
		}
	}
	else {
		b += 1;
		if (d + 1 >= b) {
			cout << "Yes" << endl;
		}
		else {
			cout << "No" << endl;
		}
	}
	return 0;
}


Measured memory_bytes: 640
N,D=map(int,input().split())
X=list(list(map(int,input().split())) for _ in range(N))
ans=0
for i in range(N):
    for j in range(N):
        dist=0
        dist=float(dist)
        if i!=j:
            for k in range(D):
                dist+=(X[i][k]-X[j][k])**2
            dist=dist**0.5
            if dist.is_integer()==True:
                    ans+=1
print(ans//2)

Measured memory_bytes: 3064
#include<iostream>
#include<string>
#include<algorithm>
#include<cmath>
using namespace std;
int main() {
	int a, b = 1, c, d = 0, e = 0;
	string s;
	cin >> s;
	for (int h = 0; h < s.size(); h++) {
		if (h % 2 == 0) {
			cout << s[h];
		}
	}
	cin >> e;
}

Measured memory_bytes: 512
N, K = list(map(int, input().split()))
A_list = list(map(int, input().split()))

l = [-1] * N
loopcnt = 0
inicnt = 0
place = 1
i = 0
l[place - 1] = 0

while i < K:
    i += 1
    next_place = A_list[place - 1]
    place = next_place
    if l[next_place - 1] != -1:
        loopcnt = i - l[next_place - 1]
        inicnt = l[next_place - 1]
        break
    else:
        l[next_place - 1] = i
if i >= K:
    print(place)

else:
    last_move_cnt = (K - inicnt) % loopcnt

    j = 1
    while j <= last_move_cnt:
        j += 1
        next_place = A_list[place - 1]
        place = next_place
    print(place)

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

// 1,6,9,36,81,216,729,1296,6561,7776,46656,59049
int dp[100010];
int f(int i){
	if(i < 0) return 100000;
	else if(dp[i] >= 0) return dp[i];
	else if(i == 0) {
		dp[i] = 0;
		return 0;
	}
	else{
		dp[i]=min({f(i-1),f(i-6),f(i-9),f(i-36),f(i-81),f(i-216),f(i-729),f(i-1296),f(i-6561),f(i-7776),f(i-46656),f(i-59049)})+1;
		return dp[i];
	}
}

int main(){
	int n;
	cin >> n;
	memset(dp, -1, sizeof(dp));
	int ans = f(n);
	cout << ans << "\n";
	return 0;
}

Measured memory_bytes: 8448
#include<bits/stdc++.h>
using namespace std;
#define nl '\n' 
#define fast ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define ll long long int
#define pii pair <int,int>
ll mod=1000000007;
int main()
{
	fast;
	int n;cin>>n;
	double ans;
	if(n==1)
		ans=1;
	else if(n%2==0)
		ans=(double)(n/2)/n;
	else
		ans=(double)((n/2) +1)/n;
	cout<<fixed<<setprecision(10)<<ans;
}

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

int n, m, w[105];

bool check(int x){
    int cnt = 1, sum = 0;
    REP(i,n){
        if(sum+w[i] <= x) sum += w[i];
        else{
            if(w[i] > x)return false;
            cnt++;
            sum = w[i];
        }
    }
    return cnt <= m;
}

int main() {
    while(cin >> m >> n, n){
        REP(i,n) cin >> w[i];
        int ok = 1500000, ng = 0;
        while(abs(ok-ng)>1){
            int mid = (ok+ng)/2;
            if(check(mid)) ok = mid;
            else ng = mid;
        }
        cout << ok << endl;
    }
    return 0;
}   



Measured memory_bytes: 3084
import core.bitop, std.algorithm, std.ascii, std.bigint, std.conv, std.math,
    std.functional, std.numeric, std.range, std.stdio, std.string, std.random,
    std.typecons, std.container, std.format;

// dfmt off
T lread(T = long)(){return readln.chomp.to!T();}
T[] lreads(T = long)(long n){return generate(()=>readln.chomp.to!T()).take(n).array();}
T[] aryread(T = long)(){return readln.split.to!(T[])();}
void scan(TList...)(ref TList Args){auto line = readln.split();
foreach (i, T; TList){T val = line[i].to!(T);Args[i] = val;}}
alias sread = () => readln.chomp();enum MOD = 10 ^^ 9 + 7;
alias PQueue(T, alias less = "a<b") = BinaryHeap!(Array!T, less);
// dfmt on

void main()
{
    long N = lread();
    auto A = lreads(N);
    A[] -= 1;
    auto visited = new bool[](N);
    long ans;
    long cur = 0;
    while (cur != 1)
    {
        if (visited[cur])
        {
            writeln(-1);
            return;
        }
        visited[cur] = true;
        cur = A[cur];
        ans++;
    }
    writeln(ans);
}


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

using namespace std;
using ll = long long;
using ld = long double;

//#define int long long
//signed main(){
int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int x;
    cin >> x;
    if(x<1200) cout << "ABC" << "\n";
    else cout << "ARC" << "\n";
    return 0;
}

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

#define lli long long int
#define pb push_back
#define f first
#define sec second

bool compare(const pair<lli,lli> &i, const pair<lli,lli> &j )
{
    return i.sec <= j.sec;
}

main()
{
    lli n,i,j,a,b,c,t,cap,w,val,sum=0;
    vector<pair<lli,lli>> v;

    cin>>n>>cap;

    for(i=0;i<n;i++)
    {
        cin>>a>>b;
        v.pb({b,a});
        sum += b;
    }

    lli dp[sum+1];
    dp[0] = 0;

    for(i=1;i<=sum;i++)
    {
        dp[i] = cap+1;
    }

    for(i=0;i<n;i++)
    {
        for(j=sum;j>=v[i].f;j--)
        {
            if(dp[j-v[i].f] < cap)
            {
                dp[j] = min(dp[j-v[i].f]+v[i].sec, dp[j]);
            }
        }
    }

    for(i=sum;i>=0;i--)
    {
        if(dp[i]<=cap)
        {
            cout<<i;
            return 0;
        }
    }
}


Measured memory_bytes: 1024
n=int(input())
a,b=[],[]
for i in range(n):
    ta,tb=map(int,input().split())
    a.append(ta);b.append(tb)
a=sorted(a);b=sorted(b)

if n%2==1:
    print(b[n//2]-a[n//2]+1)
else:
    ca=(a[n//2-1]+a[n//2])
    cb=(b[n//2-1]+b[n//2])
    print(cb-ca+1)

Measured memory_bytes: 26988
#include<bits/stdc++.h>
#include<string.h>
 
typedef long long int ll;
#define all(x) (x).begin(), (x).end()
 
using namespace std;

int nxt() {
    int x;
    cin >> x;
    return x;
}

ll nxtl(){
    ll x;
    cin>>x;
    return x;
}
 
void SieveOfEratosthenes(int n,vector <int> &primes) 
{ 
    // Create a boolean array "prime[0..n]" and initialize 
    // all entries it as true. A value in prime[i] will 
    // finally be false if i is Not a prime, else true. 
    bool prime[n+1]; 
    memset(prime, true, sizeof(prime)); 
  
    for (int p=2; p*p<=n; p++) 
    { 
        // If prime[p] is not changed, then it is a prime 
        if (prime[p] == true) 
        { 
            // Update all multiples of p greater than or  
            // equal to the square of it 
            // numbers which are multiple of p and are 
            // less than p^2 are already been marked.  
            for (int i=p*p; i<=n; i += p) 
                prime[i] = false; 
        } 
    } 
  
    // Print all prime numbers 
    for (int p=2; p<=n; p++) 
       if (prime[p]) 
          primes.push_back(p);
} 
 
ll max(ll a,ll b)
{
    if(a>b)
        return a;
    return b;
}
 
ll power(ll x, ll y,ll mod) 
{ 
    ll temp; 
    if( y == 0) 
        return 1; 
    temp = power(x, y/2,mod); 
    if (y%2 == 0) 
        return (temp*temp)%mod; 
    else
        return (((x*temp)%mod)*temp)%mod; 
}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int a=nxt(),b=nxt();
    if(a%2==b%2)
        cout<<(a+b)/2<<endl;
    else
        cout<<"IMPOSSIBLE\n";
    
    
    return 0;   
}


 
 


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N = 3000 + 10, mod = 998244353;
ll f[N][N][2];
void add(ll &x,ll y){
    (x += y) %= mod;
}
int main(){
    ios::sync_with_stdio(0);
    int a,b,c,d; cin>>a>>b>>c>>d;
    f[a][b][0] = 1;
    for(int i=a;i<=c;i++){
        for(int j=b;j<=d;j++){
            add(f[i+1][j][0],f[i][j][0]*j);
            add(f[i][j+1][1],f[i][j][0]*i);
            add(f[i+1][j][0],f[i][j][1]);
            add(f[i][j+1][1],f[i][j][1]*i);
        }
    }
    ll ans = 0;
    add(ans,f[c][d][0]);
    add(ans,f[c][d][1]);
    cout<<ans<<endl;
}


Measured memory_bytes: 144672
#include <bits/stdc++.h>
#define int long
#define ll long long
#define rep(i, n) for(int i = 0; i < n; i++)
using namespace std;
int gcd(int a,int b){return b ? gcd(b,a%b) : a;}
int lcm(int a,int b){return a/gcd(a,b)*b;}

main() {
    string S; cin >> S; int ans=0;
    rep(i,S.size()-1){
        if(S[i]!=S[i+1]){
            ans++;
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
#define MOD 1000000007
//#define MOD 998244353
#define INF 1145141919810893364
//#define INF 810114514
//#define PI 3.141592653589
typedef pair<int,int> PP;
typedef long long ll;
#define int ll
#define setdouble setprecision
#define REP(i,n) for(int i=0;i<(n);++i)
#define OREP(i,n) for(int i=1;i<=(n);++i)
#define RREP(i,n) for(int i=(n)-1;i>=0;--i)
#define GOODBYE do { cout << "No" << endl; return 0; } while (false)
#define MM <<" "<<
#define Endl endl

int gcd(int a,int b){
    if(a<=0||b<=0){
        return 0;
    }
    if(a<b)swap(a,b);
    int r=a%b;
    while(r){
        a=b;
        b=r;
        r=a%b;
    }
    return b;
}

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


signed main(void){
    int N,M;
    int A[114514];
    int B[114514]={};
    cin >> N >> M;
    REP(i,N){
        cin >> A[i];
        A[i]/=2;
        while(A[i]%2==0){
            B[i]++;
            A[i]/=2;
        }
    }
    bool c=true;
    REP(i,N){
        if(B[0]!=B[i]){
            c=false;
        }
    }
    if(!c){
        cout << 0 << endl;
        return 0;
    }
    
    int L=A[0];
    REP(i,N){
        L=lcm(L,A[i]);
        if(L>4*M)break;
    }
    while(B[0]>0){
        B[0]--;
        L*=2;
        
        if(L>4*M){
            cout << 0 << endl;
            return 0;
        }
    }
    //cout << L << endl;
    
    int Ans=(M)/L;
    Ans-=(M)/(2*L);
    cout << Ans << endl;
    
    return 0;
}



Measured memory_bytes: 1920
#include<bits/stdc++.h>
#include<bits/stdc++.h>
#include<iomanip>
using namespace std;
typedef long long ll;
typedef long  l;
typedef pair<int,int> P;
#define rep(i,n) for(int i=0;i<n;i++)
#define fs first
#define sc second
#define pb push_back
#define mp make_pair
#define eb emplace_back
#define ALL(A) A.begin(),A.end()
const int INF=1000000001;
const double PI=3.141592653589;


int main(){
  int x,a,b; cin>>x>>a>>b;
  int ans=(x-a)%b;
  cout<<ans<<endl;
  return 0;
}


Measured memory_bytes: 256
n = int(input())
abc = [list(map(int, input().split())) for _ in range(n)]

dp = [[0] * 3 for _ in range(n + 1)]

for i in range(n):
    for now in range(3):
        for prev in range(3):
            if now == prev:
                continue

            dp[i+1][now] = max(dp[i+1][now], dp[i][prev] + abc[i][now])

ans = max(dp[-1])
print(ans)


Measured memory_bytes: 50108
local mod = 1000000007
local mfl, mce = math.floor, math.ceil
local function badd(x, y) return (x + y) % mod end
local function bmul(x, y)
  local x1, y1 = mfl(x / 31623), mfl(y / 31623)
  local x0, y0 = x - x1 * 31623, y - y1 * 31623
  return (x1 * y1 * 14122 + (x1 * y0 + x0 * y1) * 31623 + x0 * y0) % mod
end
local n = io.read("*n")
local edge, edgetask = {}, {}
local asked = {}
local white, black = {}, {}
for i = 1, n do
  edge[i] = {}
  edgetask[i] = 0
  asked[i] = false
  white[i] = 0
  black[i] = 0
end
for i = 1, n - 1 do
  local p, q = io.read("*n", "*n")
  edge[p][q], edge[q][p] = true, true
  edgetask[p] = edgetask[p] + 1
  edgetask[q] = edgetask[q] + 1
end
local tasks = {1}
for i = 2, n do
  if edgetask[i] == 1 then
    table.insert(tasks, i)
    black[i] = 1
    white[i] = 1
  end
end
while 0 < #tasks do
  local src = tasks[#tasks]
  table.remove(tasks)
  asked[src] = true
  local all, whites = 1, 1
  local bs, ws = {}, {}
  for dst, _u in pairs(edge[src]) do
    if asked[dst] then
      -- child
      table.insert(bs, black[dst])
      table.insert(ws, white[dst])
    else
      -- parent
      edgetask[dst] = edgetask[dst] - 1
      if edgetask[dst] == 1 and dst ~= 1 then
        table.insert(tasks, dst)
      end
    end
  end
  local w, b = 1, 1
  for i = 1, #bs do
    w = bmul(w, badd(bs[i], ws[i]))
    b = bmul(b, ws[i])
  end
  white[src] = w
  black[src] = b
end
print(badd(black[1], white[1]))


Measured memory_bytes: 29292
#include <iostream>
#include <cstdio>
#include <vector>
#include <queue>
#include <algorithm>

using namespace std;
#define inf 101010
typedef pair<int,int> pii;
typedef pair<double,pii> pp;

int main(void){
    int n,m,p,a,b;
    while (cin>>n>>m>>p>>a>>b && n) {
        a--, b--;
        vector<int> t(n);
        for (int i = 0; i < n; i++) cin >> t[i];
        vector<vector<pii> > g(m, vector<pii>());
        for (int i = 0; i < p; i++) {
            int x,y,z;
            cin>>x>>y>>z;
            x--, y--;
            g[x].push_back(make_pair(y,z));
            g[y].push_back(make_pair(x,z));
        }
        sort(t.begin(), t.end());
        
        vector<vector<double> > d(m, vector<double>(1<<n, inf));
        priority_queue<pp, vector<pp>, greater<pp> > que;
        que.push(make_pair(0.0, make_pair(a, (1<<n)-1)));
        
        double ans = inf;
        while (!que.empty()) {
            pp p = que.top(); que.pop();
            double cost = p.first;
            int cur = p.second.first, bit = p.second.second;
            if (cur == b) {
                ans = cost;
                break;
            }
            if (cost > d[cur][bit]) continue;
            
            for (int i = 0; i < g[cur].size(); i++) {
                int to = g[cur][i].first, len = g[cur][i].second;
                for (int j = 0; j < n; j++) {
                    if (bit & 1<<j) {
                        double x = len / (double)t[j];
                        int nbit = bit & ~(1<<j);
                        if (cost+x >= d[to][nbit]) continue;
                        d[to][nbit] = cost+x;
                        que.push(make_pair(cost+x, make_pair(to, nbit)));
                    }
                }
            }
        }
        if (ans == inf) cout << "Impossible" << endl;
        else printf("%.8lf\n",ans);
    }
}

Measured memory_bytes: 4632
import math


class Vector2():
    def __init__(self, x, y):
        self.x = x
        self.y = y

    def __add__(self, v):
        return Vector2(self.x+v.x, self.y+v.y)

    def __sub__(self, v):
        return Vector2(self.x-v.x, self.y-v.y)

    def __mul__(self, v):
        return Vector2(self.x*v, self.y*v)

    def __truediv__(self, v):
        return Vector2(self.x/v, self.y/v)

    def __abs__(self):
        return math.sqrt(float(self.x*self.x+self.y*self.y))

    def __str__(self):
        return f"({self.x},{self.y})"

    def __lt__(self, v):
        if math.isclose(self.x, v.x):
            return self.y < v.y
        return self.x < v.x

    def dot(self, v):
        return self.x*v.x+self.y*v.y

    def cross(self, v):
        return self.x*v.y-self.y*v.x

    def norm(self):
        d = abs(self)
        return Vector2(self.x/d, self.y/d)


def projection(v1, v2, p):
    v12 = (v2-v1).norm()
    v1p = p-v1
    d = v12.dot(v1p)
    return v1+v12*d


def distanceLP(v1, v2, p):
    '''
    v1 -> v2の直線とpとの距離
    '''
    return abs((v2-v1).cross(p-v1))/abs(v2-v1)


def distanceSP(v1, v2, p):
    '''
    v1 -> v2の線分とpとの距離
    '''
    if (v2-v1).dot(p-v1) < 0.0:
        return abs(p-v1)
    if (v1-v2).dot(p-v2) < 0.0:
        return abs(p-v2)
    return distanceLP(v1, v2, p)


def ccw(p0, p1, p2):
    c = (p1-p0).cross(p2-p0)
    if math.isclose(c, 0.0, abs_tol=1e-10):
        d = (p1-p0).dot(p2-p0)
        if d < 0.0:
            return -1
        else:
            d1 = abs(p1-p0)
            d2 = abs(p2-p0)
            if d1 < d2:
                return 1
            else:
                return 0
    elif c < 0.0:
        return -1
    else:
        return 1


def intersect(p1, p2, p3, p4):
    '''
    p1p2とp3p4の交差判定
    '''
    #t1 = (p1.x-p2.x)*(p3.y-p1.y)+(p1.y-p2.y)*(p1.x-p3.x)
    #t2 = (p1.x-p2.x)*(p4.y-p1.y)+(p1.y-p2.y)*(p1.x-p4.x)
    #t3 = (p3.x-p4.x)*(p1.y-p3.y)+(p3.y-p4.y)*(p3.x-p1.x)
    #t4 = (p3.x-p4.x)*(p2.y-p3.y)+(p3.y-p4.y)*(p3.x-p2.x)
    # return (t1*t2) <= 0.0 and (t3*t4) <= 0.0
    c1 = ccw(p1, p2, p3)*ccw(p1, p2, p4)
    c2 = ccw(p3, p4, p1)*ccw(p3, p4, p2)
    return c1 <= 0.0 and c2 <= 0.0


def distance(a1, a2, b1, b2):
    '''
    線分a1a2とb1b2の距離
    '''
    if intersect(a1, a2, b1, b2):
        return 0.0
    return min([
        min([distanceSP(a1, a2, b1), distanceSP(a1, a2, b2)]),
        min([distanceSP(b1, b2, a1), distanceSP(b1, b2, a2)])
    ])


cx1, cy1, r1 = map(int, input().split())
cx2, cy2, r2 = map(int, input().split())

c1 = Vector2(cx1, cy1)
c2 = Vector2(cx2, cy2)
c12 = c2-c1
d = abs(c12)
# 余弦定理
a = math.acos((r1*r1+d*d-r2*r2)/(2*r1*d))
t = math.atan2(c12.y, c12.x)
a1 = c1+Vector2(math.cos(t+a)*r1, math.sin(t+a)*r1)
a2 = c1+Vector2(math.cos(t-a)*r1, math.sin(t-a)*r1)
ans = ""
for a in sorted([a1, a2]):
    ans += f"{a.x:.8f} {a.y:.8f} "
print(ans.strip())



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

using namespace std;

int seen[100000];

int dfs(vector<int> &v,int n,int nowv){
  if(nowv >= n-1)return 0;
  if(v[nowv] < v[nowv+1])return 0;
  if(seen[nowv] != -1)return seen[nowv];
  int res = 0;
  res += dfs(v,n,nowv+1) + 1;
  return seen[nowv] = res;
}

int main(){
  int n;
  cin >> n;
  vector<int> v(n);
  memset(seen,-1,sizeof(seen));
  for(int i = 0;i < n;i++)cin >> v[i];
  int res = -1;
  for(int i = 0;i < n;i++){
    res = max(dfs(v,n,i),res);
  }
  cout << res;
  return 0;
}

Measured memory_bytes: 2560
n = int(input())
T = 0
H = 0
        
for i in range(n):
    x = str(input())
    x = x.split()
    if x[0] == x[1]:
        T += 1
        H += 1
    elif x[0] < x[1]:
        H += 3
    elif x[0] > x[1]:
        T += 3
    
print(T,H)


Measured memory_bytes: 5592
#include <bits/stdc++.h>
#define ll long long int
#define ld long double
#define vl vector<ll>
#define pll pair<ll,ll>
#define mll map<ll, ll> 
#define rep(i,a)  for(ll i= 0;i < a;i++)
#define rep1(i,a) for(ll i= 1;i < a;i++)
#define foi(i, a, b)    for(ll i = a; i<b ; i++)
#define fod(i, a, b)    for(ll i = a; i>=b ; i--)
#define pb push_back
#define sz(v) v.size()
#define all(a) a.begin(), a.end()
#define max3(a, b, c)   max(max(a, b), c)
#define min3(a, b, c)   min(min(a, b), c)
#define MAX 1e6+5
#define MOD 1000000007
#define el "\n"
const ll INF = 2e9+5;
  
ll gcd(ll a, ll b){if(b==0)return a;return gcd(b, a%b);}
ll lcm(ll a, ll b){return a*b/gcd(a, b);}
ll isPrime(ll n){if(n<=3) return 1;if(n%2==0||n%3==0) return 0;
for(ll j=5;j*j<=n;j+=6){if(n%j == 0||n%(j+2) == 0) return 0;}return 1;}
 
using namespace std;
void solve(){
   ll h,w;
   cin>>h>>w;
   char arr[h][w];
   rep(i,h)rep(j,w){
      char c; 
      cin>>c;
      arr[i][j] = c;
   }
   // rep(i,h)rep(j,w)cout<<arr[i][j];
   vector<vector<ll>> dp(h,vector<ll>(w,0));
   ll i=0,j=0;
   while(i<h&&arr[i][0] != '#') {dp[i][0] = 1;i++;}
   while(j<w&&arr[0][j] != '#') {dp[0][j] = 1;j++;}
   rep1(i,h)rep1(j,w){
      if(arr[i][j] == '#') continue;
      else if(arr[i][j-1] == '#')  dp[i][j] = dp[i-1][j];
      else if(arr[i-1][j] == '#')  dp[i][j] = dp[i][j-1];
      else dp[i][j] = (dp[i-1][j]%MOD + dp[i][j-1]%MOD)%MOD;
      dp[i][j] %= MOD;
   }
   cout<<dp[h-1][w-1];

}
 
int main() {
   #ifndef ONLINE_JUDGE
      freopen("input.txt", "r" , stdin);
      freopen("output.txt", "w" , stdout);
   #endif
   ios::sync_with_stdio(0); 
   cin.tie(0); cout.tie(0);   
   ll t;
   // cin>>t;
   t = 1;
   ll tc=0;
   while(tc++<t){
      // cout<<"Case #"<<tc<<": ";
      solve();
   }
   cerr<<"Time taken : "<<(double)clock()/CLOCKS_PER_SEC<<" secs"<<endl;
   return 0;
}

Measured memory_bytes: 12024
#include <bits/stdc++.h>
typedef long long ll;
#define rep(i,n) for(ll i = 0; i < (n); ++i )
#define rep_rev(n,i) for(ll i = n; i >= 0; --i )
using namespace std;
const long long INF = 1LL << 60;

int a[100000];

int main(){
  int N; cin >> N;
  rep(i,N) cin >> a[i];
  map<int,int> mp;
  rep(i,N) mp[a[i]]++;
  int ans = 0;
  for(auto p :mp){
    int x = p.first;
    int y = p.second;
    if(y < x) ans += y;
    else ans += y - x;
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 5120
import math
n = float(input())
m_low = math.ceil(n / 1.08)
m_high = math.floor((n+1)/1.08)
if m_low > m_high:
  print(':(')
else:
  ch_low = math.floor(m_low*1.08)
  ch_high = math.floor(m_high*1.08)
  if ch_low == int(n):
    print(m_low)
  elif ch_high == int(n):
    print(m_high)
  else:
    print(':(')

Measured memory_bytes: 9060
//    >File Name: 2.cpp
//    > Author: Webwei

#include<bits/stdc++.h>
using namespace std;
int main()
{
	int x,y,z;
	cin >> x >> y >> z;
	int sum = 1;
	x-=z;
	sum=(x/(y+z));
	cout << sum << '\n';
	return 0;
}


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

int main() {
	ios::sync_with_stdio(0);
	cin.tie(0);
	
	string a, b;
	cin >> a >> b;
	int c = stoi(a + b);
	for (int i = 1; i <= 1000; i++) {
		if (i * i == c) {
			cout << "Yes" << '\n';
			return 0;
		}
	}
	cout << "No" << '\n';
	
	return 0;
}


Measured memory_bytes: 256
#!/usr/bin/env python3
import sys
INF = float("inf")


def solve(N: int, W: int, w: "List[int]", v: "List[int]"):
    DP = [[0]*(W+1) for _ in range(N+1)]

    for i in range(N):
        for j in range(W+1):
            DP[i+1][j] = DP[i][j]
            if j-w[i] >= 0:
                DP[i+1][j] = max(DP[i+1][j], DP[i][j-w[i]]+v[i])
    print(DP[N][W])
    return


def main():

    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    W = int(next(tokens))  # type: int
    w = [int()] * (N)  # type: "List[int]"
    v = [int()] * (N)  # type: "List[int]"
    for i in range(N):
        w[i] = int(next(tokens))
        v[i] = int(next(tokens))
    solve(N, W, w, v)


if __name__ == '__main__':
    main()


Measured memory_bytes: 118512
N,M,C=map(int,input().split())
B=[int(i) for i in input().split()]
cnt=0
for i in range(N):
  A=[int(i) for i in input().split()]
  sum=0
  for j in range(M):
    sum += A[j]*B[j]
  sum += C  
  if sum > 0:
    cnt+=1
print(cnt)

Measured memory_bytes: 3060
if __name__ == '__main__':
    MODULO = 10**9 + 7
    res_arr = [0, 0, 0, 1, 1, 1, 2]
    # if (S < 7):

    S = int(input())
    for i in range(7, S+1):
        res = 0
        for k in range(3, i-3 + 1):
            res = (res + res_arr[k]) % MODULO
        res_arr.append(res + 1)
    print(res_arr[S])


Measured memory_bytes: 64760
import collections
INF = 10**18
h,w,n = map(int,input().split())
li = [list(input()) for i in range(h)]
num = [0]*9
def bfs(sy,sx,gy,gx):
    d = [[INF]*w for i in range(h)]
    dx = [1,0,-1,0]
    dy = [0,1,0,-1]
    d[sy][sx] = 0
    que = collections.deque([])
    que.append((sy,sx))
    while que:
        y,x = que.popleft()
        for i in range(4):
            ny = y + dy[i]
            nx = x + dx[i]
            if 0<=nx<w and 0<=ny<h:
                if li[ny][nx] != "X" and d[ny][nx] == INF:
                    que.append((ny,nx))
                    d[ny][nx] = d[y][x] + 1
    return d[gy][gx]

for i in range(h):
    for j in range(w):
        if li[i][j] == "S":
            sy = i
            sx = j
        if li[i][j] == "1":
            gy = i
            gx = j
        elif li[i][j] == "2":
            num[1] = [i,j]
        elif li[i][j] == "3":
            num[2] = [i,j]
        elif li[i][j] == "4":
            num[3] = [i,j]
        elif li[i][j] == "5":
            num[4] = [i,j]
        elif li[i][j] == "6":
            num[5] = [i,j]
        elif li[i][j] == "7":
            num[6] = [i,j]
        elif li[i][j] == "8":
            num[7] = [i,j]
        elif li[i][j] == "9":
            num[8] = [i,j]
ans = bfs(sy,sx,gy,gx)
num[0] = [gy,gx]
for i in range(n-1):
    sy,sx = num[i]
    gy,gx = num[i+1]
    ans += bfs(sy,sx,gy,gx)
print(ans)


Measured memory_bytes: 35452
#include<iostream>
#include<string>
using namespace std;
int main(){
    int k;
    string s;
    cin>>k;
    cin>>s;
    int len=s.length();
    if(len<=k){
        cout<<s<<endl;
    }else{
        cout<<s.erase(k)<<"..."<<endl;
    }
    return 0;
}

Measured memory_bytes: 3100
package main

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

func out(x ...interface{}) {
	fmt.Println(x...)
}

var sc = bufio.NewScanner(os.Stdin)

func getInt() int {
	sc.Scan()
	i, e := strconv.Atoi(sc.Text())
	if e != nil {
		panic(e)
	}
	return i
}

func getString() string {
	sc.Scan()
	return sc.Text()
}

func main() {
	sc.Split(bufio.ScanWords)
	sc.Buffer([]byte{}, 1000000)

	w := bufio.NewWriter(os.Stdout)
	defer w.Flush()

	N, K, S := getInt(), getInt(), getInt()
	S2 := S + 1
	if S == 1000000000 {
		S2 = 1
	}
	for i := 0; i < N; i++ {
		if i < K {
			fmt.Fprint(w, S, " ")
		} else {
			fmt.Fprint(w, S2, " ")
		}
	}
	fmt.Fprintln(w)
}


Measured memory_bytes: 4096
import java.util.*;
public class Main{
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        Node nodes[] = new Node[n];
        for(int i = 0 ; i < n ; i++)
            nodes[i] = new Node(i);
        for(int i = 0 ; i < n ; i++){
            int index = sc.nextInt();
            int l = sc.nextInt();
            int r = sc.nextInt();
            if(l != -1)
                nodes[index].left = nodes[l];
            if(r != -1)
                nodes[index].right = nodes[r];
        }
	for(int i = 0 ; i < n ; i++){
		if(nodes[i].right != null)
		    nodes[i].right.parent = nodes[i];
		if(nodes[i].left != null)
		    nodes[i].left.parent = nodes[i];
	}
        for(int i = 0 ; i < n ; i++)
            System.out.println("node " + nodes[i].index + ": parent = " + nodes[i].get_parent() + ", sibling = " + nodes[i].sibling() + ", degree = " + nodes[i].degree() + ", depth = " + nodes[i].depth() + ", height = " + nodes[i].height() + ", " + nodes[i].type());
    }
}
class Node{
    int index;
    Node parent = null;
    Node left = null;
    Node right = null;
    int get_parent(){
        if(parent == null)
            return -1;
        else
            return parent.index;
    }
    int depth(){
        if(parent == null)
            return 0;
        else
            return parent.depth() + 1;
    }
    int degree(){
        int count = 0;
        if(left != null)
            count++;
        if(right != null)
            count++;
        return count;
    }
    int sibling(){
        if(parent == null)
            return -1;
        else{
            if(parent.right == null || parent.left == null)
                return -1;
            else{
                if(parent.right.index == this.index)
                    return parent.left.index;
                else
                    return parent.right.index;
            }
        }
    }
    int height(){
        if(right == null && left == null)
            return 0;
        else if(left == null)
            return right.height()+1;
        else if(right == null)
            return left.height()+1;
        else
            return Math.max(right.height(),left.height())+1;
    }
    String type(){
        if(parent == null)
            return "root";
        else if(left == null && right == null)
            return "leaf";
        else
            return "internal node";
    }
    Node(int index){
        this.index = index;
    }
}


Measured memory_bytes: 26252
#include <algorithm>
#include <iostream>
#include <iomanip>
#include <cstring>
#include <string>
#include <vector>
#include <queue>
#include <cmath>
#include <stack>
#include <set>
#include <map>
typedef long long ll;
typedef unsigned int uint;
using namespace std;

int main(){
  //string str = "ABC";
  //int a = (int)str[0];
  //cout << a << endl;

  string str;
  cin >> str;
  int N = str.size();

  if(str[0]!='A'){
    cout << "WA" << endl;
    return 0;
  }

  int cntC = 0;
  int posC;
  for(int i=0;i<N;i++){
    if(str[i]=='C'){
      cntC++;
      posC = i;
    }
  }
  if(cntC!=1 || posC<2 || N-2<posC){
    cout << "WA" << endl;
    return 0;
  }

  int cntbig = 0;
  for(int i=0;i<N;i++){
    int tmp = (int)str[i];
    if(65<=tmp && tmp<=90){
      cntbig++;
    }
  }
  if(cntbig!=2){
    cout << "WA" << endl;
    return 0;
  }

  cout << "AC" << endl;
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long
#define ull unsigned long long
#define MP make_pair
#define PII pair<int, int>
#define PLL pair<ll, ll>
#define PLI pair<ll, int>
#define PIL pair<int, ll>
#define STR string
#define Fst first
#define Snd second
#define SHN 1e9
#define LSHN 1e18
using namespace std;
int a[100010],d[100010];
int n,k;
int main()
{
	cin >>n>>k;
	for (int i=0;i<n;i++) cin >>a[i];
	fill(d,d+n,1e9);
	d[0]=0;
	for (int i=0;i<n-1;i++)
	{
		for (int j=1;j<=k;j++)
		{
			if (i+j==n) break;
			d[i+j]=min(d[i+j],d[i]+abs(a[i+j]-a[i]));
		}
	}
	cout <<d[n-1];
	return 0;
}

Measured memory_bytes: 1024
import java.util.Scanner;
class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    int n = sc.nextInt();
    int[] mon = new int[n + 1];
    int[] brave = new int[n];
    for(int i = 0 ; i < n + 1 ; i++){
      mon[i] = Integer.parseInt(sc.next());
    }
    long cnt = 0L;
    for(int i = 0 ; i < n ; i++){
      brave[i] = Integer.parseInt(sc.next());
      if(brave[i] > mon[i]){
        cnt += mon[i];
        brave[i] -= mon[i];

        if(brave[i] >= mon[i + 1]){
          cnt += mon[i + 1];
          mon[i + 1] = 0;
        }else{
          cnt += brave[i];
          mon[i + 1] -= brave[i];
        }

      }else{
        cnt += brave[i];
      }
    }
    System.out.println(cnt);
  }
}




Measured memory_bytes: 50708
#include <bits/stdc++.h>
using namespace std;
using namespace std::chrono;
#define idfc ios_base::sync_with_stdio(false),cin.tie(nullptr),cout.tie(nullptr)
//:/
#define pb push_back
#define mp make_pair
#define nt _ll128
#define ld double
long double PI =3.14159265;
using ll = long long;

const ll modo=1e9+7;
const ll ms=1e6+5;
const ll inf=1e17;


ll fac[ms];
int ar[ms];
int br[ms]={0};
int ans[ms];
ll modpow(ll a,ll b)
{
    ll r=1;
    while(b)
    {
        if(b&1)
        {
            r=(r*a)%modo;
        }
        a=(a*a)%modo;
        b>>=1;
    }
    return r;
}

void check()
{
    int i;
    fac[0]=1;
    for(i=1;i<=1000000;i++)
    {
        fac[i]=(i*fac[i-1])%modo;
    }
}

int ncr(ll n,int r)
{
    if(r>n)return 0;
    ll p=(fac[r]*fac[n-r])%modo;
   // cout<<p<<"\n";
    n=(fac[n]*modpow(p,modo-2))%modo;
    return n;
}



int main()
{
    idfc;

    check();

    int n;
    cin>>n;
    int i;

    for(i=1;i<=(n+1);i++)
    {
        cin>>ar[i];
        br[ar[i]]++;
    }
    int a;
    int b;
    for(i=1;i<=(n+1);i++)
    {
        if(br[ar[i]]>1)
        {
            a=i;break;
        }
    }
    for(i=n+1;i>=1;i--)
    {
        if(br[ar[i]]>1)
        {
            b=n+1-i;break;
        }
    }

    for(i=1;i<=(n+1);i++)
    {
        ans[i]=ncr(n+1,i);
   //     cout<<ans[i]<<"\n";
    }
    //cout<<a<<" "<<b<<"\n";
    for(i=1;i<=(a+b);i++)
    {
        ans[i]=ans[i]+modo-ncr(a+b-1,i-1);
        ans[i]%=modo;
    }
    for(i=1;i<=n+1;i++)cout<<ans[i]<<"\n";


    return 0;
}

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



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

Measured memory_bytes: 3604
#include <bits/stdc++.h>
using namespace std;
int main(){
	int w, h; cin >> w >> h;
	vector<pair<int,int> > e;
	for(int i = 0; i < w; i++){
		int x; cin >> x;
		e.push_back({x, 0});
	}
	for(int i = 0; i < h; i++){
		int x; cin >> x;
		e.push_back({x, 1});
	}
	long long ans = 0;
	int cw = 0, ch = 0;
	sort(e.begin(), e.end());
	for(auto p : e){
		int x, o; tie(x, o) = p;
		if(o){
			ans += 1ll * (w - cw + 1) * x;
			ch++;
		} else {
			ans += 1ll * (h - ch + 1) * x;
			cw++;
		}
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 2420