akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <algorithm>
using namespace std;
typedef long long int ll;
int main(void){
    ll n;
    cin >> n;
    ll b[3*n+4];
    for(ll i=1;i<=n;i++){
        cin >> b[i];
        b[n+i] = b[i];
        b[2*n+i] = b[i];
    }
    b[0]=b[n];
    ll c = 0;
    for(ll i=1;i<=n;i++){
        c += b[i];
    }
    c = c / 2;
    ll odd = 0;
    for(ll i=1;i<=n;i+=2){
        odd += b[i];
    }
    odd -= b[1];
    ll even = 0;
    for(ll i=2;i<=n;i+=2){
        even += b[i];
    }
    for(ll i=1;i<=n;i++){
        ll ans = 0;
        if(i % 2 == 0){
            cout << 2*(c-odd) << " ";
            odd = b[i+n]-b[i+1]+odd;
        }
        if(i % 2 == 1){
            cout << 2*(c-even) << " ";
            even = b[i+n]-b[i+1]+even;
        }
    }
}


Measured memory_bytes: 3712
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <sstream>
#include <queue>
#include <deque>
#include <bitset>
#include <iterator>
#include <list>
#include <stack>
#include <map>
#include <set>
#include <functional>
#include <numeric>
#include <utility>
#include <limits>
#include <time.h>
#include <math.h>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <assert.h>
#include <iomanip>

using namespace std;

int main(){
	int n, k;
	cin >> n >> k;
	if(n >= 10)
		cout << k << endl;
	else
		cout << 100*(10-n)+k << endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
static const int MOD = 1000000007;
using ll = long long;
int main(){
    int a,b;
    cin>>a>>b;
    int c;
    if(a>b){
        c=b;
        for(int i=1; i<a; i++){
            b*=10;
            c+=b;
        }
    }
    else{
        c=a;
        for(int i=1; i<b; i++){
            a*=10;
            c+=a;
        }
    }
    cout<<c<<endl;
    
   
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<map>
#include<set>
#include<utility>
#include<cmath>
#include <iomanip>
using namespace std;
int main(){
    int N, M;
    cin >> N >> M;
    int L[100000], R[100000];
    for (int i = 0; i < M; i++){
        cin >> L[i] >> R[i];
    }
    int left = 0;
    int right = 200000;
    for (int i = 0; i < M; i++){
        if(left < L[i]){
            left = L[i];
        }
        if(R[i] < right){
            right = R[i];
        }
    }
    if(right - left >= 0){
        cout << right - left + 1 << endl;
    }
    else{
        cout << 0 << endl;
    }
    return 0;
}

Measured memory_bytes: 1024
//q033.cpp
//Sat Aug 15 14:51:36 2020

#include <iostream>
#include <string>
#include <queue>
#include <map>
#include <unordered_map>
#include <vector>
#include <algorithm>
#include <math.h>
#include <set>
#define INTINF 2147483647
#define LLINF 9223372036854775807
#define MOD 1000000007
#define rep(i,n) for (int i=0;i<(n);++i)

using namespace std;
using ll=long long;
typedef pair<int,int> P;

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

	string s[h];
	rep(i,h) cin >> s[i];

	queue<P> q;
	q.push(P(0,0));

	int movex[4] = {0,1,0,-1};
	int movey[4] = {1,0,-1,0};

	int d[h][w];
	int whitenum = 0;
	rep(i,h)rep(j,w){
		d[i][j] = -1;
		if (s[i][j]=='.'){
			whitenum++;
		}
	}
	d[0][0] = 1;
	while (!q.empty()){
		P cur = q.front();q.pop();
		rep(i,4){
			P next = P(cur.first+movex[i],cur.second+movey[i]);
			if (next.first<0 || next.first>h-1 ||
				next.second<0 || next.second>w-1 ||
				d[next.first][next.second]!=-1 ||
				s[next.first][next.second]=='#'){
				continue;
			}
			d[next.first][next.second] = d[cur.first][cur.second]+1;
			q.push(next);
			if (next.first==h-1 && next.second==w-1){
				cout << whitenum-d[next.first][next.second] << endl;
				return 0;
			}
		}
	}
	cout << -1 << endl;

}

Measured memory_bytes: 3620
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n) ;i++)

using namespace std;
using p=pair<int,int>;
typedef long long ll;
const int MX = 100005;

int main() {
  int n;
  cin >> n;
  vector<ll>cnt(MX);
  rep(i,n){
    int a;
    cin >> a;
    cnt[a]++;
  }
  ll o =0;
  rep(i,MX){
    o+=i*cnt[i];
  }
  int q;
  cin >>q;
  rep(i,q){
    int b,c;
    cin >>b >> c;
    o-=b*cnt[b];
    o-=c*cnt[c];
    cnt[c]+=cnt[b];cnt[b]=0;
    o+=b*cnt[b];
    o+=c*cnt[c];
    cout << o << endl;
  }
  

  return 0;

}




Measured memory_bytes: 4028
import sys
import collections

# input処理を高速化する
input = sys.stdin.readline

def chmax(a, b):
    """ 最大値を返す関数 """
    if a >= b:
        return a
    else:
        return b

def main():  
    # 入力
    N, M = map(int, input().split())
    # 隣接関係は隣接リストで管理する
    lst_edge = [[] for _ in range(N)]
    # 各頂点の入力辺の本数
    deg = [0] * N  
    for _ in range(M):
        x, y = map(int, input().split())
        # 最初のindexをゼロにする
        lst_edge[x-1].append(y-1)
        deg[y-1] += 1
    
    # 入力辺を持たない頂点をqueueに入れる
    que = collections.deque()
    for v in range(N):
        if deg[v] == 0:
            que.append(v)

    # 各頂点の最初に入力辺を持たなかった点からの距離
    dp = [0] * N  

    while len(que) > 0:
        v = que.popleft()
        lst_nv = lst_edge[v]
        for nv in lst_nv:
            # エッジ(v, nv)をグラフから削除する
            deg[nv] -= 1
            if deg[nv] == 0:
                # エッジがなくなったことで、入力辺がなくなったらqueueに入れる
                que.append(nv)
                # 最初に入力辺を持たなかった点からの距離
                dp[nv] = chmax(dp[nv], dp[v] + 1)
    
    print(max(dp))


main()

Measured memory_bytes: 23028
import java.util.Scanner;

public class Main {
	private static Scanner sc;

	public static void main(String[] args) throws Exception {
		sc = new Scanner(System.in);
		int r = sc.nextInt();
		int D = sc.nextInt();
		int x = sc.nextInt();

		int a = 0;

		for (int i = 0; i < 10; i++) {
			if (i == 0) {
				a = r * x - D;
			} else {
				a = r * a - D;

			}
			System.out.println(a);
		}

	}
}


Measured memory_bytes: 21844
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <iomanip>
#include <stack>
#include <algorithm>
#include <string>
#include <map>
#include <iterator>

using namespace std;

int main() {

    int N;
    cin >> N;

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

    for (int i = 0; i < N; ++i) {
        cout << bs[i] << endl;
    }


    return 0;

}

Measured memory_bytes: 4052
#include <iostream>
#include <vector>

int counter = 0;
int n,m;
std::vector<std::vector<int>> d;
std::vector<int> buf;

bool check( std::vector<int>* buf, std::vector<std::vector<int>>* d ){
  for( int i=0; i<m; ++i ){
    int c=0;
    for( int j=0; j<n; ++j ){
      if ( ((*buf)[j]) && ((*d)[i][j]) ){ ++c; }
    }
    if ( (c % 2) != (*d)[i][n] ){ return false; }
  }
  return true;
}

void func( int num, std::vector<int>* buf, std::vector<std::vector<int>>* d ){
  if ( num > 0 ){
    (*buf)[num] = 0; func( num-1, buf, d );
    (*buf)[num] = 1; func( num-1, buf, d );
  } else {
    (*buf)[0]=0; if ( check(buf,d) ){ counter++; }
    (*buf)[0]=1; if ( check(buf,d) ){ counter++; }
  }
  return;
}

int main(){
  std::cin >> n >> m;
  std::vector<std::vector<int>> d(m,std::vector<int>(n+1));
  std::vector<int> buf(n);
  for( int i=0; i < m; ++i ){
    int hoge; std::cin >> hoge;
    for ( int j=0; j < hoge; ++j ){
      int h1; std::cin >> h1;
      d[i][h1-1]=1;
    }
  }
  for( int i=0; i < m; ++i ){
    std::cin >> d[i][n];
  }
  func( n-1, &buf, &d );
  std::cout << counter << std::endl;
  return 0;
}

Measured memory_bytes: 256
// template version 1.6
// {{{ define basic macro
using namespace std;
#include <iostream>
#include <bits/stdc++.h>

// varibable settings
#define int long long
#define INF 1000000000000000000LL
#define MOD 1000000007LL

// test-case
#define infile "../test/sample-1.in"

// rep
#define _overload3(_1,_2,_3,name,...) name
#define _rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(int i=(int)(a);i<(int)(b);++i)
#define rep(...) _overload3(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)
#define _rrep(i,n) rrepi(i,0,n)
#define rrepi(i,a,b) for(int i=(int)(b-1);i>=(int)(a);--i)
#define rrep(...) _overload3(__VA_ARGS__,rrepi,_rrep,)(__VA_ARGS__)

#define all(x) (x).begin(),(x).end()
#define sz(x) ((int)(x).size())
#define pb(a) push_back(a)
#define mp(a, b) make_pair(a, b)
#define uni(x) sort(all(x));x.erase(unique(all(x)),x.end())
#define ten(n) ((int)1e##n)
template<class T, size_t N> size_t sza(const T (&array)[N]) { return N; }
template<class T> inline void chmax(T &a, const T &b) { if(a < b) a = b; }
template<class T> inline void chmin(T &a, const T &b) { if(a > b) a = b; }
template<class T=int> T in() {T x; cin>>x; return (x);}
struct Fast { Fast(){ std::cin.tie(0); ios::sync_with_stdio(false); } } fast;

// dump macro
#ifdef PCM
  #include "dump.hpp"
#else
  #define dump(...) 42
  #define dump_1d(...) 42
  #define dump_2d(...) 42
#endif

typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef long double ld;
typedef pair<int,int> pii;
typedef tuple<int,int,int> iii;
template<typename T> using PQ = priority_queue<T, vector<T>, greater<T>>;
int dx[]={1, -1, 0, 0};
int dy[]={0, 0, 1, -1};
#define fi first
#define se second

// }}}

// init
#define MAX_N 300
int d[MAX_N][MAX_N]={};  // d →　a が目標

int solve(){
  int n;cin>>n;
  int a[n][n];
  rep(i, n)rep(j, n){ d[i][j] = (i==j ? 0 : INF);}

  PQ<pair<int, pii>> pq; // (cost, pair)
  rep(i, n)rep(j, n){
    cin>>a[i][j]; 
    if (i<=j) continue;
    pq.push(mp(a[i][j], mp(i, j)));
  }

  int res = 0;
  while(!pq.empty()){
    auto p = pq.top();
    pq.pop();
    int cost = p.fi;
    auto comb = p.se;
    if (cost < d[comb.fi][comb.se]){  // costを小さくしなければいけない。
      // 直接つなぐ操作に限定される。
      // 仮にどこかの迂回ルート(i - ... - j)短縮or接続してこれが達成されると仮定すると矛盾。
      // 既にpriority queから片付けた辺はd[i][j]=a[i][j]が達成されており短縮不可能。片付けていない辺はcost以上なので迂回してもcostを達成できないからである。
      d[comb.fi][comb.se] = cost;
      d[comb.se][comb.fi] = cost;
      res += cost;
      rep(i, n) rep(j, n){  // like warsharllfroid
        chmin(d[i][j], d[i][comb.fi]+d[comb.se][j]+cost);
        chmin(d[i][j], d[i][comb.se]+d[comb.fi][j]+cost);
        chmin(d[j][i], d[i][j]);
      }
    }
    else if(cost == d[comb.fi][comb.se]){  // 今までつないだ辺で達成済み
      //pass
    }
    else if(cost > d[comb.fi][comb.se]){  // 今までつないだ辺は必要条件だったが、それにより成約が満たされなくなっているペアが存在。
      cout << -1 << endl;
      return 0;
    }
  }
  cout << res << endl;

  return 0;
}

signed main() { //{{{
#ifdef INPUT_FROM_FILE
  std::ifstream in(infile);
  std::cin.rdbuf(in.rdbuf());
#endif
  solve();
  return 0;
} //}}}


Measured memory_bytes: 3192
#include <algorithm>
#include <array>
#include <bitset>
#include <cassert>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstring>
#include <deque>
#include <functional>
#include <iomanip>
#include <locale>
#include <iostream>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <sstream>
#include <string>
#include <tuple>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>

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

using namespace std;

using ll = long long;
using ld = long double;

template <typename T> T &chmin(T &a, const T &b) { return a = min(a, b); }
template <typename T> T &chmax(T &a, const T &b) { return a = max(a, b); }
template <typename T> int len(const T &x) { return x.size(); }

template<typename T>
vector<T> table(int n, T v) { return vector<T>(n, v); }

template <class... Args>
auto table(int n, Args... args) {
  auto val = table(args...);
  return vector<decltype(val)>(n, move(val));
}

struct yes_no : numpunct<char> {
  string_type do_truename()  const { return "YES"; }
  string_type do_falsename() const { return "NO"; }
};

ll sums[128000];
ll sumt[128000];

void solve(string S, string T, ll q, vector<ll> a, vector<ll> b, vector<ll> c, vector<ll> d) {
  REP(i,S.size()) sums[i + 1] = sums[i] + (S[i] == 'A' ? 1 : 2);
  REP(i,T.size()) sumt[i + 1] = sumt[i] + (T[i] == 'A' ? 1 : 2);
  REP(i,q) {
    ll ds = sums[b[i]] - sums[a[i] - 1];
    ll dt = sumt[d[i]] - sumt[c[i] - 1];
    cout << ((ds + dt * 2) % 3 == 0) << endl;
  }
}

int main() {
  locale loc(locale(), new yes_no);
  cout << boolalpha << setprecision(12) << fixed;
  cout.imbue(loc);
	string S;
	ll q;
	string T;
	cin >> S;
	cin >> T;
	scanf("%lld", &q);
	vector<ll> d(q-1+1);
	vector<ll> c(q-1+1);
	vector<ll> a(q-1+1);
	vector<ll> b(q-1+1);
	for (int i = 0 ; i <= q-1 ; i++) {
	  scanf("%lld", &a[i]);
	  scanf("%lld", &b[i]);
	  scanf("%lld", &c[i]);
	  scanf("%lld", &d[i]);
	}
	solve(S, T, q, a, b, c, d);
	return 0;
}


Measured memory_bytes: 8832
#include <bits/stdc++.h> 
using namespace std; 
#define int long long
int32_t main() 
{ 
	int h,n;
	cin>>h>>n;
	int s=0;
	while(n--){
		int t;
		cin>>t;
		s+=t;
	}
	if(s>=h)
		cout<<"Yes";
	else
		cout<<"No";
} 


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

int main(int argc, char** argv)
{
	char s[105];
	int k, n = -1;
	scanf("%d%s", &k, s);
	while(true)
	{
		if(s[++n] == '\0') return 0;
		if(n >= k)
		{
			puts("...");
			return 0;
		}		
		putchar(s[n]);
	}
	return 0;
}

Measured memory_bytes: 1648
#include<stdio.h>

int main(void) {

	int x;
	int i = 1;

	

	while (1) {
		scanf("%d", &x);
		if (x == 0) 
			break; //xが0で抜ける

		printf("Case %d: %d\n", i, x);
		i++;

	}

	return(0);

}


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

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

    vector <int> v(n);
    for (int i = 0; i < n; i++) cin >> v[i];

    int count = 0;
    for (int i = 0; i < n; i++) {
        int mn = v[i];
        int mn_idx = i;
        for (int j = i + 1; j < n; j++) {
            if (v[j] < mn) {
                mn = v[j];
                mn_idx = j;
            }
        }

        if (i != mn_idx) {
            count++;
            swap(v[i], v[mn_idx]);
        }
    }

    for (int j = 0; j < n; j++) {
        if (j) cout << " ";
        cout << v[j];
    }
    cout << "\n";

    cout << count << '\n';
    return 0;
}


Measured memory_bytes: 3112
n,x=map(int,input().split())
h=0
while (n>0 or x>0):
    for i in range(1,n+1):
        for k in range(i+1,n+1):
            for l in range(k+1,n+1):
                if (i+k+l==x):
                    if (not i==l):
                        if (not i==k):
                            if (not l==k):
                                h+=1
    print(h)
    h=0
    n,x=map(int,input().split())


Measured memory_bytes: 5592
N = int(input())
l = []
r = []
for i in range(N):
    temp_l, temp_r = input().split()
    l.append(int(temp_l))
    r.append(int(temp_r))
ans = 0
for i in range(N):
    ans += r[i] - l[i] + 1
print(ans)

Measured memory_bytes: 3060
import core.bitop;
import std.algorithm;
import std.ascii;
import std.bigint;
import std.conv;
import std.functional;
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()
{
    char[] s, t;
    scan!(char[])(s);
    scan!(char[])(t);
    auto S = cast(byte[]) s;
    auto T = cast(byte[]) t;
    S.sort();
    T.sort();
    T.reverse();
    // writeln(S);
    // writeln(T);
    writeln(S < T ? "Yes" : "No");
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using vi=vector<int>;
using vvi=vector<vi>;
using pii=pair<int,int>;
#define rep(i,n) for(int i=0;i<n;i++)
#define range(i,a,n) for(int i=a;i<n;i++)
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define INF 1e9
#define EPS 1e-9
#define MOD (1e9+7)
void put(string d){}template<class H,class...T>void put(string d,H&h,T&...t){cout<<h;if(sizeof...(t))cout<<d;put(d,t...);}
template<class T>void puti(T&a,string d=" "){bool f=1;for(auto&_:a)cout<<(exchange(f,0)?"":d)<<_;cout<<endl;}
template<class T>void putii(T&a,string d=" "){for(auto&_:a)puti(_,d);}

int main(){
	int h,w,n; cin>>h>>w>>n;
	vvi ans(h,vi(w));
	int c=0;int ink=0;
	rep(i,h)rep(j,w){
		if(ink==0){
			cin>>ink; c++;
		}
		ans[i][i%2?w-1-j:j]=c;
		ink--;
	}
	putii(ans);
	return 0;
}


Measured memory_bytes: 384
#include<iostream>
#include<algorithm>
using namespace std;
int a[6], dp[1000000], p[6] = { 1,5,10,50,100,500 };
int main() {
	for (int i = 1; i < 1000000; i++)dp[i] = 1 << 30;
	for (int i = 0; i < 6; i++) {
		for (int j = 0; j < 700000; j++) {
			dp[j + p[i]] = min(dp[j + p[i]], dp[j] + 1);
		}
	}
	while (true) {
		int c, res = 100000; cin >> c; for (int i = 0; i < 6; i++) { cin >> a[i]; }if (c == 0)break;
		for (int i = c; i < 670000; i++) {
			int h = i, c1 = 0;
			for (int j = 5; j >= 0; j--) {
				int Z = h / p[j];
				if (Z > a[j]) { h -= a[j] * p[j]; c1 += a[j]; }
				else { h -= Z*p[j]; c1 += Z; }
			}
			if (h == 0) { res = min(res, dp[i - c] + c1); }
		}
		cout << res << endl;
	}
	return 0;
}

Measured memory_bytes: 6916
#include<iostream>
using namespace std;
int main(){
  int n;
  cin>>n;
  long long arr[n];
  for(int i=0;i<n;i++)
    cin>>arr[i];
  unsigned long long int ans = 1;

  for(int i=0;i<n;i++){
  	if(arr[i]==0){
  		cout<<0<<endl;
  		return 0;
  	}
  }

  for(int i=0;i<n;i++){
    if(arr[i]>1000000000000000000/ans){
      cout<<-1<<endl;
      return 0;
    }
    ans*=arr[i];
    
  }
    cout<<ans<<endl;  
  return 0;
}


Measured memory_bytes: 4324
#include <iostream>
#include <vector>
#include <algorithm>
#define eb emplace_back
int main(int argc, char const *argv[]) {
    long long n, h;
    std::cin >> n >> h;

    long long w, t;
    std::vector<long long> wList, tList;
    while(std::cin >> w >> t){
        wList.eb(w);
        tList.eb(t);
    }
    long long c = 0;
    std::sort(wList.begin(), wList.end());
    std::sort(tList.begin(), tList.end());
    long long l = wList.back();
    for(auto end = tList.rbegin(); end != tList.rend(); ++end){
        if(*end > l){
            h -= *end;
            ++c;
        }else break;

        if(h <= 0) break;
    }
    if(h > 0) c += (((h - h / l * l) > 0 ? 1 : 0) + h / l);
    std::cout << c << std::endl;
    return 0;
}

Measured memory_bytes: 2036
#include <bits/stdc++.h>
#define rep(i , n) for (int i = 0; i < (int)(n); i++)
const int INF = 1<<29;
using namespace std;
using ll = long long;
int main(){
    int N , M;
    cin >> N >> M;
    vector <int> a(M) , b(M);
    for(int i = 0; i < M; i++){
        cin >> a[i] >> b[i];
    }
    vector <int> c;
    int C = 0;
    bool t = false;
    for(int i = 0; i < M; i++){
        if(b[i] == N){
            c.push_back(a[i]);
            C++;
        }
    }
    for(int i = 0; i < M; i++){
        if(a[i] == 1){
            c.push_back(b[i]);
            C++;
        }
    }
    sort(c.begin() , c.end());
    for(int i = 0; i < C - 1; i++){
        if(c[i] == c[i + 1]){
            t = true;
        }
    }
    if(t){
        cout << "POSSIBLE" << endl;
    }
    else{
        cout << "IMPOSSIBLE" << endl;
    }
}

Measured memory_bytes: 5880
///////////////////////////////////////////
//                                       //
//      Gagan_Sharma : DTU               // 
//                                       //                   
///////////////////////////////////////////
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

using namespace std;
using namespace __gnu_pbds;

#define int     long long
// #define mp      make_pair
#define eb      emplace_back
#define pb      push_back
#define ss      second
#define ff      first
#define IOS     ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define mod     998244353
#define MOD     (1000*1000*1000+7)
#define MN      LLONG_MIN
#define MX      LLONG_MAX
#define v1d     vector<int>
#define v2d     vector<vector<int>>
#define vip     vector<pair<int,int> >
#define v1s     vector<string>
#define pa      pair<int,int>
#define print(v) for(auto i:v)cout<<i<<" ";cout<<"\n";
#define endl    '\n'
#define input(b,n) for(int i=0;i<n;i++)cin>>b[i+1];
#define Sort(v) sort(v.begin(),v.end())
#define RSort(v)   sort(v.rbegin(),v.rend())
#define all(v)  v.begin(),v.end()
int gcd(int a,int b){return b?gcd(b,a%b):a;}
//string s = bitset<64>(a).to_string();

typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;
#define fbo find_by_order // iterator to the kth element
#define ook order_of_key  //number of items that are strictly smaller than our item k
#define T pair<int, int>
// #define ordered_set tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>

void read(int n=12){
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    cout<<setprecision(n)<<fixed;
    #ifndef ONLINE_JUDGE
         freopen("input.txt",  "r",  stdin);
         freopen("output.txt", "w", stdout);
    #endif
}


void solve(){
    int n;cin>>n;
    int sum = 0;
    for(int a=1;a<=n;a++){
        for(int b=1;b<=n;b++){
            int g = __gcd(a,b);
            for(int c=1;c<=n;c++){
                sum += __gcd(g,c);
            }
        }
    }
    cout<<sum;

}
 
int32_t main(){
    // read();
    int t = 1;
    // cin>>t;
    while(t--){
        solve();
    }
    


    return 0;
}                                                                                         

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

namespace Illumination {
	struct Position {
		public int X { get; private set; }
		public int Y { get; private set; }
		public Position(int x, int y)
			: this() {
			X = x;
			Y = y;
		}
		public Position[] GetNeighbors() {
			Position[] neighbors = new Position[6];
			if (Y % 2 == 0) {
				neighbors[0] = new Position(X + 0, Y - 1);
				neighbors[1] = new Position(X + 1, Y + 0);
				neighbors[2] = new Position(X + 0, Y + 1);
				neighbors[3] = new Position(X - 1, Y + 1);
				neighbors[4] = new Position(X - 1, Y + 0);
				neighbors[5] = new Position(X - 1, Y - 1);
			}
			else {
				neighbors[0] = new Position(X + 1, Y - 1);
				neighbors[1] = new Position(X + 1, Y + 0);
				neighbors[2] = new Position(X + 1, Y + 1);
				neighbors[3] = new Position(X + 0, Y + 1);
				neighbors[4] = new Position(X - 1, Y + 0);
				neighbors[5] = new Position(X + 0, Y - 1);
			}
			return neighbors;
		}
	}

	class Illumination {
		public const int Outside = 0;	// 建物ではなく、外に繋がっている
		public const int Inside = 1;	// 建物ではなく、外に繋がっていない
		public const int Building = 2;	// 建物

		static void Main(string[] args) {
			int W, H;
			string[] str = Console.ReadLine().Split(' ');
			W = int.Parse(str[0]);
			H = int.Parse(str[1]);
			int[,] map = new int[W + 2, H + 2];
			List<Position> bldgPositions = new List<Position>();
			List<Position> nobldgCircuitPositions = new List<Position>();
			for (int y = 1; y <= H; y++) {
				str = Console.ReadLine().Split(' ');
				for (int x = 1; x <= W; x++) {
					if (int.Parse(str[x - 1]) == 0) {		//noBuilding
						map[x, y] = Inside;
						if (x == 1 || x == W || y == 1 || y == H) nobldgCircuitPositions.Add(new Position(x, y));
					}
					else {									//Building
						map[x, y] = Building;
						bldgPositions.Add(new Position(x, y));
					}
				}
			}
			
			Action<Position> seekOutside = null;
			seekOutside = p => {
				if (map[p.X, p.Y] == Inside) {
					map[p.X, p.Y] = Outside;
					foreach (var np in p.GetNeighbors()) seekOutside(np);
				}
			};
			foreach (var p in nobldgCircuitPositions) seekOutside(p);
			Console.WriteLine(bldgPositions.Sum(p => p.GetNeighbors().Count(np => map[np.X, np.Y] == Outside)));
		}
	}
}

Measured memory_bytes: 21364
#include<stdio.h>
#define N 1000

int main(void){
  int i,num;
  int side1[N]={0},side2[N]={0},diag[N]={0};
  int rectC=0,rhomC=0;
  char sandbox;

  for(i=0;(scanf("%d%c%d%c%d",&side1[i],&sandbox,&side2[i],&sandbox,&diag[i]))==5;i++){}
  num=i;
  for(i=0;i<num;i++){
    if((side1[i]*side1[i]+side2[i]*side2[i])==diag[i]*diag[i])  rectC++;
    if(side1[i]==side2[i])  rhomC++;
  }
  printf("%d\n%d\n",rectC,rhomC);
  return 0;
}

Measured memory_bytes: 0
import sys
from collections import deque

sys.setrecursionlimit(4100000)


def inputs(num_of_input):
    ins = [input() for i in range(num_of_input)]
    return ins


def solve(inputs):
    N_STR = inputs[0]
    N = int(N_STR)

    if len(N_STR) <= 2:
        return 0

    def check_over(string):
        if int(string) > N:
            return False
        return True

    def check_all_appered(string):
        does_appered = {
            '3': False,
            '5': False,
            '7': False
        }

        for s in string:
            if s in does_appered:
                does_appered[s] = True
        are_all_true = True
        for d in does_appered.values():
            are_all_true = are_all_true and d
        return are_all_true

    def create_s(origin, until_len):
        if len(origin) == until_len:
            return [origin]

        ret = []
        ret += create_s(origin+'3', until_len)
        ret += create_s(origin+'5', until_len)
        ret += create_s(origin+'7', until_len)

        pop_items = []
        for i in range(0, len(ret)):
            if ret[i] is None \
                    or not check_all_appered(ret[i]) \
                    or not check_over(ret[i]):
                pop_items.append(i)
        for p in reversed(pop_items):
            ret.pop(p)

        return ret

    ret = []
    for i in range(3, len(N_STR)+1):
        ret += create_s('', i)
    return len(ret)


def string_to_int(string):
    return list(map(int, string.split()))


if __name__ == "__main__":
    ret = solve(inputs(1))
    print(ret)


Measured memory_bytes: 5484
import java.util.*;
public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		// 整数の入力
		int N = sc.nextInt();
        int M = sc.nextInt();
      	int Count[] = new int[N];
      	int i = 0;
      	for(i = 0;i < M * 2 ;i++){
		  Count[sc.nextInt() -1] += 1;
        }
      	for(i = 0;i < N; i++){
          System.out.println(Count[i]);   
        }

    }
}

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

int main(){
  string s;
  cin >> s;
  int ans=(s.size()%2==0);
  for(int i=0;i<s.size();i++){
    if(i%2) ans*=(s[i]=='i');
    else ans*=(s[i]=='h');
  }
  if(ans) cout << "Yes" << endl;
  else cout << "No" << endl;
}

Measured memory_bytes: 3636
#include<iostream>
using namespace std;
void trace(int A[],int N){
    for (int i = 0;i < N;i++){
        if (i > 0) cout << " ";
        cout << A[i];
        }
    cout << endl;
}

int selection_sort(int A[],int N){
    int count = 0;
    int minj;
    for (int i = 0;i < N - 1;i++){
        minj = i;
        for (int j = i;j <= N - 1;j++){
            if (A[j] < A[minj]) minj = j;
        }
        swap(A[i],A[minj]);
        if (i != minj) count += 1;
    }
    return count;
}

int main(){
    int A[100],N,count;
    cin >> N;
    for (int i = 0;i < N;i++) cin >> A[i];
    count = selection_sort(A,N);
    trace(A,N);
    cout << count << endl;
    return 0;
}


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

const int MAXN = 3000 + 10;
int a[MAXN];
vector <int> adj[MAXN];

bool dfs(int v, int p = -1) {
	for (int i: adj[v])
		if (i != p) {
			if (a[i] >= a[v])
				continue;
			else if(!dfs(i, v))
				return true;
		}
	return false;
}

int main() {
	int n;
	cin >> n;
	for (int i = 0; i < n; i++)
		cin >> a[i];
	for (int i = 0; i < n - 1; i++) {
		int a, b;
		cin >> a >> b;
		a--, b--;
		adj[a].push_back(b);
		adj[b].push_back(a);
	}
	for (int i = 0; i < n; i++)
		if (dfs(i))
			cout << i + 1 << ' ';
}

Measured memory_bytes: 384
#include <cstdio>
#include <bits/stdc++.h>
#include <algorithm>
#include <iostream>
#include <string>
#include <cmath>
#include <functional>
#include <vector>
#include <stack>
#include <queue>
#include <map>
using ll = long long;
#define rep(i,n) for (ll i=0;i<n;i++)
using namespace std;


void solve(){

}
int main (){
    ios::sync_with_stdio(0);
    cin.tie(0);
    int d,t,s;
    cin >> d >> t >> s;
    if((d+s-1)/s <= t){
        cout << "Yes";
    }else{
        cout << "No";
    }

    return 0;
}

Measured memory_bytes: 3648
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <iostream>
#include <algorithm>
#include <utility>
#include <functional>
#include <string>
#include <vector>
#include <deque>
#include <queue>
#include <stack>
#include <list>
#include <set>
#include <map>
#include <unordered_map>

#define rep(i, n) for(int i = 0; i < (int)(n); i++)
using namespace std;
using ll = long long;
const int INF = (1<<30);
const ll INFL = (1LL<<62);
const int MOD = 1000000007;
template<class T> bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> T gcd(T a, T b) { return b ? gcd(b, a % b) : a; }
template<class T> T lcm(T a, T b) { return a / gcd(a, b) * b; }
template<class T> ll mod_pow(ll a, ll n, T mod) { mod=(ll)mod; ll res=1, p=a%mod; while(n){ if(n&1) res=res*p%mod; p=p*p%mod; n>>=1; } return res; }

bool prime(int num){
    if(num < 2) return false;
    if(num == 2) return true;
    for(int i=2; i*i <= num; i++){
        if(num % i == 0) return false;
    }
    return true;
}

int main() {
    int n;
    cin >> n;
    int cnt = 0;
    while(n--){
        int a;
        cin >> a;
        if(prime(a)) cnt++;
    }
    cout << cnt << endl;
    return 0;
}


Measured memory_bytes: 3076
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int x[12][12];
int main()
{
    int n, d, ans = 0; cin >> n >> d;
    ll a;
    for (int i = 0; i < n; i++){
        for (int j = 0; j < d; j++){
            cin >> a;
            x[i][j] = a;
        }
    }
    for (int i = 0; i < n-1; i++)
    {
        for (int j = i+1; j < n; j++)
        {
            a = 0;
            for (int k = 0; k < d; k++)
            {
                a += abs(x[i][k] - x[j][k]) * abs(x[i][k] - x[j][k]);
            }
            if(ceil(sqrt(a)) == floor(sqrt(a))) ans++;
        }   
    }
    cout << ans << endl;
}

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

int main() {
  int N;
  int flag = 0;
  cin >> N;
  for (int i = 0;i < N;i++){
    string col;
    cin >> col;
    if (col == "Y"){
      flag = 1;
      break;
    }
  }
  if (flag == 1)
    cout << "Four" << endl;
  else
    cout << "Three" << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <string>
#include <cstring>
#include <math.h>
#include <cmath>
#include <limits.h>
#include <map>
#include <set>
#include <queue>
#include <algorithm>
#include <functional>
#include <stdio.h>
using namespace std;

long long MOD = 1000000007;

int func( string s ) {
    int ret = 0;
    for ( int i = 0; i < s.length(); i++ ) {
        ret += s[i] - '0';
    }
    return ret;
}

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

    string x;
    bool isOne = (N[0] == '1');
    x += N[0];

    for ( int i = 0; i < N.length()-1; i++ ) {
        x += '9';
    }
    if ( x == N ) { cout << func(N) << endl; }
    else {
        if ( !isOne ) { x[0] = x[0]-1; }
        else { x.erase(0,1);}
        // cout << x << endl;
        cout << func(x) << endl;
    }
    

    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
int main(void){
    // Your code here!
    int n,m;
    long int k;
    scanf("%d %d %ld",&n,&m,&k);
    
    long int a[200000]={};
    long int as[200001]={};
    for(int i=0;i<n;i++)
    {
        scanf("%ld",&a[i]);
        if(i==0){
            as[i]=0;
        }
        as[i+1]=as[i]+a[i];
        
        //printf("%d %d\n",a[i],as[i]);
    }//printf("\n");
    
    long int b[200000]={};
    long int bs[200001]={};
    for(int i=0;i<m;i++)
    {
        scanf("%ld",&b[i]);
        if(i==0){
            bs[i]=0;
        }
        bs[i+1]=bs[i]+b[i];
        
        //printf("%d ",bs[i]);
    }//printf("\n");
    
    int num=0;
    int mo=m;
    for(int i=0;i<=n;i++)
    {
        if(as[i]>k)
        {
            break;
        }
        for(int j=mo;j>=0;j--)
        {
            if(as[i]+bs[j]<=k)
            {
                if(i+j>num)
                {
                    num=i+j;
                }
                mo=j;
                break;
            }
        }
        
    }
    
    
    printf("%d\n",num);
}

Measured memory_bytes: 7980
#include <bits/stdc++.h>
#define pb push_back
#define mp make_pair
#define ll long long int
#define ff first
#define ss second
#define S size()
#define mod (ll)(1e9+7)
#define mset(a,k) memset(a,k,sizeof(a))
#define fr(i, x, y) for ( ll i = x; i < y;i++)
#define dr(i, x, y) for ( ll i = x; i >= y; i--)
#define all(v) v.begin(), v.end()
#define pqueue priority_queue<ll>
#define piqueue priority_queue<ll,vll ,greater<ll>>
#define mapcl map<char,ll>
#define mapll map<ll,ll>
#define mapsl map<string,ll>
#define vi vector<ll>
#define vs vector<string>
#define vb vector<bool>
#define psi pair<string,ll>
#define pii pair<ll,ll>
#define piii pair<ll,pii>
#define vii vector<pii>
#define vvi vector<vi>
#define vvii vector<vii>
using namespace std;
void fast() {
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
}
//----------------------------------------FUNCTIONS-------------------------------------
ll gcd(ll x, ll y )						{if (y == 0) return x; return gcd(y, x % y);}
ll lcm(ll a, ll b)						{return (a * b) / gcd(a, b);}
ll logx(ll base, ll num)				{int cnt = 0; while (num != 1) {num /= base; ++cnt;} return cnt;}
vi vin(ll n)							{vi a(n); fr(i, 0, n) cin >> a[i]; return a;}
void out(vi a)							{for (int i = 0; i < (ll)a.S; i++) { cout << a[i] << " "; } cout << endl;}
void in(ll *a, ll n)        			{for (ll i = 0; i < n; i++)cin >> a[i];}
void out(ll *a, ll n)					{fr(i, 0, n) {cout << a[i] << " ";} cout << '\n';}
void out1(vi v)							{fr(i, 0, (ll)v.S) {cout << v[i] << " ";} cout << endl;}
const ll MAXN = (ll)(1 * 1e6 + 5 ), level = 22;

void solve()
{
	ll n;
	cin >> n;
	ll x = ceil(n / ((1000) * 1.0));
	cout << x * 1000 - n;
}
int main()
{

#ifndef ONLINE_JUDGE
	freopen ("inp4.txt", "r", stdin);
	freopen ("out4.txt", "w", stdout);
#endif
	fast();
	ll t = 1;
	//cin >> t;
	fr(i, 0, t)
	{
		solve();
	}
}

Measured memory_bytes: 3724
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;

namespace AtCoder
{
	public class Program
	{
		static void Main(string[] args)
		{

			int[] vs = Console.ReadLine().Split().Select(p => int.Parse(p)).ToArray();

			int a = vs[0];
			int b = vs[1];
			int k = vs[2];

			int c = 0;
			for (int i = a; i > 0; i--) {
				if (a % i == 0 && b % i == 0) {
					c++;
					if (c == k) {
						Console.WriteLine(i);
						return;
					}
				}
			}

		}
	}
}

Measured memory_bytes: 13396
import java.util.Scanner;

class Main{	
	
	public static void main (String[] args){
		Scanner sc = new Scanner(System.in);
		while(sc.hasNext()){
			int n = sc.nextInt();
			int syakkin = 100000;
			for(int i=0;i<n;i++){
				syakkin *= 1.05;
				syakkin += 999;
				syakkin /= 1000;
				syakkin *= 1000;
				
			}
			System.out.println(syakkin);
		}
	}
}

Measured memory_bytes: 11000
def Main(N, A, B):
    ans = 0
    remain = 0
    for i in range(N):
        if A[i] >= B[i]:
            ans += B[i]
        else: # A[i] < B[i]
            ans += A[i]
            remain = B[i]-A[i]
            next_attack = A[i+1]-remain
            if next_attack > 0:
                ans += remain
                A[i+1] -= remain
            else:
                ans += A[i+1]
                A[i+1] = 0
    return ans
        

def main():
    N = int(input())
    A = list(map(int, input().split()))
    B = list(map(int, input().split()))
    print(Main(N, A, B))


if __name__ == '__main__':
    main()


Measured memory_bytes: 18476
#define _USE_MATH_DEFINES
//#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define rep(i,n) for(int i=0;i<n;i++)
#define INF 1000000000000000000
#define MOD 1000000007
typedef pair<int, int> P;

bool prime(int n) {
	for (int i = 2; i <= sqrt(n); i++) {
		if (n % i == 0)return false;
	}
	return n != 1;
}
int gcd(int x, int y) {
	if (y == 0)return x;
	return gcd(y, x % y);
}
int lcm(int x, int y) {
	return x / gcd(x, y) * y;
}
int mod_pow(int n, int p, int m) {
	if (p == 0) return 1;
	if (p % 2 == 0) {
		int t = mod_pow(n, p / 2, m);
		return (t * t) % m;
	}
	return n * mod_pow(n, p - 1, m) % m;
}
int extGCD(int a, int b, int& x, int& y) {
	if (b == 0) {
		x = 1;
		y = 0;
		return a;
	}
	long long d = extGCD(b, a % b, y, x);
	y -= a / b * x;
	return d;
}
int modinv(int a, int m) {
	int b = m, u = 1, v = 0;
	while (b) {
		long long t = a / b;
		a -= t * b; swap(a, b);
		u -= t * v; swap(u, v);
	}
	u %= m;
	if (u < 0) u += m;
	return u;
}

signed main() {
	string s[8] = {"SUN", "MON","TUE","WED","THU","FRI","SAT","SUN" };
	string c;
	cin >> c;
	rep(i, 7) {
		if (c == s[i]) {
			cout << 7 - i << endl;
			return 0;
		}
	}

	return 0;
}


Measured memory_bytes: 256
#include <algorithm>
#include <iostream>
#include <stdio.h>
#include <string>

using namespace std;

int main() {
  string S;
  cin >> S;
  int cnt = 0;
  int _cnt = 0;
  for (int i = 0; i < S.size(); ++i) {
    if (S[i] == '0') {
      ++cnt;
    } else {
      ++_cnt;
    }
  }
  printf("%d\n", min(cnt, _cnt) * 2);
}

Measured memory_bytes: 3260
#include <bits/stdc++.h>
using namespace std;
#define endl '\n'
#define MOD 1e9+7

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

    int n,s = 0,mn = INT_MAX;

    cin >> n;

    vector<int> a(n);

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

    if(s%10>0){ cout << s; return 0; }

    sort(a.begin(),a.end());

    for(int i = 0;i < n;i++)
    {
        s-=a[i];
        if(s%10>0){ cout << s; return 0; }
        s+=a[i];
    }

    cout << "0";
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define sz(a) ((int)(a).size())
using namespace std;
// ===================== MANASH =================== //

int n,m;

void test() {

	string s,t;
	cin >> s >> t;
	assert(sz(s) == sz(t));
	int cnt = 0;
	for( int i = 0; i < sz(s); i++) {
		cnt += !(s[i] == t[i]);
	}
	cout << cnt;
}

signed main() {

	#ifdef LOCAL
	freopen("input.txt","r",stdin);
	#endif
	test();
	return 0;

}

Measured memory_bytes: 3928
#include <iostream>
#include <stdlib.h>

using namespace std;


bool check(string s){
  int size = s.size();
  if(size==1){
    return true;
  }
  bool flag = true;

  for (int i = 0; i < size; i++){
    int l = (i - 1) >= 0 ? i - 1 : i;
    int r = (i + 1) < size ? i + 1 : i;
    if(s[i]==s[l] && s[i]==s[r]){
      flag = false;
    }
  }

  return flag;
}

string createFlagStr(string s){
  string result;
  int size = s.size();
  result.resize(size);

  for (int i = 0; i < size;i++){
    int l = (i - 1) >= 0 ? i - 1 : i;
    int r = (i + 1) < size ? i + 1 : i;
    int bit = (s[i] != s[l]) + (s[i] != s[r]) * 2;
    if(i==l)
      bit += 1;
    if(i==r)
      bit += 2;
    result[i] = bit + '0';
  }
  return result;
}

int main(void){
  string S;
  cin >> S;

  // cout << S << endl;

  string flagS = createFlagStr(S);
  // cout << flagS << endl
  //      << endl;

  int size = S.size();
  string resultS = S;

  int count = 0;

  for (int i = 0; i < size - 1; i++){
    if(flagS[i]!='3' && flagS[i+1]!='3'){
      count++;
      resultS[i+1 ] = resultS[i+1] == '0' ? '1' : '0';

      for (int j = i; j < i + 3;j++){
        int l = (j - 1) >= 0 ? j - 1 : j;
        int r = (j + 1) < size ? j + 1 : j;
        int bit = (resultS[j] != resultS[l]) + (resultS[j] != resultS[r]) * 2;
        if(j==l)
          bit += 1;
        if(j==r)
          bit += 2;
        // resultS[j] = bit + '0';
        flagS[j] = bit + '0';
      }

      // flagS[i] = '3';
      // switch(flagS[i]){
      //   case '0':
      //     flagS[i] = '3';
      //     break;
      //   case '1':
      //     flagS[i] = '3';
      //     break;
      //   case '2':
      //     flagS[i] = '1';
      //     break;
      //   case '3':
      //     flagS[i] = '2';
      //     break;
      // }
      // switch(flagS[i+1]){
      //   case '0':
      //     flagS[i+1] = '3';
      //     break;
      //   case '1':
      //     flagS[i+1] = '3';
      //     break;
      //   case '2':
      //     flagS[i+1] = '1';
      //     break;
      //   case '3':
      //     flagS[i+1] = '2';
      //     break;
      // }
      // switch(flagS[i+2]){
      //   case '0':
      //     flagS[i + 2] = '1';
      //     break;
      //   case '1':
      //     flagS[i + 2] = '0';
      //     break;
      //   case '2':
      //     flagS[i + 2] = '3';
      //     break;
      //   case '3':
      //     flagS[i+2] = '2';
      //     break;
      // }
      //   flagS = createFlagStr(resultS);
        // cout << resultS << endl
        //      << flagS << endl
        //      << createFlagStr(resultS) << endl
        //      << endl;

    }
  }
  // cout << resultS << endl;

  cout << count << endl;
}


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

typedef long long ll;
#define REP(i,n) for(int i=0,_n=(int)(n);i<_n;++i)
#define ALL(v) (v).begin(),(v).end()
#define CLR(t,v) memset(t,(v),sizeof(t))
template<class T1,class T2>ostream& operator<<(ostream& os,const pair<T1,T2>&a){return os<<"("<<a.first<<","<<a.second<< ")";}
template<class T>void pv(T a,T b){for(T i=a;i!=b;++i)cout<<(*i)<<" ";cout<<endl;}
template<class T>void chmin(T&a,const T&b){if(a>b)a=b;}
template<class T>void chmax(T&a,const T&b){if(a<b)a=b;}

int nextInt() { int x; scanf("%d", &x); return x;}
ll nextLong() { ll x; scanf("%lld", &x); return x;}

const int MAX_N = 610;
vector<int> g[MAX_N];

const double INF = 1001001001;
double E[MAX_N];
double dp[MAX_N];

int main2() {
  REP(i, MAX_N) g[i].clear();

  int N = nextInt();
  int M = nextInt();
  REP(i, M) {
    int s = nextInt()-1;
    int t = nextInt()-1;
    g[s].push_back(t);
  }

  REP(i, N) E[i] = INF;
  E[N-1] = 0;
  for (int n = N - 2; n >= 0; n--) {
    double val = 1.0;
    for (int nxt : g[n]) {
      val += E[nxt] / g[n].size();
    }
    chmin(E[n], val);
  }

  double ans = E[0];
  REP(ban_s, N) if (g[ban_s].size() >= 2) {
    int ban_t = g[ban_s][0];
    for (int nxt : g[ban_s]) {
      if (E[ban_t] < E[nxt]) {
        ban_t = nxt;
      }
    }

    REP(i, N) dp[i] = INF;
    dp[N-1] = 0;
    for (int n = N - 2; n >= 0; n--) {
      double val = 1.0;
      int M = g[n].size() - (ban_s == n ? 1 : 0);
      for (int nxt : g[n]) {
        if (ban_s == n && ban_t == nxt) continue;
        val += dp[nxt] / M;
      }
      chmin(dp[n], val);
    }

    chmin(ans, dp[0]);
  }

  printf("%.10f\n", ans);
  return 0;
}

int main() {

#ifdef LOCAL
  for (;!cin.eof();cin>>ws)
#endif
    main2();
  return 0;
}


Measured memory_bytes: 1408
N,L=input().split()
A=[]
m=300
index=0
i=0
sum=0
for i in range(int(N)):
    A.append(int(L)+i)
    if abs(m)>abs(int(A[i])):
        m=int(A[i])
        index=i
for j in range(int(N)):
    if index==j:
        continue
    sum=sum+A[j]
print(sum)

Measured memory_bytes: 3064
h, w = map(int, input().split())
s = [list(input()) for _ in range(h)]
dx = [0, 1, 0, -1]
dy = [-1, 0, 1, 0]
s.insert(0, ['#' for _ in range(w)])
s.append(['#' for _ in range(w)])

for i in range(h+2):
    for j in range(w+2):
        if j == 0:
            s[i].insert(0, '#')
        elif j == w+1:
            s[i].append('#')

for i in range(1, h+1):
    for j in range(1, w+1):
        b = 0
        for k in range(4):
            if s[i+dy[k]][j+dx[k]] == '#': b += 1
        if b == 0 and s[i][j] == '#':
            print('No')
            exit()
print('Yes')
            


Measured memory_bytes: 3064
#include <iostream>
#include <algorithm>
#include <vector>
#define llint long long
#define inf 1e18

using namespace std;

llint n;
llint a[100005];
vector<llint> comp;

int main(void)
{
	ios::sync_with_stdio(0);
	cin.tie(0);
	
	cin >> n;
	for(int i = 1; i <= n; i++) cin >> a[i];
	
	for(int i = 1; i <= n; i++) comp.push_back(a[i]);
	sort(comp.begin(), comp.end());
	comp.erase(unique(comp.begin(), comp.end()), comp.end());
	for(int i = 1; i <= n; i++) a[i] = lower_bound(comp.begin(), comp.end(), a[i]) - comp.begin() + 1;
	
	llint ans = 0;
	for(int i = 1; i <= n; i+=2){
		if(a[i] % 2 == 0) ans++;
	}
	cout << ans << endl;
	
	return 0;
}

Measured memory_bytes: 2168
open Scanf
open Printf

let flip f x y = f y x

let rec range a b = if a >= b then [] else a :: range (a+1) b

let read_int () = scanf " %d" (fun x -> x)
let rec read_ints n = if n = 0 then [] else let i = read_int () in i :: read_ints (n-1)

let rec for_iter a b f = if a >= b then [] else let x = f a in x :: for_iter (a+1) b f
let rec for_iter_ a b f = if a >= b then () else (f a; for_iter_ (a+1) b f)

let list_of_string str = range 0 (String.length str) |> List.map (fun i -> str.[i])
let array_of_string str = Array.init (String.length str) (fun i -> str.[i])

let inf = 20202020202020

let min_dists num start graph =
  let res = Array.make num inf in
  let rec trav v p d =
    res.(v) <- d;
    Array.iter (fun (w, c) -> if w <> p then trav w v (d + c)) graph.(v) in
  trav start (-1) 0;
  res

let () =
  let n = read_int () in
  let degs = Array.make (n+1) 0 in
  let edges = for_iter 0 (n-1) (fun _ ->
    let a = read_int () in let b = read_int () in let c = read_int () in
    degs.(a) <- degs.(a) + 1; degs.(b) <- degs.(b) + 1;
    (a, b, c)) in

  let n = n+1 in

  let graph = Array.init n (fun i -> Array.make degs.(i) (-1, -1)) in
  for_iter_ 0 n (fun i -> degs.(i) <- 0);
  List.iter (fun (a, b, c) ->
    graph.(a).(degs.(a)) <- (b, c); degs.(a) <- degs.(a) + 1;
    graph.(b).(degs.(b)) <- (a, c); degs.(b) <- degs.(b) + 1) edges;

  let q = read_int () in let k = read_int () in

  let dists = min_dists n k graph in
  for_iter_ 0 q (fun _ ->
    let x = read_int () in let y = read_int () in
    printf "%d\n" (dists.(x) + dists.(y)))


Measured memory_bytes: 29824
#include <bits/stdc++.h>
using namespace std;
 
int main(){
  int n;
  vector<int> A;
  int q;
  vector<int> m;
  cin >> n;
  int a;
  for(int i=0;i<n;i++) 
  {
    cin >> a;
    A.push_back(a);
  }
  cin >> q;
 
  for(int i=0;i<q;i++)
  {
    cin >> a;
    m.push_back(a);
  }
  
  bool ans[2001]{false};
  
  int num=0;
  int count=0;
  
  while(count<pow(2,n))
  {
    num=0;
    for(int i=0;i<n;i++)
    {
      a=pow(2,i);
      if(count%(a*2)/a==1) num+=A[i];
    }
    count++;
    //cout << num << endl;
    if(num<=2000) ans[num]=true;
  }
  for(int i=0;i<q;i++)
  {
    if(ans[m[i]]==false) cout << "no" << endl;
    else cout << "yes" << endl;
  }
  //cout << ansX << " " << ansY << endl;
  return 0;
}


Measured memory_bytes: 3312
import itertools
import sys

N = int(input())
P = tuple(map(int, input().split()))
Q = tuple(map(int, input().split()))

if P == Q:
    print(0)
else:
    M = [0]*N
    for i in range(N):
        M[i] = i+1

    ans = []
    for i, v in enumerate(itertools.permutations(M, N)):
        if v in [P, Q]:
            ans.append(i)

    print(abs(ans[0] - ans[1]))

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

int main(){
  string S;
  cin >> S;
  if ((S[0] == S[1] && S[2] == S[3]) || (S[0] == S[2] && S[1] == S[3]) || (S[0] == S[3] && S[1] == S[2])){
    if (S[0] == S[1] && S[1] == S[2] && S[2] == S[3]){
      cout << "No" << endl;
    }
    
     else { 
       
     cout << "Yes" << endl;
     }
    
  }
    else {
      cout << "No" << endl;
    }
  
}

Measured memory_bytes: 256