akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
#define ll long long
#define int long long
#define sz(c) c.size()
#define fr first
#define sc second
#define pb push_back
#define sz(c) c.size()
#define ppb  pop_back
#define all(a)      (a).begin(),(a).end()
#define rep(i,a,n)   for( int i=a ; i<n ; i++)
#define U 1000000007
#define N 100005
#define ins insert
using namespace std;
signed main()
{
    ios_base::sync_with_stdio(false);
    int n,k;
    cin>>n>>k;
    int a[n];
    rep(i,0,n) cin>>a[i];
    int dp[k+1][n];
    rep(i,0,k+1) rep(j,0,n) dp[i][j]=0;
    rep(i,0,a[0]+1){
       dp[i][0]=i+1;
    }
    rep(i,a[0]+1,k+1) dp[i][0]=dp[i-1][0]%U;

    rep(j,1,n){
        rep(i,0,k+1){
            int z=i-a[j];
            if(z<=0) dp[i][j]=dp[i][j-1]%U;
            else dp[i][j]=(dp[i][j-1]-dp[z-1][j-1]+U)%U;
        }
        rep(i,1,k+1) dp[i][j]=(dp[i][j]%U+dp[i-1][j]%U)%U;
    }
    if(k==0) cout<<dp[0][n-1];
    else cout<<(dp[k][n-1]-dp[k-1][n-1]+U)%U;
    /*rep(i,k-100,k+1){
        rep(j,0,n) cout<<dp[i][j]<<" ";
        cout<<endl;
    }*/


}

Measured memory_bytes: 78336
#include<iostream>
#include <string>
#include <algorithm>
using namespace std;
int main()
{
	string a, b, c, s,A,B,C;
	cin >> a >> b >> c;
	A = a[0];
	B = b[0];
	C = c[0];
	s = A+B+C;
	transform(s.begin(), s.end(), s.begin(), ::toupper);
	cout << s << endl;
}

Measured memory_bytes: 256
mod = int(1e9 + 7)

def pw(b, ex):
    if ex == 0: return 1
    if ex == 1: return b
    if ex & 1: return b % mod * pw((b*b) % mod, ex >> 1) % mod
    return pw((b*b) % mod, ex >> 1) % mod

n = int(input())
x = list(map(int,input().split()))
st = 0
en = 0

for i in x:
    st = (st + i) % mod
    en = (en + (i * i) % mod) % mod
    
st *= st
ans = int((st - en + mod) % mod)
ans = int(ans * int(pw(2, mod - 2)) % mod) % mod
print (int(ans))

Measured memory_bytes: 31436
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int main(){
 	ll r,c;
   cin>>r>>c;
   ll ans=r*c;
   if(r==1||c==1) ans=1;
   else if(ans&1) ans=ans/2+1;
   else ans=ans/2;
   cout<<ans<<endl;
   return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }

int main() {
  int N, K;
  cin >> N >> K;
  vector<int> H(N);
  for (int i = 0; i < (int)N; ++i) cin >> H[i];

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

  ll ans = 0;
  for (int i = 0; i < (int)N - K; ++i) ans += H[i];

  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 1024
import java.util.Scanner;

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

		for(int i=X-(K-1);i<=X+(K-1);i++) {
			System.out.println(i);
		}
	}
}

Measured memory_bytes: 21844
#include <stdio.h>
#include <iostream>
#include <vector>
using namespace std;
int main()
{
    int a,b;
    cin>>a>>b;
    char rem[a+1+b];
    scanf("%s",rem);
    int yes=1;
    if (rem[a]!='-')yes=0;
    if (yes==1)
    {
        for (int i=0;i<a+b+1;i++)
        {
        	if (i==a)continue;
            if (rem[i]<'0'||rem[i]>'9')
            {
                yes=0;
                break;
            }
        }
    }
    if (yes==0)printf ("No\n");
    else printf ("Yes\n");
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <sstream>
#include <stack>
#include <algorithm>
#include <cmath>
#include <queue>
#include <bitset>
#include <iomanip>
#include <limits>
#include <chrono>
#include <random>
#include <array>
#include <unordered_map>
#include <functional>
#include <complex>
#include <numeric>
#include <cctype>
#include <map>
#include <set>
#include <cstdlib>
#include <bitset>
#include <tuple>
#include <assert.h>
#include <deque>
#include <utility>


using namespace std;
typedef long long ll;

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; }
template<typename T> T gcd(T a, T b) { a = abs(a), b = abs(b); while (b > 0) { tie(a, b) = make_pair(b, a % b); } return a; }
//mt19937 rnd(chrono::steady_clock::now().time_since_epoch().count());

constexpr long long INF = 1LL << 60;
constexpr int inf = 1000000007;
//constexpr long long mod = 1000000007LL;
constexpr long long mod = 998244353LL;

int main()
{

	cin.tie(nullptr);
	ios::sync_with_stdio(false);

	ll n, a, b; cin >> n >> a >> b;
	ll res = min(n * a, b);
	cout << res << endl;
	return 0;
}

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

using namespace std;

int main() {

	int k;
	cin >> k;
	if (k % 2 == 0) {
		cout << k / 2 * k / 2 << endl;
	}
	else {
		cout << (k + 1) / 2 * (k - 1) / 2 << endl;
	}
}

Measured memory_bytes: 256
paper = [[0] * 10 for i in range(10)]

while True:
    try:
        x,y,s = map(int,input().split(','))
    except:
        break
    if s == 1:
        for i in range(10):
            for j in range(10):
                if abs(x - i) + abs(y - j) <= 1:
                    paper [i] [j] += 1
    elif s == 2:
        for i in range(10):
            for j in range(10):
                if abs(x - i) <= 1 and abs(y - j) <= 1:
                    paper [i] [j] += 1
    else:
        for i in range(10):
            for j in range(10):
                if abs(x - i) + abs(y - j) <= 2:
                    paper [i] [j] += 1

ls = sum(paper,[])
print(ls.count(0))
print(max(ls))

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

#define int long long
typedef pair<int, int> P;
#define mod 1000000007
#define INF (1LL<<60)
 
#define rep(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define repi(itr, ds) for (auto itr = ds.begin(); itr != ds.end(); itr++)
#define YES puts("YES")
#define Yes puts("Yes")
#define NO  puts("NO")
#define No  puts("No")
int gcd(int a, int b) { return b ? gcd(b, a % b) : a; }
 
const int dx[4] = { 1, 0, -1, 0 };
const int dy[4] = { 0, 1, 0, -1 };
 
 
#if 1
//-------------
// DUMPマクロ
// https://www.creativ.xyz/dump-cpp-652/
 
// vector
template <typename T>
istream& operator>>(istream& is, vector<T>& vec) {
    for (T& x : vec) is >> x;
    return is;
}
// pair
template <typename T, typename U>
ostream& operator<<(ostream& os, pair<T, U>& pair_var) {
    os << "(" << pair_var.first << ", " << pair_var.second << ")";
    return os;
}
// vector
template <typename T>
ostream& operator<<(ostream& os, const vector<T>& vec) {
    os << "{";
    for (int i = 0; i < vec.size(); i++) {
        os << vec[i] << (i + 1 == vec.size() ? "" : ", ");
    }
    os << "}";
    return os;
}
// map
template <typename T, typename U>
ostream& operator<<(ostream& os, map<T, U>& map_var) {
    os << "{";
    repi(itr, map_var) {
        os << *itr;
        itr++;
        if (itr != map_var.end()) os << ", ";
        itr--;
    }
    os << "}";
    return os;
}
// set
template <typename T>
ostream& operator<<(ostream& os, set<T>& set_var) {
    os << "{";
    repi(itr, set_var) {
        os << *itr;
        itr++;
        if (itr != set_var.end()) os << ", ";
        itr--;
    }
    os << "}";
    return os;
}
 
#define DUMPOUT cerr
 
void dump_func() {
    DUMPOUT << endl;
}
template <class Head, class... Tail>
void dump_func(Head&& head, Tail&& ... tail) {
    DUMPOUT << head;
    if (sizeof...(Tail) > 0) {
        DUMPOUT << ", ";
    }
    dump_func(std::move(tail)...);
}
#ifdef DEBUG
#define DEB
#define dump(...)                                                              \
    DUMPOUT << "  " << string(#__VA_ARGS__) << ": "                            \
            << "[" << to_string(__LINE__) << ":" << __FUNCTION__ << "]"        \
            << endl                                                            \
            << "    ",                                                         \
        dump_func(__VA_ARGS__)
#else
#define DEB if (false)
#define dump(...)
#endif
#endif


signed main(){
    int N;
    cin >> N;
    string S; cin >> S;
    int ans =0;
    rep(i,N-2){
        if(S.substr(i,3)=="ABC") ans++;
    }
    cout << ans << endl;
}


Measured memory_bytes: 256
import java.io.*;
import java.math.BigDecimal;
import java.math.BigInteger;
import java.math.RoundingMode;
import java.util.*;
import java.util.stream.IntStream;

public class Main {

    private static FastReader in = new FastReader(System.in);
    private static PrintWriter out = new PrintWriter(System.out);

    private static final long MOD = (long) 1e9 + 7;

    public static void main(String[] args) {
        solve();
        out.flush();
    }

    private static void solve() {
        int n = in.nextInt();
        int[] a = new int[n];
        int[] b = new int[n];
        for (int i = 0; i < n; i++) {
            a[i] = in.nextInt();
            b[i] = in.nextInt();
        }

        // indices
        int[] min = IntStream.range(0, n).toArray();
        int[] max = IntStream.range(0, n).toArray();

        min = Arrays.stream(min).boxed().sorted(Comparator.comparingInt(i -> a[i])).mapToInt(i -> i).toArray();
        max = Arrays.stream(max).boxed().sorted(Comparator.comparingInt(i -> b[i])).mapToInt(i -> i).toArray();

        if (n % 2 == 0) {
            int minimum = a[min[n / 2 - 1]] + a[min[n / 2]];
            int maximum = b[max[n / 2 - 1]] + b[max[n / 2]];

            out.println(maximum - minimum + 1);
        } else {
            int minimum = a[min[n / 2]];
            int maximum = b[max[n / 2]];
            out.println(maximum - minimum + 1);
        }
    }

    // https://www.geeksforgeeks.org/fast-io-in-java-in-competitive-programming/
    static class FastReader {
        BufferedReader br;
        StringTokenizer st;

        FastReader(InputStream inputStream) {
            br = new BufferedReader(new
                    InputStreamReader(inputStream));
        }

        String next() {
            while (st == null || !st.hasMoreElements()) {
                try {
                    st = new StringTokenizer(br.readLine());
                } catch (IOException  e) {
                    e.printStackTrace();
                }
            }
            return st.nextToken();
        }

        int nextInt() {
            return Integer.parseInt(next());
        }

        long nextLong() {
            return Long.parseLong(next());
        }

        double nextDouble() {
            return Double.parseDouble(next());
        }

        String nextLine() {
            String str = "";
            try {
                str = br.readLine();
            } catch (IOException e) {
                e.printStackTrace();
            }
            return str;
        }

        // https://qiita.com/masakinpo/items/5f77f2a879578a85a0bb
        public int[] nextIntArray(int n) {
            int[] a = new int[n];
            for (int i = 0; i < n; i++)
                a[i] = nextInt();
            return a;
        }

        public long[] nextLongArray(int n) {
            long[] a = new long[n];
            for (int i = 0; i < n; i++)
                a[i] = nextLong();
            return a;
        }
    }
}


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

using namespace std;


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

    int n;
    cin >> n;
    long long sum = 0;
    for (int i = 1; i <= n; ++i) {
        if(i % 3 != 0 && i % 5 != 0)
          sum += i;
    }
    cout << sum << endl;
}

Measured memory_bytes: 3652
#include<bits/stdc++.h>
using namespace std;
#define fast ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
typedef long long ll;
ll strtoint(string str);
int main(){
	fast;
	ll x,p=100,cnt=0; cin>>x;
	while(p<x){
		p+=p/100;
		++cnt;
	}
	cout<<cnt<<'\n';
	return 0;
}
ll strtoint(string str){
	ll x=0;
	stringstream ss;
	ss<<str;
	ss>>x;
	return x;
}

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

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

fn solve(s: &str) {
    let mut it = s.split_whitespace();
    let n = parse!(it);
    let al: Vec<usize> = parse!(it, n);
    let mut memo = vec![0; 20];
    let mut ret: usize = 0;
    let mut l = 0;
    for (i, a) in al.into_iter().enumerate() {
        for j in 0..20 {
            if (a >> j) & 1 == 1 {
                l = std::cmp::max(l, memo[j]);
                memo[j] = i + 1;
            }
        }
        ret += i + 1 - l;
    }
    println!("{:?}", ret); // DEBUG
}

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

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


Measured memory_bytes: 10492
#include <iostream>
#include <vector>
#include <algorithm>
#include <utility>
#include <tuple>
 
using namespace std;

#define int long long
 
struct segtree {
    vector<int> dat;
    int n;
 
    segtree(int n_) {
        n = 1;
 
        while (n < n_) n *= 2;
 
        dat.resize(2*n, 0);
    }
 
    void update(int i, int x) {
        i += n - 1;
        int diff = x - dat[i];
        dat[i] = x;
 
        while (i > 0) {
            i = (i - 1) / 2;
            dat[i] += diff;
        }
    }
 
    int query(int a, int b, int k = 0, int l = 0, int r = -1) {
        if (r == -1) r = n;
 
        if (r <= a || l >= b) return 0;
 
        if (a <= l && r <= b) {
            return dat[k];
        }
 
        int lv = query(a, b, k * 2 + 1, l, (l + r) / 2);
        int rv = query(a, b, k * 2 + 2, (l + r) / 2, r);
 
        return lv + rv;
    }
};

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

    int N; cin >> N;
    vector<int> a(N), b(N);
 
    segtree P(N), Q(N);
    vector<tuple<int, int, int>> tmp;
 
    for (int i = 0; i < N; ++i) {
        cin >> a[i] >> b[i];
        tmp.push_back(make_tuple(a[i], i, b[i]));
    }
 
    sort(begin(a), end(a));
    sort(begin(tmp), end(tmp));
 
    vector<pair<int, int>> data;
 
    for (int i = 0; i < N; ++i) {
        int aaa, bbb, val;
        tie(aaa, bbb, val) = tmp[i];
        data.push_back(make_pair(val, i));
    }
 
    sort(begin(data), end(data));
     
    for (int i = 0; i < N; ++i) {
        P.update(i, a[i]);
        Q.update(i, 1);
    }
 
    int ma = 0;
 
    for (int i = 0; i < N; ++i) {
        pair<int, int> d = data[i];
 
        int l = 0, r = N;

        int PP, QQ;
 
        for (int j = 0; j < 20; ++j) {
            int mid = (l + r) / 2;

            PP = P.query(0, mid + 1);
            QQ = Q.query(0, mid + 1);
 
            if (PP <= d.first * QQ) {
                l = mid;
            } else {
                r = mid;
            }
        }
 
        if (PP <= d.first * QQ) {
            ma = max(ma, QQ);
        }
 
        P.update(d.second, 0);
        Q.update(d.second, 0);
    }
 
    cout << ma << endl;
}

Measured memory_bytes: 43764
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define MOD 1000000007
#define INF 1LL<<30
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define all(x) (x).begin(),(x).end()


int main() {
    int n;
    cin>>n;
    vector<pair<ll,ll>> v(n);
    rep(i,n){
        ll x,l;
        cin>>x>>l;
        v[i].first=x+l;
        v[i].second=x-l;
        //v.push_back({x+l,x-l});
    }
    sort(all(v));
    int ans=0;
    ll endtime=-1LL<<60;
    rep(i,n){
        if(v[i].second>=endtime){
            endtime=v[i].first;
            ans++;
        }
        //cout<<endtime<<endl;
    }

    cout<<ans<<endl;
}



Measured memory_bytes: 1792
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int S = sc.nextInt();
        int h = S / 3600;
        int m = (S % 3600) / 60;
        int s = (S % 3600) % 60;
        System.out.println(h + ":" + m + ":" + s);
    }
}


Measured memory_bytes: 26364
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define For(i,n,k) for(int i=(n);i<(k);i++)
#define ALL(a)  (a).begin(),(a).end()
ll ans=0;
void Main(){
    ll k;cin>>k;
    string s;cin>>s;
    if(s.size()<=k){
        cout << s << endl;
    }
    else{
        For(i,0,k) cout << s[i];
        cout << "..." << endl;
    }
}
int main(){
    Main();
    /*
    東方風神録は神が出てくるので当然神ゲー
    */
    return 0;
}

Measured memory_bytes: 3632
#include <bits/stdc++.h>
using namespace std;
#define modulo 1000000007
#define mod(mod_x) ((((long long)mod_x+modulo))%modulo)
#define Inf 100000000000000000



int main(){
	
	string S;
	cin>>S;
	vector<vector<int>> dp(S.size()+1,vector<int>(4,0));
	dp[0][0] = 1;
	
	for(int i=0;i<S.size();i++){
		int x = 1;
		if(S[i]=='?')x*=3;
		for(int k=0;k<x;k++){
			for(int j=0;j<4;j++){
				dp[i+1][j] = mod(dp[i][j]+dp[i+1][j]);
			}
		}
		if(S[i]=='A'||S[i]=='?'){
			dp[i+1][1] = mod(dp[i+1][1]+dp[i][0]);
		}
		if(S[i]=='B'||S[i]=='?'){
			dp[i+1][2] = mod(dp[i+1][2]+dp[i][1]);
		}
		if(S[i]=='C'||S[i]=='?'){
			dp[i+1][3] = mod(dp[i+1][3]+dp[i][2]);
		}
	}
	/*
	for(int i=0;i<=S.size();i++){
		for(int j=0;j<4;j++){
			cout<<dp[i][j]<<',';
		}
		cout<<endl;
	}*/
	
	cout<<dp[S.size()][3]<<endl;
	
    return 0;
}


Measured memory_bytes: 5760
def resolve():
    '''
    code here
    '''
    N = int(input())
    D, X = [int(item) for item in input().split()]
    As = [int(input()) for _ in range(N)]

    cnt = 0
    for i in range(N):
        day = 1
        while day <= D:
            day +=As[i] 
            cnt +=1

    print(cnt+X)


if __name__ == "__main__":
    resolve()


Measured memory_bytes: 9060
import java.util.Scanner;

public class Main {

  public static void main(String[] args) {

    Scanner sc = new Scanner(System.in);

    String n = sc.next();
    String ans = "";

    for (int i = 0; i < 3; i++) {
      if (n.charAt(i) == '1') {
        ans += '9';
      } else {
        ans += '1';
      }
    }

    System.out.println(ans);

  }
}

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

template <typename flow_t> struct flow_graph {
	static const flow_t INF = 1e18;
	struct edge {
		int dest;
		flow_t cap;

		edge() {}
		edge(int dest_, flow_t cap_) : dest(dest_), cap(cap_) {}
	};
	vector<vector<int> > adj;
	vector<edge> edges;
	vector<int> memo;
	vector<int> dist;
	vector<int> bfs;

	flow_graph(int n) {
		memo.resize(n);
		dist.resize(n);
		adj.resize(n);
		bfs.reserve(n);
	}

	void add_edge(int from, int to, flow_t cap) {
		assert(cap >= 0);
		int e = int(edges.size());
		adj[from].push_back(e);
		adj[to].push_back(e+1);
		edges.push_back(edge(to, cap));
		edges.push_back(edge(from, 0));
	}

	void path(int sidx) {
		bfs.clear();
		bfs.push_back(sidx);
		fill(dist.begin(), dist.end(), -1);
		dist[sidx] = 0;
		for (int s = 0; s < int(bfs.size()); s++) {
			int v = bfs[s];
			for (int j = 0; j < int(adj[v].size()); j++) {
				int e = adj[v][j];
				int w = edges[e].dest;
				if (edges[e].cap > 0 && dist[w] == -1) {
					dist[w] = dist[v] + 1;
					bfs.push_back(w);
				}
			}
		}
	}

	flow_t block_flow(int tidx, int v, flow_t r) {
		if (tidx == v) {
			return r;
		}
		for (int& j = memo[v]; j < int(adj[v].size()); j++) {
			int e = adj[v][j];
			int w = edges[e].dest;
			flow_t& c = edges[e].cap;
			if (c && dist[w] == dist[v]+1) {
				flow_t del = block_flow(tidx, w, min(r, c));
				if (del > 0) {
					c -= del;
					edges[e^1].cap += del;
					return del;
				}
			}
		}
		return 0;
	}

	flow_t maxflow(int sidx, int tidx) {
		flow_t total = 0;
		while (true) {
			path(sidx);
			if (dist[tidx] == -1) break;
			fill(memo.begin(), memo.end(), 0);
			while (true) {
				flow_t del = block_flow(tidx, sidx, INF);
				if (del == 0) break;
				total += del;
			}
		}
		return total;
	}
};

using ll = long long;
const ll INF = 1e15;

int main() {
	ios::sync_with_stdio(0), cin.tie(0);
	int n;
	cin >> n;
	vector<int> a(n);
	for (int i = 0; i < n; i++) {
		cin >> a[i];
	}
	flow_graph<ll> mf(n + 2);
	int sidx = n;
	int tidx = n+1;
	ll total = 0;
	// S: 扔掉
	for (int i = 0; i < n; i++) {
		if (a[i] >= 0) {
			total += a[i];
			mf.add_edge(sidx, i, 0);
			mf.add_edge(i, tidx, a[i]);
		} else {
			mf.add_edge(sidx, i, -a[i]);
			mf.add_edge(i, tidx, 0);
		}
	}
	for (int i = 1; i <= n; i++) {
		for (int j = i+i; j <= n; j += i) {
			mf.add_edge(i-1, j-1, INF);
		}
	}
	ll answer = total - mf.maxflow(sidx, tidx);
	cout << answer << '\n';
}


Measured memory_bytes: 3712
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define rrep(ri,n) for(int ri = (int)(n-1); ri >= 0; ri--)
#define rep2(i,x,n) for(int i = (int)(x); i < (int)(n); i++)
#define repit(itr,x) for(auto itr = x.begin(); itr != x.end(); itr++)
#define rrepit(ritr,x) for(auto ritr = x.rbegin(); ritr != x.rend(); ritr++)
#define ALL(n) begin(n), end(n)
using ll = long long;
using namespace std;

const int INF = 1001001001;

int main(){
  int n;
  cin >> n;
  vector<vector<pair<int, int>>> gr(n, vector<pair<int, int>>());
  rep(i, n){
    int a;
    cin >> a;
    int k;
    cin >> k;
    rep(j, k){
      int v, c;
      cin >> v >> c;
      gr.at(i).push_back(make_pair(v, c));
    }
  }
  vector<int> d(n, INF);
  vector<bool> chk(n, false);
  d.at(0) = 0;
  chk.at(0) = true;
  int now = 0;
  rep(i, n-1){
    for(auto p : gr.at(now)){
      if(chk.at(p.first) == true) continue;
      d.at(p.first) = min(d.at(p.first), d.at(now) + p.second);
    }
    int mn = INF, nx = -1;
    rep(j, n){
      if(chk.at(j) == true) continue;
      if(mn > d.at(j)){
        mn = d.at(j);
        nx = j;
      }
    }
    if(nx == -1) break;
    chk.at(nx) = true;
    now = nx;
  }

  rep(i, n){
    cout << i << " " << d.at(i) << endl;
  }
  return 0;
}


Measured memory_bytes: 3088
#include <bits/stdc++.h>
#include <vector>
#include <iostream>
#include <iomanip>
#include <sstream>
using namespace std;

int sum_digit(int n){
  if( n == 0 ) return 0;
  else return n%10 + sum_digit(n/10);
}
int absolute(int a){
  if(a < 0) return -a;
  else return a;
}
int main()
{
  int x,y,z,K,S; cin >> K >> S;
  int count = 0;
  
  for(x = 0; x <= K; x++){
  	for(y = 0; y <= K; y++){
      z = S - x - y;
      if(z < 0 || z > K) continue;
      if(x + y + z == S){
        //cout << x << ' ' << y << ' ' << z << endl;
        count++;
      }
    }
  }
  cout << count << endl;
}

Measured memory_bytes: 256
Scanf.scanf "%d %d" (fun n k ->
    let a = Array.init n (fun _ -> Scanf.scanf " %d" (fun a -> a)) in
    Array.sort compare a;
    let rec loop i sum =
        if i = k then sum else loop (i + 1) (sum + a.(i))
    in
    loop 0 0 |> Printf.printf "%d\n"
)

Measured memory_bytes: 4136
x = input().split()
y = input().split()
x = [int(x) for x in x]
y = [int(y) for y in y]
y = sorted(y,reverse=True)
i = 0 
j = 0
for num in y:
    i=i+num
    j+=1
    if j==x[1]:
        print(i)
        break

Measured memory_bytes: 3064
#include <stdio.h>

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

	if(N <1||999<N){
		return 0;
	}

	switch(N % 10 ){
	case 2 :
	case 4 :
	case 5 :
	case 7 :
	case 9 : puts("hon"); break;
	case 0 :
	case 1 :
	case 6 :
	case 8 : puts("pon"); break;
	default : puts("bon"); break;
	}
	return 0;
}


Measured memory_bytes: 1644
#include<bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (n) ; i++)
using namespace std;
int main(){
  string S,A;
  cin >> S;
  cin >> A;

  rep( i , (int)(S.length()) ){
    S = S[S.length()-1] + S;
    S = S.erase(S.length()-1);
    
    if ( S == A ){
      cout <<"Yes"<<endl;
      exit(0);
    }
  }
  cout << "No" << endl;
  return 0;
}

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

int main() {
  ll a,b,c,k;
  cin >> a >> b >> c >> k;
  
  if(k <= a) {
    cout << k << "\n";
  }else if(k <= (a + b)) {
    cout << a << "\n";
  }else {
    cout << a - (k - (a + b)) << "\n";
  }
}

Measured memory_bytes: 3604
#include <iostream>
#include <string>
#include <vector>
#include <set>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <algorithm>
#include <iomanip>
#include <math.h>
#include <string.h>
#include <cstdio>
#include <tuple>
#include <numeric>
#define FOR(i,a,b) for(int i=a;i<b;i++)
#define REP(i,a,b) for(int i=a;i>b;i--)
#define vint vector<int> 
#define vvint vector<vint>
#define CST(x) cout<<fixed<<setprecision(x)//小数点以下の桁数指定
#define ct(a) cout<<a<<endl
static const double pi = 3.141592653589793;
using namespace std;
typedef long long ll;
const ll MOD = 1e9 + 7;
const int INF = 1e9+7;
const int mod= 1e9 + 7;


ll N, M;
ll H[100001];
bool A[100001];


ll ans;

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

	cin >> N >> M;

	FOR(i, 0, N)cin >> H[i];
	

	FOR(i, 0, M) {
		ll a, b;
		cin >> a >> b;
		a--; b--;
		if (H[a] >= H[b])A[b] = true;
		if (H[b] >= H[a])A[a] = true;
	}
	FOR(i, 0, N) {
		if (!A[i])ans++;
	}
	cout << ans << endl;






	return 0;
}


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

int main(void) {
	int n, d[100];
	int ans = 0;
	cin >> n;
	for (int i = 0; i < n; i++) {
		cin >> d[i];
	}
	
	for (int i = 0; i < n; i++) {
		for (int j = 0; j < n; j++) {
			if (i != j) {
				ans += d[i] * d[j];
			}
		}
	}
	cout << ans / 2 << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll ll_Inf = 9223372036854775807LL;

int main() {

	ll n; cin >> n;
	vector<ll> c;
	c.push_back(1);
	ll tmp6 = 6;
	while (tmp6 <= n) {
		c.push_back(tmp6);
		tmp6 *= 6;
	}
	ll tmp9 = 9;
	while (tmp9 <= n) {
		c.push_back(tmp9);
		tmp9 *= 9;
	}
	sort(c.begin(), c.end());

	vector<ll> dp(n + 1, ll_Inf);
	dp[0] = 0;
	for (ll i = 1; i <= n; i++) {
		for (ll j = 0; j < c.size(); j++) {
			if (i - c[j] < 0) continue;
			dp[i] = min(dp[i], dp[i - c[j]] + 1);
		}
	}
	cout << dp[n] << endl;
	return 0;
}

Measured memory_bytes: 1024
#include<iostream>
#include<iomanip>
#include<string>
#include<vector>
#include<queue>
#include<set>
#include<map>
#include<time.h>
using namespace std;
typedef long long ll;
typedef unsigned int uint;
#define INF (1<<30)
#define INFLL (1LL << 60)
#define MOD 1000000007
#define rep(i, n) for(int i=0; i<(n); ++i)
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; }return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; }return false; }

ll gcd(ll a, ll b) {
	while (b) {
		a -= a / b * b;
		swap(a, b);
	}
	return a;
}
//最小公倍数
ll lcm(ll a, ll b) {
	return a / gcd(a, b) * b;
}


int main()
{
	int N; cin >> N;
	vector<ll> T(N);
	rep(i, N) cin >> T[i];
	ll ans = 1;
	rep(i, N) {
		ans = lcm(ans, T[i]);
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 3156
#include<stdio.h>

int main(){

	int m,f,r;
	int total;
	char grace;
	while(1){
		scanf("%d%d%d",&m,&f,&r);
		if(m<0&&f<0&&r<0) break;
		total=m+f;
		if(m>=0&&f>=0){
		if(total>=80) grace='A';
		else if(total>=65) grace='B';
		else if(total>=50) grace='C';
		else if(total>=30)
			if(r>=50) grace='C';
			else grace='D';
		else grace='F';}
		else grace='F';
		printf("%c\n",grace);}

	return 0;
}


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

int dp[3005];
int main() {
  int n, t;
  cin >> n >> t;
  vector<pair<int,int>> v(n);
  for (auto &i : v) cin >> i.first >> i.second;
  sort(v.begin(), v.end());

  for (int i = 0; i < n; i++) {
    for (int j = t - 1; j >= 0; j--) {
      int k = min(t, j + v[i].first);
      dp[k] = max(dp[k], dp[j] + v[i].second);
    }
  }
  cout << dp[t] << endl;

  return 0;
}

Measured memory_bytes: 256
//Link : https://codeforces.com/contest/1253

#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define N 200005
#define mod 998244353
/*
#include <limits.h>
INT_MAX
LLONG_MAX
*/
ll a[N];
ll odd[N],even[N];
void solve() {
  int n;
  scanf("%d ", &n);
  for(int i=1;i<=n;++i) {
    scanf("%lld  ", &a[i]);
  }
  for(int i=1;i+1<=n;i+=2) {
    if(i==1) {
      even[i] = a[i];
      even[i+1] = a[i+1];
    } else {
      even[i+1] = a[i+1] + even[i-1];
      even[i] = a[i] + even[i-2];
    }
    even[i+1] = max(even[i+1],even[i]);
  }
  for(int i=3;i<=n;i+=2) {
    odd[i] = max(even[i-1], a[i] + odd[i-2]);
  }
  if(n&1) {
    printf("%lld\n", odd[n]);
  } else {
    printf("%lld\n", even[n]);
  }
}

int main() {
    //freopen("input.txt","r",stdin);
    solve();
    return 0;
}


Measured memory_bytes: 8524
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
using ll = long long int;

const ll MOD = 1000000007;
ll mod_pow(ll N, ll K) {
    ll ret = 1;
    for(; K>0; K>>=1) {
        if(K & 1) (ret *= N) %= MOD;
        (N *= N) %= MOD;
    }
    return ret;
}

using ll = long long int;
int main() {
    ll N, K, ans = 0, inv2 = mod_pow(2, MOD-2); cin >> N >> K;
    vector<ll> div, num;
    for(int k=1; k*k<=N; k++) {
        if(N % k == 0) {
            div.push_back(k);
            if(N / k != k) div.push_back(N / k);
        }
    }
    sort(div.begin(), div.end());
    int M = div.size(); num.resize(M);
    for(int i=0; i<M; i++) {
        num[i] = mod_pow(K, (div[i] + 1) / 2);
        for(int j=0; j<i; j++) if(div[i] % div[j] == 0) {
            num[i] = (num[i] - num[j] + MOD) % MOD;
        }
        if(div[i] % 2 == 1) (ans += div[i] * num[i]) %= MOD;
        else (ans += div[i] * num[i] % MOD * inv2) %= MOD;
    }
    cout << ans << endl;
    return 0;
}

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

using namespace std;

int n;
int dp[100100][3], r[100100][3];

int main() {
	cin >> n;
	for (int i = 0; i < n; i++) {
		for (int j = 0; j < 3; j++) cin >> r[i][j];
	}
	
	for (int i = 0; i < 3; i++) dp[0][i] = r[0][i];
	for (int i = 1; i < n; i++) {
		for (int j = 0; j < 3; j++) {
			for (int k = 0; k < 3; k++) {
				if (j != k) dp[i][j] = max(dp[i][j], dp[i - 1][k] + r[i][j]);
			}
		}
	}
	
	cout << max({dp[n - 1][0], dp[n - 1][1], dp[n - 1][2]});
}


Measured memory_bytes: 2560
#include<bits/stdc++.h>
#define REP(i,n) for(int i=0;i<(n);i++)
#define ALL(v) (v).begin(),(v).end()
#define int long long
using namespace std;
typedef vector<int>   vint;
typedef pair<int,int> pint;

signed main()
{
    int N,X; cin>>N>>X;
    vint a(N);
    REP(i,N) cin>>a[i];
    
    int ans=0;
    REP(i,N-1){
        if(a[i]+a[i+1]>X){
            if(a[i]>X) ans+=a[i]-X,a[i]=X;
            ans+=a[i]+a[i+1]-X;
            a[i+1]=X-a[i];
        }
    }
    cout<<ans<<endl;
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
/* * * *   * * *   	* * * */
#define ll  long long
#define ld long double
#define ms(a,v) memset(a,v,sizeof a)
#define pii pair<int, int>
/* * * *   * * *   	* * * */
/* *
 *
 * Author: Hamkor
 *
 * */

int main(){
	ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
	int n; cin>>n;
	int a[n], ans = 0;
	for (int i=0; i<n; ++i) {
		cin>>a[i];
		ans+=a[i];
	}
	sort(a, a+n);
	if(ans%10) cout<<ans;
	else{
		for (int i=0; i<n; ++i) if ((ans - a[i])%10){
			ans-=a[i];
			break;
		}
		if (ans%10)cout<<ans;
		else cout<<0;
	}
	return 0;
}


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

#define CPP_STR(x) CPP_STR_I(x)
#define CPP_CAT(x,y) CPP_CAT_I(x,y)
#define CPP_STR_I(args...) #args
#define CPP_CAT_I(x,y) x ## y

#define ASSERT(expr...) assert((expr))

using i8  = int8_t;
using u8  = uint8_t;
using i16 = int16_t;
using u16 = uint16_t;
using i32 = int32_t;
using u32 = uint32_t;
using i64 = int64_t;
using u64 = uint64_t;

using f32 = float;
using f64 = double;
using ll = long long;

constexpr i64 INF = 1010000000000000017LL;

constexpr i64 MOD = 1000000007LL;

constexpr f64 EPS = 1e-12;

constexpr f64 PI = 3.14159265358979323846;

#define FOR(i, start, end) for(i64 i = (start), CPP_CAT(i,xxxx_end)=(end); i < CPP_CAT(i,xxxx_end); ++i)
#define REP(i, n) FOR(i, 0, n)

#define ALL(f,c,...) (([&](decltype((c)) cccc) { return (f)(std::begin(cccc), std::end(cccc), ## __VA_ARGS__); })(c))

template<typename C>
i64 SIZE(const C& c) { return static_cast<i64>(c.size()); }

template<typename T, size_t N>
i64 SIZE(const T (&)[N]) { return static_cast<i64>(N); }

template<typename T, typename U, typename Comp=less<>>
bool chmax(T& xmax, const U& x, Comp comp={}) {
    if(comp(xmax, x)) {
        xmax = x;
        return true;
    }
    return false;
}

template<typename T, typename U, typename Comp=less<>>
bool chmin(T& xmin, const U& x, Comp comp={}) {
    if(comp(x, xmin)) {
        xmin = x;
        return true;
    }
    return false;
}

struct ProconInit {
    static constexpr int IOS_PREC = 15;
    static constexpr bool AUTOFLUSH = false;

    ProconInit() {
        cin.tie(nullptr);
        ios::sync_with_stdio(false);
        cout << fixed << setprecision(IOS_PREC);
        if(AUTOFLUSH)
            cout << unitbuf;
    }
} PROCON_INIT;

ll mod_pow(ll x, ll n) {
    if (n == 0) return 1;
    if (n % 2 == 0) {
        return mod_pow(x * x % MOD, n / 2) % MOD;
    } else {
        return x * mod_pow(x, (n - 1)) % MOD;
    }
}

ll mod_pow_r(ll x, ll n) {
    if (x == 0) return 0;
    if (n == 0) return 1;

    ll ret = 1;
    while (n) {
        if (n & 1) ret = ret * x % MOD;
        x = x * x % MOD;
        n /= 2;
    }
    return ret;
}

ll factorial(ll n) {
    ll ret = 1;
    REP(i, n) {
        ret *= (i + 1);
        ret %= MOD;
    }
    return ret;
}

ll combination(ll n, ll r) {
    if (n < 0 || n < r || r < 0) return 0;
    ll fn = factorial(n);
    ll fr = factorial(r);
    ll fn_r = factorial(n-r);

    ll d = (mod_pow(fr, MOD - 2) * mod_pow(fn_r, MOD - 2)) % MOD;
    ll u = fn % MOD;
    return u * d % MOD;
}

void solve() {
    int n, m; cin >> n >> m;
    cout << (n-1)*n / 2 + (m-1)*m / 2;
}

signed main() {
    solve();
    return 0;
}

Measured memory_bytes: 256
#include <algorithm>
#include <iostream>
#include <iomanip>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <numeric>
#include <bitset>

using namespace std;
using ll = long long;
using ld = long double;
const ll mod =  1000000007;

#define REP(i, n) for (ll i = 0; i < (n); ++i)
#define REP_FROM(i, j, n) for (ll i = (j); i < (n); ++i)
#define all(x) (x).begin(),(x).end()

ll power(ll base, ll exponent, ll module){ if(exponent % 2){ return power(base, exponent - 1, module) * base % module; }else if(exponent){ ll root_ans = power(base, exponent / 2, module); return root_ans * root_ans % module; }else{ return 1; }}
ll inverse(ll x){ return power(x, mod - 2, mod);}
ll gcd(ll a, ll b) {if(a < b) gcd(b, a);ll r;while(r=a%b) {a=b;b=r;}return b;}
struct combination{ vector<ll> fact, inv; combination(int sz) : fact(sz + 1), inv(sz + 1){ fact[0] = 1; for(int i = 1; i <= sz; i++){ fact[i] = fact[i - 1] * i % mod; } inv[sz] = power(fact[sz], mod - 2, mod); for(int i = sz - 1; i >= 0; i--){ inv[i] = inv[i + 1] * (i + 1) % mod; } } ll C(int p, int q) const{ if(q < 0 || p < q) return 0; return (fact[p] * inv[q] % mod * inv[p - q] % mod); } };

int bsearch(const vector<ll>& a, ll x){
  int lft = 0;
  int rgt = a.size();
  while (rgt - lft > 1) {
    int mid = (lft + rgt) / 2;
    if(a[mid] < x) {
      lft = mid;
    }
    else {
      rgt = mid;
    }
  }
  return lft;
}

using Pair = pair<ll, ll>;

signed main() {
  ios::sync_with_stdio(false);
  string s;
  cin >> s;
  sort(all(s));
  if(s[0] == s[1] && s[2] == s[3] && s[1] != s[2]) {
    cout << "Yes" << endl;
  }
  else {
    cout << "No" << endl;
  }
  return 0; 
}


Measured memory_bytes: 256
import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        int K = sc.nextInt();
        int[] t = new int[N];
        int[] d = new int[N];
        for (int i = 0; i < N; i++) {
            t[i] = sc.nextInt();
            d[i] = sc.nextInt();
        }
        Main abc116D = new Main();
        System.out.println(abc116D.solve(N, K, t, d));
    }

    long solve(int N, int K, int[] t, int[] d) {
        List<Sushi> sushis = new ArrayList();
        for(int i = 0; i < N; i++){
            sushis.add(new Sushi(t[i], d[i]));
        }
        ABC116DSolveWork abc116DSolve = new ABC116DSolveWork(sushis, K);
        return abc116DSolve.solve();
    }

    class ABC116DSolveWork {
        List<Sushi> sushis;
        int K;

        public ABC116DSolveWork( List<Sushi> sushis, int K) {
            this.sushis = sushis;
            this.K = K;
            Collections.sort(this.sushis);
        }

        public long solve() {
            return searchAns();
        }

        private long searchAns() {
            long point = 0;
            long size = 0;
            Set<Integer> types = new HashSet<>();
            Stack<Sushi> chohukus = new Stack();
            Queue<Sushi> kouho = new LinkedList();

            for (int i = 0; i < K; i++) {
                Sushi sushi = this.sushis.get(i);
                point += sushi.d;
                if (types.contains(sushi.t)) {
                    chohukus.push(sushi);
                } else {
                    types.add(sushi.t);
                    size += 1;
                }
            }
            long ans = point + size * size;

            for (int i = K; i < this.sushis.size(); i++) {
                Sushi sushi = this.sushis.get(i);
                if (!types.contains(sushi.t)) {
                    types.add(sushi.t);
                    kouho.add(sushi);
                }
            }

            while (!chohukus.isEmpty() && !kouho.isEmpty()) {
                Sushi delSushi = chohukus.pop();
                Sushi addSushi = kouho.poll();
                point = point - delSushi.d + addSushi.d;
                size += 1;
                long nextAns = point + size * size;

                if (nextAns > ans) {
                    ans = nextAns;
                }
            }
            return ans;
        }
    }
    class Sushi implements Comparable<Sushi>{
        public int t;
        public int d;
        public Sushi(int t, int d){
            this.t = t;
            this.d = d;
        }

        @Override
        public int compareTo(Sushi other) {
            return other.d - this.d;
        }
    }
}

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

using namespace std;

typedef long long ll;

const int INF = 1e9;
const ll LLINF = 1e18;
const ll MOD = (ll)1e9 + 7;

int main()
{
  string O, E; cin >> O >> E;
  int n = O.size() + E.size();
  string ans;
  for (int i = 0, j = 0, k = 0; i < n; ++i) {
    if (i % 2 == 0) { ans.push_back(O[j++]); }
    else { ans.push_back(E[k++]); }
  }
  printf("%s\n", ans.c_str());
  return 0;
}


Measured memory_bytes: 256
import sys
sys.setrecursionlimit(10**6)
INF = 10**7
def input():
	return sys.stdin.buffer.readline()[:-1]

n = int(input())
ver = [[-INF, INF] for _ in range(n)]
adj = [[] for _ in range(n)]
for i in range(n-1):
	a, b = map(int, input().split())
	adj[a-1].append(b-1)
	adj[b-1].append(a-1)

k = int(input())
for _ in range(k):
	w, p = map(int, input().split())
	ver[w-1] = [p, p]
	root = w-1

def dfs1(x, parent, bit):
	for v in adj[x]:
		if v == parent:
			continue
		else:
			if ver[v][1] != INF and ver[v][1]%2 == bit:
				print("No")
				sys.exit()
			dfs1(v, x, 1^bit)

dfs1(root, -1, ver[root][1]%2)

def dfs2(x, p):
	if p != -1 and len(adj[x]) == 1:
		return ver[x]
	else:
		for v in adj[x]:
			if v == p:
				continue
			else:
				m, M = dfs2(v, x)
				ver[x][0] = max(ver[x][0], m-1)
				ver[x][1] = min(ver[x][1], M+1)

		if ver[x][0] > ver[x][1]:
			print("No")
			sys.exit()
		else:
			return ver[x]

dfs2(root, -1)

ans = [INF for _ in range(n)]
ans[root] = ver[root][0]

def dfs3(x, p):
	for v in adj[x]:
		if v == p:
			continue
		else:
			if ver[v][0] <= ans[x]-1 <= ver[v][1]:
				ans[v] = ans[x] - 1
			else:
				ans[v] = ans[x] + 1
			dfs3(v, x)
	return

dfs3(root, -1)
print("Yes")
print(*ans, sep="\n")

Measured memory_bytes: 225116
h,w,c,S,max,C,N,r;
int *_M;
D(x,y){
	_M[x+(w+2)*y]=N;
	if(_M[x-1+(w+2)*y]==C)r++,D(x-1,y);
	if(_M[x+1+(w+2)*y]==C)r++,D(x+1,y);
	if(_M[x+(w+2)*(y-1)]==C)r++,D(x,y-1);
	if(_M[x+(w+2)*(y+1)]==C)r++,D(x,y+1);
}
E(int d,int *M){if(d<4||M[1+w+2]!=c){
	int *m=malloc(S);
	if(d==4){
		memcpy(_M=m,M,S);
		C=m[1+w+2],N=c;D(1,1);
		C=m[1+w+2],N=-1,r=1;D(1,1);
		if(max<r)max=r;
	}else{
		int i=1;
		for(;i<7;i++)if(M[1+w+2]!=i){
			memcpy(_M=m,M,S);
			C=m[1+w+2],N=i;D(1,1);
			E(d+1,m);
		}
	}
	free(m);
}}
a[100];
main(i,j){for(;scanf("%d%d%d",&h,&w,&c),c;printf("%d\n",max)){
	memset(a,0,S=4*(w+2)*(h+2));
	for(j=1;j<h+1;j++)for(i=1;i<w+1;i++)scanf("%d",a+i+(w+2)*j);
	E(max=0,a);
}}

Measured memory_bytes: 620
// abc142_a
#include <bits/stdc++.h>
#ifdef LOCAL
#include "../cxx-prettyprint/prettyprint.hpp"
#endif
using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> P;

#define REP(i, n) for (int (i) = 0 ; (i) < (int)(n) ; ++(i))
#define REPN(i, m, n) for (int (i) = m ; (i) < (int)(n) ; ++(i))
#define REP_REV(i, n) for (int (i) = (int)(n) - 1 ; (i) >= 0 ; --(i))
#define REPN_REV(i, m, n) for (int (i) = (int)(n) - 1 ; (i) >= m ; --(i))
#define ALL(x) x.begin(), x.end()

#define INF ((1 << 29)-1)
#define MOD (1000000007)

#define print2D(h, w, arr) REP(i, h) { REP(j, w) cout << arr[i][j] << " "; cout << endl; }
template<class T> void print(const T& x){cout << x << endl;}
template<class T, class... A> void print(const T& first, const A&... rest) { cout << first << " "; print(rest...); }
struct PreMain {PreMain(){cin.tie(0);ios::sync_with_stdio(false);cout<<fixed<<setprecision(20);}} premain;

int main() {
#ifdef LOCAL
    ifstream in("../arg.txt"); cin.rdbuf(in.rdbuf());
#endif

    int N;
    cin >> N;

    int n = (N+1) / 2;
    print(1.0 * n / N);

    return 0;
}


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

    int ans;
    string s;
int main(void){
    // Your code here!

    cin >> s;
    
    if(s[0]=='1') ans++;
    if(s[1]=='1') ans++;
    if(s[2]=='1') ans++;
    
    cout << ans << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h> 
#define ll long long
#define F first
#define FF first.first
#define FS first.second
#define S second
#define pb push_back
using namespace std;
const ll N=1000006, INF=1e16;
 
ll n, q=1, m, a[N], b[N], o, k, t, x, y, z, u, h, mx, mn, ans, Ans;
pair<ll,ll> p[N];
string s;
vector<int> v[N];
map<ll, int> f;
 
main(){ios_base::sync_with_stdio(false), cin.tie(0);
   	
	cin>>n;
	
	for (int i=1; i<=n; i++){
		cin>>a[i];
		if(a[i]<=i)ans+=f[i-a[i]];
		f[a[i]+i]++;
	}
	cout<<ans;
	
}

Measured memory_bytes: 42500
#include <stdio.h>

int main(int argc, char const *argv[]) {
  int x=0,y=0;
  int ans=0;
  scanf("%d",&x);
  int yama[x];
  for (int i = 0; i < x; i++) {
    scanf("%d",&yama[i]);
  }
  for (int i = 0; i < x; i++) {
    if (yama[i]>=y) {
      ans++;
      y=yama[i];
    }
  }
  printf("%d\n",ans);
  return 0;
}


Measured memory_bytes: 128
//#define _GLIBCXX_DEBUG
#include<bits/stdc++.h>
#define PI 3.14159265359
using namespace std;
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
const long long INF= 1e+18+1;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vector<ll> >vvl;
typedef pair<ll,ll> P;
typedef tuple<ll,ll,ll> T;
const ll MOD=1000000007LL;
string abc="abcdefghijklmnopqrstuvwxyz";
string ABC="ABCDEFGHIJKLMNOPQRSTUVWXYZ";
vl dx={-1,-1,-1,0,0,1,1,1};
vl dy={1,-1,0,1,-1,1,0,-1};
int main(){
  ll k,a,b;cin>>k>>a>>b;
  ll ans=0;
  ll MAX=k+1;
  
  if(k>=a&&b-a>0){
    k-=a-1;
    ans=a;
    ans+=(k/2*(b-a)+k%2);
  }
  cout<<max(ans,MAX)<<endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
 
#define ALL(a)  (a).begin(),(a).end()
#define ALLR(a)  (a).rbegin(),(a).rend()
#define spa << " " <<
#define test cout<<"test"<<endl;
#define fi first
#define se second
#define MP make_pair
#define rep(i,n,m) for(ll i = n; i < (ll)(m); i++)
#define rrep(i,n,m) for(ll i = n - 1; i >= (ll)(m); i--)
typedef long long ll;
typedef long double ld;
const ll MOD = 1e9+7;
//const ll MOD = 998244353;
const ll INF = 1e18;
using P = pair<ll, ll>;
template<typename T>
void chmin(T &a,T b){if(a>b)a=b;}
template<typename T>
void chmax(T &a,T b){if(a<b)a=b;}
void pmod(ll &a,ll b){a=(a+b)%MOD;}
void pmod(ll &a,ll b,ll c){a=(b+c)%MOD;}
void qmod(ll &a,ll b){a=(a*b)%MOD;}
void qmod(ll &a,ll b,ll c){a=(b*c)%MOD;}
ll median(ll a,ll b, ll c){return a+b+c-max({a,b,c})-min({a,b,c});}
void ans1(bool x){if(x) cout<<"Yes"<<endl;else cout<<"No"<<endl;}
void ans2(bool x){if(x) cout<<"YES"<<endl;else cout<<"NO"<<endl;}
void ans3(bool x){if(x) cout<<"Yay!"<<endl;else cout<<":("<<endl;}
template<typename T1,typename T2>
void ans(bool x,T1 y,T2 z){if(x)cout<<y<<endl;else cout<<z<<endl;}  
template<typename T>
void debug(vector<vector<T>>v,ll h,ll w){for(ll i=0;i<h;i++)
{cout<<v[i][0];for(ll j=1;j<w;j++)cout spa v[i][j];cout<<endl;}};
void debug(vector<string>v,ll h,ll w){for(ll i=0;i<h;i++)
{for(ll j=0;j<w;j++)cout<<v[i][j];cout<<endl;}};
template<typename T>
void debug(vector<T>v,ll n){cout<<v[0];
for(ll i=1;i<n;i++)cout spa v[i];cout<<endl;};
template<typename T>
vector<vector<T>>vec(ll x, ll y, T w){
  vector<vector<T>>v(x,vector<T>(y,w));return v;}
ll gcd(ll x,ll y){ll r;while(y!=0&&(r=x%y)!=0){x=y;y=r;}return y==0?x:y;}
//m.emplace(x,0).fi->se++;
 
vector<vector<ll>> G(200005);//隣接リスト(添え字は始点、値は終点)
vector<ll>t(200005);//訪問したかどうか
vector<ll>cnt(200005,0);
void dfs(ll k,ll num){
  t[k]=1;
  num+=cnt[k];
  cnt[k]=num;
  for(ll i=0;i<G[k].size();i++){
    if(t[G[k][i]]==0){
      dfs(G[k][i],num); 
    }
  }
}
 
int main(){
  cin.tie(NULL);
  ios_base::sync_with_stdio(false);
  ll res=0,res1=INF,res2=-INF,buf=0;
  bool judge = true;
  ll n,q;cin>>n>>q; 
  for(ll i=0;i<n-1;i++){
    ll p,q;
    cin>>p>>q;
    G[p-1].push_back(q-1);
    G[q-1].push_back(p-1);
  }
  vector<ll>x(q),y(q);
  rep(i,0,q)cin>>x[i]>>y[i];
  rep(i,0,q)cnt[x[i]-1]+=y[i];
  dfs(0,0);
  debug(cnt,n);
  return 0;
}

Measured memory_bytes: 27392
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
#define MM 1000000000;
#define mod MM + 7;
#define INF (ll)1e18
#define pi acos(-1.0)
#define MAX 100005
#define NIL -1
int main(){
    int n, p; cin >> n >> p;
    int a[n];
    bool flg = true;
    ll ans;
    for(int i = 0; i < n; i++){
        cin >> a[i];
        if(a[i]%2 == 1){
            flg = false;
        }
    }
    if(flg && p == 1){
        ans = 0;
    } else if(flg && p == 0){
        ans = pow(2, n);
    } else {
        ans = pow(2, n-1);
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
N = input()
M = input()
A = [int(a)-1 for a in raw_input().split()]
S = [0]*N
for i in range(M):
    B = [int(b)-1 for b in raw_input().split()]
    for j in range(N):
        if B[j]==A[i]:
            S[j] += 1
        else:
            S[A[i]] += 1
for s in S:
    print s

Measured memory_bytes: 6464
#include <iostream>
#include <algorithm>
#include <cstring>
#include <string>
#include <vector>
#include <cmath> 
#include <cctype>

using namespace std;

bool check_int(string str) {
    for (int i = 0; i < str.size(); i++) {
        if (isdigit(str[i]) == 0) {
            return false;
        }
    }
    
    return true;
}

int main() {
    int A, B;
    cin >> A >> B;
    string s;
    cin >> s;

    if (check_int(s.substr(0, A)) != true) {
        cout << "No" << endl;
        return 0;
    }
    if (check_int(s.substr(A + 1, B)) != true) {
        cout << "No" << endl;
        return 0;
    }

    if ((s[A] == '-') && (s.size() == A + B + 1)) {
        cout << "Yes" << endl;
    } else {
        cout << "No" << endl;
    }

    return 0;
}

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

#define rep(i, a, b) for(int i = (a); i < (b); ++i)
#define all(x) begin(x), end(x)
typedef long long ll;
typedef pair<int, int> pii;
const int inf=1010001000;
const ll  INF=1001000100010001000;
const int mod=(int)1e9+7;

int main(){
    ll n,x;
    cin>>n>>x;
    vector<ll>v(n),vv(n);

    ll m=INF;
    rep(i,0,n){
        cin>>v.at(i);
        vv.at(i)=abs(v.at(i)-x);
    }
    ll ans=0;
    rep(i,0,vv.size()-1){
        vv.at(i+1)=__gcd(vv.at(i),vv.at(i+1));
    }
    cout<<vv.at(n-1)<<endl;
return 0;
}

Measured memory_bytes: 1920