akhauriyash/Code-Regression huggingface dataset:
#![allow(
  non_snake_case,
  unused_variables,
  unused_assignments,
  unused_mut,
  unused_imports,
  dead_code
)]
//use proconio::fastout;
use proconio::input;
use proconio::marker::*;
//use std::collections::HashSet;
use std::cmp::*;
use std::collections::*;
macro_rules! debug {
  ($($a:expr),* $(,)*) => {
      #[cfg(debug_assertions)]
      eprintln!(concat!($("| ", stringify!($a), "={:?} "),*, "|"), $(&$a),*);
  };
}
fn main() {
  input! {
     N:usize,
     K:usize,
     P:[Usize1;N],
     C:[i64;N]
  }
  // 各グループごとに
  // ・1周で稼げるスコア(どこから始めても同じ)と
  // ・各ポイントから各ポイントまで移動したときの最大得点
  // …を全部求め、移動回数K以下になるように実装する。
  // starts: グラフの始点を指すベクトル
  let mut starts = vec![N; N];
  let mut ans = std::i64::MIN;
  for i in 0..N {
    if starts[i] == N {
      starts[i] = i;
      let mut cycle_score = 0;
      let mut j = P[i];
      let mut s = vec![0; N * 2 + 1];
      let mut k = 0;
      s[k] = C[j];
      cycle_score += C[j];
      while starts[j] == N {
        starts[j] = i;
        j = P[j];
        k += 1;
        s[k] = C[j];
        cycle_score += C[j];
      }
      let cycle_len = k + 1;
      // 2周分のスコアを格納。
      for k in 0..cycle_len {
        s[cycle_len + k] = s[k];
      }
      let mut sum = vec![0; cycle_len * 2 + 1];
      for k in 0..cycle_len * 2 {
        sum[k + 1] = sum[k] + s[k];
      }
      // 1周分未満での最長スコアを計算(ただしK以下)
      // K以下の場合のtmaxと、K%cycle_len以下の場合のlmaxを計算。
      // 長さl以下の最高スコアsmax[l]を計算する。
      let mut smax = vec![std::i64::MIN; cycle_len];
      for len in 1..cycle_len {
        smax[len] = smax[len - 1];
        for l in 0..cycle_len {
          smax[len] = max(smax[len], sum[l + len] - sum[l]);
        }
      }
      // 周回スコア
      debug!(cycle_score, cycle_len);
      debug!(s);
      debug!(smax);
      let mut tmp = std::i64::MIN;
      if cycle_len > K {
        tmp = smax[K];
      } else if cycle_score < 0 {
        tmp = smax[cycle_len - 1];
      } else {
        tmp = cycle_score * ((K / cycle_len) as i64);
        for l in 1..min(K, cycle_len) {
          tmp = max(tmp, smax[l] + cycle_score * (((K - l) / cycle_len) as i64));
        }
      }
      ans = max(ans, tmp);
    }
  }
  println!("{}", ans);
}


Measured memory_bytes: 2516
#include <stdio.h>

int main()
{
	int x,y;
	
	scanf("%d %d", &x, &y);
	
	while( x || y )
	{
		if( y < x )
		{
			y ^= x;
			x ^= y;
			y ^= x;
		}
		printf("%d %d\n", x, y);
		scanf("%d %d", &x, &y);
	}
	return 0;
}

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

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)   FOR(i,0,n)
#define ALL(a)     (a).begin(),(a).end()
#define RALL(a)     (a).rbegin(),(a).rend()
#define PRINT(a)   cout << (a) << endl

#define pb push_back
#define eb emplace_back
#define mp make_pair
#define Fi first
#define Se second

#define debug(x) cerr << x << " " << "(L:" << __LINE__ << ")" << '\n';

using ll = long long int;
using P = pair<int,int>;
using vi = vector<int>;
using vvi = vector<vi>;
using vvvi = vector<vvi>;
using pii = pair<int, int>;

template <typename T> using PQ = priority_queue<T>;
template <typename T> using minPQ = priority_queue<T, vector<T>, greater<T>>;

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

const int INF = 1001001001;
const ll LINF = 1001001001001001001ll;
const int MOD = 1e9 + 7;

int main(){
  int a,b;
  cin >> a >> b;
  if(a>=13){
    cout << b << endl;
  }else if(a>=6){
    cout << b / 2 << endl;

  }else{
    cout << 0 << endl;
  }
}



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

int main() {
    int N, M, X, Y;
    cin >> N >> M >> X >> Y;
    int x[N], y[M];
    for (int i = 0; i < N; ++i) cin >> x[i];
    for (int i = 0; i < M; ++i) cin >> y[i];

    int xmax = -101, ymin = 101;
    for (int i = 0; i < N; ++i) {
        if (xmax < x[i]) xmax = x[i];
    }
    for (int i = 0; i < M; ++i) {
        if (ymin > y[i]) ymin = y[i];
    }

    if (xmax < Y && ymin > X && xmax < ymin) cout << "No War" << endl;
    else cout << "War" << endl;
    
    return 0;
}

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

int main() {
    int n; cin >>n;
    vector<int> a(n);
    for (int i = 0; i < n; i++) {cin >>a[i];a[i]--;}

    int ret = 0, next = 0, swp;
    while (true) {
        if (a[next] == 100001) {ret=-1; break;}
        swp = next;
        next = a[swp];
        ret++;
        if (next==1) {break;}
        a[swp] = 100001;
    }

    cout << ret << endl;
    return 0;
}

Measured memory_bytes: 640
N=int(input())
A=list(map(int,input().split()))
A_dis=[abs(A[0]-0)]+list(abs(A[i+1]-A[i]) for i in range(N-1))+[abs(0-A[N-1])]
total=sum(A_dis)
for j in range(N):
    if j!=0 and j!=N-1:
        print(total-abs(A[j]-A[j-1])-abs(A[j+1]-A[j])+abs(A[j+1]-A[j-1]))
    elif j==0:
        print(total- abs(A[j]) - abs(A[j + 1] - A[j])+abs(A[j+1]))
    else:
        print(total- abs(A[j]) - abs(A[j - 1] - A[j]) + abs(A[j - 1]))

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

int main()
{
	//cin.tie(0);
	//ios::sync_with_stdio(false);
	int N;
	scanf("%d", &N);
	int n = N % 10;

	switch (n)
	{
	case 2:
	case 4:
	case 5:
	case 7:
	case 9:
		cout << "hon";
		break;
	case 0:
	case 1:
	case 6:
	case 8:
		cout << "pon";
		break;
	case 3:
		cout << "bon";
		break;

	default:
		break;
	}

	return 0;
}

Measured memory_bytes: 3764
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <vector>
#include <set>
#include <map>
#include <algorithm>
#define rep(i,a,b) for(int i = a; i <= b; i++)
#define dep(i,a,b) for(int i = a; i >= b; i--)
#define Rep(i,a) for(int i = 0; i < a; i++)
using namespace std;
typedef long long LL;
typedef pair<int, int> pii;
#define x first
#define y second
#define pb(a) push_back(a)
const int N = 1e6 + 10; 
int n, a[N];

bool margin(int x, int y) {
	return a[x] <= y;
}
void solve(int x, int y) {
	if (margin(x, y)) printf("First\n");
	else {
		int x1 = ((a[x] - y) & 1); //1 : win 0 :lost
		int y1; dep(i,n,1) if (a[i] > y) { y1 = ((i - x + 1) & 1); break; }
		if (x1 && y1) printf("Second\n");
		else printf("First\n"); 
	}
}

int main() {
	scanf("%d",&n);
	rep(i,1,n) scanf("%d",a + i);
	sort(a + 1, a + n + 1); reverse(a + 1, a + n + 1);
	int s = 0;
	rep(i,1,n) {
		if (margin(i, s) || margin(i + 1, s + 1)) {
			solve(i, s); return 0;
		}
		s++;
	}
	return 0;
}

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

using namespace std;
using ll = long long int;

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

    string s;
    cin >> s;
    ll r = 1e9;
    {
        char c = s[0];
        if(all_of(s.begin(), s.end(), [&](auto &x) {return c == x;})) {
            cout << 0 << endl;;
            return 0;
        }

    }
    for(char c='a'; c<='z'; c++) {
        ll i;
        string t = s;
        for(i=0; ; i++) {
            bool ok = true;
            for(ll j=0; j<t.size()-1; j++)
                if(t[j] == c || t[j+1] == c)
                    t[j] = c;
                else
                    t[j] = '.', ok = false;
            t.erase(t.end()-1, t.end());
            if(ok) break;
        }
        r = min(r,  i);
    }
    cout << r+1 << endl;
}


Measured memory_bytes: 256
s = input()
q = int(input())
mode = True
l = ''
r = ''
for _ in range(q):
    tfc = input().split()
    if int(tfc[0]) == 1:
        mode = not mode
    else:
        if mode:
            if int(tfc[1]) == 1:
                l += tfc[2]
            else:
                r += tfc[2]
        else:
            if int(tfc[1]) == 1:
                r += tfc[2]
            else:
                l += tfc[2]
print(l[::-1]+s+r if mode else r[::-1]+s[::-1]+l)

Measured memory_bytes: 4412
#include <stdio.h>
int main(void){
    int a,b,i,j;
  while(1)
       {
  scanf("%d%d",&a,&b);
  if(a==0&&b==0){break;}
 
  for(i=1;i<=a;i++)
    {
      for(j=1;j<=b;j++)
    {
      if(i>1&&i<a&&j<b&&j>1)printf(".");
      else printf("#");
    }
      printf("\n");
    }
  printf("\n");
     
       }
  return 0;
}


Measured memory_bytes: 2056
#include <bits/stdc++.h>
#include <cstdlib>
#include <cmath>
#include <algorithm>
using namespace std;
using ll = long long;
using P = pair<int,int>;
using Graph= vector<vector<int>>; 
#define rep(i,n) for (ll i=0; i < (n); ++i)
#define rep2(i,n,m) for(ll i=n;i<=m;i++)
#define rep3(i,n,m) for(ll i=n;i>=m;i--)
#define pb push_back
#define eb emplace_back
#define ppb pop_back
#define fi first 
#define se second
const ll INF=1e18 ;
inline void chmax(ll& a,ll b){a=max(a,b);}
inline void chmin(ll& a,ll b){a=min(a,b);}
ll gcd(ll a, ll b) { return b?gcd(b,a%b):a;}
ll lcm(ll a, ll b) { return a/gcd(a,b)*b;}
// ミント
const int mod = 1e9+7 ;
  //998244353;

struct mint {
  ll x; // typedef long long ll;
  mint(ll x=0):x((x%mod+mod)%mod){}
  mint operator-() const { return mint(-x);}
  mint& operator+=(const mint a) {
    if ((x += a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator-=(const mint a) {
    if ((x += mod-a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator*=(const mint a) { (x *= a.x) %= mod; return *this;}
  mint operator+(const mint a) const { return mint(*this) += a;}
  mint operator-(const mint a) const { return mint(*this) -= a;}
  mint operator*(const mint a) const { return mint(*this) *= a;}
  mint pow(ll t) const {
    if (!t) return 1;
    mint a = pow(t>>1);
    a *= a;
    if (t&1) a *= *this;
    return a;
  }

  // for prime mod
  mint inv() const { return pow(mod-2);}
  mint& operator/=(const mint a) { return *this *= a.inv();}
  mint operator/(const mint a) const { return mint(*this) /= a;}
};
istream& operator>>(istream& is, const mint& a) { return is >> a.x;}
ostream& operator<<(ostream& os, const mint& a) { return os << a.x;}
//昆布
struct combination {
  vector<mint> fact, ifact;
  combination(int n):fact(n+1),ifact(n+1) {
    assert(n < mod);
    fact[0] = 1;
    for (int i = 1; i <= n; ++i) fact[i] = fact[i-1]*i;
    ifact[n] = fact[n].inv();
    for (int i = n; i >= 1; --i) ifact[i-1] = ifact[i]*i;
  }
  mint operator()(int n, int k) {
    if (k < 0 || k > n) return 0;
    return fact[n]*ifact[k]*ifact[n-k];
  }
  mint p(int n,int k){
    return fact[n]*ifact[n-k] ;
  }
  }  c(400005);
 
mint modpow(ll a,ll b){
 if(b==0) return 1 ;
 mint c= modpow(a,b/2) ;
 if(b%2==1) return c*c*a ;
 else return c*c ;
}

mint komb(ll n,ll m){
  mint x=1 ;mint y=1 ;
  rep(i,m){
    x*= n-i ;
    y*= i+1 ;
  }
  return x/y ;
}

 map<ll,ll> factor(ll n){  //素因数とオーダーをマップで管理
  map <ll,ll> ord ;  
  for(ll i=2;i*i<=n;i++){
        if(n%i==0){
            int res=0;
            while(n%i==0){
                n/=i;
                res++;
            }
            ord[i]=res;
        }
    }
   if(n!=1) ord[n]++;
   return ord ;
 }
 

int main(){
  ll n,k ; cin>>n>>k ;
  mint ans= mint(1);
  if(k<n-1){
   rep2(i,1,k){
    ans+= c(n,i)*c(n-1,i) ;

   }
  }
  else{
    rep2(i,1,n-1){
      ans+= c(n,i)*c(n-1,i) ;
    }
  }
  cout<<ans<<endl ;
     return 0;
  }
   



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

int main() {
	int d;
	cin >> d;
	vector<int> c(30);
	vector<int> co(d+5);
	vector<int> ans(d + 5);
	int ans_c = 0;

	rep(i,26) {
		cin >> c[i];
	}

	vector<int> last(26);

	rep(i, 26) {
		last[i]=0;
	}

	vector<int> t(d + 5);
	int s[370][30];

	rep(j, d) {
		rep(i, 26) {
			cin >> s[j][i];
		}
	}
	
	rep(j, d) {

		int count = 0;
		int max_d=0;

		rep(i, 26) {
			int ma = 0;
			rep(k, 26) {
				if (i == k) {
					ma += s[j][k];
				}
				else {
					ma -= c[k] * (j + 1 - last[k]);
				}
			}

			if (count<ma) {
				count = ma;
				max_d = i;
			}
		}

		co[j] = max_d;
	}

	rep(j, d) {
		cout << co[j]+1<<endl;
	}

	return 0;
}

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

int main(){
	int N;
	cin >> N;
	pair<pair<string,int>,int> cpr[N];
	rep(i,N) {
		string s;
		int p;
		cin >> s >> p;
		cpr[i] = make_pair(make_pair(s,100-p),i+1);
	}

	sort(cpr,cpr+N);
	rep(i,N) cout << cpr[i].second << endl;

	return 0;
}


Measured memory_bytes: 3484
import java.util.Scanner

object Main extends App {
  val sc = new Scanner(System.in)
  val N, K = sc.nextInt()
  val A = Set.fill(K) {
    val d = sc.nextInt()
    Set.fill(d)(sc.nextInt())
  }

  val x = (1 to N).toSet -- A.flatten

  println(x.size)
}

Measured memory_bytes: 59248
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using pint = pair<int,  int>;
using pll = pair<ll, ll>;
using edge = pair<int, ll>;
using Graph = vector<vector<int>>; 
using WeightedGraph = vector<vector<edge>>;
const ll INF = 1LL << 60;
const int INF32 = 1 << 29;
const ll MOD = 1000000007;

int main(){
  int a,b;cin >> a >> b;
  int ans = 0;
  for(int i = a; i <= b; ++i){
    string s = to_string(i);
    int n = s.size();
    bool f = true;
    for(int j = 0; j < n; ++j){
      if(s[j]!=s[n-1-j]){
        f = false;
        break;
      }
    }
    if(f)++ans;
  }
  cout << ans << endl;
}


Measured memory_bytes: 256
/*
    Author : DemonStar
*/

// #pragma GCC optimize("Ofast")
// #pragma GCC optimize("unroll-loops")
// #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx2,tune=native")

#include <bits/stdc++.h>
using namespace std;
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
#define ordered_set tree<pair<int, int>, null_type, less<pair<int, int>>, rb_tree_tag, tree_order_statistics_node_update>
#define fast                      \
    ios_base::sync_with_stdio(0); \
    cin.tie(0);                   \
    cout.tie(0);
#define ll long long
#define pi pair<int, int>
#define pl pair<long long, long long>
#define pld pair<long double, long double>
#define endl '\n'
#define loop(i, n) for (ll i = 0; i < n; i++)
#define rep(i, begin, end) for (__typeof(begin) i = (begin) - ((begin) > (end)); i != (end) - ((begin) > (end)); i += 1 - 2 * ((begin) > (end)))
#define all(x) x.begin(), x.end()
#define vl vector<ll>
#define vi vector<int>
#define ml map<ll, ll>
#define vpl vector<pair<ll, ll>>
const ll mod = 1e9 + 7;

template <typename T, typename TT>
ostream &operator<<(ostream &os, const pair<T, TT> &t)
{
    return os << t.first << " " << t.second;
}
template <typename T>
ostream &operator<<(ostream &os, const vector<T> &t)
{
    for (auto &i : t)
        os << i << " ";
    return os;
}
template <typename T>
istream &operator>>(istream &is, vector<T> &v)
{
    for (T &t : v)
        is >> t;
    return is;
}
template <typename T1, typename T2>
istream &operator>>(istream &is, vector<pair<T1, T2>> &v)
{
    for (pair<T1, T2> &t : v)
        is >> t.first >> t.second;
    return is;
}

int main()
{
    ll n, k;
    cin >> n >> k;
    vl v(n);
    cin >> v;
    vl dp(k + 1, 0);
    dp[0] = 1;
    for (int i = 1; i < n + 1; i++)
    {
        vl tmp = dp;
        for (int j = k; j >= 0; j--)
        {
            int r = j, l = max(j - v[i - 1], 0LL);
            dp[j] = (mod + tmp[l] - (r < k ? tmp[r + 1] : 0)) % mod;
            if (j < k)
                (dp[j] += dp[j + 1]) %= mod;
        }
    }
    cout << dp[k] << endl;

#ifdef LOCAL
    cerr
        << "Time elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " s.\n";
#endif

    return 0;
}

Measured memory_bytes: 1792
n=int(input())
a=list(map(int,input().split()))
b=list(map(int,input().split()))
c=list(map(int,input().split()))
p=sum(b)
for i in range(n-1):
    if a[i]==a[i+1]-1:
        p+=c[a[i]-1]
print(p)

Measured memory_bytes: 3060
#include <algorithm>
#include <cassert>
#include <cfloat>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <deque>
#include <iostream>
#include <limits>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <tuple>
#include <unordered_map>
#include <unordered_set>
#include <vector>
 
#define FOR(i,k,n) for (int (i)=(k); (i)<(n); ++(i))
#define rep(i,n) FOR(i,0,n)
#define all(v) begin(v), end(v)
#define debug(x) cerr<< #x <<": "<<x<<endl
#define debug2(x,y) cerr<< #x <<": "<< x <<", "<< #y <<": "<< y <<endl
 
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<vector<int> > vvi;
typedef vector<ll> vll;
typedef vector<vector<ll> > vvll;
typedef deque<bool> db;
template<class T> using vv=vector<vector< T > >;

int n;
vi a;
vll accum;
ll count() {
  ll cnt = 0;
  FOR (i, 1, n) {
    accum[i] = accum[i-1] + a[i];
    if (accum[i-1] < 0 && accum[i] <= 0) {
      cnt += 1 - accum[i];
      accum[i] = 1;
    }
    if (accum[i-1] > 0 && accum[i] >= 0) {
      cnt += accum[i] + 1;
      accum[i] = -1;
    }
  }
  return cnt;
}

int main() {
  scanf("%d", &n);
  a.resize(n);
  rep (i, n) {
    scanf("%d", &a[i]);
  }
  accum.assign(n, 0);
  accum[0] = a[0];

  ll cnt_minus = 0;
  if (accum[0] >= 0) {
    cnt_minus += accum[0] + 1;
    accum[0] = -1;
  }
  cnt_minus += count();

  accum.assign(n, 0);
  accum[0] = a[0];
  ll cnt_plus = 0;
  if (accum[0] <= 0) {
    cnt_plus += 1 - accum[0];
    accum[0] = 1;
  }
  cnt_plus += count();
  printf("%lld\n", min(cnt_minus, cnt_plus));

  return 0;
}


Measured memory_bytes: 1408
n,m,x,y  = gets.split.map(&:to_i)
x_max = gets.split.map(&:to_i).max
y_min = gets.split.map(&:to_i).min

((x+1)..y).each do |z|
  if x_max < z && y_min >= z
    puts "No War"
    exit
  end
end
puts "War"

Measured memory_bytes: 3836
#define _USE_MATH_DEFINES
#include  <cmath>
#include <cstdio>
#include <vector>
#include <iostream>
#include <algorithm>
#include <string>
#include<math.h>
#include<iomanip>
#include<stdio.h>
#include <stdlib.h>
#include<stdio.h>
#include <queue>
#include<map>
#include <sstream>
#include<set>
#include<stack>
#include<time.h>
typedef long long int ll;
//#include<bits/stdc++.h>


using namespace std;



int main()
{
    int t;
    cin >> t;

    while (t) {
        if (t % 10 == 7) {
            cout << "Yes" << endl;
            return 0;
        }
        t /= 10;
    }

    cout << "No" << endl;

    return 0;

}

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

using namespace std;

#define INF 2000000000
#define MOD 1000000007
typedef long long ll;
typedef pair<int, int> P;


int main()
{
	string s;
	cin >> s;

	if (s[0] == s[1] && s[0] == s[2]) {
		cout << s << "\n";
		return 0;
	}
	if (s[0]-'0' > s[1]-'0') {
		cout << s[0] << s[0] << s[0] << "\n";
		return 0;
	}
	if (s[0]==s[1]) {
		if (s[1]-'0' > s[2]-'0') {
			cout << s[0] << s[0] << s[0] << "\n";
			return 0;
		}
	}

	int t = s[0]-'0' + 1;
	cout << t << t << t << "\n";
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
bool debug;
#define all(x) (x).begin(), (x).end()
#define ll long long

#define db(x) if(debug)cout << " " << (x) <<" "
#define dbn(x) if(debug)cout << "\n" << (#x) << " is " << (x) << endl
#define endl "\n"
#define pb push_back
#define fi first
#define se second
#define rep(i,n) for(ll i=0;i<n;i++)
#define per(i,n) for(ll i=n-1;i>=0;i--)
#define rep1(i,n) for(ll i=1;i<=n;i++)
#define per1(i,n) for(ll i=n;i>=1;i--)
// fill(all(vec), 1);
//vec.resize(unique(all(vec))-vec.begin())
const int N = 3e6;

void solve()
{
   string s;
   cin>>s;
   
   string a="hi",b="";
   while(b.size()<s.size())
   	b+=a;
   cout<<(s==b?"Yes":"No");

}



int main()
{
    debug = 0;


    if(debug)
    {
#ifndef ONLINE_JUDGE
        // for getting input from input.txt
        freopen("input.txt", "r", stdin);
        // for writing output to output.txt
        freopen("output.txt", "w", stdout);
#endif
    }

    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    int t = 1;
    // cin >> t;


    while(t--)
    {
        solve();
        // cout << endl;
    }


}

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

//直角三角形の判定
bool Get_triangle(int a,int b,int c){
    if(pow(a,2)+pow(b,2) == pow(c,2))
        return true;
    else
        return false;
}

//与えられたデータに対しての直角三角形の判定
string Judge_triangle(int a,int b,int c){
    if(Get_triangle(a,b,c) || Get_triangle(b,c,a) ||Get_triangle(c,a,b)){
        return "YES";
    }
    else{
        return "NO";
    }
}

//与えられたデータが条件に合うかの判定
bool Judge_line(int x){
    if(1<=x || x<=1000 || ceil(x) == floor(x))
        return true;
    else
        return false;
}

//main
int main(){
  int N;
  int a,b,c;
  int n=0;
    
    while(1){

  cin >> N;
    
        if(N > 1000 || ceil(N) != floor(N)){
            
        }
    else
        break;
    }
    
    string x[N];

while(N > 0 && cin >> a >> b >> c){
    
    
    while(1){
        if(Judge_line(a) && Judge_line(b) && Judge_line(c)){
            x[n] = Judge_triangle(a,b,c);
            N--;
            n++;
            break;
        }
        
        else{
            break;
        }
  }
}
    
    //結果の表示
    for(int i = 0;i < n;i++)
        cout << x[i] << endl;
    
  return 0;
}


Measured memory_bytes: 3104
import java.util.Scanner;

public class Main {
	static int p[][];

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		String s = sc.next();
		String[] wd = {"SUN", "MON", "TUE", "WED", "THU", "FRI", "SAT"};

		int i = 0;
		while(!wd[i].equals(s))
			i += 1;

		int ans = 7 - i;

		System.out.println(ans);
        return;
    }
}



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

int main() {
  int N, Sum=0;
  cin >> N;
  vector<int> L(N);
  rep(i, N) cin >> L.at(i);
  sort(L.begin(), L.end());
  rep(i, N-1) Sum=Sum+L.at(i);
  if(Sum>L.at(L.size()-1)) cout << "Yes" << endl;
  else cout << "No" << endl;
}

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

int main(void){
  int n;
  cin >> n;
  vector<int> ans(n+1);
  rep(i,n) {
    int a;
    cin >> a;
    ans[a] = i+1;
  }
  for(int i = 1; i <= n; i++){
    cout << ans[i] << " ";
    if(i == n) cout << endl;
  }
  return 0;
}

Measured memory_bytes: 3724
#include <iostream>
#include <algorithm>
#include <cmath>

using namespace std;

int main()
{
	long long n, k;
	cin >> n >> k;
	if (n <= k) {
		cout << min(abs(k - n), n) << endl;
		return 0;
	}

	long long s = n / k;
	long long t = s * k;
	n -= t;
	cout << min(abs(k - n), n) << endl;

	return 0;
}

Measured memory_bytes: 256
package main

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

type Node struct {
	prev, next *Node
	value      int
}

type LinkedList struct {
	head, tail *Node
}

func NewLinkedList() (list LinkedList) {
	head, tail := &Node{}, &Node{}
	head.next = tail
	tail.prev = head
	return LinkedList{head, tail}
}

func (list *LinkedList) Each() <-chan *Node {
	head := list.head
	ch := make(chan *Node, 1000)
	go func(ch chan *Node) {
		node := head
		for node.next != list.tail {
			node = node.next
			ch <- node
		}
		close(ch)
	}(ch)
	return ch
}

func (list *LinkedList) Insert(x int) {
	head := list.head
	newNode := &Node{value: x}
	newNode.prev = head
	newNode.next = head.next
	head.next.prev = newNode
	head.next = newNode
}

func (list *LinkedList) Delete(x int) bool {
	for node := range list.Each() {
		if node.value == x {
			node.prev.next = node.next
			node.next.prev = node.prev
			return true
		}
	}
	return false
}

func (list *LinkedList) DeleteFirst() {
	head := list.head
	node := head.next.next
	if node == nil {
		return
	}
	head.next = node
	node.prev = head
}

func (list *LinkedList) DeleteLast() {
	tail := list.tail
	node := tail.prev.prev
	if node == nil {
		return
	}
	tail.prev = node
	node.next = tail
}

func printList(list LinkedList) {
	w := bufio.NewWriter(os.Stdout)
	for node := range list.Each() {
		w.WriteString(strconv.Itoa(node.value))
		if node.next != list.tail {
			w.WriteString(" ")
		}
	}
	w.WriteString("\n")
	w.Flush()
}

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

	scanner := bufio.NewScanner(os.Stdin)
	list := NewLinkedList()
	for i := 0; i < n; i++ {
		scanner.Scan()
		s := strings.Split(scanner.Text(), " ")
		cmd := s[0]
		switch cmd {
		case "insert":
			x, _ := strconv.Atoi(s[1])
			list.Insert(x)
		case "delete":
			x, _ := strconv.Atoi(s[1])
			list.Delete(x)
		case "deleteFirst":
			list.DeleteFirst()
		case "deleteLast":
			list.DeleteLast()
		}
	}
	printList(list)
}



Measured memory_bytes: 69520
#include <iostream>
#include <stdio.h>
#include <string.h>
#include <math.h>
#include <cstdlib>
#include <stack>
#include <queue>
#include <list>

using namespace std;

class c_binary
{
private:

public:
    c_binary();
    void f_input();
};

c_binary::c_binary()
{
    
}

void c_binary::f_input()
{
    int n;
    int q;
    int s[100000];
    int t[50000];
    int i;
    int c;
    int highid;
    int lowid;
    int midid;
    
    cin >> n;
    for ( i = 0; i < n; ++i ){
        cin >> s[i]; 
    }
    
    cin >> q;
    for ( i = 0; i < q; ++i ){
        cin >> t[i]; 
    }
    
    
    c = 0;
    
    for ( i = 0; i < q; ++i ){
        highid = n-1;
        lowid = 0;
        while (lowid <= highid){
            midid = (lowid + highid) / 2;
            if (s[midid] == t[i]){
                ++c;
                break;
            } else if(s[midid] < t[i]){
                lowid = midid +1;
            } else {
                highid = midid -1;
            }
        }
    }
    cout << c << endl;
}

int main(){
    
    c_binary binary01;
    binary01.f_input();
    
    return 0;
}

Measured memory_bytes: 3652
#include <bits/stdc++.h>
using namespace std;
using ll = long long; using P = pair<int,int>;
using vl = vector<ll>; using vvl = vector<vl>;
#define mp make_pair
#define pb push_back
#define _overload3(_1,_2,_3,name,...) name
#define _rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(int i=int(a);i<int(b);i++)
#define rep(...) _overload3(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)
#define rrep(i,n) for (int i=(n-1);i >= 0;i--)
#define all(v) v.begin(),v.end()
#define sz(v) (int)((v).size())
#define MAX(v) *max_element(all(v))
#define MIN(v) *min_element(all(v))
#define Sort(v) sort(all(v))
#define Rev(v) reverse(all(v))
#define vec(type,name,...) vector<type> name(__VA_ARGS__)
#define VEC(type,name,size) vector<type> name(size);in(name)
#define vv(type,name,h,...) vector<vector<type>>name(h,vector<type>(__VA_ARGS__))
#define VV(type,name,h,w) vector<vector<type>>name(h,vector<type>(w));in(name)
void debug_out() { cout << endl; }
template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
    cout << H << " ";
    debug_out(T...);
}
#ifdef _DEBUG
#define debug(...) debug_out(__VA_ARGS__)
#else
#define debug(...) 
#endif
template <typename T>
std::ostream& operator<<(std::ostream& os, std::vector<T> vec) {
    for (std::size_t i = 0; i < vec.size(); i++)os << vec[i] << (i + 1 == vec.size() ? "" : " ");
    return os;
}
inline void IN(void){return;}
template <typename First, typename... Rest>
void IN(First& first, Rest&... rest){cin >> first;IN(rest...);return;}
template<class T>bool chmax(T &a, const T &b) {if(a<b){a=b; return 1;} return 0;}
template<class T>bool chmin(T &a, const T &b) {if(b<a){a=b; return 1;} return 0;}
const ll INF = 1LL << 60;
const ll mod = 1000000007;
const int dx[8] = {1,0,-1,0,1,1,-1,-1}; const int dy[8] = {0,1,0,-1,1,1,-1,-1};

int main(){
    cin.tie(0); ios::sync_with_stdio(false);
    ll n;
    cin >> n;
    vec(ll,a,n);
    rep(i,n) cin >> a[i];
    Sort(a);
    Rev(a);
    ll ans = a[0];
    if(n%2==1){
        rep(i,1,(n-1)/2) ans += 2*a[i];
        ans += a[(n-1)/2];
    }else{
        rep(i,1,n/2) ans += 2*a[i];
    }
    cout << ans << endl;
}

Measured memory_bytes: 4748
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <iomanip>
#include <random>
#include <cstdio>
#include <cmath>
#include <map>
#include <queue>
using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0; i < (int) n; i++)

int main() {
    int k; cin >> k;
    int a[] = {1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51};
    cout << a[k-1] << endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdlib>
#include <algorithm>
#include <cmath>
#include <vector>
#include <numeric> // accumulate(v.begin(), v.end(), 0)

using namespace std;
#define ll long long

/*
  素因数分解
*/
struct data {
  ll prime;
  int power;
  data(ll prime, int power) : prime(prime), power(power) {}
};
vector<data> result;
void factorization(ll N) {
  if(N == 1 || N == 0) return;

  bool first = true;
  int n = N;
  while(n % 2 == 0) {
    if(first) {
      result.push_back(data(2LL, 1));
      first = false;
    } else {
      result[result.size()-1].power++;
    }
    n /= 2;
  }
  first = true;

  for(ll i=3; i<ceil(sqrt(N)); i+=2) {
    while(n % i == 0) {
      if(first) {
	result.push_back(data(i, 1));
	first = false;
      } else {
	result[result.size()-1].power++;
      }
      n /= i;
    }
    first = true;
  }

  if(n != 1) {
    result.push_back(data(n, 1));
  }

  return;
}

ll ans = 0LL;
void calc(int n, ll m, int i=0, ll tmp=1LL) {
  if(i == (int)result.size()) {
    if(tmp * n <= m && tmp > ans)
      ans = tmp;
  } else {
    for(int j=0; j<=result[i].power; j++)
      calc(n, m, i+1, tmp*(ll)pow(result[i].prime, j));
  }
}

int main(){
  int N;  ll M;
  cin >> N >> M;
  factorization(M);
  calc(N, M);
  cout << ans << endl;
  return 0;
}



Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define ll long long
#define fi first
#define se second
#define pb push_back
#define rep(i, s, n) for (int i = s; i < n; i++)
#define rrep(i, s, n) for (int i = (n)-1; i >= (s); i--)
#define all(a) a.begin(),a.end()
typedef pair<int,int>pint;
typedef vector<int>vint;
typedef vector<pint>vpint;
const long long MOD = 1000000007, INF = 1e18;
 
#define endl '\n'
#define IOS() ios_base::sync_with_stdio(0);cin.tie(0)
 
template<class T>inline bool chmax(T& a,T b){if(a<b){a=b;return true;}return false;}
template<class T>inline bool chmin(T& a,T b){if(a>b){a=b;return true;}return false;}

template<typename T>vector<T>
make_v(size_t a){return vector<T>(a);}
template<typename T,typename... Ts>
auto make_v(size_t a,Ts... ts){
	return vector<decltype(make_v<T>(ts...))>(a,make_v<T>(ts...));
}

template<typename T,typename V>
typename enable_if<is_class<T>::value==0>::type
fill_v(T &t,const V &v){t=v;}

template<typename T,typename V>
typename enable_if<is_class<T>::value!=0>::type
fill_v(T &t,const V &v){
	for(auto &e:t) fill_v(e,v);
}

void pv(vector<int>&v){
	for(int i = 0;i<v.size();i++){
		if(i)cout<<' ';
		cout<<v[i];
	}
	cout<<endl;
}



signed main(){
	IOS();
	int N;
	cin >> N;
	vector<int>s(N);
	for(int i = 0;i < N;i++){
		cin>>s[i];
	}
	int ans = 0;
	rep(i,1,N/2){
		int l = 0,r = N - 1;
		int cost = 0;
		map<int,int>visit;
		while(0<=r&&l<N&&visit.count(l)==0&&visit.count(r)==0){
			if(l+i>=N-1)break;
			visit[l] = true;
			visit[r] = true;
			cost += s[l] + s[r];
			l += i;
			r -= i;
			chmax(ans,cost);
			if(l==r)break;
		}
	}
	cout<<ans<<endl;
}


Measured memory_bytes: 7808
#include <bits/stdc++.h>
#define ll long long 

using namespace std;

const int K = 100100;
const int N = 110;
const int Mod = 1e9 + 7;

int n,k;    
int a[N];
int Dp[N][K];
int Pref[N][K];

void add_self(int& x,int y){
    x += y;
    if(x >= Mod) x -= Mod;
}

int sub(int x,int y){
    x -= y;
    if(x < 0)   x += Mod;
    return x;
}

void ComputePrefix(int i)
{
    Pref[i][0] = Dp[i][0];
    for(int j = 1; j <= k; j++) Pref[i][j] = (Dp[i][j]+Pref[i][j-1]) % Mod;
}

int main()
{
    cin >> n >> k;

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

    Dp[n][k] = 1;
    ComputePrefix(n);

    for(int i = n - 1; ~i; i--)
    {
        for(int j = 0; j <= k; j++)
        {
            int L = j, R = min(k,j+a[i]); 

            add_self(Dp[i][j],sub(Pref[i+1][R],(L ? Pref[i+1][L-1] : 0)));
        }

        ComputePrefix(i);
    }

    cout << Dp[0][0];
}

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

using namespace std;
#define X first
#define Y second
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<vi> vvi;

#define debug(x) cerr << #x << " = " << (x) << endl;
template<typename T>
ostream& operator<<(ostream& o, vector<T>& v) {
    for (auto& x : v) o << x << ' ';
    return o;
}

int main(){
    std::ios_base::sync_with_stdio(false); cin.tie(0);
    int n; cin >> n;
    string a, b; cin >> a >> b;
    for (int len = n; len >= 1; len--){
        bool match = true;
        for (int i = 0; i < len; i++){
            if (b[i] != a[n-len+i]){
                match = false;
            }
        }
        if (match){
            cout << 2 * n - len << endl;
            return 0;
        }
    }
    cout << 2 * n << endl;
}


Measured memory_bytes: 256
#include<iostream>
using namespace std;
int n,m,cnt,i,j;
string str[7]={"Monday","Tuesday","Wednesday","Thursday","Friday","Saturday","Sunday"};
int t[13]={0,31,29,31,30,31,30,31,31,30,31,30,31};
int main(){
  while(cin>>n>>m&&n&&m){
    cnt=3;
    for(i=1;i<=12;i++){
      for(j=1;j<=t[i];j++){
	if(i==n&&j==m)break;
	cnt++;
      }
      if(i==n&&j==m)break;
    }
    //cout<<cnt<<endl;
    cout<<str[cnt%7]<<endl;
  }
  return 0;
}

Measured memory_bytes: 1196
#include <bits/stdc++.h>
#define rep(i, n) for (int i=0; i<(int)(n); i++)
#define all(v) v.begin(), v.end()
using namespace std;
using ll = long long;
using Graph = vector<vector<int>>;
const ll MOD = 1000000007;
const ll INF = 9999999999;
template<class T> inline bool chmin(T& a, T b){if (a>b){a = b; return true;}return false;}
template<class T> inline bool chmax(T& a, T b){if (a<b){a = b; return true;}return false;}
template<class T> inline T powerM(T a,T b){if (b==0) return 1;
  T tmp = powerM(a,b/2); if (b%2==0) return tmp*tmp%MOD; else return tmp*tmp%MOD*a%MOD; }


int N,M;

int main() {
  cin >>N >>M;
  Graph G(N);
  rep(i, M){
    int a,b; cin >>a >>b;
    a--; b--;
    G[a].push_back(b); G[b].push_back(a);
  }
  int res = 0;

  vector<int> tmp(N);
  rep(i, N) tmp[i] = i;

  do{
    bool ok = true;
    if (tmp[0] != 0) continue;
    for (int i=0; i<N-1; i++){
      int nowx = tmp[i], nextx = tmp[i+1];
      bool dame = true;
      for (auto x : G[nowx]){
        if (x == nextx){
          dame = false;
          break;
        }
      }
      if (dame){
        ok = false; break;
      }
    }
    if (ok){
      res++;
    }
  } while(next_permutation(all(tmp)));

  cout <<res <<endl;
}

Measured memory_bytes: 256
#include<stdio.h>
void merge(int *,int,int,int);
void mergeSort(int *,int,int);
int A[500000],count=0;
int main(){
  int i,j,n;
  scanf("%d",&n);
  for(i=0;i<n;i++)
    scanf("%d",&A[i]);
  mergeSort(A,0,n);
  for(i=0;i<n;i++){
    if(i>0) printf(" ");
    printf("%d",A[i]);
  }
  printf("\n%d\n",count);
  return 0;
}

void merge(int A[],int left,int mid,int right){
  int n1=mid-left,n2=right-mid,i,L[n1+1],R[n2+1],j,k;
  for(i=0;i<=n1-1;i++){
    L[i]=A[left+i];
  }
  for(i=0;i<=n2-1;i++){
    R[i]=A[mid+i];
      }
      L[n1]=1000000000;
      R[n2]=1000000000;
      i=0;
      j=0;
      for(k=left;k<=right-1;k++){
	if(L[i]<=R[j]){
	  A[k]=L[i];
	  i=i+1;
	}
	
	else{
	A[k]=R[j];
	j=j+1;
	}
	count++;
      }
}
void mergeSort(int A[],int left,int right){
  int mid;
  if(left+1<right){
    mid=(left+right)/2;
    mergeSort(A,left,mid); 
    mergeSort(A,mid,right);
    merge(A,left,mid,right);
  }
}
    
      
      
    

Measured memory_bytes: 4504
from collections import deque, defaultdict


def main():
    n, m = [int(e) for e in input().split()]
    AB = [[int(e) for e in input().split()] for i in range(m)]

    R = defaultdict(set)
    for ab in AB:
        a, b = ab
        R[a].add(b)
        R[b].add(a)

    A = [0] * (n + 1)
    Q = deque(R[1])
    Qa = deque([1] * len(R[1]))
    while len(Q) > 0:
        qe = Q.pop()
        arrow = Qa.pop()
        if A[qe] == 0:
            A[qe] = arrow
            for r in R[qe]:
                Q.appendleft(r)
                Qa.appendleft(qe)

    if A[2:].count(0) > 0:
        print('No')
        exit()

    print('Yes')
    for i in range(2, n + 1):
        print(A[i])


if __name__ == '__main__':
    main()


Measured memory_bytes: 160184
import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int m = sc.nextInt();
        ArrayList<ArrayList<Integer>> graph = new ArrayList<>();
        for (int i = 0; i < n; i++) {
            graph.add(new ArrayList<>());
        }
        for (int i = 0; i < m; i++) {
            int a = sc.nextInt() - 1;
            int b = sc.nextInt() - 1;
            graph.get(a).add(b);
        }
        int start = sc.nextInt() - 1;
        int end = sc.nextInt() - 1;
        PriorityQueue<Path> queue = new PriorityQueue<>();
        queue.add(new Path(start, 0, 0));
        int[][] costs = new int[3][n];
        for (int[] arr : costs) {
            Arrays.fill(arr, Integer.MAX_VALUE);
        }
        while (queue.size() > 0) {
            Path p = queue.poll();
            if (costs[p.mod][p.idx] <= p.value) {
                continue;
            }
            costs[p.mod][p.idx] = p.value;
            for (int x : graph.get(p.idx)) {
                queue.add(new Path(x, (p.mod + 1) % 3, p.value + 1));
            }
        }
        if (costs[0][end] == Integer.MAX_VALUE) {
            System.out.println(-1);
        } else {
            System.out.println(costs[0][end] / 3);
        }
    }
    
    static class Path implements Comparable<Path> {
        int idx;
        int mod;
        int value;
        public Path(int idx, int mod, int value) {
            this.idx = idx;
            this.mod = mod;
            this.value = value;
        }
        
        public int compareTo(Path another) {
            return value - another.value;
        }
    }
}

Measured memory_bytes: 70124
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<cmath>
#include<random>
#include<stack>
#include<queue>
#include<bitset>
#include<sstream>

using namespace std;

int main(int argc, const char *argv[]){
    int a,b;
    cin >> a >> b;
    cout << max(a+b,max(a-b,a*b)) << endl;
    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>

int main()
{
 int a,b,S,i,x;
 scanf("%d%d",&a,&b);
 if(a>=b)
 {
  x=a;
  a=b;
  b=x;
 }
 while(b>0)
 {
  x=a%b;
  a=b;
  b=x;
 }
 printf("%d\n",a);
 return 0;
}

Measured memory_bytes: 592
#include <iostream>
#include <vector>
#include <algorithm>
#include <queue>
#include <list>

using namespace std;
static const int MAX = 100000;
static const int INFTY = (1 << 29);

vector<int> G[MAX];
list<int> out;//??????
bool V[MAX];
int N;
int indeg[MAX];


//??????????????????????????????????????????????????¢?´¢
void bfs(int s)
{
	queue<int> q;
	q.push(s);
	V[s] = true;

	while (!q.empty()) {
		int u = q.front();
		q.pop();
		out.push_back(u);
		for (int i = 0; i < G[u].size(); i++) {
			int v = G[u][i];
			indeg[v]--;
			if (indeg[v] == 0 && !V[v]) {
				V[v] = true;
				q.push(v);
			}
		}
	}

}

//???????????????????????????
void tsort() {
	for (int i = 0; i < N; i++) {
		indeg[i] = 0;
	}

	for (int u = 0; u < N; u++) {
		for (int i = 0; i < G[u].size(); i++) {
			indeg[G[u][i]]++;
		}
	}


	for (int u = 0; u < N; u++) {
		if (indeg[u] == 0 && !V[u]) {
			bfs(u);
		}
	}




}

int main() {
	int s, t, M;

	cin >> N >> M;

	for (int i = 0; i < N; i++) {
		V[i] = false;
	}

	for (int i = 0; i < M; i++) {
		cin >> s >> t;
		G[s].push_back(t);
	}

	tsort();


	for (list<int>::iterator it = out.begin(); it != out.end(); it++) {
		cout << *it << endl;
	}

	return 0;

}

Measured memory_bytes: 6240
fun main(args: Array<String>) {
    val s = readLine()!!
    var len = s.length

    var ans = 0L
    for (bit in 0 until (1 shl len-1)) {
        var num = (s[0] - '0').toLong()
        for (i in 0 until len-1) {
            if (bit and (1 shl i) != 0) {
                ans += num
                num = 0
            }
            num = 10 * num + (s[i + 1] - '0')
        }
        ans += num
    }
    println(ans)
}

Measured memory_bytes: 31816
#include <iostream>
#include <math.h>
using namespace std;

int main() {
  int N[100000];
  int n; cin >> n;
  for ( int i = 0; i < n; i++ ) {
    cin >> N[i];
  }
  int cnt = 0;
  for ( int i = 0; i < n; i++ ) {
    for ( int j = 1; j < sqrt(N[i]); j++ ) {
      if ( N[i] % ( 2 * j + 1 ) == j ) {
	//cout << "N[i] % ( 2 * j +1 ) == j" << " " << N[i] << " " << j << endl;
	cnt++;
	break;
      }
    }
  }
  // cout << "cnt" << " " << cnt << endl;
  //cout << "n-cnt" << " " << n-cnt << endl;
  cout << n-cnt << endl;
  return 0;
}

Measured memory_bytes: 1360
#include<stdio.h>

int main(void)
{
	int i;
	int N;
	int a, b, c;
	
	scanf("%d",&N);
	
	for( i = 0 ; i < N ; i++ )
	{
		scanf("%d %d %d", &a, &b, &c);
		if( a*a + b*b == c*c || a*a + c*c == b*b || b*b + c*c == a*a ) printf("YES\n");
		else printf("NO\n");
	}
	
	return 0;
	
}

Measured memory_bytes: 580
#include<iostream>
using namespace std;
int main(){
	int a,b;
	int c,d;
	cin>>a>>b;
	cin>>c>>d;
	int ans=0;
	ans+=a*d;
	ans+=b*c;
	ans=ans-c*d;
	cout<<a*b-ans<<endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define int long long int
bool check(int a, int b, int c){
  if(a == b or a == c or b == c)
    return false;
  return ((a+b)>c) and (a+c)>b and (b+c)>a;
}
void solve(){
  int N;
  cin>>N;
  int arr[N];
  for(int i=0;i<N;i++)
    cin>>arr[i];

  int ans = 0;
  for(int i=0;i<N;i++){
    for(int j=i+1;j<N;j++){
      for(int k=j+1;k<N;k++){
        if(check(arr[i], arr[j], arr[k]))
          ans++;
      }
    }
  }

  cout<<ans<<endl;
}
signed main(){
  // int t;
  // cin>>t;
  // while(t--)
    solve();
}


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

int main(void){
  double a,b,c,d,e,f;
  while(cin>>a>>b>>c>>d>>e>>f){
  double p = a * e - b * d;
  double x = (e * c - b * f) / p;
  double y = (a * f - d * c) / p;
  if(0>=x&&x>=-0.0004)x=0;
  if(0>=y&&y>=-0.0004)y=0;
  printf("%.3f %.3f\n",x,y);
  }

}

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

using namespace std;

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

    int n, k, s;
    while (true)
    {
        cin >> n >> k >> s;
        if (n == 0)
            break;
        int res = 0;
        for (int i = 0; i < (1 << n); i++)
        {
            int tmp = i;
            int sum = 0, cnt = 0;
            for (int j = 0; j < n; j++)
            {
                if (tmp % 2)
                {
                    cnt++;
                    sum += (j + 1);
                }
                tmp /= 2;
            }
            if (cnt == k && sum == s)
                res++;
        }
        cout << res << endl;
    }
}


Measured memory_bytes: 3092
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for (int (i)=(0);(i)<(int)(n);++(i))
#define p(x) cout<<(x)<<endl;
#define pv(v) for(auto a: v){ cout << a << endl; }

int main() {
  int n, l; cin >> n >> l;

  int nu = 1000000000;
  int sum = 0;
  int num = 0;

  rep(i, n){
    int na = i + 1 + l -1;
    int nuu = nu;
    nu = min(nu, abs(na));
    if ( nuu != nu) {
      num = na;
    }
    sum += na;
  }
 
  p(sum - num)
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <math.h>
#include <stdio.h>
#include <algorithm>
#define rep(i,n) for (int i = 0; i <= (n); ++i)
#define rip(i,n) for (int i = 1; i <= (n); ++i)
using namespace std;
int main() {
	int a, b,ans;
	cin >> a >> b;
	if (b % a == 0)
		ans = a + b;
	else
		ans = b - a;
	cout << ans << endl;
	return 0;
}

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

using namespace std;

inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}
template<class T> inline T sqr(T x) {return x*x;}

typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<string> vs;
typedef pair<int, int> pii;
typedef long long ll;

#define all(a)  (a).begin(),(a).end()
#define rall(a) (a).rbegin(), (a).rend()
#define pb push_back
#define mp make_pair
#define each(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define exist(s,e) ((s).find(e)!=(s).end())
#define range(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n)  range(i,0,n)
#define clr(a,b) memset((a), (b) ,sizeof(a))
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

const double eps = 1e-10;
const double pi  = acos(-1.0);
const ll INF =1LL << 62;
const int inf =1 << 29;

char island[55][55];

int dh[4]={1,0,-1,0};
int dw[4]={0,1,0,-1};

int memo[55][55];


void rec(int i,int j,int color){
	if(island[i][j]!='.')
		return;
	if(memo[i][j]&(1<<color))
		return;

	memo[i][j]|=(1<<color);

	for(int k=0;k<4;++k)
		rec(i+dh[k],j+dw[k],color);

	return ;
}


int main(void){
	int w,h;
	while(cin >> w >> h){
		if(w==0&&h==0)
			break;

		rep(i,55)rep(j,55) island[i][j]='#',memo[i][j]=0;
		rep(i,h)rep(j,w) cin >> island[i+1][j+1];

		int black=0,white=0;

		for(int i=1;i<=h;++i){
			for(int j=1;j<=w;++j){
				if(island[i][j]=='.')
					continue;
				
				int color=-1;
				if(island[i][j]=='B')
					color=0;
				if(island[i][j]=='W')
					color=1;

				for(int k=0;k<4;++k)
					rec(i+dh[k],j+dw[k],color);
			}
		}

		for(int i=1;i<=h;++i){
			for(int j=1;j<=w;++j){
				if(memo[i][j]==1)
					black++;
				if(memo[i][j]==2)
					white++;		
			}
		}
		cout << black << " " << white << endl;
	}
	return 0;
}

Measured memory_bytes: 1228
#include <iostream>
#include <string>
#include <atcoder/string>

int main()
{
    std::string S;
    std::cin >> S;

    const auto sa = atcoder::suffix_array(S);
    const auto size = sa.size();

    int64_t ans = size * (size + 1) / 2;
    for (const auto x : atcoder::lcp_array(S, sa)) {
        ans -= x;
    }

    std::cout << ans << '\n';
}

Measured memory_bytes: 15564
#include<iostream>
#include<algorithm>
#include<math.h>
#include<vector>
#include<map>
#include<set>
#include<iomanip>

using namespace std;
using ll = long long;

const int MOD = 1e9 + 7;
const int INF = numeric_limits<int>::max();
const ll LLINF = numeric_limits<ll>::max();
const double PI = acos(-1.0);

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

int main() {
    vector<int> A(3); rep(i, 3) cin >> A[i];
    sort(A.begin(), A.end());

    cout << A[2] - A[1] + A[1] - A[0] << endl;
    return 0;
}


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

int main(){
//srandom((unsigned long)time(NULL));

long long n;
cin>>n;
vector<string> s;
for(long long i=0;i<n;i++){
    string str;
    cin>>str;
    s.emplace_back(str);
}

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

long long cnt=1;

for(long long i=0;i<n-1;i++){
if(s[i]!=s[i+1]) cnt++;
}
cout<<cnt<<endl;

return 0;
}



Measured memory_bytes: 11652
# Tree Walk


N = int(input())
*A, = map(int, input().split())
*B, = map(int, input().split())
idx = 0
ans = []


def rec(l=0, r=N):
    global idx
    if l >= r:
        return

    c = A[idx]
    idx += 1
    m = B.index(c)

    rec(l, m)
    rec(m+1, r)

    ans.append(c)


rec()
print(*ans)



Measured memory_bytes: 5604
#include<stdio.h>
int main(){
  int w,h,mi,mj,i,j,s;
  while(scanf("%d %d",&h,&w),w||h){
    int l=(w*w+h*h)*150*150+h,min=150*150*150*150+150;
    for(i=1;i<150;i++){
      for(j=i+1;j<150;j++){
	s=(i*i+j*j)*150*150+i;
	if(l<s&&s<min){
	  min=s;
	  mi=i;
	  mj=j;
	}
      }
    }
    printf("%d %d\n",mi,mj);
  }
  return 0;
}

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

using namespace std;

int main() {
    int N;
    cin >> N;

    vector<tuple<string, int> > vt;
    int ans = 0;
    for (int i = 0; i < N; i++) {
        string s;
        int a;
        cin >> s >> a;
        vt.emplace_back(s, a);
        ans += a;
    }

    string X;
    cin >> X;
    for (int i = 0; i < N; ++i) {
        ans -= get<1>(vt[i]);
        if (get<0>(vt[i]) == X) break;
    }
    cout << ans << endl;
}


Measured memory_bytes: 256