akhauriyash/Code-Regression huggingface dataset:
#include<stdio.h>
#include<stdlib.h>
int main(void){

  int a[6],i,j,sign=0;
  for(i=0;i<6;i++){
    scanf("%d",&a[i]);
  }
  for(i=0;i<4;i++){
    for(j=i+1;j<5;j++){
      if(abs(a[i]-a[j])>a[5])sign = 1;
    }
  }
  if(sign == 1)printf(":(");
  else printf("Yay!");

  return 0;
}

Measured memory_bytes: 128
import java.util.*;
  
public class Main {
    Scanner sc = new Scanner(System.in);
  
    public static void main(String[] args) {
        new Main(); 
    }
  
    public Main() {
        new aoj2583().doIt();
    }
    class aoj2583{
    	char map[][] = new char[70][70];
    	String dp[][] = new String[70][70];
    	void clear(int W,int H){
    		for(int i = 0;i < H;i++){
    			for(int j = 0;j < W;j++){
    				dp[i][j] = "";
    			}
    		}
    	}
    	void set(int W,int H){
    		for(int i = 0;i < H;i++){
    			String str = sc.next();
    			char ctr[] = str.toCharArray();
    			for(int j = 0;j < W;j++){
    				map[i][j] = ctr[j];
    			}
    		}
    	}
    	String dp_table(int W,int H){
    		String max = "0";
    		for(int i = 0;i < H;i++){
    			for(int j = 0;j < W;j++){
    				if(i == 0 && j == 0 && (int)map[i][j] <= 57)dp[i][j] = ""+map[i][j];
    				else if(i == 0 && (int)map[i][j] <= 57){
    					dp[i][j] = dp[i][j-1] + map[i][j];
    				}
    				else if(j == 0 && (int)map[i][j] <= 57){
    					dp[i][j] = dp[i-1][j] + map[i][j];
    				}
    				else if((int)map[i][j] <= 57){
    					dp[i][j] = dp[i][j-1] + map[i][j];
    					String str = dp[i-1][j] + map[i][j];
    					String str2 = dp[i-1][j-1] + map[i][j];
    					if(dp[i][j].length() < str.length())dp[i][j] = str;
    					if(dp[i][j].length() < str.length())dp[i][j] = str2;
    					if(dp[i][j].length() == str.length()){
    						if(dp[i][j].compareTo(str) < 0)dp[i][j] = str;
    					}
    					if(dp[i][j].length() == str2.length()){
    						if(dp[i][j].compareTo(str2) < 0)dp[i][j] = str2;
    					}
    				}
    				dp[i][j] = dp[i][j].replaceAll("^0*","");
    				if(max.length() < dp[i][j].length())max = dp[i][j];
    				else if(max.length() == dp[i][j].length()){
    					if(max.compareTo(dp[i][j]) < 0)max = dp[i][j];
    				}
    			}
    		}
    		return max;
    	}
    	void doIt(){
    		while(true){
    			int W = sc.nextInt();
    			int H = sc.nextInt();
    			if(W + H == 0)break;
    			clear(W,H);
    			set(W,H);
    			System.out.println(dp_table(W,H));
//    			for(int i = 0;i < H;i++){
//    				for(int j = 0;j < W;j++){
//    					System.out.print(dp[i][j]+" :");
//    				}
//    				System.out.println();
//    			}
    		}
    	}
    }
}

Measured memory_bytes: 91548
N, D = map(int, input().split())
X = []
for _ in range(N):
    X.append(list(map(int, input().split())))

ans = 0

for i, x in enumerate(X):
    for y in X[i+1:]:
        d = 0
        for i in range(D):
            d += (x[i] - y[i]) ** 2
        
        j = 0
        while True:
            if j ** 2 == d:
                ans += 1
                break
            elif j ** 2 > d:
                break
            j += 1
print(ans)

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

int main() {
  string s;
  cin>>s;
  int len = s.length();
  int count = 0;

  for(int i=0; i<(len/2);i++) {
    if (s[i] != s[len-(i+1)]) {
      count++;
    }
  }

  cout<<count;
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <vector>
#include <map>
#include <queue>
#include <string>
#include <set>
#include <algorithm>
#include <utility>
#include <cstring>
#include <cmath>
#include <cassert>
using namespace std;
#define int64_t long long
constexpr int64_t MOD=1e9+7;
int64_t a,b,c,d;
int64_t gcd(int64_t a,int64_t b){
    if(b>a)swap(a,b);
    if(b==0)return a;
    return gcd(b,a%b);
}
int64_t f(int64_t a){
    return a/c+a/d-a/(c*d/gcd(c,d));
}
int main() {
    cin>>a>>b>>c>>d;
    cout<<(b-a+1-f(b)+f(a-1))<<endl;
    return 0;
}


Measured memory_bytes: 256
import math
a,b,h,m=map(int,input().split())

deg_a = (a*math.cos(2*math.pi*(h*60+m)/720),a*math.sin(2*math.pi*(h*60+m)/720))
deg_b = (b*math.cos(2*math.pi*m/60),b*math.sin(2*math.pi*m/60))
#print(deg_a[0]**2+deg_a[1]**2)
#print(deg_b[0]**2+deg_b[1]**2)
#print((deg_a[0]-deg_b[0])**2)
#print((deg_a[1]-deg_b[1])**2)
print(((deg_a[0]-deg_b[0])**2+(deg_a[1]-deg_b[1])**2)**0.5)

Measured memory_bytes: 9496
nim,mike = map(int, input().split())
ab = [tuple(map(int, input().split())) for _ in range(mike)]
ab.sort()
result = 1
l, r = ab[0][0], ab[0][1]

for a,b in ab[1:]:
    if a < r:
        l = max(l,a)
        r = min(r,b)
    else:
        result += 1
        l = a
        r = b 

print(result)

Measured memory_bytes: 17388
#include<bits/stdc++.h>
#define mp make_pair
#define f first
#define se second
#define pb push_back
#define ms memset
#define MOD 1000000007
#define sp fixed<<setprecision
#define sz sizeof
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(),x.rend()
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
bool pr[1000007];
ll fpow(ll x,ll y){x=x%MOD;ll res=1;while(y){if(y&1)res=res*x;res%=MOD;y=y>>1;x=x*x;x%=MOD;}return res;}
ll inv(ll a,ll m=MOD){ll c=m;ll y=0,x=1;if(m==1)return 0;while(a>1){ll q=a/m;ll t=m;m=a%m,a=t;t=y;y=x-q*y;x=t;}if(x<0)x+=c;return x;}
int main(){
	ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
  string s,t;
  cin>>s>>t;
  ll dp[s.size()+1][t.size()+1];
  memset(dp,0,sizeof(dp));
  for(int i=0;i<=s.size();i++)
  {
    for(int j=0;j<=t.size();j++)
    {
      if(i==0 || j==0)
      dp[i][j]=0;
      else 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]);
    }
  }
  ll x=s.size();
  ll y=t.size();
  string res="";
  while(x && y)
  {
    if(s[x-1] == t[y-1])
    {
    res+=s[x-1];
    x--;
    y--;
    }
    else if(dp[x-1][y]>=dp[x][y-1])
    {
      x--;
    }
    else
     y--;
  }
  reverse(res.begin(),res.end());
  cout<<res;
}


Measured memory_bytes: 70656
from __future__ import division, print_function
# import threading
# threading.stack_size(2**27)
# import sys
# sys.setrecursionlimit(10**7)
# sys.stdin = open('inpy.txt', 'r')
# sys.stdout = open('outpy.txt', 'w')
from sys import stdin, stdout
import bisect            #c++ upperbound
import math
import heapq
i_m=9223372036854775807
def inin():
    return int(input())
def stin():
    return input()
def spin():
    return map(int,stin().split())
def lin():                           #takes array as input
    return list(map(int,stin().split()))
def matrix(n):
    #matrix input
    return [list(map(int,input().split()))for i in range(n)]

################################################
def calculate_sum(a, N): #sum of a to N
    # Number of multiples 
    m = N / a 
    # sum of first m natural numbers 
    sum = m * (m + 1) / 2
    # sum of multiples 
    ans = a * sum
    return ans
def series(N):
    return (N*(N+1))//2

def count2Dmatrix(i,list):
    return sum(c.count(i) for c in list)

def modinv(n,p):
    return pow(n,p-2,p)

def GCD(x, y): 
    x=abs(x)
    y=abs(y)
    if(min(x,y)==0):
        return max(x,y)
    while(y): 
        x, y = y, x % y 
    return x
def LCM (x, y):
    return (x * y) // GCD(x, y)
    
def Divisors(n) : 
    l = []  
    for i in range(1, int(math.sqrt(n) + 1)) :
        if (n % i == 0) : 
            if (n // i == i) : 
                l.append(i) 
            else : 
                l.append(i)
                l.append(n//i)
    return l
def isprime(n):
    for i in range(2, int(math.sqrt(n))+1):
        if n%i==0:
            return False
    return True
prime=[]
def SieveOfEratosthenes(n): 
    global prime
    prime = [True for i in range(n+1)] 
    p = 2
    while (p * p <= n): 
        if (prime[p] == True): 
            for i in range(p * p, n+1, p): 
                prime[i] = False
        p += 1
    f=[]
    for p in range(2, n): 
        if prime[p]: 
            f.append(p)
    return f
q=[]       
def dfs(n,d,v,c):
    global q
    v[n]=1
    x=d[n]
    q.append(n)
    j=c
    for i in x:
        if i not in v:
            f=dfs(i,d,v,c+1)
            j=max(j,f)
            # print(f)
    return j
# d = {}
 
"""*******************************************************"""
s = list(stin())

c = 0; temp = 0
for i in s:
    if i=='R':
        c+=1
    else:
        if c>0:
            temp = c
        c = 0
print(max(temp, c))

Measured memory_bytes: 9292
#include <vector>
#include <cstring>
#include <algorithm>
#include <math.h>
#include <iostream>
#include <queue>
using namespace std;
typedef long long ll;
const int MAXN = 100005;
const int INF = 1e9;
vector<int> G[MAXN];
int n;

vector<int> bfs(int start) {
  vector<int> dist(n, INF);
  vector<bool> visited(n, false);
  queue<int> q;
  q.push(start);
  dist[start] = 0;
  while (!q.empty()) {
    int cur = q.front(); q.pop();
    for (int i = 0; i < G[cur].size(); ++i) {
      int next = G[cur][i];
      if (visited[next]) continue;
      q.push(next);
      dist[next] = dist[cur] + 1;
      visited[next] = true;
    }
  }
  return dist;
}

int main() {
  scanf("%d", &n);

  for (int i = 0; i < n - 1; ++i) {
    int a, b;
    scanf("%d %d", &a, &b);
    a--; b--;
    G[a].push_back(b);
    G[b].push_back(a);
  }

  vector<int> dist_b = bfs(0);
  vector<int> dist_w = bfs(n - 1);

  ll bcnt = 0;
  ll wcnt = 0;
  for (int i = 0; i < n; ++i) {
    if (dist_b[i] <= dist_w[i]) bcnt++;
    else wcnt++;
  }

  if (bcnt > wcnt) puts("Fennec");
  else puts("Snuke");
  return 0;
}


Measured memory_bytes: 6656
#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
#include <map>
using namespace std;

const int maxn = 2e5 + 5;

struct Point {
	int x, y;
	
	Point(int x=0, int y=0) : x(x), y(y) {}
	
	bool operator<(Point op) {
		return x < op.x || (x == op.x && y < op.y);
	}
	
}p[maxn];

int minb, maxb;

int dis(int i, int j) {
	return abs(p[i].x-p[j].x) + abs(p[i].y-p[j].y);
}

int main() {
	int n;
	cin >> n;
	for (int i = 0; i < n; ++i)
		scanf("%d %d", &p[i].x, &p[i].y);
	sort(p, p+n);
	minb = maxb = 0;
	int ans = 0;
	for (int i = 1; i < n; ++i) {
		ans = max(ans, max(dis(minb, i), dis(maxb, i)));
		if (p[minb].x+p[minb].y > p[i].x+p[i].y)
			minb = i;
		if (p[maxb].y-p[maxb].x < p[i].y-p[i].x)
			maxb = i;
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 5312
def main():
    n = int(input())
    m = int(n**0.5)
    ans = 10e8+7
    astr = ""
    bstr = ""
    alen = 0
    blen = 0
    for a in range(1,m+1):
        if n%a == 0:
            b = n//a
            astr = str(a)
            bstr = str(b)
            alen = len(astr)
            blen = len(bstr)
            if alen > blen:
                if ans > alen:
                    ans = alen
            else:
                if ans > blen:
                    ans = blen
    print(ans)

            

if __name__ == "__main__":
    main()

Measured memory_bytes: 3064
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);       // TODO 自動生成されたメソッド・スタブ
        int n = sc.nextInt();
        int[] h = new int[n];
        for (int i = 0 ; i < n ; i++) {
            h[i] = sc.nextInt();
        }
        int cnt = 0;
        int max = 0;

        for (int i = 0 ; i < n ; i++) {
            if (h[i] >= max) {
                cnt++;
            }
            max = Math.max(max, h[i]);
        }
        System.out.println(cnt);

    }

}


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

using namespace std;

using ll = long long;
using ld = long double;

const int INF = (1 << 30) - 1;
const ll INF64 = ((ll)1 << 62) - 1;
const double PI = 3.1415926535897932384626433832795;

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

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

	int a, b, c, d;
	cin >> a >> b >> c >> d;

	int aa = min(a, b);
	int bb = min(c, d);
	cout << aa + bb << endl;
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i,n) for(int i = 0; i < (n); ++i)
int main() {
    int n;
    cin >> n;
    vector<bool> s(4, false);
    rep(i, n ) {
        char tmp_s;
        cin >> tmp_s;
        if ( tmp_s == 'P' ) s[0] = true;
        if ( tmp_s == 'W' ) s[1] = true;
        if ( tmp_s == 'G' ) s[2] = true;
        if ( tmp_s == 'Y' ) s[3] = true;
    }
    int cnt = 0;
    rep(i, 4) {
        if ( s[i] ) ++cnt;
    }
    if ( cnt == 3 ) cout << "Three" << endl;
    else            cout << "Four" << endl;
    return 0;
}


Measured memory_bytes: 256
N=input()
counts=0
for i in range(0,len(N)):
    #print(N[i])
    if N[i]=='7':
        counts+=1
        #print(counts)   
        
    else:
        counts+=0
#print(counts)   
if counts>0:        
    print('Yes')
else:
    print('No')

Measured memory_bytes: 9112
#include <stdio.h>
int main(){
    int a,b,c,i,tmp=0;
    scanf("%d %d %d",&a,&b,&c);
    for(i=1;i<100;i++){
        if(a*i%b==c){
            printf("YES\n");
            tmp=1;
            break;
        }

    }
    if(tmp==0){
        printf("NO\n");
    }

}

Measured memory_bytes: 128
#include<cstdio>
#include<vector>
#include<algorithm>
using namespace std;
vector<int> vt;
int a[250002];
int cnt[501];
int visited[250001];
pair<int, int> b[501];
int main()
{
	int n;
	scanf("%d", &n);
	for (int i = 1; i <= n; i++) {
		scanf("%d", &b[i].first);
		b[i].second = i;
	}
	for (int i = 1; i <= n; i++)
		cnt[i] = n;
	sort(b+1, b + n+1);
	int left = 1;
	for (int i = 1; i <= n; i++)
	{
		visited[b[i].first] = 1;
		cnt[b[i].second]--;
		a[b[i].first] = b[i].second;
		for (int y = 0; y < b[i].second - 1; y++)
		{
			while (a[left])
				left++;
			a[left] = b[i].second;
			cnt[b[i].second]--;
		}
		if (left > b[i].first)
		{
			puts("No");
			return 0;
		}
	}
	int update = 0;
	for (int i = 1; i <= n*n; i++)
	{
		if (!a[i]) {
			if (vt.size() == update)
			{
				puts("No");
				return 0;
			}
			a[i] = vt[update];
			cnt[a[i]]--;
			if (!cnt[a[i]])
				update++;
			
		}
		if (visited[i]) {
			if(cnt[a[i]])
				vt.push_back(a[i]);
		}
	}
	puts("Yes");
	for (int i = 1; i <= n*n; i++)
		printf("%d ", a[i]);
}

Measured memory_bytes: 2816
import qualified Data.List as L

main :: IO ()
main = do
    n <- readLn :: IO Int
    xs <- map read.words <$> getLine
    case solve n xs of
        Just ys -> putStr.unlines $ map show ys
        Nothing -> print (-1)

solve :: Int -> [Int] -> Maybe [Int]
solve n xs = go [] xs
  where
    go acc [] = Just acc
    go acc xs = case L.partition (uncurry (==)) $ zip [1..] xs of
        ([], _) -> Nothing
        (ys, zs) -> go (y:acc) $ L.delete y xs
          where
            (y, _) = last ys

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

public class Main {

	public static void main(String[] args) throws IOException {
		InputStream inputStream = System.in;
		OutputStream outputStream = System.out;
		InputReader in = new InputReader(inputStream);
		PrintWriter out = new PrintWriter(outputStream);
		TaskX solver = new TaskX();
		solver.solve(1, in, out);
		out.close();
	}

	static int INF = 1 << 30;
	static int modP = 1000000007;

	static class TaskX {
		public void solve(int testNumber, InputReader in, PrintWriter out) {

			int n = in.nextInt();
			long[] a = in.nextLongArray(n);

			Arrays.sort(a);
			long min = INF;
			long a1 = a[n-1], a2 = 0;
			for (int i = n - 1; i >= 0; i--) {

				long d1 = Math.abs(a[n-1]-a[i]);
				long d2 = Math.abs(a[i]);
				long dmin = Math.max(d1, d2);

				if (min >= dmin) {
					min = dmin;
					a2 = a[i];
				}
			}

			out.println(a1 + " " + a2);

		}
	}

	static class InputReader {
		BufferedReader in;
		StringTokenizer tok;

		public String nextString() {
			while (!tok.hasMoreTokens()) {
				try {
					tok = new StringTokenizer(in.readLine(), " ");
				} catch (IOException e) {
					throw new InputMismatchException();
				}
			}
			return tok.nextToken();
		}

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

		public long nextLong() {
			return Long.parseLong(nextString());
		}

		public double nextDouble() {
			return Double.parseDouble(nextString());
		}

		public int[] nextIntArray(int n) {
			int[] res = new int[n];
			for (int i = 0; i < n; i++) {
				res[i] = nextInt();
			}
			return res;
		}

		public long[] nextLongArray(int n) {
			long[] res = new long[n];
			for (int i = 0; i < n; i++) {
				res[i] = nextLong();
			}
			return res;
		}

		public InputReader(InputStream inputStream) {
			in = new BufferedReader(new InputStreamReader(inputStream));
			tok = new StringTokenizer("");
		}

	}

}


Measured memory_bytes: 39404
#include<bits/stdc++.h>
using namespace std;
#define inf INT_MAX
#define INF LLONG_MAX
#define ll long long
#define ull unsigned long long
#define M (int)(1e9+7)
#define P pair<int,int>
#define FOR(i,m,n) for(int i=(int)m;i<(int)n;i++)
#define RFOR(i,m,n) for(int i=(int)m;i>=(int)n;i--)
#define rep(i,n) FOR(i,0,n)
#define rrep(i,n) RFOR(i,n,0)
#define all(a) a.begin(),a.end()
const int vx[4] = {0,1,0,-1};
const int vy[4] = {1,0,-1,0};
#define F first
#define S second
#define PB push_back
#define EB emplace_back
#define int ll
#define vi vector<int>
#define IP pair<int,P>
#define PI pair<P,int>
#define PP pair<P,P>
#define Yes(f){cout<<(f?"Yes":"No")<<endl;}
#define YES(f){cout<<(f?"YES":"NO")<<endl;}


signed main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout<<fixed<<setprecision(20);

  int n;
  cin>>n;
  vector<string> s(n);
  vi v(n);

  rep(i,n){
    cin>>s[i]>>v[i];
  }

  string t;
  cin>>t;
  reverse(all(s));
  reverse(all(v));

  int ans=0;
  rep(i,n){
    if(s[i]==t) break;
    ans+=v[i];
  }

  cout<<ans<<endl;


}

Measured memory_bytes: 256
import java.util.*;
public class Main {
  public static void main(String[] args) {
    Scanner console = new Scanner(System.in);
    String word1 = console.next();
    String word2 = console.next();
    String end = word2.substring(0, word1.length());
    if (word1.compareTo(end) == 0) {
      System.out.println("Yes");
    } else {
      System.out.println("No");
    }
  }
}


Measured memory_bytes: 35504
package main

/*
グラフの表現 隣接行列による表現
*/

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

func main() {
	scanner := makeScanner(8192)
	n := eGetInt(scanner)
	g := make([][]int, n)
	for i := 0; i < n; i++ {
		g[i] = make([]int, n)
		ints := eGetInts(scanner)
		num := ints[0]
		for j := 0; j < ints[1]; j++ {
			g[num-1][ints[j+2]-1] = 1
		}
	}
	for i := 0; i < n; i++ {
		s := fmt.Sprint(g[i])
		fmt.Println(s[1 : len(s)-1])
	}
}

////////////////////////////////////////////////////////////////////////////////
// ライブラリ
////////////////////////////////////////////////////////////////////////////////
func makeScanner(maxByte int) *bufio.Scanner {
	scanner := bufio.NewScanner(os.Stdin)
	scanner.Buffer(make([]uint8, 0, 8192), maxByte)
	return scanner
}
func makeWordScanner() *bufio.Scanner {
	scanner := makeScanner(8192)
	scanner.Split(bufio.ScanWords)
	return scanner
}
func eGetLine(r *bufio.Scanner) string {
	if r.Scan() {
		return r.Text()
	}
	err := r.Err()
	if err != nil {
		log.Fatal(err)
	}
	// EOF
	return ""
}
func eGetInt(r *bufio.Scanner) int {
	line := eGetLine(r)
	return eAtoi(line)
}
func eGetInt64(r *bufio.Scanner) int64 {
	line := eGetLine(r)
	return eAtoInt64(line)
}
func eGetFields(r *bufio.Scanner) []string {
	line := eGetLine(r)
	return strings.Fields(line)
}
func eGetInts(r *bufio.Scanner) []int {
	fields := eGetFields(r)
	ints := make([]int, len(fields))
	for i := 0; i < len(ints); i++ {
		ints[i] = eAtoi(fields[i])
	}
	return ints
}
func eGetInt64s(r *bufio.Scanner) []int64 {
	fields := eGetFields(r)
	ints := make([]int64, len(fields))
	for i := 0; i < len(ints); i++ {
		ints[i] = eAtoInt64(fields[i])
	}
	return ints
}
func eGetChars(r *bufio.Scanner) []string {
	line := eGetLine(r)
	return strings.Split(line, "")
}
func eAtoi(s string) int {
	n, err := strconv.Atoi(s)
	if err != nil {
		log.Fatal(err)
	}
	return n
}
func eAtoInt64(s string) int64 {
	n, err := strconv.ParseInt(s, 10, 64)
	if err != nil {
		log.Fatal(err)
	}
	return n
}



Measured memory_bytes: 1424
#include<bits/stdc++.h>
#define fasterthanlight ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL)
#define test int T; cin>>T; while(T--)
#define endl "\n"
#define int long long
#define vi vector<int>
#define pb push_back
#define mod 1000000007
#define MAX 1e9
#define MIN -1e9
using namespace std;

//author::@whohet-->Het Patel

signed main()
{
	fasterthanlight;
	int a, b, c, k;
	cin >> a >> b >> c >> k;
	int t = 0, sum = 0;
	t = t + a; sum = sum + a;
	if (t > k)
	{
		sum = sum - (t - k);
	}
	else if (t < k)
	{
		t = t + b;
		if (t < k)
		{
			sum = sum - (k - t);
		}
	}

	cout << sum;

	//cout << "\n\n"<<"Time elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " seconds.\n";
	return 0;
}


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

#define MEM(a, b) memset(a, (b), sizeof(a))
#define FORN(i, a, n, b) for (int i = a; i < n; i += b)
#define FRON(i, a, n, b) for (int i = a; i > n; i -= b)
#define FOR(i, n) for (int i = 0; i < n; i++)
#define FRO(i, a) for (int i = a; i > 0; i--)
#define MP make_pair
#define PB push_back
#define INF 1000000010
#define MOD 1000000007 // 998244353
#define PI 3.141592653589793238462643383279502884197169399375105820974945
#define FASTIO ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0)
typedef long long ll;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef pair<int, int> PII;
typedef vector<string> VS;
typedef vector<VI> VII;

//debugging
#define n_l '\n'
#define debug(...) cout << "[" << #__VA_ARGS__ << "]: "; cout << to_string(__VA_ARGS__) << endl
template <typename T, size_t N> int SIZE(const T (&t)[N]){ return N; } template<typename T> int SIZE(const T &t){ return t.size(); } string to_string(const string s, int x1=0, int x2=1e9){ return '"' + ((x1 < s.size()) ? s.substr(x1, x2-x1+1) : "") + '"'; } string to_string(const char* s) { return to_string((string) s); } string to_string(const bool b) { return (b ? "true" : "false"); } string to_string(const char c){ return string({c}); } template<size_t N> string to_string(const bitset<N> &b, int x1=0, int x2=1e9){ string t = ""; for(int __iii__ = min(x1,SIZE(b)),  __jjj__ = min(x2, SIZE(b)-1); __iii__ <= __jjj__; ++__iii__){ t += b[__iii__] + '0'; } return '"' + t + '"'; } template <typename A, typename... C> string to_string(const A (&v), int x1=0, int x2=1e9, C... coords); int l_v_l_v_l = 0, t_a_b_s = 0; template <typename A, typename B> string to_string(const pair<A, B> &p) { l_v_l_v_l++; string res = "(" + to_string(p.first) + ", " + to_string(p.second) + ")"; l_v_l_v_l--; return res; } template <typename A, typename... C> string to_string(const A (&v), int x1, int x2, C... coords) { int rnk = rank<A>::value; string tab(t_a_b_s, ' '); string res = ""; bool first = true; if(l_v_l_v_l == 0) res += n_l; res += tab + "["; x1 = min(x1, SIZE(v)), x2 = min(x2, SIZE(v)); auto l = begin(v); advance(l, x1); auto r = l; advance(r, (x2-x1) + (x2 < SIZE(v))); for (auto e = l; e != r; e = next(e)) { if (!first) { res += ", "; } first = false; l_v_l_v_l++; if(e != l){ if(rnk > 1) { res += n_l; t_a_b_s = l_v_l_v_l; }; } else{ t_a_b_s = 0; } res += to_string(*e, coords...); l_v_l_v_l--; } res += "]"; if(l_v_l_v_l == 0) res += n_l; return res; } void debugm(){;} template<typename Heads, typename... Tails> void debugm(Heads H, Tails... T){ cout << to_string(H) << " | "; debugm(T...); } 
#define debugm(...) cout << "[" << #__VA_ARGS__ << "]: "; debugm(__VA_ARGS__); cout << endl







int main() {
    FASTIO;
    int n, m;
    int sum = 0;
    cin >> n >> m;
    FOR(i, m) {
        int s;
        cin >> s; 
        sum += s;
    }
    if (sum > n) {
        cout << -1 << '\n';
    } else {
        cout << n-sum << "\n";
    }
}



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

using namespace std;
using ii = pair<int, int>;

int eval(int d, const vector<int>& seq) {
    vector<ii> xs;

    for (auto a : seq) {
        auto x = __gcd(d, a);

        if (x < d) {
            xs.push_back(ii(x, a));
        }
    }
    sort(xs.begin(), xs.end());

    for (size_t i = 1; i < xs.size(); i++) {
        d = __gcd(d, xs[i].second);
    }

    return d;
}

int solve(const vector<int>& seq) {
    int N = seq.size();

    //Casos base
    if (N == 1) {
        return seq.front();
    } 
    if (N == 2) {
        return max(seq.front(), seq.back());
    }

    auto d1 = __gcd(seq[0], seq[1]);
    auto ans = eval(d1, seq);

    auto d2 = __gcd(seq[0], seq[2]);
    ans = max(ans, eval(d2, seq));

    auto d3 = __gcd(seq[1], seq[2]);
    ans = max(ans, eval(d3, seq));

    return ans;
}

int main(int argc, char const *argv[])
{
    ios::sync_with_stdio(false);

    int N = 0;
    cin >> N;
    vector<int> seq(N);

    for (int i = 0; i < N; i++) {
        int x;
        cin >> x;

        seq[i] = abs(x);
    }

    auto ans = solve(seq);

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 2436
#include <math.h>
#include <time.h>
#include <ctype.h>
#include <stdio.h>
#include <assert.h>
#include <stdlib.h>
#include <string.h>
#include <map>
#include <set>
#include <deque>
#include <queue>
#include <stack>
#include <bitset>
#include <string>
#include <vector>
#include <iostream>
#include <algorithm>
#include<iomanip>

#define MX 10000000000
#define mod 1000000007
#define ll long long int
#define pb(x) push_back(x)
#define MP(x,y) make_pair(x,y)

using namespace std;

ll power(ll a, ll b, ll m)
{
	if (b == 0)
		return(1);
	ll sol = power(a, b / 2, m);
	sol = (sol * sol) % m;
	if (b % 2 == 1)
		sol = (sol * a) % m;
	return(sol);
}

ll gcd(ll a, ll b)
{
	if (b == 0)
		return a;
	else
	{
		return gcd(b, a % b);
	}
}
int cnt[100005], visited[100005];
void solve()
{
	int n,m;
	cin >> n>>m;
	for (int i = 0; i < m; i++)
	{
		int a;
		string s;
		cin >> a >> s;
		if (s == "WA" )
		{
			if(visited[a]==0)
			cnt[a]++;
		}
		else
		{
			visited[a] = 1;
		}
	}
	int cntt = 0, wa = 0;;
	for (int i = 0; i < 100001; i++)
	{
		cntt += visited[i];
		if (visited[i] == 1)
		{
			wa += cnt[i];
		}
	}
	cout << cntt << " " << wa;
}
int main()
{
	 int t = 1;
   	// cin >> t;
	 while (t--)
	 {
		  solve();
	 }
	 return 0;
}

Measured memory_bytes: 1024
#include<stdio.h>

int main(){

int N,K;
scanf("%d%d",&N,&K);

int A[N];

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

for (int i = K; i < N; i++)
{
  A[i-K] < A[i] ? puts("Yes"):puts("No");
}

return 0;

}

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

int main() {
  //ifstream in("input.txt");
  //cin.rdbuf(in.rdbuf());

  int N;
  cin>>N;

  int A=0,B=0;

  for(int i=0;i<N;i++){
    int At,Bt;
    cin>>At>>Bt;
    if(At>A) A=At,B=Bt;
  }
  cout<<A+B<<endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int A;
  int B;
  int C;
  
  cin >> A >> B >> C;
 
  if (A == B && B == C) {
    cout << "Yes" << endl;
  }
  else if(A != B || A != C || B != C) {
    cout << "No" << endl;
  }
 

}


Measured memory_bytes: 256
import math
mod = 10**9+7

N = int(input())
M = math.ceil(N/3)+1
x = [[0]*(N+1) for _ in range(M)]

for i in range(3,N+1):
    x[1][i] = 1

for i in range(2,M):
    for j in range(i*3,N+1):
        x[i][j] = (x[i][j-1] + x[i-1][j-3]) % mod
ans = 0
for i in range(1,M):
    ans = (ans + x[i][N]) % mod
print(ans)

Measured memory_bytes: 40412
// clang-format off
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define main signed main()
#define loop(i, a, n) for (int i = (a); i < (n); i++)
#define rep(i, n) loop(i, 0, n)
#define all(v) (v).begin(), (v).end()
#define rall(v) (v).rbegin(), (v).rend()
#define prec(n) fixed << setprecision(n)
constexpr int INF = sizeof(int) == sizeof(long long) ? 1000000000000000000LL : 1000000000;
constexpr int MOD = 1000000007;
constexpr double PI = 3.14159265358979;
template<typename A, typename B> bool cmin(A &a, const B &b) { return a > b ? (a = b, true) : false; }
template<typename A, typename B> bool cmax(A &a, const B &b) { return a < b ? (a = b, true) : false; }
bool odd(const int &n) { return n & 1; }
bool even(const int &n) { return ~n & 1; }
template<typename T = int> T in() { T x; cin >> x; return x; }
template<typename T = int> T in(T &&x) { T z(forward<T>(x)); cin >> z; return z; }
template<typename T> istream &operator>>(istream &is, vector<T> &v) { for (T &x : v) is >> x; return is; }
template<typename A, typename B> istream &operator>>(istream &is, pair<A, B> &p) { return is >> p.first >> p.second; }
template<typename T> ostream &operator<<(ostream &os, const vector<vector<T>> &v) { int n = v.size(); rep(i, n) os << v[i] << (i == n - 1 ? "" : "\n"); return os; }
template<typename T> ostream &operator<<(ostream &os, const vector<T> &v) { int n = v.size(); rep(i, n) os << v[i] << (i == n - 1 ? "" : " "); return os; }
template<typename A, typename B> ostream &operator<<(ostream &os, const pair<A, B> &p) { return os << p.first << ' ' << p.second; }
template<typename Head, typename Value> auto vectors(const Head &head, const Value &v) { return vector<Value>(head, v); }
template<typename Head, typename... Tail> auto vectors(Head x, Tail... tail) { auto inner = vectors(tail...); return vector<decltype(inner)>(x, inner); }
// clang-format on

main {
  while (true) {
    int n = in();
    if (n == 0) break;
    vector<int> x(n), y(n), r(n), c(n);
    rep(i, n) cin >> x[i] >> y[i] >> r[i] >> c[i];
    auto intersectCC = [&](int i, int j) {
      int r2 = (r[i] + r[j]) * (r[i] + r[j]);
      int d = (x[i] - x[j]) * (x[i] - x[j]) + (y[i] - y[j]) * (y[i] - y[j]);
      return d < r2;
    };
    auto intersect = [&](int t, int used) {
      bool f = false;
      rep(i, t) f |= (~used >> i & 1) && intersectCC(t, i);
      return f;
    };
    vector<int16_t> dp(1 << n, -1);
    function<int(int)> dfs = [&](int used) {
      if (dp[used] != -1) return dp[used];
      cmax(dp[used], 0);
      rep(i, n) loop(j, i + 1, n) {
        if ((used >> i & 1) || (used >> j & 1) || c[i] != c[j]) continue;
        if (intersect(i, used) || intersect(j, used)) continue;
        cmax(dp[used], dfs(used | (1 << i) | (1 << j)) + 2);
      }
      return dp[used];
    };
    cout << dfs(0) << endl;
  }
}



Measured memory_bytes: 35732
from collections import deque
 
N = int(input())
As = [deque([])]
for _ in range(N):
  As.append(deque(list(map(int, input().split()))))

cnt = 0
cset = set([i for i in range(1,N+1)])
while len(cset) > 0:
  cnt += 1
  fset = set()
  nex = set([])
  f = 1
  for i in cset:
    if i not in fset:
      if As[As[i][0]][0] == i and As[i][0] not in fset:
        vis = As[i].popleft()
        fset.add(vis)
        fset.add(As[vis].popleft())
        if len(As[i]) > 0:
          nex.add(i)
        if len(As[vis]) > 0:
          nex.add(vis)
        f = 0
  cset = nex
  if f == 1:
    print('-1')
    exit()
      
print(cnt)

Measured memory_bytes: 98976
#include<bits/stdc++.h>
using namespace std;
char a[111][111];
int main()
{
    int h,w;
    cin>>h>>w;
    for(int i=0;i<h;++i)
    {
        scanf("%s",a[i]);
    }
    for(int i=0;i<h-1;++i)
    {
        printf("%s\n%s\n",a[i],a[i]);
    }printf("%s\n%s",a[h-1],a[h-1]);
    return 0;
}


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

namespace ConsoleApplication2
{
    class Program
    {
        static void Main(string[] args)
        {
            while (true)
            {
                //????????¨??????????????????
                string[] s = Console.ReadLine().Split(' ');
                int high = int.Parse(s[0]);
                int width = int.Parse(s[1]);


                //????????¨????????¨??????0???????????????????????????????????????
                if ((high == 0) && (width) == 0) break;


                for (int i = 0; i < high; i++)
                {
                    for (int j = 0; j < width; j++)
                    {
                        Console.Write("#");
                    }
                    Console.Write("\n");
                }

                Console.Write("\n");

            }
        }
    }
}

Measured memory_bytes: 5288
#include <algorithm>
#include <cstdio>
const int N=100005;
int a[3][N],p[N],n;
bool u[N],inv[2],flip[2];
bool check(){
	for (int i=1;i<=n;i++){
		if (a[1][i]%3!=2) return 0;
		if (abs(a[0][i]-a[1][i])!=1 || abs(a[2][i]-a[1][i])!=1) return 0;
		if (((a[1][i]+1)/3-i)&1) return 0;
		p[i]=(a[1][i]+1)/3;
		flip[i&1]^=(a[0][i]>a[1][i]);
	}
	for (int i=1;i<=n;i++)
	if (!u[i])
		for (int j=p[i];j!=i;u[j]=1,j=p[j]) inv[i&1]^=1;
	return inv[0]==flip[1] && inv[1]==flip[0];
}
int main(){
	scanf("%d\n",&n);
	for (int i=0;i<3;i++)
		for (int j=1;j<=n;j++) scanf("%d",&a[i][j]);
	if (check()) printf("Yes\n");
		else printf("No\n");
}

Measured memory_bytes: 1792
NIL = None
class Tree:
    def __init__(self, key = None):
        self.key = key
        self.p = NIL
        self.left = NIL
        self.right = NIL
n = int(input())
tree = {"root":NIL}
def insert(T, z):
    y = NIL
    x = T["root"]
    while x != NIL:
        y = x
        if z.key < x.key:
            x = x.left
        else:
            x = x.right
    z.p = y
    if y == NIL:
        T["root"] = z
    elif z.key < y.key:
        y.left = z
    else:
        y.right = z
def preorder_tree_walk(T):
    print(f" {T.key}", end="")
    if T.left != NIL:
        preorder_tree_walk(T.left)
    if T.right != NIL:
        preorder_tree_walk(T.right)
def inorder_tree_walk(T):
    if T.left != NIL:
        inorder_tree_walk(T.left)
    print(f" {T.key}", end="")
    if T.right != NIL:
        inorder_tree_walk(T.right)
for _ in range(n):
    ss = input()
    if ss[0] == "i":
        s, v = ss.split()
        insert(tree, Tree(int(v)))
    else:
        inorder_tree_walk(tree["root"])
        print()
        preorder_tree_walk(tree["root"])
        print()



Measured memory_bytes: 105016
//0034 Railway Lines

#include<iostream>
#include<numeric>
using namespace std;

int main(void)
{
	while(1)
	{
		const int N = 10;
		int l[N];
		int v1, v2;
		int i;
		char dummy;
		for(i = 0; i < N; i++)
		{
			cin >> l[i] >> dummy;
		}
		if(!cin)
			break;
		cin >> v1 >> dummy >> v2;

		//Jnw©çÌ£
		int p[N];
		partial_sum(l, l+N, p);
		//v1+v2ÌXs[hÅsum(l)ð¥j·éÔª·êá¤Ô
		double t = ((double)p[N-1] / (v1+v2));
		double crashP = v1*t;	//·êá¤Êu
		//ãÍÔÉ©Ä¢­¾¯
		for(i = 0; i < N; i++)
		{
			if(p[i] >= crashP)
			{
				cout << i+1 << endl;
				break;
			}
		}
	}
	return 0;
}

Measured memory_bytes: 0
N,M = map(int,input().split())
L = []
for _ in range(M):
    L.append(list(map(int,input().split())))
L = sorted(L,key=lambda x:x[1])
now = -10
cnt = 0
for x in L:
    if now < x[0]:
        now = x[1] - 0.5
        cnt += 1
print(cnt)


Measured memory_bytes: 65368
#include <bits/stdc++.h>
using namespace std;
#define MD 1000000007
typedef long long int ll;
typedef pair<ll, ll> P;
template <typename T>
std::string tostr(const T &t){std::ostringstream os;os << t;return os.str();}
int dx[4]={1, 0, -1, 0}, dy[4]={0, 1, 0, -1};

int main()
{
    int n,ans=0;
    cin>>n;
    vector<int> v(n),l(n),r(n);
    for(int i=0;i<n;i++){
        cin>>v[i];
    }
    l[0]=v[0];
    r[n-1]=v[n-1];
    for(int i=1;i<n;i++){
        l[i]=__gcd(l[i-1],v[i]);
    }
    for(int i=n-2;i>=0;i--){
        r[i]=__gcd(r[i+1],v[i]);
    }
    ans=r[1];
    for(int i=1;i<n;i++){
        if(i==n-1){
            ans=max(ans,l[i-1]);
        }else{
            ans=max(ans,__gcd(l[i-1],r[i+1]));
        }
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 1408
program main
    implicit none
    integer x1, x2, x3, x4, x5

    read(*,*) x1, x2, x3, x4, x5
    if (x1 == 0) then
        write(*,*) 1
    else if (x2 == 0) then
        write(*,*) 2
    else if (x3 == 0) then
        write(*,*) 3
    else if (x4 == 0) then
        write(*,*) 4
    else if (x5 == 0) then
        write(*,*) 5
    end if

end program


Measured memory_bytes: 2652
def slove():
    import sys
    input = sys.stdin.readline
    n, k = list(map(int, input().rstrip('\n').split()))
    ab = [list(map(int, input().rstrip('\n').split())) for _ in range(n)]
    ab.sort()
    t = 0
    mt = 0
    for a, b in ab:
        t += b
        mt = max(mt, a)
        if t >= k:
            print(mt)
            exit()


if __name__ == '__main__':
    slove()


Measured memory_bytes: 56540
use std::io;
use std::iter;


fn main() {
    let d = read_one::<usize>();
    let eve = iter::repeat(" Eve").take(25 - d).collect::<String>();
    println!("{}", format!("Christmas{}", eve));
}


#[allow(dead_code)]
fn read<T>() -> Vec<T>
where T:
    std::str::FromStr,
    T::Err: std::fmt::Debug {

    let mut buf = String::new();
    io::stdin().read_line(&mut buf).unwrap();
    buf.split_whitespace()
        .map(|s| s.trim().parse().unwrap())
        .collect()
}

#[allow(dead_code)]
fn read_one<T>() -> T
where T:
    std::str::FromStr,
    T::Err: std::fmt::Debug {

    let mut buf = String::new();
    io::stdin().read_line(&mut buf).unwrap();
    buf.trim().parse().unwrap()
}

Measured memory_bytes: 4352
//include
//------------------------------------------
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>

using namespace std;

//conversion
//------------------------------------------
inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}

//math
//-------------------------------------------
template<class T> inline T sqr(T x) {return x*x;}

//typedef
//------------------------------------------
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef long long LL;
typedef unsigned long long ULL;

//container util
//------------------------------------------
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())

//repetition
//------------------------------------------
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)

//constant
//--------------------------------------------
const double EPS = 1e-10;
const double PI  = acos(-1.0);

//clear memory
#define CLR(a) memset((a), 0 ,sizeof(a))

//debug
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

int main() {
  int n, money, change;
  int coin[6] = {500, 100, 50, 10, 5, 1};

  while(1) {
    cin >> money;
    if(!money) break;

    change = 1000-money;

    int cnt = 0;
    REP(i, 6) {
      while(change/coin[i] > 0) {	
	cnt++;
	change -= coin[i];
      }
    }
    cout << cnt << endl;
  }
}

Measured memory_bytes: 1160
sx, sy, tx, ty = map(int,input().split())

def go():
    out = []
    x, y = sx, sy
    while y < ty:
        out.append('U'); y += 1
    while x < tx:
        out.append('R'); x += 1
    while y > sy:
        out.append('D'); y -= 1
    while x > sx:
        out.append('L'); x -= 1
    out.append('L'); x -= 1
    while y <= ty:
        out.append('U'); y += 1
    while x < tx:
        out.append('R'); x += 1
    out.append('D'); y -= 1
    out.append('R'); x += 1
    while y >= sy:
        out.append('D'); y -= 1
    while x > sx:
        out.append('L'); x -= 1
    out.append('U');
    return ''.join(out)

print(go())


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

using namespace std;

int n;
vector<long long> a;
map<long long, unsigned long long> dp;

unsigned long long getScore(long long mid){
    if(dp.count(mid)) return dp[mid];
    unsigned long long res = 0;
    for(int i = 0; i < n; i++){
        res += abs(a[i] - (mid + i + 1));
    }
    return res;
}

int main(){
    cin >> n;
    a.resize(n);
    for(auto&& i : a){
        cin >> i;
    }
    long long s = -1000000000, g = 1000000000;
    while(s < g){
        long long mid1 = (s * 2 + g) / 3;
        long long mid2 = (s + g * 2) / 3;
        unsigned long long score1 = getScore(mid1);
        unsigned long long score2 = getScore(mid2);
        if(score1 < score2){
            g = mid2 - 1;
        }
        else if(score1 > score2){
            s = mid1 + 1;
        }else{
            s = mid1 + 1;
            g = mid2 - 1 + (mid1 == mid2);
        }
    }
    cout << min(getScore(s), getScore(g)) << "\n";
}

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

int main() {
    int K;
    cin >> K;
    string S;
    cin >> S;
    if(S.size() <= K) {
        cout << S << endl;
    } else {
        cout << S.substr(0, K) << "..." << endl;
    }
    return 0;
}

Measured memory_bytes: 3628
#include <bits/stdc++.h>
using namespace std;
int main(){
    string s;
    cin >> s;
    int ans = 0;
    for (int i = 0; i < s.size()/2; i++){
        if (s[i] != s[s.size()-i-1]) ans++;
    }
    printf("%d",ans);

}


Measured memory_bytes: 256
import sys

N = int(sys.stdin.readline())
rabbits = map(int, sys.stdin.readline().split())
                                                                                                                                                                                                                                      
i = 0
pair = 0
while i< len(rabbits):
        if rabbits[rabbits[i]-1] == i + 1:
                pair += 1
        i += 1

print pair/2

Measured memory_bytes: 11328
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <queue>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>
#include <fstream>
#include <stdio.h>
#include <complex>
#include <cstdint>
#include <tuple>

#define M_PI       3.14159265358979323846

using namespace std;

//conversion
//------------------------------------------
inline int toInt(string s) { int v; istringstream sin(s); sin >> v; return v; }
template<class T> inline string toString(T x) { ostringstream sout; sout << x; return sout.str(); }
inline int readInt() { int x; scanf("%d", &x); return x; }

//typedef
//------------------------------------------
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef pair<int, PII> TIII;
typedef long long LL;
typedef unsigned long long ULL;
typedef vector<LL> VLL;
typedef vector<VLL> VVLL;

//container util

//------------------------------------------
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define SQ(a) (a*a)
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())

//repetition
//------------------------------------------
#define FOR(i,s,n) for(int i=s;i<(int)n;++i)
#define REP(i,n) FOR(i,0,n)
#define MOD 1000000007

int main() {
	int n;
	cin >> n;
	cout << 800 * n - (n / 15) * 200 << endl;
	return 0;
}

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

using namespace std;

const long long MAX_KEYS = 12, MAX_MASK = (1LL << 12), oo = 1e12;
long long minimum_cost[MAX_MASK];

int is_submask(int mask, int submask)
{
    return ((mask&submask) == submask);
}

int main()
{
    int no_of_boxes, no_of_keys;
    cin >> no_of_boxes >> no_of_keys;

    vector <long long> cost(no_of_keys + 1, 0);
    vector <int> no_of_openable_boxes(no_of_keys + 1, 0);
    vector <long long> mask(no_of_keys + 1, 0);

    for(int i = 1; i <= no_of_keys; i++)
    {
        cin >> cost[i] >> no_of_openable_boxes[i];

        for(int j = 1; j <= no_of_openable_boxes[i]; j++)
        {
            int key;
            cin >> key;

            key--;
            mask[i] |= (1 << key);
        }
    }

    long long oo = 1e12;
    int complete_mask = (1LL << no_of_boxes) - 1;
    vector <long long> minimum_cost(complete_mask + 1, oo);
    minimum_cost[0] = 0;

    for(int i = 1; i <= no_of_keys; i++)
    {
        for(int m = 0; m <= complete_mask; m++)
        {
            if(is_submask(m,mask[i]))
            {
                for(int sub_m = 0; sub_m <= complete_mask; sub_m++)
                {
                    if(is_submask(mask[i],sub_m))
                    {
                        minimum_cost[m] = min(minimum_cost[m], minimum_cost[m^sub_m] + cost[i]);
                    }
                }

            }
        }
    }

    cout << (minimum_cost[complete_mask] == oo ? -1 : minimum_cost[complete_mask]) << "\n";
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <iomanip>

using namespace std;

int main(){
    int N, K;
    cin >> N >> K;
    double p[N];
    for(int i=0; i<N; i++){
        double P;
        cin >> P;
        p[i] = (P + 1) / 2;
    }
    double e = 0.0;

    for(int i=0; i<K; i++) e += p[i];
    double ans = e;
    for(int i=K; i<N; i++){
        e += p[i] - p[i - K];
        ans = max(ans, e);
    }
    cout << setprecision(9) <<  ans << endl;
    return 0;
}

Measured memory_bytes: 1792
#include <bits/stdc++.h>
#pragma GCC optimize("O3")

#define fi first
#define se second
#define em emplace
#define eb emplace_back
#define mp make_pair
#define pi pair<int,int>
#define vi vector<int>
#define vpi vector<pair<int,int>>
#define vll vector<ll>
#define vpll vector<pair<ll,ll>>
#define endl '\n'

#define si(v) int((v).size())
#define all(v) (v).begin(), (v).end()
#define rep(i, n) for (ll i = 0; i < (ll)(n); ++i) 
#define rep2(i, n, m) for (ll i = n; i <= (ll)(m); ++i)
#define rep3(i, n, m) for (ll i = n; i >= (ll)(m); --i)

template<class T, class U> bool chmax(T &a, U b) { if (a < b) a = b; return true; }
template<class T, class U> bool chmin(T &a, U b) { if (a > b) a = b; return true; }

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

constexpr ll MOD = 1000000007;

signed main()
{
  cout << fixed << setprecision(20);
  ios::sync_with_stdio(false);
  cin.tie(0);

  int n; cin >> n;
  vi a(n);
  rep(i, n) cin >> a[i];

  sort(all(a),greater<int>());
  
  ll ans = a[0];
  rep2(i, 1, (n/2)-1) ans += a[i] * 2LL;
  if (n % 2) ans += a[n/2];

  cout << ans << endl;

  return (0);
}


Measured memory_bytes: 3968
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <stack>
#include <map>
#include <queue>
#include <cmath>

#define MOD (1000000007)

using namespace std;

typedef long long ll;
typedef pair<ll, ll> tup;
const int MAX = 510000;

long long fac[MAX], finv[MAX], inv[MAX];

// テーブルを作る前処理
void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}

// 二項係数計算
long long COM(int n, int k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}


int main() {
    COMinit();

    ll N;
    cin >> N;

    map<int, int> m;
    vector<int> A(N);
    for(int i = 0; i < N ; i++) {
        cin >> A[i];

        if(m.find(A[i]) == m.end()) m[A[i]] = 1;
        else m[A[i]]++;
    }

    ll ret = 0;
    for(auto i = m.begin(); i != m.end(); i++) {
        ret += (ll)i->second * (i->second - 1) / 2;
    }

    for(int i = 0; i < N; i++) {
        cout << ret - (m[A[i]]-1) << endl;
    }

    return 0;
}


Measured memory_bytes: 21504
import numpy as np
N =int(raw_input())
A =map(int ,raw_input().split())
B =np.abs(A)
B = np.array(B,dtype=np.int64)
C = min(B)
D = (sum(B))
E = D - 2*C
k = 0
for i in range(N):
    if A[i]<0:
        k = k+1
if k%2 == 0:
    print D
else:
    print E

Measured memory_bytes: 19148