akhauriyash/Code-Regression huggingface dataset:
#include <cstdio>
#include <algorithm>
#include <cstring>
#include <stack>

using namespace std;

stack<char>st;
bool ch[110];
char s[110];
int fr,en;

int main()
{
	int n;
	scanf("%d",&n);
	scanf("%s",s + 1);
	for(int i = 1;i <= n;i++)
	{
		if(st.empty())
		{
			st.push(i);
			continue;
		}
		if(s[st.top()] == '(' && s[i] == ')')st.pop();
		else st.push(i);
	}
	while(st.size())
	{
		if(s[st.top()] == '(')en++;
		else fr++;
		st.pop();
	}
	for(int i = 1;i <= fr;i++)printf("(");
	printf("%s",s + 1);
	for(int i = 1;i <= en;i++)printf(")");
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define all(x) (x).begin(),(x).end()
typedef long long ll;
#define rep(i,n) for(ll i=0, i##_len=(n); i<i##_len; ++i)
#define REP(i,num,n) for(ll i=num, i##_len=(n); i<i##_len; ++i)
#define reprrev(i,a,b) for(int i=b-1;i>=a;i--)
#define reprev(i,n) reprrev(i,0,n)
using namespace std;
#define sz(x) ((int)(x).size())
#define ZERO(a) memset(a,0,sizeof(a))
#define MINUS(a) memset(a,0xff,sizeof(a))
#define MEMSET(v, h) memset((v), h, sizeof(v))
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
#define pb push_back
#define mp make_pair
#define y0 y3487465
#define y1 y8687969
#define j0 j1347829
#define j1 j234892
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
const ll INF = 1LL<<60;
 
const int MAX = 510000;
const int MOD = 1000000007;
 
long long fac[MAX], finv[MAX], inv[MAX];
 
// テーブルを作る前処理
void COMinit() {
	fac[0] = fac[1] = 1;
	finv[0] = finv[1] = 1;
	inv[1] = 1;
	for (int i = 2; i < MAX; i++) {
		fac[i] = fac[i - 1] * i % MOD;
		inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
		finv[i] = finv[i - 1] * inv[i] % MOD;
	}
}
 
// 二項係数計算
long long COM(int n, int k) {
	if (n < k) return 0;
	if (n < 0 || k < 0) return 0;
	return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}
 
struct UnionFind {
	vector<int> par, rank;
 
	UnionFind(int n) : par(n, -1), rank(n, 0) { }
	void init(int n) { par.assign(n, -1), rank.assign(n, 0); }
 
	int root(int x) {
		if (par[x] == -1) return x;
		else return par[x] = root(par[x]);
	}
 
	bool issame(int x, int y) {
		return root(x) == root(y);
	}
 
	bool merge(int x, int y) {
		x = root(x); y = root(y);
		if (x == y) return false;
		if (rank[x] < rank[y]) swap(x, y);
		if (rank[x] == rank[y]) ++rank[x];
		par[y] = x;
		return true;
	}
};
 
int main() {
	ll N;
	cin >> N;
  	vector<ll> h(N);
  	rep(i, N) cin >> h[i];
  	vector<ll> dp(N);
  	rep(i,N) dp[i] = INF;
  	dp[0] = 0;
  	REP(i, 1, N){
      chmin(dp[i], dp[i - 1] + abs(h[i] - h[i - 1]));
	  if(i > 1)chmin(dp[i], dp[i - 2] + abs(h[i] - h[i - 2]));
    }
	
	cout << dp[N-1] << endl;
}

Measured memory_bytes: 1792
#include <stdio.h>
int main(void)
{
	int a,b;
	char op;

	while(1){
	scanf("%d %c %d",&a,&op,&b);

	if ( op =='?')
	   break;
	else if ( op =='+'){
	   printf("%d\n",a+b);
	}else if ( op =='-'){
	   printf("%d\n",a-b);
	}else if ( op =='*'){
	   printf("%d\n",a*b);
	}else if ( op =='/'){
	   printf("%d\n",a/b);
	}
   }

	return 0;
}


Measured memory_bytes: 2100
#include <iostream>
#include <string>
#include <map>
#include <algorithm>
using namespace std;

int N; string S; map<pair<string, string>, int>M;
long long ret = 0;

int main() {
	cin >> N >> S;
	for (int i = 0; i < (1 << N); i++) {
		string T1 = "", T2 = "";
		for (int j = 0; j < N; j++) {
			if ((i / (1 << j)) % 2 == 0) T1 += S[N + j];
			else T2 += S[N + j];
		}
		M[make_pair(T1, T2)]++;
	}
	for (int i = 0; i < (1 << N); i++) {
		string T1 = "", T2 = "";
		for (int j = 0; j < N; j++) {
			if ((i / (1 << j)) % 2 == 0) T1 += S[j];
			else T2 += S[j];
		}
		reverse(T1.begin(), T1.end());
		reverse(T2.begin(), T2.end());
		ret += M[make_pair(T2, T1)];
	}
	cout << ret << endl;
	return 0;
}

Measured memory_bytes: 87040
#include <iostream>
#include <string>
#include <map>
#include <algorithm>
#define int long long
signed main(){
 int N,ans=0,tv;
 std::cin>>N;
 std::string temp;
 std::map <std::string,int> dictionary;
 for(int i=0;i<N;i++){
   std::cin>>temp;
   std::sort(temp.begin(),temp.end());
   dictionary[temp]++;
 }
 for(auto itr = dictionary.begin(); itr != dictionary.end(); ++itr) {
   tv=itr->second;
   ans+=tv*(tv-1)/2;
}
std::cout<<ans<<std::endl;
}


Measured memory_bytes: 11136
import std.stdio;
import std.string;
import std.conv;
import std.typecons;
import std.algorithm;
import std.functional;
import std.bigint;
import std.numeric;
import std.array;
import std.math;
import std.range;
import std.container;

void main() {
    while(true) {
        int n = readln.chomp.to!int;
        if (n==0) break;
        long[] p = readln.split.to!(long[]);
        long[] j = readln.split.to!(long[]);

        int[] ary = (n-1).iota.array;
        sort!((a,b)=>a[1]>b[1])(zip(ary, j.dup));
        long sum = p.sum;
        long num = n;
        foreach(e; ary) {
            if ((sum+j[e])*(num-1) > sum*num) {
                sum += j[e];
                num--;
            } else {
                break;
            }
        }
        writeln(sum*num);
    }
}

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

int main() {
  int a, b;
  cin >> a >> b;
  if(a >= 13){
    cout << b << endl;
  }
  else if(a >= 6 && a <= 12){
    cout << b/2 << endl;
  }
  else if(a <= 5){
    cout << 0 << endl;
  }
}

Measured memory_bytes: 256
import java.util.*;

class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		
		int n = sc.nextInt();
		int[] l1 = new int[n];
		for (int i = 0; i < n; i++) {
			l1[i] = sc.nextInt();
		}
		Arrays.sort(l1);
		
		int q = sc.nextInt();
		int[] l2 = new int[q];
		for (int i = 0; i < q; i++) {
			l2[i] = sc.nextInt();
		}
		Arrays.sort(l2);
		
		int count = 0;
		
		for (int i = 0, j = 0; i<n && j<q; i++) {
			if (l1[i] == l2[j]) {
				count++;
				j++;
			}else if (l1[i]>l2[j]) {
				i--;
				j++;
			}
		}
		
		System.out.println(count);
		
		
		
	}
}


Measured memory_bytes: 68652
object Main extends App {
  io.StdIn.readLine().toInt % 7 match {
    case 0 => println("thu")
    case 1 => println("fri")
    case 2 => println("sat")
    case 3 => println("sun")
    case 4 => println("mon")
    case 5 => println("tue")
    case 6 => println("wed")
  }
}


Measured memory_bytes: 43804
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int M=1e9+7;
int f[65][2][2],dl[65],dr[65];
ll l,r;
int dfs(int pos,bool fl,bool fr){
	if (!pos) return 1;
	int &t=f[pos][fl][fr];
	if (~t) return t;
	t=0;int up=fr?dr[pos]:1,dn=fl?dl[pos]:0;
	for (int y=0;y<=up;y++)
		for (int x=dn;x<=y;x++) (t+=dfs(pos-1,fl && x==dn,fr && y==up))%=M;
	return t;
}
int solve(ll l,ll r){
	int lenl=0,lenr=0;
	for (;l;l>>=1) dl[++lenl]=l&1;
	for (;r;r>>=1) dr[++lenr]=r&1;
	int ans=0;
	for (int i=lenl;i<=lenr;i++) (ans+=dfs(i-1,i==lenl,i==lenr))%=M;
	return ans;
}
signed main(){
	memset(f,-1,sizeof(f));
	scanf("%lld%lld",&l,&r);
	printf("%d",solve(l,r));
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <vector>
#include <map>

using namespace std;
typedef long long int ll;

int a[1000000];

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

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

    map <int, int> mp;
    for(int i=0; i<N; i++){
        mp[a[i]]++;
    }

    int ans = 0;
    for(auto p:mp){
        int x = p.first;
        int n = p.second;
        if(n<x) ans += n;
        else ans += n-x;
    }

    cout << ans << endl;
}

Measured memory_bytes: 5120
#include<iostream>
#include<string>
#include<string.h>
#include<cstring>
#include<math.h>
#include<iomanip>
#include<vector>
#include<cmath>
#include<algorithm>
#include<numeric>
#include<cctype>
#include<utility>
#include<set>
#include<map>
#include<sstream>
#include<iterator>
#include<limits>
#include<map>
#include<deque>
#include<stack>
#include<queue>
using namespace std;
#define pb push_back
#define ff(i,a,b) for(int i=a;i<b;++i)
#define ffl(i,a,b) for(long long i=a;i<b;++i)
#define all(v) v.begin(), v.end() 
#define X first
#define Y second
#define mp make_pair
typedef long long ll;
typedef std::vector<int> vec;
typedef std::vector<long long> vecl;
typedef map<int,int> mii;
typedef map<ll,ll> mll;
typedef std::pair<int,int> pii;
typedef pair<ll,ll> pll; 
const int md = 1000000007;
#define pi 3.141592653589793238462643383279


int main() {
	ios_base::sync_with_stdio(false); 
    cin.tie(NULL);    
    
 	int tt{},T{};
 	//cin>>tt;T=tt;
    tt=1;
 	while(tt--){
        //cout<<"------------- #"<<T-tt<<endl;
        ll n{},m{},ans{},k{},a{},b{},c{},f{};
        
        cin>>n;k=2;
        vecl v(n);
        ffl(i,0,n)cin>>v[i];
        ll dp[n+1];
        ffl(i,1,n)dp[i]=md;
        dp[0]=0;
        ffl(i,0,n){
            ffl(j,i+1,i+k+1){
                if(j<n)
                    dp[j]=min(dp[j],dp[i]+abs(v[j]-v[i]));
            }
        }
        cout<<dp[n-1]<<"\n";;
        
    }
    
    
	return 0;
}

Measured memory_bytes: 4788
#include <iostream>
using namespace std;
int main(){
  //int a,b;
  float a,b,c;
  cin >> a >> b;
  c=a/(b*2+1);
  int d=c;
  if(c==d){
  	cout << d << endl;
  }else{
    cout << d+1 << endl;
  }
}

Measured memory_bytes: 256
#include <algorithm>
#include <bitset>
#include <cmath>
#include <ctime>
#include <iostream>
#include <list>
#include <map>
#include <math.h>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <stdio.h>
#include <string>
#include <tuple>
#include <vector>
using namespace std;
#define rep(i,n) for(int i = 0; i < (n); i++)
#define all(a) begin(a),end(a)
typedef long long ll;
typedef pair<int,int> P;
const int inf=1e+9;
const ll mod=1000000007;
const double PI=3.14159265358979323846;
int dx[] = {1,-1,0,0};
int dy[] = {0,0,1,-1};
ll gcd(ll a, ll b){
  if (b==0) return a;
  else return gcd(b,a%b);
}
int cans(bool f){
  if(f) cout << "Yes" << endl;
  else cout << "No" << endl;
  return 0;
}




int main() {
  int k,a,b;
  bool f = false;
  cin >> k >> a >> b;
  for(int i = a; i <= b; i++) {
    if(i%k==0)
      f=true;
  }
  if(f) cout << "OK" << endl;
  else cout << "NG" << endl;
  
  return 0;
}


Measured memory_bytes: 3132
h, n = map(int, input().split())
ab = [tuple(map(int, input().split())) for _ in range(n)]
dp = [[0] * (h+1) for _ in range(n+1)]
for j in range(1, h+1): dp[0][j] = float("inf")

for i in range(1, n+1):
    for j in range(1, h+1):
        a, b = ab[i-1]
        dp[i][j] = min(dp[i-1][j], dp[i][max(0, j-a)] + b)

print(dp[-1][-1])


Measured memory_bytes: 119900
# coding: utf-8
# Your code here!
N,M=map(int,input().split())

memo=[[10**9] for i in range(N)]

for _ in range(M):
    a,b=map(int,input().split())
    memo[a-1].append(b-1)

ans=0
kill=10**9
for i in range(N):
    if i==kill:
        #print(i)
        ans+=1
        kill=10**9
    kill=min(kill,min(memo[i]))
print(ans)

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

#define rep(i,x,y) for(ll i=(x);i<(y);i++)
#define rrep(i,x,y) for(ll i=(ll)(y)-1;i>=(x);i--)
#define all(x) (x).begin(),(x).end()
#define itrout(x) for(int i=0;i<x.size();i++) {cout << x[i] << (i==x.size()-1 ? "\n" : " ");}
#ifdef LOCAL
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl
#define debugbit(x, n) cerr << #x << " = " << bitset<n>(x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl
#define itrdebug(x) cerr << #x << " "; for (auto & el : (x)) {cerr << (el) << " ";} cerr << endl
#define dassert(...) assert(__VA_ARGS__)
#else
#define debug(x)
#define debugbit(x, n)
#define itrdebug(x)
#define dassert(...)
#endif
//#define int long long

typedef long long ll;
const ll MOD = 1e9 + 7;
const long double EPS = 1e-8;

void solve(long long X, long long K, long long D){
    X = abs(X);
    if (D <= X / K) {
        cout << X - K * D << endl;
        return;
    }
    K -= (X - X % D) / D;
    assert(K >= 0);
    X = X % D;
    if (K % 2 == 1) {
        X = min(abs(X-D), abs(X+D));
    }
    cout << abs(X) << endl;
}

signed main(){
    // ios_base::sync_with_stdio(false);
    // cin.tie(NULL);
    long long X;
    scanf("%lld",&X);
    long long K;
    scanf("%lld",&K);
    long long D;
    scanf("%lld",&D);
    solve(X, K, D);
    return 0;
}


Measured memory_bytes: 3736
#include<stdio.h>
#include<stdlib.h>

int cmp(const void *x, const void *y) {
  return *(int *)y - *(int *)x;
}

int main() {
  int n;
  scanf("%d", &n);
  int *a = malloc(sizeof(int) * n);
  int *tmp = malloc(sizeof(int) * n);
  int i;
  for(i = 0; i < n; i++) {
    scanf("%d", &a[i]);
    tmp[i] = a[i];
  }
  qsort(a, n, sizeof(int), cmp);
  // for(i = 0; i < n; i++) printf("%d\n", a[i]);
  for(i = 0; i < n; i++) {
    if(tmp[i] != a[0]) printf("%d\n", a[0]);
    else               printf("%d\n", a[1]);
  }
  return 0;
}

Measured memory_bytes: 3120
#define _CRT_SECURE_NO_WARNINGS

#include<stdio.h>
#include<iostream>
#include<cmath>
#include<cstdlib>
#include<vector>
#include<string>
#include<string.h>
#include<algorithm>
using namespace std;

int main() {
	int N=0;
	int a = 0;
	int b = 0;
	int c = 0;
	cin >> N;
	//a,b,cの導出
	a = (N - N % 100) / 100;//2^2
	b = (N % 100-N%10)/10;//2^1
	c = N % 10;//2^0桁目



	if (a==c) {
	
		cout << "Yes"<< endl;
	}
	else {
		cout << "No" << endl;
	}


	return 0;
}


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

// nCr mod を計算する O(n)
const int MAX_N = 1000010;
ll fac[MAX_N], finv[MAX_N], inv[MAX_N];
// テーブルを作る前処理
void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX_N; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}
// 二項係数計算
long long COM(int n, int k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}


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

    COMinit();

    for(ll i=1;i<=k;i++){
        ll ans=COM(k-1,i-1);
        ll tmp=COM(n-k+1,i);
        ans=(ans*tmp)%MOD;
        cout<<ans<<endl;
    }
}


Measured memory_bytes: 27080
#pragma GCC optimize("O2")
#include <bits/stdc++.h>
// #include <iostream>
// #include <array>
// #include <cmath>
// #include <array>
// #include <vector>
// #include <set>
// #include <algorithm>
// #include <functional>
// #include <numeric>
// #include <map>
// #include <unordered_map>
// #include <queue>
using namespace std;
// #define MOD  998244353
// #define MOD ll(1e9) + 7
#define ll long long
const double PI = atan(1.0) * 4;
// const int N = 1e5 + 5 ;
// const ll INF = (int)1e9 ;
const int dx[4] = { -1, 0, 1, 0} ;
const int dy[4] = {0, -1, 0, 1} ;
// const ll INF = (ll)2e18 + 50;
const ll INF = 1e9 ;
const ll MOD = 1e9 + 7 ;

ll power(ll a , ll e) {
	ll res = 1LL ;
	while (e > 0) {
		if (e % 2 == 1) res = res * a % MOD ;
		a =  a * a % MOD ;
		e /= 2 ;
	}
	return res ;
}
vector<int> complement(const vector<int> &vec) {
	int n = vec.size() ;
	vector<bool> occur(n + 1 , true) ;
	vector<int> ans ;
	for (int i = 0 ; i < (int)vec.size() ; i++) {
		occur[vec[i]] = false ;
	}
	for (int i = 1 ; i <= n ; i++) {
		if (occur[i]) ans.push_back(i) ;
	}
	return ans ;
}

int main() {
	ios::sync_with_stdio(0);
	cin.tie(0);
#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif
	// int t ;
	// cin >> t;
	// while (t--) {
	vector<ll> a(5) ;
	for (int i = 0 ; i < 5 ; i++) {
		cin >> a[i] ;

	}
	for (int i = 0 ; i < 5 ; i++) {
		if (a[i] == 0) {
			cout << i + 1 << "\n";
			exit(0) ;
		}

	}

	// }
	// return 0;
}


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

#define REP(i, n) for(int i = 0; i < (int)(n); i++)
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define SORT(v, n) sort(v, v+n)
#define pb(a) push_back(a)
#define eb(a) emplace_back(a)
#define vi vector<int>
#define ddvi vector<vector<int>>

using namespace std;
typedef long long ll;
typedef pair<int, int> P;

int main(){
	#define int ll
	cin.tie(0);
	ios::sync_with_stdio(false);
	// ここに処理を記述

	int K, N;
	cin >> K >> N;

	vector<int> A;
	int temp = 0;
	for(int i=0; i<N; i++){
			cin >> temp;
			A.emplace_back(temp);
	}

	// 隣り合う2軒の距離の差が最大な組を選ぶ
	int max_dst = 0;
	REP(i,N){
		if(i == N-1){
			max_dst = max(max_dst, abs(A[0] + (K - A[i])));
		}
		else{
			max_dst = max(max_dst, abs(A[i] - A[i+1]));
		}
	}

	cout << K - max_dst << "\n";

	return 0;
}

Measured memory_bytes: 3444
#include <stdio.h>  
#include <algorithm>  
#include <assert.h>
#include <bitset>
#include <cmath>  
#include <complex>  
#include <deque>  
#include <functional>  
#include <iostream>  
#include <limits.h>  
#include <map>  
#include <math.h>  
#include <queue>  
#include <deque>
#include <set>  
#include <stdlib.h>  
#include <string.h>  
#include <string>  
#include <time.h>  
#include <unordered_map>  
#include <unordered_set>  
#include <vector>  
#include <chrono>
#include <random>
#include <time.h>
#include <fstream>
#define ll long long
#define rep2(i,a,b) for(ll i=a;i<=b;++i)
#define rep(i,n) for(ll i=0;i<n;i++)
#define rep3(i,a,b) for(ll i=a;i>=b;i--)
#define pii pair<int,int>
#define pll pair<ll,ll>
#define pq priority_queue<int>
#define pqg priority_queue<int,vector<int>,greater<int>>
#define pb push_back
#define vec vector<int>
#define vecll vector<ll>
#define vecpii vector<pii>
#define endl "\n"
#define all(c) begin(c),end(c)
using namespace std;
int in() {int x;scanf("%d",&x);return x;}
ll lin() {ll x;scanf("%lld",&x);return x;}
void print(vec v){for(auto e:v)cout<<e<<" ";cout<<endl;}
void print(vecll v){for(auto e:v)cout<<e<<" ";cout<<endl;}
void print(map<int,int> mp){for(auto e:mp)cout<<e.first<<" "<<e.second<<endl;cout<<endl;}


#define INF 1e9+7
#define LLINF 1e18+7
const ll MOD=1e9+7;
const int N=500000;

main(){
    int n=in();
    vec a;
    rep(i,n){
        a.pb(in());
    }
    vec now={0,0,0};
    ll ans=1;
    rep(i,n){
        ll cnt=0;
        rep(j,3){
            if(now[j]==a[i])cnt++;
        }
        ans=ans*cnt%MOD;
        rep(j,3){
            if(now[j]==a[i]){
                now[j]++;
                break;
            }
        }
    }
    cout<<ans;
}

Measured memory_bytes: 892
#include <iostream>
#include <vector>
#include <map>

int main(){
 int N;
 std::cin>>N;
 std::vector<int> A(N);
 for(int i=0;i<N;i++){
  std::cin>>A[i];
 }
 
 std::map<int,int> sum;
 long long ans=0;
 for(int i=0;i<N;i++){
  ans+=sum[i-A[i]];
  sum[i+A[i]]++;
 }
 std::cout<<ans<<std::endl;
 
 return 0;
}

Measured memory_bytes: 21012
#include<bits/stdc++.h>
#define rep(n) for(int i=0;i<(n);i++)
#define rep1(n) for(int i=1;i<=(n);i++)
#define all(n) n.begin(),n.end()
#define fi first
#define se second
#define lb lower_bound
#define ub upper_bound
#define int ll
using namespace std;
using ll=long long;
using pii=pair<int,int>;
#define pb push_back
ll dp[10005][105];
const ll mod = 1000000007;

signed main(){
    dp[0][0] = 1;
    string s;
    int d;
    cin>>s;
    cin>>d;
    int siz = s.size();
//assert(siz<=7);
    for(int i=1;i<=siz;i++){
      for(int j=0;j<d;j++){
        for(int k=0;k<10;k++){
          int tmp = j-k;
          tmp = (tmp%d+d)%d;
          dp[i][j] += dp[i-1][tmp];
          dp[i][j] %= mod;
        }
      }
    }

        int nsiz = siz;
        int acu = 0;
        int idx = 0;
        ll ans = 0;
        nsiz--;
        while(nsiz>=0){
          for(int i=0;i<s[idx]-'0';i++){
            int tmp = -i-acu;
            tmp = (tmp%d+d)%d;
            //cout<<nsiz<<" "<<tmp<<'\n';
            ans += dp[nsiz][tmp];
            ans %= mod;
          }
          acu += s[idx]-'0';
          idx++;
          nsiz--;
        }



        if(acu%d==0)ans++;
        ans--;

        cout<<(ans+mod)%mod<<'\n';



}


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

signed main() {
	int n, x, cnt = 0;
	while (cin >> n >> x and n) {
		cnt = 0;
		for (int i = 1; i <= n; ++i) {
			for (int j = 1; j <= n; ++j) {
				for (int k = 1; k <= n; ++k) {
					if (i < j and j < k and i + j + k == x) cnt++;
				}
			}
		}
	cout << cnt << endl;
	}
}



Measured memory_bytes: 3104
#include <bits/stdc++.h>
#define l_ength size
using ll = long long;
const int mod = 1000000007;
const int inf = (1<<30);
using namespace std;

int main(){
	int n; cin >> n;
	// v(k) := 要素 k は 1-indexed で何番目にあるか？
	vector<int> v(n+1);
	for( int i = 1; i <= n; ++i ){
		int k; cin >> k;
		v[k] = i;
	}
	set<int> s;
	s.insert(0); s.insert(n+1);
	ll ans = 0;
	// set には必ず自分より小さい要素が入っている
	for( int k = 1; k <= n; ++k ){
		auto itr = s.lower_bound(v[k]);
		int x = *(itr)-v[k];
		int y = v[k]-*(--itr);
		ans += (ll)x * (ll)y * (ll)k;
		s.insert(v[k]);
	}
	cout << ans << endl;
}

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

using namespace std;
typedef long long ll;
typedef long double ld;
#define REP(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define REPR(i,n) for(int i=n; i>-1; --i)
#define ALL(a) (a).begin(),(a).end()
#define FILL(a,n,x); REP(i,(n)){ (a)[i]=(x); }
#define CINA(a,n); REP(i,(n)){ cin >> (a)[i]; }
#define FILL2(a,n,m,x); REP(i,(n)){ REP(j,(m)){(a)[i][j]=(x);} }
#define CINA2(a,n,m); REP(i,(n)){ REP(j,(m)){cin >> (a)[i][j];} }
#define Liny "Yes\n"
#define Linn "No\n"
#define LINY "YES\n"
#define LINN "NO\n"

#define umap unordered_map
//cout << setfill('0') << right << setw(4) << 12; // "0012"
int keta(ll x){ if(x<10){return 1;} else{return keta(x/10) + 1;}}
int keta_wa(ll x){ if(x<10){return x;} else{return keta_wa(x/10) + x%10;} }
int ctoi(char c){ return ( (c>='0' && c<='9')? c - '0': 0 );}
int __stoi(string s){ return atoi(s.c_str()); }
ll sum(ll a[],ll N){ return accumulate(a,a+N,0LL);}
ll gcd(ll a,ll b){if(a<b)swap(a,b); return b?gcd(b,a%b):a;}
ll lcm(ll a,ll b){if(a<b){swap(a,b);} return a/gcd(a,b)*b;}
template<class T> void chmax(T& a, T b){ if(a<b){a=b;} }
template<class T> void chmin(T& a, T b){ if(a>b){a=b;} }

ld PI = 3.1415926535;

int main(){
  ld a,b,x; cin>>a>>b>>x;
  ld ans;
  if(a*a*b <= x*2){ ans = atan( 2*(a*a*b-x)/(a*a*a) )*180/PI; }
  else{ ans = (PI/2 - atan( x*2/(a*b*b)) )*180/PI; }
  printf("%.7Lf\n",ans);
}

Measured memory_bytes: 256
N,K = map(int,input().split())
p = list(map(int,input().split()))
ans = sum(p[0:K])
s = ans
for i in range(1,N-K+1):
    s += p[i+K-1]-p[i-1]
    ans = max(ans,s)
print((K+ans)/2)

Measured memory_bytes: 32108
#include "bits/stdc++.h"

using namespace std;

#define endl            "\n"
#define sz(x)          (int) (x.size())
#define all(v)          v.begin(), v.end()
#define isOdd(n)       (n&1)
#define pow(n, m)      (ll)powl(n, m)
#define clr(x, val)     memset(x, val, sizeof(x))

typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef vector<int> vi;

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

int n, m;
bool ok(int r, int c){
    return ~r && ~c && r < n && c < m;
}
int main()
{
    ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);

    int white = 0; cin >> n >> m;

    char a[n][m];

    bool vis[n][m] = {};

    int dis[n][m] = {};
    clr(dis, -1);

    queue<pair<int, int>> q;

    for(int i = 0; i < n; i++){
        for(int j = 0; j < m; j++){
            cin >> a[i][j];
            if(a[i][j] == '.') white++;
            else q.push({i, j}), vis[i][j] = 1, dis[i][j] = 0;
        }
    }

    if(!white) return cout << 0, 0;

    while(q.size()){
        int r = q.front().first, c = q.front().second;
        q.pop();
        for(int i = 0; i < 4; i++){
            int x = r + dx[i], y = c + dy[i];
            if(ok(x, y) && dis[x][y] == -1 && a[x][y] == '.')
                q.push({x, y}), a[x][y] = '#', dis[x][y] = 1 + dis[r][c];
        }
    }

    int mx = 0;
    for(int i = 0; i < n; i++)
        for(int j = 0; j <m; j++)
            mx = max(mx, dis[i][j]);

    cout << mx;
    return 0;
}


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

int fun(char a, char b) {
    return a == 'A' && b == 'C';
}

int main() {
    int n, q;
    cin >> n >> q;
    string s;
    cin >> s;

    vector<int> cnt(n - 1);
    cnt[0] = fun(s[0], s[1]);
    for (int i = 1; i < n - 1; i++) {
        cnt[i] = cnt[i - 1] + fun(s[i], s[i + 1]);
    }

    rep(i, q) {
        int l, r;
        cin >> l >> r;
        l--;
        r--;
        if (l == 0) {
            cout << cnt[r - 1] << endl;
        }else {
            cout << cnt[r - 1] - cnt[l - 1] << endl;
        }
    }
}


Measured memory_bytes: 1408
using System;
using System.Collections;
using System.Collections.Generic;
using System.Text;


public class C
{
	public static void Main()
	{
		string[] args = Console.ReadLine().Split(' ');
		int A = Int32.Parse(args[0]);
		int B = Int32.Parse(args[1]);
		int C = Int32.Parse(args[2]);
		int D = Int32.Parse(args[3]);
		int E = Int32.Parse(args[4]);
		int F = Int32.Parse(args[5]);

		int optSugarWater = 100 * A;
		int optSugar = 0;
		double optDencity = 0;
		for(int i = 0; i <= F/(100 * A); i++)
		{
			int binRest1 = F - i * 100 * A;
			for(int j = 0; j <= binRest1/(100 * B); j++)
			{
				int binRest2 = binRest1 - j * 100 * B;
				int sugarRest1 = (i * A + j * B) * E;
				for(int k = 0; k <= Math.Min(binRest2, sugarRest1)/C; k++)
				{
					int binRest3 = binRest2 - k * C;
					int sugarRest2 = sugarRest1 - k * C;
					for(int l = 0; l <= Math.Min(binRest3, sugarRest2)/D; l++)
					{
						if(i + j + k + l == 0)
							continue;

						double water = 100 * (i * A + j * B);
						double sugar = k * C + l * D;
						double dencity = sugar/(sugar + water);
						if(dencity > optDencity)
						{
							optDencity = dencity;
							optSugarWater = (int)(sugar + water);
							optSugar = (int)sugar;
						}
					}
				}
			}
		}
		
		Console.WriteLine("{0} {1}", optSugarWater, optSugar);
	}
}





Measured memory_bytes: 13268
#include <bits/stdc++.h>
#define int long long
#define endl '\n'
using namespace std;

typedef long long ll;
#define READ(a) int a; cin >> a;
#define READARR(a, n) int a[(n) + 1] = {}; FOR(i, 1, (n)) {cin >> a[i];}
#define READMAT(a, n, m) int a[n + 1][m + 1] = {}; FOR(i, 1, n) {FOR(j, 1, m) cin >> a[i][j];}
#define pb(x) push_back(x)
#define fi first
#define se second
#define vi vector <int>
#define pi pair <int, int>
#define vpi vector <pi>
#define FOR(i, a, b) for (int i = (a); i <= (b); i++)
#define FORD(i, a, b) for (int i = (a); i >= (b); i--)
const ll inf = 1e18;
const ll mod = 1e9 + 7;

signed main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	
	int k, x;
	cin >> k >> x;
	k--;
	FOR (i, x - k, x + k) cout << i << " ";
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <iomanip>
#include <iomanip>
#include <cmath>
using namespace std;
const int MOD = 1e9+7;
using ll = long long;
using vi = vector<int>;
#define rep(i, n) for (int i = 0; i < n; i++)
#define ALL(x) x.begin(), x.end()
int main() {
  int a,b;cin >> a >> b;
  vector<string> mine(a);
  rep(i,a){
    cin >> mine[i];
  }
  vector<bool> yoko(a,false);
  vector<bool> tate(b,false);
  for(int i = 0;i<a;i++){
    for(int j = 0;j<b;j++){
      if(mine[i][j]=='#'){
        yoko[i] = true;
        tate[j] = true;
      }
    }
  }
  for (int i = 0; i < a; i++) {
		if (yoko[i]) {
			for (int j = 0; j < b; j++) {
				if (tate[j]) {
					cout << mine[i][j];
				}
			}
			cout << endl;
		}
	}
}

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

divisor = n
ans = ""
a = ["z", "a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l", "m", "n", "o", "p", "q", "r", "s", "t", "u", "v", "w", "x", "y"]
while divisor > 0:
    if divisor % 26 == 0:
        surplus = divisor % 26
        ans = a[surplus] + ans
        divisor = divisor // 26 -1
    else:
        surplus = divisor % 26
        ans = a[surplus] + ans
        divisor = divisor // 26
print(ans)

Measured memory_bytes: 61548
use std::fmt::Write;
use std::io::*;

fn main() {
	let input = {
		let mut buf = vec![];
		stdin().read_to_end(&mut buf);
		buf.pop();
		unsafe { String::from_utf8_unchecked(buf) }
	};

	let mut l_arr = vec![];
	let mut stack = vec![];

	for (i, ch) in input.bytes().enumerate() {
		match ch {
			b'\\' => {
				stack.push((l_arr.len(), i));
			}
			b'/' => {
				if let Some((k, j)) = stack.pop() {
					if l_arr.len() < k + 1 {
						l_arr.push(i - j);
					} else {
						l_arr[k] += i - j;

						if k + 1 < l_arr.len() {
							let sum = l_arr.drain(k + 1..).sum::<usize>();
							l_arr[k] += sum;
						}
					}
				}
			}
			_ => {}
		}
	}

	let mut res = format!("{}\n", l_arr.iter().sum::<usize>());

	write!(res, "{}", l_arr.len());
	for l in l_arr {
		write!(res, " {}", l);
	}
	println!("{}", res);
}



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

using namespace std;
typedef long long ll;
typedef long double ld;
#define For(i, a, b)    for(int i = (a) ; i < (b) ; ++i)
#define rep(i, n)       For(i, 0, n)


// Write From This Line
vector<int> to[100005];

int n;
vector<int> dist(n);
void dfs(int s, int d=0, int p = -1){
	dist[s] = d;
	for(int u:to[s]){
		if(u == p) continue;
		dfs(u,d+1,s);
	}
}
vector<int> calcDist(int s) {
	// sからの各頂点への距離を求める
	dist = vector<int> (n);
	dfs(s);
	return dist;
}
int main()
{
	int s, t;
	cin >> n >> s >> t;
	--s, --t;
	rep(i,n-1){
		int a, b;
		cin >> a >> b;
		--a, --b;
		to[a].push_back(b);
		to[b].push_back(a);
	}

	vector<int> distS = calcDist(s);
	vector<int> distT = calcDist(t);

	int mx = 0;
	rep(i,n){
		if(distS[i] < distT[i]){
			mx = max(mx,distT[i]);
		}
	}
	int ans = mx - 1;
	cout << ans << endl;
}


Measured memory_bytes: 10744
#define _USE_MATH_DEFINES
#include <iostream>
#include <fstream>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cstring>
#include <cassert>
#include <string>
#include <vector>
#include <utility>
#include <complex>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <deque>
#include <tuple>
#include <bitset>
#include <limits>
#include <algorithm>
#include <array>
#include <random>
#include <complex>
#include <regex>
using namespace std;
typedef long double ld;
typedef long long ll;
typedef vector<int> vint;
typedef vector<ll> vll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<double, double> pdd;
typedef complex<ld> compd;
#define quickIO()	{cin.tie(0);	cout.sync_with_stdio(false);}
#define reach(i,a)	for(auto i:a)
#define rep(i,n)	for(int i=0;i<(int)n;i++)
#define REP(i,n)	for(int i=0;i<=(int)n;i++)
#define srep(i,a,n)	for(int i=a;i<(int)n;i++)
#define SREP(i,a,n)	for(int i=a;i<=(int)n;i++)
#define rrep(i,n)	for(int i=n-1;i>=0;i--)
#define RREP(i,n)	for(int i=n;i>=0;i--)
#define all(a)	(a).begin(),(a).end()
#define mp(a,b)	make_pair(a,b)
#define mt	make_tuple
#define pb	push_back
int bitcnt(ll x) {
	x = ((x & 0xAAAAAAAAAAAAAAAA) >> 1) + (x & 0x5555555555555555);
	x = ((x & 0xCCCCCCCCCCCCCCCC) >> 2) + (x & 0x3333333333333333);
	x = ((x & 0xF0F0F0F0F0F0F0F0) >> 4) + (x & 0x0F0F0F0F0F0F0F0F);
	x = ((x & 0xFF00FF00FF00FF00) >> 8) + (x & 0x00FF00FF00FF00FF);
	x = ((x & 0xFFFF0000FFFF0000) >> 16) + (x & 0x0000FFFF0000FFFF);
	x = ((x & 0xFFFFFFFF00000000) >> 32) + (x & 0x00000000FFFFFFFF);
	return x;
}
int bitcnt(int x) {
	x = ((x & 0xAAAAAAAA) >> 1) + (x & 0x55555555);
	x = ((x & 0xCCCCCCCC) >> 2) + (x & 0x33333333);
	x = ((x & 0xF0F0F0F0) >> 4) + (x & 0x0F0F0F0F);
	x = ((x & 0xFF00FF00) >> 8) + (x & 0x00FF00FF);
	x = ((x & 0xFFFF0000) >> 16) + (x & 0x0000FFFF);
	return x;
}
ll sqrtll(ll x) {
	ll left = 0, right = x;
	rep(i, 100) {
		ll mid = (left + right) >> 1;
		if (mid*mid <= x)	left = mid;
		else	right = mid;
	}
	return left;
}
ll gcd(ll a, ll b) {
	return a%b == 0 ? b : gcd(b, a%b);
}
#define debug(x)	printf("Case #%d: ", x)
#define DEBUG 0
const ll inf = 1e18;
const ll mod = 1e9 + 7;
const ld eps = 1e-9;
const int dx[] = { 1,0,-1,0,0 };
const int dy[] = { 0,1,0,-1,0 };

int dist[300][300];

int main() {
	int n, m, r;	cin >> n >> m >> r;
	vint rot(r);
	rep(i, r)	cin >> rot[i];
	rep(i, n)	rep(j, n)	dist[i][j] = mod;
	rep(i, m) {
		int a, b, c;	cin >> a >> b >> c;
		a--;	b--;
		dist[a][b] = dist[b][a] = c;
	}
	rep(k, n)	rep(i, n)	rep(j, n) {
		dist[i][j] = min(dist[i][j], dist[i][k] + dist[k][j]);
	}
	vint p(r);
	rep(i, r)	p[i] = i;
	ll ret = inf;
	do {
		ll tmp = 0;
		srep(i, 1, r) {
			tmp += dist[rot[p[i]] - 1][rot[p[i - 1]] - 1];
		}
		ret = min(ret, tmp);
	} while (next_permutation(all(p)));
	cout << ret << endl;
}

Measured memory_bytes: 512
n = int(input())
a = list(map(int, input().split()))

b = [0] * n
for i in range(n):
    if i % 2 == n % 2:
        j = (n+i)//2
    else:
        j = (n-i)//2
    b[j] = a[i]
print(*b)


Measured memory_bytes: 26020
#include <stdio.h>
#include <iostream>
#include <cstdlib>
#include <cmath>
#include <cctype>
#include <string>
#include <cstring>
#include <algorithm>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <ctime>
#include <vector>
#include <fstream>
#include <list>
#include <iomanip>
#include <numeric>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
#define ms(s) memset(s, 0, sizeof(s))
const int INF = 1e9;
inline int read(){
    int X = 0,w = 0 ;
    char ch = 0;
    while(!isdigit(ch)) {w |= ch == '-';ch = getchar();}
    while(isdigit(ch)) X = (X<<3) + (X<<1) + (ch ^ 48),ch = getchar();
    return w ? -X : X;
}

int x,k,a[100005];
bool sg[100005];
void solve()
{
    sg[0]=false;
    for(int i=1;i<=x;i++)
    {
        sg[i]=false;
        for(int j=0;a[j]<=i and j<k;j++)
            if(!sg[i-a[j]])
                sg[i]|=!sg[i-a[j]];
    }
    if(sg[x])
    {
        cout<<"First"<<endl;
    }
    else
    {
        cout<<"Second"<<endl;
    }
}
 
int main()
{
    cin>>k>>x;
    for(int i=0;i<k;++i)
        cin>>a[i];
    solve();
    return 0;
}

Measured memory_bytes: 384
import java.util.Scanner;

public class Main {

    int capacity;
    int n;
    int[] cost;
    int[] value;
    int[][] dp;
    Scanner in = new Scanner(System.in);

    boolean readCase() {
        while (in.hasNext()) {
            n = in.nextInt();
            capacity = in.nextInt();
            cost = new int[n];
            value = new int[n];
            for (int i = 0; i < n; i++) {
                value[i] = in.nextInt();
                cost[i] = in.nextInt();
            }
            return true;
        }
        return false;
    }

    public static void main(String[] args) {
        Main main = new Main();
        while (main.readCase()) {
            main.solve();
        }
    }

    void solve() {
        dp = new int[n + 1][];
        for (int i = 0; i < n + 1; i++) {
            dp[i] = new int[capacity + 1];
            for (int j = 0; j < capacity + 1; j++) {
                dp[i][j] = -1;
            }
        }
        System.out.println(computeMemoization(0, capacity));
    }

    int computeMemoization(int itemIdx, int weight) {
        if (dp[itemIdx][weight] != -1) {
            return dp[itemIdx][weight];
        }
        int res;
        if (itemIdx == n) {
            res = 0;
        } else if (weight < cost[itemIdx]) {
            res = computeMemoization(itemIdx + 1, weight);
        } else {
            res = Math.max(computeMemoization(itemIdx + 1, weight),
                    computeMemoization(itemIdx + 1, weight - cost[itemIdx]) + value[itemIdx]);
        }
        dp[itemIdx][weight] = res;
        return res;
    }

}

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

int main() {
  string s;
  cin >> s;
  int size = s.size();
  int arr[size];
  for (int i = 0; i < size; i++) {
    arr[i] = 0;
  }
  int cnt = 0;
  for (int i = 0; i < size; i++) {
    if (s[i] == 'R')
      cnt++;
    else {
      arr[i - 1] += cnt / 2 + cnt % 2;
      arr[i] += cnt / 2;
      cnt = 0;
    }
  }
  for (int i = size - 1; i >= 0; i--) {
    if (s[i] == 'L')
      cnt++;
    else {
      arr[i + 1] += cnt / 2 + cnt % 2;
      arr[i] += cnt / 2;
      cnt = 0;
    }
  }

  cout << arr[0];

  for (int i = 1; i < size; i++) {
    cout << " " << arr[i];
  }

  return 0;
}

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

int min(int a, int b)
{
  if(a < b)
  {
    return a;
  }
  else
  {
    return b;
  }
}

int main()
{
  int A, B, K;
  cin >> A >> B >> K;
  
  int nth = 0;
  
  for(int i = min(A, B); i >= 1; --i)
  {
    if(A % i == 0 && B % i == 0)
    {
      ++nth;
    }
    
    if(nth == K)
    {
      cout << i << endl;
      return 0;
    }
  }
}

Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main(void){
  int x,y;
  cin >> x >> y;
  
  int ans;
  
  if(x < 4) ans += (4 - x) * 100000;
  if(y < 4) ans += (4 - y) * 100000;
  
  if(x == 1 && y == 1) ans += 400000;
  
  cout << ans << endl;
  
  return 0;
}


Measured memory_bytes: 256
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <ctime>
#include <cctype>
#include <climits>
#include <iostream>
#include <string>
#include <vector>
#include <map>
#include <list>
#include <queue>
#include <deque>
#include <algorithm>
#include <numeric>
#include <utility>
#include <complex>
#include <memory>
#include <functional>
 
using namespace std;
 
#define ALL(g) (g).begin(),(g).end()
#define REP(i, x, n) for(int i = x; i <= n; i++) //変数,初期値,終値
#define rep(i,n) REP(i,0,n)
#define F(i,j,k) fill(i[0],i[0]+j*j,k)
#define P(p) cout<<(p)<<endl;
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define INF 1<<25
#define pb push_back
 
typedef vector<int> vi;
typedef vector<long long> vl;
typedef vector<double> vd;
typedef pair<int,int> pii;
typedef pair<long,long> pll;
typedef long long ll;

int main(void)
{
    int n,i;
    int ans=0;
    int dp[44] = {1,1};
    cin >> n;
    i=n;
    REP(i,2,n){
        dp[i] = dp[i-1] + dp[i - 2];
    }
    cout << dp[i] << endl;
    
    return 0;
}

Measured memory_bytes: 1160
import sys

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


def main():
    N = int(readline())

    print(N * (N + 1) // 2)

    return


if __name__ == '__main__':
    main()


Measured memory_bytes: 9040
X, Y, Z, K = map(int, input().split())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
C = list(map(int, input().split()))

sumsofAandB = sorted([a+b for a in A for b in B], reverse=True)[:K]
sumsofAll = sorted([ab+c for ab in sumsofAandB for c in C], reverse=True)
for i in range(K):
    print(sumsofAll[i])

Measured memory_bytes: 140420
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cctype>
#include <cmath>
#include <cstdint>
#include <cstdio>
#include <cstring>
#include <deque>
#include <fstream>
#include <functional>
#include <iostream>
#include <limits>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <vector>
using namespace std;
using ll = long long;
#define fst first
#define snd second

/* clang-format off */
template <class T, size_t D> struct _vec { using type = vector<typename _vec<T, D - 1>::type>; };
template <class T> struct _vec<T, 0> { using type = T; };
template <class T, size_t D> using vec = typename _vec<T, D>::type;
template <class T> vector<T> make_v(size_t size, const T& init) { return vector<T>(size, init); }
template <class... Ts> auto make_v(size_t size, Ts... rest) { return vector<decltype(make_v(rest...))>(size, make_v(rest...)); }
template <class T> inline void chmin(T &a, const T& b) { if (b < a) a = b; }
template <class T> inline void chmax(T &a, const T& b) { if (b > a) a = b; }
/* clang-format on */

struct item_t {
  int a, b;
};

vec<int, 2> solve(const vector<item_t>& items, const int T) {
  int N = items.size();
  vec<int, 2> dp = make_v(N + 1, T, -1);
  dp[0][0] = 0;
  for (int i = 0; i < N; i++) {
    auto& item = items[i];
    for (int t = 0; t < T; t++) chmax(dp[i + 1][t], dp[i][t]);
    for (int t = 0; t < T; t++) {
      if (dp[i][t] < 0) continue;
      if (t + item.a >= T) continue;
      chmax(dp[i + 1][t + item.a], dp[i][t] + item.b);
    }
  }
  return dp;
}

int main() {
#ifdef DEBUG
  ifstream ifs("in.txt");
  cin.rdbuf(ifs.rdbuf());
#endif
  int N, T;
  while (cin >> N >> T) {
    vector<item_t> items(N);
    for (auto& item : items) cin >> item.a >> item.b;
    auto dp1 = solve(items, T);
    reverse(items.begin(), items.end());
    auto dp2 = solve(items, T);
    reverse(items.begin(), items.end());
    reverse(dp2.begin(), dp2.end());
    int res = 0;
    for (int i = 0; i < N; i++) {
      int t2 = 0, mx = 0;
      for (int t = T - 1; t >= 0; t--) {
        while (t + t2 < T) {
          chmax(mx, dp2[i + 1][t2]);
          ++t2;
        }
        chmax(res, dp1[i][t] + mx + items[i].b);
      }
    }
    cout << res << endl;
  }
  return 0;
}


Measured memory_bytes: 70912
#include <bits/stdc++.h>
using namespace std;
int n, cnt, ans;
string s;
int main()
{
    cin >> n >> s;
    for (int i = 0; i < s.size(); i++)
    {
        if (s[i] == 'I')
            cnt++;
        else
            cnt--;
        ans = max(ans, cnt);
    }
    return printf("%d\n", ans), 0;
}

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

using namespace std;
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; }

//using Matrix = vector< vector<int> >;
typedef long long ll;
typedef pair<int, int> P;
const int INF = 1 << 30;
int dx[5] = {0, 0, 1, -1, 0}, dy[5] = {1, -1, 0, 0, 0};
bool cmp(P a, P b) { return a.second < b.second; } //End sort (Interval scheduling problem)

int n, x;
int l[110];
int d[110];

int main(void){
	cin>>n>>x;
	for (int i = 0; i < n; i++) cin>>l[i];
	
	int cnt = 1;
	for (int i = 0; i < n; i++) {
		d[i + 1] = d[i] + l[i];
		if (d[i + 1] > x) break;

		cnt++;
	}

	cout<< cnt <<endl;

	return 0;
}

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

int main(int argc, const char * argv[]) {
    // insert code here...
    double a,b;
    int C;
    scanf("%lf %lf %d",&a,&b,&C);
    
    printf("%f\n",a*b*sin(M_PI * C / 180)/2);
    printf("%f\n",a+b+sqrt(a*a+b*b-2*a*b*cos(M_PI*C/180)));
    printf("%f\n",b*sin(M_PI * C / 180));
    
    return 0;
}


Measured memory_bytes: 2112
#include <bits/stdc++.h>
using namespace std;
unsigned long long r=0,g=0,b=0;
int main()
{
	ios::sync_with_stdio(0);
	cin.tie(0);
	int N;
	cin>>N;
	string s;
	cin>>s;
	if(N<=3){
		cout<<0<<endl;
		return 0;
	}
	for(int i=0;i<N;i++)
	{
		if(s[i]=='R'){
			r++;
			continue;
		}
		if(s[i]=='G'){
			g++;
			continue;
		}
		b++;
	}
	unsigned long long ans=r*g*b;
	unsigned long long temp=0;
	for(int i=0;i<N;i++)
	{
		int l=i,r=(N-1)-i;
		int d=min(l,r);
		for(int j=i+1;j<=i+d;j++)
		{
			if((s[i]!=s[j])&&(s[i]!=s[i-j+i])&&(s[j]!=s[i-j+i])){
				temp++;
			}
		}
	}
	/*for(int i=1;i<=N/2;i++)
	{
		for(int j=i;j+i<N;j++)
		{
			if((s[j-i]!=s[j])&&(s[j+i]!=s[j])&&(s[j-i]!=s[j+i]))temp++;
			//cout<<j-i<<" "<<j<<" "<<j+i<<endl;
		}
	}*/
	ans-=temp;
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 3664
#include<iostream>
using namespace std;
int gcd(unsigned long a, unsigned long b){
  unsigned long x, y;
  if(a<b){
    x=b;
    y=a;
  }else{
    x=a;
    y=b;
  }
  if(y == 0){
    return x;
  }else
    return gcd(y, x % y);
}

int main(){
  unsigned long N, X;
  cin >> N >> X;
  unsigned long diff[100000];
  for(int i=0; i<N; i++){
    unsigned long x;
    cin >> x;
    diff[i]=labs(X-x);
    X = x;
  }
  
  unsigned long a=gcd(diff[0], diff[1]);
  for(int i=2; i<N; i++){
    a=gcd(a, diff[i]);
  }
  cout << a << endl;
  return 0;
}

Measured memory_bytes: 1024
using System.Linq;
using System;
public class hello
{
    public static void Main()
    {
        string[] line = Console.ReadLine().Trim().Split(' ');
        var r = int.Parse(line[0]);
        var c = int.Parse(line[1]);
        var ary = new int[r, c + 1];
        var sumtate = new int[c + 1];    //??????????¨???????????????¨???
        for (int i = 0; i < r; i++)
        {
            string[] line2 = Console.ReadLine().Trim().Split(' ');
            var sumyoko = 0;
            for (int j = 0; j < c; j++)
            {
                ary[i, j] = int.Parse(line2[j]);
                sumyoko += ary[i, j];
            }
            ary[i, c] = sumyoko;
        }
        for (int i = 0; i < c; i++)
            for (int j = 0; j < r; j++)
                sumtate[i] += ary[j, i];
        var buf = sumtate.Sum();
        sumtate[c] = buf;

        for (int i = 0; i< r; i++)
            for (int j = 0; j< c+1; j++)
            {
                if (j != c) Console.Write("{0} ", ary[i, j]);
                else Console.WriteLine(ary[i, j]);
            }
        for (int i = 0; i< c+1; i++)
        {
            if (i != c) Console.Write("{0} ", sumtate[i]);
            else Console.WriteLine(sumtate[i]);

        }
    }
}

Measured memory_bytes: 9648
#include <iostream>
#include <string>
using namespace std;
typedef long long ll;
int main(void){
    string s;
    cin >> s;
    string t;
    cin >> t;
    ll ans = 0;
    for(int i=0;i<26;i++){
        char ss = 'a' + i;
        if(s+ss==t)ans = 1;
    }
    if(ans == 0)cout << "No" << endl;
    else cout << "Yes" << endl;
    return 0;
}


Measured memory_bytes: 3576
#include <bits/stdc++.h>
#define rep(i,n) for(int i=1;i<=n;++i)
#define YES cout<<"YES"<<endl
#define NO cout<<"NO"<<endl
using namespace std;

int main(){
  string a,b;
  cin >> a >> b;
  if (a.at(0)==b.at(2) && a.at(1)==b.at(1) && a.at(2)==b.at(0)) YES;
  else NO;
  return 0;
}


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

using namespace std;

typedef long long LL;
#define N 300000

LL n,m,x,y,X,Y,xb,len,tot,tmp,ans,head[N],f[N],q[N],fa[N];
bool vis[N];
struct edge{LL v,nxt;}e[N];

void add(LL x,LL y){
	e[++tot].v=y; e[tot].nxt=head[x]; head[x]=tot;
}

void dfs(LL u,LL o){
	f[u]=o; tmp+=o; vis[u]=1;
	for (LL i=head[u],v;i;i=e[i].nxt)
		if (!vis[v=e[i].v]){fa[v]=u; dfs(v,-o);}
		else if (v!=fa[u]){X=v; Y=u;}
}

void calc(int u){
	for (int i=head[u],v;i;i=e[i].nxt)
		if (fa[v=e[i].v]==u){
			calc(v); f[u]+=f[v]; ans+=abs(f[v]);
		}
}

int main(){
	scanf("%lld%lld",&n,&m);
	for (LL i=1;i<=m;++i){
		scanf("%lld%lld",&x,&y);
		add(x,y); add(y,x);
	}
	dfs(1,1);
	if (m<n){
		calc(1);
		printf("%lld\n",f[1]?-1:ans);
		return 0;
	}
	len=1; for (int i=X;i!=Y;i=fa[i]) ++len;
	if (tmp&1){puts("-1"); return 0;}
	if (len&1){
		f[X]-=tmp/2; f[Y]-=tmp/2; ans+=abs(tmp/2);
		calc(1);
		printf("%lld\n",ans);
		return 0;
	}
	if (tmp){puts("-1"); return 0;}
	calc(1);
	q[++xb]=0;
	for (int i=X;i!=Y;i=fa[i]){q[++xb]=f[i]; ans-=abs(f[i]);}
	sort(q+1,q+xb+1);
	for (int i=1;i<=xb/2;++i) ans+=q[xb-i+1]-q[i];
	printf("%lld\n",ans);
	
	return 0;
}
			

Measured memory_bytes: 17664
import java.util.*;
public class Main {
	public static void main(String[] args)  {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		long k = sc.nextLong();
		int a[] = new int[n];		
		String pos = "POSSIBLE ", imp = "IMPOSSIBLE ";
		
		for(int i=0;i<n;i++)a[i] = sc.nextInt();
		sc.close();
		Arrays.sort(a);
		
		int min = a[0], max = a[n-1];
		//maxを因数分解
		List<Integer> ls = new ArrayList<>();
		for(int i=2;i*i<=max;i++) {
			if(max%i==0) {
				ls.add(i);
				if(i*i!=max) {
					ls.add(max/i);
				}
			}
		}
		Collections.sort(ls);
		
		int div = 1;
		for(int i=0;i<ls.size();i++) {
			int now = ls.get(i);
			boolean ok = true;
			for(int j=0;j<n;j++) {
				if(a[j]%now==0)continue;
				ok = false;
				break;
			}
			if(ok)div = now;
		}
		
		if(k>max) {
			System.out.println(imp);
			return;
		}
		if(n==1) {
			if(min == k)System.out.println(pos);
			else System.out.println(imp);
			return;
		}
		
		if(div==1) {
			System.out.println(pos);
			return;
		}
		
		if(k%div==0)System.out.println(pos);
		else System.out.println(imp);

	}
}


Measured memory_bytes: 48320