akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,o,n) for(long long i = o;i<n;i++)
#define oneforall ios::sync_with_stdio(false);cin.tie(0);
#define all(v) (v).begin(),(v).end()
#define ini(...) int __VA_ARGS__; in(__VA_ARGS__)
#define inl(...) long long __VA_ARGS__; in(__VA_ARGS__)
#define ins(...) string __VA_ARGS__; in(__VA_ARGS__)
#define int long long 
const long long INF=1e18;
void in(){} template <typename T,class... U> void in(T &t,U &...u){ cin >> t; in(u...);}
void out(){cout << "\n";} template <typename T,class... U> void out(const T &t,const U &...u){ cout << t; if(sizeof...(u)) cout << " "; out(u...);}
typedef vector<int> vi;
typedef vector<long long> vl;
typedef long long ll;
typedef vector<pair<long, long > > vpll;
typedef vector<pair<int, int > > vpii;



int32_t main() {
	oneforall
	oneforall
	oneforall
	oneforall
	oneforall
	oneforall
	oneforall
	oneforall
	oneforall
	oneforall
	oneforall
	oneforall
	oneforall
	oneforall
	
	ini(n);
	ini(n1);
	if(n1>=n)out("unsafe");
	else out("safe");	
	
















	return 0;
}


Measured memory_bytes: 3652
#include <iostream>
#include <string>

int main()
{
	while (true) {
		std::string deck;
		std::cin >> deck;
		
		if (deck == "-") break;
		
		int numOfShuffle;
		std::cin >> numOfShuffle;
		
		int shuffle_amount = 0;
		for (int i=0; i<numOfShuffle; i++) {
			int n;
			std::cin >> n;
			shuffle_amount += n;
		}
		shuffle_amount %= deck.length();
		std::cout << deck.substr(shuffle_amount) << deck.substr(0, shuffle_amount) << std::endl;
	}
		
	return 0;
}




Measured memory_bytes: 3156
a=[]
b=[]
op=[]
while True:
    x,y,z=raw_input().split()
    if(y=='?'):
        break
    a.append(int(x))
    op.append(y)
    b.append(int(z))
A=iter(a)
B=iter(b)
OP=iter(op)
for n in A:
    p=B.next()
    q=OP.next()

    if(q=='+'):
        print(n+p)
    elif(q=='*'):
        print(n*p)
    elif(q=='-'):
        print(n-p)
    elif(q=='/'):
        print(n/p)

Measured memory_bytes: 6340
n,m,c = map(int, input().split())

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

lstA=[]
for i in range(n):
    lstA.append(list(map(int,input().split())))

cnt=0
sum=0
for j in range(n):
    for k in range(m):
        ans=lstA[j][k]*lstB[k]
        sum=sum+ans
    if sum+c>0:
        cnt+=1
    sum=0

print(cnt)


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

int main(){
	int p,n,sum=0,k=0,num=0;
	double ans;
	while(scanf("%d,%d",&p,&n)!=EOF){
		//if(p==0) break;
		k++;
		sum+=p*n;
		num+=n;
	}
	cout<<sum<<endl;
	ans=(double)num/k;
	printf("%d\n",(int)(ans+0.5) );
}

Measured memory_bytes: 1232
#include<bits/stdc++.h>                                                
using namespace std;
int main(){
  int N,total = 0;
  cin >>  N;
  bool real = false;
  int cakes = 4,donuts = 7;
  for(int i=0;i< 30;i++){
    for(int j=0;j < 30;j++){
      total = cakes * j + donuts * i;
      if(total == N)
        real = true;
    }
  }
  if(real){
    cout << "Yes" << endl;
  }else{
    cout << "No" << endl;
  }
}


Measured memory_bytes: 256
import java.util.*;

public class Main {

    static int n;
    static long[] data;
    static long[] datb;

    static void add(int a, int b, int x, int k, int l, int r){
        if (a<=l && r<=b) data[k]+=x;
        else if (!(b<=l || r<=a)) {
            datb[k]+=(long)x*(Math.min(b, r)-Math.max(a, l));
            add(a, b, x, k*2+1, l, (l+r)/2);
            add(a, b, x, k*2+2, (l+r)/2, r);
        }
    }

    static long sum(int a, int b, int k, int l, int r) {
        if (a<=l && r<=b) return data[k]*(r-l)+datb[k];
        else if (!(b<=l || r<=a)) {
            long tmp = data[k]*(Math.min(b, r)-Math.max(a, l));
            tmp += sum(a, b, k*2+1, l, (l+r)/2);
            tmp += sum(a, b, k*2+2, (l+r)/2, r);
            return tmp;
        } else {
            return 0L;
        }
    }

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n_ = sc.nextInt();
        n = 1;
        while(n<n_) n*=2;
        data = new long[2*n-1];
        datb = new long[2*n-1];

        int q = sc.nextInt();
        for (int qq=0;qq<q;qq++) {
            int com = sc.nextInt();
            if (com==0) {
                int s = sc.nextInt()-1;
                int t = sc.nextInt()-1;
                int x = sc.nextInt();
                add(s, t+1, x, 0, 0, n);
            } else { // com==1
                int s = sc.nextInt()-1;
                int t = sc.nextInt()-1;
                System.out.println(sum(s, t+1, 0, 0, n));
            }
        }
        // System.out.println(Arrays.toString(data));
        // System.out.println(Arrays.toString(datb));
    }
}


Measured memory_bytes: 120764
#include<stdio.h>

int main(void){
	int n;
	while(scanf("%d", &n),n){
		int a[10] ={0};
		int t;
		
		for(int i = 0; i < n; i++){
			scanf("%d", &t);
			a[t]++;
		}
		
		for(int i = 0; i < 10; i++){
			if(a[i]==0){
				puts("-");
			}else{
				for(int j = 0; j < a[i]; j++){
					printf("*");
				}puts("");
			}
		}
	}
	return 0;
}

Measured memory_bytes: 1016
from math import ceil
X,K,D=map(int,input().split())


if abs(X)-K*D>=0:
    print(abs(abs(X)-D*K))
else:
    cnt=ceil(abs(X)/D)

    dist_1= -(abs(X)-cnt*D)
    dist_2= abs(X)-(cnt-1)*D


    remain_hop=K-cnt

    if remain_hop%2==0:
        print(dist_1)
    else:
        print(dist_2)



Measured memory_bytes: 9176
#include<bits/stdc++.h>
using namespace std;
long long int a[200005];
int main()
{
	long long int n,m,ans=0;
	int i;
	cin>>n>>m;
	for(i=1;i<=n;i++)
	{
	cin>>a[i];
	}
    sort(a+1,a+1+n);
    for(i=1;i<=n-m;i++)
    {
    	ans+=a[i];
    }
    cout<<ans;
} 

Measured memory_bytes: 1792
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner in = new Scanner(System.in);
		int num = in.nextInt();
		int limit = in.nextInt();

		int weight[] = new int[num + 1];
		int value[] = new int[num + 1];
		for ( int i = 1; i <= num; i++ ) {
			weight[i] = in.nextInt();
			value[i] = in.nextInt();
		}

		long dp[][] = new long[num + 1][limit + 1];
		for ( int w = 1; w <= limit; w++ ) {
			for ( int n = 1; n <= num; n++ ) {
				if ( w - weight[n] < 0 ) {
					dp[n][w] = dp[n - 1][w];
				} else {
					dp[n][w] = Math.max(dp[n - 1][w - weight[n]] + value[n], dp[n - 1][w]);
				}
			}
		}

		System.out.println(dp[num][limit]);
		in.close();
	}
}

Measured memory_bytes: 126676
#include <iostream>
#include <sstream>
#include <string>
#include <vector>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <algorithm>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
using namespace std;

typedef long long ll;

ll solve( int n ) {
    if ( n % 2 == 0 ) {
        if ( n == 2 ) {
            return 2;
        } else {
            ll res = 0;
            ll prev = 6;
            for ( int i = 0; i < ( n - 2 ) / 2; ++ i ) {
                res += prev;
                prev *= 3;
            }
            res += 2;
            return res;
        }
    } else {
        if ( n == 1 ) {
            return 1;
        } else {
            ll res = 0;
            ll prev = 4;
            for ( int i = 0; i <= ( n - 3 ) / 2; ++ i ) {
                res += prev;
                prev *= 3;
            }
            res ++;
            return res;
        }
    }
    return -1;
}

int main() {
    int n;
    while ( cin >> n ) {
        cout << solve( n ) << endl;
    }
	return 0;
}

Measured memory_bytes: 0
#include<iostream>
using namespace std;
int max3(int x,int y,int z){
  int max=0;
  if(x>y){
    max=x;
  }else{
    max=y;
  }
  if(max<z){
    max=z;
  }
  return max;
}
int main(void){
  int a,b;
  cin>>a>>b;
  int add=a+b;
  int sub=a-b;
  int mul=a*b;
  int ans=max3(add,sub,mul);
  printf("%d\n",ans);
  return 0;
}

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

int main() {

    bool bingo[3][3];
    int A[3][3];
    rep(i, 3) {
        rep(j, 3) {
            cin >> A[i][j];
        }
    }

    int N;
    cin >> N;

    int b[N];
    rep(i, N) cin >> b[i];

    rep(i, 3) {
        rep(j, 3) {
            bingo[i][j] = false;
            rep(k, N) if (A[i][j] == b[k]) bingo[i][j] = true;
        }
    }

    string ans = "No";

    rep(i, 3) if (bingo[i][0] and bingo[i][1] and bingo[i][2]) ans = "Yes";
    rep(i, 3) if (bingo[0][i] and bingo[1][i] and bingo[2][i]) ans = "Yes";
    if (bingo[0][0] and bingo[1][1] and bingo[2][2]) ans = "Yes";
    if (bingo[0][2] and bingo[1][1] and bingo[2][0]) ans = "Yes";

    cout << ans << endl;


    return 0;
}


Measured memory_bytes: 3592
#include <iostream>

int main()
{
    int a, b;
    char op;
    
    while (1) {
        std::cin >> a >> op >> b;
        
        if (op == '+') {
            std::cout << a + b << std::endl;
        } else if (op == '-') {
            std::cout << a - b << std::endl;
        } else if (op == '*') {
            std::cout << a * b << std::endl;
        } else if (op == '/') {
            std::cout << a / b << std::endl;
        } else if (op == '?') {
            break;
        }
        
    }
}


Measured memory_bytes: 3092
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<iomanip>
#include<math.h>
using namespace std;
typedef long long ll;
#define REP(i,n) for(int i=0; i<(n); i++)
#define FOR(i,a,b) for(int i=(a); i<(b); i++)
const long long INF = 1LL << 60;

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

	ll ans = 0;
	for (ll i = 1; i < n; i++) {
		ans += i;
	}

	cout << ans << endl;

	return 0;
}

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

bool parity(int n){
  if(n*n*n*n%10 == 1)
    return true;
  else
    return false;
}

int power(int x, int y){
  int64_t n = 1ll;
  for(int i = 0; i < y; i++)
    n *= x;
  return n;
}
int digit(int64_t x, int y){
  return x%power(10,y+1)/power(10,y);
}

int main() {
  
  int n;
  cin >> n;
  
  vector<int>n99(81);
  for(int i = 1; i < 10; i++){
    for(int j = 1; j < 10; j++){
      n99.at(9*i+j-10) = i*j;
    }
  }
  
  for(int k : n99){
    if(k == n){
      cout << "Yes" << endl;
      break;
    }
    else if(k == 81){
      cout << "No" << endl;
      break;
    }
  }
  
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define endl "\n"
using namespace std;

#define ll long long
const long long llINF = 1LL << 60;
const int iINF = 1LL << 20;
template<class T> inline bool chmin(T& a, T b) { if (b < a) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }


void execute();
int main() 
{
    cin.tie(nullptr);
    ios::sync_with_stdio(false);// cin と scanfの併用禁止
    cout << fixed << setprecision(15);
    execute();
    return 0;
}


void execute()
{
  int N, W;
  cin >> N >> W;

  ll v_MAX = 1000*100;
  ll sum_w[101][v_MAX+1] = {0};

  sum_w[0][0] = 0;
  for(int v = 1; v <= v_MAX; v++){
      sum_w[0][v] = llINF;
  }

  for(int i = 0; i < N; i++){
    int wgh, val;
    cin >> wgh >> val;
    
    for(int v = 0; v <= v_MAX; v++){
      sum_w[i+1][v] = sum_w[i][v];
      if(0 <= v - val) chmin(sum_w[i+1][v], sum_w[i][v-val]+wgh);
    }
  }

  ll res = 0;
  for (int v = 0; v <= v_MAX; v++) {
    if(sum_w[N][v] <= W) {res = v;}
  }  
  cout << res << endl; 
}


Measured memory_bytes: 79232
/*==============================================*\
ID:          shahidul_brur

Name:     Md. Shahidul Islam
Study:      CSE, BRUR
Address:  Rangpur, Bangladesh

 mail: shahidul.cse.brur@gmail.com
 FB  : fb.com/shahidul.brur
 Blog: shahidul-brur.blogspot.com(in Bengali),
       shahidul-brur-en.blogspot.com(in English)
\*===============================================*/
#include<bits/stdc++.h>
//#include <ext/pb_ds/assoc_container.hpp> // Common file
//#include <ext/pb_ds/tree_policy.hpp> // Including tree_order_statistics_node_update
//using namespace __gnu_pbds;
using namespace std;
//typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update> ordered_set;

typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef pair<int, int> ii;
typedef pair<ll, int> li;
typedef pair<int, ll> il;
typedef vector<ii> vii;
typedef vector<il> vil;
typedef vector<li> vli;

#define ff first
#define ss second
#define pb push_back
#define mp make_pair
#define sz size()
#define all(a)  a.begin(), a.end()
#define mem(a, b)     memset(a, b, sizeof(a))
#define f0(i,b) for(int i=0;i<(b);i++)
#define f1(i,b) for(int i=1;i<=(b);i++)
#define f2(i,a,b) for(int i=(a);i<=(b);i++)
#define fr(i,b,a) for(int i=(b);i>=(a);i--)
#define rep(i,a,b,c) for(int i=(a);i!=(b);i+=(c))

int dx8[] = {0, 0, 1, 1, 1, -1, -1, -1};
int dy8[] = {1,-1, 1, -1, 0, 0, -1, 1};

const double PI = acos(-1.0);
const double EPS = 1e-6;
const int MOD = (int)1e9+7;
const int maxn = (int)2e5+5;
const int LOGN = 20;
ll dp[100][100001], inf = 1e9+2;
bool vis[100][100001];
int n, c;
int ans, a[100], w[100];
ll cal(int pos, int prof){
	if(prof==0) return 0;
	if(pos==n || prof<0) return inf;
	ll &ret = dp[pos][prof];
	if(vis[pos][prof]) return ret;
	vis[pos][prof] = 1;
	ll ret0 = cal(pos+1, prof);
	ll ret1 = w[pos] + cal(pos+1, prof-a[pos]);
	ret = min(ret0, ret1);
	return ret;
}
int main()
{
    ios_base::sync_with_stdio(0); cin.tie(NULL); cout.tie(NULL);
    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);
    cin>>n>>c;
    f0(i,n) cin>>w[i]>>a[i];
    for(int prof=n*1000;prof>=0;prof--){
    	if(cal(0,prof)<=c){
    		cout << prof << "\n";
    		return 0;
    	}
    }
    return 0;
}


Measured memory_bytes: 88192
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Arrays;

public class Main {

	public static void main(String[] args) throws IOException {
		// TODO ?????????????????????????????????????????????
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		while(true){
			String [] str = br.readLine().split(" ");
			int n = Integer.parseInt(str[0]);
			int quorum = Integer.parseInt(str[1]);

			int[] availNum = new int[101];
			Arrays.fill(availNum, 0);

			if(n == 0 && quorum == 0){
				break;
			}
			for(int i = 0 ; i < n; i++){
				str = br.readLine().split(" ");
				int m = Integer.parseInt(str[0]);

				for(int j = 0; j < m ; j++){
					int date = Integer.parseInt(str[j + 1]);
					availNum[date]++;
				}

			}

			//????¶???°??\????????????????????????????????\?????¢???
			int earlyDay = 0;

			for(int i = 1; i < availNum.length ; i++){
				if(availNum[i] >= quorum && availNum[i] > availNum[earlyDay]){
					earlyDay = i;
				}
			}

			System.out.println(earlyDay);
		}

	}

}

Measured memory_bytes: 37568
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
using namespace std;
typedef long long int ll;
int main() {
	int n, k[100];
	cin >> n;
	for (int i = 0; i < n; ++i) {
		cin >> k[i];
	}
	sort(k, k + n);
	cout<<k[n-1]-k[0]<<endl;
}

Measured memory_bytes: 256
import java.util.*;

class Main{

    String[][] ab;

    void solve(){
        Scanner sc = new Scanner(System.in);

        int n = sc.nextInt();
        while(n!=0){
            ab = new String[n][2];
            for(int i=0; i<n; i++){
                ab[i][0] = sc.next();
                ab[i][1] = sc.next();
            }
            String start = sc.next();
            String goal = sc.next();

            System.out.println(bfs(start, goal));
            n = sc.nextInt();
        }
    }

    class P{
        String s;
        int cnt;
        P(String s, int cnt){
            this.s = s;
            this.cnt = cnt;
        }
    }

    int bfs(String start, String goal){
        LinkedList<P> list = new LinkedList<P>();
        list.add(new P(start, 0));
        HashSet<String> set = new HashSet<String>();

        while(list.size()>0){
            P p = list.poll();
            String s = p.s; int cnt = p.cnt;

            if(s.length()>=100) continue;
            if(s.equals(goal)) return cnt;
            if(!set.add(s)) continue;

            for(int i=0; i<ab.length; i++){
                String a = ab[i][0];
                String b = ab[i][1];
                String news = s.replaceAll(a, b);
                list.add(new P(news, cnt+1));
            }
        }
        return -1;
    }

    public static void main(String[] args){
        new Main().solve();
    }
}

Measured memory_bytes: 114024
// Author : MohamedSameh
#include <bits/stdc++.h>
typedef long long ll ;
#define pb push_back
#define f first
#define s second
#define all(v) v.begin(),v.end()
#define rall(v) v.rbegin(),v.rend()
#define SZ(a) (int)a.size()
void fo (){fflush(stdout);}
using namespace std;
void F (){
ll a[100002];
ll pre[100002];
int n , m , k  ;
scanf ("%d%d%d" , &n , &m ,&k );
for (int i =0 ; i < n ;i++)scanf ("%lld" ,a+i );
for (int i =0 ; i < m ;i++)
{
  int l , r , d ;
  scanf ("%d%d%d" , &l ,&r , &d );
  l--;
  r--;
  pre[l]+=d;
  pre[r+1]-=d;
}
a[0] += pre[0];
for (int i =  1; i < n ;i++)
{
  pre[i] += pre[i-1];
  a[i] += pre[i];
}
for (int i =0 ; i < k ;i++)
{
  int l , r;
  scanf ("%d%d" , &l ,&r );
  l-=2;
  r--;

}
for (int i =0 ; i < n ;i++)
{
  cout << a[i] <<" ";
}
}
bool kk (int j , string x )
{
  for (int i =0 ; i < SZ(x) ;i++)
  {
    if (i == j )continue ;
    if (x[i] < '0' || x[i] > '9')return false;
  }
  return true ;
}
int main ()
{
  int a , b ;
  string x ;
  cin >> a >> b >> x ;
  if (x[a] == '-' && kk (a,x))
  {
    printf ("Yes\n");
  }else
  printf ("No\n");
  //cerr << 1000 * clock() / CLOCKS_PER_SEC << "ms\n";
  return 0;
}


Measured memory_bytes: 256
import { readFileSync } from "fs";

const read = () =>
  readFileSync(0, "utf8")
    .split("\n")
    .map((line) => line.split(" "));

const main = (input: string[][]) => {
  const D = input.slice(1, -1).map((line) => Number(line[0]));

  return new Set(D).size;
};

console.log(main(read()));


Measured memory_bytes: 29604
#include <bits/stdc++.h>
using namespace std;
int main(){
  int k,n;
  cin>>k>>n;
  vector<int> a(n);
  vector<int> dist;
  for(int i=0;i<n;i++)cin>>a[i];
  for(int i=0;i<n;i++){
    if(i==n-1){
      dist.push_back(a[0]+k-a[i]);
      break;
    }
    dist.push_back(a[i+1]-a[i]);
  }
  sort(dist.begin(),dist.end());
  long long ans=0;
  for(int i=0;i<n-1;i++)ans+=dist[i];
  cout<<ans<<endl;
  return 0;
}
    

Measured memory_bytes: 5084
#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)
#define rng(x) (x).begin(),(x).end()
#define rrng(x) (x).rbegin(),(x).rend()
#define limit(x,l,r) max(l,min(x,r))
#define lims(x,l,r) (x = max(l,min(x,r)))
#define isin(x,l,r) ((l) <= (x) && (x) < (r))
#define show(x) cout << #x << " = " << (x) << endl
#define show2(x,y) cout << #x << " = " << (x) << ", " << #y << " = " << (y) << endl
#define show3(x,y,z) cout << #x << " = " << (x) << ", " << #y << " = " << (y) <<  ", " << #z << " = " << (z) << endl
#define showv(v) rep(i,v.size()) printf("%d%c", v[i], i==v.size()-1?'\n':' ')
#define showv2(v) rep(j,v.size()) showv(v[j])
#define showt(t,n) rep(i,n) printf("%d%c", t[i], i==n-1?'\n':' ')
#define showt2(t,r,c) rep(j,r) showt(t[j],c)
#define showvp(p) rep(i,p.size()) printf("%d %d\n", p[i].first, p[i].second);
#define printv(v) rep(i,v.size()) printf("%d\n", v[i])
#define printt(t,n) rep(i,n) printf("%d\n", t[i])
#define incl(v,x) find(rng(v),x)!=v.end()
#define incls(s,c) s.find(c)!=string::npos
#define fi first
#define se second
#define pb push_back
#define eb emplace_back
#define sz(x) (int)(x).size()
#define pcnt __builtin_popcountll
#define bit(n,k) ((n>>k)&1) // nのk bit目
#define bn(x) ((1<<x)-1)
#define dup(x,y) (((x)+(y)-1)/(y))
#define newline puts("")
#define uni(x) x.erase(unique(rng(x)),x.end())
#define SP << " " <<
#define v(T) vector<T>
#define vv(T) v(v(T))
using namespace std;
using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vl = vector<ll>;
using vs = vector<string>;
using P = pair<int, int>;
using T = tuple<int, int, int>;
using vp = vector<P>;
using vt = vector<T>;
const int mod = 1000000007;
const double EPS = 1e-9;
const int INF = (1<<30)-1;
//const ll INF = (1LL<<62)-1;
#define dame { puts("No"); return 0;}
#define yn {puts("Yes");}else{puts("No");}
//inline int in() { int x; scanf("%d",&x); return x;}
template<class T = int> inline T in() { T x; cin >> x; return (x);}
template<typename T>inline ll suma(const v(T)& a) { ll res(0); for (auto&& x : a) res += x; return res;}
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }

int main () {
  int n;
  cin >> n;
  vi x(n);
  rep(i,n) cin >> x[i];
  
  int ans = INF;
  rrep(p,100) {
    int tmp = 0;
    rep(i,n) {
      tmp += (x[i]-p)*(x[i]-p);
    }
    chmin(ans, tmp);
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
MOD = 10**9 + 7
def dp(a):
    L = len(a)

    dp = [[0 for j in range(13)] for k in range(L + 1)]
    dp[0][0] = 1
    for i in range(L):
        if a[i] == "?":
            for j in range(10):
                for k in range(13):
                    dp[i + 1][(j + k*10) % 13] += dp[i][k]
                    dp[i + 1][(j + k*10) % 13] %= MOD
        else:
            for j in range(13):
                dp[i + 1][(int(a[i])+j*10) % 13] += dp[i][j]
                dp[i + 1][(int(a[i])+j*10) % 13] %= MOD
    print(dp[L][5] % MOD)


def main():
    S = input()
    dp(S)


if __name__ == '__main__':
    main()

Measured memory_bytes: 65884
#include <iostream>
#include <vector>
#include <queue>
#include <stack>
#include <string>
#include <sstream>
#include <algorithm>
#include <cmath>

using namespace std;

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



int main(){
  cin.tie(0); ios::sync_with_stdio(false);    // Magic for faster cin

  int A, B, C; int X, Y;
  cin >> A >> B >> C >> X >> Y;

  if(2*C>=A+B){
    cout << A*X + B*Y << endl;
    return 0;
  } else {
    int N = (X>Y)?Y:X;
    int hasuu = (X>Y)?((X-Y)*A):((Y-X)*B);
    int hasuu2 = 2*C*abs(X-Y);
    int h = (hasuu>hasuu2)?hasuu2:hasuu;
    cout << 2*N*C + h << endl;
  }

  return 0;
}


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

namespace C
{
    class Program
    {
        static void Main(string[] args)
        {
            Run(args);
        }

        private static void Run(string[] args)
        {
            var input = Console.ReadLine().Split(' ').Select(int.Parse).ToArray();
            var N = input[0];
            var K = input[1];
            var Q = input[2];

            var aCount = new int[N];
            for (int i = 0; i < Q; i++)
            {
                var a = int.Parse(Console.ReadLine());
                aCount[a - 1]++;
            }

            for (int i = 0; i < N; i++)
            {
                if (K - Q + aCount[i] > 0) {
                    Console.WriteLine("Yes");
                } else {
                    Console.WriteLine("No");
                }
            }
        }
    }
}


Measured memory_bytes: 17884
S = list(input())
R1 = [(1 + (-1)**i)/2 for i in range(len(S))]
R2 = [(1 + (-1)**(i+1))/2 for i in range(len(S))]
count1 = 0
count2 = 0
for i in range(len(S)):
    if int(S[i]) != R1[i]:
        count1 += 1
for i in range(len(S)):
    if int(S[i]) != R2[i]:
        count2 += 1
print(min(count1,count2))

Measured memory_bytes: 10156
// C++ program to find the minimum sum of costs such that
// each elements choose one of the costs.
#include <bits/stdc++.h>
using namespace std;

int main()
{
	int n,k;
	cin>>n>>k;
	int a[n];
	int i,j;
	for(i=0;i<n;i++)
		cin>>a[i];
	int dp[n];
	dp[0]=0;
	for(i=1;i<n;i++)
	{
		int temp=INT_MAX;
		for(j=1;j<=k;j++)
			if(i-j>=0)
			temp=min(temp,abs(a[i]-a[i-j])+dp[i-j]);
		dp[i]=temp;
		// cout<<dp[i]<<" ";
	}
	cout<<dp[n-1];
}

Measured memory_bytes: 1024
#include<bits/stdc++.h>
#define fast ios::sync_with_stdio(false);cin.tie(NULL)
using namespace std;
#define int long long
#define MOD 1000000007
typedef vector<int> vi;
typedef pair<int,int> pi;
#define inf 1e18
#define For(i,a,b) for (int i = a; i < b; i++)
#define Rep(i,a,b) for (int i = a; i <= b; i++)
#define ps(x,y) fixed << setprecision(y) << x 
#define pb push_back 
#define mp make_pair 

int maxtime(int x) {
    return (x+9) / 10 * 10;
}

int remtime(int x) {
    return maxtime(x) - x;
}
 
int32_t main()
{
    fast;
    int a, b, c, d, e, ans = 0;
    cin >> a >> b >> c >> d >> e;
    ans = maxtime(a) + maxtime(b) + maxtime(c) + maxtime(d) + maxtime(e);
    ans -= max({ remtime(a), remtime(b), remtime(c), remtime(d), remtime(e) });
    cout << ans;
    
    return 0;
}

Measured memory_bytes: 3628
//https://atcoder.jp/contests/abc136/tasks/abc136_a
#include <bits/stdc++.h>
using namespace std;
using ll=int64_t;
#define FOR(i,a,b) for(int64_t i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
int main() {
    ll A,B,C; cin>>A>>B>>C;    
    ll ans=C-(A-B);
    cout<<max(ans,(ll)0)<<endl;
    return 0;
}

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

public class Main {
	public static void main(String[] args) {
		FastScanner sc = new FastScanner();
		String s = sc.next();

		int state = 0;
		for (char c : s.toCharArray()) {
			if (state == 0 && c == 'C') {
				state++;
			} else if (state == 1 && c == 'F') {
				state++;
			}
		}
		System.out.println(state == 2 ? "Yes" : "No");
	}

}

class FastScanner {
	public static String debug = null;

	private final InputStream in = System.in;
	private int ptr = 0;
	private int buflen = 0;
	private byte[] buffer = new byte[1024];
	private boolean eos = false;

	private boolean hasNextByte() {
		if (ptr < buflen) {
			return true;
		} else {
			ptr = 0;
			try {
				if (debug != null) {
					buflen = debug.length();
					buffer = debug.getBytes();
					debug = "";
					eos = true;
				} else {
					buflen = in.read(buffer);
				}
			} catch (IOException e) {
				e.printStackTrace();
			}
			if (buflen < 0) {
				eos = true;
				return false;
			} else if (buflen == 0) {
				return false;
			}
		}
		return true;
	}

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

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

	private void skipUnprintable() {
		while (hasNextByte() && !isPrintableChar(buffer[ptr]))
			ptr++;
	}

	public boolean isEOS() {
		return this.eos;
	}

	public boolean hasNext() {
		skipUnprintable();
		return hasNextByte();
	}

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

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

	public int nextInt() {
		return (int) nextLong();
	}

	public long[] nextLongList(int n) {
		return nextLongTable(1, n)[0];
	}

	public int[] nextIntList(int n) {
		return nextIntTable(1, n)[0];
	}

	public long[][] nextLongTable(int n, int m) {
		long[][] ret = new long[n][m];
		for (int i = 0; i < n; i++) {
			for (int j = 0; j < m; j++) {
				ret[i][j] = nextLong();
			}
		}
		return ret;
	}

	public int[][] nextIntTable(int n, int m) {
		int[][] ret = new int[n][m];
		for (int i = 0; i < n; i++) {
			for (int j = 0; j < m; j++) {
				ret[i][j] = nextInt();
			}
		}
		return ret;
	}
}

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

int main() {
    string s;
    cin >> s;
    int cnt = 0;
    for (int i = 1; i < s.size() - 1; i++) {
        cnt++;
    }
    cout << s[0] << cnt << s[s.size() - 1] << endl;
    return 0;
}

Measured memory_bytes: 256
n = gets.to_s.to_i
a = gets.to_s.split.map{|t| t.to_i }

a = a.map.with_index{|t,i| [t,i] }.sort.reverse

dp = Array.new(n+1){ [0] * (n+1) }

a.each_with_index do |tmp,i|
  a = tmp[0]
  k = tmp[1]
  (i+1).times do |j|
    
    dp[i+1][j+1] = [ dp[i+1][j+1],  dp[i][j] + (k-j) * a       ].max
    dp[i+1][j]   = [ dp[i+1][j],    dp[i][j] + (n-i+j-1-k) * a ].max
  end
end

puts dp[-1].max

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

char chess(int h, int w){
    if((h+w)%2==0){
        return '#';
    }
    return '.';
}

    
int main(void){
    int H,W;
    while (true){
        cin >> H >> W;
        if (H == 0 && W == 0){
               break;
        }
        for (int i = 0; i < H; i++){
            for (int j = 0; j < W; j++){
            cout << chess(i,j);
            }
        cout << endl;
        }
        cout << endl;
    } 
}


Measured memory_bytes: 3088
import java.util.*;
public class Main {

  public static void main(String[] args) { 
      Scanner sc = new Scanner(System.in);
      long n = sc.nextLong();
      int minLen = Integer.MAX_VALUE;
      for(long i = 1; i * i <= n; i++) {
        if(n % i == 0)
          minLen = Math.min(minLen, calDigit(Math.max(i, n / i)));
      }
      System.out.println(minLen);
  }

  private static int calDigit(long n) {
    int cnt = 0;
    while(n > 0) {
      cnt++;
      n /= 10;
    }
    return cnt;
  }
}

Measured memory_bytes: 21844
#include<map>
#include<set>
#include<list>
#include<cmath>
#include<queue>
#include<stack>
#include<cstdio>
#include<string>
#include<vector>
#include<complex>
#include<cstdlib>
#include<cstring>
#include<climits>
#include<numeric>
#include<sstream>
#include<iostream>
#include<algorithm>
#include<functional>
#include<cctype>

#define mp make_pair
#define pb push_back
#define REP(i,a,n) for(int i = a;i < (n);i++)
#define rep(i,n) for(int i = 0;i < (n);i++)
#define all(s) s.begin(), s.end()
#define rall(s) s.rbegin(), s.rend()
#define range(x,min,max) ((min) <= (x) && (x) <= (max))

using namespace std;

typedef long long LL;
typedef vector<int> VI;
typedef vector<vector<int> > VII;
typedef vector<string> VS;
typedef vector<bool> VB;
typedef pair<int,int> PII;

const int DX[]={1,0,-1,0},DY[]={0,-1,0,1};

int n, p;
int P;
VI cnt;

int check_winner(){
	rep(i, cnt.size()){
		if(cnt[i] == P) return i + 1;
	}
	return 0;
}

int solve(){
	P = p;
	int ans;
	rep(i, 1000000){
		rep(j, n){
			if(ans = check_winner()){
				return ans - 1;
			}else if(p == 0){
				p = cnt[j];
				cnt[j] = 0;
			}else{
				p--;
				cnt[j]++;
			}
		}
	}
	return 0;
}

int main(){
	cin.tie(0);
   	ios::sync_with_stdio(false);
	while(1){
		cnt.clear();
		cin >> n >> p;
		cnt.resize(n, 0);
		if(n == 0 && p == 0) break;
		
		cout << solve() << endl;
	}
}

Measured memory_bytes: 1196
var cnt = 0;
(function main(){
  const lines = require('fs').readFileSync('/dev/stdin', 'utf8').trim().split('\n');
  const n = Number(lines.shift());
  let arr = lines.shift().split(' ').map(Number);
  mergeSort(arr, 0, n);
  console.log(arr.join(' '));
  console.log(cnt);
})();

function merge(arr, left, mid, right) {
  let L = arr.slice(left, mid);
  let R = arr.slice(mid, right);
  L.push(Infinity);
  R.push(Infinity);
  let i = 0;
  let j = 0;
  for (let k = left; k < right; k++) {
    if (L[i] <= R[j]) arr[k] = L[i++];
    else arr[k] = R[j++];
    cnt++;
  }
}

function mergeSort(arr, left, right) {
  if (left + 1 < right) {
    let mid = Math.floor((left + right) / 2);
    mergeSort(arr, left, mid);
    mergeSort(arr, mid, right);
    merge(arr, left, mid, right);
  }
}



Measured memory_bytes: 108748
# include <bits/stdc++.h>
# define rep(i, n) for(int i=0, i##_len=(n); i<i##_len; ++i)
# define reps(i, n) for(int i=1, i##_len=(n); i<=i##_len; ++i)
# define rrep(i, n) for(int i=((int)(n)-1); i>=0; --i)
# define rreps(i, n) for(int i=((int)(n)); i>0; --i)
# define ALL(x) (x).begin(), (x).end()
# define RALL(x) (x).rbegin(), (x).rend()
# define SZ(x) ((int)(x).size())
# define pb push_back
# define optimize_cin() cin.tie(0); ios::sync_with_stdio(false)
# define debug(x) std::cerr<<#x<<": "<<(x)<<endl;
using namespace std;
using lint = long long;
template<class T> using grid = vector<vector<T>>;
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; }
static const lint MOD = (lint)1e9+7;

int main()
{
    int A, B;
    cin >> A >> B;

    if (B == 1)
    {
        cout << 0 << endl;
        return 0;
    }

    int kuti = A;
    int cnt = 1;
    while (!(kuti >= B))
    {
        kuti += A - 1;
        ++cnt;
    }

    cout << cnt << endl;

    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define int long long
#define all(sdk) sdk.begin(),sdk.end()
#define mll map<ll, ll>
#define pb push_back
#define lb lower_bound
#define ub upper_bound
#define rep(i,a,b) for(ll i=a;i<b;++i)
#define repd(i,a,b) for(ll i=a;i>=b;--i)
//#define mp make_pair
#define hell 1000000007
#define endl '\n'
#define vvll vector<vector<int> >
#define vll vector<int>
#define mint map<int,int>
#define sz(x) (int)x.size()
#define sll set<int>
#define pll pair<int,int>
#define F first
#define S second
#define INF 1e18
#define NINF -1e16

#define maxn 100005
int spf[maxn];
vll primes,prev[maxn],next[maxn];
set<int>s;
void sieve()
{
	rep(i,2,maxn)
	{
		if (spf[i]==0)
		{
			spf[i]=i;
			for(int j=2*i;j<=maxn;j+=i)
			{
				if(spf[j]==0)
					spf[j]=i;
			}
		}
	}
}
void SieveOfEratosthenes(int n) 
{ 
    bool prime[n+1]; 
    memset(prime, true, sizeof(prime)); 
  
    for (int p=2; p*p<=n; p++) 
    { 
        if (prime[p] == true) 
        { 
            for (int i=p*2; i<=n; i += p) 
                prime[i] = false; 
        } 
    }
    for (int p=2; p<=n; p++) 
    {
        if (prime[p]) 
        {
            primes.pb(p); 
            s.insert(p);
        }
    }    
} 
// bool isPrime(ll n) 
// { 
//     if (n <= 1) 
//         return false; 
//     if (n <= 3) 
//         return true; 
//     if (n % 2 == 0 || n % 3 == 0) 
//         return false; 
//     for (int i = 5; i * i <= n; i = i + 6) 
//         if (n % i == 0 || n % (i + 2) == 0) 
//             return false; 
//     return true; 
// } 
// ll power(ll x,ll y)
// {
//     ll X=x;
//     //X=X%p;//if x is greater than p
//     if(X==0)
//     {
//         return 0;
//     }
//     ll res=1ll;
//     while(y>0)
//     {
//         if(y&1)
//         {
//             res=((res)*(X));
//             y--;
//         }
//         y=y>>1;
//         X=((X)*(X));
//     }
//     // res=(res>=0)?(res%p):(res+p)%p;
//     return(res);
// }
// void dfs(int u, int par){
//     cnt[u] = 1;
//     p[u] = par;
//     for(int i : g[u]){
//         if(i != par){
//             dfs(i,u);
//             cnt[u] += cnt[i];
//         }
//     }
// }
// int children(vll v[],int parent,int src,vll& chil)
// {
// 	int ans =0;
// 	for(auto it:v[src])
// 	{
// 		if(it!=parent)
// 		{
// 			ans+= 1+children(v,src,it,chil);
// 		}
// 	}
// 	chil[src] = ans;
// 	return ans;
 
// }
bool cmp(const pair<int,int>&a,const pair<int,int>&b)
{
    if (a.F==b.F)
    return a.S<b.S;
    else
    return a.F>b.F;
}

signed main() {
	//freopen("output.txt","w",stdout);
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	srand (static_cast <unsigned> (time(0)));
// 	SieveOfEratosthenes(100005); 
// 	sort(all(primes));
    sieve();
	int t=1;
	//cin >> t;
	while (t--) 
	{
	    int n;
	    cin >> n;
	    vll h(n);
	    rep(i,0,n)
	    cin >> h[i];
	    vll dp(n,INT_MAX);
	    dp[0]=0;
	    rep(i,0,n)
	    {
	        rep(j,i+1,i+3)
	        {
	            if(j<n)
	            dp[j]=min(dp[j],dp[i]+abs(h[i]-h[j]));
	        }
	        
	    }
	    cout<<dp[n-1]<<endl;
	}
	return 0;
}

Measured memory_bytes: 10284
#include<bits/stdc++.h>
using namespace std;
#define rep(_,a,b) for(int _=a;_<b;_++)
#define per(_,a,b) for(int _=b-1;_>=a;_--)
#define pii pair<int,int>
#define fi first
#define se second
#define pb push_back
typedef long long ll;

int main()
{
    int l,r,d,ans=0;
    scanf("%d%d%d",&l,&r,&d);
    rep(i,l,r+1){
        if(i%d==0) ans++;
    }
    printf("%d",ans);
}


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

#define int ll
#define rep(i,n) for(int i=0,i##_cond=(n);i<i##_cond;++i)
#define FOR(i,a,b) for(int i=(a),i##_cond=(b);i<i##_cond;++i)
#define ROF(i,a,b) for(int i=(a)-1,i##_cond=(b);i>=i##_cond;--i)
#define sz(x) ((int)(x).size())
using ll  = long long;
using vi  = vector<int>;
template<class T>bool chmax(T &a, const T &b){if(a<b){a=b; return true;} return false;}

vi a;
int f(int x){
  int res = 0;
  rep(i,sz(a)) res += x ^ a[i];
  return res;
}  

signed main(){
  int n,k; cin >> n >> k; k++;
  a.resize(n); rep(i,n) cin >> a[i];

  // 最上位の1ビットが下から何桁目か(0ならどこも1ではない)
  int x = 0;
  ROF(i,40,0)
    if((k >> i) & 1){
      x = i+1;
      break;
    }

  // 各ビットを何にしたほうが良いか
  vi y(40);
  rep(i,n) rep(j,40){
    y[j] += (a[i] >> j) & 1;
  }
  rep(j,40){
    if(y[j] > n/2) y[j] = 0;
    else y[j] = 1;
  }

  int res = f(0);
  FOR(i,0,x){
    if(((k >> i) & 1) == 0) continue;
    int tmp = k;

    tmp -= (1ll << i);
    rep(j,i){
      if((tmp >> j) & 1) tmp -= (1ll << j);
      tmp += y[j] * (1ll << j);
    }
    chmax(res, f(tmp));
  }
  cout << res << endl;
}

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

int main() {
  int n; cin >> n;
  char tmp;
  for (int i = 0; i < n; i++) {
    cin >> tmp;
    if (tmp == 'Y') {
      cout << "Four"; return 0;
    }
  }
  cout << "Three";
  return 0;
}

Measured memory_bytes: 256
fun main(args: Array<String>) {
    val (q, h, s, d) = readLine()!!.split(" ").map { Integer.parseInt(it).toLong() }
    val n: Long = Integer.parseInt(readLine()!!).toLong()
    val first = listOf(q*8, h*4, s*2, d).withIndex().minBy{it.value}!!.index
    if (first == 3) {
        val second = listOf(q*4, h*2, s).withIndex().minBy{it.value}!!.index
        println((n / 2) * d + (n % 2) * listOf(q*4, h*2, s)[second])
    } else {
        println(listOf(q*4, h*2, s)[first] * n)
    }
}

Measured memory_bytes: 37872
#include "bits/stdc++.h"
#include "math.h"
 
using namespace std;
typedef long long ll;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef vector<vvll> vvvll;
typedef vector<bool> vb;
typedef vector<vb> vvb;
typedef vector<int> vin;
typedef vector<pair<ll,ll> > vp;
#define rep(i,a,b) for(ll i=(a);i<(b);++i)
#define drep(i,a,b) for(ll i=(a);i>(b);--i)
const int MOD = 1000000007;
const int MAX = 510000;

int main(){
  ll h,w,tmp=0,ans=0;cin>>h>>w;
  vector<string> masu(h);
  vvvll dp(2,vvll(h,vll(w,0)));
  rep(i,0,h){
    cin>>masu[i];
  }
  rep(i,0,h){
    vll c(1,0);
    ll tmp=0;
    rep(j,0,w){
      if(masu[i][j]=='.'){c[tmp]++;}
      else{tmp++;c.push_back(0);}
    }
    tmp=0;
    rep(j,0,w){
      if(masu[i][j]=='.'){dp[0][i][j]=c[tmp];}
      else{tmp++;}
    }
  }
  rep(i,0,w){
    vll c(1,0);
    ll tmp=0;
    rep(j,0,h){
      if(masu[j][i]=='.'){c[tmp]++;}
      else{tmp++;c.push_back(0);}
    }
    tmp=0;
    rep(j,0,h){
      if(masu[j][i]=='.'){dp[1][j][i]=c[tmp];}
      else{tmp++;}
    }
  }
  rep(i,0,h){
    rep(j,0,w){
      ans=max(ans,dp[0][i][j]+dp[1][i][j]);
    }
  }
  cout<<ans-1<<endl;
}



Measured memory_bytes: 94208
fun main(args : Array<String>) {
    var n = readLine()!!.toInt()

    var upper = readLine()!!.split(" ").map { it.toInt() }.toMutableList()
    var lower = readLine()!!.split(" ").map { it.toInt() }.toMutableList()

    for (i in 1 until n - 1)
        upper[i] += upper[i - 1]
    for (i in n - 2 downTo 0)
        lower[i] += lower[i + 1]

    println("%d".format(upper.zip(lower).map { it.first + it.second }.max()))
}


Measured memory_bytes: 37872
//@formatter:off
#include<bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < int(n); ++i)
#define rrep(i,n) for (int i = int(n)-1; i >= 0; i--)
#define rep2(i,s,n) for (int i = int(s); i < int(n); ++i)
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define pb push_back
#define eb emplace_back
#define vi vector<int>
#define vvi vector<vector<int>>
#define vl vector<ll>
#define vvl vector<vector<ll>>
#define vd vector<double>
#define vvd vector<vector<double>>
#define vs vector<string>
#define vc vector<char>
#define vvc vector<vector<char>>
#define vb vector<bool>
#define vvb vector<vector<bool>>
#define vp vector<P>
#define vvp vector<vector<P>>
using namespace std;
using ll = long long;
using P = pair<int,int>;
using LP = pair<ll,ll>;
template<class S,class T> istream& operator>>(istream &is,pair<S,T> &p) { return is >> p.first >> p.second; }
template<class S,class T> ostream& operator<<(ostream &os,const pair<S,T> &p) { return os<<'{'<<p.first<<","<<p.second<<'}'; }
template<class T> istream& operator>>(istream &is,vector<T> &v) { for(T &t:v){is>>t;} return is; }
template<class T> ostream& operator<<(ostream &os,const vector<T> &v) { os<<'[';rep(i,v.size())os<<v[i]<<(i==int(v.size()-1)?"":","); return os<<']'; }
void Yes(bool b) { cout << (b ? "Yes" : "No") << '\n'; }
void YES(bool b) { cout << (b ? "YES" : "NO") << '\n'; }
template<class T> bool chmin(T& a,T b) {if(a > b){a = b; return true;} return false;}
template<class T> bool chmax(T& a,T b) {if(a < b){a = b; return true;} return false;}
const int inf = 1001001001;
const ll linf = 1001001001001001001;
//@formatter:on

class unionfind {
    int n;
    vector<int> par, rank;
public:
    unionfind(int n) : n(n), par(n, -1), rank(n, 0) {}
    
    int root(int x) {
        if (par[x] < 0) return x;
        else return par[x] = root(par[x]);
    }
    
    bool same(int x, int y) { return root(x) == root(y); };
    
    bool merge(int x, int y) {
        x = root(x);
        y = root(y);
        if (x == y) return false;
        if (rank[x] < rank[y]) swap(x, y);
        if (rank[x] == rank[y]) rank[x]++;
        par[x] += par[y];
        par[y] = x;
        return true;
    }
    
    int size(int x) { return -par[root(x)]; };
    
    bool connected() {
        rep(i, n - 1) if (!same(i, i + 1)) return false;
        return true;
    }
};

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);
    int n, m;
    cin >> n >> m;
    unionfind uf(n);
    rep(i, m) {
        int a, b;
        cin >> a >> b;
        a--; b--;
        uf.merge(a, b);
    }
    int ans = -1;
    rep(i, n) {
        if (uf.root(i) == i) ans++;
    }
    cout << ans << endl;
}

Measured memory_bytes: 3992
N, K = map(int, input().split())
X = list(map(int, input().split()))
ans = float('inf')
for l in range(0, N-K+1):
    r = l + K - 1
    ans = min(ans, min(abs(X[l]), abs(X[r])) + abs(X[l] - X[r]))
print(ans)

Measured memory_bytes: 15020
# かぶっている時間を求める
# a<=cとするとd<bのときとc<b<dのときとb<c<dのときがある
a, b, c, d = gets.chomp.split.map(&:to_i)
a, c = [a, c].minmax
b, d = [b, d].minmax
if d<=b
  puts d-c
elsif c<=b && b<=d
  puts b-c
elsif b<=c && c<=d
  puts 0
end


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

ll N;

ll digit(ll n) {
    ll ret = 0;
    while (n != 0) {
        ret++;
        n /= 10;
    }
    return ret;
}

int main() {
    cin >> N;

    ll d = digit(N);
    if (N == (ll)pow(10, d) - 1) {
        cout << 9*d << endl;
    }
    else {
        ll a = N/(ll)pow(10, d-1);
        if (N%(ll)pow(10, d-1) == (ll)pow(10, d-1) - 1) {
            cout << a + 9*(d-1) << endl;
        }
        else {
            cout << a-1 + 9*(d-1) << endl;
        }
    }

    
    return 0;
}


Measured memory_bytes: 384
using System;
using System.Collections.Generic;
using System.Linq;

namespace abc057
{
    class Program
    {
        static void Main(string[] args)
        {
            var line1 = Console.ReadLine().Split(' ').Select(x => int.Parse(x)).ToArray();
            var S_Count = line1[0];
            var CP_Count = line1[1];

            var S_Posi = new List<int[]>();
            for (int i = 0; i < S_Count; i++)
            {
                S_Posi.Add(Console.ReadLine().Split(' ').Select(x => int.Parse(x)).ToArray());
            }

            var CP_Posi = new List<int[]>();
            for (int i = 0; i < CP_Count; i++)
            {
                CP_Posi.Add(Console.ReadLine().Split(' ').Select(x => int.Parse(x)).ToArray());
            }

            foreach (var s_posi in S_Posi)
            {
                var distance = CP_Posi.Select(x => Math.Abs(s_posi[0]-x[0]) + Math.Abs(s_posi[1] - x[1])).Select((x,i) => new { index = i,distance = x });
                var CP_No = distance.OrderBy(x => x.distance).ThenBy(x => x.index).First();
                Console.WriteLine(CP_No.index+1); 
            }

            //Console.ReadKey();
        }
    }
}


Measured memory_bytes: 13652
#[allow(unused_macros)]
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
    ($($r:tt)*) => {
        let s = {
            use std::io::Read;
            let mut s = String::new();
            std::io::stdin().read_to_string(&mut s).unwrap();
            s
        };
        let mut iter = s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
}

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

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

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

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

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

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

    ($iter:expr, $t:ty) => {
        $iter.next().unwrap().parse::<$t>().expect("Parse error")
    };
}
fn main() {
    input! {
        h: usize,
        w: usize,
        s: [chars; h],
    }
    let mut v = vec![vec!['.'; w+3]; h+2];
    for i in 0..h {
        for j in 0..w {
            v[i+1][j+1] = s[i][j];
        }
    }
    for i in 1..h+1 {
        for j in 1..w+1 {
            if v[i][j] == '#' && (
                v[i][j+1] == '.' &&
                v[i][j-1] == '.' &&
                v[i+1][j] == '.' &&
                v[i-1][j] == '.'
            ) {
                println!("No");
                return;
            }
        }
    }
    println!("Yes");
}

Measured memory_bytes: 4352
import sys
sys.setrecursionlimit(1000000)
N, u, v = map(int, input().split())
G = {k: [] for k in range(N+1)}
for _ in range(N-1):
    a, b = map(int, input().split())
    # 無向グラフ
    G[a].append(b)
    G[b].append(a)


def dfs(ci, d, p, dist):
    dist[ci] = d
    for ni in G[ci]:
        if ni == p:
            continue
        dfs(ni, d+1, ci, dist)


def calcDist(start):
    dist = [-1]*(N+1)
    dfs(start, 0, -1, dist)
    return dist


distU = calcDist(u)
distV = calcDist(v)

ans = 0
for i in range(1, N+1):
    if distU[i] < distV[i]:
        ans = max(ans, distV[i]-1)
print(ans)


Measured memory_bytes: 110056