akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
#define rep(i,n)for(int i=0;i<n;i++)
using namespace std;

int ans[2][100001], w, h, x, y, f[500][500];
int dx[]{ 1,-1,0,0 }, dy[]{ 0,0,1,-1 };
bool used[500][500];
struct st {
	int x, y, c;
};
bool operator<(st a, st b) {
	return a.c > b.c;
}
int main() {
	int r;
	while (scanf("%d", &r), r) {
		fill(ans[0], ans[2], INT_MAX);
		rep(i, 2) {
			memset(used, 0, sizeof(used));
			ans[i][0] = 0;
			scanf("%d%d%d%d", &w, &h, &y, &x);
			x--; y--;
			rep(j, h)rep(k, w)scanf("%d", &f[j][k]);
			priority_queue<st>que;
			que.push({ x,y,1 });
			used[x][y] = true;
			int cnt = 0, Max = 0;
			while (!que.empty()) {
				st s = que.top(); que.pop(); cnt++;
				Max = max(Max, s.c);
				ans[i][cnt] = min(ans[i][cnt], Max);
				if (cnt >= r)break;
				rep(j, 4) {
					int nx = s.x + dx[j], ny = s.y + dy[j];
					if (0 <= nx&&nx < h && 0 <= ny&&ny < w && !used[nx][ny]) {
						used[nx][ny] = true;
						que.push({ nx,ny,f[nx][ny] });
					}
				}
			}
			for (int j = r - 1; j > 0; j--)
				ans[i][j] = min(ans[i][j], ans[i][j + 1]);
		}
		int Min = INT_MAX;
		rep(i, r + 1) {
			if (ans[0][i] == INT_MAX || ans[1][r - i] == INT_MAX)continue;
			Min = min(Min, ans[0][i] + ans[1][r - i]);
		}
		printf("%d\n", Min);
	}
}

Measured memory_bytes: 5276
#include <iostream>
#include <string>
#include <vector>
#include <list>
#include <algorithm>
#include <numeric>
#include <cmath>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <functional>
#include <utility>
#include <cctype>
#include <fstream>

using namespace std;

#define ll long long
#define INF 2000000000
#define LINF 9000000000000000000
#define rep(i,n) for(int i=0;i<(int)n;i++)
#define du(x) cout<<#x<<'='<<x<<endl
#define du2(x,y) cout<<#x<<'='<<x<<' '<<#y<<'='<<y<<'\n'<<endl
#define du3(x,y,z) cout<<#x<<'='<<x<<' '<<#y<<'='<<y<<' '<<#z<<'='<<z<<'\n'<<endl
#define darr(arr,n) rep(i,(n-arr)){cout<<*(arr+i)<<' ';}cout<<endl
#define ddarr(arr,a,b) rep(i,a){rep(j,b){cout<<*(arr+i*b+j)<<' ';}cout<<endl;}
#define ddd ifstream in("Text.txt");cin.rdbuf(in.rdbuf());

int main() {

    int N, K;
    cin >> N >> K;

    if (N%K == 0)cout << 0 << endl;
    else cout << 1 << endl;

}

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

#define rep(i, n) for (ll i = 0; i < (n); ++i)
#define sz(x) int(x.size())

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

const double PI=3.14159265358979323846;

int mod = 1e9+7;
int INF = 1e9+7;
// const long long INF = 1LL<<60;

const int MAX_P = (1<<12)+1;

int main(){

  int N, M;
  cin >> N >> M;

  vector<int> price(M);
  vector<int> open_box(M);

  rep(i, M){
    int a, b;
    cin >> a >> b;
    price[i] = a;
    int tmp = 0;
    rep(_, b){
      int c;
      cin >> c;
      tmp += 1<<(c-1);
    }
    open_box[i] = tmp;
  }

  vector<int> prev(MAX_P, INF);
  prev[0] = 0;
  rep(i, M){
    vector<int> current(MAX_P, INF);
    rep(j, MAX_P){
      if(prev[j] == INF) continue;
      // 使わない
      current[j] = min(current[j], prev[j]);
      // 使う
      int next_j = (j | open_box[i]);
      if(MAX_P <= next_j) continue;
      current[next_j] = min(current[next_j], prev[j]+price[i]);
    }
    prev = current;
  }

  if(prev[(1<<N)-1] != INF){
    cout << prev[(1<<N)-1] << endl;
  }else{
    cout << -1 << endl;
  }

  return 0;
}


Measured memory_bytes: 256
N, M = map(int, input().split())
S = list(map(int, input().split()))
T = list(map(int, input().split()))
dp = [1] * (M+1)
acc = [0] * (M)
MOD = 10 ** 9 + 7
for s in S:
  ndp = [1]
  for i, t in enumerate(T):
    if s == t:
      ndp.append(ndp[-1] + dp[i+1])
      acc[i] = dp[i+1]
    else:
      ndp.append(ndp[-1] + acc[i])
  dp = ndp
print(dp[-1] % MOD)

Measured memory_bytes: 4976
#include <bits/stdc++.h>
#define ll long long
using namespace std;
int gcd(int x, int y) { return (x % y) ? gcd(y, x % y) : y; }
int main() {
  int n;
  const double PI = 3.14159265358979323846;
  cin >> n;
  cout << 2 * PI * n;

  return 0;
}

// g++ lo.cpp
// ./a.exe
// g++ -o つくりたいふぁいるめい　もとのふぁいる.cpp
/*
for (int i = 0; i < n - 2; i++) {
  for (int j = i + 1; j < n - 1; j++) {
    int k = 2 * j - i;*/

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

#define int long long

#define rep(i,n) for(int i=0;i<(n);i++)
#define pb push_back
#define all(v) (v).begin(),(v).end()
#define fi first
#define se second
typedef vector<int>vint;
typedef pair<int,int>pint;
typedef vector<pint>vpint;

template<typename A,typename B>inline void chmin(A &a,B b){if(a>b)a=b;}
template<typename A,typename B>inline void chmax(A &a,B b){if(a<b)a=b;}

int N;
string S[11111];
string T;
signed main(){
    cin>>N;
    rep(i,N)cin>>S[i];
    cin>>T;

    int a=0,b=0,c=0;
    rep(i,N){
        string s=S[i];
        rep(j,s.size())if(s[j]=='?')s[j]='a';

        bool f1=s<=T;

        s=S[i];
        rep(j,s.size())if(s[j]=='?')s[j]='z';
        bool f2=T<=s;

        if(f1&&f2)c++;
        else if(f1)a++;
        else b++;
    }

    for(int i=0;i<=c;i++){
        if(i)printf(" ");
        printf("%lld",i+a+1);
    }
    puts("");
    return 0;
}


Measured memory_bytes: 896
from collections import deque
h, w = map(int, input().split())
s = [[x for x in input()] for _ in range(h)]

delta = [(-1, 0), (1, 0), (0, 1), (0, -1)]


def bfs(i, j):
    if s[i][j] == '#':
        return -1
    q = deque([(i, j)])
    visited = [[-1 for _ in range(w)] for __ in range(h)]
    visited[i][j] = 0
    while q:
        v = q.popleft()
        for d in delta:
            vd1, vd2 = v[0]+d[0], v[1]+d[1]
            if 0 <= vd1 < h and 0 <= vd2 < w:
                if s[vd1][vd2] != '#' and visited[vd1][vd2] == -1:
                    visited[vd1][vd2] = visited[v[0]][v[1]] + 1
                    q.append((vd1, vd2))
    return max(map(max, visited))


ans = 0

for i in range(h):
    for j in range(w):
        ans = max(ans, bfs(i, j))

print(ans)


Measured memory_bytes: 44268
#include <bits/stdc++.h>
using namespace std;
#define repl(i, l, r) for (ll i = (l); i < (r); i++)
#define rep(i, n) repl(i, 0, n)
#define fi first
#define se second
#define all(x) (x).begin(), (x).end()
#define CST(x) cout << fixed << setprecision(x)
using ll = long long;
const ll MOD = 1000000007;
const int inf = 1e9 + 10;
const ll INF = 4e18 + 10;
const int dx[9] = {1, 0, -1, 0, 1, -1, -1, 1, 0};
const int dy[9] = {0, 1, 0, -1, 1, 1, -1, -1, 0};
int main() {
	cin.tie(0);
	cout.tie(0);
	ios::sync_with_stdio(false);

	rep(i, 5) {
		int a;
		cin >> a;
		if (a == 0) cout << i + 1 << endl;
	}

	return 0;
}

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

bool foo(int a, int b){
	if (b != 100){
		cout << b*pow(100, a) << endl;
	}
	else{
		if (a == 0){
			cout << 101 << endl;
		}
		else if (a == 1){
			cout << 10100 << endl;
		}
		else if (a == 2){
			cout << 1010000 << endl;
		}
	}
	return 0;
}
int main(){
	int a, b;
	cin >> a;
	cin >> b;
	foo(a, b);
	return 0;
}

Measured memory_bytes: 256
import java.util.*; 
import java.io.*;
 
public class Main {
	public static void solve(InputReader in) {
		long a = in.readLong();
	    long b = in.readLong();
		long n = in.readLong();
		long min = Math.min(b-1,n); 
		System.out.println( (min*a)/b - (a * (min/b)) ); 
	}
    public static void main(String ...strings) {
    	InputReader in = new InputReader(System.in); 
    	int t = 1;
    	while(t-- > 0) {
    		solve(in); 
    	}
    }
}

class InputReader{
	private InputStream stream;
	private byte[] buf = new byte[1024];
	private int curChar;
	private int numChars;
	private SpaceCharFilter filter;

	public InputReader(InputStream stream) {
		this.stream = stream;
	}

    public int read() {
		if (numChars == -1)
			throw new InputMismatchException();
		if (curChar >= numChars) {
			curChar = 0;
			try {
				numChars = stream.read(buf);
			} catch (IOException e) {
				throw new InputMismatchException();
			}
			if (numChars <= 0)
				return -1;
		}
		return buf[curChar++];
	}

    public int readInt() {
		int c = read();
		while (isSpaceChar(c))
			c = read();
		int sgn = 1;
		if (c == '-') {
			sgn = -1;
			c = read();
		}
		int res = 0;
		do {
			if (c < '0' || c > '9')
				throw new InputMismatchException();
			res *= 10;
			res += c - '0';
			c = read();
		} while (!isSpaceChar(c));
		return res * sgn;
	}

    public String readString() {
		int c = read();
		while (isSpaceChar(c))
			c = read();
		StringBuilder res = new StringBuilder();
		do {
			res.appendCodePoint(c);
			c = read();
		} while (!isSpaceChar(c));
		return res.toString();
	}

    public long readLong() {
		int c = read();
		while (isSpaceChar(c)) {
			c = read();
		}
		int sgn = 1;
		if (c == '-') {
			sgn = -1;
			c = read();
		}
		long res = 0;
		do {
			if (c < '0' || c > '9') {
				throw new InputMismatchException();
			}
			res *= 10;
			res += c - '0';
			c = read();
		} while (!isSpaceChar(c));
		return res * sgn;
	}
	
    public boolean isSpaceChar(int c) {
		if (filter != null)
			return filter.isSpaceChar(c);
		return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
	}

    public String next() {
		return readString();
	}

    public interface SpaceCharFilter {
		public boolean isSpaceChar(int ch);
	}
}


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

int main()
{
	int N;
	cin >> N;
	if (N == 3 || N == 5 || N == 7) cout << "YES" << endl;
	else cout << "NO" << endl;
}


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

#define rep2(x,fr,to) for(int (x)=(fr);(x)<(to);(x)++)
#define rep(x,to) for(int (x)=0;(x)<(to);(x)++)
#define repr(x,fr,to) for(int (x)=(fr);(x)>=(to);(x)--)
#define all(c) (c).begin(),(c).end()
#define sz(v) (int)(v).size()

using namespace std;
typedef long long ll; typedef vector<int> VI; typedef pair<int,int> pii;
const int mod = (int)1e9 + 7;

ll f(ll z){
	ll rt=0;
	while(z>0){z /=10; rt++;}
	//printf(" %d:%d ",oz,rt);
	return rt;
}

int main()
{
	
	//cin.tie(0); ios_base::sync_with_stdio(false);
	ll n;
	cin >> n;
	ll ans = 1LL<<50;
	ll sq= sqrt(n);

	for(ll a=1;a<=sq;a++){
		if(n%a==0){
			ans = min(ans, max(f(a), f(n/a)));
		}
	}
	cout << ans <<endl;
	return 0;
}


Measured memory_bytes: 256
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10 ** 7)

n = int(input())

words = []
for _ in range(n):
    w = input().strip()

    if w in words:
        print('No')
        sys.exit(0)

    if len(words) == 0:
        words.append(w)
        continue

    if words[-1][-1] != w[0]:
        print('No')
        sys.exit(0)
    else:
        words.append(w)
print('Yes')


Measured memory_bytes: 61808
#include <iostream>
#include <vector>
#include <algorithm>
#include <functional>
#include <cmath>
#include <map>

#define reps(i,s,n) for(int (i) = (s); (i) < (n); (i)++)
#define rep(i,n) reps(i,0,n)
using namespace std;
using ll = long long;

int main(){
    ll k,a,b;
    cin >> k >> a >> b;
    ll ans = 0;

    if(a >= b) {
        cout << 1+k << endl;
        //cout << "I "<<endl; 
        return 0;
    }else{
        if(b-a <= 2){
            cout << 1+k << endl;
            //cout << "II "<<endl; 
            return 0;
        }else{
            if(a >= k){ 
                cout << 1+k << endl;
                //cout << "III"<<endl; 
                return 0;
            }else{
                ll tmp = k-(a-1);
                ll change_cnt = tmp/2;
                ans = a + (b-a) * change_cnt;
                if(tmp % 2 == 1)ans += 1;

                //cout << tmp << " " << change_cnt << " ";
                cout << ans << endl;
                return 0;
            }
        }
    }

    return 0;
}

Measured memory_bytes: 256
import numpy as np
from numpy.fft import rfft,irfft
N,M = map(int,input().split())
A = list(map(int,input().split()))
a = np.zeros(10**5+1)
for i in range(N):
    a[A[i]] += 1
b = rfft(a,2*10**5+1)
b = irfft(b*b,2*10**5+1)
b = np.rint(b).astype(np.int64)
c = 0
ans = 0
for n in range(2*10**5,1,-1):
    if c+b[n]<M:
        c += b[n]
        ans += b[n]*n
    else:
        ans += (M-c)*n
        c = M
        break
print(ans)

Measured memory_bytes: 43308
N=int(input())
l=[0]*N
for i in range(N-1):
 c,s,f=map(int,input().split())
 l[i]=c+s
 for j in range(i):
  l[j]=max(l[j],s,-(-l[j]//f)*f)+c

for i in l:print(i)

Measured memory_bytes: 9172
#include <iostream>
#include <vector>
#include <algorithm>
#include <utility>

using namespace std;

#define int long long
#define w first
#define v second

int N, W;

signed main()
{
	cin >> N >> W;
	vector<pair<int, int>> a;

	for (int i = 0; i < N; ++i) {
		int w, v; cin >> w >> v;
		a.push_back(make_pair(w, v));
	}

	sort(begin(a), end(a));

	vector<int> dp(W+5), tmp;

	for (int i = 0; i < N; ++i) {
		tmp = vector<int>(W+5);
		
		for (int j = 0; j <= W; ++j) {
			tmp[j] = max(tmp[j], dp[j]);
			if (j + a[i].w > W) break;
			tmp[j + a[i].w] = max(dp[j + a[i].w], dp[j] + a[i].v);
		}

		dp = tmp;
	}

	int ans = 0;
	for (int i = 0; i <= W; ++i) ans = max(ans, dp[i]);

	cout << ans << endl;
}


Measured memory_bytes: 2656
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int n;
  cin >> n;
  
  string s;
  cin >> s;
 
  int num=1;
  for(int i=0; i<n-1; i++){
    if(s[i]!=s[i+1]){
      num++;
    }
  }
  
  cout << num << endl;
  
}


Measured memory_bytes: 512
fun main(args: Array<String>) {
    val N = readLine()!!.toInt()

    val a = Array(N) { Array(N) {0} }

    var k = 1;
    while(1L shl (k - 1) < N) {
        val b = 1 shl (k - 1)

        for (i in 0 until N) {
            for(j in i + 1 until N) {
                if ((i and b) != (j and b)) {
                    a[i][j] = k
                }
            }
        }
        k++
    }

    for(i in 0 until N - 1) {
        println(a[i].slice(i + 1 until N).joinToString(" "))
    }
}

Measured memory_bytes: 39604
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

    ($next:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
}

macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };

    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };

    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
    };

    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}

fn main() {
    input!{
        N: i32, K: i32,
        R: i32, S: i32, P: i32,
        T: chars, 
    }
    let ans = rsp_game(N, K, R, S, P, T);
    println!("{}", ans);
}

fn rsp_game(N: i32, K: i32, r: i32, s: i32, p: i32, T: Vec<char>) -> i32 {
    let mut ans = 0;
    let mut S = vec!('r'; N as usize);
    for i in 0..N {
        let win = win_hand(T[i as usize]);
        if i < K {
            S[i as usize] = win;
            ans += if win == 'r' {r} else if win == 'p' {p} else {s};
        }
        else {
            if S[(i - K) as usize] == win {
                S[i as usize] = 'n';
            }
            else {
                S[i as usize] = win;
                ans += if win == 'r' {r} else if win == 'p' {p} else {s};
            }
        }
    }
    ans
}

fn win_hand(c: char) -> char {
    let mut h = 'r';
    if c == 'p' {
        h = 's';
    }
    else if c == 'r' {
        h = 'p';
    }
    h
}


Measured memory_bytes: 4476
#include <cstdio>
#include <cmath>
using namespace std;
int count=0;
void merge(int a[],int left,int mid,int right){
	int n1=mid-left,n2=right-mid;
	int l[n1+1],r[n2+1];
	for(int i=0;i<n1;i++)	l[i]=a[left+i];
	for(int i=0;i<n2;i++)	r[i]=a[mid+i];
	l[n1]=INFINITY;	r[n2]=INFINITY;
	int i=0,j=0;
	for(int k=left;k<right;k++){
		count++;
		if(l[i]<=r[j]){
			a[k]=l[i];
			i++;
		}
		else{
			a[k]=r[j];
			j++;
		}
	}
}
void mergesort(int a[],int left,int right){
	if(left+1<right){
		int mid=(left+right)/2;
		mergesort(a,left,mid);
		mergesort(a,mid,right);
		merge(a,left,mid,right);
	}
}

int main(){
	int n;	scanf("%d",&n);
	int data[n];
	for(int i=0;i<n;i++){
		scanf("%d",&data[i]);
	}
	mergesort(data,0,n);
	printf("%d",data[0]);
	for(int i=1;i<n;i++)	printf(" %d",data[i]);	
	printf("\n%d\n",count);
	return 0;
}

Measured memory_bytes: 4932
#include <bits/stdc++.h>
#define all(x) (x).begin(), (x).end()
using namespace std;
using ll = long long;
using P = pair<ll, ll>;
const string ln = "\n";
constexpr int INF = 1001001001;
constexpr int MOD = 1000000007;

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

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

  sort(all(b));
  reverse(all(b));

  ll ma = *max_element(all(a));

  ll cnt = 0;
  for (int i = 0; i < n; i++) {
    if (b[i] < ma) {
      break;
    }

    h -= b[i];
    cnt++;

    if (h <= 0) {
      break;
    }
  }

  if (h > 0) {
    cnt += (h + ma - 1) / ma;
  }

  cout << cnt << endl;

  return 0;
}

Measured memory_bytes: 1792
import java.util.Scanner;

public class Main{

	public static void main(String[] args) {
		//コンテストドリンク
		Scanner sc =new Scanner(System.in);
		int n=sc.nextInt();
		int sum=0;
		int t[] =new int[n];
		for(int i=0;i<n;i++){
			t[i]=sc.nextInt();
			sum+=t[i];
		}
		int m=sc.nextInt();
		System.out.println();
		for(int i=0;i<m;i++){
			System.out.println(sum-t[sc.nextInt()-1]+sc.nextInt());
		}
	}

}


Measured memory_bytes: 10444
n = int(input())
a = list(map(int,input().split()))
flg = 0
for i in a:
  if i%2 == 0:
    if i%3 == 0 or i%5 == 0:
      continue
    else:
      flg = 1
if flg:
  print("DENIED")
else:
  print("APPROVED")

Measured memory_bytes: 2940
package main

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

var sc = bufio.NewScanner(os.Stdin)

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

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

func main() {
	sc.Split(bufio.ScanWords)
	n := nextInt()
	m := nextInt()
	//和が偶数になるのは奇数どうし、偶数どうしを選んだ時
	fmt.Println((n*(n-1) + m*(m-1)) / 2)
}

Measured memory_bytes: 640
while True:
    i = input()
    if(i == 0):
        break
    li = []
    for x in xrange(i):
        li.append(map(int,raw_input().split()))
    ascore = 0
    bscore = 0
    for i in li:
        if(i[0] > i[1]):
            ascore += sum(i)
        elif (i[0] < i[1]):
            bscore += sum(i)
        else:
            ascore += i[0]
            bscore += i[1]
    print str(ascore) + " " + str(bscore)

Measured memory_bytes: 5712
#include<stdio.h>
#include<string.h>
#include<math.h>
#include<iostream>
#include<string>
#include<sstream>
#include<algorithm>
#include<map>
#include<set>
#include<queue>
#include<stack>
#include<vector>
using namespace std;
typedef long long ll; 
typedef pair<int, int> P; 
const int mod = 1e9 + 7;
const int N = 2e6 + 5;
struct ed{
	int to, nxt;
}e[N << 1];
int head[N], tot = 1;
void add(int u, int v){
	e[tot].to = v, e[tot].nxt = head[u], head[u] = tot++;
}
ll gcd(ll a, ll b)
{
	return b == 0 ? a : gcd(b, a % b);
}
ll f[N], h[N], a[N], n, ans;
int  main()
{
	scanf("%lld", &n);
	for (int i = 0; i < n; i++)
	{
		scanf("%lld", &a[i]);
		if (i)
			f[i] = gcd(f[i - 1], a[i]);
		else
			f[i] = a[i];
	}
	for (int i = n - 1; i >= 0; i--)
	{
		if (i == n - 1)
			h[i] = a[i];
		else
			h[i] = gcd(h[i + 1], a[i]);
	}
	for (int i = 0; i < n; i++)
	{
		if (i == 0)
			ans = max(ans, h[i + 1]);
		else if (i == n - 1)
			ans = max(ans, f[n - 2]);
		else
			ans = max(ans, gcd(f[i - 1], h[i + 1]));
	}
	printf("%lld\n", ans);
}

Measured memory_bytes: 5452
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0; i<(n); i++)
using ll = long long;
using P = pair<int,int>;
struct UnionFind {
vector<int> d;
UnionFind(int n):d(n,-1){}
int root(int x){
    if(d[x] <0) return x;
    return d[x] = root(d[x]);
}
bool unite(int x,int y){
    x = root(x),y = root(y);
    if(x == y) return false;
    if(d[x] > d[y]) swap(x,y);
    d[x] += d[y];
    d[y] = x;
    return true;
}
int size(int x) {return -d[root(x)];}
bool same(int x,int y){return root(x) == root(y);}
};
int main()
{
    int n,m;
    cin >> n >> m;
    vector<int> p(n);
    rep(i,n){
        cin >> p[i];
        p[i]--;
    }
    UnionFind uf(n);
    rep(i,m){
        int x,y;
        cin >> x >> y;
        x--;y--;
        uf.unite(x,y);

    }
    int ans = n;
    rep(i,n){
        if(uf.same(i,p[i]))continue;
        ans--;

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

Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
int n, first, second, c_first, c_second, third, c_third;
int main() {
	cin >> n;
	cin >> first >> second;
	c_second = abs(first - second);
	n -= 2;
	//cout << "-" << c_second << "-" << endl;
	while(n--) {
		cin >> third;
		//cout << "/" << c_first << " " << c_second << "/" << endl;
		//cout << "+" << c_first + abs(first - third) << " " << c_second + abs(second - third) << "+" << endl;
		c_third = min(c_first + abs(first - third), c_second + abs(second - third));
		c_first = c_second;
		c_second = c_third;
		first = second;
		second = third;
		//cout << "-" << c_first << " " << c_second << "-" << endl;
	}
	cout << c_second;
} 


Measured memory_bytes: 3596
import sys

input = sys.stdin.readline


def main():
    X = int(input())

    ans = 1
    for b in range(2, 32):
        p = 2
        while True:
            y = b ** p
            if y <= X:
                if y > ans:
                    ans = y
                p += 1
            else:
                break

    print(ans)


if __name__ == "__main__":
    main()


Measured memory_bytes: 2940
package main

import "fmt"

func main() {
	var n, a, b int
	fmt.Scan(&n, &a, &b)

	s1 := b
	s2 := a
	for i := 0; i < n-1; i++ {
		s1 += a
		s2 += b
	}

	ans := s2 - s1 + 1
	if ans < 0 {
		ans = 0
	}
	fmt.Println(ans)
}


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

void solve(int N, vector<int> a)
{
    int res = 0;
    for (int i = 0; i < N; i++)
    {
        if (i % 2 == 0 && a.at(i) % 2 != 0)
            res++;
    }
    cout << res << endl;
}

int main()
{
    int N;
    cin >> N;
    vector<int> a(N);
    for(int i = 0; i < N; i++) {
        cin >> a.at(i);
    }
    solve(N, move(a));
    return 0;
}


Measured memory_bytes: 3628
#include "iostream"
#include "climits"
#include "list"
#include "queue"
#include "stack"
#include "set"
#include "functional"
#include "algorithm"
#include "string"
#include "map"
#include "unordered_map"
#include "unordered_set"
#include "iomanip"
#include "cmath"
#include "random"
#include "bitset"
#include "cstdio"
#include "numeric"
#include "cassert"
#include "ctime"

using namespace std;

//constexpr long long int MOD = 1000000007;
constexpr int MOD = 1000000007;
//constexpr int MOD = 998244353;
//constexpr long long int MOD = 998244353;
constexpr long double EPS = 1e-12;

//int N, M, K, H, W, L, R;
long long int N, M, K, H, W, L, R;

long long int power(long long int x, long long int n, long long int M) {
	long long int ret = 1;
	long long int by = x;
	while (n) {
		if (n & 1) {
			ret *= by;
			ret %= M;
		}
		by *= by;
		by %= M;
		n >>= 1;
	}
	return ret;
}

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

	cin >> N >> M;
	vector<vector<long long int>>dp(N + 1, vector<long long int>(M + 1, 1));
	vector<vector<long long int>>sum(N + M + 1, vector<long long int>(N + 1, 1));
	for (int i = 1; i <= N; i++) {
		for (int j = 1; j <= M; j++) {
			dp[i][j] = dp[i - 1][j] + dp[i][j - 1];
			dp[i][j] %= MOD;
			sum[i + j][i] = dp[i][j];
		}
	}
	for (int i = 1; i <= N + M; i++) {
		for (int j = 1; j <= N; j++) {
			sum[i][j] += sum[i][j - 1];
			sum[i][j] %= MOD;
		}
	}
	vector<long long int>naname(N + 1);
	for (int i = 0; i <= N; i++)naname[i] = sum[i][i];
	for (int i = 1; i <= N; i++) {
		naname[i] += naname[i - 1];
		naname[i] %= MOD;
	}
	long long int ans = 0;
	for (int i = 0; i <= N; i++) {
		for (int j = 0; j <= i; j++) {
			long long int by = 0;
			int r = j, b = i - j;
			if (b > M - 1)continue;
			if (b == 0) {
				ans++;
				continue;
			}
			int bb = b - 1;
			for (int k = 0; k < min(r,bb); k++) {
				by += sum[bb][min(k,bb)];
			}
			for (int k = min(r, bb); k <= r; k++) {
				by += sum[bb][min(k, bb)];
			}

			by %= MOD;
			long long int add = dp[i - j][M - 1 - i + j];
			ans += add * by;
			ans %= MOD;
		}
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 94336
#include<bits/stdc++.h>
#define ll long long
using namespace std;
const ll N=200006;

struct flower{
	ll hi;
	ll bt;
};

ll n;
vector<flower> v(N);

ll lis(){
   vector<ll> dp(n+1);
   dp[0]=0;
   dp[1]=v[1].bt;
   
   map<ll,ll> m;
   m[v[1].hi]=dp[1];
   ll ans=dp[1];
   for(ll i=2;i<=n;i++){
   	  
   	  dp[i]=v[i].bt;
   	  auto it= m.lower_bound(v[i].hi + 1);
   	  if(it!=m.begin()){
   	  it--;
   	  dp[i]+= it->second;
      }
   	  m[v[i].hi]=dp[i];
   	  it=m.upper_bound(v[i].hi);
   	  while(it!=m.end() && it->second <=dp[i]){
   	        auto temp=it;
			temp++; 
			m.erase(it);
			it=temp;  	
	  }
	 ans=max(ans,dp[i]);
   }	
   return ans;
}

int main(){
    cin>>n;
	for(ll i=1;i<=n;i++){
		cin>>v[i].hi;
	}	
	
	for(ll i=1;i<=n;i++){
		cin>>v[i].bt;
	}	
	
	cout<<lis()<<endl;
}

Measured memory_bytes: 17408
#include<cstdio>
#include<algorithm>
using namespace std;
const int M=2e5+5,P=1e9+7;
int a[M];
int cnt[M];
struct node{
	int l,r;
	bool operator <(const node &_)const{
		return r<_.r;
	}
}p[M];
int dp[M],num[M];
int pre[M];
int main(){
	int n;
	scanf("%d",&n);
	for(int i=1;i<=n;i++){
		scanf("%d",&a[i]);
	}
	a[0]=2e9;
	int ct=0;
	for(int i=1;i<=n;i++){
		if(a[i]!=a[i-1]){
			if(pre[a[i]])p[++ct]=(node){pre[a[i]],i};
			pre[a[i]]=i;
		}
	}
	sort(p+1,p+1+ct);
	dp[0]=num[0]=1;
	for(int i=1;i<=ct;i++){
		int l=1,r=i-1,ans=0;
		while(l<=r){
			int mid=(l+r)>>1;
			if(p[mid].r<=p[i].l)ans=mid,l=mid+1;
			else r=mid-1;
		}
		dp[i]=num[ans];
		num[i]=(num[i-1]+dp[i])%P;
	}
	printf("%d\n",num[ct]);
	return 0;
}

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

const int64_t MOD = 1e9+7;
void add(int64_t& a, int64_t b){
    a = (a+b) % MOD;
}
void mul(int64_t& a, int64_t b){
    a = a*b % MOD;
}

int main(){
    int S;
    cin >> S;
    vector<int64_t> dp(S+1);
    dp[0] = 1;
    for(int i=0; i<S; i++) for(int j=i+3; j<=S; j++) add(dp[j], dp[i]);
    cout << dp[S] << endl;
    return 0;
}


Measured memory_bytes: 3636
#include<vector>
#include<list>
#include<map>
#include<climits>
#include<set>
#include<deque>
#include<stack>
#include<bitset>
#include<algorithm>
#include<functional>
#include<numeric>
#include<utility>
#include<sstream>
#include<iostream>
#include<iomanip>
#include<cstdio>
#include<cmath>
#include<cstdlib>
#include<cctype>
#include<string>
#include<cstring>
#include<ctime>
#include<queue>
#include<random>
#include<cctype>


using namespace std;

typedef long long ll;
typedef long long LL;

typedef vector<int> VI;
typedef vector<VI> VVI;

int main() {


    while (true)
    {

        int L, Max;
        cin >> L >> Max;
        
        if (L == 0 && Max == 0)
            break;


        VI d(L);
        for (auto& i : d) cin >> i;


        int result = -1;
        for (int i{}; i < L; ++i)
        {
            for (int j{}; j < L; ++j)
            {
                if (i == j) continue;

                auto current = d[i] + d[j];
                if (result < current && current <= Max)
                    result = current;
            }
        }

        if (result == -1)
            cout << "NONE" << endl;
        else
            cout << result << endl;
    }

}


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

using namespace std;

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

	map<char, string> mp;
	string sa, sb, sc;
	cin >> sa >> sb >> sc;
	mp['a'] = sa;
	mp['b'] = sb;
	mp['c'] = sc;
	char cur = 'a';
	for (;;) {
		if (mp[cur].empty()) {
			cout << (char) toupper(cur) << '\n';
			return 0;
		}
		char nxt = mp[cur][0];
		mp[cur] = mp[cur].substr(1);
		cur = nxt;
	}

	return 0;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ll int64_t
#include <cstdlib> 
#include <math.h>
#include<cstdio>
#include<cstring>
#define FOR(I, A, B) for (ll I = (A); I <= (B); I++)
#define IOS ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define fo(i,n) for(ll i=0;i<n;i++)
#define sz(a) ll((a).size())
#define pb push_back
#define all(c) (c).begin(),(c).end()
#define tr(c,i) for(auto i = (c).begin(); i != (c).end(); i++)
#define present(c,x) ((c).find(x) != (c).end())
#define cpresent(c,x) (find(all(c),x) != (c).end())
#define dbg(x) cout << #x << " = " << x << endl
#define dbg2(x,y) cout << #x << " = " << x << ", " << #y << " = " << y << endl
#define dbg3(x,y,z) cout << #x << " = " << x << ", " << #y << " = " << y << ", " << #z << " = " << z << endl
#define dbg4(x,y,z,q) cout << #x << " = " << x << ", " << #y << " = " << y << ", " << #z << " = " << z << ", " << #q << " = " << q << endl
#define scan(char_array) scanf("%[^\n]s",&char_array);


int main(){
	ll n;
	cin>>n;
	ll tmp;
	
	map<ll,ll> mp;
	fo(i,n){
		cin>>tmp;
		mp[tmp]=i;

	}
	set<ll> st;

	ll ans=0;
	st.insert(mp[n]);
	ll a,b,c,d,our;
	for(ll i=n-1;i>=1;i--){
		our=mp[i];
		bool a_t=false;
		bool b_t=false;
		bool c_t=false;
		bool d_t=false;
		auto it=st.lower_bound(our);
		if(it==st.end()){
			c=n;
			d=n;
		}
		else{
			c=*it;
			it++;
			if(it==st.end()) {
				d=n;
				
			}
			else{
				d=*it;
			}
		}
		auto it2=st.lower_bound(our);
		
		if(it2==st.begin()){
			b=-1;
			a=-1;
		}
		else{
			it2--;
			b=*it2;
			if(it2==st.begin()){
				a=-1;

			}
			else{
			    it2--;
				a=*it2;
			}
		}
		//dbg(i);
		//dbg4(a,b,c,d);
		st.insert(our);
		ans=ans+((b-a)*(c-our)+(d-c)*(our-b))*i;





	}
	cout<<ans<<endl;
}

Measured memory_bytes: 11136
#include <iostream>
#include <iomanip>
// std::cout << std::setprecision(2) << 3.141; // "3.1"
#include <algorithm>
#include <vector>
#include <string>
#include <cmath>
#include <map>

using namespace std;

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> plglg;
typedef pair<double, ll> pdlg;
typedef tuple<int, int, int> tiii;
typedef tuple<ll, ll, ll> tlglglg;
typedef tuple<double, double, double> tddd;

static const int giga = pow(10,9);
// double pi = 3.141592653589793238463;

int main(void){
  int x,a;
  cin >> x >> a;

  if(x < a){
    cout << 0 << endl;
  } else {
    cout << 10 << endl;
  }

  return 0;
}

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

int main(){
  int k,a,b,ans=0;
  cin>>k>>a>>b;
  for(int i=a;i<=b;i++){
    if(i%k==0)ans++;
  }
  if(ans==0)cout <<"NG";
  else cout <<"OK";
}


Measured memory_bytes: 3596
import sys
from math import ceil

N = int(input())
ans = []

if N == 0:
    print(0)
    sys.exit()

while N != 1:
    if N % 2 == 0:
        ans.append('0')
    else:
        ans.append('1')
    N = ceil(N / -2)
    
ans.append('1')
ans = ''.join(ans)
print(ans[::-1])

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

#define ll long long

template<typename T> void drop(const T &x){cout<<x<<endl;exit(0);}

void solve() {
  ll n, m; cin >> n >> m;
  ll cc=m/2;
  ll ans;
  if(cc<n) {
    ans = cc;
  } else {
    ans=n;
    m-=n*2; m/=4;
    ans+=m;
  }
  cout << ans << endl;

  return;
}

signed main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int T=1;
  //cin >> T;
  while(T--) solve();

  return 0;
}


Measured memory_bytes: 3608
import java.util.*;
class Main {
    public static void main(String[] args) {
	Scanner sc = new Scanner(System.in);
	int N = sc.nextInt();
	int D = sc.nextInt();
	int X = sc.nextInt();
	int ans = 0;
	for(int i = 0; i < N; i++) {
	    int t = sc.nextInt();
	    int cnt = 0;
	    while((cnt*t)+1<=D) {
		ans++;
		cnt++;
	    }
	}
	System.out.println(ans + X);
    }
}

Measured memory_bytes: 21076
A = []
min_digit = 9
for _ in range(5):
  s = input()
  n = int(s)
  digit = int(s[-1])
  if digit > 0 and digit < min_digit:
    min_digit = digit
    A = A + [n]
  else:
    A = [n] + A
    
import math as m
A = [int(m.ceil(n/10)*10) for n in A[:-1]] + [A[-1]]
print(sum(A))

Measured memory_bytes: 9068
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
#define endl '\n'
#define mod 1000000007
#define modd 998244353
#define PI 3.1415926535897932384626
#define all(x) x.begin(),x.end()
#define pb push_back
#define mp make_pair
#define ff first
#define ss second

void io() {
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
	#endif
}

int main() {
	io();
	
	int n;
	cin>>n;
	vector<int> v(n);
	int xr=0;
	for(auto &x:v) {
		cin>>x;
		xr^=x;
	}
	for(auto x:v)
		cout<<(xr^x)<<" ";
	return 0;
}


Measured memory_bytes: 3988
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

using namespace std;
using namespace __gnu_pbds;

#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define fbo find_by_order
#define ook order_of_key

typedef long long ll;
typedef pair<ll,ll> ii;
typedef vector<int> vi;
typedef long double ld;
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> pbds;
typedef set<int>::iterator sit;
typedef map<int,int>::iterator mit;
typedef vector<int>::iterator vit;

ll n, m, a, b, x[100001];

int main(){
	ios_base::sync_with_stdio(false); cin.tie(0);
	cin >> n >> m;
	for(int i = 0; i < m; i++){
		cin >> a >> b;
		x[a]++;
		x[b]--;
	}
	for(int i = 1; i <= n-1; i++){
		x[i] += x[i-1];
		if(x[i]%2==1){
			cout << "NO";
			return 0;
		}
	}
	cout << "YES";
}


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

int main() {
    int a,b,c,k;
    cin>>a>>b>>c>>k;
    int ans = 0;
    if(k>=a){
        ans+=a;
        k-=a;
    }
    else{
        ans+=k;
        k=0;
    }
    if(k>=b){
        k-=b;
    }
    else{
        k=0;
    }
    ans-=k;
    cout<<ans;
    return 0;
}


Measured memory_bytes: 3624
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
using namespace std;
#ifdef ENABLE_DEBUG
#define dump(a) cerr<<#a<<"="<<a<<endl
#define dumparr(a,n) cerr<<#a<<"["<<n<<"]="<<a[n]<<endl
#else
#define dump(a) 
#define dumparr(a,n) 
#endif
#define FOR(i, a, b) for(ll i = (ll)a;i < (ll)b;i++)
#define For(i, a) FOR(i, 0, a)
#define REV(i, a, b) for(ll i = (ll)b-1LL;i >= (ll)a;i--)
#define Rev(i, a) REV(i, 0, a)
#define REP(a) For(i, a)
#define SIGN(a) (a==0?0:(a>0?1:-1))

typedef long long int ll;
typedef unsigned long long ull;
typedef unsigned int uint;
typedef pair<ll, ll> pll;
typedef pair<ll,pll> ppll;
typedef vector<ll> vll;
typedef long double ld;
typedef pair<ld,ld> pdd;

const ll INF=(1LL<<50);
#if __cplusplus<201700L
ll gcd(ll a, ll b) {
  if(a < b) return gcd(b, a);
  ll r;
  while ((r=a%b)) {
    a = b;
    b = r;
  }
  return b;
}
#endif
template<class T>
bool chmax(T& a,const T& b){
  if(a<b){
    a=b;
    return true;
  }
  return false;
}
template<class T>
bool chmin(T& a,const T& b){
  if(a>b){
    a=b;
    return true;
  }
  return false;
}
template<class S,class T>
std::ostream& operator<<(std::ostream& os,pair<S,T> a){
  os << "(" << a.first << "," << a.second << ")";
  return os;
}
template<class T>
std::ostream& operator<<(std::ostream& os,vector<T> a){
  os << "[ ";
  REP(a.size()){
    os<< a[i] << " ";
  }
  os<< " ]";
  return os;
}

const string YES = "Yes";
const string NO = "No";

void solve(std::string S, std::string T){
  for (char i = 'a'; i <= 'z'; i++)
  {
    if(S+i==T){
      cout<<YES<<endl;
      return ;
    }
  }
  cout<<NO<<endl;
  return;
  
}

int main(){
  cout<<setprecision(1000);
    std::string S;
    std::cin >> S;
    std::string T;
    std::cin >> T;
    solve(S, T);
    return 0;
}


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

char c[110][110];

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

	int h, w;
	cin >> h >> w;

	for(int i = 0; i < h; ++i){
		for(int j = 0; j < w; ++j){
			cin >> c[i][j];
		}
	}

	for(int i = 0; i < h; ++i){
		int cnt = -1;
		for(int j = 0; j < w; ++j){
			if(c[i][j] == 'c'){
				cnt = 0;
			}
			else if(cnt != -1){
				++cnt;
			}
			if(j != 0) cout << " ";
			cout << cnt;
		}
		cout << endl;
	}

	return 0;
}

Measured memory_bytes: 3144
#include <bits/stdc++.h>
#define fastio ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
using namespace std;

int main(void){
  fastio;
  long long l,n;
  cin>>n>>l;
  string s;
  vector<string>vs;
  for (int i = 0; i < n; ++i)
  {
    cin>>s;
    vs.push_back(s);
  }
  sort(vs.begin(),vs.end());
  for (std::vector<string>::iterator i = vs.begin(); i != vs.end(); ++i)
  {
    cout<<*i;
  }
  cout<<endl;
  return 0;
}

Measured memory_bytes: 256
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <vector>
#include <queue>
#include <map>
#include <iterator>
#include <cmath>
#include <set>
#include <deque> 
#include <string>


using namespace std;

char s[20];
char t[20];
char u[20];
int a, b;
		
int main()
{
	scanf("%s%s", &s, &t);
	scanf("%d%d", &a, &b);
	scanf("%s", &u);
	
	if (strcmp(s, u) == 0) {
		a--;
	}
	
	if (strcmp(t, u) == 0) {
		b--;
	}
	
	printf("%d %d\n", a, b);
	
	return 0;
}


Measured memory_bytes: 128
using System;

namespace Sample101
{
    class Program
    {
        static void Main(string[] args)
        {
            var n = int.Parse(Console.ReadLine());
            var Taro = 0;
            var Hanako = 0;
            for (int i = 0; i < n; i++)
            {
                var line = Console.ReadLine().Split(' ');
                // 太郎と花子で比較して点数計算
                if (line[0] == line[1])
                {
                    Taro += 1;
                    Hanako += 1;
                } else if (line[0].CompareTo(line[1]) < 0)
                {
                    Hanako += 3;
                } else
                {
                    Taro += 3;
                }
            }

            Console.WriteLine(Taro + " " + Hanako);
        }
    }
}


Measured memory_bytes: 18784
#include<stdio.h>
#include<stdlib.h>
typedef struct list{
  int u, k, *v;
}T_list;
int main(){
  int n;
  scanf("%d", &n);
  T_list lst[n];
  int mat[n][n];
  int i, j;
  for(i = n - 1; i >= 0; i--)
    for(j = n - 1; j >= 0; j--)
      mat[i][j] = 0;
  for(i = 0; i < n; i++){
    scanf("%d %d", &lst[i].u, &lst[i].k);
    if(lst[i].k){
      lst[i].v = (int *)malloc(sizeof(int) * lst[i].k);
      for(j = 0; j < lst[i].k; j++){
	scanf("%d", &lst[i].v[j]);
	mat[lst[i].u - 1][lst[i].v[j] - 1] = 1;
      }
      free(lst[i].v);
    }
  }
  for(i = 0; i < n; i++){
    printf("%d", mat[i][0]);
    for(j = 1; j < n; j++)
      printf(" %d", mat[i][j]);
    printf("\n");
  }
  return 0;
}

Measured memory_bytes: 640
#include<iomanip>
#include<limits>
#include<thread>
#include<utility>
#include<iostream>
#include<string>
#include<algorithm>
#include<set>
#include<map>
#include<vector>
#include<stack>
#include<queue>
#include<cmath>
#include<numeric>
#include<cassert>
#include<random>
#include<chrono>
#include<unordered_set>
#include<unordered_map>
#include<fstream>
#include<list>
#include<functional>
#include<bitset>
#include<complex>
#include<tuple>
using namespace std;
typedef unsigned long long int ull;
typedef long long int ll;
typedef pair<ll,ll> pll;
typedef long double D;
#define F first
#define S second
const ll E=1e18+7;
const ll MOD=1000000007;

class comb{
private:
    ll mod;
    ll mx;
    vector<ll> F;
    vector<ll> FR;
    
public:
    comb(ll mod=1000000007,ll mx=100000):mod(mod),mx(mx),F(mx+1,1),FR(mx+1,1){
        mk_F();
    }
    
    ll mod_pow(ll a,ll x){
        a%=mod;
        ll ans=1;
        while(x>0){
            if(x&1){ans*=a; ans%=mod;}
            a*=a;
            a%=mod;
            x>>=1;
        }
        return ans;
    }
    
    pll Ex_gcd(ll a,ll b){
        if(b==0){return {1,0};}
        pll ret=Ex_gcd(b,a%b);
        ret.F-=a/b*ret.S;
        return {ret.S,ret.F};
    }
    
    ll prime_R(ll a){
        return mod_pow(a,mod-2);
    }
    
    ll R(ll a){
        ll ret=Ex_gcd(a,mod).F;
        ret%=mod;
        if(ret<0){ret+=mod;}
        return ret;
    }
    
    void mk_F(){
        for(ll i=1;i<=mx;i++){F[i]=F[i-1]*i%mod; FR[i]=R(F[i]);}
    }
    
    ll c(ll n,ll k){
        if(n<k || n<0 || k<0){return 0;}
        if(n==k || k==0){return 1;}
        return F[n]*FR[n-k]%mod*FR[k]%mod;
    }
    
    //mod must be prime
    ll Lucas_C(ll n,ll m){
        ll ret=1;
        while(n>0 || m>0){
            ret*=c(n%mod,m%mod);
            ret%=mod;
            n/=mod; m/=mod;
        }
        return ret;
    }
    
    ll Stirling(ll n,ll k){
        ll ret=0;
        for(ll i=1;i<=k;i++){
            if((k-i)%2){ret-=c(k,i)*mod_pow(i,n)%mod;}
            else{ret+=c(k,i)*mod_pow(i,n)%mod;}
            ret%=mod;
        }
        ret*=R(F[k]);
        ret%=mod;
        if(ret<0){ret+=mod;}
        return ret;
    }
    
    ll Bell(ll n,ll k){
        ll ret=0;
        for(ll i=1;i<=k;i++){ret+=Stirling(n,i); ret%=mod;}
        return ret;
    }
};

comb C(MOD,1000000);

int main(){
    ll n,m,k;
    cin>>n>>m>>k;
    ll ans=0;
    ll cnt=0;
    for(ll i=0;i<k;i++){
        cnt+=i*C.c(n,i)%MOD*C.c(m*n-n-1,k-1-i)%MOD;
        cnt%=MOD;
    }
    for(ll i=0;i<m;i++){
        ans+=n*cnt%MOD*((i*(i+1)/2+(m-i)*(m-i-1)/2)%MOD)%MOD;
        ans%=MOD;
    }
    cnt=0;
    for(ll i=0;i<k;i++){
        cnt+=i*C.c(m,i)%MOD*C.c(m*n-m-1,k-1-i)%MOD;
        cnt%=MOD;
    }
    for(ll i=0;i<n;i++){
        ans+=m*cnt%MOD*((i*(i+1)/2+(n-i)*(n-i-1)/2)%MOD)%MOD;
        ans%=MOD;
    }
    const ll inv=(MOD+1)/2;
    ans*=inv;
    ans%=MOD;
    if(ans<0){ans+=MOD;}
    cout<<ans<<endl;
    
    
    return 0;
}


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


int main(){
  int n, m;
  cin >> n >> m;
  vector<vector<int>> v(m,vector<int>(2, 0));
  for(int i = 0; i < m; i++){
      cin >> v[i][0] >> v[i][1];
  }
  int k;
  if(n == 1){k = 0;}
  else{k = pow(10, n-1);}
  for(int i = k; i < pow(10,n); i++){
      string s = to_string(i);
      bool f = true;
      for(int j = 0; j < m; j++){
          if(s[v[j][0]-1] != v[j][1]+48){f = false; break;}
      }
      if(f){cout << i << endl; break;}
      if(f == false && i == pow(10,n) - 1){cout << -1 << endl;}
  }
  
}

Measured memory_bytes: 256
S = str(input())
A = S[0]
for i in range(1, len(S)):
    if A[i-1] == "0":
        A += "1"
    else:
        A += "0"
ans = 0
for i in range(0, len(S)):
    if S[i] != A[i]:
        ans += 1
print(ans)


Measured memory_bytes: 3188
#include<iostream>
#include<cmath>

double dp[1000] = { 0 };

int height(double v) {
	for (int i = 2; i < 1000; i++) {
		if (dp[i] == 0) {
			double t = std::sqrt((5 * i - 5) / 4.9);
			dp[i] = 9.8 * t;
		}
		if (dp[i] >= v) return i;
	}
	return 0;
}

int main() {
	double v;
	while (std::cin >> v) {
		std::cout << height(v) << std::endl;
	}
	return 0;
}


Measured memory_bytes: 3156
//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
typedef int64_t int64;
typedef uint32_t uint;
typedef uint64_t uint64;

//---

template <typename T>
inline void print(const T& rhs){ std::cout<<" = "<<rhs<<std::endl; }
template <typename T>
inline void print(const std::vector<T>& rhs){
    std::cout<<" = [ ";
    for(uint i=0; i<rhs.size(); ++i){ std::cout<<rhs[i]<<' '; }
    std::cout<<"]"<<std::endl;
}
template <typename T>
inline void print(const std::vector<std::vector<T>>& rhs){
    std::cout<<" = "<<std::endl;
    std::cout<<"[[ ";
    for(uint p=0; p<rhs.size(); ++p){
        if(p!=0){ std::cout<<" [ "; }
        for(uint q=0; q<rhs[p].size(); ++q){
            std::cout<<rhs[p][q]<<' ';
        }
        if(p!=rhs.size()-1){ std::cout<<"]"<<std::endl; }
    }
    std::cout<<"]]"<<std::endl;
}
template <typename TL, typename TR>
inline void print(const std::vector<std::pair<TR,TL>>& rhs){
    std::cout<<" = [";
    uint i=0;
    for(; i<rhs.size()-1; ++i){ std::cout<<"[f: "<<rhs[i].first<<", s: "<<rhs[i].second<<"], "; }
    std::cout<<"[f: "<<rhs[i].first<<", s: "<<rhs[i].second<<"]]" << endl;
}
#define printn(var) {printf("%s", #var);print(var);}
#define printn_all(var) {printf("%s(%d): ", __func__, __LINE__);printf("%s", #var);print(var);}

//---

string ssprintf(const char* format, ...){
    va_list args;
    va_start(args, format);
    char* buf;
#ifdef _WIN32
    int len = _vscprintf(format, args)+1;
    buf = (char*)malloc(len * sizeof(char));
    vsprintf_s(buf, len, format, args);
#else
    if(vasprintf(&buf, format, args) == -1){
        return std::string("");
    }
#endif
    std::string ret = buf;
    free(buf);
    va_end(args);
    return ret;
}

int main(){
//    ios_base::sync_with_stdio(false);
//    cin.tie(NULL);
    
    uint N, M; cin >> N >> M;
    vector<pair<int, int>> vPY(M);
    vector<vector<int>> vvPY(N);
    for(uint i=0; i<M; ++i){
        int P, Y; cin >> P >> Y;
        vvPY[P-1].push_back( Y );
        vPY[i].first  = P;
        vPY[i].second = Y;
    }
    for(uint i=0; i<vvPY.size(); ++i){
        sort(vvPY[i].begin(), vvPY[i].end());
    }
    
    unordered_map<string, string> ht;
    for(uint pi=0; pi<vvPY.size(); ++pi){
        for(uint yi=0; yi<vvPY[pi].size(); ++yi){
            int P = pi+1;
            int Y = vvPY[pi][yi];
            string key = ssprintf("%06d%06d", P, Y   ); // input
            string val = ssprintf("%06d%06d", P, yi+1); // output
            ht[key] = val;
        }
    }
    
    for(uint i=0; i<vPY.size(); ++i){
        int P = vPY[i].first;
        int Y = vPY[i].second;
        string key = ssprintf("%06d%06d", P, Y);
        cout << ht[key] << endl;
    }
    
    return 0;
}

Measured memory_bytes: 22820
#include <iostream>
#include <cmath>
#include <string>
#include <algorithm>
#include <set>
#include <vector>
#include <map>
#include <list>
#include <stack>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <queue>
#define mkp make_pair
#define pr(num) cout << num << "\n"
#define max(a, b) ((a)>(b) ? (a):(b))
#define min(a, b) ((a)<(b) ? (a):(b))
#define INF 1000000000000000000
#define MOD 1000000007LL
#define MAX 100010
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
typedef map<ll, ll> Map;

int main(void) {
    string N;
    ll D;
    cin >> N >> D;
    ll dp[N.size()+5][D+5][2];
    ll i, j, l;
    memset(dp, 0, sizeof(dp));
    dp[0][0][1]=1;
    
    for(i=0; i<N.size(); i++) {
        for(j=0; j<D; j++) {
            
            for(l=0; l<10; l++) {
                dp[i+1][(j+l)%D][0]+=dp[i][j][0];
                dp[i+1][(j+l)%D][0]%=MOD;
            }
            
            for(l=0; l<N[i]-'0'; l++) {
                dp[i+1][(j+l)%D][0]+=dp[i][j][1];
                dp[i+1][(j+l)%D][0]%=MOD;
            }
            
            dp[i+1][(j+N[i]-'0')%D][1]+=dp[i][j][1];
            dp[i+1][(j+N[i]-'0')%D][1]%=MOD;
        }
    }
    
    ll ans=dp[N.size()][0][0]+dp[N.size()][0][1];
    ans--;
    pr((ans+MOD)%MOD);
}


Measured memory_bytes: 16640