akhauriyash/Code-Regression huggingface dataset:
package main

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

func out(x ...interface{}) {
	fmt.Println(x...)
}

var sc = bufio.NewScanner(os.Stdin)

func getInt() int {
	sc.Scan()
	i, e := strconv.Atoi(sc.Text())
	if e != nil {
		panic(e)
	}
	return i
}

func getString() string {
	sc.Scan()
	return sc.Text()
}

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

	N := getInt()
	a := make([]int, N)
	for i := 0; i < N; i++ {
		a[i] = getInt() - 1
	}

	s := 0
	ans := 0
	for {
		if ans == N {
			ans = -1
			break
		}
		if s == 1 {
			break
		}
		s = a[s]
		ans++
	}
	out(ans)
}


Measured memory_bytes: 2048
#![allow(non_snake_case)]
#![allow(unused_variables)]

fn main() {
    let N: i64 = {
        let mut line: String = String::new();
        std::io::stdin().read_line(&mut line).unwrap();
        line.trim().parse().unwrap()
    };

    let ans = (1..N)
        .map(|i| {
            let a: u32 = i.to_string().chars().map(|c| c.to_digit(10).unwrap()).sum();
            let b: u32 = (N - i).to_string().chars().map(|c| c.to_digit(10).unwrap()).sum();
            a + b
        })
        .min()
        .unwrap();

    println!("{}", ans);
}


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

ans = 0
while any(a[i] >= n for i in range(n)):
    res = [-(-(a[i] - n + 1) // n) for i in range(n)]
    x = sum(res)
    a = [a[i] + x - (n + 1) * res[i] for i in range(n)]
    ans += x
    #print(ans)

print(ans)

Measured memory_bytes: 41072
#include <stdio.h>
#define LMNTH 4280
#define BSCCHG 1150

int main(void)
{
	int w, chg;

	while (1) {
		scanf("%d", &w);
		if (w == -1)
			break;
		chg = BSCCHG;
		if (w > 30)
			chg += 1250 + 1400 + 160 * (w - 30);
		else if (w > 20)
			chg += 1250 + 140 * (w - 20);
		else if (w > 10)
			chg += 125 * (w - 10);
		printf("%d\n", LMNTH - chg);
	}

	return 0;
}

Measured memory_bytes: 600
import sys
from io import StringIO
import unittest
import os
import bisect

# 検索用タグ、尺取り、3つの内2つを固定
# https://drken1215.hatenablog.com/entry/2019/10/20/032700

# 実装を行う関数
def resolve():
    n = int(input())
    ls = list(map(int, input().split()))

    ls.sort()

    ans = 0
    # 尺取り
    for i in range(n - 2):
        a = ls[i]
        for j in range(i + 1, n - 1, 1):
            b = ls[j]
            # 以下がサンプル通りだが、TLE。
            # for k in range(j + 1, n, 1):
            #     c = ls[k]
            #     if not c < a + b:
            #         break
            #     ans += 1
            cnt = bisect.bisect_left(ls, a + b, j)
            ans += cnt - j - 1

    print(ans)


# テストクラス
class TestClass(unittest.TestCase):
    def assertIO(self, assert_input, output):
        stdout, sat_in = sys.stdout, sys.stdin
        sys.stdout, sys.stdin = StringIO(), StringIO(assert_input)
        resolve()
        sys.stdout.seek(0)
        out = sys.stdout.read()[:-1]
        sys.stdout, sys.stdin = stdout, sat_in
        self.assertEqual(out, output)

    def test_input_1(self):
        test_input = """4
3 4 2 1"""
        output = """1"""
        self.assertIO(test_input, output)

    def test_input_2(self):
        test_input = """3
1 1000 1"""
        output = """0"""
        self.assertIO(test_input, output)

    def test_input_3(self):
        test_input = """7
218 786 704 233 645 728 389"""
        output = """23"""
        self.assertIO(test_input, output)

    # 自作テストパターンのひな形(利用時は「tes_t」のアンダーバーを削除すること
    def tes_t_1original_1(self):
        test_input = """データ"""
        output = """データ"""
        self.assertIO(test_input, output)


# 実装orテストの呼び出し
if __name__ == "__main__":
    if os.environ.get("USERNAME") is None:
        # AtCoder提出時の場合
        resolve()

    else:
        # 自PCの場合
        unittest.main()


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

using namespace std;


int main() {
  int n, a, b, c, d;
  scanf("%d%d%d%d%d", &n, &a, &b, &c, &d);
  --n;
  for (int pos = 0; pos <= n; pos++) {
    long long left = (long long) c * pos + (long long) -d * (n - pos);
    long long right = (long long) d * pos + (long long) -c * (n - pos);
    if (a + left <= b && b <= a + right) {
      puts("YES");
      return 0;
    }
  }
  puts("NO");
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
// statics
using namespace std;
using int64 = int_fast64_t;
using PAIR = pair<int64, int64>;
constexpr int INF = 1 << 30;
constexpr int64 LINF = 1LL << 60;
constexpr int MOD = 1e9 + 7;
constexpr int MAX_N = 3e5 + 1;

// init/input
#define int int64
#define INIT ios::sync_with_stdio(false);cin.tie(0);
#define VAR(type, ...) type __VA_ARGS__;MACRO_VAR_Scan(__VA_ARGS__);
template<typename T> void MACRO_VAR_Scan(T &t) {cin>>t;}
template<typename First, typename...Rest> void MACRO_VAR_Scan(First &first, Rest&...rest) {cin>>first;MACRO_VAR_Scan(rest...);}
#define VEC(type, c, n) vector<type> c(n);for(auto &&i:c)cin>>i;

// out
#define OUT(dist) cout<<(dist);
#define FOUT(n, dist) cout<<fixed<<setprecision(n)<<(dist);
#define SP cout<<" ";
#define BR cout<<endl;
#define zero(n) cout<<setfill('0')<<right<<setw(n)
#define debug(x) cerr<<#x<<":"<< (x);BR;

// utility
#define ALL(a) (a).begin(), (a).end()
#define EACH(i, a) for(auto &&i:(a))
#define FOR(i, a, b) for(int i=(a);i<(b);++i)
#define RFOR(i, a, b) for(int i=(b)-1;i>=0;--i)
#define REP(i, n) for(int i=0;i<(n);++i)
#define RREP(i, n) for(int i=(n)-1;i>=0;--i)

signed main() {
  INIT;
	int n; string a, b, c;
	cin >> n >> a >> b >> c;
	int ans = 0;
	REP(i, n) {
		if (a[i] == b[i] && b[i] == c[i]) continue;
		int tmp = 0;
		if (a[i] != b[i] && b[i] != c[i] && c[i] != a[i]) ans += 2;
	  else ++ans;
	}
	cout << ans << endl;
  
  return 0;
}


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

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

using namespace std;
typedef long long ll;

int main()
{
	int n;
	cin >> n;
	
	rep(i,n)
	{
		ll a;
		cin >> a;
	
		cout << "Case " << i+1 << ":" << endl;
		rep(j,10)
		{
			a *= a;
			a /= 100;
			ll b = a/10000;
			b *= 10000;
			a -= b;
			cout << a << endl;
		}
	}
	return 0;
}

Measured memory_bytes: 1164
#include <iostream>
#include <string>
#include <vector>
using namespace std;

int main(){
	int N;
	int T;
	cin >> N;
	cin >> T;
	/*
	vector<int> c(N);
	vector<int> t(N);
	*/
	int c,t;
	int costMin = 10000;
	for(int i = 0; i < N; i++){
		cin >> c;
		cin >> t;
		if(t <= T && c < costMin) costMin = c;
	}

	if(costMin == 10000){
		cout << "TLE" << endl;
	}
	else{
		cout << costMin << endl;		
	}


}

Measured memory_bytes: 256
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<math.h>
#define scani(x) scanf("%d",&x)
#define scanc(x) scanf("%s",x)
#define printi(x) printf("%d",x)
#define printin(x) printf("%d\n",x)
#define printc(x) printf("%s",x)
#define repd(i,n,m) for(int i = n; i > m; i--)
#define repu(i,n,m) for(int i = 0; i < m; i++)
#define allprintu(i,n,m,a) for(int i = n; i < m; i++){if(i != m-1){printf("%d ",a[i]);}else{printf("%d",a[i]);}}
#define allprintd(i,n,m,a) for(int i = n; i > m; i--){if(i != 0){printf("%d ",a[i]);}else{printf("%d\n",a[i]);}}
	
int main(void){
	int n,q;
	int s[10000],t[500];
	int same = 0;

	scani(n);
	repu(i,0,n){
		scani(s[i]);
	}
	scani(q);
	repu(i,0,n){
		scani(t[i]);
	}
	repu(i,0,q){
		repu(j,0,n){
			if(t[i] == s[j]){
				same++;
				break;
			}
		}
	}

	printin(same);
	return 0;
}


Measured memory_bytes: 2144
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0; i<n; i++)
#define PI 3.14159265359
#define INF 1000100100
#define all(x) (x).begin(),(x).end()
typedef long long ll;
#define P pair<int, int>
using namespace std;

int main(){
    int a,b,t; cin >> a >> b >> t;
    cout << (t/a)*b << endl;
}

//rate1379

Measured memory_bytes: 256
using System;
class _0011
{
    public static void Main()
    {
        char[] splitChar = { ',' };
        int w = int.Parse(Console.ReadLine());
        int n = int.Parse(Console.ReadLine());
        int[] line = new int[w];
        for (int i = 0; i < w; i++) line[i] = i + 1;
        string str;
        int swap = 0;
        for (int i = 0; i < n; i++)
        {
            str = Console.ReadLine();
            string[] data = str.Split(splitChar);
            swap = line[int.Parse(data[0])-1];
            line[int.Parse(data[0])-1] = line[int.Parse(data[1])-1];
            line[int.Parse(data[1])-1] = swap;
        }
        for (int i = 0; i < w; i++) Console.WriteLine(line[i]);
    }
}

Measured memory_bytes: 5600
#include<bits/stdc++.h>
using namespace std;
long long n,ans,t=1,t2,x2;
double dl(long long x)
{
	t2=0; 
	x2=x;
    while(x!=0) 
	{
		t2=t2+x%10ll;
		x/=10ll;
	}
    return (x2*1.0)/(t2*1.0);
}
int main()
{
    cin>>n;
    for(int i=1;i<=n;i++)
	{
        while(1)
		{
            if(dl(ans+t)>dl(ans+t*10ll))
            {
                t*=10ll;
            }
            else
            {
            	break;
			}
        }
        ans+=t;
        cout<<ans<<endl;
    }
} 

Measured memory_bytes: 3504
from collections import deque
import sys
def main():
    H,W = list(map(int,sys.stdin.readline().split()))
    place_h = [0,-1,0,1]
    place_w = [1,0,-1,0]
    black = 0
    q = deque([])
    dist = []
    A = []
    for i in range(H):
        a = sys.stdin.readline().split()
        a = list(a[0])
        dist_sub = []
        for j in range(W):
            if a[j] == "#":
                black += 1
                q.append([i,j])
                dist_sub.append(0)
            else:
                dist_sub.append(-1)
        A.append(a)
        dist.append(dist_sub)

    ans = 0
    
    while len(q) > 0:
        vh,vw = q.popleft()
        for m in range(4):
            nvh = vh+place_h[m]
            nvw = vw+place_w[m]
            if 0<=nvh<H and 0<=nvw<W and dist[nvh][nvw] == -1:
                q.append([nvh,nvw])
                dist[nvh][nvw] = dist[vh][vw]+1
                if ans < dist[nvh][nvw]:
                    ans = dist[nvh][nvw]

    print(ans)

if __name__ == "__main__":
    main()




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

int main(){
  int n,y;
  cin>>n>>y;
  for(int a=0;a<=n;a++){
    for(int b=0;b<=n;b++){
      if((n-a-b>=0) && 10000*a + 5000*b + 1000*(n-a-b) == y){
        cout<<a<<" "<<b<<" "<<n-a-b<<endl;
        return 0;
      }
    }
  }
  cout<<-1<<" "<<-1<<" "<<-1<<endl;
}

Measured memory_bytes: 256
S = input()

if S=='SUN':
    print(7)
elif S=='SAT':
    print(1)
elif S=='FRI':
    print(2)
elif S=='THU':
    print(3)
elif S=='WED':
    print(4)
elif S=='TUE':
    print(5)
elif S=='MON':
    print(6)


Measured memory_bytes: 38256
#include <bits/stdc++.h>
#include <boost/integer/common_factor_rt.hpp>
using namespace std;
using ll=long long;
const int MOD=1000000007;


int main() {
  int n;
  cin >> n;
  vector<int> l(n);
  for(int i=0;i<n;i++){
    cin >> l.at(i);
  }
  sort(l.begin(),l.end());
  ll ans=0;
  for(int i=0;i<n-2;i++){
    for(int j=i+1;j<n-1;j++){
      for(int k=j+1;k<n;k++){
        if(l[i]+l[j]>l[k])
        ans++;
        else
        break;
      }
    }
  }
  cout << ans << endl;
}

Measured memory_bytes: 3608
#include <iostream>
#include <algorithm>
#include <vector>
#include <cmath>
#include <set>
using namespace std;
using ll = long long;
#define PI (acos(-1))

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

  int A[N];
  int point[N] = {};

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

  for (int i = 0; i < N - K; i++)
  {
    if (A[i] < A[i + K])
    {
      cout << "Yes" ;
      cout << "\n";
    }
    else
    {
      cout << "No";
      cout << "\n";
    }
  }
}


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

string s, t;

int main(void)
{
	int i;

	cin >> s >> t;

	for (i = 0; i < s.size(); i++)
		if (s[i] != t[i])
		{
			printf("No");
			return 0;
		}
	printf("Yes");
}

Measured memory_bytes: 3692
#include <bits/stdc++.h>
#include <chrono>
#include <math.h>
using namespace std;
using ll = long long;
using ld = long double;
using namespace std::chrono; 
#define fo(i,z,n) for(int i = z;i<n;i++)
#define Fo(i,z,n) for(ll i = z;i<n;i++)
#define INT_BITS 32
#define mod 1000000007
#define vi vector<int>
#define vll vector<ll>
#define vvi vector<vector<int> >
#define vvl vector<vector<ll> > 
#define pb push_back
#define f first
// #define s second
#define int long long
#define all(c) (c).begin(), (c).end()
#define endl '\n'

ll pow(ll a,ll p,ll m=mod)
{ll res=1;while(p>0){if(p&1)res=(res*a)%m;a=(a*a)%m;p>>=1;}
return res;}




int32_t main()
{
 
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
     cout.tie(0);
   	
//      int t;
//      cin >> t;
//      while(t--){



// }

int x,y;
cin >> x >> y;
	
	int b= (y-2*x)/2;
	int a = (4*x-y)/2;
	if(y&1)cout << "No" << endl;
	else if(b < 0 || a < 0)cout << "No" << endl;
	else cout << "Yes" << endl;
return 0;
}



Measured memory_bytes: 3652
#include<iostream>
#include<iomanip>
#include<cmath>
#include<string>
#include<cstring>
#include<vector>
#include<list>
#include<algorithm>
#include<map>
#include<set>
#include<queue>
#include<stack>
using namespace std;
typedef long long ll;
#define fi first
#define se second
#define mp make_pair
#define rep(i, n) for(int i=0;i<n;++i)
#define rrep(i, n) for(int i=n;i>=0;--i)
const int inf=1e9+7;
const ll mod=1e9+7;
const ll mod1=998244353;
const ll big=1e18;
const double PI=2*asin(1);

int main() {
  int N;
  cin>>N;
  queue<string> que;
  string state = "a";
  que.push(state);
  char maxchr;
  while(!que.empty()) {
    state = que.front();que.pop();
    if(state.size()==N) {
      cout<<state<<endl;
      continue;
    }
    maxchr = state[0];
    for(int i=0;i<state.size();++i) maxchr = max(maxchr, state[i]);
    for(char a='a'; a<=maxchr+1;++a) {
      state.push_back(a);
      que.push(state);
      state.pop_back();
    }
  }
}



Measured memory_bytes: 7304
#include<iostream>
#include<algorithm>
#include<vector>
#include<queue>
#include<map>
#include<set>
#include<stack>
using namespace std;
typedef long long ll;
ll MOD = 1e9+7;
#define rep(i,n) for(int i = 0; i < (n); ++i)
int main() {
    int n;
    cin >> n;
    vector<int> a(n+1);
    int ans = 0;
    rep(i, n) {
        int tmp_a;
        cin >> tmp_a;
        a[i+1] = tmp_a;
        if ( tmp_a < i + 1 ) {
            if ( a[tmp_a] == i+1 ) ++ans;
        }

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


Measured memory_bytes: 640
#include<iostream>
#include<string>
#include<cstring>
using namespace std;
int main(void){
	int jage1=0,jage2=0,time;
	char card1[100],card2[100];
	cin>>time;
	for(int abc=0;abc<time;abc++){
		cin>>card1>>card2;
		if(strcmp(card1,card2)>0){
			jage1+=3;
		}else if(strcmp(card1,card2)<0){
			jage2+=3;
		}else{
			jage1++;
			jage2++;
		}
	}
	cout<<jage1<<" "<<jage2<<endl;
	return 0;
}

Measured memory_bytes: 1172
import sys
primes=[2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59, 61, 67, 71, 73, 79, 83, 89, 97]
num3=0
num5=0
num15=0
num25=0
num75=0
n=int(input())
for i in primes:
  tmp=0
  j=1
  while n//pow(i,j)>0:
    tmp+=n//pow(i,j)
    j+=1
  if tmp>=2:
    num3+=1
  if tmp>=4:
    num5+=1
  if tmp>=14:
    num15+=1
  if tmp>=24:
    num25+=1
  if tmp>=74:
    num75+=1
print(num75+max(0,(num3-1)*num25)+max(0,((num3-2)*(num5-1)*num5)//2)+max(0,((num5-1)*num15)))

  

Measured memory_bytes: 61976
#pragma GCC optimize("Ofast")
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define rep(i,n) for(int i=0;i<n;i++)
#define INF 1000000000000000000
#define MOD 1000000007
typedef pair<int, int> P;

bool prime(int n) {
	for (int i = 2; i <= sqrt(n); i++) {
		if (n % i == 0)return false;
	}
	return n != 1;
}
int gcd(int x, int y) {
	if (y == 0)return x;
	return gcd(y, x % y);
}
int lcm(int x, int y) {
	return x / gcd(x, y) * y;
}
int mod_pow(int n, int p, int m) {
	if (p == 0) return 1;
	if (p % 2 == 0) {
		int t = mod_pow(n, p / 2, m);
		return (t * t) % m;
	}
	return n * mod_pow(n, p - 1, m) % m;
}
int extGCD(int a, int b, int& x, int& y) {
	if (b == 0) {
		x = 1;
		y = 0;
		return a;
	}
	long long d = extGCD(b, a % b, y, x);
	y -= a / b * x;
	return d;
}
int modinv(int a, int m) {
	int b = m, u = 1, v = 0;
	while (b) {
		long long t = a / b;
		a -= t * b; swap(a, b);
		u -= t * v; swap(u, v);
	}
	u %= m;
	if (u < 0) u += m;
	return u;
}
int digit(int x) {
	int cnt = 0;
	while (x > 0) {
		cnt += x % 10;
		x /= 10;
	}
	return cnt;
}
int read() {
	int tmp;
	cin >> tmp;
	return tmp;
}
int xor128() {
	static int x = 123456789, y = 362436069, z = 521288629, w = 88675123;
	int t = (x xor (x << 11));
	x = y; y = z; z = w;
	return (w = (w xor (w >> 19)) xor (t xor (t >> 8)));
}

class UnionFind {
	vector<int>par;
public:
	UnionFind(int n) {
		rep(i, n) par.push_back(-1);
	}

	int root(int x) {
		if (par[x] < 0) return x;
		else return par[x] = root(par[x]);
	}

	bool same(int a, int b) {
		return root(a) == root(b);
	}

	void unite(int x, int y) {
		x = root(x), y = root(y);
		if (x == y) return;
		if (par[y] < par[x]) swap(x, y);
		par[x] += par[y];
		par[y] = x;
		return;
	}

	int size(int x) {
		return -par[root(x)];
	}
};

signed main() {
	int n, k, l;
	cin >> n >> k >> l;
	UnionFind ro(n), tr(n);
	rep(i, k) {
		int p, q;
		cin >> p >> q;
		p--,q--;
		ro.unite(p, q);
	}
	rep(i, l) {
		int p, q;
		cin >> p >> q;
		p--,q--;
		tr.unite(p, q);
	}

	map<P, int>ma;
	rep(i, n) {
		int x = ro.root(i), y = tr.root(i);
		ma[{x, y}]++;
	}
	rep(i, n) {
		int x = ro.root(i), y = tr.root(i);
		cout << ma[{x, y}] << " ";
	}
	cout << endl;

	return 0;
}

Measured memory_bytes: 15088
n, k = map(int, input().split())
h = list(map(int, input().split()))
dp = [float('inf')] * n
dp[0] = 0

for i in range(n):
  for j in range(max(0, i-k), i):
    dp[i] = min(dp[j]+abs(h[j] - h[i]), dp[i])
print(dp[-1])

Measured memory_bytes: 55008
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        char[] s = sc.next().toCharArray();
        int left = 0;
        int max = 0;
        int right=0;
        while(true){
            while(right < s.length && (s[right]=='A' || s[right]=='T' || s[right] == 'C' || s[right] == 'G'))right++;
            max = Math.max(max,right-left);
            if(right >= s.length)break;
            left = right+1;
            right++;
        }
        sc.close();
        System.out.println(max);
    }
}

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

// 総数を1000000007で割った余り
const long long mod = 1e9 + 7;

using ll = long long;
#define ld long double
#define ull unsigned long long int

#define rep(i, n) for (int i = 0, i##_len = (n); i < i##_len; ++i)
#define rep1(i, n) for (int i = 1, i##_len = (n); i <= i##_len; ++i)
#define rrep(i, n) for (int i = ((int)(n)-1); i >= 0; --i)
#define rrep1(i, n) for (int i = ((int)(n)); i > 0; --i)
#define sz(x) ((int)(x).size())
#define SORT(v, n) sort(v, v + n);
#define VSORT(v) sort(v.begin(), v.end());
#define RSORT(x) sort(rall(x));
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define FOR(i, m, n) for (int i = m; i < n; i++)  // (i, 3, 10) i=3～i=9まで
#define pb push_back

typedef pair<int, int>    pii;
typedef vector<int>       vi;
typedef vector<vi>        vii;
typedef vector<double>    vd;
typedef vector<long long> vl;

// template<class T>bool maxc(T &a, const T &b) { if (a<b) { a=b; return 1; } }
// template<class T>bool minc(T &a, const T &b) { if (b<a) { a=b; return 1; } }

#define INF (1e9)
#define PI (acos(-1))
#define EPS (1e-7)

int main() {
    // cin.tie(0);
    // ios::sync_with_stdio(false);
    // cout << fixed << setprecision(5);

    // 入力
    int l, r;
    cin >> l >> r;

    // 処理
    int ans = 2019;
    int a, b;
    for (int i = l; i < r; i++) {
        for (int j = l + 1; j <= r; j++) {
            a   = i % 2019;
            b   = j % 2019;
            ans = min(ans, (a * b) % 2019);
            if (ans == 0) {
                cout << ans << endl;
                return 0;
            }
        }
    }

    // 出力
    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 256
using System;
using System.Linq;

namespace AtCoder.Question
{
    public class QuestionA
    {
        public static void Main(string[] args)
        {
            var k = Console.ReadLine();
            var s = Console.ReadLine();

            var length = int.Parse(k);

            if (s.Length <= length)
            {
                Console.WriteLine(s);
            }
            else
            {
                Console.WriteLine($"{s.Substring(0,length)}...");
            }
        }
    }
}


Measured memory_bytes: 27540
#include<iostream>
#include<string>
#include<algorithm>
#include<map>
#include<stdlib.h>
#include<iomanip>
#include<limits>
#include<queue>
#include<stack>
#include<math.h>
#include<array>
const int INF = 1e9;
const int MOD = 1e9 + 7;
using namespace std;
int main(){
	int a, b, c, d;
	cin >> a >> b >> c >> d;
	int x = c - a, y = d - b;
	printf("%d %d %d %d\n", c - y, d + x, a - y, b + x);
	return 0;
}

Measured memory_bytes: 256
package main

import "fmt"

func abs(a int) int {
	if a >= 0 {
		return a
	}
	return -a
}
func min(a, b int) int {
	if a >= b {
		return b
	}
	return a
}

func main() {
	var a, b int
	fmt.Scan(&a, &b)
	if abs(a-b)%2 == 0 {
		fmt.Println((abs(a-b) / 2) + min(a, b))
	} else {
		fmt.Println("IMPOSSIBLE")
	}
}


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

int main() {
  int A,B,M;
  cin >> A >> B >> M;

  vector<int> typea(A);
  vector<int> typeb(B);
  vector<vector<int>> typem(M, vector<int>(3));

  for (int i = 0; i < A; i++) {
    cin >> typea.at(i);
  }

  for (int i = 0; i < B; i++) {
    cin >> typeb.at(i);
  }

  for (int i = 0; i < M; i++) {
    for (int j = 0; j < 3; j++) {
      cin >> typem.at(i).at(j);
    }
  }
  
  vector<int> discountM(M);
  for (int i = 0; i < M; i++) {
    int discountA = typem.at(i).at(0);
    int discountB = typem.at(i).at(1);
    discountM.at(i) = typea.at(discountA-1) + typeb.at(discountB-1) - typem.at(i).at(2);
  }
  
  
  sort(discountM.begin(), discountM.end());
  
  int minprice = 0;
  int discountprice = discountM.at(0);
  
  
  sort(typea.begin(), typea.end());
  sort(typeb.begin(), typeb.end());
  
  minprice = typea.at(0) + typeb.at(0);

  
  if ( minprice >= discountprice ){
    cout << discountprice << endl;
  }
  else {
    cout << minprice << endl;
  }



  
}


Measured memory_bytes: 8576
#include <bits/stdc++.h>
#include <vector>
#include <algorithm>
#include <cmath>

using namespace std;

int gcd(int a, int b) {
//
if(a<0) a=b;
if(b<0) b=a;
//
	if (b == 0) return a;
	return gcd(b, a%b);
}

int lcm(int a, int b) {
	return a*b/gcd(a, b);
}

int main(){

	int n, x, ans=-1;
	vector<int> v;

	cin>> n >> x;
	v.resize(n+1);
	v[n]=x;
	for(int i=0;i<n;i++) cin>> v[i];
	sort(v.begin(), v.end());

	for(int i=0;i<v.size()-1;i++){
		v[i]=v[i+1]-v[i];
		ans=gcd(v[i], ans);
	}

	cout<< ans << endl;


}

Measured memory_bytes: 640
#include<bits/stdc++.h>
#include<array>
#define nguyendz the_best


#define ll long long
#define ld long double
#define pb push_back
#define all(n) n.begin(),n.end()
#define eb emplace_back
#define endl "\n"
#define pll pair<ll,ll>
#define YES cout <<"YES"<<endl;
#define NO cout <<"NO"<<endl;
#define ff first
#define ss second
#define setpre(x) fixed<<setprecision(x)
//do not use "\n" in interactive problem
// ((x|y)-y) (x&(~y))
// __gcd(fibo(x),fibo(y)=fibo(__gcd(x,y))
//so luong tap hop gom d phan tu khac nhau dc tao tu k so phan biet la k mu d
// a+b=(a^b)+2*(a&b)
using namespace std;
const ll maxn=5e5+100;

const ll maxx=1e13;
const ll mod1=1000000007;
const ll mod2=998244353;
priority_queue<pll,vector<pll>,greater<pll>> q;

ll  a[34]= {1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51};
int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    //freopen("test.txt","r",stdin);
   //   freopen("PHONGHAU.INP", "r", stdin);
    //   freopen("PHONGHAU.OUT", "w", stdout);
 ll a, b;
  cin>>a>>b;
  if (a==1||b==1)
  {
      cout <<1;
      return 0;
  }
  ll t=a*b+1 ;
  cout <<t/2;

}


Measured memory_bytes: 256
def main():
    cs = [list(map(int, input().split())) for _ in range(3)]
    if cs[0][0] - cs[0][1] == cs[1][0] - cs[1][1] == cs[2][0] - cs[2][1] \
            and cs[0][0] - cs[0][2] == cs[1][0] - cs[1][2] == cs[2][0] - cs[2][2] \
            and cs[0][0] - cs[1][0] == cs[0][1] - cs[1][1] == cs[0][2] - cs[1][2] \
            and cs[0][0] - cs[2][0] == cs[0][1] - cs[2][1] == cs[0][2] - cs[2][2]:
        print('Yes')
    else:
        print('No')


if __name__ == '__main__':
    main()


Measured memory_bytes: 3064
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include <queue>
#include <string>
#include <set>
#define INF 1000000000
#define LLINF 2000000000000000
using namespace std;
#define FOR(i,a,b) for(int i=a;i<b;i++)
#define LOOP(i,N) for(int i=0;i<N;i++)
#define LOOP1(i,N) for(int i=1;i<=N;i++)
typedef pair<int,int> P;
typedef pair<int,pair<int,int> > PP;
#define int long long

signed main(){
	int n;
	cin >> n;
	int a[n+1];
	LOOP(i,n+1) cin >> a[i];
	int b[n];
	LOOP(i,n) cin >> b[i];

	int leftsum = 0;
	int lscore = 0;
	int lmp = 0;
	LOOP(i,n){
		lscore = min(b[i],(a[i]-lmp)<0 ? 0 : a[i]-lmp);
		leftsum += lscore;
		lmp = b[i]-lscore;
		leftsum += min(lmp,a[i+1]);
		cerr << lscore << ":" << lmp << endl;
	}
	int ra[n+1];
	int rb[n+1];
	int rsum = 0;
	int rscore = 0;
	int rmp = 0;
	LOOP(i,n+1){
		ra[i]=a[n-i];
		cerr << ra[i] << ",";
	}cerr << endl;
	LOOP(i,n){
		rb[i]=b[n-i-1];
		cerr << rb[i] << ",";
	}cerr << endl;

	LOOP(i,n){
		rscore = min(rb[i],(ra[i]-rmp)<0 ? 0 : ra[i]-rmp);
		rsum += rscore; cerr << rsum << "/";
		rmp = rb[i]-rscore; cerr << rmp << "/";
		rsum += min(rmp,ra[i+1]);cerr << rsum << "/";
		cerr << rscore << ":" << rmp << endl;
	}
	cerr << leftsum << "*" << rsum << endl;
	cout << max(leftsum,rsum) << endl;
}


Measured memory_bytes: 3328
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
#define _GLIBCXX_DEBUG
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
using namespace std;
using ll = long long;
const int INF = 1001001001;
const int MOD = 1000000007;
typedef long long ll;

template<typename T> void print(const T & v);


int main() {
    string S;
    cin >> S;
    if(S == "SAT"){
        cout << 1 << endl;
    }else if(S == "FRI"){
        cout << 2 << endl;
    }else if(S == "THU"){
        cout << 3 << endl;
    }else if(S == "WED"){
        cout << 4 << endl;
    }else if(S == "TUE"){
        cout << 5 << endl;
    }else if(S == "MON"){
        cout << 6 << endl;
    }else if(S == "SUN"){
        cout << 7 << endl;
    }
    return 0;

}


// Use For Debug
template <typename T>
void print(T const & v){
    for(int i = 0; i < v.size(); i++){
        if(i) cout << " ";
        cout << v[i];
    }
    cout << endl;
}


Measured memory_bytes: 256
import java.util.Arrays;
import java.util.Scanner;
public class Main{

	public static void main(String[] args) {
		Scanner stdIn = new Scanner(System.in);
		
		int[] a = new int[3];
		
		
		for(int i = 0; i < 3; i++) {
			a[i] = stdIn.nextInt();
		}
		
		
		
		Arrays.parallelSort(a);
		int cnt  = a[0]+a[1];
		int k = stdIn.nextInt();
		for(int i = 0; i < k; i++) {
			a[a.length-1]*=2;
		}
		System.out.println(cnt+a[a.length-1]);
		
	}

}


Measured memory_bytes: 21844
n, k = map(int, input().split())
LR = [[*map(int, input().split())] for _ in range(k)]

MOD = 998244353
dp = [0]*n  # [0,n-1]
dp[0] = 1 # init
dp[1] = -1  # for Cumulative sum

for i in range(n): # i:[0,n-1]
    if i > 0: dp[i] += dp[i-1] # Cumulative sum
    for l, r in LR:
        if i+l < n:
            dp[i+l] += dp[i]
            dp[i+l] %= MOD
        if i+r+1 < n:
            dp[i+r+1] -= dp[i]
            dp[i+r+1] %= MOD

print((dp[n-1] + MOD) % MOD)


Measured memory_bytes: 20904
#include "bits/stdc++.h"
using namespace std;

typedef long long ll;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
typedef pair<ll, ll> P;
#define rep(i, n) for(ll i = 0; i < n; i++)
#define REP(i, a, b) for(ll i = a; i <= b; i++)
#define out(x) std::cout << x << '\n'
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define pb push_back
#define sz(x) ((int)(x).size())
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }
ll lcm(ll a, ll b) { ll g = gcd(a, b); return a / g * b; }
const int dx[4] = { 1, 0, -1,  0 };
const int dy[4] = { 0, 1,  0, -1 };
const int INF = INT_MAX / 2;
const ll  inf = LLONG_MAX / 2;
const int mod = 1000000007;
const int MAX_N = 101010;
const long double PI = acos(-1);

int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	cout << fixed << setprecision(10);
	/*------------------------------*/

	int n;
	cin >> n;

	string s[2];
	cin >> s[0] >> s[1];

	ll ans = 1;
	int pre = -1;
	for (int i = 0; i < n; i++) {
		if (s[0][i] != s[1][i]) {
			if (pre == 0) {
				ans *= 2;
				ans %= mod;
			}
			else if (pre == 1) {
				ans *= 3;
				ans %= mod;
			}
			else {
				ans = 6;
				ans %= mod;
			}
			pre = 1;
			i++;
		}
		else {
			if (pre == 0) {
				ans *= 2;
				ans %= mod;
			}
			else if (pre == 1) {
				ans *= 1;
				ans %= mod;
			}
			else {
				ans = 3;
				ans %= mod;
			}
			pre = 0;
		}
	}

	out(ans);

	return 0;
}

Measured memory_bytes: 256
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import accumulate, permutations, combinations, product
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left
from fractions import gcd
from heapq import heappush, heappop
from functools import reduce
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def ZIP(n): return zip(*(MAP() for _ in range(n)))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7

N, K = MAP()
A = LIST()
A.sort(reverse=True)
ans = 0

lim = 10**6  # 必要そうな階乗の限界を入れる
fact = [1] * (lim+1)
fact_inv = [1] * (lim+1)
for n in range(1, lim+1):
    fact[n] = (fact[n-1] * n) % mod
fact_inv[lim] = pow(fact[lim], mod-2, mod)
for n in range(lim, 0, -1):
    fact_inv[n-1] = (n * fact_inv[n]) % mod
def C(n, r):
    return (((fact[n] * fact_inv[r]) % mod) * fact_inv[n-r]) % mod

for i in range(N-K+1):
	ans += A[i] * C(N-i-1, K-1)
	ans %= mod
for i in range(N-K+1):
	ans -= A[N-i-1] * C(N-i-1, K-1)
	ans %= mod

print(ans)


Measured memory_bytes: 92316
#include <cmath>
#include <cstdio>
#include <vector>
#include <iostream>
#include <algorithm>
#include <unordered_set>
#include <cstring>
#include <queue>
#include <map>
#include <set>
#include <stack>
#include <bitset>
using namespace std;
typedef long long ll;
const int maxn = 100005;

string s;
int main() {
#ifdef suiyuan2009
  freopen("in.cpp","r",stdin);
#endif // suiyuan2009
  ll ret=0;
  while(1) {
    int st=(ret==0LL);
    int l=st,r=9,ans=-1;
    while(l<=r) {
      int m=(l+r)>>1;
      printf("? %lld\n",ret*10+m);
      fflush(stdout);
      cin>>s;
      if(s[0]=='Y') {
        ans=m;
        l=m+1;
      } else r=m-1;
    }
    if(ans!=9) {
      ret=ret*10+ans;
    } else {
      printf("? %lld\n",ret*100+st*10);
      fflush(stdout);
      cin>>s;
      if(s[0]=='N') {
        int l=st+1,r=9,ans=-1;
        while(l<=r) {
          int m=(l+r)>>1;
          printf("? %lld\n",ret*100+m*10);
          fflush(stdout);
          cin>>s;
          if(s[0]=='Y') {
            ans=m;
            r=m-1;
          } else l=m+1;
        }
        printf("! %lld\n",ret*10+ans);
        fflush(stdout);
        exit(0);
      } else {
        ll tmp=ret*10+st;
        while(tmp<=100000000000000000L)tmp*=10;
        printf("? %lld\n",tmp);
        fflush(stdout);
        cin>>s;
        if(s[0]=='N') {
          ret=ret*10+9;
        } else {
          printf("! %lld\n",ret*10+st);
          fflush(stdout);
          exit(0);
        }
      }
    }
  }
  return 0;
}


Measured memory_bytes: 692
import sys
input=sys.stdin.readline

def main():
    a,b,c,k = map(int, input().split())
    if a >= k:
        print(k)
    else: # aより多い
        k -= a
        if b >= k:
            print(a)
        else:
            k -= b
            print(a-k)


if __name__=="__main__":
    main()


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

bool is_prime(int x){
    for(int i = 2; i <= sqrt(x); i++){
        if(x % i == 0) return false;
    }
    return true;
}

int main(){
    int x;
    cin >> x;
    for(; ; x++){
        if(is_prime(x) == true){
            cout << x;
            break;
        }
    }
    return 0;
}

Measured memory_bytes: 256
S=input()
K=int(input())
f=0
if(K<=len(S)):
    for s in S[:K]:
        if s!="1":
            break
    else:
        print("1")
        f=1
if f==0:      
    for s in S:
        if(s!="1"):
            print(s)
            break

Measured memory_bytes: 3064
#include<bits/stdc++.h>
using namespace std;
using p = pair<int,long long>;
#define white 0
#define gray 1
#define black 2



int main(){
  int n,q;
  cin >> n >> q;
  auto px = vector<long long>(n,0);
  //auto m  = vector<vector<int>>(n,vector<int>(n,0));
  auto m1  = vector<vector<int> >(n);
  for (int i = 0; i < n-1; i++)
  {
      int a,b;
      cin >> a >> b; 
      //m[a-1][b-1] = 1;
      //m[b-1][a-1] = 1;
      m1[a-1].push_back(b-1);
  }
  
  
  for (int i = 0; i < q; i++)
  {
     int j,count=0;
     cin >> j >> count;
     px[j-1] += count; 
  }
  
  queue<p> que;
  que.push(make_pair(0,px[0])); //point.count
  auto color = vector<int>(n,0);
  color[0] = black;
  
  
  while (!que.empty())
  {
    auto s = que.front();
    que.pop();
    for(auto i : m1[s.first])
    //for (int i = s.first+1; i < n; i++)
    {
       //if(m[s.first][i] == 0 && m[i][s.first] ==0 ) continue;
       if(color[i] !=black){
          color[i] = black;
          px[i] += s.second;
          que.push(make_pair(i,px[i]));
       }
    }

  }
  
	for (int i = 0; i < n; i++)
    {
      cout << px[i] << " ";
    }
  
  
}

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

using namespace std;

int N;
vector<int> graph[200005];
int par[200005];
int clr[200005];
vector<int> lst[3];
int ans[200005];
int cnt[2];

void dfs(int n){
	cnt[clr[n]]++;
	for(int e : graph[n]){
		if(e != par[n]){
			par[e] = n;
			clr[e] = clr[n] ^ 1;
			dfs(e);
		}
	}
}

int main(){
	cin.sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	cin >> N;
	for(int i = 1; i<N; i++){
		int a, b;
		cin >> a >> b;
		graph[a].push_back(b);
		graph[b].push_back(a);
	}
	dfs(1);
	for(int i = 1; i<=N; i++){
		lst[i%3].push_back(i);
	}
	if(cnt[0] < cnt[1]){
		swap(lst[1], lst[2]);
	}
	if(cnt[0] <= N/3){
		for(int i = 1; i<=N; i++){
			if(clr[i] == 0){
				ans[i] = lst[0].back();
				lst[0].pop_back();
			}
			else if(lst[1].size()){
				ans[i] = lst[1].back();
				lst[1].pop_back();
			}
			else if(lst[2].size()){
				ans[i] = lst[2].back();
				lst[2].pop_back();
			}
			else{
				ans[i] = lst[0].back();
				lst[0].pop_back();
			}
		}
	}
	else if(cnt[1] <= N/3){
		for(int i = 1; i<=N; i++){
			if(clr[i] == 1){
				ans[i] = lst[0].back();
				lst[0].pop_back();
			}
			else if(lst[1].size()){
				ans[i] = lst[1].back();
				lst[1].pop_back();
			}
			else if(lst[2].size()){
				ans[i] = lst[2].back();
				lst[2].pop_back();
			}
			else{
				ans[i] = lst[0].back();
				lst[0].pop_back();
			}
		}
	}
	else{
		for(int i = 1; i<=N; i++){
			if(!clr[i]){
				if(lst[1].size()){
					ans[i] = lst[1].back();
					lst[1].pop_back();
				}
				else if(lst[0].size()){
					ans[i] = lst[0].back();
					lst[0].pop_back();
				}
				else{
					while(1);
				}
			}
			else{
				if(lst[2].size()){
					ans[i] = lst[2].back();
					lst[2].pop_back();
				}
				else if(lst[0].size()){
					ans[i] = lst[0].back();
					lst[0].pop_back();
				}		
			}
		}
	}
	for(int i =1 ; i<=N; i++){
		cout << ans[i] << " ";
	}
}

Measured memory_bytes: 20728
#import sys
#import numpy as np
import math
#from fractions import Fraction
import itertools
from collections import deque
from collections import Counter
#import heapq
#from fractions  import gcd
#input=sys.stdin.readline
import bisect
n=int(input())
def factorize(n):
    fct={}
    temp=n
    if temp<4:
        fct[temp]=1
    else:
        e=0
        while temp%2==0:
            temp=temp//2
            e+=1
        if e>0:
            fct[2]=e
    
    for b in range(3,int(n**0.5)+1,2):
        e=0
        while temp%b == 0:
            temp=temp//b
            e+=1
        if e>0:
            fct[b]=e
    if temp!=1:
        fct[temp]=1
    return fct
dic={}
for i in range(2,n+1):
    d=factorize(i)
    for j in d:
        if j not in dic:
            dic[j]=d[j]
        else:
            dic[j]+=d[j]
n2=0
n4=0
n24=0
n14=0
n74=0
for i in dic:
    if dic[i]>=4:
        n4+=1
    if dic[i]>=2:
        n2+=1
    if dic[i]>=14:
        n14+=1
    if dic[i]>=24:
        n24+=1
    if dic[i]>=74:
        n74+=1
ans=((n4*(n4-1))//2)*(n2-2)+((n4-1)*n14)+((n2-1)*n24)+n74
print(ans)

Measured memory_bytes: 66288
#include <iostream>
using namespace std;
int h;
int field[15][5];
int changed[15][5];
int main(){
	while(1){
		cin >> h;
		if(h==0)break;
		int ans=0;
		for(int i=0;i<h;i++){
			for(int j=0;j<5;j++){
				cin >> field[i][j];
			}
		}
		while(1){
			bool ok=true;
			for(int i=0;i<h;i++){
				for(int j=0;j<3;j++){//起点として見るのは3番目までで良い
					if(field[i][j]==field[i][j+1]&&field[i][j]>0){
						int cnt=0;
						int copy=field[i][j];
						while(copy==field[i][j]&&j<5){
							cnt++;
							j++;
						}
						if(cnt>2){
							j-=cnt;
							for(int k=j;k<5;k++){
								if(copy==field[i][k]){
									changed[i][k]=1;
								}
								else break;
							}
							j+=cnt;
						}
						j--;
					}
				}
			}
			for(int i=0;i<h;i++){
				for(int j=0;j<5;j++){
					if(changed[i][j]==1){
						ok=false;
						ans+=field[i][j];
						for(int k=i;k>0;k--){
							field[k][j]=(field[k-1][j]>0?field[k-1][j]:0);
						}
						field[0][j]=0;
					}
				}
			}
			for(int i=0;i<h;i++){
				for(int j=0;j<5;j++){
					changed[i][j]=0;
				}
			}
			if(ok)break;
		}
		cout << ans << endl;
	}
	return 0;
}


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

#define int long long
#define negINF -999999999999999

// #include "debug.cpp"

int n, perm[6000], value[6000];

int check(int ind, int k){
	int i, j, ans = 0;

	int cycleValue = 0, cycleLength = 1;
	int oriind = ind;
	cycleValue += value[perm[ind]];
	ind = perm[ind];

	int ma = cycleValue;
	while(ind != oriind){
		if(cycleLength == k)
			break;
		cycleValue += value[perm[ind]];
		ind = perm[ind];
		ma = max(ma, cycleValue);
		cycleLength++;
	}


	if(cycleLength == k)
		return ma;

	// debug(cycleValue, cycleLength, k);

	if(cycleValue > 0){
		ans += cycleValue*(k/cycleLength - 1);
		k %= cycleLength;
		k += cycleLength;
		// debug(ans);
// 
		int ma = negINF, temp = 0;
		ind = oriind;
		while(k != 0){
			// debug(ma, temp);
			temp += value[perm[ind]];
			ma = max(ma, temp);
			ind = perm[ind];
			k--;
		}

		return ans+ma;
	}

	return ma;

}

int32_t main(){
	int i, j, k;
	cin >> n >> k;
	for(i=0; i<n; i++){
		cin >> perm[i];
		perm[i]--;
	}
	for(i=0; i<n; i++){
		cin >> value[i];
	}

	int ans = -9999999999999;
	for(i=0; i<n; i++){
		int lol = check(i, k);
		// debug(lol, i);
		ans = max(ans, check(i, k));
	}

	cout << ans << "\n";

	
}

Measured memory_bytes: 3708
#include <bits/stdc++.h>
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define RFOR(i,a,b) for(int i=(b) - 1;i>=(a);i--)
#define REP(i,n) for(int i=0;i<(n);i++)
#define RREP(i,n) for(int i=n-1;i>=0;i--)

#define PB push_back
#define INF INT_MAX/3
#define ALL(a) (a).begin(),(a).end()
#define RALL(a) (a).rbegin(),(a).rend()
#define CLR(a) memset(a,0,sizeof(a))

typedef long long int ll;

using namespace std;

int main(){
    vector< pair<double,string> > num;
    double d[] = {0.5,0.25,0.125,0.0625};
    REP(i,2){
	REP(j,2){
	    REP(k,2){
		REP(l,2){
		    num.PB( pair<double,string>(i*d[0] + j*d[1] + k*d[2] + l*d[3],to_string(i)+to_string(j)+to_string(k)+to_string(l)));
		}
	    }
	}
    }


    while(true){
	double n;
	cin >> n;
	if(n<0) break;
	int m = (int)(n);
	n -= (double)(m);
	if((m&(0xff00))==0){
	    bool flg = false;
	    REP(i,num.size()){
		if(n == num[i].first) {
		    flg = true;
		    stack<int> ans;
		    while(m>0){
			ans.push(m%2);
			m /= 2;
		    }
		    REP(i,8-ans.size()){
			cout << 0;
		    }
		    while(!ans.empty()){
			cout << ans.top();
			ans.pop();
		    }
		    cout << "." + num[i].second << endl;
		    break;
		}
	    }
	    if(!flg) cout << "NA" << endl;
	}else{
	    cout <<"NA"<<endl;
	}
    }
    return 0;
}

Measured memory_bytes: 3180
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time

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

def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def S(): return input()


def main():
    a,b = LI()

    return (a+b)%24



print(main())


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


#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

#define error(args...) { string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); stringstream _ss(_s); istream_iterator<string> _it(_ss); err(_it, args); }
#define all(x) x.begin(),x.end()
#define sz(x) (int)x.size()


using namespace std;
using namespace __gnu_pbds;

template<class T> using ordered_set = tree<T,null_type,less<T>,rb_tree_tag,tree_order_statistics_node_update>;
using ll  = long long;

using point = complex<double>;


void err(istream_iterator<string> it) {cerr << endl;}
template<typename T, typename... Args>void err(istream_iterator<string> it, T a, Args... args) {cerr << *it << " = " << a << endl;err(++it, args...);}




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

const double EPS = 1e-9;
const long long mod = 1e9 + 7;
const long long INF = 1e18;
const int N = 3e5 + 5;




int main()
{
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    string str;
    cin >> str;
    int ans1 = 0 ,ans2 = 0;
    for(int i = 0; i < str.size(); ++i){
        if( (str[i]-'0') % 2 != i %2 )ans1++;
    }
    for(int i = 0; i < str.size(); ++i){
        if((str[i]-'0') % 2 == i % 2)ans2++;
    }
    cout << min(ans1,ans2) << '\n';
    return 0;
}


Measured memory_bytes: 3748
#
# File    : D.rb
# Author  : Kazune Takahashi
# Created : 2018-6-23 21:14:41
# Powered by Visual Studio Code
#

k = gets.to_i

def calc(num)
  s = 0
  num.to_s.chars{|c|
    s += c.to_i
  }
  return num / s.to_f
end

def f(num)
  ary = [[calc(num), num]]
  str = num.to_s
  for i in 0...str.size do
    c = str[i].to_i
    for j in (c + 1)..9 do
      str2 = str.dup
      str2[i] = j.to_s
      for k in (i + 1)...str.size do
        str2[k] = "9"
      end
      ary << [calc(str2.to_i), str2.to_i]
    end
  end
  return ary.min[1]
end

ans = 1
k.times{
  puts ans
  ans = f(ans + 1)
}

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

vector<int> input(int N){
    int i;
    vector<int> output(N);
    for(i=0;i<N;i++)cin>>output[i];
    return output;
}

int main(){
    int i;
    int N;
    int same_streak=0;
    int result=0;
    vector<int>P;
    cin>>N;
    P=input(N);
    vector<int>A(N);
    for(i=1;i<=N;i++)A[i-1]=i;

    for(i=0;i<N;i++){
        if(A[i]==P[i]){
            same_streak+=1;
        }else{
            if(same_streak==1){
                result+=1;
            }else if(same_streak>1){
                result+=same_streak/2+same_streak%2;
            }
            same_streak=0;
        }
    }
    if(same_streak==1){
        result+=1;
    }else if(same_streak>1){
        result+=same_streak/2+same_streak%2;
    }

    cout<<result<<endl;
}

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

#define ll long long
#define sp ios_base::sync_with_stdio(false),cin.tie(NULL),cout.tie(NULL)
#define cps CLOCKS_PER_SEC
#define mod (ll)1000000007
#define f first
#define s second
#define debug1(x) cerr<<x<<"\n"
#define debug2(x,y) cerr<<x<<" "<<y<<"\n"
#define debug3(x,y,z) cerr<<x<<" "<<y<<" "<<z<<"\n"
#define nl cerr<<"\n";
#define pq priority_queue
#define inf 0x3f3f3f3f
#define test cerr<<"abcd\n";
#define pi pair<int,int>
#define pii pair<int,pi>
#define pb push_back
#define mxn 200005
ll dp[1001][1001];
char a[1001][1001];

int main() {
sp;
int n,m;
cin>>n>>m;
for(int i=1; i<=n; ++i)
    for(int j=1; j<=m; ++j)cin>>a[i][j];
dp[1][1]=1;
for(int i=1; i<=n; ++i)
for(int j=1; j<=m; ++j){
    if(i==1&&j==1)continue;
    if(a[i][j]=='#')continue;
    dp[i][j]=dp[i-1][j]+dp[i][j-1];
    dp[i][j]%=mod;
}
cout<<dp[n][m];
return 0;}


Measured memory_bytes: 9088
#include <cstdio>
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <queue>
#include <map>
using namespace std;

int i,j,k;
map<vector<vector<int> > , int> memo;

bool is_goal(vector<vector<int> > inans){
	vector<vector<int> > ans(2, vector<int>(4));	//初期化必須
	for(i=0; i<8; i++){
			int x = i % 4;
			int y = i / 4;
			ans[y][x] = i;
	}
	//cout << "goal実行" <<endl;
	if(inans == ans)	return true;
	return false;
}
/*
void checker(vector<vector<int>> check, string str, int i){
	cout << str << " , " << i << endl;
	for(i=0; i<8; i++){
			int x = i % 4;
			int y = i / 4;
			cout << "check[" << y << "][" << x << "]=" << check[y][x] <<endl;
	}
	cout << " " << endl;
}
*/

int BFS(vector<vector<int> > inans){

	memo[inans] = 0;
	queue<vector<vector<int> > > q;
	q.push(inans);

	while( !q.empty() ){
		vector<vector<int> > now = q.front();
		q.pop();
	//					checker(now,"now",500);
	//	if(is_goal(now) == true)	return memo[now];

		int nowcost = memo[now];
	//					cout << "nowcost = " <<nowcost <<endl;

		//vector<vector<int>> next = now;

		for(i=0; i<8; i++){
			int x = i % 4;
			int y = i / 4;
			//left
			if(x != 0 && now[y][x]==0){
				swap(now[y][x-1] , now[y][x]);
				while( !memo.count(now) ){
					memo[now] = nowcost + 1;
					q.push(now);
				}
	//			checker(now,"left",i);
				swap(now[y][x-1] , now[y][x]);
			}
			//down
			if(y != 1 && now[y][x]==0){
				swap(now[y+1][x] , now[y][x]);
				while( !memo.count(now) ){
					memo[now] = nowcost + 1;
					q.push(now);
				}
	//			checker(now,"down",i);
				swap(now[y+1][x] , now[y][x]);
			}
			//right
			if(x != 3 && now[y][x]==0){
				swap(now[y][x+1] , now[y][x]);
				while( !memo.count(now) ){
					memo[now] = nowcost + 1;
					q.push(now);
				}
	//			checker(now,"right",i);
				swap(now[y][x+1] , now[y][x]);
			}
			//up
			if(y != 0 && now[y][x]==0){
				swap(now[y-1][x] , now[y][x]);
				while( !memo.count(now) ){
					memo[now] = nowcost + 1;
					q.push(now);
				}
	//			checker(now,"up",i);
				swap(now[y-1][x] , now[y][x]);
			}
		} //cout << q.size() <<endl;
	}
	return -1;
}



int main()
{
	    vector<vector<int> > a(2, vector<int>(4)); 
        for(i = 0; i < 8; i++){ 
            int xx = i % 4, yy = i / 4; 
            a[yy][xx] = i; 
        } 
        // 幅優先探索 (最初にすべての解を求めておく) 
        int ans = BFS(a); 
		
		


	vector<vector<int> > in(2, vector<int>(4));	//初期化しないとエラー出る
	while(cin >> in[0][0]){
		for(i=1; i<8; i++){
			int x = i % 4;
			int y = i / 4;
			cin >> in[y][x];
		}
	//	checker(in,"first",100);
		cout << memo[in] << endl;
	}
}

Measured memory_bytes: 5352
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
ll n, a[100009], dp[100009];
ll f(int i) {
	if (i > n)return 1e9;
	else if (i == n)return 0;
	if (dp[i] != -1)return dp[i];
	return dp[i] = min(f(i + 1) + abs(a[i] - a[i + 1]), f(i + 2) + abs(a[i] - a[i + 2]));
}
int main() {
	memset(dp, -1, sizeof dp);
	cin >> n;
	for (int i = 1; i <= n; i++) cin >> a[i];
	cout << f(1) << endl;
}

Measured memory_bytes: 3328