akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
#define X first
#define Y second
#define pb emplace_back
#define FOR(i,a,b) for(int (i)=(a);i<(b);++(i))
#define EFOR(i,a,b) for(int (i)=(a);i<=(b);++(i))
#define rep(X,Y) for (int (X) = 0;(X) < (Y);++(X))
#define reps(X,S,Y) for (int (X) = S;(X) < (Y);++(X))
#define rrep(X,Y) for (int (X) = (Y)-1;(X) >=0;--(X))
#define rreps(X,S,Y) for (int (X) = (Y)-1;(X) >= (S);--(X))
#define all(X) (X).begin(),(X).end()
#define rall(X) (X).rbegin(),(X).rend()
#define eb emplace_back
#define UNIQUE(X) (X).erase(unique(all(X)),(X).end())

using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef ll LL;
typedef pii PII;
typedef pll PLL;
template<class T> using vv=vector<vector<T>>;
template<class T> inline bool MX(T &l,const T &r){return l<r?l=r,1:0;}
template<class T> inline bool MN(T &l,const T &r){return l>r?l=r,1:0;}
const ll MOD=1e9+7;

int N;
int M;
int A[114514];
vector<int> ms[2];
vector<int> ans;

int main() {
  scanf("%d%d", &N, &M);
  rep(i, M) {
    scanf("%d", &A[i]);
    ms[A[i]%2].eb(A[i]);
  }

  if (ms[1].size() > 2) {
    puts("Impossible");
    return 0;
  }

  if (M < 2) {
    printf("%d\n", A[0]);
    if (A[0] == 1) puts("1\n1");
    else printf("2\n%d %d\n", 1, A[0]-1);
    return 0;
  }

  while (ms[1].size() < 2) {
    assert(!ms[0].empty());
    ms[1].eb(ms[0].back());
    ms[0].pop_back();
  }

  ans.eb(ms[1][0]+1);
  for (int v : ms[0]) {
    ans.eb(v);
  }
  if (ms[1][1] > 1) {
    ans.eb(ms[1][1]-1);
  }

  printf("%d", ms[1][0]);
  for (int v : ms[0]) {
    printf(" %d", v);
  }
  printf(" %d\n", ms[1][1]);

  printf("%d\n", (int)ans.size());
  int K = ans.size();
  rep(i, K) {
    printf("%d%c", ans[i], " \n"[i == K-1]);
  }
}


Measured memory_bytes: 256
#include <stdio.h>

int main(void)
{
	/*?????°??£?¨?*/
	int r,c,i,j,sum;
	int data[101][101];
	
	/*??\???*/
	scanf("%d %d",&r,&c);
	for(i=0;i<r;i++){
		for(j=0;j<c;j++){
			scanf("%d",&data[i][j]);
		}
	}
	
	/*??????*/
	for(i=0;i<r;i++){
		sum=0;
		for(j=0;j<c;j++){
			sum+=data[i][j];
		}
		data[i][c]=sum;
	}
	for(i=0;i<=c;i++){
		sum=0;
		for(j=0;j<r;j++){
			sum+=data[j][i];
		}
		data[r][i]=sum;
	}
	
	/*??????*/
	for(i=0;i<=r;i++){
		for(j=0;j<=c;j++){
			if(j) printf(" ");
			printf("%d",data[i][j]);
		}
		printf("\n");
	}
	return 0;
}

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

int A[3][3],tmp[3][3],dx[4]={0,1,0,-1},dy[4]={1,0,-1,0};

void empty(int *x,int *y) {
  int i,j;
  for(i=0;i<3;i++){
    for(j=0;j<3;j++){
      if(!A[i][j]){
        *x=j;
        *y=i;
        return;
      }
    }
  }
}

void swap(int *a, int *b) {
  int tmp;
  tmp= *a;
  *a= *b;
  *b = tmp;
}


int cal() {
  int i,u,sum=0;
  for(i=0;i<9;i ++){
    u=A[i/3][i%3];
    if(u != 0){
      u--;
      sum += abs(i/3 - u/3)+abs(i%3 - u%3);
    }
  }
  return sum;
}

int dfs(int x, int y, int p, int d, const int lim) {
  int i,v,nx,ny,res;
  v=cal();
  if(v == 0) return d;
  
  if(d+v > lim) return -1;
  
  for(i=0;i<4;i++){
    nx = x+dx[i];
    ny = y+dy[i];
    if(~p&&i == (p+2)%4) continue;
    if(!(0 <= nx && nx < 3 && 0 <= ny && ny < 3)) continue;
    swap(&A[y][x],&A[ny][nx]);
    res=dfs(nx,ny,i,d+1,lim);

    if(~res) return res;
    
    swap(&A[y][x],&A[ny][nx]);
  }

  return -1;
}

int main() {
  int i,j,ans,x,y,l;
  for(i=0;i<3;i++){
    for(j=0;j<3;j++){
      scanf("%d",&A[i][j]);
    }
  }
  empty(&x,&y);
  for(l=0;l<100;l++){
    for(i=0;i<3;i++){
      for(j =0;j<3;j++){
        tmp[i][j] = A[i][j];
      }
    }
    ans = dfs(x,y,-1,0,l);
    if(ans != -1){
      printf("%d\n",ans);
      break;
    }

    for(i=0;i<3;i++){
      for(j=0;j<3;j++){
        A[i][j]=tmp[i][j];
      }
    }

    ans = -1;

    if(l == 99){
      printf("%d\n",ans);
    }
  }


  return 0;
}



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

int main(){
	cin.tie(0);
   	ios::sync_with_stdio(false);
	
	int N,K;
	cin>>N>>K;
    int max_k = (N-1)*(N-2)/2;
    if(K>max_k){
        cout<<-1<<"\n";
        return 0;
    }
    int d = max_k - K;
    int M = N-1+d;
    cout<<M<<"\n";
    rep(i,N-1){
        cout<<N<<" "<<i+1<<"\n";
    }
    int i=1,j=i+1;
    while(d>0){
        cout<<i<<" "<<j<<"\n";
        --d;
        ++j;
        if(j==N){
            ++i;
            j=i+1;
        }
    }    
	return 0;
}

Measured memory_bytes: 256
using System;
using System.Linq;
using static System.Console;
using static System.Math;
class E { static void Main() => new K(); }
class K
{
	int F() => int.Parse(ReadLine());
	int[] G() => ReadLine().Split().Select(x => int.Parse(x)).ToArray();
	const long Mod = 1000000007;
	int N;
	int[] A, B, M;
	bool[] X;
	public K()
	{
		N = F();
		A = G();
		B = G();
		M = new int[N];
		X = new bool[N];
		WriteLine(Calc());
	}
	long Calc()
	{
		for (var i = 0; i < N; i++) if (!H(i)) return 0;
		var a = 1L;
		for (var i = 0; i < N; i++) if (!X[i]) a = (a * M[i]) % Mod;
		return a;
	}
	bool H(int n)
	{
		var l = -1;
		if (n == 0 || A[n - 1] < A[n]) l = A[n];
		var r = -1;
		if (n == N - 1 || B[n] > B[n + 1]) r = B[n];
		if (l < 0 && r < 0)
		{
			M[n] = Min(A[n], B[n]);
			return true;
		}
		X[n] = true;
		if (l < 0) return r <= A[n];
		else if (r < 0) return l <= B[n];
		else return l == r;
	}
}


Measured memory_bytes: 25296
#include "stdio.h"
#include "math.h"
int main(int argc, char const *argv[])
{
	int num,i;
	int x[100],y[100];
	double ans1=0,ans2=0,ans3=0,ans4=0,max;
	scanf("%d",&num);
	for(i=0;i<num;i++)
		scanf("%d",&x[i]);
	for(i=0;i<num;i++)
		scanf("%d",&y[i]);
	for(i=0;i<num;i++){
		ans1 = ans1 + fabs(x[i]-y[i]);
		if(i==0)
			max = fabs(x[i]-y[i]);
		else if(max < fabs(x[i]-y[i]) )
			max = fabs(x[i]-y[i]);
	}
	for(i=0;i<num;i++){
		ans2 = ans2 + pow( fabs(x[i]-y[i]) , 2 );
	}
	ans2 = sqrt(ans2);
	for(i=0;i<num;i++){
		ans3 = ans3 + pow( fabs(x[i]-y[i]) , 3 );
	}
	ans3 = cbrt(ans3);	
	ans4 = max;
	printf("%lf\n",ans1);
	printf("%lf\n",ans2);
	printf("%lf\n",ans3);
	printf("%lf\n",ans4);
	return 0;
}


Measured memory_bytes: 708
#include<iostream>
#include<deque>
#include<vector>

using namespace std;

int main(){
  int n,q,nowTime=0;
  cin>>n>>q;
  deque<int> time;
  deque<string> name;
  vector<int> lastTime;
  vector<string> lastName;
  string S;
  int I;
  for(int i=0;i<n;i++){
    cin>>S>>I;
    name.push_back(S);
    time.push_back(I);
  }
  while(name.size()>0){
    if(time[0]>q){
      time[0]-=q;
      S=name[0];
      I=time[0];
      name.pop_front();
      time.pop_front();
      name.push_back(S);
      time.push_back(I);
      nowTime+=q;
    }else{
      nowTime+=time[0];
      S=name[0];
      name.pop_front();
      time.pop_front();
      lastName.push_back(S);
      lastTime.push_back(nowTime);
    }
  }
  for(int i=0;i<n;i++){
    cout<<lastName[i]<<" "<<lastTime[i]<<endl;
  }
}



Measured memory_bytes: 6640
import std.stdio, std.algorithm, std.conv, std.array, std.string, std.math, std.typecons, std.numeric;

void main()
{
    auto H = readln.chomp.to!int;
    auto W = readln.chomp.to!int;
    auto N = readln.chomp.to!int;
    writeln((N + max(H, W) - 1) / max(H, W));
}

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

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

int main(){

    int input[5];
    int i,j,k;
    int amari,amari_min=10,index=0;
    int ans=0;
    int num_kari;

    for(i=0;i<5;i++){
        cin >> input[i];
    }

    for(i=0;i<5;i++){
        amari = input[i] % 10;
        if(amari < amari_min && amari != 0){
            amari_min = amari;
            index = i;
        }
    }

    // cout << "amarimin=" << amari_min << endl;

    for(i=0;i<5;i++){
        if(i == index){
            continue;
        }
        num_kari = input[i];
        if(input[i] % 10 != 0){
            ans += input[i] + 10 - (num_kari % 10);
        }
        else ans += input[i];
    }

    ans += input[index];

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <memory>
#include <string>
#include <set>
#include <map>
#include <queue>
#include <tuple>

using namespace std;

int main() {
    int h, w;
    cin >> h >> w;
    vector<pair<int, int>> directions = {make_pair(-1, 0), make_pair(1, 0), make_pair(0, -1), make_pair(0, 1)};
    vector<bool> used(h * w, false);
    queue< tuple<int, int, int> > search_sets;
    for (int i = 0; i < h; i++) {
        string s;
        cin >> s;
        for (int j = 0; j < w; j++) {
            if (s[j] == '#') {
                used[i * w + j] = true;
                search_sets.push(make_tuple(i, j, 0));
            }
        }
    }
    int ans = 0;
    while (search_sets.size() > 0) {
        auto t = search_sets.front();
        search_sets.pop();
        int dist = get<2>(t);
        ans = max(ans, dist);
        for (auto d: directions) {
            int new_x = get<0>(t) + get<0>(d);
            int new_y = get<1>(t) + get<1>(d);
            if (new_x < 0 || new_x >= h || new_y < 0 || new_y >= w) {
                continue;
            }
            if (used[new_x * w + new_y]) {
                continue;
            }
            search_sets.push(make_tuple(new_x, new_y, dist + 1));
            used[new_x * w + new_y] = true;
        }
    }

    cout << ans << endl;
}

Measured memory_bytes: 12560
n = int(input())
creature_states = list(map(int, input().split()))
creature_states.sort()

count = 0
total_size = creature_states[0]

for i in range(1, n):
  if creature_states[i] <= total_size * 2:
    count += 1
  else:
    count = 0
  total_size += creature_states[i]

print(count + 1)

Measured memory_bytes: 14320
#include <iostream>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <string>
#include <list>
#include <queue>
#include <cmath>
#include <numeric>
using namespace std;

int inf = (1 << 30);
int mod = 1e9 + 7;
int64_t inf64 = (1LL << 60);

template <typename T>
T gcd(T a, T b) {
    if(b == 0) return a;
    else return gcd(b, a % b);
}

template <typename T>
T lcm(T a, T b) {
    T g = gcd(a, b);
    return a / g * b;
}

bool check(vector<int> a, int index, int key){
    if(a[index] >= key) return true;
    else return false;
}

int lower_bound(vector<int> a, int key){
    int left = -1, right = a.size();
    while(right - left > 1){
        int mid = left + (left + right) / 2;
        if(check(a, mid, key)) right = mid;
        else left = mid;
    }
    return right;
}

int main(){

    int N, M;
    cin >> N >> M;
    vector<int> k(M);
    vector<vector<int> > s(M);
    for(int i = 0; i < M; i++){
        cin >> k[i];
        for(int j = 0; j < k[i]; j++){
            int swi;
            cin >> swi;
            s[i].emplace_back(swi);
        }
    }
    vector<int> p(M);
    for(int i = 0; i < M; i++) cin >> p[i];

    int ans = 0;
    for(int bit = 0; bit < (1 << N); bit++){
        bool flag = true;
        for(int i = 0; i < M; i++){
            int count = 0;
            for(int j = 0; j < k[i]; j++){
                if(bit & (1 << (s[i][j] - 1))) count++;
            }
            if(count % 2 != p[i]){
                flag = false;
                break;
            }
        }
        if(flag) ans++;
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256
<?php
$a = [];
fscanf(STDIN, "%d %d %d", $a[0], $a[1], $a[2]);

sort($a);

if ($a[0] == 5 && $a[1] == 5 && $a[2] == 7) {
    echo "YES\n";
} else {
    echo "NO\n";
}


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

const int N = 1e5 + 10;
const int mod = 1e9 + 7;

int dp[N];
	
int main()
{
	int n,m;
	cin >> n >> m;
	set<int> no;
	for(int i=0;i<m;++i)
	{
		int x;
		cin >> x;
		no.insert(x);
	}

	dp[0] = 1;
	dp[1] = 1;
	
	for(int i=2;i<=n;++i)
	{
		if(no.count(i-1)==0)dp[i] = (dp[i] + dp[i-1])%mod;
		if(no.count(i-2)==0)dp[i] = (dp[i] + dp[i-2])%mod;
	}
	
	cout << dp[n]%mod;
}


Measured memory_bytes: 4992
#include<bits/stdc++.h> 
using namespace std; 
// Binary indexed tree supporting binary search.
 
 
#define x first
#define y second

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

typedef pair<int, int> pii;
//#define forn(i, a,b) for (int i = (int) a; i <= (int) b; ++i)
 struct road{
 	int u,v,a,b;
 };
const long long INF = 1000000000000000000;
const int MAXN = 55;
const int MAXM = 110;

map<pii,pii> edges; 
vector<road> roads(MAXM);
vector<pii> ps(MAXN);
vector<pair<pii,int> > adj[MAXN][MAXN*MAXN];
pii p[MAXN][MAXN*MAXN];
long long d[MAXN][MAXN*MAXN];
vector<long long> ans(MAXN);
void dijkstra(pair<int ,int> s) {
    forn(i,MAXN){
    	forn(j,MAXN*MAXN){
    		d[i][j] = INF;
    		p[i][j] = make_pair(-1,-1);
		}
	}
    d[s.x][s.y] = 0;
    priority_queue<pair<long long,pii>, vector<pair<long long,pii> >, greater<pair<long long,pii> > > q;
    q.push(make_pair(0,s));
    while (!q.empty()) {
        pii v = q.top().second;
        long long d_v = q.top().first;
        q.pop();
        if (d_v != d[v.x][v.y])
            continue;
		forn(i,adj[v.x][v.y].size()){
			pii to = adj[v.x][v.y][i].first;
            int len = adj[v.x][v.y][i].second;

            if (d[v.x][v.y] + len < d[to.x][to.y]) {
                d[to.x][to.y] = d[v.x][v.y] + len;
                p[to.x][to.y] = v;
                q.push({d[to.x][to.y], to});
            }
		}
        
    }
}
void process(int N,int M,int S){
	int maxa = 0;
	forn(i,M){
		if(roads[i].a >maxa){
			maxa = roads [i].a;
		}
	}
	int c = (N-1)*maxa;
	S = min(c , S);
	
	forn(i,N){
		forn(j,c+1){
			if(j+ps[i].x<=c)
				adj[i][j].push_back(make_pair(make_pair(i,j+ps[i].x),ps[i].y));
		}
	}
	forn(i,M){
		forn(j,c+1){
			if(j-roads[i].a>=0)
				adj[roads[i].u][j].push_back(make_pair(make_pair(roads[i].v,j-roads[i].a),roads[i].b));
			if(j-roads[i].a>=0)
				adj[roads[i].v][j].push_back(make_pair(make_pair(roads[i].u,j-roads[i].a),roads[i].b));
		}
	}
	dijkstra(make_pair(0,S));
	for(int j = 1;j<N;j++){
		long long mini = INF;
		for(int i = 0;i<=c;i++){
			if(d[j][i] <mini){
				mini = d[j][i];
			}
		}
		ans[j-1] = mini;
	}
	
}

int main(){
    ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
    int N,M,S;
	cin>>N>>M>>S;
	forn(i,M){
		int u,v,a,b;
		cin>>u>>v>>a>>b;
		u--;v--;
		roads[i].u = u;
		roads[i].v = v;
		roads[i].a = a;
		roads[i].b = b;
		edges[make_pair(u,v)] = make_pair(a,b);
		edges[make_pair(v,u)] = make_pair(a,b);
	}
	forn(i,N){
		cin>>ps[i].x>>ps[i].y;
	}
	process(N,M,S);
	forn(j,N-1){
		cout<<ans[j]<<'\n';
	}
	return 0;	
}

Measured memory_bytes: 23068
use std::io::stdin;

fn main() {
    let mut string = String::new();
    stdin().read_line(&mut string);
    let N: i64 = string.trim().parse().unwrap();
    let mut sum: i64 = 0;
    for i in 1..N+1 {
        if i % 3 != 0 {
            if i % 5 != 0 {
                sum += i;
            }
        }
    }
    println!("{:?}", sum);
}


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

int main() {
  int N, K;
  int sum= 0;
  cin >> N >> K;
  
  vector<int> p(N);
  for (int i = 0; i < N; i++) {
    cin >> p.at(i);
  }
    
  sort(p.begin(),p.end());
  for (int i = 0; i < K; i++) {
    sum += p.at(i);
  }
  
   cout << sum << endl;
}


Measured memory_bytes: 3628
/*
	ALDS1_1_B: Greatest Common Divisor
*/
#include	<iostream>
#include	<algorithm>

using namespace std;

int main(void) {
	int a, b, r;
	cin >> a >> b;
	while(1) {
		if(a < b) { swap(a, b); }
		r = a % b;
		if(r == 0) { break; }
		a = r;
	}
	cout << b << endl;
}

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

N = INT()
S = input()

tmp_W = 0
tmp_E = 0
W = []
E = []
ans = INF

cnt = [0]*len(S)
for i in range(len(S)):
	if S[i] == "W":
		tmp_W += 1
	cnt[i] += tmp_W

for i in range(len(S)-1, -1, -1):
	if S[i] == "E":
		tmp_E += 1
	cnt[i] += tmp_E

print(min(cnt)-1)
	





Measured memory_bytes: 17576
using System;

public class Test
{
	public static void Main()
	{
		string line = System.Console.ReadLine();
   		string[] ab = line.Split(' ');
   		double W = double.Parse(ab[0]);
   		double H = double.Parse(ab[1]);
   		double x = double.Parse(ab[2]);
   		double y = double.Parse(ab[3]);
   		double r = double.Parse(ab[4]);
   		
   		if( r <= x && x <= W-r && r <= y && y <= H-r){
   			Console.WriteLine("Yes");
   		}else{
   			Console.WriteLine("No");
   		}

	}
}

Measured memory_bytes: 9316
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef struct _dot{
    int x;
    int y;
}Dot;
bool Check(vector<Dot> list,int Assumption[]){
    
    for(int i=0;i<list.size();i++){
        if(Assumption[list[i].x ] != list[i].y) return false;
    }
    return true;
}
int main(){
    
    int N; cin >> N;
    vector<vector<Dot>> list(N);
    
    for(int i=0;i<N;i++){
        int k; cin >> k;
        for(int j=0;j<k;j++){
            int x,y; cin >> x >> y;
            Dot k; k.x = x-1; k.y = y;
            list.at(i).push_back(k);
        }
    }
    
    
    int ans = 0;
    int size = pow(2,N) - 1;
    for (int bits = size;bits >=0; bits--) {
        
        int Assumption[N];
        int num = 0;
        for(int i=0;i<N;i++){
            int mask = 1 << i;
            if(bits & mask){Assumption[i] = 1;num++;}
            else{Assumption[i] = 0;}
        }
        for (int i=0;i<N;i++) {
            int mask = 1 << i;
            if (bits & mask) {
            
                if(Check(list.at(i),Assumption) == false) break;
            }
            if(i== N-1 && ans < num) ans = num;
        }
 
    }
    cout << ans << endl;
}

Measured memory_bytes: 4032
#dpでできないかな？
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10**7)
from collections import Counter, deque
from collections import defaultdict
from itertools import combinations, permutations, accumulate, groupby, product
from bisect import bisect_left,bisect_right
from heapq import heapify, heappop, heappush
from math import floor, ceil,pi
from operator import itemgetter
def I(): return int(input())
def MI(): return map(int, input().split())
def LI(): return list(map(int, input().split()))
def LI2(): return [int(input()) for i in range(n)]
def MXI(): return [[LI()]for i in range(n)]
def SI(): return input().rstrip()
def printns(x): print('\n'.join(x))
def printni(x): print('\n'.join(list(map(str,x))))
inf = 10**17
mod = 10**9 + 7

def dfs(x,tree,al):
    for i in tree[x]:
        if al[i]<0:
            al[i]=0
            dfs(i,tree,al)
    
        
def main():  
    n,m=MI()
    lis=[LI() for i in range(m)]
    #print(lis)
    cou=0
    for i in range(m):
        tree=[[] for i in range(n)]
        for j in range(m):
            if i!=j:
                tree[lis[j][0]-1].append(lis[j][1]-1)
                tree[lis[j][1]-1].append(lis[j][0]-1)
        count=0
        for k in range(n):
            al=[-1]*n
            al[k]=0
            dfs(k,tree,al)
            #print(al)
            if not -1 in al:
                count+=1
        if count!=n:
            cou+=1
    print(cou)    

if __name__ == '__main__':
    main()

Measured memory_bytes: 3440
#include<bits/stdc++.h>
#define ll long long
#define mod 998244353
#define pb push_back
using namespace std;

int n; char s[109]; vector<int> a;
map<pair<vector<int>,bool>,int> mp;
int solve(vector<int> a,bool flag){
	int n=a.size();
	pair<vector<int>,bool> now=make_pair(a,flag);
	if (!n) return 1; if (n==1) return a[0]+1;
	if (mp.count(now)) return mp[now];
	int i,j,k,tmp,ans=0; vector<int> b,c;
	b.clear(); b.pb(a[0]);
	ans=solve(b,0);
	b.clear();
	for (i=1; i<n; i++) b.pb(a[i]);
	ans=(ll)ans*solve(b,0)%mod;
	for (i=1; i<=(n>>1); i++){
		b.clear();
		for (j=0; j<i; j++) b.pb(1);
		for (j=1; i*j<=n; j++){
			//if (i*j==n && flag) break;
			for (k=0; k<i; k++) b[k]&=a[i*(j-1)+k];
			if (j>1){
				tmp=solve(b,0);
				c.clear();
				for (k=i*j; k<n; k++) c.pb(a[k]);
				ans=(ans+(ll)tmp*solve(c,0))%mod;
			}
		}
	}
	
	mp[now]=ans; return ans;
}
int main(){
	scanf("%s",s+1); n=strlen(s+1);
	int i;
	for (i=1; i<=n; i++) a.pb(s[i]-'0');
	printf("%d\n",solve(a,0));
	return 0;
}


Measured memory_bytes: 7680
import sys, os

f = lambda:list(map(int,input().split()))
if 'local' in os.environ :
    sys.stdin = open('./input.txt', 'r')

def solve():
    x,a,b = f()

    after_by = a - b

    if a-b>=0:
        print('delicious')
    elif b-a<=x:
        print('safe')
    else:
        print('dangerous')

solve()


Measured memory_bytes: 3060
package main

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

type card struct {
	suite  string
	number int
}

func partition(a []card, left, right int) int {
	p := a[right].number // pivot
	i := left - 1                   // pivotより大きいものと小さいものの境目の位置
	for j := left; j < right; j++ { // left ~ right-1までa[j]をスキャンする
		if a[j].number <= p {
			i++
			a[i], a[j] = a[j], a[i]
		}
	}
	a[i+1], a[right] = a[right], a[i+1]
	return i + 1
}

func quickSort(a []card, left, right int) {
	if left < right {
		q := partition(a, left, right)
		quickSort(a, left, q-1)
		quickSort(a, q+1, right)
	}
}

func main() {
	var n int
	fmt.Scan(&n)
	sc := bufio.NewScanner(os.Stdin)
	sc.Split(bufio.ScanWords)

	cards := make([]card, n)
	ccards := make([]card, n)
	for i := 0; i < len(cards); i++ {
		sc.Scan()
		cards[i].suite = sc.Text()
		sc.Scan()
		cards[i].number, _ = strconv.Atoi(sc.Text())
	}
	copy(ccards, cards)
	quickSort(cards, 0, len(cards)-1)
	mergeSort(ccards, 0, len(cards))
	ok := true
	for i := 0; i < n; i++ {
		if cards[i].number == ccards[i].number && cards[i].suite != ccards[i].suite {
			ok = false
			break
		}
	}
	if ok {
		fmt.Println("Stable")
	} else {
		fmt.Println("Not stable")
	}
	for i := range cards {
		fmt.Printf("%s %d\n", cards[i].suite, cards[i].number)
	}
}

const inf = int(1e10) + 1

func merge(a []card, left, mid, right int) {
	// L : a[left:mid]
	// R : a[mid:right]
	// L,Rはそれぞれソートされている。これらをマージする
	L := make([]card, 0)
	R := make([]card, 0)
	var infcard card
	infcard.suite = "A"
	infcard.number = inf
	for i := 0; i < mid-left; i++ {
		L = append(L, a[left+i])
	}
	L = append(L, infcard)
	for i := 0; i < right-mid; i++ {
		R = append(R, a[mid+i])
	}
	R = append(R, infcard)
	var i, j int
	for k := left; k < right; k++ {
		if L[i].number <= R[j].number {
			a[k] = L[i]
			i++
		} else {
			a[k] = R[j]
			j++
		}
	}
}

func mergeSort(a []card, left, right int) {
	if left+1 < right {
		mid := (left + right) / 2
		mergeSort(a, left, mid)
		mergeSort(a, mid, right)
		merge(a, left, mid, right)
	}
}



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

using namespace std;

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

// chmax, chmin
template<class T>
inline bool chmax(T &a, T b) {
    if (a < b) {
        a = b;
        return 1;
    }
    return 0;
}

template<class T>
inline bool chmin(T &a, T b) {
    if (a > b) {
        a = b;
        return 1;
    }
    return 0;
}


int main() {
    int n;
    cin >> n;
    string s;
    cin >> s;
    int r = count(s.begin(), s.end(), 'R');
    cout << count(s.begin(), s.begin() + r, 'W') << endl;
    return 0;
}


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

using namespace std;

int main() {
  int n;
  cin >> n;
  multiset<long long> a;
  for (int i = 0; i < n; i++) {
    int num;
    cin >> num;
    a.insert(num);
  }

  int ans = 0;
  while (!a.empty()) {
    long long x = *a.rbegin();
    a.erase(a.find(x));
    long long next_two_power = 1;
    while (next_two_power <= x) {
      next_two_power <<= 1;
    }

    long long target = next_two_power - x;
    auto it = a.find(target);
    if (it != a.end()) {
      a.erase(it);
      ans++;
    }
  }
  cout << ans;
}


Measured memory_bytes: 9600
#include<iostream>
#include<vector>
int main() {
	int n,max=0,cou;
	std::vector<int> a, b;
	std::cin >> n;
	for (int i = 0; i < n; i++) {
		int x, y;
		std::cin >> x>>y;
		a.push_back(x);
		b.push_back(y);
	}
	for (int i = 0; i < n; i++) {
		if (max < a[i]) {
			cou = i;
			max = a[i];
		}
	}
	std::cout << a[cou] + b[cou] << std::endl;
	return 0;
}

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

int main()
{
    int h, a;
    cin >> h >> a;

    int answer = 0;
    while (h > 0)
    {
        answer++;
        h -= a;
    }

    cout << answer << endl;
}

Measured memory_bytes: 256
#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 INF 2e9
#define MOD 1e9+7;
#define ALL(v) v.begin(), v.end()
using namespace std;
typedef long long LL;
typedef vector<int> VI;
typedef vector<string> VS;

int main(){
    int A, B, K, cnt = 0;
    cin >> A >> B >> K;
    int G = __gcd(A, B);
    for (int i = G; i > 0; i--){
        if (G % i == 0){
            cnt++;
        }
        if (cnt == K){
            cout << i << endl;
            return 0;
        }
    }
}

Measured memory_bytes: 256
def same_string(a, b, start):
  if len(a) != len(b):
    return False
  
  for i in range(len(a)):
    if a[i] != b[start]:
      return False
    start = (start + 1) % len(b)
  return True


def can_rotate(a, b):
  for i in range(len(b)):
    if same_string(a, b, i):
      return True
  return False


a = input()
b = input()
print("Yes" if can_rotate(a, b) else "No")

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
vector<int> sprime(int n) 
{ 
    
    bool prime[n+1]; vector<int>v;
    memset(prime, true, sizeof(prime)); 
  
    for (int p=2; p*p<=n; p++) 
    { 
        // If prime[p] is not changed, then it is a prime 
        if (prime[p] == true) 
        { 
            // Update all multiples of p greater than or  
            // equal to the square of it 
            // numbers which are multiple of p and are 
            // less than p^2 are already been marked.  
            for (int i=p*p; i<=n; i += p) 
                prime[i] = false; 
        } 
    } 
  
    // Print all prime numbers 
    for (int p=2; p<=n; p++) 
      { if (prime[p]) 
          {
              v.push_back(p);
          }
      }
      return v;
} 
int main() {
	// your code goes here
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	long long int n,d,x,y;cin>>n>>d;int c=0;
	for(long long int i=0;i<n;i++)
	{
	    cin>>x>>y;
	    double sum=sqrt((x*x)+(y*y));
	    if(sum<=d)
	    c++;
	}
	cout<<c<<"\n";
	return 0;
}


Measured memory_bytes: 3704
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <array>
#include <queue>
#include <map>
#include <set>
#include <sstream>
#include <stdio.h>
#include <cstring>;

using namespace std;

#define Rep(i,a,b) for(int i = a; i < b; i++)
#define rep(i,b) Rep(i,0,b)
#define rrep(i,a) for(int i = a; i >= 0; i--)
#define allof(a) (a).begin(), (a).end()
#define pb push_back

typedef long long ll;
const int inf = 1e9 + 7;
const ll infll = 1ll << 60ll;
const ll mod = 1e9 + 7;
// 0~3までは右左下上 4~7までは斜め
constexpr int dx[] = { 1, 0, -1, 0, 1, 1, -1, -1 };
constexpr int dy[] = { 0, -1, 0, 1, 1, -1, -1, 1 };

// 最大公約数
ll gcd(ll a, ll b) {
	if (b == 0) return a;
	return gcd(b, a%b);
}

// 最小公約数
long lcm(long a, long b) {
	return a / gcd(a, b) * b;
}

int h, w;

int a[500][500];
vector<pair<int, int>> pa;

int cnt = 0;

void bfs(int i, int j) {
	if (a[i][j] % 2) {
		// 自身より右か下のマスに送る
		if (j + 1 < w) {
			a[i][j]--;
			a[i][j + 1]++;
			pa.push_back({ i+1,j+1 });
			pa.push_back({ i + 1,j+2});
			cnt++;
		}
		else if (i + 1 < h) {
			a[i][j]--;
			a[i + 1][j]++;
			pa.push_back({ i + 1,j + 1 });
			pa.push_back({ i + 2,j + 1 });
			cnt++;
		}
	}
}

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

	memset(a,0,sizeof(a));

	cin >> h >> w;

	// 横がw 縦がh
	rep(i, h) {
		rep(j, w) {
			cin >> a[i][j];
		}
	}

	rep(i, h) {
		rep(j, w) {
			bfs(i, j);
		}
	}

	cout << cnt << endl;
	rep(i, cnt) {
		cout << pa[2 * i].first << " " << pa[2 * i].second << " "
			<< pa[2 * i + 1].first << " " << pa[2 * i + 1].second << endl;
	}

	return 0;
}

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

used = [False]*N
verts = [[[], None] for i in range(N)] # to color

for i in range(N-1):
    u, v, w = map(int,input().split())
    v -= 1
    u -= 1
    verts[v][0].append((u, w))
    verts[u][0].append((v, w))

q = [(0, 0)] # 0, distance
verts[0][1] = 1 # black
used[0] = True
while q != []:
    v, c = q.pop(0)
    vert = verts[v]
    for w,d in vert[0]:
        if not used[w]:
            used[w] = True
            if (c+d) % 2 == 0:
                verts[w][1] = 1
            else:
                verts[w][1] = 0
            q.append((w, c+d))
for i in range(N):
    print(verts[i][1])


Measured memory_bytes: 48368
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.*;

public class Main {
    
	public static void main(String[] args) throws Exception {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		int N = Integer.parseInt(br.readLine());
		
		while(N != 0){
			Point point = new Point(0,0);
			for(int i=0;i<N;i++){
				String[] lines = br.readLine().split(" ");
				int a = Integer.parseInt(lines[0]);
				int b = Integer.parseInt(lines[1]);
				if(a>b){
					point.a += a+b;
				}else if(b>a){
					point.b += a+b;
				}else{
					point.a += a;
					point.b += b;
				}
			}
			System.out.println(point.a + " " + point.b);
			N = Integer.parseInt(br.readLine());
		}
	}
	static class Point{
		public int a;
		public int b;
		Point(int a,int b){
			this.a = a;
			this.b = b;
		}
	}
}

Measured memory_bytes: 36352
import java.io.IOException;
import java.util.Arrays;
import java.util.Scanner;

public class Main {

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

		new Main().run();
	}

	private void run() throws IOException {
		Scanner scanner = new Scanner(System.in);
		n = scanner.nextInt();
		k = scanner.nextInt();
		plan = new int[n + 1];
		for (int i = 0; i < k; i++)
			plan[scanner.nextInt()] = scanner.nextInt();
		dp = new int[n + 1][4][4];
		for (int[][] dpp : dp)
			for (int[] dppp : dpp)
				Arrays.fill(dppp, -1);
		System.out.println(slove(1, 0, 0));

	}

	private int slove(int day, int pre1, int pre2) {
		if (day == n + 1)
			return 1;
		if (dp[day][pre1][pre2] != -1)
			return dp[day][pre1][pre2];
		if (plan[day] != 0)
			if (pre2 == pre1 && pre1 == plan[day])
				return 0;
			else
				return slove(day + 1, plan[day], pre1) % mod;
		int ret = 0;
		for (int i = 1; i < 4; i++) {
			if (i == pre1 && pre1 == pre2)
				continue;
			ret += slove(day + 1, i, pre1) % mod;
		}
		return dp[day][pre1][pre2] = ret % mod;
	}

	int n, k;
	int[] plan;
	int[][][] dp;
	int mod = 10000;
}

Measured memory_bytes: 19708
import sys
sys.setrecursionlimit(2147483647)
INF=float("inf")
MOD=10**9+7
input=lambda :sys.stdin.readline().rstrip()
def resolve():
    n=int(input())
    A=list(map(int,input().split()))
    B=list(map(int,input().split()))
    score=0
    # pattern 1
    for i in range(n):
        k=min(A[i],B[i])
        score+=k
        A[i]-=k
        B[i]-=k
        if(B[i]>0):
            k=min(A[i+1],B[i])
            score+=k
            A[i+1]-=k
            B[i]-=k
    print(score)
resolve()

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

#define fi first
#define se second
#define pb push_back
#define all(x) begin(x), end(x)
#define sz(x) (int)(x).size()
#define FOR(i, a, b) for (int i = a; i <= (b); i++)
#define ROF(i, a, b) for (int i = a; i >= (b); i--)

using pii = pair<int, int>; using vpii = vector<pii>;
using vi = vector<int>; using vvi = vector<vi>;
using ll = long long;
using pll = pair<ll, ll>; using vpll = vector<pll>;
using vll = vector<ll>; using vvll = vector<vll>;

int main() {
    int r, c, k; cin >> r >> c >> k;
    vvll a(r + 1, vll(c + 1));
    FOR(i, 1, k) {
        int x, y, v; cin >> x >> y >> v;
        a[x][y] = v;
    }
    vector <vvll> dp(r + 1, vvll(c + 1, vll(4)));
    ll ans = 0;
    FOR(i, 1, r) FOR(j, 1, c) {
        FOR(l, 0, 3)
            dp[i][j][0] = max(dp[i][j][0], dp[i - 1][j][l]);
        dp[i][j][0] = max(dp[i][j][0], dp[i][j - 1][0]);
        FOR(l, 1, 3)
            dp[i][j][l] = dp[i][j - 1][l];
        ROF(l, 3, 1)
            dp[i][j][l] = max(dp[i][j][l], dp[i][j][l - 1] + a[i][j]);
        FOR(l, 0, 3)
            ans = max(ans, dp[i][j][l]);
    }
    cout << ans << endl;
}

Measured memory_bytes: 706588
// #pragma comment(linker, "/stack:200000000")
// #pragma GCC optimize("Ofast")
// #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx")
// #pragma warning(disable : 4996)
#include<bits/stdc++.h>
 
using namespace std;
 
using ll = long long;
using ld = long double;
using ull = unsigned long long;
 
#define int long long
#define F first
#define S second
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()
#define len(s) (int)(s).size()
// #define endl '\n'
 
 
inline void accell() {
    cin.tie(0);
    cout.tie(0);
    ios_base::sync_with_stdio(0);
}
 
template<class T> ostream& operator<< (ostream& out, const pair<int, int>&X) {
    out << X.first << ' ' << X.second << endl;
    return out;
}
 
template<class T> ostream& operator<< (ostream& out, const vector<T> &X) {
    for (const auto& it : X)
        out << it << ' ';
    return out;
}
template<class T> ostream& operator<< (ostream& out, const set<T> &X) {
    for (const auto& it : X)
        out << it << ' ';
    return out;
}
template<class T> void dbg(const T &X) {
    cerr << "DEBUG: " << ": ";
    cerr << X << endl;
}
 
const int MOD1 = 1e9 + 7;
const int N = 5e5 + 25;
const int MOD2 = 998244353;
const int inf = 1e13;
const int mx = (1 << 19) - 1;
const int mod = 1e9 + 7;

int fenv[N];

void add(int v, int x) {
	if (v < 0) return;
	for (int i = v; i < N; i |= (i + 1))
		fenv[i] += x;
}
int sum(int r) {
	int res = 0;
	for (int i = r; i >= 0; i = (i & (i + 1)) - 1)
		res += fenv[i];
	return res;
}
int get(int l, int r) {
	return sum(r) - sum(l - 1);
}


signed main() {
    accell();
    #ifdef LOCAL
        freopen("input.txt", "r", stdin);
        freopen("output.txt", "w", stdout);
    #endif
	int n, q;
	cin >> n >> q;
	vector<int>c(n);
	for (int i = 0; i < n; ++i) {
		cin >> c[i];
		--c[i];
	}
	vector<int>lst(n, -1);
	vector<int>cur(n, -1);
	for (int i = 0; i < n; ++i) {
		cur[i] = lst[c[i]];
		lst[c[i]] = i;
	}
	vector<pair<pair<int, int>, int> > v(q);
	for (int i = 0; i < q; ++i) {
		cin >> v[i].first.first >> v[i].first.second;
		v[i].first.first--, v[i].first.second--;
		v[i].second = i;
	}
	sort(all(v), [&](pair<pair<int, int>, int>x, pair<pair<int, int>, int>y) {
		return x.first.second < y.first.second;
	});
	int j = 0;
	vector<int>ans(q);
	for (int i = 0; i < n; ++i) {
		add(i, 1);
		add(cur[i], -1);
		while (j < len(v) && v[j].first.second == i) {
			ans[v[j].second] = get(v[j].first.first, v[j].first.second);
			++j;
		}
	}
	for (int i = 0; i < q; ++i) {
		cout << ans[i] << '\n';
	}
	return 0;
}


Measured memory_bytes: 35104
#include<iostream>

using namespace std;

int main(){

  int x,y;

    for( ; ; ){


    cin>> x >> y;

    if(x==0&&y==0)break;

		    if(x<y||x==y){
		      cout<<x<<" "<<y<<endl;
		    }

		    else{
		      cout<<y<<" "<<x<<endl;
		    }

    }

  return 0;
}

Measured memory_bytes: 3028
//Don't have to see. start------------------------------------------
var read = require('readline').createInterface({
  input: process.stdin, output: process.stdout
});
var obj; var inLine = [];
read.on('line', function(input){inLine.push(input);});
read.on('close', function(){
  obj = init(inLine);
  console.error('\n↑入力 ↓出力');
  Main();
});
function makeClone(obj){return (obj instanceof Set) ? new Set(Array.from(obj)) : JSON.parse(JSON.stringify(obj));}
function nextInt(){return myconv(next(),1);} function nextStrArray(){return myconv(next(),2);}
function nextIntArray(){return myconv(next(),4);} function nextCharArray(){return myconv(next(),6);}
function next(){return obj.next();} function hasNext(){return obj.hasNext();}
function init(input){  
  return {
    list : input, index : 0, max : input.length,
    hasNext : function(){return (this.index < this.max);},
    next : function(){if(this.hasNext()){return this.list[this.index++];}else{throw 'ArrayIndexOutOfBoundsException ‚There is no more input';}}
  };
}
function myout(s){console.log(s);}
function myerr(s){console.error('debug:' + require('util').inspect(s,false,null));}
//param "no" is
//unknown or outlier : return i. 1: parseInt.
//2: split space. 4: split space and parseInt.
//6: split 1 character. 7: split 1 character and parseInt.
//8: join space. 9: join nextline. 0: join no character.
function myconv(i,no){try{switch(no){case 1:return parseInt(i);case 2:return i.split(' ');case 4:return i.split(' ').map(Number);case 6:return i.split('');case 7:return i.split('').map(Number);case 8:return i.join(' ');case 9:return i.join('\n');case 0:return i.join('');default:return i;}}catch(e){return i;}}

//Don't have to see. end------------------------------------------
function Main(){
  var N = nextInt();
  var list = nextIntArray();
  var output = 0;
  for(var i = 1; i < N; i++){
    if(list[i - 1] > list[i]){
      output += Math.abs(list[i - 1] - list[i]);
      list[i] = list[i - 1];
    }
  }
  myout(output);
}

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

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

	vector<int> h(n);

	int mxh = 0;
	string ans = "Yes";

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

		if(h[i]>mxh){
			mxh = h[i];
		}

		else if(h[i]<mxh-1){
			ans = "No";
		}
	}

	cout << ans << endl;
}

Measured memory_bytes: 640
#include<bits/stdc++.h>
#define fi first
#define se second
#define mp make_pair
#define INF 1000000007
#define inf 10000000
#define mod 1000000007
#define debug x==3&&y==5&&to_x==5&&to_y==7
#define debug1 to_x==5&&to_y==7
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pi;
typedef pair<ll,ll> pl;
template <typename T> T Max(T X,T Y){return X>Y?X:Y;}
template <typename T> T Min(T X,T Y){return X<Y?X:Y;}

struct xy{
	int px,py,psum;
};
int m,n,sx,sy,ex,ey;
bool a[1005][1005],vis[1005][1005];
string s;
deque<xy> q;

bool cango(int x,int y)
{
	if(x<=0||y<=0||x>n||y>m) return false;
	if(vis[x][y]||!a[x][y]) return false;
	return true;
}

int main()
{
//	memset(f,-1,sizeof(f));
	cin>>n>>m;
	cin>>sx>>sy;
	cin>>ex>>ey;
	for(int i=1;i<=n;i++)
	{
		cin>>s;
		for(int j=0;j<m;j++)
			a[i][j+1]=s[j]=='.';
	}
	//f[sx][sy]=0;
	xy start;
	start.px=sx,start.py=sy,start.psum=0;
	q.push_front(start);
	while(!q.empty())
	{
		/*for(deque<xy>::iterator it=q.begin();it!=q.end();it++)
		{
			cout<<(*it).px<<" "<<(*it).py<<" "<<(*it).psum<<endl;
		}cout<<vis[5][7]<<endl;
		puts("-----------");*/
		xy pos=q.front();
		q.pop_front();
		int x=pos.px,y=pos.py;
		//cout<<x<<" "<<y<<" "<<pos.psum<<endl;
		if(x==ex&&y==ey)
		{
			cout<<pos.psum<<endl;
			return 0;
		}
		if(vis[x][y])
		{
			continue;
		}
		vis[x][y]=true;
		const int dx[]={-1,0,0,1},dy[]={0,-1,1,0};
		
		for(int i=0;i<4;i++)
		{
			int to_x=x+dx[i],to_y=y+dy[i];
			if(!cango(to_x,to_y)) continue;
			xy to;
			to.px=to_x,to.py=to_y,to.psum=pos.psum;
			q.push_front(to);
		}
		for(int i=-2;i<=2;i++)
			for(int j=-2;j<=2;j++)
			{
				int to_x=x+i,to_y=y+j;
				
				if(!cango(to_x,to_y)) continue; 
				xy to;
				to.px=to_x,to.py=to_y,to.psum=pos.psum+1;
				//if(debug1) cout<<to.px<<" "<<to.py<<" "<<to.psum<<endl;
				q.push_back(to);
			}
	}
	puts("-1");
	return 0;
}

Measured memory_bytes: 6404
N, A, B = map(int, input().split())
total = 0

# 各桁の和を計算する関数
def sumOfDigits(n):
    sum = 0
    while n > 0:
        sum += n % 10
        n = n // 10
    return sum

for i in range(1, N + 1, 1):
    j = sumOfDigits(i)
    if A <= j and j <= B:
        total += i

print(total)

Measured memory_bytes: 3060
n = int(input())
v = [i for i in input().split()]
v1 = {}
v2 = {}
for i in range(n//2):
    if  v[2 *i +1] in v1.keys():
        v1[v[2 * i +1]] += 1
    else:
        v1[v[2 * i + 1]] = 1

    if v[2 * i] in v2.keys():
        v2[v[2 * i]] += 1
    else:
        v2[v[2 * i]] = 1
v1 = sorted(v1.items(),key=lambda x:  x[1])
v2 = sorted(v2.items(),key=lambda x:  x[1])
v1.reverse()
v2.reverse()
v1.append((None,0))
v2.append((None,0))
#print(v1)
if v1[0][0] == v2[0][0]:
    ans = max(v1[0][1]+v2[1][1] , v1[1][1] + v2[0][1])
else:
    ans = v1[0][1] + v2[0][1]
print(n - ans)

Measured memory_bytes: 26500
#include <stdio.h>
#include <ctype.h>

static
const char  * s[ ] = { ".,!? ", "abc", "def", "ghi",
                               "jkl", "mno", "pqrs",
                               "tuv", "wxyz" };

/** Application main entry point. */
int main (
  int     argc,
  char  * argv[ ]
  )
{
  int n;

  scanf ( "%d", &n );
  while ( n-- )
  {
    const char  * p   = NULL;
    int           ch  = '\0';

    while ( !isdigit ( ch ) ) ch = getchar ( );

    for ( ; isdigit ( ch ); ch = getchar ( ) )
    {
      if ( ch == '0' )
      {
        if ( p != NULL )  putchar ( *p );
        p = NULL;
      }
      else
      {
        if ( p == NULL )  p = "";
        else              ++p;

        if ( *p == '\0' ) p = s[ ch - '1' ];
      }
    }
    puts ( "" );
  }

  return ( 0 );
}

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

def main():
    N, K = [int(x) for x in input().split()]
    h = [int(x) for x in input().split()]

    ans = 0
    for x in h:
        if x >= K:
            ans += 1

    print(ans)



if __name__ == '__main__':
    main()



Measured memory_bytes: 11880
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0; i<(n) ;i++)
#define pb push_back
#define all(v) (v).begin(),(v).end()
#define fi first
#define se second
#define sz(x) ((int)(x).size())
using ll=long long;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
#define MOD  1000000007
const ll INF=1e18;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b){ a = b; return 1; } return 0; }



int main(int argc, char const *argv[]) {
  int k,a,b;
  cin >> k >> a >> b;
  bool f=false;
  for(int i=a; i<=b; i++) if(i%k==0)f=true;
  if(f) cout << "OK" << endl;
  else cout << "NG" << endl;
  return 0;
}


Measured memory_bytes: 3608
N,K = (int(T) for T in input().split())
Next = [int(T)-1 for T in input().split()]
GetP = [int(T) for T in input().split()]
DispP = [0]*N
for TN in range(0,N):
    Now   = Next[TN]
    Point = GetP[Now]
    MAXP  = Point
    RoopC = 1
    RoopFlag = False
    for TK in range(1,K):
        Now = Next[Now]
        Point += GetP[Now]
        RoopC += 1
        if Now==TN and Point>=0:
            RoopFlag = True
            break
        elif Now==TN and Point<0:
            RoopFlag = False
            break
        if MAXP<Point:
            MAXP = Point
            MInd = TK
    if RoopFlag:
        Omit = K-RoopC*(K//RoopC)
        PointO = 0
        MAXO = 0
        for TO in range(0,Omit):
            Now = Next[Now]
            PointO += GetP[Now]
            if MAXO<PointO:
                MAXO = PointO
        if Point*(K//RoopC)+MAXO>=Point*((K//RoopC)-1)+MAXP:
            DispP[TN] = Point*(K//RoopC)+MAXO
        else:
            DispP[TN] = Point*((K//RoopC)-1)+MAXP
    else:
        DispP[TN] = MAXP
print(max(DispP))

Measured memory_bytes: 69040
import java.util.*;

public class Main {
    private static int MAX_WEIGHT = 100000;

    private static long solve(int N, int W, int[] w, int[] v) {
        long[] maxValue = new long[MAX_WEIGHT + 1];
        long[] candidateMaxValue = new long[MAX_WEIGHT + 1];

        for (int k = 0; k < N; k++) {
            Arrays.fill(candidateMaxValue, 0);
            candidateMaxValue[w[k]] = v[k];
            for (int weight = 1; weight <= MAX_WEIGHT; weight++) {
                if (maxValue[weight] == 0) continue;

                if (weight + w[k] <= MAX_WEIGHT) {
                    candidateMaxValue[weight + w[k]] = maxValue[weight] + v[k];
                }
            }
            for (int weight = 1; weight <= MAX_WEIGHT; weight++) {
                maxValue[weight] = Math.max(maxValue[weight], candidateMaxValue[weight]);
            }
        }

        long result = 0;
        for (int weight = 1; weight <= W; weight++) {
            result = Math.max(result, maxValue[weight]);
        }

        return result;
    }

    public static void main(String[] args) {
        int N, W;
        int[] w;
        int[] v;
        try (Scanner scanner = new Scanner(System.in)) {
            N = scanner.nextInt();
            W = scanner.nextInt();

            w = new int[N];
            v = new int[N];
            for (int i = 0; i < N; i++) {
                w[i] = scanner.nextInt();
                v[i] = scanner.nextInt();
            }
        }

        long result = solve(N, W, w, v);
        System.out.println(result);

        //test();
    }

    private static void test() {
        testCase(3, 8, new int[] {3, 4, 5}, new int[] {30, 50, 60}, 90);
        testCase(5, 5, new int[] { 1, 1, 1, 1, 1}, new int[] {1000000000,1000000000,1000000000,1000000000,1000000000}, 5000000000L);
        testCase(6, 15, new int[] {6,5,6,6,3,7}, new int[] {5,6,4,6,5,2}, 17);

        timingTest(100);

        System.out.println("DONE");
    }

    private static void timingTest(int size) {
        int[] w = new int[size];
        int[] v = new int[size];
        for (int i=0; i < size; i++) {
            w[i] = Math.min(i*i, MAX_WEIGHT);
            v[i] = i;
        }

        long start = System.currentTimeMillis();
        solve(size, Math.min(100*size*size, MAX_WEIGHT), w, v);
        long elapsed = System.currentTimeMillis() - start;
        System.out.println("timing size=" + size + " elapsed=" + elapsed);
    }

    private static void testCase(int N, int W, int[] w, int[] v, long expected) {
        long result = solve(N, W, w, v);
        if (result != expected) {
            System.out.println("FAILED N=" + N + " W=" + W + " w=" + Arrays.toString(w) + " v=" + Arrays.toString(v)
                    + ", was " + result + " expected " + expected);
        }
    }
}


Measured memory_bytes: 26580
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using vi = vector<int>;
using vvi = vector<vector<int>>;
using vl = vector<ll>;
using vvl = vector<vector<ll>>;
#define all(x) x.begin(),x.end()
#define rep(i,j,n) for (long long i = j; i < (long long)(n); i++)
#define _GLIBCXX_DEBUG
#define MOD 1000000007
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
//name[i][j]-> vvl name(i,vl(j))
//map<int,int>mp
//余りを切り上げる =>  (a + b - 1) / b 

using pl = pair<ll,ll>;
signed main(){
	ll n; cin>>n; 
	vector<pl> v(n+1);
	vl t(n+1);
	v[0]=make_pair(0,0);
	rep(i,1,n+1){
		cin>>t[i];
		cin>>v[i].first>>v[i].second;
	}
	rep(i,1,n+1){
		ll x=abs(v[i].first-v[i-1].first);
		ll y=abs(v[i].second-v[i-1].second);
		//cout<<"x:"<<x<<" y:"<<y<<endl;
		if(t[i]-t[i-1]<x+y || (t[i]-t[i-1])%(x+y)==1){
			//cout<<i<<endl;
			cout<<"No"<<endl;
			return 0;
		}
	}
	cout<<"Yes"<<endl;
	
	
	return 0;
}

Measured memory_bytes: 5504
#include<bits/stdc++.h>
using namespace std;
#define pb push_back
#define ll long long int
int main()
{  
	double n,k;
	cin>>n>>k;
	double ans = 0;
	for(int i=1;i<=n;i++)
		if(k/i>=1)
			ans = ans + pow(0.5,ceil(log(k/i)/log(2)));
		else
			ans++;
	ans/=n;
	printf("%.12f",ans);
}

Measured memory_bytes: 512