akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define rep(i,a,b) for(int i=(int)(a);i<(int)(b);++i)
#define rrep(i,a,b) for(int i=(int)(a);i>=(int)(b);--i)
#define fore(i,a) for(auto &i:a)
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
#define isin(i,a,b) ((a) <= (i) && (i) < (b))
#define uni(a) (a).erase(unique(all(a)),(a).end())
#define fi first
#define se second
#define pb push_back
#define sz(a) (int)(a).size()
#define v(T) vector<T>
#define vv(T) v(v(T))
using namespace std;
using ll  = long long;
using unit= unsigned;
using ull = unsigned long long;
using P   = pair<int,int>;
using vi  = vector<int>;
using vl  = vector<ll>;
using vvi = vector<vi>;
using vp  = vector<P>;
void _main(); int main(){ cin.tie(0); ios::sync_with_stdio(false); _main(); }
template<class T>string join(const v(T)&v){stringstream s;rep(i,0,sz(v))s<<' '<<v[i];return s.str().substr(1);}
template<class T>inline ostream& operator<<(ostream&o,const v(T)&v){if(sz(v))o<<join(v);return o;}
template<typename T1,typename T2>inline ostream& operator<<(ostream&o,const pair<T1,T2>&v){return o<<v.fi<<","<<v.se;}
template<class T>void YES(T condition){ if(condition) cout << "YES" << endl; else cout << "NO" << endl; }
template<class T>void Yes(T condition){ if(condition) cout << "Yes" << endl; else cout << "No" << endl; }
template<class T>void POSS(T condition){ if(condition) cout << "POSSIBLE" << endl; else cout << "IMPOSSIBLE" << endl; }
template<class T>void Poss(T condition){ if(condition) cout << "Possible" << endl; else cout << "Impossible" << endl; }
template<class T>bool chmax(T &a, const T &b){ if (a<b){ a = b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b){ if (b<a){ a = b; return 1; } return 0; }
template<class T>T gcd(T a, T b){ if (b==0){ return a; }else{ return gcd(b, a%b); }}
template<class T>T lcm(T a, T b){ return a / gcd(a, b) * b; }
constexpr double eps = 1e-10;
constexpr int inf = INT_MAX / 2;
constexpr ll infl = 1LL << 60;

void _main() {
  int N;
  cin >> N;
  vi A(N);
  rep(i, 0, N) cin >> A[i];

  ll x2 = 0;
  rep(i, 0, N) {
    if (i & 1) x2 -= A[i];
    else       x2 += A[i];
  }

  vi ans(N, 0);
  ans[0] = x2 / 2;
  rep(i, 0, N-1) ans[i+1] = A[i] - ans[i];
  rep(i, 0, N)   ans[i] *= 2;
  rep(i, 0, N) cout << ans[i] << (i==N-1?"\n":" ");
}

Measured memory_bytes: 2176
#include <stdlib.h>
#include <bits/stdc++.h>
#include <math.h>
using namespace std;
using ll=long long;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
inline constexpr ll gcd(ll a,ll b){if(!a||!b)return 0;while(b){ll c=b;b=a%b;a=c;}return a;}
inline constexpr ll lcm(ll a,ll b){if(!a||!b)return 0;return a*b/gcd(a,b);}

int main() {
  long long a,b;
  cin>>a>>b;
  vector<vector<char>> data(a,vector<char>(b));
  rep(i,a){
    rep(j,b){
      cin>>data.at(i).at(j);
    }
  }
  rep(i,a){
    bool f3=false;
    rep(j,b){
      int numy=i;int numx=j;
      bool f1=true;bool f2=true;
      rep(k,a){
        if(data.at(k).at(numx)=='#'){
          f1=false;
        }
      }
      rep(l,b){
        if(data.at(numy).at(l)=='#'){
          f2=false;
        }
      }
      if(f1||f2){
      }
      else{
        cout<<data.at(numy).at(numx);
        f3=true;
      }
    }
    if(f3){
      cout<<endl;
    }
  }
}


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

using namespace std;

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

  if (s.length() == 1 && t.length() == 1 && s == t) {
    cout << 1 << endl;
    return 0;
  }

  unordered_map<char, vector<int>> index;

  int s_len = s.length();
  for (int i = 0; i < s_len * 2; ++i) {
    index[s[i % s_len]].push_back(i);
  }
  
  int cycle = 0;
  int p = -1;
  for (int i = 0; i < t.length(); ++i) {
    auto it = index.find(t[i]);
    if (it == index.end()) {
      puts("-1");
      return 0;
    }
    auto pos = lower_bound((it->second).begin(), (it->second).end(), p % s_len + 1);
    p = *pos;
    if (p >= s_len) ++cycle;
  }
  if (s.length() == 1) {
    cout << t.length() << endl;
    return 0;
  }
  cout << (long long) cycle * s_len + (p % s_len) + 1 << endl;
  return 0;
}



Measured memory_bytes: 1724
import sys
N,M=map(int,input().split())
if M==0:
  if N==1:
    ans=0
  else:
    ans=10**(N-1)
  print(ans)
  sys.exit()
listSC=[]  
for k in range(M):
  s,c=map(int,input().split())
  listSC+=[[s,c]]  
MIN=0  
if N==1:
  MIN=0
else:
  MIN=10**(N-1)
for i in range(MIN,10**N):
  A=list(str(i))
  for k in range(M):
    if A[listSC[k][0]-1]!=str(listSC[k][1]):
      break
    if k==M-1:
      ans=i
      print(ans)
      sys.exit()
  if i==10**N-1:
    print(-1)

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

int main()
{
    int N;
    cin >> N;
    vector<int> a(N);
    for (int i = 0; i < N; i++)
    {
        cin >> a[i];
    }
    vector<int> b(N);
    int l = 0;
    int r = N - 1;
    if (N % 2 == 0)
    {
        for (int i = N - 1; i >= 0; i--)
        {
            if (i % 2 == 1)
            {
                b[l] = a[i];
                l++;
            }
            else
            {
                b[r] = a[i];
                r--;
            }
        }
    }
    else
    {
        for (int i = N - 1; i >= 0; i--)
        {
            if (i % 2 == 0)
            {
                b[l] = a[i];
                l++;
            }
            else
            {
                b[r] = a[i];
                r--;
            }
        }
    }
    for (int i = 0; i < N; i++)
    {
        cout << b[i] << ' ';
    }
    cout << endl;
    return 0;
}

Measured memory_bytes: 3712
#include <bits/stdc++.h>
using namespace std;
#define _overload3(_1,_2,_3,_4,name,...) name
#define _rep(i,n) repi(i,0,n)
#define repi(i,a,n) (int i=a;i<n;i++)
#define per(i,a,n,s) (int i=n-1;i>=a;i--)
#define range(...) _overload3(__VA_ARGS__,per,repi,_rep,)(__VA_ARGS__)
#define all(x) (x).begin(),(x).end()
#define vecin(x) for(auto&youso_: (x) ) cin >>  youso_
#define vecout(x) for(auto&youso_: (x) ) cout << youso_ << " " ; cout << endl
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+10;
const int mod = 1e9+7;
const long long llinf = 1e18;
#define _GLIBCXX_DEBUG
// head

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

int main(){
    int h,w;
    cin >>h>>w;
    vector<string> s(h);
    vecin(s);
    // vecout(s);
    for range(i,h){
        for range(j,w){
            if (s[i][j]=='.'){
                int count =0;
                for range(d,8){
                    int nx=j+dx8[d];
                    int ny=i+dy8[d];
                    // cout <<nx<<" "<<ny<<endl;
                    if ((0<=nx && nx<w && 0<=ny && ny<h)){

                        if (s[ny][nx]=='#') count++;}
                }
                s[i][j]='0'+count;
            }
        }
    }
    for range(i,h){
        cout << s[i] << endl;
    }
        
    
}

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

#define all(A) begin(A), end(A)
#define sz(A) int(A.size())

using namespace std;

typedef long long ll;

int main () {
  ios::sync_with_stdio(false); cin.tie(0);
  int r, g, b, n;
  cin >> r >> g >> b >> n;
  int ans = 0;
  for (int i = 0; i <= n / r + 1; i++) {
    for (int j = 0; j <= n / g + 1; j++) {
      int k = n - i * r - j * g;
      if (k >= 0 and k % b == 0) {
        ans++;
      }
    }
  }
  cout << ans << endl;
  return (0);
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = int64_t;
template <typename T> using V = vector<T>;

bool solve() {
    ll T, D, L;
    cin >> T >> D >> L;
    if(!(T + D + L)) return false;
    ll rest_w = 0;
    ll ans = 0;
    for(ll i = 0; i < T; i++) {
        if(rest_w > 0) {
            ans++;
            rest_w--;
        }
        ll x;
        cin >> x;
        if(L <= x) rest_w = D;
    }
    cout << ans << endl;
    return true;
}

int main() {
    while(solve());
    return 0;
}



Measured memory_bytes: 3088
#include <iostream>
#include <string>
#include <vector>
#include <queue>
#include <map>
#include <algorithm>
#include <iomanip>

typedef long long ll;
const ll MOD = 1e9 + 7;
const long long INF = 1LL<<60;

const ll NMAX = 2010;
using namespace std;

double dp[310][310][310];
int n;
double calc(int i, int j, int k){
    if(dp[i][j][k] != 0) return dp[i][j][k];
    if(i == 0 && j == 0 & k == 0) return 0.0;

    double v = 0.0;
    v += i > 0 ? calc(i-1,j,k)*i : 0.0;
    v += j > 0 ? calc(i+1,j-1,k)*j : 0.0;
    v += k > 0 ? calc(i,j+1,k-1)*k : 0.0;
    v += n;
    v *= 1.0/(i+j+k);

    dp[i][j][k] = v;
    return v;
}

int main(){
    cin >> n;
    vector<int> a(n);
    vector<int> c(4);
    for(int i = 0; i < 4; i++) c[i] = 0;
    for(int i = 0; i < n; i++){
        cin >> a[i];
        c[a[i]] += 1;
    }

    for(int i = 0; i <= n; i ++){
        for(int j = 0; j <= n; j++){
            for(int k = 0; k <= n; k++){
                dp[i][k][j] = 0.0;
            }
        }
    }

    cout << std::fixed << std::setprecision(10) << calc(c[1],c[2],c[3]) << endl;
    return 0;
}

Measured memory_bytes: 227712
#include <iostream>
#include <numeric>
#include <algorithm>
#include <string>
#include <vector>

int main(void)
{
  int n;
  std::cin >> n;
  std::vector<int> a(n);
  for(auto& i: a){ std::cin >> i; }

  std::vector<int> b;
  int i;
  for(i = n-1; i >= 0; i-=2){ b.push_back(a[i]); }
  for(i = (i+3)%2; i < n; i+=2){ b.push_back(a[i]); }

  for(i = 0; i < n; ++i){
    std::cout << b[i];
    if(i != n-1){ std::cout << " "; }
  }
  std::cout << std::endl;

  return 0;
}






Measured memory_bytes: 3828
X, Y, A, B, C = map(int, input().split())
P = list(map(int, input().split()))
Q = list(map(int, input().split()))
R = list(map(int, input().split()))

P.sort(reverse=True)
Q.sort(reverse=True)
R.sort(reverse=True)


ans = 0
tX = X # Num of Ori. Red
tY = Y # Num of Ori. Green

for i in range(X):
  ans += P[i]
for i in range(Y):
  ans += Q[i]

temp = ans
#Update Section:
for i in range( min(X+Y, C) ): # i+1 = Num of Non. Color
  if tX > 0 and tY > 0:
      if P[tX-1] < Q[tY-1]:
        temp += R[i] - P[tX-1]
        tX -= 1
      else:
        temp += R[i] - Q[tY-1]
        tY -= 1
  elif tX == 0:
    temp += R[i] - Q[tY-1]
    tY -= 1
  else:# tX == 0:
    temp += R[i] - P[tX-1]
    tX -= 1
  ans = max(ans, temp)
  
print(ans)

Measured memory_bytes: 22720
//http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=GRL_7_A&lang=jp

#include <iostream>
#include <vector>
using namespace std;

class BM{
public:
	vector<vector<int> >G;
	vector<int>match;
	vector<int>used;
	BM(int n){
		G.resize(n);
	}
	void addEdge(int from, int to){
		G[from].push_back(to);
		G[to].push_back(from);
	}
	bool dfs(int v){
		used[v] = 1;
		for (int i = 0; i < G[v].size(); i++){
			int u = G[v][i];
			int w = match[u];
			if (w < 0 || !used[w] && dfs(w)){
				match[v] = u;
				match[u] = v;
				return true;
			}
		}
		return false;
	}
	int flow(){
		int res = 0;
		match.clear();
		match.resize(G.size(), -1);
		for (int v = 0; v < G.size(); v++){
			if (match[v] < 0){
				used.clear();
				used.resize(G.size(), 0);
				if (dfs(v)){
					res++;
				}
			}
		}
		return res;
	}
};

int main(){

	int X, Y, E;
	cin >> X >> Y >> E;
	BM bm(X + Y);
	for (int i = 0; i < E; i++){
		int x, y;
		cin >> x >> y;
		bm.addEdge(x, y + X);
	}
	cout << bm.flow() << endl;

	return 0;
}



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

//type
#define ll long long
typedef pair<int, int> P;
//定数
#define INF 1000000000000 //10^12:∞
#define MOD 1000000007    //10^9+7:合同式の法
#define MAXR 100000       //10^5:配列の最大のrange
//略記
#define PB push_back //挿入
#define MP make_pair //pairのコンストラクタ
#define F first      //pairの一つ目の要素
#define S second     //pairの二つ目の要素
#define Z class
// OTHER
// xの二乗を返す (関数テンプレート版)
template <typename T>
T square(T x) { return x * x; }
#define chmax(x, y) (x = max(x, y))
#define chmin(x, y) (x = min(x, y))
// loop
#define rep(i, n) for (int i = 0; i < (n); i++)
#define REPD(i, n) for (ll i = n - 1; i >= 0; i--)
#define FOR(i, a, b) for (ll i = a; i <= ll(b); i++)
#define FORD(i, a, b) for (ll i = a; i >= ll(b); i--)
#define FORA(i, I) for (const auto &i : I)

// vector
#define ALL(x) x.begin(), x.end()

// output
#define YES() printf("YES\n")
#define NO() printf("NO\n")
#define isYES(x) printf("%s\n", (x) ? "YES" : "NO")
#define Yes() printf("Yes\n")
#define No() printf("No\n")
#define ln cout << '\n'
template <Z A>
void pr(A a)
{
  cout << a;
  ln;
}
template <Z A, Z B>
void pr(A a, B b)
{
  cout << a << ' ';
  pr(b);
}

int ans = 0;
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *

int main()
{
  int n;
  cin >> n;
  pr(3 * n * n);
  return 0;
}


Measured memory_bytes: 3608
# -*- coding: utf-8 -*-

def input_one_number():
    return int(input())

def input_multiple_number():
    return map(int, input().split())

def input_multiple_number_as_list():
    return list(map(int, input().split()))

import math
PI = math.pi

A,B,H,M = input_multiple_number()

HHrad = 2*PI/12*H + 2*PI/12/60*M
MMrad = 2*PI*M/60

ans = pow(A**2 + B**2 -2*A*B*math.cos(HHrad-MMrad),0.5)

print(ans)



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

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    ll x,n,i,ans,p;
    cin>>x>>n;
    map<ll,ll> ma;
    for(i=0;i<n;i++)
    {
        cin>>p;
        ma[p]++;
    }
    for(i=0;i<250;i++)
    {
        if(ma[x-i]==0)
        {
            ans=x-i;
            break;
        }
        else if(ma[x+i]==0)
        {
            ans=x+i;
            break;
        }
    }
    cout<<ans;
   
    return 0;
}

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

int main() {
    int N;
    cin >> N;
    vector<int> v(N);
    rep(i, N) cin >> v[i];
    sort(v.begin(), v.end());
    double ans = v[0];
    rep(i, N - 1) ans = (ans + v[i + 1])/2;
    printf("%.10lf", ans);
    return 0;
}

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

using namespace std;

#define M  100000+100
typedef long long LL;

int main()
{

    LL n;
    cin>>n;
    if(n<=2) cout<<"0";
    else
    {
        cout<<(n-1)/2;
    }
    return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;
import java.util.regex.Pattern;

public class Main {
	
	public static void main(String[] args) {
		
		Scanner scanner = new Scanner(System.in);
		
		String A = scanner.next();
		
		scanner.close();
		
		boolean result = Pattern.matches("^[A-Z]+$", A);
		
		if (result) {
			System.out.println("A");
		} else {
			System.out.println("a");
		}
	}

}


Measured memory_bytes: 26980
import java.util.*;

public class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);

    int[] array = new int[5];
    for(int i=0; i<5; i++){
      array[i] = sc.nextInt();
    }

    int k = sc.nextInt();

    int sub = array[4] - array[0];

    if(sub>k){
      System.out.println(":(");
    }else{
      System.out.println("Yay!");
    }
  }
}

Measured memory_bytes: 23124
#include <bits/stdc++.h>
using namespace std;
#define MAX_N 100000
#define MAX_M 100000
const int INF = 1e9;

int main(){
    int n;
    cin>>n;
    vector<int> A(n);
    for(int i=0;i<n;i++){
        cin>>A[i];
    }
    sort(A.begin(),A.end());
    for(int i=0;i<n;i++){
        cout<<A[i];
        if(i+1<n) cout<<" ";
    }
    cout<<endl;
}


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

using VS = vector<string>;    using LL = long long;
using VI = vector<int>;       using VVI = vector<VI>;
using PII = pair<int, int>;   using PLL = pair<LL, LL>;
using VL = vector<LL>;        using VVL = vector<VL>;

#define ALL(a)  begin((a)),end((a))
#define RALL(a) (a).rbegin(), (a).rend()
#define SZ(a) int((a).size())
#define SORT(c) sort(ALL((c)))
#define RSORT(c) sort(RALL((c)))
#define UNIQ(c) (c).erase(unique(ALL((c))), end((c)))
#define FOR(i, s, e) for (int(i) = (s); (i) < (e); (i)++)
#define FORR(i, s, e) for (int(i) = (s); (i) > (e); (i)--)
//#pragma GCC optimize ("-O3") 
#ifdef YANG33
#include "mydebug.hpp"
#else
#define DD(x) 
#endif
const int INF = 1e9;                          const LL LINF = 1e16;
const LL MOD = 1000000007;                    const double PI = acos(-1.0);
int DX[8] = { 0, 0, 1, -1, 1, 1, -1, -1 };    int DY[8] = { 1, -1, 0, 0, 1, -1, 1, -1 };

/* -----  2019/03/12  Problem: ABC 084 A / Link: http://abc084.contest.atcoder.jp/tasks/abc084_a  ----- */


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

	LL N; 
	cin >> N;
	
	LL ans = 48-N;
	
	
	cout << (ans) << "\n";

	return 0;
}


Measured memory_bytes: 256
#include "bits/stdc++.h"
#define ll long long
#define rep2(i,a,b) for(int i=a;i<=b;++i)
#define rep(i,n) for(int i=0;i<n;i++)
#define pii pair<int,int>
#define tii tuple<int,int,int>
#define pq priority_queue<int>
#define pqg priority_queue<int,vector<int>,greater<int>>
#define pb push_back
#define edge(v,a,b) v[a].pb(b);v[b].pb(a);
ll MOD=1e9+7;
#define INF 2*1e9
#define N 400000
using namespace std;
//区間加算
static const int MAX_SIZE = 1 << 19; //segment tree のサイズ。 2^19 ≒ 5.2 * 10^5
ll all[2 * MAX_SIZE - 1], part[2 * MAX_SIZE - 1]; // segment tree
//区間[a, b)に値xを加算する.
void add(int a, int b, int x, int k, int l, int r)
{
    if (a <= l && r <= b){ //[l, r)が[a, b)に完全に内包されていれば
        all[k] += x; //[l, r)の全ての区間が持つ値としてxを足す.
    }
    else if (l < b && a < r){ //[l, r)と[a, b)が交差していれば
        part[k] += (min(b, r) - max(a, l)) * x;  //交差している分の値を, 部分的な和を持つノードに加算する.
        add(a, b, x, k * 2 + 1, l, (l + r) / 2); //子でも同じ処理を行う.
        add(a, b, x, k * 2 + 2, (l + r) / 2, r); //〃.
    }
}
void ADD(int a,int b,int x){
    add(a,b,x,0,0,MAX_SIZE);
}
ll sum(int a, int b, int k, int l, int r)
{
    if (b <= l || r <= a){ //[a, b)と[l, r)が全く交差しない場合
        return (0);
    }
    else if (a <= l && r <= b){ //完全に内包されていれば
        return (all[k] * (r - l) + part[k]);
    }
    else { //[l, r)と[a, b)が交差していれば
        ll res;
        res = (min(b, r) - max(a, l)) * all[k]; //そのノードの全ての要素が持つ値のうち, [a, b)に属すものの分だけを加算する.
        res += sum(a, b, k * 2 + 1, l, (l + r) / 2); //子ノードで和を求める.
        res += sum(a, b, k * 2 + 2, (l + r) / 2, r); //〃
        return (res);
    }
}
//[a,b)の和を求める
ll SUM(int a,int b){
    return sum(a,b,0,0,MAX_SIZE);
}
struct line{
    int length,left,right;
    bool operator<(const line& x){
        return (length<x.length);
    }
};
main(){
    int n,m;
  	cin>>n>>m;
    line l[N];
    rep(i,n){
        cin>>l[i].left>>l[i].right;
        l[i].length=(l[i].right-l[i].left+1);
    }
    sort(l,l+n);
    int num=n,temp=0;
    rep2(i,1,m){
        while(l[temp].length<i&&temp<n){
            num--;
            add(l[temp].left,l[temp].right+1,1,0,0,MAX_SIZE);
            temp++;
        }
        int ans=num;
        for(int j=0;j<=m;j+=i){
            ans+=sum(j,j+1,0,0,MAX_SIZE);
        }
        cout<<ans<<endl;
    }
}

Measured memory_bytes: 14208
#include <bits/stdc++.h>
using namespace std;
const int mod = 1000000007;

int main(){
    int W, a, b;
    cin >> W >> a >> b;
    int ans;
    if(a + W <= b){
        ans = b-(a+W);
    }else if(a <= b && b <= a +W){
        ans = 0;
    }else if (b <= a && a <= b+W){
        ans = 0;
    }else{
        ans = a-(b+W);
    }
    cout << ans << endl;
}

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

#define pb push_back
#define mp make_pair

#define F first
#define S second

using ll = long long;
using namespace std;

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

const int mod = 1000000007;
const int INF = 1e+9;

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

    int res = 0;
    while (true) {
        // Maxが0で終了
        if (*max_element(h.begin(), h.end()) == 0) break;

        // 区間分割する
        int i = 0;
        while (i < n) {
            if (h[i] == 0) ++i; // 0で何もしないで進む
            else {
                res++; // 区間の始まり
                while (i < n && h[i] > 0) {
                    --h[i];
                    i++;
                }
            }
        }
    }
    cout << res << endl;
}


Measured memory_bytes: 256
pub struct Scanner<R> {
    reader: R,
}

impl<R> Scanner<R> {
    pub fn new(reader: R) -> Scanner<R> {
        Scanner { reader }
    }
}

fn is_whitespace(b: u8) -> bool {
    b == b' ' || b == b'\n' || b == b'\r' || b == b'\t'
}

impl<R: std::io::Read> Scanner<R> {
    pub fn read<T: std::str::FromStr>(&mut self) -> T {
        let buf = std::io::Read::bytes(self.reader.by_ref())
            .map(|b| b.expect("Read failed"))
            .skip_while(|&b| is_whitespace(b))
            .take_while(|&b| !is_whitespace(b))
            .collect::<Vec<_>>();
        unsafe { std::str::from_utf8_unchecked(&buf) }
            .parse()
            .ok()
            .expect("Parse error")
    }

    pub fn read_vec<T: std::str::FromStr>(&mut self, n: usize) -> Vec<T> {
        (0..n).map(|_| self.read()).collect()
    }

    pub fn read_chars(&mut self) -> Vec<char> {
        self.read::<String>().chars().collect()
    }
}

fn main() {
    let stdin = std::io::stdin();
    let mut sc = Scanner::new(stdin.lock());
    loop {
        let n = sc.read::<usize>();
        if n == 0 {
            break;
        }
        let w = sc
            .read_vec::<String>(n)
            .iter()
            .map(|s| s.len())
            .collect::<Vec<_>>();
        for start in 0..n {
            let mut iter = w.iter().skip(start);
            let hike = [5, 12, 17, 24, 31];
            let mut ok = true;
            let mut sum = 0;
            for &c in &hike {
                while let Some(&w) = iter.next() {
                    sum += w;
                    if sum >= c {
                        break;
                    }
                }
                if sum != c {
                    ok = false;
                }
            }
            if ok {
                println!("{}", start + 1);
                break;
            }
        }
    }
}



Measured memory_bytes: 5036
#include <iostream>
using namespace std;
string check(string & a, string & b)
{
  for(int i = 0; i < a.size(); i++)
    if( a[i] != b[i] )
      return "No";
  return "Yes";
}
int main()
{
  string a, b;
  cin >> a >> b;
  cout << check(a,b);
  return 0;
}
  

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

vector<int> input(int N){
    int i;
    vector<int> output(N);
    for(i=0;i<N;i++)cin>>output[i];
    return output;
}

int main(){
    int N,i;
    vector<int> A;
    cin>>N;
    vector<int> result(N);
    A=input(N);

    for(i=0;i<N;i++){
        result[A[i]-1]=i+1;
    }

    cout<<result[0];
    for(i=1;i<N;i++)cout<<" "<<result[i];
    cout<<endl;
    
    return 0;
}

Measured memory_bytes: 1664
N = int(input())

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

m = None
for i in range(len(Ws)):
    s1 = sum(Ws[:i])
    s2 = sum(Ws[i:])
    if m is None:
        m = abs(s2 - s1)
    else:
        m = min(m, abs(s2-s1))
print(m)


Measured memory_bytes: 38512
#include <iostream>

using namespace std;

int main()
{
    ios_base::sync_with_stdio(0);
    string s, t;
    int a, b;
    string u;
    cin >> s >> t >> a >> b >> u;
    if (u == s)
        cout << a - 1 << " " << b;
    else
        cout << a << " " << b - 1;
    return 0;
}


Measured memory_bytes: 256
import java.util.*;
import java.lang.*;

import static java.lang.StrictMath.abs;

class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int d = sc.nextInt();
        if((n) %(2*d+1)>0){
            System.out.println(n/((2*d)+1)+1);
        }else {

            System.out.println(n / (2 * d+1));
        }
    }
}


Measured memory_bytes: 23764
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#define rep(i, n)   for(int i = 0; i < (n); i++)
using namespace std;
typedef long long ll;

ll pow(ll a, ll n){
    ll tmp = 1;
    rep(i, n)   tmp *= a;
    return tmp;
}

int main(){
    int x;  cin >> x;
    ll a, b;
    for(a = -200; a < 200; a++) for(b = -200; b < 200; b++){
        if(pow(a, 5) - pow(b, 5) == x){
            printf("%lld %lld\n", a, b);
            return 0;
        }
    }
}


Measured memory_bytes: 3748
PROGRAM ATCODER

implicit none
integer :: h,w,i,j
character(len=100),allocatable :: c(:)

read(*,*) h,w
allocate(c(h))

do i = 1, h
  read(*,*) c(i)
  write(*,'(a)') trim(c(i))
  write(*,'(a)') trim(c(i))
end do

contains
!!!!!! サブルーチンは↓
!!!!!!

END PROGRAM ATCODER

Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
 
// GNU C Compiler
//template<class T> inline string toString(T x) { ostringstream sout; sout << x; return sout.str(); }
 
 
/*
--------------------------------------------
 
	type
 
--------------------------------------------
*/
using LL = long long;
using ULL = unsigned long long;
//using pair<T1, T2> = p12;
 
/*
--------------------------------------------
 
	container
 
--------------------------------------------
*/
#define PB emplace_back
#define MP make_pair 
#define SZ(a) int((a).size())
 
/*
--------------------------------------------
 
	repetition
 
--------------------------------------------
*/
#define MAX(a,b) (a>b)?a:b
#define MIN(a,b) (a>b)?b:a
#define REP(n) for(int i=0; i<n; i++)
#define REPj(n) for(int j=0; j<n; j++)
#define REPinit(a,n) for(int i=a; i<n; i++)
#define REPinitj(a,n) for(int j=a; j<n; j++)
 
//algorithm
//#define SORT(c) sort((c).begin(),(c).end())
 
/*
--------------------------------------------
 
	constant
 
--------------------------------------------
*/
//clear memory
#define CLR(a) memset((a), 0 ,sizeof(a))
 
/*
 
	Optimizer
 
*/
//#pragma GCC optimize("Ofast")


/*
 
	Utility Algorithm
 
*/
template <typename T>
void swapAlgorithm(T& a, T& b) {
    T tmp = a;
    a = b;
    b = tmp;
}

LL euclideanAlgorithm(LL a, LL b) {
    LL a_tmp = a;
    LL b_tmp = b;

    if (a_tmp > b_tmp) {
        swapAlgorithm<LL>(a_tmp, b_tmp);
    }

    LL r = a_tmp % b_tmp;
    while (r != 0) {
        a_tmp = b_tmp;
        b_tmp = r;
        r = a_tmp % b_tmp;
    }
    return b_tmp;    
}

LL getLCM(LL a, LL b) {
    return (a * b)/(euclideanAlgorithm(a, b));
}

/*
  Code
*/

double eauclidDistance(pair<double, double>& x1, pair<double, double>& x2) {
  return sqrt((x1.first - x2.first) * (x1.first - x2.first) + (x1.second - x2.second) * (x1.second - x2.second));
}

void swap(int& a, int& b) {
  int tmp;
  tmp = a;
  a = b;
  b = tmp;
}

vector<string> squareNum(100101, "No");

int main(int argc, char const *argv[])
{
  for(int i=1; i < (int)(sqrt(100100)); i++) {
    squareNum[i*i] = "Yes";
  }

  string a,b;
  cin >> a >> b;

  int ab = atoi((a+b).c_str());
  cout << squareNum[ab] << endl;
  
  return 0;
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
#define int long long
using namespace std;
int dp[300005];
int mod = 1e9 + 7,ans;
int fp(int x,int y){
    if(!y)return 1LL;
    int ans = fp(x,y/2);
    ans*=ans;
    ans%=mod;
    if(y & 1)ans*=x;
    ans%=mod;
    return ans;
}
void addSelf(int&x,int y){
x+=y;
x%=mod;
}
int multiSelf(int x,int y){
    return (x*y)%mod;
}
 main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    int n,k;
    cin>>n>>k;
    for(int i =k; i>=1; i--){
        int cur = fp(k/i,n);
        for(int j =i*2; j<=k; j+=i)
            cur = ((cur % mod - dp[j]%mod )+ mod)%mod;
        dp[i] = cur;
        addSelf(ans,multiSelf(dp[i],i));
    }
    cout<<ans<<endl;


}


Measured memory_bytes: 4388
H,W = map(int,input().split())
S = "".join(input() for _ in [0]*H)
n = {}
for s in S: n[s] = n.get(s,0)+1
c = [0]*2
for i in n.values():
    if i%2:c[0]+=1
    if i%4>1:c[1]+=1
if H%2 and W%2: ans = c[0]==1 and (c[1]<=(H+W-2)//2)
elif H%2: ans = c[0]==0 and (c[1]<=W//2)
elif W%2: ans = c[0]==0 and (c[1]<=H//2)
else: ans = c[0]==c[1]==0
print("Yes" if ans else "No")

Measured memory_bytes: 3064
use std::io::{stdin, Read};

macro_rules! parse {
    ($it: ident) => {
        $it.next().unwrap().parse().unwrap()
    };
    ($it: ident,2) => {
        (parse!($it), parse!($it))
    };
    ($it: ident,3) => {
        (parse!($it), parse!($it), parse!($it))
    };
    ($it: ident,4) => {
        (parse!($it), parse!($it), parse!($it), parse!($it))
    };
    ($it: ident, $n: expr) => {
        (&mut $it).take($n).map(|e| e.parse().unwrap()).collect();
    };
}

fn solve(s: &str) {
    let mut it = s.split_whitespace();
    let (n, k): (usize, usize) = parse!(it, 2);
    let a = n % k;
    println!("{}", std::cmp::min(k - a, a));
}

fn main() {
    let mut s = String::new();
    stdin().read_to_string(&mut s).unwrap();
    solve(&s);
}

#[cfg(test)]
mod tests {
    use super::*;
    #[test]
    fn test_input() {
        let s = "
        ";
        solve(s);
    }
}


Measured memory_bytes: 4352
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <stdbool.h>
#include <math.h>

int main(void){

    int A, B;

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

    char S[A+B+2];

    scanf("%s", S);

    int f = 0;

    for(int i = 0; i < A+B+1; i++){
        if(i == A){
            if(S[i] != '-'){
                f = 1;
            }
        }else{
            if(S[i] < '0' || S[i] > '9'){
                f = 1;
            }
        }
    }

    if(f == 1){
        printf("No\n");
    }else{
        printf("Yes\n");
    }

    return 0;
}

Measured memory_bytes: 1620
#include <bits/stdc++.h>
using namespace std;
const int maxn = 2e5+5;
typedef long long ll;
ll val[maxn];
vector<int> edge[maxn];
int vis[maxn];

void init(){
    memset(vis, 0, sizeof(vis));
    memset(val, 0, sizeof(val));
    for(int i=0;i<maxn;i++){
        edge[i].clear();
    }
}

void dfs(int u, ll father_val){
    vis[u] = 1;
    val[u] += father_val;
    for(auto v:edge[u]){
        if(!vis[v]){
            dfs(v, val[u]);
        }
    }
}

int main()
{
    int n, q;
    while(cin>>n>>q){
        int a, b;
//        init();
        for(int i=0;i<n-1;i++){
            cin>>a>>b;
            edge[a].push_back(b);
            edge[b].push_back(a);
        }
        for(int i=0;i<q;i++){
            cin>>a>>b;
            val[a]+=b;
        }
        dfs(1, 0LL);
        for(int i=1;i<=n;i++){
            cout<<val[i]<<" ";
        }
        cout<<endl;
    }
    return 0;
}


Measured memory_bytes: 21888
#include<cstdio>
#include<algorithm>
int main(){
    int n,w[100],ans=1e9;
    scanf("%d",&n);
    for(int i=0;i<n;i++)scanf("%d",&w[i]);
    for(int t=0;t<n;t++){
        int s1=0,s2=0;
        for(int i=0;i<t;i++)s1+=w[i];
        for(int i=t;i<n;i++)s2+=w[i];
        ans=std::min(ans,std::abs(s1-s2));
    }
    printf("%d\n",ans);
    return 0;
}

Measured memory_bytes: 128
#include<iostream>
#include<vector>
#include<numeric>
#include<algorithm>
using namespace std;
class disjointset{
  public:
    vector<int>rank,parent,sz;
    disjointset(){}
	disjointset(int size){
        parent=vector<int>(size+1);
        rank=vector<int>(size+1,0);
        sz=vector<int>(size+1,1);
        iota(parent.begin(),parent.end(),0);
	}
    int root(int n){return (parent[n]==n?n:parent[n]=root(parent[n]));}
    void unite(int x,int y){
        x=root(x);y=root(y);
        if(x!=y){
            if(rank[x]>rank[y])parent[y]=x,sz[x]+=sz[y];
            else parent[x]=y,sz[y]+=sz[x];
            if(rank[x]==rank[y])rank[root(x)]++;
        }
    }
    bool same(int x,int y){return root(x)==root(y);}
    int size(int n){return sz[root(n)];}
};
int main(){
    int n,m;
    cin>>n>>m;
    disjointset ds(n);
    vector<int>a(m),b(m);
    vector<long long>ans(m);
    for(int i=0;i<m;i++)cin>>a[i]>>b[i];
    ans[0]=(long long)n*(n-1)/2;
    for(int i=m-1;i>0;i--){
        if(ds.same(a[i],b[i]))ans[m-i]=ans[m-i-1];
        else ans[m-i]=ans[m-i-1]-(long long)ds.size(a[i])*ds.size(b[i]);
        ds.unite(a[i],b[i]);
    }
    reverse(ans.begin(),ans.end());
    for(auto x:ans)cout<<x<<endl;
    return 0;
}

Measured memory_bytes: 4096
#include<stdio.h>
int main()
{
    int a,b,c;
    scanf("%d %d",&a,&b);
    if(a==1 && b==2)
        printf("3");
     else if(a==2 && b==1)
        printf("3");
         else if(a==3 && b==1)
        printf("2");
         else if(a==1 && b==3)
        printf("2");
         else if(a==2 && b==3)
        printf("1");
    else
        printf("1");
        return 0;



}

Measured memory_bytes: 128
#include<bits/stdc++.h>
#define int long long
#define F first
#define S second
#define pb push_back
#define mp make_pair
#define all(v) v.begin(),v.end()
#define hell 1000000007
#define rep(i,a,b) for(int i=a;i<b;i++)
#define repd(i,a,b) for(int i=a;i>=b;i--)
using namespace std;
void solve(){
    int n;
    cin>>n;
    int ans = 1e18;
    for(int i = 1;i*i<=n;i++){
        if(n%i==0){
            ans = min(ans,i+(n/i)-2);
        }
    }
    cout<<ans<<endl;
    return;
}
signed main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    // #ifndef ONLINE_JUDGE
    //     freopen("input.txt", "r", stdin);
    //     freopen("output.txt", "w", stdout);
    // #endif
    int tests = 1;
    //cin>>tests;
    while(tests--){
        solve();
    }
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#include<bits/stdc++.h>
using namespace std;
typedef     long long    ll;
typedef     vector<int> vi;
typedef     vector<long long> vl;
typedef     pair<int, int>pi;
typedef     pair<long long, long long>pl;
#define F   first
#define S   second
#define pb  push_back
#define     all(x)      x.begin() , x.end()
#define mp  make_pair
#define       FOR(i,a,b) for(i=a;i<=b;i++)
#define     mem(a)      memset(a , 0 ,sizeof a)
#define     memn(a)     memset(a , -1 ,sizeof a)
 int main()
 {
   string s,t;
   char ch;
   cin>>s>>t;
   cout<<t<<s<<endl;
 }

Measured memory_bytes: 3568
fun main(args: Array<String>) {
    val (a, b) = readLine()?.split(" ")?.map { it.toInt() } ?: return
    var count = 0
    for (i in a..b) {
        if ((i / 10000) != (i % 10)) {
            continue
        }
        val mid = (i % 10000) / 10
        if ((mid / 100) != (mid % 10)) {
            continue
        }
        count++
    }
    println(count)
}

Measured memory_bytes: 38000
import sys
input = sys.stdin.readline


def main():
    N = int(input())
    A = list(map(int, input().strip().split()))

    total = sum(A)
    for i, a in enumerate(A):
        if i%2 == 0:
            continue
        total -= 2*a
    ans = [total]

    for i, a in enumerate(A):
        tmp = 2*a - ans[i]
        ans.append(tmp)

    print(" ".join(map(str, ans[:-1])))


if __name__ == "__main__":
    main()


Measured memory_bytes: 81432
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
using namespace std;
typedef long long ll;

int main(){
    int n,q,l,r,ans,A[100000],B[100000];
    string s;
    cin>>n>>q>>s;
    A[0]=0;
    B[0]=0;
    for(int i=1;i<n;i++){
        A[i]=0;
        if(s[i-1]=='A'&&s[i]=='C')A[i]=1;
        B[i]=B[i-1]+A[i];
    }
    for(int i=0;i<q;i++){
        cin>>l>>r;
        ans=B[r-1]-B[l-1];
        cout<<ans<<endl;
    }
}


Measured memory_bytes: 1408
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp> 
#include <ext/pb_ds/detail/standard_policies.hpp>
using namespace __gnu_pbds;
using namespace std;
#define getbit(n, i) (((n) & (1LL << (i))) != 0) 
#define setbit0(n, i) ((n) & (~(1LL << (i)))) 
#define setbit1(n, i) ((n) | (1LL << (i))) 
#define togglebit(n, i) ((n) ^ (1LL << (i))) 
#define lastone(n) ((n) & (-(n))) 
char gap = 32;
template<typename T> 
ostream& operator<<(ostream &os, const vector<T> &v) { 
    os << '{'; 
    for (const auto &x : v) os << gap << x;
        return os << '}'; 
}
template<typename A, typename B> 
ostream& operator<<(ostream &os, const pair<A, B> &p) {
        return os << '(' << p.first << gap << p.second << ')';
}

template <class T>
void read(T &x) {
    char c;
    for (c = getchar(); c < '0' || c > '9'; c = getchar())
        ;
    for (x = 0; c <= '9' && c >= '0'; c = getchar()) x = x * 10 + (c & 15);
}
#define ll long long 
#define lll __int128_t
#define pb push_back
#define mp make_pair
typedef pair < int,int> ii;
typedef vector<ii> vii;
typedef vector<ll>vl;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef tree<
int,
null_type,
less<int>,
rb_tree_tag,
tree_order_statistics_node_update>
ordered_set;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
ll hashPrime = 1610612741;

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    ll n;
    cin >> n;
    cout << (n + 1) % 2;
    return 0;
}

Measured memory_bytes: 3612
#define _CRT_SECURE_NO_WARNINGS
#include<bits/stdc++.h>
#define fi first
#define se second
#define pb push_back
#define E "\n"

using namespace std;
const long long MOD = 1e9 + 7;

long long ans, a, b, c, d;

int main()
{
  ios::sync_with_stdio(0); cin.tie(0);
  cin >> a >> b >> c >> d;
  ans = -1e18;
  ans = max(ans, a * c);
  ans = max(ans, a * d);
  ans = max(ans, b * c);
  ans = max(ans, b * d);
  cout << ans << E;
  //system("pause");
  return 0;
}

Measured memory_bytes: 3648
import Control.Applicative
import Data.List
main = do
  [w, h, x, y, r] <- (map read . words) <$> getLine
  putStrLn $ isThereCircleInRectangle w h x y r

isThereCircleInRectangle w h x y r
  | r <= x && x <= w - r && r <= y && y <= h - r = "Yes"
  | otherwise = "No"

Measured memory_bytes: 3568
from sys import stdin
nii=lambda:map(int,stdin.readline().split())
lnii=lambda:list(map(int,stdin.readline().split()))

n,k=nii()
a=lnii()

x=0
x_list=[1]
x_table=[0 for i in range(n+1)]
x_table[1]=1

for i in range(k):
  nx=a[x]

  if x_table[nx]!=0:
    inx=x_list.index(nx)
    loop=x_list[inx:]
    zan=k-i

    q=zan%len(loop)

    nx=loop[q-1]
    break

  else:
    x=nx-1
    x_list.append(nx)
    x_table[nx]+=1

print(nx)

Measured memory_bytes: 104908
#include<bits/stdc++.h>
using namespace std;
using ll=long long;
int main()
{
ll a,b,c;
cin>>a>>b>>c;
ll ans=b*((a)/(b+c)),d;
d=(a%(c+b));
if(d<=b)ans+=d;
else ans+=b;
cout<<ans;
}

Measured memory_bytes: 3508
#include<iostream>
#include<algorithm>
#include<functional>
#include<cmath>
#include<string>
#include<vector>
#include<stack>
#include<queue>
#include<map>
#include<set>
#include<deque>
using namespace std;
#define ll long long
const int mod = 1000000007;
const ll INF = 1000000000000000000;


int main()
{
	string c[3];
	cin >> c[0] >> c[1] >> c[2];
	cout << c[0][0] << c[1][1] << c[2][2] << endl;
}

Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
#define rep(i,n) for(int (i)=0;(i)<(int)(n);++(i))
#define rer(i,l,u) for(int (i)=(int)(l);(i)<=(int)(u);++(i))
#define reu(i,l,u) for(int (i)=(int)(l);(i)<(int)(u);++(i))
static const int INF = 0x3f3f3f3f; static const long long INFL = 0x3f3f3f3f3f3f3f3fLL;
typedef vector<int> vi; typedef pair<int, int> pii; typedef vector<pair<int, int> > vpii; typedef long long ll;
template<typename T, typename U> static void amin(T &x, U y) { if (y < x) x = y; }
template<typename T, typename U> static void amax(T &x, U y) { if (x < y) x = y; }

int main() {
	int N;
	while (~scanf("%d", &N)) {
		vector<int> A(N + 2);
		for (int i = 1; i < N + 1; ++ i)
			scanf("%d", &A[i]);
		ll sum = 0;
		rep(i, N + 1)
			sum += abs(A[i + 1] - A[i]);
		rep(i, N) {
			ll ans =
				sum -
				abs(A[i + 1] - A[i]) -
				abs(A[i + 2] - A[i + 1]) +
				abs(A[i + 2] - A[i]);
			printf("%lld\n", ans);
		}
	}
	return 0;
}


Measured memory_bytes: 1664
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define REP(i, a, b) for(ll i=(a); i<(b); i++)
#define PER(i, a, b) for(ll i=(a); i>=(b); i--)
#define rep(i, n) REP(i, 0, n)
#define per(i, n) PER(i, n, 0)
#define ALL(a)  (a).begin(),(a).end()
const ll INF = 1e18+18;
const ll MAX = 200000;
const ll MOD = 1000000007;
#define Yes(n) cout << ((n) ? "Yes" : "No") << endl;
#define YES(n) cout << ((n) ? "YES" : "NO") << endl;



int main(){
    ll H, W, K;
    cin>>H>>W>>K;
    vector<vector<ll>> S(H, vector<ll>(W));
    rep(i, H){
        rep(j, W){
          	char C;
          	cin>>C;
          	
            S[i][j]=C-'0';
        }
    }
    ll Ans=100000007;
    for(ll bit=0; bit<(1<<H-1); ++bit){
        ll T=1;
        rep(i, H-1){
            if(bit&(1<<i))T++;
        }
		//cout<<"T="<<T<<" ";
        vector<vector<ll>> U(T, vector<ll>(W, 0));
        ll P=0;
        rep(i, H){
            rep(j, W){
              	
                if(S[i][j])U[P][j]++;
              	//cout<<U[P][j]<<" ";
            }
            if(i<=H-2){
                if(bit&(1<<i)){
                  	P++;
              		//cout<<"!";
                }
            }
        }
      	
        vector<ll> Su(T, 0);
        ll Cou=0;
        bool Over=false;
        rep(j, W){
            bool Change=false;
            rep(i, T){
                Su[i]+=U[i][j];
                if(Su[i]>K)Change=true;
            }
            if(Change){
                Cou++;
                rep(i, T){
                    Su[i]=U[i][j];
                    if(Su[i]>K)Over=true;
                }
            }
        }
        if(Over)continue;
        Ans=min(Ans, T+Cou-1);
      	//cout<<" Ans="<<T+Cou-1<<endl;
    }
    cout<<Ans<<endl;
}



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

struct Food {
	int id;
	string name;
	int w, s;
	
	Food(){id = 0; w = 0; s = 0;}
	
	bool operator < (const Food &t) const {
		return id < t.id;
	}
};

int main()
{
	int n;
	
	while (scanf("%d", &n), n){
		vector<Food> f(n);
		
		for (int i = 0; i < n; i++){
			f[i].id = i;
			cin >> f[i].name >> f[i].w >> f[i].s;
		}
		
		vector<Food> res(n);
		int minG = 1001001001;
		
		do {
			int sum = 0;
			bool fl = false;
			for (int i = n - 1; i >= 0; i--){
				if (f[i].s < sum){
					fl = true;
					break;
				}
				sum += f[i].w;
			}
			
			if (!fl){
				int G = 0;
				for (int i = 0; i < n; i++){
					G += f[i].w * (i + 1);
				}
				
				if (minG > G){
					res = f;
					minG = G;
				}
			}
			
		} while (next_permutation(f.begin(), f.end()));
		
		for (int i = 0; i < n; i++){
			cout << res[i].name << endl;
		}
	}
	
	return 0;
}

Measured memory_bytes: 1256
#include <iostream>
#include <vector>
#include <string.h>
#include <stack>
#include <queue>
#include <algorithm>
#include <climits>
#include <cmath>
#include <map>
#include <set>
#include <assert.h>
#include <sstream>
#include <bitset>
#define REP(i,n) for(ll i=0;i<(n);i++)
#define MOD 1000000007
#define int long long
#ifdef int
const long long INF = LLONG_MAX / 10;
#else
const int INF = 1010101010;
#endif
using namespace std;
typedef long long ll;
typedef vector<vector<ll>> mat;
typedef pair<int, int> P;
//typedef pair<double, double> P;



signed main()
{
    int A[3];

    cin >> A[0] >> A[1] >> A[2];
    sort(A, A + 3);

    if (A[0] == A[1]) {
        cout << A[2] << endl;
    } else {
        cout << A[0] << endl;
    }
}


Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<map>

const int MAXN=4e5+5;

int R,C,n;

int seq[MAXN];
inline int getp(int r,int c)
{
	if(!r) return c;
	if(c==C) return C+r;
	if(r==R) return C+R+C-c;
	if(!c) return C+R+C+R-r;
	return -1;
}

std::map<int,int> mp;
int st[MAXN],tp;
inline bool jud()
{
	for(std::map<int,int>::iterator i=mp.begin();i!=mp.end();i++) if(i->second)
		i->second^st[tp]?st[++tp]=i->second:tp--;
	return !tp;
}

int main()
{
	int i;scanf("%d%d%d",&R,&C,&n);
	for(i=1;i<=n;i++)
	{
		int x1,y1,x2,y2;scanf("%d%d%d%d",&x1,&y1,&x2,&y2);
		int p1=getp(x1,y1),p2=getp(x2,y2);
		if(~p1&&~p2) mp[p1]=mp[p2]=i;
	}
	puts(jud()?"YES":"NO");
	return 0;
}

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

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int N;
  string S;
  cin >> N >> S;

  int ans = 0;
  for (int i = 0; i < N; i++) {
    int count = 0;
    string X, Y;
    X = S.substr(0, i + 1);
    Y = S.substr(i + 1);
    sort(X.begin(), X.end());
    sort(Y.begin(), Y.end());
    X.erase(unique(X.begin(), X.end()), X.end());
    Y.erase(unique(Y.begin(), Y.end()), Y.end());
    for (int j = 0; j < X.size(); j++) {
      for(int k = 0; k < Y.size(); k++) {
        if (X.at(j) == Y.at(k)) {
          count ++;
          break;
        }
      }
    }
    ans = max(ans, count);
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
use std::collections::HashSet;
use std::io::stdin;

fn main() {
    let mut s = String::new();
    stdin().read_line(&mut s).ok();
    let mut itr = s.split_whitespace().map(|e| e.parse().unwrap());
    let n: usize = itr.next().unwrap();
    let k: usize = itr.next().unwrap();
    let mut set = HashSet::new();

    for _ in 0..k {
        s.clear();
        stdin().read_line(&mut s).ok();
        let d: usize = s.trim().parse().unwrap();
        s.clear();
        stdin().read_line(&mut s).ok();
        let mut itr = s.split_whitespace().map(|e| e.parse::<usize>().unwrap());
        for e in itr {
            set.insert(e);
        }
    }

    let mut ans = 0;
    for i in 1..=n {
        if !set.contains(&i) {
            ans += 1;
        }
    }

    println!("{}", ans);
}


Measured memory_bytes: 2156
#include<stdio.h>
#define N 100
#define INF 10000000

void DFS(int,int);

int n,size[N],c[N][N],d[N],to[N][N];

int main(int argc,char *argv[]){
  int i,j,u;

  scanf("%d",&n);
  for(i=0;i<n;i++){
    scanf("%d",&u);
    scanf("%d",&size[u]);
    for(j=0;j<size[u];j++){
      scanf("%d",&to[u][j]);
      scanf("%d",&c[u][j]);
    }
  }

  for(i=0;i<n;i++) d[i] = INF;
  DFS(0,0);
  for(i=0;i<n;i++){
    printf("%d %d\n",i,d[i]);
  }

  return 0;
}

void DFS(int p,int x){
  int i;
  d[p] = x;
  for(i=0;i<size[p];i++){
    if(d[to[p][i]] > x + c[p][i]) DFS(to[p][i],x + c[p][i]);
  }
}

Measured memory_bytes: 676
#include <queue>
#include <limits>
#include <string>
#include <vector>
#include <iostream>
#include <algorithm>
using namespace std;
struct edge {
	int to, cost;
	edge(int to_, int cost_) : to(to_), cost(cost_) {};
};
bool operator<(const edge& e1, const edge& e2) {
	return e1.cost < e2.cost;
}
template<class Type>
std::vector<Type> shortest_path(std::vector<std::vector<edge> > &G, int s) {
	std::priority_queue<edge> que; que.push(edge(s, 0));
	std::vector<Type> ret(G.size(), std::numeric_limits<Type>::max()); ret[s] = 0;
	while (!que.empty()) {
		edge u = que.top(); que.pop();
		for (edge e : G[u.to]) {
			if (ret[e.to] > ret[u.to] + e.cost) {
				ret[e.to] = ret[u.to] + e.cost;
				que.push(edge(e.to, -ret[e.to]));
			}
		}
	}
	return ret;
}
int n, m, d, e;
int main() {
	while (cin >> n >> m, n) {
		string s, t, g;
		cin >> s >> t >> g;
		vector<string> a(m), b(m), r; vector<int> x(m);
		for (int i = 0; i < m; i++) {
			cin >> a[i] >> b[i] >> d >> e;
			x[i] = d / 40 + e;
			r.push_back(a[i]);
			r.push_back(b[i]);
		}
		sort(r.begin(), r.end());
		r.erase(unique(r.begin(), r.end()), r.end());
		int sp = lower_bound(r.begin(), r.end(), s) - r.begin();
		int tp = lower_bound(r.begin(), r.end(), t) - r.begin();
		int gp = lower_bound(r.begin(), r.end(), g) - r.begin();
		vector<vector<edge> > G(n);
		for (int i = 0; i < m; i++) {
			int ptr1 = lower_bound(r.begin(), r.end(), a[i]) - r.begin();
			int ptr2 = lower_bound(r.begin(), r.end(), b[i]) - r.begin();
			G[ptr1].push_back(edge(ptr2, x[i]));
			G[ptr2].push_back(edge(ptr1, x[i]));
		}
		int w1 = shortest_path<int>(G, sp)[tp];
		int w2 = shortest_path<int>(G, tp)[gp];
		cout << w1 + w2 << endl;
	}
	return 0;
}

Measured memory_bytes: 3924
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<math.h>
using namespace std;
int main(){
vector<int>vec(3);
 
for(int i=0;i<3;i++){
	cin>>vec[i];
}
sort(vec.begin(),vec.end());
 
if(vec[0]==5&&vec[1]==5&&vec[2]==7)
cout<<"YES"<<endl;
else
cout<<"NO"<<endl;
}

Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main {

	public static void main(String[] args) throws IOException {
		// TODO 自動生成されたメソッド・スタブ
		InputStreamReader ir = new InputStreamReader(System.in);
		BufferedReader br = new BufferedReader(ir);
		String in = br.readLine();
		String result = in.replace(',', ' ');
		System.out.println(result);

	}

}


Measured memory_bytes: 8148