akhauriyash/Code-Regression huggingface dataset:
h,w = map(int,input().split())
a = list()
for i in range(h):
    s = input()
    if s != '.'*w:
        a.append(s)
n = len(a)
k = 0
while k < w:
    if all(a[i][k] == '.' for i in range(n)):
        for j in range(n):
            a[j] = a[j][:k] + a[j][k+1:]
        w -= 1
    else:
        k += 1
for i in range(n):
    print(a[i])

Measured memory_bytes: 3064
#include<iostream>
#include<string>
#include<set>
using namespace std;
int A(string a,string b){
	set <char> S1,S2;
	for(int i=0;i<a.size();i++)
		S1.insert(a[i]);
	for(int i=0;i<b.size();i++)
		S2.insert(b[i]);
	set <char>::iterator it1=S1.begin();
	set <char>::iterator it2=S2.begin();
	int ans=0;
	while(it1!=S1.end()&&it2!=S2.end()){
		if(*it1==*it2){
			ans++;
			it1++;it2++;
		}
		else if(*it1<*it2)
			it1++;
		else it2++;
	}
	return ans;
}
int main(){
	int n;
	string s;
	cin>>n>>s;
	int a=0;
	for(int i=1;i<n-1;i++){
		a=max(a,A(s.substr(0,i),s.substr(i)));
	}
	cout<<a<<endl;
}

Measured memory_bytes: 256
#include <stdio.h>
int m[100][100];
int d[100];


void visit(int u){

}

int main (){
  int i,j,n,k,u,r;

  scanf("%d",&n);
  for(i=0;i<n;i++)
    for(j=0;j<n;j++)
      m[i][j] = 0;

  for(i=0;i<n;i++){
    scanf("%d",&r);
    scanf("%d",&k);
    for(j=0;j<k;j++){
      scanf("%d",&u);
      m[r-1][u-1] = 1;
    }
  }
  for(i=0;i<n;i++){
    for(j=0;j<n;j++){
      printf("%d",m[i][j]);
      if(j<n-1) printf(" ");
    }
    printf("\n");
  }
  return 0;
}

    

Measured memory_bytes: 640
#include<iostream>
#include<algorithm>
using namespace std;
int main() {
	int n;
	while (cin >> n, n) {
		int imos[86410] = {};
		for (int i = 0; i < n; i++) {
			int a, b, c, d, e, f; char ch;
			cin >> a >> ch >> b >> ch >> c;
			cin >> d >> ch >> e >> ch >> f;
			imos[a * 3600 + b * 60 + c]++;
			imos[d * 3600 + e * 60 + f]--;
		}
		int ans = imos[0];
		for (int i = 1; i <= 86400; i++) {
			imos[i] += imos[i - 1];
			ans = max(ans, imos[i]);
		}
		cout << ans << endl;
	}
}

Measured memory_bytes: 3396
s = input()
a = None
z = None
for i in range(len(s)):
  j = len(s)-1-i
  if a == None and s[i] == 'A':
    a = i
  if z == None and s[j] == 'Z':
    z = j
s = z - a + 1
# print("a,z,s",a,z,s)
print(s)

Measured memory_bytes: 3516
#include<bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define rrep(i,n) for (int i = (n)-1; i >= 0; i--)
#define rep2(i,s,n) for (int i = (s); i < (n); ++i)
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define pb push_back
#define eb emplace_back
#define vi vector<int>
#define vvi vector<vector<int>>
#define vl vector<ll>
#define vvl vector<vector<ll>>
#define vd vector<double>
#define vs vector<string>
#define vc vector<char>
#define vb vector<bool>
#define vp vector<P>
using namespace std;
using ll = long long;
using P = pair<int,int>;
using LP = pair<ll,ll>;
template<class S,class T> istream& operator>>(istream &is,pair<S,T> &p) { return is >> p.first >> p.second; }
template<class S,class T> ostream& operator<<(ostream &os,const pair<S,T> &p) { return os<<'{'<<p.first<<","<<p.second<<'}'; }
template<class T> istream& operator>>(istream &is,vector<T> &v) { for(T &t:v){is>>t;} return is; }
template<class T> ostream& operator<<(ostream &os,const vector<T> &v) { os<<'[';rep(i,v.size())os<<v[i]<<(i==v.size()-1?']':','); return os; }
void Yes(bool b) { cout << (b ? "Yes" : "No") << endl; }
void YES(bool b) { cout << (b ? "YES" : "NO") << endl; }
template<class T> bool chmin(T& a,T b) {if(a > b){a = b; return true;} return false;}
template<class T> bool chmax(T& a,T b) {if(a < b){a = b; return true;} return false;}
const int inf = 1001001001;
const ll linf = 1001001001001001001;

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr); cout.tie(nullptr);
    int q;
    cin >> q;
    while(q--) {
        int a,b;
        cin >> a >> b;
        if(a > b) swap(a,b);
        if(b == 1) {
            cout << 0 << endl;
            continue;
        }
        ll c = (ll)a*b;
        ll ans = a-1;
        int ok = 1,ng = inf;
        auto f = [&](int x) {
            return (ll)x*(x-1) <= c;
        };
        while(abs(ok-ng) > 1) {
            int mid = (ng+ok)/2;
            if(f(mid)) ok = mid;
            else ng = mid;
        }
        chmin(ok,b-1);
        if((c+ok-1)/ok-1 > a) {
            ans += ok;
            ll mx = (c+ok-1)/ok-1;
            ll mn = max((c+b-2)/(b-1)-1,a+1LL);
            ans += mx-mn;
        } else {
            ans += (c+a)/(a+1)-1;
        }
        cout << ans << "\n";
    }
//    int a,b;
//    cin >> a >> b;
//    int ans = 0;
//    vi used(1000,0);
//    used[b] = 1;
//    rep2(i,1,1000) {
//        if(i == a) continue;
//        rrep(j,1000) {
//            if(j == 0) break;
//            if(i*j >= a*b) continue;
//            if(used[j]) continue;
//            used[j] = 1;
//            cout << make_pair(i,j) << endl;
//            ans++;
//            break;
//        }
//    }
//    cout << ans << endl;
}


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

using namespace std;

#define REP1(i,n) for(int i=1, i##_len=(n); i<i##_len; ++i)
#define REP(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define pow(x) x*x
#define ll long long
static const ll MAX = 1000000;
static const ll INFTY = 1e12;
static const ll MOD = 1000000007;

template < typename T > inline string toString( const T &a ) { ostringstream oss; oss << a; return oss.str(); };

struct edge {
    ll to, cost;
};

using Graph = vector<vector<int>>;
using _Graph = vector<vector<edge>>;


const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};

// 深さ優先探索
vector<bool> seen;
vector<int> colors;

int H, W, N;
int sx, sy, gx, gy; 
vector<vector<char>> field;
vector<vector<int>> dist;
//vector<pair<int, int>> gx, gy;
deque<pair<int, int>> que;

typedef vector<vector<int> > Matrix;

const int INF = 100000000;


int main() {

    ll N, K;
    cin >> N >> K;

    // cout << summin << " " << summax << endl;
    ll ans = 0;
    for(ll i = K; i <= N+1; i++){
        ll max_ = N-i+1;
        ll min_ = i-1;
        ll summax = (N + max_) * i / 2;
        ll summin = (0 + min_) * i / 2;
        ans += summax - summin + 1;
        ans %= MOD;
        // cout << ans << endl;
    }

    cout << ans << endl;

}


/*
                   _ooOoo_
                  o8888888o
                  88" . "88
                  (| -_- |)
                  O\  =  /O
               ____/`---'\____
             .'  \\|     |//  `.
            /  \\|||  :  |||//  \
           /  _||||| -:- |||||-  \
           |   | \\\  -  /// |   |
           | \_|  ''\---/''  |   |
           \  .-\__  `-`  ___/-. /
         ___`. .'  /--.--\  `. . __
      ."" '<  `.___\_<|>_/___.'  >'"".
     | | :  `- \`.;`\ _ /`;.`/ - ` : | |
     \  \ `-.   \_ __\ /__ _/   .-` /  /
======`-.____`-.___\_____/___.-`____.-'======
                   `=---='
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
         pass System Test!
*/


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

using Pixel = std::vector<std::vector<char>>;

Pixel init_pixel(int width, int height) {
        Pixel pixel;
        pixel.resize(height + 1);

        for (auto &inner_pixel: pixel) {
                inner_pixel.resize(width);
        }

        char input;
        for (int i = 1; i <= height; i++) {
                for (int j = 0; j < width; j++) {
                        std::cin >> input;
                        pixel[i][j] = input;
                }
        }
        return pixel;
}

void height_twice_pixel(Pixel &orig, int width, int height) {
        orig.resize((height * 2) + 1);
        for (auto &orig_inner: orig) {
                orig_inner.resize(width);
        }
}

Pixel paint(Pixel &orig, int width, int height) {
        Pixel result(orig);
        for (int i = 1; i <= height * 2; i++) {
                for (int j = 0; j < width; j++) {
                        result[i][j] = orig[(i + 1) / 2][j];
                }
        }
        return result;
}

void output(Pixel &pixel, int width, int height) {
        for (int i = 1; i <= height * 2; i++) {
                for (int j = 0; j < width; j++) {
                        std::cout << pixel[i][j];
                }
                std::cout << std::endl;
        }
}

int main(int argc, char *argv[]) {
        int height = 0;
        int width = 0;

        std::cin >> height;
        std::cin >> width;

        Pixel pixel(init_pixel(width, height));

        height_twice_pixel(pixel, width, height);
        Pixel result = paint(pixel, width, height);
        output(result, width, height);

        return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
int main(){
  
  int a[11]={},i,temp,j;
  
  for(i=0;i<10;i++){
    scanf("%d",&a[i]);
  }

  for(i=0;i<9;i++){
    for(j=9;j>i;j--){
      if(a[j]>a[j-1]){
	temp=a[j];
	a[j]=a[j-1];
	a[j-1]=temp;
      }
    }
  }
  
  for(i=0;i<3;i++){
    printf("%d\n",a[i]);
  }
  
  return 0;
}

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

using namespace std;

const int MAX_M = 100000;
int n, m;
int pref[MAX_M] = {};
pair<int, pair<int, int> > yp[MAX_M];

int main()
{
  cin >> n >> m;
  for (int i = 0; i < m; ++i) {
    cin >> yp[i].second.second >> yp[i].first;
    yp[i].second.first = i;
  }

  sort(yp, yp+m);

  vector<pair<int, pair<int, int> > > l;
  for (int i = 0; i < m; i++) {
    int j = yp[i].second.second-1;
    pref[j]++;
    l.push_back(make_pair(yp[i].second.first, make_pair(j+1, pref[j])));
  }

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

  for (auto p : l) {
    printf("%06d%06d\n", p.second.first, p.second.second);
  }

  return 0;
}


Measured memory_bytes: 4340
fun main(args: Array<String>) {
    val N = readLine()!!.toInt()
    val AN = readLine()!!.split(" ").map(String::toInt)

    val map = mutableMapOf<Int, Long>()
    for (A in AN) {
        map[A] = map.getOrElse(A, { 0L }) + 1L
    }

    fun nC2(n: Long): Long {
        return n * (n - 1) / 2
    }

    var sum = 0L
    for ((k, v) in map) {
        sum += nC2(v)
    }

    for (A in AN) {
        val v = map[A]!!
        val before = nC2(v)
        val after = nC2(v - 1)
        println(sum + after - before)
    }
}


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

typedef long long ll;
typedef pair<int, int> P;
typedef pair<ll, ll> LP;

#define pb push_back
#define rep(i, a, n) for(int i = (a); i < (n); i++)
#define dep(i, a, n) for(int i = (a); i >= (n); i--)
#define mod (ll)1e9+7

__attribute__((constructor))
void initial() {
  cin.tie(0);
  ios::sync_with_stdio(false);
}

signed main() {
  int n;
  int c[501], s[501], f[501];
  cin >> n;
  rep(i, 0, n - 1) {
    cin >> c[i] >> s[i] >> f[i];
  }

  rep(i, 0, n - 1) {
    int t = s[i];
    rep(j, i, n - 1) {
      if(t < s[j]) {
        t = s[j] + c[j];
      }else {
        int ss = s[j];
        while(t > ss) ss += f[j];
        t += c[j] + ss - t;
      }
    }
    cout << t << endl;
  }
  cout << 0 << endl;
}


Measured memory_bytes: 256
import java.io.*;

class Main {
  public static void main(String[] args) throws IOException {
    BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
    String str = br.readLine();
    
    int value = Integer.parseInt(str);
    int digitSum = 0;
    for(int i = 0; i < str.length(); i++) {
      digitSum += (str.charAt(i) - '0');
    }
    
    if(value % digitSum == 0) {
	    System.out.println("Yes");
    }
    else {
	    System.out.println("No");
    }
  }
}


Measured memory_bytes: 21332
/*
    Mbak Rose Dong
*/
#include<bits/stdc++.h>
using namespace std;
struct angka
{
    int byk;
    int cost;
};

struct angka node[100100];
bool desc(struct angka a, struct angka b)
{
    return a.cost < b.cost;
}
int main()
{
    int i,j,x,y,ans,curr=0,n,m,c;
    long long int rose = 0;
    scanf("%d %d",&n,&m);
    for(i=0;i<n;i++)
    {
        int jml,cost;
        scanf("%d %d",&cost,&jml);
        node[i].cost = cost;
        node[i].byk = jml;
    }
    sort(node,node+n,desc);
    for(i=0;i<n;i++)
    {
        while(m > 0 && node[i].byk > 0)
        {
            m--;
            rose += node[i].cost;
            node[i].byk--;
        }
    }
    printf("%lld\n",rose);
    return 0;
}


Measured memory_bytes: 1024
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<cmath>
#include<climits>
#include<cmath>
#include<stdio.h>
#include<fstream>
#include<numeric>

int main(){
	std::string S;
	std::cin >> S;
	int cnt1=0;
	int cnt2=0;
	int i=0;

	for(auto s : S){
		if(i%2 != s-'0') cnt1++;
		if((i+1)%2 != s-'0') cnt2++;
		i++;
	}

	if(cnt1<cnt2) std::cout << cnt1 << std::endl;
	else std::cout << cnt2 << std::endl;

	return 0;
}


Measured memory_bytes: 512
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
using P = pair<ll,ll>;
//マクロ
//forループ関係
//引数は、(ループ内変数,動く範囲)か(ループ内変数,始めの数,終わりの数)、のどちらか
//Dがついてないものはループ変数は1ずつインクリメントされ、Dがついてるものはループ変数は1ずつデクリメントされる
#define FOR(i,a,b) for(ll i=a;i<=(ll)(b);i++)
//xにはvectorなどのコンテナ
#define ALL(x) (x).begin(),(x).end() //sortなどの引数を省略したい
#define SIZE(x) ((ll)(x).size()) //sizeをsize_tからllに直しておく
#define MAX(x) *max_element(ALL(x)) //最大値を求める
#define MIN(x) *min_element(ALL(x)) //最小値を求める
//定数
#define INF 1000000000000 //10^12:極めて大きい値,∞
#define inf 2147483647 //int値の最大値
#define MOD 1000000007 //10^9+7:合同式の法
#define MAXR 100000 //10^5:配列の最大のrange(素数列挙などで使用)
//略記
#define PB push_back //vectorヘの挿入
#define MP make_pair //pairのコンストラクタ
#define F first //pairの一つ目の要素
#define S second //pairの二つ目の要素
#define CST(x) cout<<fixed<<setprecision(x)//小数点以下の桁数指定
template<class T> inline bool chmin(T& a, T b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}
template<class T> inline bool chmax(T& a, T b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}
int gcd(int a, int b) {
    if (b==0) return a;
    else return gcd(b, a%b);
}
int lcm(int a, int b) {
    return a * b / gcd(a, b);
}
int two(int n){
	ll ans=1;
	rep(i,n){
		ans*=2;
	}
	return ans;
}
int main() {
	cin.tie(0);
	cout.tie(0);
	ios::sync_with_stdio(false);
  
  int h,w;

   while(1){
     cin>>h>>w;

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

     rep(i,h){
       rep(j,w){
         if(i==0 || i==h-1){
           cout<<'#';
         }
         
         else if(j==0 || j==w-1)cout<<'#';
         else
         {
            cout<<'.';
         }
         
       }
        cout<<endl;
     }
     cout<<endl;
   }
}


Measured memory_bytes: 3120
import math
N = int(input())


beki = [1]
for i in range(2,32):
    beki = beki + [pow(i,j_prime) for j_prime in range(2,11) if pow(i,j_prime) <= 1000]
beki_uniq = list(set(beki))
beki_small = max([i for i in beki_uniq if i <= N])


print(beki_small)



Measured memory_bytes: 3060
n,k=map(int,input().split())
p=list(map(int, input().split()))

min=p[0]
for i in range(n-1) :
    for j in range(n-1-i) :
        if(p[i]>p[j+i+1]) :
            t=p[i]
            p[i]=p[j+i+1]
            p[j+i+1]=t
    
sum=0
for i in range(k) :
    sum+=p[i]

print(sum)

Measured memory_bytes: 9020
#include <iostream>
#include <vector>
#include <algorithm>
#include <iomanip>
#include <string>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <tuple>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cassert>
#include <cstdint>
#include <numeric>
#include <bitset>
#include <functional>

using namespace std;

using ll =  long long;
using Pll = pair<ll, ll>;
using Pii = pair<int, int>;

constexpr ll MOD = 998244353;
constexpr long double EPS = 1e-10;
constexpr int dyx[4][2] = {
    { 0, 1}, {-1, 0}, {0,-1}, {1, 0}
};

ll modpow(ll a, ll t) {
    ll ret = 1LL;
    while(t){
        if(t & 1LL){
            ret *= a;
            ret %= MOD;
        }
        a *= a;
        a %= MOD;
        t >>= 1;
    }
    return ret;
}

ll modinv(ll a) {
    return modpow(a, MOD-2);
}

int main() {
    ios::sync_with_stdio(false); cin.tie(nullptr);
    int n;
    cin >> n;
    string s;
    cin >> s;

    vector<ll> dp(8, 0LL);
    dp[0] = n;
    ll ans = 1LL;
    for(int i=0;i<3*n;++i) {
        int c = (s[i] == 'R')?0:((s[i] == 'G')?1:2);
        for(int j=6;j>=0;--j) {
            if(j & (1<<c)) continue;
            if(dp[j]) {
                ans *= dp[j];
                ans %= MOD;
                ++dp[j|(1<<c)];
                --dp[j];
                break;
            }
        }
    }
    cout << ans << endl;
}


Measured memory_bytes: 720
import sys
stdin = sys.stdin
 
sys.setrecursionlimit(10**5) 
 
def li(): return map(int, stdin.readline().split())
def li_(): return map(lambda x: int(x)-1, stdin.readline().split())
def lf(): return map(float, stdin.readline().split())
def ls(): return stdin.readline().split()
def ns(): return stdin.readline().rstrip()
def lc(): return list(ns())
def ni(): return int(stdin.readline())
def nf(): return float(stdin.readline())

def cum_2d(field:list):
    row = len(field)
    col = len(field[0])
    
    # 横方向に累積和
    for r in range(row):
        for c in range(col-1):
            field[r][c+1] += field[r][c]
    
    # 縦方向に累積和
    for c in range(col):
        for r in range(row-1):
            field[r+1][c] += field[r][c]
            
    return field
            

n,m,q = li()
train = []
query = []

field = [[0 for _ in range(n+1)] for _ in range(n+1)]

for _ in range(m):
    train.append(tuple(li()))
    
for _ in range(q):
    query.append(tuple(li()))
    
for ts, tt in train:
    field[ts][tt] += 1
    
field = cum_2d(field)
        
for qs,qt in query:
    print(field[qt][qt] - field[qt][qs-1] - field[qs-1][qt] + field[qs-1][qs-1])
    

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

int main(){
  string S;
  cin >> S;
  int lenS = S.size();
  int ans = lenS/2;
  char seg;
  while(true){
    if ((ans == lenS/2) && (lenS%2==1)){
      ans++;
      seg = S[lenS/2];
    } else if ((ans == lenS/2) && (lenS%2==0)){
      seg = S[lenS/2];
      if (seg != S[lenS/2-1]) break;
      ans++;
    } else if ((S[ans] == seg) && (S[lenS-1-ans] == seg)) ans++;
      else break;
    if (ans == lenS) break;
  }
  cout << ans << endl;
}


Measured memory_bytes: 512
#define _GLIBCXX_DEBUG //エラーを出すためのおまじない
#include <bits/stdc++.h>
//#include <cstdlib>  // abs() for integer
#include <cmath>    // abs() for float, and fabs()
using namespace std;
#define coYES cout << "YES" << endl
#define coNO cout << "NO" << endl
#define coYes cout << "Yes" << endl
#define coNo cout << "No" << endl
#define coyes cout << "yes" << endl
#define cono cout << "no" << endl
#define rep(i, n) for (int i = 0; i < (int)(n); i++)

int main() {
  string s;
  cin >> s;
  int size = s.size();
  int sita = -1;
  int ue = -1;
  rep(i, size) {
    if (s.at(i) == 'A') {
      sita = i;
      break;
    }
  }
  reverse(s.begin(), s.end());
  rep(i, size) {
    if (s.at(i) == 'Z') {
      ue = i;
      break;
    }
  }
  cout << size - sita -ue << endl;
}
  
      
      


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

using namespace std;

vector<vector<int>> E;
vector<bool> visited;

void dfs(int i, int d, vector<int> &A){
    if (visited[i])
        return;
    visited[i] = true;
    A[i] = d;
    for (const auto &e: E[i])
        dfs(e, d + 1, A);
}

int main(){
    int n, u, v;
    cin >> n >> u >> v;
    u--; v--;
    E.assign(n, vector<int>());
    for (int i = 0; i < n - 1; i++){
        int a, b;
        cin >> a >> b;
        a--; b--;
        E[a].push_back(b);
        E[b].push_back(a);
    }

    
    vector<int> d_a(n), d_b(n);
    visited.assign(n, false);

    dfs(u, 0, d_a);
    visited.assign(n, false);
    dfs(v, 0, d_b);

    int ans = 0;
    for (int i = 0; i < n; i++){
        if (d_a[i] < d_b[i]){
            ans = max(ans, d_b[i]);
        }
    }

    cout << ans - 1 << endl;
}

Measured memory_bytes: 10368
#include<iostream>
#include<string.h>
#include<string>
#include<stdio.h>
#include<algorithm>
#include<vector>
#include<bitset>
#include<math.h>
#include<stack>
#include<queue>
#include<set>
#include<map>
using namespace std;
typedef long long ll;
typedef long double db;
typedef vector<int> vi;
typedef pair<int,int> pii;
const int N=2000000+100;
const db pi=acos(-1.0);
#define lowbit(x) ((x)&(-x))
#define sqr(x) (x)*(x)
#define rep(i,a,b) for (register int i=a;i<=b;i++)
#define per(i,a,b) for (register int i=a;i>=b;i--)
#define go(u,i) for (register int i=head[u],v=sq[i].to;i;i=sq[i].nxt,v=sq[i].to)
#define fir first
#define sec second
#define mkp make_pair
#define pb push_back
#define maxd 998244353
#define eps 1e-8
inline int read()
{
    int x=0,f=1;char ch=getchar();
    while ((ch<'0') || (ch>'9')) {if (ch=='-') f=-1;ch=getchar();}
    while ((ch>='0') && (ch<='9')) {x=x*10+(ch-'0');ch=getchar();}
    return x*f;
}

inline ll readll()
{
    ll x=0;int f=1;char ch=getchar();
    while ((ch<'0') || (ch>'9')) {if (ch=='-') f=-1;ch=getchar();}
    while ((ch>='0') && (ch<='9')) {x=x*10+(ch-'0');ch=getchar();}
    return x*f;
}

int tot,n,pw[20],ch[N][3],tag[N],pos[N],ans[N],rt,m;
char s[N];

void build(int &id,int dep,int now)
{
    id=(++tot);
    if (dep==n)
    {
        pos[id]=now;return;
    }
    build(ch[id][0],dep+1,now);
    build(ch[id][1],dep+1,now+pw[dep]);
    build(ch[id][2],dep+1,now+pw[dep]*2);
}

void addtag(int id) 
{
    tag[id]^=1;
    swap(ch[id][1],ch[id][2]);
}

void pushdown(int id)
{
    if (tag[id])
    {
        addtag(ch[id][0]);addtag(ch[id][1]);addtag(ch[id][2]);
        tag[id]=0;
    }
}

void add(int id,int dep)
{
    if (dep==n) return;
    pushdown(id);
    int x=ch[id][0],y=ch[id][1],z=ch[id][2];
    ch[id][0]=z;ch[id][1]=x;ch[id][2]=y;
    add(ch[id][0],dep+1);
}

void findans(int id,int dep,int now)
{
    if (dep==n)
    {
        ans[pos[id]]=now;return;
    }
    pushdown(id);
    findans(ch[id][0],dep+1,now);
    findans(ch[id][1],dep+1,now+pw[dep]);
    findans(ch[id][2],dep+1,now+pw[dep]*2);
}

int main()
{
    n=read();
    pw[0]=1;
    rep(i,1,n) pw[i]=pw[i-1]*3;
    build(rt,0,0);
    scanf("%s",s+1);m=strlen(s+1);
    rep(i,1,m)
    {
        if (s[i]=='S') addtag(rt);
        else add(rt,0);
    }
    findans(rt,0,0);
    rep(i,0,pw[n]-1) printf("%d ",ans[i]);
    return 0;
}

Measured memory_bytes: 21968
#include <iostream>
#include <string>
#include <utility>
#include <algorithm>
#include <map>
#include <vector>
#include <cmath>
#include <cstdlib>
#include <queue>

using namespace std;

#define REP(i, n) for(int i = 0;i < n;i++)
#define REPR(i, n) for(int i = n;i >= 0;i--)
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define FORR(i, m, n) for(int i = n;i >= m;i--)
#define REPO(i, n) for(int i = 1;i <= n;i++)
#define ll long long
#define INF 999999999
#define MINF -999999999
#define ALL(n) n.begin(),n.end()
#define MP make_pair
#define F first
#define S second
int dp[1100][1100]; 

int main() {
	int n;
	string a, b;
	cin >> n;
	REP(z, n) {
		cin >> a >> b;
		REP(i, 1100) REP(j, 1100) dp[i][j] = 0;
		REP(i, a.length()) {
			REP(j, b.length()) {
				if (a[i] == b[j]) dp[i + 1][j + 1] = max(dp[i][j] + 1, max(dp[i][j + 1], dp[i + 1][j]));
				else dp[i + 1][j + 1] = max(dp[i][j + 1], dp[i + 1][j]);
			}
		}
		cout << dp[a.length()][b.length()] << endl;
	}
}





Measured memory_bytes: 7908
#include <bits/stdc++.h>
using namespace std;
using ll = long long ;
using P = pair<ll, ll>;
using Vec = vector<ll>;
#define FOR(i, m, n) for(ll (i) = (m); (i) < (n); (i)++)
#define FORN(i, m, n) for(ll (i) = (m); (i) <= (n); (i)++)
#define FORR(i, m, n) for(ll (i) = (m); (i) >= (n); (i)--)
#define rep(i, n) FOR(i, 0, n)
#define repn(i, n) FORN(i, 1, n)
#define repr(i, n) FORR(i, n, 0)
#define repnr(i, n) FORR(i, n, 1)
#define co(n) cout << (n) << endl
#define cosp(n) cout << (n) << ' '
#define setp(n) cout << fixed << setprecision(n);
#define all(s) (s).begin(), (s).end()
#define pb push_back
#define mp make_pair
#define fs first
#define sc second

const ll INF = 1e9+1;
const ll LINF = 1e18+1;
const ll MOD = 1e9+7;
//const ll MOD = 998244353;
const double PI = acos(-1);
const double EPS = 1e-9;

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

	unordered_set<ll> st;
	ll ans = 0;
	rep(i, n){
		ll r;
		cin >> r;
		if(st.find(r) == st.end()){
			ans++;
			st.insert(r);
		}
	}
	co(ans);
	
	return 0;
}


Measured memory_bytes: 256
n = int(input())
a = list(map(int,input().split()))
b = list(map(int,input().split()))
c = list(map(int,input().split()))
csum=0
for i in range(n-1):
  if a[i]+1 == a[i+1]:
    csum = csum + c[a[i]-1]
  else:
    csum = csum

print(sum(b)+csum)

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

using namespace std;

int main() {
  int n, c;
  cin >> n >> c;
  vector<vector<int>> d(c, vector<int>(c));
  for (int i = 0; i < c; ++i) {
    for (int j = 0; j < c; ++j) {
      cin >> d[i][j];
    }
  }
  vector<vector<int>> v(3);
  for (int i = 0; i < n; ++i) {
    for (int j = 0; j < n; ++j) {
      int cc;
      cin >> cc;
      cc--;
      v[(i + j) % 3].push_back(cc);
    }
  }
  vector<vector<int>> a(3, vector<int>(c, 0));
  for (int i = 0; i < 3; ++i) {
    for (int j = 0; j < c; ++j) {
      for (auto x : v[i]) {
        a[i][j] += d[x][j];
      }
    }
  }
  int ans = 1e9;
  for (int i = 0; i < c; ++i) {
    for (int j = i + 1; j < c; ++j) {
      for (int k = j + 1; k < c; ++k) {
        ans =
            min({ans, a[0][i] + a[1][j] + a[2][k], a[0][i] + a[1][k] + a[2][j],
                 a[0][j] + a[1][i] + a[2][k], a[0][j] + a[1][k] + a[2][i],
                 a[0][k] + a[1][i] + a[2][j], a[0][k] + a[1][j] + a[2][i]});
      }
    }
  }
  cout << ans << endl;
}

Measured memory_bytes: 1524
#include <stdio.h>
#include <string.h>

int main(){

	int M,N;
	char s[110];
	scanf("%s",&s);
	
	int len = strlen(s);
	int i;
	char s1[100],s2[100];
	
	for(i=0;i<(len-1)/2;i++){
		s1[i]=s[i];
	}
	s1[i+1]='\0';

	for(i=(len+3)/2-1;i<len;i++){
		s2[i-((len+3)/2-1)]=s[i];
	}
	s2[i+1]='\0';
	
	for(i=0;i<(len-1)/2;i++){
		
		if(s1[i]!=s2[i]){
			printf("No\n");
			return 0;
		}
		
	}
	printf("Yes\n");


 return 0;
 }

Measured memory_bytes: 128
import java.util.*;

class Main {

	public static void main(String[] args) {
		Scanner in = new Scanner(System.in);
		int x,i=0;
		while(true){
			i++;
			x = in.nextInt();
			if(x == 0) break;
			System.out.println("Case " + i + ": " + x);
		}
	}
}

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

#define FOR(i, j, k) for (int i = j; i < k; i++)
#define REP(i, j) FOR(i, 0, j)
#define fst first
#define snd second
#define pb push_back
#define eb emplace_back
#define all(obj) (obj).begin(), (obj).end()
#define rall(obj) (obj).rbegin(), (obj).rend()
typedef long long int ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<vi> vvi;

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

template <typename T> istream &operator>>(istream &is, vector<T> &vec) {
  for (T &x : vec)
    is >> x;
  return is;
}

int main() {

  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.precision(10);

  cout << fixed;

  int r, d, x;
  cin >> r >> d >> x;

  REP(i, 10) {
    x = r * x - d;
    cout << x << endl;
  }

  return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
#include<ctype.h>
int main(){
  char c;
  char h[26]={'a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z'};
  int ans[26]={0};
  int i;
  while(scanf("%c",&c)!=EOF){
    c = tolower(c);
    for(i=0;i<26;i++){
      if(h[i]==c){
	ans[i]++;
	break;
      }
    }
  }
  for(i=0;i<26;i++){
    printf("%c : %d\n",h[i],ans[i]);
  }
  return 0;
}

Measured memory_bytes: 972
#include<bits/stdc++.h>
using namespace std;
#define INF (1LL<<60)
#define DEKAI 1000000007
#define lp(i,n) for(int i=0;i<n;i++)
#define int long long

#define N 100


signed main(){
	int n,x;
	cin>>n>>x;
	int a[10000];
	lp(i,n){
		cin>>a[i];
	}
	int ans=1;
	int now=0;
	lp(i,n){
		now+=a[i];
		if(now>x)break;
		ans++;
	}
	cout<<ans<<endl;
	return 0;

}

Measured memory_bytes: 256
package main

import (
	"bufio"
	"fmt"
	"log"
	"math"
	"os"
	"strconv"
)

var sc = bufio.NewScanner(os.Stdin)
var buff []byte

func nextString() string {
	sc.Scan()
	return sc.Text()
}

func nextFloat64() float64 {
	sc.Scan()
	f, err := strconv.ParseFloat(sc.Text(), 64)
	if err != nil {
		panic(err)
	}
	return f
}

func nextInt() int {
	sc.Scan()
	i, err := strconv.Atoi(sc.Text())
	if err != nil {
		panic(err)
	}
	return i
}

func nextInts(n int) (r []int) {
	r = make([]int, n)
	for i := 0; i < n; i++ {
		r[i] = nextInt()
	}
	return r
}

var dy = []int{0, 1, 0, -1}
var dx = []int{1, 0, -1, 0}
var MAX = math.MaxInt64

func maxInt(a ...int) int {
	r := a[0]
	for i := 0; i < len(a); i++ {
		if r < a[i] {
			r = a[i]
		}
	}
	return r
}
func minInt(a ...int) int {
	r := a[0]
	for i := 0; i < len(a); i++ {
		if r > a[i] {
			r = a[i]
		}
	}
	return r
}
func sum(a []int) (r int) {
	for i := range a {
		r += a[i]
	}
	return r
}
func absInt(a int) int {
	if a < 0 {
		return -a
	}
	return a
}

type Pair struct {
	a, b int
}

type Pairs []Pair

func (p Pairs) Len() int {
	return len(p)
}
func (p Pairs) Swap(i, j int) {
	p[i], p[j] = p[j], p[i]
}

func (p Pairs) Less(i, j int) bool {
	if p[i].a == p[j].a {
		return p[i].b < p[j].b
	}
	return p[i].a < p[j].a
}

func init() {
	sc.Split(bufio.ScanWords)
	sc.Buffer(buff, bufio.MaxScanTokenSize*1024)
	log.SetFlags(log.Lshortfile)
}

func main() {
	x := nextInt()
	if x < 600 {
		fmt.Println("8")
		return
	}
	if x < 800 {
		fmt.Println("7")
		return
	}
	if x < 1000 {
		fmt.Println("6")
		return
	}
	if x < 1200 {
		fmt.Println("5")
		return
	}
	if x < 1400 {
		fmt.Println("4")
		return
	}
	if x < 1600 {
		fmt.Println("3")
		return
	}
	if x < 1800 {
		fmt.Println("2")
		return
	}
	if x < 2000 {
		fmt.Println("1")
		return
	}
}


Measured memory_bytes: 1772
def main():
    n,m=map(int,input().split())

    L=2**n

    cost=[0]+[10**8 for i in range(L-1)]

    for _ in range(m):
        a,b = map(int,input().split())

        c = sum(map(lambda x:2**(int(x)-1), input().split()))
        for i in range(L):
            q = c|i
            cost[q] = min(cost[q], cost[i]+a)
    print(cost[L-1] if cost[L-1]<10**8 else -1)

if __name__ == '__main__':
    main()


Measured memory_bytes: 3188
#include <vector>
#include <iostream>
#include <utility>
#include <algorithm>
#include <string>
#include <deque>
#include <queue>
#include <tuple>
#include <queue>
#include <functional>
#include <cmath>
#include <iomanip>
#include <map>
#include <set>
#include <numeric>
#include <unordered_map>
#include <unordered_set>
#include <complex>
#include <iterator>
#include <array>
#include <memory>
#include <stack>
#include <cstring>
#define vi vector<int>
#define vvi vector<vector<int> >
#define ll long long int
#define vl vector<ll>
#define vvl vector<vector<ll>>
#define vb vector<bool>
#define vc vector<char>
#define vs vector<string>
#define ld long double
#define INF 1e9
#define EPS 0.0000000001
#define rep(i,n) for(int i=0;i<n;i++)
#define loop(i,s,n) for(int i=s;i<n;i++)
#define all(in) in.begin(), in.end()
template<class T, class S> void cmin(T &a, const S &b) { if (a > b)a = b; }
template<class T, class S> void cmax(T &a, const S &b) { if (a < b)a = b; }
#define MAX 9999999
using namespace std;
typedef pair<int, int> pii;
typedef pair<double,double>pdd;
typedef pair<ll,ll>pll;
int main(){
    int n;
    char hoge[]={"abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"};
    int hoge_size=(int)strlen(hoge);
    map<char,int>mp;
    rep(i,hoge_size){
        mp[hoge[i]]=i;
    }
    while(cin>>n,n){
        vi key(n); rep(i,n)cin>>key[i];
        string s; cin>>s;
        string ans;
        int cnt=0;
        for(int i=0; i<s.size();i++){
            int gotiusa=mp[s[i]]-key[cnt];
            if(gotiusa<0)gotiusa+=52;
            cout<<hoge[gotiusa];
            cnt++;
            if(cnt==key.size())cnt=0;
        }
        cout<<endl;
    }
}

Measured memory_bytes: 3100
let rec f maxN others lst =
  match lst with
  | [] -> (maxN, others)
  | x :: xs ->
    if x > maxN then f x (maxN :: others) xs
    else f maxN (x :: others) xs
let rec sum lst = match lst with
  | [] -> 0
  | x :: xs -> x + sum xs
let () = Scanf.scanf "%d\n"
    (fun n -> Array.init n (fun _ -> Scanf.scanf " %d" (fun x -> x)))
  |> Array.to_list
  |> f 0 []
  |> (fun (maxN, otherlst) -> if maxN < sum otherlst then "Yes" else "No")
  |> print_string

Measured memory_bytes: 384
import sys
S = input()
SL = list(S)
N = len(S)

if S[0] != "A":
    print("WA")
    sys.exit()

if S[2:-1].count("C") != 1:
    print("WA")
    sys.exit()

SL[0] = "a"
for i in range(2,N-1):
    if SL[i] == "C":
        SL[i] = "c"
        break
S2 = "".join(SL)
if not S2.islower():
    print("WA")
    sys.exit()
print("AC")


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

int main() {
  int N;

  cin >> N;

  vector<int> input(N);

  rep(i,N){
    cin >> input.at(i);
  }

  sort(input.begin(), input.end());
  int count=0;

  for(int i = 0; i< N;i++){
    for(int j = i+1; j< N-1;j++){
      for(int k = j+1; k<N;k++){   
        if(((input.at(j) + input.at(i)) > input.at(k)) && input.at(j) != input.at(k) && input.at(i) != input.at(k) && input.at(i) != input.at(j)){
          count++;
        }
      }
    }
  }
  cout << count << endl;
}

Measured memory_bytes: 3516
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using vi = vector<int>;
using vvi = vector<vector<int>>;
using vl = vector<ll>;
using vvl = vector<vector<ll>>;
#define debug(x) cerr<<#x<<": "<<x<<endl;
#define MOD 1000000007ULL;
#define rep(i,n) for(int i=0;i<n;i++)


int main() {
	int A,B;
  	cin>>A>>B;
  
  	if(A>9 ||B>9){
     	cout<<-1<<endl;
      	return 0;
    }
 	else{
     	cout<<A*B<<endl;
      	return 0;
    }
  
  	
  	
  
  
}

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

int main() {
    int N;
    cin >> N;
    vector<pair<int,int>> place(N);
    rep(i,0,N) {
        int x, y;
        cin >> x >> y;
        place[i] = make_pair(x,y);
    }

    double sum_len = 0;
    int num_route = 0;
    vector<int> route(N);
    rep(i,0,N) route[i] = i;
    do {
        rep(i,0,N-1) sum_len += sqrt(pow(place[route[i]].first-place[route[i+1]].first,2)+pow(place[route[i]].second-place[route[i+1]].second,2));
        num_route++;
    } while (next_permutation(all(route)));
    cout << fixed << setprecision(20);
    cout << sum_len / num_route << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <iomanip>
#include <math.h>

using namespace std;

int main(){
	
	
	double a,b,c,d;
	cin >> a >>  b >> c >> d;
	//cout << d <<a << b <<c;
	if (b>=c){
		cout << "Yes" <<endl;
	}
	else if (d>=a){
		cout << "No"<<endl;
	}
	else{
		if (ceil(c/b)<=ceil(a/d)){ //9 11 10 10
		//cout << ceil(c/b);
		cout << "Yes"<<endl;}
		else
		cout <<"No"<<endl;
	}
	
	
	
	return 0;
	
	
	
}

Measured memory_bytes: 3708
#include <iostream>
using namespace std;
 
int main() {
	unsigned long long a,b;cin>>a>>b;
	unsigned long long cnt=1;
	while(1){
		if(a*2<=b){
			cnt++;
			a*=2;
		}else break;
	}
	cout<<cnt<<endl;
	return 0;
}

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

using std::cin;
using std::cout;
using std::endl;

using std::string;
using std::pair;

using std::vector;
using std::sort;
using std::lower_bound;
using std::upper_bound;
using std::find_if;
using std::copy;
using std::copy_if;

int main(){
    int N;
    cin >> N;
    int min=33;
    for(int i=0;i<N;i++){
        int a;
        cin >> a;
        int count=0;
        while(a%2==0){
            a/=2;
            count++;
        }
        min=std::min(count,min);
    }

    cout << min << endl;

    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <string>
#include <utility>
#include <algorithm>
#include <map>
#include <cstdio>
#include <cassert>
using namespace std;

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

	int a, b, c, x, y;
	cin >> a >> b >> c >> x >> y;
	
	int ans = a * x + b * y;
	int tmp = c * x * 2;
	if (y > x) tmp += min(b * (y-x), 2 * c * (y-x));
	ans = min(ans, tmp);
	
	tmp = c * y * 2;
	if (x > y) tmp += min(a * (x-y), 2 * c * (x-y));
	ans = min(ans, tmp);
	cout << ans << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
#include <map>
#include <cmath>
#include <iomanip>
#include <vector>
#include <queue>
#include <functional>
#include <random>
#include <ctime>

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

int main() {
    int input, answer;
    cin >> input;
    answer = input;
    vector<int> six, nine;
    int b = 6;
    while (b < 100000) {
        six.push_back(b);
        b *= 6;
    }
    b = 9;
    while (b < 100000) {
        nine.push_back(b);
        b *= 9;
    }
    sort(six.begin(), six.end(), greater<int>());
    sort(nine.begin(), nine.end(), greater<int>());
    int useNine = input / 9;
    int useSix = (input - useNine * 9) / 6;
    while (useNine >= 0) {
        int thisAnswer = 0;
        int nineSum = useNine * 9;
        for (int i : nine) {
            int quotient = nineSum / i;
            thisAnswer += quotient;
            nineSum -= quotient * i;
        }
        int sixSum = useSix * 6;
        for (int i : six) {
            int quotient = sixSum / i;
            thisAnswer += quotient;
            sixSum -= quotient * i;
        }
//        cout << useNine;
//        cout << "\r\n";
//        cout << useSix;
//        cout << "\r\n";
//        cout << input - useSix * 6 - useNine * 9;
//        cout << "\r\n";
//        cout << "\r\n";
        thisAnswer += input - useSix * 6 - useNine * 9;
        useNine--;
        useSix = (input - useNine * 9) / 6;
        if (answer > thisAnswer) {
            answer = thisAnswer;
        }
    }
    cout << answer;
    return 0;
}



Measured memory_bytes: 256
n=int(input())
string_list=[input() for i in range(n)]
import collections
import numpy as np
c = collections.Counter(string_list)
d=c.most_common()
x=int(d[0][1])
z=[]
for i in range(len(d)):
  y=int(d[i][1])
  if x==y:
    z.append(str(d[i][0]))
    
z.sort()
for i in range(len(z)):
  print(z[i])

Measured memory_bytes: 56360
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define MAXN 500100
#define mod 1000000007
ll fac[MAXN], inv[MAXN];
ll f(ll n, ll r){
    if(n < r ||  n < 0 || r < 0) return 0;
    else{
        ll ans = fac[n];
        ans = (ans * inv[r])%mod;
        ans = (ans * inv[n-r])%mod;
        return ans;
    }
}
ll modexp(ll a, ll b, ll m){
    if (b==0)
        return 1;
    ll temp = modexp(a,b/2,m);
    temp = (temp*temp)%m;
    if (b&1)
        return (temp*(a%m))%m;
    return temp;
}
void solve(){
    fac[0] = inv[0] = 1;
    for(ll i = 1; i < MAXN; i++){
        fac[i] = (fac[i-1] * i)%mod;
        inv[i] = (inv[i-1] * modexp(i, mod-2, mod))%mod;
    }
    ll n, m;
    cin>>n>>m;  
    ll ans = 0;
    ll si = 1;
    for(ll i = 1; i <= n; i++){
        ll val = (f(n, i) * f(m, i))%mod;
        val = (val * f(m-i, n-i))%mod;
        val = (val * f(m-i, n-i))%mod;
        val = (val * fac[i])%mod;
        val = (val * fac[n-i])%mod;
        val = (val * fac[n-i])%mod;
        val = val * si;
        si = si * (-1);
        ans = (ans  + val + mod)%mod;
        while(ans < 0) ans += mod;
    }
    ll x = (f(m, n) * fac[n])%mod;
    x = (x * x)%mod;
    ans = (x - ans + mod)%mod;
    cout<<ans<<endl;
}
int main(){
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    solve();
}


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

typedef long long   signed int LL;
typedef long long unsigned int LU;

#define incID(i, l, r) for(int i = (l)    ; i <  (r); i++)
#define incII(i, l, r) for(int i = (l)    ; i <= (r); i++)
#define decID(i, l, r) for(int i = (r) - 1; i >= (l); i--)
#define decII(i, l, r) for(int i = (r)    ; i >= (l); i--)
#define  inc(i, n) incID(i, 0, n)
#define inc1(i, n) incII(i, 1, n)
#define  dec(i, n) decID(i, 0, n)
#define dec1(i, n) decII(i, 1, n)

#define inII(v, l, r) ((l) <= (v) && (v) <= (r))
#define inID(v, l, r) ((l) <= (v) && (v) <  (r))

#define PB push_back
#define EB emplace_back
#define MP make_pair
#define FI first
#define SE second
#define PQ priority_queue

#define  ALL(v)  v.begin(),  v.end()
#define RALL(v) v.rbegin(), v.rend()
#define  FOR(it, v) for(auto it =  v.begin(); it !=  v.end(); ++it)
#define RFOR(it, v) for(auto it = v.rbegin(); it != v.rend(); ++it)

template<typename T> bool   setmin(T & a, T b) { if(b <  a) { a = b; return true; } else { return false; } }
template<typename T> bool   setmax(T & a, T b) { if(b >  a) { a = b; return true; } else { return false; } }
template<typename T> bool setmineq(T & a, T b) { if(b <= a) { a = b; return true; } else { return false; } }
template<typename T> bool setmaxeq(T & a, T b) { if(b >= a) { a = b; return true; } else { return false; } }
template<typename T> T gcd(T a, T b) { return (b == 0 ? a : gcd(b, a % b)); }
template<typename T> T lcm(T a, T b) { return a / gcd(a, b) * b; }

// ---- ----

int n, h[101];

int main() {
	cin >> n;
	inc(i, n) { cin >> h[i]; }
	n++;
	
	int ans = 0;
	inc1(j, 100) {
		int c = 0;
		inc(i, n) {
			if(h[i] >= j) { c = 1; } else { ans += c; c = 0; }
		}
	}
	
	cout << ans << endl;
	
	return 0;
}


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

if __name__ == '__main__':
    n, m = map(int, raw_input().split())
    cities = []
    for i in range(0, m):
        p, y = map(int, raw_input().split())
        cities.append((y, p, i))
    cities.sort()

    city_codes = [0] * (n + 1)
    postal_codes = [""] * m
    for j in range(0, m):
        y, p, i = cities[j]
        city_codes[p] += 1
        postal_codes[i] = "%06d%06d"%(p, city_codes[p])
    for postal_code in postal_codes:
        print postal_code
    

Measured memory_bytes: 30076
import itertools
n =int(input())
p =list(map(str ,input().split()))
q =list(map(str ,input().split()))
l =[]
for i in range(1 ,n+1):
    l.append(str(i))
cnt =1
for v in itertools.permutations(l,n):
    if p == list(v):
        a =cnt
    if q == list(v):
        b =cnt
    cnt +=1
print(abs(a-b))

Measured memory_bytes: 3064
#include<bits/stdc++.h>
using namespace std;
typedef int64_t ll;
typedef long double ld;
const ll MOD=1000000007;
#define rep(i,n) for(ll i=0;i<(ll)(n);i++)
long long gcd(long long a,long long b){
    ll gcdmax=max(a,b);
    ll gcdmin=min(a,b);
    while(true){
        if(gcdmax%gcdmin==0)break;
        else gcdmax%=gcdmin;
        swap(gcdmin,gcdmax);
    }
    return gcdmin;
}
ll powerup(ll N,ll P,ll M){
    if(P==0)return 1;
    else if(P%2==0){
        ll t=powerup(N,P/2,M);
        return t*t%M;
    }
    else return N*powerup(N,P-1,M)%M;
}
vector<ll> find_divisor(ll N){
  ll k=1;
  while(k*k<=N){
    k++;
  }
  vector<ll> A(1);
  rep(i,k){
    if(i==1)A.at(0)=1;
    else if(i>=2){
      if(N%i==0)A.push_back(i);
    }
  }
  ll t=0;
  t=A.size();
  rep(i,t){
    if(A.at(t-i-1)*A.at(t-i-1)!=N)A.push_back(N/A.at(t-1-i));
  }
  return A;
}

bool isOK(ll index, ll key,vector<ll> A){
    if(A.at(index)>=key) return true;
    else return false;
}

ll binary_search(ll key,vector<ll> A){
    ll left=-1;
    ll right=A.size();
    while(right-left>1){
        int mid=left+(right-left)/2;
        if(isOK(mid,key,A)) right=mid;
        else left=mid;
    }
    return right;
}
bool isOKA(ll index, ll key,vector<ll> A){
    if(A.at(index)>key) return true;
    else return false;
}

ll binary_searchA(ll key,vector<ll> A){
    ll left=-1;
    ll right=A.size();
    while(right-left>1){
        int mid=left+(right-left)/2;
        if(isOKA(mid,key,A)) right=mid;
        else left=mid;
    }
    return right;
}
int main()
{
    ll N;
    cin>>N;
    vector<ll> A(N);
    vector<ll> B(N);
    ll H;
    rep(i,N){
        cin>>H;
        A.at(i)=H+i;
        B.at(i)=i-H;
    }
    vector<ll> C(N);
    vector<ll> D(N);
    rep(i,N){
        if(A.at(i)<N)C.at(A.at(i))++;
        if(B.at(i)>0)D.at(B.at(i))++;
    }
    ll ans=0;
    rep(i,N){
        ans+=C.at(i)*D.at(i);
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 9592
@d,@g = gets.chomp.split.map(&:to_i)
@ps,@cs = @d.times.map{gets.chomp.split.map(&:to_i)}.transpose
@ans = []
def dfs(i,sum,count,b)
  if i == @d
    if sum < @g
      index = b.rindex("0")
      n = (@g - sum)/((index + 1)*100)
      add_count = (@g - sum) % ((index + 1)*100) == 0 ? n : n + 1
      if add_count <= @ps[index]
        @ans << count + add_count
      end
    else 
      @ans << count 
    end
  else
    dfs(i+1,sum + @ps[i]*(i+1)*100 + @cs[i] ,count + @ps[i],b+"1")
    dfs(i+1,sum,count,b+"0")
  end
end

dfs(0,0,0,"")
puts @ans.min

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

using namespace std;
using ll = long long;
int N;
vector<ll> A;
int main(){
    cin >> N;
    cin.ignore();
    for(int i = 0; i < N; i++){
        ll tmp;
        cin >> tmp;
        A.push_back(tmp);
    }
    cin.ignore();

    ll max = A[0];
    ll sum = 0;
    for(int i = 1; i < N; i++){
        if(A[i] < max){
            sum += max - A[i];
        } else {
            max = A[i];
        }
    }
    cout << sum << endl;
    
    return 0;
}

Measured memory_bytes: 5348
N,M=map(int, input().split())
yoi = []
for i in range(N):
  yoi.append(True)
H=list(map(int, input().split()))
for i in range(M):
  A,B=map(int, input().split())
  if H[A-1]<=H[B-1]: yoi[A-1]=False
  if H[B-1]<=H[A-1]: yoi[B-1]=False 
print(len([1 for x in yoi if x==True]))

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

int main(){
    ll n,k;
    cin >> n >> k;
    if(n == 0){
        cout << 0 << endl;
        return 0;
    }
    else{
        ll s = n % k;
        ll ans = min(s,abs(s-k));
        cout << ans << 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 all(x)    (x).begin(),(x).end()
typedef long long ll;
const int MOD = (int)1e9 + 7;

int main(){
  string s;
  cin >> s;
  rep(i,s.size()) cout << (s[i] == '1' ? '9' : '1');
  cout << endl;
}



Measured memory_bytes: 256
### constants

MAX_INT = 1 << 30

### subroutines

def calc_del_mc(n, tbls)
  sts = [[0, 0]]
  to = {}
  prvs = (n - 1).times.map{{}}

  for i in (0...(n - 1))
    tbli = tbls[i]
    to = {}

    for st in sts
      ti, ci = st

      for tbl in tbli
        xij, yij, cij, tfij = tbl

        if tfij && xij >= ti
          ci0 = ci + cij
          if to[yij].nil?
            to[yij] = [yij, ci0]
            prvs[i][yij] = ti
          elsif to[yij][1] > ci0
            to[yij][1] = ci0
            prvs[i][yij] = ti
          end
        end
      end

      sts = to.values.sort
    end
  end

  min_cost = MAX_INT
  min_yi = nil

  for st in sts
    ti, ci = st
    if min_cost >ci
      min_cost = ci
      min_yi = ti
    end
  end

  return nil if min_yi.nil?

  prv_yi = min_yi
  (n - 2).downto(0) do |i|
    for tbl in tbls[i]
      tbl[3] = false if tbl[1] == prv_yi
    end
    prv_yi = prvs[i][prv_yi]
  end

  min_cost
end

### main

loop do
  n = gets.to_i
  break if n == 0

  tbls = []
  (n - 1).times do
    mi = gets.to_i
    tbli = []
    mi.times do
      xij, yij, cij = gets.split.map(&:to_i)
      tbli << [xij, yij, cij, true]
    end
    tbls << tbli.sort
  end
  #p tbls

  g = gets.to_i

  csum = 0
  glen = 0

  while glen < g
    c = calc_del_mc(n, tbls)
    break if c.nil?

    csum += c
    glen += 1
  end

  puts [glen, csum].join(' ')
end

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

int main(){
    int N,M;
    cin >> N >> M;
    vector<int> L(M),R(M);

    int left = 1;
    int right = N;

    for(int i = 0;i < M;++i){
        int a,b;
        cin >> a >> b;
        left = max(left,a);
        right = min(right,b);
    }

    cout << max(right -left +1,0) << endl;
    
    

}

Measured memory_bytes: 1024