akhauriyash/Code-Regression huggingface dataset:
import queue

N,M,K=map(int,input().split())
friend=[[] for i in range(N)]
block=[[] for i in range(N)]
color=[-1]*N
c=0
for i in range(M):
    a,b=map(int,input().split())
    friend[a-1].append(b-1)
    friend[b-1].append(a-1)
for i in range(K):
    a,b=map(int,input().split())
    block[a-1].append(b-1)
    block[b-1].append(a-1)

q=queue.Queue()
count=[0]*N

for i in range(N):
    if color[i]==-1:
        q.put(i)
        color[i]=c
        count[c]+=1
        while not q.empty():
            s=q.get()
            for t in friend[s]:
                if color[t]==-1:
                    color[t]=c
                    count[c]+=1
                    q.put(t)
        c+=1

for i in range(N):
    block_in_color=0
    for t in block[i]:
        if color[i]==color[t]:
            block_in_color+=1
    print(count[color[i]]-len(friend[i])-block_in_color-1)


Measured memory_bytes: 106344
#include <iostream>
#include <iomanip>
#include <complex>
#include <vector>
#include <utility>
#include <algorithm>
#include <cmath>
using namespace std;

const double EPS = 1e-10;
const double INF = 1e12;
#define LE(n,m) ((n) < (m) + EPS)
#define GE(n,m) ((n) + EPS > (m))
#define EQ(n,m) (abs((n)-(m)) < EPS)
#define X real()
#define Y imag()

typedef complex<double> P;
typedef vector<P> VP;
struct L : VP{
    L(const P& a, const P& b){ resize(2); at(0)=a; at(1)=b; }
    L(){ resize(2); }
};

double dot(P a, P b){
    return (conj(a)*b).X;
}
double cross(P a, P b){
    return (conj(a)*b).Y;
}

//ccw
int ccw(P a, P b, P c){
    b -= a;
    c -= a;
    if(cross(b,c) > EPS) return +1; //counter clockwise
    if(cross(b,c) <-EPS) return -1; //clockwise
    if(dot(b,c) < EPS) return +2; //c-a-b
    if(norm(b) < norm(c)) return -2; //a-b-c
    return 0; //a-c-b
}

bool intersectSS(const L& s, const L& t){
    return ( ccw(s[0],s[1],t[0]) *ccw(s[0],s[1],t[1]) <= 0 ) &&
        ( ccw(t[0],t[1],s[0]) *ccw(t[0],t[1],s[1]) <= 0 );
}
bool intersectSP(const L& s, const P& p){
    return abs(s[0]-p) +abs(s[1]-p) -abs(s[1]-s[0]) < EPS;
}


P projection(const L& l, const P& p) {
  double t = dot(p-l[0], l[0]-l[1]) / norm(l[0]-l[1]);
  return l[0] + t*(l[0]-l[1]);
}

double distanceSP(const L &s, const P &p) {
  const P r = projection(s, p);
  if (intersectSP(s, r)) return abs(r - p);
  return min(abs(s[0]-p), abs(s[1]-p));
}
double distanceSS(const L &s, const L &t) {
  if (intersectSS(s, t)) return 0;
  return min(min(distanceSP(s, t[0]), distanceSP(s, t[1])),
             min(distanceSP(t, s[0]), distanceSP(t, s[1])));
}

int main(){
    while(1){
        int n,m,l;
        cin >> n >> m >> l;
        if(n==0) break;
        
        vector<vector<L> > star(n, vector<L>(5));
        for(int i=0; i<n; i++){
            double x,y,a,r;
            cin >> x >> y >> a >> r;
            P top(0, r);
            double rad = a*M_PI/180.0;
            top *= P(cos(rad), sin(rad));

            P v[5];
            v[0]=top;
            for(int j=1; j<5; j++){
                v[j] = v[j-1]*P(cos(0.4*M_PI), sin(0.4*M_PI));
            }
            for(int j=0; j<5; j++){
                v[j] += P(x,y);
            }
            for(int j=0; j<5; j++){
                star[i][j] = L(v[j], v[(j+2)%5]);
            }
        }

        vector<vector<double> > adj(n, vector<double>(n, INF));
        for(int i=0; i<n; i++){
            for(int j=i; j<n; j++){
                double dist=INF;
                for(int k=0; k<5; k++){
                    for(int l=0; l<5; l++){
                        dist = min(dist, distanceSS(star[i][k], star[j][l]));
                    }
                }
                adj[i][j] = adj[j][i] = dist;
            }
        }

        for(int k=0; k<n; k++){
            for(int i=0; i<n; i++){
                for(int j=0; j<n; j++){
                    adj[i][j] = min(adj[i][j], adj[i][k]+adj[k][j]);
                }
            }
        }

        cout << fixed;
        cout << setprecision(10);
        cout << adj[m-1][l-1] << endl;
    }
    return 0;
}

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

int main(){
  int n,k,ans=1,hoge,foo;
  cin >> n;
  cin >> k;
  for(int i=0;i<n;i++){
    hoge=ans*2;
    foo=ans+k;
    if(hoge>foo){
      ans=foo;
    }else{
      ans=hoge;
    }
  }
  cout << ans << '\n';
  return 0;
}


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

using namespace std;

char s[2000020];
char t[500005];

int b[2000020];
int matchIndx[2000020];

vector<int> AdjList[2000020];
int dist[2000020];

int main(){
	scanf(" %s %s", s, t);
	
	int n = strlen(s);
	int n2 = strlen(s);
	
	for(int i = 0; i < n; i ++){
		for(int j = 1; j < 2000016/n; j ++){
			s[j*n+i] = s[i];
		}
	}
	
	n = strlen(s);
	int m = strlen(t);
	//printf("%d %d\n", n, m);
	
	// KMP from CP3
	int i = 0, j = -1; b[0] = -1;
	while(i < m){
		while(j >= 0 && t[i] != t[j]){j=b[j];}
		i++; j++;
		b[i] = j;
	}
	
	int numMatch = 0;
	i = 0, j = 0;
	while(i < n){
		while(j >= 0 && s[i] != t[j]){j = b[j];}
		i ++; j ++;
		if(j == m){
			numMatch ++;
			if(i < 0){
				printf("P is found at index %d to %d in T\n", i-j, i);
			}
			AdjList[i-j].push_back(i);
			j = b[j];
		}
	}
	
	memset(dist, -1, sizeof(dist));
	for(int i = 0; i < n; i ++){
		if(dist[i] == -1){
			queue<int> q;
			q.push(i);
			dist[i] = 0;
			while(!q.empty()){
				int u = q.front(); q.pop();
				for(int v: AdjList[u]){
					if(dist[v] == -1){
						q.push(v);
						if(v-i >= 3*n2){
							printf("-1");
							return 0;
						} 
						dist[v] = dist[u] + 1;
					}
				}
			}
		}
	}
	
	int ans = 0;
	for(int i = 0; i < n; i ++){
		ans = max(ans, dist[i]);
	}
	printf("%d", ans);
	return 0;
}


Measured memory_bytes: 123264
N = int(input())
a = [0]
for _ in range(N):
  a.append(int(input()))

Q = [0 for i in range(N + 1)]
for i in range(N + 1):
    Q[a[i]] = i
ans = 1
num = 1

for idx in range(2, len(Q)):
    if Q[idx - 1] < Q[idx]:
        num += 1
    else:
        ans, num = max(num, ans), 1

print(N - max(num, ans))


Measured memory_bytes: 18964
#include<bits/stdc++.h>
using namespace std;
int main()
{
 int n;
 cin>>n;
 int i=1;
 int a[10][10];
 memset(a,0,sizeof(a));
 while(i<=n)
 {
 	int e=i%10;
 	int l=log10(i);
 	int s=i/pow(10,l);
 //	cout<<s<<" "<<e<<endl;
 	a[s][e]++;
 	i++;
 }
 int j;
 int ans=0;
 for(i=0;i<10;i++)
 {
 	for(j=0;j<10;j++)
    {
    //	cout<<a[i][j]<<" ";
	  ans+=(a[i][j]*(a[j][i]));
    }
    //cout<<endl;
 }
 cout<<ans<<endl;
 return 0;
}



Measured memory_bytes: 640
H, W = list(map(int, input().split()))
A = [list(map(int, input().split())) for _ in range(H)]

tmp = 0

ans = []

for j in range(H):
    if j % 2 == 0:
        for i in range(W):
            if j == H-1 and i == W-1:
                break
            if A[j][i] % 2 != 0:
                A[j][i] -= 1
                if i == W-1:
                    A[j+1][i] += 1
                    ans.append([j, i, j+1, i])
                else:
                    A[j][i+1] += 1
                    ans.append([j, i, j, i+1])

    else:
        for i in range(W-1, -1, -1):
            if j == H-1 and i == 0:
                break
            if A[j][i] % 2 != 0:
                A[j][i] -= 1
                if i == 0:
                    A[j+1][i] += 1
                    ans.append([j, i, j+1, i])
                else:
                    A[j][i-1] += 1
                    ans.append([j, i, j, i-1])


print(len(ans))
for a in ans:
    a[0] += 1
    a[1] += 1
    a[2] += 1
    a[3] += 1
    print(*a)


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

using namespace std;

typedef pair<int, int> P;
typedef long long ll;
#define rep(i, n) for(int i=0;i<n;i++)
#define rep2(i, m, n) for(int i=m;i<n;i++)
#define rrep(i, n, m) for(int i=n;i>=m;i--)
using Graph = vector<vector<int>>;
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
const ll MOD = 1000000007;
#ifdef __DEBUG

#include "cpp-pyprint/pyprint.h"

#endif

void Main() {
    int N;
    cin >> N;
    vector<int> A;
    for (int i = 0; i < N; ++i) {
        int a;
        cin >> a;
        A.push_back(a);
    }
    vector<int> B;
    copy(A.begin(), A.end(), back_inserter(B));
    sort(B.begin(), B.end());

    for (int j = 0; j < N; ++j) {
        if (A[j] != B[N-1]) {
            cout << B[N-1] << endl;
        } else {
            cout << B[N-2] << endl;
        }
    }

}

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


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

namespace ABC066A
{
    class Program
    {
        static void Main(string[] args)
        {
            int a, b, c, d;

            var word = Console.ReadLine().Split(' ');

            a = int.Parse(word[0]);
            b = int.Parse(word[1]);
            c = int.Parse(word[2]);

            d = a + b;

            if (d > a+c) d = a+c;
            if (d > b+c) d = b+c;

            Console.WriteLine(d);

            Console.ReadKey();




        }
    }
}


Measured memory_bytes: 11092
#include <stdio.h>
#include <iostream>
#define N 100

using namespace std;
struct Card {
  char suit, value;
};

void BubbleSort(struct Card arr[],int n){
  int i,j,mini;
  struct Card tmp;

  for(i=0;i<n-1;i++){
    for(j=n-1;j>=i+1;j--){
      if(arr[j].value < arr[j-1].value){
        tmp = arr[j];
        arr[j] = arr[j-1];
        arr[j-1] = tmp;
      }
    }
  }
}


void SelectionSort(struct Card arr[],int n){
    int i,j,minj;
    struct Card tmp;

    for(i=0;i<n;i++){
      minj = i;
    for(j=i;j<n;j++){
      if(arr[j].value < arr[minj].value){
        minj = j;
      }
    }
      tmp = arr[i];
      arr[i] = arr[minj];
      arr[minj] = tmp;
  }
}

void print(struct Card arr[], int n){
  int i;
  for(i=0;i<n;i++){
    if(i > 0){
      printf(" ");
    }
    cout << arr[i].suit << arr[i].value;
  }
  cout << endl;
}


int isstable(struct Card C1[], struct Card C2[],int n){
  int i;
  for(i=0;i<n;i++){
    if(C1[i].suit != C2[i].suit) return 0;
  }
  return 1;
}

int main(void){

  int i,j,n,tmp;
  struct Card arr1[N];
  struct Card arr2[N];

  scanf("%d",&n);

  for(i=0;i<n;i++){
    cin >> arr1[i].suit >> arr1[i].value;
  }

  for(i=0;i<n;i++){
    arr2[i] = arr1[i];
  }

  BubbleSort(arr1,n);
  SelectionSort(arr2,n);

  print(arr1,n);
  printf("Stable\n");

  print(arr2,n);

  if(isstable(arr1,arr2,n)){
    printf("Stable\n");
  }else{
    printf("Not stable\n");
  }

return 0;

}








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

class dice
{
public:
    int F[6];
    dice();
    void roll_a();
    void roll_b();
    bool check(const dice& d);
};

dice::dice()
{
    for(int i = 0; i < 6; i++) cin >> F[i];
}

void dice::roll_a()
{
    static int i, j;
    i = F[0]; F[0] = F[2]; F[2] = F[1]; F[1] = i;
    j = F[3]; F[3] = F[4]; F[4] = F[5]; F[5] = j;
}

void dice::roll_b()
{
    static int k;
    k = F[0]; F[0] = F[5]; F[5] = k;
    k = F[1]; F[1] = F[3]; F[3] = k;
    k = F[2]; F[2] = F[4]; F[4] = k;
}

bool dice::check(const dice& d)
{
	static int l, m;
    if((d.F[0] != F[0]) || (d.F[5] != F[5])) return false;

    for(l = 1; l <= 4; l++){
        for(m = 1; m <= 4; m++){
            if(d.F[m] != F[(l * m) % 5]) break;
        }
        if(m == 5) return true;
    }
    return false;
}

int main()
{
    dice d1 = dice();
    dice d2 = dice();
    bool eq = false;

    eq = d1.check(d2);
    if(!eq){ d1.roll_a(); eq = d1.check(d2); }
    if(!eq){ d1.roll_a(); eq = d1.check(d2); }

    if(!eq) d1.roll_b();

    eq = d1.check(d2);
    if(!eq){ d1.roll_a(); eq = d1.check(d2); }
    if(!eq){ d1.roll_a(); eq = d1.check(d2); }

    if(eq){
        cout << "Yes" << endl;
    }else{
        cout << "No" << endl;
    }

    return 0;
}

Measured memory_bytes: 1160
//vec[i]の範囲外エラー表示
#define _GLIBCXX_DEBUG
//includeとusing
#include <bits/stdc++.h>
using namespace std;
//型名省略
template <class T>
using V = vector<T>;
template <class T>
using VV = V<V<T>>;
using ll = long long;
using st = string;
using vl = vector<long long>;
using vvl = vector<vector<long long>>;
using vc = vector<char>;
using vvc = vector<vector<char>>;
using vs = vector<string>;
using vb = vector<bool>;
using vvb = vector<vector<bool>>;
using pll = pair<ll, ll>;
using pcc = pair<char, char>;
//定数
const ll INF = 1e9;
const ll MOD = 1e9+7;
const vl dx = {1,0,-1,0,1,0,-1,0};
const vl dy = {0,1,0,-1,0,1,0,-1};
//マクロ
#define rep(i,n) for(ll i = 0; i < (ll) n; i++)
#define rrep(i,n) for(ll i = (ll) n - 1; i >= 0;i--)
#define REP(i,x,n) for(ll i = (ll) x; i < (ll) n; i++)
#define RREP(i,x,n) for(ll i = (ll) n - 1; i >= x; i--)
#define each(i,A) for(ll i: (vl) A)
#define all(A) A.begin(), A.end()
#define Size(A) ll(A.size())
//入力
template<typename T> T input() {T x; cin >> x; return x;}
//正誤判定
void Yes(bool ans){cout << (ans? "Yes" : "No") << endl;}
void YES(bool ans){cout << (ans? "YES" : "NO") << endl;}
//余り切り上げ
ll ceil(ll a,ll b) {return (a + b - 1) / b;}
//最大値・最小値
template <typename T> bool chmax(T &a, const T& b) {if(a < b) {a = b; return true;} return false;}
template <typename T> bool chmin(T &a, const T& b) {if(a > b) {a = b; return true;} return false;}
//最大公約数
ll gcd(ll a,ll b){if(a<b)swap(a,b); if(a%b==0)return b; return gcd(b,a%b);}
//最小公倍数
ll lcm(ll a,ll b){return a/gcd(a,b)*b;}
//n乗の余り
ll modpow(ll x,ll n,ll mod){ll res=1;for(ll i=0;i<n;i++){res=res*x%mod;}return res;}
ll MODpow(ll x,ll n){ll res=1;for(ll i=0;i<n;i++){res=res*x%MOD;}return res;}


/*--------------------------------------------------------------------------*/

//main関数
int main() {
    ll h,n; cin >> h >> n;
    ll cnt = 0;
    rep(i,n){
        ll a; cin >> a;
        cnt += a;
    }
    Yes(cnt >= h);
}



Measured memory_bytes: 3632
import java.util.*;

public class Main {
    static int n, k;
    static int[] a;
    static int modP = 1000000007;
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        String s = in.next();
        k = in.nextInt();

        Set<String> set = new HashSet<>();
        Queue<String> pq = new PriorityQueue<>();
        int len = s.length();
        for(int i = 0; i < len; i++) {
            int lim = i+k+1 < len+1 ? i+k+1 : len+1;
            for(int j = i+1; j < lim; j++) {
                String sub = s.substring(i, j);
                if(!set.contains(sub)) {
                    pq.add(sub);
                    set.add(sub);
                }
            }
        }

        for(int i = 0; i < k-1; i++) {
            pq.poll();
        }

        print(pq.peek());
    }

    static void print(String s) {
        System.out.println(s);
    }
    static void print(int i) {
        System.out.println(i);
    }
}

class P {
    int x, y;
    P(int x, int y) {
        this.x = x;
        this.y = y;
    }
}

class E {
    int l, r, d;
    E(int l, int r, int d) {
        this.l = l;
        this.r = r;
        this.d = d;
    }
}

Measured memory_bytes: 24276
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int A, B, N, sum;
  cin >> A >> B;
  sum=0;

  for(int i=A;i<=B;i++){
    N=i;
    int x1, x2, x3,x4,x5;
    x1=N%10;
    if(x1>0){
      N/=10; x2=N%10;
      N/=10; x3=N%10;
      N/=10; x4=N%10;
      N/=10; x5=N%10;
      if(x1==x5)  if(x2==x4) sum++;
    }
  }

  cout << sum << endl;

}

Measured memory_bytes: 256
import java.util.*;
public class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    String s = sc.next();
    int a = Integer.parseInt(s.substring(0,4));
    int b = Integer.parseInt(s.substring(5,7));
    int c = Integer.parseInt(s.substring(8,10));
    if(a < 2019){
      System.out.println("Heisei");
    }else if(a > 2019){
      System.out.println("TBD");
    }else{
      if(b < 4){
        System.out.println("Heisei");
      }else if(b > 4){
        System.out.println("TBD");
      }else{
        if(c <= 30){
          System.out.println("Heisei");
        }else{
          System.out.println("TBD");
        }
      }
    }
  }
}


Measured memory_bytes: 20820
import sys,math,collections,itertools
input = sys.stdin.readline
m=998244353

N=int(input())
D=list(map(int,input().split()))
Dc = collections.Counter(D)
count=1
if D[0] !=0 or Dc[0]>1:
    print(0)
else:
    for i in range(1,max(Dc.keys())+1):
        count *=pow(Dc[i-1],Dc[i],m)
    print(count%m)
    


Measured memory_bytes: 24452
#include<bits/stdc++.h>
using namespace std;
main(){
  int a[5];
  int r,p,s;
  while(1){
    r=0;
    p=0;
    s=0;
    for(int i=0;i<5;i++){
      cin>>a[i];
      switch(a[i]){
      case 0:
	return 0;
      case 1:
	r=1;
	break;
      case 2:
	s=1;
	break;
      case 3:
	p=1;
	break;
      }
    }
    for(int i=0;i<5;i++){
      if((r==1&&p==1&&s==1)||(r==1&&p==0&&s==0)||(r==0&&p==1&&s==0)||(r==0&&p==0&&s==1)){
	printf("3\n");
      }
      else{
	switch(a[i]){
	case 1:
	  if(s==1){
	    printf("1\n");
	  }
	  else{
	    printf("2\n");
	  }
	  break;
	case 2:
	  if(p==1){
	    printf("1\n");
	  }
	  else{
	    printf("2\n");
	  }
	  break;
	case 3:
	  if(r==1){
	    printf("1\n");
	  }
	  else{
	    printf("2\n");
	  }
	  break;
	}
      }
    }
  }
}

Measured memory_bytes: 1116
#include<bits/stdc++.h>
using namespace std;
struct rest
{
	string s;
	int num;
};
bool cmp(rest a,rest b)
{
	if(a.s!=b.s)
	    return a.s<b.s;
	else
	    return a.num>b.num;
}
int main()
{
	int n;
	cin>>n;
	rest resta[n+1];
	rest restb[n+1];
	for(int i=1;i<=n;i++)
	{
		cin>>resta[i].s>>resta[i].num;
	}
	for(int i=1;i<=n;i++)
	{
	    restb[i].s=resta[i].s;
		restb[i].num=resta[i].num;	
	}
	sort(resta+1,resta+n+1,cmp);
	int ans[n+1];
	for(int i=1;i<=n;i++)
	{
		for(int j=1;j<=n;j++)
		{
			if(resta[i].s==restb[j].s && resta[i].num==restb[j].num)
			{
				ans[i]=j;
				continue;
			}
		}
	}
	for(int i=1;i<=n;i++)
	{
		cout<<ans[i]<<endl;
	}
	return 0;
}

Measured memory_bytes: 256
import sys
from heapq import heappop, heappush, heapify

sys.setrecursionlimit(10 ** 7)

read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

N, M = map(int, input().split())
A = list(map(int, input().split()))
A = [-a for a in A]
heapify(A)

for _ in range(M):
    a = heappop(A)
    if a == 0:
        break
    a = -(-a // 2)
    heappush(A, a)

ans = -sum(A)
print(ans)


Measured memory_bytes: 14180
#include <stdio.h>
int main(){
  int a,b,n,i,j,sum,count;
  char re;

  while(1){
    count=0;
    scanf("%d",&n);
    if(n==0)break;
    if(n==1)count++;
    if(n>10)n=10;
    sum=0;
    sum+=n;
    while(1){
      scanf("%c",&re);
      if(re!=' ')break;
      scanf("%d",&n);
      if(n==1)count++;
      if(n>10)n=10;
      sum+=n;
    }
    for(i=0;i<count;i++){
      if(count>0&&sum+10<=21){
	count--;
	sum+=10;
      }
    }
    if(sum>21)printf("0\n");
    else printf("%d\n",sum);
    
    

    
    
    
    
    
  }
  
  return 0;
}

Measured memory_bytes: 612
/**akshaykumar99**/
 
#include<bits/stdc++.h>
using namespace std;
 
#define f(i,x,n) for(i=x;i<n;i++)
#define fr(i,x,n) for(i=x;i>n;i--)
#define pu push_back           
#define pp pop_back
#define F first
#define S second
#define all(v) v.begin(),v.end()
#define rall(v) v.rbegin(),v.rend()
#define SP(x) fixed<<setprecision(x)
#define IOS() ios::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
 
const long long MOD=1e9+7;
const long double PI = acos(-1);
const long long INF=INT_MAX;
const long long LINF=LLONG_MAX;
const long long N=1e5+1;
 
typedef long long ll;
typedef long double ld;

int main()
{
    IOS();
    int h,w,k,i,j,q;
    cin>>h>>w>>k;
    char c[h+2][w+2];
    int rr[h+1]={0};
    f(i,1,h+1)
        f(j,1,w+1)
        {
            cin>>c[i][j];
            if(c[i][j]=='#')
                rr[i]=1;
        }
    int res[h+2][w+2]={0};
    int kk=1,r=0,f=0;
    if(rr[1])
        f(j,1,w+1)
        {
            if(c[1][j]=='#')
            {
                if(f)
                    kk++;
                f=1;
            }
            res[1][j]=kk;
        }
    f(i,2,h+1)
    {
        r=0;
        if(!rr[i])
            continue;
        if(f)
            kk++;
        f(j,1,w+1)
        {
            if(rr[i])
            {
                if(c[i][j]=='#')
                {
                    if(r)
                        kk++;
                    r=1;
                    f=r;
                }
                res[i][j]=kk;
            }
            else
            {
                res[i][j]=res[i-1][j];
            }
        }
    }
    int p=1;
    f(i,1,h+1)
    {
        if(rr[i])
        {
            f(j,p,i)
            {
                if(rr[j]==0)
                {
                    f(q,1,w+1)
                        res[j][q]=res[i][q];
                }
            }
            j=i+1;
            while(j<h+1)
            {
                if(rr[j]==0)
                {
                    f(q,1,w+1)
                        res[j][q]=res[i][q];
                }
                else
                    break;
                j++;
            }
            p=j+1;
        }
    }
    f(i,1,h+1)
    {
        f(j,1,w+1)
            cout<<res[i][j]<<' ';
        cout<<"\n";
    }
    return 0;
}

Measured memory_bytes: 1280
N = gets.to_i
min = 100
a=gets.split(" ").map!{|i| i.to_i}

N.times do |i|
  sum = 0
  while a[i] % 2 == 0
    a[i] = a[i] / 2
    sum = sum + 1
  end
  if min > sum 
    min = sum
  end
end

puts min

Measured memory_bytes: 1788
#include <bits/stdc++.h>
#define ALL(obj) begin(obj), end(obj)
#define debug(x) cerr << #x << ": " << x << '\n'
using namespace std;
template <class T>
vector<T> make_vec(size_t a) {
    return vector<T>(a);
}
template <class T, class... Ts>
auto make_vec(size_t a, Ts... ts) {
    return vector<decltype(make_vec<T>(ts...))>(a, make_vec<T>(ts...));
}
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;
}

using ll = long long;
using ull = unsigned long long;
const ll INF = 1e18;
// const int MOD = 1e9 + 7;

int main() {
    int N;
    cin >> N;
    vector<int> a(N);
    for (int i = 0; i < N; i++) {
        cin >> a[i];
    }

    ll ans = INF;
    ll sum = 0;
    ll tmp = 0;
    for (int i = 0; i < N; i++) {
        sum += a[i];
        if (i % 2 == 0) {
            ll add = max(1LL - sum, 0LL);
            sum += add;
            tmp += add;
        } else {
            ll sub = min(-1LL - sum, 0LL);
            sum += sub;
            tmp -= sub;
        }
    }
    chmin(ans, tmp);

    sum = 0;
    tmp = 0;
    for (int i = 0; i < N; i++) {
        sum += a[i];
        if (i % 2 == 1) {
            ll add = max(1LL - sum, 0LL);
            sum += add;
            tmp += add;
        } else {
            ll sub = min(-1LL - sum, 0LL);
            sum += sub;
            tmp -= sub;
        }
    }
    chmin(ans, tmp);

    cout << ans << endl;
}


Measured memory_bytes: 3760
#include <bits/stdc++.h>
using namespace std;
int main()
{
    int N, A, B; cin >> N >> A >> B;
    int a, b, c; a = b = c = 0;
    for (int i = 0; i < N; i++) {
        int p; cin >> p;
        if (p <= A) a++;
        if (A + 1 <= p && p <= B) b++;
        if (B + 1 <= p) c++;
    }
    cout << min({a, b, c}) << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using P = pair<int, int>;
using PLL = pair<ll, ll>;
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define repn(i,n) for(int i = 0; i <= (int)(n); i++)
#define srep(i,l,n) for(int i = l; i < (int)(n); i++)
#define srepn(i,l,n) for(int i = l; i <= (int)(n); i++)
#define drep(i,n) for(int i = (int)(n-1); i >= 0; i--)
#define drepn(i,n) for(int i = (int)(n); i >= 0; i--)
#define size(s) (int)s.size()
#define debug(var)  do{std::cout << #var << " : ";view(var);}while(0)
template<typename T> void view(T e){std::cout << e << std::endl;}
template<typename T> void view(const std::vector<T>& v){for(const auto& e : v){ std::cout << e << " "; } std::cout << std::endl;}
template<typename T> void view(const std::vector<std::vector<T> >& vv){ for(const auto& v : vv){ view(v); } }
template<typename T> inline istream& operator>>(istream &i, vector<T> &v) {rep(j, size(v)) i >> v[j]; return 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> T gcd(T a, T b) {if(b==0)return a; else return gcd(b,a%b);}
template<class T> T lcm(T a, T b) {return a/gcd(a,b)*b;}
template<class T = int> using V = vector<T>;
template<class T = int> using VV = vector<V<T>>;
bool isIn(int i, int j, int h, int w) {return i >= 0 && i < h && j >= 0 && j < w;}
void Yes(){cout << "Yes" << endl;}
void No(){cout << "No" << endl;}
void YES(){cout << "YES" << endl;}
void NO(){cout << "NO" << endl;}
void err() {cout << -1 << endl;}
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define pb push_back
#define ep emplace_back

const int MOD = 1000000007;
const int INF = 1e9;

#define PI acos(-1);
int dx[4] = {1,-1,0,0};
int dy[4] = {0,0,1,-1};
int ddx[8] = {1,1,1,-1,-1,-1,0,0};
int ddy[8] = {0,1,-1,0,1,-1,1,-1};


int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n;
    cin >> n;
    int mx = 0, ans = 0;
    rep(i, n) {
        int a;
        cin >> a;
        if(mx <= a) ans++;
        chmax(mx, a);
    }
    printf("%d\n", ans);
}

Measured memory_bytes: 3696
# 1.　s1,s2,s3を入力する
s1, s2, s3 = map(str,input().split())

# 2.　s1,s2,s3の先頭文字を取り出して、一つのリストに格納する
s_list = [s1[0], s2[0], s3[0]]

# 3.　2を結合し、大文字にする
s = "".join(s_list)
ss = s.upper()

# 4.　3を大文字にする
print(ss)


Measured memory_bytes: 8984
#include <bits/stdc++.h>
#include <iostream>
#include <vector>
#include <tuple>
using namespace std;
#define reps(i,s,n) for(int i = s; i < n; i++)
#define rep(i,n) reps(i,0,n)
#define fi first
#define se second
typedef long long ll;

int N,M,H,W,K,A,B;
string S;
string alpha = "abcdefghijklmnopqrstuvwxyz";
string ALPHA = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";

int main() {
    cin>>N>>K;
    vector<int> a(N,0);
    vector<bool> dp(K+1,false);//1-indexed,fiが勝ち=true
    rep(i,N) cin >> a.at(i);
    rep(i,K+1){
        if(i == 0) continue;
        for(int ai : a ) { 
            if(i < ai) break; 
            if(!dp.at(i-ai)) { 
                dp.at(i) = true;
                break;
            }
        } 
    }
    if(dp.at(K)) cout << "First" << endl;
    else cout << "Second" <<endl;
}


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

def solve(n,h):
    ans = 0
    counter = 0
    memo = 0
    for i in range(n):
        if h[i] <= memo:
            counter += 1
        else:
            counter = 0
        memo = h[i]
        ans = max(ans,counter)
    return ans

def main():
    N = int(input())
    H = list(map(int,input().split()))
    print(solve(N,H))

if __name__ == '__main__':
    main()


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

long long getResult(const vector<long long> &stockPrices, const long long days){
  long long cash = 1000;
  long long stockCount = 0;

  for(uint i = 0; i < days; i++){
    if(i == days - 1 || stockPrices[i] >= stockPrices[i+1]){
      cash += stockCount * stockPrices[i];
      stockCount = 0;
    }else{
      stockCount += cash / stockPrices[i];
      cash %= stockPrices[i];
    }
  }
  return cash;
}

int main(){
  long long N;
  cin >> N;
  
  vector<long long> A(N);
  for(long long i = 0; i < N; i++){
    cin >> A[i];
  }
  
  long long result = getResult(A, N);
  cout << result << endl;
  
  return 0;
}

Measured memory_bytes: 3532
from itertools import  product
N,M,X = map(int,input().split())
ca = [list(map(int,input().split())) for _ in range(N)]
for i in range(1,M+1):
    count=0
    for j in range(N):
        count+=ca[j][i]
    if count<X:
        print(-1)
        exit()

ans = []
for z in product((0, 1), repeat=N):#bit全探索のくみあわせを勝手に作ってくれるので使うとよい
    count=0
    count2=[0]*M
    for i in range(N):
        if z[i]==1:
            count+=ca[i][0]
            for j in range(1,M+1):
                count2[j-1]+=ca[i][j]
    
    for i in range(M):
        if count2[i]<X:
            break
    else:
        ans.append(count)
print(min(ans))


Measured memory_bytes: 9320
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#pragma GCC optimize ("Ofast")
#pragma GCC omodtimize("unroll-loops,no-stack-protector")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
 
using namespace __gnu_pbds;
using namespace std;
 
template <typename T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
 
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<long long,long long> ii; 	
typedef complex<long double> com;

const ll mod = 1e9+7;

long long binpow(long long a, long long b) {
    a %= mod;
    long long res = 1;
    while (b > 0) {
        if (b & 1)
            res = res * a % mod;
        a = a * a % mod;
        b >>= 1;
    }
    return res;
}

int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	ll n,k;
	cin >> n >> k;
	ll ans = 0;
	vector <ll> arr(k+1);
	for (int z=k;z>=1;z--){
		arr[z] = binpow((k/z),n);
		ll x = z+z;
		while (x <= k){
			arr[z] -= arr[x];
			if (arr[z] < 0) arr[z] += mod;
			x += z;
		}
	}
	for (int z=1;z<=k;z++){
		ans += (z*arr[z])%mod;
		ans %= mod;
	}
	cout << ans << endl;
}

Measured memory_bytes: 3996
import sys
X, Y, Z, K = map(int, input().split())
A = list(map(int, sys.stdin.readline().split()))
B = list(map(int, sys.stdin.readline().split()))
C = list(map(int, sys.stdin.readline().split()))
A.sort(reverse = True)
B.sort(reverse = True)
C.sort(reverse = True)
AB = []
ans = []
for a in A:
    for b in B:
        AB.append(a + b)
AB.sort(reverse=True)
AB = AB[:min(3001, X*Y*Z+1)]
for c in C:
    for ab in AB:
        ans.append(c + ab)
ans.sort(reverse=True)
for i in range(K):
    print(ans[i])


Measured memory_bytes: 162272
#include <iostream>

bool SumSearch(const int* const A, 
               const int q, 
               const int sum, 
               const int depth, 
               const int size) {
    if(sum == q) return true;
    if(depth == size) return false;
    return SumSearch(A, q, sum+A[depth], depth+1, size) || SumSearch(A, q, sum, depth+1, size);
}

int main() {
    int n;
    int A[30];
    std::cin >> n;

    for(int i=0; i<n; ++i) {
        std::cin >> A[i];
    }

    int q;
    int Q[210];
    std::cin >> q;

    for(int i=0; i<q; ++i) {
        std::cin >> Q[i];
    }

    for(int i=0; i<q; ++i) {
        if(SumSearch(A, Q[i], 0, 0, n)) {
            std::cout << "yes" << std::endl;
        } else {
            std::cout << "no" << std::endl;
        }
    }
}


Measured memory_bytes: 3092
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
#define srep(i,s,t) for (int i = s; i < t; ++i)
using namespace std;
typedef long long int ll;
#define dame { puts("-1"); return 0;}
#define yn {puts("Yes");}else{puts("No");}


int main() {
    while(true){
        int n;
        cin >> n;
        if(n==0){
            break;
        }

        ll a[4001]  = {};

        int retu[4000];
        int count = 0;
        int flag[4001] = {};

        rep(i,n){
            int e;
            ll p,q;
            cin >> e >> p >> q;
            a[e] += p*q;
            //cout << a[e];
            if(flag[e]==0){
                retu[count] = e;
                count++;
                flag[e] = 1;
            }
        }
        int f = 0;
        rep(i,count){
            //cout << a[retu[i]];
            if(a[retu[i]]>=1000000){
                cout << retu[i] << endl;
                f = 1;
            }
        }
        if(f==0){
            cout << "NA" << endl;
        }

    }
    return 0;
}
 
 


Measured memory_bytes: 3096
#include <iostream>
#include <algorithm>
#include <vector>
#include <map>
using namespace std;
int collatz(int x){
    if(x % 2 == 0){
        return x / 2;
    }
    else{
        return x * 3 + 1;
    }
}
int main(void){
    int s;
    cin >> s;
    vector<int> a;
    map<int,int> b;
    a.push_back(s);
    b[s]++;
    int ans = 0;
    for(int i=1;;i++){
        a.push_back(collatz(a[i-1]));
        if(b[a[i]]){
            ans = i + 1;
            break;
        }
        else{
            b[a[i]]++;
        }
    }
    
    
    cout << ans << endl;
}


Measured memory_bytes: 3200
#include <iostream>
#include <bits/stdc++.h>
#define pb push_back
typedef long long ll;

using namespace std;

const ll mod = 1e9+7;

void Fastio(){
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
}

ll fact[1000006], inv[1000006];

ll fp(ll base, ll exp)
{
    if (exp == 0)
        return 1;
    ll ans = fp(base, exp / 2);
    ans = (ans * ans) % mod;
    if (exp % 2 != 0)
        ans = (ans * (base % mod)) % mod;
    return ans;
}


ll gcd(int a, int b){
    if(b==0)return a;
    return gcd(b,a%b);
}

void calcFacAndInv(ll n)
{
    fact[0] = inv[0] = 1;
    for (ll i = 1; i <= n; i++)
    {
        fact[i] = (i * fact[i - 1]) % mod;
        inv[i] = fp(fact[i], mod - 2);
    }
}

ll ncr(ll n, ll r)
{
    return ((fact[n] * inv[r]) % mod * inv[n - r]) % mod;
}

ll lcm(ll a, ll b){
    return (((a*b)%mod)*(fp(gcd(a,b), mod-2)))%mod;
}

ll npr(ll n, ll r)
{
    return (fact[n] * inv[n - r]) % mod;
}

int main()
{
    Fastio();
    calcFacAndInv(1e5+5);
    int n,k; cin>>n>>k;
    int arr[n];
    for(int i=0; i<n; i++){cin>>arr[i];}
    sort(arr,arr+n);
    ll res=0;
    for(int i=0; i<n; i++){
        if(i>=k-1)res+=(arr[i]*ncr(i,k-1));
        if(i+k-1<=n)res+=(-arr[i]*ncr(n-i-1,k-1));
        res%=mod;
    }
    cout<<res<<'\n';


    return 0;
}


Measured memory_bytes: 5504
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
using namespace std;
using ll = long long;
using P = pair<int, int>;
using vi = vector<int>;
using vc = vector<char>;
using vs = vector<string>;
using vll = vector<long long>;
using vvi = vector<vector<int>>;
using vvc = vector<vector<char>>;
using vvll = vector<vector<long long>>;
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 (b<a) {a=b; return 1;} return 0;}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    
    int sx, sy, tx, ty;
    cin >> sx >> sy >> tx >> ty;
    string ans = "";
    int y = ty - sy;
    int x = tx - sx;
    ans += string(y, 'U');
    ans += string(x, 'R');
    ans += string(y, 'D');
    ans += string(x, 'L');
    ans += "L";
    ans += string(y+1, 'U');
    ans += string(x+1, 'R');
    ans += "D";
    ans += "R";
    ans += string(y+1, 'D');
    ans += string(x+1, 'L');
    ans += "U";
    cout << ans << endl;

}

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

using namespace std;
typedef long long ll;

const double d2r = M_PI/180.;

int main(){
  double A, B;
  int H, M;
  cin >> A >> B >> H >> M;
  
  double angH = (360. / 12. * H + 30. * M / 60.) * d2r;
  double angM = 360. / 60. * M * d2r;
  double ang = angH - angM;
  
  double ret = sqrt(A*A + B*B - 2.*A*B*cos(ang));
  
  cout <<std::setprecision(15) <<  ret << endl;
    
  return 0;
}

Measured memory_bytes: 4148
#include <iostream> // cout, endl, cin
#include <cmath> //sqrt pow
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower
 
#define rep(i,n) for(int i = 0; i < n; i++)
#define vi vector<int>
#define vvi vector<vi>
#define pii pair<int, int>
#define mod 1000000007
using ll = long long;
using namespace std;
int main(){
  char s;
  cin >> s;
  rep(i, 3){
    char t;
    cin >> t;
    if(s == t){
      cout << "Bad" << endl;
      return 0;
    }
    s = t;
  }
  cout << "Good" << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include<bits/stdc++.h>
typedef long long ll;
using namespace std;
ll n,a,ans;
vector<ll> v,u;
typedef long long ll;
int main(void){
    cin>>n;
    for(int i=0;i<n;i++){
        cin>>a;
        v.push_back(a);
    }
    sort(v.begin(),v.end());
    reverse(v.begin(),v.end());
    for(int i=0;i<n;i++){
        if(i==0)u.push_back(v[i]);
        else{u.push_back(v[i]);u.push_back(v[i]);}
    }
    for(int i=0;i<n-1;i++){
        ans+=u[i];
    }
    cout<<ans<<endl;
}


Measured memory_bytes: 9004
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <string>

using ll = long long;

using namespace std;

int main() {
    int a, b, c;
    cin >> a >> b >> c;
    cout << (a + b + c >= 22 ? "bust" : "win") << '\n';
    return 0;
}

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

const int INT = 1000000007;

int64_t function1(int64_t k, int a) {
  if(a == 1) {
    return k % INT;
  }
  else if(a % 2 == 0) {
    return function1(k, a / 2) * function1(k, a / 2) % INT;
  }
  else {
    int64_t ans = k;
    ans = ans * function1(k, a / 2) % INT;
    ans = ans * function1(k, a / 2) % INT;
    return ans;
  }
}
    
  

int main() {
  int64_t N, M;
  cin >> N >> M;
  int64_t combi = 1;
  int64_t permu1 = 1;
  int64_t permu2 = 1;
  for(int64_t i = 0; i < N; i++) {
    permu2 *= M - i;
    permu2 %= INT;
  }
  int64_t ans = permu2 * permu2 % INT;
  for(int64_t i = 1; i <= N; i++) {
    combi *= N - i + 1;
    combi %= INT;
    combi *= function1(i, INT - 2);
    combi %= INT;
    permu1 *= M - i + 1;
    permu1 %= INT;
    permu2 *= function1(M - i + 1, INT - 2);
    permu2 %= INT;
    int64_t keep = combi * permu1 % INT;
    keep *= permu2;
    keep %= INT;
    keep *= permu2;
    keep %= INT;
    if(i % 2 == 0) {
      ans += keep;
      ans %= INT;
    }
    else {
      ans -= keep;
      ans %= INT;
    }
  }
  cout << (ans + INT) % INT << endl;
}


Measured memory_bytes: 3600
#include <bits/stdc++.h>
#define _GLIBCXX_DEBUG
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define rrep(i, n) for (int i = 1; i < (n+1); ++i)
using namespace std;
using ll = long long;
const ll INF = +10010010000;

typedef pair<ll,ll> P;
const ll MO = 1000000007;

int main(){
    int n;
    cin >> n;
    ll t=0;
    vector<int> a(n+2),diff(n+2);
    a[0] =0;a[n+1] = 0;
    rrep(i,n){
        cin >> a[i];
    }
    rrep(i,n+1){
        diff[i] = abs(a[i] - a[i-1]);
        t+=diff[i];
    }

    rrep(i,n){
        ll ans = t - diff[i] - diff[i+1];
        ans += abs(a[i+1]-a[i-1]);
        cout << ans <<endl;
    }
    return 0;
}

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

int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    int N;
    cin >> N;
    ll ans = 0;
    for(int i=1; i<=N; i++) ans += ll(i) * (N-i+1);
    for(int i=0; i<N-1; i++)
    {
        ll u, v;
        cin >> u >> v;
        if(v < u) swap(u, v);
        ans -= u * (N-v+1);
    }
    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 3544
#include<iostream>
#include<cstdio>
#include<cstring>
using namespace std;
#define N 23
inline int read(){
	int x=0,f=1;
	char c=getchar();
	while(c<'0'||c>'9'){
		if(c=='-')f=-1;
		c=getchar();
	}
	while(c>='0'&&c<='9'){
		x=(x<<1)+(x<<3)+c-'0';
		c=getchar();
	}
	return x*f;
}
char s[N];
int n;
int main(){
	scanf("%s",s+1);
	n=strlen(s+1);
	if(n&1)return !printf("No\n");
	for(int i=1;i<=n;i+=2){
		if(s[i]!='h')return !printf("No\n");
	}
	for(int i=2;i<=n;i+=2){
		if(s[i]!='i')return !printf("No\n");
	}
	printf("Yes\n");
	return 0;
}



Measured memory_bytes: 3828
H,W = map(int,input().split())

N = int(input())

a = list(map(int,input().split()))


c = []


Wind = 0
nlis = []
for ind,num in enumerate(a):

    ind += 1

    for j in range(num):

        nlis.append(ind)

        if len(nlis) == W:

            if Wind % 2 == 1:
                nlis.reverse()

            Wind += 1
            c.append(nlis)
            nlis = []

for i in c:
    print (" ".join(map(str,i)))
    


Measured memory_bytes: 3572
#!/usr/bin/python3

n, c = map(int, input().split())
x = [0]
v = [0]
ca = [0]
csum = 0
dmaxa1 = [0]
dmaxa2 = [0]
dmaxa1i = 0
dmaxa2i = 0
for i in range(n):
    xi, vi = map(int, input().split())
    x.append(xi)
    v.append(vi)
    csum += vi
    ca.append(csum)
    dmaxa1i = max(dmaxa1i, csum - xi)
    dmaxa2i = max(dmaxa2i, csum - xi * 2)
    dmaxa1.append(dmaxa1i)
    dmaxa2.append(dmaxa2i)
x.append(c)

cb = [0]
for i in range(n):
    csum -= v[i]
    cb.append(csum)
cb.append(0)

gainMax = 0
for b in range(1, n + 2):
    gain = cb[b]
    loss1 = (c - x[b]) * 2
    loss2 = c - x[b]
    d1 = dmaxa1[b - 1] + gain - loss1
    d2 = dmaxa2[b - 1] + gain - loss2
    gainMax = max(gainMax, max(d1, d2))

print(gainMax)

Measured memory_bytes: 27628
x,n = map(int,input().split())
if n>0:
  p = list(map(int,input().split()))
else:
  print(x)
  exit()
dx = 0
while True:
  if x-dx not in p:
    print(x-dx)
    exit()
  elif x+dx not in p:
    print(x+dx)
    exit()
  dx+=1

Measured memory_bytes: 61880
#include<stdio.h>

int main(void) {
	int number[3];
	int i;
	int five=0, seven=0;

	scanf("%d %d %d", &number[0], &number[1], &number[2]);
	for (i = 0; i < 3; i++) {
		if (number[i] == 5) five++;
		if (number[i] == 7) seven++;
	}
	if ((five == 2) && (seven == 1))printf("YES");
	else printf("NO");
	return 0;
}

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

int main() {
    int c, n, m; cin >> c >> n >> m;
    vector<int> dp(c + 1);
    vector<int> s(n), p(n);
    for(int i = 0; i < n; ++i) {
        cin >> s[i] >> p[i];
    }
    for(int i = 0; i < n; ++i) {
        auto nxt = dp;
        for(int j = 0; j + s[i] <= c; ++j) {
            nxt[j + s[i]] = max(nxt[j + s[i]], dp[j] + p[i]);
        }
        dp = move(nxt);
    }
    for(int k = 1; k <= m; ++k) {
        cout << dp[c / k] * k << endl;
    }
}



Measured memory_bytes: 3244
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
const ll MOD = 1e9 + 7;
const ll INF = 1LL << 60;
const double PI = 3.141592653589793238;
const double EPS = 1e-10;

int main() {
	int N;
	cin >> N;
	vector<ll> a(N);
	for (int i = 0; i < N; i++) cin >> a[i];
	ll ans = 0;
	while (1) {
		ll s = 0;
		for (int i = 0; i < N; i++) {
			s += a[i] / N;
		}
		ans += s;
		if (s == 0) break;
		for (int i = 0; i < N; i++) {
			a[i] += s - (a[i] / N)*(N + 1);
		}
	}
	cout << ans << endl;
 }

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

int main() {
    using namespace std;
    unsigned long N, K;
    cin >> N >> K;
    string S;
    cin >> S;
    S = 'R' + S + 'L';
    unsigned long ans{0};
    for(unsigned long i = 0; i <= N; ++i)ans += S[i] != S[i + 1];
    if(ans <= 2 * K + (S[0] != S[1]) + (S[N] != S[N + 1])){
        cout << N - 1 << endl;
    }else{
        for(unsigned long i = 1, j = 0; i <= N && j <= 2 * K; ++i){
            auto c = S[i];
            S[i] ^= (j & 1) * 30;
            j += c != S[i + 1];
        }
        ans = 0;
        for(unsigned long i = 1; i <= N; ++i)ans += S[i] == (S[i] == 76 ? S[i - 1] : S[i + 1]);
        cout << ans << endl;
    }
    return 0;
}

Measured memory_bytes: 512
#include<iostream>
#include<algorithm>
using namespace std;

int main() {
	int a, b, c;
	int output = 0;
	cin >> a >> b >> c;
	if (a == b) {
		if (c%a == 0){
			output = 1;
		}else{
			output = 0;
		}
	}
	else{
		for (int i = a; i <= b; i++) {
		if (c%i == 0) {
			output += 1;
			}
		}
	}
	cout << output << endl;
	cin >> output;
	return 0;
}

Measured memory_bytes: 3076
import math
List = [int(input()) for i in range(5)]
last = list(map(lambda x: x % 10, List))

lastnum = 0

last = sorted(last)
for i in range(5):
  if last[i] == 0:
    lastnum = 10
  else :
    lastnum = last[i]
    break

tensum =  list(map(lambda x: (math.ceil(x / 10))*10, List))

print(sum(tensum) - 10 + lastnum)

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

int main() {
  int W, H, N;
  cin >> W >> H >> N;
  vector<int> x(N), y(N), a(N);
  vector<int> hs(2, 0), mu(2);
  mu.at(0) = W;
  mu.at(1) = H;
  for (int i=0; i<N; i++)
    cin >> x.at(i) >> y.at(i) >> a.at(i);
  
  for (int i=0; i<N; i++){
    if (a.at(i) == 1 && hs.at(0) < x.at(i)) hs.at(0) = x.at(i);
    else if (a.at(i) == 2 && mu.at(0) > x.at(i)) mu.at(0) = x.at(i);
    else if (a.at(i) == 3 && hs.at(1) < y.at(i)) hs.at(1) = y.at(i);
    else if (a.at(i) == 4 && mu.at(1) > y.at(i)) mu.at(1) = y.at(i);
  }
  if (hs.at(0) < mu.at(0) && hs.at(1) < mu.at(1))
    cout << (mu.at(0) - hs.at(0)) * (mu.at(1) - hs.at(1)) << endl;
  else cout << 0 << endl;
}

Measured memory_bytes: 256
#include<stdio.h>
int A[2000],n;
int solve(int ,int);
int main(){
  int M,i,j;
  scanf("%d",&n);
  for(i=0;i<n;i++){
    scanf("%d",&A[i]);
  }
  scanf("%d",&M);
  int b[M];
  for(j=0;j<M;j++){
    scanf("%d",&b[j]);
  }
  for(j=0;j<M;j++){
    if(solve(0,b[j]))printf("yes\n");
    else printf("no\n");
  }
  return 0;
}
int solve(int i,int m){
  int res;
  if(m==0){
    return 1;
  }
  if(i>=n){
    return 0;
  }
  res=solve(i+1,m)||solve(i+1,m-A[i]);
  return res;
}



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

bool a[10][10];
int n,m,k,ans;
char st[10];

int main() {
	scanf("%d%d%d",&n,&m,&k);
	for (int i=1;i<=n;++i) {
		scanf("%s",st+1);
		for (int j=1;j<=m;++j)
		if (st[j]=='#') a[i][j]=1;
	}
	
	for (int x=0;x<(1<<n);++x)
	for (int y=0;y<(1<<m);++y) {
		int sl=0;
		for (int i=1;i<=n;++i)
		if ((1<<i-1)&x)
			for (int j=1;j<=m;++j)
			if ((1<<j-1)&y)
			if (a[i][j])
			++sl;
		if (sl==k) ++ans;
	}
	printf("%d\n",ans);
	
	return 0;
}

Measured memory_bytes: 3792
N = int(input())
S = input()

for a,b in ['SS','SW','WS','WW']:
    tmp = a+b
    for c in S:
        if (c=='x') ^ (tmp[-1]=='W'):
            tmp += ('W' if tmp[-2]=='S' else 'S')
        else:
            tmp += tmp[-2]
    #print(tmp)
    if tmp[:2] == tmp[-2:]:
        print(tmp[1:-1])
        exit()
print(-1)

Measured memory_bytes: 3444
#include <iostream>
#include <cstring>
#include <algorithm>
#include <vector>

#define LL long long
using namespace std;

int main(void) {
  const int num = 1000000000+7;
  int n;
  cin >> n;

  int element[n];
  for (int i=0; i<n; i++) {
    element[i] = 0;
  }

  for(int i=2; i<=n; i++) {
    int m=i;
    int a=2;
    while(m>=a*a) {
      if(m%a==0) {
        element[a-1]++;
        m/=a;
      } else {
        a++;
      }
    }
    element[m-1]++;
  }
  /*
  for (int i=0; i<n; i++) {
    cout << i+1 << ":" << element[i] << endl;
  }
  */

  LL ans=1;
  for (int i=0; i<n; i++) {
    if (element[i] != 0) {
      ans*=(element[i]+1);
      ans%=num;
    }
  }

  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ll long long int
#define mod 1000000007
using namespace std;
int main() {
	int n,k;
	cin>>n>>k;
	int c=0;
	while(n)
	{
		n=n/k;
		c++;
	}
	cout<<c;
	
}

Measured memory_bytes: 256
N, K = map(int,input().split())

def f_10_to_n(X, n):
    X_dumy = X
    ans = ''
    while X_dumy>0:
        ans = str(X_dumy%n)+ans
        X_dumy = int(X_dumy/n)
    return ans

print(len(f_10_to_n(N, K)))

Measured memory_bytes: 3060
#!/usr/bin/env python3
#ABC72 D

import sys
import math
import bisect
sys.setrecursionlimit(1000000000)
from heapq import heappush, heappop
from collections import defaultdict
from itertools import accumulate
from collections import Counter
from collections import deque
from operator import itemgetter
from itertools import permutations
mod = 10**9 + 7
def I(): return int(sys.stdin.readline())
def LI(): return list(map(int,sys.stdin.readline().split()))

n = I()
p = LI()
ans = 0
for i in range(n-1):
    if p[i] == i+1:
        p[i],p[i+1] = p[i+1],p[i]
        ans += 1
if p[-1] == n:
    ans += 1
print(ans)


Measured memory_bytes: 52316