akhauriyash/Code-Regression huggingface dataset:
// AOJ 2304 Reverse Roads
// 2018.3.10 bal4u

#include <stdio.h>
#include <stdlib.h>
#include <string.h>

/*******************************************/
/* Dinic's Max Flow Algorithm 
/*******************************************/

#define INF 0x01010101
#define VMAX 303
typedef struct { int to; int cap; int rev; } EDGE;
EDGE edge[VMAX][VMAX]; int hi[VMAX];
int V;				// 頂点数
int level[VMAX], iter[VMAX];
int queue[VMAX], qtop;

void add_edge(int from, int to, int cap)
{
	int f, t;
	EDGE *e;

	f = hi[from]++, t = hi[to]++;
	e = &edge[from][f], e->to = to, e->cap = cap, e->rev = t;
//	e = &edge[to][t], e->to = from, e->cap = 0,   e->rev = f;
	e = &edge[to][t], e->to = from, e->cap = cap, e->rev = f;
}

void bfs(int s)
{
	int i, v;
	EDGE *e;
	
	memset(level, -1, V << 2);
	level[s] = 0;
	queue[0] = s, qtop = 1;
	while (qtop) {
		v = queue[--qtop];
		for (i = 0; i < hi[v]; i++) {
			e = &edge[v][i];
			if (e->cap > 0 && level[e->to] < 0) {
				level[e->to] = level[v] + 1;
				queue[qtop++] = e->to;
			}
		}
	}
}
 
int dfs(int v, int t, int f)
{
	int *i, d;
	EDGE *e;
	
	if (v == t) return f;
	for (i = &iter[v]; *i < hi[v]; (*i)++) {
		e = &edge[v][*i];
		if (e->cap > 0 && level[v] < level[e->to]) {
			d = dfs(e->to, t, f <= e->cap? f: e->cap);
			if (d > 0) {
				e->cap -= d;
				edge[e->to][e->rev].cap += d;
				return d;
			}
		}
	}
	return 0;
}
 
int maxFlow(int s, int t)
{
	int f, flow = 0;
	while (1) {
		bfs(s);
		if (level[t] < 0) break;
		memset(iter, 0, V << 2);
		while ((f = dfs(s, t, INF)) > 0) flow += f;
	}
	return flow;
}

/**********************************************/

//#define getchar_unlocked()  getchar()
int in()
{
	int n = 0;
	int c;
	c = getchar_unlocked();
	do n = 10*n + (c & 0xf), c = getchar_unlocked();
	while (c >= '0');
	return n;
}

char dir[303][303]; int id[303][303];
int  ans[1002], sz;

int cmp(int *a, int *b) { return *a - *b; }

int main()
{
	int N, M, S, T, i, j;
	EDGE *e;

	N = in(), M = in();
	
	for (i = 1; i <= M; i++) {
		int x = in()-1, y = in()-1;
		dir[y][x] = 1, id[y][x] = i;
		add_edge(x, y, 1);
	}
	S = in()-1, T = in()-1,	V = N;

	printf("%d\n", maxFlow(S, T));

	sz = 0;
	for (i = 0; i < V; i++) for (j = 0; j < hi[i]; j++) {
		e = &edge[i][j];
		if (e->cap < 1 && dir[i][e->to]) ans[sz++] = id[i][e->to];
	}
	qsort(ans, sz, sizeof(int), cmp);
	printf("%d\n", sz);
	for (i = 0; i < sz; i++) printf("%d\n", ans[i]);
	return 0;
}


Measured memory_bytes: 3388
#include <cstdio>
#include <cmath>
#include <algorithm>
const double PI =3.141592653589793238;
#define MAX 100
using namespace std;
int arr[MAX+10][MAX+10];
int h, w;
int main(){
    scanf("%d %d", &h,&w);
    for (int i=0;i<h;i++){
    	scanf("%s",arr[i]);
	}
	for(int i=0;i<w+2;i++){
		printf("#");
	}
	printf("\n");
	for(int i=0;i<h;i++){
		printf("#");
		printf("%s",arr[i]);
		printf("#\n");
	}
	for(int i=0;i<w+2;i++){
		printf("#");
	}
	return 0;
} 

Measured memory_bytes: 256
#include <stdio.h>
#include <iostream>
#include <vector>
#include <string>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <math.h>
#include <algorithm>
using namespace std;
#define ll long long

const ll INF = 7+(1e+10);
typedef ll Weight;
struct Edge {  //src:辺の始点,dst:辺の終点,weight:辺の重さ
  ll src, dst;
  Weight weight;
  Edge(ll src, ll dst, Weight weight) :
    src(src), dst(dst), weight(weight) { }
};
bool operator < (const Edge &e, const Edge &f) {
  return e.weight != f.weight ? e.weight > f.weight : //辺は重さが重いものを"小さい"と定義する
    e.src != f.src ? e.src < f.src : e.dst < f.dst;
}
typedef vector<Edge> Edges;
typedef vector<Edges> Graph;

//引数 Graph:隣接リスト,dist:各頂点から各頂点までの距離が入る,inter:最短路木の親頂点が入る
//戻値 負閉路が存在しない場合:true,そうでないとき:false
bool shortestPath(const Graph &g,vector<vector<Weight> > &dist,vector<vector<ll> > &inter) {
  ll n = g.size();
  dist.assign(n,vector<Weight>(n,INF));
  for(ll i=0;i<n;i++){
    dist[i][i]=0;
  }
  for(ll i=0;i<n;i++){
    for(auto f=g[i].begin();f!=g[i].end();f++){
      dist[i][f->dst]=f->weight;
    }
  }
  inter.assign(n, vector<ll>(n,-1));
  for(ll k=0;k<n;k++){
    for(ll i=0;i<n;i++){
      for(ll j=0;j<n;j++){
        if(dist[i][k]<INF && dist[k][j]<INF && dist[i][j]>dist[i][k]+dist[k][j]){
          dist[i][j] = dist[i][k] + dist[k][j];
          inter[i][j] = k;
        }
      }
    }
  }
  for(ll i=0;i<n;i++){
    if(dist[i][i]<0){
      return false;
    }
  }
  return true;
}
void buildPath(const vector<vector<ll> > &inter,ll s,ll t,vector<ll> &path) {
  ll u = inter[s][t];
  if (u < 0) path.push_back(s);
  else buildPath(inter, s, u, path), buildPath(inter, u, t, path);
}
vector<ll> buildPath(const vector<vector<ll> > &inter,ll s,ll t) {
  vector<ll> path;
  buildPath(inter, s, t, path);
  path.push_back(t);
  return path;
}


int main(){
  ll v,e;
  cin>>v>>e;
  Graph g(v);
  ll s,t,d;
  for(ll i=0;i<e;i++){
    cin>>s>>t>>d;
    g[s].push_back(Edge(s,t,d));
  }
  vector<vector<Weight> >dist;
  vector<vector<ll> > inter;
  bool ans=shortestPath(g,dist,inter);
  if(!ans){
    cout<<"NEGATIVE CYCLE"<<endl;
    return 0;
  }
  for(ll i=0;i<v;i++){
    if(dist[i][0]>=INF)cout<<"INF";
    else cout<<dist[i][0];
    for(ll j=1;j<v;j++){
      if(dist[i][j]>=INF)cout<<" "<<"INF";
      else cout<<" "<<dist[i][j];
    }
    cout<<endl;
  }
}



Measured memory_bytes: 3360
/*

*/
#include<iostream>
#include<iomanip>
#include<ios>
#include<vector>
#include<queue>
#include<stack>
#include<map>
#include<string>
#include<algorithm>
#include<utility>
#include<math.h>
#include<cstdlib>
#define rep(i, n) for(int i=0;i<n;i++)
#define repb(i, a, b) for(int i=a;i<b;i++)
#define MAX_N 10000

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

const int INF = 1<<30;
const ll MOD = ll(1e9+7);

int main(){
  int k;cin>>k;string s;cin>>s;
  if((int)s.size()<=k)cout<<s<<endl;
  else cout<<s.substr(0, k)<<"..."<<endl;
  // system("read -n 1 -s -p \"Press any key to continue...\"");
}


Measured memory_bytes: 3624
#include<stdio.h>
int field[8][8]={0};
int dx[]={-1,0,1,0};
int dy[]={0,-1,0,1};

void f(int x,int y){
	int i,j;
	field[y][x]=0;
	for(i=0;i<4;i++){
		for(j=1;j<=3;j++){
			if(x+dx[i]*j >= 0 && x+dx[i]*j < 8 && y+dy[i]*j >= 0 && y+dy[i]*j < 8){
				if(field[y+dy[i]*j][x+dx[i]*j]==1){
					f(x+dx[i]*j,y+dy[i]*j);
				}
				field[y+dy[i]*j][x+dx[i]*j]=0;
			}
		}
	}
}
int main(void){
	int n,i,j,k,x,y;
	char a[8];
	scanf("%d",&n);
	for(i=0;i<n;i++){
		for(j=0;j<8;j++){
			scanf("%s",a);
			for(k=0;k<8;k++){
				field[j][k] = a[k] - '0';
			}
		}
		scanf("%d %d",&x,&y);
		f(x-1,y-1);
		printf("Data %d:\n",i+1);
		for(j=0;j<8;j++){
			for(k=0;k<8;k++){
				printf("%d",field[j][k]);
			}
			puts("");
		}
	}
	return 0;
}

Measured memory_bytes: 608
import java.util.Scanner;
public class Main {
	public static void main(String[] args){
		Scanner as = new Scanner(System.in);
		int a = Integer.parseInt(as.next());
		int b = Integer.parseInt(as.next());
		String[] c;
		c = new String[a];
		for(int i=0;i<a;i++){
			c[i]  = as.next();
		}
		for(int i=0;i<a+a;i++){
			System.out.println(c[i/2]);
		}
	}
}

Measured memory_bytes: 11272
#include <iostream>
#include <vector>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <algorithm>
#include <iomanip>
#include <numeric>
#include <queue>
#include <cmath>
using namespace std;

int main() {  
    string s;
    cin >> s;
    int i1 = 0, i2 = 0;
    for (int i = 0; i < s.size(); i++) {
        if (s[i] == 'A') {
            i1 = i;
            break;
        }
    }
    for (int i = s.size() - 1; i >= 0; i--) {
        if (s[i] == 'Z') {
            i2 = i;
            break;
        }
    }
    cout << i2 - i1 + 1 << endl;
}




Measured memory_bytes: 3748
#include<bits/stdc++.h>
typedef long long ll;
#define REP(i,a,b) for(int i=a;i<b;i++)
#define IN(n) int n; cin>>n;
#define ARR(arr,i,n) int arr[n]; REP(i,0,n){cin>>arr[i];}
#define MOD 1000000007

using namespace std;

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

    // code comes here

    int n;
    cin>>n;

    int x[n],sum=0;
    for(int i=0;i<n;i++)
    {

        cin>>x[i];
        sum+=x[i];
    }
    int p=sum/n;
    int p1=p+1;
        sum=0;
        int sum1=0;
    for(int i=0;i<n;i++)
    {

        sum+=(x[i]-p)*(x[i]-p);
        sum1+=(x[i]-p1)*(x[i]-p1);

    }

    cout<<min(sum,sum1)<<endl;
    return 0;
}






Measured memory_bytes: 256
#include <stdio.h>

int main(void)
{
  int n[2], m, d;

  while (scanf("%d %d",&n[0], &n[1])!=EOF){
    d = 1;
    m = n[0] + n[1];
    while (m > 0){
      if (m > 9){
        m /= 10;
        d++;
      }
      else {
        break;
      }
    }
    printf("%d\n", d);
  }
  
  return (0);
}

Measured memory_bytes: 600
import itertools
N,X,Y = map(int, input().strip().split())
ans_dict = {k:0 for k in range(1, N)}
for i,j in itertools.combinations(range(1, N+1), 2):
  if i > j: i, j = j, i
  # i < j
  if i < X and j <= X:  # LL
    ans_dict[j-i] += 1
  elif Y <= i and Y < j:  # RR
    ans_dict[j-i] += 1
  elif i <= X and Y <= j:  # LR
    ans_dict[(X-i)+(j-Y)+1] += 1
  elif X <= i <= Y and X <= j <= Y:  # CC
    # これはウソ　一回遠回りした方が良い可能性がある
    d = min(j-i, (i-X)+(Y-j)+1)
    ans_dict[d] += 1
  elif i <= X and X <= j <= Y:  # LC
    d = min(j-i, (X-i)+(Y-j)+1)
    ans_dict[d] += 1
  elif X <= i <= Y and Y <= j:  # CR
    d = min(j-i, (i-X)+(j-Y)+1)
    ans_dict[d] += 1

for k in range(1, N):
  print(ans_dict[k])




Measured memory_bytes: 49244
require 'set'

class Hash
  def push(key, value)
    self[key] = [] if self[key] == nil
    self[key].push(value)
  end
end

class Array
  def lower_bound(value)
    left = -1;
    right = self.length;
    while left + 1 < right
      mid = left + (right - left) / 2;
      if self[mid] >= value
        right = mid
      else
        left = mid
      end
    end
    right
  end

  def unique
    res = [self.first]
    each_cons(2) do |a, b|
      if a != b
        res.push(b)
      end
    end
    res
  end
end

def get_ints
  gets.split.map(&:to_i)
end

def get_ints_minus_one
  get_ints.map { |x| x - 1 }
end

def get_int
  gets.chomp.to_i
end

class Combination
  def initialize(n, mod)
    @mod = mod
    @fac, @finv, @inv = Array.new(3) { [] }
    @fac[0] = @fac[1] = 1
    @finv[0] = @finv[1] = 1
    @inv[1] = 1
    i = 2
    while i < n
      @fac[i] = @fac[i - 1] * i % @mod
      @inv[i] = @mod - @inv[@mod % i] * (@mod / i) % @mod
      @finv[i] = @finv[i - 1] * @inv[i] % @mod
      i += 1
    end
  end

  def nCk(n, k)
    return 0 if (n < k) || (n < 0 || k < 0)

    @fac[n] * (@finv[k] * @finv[n - k] % @mod) % @mod
  end
end

N, M, K = get_ints
MOD = 998244353

ans = 0

m_stock = [1]

test = 1
1.step(N) do |i|
  test = (test * (M-1)) % MOD
  m_stock[i] = test
end

combination = Combination.new(N, MOD)

0.step(K) do |k|
  stock = M * m_stock[N-k-1] % MOD
  stock *= combination.nCk(N-1, k)
  stock %= MOD
  ans += stock
  ans %= MOD
end

puts ans


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

using namespace std;

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

  int h, w, k;
  cin >> h >> w >> k;
  vector<string> s(h);
  int cur = 0;
  for (int i = 0; i < h; ++i) {
    cin >> s[i];
    for (char c : s[i]) {
      cur += c == '#';
    }
  }
  int ans = 0;
  for (int mh = 0; mh < (1 << h); ++mh) {
    for (int mw = 0; mw < (1 << w); ++mw) {
      auto ns = s;
      int x = cur;
      for (int i = 0; i < h; ++i) {
        if (mh & (1 << i)) {
          for (int j = 0; j < w; ++j) {
            x -= ns[i][j] == '#';
            ns[i][j] = '.';
          }
        }
      }
      for (int j = 0; j < w; ++j) {
        if (mw & (1 << j)) {
          for (int i = 0; i < h; ++i) {
            x -= ns[i][j] == '#';
            ns[i][j] = '.';
          }
        }
      }
      ans += x == k;
    }
  }
  cout << ans;

  return 0;
}


Measured memory_bytes: 3624
#include <cstdio>
using namespace std;
int main(void){
  char data[11];
  while(~scanf("%s",data)){
    for(int i=0;i<10;i++){
      data[i]-='0';
    }
    for(int i=0;i<9;i++){
      for(int j=0;j<9-i;j++){
	data[j]=(data[j]+data[j+1])%10;
      }
    }
    printf("%c\n",data[0]+'0');
  }
  return(0);
}

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

using namespace std;
using ll=long long;
using ld=long double;
using P=pair<ll,ll>;
#define FOR(i,n,m) for(ll i=n; i<(ll)m;i++)
#define FORr(i,n,m) for(ll i=n; i>(ll)m; i--)
#define FORm(i,m) for(auto i=m.begin();i!=m.end();i++)
#define cinv(v,n,m) FOR(i,n,m) cin>>v.at(i)
#define coutv(v,n,m) FOR(i,n,m) cout<<v.at(i) <<" "
#define cout(n) cout<<fixed<<setprecision(n)
int main(){
  ll N,K;
  cin>>N>>K;
  ll res=0;
  FOR(i,K+1,N+1){
    res+=N/i*(i-K);
    //cout<<res<<" ";
    if(K==0) res+=N%i-K;
    else if(N%i>=K)res+=N%i-K+1;

    //cout<<res<<endl;
  }
  cout<<res<<endl;
}


Measured memory_bytes: 256
#include <stdio.h>
int main()
{
  int n,i,j,flag,s,count=0;
  int x[100];

  scanf("%d",&n);
  for(i=0;i<n;i++){

   scanf("%d",&x[i]);
  }
  flag=1;
  while(flag==1){
   flag=0;
    for(j=n-1;j>0;j--){
     if(x[j]<x[j-1]){
     s=x[j];
    x[j]=x[j-1];
    x[j-1]=s;
    flag=1;
    count++;
      }
     }
    }
   for(j=0;j<n-1;j++){
    printf("%d ",x[j]);
   }
   printf("%d\n",x[n-1]);
    printf("%d\n",count);

    return 0;
}

Measured memory_bytes: 1784
N = int(input())
A = input()
B = input()
C = input()

x = 0

for i in range(N):
    if (A[i] == B[i]) and (A[i] == C[i]) :
        x = x
    elif (A[i] != B[i]) and (B[i] != C[i]) and (A[i] != C[i]):
        x += 2
    else :
        x += 1

print(x)


Measured memory_bytes: 3060
from heapq import *
n, m = map(int, input().split())
a = list( map(int, input().split()) )
card = []
for _ in range(m):
  b_, c_ = map(int, input().split())
  card.append([b_, c_])

heapify(a)
card.sort(key=lambda x:x[1], reverse=True)

for i in range(m):
  for _ in range(card[i][0]):
    if a[0]<card[i][1]:
      heappushpop(a, card[i][1])
    else:
      break
print(sum(a))

Measured memory_bytes: 25656
fun main(args: Array<String>) {
    val (H,W) = readLine()!!.split(" ").map {it.toInt()}
    val listString = mutableListOf<String>()
    for(i in 0 until H) listString.add(readLine().toString())
    repeat(W+2) { 
        print("#")
     }
     print("\n")
    listString.forEach{ string ->
        println("#${string}#")
    }
    repeat(W+2) { 
        print("#")
     }
}

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

#define ll long long 
#define MOD 1000000007
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define all(x) (x).begin(), (x).end()

ll C2(ll x) {
	return (x * (x + 1)) / 2;
}

int main(){

	#ifndef ONLINE_JUDGE
		freopen("input.txt", "r", stdin);
		freopen("output.txt", "w", stdout);
	#endif
		
	ios::sync_with_stdio(0); cin.tie(0);
	ll n; cin >> n;
	ll c1 = n / 3, c2 = n / 5, c3 = n / 15;
	cout << C2(n) - 3 * C2(c1) - 5 * C2(c2) + 15 * C2(c3);

	return 0;
}

Measured memory_bytes: 3656
#include <bits/stdc++.h>
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  for(int i=0;i<(n);++i)
#define FORq(i, m, n) for(int i = (m);i <= (n);++i)
#define SCD(n) scanf("%d",&n)
#define SCD2(m,n) scanf("%d%d",&m,&n)
#define SCD3(m,n,k) scanf("%d%d%d",&m,&n,&k)
#define PB push_back
#define MP make_pair
#define ARSCD(A,N) REP(i,N){SCD(A[i]);}
#define ARSCD1(A,N) FORq(i,1,N){SCD(A[i]);}
#define PRINTD(n) printf("%d\n",n)
#define PRINTLLD(n) printf("%lld\n",n)
#define DEBUG printf("%s\n","debug")
#define fst first
#define snd second
#define IN(x,S) (S.count(x) != 0)
using namespace std;
typedef pair<int,int> PII;
typedef vector<int> VI;
typedef long long ll;
//////////////////////////////////////////////////////
ll rupdiv(ll x,ll y){
	if (x % y == 0){
		return x/y;
	}else{
		return ((x/y) + 1);
	}
}

int main(){
	ll M,m;
	ll K; cin >> K;
	vector<ll> A;
	REP(i,K){
		ll x; cin >> x;
		A.PB(x);
	}
	
	reverse(A.begin(),A.end());

	if (A[0] == 1){
		m = 2; M = 2;
	}else if (A[0] == 2){
		m = 2; M = 3;
	}else{
		PRINTD(-1); return 0;
	}
	
	FORq(i,1,K-1){
		ll d = A[i];
		ll m2,M2;
		if (m<=d){
			m2 = d;
		}else{
			m2 = rupdiv(m,d) * d;
		}
		
		if (M < m2){
			PRINTD(-1); return 0;
		}
		
		if (d <= M){
			M2 = d * ((M/d) + 1) - 1;
			ll M3 = (M/d) * d;
			if (M3 < m){
				PRINTD(-1); return 0;
			}
			
		}else{
			PRINTD(-1); return 0;
		}
			
			
			if (m2 > M2){
				PRINTD(-1); return 0;
			}
			
		m = m2;
		M = M2;
	}
	
	printf("%lld %lld\n",m,M);
	
	return 0;
}



Measured memory_bytes: 1528
#include <cassert>
#include <cstdio>
#include <vector>
#include <set>

#include <map>
#include <unordered_map>
#include <deque>
#include <string>
#include <utility>
#include <algorithm>
#include <iostream>
#include <iostream>
#include <climits>

using namespace std;

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; }

const int INF = 1e9;
const long long LINF = 1e18;

int main() {
	long long H, N;
	cin >> H >> N;

    long long sum = 0;
    for (int i = 0; i < N; i++) {
        int Ai;
        cin >> Ai;
        sum += Ai;
    }

		if (sum >= H) {
				cout << "Yes" << endl;
				return 0;
		}
    cout << "No" << endl;
    return 0;
}

Measured memory_bytes: 888
#include<bits/stdc++.h>
namespace my_std{
	using namespace std;
	#define reg register
	#define Rint register int
	#define FOR(i,a,b) for(register int i=(a);i<=(b);++i)
	#define ROF(i,a,b) for(register int i=(a);i>=(b);--i)
	#define FORit(templ,arr,i,a,b) for(register templ *i=(arr)+(a);i!=(arr)+(b)+1;++i)
	#define ROFit(templ,arr,i,a,b) for(register templ *i=(arr)+(b);i!=(arr)+(a)-1;--i)
	#define GO(x,p,e,i,v) for(register int i=p[x].head,v;i;i=e[i].link)
	#define MEM(x,v) memset(x,v,sizeof(x))
	#define fir first
	#define sec second
	#define pq priority_queue
	#define PII pair<int,int>
	#define MP make_pair
	typedef long long LL;
	typedef double DB;
	inline int read(){
		int ans=0,f=1;char c=getchar();
		while(!isdigit(c)){ f^=(c=='-'); c=getchar(); }
		for(;isdigit(c);c=getchar()) ans=ans*10+c-'0'; return f?ans:-ans;
	}
	const int mod = 1e9+7;
	inline void inc(int &x,const int &y){ x+=y; if(x>=mod) x-=mod; }
	inline int ksm(int x,LL y){ int res=1; for(;y;y>>=1,x=1ll*x*x%mod) if(y&1) res=1ll*res*x%mod; return res;}
	inline int gcd(int x,int y){ if(x<y) swap(x,y); return y?gcd(y,x%y):x; }
	#define FILE(s) freopen(s".in","r",stdin),freopen(s".out","w",stdout)
}
using namespace my_std;

int main(){
	printf("%d",180*(read() - 2));
	return 0;
}

Measured memory_bytes: 256
#include <math.h>
#include <ctype.h>
#include <limits.h>
#include <string.h>
#include <assert.h>

#include <vector>
#include <numeric>
#include <iostream>
#include <algorithm>

#define nl                std::cout << "\n"
#define in(x)             std::cin  >> (x)
#define out(x)            std::cout << (x) << " "
#define err(x)            std::cerr << "DBG: " << #x << " " << (x) << "\n"

#define inn(x)            int x; in(x);
#define rep(i, n)         for (int i =  0 ; i < (n); ++i)
#define repr(i, l, r)     for (int i = (l); i < (r); ++i)
#define rrep(i, n)        for (int i = (n) - 1; i > -1; --i)

#define no                puts("NO")
#define yes               puts("YES")

using ll  = long long int;
using vi  = std::vector<int>;
using ii  = std::pair<int, int>;
using iii = std::pair<ii, int>;
using vii = std::vector<ii>;

const int N = 1010101;
const int MD = 1e9 + 7;

void solve() {
    int n; in(n);

    int w[n]; rep(i, n) in(w[i]);

    int ps[n + 1]; ps[0] = w[0];
    repr(i, 1, n) ps[i] = ps[i - 1] + w[i];

    int ss[n + 1]; ss[n - 1] = 0;
    rrep(i, n - 1) ss[i] = ss[i + 1] + w[i + 1];

    int ans = INT_MAX;
    rep(i, n) ans = std::min(ans, abs(ps[i] - ss[i]));

    out(ans);
}

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

    //int t; in(t); repr(tc, 1, t + 1)
    solve();

    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define f first
#define s second
#define fore(i,a,b) for(int i = (a), ThxMK = (b); i < ThxMK; ++i)
#define pb push_back
#define eb emplace_back
#define all(s) begin(s), end(s)
#define _ ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define sz(s) int(s.size())
#define ENDL '\n'
using namespace std;
typedef long double ld;
typedef long long lli;
typedef pair<int,int> ii;
typedef vector<int> vi;
typedef vector<lli> vl;
typedef vector<ii> vii;
typedef vector<vi> vvi;
typedef vector<bool> vb;
typedef vector<vl> vvl;
#define deb(x) cout << #x": " << (x) << endl;

const int N = 1e3+5;
const lli INF = 1e18;
const lli MOD = 1e9+7;

bool mm[N];
vi primes(1,2);
ld nk[N][N];
void sieve(){
	for(int i = 4; i<N; i+=2)mm[i]=1;
	for(int i = 3; i*i<=N; i+=2)if(!mm[i])for(int j = i*i; j<N; j+=i)mm[j]=1;
	for(int i = 3; i<N; i+=2)if(!mm[i])primes.pb(i);
}

void pascal(){
	fore(i,0,N)nk[i][0]=nk[i][i]=1.0;
	fore(i,1,N)fore(j,1,i)nk[i][j]=nk[i-1][j-1]+nk[i-1][j];
}

lli gcd(lli a, lli b){return (b?gcd(b,a%b):a);}

lli lcm(lli a, lli b){
	if(a<b)swap(a,b);
	lli c = gcd(a,b);
	a/=c;
	return a*b;
}

int popcount(lli x) { return __builtin_popcountll(x); }

lli poww(lli a, lli b){
	lli res =1;
	while(b){
		if(b&1) res = res * a;
		a = a*a;
		b/=2;
	}
	return res;
}

lli powm(lli a, lli b){
	lli res =1;
	while(b){
		if(b&1) res = (res * a)%MOD;
		a = (a*a)%MOD;
		b/=2;
	}
	return res;
}

bool isPrime(lli x){
	if(x==1)return 0;
	for(auto i:primes){
		if(i*i>x)return 1;
		if(x%i==0)return 0;
	}
	return 1;
}

// ---- コーディングはここから！ ('-')7


int main(){_
	int n; cin>>n;
	lli res = 0;
	fore(i,1,n+1)res+=1LL*i*(n-i+1);
	fore(i,0,n-1){
		lli a,b; cin>>a>>b;
		if(a>b)swap(a,b);
		res-=a*(n-b+1);
	}
	cout<<res<<ENDL;





}


Measured memory_bytes: 3576
#include <iostream>
#define ll long long
using namespace std;
ll k[200];
int main()
{
    ll n;
    cin >> n;
    for (ll i = 0; i < 200; i++) {
        k[i] = i * i * i * i * i;
        for (ll j = 0; j < i; j++) {
            if (k[i] - k[j] == n) {
                cout << i << " " << j;
            }
            else if (k[i] + k[j] == n) {
                cout << i << " " << -j;
            }
        }
    }
}

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

int main(){
  int N,K,sum=0,x;
  cin>>N>>K;
  for (int i=0;i<N;i++){
    cin>>x;
    if (x<(K+1)/2){
      sum+=x;
    }
    else {
      sum+=K-x;
    }
  }
  cout<<sum*2<<endl;
}

Measured memory_bytes: 256
INF = 10**9
N = int(input())
happiness = [[0, 0, 0]]
for _ in range(N):
  happiness.append(list(map(int, input().split())))
dp = [[-INF] * 3 for _ in range(N+1)]
dp[0] = [0, 0, 0]

for i in range(1, N+1):
  dp[i][0] = max(dp[i-1][1], dp[i-1][2]) + happiness[i][0]
  dp[i][1] = max(dp[i-1][2], dp[i-1][0]) + happiness[i][1]
  dp[i][2] = max(dp[i-1][0], dp[i-1][1]) + happiness[i][2]
print(max(dp[N]))

Measured memory_bytes: 100836
import java.util.Scanner;


/*
1
0 0 0 3 0 1 0 2
*/

public class Main {
	static double EPS = 0.0000000001;

	public static void main(String[] args) {
		Scanner s = new Scanner(System.in);
		int q = s.nextInt();
		for (int i=0;i<q;i++) {
			if (intersect(new Point(s.nextInt(),s.nextInt()), new Point(s.nextInt(),s.nextInt()), new Point(s.nextInt(),s.nextInt()), new Point(s.nextInt(),s.nextInt()) )) {
				System.out.println(1);
			} else {
				System.out.println(0);
			}
		}
	}
	static int ccw(Point lp0, Point lp1, Point p) {
		Vector lv = lp1.diff(lp0);
		Vector pv = p.diff(lp0);
		double cp=0.0;
		if ((cp=lv.crossProduct(pv))>EPS) {return -1;} // counter-clockwise
		if (cp<-EPS) {return 1;} // clockwise
		if (lv.dotProduct(pv)<-EPS) return 2; // online-back
		if (lv.norm() < pv.norm()) return 3; // online-front
		return 0; // on-segment
	}
	static boolean intersect(Point p0, Point p1, Point p2, Point p3) {
		int ccw0=ccw(p0,p1,p2)*ccw(p0,p1,p3);
		int ccw1=ccw(p2,p3,p0)*ccw(p2,p3,p1);
		return ccw0<=0&&ccw1<=0||ccw0==0&&ccw1==6||ccw0==6&&ccw1==0;}
	static boolean intersect(Segment s1, Segment s2){return intersect(s1.p1,s1.p2,s2.p1,s2.p2);}

}
class Point {
	double x; double y;
	public Point(double ax, double ay){x=ax;y=ay;}
	public Vector sum(Point p) { return new Vector(x+p.x,y+p.y); }
	public Vector diff(Point p) { return new Vector(x-p.x,y-p.y); }
	public Vector mult(double k) { return new Vector(x*k,y*k); }
	public Vector div(double k) { return new Vector(x*(1.0/k),y*(1.0/k)); }
	static double EPS = 0.0000000001;
	public boolean equals(Point p){return Math.abs(x-p.x)<EPS && Math.abs(y-p.y)<EPS;}
	public String toString(){return "("+x+","+y+")";}
}
class Vector extends Point {
	public Vector(double ax, double ay) {super(ax,ay);}
	public Vector(Point p1, Point p2) {super(p1.x-p2.x,p2.x-p2.y);}
	public double norm() {return x*x+y*y;}
	public double abs() {return Math.sqrt(norm());}
	// TODO:
	public boolean isSmallerThan(Vector v) {return x!=v.x?x<v.x:y<v.y;}
	public double dotProduct(Vector v) {return x*v.x+y*v.y;}
	public double crossProduct(Vector v) {return x*v.y - y*v.x;}
}

class Segment {
	Point p1; Point p2;
	public Segment(Point ap1, Point ap2){p1=ap1;p2=ap2;}
	public double dotProduct(Segment s) {return (p1.x-p2.x)*(s.p1.x-s.p2.x)+(p1.y-p2.y)*(s.p1.y-s.p2.y);}
	public double crossProduct(Segment s) {return (p1.x-p2.x)*(s.p1.y-s.p2.y) - (p1.y-p2.y)*(s.p1.x-s.p2.x);}
	public String toString(){return p1.toString()+"->"+p2.toString();}
}

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

int main() {
  int N;
  cin >> N;
  for (int i{9}; i >= 1; --i) {
    if (N % i == 0 && N / i <= 9) {
      cout << "Yes" << endl;
      return 0;
    }
  }

  cout << "No" << endl;
  return 0;
}


Measured memory_bytes: 3608
N,A,B,C,D=map(int,input().split())
s=list('.'+input())
def ren(start,end):
    count=0
    MAX=0
    for k in range(start,end+1):
        if s[k]==".":
            count+=1
            MAX=max(count,MAX)
        else:
            count=0
    return MAX>=3


def S(snuke,c):
    while snuke<=c and s[snuke]==".":
        if snuke==c:
            return True
        if s[snuke+1]=='#':
            snuke+=2
        else:
            snuke+=1
    return False

def H(hnuke,d):
    while hnuke<=d and s[hnuke]==".":
        if hnuke==d:
            return True
        if s[hnuke+1]=='#':
            hnuke+=2
        else:
            hnuke+=1
    return False


x=S(A,C)
y=H(B,D)

if (B<A and C<D):
    z= x and y and ren(A-1,C+1)

elif (A<B and D<C):
    z= x and y and ren(B-1,D+1)
else:
    z= x and y
print("Yes" if z else "No")

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

using namespace std ;

const int MAX = 1e5 + 10 ;

int arr[MAX] ;
long long a , b , n ;

int main()
{
	ios_base::sync_with_stdio(0) ;
	cin.tie(0) ;
	cin>>a>>b>>n ;
	long long x = min(n , b-1ll) ;
	return cout<<a*x/b-a*(x/b)<<"\n" , 0 ;
}		

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

const string IMPOSSIBLE = "Impossible";

#define LLD_SPEC "%lld"

void Show(const vector<int>& ra, const vector<int>& rb) {
    for (int x : ra) {
        printf("%d ", x);
    }
    printf("\n");

    printf("%d\n", (int) rb.size());
    for (int x : rb) {
        printf("%d ", x);
    }
    printf("\n");
}

int main() {
    int n, m;
    scanf("%d%d", &n, &m);
    vector<int> a(m);
    for (int i = 0; i < m; ++i) {
        scanf("%d", &a[i]);
    }

    if (n == 1) {
        Show({1}, {1});
        return 0;
    }

    if (m == 1) {
        Show(a, {a[0] - 1, 1});
        return 0;
    }

    if (m == 2) {
        if (a[0] == 1 && a[1] == 1) {
            Show(a, {2});
        } else if (a[1] == 1) {
            Show(a, {a[0] - 1, 2});
        } else {
            Show(a, {a[0] + 1, a[1] - 1});
        }
        return 0;
    }

    vector<int> vals[2];

    for (int x : a) {
        vals[x & 1].push_back(x);
    }

    if (vals[1].size() > 2) {
        printf("%s\n", IMPOSSIBLE.c_str());
        return 0;
    }

    vector<int> ra;
    ra.reserve(m);
    if (vals[1].size() > 0) {
        ra.push_back(vals[1].back());
        vals[1].pop_back();
    }

    for (int x : vals[0]) {
        ra.push_back(x);
    }

    if (vals[1].size() > 0) {
        ra.push_back(vals[1].back());
    }

    vector<int> rb;
    rb.reserve(m);

    rb.push_back(ra[0] + 1);
    for (int i = 1; i + 1 < (int) ra.size(); ++i) {
        rb.push_back(ra[i]);
    }
    if (ra.back() != 1) {
        rb.push_back(ra.back() - 1);
    }

    Show(ra, rb);

    return 0;
}

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

typedef long long ll;
typedef long double ld;
typedef vector<vector<int>> Graph;
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
#define pi 3.14159265359
#define inf 2147483647
#define INF 9223372036854775807
#define mod 1000000007
#define mod2 998244353

int main() {
    int N, M; cin >> N >> M;
    priority_queue<ll> pq;
    for(int i = 0; i < N; i++) {
        ll A; cin >> A;
        pq.push(A);
    }
    for(int i = 0; i < M; i++) {
        ll n = pq.top(); pq.pop();
        pq.push(n / 2);
    }
    ll sum = 0;
    while(!pq.empty()) {
        sum += pq.top();
        pq.pop();
    }
    cout << sum << endl;
    return 0;
}

Measured memory_bytes: 4236
#include<bits/stdc++.h>
using namespace std;
#define int long long
int memo[1111111];
int dfs(int v){
  if(~memo[v]) return memo[v];
  if(v==1) return 0;
  if(v%2) return dfs(v*3+1)+1;
  else return dfs(v/2)+1;
}
signed main(){
  memset(memo,-1,sizeof(memo));
  int n;
  while(cin>>n,n) cout<<dfs(n)<<endl;
  return 0;
}

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

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

using namespace std;

int main(){
	int x,y,z; scanf("%d%d%d",&x,&y,&z);
	printf("%d %d %d\n",z,x,y);
	return 0;
}


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

def main():
    N, M = map(int, input().split())
    L =[0 for i in range(M)]
    R = [0 for i in range(M)]

    for i in range(0, M):
        L[i], R[i] = map(int, input().split())
    
    print(max(min(R) - max(L) + 1, 0))


main()

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

int main() {
    int n, d;
    cin >> n >> d;
    double x[20][20];
    for (int i = 0; i < n; i++) {
        for (int j = 0; j < d; j++) {
            cin >> x[i][j];
        }
    }

    int cnt = 0;
    for (int i = 0; i < n; i++) {
        for (int j = i + 1; j < n; j++) {
            long long sum = 0;
            for (int k = 0; k < d; k++) {
                sum += abs(x[i][k] - x[j][k]) * abs(x[i][k] - x[j][k]);
            }
            if ((double)sqrt(sum) == (long long)sqrt(sum)) cnt++;
        }
    }

    cout << cnt << endl;
    return 0;
}

Measured memory_bytes: 256
import java.io.PrintWriter;
import java.util.Scanner;
 
public class Main {
    private static int[] path;
 
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int a = sc.nextInt();
        int b = sc.nextInt();
        path = new int[1 << n];
        if (Integer.bitCount(a ^ b) % 2 != 0) {
            System.out.println("YES");
        } else {
            System.out.println("NO");
            return;
        }
        path(a, b, 0, (1 << n) - 1);
        PrintWriter pw = new PrintWriter(System.out);
        for (int i = 0; i < path.length; i++) {
            pw.print(path[i] + " ");
        }
        pw.println();
        pw.flush();
    }
 
    private static void path(int a, int b, int st, int mask) {
        int diffBit = Integer.highestOneBit(mask & (a ^ b));
        mask = mask ^ diffBit;
        int size = Integer.bitCount(mask);
        if (size == 0) {
            path[st] = a;
            path[st + 1] = b;
        } else {
            int otherBit = Integer.highestOneBit(mask);
            path(a, a ^ otherBit, st, mask);
            path(a ^ diffBit ^ otherBit, b, st + (1 << size), mask);
        }
    }
}

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

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

    static class Task {
        public void solve(int testNumber, Scanner in, PrintWriter out) {
            String s = in.next();
            if (s.indexOf("a") != -1
                    && s.indexOf("b") != -1
                    && s.indexOf("c") != -1) {
                out.println("Yes");
            } else {
                out.println("No");
            }
        }

    }
}



Measured memory_bytes: 23252
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int X = sc.nextInt();
		int a = 0;
		for(int i=X; i<1000000; i++) {
			int b = 0;
			for(int j=1; j<i; j++) {
				if(i%j==0) b++;
			}
			if(b<=2) {
				a = i;
				break;
			}
		}
		sc.close();
		System.out.println(a);
	}

}

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

using namespace std;

#define REP(i, n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define REPR(i, n) for(int i = n;i >= 0;i--)
#define REP3(i, m, n) for(int i = m, i##_len=(n);i < i##_len;i++)
#define FORVEC(i, v) for(int i = 0;i < v.size();i++)

#define INF 1000000000
#define pb(a) push_back(a)
#define vi vector<int>
#define vvi vector<vi>
#define P pair<int,int>
#define all(vec) (vec.begin()),(vec.end())
#define ll long long int;
#define sz(x) ((int)(x).size())
#define in(x) int x;cin>>x;
#define bit(n) (1<<(n))


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; }


int main(){
	char y[10];
	string s;
	int n,cnt=0;
	cin>>s;
	cin>>n;
	REP(i,n){
		cin>>y;
		REP(j,10){
			bool flag=true;
			REP(k,sz(s)){
				if(s.at(k)!=y[(j+k)%10]){
					flag=false;
					break;
				}
			}
			if(flag){
				cnt++;
				break;
			}
		}
	}
	cout<<cnt<<"\n";
	return 0;
}

Measured memory_bytes: 3172
H,W=map(int,input().split())
L=[[0 for j in range(W)] for i in range(H)]
N=int(input())
R=list()
a=list(map(int,input().split()))
for i in range(N):
  R+=[i+1]*a[i]
for i in range(H):
  if i%2==0:
    s=list(R[i*W:(i+1)*W])
    s=list(map(str,s))
    print(" ".join(s))
  else:
    s=list(R[i*W:(i+1)*W])
    s=list(reversed(s))
    s=list(map(str,s))
    print(" ".join(s))

Measured memory_bytes: 9440
/*
* @Author Silviase(@silviasetitech)
* For ProCon
*/

import java.util.*;
import java.lang.*;
import java.math.*;

class Main{
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        
        int n = sc.nextInt();
        int[] fl = new int[n];
        double av = 0;
        int ans = 0;
        for (int i = 0; i < n; i++) {
            fl[i] = sc.nextInt();
            av += fl[i];
        }
        av/=n;

        for (int i = 0; i < n; i++) {
            if (Math.abs( av-fl[ans] ) > Math.abs( av-fl[i] )  ) {
                ans = i;
            }
        }

        System.out.println(ans);

        sc.close();
    }

}

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

using namespace std;

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

    vector<pair<long long, long long> > P(N);
    for (int i = 0; i < N; ++i) {
        long long x, l;
        cin >> x >> l;
        P[i] = make_pair(x + l, x - l);
    }
    sort(P.begin(), P.end());

    int ans = 1;
    int cur = 0;//現在の右端に対応するインデックス
    for (int i = 1; i < N; ++i) {
        if (P[cur].first <= P[i].second) {
            ans++;
            cur = i;
        }
    }

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


Measured memory_bytes: 1792
K = input()
A,B = map(int,input().split())
K = int(K)
C = 0
D = 0

for i in range(A,B + 1):
    if i % K == 0:
        print("OK")
        D = 1
        break
    else:
        C = 1

if C >= 1 and D < 1:
    print("NG")

Measured memory_bytes: 9184
#include <iostream>
#include <vector>
#include <cmath>
#include <algorithm>
using namespace std;
int main() {
    int N;
    cin >> N;
    vector<int> x(N), y(N), h(N);
    int nz = -1;
    for (int i = 0; i < N; i++) {
        cin >> x[i] >> y[i] >> h[i];
        if (h[i] != 0 && nz == -1) nz = i;
    }
    for (int px = 0; px <= 100; px++) {
        for (int py = 0; py <= 100; py++) {
            int ph = h[nz] + abs(px - x[nz]) + abs(py - y[nz]);
            bool f = true;
            for (int i = 0; i < N; i++) {
                if (i == nz) continue;
                if (max(ph - abs(x[i] - px) - abs(y[i] - py), 0) != h[i]) f = false;
            }
            if (f) {
                cout << px << " " << py << " " << ph << endl;
                return 0;
            }
        }
    }
}


Measured memory_bytes: 256
#include <iostream>

using namespace std;
#define MAX 1000000
#define INF 1000000000

int dp1[MAX + 1], dp2[MAX + 1];

int main()
{
    for (int i = 1; i <= MAX; i++)
    {
        dp1[i] = INF;
        dp2[i] = INF;
    }

    for (int n = 1; n * (n + 1) * (n + 2) / 6 <= MAX; n++)
    {
        int a = n * (n + 1) * (n + 2) / 6;
        for (int i = a; i < MAX; i++)
        {
            dp1[i] = min(dp1[i], dp1[i - a] + 1);
        }
        if (a % 2 == 0)
            continue;
        for (int i = a; i < MAX; i++)
        {
            dp2[i] = min(dp2[i], dp2[i - a] + 1);
        }
    }

    while (1)
    {
        int n;
        cin >> n;
        if (n == 0)
            break;
        cout << dp1[n] << " " << dp2[n] << endl;
    }
    return 0;
}


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

int main(){
    int N; cin >> N;
    string S; cin >> S;
    int l[300300],r[300300]; //
    l[0]=0; r[N]=0;
    for(int i=0; i<N; i++){
        l[i+1]=l[i];
        r[N-i-1]=r[N-i];
        if(S.at(i)=='W')  l[i+1]++;
        if(S.at(N-1-i)=='E') r[N-i-1]++;
    }
    int minimum=300300;
    for(int i=0; i<N; i++){
        minimum = min (minimum, l[i]+r[i+1]);
//        cout << l[i]+r[i+1] << endl;
    }
    cout << minimum <<endl;
}

Measured memory_bytes: 3076
#include<bits/stdc++.h>
using namespace std;
int main(){
  string s;cin>>s;
  int n=s.size(),c=0;
  for(int i=0;i<n;i++){
    if(i%2==0){
      if(s.at(i)=='L'){
        c++;
        break;
      }
    }
    else{
      if(s.at(i)=='R'){
        c++;
        break;
      }
    }
  }
  if(c>0)cout<<"No"<<endl;
  else cout<<"Yes"<<endl;
}
  


Measured memory_bytes: 256
H, W, K = map(int, input().split())
S = []
ans = 0

def binlist(x,k):
  s = []
  for i in range(k):
    s.append(x % 2)
    x = x // 2
  return s
    
for i in range(H):
  temp1 = input()
  temp2 = [temp1[i] for i in range(len(temp1))]
  S.append(temp2)
for i in range(2 ** H):
  for j in range(2 ** W):
    A = binlist(i, H)
    B = binlist(j, W)
    c = 0
    for k in range(H):
      for l in range(W):
        if A[k] == 0 and B[l] == 0 and S[k][l] == "#":
          c += 1
    if c == K:
      ans += 1
      
print(ans)

Measured memory_bytes: 9232
#include<iostream>
#include<algorithm>
#include<vector>
#include<queue>
#define lol(i,n) for(int i=0;i<n;i++)
#define mod 1000000007
typedef long long ll;

using namespace std;
#define N 200010
ll n,a[N],c[N];
int B(ll key){
    int l=0,r=n+1,mid;
    while(l<r-1){
	mid=(l+r)/2;
	if(c[mid]*2<key)l=mid;
	else r=mid;
    }
    return l;
}
ll F(ll x,ll y,ll z,ll w){
    ll maxi=max(max(x,y),max(z,w));
    ll mini=min(min(x,y),min(z,w));
    return maxi-mini;
}
int main(){
    cin>>n;
    c[0]=0;
    lol(i,n){
	cin>>a[i];
	c[i+1]=c[i]+a[i];
    }
    ll ans=(ll)mod*(ll)mod;
    for(int k=0;k<=n;k++){
	int x=B(c[k]);
	int y=B(c[n]-c[k]+c[k]*2);
	ans=min(ans,F(c[n]-c[y],c[y]-c[k],c[k]-c[x],c[x]));
	x++;
	ans=min(ans,F(c[n]-c[y],c[y]-c[k],c[k]-c[x],c[x]));
	y++;
	ans=min(ans,F(c[n]-c[y],c[y]-c[k],c[k]-c[x],c[x]));
	x--;
	ans=min(ans,F(c[n]-c[y],c[y]-c[k],c[k]-c[x],c[x]));
    }
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 3328
#define _CRT_SECURE_NO_WARNINGS
#include<stdio.h>
int main(void)
{
	int a, b, c;

	scanf("%d", &a);

	for (b = 1; b < 10; b++) {
		c = b * 100 + b * 10 + b;
		if (a <= c) {
			printf("%d", c); break;
		}
	}


	return 0;

}

Measured memory_bytes: 128
<?php

$student_number = [];
for ($i = 0; $i < 28; $i++) {
    $student_number[] = intval(trim(fgets(STDIN)));
}

for ($i = 1; $i < 31; $i++) {
    if (!in_array($i, $student_number)) echo $i . PHP_EOL;
}


Measured memory_bytes: 9228
n = int(input())
a = list(map(int,input().split()))
b = list(map(int,input().split()))
if sum(a)>sum(b):
  print("No")
else:
  ca = 0
  cb = 0
  for i in range(n):
    if a[i]>b[i]:
      cb += a[i]-b[i]
    else:
      ca += (b[i]-a[i]+1)//2
      cb += (b[i]-a[i])%2
  x = sum(b)-sum(a)
  if x >= ca and x >= cb and (x-ca)*2 == x-cb:
    print("Yes")
  else:
    print("No")

Measured memory_bytes: 4596
#include<iostream>
#include<string>
#include<cstring>
#include<algorithm>
using namespace std;

int main(){
	char s[100010];
	cin >> s;
	int len = strlen(s), ans = len;
	for(int i = 1; i < len; i++){
		if(s[i] != s[i-1])
			ans = min(ans,max(i,len-i));
	}
	cout << ans << endl; 
	
	return 0;
}

Measured memory_bytes: 384
#include<bits/stdc++.h>
using namespace std;
int main()
{
	int n;
	cin>>n;
	int b=n%10;
	//cout<<b;
	if(b==3){
		cout<<"bon";
	}
	else if(b==0 || b==6||b==1||b==8)
	{
		cout<<"pon";
	}
	else
	{
		cout<<"hon";
	}
}	

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

int main() {
    int N; cin >> N;
    vector<int> V(N), C(N);
    int Vs = 0, Cs = 0;
    for (int i = 0; i < N; i++) {
        cin >> V.at(i);
        Vs += V.at(i);
    }
    for (int i = 0; i < N; i++) {
        cin >> C.at(i);
        Cs += C.at(i);
    }
    
    int M = Vs - Cs;
    for (int i = 0; i < N; i++) {
        M = max(M, M - V.at(i) + C.at(i));
    }
    cout << M << endl;
}

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

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

using namespace std;

typedef long long ll;
const int MAX = 300100;
int n,m;
ll sum[MAX],a[MAX],b[MAX],c[MAX];

int main(){
  cin >> n;
  rep(i,n) cin >> a[i];
  sort(a,a+n);
  rep(i,n) {
    if( i == 0 ) sum[i] = a[i];
    else         sum[i] = a[i] + sum[i-1];
  }
  cin >> m;
  rep(i,m) cin >> b[i];
  rep(i,m) {
    cin >> c[i];
    int p = upper_bound(a,a+n,b[i]) - a;
    if( ( p - 1 >= 0 && sum[p-1] >= c[i] ) || ( p - 1 < 0 && c[i] == 0) ) {
      puts("Yes");
    } else {
      puts("No");
    }
  }
  return 0;
}

Measured memory_bytes: 10428
#include<iostream>
using namespace std;
void solve(int,int);
int main(){
  double n,sn;
  while(1){
    cin >> n;
    if(n==-1.0) break;
    sn = n * 16;
    if(sn!=(int)sn || sn>=4096) cout << "NA";
    else solve((int)sn,0);
    cout << endl;
  }
}
void solve(int sn,int p){
  if(p == 12) return;
  solve(sn/2,p+1);
  if(p == 3) cout << ".";
  cout << sn % 2;
}

Measured memory_bytes: 1224
def hiku(x, k)
  xx, kk = x, k
  if x > 0 && k > 0
    if x > k
      xx = x - k
      kk = 0
    else
      xx = 0
      kk = k - x
    end
  end
  [xx, kk]
end

a, b, k = gets.split.map(&:to_i)

a, k = hiku(a, k)
b, k = hiku(b, k)

puts "#{a} #{b}"

Measured memory_bytes: 1788
#include<bits/stdc++.h>
#define eoi ios::sync_with_stdio(0),ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0);
using namespace std;
int main()
{
    eoi;
    int a,b,c,d,sum=0;
    cin>>a>>b>>c>>d;
    if(a>=b){
    sum+=(b*c);}
    else{cout<<a*c;return 0;}
    if(a-b>0){
        sum+=(a-b)*d;
    }
    cout<<sum;
}







Measured memory_bytes: 256
#![allow(non_snake_case, unused_imports)]

// Input macros
macro_rules! input { (source = $s:expr, $($r:tt)*) => { let mut iter = $s.split_whitespace(); let mut next = || { iter.next().unwrap() }; input_inner!{next, $($r)*} }; ($($r:tt)*) => { let stdin = std::io::stdin(); let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock())); let mut next = move || -> String{ bytes.by_ref().map(|r|r.unwrap() as char).skip_while(|c|c.is_whitespace()).take_while(|c|!c.is_whitespace()).collect() }; input_inner!{next, $($r)*} }; }
macro_rules! input_inner { ($next:expr) => {}; ($next:expr, ) => {}; ($next:expr, $var:ident : $t:tt $($r:tt)*) => { let $var = read_value!($next, $t); input_inner!{$next $($r)*} }; ($next:expr, mut $var:ident : $t:tt $($r:tt)*) => { let mut $var = read_value!($next, $t); input_inner!{$next $($r)*} }; }
macro_rules! read_value { ($next:expr, ( $($t:tt),* )) => { ( $(read_value!($next, $t)),* ) }; ($next:expr, [ $t:tt ; $len:expr ]) => { (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>() }; ($next:expr, [ $t:tt ]) => { { let len = read_value!($next, usize); (0..len).map(|_| read_value!($next, $t)).collect::<Vec<_>>() } }; ($next:expr, chars) => { read_value!($next, String).chars().collect::<Vec<char>>() }; ($next:expr, bytes) => { read_value!($next, String).into_bytes() }; ($next:expr, usize1) => { read_value!($next, usize) - 1 }; ($next:expr, $t:ty) => { $next().parse::<$t>().expect("Parse error") }; }

// Module
use std::cmp::{min,max};
use std::collections::{HashSet,HashMap,VecDeque,BinaryHeap};

// Functions

// Main
fn main(){
    input!{
        N: usize,
        D: [usize; N]
    }
    let mut set = HashSet::new();
    for d in D{
        set.insert(d);
    }
    println!("{}", set.len());
}


Measured memory_bytes: 4352
N, Y = [int(i) for i in input().split()]

def otoshidamaChekcer(N,Y):
    combi = []
    for man in range(N+1):
        for gosen in range(N-man+1):
            sen = N-man-gosen
            if man + gosen + sen == N:
                otoshidama = (man * 10000) + (gosen * 5000) + (sen * 1000)
                # print(man, gosen, sen, otoshidama)
                if otoshidama == Y:
                    return ' '.join(map(str, [man,gosen,sen]))
    return False

combi = otoshidamaChekcer(N,Y)

if combi:
    print(combi)
else :
    print('-1 -1 -1')

Measured memory_bytes: 3188
#include <bits/stdc++.h>
using namespace std;
const long long MAX = 100055;
const long long MOD = 1000000007;
long long fac[MAX], finv[MAX], inv[MAX];
bool used[100005]={0};
long long c[100005],ans;
int k,parent[100005];
vector<int> v[100005];

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

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

void dfs(int nord){
	int r,count=-1,keep;
	for(r=0;r<v[nord].size();r++){
		if(!used[v[nord][r]]){
			count++;
			used[v[nord][r]]=1;
			if(count==0){
				if(c[nord]-1>k-2) c[v[nord][r]]=c[nord]-1;
				else c[v[nord][r]]=k-2;
				keep=c[v[nord][r]];
			} else {
				c[v[nord][r]]=keep-count;
			}
			ans=(ans*c[v[nord][r]])%MOD;
			dfs(v[nord][r]);
		}
	}
}

int main (){
	COMinit();
	int n,i,a,b;
	cin >> n >> k;
	for(i=1;i<n;i++){
		cin >> a >> b;
		v[a].push_back(b);
		v[b].push_back(a);
	}
	v[1].push_back(0);
	v[0].push_back(1);
	parent[1]=0;
	c[0]=k+1;
	used[0]=1;
	ans=1;
	dfs(0);
	cout << ans << endl;
    return 0;
}

Measured memory_bytes: 15232
#include <iostream>
using namespace std;
typedef long long ll;
int main()
{
    ll a[3],b[3];
    cin>>a[1]>>a[2];
    cin>>b[1]>>b[2];
    ll ans=-8e18;
    for(int i=1; i<=2; i++){
        for(int j=1; j<=2; j++){
            ans=max(ans,a[i]*b[j]);
        }
    }
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 3164
#include<iostream>
#include<math.h>
#include<vector>
#include<algorithm>
#include<numeric>
#include<map>
#include<queue>
using namespace std;

int main(){
    int K;cin>>K;
    if(K%2==0)cout<<pow(K/2,2)<<endl;
    else cout<<(K/2)*(K/2+1)<<endl;

    return 0;
}

Measured memory_bytes: 256