akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include <algorithm>
#include<string>
#include<math.h>
#include <functional>
using namespace std;

int main(void) {
	int N, M;
	int A[100000];
	long long int ans = 0;
	cin >> N >> M;
	//データを格納，加工(mod M) 
	for (int i = 0;i < N;i++) {
		int n = 0;
		cin >> n;
		A[i] = n%M;
	}
	//累積和を求める(mod M)
	for (int i = 1;i < N;i++) {
		A[i] += A[i - 1];
		A[i] = A[i] % M;
	}
	sort(A, A + N);
	int s = 1;
	for (int i = 0;i < N - 1;i++) {
		//1つだけ選ぶものを加算
		if (A[i] == 0)
			ans++;
		//同じ値のものが何個あるかカウント
		if (A[i] == A[i + 1]) {
			s++;
		}
		//同じ値のものがこれ以上ない＝その値のものは数え終わり
		//同じ値のものがs(>=2)個あるとすると sC2組の組み合わせがあるのでansをその分増やす
		else if (s >= 2) {
			ans += (long long int)s*(s - 1) / 2;
			s = 1;
		}
	}
	if (A[N - 1] == 0)
		ans++;
	if (s >= 2) {
		ans += (long long int)s*(s - 1) / 2;
		s = 1;
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 640
N,D = map(int, input().split())
X = [list(map(int, input().split())) for _ in range(N)]

flg = 0
for i in range(N):
    for j in range(i, N):
        if i==j:
            continue
        d = 0
        for k in range(D):
            d += pow((X[i][k] - X[j][k]), 2)
        if pow(d, 0.5).is_integer():
            flg += 1
print(flg)


Measured memory_bytes: 3060
package main

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

var sc = bufio.NewScanner(os.Stdin)

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

func StrToInt(s string) int {
  n,_ := strconv.Atoi(s)
  return n
}

func Abs(n int) int {
   return int(math.Abs(float64(n)))
}

func IsOdd (n int) bool {
  return n % 2 == 1
}

func main() {
	var n int 
    n = StrToInt(NewLine())
    t := []int{0}
    x := []int{0}
    y := []int{0}
    
  for i:=0;i<n;i++{
    nums := strings.Split(NewLine()," ")
    t = append(t, StrToInt(nums[0]))
    x = append(x, StrToInt(nums[1]))
    y = append(y, StrToInt(nums[2]))
  }

  ans := true
  for i:=0;i<n;i++{
    time := Abs(t[i+1] - t[i])
    dis := Abs(x[i+1] - x[i]) + Abs(y[i+1] - y[i])
    
 
     if time <  dis || IsOdd(time) != IsOdd(dis) {
        ans = false
    }
    
  }
  
  if ans {
    fmt.Println("Yes")
  } else {
    fmt.Println("No")
  }
}

Measured memory_bytes: 6912
#include<bits/stdc++.h>
using namespace std;
int dp[3][100001];

int main(){
      int n, a, b, c;
      cin>>n;
      dp[0][0]=dp[1][0]=dp[2][0]=0;
      for(int i=1; i<=n; i++)
      {
            cin>>a>>b>>c;
            dp[0][i]=a+max(dp[1][i-1], dp[2][i-1]);
            dp[1][i]=b+max(dp[0][i-1], dp[2][i-1]);
            dp[2][i]=c+max(dp[0][i-1], dp[1][i-1]);
      }
      int ans=-1;
      for(int i=0; i<3; i++)
      ans=max(ans, dp[i][n]);
      cout<<ans<<'\n';
}

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

int main() {
  int N,M,X=0.;
  cin >> N >> M;
  vector<int>L(M);
  vector<int>R(M);
  for(int i=0; i<M; i++){
    cin >> L[i] >> R[i];
  }
  sort(L.begin(),L.end());
  sort(R.begin(),R.end());
  if(R[0]-L[M-1] >= 0){
    cout << R[0]-L[M-1]+1 << endl;
    return 0;
  }
  cout << 0 << endl;
}


Measured memory_bytes: 4040
N,Q=map(int,input().split())
s="0"+input()+"0"
queri=[list(input().split()) for i in range(Q)]

L,R=0,N+1
for i in range(Q-1,-1,-1):
    t,d=queri[i]
    if t==s[L] and d=="R":
        L-=1
    elif t==s[L+1] and d=="L":
        L+=1
    if t==s[R] and d=="L":
        R+=1
    elif t==s[R-1] and d=="R":
        R-=1

print(R-L-1)

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

bool check(int N, const std::unordered_set<int> D) {
	while(N > 0) {
		if(D.find(N % 10) != D.end()) return false;
		N /= 10;
	}
	return true;
}

int main() {
	int N, K;
	std::unordered_set<int> D;

	std::cin >> N >> K;
	for(int i = 0; i < K; ++i) {
		int d;
		std::cin >> d;
		D.insert(d);
	}

	for(int i = N; i <= 10 * N; ++i) {
		if(check(i, D)) {
			std::cout << i << std::endl;
			return 0;
		}
	}
}

Measured memory_bytes: 256
n = int(input())
w = list(map(int, input().split()))
s1 = [0] * (n + 1)
for i in range(1, n + 1):
    s1[i] = s1[i - 1] + w[i - 1]
ans = 1000000
for i in range(1, n):
    s2 = sum(w) - s1[i]
    ans = min(ans, abs(s1[i] - s2))
print(ans)


Measured memory_bytes: 3060
#include <algorithm>
#include <cstdio>
#include <iostream>
#include <vector>
#include <stack>
#include <queue>
#include <map>
#include <cmath>
#include <set>
#include <cstring>
#include <string>
#include <bitset>
#include <stdlib.h>
#include <time.h> 
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef unsigned long long ull;
#define st first
#define sd second
#define mkp make_pair
#define pb push_back
void wenjian(){freopen("concatenation.in","r",stdin);freopen("concatenation.out","w",stdout);}
void tempwj(){freopen("hash.in","r",stdin);freopen("hash.out","w",stdout);}
ll gcd(ll a,ll b){return b == 0 ? a : gcd(b,a % b);}
ll qpow(ll a,ll b,ll mod){a %= mod;ll ans = 1;while(b){if(b & 1)ans = ans * a % mod;a = a * a % mod;b >>= 1;}return ans;}
struct cmp{bool operator()(const pii & a, const pii & b){return a.second > b.second;}};
int lb(int x){return  x & -x;}

const int inf = 0x3f3f3f3f;
const ll INF = 0x3f3f3f3f3f3f3f3f;
const ll mod = 1e9+7;
const int maxn = 3e5+5;
int a[maxn];

int main()
{
	int n;
	scanf("%d",&n);
	int sum =0 ;
	for (int i = 1; i <= n; i ++ )
	{
		scanf("%d",&a[i]);
		sum ^= a[i];
	}
	for (int i = 1; i<= n; i ++ )
	{
		a[i] = a[i] ^ sum;
		printf("%d ",a[i]);
	}
	printf("\n");
}

Measured memory_bytes: 4004
from heapq import heappop,heappush,heapify

N = int(input())
heap = list(map(int,input().split()))
heapify(heap)

while(len(heap)>=2):
    x = heappop(heap)
    y = heappop(heap)
    #print(x,y)
    heappush(heap,(x+y)/2)
print(heappop(heap))

Measured memory_bytes: 9164
import sys

def solve():
    S = input()
    N = len(S)
    A = [0] * (N + 1)
    init = []
    for i in range(N - 1):
        if  S[i] == ">" and S[i + 1] == "<": init.append(i + 1)
    #right

    if S[0] == "<":
        d = 1
        A[d] = A[d - 1] + 1
        while d <= N - 1:
            if S[d] == ">": break
            d += 1
            A[d] = A[d-1] + 1

    for s in init:
        d = s + 1
        A[d] = A[d - 1] + 1
        while d <= N - 1:
            if S[d] == ">": break
            d += 1
            A[d] = A[d-1] + 1

    #left
    if S[N - 1] == ">":
        d = N - 1
        while d >= 0:
            if S[d] == "<": break
            A[d] = max(A[d], A[d+1] + 1)
            d -= 1
            
    for s in init:
        d = s - 1
        while d >= 0:
            if S[d] == "<": break
            A[d] = max(A[d], A[d+1] + 1)
            d -= 1

    print(sum(A))
    #print(A)

    return 0

if __name__ == "__main__":
    solve()

Measured memory_bytes: 23452
# -*- coding: utf-8 -*-
import sys
import copy
import collections
from bisect import bisect_left
from bisect import bisect_right
from collections import defaultdict
from heapq import heappop, heappush
import numpy as np
import statistics
from statistics import mean, median,variance,stdev
import math

def main():
	A, B, K = map(int, input().split(" "))
	
	tmp = -1
	e = min(B, A+K)
	for i in range(A, e):
		print(i)
		tmp = i
	
	#Aprint("sss")
	
	s = max(A, tmp+1, B-K+1)
	for i in range(s, B+1):
		print(i)
			
	
if __name__ == "__main__":
	main()


Measured memory_bytes: 13264
import java.util.*;

public class Main{
    public static void main(String[] args){
        Scanner s = new Scanner(System.in);
        while(true){
            String card = s.next();
            if (card.equals("-")) break;
            int m = s.nextInt();
            for (int i=0; i<m; i++){
                int h = s.nextInt();
                String front = card.substring(0,h);
                String back = card.substring(h);
                card = back+front;
            }
            System.out.println(card);
        }
    }
}


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

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

int main(){

    long long N, X;
    cin >> N >> X;
    vector<long long> x(N);
    for(int i = 0; i < N; i++) cin >> x[i];

    long long max = abs(X - x[0]);
    for(int i = 1; i < N; i++){
        max = gcd(max, abs(X - x[i]));
    }

    cout << max << endl;

    return 0;
}

Measured memory_bytes: 1024
#[allow(unused_imports)]
use std::collections::VecDeque;
#[allow(unused_imports)]
use std::cmp;
#[allow(unused_imports)]
use std::collections::HashMap;

#[allow(unused_macros)]
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        #[allow(unused_variables)]
        #[allow(unused_mut)]
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

#[allow(unused_macros)]
macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

    ($next:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
}

#[allow(unused_macros)]
macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };

    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };

    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
    };

    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}

fn main() {
    input!{
        n: usize,
        x: usize,
        y: usize,
    }
    let mut graph: Vec<Vec<usize>> = vec![vec![]; n];
    for i in 0..n-1 {
        graph[i].push(i+1);
        graph[i+1].push(i);
    }
    graph[x-1].push(y-1);
    graph[y-1].push(x-1);
    let mut answer: Vec<i64> = vec![0; n];
    for i in 0..n {
        let mut que: VecDeque<usize> = VecDeque::new();
        let mut dist: Vec<i32> = vec![-1; n];
        dist[i] = 0;
        que.push_back(i);
        while !que.is_empty() {
            let p = match que.pop_front() {
                Some(x) => x,
                _ => 0
            };
            let nx_v = dist[p] + 1;
            for k in &graph[p] {
                if dist[*k] != -1 {continue;}
                if i < *k {
                    answer[nx_v as usize] += 1;
                }
                dist[*k] = nx_v;
                que.push_back(*k);
            }
        }
    }

    for i in 1..n {
        println!("{}", answer[i]);
    }
}


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

int main()
{
    int a,b,c,d;
    cin >> a >> b >> c >> d;
    if((abs(b - a) <= d) && (abs(c - b) <= d) || (abs(a-c) <= d)){
        cout << "Yes" << endl;
    }else{
        cout << "No" << endl;
    }
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#include<cctype>
using namespace std;
#define rep(i,n) for (int i=0;i<(n);i++)
#define all(v) (v).begin(),(v).end()
typedef long long int ll;
#define pi 3.1415926535897932384
#define E9 1000000000
#define eps 1e-4
#define pii pair<int,int>


int main(){
  int N, Y; cin >> N >> Y;
  int y = Y/1000;
  
  for (int n1=0;n1<=N;n1++){
    if ((y-N-9*n1)>=0 && (y-N-9*n1)%4==0) {
      int n2 = (y-N-9*n1)/4, n3 = N - n1 - n2;
      
      if (n3>=0){
        cout << n1 << " " << n2 << " " << n3 << endl;
        return 0;
      }
    }
  }
  cout << -1 << " " << -1 << " " << -1 << endl;

  

  
  
  // cout << fixed << setprecision(10);
  
  return 0;
}



Measured memory_bytes: 256
#pragma region
#include <algorithm>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <stack>
#include <string>
#include <vector>
typedef long long ll;
#define rep(i, a, n) for (long long i = a; i <= n; ++i)
#define per(i, a, n) for (long long i = n; i >= a; --i)
#define IO ios::sync_with_stdio(false), cin.tie(0), cout.tie(0)
using namespace std;
/*
 *                                                     __----~~~~~~~~~~~------___
 *                                    .  .   ~~//====......          __--~ ~~
 *                    -.            \_|//     |||\\  ~~~~~~::::... /~
 *                 ___-==_       _-~o~  \/    |||  \\            _/~~-
 *         __---~~~.==~||\=_    -_--~/_-~|-   |\\   \\        _/~
 *     _-~~     .=~    |  \\-_    '-~7  /-   /  ||    \      /
 *   .~       .~       |   \\ -_    /  /-   /   ||      \   /
 *  /  ____  /         |     \\ ~-_/  /|- _/   .||       \ /
 *  |~~    ~~|--~~~~--_ \     ~==-/   | \~--===~~        .\
 *           '         ~-|      /|    |-~\~~       __--~~
 *                       |-~~-_/ |    |   ~\_   _-~            /\
 *                            /  \     \__   \/~                \__
 *                        _--~ _/ | .-~~____--~-/                  ~~==.
 *                       ((->/~   '.|||' -_|    ~~-/ ,              . _||
 *                                  -_     ~\      ~~---l__i__i__i--~~_/
 *                                  _-~-__   ~)  \--______________--~~
 *                                //.-~~~-~_--~- |-------~~~~~~~~
 *                                       //.-~~~--\
 *                       ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
 */
#pragma endregion
const int maxn = 305;
int a[4], n;
double dp[maxn][maxn][maxn];
double dfs(int c1, int c2, int c3) {
    if (!c1 && !c2 && !c3) return 0;
    if (dp[c1][c2][c3] > 0) return dp[c1][c2][c3];
    double sum = c1 + c2 + c3;
    double ans = n / sum;
    if (c1) ans += c1 / sum * dfs(c1 - 1, c2, c3);
    if (c2) ans += c2 / sum * dfs(c1 + 1, c2 - 1, c3);
    if (c3) ans += c3 / sum * dfs(c1, c2 + 1, c3 - 1);
    return dp[c1][c2][c3] = ans;
}
int main() {
    IO;
    cin >> n;
    rep(i, 1, n) {
        int x;
        cin >> x;
        a[x]++;
    }
    cout << fixed << setprecision(10) << dfs(a[1], a[2], a[3]) << endl;
}

Measured memory_bytes: 112628
n= int(input())
s = input()

# ord(A) -> 65, ord(Z) -> 90

ans = ""
for i in range(len(s)):
    chr_num = ord(s[i]) + n
    if chr_num > 90:
        chr_num = (chr_num % 90) + 64
    ans += chr(chr_num)
print(ans)



Measured memory_bytes: 3060
import java.util.*;

public class Main {
    public static void main(String[] args){
    
    Scanner sc = new Scanner(System.in);
    int A = sc.nextInt();
    int B = sc.nextInt();
    
      if(B%A == 0){
	System.out.println(A+B);
      }else{
	System.out.println(B-A);
    }
      }
}

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

using namespace std;

#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REP(i,a) FOR(i,0,a)

int way[]={0,1,2,3,4,5,6,7,8,9,5,4,3,2,1};

int s,g;
vector<int> w1,w2;
vector<int> ss;

void solve(){
	w1.clear();
	w2.clear();
	ss.clear();
	REP(i,15){
		if (way[i]==s){
			ss.push_back(i);
		}
	}
	if (ss.size()==1){
		int v=ss[0];
		while (way[v]!=g){
			printf("%d ",way[v]);
			v++;
			v%=15;
		}
		printf("%d\n",g);
		return;
	}
	int v=ss[0];
	while (way[v]!=g){
		w1.push_back(way[v]);
		v++;
		v%=15;
	}
	w1.push_back(g);
	v=ss[1];
	while (way[v]!=g){
		w2.push_back(way[v]);
		v++;
		v%=15;
	}
	w2.push_back(g);
	if (w1.size()<w2.size()){
		REP(i,(int)w1.size()){
			if (i) printf(" ");
			printf("%d",w1[i]);
		}
		printf("\n");
	}else{
		REP(i,(int)w2.size()){
			if (i) printf(" ");
			printf("%d",w2[i]);
		}
		printf("\n");
	}
}

int main(){
	int n;
	cin>>n;
	REP(i,n){
		cin>>s>>g;
		solve();
	}
	return 0;
}

Measured memory_bytes: 1200
//Akash Kumar Mondol
//Department of ICE,University of Rajshahi,Bangladesh
#include<bits/stdc++.h>
using namespace std;
#define pr(x) cerr << "\n" << (#x) << " is " << (x) << endl
#define ll long long
#define pii pair<int,int>
#define pll pair<ll,ll>
#define sci(x) scanf("%d",&x)
#define scl(x) scanf("%lld",&x)
#define scd(x) scanf("%lf",&x)
#define pfi(x) printf("%d",x)
#define pfl(x) printf("%lld",x)
#define pfd(x) printf("%lf",x)
#define pfc(x) printf("Case %d: ",x)
#define ps printf(" ")
#define pn printf("\n")
#define mod 1000000007
#define Toggle(n,i) (n^(1<<i))
#define Check(n,i) (n&(1<<i))
#define Set(n,i) (n|(1<<i))
#define Reset(n,i) (n&(~(1<<i)))
//#define valid(nx,ny) nx>=0&& nx<r && ny>=0 && ny<c
//memset(a, 0, sizeof(a));
//freopen("file_name.txt","read_or_write",stdout_or_stdin);
int visit[100005];
int ans;
vector<int>vec[100005];
vector<pii>ve;
map<pii,int>mp;
int color[100005];
void bfs(int s)
{
    queue<int>q;
    visit[s]=1;
    int cnt=1;
    q.push(s);
    while(!q.empty())
    {
        int top=q.front();
        q.pop();
        for(int i=0;i<vec[top].size();i++)
        {
            int v=vec[top][i];
            if(!visit[v])
            {
                visit[v]=1;
                if(cnt==color[top]) cnt++;
                color[v]=cnt;
                mp[{top,v}]=cnt;
                mp[{v,top}]=cnt;
                cnt++;
                q.push(v);
            }
        }
        ans=max(ans,cnt-1);
        cnt=1;
    }
}
int main()
{
    //freopen("file_name.txt","w",stdout);
    //ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
    int n,x,y;
    sci(n);
    for(int i=0;i<n-1;i++)
    {
        sci(x);sci(y);
        vec[x].push_back(y);
        vec[y].push_back(x);
        ve.push_back({x,y});
    }
    bfs(1);
    pfi(ans);pn;
    for(int i=0;i<ve.size();i++)
    {
        int a=ve[i].first;
        int b=ve[i].second;
        printf("%d\n",mp[{b,a}]);
    }
    return 0;
}




Measured memory_bytes: 20084
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,n) for(int i=0;i<n;i++)
#define why(n,x) int n;while(cin >>n,n!=x)
#define iFOR(i,x,n)for(int i=x;i<n;i++)
#define unless(flg) if ( !(flg) )
#define read cin<<
#define echo cout<<
#define fin <<'\n'
#define __ <<" "<<
#define ___ <<" "
#define bash push_back
#define ALL(x) x.begin(),x.end()
#define SWAP(a,b) ((a != b) && (a += b,b = a - b,a -= b))
#define cinf(n,x) for(int UNCH=0;UNCH<(n);UNCH++) cin >> x[UNCH];
#define fcin(n,x) for(int UNCH=1;UNCH<=(n);UNCH++) cin>> x[UNCH];
#define memmin(x) memset((x),-1,sizeof((x)))
#define memzer(x) memset((x), 0,sizeof((x)))
#define meminf(x) memset((x),0x3f,sizeof((x)))
#define int long long
typedef long long ll;
typedef pair < int , int >  pii;
typedef vector < int > vit;
typedef map < string , int > mstit;
typedef vector < pii > vpi ;
typedef greater < pii > gpi;
typedef priority_queue < pii , vpi , gpi > dijk ;
static const signed int INF = 0x3f3f3f3f;
static const signed long long LINF = 0x3f3f3f3f3f3f3f3fLL;
static const signed int SMOD = 1000000007;
static const signed int NMOD = 1000000009;
static const signed int dx[]={1,0,-1,0,1,1,-1,-1};
static const signed int dy[]={0,-1,0,1,-1,1,-1,1};

bool inside(int x,int y,int w,int h){return (x>=0 && y>=0 && x<w && y<h);}
template<class T>T abs(T &x){return x<0 ? -x : x;}
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
int qp(int a,ll b,int mo){int ans=1;do{if(b&1)ans=1ll*ans*a%mo;a=1ll*a*a%mo;}while(b>>=1);return ans;}
int gcd(int a,int b){return b?gcd(b,a%b):a;}

int n,m,a,b,c,d,h,w,x,y;
string str;

signed main(){
  string cod="CODEFESTIVAL2016";
  int ans = 0;
  cin >> str;
  FOR(i,str.length()){
    if(str[i]!=cod[i]) ans++;
  }
  
  cout << ans fin;
  return 0;
}



struct xyz{ xyz(){ cin.tie(0), ios::sync_with_stdio(false); cout <<fixed<<setprecision(12);};}xyzzy;



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

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

int main() {
  int n, k;
  cin >> n >> k;

  int d = 1;

  rep(i, n) {
    if (d * 2 > d + k) {
      d += k;
    } else {
      d *= 2;
    }
  }

  cout << d << endl;
}

Measured memory_bytes: 256
import sys
input = sys.stdin.readline
input = sys.stdin.buffer.readline


#sys.setrecursionlimit(10**9)
#from functools import lru_cache

def RD(): return sys.stdin.read()
def II(): return int(input())
def MI(): return map(int,input().split())
def MF(): return map(float,input().split())
def LI(): return list(map(int,input().split()))
def LF(): return list(map(float,input().split()))
def TI(): return tuple(map(int,input().split()))
# rstrip().decode()

#import numpy as np
#import bisect

def main():

	n=II()

	ans=0

	for i in range(1,n+1):
		k=n//i
		ans+=i*k*(k+1)//2

	print(ans)











if __name__ == "__main__":
	main()


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

string abc101_b(int n) {
	string s = to_string(n);
	int sum = 0;
	const char* c = s.c_str();
	while (*c != 0) {
		sum += (*c - '0');
		c++;
	}
	if (n % sum == 0) {
		return "Yes";
	}
	return "No";
}

void abc_101_b_test() {
	assert(abc101_b(12).compare("Yes") == 0);
	assert(abc101_b(101).compare("No") == 0);
	assert(abc101_b(999999999).compare("Yes") == 0);

}

int main()
{
	int n;
	cin >> n;
	cout << abc101_b(n) << endl;

	return 0;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef vector<int> vi;
int main(){
    int n;
    scanf("%d",&n);
    int p[n][n]; memset(p,-1,sizeof(p));
    for (int i = 0; i < n; i++){
        int x;
        scanf("%d",&x);
        for (int j = 0; j < x; j++){
            int a,b;
            scanf("%d%d",&a,&b);
            a--;
            p[i][a] = b;
        }
    }
    int ans = 0;
    for (int m = 0; m < (1<<n); m++){
        int ct = 0;
        int q[n];
        for (int i = 0; i < n; i++){
            q[i] = m&(1<<i) ? 1: 0;
            ct += q[i];
        }
        for (int i = 0; i < n; i++){
            if (q[i]){
                for (int j = 0;  j < n; j++){
                    //printf("%d says %d %d, %d\n",i,j,p[i][j],q[j]);
                    if (p[i][j] != -1 && p[i][j] != q[j]) goto bad;
                }
            }
        }
        //printf("%d can\n",m);
        ans = max(ans,ct);
        bad:;
    }
    printf("%d",ans);

}


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

int main()
{
  int N;
  cin >> N;
  
  vector<int> a(N);
  rep(i, N)
  {
    cin >> a[i];
  }
  
  int tmp_a = a[0];
  int counter = 1;
  bool flag = false;
  rep(i, N)
  {
    if (2 == tmp_a)
    {
      flag = true;
      break;
    }
    
    counter++;
    tmp_a = a[tmp_a - 1];
  }
  
  if (flag)
  {
    cout << counter << endl;
  }
  else
  {
    cout << -1 << endl;
  }
}


Measured memory_bytes: 640
/*
 * d.cc: 
 */

#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<iostream>
#include<string>
#include<vector>
#include<map>
#include<set>
#include<stack>
#include<list>
#include<queue>
#include<deque>
#include<algorithm>
#include<numeric>
#include<utility>
#include<complex>
#include<functional>

using namespace std;

/* constant */

const int MAX_N = 100;
const int MAX_M = 10;

typedef long long ll;

const int INF = 1 << 30;
const ll LINF = 1LL << 60;

/* typedef */

typedef vector<int> vi;
typedef queue<int> qi;
typedef pair<int,int> pii;

/* global variables */

int xs[MAX_N], as[MAX_M], bs[MAX_M], cs[MAX_M];
bool dp[MAX_M][MAX_N][MAX_N];

/* subroutines */

/* main */

int main() {
  int n;
  cin >> n;
  for (int i = 0; i < n; i++) cin >> xs[i];

  int m;
  cin >> m;
  for (int i = 0; i < m; i++) {
    cin >> as[i] >> bs[i] >> cs[i];
    bs[i]--, cs[i]--;
  }

  for (int i = 0; i < m; i++)
    for (int j = 0; j < n; j++)
      dp[i][j][j] = (as[i] == xs[j]);

  for (int l = 1; l < n; l++)
    for (int i = 0; i < m; i++)
      for (int j0 = 0, j1 = l; j1 < n; j0++, j1++) {
	dp[i][j0][j1] = false;
	for (int k = j0; k < j1; k++)
	  if (dp[bs[i]][j0][k] && dp[cs[i]][k + 1][j1]) {
	    dp[i][j0][j1] = true;
	    break;
	  }
      }

  cout << (dp[0][0][n - 1] ? "Yes" : "No") << endl;
  return 0;
}

Measured memory_bytes: 1252
import std.stdio;
import std.conv;
import std.string;
import std.typecons;
import std.algorithm;
import std.array;
import std.range;
import std.math;
import std.regex : regex;
import std.container;

void main()
{
	int n, num;
	while (n = readln.chomp.to!int, n) {
		num++;
		auto mat = new int[][](n, n);
		mat[0][0] = 1;
		int cnt = 1, x, y;
		bool gd;
		while (cnt != n*n) {
			int nx, ny;
			bool f;
			if (gd) {
				nx = x - 1;
				ny = y + 1;
				if (ny >= n) {
					nx += 2;
					ny--;
					f = 1;
				} else if (nx < 0) {
					nx++;
					f = 1;
				}
			} else {
				nx = x + 1;
				ny = y - 1;
				if (nx >= n) {
					nx--;
					ny += 2;
					f = 1;
				} else if (ny < 0) {
					ny++;
					f = 1;
				}
			}
			if (f) gd = !gd;
			mat[nx][ny] = mat[x][y] + 1;
			x = nx;
			y = ny;
			cnt++;
		}
		writeln("Case ", num, ":");
		foreach (i; 0..n) {
			foreach (j; 0..n) {
				writef("%3d", mat[j][i]);
			}
			writeln("");
		}
	}
}

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

int main() {
    int n, m;
    cin >> n >> m;
    for (int x = m/n; x >= 1; x--) {
        if (m % x == 0) {
            cout << x << endl;
            return 0;
        }
    }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <algorithm>
#include <queue>
using namespace std;
int main() {
	int N; 
	cin >> N; 
	long long int A[300010] = {}; 
	priority_queue<long long int, vector<long long int>,greater<long long int>> P1; 
	priority_queue<long long int, vector<long long int>> P2;
	long long int left = 0, right = 0;  
	for(int i = 0; i < N * 3; i++) {
		cin >> A[i]; 
		if(i < N){left += A[i]; P1.push(A[i]);}
		if(i >= N * 2){right += A[i]; P2.push(A[i]);}
	}
	long long int L[300010] = {}; long long int R[300010] = {}; 
	L[N - 1] = left, R[N * 2 - 1] = right; 
	for(int i = N; i <= N * 2 - 1; i++){
		L[i] = L[i-1] + A[i];
		P1.push(A[i]);  
		L[i] -= P1.top(); 
		P1.pop(); 
	}
	for(int i = N * 2 - 2; i >= N - 1; i--){
		R[i] = R[i+1] + A[i+1];
		P2.push(A[i+1]);  
		R[i] -= P2.top(); 
		P2.pop(); 
	}
	long long int ans = -1e15; 
	for(int i = N - 1; i <= N * 2 - 1; i++){
		ans = max(ans, L[i] - R[i]); 
	}
	cout << ans << endl; 
}

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

typedef pair <int, int> ii;
const int maxn = 1e5 + 10;

int N, X, Y, Z;
ii A[maxn];
long long f[maxn], g[maxn];
priority_queue <int> q;

int main() {
   // freopen("input.in", "r", stdin);
  //  freopen("output.out", "w", stdout);

    scanf("%d%d%d", &X, &Y, &Z);
    N = X + Y + Z;
    long long cnt = 0;
    for (int i = 1; i <= N; ++i) {
        int x, y, z; scanf("%d%d%d", &x, &y, &z);
        cnt += z; A[i] = ii(x - z, y - z);
    }
    sort(A + 1, A + N + 1, [] (ii a, ii b) { return a.first - a.second > b.first - b.second; });
    for (int i = 1; i <= N; ++i) {
        cnt += A[i].first; q.push(-A[i].first);
        if (i > X) cnt += q.top(), q.pop();
        f[i] = cnt;
    }
    cnt = 0;
    while (!q.empty()) q.pop();
    for (int i = N; i > 0; --i) {
        cnt += A[i].second; q.push(-A[i].second);
        if (i <= N - Y) cnt += q.top(), q.pop();
        g[i] = cnt;
    }
    long long ans = 0;
    for (int i = X; i <= X + Z; ++i)
        ans = max(ans, f[i] + g[i + 1]);
    printf("%lld\n", ans);

    return 0;
}


Measured memory_bytes: 3064
import java.io.InputStreamReader;
import java.io.BufferedReader;
import java.io.PrintWriter;
import java.io.IOException;
import java.util.Scanner;

public class Main {

    public static void main(String[] args) throws IOException{
        Scanner reader = null;
        PrintWriter writer = null;
        
        try {
            reader =new Scanner(new BufferedReader(new InputStreamReader(System.in)));
            writer = new PrintWriter(System.out);
            
            writer.println(48 - reader.nextInt());
            
        }finally{
            if(reader != null){
                reader.close();
            }
            if(writer != null){
                writer.close();
            }
        }

    }
}

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

int main() {
  int n;
  cin >> n;

  ll sum = 0;

  for (int i = 1; i <= n; i++) {
    if (i % 3 == 0 || i % 5 == 0) continue;
    sum += i;
  }

  cout << sum << endl;

  return 0;
}


Measured memory_bytes: 3640
#include<bits/stdc++.h>
using namespace std;
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
#define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>
#define int  long long
#define min(a,b) ((a)<(b)?(a):(b))
#define max(a,b) ((a)>(b)?(a):(b))
#define fast  ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0)
#define mod 998244353
// order_of_key and *find_by_order
#define N 100001

int32_t main() {
	fast;
	int l, r, d;
	cin >> l >> r >> d;
	int ans = 0;
	for (int i = l; i <= r; i++) {
		if (i % d == 0)
			ans++;
	}
	cout << ans;
}











Measured memory_bytes: 3644
#include<iostream>
#include<vector>
#include<map>
#include<algorithm>

using namespace std;
typedef long long ll;

struct union_find{
  
  vector<int> par;
  
  union_find(int n){ 
    par.resize(n);
    for(int i = 0; i < n; i++){ par[i] = i;}
  }
  
  int root(int x){
    if( par[x] == x){ return x;}
    else{ return par[x] = root(par[x]);}
  }
  
  bool issame(int x, int y){
    return root(x) == root(y);
  }

  void unite(int x, int y){
    if(issame(x,y)){ return ;}
    else{ par[root(x)] = root(y);}
  }
  
};

int main(){
  int N,K,L; cin >> N >> K >> L;
  
  union_find uf1(N),uf2(N);
  
  for(int i = 0; i < K; i++){
    int a,b; cin >> a >> b; a--; b--;
    uf1.unite(a,b);
  }
  
  for(int i = 0; i < L; i++){
    int a,b; cin >> a >> b; a--; b--;
    uf2.unite(a,b);
  }
  
  map<pair<int,int>,int> mp;
  
  for(int i = 0; i < N; i++){
    mp[{uf1.root(i),uf2.root(i)}]++;
  }
  
  for(int i = 0; i < N; i++){
    cout << mp[{uf1.root(i),uf2.root(i)}] << " ";}
  
  cout << endl;
  
  return 0;
}

Measured memory_bytes: 13568
/**
        	C++14 (GCC 5.4.1)
**/
#include <iostream>
#include <cmath>
#include <algorithm>
#include <string>
#include <vector>
#include <set>
// #include <bits/stdc++.h>
using namespace std;

int main(){
    long long H, W, A, B;

    cin >> H >> W >> A >> B;

    vector< vector< long long > > s(H, vector<long long>(W));
    // vector< vector< long long > > c(W, vector<long long>(2,0));

    for(long long i = 0 ; i < H ; i++){
        for(long long j = 0 ; j < W ; j++){
            if((i < B && j < A )||(i >= B && j >= A) ){
                s[i][j] = 1;
            }
            else {
                s[i][j] = 0;
            }
        }
    }
    for(long long i = 0 ; i < H ; i++){
        for(long long j = 0 ; j < W ; j++){
            cout << s[i][j] ;
        }
        cout << endl;
    }


}

Measured memory_bytes: 9088
#from statistics import median
#import collections
#aa = collections.Counter(a) # list to list || .most_common(2)で最大の2個とりだせるお a[0][0]
from math import gcd
from itertools import combinations,permutations,accumulate, product # (string,3) 3回
#from collections import deque
from collections import deque,defaultdict,Counter
import decimal
import re
import math
import bisect
import heapq
#
#
#
# pythonで無理なときは、pypyでやると正解するかも！！
#
#
# my_round_int = lambda x:np.round((x*2 + 1)//2)
# 四捨五入g
#
# インデックス系
# int min_y = max(0, i - 2), max_y = min(h - 1, i + 2);
# int min_x = max(0, j - 2), max_x = min(w - 1, j + 2);
#
#
import sys
sys.setrecursionlimit(10000000)
mod = 10**9 + 7
#mod = 9982443453
#mod = 998244353
INF = float('inf')
from sys import stdin
readline = stdin.readline
def readInts():
  return list(map(int,readline().split()))
def readTuples():
    return tuple(map(int,readline().split()))
def I():
    return int(readline())

#dic = defaultdict(int)
n,k = readInts()
D = Counter(readInts())
def ok(n):
    while n:
        v = n%10
        if D[v]:
            return False
        n //= 10
    return True
ans = n
for i in range(n, 100000):
    if ok(i):
        ans = i
        break
print(ans)


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

from fractions import gcd
from math import ceil,floor
import collections

# n=int(input())
# A,B,C,D=map(int, input().split())
# string = input()
# list = list(map(int, input().split()))


S = input()
SC = collections.Counter(S)

ans = 'No'

if len(SC.most_common()) == 2:
    ans = 'Yes'


print(ans)


Measured memory_bytes: 5728
#include<bits/stdc++.h>
using namespace std;
#define F first
#define S second
#define PB push_back
#define MP make_pair
#define REP(i,a,b) for(inti=a;i<=b;i++)

#define MOD 1000000009
typedef long long int ll;
typedef vector<int>vi;
typedef pair<int,int>pi;



int main()
{

    ll a,b,c,d;
    cin>>a>>b>>c>>d;

    cout<<max(max(max(max(a*d,a*c),b*c),b*d),a*c)<<endl;
 return 0;
}


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

const int MAXF = 200000;
const int MOD  = 1000000007;

ll f[MAXF + 5], invf[MAXF + 5];

inline ll lgput(ll a, ll n) {
  ll res = 1;
  while (n > 0) {
    if (n % 2 == 1)
      res = 1LL * res * a % MOD;
    a = 1LL * a * a % MOD;
    n /= 2;
  }
  return res;
}

inline ll comb(ll n, ll k) {
  if (n < k) {
    return 0;
  } else if (n < 0 || k < 0) {
    return 0;
  } else {
    return 1LL * f[n] % MOD * invf[n - k] % MOD * invf[k] % MOD;
  }
}

vector<pair<ll, ll>> prime_factorize(ll n) {
  vector<pair<ll, ll>> res;
  for (ll p = 2; p * p <= n; p++) {
    if (n % p != 0)
      continue;
    int num = 0;
    while (n % p == 0) {
      num++;
      n /= p;
    }
    res.push_back(make_pair(p, num));
  }
  if (n != 1)
    res.push_back(make_pair(n, 1));
  return res;
}

int main() {
  ll N, M;
  cin >> N >> M;

  f[0]    = 1;
  invf[0] = 1;
  for (int i = 1; i <= MAXF; i++) {
    f[i] = f[i - 1] * i % MOD;
  }
  invf[MAXF] = 1LL * lgput(f[MAXF], MOD - 2) % MOD;
  for (int i = MAXF - 1; i >= 1; i--) {
    invf[i] = 1LL * invf[i + 1] * (i + 1) % MOD;
  }

  auto vec = prime_factorize(M);
  ll res   = 1;
  for (auto p : vec) {
    ll num = p.second;
    ll tmp = comb(num + N - 1, N - 1) % MOD;
    res    = res * tmp % MOD;
  }

  cout << res << endl;
  return 0;
}


Measured memory_bytes: 3328
#include <bits/stdc++.h>
    using namespace std;
    int main() {
    	int A, B, C, D, E, F;
    	bool dp[30];
    	cin >> A >> B >> C >> D >> E >> F;
    	for(int i = 0; i < 30; i++) {
    		dp[i] = false;
    	}
    	double d = 0;
    	int water = 0, sugar = 0;
    	int WATER = 0, SUGAR = 0;
    	for(int w = 0; w < 30; w++) {
    		for(int x = 0; x < 30; x++) {
    			water = A * w + B * x;
    			if(water > 30) break;
    			if(w + x == 0 || dp[water]) continue;
    			for(int y = 0; 1; y++) {
    				if( water * 100 + C * y > 3000) break;
    				for(int z = 0; 1; z++) {
    					sugar = C * y + D * z;
    					if(100 * water + sugar > F) break;
    					double value = (double)(sugar) / (double)(water);
    					if( value <= E && value > d) {
    						d = value;
    						WATER = water, SUGAR = sugar;
    					}
    					dp[w * A + x * B] = true;
    				}
    			}
    		}
    	}
    	if(WATER == 0) WATER = A;
    	cout << (WATER * 100 + SUGAR) << " " << SUGAR << endl;
    	return 0;
    }

Measured memory_bytes: 256
#include <algorithm>
#include <iostream>
#include <vector>
#include <map>
#include <cstdio>
#include <string>
#include <cmath>
#include <queue>
#include <tuple>
#include <set>
#include <assert.h>
#include <sstream>
#include <string>
//#include <bits/stdc++.h>
#define maxs(x,y) x = max(x,y)
#define mins(x,y) x = min(x,y)
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define repr(i, n) for (int i = (n) - 1; i >= 0; i--)
#define FOR(i,i0,n) for(int (i)=(i0);(i)<(n);(i)++)
#define FORR(i,i0,n) for(int (i)=(n)-1; (i)>=(i0);(i)--)
#define SORT(x) sort(x.begin(),x.end())
#define SORTR(x) sort(x.begin(),x.end(),greater <>())
#define rn return
#define fi first
#define se second
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define mt make_tuple
using namespace std;
using ll = long long;
typedef std::pair<ll,ll> P;
//#include <boost/multiprecision/cpp_int.hpp>
//using bint = boost::multiprecision::cpp_int;


int main(){
    int n;
    cin >> n;
    vector<pair<int,string>> S;
    map<string,int> m;
    
    rep(i,n){
        string s;
        cin >> s;
        m[s]++;
    }
    map<string,int>::iterator it = m.begin();
    while(it != m.end()){
        S.pb(mp(it->second, it->first));
        it++;
        
    }
    
    SORTR(S);
    S.pb(mp(1e9,"BUG"));
    int i = 0;
    vector<string> o;
    o.pb(S[i].se);
    while(S[i].fi == S[i+1].fi){
        o.pb(S[i+1].se);
        i++;
    }
    SORT(o);
    for(auto e:o){
        cout << e << endl;
    }
}



Measured memory_bytes: 32876
n= int(input())
a = list(map(int, input().split()))
a.append(0)
ans=1000
b = 0
for i in range(1,n+1):
  if a[i] < a[i-1]:
    if i-1-b>0:
      ans = ans//a[b]*a[i-1]+ans%a[b]
    b = i
print(ans)

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

int main(){
  string s,t;
  cin >> s >> t;
  if(s[0] == t[2] && s[1] == t[1] && s[2] == t[0]) cout << "YES" << endl;
  else cout << "NO" << endl;
  return 0;
}

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

using namespace std;

int main(){

	int tmp, ans=1;
	string s;

	cin >> tmp;
	cin >> s;

	for (int i = 1;i < s.size();i++) {
		if (s[i] != s[i - 1]) ans++;
	}

	cout<< ans << endl;


}


Measured memory_bytes: 512
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <cmath>
#include <vector>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <queue>
#include <ctime>
#include <cassert>
#include <complex>
#include <string>
#include <cstring>
#include <chrono>
#include <random>
#include <queue>
#include <bitset>
#include <iomanip>
using namespace std;
#define all(x) x.begin(), x.end()
typedef vector <int> vi;
typedef pair<int,int> ii;
typedef long long ll;
typedef long double ld;
const int mod = 1e9 + 7;
const ll inf = 3e18 + 5;
int add(int a, int b) { return (a += b) < mod ? a : a - mod; }
int mul(int a, int b) { return 1LL * a * b % mod; }
int sub(int a, int b) { return (a -= b) < 0 ? a + mod : a; }

int n, a[105], dp[100005];

int main(){
    int k;
    cin >> n >> k;
    dp[0] = 1;
    for(int i = 0; i < n; i++){
        cin  >> a[i];
        int psum[100500] = {};
        for(int used = k; used >= 0; used--){
            int dodaj = dp[used];
            int l = used + 1;
            int r = used + min(a[i], k - used);
            if(l <= r){
                psum[l] = add(psum[l], dodaj);
                if(r + 1 <= k)
                    psum[r + 1] = sub(psum[r + 1], dodaj);
            }
        }
        int pref = 0;
        for(int i = 0; i <= k; i++){
            pref = add(pref, psum[i]);
            dp[i] = add(dp[i], pref);
        }
    }
    cout << dp[k];
}

Measured memory_bytes: 1024
#include <stdio.h>

int main(void) {

	int i = 1;
	int n;
	int x;
	
	scanf("%d",&n);
	
	x = i;
	while(x != 0){
		
		if(x % 3 ==0){
			printf(" %d",i);
		}else{
			while(x > 0){
				if(x % 10 ==3){
					printf(" %d",i);
					break;
				}
				x /= 10;
			}
		}
		i++;
		if(i > n){
			break;
		}else{
			x = i;
		}
	}
	printf("\n");

	return 0;
}



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

int main() {
vector<int> vec(3);
  vector<int> aaa={5,5,7};
  cin>>vec.at(0)>>vec.at(1)>>vec.at(2);
  sort(vec.begin(),vec.end());
  if(vec==aaa) cout<<"YES"<<endl;
  else cout<<"NO"<<endl;
}

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

int a[100005];

int main()
{
	int n, l;
	scanf("%d%d", &n, &l);
	for (int i = 0; i < n; i++) scanf("%d", &a[i]);

	for (int i = 1; i < n; i++)
	{
		if (a[i - 1] + a[i] >= l)
		{
			printf("Possible\n");
			for (int j = 1; j < i; j++) printf("%d\n", j);
			for (int j = n - 1; j >= i; j--) printf("%d\n", j);
			return 0;
		}
	}
	printf("Impossible\n");
}

Measured memory_bytes: 1152
def all_index(s, c):
    ins = []
    for i in range(len(s)):
        if s[i] == c:
            ins.append(i)

    return ins


s = input().strip()
k = int(input())

ss = set()
alphabets = sorted(list(set(s)))
for c in alphabets:
    ins = all_index(s, c)
    for i in ins:
        for j in range(i, len(s)):
            if (j+1 - i) > k:
                break

            ss.add(s[i:j+1])

    if len(ss) >= k:
        break

print(sorted(list(ss))[k-1])

Measured memory_bytes: 3188
#include <iostream>
#include <limits.h>
#include <algorithm>
#include <bitset>
#include <cctype>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <functional>
#include <iomanip>
#include <list>
#include <map>
#include <numeric>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>
#include <queue>
#include <unordered_map>
#include <unordered_set>
#include <cassert>

#define REP(i,n) for(int i=0;i<n;i++)
#define all(x) (x).begin(),(x).end()
#define mp make_pair
#define pb push_back
#define eb emplace_back

typedef long long ll;
using namespace std;

int main(void){
    cin.tie(0);
    ios::sync_with_stdio(false);
    // cout << fixed << setprecision(20);
    int n;cin >> n;
    vector<ll> s(n);
    REP(i,n)cin >> s[i];
    ll ans = 0;
    for(ll c = 1;c <= n-2;c++){
        vector<bool> used(n,false);
        ll cur = 0;
        for(ll k = 0;(k+1)*c < n-1;k++){
            if(used[(n-1)-k*c] or used[(k*c)])break;
            else{
                cur += s[(n-1)-k*c] + s[k*c];
                if(k*c == (n-1)-k*c)break;
                ans = max(ans,cur);
                used[(n-1)-k*c] = 1;
                used[k*c] = 1;
            }
        }
    }
    cout << ans << '\n';

    return 0;
}


Measured memory_bytes: 1024
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.IO;

using static Input;
using static Util;
class Program
{
    static int[] A;
    static void INPUT()
    {
        A = LineInt();
    }
    static void OUTPUT()
    {
        var c = 1;
        var ans = 0;
        while(c < A[1])
        {
            ans++;
            c += A[0] - 1;
        }
        
        Console.WriteLine(ans);

    }

    static void Main(string[] args)
    {
#if DEBUG  
        TESTINPUT();
#else
        INPUT();
#endif
        OUTPUT();
    }

    static void TESTINPUT()
    {
        A = new int[]{ 8, 8};
    }
}

public class Input
{
    public const long MOD = 1000000007;
    public const int INF = 1000000007;
    private static Queue<string> q = new Queue<string>();
    private static void Confirm() { if (q.Count == 0) foreach (var s in Console.ReadLine().Split(' ')) q.Enqueue(s); }
    public static int NextInt() { Confirm(); return int.Parse(q.Dequeue()); }
    public static long NextLong() { Confirm(); return long.Parse(q.Dequeue()); }
    public static string NextString() { Confirm(); return q.Dequeue(); }
    public static double NextDouble() { Confirm(); return double.Parse(q.Dequeue()); }
    public static int[] LineInt() { return Console.ReadLine().Split(' ').Select(int.Parse).ToArray(); }
    public static long[] LineLong() { return Console.ReadLine().Split(' ').Select(long.Parse).ToArray(); }
    public static string[] LineString() { return Console.ReadLine().Split(' ').ToArray(); }
    public static double[] LineDouble() { return Console.ReadLine().Split(' ').Select(double.Parse).ToArray(); }
}

class Util
{

}




Measured memory_bytes: 13396
#include <bits/stdc++.h>
using namespace std;
const int MAXN=8;
const int INF=100000;
int n;
int six[MAXN],nin[MAXN];
int dp[INF+1];
int main(){
	scanf("%d",&n);
	six[0]=nin[0]=1;
	for(int i=1;i<MAXN;++i){
		six[i]=six[i-1]*6;
		nin[i]=nin[i-1]*9;
	}
	for(int i=1;i<=n;++i){
		dp[i]=i;
		for(int j=0;j<MAXN;++j){
			if(six[j]>i) break;
			dp[i]=min(dp[i],dp[i-six[j]]+1);
		}
		for(int j=1;j<MAXN;++j){
			if(nin[j]>i) break;
			dp[i]=min(dp[i],dp[i-nin[j]]+1);
		}
	}
	printf("%d",dp[n]);
	return 0;
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for(int i = 0; i < (int)(n); ++i)

int main() {
  int n, x;
  cin >> n >> x;
  
  vector<int> a(n);
  REP(i, n)
    cin >> a.at(i);
  sort(a.begin(), a.end());
  
  int ans = 0;
  REP(i, n) {
    if (x >= a.at(i)) {
      ++ans;
      x -= a.at(i);
    }
    else
      break;
  }
  
  if (x > 0)
    ans = min(ans, n - 1);
  
  cout << ans << endl;
  
  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
using namespace std;
#define gcd(a,b) __gcd(a,b)

int main(){
  int n,a,b = 1;

  cin >> n;
  for(int i = 0 ; i < n ; i++){
    cin >> a;
    b = (a*b) / gcd(a,b);
  }
  cout << b << endl;

  return 0;
}

Measured memory_bytes: 1164
#include <bits/stdc++.h>
#define debug(x) cerr << "\n" \
                      << #x << " = " << x << ".\n"
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
//#define int long long
using namespace std;
typedef long long ll;
//using pii pair<int,int>;
typedef pair<int, int> pii;
//using ll long long;
const int INF = ((1LL << 30) + (1LL << 29));
const ll MOD = 1000000007;

//=============================================================
int N,L;
vector<string> S;

void input(){
  cin>>N>>L;
  S = vector<string>(N);
  rep(i,N){cin>>S[i];}
}

void solve()
{
  sort(S.begin(),S.end());
  rep(i,N){cout<<S[i];}
  cout<<endl;
}



signed main()
{
  input();
  solve();

  return 0;
}

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

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	int n;
	cin >> n;
	vector<ll> a(n);
	ll sum = 0, cnt = 0;
	rep(i,n){
		cin >> a[i];
		sum += a[i];
		if(i%2 == 1) cnt += a[i];
	}
	ll x = sum - 2*cnt;
	cout << x;
	ll y;
	for(int i = 1; i < n; i++){
		y = 2*a[i-1] - x;
		cout << " " << y;
		x = y;
	}
	cout << endl;
	return 0;
}

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


int mi = 10000000;
int N, A, B, C;
vector<int> l(8);

void dfs(int cur,int a,int b,int c,int co) {
  if (cur == N) {
    if (a==0 || b==0 || c==0) return;
    mi = min(mi, co + abs(A - a) + abs(B - b) + abs(C - c));
	return;
  }
  dfs(cur + 1, a + l[cur], b, c, co + 10);
  dfs(cur + 1, a, b + l[cur], c, co + 10);
  dfs(cur + 1, a, b, c + l[cur], co + 10);
  dfs(cur + 1, a, b, c, co);
}


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

  dfs(0, 0, 0, 0, -30);
  cout << mi << endl;
}


Measured memory_bytes: 256
N = int(input())

s = ""

while N != 0:
    # Pythonでは負の数を割っても余りが正になる
    # -2で割ったときの"理想的な"余り(0or1になってくれる)は2で割った余りと同じ
    # -2で割ったときの余りは0or-1となってしまう、-1となったら1に置き換えるとしても良い
    r = int(N % 2)
    # ここは素直に-2
    N = (N - r) / (-2)
    s += str(int(r))

# N=0の時は空文字列が返ってきてしまう
if s == "":
    print(0)
    exit()
else:
    # reverse
    print(s[::-1])


Measured memory_bytes: 9204
import math
def check(a, b):
  sum = 0
  a = [int(i) for i in a]
  b = [int(i) for i in b]
  for i in range(D):
    sum += (abs(a[i]-b[i]))**2
  if math.sqrt(sum).is_integer():
    return 1
  else:
    return 0
N, D = map(int, input().split())
X = [input().split() for _ in range(N)]
count = 0
for i in range(N):
  for j in range(i+1, N):
    count += check(X[i],X[j])
print(count)

Measured memory_bytes: 3064