akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>

#define rep(i, n) for (int i = 0; i < int(n); i++)
#define rrep(i, n) for (int i = int(n) - 1; i >= 0; i--)
#define reps(i, n) for (int i = 1; i <= int(n); i++)
#define rreps(i, n) for (int i = int(n); i >= 1; i--)
#define repc(i, n) for (int i = 0; i <= int(n); i++)
#define rrepc(i, n) for (int i = int(n); i >= 0; i--)
#define repi(i, a, b) for (int i = int(a); i < int(b); i++)
#define repic(i, a, b) for (int i = int(a); i <= int(b); i++)
#define all(a) (a).begin(), (a).end()
#define bit32(x) (1 << (x))
#define bit64(x) (1ll << (x))
#define sz(v) ((int) v.size())

using namespace std;

using i64 = long long;
using f80 = long double;
using vi32 = vector<int>;
using vi64 = vector<i64>;
using vf80 = vector<f80>;
using vstr = vector<string>;

inline void yes() { cout << "Yes" << endl; exit(0); }
inline void no() { cout << "No" << endl; exit(0); }
inline i64 gcd(i64 a, i64 b) { if (min(a, b) == 0) return max(a, b); if (a % b == 0) return b; return gcd(b, a % b); }
inline i64 lcm(i64 a, i64 b) { if (min(a, b) == 0) return max(a, b); return a / gcd(a, b) * b; }
template <typename T> class pqasc : public priority_queue<T, vector<T>, greater<T>> {};
template <typename T> class pqdesc : public priority_queue<T, vector<T>, less<T>> {};
template <typename T> inline void amax(T &x, T y) { x = max(x, y); }
template <typename T> inline void amin(T &x, T y) { x = min(x, y); }
template <typename T> inline T exp(T x, i64 n, T e = 1) { T r = e; while (n > 0) { if (n & 1) r *= x; x *= x; n >>= 1; } return r; }
template <typename T> istream& operator>>(istream &is, vector<T> &v) { for (auto &x : v) is >> x; return is; }
template <typename T> ostream& operator<<(ostream &os, vector<T> &v) { rep(i, v.size()) { if (i) os << ' '; os << v[i]; } return os; }
void solve(); int main() { ios::sync_with_stdio(0); cin.tie(0); cout << fixed << setprecision(16); solve(); return 0; }

void solve() {
  int n;
  cin >> n;
  int k = 0;
  using P = pair<int, int>;
  using vvp = vector<vector<P>>;
  auto rec = [&](auto rec, int n, int col) -> vvp {
    if (n == 1) {
      return vvp(1);
    }
    int na = (n + 0) / 2;
    int nb = (n + 1) / 2;
    vvp a = rec(rec, na, col + 1);
    vvp b = rec(rec, nb, col + 1);
    rep(i, nb) {
      for (auto& p : b[i]) {
        p.first += na;
      }
      a.emplace_back(b[i]);
    }
    rep(i, na) rep(j, nb) {
      int u = i;
      int v = na + j;
      a[u].emplace_back(v, col);
      a[v].emplace_back(u, col);
    }
    return a;
  };
  auto res = rec(rec, n, 1);
  auto ans = vector<vi32>(n, vi32(n));
  rep(u, n) {
    for (auto p : res[u]) {
      int v, c;
      tie(v, c) = p;
      ans[u][v] = c;
      ans[v][u] = c;
    }
  }
  rep(i, n - 1) repi(j, i + 1, n) {
    cout << ans[i][j] << (j == (n - 1) ? '\n' : ' ');
  }
}


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

void listShuffle(const int n, int* cards) {
    int* nCards = new int [n + 1];
    for (int i = 1; i <= n; i++) {
        nCards[i] = cards[n + i];
    }
    for (int i = n; i > 0; i--) {
        cards[2 * i - 1] = cards[i];
    }
    for (int i = 1; i <= n; i++) {
        cards[2 * i] = nCards[i];
    }
    delete[] nCards;
}

void cutByK(const int k, const int n, int* cards) {
    int* kCards = new int [k + 1];
    for (int i = 1; i <= k; i++) {
        kCards[i] = cards[i];
    }
    for (int i = 1; i <= 2 * n - k; i++) {
        cards[i] = cards[k + i];
    }
    for (int i = 1; i <= k; i++) {
        cards[2 * n - k + i] = kCards[i];
    }
    delete[] kCards;
}

int main() {
    int n, m;
    cin >> n >> m;
    int* cards = new int [2 * n + 1];
    for (int i = 1; i <= 2 * n; i++) {
        cards[i] = i;
    }
    for (int i = 0; i < m; i++) {
        int k;
        cin >> k;
        if (k == 0) {
            listShuffle(n, cards);
        } else if (1 <= k && k <= 2 * n - 1) {
            cutByK(k, n, cards);
        }
    }
    for (int i = 1; i <= 2 * n; i++) {
        cout << cards[i] << endl;
    }
    delete[] cards;
}

Measured memory_bytes: 0
#include<stdio.h>
#include<math.h>
 
int main(void){
   
  int  x,h;
  double high;
 
  while(1){
    scanf("%d %d",&x,&h);
    if(!x && !h)break;
 
    high = sqrt( x/2.0 * x/2.0 + h*h);
 
    printf("%lf\n",x*x + 2*high*x);
  }
 
  return 0;
}

Measured memory_bytes: 632
#include <cstdio>
#include <cstring>
#include <iostream>
#include <string>
#include <cmath>
#include <bitset>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <algorithm>
#include <complex>
#include <unordered_map>
#include <unordered_set>
#include <random>
#include <cassert>
#include <fstream>
#include <utility>
#include <functional>
#include <time.h>
#include <stack>
#include <array>
#include <list>
#define popcount __builtin_popcount
using namespace std;
typedef long long int ll;
typedef pair<int, int> P;

int main()
{
    int n;
    cin>>n;
    int d[505][505], a[505][505];
    for(int i=0; i<n; i++){
        for(int j=0; j<n; j++){
            a[i][j]=1;
            d[i][j]=min({i+1, j+1, n-i, n-j});
        }
    }
    int dx[4]={1, -1, 0, 0}, dy[4]={0, 0, 1, -1};
    int ans=0;
    for(int i=0; i<n*n; i++){
        int p; cin>>p; p--;
        int x=p/n, y=p%n;
        d[x][y]--;
        a[x][y]=0;
        ans+=d[x][y];
        queue<P> que;
        que.push({x, y});
        while(!que.empty()){
            P p=que.front(); que.pop();
            int x1=p.first, y1=p.second;
            for(int k=0; k<4; k++){
                int x2=x1+dx[k], y2=y1+dy[k];
                if(x2<0 || x2>=n || y2<0 || y2>=n) continue;
                if(d[x2][y2]>d[x1][y1]+a[x2][y2]){
                    d[x2][y2]=d[x1][y1]+a[x2][y2];
                    que.push({x2, y2});
                }
            }
        }
    }
    cout<<ans<<endl;
	return 0;
}


Measured memory_bytes: 5568
#include<stdio.h>

int main(){

double a,b,c,d,e,f;
double x,y;

while(scanf("%lf %lf %lf %lf %lf %lf",&a,&b,&c,&d,&e,&f)!=EOF){
y=(c*d-a*f)/(b*d-a*e);
x=(c*e-b*f)/(a*e-b*d);
if(x==-0)x=0;if(y==-0)y=0;
printf("%.3lf %.3lf\n",x,y);
}
return 0;
}

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

using namespace std;

vector<vector<long long int>>graph;

long long int saiki( long long int N ) {
	if( graph[N].size() == 0 ) {
		return 0;
	}
	vector<long long int>D( graph[N].size() );
	for( size_t i = 0; i < graph[N].size(); i++ ) {
		D[i] = saiki( graph[N][i] );
	}
	sort( D.rbegin(), D.rend() );
	for( size_t i = 0; i < graph[N].size(); i++ ) {
		D[i] += i + 1;
	}
	sort( D.rbegin(), D.rend() );
	//cout << N + 1 << " " << D[0] << endl;
	return D[0];
}

int main() {
	long long int N;
	cin >> N;
	vector<long long int>D( N );
	graph = vector<vector<long long int>>( N );
	for( size_t i = 1; i < N; i++ ) {
		cin >> D[i];
		D[i]--;
		graph[D[i]].push_back( i );
	}
	cout << saiki( 0 ) << endl;
}

Measured memory_bytes: 20608
#include "bits/stdc++.h"
using namespace std;
#define ll long long int
#define rep(i,n) for( int i = 0; i < n; i++ )
#define rrep(i,n) for( int i = n; i >= 0; i-- )
#define REP(i,s,t) for( int i = s; i <= t; i++ )
#define RREP(i,s,t) for( int i = s; i >= t; i-- )
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define INF 2000000000
#define mod 1000000007
#define INF2 1000000000000000000


int main(void)
{
	cin.tie(0);
	ios::sync_with_stdio(false);
	int N; cin >> N;
	string S[N * 2];
	rep(i, N) cin >> S[i];
	rep(i, N) S[i] += S[i];
	rep(i, N) S[i].pop_back();
	rep(i, N) S[N + i] = S[i];

	int flag1 = 1;
	int flag2 = 1;
	int flag3 = 1;
	rep(i, N) {
		rep(j, N) {
			if (S[i][j] != S[j][i]) {
				flag1 = 0;
				break;
			}
		}
	}
	rep(i, N - 1) {
		rep(j, N) {
			// cout << S[i + 1][j] << " " << S[0][(j + i) % N];
			if (S[i + 1][j] != S[0][(j + i + 1) % N]) {
				flag3 = 0;
				break;
			}
		}
		// cout << endl;
	}
	rep(i, N) {
		rep(j, N) {
			if (S[i][j] != S[N - j - 1][N - i - 1]) {
				flag2 = 0;
				break;
			}
		}
	}
	int flag4 = 0;
	rep(A, N) {
		int ok = 1;
		rep(i, N) {
			rep(j, N) {
				if (S[i + A][j] != S[j + A][i]) {
					ok = 0;
					break;
				}
				if (!ok) break;
			}
		}
		flag4 += ok;
	}
	/*
	rep(B, N) {
	int ok = 1;
	rep(i, N) {
	rep(j, N) {
	if (S[i][j + B] != S[j][i + B]) {
	ok = 0;
	break;
	}
	if (!ok) break;
	}
	}
	flag4 += ok;
	}
	*/
	//dump(flag4);
	cout << flag4 * N << endl;

	return 0;
}


Measured memory_bytes: 768
#include<iostream>
using namespace std;
#define PRICE_CAKE 4
#define PRICE_DONUT 7
#define MAX_PRICE 100
int main()
{
    int max_cake = MAX_PRICE / PRICE_CAKE + 1;
    int max_donut = MAX_PRICE / PRICE_DONUT + 1;
    int price;
    cin >> price;
    for(int i = 0; i <= max_cake; ++i)
    {
        for(int j = 0; j <= max_donut; ++j)
        {
            if(price == i * PRICE_CAKE + j * PRICE_DONUT)
            {
                cout << "Yes\n";
                return 0;
            }
        }
    }
        cout << "No\n";
    return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main { 
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int A = sc.nextInt();
    int B = sc.nextInt();
    int C = sc.nextInt();
    int total = A + B + C;
    int min = Math.min(Math.min(A,B),Math.min(B,C));
    int max = Math.max(Math.max(A,B),Math.max(B,C));
    int middle = total - min - max;
    int ans =0;
    ans = max - middle;
    min += ans;
    ans += (max - min) / 2;
    if ((max - min) % 2 == 1) ans+=2;
    System.out.println(ans);
  }
}    

Measured memory_bytes: 36052
#[allow(unused_imports)]
use std::cmp::*;
#[allow(unused_imports)]
use std::collections::*;
#[allow(unused_imports)]
use std::iter::*;
#[allow(unused_imports)]
use std::*;

macro_rules! test {
    ($($input:expr => $output:expr),* $(,)*) => {
#[test]
        fn solve_test() {
            $(
                assert_eq!(solve($input), $output);
            )*
        }
    };
}
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
    ($($r:tt)*) => {
        let mut s = {
            use std::io::Read;
            let mut s = String::new();
            std::io::stdin().read_to_string(&mut s).unwrap();
            s
        };
        let mut iter = s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
}

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

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

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

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

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

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

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

macro_rules! stdin {
    () => {{
        use std::io::Read;
        let mut s = String::new();
        std::io::stdin().read_to_string(&mut s).unwrap();
        s
    }};
}

fn main() {
    println!("{}", solve(&stdin!()));
}
fn solve(src: &str) -> String {
    input! {
        source = src,
        n:isize,
        k:isize,
    }
    let px = n % k;
    min(px, k - px).to_string()
}
test! {
    "7 4" => "1",
    "2 6" => "2",
    "1000000000000000000 1" => "0",
}


Measured memory_bytes: 2108
import sys
readline = sys.stdin.readline

X,Y,Z,K = map(int,readline().split())

A = sorted(list(map(int,readline().split())),reverse = True)
B = sorted(list(map(int,readline().split())),reverse = True)
C = sorted(list(map(int,readline().split())),reverse = True)

# AとBを組み合わせたケーキの上位K位を作る
AB = []
for a in range(len(A)):
  for b in range(len(B)):
    AB += [A[a] + B[b]]
    
AB = sorted(AB,reverse = True)[:K]

# ABとCを組み合わせたケーキの上位K位を作る
ans = []
for ab in range(len(AB)):
  for c in range(len(C)):
    ans += [AB[ab] + C[c]]
    
ans = sorted(ans,reverse = True)[:K]
for a in ans:
  print(a)

Measured memory_bytes: 146380
from collections import deque
from sys import stdin

def main():
    S = deque([s for s in input()])
    Q = int(input())
    order = True
    for i in range(Q):
        query = stdin.readline()
        t = int(query[0])
        if t == 1:
            order = not order
        else:
            f = int(query[2])
            c = query[4]
            if not order:
                f = 3  - f # 2, 1 -> 1, 2
            left = True
            if f == 1:
                S.appendleft(c)
            else:
                S.append(c)
    if not order:
        S.reverse()
    print(''.join(S))

if __name__ == '__main__':
    main()


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

int main (void){
  long int n,ans = 0;
  cin >> n;
  vector<long int> a(n,0);

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

cout << ans << endl;
return 0;

}


Measured memory_bytes: 3596
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
#define repA(a,i,n) for(int i=a;i<n;i++)
#define trav(a,x)for(auto &a: x)
#define fll(a) memset(a,0,sizeof(a));
#define mp make_pair
#define pb push_back
#define all(x) x.begin(),x.end()
#define F first
#define S second
#define itr(it,x) for(auto it=x.begin();it!=x.end();it++)
typedef long long ll;
typedef long double ld;
typedef pair<int,int>pii;
typedef vector<int>vi;
typedef map<int,int>ma;
#define fastio ios_base::sync_with_stdio(false); cin.tie(NULL);
void fopen()
{
    freopen("input.txt","r",stdin);
    freopen("output.txt","w",stdout);   
}
int main()
{
    int h,a;
    cin>>h>>a;
    cout<<h/a+1*bool(h%a);
    
}

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.at(i);
  sort(A.begin(),A.end());
  cout<<A.at(N-1)-A.at(0)<<endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<(n);i++)
using ll = long long;
using P = pair<int,int>;
int main(void) {
    int x; cin >> x;
    string ans;
    if(x < 1200) ans = "ABC";
    else ans = "ARC";
    cout << ans;
}


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

int main() {
    char ch, b[4];
    int a[4], s1= 0,s2 = 0, i, j, k, m;
    for (i = 0; i < 4; i++) {
        cin >> ch;
        a[i] = ch - '0';
        s1 += a[i];
    }
    if (s1 == 7) cout << a[0] << '+' << a[1] << '+' << a[2] << '+' << a[3] << "=7" << endl;
    else {
		s2 = a[0] - a[1] - a[2] - a[3];
        if (s2 == 7) cout << a[0] << '-' << a[1] << '-' << a[2] << '-' << a[3] << "=7" << endl;
		else {
			for (k = 0; k < 2; k++) {
				for (i = 1; i < 4; i++) {
					for (j = 1; j < 4; j++) {
						if (j == i) k == 0 ? b[j] = '+' : b[j] = '-';
						else k == 0 ? b[j] = '-' : b[j] = '+';
					}
					m = k == 0 ? s2 + 2 * a[i]: s1 - 2 * a[i];
					if (m == 7) { cout << a[0] << b[1] << a[1] << b[2] << a[2] << b[3] << a[3] << "=7" << endl; exit(0); }
				}
			}
		}   
    }
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
    #include <ext/pb_ds/assoc_container.hpp> 
    #include <ext/pb_ds/tree_policy.hpp> 
    using namespace std;
    using namespace __gnu_pbds; 
    #define lli long long int
    #define fr(i,a,b) for(lli i=a;i<b;i++)
    #define bfr(i,a,b) for(lli i=a;i>=b;i--)
    #define fio ios_base::sync_with_stdio(false); cin.tie(NULL),cout.tie(NULL);
    #define tc int t;cin>>t;while(t--)
    #define mod 1000000007LL
    #define mod2 998244353LL
    #define all(vec) vec.begin(),vec.end()  
    #define ld long double
    #define pb push_back

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



    int main()
    {
                           
             

           
                        
              fio

              string s;
              cin>>s;
              if(s[0]=='7' || s[1]=='7' || s[2]=='7')cout<<"Yes";
              else cout<<"No";
              
              
return 0;}

Measured memory_bytes: 3652
#include<stdio.h>
#include<stdlib.h>
#include<string.h>


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

	int a[M];
	int b[M];
	int count[50] = {0};
	for (int i = 0; i < M; i++)
	{
		scanf("%d %d",&a[i],&b[i]);
	}

	for(int i = 0; i < M; i++){
		count[a[i] - 1]++;
		count[b[i] - 1]++;
	}

	for(int i = 0; i < N; i++){
		printf("%d\n",count[i]);
	}
	
	return 0;
}

Measured memory_bytes: 128
import java.util.Scanner;

/**
 * https://abc050.contest.atcoder.jp/tasks/abc050_b
 */
public class Main {

	public static void main(String[] args) {
		
		Scanner sc = new Scanner(System.in);
		int N = Integer.parseInt(sc.next());
		int[] t = new int[N];
		long sum = 0;
		for(int i=0; i<N; i++){
			t[i] = Integer.parseInt(sc.next());
			sum = sum + t[i];
		}
		int M = Integer.parseInt(sc.next());
		long[] ans = new long[M];
		for(int i=0; i<M; i++){
			int p = Integer.parseInt(sc.next())-1;
			int x = Integer.parseInt(sc.next());
			ans[i] = sum - t[p] + x;
		}
		sc.close();

		for(long a: ans) System.out.println(a);
		
	}

}


Measured memory_bytes: 22996
#include <iostream>
#include <sstream>
#include <fstream>
#include <string>
#include <vector>
#include <tuple>
#include <deque>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <algorithm>
#include <functional>
#include <utility>
#include <bitset>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <cstdio>
#include <numeric>
#include <string.h>
#define rep(i, x) for (int i = 0; i < (int)(x); i++)
#define repn(i, x) for (int i = 1; i <= (int)(x); i++)
#define repr(i, x) for (int i = ((int)(x) - 1); i >= 0; i--)
#define reprn(i, x) for (int i = ((int)(x)); i > 0; i--)
#define all(x) (x).begin(),(x).end()
typedef long long int64;
using namespace std;
const double PI = 3.14159265358979323846;
const double EPS = 1e-12;
const int INF = 1<<29;
const long long INFL = 1e18;
const int MOD = 1000000007;
const int MAX = 210000;

int gcd(int a, int b) {
    return b != 0 ? gcd(b, a % b) : a;
}

//逆元を求める関数
long long fac[MAX], finv[MAX], inv[MAX];
void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++) {
      fac[i] = fac[i-1] * i % MOD;
      inv[i] = MOD - inv[MOD%i] * (MOD/i) % MOD;
      finv[i] = finv[i-1] * inv[i] % MOD;
    }
}
//組み合わせ
long long COM (int n, int k) {
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n-k] % MOD) % MOD;
}

void solve() {
		int n; cin >> n;
		vector<int> a(n);
		bool no_one = true;
		rep (i, n) {
			cin >> a[i];
			if (a[i] == 1) no_one = false;
		}
		if (no_one) {
			cout << -1 << endl;
			return;
		}
		int target = 1;
		int sum = 0;
		rep (i, n) {
			if (a[i] != target) sum++;
			else target++;
		}
		cout << sum << endl;
    return;
}

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



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

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

int main()
{
    int a, b, c, d;
    scanf("%d%d%d%d", &a, &b, &c, &d);
    printf("%d\n", std::max(std::min(b, d) - std::max(a, c), 0));

    return 0;
}

Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main() {
	int n, x, i, j, k, count;
	while (1) {
		cin >> n >> x;
		if (n == 0 && x == 0) {
			break;
		}
		count = 0;
		for (i = 1; i <= n; i++) {
			for (j = i + 1; j <= n; j++) {
				for (k = j + 1; k <= n; k++) {
					if (i + j + k == x) {
						count++;
					}
				}
			}
		}
		cout << count << endl;
	}
	
	return 0;
}


Measured memory_bytes: 3112
#include <stdio.h>
#include <stdlib.h>
#define int long long
#define inf (int)(2e9)

int N, *A;

int ABS(int x){
	return x >= 0 ? x : -x;
}

int val(int b){
	int i, ans = 0;
	for(i = 0; i < N; i++){
		ans += ABS(A[i] - (b + i + 1));
	}
	return ans;
}

int min(int a, int b){
	return a <= b ? a : b;
}

signed main(){
	int i;
	scanf("%lld", &N);
	A = (int *)malloc(sizeof(int) * N);
	for(i = 0; i < N; i++){
		scanf("%lld", &A[i]);
	}
	int l = -inf, h1, h2, r = inf;
	while(r - l > 2){
//		printf("(l, r) = (%lld, %lld)\n", l, r);
		h1 = (r + 2 * l) / 3;
		h2 = (2 * r + l) / 3;
//		printf("(h1, h2) = (%lld, %lld)\n", h1, h2);
//		printf("(val(h1), val(h2)) = (%lld, %lld)\n", val(h1), val(h2));
		if(val(h1) < val(h2)){
			r = h2;
		}
		else{
			l = h1;
		}
	}
//	printf("(l, r) = (%lld, %lld)\n", l, r);
	printf("%lld\n", min(min(val(l), val(r)), val((l + r) / 2)));
	return 0;
}

Measured memory_bytes: 1664
#
# Written by NoKnowledgeGG @YlePhan
# ('ω')
#
#import math
#mod = 10**9+7
#import itertools
#import fractions
#import numpy as np
#mod = 10**4 + 7
"""def kiri(n,m):
  r_ = n / m
  if (r_ - (n // m)) > 0:
    return (n//m) + 1
  else:
    return (n//m)"""

""" n! mod m 階乗
mod = 1e9 + 7
N = 10000000
fac = [0] * N
def ini():
  fac[0] = 1 % mod
  for i in range(1,N):
    fac[i] = fac[i-1] * i % mod"""

"""mod = 1e9+7
N = 10000000
pw = [0] * N
def ini(c):
  pw[0] = 1 % mod
  for i in range(1,N):
    pw[i] = pw[i-1] * c % mod"""

"""
def YEILD():
  yield 'one'
  yield 'two'
  yield 'three'
generator = YEILD()
print(next(generator))
print(next(generator))
print(next(generator))
"""
"""def gcd_(a,b):
  if b == 0:#結局はc,0の最大公約数はcなのに
    return a
  return gcd_(a,a % b) # a = p * b + q"""
"""def extgcd(a,b,x,y):
  d = a
  if b!=0:
    d = extgcd(b,a%b,y,x)
    y -= (a//b) * x
    print(x,y)
  else:
    x = 1
    y = 0
  return d"""
# 最大公約数 と 最小公倍数
"""def gcd(a,b):
  if b == 0:
    return a
  return gcd(b, a % b)
def lcm(a,b):
  g = gcd(a,b)
  return (a * b) // g"""

def readInts():
  return list(map(int,input().split()))
mod = 10**9 + 7

def main():
  A,B,C,D,E,F = readInts()
  dic = {}
  for a in range(31):# 30まで
    for b in range(31): # 30まで
      for c in range(101): # 100まで
        for d in range(101):
          w = (100*A)*a + (100 * B ) *b
          s = C * c + D * d
          if w == 0:
            break
          if w + s > F:
            break
          else:
            if w/100 * E >= s:
              mitudo = 100 * s / (w + s)
              dic[a,b,c,d] = mitudo
  maxV = max(dic.values())
  for k,v in dic.items():
    if v == maxV:
      print((100*A)*k[0] + (100*B)*k[1] + C*k[2] + D*k[3],C*k[2] + D*k[3])
      exit()
if __name__ == '__main__':
  main()

Measured memory_bytes: 39652
#define _GLIBCXX_DEBUG
#define rep(i,n) for(int i=0;i<n;i++)
#include <bits/stdc++.h>
#include <numeric>
using namespace std;
typedef long long ll;
const int mod= 1e+9+7;

int main() {
    ll x; cin>>x;
    ll cnt=0;
    for(int i=1;i<=x;i++){
        cnt+=i;
        if(cnt>=x){
            cout<<i<<endl;
            return 0;
        }
    }
}



Measured memory_bytes: 256
stack = []
top = 0
def push(a):
    global top
    stack[top] = a
    top += 1 

def pop():
    global top
    top -= 1
    return stack[top]


if __name__ == '__main__':
    stack.extend(range(0,10000,1))
    s = str(input()).split()
    for c in s:
        #print(stack)
        if c == '+':
            push((pop())+pop())
        elif c == '-':
            push((-pop())+pop())
        elif c == '*':
            push(pop()*pop())
        else:
            push(int(c))
    print(pop())





Measured memory_bytes: 5928
#include <iostream>
#include <vector>
#include <string>
#include <cstring>
#include <queue>
#include <set>
#include <stack>
#include <map>
#include <unordered_map>
#include <cmath>
#include <utility> // pair make_pair
#include <algorithm>
#include <functional>
#include <iomanip>
#include <climits> // LLONG_MAX, LLONG_MIN, INT_MIN, INT_MAX
#include <assert.h>

#define m0(x) memset(x,0,sizeof(x))
#define m1(x) memset(x,63,sizeof(x))
#define fill(x,y) memset(x,y,sizeof(x))
#define ll long long
//#define int ll
#define INF INT_MAX/10
#define MOD 1000000007

using namespace std;
using Pi = pair<int, int>;
using Graph = vector<vector<int> >;
using WeightGraph = vector<vector<Pi> >;

int Input[100100];

int main() {
  string S; cin >> S;
  if (S == "A") {
    cout << "T" << endl;
  } else if (S== "T") {
    cout << "A" << endl;
  } else if (S == "G") {
    cout << "C" << endl;
  } else if (S == "C") {
    cout << "G" << endl;
  }
}


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

#define all(a) (a).begin(), (a).end()
#define rall(a) (a).rbegin(), (a).rend()
#define MIN(a) *min_element(all(a))
#define MAX(a) *max_element(all(a))
#define SUM(a) accumulate(all(a), 0LL)
#define REP(i, n) for(int (i)=0; (i)<(n); (i)++)
#define RREP(i, n) for(int (i)=(n)-1; (i)>=0; (i)--)
#define FOR(i, m, n) for(int (i)=(m); (i)<(n); i++)
#define FORR(i, m, n) for(int (i)=(n)-1; (i)>=(m); i--)
#define debug(x) cerr << #x << " = " << x << endl
//#define int long long

typedef long long ll;
//ll const MOD = 998244353;
ll const MOD = 1e9+7;
int const inf = 1e9;
ll const INF = 1e18;

inline void ios_(){cin.tie(0); ios::sync_with_stdio(false);}
template<typename T> int size(const T& a){return (int)a.size();}
template<typename T> T Div(T a, T b){return (a + b - 1) / b;}
template<typename T> bool chmin(T& a, const T& b){if(a > b){a = b; return true;} return false;}
template<typename T> bool chmax(T& a, const T& b){if(a < b){a = b; return true;} return false;}



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

    vector<pair<int,int>> v, u;
    REP(i, n){
        string s;
        cin >> s;
        int a = 0, b = 0;
        REP(j, s.size()){
            if(s[j] == '(') b++;
            else b--;
            chmin(a, b);
        }
        if(b >= 0){
            v.emplace_back(make_pair(a, b));
        }else{
            int d = -b;
            int c = a - b;
            u.emplace_back(make_pair(c, d));
        }
    }

    sort(all(v), [](const auto& a, const auto& b){return a.first > b.first;});
    sort(all(u), [](const auto& a, const auto& b){return a.first > b.first;});

    int sumv = 0;
    REP(i, v.size()){
        if(sumv + v[i].first < 0){
            cout << "No" << endl;
            return 0;
        }
        sumv += v[i].second;
    }

    int sumu = 0;
    REP(i, u.size()){
        if(sumu + u[i].first < 0){
            cout << "No" << endl;
            return 0;
        }
        sumu += u[i].second;
    }

    cout << (sumv == sumu ? "Yes" : "No") << endl;
    return 0;
}


Measured memory_bytes: 11236
from collections import defaultdict
d = defaultdict(str)
k = defaultdict(str)

S = input()
T = input()

ans = "Yes"

for i in range(len(S)):
  if d[S[i]] and d[S[i]] != T[i]:
    ans = 'No'
    break

  if k[T[i]] and k[T[i]] != S[i]:
    ans = 'No'
    break

  d[S[i]] = T[i]
  k[T[i]] = S[i]

print(ans)

Measured memory_bytes: 3932
N, M = map(int, input().split())

halls = [int(input()) for i in range(M)]

dp = [1] * (N + 1)
for i in range(len(halls)):
    dp[halls[i]] = 0

for i in range(2, N + 1):
    if dp[i] == 0:
        continue
    dp[i] = dp[i - 1] + dp[i - 2]

print(dp[N] % 1000000007)

Measured memory_bytes: 460020
N=int(input())
x=[];y=[]
for i in range(N):
    xi,yi=map(int,input().split())
    x.append(xi);y.append(yi)
ans=0
for i in range(N):
    for j in range(N):
        ans+=((x[j]-x[i])**2+(y[j]-y[i])**2)**0.5/N
print(ans)

Measured memory_bytes: 38384
import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();

        Map<Integer, Set<Integer>[]> map = new HashMap<>();
        for(int i = 1; i <= n ; i++) {
        	map.put(i, new HashSet[2]);
        	map.get(i)[0] = new HashSet<>();
        	map.get(i)[1] = new HashSet<>();
        }

        for(int i = 1; i <= n; i++) {
        	int num = sc.nextInt();
        	for(int j = 0; j < num; j++) {
        		int people = sc.nextInt();
        		int flag = sc.nextInt();
        		if(flag == 1) 
        		    map.get(i)[0].add(people);
        		else
        		    map.get(i)[1].add(people);
        	}
        }
        int ans = 0;
        Set<Integer> trueSets = new HashSet<>();
        Set<Integer> falseSets = new HashSet<>();
        
        loop:
        for(int bit = 0; bit < (1 << n); bit++) {
        	trueSets = new HashSet<>();
        	falseSets = new HashSet<>();
        	for(int j = 0; j < n; j++) {
        	    int p = j + 1;
        		if((bit >> j & 1) == 1) {
        			trueSets.addAll(map.get(p)[0]);
        			falseSets.addAll(map.get(p)[1]);
        		}
        	}

        	for(int j = 0; j < n; j++) {
        	    int p = j + 1;
        		if((bit >> j & 1) == 1) {
        			if(falseSets.contains(p))
        				continue loop;
        		} else {
        		    if(trueSets.contains(p))
        				continue loop;
        		}
        	}


        	ans = Math.max(ans, Integer.bitCount(bit));
        }

        System.out.println(ans);
    }
}


Measured memory_bytes: 44984
#include<bits/stdc++.h>
using namespace std;
int main()
{
  long long n,m,i,k,count=0,x=1;
  float sum;
  cin>>n>>m;
  vector<int>a(n);
  for(i=0;i<n;i++)
    cin>>a[i];
  sort(a.begin(),a.end());
  for(i=0;i<n;i++)
    sum+=a[i];
  k=4*m;
  sum=sum/k;
  for(i=n-1;i>=0;i--)
  {
    if(a[i]>=sum)
      count++;
  }
  if(count>=m)
    cout<<"Yes";
    else
      cout<<"No";
}


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

using ll = long long;

#define rep(i, n) for (int i = 0; i < (n); ++i)
#define rrep(i, n) for (int i = 1; i <= (n); ++i)
#define drep(i, n) for (int i = (n)-1; i >= 0; --i)
#define ddrep(i, n) for (int i = n; i > 0; --i)
#define srep(i, s, t) for (int i = s; i < t; ++i)
#define ssrep(i, s, t) for (int i = s; i <= t; ++i)

#define rng(a) a.begin(), a.end()
#define pb push_back
#define eb emplace_back
#define fi first
#define se second

#define chmax(x, y) (x = max(x, y))
#define chmin(x, y) (x = min(x, y))

using pi = pair<int, int>;
using vi = vector<int>;
using vvi = vector<vi>;
using vl = vector<ll>;
using vvl = vector<vl>;
using ld = long double;

template <class T, class U>
ostream &operator<<(ostream &os, const pair<T, U> &p) {
  os << "(" << p.first << "," << p.second << ")";
  return os;
}

template <class T> ostream &operator<<(ostream &os, const vector<T> &v) {
  os << "{";
  rep(i, (int)v.size()) {
    if (i)
      os << ",";
    os << v[i];
  }
  os << "}";
  return os;
}

template <typename T, size_t S> void printArray(const T (&array)[S]) {
  for (auto val : array)
    std::cout << val << ", ";
  std::cout << "\n";
}

const int mod = 1e9 + 7;
const int inf = 1e9 + 5;

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << std::setprecision(10);

  int n; std::cin >> n;
  map<int, int> cnt;
  rep(i, n) {
    int a; std::cin >> a;
    cnt[a]++;
  }
  int over = 0;
  for (auto &p : cnt) {
    over += p.se - 1;
  }
  std::cout << n - over - (over % 2) << "\n";
}


Measured memory_bytes: 4992
//霊符「夢想封印」！！！！
import java.util.Scanner;
public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner (System.in);
		String a,b,c,abc;
		a = sc.next();
		b = sc.next();
		c = sc.next();
		abc = a+b+c;
		if(abc.equals("557")||abc.equals("575")||abc.equals("755")) {
			System.out.println("YES");
		}
		else {
			System.out.println("NO");
		}
	}
}

Measured memory_bytes: 21844
class UnionFind(object):
    def __init__(self, n=1):
        self.par = [i for i in range(n)]  # グループ番号
        self.rank = [0 for _ in range(n)]

    def find(self, x):
        """
        x が属するグループを探索
        """
        if self.par[x] == x:
            return x
        else:
            self.par[x] = self.find(self.par[x])
            return self.par[x]

    def union(self, x, y):
        """
        x と y のグループを結合
        """
        x = self.find(x)
        y = self.find(y)
        if x != y:
            if self.rank[x] < self.rank[y]:
                x, y = y, x
            if self.rank[x] == self.rank[y]:
                self.rank[x] += 1
            self.par[y] = x

    def is_same(self, x, y):
        """
        x と y が同じグループか否か
        """
        return self.find(x) == self.find(y)


N, M = map(int, input().split())
p = list(map(int, input().split()))
u = UnionFind(N + 1)
for i in range(M):
    a, b = map(int, input().split())
    u.union(a - 1, b - 1)
c = 0
for i in range(N):
    # print(u.find(i), u.find(p[i]))
    if u.find(i) == u.find(p[i] - 1):
        c += 1
print(c)


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

using namespace std;
#define N 111111

int n;
int a[N][3],b[N][3];
int main(){
	ios_base::sync_with_stdio(0); cin.tie();
	cin>>n;
	for (int i=0; i<n; i++){
		for (int j=0; j<3; j++){
			cin>>a[i][j];
		}
	}
	b[0][0]=a[0][0]; b[0][1]=a[0][1]; b[0][2]=a[0][2];
	for (int i=1; i<n; i++){
		for (int j=0; j<3; j++){
			b[i][j]=a[i][j]+max(b[i-1][(j+1)%3],b[i-1][(j+2)%3]);
		}
	}
	cout<<max(max(b[n-1][0],b[n-1][1]),b[n-1][2]);
	return 0;
}

Measured memory_bytes: 2560
#include <bits/stdc++.h>
//---------------------------
using namespace std;
//---------------------------
#define REP(i,n) for(int i = 0; i < (n); i++)
#define P(x) cout << (x) << "\n"

#define MOD 1e9+7
#define PI acos(-1.0)
#define ll long long
#define INF 1000000001

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

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

  // ifstream in("input.txt");
  // cin.rdbuf(in.rdbuf());

  int n,k;cin>>n>>k;
  int l[50]={};
  int mx=0;
  REP(i,n){
    cin>>l[i];
  }
  sort(l,l+n);
  reverse(l,l+n);
  REP(i,k){
    mx+=l[i];
  }
  P(mx);
  return 0;
}


Measured memory_bytes: 384
#include <stdio.h>
#include <string.h>
#define MOD	10007

int N;
char S[1123];
int memo[1123][7];

int to_num(char str) {
	if (str == 'J') { return 1; }
	if (str == 'O') { return 2; }
	else { return 4; }
}
// dp(i,s) = i??\????????????????????????????????????s?????¨??????i??\????????§???????????¨?????°
int dp(int i, int s) {
	int res = 0;
	if (i == N) { return memo[i][s] = 1; }
	if (memo[i][s] != -1) { return memo[i][s]; }
	for (int j = 1; j <= 7; ++j) {
		if ((s&j) && (j&to_num(S[i]))) {
			res += dp(i + 1, j);
			res %= MOD;
		}
	}
	return memo[i][s] = res;
}
int main(void) {
	scanf("%d%s", &N, &S);

	memset(memo, -1, sizeof(memo));

	printf("%d\n", dp(0, 1));
	return 0;
}

Measured memory_bytes: 2784
m['= r'][5],W,z,k,i,*p;f(i){k[p=m[i]]=p[4]+47?0:p[k]?:1+f(i+(1+k%2*W)*(k/2?:-1));}main(t){for(scanf("%*d%d",&W);m[++i-~W][4]=~getchar(););for(;k--?:(t=k=3,--i);z=z<-t?-t:z)t-=f(i-~W);printf("%d",z);}

Measured memory_bytes: 78464
#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.at(i);
  }
  sort(a.begin(), a.end());
  cout << a.at(n-1)-a.at(0) << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
#include <iomanip>
#include <vector>
#include <map>
#include <cmath>
#include <queue>
#include <utility>
#include <functional>
#include <deque>
#include <cctype>
#include <stack>

using ll = long long;
typedef unsigned long long ull;
typedef std::pair<int, int>p;

ll min(ll a, ll b) {
	if (a >= b)return b;
	else return a;
}
ll max(ll a, ll b) {
	if (a >= b)return a;
	else return b;
}
ll gcd(ll a, ll b) {
	if (b == 0) return a;
	return gcd(b, a%b);
}
ll lcm(ll a, ll b) {
	ll g = gcd(a, b);
	return a / g * b;
}

const ll Z = 1000000007;
const ll INF = 1 << 30;
const ll INF2 = 9000000000000000000LL;
bool flag = true;
bool fl = false;
bool f = false;
bool used[210];
bool graph[100][100];
bool visited[8];
int abc[26] = { 0 };

int main() {
	ll n, a[100000], b[100000], ansA = 0, ansB = 0;
	std::cin >> n;
	for (int i = 0;i < n;i++) {
		std::cin >> a[i];
		b[i] = a[i];
	}
	for (int i = 0;i <= n - 1;) {
		if (a[i] <= 0)ansA += abs(1 - a[i]), a[i] = 1;
		i++;
		if (i == n)break;
		a[i] += a[i - 1];
		if (a[i] >= 0)ansA += abs(a[i] + 1), a[i] = -1;
		i++;
		if (i == n)break;
		a[i] += a[i - 1];
	}
	for (int i = 0;i <= n - 1;) {
		if (b[i] >= 0)ansB += abs(b[i] + 1), b[i] = -1;
		i++;
		if (i == n)break;
		b[i] += b[i - 1];
		if (b[i] <= 0)ansB += abs(1 - b[i]), b[i] = 1;
		i++;
		if (i == n)break;
		b[i] += b[i - 1];
	}
	std::cout << min(ansA, ansB) << std::endl;
}

Measured memory_bytes: 1792
import java.io.*;
import java.util.*;
class Main{
	static final long MOD = 1_000_000_007; // 10^9+7
    static final int MAX = 2_147_483_646; // intMax 
    static final int INF = 1_000_000_000; // 10^9  
    public static void main(String[] args) throws Exception {
		hayami saori = new hayami();
		int a = saori.saori_hayami();
		int b = saori.saori_hayami();
		int c = saori.saori_hayami();
		int num = a - b;
		num = c -num;
		if(num < 0){
			num = 0;
		}
		System.out.println(num);
		
		saori.close();
    }
}

class hayami implements Closeable {
	private final InputStream in = System.in;
	private final byte[] hayami = new byte[1024];
	private int Hayami = 0;
	private int saori = 0;
	private boolean HayamiSaori() {
		if (Hayami < saori) {
			return true;
		}else{
			Hayami = 0;
			try {
				saori = in.read(hayami);
			} catch (IOException e) {
				e.printStackTrace();
			}
			if (saori <= 0) {
				return false;
			}
		}
		return true;
	}
	private int SaoriHayami() { 
		if (HayamiSaori()) {
            return hayami[Hayami++];
         }else{
             return -1;
         }
	}
	private static boolean hayami_saori(int hayami) { 
		return 33 <= hayami && hayami <= 126;
	}
	public boolean hayamisaori() { 
		while(HayamiSaori() && !hayami_saori(hayami[Hayami])) Hayami++; return HayamiSaori();
	}
	public String nextHayami() {
		if (!hayamisaori()) throw new NoSuchElementException();
		StringBuilder hayamin = new StringBuilder();
		int saori = SaoriHayami();
		while(hayami_saori(saori)) {
			hayamin.appendCodePoint(saori);
			saori = SaoriHayami();
		}
		return hayamin.toString();
	}
	public long saorihayami() {//nextLong
		if (!hayamisaori()) throw new NoSuchElementException();
		long hayami = 0;
		boolean misao = false;
		int saori = SaoriHayami();
		if (saori == '-') {
			misao = true;
			saori = SaoriHayami();
		}
		if (saori < '0' || '9' < saori) {
			throw new NumberFormatException();
		}
		while(true){
			if ('0' <= saori && saori <= '9') {
				hayami *= 10;
				hayami += saori - '0';
			}else if(saori == -1 || !hayami_saori(saori)){
				return misao ? -hayami : hayami;
			}else{
				throw new NumberFormatException();
			}
			saori = SaoriHayami();
		}
	}
	public int saori_hayami() {//nextInt
		long hayami = saorihayami();
		if (hayami < Integer.MIN_VALUE || hayami > Integer.MAX_VALUE) throw new NumberFormatException();
		return (int) hayami;
	}
	public double Hayamin() { //nextDouble
		return Double.parseDouble(nextHayami());
	}
	public void close() {
		try {
			in.close();
		} catch (IOException e) {
		}
    }
    
}

Measured memory_bytes: 21076
import java.util.*;
import java.util.regex.Pattern;
 
public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    Boolean b = false;
    int n = Integer.parseInt(sc.next());
    String pattern = "^\\d{1}$";
    Pattern p = Pattern.compile(pattern);
    for(int i = 1; i < 10; i++) {
	  if(n % i == 0) {
        if(p.matcher(String.valueOf(n/i)).find()){
    		System.out.println("Yes");
            b = true;
		}
        if(b)
        break;
      }
    }
    if(!b){
      System.out.println("No");
    }
  }
}

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

int main() {
  int a;
  int count = 0;
  cin >> a;
  while( a != 0){
    if(a % 10 == 1){
      count ++;
    }
    a = a / 10;
  }
  cout << count << endl;
}

Measured memory_bytes: 256
#include<iostream>

using namespace std;

int main()
{
	int n,i,j,num,array[30];
	
	for(;;)
	{
		cin >> n;
		if(n==0)
			break;
		num=32;
		
		for(i=0;i<n;i++)
			cin >> array[i];
		
		for(i=0;num>0;i++)
		{
			num-=(num-1)%5;
			cout << num << endl;
			if(i==n)
				i=0;
			num-=array[i];
			if(num<0)
			cout << "0" << endl;
			else
			cout << num << endl;
		}
	}
}

Measured memory_bytes: 0
#include <bits/stdc++.h>
#define show(x) cerr << #x << " = " << (x) << endl
using namespace std;
using P = pair<int, int>;
constexpr P NG = {-1, -1};
template <typename T, typename A>
inline ostream& operator<<(ostream& os, const vector<T, A>& v)
{
    os << "[";
    for (const auto& p : v) { os << p << ","; }
    return (os << "]" << endl);
}
template <typename S, typename T>
inline ostream& operator<<(ostream& os, const pair<S, T>& p) { return (os << "<" << p.first << "," << p.second << ">"); }
int main()
{
    for (int H, W;;) {
        cin >> W >> H;
        if (W == 0 and H == 0) { break; }
        vector<string> p(H);
        for (int i = 0; i < H; i++) { cin >> p[i]; }
        p.push_back(string(W, '0'));
        auto in = [&](const int y, const int x) { return y >= 0 and y <= H and x >= 0 and x < W; };
        auto dfs = [&](auto&& self, const int y, const int x) -> pair<P, vector<P>> {
            constexpr int d[] = {-1, 0, 1, 0, -1};
            queue<P> q;
            const char ch = p[y][x];
            q.push({y, x}), p[y][x] = '.';
            vector<P> cell{{y, x}};
            while (not q.empty()) {
                const int y = q.front().first, x = q.front().second;
                q.pop();
                for (int t = 0; t < 4; t++) {
                    const int newy = y + d[t], newx = x + d[t + 1];
                    if (not in(newy, newx) or p[newy][newx] != ch) { continue; }
                    p[newy][newx] = '.', q.push({newy, newx}), cell.push_back({newy, newx});
                }
            }
            P ans = {0, 4};
            for (const auto& c : cell) {
                ans.first += c.second;
                if (not in(c.first - 1, c.second) or p[c.first - 1][c.second] == '.') { continue; }
                const auto sub = self(self, c.first - 1, c.second);
                const auto info = sub.first;
                if (info == NG) { return {NG, {}}; }
                const auto ucell = sub.second;
                int l = W + 1, r = -1;
                for (const auto& c : cell) {
                    for (const auto& u : ucell) {
                        if (c.first - 1 == u.first and c.second == u.second) { l = min(l, c.second), r = max(r, c.second); }
                    }
                }
                if ((2 * l - 1) * info.second < 2 * info.first and 2 * info.first < (2 * r + 1) * info.second) {
                    ans.first += info.first, ans.second += info.second;
                } else {
                    return {NG, {}};
                }
            }
            return {ans, cell};
        };
        const auto ans = dfs(dfs, H, 0);
        cout << (ans.first == NG ? "UN" : "") << "STABLE" << endl;
    }
    return 0;
}



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

//素因数分解(関数ver)
map<int64_t,int64_t> prime_fact(int64_t n){
  int64_t a = 2;
  map<int64_t,int64_t> mp;
  while(n >= a*a){
    if(n %a == 0){
      if(mp.count(a)){
        mp[a]++;
      }
      else{
        mp[a] = 1;
      }
      n /= a;
    }
    else{
      a++;
    }
  }
  if(mp.count(n)){
    mp[n]++;
  }
  else{
    mp[n] = 1;
  }
  return mp;
}

int main(){
  int N;
  cin >> N;
  vector<int> vec(N);
  for(int i=0; i<N; i++){
    cin >> vec[i];
  }
  
  bool pairwise = true;
  bool setwise = true;
  
  set<int> S;
  set<int> common;
  for(int i=0; i<N; i++){
    if(i == 0 || vec[i] == 1){
      map<int64_t, int64_t> A = prime_fact(vec[i]);
      for(auto itr = A.begin(); itr != A.end(); itr++){
        S.insert(itr->first);
      }
    }
    else{
      map<int64_t, int64_t> A = prime_fact(vec[i]);
      for(auto itr = A.begin(); itr != A.end(); itr++){
        if(S.count(itr->first)){
          pairwise = false;
          common.insert(itr->first);
        }
        S.insert(itr->first);
      }
    }
    if(!pairwise){
      break;
    }
  }
  
  if(pairwise){
    cout << "pairwise coprime" << endl;
    return 0;
  }
  
  for(auto itr = common.begin(); itr != common.end(); itr++){
    int cnt = 0;
    for(int i=0; i<N; i++){
      if(vec[i] %*itr == 0){
        cnt++;
      }
    }
    if(cnt == N){
      setwise = false;
      break;
    }
  }
  
  if(setwise){
    cout << "setwise coprime" << endl;
  }
  else{
    cout << "not coprime" << endl;
  }
}

Measured memory_bytes: 7296
#include <bits/stdc++.h>
using namespace std;
#define _GLIBCXX_DEBUG
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
using ll = long long;
using ld = long double;
#define rep2(i, s, n) for (ll i = (s); i < (ll)(n); i++)
#define rep3(i, n) for (ll i = 1; i < (ll)(n+1); i++)
#define rep4(i, s, n) for (ll i = (s); i < (ll)(n+1); i++)
#define repr(i,n) for (ll i = (n-1); i>=0;i--)
#define repr3(i,n) for(ll i = (n);i>0;i--)
#define stlen(s) ll s.size()-1
#define all(v) v.begin(), v.end()
#define cout(n) cout<<std::fixed<<std::setprecision(n)
using Graph = vector<vector<int>>;
#define INF1  INT_MAX;
#define INF2  LLONG_MAX;
#define PI  3.14159265358979323846;



int main() {
string S;
cin>>S;
int ans=0;
rep(i,S.size()){
    if(S[i]=='+'){
        ans++;
    }
    else{
        ans--;
    }
}
cout<<ans<<endl;
return 0;
}




Measured memory_bytes: 256
import java.util.*;
public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        HashMap<String, Integer> hash = new HashMap<String, Integer>();
        
        String alpha = "abcdefghijklmnopqrstuvwxyz";
        for(int i = 0; i < 26; i++) {
            char ch = alpha.charAt(i);
            String st = String.valueOf(ch);
            hash.put(st, 0);
        }
        
        while(true) {
            String line;
            try {
                line = sc.nextLine();
            }catch(NoSuchElementException e) {
                break;
            }
            String[] st = line.split("");
            for(int i = 0; i < st.length; i++) {
                String str = st[i].toLowerCase();
                if(hash.containsKey(str)) {
                    hash.put(str, hash.get(str) + 1);
                }
                
            }
        }
        for(String str : hash.keySet()) {
            System.out.println(str + " : " + hash.get(str));
        }

    }
 }


Measured memory_bytes: 27324
#include<iostream>


using namespace std;

int main(void)
{
int n,a = 0,b = 0,c = 0;
cin>>n;

for(int i=0;i<n;i++)
{
    cin>>a>>b>>c;

        if(c*c == (b*b+a*a)|| (a * a + c * c )== b * b ||( b * b + c * c) == a * a){
        cout<<"YES"<<endl;
        }
        else{
            cout<<"NO"<<endl;
        }

}

return 0;
}

Measured memory_bytes: 1152
import java.util.Scanner;
public class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    int r,D,x,i;
    int[] a = new int[10];
    r = sc.nextInt();
    D = sc.nextInt();
    x = sc.nextInt();
    a[0] = (r*x)-D;
    System.out.println(a[0]);
    for(i=1;i<10;i++){
      a[i] = (r*a[i-1])-D;
      System.out.println(a[i] + "\n");
    }
  }
}

Measured memory_bytes: 23764
/**
 *start coding only after you have clear idea. Otherwise you will waste time to change your code frequently and debug
 */

#include <bits/stdc++.h>
using namespace std;
int gcd(int a, int b)
{
    if (a == 0)
        return b;
    return gcd(b % a, a);
}

int findGCD(int arr[], int n)
{
    int result = arr[0];
    for (int i = 1; i < n; i++)
        result = gcd(arr[i], result);

    return result;
}
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int n;
    cin>>n;
    long long sum=0;
    for(int i=1;i<=n;i++)
    {
        for(int j=1;j<=n;j++)
        {
            for(int k=1;k<=n;k++)
            {
                int arr[]={i,j,k};
                if(i==1||j==1||k==1){
                    sum=sum+1;
                }else{
                sum=sum+findGCD(arr,3);
                }

            }
        }
    }
    cout<<sum;

    return 0;
}


Measured memory_bytes: 3648
nmxy = list(map(int, input().split()))
n = nmxy[0]
m = nmxy[1]
x = nmxy[2]
y = nmxy[3]
xlist = list(map(int, input().split()))
ylist = list(map(int, input().split()))


xlist.append(x)
ylist.append(y)

if max(xlist) < min(ylist):
    print("No War")
else:
    print("War")

Measured memory_bytes: 3064