akhauriyash/Code-Regression huggingface dataset:
import sys
sys.setrecursionlimit(50*50)

seen = []
field = []
dx =[0, 1, 1, 1, 0, -1, -1, -1]
dy =[1, 1, 0, -1, -1, -1, 0, 1]
global W, H

def dfs_grid(w, h):
    seen[h][w]=True
    #print(h, w)

    for i in range(8):
        nw = w + dx[i]
        nh = h + dy[i]

        if nw < 0 or nw >= W or nh < 0 or nh >= H:
            continue
        if field[nh][nw] == 0:
            continue
        if seen[nh][nw]:
            continue

        dfs_grid(nw, nh)
while True:
    W, H = map(int, input().split())
    cnt =0

    if W ==0 and H ==0:
        break

    for i in range(H):
        field.append(list(map(int,(input().split()))))
        seen.append([False]* W)

    #print(field)
    #print(seen)

    for i in range(H):
        for j in range(W):
            if field[i][j]==0:
                continue
            if not(seen[i][j]):
                dfs_grid(j, i)
                cnt +=1

    #print(seen)
    field.clear()
    seen.clear()
    print(cnt)


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

using namespace std;

int main(){
    int n;
    string s;

    cin >> n >> s;

    string a = s.substr(0, n / 2);

    if(a + a == s){
        cout << "Yes" << endl;
    }else{
        cout << "No" << endl;
    }

    return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
#define MAX 101

int main(){
    int n, u, v, k, vmax = 0;
    int G[MAX][MAX];

    for(int i = 0; i < MAX; i++){
        for(int j = 0; j < MAX; j++){
            G[i][j] = 0;
        }
    }

    scanf("%d", &n);

    for(int i = 0; i < n; i++){
        scanf("%d %d", &u, &k);
        for(int j = 0; j < k; j++){
            scanf("%d", &v);
            if(vmax < v)vmax = v;
            G[u][v - 1] = 1;
        }
    }

    for(int i = 0; i < n;i++){
        for(int j = 0; j < vmax; j++){
            printf("%d", G[i + 1][j]);
            if(j < vmax - 1)printf(" ");
        }
        printf("\n");
    }

    return 0;
}



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

#define REP(i, x, n) for (int i = x; i < (int)(n); i++)
#define rep(i, n) REP(i, 0, n)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define sz(x) (int)(x.size())
#define popcount(x) __builtin_popcount(x)
#define popcountll(x) __builtin_popcountll(x)
#define uniq(x) x.erase(unique(x.begin(), x.end()), x.end())
#define F first
#define S second
#define mp make_pair
#define eb emplace_back
#define pii pair<int, int>
#define pll pair<ll, ll>

using namespace std;

typedef long long ll;

/* --- INFやMODの値が適切か確認する --- */
// const int INF = 1 << 30;
// const ll INF = 1LL << 60;
// const ll MOD = 1000000007;

int main() {
  int n, m;
  cin >> n >> m;
  cout << (n == m ? "Yes" : "No") << endl;
}


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

#define debug(x) cout <<"DEBUG"<<" "<< #x << ":" << x << '\n'

//↓0-originか1-originでn回繰り返し
#define rep(i,n) for(int i = 0; i < ((int)(n)); i++)   //0-origin昇順
#define rep1(i,n) for(int i = 1; i <= ((int)(n)); i++) //1-origin昇順
#define rrep(i,n) for(int i = ((int)(n)-1); i >= 0; i--)  //0-origin降順
#define rrep1(i,n) for(int i = ((int)(n)); i >= 1; i--)   //1-origin降順
//rep2 -> 第二引数 m から n 回繰り返し ex) m=5 n=3 なら i=5,i=6,i=7 まで
#define rep2(i,m,n) for(int i = ((int)(m)); i < ((int)(n))+((int)(m)); i++)
#define SIZE(x) ((int)((x).size()))
#define all(x) (x).begin(),(x).end()
typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef vector<vi> vii; //2次元配列
typedef vector<ll> vll;
typedef vector<string> vs;
template<class T,class U> inline bool chmax(T &a, const U &b){if(a<b){a=b;return 1;}return 0;}
template<class T,class U> inline bool chmin(T &a, const U &b){if(a>b){a=b;return 1;}return 0;}

/* 円周率は M_PI を使おうね */
const ll infll = (1LL<<62)-1;
const int inf = (1<<30)-1;

/*FUNCs=================================================*/


/*MAIN==================================================*/
signed main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);   //cin cout 高速化
    //cout << fixed << setprecision(10);

    int n, m, x, y, cnt = 1;
    cin >> n >> m;

    bool capability[n+10] = {}; //赤あるか？
    vi balls(n+10, 1);  //球の数
    capability[1] = 1;

    while(cin >> x >> y) {
        if(!balls[x]) continue;
        --balls[x];   //とりあえず取り出す
        ++balls[y];   //yのボールが増える
        
        if(capability[x]) {   //xに赤があるかもしれないとき
            if(!capability[y]) ++cnt;
            capability[y] = true;
        }
        if(balls[x] == 0) {  //xからボールがなくなるパターン
            if(capability[x]) --cnt;  //赤があるかもしれない状態だったなら--cnt;
            capability[x] = false;
        }
    }

    cout << cnt << '\n';
}

Measured memory_bytes: 768
#include <iostream>
using namespace std;
int main() {
    int a, b, c;
    cin >> a >> b >> c;
    bool ispoor = false;
    if (a == b && b != c)
        ispoor = true;
    if (b == c && c != a)
        ispoor = true;
    if (c == a && a != b)
        ispoor = true;
    if(ispoor)
        cout << "Yes" << endl;
    else
        cout << "No" << endl;    
}

Measured memory_bytes: 3104
#include <bits/stdc++.h>
using namespace std;
int main() {
	string N;
	cin >> N;
	int l = N.size();
	int a = 0;
	for (int i = 0; i < l; i++) {
		if (N.at(i) == '1') {
			a = a + 1;
		} else if (N.at(i) == '2') {
			a = a + 2;
		} else if (N.at(i) == '3') {
			a = a + 3;
		} else if (N.at(i) == '4') {
			a = a + 4;
		} else if (N.at(i) == '5') {
			a = a + 5;
		} else if (N.at(i) == '6') {
			a = a + 6;
		} else if (N.at(i) == '7') {
			a = a + 7;
		} else if (N.at(i) == '8') {
			a = a + 8;
		} else if (N.at(i) == '9') {
			a = a + 9;
		}
	}
	string ans;
	if (a % 9 == 0) {
		ans = "Yes";
	} else {
		ans = "No";
	}
	cout << ans << endl;
}


Measured memory_bytes: 3756
//
// Created by Pulak on 06-10-2019.
//
#include <stdio.h>

#define fl(i)  (L +i-1)

int main() {
    int N, L;
    scanf("%d %d", &N, &L);
    int ans = 0;
    int F = N * (L - 1) + (N * (N + 1) / 2);
    if (fl(1) * fl(N) < 0) ans = F;
    else if (F > 0) ans = F - fl(1);
    else if (F < 0){ ans = F - fl(N);}
    printf("%d ",ans);
    
}


Measured memory_bytes: 128
#include <bits/stdc++.h>
#define ll long long
int main()
{
    ll d, t, s;

    std::cin >> d >> t >> s;
    if (d - t * s > 0) {
        std::cout << "No" << std::endl;
    } else {
        std::cout << "Yes" << std::endl;
    }

    return 0;
}

Measured memory_bytes: 3636
#include<bits/stdc++.h>
typedef long long int ll;
typedef unsigned long long int ull;
#define BIG_NUM 2000000000
#define HUGE_NUM 99999999999999999
#define MOD 1000000007
#define EPS 0.000000001
using namespace std;



int main(){

	int A,B,C;

	scanf("%d %d %d",&A,&B,&C);

	if((A == B && A != C) || (A == C && A != B) || (B == C && B != A)){

		printf("Yes\n");

	}else{

		printf("No\n");
	}

	return 0;
}


Measured memory_bytes: 256
//Radhe Radhe
#include<bits/stdc++.h>
#define ll long long
using namespace std;
int main()
{
    ll n,i,j,misplaced=0;
    cin>>n;
    ll a[n];
    for(i=0; i<n; i++)
        cin>>a[i];

    for(i=0; i<n; i++)
    {

        if(i+1!=a[i])
            misplaced++;
    }
    if(misplaced==0||misplaced==2)
        cout<<"YES"<<endl;
    else
        cout<<"NO"<<endl;
    return 0;
}





Measured memory_bytes: 3600
import math

A, B, H, M  = map(int, input().split())

total_m = H * 60 + M
theta_radians = (abs(12 * M - total_m)) / 2
ans_2 = A**2 + B**2 -2*A*B*(math.cos(math.radians(theta_radians)))
ans = math.sqrt(ans_2)

print(ans)

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

namespace AtCorder
{
	public class Program
	{
		static void Main(string[] args)
		{
			Scanner cin = new Scanner();
			int n = cin.Int();
			int d = cin.Int();
			int[,] a = new int[n, d];
			for (int i = 0; i < n; i++) {
				for (int j = 0; j < d; j++) {
					a[i, j] = cin.Int();
				}
			}

			long ans = 0;
			for (int i = 0; i < n; i++) {
				for (int j = i + 1; j < n; j++) {
					double sum = 0;
					for (int k = 0; k < d; k++) {
						sum += Math.Pow(a[i, k] - a[j, k], 2);
					}

					double length = Math.Sqrt(sum);
					if (length - (long)length < 0.000001) {
						++ans;
					}
				}
			}

			Console.WriteLine(ans);
		}
	}

	public class Scanner
	{
		string[] s;
		int i;

		char[] cs = new char[] { ' ' };

		public Scanner()
		{
			s = new string[0];
			i = 0;
		}

		public string Next()
		{
			if (i < s.Length) return s[i++];
			string st = Console.ReadLine();
			while (st == "") st = Console.ReadLine();
			s = st.Split(cs, StringSplitOptions.RemoveEmptyEntries);
			if (s.Length == 0) return Next();
			i = 0;
			return s[i++];
		}

		public int Int()
		{
			return int.Parse(Next());
		}
		public int[] ArrayInt(int N, int add = 0)
		{
			int[] Array = new int[N];
			for (int i = 0; i < N; i++) {
				Array[i] = Int() + add;
			}
			return Array;
		}

		public long Long()
		{
			return long.Parse(Next());
		}

		public long[] ArrayLong(int N, long add = 0)
		{
			long[] Array = new long[N];
			for (int i = 0; i < N; i++) {
				Array[i] = Long() + add;
			}
			return Array;
		}

		public double Double()
		{
			return double.Parse(Next());
		}


		public double[] ArrayDouble(int N, double add = 0)
		{
			double[] Array = new double[N];
			for (int i = 0; i < N; i++) {
				Array[i] = Double() + add;
			}
			return Array;
		}
	}
}


Measured memory_bytes: 11092
#define _USE_MATH_DEFINES
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cctype>
#include <clocale>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <deque>
#include <fstream>
#include <functional>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <list>
#include <map>
#include <queue>
#include <regex>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <tuple>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>

using namespace std;

#define IOS ios::sync_with_stdio(false); cin.tie(0);
#define FOR(i, s, n) for(int i = (s), i##_len=(n); i < i##_len; ++i)
#define FORS(i, s, n) for(int i = (s), i##_len=(n); i <= i##_len; ++i)
#define VFOR(i, s, n) for(int i = (s); i < (n); ++i)
#define VFORS(i, s, n) for(int i = (s); i <= (n); ++i)
#define REP(i, n) FOR(i, 0, n)
#define REPS(i, n) FORS(i, 0, n)
#define VREP(i, n) VFOR(i, 0, n)
#define VREPS(i, n) VFORS(i, 0, n)
#define RFOR(i, s, n) for(int i = (s), i##_len=(n); i >= i##_len; --i)
#define RFORS(i, s, n) for(int i = (s), i##_len=(n); i > i##_len; --i)
#define RREP(i, n) RFOR(i, n, 0)
#define RREPS(i, n) RFORS(i, n, 0)
#define ALL(v) (v).begin(), (v).end()
#define SORT(v) sort(ALL(v))
#define RSORT(v) sort(ALL(v), greater<decltype(v[0])>())
#define SZ(x) ((int)(x).size())
#define PB push_back
#define EB emplace_back
#define MP make_pair
#define MT make_tuple
#define BIT(n) (1LL<<(n))
#define UNIQUE(v) v.erase(unique(ALL(v)), v.end())

using ld = long double;
using ll = long long;
using ui = unsigned int;
using ull = unsigned long long;
using Pi_i = pair<int, int>;
using VB = vector<bool>;
using VC = vector<char>;
using VD = vector<double>;
using VI = vector<int>;
using VLL = vector<ll>;
using VS = vector<string>;
using VSH = vector<short>;
using VULL = vector<ull>;

const int MOD = 1000000007;
const int INF = 1000000000;
const int NIL = -1;
const double EPS = 1E-10;

template<class T, class S>
bool chmax(T &a, const S &b){
    if(a < b){
        a = b; return true;
    }
    return false;
}
template<class T, class S>
bool chmin(T &a, const S &b){
    if(b < a){
        a = b; return true;
    }
    return false;
}


int main(){
    int N, K; cin >> N >> K;
    cout << ((2*K-1 <= N) ? "YES" : "NO") << endl;
    return 0;
}


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

int main(){
    int N,K;
    cin>>N>>K;
    vector<int> D(10,0); 
    for(int i=0;i<K;i++){
        int d;
        cin>>d;
        D[d]=1;
    }
    for(int i=N;true;i++){
        bool ok=true;
        int n=i;
        while(n){
            if(D[n%10])ok=false;
            n/=10;
        }
        if(ok){
            cout<<i<<endl;
            return 0;
        }
    }

    return 0;
}

Measured memory_bytes: 256
n=int(input())
l=[list(map(int,input().split())) for i in range(n)]

dp=[[-1,-1,-1] for i in range(n+1)]
dp[0][0]=0
dp[0][1]=0
dp[0][2]=0
for i in range(n):
    for j in range(3):
        for k in range(3):
            if j==k:
                continue
            dp[i+1][j]=max(dp[i+1][j],dp[i][k]+l[i][j])
print(max(dp[-1]))

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

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

    vector<unsigned int> l(n);
    for(unsigned int i = 0; i < n; i++) {
        cin >> l.at(i);
    }

    sort(l.begin(), l.end());
    unsigned int count = 0;
    for(unsigned int i = 0; i < n-2; i++) {
        for(unsigned int j = i + 1; j<n-1; j++) {
            for(unsigned int k = j + 1; k < n; k++) {
                if(l.at(i) + l.at(j) > l.at(k)) {
                    count++;
                } else {
                    break;
                }
            }
        }
    }
    cout << count;

}


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

class DisjointSet {
 public:
  DisjointSet(int size) : parent_(size), size_(size, 1) {
    for (int i = 0; i < size; ++i) {
      parent_[i] = i;
    }
  }
  int Find(int x) {
    int& p = parent_[x];
    if (p != x) p = Find(p);
    return p;
  }
  void Union(int x, int y) {
    x = Find(x), y = Find(y);
    if (x == y) return;
    if (Size(x) > Size(y)) std::swap(x, y);
    parent_[x] = parent_[y];
    size_[y] += size_[x];
  }
  int Size(int x) { return size_[Find(x)]; }
  bool Same(int x, int y) { return Find(x) == Find(y); }

 private:
  std::vector<int> parent_, size_;
};

// #undef DEBUG  // Uncomment this line to forcefully disable debug print.
#if DEBUG
template <typename T>
void debug(T value) {
  std::cerr << value;
}
template <typename T, typename... Ts>
void debug(T value, Ts... args) {
  std::cerr << value << ", ";
  debug(args...);
}
#define DBG(...)                              \
  do {                                        \
    cerr << #__VA_ARGS__ << ": ";             \
    debug(__VA_ARGS__);                       \
    cerr << " (L" << __LINE__ << ")" << endl; \
  } while (0)
#else
#define DBG(...)
#endif

#define ALL(x) (x).begin(), (x).end()
#define FOR(i, n) for (auto i : (n))
#define REP(i, n) for (int i = 0; i < (int)(n); ++i)

using ll = long long;

using namespace std;

int main() {
  int N, M, K;
  cin >> N >> M >> K;

  DisjointSet ds(N);
  vector<set<int>> friends(N);
  vector<set<int>> blocks(N);
  REP(i, M) {
    int a, b;
    cin >> a >> b;
    --a, --b;
    friends[a].insert(b);
    friends[b].insert(a);
    ds.Union(a, b);
    DBG(a, b, ds.Find(a), ds.Find(b), ds.Size(a), ds.Size(b));
  }
  REP(i, K) {
    int a, b;
    cin >> a >> b;
    --a, --b;
    blocks[a].insert(b);
    blocks[b].insert(a);
  }

  REP(i, N) {
    int cnt = ds.Size(i) - 1 - friends[i].size();
    FOR(b, blocks[i]) if (ds.Same(b, i)) --cnt;
    if (i) cout << " ";
    cout << cnt;
  }
  cout << endl;
}


Measured memory_bytes: 29696
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define loop(i,a,b) for(i=a;i<b;i++)
#define rloop(i,a,b) for(i=a;i>=b;i--)
#define vi vector<int>
#define vs vector<string>
typedef pair<string,int> card;
#define mark first
#define kazu second
const int inf=1e9+1;
const ll INF=1e16;
#define MOD 1000000007
#define mod 1000000009
#define pi 3.14159265358979323846

int main(){
	int i,j,k,n;
	cin>>n;
	vi a(n),b(n);
	loop(i,0,n){
		cin>>a[i];
	}
	sort(a.begin(),a.end());
	cout<<a[0];
	loop(i,1,n){
		cout<<" "<<a[i];
	}
	cout<<"\n";
}

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

int main(){
  int N; cin >> N;
  vector<int> vec(N);
  for (int i = 0; i < N; i++ ) cin >> vec.at(i);
  //入力値の受け取り
  sort(vec.begin(), vec.end());
  reverse(vec.begin(), vec.end());
  int count = 0;
  for (int i = 0; i < N; i+=2 ) count += vec.at(i);
  for (int i = 1; i < N; i+=2 ) count -= vec.at(i);
  cout << count << endl;
}

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


typedef long long ll;
typedef pair<int,int> ii;
typedef vector<int> vi;
typedef vector<ii> vii;
typedef long double ld;

typedef set<int>::iterator sit;
typedef map<int,int>::iterator mit;
typedef vector<int>::iterator vit;

const int INF = 1e9 + 7;
const int MOD = 1e9 + 7;
const int MAXN = 1e6 + 3;

#define _  %  MOD
#define __ %= MOD

#define      each(it,s)        for(auto it = s.begin(); it != s.end(); ++it)
#define      sortA(v)          sort(v.begin(), v.end())
#define      sortD(v)          sort(v.begin(), v.end(), greater<auto>())
#define      fill(a)           memset(a, 0, sizeof (a))

#define      swap(a,b)        {a=a+b;b=a-b;a=a-b;}
#define      rep(i, n)         for(ll i = 0; i < (n); ++i)
#define      repA(i, a, n)     for(ll i = a; i <= (n); ++i)
#define      repD(i, a, n)     for(ll i = a; i >= (n); --i)
#define watch(x) cout << (#x) << " is " << (x) <<endl

#define fi first
#define se second
#define mp make_pair
#define pb push_back

#define fbo find_by_order
#define ook order_of_key

ll gcd(ll a,ll b){if(b==0) return a; else return gcd(b,a%b);}
ll power(ll x,ll y){ll res=1; while(y>0){if(y&1) res=res*x;y=y>>1;x=x*x;}return res;} // modular exponent

int main()
{
    ios_base::sync_with_stdio(false); // don't use printf and scanf
    cin.tie(NULL); // cout<<fixed<<setprecision
    int k; cin>>k;
    int a,b;cin>>a>>b;
    if(a/k==b/k&&a%k!=0){
        cout<<"NG"<<endl;
    }
    else if(a/k!=b/k){
        cout<<"OK"<<endl;
    }
    else{
        cout<<"OK"<<endl;
    }
} 

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

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

signed main(){
    int A, B, C, D;
    cin >> A >> B >> C >> D;
    
    int g = C * D / gcd(C, D);
    //cout << g << endl;
    cout << (B - A + 1) - (B / C - (A - 1) / C) - (B / D - (A - 1) / D) + (B / g - (A - 1) / g) << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define rrep(ri,n) for(int ri = (int)(n-1); ri >= 0; ri--)
#define rep2(i,x,n) for(int i = (int)(x); i < (int)(n); i++)
#define rrep2(ri,x,n) for(int ri = (int)(n-1); ri >= (int)(x); ri--)
#define repit(itr,x) for(auto itr = x.begin(); itr != x.end(); itr++)
#define rrepit(ritr,x) for(auto ritr = x.rbegin(); ritr != x.rend(); ritr++)
#define ALL(x) x.begin(), x.end()
using ll = long long;
using namespace std;
const ll mod = 1000000007;

int main(){
  int n, k;
  cin >> n >> k;
  if(n == k){
    bool f = true;
    ll ans = 1;
    rep(i, n){
      ll in;
      cin >> in;
      if(in < 0){
        in *= -1;
        f ^= 1;
      }
      ans *= in;
      ans %= mod;
      
    }
    if(f == false){
      ans = mod - ans;
      ans %= mod;
    }
    cout << ans << endl;
    return 0;
  }
  vector<ll> ps, ng;
  rep(i, n){
    ll in;
    cin >> in;
    if(in < 0) ng.push_back(-1*in);
    else ps.push_back(in);
  }
  sort(ng.begin(), ng.end());
  sort(ps.begin(), ps.end());
  if(ps.size() == 0 && k % 2 == 1){
    ll ans = 1;
    rep(i, k){
      ans *= ng.at(i);
      ans %= mod;
    }
    ans = mod - ans;
    ans %= mod;
    cout << ans << endl;
    return 0;
  }

  priority_queue<ll> q;
  for(int i = ng.size()-1; i >= 1; i -= 2){
    q.push(ng.at(i) * ng.at(i-1));
    // cerr << ng.at(i)*ng.at(i-1) << endl;
  }
  // cerr << endl;
  ll ans = 1;
  int st = -1;
  if(k % 2 == 1){
    ans *= ps.back();
    st = ps.size()-1;
  }
  for(int i = ps.size()-1; i >= 1; i -= 2){
    if(i == st){
      i++;
      continue;
    }
    q.push(ps.at(i)*ps.at(i-1));
  }
  rep(i, k/2){
    ll now = q.top(); q.pop();
    now %= mod;
    ans *= now;
    ans %= mod;
  }
  cout << ans << endl;
  return 0;
}

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

ll dp[401][400];
ll prefix[401];
int main() {
  ios::sync_with_stdio(0); cin.tie(0);
  int n;
  cin >> n;
  for (int i = 0; i < n; i++) {
    ll a;
    cin >> a;
    prefix[i+1] = prefix[i]+a;
  }
  fill_n((ll*)dp, 401*400, 1e18);
  for (int l = 1; l <= n; l++) {
    for (int i = 0; i+l <= n; i++) {
      if (l == 1) dp[1][i] = 0;
      for (int j = i+1; j < i+l; j++) {
	dp[l][i] = min(dp[l][i], dp[j-i][i]+dp[l-(j-i)][j]+prefix[i+l]-prefix[i]);
      }
    }
  }
  cout << dp[n][0] << endl;
}


Measured memory_bytes: 1536
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<int, int>;

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


void solve(long long X, long long N, std::vector<long long> p){
    ll ans = 0;
    ll score = 999999999999999;
    vector<ll> a(200);
    rep(i,N) a[p[i]] = 1;
    if(N == 0){
        cout << X << endl;
        return;
    }

    for(int i = 0; i<200; i++){
        if(a[i]) continue;
        ll now = abs(i-X);
        if(now < score){
            score = now;
            ans = i;
        }
    }
    cout << ans << endl;

}

int main(){
    long long X;
    scanf("%lld",&X);
    long long N;
    scanf("%lld",&N);
    std::vector<long long> p(N);
    for(int i = 0 ; i < N ; i++){
        scanf("%lld",&p[i]);
    }
    solve(X, N, std::move(p));
    return 0;
}


Measured memory_bytes: 3696
#include <iostream>
//#include <queue>
//#include <bits/stdc++.h>
#include <string>
#include <sstream>
#include <cmath>
#include <fenv.h>
#include <cstdio>

using namespace std;

int solve(int a,int b)
{
	float r = (a+b)/2.0;
	cout << static_cast<int>( round(r)) << endl;
}

int main(){
int a, b; cin >> a; cin >> b;
solve(a,b);
	//solve(7,4);
	//solve(1,3);

	return 0;
}


Measured memory_bytes: 384
#include <iostream>
#include <algorithm>
#include <string>
#include <stack>
#include <queue>
#include <vector>
#include <set>
#include <cmath>
#define FOR(i,a,b) for(int i=a;i<b;i++)
#define ROF(i,a,b) for(int i=b-1;i>=a;i--)
#define FI first
#define SE second
#define MA(i,j) make_pair(i,j)
#define PA pair<int,int>
#define PB push_back
#define PQ priority_queue<int>
#define PGQ priority_queue<int,vector<int>,greater<int> >
#define VE vector<int>
#define VP vector<PA>
#define YES(i) cout<<(i?"YES":"NO")<<endl
#define Yes(i) cout<<(i?"Yes":"No")<<endl
#define MOD 1000000007
#define INF 1000000007
using namespace std;
//
int main(){
  int N,T,A[100000],B[100000];
  cin>>N>>T;
  FOR(i,0,N){
    cin>>A[i];
  }
  int MAX=-1;
  ROF(i,0,N){
    if(MAX<A[i]){
      MAX=A[i];
    }
    B[i]=MAX;
  }
  MAX=-1;
  int ans=0;
  FOR(i,0,N){
    if(B[i]-A[i]>MAX){
      MAX=B[i]-A[i];
      ans=1;
    }else if(B[i]-A[i]==MAX){
      ans++;
    }
  }
  cout<<ans<<endl;
  return 0;
}


Measured memory_bytes: 1024
#include<bits/stdc++.h>
#define re register 
#define ll long long
#define in inline
using namespace std;
inline ll read(){
	int t=0;
	char v=getchar();
	while(v<'0'||v>'9')v=getchar();
	while(v>='0'&&v<='9'){
		t=(t<<3)+(t<<1)+v-'0';
		v=getchar();
	}
	return t;
}
ll n,m,a[2002],l,r,ans;
int main(){
	n=read();
	for(re ll i=1;i<=n;++i)a[i]=read();
	sort(a+1,a+n+1);
	for(re ll i=1;i<=n-2;++i){
		l=i+1;
		for(re ll j=i+1;j<=n-1;++j){
			l=max(l,j+1);
			r=n;
			while(l<r){
				m=(l+r)>>1;
				if(a[m]>=a[i]+a[j])r=m;
				else l=m+1;
			}
			while(a[l]>=a[i]+a[j])l--;
			if(l>j);
			ans+=l-j;
		}
	}
	printf("%lld",ans);
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(){
  int n;
  cin>>n;
  int ans=n%10;
  if(ans==2 || ans==4 || ans==5 || ans==7 || ans==9)cout<<"hon"<<endl;
  if(ans==0 || ans==1 || ans==6 || ans==8)cout<<"pon"<<endl;
  if(ans==3)cout<<"bon"<<endl;
  return 0;
}

Measured memory_bytes: 3652
import sys

sys.setrecursionlimit(10**7)
INF = 10 ** 18
MOD = 10 ** 9 + 7
def LI(): return list(map(int, sys.stdin.readline().split()))
def II(): return int(sys.stdin.readline())
def LS(): return list(map(list, sys.stdin.readline().split()))
def S(): return list(sys.stdin.readline())[:-1]

def main():
    a = II()
    print(int(a * a * a))

if __name__ == '__main__':
    main()

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


int main (){
    ll a,b,c;   cin >> a >> b >> c;
    if(c-(a-b)<=0) cout <<  0 << endl;
    else cout << c-(a-b) << endl;    
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cmath>
#include<vector>
#include<utility>
#include<queue>
#include<deque>
#include<stack>
#include<set>
#include<map>
#include<bitset>
#include<string>
#define rep(i,n,m) for(int i=(n);i<(int)(m);i++)
#define reps(i,n,m) for(int i=(n);i<=(int)(m);i++)
#define all(v) v.begin(), v.end()
#define allr(v) v.rbegin(), v.rend()
#define SZ(x) ((int)(x).size())
#define pb push_back
#define mp make_pair
#define fs first
#define sc second
#define lb lower_bound
#define ub upper_bound
#define LB(a,x) lb(all(a), x) - a.begin()
#define UB(a,x) ub(all(a), x) - a.begin()
#define printfdouble(x) printf("%.12f\n",(x))
#define chartoint(c) (int)((c) - '0')
#define chartoll(c) (long long)((c) - '0')
#define MOD 1000000007
#define itn int
#define enld endl
#define ednl endl
#define icn cin
#define stirng string
using namespace std;
typedef long long ll;
const double pi = 3.141592653589793;
using Graph = vector<vector<int>>;
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<typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val){
    std::fill( (T*)array, (T*)(array+N), val );
}

int N,M,Q;
int a[55],b[55],c[55],d[55];
int ans;

void dfs(vector<int> A){
    if(SZ(A) == N+1){
        int sum = 0;
        rep(i,0,Q){
            if(A[b[i]] - A[a[i]] == c[i]) sum += d[i];
        }
        chmax(ans, sum);
        return;
    }

    A.push_back(A.back());
    while(A.back() <= M){
        dfs(A);
        A.back()++;
    }
}

int main(){
    cin.tie(0);ios::sync_with_stdio(false);
    cin >> N >> M >> Q;
    rep(i,0,Q){
        int x,y,z,w; cin >> x >> y >> z >> w;
        a[i] = x;
        b[i] = y;
        c[i] = z;
        d[i] = w;
    }

    vector<int> v(1,1);
    dfs(v);
    cout << ans << endl;
    return 0;
}

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

int g[200][200];

int main() {
    int n; cin >> n;
    rep(i, n){
        int x; cin >> x;
        int y; cin >> y;
        rep(j, y){
            int k; cin >> k;
            g[i+1][k] = 1;
        }
    }

    rep(i, n){
        rep(j, n){
            cout << g[i+1][j+1];
            if(j == n-1){
                cout << endl;
            } else {
                cout << " ";
            }
        }
    }

    return 0;
}


Measured memory_bytes: 3124
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int N;
  cin >> N;
  vector<int> C(N);
  vector<int> V(N);
  for(int i=0;i<N;i++)
    cin >> V.at(i);
  for(int i=0;i<N;i++)
    cin >> C.at(i);
  
  /*
  * we have N stones, and these value are V(i).
  * we can choose stones, and pay costs as C(i).
  * the total of value is X, and total cost is Y.
  * show the max of (X - Y).
  * 
  * calc each V(i) - C(i).
  * and sum all positive value of them. <- max of (X - Y)
  */

  int z;  
  int sum = 0;
  for(int i=0;i<N;i++){
    z = V.at(i) - C.at(i);
    if(z > 0)
      sum += z;
  }
  
  cout << std::setprecision(20);
  cout << sum << endl;
}


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

#define mk make_pair
#define pb push_back

typedef long long lld;
typedef pair<lld,lld> pr;
typedef priority_queue <lld> max_heap;
typedef priority_queue <lld, vector<lld>, greater<lld> > min_heap;
lld const mod = 1e9+7;

lld power(lld x, lld y)
{
    lld res = 1;
    while (y > 0) {
        if (y & 1)
            res = res * x;
        y = y >> 1;
        x = x * x;
    }
    return res;
}

lld power_mod(lld base, lld y)
{
    lld t = 1;
    while (y > 0)
    {

        if (y % 2 != 0)
            t = (t * base) % mod;
        base = (base * base) % mod;
        y /= 2;
    }
    return t % mod;
}

lld nCrModp(lld n, lld r, lld p)
{
    if (r > n - r)
        r = n - r;
    lld C[r + 1]={0};
    C[0] = 1;

    for (lld i = 1; i <= n; i++)
    {
      for (lld j = min(i, r); j > 0; j--)
      {
        C[j] = (C[j] + C[j - 1]) % p;

      }
    }
    return C[r];
}

int main()
{
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  lld n;
  cin>>n;
  char a = 'a';
  string ans;
  while(n>0)
  {
    char b = a+(n-1)%26 ;
    ans = b + ans;
    n = (n-1)/ 26;
  }
  cout<<ans<<endl;

}


Measured memory_bytes: 3640
#include <iostream>

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

using namespace std;

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

    if (N % 500 <= A)
        cout << "Yes" << endl;
    else
        cout << "No" << endl;
        
    return 0;
}

Measured memory_bytes: 256
N = int(input())
L = list(map(int,input().split()))
#各bit 累積和テーブル作成
bit =[[0 for i in range(20)] for _ in range(N+1)]
for j in range(N):
    for i in range(20):
        bit[j+1][i] = (L[j] >> i) & 1
#accumulate
for j in range(1,len(L)):
    for i in range(20):
        bit[j+1][i] += bit[j][i]
#作成終了

#1がダブって立ってたらアウト
def check(start,x):
    #bit20桁チェック
    for i in range(20):
        if bit[x][i] - bit[start][i] >= 2:
            return False
    return True

#bisect( [x,y) 半開区間で探索)
def bisect(start,x,y):
    if y - x == 1: return x
    mid = (x + y) // 2
    if check(start,mid) == False:
        return bisect(start,x,mid)
    else:
        return bisect(start,mid,y)

cnt = 0
#今見てるとこが右からn番目でここより右にある物の中からいい感じ(check()の境界)のところを二分で探す
for n in range(N):
    #OKな個数を足し込む
    cnt += bisect(n, n, N+1) - n
print(cnt)



Measured memory_bytes: 125900
import math
def main():
    N, P = map(int, input().split())
    A = [int(a) for a in input().split()]
    modA = list()

    for a in A:
        modA.append(a % 2)

    zero = modA.count(0)
    one = modA.count(1)

    ans = tmp = 0
    f = math.factorial
    if P == 0:
        for i in range(0, one + 1, 2):
            tmp += f(one) // (f(i) * f(one - i))
    else:
        for i in range(1, one + 1, 2):
            tmp += f(one) // (f(i) * f(one - i))

    if zero > 0:
        ans = tmp * 2 ** zero
    else:
        ans = tmp

    print(ans)

if __name__ == "__main__":
    main()

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

int main() {
  int n, m;
  cin >> n >> m;
  vector<int> pena(n, 0);
  vector<int> ac(n, 0);
  for(int i = 0; i < m; ++i) {
    int p;
    string s;
    cin >> p >> s;
    --p;
    if(ac[p]) continue;
    if(s == "AC") {
      ac[p] = 1;
    } else {
      pena[p]++;
    }
  }
  int AC = 0, PENA = 0;
  for(int i = 0; i < n; ++i) {
    AC += ac[i];
    if(ac[i]) PENA += pena[i];
  }
  cout << AC << ' ' << PENA << endl;
}


Measured memory_bytes: 4052
#include <iostream>
#include <string>
using namespace std;
int main()
{
	string s;
	int start=0,end=0;
	cin>>s;
	for(int i=0;i<s.length();i++)
	{
		if(s[i]=='C')start=1;
		if(start==1&&s[i]=='F')
		{
			cout<<"Yes"<<endl;
			return 0;
		}
	}
	cout<<"No"<<endl;
	return 0;
}

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

#define PI acosl(-1)
using namespace std;

int main() {
  double ans,rad,deg,A,B;
  double H,M;
  cin >> A >> B >> H >> M;
  H = 30*H + 0.5*M;
  M *= 6;
  if(H > M){
    deg = H - M;
  }
  else{
    deg = M - H;
  }
  /*
  rad = cos((deg*PI)/180.0);
  ans = A*A + B*B - rad*2*A*B;
  cout << setprecision(20) << sqrt(ans) << endl;
  */
  rad = cos((deg*M_PI)/180.0);
  ans = A*A + B*B - 2*A*B*rad;
  cout << setprecision(10) << sqrt(ans) << endl;
  return 0;
}


Measured memory_bytes: 4136
n, q = map(int, raw_input().split())
A = [[0, 0] for i in range(n)]

for i in range(n):
    temp = raw_input().split()
    A[i][0] = temp[0]
    A[i][1] = int(temp[1])

time = 0
while A != []:
    if A[0][1] - q > 0:
        A[0][1] = A[0][1] - q
        time = time + q
        A.append(A.pop(0))
    else:
        print A[0][0],
        print time + A[0][1]
        time = time + A[0][1]
        A.pop(0)

Measured memory_bytes: 15520
import core.bitop;
import std.algorithm;
import std.ascii;
import std.bigint;
import std.conv;
import std.functional;
import std.format;
import std.math;
import std.numeric;
import std.range;
import std.stdio;
import std.string;
import std.random;
import std.typecons;

alias sread = () => readln.chomp();
alias Point2 = Tuple!(long, "y", long, "x");

T lread(T = long)()
{
    return readln.chomp.to!T();
}

T[] aryread(T = long)()
{
    return readln.split.to!(T[])();
}

void scan(TList...)(ref TList Args)
{
    auto line = readln.split();
    foreach (i, T; TList)
    {
        T val = line[i].to!(T);
        Args[i] = val;
    }
}

void minAssign(T, U = T)(ref T dst, U src)
{
    dst = cast(T) min(dst, src);
}

void maxAssign(T, U = T)(ref T dst, U src)
{
    dst = cast(T) max(dst, src);
}

enum MOD = (10 ^^ 9) + 7;

void main()
{
    long N = lread();
    auto T = new long[](N);
    foreach (i; 0 .. N)
        T[i] = lread();
    // gcd(10, 1000000000000000000).writeln;
    // writeln(10 * 1000000000000000000);
    long lcm(long a, long b)
    {
        // writefln("%d %d", a, b);
        return a * (b / gcd(a, b));
    }

    T.reduce!lcm().writeln();
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long
#define fir first
#define sed second
#define i64 int64_t
#define mp make_pair
#define pb push_back
const int mod = 1e9+7;

using namespace std;
ifstream fi("");
ofstream fo("");

int main(){
    ios::sync_with_stdio(0);cin.tie(0);
    string a,b;
    int n;
    cin>>n;
    cin>>a>>b;
    for (int i=0;i<n;i++) cout<<a[i]<<b[i];

    }





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

int main() {
    int N;
    long long T;
    cin >> N >> T;

    vector<long long> t(N);
    for (int i = 0; i < N; i++){
        cin >> t.at(i);
    }
    
    long long ans=T; //最後にT秒出るのを含めておく

    for (int i = 0; i < N-1; i++){
        ans=ans+min(T,t.at(i+1)-t.at(i));
    }

    cout << ans << endl;
    


}

Measured memory_bytes: 4660
#include <bits/stdc++.h>
#define INF (1<<30)
#define MOD 1000000007
#define l_ength size
using ll = long long;
using namespace std;

int main(){
	int a[4] = {0, 0, 0, 0};
	for( int i = 0; i < 6; ++i ){
		int t; cin >> t;
		++a[t-1];
	}
	int x = 0, y = 0;
	for( int i = 0; i < 4; ++i ){
		if( a[i] == 2 ){
			++x;
		}  else if ( a[i] == 1 ){
			++y;
		}
	}
	if( x == 2 && y == 2 ){
		cout << "YES" << endl;
	} else {
		cout << "NO" << endl;
	}
	return 0;
}

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

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll N,A,B,X,Y;
    cin >>N >> A >> B;
    X = N / (A+B);
    Y = min(N-((A+B)*X),A);
    cout << A*X + Y << "\n";
    return 0;
    }

Measured memory_bytes: 256
#include <stdio.h>

int main(){
 int a,b;
 while(scanf("%d %d ",&a,&b)>0){
  a+=b;
  b=0;
  while(a>0){
   b++;
   a/=10;
  }
  printf("%d\n",(b?b:1));
 }



 return 0;
}

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

#define ll          long long
#define pb          push_back
#define pii         pair<int,int>
#define vi          vector<int>
#define vii         vector<pii>
#define mi          map<int,int>
#define mii         map<pii,int>
#define all(a)      (a).begin(),(a).end()
#define x           first
#define y           second
#define sz(x)       (int)x.size()
#define endl        '\n'
#define hell        1000000007
#define rep(i,a,b)  for(int i=a;i<b;i++)
using namespace std;
int n,k;
void solve(){
    cin>>n>>k;
    rep(i,0,n){
        int x;
        cin>>x;
    }
    cout<<((n-1+k-2)/(k-1))<<endl; 
}

signed main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    int t=1;
    // cin>>t;
    while(t--){
        solve();
    }
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using lint = long long int;
template<class T = int> using V = vector<T>;
template<class T = int> using VV = V< V<T> >;
template<class T> void assign(V<T>& v, int n, const T& a = T()) { v.assign(n, a); }
template<class T, class... U> void assign(V<T>& v, int n, const U&... u) { v.resize(n); for (auto&& i : v) assign(i, u...); }

int main() {
  cin.tie(NULL); ios::sync_with_stdio(false);
  int n; cin >> n;
  V<string> w(n); for (int i = 0; i < n; i++) cin >> w[i];
  map<string, int> mp;
  for (int i = 0; i < n; i++) mp[w[i]]++;
  for (auto&& i : mp) if (i.second >= 2) return cout << "No" << '\n', 0;
  for (int i = 0; i < n - 1; i++) {
    if (w[i].back() != w[i + 1].front()) return cout << "No" << '\n', 0;
  }
  cout << "Yes" << '\n';
}

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

int main()
{
ll l , r ;
cin >> l >> r ;

rep(i,63){
  ll dp[i+1][2][2]={};
  if((1LL<<i+1)<=l||(1LL<<i)>r)continue;
  if(r>>i==1LL&&l>>i==1LL)dp[i][1][1]=1;
  else if(l>>i==1LL)dp[i][1][0]=1;
  else if(r>>i==1LL)dp[i][0][1]=1;
  else dp[i][0][0]=1;
  rep(j,i){
    ll k=i-j;
    dp[k-1][0][0]+=dp[k][0][0]*3;
    if(r>>(k-1)&1LL && l>>(k-1)&1LL){
      dp[k-1][1][1]+=dp[k][1][1];

      dp[k-1][0][1]+=dp[k][0][1]*2;
      dp[k-1][0][0]+=dp[k][0][1];

      dp[k-1][1][0]+=dp[k][1][0];
    }
    else if(r>>(k-1)&1LL){
      dp[k-1][1][1]+=dp[k][1][1];
      dp[k-1][0][1]+=dp[k][1][1];
      dp[k-1][1][0]+=dp[k][1][1];

      dp[k-1][0][1]+=dp[k][0][1]*2;
      dp[k-1][0][0]+=dp[k][0][1];

      dp[k-1][1][0]+=dp[k][1][0]*2;
      dp[k-1][0][0]+=dp[k][1][0];
    }
    else if(l>>(k-1)&1LL){
      dp[k-1][0][1]+=dp[k][0][1];

      dp[k-1][1][0]+=dp[k][1][0];
    }
    else{
      dp[k-1][1][1]+=dp[k][1][1];

      dp[k-1][0][1]+=dp[k][0][1];

      dp[k-1][1][0]+=dp[k][1][0]*2;
      dp[k-1][0][0]+=dp[k][1][0];
    }
    rep(x,2)rep(y,2)dp[k-1][x][y]%=mo;
  }
  ans+=dp[0][0][0]+dp[0][0][1]+dp[0][1][0]+dp[0][1][1];
  ans%=mo;
}

cout << ans << endl;
return 0;
}


Measured memory_bytes: 256
from collections import deque
from sys import stdin
input = stdin.readline


def main():
  N, M = list(map(int, input().split()))
  G = [[] for _ in range(N+1)]
  for i in range(M):
    a, b = map(int, input().split())
    G[a].append(b)
    G[b].append(a)

  from_ = [0]*(N+1)

  q = deque([1])
  seen = set()
  seen.add(1)

  while len(q):
    now = q.popleft()
    for next_ in G[now]:
      if next_ not in seen:
        seen.add(next_)
        q.append(next_)
        from_[next_] = now

  print('Yes')
  for i in range(2, N+1):
    print(from_[i])


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


Measured memory_bytes: 107316
#include<bits/stdc++.h>
using namespace std;
const int dx[4]={0,1,0,-1};
const int dy[4]={1,0,-1,0};
int n,m,k,mn,dist[805][805];
char s[805][805];
queue<pair<int,int> >q;
int dis(int x,int y){return (min(min(x,y),min(n-1-x,m-1-y))+k-1)/k;}
int main()
{
	scanf("%d%d%d",&n,&m,&k);
	memset(dist,-1,sizeof(dist));
	for(int i=0;i<n;i++)
	{
		scanf("%s",s[i]);
		for(int j=0;j<m;j++)if(s[i][j]=='S')
		{
			q.push(make_pair(i,j));
			dist[i][j]=0;
			mn=dis(i,j)+1;
		}
	}
	while(!q.empty())
	{
		int x=q.front().first,y=q.front().second;
		q.pop();
		if(dist[x][y]==k)break;
		for(int i=0;i<4;i++)
		{
			int xx=x+dx[i],yy=y+dy[i];
			if(xx>=0&&xx<n&&yy>=0&&yy<m&&s[xx][yy]=='.'&&dist[xx][yy]==-1)
			{
				dist[xx][yy]=dist[x][y]+1;
				q.push(make_pair(xx,yy));
				mn=min(mn,dis(xx,yy)+1);
			}
		}
	}
	printf("%d\n",mn);
	return 0;
}

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

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

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


int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n;
    cin >> n;
    cout << (n + 999) / 1000 * 1000 - n << endl;
}

Measured memory_bytes: 3640
import copy
N=int(input())
l=[]
for i in range(N):
  l.append(int(input()))
M=max(l)
L=copy.copy(l)
l.remove(M)
m=max(l)
for j in range(N):
  if L[j]==M:
    print(m)
  else:
    print(M) 

Measured memory_bytes: 14560
#include <bits/stdc++.h>
using namespace std;
using Int = long long;
vector<vector<int>> G;
vector<double> up, down, ans;
void recur1(int node, int prev) {
    vector<int> A;
    for (int next : G[node]) if (next != prev) A.push_back(next);
    for (int next : A) {
        recur1(next, node);
        down[node] += down[next];
    }
    if (A.size() != 0) {
        down[node] /= A.size();
    }
    down[node] += 1;
}
void recur2(int node, int prev) {
    double total = 0;
    int cnt = 0;
    if (prev == -1) {
        up[node] = 0;
        ans[node] = down[node];
    } else {
        total += up[node];
        cnt += 1;
    }
    for (int next : G[node]) if (next != prev) {
        total += down[next];
        cnt += 1;
    }
    ans[node] = total / cnt;
    for (int next : G[node]) if (next != prev) {
        if (cnt == 1) {
            up[next] = 1;
        } else {
            up[next] = 1 + (total - down[next]) / (cnt - 1);
        }
        recur2(next, node);
    }
}
int main() {
    cin.tie(nullptr); ios::sync_with_stdio(false);
    int N; cin >> N;
    G.resize(N), up.resize(N), down.resize(N), ans.resize(N);
    for (int i = 0; i < N - 1; i++) {
        int u, v; cin >> u >> v; u--, v--;
        G[u].push_back(v);
        G[v].push_back(u);
    }
    recur1(0, -1);
    recur2(0, -1);
    cout << fixed << setprecision(9);
    for (int i = 0; i < N; i++) {
        cout << ans[i] << '\n';
    }
    return 0;
}


Measured memory_bytes: 24320
//Atcoder Beginner Contest 085 C
#include<iostream>
using namespace std;
 
int main(){
	int N, Y;
	int x, y, z;
	
	cin >> N >> Y;
	
	for (x=0; x<=Y/10000; x++)
	  for (y=0; y<=Y/5000; y++)
	    {
	    	z=N - x - y;
	    	if ( z>=0 && x*10000+y*5000+z*1000==Y )
	    	{
	    	   cout << x <<" " << y << " " << z;
	    	   return 0;
	        }
	    }
	
	cout << "-1 -1 -1";
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main() {
	int64_t n;
	cin >> n;
	vector<int> p(n);
	for (int i = 0; i < n; i++) cin >> p.at(i);

	int64_t ans = 0;
	int64_t low = 10000000000;
	for (int i = 0; i < n; i++) {
		if (p.at(i) <= low) {
			ans++;
			low = p.at(i);
		}
	}
	cout << ans << endl;
}

Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
int calcAddOrder(int n){
    int sum = 0;
    while(n > 0){
        sum += n % 10;
        n /= 10;
    }
    return sum;
}

int main(){
    int N, A, B;
    cin >> N >> A >> B;
    int total = 0;
    int sum = 0;
    for(int i = 0; i <= N; i++){
        sum = calcAddOrder(i);
        if(sum >= A && sum <= B){
            total += i;
        }
    }
    cout << total << endl;
}



Measured memory_bytes: 256
import math

X = int(input())

def prime(num):
    if num < 2:
        return False
    if num == 2:
        return True
    if num % 2 == 0:
        return False

    m = math.floor(num/2) + 1
    for p in range(3, m, 2):
        if num % p == 0:
            return False
    return True

while prime(X) == False:
    X += 1

print(X)

Measured memory_bytes: 9172
from sys import stdin

n, m = [int(i) for i in stdin.readline().rstrip().split()]
a = [-1] + [int(stdin.readline()) for _ in range(m)] + [n+1]

fib_l = [-1] * (n+3)

def make_fib(n):
    fib_l[0] = fib_l[1] = 1
    for i in range(2, n):
        fib_l[i] = fib_l[i-1] + fib_l[i-2]

make_fib(n+3)
ret = 1
for i in range(m+1):
    t = a[i+1] - a[i] - 2
    if t < 0:
        ret = 0
        break
    ret *= fib_l[t]
print(ret % 1000000007)

Measured memory_bytes: 464008
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
ll solve(vector<ll> vec)
{
    ll pos_sum = 0;
    int cnt = 0;
    ll positive_min = INT_MAX;
    ll negtive_max = INT_MIN;
    ll neg_sum = 0;
    for(ll x:vec)
    {
        if(x<0)
            cnt++, neg_sum += x, negtive_max = max(negtive_max, x);
        else
            positive_min = min(positive_min,x), pos_sum += x;
    }
    if(cnt % 2 == 0)
    {
        return pos_sum - neg_sum;
    }
    return max(pos_sum - neg_sum - positive_min*2, pos_sum - neg_sum + negtive_max * 2);
}
int main()
{
    int n;
    cin>>n;
    vector<ll> dat(n);
    for(int i=0;i<n;++i)cin>>dat[i];
    cout<<solve(dat);
}

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

int f(int x) {
  int count = 0;
  
  while(x % 2 == 0){
    x /= 2;
    count++;
  }
  
  return count;
}

int main() {
  int n, i;
  cin >> n;
  
  vector<int> a(n), b(n);
  for(i = 0; i < n; i++){
    cin >> a.at(i);
    b.at(i) = f(a.at(i));
  }
  
  sort(b.begin(), b.end());
  
  cout << b.at(0) << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <boost/multiprecision/cpp_int.hpp>

using boost::multiprecision::cpp_int;
using namespace std;

#if __has_include("print.hpp")
  #include "print.hpp"
#endif

#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define ALL(x) (x).begin(), (x).end()
#define RALL(x) (x).rbegin(), (x).rend()
#define MOD 1000000007

typedef long long ll;
typedef pair<ll, ll> p;


int main(){
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n;
  string s;
  cin >> n >> s;
  string tmp = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
  for(auto a : s){
    int tmp2 = a - 'A';
    cout << tmp[(tmp2 + n) % 26];
  }
  cout << endl;
}


Measured memory_bytes: 256
#include <cstdio>
using namespace std;
double sequence(double a) {
  double s[10];
  double sum = 0;
  for(int i = 0; i < 10; ++i) {
	if(i == 0) {
	  s[i] = a;
	}
	else if(i % 2) { // odd
	  s[i] = s[i - 1] * 2;
	}
	else { // even
	  s[i] = s[i - 1] / 3;
	}
	sum += s[i];
  }
  return sum;
}
int main() {
  double a;
  while(~scanf("%lf", &a)) {
	printf("%.8f\n", sequence(a));
  }
  return 0;
}

Measured memory_bytes: 2576
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<iomanip>
#include<math.h>
#include<complex>
#include<queue>
#include<deque>
#include<stack>
#include<map>
#include<set>
#include<bitset>
#include<functional>
#include<assert.h>
#include<numeric>

using namespace std;

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

using ll = long long;
const int inf=1e9+7;
const ll longinf=1LL<<60 ;
const ll mod=1e9+7 ;

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
	
  	ll a;
    string b;
    cin >> a >> b;
    ll b100 = (b[0] - '0')*100 + (b[2] - '0') * 10 + (b[3] - '0');
    ll res = a * b100 / 100;
    cout << res << "\n";
                
}


Measured memory_bytes: 3636