akhauriyash/Code-Regression huggingface dataset:
fn main() {
    let buf = io::read_string();
    let mut sc = io::Scanner::new(&buf);
    let n: usize = sc.read();
    let mut f = vec![0; 101];
    f[0] = 1;
    for i in 0..100 {
        if f[i] == 1 {
            for j in 0..25 {
                if i + 4 * j > 100 {
                    break;
                }
                f[i + 4 * j] = 1;
            }
        }
    }

    for i in 0..100 {
        if f[i] == 1 {
            for j in 0..15 {
                if i + 7 * j > 100 {
                    break;
                }
                f[i + 7 * j] = 1;
            }
        }
    }

    println!("{}", if f[n] == 1 {
        "Yes"
    } else {
        "No"
    });
}

#[allow(dead_code)]
mod io {
    use std;
    use std::io::Read;
    use std::str::{FromStr, SplitWhitespace};
    pub struct Scanner<'a> {
        pub iter: SplitWhitespace<'a>,
    }
    impl<'a> Scanner<'a> {
        pub fn new(s: &'a str) -> Scanner<'a> {
            Scanner {
                iter: s.split_whitespace(),
            }
        }
        pub fn read<T: FromStr>(&mut self) -> T {
            self.iter
                .next()
                .unwrap()
                .parse()
                .ok()
                .expect("parsing failed")
        }
        pub fn read_vec<T: FromStr>(&mut self, n: usize) -> Vec<T> {
            (0..n).map(|_| self.read()).collect()
        }
    }
    pub fn read_string() -> String {
        let mut s = String::new();
        std::io::stdin().read_to_string(&mut s).unwrap();
        s
    }
}


Measured memory_bytes: 4476
N = int(input())
L = list(map(int,input().split()))
L.sort()
count = 0
from bisect import bisect_left
for i in range(N - 2):
  for j in range(i + 1, N - 1):    
      count += bisect_left(L, L[i] + L[j]) - 1 - j
      
print(count)

Measured memory_bytes: 3188
def derive_adjacency(animal, statement, neighbor):
    if animal + statement in ['So', 'Wx']:
        return neighbor
    else:
        return 'W' if neighbor == 'S' else 'S'

input()
S = input()
for a, b in ['SS', 'SW', 'WS', 'WW']:
    tmp = derive_adjacency(a, S[0], b) + a + b
    for c in S[1:]:
        tmp += derive_adjacency(tmp[-1], c, tmp[-2])
    if tmp[:2] == tmp[-2:]:
        print(tmp[1:-1])
        break
else:
    print(-1)

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

 public class Main{
// taking inputs
static BufferedReader s1;
static BufferedWriter out;
static String read() throws IOException{String line="";while(line.length()==0){line=s1.readLine();continue;}return line;}
static int int_v (String s1){return Integer.parseInt(s1);}
static long long_v(String s1){return Long.parseLong(s1);}
static int[] int_arr() throws IOException{String[] a=read().split(" ");int[] b=new int[a.length];for(int i=0;i<a.length;i++){b[i]=int_v(a[i]);}return b;}
static long[] long_arr() throws IOException{String[] a=read().split(" ");long[] b=new long[a.length];for(int i=0;i<a.length;i++){b[i]=long_v(a[i]);}return b;}
static void assign(){s1=new BufferedReader(new InputStreamReader(System.in));out=new BufferedWriter(new OutputStreamWriter(System.out));}
static long Modpow(long a,long p,long m){long res=1;while(p>0){if((p&1)!=0){res=(res*a)%m;}p >>=1;a=(a*a)%m;}return res;}
static long Modmul(long a,long b,long m){return ((a%m)*(b%m))%m;}
static long ModInv(long a,long m){return Modpow(a,m-2,m);}
static long nck(int n,int r,long m){if(r>n){return 0l;}return Modmul(f[n],ModInv(Modmul(f[n-r],f[r],m),m),m);}
static long[] f;
static long mod=(long)1e9+7;
//......................................@uthor_Alx..............................................
   static long dis(long x1,long y1){
   		return x1*x1+y1*y1;
   }
   public static void main(String[] args) throws  IOException{
				assign();
				int t=1;//int_v(read()),cn=1;
				while(t--!=0){
					int[] x=int_arr();
					int n=x[0],d=x[1];
					int res=0;
					for(int i=0;i<n;i++){
						long[] p=long_arr();
						if(dis(p[0],p[1])<=(long)d*d) res++;
					}
					out.write(res+"");
					
				}
			    
			    out.flush();

	}
}

	       

	       


Measured memory_bytes: 56992
a, b , k = gets.chomp.split(" ").map(&:to_i)
kizyun = a + b 
if a >= k
    aa = a - k
    bb = b
elsif kizyun >= k && k >= a
    aa = 0
    bb = a + b - k
else
    aa = 0
    bb = 0
end
print aa
print " "
print bb
print "\n"

Measured memory_bytes: 14152
#include <bits/stdc++.h>
#include <cstring>
#include <algorithm>

#define pi 2 * acos(0.00)
#define ll long long
#define fastio ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define nl '\n'
#define null '\0'
#define mx 1000007

using namespace std;


int main()
{
    fastio;

    string a;
    cin>>a;
    if(a=="ARC")    cout<<"ABC\n";
    else if(a=="ABC")   cout<<"ARC\n";
    
}

Measured memory_bytes: 3652
/*
 ID: bradyawn
 PROG: contest
 LANG: C++11
 */

#include <iostream>
#include <algorithm>
#include <iomanip>
#include <fstream>
#include <vector>
#include <deque>
#include <string>
#include <cmath>
#include <map>
#include <unordered_map>
#include <utility>
#include <set>
#include <unordered_set>
#include <ctime>
#include <queue>
#include <stack>
#include <bitset>
#include <random>
#include <cstring>
#include <complex>
#include <cassert>

using namespace std;

typedef long long ll;
typedef pair<int,int> i2;
typedef pair<ll,ll> ll2;

const ll mod = 1e9+7;

int cntA[100001]; //A's  prefix
int cntC[100001]; //C's  prefix
int cntQ[100001]; //?'s  prefix
ll  pow3[100001]; //3 ^ i modded

int getA(int a, int b)
{
    if (a > b) return 0;
    return cntA[b]-cntA[a-1];
}

int getC(int a, int b)
{
    if (a > b) return 0;
    return cntC[b]-cntC[a-1];
}

int getQ(int a, int b)
{
    if (a > b) return 0;
    return cntQ[b]-cntQ[a-1];
}

ll exp3(int cur)
{
    if (cur < 0) cur = 0;
    return pow3[cur];
}

int n;
string s;

int main()
{
    //ifstream inf("");
    //ofstream outf("");
    //cout << setprecision(10);
    ios::sync_with_stdio(0); cin.tie(0);
    
    cin >> s;
    n = s.size();
    s = 'S'+s;

    pow3[0] = 1;
    for (int i = 1; i <= n; i++)
    {
        cntA[i] = cntA[i-1] + (s[i] == 'A');
        cntC[i] = cntC[i-1] + (s[i] == 'C');
        cntQ[i] = cntQ[i-1] + (s[i] == '?');
        pow3[i] = pow3[i-1]*3%mod;
    }
    
    ll ret = 0;
    
    for (int i = 1; i <= n; i++)
    {
        if (s[i] != 'B' && s[i] != '?') continue;
        
        ll A = getA(1, i);
        ll C = getC(i+1, n);
        ll prevQ = getQ(1, i-1); //flag
        ll nxtQ = getQ(i+1, n); //flag
        
        //sum of a's across all possible
        ll x = A*exp3(prevQ) + prevQ*exp3(prevQ-1);
        x %= mod;
        
        //sum of c's across all possible
        ll y = C*exp3(nxtQ) + nxtQ*exp3(nxtQ-1);
        y %= mod;
        
        ret += x*y;
        ret %= mod;
    }
    
    cout << ret << '\n';
    
    return 0;
    
}




Measured memory_bytes: 2284
#include<stdio.h>

int main(void){
    int high, wide;
    int x, y;
    
    while(1){
      scanf("%d %d", &high, &wide);
      if (high == 0 && wide == 0)
          break;
      for(x = 0; x < high; x++){
        for(y = 0; y < wide; y++){
            printf("#");
        }
        printf("\n");
      }
        printf("\n");
    }
    return 0;
}




Measured memory_bytes: 2064
import java.util.*;
import java.math.BigInteger;
// warm-up
public class Main {

	static void solve() {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt()-1;
		BigInteger[] c = {new BigInteger("2"), BigInteger.ONE};
		while (N-->0) {
			BigInteger t = c[0].add(c[1]);
			c[0] = c[1];
			c[1] = t;
		}
		System.out.println(c[1]);
		sc.close();		
	}

	public static void main(String args[]) {
		solve();
	}

}

Measured memory_bytes: 35788
#include <iostream>
#include <algorithm>
#include <utility>
#include <vector>
#include <list>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <string>
#include <sstream>
#include <cstring>
#include <cstdlib>

using namespace std;

#define ALL(c) c.begin(),c.end()
#define RALL(c) c.rbegin(),c.rend()
#define SORT(x) sort((x).begin(),(x).end())
#define REP(i,x,y) for(int i=(x);i<(y);++i)
#define MP(a,b) make_pair((a),(b))
#define debug(x) #x << "=" << (x)
 
#ifdef DEBUG
#define _GLIBCXX_DEBUG
#define dump(x) std::cerr << debug(x) << " (L:" << __LINE__ << ")" << std::endl
#else
#define dump(x)
#endif

typedef long long int ll;
typedef pair<int,int> pii;
//template<typename T> using vec=std::vector<T>;

const int INF=1<<30;
const long long int INF_=1LL<<58;
const double EPS=1e-9;
const int dx[]={1,0,-1,0},dy[]={0,1,0,-1};

template <typename T> ostream &operator<<(ostream &os, const vector<T> &vec){
	os << "[";
	for (const auto &v : vec) {
		os << v << ",";
	}
	os << "]";
	return os;
}

void Solve(){
	const int mod=1000000007;
	int N,W;
	cin >> N >> W;
	
	vector<int> v(N);
	REP(i,0,N) cin >> v[i];
	sort(v.begin(),v.end());

	//static vector<vector<ll>> dp(N,vector<ll>(W+1));
	static ll dp[200][10001];
	ll ans=0,sum=0;
	REP(i,0,N){
		if(sum>W) break;
		dp[i][sum]=1;
		REP(j,i+1,N){
			REP(k,sum,W+1){
				dp[j][k]=dp[j-1][k];
				if(k-v[j]>=0) dp[j][k]=(dp[j][k]+dp[j-1][k-v[j]])%mod;
			}
		}
		//W-w<v[i] <-> w>W-v[i]
		REP(w,W-v[i]+1,W+1) ans=(ans+dp[N-1][w])%mod;
		//fill(dp.begin(),dp.end(),vector<ll>(W+1));
		memset(dp,0,sizeof(dp));
		sum+=v[i];
	}
	if(sum<=W) ++ans;
	
	cout << ans << endl;
}

int main(){
	std::ios::sync_with_stdio(false);
	std::cin.tie(0);
	Solve();
	return 0;
}

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

int N, K;
vector<int> adj[2010];

int dfs(int u, int p, int k) {
    int ret = 1;
    if(!k) return ret;
    for(int i = 0; i < adj[u].size(); i++) {
        int v = adj[u][i];
        if(v == p) continue;
        ret += dfs(v, u, k - 1);
    }
    return ret;
}

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

    for(int i = 0; i < N - 1; i++) {
        int u, v; scanf("%d %d", &u, &v);
        u--; v--;

        adj[u].push_back(v);
        adj[v].push_back(u);
    }

    if(K == 1) {
        printf("%d", N - 2);
        return 0;
    }

    int ans = 0;
    for(int u = 0; u < N; u++) {
        int sum = 0;
        int mx = 0;
        for(int i = 0; i < adj[u].size(); i++) {
            int v = adj[u][i];

            int t1 = dfs(v, u, K / 2 - 1);
            int t2 = dfs(v, u, (K + 1) / 2 - 1);
            sum += t1;
            mx = max(mx, t2 - t1);
        }
        ans = max(ans, 1 + sum + mx);
    }
    printf("%d", N - ans);
}


Measured memory_bytes: 384
Imports System.Collections.Generic
Imports System.Console

Module Program
    Sub Main()
        Dim N As Integer = NextInt()
        Dim L As Integer() = New Integer(2 * N - 1) {}
        For i As Integer = 0 To 2 * N - 1
            L(i) = NextInt()
        Next
        Array.Sort(L)

        Dim ans As Integer
        For i As Integer = 0 To N - 1
            ans += L(2 * i)
        Next

        WriteLine(ans)
    End Sub

    Function NextInt() As Integer
        Return CInt(NextString())
    End Function

    Function NextString() As String
        Dim result As New List(Of Char)
        Do
            Dim tmp As Integer = Read()
            If tmp < 0 Then Exit Do
            Dim nextChar As Char = Chr(tmp)

            If Not Char.IsWhiteSpace(nextChar) Then
                result.Add(nextChar)
            ElseIf nextChar <> vbCr Then
                Exit Do
            End If
        Loop
        Return New String(result.ToArray())
    End Function

End Module


Measured memory_bytes: 21968
#include <iostream>
#include <queue>

using namespace std;

int W, H, N;
char map[1005][1005];
int fact_x[10], fact_y[10];

const int vec_x[] = {-1, 1, 0, 0}, vec_y[] = {0, 0, -1, 1};
int dist[1005][1005];

int main(void)
{
	cin >> H >> W >> N;
	for(int y = 0; y < H; y++){
		for(int x = 0; x < W; x++){
			cin >> map[x][y];
			if(map[x][y] >= '1' && map[x][y] <= '9'){
				fact_x[map[x][y] - '0'] = x;
				fact_y[map[x][y] - '0'] = y;
				map[x][y] = '.';
			}else if(map[x][y] == 'S'){
				fact_x[0] = x;
				fact_y[0] = y;
				map[x][y] = '.';
			}
		}
	}
	
	int ans = 0;
	int sx, sy, gx, gy;
	int cx, cy, nx, ny;
	
	for(int i = 0; i < N; i++){
		
		queue<int> Q;
		
		sx = fact_x[i];
		sy = fact_y[i];
		gx = fact_x[i+1];
		gy = fact_y[i+1];
		
		for(int x = 0; x < W; x++){
			for(int y = 0; y < H; y++){
				dist[x][y] = -1;
			}
		}
		
		Q.push(sx * 10000 + sy);
		dist[sx][sy] = 0;
		
		while((int)Q.size()){
			cx = Q.front() / 10000;
			cy = Q.front() % 10000;
			Q.pop();
			
			for(int dir = 0; dir < 4; dir++){
				nx = cx + vec_x[dir];
				ny = cy + vec_y[dir];
				if(nx < 0 || nx >= W || ny < 0 || ny >= H) continue;
				if(map[nx][ny] != '.' || dist[nx][ny] != -1) continue;
				Q.push(nx * 10000 + ny);
				dist[nx][ny] = dist[cx][cy] + 1;
			}
		}
		
		ans += dist[gx][gy];
	}
	
	cout << ans << endl;
	return 0;
}
	

Measured memory_bytes: 8052
n = gets.to_i
a = gets.split.map(&:to_i)
b = gets.split.map(&:to_i)
c = gets.split.map(&:to_i)
ans = 0
n.times do |i|
    ans += b[a[i]-1]
    if i > 0 && a[i-1]+1 == a[i]
        ans += c[a[i-1]-1]
    end
end
puts ans

Measured memory_bytes: 1916
class Dice:
    """サイコロを操作するクラス"""
    def __init__(self, num):
        self.num = num
    def roll_north(self):
        tmp = self.num[:]
        self.num[0] = tmp[1]
        self.num[1] = tmp[5]
        self.num[4] = tmp[0]
        self.num[5] = tmp[4]
    def roll_east(self):
        tmp = self.num[:]
        self.num[0] = tmp[3]
        self.num[2] = tmp[0]
        self.num[3] = tmp[5]
        self.num[5] = tmp[2]
    def roll_right(self):
        tmp = self.num[:]
        self.num[1] = tmp[3]
        self.num[2] = tmp[1]
        self.num[3] = tmp[4]
        self.num[4] = tmp[2]
    def is_same(self, dice):
        flg = False
        for i in range(20):
            if flg == True:
                break
            self.roll_north()
            for k in range(20):
                if flg == True:
                    break
                self.roll_east()
                for l in range(20):
                    self.roll_right()
                    if dice == self.num:
                        flg = True
                        break
        return flg
    def print_dice(self):
        print(self.num)

dices = []
diff = True # 全部のdiceが異なるかどうか
for i in range(int(input())):
    dices.append(Dice(list(map(int, input().split()))))
for i in dices[1:]:
    diff = diff and not(dices[0].is_same(i.num))
if diff:
    print("Yes")
else:
    print("No")


Measured memory_bytes: 5616
#include <iostream>

using namespace std;
typedef unsigned long long int yen;

int main(){
  int year, n, m, kind, fee;
  double percent;
  yen benefit;
  yen fund;
  yen res;
  yen max_benefit;
  cin >> m;
  for(int i=0;i < m;i++){
    cin >> fund >> year >> n;
    max_benefit = 0;
    for(int j=0;j < n;j++){
      cin >> kind >> percent >> fee;
      res = fund;
      benefit = 0;
      for(int k=0;k < year;k++){
        if(kind){
          res += percent * res - fee;
        }else{
          benefit += percent * res;
          res -= fee;
        }
      }
      max_benefit = max( res + benefit, max_benefit);
    }
    cout << max_benefit << endl;
  }
  return 0;
}

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

int main(void) {
int X,N,x;
bool T=true;
cin >>X >>  N;
  
  vector<int> vec(N);
  for (int i = 0; i < N; i++) {
    cin >> vec.at(i);
  }
  
  vector<int> a = {-1,1};
  for(int j=0;j<N+1;j++){
  	for(int i : a){
  		x=X+i*j;
          for(int k=0;k<N;k++){
        	if(vec.at(k)==x)break;
            if(k==N-1){
              T=false;
              break;
            }
          }
      	if(T==false)break;
  	}
    if(T==false)break;
  }
  
  
  cout << x << endl;
}

  
  

Measured memory_bytes: 3644
import math

N = int(input())

fac = {}
mm = N
#print(mm)
count = 0
while mm % 2 == 0:
    count += 1
    mm //= 2
if count > 0:
    fac[2] = count
f = 3
count = 0
while f ** 2 <= mm:
    while mm % f == 0:
        count += 1
        mm //= f
        #print(f,count)
    if count > 0:
        fac[f] = count
        count = 0
    f += 2
    #print(fac)
if mm != 1:
    if mm in fac:
        fac[mm] += 1
    else:
        fac[mm] = 1
#print(fac)


div = [1]

for x in fac:
    div_ = []
    for y in range(fac[x]+1):
        for z in range(len(div)):
            div_.append(div[z] * (x**y))
    div = div_[:]
M = N
for p in range(len(div)):
    M_ = int(math.log10(max(div[p],N//div[p]))) + 1
    if M_ < M:
        M = M_

print(M)

Measured memory_bytes: 3064
#include <iostream>
using namespace::std;
int N;
int main(){
    cin>>N;
    double odd=0;
    for(int i=1;i<=N;i++){
        if(i%2==1){
            ++odd;
        }
    }
    double ans;
    ans = odd/N;
    cout<<ans;


    return 0;
}

Measured memory_bytes: 256
#include <iostream>

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

const string YES = "Yes";
const string NO = "No";

void solve(ll N, ll A) {
  bool pred = N%500 <= A;
  cout << (pred ? YES : NO) << endl;
}

int main() {
  ll N;
  cin >> N;
  ll A;
  cin >> A;
  solve(N, A);
  return 0;
}


Measured memory_bytes: 256
n,m,x,y = gets.chomp.split(" ").map(&:to_i)
arr_x = gets.chomp.split(" ").map(&:to_i)
arr_y = gets.chomp.split(" ").map(&:to_i)

left = [arr_x.max,x].max
right = [arr_y.min,y].min

if right - left > 0
  puts "No War"
else
  puts "War"
end

Measured memory_bytes: 1788
import java.io.InputStream;
import java.io.PrintStream;
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;

public class Main {
	InputStream in = System.in;
	PrintStream out = System.out;

	boolean check(int x) {
		int a;
		boolean[] z = new boolean[10];
		while (x > 0) {
			a = x % 10;
			z[a] = true;
			x = x / 10;
		}
		return !z[0] && !z[1] && !z[2] && z[3] && !z[4] && z[5] && !z[6] && z[7] && !z[8] && !z[9];
	}

	List<Integer> gen(int k) {
		if (k == 1) {
			List<Integer> result = new ArrayList<>();
			result.add(3);
			result.add(5);
			result.add(7);
			return result;
		}

		List<Integer> result = new ArrayList<>();
		List<Integer> a = gen(k - 1);

		for (int i = 0; i < a.size(); i++) {
			int b = a.get(i);
			result.add(b * 10 + 3);
			result.add(b * 10 + 5);
			result.add(b * 10 + 7);
		}
		return result;

	}

	List<Integer> gen2(int k) {
		List<Integer> result = new ArrayList<>();
		for (int i = 3; i <= k; i++) {
			result.addAll(gen(i));
		}
		return result;
	}

	public void _main(String[] args) {
		Scanner sc = new Scanner(in);

		int n = sc.nextInt();

		int ans = 0;
		List<Integer> g = gen2(9);
		for (int x : g) {
			if (x > n) {
				break;
			}
			if (check(x)) {
				ans++;
			}
		}

		out.println(ans);

		sc.close();

	}

	public static void main(String[] args) {
		new Main()._main(args);
	}

}


Measured memory_bytes: 25300
#include <algorithm>
#include <climits>
#include <iostream>
#include <string>
#include <utility>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <iomanip>
#include <cmath>
#include <stack>
#define rep(i,n) for (int i=0; i<(n); ++i)
using namespace std;
using ll = long long int;

template <class T> ostream &operator<<(ostream &os, vector<T> &v) {
  for (auto i = v.begin(); i != v.end(); i++) {
    os << *i << " ";
  }
  return os;
}

const long long MOD = 1000000007;

int main(){
  vector<int> v(3);
  cin>>v[0]>>v[1]>>v[2];
  sort(v.begin(), v.end());
  int ans = 0;
  while(v[0]!=v[1] or v[1]!=v[2]) {
    if(v[0]!=v[1] and v[1]==v[2]) {
      v[0]+=2;
    } else {
      v[0]++;
      v[1]++;
    }
    ans++;
    sort(v.begin(), v.end());
  }
  std::cout << ans << std::endl;
  return 0;
}


Measured memory_bytes: 256
import Control.Applicative ((<$>))

main :: IO ()
main = solve <$> map read <$> words <$> getLine >>= print

solve :: [Int] -> Int
solve [d, n] | d == 0 = ls !! (n-1)
             | d == 1 = map (*100) ls !! (n-1)
             | otherwise = map (*10000) ls !! (n-1)
  where ls = [1 .. 99] ++ [101]


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

using ll = long long;
#define countof(a) (sizeof(a)/sizeof((a)[0]))
#define rep(i, n) for(int i = 0; i < (n); i++)
#define rep1(i, n) for(int i = 1; i < (n); i++)
#define all(a) begin(a),end(a)
template<class T> istream& operator >> (istream& s, vector<T>& v)
{ for (T& x: v) { s >> x; } return s;}
template<class T> void cout_v(const vector<T>& c)
{ for (int i = 0; i < c.size(); i++) cout << c[i] << endl; }
template<class T> void cout_h(const vector<T>& c)
{ for (int i = 0; i < c.size(); i++) cout << c[i] << (i==c.size()-1?"\n":" "); }
template<class T> inline bool chmin(T& a, T b) {return a>b?a=b,true:false;}
template<class T> inline bool chmax(T& a, T b) {return a<b?a=b,true:false;}
#define SP << " " <<
#define FMT(a) #a<<":"<<a 
#define FMT2(a,b) #a<<":"<<a<<", "<<#b<<":"<<b 
#define FMT3(a,b,c) #a<<":"<<a<<", "<<#b<<":"<<b<<", "<<#c<<":"<<c 
#define FMT4(a,b,c,d) #a<<":"<<a<<", "<<#b<<":"<<b<<", "<<#c<<":"<<c<<", "<<#d<<":"<<d 
void Yes(bool f){cout<<(f?"Yes":"No")<<endl;}


int main()
{
    cin.tie(0); ios::sync_with_stdio(false);
 
    string s;
    int K;
    cin >> s >> K;

    vector<string> ss(25000);

    int i_ss = 0;
    rep(i, s.size()) {
        for (int j = 0; j < K; j++) {
            if (i - j >= 0) ss[i_ss++] = s.substr(i-j, j+1);
            else break;
        }
    }
    ss.resize(i_ss);
    sort(all(ss));
    unique(all(ss));

    cout << ss[K-1] << endl;
}


Measured memory_bytes: 1664
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define ull unsigned long long int
#define ld long double
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define endl "\n"
#define intarr(arr, n)  ll arr[n];  for (ll i = 0; i < n; i++)  cin >> arr[i]
#define inpvec(vec,n) for(ll i=0;i<n;i++){ll var;cin>>var;vec.push_back(var);}
#define ff first
#define ss second
#define pb push_back
#define mkp make_pair
#define vec vector<ll>
#define pi pair<ll,ll>
#define changeline cout<<endl
#define loop(i,a,b) for(ll i=a;i<b;i++)
#define rev(i,a,b) for(ll i=a;i>=b;i--)
#define all(v) v.begin(),v.end()
#define mod2 998244353
#define NO cout << "NO" <<endl
#define YES cout << "YES" <<endl
#define mem(arr,val) memset(arr,val,sizeof(arr));
const ll mod=1e9+7;
#define piii 3.14159265358979323846264338327950
#define print(a, n, m)     for (ll i = n; i < m; i++) {  cout << a[i] << " "; }  cout << endl
#define con continue

bool prime(ll n) 
{ 
    if (n <= 1)  return false; 
    if (n <= 3)  return true; 
    if (n%2 == 0 || n%3 == 0) return false; 
  
    for (ll i=5; i*i<=n; i=i+6) 
        if (n%i == 0 || n%(i+2) == 0) 
           return false; 
  
    return true; 
}
bool isPerfectSquare(ll x) {   
  long double sr = sqrt(x); 
  return ((sr - floor(sr)) == 0); 
} 
bool subsequence_checker(string str1, string str2, ll m, ll n) 
{ 
    if (m == 0) return true; 
    if (n == 0) return false; 
    if (str1[m-1] == str2[n-1]) 
        return subsequence_checker(str1, str2, m-1, n-1); 
    return subsequence_checker(str1, str2, m, n-1); 
}
bool cmp(const pair<int,int> &a,  const pair<int,int> &b) 
{ 
    if(a.ff == b.ff)
        return a.ss < b.ss;
    return (a.ff > b.ff); 
}
//////////////////////////////////////////////////// Lets Do It ////////////////////////////////////////////////////////
int gcd(int p, int q){
if(p % q == 0)return q;
return gcd(q, p % q);
}

ull findProductSum(ull A[], ull n) 
{ 

    ull array_sum = 0; 
    for (ull i = 0; i < n; i++) 
        array_sum = array_sum + A[i]; 
  
    ull array_sum_square = (array_sum * array_sum )%mod; 
  
    ull individual_square_sum = 0; 
    for (ull i = 0; i < n; i++) 
        individual_square_sum += (A[i]*A[i])%mod; 
  
    return (((array_sum_square - individual_square_sum)%mod)/2)%mod; 
} 
void solve()
{

    // ull n;
    // cin>>n;
    // ull a[n];
    // loop(i,0,n)
    // {
    //     cin>>a[i];
    // }

    // cout<< findProductSum(a,n);

    //cout<<ans;
    ll n;
    cin>>n;
    vec a;
    inpvec(a,n);
    
    ll suf[n];
    suf[n-1]=a[n-1];
    rev(i,n-2,0){
        suf[i]=(suf[i+1]+a[i])%mod;
    }
    ll res=0;
    
    loop(i,0,n-1){
        res=(res+(a[i]*suf[i+1])%mod)%mod;
    }
    
    cout<<res;

    return;
}
 
int main()
{
#ifndef ONLINE_JUDGE
  freopen("input.txt", "r", stdin);
  freopen("output.txt", "w", stdout);
#endif
    IOS;
    ll t;
    //cin>>t;
    t=1;

    while(t--){
        solve();
        cout<<endl;
    }

    cerr << "\nTime elapsed: " << 1000 * clock() / CLOCKS_PER_SEC << "ms\n";
    return 0;
} 



Measured memory_bytes: 6312
//  C - Grid Repainting 2
// https://abc096.contest.atcoder.jp/tasks/abc096_c
//
#include <iostream>
#include <vector>
using namespace std;


string solve(vector<vector<char>> pict, unsigned int h, unsigned int w) {
    vector<int> dx = {0, 0, -1, 1};
    vector<int> dy = {-1, 1, 0, 0};
    bool is_valid = true;

    for (int cy = 0; cy < h; ++cy) {
        for (int cx = 0; cx < w; ++cx) {
            if (pict[cy][cx] == '#') {
                is_valid = false;
                for (int i = 0; i < 4; ++i) {
                    int nx = cx + dx[i];
                    int ny = cy + dy[i];
                    if ((0 <= nx && nx < w) && (0 <= ny && ny < h)) {
                        if (pict[ny][nx] == '#') {
                            is_valid = true;
                            break;
                        }
                    }
                }
                if (!is_valid)
                    return "No";
            }
        }
    }
    return "Yes";
}


int main(void) {
    unsigned int h, w;
    cin >> h >> w;
    vector<vector<char>> pict(h);
    for (int y = 0; y < h; ++y) {
        pict[y].resize(w);
        for (int x = 0; x < w; ++x)
            cin >> pict[y][x];
    }

    string ans = solve(pict, h, w);
    cout << ans << endl;
}







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

#define pb(a) push_back(a)

typedef long long ll;
const ll inf = 1e9+7;
const int MAX_N = 1e5+5;
int dx[] = {-1,0,1,0},dy[] = {0,1,0,-1};
vector<ll> prime;

ll inv[MAX_N],fac[MAX_N];

template <class T = ll> T in(){T x;cin >> x;return x;}

inline ll GCD(ll a,ll b){ll c;while(b!=0){c=a%b;a=b;b=c;}return a;}
inline ll LCM(ll a,ll b){return a*b/GCD(a,b);}
inline ll POW(ll a,ll b){ll c=1;while(b>0){if(b&1){c=a*c%inf;}a=a*a%inf;b>>=1;}return c;}
inline void _nCr(){fac[0]=1;for(int i=1;i<MAX_N;i++){fac[i]=fac[i-1]*i%inf;}for(int i=0;i<MAX_N;i++){inv[i]=POW(fac[i],inf-2);}}
inline ll nCr(ll n,ll r){return (fac[n]*inv[r]%inf)*inv[n-r]%inf;}
inline void PRI(ll n){bool a[n+1];for(int i=0;i<n+1;i++){a[i]=1;}for(int i=2;i<n+1;i++){if(a[i]){prime.pb(i);ll b=i;while(b<=n){a[b]=0;b+=i;}}}}

class UnionFind {
private:
    int par[MAX_N];
    int rank[MAX_N];
public:
    void init(int n);
    int find(int x);
    void unite(int x,int y);
    bool same(int x,int y);
};

void UnionFind::init(int n) {
    for (int i = 0;i < n;i++) {
        par[i] = i;
        rank[i] = 0;
    }
}

int UnionFind::find(int x) {
    if (par[x] == x) return x;
    else return par[x] = find(par[x]);
}

void UnionFind::unite(int x,int y) {
    x = find(x);
    y = find(y);
    if (rank[x] < rank[y]) par[x] = y;
    else {
        par[y] = x;
        if (rank[x] == rank[y]) rank[x]++;
    }
}

bool UnionFind::same(int x,int y) {
    x = find(x);
    y = find(y);
    return x == y;
}

int main() {
    int n;cin >> n;
    double btc=0;int jpy=0;
    for (int i = 0;i < n;i++) {
        double x = in<double>();string y = in<string>();
        if (y=="JPY") jpy+=x;
        else btc+=x;
    }
    cout << jpy+btc*380000.0 << endl;
}

Measured memory_bytes: 256
#define _CRT_SECURE_NO_WARNING

#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<algorithm> 
using namespace std;
typedef long long ll;
char ch[30];
int main()
{
	ll a,i,p=0;
	scanf("%s",ch);
	sscanf(ch,"%lld",&a);
	for(i=0;i<strlen(ch);i++)
	{
		p+=ch[i]-'0';
	}
	if(a%p==0) printf("Yes\n");
	else printf("No\n");
	return 0;
}

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

Measured memory_bytes: 256
N,K = map(int,input().split())
x = [0 for i in range(N)]
y = [0 for i in range(N)]
p = [0 for i in range(N)]
q = [0 for i in range(N)]
for i in range(N):
    x[i],y[i] = map(int, input().split())
    p[i]=x[i]
    q[i]=y[i]
x.sort()
y.sort()
S = [[0 for i in range(N+1)]for i in range(N+1)]
for n in range(N):
    for i in range(N):
        for j in range(N):
            if p[n]<=x[i] and q[n]<=y[j]:
                S[i+1][j+1]+=1
R=(x[N-1]-x[0])*(y[N-1]-y[0])
for a in range(N):
    for b in range(N):
        for c in range(a,N):
            for d in range(b,N):
                if (S[a][b]+S[c+1][d+1]-S[a][d+1]-S[c+1][b])>=K:
                    if (x[c]-x[a])*(y[d]-y[b])<R:
                        R=(x[c]-x[a])*(y[d]-y[b])
print(R)


Measured memory_bytes: 45036
#include<bits/stdc++.h>
using namespace std;
#define int long long int
#define until(x) while(!(x))
#define unless(x) if(!(x))
#define all(x) (x).begin(),(x).end()
#define F first
#define S second
#define pc __builtin_popcount

int ar[100005];
pair<int,int> qs[100005];
int n,q;

int32_t main(){
	cin>>n>>q;
	for(int i=1;i<=n;i++){
		cin>>ar[i];
	}
	sort(ar+1,ar+n+1);
	for(int i=1;i<=q;i++){
		cin>>qs[i].S>>qs[i].F;
	}
	sort(qs+1,qs+q+1,greater<pair<int,int> >());
	int i=1,j=1;
	while(qs[i].F>ar[j] && j<=n && i<=q){
		int k;
		for(k=0;k<qs[i].S && qs[i].F>ar[j+k] && (j+k)<=n;k++){
			ar[j+k]=qs[i].F;
			//cout<<qs[i].F<<" "<<k<<" "<<qs[i].S<<" "<<j+k<<"\n";
		}
		j+=k;
		i++;
		//cout<<j<<"\n";
	}
	int ans = 0;
	for(int i=1;i<=n;i++){
		//cout<<ar[i]<<" ";
		ans += ar[i];
	}
	cout<<ans;
}


Measured memory_bytes: 2560
//K-OS WITH THE OCDE

#pragma GCC optimize("Ofast")
#pragma GCC target("avx,avx2,fma")
#pragma GCC optimization ("unroll-loops")

#include <iostream>
#include <numeric>
#include <iomanip>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <cmath>
#include <vector>
#include <set>
#include <stack>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <queue>
#include <deque>
#include <ctime>
#include <cassert>
#include <complex>
#include <string>
#include <cstring>
#include <climits>

using namespace std;

typedef long long int ll;
typedef long double db;


#define TEST ll t; cin>>t; while(t--)
#define vell vector<ll>
#define pl pair<ll,ll>
#define all(v) v.begin(),v.end()
#define pb push_back
#define ff first
#define ss second
#define mp make_pair
#define dbg(x)  cerr << #x << ": "<< x <<endl
#define dbg2(x,y) cerr<< #x <<": "<< x <<" || "<< #y << ": " << y << endl

#define endl "\n"
#define MAX 1e18
#define MIN INT_MIN
#define mod 1000000007



void solve()
{
     db d , t , s;
     cin >> d >> t >> s;

     db tt = d/s;

     if(tt <= t)
        cout << "Yes";
    else
        cout << "No";
}

int main()
{
    #ifndef ONLINE_JUDGE
        freopen("input.txt", "r", stdin);
        freopen("output.txt", "w", stdout);
    #endif
    ios_base::sync_with_stdio(0);cin.tie(0);   
    //TEST
     solve();
}



Measured memory_bytes: 3744
/*
 Shahadat Hossain
 I.C.T Department
 Comilla University
 Session: 2013-2014
 */

#include<bits/stdc++.h>
using namespace std;

//#define int long long
#define valid(x,y) x>=0 && y>=0 && x<n && y<n
#define all(x) x.begin(),x.end()
#define pb(x) push_back(x)
#define sz(x) (int)x.size()
#define ms(a,b) memset(a, b, sizeof(a))
#define eps 1e-5
#define input freopen("/Users/shahadat/Desktop/input.txt", "r", stdin)
#define output freopen("/Users/shahadat/Desktop/output.txt", "w", stdout)
#define d(x) cout << #x << " = " << x << endl
#define dd(x,y) cout << #x << " = " << x << "   " << #y << " = " << y << endl
#define ddd(x,y,z) cout << #x << " = " << x << "   " << #y << " = " << y << "   " << #z << " = " << z << endl
//fprintf(stdout,"\nTIME: %.3lf sec\n", (double)clock()/(CLOCKS_PER_SEC));
//int gcd(int n,int m){return m==0?n:gcd(m,n%m);}
#define bit(n,k) (((n)>>(k))&1)
#define UNIQUE(X) (X).erase(unique(all(X)),(X).end())
#define SORT_UNIQUE(c) (sort(c.begin(),c.end()), c.resize(distance(c.begin(),unique(c.begin(),c.end()))))
#define pr(x) {cout << (x) << '\n';  }
#define GET_POS(c,x) (lower_bound(c.begin(),c.end(),x)-c.begin())
#define mask(i) ((1LL<<(i)))
#define endl '\n'
double const PI = acos(-1);
int gcd(int n,int m){return m==0?n:gcd(m,n%m);}

using namespace std;
typedef long long ll;
typedef pair<int, int> ii;
typedef vector<ii> vii;
typedef vector<int> vi;

int const N = 1e5+10;
int const M = 505;
int const MOD = 998244353;
const int INF = 1e9 + 5;

void solve(){
    int n, k;
    cin >> n >> k;
    
    vector<int> h(n);
    for(int& x: h)
        cin >> x;
    
    vector<int> dp(n, INF);
    
    dp[0] = 0;
    for(int i = 0; i < n; i++){
        for(int j = i + 1; j <= i + k; j++){
            if(j < n)
                dp[j] = min(dp[j], dp[i] + abs(h[i] - h[j]));
        }
    }
    cout << dp[n - 1] << endl;
}

int32_t main(){
    solve();
}


Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std ;
#define async ios_base::sync_with_stdio(false); cin.tie(NULL);
#define Int long long int
#define let auto
#define of :
#define all(y) y.begin(), y.end()
#define present( x, y ) (x.find( y ) != x.end())
#define _matrix(T) vector<vector<T>>
template<class T>
auto matrix( int r, int c, T v ){
	return vector<vector<T>>( r, vector<T>( c, v ) ) ;
}
const int mod = (int)1e9 + 7 ;
const int inf = (int)1e18 ;
void mxz( int &a, int b ){
	a = max( a, b ) ;
}

signed main(){
	int T ; cin >> T ;
	if( T >= 30 ) cout << "Yes" ;
	else cout << "No" ;
	return 0 ;
}


Measured memory_bytes: 3536
#
# 　　  ⋀_⋀　 
#　　  (･ω･)  
# .／ Ｕ ∽ Ｕ＼
#  │＊　合　＊│
#  │＊　格　＊│ 
#  │＊　祈　＊│ 
#  │＊　願　＊│ 
#  │＊　　　＊│ 
#      ￣
#
import sys
sys.setrecursionlimit(10**6)
input=sys.stdin.readline
from math import floor,sqrt,factorial,hypot,log #log2ないｙｐ
from heapq import heappop, heappush, heappushpop
from collections import Counter,defaultdict,deque
from itertools import accumulate,permutations,combinations,product,combinations_with_replacement
from bisect import bisect_left,bisect_right
from copy import deepcopy
from fractions import gcd
from random import randint
def ceil(a,b): return (a+b-1)//b
inf=float('inf')
mod = 10**9+7
def pprint(*A): 
    for a in A:     print(*a,sep='\n')
def INT_(n): return int(n)-1
def MI(): return map(int,input().split())
def MF(): return map(float, input().split())
def MI_(): return map(INT_,input().split())
def LI(): return list(MI())
def LI_(): return [int(x) - 1 for x in input().split()]
def LF(): return list(MF())
def LIN(n:int): return [I() for _ in range(n)]
def LLIN(n: int): return [LI() for _ in range(n)]
def LLIN_(n: int): return [LI_() for _ in range(n)]
def LLI(): return [list(map(int, l.split() )) for l in input()]
def I(): return int(input())
def F(): return float(input())
def ST(): return input().replace('\n', '')

# UnionFind
class UnionFind():
    def __init__(self, n):
        self.nodes=[-1] * n  # nodes[x]: 負なら、絶対値が木の要素数

    def get_root(self, x):
        # nodes[x]が負ならxが根
        if self.nodes[x] < 0:
            return x
        # 根に直接つなぎ直しつつ、親を再帰的に探す
        else:
            self.nodes[x]=self.get_root(self.nodes[x])
            return self.nodes[x]

    def unite(self, x, y):
        root_x=self.get_root(x)
        root_y=self.get_root(y)
        # 根が同じなら変わらない
        # if root_x == root_y:
        # pass
        if root_x != root_y:
            # 大きい木の方につないだほうが計算量が減る
            if self.nodes[root_x] < self.nodes[root_y]:
                big_root=root_x
                small_root=root_y
            else:
                small_root=root_x
                big_root=root_y
            self.nodes[big_root] += self.nodes[small_root]
            self.nodes[small_root]=big_root

def main():
    N,M,K=MI()
    uf=UnionFind(N)
    get_root, unite, nodes=uf.get_root, uf.unite, uf.nodes
    
    friend_cnt = [0]*N
    ans = [0]*N
    for _ in range(M):
        a,b = MI_()
        unite(a,b)
        friend_cnt[a]+=1
        friend_cnt[b]+=1
    for i in range(N):
        ans[i] = -nodes[get_root(i)]-1-friend_cnt[i]
    for _ in range(K):
        a,b = MI_()    
        if get_root(a)==get_root(b):
            ans[a]-=1
            ans[b]-=1
    print(*ans)
    
if __name__ == '__main__':
    main()

Measured memory_bytes: 103924
/*2019/09/13 */
#include<stdio.h>
#include<stdlib.h>
#include<math.h>
#include<string.h>
#define MOD 1000000007
#define MIN 999999999
#define MAX -999999999
typedef long long int ll;
typedef unsigned long long int ull;
void llswap(ll *x,ll *y){ll tmp;tmp=*x;*x=*y;*y=tmp;}
void swap(int *x,int *y){int tmp;tmp=*x;*x=*y;*y=tmp;}
int rmax(int x,int y){return x>y?x:y;}
int rmin(int x,int y){return x>y?y:x;}
ll llrmax(ll x,ll y){return x>y?x:y;}
ll llrmin(ll x,ll y){return x>y?y:x;}
int asc(const void *a,const void *b){return *(int*)a-*(int*)b;}
int desc(const void *a,const void *b){return *(int*)b-*(int*)a;}
int llasc(const void *a,const void *b){return *(ll*)a-*(ll*)b;}
int lldesc(const void *a,const void *b){return *(ll*)b-*(ll*)a;}
int gcd(int x,int y){if(y==0)return x;return gcd(y,x%y);}
/*
int asc_t(const void *a,const void *b){return ((struct_t*)a)->member - ((struct_t*)b)->member;}
int desc_t(const void *a,const void *b){return ((struct_t*)b)->member - ((struct_t*)a)->member;}
*/

int main(){
    int n,a[200000];
    int num[200000]={};
    scanf("%d",&n);
    for(int i=0;i<n;i++){
        scanf("%d",&a[i]);
        num[a[i]]++;
    }
    int cnt=0;
    int max=MAX;
    qsort(a,n,sizeof(int),asc);
    for(int i=0;i<n;i++){
        if(a[i]==0){
            cnt=num[a[i]]+num[a[i]+1];
        }else{
            cnt=num[a[i]-1]+num[a[i]]+num[a[i]+1];
        }
        if(max<cnt)max=cnt;
    }
    
    printf("%d\n",max);
    return 0;
}

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

Measured memory_bytes: 3060
#include <iostream>
#include<stdio.h>
using namespace std;

int main()
{
   int x,s=0;
   for(int i=0;i<3;i++){
    scanf("%d",&x);
        s+=x;
    }
    if(s>=22){
        printf("bust");
    }
    else{
        printf("win");
    }
    return 0;
}


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

#define irep(i,n) for(int i = 0; i < (int)(n); i++)
#define irep2(i,a,n) for(int i = (int)(a); i <= (int)(n); i++)
#define irrep(i,n) for(int i = (int)(n-1); i > -1; i--)
#define irrep2(i,n,a) for(int i = (int)(n); i >= (int)(a); i--)

#define fi first
#define se second

using namespace std; 

using ll = long long;
using v_int = vector<int>;
using v2_int = vector<v_int>;
using v_ll = vector<ll>;
using v2_ll = vector<v_ll>;
using v_string = vector<string>;
using v_bool = vector<bool>;
using v2_bool = vector<v_bool>;
using pii = pair<int, int>;
using mii = map<int, int>;

const double PI = 3.1415926535897932;
const int INF = (int)2e9;
const ll LINF = (ll)2e18;
const ll MOD = 1000000007;
const int dc[8] = {1, -1, 0,  0, 1, -1,  1, -1};
const int dr[8] = {0,  0, 1, -1, 1,  1, -1, -1};

template<typename T, typename U> inline
ostream& operator<<(ostream &o, pair<T,U> &p) {
    return o << "{" << p.first << "," << p.second << "}";
}
template<typename T> inline
istream& operator>>(istream &is, vector<T> &vec) {
    for(auto &v : vec) { is >> v; }
    return is;
}
template<typename T> inline
ostream& operator<<(ostream &os, vector<T> &vec) {
    for(auto &v : vec) { os << v << ",";} 
    return os;
}
template<typename T> inline
ostream& operator<<(ostream &os, vector<vector<T> > &mat) {
    for(auto &row : mat) { os << row << endl; }
    return os;
}
template<typename T> inline
void chmin(T &a, T b) { a = min(a, b); }
template<typename T> inline
void chmax(T &a, T b) { a = max(a, b); }

int main(void)
{
    int x;
    cin >> x;

    if(x >= 30) {
        cout << "Yes" << endl;
    } else {
        cout << "No" << endl;
    }
    return 0;
}

/*atcoder*/



Measured memory_bytes: 3620
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;

int main() {
    string s;
    cin >> s;

    int n = s.length();

    int ans = 0;
    int l = 0, r = n - 1;
    while (l <= r) {
        if (s[l] != 'x' && s[r] != 'x' && s[l] != s[r]) {
            cout << -1 << endl;
            return 0;
        }
        if (s[l] == s[r]) {
            l++;
            r--;
        } else if (s[l] == 'x') {
            ans++;
            l++;
        } else {
            ans++;
            r--;
        }
    }

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


Measured memory_bytes: 512
#include <algorithm>
#include <iostream>
#include <stack>
#include <queue>
#include <cmath>
#include <string>
#include <iterator>
#include <map>
#include <set>
#include <iomanip>
#include <vector>
#include <cstdint>
using namespace std;
using ll = long long;
using ld = long double;
using P = pair<ll, ll>;
using Graph = vector<vector<int>>;
int dx[] = {0, 1, 0, -1};
int dy[] = {1, 0, -1, 0};
#define rep(i, N) for(int i = 0; i < N; i++)
#define rep2(i, l, r) for (ll i = (ll)l; i < (ll)(r); i++)
#define INF 1000000000000000
#define MAX 200001

#pragma GCC target("avx2")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
const ll MOD = 1000000007;

template <typename T > inline string toString(const T &a) {ostringstream oss; oss << a; return oss.str();};

int main(){
    int N;
    cin >> N;
    vector<int> c(N);
    rep(i,N) cin >> c[i];
    vector<int> color(200005,-1);
    vector<ll> dp(N+1,0);
    dp[0] = 1;
    rep(i,N){
        if(color[c[i]] == -1){
            dp[i+1] += dp[i];
            dp[i+1] %= MOD;
            color[c[i]] = i+1;
        }
        else{
            if(color[c[i]] != i){ 
                dp[i+1] += dp[color[c[i]]] + dp[i];
            }
            else dp[i+1] = dp[i];
            dp[i + 1] %= MOD;
            color[c[i]] = i+1;
        }
    }
    cout << dp[N] << endl;
}

Measured memory_bytes: 6424
#include <iostream>
#include <algorithm>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <string.h>
#include <vector>
#include <queue>
#include <cmath>
#include <bitset>
#include <complex>
#include <functional>
#include <numeric>
#include <iomanip>

// output
#define SPBR(w, n) std::cout<<(w + 1 == n ? '\n' : ' ');
#define YES cout << "YES" << endl
#define Yes cout << "Yes" << endl
#define NO cout << "NO" << endl
#define No cout << "No" << endl
// utility
#define ALL(i) (i).begin(), (i).end()
#define FOR(i, a, n) for(int i=(a);i<(n);++i)
#define RFOR(i, a, n) for(int i=(n)-1;i>=(a);--i)
#define REP(i, n) for(int i=0;i<int(n);++i)
#define RREP(i, n) for(int i=int(n)-1;i>=0;--i)
#define IN(a, x, b) (a<=x && x<b)
#define OUT(a, x, b) (x<a || b<=x)
template<class T> inline T chmax(T & a, const T b) { return a = (a < b) ? b : a; }
template<class T> inline T chmin(T& a, const T b) { return a = (a > b) ? b : a; }

// type/const
#define int ll
using ll = long long;
using ull = unsigned long long;
using ld = long double;
const int MOD = 1000000007;
/* const int MOD = 998244353; */
const int INF = 1e18;
const double PI = acos(-1);

using namespace std;
struct INIT { 
  INIT(){cin.tie(0); ios::sync_with_stdio(false);
  cout << fixed << setprecision(10);
}}INIT;


signed main() {
  int N, X, Y; 
  cin >> N >> X >> Y;
  X--; Y--;

  vector<int> dist(N, 0);
  REP(i, N) FOR(j, i+1, N){
    if(i == j) continue;
    dist[min(j-i, 1+min(abs(X-i)+abs(Y-j), abs(Y-i)+abs(X-j)))]++;
  }

  FOR(i, 1, N){
    cout << dist[i] << "\n";
  }

  return 0;
}

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

N = INT()
A = LIST()

if len(A) == len(set(A)):
  print("YES")
else:
  print("NO")

Measured memory_bytes: 27256
#include <iostream>
#include <fstream>
#include <set>
#include <map>
#include <string>
#include <vector>
#include <bitset>
#include <algorithm>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <cassert>
#include <queue>

#define mp make_pair
#define pb push_back


typedef long long ll;
typedef long double ld;

using namespace std;
const ll MOD = 1e9 + 7;
int n, k;
ll dp[5100];
int a[5100];

void add(int x) {
	for (int i = k - 1; i >= x; --i)
		dp[i] = (dp[i] + dp[i - x]) % MOD;
}

void del(int x) {
	for (int i = 0; i < k - x; ++i) {
		dp[i + x] = (dp[i + x] - dp[i] + MOD) % MOD;
	}
}


int main() {
	cin >> n >> k;
	for (int i = 0; i < n; ++i) {
		cin >> a[i];
		a[i] = min(a[i], k);
	}
	dp[0] = 1;
	for (int i = 0; i < n; ++i)
		add(a[i]);
	int ans = 0;
	for (int i = 0; i < n; ++i) {
		del(a[i]);
		int l = k - a[i];
		int fl = 0;
		for (int j = l; j < k; ++j)
			if (dp[j]) {
				fl = 1;
				break;
			}
		if (!fl)
			ans += 1;
		add(a[i]);
	}
	cout << ans << "\n";
	return 0;
}




Measured memory_bytes: 256
#include <stdio.h>
#include <string.h>

int main(void) {
	char heya[101][102];
	int tootta[101][101];
	int x,y;
	int xmax,ymax;
	int loop;
	while(1) {
		scanf("%d %d",&ymax,&xmax);
		if(xmax==0 && ymax==0)break;
		for(y=0;y<ymax;y++)scanf("%s",heya[y]);
		memset(tootta,0,sizeof(tootta));
		x=0;y=0;
		loop=0;
		while(heya[y][x]!='.') {
			if(tootta[y][x]) {
				puts("LOOP");
				loop=1;
				break;
			}
			tootta[y][x]=1;
			switch(heya[y][x]) {
				case '>':
					x++;
					break;
				case '<':
					x--;
					break;
				case '^':
					y--;
					break;
				case 'v':
					y++;
					break;
			}
		}
		if(loop==0)printf("%d %d\n",x,y);
	}
	return 0;
}

Measured memory_bytes: 0
import java.util.*;

class Main {
  public static void main(String args[]){
    Scanner sc = new Scanner(System.in);
    
    int n = sc.nextInt();
    String list[] = new String[n];
    for (int i = 0; i < n; i++)
      list[i] = sc.next();
    int m = sc.nextInt();
    int flag = 0;
    for (int i = 0; i < m; i++) {
      String s = sc.next();
      for (int j = 0; j < n; j++) {
        if (s.equals(list[j])) {
          if (flag % 2 == 0)
            System.out.println("Opened by " + s);
          else
            System.out.println("Closed by " + s);
          flag++;
          break;
        }
        else if (j == n - 1)
          System.out.println("Unknown " + s);
      }
    }
  }
}



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

int main() {
	
	long long X, K, D;

	cin >> X >> K >> D;
	X = abs(X);

	if (X/D >= K)
		X = X- D*K;
	else {
		long long A = X / D;
		X -= A * D;
		if ((K - A) % 2 == 1) X = abs(X - D);
	}

	cout << X << endl;

}

Measured memory_bytes: 3588
#include <bits/stdc++.h>
using namespace std;
using ll = long long;

int main()
{
	ll N, A, B, C, D;
	cin >> N >> A >> B >> C >> D;
	B -= A;
	N--;
	ll mi = C * N, ma = D * N;
	bool res = false;
	for (int i = 0; i <= N; i++) {
		if (mi <= B && B <= ma) {
			res = true;
			break;
		}
		ma -= D + C;
		mi -= D + C;
	}
	cout << (res ? "YES" : "NO") << endl;
	return 0;
}


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

#define REP(i, a, b) for (int i = int(a); i < int(b); i++)
#define dump(val) cerr << __LINE__ << ":\t" << #val << " = " << (val) << endl

using namespace std;

typedef long long int lli;

template<typename T>
vector<T> make_v(size_t a, T b) {
    return vector<T>(a, b);
}

template<typename... Ts>
auto make_v(size_t a, Ts... ts) {
    return vector<decltype(make_v(ts...))>(a, make_v(ts...));
}

int main() {
    int N, K;
    cin >> N >> K;
    cout << ((N % K) != 0) << endl;
    return 0;
}


Measured memory_bytes: 256