akhauriyash/Code-Regression huggingface dataset:
import qualified Data.ByteString.Char8 as BS
import Data.Maybe

readInt = fst . fromJust . BS.readInt

readIntList = map readInt . BS.words

getIntList = readIntList <$> BS.getLine

main = do
  [n, r] <- getIntList
  print $ if n >= 10 then r else (r + (10 - n) * 100)


Measured memory_bytes: 3736
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N = 1035, INF = 0x3f3f3f3f, M = 2e6 + 5;
//
const ll LNF = 0x3f3f3f3f3f3f3f3f;
#define rep(i, l, r) for (int i = l; i <= r; i++)
#define per(i, r, l) for (int i = r; i >= l; i--)
#define repe(i, u) for (int i = head[u]; i; i = nxt[i])
int n, a[N][N], vis[N];
bool flag;
bool ok() {
  for (int i = 1; i <= n; i++)
    if (a[i][0] != n) return 0;
  return 1;
}

int main() {
  ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
  cin >> n;
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= n - 1; ++j) cin >> a[i][j];
    a[i][0] = 1;
  }
  for (int z = 0; z <= 0x3f3f3f3f; z++) {
    if (ok()) {
      cout << z << '\n';
      return 0;
    }
    flag = 0;
    memset(vis, 0, sizeof vis);
    for (int i = 1; i <= n; i++) {
      if (vis[i] || a[i][0] == n) continue;
      int x = a[i][a[i][0]];
      if (!vis[i] && !vis[x] && a[x][a[x][0]] == i) {
        a[i][0]++;
        a[x][0]++;
        vis[i] = vis[x] = 1;
        flag = 1;
      }
    }
    if (!flag) {
      cout << -1 << '\n';
      return 0;
    }
  }
  return 0;
}


Measured memory_bytes: 4352
/**
 * @author: shashankchdhry
 * @made:   2020-03-30 19:39:16 
**/
#include <bits/stdc++.h>

using namespace std;

inline bool check(int);

int arr[10];

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

    int n, k;
    cin >> n >> k;

    for (int i = 0; i < k; i++)
    {
        int temp;
        cin >> temp;
        arr[temp] = 1;
    }

    while (true)
    {
        if (check(n))
            break;
        n++;
    }
    cout << n << "\n";

    return 0;
}

bool check(int n)
{
    if (n == 0)
    {
        if (arr[n] == 1)
            return false;
    }
    while (n != 0)
    {
        int temp = n%10;
        n /= 10;
        if (arr[temp] == 1)
            return false;
    }
    return true;
}

Measured memory_bytes: 256
#include<iostream>
#include<cmath>
#include<cstdio>

using namespace std;

struct Zahyou{double x; double y;};

Zahyou Wa(Zahyou a,Zahyou b){
    Zahyou c;
    c.x = a.x + b.x;
    c.y = a.y + b.y;
    return c;
}

Zahyou Sa(Zahyou a,Zahyou b){
    Zahyou c;
    c.x = a.x - b.x;
    c.y = a.y - b.y;
    return c;
}

Zahyou Triple(Zahyou a,Zahyou b){
    Zahyou c;
    c.x = (b.x - a.x)/3;
    c.y = (b.y - a.y)/3;
    return c;
}

Zahyou Top(Zahyou a,Zahyou b){
    Zahyou k,c;
    k = Sa(b,a);
    c.x = k.x *cos(M_PI/3) - k.y *sin(M_PI/3);
    c.y = k.x *sin(M_PI/3) + k.y *cos(M_PI/3);
    return Wa(a,c);
}

void disp(Zahyou a){
    printf("%.8f %.8f\n",a.x,a.y);
}

void Koch(int n,Zahyou l,Zahyou r){
    if (n == 0 ) {
        return;
    }
    Zahyou mid1,mid2,top;
    mid1 = Wa(l,Triple(l,r));
    mid2 = Wa(mid1,Triple(l,r));
    top = Top(mid1,mid2);
    
    if(n == 1){
        disp(mid1);
        disp(top);
        disp(mid2);
        disp(r);
    }
    
    Koch(n-1,l,mid1);
    Koch(n-1,mid1,top);
    Koch(n-1,top,mid2);
    Koch(n-1,mid2,r);
}


int main(){
    int n;
    cin >> n;
    Zahyou A,B;
    A.x = 0; A.y = 0;
    B.x = 100; B.y = 0;
    disp(A);
    Koch(n,A,B);
    if (n==0) {
        disp(B);
    }
    return 0;
}

Measured memory_bytes: 1200
#include<bits/stdc++.h>
#pragma GCC optimize("Ofast")
using namespace std;
#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> indexed_set;

#define endl            "\n"
#define forn(i,x,n)     for(int i=x; i<n; i++)
#define forit(it, m)    for(decltype(m)::iterator it = m.begin(); it!=m.end(); ++it)
#define ff              first
#define ss              second
#define int             long long
#define pb              push_back
#define mp              make_pair
#define pii             pair<int,int>
#define vi              vector<int>
#define mii             map<int,int>
#define pqb             priority_queue<int>
#define pqs             priority_queue<int,vi,greater<int> >
#define setbits(x)      __builtin_popcountll(x)
#define zrobits(x)      __builtin_ctzll(x)
#define mod             1000000007
#define inf             1e18
#define ps(x,y)         fixed<<setprecision(y)<<x
#define mk(arr,n,type)  type *arr=new type[n];
#define w(x)            int x; cin>>x; while(x--)
mt19937                 rng(chrono::steady_clock::now().time_since_epoch().count());


void zeus()
{
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#endif
}
int fast_pow(long long base, long long n, long long M)
{
    if (n == 0)
        return 1;
    if (n == 1)
        return base;
    long long halfn = fast_pow(base, n / 2, M);
    if (n % 2 == 0)
        return ( halfn * halfn ) % M;
    else
        return ( ( ( halfn * halfn ) % M ) * base ) % M;
}
int32_t main() {

    zeus();

    int x;

    int n, d; cin >> n >> d;

    int cnt = 0;

    forn(i, 0, n) {
        int x, y; cin >> x >> y;
        if (x * x + y * y <= d * d) {
            cnt++;
        }
    }
    cout << cnt << endl;


}

Measured memory_bytes: 3644
#include<stdio.h>
#include<algorithm>
using namespace std;
int a[5];
int main()
{
    int i;
    for(i=0;i<3;i++)
        scanf("%d",&a[i]);
    sort(a,a+3);
    printf("%d\n",a[0]+a[1]);
    return 0;
}


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

public class Main {

	public static void main(String[] args) {

		Scanner scan = new Scanner(System.in);
		int a = scan.nextInt();
		int b = scan.nextInt();
		int c = scan.nextInt();
		int[] list = {a,b,c};
		int min = 0;
		int mid = 0;
		int max = 0;
		int count = 0;
		Arrays.sort(list);

		min = list[0];
		mid = list[1];
		max = list[2];

		for (int i = mid; i < max; i++) {
			count++;
			min++;
		}

		for (int j = min; j < max; j+=2) {
			count++;
			min += 2;
		}

		if (min == max) {
			System.out.println(count);
		} else {
			System.out.println(count + 1);
		}

		scan.close();

	}

}


Measured memory_bytes: 22100
--   1
-- 4 2 3 5 ??? 1????????¢???2?????£??¢
--   6

mov :: (Int,Int,Int,Int,Int,Int) -> Char -> (Int,Int,Int,Int,Int,Int)
mov (p1,p2,p3,p4,p5,p6) 'N' = (p2,p6,p3,p4,p1,p5)
mov (p1,p2,p3,p4,p5,p6) 'S' = (p5,p1,p3,p4,p6,p2)
mov (p1,p2,p3,p4,p5,p6) 'W' = (p3,p2,p6,p1,p5,p4)
mov (p1,p2,p3,p4,p5,p6) 'E' = (p4,p2,p1,p6,p5,p3)

ini :: [Int] -> (Int,Int,Int,Int,Int,Int)
ini (a:b:c:d:e:f:_) = (a,b,c,d,e,f)

-- ?????¢???????????????
m1 :: (Int,Int,Int,Int,Int,Int) -> Int -> (Int,Int,Int,Int,Int,Int)
m1 i@(p1,p2,p3,p4,p5,p6) n
  | p2 == n            = i
  | p4 == n || p3 == n = m1 (mov i 'E') n
  | otherwise          = m1 (mov i 'N') n

-- ?????¢???????????????
m2 :: (Int,Int,Int,Int,Int,Int) -> Int -> (Int,Int,Int,Int,Int,Int)
m2 i@(p1,p2,p3,p4,p5,p6) n
  | p1 == n            = i
  | otherwise          = m2 (mov i 'E') n

ans :: (Int,Int,Int,Int,Int,Int) -> (Int,Int,Int,Int,Int,Int) -> String
ans a@(a1,a2,a3,a4,a5,a6) b@(b1,b2,b3,b4,b5,b6) =
  let a'  = m1 a  b2
      a'' = m2 a' b1
  in
    if a'' == b
    then "Yes"
    else "No"

main = do
  l1 <- getLine
  l2 <- getLine
  let d1 = ini $ map read $ words l1
      d2 = ini $ map read $ words l2
      o  = ans d1 d2
  putStrLn o

Measured memory_bytes: 3672
#include <stdio.h>
#include <string.h>
#define N 10000000

void insert(int);
void inorder(int);
void preorder(int);
int find(int, int);

typedef struct{
  int k, r, l;
}Node;

Node T[N+1];
int M;

void insert(int x){
  int n = 0;
  while(1){
    if(x < T[n].k){
      if(T[n].l == -1){
        T[n].l = M;
        T[M++].k = x;
        break;
      }
      else n = T[n].l;
    }
    else{
      if(T[n].r == -1){
        T[n].r = M;
        T[M++].k = x;
        break;
      }
      else n = T[n].r;
    }
  }
}

void inorder(int n){
  if(T[n].l != -1){
    inorder(T[n].l);
  }
  printf(" %d", T[n].k);
  if(T[n].r != -1){
    inorder(T[n].r);
  }
}

void preorder(int n){
  printf(" %d",T[n].k);
  if(T[n].l != -1){
    preorder(T[n].l);
  }
  if(T[n].r != -1){
    preorder(T[n].r);
  }
}

int find(int n, int x){
  if(T[n].k == x) return 1;
  if(x < T[n].k && T[n].l != -1){
      if(find(T[n].l, x)) return 1;
    }
    if(T[n].k < x && T[n].r != -1){
      if(find(T[n].r, x)) return 1;
    }
    return 0;
}

int main(){
  int n, i, x, in, first=1;
  char str[100];

  scanf("%d",&n);

  for(i=0; i<=n; i++){
    T[i].k = T[i].l = T[i].r = -1;
  }
  M = 0;
  while(n--){
    scanf("%s",str);
    if(!strcmp(str, "insert")){
      scanf("%d", &x);
      if(first){
        T[M++].k = x;
        first = 0;
      }
      else insert(x);
    }
    else if(!strcmp(str, "find")){
      scanf("%d", &in);
      if(find(0., in) == 1) printf("yes\n");
      else printf("no\n");
    }
    else{
      inorder(0);
      printf("\n");
      preorder(0);
      printf("\n");
    }
  }
  return 0;
}

Measured memory_bytes: 6760
int w,h;
int d[9][9],q[9][9];
int a[4]={-1,0,1,0};
int X,Y,C,t;
int b=0;
int chk(int x,int y){
	int i=0,ans=1;
	if(q[y][x])return 0;
	q[y][x]=1;
	if(d[y][x])return y==Y&&x==X;
	for(;i<4;i++)ans+=chk(x+a[i],y+a[(i+1)%4]);
	return ans;
}
int dfs(int x,int y,int c){
	int i=0;
	if(!c&&x==X&&y==Y)return 1;
	memset(q,0,324);
	if(d[y][x]||chk(x,y) != c+(x!=X||y!=Y))return 0;
	if(b++ > 120000)return 2;
	d[y][x]=1;
	for(;i<4;i++)if(t=dfs(x+a[i],y+a[(i+1)%4],c-1))return t;
	return d[y][x]=0;
}
int main(i,j){
	for(;C=0,b=0,scanf("%d%d\n",&w,&h),h;puts(C>3&&dfs(X,Y,C)==1?"Yes":"No")){
		memset(d,-1,324);
		for(j=1;j<=h;j++)for(i=1;i<=w;i++)scanf("%d",&t),(d[j][i]=t)||(++C,X=i,Y=j);
	}
	return 0;
}

Measured memory_bytes: 388
#include <iostream>
#include <cstdio>
#include <vector>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <cmath>
#include <deque>
#include <algorithm>
#include <random>
#include <ctime>
using namespace std;
using ld = long double;
using ll = long long;
using pii = pair<int, int>;

#define int int64_t
#define pb push_back
#define pbb pop_back
#define pf pop_front
#define pff push_front
#define mp make_pair
#define all(c) (c).begin(),(c).end()
#define rall(c) (c).rbegin(),(c).rend()

const int INF = 1e6, MOD = 1e9 + 7, MAXN = 1e5 + 7;
const ld EPS = 1e-9, PI = acos(-1);

int32_t main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);

    int n;
    cin >> n;
    vector<pii> nums(n);
    for (int i = 0; i < n; ++i) {
        cin >> nums[i].first;
        nums[i].second = i;
    }

    sort(all(nums));
    vector<int> answer(n);
    for (int i = 0; i < n / 2; ++i)
        answer[nums[i].second] = nums[n / 2].first;
    for (int i = n / 2; i < n; ++i)
        answer[nums[i].second] = nums[n / 2 - 1].first;

    for (int elem : answer)
        cout << elem << "\n";

    return 0;
}


Measured memory_bytes: 5376
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <algorithm>
using namespace std;


int main()
{
	string S,T;
	cin>>S>>T;
	int flag=0;
	for (int i=0;i<S.length();i++)
	{
		if (S[i]==T[0])
		{
			string tmp1,tmp2;
			tmp1=S.substr(i,S.length());
			tmp2=S.substr(0,i);
			tmp1+=tmp2;
		//	cout<<tmp1<<endl;
			if (tmp1==T)
			{
				flag=1;
				break;
			}
		}
	}
	if (flag) puts("Yes");
	else puts("No");
	return 0;
}
 

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> d(n);
    rep(i,n) cin >> d[i];
    int sum = 0;
    for (int i = 0; i < n; i++) {
        for (int j = i+1; j < n; j++) {
            sum += d[i]*d[j];
        }
    } 
    cout << sum << endl;
    return 0;
}

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

typedef int in;
#define int long long
#define push_back pb
int MAX=1e9;
int MAXEST=1e18;
int MOD=1e9+7;

int n;
int a[405];
int dp[405][405];

int cost(int s,int e){
    int x=0;
    if(s) x=a[s-1];
    return a[e]-x;
}
int f(int s, int e){
    if(s==e){
        return 0;
    }
    int &ret=dp[s][e];
    if(ret!=-1)
        return ret;
    ret=MAXEST;
    for(int i=s;i<e;i++){
        int x=cost(s,i)+f(s,i);
        int y=cost(i+1,e)+f(i+1,e);
        ret=min(ret,x+y);
    }
    return ret;
}

in main()
{
    int tc=1;
//    cin>>tc>>st;
    while(tc--)
    {
        cin>>n;
        for(int i=0;i<n;i++){
            cin>>a[i];
            if(i)
                a[i]+=a[i-1];
        }
        memset(dp,-1,sizeof dp);
        cout<<f(0,n-1)<<endl;
    }
    return 0;
}


Measured memory_bytes: 4924
#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>;
#define chmax(x,y) x = max(x,y);
#define chmin(x,y) x = min(x,y);
const int di[] = {-1, 0, 1, 0};
const int dj[] = {0, -1, 0, 1};
const int INF = 1001001001;



int main() {
    string s;
    cin >> s;
    int n = s.size();
    vector<int> a(n);
    rep(i,n) {
        a[i] = s[i] - '0';
    }
    int b = INF;
    int ans = 0;
    rep(i,n-2) {
        int now = a[i]*100 + a[i+1]*10 + a[i+2];
        if (b > abs(753-now)) {
            ans = now;
            b = abs(753-now);
        }
    }
    cout << b << endl;
    return 0;
}

Measured memory_bytes: 3612
import math
import copy
from queue import Queue
import heapq
import numpy as np

MOD = 5000000007

#n = int(input())
#b = int(input())
a, b, k = [int(i) for i in input().split()]
#table = [[int(i)  for i in input().split()] for j in range(m)]
#table = [list(input()) for n in range(r)] #table[h][w]
#p = [int(i) for i in input().split()]
#s = [int(i) for i in range(n)]
#p = [int(input()) for i in range(m)]
#s = input()

#list = list(s)
#dp = [MOD for _ in range(m)]
#dp = [[0 for _ in range(n+1)] for _ in range(n+1)]
#dp = [[[0 for _ in range(11)] for _ in range(2)] for _ in range(11)]

#Combination = [[0 for _ in range(n+1)] for _ in range(n+1)]
#b = [[0 for _ in range(n+1)] for _ in range(n+1)]

count = 0
for i in range(100,0, -1):
    if((a % i == 0) and (b % i == 0)):
        count += 1
        if(count == k):
            print(i)


Measured memory_bytes: 12492
#include <assert.h>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <climits>
#include <algorithm>
#include <numeric>
#include <functional>
#include <iostream>
#include <string>
#include <array>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <complex>
#include <bitset>
typedef long long ll;
typedef unsigned long long ull;

# define INF 0x3f3f3f3f

#define REP(i, n) for (int i = 0; i < n; i++)
#define REPR(i, n) for (int i = n; i >= 0; i--)
#define DEBUG(vec) for (auto v : vec) { cout << v << " "; } cout << endl;

using namespace std;

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

  ll N, M;
  cin >> N >> M;
  if (M < N) {
    swap(N, M);
  }

  if (N >= 2) {
    cout << (N - 2) * (M - 2) << endl;
  } else {
    if (M == 1) {
      cout << 1 << endl;
    } else {
      cout << M - 2 << endl;
    }
  }
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main() {
  string S; cin >> S;
  string T; cin >> T;
  int cnt = 0;
  for(int i = 0; i < 3; i++){
    if(S[i] == T[i]) cnt++;
  }
  cout << cnt << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int N;
  long long int K;
  cin >> N >> K;
  vector<long long int> a(N);
  vector<long long int> f(N);
  long long int x = 1;
  for (int i = 0; i < N; i++) {
    cin >> a.at(i);
  }
  for (int i = 0; i < N; i++) {
    cin >> f.at(i);
    x = max(x, a.at(i) * f.at(i));
    f.at(i) = 0 - f.at(i);
  }
  sort(a.begin(), a.end());
  sort(f.begin(), f.end());
  long long int m = x / 2;
  long long int h = x;
  long long int l = 0;
  while (h - l > 1) {
    bool b = true;
    long long int k = 0;
    for (int i = 0; i < N; i++) {
      int F = 0 - f.at(i);
      long long int y = m / F;
      if (a.at(i) > y) {
        k += a.at(i) - y;
      }
      if (k > K) {
        b = false;
        break;
      }
    }
    if (b) {
      h = m;
      m = (l + h) / 2;
    }
    else {
      l = m;
      m = (h + l) / 2;
    }
  }
  bool L = true;
  long long int kl = 0;
  for (int i = 0; i < N; i++) {
    int F = 0 - f.at(i);
    long long int y = l / F;
    if (a.at(i) > y) {
      kl += a.at(i) - y;
    }
    if (kl > K) {
      L = false;
      break;
    }
  }
  if (L) {
    cout << l <<endl;
  }
  else {
    cout << h <<endl;
  }
}

Measured memory_bytes: 3328
#include "iostream"
using namespace std;
int main(){
    long long n,k,a,b;
    cin >>n>>k;
    if (k%2) {
        a=n/k;
        cout <<a*a*a<<endl;
    } else{
        a=n/k;
        b=(n+k/2)/k;
        cout <<a*a*a+b*b*b<<endl;
    }
}

Measured memory_bytes: 256
import java.io.IOException;
import java.io.InputStream;
import java.util.NoSuchElementException;

public class Main {
	public static void main(String[] args) {
		FastScanner sc = new FastScanner();
		int N = sc.nextInt();
		int D = sc.nextInt();
		System.out.println((N+2*D)/(2*D+1));
	}
}

class FastScanner {
    private final InputStream in = System.in;
    private final byte[] buffer = new byte[1024];
    private int ptr = 0;
    private int buflen = 0;
    private boolean hasNextByte() {
        if (ptr < buflen) {
            return true;
        } else {
            ptr = 0;
            try {
                buflen = in.read(buffer);
            } catch (IOException e) {
                e.printStackTrace();
            }
            if (buflen <= 0) {
                return false;
            }
        }
        return true;
    }

    private int readByte() {
        if (hasNextByte())
            return buffer[ptr++];
        else
            return -1;
    }

    private static boolean isPrintableChar(int c) {
        return 33 <= c && c <= 126;
    }

    public boolean hasNext() {
        while (hasNextByte() && !isPrintableChar(buffer[ptr]))
            ptr++;
        return hasNextByte();
    }

    public String next() {
        if (!hasNext())
            throw new NoSuchElementException();
        StringBuilder sb = new StringBuilder();
        int b = readByte();
        while (isPrintableChar(b)) {
            sb.appendCodePoint(b);
            b = readByte();
        }
        return sb.toString();
    }

    public long nextLong() {
        if (!hasNext())
            throw new NoSuchElementException();
        long n = 0;
        boolean minus = false;
        int b = readByte();
        if (b == '-') {
            minus = true;
            b = readByte();
        }
        if (b < '0' || '9' < b) {
            throw new NumberFormatException();
        }
        while (true) {
            if ('0' <= b && b <= '9') {
                n *= 10;
                n += b - '0';
            } else if (b == -1 || !isPrintableChar(b)) {
                return minus ? -n : n;
            } else {
                throw new NumberFormatException();
            }
            b = readByte();
        }
    }

    public int nextInt() {
        long nl = nextLong();
        if (nl < Integer.MIN_VALUE || nl > Integer.MAX_VALUE)
            throw new NumberFormatException();
        return (int) nl;
    }

    public double nextDouble() {
        return Double.parseDouble(next());
    }
}


Measured memory_bytes: 19796
# 再帰関数の呼び出し回数が多くなる時はこれが必要！！無いとruntime errorになる。
import sys
sys.setrecursionlimit(100000+10)

# 木の深さ優先探索
def add_edge(u, v):
	G[u].append(v)
	G[v].append(u)

def dfs(vertex, x_set, y_set):

	global visited

	if visited[vertex]:
		#探索済み
		return 0
	visited[vertex] = True

	x_set.add(coords[vertex][1])
	y_set.add(coords[vertex][2])
	for v in G[vertex]:
		if visited[v]:
			#探索済み
			pass
		else:
			dfs(v, x_set, y_set)

	return len(x_set)*len(y_set)

n = int(input())

G = [[] for _ in range(n)] #グラフの隣接リスト表現

visited = [False] * n
now_index = n-1

coords = [ [i] + list(map(int, input().split())) for i in range(n)]

from operator import itemgetter

# xでソート
coords_xs = sorted(coords, key = itemgetter(1))
for i in range(n-1):
	if coords_xs[i][1] == coords_xs[i+1][1]: 
		# 隣接 coords_xs[i][0] coords_xs[i+1][0]
		add_edge(coords_xs[i][0], coords_xs[i+1][0])

# yでソート
coords_ys = sorted (coords, key = itemgetter(2))
for i in range(n-1):
	if coords_ys[i][2] == coords_ys[i+1][2]: 
		# 隣接 coords_ys[i][0] coords_ys[i+1][0]
		add_edge(coords_ys[i][0], coords_ys[i+1][0])

# 深さ優先探索
final = 0
for i in range(n):
	x_set = {coords[i][1]} #set
	y_set = {coords[i][2]}
	final += dfs(i, x_set, y_set)

print(final - n)
# print(coords)


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

#define FOR(i, a, b) for (int (i) = (a); (i) < (b); i++)
#define REP(i, n) FOR(i, 0, n)
//#define TRACE(x) cerr << #x << " " << x << endl
#define TRACE(x)
#define eb emplace_back
#define _ << " " <<
typedef long long ll;
typedef std::pair<int, int> ii;
#define X first
#define Y second
#define double long double
typedef double db;
using namespace std;

const int MaxN = 200100;
const int Mod = 1e9 + 7;

int N;
ll dp[20][20][20];

ll solve(string S, string A, string B) {
  dp[0][0][0] = 1;

  TRACE(S _ A _ B);

  FOR(i, 1, N + 1) {
    FOR(a, 0, (int)A.size() + 1) {
      FOR(b, 0, (int)B.size() + 1) {
        dp[i][a][b] = 0; 
        if (a == 0 && b == 0) continue;

        if (a > 0){
          dp[i][a][b] += (S[i-1] == A[a-1]) ? dp[i-1][a-1][b] : 0;
          TRACE(i _ a _ b);
        }
        if (b > 0){
          dp[i][a][b] += (S[i-1] == B[b-1]) ? dp[i-1][a][b-1] : 0;
          TRACE(i _ a _ b);
        }
      }
    }
  }


  return dp[N][(int)A.size()][(int)B.size()];
}

void load() {
  cin>>N;
  string S;
  cin>>S;

  ll ret = 0;
  REP(mask, (1 << N)) {
    if (mask & 1) continue;
    string A, B;
    REP(i, N) {
      if ((1 << i) & mask) A += S[i];
      else B += S[i];
    }

    string P;
    FOR(i, N, 2*N)
      P = S[i] + P;

    ret += solve(P, A, B);
  }

  cout << ret * 2 << endl;
}

int main() {
  ios_base::sync_with_stdio(false);
  load();	
  return 0;
}




Measured memory_bytes: 384
n = int(input())
edge = [[] for _ in range(n)]
for _ in range(n-1):
  a, b = map(int, input().split())
  edge[a-1].append(b-1)
  edge[b-1].append(a-1)
 
group = [False] * n
parent = list(range(n))
stack = [0]
while stack:
  v = stack.pop()
  while edge[v]:
    u = edge[v].pop()
    if parent[v] != u:
      group[u] = not group[v]
      parent[u] = v
      stack.append(u)
 
three = 3
p = [0] * n
if group.count(False) <= n // 3:
  other = 1
  for i in range(n):
    if group[i] and other <= n:
      p[i] = other
      other += other % 3
    else:
      p[i] = three
      three += 3
elif group.count(True) <= n // 3:
  other = 1
  for i in range(n):
    if not group[i] and other <= n:
      p[i] = other
      other += other % 3
    else:
      p[i] = three
      three += 3
else:
  one, two = 1, 2
  for i in range(n):
    if group[i] and one <= n:
      p[i] = one
      one += 3
    elif not group[i] and two <= n:
      p[i] = two
      two += 3
    else:
      p[i] = three
      three += 3
print(' '.join(map(str, p)))

Measured memory_bytes: 121804
#define ll long long
#define FOR(i, begin, end) for(ll i=(begin);i<(end);i++)
#define REP(i, n) FOR(i,0,n)
#define SORT(a) sort(a.begin(), a.end())
#define SORTD(a) sort(a.rbegin(), a.rend());
#define UNIQUE(a) unique(a.begin(), a.end())
#define INF 1000000000000000000
#define INT_MAX 2147483647

#include <iostream>
#include <string>
#include <vector>
#include <cmath>
#include <cctype>
#include <numeric>
#include <algorithm>
#include <queue>
#include <set>
#include <utility>
#include <ios>
#include <iomanip>
#include <sstream>
#include <map>

using namespace std;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using vi = vector<int>;
using vl = vector<ll>;

const ll mod = 1e9+7;

int main() {
	ll n;
	cin >> n;
	ll sum = 0;
	ll minus = 0;
	ll min = INF;
	ll a;

	REP(i, n) {
		cin >> a;
		if (a > 0) {
			sum += a;
			if (min > a) {
				min = a;
			}
		}
		else {
			minus++;
			sum += a * (-1);
			if (min > a*(-1)) {
				min = a * (-1);
			}
		}
	}
	if (minus % 2 == 0) {
		cout << sum << endl;
	}
	else {
		cout << sum - min*2 << endl;
	}
}

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

int main() {
	int n, q; cin >> n >> q;
	string s; cin >> s;
	vector<int>dp(n+1,0);
	for (int i = 1; i <= n; i++) {
		if (s[i - 1] == 'A' && s[i] == 'C')dp[i] = dp[i - 1] + 1;
		else dp[i] = dp[i - 1];
	}

	for (int i = 0; i < q; i++) {
		int l, r; cin >> l >> r; l--, r--;
		cout << dp[r] - dp[l] << endl;
	}

	return 0;
}

Measured memory_bytes: 1536
#include <bits/stdc++.h>
#define MOD 1000000007
using namespace std;

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

long long modinv(long long a, long long m=MOD) {
    long long b = m, u = 1, v = 0;
    while (b) {
        long long t = a / b;
        a -= t * b; swap(a, b);
        u -= t * v; swap(u, v);
    }
    u %= m; 
    if (u < 0) u += m;
    return u;
    /*MODの割り算の際に
    a/＝b;
    を
    a *= modinv(b,MOD);
    とする。
        */
}


int main(){
    ll X ;
    ll A,B;
    cin >> X;
    for(int i=-200;i<=200;i++) {
        ll s = pow(i,5);
        for(int j=-200;j<=200;j++)  {
            ll k = pow(j,5);
            if(s-k==X){
                A = i;
                B = j;
            }
        }
    }

    cout << A << " " << B << endl;
    
    return 0;
}

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

int main(){
        ll n; scanf("%lld", &n);
        vector<ll> a(1000000, 0);
        for(ll i=0; i<n; i++){
                ll tmp; scanf("%lld", &tmp);
                a[tmp]++;
        }

        ll ans = 0;
        for(ll i=1; i<99999; i++) ans = max(ans, a[i-1]+a[i]+a[i+1]);
        printf("%lld\n", ans);
        return 0;
}

Measured memory_bytes: 8064
import java.util.*;
public class Main {
    private static long N, M, K;
    private static final long MOD = 998244353L;
    private static Map<Long, Long> ans = new HashMap<>();
    public static void main(String args[]){
        Scanner sc = new Scanner(System.in);
        N = sc.nextLong();
        M = sc.nextLong();
        K = sc.nextLong();
        long sum = 0;
        initCom();
        for(int i=0;i<=K;i++){
            sum += fun(i);
            sum %= MOD;
        }
        System.out.println(sum);
    }
    static int MAX = 510005;

    private static long[] FAC = new long[MAX];
    private static long[] INV_FAC = new long[MAX];

    private static void initCom(){
        FAC[0]=FAC[1]=1;
        INV_FAC[0]=INV_FAC[1]=1;
        for(int i=2;i<MAX;i++){
            FAC[i]=FAC[i-1]*i % MOD;
            INV_FAC[i]=modinv(FAC[i]);
        }
    }

    private static long comb(int n, int k){
        return (((FAC[n] * INV_FAC[n-k]) % MOD) * INV_FAC[k]) % MOD;
    }


    private static long modpow(long a, long b){
        if(b == 1){
            return a % MOD;
        }
        if(b == 0){
            return 1;
        }
        long res = b/2;
        long rem = b%2;
        long p = modpow(a, res) % MOD;
        if(rem == 1){
            return (((p*p) % MOD)*a) % MOD;
        }else{
            return (p*p) % MOD;
        }
    }

    private static long modinv(long a){
        return modpow(a, MOD-2);
    }


    private static long lucus(int n, int k, int mod){
        long res = 1L;
        while(n > 0){
            int n1 = n % mod;
            int k1 = k % mod;
            if(n1 == k1){
                res *= 1;
                n /= mod;
                k /= mod;
                continue;
            }else if(n1 < k1){
                res = 0;
                break;
            }else {
                res *= (long) comb(n1, k1);
                res %= mod;
                n /= mod;
                k /= mod;
            }
        }
        return res;
    }

    private static long fun(int k){
        long ans = comb((int)N-1, k);
        ans %= MOD;
        ans *= M;
        ans %= MOD;
        ans *= modpow(M-1, N-k-1);
        ans %= MOD;
        return ans;
    }

}


Measured memory_bytes: 44288
# -*- coding: utf-8 -*-
n = int(input())
a = list(map(int,input().split()))

m = a[0]

def gcd(a, b):
    if a < b:
        a, b = b, a
    if b == 0:
        return a
    c = a % b
    return gcd(b, c)

def lcm(a, b):
    "gcd関数を必要とする"
    return (a * b) // gcd(a,b)

for i in range(n):
    m = lcm(m,a[i])

m -= 1

ans = 0

for i in range(n):
    ans += m % a[i]

print(ans)

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

using namespace std;
typedef long long ll;
#define rep(i, n) for(int i=0; i<(int)n; i++)
#define rept(i, a, b) for(int i=a ; i<=b; i++)
    
int main(){
    int n; cin >> n;
    int w[n+1]; rept(i, 1, n) cin >> w[i]; 
    int s1, s2;
    int mi = 10000;
    
    rept(t, 1, n-1){
        s1 = 0; s2 = 0;
        rept(i, 1, n){
            if(i<=t) s1 += w[i];
            else s2 += w[i];
        }
        if(mi >= abs(s1 - s2)) mi = abs(s1- s2);
    }
    cout << mi << endl;
}
                
    

Measured memory_bytes: 256
while True:
    H, W = map(int, input().split())
    if H == 0 and W == 0:
        break
    
    for h in range(H):
        row = []
        for w in range(W):
            if w % 2 == h % 2:      # h, wの偶奇のパターンは一致する
                row.append("#")
            else:
                row.append(".")
                
        print("".join(row))
                
    print()


Measured memory_bytes: 5616
#include<cstdio>
#include<iostream>
#include<algorithm>
#include<cstring>
#include<cmath>
typedef long long ll;
typedef double dd;
#define For(i,j,k) for (int i=(int)j;i<=(int)k;++i)
#define Forr(i,j,k) for (int i=(int)j;i>=(int)k;--i)
#define Set(a,p) memset(a,p,sizeof(a))
using namespace std;

template<typename T>bool chkmax(T &a,T b) { return a<b?a=b,1:0; }
template<typename T>bool chkmin(T &a,T b) { return a>b?a=b,1:0; }

const int maxn=1e6+1e2;
struct Edge {
	int from,to,dis;
}e[100];
int N,n;
int ansn,m;
int Log[maxn],a[100];

inline void file() {
	freopen("ARC102D.in","r",stdin);
	freopen("ARC102D.out","w",stdout);
}

inline void add(int from,int to,int dis) {
	e[++m]=(Edge){from,to,dis};
}

inline void print() {
	printf("%d %d\n",ansn,m);
	For (i,1,m) printf("%d %d %d\n",e[i].from,e[i].to,e[i].dis);
}

int main() {
//	file();
	scanf("%d",&N);
	For (i,2,N+1) Log[i]=Log[i>>1]+1;
//	For (i,1,N) cout << Log[i] << endl;
	n=Log[N]; ansn=n+1; N-=(1<<n);
	For (i,2,n+1) {
		add(i-1,i,(1<<(n+1-i)));
		add(i-1,i,0);
		a[n+1-i]=i;
	}
	int NN=0;
	while (N>0) {
//		cout << "N=" << N << endl;
		NN+=(1<<n); n=Log[N];
		add(1,a[n],NN);
		N-=(1<<n);
	}
	print();
	return 0;
}

Measured memory_bytes: 4096
INT = lambda: int(input())
INTM = lambda: map(int,input().split())
STRM = lambda: map(str,input().split())
STR = lambda: str(input())
LIST = lambda: list(map(int,input().split()))
def do():
    n=INT()
    print(n*800-n//15*200)
if __name__ == '__main__':
    do()

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

#define reg register
typedef long long ll;
#define rep(i,a,b) for(int i=a,i##end=b;i<=i##end;++i)
#define drep(i,a,b) for(int i=a,i##end=b;i>=i##end;--i)

char IO;
int rd(){
	int s=0,f=0;
	while(!isdigit(IO=getchar())) if(IO=='-') f=1;
	do s=(s<<1)+(s<<3)+(IO^'0');
	while(isdigit(IO=getchar()));
	return f?-s:s;
}

const int N=810;
const int z[5][4]={{0,1},{0,-1},{1,0},{-1,0}};

int n;
string s;


int main(){
	n=rd();
	if(n>=3200) {
		cin>>s;
		cout<<s<<endl;
	} else puts("red");
	;
}









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

int main() {
    long long N, Q;
    cin >> N >> Q;
    string S;
    cin >> S;
    vector <int> a(N, 0);
    for (long long i=0; i<N; i++) {
        if (i+1 < N && S.at(i)=='A' && S.at(i+1)=='C') a.at(i) = 1;
    }
    vector <long long> s(N+1, 0);
    for (long long i=0; i<N; i++) {
        s.at(i+1) = s.at(i) + a.at(i); 
    }
    vector <long long> ans(Q);
    for (long long i=0; i<Q; i++) {
        long long l,r;
        cin >> l >> r;
        ans.at(i) = s.at(r-1) - s.at(l-1);
    }
    for (long long i=0; i<Q; i++) cout << ans.at(i) << endl;
}

Measured memory_bytes: 5308
n, x, y = map(int, input().split())
x -= 1
y -= 1
ans_l = [0]*n

def min_dist(a,b):
    return min(b-a, abs(x-a)+1+abs(y-b), abs(x-b)+1+abs(y-a))
for i in range(n):
    for j in range(i, n):
        ans_l[min_dist(i,j)] += 1
print('\n'.join([str(ans) for ans in ans_l[1:]]))

Measured memory_bytes: 3188
'use strict'

const main = arg => {
    const input = arg.trim().split("\n");
    const matrixNum = input[0].split(" ").map(str => parseInt(str, 10));
    const a = input.slice(1).slice(0, matrixNum[0]);
    const b = input.slice(1).slice(matrixNum[0], input.length).map(str => parseInt(str, 10));
    const result = [];

    a.forEach((matrix, i) => {
        const m = matrix.split(" ").slice(0, matrixNum[1]).map(str => parseInt(str, 10));
        var sum = 0;

        m.forEach((a, j) => { sum += a * b[j]  });
        result.push(sum);
    });

    console.log(result.join("\n"));
}

main(require('fs').readFileSync('/dev/stdin', 'utf8'));


Measured memory_bytes: 17404
public class Main {

  private static void solve() {
    int n = ni();
    System.out.println(n * n * n);

  }

  public static void main(String[] args) {
    new Thread(null, new Runnable() {
      @Override
      public void run() {
        long start = System.currentTimeMillis();
        String debug = args.length > 0 ? args[0] : null;
        if (debug != null) {
          try {
            is = java.nio.file.Files.newInputStream(java.nio.file.Paths.get(debug));
          } catch (Exception e) {
            throw new RuntimeException(e);
          }
        }
        reader = new java.io.BufferedReader(new java.io.InputStreamReader(is), 32768);
        solve();
        out.flush();
        tr((System.currentTimeMillis() - start) + "ms");
      }
    }, "", 64000000).start();
  }

  private static java.io.InputStream is = System.in;
  private static java.io.PrintWriter out = new java.io.PrintWriter(System.out);
  private static java.util.StringTokenizer tokenizer = null;
  private static java.io.BufferedReader reader;

  public static String next() {
    while (tokenizer == null || !tokenizer.hasMoreTokens()) {
      try {
        tokenizer = new java.util.StringTokenizer(reader.readLine());
      } catch (Exception e) {
        throw new RuntimeException(e);
      }
    }
    return tokenizer.nextToken();
  }

  private static double nd() {
    return Double.parseDouble(next());
  }

  private static long nl() {
    return Long.parseLong(next());
  }

  private static int[] na(int n) {
    int[] a = new int[n];
    for (int i = 0; i < n; i++)
      a[i] = ni();
    return a;
  }

  private static char[] ns() {
    return next().toCharArray();
  }

  private static long[] nal(int n) {
    long[] a = new long[n];
    for (int i = 0; i < n; i++)
      a[i] = nl();
    return a;
  }

  private static int[][] ntable(int n, int m) {
    int[][] table = new int[n][m];
    for (int i = 0; i < n; i++) {
      for (int j = 0; j < m; j++) {
        table[i][j] = ni();
      }
    }
    return table;
  }

  private static int[][] nlist(int n, int m) {
    int[][] table = new int[m][n];
    for (int i = 0; i < n; i++) {
      for (int j = 0; j < m; j++) {
        table[j][i] = ni();
      }
    }
    return table;
  }

  private static int ni() {
    return Integer.parseInt(next());
  }

  private static void tr(Object... o) {
    if (is != System.in)
      System.out.println(java.util.Arrays.deepToString(o));
  }
}



Measured memory_bytes: 21332
import java.util.Scanner;

public class  Main{
	public static void main(String[] args) {
		Scanner src = new Scanner(System.in);
		int i = 1;
		
		while(true) {
			int a = src.nextInt();
			int b = src.nextInt();
       
			if((a == 0) && (b == 0)){
				break;
			}else {
				if(a < b) {
					System.out.println(String.format("%d %d",a ,b));
				}else {
					System.out.println(String.format("%d %d",b ,a));
				}
			}
   		}
	}
}



Measured memory_bytes: 40348
#!/usr/bin/env python3
import sys
INF = float("inf")


def solve(a: int, b: int):
    if a < b:
        a, b = b, a
    print(str(b)*a)
    return


def main():

    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    a = int(next(tokens))  # type: int
    b = int(next(tokens))  # type: int
    solve(a, b)


if __name__ == '__main__':
    main()


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

using namespace std;
using ll = long long;

int main() {
    string a, b;
    cin >> a >> b;
    ll n = stoi(a + b);

    for (int i = 1; i <= 1000; ++i) {
        if (i * i == n) {
            cout << "Yes" << endl;
            exit(EXIT_SUCCESS);
        }
    }

    cout << "No" << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define fast ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define int long long
#define endl "\n"
using namespace std;

int32_t main() {

    fast
    int n;
    cin>>n;

    vector<int>arr(n);

    for(auto&i:arr){
        cin>>i;
    }
    int maxSoFar=INT_MIN;

    int sum=0;

    for(int i=0;i<n;i++){
        if(arr[i]>=maxSoFar){
            maxSoFar=arr[i];
        }
        else{
            sum+=(maxSoFar-arr[i]);
        }
    }
    cout<<sum;



    return 0;
}



Measured memory_bytes: 4748
#include<bits/stdc++.h>
#include<sstream>
#define _ ios_base::sync_with_stdio(0);cin.tie(0);
#define REP(i,n) for(int i=0;i<(int)(n);i++)

using namespace std;

void call(int n){
  for(int i=1;i<=n;i++){
    stringstream ss;
    ss<<i;
    char c[8];
    ss>>c;
    if(i%3==0||strstr(c,"3"))
      cout<<" "<<i;
  }
  cout<<endl;
}

int main(){ _;
  int n;cin>>n;
  call(n);
}

Measured memory_bytes: 1224
//参加気分でさ

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0; i < (n); i++)
#define rep1(i, n) for(int i = 1; i <= (n); i++)
#define co(x) cout << (x) << "\n"
#define cosp(x) cout << (x) << " "
#define ce(x) cerr << (x) << "\n"
#define cesp(x) cerr << (x) << " "
#define pb push_back
#define mp make_pair
#define Would
#define you
#define please


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


	int N;
	cin >> N;
	
	int kotae[100001];

	rep1(i, N) {
		int A;
		cin >> A;

		kotae[A] = i;
	}

	rep1(i, N) cout << kotae[i] << " ";

	Would you please return 0;
}

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

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

Measured memory_bytes: 256
#!/usr/bin/env python3
import sys


def f(n, N, K):
    '''
    >>> f(2, 10, 2)
    0
    >>> f(1, 10, 0)
    10
    >>> f(1, 10, 1)
    0
    >>> f(2, 10, 1) # 1, 3, 5, 7, 9
    5
    >>> f(3, 10, 0) 
    10
    >>> f(3, 10, 1) # 1, 2, 4, 5, 7, 8, 10
    7
    >>> f(3, 10, 2) # 2, 5, 8
    3
    >>> f(5, 5, 2)
    3
    '''
    if n <= K:
        return 0
    if K == 0:
        return N
    ans = max(N % n - (K - 1), 0)
    ans += N // n * (n - K)
    return ans


def solve(N: int, K: int):
    ans = 0
    for b in range(N+1):
        #print(b, f(b, N, K))
        ans += f(b, N, K)
    return ans


# Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    K = int(next(tokens))  # type: int
    print(solve(N, K))

def test():
    import doctest
    doctest.testmod()

if __name__ == '__main__':
    test()
    main()


Measured memory_bytes: 8296
#include <stdio.h>

int main()
{
	int a, b, c, k;
	
	scanf("%d %d %d %d", &a, &b, &c, &k);
	
	if(a >= b && a >= c) printf("%d", a*(1<<k) + b + c);
	else if(b >= c) printf("%d", a + b*(1<<k) + c);
	else printf("%d", a + b + c*(1<<k));
	
	return 0;
}

Measured memory_bytes: 128
#include <algorithm>
#include <climits>
#include <complex>
#include <cstring>
#include <iostream>
#include <map>
#include <set>
#include <vector>

// using
using namespace std;

// typedef
typedef long long ll;

// define
#define ALL(c) (c).begin(), (c).end()
#define SORT(c) sort(ALL(c))
#define REVERSE(c) reverse(ALL(c))
#define UNIQ(c) unique(ALL(c))
#define FOR(i, a, b, c) for (int i = (int)(a); i < (int)(b); i += (int)(c))
#define REP(i, n) FOR(i, 0, n, 1)
#define RFOR(i, a, b, c) for (int i = (int)(a); i >= (int)(b); i -= (int)(c))
#define RREP(i, n) RFOR(i, n, 0, 1)

// functions
int ceil(int a, int b) {
    return (a + b - 1) / b;
}
int round(int a, int b) {
    return (a + b / 2) / b;
}
int gcd(int a, int b) {
    return b ? gcd(b, a % b) : a;
}
int lcm(int a, int b) {
    return a * b / gcd(a, b);
}
template <class T> bool amax(T &a, const T &b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}
template <class T> bool amin(T &a, const T &b) {
    if (b < a) {
        a = b;
        return true;
    }
    return false;
}

// main
int main() {
    string S;
    ll K;
    cin >> S >> K;
    int N = S.size(), cnt = 0;
    REP(i, N) {
        if (S[i] == '1') {
            cnt++;
        } else {
            break;
        }
    }
    if (cnt >= K) {
        cout << 1 << endl;
    } else {
        cout << S[cnt] << endl;
    }
    return 0;
}


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

bool goodness(string s, int i){
  bool ans = true;
  for(int n=0;n<3;n++){
    ans = ans && (s[n+i] == s[i]);
  }
  return ans;
}

int main() {
  string N;
  cin >> N;
  string ans;
  if(goodness(N,0) || goodness(N,1)){
    cout << "Yes" << endl;
  } else{
  	cout << "No" << endl;
  }
}


Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define sz(x) ((int)(x).size())
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define repr(i, n) for (int i = (int)(n)-1; i >= 0; i--)
#define repf(i, x, n) for (int i = (int)(x); i < (int)(n); i++)
#define repfr(i, x, n) for (int i = (int)(x)-1; i >= (int)(n); i--)
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;
}
template <class T> inline void in(T &a) { cin >> a; }
template <class T, class U> inline void in(T &a, U &b) { cin >> a >> b; }
template <class T, class U, class V> inline void in(T &a, U &b, V &c) {
  cin >> a >> b >> c;
}
template <class T> inline void out(T a) { std::cout << a << endl; }
template <class T, class U> inline void out(T a, U b) {
  cout << a << ' ' << b << endl;
}
template <class T, class U, class V> inline void out(T a, U b, V c) {
  cout << a << ' ' << b << ' ' << c << endl;
}
#define inf 1e9
using ll = int64_t;

void Main() {
  ll n;
  in(n);

  int i = 0;
  while (n >= i * i) {
    i++;
  }

  out((i - 1) * (i - 1));

  return;
}

int main() {
  std::cin.tie(nullptr);
  std::ios_base::sync_with_stdio(false);
  std::cout << std::fixed << std::setprecision(15);
  Main();
  return 0;
}


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

namespace PowerSocke
{
    class Program
    {
        static void Main(string[] args)
        {
            var arr = Console.ReadLine().Split().Select(int.Parse).ToArray();

            var a = arr[0];
            var b = arr[1];
            var counter = 0;
            var temp = 1;

            while (temp < b)
            {
                temp--;
                temp += a;
                counter++;
            }

            Console.WriteLine(counter);
        }
    }
}


Measured memory_bytes: 13396
#include "bits/stdc++.h"
using namespace std;
int Array[505][505];
vector<pair<int,int> > Start , End;

int main(){
	int rows , cols , i , j;
	scanf( "%d%d" , &rows , &cols );

	for( i = 1 ; i <= rows ; ++i ){
		for( j = 1 ; j <= cols ; ++j )
			scanf( "%d" , &Array[i][j] );
	}

	for( i = 1 ; i <= rows ; ++i ){
		for( j = 1 ; j < cols ; ++j ){
			if( Array[i][j] % 2 == 1 ){
				--Array[i][j];
				++Array[i][j + 1];
				Start.emplace_back( make_pair( i , j ) );
				End.emplace_back( make_pair( i , j + 1 ) );
			}
		}
	}

	for( i = 1 ; i < rows ; ++i ){
		if( Array[i][cols] % 2 == 1 ){
			--Array[i][cols];
			++Array[i + 1][cols];
			Start.emplace_back( make_pair( i , cols ) );
			End.emplace_back( i + 1 , cols );
		}
	}

	printf( "%d\n" , int(Start.size()) );

	for( i = 0 ; i < int(Start.size()) ; ++i )
		printf( "%d %d %d %d\n" , Start[i].first , Start[i].second , End[i].first , End[i].second );
	return 0;
}

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

typedef long long ll;
typedef unsigned long long ull;
typedef string st;
typedef double db;
typedef vector<long long> vecll;
typedef vector<char> vechar;

int main(){
    ll A, B, C, X;
    cin >> A >> B >> C >> X;
    
    ll ans = 0;
    for(ll i = 0; i <= A; i++){
        for(ll j = 0; j <= B; j++){
            ll dif = X - 500 * i - 100 * j;
            if(dif % 50 == 0 && dif >= 0 && dif / 50 <= C) ans++;
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
from collections import Counter

n,k=list(map(int,input().split()))
enum=0
denom=2**20

for pip in range(1,n+1):
    cnt=0
    score=pip
    while score<k:
        score*=2
        cnt+=1
    
    enum+=2**(20-cnt)

print(enum/denom/n)

Measured memory_bytes: 66380
#include<bits/stdc++.h>
#define int long long int
#define f(i,s,e) for(i=s;i<e;++i)
#define fr(i,s,e) for(i=s;i>=e;i--)
#define ff(i,s,e,f) for(i=s;i<e && f;++i)
#define mem(arr,val) memset(arr, val, sizeof(arr))
#define mems(arr, val, n) memset(arr, val, n)
#define vec vector<int>
#define pr pair<int,int>
#define vp vector<trip>
#define _in(v) for(auto &x:v) cin>>x;
#define _out(v) for(auto x:v) cout<<x<<" "; cout<<endl;
#define lim 1000000
#define mod 1000000007
#define Arena ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define flush this_thread::sleep_for(chrono::seconds(0));
using namespace std;


signed main(void)
{
    Arena
    register int i,j,num,z,t=1;
    //cin>>t;
    f(z,1,t+1)
    {
        int n,k;cin>>k>>n;
        vec v(n);_in(v);
        int ans = abs(v[0]-v[n-1]);
        f(i,1,n)
        {
            int d = abs(v[i%n]-v[(n-1+i)%n]);
            ans=min(ans,k-d);
        }
        cout<<ans<<endl;
    }
    return 0;
}

Measured memory_bytes: 1792
#include <cmath>
#include <cstdio>
#include <vector>
#include <iostream>
#include <algorithm>
#include <queue>
#include <string>
#include <set>
#include <map>
#define REP(i,n) for(ll i = 0; i < (ll)n; i++)
#define INF 1000000000000000
using namespace std;
typedef long long ll;
typedef double db;
typedef string str;

int main(){
  int n;
  cin >> n;
  ll a[n];
  REP(i,n) cin >> a[i];
  sort(a,a+n);
  ll b[n];
  bool mergable[n];
  REP(i,n){
    if(i==0){
      b[i] = a[i];
      mergable[i] = false;
    }else{
      b[i] = b[i-1] + a[i];
      mergable[i] = a[i]<=2*b[i-1];
    }
  }
  int ans = 1;
  REP(i,n){
    if(!mergable[n-1-i]) break;
    ans++;
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 1920
n=int(input())
lists=list(map(int,input().split()))
a=1
b=0
for i in range (1,n+1):
  b=b+lists[i-1]
for j in range (1,n+1):
  if 2*lists[j-1]>=b:
    a=0
if a==0:
  print("No")
else:
  print("Yes")

Measured memory_bytes: 3064
# coding=utf-8

n = int(input())
M = [[0 for _ in range(n)] for _ in range(n)]
for _ in range(n):
    u, k, *v = map(int, input().split())
    u = u-1 #for index
    if k == 0:
        continue
    for num in v:
        num = num-1 #for index
        M[u][num] = 1
for row in M:
    print(*row)

Measured memory_bytes: 8428