akhauriyash/Code-Regression huggingface dataset:
using System;
using System.Collections.Generic;
using System.Collections.Specialized;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using static System.Console;

namespace ABC81_C
{
    class Program
    {
        static void Main(string[] args)
        {
            var s = ReadLine().Split();
            int n = int.Parse(s[0]);
            int k = int.Parse(s[1]);
            var a = ReadLine().Split().Select(int.Parse).ToArray();
            var d = new Dictionary<long, long>();
            var l = new List<long>();
            long u = 0;

            for (int i = 0; i < n; i++)
            {
                if (!d.ContainsKey(a[i]))
                {
                    d[a[i]] = 0;
                    u++;
                }
                d[a[i]] += 1;
            }
            foreach (var item in d)
            {
                l.Add(item.Value);
            }
            l.Sort();
            long uu = u - k;
            long count = 0;
            for (int i = 0; i < uu; i++)
            {
                count += l[i];
            }
            WriteLine(count);
        }
    }
}


Measured memory_bytes: 44228
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
typedef pair<int, int> P;
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; }

string s;

int main(){
  cin >> s;
  int n = s.size();
  int res = 0;
  for(int i = 0; i < n; i++){
    for(int j = i; j < n; j++){
      char c = s.at(j);
      if(c != 'A' && c != 'G' && c != 'C' && c != 'T') break;
      chmax(res, j - i + 1);
    }
  }
  cout << res << endl;
  
}


Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <cmath>
using namespace std;

int main()
{
	int N;
	int n = 1;
	while (cin >> N, N)
	{
		double x[64], y[64];
		for (int i=0; i<N; i++)
			cin >> x[i] >> y[i];

		double ans = 0.0;
		for (int i=0; i<N; i++)
			ans += x[i]*y[(i+1)%N]-x[(i+1)%N]*y[i];

		cout << n++ << ' ' << setprecision(1) << setiosflags(ios::fixed) << -ans/2.0 << endl;
	}
}

Measured memory_bytes: 0
n=int(input())
t,a=list(map(int, input().split()))
l=list(map(int, input().split()))
new=[]
for i in l:
  new.append(t-(i*(6/1000)))
for i in range(n):
  new[i]-=a
  new[i]=abs(new[i])
print(new.index(min(new))+1)

Measured memory_bytes: 3188
#include<iostream>
#include<vector>
#include<map>
#include<utility>
#define USED 100000000000
using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
int main(){
  ll n,ans,tmp_c=0,p,q;
  map<P,ll> mp;
  bool no_cost;
  cin >> n;
  ll x[n],y[n];
  for(int i=0;i<n;i++){
    cin >> x[i] >> y[i];
  }
  for(int i=0;i<n;i++){
    for(int j=0;j<n;j++){
      if(i==j)continue;
      mp[P(x[i]-x[j],y[i]-y[j])]++;
    }
  }
  for(auto i=mp.begin();i!=mp.end();i++){
    tmp_c=max(tmp_c,i->second);
  }
  cout << n-tmp_c<<endl;
}


Measured memory_bytes: 384
//    https://youtu.be/zRIbf6JqkNc

#include<bits/stdc++.h>
using namespace std;

typedef long long ll;
typedef long double ld;
typedef long long unsigned llu;
typedef pair<long long, long long> pll;
const long long inf = 2000000000000000000LL;	// 2e18
#define pi                  acos(-1.0)
#define fast                ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define shesh               "\n"
#define ff                  first
#define ss                  second
#define pb                  push_back
#define bp                  pop_back
#define pf                  push_front
#define fp                  pop_front
#define ub                  upper_bound
#define lb                  lower_bound
#define all(x)              x.begin(), x.end()
#define debug(x)            cout<<"debug "<<x<<"\n"
#define mest(a,b)           memset(a,b,sizeof(a))
vector<pair<ll,ll> >v;
ll dp[10010];
ll solve(ll h){
    if(h<=0) return (ll)0;
    if(dp[h]!=-1) return dp[h];
    ll i,temp=inf;
    for(i=0;i<v.size();i++){
        temp=min(temp,v[i].ss+solve(h-v[i].ff));
    }
    dp[h]=temp;
    return dp[h];
}
int main(){
    fast;
    ll t,n,m,i,j,k,temp,flag,ans,h;
    memset(dp,-1,sizeof(dp));
    cin>>h>>n;
    for(i=0;i<n;i++){
        cin>>j>>k;
        v.pb({j,k});
    }
    sort(all(v));
    cout<<solve(h);
    return 0;
}


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

#define mod      1e9+7;
#define INF      1e9+9;
#define ps(x,y)  fixed<<setprecision(y)<<x
# define PI 3.14159265358979323846264338327950 L
typedef long long ll;
typedef unsigned long long ull;
int main()
{
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
#ifndef ONLINE_JUDGE
	//freopen("input.txt","r",stdin);
	//freopen("output.txt","w",stdout);
#endif
	int n,k;
	cin>>n>>k;
	int a[n];
	for(int i=0;i<n;i++){
		cin>>a[i];
	}
	int dp[n];
	for(int i=0;i<n;i++)
		dp[i]=INT_MAX;
	dp[0]=0; dp[1]=abs(a[1]-a[0]);
	for(int i=2;i<n;i++){
		for(int j=1;j<=k && i-j>=0; j++){
			dp[i]=min(dp[i],dp[i-j]+abs(a[i]-a[i-j]));
			//cout<<dp[i]<<endl;
		}
		//cout<<endl;
	}
	//for(int i=0;i<n;i++)
	//	cout<<dp[i]<<" ";
	cout<<dp[n-1]<<endl;
	return 0;
}

Measured memory_bytes: 4364
#include<stdio.h>
int main (void)
{
	int a,b,c,i,k,tmp=2;
	int p[256],j=1;
	scanf("%d %d %d",&a,&b,&k);
	c=a;
	p[0]=1;
	if(a>b)
	{
		c=b;
	}
	
	for(i=2;i<=c;i++){
	if(a%i==0&&b%i==0)
	{
		p[j]=i;
		tmp++;
		j++;
	}
}

printf("%d",p[j-k]);
return 0;
}

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

using namespace std;

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

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

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

	int n;
	cin >> n;
	string s;
	cin >> s;

	int ecnt = 0;
	int wcnt = 0;

	rep(i, s.size()) {
		if (s[i] == 'E') ecnt++;
		else wcnt++;
	}

	int ans = inf;
	int leftCnt = 0;
	// i番目の人をリーダーとする
	rep(i, n) {
		int temp = 0;
		// west = 西　east = 東
		// i番目より西の人は東を向かなきゃならない
		// i番目より東の人は西を向かなきゃならない
		temp += leftCnt;
		if (s[i] == 'W') {
			temp += ecnt;
			leftCnt++;
		}
		else {
			ecnt--;
			temp += ecnt;
		}
		ans = min(ans, temp);
	}

	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 720
#include<stdio.h>
#define ll long long
ll pom(ll a,ll n,int m){ll x=1;for(a%=m;n;n/=2)n&1?x=x*a%m:0,a=a*a%m;return x;}
#define MOD 998244353

int main(){
	int n;
	scanf("%d",&n);
	ll ans=0;
	for(int i=0;i<n;i++){
		int x;
		scanf("%d",&x);
		ans=(ans+pom(2,n-1-i,MOD)*x%MOD*pom(x+1,i,MOD))%MOD;
	}
	printf("%d\n",ans);
}


Measured memory_bytes: 2092
import java.util.*;
import java.io.*;
import static java.lang.Math.*;

class Main {

    public static void main( final String[] args ) {

	final Scanner stdin = new Scanner( System.in );

	while ( true ) {

	    final int w = stdin.nextInt();
	    final int h = stdin.nextInt();

	    if ( w == 0 && h == 0 ) {
		break;
	    }

	    boolean[][] map = new boolean[ h ][ w ];

	    for ( int i = 0; i < h; i++ ) {
		for ( int j = 0; j < w; j++ ) {
		    map[ i ][ j ] = ( stdin.nextInt() == 1 );
		}
	    }

	    int count = 0;
	    for ( int i = 0; i < h; i++ ) {
		for ( int j = 0; j < w; j++ ) {
		    if ( dfs( map, i, j ) > 0 ) {
			count++;
		    }
		}
	    }
	    System.out.println( count );
	}	
    }

    static int[] dx = { 1, 1, 1, 0, -1, -1, -1, 0 };
    static int[] dy = { -1, 0, 1, 1, 1, 0, -1, -1 };
    
    static int dfs( final boolean[][] map, final int y, final int x ) {
	int count = 0;
	if ( map[ y ][ x ] ) {
	    count++;
	    map[ y ][ x ] = false;
	}
	for ( int i = 0; i < 8; i++ ) {
	    final int ny = y + dy[ i ];
	    final int nx = x + dx[ i ];

	    if ( 0 <= nx && nx < map[ 0 ].length &&
		 0 <= ny && ny < map.length &&
		 map[ ny ][ nx ] ) {

		count += dfs( map, ny, nx );		
	    }
	}
	return count;
    }    
}

Measured memory_bytes: 43132
/*+lmake
 * STD = c++14
 * DEFINE += WAAUTOMATON
 */
#include <bits/stdc++.h>
using namespace std;
using LL=long long;
using ULL=unsigned long long;
#ifdef WAAUTOMATON
#define debug(args...)                                                                             \
    {                                                                                              \
        dbg, args;                                                                                 \
        cerr << endl;                                                                              \
    }
#define massert(x) assert(x)
#else
#define debug(args...) // Just strip off all debug tokens
#define massert(x)
#endif
struct debugger
{
    template<typename T> debugger& operator , (const T& v)
    {    
        cerr<<v<<" ";    
        return *this;    
    }
} dbg;

LL a[100001];
int main(){	
#ifdef WAAUTOMATON
	//freopen("in.txt","r",stdin);
#endif
	int n;
	LL c,k;
	cin>>n;
	for(int i=1; i<=n; ++i) {
		cin>>a[i];
	}
	sort(a+1,a+1+n);
	LL sum=0;
	int p=1;
	for(int i=1; i<n; ++i) {
		sum+=a[i];
		if (sum*2<a[i+1]) p=i+1;
	}
	cout<<(n-p+1)<<endl;
	return 0;
}


Measured memory_bytes: 1024
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Scanner;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        Scanner in = new Scanner(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        TaskC solver = new TaskC();
        solver.solve(1, in, out);
        out.close();
    }

    static class TaskC {
        public void solve(int testNumber, Scanner in, PrintWriter out) {
            int n = in.nextInt();
            int m = in.nextInt();
            int ans = (int) Math.pow(2, m) * (((m * 1900)) + ((n - m) * 100));
            out.println(ans);
        }

    }
}



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

class Program {
    static void Main() {
        string[] stdin = Console.ReadLine().Split();
        int r = int.Parse(stdin[0]);
        int c = int.Parse(stdin[1]);
        List<List<int>> sheet = new List<List<int>>();
        for(int i = 0; i < r; i++) {
            sheet.Add(Console.ReadLine().Split().Select(s => int.Parse(s)).ToList());
            sheet[i].Add(sheet[i].Sum());
            Console.WriteLine(string.Join(" ", sheet[i]));
        }
        for(int i = 0; i <= c; i++) {
            int ans = 0;
            for(int j = 0; j < r; j++) ans += sheet[j][i];
            Console.Write("{0}{1}", ans, i == c? '\n' : ' ');
        }
    }
}


Measured memory_bytes: 18492
#include<iostream>
#include<cstdio>
#include<cmath>
#include<algorithm>
#include<string>
#include<cstring>
#include<cstdlib>
using namespace std;
int a,b,h;
int main()
{
  cin>>a>>b>>h;
  cout<<(a+b)*h/2<<endl;
  return 0;
}


Measured memory_bytes: 256
fn read<T: std::str::FromStr>(
    stdin_lock: &mut std::io::StdinLock,
    buf: &mut Vec<u8>,
    delimiter: u8,
) -> T {
    buf.clear();
    let l = std::io::BufRead::read_until(stdin_lock, delimiter, buf).unwrap();
    buf.truncate(l - 1); // remove delimiter
    let s = unsafe { std::str::from_utf8_unchecked(&buf) };
    s.parse().unwrap_or_else(|_| panic!("read"))
}

fn main() {
    let stdin = std::io::stdin();
    let mut stdin_lock = stdin.lock();
    let mut buf: Vec<u8> = Vec::new();
    let a: u16 = read(&mut stdin_lock, &mut buf, b' ');
    let b: u16 = read(&mut stdin_lock, &mut buf, b' ');
    let c: u16 = read(&mut stdin_lock, &mut buf, b'\n');
    let mut vs: Vec<u16> = vec![a, b, c];
    vs.sort();
    let ans = vs[2] - vs[0];
    println!("{}", ans);
}


Measured memory_bytes: 4352
#include <cstdio>
#include <cstring>
#include <string>
#include <iostream>
#include <algorithm>

std:: string s1, s2;

int main() {
	std::cin >> s1 >> s2;
	int len = s1.length(), ans = 0;
	for (int i = 0; i < len; ++i) {
		if (s1[i] != s2[i]) ++ans;
	}
	printf("%d\n", ans);
	return 0;
}

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

signed main(){
    int n,a;
    cin>>n;
    int iro[9]={};
    for(int i=0;i<n;i++){
        cin>>a;
        if(a>=3200)iro[8]++;
        else iro[a/400]++;
    }
    int ans1=0;
    for(int i=0;i<8;i++){
        if(iro[i]!=0){
            ans1++;
            
        }
    }
    cout <<max(ans1,1) <<' ' << ans1+iro[8];
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <stack>
#include <cctype>
#include <algorithm>
#include <vector>
#include <map>
#include <cmath>
#include <stdlib.h>
#include <tuple>
#include <iomanip>
#include <iterator>
#include <stdio.h>
using namespace std;
const double PI = 3.14159265358979323846;


int main() {
    string s;
    cin >> s;

    char buffer[2][200000];
    int index[2] = { 0,0 };

    int control = 0;

    int Q;
    cin >> Q;

    for (int i = 0; i < Q; i++) {
        int T;
        cin >> T;

        if (T == 1) {
            control++;
        }
        else {
            int F;
            cin >> F;
            char C;
            cin >> C;

            int id = (control + (F - 1)) % 2;
            buffer[id][index[id]] = C;
            index[id]++;
        }
    }

    for (int i = index[control % 2] - 1; i >= 0; i--) {
        cout << buffer[control % 2][i];
    }

    if (control%2 == 0) {
        cout << s;
    }
    else {
        auto c_str = s.c_str();
        int size = s.size();

        for (int i = size - 1; i >= 0; i--) {
            cout << c_str[i];
        }
    }

    for (int i = 0; i < index[(control + 1) % 2]; i++) {
        cout << buffer[(control + 1) % 2][i];
    }
    return 0;
}

Measured memory_bytes: 1024
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
#define USE_LLONG_AS_INT
#ifdef USE_LLONG_AS_INT
#define int long long
#define inf (1ll<<60)
#else
#define inf (1<<30)
#endif
#define rep(i,n) for(int i=0;i<n;i++)
#define Rep(i,a,b) for(int i=a;i<b;i++)
#define REP(i,a,b) for(int i=a;i<=b;i++)
#define rev(i,n) for(int i=n-1;i>=0;i--)
#define vi vector<int>
#define vvi vector<vi>
#define pb push_back
#define pi pair<int,int>
#define vp vector<pair<int,int>>
#define mp make_pair
#define all(v) (v).begin(),(v).end()
#define fi first
#define se second
#define MEMSET(a) memset(a,0,sizeof(a))
#define Yes(f) cout<<(f?"Yes":"No")<<endl
#define yes(f) cout<<(f?"yes":"no")<<endl
#define YES(f) cout<<(f?"YES":"NO")<<endl
#define SORT(v) sort(all(v))
#define RSORT(v) sort(all(v), greater<int>())

using namespace std;

const int mod=1e9+7;
const string sp=" ";

void run();

void init() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout<<fixed<<setprecision(12);
}

signed main(){
    init();
    run();
    return 0;
}

void run(){
	string s;
	cin>>s;
	int n=s.length();
	int ans=n*(n-1)/2+1;
	vi c(26);
	rep(i,n)c[s[i]-'a']++;
	rep(i,26)ans-=c[i]*(c[i]-1)/2;
	cout<<ans<<endl;
}

Measured memory_bytes: 720
def main():
    n = int(input())

    ans = 0
    for i in range(1, n//2 + 1):
        ans += i * (n//i) * (n//i + 1) // 2

    ans += (n + n//2 + 1) * (n - n//2) // 2

    print(ans)

main()

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

#define ALL(c) c.begin(), c.end()
#define SZ(c) ((int)c.size())
#define REP(i, n) for (int i = 0, loop_num_##i = n; i < loop_num_##i; i++)


template<class Abel> struct UnionFind {
    vector<int> par;
    vector<int> rank;
    vector<Abel> diff_weight;

    UnionFind(int n = 1, Abel SUM_UNITY = 0) {
        init(n, SUM_UNITY);
    }

    void init(int n = 1, Abel SUM_UNITY = 0) {
        par.resize(n); rank.resize(n); diff_weight.resize(n);
        for (int i = 0; i < n; ++i) par[i] = i, rank[i] = 0, diff_weight[i] = SUM_UNITY;
    }

    int root(int x) {
        if (par[x] == x) {
            return x;
        }
        else {
            int r = root(par[x]);
            diff_weight[x] += diff_weight[par[x]];
            return par[x] = r;
        }
    }

    Abel weight(int x) {
        root(x);
        return diff_weight[x];
    }

    bool issame(int x, int y) {
        return root(x) == root(y);
    }

    bool merge(int x, int y, Abel w) {
        w += weight(x); w -= weight(y);
        x = root(x); y = root(y);
        if (x == y) return false;
        if (rank[x] < rank[y]) swap(x, y), w = -w;
        if (rank[x] == rank[y]) ++rank[x];
        par[y] = x;
        diff_weight[y] = w;
        return true;
    }

    Abel diff(int x, int y) {
        return weight(y) - weight(x);
    }
};
// quoted from: https://qiita.com/drken/items/cce6fc5c579051e64fab

signed main() {
	while (1) {
		int N, M;
		cin >> N >> M;
		if (N == 0 && M == 0) break;
		UnionFind<int> uf(N);
		REP(i, M) {
			char q;
			cin >> q;
			int a, b, w;
			if (q == '!') {
				cin >> a >> b >> w;
				a--, b--;
				uf.merge(a, b, w);
			} else {
				cin >> a >> b;
				a--, b--;
				if (uf.issame(a, b)) {
					cout << uf.diff(a, b) << endl;
				} else {
					cout << "UNKNOWN" << endl;
				}
			}
		}
	}
}



Measured memory_bytes: 5216
/*
 * 16-10-15_ABC046_C.cpp
 *
 *  Created on: 2016/10/15
 *      Author: ryoma
 */

#include<iostream>
#include<algorithm>

using namespace std;

long long x=1,y=1;
int main(){
	int N;
	cin >> N;
	for(int i=0;i<N;i++){
		long long T,A;
		cin >> T >> A;
		long long n = max((x-1)/T,(y-1)/A)+1;
		x = n*T;
		y = n*A;
	}
	cout << x+y<<endl;
	return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
int main(){
  int a,b,c,k;
  scanf("%d%d%d%d",&a,&b,&c,&k);
  if(k<=a){
    printf("%d\n",k);
  }
  else if(k<=a+b){
    printf("%d\n",a);
  }
  else{
    printf("%d\n",a-1*(k-a-b));
  }
  return 0;
}



Measured memory_bytes: 1732
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define FOR(i,a,b) for(int i=a;i<=b;i++)
#define FORD(i,a,b) for(int i=a;i>=b;i--)
#define ALL(a)  (a).begin(),(a).end()
#define SZ(a) int((a).size())
#define SORT(c) sort((c).begin(),(c).end())
#define PB push_back
#define MP make_pair
#define MEMSET(v, h) memset((v), h, sizeof(v))
#define sqr(x)  ((x) * (x)) 
#define cub(x)  ((x) * (x) * (x))
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
// int gcd(int a,int b){return b?gcd(b,a%b):a;}

int main() {
  int n; cin >> n;
  string a,b; cin >> a >> b;

  string ans;

  FOR(i,0,n-1){
    ans += a[i];
    ans += b[i];
  }

  cout << ans << endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define f(a,n) for(ll i=a;i<n;i++)
#define ll long long
#define pb push_back
#define mp make_pair
#define X first
#define Y second
#define all(v) v.begin(),v.end()
using namespace std;
const ll mod=(1e+9)+7;
const ll size = 2e5+9;
ll gcd(ll a,ll b) {if(b==0)return a;return gcd(b,a%b);}
ll power(ll a,ll b,ll m = mod) {ll res = 1;while(b>0){if(b&1)res = (res*a)%m;b = b>>1;a = (a*a)%m;}return res;}


void solve()
{
    ll n;
    cin>>n;
    ll a[n];
    f(0,n)
    cin>>a[i];
    sort(a,a+n);
    cout<<abs(a[0]-a[n-1])<<endl;

}

int main()
{
    #ifdef JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
    #endif
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    clock_t beg = clock();
    solve();
    clock_t end = clock();
    fprintf(stderr, "%.3f sec, Copyright %c 2019 Skyscraper. \n", double(end - beg) / CLOCKS_PER_SEC , 184);
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <fstream>
#include <cstdio>
#include <cmath>
#include <vector>
#include <string>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <deque>
#include <bitset>
#include <algorithm>
#include <complex>
#include <array>
#include <iomanip>
using namespace std;

#define REP(i,n) for(int i=0; i<n; ++i)
#define FOR(i,a,b) for(int i=a; i<=b; ++i)
#define FORR(i,a,b) for (int i=a; i>=b; --i)
#define ALL(c) (c).begin(), (c).end()

typedef long long ll;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef vector<long double> VD;
typedef vector<VI> VVI;
typedef vector<VL> VVL;
typedef vector<VD> VVD;
typedef pair<int,int> P;
typedef pair<ll,ll> PL;

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

int in() { int x; scanf("%d", &x); return x; }
ll lin() { ll x; scanf("%lld", &x); return x; }
#define INF 1LL<<60

void dfs(int cur_x, int cur_y, vector<vector<int> >& c, vector< vector<bool> >& visited, int H, int W) {
    visited[cur_y][cur_x] = true;
    for(int dx=-1; dx<=1; dx++)
        for(int dy=-1; dy<=1; dy++)
            if(
            (dx !=0 || dy != 0)
            && (cur_x+dx>=0)
            && (cur_x+dx<W)
            && (cur_y+dy>=0)
            && (cur_y+dy<H)
            && c[cur_y+dy][cur_x+dx] == 1
            && !visited[cur_y+dy][cur_x+dx]) {
                dfs(cur_x+dx, cur_y+dy, c, visited, H, W);
            }
}

int main() {
    while(1) {
        int W, H;
        cin >> W >> H;
        if(W==0 && H==0) break;
        vector<vector<int> > c(H, vector<int>(W));
        vector<vector<bool> > visited(H, vector<bool>(W, false));
        REP(i, H)
            REP(j, W) cin >> c[i][j];

        int ans = 0;
        REP(i, H)
            REP(j, W)
                if(!visited[i][j] && c[i][j] == 1) {
                    ans++;
                    dfs(j, i, c, visited, H, W);
                }
        cout << ans << endl;
    }
    return 0;
}


Measured memory_bytes: 3356
from collections import Counter
from itertools import accumulate


def solve(string):
    n, m, *a = map(int, string.split())
    d = Counter(_a % m for _a in accumulate([0] + a))
    return str(sum(v * (v - 1) // 2 for v in d.values()))


if __name__ == '__main__':
    print(solve('\n'.join([input(), input()])))


Measured memory_bytes: 15524
import java.util.*;
public class Main{
  public static void main(String[] args){
    try{
      Scanner scanner = new Scanner(System.in);
      int N = scanner.nextInt();
      if(N%(findSumOfDigits(N))==0){
        System.out.println("Yes");
      }else{
        System.out.println("No");
      }
      scanner.close();
    }catch(Exception e){
      System.out.println("何か入力してください");
    }
  }
  public static int findSumOfDigits(int n){
    int sum = 0;
    while(n>0){
      sum += n%10;
      n /= 10;
    }
    return sum;
  }
}


Measured memory_bytes: 21844
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

int cmpfunc (const void * a, const void * b) {
   return strcmp(*(const char**)a,*(const char**)b );
}

int main(){
	char str[5000]="";
	scanf("%s",str);
	int K,rank=0;
	scanf("%d",&K);
	char **arr=malloc(sizeof(char*)*K*strlen(str));
	for(int i=0;i<strlen(str);i++){
		for(int j=0;j<K;j++){
			for(int l=0;l<K;l++){ arr[K*i+j]=malloc(sizeof(char)*K); }
			for(int l=0;l<=j;l++) arr[K*i+j][l]=str[l+i];
		}
	}
	qsort(arr,K*strlen(str),sizeof(*arr),cmpfunc);
	for(int i=0;rank<K;i++){ if(i==0||(i>0 && strcmp(arr[i],arr[i-1]))) rank++; if(rank==K) printf(arr[i]); }
	return 0;
}


Measured memory_bytes: 4476
#include <bits/stdc++.h>
using namespace std;
#define int long long int
#define pb push_back
#define N 500100
#define MOD 1000000007
#define fn(i,n) for(int i=0;i<n;i+=1)
#define rep(i,l,r) for(int i=l;i<=r;i+=1)
#define INF 100000000000000
#define pii pair<int,int>
#define speed ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
int power(int x,int y){
    int res=1LL;
    while(y){
        if(y&1){
            res=(res*x)%MOD;
        }
        x=(x*x)%MOD;
        y=(y>>1);
    }
}


signed main()
{
    
    speed
    int n,r;cin>>n>>r;
    int cnt=0;
    while(n){
        cnt+=1;
        n=n/r;
    }
    cout<<cnt<<endl;

    

    
    return 0;
}

Measured memory_bytes: 256
#include "iostream"
#include "climits"
#include "list"
#include "queue"
#include "stack"
#include "set"
#include "functional"
#include "algorithm"
#include "string"
#include "map"
#include "unordered_map"
#include "unordered_set"
#include "iomanip"
#include "cmath"
#include "random"
#include "bitset"
#include "cstdio"
#include "numeric"
#include "cassert"

using namespace std;

//const long long int MOD = 1000000007;
const int MOD = 1000000007;
//const int MOD = 998244353;
//const long long int MOD = 998244353;
const double EPS = 1e-8;

int N, M, K, H, W, L, R;
//long long int N, M, K, H, W, L, R;


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

	cin >> N;
	int box = 1;
	while (box < N)box <<= 1;
	if (box == N) {
		cout << "No\n";
		return 0;
	}
	cout << "Yes\n";
	cout << 1 << " " << 2 << endl;
	cout << 2 << " " << 3 << endl;
	cout << 3 << " " << N + 1 << endl;
	cout << N + 1 << " " << N + 2 << endl;
	cout << N + 2 << " " << N + 3 << endl;
	for (int i = 4; i <= N - 1; i += 2) {
		cout << 1 << " " << i << endl;
		cout << i << " " << i + 1 << endl;
		cout << 1 << " " << N + i + 1 << endl;
		cout << N + i + 1 << " " << N + i << endl;
	}
	if (N % 2 == 0) {
		for (int i = 2; i < N; i += 2) {
			int box = N ^ 1 ^ i;
			if (box < N) {
				cout << i << " " << N << endl;
				cout << box + N << " " << 2 * N << endl;
				return 0;
			}
		}
	}
}

Measured memory_bytes: 2304
#include <algorithm>
#include <bitset>
#include <complex>
#include <cstdio>
#include <cstdint>
#include <cassert>
#include <cmath>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <limits>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <tuple>
#include <utility>
#include <vector>
using namespace std;

using int64 = int64_t;

constexpr int64 MOD = 1000000007;

int main() {
    int64 X;
    cin >> X;
    int64 x = 1;
    while (x * (x+1) / 2 < X) { ++x; }
    cout << x << endl;
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include<math.h>
using namespace std;

int main() {
	unsigned long long int a,b,x,ret=0,tmp;
	cin >> a >> b >> x;
	ret = b / x - a / x;
	if (a % x == 0) {
		ret++;
	}
	cout << ret;
	return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<algorithm>
#include<set>
#include<map>
#include<queue>
#include<cmath>
#include<iomanip>
#include<cstring>
#include<cstdio>
#define initdp(a,b) for(int i=0;i<=a;i++)for(int j=0;j<=b;j++)dp[i][j]=-1;
#define fi first
#define se second
#define pb push_back
#define pii pair<int,int>
#define ppi pair<pii,int>
#define pip pair<int,pii>
#define ll long long
#define pll pair<ll,ll>
#define rep(i,n) for(int i=0;i<n;i++)
#define repd(i,n) for(int i=n-1;i>=0;i--)
#define inf 1000000001
#define inf1 1000000000000000001
#define mod 1000000007
#define pie 3.14159265358979323846
#define N 1000005
#define mid(l,r) l+(r-l)/2
using namespace std;
int dx[4]={1,0,-1,0},dy[4]={0,1,0,-1};
int ddx[8]={1,1,0,-1,-1,-1,0,1},ddy[8]={0,1,1,1,0,-1,-1,-1};
void mad(ll &a,ll b){a=(a+b)%mod;if(a<0)a+=mod;}
ll gcd(ll a,ll b){ if(!a)return b;return gcd(b%a,a);}

void solve(){
	ll n;
	cin>>n;
	ll a[n];
	rep(i,n)cin>>a[i];
	ll ans=0;
	for(int i=1;i<n;i++){
		if(a[i]<a[i-1]){
			ans+=a[i-1]-a[i];
			a[i]=a[i-1];
		}
	}
	cout<<ans;
}
int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	int t;
	//cin>>t;
	t=1;
	while(t--){
		solve();
	}
}

Measured memory_bytes: 5200
#include "bits/stdc++.h"
using namespace std;

/* macro */
#define rep(i,a,b) for(int i=a;i<b;i++)
#define revrep(i,a,b) for(int i = a; i > b; i--)
#define int long long
#define exist(s,e) ((s).find(e)!=(s).end())
#define all(v) (v).begin(), (v).end()
#define each(s,itr) for(auto (itr) = s.begin(); (itr) != s.end(); (itr)++)
#define sum(v) accumulate(all(v), (0LL))
#define isin(a, b, c) (b <= a && a <= c)
#define println cout << "\n";
#define sz(v) (int)v.size()


/* alias */
template<class T> using vec = vector<T>;
typedef vector<int> vi;
typedef pair<int, int> pi;
typedef tuple<int, int, int> ti;
typedef map<int, int> mi;
typedef set<int> si;


/* constant */
const int inf = 1LL << 62;
const int mod = 1e9 + 7;
const int dx[8]={1,0,-1,0,-1,1,-1,1};
const int dy[8]={0,1,0,-1,-1,-1,1,1};
const string alphabet = "abcdefghijklmnopqrstuvwxyz";

/* io_method */
int input(){int tmp;cin >> tmp;return tmp;}
string raw_input(){string tmp;cin >> tmp;return tmp;}
template<class T> void printx(T n){cout << n;}
template<class T, class U> void printx(pair<T, U> p){cout << "(" << p.first << "," << p.second << ")";}
template<class T, class U, class V> void printx(tuple<T, U, V> t){cout << "{" << get<0>(t) << "," << get<1>(t) <<"," << get<2>(t) << "}" << endl;}
template<class T> void printx(vector<T> v){cout << "{";rep(i,0,v.size()){printx(v[i]);if(i != v.size()-1)printx(",");}cout << "}";}
template<class T> void print(T n){printx(n);cout << endl;}
template<class T> void print(set<T> s){cout << "{";each(s, e){if(e != s.begin()) printx(",");printx(*e);}cout << "}" << endl;}
template<class T, class U> void print(map<T, U> mp){cout << "{";each(mp, e){cout << "(" << e -> first << "," << e -> second << ")";}cout << "}" << endl;}
template<class T> void printans(vec<T> v){rep(i,0,sz(v)){cout << v[i] << (i == sz(v) - 1 ? "" : " ");}cout << endl;}


/* general_method */
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 cut(T &a, int l, int r){return T(a.begin()+l, a.begin()+r);}

/* main */

int a, b, c, d;
void in(){
    cin >> a >> b >> c >> d;
}

void solve(){

    print(min(a, b) + min(c, d));


}

signed main(){

    cin.tie(0);
    ios::sync_with_stdio(false);
    in();
    solve();
    
}

Measured memory_bytes: 256
K, N = list(map(int, input().split()))
a = list( map( int, input().split() ) )
for i in range(N):
  a.append( a[i] + K )

d = []
for i in range(N):
  d.append( a[i+1] - a[i] )

max_index = d.index(max(d))

print(a[max_index + N] - a[max_index + 1])

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

struct info{
    ll first;
    ll second;
    ll third;
    info(ll f, ll s, ll t){
        first = f; second = s; third = t;
    }
};

int main(){
    ll n;
    cin >> n;
    // first node, second length
    vector<vector<pair<ll, ll>>> g(n+1);
    vector<ll> ans(n+1, -1);
    rep(i, 0, n-1){
        ll u, v, w;
        cin >> u >> v >> w;
        g[u].push_back({v, w});
        g[v].push_back({u, w});
    }
    
    // first parent, second child, third length;
    queue<info> que;
    ans[1] = 0;
    for(auto p : g[1]){
        info tmp(1, p.first, p.second);
        que.push(tmp);
    }
    while(!que.empty()){
        auto q = que.front();
        que.pop();
        if(ans[q.second] != -1) continue;
        ans[q.second] = (ans[q.first] + q.third%2)%2;
        for(auto p : g[q.second]){
            if(ans[p.first] == -1){
                info tmp(q.second, p.first, p.second);
                que.push(tmp);
            }
        }
    }

    rep(i, 1, n+1){
        cout << ans[i] << endl;
    }
    return 0;
}

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

int main(){
  string s;
  cin >> s;

  int n = s.size();
  int64_t ans = 0;
  for (int i = 0; i < (1 << (n - 1)); i++){
    bitset<10> op(i);
    op.set(n - 1, 1);
    int bg = 0;
    for (int j = 0; j < n; j++){
      if (op.test(j)){
        string t = s.substr(bg, j - bg + 1);
        int64_t p = stoll(t);
        ans += p;
        bg = j + 1;
      }
    }
  }

  cout << ans << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;

int main(){

	int numc[14];
	int in[5];

	while(1){
		
		for(int i=0; i<14; ++i){
			numc[i] = 0;
		}

		for(int i=0; i<5; ++i){
			
			int a;
			char c;
			
			cin >> a;

			if(cin.eof())
				return 0;

			numc[a]++;
			in[i] = a;

			if(i<4)
				cin >> c;
		}

		sort(numc, numc+14, greater<int>());
		sort(in, in+5);

		if(numc[0]>=4){
				cout << "four card" << endl;
				continue;
		}
		if(numc[0]==3&&numc[1]==2){
				cout << "full house" << endl;
				continue;
		}
		
		bool str = true;
			
		for(int i=0; i<4; ++i){
			
			if(in[i+1]-in[i]!=1){
				str = false;
				break;
			}
		}
				
		if(str||in[0]==1&&in[1]==10&&in[2]==11&&in[3]==12&&in[4]==13){
			cout << "straight" << endl;
			continue;
		}
		if(numc[0]>=3){
				cout << "three card" << endl;
				continue;
		}
		if(numc[0]>=2&&numc[1]>=2){
				cout << "two pair" << endl;
				continue;
		}
		if(numc[0]>=2){
				cout << "one pair" << endl;
				continue;
		}
		else{
				cout << "null" << endl;
				continue;
		}
	}

	return 0;
}

Measured memory_bytes: 1176
n,a,b= map(int,input().split())
sh = sorted([int(input()) for i in range(n)],reverse=True)
sumh = sum(sh)
def nibu(t):
    rt=0
    for i in range(n):
        temp = -1*(-1*max(0,sh[i]-t*b)//(a-b))
        if temp>0:rt+=-1*(-1*max(0,sh[i]-t*b)//(a-b))
        else:break
        if rt>t:return False
    return True if t>=rt else False
l=max(sh)//a
r=max(sh)//b+1
while r-l!=1:
    m = (l+r)//2
    if nibu(m):r=m
    else:l=m
print(r)

Measured memory_bytes: 8280
#include <iostream>
#include <vector>
#include <string>
#include <sstream>
#include <algorithm>
#include <map>
#include <set>
#include <cstdio>
#include <cmath>
#include <queue>
#include <stack>
#define rep(i,l,n) for(lint i=l;i<n;i++)
#define rer(i,l,n) for(lint i=l;i<=n;i++)
#define all(a) a.begin(),a.end()
#define o(a) cout<<a<<endl
#define pb(a) push_back(a)
#define mk(a,b) make_pair(a,b)
#define fi first
#define se second
using namespace std;
typedef long long lint;
typedef vector<int> vi;
typedef vector<lint> vli;
typedef vector<vi> vvi;
typedef pair<int, int> pii;

int main(){
	while (1){
		int n, m;
		cin >> n;
		if (n == 0) break;
		int d[30][30] = {};
		rep(i, 0, n){
			int y, x;
			cin >> x >> y;
			d[x][y] = 1;
		}
		int cnt = 0;
		cin >> m;
		int y = 10, x = 10;
		rep(i, 0, m){
			char s;
			int a;
			cin >> s >> a;
			while(a--){
				if (s == 'N') y++;
				else if (s == 'E') x++;
				else if (s == 'W') x--;
				else if (s == 'S') y--;
				if (d[x][y]){
					cnt++; d[x][y] = 0;
				}
			}
		}
		if (cnt == n) o("Yes");
		else o("No");
	}
}

Measured memory_bytes: 1156
#include <cstdio>
#include <vector>
#include <algorithm>
using namespace std;
int main() {
	int n;
	scanf("%d", &n);
	n = 2 * n;
	vector<int> num;
	for (int i = 0; i < n; i++) {
		int number;
		scanf("%d", &number);
		num.push_back(number);
	}
	int ans = 0;
	sort(num.begin(), num.end());
	for (int i = 0; i < n; i+=2) {
		ans += num[i];
	}
	printf("%d\n", ans);
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
 
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
 
#define oset tree<int , null_type, less_equal<int> , rb_tree_tag, tree_order_statistics_node_update>
#define show(x) cout<<#x<<" "<<x<<'\n'
 
#define MAX 1000000007
#define N 100000
 
using namespace std;
using namespace __gnu_pbds;

int main(){
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  long long int n,i;
  long long int sum = 0;
  cin>>n;
  vector<long long int> num(n);
  for(i=1;i<n;i++){
    cin>>num[i];
  }
  sum += num[1] + num[n-1];
  for(i=1;i<n-1;i++){
    sum += min(num[i],num[i+1]);
  }
  cout<<sum<<endl;
  return 0;
}

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

#define ll long long int
#define str string

ll MOD = 1000000007, INFL = 1ll << 60, INF = 1 << 30, mod = 1e9 + 7, Max = INF, Min = -1;
ll a = 0, b = 0, c = 0, n = 0, m = 0, kiroku = 0, sum = 0, MASK = 0;
ll A[50000][3] = {}, B[500000] = {}, dp[200000][3], rui[500000] = {}, dp2[1 << 12] = {};
int dy[] = { 0, 0, 1, -1 }, dx[] = { 1, -1, 0, 0 };
vector <ll> v;
str S, T;
bool check = true, check2 = false;


int main() {
	//Code Line
	cin >> a;
	for (int i = 1; i < sqrt(a) + 1; i++) {
		if (a % i == 0)b = i;
	}
	c = a / b;
	
	cout << (c - 1) + (b - 1) << endl;
	return 0;
}


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

using namespace std;
#define inf 1000000000
#define unvisited -1
#define visited 1
#define eps 1e-9
#define mp make_pair
#define pb push_back
#define pi acos(-1.0)
#define uint64 unsigned long long
#define FastSlowInput ios_base::sync_with_stdio(false); cin.tie(NULL);
typedef long long ll;
typedef vector<int> vi;
typedef pair<int,int> ii;
typedef vector<ii> vii;

const int maxn = 103;
const int mod = 1e9 + 7;

int dp[101][100001];

void add(int &a, int b){
	if(b < 0){b += mod;}
	a += b;
	if(a > mod){a-=mod;}
}

int main(){
	int n,k,i,j;
	int a[maxn];
	scanf("%d %d",&n,&k);
	for(i=0;i<n;i++){
		scanf("%d",&a[i]);
	}
	for(i=0;i<=k;i++){
		if(a[0] >= i){dp[0][i] = 1;}
	}
	// printf("n: %d\n",n);
	int pref[100001];
	for(i=1;i<n;i++){
		for(j=0;j<=k;j++){
			pref[j] = dp[i-1][j];
			if(j){add(pref[j], pref[j-1]);}
		}

		for(j=0;j<=k;j++){
			int maks = j, minim = max(0, j-a[i]);
			int tambah = pref[maks] - (minim ? pref[minim-1]: 0);

			add(dp[i][j], tambah);
		}
	}
	printf("%d\n",dp[n-1][k]);
	return 0;
};

Measured memory_bytes: 39680
#include <iostream>
#include <algorithm>
#include <string>
#include <map>

using namespace std;

map<char, bool> pos;

void swapCups(char a, char b) {
  swap(pos[a], pos[b]);
}

int main(void) {
  string command;

  pos['A'] = true;
  pos['B'] = false;
  pos['C'] = false;

  while(cin >> command) {
    swapCups(command[0], command[2]);
  }
  
  if(pos['A']) {
    cout << 'A';
  }
  else if(pos['B']) {
    cout << 'B';
  }
  else {
    cout << 'C';
  }
  cout << endl;
  return 0;
}

Measured memory_bytes: 1176
from collections import deque

N,K = map(int,input().split())

A = [int(i) for i in input().split()]

B = deque(A[:K])

for i in range(K,N):
  if B.popleft() < A[i]:
    print('Yes')
  else:
    print('No')    
    
  B.append(A[i])


Measured memory_bytes: 32516
#include<bits/stdc++.h>
using namespace std;
int main()
{
	int n,i,s=0;
	cin>>n;
	bool a[5]={false};
	for(i=1;i<=n;i++)
	{
		char c;
		cin>>c;
		if(c=='P')
			a[1]=true;
		if(c=='W')
			a[2]=true;
		if(c=='G')
			a[3]=true;
		if(c=='Y')
			a[4]=true;
	}
	for(i=1;i<=4;i++)
	{
		if(a[i]==true)
			s++;
	}
	if(s==3)
		cout<<"Three"<<endl;
	if(s==4)
		cout<<"Four"<<endl;
	return 0;
}

Measured memory_bytes: 256
import java.util.*

fun main(args: Array<String>) {
    val INF = -100000007
    val (H, W) = readLine()!!.split(" ").map(String::toInt)
    val maze = Array(H) {
       readLine()!!.toCharArray()
    }
    fun bfs(sx: Int, sy: Int): Int {
        var dmax = 0
        val dx = arrayOf(1,0,-1,0)
        val dy = arrayOf(0,1,0,-1)
        val que = ArrayDeque<Pair<Int,Int>>()
        que.addLast(Pair(sx, sy))
        val d = Array(H){ Array(W) {INF} }
        d[sy][sx] = 0
        while (que.size > 0) {
            val p = que.removeFirst()
            for (i in 0..3) {
                val nx = p.first + dx[i]
                val ny = p.second + dy[i]
                if ((nx in 0 until W) && (ny in 0 until H) && maze[ny][nx] == '.' && d[ny][nx] == INF) {
                    que.addLast(Pair(nx, ny))
                    d[ny][nx] = d[p.second][p.first] + 1
                    if (dmax <  d[ny][nx]) {
                        dmax = d[ny][nx]
                    }
                }
            }
        }
        return dmax
    }
    var ans = 0
    for (h in 0 until H) {
        for (w in 0 until W) {
            if (maze[h][w] != '.') continue
            ans = Math.max(ans, bfs(w, h))
        }
    }
    println(ans)
}

Measured memory_bytes: 42496
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(x) x.begin(),x.end()

int main() {
   int d,l=11,sum=0,cnt=0; 
   rep(i,5){
      cin >> d;
      sum+=d;
      if(d%10==0)
      cnt++;
      while(sum%10!=0)
      sum++;
      if(d%10!=0)
      l=min(d%10,l);
   }
   if(cnt!=5)
   cout << sum-(10-l) << endl;
   else 
   cout << sum << endl;
}

Measured memory_bytes: 256
import numpy as np

N, A, B = map(int, input().split())

H = []

for i in range(N):
    H.append(int(input()))

H = np.array(H)

def binary_search(x):
    H_tmp = H - B * x
    H_tmp = H_tmp[H_tmp > 0]
    count = ((H_tmp + A - B - 1) // (A - B)).sum()
    return x >= count

left = 0
right = 10**10

while(right - left > 1):
    mid = (left + right) // 2
    ret = binary_search(mid)
    if ret:
        right = mid
    else:
        left = mid

print(right)

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


// https://qiita.com/drken/items/3b4fdf0a78e7a138cd9a#4-%E7%B4%AF%E4%B9%97-an

const int MAX = 200000;
const int MOD = 1000000007;

long long fac[MAX], finv[MAX], inv[MAX];

// テーブルを作る前処理
void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}

// 二項係数計算
long long COM(int n, int k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

int main(void)
{
    int H, W, A, B;

    cin >> H >> W >> A >> B;

    long long int ans = 0;
    
    COMinit();

    for(int i = B; i < W; ++i)
    {
        ans = (ans + ((COM(H-A-1+i, H-A-1) * COM(A-1+W-i-1, A-1)) % MOD)) % MOD;
    }

    cout << ans << endl;

    return 0;
}



Measured memory_bytes: 8280
fun main(args: Array<String>) {
    val MOD = 1000000007L
    val SIZE = 2002
    val c = Array<LongArray>(SIZE + 1) { LongArray(SIZE + 1) }
    c[0][0] = 1
    for (i in 0 until SIZE) {
        for (j in 0 until SIZE) {
            c[i + 1][j] += c[i][j]
            c[i + 1][j] %= MOD
            c[i + 1][j + 1] += c[i][j]
            c[i + 1][j + 1] %= MOD
        }
    }
    fun comb(n: Int, k: Int) = if (n < k) 0 else c[n][k]
    fun g(n: Int, k: Int) = comb(n + k - 1, k - 1)
    fun f(n: Int, k: Int) = if (n == 0 && k == 0) 1 else if (k < 1) 0 else g(n-k, k)

    val (N, K) = listOfInt()
    val R = N - K
    for (i in 1 .. K) {
        val blue = f(K, i)
        var red =  f(R, i - 1); red %= MOD
            red += f(R, i); red %= MOD
            red += f(R, i); red %= MOD
            red += f(R, i + 1); red %= MOD
        val ans = blue * red % MOD
        println(ans)
    }
}
fun next() = readLine()!!
fun listOfString() = next().split(" ")
fun listOfInt() = listOfString().map { Integer.parseInt(it) }

Measured memory_bytes: 92648
import java.util.Scanner;

public class Main {

    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int a[] = new int[n];
        for(int i = n - 1; i >= 0; i--){
            int num = sc.nextInt();
            a[i] =  num;
        }
        for(int j = 0; j < n; j++){
            System.out.print(a[j]);
            if(j == n - 1){
                break;
            }
            System.out.print(" ");
        }
        System.out.println("");
}
}

Measured memory_bytes: 26316
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include <numeric>
#include <string>
 
using namespace std;
 
int main(void){
	string str; cin >> str;
	cout << str.substr(0,4) << " " << str.substr(4,str.size()-4) << endl;
 
	return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

/**
 * http://abc086.contest.atcoder.jp/tasks/abc086_a
 */
public class Main {

	public static void main(String[] args) {
		
		Scanner sc = new Scanner(System.in);
		int a = sc.nextInt();
		int b = sc.nextInt();
		sc.close();
		
		System.out.println(a*b%2==1 ? "Odd" : "Even");

	}

}


Measured memory_bytes: 21076
from bisect import bisect_left
from itertools import permutations
n=int(input())
p=''.join(map(str,input().split()))
q=''.join(map(str,input().split()))
l=list(range(1,n+1))
A=list(permutations(l,n))
A=[''.join(map(str,i)) for i in A]
A.sort()
a=bisect_left(A,p)
b=bisect_left(A,q)
print(abs(a-b))

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

int main() {
	int N;
	cin >> N;
	vector<int> d(N);
	for (int i = 0; i < N; i++) {
		cin >> d.at(i);
	}
	sort(d.begin(), d.end());
	int mid1 = d.at(N / 2 - 1), mid2 = d.at(N / 2);
	cout << mid2 - mid1 << endl;
}

Measured memory_bytes: 640
// ABC51-C.cpp : アプリケーションのエントリ ポイントを定義します。
//

#include <iostream>
using namespace std;

int main()
{
	int sx, sy, tx, ty;
	cin >> sx >> sy >> tx >> ty;
	for (size_t i = 0; i < ty - sy; i++) cout << 'U';
	for (size_t i = 0; i < tx - sx; i++) cout << 'R';
	for (size_t i = 0; i < ty - sy; i++) cout << 'D';
	for (size_t i = 0; i < tx - sx; i++) cout << 'L';
	cout << 'L';
	for (size_t i = 0; i < ty - sy + 1; i++) cout << 'U';
	for (size_t i = 0; i < tx - sx + 1; i++) cout << 'R';
	cout << "DR";
	for (size_t i = 0; i < ty - sy + 1; i++) cout << 'D';
	for (size_t i = 0; i < tx - sx + 1; i++) cout << 'L';
	cout << 'U' << endl;


	return 0;
}



Measured memory_bytes: 256
n = int(input())
num = list(map(int, input().split()))
sum1 = sum2 = 0
for i in range(n):
    if i % 2 == 0:
        x = max(num)
        a = num.index(x)
        sum1 += x
        del num[a]
    else:
        y = max(num)
        b = num.index(y)
        sum2 += y
        del num[b]

print(sum1 - sum2)
 


Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std::literals::string_literals;
using i64 = std::int_fast64_t;
using std::cout;
using std::cerr;
using std::endl;
using std::cin;

template<typename T>
std::vector<T> make_v(size_t a){return std::vector<T>(a);}

template<typename T,typename... Ts>
auto make_v(size_t a,Ts... ts){
  return std::vector<decltype(make_v<T>(ts...))>(a,make_v<T>(ts...));
}

int main() {
	int n, k; scanf("%d%d", &n, &k); std::vector<int> a(n);
	for(int i = 0; i < n; i++) scanf("%d", &a[i]);
	sort(begin(a), end(a));

	const int MOD = 1e9 + 7;
	auto inverse = [&](i64 x) {
		i64 ret = 1, n = MOD - 2;
		while(n) {
			if(n & 1) (ret *= x) %= MOD;
			(x *= x) %= MOD;
			n >>= 1;
		}
		return ret;
	};
	
	std::vector<i64> fact(n + 1, 1), inv(n + 1, 1);
	for(i64 i = 1; i < n + 1; i++) fact[i] = fact[i - 1] * i % MOD;
	for(int i = 0; i < n + 1; i++) inv[i] = inverse(fact[i]);

	auto comb = [&](int n, int r) {
		return fact[n] * inv[n - r] % MOD * inv[r] % MOD;
	};

	i64 ans = 0;
	for(int i = k - 1; i < n; i++) (ans += comb(i, k - 1) * a[i] % MOD) %= MOD;
	reverse(begin(a), end(a));
	for(int i = k - 1; i < n; i++) (ans -= comb(i, k - 1) * a[i] % MOD) %= MOD;
	if(ans < 0) ans += MOD;

	printf("%lld\n", ans);
	return 0;
}


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

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

typedef pair<int, int> P;

#define mp make_pair
#define ft first
#define sd second

int m, n;
P s[200];
P ns[1000];

int main() {
	ios::sync_with_stdio(false);
	
	while(cin >> m, m) {
		rep(i, m) cin >> s[i].ft >> s[i].sd;
		cin >> n;
		rep(i, n) cin >> ns[i].ft >> ns[i].sd;
		sort(s, s+m);
		sort(ns, ns+n);
		int dx, dy;
		rep(i, n) {
			dx = ns[i].ft-s[0].ft;
			dy = ns[i].sd-s[0].sd;
			bool flg = true;
			repi(j, 1, m) {
				if(!binary_search(ns, ns+n, mp(s[j].ft+dx, s[j].sd+dy))) {
					flg = false;
					break;
				}
			}
			if(flg)break;
		}
		cout << dx << " " << dy << endl;
	}
	
	return 0;
}

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

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

int main() {
    long long n;
    cin >> n;
    for (int a = 1; a <= 3500; a++) {
        for (int b = 1; b <= 3500; b++) {
            long long x = 4 * a * b - n * a - n * b;
            long long y = n * a * b;
            if (x > 0) {
                if (x / gcd(x, y) == 1) {
                    cout << a << " " << b << " " << y / gcd(x, y) << endl;
                    return 0;
                }
            }
        }
    }
}

Measured memory_bytes: 256