akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
const int N = 100005;
int n, a[N], ans[N];
int main () {
	scanf("%d", &n);
	for (int i = 1; i <= n; i++) {
		scanf("%d", &a[i]);
		ans[a[i]] = i;
	}
	for (int i = 1; i <= n; i++) printf("%d ", ans[i]);
	printf("\n");
	return 0;
}

Measured memory_bytes: 1536
#include <bits/stdc++.h>
using namespace std;
int main()
{
    int h,w;
    while (1)
    {
        cin >> h >> w;
        if(h == 0 && w == 0)
            break;
    
        for(int i = 0 ; i < h ; i++){
            for (int j = 0; j < w; j++)
            {
                if((i + j)%2 == 0)
                    cout << "#";
                else
                    cout << ".";
            }
            cout << endl;
        }
        cout << endl;
    }
  
    return 0;
}


Measured memory_bytes: 3044
#include<bits/stdc++.h>
#include <fstream>
#pragma GCC optimize("O2")
using namespace std;

#define F first
#define S second
#define migmig ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define ll long long 
#define ld long double
#define pii pair <int ,int >
#define bug(x)  cout<<"passed "<<x<<endl;
#define ashar(x , y , z) cout<<setprecision(x)<<fixed<<y ; if (z==1) cout<<"\n" ;
long long const inf = 1e18, linf = 2e9, mod = 1e9+7 , inf2 = 1e12;
int const mxn = 3e5 + 10 ;


ll poww(ll a, ll b, ll md) {
    return (!b ? 1 : (b & 1 ? a * poww(a * a % md, b / 2, md) % md : poww(a * a % md, b / 2, md) % md));
}

int mark[mxn] , ans, h[mxn] ; 

int main(){
	int n , m ; 
	cin>>n>>m ;
	for (int i = 1; i <= n ; i++)
		cin>>h[i] ; 
	for (int i = 1 ; i <= m ; i++){
		int a , b; 
		cin>>a>>b ; 
		if (h[a]==h[b]){
			mark[a] =1 ;
			mark[b] = 1; 
		}
		else if (h[a] > h[b])
			mark[b] = 1 ; 
		else
			mark[a] = 1 ; 
	}
	for (int i = 1 ; i <= n ; i ++){
		if (!mark[i])
			ans++ ; 
	}
	cout<<ans ; 
}	

Measured memory_bytes: 4408
#include<cstdio>
#include<iostream>
#include<cstring>


#define len 12
using namespace std;

char num[12];
int in;

int main () {

  while ( true ) {
    cin >> in;

    if ( in == 0 )
      break;

    for ( int i=11; i>=0; i-- ) {
      num[i] = in%8+'0';
      //num[i] = in%8+'0';
      in = in>>3;
    }
  
    int count = 0;
    while ( num[count] == '0' )
      count++;
  

    for ( int i=count;i <len; i++ ) {
      if ( num[i] == '4' )
	cout << '5';
      else if ( num[i] >'4' )
	cout << (char)(num[i]+2);
      else
	cout << num[i];
    }
    cout << endl;
  }

}

Measured memory_bytes: 852
//Rafiqul Islam, MBSTU,ICT

#include <cstdio>
#include <algorithm>
#include <vector>
#include <set>
#include <queue>
#include <algorithm>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <iostream>
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;

#define pb push_back
#define mk make_pair
#define f0(i,b) for(int i=0;i<(b);i++)
#define f1(i,b) for(int i=1;i<=(b);i++)
#define f2(i,a,b) for(int i=(a);i<=(b);i++)
#define sf(a) scanf("%d",&a);
#define sfl(a) scanf("%lld",&a);
#define pf(a) printf("%d\n",a);
#define pfl(a) printf("%lld\n",a);
#define TEST int test; cin >> test ;while(test--)
#define ii pair<int,int>
#define iil pair<ll,ll>
#define loop(i,a,b) for(int i = a ; i < b ; i++)
#define INF 2147483647
#define endl "\n"
#define all(v) v.begin(),v.end()

int dx8[] = {0, 0, 1, 1, 1, -1, -1, -1};
int dy8[] = {1,-1, 1, -1, 0, 0, -1, 1};
int dx4[] = {0, 0, 1, -1};
int dy4[] = {1, -1, 0, 0};

const double pi = acos(-1.0);
const ll mod = 1e9 + 7;;
const ll maxn = 1e5+5;

ll power(ll x, unsigned long long y)
{
    ll res = 1;     // Initialize result

    while (y > 0)
    {
        // If y is odd, multiply x with result
        if (y & 1)
            res = (res*x);

        // y must be even now
        y = y>>1; // y = y/2
        x = (x*x);  // Change x to x^2
    }
    return res;
}
ll modOp(ll a, ll b)
{
    ll c = a % b;
    if (c < 0)
        c += b;
    return c;
}
ll iv[maxn + 1];
void mod_inv()
{
    iv[1] = 1;
    for(ll i = 2 ; i <= maxn ; i++ )
    {

        iv[i] = (mod - mod/i * iv[mod%i]%mod)%mod;
        //cout << iv[i] << endl;
    }
}

ll Logn(ll n, ll base)
{
    return (n > base - 1) ? 1 + Logn(n / base, base) : 0;
}

void run_case()
{
  int n;
  cin >> n;
  if(n == 0) cout << 1 << endl;
  else cout << 0 << endl;
}
int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(NULL);
    cout.tie(NULL);
    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);
    //TEST
    run_case();
    //main();
    return 0;
}


Measured memory_bytes: 3608
#include <iostream>
#include <stdio.h>
#include <algorithm>
#include <cmath>
#include <string>
#include <vector>
#include <iomanip>
#include <queue>
#include <deque>
#include <map>
#include <unordered_map>
#define rep(i,n) for(int i=0;i<n;i++)
#define repn(i,n) for(int i=1;i<=n;i++)
#define repr(e,x) for(auto& e:x)
using namespace std;
typedef long long ll;
typedef long double ld;
//typedef pair<int,int> P;
double const PI=3.141592653589793;
int const INF=1001001001;
ll const LINF=1001001001001001001;
ll const MOD=1000000007;

int A,B,C,K;

int main(){
    cin>>A>>B>>C>>K;

    int cnt=0;
    while(cnt<=K && A>=B){
        cnt++;
        B*=2;
    }
    while(cnt<=K && B>=C){
        cnt++;
        C*=2;
    }

    if(cnt>K) cout<<"No"<<endl;
    else cout<<"Yes"<<endl;
}

Measured memory_bytes: 3584
#include <stdio.h>


int main(void)
{
	int h[300];
	int w[300];
	int i = -1,j,k,l;
	do{
		i++;
		scanf("%d%d", &h[i], &w[i]);
	} while (h[i] != 0 || w[i] != 0);
	for (j = 0; j <= i; j++){
		for (l = 0; l < h[j]; l++){
			for (k = 0; k < w[j]; k++) { printf("#"); }
			printf("\n");
		}
		if(j != i)printf("\n");
	}

	return 0;
}

Measured memory_bytes: 1812
#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 fast ios_base::sync_with_stdio(0);cin.tie(NULL);cout.tie(NULL)

#define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>

#define ll long long
#define ld long double
#define pb(a) push_back(a)
#define eb(a) emplace_back(a)

#define xx first
#define yy second
#define mp make_pair
#define pll pair<ll,ll>
#define mll map<ll,ll>
#define vll vector<ll>
#define pdd pair<double,double>
#define ALL(v) (v).begin(), (v).end()

const ll MOD=1e9+7;
const ll inf=1e10;

#define MODSET(d) if ((d) >= MOD) d %= MOD;
#define MODNEGSET(d) if ((d) < 0) d = ((d % MOD) + MOD) % MOD;
#define put(x) cout<<#x<<" = "<<x<<endl;

ll power(ll a,ll n){
    ll ans=1;
    while(n){
        if(n&1)
            ans=(ans*a);
        n>>=1;
        a=(a*a);
    }
    return ans;
}


ll powerMod(ll a,ll n){
    ll ans=1;
    while(n){
        if(n&1)
            ans=(ans*a)%MOD;
        n/=2;
        a=(a*a)%MOD;
    }
    return ans;
}

ll powerMod1(ll a,ll n,ll mod){
    ll ans=1;
    while(n){
        if(n&1)
            ans=(ans*a)%mod;
        n>>=1;
        a=(a*a)%mod;
    }
    return ans;
}

ll lcm(ll a,ll b){
    return a*(b/__gcd(a,b));
}

ll sumdigit(ll n){
    ll sum=0;
    while(n){
        sum+=n%10;
        n=n/10;
    }
    return sum;
}

ll countSetBit(ll a){
    return __builtin_popcount(a);
}
ll countBit(ll a){
    ll sum=0;
    while(a){
        sum++;
        a>>=1;
    }
    return sum;
}

ll length(ll a){
    ll ans=0;
    while(a){
        ans++;
        a=a/10;
    }
    return ans;
}

bool isVowel(char c){
	if(c=='a' or c=='e' or c=='i' or c=='o' or c=='u')
		return true;
	return false;
}

const int sz=1e5+10;


int main()
{
    fast;
    
    ll t;
    //~ cin>>t;
    t=1;
    while(t--){
        int n,w;
        cin>>n>>w;
        
        int a[n][2];
        for(int i=0;i<n;i++){
			cin>>a[i][0]>>a[i][1];
		}
		ll dp[2][w+1];
		memset(dp,0,sizeof dp);
		
		int flag=1;
		for(int i=1;i<=n;i++){
			for(int j=1;j<=w;j++){
				dp[flag][j]=dp[flag^1][j];
				if(j>=a[i-1][0]){
					dp[flag][j]=max(dp[flag][j],dp[flag^1][j-a[i-1][0]]+a[i-1][1]);
				}
			}
			//~ for(int j=0;j<=w;j++){
				//~ cout<<dp[flag][j]<<" ";
			//~ }
			//~ cout<<endl;
			flag^=1;
			//~ put(flag);
		}
		//~ for(int i=0;i<=n;i++){
			//~ for(int j=0;j<=w;j++){
				//~ cout<<dp[i][j]<<" ";
			//~ }
			//~ cout<<endl;
		//~ }
		cout<<dp[flag^1][w];
	}
    return 0;
}


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

int n, g[101][101], g_size[101];
bool used[101];

int rec(int idx)
{
  int ret = 1;
  for(int i = 0; i < g_size[idx]; i++){
    if(!used[g[idx][i]]){
      used[g[idx][i]] = true;
      ret = max( ret, rec(g[idx][i]) + 1);
      used[g[idx][i]] = false;
    }
  }
  return ret;
}


int main()
{
  while(cin >> n, n){
  fill_n( g_size, 101, 0);
  for(int i = 0; i < n; i++){
    int a, b;
    cin >> a >> b;
    g[a][g_size[a]++] = b;
    g[b][g_size[b]++] = a;
  }

  int ans = 1;
  for(int i = 1; i <= 100; i++){
    if(g_size[i] > 0){
      used[i]  = true;
      ans = max( ans, rec(i));
      used[i] = false;
    }
  }
  cout << ans << endl;
}
}

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

int main(){
    string s;
    cin >> s;
    int a = stoi(s.substr(0,2));
    int b = stoi(s.substr(2,2));

    bool flag1 = false, flag2 = false;
    if(1 <= a && a <= 12) flag1 = true;
    if(1 <= b && b <= 12) flag2 = true;

    if(flag1 && flag2) cout << "AMBIGUOUS" << endl;
    else if(flag1) cout << "MMYY" << endl;
    else if(flag2) cout << "YYMM" << endl;
    else cout << "NA" << endl;
}


Measured memory_bytes: 3640
#include<iostream>
#include<vector>
#include<algorithm>
#define NMAX 3
int main(){
    using namespace std;
    vector<int> v;
    int tmp;
    for(int i=0;i<NMAX;i++){
        cin>>tmp;
        v.push_back(tmp);
    }
    sort(v.begin(),v.end());
    for(int i=0;i<v.size()-1;i++){
        cout<<v[i]<<" ";
    }
    cout<<v[v.size()-1]<<endl;
    

}


Measured memory_bytes: 3160
# coding: utf-8
# Your code here!

n = int(input())

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

for i in range(n):
    adj = list(map(int,input().split()))
    if adj[1] != 0:
        for j in range(2,2+adj[1]):
            ans[i][adj[j]-1] = 1
for i in range(n):
    print(*ans[i]) 


Measured memory_bytes: 6392
#include <iostream>
using namespace std;
int f(int n) {
  auto s = to_string(n);
  return s[0] * 10 + s.back() - '0' * 11;
}
int N, d[100];
int main() {
  cin >> N;
  while (N) ++d[f(N--)];
  for (int i = 1; i < 100; ++i) N += d[i] * d[i % 10 * 10 + i / 10];
  cout << N << endl;
}


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

typedef long long ll;
const ll INF = 1e18;

int main(){
	int n,k;
	cin >> n >> k;
	vector<int> p(n), c(n);
	for(int i=0; i<n; i++) cin >> p[i], --p[i];
	for(int i=0; i<n; i++) cin >> c[i];

	ll ans = -INF;

	for(int i=0; i<n; i++){
		int v = i;
		ll cycle_sum = 0;
		int cycle_cnt = 0;

		while(true){
			cycle_cnt++;
			cycle_sum += c[v];
			v = p[v];
			if(v == i) break;
		}

		ll path = 0;
		int cnt = 0;

		while(true){
			cnt++;
			path += c[v];

			if(cnt > k) break;

			int num = (k-cnt)/cycle_cnt;
			ll score = path + max(0ll, cycle_sum)*num;
			ans = max(ans, score);

			v = p[v];
			if(v==i) break;
		}
	}

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

Measured memory_bytes: 3672
#include <bits/stdc++.h>
using namespace std;
#define rep(i,a,n) for (int i=a;i<n;i++)
#define per(i,a,n) for (int i=n-1;i>=a;i--)
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define fi first
#define se second
#define SZ(x) ((int)(x).size())
typedef vector<int> VI;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> PII;
typedef double db;
//mt19937 mrand(random_device{}()); 
const ll mod=1000000007;
//int rnd(int x) { return mrand() % x;}
ll powmod(ll a,ll b) {ll res=1;a%=mod; assert(b>=0); for(;b;b>>=1){if(b&1)res=res*a%mod;a=a*a%mod;}return res;}
ll gcd(ll a,ll b) { return b?gcd(b,a%b):a;}
// head
int main() {
	int n,cntr=0,ans=0;
	string s;
	cin>>n>>s;
	rep(i,0,n){
		if(s[i]=='R')cntr++;
	}
	rep(i,0,n){
		if(s[i]=='W'){
			if(cntr>0){
				ans++;
				cntr--;
			}
		}
		if(s[i]=='R'){
			cntr--;
		}
	}
	cout<<ans;
} 

Measured memory_bytes: 3736
#include <bits/stdc++.h>
using namespace std;
 
int main() {

    string s, t;

    cin >> s >> t;

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

    if(s < t)cout << "Yes" << endl;
    else cout << "No" << endl;

}

Measured memory_bytes: 256
#include <iostream>

int Combination(int a, const int b) {
  if (a < 2) {
    return 0;
  }
  int numer = 1;
  int denom = 1;
  for (int i = 1; i <= b; ++i) {
    denom *= i;
    numer *= a--;
  }
  return numer / denom;
}

int main(int, char**) {
  int N, M;
  std::cin >> N >> M;
  const int result = Combination(M, 2) + Combination(N, 2);
  std::cout << result << std::endl;
  return 0;
}


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

using namespace std;

#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define ALL(a) (a).begin(),(a).end()
#define PI 3.141592653589793238
#define INF 1050000000

using vi = vector<int>;


int main() {

	string N;

	cin >> N;

	REP(i, 3) {
		if (N[i] == '1') {
			N[i] = '9';
		}
		else {
			N[i] = '1';
		}
	}

	cout << N << endl;

	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <bits/stdc++.h>
#include <string>
#include <math.h>
#include <vector>
#include <algorithm>
using namespace std;

int main(){
    string s; cin>>s;
    //もし条件でない文字であったときに0にして振り出しに戻す
    int ans=0;
    int a=0;
    for(int i=0;i<s.size();i++){
        if(s[i]=='A'||s[i]=='T'||s[i]=='C'||s[i]=='G') a++;
        else a=0;
        ans=max(a,ans);
    }
    cout<<ans<<endl;
    return 0;
}

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

#define int long long
#define pb push_back 
#define pf push_front 
#define mp make_pair
#define fr first
#define sc second
#define Rep(i, n) for ( int i = 0 ; i < (n); i++ )
#define All(v) v.begin(), v.end()

typedef pair<int, int> Pii; typedef pair<int, Pii> Pip;
const int INF = 1107110711071107;
int dx[4] = {0, 1, 0, -1}, dy[4] = {-1, 0, 1, 0};

int N;
char data[130][130];
bool used[130][130];

void bfs(int y, int x) {
  if ( used[y][x] ) return;
  used[y][x] = true;
  Rep(k, 4) {
    int ny = y+dy[k], nx = x+dx[k];    
    if ( ny < 0 || nx < 0 || ny >= N || nx >= N || data[ny][nx] == 'x' ) continue;
    bfs(ny, nx);
  }
}

signed main() {
  cin >> N;
  Rep(i, N) Rep(j, N) cin >> data[i][j];

  int ans = 0;
  Rep(i, N) Rep(j, N) {
    if ( data[i][j] == 'o' && !used[i][j] ) {
      bfs(i, j);
      ans++;
    }
  }

  cout << ans/3 << endl;
}

Measured memory_bytes: 3132
#include <bits/stdc++.h>
using namespace std;
#define FOR(i, o, n) for (auto i = (o); (i) < (n); ++(i))
#define FOR1(i, n) FOR(i, 1, n+1)
#define REP(i, n) FOR(i, 0, n)
#define REPR(i, n) for (auto i = (n)-1; (i) >= 0; --i)
#define REPI(itr, v) for (auto itr = v.begin(); itr != v.end(); ++itr)
#define REPIR(itr, v) for (auto itr = v.rbegin(); itr != v.rend(); ++itr)
#define fi first
#define se second
#define ll long long
#define int long long
#define V2(name, h, w) vector<vector<int> > name((h), vector<int>(w));
#define myCeil(dividend, divisor) ceil((double)(dividend) / (double)(divisor))
#define myFloor(dividend, divisor) floor((double)(dividend) / (double)(divisor))
#define calcDigits(num) floor(log10(num))+1

#define dl(line) cerr << "RUN: until " << (line) << "th line." << endl;
#define dv(name, value) cerr << (name) << " is " << (value) << endl;
#define da(v)  cerr << "["; REPI(itr, v){cerr << *itr << (itr != --v.end() ? ", " : "");} cerr << "]" << endl;
#define dpa(v) cerr << "[ " << endl;REPI(itr, v) { cerr << "  [" << (*itr).first << ", " << (*itr).second << ']' << (itr != --v.end() ? "," : "") << endl; } cerr << "]" << endl;

signed main(){
  long long N;
  scanf("%lld",&N);
  map<string, int> mp;

  for(int i = 0 ; i < N ; i++){
    string inpS; cin >> inpS;
    sort(inpS.begin(), inpS.end());
    mp[inpS] += 1;
  }

  int sum = 0;
  for(const auto& e : mp) {
    if (e.se != (ll)0) {
      int x = e.se;
      sum += ((x-1) + (x-1)*(x-1)) / 2;
    }
  }

  cout << sum << endl;
}


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

int main(){
int H, W; cin >> H >> W;
vector<vector<char>> a(H, vector<char>(W));
for (int i = 0; i < H; i++) {
    for (int j = 0; j < W; j++) {
        cin >> a[i][j];
    }
}

for (int i = 0; i < H; i++) {
    a[i].push_back('#');
    a[i].insert(a[i].begin(), '#');
}

vector<char> line(W + 2);
for (int j = 0; j < W + 2; j++) {
    line[j] = '#';
}

a.push_back(line);
a.insert(a.begin(), line);

for (int i = 0; i < H + 2; i++) {
    for (int j = 0; j < W + 2; j++) {
        cout << a[i][j];
    } 
    cout << endl;
}
}

Measured memory_bytes: 256
import sys
from collections import deque  # 双方向キュー
from collections import defaultdict  # 初期化済み辞書
from heapq import heapify, heappush, heappop, heappushpop  # プライオリティキュー
from bisect import bisect_left, bisect_right  # 二分探索
#import numpy as np  # 1.8.2
#import scipy  # 0.13.3
#sys.setrecursionlimit(int(1e+6))
s2nn = lambda s: [int(c) for c in s.split(' ')]
ss2nn = lambda ss: [int(s) for s in ss]
ss2nnn = lambda ss: [s2nn(s) for s in ss]
i2s = lambda: sys.stdin.readline().rstrip()
i2n = lambda: int(i2s())
i2nn = lambda: s2nn(i2s())
ii2ss = lambda n: [sys.stdin.readline().rstrip() for _ in range(n)]
ii2sss = lambda n: [list(sys.stdin.readline().rstrip()) for _ in range(n)]
ii2nn = lambda n: ss2nn(ii2ss(n))
ii2nnn = lambda n: ss2nnn(ii2ss(n))
MOD = int(1e+9) + 7

# bitリスト
def getBitsL(n, L):
    bits = [0] * L
    for i in range(L):
        bits[i] = (n & 1) == 1
        n >>= 1
    return bits

def main():
    N, M = i2nn()
    KS = ii2nnn(M)
    P = i2nn()
    n = 0
    for i in range(2**N):
        bits = getBitsL(i, N)
        b = True
        for j, ks in enumerate(KS):
            t = 0
            for k in ks[1:]:
                if bits[k-1]:
                    t += 1
            if t % 2 != P[j]:
                b = False
        if b:
            n += 1
    print(n)

main()


Measured memory_bytes: 43228
#include<bits/stdc++.h>
using namespace std;
int main(){
	#ifndef ONLINE_JUDGE
        freopen("input.txt","r",stdin);
        freopen("output.txt","w",stdout);
    #endif
    // string s;
    // cin>>s;
   	// int flag=1;
    // for(int i=0;i<s.size();++i){
    // 	for(int j=i+1;j<s.size();++j){
    // 		if(s[i]==s[j]){
    // 			flag=0;
    // 			break;
    // 		}
    // 	}
    // }
    // cout<<((flag)?"yes":"no");



    // string s;
    // cin>>s;
    // set<char>c;
    // for(char k:s) c.insert(k);
    // cout<<((s.size()==c.size())?"yes":"no");
    


    // string s;
    // cin>>s;
    // map<char,int>m;
    // for(int i=0;i<s.size();++i){
    // 	if(m[s[i]]>0){
    // 		cout<<"no";
    // 		return 0;
    // 	}
    // 	++m[s[i]];
    // }
    // cout<<"yes";

    // int a,b;
    // cin>>a>>b;
    // int ans=a+b;
    // (ans>=10)?cout<<"error":cout<<ans;
    

    // int n;
    // cin>>n;
    // int a,mx=0,mi=1000;
    // for(int i=0;i<n;++i){
    // 	cin>>a;
    // 	if(mx<a) mx=a;
    // 	if(mi>a) mi=a;
    // }


    int n;
    cin>>n;
    int ar[n];
    for(int i=0;i<n;++i) cin>>ar[i];
   	cout<<*max_element(ar,ar+n)-*min_element(ar,ar+n);
    return 0;
}


Measured memory_bytes: 3588
// C - Vacation
#include <bits/stdc++.h>
using namespace std;
// void abcprn(int a, int b, int c){printf("%4d,%4d,%4d\n",a,b,c);}

int main(){
	int N; cin>>N;
	int a,b,c; cin>>a>>b>>c;
	// cout<<"dp:a    b    c\n";//
	// abcprn(a,b,c);//
	while(--N){
		int pa=a, pb=b, pc=c;
		cin>>a>>b>>c;
		a += max(pb, pc);
		b += max(pc, pa);
		c += max(pa, pb);
		// abcprn(a,b,c);//
	}
	cout<< max({a, b, c}) <<endl;
}

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

#define ll long long

int main(){
	ll n,a[100];
	cin>>n;
	for(int i=0; i<n; i++){
		cin>>a[i];
	}
	ll ans=0;
	ll sm=0;
	for(int i=n-1; i>=0; i--){
		ans+=a[i]*sm;
		sm+=a[i];
	}
	cout<<ans<<endl;
}


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

// int/long:		-2,147,483,648 - 2,147,483,648 (-2^31 <= int < 2^31)
// long/long long:	-9,223,372,036,854,775,808 - 9,223,372,036,854,775,807 (-2^63 <= long < 2^63)

#define	INF (1<<29)
//536,870,912

// lower_bound(A.begin(), A.end(), N)
// upper_bound(...

// A.erase(unique(A.begin(), A.end()), A.end())

// bit: &/and, |/or, ^/xor, ~/not

// getline(cin, String)

// Graph
// Warshall-Floyd: Distance between each node, N^3
// Dijkstra: Distance from the start node, N^2
// DFS(Depth-First Search)

#define	MOD 1000000007

int	main() {
	int N, x;
	cin >>N >>x;
	if ((1==x)||(2*N-1==x)) {
		cout <<"No" <<endl;
		return 0;
	}
	cout <<"Yes" <<endl;
	if (x==N) {
		for (int i=1; i<2*N; i++)
			cout <<i <<endl;
		return 0;
	}
	if (x<N) {
		for (int i=N; i>0; i--)
			if (i!=x)
				cout <<i <<endl;
		cout <<x <<endl;
		for (int i=N+1; i<2*N; i++)
			cout <<i <<endl;
	} else {
		for (int i=1; i<N; i++)
			cout <<i <<endl;
		cout <<x <<endl;
		for (int i=2*N-1; i>=N; i--)
			if (i!=x)
				cout <<i <<endl;
	}
	return 0;
}



Measured memory_bytes: 1536
A, B, K = map(int, input().split(' '))

if (B - A + 1) < 2 * K:
    for i in range(A, B + 1):
        print(i)
else:
    for i in range(A, A + K):
        print(i)
    for i in range(B - K + 1, B + 1):
        print(i)



Measured memory_bytes: 3060
#include<iostream>
#include<fstream>
#include<cstdio>
#define Maxn 200000
int N;
char c[Maxn+5];
int cntR=0,cntW=0;
int ans=0;
using namespace std;
int main()
{
	scanf("%d",&N);
	scanf("%s",c+1);
	for(int i=1;i<=N;i++){
		if(c[i]=='R')cntR++;
		if(c[i]=='W')cntW++;
	}
	for(int i=1;i<=cntR;i++)if(c[i]=='W')ans++;
	printf("%d",ans);
	return 0;
}

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


void print_array(int *x, int n)
{
	for (int k = 0; k < n; ++k)
	{
		if (k == n- 1)
		{
			printf("%d\n", x[k]);
		}
		else
		{
			printf("%d ", x[k]);
		}
	}
}


int main(int argc, char const *argv[])
{
	int n = 0, key = 0, j;
	cin >> n;

	int array[n];

	for (int i = 0; i < n; ++i)
	{
		cin >> array[i];
	}

	print_array(array, n);

	/*===== insertion sort =====*/
	for (int i = 1; i < n; ++i)
	{
		key = array[i];
		j = i - 1;
		while(j >= 0 && array[j] > key)
		{
			array[j + 1] = array[j];
			j--;
		}
		array[j + 1] = key;
		print_array(array, n);
	}

	return 0;
}

Measured memory_bytes: 1144
// ABC060_B
#include <iostream>
#include <string>
#include <vector>
#include <iterator>
#include <tuple>
#include <map>
#include <unordered_map>
#include <set>
#include <unordered_set>
#include <stack>
#include <queue>
#include <algorithm>
#include <functional>  // std::greater<T>()
#include <utility>  // std::swap()
#include <numeric>  // accumulate(ALL(vec), 0)  0 は初期値
#include <bitset>  // static_cast<std::bitset<8>>
#include <sstream>  // std::stringstream
#include <cmath>
#include <climits>  // INT_MIN
#include <cctype>  // std::isdigit()
#include <iomanip>  // std::setprecision()
using namespace std;
using ll = long long;

#define REP(i, n) for (ll i=0; i < n; i++)  // 0 ~ n-1
#define MIN(vec) min_element(vec.begin(), vec.end())  // イテレータのため、値を取り出すときは * を先頭につける
#define MAX(vec) max_element(vec.begin(), vec.end())
#define IDX(vec, element_iter) distance((vec).begin(), element_iter)
#define SUM(vec) accumulate(vec.begin(), vec.end(), 0LL)  // 0 は初期値
#define vl vector<ll>
#define pll pair<ll, ll>
#define F first
#define S second

int main() {
    // input
    ll A, B, C;
    cin >> A >> B >> C;
    
    // calculation
    if (A == 1) {
        cout << "YES" << "\n";
    } else {
        for (ll i = 1; i <= B; ++i) {
            if ((A*i)%B == C) {
                cout << "YES" << "\n";
                return 0;
            }
        }
        cout << "NO" << "\n";
    }
    
    return 0;
}

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

class DisjointSetUnion {
  int size;
  vector<int> V;
  public:
  DisjointSetUnion(int s): size(s), V(s, -1) {
    for (int i = 0; i < s; i++) V[i] = i;
  }
  void connect(int u, int v) {
    V[find(u)] = find(v);
  }
  int find(int node) {
    int cur_node = node, p = V[node];
    while (cur_node != p) {
      V[cur_node] = V[p];
      cur_node = p;
      p = V[p];
    }
    return cur_node;
  }
  int same(int u, int v) {
    return (find(u) == find(v));
  }
};

int main() {
  int N,M; cin>>N>>M;
  DisjointSetUnion d(N);
  for (int i = 0; i < M; i++){
    int a,b;cin>>a>>b; a--;b--;
    d.connect(a, b);
  }
  set<int> S;
  for (int i = 0;i<N;i++) S.insert(d.find(i));
  cout<<S.size()-1<<endl;
}

Measured memory_bytes: 7744
#include <iostream>
#include <queue>
#include <map>
#include <cmath>
#include <algorithm>
#include <queue>
#include <cstdarg>
#include <set>
#include <limits>
#include <iomanip>

using namespace std;
#define INF 2e9 + 9
#define MOD 1000000007
#define ALL(v) v.begin() , v.end()
#define Int int64_t
#define pll pair<Int,Int>
template<class T> using pql = priority_queue<T, vector<T>>;
template<class T> using pq = priority_queue<T, vector<T>, greater<T>>;
#define ll(n) Int n; cin >> n;
#define LL(...) Int __VA_ARGS___; cin >> __VA_ARGS___;
#define OUT(...) cout << __VA_ARGS___;
#define RP(n, i, s) for(Int i = s ;i < n ;i++)
#define REP(n, i) for (Int i = 0; i < n; i++)
#define REPe(n, i) for (Int i = 1; i <= n; i++)
#define RPe(n, i, s) for (Int i = s; i <= n; i++)
#define upd_max(maxer, updater) if (maxer < updater) maxer = updater;
#define upd_min(miner, updater) if (miner > updater) miner = updater;

void ansYes(bool flag) {
    if (flag) cout << "Yes" << endl; else cout << "No" << endl;
}

void ansYES(bool flag) {
    if (flag) cout << "YES" << endl; else cout << "NO" << endl;
}

struct node {
    Int to;
    Int length;
};


vector<Int> divisor(Int n) {
    vector<Int> ret;
    for (Int i = 1; i * i <= n; i++) {
        if (n % i == 0) {
            ret.push_back(i);
            if (i * i != n) ret.push_back(n / i);
        }
    }
    return (ret);
}

/*
vector<vector<int>> to;
vector<int> flag;
vector<int> c;


Int dfs(int from, int mae) {
    flag[from] = 1;
    Int mini = 0;
    for (auto next : to[from]) {
        if (next == mae) continue;
        if (flag[next] == 1) {
            return -1;
        } else {
            mini = min(mini, dfs(next, from));
        }
    }
    return mini;
}*/

int dx8[8] = {0, -1, -1, -1, 0, 1, 1, 1};
int dy8[8] = {-1, -1, 0, 1, 1, 1, 0, -1};

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

struct datas {
    Int max;
    Int size;
};

class ContainChecker {
protected:
    Int minx, miny, maxx, maxy;
public:
    ContainChecker(Int minx, Int miny, Int maxx, Int maxy) : minx(minx), miny(miny), maxx(maxx), maxy(maxy) {};

    bool in(Int x, Int y) {
        return (minx <= x && miny <= y && x <= maxx && y <= maxy);
    }
};

Int n;
vector<string> que;
void dfs(string s,char k) {
   // cout << s << endl;
    if (s.size() == n) {
        que.push_back(s);
        return;
    }
    for (int i = 0; i <= k;i++){
        dfs(s + (char)('a'+i),i+1);
    }
}
int main(void) {
    Int d, n;
    cin >> d >> n;
    Int x;
    if (d == 0) x = 1;
    if (d == 1) x = 100;
    if (d == 2) x = 10000;
    if (n <= 99) cout << n * x << endl; else cout << 101 * x << endl;
}




Measured memory_bytes: 256
import java.util.*;

public class Main{
	public static void main(String[] $){
		System.err.println();
		Scanner s=new Scanner(System.in);
		int n=s.nextInt();

		Permutation p=new Permutation(n);

		int[]a=new int[n],b=new int[n];
		Arrays.setAll(a,i->s.nextInt()-1);
		Arrays.setAll(b,i->s.nextInt()-1);

		int i=0,A=0,B=0;
		for(int[]o:p) {
			++i;
			if(Arrays.equals(a,o))
				A=i;
			if(Arrays.equals(b,o))
				B=i;
		}
		System.out.println(Math.abs(A-B));
	}
}

class Permutation implements Iterable<int[]> {
	private final int size;

	/**
	 * <p>順列を表すクラスのコンストラクタ。反復子が返す配列の要素数を指定する。
	 * @param size 順列の要素数（10程度が妥当な最大値）
	 * @throws IllegalArgumentException 引数（順列の要素数）が0以下の場合
	 */
	public Permutation(int size) {
		if (size <= 0) throw new IllegalArgumentException();
		this.size = size;
	}

	@Override
	public Iterator<int[]> iterator() {
		return new Iter(size);
	}

	private class Iter implements Iterator<int[]> {
		private final int[] source;
		private boolean isFirst = true;

		private Iter(int size) {
			source = new int[size];
			for(int i = 0; i < size; ++i) {
				source[i] = i;
			}
		}

		/**
		 * <p>反復子がまだ順列を返しうるか調べる。
		 * 本メソッドは{@link Iter#next()}呼び出し前に必ず1回ずつ実行する必要がある。
		 * @return 順列が存在する場合はtrue
		 */
		@Override
		public boolean hasNext() {
			if (isFirst) {
				isFirst = false;
				return true;
			}

			int n = source.length;
			for (int i = n - 1; i > 0; i--) {
				if (source[i - 1] < source[i]) {
					int j = n;
					while (source[i - 1] >= source[--j]);
					swap(source, i - 1, j);
					reverse(source, i, n);
					return true;
				}
			}
			reverse(source, 0, n);
			return false;
		}

		/**
		 * <p>次の順列を表すint型配列を返す。
		 * <p>このメソッドが返す参照は常に同じ配列に対する参照である。
		 * このため配列の要素を変更したり次回の{@link Iter#next()}呼び出し後も参照する場合は、
		 * クラスの呼び出し側が配列のクローンを生成して利用する必要がある。
		 * @return 順列を表すint型配列
		 */
		@Override
		public int[] next() {
			return source;
		}

		@Override
		public void remove() {
			throw new UnsupportedOperationException();
		}

		private void swap(int[] is, int i, int j) {
			int t = is[i];
			is[i] = is[j];
			is[j] = t;
		}

		private void reverse(int[] is, int s, int t) {
			while (s < --t) swap(is, s++, t);
		}
	}
}


Measured memory_bytes: 26708
#include <bits/stdc++.h>
#define int long long
using namespace std;
const int MOD = pow(10, 9) + 7;
//const int MOD = 998244353;
//const int MOD = ;
int mod(int A, int M) {return (A % M + M) % M;}
const int INF = 1LL << 60;
template <class T> bool chmin(T& a, T b) {if (a > b) {a = b; return true;} return false;}
template <class T> bool chmax(T& a, T b) {if (a < b) {a = b; return true;} return false;}
int divCeil(int A, int B) {return (A + (B - 1)) / B;}
int myctoi(char C) {return C - 48;}
char myitoc(int N) {return '0' + N;}

signed main()
{
  int N, M;
  cin >> N >> M;

  vector<vector<bool> > G(N, vector<bool>(N));
  for (int i = 0; i < M; i++)
  {
    int a, b;
    cin >> a >> b;
    a--; b--;
    G.at(a).at(b) = true;
    G.at(b).at(a) = true;
  }
  
  vector<int> p(N);
  for (int i = 0; i < N; i++)
  {
    p.at(i) = i;
  }
  
  int ans = 0;
  do
  {
    bool ok = true;
    for (int i = 0; i < N - 1; i++)
    {
      if (!G.at(p.at(i)).at(p.at(i + 1)))
      {
        ok = false;
        break;
      }
    }
    if (ok) ans++;
  } while (next_permutation(p.begin(), p.end()) && p.at(0) == 0);
  
  cout << ans << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define int long long
#define io ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define pb push_back
#define rep(i,l,r) for(int i=l;i<r;i++)
#define bep(i,l,r) for(int i=l;i>=r;i--)
#define ld long double
#define ff first
#define ss second
#define pii pair<int,int>
#define vi vector<int>
#define vii vector<pii>
#define el '\n'
#define sz(s) s.size()
#define all(v) v.begin(),v.end()
#define mii map<int,int>
#define mr  make_pair
using namespace std;
int mod = 1e9+7;
int inf = 1e18;
const int N = 5e5+999;
int powmod(int a,int b) {int res=1;if(a>=mod)a%=mod;for(;b;b>>=1){if(b&1)res=res*a;if(res>=mod)res%=mod;a=a*a;if(a>=mod)a%=mod;}return res;}
int arr[N];
signed main()
{
    io
    int tt = 1;
    //cin>>tt;
    while(tt--)
    {
        unordered_map<int,vector<string>> mp;
        int n,m;
        cin>>n>>m;
        int x;
        string s;
        rep(i,0,m)
        {
            cin>>x>>s;
            mp[x].pb(s);
        }
        int right = 0,wrong = 0;
        for(auto x:mp)
        {
            int ct = 0;
            bool flag = false;
            for(auto xxx:mp[x.ff])
            {
                if(xxx=="AC")
                {
                    right++;
                    flag = true;
                    break;
                }
                else
                    ct++;

            }
            if(flag)
                wrong+=ct;

        }
        cout<<right<<" "<<wrong<<el;

    }
   return 0;
}


Measured memory_bytes: 13732
#define _USE_MATH_DEFINES
#include <cassert>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <string>
#include <sstream>
#include <vector>
#include <queue>
#include <stack>
#include <list>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <algorithm>
#include <complex>
#include <cmath>
#include <numeric>
#include <bitset>
#include <functional>
#include <random>
#include <ctime>

using namespace std;

#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
  cerr << name << ": " << arg1 << endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
  const char* comma = strchr(names + 1, ',');
  cerr.write(names, comma - names) << ": " << arg1 << " |";
  __f(comma + 1, args...);
}

typedef long long int64;
typedef pair<int, int> ii;
const int INF = 1 << 29;
const int MOD = 1e9 + 7;

int main() {
  int a, b, h;
  cin >> a >> b >> h;
  cout << (a + b) * h / 2 << endl;
  return 0;
}


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

int main(void)
{
  string s;
  cin>>s;
  int c=0;
  if(s[0]=='1')
    c++;
  if(s[1]=='1')
    c++;
  if(s[2]=='1')
    c++;
  cout<<c<<endl;
}

Measured memory_bytes: 256
l=[0]*4
for i in range(int(input())):
  s=input()
  if s=='AC':
    l[0]+=1
  elif s=='WA':
    l[1]+=1
  elif s=='RE':
    l[3]+=1
  else:
    l[2]+=1
print(f'AC x {l[0]}',f'WA x {l[1]}',f'TLE x {l[2]}',f'RE x {l[3]}')

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

int main() {
  int N,M;
  cin >> N >> M;
  vector<int> road(N);
  for(int i = 0;i < M;i++){
    int a, b;
  cin >> a >> b;
  road.at(a - 1)++;
  road.at(b - 1)++;
  }
  for(int k = 0;k < N;k++){
    cout << road.at(k) << endl;
  }
}
    
  
  
    

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


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

   int first = l;
   int last = n + l - 1;

   int eat_apple;
   if(last < 0)eat_apple = last;
   else if(first > 0)eat_apple = first;
   else eat_apple = 0;

   int ans = (first + last) * n / 2 - eat_apple;
   
   print(ans);
}

Measured memory_bytes: 256
const lines=readlines(open("/dev/fd/0"))
let
    state=0
    global input
    input()=lines[state+=1]
end
int(s::String)=parse(Int32,s)
intSub(s::SubString{String})=parse(Int32,s)
intLine()=map(intSub,split(input()))
function main()
    m=t=0
    for c in input()
        if c in "ACGT"
            t+=1
            m=max(m,t)
        else
            t=0
        end
    end
    print(m)
end
main()

Measured memory_bytes: 108928
fun main(args: Array<String>) {
    val nmq = readLine()!!.split(" ")
    val n = nmq[0].toInt()
    val m = nmq[1].toInt()
    val q = nmq[2].toInt()
    val values = IntRange(1, q).map {
        val input = readLine()!!.split(" ")
        IntNums(input[0].toInt(), input[1].toInt(), input[2].toInt(), input[3].toInt())
    }

    var permutation = mutableListOf<MutableList<Int>>()
    for(i in 1..m) {
        createPermutation(mutableListOf(i), n, m, permutation)
    }
    val maxVal =  permutation.map { perm -> values.filter{ perm[it.b-1] - perm[it.a-1] == it.c }.map { it.d }.sum() }.max()
    print(maxVal)

}

data class IntNums(val a: Int, val b: Int, val c:Int, val d: Int)

fun createPermutation(base: MutableList<Int>, n: Int, m: Int, result: MutableList<MutableList<Int>>) {
    if(base.size == n) {
        result.add(MutableList(base.size) { i -> base[i] })
    }
    if(base.size >= n) return

    for(i in base[base.size -1]..m) {
        var newArray = MutableList(base.size) { i -> base[i] }
        newArray.add(i)
        createPermutation(newArray,n,m, result)
    }
    return
}

Measured memory_bytes: 76116
#include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <map>
#include <numeric>
#include <string>
#include <cmath>
#include <iomanip>
#include <queue>
#include <list>
#include <stack>
#include <cctype>

using namespace std;

/* typedef */

typedef long long ll;

/* constant */

const int INF = 1 << 30;
const int mod = 1000000007;
const double pi = 3.141592653589;
/* global variables */

/* function */

/* main */
int main() {

    vector<int> cnt(26, 0);

    string S;
    while(getline(cin,S)) {
        for (int i = 0; i < S.size(); i++) {
            char ch = S[i];
            if (isalpha(ch)) {
                if (isupper(ch))
                    ch = tolower(ch);
                int ascii = ch - 'a';
                cnt[ascii]++;
            }
        }
    }

    for (int i = 0; i <= 25; i++) {
        cout << char('a' + i) << " : " << cnt[i] << '\n';
    }

}



Measured memory_bytes: 3080
n,l = map(int,input().split())
a = [0]*n
for i in range(n):
    a[i] = l + i
sum_ = sum(a)
cnt = abs(a[0])
ans = sum(a) - a[0]
for i in range(n):
    v = a[i]
    a[i] = 0
    if abs(sum_ - sum(a)) <= cnt:
        cnt = abs(sum_ - sum(a))
        ans = sum(a)
    a[i] = v
print(ans)

Measured memory_bytes: 3064
#include <iostream>
#include <algorithm>
#include <vector>
#include <math.h>
#include <iomanip>
using namespace std;
typedef long long ll;

int main() {
    ll n, ans = 1e15;
    cin >> n;
    for (ll i = 1; i <= pow(n, 0.5); i++) {
        if (n % i == 0) ans = min(ans, i + n / i);
    }
    cout << ans - 2 << endl;


}

Measured memory_bytes: 384
#include <cstdio>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <vector>
#include <string>
#include <map>
#include <set>
#include <cassert>
using namespace std;
#define rep(i,a,n) for (int i=a;i<n;i++)
#define per(i,a,n) for (int i=n-1;i>=a;i--)
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define fi first
#define se second
#define SZ(x) ((int)(x).size())
typedef vector<int> VI;
typedef long long ll;
typedef pair<int,int> PII;
const ll mod=1000000007;
ll powmod(ll a,ll b) {ll res=1;a%=mod; assert(b>=0); for(;b;b>>=1){if(b&1)res=res*a%mod;a=a*a%mod;}return res;}
// head

const int N=201000;
int dep[N],p[N][22];
int n,u,v,mc,md,pu,pv,maxd[N],mad[N],l[N],shav[N];
ll ret;
VI e[N];
char fav[N];
void dfs(int u,int f,int dis) {
	p[u][0]=f; dep[u]=dis;
	if (dis>md) md=dis,mc=u;
	for (auto v:e[u]) if (v!=f) {
		dfs(v,u,dis+1);
	}
}
#define LOGN 18
int lca(int u,int v) {
	if (dep[u]>dep[v]) swap(u,v);
	per(i,0,LOGN) if (dep[p[v][i]]>=dep[u]) v=p[v][i];
	if (u==v) return u;
	per(i,0,LOGN) if (p[v][i]!=p[u][i]) u=p[u][i],v=p[v][i];
	return p[u][0];
}
int dist(int u,int v) {
	return dep[u]+dep[v]-2*dep[lca(u,v)];
}
void solve(int u,int f) {
	mad[u]=0;
	for (auto v:e[u]) if (v!=f) {
		solve(v,u);
		mad[u]=max(mad[u],mad[v]+1);
	}
	shav[u]=mad[u]+2; // if (u,d) d>=shav[u] -> (f,d-1)
	if (fav[u]=='1') l[u]=0;
//	printf("gg %d %d\n",u,maxd[u]);
	if (f!=0) {
		if (maxd[u]>maxd[f]) {
			l[f]=min(l[f],max(l[u]-1,shav[u]-1));
//			printf("ff %d %d %d\n",u,shav[u],l[u]);
			ret+=max(0,shav[u]-l[u]);
		} else {
			// double center
			shav[u]=maxd[u]; // d>=shav[u] -> (f,d)
			l[f]=min(l[f],max(l[u],shav[u]));
			ret+=max(0,shav[u]-l[u]);

		}
	} else ret+=max(0,maxd[u]-l[u]+1);
}
int main() {
	scanf("%d",&n);
	rep(i,1,n) {
		scanf("%d%d",&u,&v);
		e[u].pb(v); e[v].pb(u);
	}
	dfs(1,0,1);
	md=0;
	pu=mc;
	dfs(pu,0,1);
	rep(j,1,LOGN) rep(i,1,n+1) p[i][j]=p[p[i][j-1]][j-1];
	pv=mc;
	rep(i,1,n+1) maxd[i]=max(dist(i,pu),dist(i,pv));
//	printf("ss %d %d\n",pu,pv);
//	rep(i,1,n+1) printf("%d ",maxd[i]); puts("");
	int rt=min_element(maxd+1,maxd+n+1)-maxd;
//	printf("root %d\n",rt);
	scanf("%s",fav+1);
	rep(i,1,n+1) l[i]=1<<30;
	solve(rt,0);
	printf("%lld\n",ret);
}


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

using namespace std;


//ifstream in("input.txt");
//ofstream out("output.txt");
//ios::sync_with_stdio(false);
typedef pair<int,int> pii;
typedef long long int ll;

int P[1005],V[1005],A[1005],B[1005];
int N,ans,x;
vector<int> albero[1005];
vector<int> S;
bitset<5010> K;

void DFS(int k)
{

    //cout<<k<<endl;
    for(int i : albero[k])
        DFS(i);

    if(albero[k].empty())
    {

        A[k]=0;
        B[k]=0;

    }
    else
    {

        S.clear();
        K.reset();

        ans=0;
        for(int i : albero[k])
        {
            ans+=min(V[i],B[i]);
            S.push_back(max(V[i],B[i])-min(V[i],B[i]));
            //cout<<k<<" "<<i<<" "<<ans<<endl;
            /*
            cout<<"V ";
            for(int i=0;i<N;i++)
                cout<<V[i+1]<<" ";
            cout<<endl;
            cout<<"A ";
            for(int i=0;i<N;i++)
                cout<<A[i+1]<<" ";
            cout<<endl;
            cout<<"B ";
            for(int i=0;i<N;i++)
                cout<<B[i+1]<<" ";
            cout<<endl;
            */
        }

        if(ans>V[k])
        {
            cout<<"IMPOSSIBLE";
            exit(0);
        }

        K[0]=true;
        for(int i=0;i<albero[k].size();i++)
            for(int j=5005-S[i];j>=0;j--)
                    K[j+S[i]] = K[j+S[i]] || K[j];

        for(x=V[k]-ans;!K[x];x--);
        ans+=x;
        A[k]=ans;

        ans=0;
        for(int i : albero[k])
            ans+=V[i]+B[i];
        B[k]=ans-A[k];

    }

}

int main()
{

    ios::sync_with_stdio(false);
    cin>>N;
    for(int i=0;i<N-1;i++)
        cin>>P[i+2];
    for(int i=1;i<N+1;i++)
        cin>>V[i];

    for(int i=2;i<=N;i++)
        albero[P[i]].push_back(i);

    DFS(1);

    cout<<"POSSIBLE";

}


Measured memory_bytes: 384
from collections import Counter
import sys

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

def main():
    n,p=MI()
    s=SI()
    if p==2 or p==5:
        ans=0
        for i,c in enumerate(s):
            if int(c)%p==0:ans+=i+1
        print(ans)
        exit()
    aa=[int(c) for c in s[::-1]]
    cc=[0]
    ten=1
    for a in aa:
        cc.append((cc[-1]+a*ten)%p)
        ten=ten*10%p
    cnt=Counter(cc)
    ans=0
    for v in cnt.values():
        ans+=v*(v-1)//2
    print(ans)

main()

Measured memory_bytes: 13620
from sys import stdin
from sys import setrecursionlimit
import bisect   
setrecursionlimit(10 ** 7)

k = int(input())
now = 7

for i in range(1,10**6+1):
    if now%k == 0:
        print(i)
        exit()
    now *= 10
    now += 7
    now %= k

print(-1)

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

int main(){
    int n,m;    cin>>n>>m;
    int x[n+1]; cin>>x[0];
    int y[m+1]; cin>>y[0];

    for(int i=1;i<=n;i++)cin>>x[i];
    for(int i=1;i<=m;i++)cin>>y[i];

    bool flag=false;

    for(int i=0;i<=n;i++){
        for(int j=0;j<=m;j++){
            if(y[j]<=x[i]){
                flag=true;
                break;
            }
        }
        if(flag==true)break;
    }

    flag==true? cout<<"War"<<endl : cout<<"No War"<<endl;



    return 0;
}


Measured memory_bytes: 256
use std::io::BufRead;
use std::str::FromStr;

struct Student {
    seq: i32,
    num: i32
}

fn main() {
    let stdin = std::io::stdin();
    let mut t = Tokenizer::new(stdin.lock().lines().map(|x| x.unwrap()));

    let n: i32 = t.take();
    let mut h: Vec<Student> = Vec::new();
    for i in 1 .. n+1 {
        h.push( Student { seq: i, num: t.take() } );
    }
    h.sort_by(|a,b| a.num.partial_cmp(&b.num).unwrap() );
    for i in h.iter() {
        print!( "{} ", i.seq );
    }
    println!("");
}


#[cfg(test)]
mod test {
    use super::*;
    #[test]
    fn test1() {
        let result = problem( 5 );
        assert_eq!(result,vec![3,6,1]);
    }
}


struct Tokenizer<S: Iterator<Item = String>> {
    input: S,
    items: Vec<String>,
}

impl<S: Iterator<Item = String>> Tokenizer<S> {
    pub fn new(input: S) -> Self {
        Tokenizer {
            input: input,
            items: Vec::new(),
        }
    }

    pub fn take<T: FromStr>(&mut self) -> T {
        loop {
            if let Some(r) = self.items.pop() {
                return r.parse().ok().expect("parse failed");
            }
            let mut items = self
                .input
                .next()
                .unwrap()
                .split_whitespace()
                .map(|x| x.to_string())
                .collect::<Vec<String>>();
            items.reverse();
            self.items = items;
        }
    }
}


Measured memory_bytes: 10492
#include <bits/stdc++.h>
#define rep(i, a, n) for(int i = a; i < n; i++)
#define int long long
using namespace std;
typedef pair<int, int> P;
const int mod = 1000000007;
const int INF = 1e18;

signed main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    int m1, d1, m2, d2;
    cin >> m1 >> d1 >> m2 >> d2;
    cout << (d2 == 1) << endl;
}

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

int main() {
  int k, n, f, p, m = 0;
  scanf("%d %d", &k, &n);
  scanf("%d", &p);
  f = p;
  for(int i = 1; i < n; i++) {
    int a;
    scanf("%d", &a);
    m = max(m, a - p);
    p = a;
  }
  m = max(m, k - p + f);
  printf("%d\n", k - m);
}

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

int main(){
	int a, b, d, r;
	double f;
	cin >> a >> b;
	d=a/b;
	r=a%b;
	f=(double)a/(double)b;
	// cout << d << " " << r << " " << f << endl;
	printf("%d %d %0.5lf\n", d, r, f);
	return 0;
}

Measured memory_bytes: 3208
#include <stdio.h>

int main()
{
	int L, A, B, C, D;
	scanf("%d%d%d%d%d", &L, &A, &B, &C, &D);
	if (A%C == 0)A = A / C;
	else A = A / C + 1;
	if (B%D == 0)B = B / D;
	else B = B / D + 1;
	printf("%d\n", L - (A > B ? A : B));
	return 0;
}

Measured memory_bytes: 596
#include<algorithm>
#include<iostream>
#include<vector>
#include<string>
#include<queue>
#include<stack>
#include<cmath>
#include<list>
#include<set>
#include<map>

using namespace std;
long long MOD = 1000000007LL;

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

	vector<int> costmap(N);
	costmap[0] = 0;
	costmap[1] = abs(H[1] - H[0]);

	int X = 2;
	for (; X < N; ++X) {
		costmap[X] = min(abs(H[X] - H[X - 1]) + costmap[X - 1], abs(H[X] - H[X - 2]) + costmap[X - 2]);
	}

	cout << costmap[N - 1] << endl;

	return 0;
}


Measured memory_bytes: 1024
#define _USE_MATH_DEFINES
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<climits>
#include<string>
#include<vector>
#include<list>
#include<map>
#include<set>
#include<cmath>
#include<queue>
#include<cstring>
#include<stack>
#include<functional>
using namespace std;
const int INF = INT_MAX / 2;

typedef long long ll;

int N;
ll d[10], v[10];

ll GCD(ll a, ll b)
{
	if(b == 0) return a;
	return GCD(b, a % b);
}

ll LCM(ll a, ll b)
{
	return a / GCD(a, b) * b;
}

int main(){
	while(cin >> N, N)
	{
		int p, d1, d2;
		int ans_n, ans_d = -1;
		for(int i = 0; i < N; i++)
		{
			cin >> p >> d1 >> d2;
			if(d1 + d2 > ans_d) ans_n = p, ans_d = d1 + d2;
		}
		printf("%d %d\n", ans_n, ans_d);
	}
	return 0;
}

Measured memory_bytes: 1144
#include<stdio.h>

int main(void)
{
  int i;
  int N;
  int l[1001],r[1001];
  int sum=0;

  scanf("%d",&N);
  
  for(i=0;i<N;i++){
  scanf("%d %d",&l[i],&r[i]);
  sum+=(r[i]-l[i]+1);
  }
  
  printf("%d\n",sum);
  
  return 0;
  }

Measured memory_bytes: 128
#include <iostream>
#include <vector>
#include <climits>
#include <algorithm>
#include <cmath>
#include <map>
#include <set>
#include <string>
#include <bitset>
#include <utility>
#include <numeric>

using ll = long long;
using namespace std;

constexpr int MOD = 1e9 + 7;
constexpr ll MOD_LL = ll(1e9) + 7;

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


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

using namespace std;

using i64 = int64_t;

const i64 MOD = 1e9 + 7;

signed main(){
    int n;
    string s, t;
    cin >> n >> s >> t;

    vector<i64> dp(26, 0);
    dp[s[0] - 'a'] = 1;
    for(int i = 1; i < n - 1; ++i){
        dp[s[i] - 'a'] += dp[t[i] - 'a'];
        dp[s[i] - 'a'] %= MOD;
    }
    cout << dp[t.back() - 'a'] << endl;
}



Measured memory_bytes: 3292