akhauriyash/Code-Regression huggingface dataset:
#include<stdio.h>
#include<math.h>
#include<stdlib.h>
#include<string.h>

// return track_count;
int NeedTrack(int max,int obje[],int n){
	int re = 0;
	int val = 0;
	for(int i = 0; i < n; i++){
		if(max < obje[i]){ //本来なら載せれないので
			return 10000000;
		}else if(val + obje[i] <= max){
			val += obje[i];
		}else{
			re++;
			val = obje[i];
		}
	}
	return re+1;
}




int main() {
	int n,k;
	scanf("%d",&n);
	scanf("%d",&k);
	
	int list[n];
	int max = 0;
	
	//まずは代入していく。
	for(int i = 0; i < n; i++){
		scanf("%d",&list[i]);
		if(max < list[i]){
			max = list[i];
		}
	}
	
	int left = 0;
	int right = max * n;
	int mid;
	
	int retu = -1;
	for(;left <= right;){
		mid = (left + right) / 2;
		int ch = NeedTrack(mid,list,n);
//		printf("%d\t%d\t%d\t%d\n",left,mid,right,ch);
		if(left == right){
			if(ch <= k){
				retu = mid;
			}
			break;
		}
		if(ch < k){
			right = mid;
		}else if(ch > k){
			left = mid + 1;
		}else{
			if(mid == retu){
//				printf("break_b\n");
				break;
			}else{
				right = mid;
				retu = mid;
			}
		}
		
	}
	
	printf("%d\n",retu);
	return 0;
}






Measured memory_bytes: 2228
class Array
	def accum
		inject([0]){|a, x| a + [a[-1] + x]}[1..-1]
	end
end

m, n = gets.split.map &:to_i
k = gets.to_i

a = (1..m).map{ gets.chomp.split("") }

d = m*n+1

orig = a.map{|r| r.map{|c|
	case c
		when ?J; 1
		when ?O; d
		when ?I; d * d
	end
}}

orig.each{|r|
	(1..n-1).each{|j|
		r[j] += r[j-1]
	}
	r.unshift 0
}

(1..m-1).each{|i|
	(1..n).each{|j|
		orig[i][j] += orig[i-1][j]
	}
}
orig.unshift([0] * (n+1))

k.times{
	y1, x1, y2, x2 = gets.split.map &:to_i
	x = orig[y2][x2] - orig[y1-1][x2] - orig[y2][x1-1] + orig[y1-1][x1-1]
	j = x % d
	x /= d
	o = x % d
	i = x / d
	puts "#{j} #{o} #{i}"
}

Measured memory_bytes: 171584
# include <bits/stdc++.h>
#define INF 1e9
using namespace std;

int main(){

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

  H[0]--;
  string ans = "Yes";
  for(int i=1; i < N; i++){
    if(H[i-1] > H[i]){
      ans = "No";
      break;
    } else if (H[i-1] < H[i]){
      H[i]--;
    }
  }

  cout << ans << endl;

}


Measured memory_bytes: 640
#include <stdio.h>
#include <stdlib.h>
int asc(const void *n, const void *m){
    return *(long long*) n-*(long long*)m;
}
long long gcd(long long x,long long y){
    if(x%y==0) return y;
    else return gcd(y,x%y);
}
int main(void){
    long long n,i,j;
    scanf("%lld",&n);
    long long a[n];
    for(i=0;i<n;i++) scanf("%lld",&a[i]);
    qsort(a,n,sizeof(a[0]),asc);
    long long min = a[0];
    for(i=1;i<n;i++) min = gcd(min,a[i]);
    if(min==0) printf("%lld",a[0]);
    else printf("%lld",min);
}

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

int main() {
  int a, b;
  cin >> a >> b;
  for (int i = 1; i <= 1000; ++i) {
    if (floor(i * 0.08) == a && floor(i * 0.1) == b) {
      cout << i << endl;
      return 0;
    }
  }
  cout << -1 << endl;
}


Measured memory_bytes: 256
using System;
using System.Linq;
using System.Collections.Generic;
using System.Numerics;

namespace c
{
    class Program
    {
        static void Main(string[] args)
        {
            var _ = Console.ReadLine().Split();
            var n = BigInteger.Parse(_[0]);
            var k = BigInteger.Parse(_[1]);

            if(n % k == 0){
                Console.WriteLine(0);
            }else if(n >= k){
                var t = n % k;
                if(k - t > t){
                    Console.WriteLine(t);
                }else{
                    Console.WriteLine(k - t);
                }
            }else{
                if(k - n > n){
                    Console.WriteLine(n);
                }else{
                    Console.WriteLine(k - n);
                }
            }
        }
    }
}


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

int main() {
  int A;
  cin >> A;
  int a=A%10;
  int b=A/10%10;
  int c=A/100%10;
  int d=A/1000;
  if (b==c){
    if(a==b||c==d)cout<<"Yes"<<endl;
    else cout<<"No"<<endl;
  }
  else cout<<"No"<<endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define rep(i, n) for (ll i = 0; i < (ll)n; ++i)
ll dx[4] = { 0, 1, 0, -1 };
ll dy[4] = { 1, 0, -1, 0 };
static const ll INF = 1 << 21;
static const ll MOD = 1e9 + 7;
static const int MAX = 100;
static const int WHITE = 0;
static const int GRAY = 1;
static const int BLACK = 2;

int n, M[MAX][MAX];

void dijkstra()
{
    int minv;
    int d[MAX]; // d[v]: Sからvに行ける最小コスト
    int color[MAX];

    rep(i, n)
    {
        d[i] = INF;
        color[i] = WHITE;
    }

    d[0] = 0;
    color[0] = GRAY;

    while (1) {
        minv = INF;
        int u = -1;
        rep(i, n)
        {
            if (d[i] < minv && color[i] != BLACK) {
                u = i;
                minv = d[i];
            }
        }
        if (u == -1) {
            break;
        }
        color[u] = BLACK;
        rep(v, n)
        {
            if (color[v] != BLACK && M[u][v] != INF) {
                if (d[u] + M[u][v] < d[v]) {
                    d[v] = d[u] + M[u][v];
                    color[v] = GRAY;
                }
            }
        }
    }

    rep(i, n)
    {
        cout << i << " " << (d[i] == INF ? -1 : d[i]) << endl;
    }
}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cin >> n;

    rep(i, n)
    {
        rep(j, n)
        {
            M[i][j] = INF;
        }
    }

    int k, c, u, v;
    rep(i, n)
    {
        cin >> u >> k;
        rep(j, k)
        {
            cin >> v >> c;
            M[u][v] = c;
        }
    }

    dijkstra();

    return 0;
}


Measured memory_bytes: 3224
def main():
    N = int(input())
    A = list(map(int, input().split()))

    if N == 2:
        print(max(A[0]+A[1], (-A[0])+(-A[1])))
        return

    a_sum, a1, a2 = 0, A[0], A[1]
    b_sum, b1, b2 = 0, -A[0], -A[1]
    for i in range(2, N):
        #print(a_sum, a1, a2)
        #print(b_sum, b1, b2)
        #print(A[i])
        

        if (a_sum + a1 + a2 + A[i]) > (b_sum + b1 + b2 + A[i]):
            new_a_sum = a_sum + a1
            new_a1 = a2
            new_a2 = A[i]
        else:
            new_a_sum = b_sum + b1
            new_a1 = b2
            new_a2 = A[i]

        if (a_sum + a1 - a2 - A[i]) > (b_sum + b1 - b2 - A[i]):
            new_b_sum = a_sum + a1
            new_b1 = -a2
            new_b2 = -A[i]
        else:
            new_b_sum = b_sum + b1
            new_b1 = -b2
            new_b2 = -A[i]

        a_sum, a1, a2 = new_a_sum, new_a1, new_a2
        b_sum, b1, b2 = new_b_sum, new_b1, new_b2
        
    print(max(a_sum+a1+a2, b_sum+b1+b2))

main()


Measured memory_bytes: 14480
#include<bits/stdc++.h>
#define ll long long int
#define pb push_back
#define mp make_pair
using namespace std;
main()
{
    int a,b,c;
    map<int,int>p;
    cin>>a>>b>>c;
    p[a]++;p[b]++;p[c]++;
    if(p[5]==2&&p[7]==1)
        cout<<"YES";
    else
        cout<<"NO";
}


Measured memory_bytes: 3632
#include <iostream>
    #include <cstdio>
    #include <algorithm>
    using namespace std;
     
    const int N = 105;
     
    int n, ind[N], p[N];
    string s[N];
     
    int main()
    {
      	cin >> n;
      	for (int i = 1; i <= n; i++)
        {
          	cin >> s[i] >> p[i];
          	ind[i] = i;
        }
      	sort(ind + 1, ind + n + 1, [](const int &x, const int &y) {
          	return s[x] < s[y] || (s[x] == s[y] && p[x] > p[y]);
        });
      	for (int i = 1; i <= n; i++)
          	cout << ind[i] << '\n';
    }

Measured memory_bytes: 256
vector = ((0, -1), (1, 0), (0, 1), (-1, 0))

def make_guruguru(d):
  lst = [["#"] * (d + 4)]
  for _ in range(d + 2):
    lst.append(["#"] + [" "] * (d + 2) + ["#"])
  lst.append(["#"] * (d + 4))
  x, y = 2, d + 1
  lst[y][x] = "#"
  direct = 0
  vx, vy = vector[0]
  cnt = 1
  while True:
    while lst[y + vy * 2][x + vx * 2] == " ":
      lst[y + vy][x + vx] = "#"
      y += vy
      x += vx
      cnt += 1
    if cnt <= 1:
      break
    direct = (direct + 1) % 4
    vx, vy = vector[direct]
    cnt = 0
  for y in range(2, d + 2):
    print("".join(lst[y][2:-2]))

n = int(input())
make_guruguru(int(input()))
for _ in range(n - 1):
  print()
  make_guruguru(int(input()))


Measured memory_bytes: 5700
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner scanner = new Scanner(System.in);
		int a = scanner.nextInt();
		int[] x = new int[a];
		for (int i = 0; i < a; i++) {
			x[i] = scanner.nextInt();
		}
		int[] y = new int[a];
		for (int i = 0; i < a; i++) {
			y[i] = scanner.nextInt();
		}
		double[] p = new double[4];
		for (int i = 0; i < a; i++) {
			double p0 = Math.abs(x[i] - y[i]);
			p[1] += Math.pow(p0, 2);
			p[2] += Math.pow(p0, 3);
			p[3] = Math.max(p[3], p0);
			p[0] += p0;
		}
		p[1] = Math.sqrt(p[1]);
		p[2] = Math.cbrt(p[2]);
		for (double aa : p)
			System.out.println(aa);
	}
}

Measured memory_bytes: 20396
#include<bits/stdc++.h>
using namespace std;
int main()
{
    string s,t;
    int n = 0;
    int len;
    cin >> len ;
    cin >> s >> t;
    n = len;
    bool tru=false;
    for(int i=0;i<len;i++){
        for(int j=0;(i+j)<len;j++){
            tru = true;
            //cout << s[i+j] << " " << t[j] << endl;
            if(s[i+j]!=t[j]){
                tru = false;
                break;
            }
        }
        if(tru){
            n=i;
            break;
        }
    }
    cout << len+n << endl;
    return 0;
}


Measured memory_bytes: 256
#include<cstdio>
#include<cmath>
#include<climits>
#include<algorithm>
#include<sstream>
#include<iostream>
#include<string>
#include<queue>
#include<stack>
#include<set>
#include<list>
#include<map>
#include<vector>

using namespace std;


#define rep(i,n) for(int i=0; i<n; i++)
#define rept(i,a,b) for(int i=a; i<b; i++)
#define ll long long
#define MOD 1000000007

#define IMIN INT_MIN;
#define IMAX INT_MAX;


int main(){
    int A, B;
    cin >> A >> B;
    rep(i, 100000) {
        if(i * 8 / 100 == A && i / 10 == B) {
            cout << i << endl;
            exit(0);
        }
    }
    cout << -1 << endl;


	return 0;
}


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

int main()
{
    string n;
    cin >> n;
    int jdg = 0;
    for (int i = 0; i < n.size(); i++)
    {
        jdg += n.at(i) - '0';
    }
    if (jdg % 9 == 0)
    {
        puts("Yes");
    }
    else
    {
        puts("No");
    }
}

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

int main(){
    vector <int> A;;
    int tmp, cnt = 0;

    while(cin >> tmp){
        A.push_back(tmp);
    }
    sort(A.begin(), A.end());
    if((A[1] - A[0])%2 == 0){
        cnt += (A[1] - A[0])/2;
    }else{
        A[1] += 1;
        A[2] += 1;
        cnt += (A[1] - A[0])/2 + 1;
    }
    cnt += A[2] - A[1];

    cout << cnt << endl;

    return 0;

}


Measured memory_bytes: 256
// Package main provides
//
// File:  d.go
// Author: ymiyamoto
//
// Created on Sat Dec  1 14:35:30 2018
//
package main

import "fmt"

var n, m int

func isPrime(a int) bool {
	for i := 2; i*i < a; i++ {
		if a%i == 0 {
			return false
		}
	}
	return true
}

func main() {
	fmt.Scan(&n, &m)

	if isPrime(m) {
		fmt.Println(1)
		return
	}

	for i := n; i <= m/2; i++ {
		if m%i == 0 {
			fmt.Println(m / i)
			return
		}
	}
	fmt.Println(1)
}


Measured memory_bytes: 512
#include <stdio.h>

  int main(void)
{
  int W,H,x,y,r;
   scanf("%d %d %d %d %d", &W, &H, &x, &y, &r);

 if(x >= r &&  x <= W-r && y >= r && y <= H-r){
   printf("Yes\n");
 } else {
   printf("No\n");
}

  return 0;
}

Measured memory_bytes: 584
#include <bits/stdc++.h>
using namespace std;
int main(){
	string s,c,beg[4]={"SS","SW","WS","WW"};
	int i,j,n;
	cin>>n;
	cin>>s;
	for(j=0;j<4;j++)
	{
		c=beg[j];
		for(i=1;i<n-1;i++)
		{
			if(c[i]=='S')
			{
				if(s[i]=='o')
					c+=c[i-1];
				else
				{
					if(c[i-1]=='S')
						c+="W";
					else
						c+="S";
				}
			}
			else
			{
				if(s[i]=='x')
					c+=c[i-1];
				else
				{
					if(c[i-1]=='S')
						c+="W";
					else
						c+="S";
				}
			}
		}
		if(c[0]=='S')
		{
			if(s[0]=='o')
			{
				if(c[1]!=c[n-1])
					continue;
			}
			else
				if(c[1]==c[n-1])
					continue;
		} 
		else
		{
			if(s[0]=='x')
			{
				if(c[1]!=c[n-1])
					continue;
			}
			else
				if(c[1]==c[n-1])
					continue;
		}
		if(c[n-1]=='S')
		{
			if(s[n-1]=='o')
			{
				if(c[0]!=c[n-2])
					continue;
			}
			else
				if(c[0]==c[n-2])
					continue;
		} 
		else
		{
			if(s[n-1]=='x')
			{
				if(c[0]!=c[n-2])
					continue;
			}
			else
				if(c[0]==c[n-2])
					continue;
		}
		cout<<c<<endl;
		return 0;
	}
	cout<<"-1"<<endl;
	return 0;
}

Measured memory_bytes: 640
from sys import stdin
input = stdin.readline

a,b,c = map(int, input().split())
k = int(input())

cnt = 0

while a >= b:
    b *= 2
    cnt += 1

while b >= c:
    c *= 2
    cnt += 1

if(cnt <= k):
    print("Yes")
else:
    print("No")

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

void fnInput(vector<int>& rvnPodr, vector<int>& rvnIodrSeq)
{
  int nMaxSiz;

  cin >> nMaxSiz;
  rvnPodr.resize(nMaxSiz + 1);
  rvnIodrSeq.resize(nMaxSiz + 1);

  for (int i = 1; i < nMaxSiz + 1; i++)
    cin >> rvnPodr[i];

  int nNode;
  for (int i = 1; i < nMaxSiz + 1; i++)
  {
    cin >> nNode;
    rvnIodrSeq[nNode] = i;
  }
}

void fnPostOrder(const vector<int>& cnrvnPodr, const vector<int>& cnrvnIodrSeq, int nLeft, int nRight)
{
  static int stnx = 1;
  static int stnPrt = 0;

  if (nLeft == nRight) return;

  int nNode = cnrvnPodr[stnx++];
  int nMid = cnrvnIodrSeq[nNode];

  fnPostOrder(cnrvnPodr, cnrvnIodrSeq, nLeft, nMid);
  fnPostOrder(cnrvnPodr, cnrvnIodrSeq, nMid + 1, nRight);

  if (stnPrt++) cout << " ";
  cout << nNode;
}

int main()
{
  cin.tie(0);
  ios::sync_with_stdio(false);
  vector<int> vnPodr, vnIodrSeq;
  fnInput(vnPodr, vnIodrSeq);

  fnPostOrder(vnPodr, vnIodrSeq, 1, vnPodr.size());
  cout << endl;
  return 0;
}

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

const int N = 1e6;

bool isp[N];

void prime()
{
	isp[0]=isp[1]=true;
	for(int i=2;i*i<=N;i++)
	{
		if(isp[i]==false)
		{
			for(int j=i*2;j<N;j+=i)
				isp[j]=true;
		}
	}
}

int main()
{
	ios_base::sync_with_stdio(false);
	prime();
	
		
	vector<int> f;
	for(int i=2;i<N;i++)
	{
		if(!isp[i])
			f.push_back(i);
	}
	int x;
	cin>>x;
	int ind =  lower_bound(f.begin(),f.end(),x) - f.begin();
	cout<<f[ind];
}

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

using namespace std;
typedef long long ll;
#define MOD 1000000007
template<typename T1,typename T2> inline void chmin(T1 &a,T2 b){if(a>b) a=b;}
template<typename T1,typename T2> inline void chmax(T1 &a,T2 b){if(a<b) a=b;}

int n;
int A[20];
int X[20][20];
int Y[20][20];

int counter(int x) {
    if(x == 0) return 0;
    return counter(x >> 1) + (x & 1);
}

int main() {
    cin >> n;

    for(int i=0; i<n; i++) {
        cin >> A[i];
        for(int j=0; j<A[i]; j++) {
            cin >> X[i][j] >> Y[i][j];
            X[i][j]--;
        }
    }

    int ans;
    for(int bits=1; bits<(1<<n); bits++) {
        bool flg = true;

        for(int i=0; i<n; i++) {
            if(!(bits & (1 << i))) continue;
            for(int j=0; j<A[i]; j++)
                if((bits >> X[i][j] & 1) ^ Y[i][j]) flg = false;
        }

        if(flg) ans = max(ans, counter(bits));
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256
N, M = map(int, input().split())

cnt = [0]*M
W = [0]*N
for i in range(N):
    W[i] = list(map(int, input().split()))
    for k in range(1, W[i][0]+1):
        cnt[W[i][k]-1] += 1
ans = cnt.count(N)
print(ans)

Measured memory_bytes: 3060
#include <cstdio>
#include <cstring>
using namespace std;

char alphabet;
char board[4][4];
int dx[4], dy[4];
int count;

void attempt(int y, int x)
{
  if (y == 4) {
    ++count;
  } else if (board[y][x]) {
    if (x == 3)
      attempt(y+1, 0);
    else
      attempt(y, x+1);
  } else {
    board[y][x] = alphabet;
    for (int i = 0; i < 4; ++i) {
      int ny = y + dy[i];
      int nx = x + dx[i];
      if (ny < 0 || ny >= 4 || nx < 0 || nx >= 4 || board[ny][nx])
        continue;
      board[ny][nx] = alphabet;
      ++alphabet;
      if (x == 3)
        attempt(y+1, 0);
      else
        attempt(y, x+1);
      --alphabet;
      board[ny][nx] = 0;
    }
    board[y][x] = 0;
  }
}

int main()
{
  while (scanf("%d%d%d%d%d%d%d%d", dx, dy, dx+1, dy+1, dx+2, dy+2, dx+3, dy+3) == 8) {
    memset(board, 0, sizeof(board));
    alphabet = 'A';
    count = 0;
    attempt(0, 0);
    printf("%d\n", count);
  }
}

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

int main(){
  vector<int> N(3);
  int count_5 = 0, count_7 = 0;
  for(int i = 0; i < 3; i++){
    cin >> N.at(i);
    if(N.at(i) == 5) count_5++;
    else if(N.at(i) == 7) count_7++;
  }
  
  if(count_5 == 2 && count_7 == 1) cout << "YES" << endl;
  else cout << "NO" << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define rep(i,N) for(int i=0;i<(N);i++)
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
using namespace std;
const long long MOD = 1e9 + 7;
const long long INF = 1e12;
const int inf = 1e9;
const int mod = 1e9+7;
typedef long long ll;
typedef pair<ll,int> P;
typedef set<int> S;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
ll gcd(ll a, ll b){
    if(a < b)  swap(a,b);
    if(a%b==0) return b;
    else return gcd(b,a%b);
}
ll ngcd(vector<ll> a){
    ll res;
    res = a[0];
    for(int i = 1; i < a.size() && res != 1; i++) {
        res = gcd(a[i], res);
    }
    return res;
}
ll lcm(ll a, ll b) {
    return a / gcd(a, b) * b;
}
ll nlcm(vector<ll> numbers) {
    ll res;
    res = numbers[0];
    for (ll i = 1; i < numbers.size(); i++) {
        res = lcm(res, numbers[i]);
    }
    return res;
}
ll nCr(ll n, ll r){
    ll a = 1;
    ll b = 1;
    rep(i,r){
        a *= n - i;
        b *= r - i;
        ll c = gcd(a,b);
        a /= c;
        b /= c;
    }
    return a/b;
}
ll max(ll a,ll b){
    if(a > b) return a;
    else return b;
}
int main(){
    cout << fixed << setprecision(10);
    int n,p;
    cin >> n >> p;
    int a = 0, b = 0;
    rep(i,n){
        int x;
        cin >> x;
        if(x%2 == 0) a++;
        else b++;
    }
    ll ans = 0;
    if(p == 0){
        rep(i,b+1){
            if(i%2 != 0) ans += nCr(b,i);
        }
        cout << max(ans,1LL) * (1LL<<a) << endl;
    }else{
        rep(i,b+1){
            if(i%2 == 0) ans += nCr(b,i);
        }
        if(b == 0){
            cout << 0 << endl;
            return 0;
        }
        cout << ll(max(ans,1LL)) * (1LL<<a) << endl;
    }
    return 0;
}

Measured memory_bytes: 3644
import java.util.Scanner;

public class Main {

  public static void main(String[] args) {

    Scanner scan = new Scanner(System.in);

    int a = scan.nextInt();
    int b = scan.nextInt();
    int c = scan.nextInt();
    int x = scan.nextInt();
    int y = scan.nextInt();

    long min = Long.MAX_VALUE;

    for (int i = 0; i <= Math.pow(10, 5); i++) {
      min = Math.min(min, 2 * c * i + Math.max(0, x - i) * a + Math.max(0, y - i) * b);
    }
    
    System.out.println(min);

  }

}

Measured memory_bytes: 23252
#include <iostream> 
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define mk make_pair
#define MAX 1000001
ll prime[MAX];
#define FAST           ios_base::sync_with_stdio(false); cin.tie(NULL);cout.tie(NULL);
#define mod 1000000007
#define gcd __gcd
// ll rec(vector<vector<ll> >& dp,vector<ll>& arr,int n,int i,int k,int w)
// {
//   ll ans=0;
//   if(i>=n)
//     return 0;

//   if(dp[i][k]!=-1)
//     return dp[i][k];


//   if(k!=0)
//   ans=max(rec(dp,arr,n,i+1,w,w),arr[i]+rec(dp,arr,n,i+1,k-1,w));
//   else
//   ans=max(rec(dp,arr,n,i+1,k,w),rec(dp,arr,n,i+1,w,w));

//   return dp[i][k]=ans;

// }

//ll t[400008];
// void build(vector<ll>& a, int v, int tl, int tr) {
//     if (tl == tr) {
//         t[v] = a[tl];
//     } else {
//         int tm = (tl + tr) / 2;
//         build(a, v*2, tl, tm);
//         build(a, v*2+1, tm+1, tr);
//         t[v] = max(t[v*2] ,t[v*2+1]);
//     }
// }

// ll maxi(int v, int tl, int tr, int l, int r) {
//     if (l > r) 
//         return 0;
//     if (l == tl && r == tr) {
//         return t[v];
//     }
//     int tm = (tl + tr) / 2;
//     return max(maxi(v*2, tl, tm, l, min(r, tm)) ,maxi(v*2+1, tm+1, tr, max(l, tm+1), r));
// }



// void update(int v, int tl, int tr, int pos, ll new_val) {
//     if (tl == tr) {
//         t[v] = new_val;
//     } else {
//         int tm = (tl + tr) / 2;
//         if (pos <= tm)
//             update(v*2, tl, tm, pos, new_val);
//         else
//             update(v*2+1, tm+1, tr, pos, new_val);
//         t[v] = max(t[v*2] ,t[v*2+1]);
//     }
// }


struct hash_pair {
   template <class T1, class T2>
   size_t operator()(const pair<T1, T2>& p) const{
      auto hash1 = hash<T1>{}(p.first);
      auto hash2 = hash<T2>{}(p.second);
      return hash1 ^ hash2;
   }
};


int temp[1000002]={0};

void sieve()
{
  temp[1]=1;
  for(int i=2;i<1000002;i++)
  {
    if(temp[i]==0)
    { temp[i]=i;
      for(int j=i*2;j<1000002;j+=i)
      { 
        if(temp[j]==0)
        temp[j]=i;
      }
    }
  }

}

int dfs(int i,vector<vector<int> > &g,vector<int>& p,vector<int>& c)
{
  int sub=1;
  for(auto x:g[i])
  {
    if(p[i]!=x)
    {
      p[x]=i;
      sub+=dfs(x,g,p,c);
    }
  }

  return c[i]=sub;
}


int main() { 


ll n;
cin>>n;
ll ans1=1,ans2=1,ans3=1,ans4=1;

if(n==1)
  { cout<<0;
    return 0;
}


for(int i=0;i<n;i++)
{
  ans1=(ans1*10)%mod;
}


for(int i=0;i<n;i++)
{
   ans2=(ans2*9)%mod;
}
ans2=(ans2*2)%mod;

for(int i=0;i<n;i++)
{
   ans3=(ans3*8)%mod;
}

ans4=((ans1-ans2+mod)%mod + ans3)%mod;
cout<<ans4;

return 0;
}
/*
1
4
1 2
2 3
3 4
*/


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

int tongS[100001]={0},tongT[100001]={0},q;
string S,T;

int main()
{
	cin>>S>>T;
	S=' '+S;
	T=' '+T;
	
	for(int i=1;i<S.length();++i)
	{
		tongS[i]=(tongS[i-1]+(S[i]-64));
	}
	
	for(int i=1;i<T.length();++i)
	{
		tongT[i]=(tongT[i-1]+(T[i]-64));
	}
	cin>>q;
	
	int x,y,z,t;
	for(int i=1;i<=q;++i)
	{
		cin>>x>>y>>z>>t;
		if((tongS[y]-tongS[x-1])%3==(tongT[t]-tongT[z-1])%3)
		{
			cout<<"YES"<<endl;
		}
		else
		{
			cout<<"NO"<<endl;
		}
	}
}


Measured memory_bytes: 4652
days=['Sunday','Monday','Tuesday','Wednesday','Thursday','Friday','Saturday']
dom=[31,29,31,30,31,30,31,31,30,31,30,31]
while True:
    try:
        try:
            (m,d)=map(int,raw_input().split())
        except: break
        if m==0 and d==0: break
        day=4-1
        for i in xrange(m-1):
            day+=dom[i]
        day+=d
        print days[day%7]
    except EOFError: break

Measured memory_bytes: 4220
#include<bits/stdc++.h>
//ios::sync_with_stdio(false);cin.tie(0);
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
typedef pair<pii,int> ppii;
typedef pair<int,pii> pipi;
typedef pair<ll,ll> pll;
typedef pair<pll,ll> ppll;
typedef pair<ll,pll> plpl;
typedef tuple<ll,ll,ll> tl;
ll mod=1000000007;
ll mod2=998244353;
ll mod3=1000003;
ll mod4=998244853;
ll inf=1000000000000000000;
double pi=2*acos(0);
#define rep(i,m,n) for(ll i=m;i<n;i++)
#define rrep(i,n,m) for(ll i=n;i>=m;i--)
int dh[4]={1,-1,0,0};
int dw[4]={0,0,1,-1};
int ddh[8]={-1,-1,-1,0,0,1,1,1};
int ddw[8]={-1,0,1,-1,1,-1,0,1};
ll lmax(ll a,ll b){
    if(a<b)return b;
    else return a;
}
ll lmin(ll a,ll b){
    if(a<b)return a;
    else return b;
}
ll gcd(ll a,ll b){
    if(a<b)swap(a,b);
    if(b==0)return a;
    if(a%b==0)return b;
    return gcd(b,a%b);
}
ll Pow(ll n,ll k){
    ll ret=1;
    ll now=n;
    while(k>0){
        if(k&1)ret*=now;
        now*=now;
        k/=2;
    }
    return ret;
}
ll beki(ll n,ll k){
    ll ret=1;
    ll now=n;
    while(k>0){
        if(k%2==1){
            ret*=now;
            ret%=mod2;
        }
        now*=now;
        now%=mod2;
        k/=2;
    }
    return ret;
}

int main(){
    ios::sync_with_stdio(false);cin.tie(0);
    int k,n;cin>>k>>n;
    if(k%2==0){
        cout<<k/2<<" ";
        rep(i,0,n-1)cout<<k<<" ";
        cout<<endl;
        return 0;
    }
    if(k==1){
        rep(i,0,n/2)cout<<1<<" ";
        if(n%2==1)cout<<1<<" ";
        cout<<endl;
        return 0;
    }
    if(n==1){
        cout<<(k+1)/2<<endl;
        return 0;
    }
    if(n==2){
        cout<<(k+1)/2<<" "<<k/2<<endl;
        return 0;
    }
    int u=n/2;
    ll s=1;
    ll t=0;
    vector<ll> v;
    ll sum=0;
    ll num=0;
    rep(i,1,n+1){
        t=k/2*s+1;
        s=k*s+1;
        sum+=t;
        if(sum>=u){
            rep(j,0,n-i){
                v.push_back((k+1)/2);
                
            }
            t=sum-u;
            num=i;
            break;
        }
    }
    //cout<<t<<endl;
    for(;;){
        if(t==0)break;
        ll r=(Pow(k,num)-1)/(k-1);
        //cout<<r<<" "<<t<<endl;
        ll rr=(t-1)/r;
        v.push_back(rr+1);
        if((t-1)%r==0){
            break;
        }
        t-=r*rr;
        t--;
        num--;
    }
    rep(i,0,v.size())cout<<v[i]<<" ";
    cout<<endl;
}


Measured memory_bytes: 5744
/*
    Author : manu_sy
*/
#include <bits/stdc++.h>
using namespace std;

#define int long long

const int hell = 1e9+7;
const int N = 1e2+7;
const int K = 1e5+7;

int n, k, a[N], dp[N][K], prefix[K];

// dp[i][j] : no. of ways to get sum j till pos i
// dp[i][j] = dp[i-1][j] + dp[i-1][j-1] + dp[i-1][j-2] + ... + dp[i-1][j-a[i]]
// We can store dp[i-1][j] values in prefix sum array so that the RHS can be calculated in O(1)

signed main() {

    cin >> n >> k;
    for (int i = 1; i <= n; i++) cin >> a[i];

    dp[0][0] = 1;
    fill(prefix, prefix+K-1, 1);

    for (int i = 1; i <= n; i++) 
    {
        for (int j = 0; j <= k; j++) 
        {
            dp[i][j] = prefix[j];
            if (j-a[i]-1 >= 0) 
                dp[i][j] = (dp[i][j] + hell - prefix[j-a[i]-1])%hell;
        }

        prefix[0] = dp[i][0];
        for (int j = 1; j <= k; j++) prefix[j] = (prefix[j-1] + dp[i][j])%hell;
    }   
    cout << dp[n][k] << endl;

    return 0;
}

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

using namespace std;
#define int int64_t
#define rep(i, n) for (int i = 0; i < (n); i++)
#define reps(i, n) for (int i = 1; i <= (n); i++)
#define all(x) (x).begin(), (x).end()
#define gsort(x) sort((x).begin(), (x).end(), greater<int>())
#define rv(s) reverse((s).begin(), (s).end())
#define pii pair<int, int>
#define re(s) reverse((s).begin(), (s).end())
#define setout(n, x) setw(n) << setfill(x)
#define Fixed fixed << setprecision(10);
const long long mod = 1e9 + 7;

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

   string s;
   int cnt = 0;

   cin >> s;

   rep(i, s.size())
   {
      if (i != 0 && s[i] == s[i - 1])
      {
         if (s[i] == '0')
            s[i] = '1';
         else
            s[i] = '0';

         ++cnt;
      }
   }

   cout << cnt << '\n';
}

Measured memory_bytes: 512
#include<bits/stdc++.h>
using namespace std;
int main() 
{
  long long n,k;
  cin>>n>>k;
  if(k>n)
  cout<<min(n,k-n)<<"\n";
  else
  {
  	long long mod=n%k;
  	if(mod==0)
  	 cout<<"0\n";
  	else
  	cout<<min(abs(mod-k),mod)<<"\n";
  }
}


Measured memory_bytes: 384
data = list(map(int,input().split()))
price = list(map(int,input().split()))

#print(data)
#print(price)

price.sort()

#print(price)

res = 0

for i in range(data[1]):
#    print ( 'i = {}'.format(i))
    res += price[i]

print(res)

Measured memory_bytes: 9252
#include <iostream>
using namespace std;
string S, T;
int main() {
    cin >> S >> T;
    int maxMatch = 0;
    for(int i = 0; i + T.size() - 1 < S.size(); ++i) {
        int match = 0;
        for(int j = 0; j < T.size(); ++j) {
            if(S[i + j] == T[j]) match++;
        }
        maxMatch = max(match, maxMatch);
    }
    cout << T.size() - maxMatch << endl;
    return 0;
}


Measured memory_bytes: 3628
fun main (args:Array<String>){
    val stlist = readLine()!!.split(" ")
    val numlist = readLine()!!.split(" ").map(String::toInt)
    val u : String = readLine()!!
    if(u == stlist[0]){
        val aaa = numlist[0] - 1
        print(aaa)
        print(" ")
        print(numlist[1])
        return
    }
    if(u == stlist[1]){
        val bbb = numlist[1] - 1
        print(numlist[0])
        print(" ")
        print(bbb)
        return
    }

}

Measured memory_bytes: 36200
#include <iostream>
#include <vector>
#include <algorithm>
#include <cstdio>
#include <string>
#include <map>


#define rep(x,to) for(int x=0;x<to;x++)
#define rep2(x,from,to) for(int x=from;x<to;x++)

using namespace std;


int main(void){

int bg,tn;
char k;
map <int,int> bgtn;
vector<int> tns;
	while(cin >> bg >> k >> tn){
		if( cin.eof() || (bg == 0 && tn == 0) ) break;
		tns.push_back(tn);
		bgtn[bg] = tn;
	}
	
	sort(tns.begin(),tns.end(),greater<int>());
	tns.erase(unique(tns.begin(), tns.end()), tns.end());

	while(cin >> bg){
		if( cin.eof()  ) break;
		rep(i,tns.size()) if(bgtn[bg] == tns[i]) {
				cout << i+1  <<endl;
				break;
			}
	}
	return 0;
	
	
}

Measured memory_bytes: 1216
#include <iostream>
#include <string>
#include <cstring>
#include <algorithm>
#include <cmath>
#include <cstdio>

using namespace std;

double ksm(int b)
{
    double s=1.0000000,a=0.5000000000;
    while(b>0)
    {
        if(b%2) s*=a;
        a*=a;
        b>>=1;
    }
    return s;
}
int main()
{
    int reco[30];
    for(int i=0;i<30;i++)
    {
        int a=1<<i;
        if(a>1000000)
            break;
        reco[i]=a;
    }
    int n,k;
    cin>>n>>k;
    double ans=0.0;
    for(int i=1;i<=n;i++)
    {
        if(i>=k) {ans+=1;continue;}
        for(int j=0;j<30;j++)
        {
            if(reco[j]*i>=k)
            {
                ans+=ksm(j);
                break;
            }
        }
    }
    ans*=(1.0/n);
    printf("%.12lf\n",ans);
    return 0;
}


Measured memory_bytes: 256
#include<iostream>
using namespace std;
int main(){
	int a,b,c,x; cin>>a>>b>>c>>x;
	int ans=0;
	for(int i=0;i<=a;i++){
		for(int j=0;j<=b;j++){
			for(int k=0;k<=c;k++){
				if(500*i+100*j+50*k==x) ans++;
			}
		}
	}
	cout << ans << endl;
}


Measured memory_bytes: 256
/* 競プロ用のテンプレ
 * SKMT
 * 作成日   2020年09月06日  15:14
 * ファイル名    b.cpp
 * 分かりませんでした…
 */
#include<bits/stdc++.h>
using namespace std;

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

int main(int argc, char const* argv[]){
	string S,T;
	cin >>S;
	cin >>T;
	int ans=T.size();
	for(int S_in = 0; S_in <=S.size() - T.size();S_in++){
		int diff=0;
		for(int i=0;i<T.size();i++){
			if(T.at(i) != S.at(S_in+i)){
				diff = diff+1;
			}
		}
		ans=min(ans,diff);
	}
	cout << ans << endl;	
	return 0;
}


Measured memory_bytes: 3572
from itertools import combinations as C

d = {}
for _ in range(int(input())):
    s = input()[0]
    d[s] = d.get(s, 0) + 1

dk = set(d.keys()) & set("MARCH")
ans = 0
for p, q, r in C(dk, 3):
    ans += d[p] * d[q] * d[r]
else:
    print(ans)

Measured memory_bytes: 9156
D,G=map(int, input().split())
li = []
for i in range(D):
  li.append(list(map(int, input().split())))

min_n=10**9
n = 0
s=0
for ind in range(2**D):
  n=0
  s=0
  for j in range(D):
    if ind>>j & 1:
      s += (j+1)*100*li[j][0]+li[j][1]
      n+=li[j][0]
  # print(s)
  if s < G:
    for j in range(D-1,-1,-1):
      if ind>>j & 1 == 0:
        tmp = (G-s) / ((j+1)*100)
        if (G-s) % ((j+1)*100) != 0:
          tmp += 1
        if tmp > 0:
          if tmp>=li[j][0]:
            tmp=li[j][0]-1
          s += (j+1)*100*tmp
          n+= tmp
      if s >= G:
        # print(tmp)
        break
  if s >= G:
    if n<min_n:
      # print(ind)
      min_n=n

print(int(min_n))
      

Measured memory_bytes: 3188
#include <iostream>
#include <algorithm>
#include <vector>
using namespace std;
int main () {
    int N, ans=0;
    vector<int> x;
    cin >> N;
    for (int i=0;i<N;i++){
        int a;
        cin >> a;
        x.push_back(a);
    }
    sort(x.begin(),x.end());
    for (int i=0;i<N;i++)
        ans+=x[i];
    ans-=x[N-1]/2;
    cout << ans;
    return 0;
}

Measured memory_bytes: 256
//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<int, int>;
#define rep(i, n) for (int i = 0; i < (n); i++)
#define all(v) v.begin(), v.end()
#define allr(v) v.rbegin(), v.rend()
vector<int> dx = {-1, -1, -1, 0, 0, 1, 1, 1};
vector<int> dy = {-1, 0, 1, -1, 1, -1, 0, 1};

int main () {
    vector<ll> ans(2e4, 0);
    for (int x = 1; x <= 200; x++) {
        for (int y = 1; y <= 200; y++) {
            for (int z = 1; z <= 200; z++) {
                ll now = x*x + y*y + z*z + x*y + y*z + z*x;
                if (now > 1e4 + 5) continue;
                ans[now]++;
            }
        }
    }
    int n; cin >> n;
    for (int i = 1; i <= n; i++) {
        cout << ans[i] << endl;
    }

    return 0;
}

Measured memory_bytes: 3628
#pragma GCC optimize("Ofast", "unroll-loops")

#include <bits/stdc++.h>

using namespace std;

#define ll long long
#define ld long double

ll gcd(ll a, ll b){
    if (b > a) return gcd(b, a);
    if (b == 0) return a;
    return gcd(b, a % b);
}

vector<ll> divisor(ll k){
    vector<ll> d;
    for (ll i = 1;i * i <= k;++i){
        if (k % i == 0){
            d.push_back(i);
            if (i * i != k)
                d.push_back(k / i);
        }
    }
    sort(d.begin(),d.end());
    return d;
}

int main(void){
	int N; cin >> N;
	vector<ll> A(N);
	for (auto& ai : A)
		cin >> ai;
	
	ll g_all = gcd(A[0], A[1]);
	for (int i = 2; i < N; ++i)
		g_all = gcd(g_all, A[i]);

	if (g_all != 1){
		cout << "not coprime" << endl;
		return 0;
	}

	map<ll, int> cnt;
	for (auto ai : A){
		auto div = divisor(ai);
		for (auto di : div){
			if (di == 1) continue;
			int tmp = ++cnt[di];
			if (tmp >= 2){
				cout << "setwise coprime" << endl;
				return 0;	
			}
		}
	}

	cout << "pairwise coprime" << endl;

	return 0;
}

Measured memory_bytes: 11180
#include "bits/stdc++.h"
#define rep(i,n) for(int i = 0; i < (n); ++i)
using namespace std;
typedef long long int ll;
typedef pair<int, int> P;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n;
    cin >> n;
    map<int, int> mp;
    rep(i,n){
        int a;
        cin >> a;
        ++mp[a];
    }
    int ans = 0;
    for(auto e : mp){
        if(e.first < e.second) ans += e.second - e.first;
        if(e.first > e.second) ans += e.second;
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 8128
/// In the name of God
#include <bits/stdc++.h>
#define int long long
using namespace std;
typedef pair<int,int> pii;
typedef long long ll;
typedef long double ld;
typedef vector<int> vi;

#define y1 def1
#define X first
#define Y second
#define endl '\n'
#define all(o) o.begin(), o.end()
#define IOS ios::sync_with_stdio(0), cin.tie(0)
map<pair<pii,int>, bool> mp;
int get(int a,int b,int c){
    if(mp[{{a, b}, c}]){
        cout << -1 << endl;
        exit(0);
    }
    mp[{{a,b}, c}] = 1;
    if(a % 2 == 1 || b % 2 == 1 || c % 2 == 1) return 0;
    int na = b/2 + c/2;
    int nb = a/2 + c/2;
    int nc = a/2 + b/2;
    return get(na, nb, nc) + 1;
}
main(){
    IOS;
    int a, b, c;
    cin >> a >> b >> c;
    cout << get(a, b, c) << endl;
}


Measured memory_bytes: 256
import java.util.Scanner;
public class Main {
	public static void main(String[] args){
		Scanner sc=new Scanner(System.in);
		while(sc.hasNext()){
			int[] a=new int[101];
			while(a[0]<2){
				a[sc.nextInt()]++;
			}
			boolean flag=false;
			if(a[1]%2==1&&a[2]%2==1){
				flag=true;
				for(int i=3;i<101;i++){
					if(a[i]%2==1){
						flag=false;
						break;
					}
				}
			}
			System.out.println(flag?"OK":"NG");
		}
	}
}

Measured memory_bytes: 24412
import java.util.Scanner;

public class Main {

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

		int n = sc.nextInt();
		int k = sc.nextInt();

		int r = 1;
		
		for(int i = 1; i <= n; i++) {
			if(k >r) {
				r *= 2;
			} else {
				r += k;
			}
		}

		System.out.println(r);

	}

}


Measured memory_bytes: 21844
#include<stdio.h>

int main(){
  int n,i,k,l[50];
  scanf("%d%d",&n,&k);
  for(i=0;i<n;i++)scanf("%d",&l[i]);
  int j;
  for(i=0;i<n;i++){
    for(j=0;j<n;j++){
      if(l[i]>l[j]){
        int tmp=l[i];
        l[i]=l[j];
        l[j]=tmp;
      }
    }
  }
  int ans=0;
  for(i=0;i<k;i++)ans+=l[i];
  printf("%d\n",ans);
  return 0;
}

Measured memory_bytes: 128
import sys,collections as cl,bisect as bs,random
sys.setrecursionlimit(100000)
input = sys.stdin.readline
mod = 10**9+7
Max = sys.maxsize
def l(): #intのlist
	return list(map(int,input().split()))
def m(): #複数文字
	return map(int,input().split())
def onem(): #Nとかの取得
	return int(input())
def s(x): #圧縮
	a = []
	if len(x) == 0:
		return []
	aa = x[0]
	su = 1
	for i in range(len(x)-1):
		if aa != x[i+1]:
			a.append([aa,su])
			aa = x[i+1]
			su = 1
		else:
			su += 1
	a.append([aa,su])
	return a
def jo(x): #listをスペースごとに分ける
	return " ".join(map(str,x))
def max2(x): #他のときもどうように作成可能
	return max(map(max,x))
def In(x,a): #aがリスト(sorted)
    k = bs.bisect_left(a,x)
    if k != len(a) and a[k] ==  x:
        return True
    else:
        return False

def pow_k(x, n):
    ans = 1
    while n:
        if n % 2:
            ans *= x
        x *= x
        n >>= 1
    return ans

"""
def nibu(x,n,r):
	ll = 0
	rr = r
	while True:
		mid = (ll+rr)//2

	if rr == mid:
		return ll
	if (ここに評価入れる):
		rr = mid
	else:
		ll = mid+1
"""

d = onem()

c = l()

s = []
sel = [0 for i in range(365)]

day = [[0 for i in range(26)] for j in range(365)]
ans = 0
for i in range(d):
	s.append(l())
	ss = [[s[-1][i],i+1] for i in range(26)]

	ak = 0

	for j in range(26):
		if i != 0:
			ak -= c[j] * (i-day[i-1][j]+1)
		else:
			ak -= c[j]

	ma = [-1,-1]
	for j in range(26):
		if i != 0:
			if ma[0] <= c[j] * (i-day[i-1][j]+1) + s[-1][j]:
				ma[0] = c[j] + (i-day[i-1][j]+1) + s[-1][j]
				ma[1] = j
		else:
			if ma[0] <= c[j] + s[-1][j]:
				ma[0] = c[j] + s[-1][j]
				ma[1] = j
	ans += ma[0] + ak
	sel[i] = ma[1]+1

	for j in range(26):
		if j == ma[1]:
			day[i][j] = i
		else:
			day[i][j] = day[i-1][j] if i - 1 >= 0 else 0



for _ in range(140000):
	ima = random.randrange(365)
	po = [[s[ima][i]-c[i],i+1] for i in range(26)]
	po.sort(reverse = True)
	while True:
		data = po[random.randrange(10)][1]
		if sel[ima] != data:
			break
	data = data-1
	ppp = 0
	for i in range(26):
		if ima == day[ima][i]:
			now = i
			break
	else:
		while True:
			now = random.randrange(26)
			if now != data:
				break 
	for i in range(ima+1,365):
		if day[i][data] == i:
			ppp += (i - ima) * c[data]
			break
	else:
		ppp += (364-ima) * c[data]
	ppp += s[ima][data]

	for i in range(ima+1,365):
		if day[i][now] == i:
			ppp -= (i - ima) * c[now]
			break
	else:
		ppp -= (364-ima) * c[now]
	ppp -= s[ima][now]
	if ppp > 0:
		for i in range(ima,365):
			if day[i][data] != i:
				day[i][data] = ima
			else:
				break
		po = ima - 1 if ima != 0 else 0
		for i in range(ima,365):
			if day[i][now] != i:
				day[i][now] = po
			else:
				break
		sel[ima] = data+1
		ans += ppp

for i in sel:
	print(i)


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

int main(){
int m,f,r;
while(true){
cin>>m>>f>>r;
if(m==-1&&f==-1&&r==-1){return 0;}
if(m==-1||f==-1){cout<<"F"<<endl;continue;}
if(m+f>=80){cout<<"A"<<endl;continue;}
if(m+f>=65){cout<<"B"<<endl;continue;}
if(m+f>=50){cout<<"C"<<endl;continue;}
if(m+f>=30&&r>=50){cout<<"C"<<endl;continue;}
if(m+f>=30){cout<<"D"<<endl;continue;}
if(m+f<30){cout<<"F"<<endl;continue;}
}
}

Measured memory_bytes: 3084
fun main(args:Array<String>) {
  val (n, k) = (1..2).map { readLine()!!.toInt() }
  val add = fun(i:Int):Int { return i * 2 } 
  val bys = fun(i:Int):Int { return i + k } 

  val funs = (0..n-1).map { slice ->
    (0..n-1).map { 
      when { 
       it <= slice -> add
       else -> bys
      }
    } 
  }
  funs.map { funlist -> 
    var s1 = 1
    funlist.map { s1 = it(s1) }
    var s2 = 1
    funlist.reversed().map { s2 = it(s2) }
    listOf(s1, s2)
  }.flatten().min().run(::println)
}

Measured memory_bytes: 36032
import java.util.*;
import java.io.*;
 
public class Main {
    public static void main(String[] args) throws Exception {
        FastScanner sc = new FastScanner(System.in);
        PrintWriter pw = new PrintWriter(System.out);
        int n = sc.nextInt();
        int T = sc.nextInt();
        int ans = 10000;
        for(int i = 0; i < n; i++){
            int c = sc.nextInt();
            int t = sc.nextInt();
            if(T >= t){
                ans = Math.min(ans,c);
            }
        }
        pw.println(ans != 10000 ? ans : "TLE");
        pw.flush();
    }

    static class GeekInteger {
        public static void save_sort(int[] array) {
            shuffle(array);
            Arrays.sort(array);
        }
 
        public static int[] shuffle(int[] array) {
            int n = array.length;
            Random random = new Random();
            for (int i = 0, j; i < n; i++) {
                j = i + random.nextInt(n - i);
                int randomElement = array[j];
                array[j] = array[i];
                array[i] = randomElement;
            }
            return array;
        }
 
    }
}

class FastScanner {
    private BufferedReader reader = null;
    private StringTokenizer tokenizer = null;
    public FastScanner(InputStream in) {
        reader = new BufferedReader(new InputStreamReader(in));
        tokenizer = null;
    }

    public String next() {
        if (tokenizer == null || !tokenizer.hasMoreTokens()) {
            try {
                tokenizer = new StringTokenizer(reader.readLine());
            } catch (IOException e) {
                throw new RuntimeException(e);
            }
        }
        return tokenizer.nextToken();
    }

    public String nextLine() {
        if (tokenizer == null || !tokenizer.hasMoreTokens()) {
            try {
                return reader.readLine();
            } catch (IOException e) {
                throw new RuntimeException(e);
            }
        }
        return tokenizer.nextToken("\n");
    }

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

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

    public double nextDouble() {
         return Double.parseDouble(next());
    }
    
    public String[] nextArray(int n) {
        String[] a = new String[n];
        for (int i = 0; i < n; i++)
            a[i] = next();
        return a;
    }

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

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


Measured memory_bytes: 25632
N, M, K = map(int, input().split())
mod = 998244353

fact = [1 for i in range(N+1)]
fact_inv = [1 for i in range(N+1)]

for i in range(1, N+1):
    fact[i] = fact[i-1] * i % mod
    fact_inv[i] = pow(fact[i], mod-2, mod)

def cmb(n,k):
    return fact[n] * fact_inv[k] % mod * fact_inv[n-k] %mod

ans = 0

for k in range(K+1):
    now = M * pow(M-1, N-k-1, mod) * cmb(N-1,k)
    ans = (ans + now % mod) % mod

print(ans)



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

vector<ll> a,b,c;
int main(void){
	ll x,y,z,k;
	cin>>x>>y>>z>>k;
	a = vi(x);
	b = vi(y);
	c = vi(z);
	for(int i = 0; i <x; i++){
		cin>>a[i];
	}
	for(int i = 0; i < y; i++){
		cin>>b[i];
	}
	for(int i = 0; i < z; i++){
		cin>>c[i];
	}
	sort(a.begin(), a.end(), greater<ll>());
	sort(b.begin(), b.end(), greater<ll>());
	sort(c.begin(), c.end(), greater<ll>());
	priority_queue<vi> q;
	q.push(vi({a[0] + b[0] + c[0], 0, 0, 0}));
	set<vi> seen;
	while(k--){
		vi t = q.top(); q.pop();
		cout<<t[0]<<'\n';
		int ai = t[1], bi = t[2], ci = t[3];
		vi tt(4);
		vi ttt(3);
		if(ai + 1 < x){
			ttt[0] = ai + 1;
			ttt[1] = bi;
			ttt[2] = ci;
			if(!seen.count(ttt)){
				seen.insert(ttt);
				tt[0] = t[0] - a[ai] + a[ai+1];
				tt[1] = ai + 1;
				tt[2] = bi;
				tt[3] = ci;
				q.push(tt);
			}
		}
		if(bi + 1 < x){
			ttt[1] = bi + 1;
			ttt[0] = ai;
			ttt[2] = ci;
			if(!seen.count(ttt)){
				seen.insert(ttt);
				tt[0] = t[0] - b[bi] + b[bi+1];
				tt[2] = bi + 1;
				tt[1] = ai;
				tt[3] = ci;
				q.push(tt);
			}
		}
		if(ci + 1 < x){
			ttt[2] = ci + 1;
			ttt[0] = ai;
			ttt[1] = bi;
			if(!seen.count(ttt)){
				seen.insert(ttt);
				tt[0] = t[0] - c[ci] + c[ci+1];
				tt[3] = ci + 1;
				tt[2] = bi;
				tt[1] = ai;
				q.push(tt);
			}
		}
	}
	return 0;
}


Measured memory_bytes: 4504
#include <bits/stdc++.h>
using namespace std;
#define int long long
typedef pair<int,int> P;
int INF = 1e16+7;
int mod = 1e9+7;
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};
signed main() {
    int N;
    cin >> N;
    vector<P>xy(N);
    for(int i = 0; i < N; i++) {
        cin >> xy[i].first >> xy[i].second;
    }
    sort(xy.begin(),xy.end());
    map<P,int>Mp;
    for(int i = 0; i < N; i++) {
        for(int j = i+1; j < N; j++) {
            Mp[{xy[j].first-xy[i].first,xy[j].second-xy[i].second}]++;
        }
    }
    int cnt = 0;
    for(pair<P,int> x:Mp) {
        cnt = max(cnt,x.second);
    }
    cout << N-cnt << endl;
}


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

int main() {
	int h[1000005],c=0;
	cin>>h[0];
	for(int i=1;i<1000005;i++){
	    if(h[i-1]%2==0){
	        h[i]=h[i-1]/2;
	    }
	    else{
	        h[i]=h[i-1]*3+1;
	    }
	    for(int j=0;j<i;j++){
	        if(h[i]==h[j]&&c==0){
	            c=i+1;
	            break;
	        }
	    }
	    if (c!=0)break;
	}
	cout<<c;
	return 0;
}


Measured memory_bytes: 384
#include <cstdio>
int main(){
	float l[10], v, w;
	while(~scanf("%f,%f,%f,%f,%f,%f,%f,%f,%f,%f,%f,%f",l,l+1,l+2,l+3,l+4,l+5,l+6,l+7,l+8,l+9,&v,&w)){
		int a = 0, r, d=0, i=0;
		for(;i<10;i++)d+=l[i];

		for(i=0;i<10;i++){
			a += l[i];
			if(d*v/(v+w) <= a){r = i + 1;break;}
		}
		printf("%d\n", r);
	}
}

Measured memory_bytes: 0
import math
A, B, H, M = map(int, input().split())
X = A * math.cos((H / 6 + M / 360) * math.pi) - B * math.cos(M / 30 * math.pi)
Y = A * math.sin((H / 6 + M / 360) * math.pi) - B * math.sin(M / 30 * math.pi)
print(math.sqrt(X ** 2 + Y ** 2))

Measured memory_bytes: 9500
#include<bits/stdc++.h>
using namespace std;
#define int long long

signed main()
{
	string s,t;
  	cin>>s>>t;
  	int n = s.length();
  	int m = t.length();
  
  	int ans = (int)1e9;
  
  	for (int i=0; i<n; ++i)
    {
      	int cost = 0;
      	if ( i + m - 1>=n)
          	break;
      	for (int j=0; j<m; ++j)
          	cost+=( t[j]!=s[j+i] );
//cout<<i<<"  "<<cost<<endl;
        ans = min(cost,ans);
    }
  
  	cout<< ans <<endl;
}

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

using namespace std;

int main() {
    ios_base::sync_with_stdio(false);
    cout.precision(15);
    cout << fixed;
    cin.tie(0);

    string s;
    cin >> s;
    int n = s.length();
    int ans = 0;
    for (int i = 0; i < n/2; i++) {
        if (s[i] != s[n-1-i]) ans++;
    }
    cout << ans << endl;

    return 0;
}


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

int main()
{
    ll N; cin >> N;
    set<ll> S;
    rep(i, N) {
        ll tmp; cin >> tmp;
        S.insert(tmp);
    }
    cout << S.size() << endl;


}


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

void trace(int A[],int N){
    for(int i=0;i<N;i++){
        if(i)cout << " ";
        cout << A[i];
    }
    cout << endl;
}

void insertionSort(int A[],int N){
    for(int i=0;i<N;i++){
        int v,j;
        v = A[i];
        j = i-1;
        while(j >=0 && A[j] > v){
            A[j+1] = A[j];
            j--;
            A[j+1]=v;
        }
        trace(A,N);
    }
}

int main(void){
    int n;
    cin >> n;
    
    int arr[n];
    for(int i=0;i<n;i++){
        cin >> arr[i];
    }
    
    insertionSort(arr,n);
    
    
}

Measured memory_bytes: 1160