akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
#define FAST ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0)
#define dofloat cout<<fixed<<setprecision(8)
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define bitcount __builtin_popcount
#define all(vec) vec.begin(),vec.end()
#define rall(vec) vec.rbegin(),vec.rend()
using namespace std;
typedef long long ll;
typedef long double ld;
typedef vector<long long> vl;
typedef pair<long long,long long> pll;
typedef vector<pair<long long,long long> > vll;
typedef vector<pair<int,int> > vii;
typedef vector<int> vi;
typedef pair<int,int> ii;
const long long MOD=1000000007;
const long long MAX=100005;
const long double PI=3.14159265359;
const long double G=9.807;
const long long INF=1e18;
const long double EPS=1e-6;
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
bool isprime(ll a){
  if(a==2)return 1;
  if(!(a&1))return 0;
  for(ll i=3;i*i<=a;i+=2)
    if(a%i==0)return 0;
  return 1;
}
ll mpow(ll base,ll exponent,ll modulus){
  if(modulus==1)return 0;
  long long result = 1;
  base=base%modulus;
  while(exponent){
    if(exponent%2 == 1)
    result=(result*base)%modulus;
    exponent=exponent>>1;
    base=(base*base)%modulus;
  }
  return result;
}
ll minv(ll a,ll mod){
  ll _gcd=gcd(a,mod);
  assert(_gcd==1);
  return mpow(a,mod-2,mod);
}


/*
ll ncr(ll N,ll K){
  if(N<K)return 0;
  if(K==0)return 1;
  if(N==0)return 0;

  ll den=1;
  for(ll i=1;i<=K;i++)den*=i;
  ll num=1;
  while(K--){
    num*=N;
    if(num%den==0){
      num/=den;
      den=1;
    }
    N--;
  }

  return num;
}
*/
string s;
int main(){FAST;
  ll k;cin>>k;
cin>>s;
if(s.length()<=k){
  cout<<s;
}
else{
  for(ll i=0;i<k;++i)cout<<s[i];
  cout<<"...";
}
return 0;
}

/*
 WA? check edge cases, N=1,M=1 etc. Read code fully once and check all variables.
 Read the question again and see what you might have missed.
 Consider changing your solution or find more cases.
 */


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

#define rep(i, n) for(int i = 0; i < n; i++)

using namespace std;
using ll = long long;
int mod = 1000000007;

void solve();

int main(void){
    int K, T; cin >> K >> T;
    int A[T];
    rep(i, T) cin >> A[i];
    if(T == 1){ cout << A[0]-1 << endl; return 0;}
    rep(i, K){
        int first, second;
        if(A[0] > A[1]) {first = 0; second = 1;}
        else {first = 1; second = 0;}
        for(int j = 2; j < T; j++){
            if(A[j] > A[first]){
                second = first;
                first = j;
            }
            else if(A[j] > A[second]){
                second = j;
            }
        }
        if(A[second] == 0){
            cout << A[first]-1 << endl;
            break;
        }
        if(i % 2 == 0) A[first]--;
        else A[second]--;
    }
    return 0;
}

void solve(){}

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

#define t_case ll test;cin>>test;while(test--)
#define left(nod) 2*nod
#define right(nod) 2*nod+1
#define ss second
#define ff first
#define pb push_back
#define pll pair<ll,ll>
#define FAST ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define deb(a) cout<<#a<<": "<<a;cout<<endl;
#define deba(a...) cout<<endl;cout<<#a<<": ";for(auto it:a)cout<<it<<" ";cout<<endl;

int main()
{
	FAST;//not faster than scanf printf
	
	ll n;cin>>n;ll a[200009];
	for(ll i=1;i<=n;i++)cin>>a[i];
	
	ll p[200009];p[n+1]=0;ll mo=1e9+7;
	for(ll i=n;i>=1;i--)p[i]=(p[i+1]+a[i])%mo;
	ll s=0;
	for(ll i=1;i<=n-1;i++)
	{
		s+=(a[i]*p[i+1])%mo;s%=mo;
		
	}
	
	cout<<s;
	
}


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

#define REP(i, n) for (ll i = 0; i < (ll)(n); i++)
#define REPD(i, n) for (ll i = n - 1; i >= 0; i--)
#define FOR(i, a, b) for (ll i = a; i <= (ll)(b); i++)
#define FORD(i, a, b) for (ll i = a; i >= (ll)(b); i--)

#define ALL(x) (x).begin(), (x).end()
#define SIZE(x) ((ll)(x).size())
#define MAX(x) *max_element(ALL(x))
#define MIN(x) *min_element(ALL(x))

#define INF 1000000000000
#define MOD 1000000007
#define MAXR 100000

using namespace std;
typedef long long ll;

int main() {
    using Graph = vector<vector<int>>; // グラフ型
    ll N, M;
    cin >> N >> M;
    Graph G(N);
    int A, B;
    REP(i, M){
        cin >> A >> B;
        G[A-1].push_back(B-1);
        G[B-1].push_back(A-1);
    }
    vector<int> parent(N, -1);
    vector<bool> seen(N, false);
    int count = 0;
    queue<int> q;
    q.push(0);
    seen[0] = true;
    while(!q.empty()){
        int current = q.front();
        q.pop();
        for (int g : G[current]){
            if (!seen[g]){
                seen[g] = true;
                parent[g] = current;
                q.push(g);
            }
        }
    }
    if (*min_element(ALL(seen)) == 0){
        cout << "No";
    }else{
        cout << "Yes" << endl;
        FOR(i, 1, seen.size()-1){
            cout << parent[i]+1 << endl;
        }
    }
}

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

int main() {
  int A, B, C, D;
  int left, right;
  
  cin >> A >> B >> C >> D;
  left = A+B; right = C+D;
  if (left > right){
    cout << "Left" << endl;
  }else if(left < right){ 
    cout << "Right" << endl;
  }else{
    cout << "Balanced" << endl;
  }
}

Measured memory_bytes: 3564
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time,copy,functools
from collections import deque

sys.setrecursionlimit(10**7)
inf = 10**20
mod = 10**9 + 7

DR = [1, -1, 0, 0]
DC = [0, 0, 1, -1]

def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def S(): return input()
     
def main():
    n, m, d = LI()
    if d == 0:
        p = (m-1) / n
    else:
        p = 2 * (n-d) * (m-1) / (n * n)
    print(p)
main()



Measured memory_bytes: 5436
using System;
using System.Collections.Generic;
using System.Windows;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Atcoder
{
    public class Program
    {
        static void Main(string[] args)
        {
            var s = Read();
            long now = 0;
            var k = 1;
            var rest = new int[10000];
            long ans = 0;
            rest[0] = 1;
            for (int i = 0; i < s.Length; i++)
            {
                var si = s[s.Length - i - 1].Long();
                now += si * k % 2019;
                now = now % 2019;
                ans += rest[now];
                rest[now] += 1;
                k = k * 10 % 2019;
            }
            WriteRead(ans);
        }
        
        public static string Read()
        {
            return Console.ReadLine();
        }

        public static string[] ReadSplit()
        {
            return Console.ReadLine().Split(' ');
        }

        public static void WriteRead(object str)
        {
            Console.WriteLine(str);
            Read();
        }

        public static void Write(object str)
        {
            Console.WriteLine(str);
        }

        private static bool ChangeMin<T>(ref T a, T b) where T : IComparable
        {
            if (a.CompareTo(b) > 0)
            {
                a = b;
                return true;
            }
            return false;
        }

        private static bool ChangekMax<T>(ref T a, T b) where T : IComparable
        {
            if (b.CompareTo(a) > 0)
            {
                a = b;
                return true;
            }
            return false;
        }
    }
}


public static class Extentions
{
    public static int Int(this object obj)
    {
        return int.Parse(obj.ToString());
    }

    public static long Long(this object obj)
    {
        return long.Parse(obj.ToString());
    }

    public static decimal Decimal(this object obj)
    {
        return decimal.Parse(obj.ToString());
    }

    public static double Double(this object obj)
    {
        return double.Parse(obj.ToString());
    }

    public static T2 GetValueZero<T1, T2>(this Dictionary<T1, T2> d, T1 key) where T2 : struct
    {
        T2 value;
        if (d.TryGetValue(key, out value))
        {
            return value;
        }
        return new T2();
    }
}



Measured memory_bytes: 21704
#!/usr/bin/python3
# -*- coding: utf-8 -*-

import sys

n, quantum = map(int, sys.stdin.readline().split())

proc_q = list()
for i in range(n):
    p_name, length = sys.stdin.readline().split()
    proc_q.append([p_name, int(length)])

elapse = 0
while proc_q:
    process = proc_q.pop(0)  # retrieve 1st element
    p_time = min(quantum, process[1])
    elapse += p_time
    if p_time == process[1]:
        print(process[0], elapse)
    else:
        proc_q.append([process[0], process[1]-quantum])



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

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

    int l;
    l=s.size();
    rep(i,l){
        s[i]=s[i]+n;
        if (s[i]>90){
            s[i]-=26;
        }
    } 

    
    cout << s << endl;
    

    return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
int main()
{
    int A,B;
    scanf("%d",&A);
    scanf("%d",&B);
    if(A==1&&B==2){
        printf("3\n");
    }
    else if(A==2&&B==1){
        printf("3\n");
    }
    else if(A==1&&B==3){
        printf("2\n");
    }
    else if(A==3&&B==1){
       printf("2\n");
    }
    else if(A==3&&B==2){
        printf("1\n");
    }
    else if(A==2&&B==3){
       printf("1\n");
    }
    return 0;
}


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

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

  int i = 0;
  int A = 0;
  while (i < N) {
    int l, r;
    cin >> l >> r;
    A = A + r - l + 1;
    i++;
  }
  cout << A << endl;
}

Measured memory_bytes: 256
#include<stdio.h>
#define N 100000

int abs(int a);

int main(void){
	int i;
	int h[N];
	int min[N]={0};
	int n;
	scanf("%d",&n);
	for(i=0;i<n;i++){
		scanf("%d",&h[i]);
	}
	min[0]=0;
	min[1]=abs(h[1]-h[0]);
	for(i=2;i<n;i++){
		/*最小コストをminに格納*/
		if((min[i-2] + abs(h[i-2] - h[i])) < (min[i-1] + abs(h[i-1] - h[i]))){
			min[i]=min[i-2]+abs(h[i-2]-h[i]);
		}else{
			min[i]=min[i-1]+abs(h[i-1]-h[i]);
		}
	}
	printf("%d",min[n-1]);
	return 0;
}

int abs(int a){
	int ret;
	if(a<0){
		ret=(-1)*a;
	}else{
		ret=a;
	}
	return ret;
}

Measured memory_bytes: 896
#include<bits/stdc++.h> 
using namespace std;
#define ll long long
#define mod 1000000007ll
#define vll vector<ll>
#define pll pair<ll,ll>
#define vpll vector<pll>
#define pb push_back
#define mp make_pair
#define x first
#define y second
#define db(x) cout << #x << " = " << x << '\n'
#define sep cout << "\n********************************************\n"
#define fast  ios_base::sync_with_stdio(false), cin.tie(NULL)
ll countpf(ll num)
{
	ll ans = 0;
	for (ll i = 2; i * i <= num; ++i)
	{
		if (num % i == 0)
		{
			ans ++;
			while (num % i == 0)
				num /= i;
		}
	}
	if (num > 1)
		ans ++;
	return ans + 1;
}
int main(int argc, char const *argv[])
{
    fast;
    ll a, b;
    cin >> a >> b;
    cout << countpf(__gcd(a, b)) << '\n';
    return 0;
}

Measured memory_bytes: 3560
N = gets.chomp.to_i
h = Array.new(N)
str = gets.split
for i in 0...N do
    h[i] = str[i].to_i
end

a = 0
max = 0

for i in 0...N-1 do
    if h[i] >= h[i+1]
        a += 1
    else
        if max < a
            max = a
        end
        a = 0
    end
end

if max < a
    max = a
end

puts max

Measured memory_bytes: 8580
#include <iostream>
#include <string>

int main()
{
  std::string s;
  std::cin >> s;
  const size_t n = s.length();

  size_t cnt = 0;
  for (size_t i = 0; i < n / 2; i++)
  {
    if (s[i] != s[n-1-i])
    {
      cnt++;
    }
  }
  
  std::cout << cnt << std::endl;

  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> PII;
const int mod=1e4+7;
const int inf=0x3f3f3f3f;
const double eps=1e-8;
//ll powmod(ll a,ll b) {ll res=1;a%=mod; assert(b>=0); for(;b;b>>=1){if(b&1)res=res*a%mod;a=a*a%mod;}return res;}

int main(){
    int a,s=0,mx=0;
    for(int i=0;i<3;i++){
        cin>>a;
        s+=a;
        mx=max(mx,a);
    }
    if(s-mx==mx) puts("Yes");
    else puts("No");
    return 0;
}


Measured memory_bytes: 256
#include<cstdio>

using namespace std;

int W,D,hw[15],hd[15];
int main()
{
	while(scanf("%d%d",&W,&D)==2)
	{
		if(W==0 && D==0) break;

		int ans=0;
		for(int i=1;i<=W;i++) scanf("%d",&hw[i]);
		for(int i=1;i<=D;i++) {scanf("%d",&hd[i]);ans+=hd[i];}

		for(int i=1;i<=W;i++)
		{
			bool flag=0;
			for(int j=1;j<=D;j++)
				if(hw[i]==hd[j]) {hd[j]=-1;flag=1;break;}
			if(!flag) ans+=hw[i];
		}
		printf("%d\n",ans);
	}
	return 0;
}

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

main() {
  int ans = 100;
  string s; cin >> s;
  rep(i, 26) {
    vi pos;
    pos.push_back(-1);
    rep(j, s.length()) {
      if (s[j] == 'a' + i) pos.push_back(j);
    }
    pos.push_back(s.length());
    vi interval;
    rep(j, pos.size() - 1) interval.push_back(pos[j + 1] - pos[j] - 1);
    int lmax = 0;
    rep(j, interval.size()) lmax = max(lmax, interval[j]);
    ans = min(ans, lmax);
  }

  cout << ans << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int maxn=1e3+7;
const int mod=1e9+7;
char a[10];
int main()
{
  scanf("%s",a+1);
  if(a[3]==a[4]&&a[5]==a[6])
  printf("Yes");
  else
  printf("No"); 
 } 

Measured memory_bytes: 256
#dt = {} for i in x: dt[i] = dt.get(i,0)+1
import sys;input = sys.stdin.readline
inp,ip = lambda :int(input()),lambda :[int(w) for w in input().split()]

import sys
sys.setrecursionlimit(10**6)

def dfs(u):
    global grpah,vis,dp
    vis[u] = 1
    for i in graph[u]:
        if not vis[i]:
            dfs(i)
        dp[u] = max(dp[u],dp[i] + 1)

n,m = ip()
graph = [[] for i in range(n+1)]
for i in range(m):
    a,b = ip()
    graph[a].append(b)

dp = [0]*(n+1)
vis = [0]*(n+1)
for i in range(1,n+1):
    if not vis[i]:
        dfs(i)
#print(dp)
print(max(dp))

Measured memory_bytes: 150480
import java.util.*;

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

        int N = sc.nextInt();
        int A = sc.nextInt();
        int[] x = new int[N];
        for (int i = 0; i < N; i++) {
            x[i] = sc.nextInt();
        }

        long[][] dp = new long[N][A*N+1];
        for (int i = 0; i < N; i++) {
            for (int j = i; j >= 1; j--) {
                for (int k = 0; k <= A*N; k++) {
                    if (dp[j-1][k] > 0 && k+x[i] <= A*N) {
                        dp[j][k + x[i]] += dp[j-1][k];
                    }
                }
            }
            if (x[i] <= A*N) dp[0][x[i]] += (long)1;
        }

        long ans = 0;
        for (int i = 0; i < N; i++) {
            ans += (long)dp[i][A*(i+1)];
        }

        System.out.println(ans);
    }
}


Measured memory_bytes: 23636
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <iostream>
#include <vector>
#include <cstring>

using namespace std;

const int N = 2222;
const int MOD = 1e9 + 7;

int n, m, k;
int f[N][N], vis[N][N];

int dfs(int n, int m) {
	if (n + m == 1) return f[n][m] = 1;
	if (n + m == k) {
		if (n == k || m == k) return f[n][m] = 0;
		return f[n][m] = 1;
	}
	if (vis[n][m] != -1) return f[n][m];
	vis[n][m] = 1;
	int &ret = f[n][m];
	ret = 0;
	for (int i = 0; i < k; i++) {
		if (n >= i && m >= k - i - 1) {
			ret += dfs(n - i, m - (k - i - 1));
			ret %= MOD;
		}
	}
	return ret;
}

int main() {
	scanf("%d %d %d", &n, &m, &k);
	memset(vis, -1, sizeof(vis));
	int ans = 0;
	for (int i = n; i > 0; i -= k - 1) {
		for (int j = m; j > 0; j -= k - 1) {
			ans += dfs(i, j);
			//cout << "i = " << i << " j = " << j << " " << f[i][j] << " " << ans << endl;
			ans %= MOD;
		}
	}
	printf("%d\n", ans);
	return 0;
}


Measured memory_bytes: 37120
#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()

vector<vector<int>> cnt(26);

int main(){
    string s,t;
    cin>>s>>t;
    ll n=s.size();
    ll m=t.size();

    rep(i,n){
        cnt[s[i]-'a'].push_back(i);
    }

    rep(i,m){
        if(cnt[t[i]-'a'].size()==0){
            cout<<-1<<endl;
            return 0;
        }
    }

    ll q=0;
    int pre=-1;
    rep(i,m){
        int id=upper_bound(all(cnt[t[i]-'a']),pre)-cnt[t[i]-'a'].begin();
        if(id==cnt[t[i]-'a'].size()){
            q++;
            pre=cnt[t[i]-'a'][0];
        }
        else{
            pre=cnt[t[i]-'a'][id];
        }
        //cout<<id<<" "<<pre<<endl;
    }

    //cout<<q<<" "<<pre<<endl;
    ll ans=q*n+pre+1;
    cout<<ans<<endl;
}

Measured memory_bytes: 4252
for _ in range(int(input())):
    x1, y1, r1, x2, y2, r2 = [float(x) for x in input().split()]
    distance = ((x1 - x2)**2 + (y1 - y2)**2)**0.5
    if distance > r1 + r2:
        print(0)
    else:
        if r1 > r2 and distance + r2 < r1:
            print(2)
        elif r1 < r2 and distance + r1 < r2:
            print(-2)
        else:
            print(1)



Measured memory_bytes: 5652
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main {
	public static void main(String[] args) throws NumberFormatException,
			IOException {
		BufferedReader reader = new BufferedReader(new InputStreamReader(
				System.in));
		StringBuilder builder = new StringBuilder();
		while (true) {
			int a = Integer.parseInt(reader.readLine());
			if (a == 0)
				break;
			int[] primes = new int[a * 100];
			for (int i = 2; i < a * 100; i++) {
				if (primes[i] == 1) {
					continue;
				}
				for (int j = i * 2; j < a * 100; j += i) {
					primes[j] = 1;
				}
			}
			int count = 0;
			long sum = 0;
			for (int i = 2; i < a * 100; i++) {
				if (primes[i] == 0) {
					sum += i;
					count++;
					if (count == a) {
						break;
					}
				}
			}
			System.out.println(sum);
		}

	}
}

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

int main() {
    int N, P; cin >> N >> P;
    string s; cin >> s;
    vector<int> S(N); for (int i = 0; i < N; i++) S[i] = s[i]-'0';

    if (P == 2 || P == 5) {
        ll ans = 0;
        for (int i = 0; i < N; i++) {
            if (S[i] % P == 0) {
                ans += i + 1;
            }
        }
        cout << ans << endl;
        return 0;
    } else {
        vector<ll> comb(P, 0);
        comb[0] = 1;
        int t = 1, r = 0;
        for (int i = N-1; 0 <= i; i--) {
            r = (t * S[i] + r) % P;
            t = (t * 10) % P;
            comb[r]++;
        }
        ll ans = 0;
        for (int i = 0; i < P; i++) {
            ans += (comb[i] * (comb[i]-1)) / 2;
        }
        cout << ans << endl;
        return 0;
    }
}


Measured memory_bytes: 1412
#include <iostream>
#include <cmath>

using namespace std;

int main() {
    int n, t, a, h;

    cin >> n >> t >> a;

    double best = 1e+9, best_num = -1;
    for (int i=0; i<n; i++) {
        cin >> h;
        if (best > abs(a - (t - h * 0.006))) {
            best = abs(a - (t - h * 0.006));
            best_num = i+1;
        }
    }

    cout << best_num << endl;

    return 0;
}

Measured memory_bytes: 256
n=int(input())
box=[0]+list(map(int,input().split()))+[0]
count=0
for i in range(n+1):count +=abs(box[i]-box[i+1])
for j in range(1,n+1):
    print(count-(abs(box[j-1]-box[j])+abs(box[j]-box[j+1]))+abs(box[j-1]-box[j+1]))

Measured memory_bytes: 64876
import collections

n = int(input())
a = list(map(int, input().split()))
counter = collections.Counter(a)
max_count = 0
for i in range(0, max(a) + 1):
    max_count = max(max_count, counter[i - 1] + counter[i] + counter[i + 1])
print(max_count)


Measured memory_bytes: 14564
#include <iostream>
#include <set>
#include <map>
#include <string>
#include <math.h>
#include <algorithm>
#include <vector>
#include <stack>
#include <queue>
#include <bitset>
#include <string.h>

using namespace std;

// #define for(i,a,b) for (int i=(a);i<(b);++i)
typedef long long ll;
typedef pair<ll,ll> P;
#define REP(i,n) for(long long i = 0; i < (long long)(n); i++)
#define pb push_back // vectorに要素追加
#define INF (ll)1e18

int main() {
	// 入力
	double W,H,x,y;cin>>W>>H>>x>>y;

    // 解法
    double ans = W*H/2;
    ll ans2 = 0;
    if (W==x*2 & H==y*2) ans2 = 1;

    // 出力
    cout<<ans<<" "<<ans2<<endl;
    
}


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

using namespace std;

typedef long long ll;

signed main()
{
    ll n;
    cin >> n;
    vector<ll> a(n);
    for(auto& x : a)
        cin >> x;

    set<ll> s;
    vector<pair<ll,ll>> p;
    for(ll i = 0; i < n; ++i)
        p.emplace_back(a[i], i);
    sort(p.begin(), p.end());

    s.insert(-1);
    s.insert(n);

    ll ans = 0;

    for(ll i = 0; i < n; ++i){
        ll ind = p[i].second;
        auto nex = s.lower_bound(ind);
        auto pre = prev(nex);

        ll dist1 = ind - *pre;
        ll dist2 = *nex - ind;

        s.insert(p[i].second);

        ans += p[i].first * dist1 * dist2;
    }
    cout << ans << endl;
}


Measured memory_bytes: 15212
#include <cstdio>
#include <cassert>
#include <algorithm>
#include <functional>
#include <iostream>
#include <vector>
using namespace std;

typedef long long ll;

// vector
template<typename T> ostream& operator<<(ostream& s, const vector<T>& v) {
  int len = v.size();
  for (int i = 0; i < len; ++i) {
    s << v[i]; if (i < len - 1) s << "\t";
  }
  return s;
}

int lx[200010];
vector<int> edges[200010];
bool visit[200010];
int ans[200010];

void dfs(int s, int x) {
  visit[s] = true;
  ans[s] = x + lx[s];
  for (int t : edges[s]) {
    if (visit[t]) continue;
    dfs(t, x + lx[s]);
  }
}

int main() {
  int n, q;
  cin >> n >> q;
  vector<ll> lv(n);
  for (int i = 0; i < n-1; ++i) {
    int a, b;
    cin >> a >> b;
    --a; --b;
    edges[a].push_back(b);
    edges[b].push_back(a);
  }
  for (int i = 0; i < q; ++i) {
    int p, x;
    cin >> p >> x;
    --p;
    lx[p] += x;
  }
  dfs(0, 0);
  for (int i = 0; i < n; ++i) {
    cout << ans[i] << " ";
  }
  cout << endl;
}



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

int main(){
    int n, a[200005], first = 0, second = 0;
    cin >> n;
    rep(i,n){
        cin >> a[i];
        if(a[i] > first){
            second = first;
            first = a[i];
        }else if(a[i] > second){
            second = a[i];
        }
    }
    rep(i,n){
        if(a[i] == first) cout << second << endl;
        else cout << first << endl;
    }
}

Measured memory_bytes: 2432
#include <iostream>
#include <algorithm>
#include <bitset>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <cstring>
#include <utility>
#include <vector>
#include <complex>
#include <valarray>
#include <fstream>
#include <cassert>
#include <cmath>
#include <functional>
#include <iomanip>
#include <numeric>
#include <climits>
#include <random>

#define _overload(a, b, c, d, ...) d
#define _rep1(X, A, Y) for (int (X) = (A);(X) <= (Y);++(X))
#define _rep2(X, Y) for (int (X) = 0;(X) < (Y);++(X))
#define rep(...) _overload(__VA_ARGS__, _rep1, _rep2)(__VA_ARGS__)
#define rrep(X,Y) for (int (X) = Y-1;(X) >= 0;--(X))
#define all(X) (X).begin(),(X).end()
#define len(X) ((int)(X).size())
#define mod(n, m) (((n)%(m)+(m))%m)
#define fi first
#define sc second
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> Pii;
typedef pair<ll,ll> Pll;
const int INFINT = 1 << 30;                          // 1.07x10^ 9
const ll INFLL = 1LL << 60;                          // 1.15x10^18
const double EPS = 1e-10;
const int MOD = 1000000007;
const int dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};

const int MAX_H = 200000, MAX_W = 200000, MAX_N = 200000;
int H, W, N;
int Sx, Sy;
string S, T;


int main() {
  std::ios::sync_with_stdio(false);std::cin.tie(0);
  
  cin >> H >> W >> N;
  cin >> Sx >> Sy;
  cin >> S >> T;
  
  int lb = 0, ub = W+1;
  for (int i = N-1; i >= 0; --i) {
      if (T[i] == 'R' && lb != 0) --lb;
      if (T[i] == 'L' && ub != W+1) ++ub;
      if (S[i] == 'L') ++lb;
      if (S[i] == 'R') --ub;
      if ((ub-lb) == 1) {
          cout << "NO" << endl;
          return 0;
      }
  }

  if (Sy <= lb || Sy >= ub) {
      cout << "NO" << endl;
      return 0;
  }

  lb = 0, ub = H+1;
  for (int i = N-1; i >= 0; --i) {
      if (T[i] == 'D' && lb != 0) --lb;
      if (T[i] == 'U' && ub != H+1) ++ub;
      if (S[i] == 'U') ++lb;
      if (S[i] == 'D') --ub;
      if ((ub-lb) == 1) {
          cout << "NO" << endl;
          return 0;
      }
  }

  if (Sx <= lb || Sx >= ub) {
      cout << "NO" << endl;
      return 0;
  }


  cout << "YES" << endl;

  return 0;
}



Measured memory_bytes: 1020
/**
*   @Author : MeGA
*   @InitTime :01/24/20 13:35:09
*   @Idea : 
*
*
*
*
*
*
*
**/
#include <bits/stdc++.h>
using namespace std;  
int sz[26];
vector<int>pos[26];
int main(){
#ifndef ONLINE_JUDGE
  // freopen("in","r",stdin);
  // freopen("out","w",stdout);
#endif
     string str;
     cin>>str;
          
     for(int i=0;i<str.size();i++){
        pos[str[i]-'a'].push_back(i+1);
     }

     string t;
     cin>>t;
     long long ans=0;
     int prev=-1;
     for(char c:t){
        if(pos[c-'a'].size()==0){
           printf("-1");
           return 0;
        }else{
           int cur_idx=upper_bound(pos[c-'a'].begin(),pos[c-'a'].end(),prev)-pos[c-'a'].begin();
           if(cur_idx==pos[c-'a'].size()){
             cur_idx=pos[c-'a'][0];
           }else{
              cur_idx=pos[c-'a'][cur_idx];
           }
           if(prev==-1)prev=0;
        //   cerr<<cur_idx<<endl;
           if(cur_idx <= prev){
     //     cerr<<str.size()<<" "<<prev<<" ho"<<endl;
              ans+=str.size()-prev+cur_idx;
           }else{
       //    cerr<<cur_idx<<" "<<prev<<" hoi"<<endl;
             ans+=(cur_idx-prev);
           }
           prev=cur_idx;
         }
     }

     printf("%lld",ans);


}

Measured memory_bytes: 1152
package main
import (
	"fmt"
)
func main(){
	var n, m, i, x int
	var y string
	fmt.Scan(&n, &m)
	ac:=0
	wa:=0
	if m==0{
		fmt.Println(ac, wa)
		return
	}
	ans:=make([]int, 100001)
	wrong:=[100001]int{}

	for i=0;i<m;i++{
		fmt.Scan(&x, &y)
		if y=="AC"{
			ans[x]=1
		}else if y=="WA"&&ans[x]==0{
			wrong[x]++
		}
	}
	for i=1;i<=n;i++{
		if ans[i]==1{
			ac++
			wa+=wrong[i]
		}
	}
	fmt.Println(ac, wa)
}


Measured memory_bytes: 6272
#include<bits/stdc++.h>
using namespace std;
#define ll  long long
#define FASTINOUT ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
const ll mod = 1e9+7;
const int N=2e5+9;
int main()
{
    FASTINOUT;
    set<char>s;
    s.insert('a');
    s.insert('u');
    s.insert('e');
    s.insert('i');
    s.insert('o');
    char z;
    cin>>z;
    if (s.find(z)!=s.end())
        cout<<"vowel\n";
    else
        cout<<"consonant";
    return 0;
}


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

#define int long long
#define str string
#define rep(x,y) for(int i=x;i<y;i++)
#define REP(x,y) for(int j=x;j<y;j++)
#define all(x) x.begin(),x.end()
#define vint vector<int>
#define vchar vector<char>
#define vstr vector<string>
#define pb(n) push_back(n)

signed main(){
  int A,B,N,M,count=0,count2=0,count3=0,stack=0;
  str S,T;
  vstr W(N);

  vector<vchar> a(N,vchar(M));
  cin>>N;
  vint V(N);
  vint C(N);
  rep(0,N)cin>>V.at(i);
  rep(0,N)cin>>C.at(i);
  rep(0,N)if(V.at(i)-C.at(i)>0)count+=V.at(i)-C.at(i);
  cout<<count<<endl;
}


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

using namespace std;

typedef long long int64;
const int64 INF = 1LL << 55;

int N, M, T;
int x[200000], y[200000], z[200000];
vector< pair< int, int > > g[200000];
int64 v[200000];

struct UnionFind
{
  vector< int64 > data, time, score;

  UnionFind(int sz)
  {
    data.assign(sz, -1LL);
    time.assign(sz, T);
    score.resize(sz);
    for(int i = 0; i < sz; i++) {
      if(v[i] == INF) score[i] = -INF;
      else score[i] = 0;
    }
  }

  int64 find(int64 k)
  {
    if(data[k] < 0) return (k);
    return (data[k] = find(data[k]));
  }

  void unite(int64 x, int64 y, int64 z)
  {
    x = find(x), y = find(y);
    if(x == y) return;
    score[x] = max(score[x] + size(x) * (time[x] - z), score[y] + size(y) * (time[y] - z));
    data[x] += data[y];
    data[y] = x;
    time[x] = z;
  }

  int64 size(int64 k)
  {
    return (-data[find(k)]);
  }

  int64 res()
  {
    return (score[find(0)] + size(0) * time[find(0)]);
  }
};

int main()
{
  cin >> N >> M >> T;
  for(int i = 0; i < M; i++) {
    cin >> x[i] >> y[i] >> z[i];
    --x[i], --y[i];
    g[x[i]].emplace_back(y[i], z[i]);
    g[y[i]].emplace_back(x[i], z[i]);
  }

  fill_n(v, 100000, INF);
  queue< int > que;
  que.push(0);
  v[0] = 0;
  while(!que.empty()) {
    int p = que.front();
    que.pop();
    for(auto &e : g[p]) {
      if(v[e.first] != INF || v[p] >= e.second) continue;
      v[e.first] = v[p] + 1;
      que.emplace(e.first);
    }
  }

  vector< int > to(M);
  iota(begin(to), end(to), 0);
  sort(begin(to), end(to), [&](int a, int b)
  {
    return (z[a] > z[b]);
  });
  UnionFind tree(N);
  for(int i : to) tree.unite(x[i], y[i], z[i]);
  cout << tree.res() << endl;
}

Measured memory_bytes: 20132
#include <stdio.h>
int main(void){
  int number,num1,num2,yes;
  scanf("%d",&number);//numberに値を入力
  yes = 0;//yesに０を代入
  for(num1 = 1;num1 <= 9;++num1){//num1を1から9まで1ずつ増やして
    for(num2 = 1;num2 <= 9;++num2){//num2を1から9まで1ずつ増やして
      if(number == num1 * num2 && yes == 0){//numberがnum1とnum2の積となり、かつyes = 0の時
        printf("Yes\n");//Yesを出力
        yes += 1;//yesに1を加える
      }
    }
  }
  if(yes == 0){//yesが0の時
    printf("No\n");//Noを出力
  }
  return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for(ll i = 0, i##_len = (n); i < i##_len; i++)
#define reps(i, s, n) for(ll i = (s), i##_len = (n); i < i##_len; i++)
#define rrep(i, n) for(ll i = (n) - 1; i >= 0; i--)
#define rreps(i, e, n) for(ll i = (n) - 1; i >= (e); i--)
#define all(x) (x).begin(), (x).end()
#define sz(x) ((ll)(x).size())
#define len(x) ((ll)(x).length())

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    // std::ifstream in("input.txt");
    // std::cin.rdbuf(in.rdbuf());
    vector<ll> n(4);
    rep(i, 4) cin >> n[i];
    sort(all(n));
    if ((n[0] == 1) && (n[1] == 4) && (n[2] == 7) && (n[3] == 9)) {
        cout << "YES" << endl;
    }
    else {
        cout << "NO" << endl;
    }
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cmath>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <string>
#include <utility>
#include <algorithm>
#include <functional>
#include <deque>
#define INF 1e9
#define MOD 1000000007
#define MAX_N 100001
#define mod(x) ((x % MOD) + MOD) % MOD
#define MAX_H 51
#define MAX_W 51

using namespace std;

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

int main() {
    int H, W;
    char s[MAX_H][MAX_W];
    
    cin >> H >> W;
    for (int i = 0; i < H; ++i) {
        for (int j = 0; j < W; ++j) {
            cin >> s[i][j];
        }
    }
    
    bool flag = true;
    for (int i = 0; i < H; ++i) {
        for (int j = 0; j < W; ++j) {
            if (s[i][j] == '#' &&
                ((i-1 < 0) || s[max(i-1, 0)][j] == '.') &&
                ((i+1 > H-1) || s[min(i+1, H-1)][j] == '.') &&
                ((j-1 < 0) || s[i][max(j-1, 0)] == '.') &&
                ((j+1 > W-1) || s[i][min(j+1, W-1)] == '.')) {
                flag = false;
            }
        }
    }
    
    if (flag) {
        cout << "Yes\n";
    } else {
        cout << "No\n";
    }
    return 0;
}


Measured memory_bytes: 256
#include <stdio.h>

int main () {

    int i, j, mini, N, k, l, m;
    int A[100];

    m = 0;

    scanf("%d", &N);

    for ( i = 0; i < N; i++ )
        scanf("%d", &A[i]);

    for ( i = 0; i < N; i++ ) {
        mini = 101;
        for ( j = i; j < N; j++ ) {
            if ( A[j] < mini ) {
                mini = A[j];
                k = j;
            }
        }
        if ( mini != A[i] ) {
            l = A[i];
            A[i] = A[k];
            A[k] = l;
            m += 1;
        }
    }

    for ( i = 0; i < N - 1; i++ )
        printf("%d ", A[i]);
        printf("%d", A[N - 1]);
        puts("");
        printf("%d\n", m);

    return 0;

}


Measured memory_bytes: 1968
#include<iostream>
#include<cmath>
using std::cin;
using std::cout;
using std::endl;
using std::string;

int Dice(int n[6],int k[6]){
  int g = 1;
  int sou = 2;
  int east = 3;
  int west = 4;
  int nor = 5;
  int t = 0;
  string str;
  if (k[0] == n[1]){
    str = 'N';
  }else if(k[0] == n[2]){
    str = 'W';
  }else if(k[0] == n[3]){
    str = 'E';
  }else if(k[0] == n[4]){
    str = 'S';
  }else if(k[0] == n[5]){
    str = "NN";
  }else{
    str = 'Y';
  }

  for(int i = 0;i < str.length(); i++){
    if(str[i] == 'E'){
      east = g;
      g = west;
      west = 7-east;
    }else if(str[i] == 'W'){
      west = g;
      g = east;
      east = 7-west;
    }else if(str[i] == 'N'){
      nor = g;
      g = sou;
      sou = 7-nor;
    }else if(str[i] == 'S'){
      sou = g;
      g = nor;
      nor = 7-sou;
    }else{
    }
  }

  for(int i = 0; i < 5;i++){
    int temp = nor;
    nor = east;
    east = sou;
    sou = west;
    west = temp;
    if(n[sou-1] == k[1] && n[nor-1] == k[4] && n[east-1] == k[2] && n[west-1] == k[3]){
      t = 1;
    }
  }
  return t;
}

int main(void){
  int k[6];
  int n[6];
  for(int i = 0;i < 6;i++){
    cin >> n[i];
  }
  for(int i = 0;i < 6;i++){
    cin >> k[i];
  }
  if(Dice(n,k) == 1){
    cout << "Yes" << endl;
  }else{
    cout << "No" << endl;
  }
  int q;
}
      

Measured memory_bytes: 3144
package main

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

var stdInScanner = bufio.NewScanner(os.Stdin)

func nextInt() int {
	stdInScanner.Scan()
	i, _ := strconv.Atoi(stdInScanner.Text())
	return i
}

func main() {
	stdInScanner.Split(bufio.ScanWords)

	N := nextInt()
	D := nextInt()

	var x, y float64
	count := 0
	for i := 0; i < N; i++ {
		x = float64(nextInt())
		y = float64(nextInt())
		if float64(D) >= math.Sqrt(x*x+y*y) {
			count++
		}
	}
	fmt.Println(count)
}


Measured memory_bytes: 4908
# -*- coding: utf-8 -*-
##################################
# University of Wisconsin-Madison
# Author: Yaqi Zhang
##################################

# standard library
import sys
from functools import lru_cache

sys.setrecursionlimit(10**9)

Input = lambda: sys.stdin.readline().rstrip()
IntRead = lambda: int(Input())
LineRead = lambda: list(map(int, Input().split()))

def main():
    N = IntRead()
    INF = 10**18
    nums = LineRead()
    @lru_cache(None)
    def dp(idx, n):
        if idx >= N:
            return -INF
        if N - idx + 2 < 2 * n:
            return -INF
        if n == 0:
            return 0
        elif n == 1:
            return max(nums[idx:])
        return max(nums[idx] + dp(idx + 2, n - 1), dp(idx + 1, n))
    print(dp(0, N // 2))


if __name__ == "__main__":
    main()


Measured memory_bytes: 204316
#include<stdio.h>
#include<string.h>
int main(){
	int n,m,f[1000],i,p;
	while(scanf("%d%d",&n,&m),n){
		for(i=0;i<n;i++)
			f[i]=1+i;
		p=0;
		while(n>1){
			p=(p+m-1)%n;
			memmove(f+p,f+p+1,sizeof(int)*(n-p-1));
			n--;
		}
		printf("%d\n",f[0]);
	}
	return 0;
}

Measured memory_bytes: 0
a = int(input())
b = int(input())
c = int(input())
x = int(input())

ans = []
mon = 0

for fh in range(a+1) :
    for h in range(b+1) :
        for f in range(c+1) :
            mon = f * 50 + h * 100 + fh * 500
            ans.append(mon)
print(ans.count(x))


Measured memory_bytes: 8292
#include <cstdio>

static const size_t H_MAX = 250;
static int A[H_MAX+1];

int main() {
  size_t H;
  scanf("%zu", &H);
  for (size_t i = 1; i <= H; i++)
    scanf("%d\n", A + i);
  for (size_t i = 1; i <= H; i++) {
    printf("node %zu: key = %d, ", i, A[i]);
    if (i > 1)
      printf("parent key = %d, ", A[i/2]);
    if (2 * i <= H)
      printf("left key = %d, ", A[2*i]);
    if (2 * i + 1 <= H)
      printf("right key = %d, ", A[2*i+1]);
    puts("");
  }
  return 0;
}

Measured memory_bytes: 2652
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
#define rep(k,i,n) for(ll i=k;i<n;++i)

int main(void){
    // Your code here!
    ll n,k;
    cin>>n>>k;
    ll c[k];
    rep(0,i,k)c[i]=0;
    rep(0,i,n){
        ++c[(i+1)%k];
    }
    ll ans=0;
    ans+=c[0]*c[0]*c[0];
    ll mid=k/2;
    if(k%2==0)ans+=c[mid]*c[mid]*c[mid];
    cout<<ans<<endl;
}


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

int main(){
  int n;
  cin>>n;
  vector<int> a(n);
  for(auto &v:a) cin>>v;

  int ma=0;
  int mi=1e6;
  for(int i=0;i<n;i++){
    ma=max(a[i],ma);
    mi=min(a[i],mi);
  }

  if(ma==mi){
    if(ma<=n/2){
      cout<<"Yes"<<endl;
      return 0;
    }
    if(ma==n-1){
      cout<<"Yes"<<endl;
      return 0;
    }
    cout<<"No"<<endl;
    return 0;
  }
  else if(ma==mi+1){
    int cnt=0;
    for(int i=0;i<n;i++){
      if(a[i]==mi) cnt++;
    }
    if(n-cnt==1){
      cout<<"No"<<endl;
      return 0;
    }
    if(cnt+1<=ma && ma<=cnt+(n-cnt)/2) cout<<"Yes"<<endl;
    else cout<<"No"<<endl;
  }
  else{
    cout<<"No"<<endl;
  }
  return 0;
}


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

#define INF 1.1e9
#define LINF 1.1e18
#define FOR(i,a,b) for (int i = (a); i < (b); ++i)
#define REP(i,n) FOR(i,0,n)
#define ALL(v) (v).begin(), (v).end()
#define pb push_back
#define pf push_front
#define fi first
#define se second

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

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

int n;
ll z,w,a[2000];

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

	cin>>n>>z>>w;
	REP(i,n) cin>>a[i];
	ll ans=abs(w-a[n-1]);
	if(n!=1) ans=max(ans,abs(a[n-1]-a[n-2]));
	cout<<ans<<endl;

	return 0;
}


Measured memory_bytes: 256
#include<stdio.h>

void swap(int *a,int *b){
	int hold;
	hold=*a;
	*a=*b;
	*b=hold;
}

int main(){
	int a,b,c,i;
	scanf("%d %d %d",&a,&b,&c);
	for(i=0;i<2;i++){
		if(a>b) swap(&a,&b);
		if(b>c) swap(&b,&c);
	}
	if((a+b)==c) printf("Yes\n");
	else printf("No\n");
	return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
  
using namespace std;
  
#define rep(i,n) REP(i,0,n)
#define REP(i,s,e) for(int i=(s); i<(int)(e); i++)
#define repr(i, n) REPR(i, n, 0)
#define REPR(i, s, e) for(int i=(int)(s-1); i>=(int)(e); i--)
#define pb push_back
#define all(r) r.begin(),r.end()
#define rall(r) r.rbegin(),r.rend()
#define fi first
#define se second
  
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
 
const int INF = 1e9;
const ll MOD = 1e9 + 7;
double EPS = 1e-8;

int main(){
    string s;
    cin >> s;
    s[3] = '8';
    cout << s<< endl;
    return 0;
}

Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
#define rep(i,a,n) for(int i=a;i<n;i++)
#define ALL(s) s.begin(),s.end()
const int M=100010;
using ll=long long;

int main(){
	string s;
	bool f=true;
	cin>>s;
	int x=s.size();
	reverse(ALL(s));
	s+="345678";
	for(int i=0;i<x;){
		string t="";
		rep(j,i,i+7)t+=s[j];
		if(t=="remaerd"){
			i+=7;
			continue;
		}
		t="";
		rep(j,i,i+6)t+=s[j];
		if(t=="resare"){
			i+=6;
			continue;
		}
		t="";
		rep(j,i,i+5)t+=s[j];
		if(t=="maerd"||t=="esare"){
			i+=5;
			continue;
		}
		cout<<"NO"<<endl;
		return 0;
	}
	cout<<"YES"<<endl;
	return 0;
}

Measured memory_bytes: 512
#include<bits/stdc++.h>
using namespace std;
int x,y,z;
int k;
long long a[1005],b[1005],c[1005];
long long sum[1005*1005];
long long ans[3005*1005];
long long cnt;

bool cmp (long long x , long long y)
{
	return x > y;
}

int main()
{
	scanf("%d%d%d%d",&x,&y,&z,&k);
	for(int i=1;i<=x;++i)
	    scanf("%lld",&a[i]);
	for(int i=1;i<=y;++i)
	    scanf("%lld",&b[i]);
	for(int i=1;i<=x;++i)
		for(int j=1;j<=y;++j)
		   sum[++cnt]=a[i]+b[j];
	for(int i=1;i<=z;++i)
	    scanf("%lld",&c[i]);
	sort(sum+1,sum+1+cnt,cmp);
	long long now=0;
	for(int i=1;i<=k;++i)
	{
		for(int j=1;j<=z;++j)
		    ans[++now]=sum[i] + c[j];
	}
	sort(ans+1,ans+1+now,cmp);
	for(int i=1;i<=k;++i)
	   printf("%lld\n",ans[i]);
	return 0;
}

Measured memory_bytes: 35076
#include <bits/stdc++.h>
using namespace std;
int main () {
  long A, B, N;
  cin >> A >> B >> N;
  long ans = (A * min(B - 1, N) / B) - A * (min(B - 1, N) / B);
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 3632
#include<iostream>
#include<vector>
using namespace std;
int main() {
	int s;
	cin >> s;
	vector<int>a(1,s);
	int cnt = 1;
	bool judge = true;
	while (judge) {
		if (s % 2 == 0) {
			s = s / 2;
			++cnt;
		}
		else if (s % 2 == 1) {
			s = 3 * s + 1;
			++cnt;
		}
		for (int i : a) {
			if (s == i) {
				judge = false;
			}
		}
		a.push_back(s);
	}
	cout << cnt << endl;


	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(void){
    int n,b=0;
    long ans=0;
    cin >> n;
    vector<long> a(n);
    for (int i=0;i<n;i++){
        cin >> a.at(i);
        if (a.at(i)<0) {
            b++;
            a.at(i)=a.at(i)*(-1);
        }
        ans=ans+a.at(i);
    }
    sort(a.begin(), a.end());
    if (b%2==0) cout << ans << endl;
    else cout << ans-2*a.at(0) << endl;
}


Measured memory_bytes: 1024
#include <iostream>
#include<cmath>
#include<vector>
#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()
typedef long long ll;

using namespace std;



int main() {
    double n;
    cin>>n;
    vector<int>f(n+1);
    rrep(i,n){
        rrep(x,sqrt(i/6)){
            for(int z = x; z <= sqrt(i-2)-1; z++){
                for(int y =x; y <=z; y++){
                    int res = x*x+y*y+z*z+x*y+y*z+z*x;
                    if(res == i){
                        f[i]++;
                        if(x==y&&y==z&&z==x) break;
                        else if(x==y || y==z) f[i]+=2;
                        else f[i]+=5;
                    }
                }
            }
        }
    }
    rrep(i,n){
        cout<<f[i]<<endl;
    }

    return 0;
}

Measured memory_bytes: 3660
import sys
sys.setrecursionlimit(4100000)
import math
import itertools
INF = float('inf')
from heapq import heapify, heappop, heappush

def main():
    S = input()

    ans = 0
    for i in range(len(S)):
        S_tmp = S[:-i-1]
        if len(S_tmp)%2 != 0:
            continue
        ci = len(S_tmp)//2
        if S_tmp[:ci] == S_tmp[ci:]:
            ans = max(ans, len(S_tmp))
    print(ans)


if __name__ == '__main__':
    main()


Measured memory_bytes: 62404
// Vicfred
// https://atcoder.jp/contests/abc129/tasks/abc129_c
// dynamic programming
import std.algorithm;
import std.array;
import std.conv;
import std.stdio;
import std.string;

void main() {
    const long mod = 10^^9 + 7;
    long n, m;
    readf("%s %s\n", &n, &m);

    long[] as = new long[m+1];
    long[] a = new long[n+1];

    foreach(i; 1..m+1) {
        readf("%s\n", &as[i]);
        a[as[i]] = 1;
    }


    long[] dp = new long[n+1];
    dp[0] = 1;
    if(a[1] == 0)
        dp[1] = 1;

    for(int i = 2; i <= n; i++) {
        if(a[i - 1] == 0)
            dp[i] += dp[i - 1];
        dp[i] %= mod;
        if(a[i - 2] == 0)
            dp[i] += dp[i - 2];
        dp[i] %= mod;
    }

    dp[n].writeln;
}



Measured memory_bytes: 5004
object Main extends App {
    var get = readLine
    var i = 0
    var j = 0
    var max = 0
    var sum = 0
    var loop = 0
  
  for(i <- 0 to get.size - 1) {
    	j=i
      while(loop==0){
        if(get.charAt(j)=='A')
          sum+=1
    	else if(get.charAt(j)=='C')
          sum+=1
    	else if(get.charAt(j)=='G')
          sum+=1
    	else if(get.charAt(j)=='T')
          sum+=1
        else
    		loop=1
        j +=1
        if(j>get.size-1 || max > get.size -1)
        loop=1
      }
        max = math.max(sum,max)
        sum = 0
        loop = 0
  }
  println(max)
}

Measured memory_bytes: 25416
#include <stdio.h>
main()
{
    long long int ans=1;
    long long int input;
    scanf("%lld",&input);
    while (1)
    {
        if ((ans*(ans+1)/2)<input)
        {
            ans++;
        }
        else
        {
            break;
        }
    }
    printf("%lld",ans);
}


Measured memory_bytes: 128
#include <iostream>
#include <vector>
using namespace std;
using Int = long long int;
using UInt = unsigned long long int;
using VI = vector<Int>;
using VVI = vector<vector<Int> >;

// 隣接リスト
class DepthFirstSearch {
    public:
    // 探索のデフォルト始点
    const static UInt DEFAULT_START_NODE_NUMBER = 0;
    // 入力: 隣接リスト
    // 出力: ハミルトンパスの個数
    static UInt HamiltonianPathNumber(VVI& adjacency_list) {
        VI dst_table(adjacency_list.size(), 0); // ノードを探索したかどうかをチェックするテーブル
        return InnerHamiltonianPathNumber(adjacency_list, dst_table, DEFAULT_START_NODE_NUMBER);
    }
    private:
    static UInt InnerHamiltonianPathNumber(VVI& adjacency_list, VI dst_table, UInt node_number) {
        // dst_tableを値渡しにする事で，再起する前の頂点の到達状況を保持することができる．
        // これにより，再起による到達の影響を受けない．
        UInt ret = 0;
        dst_table[node_number] = 1;
        bool all_filled = true;
        for (UInt i = 0; i < adjacency_list.size(); ++i) {
            if (dst_table[i] == 0) {
                all_filled = false;
            }
        }
        if (all_filled == true) {
            ret += 1;
        }
        for (UInt i = 0; i < adjacency_list[node_number].size(); ++i) {
            if (dst_table[adjacency_list[node_number][i]] == 0) {
                ret += InnerHamiltonianPathNumber(adjacency_list, dst_table, adjacency_list[node_number][i]);
            }
        }
        return ret;
    }
};

int main(void) {
    Int n, m;
    cin >> n >> m;
    VVI v(n);
    Int s, t;
    for (Int i = 0; i < m; ++i) {
        cin >> s >> t;
        --s;--t;
        v[s].push_back(t);
        v[t].push_back(s);
    }
    cout << DepthFirstSearch::HamiltonianPathNumber(v) << endl;
    return 0;
}


Measured memory_bytes: 3564