akhauriyash/Code-Regression huggingface dataset:
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Scanner;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        Scanner in = new Scanner(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        Task solver = new Task();
        solver.solve(1, in, out);
        out.close();
    }

    static class Task {
        public void solve(int testNumber, Scanner in, PrintWriter out) {
            int a = in.nextInt();
            out.println(a + a * a + a * a * a);
        }

    }
}



Measured memory_bytes: 27008
#include<bits/stdc++.h>
#define rep(i,n) for (long long i = 0; i < (n); ++i)

using namespace std;

long long H, N;
long long A[1005];
long long B[1005];
long long dp[10005];

int main(){
	cin >> H >> N;
	rep(i, N) {
		cin >> B[i] >> A[i];
		//cin >> A[i] >> B[i];
	}

	rep(i, H + 5) dp[i] = LONG_MAX;

	dp[H] = 0;
	for(long long i = H; i >= 0; i--) {
		if(dp[i] != LONG_MAX) {
			rep(j, N) {
				long long next = max(0LL, i - B[j]);
				dp[next] = min(dp[next], dp[i] + A[j]);
			}
		}
	}
	cout << dp[0] << endl;
}


Measured memory_bytes: 3668
package main

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

var sc = bufio.NewScanner(os.Stdin)

func init() {
	sc.Split(bufio.ScanWords)
}

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

func main() {
	x := nextInt()
	s := x % 100
	i5 := s / 5
	i4 := s % 5 / 4
	i3 := s % 5 % 4 / 3
	i2 := s % 5 % 4 % 3 / 2
	i1 := s % 5 % 4 % 3 % 2 / 1

	if x / 100 >= (i5 + i4 + i3 + i2 + i1) {
		fmt.Printf("1")
	} else {
		fmt.Printf("0")
	}
}


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

		long a = sc.nextLong();
		long v = sc.nextLong();
		long b = sc.nextLong();
		long w = sc.nextLong();
		long t = sc.nextLong();

		if ( v<=w ) {
			System.out.println("NO");
			System.exit(0);
		}

		int dir = 0;
		if ( b>a ) dir = 1;
		else       dir = -1;

		long dist = Math.abs(a-b);

		long rec = Math.abs(v-w);

		if ( dist<=rec*t ) {
			System.out.println("YES");
		} else {
			System.out.println("NO");
		}
	}
}

Measured memory_bytes: 35880
#include <iostream>
#include <cstring>
#include <stdlib.h>
#include <vector>
#include <algorithm>
#include <cmath>
#include <stack>
#include <queue>
#include <math.h>
#include <string>
#include <map>
using namespace std;

int main()
{
    int n;
    cin >> n;
    int a=0, b=0;
    for(int i=1; i<=n; i++){
        if(i%2==0) a++;
        else b++;
    }
    cout << a*b << endl;
    
    return 0;
}

Measured memory_bytes: 256
n,k = map(int,input().split())
a = [i for i in range(n+1)]
b = []
x = 0
for i in range(n+1):
    x += i
    b.append(x)
MOD = 10**9 + 7

ans = 0
for i in range(k,n+1):
    ans = (ans + (b[n] - b[n-i]) - b[i-1] + 1) % MOD
    
print(ans+1)

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

int main() {
    int W,H,x,y,r;
    cin >> W >> H >> x >> y >> r;
    
    if (r <= x && x <= W - r && r <= y && y <= H - r ){
        cout << "Yes" << endl;
    }
    else {
        cout << "No" << endl;
    }
}


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

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

    int a = 0;
    int b = accumulate(W, W+N, 0);
    int DifferenceMin = b;
    for (int i = 0; i < N; i++) {
        a += W[i];
        b -= W[i];
        if (DifferenceMin > abs(a-b)) {
            DifferenceMin = abs(a-b);
        }
        else {
            cout << DifferenceMin << endl;
            return 0;
        }
    }
}


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

typedef std::int_fast32_t  s32;
typedef std::uint_fast32_t u32;
typedef std::int_fast64_t  s64;
typedef std::uint_fast64_t u64;

const unsigned long mod = 1000000007;
const double EPS = 0.00000001;
const int INF = (1 << 29);

typedef std::pair<int, int> pii;

template<typename T>
void print_array(T *A_, s32 size) {
  //printf("%d\n", size);
  if( size != 0 ) {
    for(int i = 0; i < size - 1; ++i) {
      printf("%d ", A_[i]);
    }
    printf("%d\n", A_[size - 1]);
  }
}


auto main() -> int {

  for(;;) {
    int e;
    std::cin >> e;
    if( e == 0 ) break;

    int res = INF;
    for(int z = 0; z <= 100; ++z) {
      for(int y = 0; y <= 1000; ++y) {
        int x = e - z * z * z - y * y;
        if( x < 0 ) continue;
        if( x + y + z < res ) {
          res = x + y + z;
        }
      }
    }
    
    std::cout << res << std::endl;
  }
  
  return 0;
}

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

int N;
char c;


int main(){
  cin >> N;
  bool flag = false;
  for(int i=0; i<N;i++){
    cin >> c;
    if(c=='Y')
      flag=true;
  }
  if(flag)
    cout << "Four" << endl;
  else
    cout << "Three" << endl;
    
}





Measured memory_bytes: 256
N = int(input())
MOD = 10 ** 9 + 7

memo = [{} for i in range(N+1)]

def f(x):
  for i in range(4):
    temp = list(x)
    if i >= 1:
      temp[i-1], temp[i] = temp[i], temp[i-1]
    if ''.join(temp).count('AGC') >= 1:
      return False
  return True

def dfs(temp, x):
  if x in memo[temp]:
    return memo[temp][x]
  if temp == N:
    return 1
  ans = 0
  for c in 'ACGT':
    if f(x + c):
      ans = (ans + dfs(temp + 1, x[1:] + c)) % MOD
  memo[temp][x] = ans
  return ans

print(dfs(0, 'XXX'))

Measured memory_bytes: 3872
import std.stdio, std.conv, std.array, std.string, std.algorithm, std.container, std.range, core.stdc.stdlib, std.math, std.typecons;
T[][] combinations(T)(T[] s, in int m) {   if (!m) return [[]];   if (s.empty) return [];   return s[1 .. $].combinations(m - 1).map!(x => s[0] ~ x).array ~ s[1 .. $].combinations(m); }

void main() {
  auto size = readln.chomp.to!int;
  auto words = readln.split.to!(string[]);

  void solve() {
    string result;
    foreach(i; 0..size) {
      result ~= words[0][i];
      result ~= words[1][i];
    }

    result.writeln;
  }

  solve();
}


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

using namespace std;

int main() {
  int N;
  cin >> N;
  
  string S;
  cin >> S;
  
  int ret = 0;
  for (int i = 1; i < S.size(); i++) {
    string S1 = S.substr(0, i);
    string S2 = S.substr(i);
    cerr << S1 << " " << S2 << endl;
    
    int cnt[2][26];
    for (int j = 0; j < 2; j++) {
      for (int k = 0; k < 26; k++) {
        cnt[j][k] = 0;
      }
    }
    
    for (int j = 0; j < S1.size(); j++) {
      cnt[0][S1[j] - 'a']++;
    }
    for (int j = 0; j < S2.size(); j++) {
      cnt[1][S2[j] - 'a']++;
    }
    
    int tmp = 0;
    for (int j = 0; j < 26; j++) {
      tmp += cnt[0][j] > 0 && cnt[1][j] > 0;
    }
    
    ret = max(ret, tmp);
  }
  
  cout << ret << endl;
}

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

int main(){
    
    cin.tie(0);
    ios::sync_with_stdio(0);
    
    int n;
    cin >> n;
    
    string s;
    cin >> s;
    
    if(n % 2 != 0){
        cout << "No" << endl;
        return 0;
    } else {
        if(s.substr(0,n/2) == s.substr(n/2,n/2)){
            cout << "Yes" << endl;
        } else {
            cout << "No" << endl;
        }
    }
}



Measured memory_bytes: 256
#define _USE_MATH_DEFINES

#include<iostream>
#include<math.h>
#include<stdio.h>

using namespace std;

int main() {

	double r;
	//const double pi = 3.141592653;

	double S, l;
	
	cin >> r;

	l = r * 2 * M_PI;
	S = r * r * M_PI;

	printf("%.6f %.6f\n", S, l);

	return 0;
}

Measured memory_bytes: 3284
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <vector>
#include <functional>
#include <queue>
#include <string>
#include <cstring>
#include <numeric>
#include <cstdlib>
#include <cmath>
using namespace std;

typedef long long ll;

#define INF 10e17 // 4倍しても(4回足しても)long longを溢れない
#define rep(i,n) for(int i=0; i<n; i++)
#define rep_r(i,n,m) for(int i=m; i<n; i++)
#define END cout << endl
#define MOD 1000000007
#define pb push_back
#define sorti(x) sort(x.begin(), x.end())
#define sortd(x) sort(x.begin(), x.end(), std::greater<int>())

class Union_Find {
public:
  vector<int> par;

  Union_Find(int n) : par(n, -1) {}
  void init(int n) {
    par.assign(n, -1);
  }

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

  bool issame(int x, int y) {
    return root(x) == root(y);
  }

  bool merge(int x, int y) {
    x = root(x);
    y = root(y);
    if (x == y) return false;
    if (par[x] > par[y]) swap(x,y);
    par[x] += par[y];
    par[y] = x;
    return true;
  }

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

typedef pair<int,int> pi;

int main() {
  ll n,m;
  cin >> n >> m;
  vector<pi> P(m);
  Union_Find uf(n);

  rep(i,m) {
    int a,b;
    cin >> a >> b;
    P[i].first = --a; P[i].second = --b;
  }

  ll total = (n * (n - 1)) / 2;

  vector<ll> ans;
  for (int i = m-1; i >= 0; --i) {
    ans.push_back(total);
    int a = P[i].first, b = P[i].second;
    if (uf.issame(a,b)) {
      continue;
    }
    ll ta = uf.size(a), tb = uf.size(b);
    total -= ta * tb;
    // ans.push_back(total);
    uf.merge(a,b);
  }

  for (int i = m - 1; i >= 0; --i) {
    cout << ans[i] << endl;
  }
}


Measured memory_bytes: 3444
org=gets.chomp
t=gets.to_i
t.times do
  com=gets.split(' ')
  s=com[1].to_i
  e=com[2].to_i
  case com[0]
  when "replace" then
       str=com[3]
       org[s..e]=str
  when "reverse" then
       tmp=org[s..e].reverse
       org[s..e]=tmp
  when "print" then
       printf("%s\n", org[s..e])
  end
end

Measured memory_bytes: 8700
#![allow(unused_mut)]
#![allow(non_snake_case)]
#![allow(unused_imports)]
use std::collections::HashSet;
use std::collections::HashMap;
use std::collections::BTreeSet;
use std::collections::VecDeque;
use std::cmp::{max, min};
use std::io::prelude::*;

fn input<T>() -> T
    where T: std::str::FromStr {
    let stdin = std::io::stdin();
    let token: String = stdin
        .lock()
        .bytes()
        .map(|c| c.unwrap() as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().unwrap()
}

fn main() {
    let n: usize = input();
    println!("{}", (n - 2) * 180)
}

Measured memory_bytes: 4352
import java.util.*;
import java.io.*;

public class Main
{
	public static void main(String [] Args)
	{
		Scanner in=new Scanner(System.in);
		long n=in.nextLong();
		if(n%2==1)
			System.out.println(0);
		else
		{
			long ans=0;
			long q=5;
			n=n/2;
			while(n>=q)
			{
				ans=ans+n/q;
				q=q*5;
			}
			System.out.println(ans);
		}		
	}
}
	

Measured memory_bytes: 21204
#include <bits/stdc++.h>
#define ff first
#define ss second
#define pb push_back
#define mp make_pair
#define speedhack ios_base::sync_with_stdio(false); cin.tie(nullptr);
#define fromfile freopen("input.txt", "r", stdin);  freopen("output.txt", "w", stdout); 
#define mod int (1e9+7)
#define MAXN int (1e9)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<ull, ull> pull;
typedef pair<int, int> pii;
typedef pair<ld, ld> pld;
 


int k,t,n;
ll a,b,c,d;

int main() {
    speedhack;
    //fromfile;
    string str;
    cin >> k;
    cin >> str;
    if (str.size() <= k){
        cout << str;
    }
    else{
        for(int j = 0; j<k; j++){
            cout << str[j];
        }
        cout << "...";

    }

}
 
 
    

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

N=int(input())

def keta(x):
    a = 0
    while x>0:
        x//=10
        a+=1
    return a

N_keta = keta(N)

ans=0

for i in range(3,N_keta+1):
    for j in range(3**i):
        s=""
        tmp=j
        f0=False
        f1=False
        f2=False
        for k in range(i):
            r=tmp%3
            if r==0:
                f0=True
                s+="7"
            elif r==1:
                f1=True
                s+="5"
            else:
                f2=True
                s+="3"
            tmp//=3
        if f0 and f1 and f2 and N >= int(s):
            ans+=1
print(ans)



Measured memory_bytes: 3064
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
public class Main {
	public static void main(String[] args)throws IOException {

		BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
		while(true){
			int n=Integer.parseInt(br.readLine());
			if(n==0)break;
			String[] dat=br.readLine().split(" ");
			int[] p= new int[n];
			int sum=0;
			double h,hsa;
			for (int i=0;i<n;i++){
				p[i] = Integer.parseInt(dat[i]);
				sum +=p[i];
			}
			
			h=(double)sum/n;
			double bun=0;
			for (int i=0;i<n;i++){
				bun +=(p[i]-h)*(p[i]-h);
			}
			hsa=(double)Math.sqrt(bun/n);	
			System.out.printf("%.8f\n",hsa);
		}
	}
}

Measured memory_bytes: 19300
#include <stdio.h>
#include <stdlib.h>

#define INF 2147483647

int matrixChainOrder(int *, int);

int **m;

main(){
	int n, i, *p;

	scanf("%d", &n);
	p = malloc(sizeof(int) * (n + 1));
	m = malloc(sizeof(int*) * n);
	for (i = 0; i < n; i++){
		m[i] = malloc(sizeof(int) * n);
	}

	scanf("%d%d", p, p + 1);
	for (i = 2; i <= n; i++){
		scanf("%*d%d", p + i);
	}
	//for (i = 0; i <= n; i++) printf("%d ", *(p + i));

	printf("%d\n", matrixChainOrder(p, n));

	return 0;
}

int matrixChainOrder(int *p, int n){
	int i, j, k, l, tmp;

	for (i = 0; i < n; i++){
		m[i][i] = 0;
	}
	for (l = 1; l < n; l++){  // l=??????????????????????´???°-1
		for (i = 0; i < n - l; i++){  // i=???????????????, ???????????????:i+l
			m[i][i + l] = INF;  // ????????¨???????????§?????£??\
			for (k = i; k < i+l ; k++){  // k=????????? (A*B*C)(D*E)?????????C
				tmp = m[i][k] + m[k+1][i+l] + p[i]*p[k+1]*p[i+l+1];
				if (tmp < m[i][i + l]) m[i][i + l] = tmp;
			}
		}
	}
	return m[0][n - 1];
}

Measured memory_bytes: 636
#include<bits/stdc++.h>
using namespace std;
#define max(a,b) ((a>b)?a:b);
#define min(a,b) ((b>a)?a:b);
#define ff first
#define ss second
#define pb push_back
#define pf push_front
#define mp make_pair
#define pu push
#define pp pop_back
#define in insert
#define forn(low,high,i) for(i=low;i<high;i++)
#define forrev(high,low,i) for(i = high; i>= low;i--)                                 //g++ template.cpp -o template.exe
//#define all(x) (x).begin(), (x).end()
typedef long long int ll;
typedef long double ld;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vi> vvi;
typedef vector<vl> vvl;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef vector<pii> vpii;
typedef vector<pll> vpll;
const ll mod =1e9+7;
const ll maxn=100000;







bool sortbysec(const pair<int,int> &a,                         //sorting of elements wrt second
              const pair<int,int> &b) 
{ 
    return (a.second < b.second); 
} 




int main()
{
	
	unsigned long long int n,i;
	long long int k=1;
	cin>>n;
	//unsigned long long int a[n];
	long  double po,qo,a[n],sum=1;
	for(i=0;i<n;i++)
	{
		cin>>a[i];
	}
	sort(a,a+n);
	for(i=0;i<n;i++)
	{

		if(k==-1 || sum==0)
			continue;
		
		
		

		po=a[i];
		qo=sum;
		
		if(a[i]==0)
		{
			sum=0;
			continue;
		}

		if((log10(a[i])+log10(sum))<=18)
		{
			sum=sum*a[i];
		}
		else
			k=-1;

	}
	if(k==-1 || log10(sum)>18)
		cout<<"-1"<<endl;
	else
	cout<<(unsigned long long int)sum;


	return 0;
}

Measured memory_bytes: 5264
import java.util.Scanner;
 
public class Main {
    private static int n;
    private static int q;
    private static int[] p;
    private static int[] rank;
 
    private static boolean same(int x, int y) {
        return findSet(x) == findSet(y);
    }
 
    private static void unite(int x, int y) {
        int i = findSet(x);
        int j = findSet(y);
 
        if (i == j) return;

        if (rank[i] > rank[j]){
            p[j] = p[i];
        }
        else {
            p[i] = p[j];
            if(rank[i] == rank[j]){
            rank[j]++;
            }
        }	
    }
 
    private static int findSet(int i) {
        while (i != p[i]){
            p[i] = p[p[i]];
            i = p[i];
        }
        return i;
    }
 
    private static void DisjointSet() {
        p = new int[n];
        rank = new int[n];
 
        for (int i = 0; i < n; i++) {
            p[i] = i;
            rank[i] = 0;
        }
    }
 
 
    public static void main (String[] args){
        Scanner scanner = new Scanner(System.in);
        n = scanner.nextInt();
        q = scanner.nextInt();
 
        DisjointSet();
        for (int i = 0; i < q; i++) {
            int com = scanner.nextInt();
            int x = scanner.nextInt();
            int y = scanner.nextInt();
 
            if (com == 0){
                unite(x, y);
            }
            if (com == 1){
                if (same(x, y)){
                    System.out.println(1);
                }else{
                    System.out.println(0);
		}
            }
        }
    }
}

Measured memory_bytes: 103236
import string
N = int(input())
strings = string.ascii_lowercase
ans = ""

index = 26
cnt = 1
# Nがcnt文字で表される場合、cnt-1文字までの場合の数を引く.
while N > index:
    N -= index
    index *= 26
    cnt += 1

N -= 1
for _ in range(cnt):
    M = N % 26
    ans += strings[M]
    N //= 26


# print(ans[::-1].rjust(cnt,'a'))
print(ans[::-1].rjust(cnt,'a'))

Measured memory_bytes: 9980
#include <cstdio>
#include <algorithm>
#pragma warning(disable:4996)

int h, A[600000];

void maxHeapify(int i) {
	int l, r, largest;
	l = i * 2;
	r = l + 1;
	if (l <= h && A[l] > A[i]) largest = l;
	else largest = i;
	if (r <= h && A[r] > A[largest]) largest = r;
	if (largest != i) {
		std::swap(A[i], A[largest]);
		maxHeapify(largest);
	}
}

int main() {
	int i;
	scanf("%d", &h);
	for (i = 1; i <= h; i++) scanf("%d", &A[i]);
	for (i = h / 2; i >= 1; i--) maxHeapify(i);
	for (i = 1; i <= h; i++) printf(" %d", A[i]);
	printf("\n");
	return 0;
}

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

#define for_(i,a,b) for(int i=(a);i<(b);++i)

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

const int ax[2][8] = {
	{0, 1, 2, 3, 0, 1, 2, 3},
	{0, 0, 0, 0, 1, 1, 1, 1}
};

const int ay[2][8] = {
	{0, 0, 0, 0, 1, 1, 1, 1},
	{0, 1, 2, 3, 0, 1, 2, 3}
};

int W, H, sx, sy, gx, gy, n, board[110][110];

bool dfs(int x, int y) {
	if (x == gx && y == gy) return true;
	int c = board[y][x];
	board[y][x] = -1;
	
	for_(d,0,4) {
		int nx = x + dx[d], ny = y + dy[d];
		if (nx < 1 || W < nx || ny < 1 || H < ny) continue;
		if (board[ny][nx] != c) continue;
		if (dfs(nx, ny)) return true;
	}
	
	return false;
}

int main() {
	while (cin >> W >> H, W) {
		memset(board, -1, sizeof(board));
		
		cin >> sx >> sy;
		cin >> gx >> gy;
		cin >> n;
		
		for_(i,0,n) {
			int c, d, x, y;
			cin >> c >> d >> x >> y;
			for_(a,0,8) board[y + ay[d][a]][x + ax[d][a]] = c;
		}
		
		if (board[sy][sx] != -1 && dfs(sx, sy)) puts("OK");
		else puts("NG");
	}
}

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

int main() {
  string S;
  cin >> S;
  if(S == "Sunny")cout << "Cloudy" << endl;
  if(S == "Cloudy")cout << "Rainy" << endl;
  if(S == "Rainy")cout << "Sunny" << endl;
  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define ll long long
ll gcd(int x, int y) { return (x % y)? gcd(y, x % y): y; }    //最大公約数
ll lcm(ll x, ll y) { return x / gcd(x, y) * y; }     //最小公倍数
using Graph = vector<vector<int>>;
ll inf=300000000000000000;
const double PI = 3.14159265358979323846;
const int MAX = 1010000;
const ll MOD = 1000000007;

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

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

// 二項係数計算
long long COM(int n, int k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}
long long modpow(long long a, long long n, long long mod) {
    long long res = 1;//a^n%mod
    while (n > 0) {
        if (n & 1) res = res * a % mod;
        a = a * a % mod;
        n >>= 1;
    }
    return res;
}
long long modinv(long long a, long long m) {
    long long 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 main(){
  rep(i,365)cout << 26-i%26 << endl;
}


Measured memory_bytes: 3632
function Main(input) {
  input = input.split("\n");
  var a = ~~input[0];
  var b = ~~input[1];
  var c = ~~input[2];
  var d = ~~input[3];
  var e = ~~input[4];

  var AtCoder = function(a,b,c,d,e){
    this.menu = {"Don":a,"Curry":b,"Pasta":c,"Ramen":d,"Hamburg":e};
    this.max = a+b+c+d+e+50;
  };

  AtCoder.prototype = {
    procedure: function(){
      var max_time=10000000;
      for(item1 in this.menu){
        var time1 = 0;
        time1 = time1+(this.menu[item1]+(10-this.menu[item1]%10)%10);
        for(item2 in this.menu){
          if(item1 == item2) continue;
          var time2 = time1;
          time2 = time2+(this.menu[item2]+(10-this.menu[item2]%10)%10);
          for(item3 in this.menu){
            if(item1 == item3 || item2 == item3) continue;
            var time3 = time2;
            time3 = time3+(this.menu[item3]+(10-this.menu[item3]%10)%10);
            for(item4 in this.menu){
              if(item1 == item4 || item2 == item4 || item3 == item4) continue;
              var time4 = time3;
              time4 = time4+(this.menu[item4]+(10-this.menu[item4]%10)%10);
              for(item5 in this.menu){
                if(item1 == item5 || item2 == item5 || item3 == item5 || item4 == item5) continue;
                var time5 = time4;
                time5 = time5+this.menu[item5];
                if(max_time > time5) max_time=time5;
              }
            }
          }
        }
      }
      return max_time;
    }
  }
  var atcoder = new AtCoder(a,b,c,d,e);
  console.log(atcoder.procedure());
}
Main(require("fs").readFileSync("/dev/stdin", "utf8"));


Measured memory_bytes: 7500
#include <iostream>
#include <string>
using namespace std;
string s;
int main(){
    cin>>s;
    if(s.size()<=25){
        int a[26]={};
        for(int i=0;i<s.size();i++)a[s[i]-'a']=1;
        cout<<s;
        for(int i=0;i<26;i++){
            if(a[i]==0){
                cout<<char('a'+i);
                return 0;
            }
        }
    }
    for(int i=s.size()-1;i;i--){
        if(s[i-1]<s[i]){
            for(int j=0;j<i-1;j++)cout<<s[j];
            for(int j=s.size();j>=i;j--){
                if(s[i-1]<s[j]){
                    cout<<s[j];
                    return 0;
                }
            }
        }
    }
    cout<<-1;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main() {
    int input, happiness = 0;
    cin >> input;
    if (input >= 500) {
        happiness += (input / 500) * 1000;
        int rest = input % 500;
        happiness += (rest / 5) * 5;
    } else {
        happiness += (input / 5) * 5;
    }

    cout << happiness;
}

Measured memory_bytes: 256
#include <iostream>
using namespace std;
int n,m,x,y;
bool f[3000001], l[3000001];
int main() {
	cin >> n >> m;
	for(int i=0;i<m;i++){
		cin >> x >> y;
		if(x>y){
			swap(x,y);
		}
		if(x==1){
			f[y]=1;
		}
		if(y==n){
			l[x]=1;
		}
	}
	for(int i=0;i<3000001;i++){
		if((f[i])&&(l[i])){
			cout << "POSSIBLE";
			return 0;
		}
	}
	cout << "IMPOSSIBLE";
	return 0;
}

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

int main() {

  long long int n;
  cin >> n;

  string s;
  cin >> s;

  s += s[0];
  s += s[1];

  for ( long long int i = 0; i < 4; i++ ) {

    string ans = "";

    for ( long long int j = 0; j < n + 2; j++ ) {
      ans += "N";
    }
    if ( i / 2 == 0 ) {
      ans[0] = 'S';
    }else {
      ans[0] = 'W';
    }
    if ( i % 2 == 0 ) {
      ans[1] = 'S';
    }else {
      ans[1] = 'W';
    }

    for ( long long int j = 1; j < n+1; j++ ) {
      if ( ans[j] == 'S' ) {
	if ( s[j] == 'o' ) {
	  ans[j+1] = ans[j-1];
	}else {
	  if ( ans[j-1] == 'S' ) {
	    ans[j+1] = 'W';
	  }else {
	    ans[j+1] = 'S';
	  }
	}
      }else {
	if ( s[j] == 'o' ) {
	  if ( ans[j-1] == 'S' ) {
	    ans[j+1] = 'W';
	  }else {
	    ans[j+1] = 'S';
	  }
	}else {
	  ans[j+1] = ans[j-1];
	}
      }
    }

    if ( ans[0] != ans[n] || ans[1] != ans[n+1] ) continue;
    for ( long long int j = 0; j < n; j++ ) {
      cout << ans[j];
    }
    cout << endl;
    return 0;

  }

  cout << -1 << endl;

  return 0;

}


Measured memory_bytes: 640
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		
		int k = scan.nextInt();
		String s = scan.next();
		
		if(s.length() <= k) {
			System.out.println(s);
		}else {
			System.out.println(s.substring(0,k) + "...");
		}

	}
}

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

int main() {
    int n, a;
    scanf("%d", &n);
    map<int, int> mp;

    for (int i = 0; i < n; i++) {
        cin >> a;
        mp[a]++;
    }

    int ans = 0;
    for (auto u:mp) {
        if(u.second >= u.first) ans += u.second - u.first;
        else ans += u.second;
    }

    cout << ans << endl;
}

Measured memory_bytes: 8180
#include <bits/stdc++.h>
#define INF 2147483647
#define INF_LL 9223372036854775807
using namespace std;
typedef long long int ll;
typedef unsigned long long int ull;

int main() {
	int A, B, X;
	cin >> A >> B >> X;
	if (A + B >= X && A <= X)cout << "YES" << endl;
	else cout << "NO" << endl;
	return 0;
}

Measured memory_bytes: 256
class RMQ
  def initialize(n, max)
    @max = max
    @n = 2 ** Math.log2(n).ceil
    @dat = Array.new(@n * 2, @max)
  end

  def update(i, x)
    i += @n - 1
    @dat[i] = x
    while i.positive?
      i = (i - 1) / 2
      @dat[i] = [@dat[i * 2 + 1], @dat[i * 2 + 2]].min
    end
  end

  def query(a, b, k = 0, l = 0, r = @n)
    return @max if r <= a || b <= l
    return @dat[k] if a <= l && r <= b
    vl = query(a, b, k * 2 + 1, l, (l + r) / 2)
    vr = query(a, b, k * 2 + 2, (l + r) / 2, r)
    [vl, vr].min
  end
end

n, q = gets.split.map(&:to_i)
rmq = RMQ.new(n, (2 ** 31) - 1)
q.times do
  com, x, y = gets.split.map(&:to_i)
  if com.zero?
    rmq.update(x, y)
  elsif com == 1
    puts rmq.query(x, y + 1)
  end
end



Measured memory_bytes: 8968
#include<iostream>
#include<vector>
#include<queue>

using namespace std;

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

	int max = 0, maxi = 0;
	for(int i = 0; i < N; ++i){
		if(max < A[i]) { max = A[i]; maxi = i; }
	}

	priority_queue<int> pq;

	for(int i = 0; i < N; ++i) pq.push(A[i]);

	int firmax = pq.top();
	pq.pop();
	int secmax = pq.top();

	for(int i = 0; i < N; ++i){
		if(i != maxi)
			cout << firmax << endl;
		else
			cout << secmax << endl;
	}

	return 0;
}


Measured memory_bytes: 3316
l,r = map(int,input().split())

if r - l >= 2040:
    print(0)
    exit(0)

res = 10 ** 100
for i in range(l, r + 1):
    for j in range(i + 1, r + 1):
        res = min(res, i * j % 2019)
print(res)

Measured memory_bytes: 40812
import sys

sys.setrecursionlimit(4100000)


def inputs(num_of_input):
    ins = [input() for i in range(num_of_input)]
    return ins


def solve(inputs):
    N = int(inputs[0])

    half = N // 2
    if N % 2 == 0:
        return half - 1
    else:
        return half


def string_to_int(string):
    return list(map(lambda x: int(x), string.split()))


if __name__ == "__main__":
    ret = solve(inputs(1))
    print(ret)


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

using namespace std;
typedef long long ll;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<ll> VL;
typedef vector<VL> VVL;
typedef pair<int, int> PII;

#define FOR(i, a, n) for (int i = (int)a; i < (int)n; ++i)
#define REP(i, n) FOR(i, 0, n)
#define ALL(x) x.begin(), x.end()
#define MOD 1000000007
#define INF 1000000000
#define PI 3.14159265359
#define EPS 1e-12
#define MAX_N 100000

int main(void)
{
  ll n, a[MAX_N], b[MAX_N];
  cin >> n;
  REP(i, n) {
    cin >> a[i] >> b[i];
  }

  ll count = 0;
  for(int i=n-1; i>=0; i--) {
    if((a[i]+count)%b[i] != 0) {
      count += (b[i] - (a[i]+count) % b[i]);
    }
  }

  cout << count << endl;

  return 0;
}


Measured memory_bytes: 1792
#include<bits/stdc++.h>
using namespace std;
inline int read(){
	char c=getchar();int s=0;
	while(c<'0'||c>'9')c=getchar();
	while(c>='0'&&c<='9'){
		s=s*10+c-'0';c=getchar();
	}return s;
}
const int N=1e5+888;
int n,a[N];
int cmp(int x,int y){
	return x>y;
}
int main(){
	n=read();
	for(int i=1;i<=n;i++){
		a[i]=read();
	}
	sort(a+1,a+n+1,cmp);
	int jl=0;
	for(int i=1;i<=n;i++){
		if(a[i]>=i)jl=i;
	}
	int js=0;
	for(int i=jl;i<=n;i++){
		if(a[i]<jl)break;
		js++;
	}
	int h=((a[jl]-jl+1)%2);
	if(js%2==1&&h==1)puts("Second");
	else puts("First");
}

Measured memory_bytes: 3912
#define _CRT_SECURE_NO_WARNINGS
#define _USE_MATH_DEFINES
#include <iostream>
#include <cstdio>
#include <vector>
#include <string>
#include <array>
#include <queue>
#include <deque>
#include <set>
#include <list>
#include <map>
#include <stack>
#include <utility>
#include <algorithm>
#include <numeric>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cctype>
#include <cstring>
#include <climits>
#include <bitset>
#include <complex>
#include <random>
#include <functional>
#include <sstream>
#include <iomanip>

using namespace std;

#define rep(i, n) for(int i=0; i<(n); i++)
#define FOR(i, m, n) for(int i=(m);i<(n);i++)
#define sz(x) ((int)(x).size())
#define all(x) (x).begin(),(x).end()
#define SORT(x) sort((x).begin(),(x).end())
#define REVE(x) reverse((x).begin(),(x).end())
#define mp make_pair
#define pb push_back
#define dump(x)  cout << #x << " = " << (x) << endl;
#define forauto(i, a) for(auto i:a)cout << i << " "; puts("");

typedef long long LL;
typedef vector<int> VI;
typedef vector<LL> VL;
typedef vector<string> VS;
typedef vector<bool> VB;
typedef vector<vector<int>> VVI;
typedef pair<int, int> PII;
typedef pair<double, double> PDD;
typedef complex<double> CD;

int main() {
	LL n, m; cin >> n >> m;
	vector<pair<LL,LL>> ab(n);
	rep(i, n)cin >> ab[i].first >> ab[i].second;
	SORT(ab);

	LL ans = 0;
	rep(i, n) {
		if (ab[i].second <= m) {
			ans += ab[i].first*ab[i].second;
			m -= ab[i].second;
		}
		else {
			ans += ab[i].first*m;
			break;
		}
	}
	cout << ans << endl;
}

Measured memory_bytes: 1792
#include <bits/stdc++.h>
using namespace std;
#define endl "\n"
#define pb push_back
typedef long long ll;
typedef vector<long long> vll;
#define fo(i,a) for(ll i=0;i<a;i++)
#define Fo(i,a,b) for(ll i=a;i<b;i++)
#define deb(x) cout<<#x<<" = "<<x<<"\n"

void solve(){
    char a;
    cin>>a;
    cout<<(isupper(a)?"A":"a");
}


int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);

	ll t=1;
//	cin>>t;
	while(t--){
		solve();
	}
	return 0;
}



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

#define ll long long

ll GCD(ll a, ll b) {
  return a % b ? GCD(b, a % b): b;
}


vector<pair<ll, ll> > prime_factorize(ll n) {
    vector<pair<ll,ll>> res;
    for (ll a = 2; a * a <= n; ++a) {
        if (n % a != 0) continue;
        ll ex = 0; // 指数

        // 割れる限り割り続ける
        while (n % a == 0) {
            ++ex;
            n /= a;
        }

        // その結果を push
        res.push_back({a, ex});
    }

    // 最後に残った数について
    if (n != 1) res.push_back({n, 1});
    return res;
}

int main() {
  ll A, B;
  cin >> A >> B;
  
  ll g = GCD(max(A, B), min(A,B));
  
  
  vector<pair<ll,ll>> vec_f = prime_factorize(g);
  
  cout << vec_f.size() + 1 << endl;
  
  
  
  
  
}

Measured memory_bytes: 3516
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <string>
#include <sstream>
#include <complex>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
using namespace std;
typedef long long unsigned int ll;

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

int s(int n)
{
    if(n < 10){
        return n;
    }
    return (n % 10) + s(n / 10);
}

int main() {
    //cout.precision(10);
    int in;
    cin >> in;
    if(in % s(in) == 0){
        cout << "Yes" << endl;
    } else {
        cout << "No" << endl;
    }
    return 0;
}


Measured memory_bytes: 256
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <iostream>
#include <istream>
#include <iterator>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
//#include <tuple>
#include <iomanip>
#include <cstring>
using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef vector<ll> vec;
typedef vector<vec> mat;
#define rep(i, n) for(ll i = 0; i < (n); i++)
#define revrep(i, n) for(ll i = (n-1); i >= 0; i--)
#define pb push_back
#define f first
#define s second
ll max(ll a, ll b){return (a > b) ? a : b;}
ll min(ll a, ll b){return (a < b) ? a : b;}
ll max3(ll a, ll b, ll c){return max(a, max(b, c));};
ll min3(ll a, ll b, ll c){return min(a, min(b, c));};
ll max4(ll a, ll b, ll c, ll d){return max(max(a, b), min(c, d));};
ll min4(ll a, ll b, ll c, ll d){return min(min(a, b), min(c, d));};
ll max5(ll a, ll b, ll c, ll d, ll e){return max(max(a, b), max3(c, d, e));};
ll min5(ll a, ll b, ll c, ll d, ll e){return min(min(a, b), min3(c, d, e));};

const ll INFL = 1LL << 60;//10^18 = 2^60
const int INF = 1 << 30;//10^9
ll MOD = 1000000007;
//ll MOD = 998244353;
/*
vector<ll> dy = {0, 0, 1, -1, 1, 1, -1, -1, 0};
vector<ll> dx = {1, -1, 0, 0, 1, -1, 1, -1, 0};
*/

ll pow_long(ll x, ll k){
  ll res = 1;
  while(k > 0){
    if(k % 2) res *= x;
    x *= x;
    k /= 2;
  }
  return res;
}
ll pow_mod(ll x, ll k){
  x %= MOD; x += MOD; x %= MOD;
  ll res = 1;
  while(k > 0){
    if(k % 2){
      res *= x; res %= MOD;
    }
    x *= x; x %= MOD;
    k /= 2;
  }
  return res;
}

ll inverse(ll x){return pow_mod(x, MOD - 2);};

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

ll lcm(ll x, ll y){return x / gcd(x, y) * y;};

ll kai_mod(ll x){
  if(x == 0) return 1;
  return x * kai_mod(x-1) % MOD;
}

/*
//コンビネーション
const int MAXcomb = 200010;
ll fac[MAXcomb], finv[MAXcomb], inv[MAXcomb];
//facはn!,finvは1/n!
//invは逆元
void COMinit(){
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for(int i = 2; i < MAXcomb; i++){
        fac[i] = fac[i-1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD/i) % MOD;
        finv[i] = finv[i-1] * inv[i] % MOD;
    }
}
ll comb(int n, int k){
    if(n < k) return 0;
    if(n < 0 || k < 0) return 0;
    return fac[n] * finv[k] % MOD * finv[n-k] % MOD;
}
*/

int main(){
  ll X, Y;
  cin >> X >> Y;
  if(X % Y == 0) cout << -1 << endl;
  else{
    for(ll i = 1;;i++){
      if((X * i) % Y){
        cout << X * i << endl;
        return 0;
      }
    }
  }
}


Measured memory_bytes: 256
res = [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]
n = int(input())
print(res[n-1])

Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
#define all(c) (c).begin(),(c).end()
#define rrep(i,n) for(int i=(int)(n)-1;i>=0;i--)
#define REP(i,m,n) for(int i=(int)(m);i<(int)(n);i++)
#define rep(i,n) REP(i,0,n)
#define iter(c) __typeof((c).begin())
#define tr(it,c) for(iter(c) it=(c).begin();it!=(c).end();it++)
#define mem(a) memset(a,0,sizeof(a))
#define pd(a) printf("%.10f\n",a)
#define pb(a) push_back(a)
#define in(a) insert(a)
#define pi M_PI
#define R cin>>
#define F first
#define S second
#define C class
#define ll long long
#define ln cout<<'\n'
template<C T>void pr(T a){cout<<a;ln;}
template<C T,C T2>void pr(T a,T2 b){cout<<a<<' '<<b;ln;}
template<C T,C T2,C T3>void pr(T a,T2 b,T3 c){cout<<a<<' '<<b<<' '<<c;ln;}
template<C T>void PR(T a,int n){rep(i,n){if(i)cout<<' ';cout<<a[i];}ln;}
bool check(int n,int m,int x,int y){return x>=0&&x<n&&y>=0&&y<m;}
const ll MAX=1000000007,MAXL=1LL<<60,dx[4]={-1,0,1,0},dy[4]={0,1,0,-1};
typedef pair<int,int> P;
void extended_euclid(ll x,ll y,ll *c,ll *a,ll *b){
  ll a0,a1,a2,b0,b1,b2,r0,r1,r2,q;
  r0=x;r1=y;a0=1;a1=0;b0=0;b1=1;
  while(r1>0){
    q=r0/r1;r2=r0%r1;a2=a0-q*a1;b2=b0-q*b1;
    r0=r1;r1=r2;a0=a1;a1=a2;b0=b1;b1=b2;
  }
  *c=r0;*a=a0;*b=b0;
}

ll get_inv(ll n, ll p){
  ll a,b,c;
  extended_euclid(n,p,&c,&a,&b);
  if(a<p) a+=p;
  return a%p;
}

ll fact[2000100],fact_inv[2000100];

ll nCr(int N, int K){
  if(K<0||K>N) return 0;
  return fact[N]*fact_inv[K]%MAX*fact_inv[N-K]%MAX;
}
void init() {
  fact[0]=1;
  REP(i,1,2000100) fact[i]=fact[i-1]*i%MAX;
  fact_inv[2000050]=get_inv(fact[2000050],MAX);
  for(int i=2000050-1;i>=0;i--) fact_inv[i]=fact_inv[i+1]*(i+1)%MAX;
}

void Main() {
  init();
  ll n,m,x,y,ans=0;
  cin >> n >> m >> x >> y;
  for(int i=0; i<n-x; i++) {
    ans+=nCr(i+y-1,i)*nCr((n-i)+(m-y)-2,(n-i)-1)%MAX;
    ans%=MAX;
  }
  pr(ans);
}

int main() {
  ios::sync_with_stdio(0);cin.tie(0);
  Main();return 0;
}


Measured memory_bytes: 31488
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n)for(int i=0;i<(n);i++)
#define ALL(a) (a).begin(), (a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define pb push_back
using ll = long long;
using P = pair<int, int>;

int main(){
    string sa, sb, sc; cin >> sa >> sb >> sc;
    int a = 0, b = 0, c = 0;

    char turn = 'a';
    while(1){
        //cout << turn << " ";
        
        if(turn == 'a'){
            if(a == sa.size()){
                cout << "A" << endl;
                return 0;
            }
            turn = sa[a];
            a++;
        }else if(turn == 'b'){
            if(b == sb.size()){
                cout << "B" << endl;
                return 0;
            }
            turn = sb[b];
            b++;
        }else if(turn == 'c'){
            if(c == sc.size()){
                cout << "C" << endl;
                return 0;
            }
            turn = sc[c];
            c++;
        }

    }

}

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

int main() {
    //input
    int a,b,c;
    cin >> a >> b >> c;
    if(a+b+c == 17){
        cout << "YES" << endl;
    }else{
        cout << "NO" << endl;
    }

    return 0;
}

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

#define INT_MAX 2147483647
//Macro

using namespace std;

int solve(int n, int s, vector<int> d){
	vector<int> dp(n+1, INT_MAX); //Generate a Vector, of Size n+1, and Filled with INT_MAX
	dp[0] = 0; //Initialize dp[0] to 0
	for(int i = 0; i < s; i++){ //Iterate from 0 -> s
		for(int j = 0; (j + d[i]) <= n; j++){ //Iterate from 
			if(dp[j] != INT_MAX){
				dp[j+d[i]] = min(dp[j+d[i]], dp[j]+1);
			}
		}
    }
	return dp[n];
}

int main(){
	int n, m;
	cin >> n >> m;
	vector<int> x(m);
	for(int i = 0; i < m; i++){
		cin >> x[i];
	} //Finished Resolving Inputs
	cout << solve(n, m, x) << endl; //Perform Solve Function
}


Measured memory_bytes: 3252
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cfloat>
#include <map>
//#include <utility>
#include <set>
#include <iostream>
//#include <memory>
#include <string>
#include <vector>
#include <algorithm>
//#include <functional>
#include <sstream>
//#include <deque>
#include <complex>
#include <stack>
#include <queue>
#include <cstdio>
//#include <cctype>
#include <cstring>
//#include <ctime>
#include <iterator>
#include <bitset>
//#include <numeric>
//#include <list>
//#include <iomanip>

#if __cplusplus >= 201103L
#include <array>
#include <tuple>
#include <initializer_list>
#include <unordered_set>
#include <unordered_map>
#include <forward_list>

#define cauto const auto&
#else

#endif

using namespace std;


namespace{
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;

typedef vector<int> vint;
typedef vector<vector<int> > vvint;
typedef vector<long long> vll, vLL;
typedef vector<vector<long long> > vvll, vvLL;

#define VV(T) vector<vector< T > >

template <class T>
void initvv(vector<vector<T> > &v, int a, int b, const T &t = T()){
    v.assign(a, vector<T>(b, t));
}

template <class F, class T>
void convert(const F &f, T &t){
    stringstream ss;
    ss << f;
    ss >> t;
}


#define reep(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n) reep((i),0,(n))
#define ALL(v) (v).begin(),(v).end()
#define PB push_back
#define F first
#define S second
#define mkp make_pair
#define RALL(v) (v).rbegin(),(v).rend()


#define MOD 1000000007LL
#define EPS 1e-8
static const int INF=1<<24;
double PI = asin(0.5)*6.0;

void mainmain(){
	int n,m;
	// printf("%.6lf\n",PI);
	while(cin>>n,n){
		double t1=0,t2=0;
		double tt1=360,tt2=360;
		rep(i,n-1){
			double t;
			cin>>t;
			tt1-=t;
			t1+=sin(t/180*PI);
		}
		t1+=sin(tt1/180*PI);
		cin>>m;
		rep(i,m-1){
			double t;
			cin>>t;
			tt2-=t;
			t2+=sin(t/180*PI);
		}
		t2+=sin(tt2/180*PI);
		if(t1-t2>EPS) cout<<1<<endl;
		else if(t1-t2<-EPS) cout<<2<<endl;
		else cout<<0<<endl; 
	}
}



}
main() try{
    mainmain();
}
catch(...){
}

Measured memory_bytes: 1264
#include <iostream>
#include <cstdlib>
#include <utility>
#include <algorithm>
#include <string>
#include <vector>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <cmath>
#include <numeric>

using namespace std;

using ll = long long;
using vi = vector<int>; using vi2 = vector<vi>;
#define loopi(i, a, b) for(int i = (int)a; i < (int)b; i++)
#define loop(i, n) for (int i = 0; i < (int)n; i++)
#define loopeq(i, n) for (int i = 0; i <= (int)n; i++)
#define loopll(i, n) for (ll i = 0; i < (ll)n; i++)

int main() {
    int n; cin >> n;
    set <string> s;
    loop(i,n) {
        string si; cin >> si;
        s.insert(si);
    }
    cout << s.size() << endl;
}

Measured memory_bytes: 19252
import sys
sys.setrecursionlimit(10**7)
input = sys.stdin.readline

n = int(input())
graph = [[] for _ in range(n)]
for i in range(n-1):
    a, b = map(int, input().split())
    a -= 1
    b -= 1
    graph[a].append(b)
    graph[b].append(a)


def dfs(v, dist, memo):
    memo[v] = dist
    for nv in graph[v]:
        if memo[nv] >= 0:
            continue
        dfs(nv, dist+1, memo)

memo = [-1] * n
dfs(0, 0, memo)

node = 0
dist = 0
for i in range(n):
    if memo[i] > dist:
        dist = memo[i]
        node = i

memo = [-1] * n
dfs(node, 0, memo)

dist = max(memo)
count = dist + 1

dp = [0] * (count + 10)
dp[0] = 0
dp[1] = 1
dp[2] = 0
dp[3] = 1
dp[4] = 1


if count >= 5:
    for i in range(5, count+1):
        if dp[i-2] == 1 and dp[i-1] == 1:
            dp[i] = 0
        else:
            dp[i] = 1

if dp[count]:
    print("First")
else:
    print("Second")



Measured memory_bytes: 225432
def irohachan(A,B,C):
    if  (A == 5 or A ==7) and (B == 5 or B ==7) and (C == 5 or C ==7) and (A+B+C ==17):
        print("YES")
    else:
        print("NO")

A,B,C = list(map(int, input().split()))
irohachan(A,B,C)

Measured memory_bytes: 3060
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
using namespace std;

#define F first
#define S second
#define pb push_back
#define eb emplace_back
#define PI 3.14159265359
#define sz(c) (int)c.size()
#define len(c) (int)c.length()
#define hcf(a, b) __gcd(a, b)
#define all(c) c.begin(), c.end()
#define vint vector<int>
#define vll vector<ll>
#define vpint vector<pair<int, int>>
#define vpll vector<pair<ll, ll>>
#define fr(it, a, b) \
    for (int it = (a); it < (b); it++)
#define tr(con, it) \
    for (auto it = con.begin(); it != con.end(); it++)
#define present(con, ele) (con.find(ele) != con.end())
#define cpresent(con, ele) (find(all(con), ele) != con.end())
#define maximum(a, b, c) (a > b ? (a > c ? a : c) : (b > c ? b : c))
#define minimum(a, b, c) (a < b ? (a < c ? a : c) : (b < c ? b : c))
typedef long long ll;
typedef long double lf;
typedef pair<int, int> pi;
typedef unsigned long long lu;
const ll mod = 1e9 + 7;
int32_t main()
{
    // freopen("input.txt", "r", stdin);
    // freopen("output.txt", "w", stdout);
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    ll n, ans = 0;
    cin >> n;
    ans = ((n * (n + 1) * (2 * n + 1)) / 6 + (n * (n + 1)) / 2) / 2;
    for (int i = 0; i < n - 1; i++)
    {
        ll u, v;
        cin >> u >> v;
        ans -= min(u, v) * (n - max(u, v) + 1);
    }
    cout << ans << "\n";
    return 0;
}

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

vector<pair<int, int> > a(2010);
long dp[2010][2010];

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

int main(){
	int n, x;
	scanf("%d", &n);
	for(int i = 0; i < n; i++) {
		scanf("%d", &x);
		a.push_back(make_pair(x, i));
	}
	sort(a.begin(), a.end(), greater<pair<int, int> >());
	long ans = 0;
	for(int l = 0; l < n; l++) {
		for(int r = 0; r < n; r++) {
			if(l + r == n) {
				chmax(ans, dp[l][r]);   break;
			}else{
				chmax(dp[l+1][r], dp[l][r] + (long)a[l+r].first * abs(l - a[l+r].second));
				chmax(dp[l][r+1], dp[l][r] + (long)a[l+r].first * abs((n-1-r) - a[l+r].second));
			}
		}
	}
	printf("%ld\n", ans);
}


Measured memory_bytes: 26524
import heapq
from collections import defaultdict
N, K = map(int, input().split())

sushi = defaultdict(list)
for i in range(N):
    t, d = map(int, input().split())
    sushi[t].append(d)

# 各種類で最大のもの
P = []
# Pに入らなかったもの
Q = []

for k in sushi.keys():
    # 最大のものだけ
    sushi[k].sort(reverse=True)
    P.append(sushi[k][0])
    for x in sushi[k][1:]:
        Q.append(-x)

# heapqで最小値を扱う
heapq.heapify(P)
# heapqで最大値を扱う
heapq.heapify(Q)

cur = 0
# 全種類食べることが出来る場合
if K >= len(sushi.keys()):
    max_variation = len(sushi.keys())
    # 全種類について、最大のものを食べる
    cur += sum(P)
    # まだ食べられるので、Qを大きい方から食べる
    for _ in range(K - max_variation):
        cur += -heapq.heappop(Q)
    ans = cur + max_variation**2
# 全種類食べることが出来ない場合
else:
    # 最大値が大きい方からからK種類だけPに残す
    # 選べなかったものはQに突っ込む
    while len(P) > K:
        m = heapq.heappop(P)
        heapq.heappush(Q, -m)
    max_variation = K
    cur += sum(P)
    ans = cur + max_variation**2

# max_variation-1, ..., 1種類食べるとき
for i in range(max_variation - 1, 0, -1):
    # Pのうち、最小のものは一旦諦める
    p = heapq.heappop(P)
    cur -= p

    # 諦めたものをQに入れて、Qから最大のものを1つ食べる
    # 結果的にi種類ではなくなる場合もあるが、無視できる
    heapq.heappush(Q, -p)
    cur += -heapq.heappop(Q)
    ans = max(ans, cur + i**2)

print(ans)


Measured memory_bytes: 98276
#include<iostream>
#include<string>
#include<cstdio>
#include<vector>
#include<cmath>
#include<algorithm>
#include<functional>
#include<iomanip>
#include<queue>
#include<ciso646>
#include<random>
#include<map>
#include<set>
#include<complex>
#include<bitset>
#include<stack>
#include<unordered_map>
#include<utility>
using namespace std;
typedef long long ll;
typedef unsigned int ui;
const ll mod = 1000000007;
typedef long double ld;
const ll INF = 1e+14;
typedef pair<int, int> P;
#define stop char nyaa;cin>>nyaa;
#define rep(i,n) for(int i=0;i<n;i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define per1(i,n) for(int i=n;i>=1;i--)
#define Rep1(i,sta,n) for(int i=sta;i<=n;i++)
typedef complex<ld> Point;
const ld eps = 1e-8;
const ld pi = acos(-1.0);
typedef pair<ld, ld> LDP;
typedef pair<ll, ll> LP;
#define fr first
#define sc second
#define all(c) c.begin(),c.end()
#define pb push_back
 
void Yes(){
	cout<<"Yes"<<endl;
	exit(0);
}
 
void No(){
	cout<<"No"<<endl;
	exit(0);
}

int main(){
  string S;
  cin>>S;
  int N=S.size();
  bool ok=true;
  rep1(i,N){
    if(i%2==0){
      if(S[i-1]=='R')  ok=false;
    }
    else{
      if(S[i-1]=='L') ok=false;
    }
  }
  if(ok) cout<<"Yes"<<endl;
  else cout<<"No"<<endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<algorithm>
using namespace std;

int main(){
	int N;
	cin>>N;
	
	int d[N];
	for(int i=0;i<N;i++){
		cin>>d[i];
	}
	
	int ans;
	sort(d,d+N);
	int min=d[N/2-1];
	//cout<<min<<endl;
	sort(d,d+N,greater<int>());
	int max=d[N/2-1];
	//cout<<max<<endl;
	ans=max-min;
	
	cout<<ans<<endl;
	
	return 0;
	
	
	
}

Measured memory_bytes: 640