akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
using namespace std;
typedef long long ll;
int dp[3050][3050]={};
int p,q;
int max(int a,int b){
  if(a<b)return b;
  else return a;
}
int main(){
  int n;
  string s,t;
  cin>>s>>t;
  vector<int> array;
  int size_s=(int)s.length();
  int size_t=(int)t.length();
  for(int i=1;i<=size_s;i++){
    for(int j=1;j<=size_t;j++){
      if(s[i-1]==t[j-1]){
	dp[i][j]=dp[i-1][j-1]+1;
      }
      else dp[i][j]=max(dp[i-1][j],dp[i][j-1]);
    }
  }
  n=dp[size_s][size_t];
  int buf=size_t;
  for(int i=size_s;i>=1;i--){
    int j=buf;
    for(j=buf;j>=1;j--){
      if(dp[i][j]!=dp[i-1][j] && dp[i][j]!=dp[i][j-1]){
	if(dp[i][j]==n){
	array.push_back(j-1);
	buf=j;
	n--;
	break;
      }
      }
    }
  }
  /*  for(int i=size_s;i>0;i--){
    if(dp[i][size_t]!=dp[i-1][size_t])array.push_back(i-1);
  }*/
  int num=array.size();
  for(int i=num-1;i>=0;i--){
    cout<<t[array[i]];
  }
  cout<<endl;
  //  cout<<dp[size_s][size_t]<<endl;
  return 0;
}


Measured memory_bytes: 36096
s = str(input())
k = int(input())

t = 0
  
for i in range(len(s)):
  temp = s[i]
  if temp == '1':
    t += 1
  else:
    break

if t == 0:
  print(s[0])
else:
  if k <= t:
    print('1')
  else:
    print(temp)
    
 

Measured memory_bytes: 38384
#include <bits/stdc++.h>
#define fi first
#define se second
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
#define srep(i,s,t) for (int i = s; i < t; ++i)
#define rng(a) a.begin(),a.end()
#define pb push_back
#define sz(x) (int)(x).size()
using namespace std;
typedef long long int ll;
typedef pair<int,int> P;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<P> vp;
const ll LINF = 1001002003004005006ll;
const int INF = 1001001001;


int main() {
  int n;
  cin >> n;
  vl v(n);
  rep(i,n){
    cin >> v[i];
  }
  long ans=0;
  rep(i,n){
    ll a=v[i];
    while(a%2==0){
      a /= 2;
      ans ++;
    }
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 384
#include<bits/stdc++.h>
using namespace std;
#define LL long long
#define ULL unsigned long long
#define mp make_pair
#define pb push_back
#define pii pair<int,int>
#define pll pair<LL,LL>
#define x first
#define y second
#define pi acosl(-1)
#define sqr(x) ((x)*(x))
#define pdd pair<double,double>
#define MEMS(x) memset(x,-1,sizeof(x))
#define MEM(x) memset(x,0,sizeof(x))
#define EPS 1e-4
#define arg ARG
#define cpdd const pdd
#define rank Rank
#define MAXN 205
//#define N 262144
#define ULL unsigned long long
#define ll long long
LL fra[2000005];
LL inv[2000005];
int mod=1e9+7;
LL f_pow(LL a,LL b){
    LL res=1,tmp=a;
    while(b){
        if(b&1)res=res*tmp%mod;
        tmp=tmp*tmp%mod;
        b>>=1;
    }
    return res;
}
LL C(int a,int b){
    return fra[a]*inv[b]%mod*inv[a-b]%mod;
}
int main(){
    fra[0]=1;
    for(int i =1;i<2000005;i++)fra[i]=fra[i-1]*i%mod;
    inv[2000004]=f_pow(fra[2000004],mod-2);
    for(int i =2000003;i>=0;i--)inv[i]=inv[i+1]*(i+1)%mod;
    int k;
    scanf("%d",&k);
    char c[1000005];
    scanf("%s",c);
    int n=strlen(c);

    LL ans=0;
    for(int i = 0;i<=k;i++){
        ans+=f_pow(25,i)*C(n-1+i,i)%mod*f_pow(26,k-i)%mod;
        ans%=mod;
    }
    printf("%lld\n",ans);
}

Measured memory_bytes: 35936
s = list(input())
n = len(s)

a = [0] * (n+1)
for i in range(n):
    if s[i] == '<':
        a[i+1] = a[i]+1
for i in reversed(range(n)):
    if s[i] == '>':
        a[i] = max(a[i+1]+1,a[i])
print(sum(a))

Measured memory_bytes: 93660
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.IO;
using static System.Console;
using static System.Math;

class program
{
    static public int mod = 1000000007;
    static void Main()
    {
        var nk = longa();
        long n = nk[0], k = nk[1];
        long ans = 0;
        for(long i = k; i <= n+1 ; i++)
        {
            ans = (ans + (i * n) % mod - (i * (i - 1)) % mod + 1) % mod;
        }
        Write(ans);
    }

    static int pow(int a, int b) { string binary = Convert.ToString(b, 2); int bileng = binary.Length; long a_power = a; long value = 1; for (int i = bileng - 1; i >= 0; i--) { if (binary[i] == '1') { value = value * a_power % mod; } a_power = a_power * a_power % mod; } return (int)value; }
    static string rstr() { return ReadLine(); }
    static int rint() { return int.Parse(ReadLine()); }
    static long rlong() { return long.Parse(ReadLine()); }
    static string[] stra() { return ReadLine().Split(' '); }
    static char[] chara() { string[] a = stra(); string b = ""; for (int i = 0; i < a.Length; i++) { b += a[i]; } return b.ToCharArray(); }
    static int[] inta() { string[] read_str_array = ReadLine().Split(' '); int[] return_int_array = new int[read_str_array.Length]; for (int countup_i = 0; countup_i < read_str_array.Length; countup_i++) { return_int_array[countup_i] = int.Parse(read_str_array[countup_i]); } return return_int_array; }
    static long[] longa() { string[] read_str_array = ReadLine().Split(' '); long[] return_long_array = new long[read_str_array.Length]; for (long countup_i = 0; countup_i < read_str_array.Length; countup_i++) { return_long_array[countup_i] = long.Parse(read_str_array[countup_i]); } return return_long_array; }
    static double[] doublea() { string[] read_str_array = ReadLine().Split(' '); double[] return_double_array = new double[read_str_array.Length]; for (long countup_i = 0; countup_i < read_str_array.Length; countup_i++) { return_double_array[countup_i] = double.Parse(read_str_array[countup_i]); } return return_double_array; }
    static long GCD(long a, long b) { if (a < b) { long temp = a; a = b; b = temp; } if (a % b == 0) { return b; } else { long temp = b; b = a % b; a = temp; return GCD(a, b); } }
    static long LCM(long a, long b) { return a * b / GCD(a, b); }
    static void WriteArray2(int[,] a, int b, int c) { for (int i = 0; i < b; i++) { for (int j = 0; j < c; j++) { if (j != 0) Write(" "); Write(a[i, j]); } WriteLine(); } }
    static void WriteArray(int[] a, int b) { for (int i = 0; i < b; i++) { Write(" "); Write(a[i]); } WriteLine(); }
}


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

int main(){
  int N;
  vector<int> v;
  cin >> N;
  for(int i=0; i<N; i++){
    int va; cin >> va;
    v.push_back(va);
  }
  for(int i=0; i<N; i++){
    int c; cin >> c;
    v[i]-=c;
  }
  int max=0;
  for(int i=0; i<N; i++){
    if(v[i]>=0) max+=v[i];
  }
  cout << max << endl;
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <boost/range/irange.hpp>
#include <boost/range/adaptors.hpp>

using namespace std;
using namespace boost;
using namespace boost::adaptors;
using uint = unsigned int;
using ll = long long int;
using ull = unsigned long long int;

int main() {
    string a, b, c;
    cin >> a >> b >> c;
    if (a.back() == b.front() && b.back() == c.front())cout << "YES"; else cout << "NO";
    return 0;
}

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

typedef long long ll;
#define FOR(i,a,b) for(int i=(a);i<(int)(b);++i)
#define rep(i,n) FOR(i,0,n)

int main(){
    ll n;
    scanf("%lld", &n);
    vector<ll> a(n+2);
    ll tot = 0;
    rep(i,n) {
        scanf("%lld", &a[i]);
        tot += a[i];
    }
    
    ll sum = n * (n+1) / 2LL;
    if(tot % sum != 0) {
        puts("NO"); return 0;
    }

    ll d = 0, cnt = 0;
    bool f = true;
    rep(i,n){
        d = (a[(i+1) % n] - a[i]);
        d -= tot / sum;
        if(d > 0) f = false;
        if(d % n == 0) cnt += -d/n;
    }
    if(cnt != tot / sum) f = false;

    puts(f ? "YES" : "NO");

    return 0;
}

Measured memory_bytes: 1024
#include<stdio.h>
int main()
{
    int c=0,c1=0,i,t;
    scanf("%d",&t);
    for(i=1;i<=t;i++)
    {
        if(i%2==0)
            c++;
        else
            c1++;

    }
    printf("%d\n",c*c1);
return 0;
}


Measured memory_bytes: 128
#include<iostream>
#include<string>
#include<cmath>
#include<cstdlib>
#include<vector>
#include<map>
#include<set>
#include<algorithm>

using namespace std;

int main(){
  int a,b,c;
  string s1,s2;
  cin>>a>>b;

  int tmp = b-a;
  int tmp2 = 0;
  for(int i=1;i<=tmp;i++){
    tmp2 += i;
  }
  cout<<(tmp2-b)<<endl;
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(void){
  string S;
  cin >> S;
  
  int zd, fd, sd, td;
  zd = S[3] - '0';
  fd = S[2] - '0';
  sd = S[1] - '0';
  td = S[0] - '0';  
  
  string ret = "";
  
  int L = td*10+sd;
  int R = fd*10+zd;

  if(L == 0){
    if(R == 0 || R > 12) ret += "NA";
    else ret += "YYMM";
  }else if(L > 12){
    if(R == 0 || R > 12) ret += "NA";
    else ret += "YYMM";
  }else if(L <= 12){
    if(R == 0 || R > 12) ret += "MMYY";
    else ret += "AMBIGUOUS";
  }
  cout << ret << endl;
  return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<iomanip>
using namespace std;
main()
{

             long long a,b,i,j;
             cin>>a>>b;
             if(a>b){
                for(i=0;i<a;i++){
                                cout<<b;
                }
             }
             else{
                for(i=0;i<b;i++){
                                cout<<a;
                }
             }
            cout<<endl;
}


Measured memory_bytes: 3536
def main():
    H, W, D = map(int, input().split())
    A = [
        list(map(int, input().split()))
        for _ in range(H)
    ]
    Q = int(input())
    LR = [
        list(map(int, input().split()))
        for _ in range(Q)
    ]

    f(H, W, D, A, Q, LR)


def f(H, W, D, A, Q, LR):
    """
    距離を計算しておく
    """
    pos = [None for _ in range(H * W + 1)]
    for y in range(H):
        for x in range(W):
            a = A[y][x]
            pos[a] = (x, y)

    d = [0 for _ in range(H * W + 1)]
    for i in range(1, D + 1):
        current = i
        dist = 0
        while current + D <= H * W:
            _next = current + D
            i, j = pos[current]
            x, y = pos[_next]

            dist += abs(x - i) + abs(y - j)

            # print((j, i), "to", (y, x), "cur", current, "next", _next, dist)
            d[_next] = dist
            current = _next

    # print(d)

    for l, r in LR:
        ans = d[r] - d[l]
        print(ans)


if __name__ == '__main__':
    main()


Measured memory_bytes: 42376
//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>

using namespace std;

//----------------------- Print Function ----------------------//

inline void print() {
    cout << endl;
}
template <typename First, typename... Rest>
void print(const First &first, const Rest &... rest) {
    cout << first << ' ';
    print(rest...);
}

template <typename T>
void print(const vector<T> &v) {
    for (auto e : v) cout << e << ' ';
    cout << endl;
}

//------------------------- Libraries -------------------------//

//--------------------------- Solve ---------------------------//

struct edge {
    int to;
    int cost;
};

int N, M; 
vector<vector<edge>> g;
vector<bool> visited; 
vector<int> d;
bool ans = true;

void dfs(int v) {  
    visited[v] = true;
    bool res = true;
    for (auto e : g[v]) {
        if (visited[e.to]) {
            if (d[e.to] != d[v] + e.cost) {
                ans = false;
            }
        }
        else {
            d[e.to] = d[v] + e.cost;
            dfs(e.to);
        }
    }
}

void solve() {
    cin >> N >> M;
    g.resize(N);
    for (int i = 0; i < M; i++) {
        int L, R, D; cin >> L >> R >> D;
        L--; R--;
        g[L].push_back({R, D});
        g[R].push_back({L, -D});
    }

    visited.resize(N);
    d.resize(N);
    for (int i = 0; i < N; i++) {
        if (!visited[i]) {
            d[i] = 0;
            dfs(i);
        }
    }

    cout << (ans ? "Yes" : "No") << '\n';
}

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

    solve();

    return 0;
}

Measured memory_bytes: 14988
#include<cstdio>
#include<iostream>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<queue>
#include<stack>
#include<map>
#include<set>
#include<vector>
#define ll long long
#define INF 0x3f3f3f3f
using namespace std;
const int N=1e5+5;
template<class T>inline void read(T &res)
{
char c;T flag=1;
while((c=getchar())<'0'||c>'9')if(c=='-')flag=-1;res=c-'0';
while((c=getchar())>='0'&&c<='9')res=res*10+c-'0';res*=flag;
}
ll ans,n,a,b;
int main(){
	read(n),read(a),read(b);
	if((b-a)%2==0)ans=(b-a)/2;
	else {
		ans=a-1+(b-a+1)/2;
		ans=min(ans,n-b+(b-a+1)/2);
	}
	cout<<ans<<endl;
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define FAST       			ios_base :: sync_with_stdio(false); cin.tie(NULL);

int main() {
  FAST;
  string N;
  cin >> N;
  if (((N.at(0) == N.at(1)) && (N.at(1) == N.at(2))) || ((N.at(1) == N.at(2)) && (N.at(2) == N.at(3)))) {
    cout << "Yes" << endl;
  }
  else {
    cout << "No" << endl;
  }
}

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

using namespace std;

string a, b;

int main()
{
    cin >> a;
    b = a;
    
    reverse(b.begin(), b.end());
    
    for (int i = 0; i < b.size(); ++i)
    {
        if (b[i] == 'b') b[i] = 'd';
        else if (b[i] == 'd') b[i] = 'b';
        else if (b[i] == 'p') b[i] = 'q';
        else if (b[i] == 'q') b[i] = 'p';
    }
    
    if (a == b) cout << "Yes\n";
    else cout << "No\n";
    
    return 0;
}

Measured memory_bytes: 512
/*------------------------------------
........Bismillahir Rahmanir Rahim....
..........created by Abdul Aziz.......
------------------------------------*/
#include <iostream>
#include <algorithm>
#include <stdio.h>
#include <cmath>
#include <vector>
#include <set>
#include <list>
#include <stack>
#include <map>
#include <cstring>
#include <unordered_map>
#include <queue>
#define   mod  998244353
#define   int  long long 
#define   ld   long double
#define   pb   push_back
#define   vi   vector<int> 
#define   co(x)  cout << x << '\n' 
#define   dbg(x)  cerr << #x << " = " << x << '\n'
#define   sz(x)  (int)x.size()
#define   all(a) (a.begin(),a.end())
#define   ff   first
#define   ss   second
#define   pii  pair<int,int> 
#define   lcm(a,b) (a*b)/__gcd(a,b) 
using namespace std;

inline void solve(){
    int  n, len = 0 ; 
    cin >> n ; 
    map <int,int> oc; 
    for (int i=0,c;i<n;i++) {
        cin >> c ; 
        oc[c]++ ; 
        if (!oc[c+1]) oc[c+1] = oc[c]; 
        len = max(len,oc[c]); 
    }
    cout << (n - len) << endl ; 
}

signed main()
{
    int n=1; // cin>>n; 
    while (n--) solve(); 
    return 0; 
}


Measured memory_bytes: 16128
#include <iostream>
using namespace std;
int A[200001];
int arrived[200001]; // 最初にその場所についた時の使用回数

int main(void) {
  int N;
  long long K;
  cin >> N >> K;
  for (int i = 1; i <= N; i++) {
    cin >> A[i];
    arrived[i] = -1;
  }

  long long use_tlp = 0;
  int pos = 1;
  arrived[1] = 0;
  for (;;) {
    pos = A[pos];
    use_tlp++;
    if (arrived[pos] >= 0) break;
    arrived[pos] = use_tlp;
  }

  long long offset = arrived[pos];
  long long interval = use_tlp - offset;


  // 数えなおす
  if (offset >= K) {
    pos = 1;
    for (int i = 0; i < K; i++) {
      pos = A[pos];
    }
    cout << pos << endl;
    return 0;
  }

  K -= offset;
  K %= interval;
  for (int i = 0; i < K; i++) {
    pos = A[pos];
  }
  cout << pos << endl;
  return 0;
}


Measured memory_bytes: 5192
#include<stdio.h>
int main(void){
	int i,j,w,h,out[150][2],c,big,count=0,temp;
	while(1){
		scanf("%d %d",&h,&w);
		if(h==0 && w==0){
			break;
		}
		c=h*h+w*w;
		temp=150*150;
		for(i=1;i<150;i++){
			for(j=1;j<150;j++){
				if(j>i && temp>i*i+j*j){
					
					if(c<i*i+j*j && j>i){
						
						out[count][0]=i;
						out[count][1]=j;
						temp=i*i+j*j;
						//printf("temp%d,i%d,j%d,\n",temp,i,j);
					}
					if(c<=i*i+j*j && i>h){
						
						out[count][0]=i;
						out[count][1]=j;
						temp=i*i+j*j;
						//printf("temp%d,i%d,j%d,\n",temp,i,j);
					}
				}
			}
		}
	
		count++;
	}
	//printf("\n\n");
	for(i=0;i<count;i++){
		printf("%d %d\n",out[i][0],out[i][1]);
	}
	return 0;
}

Measured memory_bytes: 600
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ

		Scanner scanner = new Scanner(System.in);

		//入力表示
		String S = scanner.next();

		switch (S) {
		case "Sunny":
			System.out.println("Cloudy");
			break;
		case "Rainy":
			System.out.println("Sunny");
			break;
		case "Cloudy":
			System.out.println("Rainy");
			break;
		}
	}
}


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

int main() {
	int a,b;
	cin>>a>>b;
	if(a+b==15)
	cout<<"+";
	else if(a*b == 15)
	cout<<"*";
	else
	cout<<"x";
	return 0;
}

Measured memory_bytes: 384
from collections import Counter
import sys
sys.setrecursionlimit(100001)
def input():
    return sys.stdin.readline()[:-1]
N = int(input())
A = list(map(int, input().split()))
C = Counter(A)
ans = 0
cnt = 0
for key in C:
    if C[key] % 2:
        ans += 1
    else:
        cnt += 1
        ans += 1
print(ans - cnt % 2)


Measured memory_bytes: 18656
def main():
    import sys
    sys.setrecursionlimit(10 ** 7)
    readline = sys.stdin.readline

    def dfs(v):
        """最長有向パスに含まれる頂点数"""
        if memo[v] != -1:
            return memo[v]

        ret = 0
        for u in g[v]:
            ret = max(ret, dfs(u))
        ret += 1  # 自身
        memo[v] = ret
        return ret

    n, m = map(int, readline().split())

    g = tuple(set() for _ in range(n))
    for _ in range(m):
        x, y = (int(c) - 1 for c in input().split())
        g[x].add(y)

    memo = [-1] * n

    ret = 0
    for i in range(n):
        ret = max(ret, dfs(i))
    print(ret - 1)


if __name__ == '__main__':
    main()


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

int main(void){
	int n, t[100], m, p[100], x[100], time;
	cin >> n;
	for (int i = 0; i < n; ++i){
		cin >> t[i];
	}
	cin >> m;
	for (int i = 0; i < m; ++i){
		cin >> p[i] >> x[i];
	}
	for (int i = 0; i < m; ++i){
		time = 0;
		for (int j = 0; j < n; ++j){
			if (j + 1 == p[i]){
				time += x[i];
			}else{
				time += t[j];
			}
		}
		cout << time << endl;
	}
	return 0;
}

Measured memory_bytes: 256
#include<cstdio>
#include<algorithm>
#include<cstring>
using namespace std;
typedef long long ll;
#define M 200005
int sl[M],mp[M],vs[M];
char S[M];
inline void rd(int &l){
	l=0;int f=0;char ch=getchar();
	while(ch>'9'||ch<'0'){if(ch=='-')f=1;ch=getchar();}
	while(ch>='0'&&ch<='9'){l=l*10+ch-'0';ch=getchar();}
	if(f)l=-l;
}
int main(){
	int N,K,C,tp=1;
	rd(N);rd(K);rd(C);
	scanf("%s",S+1);
	for(int i=1;i<=N;++i)mp[i]=(S[i]=='x');
	for(int i=1;i<=K;++i){
		while(tp<=N&&mp[tp])++tp;
		sl[i]=tp;
		tp+=C+1;
	}
	if(K&&sl[K]){
		tp=N;
		for(int i=K;i;--i){
			while(tp&&mp[tp])--tp;
			vs[i]=tp;
			// printf("%d %d\n",sl[i],vs[i]);
			tp-=C+1;
		}
		for(int i=1;i<=K;++i)if(vs[i]==sl[i])printf("%d\n",vs[i]);
	}
	// getchar();
	// getchar();
	return 0;
}

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

struct UnionFind
{
    vector<int> par; // par[i]:iの親の番号　(例) par[3] = 2 : 3の親が2

    UnionFind(int N) : par(N)
    { // 最初は全てが根であるとして初期化
        for (int i = 0; i < N; i++)
            par[i] = i;
    }

    int root(int x)
    { // データxが属する木の根を再帰で得る：root(x) = {xの木の根}
        if (par[x] == x)
            return x;
        return par[x] = root(par[x]);
    }

    void unite(int x, int y)
    {                     // xとyの木を併合
        int rx = root(x); //xの根をrx
        int ry = root(y); //yの根をry
        if (rx == ry)
            return;   //xとyの根が同じ(=同じ木にある)時はそのまま
        par[rx] = ry; //xとyの根が同じでない(=同じ木にない)時：xの根rxをyの根ryにつける
    }

    bool same(int x, int y)
    { // 2つのデータx, yが属する木が同じならtrueを返す
        int rx = root(x);
        int ry = root(y);
        return rx == ry;
    }
};

int main()
{
    int n;
    cin >> n;
    vector<pint> x(n), y(n);
    rep(i, n)
    {
        int X, Y;
        cin >> X >> Y;
        x[i] = pint(X, i);
        y[i] = pint(Y, i);
    }

    sort(x.begin(), x.end());
    sort(y.begin(), y.end());

    vector<ppint> dx(n - 1), dy(n - 1);
    rep(i, n - 1)
    {
        dx[i] = ppint(abs(x[i + 1].first - x[i].first), pint(x[i].second, x[i + 1].second));
        dy[i] = ppint(abs(y[i + 1].first - y[i].first), pint(y[i].second, y[i + 1].second));
    }

    sort(dx.begin(), dx.end());
    sort(dy.begin(), dy.end());

    int rx = 0, ry = 0;
    UnionFind tree(n);

    ll ans = 0;

    while (1)
    {
        if (rx == n - 1 && ry == n - 1)
            break;
        int ddx = INT32_MAX, ddy = INT32_MAX;
        if (rx != n - 1)
            ddx = dx[rx].first;
        if (ry != n - 1)
            ddy = dy[ry].first;
        int a, b, d;
        if (ddx < ddy)
        {
            a = dx[rx].second.first;
            b = dx[rx].second.second;
            ++rx;
            d = ddx;
        }
        else
        {
            a = dy[ry].second.first;
            b = dy[ry].second.second;
            ++ry;
            d = ddy;
        }
        if (!tree.same(a, b))
        {
            tree.unite(a, b);
            ans += d;
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 10464
import java.io.IOException;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) throws NumberFormatException, IOException {

		Scanner sc = new Scanner(System.in);

		String S = sc.next();
		StringBuffer sb = new StringBuffer();

		for (int i=0; i <S.length(); i++){
			if (i % 2 == 0){
				sb.append(S.charAt(i));
			}
		}
		System.out.println(sb.toString());
	}
}



Measured memory_bytes: 25368
import java.util.Scanner;

public class Main {
    public static int findMinCost(int heights[],int k){
        int n = heights.length;
        int[] min = new int[n];
        min[0] = 0;
        min[1] = Math.abs(heights[1]-heights[0]);
        for(int i=2;i<n;i++){
            int temp;
            min[i] = Integer.MAX_VALUE;
            int count = k;
            for(int j=i-1;count-->0 && j>=0;j--){
                temp = Math.abs(heights[i]-heights[j])+min[j];
                min[i] = Math.min(temp,min[i]);
            }
        }
        return min[n-1];
    }
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int k = sc.nextInt();
        int heights[] = new int[n];
        for(int i=0;i<n;i++){
            heights[i] = sc.nextInt();
        }
        System.out.println(findMinCost(heights,k));
    }
}


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

int main() {
  int N, A, B;
  int sum = 0;

  cin >> N >> A >> B;

  int wa[N];

  for(int i = 1; i <= N; i++){
    int j = i;
    wa[i - 1] = 0;

    while(j != 0){
      wa[i - 1] += j % 10;
      j /= 10;
    }
  }

  for(int i = 0; i < N; i++){
    if(wa[i] >= A && wa[i] <= B){
      sum += i + 1;
    }
  }

  cout << sum << endl;


  return 0;
}

Measured memory_bytes: 256
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.StringTokenizer;
import java.io.IOException;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 *
 * @author Jasper van Merle
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        InputReader in = new InputReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        TaskB solver = new TaskB();
        solver.solve(1, in, out);
        out.close();
    }

    static class TaskB {
        public void solve(int testNumber, InputReader in, PrintWriter out) {
            int n = in.nextInt();

            int max = Integer.MAX_VALUE;

            for (int i = 0; i < n; i++) {
                int a = in.nextInt();

                int total = 0;

                while (a % 2 == 0) {
                    a /= 2;
                    total++;
                }

                if (total < max) {
                    max = total;
                }
            }

            out.println(max);
        }

    }

    static class InputReader {
        private BufferedReader br;
        private StringTokenizer st;

        public InputReader(InputStream in) {
            br = new BufferedReader(new InputStreamReader(in));
        }

        public String next() {
            while (st == null || !st.hasMoreElements()) {
                try {
                    st = new StringTokenizer(br.readLine());
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }

            return st.nextToken();
        }

        public int nextInt() {
            return Integer.parseInt(next());
        }

    }
}



Measured memory_bytes: 21460
#include<cstdio>
#include<algorithm>
using namespace std;
int n;
struct node{
	int val,id;
}a[200001];
inline bool cmp(node x,node y){
	return x.val>y.val;
}
int main(){
	scanf("%d",&n);
	for(register int i=1;i<=n;i++){
		scanf("%d",&a[i].val);
		a[i].id=i;
	}
	sort(a+1,a+1+n,cmp);
	for(register int i=1;i<=n;i++){
		if(i==a[1].id)printf("%d\n",a[2].val);
		else printf("%d\n",a[1].val);
	}
}

Measured memory_bytes: 3072
#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 INIT(a,n,x); REP(i,(n)){ (a)[i]=(x); }
#define CINA(a,n); REP(i,(n)){ cin >> (a)[i]; }
#define INIT2(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 );}
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;}

string solve(){
  ll N; cin>>N;
  string ans = "";
  ll temp = N;
  ll i = 0;
  while(temp!=0){
    if(temp%2==0){
      ans += "0";
      temp /= -2;
    }
    else{
      ans += "1";
      temp = (temp-1)/(-2);
    }
    ++i;
  }
  if(ans.size()>0){
    reverse(ALL(ans));
  }else{
    ans = "0";
  }
  return ans;
}

int main(){
  cout << solve()<<"\n";
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (n); i++)
#define ALL(v) (v).begin(), (v).end()
using ll = long long;
using P = pair<int, int>;
constexpr int INF = 1e9;
constexpr long long LINF = 1e18;
constexpr long long MOD = 1e9 + 7;

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

Measured memory_bytes: 5184
#include "bits/stdc++.h"
using namespace std;
#define FOR(i,j,k) for(int (i)=(j);(i)<(int)(k);++(i))
#define rep(i,j) FOR(i,0,j)
#define each(x,y) for(auto &(x):(y))
#define mp make_pair
#define MT make_tuple
#define all(x) (x).begin(),(x).end()
#define debug(x) cout<<#x<<": "<<(x)<<endl
#define smax(x,y) (x)=max((x),(y))
#define smin(x,y) (x)=min((x),(y))
#define MEM(x,y) memset((x),(y),sizeof (x))
#define sz(x) (int)(x).size()
#define rt return
using dbl = double;
using ll = long long;
using pii = pair<int, int>;
using vi = vector<int>;
using vll = vector<ll>;

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    int N;
    cin >> N;
    
    using E = tuple<int, int, int>;
    vector<E> e;
    vector<vi> A(N, vi(N));

    ll INF = LLONG_MAX / 10;
    vector<vll> D(N, vll(N, INF));
    rep(i, N)D[i][i] = 0;
    rep(i, N)rep(j, N) {
        cin >> A[i][j];
        if (i < j) {
            e.emplace_back(A[i][j], i, j);
        }
    }
    sort(all(e));

    ll ans = 0;
    each(a, e) {
        int d, u, v;
        tie(d, u, v) = a;
        if (d > D[u][v]) {
            cout << -1 << endl;
            return 0;
        }
        
        if (d < D[u][v]) {
            D[u][v] = D[v][u] = d;
            ans += d;
            rep(x, N)rep(y, N) {
                D[x][y] = min(D[x][y], D[x][u] + D[u][v] + D[v][y]);
                D[x][y] = min(D[x][y], D[x][v] + D[v][u] + D[u][y]);
            }
        }
    }

    cout << ans << endl;
}


Measured memory_bytes: 2304
#include <cstdio>
#include <sstream>
#include <cstdlib>
#include <cctype>
#include <cmath>
#include <algorithm>
#include <set>
#include <queue>
#include <stack>
#include <list>
#include <iostream>
#include <fstream>
#include <numeric>
#include <string>
#include <vector>
#include <cstring>
#include <map>
#include <iterator>
#include <iomanip>
#include <unordered_map>

using namespace std;

int n,x,y;

int dist(int i, int j)
{   
    return min( (j-i), abs(i-x)+abs(j-y)+1 );
}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);

    cin>>n>>x>>y;
    int graph[n]={};
    
    for (int i = 1; i < n; ++i)
    {
        for (int j = i+1; j < n+1; ++j)
        {
            graph[dist(i,j)]++;
        }
    }
    for (int i = 1; i < n; ++i)
    {
        cout<<graph[i]<<endl;
    }

}



Measured memory_bytes: 256
#include<bits/stdc++.h>
#define F first
#define S second
#define PB push_back
#define MP make_pair
#define endl '\n'

using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef pair<int,int> pi;

ll ar[200005];

int main()
{
    string s,t,r;
    t="s";
    r="es";
    cin>>s;
    ll a,b;
    a=s.size();
    if(s[a-1]=='s')
    {
        cout<<s<<r<<endl;
    }
    else{
        cout<<s<<t<<endl;
    }
    return 0;
}


Measured memory_bytes: 3628
#include <iostream>
#include <string>
#include <vector>
#include <set>
#include <algorithm>
#include <cctype>
#include <cmath>
#include <queue>
#include <map>
#include <numeric>
#include <unordered_map>
#include <iomanip>
#include <functional>
#include <bitset>
#include <complex>
#include <stack>



#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define repi(i,a,b) for(int i=int(a);i<int(b);i++)
#define all(x) (x).begin(),(x).end()

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; }

typedef long long ll;

using namespace std;


int main()
{
  ios::sync_with_stdio(false);
  cin.tie(0);
  int a,b;
  cin>>a>>b;
  cout<<(a+b)%24<<endl;

  return 0;

}


Measured memory_bytes: 256
#include<iostream>
#include<vector>
using namespace std;
int main(){
    int n,m;
    cin >> n >> m;
    vector<vector<char>>field_first;
    vector<vector<int>> field_second;
    vector<char>v(m,'.');
    vector<int>v2(m,-1);
    for(int i = 0;i < n;i++){
        field_first.push_back(v);
        field_second.push_back(v2);
    }
    for(int i = 0;i < n;i++){
        for(int j = 0;j < m;j++){
            
            cin >> field_first[i][j];

        }
    }
    for(int i = 0;i < m;i++){
        for(int j = 0;j < n;j++){
            for(int k = 0;k < m;k++){
                if(field_first[j][k] == 'c' && field_second[j][k] == -1){
                    field_second[j][k] = i;                    
                }
            }
        }
        if(i != m - 1){
            for(int j = 0;j < n;j++){
                for(int k = m - 1;k > -1;k--){
                    if(field_first[j][k] == 'c' ){
                        if(m != m - 1)field_first[j][k + 1] = 'c';
                        field_first[j][k] = '.';
                        
                    }
                }
            }
        }
    }
    for(int i = 0; i < n;i++){
        for(int j = 0; j < m;j++){
            cout << field_second[i][j];
            if(j != m - 1)cout << " ";
        }
        cout << endl;
    }
    return 0;
}


Measured memory_bytes: 3188
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const ll INF = 1e18;
const ll mod = 1000000007;

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
template<class T> inline bool chmax(T& a, T b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template<class T> inline bool chmin(T& a, T b) {
  if (a > b) {
    a = b;
    return 1;
  }
  return 0;
}
int ctoi(char c) {
  if (c >= '0' && c <= '9') {
    return c - '0';
  }
  return 0;
}
ll factorial(ll n) {
  if (n == 1) {
    return 1;
  }
  ll ans = factorial(n-1);
  return ans*n;
}
ll gcd(ll a, ll b) {
  if (a < b) {
    ll tmp = a;
    a = b;
    b = tmp;
  }
  ll r = a%b;
  while(r != 0) {
    a = b;
    b = r;
    r = a%b;
  }
  return b;
}
ll lcm(ll a, ll b) {
  return (a/gcd(a, b))*b;
}

int main() {
  ll n;
  cin >> n;
  vector <vector <ll>> v(n, vector <ll> (n, 0));
  ll u, k;
  rep(i, n) {
    cin >> u >> k;
    rep(j, k) {
      ll a;
      cin >> a;
      v.at(u-1).at(a-1)++;
    }
  }
  rep(i, n) {
    rep(j, n) {
      if (j) {
        cout << ' ' << v.at(i).at(j);
      } else {
        cout << v.at(i).at(j);
      }
    }
    cout << endl;
  }
}


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

using int32 = int_fast32_t;
using int64 = int_fast64_t;

const int32 INF = 1e9;
const int32 MOD = 1e9+7;
const int64 LLINF = 1e18;

#define YES(n) cout << ((n) ? "YES\n" : "NO\n"  )
#define Yes(n) cout << ((n) ? "Yes\n" : "No\n"  )
#define POSSIBLE cout << ((n) ? "POSSIBLE\n" : "IMPOSSIBLE\n"  )
#define ANS(n) cout << (n) << "\n"
#define REP(i,n) for(int64 i=0;i<(n);++i)
#define FOR(i,a,b) for(int64 i=(a);i<(b);i++)
#define FORR(i,a,b) for(int64 i=(a);i>=(b);i--)
#define ALL(obj) (obj).begin(),(obj).end()
#define pii pair<int32,int32>
#define pll pair<int64,int64>
#define pb(a) push_back(a)

int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  int32 n;
  cin >> n;
  vector<int32> x(n);
  REP(i,n)cin >> x[i];
  int32 ans = INF;
  REP(j,101){
    int32 s = 0;
    REP(i,n){
      s += (x[i] - j) * (x[i] - j);
    }
    ans = min(ans, s);
  }
  ANS(ans);
  return 0;
}

Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main(){
  int n;
  unsigned long long int ans = 1, pre = 2;
  
  cin >> n;
 
  if(n == 1){
    ans = 1;
  }
  else{
  	 for(int i = 1; i < n; i++){
       unsigned long long int tmp = ans;
       ans += pre;
       pre = tmp;
     }
  }
  
  cout << ans << endl;
  
  return 0;
}

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

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

    long long ans = 0;

    for (int i = 1; i <= N; ++i){
        if( i%3 == 0 or i%5==0 ){
            continue;
        }else{
            ans += i;
        }
    }

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

Measured memory_bytes: 3636
#include <iostream>
#include <algorithm>

using namespace std;

int check(int a[51], int n)
{
	int c=0, r=-1;
	
	for(int i = 0; i < n; i++){
		if(a[i] > 0){
			c++;
			r = i;
		}
	}
	if(c > 1){
		r = -1;
	}
	
	return r;
}

int main()
{
	int n, p, s, t, a[51];
	
	while(1){
		cin >> n >> p;
		if(n == 0 && p == 0){
			break;
		}
		fill(a, a+51, 0);
		t = 0;
		bool f = true;
		for(int i = 0; i < 1000000; i++){
			if(p == 0){
				s = check(a, n);
				if(s != -1){
					cout << s << endl;
					f = false;
					break;
				}
				p += a[t];
				a[t] = 0;
			} else {
				p--;
				a[t]++;
			}
			
			t++;
			if(n == t){
				t = 0;
			}
		}
		
		if(f){
			cout << 0 << endl;
		}
	}
	
	return 0;
}

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

typedef long long ll;
const ll INF = 1LL<<60, MOD = 1e9 + 7;
#define REP(i,a,b) for(ll i=a;i<b;i++)
#define rep(i,n) REP(i,0,n)
#define all(v) (v).begin(), (v).end()
#define m_p make_pair

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    ll n,sum=0;
    cin >> n;
    vector<ll> b(n-1),a(n);
    rep(i,n-1) cin >> b[i];
    if(n==2) sum += b[0]*2;
    else{
        a[0] = b[0];
        rep(i,n-2){
            a[i+1] = min(b[i],b[i+1]);
        }
        a[n-1] = b[n-2];
        rep(i,n) sum += a[i];
    }
    cout << sum << endl;
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define PB push_back
#define PPB pop_back
#define MP make_pair
#define IOS ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define test(x) cout<<(x)<<" "
#define d1(x) cout<<(x)<<endl
#define d2(x,y) cout<<(x)<<" "<<(y)<<endl
#define d3(x,y,z) cout<<(x)<<" "<<(y)<<" "<<(z)<<endl
#define loop(i,start,end) for(ll i=start; i<end; i++)
#define rloop(j,start,end) for(ll j=start-1; j>=end; j--)

int main()
{   
    IOS;

    ll n,W;
    cin>>n>>W;

    ll v[n+1],w[n+1],sumV=0;

    loop(i,1,n+1)
    {  
        cin>>w[i]>>v[i];
        //sumV+=v[i];
    }

    ll dp[W+1]={0};
    // maximum value with the items for weight
    loop(i,1,n+1)
        rloop(j,W+1,w[i])
            dp[j]=max(dp[j],v[i]+dp[j-w[i]]);
    
    d1(dp[W]);
}

Measured memory_bytes: 1024
#include <iostream>

using namespace std;

int main(int argc, char const *argv[])
{
	int n;
	int cnt;
	int sum;
	int i1,i2;

	while(1){
		cin>>n;
		if(n==0) break;

		cnt=0;

		for(i1=1;i1<=n/2;i1++){
			sum=0;
			i2=i1;
			while(1){
				sum+=i2;
				
				if(sum==n) {
					cnt++;
					break;
				}
				else if(sum>n) break;

				i2++;
			}
		}
		cout<<cnt<<endl;
	}
	return 0;
}

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

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

  sort(s.begin(), s.end());
  sort(t.begin(), t.end());
  reverse(t.begin(), t.end());

  if (s < t) cout << "Yes" << endl;
  else
    cout << "No" << endl;
  return 0;
}


Measured memory_bytes: 256
//ABC 073 D
#include <iostream>
#include <vector>
#include <array>
#include <algorithm>
#include <cstdio>
#include <cstdlib>
#include <string>
#include <iomanip>
#include <map>
using namespace std;

#define INF (1<<29)

int N, M, R;
int d[201][201];
int r[9];
int A, B, C;
int res;
bool used[9];

//c:次に通過する町の数
//las:今いる町・最後に通った町
//dist:今現在の距離、最初は0からスタート
void dfs(int c, int las, int dist) {

	//すでにすべての町を通っているなら
	if (c == R + 1) {
		//距離を更新しておしまい
		if (res > dist)res = dist;
		return;
	}
	//そうでないなら
	for (int i = 1; i <= R; i++)
		//次はまだ通過していないi番目に向かう
		if(!used[i]) {
			//通過フラグを立て
			used[i] = true;
			//どの町もまだ通っていないなら距離0として探索を続け
			if (las == -1)dfs(c + 1, i, 0);
			//そうでないならここからの距離を加算し探索を続ける
			else dfs(c + 1, i, dist + d[r[las]][r[i]]);
			//最後に探索を終えて戻ってくるとき、通過フラグを取り消す
			used[i] = false;
		}

}

int main() {
	scanf("%d%d%d", &N, &M, &R);
	for (int i = 1; i <= N; i++)for (int j = 1; j <= N; j++)if (i != j)d[i][j] = INF;
	for (int i = 1; i <= R; i++)scanf("%d", &r[i]);//どの町を通れば良いか
	for (int i = 1; i <= M; i++) {
		scanf("%d%d%d", &A, &B, &C);
		//もし今現在の距離が与えられた距離より大きければ、与えられた距離に直す
		if (d[A][B] > C)d[A][B] = d[B][A] = C;
	}

	//ワーシャルフロイド法
	//単純な三重ループで書きやすいのが嬉しい
	for (int k = 1; k <= N; k++)
		for (int i = 1; i <= N; i++)
			for (int j = 1; j <= N; j++)
				//経由した方が早いならそっちを最短距離に
				if (d[i][j] > d[i][k] + d[k][j])
					d[i][j] = d[i][k] + d[k][j];
	//これで各点間の最短距離が求まりました！

	res = INF;

	//あとはRすべてを通るときの最短距離を深さ優先探索で求める
	dfs(1, -1, 0);


	//最短距離を表示しておしまい
	printf("%d\n", res);




	return 0;
}

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

int main() {
	long long n, m; cin >> n >> m;
	pair<long long, long long> d[n];
	for (int i = 0; i < n; i++)
	{
		cin >> d[i].first >> d[i].second;
	}
	sort(d, d + n);

	long long res = 0, id = 0;
	while (m > 0)
	{
		res += d[id].first * min(m, d[id].second);
		m -= min(m, d[id].second);
		id++;
	}
	cout << res << endl;
	return 0;
}


Measured memory_bytes: 5172
/**
 * File    : JOI_2007_darts.cpp
 * Author  : Kazune Takahashi
 * Created : 2018-3-8 20:45:20
 * Powered by Visual Studio Code
 */

#include <iostream>
#include <iomanip>   // << fixed << setprecision(xxx)
#include <algorithm> // do { } while ( next_permutation(A, A+xxx) ) ;
#include <vector>
#include <string> // to_string(nnn) // substr(m, n) // stoi(nnn)
#include <complex>
#include <tuple>
#include <queue>
#include <stack>
#include <map> // if (M.find(key) != M.end()) { }
#include <set>
#include <random> // random_device rd; mt19937 mt(rd());
#include <cctype>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <cstdlib>
using namespace std;

#define DEBUG 0 // change 0 -> 1 if we need debug.

typedef long long ll;

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

// const int C = 1e6+10;
// const ll M = 1000000007;

int N, M;
int P[1010];
vector<int> S;

int main()
{
  while (cin >> N >> M && N && M)
  {
    S.clear();
    for (auto i = 0; i < N; i++)
    {
      cin >> P[i];
    }
    P[N] = 0;
    N++;
    for (auto i = 0; i < N; i++)
    {
      for (auto j = i; j < N; j++)
      {
        int sum = P[i] + P[j];
        if (sum <= M)
        {
          S.push_back(sum);
        }
      }
    }
    sort(S.begin(), S.end());
    int ans = 0;
    int l = 0;
    int r = S.size() - 1;
    while (l <= r)
    {
      int sum = S[l] + S[r];
      if (sum <= M)
      {
        ans = max(ans, sum);
        l++;
      }
      else
      {
        r--;
      }
    }
    cout << ans << endl;
  }
}


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

int a, b;

void solve() {
    cin >> a >> b;
    cout << (a > 9 || b > 9 ? -1 : a * b) << "\n";
}

int main() {
    
    ios_base::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);
    
    solve();
    
}

Measured memory_bytes: 3660
#include<bits/stdc++.h>
using namespace std;
namespace Flandle_Scarlet
{
    #define N 200100
    class DSU
    {
        public:
            int Father[N],Cnt[N];
            void Init()
            {
                for(int i=0;i<N;i++)
                {
                    Father[i]=i;
                    Cnt[i]=1;
                }
            }
            int Find(int x)
            {
                return (x==Father[x])?x:(Father[x]=Find(Father[x]));
            }
            void Merge(int x,int y)
            {
                int ax=Find(x),ay=Find(y);
                if (Cnt[ax]<Cnt[ay])
                {
                    Cnt[ay]+=Cnt[ax];
                    Father[ax]=ay;
                }
                else
                {
                    Cnt[ax]+=Cnt[ay];
                    Father[ay]=ax;
                }
            }
    }D1,D2;
    int n,k,l;
    void R1(int &x)
    {
        x=0;char c=getchar();int f=1;
        while(c<'0' or c>'9') f=(c=='-')?-1:1,c=getchar();
        while(c>='0' and c<='9') x=(x<<1)+(x<<3)+(c^48),c=getchar();
        x=(f==1)?x:-x;
    }
    void Input()
    {
        R1(n),R1(k),R1(l);
        D1.Init();
        D2.Init();
        for(int i=1;i<=k;++i)
        {
            int a,b;
            R1(a),R1(b);
            D1.Merge(a,b);
        }
        for(int i=1;i<=l;++i)
        {
            int a,b;
            R1(a),R1(b);
            D2.Merge(a,b);
        }
    }
    #define pii pair<int,int>
    #define _1 first
    #define _2 second
    map<pii,int> rec;
    void Soviet()
    {
        for(int i=1;i<=n;++i)
        {
            int an1=D1.Find(i),an2=D2.Find(i);
            rec[make_pair(an1,an2)]++;
        }
        for(int i=1;i<=n;++i)
        {
            int an1=D1.Find(i),an2=D2.Find(i);
            printf("%d ",rec[make_pair(an1,an2)]);
        }
    }
    void IsMyWife()
    {
        if (0)
        {
            freopen("","r",stdin);
            freopen("","w",stdout);
        }
        Input();
        Soviet();
    }
};
int main()
{
    Flandle_Scarlet::IsMyWife();
    return 0;
}


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

#define int long long

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

int N;

signed main() {
    cin >> N;
    int ans = 10000;
    for (int i = 0; i < N; i++) {
        int A;
        cin >> A;
        int cur = 0;
        while (A % 2 == 0) {
            A /= 2;
            cur++;
        }
        ans = min(ans, cur);
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
def main():
	A, B, C, D = map(int, input().split())
	div_c, div_d, div_cd = 0, 0, 0

	def gcd(x, y):
		if x > y:
			x, y = y, x
		if y % x == 0:
			return x
		return gcd(y%x, x)
	div_c = B//C - A//C
	div_d = B//D - A//D
	if A%C==0:
		div_c += 1
	if A%D==0:
		div_d += 1
	cd = C*D//gcd(C, D)
	div_cd = B//cd - A//cd
	if A%cd==0:
		div_cd += 1
	divable = div_c+div_d-div_cd
	total = B-A+1
	print(total-divable)


if __name__ == '__main__':
	main()

Measured memory_bytes: 3064
// Problem : C - Skill Up
// Contest : AtCoder - AtCoder Beginner Contest 167
// URL : https://atcoder.jp/contests/abc167/tasks/abc167_c
// Memory Limit : 1024.000000 MB 
// Time Limit : 2000.000000 milisec 
// Powered by CP Editor (https://github.com/coder3101/cp-editor)

#include<bits/stdc++.h>
#define ll                    long long int
#define pb                    push_back
#define F                     first
#define S                     second
#define mp                    make_pair
#define MOD                   1000000007
#define vi                    vector<int>
#define vll                   vector<ll>
#define pll                   pair<ll,ll>
#define pii                   pair<int,int>
#define all(p)                p.begin(),p.end()
#define mid(s,e)              (s+(e-s)/2)
#define eb                    emplace_back
#define ull                   unsigned long long
#define bug(x)				  cout<<"  [ "#x<<" = "<<x<<" ]"<<endl;
#define KAMEHAMEHA            ios_base::sync_with_stdio(0);
#define RASENGAN              ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
using namespace std;
int n,m,x,mn=INT_MAX;
int c[12],a[12][12];
void func(int book,vi sum,int total)
{
	if(book==n)
		return;
	func(book+1,sum,total);
	bool check=true;
	total+=c[book];
	for(int i=0;i<m;i++)
	{
		sum[i]+=a[book][i];
		if(sum[i]<x)
			check=false;
	}
	if(check==true)
		mn=min(mn,total);
	func(book+1,sum,total);
}
int main()
{
    KAMEHAMEHA
//    #ifdef _soumik
//        freopen("input.txt", "r", stdin);
//    #endif
	
	cin>>n>>m>>x;
	
	for(int i=0;i<n;i++)
	{
		cin>>c[i];
		for(int j=0;j<m;j++)
			cin>>a[i][j];
	}
	vi sum(m);
	func(0,sum,0);
	if(mn==INT_MAX)
		cout<<-1<<endl;
	else
		cout<<mn<<endl;
    return 0;
}



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

#define loop(i,n) for(int i = 0;i < int(n);i++)
#define rloop(i,n) for(int i = int(n);i >= 0;i--)
#define range(i,a,b) for(int i = int(a);i <= int(b);i++)
#define SZ(c) int(c.size())
#define ALL(c) c.begin(), c.end()
#define RALL(c) c.rbegin(), c.rend()
#define PI acos(-1)
#define pb push_back
#define mp make_pair
#define fr first
#define sc second
#define sfi1(v) scanf("%d",&v)
#define sfi2(v1,v2) scanf("%d %d",&v1,&v2)
#define sfi3(v1,v2,v3) scanf("%d %d %d",&v1,&v2,&v3)
#define sfll1(v) scanf("%I64d",&v);
#define sfll2(v1,v2) scanf("%I64d %I64d",&v1,&v2)
#define sfll3(v1,v2,v3) scanf("%I64d %I64d %I64d",&v1,&v2,&v3)
#define endl '\n'

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



int main()
{

#ifndef ONLINE_JUDGE
	//freopen("in.in", "r", stdin);
	//freopen("out.in", "w", stdout);
#endif
	ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);


    int a;
    cin >> a;
    cout << a + a * a + a * a * a << endl;

    return 0;
}


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

signed main(){
    int h,w;cin>>h>>w;
    rep(i,h){
        string s;
        cin>>s;
        cout<<s<<endl<<s<<endl;
    }
}

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

//#include <atcoder/all>

using namespace std;
//using namespace atcoder;

//#define int long long
#define ll long long

ll INF = (1LL << 60);
int mod = 998244353;
using P = pair<ll, ll>;

signed main() {
	int n; cin >> n;
	int ans = (n + 1) / 2;
	cout << fixed << setprecision(15) << (double)ans / (double)n << endl;
	return 0;
}



Measured memory_bytes: 3668