akhauriyash/Code-Regression huggingface dataset:
from functools import cmp_to_key
n, w = [int(e) for e in input().split()]
d = [[int(e) for e in input().split()] for i in range(n)]
d.sort(key = cmp_to_key(lambda x, y: y[1] / y[0] - x[1] / x[0]))
t = {}
t[w] = 0
for i in range(n):
  keys = list(sorted(t.keys())) # sort しないと品物iを複数回ナップサックに詰める可能性がある
  tw, tv = d[i]
  for j in keys:
    nw = j - tw
    if nw < 0:
      continue
    nv = t[j] + tv
    if nw in t:
      if nv > t[nw]:
        for k in list(t.keys()):
          if k <= nw and t[k] < nv:
            del t[k]
        t[nw] = nv
    else:
      Flag = False
      for k in t:
        if nw <= k and nv <= t[k]:
          Flag = True
          break
      if Flag:
        continue
      for k in list(t.keys()):
        if k <= nw and t[k] < nv:
          del t[k]
      t[nw] = nv
        
print(max(t.values()))


Measured memory_bytes: 44636
import java.io.IOException;
import java.io.InputStream;
import java.util.NoSuchElementException;

public class Main {

	public static void main(String[] args) {

		FastScanner sc = new FastScanner();
		int R = sc.nextInt();

		System.out.println(3 * (int)Math.pow(R, 2));

	}

}

class FastScanner {
	private final InputStream in = System.in;
	private final byte[] buffer = new byte[1024];
	private int ptr = 0;
	private int buflen = 0;

	private boolean hasNextByte() {
		if (ptr < buflen) {
			return true;
		} else {
			ptr = 0;
			try {
				buflen = in.read(buffer);
			} catch (IOException e) {
				e.printStackTrace();
			}
			if (buflen <= 0) {
				return false;
			}
		}
		return true;
	}

	private int readByte() {
		if (hasNextByte())
			return buffer[ptr++];
		else
			return -1;
	}

	private static boolean isPrintableChar(int c) {
		return 33 <= c && c <= 126;
	}

	public boolean hasNext() {
		while (hasNextByte() && !isPrintableChar(buffer[ptr]))
			ptr++;
		return hasNextByte();
	}

	public String next() {
		if (!hasNext())
			throw new NoSuchElementException();
		StringBuilder sb = new StringBuilder();
		int b = readByte();
		while (isPrintableChar(b)) {
			sb.appendCodePoint(b);
			b = readByte();
		}
		return sb.toString();
	}

	public long nextLong() {
		if (!hasNext())
			throw new NoSuchElementException();
		long n = 0;
		boolean minus = false;
		int b = readByte();
		if (b == '-') {
			minus = true;
			b = readByte();
		}
		if (b < '0' || '9' < b) {
			throw new NumberFormatException();
		}
		while (true) {
			if ('0' <= b && b <= '9') {
				n *= 10;
				n += b - '0';
			} else if (b == -1 || !isPrintableChar(b)) {
				return minus ? -n : n;
			} else {
				throw new NumberFormatException();
			}
			b = readByte();
		}
	}

	public int nextInt() {
		long nl = nextLong();
		if (nl < Integer.MIN_VALUE || nl > Integer.MAX_VALUE)
			throw new NumberFormatException();
		return (int) nl;
	}

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


Measured memory_bytes: 22484
#include <stdio.h>
int main(void){
 long int n,a,b,t;
 scanf("%ld%ld%ld",&n,&a,&b);
 if(n%(a+b)<=a) t=n%(a+b);
 else t=a;
 printf("%ld",a*(n/(a+b))+t);
return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  vector<bool>v(3,false);
  for(int X=0;X<2;X++){
    int A;
    cin>>A;
    v[A-1]=true;
  }
  for(int X=0;X<3;X++){
    if(v[X]==false){
      cout<<X+1<<endl;
    }
  }
}

Measured memory_bytes: 3536
using System;
using System.Linq;
using System.Collections.Generic;
class Program
{
	static void Main()
	{
	string[] input = Console.ReadLine().Split(' ');//Splitで区切り文字を指定して複数個受け取る。
	int h = int.Parse(input[0]);
	int w = int.Parse(input[1]);

    List<char> characters = new List<char>();
    List<int> numbers = new List<int>();//文字の数一覧
    for(int i = 0; i < h; i++)
    {
    string numsA = Console.ReadLine();
    char[] nums = numsA.ToCharArray();
      for(int j = 0; j < nums.Length; j++) characters.Add(nums[j]);
    }
    characters.Sort();//並び替え

    int count = 1;//文字数を数える
    for(int i = 0; i < characters.Count()-1; i++)
    {
      if(characters[i] == characters[i+1])
      {
      count++;
        if(i == characters.Count()-2) numbers.Add(count);
      }
      else
      {
        numbers.Add(count);
        if(i == characters.Count()-2) numbers.Add(1);
        count = 1;
      }
    }

    

    int oddNum = 0;//奇数の個数
    for(int i = 0; i < numbers.Count(); i++)
    {
      if(numbers[i] % 2 == 1) oddNum++;
    }

    int secondNum = 0;//2(mod4)の個数
    for(int i = 0; i < numbers.Count(); i++)
    {
      if(numbers[i] % 4 == 2 || numbers[i] % 4 == 3) secondNum++;
    }

    bool answer = true;

    if((h == 1 && w % 2 == 0)||(w == 1 && h % 2 == 0))
    {
        if(oddNum >= 1) answer = false;
    }
    
    else if((h == 1 && w % 2 == 1)||(w == 1 && h % 2 == 1))
    {
      if(oddNum >= 2) answer = false;
    }

    else if(h % 2 == 0 && w % 2 == 0)
    {
      if(oddNum >= 1 || secondNum >= 1) answer = false;
    }

    else if(h % 2 == 0 && w % 2 == 1)
    {
      if(oddNum >= 1 || secondNum > h/2) answer = false;
    }

    else if(h % 2 == 1 && w % 2 == 0)
    {
      if(oddNum >= 1 || secondNum > w/2) answer = false;
    }

    else if(h % 2 == 1 && w % 2 == 1)
    {
      if(oddNum >= 2 || secondNum > h/2+w/2) answer = false;
    }

    Console.WriteLine(answer ? "Yes" : "No");

	}
}

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

using namespace std;

using ll = long long;
using Vi = vector<int>;
using Vl = vector<ll>;
using Pii = pair<int, int>;
using Pll = pair<ll, ll>;

constexpr int I_INF = (1 << 30);
constexpr ll L_INF = (1ll << 62);

//==================================

int dp[10550010][2];

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

    int D, G;
    cin >> D >> G;
    G /= 100;

    Vi p(D), c(D);
    for (int i = 0; i < D; ++i) {
        cin >> p[i] >> c[i];
        c[i] /= 100;
    }

    for (int i = 0; i < G; ++i) {
        dp[i][0] = dp[i][1] = I_INF;
    }
    dp[0][0] = 0;

    int ans = I_INF;

    for (int di = 1; di <= D; ++di) {
        for (int pi = 1; pi <= p[di - 1]; ++pi) {
            for (int i = 0; i < G; ++i) {
                if (dp[i][0] == I_INF) continue;

                if (pi == p[di - 1]) {
                    if (i + di * pi + c[di - 1] >= G) {
                        ans = min(ans, dp[i][0] + pi);
                    }
                    else {
                        dp[i + di * pi + c[di - 1]][1] = min(dp[i + di * pi + c[di - 1]][1], dp[i][0] + pi);
                    }
                }
                else {
                    if (i + di * pi >= G) {
                        ans = min(ans, dp[i][0] + pi);
                    }
                    else {
                        dp[i + di * pi][1] = min(dp[i + di * pi][1], dp[i][0] + pi);
                    }
                }
            }
        }
        for (int i = 0; i < G; ++i) {
            dp[i][0] = min(dp[i][0], dp[i][1]);
        }
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 1024
import Control.Monad
import Control.Applicative
import Data.Functor
import Data.List
import Data.Char

rotate s n = drop n s ++ take n s

main = do
    s <- getLine
    when (s /= "-") $ do
        m <- readLn
        replicateM m readLn >>= putStrLn . foldl rotate s 
        main

Measured memory_bytes: 4132
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cmath>
#include<vector>
using namespace std;
 
long long cnt;
int l;
int A[1000000];
int n;
vector<int> G;
 
void insertionSort(int A[], int n, int g) {
for ( int i = g; i < n; i++ ) {
  int v = A[i];
  int j = i - g;
while( j >= 0 && A[j] > v ) {
  A[j + g] = A[j];
  j -= g;
  cnt++;
}
A[j + g] = v;
}
}
 void shellSort(int A[], int n) {
for ( int h = 1; ; ) {
if ( h > n ) break;
G.push_back(h);
h = 3*h + 1;
}
 
for ( int i = G.size()-1; i >= 0; i-- ) {
insertionSort(A, n, G[i]);
}
}
 
int main() {
 cin >> n;
for ( int i = 0; i < n; i++ ) scanf("%d", &A[i]);
cnt = 0;
 
shellSort(A, n);
 
cout << G.size() << endl;
for ( int i = G.size() - 1; i >= 0; i-- ) {
printf("%d", G[i]);
if ( i ) printf(" ");
}
printf("\n");
printf("%d\n", cnt);
for ( int i = 0; i < n; i++ )
printf("%d\n", A[i]);
 
return 0;
}


Measured memory_bytes: 7116
dice = {
	1: [2, 3, 5, 4],
	2: [6, 3, 1, 4],
	3: [2, 6, 5, 1],
	4: [2, 1, 5, 6],
	5: [1, 3, 6, 4],
	6: [2, 4, 5, 3]
}
tags = []

def GetRight(top, front):
	numList = dice[top]
	for i in range(4):
		if numList[i] == front:
			return numList[(i+1)%4]

def SetDice():
	global tags
	tags = input().split(" ")
	
def DoQuestion():
	nums = input().split(" ")
	top = tags.index(nums[0])+1
	front = tags.index(nums[1])+1
	right = GetRight(top, front)
	print(tags[right-1])
	
SetDice()
q = int(input())
for i in range(q):
	DoQuestion()
	

Measured memory_bytes: 5596
#include<bits/stdc++.h>
using namespace std;
const long long maxn=1005;
const long long inf=0x3f3f3f3f;
long long dp[maxn][maxn]; 
int main(){
	ios::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	//freopen(".in","r",stdin);
	//freopen(".out","w",stdout);
	long long k;
	cin>>k;
	for(long long i=0;i<=9;i++)
		dp[1][i]=1;
	for(long long i=2;i<=10;i++)
		for(long long j=0;j<=9;j++)
			dp[i][j]=dp[i-1][j]+dp[i-1][j-1]+dp[i-1][j+1];
	long long l=0,r=0,flag=0;
	for(long long i=1;i<=10;i++)
	{
		for(long long j=1;j<=9;j++)
		{
			if(k<=dp[i][j])
			{
				l=i;
				r=j;
				flag=1;
				break;
			}
			k-=dp[i][j];
		}
		if(flag==1)
			break;
	}
	l--;
	queue<long long> q;
	q.push(r);
	while(l!=0)
	{
		if(k<=dp[l][r-1])
		{
			r--;
			q.push(r);
		}
		else
		{
			k-=dp[l][r-1];
			if(k<=dp[l][r])
				q.push(r);
			else
			{
				k-=dp[l][r];
				r++;
				q.push(r);
			}
		}
		l--;
	}
	while(!q.empty())
	{
		cout<<q.front();
		q.pop();
	}
	return 0;
}




Measured memory_bytes: 256
#include<stdio.h>
int main()
{
    int A,B,C,D,L,R;
    scanf("%d %d %d %d",&A,&B,&C,&D);
    L=A+B;
    R=C+D;
    if(L>R){
        printf("Left\n");
    }
      else if(L<R){
        printf("Right\n");
    }
     else if(L=R){
        printf("Balanced\n");
    }
    return 0;

}


Measured memory_bytes: 1600
import java.io.PrintWriter;
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        try (InputReader in = new InputReader(); PrintWriter out = new PrintWriter(System.out)) {
            new Main().solve(in, out);
            out.flush();
        }
    }

    void solve(InputReader in, PrintWriter out) {
        String s = in.next();

        int count = 0;
        for (char c : s.toCharArray()) {
            if (c == 'o') {
                count++;
            }
        }

        if (count + (15 - s.length()) >= 8) {
            out.println("YES");
        } else {
            out.println("NO");
        }
    }
}

class InputReader implements AutoCloseable {
    private final Scanner sc = new Scanner(System.in);

    String next() {
        return this.sc.next();
    }

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

    long nextLong() {
        return Long.parseLong(this.sc.next());
    }

    double nextDouble() {
        return Double.parseDouble(this.sc.next());
    }

    @Override
    public void close() {
        this.sc.close();
    }
}


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

using namespace std;

typedef long long ll;

int n, a, b, c, ans = 1e9;

vector<int> l;
void dfs(int i, int aa, int bb, int cc, int MP)
{
    if(i == n)
	{
		if(aa == a || bb == b || cc == c) 
			return ;
    	else
		{
    	    ans = min(ans, abs(aa) + abs(bb) + abs(cc) + MP);
    	    return ;
    	}
	} 
    dfs(i+1, aa - l[i], bb, cc, MP + (aa == a? 0:10));
    dfs(i+1, aa, bb - l[i], cc, MP + (bb == b? 0:10));
    dfs(i+1, aa, bb, cc-l[i], MP +(cc == c? 0:10));
    dfs(i+1, aa, bb, cc, MP);
}

int main()
{
    cin >> n >> a >> b >> c;
    getchar();
    for(int i = 1;i <= n; i++)
	{
        int c;
        cin >> c;
        getchar();
        l.push_back(c);
    }
    dfs(0, a, b, c, 0);
    cout << ans << endl;
    return 0;
}


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

int n,A[22];

bool check(int dep,int key){
  if(key==0){
    return 1;
  }
  if(dep==n){
    return 0;
  }
  bool res;
  res= check(dep+1,key)||check(dep+1,key-A[dep]);
  return res;
}

int main(){
  cin>> n;
  for(int i=0;i<n;i++){
    scanf("%d",&A[i]);
  }
  int k,ans=0;
  cin>>k;
  for(int i=0;i<k;i++){
    int key;
    cin>>key;
    cout << (check(0,key)?"yes":"no")<<endl;
  }

}


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

using namespace std;

using ll = long long;
using vi = vector<int>;
using vll = vector<ll>;
using vvi = vector<vector<int>>;
using vvl = vector<vector<ll>>;
int n, m;
vector<vector<int>> p;

struct N {
  int i, r, d;
};

bool operator<(const N &l, const N &r) {
  return l.d > r.d;
}

int main() {
  cin.tie(nullptr);
  ios::sync_with_stdio(false);
  cin >> n >> m;
  p.resize(n);
  for (int i = 0; i < m; i++) {
    int s, t;
    cin >> s >> t;
    s--;
    t--;
    p[s].push_back(t);
  }
  int s, t;
  cin >> s >> t;
  s--;
  t--;
  priority_queue<N> q;
  q.push(N{s, 0, 0});
  vector<vector<bool>> used(3, vector<bool>(n));
  while (q.size()) {
    N now = q.top();
    q.pop();
    if (used[now.r][now.i]) continue;
    used[now.r][now.i] = true;
    if (now.r == 0 && now.i == t) {
      cout << now.d / 3 << endl;
      return 0;
    }
    for (auto &j : p[now.i]) {
      if (used[(now.r + 1) % 3][j]) continue;
      q.push(N{j, (now.r + 1) % 3, now.d + 1});
    }
  }
  cout << -1 << endl;

  return 0;
}


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

int main()
{
    string str;
    cin >> str;
    
    string out;
    if(str == "A"){
        out = "T";
    }
    else if(str == "T"){
        out = "A";
    }
    else if(str == "G"){
        out = "C";
    }
    else if(str == "C"){
        out = "G";
    }
    
    cout << out << endl;
    
    return 0;
}

Measured memory_bytes: 256
module AOJ_Volume0095;

import std.stdio,std.string,std.conv,std.array,std.algorithm;

int main()
{
	int n = readln.chomp.to!int;
	int ans = 0;
	int res[21][2];
	foreach(i;0..n)
	{
		string[] s = readln.chomp.split(" ");
		int a = s[0].to!int;
		int v = s[1].to!int;
		res[i][0] = a;
		res[i][1] = v;
		ans = max(ans,v);
	}

	int min_num = 21;
	foreach(i;0..n)
	{
		if(ans == res[i][1])
		{
			min_num = min(min_num,res[i][0]);
		}
	}
	writeln(min_num," ",ans);
	return 0;
}

Measured memory_bytes: 1068
import numpy as np
import math
n = int(input())

def min_c(a, b, c):
    a1 = sum((b - c)** 2)
    b1 = sum((a - c)** 2)
    c1 = sum((a - b)** 2)
    a1, b1, c1 = sorted([a1, b1, c1],reverse=True)
    if a1 >= b1 + c1:
        return math.sqrt(a1) / 2
    a1 = math.sqrt(a1)
    b1 = math.sqrt(b1)
    c1 = math.sqrt(c1)
    cosa = (b1 ** 2 + c1 ** 2 - a1 ** 2) / (2 * b1 * c1)
    sina=math.sqrt(1-cosa**2)
    return a1/2/sina
    

xy = []
for _ in range(n):
    xy.append(np.array([int(i) for i in input().split()]))

if n == 2:
    ans=math.sqrt(sum((xy[0]-xy[1])**2))/2
else:
    ans=0
    for i in range(n):
        for j in range(i + 1, n):
            for k in range(j + 1, n):
                ans = max(ans, min_c(xy[i], xy[j], xy[k]))
print(ans)

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

#define INF INT_MAX/2
#define MOD 1000000007

using namespace std;

using ll = long long;
using ull = unsigned long long;

bool ok(ll sum,ll a){
   return ((sum+a) == (sum^a));
}

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

   int N;
   cin>>N;
   vector<ll>A(N);
   for(int i=0;i<N;i++)cin>>A[i];

   ll ans = 0;
   ll sum = 0;
   int right = 0;
   for(int left=0;left<N;left++){

      while(ok(sum,A[right])&&right<N){
         sum+=A[right];
         right++;
      }

      ans += right-left;

      if(right == left)right++;
      else sum -= A[left];
   }

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


Measured memory_bytes: 1792
#include<bits/stdc++.h>
using namespace std;
int main(){
	int N,hyaku,jikai;
	cin >> N;
	hyaku = N / 100;

	if(hyaku*111 < N) hyaku++;

	for(int i=1;i<=9;++i){
		if(i == hyaku) jikai = hyaku * 111;
	}

	cout << jikai << endl;
}


Measured memory_bytes: 256
MOD = 10**9+7
h, w, K = map(int, input().split())
n = w-1
dp = [[0] * w for _ in range(h+1)]
dp[0][0] = 1

def judge(edge):
    for i in range(1, n):
        if edge[i] and edge[i-1]: return False
    return True

for i in range(1, h+1):
    for j in range(w):
        for k in range(2**n):
            edge = [1 & (k >> l) for l in range(n)]
            if not judge(edge): continue
            if j < w-1 and edge[j]: dp[i][j] += dp[i-1][j+1]
            if j > 0 and edge[j-1]: dp[i][j] += dp[i-1][j-1]
            edge.append(0)
            if not edge[j] and not edge[j-1]:
                dp[i][j] += dp[i-1][j]

            dp[i][j] %= MOD

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


Measured memory_bytes: 48732
#include <iostream>
#include <vector>
#include <utility>
#include <cmath>

using namespace std;

#define P pair<int, int>

int main(void){
	int n, m;

	cin >> n >> m;

	vector<P> student(n+1), check(m+1);

	int a, b;
	for (int i = 0; i < n; i++){
		cin >> a >> b;
		student[i+1] = P(a, b);
	}

	for (int i = 0; i < m; i++){
		cin >> a >> b;
		check[i+1] = P(a, b);
	}

	for (int i = 1; i < n+1; i++){		
		int min = 1e9, id = 1;

		for (int j = 1; j < m+1; j++){
			if (abs(student[i].first - check[j].first) + abs(student[i].second - check[j].second) < min){
				min = abs(student[i].first - check[j].first) + abs(student[i].second - check[j].second);
				id = j;
			}
		}

		cout << id << endl;
	}

	

}

Measured memory_bytes: 256
#include <algorithm>
#include <cmath>
#include <iostream>
#include <deque>
#include <vector>
#include <string>
#include <utility>
#include <queue>
#include <unordered_map>
#include <unordered_set>

using namespace std;

int main()
{
	constexpr double PI = 3.1415926535;
	int a, b, x;
	cin >> a >> b >> x;

	if (2 * x > a * a * b)
	{
		int air = a * a * b - x;
		double c = (2.0 * air) / (a * a);
		printf("%f", (180.0 * atan2(c, a) / PI));
	}
	else
	{
		double c = (2.0 * x) / (a * b);
		printf("%f", (180.0 * atan2(b, c) / PI));
	}
}

Measured memory_bytes: 384
n = int(input())
V = list(map(int,input().split()))

from collections import Counter

v1 = []
v2 = []
for i in range(0,n-1,2):
  v1.append(V[i])
for i in range(1,n,2):
  v2.append(V[i])
  
c1 = Counter(v1).most_common() + [(0,0)]
c2 = Counter(v2).most_common() + [(0,0)]

if c1[0][0] == c2[0][0]:
  a1 = n -c1[1][1]-c2[0][1]
  a2 = n -c1[0][1]-c2[1][1]
  ans = min(a1,a2)
  
else:
  ans = n-c1[0][1]-c2[0][1]

print(ans)

Measured memory_bytes: 21084
import java.util.*;
public class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    int N = sc.nextInt();
    int Y = sc.nextInt();

    for(int a=0; a<=N; a++){
      for(int b=0; b<=N-a; b++){
        int c = N - a - b;
        int total = a * 10000 + b * 5000 + c * 1000;
        if(total == Y){
          System.out.println(a + " " + b + " " + c);
          return;
        }
      }
    }
    System.out.println("-1 -1 -1");
  }
}


Measured memory_bytes: 23252
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <functional>
#include <utility>
using namespace std;
#define MOD 1000000007
#define ADD(X,Y) ((X) = ((X) + (Y)%MOD) % MOD)
typedef long long i64; typedef vector<int> ivec; typedef vector<string> svec; typedef pair<int, int> pi;
int dd[] = { 0, 1, 0, -1, 0 };


int main()
{
	int N;
	ivec A;
	cin >> N;
	for (int i = 0; i < N; i++)
	{
		int a;
		cin >> a;
		A.push_back(a);
	}
	sort(A.begin(), A.end());
	cout << A[N - 1] - A[0] << endl;
	return 0;
}


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

using namespace std;

#define pb push_back
#define pp pop_back
#define F first
#define S second
#define endl "\n"
#define m_p make_pair

typedef long long ll;
typedef long double ld;

void INeedIt() {
	ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
}
int main() {
	INeedIt();
	int a, b;
	char c;
	cin>>a>>c>>b;
	if (c=='-') cout<<a-b;
	else cout<<a+b;
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
	int n,d,x,i,a,sum=0,c;
	cin>>n>>d>>x;
	for(i=1;i<=n;i++)
	{
		c=1;
		cin>>a;
		while(c<=d)
			c+=a,sum++;
	}
	cout<<x+sum<<endl;
	return 0;
}

Measured memory_bytes: 256
#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(){
    string x;
    cin >> x;
    ll l,ss=0,tt=0;
    l=x.size();

    string s;
    ll ans=0;
    rep(i,l){
        if(x[l-1-i]=='S'){
            ++ss;
        }
        else{
            
            ++tt;
        }
        ans=max(ans,ss-tt);
    }

    cout << 2*ans << endl;
    

    return 0;
}

Measured memory_bytes: 3704
#include <iostream>
#include <math.h>
using namespace std;

int main(void) {
	long long int n, kon_i;
	double kon_d;
	cin >> n;
	kon_d = sqrt(n);
	kon_i = (long long int)(kon_d) + 1;
	for (long long int i = kon_i; i > 0; i--) {
		if (n % i == 0) {
			cout << (i - 1) + (n / i - 1) << endl;
			return 0;
		}
	}
}

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

int main() {
  int K;
  cin >> K;
  int64_t count = 1;
  int64_t seven = 7;
  bool judge = false;
  for (int i = 0;i < K; i++){
    if (seven % K == 0){
      judge = true;
      break;
    }
    else {
      seven = (seven * 10 + 7) % K;
      count++;
    }
  }
  if (judge == true){
  	cout << count << endl;
  }
  else{
      cout << -1 << endl;
  }
}




Measured memory_bytes: 3600
#include <bits/stdc++.h>
#include <string>
#include <cstring>
#include <algorithm>
#include <math.h>
#include <map>
#include <bitset>
#include <cmath>
#include <set>
#include <utility>

#define INF 1000000000000
#define MOD 1000000007 //10^9+7:合同式の法

using namespace std;
typedef long long ll;

//マクロ
#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--)

int main(){
    int N,goukei = 0;
    cin >> N;
    vector<int> p(N);

    for(int i = 0;i < N;i++)
        cin >> p.at(i);

    sort(p.begin(),p.end());
    
    for(int i = 0;i < N;i++){
        if(i == N -1)
            goukei += p.at(i) / 2;
        else
            goukei += p.at(i);
        
    }

    cout << goukei << endl;


}

Measured memory_bytes: 3612
#include<stdio.h>
int main(){
  int n,m,c,i,l;
  char s[1000001];
  while(scanf("%d",&n),n){
    c=0;
    l=1;
    scanf("%d\n%s",&m,s);
    for(i=1;i<m;i++){
      if(s[i-1]==s[i])l=1;
      else	      l++;
      if(s[i]=='I'&&l>n*2)c++;
    }
    printf("%d\n",c);
  }
  return 0;
}

Measured memory_bytes: 1580
R, G, B, N = list(map(int, input().split()))

z = 0
for r in range(3001):
    rR = r * R
    if rR > N:
        break
    for g in range(3001):
        gG = g * G
        if rR + gG > N:
            break
        if (N - rR - gG) % B == 0:
            z = z + 1

print(z)

Measured memory_bytes: 2940
#include <bits/stdc++.h> 
#include <vector>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define size_of_array(array) (sizeof(array)/sizeof(array[0]))
using ll =long long;
using namespace std;
using Graph=vector<vector<int>>;
using Field=vector<vector<int>>;

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

const int m=2019;
int main(){
    string s;
    cin>>s;
    int n=s.size();
    reverse(s.begin(),s.end());
    int tot=0,x=1;
    ll ans=0;
    vector<int> cnt(m);
    rep(i,n){
        cnt[tot]++;
        tot+=(s[i]-'0')*x;
        tot%=m;
        ans+=cnt[tot];
        x=x*10%m;
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 3724
// in the name of Allah ;
#include<bits/stdc++.h>
using namespace std;
const int lg = 40 ;
int t[lg] , n ;
multiset < int > st ;
void init()
{
	t[0] = 1 ;
	for ( int i = 0 ; i < lg -1 ; i++ ) 
		t[i+1] = t[i]*2 ;
}
void input() 
{
	cin >> n ;
	int x ;
	for ( int i = 0 ; i < n ; i++ ) 
		cin >> x , st.insert ( x ) ;
}
int main () 
{
	init() ;
	input() ;
	int ans = 0 ;
	while ( st.size() )
	{
		int x = *st.rbegin() ;
		st.erase ( st.find(x) ) ;
		for ( int j = lg-1 ; j >= 0 ; j-- ) 
		{
			if ( st.find ( t[j] - x ) != st.end() ) 
			{
				ans++ , st.erase ( st.find ( t[j]-x ) ) ;
				break;
			}
		}
	}
	cout << ans << endl;
}

Measured memory_bytes: 9600
//A Addition and Subtraction Easy
#include<bits/stdc++.h>
using namespace std;

int main()
{
  int a,b;
  char op;
  cin>>a>>op>>b;
  if(op=='+')
  {
    cout<<a+b<<endl;
  }
  if(op=='-')
  {
    cout<<a-b<<endl;
  }
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define inf 10000000000
int main()
{
    string s;
    cin>>s;
    int k=s.length();
    ll w=0;
    for(int i=0;i<k;i++)
    {
        w+=(s[i]-'0');
    }
    if(w%9==0)
    cout<<"Yes\n";
    else
    cout<<"No\n";
    return 0;
}


Measured memory_bytes: 3716
using System;
using System.Diagnostics;
using System.IO;
using System.Text;
using System.Linq;
using System.Collections.Generic;
using System.Text.RegularExpressions;
using System.Runtime.InteropServices;

class Program
{
    const string Yes = "Yes";
    const string No = "No";
    const long Mod = 1000000007;
    const char White = '.';
    const char Black = '#';

    static void Main(string[] args) {
#if DEBUG
        MyDebugger.Test(process, "../TextFile1.txt");
#else
        object ret = process(new StreamReader(Console.OpenStandardInput()));
        Console.WriteLine(ret);
#endif
    }

    static object process(TextReader input) {
        var n = int.Parse(input.ReadLine());
        var ary = ToIntArray(input.ReadLine(), n);

        var c1 = 0;
        var c2 = 0;
        foreach(var a in ary) {
            if (a % 4 == 0) c1++;
            else if (a % 2 == 0) ;
            else c2++;
        }

        if(c1+c2 == n) {
            return c1 >= c2 - 1 ? Yes : No;
        } else {
            return c1 >= c2 ? Yes : No;
        }
    }


    static int[] ToIntArray(string strs, int n) {
        var ret = new int[n];
        var spl = strs.Split(' ');
        for (int i = 0; i < n; i++)
            ret[i] = int.Parse(spl[i]);
        return ret;
    }
}


Measured memory_bytes: 27840
#include <algorithm>
#include <cassert>
#include <cmath>
#include <cstdint>
#include <deque>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <regex>
#include <set>
#include <sstream>
#include <string>
#include <tuple>
#include <utility>
#include <vector>

using namespace std;
using ll = long long;

#define EPS (1e-7)
#define ALL(x) begin(x), end(x)

vector<ll> discard(vector<ll> juels, ll count) {
  sort(begin(juels), end(juels), greater<>());
  while (count > 0) {
    if (juels.size() > 0 && juels.back() < 0) {
      juels.pop_back();
    }
    count--;
  }
  return juels;
}

int main() {
  ll N, K;
  cin >> N >> K;
  vector<ll> V(N);
  for (ll i = 0; i < N; i++) {
    cin >> V[i];
  }

  ll ans = 0;
  for (ll a = 0; a <= K && a <= N; a++) {
    for (ll b = 0; a + b <= K && a + b <= N; b++) {
      const ll discard_count = K - a - b;
      vector<ll> vec;
      copy(cbegin(V), next(cbegin(V), a), back_inserter(vec));
      copy(prev(cend(V), b), cend(V), back_inserter(vec));
      vec = discard(vec, discard_count);
      ll temp = accumulate(cbegin(vec), cend(vec), 0LL);
      ans = max(ans, temp);
    }
  }
  cout << ans << endl;

  return 0;
}


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


int main (void) {
char S[100]={'\0'};
scanf("%s",S);
char pal[100]={'\0'};
int count =0;
for (int i=0;i<strlen(S);i++){
    pal[i]=S[(strlen(S)-1)-i];
    if (pal[i]!=S[i]) {count++;}
}
printf("%d",count/2);
return EXIT_SUCCESS;
}

Measured memory_bytes: 128
import math

K = int(input()) + 1
ans = 0
for a in range(1,K):
    for b in range(a,K):
        for c in range(b,K):
            ab = math.gcd(a,b)
            part = math.gcd(ab,c)
            if a == b or b == c:
                if not (a == b and b == c):
                    part = part * 3
            else:
                    part = part * 6                   
            ans += part
print(ans)

Measured memory_bytes: 9200
#include <iostream>
#include <vector>
#include <cmath>
using ll = long long;
using namespace std;

ll f(ll b, ll n) {
    if(n == 0) {
        return 0;
    }
    return f(b, n / b) + (n % b);
}

int main() {
    ll n, s;
    cin >> n >> s;
    if(s == n) {
        cout << n + 1 << endl;
    } else {
        for(int i=2; i<sqrt(n)+1; ++i) {
            if(f(i, n) == s) {
                cout << i << endl;
                return 0;
            }
        }

        for(int i=sqrt(n)+1; i>=1; --i) {
            ll b = (n - s) / i + 1;
            if(b >= 2 && f(b, n) == s) {
                cout << b << endl;
                return 0;
            }
        }
        cout << -1 << endl;
    }
}


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

#define ll int64_t
using namespace std;
#include <cstdlib> 
#include <math.h>
#include<cstdio>
#include<cstring>
#define FOR(I, A, B) for (ll I = (A); I <= (B); I++)
#define fo(i,n) for(ll i=0;i<n;i++)
#define sz(a) ll((a).size())
#define pb push_back
#define all(c) (c).begin(),(c).end()
#define dbg(x) cout << #x << " = " << x << endl
#define dbg2(x,y) cout << #x << " = " << x << ", " << #y << " = " << y << endl
#define dbg3(x,y,z) cout << #x << " = " << x << ", " << #y << " = " << y << ", " << #z << " = " << z << endl
#define dbg4(x,y,z,q) cout << #x << " = " << x << ", " << #y << " = " << y << ", " << #z << " = " << z << ", " << #q << " = " << q << endl
#define scan(char_array) scanf("%[^\n]s",&char_array)
#define IOS ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);


int main(){
    ll n,m;
  IOS
    cin>>n>>m;
    ll a[n];
    
    fo(i,n) cin>>a[i];
    map<ll,ll> mp;
    ll tmp=0;
    fo(i,n){
        tmp=(tmp+a[i])%m;
        mp[tmp]++;

    }
    ll ans=0;
    for(auto kk:mp){
        if(kk.second>1){
            ll tmp= kk.second*(kk.second-1);

            tmp=tmp/2;
            ans+=tmp;
        }
    }
    ans+=mp[0];
    cout<<ans<<endl;

}

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

int main(){
    int N;
    cin >> N;
    vector<int> P(N);
    for(int i=0;i<N;i++) cin >> P[i];

    int ans = 1e9;

    for(int x = 0; x <= P[0];x++){
        vector<int> p = P;
        int res = x;
        p[0] -= x;
        for(int i=0;i<N-1;i++){
            if(p[i] <= 0) continue;
            res += p[i]*2;
            p[i+1] -= p[i];
        }
        if(p[N-1] > 0) res += p[N-1];
        ans = min(ans,res);
    }
    cout << ans << endl;;
}


Measured memory_bytes: 3176
def solve(S):
    mid = len(S) // 2
    num_change = 0
    for i in range(mid):
        if S[i] != S[len(S)-1-i]:
            num_change += 1
    return num_change


if __name__ == "__main__":
    import sys
    for line in sys.stdin:
        text = line.strip("\n")

    print(solve(text))

Measured memory_bytes: 38384
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef double lf;
typedef pair<ll,ll> ii;
#define REP(i,n) for(int i=0;i<n;i++)
#define REP1(i,n) for(ll i=1;i<=n;i++)
#define RST(i,n) memset(i,n,sizeof i)
#define SZ(a) (int)a.size()
#define ALL(a) a.begin(),a.end()
#define X first
#define Y second
#define mkp make_pair
#define pb push_back
#define eb emplace_back
#define pob pop_back
#ifdef cold66
#define debug(...) do{\
    fprintf(stderr,"%s - %d (%s) = ",__PRETTY_FUNCTION__,__LINE__,#__VA_ARGS__);\
    _do(__VA_ARGS__);\
}while(0)
template<typename T>void _do(T &&_x){cerr<<_x<<endl;}
template<typename T,typename ...S> void _do(T &&_x,S &&..._t){cerr<<_x<<", ";_do(_t...);}
template<typename _a,typename _b> ostream& operator << (ostream &_s,const pair<_a,_b> &_p){return _s<<"("<<_p.X<<","<<_p.Y<<")";}
template<typename It> ostream& _OUTC(ostream &_s,It _ita,It _itb)
{
    _s<<"{";
    for(It _it=_ita;_it!=_itb;_it++)
    {
        _s<<(_it==_ita?"":",")<<*_it;
    }
    _s<<"}";
    return _s;
}
template<typename _a> ostream &operator << (ostream &_s,vector<_a> &_c){return _OUTC(_s,ALL(_c));}
template<typename _a> ostream &operator << (ostream &_s,set<_a> &_c){return _OUTC(_s,ALL(_c));}
template<typename _a,typename _b> ostream &operator << (ostream &_s,map<_a,_b> &_c){return _OUTC(_s,ALL(_c));}
template<typename _t> void pary(_t _a,_t _b){_OUTC(cerr,_a,_b);cerr<<endl;}
#define IOS()
#else
#define debug(...)
#define pary(...)
#define endl '\n'
#define IOS() ios_base::sync_with_stdio(0);cin.tie(0);
#endif // cold66
//}
template<class T> inline bool chkmax(T &a, const T &b) { return b > a ? a = b, true : false; }
template<class T> inline bool chkmin(T &a, const T &b) { return b < a ? a = b, true : false; }
template<class T> using MaxHeap = priority_queue<T>;
template<class T> using MinHeap = priority_queue<T, vector<T>, greater<T>>;

const ll MAXn=4e2+5,MAXlg=__lg(MAXn)+2;
const ll MOD=1000000007;
const ll INF=0x3f3f3f3f3f3f3f3f;

ll dp[MAXn][MAXn],dp1[MAXn][MAXn];
ll d[MAXn];
int main(){
  IOS();
  ll n;
  cin >> n;
  REP (i,n) cin >> d[i];
  REP (i,n) REP (j,n) dp[i][j] = dp1[i][j] = INF;
  REP (i,n) dp[i][i] = dp1[i][i] = d[i];
  
  REP1 (dis,n-1) {
    REP (l,n) {
      ll r = l+dis;
      if (r >= n) continue;
      for (ll i=l;i<r;i++) {
        dp[l][r] = min(dp[l][r],dp[l][i]+dp[i+1][r]);
      }
      for (ll i=l;i<r;i++) {
        dp1[l][r] = min(dp1[l][r],dp1[l][i]+dp1[i+1][r]+dp[l][r]);
      }
    }
  }

  cout << dp1[0][n-1]-dp[0][n-1] << endl;
}


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

#define FOR(i,a,b) for (int i = (a); i < (b); ++i)
#define F0R(i,a) FOR(i,0,a)
#define ROF(i,a,b) for (int i = (b)-1; i >= (a); --i)
#define R0F(i,a) ROF(i,0,a)

using ll = long long;
using ld = long double;
ll INF = LLONG_MAX;

using vi = vector<int>;
using vll = vector<ll>;
using pii = pair<int, int>;

namespace output {
	void pr(int x) { cout << x; }
	void pr(long x) { cout << x; }
	void pr(ll x) { cout << x; }
	void pr(unsigned x) { cout << x; }
	void pr(unsigned long x) { cout << x; }
	void pr(unsigned long long x) { cout << x; }
	void pr(float x) { cout << x; }
	void pr(double x) { cout << x; }
	void pr(ld x) { cout << x; }
	void pr(char x) { cout << x; }
	void pr(const char* x) { cout << x; }
	void pr(const string& x) { cout << x; }
	void pr(bool x) { pr(x ? "true" : "false"); }
	template<class T> void pr(const complex<T>& x) { cout << x; }
	
	template<class T1, class T2> void pr(const pair<T1,T2>& x);
	template<class T> void pr(const T& x);
	
	template<class T, class... Ts> void pr(const T& t, const Ts&... ts) { 
		pr(t); pr(ts...); 
	}
	template<class T1, class T2> void pr(const pair<T1,T2>& x) { 
		pr("{",x.f,", ",x.s,"}"); 
	}
	template<class T> void pr(const T& x) { 
		pr("{"); // const iterator needed for vector<bool>
		bool fst = 1; for (const auto& a: x) pr(!fst?", ":"",a), fst = 0; 
		pr("}");
	}
	
	void print() { pr("\n"); } // print w/ spaces
	template<class T, class... Ts> void print(const T& t, const Ts&... ts) { 
		pr(t); if (sizeof...(ts)) pr(" "); print(ts...); 
	}
}

using namespace output;

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

	int N; cin >> N;
	vi arr (N);
	F0R(i, N) cin >> arr[i];

	int res = 0;

	int j = 0;
	F0R(i, N) {
		if (arr[i] != i + 1) continue;

		while (j < i || (j < N && arr[j] == j + 1)) ++j;
		res += (j - i + 1) / 2;
		i = j;
	}
	print(res);
}

Measured memory_bytes: 640
#include<iostream>
#include<math.h>
#include<vector>
#include<algorithm>
#include<numeric>
#include<map>
#include<queue>
using namespace std;

int main(){
    int N;cin>>N;
    if(N%2==0)cout<<N<<endl;
    else cout<<2*N<<endl;
    return 0;
}

Measured memory_bytes: 256
//THINK FIRST CODE NEXT!!!!!!!!!!!!!!!!!
//It does not matter how slowly you go as long as you do not stop. - Confucius
#include<bits/stdc++.h>
using namespace std;
#define deb(x) cout << #x << ':' << x << endl;
#define loop3(i, k, n) for(i=k; i<n; i++)
#define ll  long long 
#define loop(i,n) for(int i=0;i<n;i++)
#define loop2(i,n) for(int i = 1;i<=n;i+=1)
#define pb push_back
#define mp make_pair
#define v1d vector<ll> 
#define v2d vector<vector<ll>>
#define Sort(v) sort(v.begin(),v.end())
const int INF = 1e9 +5 ;
#define ll        long long
// #define mp      make_pair
#define eb         emplace_back
#define pb         push_back
#define ss         second
#define ff         first
#define IOS        ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define mod        998244353
#define MOD        (1000*1000*1000+7)
#define MN         LLONG_MIN
#define MX         LLONG_MAX
#define v1d        vector<ll>
#define v2d        vector<vector<ll>>
#define vip        vector<pair<ll,ll> >
#define v1s        vector<string>
#define pa         pair<ll,ll>
#define mxpq(T)    priority_queue <T>
#define mnpq(T)    priority_queue<T,vector<T>,greater<T>>
#define print(v)   for(auto i:v)cout<<i<<" ";cout<<endl;
#define p2d(v)     for(auto a:v){for(auto b:a)cout<<b<<" ";cout<<endl;}
#define p1d(v)     for(auto a:v)cout<<a<<" ";cout<<endl;
#define ppd(v)     for(auto a:v)cout<<a.ff<<" "<<a.ss<<endl;
#define input(b,n) for(int i=0;i<n;i++)cin>>b[i];
#define Sort(v)    sort(v.begin(),v.end())
#define RSort(v)   sort(v.rbegin(),v.rend())
#define all(v)     v.begin(),v.end()
int gcd(int a,int b){return b?gcd(b,a%b):a;}
//string s = bitset<64>(a).to_string();

// recursion solution
ll fun1(v1d wt,v1d val, ll W, ll n)
{
    if(W == 0 || n == 0)
        return 0;
    
    if(wt[n-1] <= W)
    {
        return max(val[n-1]+fun1(wt,val,W-wt[n-1],n-1),fun1(wt,val,W,n-1));
    }
    return fun1(wt,val,W,n-1);
}

// memoization solution


ll fun2(v1d wt,v1d val, ll W, ll n,v2d dp)
{
    if(W == 0 || n == 0)
        return 0;
    if(dp[n][W]!= -1)
        return dp[n][W];
    
    if(wt[n-1] <= W)
    {
        return dp[n][W] = max(val[n-1]+fun2(wt,val,W-wt[n-1],n-1,dp),fun2(wt,val,W,n-1,dp));
    }
    return fun2(wt,val,W,n-1,dp);
}

//tabular method 

ll fun3(v1d wt,v1d val, ll W)
{
    ll n = wt.size();
    v2d dp(n+1,v1d (W+1));
    for(int i = 1; i<=n;i++)
    {
        for(int j = 1; j<=W;j++)
        {
            /*if(i == 0 || j == 0)
            {
                continue;
            }*/
            if(wt[i-1]>j)
            {
                dp[i][j] = dp[i-1][j];
            }
            else
            {
                dp[i][j] = max(dp[i-1][j-wt[i-1]] + val[i-1],dp[i-1][j]);
            }
            
        }
    }
    return dp[n][W];
}


int main()
{
    ll n,W;
    cin>>n>>W;
    v1d wt(n),val(n);
    loop(i,n)
    {
        cin>>wt[i]>>val[i];
    }
    // int ans = fun1(wt,val,W,n);
    v2d dp(n+1,v1d(W+1,-1));
    // int ans1 = fun2(wt,val,W,n,dp);
    // cout<<ans1<<" ";
    ll ans3 = fun3(wt,val,W);
    // deb(ans3);
    cout<<ans3;
    // deb(ans1);
    return 0;
}

Measured memory_bytes: 159088
import java.util.*;

public class Main{
    public static void main(String[]args){
        Scanner sc=new Scanner(System.in);
        String s=sc.next();
        for(int i=0;i<s.length();i++){
            if(i%2==0) System.out.print(s.charAt(i));
        }
        System.out.println("");
    }
}

Measured memory_bytes: 29404
#include <cstdio>
#include <iostream>
#include <string>
#include <vector>
#include <sstream>
#include <map>
#include <set>
#include <queue>
#include <algorithm>
#include <cmath>
#include <cstring>
#include <typeinfo>
#include <numeric>
#include <functional>
#include <unordered_map>
#include <bitset>
#include <stack>
#include <assert.h>
#include <unordered_set>
#include <random>


using namespace std;
using ll = long long;
using ull = unsigned long long;

const ll INF = 1e18;
const ll MOD = 1e9 + 7;

#define REP(i, n) for(ll i = 0; i < n; i++)



















int main(){
    ll x;
    cin >> x;
    ll v = 100, ans = 0;
    for(ll v = 100; v < x; v += v / 100){
        ans++;
    }
    cout << ans << endl;
}

Measured memory_bytes: 3636
#from collections import deque,defaultdict
printn = lambda x: print(x,end='')
inn = lambda : int(input())
inl   = lambda: list(map(int, input().split()))
inm   = lambda:      map(int, input().split())
ins = lambda : input().strip()
DBG = True # and False
BIG = 10**18
R = 10**9 + 7

def ddprint(x):
  if DBG:
    print(x)

k = inn()
s = ins()
if len(s)<=k:
    print(s)
else:
    print(s[:k]+'...')


Measured memory_bytes: 61780
#include<bits/stdc++.h>
#include <cctype>
#define ll          long long int
#define PB          push_back
#define PII         pair<ll int,ll int>
#define VI          vector<ll int>
#define ALL(a)      (a).begin(),(a).end()
#define F           first
#define S           second
#define SZ(x)       (ll int)x.size()
#define hell2        998244353
#define hell9        1000000007
#define FO(i,a,b)    for(i=a;i<b;i++)
#define lbnd        lower_bound
#define ubnd        upper_bound
#define BS          binary_search
#define MP          make_pair
using namespace std;
#define fio ios_base::sync_with_stdio(false);cin.tie(0);
/*ll power(ll x, ll y, ll p) 
{ 
    ll res = 1;
    x = x % p;  
    while (y > 0) 
    { 
        if (y & 1) 
            res = (res*x) % p; 
      y = y>>1; 
        x = (x*x) % p; 
    } 
    return res; 
} 
ll modInverse(ll n, ll p) 
{ 
    return power(n, p-2, p); 
} 
ll fac[500000]={0};
ll done=1;
ll ncrModP(ll n, ll r, ll p) 
{ 
   if (r==0) 
      return 1; 
     
    fac[0] = 1; 
    if(n>done)
    {for (ll i=done ; i<=n; i++) 
        fac[i] = (fac[i-1]*i)%p;}
        done=max(done,n); 
  
    return (fac[n]* modInverse(fac[r], p) % p * 
            modInverse(fac[n-r], p) % p) % p; 

} 
/*ll ncrM(ll n, ll r, ll p) 
{ 
    if (r > n - r) 
        r = n - r; 
    ll C[r + 1]; 
    memset(C, 0, sizeof(C)); 
    C[0] = 1; 
    for (ll i = 1; i <= n; i++) { 
        for (ll j = min(i, r); j > 0; j--) 
      C[j] = (C[j] + C[j - 1]) % p; 
    } 
    return C[r]; 
}
map<ll,ll>f;
ll done=2;
ll fib(ll k)
{
    ll i;f[0]=1;f[1]=1;f[2]=2;
    if(k<=done)return f[k];
    for(i=done;i<=k;i++)f[i]=(f[i-1]%hell9+f[i-2]%hell9)%hell9;
    done=k;
    return f[k]%hell9;
}*/
int main()
{
//  #ifndef ONLINE_JUDGE
//    freopen("input.txt", "r", stdin);
//    freopen("output.txt", "w", stdout);
//  #endif
    fio
    ll n,i;
    cin>>n;
    ll a[n];ll dp[n];
    FO(i,0,n)cin>>a[i];
    dp[0]=0;
    dp[1]=abs(a[1]-a[0]);
    FO(i,2,n)
    {
        dp[i]=min(dp[i-1]+abs(a[i]-a[i-1]),dp[i-2]+abs(a[i]-a[i-2]));
    }
    cout<<dp[n-1];
    return 0;
}

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

using namespace std;
using ll = long long;
#define int ll
using VI = vector<int>;
using VVI = vector<VI>;
using PII = pair<int, int>;

#define FOR(i, a, n) for (ll i = (ll)a; i < (ll)n; ++i)
#define REP(i, n) FOR(i, 0, n)
#define ALL(x) x.begin(), x.end()
#define PB push_back

const ll INF = (1LL<<60);
const int MOD = 1000000007;

template <typename T> T &chmin(T &a, const T &b) { return a = min(a, b); }
template <typename T> T &chmax(T &a, const T &b) { return a = max(a, b); }
template <typename T> bool IN(T a, T b, T x) { return a<=x&&x<b; }
template<typename T> T ceil(T a, T b) { return a/b + !!(a%b); }
template<class S,class T>
ostream &operator <<(ostream& out,const pair<S,T>& a){
  out<<'('<<a.first<<','<<a.second<<')';
  return out;
}
template<class T>
ostream &operator <<(ostream& out,const vector<T>& a){
  out<<'[';
  REP(i, a.size()) {out<<a[i];if(i!=a.size()-1)out<<',';}
  out<<']';
  return out;
}

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

vector<PII> g1[100010], g2[100010];
signed main(void)
{
  cin.tie(0);
  ios::sync_with_stdio(false);

  int n, m, s, t;
  cin >> n >> m >> s >> t; s--, t--;
  REP(i, m) {
    int u, v, a, b;
    cin >> u >> v >> a >> b; u--, v--;
    g1[u].PB({v, a});
    g1[v].PB({u, a});
    g2[u].PB({v, b});
    g2[v].PB({u, b});
  }

  VVI d(2, VI(n));
  auto dijkstra = [&](int s, int type) {
    d[type].assign(n, INF);
    d[type][s] = 0;
    priority_queue<PII, vector<PII>, greater<PII>> que;
    que.push(PII{d[type][s], s});

    while(que.size()) {
      PII p = que.top(); que.pop();
      int v = p.second;
      if(d[type][v] < p.first) continue;
      for(PII &e: (type==0?g1[v]:g2[v])) {
        if(d[type][e.first] > d[type][v] + e.second) {
          d[type][e.first] = d[type][v] + e.second;
          que.push(PII{d[type][e.first], e.first});
        }
      }
    }
  };

  dijkstra(s, 0);
  dijkstra(t, 1);

  VI ans(n);
  REP(i, n) ans[i] = d[0][i] + d[1][i];
  for(int i=n-2; i>=0; --i) chmin(ans[i], ans[i+1]);
  REP(i, n) cout << dec << (ll)1e15 - ans[i] << endl;

  return 0;
}


Measured memory_bytes: 18956
#include <iostream>

using namespace std;

long long int gcd(int a, int b)
{
    return !b ? a : gcd(b, a % b);
}
long long int lcm(int a, int b)
{
    return (a/ gcd(a, b)) * b;
}
int main()
{
    int a, b;
    cin>>a>>b;

    cout<<lcm(a, b)<<endl;

    return 0;
}


Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
using lint = long long;
const lint mod = 998244353;
#define all(x) (x).begin(), (x).end()
#define bitcount(n) __builtin_popcountl((lint)(n))
#define fcout cout << fixed << setprecision(15)
#define highest(x) (63 - __builtin_clzl(x))
template<class T> inline void YES(T condition){ if(condition) cout << "YES" << endl; else cout << "NO" << endl; }
template<class T> inline void Yes(T condition){ if(condition) cout << "Yes" << endl; else cout << "No" << endl; }
template<class T = string, class U = char>int character_count(T text, U character){ int ans = 0; for(U i: text){ ans += (i == character); } return ans; }
lint power(lint base, lint exponent, lint module){ if(exponent % 2){ return power(base, exponent - 1, module) * base % module; }else if(exponent){ lint root_ans = power(base, exponent / 2, module); return root_ans * root_ans % module; }else{ return 1; }}
struct position{ int y, x; }; position mv[4] = {{0, -1}, {1, 0}, {0, 1}, {-1, 0}}; // double euclidean(position first, position second){ return sqrt((second.x - first.x) * (second.x - first.x) + (second.y - first.y) * (second.y - first.y)); }
template<class T, class U> string to_string(pair<T, U> x){ return to_string(x.first) + "," + to_string(x.second); } string to_string(string x){ return x; }
template<class itr> void array_output(itr start, itr goal){ string ans; for(auto i = start; i != goal; i++) ans += to_string(*i) + " "; if(!ans.empty()) ans.pop_back(); cout << ans << endl; }
template<class itr> void cins(itr first, itr last){ for(auto i = first; i != last; i++){ cin >> (*i); } }
template<class T> T gcd_calc(T a, T b){ if(b){ return gcd_calc(b, a % b); }else{ return a; }}
template<class T> T gcd(T a, T b){ if(a < b) swap(a, b); return gcd_calc(a, b); }
template<class T> T lcm(T a, T b){ return a / gcd(a, b) * b; }
struct combination{ vector<lint> fact, inv; combination(int sz) : fact(sz + 1), inv(sz + 1){ fact[0] = 1; for(int i = 1; i <= sz; i++){ fact[i] = fact[i - 1] * i % mod; } inv[sz] = power(fact[sz], mod - 2, mod); for(int i = sz - 1; i >= 0; i--){ inv[i] = inv[i + 1] * (i + 1) % mod; } } lint C(int p, int q) const{ if(q < 0 || p < q) return 0; return (fact[p] * inv[q] % mod * inv[p - q] % mod); } };
template<class itr> bool next_sequence(itr first, itr last, int max_bound){ itr now = last; while(now != first){ now--; (*now)++; if((*now) == max_bound){ (*now) = 0; }else{ return true; } } return false; }
inline int at(int x, int k){ return (x >> k) & 1; }
random_device rnd;

int main(){
    int n;
    cin >> n;
    int p[n];
    cins(p, p + n);
    int ans = 0;
    for(int i = 1; i < n - 1; i++){
        ans += ((p[i - 1] < p[i] && p[i] < p[i + 1]) || (p[i - 1] > p[i] && p[i] > p[i + 1]));
    }
    cout << ans << endl;
}


Measured memory_bytes: 256
# -*- coding: utf-8 -*-


def main():
    h, w, d = map(int, input().split())
    a = [list(map(int, input().split())) for _ in range(h)]
    pieces = [0] * (h * w + 1)
    cost = [0 for _ in range(h * w + 1)]

    for hi in range(h):
        for wi in range(w):
            number = a[hi][wi]
            pieces[number] = (hi, wi)

    # See:
    # https://img.atcoder.jp/abc089/editorial.pdf
    # https://www.youtube.com/watch?v=EDq1rl-6YcQ
    for i in range(d + 1, h * w + 1):
        prev_piece = pieces[i - d]
        next_piece = pieces[i]

        cost[i] = cost[i - d] + \
            abs(next_piece[1] - prev_piece[1]) + \
            abs(next_piece[0] - prev_piece[0])

    q = int(input())
    ans = [0 for _ in range(q)]

    for j in range(q):
        lj, rj = map(int, input().split())
        ans[j] = cost[rj] - cost[lj]

    print('\n'.join(map(str, ans)))


if __name__ == '__main__':
    main()


Measured memory_bytes: 29196