akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include<stdio.h>
using namespace std;

int main(){
   int r,c;
   cin >> r >> c;
   int a[r+1][c+1];
    for (int i=0 ;i< r+1; i++){
       for (int j=0; j<c+1; j++){
           a[i][j]=0;
       }
   }
   for (int i=0 ;i< r; i++){
       for (int j=0; j<c; j++){
           cin >> a[i][j];
           a[r][j]+=a[i][j];
           a[i][c]+=a[i][j];
           a[r][c]+=a[i][j];
       }
   }

    for(int i=0; i<=r; i++){
        for(int j=0; j<c; j++){
            cout << a[i][j] << " ";
        }
        cout << a[i][c] << endl;
    }
}





Measured memory_bytes: 3096
import math

n = int(input())
s  = [list(map(int,input().split())) for _ in range(n)]

x = math.factorial(n)
y = (n-1)*(n)/2
z = x*(n-1)/y

sum_dis = 0
for i in range(n-1):
    xi = s[i][0]
    yi = s[i][1]
    for j in range(i+1,n):    
        xj = s[j][0]
        yj = s[j][1]
        dis = math.sqrt(math.pow((xi-xj),2) + math.pow((yi - yj),2))
        sum_dis += z*dis

print(sum_dis/x)



Measured memory_bytes: 3316
def trace(a,n) :
    li=[]
    for i in xrange(n):
        li.append(str(a[i]))
    print(" ".join(li))
    
def bubblesort(a,n):
    flag=1
    ct=0
    while flag:
        flag=0
        if n==0:
            break
        else :
            for i in xrange(n-1,0,-1):
                if a[i]<a[i-1]:
                    keep=a[i-1]
                    a[i-1]=a[i]
                    a[i]=keep
                    ct+=1
                    flag=1
    return ct
n=input()
a=map(int,raw_input().split())
ct=bubblesort(a,n)
trace(a,n)
print(ct)
                

Measured memory_bytes: 6476
from collections import deque
N,Q = map(int,input().split())
ab = [[] for i in range(N)]
for i in range(N-1):
    a,b = list(map(int,input().split()))
    a -= 1
    b -= 1
    ab[a].append(b)
    ab[b].append(a)
px = [0 for i in range(N)]
for i in range(Q):
    p,x = list(map(int,input().split()))
    px[p-1] += x
que = deque()
alr = set()
alr.add(0)
que.append(0)
while que:
    q = que.popleft()
    sumq = px[q]
    for i in ab[q]:
        if i in alr:
            continue
        else:
            que.append(i)
            alr.add(i)
            px[i] += sumq
print(*px)

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

int MAX_DP = 18000;
int CENTER = 9000;
bool dp[3002][18000];
bool dp2[3002][18000];

int main()
{
	string S;
	cin >> S;
	int count = 0;
	for (auto c : S) {
		if (c == '1') {
			count += 1;
		}
	}
	cout << count << endl;

	return 0;
}

Measured memory_bytes: 256
#include <cmath>
#include <iostream>
#define int long long

using namespace std;

int n,b,a;
int tot;

signed main(){
    cin>>n;
    for(int i=1;i<=n;i++){
        cin>>a>>b;
        tot+=(b-a+1);
    }
    cout<<tot;
    return 0;
}

//Flamire txdy

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define fi first
#define se second
#define all(x) (x).begin(), (x).end()
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define repp(i, a, b) for (int i = a; i <= (b); ++i)
#define repr(i, a, b) for (int i = a; i >= (b); --i)
typedef long long ll;
const int INF = 1001001001;
const ll LINF = 1001001001001001001ll;
const int MOD = 1e9 + 7;

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 main() {
  string S;
  cin >> S;

  int zeros = 0;
  int ones = 0;

  rep(i, S.size()) {
    if (S[i] == '0')
      zeros++;
    else
      ones++;
  }
  int ans = min(zeros, ones) * 2;
  cout << ans << endl;
}

Measured memory_bytes: 512
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <string.h>
#include <queue>
#include <algorithm>
#include<iostream>
#include<vector>
#include<map>
#include<string>
#include <iomanip>
#include<deque>
#include<stack>
#include<set>
#include <numeric>

using namespace std;
typedef unsigned int uint;
typedef long long ll;
//typedef pair<int, int> P;
const int INF = 111111111;
const ll LLINF = 1e17 + 1;
const int DX[9] = { 0,0,1,-1, 1, 1, -1, -1, 0 }; // 4;４近傍
const int DY[9] = { 1,-1,0,0, 1, -1, 1, -1, 0 }; // 8:８近傍 9:(0,0)を含む
const int DIV = 1000000007; //10^9 + 7
const double PI = 3.14159265358979323846264338327950288;




int main() {

	//==================================
	cin.tie(nullptr);
	ios_base::sync_with_stdio(false);
	cout << fixed << setprecision(15);
	//==================================

	vector<vector<int>> C(3);
	for (int i = 0; i < 3; i++) {
		for (int j = 0; j < 3; j++) {
			int temp;
			cin >> temp;
			C[i].emplace_back(temp);
			}
	}

	for (int i = 0; i < 2; i++) {
		for (int j = 0; j < 2; j++) {
			if (C[i][j] - C[i][j + 1] != C[i + 1][j] - C[i + 1][j + 1]) {
				cout << "No";
				return 0;
			}
			if (C[i][j] - C[i + 1][j] != C[i][j + 1] - C[i + 1][j + 1]) {
				cout << "No";
				return 0;
			}

		}
	}

	cout << "Yes";

}	


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

using namespace std;

int main(){
    int X, A, B; cin >> X >> A >> B;
         if (A   >= B) cout << "delicious" << endl;
    else if (B-A <= X) cout << "safe"      << endl;
    else               cout << "dangerous" << endl;
    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<string>

using namespace std;
#define REP(i, limit) for(int i=0; i< limit; ++i)
#define LINT long long

const LINT MOD = 1000000007;

int main(){
  int N;
  string S1, S2;
  cin >> N;
  cin >> S1;
  cin >> S2;
  LINT ans;
  bool tate;

  int i = 0;
  if(S1[0] == S2[0]){
    ans = 3;
    ++i;
    tate = true;
  }
  else{
    ans = 6;
    i = i+2;
    tate = false;
  }

  while(i < N){

    if(S1[i] == S2[i]){
      if(tate) ans = (ans * 2) % MOD;
      tate = true;
      ++i;
    }
    else{
      if(tate) ans = (ans*2) % MOD;
      else ans = (ans*3) % MOD;
      tate = false;
       i = i+2;
    }
  }

  cout << ans;


  return 0;
}


Measured memory_bytes: 256
#include<iostream>

using namespace std;

int main(){
  int n;
  cin >> n;
  string s;
  cin >> s;
  int acount = 0;
  int bcount = 0;
  int a[300000] = {0};
  int b[300000] = {0};
  for(int i = 0; i < n ; i++){
    if(s[i] == 'W'){
      a[i] = acount+1;
      acount++;
    }
    else a[i] = acount;
    if(s[n-i-1] == 'E'){
      b[n-i-1] = bcount+1;
      bcount++;
    }
    else b[n-i-1] = bcount;
  }
  int mini = 300000;
  for(int i = 0; i < n ; i++){
    if(mini > a[i]+b[i]) mini = a[i]+b[i];
//    cout << a[i]+b[i];
  }
//  cout << endl;
  cout << mini-1 << endl;
}


Measured memory_bytes: 3076
import scala.io.StdIn._
object Main extends App{
  val sc = new java.util.Scanner(System.in)
  val a,b,c = sc.nextInt
  if(a<b){
    if(b<c){
      print(c*10+a+b)  
    }
    else{
      print(b*10+a+c)  
    }
  }
  else{
    if(a<c){
      print(c*10+a+b)  
    }
    else{
      print(a*10+b+c)  
    }
  }
}

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

const int H=60*60;
const int M=60;
const int S =1;

int train[24*H+1];
int unit[3]={H,M,S};

int getTime(string s){
  string tmp;
  int res=0;
  for(int i=0;i<3;i++){
    tmp=s.substr(3*i,2);
    int val=atoi(tmp.c_str());
    res+=unit[i]*val;
  }
  return res;
}

int main(){
  int n;
  while(cin>>n,n){
    memset(train,0,sizeof(train));
    for(int i=0;i<n;i++){
      string start,arrival;
      int st=0,at=0;
      cin>>start>> arrival;
      st=getTime(start);
      at=getTime(arrival);
      for(int i=st;i<at;i++)train[i]++;
    }
    int ans=0;
    for(int i=0;i<=24*H;i++){
      ans=max(ans,train[i]);
      //cout << train[i] << " ";
    }
    cout << ans << endl;
  }
  return 0;
}

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

#define INF 1000010000
#define nl '\n'
#define pb push_back
#define ppb pop_back
#define mp make_pair
#define fi first
#define se second
#define pii pair<int,int>
#define pdd pair<double,double>
#define all(c) (c).begin(), (c).end()
#define SORT(c) sort(all(c))
#define sz(c) (c).size()
#define rep(i,n) for( int i = 0; i < n; ++i )
#define repi(i,n) for( int i = 1 ; i <= n; ++i )
#define repn(i,n) for( int i = n - 1 ; i >= 0 ; --i )
#define repf(j,i,n) for( int j = i ; j < n ; ++j )
#define die(s) {std::cout << s << nl;}
#define dier(s) {std::cout << s; return 0;}
#define vi vector<int>
typedef long long ll;
#define MAXN 202020
using namespace std;

vi g[MAXN];

vi used(MAXN , 0);

void dfs(int cur){
	used[cur] = 1;
	for(int to : g[cur]){
		if(!used[to]){
			dfs(to);
		}
	}
}

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

	int n , m;
	cin >> n >> m;

	rep(i , m){
		int u , v;
		cin >> u >> v;
		if(u > v)swap(u , v);
		if(u == 1 || v == n){
			g[v].pb(u);
			g[u].pb(v);
		}
	}
	
	dfs(1);
	cout << (used[n] ? "POSSIBLE" : "IMPOSSIBLE");
	return 0;
}

Measured memory_bytes: 12784
#include <bits/stdc++.h>
using namespace std;
#define testing 1
#define FOR(ii, ss, ee) for(ll ii = (ss); ii <= (ll)(ee); ++ii)
#define DEC(ii, ss, ee) for(ll ii = (ss); ii >= (ll)(ee); --ii)
#define IAMSPEED ios_base::sync_with_stdio(false); cin.tie(0);
#define db(x) cerr << #x << "=" << x << endl
#define db2(x, y) cerr << #x << "=" << x << " , " << #y << "=" << y << endl
#define db3(a,b,c) cerr<<#a<<"="<<a<<","<<#b<<"="<<b<<","<<#c<<"="<<c<<endl
#define dbv(v) cerr << #v << ":"; for (auto i : v) cerr << i << ' '; cerr << endl
#define dbvp(v) cerr << #v << ":"; for (auto i : v) cerr << "{"  << i.f << ',' << i.s << "} "; cerr << endl
#define dba(a,ss,ee) cerr << #a << ":"; FOR(i,ss,ee) cerr << a[i] << ' '; cerr << endl
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
#define ll long long 
#define pb push_back
#define inf (int)1e9
#define oo (ll)1e18
#define all(x) (x).begin(), (x).end()
#define f first
#define s second
#define reach cerr << "hi\n";
typedef pair <int, int> pi;
typedef pair <ll,ll> pl;
typedef pair <pi, int> pii;
typedef tuple<int,int,int> ti3;
string lts(ll x) {stringstream s; s << x; return s.str(); }
ll stl(string x) {stringstream s(x); ll temp; s >> temp; return temp; }
string cts(char x) {string s(1,x); return s;}
const int MOD = 1e9 + 7;
template <typename T> void maxself(T& a, T b) {
	a = max(a, b);
}
template <typename T> void minself(T& a, T b) {
	a = min(a, b);
}
#define MAXN
#if !testing
	#define cerr if(0)cout
#endif

int32_t main() {
	IAMSPEED
	// set testing to 0 when submitting to judge
	int n; cin >> n;
	int small; cin >> small;
	int ans = 1;
	FOR(i,2,n) {
		int x; cin >> x;
		if (x<small) {
			small=x;
			++ans;
		}
	}
	cout << ans;
}


Measured memory_bytes: 256
#define _USE_MATH_DEFINES
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define rep(i,n)         for(int i=0; i<(n); i++)
#define P pair<int, int>
#define prtd(n, var)     cout << fixed << setprecision(n) << var << "\n"

//----------------------------------------------------
using Graph = vector<vector<int>>;


int main(){
    int n, m;
    cin >> n >> m;
    Graph G(n);
    for(int i = 0; i < m; i++){
        int from, to;
        cin >> from >> to;
        from--; to--;
        G[from].push_back(to);
        G[to].push_back(from);
    }

    vector<int> dist(n, -1);
    vector<int> to(n, -1);
    queue<int> que;
    dist[0] = 0;
    que.push(0);
    while(!que.empty()){
        int v = que.front(); que.pop();
        for(int nv : G[v]){
            if(dist[nv] != -1) continue;
            to[nv] = v;
            to[nv]++;
            dist[nv] = dist[v] + 1;
            que.push(nv);
        }

    }
    for(int v = 0; v < n; v++){
        if(dist[v] == -1){
            cout << "No" << endl;
            break;
        }
    }
    cout << "Yes" << endl;
    for(int v = 1; v < n; v++){
        cout << to[v] << endl;
    }

}

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

using namespace std;

typedef long long ll;

int main(){
    ll n, ans = 0;   cin >> n;
    vector<ll> a(n);
    for (int i = 0; i < n; i++)
        cin >> a[i];

    for (ll i = n-1; i >= 0; i--) {
        if (i-(a[i]-1) < 1) {
            cout << -1 << endl;
            return 0;
        }

        if (i+1 < n && a[i] < a[i+1]-1) {
            cout << -1 << endl;
            return 0;
        }

        if (i+1 < n && a[i+1] - 1 == a[i])
            continue;

        ans += a[i];
    }

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

Measured memory_bytes: 4824
import sys

readline = sys.stdin.readline
readall = sys.stdin.read
ns = lambda: readline().rstrip()
ni = lambda: int(readline().rstrip())
nm = lambda: map(int, readline().split())
nl = lambda: list(map(int, readline().split()))
prl = lambda x: print(*x ,sep='\n')

n = ni()
a = nl()
for i,j in enumerate(a):
    if i == 0:
        t = j
        continue
    t = t ^ j
for k in a:
    print(t ^ k)


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

int main()
{
  int a, b;
  cin >> a >> b;
  if (abs(a - b) % 2 == 0) {
    cout << (a + b) / 2 << endl;
  } else {
    cout << "IMPOSSIBLE" << endl;
  }
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(){
  int w, a, b;
  cin >> w >> a >> b;
  if(a<=b){
    if(a+w>=b){
      cout << 0 << endl;
    }
    else {
      cout << b-a-w << endl;
    }
  }
  else{
    if(b+w>=a){
      cout << 0 << endl;
    }
    else{
      cout << a-b-w << endl;
    }
  }
}

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

int main(void){
   string S;
   cin>>S;
   int Q;
   cin>>Q;
   string result;
   for(int i=0;i<Q;i++){
      int T;
      cin>>T;
      if(T==1){
         string temp=S;
         S=result;
         result=temp;
      }else{
         int F;
         char C;
         cin>>F>>C;
         if(F==1){
            result.push_back(C);
         }else{
            S.push_back(C);
         }
      }
   }
   reverse(result.begin(),result.end());
   cout<<result+S<<endl;
   return 0;
}

Measured memory_bytes: 1248
#include <bits/stdc++.h>
using namespace std;
#define endl '\n'
#define D(x) cerr << #x << " = " << (x) << ", "
template <typename T> ostream& operator<<(ostream& _o_, const vector<T>& _v_){ \
 if(!_v_.empty()){_o_<<'[';copy(_v_.begin(),_v_.end(),ostream_iterator<T>(_o_,", "));_o_<<"\b\b]";}return _o_;}
#define rep(i, begin, end) for (__typeof(end) i = (begin) - ((begin) > (end)); i != (end) - ((begin) > (end)); i += 1 - 2 * ((begin) > (end)))
typedef unsigned int uint;
typedef unsigned long ul;
typedef unsigned long long ull;
typedef long long ll;
typedef long double ld;
typedef unsigned char uchar;
struct secure_hash {
 static uint64_t splitmix64(uint64_t x) {
  x += 0x9e3779b97f4a7c15; x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9; x = (x ^ (x >> 27)) * 0x94d049bb133111eb; return x ^ (x >> 31); }
 size_t operator()(uint64_t x) const {
  static const uint64_t FIXED_RANDOM = chrono::steady_clock::now().time_since_epoch().count(); return splitmix64(x + FIXED_RANDOM); } };
template<typename T> using V = vector<T>;
template<typename T, typename U> using umap = unordered_map<T,U,secure_hash>;
template<typename T> using uset = unordered_set<T,secure_hash>;
template<typename T> using min_heap = priority_queue<T, vector<T>, greater<T>>;
template<typename T> using max_heap = priority_queue<T>;

int n, m;
V<V<int>> adj;
V<int> dp;

int f(int u)
{
    int& ans = dp[u];
    if (ans == -1) {
        ans = 0;
        for (int v : adj[u]) {
            ans = max(ans, f(v)+1);
        }
    }
    return ans;
}

int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
    cin >> n >> m;
    adj.resize(n);
    rep(i,0,m) {
        int x, y;
        cin >> x >> y; --x, --y;
        adj[x].push_back(y);
    }
    dp.assign(n, -1);
    int ans = 0;
    rep(i,0,n) ans = max(ans, f(i));
    cout << ans << endl;
}


Measured memory_bytes: 7424
// I SELL YOU...! 
#include<iostream>
#include<vector>
#include<algorithm>
#include<functional>
#include<queue>
#include<chrono>
using namespace std;
using ll = long long;
using P = pair<ll,ll>;
signed main(){
  string s;
  cin >> s;
  if(s[0]==s[2]) cout <<"Yes\n";
  else cout <<"No\n";
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <map>
#include <cmath>
#include <iomanip>
#include <set>
#include <sstream>
#include <queue>
using namespace std;
typedef long long ll;

int main() {
  int a,b,c;
  cin >> a >> b >> c;
  int maxi = max({a,b,c});

  if ((3*maxi-(a+b+c)) % 2 == 0) {
    cout << (3*maxi-(a+b+c)) / 2 << endl;
  } else {
    cout << (3*(maxi+1)-(a+b+c)) / 2 << endl;
  }
  return 0;
}

Measured memory_bytes: 3228
package main

import (
	"bufio"
	"fmt"
	"io"
	"os"
	"strconv"
)

var (
	readString func() string
	stdout     *bufio.Writer
)

func init() {
	readString = newReadString(os.Stdin)
	stdout = bufio.NewWriter(os.Stdout)
}

func newReadString(ior io.Reader) func() string {
	r := bufio.NewScanner(ior)
	r.Buffer(make([]byte, 1024), int(1e+11))
	r.Split(bufio.ScanWords)

	return func() string {
		if !r.Scan() {
			panic("Scan failed")
		}
		return r.Text()
	}
}

func readInt() int {
	return int(readInt64())
}

func readInt64() int64 {
	i, err := strconv.ParseInt(readString(), 0, 64)
	if err != nil {
		panic(err.Error())
	}
	return i
}

func readIntSlice(n int) []int {
	b := make([]int, n)
	for i := 0; i < n; i++ {
		b[i] = readInt()
	}
	return b
}

func readLengthAndSlice() (int, []int) {
	n := readInt()
	return n, readIntSlice(n)
}

func printf(f string, args ...interface{}) (int, error) {
	return fmt.Fprintf(stdout, f, args...)
}

func println(args ...interface{}) (int, error) {
	return fmt.Fprintln(stdout, args...)
}

func eprintln(args ...interface{}) (int, error) {
	return fmt.Fprintln(os.Stderr, args...)
}

// readString() string
// readInt() int
// readIntSlice(n int) []int
// readLengthAndSlice() []int

// -----------------------------------------------------------------------------

func main() {
	defer stdout.Flush()
	a := make([]int, 5)
	for i := range a {
		a[i] = readInt()
	}
	k := readInt()

	if a[4]-a[0] > k {
		println(":(")
		return
	}
	println("Yay!")
}

// -----------------------------------------------------------------------------


Measured memory_bytes: 640
n = int(input().strip()[-1])
a = [2,4,5,7,9]
b = [0,1,6,8]
c = [3]

if n in a:
    print('hon')
    exit()
if n in b:
    print('pon')
    exit()
if n in c:
    print('bon')
    exit()


Measured memory_bytes: 61648
import java.util.*;

class Main {
    public static void main (String [] args) {

        for (int x = 1; x <= 9; x++) {
            for (int y = 1; y <= 9; y++) {
                System.out.printf("%dx%d=%d\n", x, y, x*y);
            }
        }

    }
}

Measured memory_bytes: 12000
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vi = vector<ll>;
using vii = vector<vi>;
using Pll = pair<ll, ll>;
#define rep(i,n) for(ll i=0;i<(ll)(n);i++)
#define all(v) v.begin(), v.end()
#define sz(x) ((int) x.size())
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define F first
#define S second
const int MOD = 1e9+7;
const int INF = 2e9;
template<class T> void print(const T& t){ cout << t << endl; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
int gcd(int a,int b){return b?gcd(b,a%b):a;}

ll dp[100007];
int main(){
  rep(i,100007){
    dp[i] = 0;
  }
  ll n;
  cin >> n;
  rep(i,n){
    ll a;
    cin >> a;
    if(a==0){
      dp[100002]++;
      dp[0]++;
      dp[1]++;
    }
    else{
      dp[a - 1]++;
      dp[a]++;
      dp[a + 1]++;
    }
  }
  ll ans = 0;
  rep(i, 100003){
    chmax(ans, dp[i]);
  }
  print(ans);
}

Measured memory_bytes: 1024
import Control.Applicative
import Control.Monad
import System.IO.Unsafe
import Control.Monad.ST
import Data.Functor
import Data.Function
import Data.Monoid
import Data.Maybe
import Data.List
import Data.Foldable (foldMap)
import Data.List.Split
import Data.Bits
import Data.Char
import Data.Ix
import Data.Ratio
import Data.Ord
import Data.Tuple
import Data.Array
import Data.Array.IO
import Data.Array.ST
import Data.IORef
import Data.STRef
 
readInt = read :: String -> Int
readDouble = read :: String -> Double
getInt = readLn :: IO Int
getInts = map readInt . words <$> getLine
getDouble = readLn :: IO Double
sjoin :: (Show a) => [a] -> String
sjoin = unwords . map show
cond :: a -> a -> Bool -> a
cond t f c = if c then t else f
apply2 :: (a -> a -> b) -> [a] -> b
apply2 f [x,y] = f x y
apply3 :: (a -> a -> a -> b) -> [a] -> b
apply3 f [x,y,z] = f x y z
fnBin :: (b -> c -> d) -> (a -> b) -> (a -> c) -> a -> d
fnBin op f g x = op (f x) $ g x
fnTuple :: (a -> b, a -> c) -> a -> (b, c)
fnTuple (f,g) a = (f a, g a)
replace :: (Eq a) => a -> a -> [a] -> [a]
replace x y = map (\z -> if z==x then y else z)
modifyArray :: (Ix i, MArray a e m) => a i e -> i -> (e -> e) -> m ()
modifyArray arr ix f = readArray arr ix >>= writeArray arr ix . f
-- end of templete


main = getInts >>= print . (`div` 2) . (+1) . sum

Measured memory_bytes: 508
import java.util.Scanner;

public class Main {
	public static void main(String [] args){
		Scanner sc = new Scanner(System.in);
		int size = sc.nextInt();
		int array[] = new int [size];
		for(int i=0; i<size; i++ ){
			array[i] = sc.nextInt();
		}
		
		
		for(int k=0; k<size; k++){
			
			if(k == size-1){
				System.out.println(array[k]);
			}else{
				System.out.print(array[k] + " ");
			}
		}
		//?????\?????????
		for(int i=1; i<size; i++){
			int v = array[i];
			int j = i-1;
			while(j >= 0 && array[j] > v){
				array[j+1] = array[j];
				j--;
			}
			array[j+1] = v;
		//???????????§
			for(int k=0; k<size; k++){
				if(k == size-1){
					System.out.println(array[k]);
				}else{
					System.out.print(array[k] + " ");
				}
			}
		}
	}
}

Measured memory_bytes: 32448
#include <bits/stdc++.h>
using i64 = long long;

int main() {
    i64 n, x;
    std::cin >> n >> x;

    std::vector<std::tuple<i64, i64, i64, i64>> v;
    i64 min = 0;
    for (int i = 0; i < n; i++) {
        i64 b, l, u;
        std::cin >> b >> l >> u;
        v.emplace_back(b * l + (x - b) * u, b, l, u);
        min -= l * b;
    }
    std::sort(v.begin(), v.end(), std::greater<>());
    std::vector<i64> ss(n + 1);
    for (int i = 0; i < n; i++) {
        ss[i + 1] = ss[i] + std::get<0>(v[i]);
    }

    i64 ll = -1, rr = n * x;
    while (rr - ll > 1) {
        auto m = (ll + rr) / 2;
        i64 q = std::min(m / x, n - 1), rem = m % x;
        i64 d = 0;
        for (int i = 0; i < n; i++) {
            i64 tmp = i < q ? ss[q + 1] - std::get<0>(v[i]) : ss[q];
            tmp += rem < std::get<1>(v[i]) ? rem * std::get<2>(v[i]) : std::get<1>(v[i]) * std::get<2>(v[i]) + (rem - std::get<1>(v[i])) * std::get<3>(v[i]);
            d = std::max(d, tmp);
        }
        if (d + min >= 0) rr = m;
        else ll = m;
    }
    std::cout << rr << std::endl;

    return 0;
}


Measured memory_bytes: 6512
import sys

sys.setrecursionlimit(10 ** 5)
int1 = lambda x: int(x) - 1
p2D = lambda x: print(*x, sep="\n")
def II(): return int(sys.stdin.readline())
def MI(): return map(int, sys.stdin.readline().split())
def LI(): return list(map(int, sys.stdin.readline().split()))
def LLI(rows_number): return [LI() for _ in range(rows_number)]
def SI(): return sys.stdin.readline()[:-1]

def main():
    n=II()
    aa=[]
    cnt=[0]*200005
    for _ in range(n):
        c=II()
        if not aa or aa[-1]!=c:aa.append(c)
    #print(aa)
    md=10**9+7
    ans=1
    for a in aa:
        cnt[a]=(cnt[a]+ans)%md
        ans=cnt[a]
    print(ans)

main()

Measured memory_bytes: 16556
#include <bits/stdc++.h>
using namespace std;
#define int long long   // <-----!!!!!!!!!!!!!!!!!!!

#define rep(i,n) for (int i=0;i<(n);i++)
#define rep2(i,a,b) for (int i=(a);i<(b);i++)
#define rrep(i,n) for (int i=(n)-1;i>=0;i--)
#define rrep2(i,a,b) for (int i=(a)-1;i>=b;i--)
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
#define printV(_v) for(auto _x:_v){cout<<_x<<" ";}cout<<endl
#define printVS(_vs) for(auto _x : _vs){cout << _x << endl;}
#define printVV(_vv) for(auto _v:_vv){for(auto _x:_v){cout<<_x<<" ";}cout<<endl;} cout << endl;
#define printP(_p) cout << _p.first << " " << _p.second << endl
#define printVP(_vp) for(auto _p : _vp) printP(_p);

typedef long long ll;
typedef pair<int, int> Pii;
typedef tuple<int, int, int> TUPLE;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<vvi> vvvi;
typedef vector<Pii> vp;
const int inf = 1e9;
const int mod = 1e9 + 7;

typedef complex<double> P;
const double EPS = 1e-10;
const double INF = 1e18;
const double PI = acos(-1);

P readP() {
    double x, y;
    cin >> x >> y;
    return P(x, y);
}

double distanceCC(P c1, double r1, P c2, double r2) {
    double d = abs(c1 - c2);
    return max(0., d - (r1 + r2));
}

struct edge {
    int to;
    double cost;
    edge(){}
    edge(int _to, double _cost) : to(_to), cost(_cost) {}
};
typedef vector<vector<edge>> Graph;

// undirected
void addEdge(Graph& G, int x, int y, double c) {
    G[x].emplace_back(y, c);
    G[y].emplace_back(x, c);
}
double dijkstra(const Graph& G, int s, int g) {
    int n = G.size();
    using State = pair<double, int>;
    priority_queue<State, vector<State>, greater<State>> pq;   // cost, vertex
    vector<double> d(n, INF);
    d[s] = 0;
    pq.push(make_pair(0, s));

    while (!pq.empty()) {
        auto p = pq.top(); pq.pop();
        int v = p.second;
        if (v == g) break;
        if (d[v] < p.first) continue;
        for (const auto& e : G[v]) {
            if (d[e.to] > d[v] + e.cost) {
                d[e.to] = d[v] + e.cost;
                pq.push(make_pair(d[e.to], e.to));
            }
        }
    }
    return d[g];
}

signed main() {
    std::ios::sync_with_stdio(false);
    std::cin.tie(0);

    P s, g;
    s = readP();
    g = readP();
    int n;
    cin >> n;

    vector<P> c(n + 2);
    vector<double> r(n + 2);
    c[0] = s;
    r[0] = 0;
    rep(i, n) {
        c[i + 1] = readP(); cin >> r[i + 1];
    }
    c.back() = g;
    r.back() = 0;

    Graph G(n + 2);
    rep(i, n + 2) {
        rep2(j, i + 1, n + 2) {
            addEdge(G, i, j, distanceCC(c[i], r[i], c[j], r[j]));
        }
    }

    cout << fixed << setprecision(10) << dijkstra(G, 0, n + 1) << endl;
}


Measured memory_bytes: 20720
#include<bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;i++)
#define loop(i,x,n) for(int i=x;i<n;i++)
#define pb push_back
#define int long long
using namespace std;
const int INF=1000000007;
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};


signed main(){
  string s,t;
  cin>>s;
  rep(i,4)t+=s[i];
  cout<<(t=="YAKI"?"Yes":"No")<<endl;


  return 0;
}


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

//const double PI = acos(-1);
using ll = long long;
using ull = unsigned long long;
const ll inf = 2e9;
const ll INF = 4e10;
const ll MOD = 1e9+7;
typedef pair<int,int> P;

ll n;
ll a[9];
ll A, B, C;

ll f(ll now, ll cost, ll aa, ll bb, ll cc) {
  ll ans = inf;
  if (now == n) {
    if (aa == 0 || bb == 0 || cc == 0) return inf;
    return cost + abs(A - aa) + abs(B - bb) + abs(C - cc);
  }
  ans = min(ans, f(now+1LL, cost, aa, bb, cc));
  ans = min(ans, f(now+1LL, cost + (ll)(aa == 0? 0:10), aa + a[now], bb, cc));
  ans = min(ans, f(now+1LL, cost + (ll)(bb == 0? 0:10), aa, bb + a[now], cc));
  ans = min(ans, f(now+1LL, cost + (ll)(cc == 0? 0:10), aa, bb, cc + a[now]));

  return ans;
}

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

  cin >> n >> A >> B >> C;
  for (int i = 0; i < n; i++) cin >> a[i];

  cout << f(0LL,0LL,0LL,0LL,0LL) << endl;
  return 0;
}


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

int mid(int a,int b,int c){
  return a+b+c-max(max(a,b),c)-min(min(a,b),c);
}

int main(){
    int N;
    cin >> N;
    vector<int> H(N);
    for(int i= 0; i < N;i++){
        cin >> H.at(i);
    }
    bool A = 1;
    for(int i = N - 1 ; i > 0 ;i--){
        if(H.at(i) - H.at(i - 1) == -1){
            H.at(i - 1)--;
        } 
        if(H.at(i) - H.at(i - 1) < -1){
            A = 0;
        }
    }
    if(A) cout << "Yes" << endl;
    else cout <<"No" << endl;
}

Measured memory_bytes: 640
#include<stdio.h>

int main(){
    int n,a[3],b;
    scanf("%d",&n);
    a[0]=n/100;
    a[1]=(n-100*a[0])/10;
    a[2]=(n-100*a[0]-10*a[1]);

    if(a[0]<=a[1]){
        if(a[0]<a[1]){
            b=100*(a[0]+1)+10*(a[0]+1)+a[0]+1;
        }else{
            if(a[1]<a[2]){
                b=100*(a[0]+1)+10*(a[0]+1)+a[0]+1;
            }else{
                b=100*a[0]+10*a[0]+a[0];
            }
        }

    }else{
        b=100*a[0]+10*a[0]+a[0];
    }
    printf("%d",b);
    return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define FOR(I,A,B) for(ll I = ll(A); I < ll(B); ++I)
 
 
int main(){
	ll n,q,k;
	cin >> n;
	set<ll> se;
	FOR(i,0,n){
		cin>>k;
		se.insert(k);
	}
	cin >> q;
	bool ans = true;
	FOR(i,0,q){
		cin >> k;
		ans = ans && se.count(k);
	}
	cout << ans << endl;
}


Measured memory_bytes: 12496
/*------------------------------------
........Bismillahir Rahmanir Rahim....
..........created by Abdul Aziz.......
------------------------------------*/
#include <iostream>
#include <algorithm>
#include <stdio.h>
#include <cmath>
#include <vector>
#include <set>
#include <list>
#include <stack>
#include <map>
#include <cstring>
#include <unordered_map>
#include <queue>
#define   mod  998244353
#define   int  long long 
#define   ld   long double
#define   pb   push_back
#define   vi  vector<int> 
#define   dbg(x)  cerr << #x << " = " << x << '\n'
#define   sz(x)  (int)x.size()
#define   all(a) (a.begin(),a.end())
#define   ff   first
#define   ss   second
#define   pii  pair<int,int> 
#define   lcm(a,b) (a*b)/__gcd(a,b) 
using namespace std;

vi g[300005];
map <pii,int> cost;
int node;
int dis[300005];
bool vis[300005];

void dfs(int u){
    if (vis[u]) return;
    vis[u] = true;
    for (auto &it: g[u]){
        if (!vis[it]){
            dis[it] = dis[u]+cost[{u,it}];
            dfs(it);
        }
    }
}

signed main()
{
    cin >> node ; 
    for (int i=1;i<node;i++){
        int a,b,c;
        cin >> a >> b >> c ; 
        g[a].pb(b); g[b].pb(a);
        cost[{a,b}]=c; cost[{b,a}]=c;
    }
    int q,root; cin>>q>>root;
    dis[root]=0;
    dfs(root);
    while (q--){
        int a, b;
        cin >> a >> b ; 
        cout << dis[a]+dis[b] << endl;
    }
    return 0;
}


Measured memory_bytes: 39608
//AcFreak

#include<bits/stdc++.h>
#define lint long long int 
#define mp make_pair
#define pb push_back
#define f first
#define INF (lint )(1e9)
#define __ ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define s second
#define endl '\n'
#define pii pair<int,int >
using namespace std;
struct pair_hash {
    template <class T1, class T2>
    std::size_t operator () (const std::pair<T1,T2> &p) const {
        auto h1 = std::hash<T1>{}(p.first);
        auto h2 = std::hash<T2>{}(p.second);
        
        return h1 ^ h2;  
    }
};
int main()
{__
      
      string name;
      cin>>name;
      
      lint k;
      cin>>k;
      
      int i,j;
      for(i=0;i<name.length();i++)
      {
            if(name[i]=='1' && k>1)
            {
                  k--;
            }
            else if(name[i]=='1' && k == 1)
            {
                  cout<<1<<endl;
                  return 0;
            }
            else
            {
                  cout<<name[i]<<endl;
                  return 0;
            }
      }
      return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <string.h>
int main(){
	char str[201];
	char ue[201];
	char shita[201];
	int m,h;
	int i;

	while(1){
		scanf(" ");
		gets(str);
		if(str[0] == '-' && str[1] == '\0')break;
		scanf("%d", &m);
		for(i = 0;i < m; i++){
			scanf("%d", &h);
			strcpy(shita, str);
			strcpy(ue, str+h);
			shita[h]='\0';
			strcpy(str, ue);
			strcat(str, shita);
		}
		printf("%s\n", str);
	}

	return 0;
}

Measured memory_bytes: 600
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>

using namespace std;

const long long bigv = 10000000000000LL;

int main() {
  int N, wmax, maxidx;
  cin >> N >> wmax;
  
  long long * dp = new long long[100001];
  for(int i=0;i<100001;i++){
    dp[i] = bigv;
  }
  dp[0] = 0;
  maxidx = 0;
  
  for(int i=0;i<N;i++){
    long long w,v;
    cin >> w >> v;
    
    for(int j=maxidx;j>=0;j--){
      if( dp[j] < bigv ){
        long long t = dp[j] + w;
        if( t <= wmax ){
          if( dp[j+v] == bigv ){
            dp[j+v] = t;
          } else {
            dp[j+v] = min( t , dp[j+v] );
          }
          if( j+v > maxidx ) maxidx = j + v;
        }
      }
    }
  }
  
  int maxv;
  for(maxv=100000;maxv>0;maxv--){
    if( dp[maxv] < bigv ) break;
  }
  
  cout << maxv;
  return 0;
}



Measured memory_bytes: 1024
import numpy as np

n = int(input())
s = input()
e_cnt_list = [0 for _ in range(n)]
w_cnt_list = [0 for _ in range(n)]
e_cnt = 0
w_cnt = 0
for i in range(1, n):
    if s[i-1] == 'W':
        w_cnt += 1
    w_cnt_list[i] = w_cnt
    if s[-i] == 'E':
        e_cnt += 1
    e_cnt_list[-i-1] = e_cnt
print(np.min(np.array(w_cnt_list) + np.array(e_cnt_list)))

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

#define N 100000
#define WHITE 0  // 未訪問
#define BLACK 1  // 訪問ずみ

// 連結成分の番号を振る関数
void dfs(int n, int comp[], vector<int> G[]) {
  int i, j, vertex, neighbor, color[N];
  stack<int> S;
  // 初期状態
  for (i = 0; i < n; i++) color[i] = WHITE;

  for (i = 0; i < n; i++) {
    if (color[i] == WHITE) {
      // dfs
      S.push(i);
      while (!S.empty()) {
        vertex = S.top();
        S.pop();        
        color[vertex] = BLACK;  // 訪問済みにする
        comp[vertex] = i;  // 連結成分の番号を振る          
        for (j = 0; j < (int) G[vertex].size(); j++) {
          neighbor = G[vertex][j]; // 隣接している頂点：友人
          if (color[neighbor] == WHITE) S.push(neighbor);
        }
      }
    }
  }
}

int main() {
  int i, n, m, q, s, t;
  int comp[N];  // 連結成分の番号
  vector<int> G[N];  // グラフを表現する隣接リスト

  cin >> n >> m;
  // 隣接リストを作成
  for (i = 0; i < m; i++) {
    cin >> s >> t;
    G[s].push_back(t);
    G[t].push_back(s);
  }

  // グラフを連結成分に分ける
  dfs(n, comp, G);

  cin >> q;
  for (i = 0; i < q; i++) {
    cin >> s >> t;
    if (comp[s] == comp[t]) cout << "yes" << endl;
    else cout << "no" << endl;
  }
  
  return 0;
}



Measured memory_bytes: 9412
#include<stdio.h>
#include<stdlib.h>
 
#define MAX 1000000
 
typedef struct{
  int parent;
  int left;
  int right;
}Node;
 
void RootedTree(int);
Node T[MAX];
 
int main(){
  int n,i,j;
  int k,id,child,x,depth;
 
  scanf("%d",&n);
 
  for(i=0;i<n;i++){
    T[i].parent=-1;
    T[i].left=-1;
    T[i].right=-1;
  }
 
  for(i=0;i<n;i++){
    scanf("%d%d",&id, &k);
    for(j=0;j<k;j++){
      scanf("%d",&child);
      T[child].parent=id;
      if(j==0) T[id].left=child;
      else if(j>0) T[x].right=child;
      x=child;
    }
  }
 
  for(i=0;i<n;i++) RootedTree(i);
  return 0;
}
 
void RootedTree(int n){
  int i=T[n].parent;
  int depth=0;
 
  while(i!=-1){
    i = T[i].parent;
    depth++;
  }
 
  if(depth == 0) printf("node %d: parent = %d, depth = %d, root, ",n ,T[n].parent, depth);
  else if(T[n].left == -1) printf("node %d: parent = %d, depth = %d, leaf, ",n ,T[n].parent, depth);
  else printf("node %d: parent = %d, depth = %d, internal node, ",n ,T[n].parent, depth);
 
  i=T[n].left;
  printf("[");
  if(i!=-1) printf("%d",i);
 
  while(i!=-1){
    i=T[i].right;
    if(i!=-1) printf(", %d",i);
  }
  printf("]\n");
}

Measured memory_bytes: 1788
#include<bits/stdc++.h>
using namespace std;
int main()
{
	int n;
	scanf("%d",&n);
	int a[10];
	a[1]=n%10; n=n/10;
	a[2]=n%10;n=n/10;
	a[3]=n%10;
	if(a[1]==a[3])
	 printf("Yes\n");
	else printf("No\n");
}

Measured memory_bytes: 256
line = int(input())

s_set = [x for x in range(1, 14)]
h_set = s_set[:]
c_set = s_set[:]
d_set = s_set[:]

taro_list = []
for i in range(line):
    taro_list.append(input())

for card in taro_list:
    suite = card.split(" ")[0]
    num = int(card.split(" ")[1])
    if suite == "S": s_set.remove(num)
    if suite == "H": h_set.remove(num)
    if suite == "C": c_set.remove(num)
    if suite == "D": d_set.remove(num)

for e in s_set:
    print("S " + str(e))

for e in h_set:
    print("H " + str(e))


for e in c_set:
    print("C " + str(e))

for e in d_set:
    print("D " + str(e))

Measured memory_bytes: 7760
#include <stdio.h>
#include <vector>
#include <stack>
#include <functional>
#include <numeric>
#include <complex>
#include <queue>
#include <map>
#include <unordered_map>
#include <list>
#include <set>
#include <unordered_set>
#include <assert.h>
#include <cstring>
#include <sstream>
#include <string>
#include <algorithm>
#include <iostream>
 
#define sz(x) ((int)(x).size())
#define all(x) (x).begin(), (x).end()
#define X first
#define Y second
#define pb(x) push_back(x)
#define FOR(k, n) for (int k = 0; k < n; k++)
#define FORN(k, s, n) for (int k = s; k < n; k++)
#define debug(x) printf("x = %d\n", x);
#define debug2(x, y) printf("x = %d, y = %d\n", x, y);
#define debug3(x, y, z) printf("x = %d, y = %d, z = %d\n", x, y, z);
#define debug4(x, y, z, t) printf("x = %d, y = %d, z = %d, t = %d\n", x, y, z, t);
 
#pragma warning(disable : 6031)
#pragma warning(disable : 4101)
 
using namespace std;
 
typedef long long ll;
typedef pair<int, int> pii;
typedef long double ld;
typedef complex<double> cd;
 
const int INF = 1e9;
const long long LINF = 1e18;
const double PI = acos(-1);
 
// Solution

const int MAXN = 55;

int n, A[MAXN];
double ans;

int main() {
    scanf("%d", &n);

    for (int i = 0; i < n; i++) {
        scanf("%d", &A[i]);
    }

    sort(A, A + n);

    ans = (A[0] + A[1]) / 2.0;

    for (int i = 2; i < n; i++) {
        ans = (ans + A[i]) / 2.0;
    }

    printf("%lf\n", ans);

    return 0;
}

Measured memory_bytes: 256
#define _USE_MATH_DEFINES
#include <iostream>
#include <complex>
#include <algorithm>
#include <vector>
#include <stack>
#include <string>
#include <queue>
#include <cmath>
#include <math.h>
#include <numeric>
#include <list>
#include <sstream>
#include <fstream>
#include <iomanip>
#include <climits>
#include <set>
#include <memory.h>
#include <memory>
#include <cstdio>
#include <cstdlib>
#include <cctype>
#include <cassert>
#include <map>
#include <cassert>
#include <time.h>

using namespace std;

typedef complex<double> xy_t;
typedef long long ll;
typedef pair<int, int> P;
typedef pair<int , P> PP;
typedef pair<int, string> Ps;
typedef vector<int> vec;
typedef vector<vec> mat;
const int INF= 1 << 30;
const double EPS = 1e-9;
const double PI = 3.1415926535897932384626433832795;

int nums[1000];
int pos;
int main(){
	int n, m;
	int a;
	int res;
	bool f;
	while(cin >>n >> m && (n || m)){
		pos = 0;
		f = false;
		for(int i = 0; i < n; i++){
			cin >> nums[i];
		}
		for(int i = 0; i < m; i++){
			cin >> a;
			pos += a;
			if(f) continue;
			if(pos <= n-1){
				pos += nums[pos];
			}
			if(pos >= n - 1){
				res = i + 1;
				f = true;
			}
		}
		cout << res << endl;
	}
	return 0;
}

Measured memory_bytes: 0
#include <bits/stdc++.h>
using namespace std;
#define mp make_pair
#define pb push_back
#define fi first
#define se second

int n, h[200007], x, a[200007];
long long it[800007];

void update(int k, int l, int r, int pos, long long val){
	if(l > pos || r < pos) return;
	if(l == r){
		it[k] = val;
		return;
	}
	int mid = (l + r) >> 1;
	update(k << 1, l, mid, pos, val);
	update(k << 1 | 1, mid + 1, r, pos, val);
	it[k] = max(it[k << 1], it[k << 1 | 1]);
}

long long get(int k, int l, int r, int L, int R){
	if(l > R || r < L) return 0;
	if(l >= L && r <= R) return it[k];
	int mid = (l + r) >> 1;
	return max(get(k << 1, l, mid, L, R), get(k << 1 | 1, mid + 1, r, L, R));
}

signed main(){
	ios_base::sync_with_stdio(0); cin.tie(0);
	cin >> n;
	for(int i = 1; i <= n; i++){
		cin >> x;
		h[x] = i;
	}
	for(int i = 1; i <= n; i++){
		cin >> a[i];
	}
	long long val = 0;
	for(int i = 1; i <= n; i++){
		int id = h[i];
		val = get(1, 1, n, 1, id);
		val += a[id];
		//cout << val << endl;
		update(1, 1, n, id, val);
	}
	cout << it[1];
}


Measured memory_bytes: 7936
#include <iostream>
#include <set>
#include <queue>
#include <vector>
#include <algorithm>
#include <cmath>
#include <string>
#include <cstring>
#include <climits>
#include <sstream>
#include <iomanip>
#include <map>
#include <stack>
#include <numeric>
#include <functional>

using namespace std;
#define ALL(x)			(x).begin(),(x).end()
#define REP(i, n)		for (int (i) = 0 ; (i) < (ll)(n) ; ++(i))
#define REPN(i, m, n)	for (int (i) = m ; (i) < (ll)(n) ; ++(i))
#define INF				(int)2e9
#define MOD				(1000 * 1000 * 1000 + 7)
#define Ceil(x, n)		(((((x))+((n)-1))/n))	
#define CeilN(x, n)		(((((x))+((n)-1))/n)*n)	
#define FloorN(x, n)	((x)-(x)%(n))			
#define IsOdd(x)		(((x)&0x01UL) == 0x01UL)			
#define IsEven(x)		(!IsOdd((x)))						
#define M_PI			3.14159265358979323846
typedef long long			ll;
typedef unsigned long long	ull;
typedef pair<ll, ll>		P;
typedef vector<ll>			VLL;
typedef vector<VLL>			VVLL;
typedef vector<VVLL>		VVVLL;

/*-----------------------------------------------------------------------------
　処理
 -----------------------------------------------------------------------------*/
int main()
{
	int H, W, N;
	cin >> H >> W >> N;
	vector<ll> a(N);
	REP(i, N) {
		cin >> a[i];
	}

	vector<vector<ll>> ans(H, vector<ll>(W));
	int aIdx = 0;
	REP(i, H) {
		REP(j, W) {
			int yokoIdx = j;
			if (IsOdd(i)) {
				yokoIdx = W - j - 1;
			}
			if (0 == a[aIdx]) {
				aIdx++;
			}
			ans[i][yokoIdx] = aIdx + 1;
			a[aIdx]--;
		}
	}



	REP(i, H) {
		REP(j, W) {
			cout << ans[i][j] << " ";
		}
		cout << endl;
	}

	return 0;
}


Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, a, b) for (int i = a; i < (int)(b); i++)
#define all(v) v.begin(), v.end()
const int MOD = 1e9 + 7;
const int INF = 1e9;
//'A' = 65, 'Z' = 90, 'a' = 97, 'z' = 122

int main() {
    int n, m, x;
    cin >> n >> m >> x;
    int c[n];
    int a[n][m];
    rep(i, 0, n) {
        cin >> c[i];
        rep(j, 0, m) {
            cin >> a[i][j];
        }
    }
    int ans = INF;
    rep(i, 0, (1 << n)) {
        int p[m] = {};
        int cost = 0;
        rep(j, 0, n) {
            if (i & (1 << j)) {
                rep(k, 0, m) {
                    p[k] += a[j][k];
                }
                cost += c[j];
            }
        }
        bool ok = true;
        rep(i, 0, m) {
            if (p[i] < x) {
                ok = false;
            }
        }
        if (ok) ans = min(ans, cost);
    }
    if (ans == INF) ans = -1;
    cout << ans << endl;
    return 0;
}


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

using namespace std;

int main() {
    std::ios::sync_with_stdio(false);

    string s;
    int n;
    std::cin >> n;
    std::cin >> s;
    const int sz = s.size();
    for (int i = 0; i < s.size(); ++i) {
        if (i < n) {
            std::cout << s[i];
        } else {
            std::cout << "...\n";
            return 0;
        }
    }

    return 0;
}


Measured memory_bytes: 3604
#include<stdio.h>
int sum(int a){
  int su=0;
  while(a != 0){
    su += a % 10;
    a /= 10;
  }
  return su;
}
int main(void){
  int a,b,i,min=100000;
  scanf("%d",&a);
  for(i=1;i<=a/2;i++){
    b = sum(i)+sum(a-i);
    if(b < min){
      min = b;
    }
  }
  printf("%d",min);
  return 0;
}


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

int main(){
    int N, K;
    cin >> N >> K;
    vector<int> x(N);
    rep(i, N) cin >> x[i];

    int ans = 0;
    rep(i, N){
        ans += 2 * min(x[i], K - x[i]);
    }

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

Measured memory_bytes: 256
#include <iostream>
#include <set>

using namespace std;

#define WH 52

int dx[4]={0,0,1,-1};
int dy[4]={1,-1,0,0};
char f[WH][WH];

set<char> s;

void dfs1(int ,int);
void dfs2(int ,int ,char);

int main(int argc, char const *argv[])
{
	int w,h;
	int bb,ww;

	while(1){
		cin>>w>>h;
		if(w+h==0) break;

		for(int i1=0;i1<WH;i1++){
			for(int i2=0;i2<WH;i2++){
				f[i1][i2]='#';
			}
		}

		for(int i1=1;i1<=h;i1++){
			for(int i2=1;i2<=w;i2++){
				cin>>f[i1][i2];
			}
		}

		for(int i1=1;i1<=h;i1++){
			for(int i2=1;i2<=w;i2++){
				if(f[i1][i2]=='.') {
					s.clear();
					dfs1(i2,i1);
					if(s.size()==2){}
					else dfs2(i2,i1,(*s.begin()));
				}
			}
		}

		bb=0;
		ww=0;
		for(int i1=1;i1<=h;i1++){
			for(int i2=1;i2<=w;i2++){
				if(f[i1][i2]=='b') bb++;
				else if(f[i1][i2]=='w') ww++;
			}
		}

		cout<<bb<<" "<<ww<<endl;
	}
	return 0;
}

void dfs1(int x,int y){

	f[y][x]='@';
	for(int i1=0;i1<4;i1++){
		if(f[y+dy[i1]][x+dx[i1]]=='B') s.insert('b');
		else if(f[y+dy[i1]][x+dx[i1]]=='W') s.insert('w');
		else if(f[y+dy[i1]][x+dx[i1]]=='.') dfs1(x+dx[i1],y+dy[i1]);
		else {}
	}

}

void dfs2(int x,int y, char c){

	f[y][x]=c;
	for(int i1=0;i1<4;i1++){
		if(f[y+dy[i1]][x+dx[i1]]=='@') dfs2(x+dx[i1],y+dy[i1],c);
	}
}

Measured memory_bytes: 1392
import java.util.Scanner;


public class Main {
	
	public static void main(String[] args) {
		
        Scanner scan = new Scanner(System.in);
        
        int t = scan.nextInt();
        
        int arr[] = new int[t+1];
        
        for(int i = 1; i <= t; i++) {
            int data = scan.nextInt();
            arr[i] = data;
        }
        
        scan.close();
        
        for(int i = 1; i <= t; i++) {
        	
        	int temp = i;
        	
        	int parent = temp/2;
        	int left = 2*temp;
        	int right = 2*temp+1;
        	
        	System.out.print("node " + i + ":");
        	System.out.print(" key = " + arr[i] + ", ");
        	
        	if(parent <= t && parent > 0) {
        		
        		System.out.print("parent key = " + arr[parent] + ", ");
        		
        	}
        	
        	if(left <= t && left > 0) {
        		
        		System.out.print("left key = " + arr[left] + ", ");
        		
        	}
        	
        	if(right <= t && right > 0) {
        		
        		System.out.print("right key = " + arr[right] + ", ");
        		
        	}
        	
        	System.out.println();
        	
        }
        
    }	
}




Measured memory_bytes: 27424
n = int(input())
h = tuple(map(int, input().split()))

ans = 0
move = 0
for i in range(n-1):
    if h[i] >= h[i+1]:
        move += 1
    else:
        ans = max(ans, move)
        move = 0
ans = max(ans, move)
print(ans)


Measured memory_bytes: 15148
import collections
n = int(input())
a = list(map(int, input().split()))
cumsum = [0]
for i in range(n):
  cumsum.append(cumsum[i]+a[i])
c = collections.Counter(cumsum)
values, counts = zip(*c.most_common())
ans = 0
for i in counts:
  if i >= 2:
    ans += (i*(i-1)) // 2
  else:
    break
print(ans)

Measured memory_bytes: 62940
#include <stdio.h>
#include <math.h>
int main(){
  int N,M,A,sum,ans,i;
  sum=0;
  scanf("%d %d",&N,&M);
  for(i=0;i<M;i++){
    scanf("%d",&A);
    sum=sum+A;
  }
  if(sum>N) ans=-1;
  else ans=N-sum;
  printf("%d",ans);
  return 0;
}

Measured memory_bytes: 1736