akhauriyash/Code-Regression huggingface dataset:
use std::io::Read;

fn run() {
    let mut s = String::new();
    std::io::stdin().read_to_string(&mut s).unwrap();
    let mut it = s.trim().split_whitespace();
    let n: usize = it.next().unwrap().parse().unwrap();
    let mut a = vec![];
    for _ in 0..n {
        let len: usize = it.next().unwrap().parse().unwrap();
        let mut b = vec![];
        for _ in 0..len {
            let x: usize = it.next().unwrap().parse::<usize>().unwrap() - 1;
            let y: usize = it.next().unwrap().parse().unwrap();
            b.push((x, y));
        }
        a.push(b);
    }
    let mut ans = 0;
    for bit in 0..(1 << n) {
        let mut ok = true;
        for i in 0..n {
            let b = (bit >> i) & 1;
            for &(x, y) in &a[i] {
                if b == 1 && (bit >> x) & 1 != y {
                    ok = false;
                }
            }
        }
        if ok {
            ans = std::cmp::max(ans, bit.count_ones());
        }
    }
    println!("{}", ans);
}

fn main() {
    run();
}


Measured memory_bytes: 4352
#include <stdio.h>
#define min(X, Y) ((X) < (Y) ? (X) : (Y))
#define max(X, Y) ((X) > (Y) ? (X) : (Y))
typedef long long ll;

ll sum[100005];

int main()
{
    ll n, m;
    ll l, r;
    ll ans = 0;

    scanf("%lld %lld", &n, &m);
    for (int i = 0; i < m; i++) {
        scanf("%lld %lld", &l, &r);

        sum[l] += 1;
        sum[r + 1] -= 1;
    }

    for (int i = 1; i <= n; i++) {
        sum[i] += sum[i - 1];

        if (sum[i] == m) {
            ans++;
        }
    }

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

    return 0;
}


Measured memory_bytes: 896
// {{{
#include <algorithm>
#include <array>
#include <bitset>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <iostream>
#include <iterator>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <tuple>
#include <utility>
#include <vector>
// }}}

using namespace std;

using ll = long long;
using ull = unsigned long long;
using ld = long double;

static constexpr int mod = (int)1e9 + 7;
static constexpr int inf = 100100100;
static constexpr ll linf = 1e18;
static constexpr double eps = 1e-9;
static constexpr double pi = 3.14159265359;

#define rep(i, n) for (ll i = 0; i < n; ++i)
#define rrep(i, n) for (ll i = n; i >= 0; --i)
#define all(c) begin(c), end(c)
#define rall(c) rbegin(c), rend(c)
#define pb push_back
#define ist insert
#define fst first
#define snd second


int main() {
    // cin.tie(0);
    // ios_base::sync_with_stdio(false);
    char b;
    cin >> b;
    map<char, char> M = {
        {'A', 'T'},
        {'C', 'G'},
        {'G', 'C'},
        {'T', 'A'}
    };
    cout << M[b] << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h> 
#include <cstring>
using namespace std;
//typedef
typedef long long ll;
typedef vector<int> vi;
typedef vector<string> vs;
//define
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n)  FOR(i,0,n)

int main(){
   int n;
   cin >> n ;
   vi a(n);
   rep(i,n) cin >> a.at(i);

   int b[n];
   b[0] = 0;
   FOR(i,0,n){

       b[a.at(i)] = i+1; 
   }
   FOR(i,1,n+1) cout << b[i] << endl;
 return 0;
}

Measured memory_bytes: 1536
#include <bits/stdc++.h>
using namespace std;
pair<int, int> x[1000000];
tuple<int, int, int> y[1000000];
int Hush[1000000], Hush2[1000000], n, a;
char c, T[5] = "HDSC";
int partition(int p, int r)
{
	int X = x[r].second;
	int j = p - 1;
	for (int i = p; i < r; i++)
	{
		if (x[i].second <= X)
		{
			j++;
			swap(x[j], x[i]);
		}
	}
	swap(x[j + 1], x[r]);
	return j + 1;
}
void quicksort(int p, int r)
{
	if (p < r)
	{
		int q = partition(p, r);
		quicksort(p, q - 1);
		quicksort(q + 1, r);
	}
}
int main()
{
	cin >> n;
	for (int i = 0; i < n; i++)
	{
		cin >> c >> a;
		int R = 0;
		for (int j = 0; j < 4; j++)
		{
			if (T[j] == c)
			{
				R = j;
			}
		}
		x[i] = make_pair(R, a);
		y[i] = make_tuple(a, i, R);
	}
	quicksort(0, n - 1);
	sort(y, y + n);
	for (int i = 0; i < n; i++)
	{
		Hush[i] = x[i].second * 100 + x[i].first;
		Hush2[i] = get<0>(y[i]) * 100 + get<2>(y[i]);
	}
	int Stable = 1;
	for (int i = 0; i < n; i++)
	{
		if (Hush[i] != Hush2[i])
		{
			Stable = 0;
		}
	}
	if (Stable == 1)
	{
		cout << "Stable" << endl;
	}
	else
	{
		cout << "Not stable" << endl;
	}
	for (int i = 0; i < n; i++)
	{
		cout << T[x[i].first] << ' ' << x[i].second << endl;
	}
	return 0;
}



Measured memory_bytes: 5732
import math
import fractions
import bisect
import collections
import itertools
import heapq
import string
import sys
import copy
from decimal import *
from collections import deque
sys.setrecursionlimit(10**7)
MOD = 10**9+7
INF = float('inf') #無限大
def gcd(a,b):return fractions.gcd(a,b) #最大公約数
def lcm(a,b):return (a*b) // fractions.gcd(a,b) #最小公倍数
def iin(): return int(sys.stdin.readline()) #整数読み込み
def ifn(): return float(sys.stdin.readline()) #浮動小数点読み込み
def isn(): return sys.stdin.readline().split() #文字列読み込み
def imn(): return map(int, sys.stdin.readline().split()) #整数map取得
def imnn(): return map(lambda x:int(x)-1, sys.stdin.readline().split()) #整数-1map取得
def fmn(): return map(float, sys.stdin.readline().split()) #浮動小数点map取得
def iln(): return list(map(int, sys.stdin.readline().split())) #整数リスト取得
def iln_s(): return sorted(iln()) # 昇順の整数リスト取得
def iln_r(): return sorted(iln(), reverse=True) # 降順の整数リスト取得
def fln(): return list(map(float, sys.stdin.readline().split())) # 浮動小数点リスト取得
def join(l, s=''): return s.join(l) #リストを文字列に変換
def perm(l, n): return itertools.permutations(l, n) # 順列取得
def perm_count(n, r): return math.factorial(n) // math.factorial(n-r) # 順列の総数
def comb(l, n): return itertools.combinations(l, n) # 組み合わせ取得
def comb_count(n, r): return math.factorial(n) // (math.factorial(n-r) * math.factorial(r)) #組み合わせの総数
def two_distance(a, b, c, d): return ((c-a)**2 + (d-b)**2)**.5 # 2点間の距離
def m_add(a,b): return (a+b) % MOD
def print_list(l): print(*l, sep='\n')

def sieves_of_e(n):
    is_prime = [True] * (n+1)
    is_prime[0] = False
    is_prime[1] = False
    for i in range(2, int(n**0.5)+1):
        if not is_prime[i]: continue
        for j in range(i * 2, n+1, i): is_prime[j] = False
    return is_prime

N,A,B = imn()

if (B - A) % 2 == 0:
    print('Alice')
else:
    print('Borys')



Measured memory_bytes: 5940
#include <iostream>
#include <vector>
#include <map>
#include <algorithm>
using namespace std;

string S;

int main() {
    cin >> S;
    string key = "keyence";
    
    if (S.substr(0, key.size()) == key || S.substr(S.size() - key.size(), key.size()) == key) {
        cout << "YES" << endl;
        return 0;
    }
    
    for (int i = 1; i < key.size(); i++) {
        if (S.substr(0, i) == key.substr(0, i) && S.substr(S.size() + i - key.size(), key.size() - i) == key.substr(i, key.size() - i)) {
            cout << "YES" << endl;
            return 0;
        }
    }
    cout << "NO" << endl;
}

Measured memory_bytes: 256
a,b,c = map(int, input().split(" "))
pr=True
count=0
while(a%2==0 and b%2==0 and c%2==0):
    ta,tb,tc=a,b,c
    a=tb/2+tc/2
    b=ta/2+tc/2
    c=ta/2+tb/2
    count += 1
    if ta == a and tb == b and tc == c:
        print(-1)
        pr=False
        break
if pr:
    print(count)

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

typedef long long ll;

int main() {
	int n;
	cin >> n;
	vector<int> v(n);
	for (int i = 0; i < n; ++i) {
		cin >> v[i];
	}
	vector<int> b = v;
	sort(v.begin(),v.end());
	int index1 = 0; 
	int index2 = 0;
	int cnt = 0;
	for (int i = 0; i < n; ++i) {
		if (b[i] != v[i]) {
			if (cnt == 0) {
				index1 = i;
			}else {
				index2 = i;
			}
			cnt++;
		}
	}
	if (cnt == 0) {
		cout << "YES";
	}else if (cnt == 2) {
	    swap(v[index1],v[index2]);
	    if (v == b) {
			cout << "YES";
		}else {
			cout << "NO";
		}
	}else {
		cout << "NO";
	}
}



















Measured memory_bytes: 256
N, M = map(int, input().split())
A = [list(map(int, input().split()))[1:] for _ in range(N)]
chk = {}
for a in A:
    for x in a:
        if x in chk:
            chk[x] += 1
        else:
            chk[x] = 1
print(sum([1 for k, v in chk.items() if v == N]))

Measured memory_bytes: 3060
#include "bits/stdc++.h"
using namespace std;
#define INF 1e9
#define rep(i, n) for (int i = 0; i < n; i++)
#define rep2(i, l, r) for (int i = (l); i < (r); i++)
#define ALL(x) (x).begin(), (x).end()     //昇順
#define RALL(x) (x).rbegin(), (x).rend()  // 降順
#define FOR(i, c) \
  \ for (__typeof((c).begin()) i = (c).begin(); i != (c).end(); ++i)
const long long mod = 1e9 + 7;
typedef long long ll;  // ll とdoubleは違う
typedef priority_queue<int> PQ;
typedef vector<long long> VL;
typedef vector<bool> VB;
typedef vector<int> VI;  // VI a(n);
typedef vector<double> VD;
typedef vector<string> VS;
typedef vector<char> VC;
typedef vector<VS> VSS;
typedef vector<VC> VCC;
typedef vector<VI> VII;  // VII a(n,vector<int>(m)) n * m
typedef vector<VL> VLL;
typedef pair<int, int> PII;
typedef map<int, int> MP;  // MP a;
typedef vector<pair<ll, ll>> PS;

template <class T, class U>  // chmax(max, a);
bool chmax(T &a, U b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T, class U>  // chmin(min,a)
bool chmin(T &a, U b) {
  if (a > b) {
    a = b;
    return 1;
  }
  return 0;
}
template <typename T>  // operator << (cout,a);
ostream &operator<<(ostream &os, vector<T> &v) {
  os << "{";
  rep(i, (int)v.size()) { os << v[i] << (i < v.size() - 1 ? ", " : ""); }
  os << "}";
  return os;
}

// g++ -std=c++11 prac.cpp

int main() {
  ll x=0,y=0,z=0,k,n,m,h,w,sum=0,ans=0,Max=-1e9,Min=1e9+1;
  string s,t,u;
  bool ok = false;
  cin >> x>> y>>z;
  VI a(10);
  a[x]++;
  a[y]++;
  a[z]++;
  rep(i,10){
    if(a[i]>=1){
      ans++;
    }
  }
  if(ans==2)
    cout << "Yes" << endl;
  else
  cout << "No" << endl;
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long
#define ull unsigned long long
#define iterator IT
#define SIZ(V) V.size()
#define FS(a) fixed<<setprecision(a)
using namespace std;
namespace STARTER {
	int MAX(int a,int b) {
		return a>b?a:b;
	}
	int MIN(int a,int b) {
		return a<b?a:b;
	}
	int ABS(int a) {
		return a<0?-a:a;
	}
	int GCD(int a,int b) {
		return !b?a:GCD(b,a%b);
	}
	int LCM(int a,int b) {
		return a/GCD(a,b)*b;
	}
	int QSM(int a,int b,int p) {
		int ret=1;
		while (b) {
			if (b&1)
				ret=ret*a%p;
			a=a*a%p;
			b>>=1;
		}
		return ret;
	}
	int ROUND(double a) {
		return a+0.5;
	}
}
using STARTER::MAX;
using STARTER::MIN;
using STARTER::ABS;
using STARTER::GCD;
using STARTER::LCM;
using STARTER::QSM;
using STARTER::ROUND;
int main() {
	int n,r;
	cin>>n>>r;
	if (n>=10)
		cout<<r<<'\n';
	else
		cout<<r+100*(10-n)<<'\n';
	return 0;
}


Measured memory_bytes: 256
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cassert>
#include <climits>
#include <vector>
#include <string>
#include <map>
#include <algorithm>
#include <numeric>
using namespace std;

#define REP(i, n) for (int i = 0; i < (int)(n); ++i)
#define FOR(i, a, b) for (int i = (a); i < (int)(b); ++i)
#define FOREACH(i, c) for (__typeof((c).begin()) i = (c).begin(); i != (c).end(); ++i)

const int dy[] = {-1, 0, 1, 0};
const int dx[] = {0, -1, 0, 1};
double prob[20][3][3];

int main()
{
  int n;
  while (scanf("%d", &n), n) {
    memset(prob, 0, sizeof(prob));
    char cs, ct, cb;
    scanf(" %c %c %c", &cs, &ct, &cb);
    int s = cs - 'A', t = ct - 'A', b = cb - 'A';
    prob[0][s / 3][s % 3] = 1.0;
    for (int i = 0; i < n; ++i) {
      for (int y = 0; y < 3; ++y) {
        for (int x = 0; x < 3; ++x) {
          for (int d = 0; d < 4; ++d) {
            int ny = y + dy[d];
            int nx = x + dx[d];
            if (ny < 0 || ny >= 3 || nx < 0 || nx >= 3) { ny = y; nx = x; }
            if (ny == b / 3 && nx == b % 3) { ny = y; nx = x; }
            prob[i+1][ny][nx] += 0.25 * prob[i][y][x];
          }
        }
      }
    }
    printf("%.9lf\n", prob[n][t / 3][t % 3]);
  }
}

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

typedef long long LL;

LL t,n,m,ans,tot;
LL f[111],g[111];

int main()
{
	LL i,j,k,l,ca=0,u,v,w;
	cin>>n;
	for(i=1;ans<n;i++){
		ans+=i;
	}
	cout<<i-1<<endl;
	return 0;
 } 

Measured memory_bytes: 256
#![allow(unused_mut)]
#![allow(non_snake_case)]
#![allow(unused_imports)]
use std::collections::HashSet;
use std::collections::HashMap;
use std::collections::BTreeSet;
use std::collections::VecDeque;
use std::cmp::{max, min};
// https://qiita.com/tanakh/items/0ba42c7ca36cd29d0ac8
#[allow(unused_macros)]
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
    ($($r:tt)*) => {
        let s = {
            use std::io::Read;
            let mut s = String::new();
            std::io::stdin().read_to_string(&mut s).unwrap();
            s
        };
        let mut iter = s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
}

#[allow(unused_macros)]
macro_rules! input_inner {
    ($iter:expr) => {};
    ($iter:expr, ) => {};

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

#[allow(unused_macros)]
macro_rules! read_value {
    ($iter:expr, ( $($t:tt),* )) => {
        ( $(read_value!($iter, $t)),* )
    };

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

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

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

    ($iter:expr, $t:ty) => {
        $iter.next().unwrap().parse::<$t>().expect("Parse error")
    };
}
fn main() {
    input! {
        n: usize,
        ab: [(i64, i64); n],
    }
    let mut ab = ab;
    ab.sort_by_key(|x| x.1);
    let mut sum = 0;
    for m in ab {
        sum += m.0;
        if sum <= m.1 {
        } else {
            println!("No");
            return;
        }
    }
    println!("Yes");
}

Measured memory_bytes: 13560
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll ZERO = 0;
const int Inf = 1000000000;
const ll INF= 1e18;
const ll MOD = 1000000007;
const double PI = 3.1415926535897;
typedef pair<ll,ll> P;

int main() {
    int N,M;
    cin >> N >> M;
    vector<pair<int,int>> vec(M);
    for(int i = 0;i < M;i++) {
        cin >> vec.at(i).first >> vec.at(i).second;
    }
    sort(vec.begin(),vec.end());
    int l = 0;
    int r = Inf;
    int ret = 1;
    for(int i = 0;i < M;i++) {
        l = max(l,vec.at(i).first);
        r = min(r,vec.at(i).second);
        if(l >= r) {
            ret++;
            l = vec.at(i).first;
            r = vec.at(i).second;
        }
    }
    cout << ret << endl;
}

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

int main() {
	ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
	char c; cin >> c;
	if (c == 'A' || c == 'T') {
		c ^= 'A' ^ 'T';
	} else {
		c ^= 'C' ^ 'G';
	}
	cout << c << '\n';

	return 0;
}


Measured memory_bytes: 256
#ifndef BZ
#pragma GCC optimize "-O3"
#endif
#include <bits/stdc++.h>

#define FASTIO
#define ALL(v) (v).begin(), (v).end()
#define rep(i, l, r) for (int i = (l); i < (r); ++i)

#ifdef FASTIO
#define scanf abacaba
#define printf abacaba
#endif

typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;

using namespace std;


/*
ll pw(ll a, ll b) {
	ll ans = 1; while (b) {
		while (!(b & 1)) b >>= 1, a = (a * a) % MOD;
		ans = (ans * a) % MOD, --b;
	} return ans;
}
*/

int main() {
#ifdef FASTIO
	ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);
#endif
	ll a, b, c;
	cin >> a >> b >> c;
	cout << b + min(c, a + b + 1) << "\n";
	return 0;
}




Measured memory_bytes: 256
#include <cstdlib>
#include <iostream>
#include <string>
#include <time.h>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <sstream>
#include <iomanip>
#include <vector>
#include <functional>
#include <numeric>
#include <cassert>
#include <algorithm>
#include <functional>
//#include "bits/stdc++.h"
using namespace std;
//using namespace std::vector;
#define rep(i,a,b) for(ll i=(a);i<(b);++i)

#define huge 1000000007
typedef long long int ll;
ll gcd(ll a, ll b);
ll bur(ll N, ll X);


int main(void) {

	ll N = 0;
	ll A = 0;
	ll B = 0;
	ll C = 0;
	ll D = 0;
	ll X = 0;
	//ll T = 0;
	//ll M = 0;
	ll h[1000] = {};
	//ll b[100] = {};
	//ll c[100] = {};
	//ll d[100] = {};

	//ll v[3] = {};
	//ll *c, *s, *n;
	string S,T,U[52];
	ll count = 0;
	ll count2 = 0;
	float sum = 0;
	ll min = 1000000000000;
	ll max = 0;
	ll smax = 0;
	ll max2 = 0;
	ll smax2 = 0;
	int tmax = 0;
	int tmax2 = 0;
	//int flag = 0;
	char temp,head;
	//int is = 0;
	bool flag = false;
	
	//char p;

	ll all = 0;
	ll niku = 0;
	ll state = 2;
	bool down = true;
	

	//cin >> S;
	
	//vector<pair<int,int>> ch(50);
	
	

	cin >> A >> B;

	if (A == 1)
		A = 14;

	if (B == 1)
		B = 14;

	if(A>B)
	cout << "Alice" << endl;
	else if(B>A)
		cout << "Bob" << endl;
	else
	cout << "Draw" << endl;


	//x = (ll *)malloc((N+1) * sizeof(ll));
	//c = (ll *)malloc((N) * sizeof(ll));
	//cin >> D >> G;
	//vector<pair<int,int>> tr(M);
	//vector<pair<int,int>> qes(Q);
	//sort(c.begin(), c.end());
	
	//cout << c[2] - c[1] << endl;

	
	/*A = N / 1000;
	N %= 1000;
	B = N / 100;
	N %= 100;
	C = N / 10;
	N %= 10;
	D = N;*/
	


	//cin >> N >> M;

	//vector<pair<int,int>> c(M);
	////vector<pair<int, int>> e(M);
	//vector<ll> d(M);

	//rep(i, 0, M) {
	//	cin >> c[i].first >> c[i].second;
	//	//e[i].first = c[i].first;
	//	//e[i].second = c[i].second;

	//}
	////sort(c.begin(), c.end());

	//

	//rep(i, 0, M) {

	//	
	//	
	//	rep(j, 0, M) {
	//		if (c[i].first == c[j].first && c[j].second < c[i].second) {
	//			d[i]++;
	//			//cout << j << endl;
	//		}
	//	}
	//	cout << std::setfill('0') << std::right << std::setw(6) << c[i].first;
	//	cout << std::setfill('0') << std::right << std::setw(6) << d[i]+1 << endl;
	//}

	return 0;

}

ll bur(ll N,ll X) {
	ll pan = 1;
	ll pat = 1;
	ll burg = 0;



	if (X > burg) {
		if (N == 0)
			return pat;


		burg += pan;
		burg += bur(N - 1, X);
		burg += pat;
		burg += bur(N - 1, X);
		burg += pan;


	}

	return burg;

}

ll gcd(ll a, ll b) {
	
	/* 自然数 a > b を確認・入替 */
	if (a<b) {
		ll tmp = a;
		a = b;
		b = tmp;
	}
	ll x = b;
	ll y = a;
	/* ユークリッドの互除法 */
	ll r = a % b;
	while (r != 0) {
		a = b;
		b = r;
		r = a % b;
	}


	return y/b*x;
}



Measured memory_bytes: 256
import java.util.*;
import static java.util.Arrays.*;
import static java.lang.Math.*;
public class Main {

	static Scanner sc = new Scanner(System.in);
	
	public static void main(String[] args) {
		while (read())
			solve();
	}
	
	static final int INF = 10000000;
	static int N, M, K;
	static int[] P = new int[200], Q  = new int[200], R  = new int[200];
	static int[][] cost = new int[101][101], time = new int[101][101];
	static boolean read() {
		N = sc.nextInt(); M = sc.nextInt();
		if (N == 0 && M == 0) return false;
		for (int i = 0; i < 101; i++) {
			fill(cost[i], INF);
			fill(time[i], INF);
			cost[i][i] = time[i][i] = 0;
		}
		
		for (int i = 0; i < N; i++) {
			int a = sc.nextInt(), b  = sc.nextInt(), c  = sc.nextInt(), t = sc.nextInt();
			cost[a][b] = cost[b][a] = c;
			time[a][b] = time[b][a] = t;
		}
		
		K = sc.nextInt();
		for (int i = 0; i < K; i++) {
			P[i] = sc.nextInt();
			Q[i] = sc.nextInt();
			R[i] = sc.nextInt();
		}
		
		return true;
	}

	static void solve() {
		for (int k = 1; k <= M; k++) { 
			for (int i = 1; i <= M; i++) {
				for (int j = 1; j <= M; j++) {
					time[i][j] = min(time[i][j], time[i][k] + time[k][j]);
					cost[i][j] = min(cost[i][j], cost[i][k] + cost[k][j]);
				}
			}
		}
		
		for (int i = 0; i < K; i++) {
			if (R[i] == 0) 
				System.out.println(cost[P[i]][Q[i]]);
			else 
				System.out.println(time[P[i]][Q[i]]);
		}
	}	
}

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

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

Measured memory_bytes: 3592
K = int(input())

def is_lunlun(i):
    result = -1
    n = [ord(c) -48 for c in str(i)]
    for j in range(len(n) - 1):
        if abs(n[j] - n[j + 1]) <= 1:
            continue
        if n[j] < n[j + 1]:
            for k in range(j + 1, len(n)):
                n[k] = 0
            result = int(''.join(str(k) for k in n))
            result += 10 ** (len(n) - (j + 1))
        else:
            result = int(''.join(str(k) for k in n))
            result += 10 ** (len(n) - (j + 2))
        break
    return result

i = 1
while True:
    #print(i)
    t = is_lunlun(i)
    if t == -1:
        K -= 1
        if K == 0:
            print(i)
            exit()
        i += 1
    else:
        i = t


Measured memory_bytes: 3064
import std.stdio, std.algorithm, std.conv, std.array, std.string, std.math, std.typecons, std.numeric, std.container, std.range;

void get(Args...)(ref Args args)
{
    import std.traits, std.meta, std.typecons;

    static if (Args.length == 1) {
        alias Arg = Args[0];
        
        static if (isArray!Arg) {
            args[0] = readln.split.to!Arg;
        } else static if (isTuple!Arg) {
            auto input = readln.split;
            static foreach (i; 0..Fields!Arg.length) {
                args[0][i] = input[i].to!(Fields!Arg[i]);
            }
        } else {
            args[0] = readln.chomp.to!Arg;
        }
    } else {
        auto input = readln.split;
        assert(input.length == Args.length);

        static foreach (i; 0..Args.length) {
            args[i] = input[i].to!(Args[i]);
        }
    }
}

void get_lines(Args...)(size_t N, ref Args args)
{
    import std.traits, std.range;

    static foreach (i; 0..Args.length) {
        static assert(isArray!(Args[i]));
        args[i].length = N;
    }

    foreach (i; 0..N) {
        static if (Args.length == 1) {
            get(args[0][i]);
        } else {
            auto input = readln.split;
            static foreach (j; 0..Args.length) {
                args[j][i] = input[j].to!(ElementType!(Args[j]));
            }
        }
    }
}

alias P = Tuple!(int, "x", int, "y");

void main()
{
    int H, W, N; get(W, H, N);
    P[] ps; get_lines(N, ps);
    sort!"a.x < b.x"(ps);
    auto MAP = new int[][H];
    foreach (p; ps) {
        MAP[p.y-1] ~= p.x-1;
    }
    foreach (ref L; MAP) L ~= W;

    int x, res = W;
    foreach (y, L; MAP) {
        int r_limit;
        if (L[0] > x) {
            res = min(res, L[0]);
            r_limit = L[0];
        } else {
            int l, r = L.length.to!int-1;
            while (l+1 < r) {
                auto m = (l+r)/2;
                if (L[m] < x) {
                    l = m;
                } else {
                    r = m;
                }
            }
            res = min(res, L[r]);
            r_limit = L[r];
        }

        if (x+1 == r_limit) break;
        ++x;

        if (y < H-1) {
            auto LL = MAP[y+1];
            int l, r = LL.length.to!int-1;
            if (LL[0] >= x) {
                r = 0;
            } else {
                while (l+1 < r) {
                    auto m = (l+r)/2;
                    if (LL[m] < x) {
                        l = m;
                    } else {
                        r = m;
                    }
                }
            }
            while (r < LL.length && x < r_limit && LL[r] == x) {
                ++x;
                ++r;
            }
            if (x == r_limit) break;
        }
    }
    writeln(res);
}

Measured memory_bytes: 11560
"use strict";
var GET=(function(){function f(s){return new g(s);}function g(s){this._s=s.trim().split("\n");this._y=0;}g.prototype.a=function(f){var s=this._s, y=this._y, r;if(typeof s[y]==="string")s[y]=s[y].split(" ").reverse();r=s[y].pop();if(!s[y].length)this._y++;return f?r:+r;};g.prototype.l=function(f){var s=this._s[this._y++].split(" ");return f?s:s.map(a=>+a);};g.prototype.m=function(n,f){var r=this._s.slice(this._y,this._y+=n).map(a=>a.split(" "));return f?r:r.map(a=>a.map(a=>+a));};g.prototype.r=function(n,f){var r=this._s.slice(this._y,this._y+=n);return f?r:r.map(a=>+a);};return f;})();
var o=GET(require("fs").readFileSync("/dev/stdin","utf8"));
function xArray(v){var a=arguments,l=a.length,r="Array(a["+--l+"]).fill(0).map(x=>{return "+v+";})";while(--l)r="Array(a["+l+"]).fill(0).map(x=>"+r+")";return eval(r);}
function abs(a){return Math.abs(a);}
function max(a,b){return Math.max(a,b);}

console.log(main());
function main(){
  var h = o.a();
  var w = o.a();
  var a = o.m(h);
  var b = o.m(h);
  var dp = [];
  var t = abs(a[0][0]-b[0][0]);
  dp[0] = Array(t+1);
  dp[0][t] = 1;
  var x,y;
  for(x = 1; x < w; x++){
    var u = dp[x-1].length;
    t = abs(a[0][x]-b[0][x]);
    dp[x] = Array(u+t);
    while(u--){
      if(dp[x-1][u] !== 1)continue;
      dp[x][u+t] = 1;
      if(t < u)dp[x][u-t] = 1;
      else dp[x][t-u] = 1;
    }
  }
  for(y = 1; y < h; y++){
    var dp2 = [];
    var u = dp[0].length;
    t = abs(a[y][0]-b[y][0]);
    dp2[0] = Array(u+t);
    while(u--){
      if(dp[0][u] !== 1)continue;
      dp2[0][u+t] = 1;
      if(t < u)dp2[0][u-t] = 1;
      else dp2[0][t-u] = 1;
    }
    for(x = 1; x < w; x++){
      var u = max(dp[x].length,dp2[x-1].length);
      t = abs(a[y][x]-b[y][x]);
      dp2[x] = Array(u+t);
      while(u--){
        if(dp[x][u] !== 1 && dp2[x-1][u] !== 1)continue;
        dp2[x][u+t] = 1;
        if(t < u)dp2[x][u-t] = 1;
        else dp2[x][t-u] = 1;
      }
    }
    dp = dp2;
  }
  for(var i = 0; 1; i++){
    if(dp[w-1][i])return i;
  }
}

Measured memory_bytes: 83520
#include <vector>
#include <algorithm>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <cstdio>
#include <cmath>
#include <cstring>
using namespace std;
int n,x;
char s[8];
int main()
{for(;;){
	scanf("%d",&n);
	if(!n) return 0;
	int ans=1;
	int dice[6]={1,2,3,5,4,6};
	for(int i=0;i<n;i++){
		scanf("%s",s);
		if(strcmp(s,"North")==0){
			x=dice[0];
			dice[0]=dice[1];
			dice[1]=dice[5];
			dice[5]=dice[3];
			dice[3]=x;
		}
		else if(strcmp(s,"South")==0){
			x=dice[0];
			dice[0]=dice[3];
			dice[3]=dice[5];
			dice[5]=dice[1];
			dice[1]=x;
		}
		else if(strcmp(s,"East")==0){
			x=dice[0];
			dice[0]=dice[4];
			dice[4]=dice[5];
			dice[5]=dice[2];
			dice[2]=x;
		}
		else if(strcmp(s,"West")==0){
			x=dice[0];
			dice[0]=dice[2];
			dice[2]=dice[5];
			dice[5]=dice[4];
			dice[4]=x;
		}
		else if(strcmp(s,"Right")==0){
			x=dice[1];
			dice[1]=dice[2];
			dice[2]=dice[3];
			dice[3]=dice[4];
			dice[4]=x;
		}
		else{
			x=dice[1];
			dice[1]=dice[4];
			dice[4]=dice[3];
			dice[3]=dice[2];
			dice[2]=x;
		}
		ans+=dice[0];
	}
	printf("%d\n",ans);
}}

Measured memory_bytes: 1032
#!/usr/bin/env python3
# -*- coding: utf-8 -*-

import array
from bisect import *
from collections import *
import fractions
import heapq 
from itertools import *
import math
import re
import string

N = int(input())
D = map(int, input().split())
c = Counter(D)

M = int(input())
T = map(int, input().split())

ok = True
for t in T:
    if c[t] > 0:
        c[t] -= 1
    else:
        ok = False
        break
if ok:
    print("YES")
else:
    print("NO")






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

int main(){
  int a;
  cin >> a;
  bool ans = false;
  for (int i = 1; i <= 9; i++) {
    if (a%i == 0) {
      for (int j = 1; j <= 9; j++) {
        if (a/i == j) {
          ans = true;
        }
      }
    }
  }
  if (ans) cout << "Yes" << endl;
  else cout << "No" << endl;
}

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

using namespace std;

template<class Abel> struct Union_Find_Weight
{
	vector<int> par;
	vector<Abel> diff_weight;
	int n;
	Union_Find_Weight(int a, Abel SUM_UNITY = 0) {init(a, SUM_UNITY);}
	void init(int a, Abel SUM_UNITY) {
		n = a;
		par.resize(n, -1);
		diff_weight.resize(n, SUM_UNITY);
	}
	int root(int x) {
		if (par[x] < 0) return x;
		int r = root(par[x]);
		diff_weight[x] += diff_weight[par[x]];
		return par[x] = r;
	}
	Abel weight(int x) {
		root(x);
		return diff_weight[x];
	}
	Abel diff(int x, int y) {
		return weight(y) - weight(x);
	}
	bool same(int x, int y) {
		return root(x) == root(y);
	}
	bool unite(int x, int y, Abel w) {
// weight(y) - weight(x) = w
		w += weight(x);
		w -= weight(y);
		x = root(x);
		y = root(y);
		if (x == y) return false;
		if (size(x) < size(y)) swap(x, y), w = -w;
		par[x] += par[y];
		par[y] = x;
		diff_weight[y] = w;
		return true;
	}
	int size(int x) {
		x = root(x);
		return -par[x];
	}
};

int main()
{
	int n, m;
	cin >> n >> m;
	Union_Find_Weight<int> uf(n+1);
	while (m--) {
		int l, r, d;
		cin >> l >> r >> d;
		if (!uf.unite(l, r, d)) {
			if (uf.diff(l, r) != d) {
				cout << "No" << endl;
				return 0;
			}
		}
	}
	cout << "Yes" << endl;
}


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

int main()
{
	int a[333] = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 1, 1, 1, 1, 0, 0, 0, 1, 0, 1, 1, 1, 0, 1, 0, 0, 0, 0, 0, 1, 0, 1, 0, 1, 0, 0, 0, 1, 0, 0, 0, 0, 1, 1, 0, 0, 0, 0, 1, 0, 0, 1, 0, 0, 1, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 0, 1, 1, 1, 1, 1, 0, 0, 1, 0, 1, 1, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 1, 1, 1, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 1, 0, 0, 1, 1, 1, 0, 0, 1, 1, 0, 1, 0, 1, 0, 0, 0, 1, 1, 1, 0, 0, 1, 1, 1, 1, 1, 1, 0, 1, 0, 0, 0, 0, 0, 1, 1, 1, 0, 0, 1, 1, 0, 0, 1, 0, 0, 0, 1, 1, 0, 0, 1, 0, 0, 0, 0, 1, 1, 1, 1, 0, 0, 1, 0, 0, 1, 1, 0, 1, 0, 0, 0, 0, 1, 1, 0, 1, 0, 1, 1, 1, 0, 0, 1, 1, 1, 1, 1, 0, 1, 1, 0, 0, 0, 0, 1, 1, 0, 0, 1, 0, 1, 0, 0, 1, 1, 0, 1, 0, 0, 1, 0, 0, 1, 0, 1, 1, 0, 1, 0, 1, 1, 0, 0, 1, 0, 0, 1, 0, 0, 1, 0, 0, 1};

	string s;
	cin >> s;

	int n = s.size();

	int nxt[500][n];
	for (int j = 0; j < n; j++)
	{
		nxt[0][j] = j + ((s[j] == 'R') ? 1 : -1);
	}

	for (int i = 1; i < 500; i++)
	{
		for (int j = 0; j < n; j++)
		{
			nxt[i][j] = nxt[i - 1][nxt[i - 1][j]];
		}
	}

	vector<int> cnt(n, 0);

	for (int t = 0; t < n; t++)
	{
		int p = t;
		for (int x = 0; x < 333; x++)
		{
			if (a[x])
			{
				p = nxt[x][p];
			}
		}
		cnt[p]++;
	}

	for (auto &ans : cnt)
	{
		cout << ans << ' ';
	}
	cout << endl;

	return 0;
}

Measured memory_bytes: 196352
#include <cstdlib>
#include <cmath>
#include <stdio.h>
#include <iostream>
#include <algorithm>
#include <vector>
#include <stack>
#include <queue>
#include <cstring>
#include <string>
#include <map>
#include <list>
#define MOD 1000000007
#define INF 1000000000
typedef long long ll;
using namespace std;
typedef pair<int,int> P;

int main(void){
    string x,y;
    cin>>x>>y;
    if(x<y)cout<<"<"<<endl;
    else if(x>y)cout<<">"<<endl;
    else cout<<"="<<endl;
    
    return 0;
}


Measured memory_bytes: 384
#include<iostream>
using namespace std;
int main(){
  int n;
  cin >> n;
  for (int i=0;i*7<=n;i++){
    for(int j=0;j*4+i*7<=n;j++){
      if(i*7+j*4 == n) {
	cout << "Yes" << endl;
	return 0;
      }
    }
  }
  cout << "No" << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
using namespace std;
int
main ()
{
  int h, w, w2;
  while (true)
    {
      cin >> h >> w;
      if (h == 0 && w == 0)
	exit (0);
      w2 = w;
      while (h-- > 0)
	{
	  w = w2;
	  while (w-- > 0)
	    cout << "#";
	  cout << endl;
	}
          cout << endl;
    }
}

Measured memory_bytes: 1152
#include<bits/stdc++.h>
using namespace std;
 
#define int long long int
#define ff first
#define ss second
#define pb push_back
 
int bexp(int a, int b, int mod)
{
    int res = 1;
    if (mod <= 0)
        return 0;
 
    while (b)
    {
        if (b & 1) res = (res * a) % mod;
 
        a = (a * a) % mod; 
        b >>= 1;
    }
    return res;
}
 
#define N 300010
#define MOD 1000000007
 
int gcd(int a, int b)
{
    if (b == 0)
        return a;
    return gcd(b, a % b);
}

struct comp {
    bool operator() (const pair<int, int> a, const pair<int, int> b) const
    {
        return a.ss * (a.ff - a.ff / 2) > b.ss * (b.ff - b.ff / 2);
    }
};

int32_t main()
{
    ios::sync_with_stdio(false);
    cin.tie(NULL);
    cout.precision(10);

    int n;
    cin >> n;

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

    int ans = 0;

    for (int i = 0; i < n; ++i)
    {
        ans = (ans + a[i] * (c[n] - c[i + 1] + MOD) % MOD) % MOD;
    }

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

Measured memory_bytes: 6788
#include <iostream>

using namespace std;

typedef long long ll;
#define x first
#define y second
#define mp make_pair

ll x, y;

int main(){
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
cin >> x >> y;
if(x == 1 || y == 1){
	cout << 1 << endl;
}
else{
	cout << (x * y + 1) / 2LL << endl;
}

return 0;
}



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

#define rep(i,n) for(int i = 0; i < (n); i++)
#define rrep(i,n) for(int i = (n)-1; i >= 0; i--)
#define rep1(i,n) for(int i = 1; i <= (n); i++)
#define rrep1(i,n) for(int i = (n); i > 0; i--)

#define ll long long
#define pi pair<int, int>
#define pll pair<ll, ll>

#define MOD 1000000007
#define INF 1000000000000000LL

using namespace std;

#define MAXN 200001

ll dp[MAXN+1];
int h[MAXN+1];
int a[MAXN+1];
ll bit[MAXN+1];
pi flowers[MAXN+1];

void set_val(int idx, ll val){
  idx++;
  while(idx<MAXN+1){
    bit[idx] = max(bit[idx], val);
    idx += idx & -idx;
  }
}

ll max_val(int idx){
  ll res=0;
  idx++;
  while(idx){
    res = max(res, bit[idx]);
    idx -= idx & -idx;
  }
  return res;
}

int main(){
  int n;cin>>n;
  rep(i, n)cin>>h[i];
  rep(i, n)cin>>a[i];
  rep(i, n){
    flowers[i].first = h[i];
    flowers[i].second = i;
  }
  sort(flowers, flowers+n);

  ll ans=0;
  rep(i, n){
//cout<<flowers[i].first<<' '<<flowers[i].second<<endl;
    int ci = flowers[i].second;
    dp[ci] = max_val(ci-1)+a[ci];
    set_val(ci, dp[ci]);
    ans = max<ll>(ans, dp[ci]);
//cout<<ans<<endl;

  }

  cout<<ans<<endl;

  return 0;
}


Measured memory_bytes: 9864
#include <iostream>
#include<string>
#include<cmath>
#include<algorithm>
#include<cctype>
#include<queue>
#include<deque>
#include<regex>
#include<stack>
#include<stdio.h>
#include<vector>
#include<set>
#include<map>
#include<iomanip>

#define rep(i, n) for(int i=0;i<n;i++)

typedef int long long ll;
using namespace std;
typedef pair<int, int> P;
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};
const ll MOD = 1e9 + 7;
static const int MAX = 100;
static const int INF = (1 << 23);

int main() {
    int n;
    cin>>n;
    vector<int> v1;
    vector<int> v2;
    map<int,int> vv1;
    map<int,int> vv2;
    set<int> s;
    rep(i,n){
        int a;
        cin>>a;
        s.insert(a);
        if(i%2){
            v1.push_back(a);
            vv1[a]++;
        }else{
            v2.push_back(a);
            vv2[a]++;
        }
    }

    if(s.size()==1){
        cout<<n/2<<endl;return 0;
    }



    vector<pair<int,int>> a1;
    vector<pair<int,int>> b1;

    for(auto &&a:vv1){
        a1.push_back({a.second,a.first});
       // cout<<a.second<<a.first<<endl;
    }
    for(auto &&a:vv2){
        b1.push_back({a.second,a.first});
       // cout<<a.second<<a.first<<endl;
    }

    sort(a1.rbegin(),a1.rend());
    sort(b1.rbegin(),b1.rend());


    int od[2]={INF,INF};
    int ev[2]={INF,INF};
    od[0]=a1[0].second;ev[0]=b1[0].second;
    if(a1.size()!=1)od[1]=a1[1].second;
    if(b1.size()!=1)ev[1]=b1[1].second;

    int ans=INF;
    rep(i,2){//od
        rep(j,2){//ev
            if(od[i]!=INF&&ev[j]!=INF&&od[i]!=ev[j]){
                int q=v1.size()-a1[i].first;
                q+=v2.size()-b1[j].first;
                ans=min(ans,q);

            }

        }
    }
cout<<ans<<endl;















    return 0;
}


Measured memory_bytes: 11124
#include <iostream>
#include <climits>
#include <cmath>
#include <algorithm>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <string>
#include <deque>
#define INF_INT (INT_MAX / 2)
#define INF_LONG (LONG_MAX / 2)
//#define DEBUG true
#define DEBUG false
using namespace std;

typedef long long ll;
typedef pair< int, int > pii;
typedef pair< ll, ll > pll;
typedef pair< ll, int > pli;
typedef pair< int, ll > pil;

int ceil(int x, int y){
  return (x % y == 0) ? x / y : x / y + 1;
}

int gcd(int x, int y){
  return y ? gcd(y, x % y) : x;
}

int lcm(int x, int y){
  return x / gcd(x, y) * y;
}

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

  int n, sx;
  cin >> n >> sx;
  int x[n];
  for(int i = 0; i < n; i++) cin >> x[i];

  int y[n + 1];
  for(int i = 0; i < n; i++){
    y[i] = x[i];
  }
  y[n] = sx;

  sort(y, y + n + 1);

  int ans = y[1] - y[0];
  for(int i = 1; i + 1 < n + 1; i++){
    ans = gcd(ans, y[i + 1] - y[i]);
  }

  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 1024
#define _GLIBCXX_DEBUG
// header {{{
#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 f80 = __float80;
// }}}
constexpr i64 INF = 1'010'000'000'000'000'017LL;
constexpr i64 MOD = 1'000'000'007LL;
constexpr f64 EPS = 1e-12;
constexpr f64 PI = 3.14159265358979323846;
// util {{{
#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;
}
// }}}

// init {{{
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;
// }}}

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

signed main() {
    int n,d;
    cin>>n>>d;
    vector<vector<int>> x(n,vector<int>(d));
    REP(i,n){
        REP(r,d){
            cin>>x[i][r];
        }
    }
    int sum = 0;

    REP(i,n){
        FOR(j,i+1,n){
            int d2 = 0;
            REP(r,d){
                d2 += pow(x[i][r]-x[j][r],2);
            }
            REP(k,40*40*10){
                if(k*k==d2){
                    sum++;
                    break;
                }
            }
           
        }

    }
    cout<<sum<<endl;

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

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

using namespace std;

int main(void) {
	int n;
	cin >> n;
	vector<int> in(n);
	for (int i = 0; i < n; ++i) {
		cin >> in[i];
	}
	int min = in[0];
	int max = in[0];
	long long sum = in[0];
	for (int i = 1; i < n; ++i) {
		if (min > in[i]) {
			min = in[i];
		}
		if (max < in[i]) {
			max = in[i];
		}
		sum += in[i];
	}
	cout << min << " " << max << " " << sum << endl;

	return 0;
}


Measured memory_bytes: 3124
#include <iostream>
#include <string>
#include <algorithm>
using namespace std;

int main()
{
    string s;
    cin >> s;
    int n = s.length();
    string f = s.substr(0, (n - 1) / 2), b = s.substr((n + 3) / 2 - 1, (n - 1) / 2);
    // cout << f << ' ' << b << endl;
    string _f = f, _b = b, _s = s;
    reverse(f.begin(), f.end());
    reverse(b.begin(), b.end());
    reverse(s.begin(), s.end());
    if (f == _f && b == _b && s == _s)
    {
        cout << "Yes\n";
        return 0;
    }
    cout << "No\n";
    return 0;
}


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

def main():
    n,q = map(int,input().split())
    edges = [list(map(int,input().split())) for _ in range(n-1)]
    px = [list(map(int,input().split())) for _ in range(q)]

    count = [0]*n
    ans = [0]*n
    visit = [False] * n
    visit[0] = True

    roots = [[] for _ in range(n)]

    for a,b in edges:
        roots[a-1].append(b-1)
        roots[b-1].append(a-1)

    for p,x in px:
        count[p-1] += x

    q = [0]

    ans[0] = count[0]

    while q:
        label = q.pop(-1)
        for i in roots[label]:
            if not visit[i]:
                ans[i] += ans[label] + count[i]
                visit[i] = True
                q.append(i)


    for i in ans:
        print(i,end = ' ')

if __name__ == '__main__':
    main()


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

typedef long long ll;
typedef long double ld;
typedef vector<ll> vi;
typedef pair<ll, ll> pii;
typedef vector<pii> vii;
typedef map<ll, ll> mii;
const int MOD = 1e9 + 7;

#define fastIO \
ios_base::sync_with_stdio(false); cin.tie(nullptr);
#define endl "\n"
#define pb push_back
#define ff first
#define ss second
#define mp make_pair 

int main() {
    fastIO;
    string s;
    cin >> s;
    for (auto c : s)    if (c == '7')   {cout << "Yes" << endl; return 0;}
        cout << "No" << endl;
    return 0;
}


Measured memory_bytes: 3612
#![allow(non_snake_case)]
#![allow(unused_variables)]
#![allow(dead_code)]

fn main() {
    let (N, u, v): (usize, usize, usize) = {
        let mut line: String = String::new();
        std::io::stdin().read_line(&mut line).unwrap();
        let mut iter = line.split_whitespace();
        (
            iter.next().unwrap().parse().unwrap(),
            iter.next().unwrap().parse().unwrap(),
            iter.next().unwrap().parse().unwrap()
        )
    };
    let (A, B): (Vec<usize>, Vec<usize>) = {
        let (mut A, mut B) = (vec![], vec![]);
        for _ in 0..(N - 1) {
            let mut line: String = String::new();
            std::io::stdin().read_line(&mut line).unwrap();
            let mut iter = line.split_whitespace();
            A.push(iter.next().unwrap().parse().unwrap());
            B.push(iter.next().unwrap().parse().unwrap());
        }
        (A, B)
    };

    let G = {
        let mut G = vec![std::collections::HashSet::new(); N + 1];
        for i in 0..(N - 1) {
            G[A[i]].insert(B[i]);
            G[B[i]].insert(A[i]);
        }
        G
    };
    let mut parent = vec![N + 1; N + 1];
    let mut children = vec![std::collections::HashSet::new(); N + 1];
    parent[v] = v;
    fn construct_tree(
        i: usize,
        parent: &mut Vec<usize>,
        children: &mut Vec<std::collections::HashSet<usize>>,
        G: &Vec<std::collections::HashSet<usize>>,
    ) {
        for &j in &G[i] {
            if parent[j] == G.len() {
                parent[j] = i;
                children[i].insert(j);
                construct_tree(j, parent, children, &G);
            }
        }
    }
    construct_tree(v, &mut parent, &mut children, &G);

    const INF: i64 = 1e18 as i64;
    let mut dp = vec![INF; N + 1];
    let mut q = std::collections::BinaryHeap::new();
    q.push((0, v));
    while let Some((dist, i)) = q.pop() {
        let dist = -dist;
        if dist < dp[i] {
            dp[i] = dist;
            for &j in &G[i] { q.push((-(dist + 1), j)); }
        }
    }
    let d1 = (dp[u] - 1) / 2;
    let x = (0..d1).fold(u, |res, _| parent[res]);
    let mut dp2 = vec![INF; N + 1];
    let mut q = std::collections::BinaryHeap::new();
    q.push((0, x));
    while let Some((dist, i)) = q.pop() {
        let dist = -dist;
        if dist < dp2[i] {
            dp2[i] = dist;
            for &j in &G[i] {
                if j != parent[x] {
                    q.push((-(dist + 1), j));
                }
            }
        }
    }
    let d2 = dp2.iter().filter(|&&y| y < INF).max().unwrap();
    let d3 = (dp[u] - 1) % 2;
    let ans = d1 + d2 + d3;
    println!("{}", ans);
}

Measured memory_bytes: 122620
#include <bits/stdc++.h>
using namespace std;
#define mod 998244353
#define MOD 1000000007
#define inf 0x3f3f3f3f
#define linf 0x3f3f3f3f3f3f3f3fll
typedef long long ll;
typedef pair<int,int> pii;
typedef unsigned long long ull;
const int maxn=2e5+10;
int l[maxn],r[maxn],c[maxn];
vector<pii> itvs;
vector<int> st[maxn];
struct BIT
{
	ll bit[maxn];
	void add(int x,ll v)
	{
		while(x<maxn)
		{
			bit[x]=min(bit[x],v);
			x+=x&-x;
		}
	}
	ll sum(int x)
	{
		ll ret=linf;
		while(x>0)
		{
			ret=min(ret,bit[x]);
			x-=x&-x;
		}
		return ret;
	}
}tree;
int n,m;
int main()
{
	scanf("%d%d",&n,&m);
	for(int i=0;i<m;i++)
	{
		scanf("%d%d%d",&l[i],&r[i],&c[i]);
		itvs.push_back(make_pair(l[i],0));
		itvs.push_back(make_pair(r[i],1));
	}
	sort(itvs.begin(),itvs.end());
	itvs.erase(unique(itvs.begin(),itvs.end()),itvs.end());
	for(int i=0;i<m;i++)
	{
		l[i]=lower_bound(itvs.begin(),itvs.end(),make_pair(l[i],0))-itvs.begin();
		st[l[i]].push_back(i);
		r[i]=lower_bound(itvs.begin(),itvs.end(),make_pair(r[i],1))-itvs.begin();
//		cout<<i<<" "<<l[i]<<" "<<r[i]<<endl;
	}
//	system("pause");
	memset(tree.bit,0x3f,sizeof(tree.bit));
//	tree.add(itvs.size(),0);
//	cout<<tree.sum(itvs.size())<<endl;
	ll ans=linf;
	for(int i=0;i<itvs.size();i++)
	{
		int pos=itvs[i].first;
		int op=itvs[i].second;
	//	cout<<i<<" "<<pos<<" "<<op<<endl; 
		if(!i&&pos!=1)
		{
			printf("-1\n");
			return 0;
		}
		if(op==0)
		{
			ll val=tree.sum(itvs.size()-i+1);
			if(!i)val=0;
			if(val>=linf)continue;
		//	cout<<itvs.size()<<" "<<(itvs.size()-i)<<" "<<val<<endl;
			for(int j=0;j<st[i].size();j++)
			{
				int rht=r[st[i][j]];
			//	cout<<"add "<<(itvs.size()-rht+1)<<" "<<val+c[st[i][j]]<<" "<<st[i][j]<<endl;
				tree.add(itvs.size()-rht+1,val+c[st[i][j]]);
			}
		}
		else
		{
			if(pos==n)
			{
				ans=min(ans,tree.sum(itvs.size()-i+1));
			}
		}
	}
	if(ans==linf)ans=-1;
	printf("%lld\n",ans);
	return 0;
}

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

int main() {
	static long long DP[100010][13] = {}, X[12] = {}, MOD = 1000000007;
	X[0] = 1;
	for (int i = 1; i < 12; i++) {
		X[i] = (X[i - 1] * 10) % 13;
	}
	string S;
	cin >> S;
	reverse(S.begin(), S.end());
	DP[0][0] = 1;
	for (int i = 0; i < S.size(); i++) {
		if (S[i] == '?') {
			for (int j = 0; j < 10; j++) {
				for (int k = 0; k < 13; k++) {
					DP[i + 1][(k + X[i % 12] * j) % 13] += DP[i][k];
					DP[i + 1][(k + X[i % 12] * j) % 13] %= MOD;
				}
			}
		}
		else {
			for (int k = 0; k < 13; k++) {
				DP[i + 1][(k + X[i % 12] * (S[i] - '0')) % 13] += DP[i][k];
				DP[i + 1][(k + X[i % 12] * (S[i] - '0')) % 13] %= MOD;
			}
		}
	}
	cout << DP[S.size()][5] << endl;
}

Measured memory_bytes: 10624
#include <iostream>

int main()
{
  std::string n;
  std::cin >> n;
  int a = static_cast<int>(n[0] - '0');
  int b = static_cast<int>(n[1] - '0');
  int c = static_cast<int>(n[2] - '0');
  int d = static_cast<int>(n[3] - '0');
  if (a + b + c + d == 7)
  {
    std::cout << n[0] << "+" << n[1] << "+" << n[2] << "+" << n[3] << "=7" << std::endl;
    return 0;
  }
  else if (a + b - c + d == 7)
  {
    std::cout << n[0] << "+" << n[1] << "-" << n[2] << "+" << n[3] << "=7" << std::endl;
    return 0;
  }
  else if (a + b + c - d == 7)
  {
    std::cout << n[0] << "+" << n[1] << "+" << n[2] << "-" << n[3] << "=7" << std::endl;
    return 0;
  }
  else if (a + b - c - d == 7)
  {
    std::cout << n[0] << "+" << n[1] << "-" << n[2] << "-" << n[3] << "=7" << std::endl;
    return 0;
  }
  else if (a - b + c + d == 7)
  {
    std::cout << n[0] << "-" << n[1] << "+" << n[2] << "+" << n[3] << "=7" << std::endl;
    return 0;
  }
  else if (a - b - c + d == 7)
  {
    std::cout << n[0] << "-" << n[1] << "-" << n[2] << "+" << n[3] << "=7" << std::endl;
    return 0;
  }
  else if (a - b + c - d == 7)
  {
    std::cout << n[0] << "-" << n[1] << "+" << n[2] << "-" << n[3] << "=7" << std::endl;
    return 0;
  }
  else
  {
    std::cout << n[0] << "-" << n[1] << "-" << n[2] << "-" << n[3] << "=7" << std::endl;
    return 0;
  }
  
  
  return 0;
}

Measured memory_bytes: 256