akhauriyash/Code-Regression huggingface dataset:
def phyonkichi(p, n):
    yoko = 0
    tate = 1
    s = dic[n]
    p_lis = [(p[yoko]+a[yoko], p[tate]+a[tate]) for a in jump]
    s_lis = [(s[yoko]+a[yoko], s[tate]+a[tate]) for a in sprinkler]
    c_lis = []
    for v in list(set(p_lis) & set(s_lis)):
        if 0 <= v[yoko] <= 9 and 0 <= v[tate] <= 9:
            c_lis.append(v)
    if c_lis:
        if n == N:
            print 'OK'
            return True
        else:
            for v in c_lis:
                if phyonkichi(v, n+1): return True
    else:
        return
        
jump = [(2,-1),(2,0),(2,1),
        (-1,-2),(0,-2),(1,-2),
        (-2,1),(-2,0),(-2,-1),
        (-1,2),(0,2),(1,2)]

sprinkler = [(0,0),(1,0),(1,-1),
             (0,-1),(-1,-1),(-1,0),
             (-1,1),(0,1),(1,1)]

while True:
    w, h = map(int, raw_input().split(' '))
    if w == 0 and h == 0: break
    N = int(raw_input())
    lis = raw_input().split(' ')
    lis = [lis[i:i+2] for i in range(0, 2*N, 2)]
    dic = {}
    for i, c in enumerate(lis):
        dic[i+1] = (int(c[0]), int(c[1]))
    else:
        if not phyonkichi((w, h), 1):
            print 'NA'

Measured memory_bytes: 4344
package main

import "fmt"

func main() {
	var (
		xs       = make([]int, 3)
		max, sum int
	)
	for i := range xs {
		fmt.Scan(&xs[i])
		sum += xs[i]
		if xs[i] > max {
			max = xs[i]
		}
	}
	fmt.Println(sum - max)
}


Measured memory_bytes: 512
#include <stdio.h>

int main()
{
  int i, j;
  int h, w;

  while (1) {
    scanf("%d %d", &h, &w);
    if (h == 0 && w == 0) break;
    
    for (i = 0; i < h; i++) {
      for (j = 0; j < w; j++) {
        putchar('#');
      }
      putchar('\n');
    }
    putchar('\n');
  }
  return 0;
}



Measured memory_bytes: 2032
use std::io::{stdin, Read, StdinLock};
use std::str::FromStr;

struct Scanner<'a> {
    cin : StdinLock<'a>,
}

impl<'a> Scanner<'a> {
    fn new(cin : StdinLock<'a>) -> Scanner<'a> {
        Scanner { cin: cin }
    }

    fn read1<T: FromStr>(&mut self) -> Option<T> {
        let token = self.cin.by_ref().bytes().map(|c| c.unwrap() as char)
            .skip_while(|c| c.is_whitespace())
            .take_while(|c| !c.is_whitespace())
            .collect::<String>();
        token.parse::<T>().ok()
    }

    fn read<T: FromStr>(&mut self) -> T {
        self.read1().unwrap()
    }
}

fn main(){
    let cin = stdin();
    let cin = cin.lock();
    let mut sc = Scanner::new(cin);

    loop{
        let n : usize = sc.read();
        if n == 0 { break; }
        let mut nxt = 1;
        let mut l = 0;
        let mut r = 0;
        let mut cnt = 0;
        for _ in 0..n {
            let v: String = sc.read();
            match &*v {
                "lu" => { l = 1; },
                "ru" => { r = 1; },
                "ld" => { l = 0; },
                "rd" => { r = 0; },
                _ => ()
            };
            if l == nxt && r == nxt {
                cnt += 1;
                nxt ^= 1;
            }
        }
        println!("{}", cnt);
    }
}



Measured memory_bytes: 5048
#include<bits/stdc++.h>
#include<random>
#include <chrono>
#define lowbit(i) (i&(-i))
using namespace std;

namespace _ {
	bool rEOF = 1;//为0表示文件结尾
	inline char nc() {
		static char buf[100000], *p1 = buf, *p2 = buf;
		return p1 == p2 && rEOF && (p2 = (p1 = buf) + fread(buf, 1, 100000, stdin), p1 == p2) ? (rEOF = 0, EOF) : *p1++;
	}
	template<class _T>
	inline bool read(_T &num) {
		char c = nc(), f = 1; num = 0;
		while (c<'0' || c>'9')c == '-' && (f = -1), c = nc();
		while (c >= '0'&&c <= '9')num = num * 10 + c - '0', c = nc();
		return (bool)(num *= f);
	}
	inline bool need(char &c) { return c >= 'A'&&c <= 'z' || c >= '0'&&c <= '9' || c >= 'A'&&c <= 'Z'; }//读入的字符范围
	inline bool read_str(char *a) {
		while ((*a = nc()) && need(*a) && rEOF)++a;
		*a = '\0'; return rEOF;
	}
}using namespace _;

void file(bool opt)
{
	if (opt&&fopen("in.txt", "r"))
	{
		freopen("in.txt", "r", stdin);
		//freopen("out.txt", "w", stdout);
	}
}

long long n, k;
long long sum = 0;
long long a[505 + 5];
long long l[505], r[505];
vector<long long>que;


bool check(long long g)
{
	vector<pair<long long, long long>>q2;
	for (int i = 1; i <= n; i++)
	{
		long long x = a[i] % g;
		q2.push_back({ x,g - x });
	}
	sort(q2.begin(), q2.end());
	for (int i = 1; i <= n; i++)
		l[i] = l[i - 1] + q2[i - 1].first;
	for (int i = n; i >= 1; i--)
		r[i] = r[i + 1] + q2[i - 1].second;
	for (int i = 1; i < n; i++)
		if (l[i] == r[i + 1] && l[i] <= k)
			return 1;
	return 0;
}

int main()
{
	cin >> n >> k;
	for (int i = 1; i <= n; i++)cin >> a[i], sum += a[i];
	sort(a + 1, a + 1 + n);
	for (long long i = 1; i*i <= sum; i++)
	{
		if (sum%i == 0)
		{
			que.push_back(i);
			if (i != sum / i)que.push_back(sum / i);
		}
	}
	sort(que.begin(), que.end(), [](long long a, long long b) {return a > b; });
	for (int i = 0; i < que.size(); i++)
	{
		if (check(que[i]))
		{
			printf("%lld\n", que[i]);
			return 0;
		}
	}
	printf("1\n");
	return 0;
}


Measured memory_bytes: 384
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (int)(n); i++)
#define REP(i,n) for (int i = 1; i < (int)(n); i++)
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(),x.rend()
#define vout(x) rep(i,x.size()) cout << x[i] << " "
template<class T> bool chmin(T &a, T b) {if(a>b) {a=b;return 1;}return 0;}
template<class T> bool chmax(T &a, T b) {if(a<b) {a=b;return 1;}return 0;}
using namespace std;
using vint = vector<int>;
using vvint = vector<vector<int>>;
using ll = long long;
using vll = vector<ll>;
using vvll = vector<vector<ll>>;
using P = pair<int,int>;
const int inf = 1e9;
const ll inf_l = 1e18;
const int MAX = 1e5;

int main() {
    ll n; cin >> n;
    int x = 1;
    vector<char> ans;
    while (true) {
        if (n <= pow(26,x)) {
            n--;
            rep(i,x) {
                ans.push_back(n%26+'a');
                n /= 26;
            }
            break;
        } else {
            n -= pow(26,x);
            x++;
        }
    }
    rep(i,ans.size()) cout << ans[ans.size()-1-i];
    cout << endl;
}

Measured memory_bytes: 4080
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
 
signed main(){
	string S, T;
	cin >> S >> T;
	int count = 0;
	for(int i = 0; i < S.length(); i++){
		if(S[i] != T[i]){
			count++;
		}
	}
	cout << count << endl;
 
	return 0;
}

Measured memory_bytes: 3836
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {

        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        int a[] = new int[N];
        for(int i =0;i<N;i++){
           a[i] = sc.nextInt();
        }
        int resultflag = 1;
        for (int i =0;i<N;i++){
            if(a[i]==resultflag){
                resultflag++;
            }
        }
        if(resultflag==1){
            System.out.println(-1);
        }else {
            System.out.println(N-resultflag+1);
        }
    }
}


Measured memory_bytes: 77488
N,M = map(int,input().split())
XY = [[0,1] for _ in range(N)]
XY[0] = [1,1]
for _ in range(M):
  x,y = map(int,input().split())
  x -= 1
  y -= 1
  
  XY[y][1] += 1
  XY[x][1] -= 1
  
  if XY[x][0] == 1:
    XY[y][0] = 1
    if XY[x][1] == 0:
      XY[x][0] = 0

print(sum([flag for flag, _ in XY]))

Measured memory_bytes: 61088
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
typedef long long ll;
int main(){
    ll n,A[200001],B[200001];
    cin>>n;
    rep(i,n) cin>>A[i];
    rep(i,n) cin>>B[i];
    ll C[200001]={0};
    rep(i,n) C[i]=B[(i-1+n)%n]+B[(i+1)%n];
    queue<int> que;
    rep(i,n) if(C[i]<=B[i]) que.push(i);
    ll ans=0;
    while(!que.empty()){
        int a=que.front();
        que.pop();
        if(C[a]>B[a]||A[a]==B[a]) continue;
        ll b=(B[a]-A[a])/C[a];
        B[a]-=b*C[a];
        C[(a-1+n)%n]-=b*C[a];
        C[(a+1)%n]-=b*C[a];
        ans+=b;
        if(C[(a-1+n)%n]<=B[(a-1+n)%n]) que.push((a-1+n)%n);
        if(C[(a+1)%n]<=B[(a+1)%n]) que.push((a+1)%n);
    }
    int x=1;
    rep(i,n) if(A[i]!=B[i]) x=0;
    if(x) cout<<ans;
    else cout<<-1;
}

Measured memory_bytes: 5376
#include <iostream>

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

int main(){
  int a,b,c,x;cin>>a>>b>>c>>x;
  int temp;
  int ans=0;
  rep(i,a+1){
    rep(j,b+1){
      temp=x-i*500-j*100;
      if(temp>=0&&temp/50<=c){
        ans++;
      }
    }
  }
  cout<<ans<<endl;
}

Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main{

	public static void main(String[] args) throws IOException {

		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

		while (true) {
			String[] num = br.readLine().split(" ");
			int n = Integer.parseInt(num[0]);
			int x = Integer.parseInt(num[1]);
			// ????????????
			if (n == 0 && x == 0)
				break;
			int cnt = 0;
			// 5 9
			for (int i = 1; i <= n - 2; i++) {
				for (int j = i + 1; j <= n - 1; j++) {
					for (int k = j + 1; k <= n; k++) {
						if ((i + j + k) == x)
							cnt++;
					}
				}
			}
			System.out.println(cnt);

		}

	}
}

Measured memory_bytes: 24832
#include<bits/stdc++.h>
using namespace std;
int cnt[100009];

int main(){
  int n,m;
  cin>>n>>m;
  for(int i=0;i<m;i++){
    int l,r;
    cin>>l>>r;
    cnt[l]++;
    cnt[r+1]--;
  }
  int ans=0;
  for(int i=1;i<=n;i++){
    cnt[i]+=cnt[i-1];
    if(cnt[i]==m)ans++;
  }
  cout<<ans<<endl;
  return(0);
}


Measured memory_bytes: 768
s=input()
bin_num = int(s,2)
mask = 0
s_len = len(s)
for i in range(s_len):
    mask = (mask<<1) + (i%2)
mask_inv = (2**s_len-1)-mask
mask = bin_num ^ mask
mask_inv = bin_num ^ mask_inv
print(min(bin(mask).count("1"), bin(mask_inv).count("1")))

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

using namespace std;
typedef long long ll;
const int MAXN = 2e5 + 5;
int a[MAXN];

int main() {
    cin >> a[1] >> a[2] >> a[3];
    sort(a + 1, a + 4);
    int ans = 0;
    ans += a[3] - a[2];
    a[1] += ans;
    if ((a[3] - a[1]) % 2 == 0)
        cout << ans + (a[3] - a[1]) / 2 << endl;
    else
        cout << ans + (a[3] - a[1]) / 2 + 2 << endl;
    return 0;
}

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

fn main() {
    let (W, a, b): (i64, i64, i64) = {
        let mut line: String = String::new();
        std::io::stdin().read_line(&mut line).unwrap();
        let mut iter = line.split_whitespace();
        (
            iter.next().unwrap().parse().unwrap(),
            iter.next().unwrap().parse().unwrap(),
            iter.next().unwrap().parse().unwrap()
        )
    };

    let ans = if b >= a + W {
        b - (a + W)
    } else if b + W <= a {
        a - (b + W)
    } else {
        0
    };

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


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

#define int long long

#define rep(i,n) for(int i=0;i<(n);i++)
#define pb push_back
#define eb emplace_back
#define all(v) (v).begin(),(v).end()
#define fi first
#define se second

using vint=vector<int>;
using pint=pair<int,int>;
using vpint=vector<pint>;

template<typename A,typename B>inline void chmin(A &a,B b){if(a>b)a=b;}
template<typename A,typename B>inline void chmax(A &a,B b){if(a<b)a=b;}

template<class A,class B>
ostream& operator<<(ostream& ost,const pair<A,B>&p){
    ost<<"{"<<p.first<<","<<p.second<<"}";
    return ost;
}

template<class T>
ostream& operator<<(ostream& ost,const vector<T>&v){
    ost<<"{";
    for(int i=0;i<v.size();i++){
        if(i)ost<<",";
        ost<<v[i];
    }
    ost<<"}";
    return ost;
}

inline int topbit(unsigned long long x){
    return x?63-__builtin_clzll(x):-1;
}

inline int popcount(unsigned long long x){
    return __builtin_popcountll(x);
}

inline int parity(unsigned long long x){
    return __builtin_parity(x);
}

const int MAX=20;
int H,W;
char fld[MAX+10][MAX+10];
int dy[4]={-1,0,1,0};
int dx[4]={0,-1,0,1};

const int INF=1001001001;
int dist[MAX][MAX];
int bfs(int sy,int sx){
    fill_n(*dist,MAX*MAX,INF);
    dist[sy][sx]=0;
    queue<pint>que;
    que.emplace(sy,sx);
    while(que.size()){
        int y,x;
        tie(y,x)=que.front();
        que.pop();
        rep(d,4){
            int ny=y+dy[d];
            int nx=x+dx[d];
            if(ny<0||ny>=H||nx<0||nx>=W||fld[ny][nx]=='#'||dist[ny][nx]!=INF)continue;
            dist[ny][nx]=dist[y][x]+1;
            que.emplace(ny,nx);
        }
    }

    int ret=0;
    rep(i,H)rep(j,W)if(dist[i][j]!=INF)chmax(ret,dist[i][j]);
    return ret;
}

signed main(){
    cin>>H>>W;
    rep(i,H)cin>>fld[i];

    int ans=0;
    rep(i,H)rep(j,W){
        if(fld[i][j]=='#')continue;
        chmax(ans,bfs(i,j));
    }
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 256
#include<stdio.h>

int a[200010]; 
int ans[200010]; 

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

return 0;
}


Measured memory_bytes: 3268
import java.util.*;
public class Main{
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int s = sc.nextInt();
    int w = sc.nextInt();
    if(w>=s){
      System.out.println("unsafe");
    }else{
      System.out.println("safe");
    }
  }
}


Measured memory_bytes: 35832
#include<bits/stdc++.h>
using namespace std;
#define INF 1e9
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define ALL(x) (x).begin(), (x).end()
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int, int> pii;
template<typename T1,typename T2> inline void chmin(T1 &a,T2 b){if(a>b) a=b;}
template<typename T1,typename T2> inline void chmax(T1 &a,T2 b){if(a<b) a=b;}
const int MOD = 1000000007;

int x[] = {-1, 0, 1, 0};
int y[] = {0, -1, 0, 1};

int h, w;
vector<string> v;

int bfs(int sy, int sx) {
  vector<vector<int>> cnt(h, vector<int>(w, -1));
  queue<pii> q;
  q.push(pii(sy, sx));
  cnt[sy][sx] = 0;
  while(!q.empty()) {
    auto p = q.front();
    q.pop();
    rep(i,4) {
      int nextX = p.second + x[i];
      int nextY = p.first + y[i];
      if (nextX < 0 || nextX > w-1 || nextY < 0 || nextY > h-1) continue;
      if (cnt[nextY][nextX] != -1) continue;
      if (v[nextY][nextX] == '#') continue;
      cnt[nextY][nextX] = cnt[p.first][p.second] + 1;
      q.push(pii(nextY, nextX));
    }
  }
  int res = 0;
  rep(i,h) rep(j,w) res = max(res, cnt[i][j]);
  return res;
}

void solve() {
  cin >> h >> w;
  v.resize(h);
  rep(i,h) cin >> v[i];
  int ans = 0;

  rep(i,h) rep(j,w) {
    if (v[i][j] == '#') continue;
    ans = max(ans, bfs(i,j));
  }
  cout << ans << endl;
}

int main() {
  solve();
  return 0;
}

Measured memory_bytes: 3556
//#include "SaveFuncs.cpp"

#include <iostream>
#include <array>
#include <vector>
#include <algorithm>
#include <string>
#include <cmath>
#include <queue>
#include <stack>
#include <map>
#include <iomanip>	//cout << fixed << setprecision(桁数);
#include <stdexcept>

using namespace std;
using ll = long long;

#define rep(i, n) for(int i=0, i##_len=(n); i<i##_len; i++)
#define rep1(i, n) for(int i=1, i##_len=(n); i<i##_len; i++)
#define rrep(i, n) for(int i=(n)-1; i >= 0; i--)
#define rrep1(i, n) for(int i=(n); i > 0; i--)
#define all(x) (x).begin(), (x).end()
#define pair(a, b) make_pair(a, b);
//#define int long long
constexpr int INF = 2000000100;
constexpr int DIV = 1000000007;	// 10e9+7
template<class T> bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> T divUp(T a, T b) { if (a % b == 0) { return a / b; } return a / b + 1; }
string strMulti(string t, int n) { string out = ""; for (int i = 0; i < n; i++) { out += t; } return out; }

/*****/

int Main()
{
	int K, X;
	cin >> K >> X;

	for (int i = -K + 1; i < 0; i++)
	{
		cout << X + i << " ";
	}
	cout << X << " ";
	for (int i = 1; i <= K - 1; i++)
	{
		cout << X + i << " ";
	}

	return 0;
}

/*****/

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

	Main();

	return 0;
}


Measured memory_bytes: 256
import java.util.*;
import java.util.stream.Collectors;

public class Main{
    Scanner in = new Scanner(System.in);

    void solve(){
        List<String> list = Arrays.asList(in.nextLine().replaceAll(",|\\."," ").split("[ ]+"));
        list = list.stream()
            .filter(s -> 2 < s.length() && s.length() < 7)
            .collect(Collectors.toList());
        System.out.println(String.join(" ", list));
    }
    
    public static void main(String[] args){
        new Main().solve();    
    }
}

Measured memory_bytes: 32304
/**
 * Title: D - Friend Suggestions
 * Url: https://atcoder.jp/contests/abc157/tasks/abc157_d
 */
#include<bits/stdc++.h>

using namespace std;

#define ll long long

const int MAX_N = 100000;

// 連結成分表作成
vector<int> dfs(int n, vector<vector<int>> G) {
    int i, j, vertex, neighbor;
    vector<int> comp(n+1, 0);
    vector<int> used(n+1, 0);
    stack<int> S;

    for(int i=1; i<=n; i++) {
        if(used[i]==0) {
            // dfs
            S.push(i);
            while(!S.empty()) {
                vertex = S.top();
                S.pop();
                used[vertex] = 1;
                comp[vertex] = i;
                for(j=0; j<(int) G[vertex].size(); j++) {
                    neighbor = G[vertex][j];    // 隣接している友人
                    if(used[neighbor]==0) S.push(neighbor);
                }
            }
        }
    }
    return comp;
}

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

    vector<vector<int>> friends(n+1);
    vector<vector<int>> nfriends(n+1);

    // 友達の登録
    for(int i=0; i<m; i++) {
        int ai, bi; cin >> ai >> bi;
        friends[ai].push_back(bi);
        friends[bi].push_back(ai);
    }

    // ブロック
    for(int i=0; i<k; i++) {
        int ci, di; cin >> ci >> di;
        nfriends[ci].push_back(di);
        nfriends[di].push_back(ci);
    }

    // 連結成分表
    auto comp = dfs(n, friends);

    // O(N)
    map<int, int> dic;
    for(auto e:comp) {
        dic[e]++;
    }

    vector<int> nfnum(n+1, 0);
    for(int i=1; i<=n; i++) {
        for(auto p:nfriends[i]) {
            if(comp[p] == comp[i]) nfnum[i]++;
        }
    }

    for(int i=1; i<=n; i++) {
        if(i==n) {
            cout << dic[comp[i]] - friends[i].size() - nfnum[i] - 1 << endl;
        } else {
            cout << dic[comp[i]] - friends[i].size() - nfnum[i] - 1 << " ";
        }
    }

    return 0;
}

Measured memory_bytes: 18296
//@author rohit_0801
// help source : https://www.geeksforgeeks.org/given-an-array-arr-find-the-maximum-j-i-such-that-arrj-arri/

 
#include <bits/stdc++.h>
#define ll long long int
#define ff first
#define ss second
#define mp make_pair
#define pb push_back
#define debug 0
 
using namespace std;
const ll MOD = 1000000007;
const ll MODD = MOD-1;
 
ll ar[900780], left_max[448390], right_min[123456],br[1234567];
ll dp[505][505], mat[505][505];

vector<ll> vec[555],pec;

void go(int n, int k)
{
    for (int i=0; i<=n; i++)
        for (int j=0;j<=k;j++)
            dp[i][j] = 0;
 
    dp[0][0] = 0;
 

    for (int i=1;i<=n;i++)
		for (int j=1;j<=k;j++)
 			for (int m=i-1;m>=0;m--)
                dp[i][j] = max(dp[i][j], mat[i-1][m]);
 
 
}

ll solve(ll n)
{
	ll c=0;
    for(int i=1;i<=n;i++){
    	if(n%i==0){
    		c++;
		}
	}
	
	if(c==8){
		return 1;
	}
	else{
		return 0;
	}
}
 
 
int main() {
	//srand(time(0));
	ll a,b,n,m,flag=0,r,t,u,v,w,x,y,z,k,res=0,d,maxm=-999999999,i,j,ct,h,ans=0,s,l,e,f,p,minm=999999999,c,type,q,len,siz;
 	
 	vector<ll>::iterator it,jt;
 	
 	string str="",ptr="";
 	char ch;
 	
 	cin>>str;
 	cin>>k;
 	
 	len=str.length();
 	
 	if(len==1){
 		cout<<str;
 		return 0;
	 }
 	
 	for(i=0;i<len;i++){
 		if(str[i]!='1'){
 			flag=1;
		 }
	 }
	 
	 if(flag==0){
	 	cout<<1;
	 }
	 else{
	 	res=k;
	 	for(i=0;i<len;i++){
	 		if(str[i]=='1'){
	 			res--;
	 			if(res<=0){
	 				cout<<1;
	 				break;
				 }
			 }
			 else{
			 	cout<<str[i];
			 	break;
			 }
		 }
	 }
 	
	
	return 0;
}  

Measured memory_bytes: 256
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <queue>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>

using namespace std;

#define dump(x)  cerr << #x << " = " << (x) << endl;
#define PB push_back
#define MP make_pair
#define ll long long

inline int toInt(string s){int v;istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x){ostringstream sout;sout<<x;return sout.str();}

int main(){
    std::ios::sync_with_stdio(false);
    int a,b,c,d;
    cin >> a >> b >> c >> d;
    cout << ((( (abs(a-b) <= d) && (abs(b-c) ) <= d) || abs(a-c) <= d) ? "Yes" : "No") << endl;
}

Measured memory_bytes: 256
#pragma GCC optimize("Ofast")

#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef pair<ld,ld> pdd;

#define X first
#define Y second

//#include <boost/unordered_map.hpp>
//using namespace boost;

/*
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> rbtree;
rbtree T;
*/

namespace io{
	const int L = (1 << 20) + 1;
	
	char buf[L], *S , *T, c;
	 
	char getchar() {
		if(__builtin_expect(S == T, 0)) {
			T = (S = buf) + fread(buf, 1, L, stdin);
			return (S == T ? EOF : *S++);
		}
		return *S++;
	}
	
	int inp() {
		int x = 0, f = 1; char ch;
		for(ch = getchar(); !isdigit(ch); ch = getchar())
			if(ch == '-') f = -1;
		for(; isdigit(ch); x = x * 10 + ch - '0', ch = getchar());
		return x * f;
	}
	
	unsigned inpu()
	{
		unsigned x = 0; char ch;
		for(ch = getchar(); !isdigit(ch); ch = getchar());
		for(; isdigit(ch); x = x * 10 + ch - '0', ch = getchar());
		return x;
	}
	
	ll inp_ll() {
		ll x = 0; int f = 1; char ch;
		for(ch = getchar(); !isdigit(ch); ch = getchar())
			if(ch == '-') f = -1;
		for(; isdigit(ch); x = x * 10 + ch - '0', ch = getchar());
		return x * f;
	}
	
	char B[25], *outs=B+20, *outr=B+20;
	template<class T>
	inline void print(register T a,register char x=0){
		if(x) *--outs = x, x = 0;
		
		if(!a)*--outs = '0';
		else 
			while(a)
				*--outs = (a % 10) + 48, a /= 10;
		
		if(x)
			*--outs = x;
		
		fwrite(outs, outr - outs , 1, stdout);
		outs = outr;
	}
};

using io :: print;
using io :: inp;
using io :: inpu;
using io :: inp_ll;

using i32 = int;
using i64 = long long;
using u8 = unsigned char;
using u32 = unsigned;
using u64 = unsigned long long;
using f64 = double;
using f80 = long double;

ll power(ll a, ll b, ll p)
{
	if (!b) return 1;
	ll t = power(a, b/2, p);
	t = t*t%p;
	if (b&1) t = t*a%p;
	return t;
}

const int MAXN = 200010;
const u64 MOD = 1000000007;
const f80 MI = f80(1)/MOD;
const int INF = 1000000010;

int n;
char s[MAXN];

void addedge(int x, int y)
{
	printf("%d %d\n", x, y);
}

void work()
{
	if (s[n] == '1')
	{
		puts("-1");
		return;
	}
	for (int i = 1; i < n; ++ i)
		if (s[i] == '1' && s[n-i] != '1')
		{
			puts("-1");
			return;
		}
	if (s[1] != '1')
	{
		puts("-1");
		return;
	}
	int tot = 1, pre = 1, cur = 1, size = 1;
	for (int i = 2; i <= n/2; ++ i)
		if (s[i] == '1')
		{
			cur = ++ tot;
			addedge(cur, pre);
			size ++;
			while (size != i)
			{
				addedge(cur, ++ tot);
				size ++;
			}
			pre = cur;
		}
	cur = ++ tot;
	addedge(cur, pre);
	size ++;
	while (size != n)
	{
		addedge(cur, ++ tot);
		size ++;
	}
}

int main()
{
	
	scanf("%s", s+1);
	n = strlen(s+1);
	work();
	
	return 0;
}


Measured memory_bytes: 1536
#include <iostream>
#include <algorithm>

int main() {
    int A, B, C, X, Y;
    std::cin >> A >> B >> C >> X >> Y;

    int min_price = A * X + B * Y;
    for (int c = 0; c <= std::max(X, Y) * 2; c += 2) {
        int a = std::max(X - c / 2, 0);
        int b = std::max(Y - c / 2, 0);
        min_price = std::min(A * a + B * b + C * c, min_price);
    }
    std::cout << min_price << std::endl;
}


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

int main(){
	int n;
	cin>>n;
	
	int ac=0;
	int wa=0;
	int tle=0;
	int re=0;
	for(int i=0;i<n;i++){
		string s;
		cin>>s;
		if(s=="AC") ac++;
		if(s=="WA") wa++;
		if(s=="TLE") tle++;
		if(s=="RE") re++;
	}
	cout<<"AC"<<" "<<"x"<<" "<<ac<<"\n";
	cout<<"WA"<<" "<<"x"<<" "<<wa<<"\n";
    cout<<"TLE"<<" "<<"x"<<" "<<tle<<"\n";
    cout<<"RE"<<" "<<"x"<<" "<<re<<"\n";
    
    return 0;
}

Measured memory_bytes: 3620
package main

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

func main() {
  reader := bufio.NewReader(os.Stdin)
  text, _ := reader.ReadString('\n')
  arr := strings.Fields(text)
  a, _ := strconv.Atoi(arr[0])
  b, _ := strconv.Atoi(arr[1])
  if (a + b) % 2 == 0 {
  	fmt.Println((a + b) / 2)
  } else {
    fmt.Println("IMPOSSIBLE")
  }
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
 
using namespace std;
#define int long long
#define mod 1000000007
int mat[55][55];
 
void power(int n, int pw)
{
    int iden[n][n];
    int i, j;
    for(i=0;i<n;i++)
        for(j=0;j<n;j++)
            if(i == j)
                iden[i][j] = 1;
            else    
                iden[i][j] = 0;
    while(pw)
    {
        if(pw%2 == 1)
        {
            int res[n][n];
            for(i=0;i<n;i++)
                for(j=0;j<n;j++)
                {
                    res[i][j] = 0;
                    for(int k=0;k<n;k++)
                        res[i][j] = (res[i][j] + iden[i][k]*mat[k][j]%mod)%mod;
                }
            for(i=0;i<n;i++)
                for(j=0;j<n;j++)
                    iden[i][j] = res[i][j];
        }
        pw=pw/2;
        int res[n][n];
        for(i=0;i<n;i++)
            for(j=0;j<n;j++)
            {
                res[i][j] = 0;
                for(int k=0;k<n;k++)
                    res[i][j] = (res[i][j] + mat[i][k]*mat[k][j]%mod)%mod;
            }
        for(i=0;i<n;i++)
            for(j=0;j<n;j++)
                mat[i][j] = res[i][j];
    }
    for(i=0;i<n;i++)
        for(j=0;j<n;j++)
            mat[i][j] = iden[i][j]%mod;
}
 
signed main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    int n, m, k;
    cin >> n >> k;
    int i, j;
    for(i=0;i<n;i++)
        for(j=0;j<n;j++)
            cin >> mat[i][j];
    power(n, k);
    int sum = 0;
    for(i=0;i<n;i++)
        for(j=0;j<n;j++)
            sum = (sum + mat[i][j])%mod;
    cout << (sum+mod)%mod;
}

Measured memory_bytes: 3688
#include <iostream>
#include <algorithm>
using namespace std;
int main() {
	int a, b, c;
	cin >> a >> b >> c;
	int ab = a + b;
	int bc = b + c;
	int ca = c + a;
	cout << min(ab,min(bc,ca)) << endl;
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, n, m) for (int i = (int)(n); i < (int)(m); i++)
#define repr(i, n, m) for (int i = (int)(n) - 1; i >= (int)(m); i--)
using namespace std;
using ll = int64_t;
const int MOD = 1000000007; // 10^9+7

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

    vector<ll> x(n), y(n);
    rep(i, 0, n) {
        cin >> x[i] >> y[i];
    }

    int ans = 0;
    rep(i, 0, n) {
        if (x[i] * x[i] + y[i] * y[i] <= d * d)
        {
            ans++;
        }
    }

    cout << ans << endl;
}


Measured memory_bytes: 6428
#include <algorithm>
#include<iostream>
#include<vector>
#include<deque>
#include<queue>
#include<list>
#include<stack>
#include<map>
#include<set>
#include<string>
#include <sstream>

#include<stdlib.h>
#include<string.h>
#include<math.h>
#include<limits.h>

using namespace std;



int main(){
  long ii,jj,kk,n,q;
  int k;
  vector<int> a;

  cin >> n;

  a.resize(n);

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

  cin >> q;
  int ret;

  for(ii=0;ii<q;ii++){
    cin >> k;
    //ret = lower_bound(&a,k);
    auto it = lower_bound(a.begin(),a.end(),k);
    if(it == a.end()){
      cout << a.size() << endl;
    }
    else{
      cout << distance(a.begin(),it) << endl;
    }

  }
  
  //for(ii=0;ii<q;ii++){
  //  cin >> k;
  //  if(binSearch(&a,k)){
  //    cout << "1" << endl;
  //  }
  //  else{
  //    cout << "0" << endl;
  //  }
  //}
  
  return 0;
}



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

using namespace std;

int main(){
 int n; cin >> n;
 int a[n], b[n], mx = 0, mx2, ind = 0;
 for(int i=0; i<n; ++i){
   cin >> a[i];
   b[i] = a[i];
   if(a[i] > mx){
     mx = a[i];
     ind = i;
   }
 }
 sort(a, a+n);
 mx2 = a[n-2]; 
 for(int i=0; i<n; ++i){
   if(i==ind)
     cout << mx2  << "\n";
   else
     cout << mx <<"\n";
 }
 return 0;
}


Measured memory_bytes: 3200
def resolve():
    # 整数 1 つ
    n = int(input())
    # 整数複数個
    # a, b = map(int, input().split())
    # 整数 N 個 (改行区切り)
    # N = [int(input()) for i in range(N)]
    # 整数 N 個 (スペース区切り)
    A = list(map(int, input().split()))
    # 整数 (縦 H 横 W の行列)
    # A = [list(map(int, input().split())) for i in range(H)]

#偶数項を正とする
    sumeven = 0
    cnteven = 0
    for i in range(n):
        sumeven += A[i]
        if i % 2 == 0:
            if sumeven <= 0:
                cnteven += abs(sumeven) + 1
                sumeven += abs(sumeven) + 1
        else:
            if sumeven >= 0:
                cnteven += (sumeven + 1)
                sumeven -= (sumeven + 1)

# 奇数項を正とする
    sumodd = 0
    cntodd = 0
    for i in range(n):
        sumodd += A[i]
        if i % 2 == 1:
            if sumodd <= 0:
                cntodd += abs(sumodd) + 1
                sumodd += abs(sumodd) + 1
        else:
            if sumodd >= 0:
                cntodd += (sumodd + 1)
                sumodd -= (sumodd + 1)

    print(min(cnteven, cntodd))
#    print(cnteven, cntodd)

resolve()

Measured memory_bytes: 63728
#include<bits/stdc++.h>
#define INF 2000000000
#define MOD 1000000007
#define EPS (1e-10)

using namespace std;

int main(int argc, char *argv[]) {

	long N,K; cin >> N >> K;
	
	long minSum = 0;
	long maxSum = 0;
	long ans = 0;
	for (long i = K; i <= N + 1; i++) {
		minSum = (i * (i - 1) / 2) % MOD;	
		minSum %= MOD;
		minSum *= 2;
		minSum %= MOD;
		ans += (i * N) % MOD  - minSum + 1;
		ans %= MOD;
	}
	cout << ans << endl;

	return 0;
}


Measured memory_bytes: 3640
import std.conv, std.functional, std.range, std.stdio, std.string;
import std.algorithm, std.array, std.bigint, std.complex, std.container, std.math, std.numeric, std.regex, std.typecons;
import core.bitop;

class EOFException : Throwable { this() { super("EOF"); } }
string[] tokens;
string readToken() { for (; tokens.empty; ) { if (stdin.eof) { throw new EOFException; } tokens = readln.split; } auto token = tokens.front; tokens.popFront; return token; }
int readInt() { return readToken.to!int; }
long readLong() { return readToken.to!long; }
real readReal() { return readToken.to!real; }

bool chmin(T)(ref T t, in T f) { if (t > f) { t = f; return true; } else { return false; } }
bool chmax(T)(ref T t, in T f) { if (t < f) { t = f; return true; } else { return false; } }

int binarySearch(alias pred, T)(in T[] as) { int lo = -1, hi = cast(int)(as.length); for (; lo + 1 < hi; ) { const mid = (lo + hi) >> 1; (unaryFun!pred(as[mid]) ? hi : lo) = mid; } return hi; }
int lowerBound(T)(in T[] as, T val) { return as.binarySearch!(a => (a >= val)); }
int upperBound(T)(in T[] as, T val) { return as.binarySearch!(a => (a > val)); }


enum long MO = 1_000_003;
enum LIM = cast(int)(MO);

long[] inv, fac, invFac;
void prepare() {
  inv = new long[LIM];
  fac = new long[LIM];
  invFac = new long[LIM];
  inv[1] = 1;
  foreach (i; 2 .. LIM) {
    inv[i] = MO - ((MO / i) * inv[cast(size_t)(MO % i)]) % MO;
  }
  fac[0] = invFac[0] = 1;
  foreach (i; 1 .. LIM) {
    fac[i] = (fac[i - 1] * i) % MO;
    invFac[i] = (invFac[i - 1] * inv[i]) % MO;
  }
}

long power(long a, long e) {
  long x = a % MO, y = 1;
  for (; e; e >>= 1) {
    if (e & 1) y = (y * x) % MO;
    x = (x * x) % MO;
  }
  return y;
}

void main() {
  prepare();
  
  try {
    for (; ; ) {
      const numCases = readInt();
      foreach (caseId; 0 .. numCases) {
        const X = readLong();
        const D = readLong();
        const N = readLong();
        
        long ans;
        if (D == 0) {
          ans = power(X, N);
        } else {
          const a = (X * inv[cast(size_t)(D)]) % MO;
          const b = a + (N - 1);
          if (0 < a && b < MO) {
            ans = fac[cast(size_t)(b)];
            ans *= invFac[cast(size_t)(a - 1)];
            ans %= MO;
            ans *= power(D, N);
            ans %= MO;
          }
        }
        writeln(ans);
      }
    }
  } catch (EOFException e) {
  }
}


Measured memory_bytes: 29564
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <cmath>
#include <vector>
#include <queue>
#include <utility>

using namespace std;
typedef long long ll;
const int LEN = 100000;

struct fastio{
  int it,len;
  char s[LEN + 5];
  fastio(){
    it = len = 0;
  }
  char get(){
    if(it < len) return s[it++];
    it = 0, len = fread(s,1,LEN,stdin);
    return len ? s[it++] : EOF;
  }
  bool notend(){
    char c;
    for(c = get();c == ' ' || c == '\n';c = get());
    if(it) it--;
    return c != EOF;
  }
  void put(char c){
    if(it == LEN) fwrite(s,1,LEN,stdout), it = 0;
    s[it++] = c;
  }
  void flush(){
    fwrite(s,1,it,stdout);
  }
}buff,bufo;
inline int getint(){
  char c; int res = 0, sig = 1;
  for(c = buff.get();c < '0' || c > '9';c = buff.get()) if(c == '-') sig = -1;
  for(;c >= '0' && c <= '9';c = buff.get()) res = res * 10 + (c - '0');
  return sig * res;
}
inline ll getll(){
  char c; ll res = 0, sig = 1;
  for(c = buff.get();c < '0' || c > '9';c = buff.get()) if(c == '-') sig = -1;
  for(;c >= '0' && c <= '9';c = buff.get()) res = res * 10 + (c - '0');
  return sig * res;
}
inline void putint(int x,char suf){
  if(!x) bufo.put('0');
  else{
    if(x < 0) bufo.put('-'), x = -x;
    int k = 0; char s[15];
    while(x){
      s[++k] = x % 10 + '0';
      x /= 10;
    }
    for(;k;k--) bufo.put(s[k]);
  }
  bufo.put(suf);
}
inline void putll(ll x,char suf){
  if(!x) bufo.put('0');
  else{
    if(x < 0) bufo.put('-'), x = -x;
    int k = 0; char s[25];
    while(x){
      s[++k] = x % 10 + '0';
      x /= 10;
    }
    for(;k;k--) bufo.put(s[k]);
  }
  bufo.put(suf);
}
inline char get_char(){
  char c;
  for(c = buff.get();c == ' ' || c == '\n';c = buff.get());
  return c;
}
#define maxn 205
int n;
char s[maxn][maxn];
int col[maxn];
bool dfs_check(int u,int c){
  col[u] = c;
  for(int i = 1;i <= n;i++){
    if(s[u][i] == '1'){
      if(col[i] == -1){
        if(!dfs_check(i,1 - col[u])) return false;
      }else if(col[u] == col[i]) return false;
    }
  }
  return true;
}
int dis[maxn];
int main(){
  scanf("%d",&n);
  for(int i = 1;i <= n;i++) scanf("%s",s[i] + 1);
  for(int i = 1;i <= n;i++){
    if(s[i][i] == '1'){
      puts("-1");
      return 0;
    }
  }
  memset(col,-1,sizeof(col));
  if(!dfs_check(1,0)){
    puts("-1");
    return 0;
  }
  int ans = 0;
  for(int i = 1;i <= n;i++){
    queue <int> que;
    int res = 0;
    memset(dis,0x3f,sizeof(dis));
    dis[i] = 0;
    que.push(i);
    while(!que.empty()){
      int u = que.front(); que.pop();
      res = max(res,dis[u]);
      for(int v = 1;v <= n;v++){
        if(s[u][v] == '1'){
          if(dis[v] > dis[u] + 1){
            dis[v] = dis[u] + 1;
            que.push(v);
          }
        }
      }
    }
    ans = max(ans,res);
  }
  printf("%d\n",ans + 1);
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
const int mn = 1000000007;

int main(void)
{
    int N, K, X, Y;

    cin >> N >> K >> X >> Y;

    int ans = 0;

    if(N > K)
    {
        ans += K * X;
        ans += (N-K) * Y;
    }
    else
    {
        ans += N * X;
    }
    

    cout << ans << endl;

    return 0;
}



Measured memory_bytes: 3632
#include <stdio.h>
int main() {
	int N, i, count = 0, num = 0;
	int A[20];
	int B[20];
	int C[20];

	scanf("%d", &N);
	for (i = 0; i < N; i++)
		scanf("%d", &A[i]);
	for (i = 0; i < N; i++)
		scanf("%d", &B[i]);
	for (i = 0; i < N - 1; i++)
		scanf("%d", &C[i]);

	for (i = 0; i < N; i++) {
		count += B[A[i] - 1];
		if (i != 0) {
			if (A[i] - 1 == num)
				count += C[num - 1];
		}
		num = A[i];
	}
	printf("%d", count);
	return 0;
}

Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main() {
    int A, B, C, X;
    int method_count = 0;

    cin >> A >> B >> C >> X;

    for(int cnt_A = 0; cnt_A <= A; cnt_A++) {
        int val_A = cnt_A * 500;
        if(val_A > X) break;

        for(int cnt_B = 0; cnt_B <= B; cnt_B++) {
            int val_B = cnt_B * 100;
            if(val_A + val_B > X) break;
            int target_val = X - val_A - val_B;

            if(target_val % 50 != 0) continue;
            if(target_val / 50 > C) continue;
            method_count++;
        }
    }

    cout << method_count << endl;
    
    return 0;
}

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


int main() {
    int n;
    cin>>n;
    int ac=0;
    int wa=0;
    int tle=0;
    int re=0;
    rep(i,n){
        string s;
        cin>>s;
        if(s=="AC"){
            ac++;
        }
        if(s=="WA"){
            wa++;
        }
        if(s=="TLE"){
            tle++;
        }
        if(s=="RE"){
            re++;
        }
    }
    cout<<"AC x "<<ac<<endl;
    cout<<"WA x "<<wa<<endl;
    cout<<"TLE x "<<tle<<endl;
    cout<<"RE x "<<re<<endl;
}

Measured memory_bytes: 3640
#include<iostream>
#include<iomanip>
#include<math.h>
#include<algorithm>
#include<utility>
#include<functional>
#include<queue>
#include<string.h>
#include<string>
#include<set>
#include<map>
#include<vector>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
const int MOD = 1000000007;
const ll INF=2e18;
ll N;
ll A[100],B[100],C[100];
int main(){
  cin>>N;
  ll pre=-1;
  for(ll i=0;i<N;i++){
    cin>>A[i];
  }
  ll ans=0;
  for(ll i=0;i<N;i++){
    cin>>B[i];
    ans+=B[i];
  }
  for(ll i=0;i<N-1;i++){
    cin>>C[i];
  }
  for(ll i=0;i<N-1;i++){
    if(A[i]==A[i+1]-1){
      ans+=C[A[i]-1];
    }
  }
  cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <queue>
#include <set>
#include <map>
#include <vector>
#include <stack>
#include <cmath>
#include <algorithm>
#include <cstdio>
#include <cctype>
#include <functional>
#include <string>
#include <cstring>
#include <sstream>
#include <deque>
#define fir first
#define sec second
using namespace std;

typedef long long ll;
typedef pair<int,int> P;
typedef pair<P,int> Q;

const int inf1=1e9+9;
const ll inf2=1e16+9;
const ll mol=1e9+7;
const int maxn=2e5+9;
const ll maxx=1e12+9;

int n,num;

int main()
{
    scanf("%d",&n);
    scanf("%d",&num);
    ll ans=0,ma=num;
    for(int i=1;i<n;i++)
    {
        scanf("%d",&num);
        if(num>ma) ma=num;
        else ans+=ma-num;
    }
    printf("%lld\n",ans);
}


Measured memory_bytes: 3248
import java.util.*

fun mul(A: Array<Int>, B: Array<Int>): Array<Int> {
    val C = Array(A.size) { it }

    for (i in A.indices) {
        C[i] = B[A[i]]
    }

    return C
}

fun pow(A: Array<Int>, k: Long): Array<Int> {
    var R = Array(A.size) { it }
    var B = A
    var l = k

    while (l > 0) {
        if (l and 1 != 0L) {
            R = mul(R, B)
        }
        B = mul(B, B)
        l /= 2
    }

    return R
}

fun main(args: Array<String>) {
    val (N, K) = readLine()!!.split(" ").map{it.toLong()}
    val A = readLine()!!.split(" ").map{it.toInt()}
    val ts = Array(200010) { TreeSet<Int>() }
    val mp = Array(A.size + 1) { it }

    A.forEachIndexed { index, v -> ts[v].add(index) }

    mp[A.size] = 0
    for (i in A.indices.reversed()) {
        if (i == A.size - 1) {
            mp[i] = ts[A[i]].first() + 1

            continue
        }

        val a = ts[A[i]].higher(i)
        if (a != null) {
            if (a >= mp.size - 1) {
                mp[i] = 0
            } else {
                mp[i] = mp[a + 1]
            }
        } else {
            mp[i] = ts[A[i]].first() + 1
        }
    }

    var B = pow(mp, K - 1)
    if (B[0] == B.size - 1) {
        B = pow(mp, K - 2)
    }

    val S = ArrayDeque<Int>()
    val st = TreeSet<Int>()

    for (i in B.first() % A.size until A.size) {
        if (st.contains(A[i])) {
            while (S.isNotEmpty()) {
                st.remove(S.last)
                if (S.pollLast() == A[i]) {
                    break
                }
            } } else {
            S.addLast(A[i])
            st.add(S.last)
        }
    }

    println(S.joinToString(" "))
}


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

namespace ITP1_3
{
    class Program
    {
        static void Main()
        {
            int[] i = Console.ReadLine().Split(' ').Select(int.Parse).ToArray();
            int a = i[0], b = i[1] - a + 1, c = i[2];
            Console.Write("{0}\n", Enumerable.Range(a, b).Where(e => c % e == 0).Count());
        }
    }
}

Measured memory_bytes: 9680
#include<algorithm>
#include<iostream>
#include<cstring>
#include<string>
#include<vector>
#include<cstdio>
#include<cmath>
#include<map>
#include<set>
using namespace std;
int n,q;
pair <string,long long> que[110005];
pair <long long,string> ans[100005];
const long long mod=100005;
int main()
{
	scanf("%d%d",&n,&q);
    for(int i=0;i<n;i++)
    {
    	cin>>que[i].first;
    	scanf("%d",&que[i].second);
	}
	int f=0,cnt=n,sum=0;
	while(cnt)
	{
		int a=que[f].second;
		string b=que[f].first;
		if(a>q)
		{
			sum+=q;
			a-=q;
			que[(f+cnt)%mod].second=a;
			que[(f+cnt)%mod].first=b;
			f++;
			f%=mod;
		}
		else
		{
			sum+=a;
		    ans[n-cnt].first=sum;
		    ans[n-cnt].second=b;
		    cnt--;
			f++;
			f%=mod;
		}
	}
	for(int i=0;i<n;i++)
	    cout<<ans[i].second<<' '<<ans[i].first<<endl;
	return 0;
}


Measured memory_bytes: 8836
using System;
using System.IO;
using System.Collections.Generic;

namespace AGC032B
{
    public partial class Program
    {
        void Solve(StreamScanner ss, StreamWriter sw)
        {
            //---------------------------------
            var N = ss.Next(int.Parse);
            var sub = N + 1 - N % 2;
            var res = new List<string>();

            for (var i = 1; i < N; i++)
            for (var j = i + 1; j <= N; j++)
            {
                if (i + j == sub) continue;
                res.Add($"{i} {j}");
            }

            sw.WriteLine(res.Count);
            sw.WriteLine(string.Join("\n", res));
            //---------------------------------
        }
    }

    public class StreamScanner
    {
        static readonly char[] Separator = {' '};
        readonly StreamReader streamReader;

        string[] line = new string[0];
        int index = 0;

        public StreamScanner(Stream stream)
        {
            this.streamReader = new StreamReader(stream);
        }

        public string Next()
        {
            return Next(s => s);
        }

        public string[] Next(int x)
        {
            return Next(s => s, x);
        }

        public string[][] Next(int x, int y)
        {
            return Next(s => s, x, y);
        }

        public T Next<T>(Func<string, T> parser)
        {
            if (index < line.Length) return parser(line[index++]);
            index = 0;
            line = streamReader.ReadLine()?.Split(Separator, StringSplitOptions.RemoveEmptyEntries);
            return Next(parser);
        }

        public T[] Next<T>(Func<string, T> parser, int x)
        {
            var ret = new T[x];
            for (var i = 0; i < x; ++i) ret[i] = Next(parser);
            return ret;
        }

        public T[][] Next<T>(Func<string, T> parser, int x, int y)
        {
            var ret = new T[y][];
            for (var i = 0; i < y; ++i) ret[i] = Next(parser, x);
            return ret;
        }
    }

    public partial class Program
    {
        static void Main()
        {
            Excute(Console.OpenStandardInput(), Console.OpenStandardOutput());
        }

        public static void Excute(Stream input, Stream output)
        {
            var ss = new StreamScanner(input);
            var sw = new StreamWriter(output);
            new Program().Solve(ss, sw);
            sw.Flush();
        }
    }
}

Measured memory_bytes: 13280
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < n; i++)
#define REPR(i, n) for (int i = n; i >= 0; i--)
#define FOR(i, m, n) for (int i = m; i < n; i++)
#define FORR(i, m, n) for (int i = m; i >= n; i--)
#define INF 1e9;
using namespace std;
typedef long long ll;
int main() {
  string S;
  cin >> S;
  map<char, ll> mp;
  REP(i, S.length()) { mp[S[i]]++; }
  for (auto x : mp) {
    if (x.second > 1) {
      cout << "no";
      return 0;
    }
  }
  cout << "yes";
  return 0;
}

Measured memory_bytes: 256
import java.util.Arrays;
import java.util.Scanner;

public class Main {

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

		String a = sc.next();
		String b = sc.next();
		int count = 0;
		for (int i = 0; i < a.length(); i++) {
			if (a.charAt(i) != b.charAt(i)) {
				count++;
			}
		}
      
		System.out.println(count);
    }
}

Measured memory_bytes: 41224
#include <cstdio>
#include <climits>
#include <cmath>
#include <iostream>
#include <iomanip>
#include <string>
#include <cstdio>
#include <climits>
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <utility>
#include <queue>
#include <cstring>
#include <set>
#define rep(i, n) for (int i = 0; i < int(n); i++)
using namespace std;
long long MOD = 1000000007;
long long INF = 1000000000000000; //10^15
typedef long long ll;
typedef unsigned long long ull;

ll powMod(ll x, ll n) {
  if (n == 0) return 1;
  ll r = powMod(x, n / 2);
  if (n % 2 == 0) return (r * r) % MOD;
  return (r * r % MOD) * x % MOD;
}

bool ijv(int i, int j, int h, int w) {
  if (0 <= i && i < h && 0 <= j && j < w) return true;
  return false;
}


int main(void) {

  int n, p[200010];
  cin >> n;
  rep(i, n) cin >> p[i];
  int mi = INT_MAX;
  int ans = 0;
  rep(i, n) {
    if (mi >= p[i]) ans++;
    mi = min(mi, p[i]);
  }
  cout << ans << endl;
}


Measured memory_bytes: 1024
def main():
    n = int(input())
    a = sorted(list(map(int,input().split())),reverse=True)
    ans = a[0]
    for i in range(1,n-1):
        if i%2!=0:
            ans += a[(i+1)//2]
        else:
            ans += a[i//2]
    print(ans)


if __name__ == "__main__":
    main()


Measured memory_bytes: 31620
//*****Jai Mata di*****//

#include<bits/stdc++.h>
using namespace std;
#define Nitroboost  ios_base::sync_with_stdio(0);cin.tie(NULL);cout.tie(NULL)
#define ll long long int 
const int mod=1e9+7;
const int N=2e5+15;
#define debug cout<<"Good uptill here"<<endl<<flush;
#define deb(x) cout<<#x<<":"<<x<<endl<<flush;

vector<int>adj[N];
int h[N];
ll ans=0;
priority_queue<int,vector<int>,greater<int> >q;
vector<pair<int,int> >L,R;
int rsum[100],dsum[100];
int dp[100];


int main()
{
    Nitroboost;
    int n;
    cin>>n;
    int a[n];
    for(int i=0;i<n;i++)
        cin>>a[i];
    sort(a,a+n);
    ll sum=a[n-1];
    int rem=n-1-1;
    int ptr=n-2;
    int flag=0;
    while(rem--)
    {
      sum+=a[ptr];
      if(flag%2!=0){
        flag=0;
        ptr--;}
      else
      flag++;
    }
    
    cout<<sum;
}
    

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

import sys

def n_gram(target, n):
    return [ target[idx:idx + n] for idx in range(len(target) - n + 1)]

def main():
    s = input()
    t = input()
    ans_list=[]
    ans=[]
    count=0

    ans_list=n_gram(s,len(t))

    for word in ans_list:
        for str1,str2 in zip(word,t):
            if str1==str2:
                count+=1
        ans.append(count)
        count=0
    print(len(t)-max(ans))

if __name__ == "__main__":
    main()

Measured memory_bytes: 9204