akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef long double ld;
const ll N = 100005;
char en = '\n';
ll inf = 1e16;
ll mod = 1e9 + 7;
ll power(ll x, ll n, ll mod) {
  ll res = 1;
  x %= mod;
  while (n) {
    if (n & 1)
      res = (res * x) % mod;
    x = (x * x) % mod;
    n >>= 1;
  }
  return res;
}

int32_t main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);

  ll n, x;
  cin >> n >> x;
  ll arr[n + 5];
  ll res = 0;
  ll d = 0;
  if (d <= x)
    res++;
  for (ll i = 1; i <= n; i++) {
    cin >> arr[i];
    d += arr[i];
    if (d <= x)
      res++;
  }

  cout << res << en;

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

		//対象文字列
		String str = sc.nextLine();

		//文字単位で配列に格納
		String[] str2 = str.split("");

		//命令の数
		int loop = sc.nextInt();

		for (int i = 0; i < loop; i++) {

			//命令の種類
			String command = sc.next();

			//種類ごとに与えられる変更範囲
			int a = sc.nextInt();
			int b = sc.nextInt();

			//命令がprintの時
			if (command.equals("print")) {
				for (int j = a; j <= b; j++) {//a-bを出力
					System.out.print(str2[j]);
				}
				System.out.print("\n");
			}

			//命令がreverseの時
			else if (command.equals("reverse")) {
				//a-bの外周から内側に向かって入れ替え
				for (int j = b, k = a; j > k; j--, k++) {
					String tmp="";
					tmp = str2[j];
					str2[j] = str2[k];
					str2[k] = tmp;

				}
			}

			//命令がreplaceの時
			else if (command.equals("replace")) {
				String rep = sc.next();//差し替え文字列の入力
				String[] rep2 = rep.split("");//差し替え文字を配列に分解
				int k = 0;//差し替え文字列用の配列位置の初期化
				for (int j = a; j <= b; j++) {
					str2[j] = rep2[k];//元配列を差し替え
					k++;//必要数になるまで増加
				}
			}
		}

		sc.close();
	}

}



Measured memory_bytes: 34924
#include <bits/stdc++.h>
//#include <ext/pb_ds/tree_policy.hpp>
//#include <ext/pb_ds/assoc_container.hpp>
using namespace std;
//using namespace __gnu_pbds;
//template<typename key, typename val>
//using ordered_tree =
//  tree<key, val, greater<>, rb_tree_tag, tree_order_statistics_node_update>;
typedef long long int64;
typedef complex<double> comp;
const double pi = 3.14159265358979323846;
const int inf = (int)1e+9 + 2;
const int64 inf64 = (int64)1e+18 + 2;
const double dinf = 1e+20;
const int mod = /*1'000'000'007;//*/998244353;
const int base = 2187;
const double eps = 1e-8;
const int N = 200'000;
const int LOGN = 19;

int n, m, k;

void solve(int test) {
  cin >> n;
  vector<int> x(n), y(n);
  for (int i = 0; i < n; ++i) {
    cin >> x[i] >> y[i];
  }
  vector<int> p(n);
  iota(begin(p), end(p), 0);
  int iter = 0;
  double total = 0;
  do {
    for (int i = 1; i < n; ++i) {
      int c1 = x[p[i]];
      int d1 = y[p[i]];
      int c2 = x[p[i - 1]];
      int d2 = y[p[i - 1]];
      total += sqrt((c1 - c2) * (c1 - c2) + (d1 - d2) * (d1 - d2));
    }
    ++iter;
  } while (next_permutation(begin(p), end(p)));
  cout.setf(ios::fixed);
  cout.precision(11);
  cout << total / iter << '\n';
}

void precalc() {
}

int main() {
  ios::sync_with_stdio(0);
  cin.tie(0), cout.tie(0);
  precalc();
  int test = 1;
  //cin >> test;
  //auto start = chrono::high_resolution_clock::now();
  for (int i = 1; i <= test; ++i) {
    solve(i);
  }
  //cerr << chrono::duration_cast<chrono::milliseconds>(chrono::high_resolution_clock::now() - start).count() << '\n';
  return 0;
}


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

ll a[300000];
int main() {
	ll n; scanf("%lld", &n);
	rep(i, n) {
		scanf("%lld", &a[i + 1]);
		a[i + 1 + n] = a[i + 1];
	}
	for (ll i = 1; i <= 2 * n; i++)
		a[i] += a[i - 1];
	ll s = 0, g = a[n];
	while (s != g) {
		ll t = (s + g) / 2;
		if (g - s == 1)t = g;
		bool f = 0;
		rep(i, n) {
			ll j = lower_bound(a + i, a + i + n + 1, a[i] + t) - a;
			if (j == n + i + 1)continue;
			ll k = lower_bound(a + j, a + i + n + 1, a[j] + t) - a;
			if (a[k] - a[j] >= t&&a[i + n] - a[k] >= t) { f = 1; break; }
		}
		if (f)s = t;
		else g = t - 1;
	}
	printf("%lld\n", s);
}

Measured memory_bytes: 4780
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(n);++i)
#define rrep(i,n) for(int i=1;i<(n);++i)
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
#define maxs(a, b) a = max(a, b)
#define mins(a, b) a = min(a, b)
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
const ll linf = (1ll << 61);
const int inf = 1001001001;
const int mod = 1000000007;

int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	int n;
	cin >> n;
	vector<int> p(n);
	rep(i, n) {
		int x;
		cin >> x;
		x--;
		p[x] = i;
	}
	int t = 1, ans = 1;
	rrep(i, n) {
		if (p[i] > p[i - 1]) {
			t++;
		}
		else {
			t = 1;
		}
		maxs(ans, t);
	}
	cout << n - ans << endl;
	return 0;
}


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

int main(){
    using namespace std;
    unsigned long N;
    cin >> N;
    vector<unsigned long> A(N);
    __gnu_pbds::gp_hash_table<unsigned long, unsigned long> m;
    unsigned long ans{0};
    for(auto& i : A){
        cin >> i;
        ans += m[i]++;
    }
    for(const auto& i : A)cout << ans - m[i] + 1 << endl;
    return 0;
}

Measured memory_bytes: 12396
import java.util.*;
import java.io.*;
class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int n = sc.nextInt();
    int[] a = new int[n];
    for(int i = 0; i<n; i++)
      a[i] = sc.nextInt();
    int[] dp = new int[n+1];
    for(int i = 2; i<=n; i++) {
        dp[i] = dp[i-1]+Math.abs(a[i-1]-a[i-2]);
        if(i>=3)
            dp[i] = Math.min(dp[i], dp[i-2]+Math.abs(a[i-3]-a[i-1]));
    }
    System.out.println(dp[n]);
  }
}

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

int main()
{
	int A[200000], n;
	cin >> n;

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

	int max = -10000000000;
	int min = A[0];

	for (int i = 1;i < n;i++) {
		if (A[i] - min > max)
			max = A[i] - min;

		if (min > A[i])
			min = A[i];
	}

	cout << max << endl;
	

    return 0;
}

Measured memory_bytes: 3852
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
ll gcd(ll a, ll b) {
	if (b==0) return a;
    else{
    	return gcd(b,a%b);
    }
}
 
int main() {
	ll a,b;
  	cin >> a >> b;
  	if((a+b)%3==0 || a%3 == 0 || b%3 == 0){
      cout << "Possible" << endl;
    }
  	else{
      cout << "Impossible" << endl;
    }
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <string>
#include <functional>
#include <math.h>
#include <map>
using namespace std;

int main() {
	int n, y;
	int ans[3] = { 0 };
	cin >> n >> y;
	int man = floor(y / 10000);
	int gosen = floor((y - 10000 * man) / 5000);
	int sen = floor((y - 10000 * man - 5000 * gosen) / 1000);
	int sum = man + gosen + sen;
	if (sum > n) {
		ans[0] = -1;
		ans[1] = -1;
		ans[2] = -1;
		cout << ans[0] << " " << ans[1] << " " << ans[2] << endl;
		return 0;
	}
	else {
		for (int i = 0; i <= man; i++) {
			for (int j = 0; j <= man - i; j++) {
				for (int u = 0; u <= gosen; u++) {
					if ((n - sum) == 9 * i + 1 * j + 4 * u) {
						man -= i;
						man -= j;
						gosen -= u;
						gosen += 2 * j;
						sen += 10 * i;
						sen += 5 * u;
						cout << man << " " << gosen << " " << sen << endl;
						return 0;
					}
				}
			}
		}
	}
	cout << -1 << " " << -1 << " " << -1 << endl;
	
	return 0;
}

Measured memory_bytes: 256
#[allow(unused_imports)]
use std::cmp::*;
#[allow(unused_imports)]
use std::collections::*;
#[allow(unused_imports)]
use std::io::{Write, BufWriter};

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

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

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

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

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

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

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

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

fn main() {
    input! {
        n: usize,
        task: [(i64, i64); n],
    }
    
    let mut task = task;
    task.sort_by_key(|&(_, b) | b);
    let mut pass = 0;
    let mut ans = true;
    for &(a, b) in &task {
        pass += a;
        if pass > b {
            ans = false;
        }
    }

    println!("{}", if ans {"Yes"} else {"No"});
}

Measured memory_bytes: 10492
N, M = gets.split.map(&:to_i)

LR = M.times.map { gets.split.map(&:to_i) }

al = 1
ar = N

LR.each do |l, r|
  al = al < l ? l : al
  ar = r < ar ? r : ar

  if ar < al
    puts 0
    exit
  end
end

puts ar - al + 1

Measured memory_bytes: 9596
#include<bits/stdc++.h>
using namespace std;
typedef long long LL;
typedef pair<LL,LL> P;

int main(){
    int N,K,X,Y;
    cin >> N >> K >> X >> Y;
    if(N<=K) cout << N*X << endl;
    else cout << K*X+(N-K)*Y << endl;
    return 0;
}

Measured memory_bytes: 256
k, n = map(int,input().split())
li = list(map(int,input().split()))

ans = k
max_dis = 0

for i in range(n-1):
    s = li[i+1] - li[i]
    if max_dis < s:
        max_dis = s

tmp = li[0] + (k - li[-1])

max_dis = max(tmp, max_dis)

print(k - max_dis)

Measured memory_bytes: 26436
#include <bits/stdc++.h>
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)   FOR(i,0,n)
#define ALL(obj)   (obj).begin(),(obj).end()

#define debug(var)  do{std::cout << __LINE__ << "> " << #var << ": ";view(var);}while(0)
template<typename T> void view(T e){std::cout << e << std::endl;}
template<typename T> void view(const std::vector<T>& v){for(const auto& e : v){ std::cout << e << " "; } std::cout << std::endl;}
template<typename T> void view(const std::vector<std::vector<T> >& vv){ for(const auto& v : vv){ view(v); } }

using namespace std;
using ll = long long;
using vi = vector<int>;
using vl = vector<ll>;
using vvi = vector<vector<int>>;
using vvl = vector<vector<ll>>;

void Main() {
	int N, K; cin >> N >> K;
	string S; cin >> S;
	REP(i,N) {
		if (i == K - 1) {
			cout << (char)(S[i] + 0x20);
		} else {
			cout << S[i];
		}
	}
	cout << endl;
}

int main() {
    cin.tie(nullptr);
	ios_base::sync_with_stdio(false);
	cout << fixed << setprecision(15);
	Main();
}


Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;
long long n, power[19], power19[6], ret; pair<long long, long long>T[1 << 20];
int main() {
	cin >> n;
	power[0] = 1; for (int i = 1; i <= 18; i++)power[i] = power[i - 1] * 10;
	power19[0] = 1; for (int i = 1; i <= 5; i++)power19[i] = power19[i - 1] * 19;
	for (int i = 2; i <= 18; i++) {
		vector<long long>E;
		for (int j = 0; j < i; j++) {
			if (power[i - j - 1] <= power[j])continue;
			E.push_back(power[i - j - 1] - power[j]);
		}
		for (int j = 0; j < power19[E.size() / 2]; j++) {
			int bit[6]; for (int k = 0; k < E.size() / 2; k++)bit[k] = (j / power19[k]) % 19;
			long long V = 0, U = 1;
			for (int k = 0; k < E.size() / 2; k++) {
				long long R = 0; if (k == 0)R = 1;
				V += E[k] * (bit[k] - 9), U *= (10 - abs(bit[k] - 9) - R);
			}
			T[j + 1] = make_pair(V, U);
		}
		long long SZ = power19[E.size() / 2]; T[0] = make_pair(-(1LL << 62), 0);
		sort(T, T + SZ + 1); long long H = E.size() - E.size() / 2;
		for (int j = 1; j <= SZ; j++)T[j].second += T[j - 1].second;
		for (int j = 0; j < power19[H]; j++) {
			int bit[6]; for (int k = 0; k < H; k++)bit[k] = (j / power19[k]) % 19;
			long long P = 0, Q = 1;
			for (int k = E.size() / 2; k < E.size(); k++) {
				P += E[k] * (bit[k - E.size() / 2] - 9);
				long long R = 0; if (k == 0)R = 1;
				Q *= (10 - abs(bit[k - E.size() / 2] - 9) - R);
			}

			int pos1 = lower_bound(T, T + SZ + 1, make_pair(n - P - 1, (1LL << 60))) - T; pos1--;
			int pos2 = lower_bound(T, T + SZ + 1, make_pair(n - P, (1LL << 60))) - T; pos2--;

			if (i % 2 == 1)Q *= 10;
			ret += Q*(T[pos2].second - T[pos1].second);
		}
	}
	cout << ret << endl;
	return 0;
}

Measured memory_bytes: 2432
#include <algorithm>
#include <cmath>
#include <complex>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <vector>
#include <functional>
#include <cstring>
#include <regex>
#include <random>
#include <cassert>
using namespace std;

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define repr(i, s, n) for (int i = (s); i < (int)(n); i++)
#define revrep(i, n) for (int i = (n) - 1; i >= 0; i--)
#define revrepr(i, s, n) for (int i = (n) - 1; i >= s; i--)
#define debug(x) cerr << #x << ": " << x << "\n"
#define popcnt(x) __builtin_popcount(x)

using ll = long long;
using P = pair<int, int>;

const long long MOD = 1e9+7;

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

template<class T>
istream& operator >>(istream &is, vector<T> &v) {
    for (int i = 0; i < (int)v.size(); i++) cin >> v.at(i);
    return is;
}

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

template<class T>
void print(const vector<T> &v, const string &delimiter) { rep(i, v.size()) cout << (0 < i ? delimiter : "") << v.at(i); cout << endl; }

template<class T>
void print(const vector<vector<T>> &vv, const string &delimiter) { for (const auto &v: vv) print(v, delimiter); }

vector<vector<int>> graph;

bool get_path(int pre, int v, int goal, vector<int> &path) {
    if (v == goal) {
        path.push_back(v);
        return true;
    }
    
    for (int to: graph[v]) if (pre != to) {
        if (get_path(v, to, goal, path)) {
            path.push_back(v);
            return true;
        }
    }
    return false;
}

int main() {
    int n;
    cin >> n;
    int e = n - 1;
    graph.resize(n);
    vector<vector<int>> edge_num(n, vector<int>(n));
    rep(i, e) {
        int a, b;
        cin >> a >> b;
        a--; b--;
        graph[a].push_back(b);
        graph[b].push_back(a);
        edge_num[a][b] = i;
        edge_num[b][a] = i;
    }
    int m;
    cin >> m;
    vector<vector<bool>> group(m, vector<bool>(e));
    rep(i, m) {
        int u, v;
        cin >> u >> v;
        u--; v--;
        vector<int> path;
        get_path(-1, u, v, path);
        rep(j, (int)path.size() - 1) group[i][edge_num[path[j]][path[j + 1]]] = true;
    }
    
    vector<int> mask(n - 1);
    rep(i, m) rep(j, e) if (group[i][j]) mask[j] |= 1 << i;
    
    vector<vector<ll>> dp(e + 1, vector<ll>(1 << m));
    dp[0][0] = 1;
    rep(i, e) rep(bit, 1 << m) {
        dp[i + 1][bit] += dp[i][bit];
        dp[i + 1][bit | mask[i]] += dp[i][bit];
    }
    
    cout << dp[e][(1 << m) - 1] << endl;
    
    /*rep(i, e + 1) {
        rep(j, 1 << m) cout << dp[i][j] << " ";
        cout << endl;
    }*/
}

Measured memory_bytes: 418304
# -*- coding: utf-8 -*-

n,a,b = map(int,input().split())
x = list(map(int,input().split()))

fatigue = 0

for i in range(1,n):
    if (x[i] - x[i-1]) * a <= b:
        fatigue += (x[i] - x[i-1]) * a
    else:
        fatigue += b

print(fatigue)


Measured memory_bytes: 14224
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner scanner = new Scanner(System.in);
		int n = scanner.nextInt();
		int a = scanner.nextInt();
		long max = a;
		int min = a;
		long total = a;
		for (int i = 0; i< n-1; ++i) {
			int b = scanner.nextInt();
			total = total + b;
			if (max < b) {
				max = b;
			} else if (min > b) {
				min = b;
			}
			

		}

		System.out.println(min + " " + max + " " + total);
	}
}



Measured memory_bytes: 41400
#include <iostream>
#include <algorithm>
#include <vector>
#include <iomanip>
#include <map>
#include <set>
using namespace std;

void solve(){
  vector<vector<int> > c(3, vector<int>(3));
  for(int i = 0; i < 3; i++) for(int j = 0; j < 3; j++) cin >> c[i][j];
  vector<int> b(3);
  for(int i = 0; i < 3; i++){
    b[i] = c[0][i];
  }
  int i;
  for(i = 1; i < 3; i++){
    int x = c[i][0] - b[0];
    if(c[i][1] - x == b[1] && c[i][2] - x == b[2]);
    else break;
  }
  if(i == 3) cout << "Yes\n";
  else cout << "No\n";
  return;
}

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


Measured memory_bytes: 256
#include <iostream>
#include <utility>
#include <vector>
#include <string>
#include <algorithm>
using namespace std;
#define int long long
#define REP(i, n) for (int i = 0; i < (int)(n); i++)
#define FOR(i, m, n) for (int i = m; i < n; i++)
#define SORT(x) sort(x.begin(), x.end())
#define RS(x) rsort(x.begin(),x,end()))
#define REVE(x) reverse(x.begin(), x.end())
#define ALL(x) (x).begin(), (x).end()
typedef long double ld;
signed main(){
int n;
  cin >>n;
vector<string> a(n);
REP(i,n){
    cin >> a[i];
}
SORT(a);
a.erase(std::unique(a.begin(), a.end()), a.end());
cout << a.size();
}

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

bool isprime(int x)
{
	if(x==2)
		return true;
	
	if(x<2||x%2==0)
		return false;

	for(int i=3;i*i<=x;i+=2){
		if(x%i==0)
			return false;
	}

	return true;
}

int main()
{
	int n;
	cin>>n;
	
	int cnt=0;
	
	for(int i=0;i<n;i++){
		int x;
		cin>>x;
		
		if(isprime(x)){
			cnt++;
		}
	}

	cout<<cnt<<endl;

	return 0;
}

Measured memory_bytes: 3068
n=input()
a=map(int,raw_input().split())
#print n
#print a

a1_sum=0
a1=[]
for i in a:
	a1_sum+=i
	a1.append(a1_sum)

#print a1


#+,-
b=[]
chn_val=0
for i,val in enumerate(a1):
	val+=chn_val
	if i%2==0:
		if val>0:
			pass
		else:
			t_val=1-val
			chn_val+=t_val
			b.append(t_val)
	else:
		if val<0:
			pass
		else:
			t_val=-1-val
			chn_val+=t_val
			b.append(t_val)
ans1=0
if len(b)==0:
	ans1=0
else:
	for i in b:
		ans1+=abs(i)

#-,+
b=[]
chn_val=0
for i,val in enumerate(a1):
	val+=chn_val
	if i%2==0:
		if val<0:
			pass
		else:
			t_val=-1-val
			chn_val+=t_val
			b.append(t_val)
	else:
		if val>0:
			pass
		else:
			t_val=1-val
			chn_val+=t_val
			b.append(t_val)

ans2=0
if len(b)==0:
	ans2=0
else:
	for i in b:
		ans2+=abs(i)


print min(ans1,ans2)
			
			



Measured memory_bytes: 11272
class UnionFind():
    def __init__(self, n):
        self.n = n
        self.parents = [-1]*n  # 根のノードは限らないので注意

    def find(self, x):  # あるノードの親を探すためのメソッド
        if self.parents[x] < 0:  # 親の場合、要素の個数を負の値で保持している
            return x  # 自身が親であるということ
        else:
            self.parents[x] = self.find(self.parents[x])  # 再帰的に親を探しにいく
            return self.parents[x]

    def union(self, x, y):
        x = self.find(x)  # この変数xに格納されているものは必ず根のノード
        y = self.find(y)  # この変数yに格納されているものは必ず根のノード
        if x == y:
            return  # もし同じ親ならば何も起こらない

        if self.parents[x] > self.parents[y]:  # それぞれ、要素の個数が負で格納されている
            # yのグループの方が要素が多いの場合（yの方が値が小さいということは、負の世界では値が大きいため）
            x, y = y, x  # 必ずxの方が要素が多い状態にする

        self.parents[x] += self.parents[y]  # 負の値だが、これでいい
        self.parents[y] = x  # yは親ではなくなったため、新しい親であるxの値を正でもつ

    def size(self, x):
        return -self.parents[self.find(x)]  # 親まで辿ればグループの大きさが負で格納されているため、それにマイナスをつけてreturnする

    def same(self, x, y):
        return self.find(x) == self.find(y)  # 親が同じならTrueが返却される

    def members(self, x):  # この実装変じゃね？
        root = self.find(x)  # 親の値を取得する
        return [i for i in range(self.n) if self.find(i) == root]

    def roots(self):
        return [i for i, x in enumerate(self.parents) if x < 0]

    def group_counts(self):
        return len(self.roots())  # グループの数を返す

    def all_group_members(self):
        return {r: self.members(r) for r in self.roots()}  # 親のノード番号をキーにして、子のノードを対応させた辞書を返す

    def __str__(self):
        return '\n'.join('{}: {}'.format(r, self.members(r)) for r in self.roots())


N, M = map(int, input().split())  # N頂点, M辺の無向連結グラフ

edges = []
for _ in range(M):
    a, b = map(lambda x: int(x)-1, input().split())
    edges.append((a, b))
ans = M # 全ての辺が橋だと仮定する
for i in range(M):
    uf = UnionFind(N)
    for j in range(M):
        if j == i:
            continue
        uf.union(edges[j][0], edges[j][1])
    if min(uf.parents) == -N:  # その辺がなくても全てのノードが繋がるならばその辺は橋ではない
        ans -= 1
print(ans)


Measured memory_bytes: 3188
#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);
	}
	int counter = 0;
	while (true) {
		bool odd = false;
		for (int i = 0; i < N; i++) {
			if (A.at(i) % 2 != 0) {
				odd = true;
			}
		}
			if (odd) break;

			for (int i=0; i < N; i++) {
				A.at(i) /= 2;
			}
			counter++;
		}
	cout << counter << endl;
	}

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

//#define int long long
typedef long long ll;

typedef unsigned long long ul;
typedef unsigned int ui;
const ll mod = 1000000007;
const ll INF = mod * mod;
const int INF_N = 1e+9;
typedef pair<int, int> P;
#define stop char nyaa;cin>>nyaa;
#define rep(i,n) for(int i=0;i<n;i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define per1(i,n) for(int i=n;i>=1;i--)
#define Rep1(i,sta,n) for(int i=sta;i<=n;i++)
#define all(v) (v).begin(),(v).end()
typedef pair<ll, ll> LP;
typedef long double ld;
typedef pair<ld, ld> LDP;
const ld eps = 1e-12;
const ld pi = acos(-1.0);
//typedef vector<vector<ll>> mat;
typedef vector<int> vec;

//繰り返し二乗法
ll mod_pow(ll a, ll n, ll m) {
	ll res = 1;
	while (n) {
		if (n & 1)res = res * a%m;
		a = a * a%m; n >>= 1;
	}
	return res;
}

struct modint {
	ll n;
	modint() :n(0) { ; }
	modint(ll m) :n(m) {
		if (n >= mod)n %= mod;
		else if (n < 0)n = (n%mod + mod) % mod;
	}
	operator int() { return n; }
};
bool operator==(modint a, modint b) { return a.n == b.n; }
modint operator+=(modint &a, modint b) { a.n += b.n; if (a.n >= mod)a.n -= mod; return a; }
modint operator-=(modint &a, modint b) { a.n -= b.n; if (a.n < 0)a.n += mod; return a; }
modint operator*=(modint &a, modint b) { a.n = ((ll)a.n*b.n) % mod; return a; }
modint operator+(modint a, modint b) { return a += b; }
modint operator-(modint a, modint b) { return a -= b; }
modint operator*(modint a, modint b) { return a *= b; }
modint operator^(modint a, int n) {
	if (n == 0)return modint(1);
	modint res = (a*a) ^ (n / 2);
	if (n % 2)res = res * a;
	return res;
}

//逆元(Eucledean algorithm)
ll inv(ll a, ll p) {
	return (a == 1 ? 1 : (1 - p * inv(p%a, a)) / a + p);
}
modint operator/(modint a, modint b) { return a * modint(inv(b, mod)); }

const int max_n = 1 << 18;
modint fact[max_n], factinv[max_n];
void init_f() {
	fact[0] = modint(1);
	for (int i = 0; i < max_n - 1; i++) {
		fact[i + 1] = fact[i] * modint(i + 1);
	}
	factinv[max_n - 1] = modint(1) / fact[max_n - 1];
	for (int i = max_n - 2; i >= 0; i--) {
		factinv[i] = factinv[i + 1] * modint(i + 1);
	}
}
modint comb(int a, int b) {
	if (a < 0 || b < 0 || a < b)return 0;
	return fact[a] * factinv[b] * factinv[a - b];
}
using mP = pair<modint, modint>;

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




void solve() {
    int N; cin >> N;
	vec X(N);
	rep(i, N){
		cin >> X[i];
	}
	sort(all(X));
	int l = X[0];
	reverse(all(X));
	int r = X[0];

	ll res = INF;
	Rep1(i, l, r){
		ll tmp=0;
		rep(j, N){
			tmp += (i-X[j])*(i-X[j]);
		}
		res = min(res, tmp);
	}

	cout << res << endl;
}

signed main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  //cout << fixed << setprecision(10);
  //init_f();
  //init();
  //int t; cin >> t; rep(i, t)solve();
  solve();
//   stop
    return 0;
}


Measured memory_bytes: 4352
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ABC_C
{
    class C061
    {
        static void Main(string[] args)
        {
            string[] s1 = Console.ReadLine().Split(' ');
            int N = int.Parse(s1[0]);
            long K = long.Parse(s1[1]);

            SortedDictionary<int, long> dic = new SortedDictionary<int, long>();
            List<int> list = new List<int>();
            for (int i = 0; i < N; i++)
            {
                string[] s = Console.ReadLine().Split(' ');
                int a = int.Parse(s[0]);
                int b = int.Parse(s[1]);

                if (!dic.ContainsKey(a)) dic.Add(a, 0);
                dic[a] += b;
            }

            long counter = 0;
            int index = 0;
            List<long> v = dic.Values.ToList();
            while (true)
            {
                counter += v[index];
                if (counter >= K) break;
                index++;
            }
            int x = dic.Keys.ToList()[index];
            Console.WriteLine(x);

        }
    }
}


Measured memory_bytes: 21700
#include<iostream>
#include<algorithm>
#include<cmath>
#include<map>
#include<stdio.h>
#include<vector>
using namespace std;
#define int long long
#define rep(s,i,n) for(int i=s;i<n;i++)
#define c(n) cout<<n<<endl;
#define ic(n) int n;cin>>n;
#define sc(s) string s;cin>>s;
#define mod 1000000007
#define inf 1000000000000000007
#define f first
#define s second
#define mini(c,a,b) *min_element(c+a,c+b)
#define maxi(c,a,b) *max_element(c+a,c+b)
int keta(int x){
	rep(0,i,30){
		if(x<10){
			return i+1;
		}
		x=x/10;
	}
}
int gcd(int x,int y){
	int aa=x,bb=y;
	rep(0,i,1000){
		aa=aa%bb;
		if(aa==0){
			return bb;
		}	
		bb=bb%aa;
		if(bb==0){
			return aa;
		}
	}
}	
int lcm(int x,int y){
	int aa=x,bb=y;
	rep(0,i,1000){
		aa=aa%bb;
		if(aa==0){
			return x/bb*y;
		}	
		bb=bb%aa;
		if(bb==0){
			return x/aa*y;
		}
	}
}
char mem[114514];
char t[114514];
char s[114514][10];
string ss[114514];
int a[114514],b[114514];
signed main(){
	ic(n)
	rep(0,i,n){
		rep(0,j,10){
			cin>>s[i][j];
		}	
		sort(s[i],s[i]+10);
	}	
	rep(0,i,n){
		rep(0,j,10){
			ss[i]+=s[i][j];
		}
	}			
	sort(ss,ss+n);
	int ans=0,renzoku=0;
	rep(0,i,n){
		if(ss[i]==ss[i+1]){
			renzoku++;
		}
		else{
			ans+=renzoku*(renzoku+1)/2;
			renzoku=0;
		}
	}
	c(ans)		
}	


Measured memory_bytes: 8320
//#pragma GCC optimize("Ofast")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,avx2,fma")
//#pragma GCC optimize("unroll-loops")

#include <bits/stdc++.h>

using namespace std;

#define PI          3.1415926535897932384626433832795l

#define pb push_back
#define mp make_pair
#define lb lower_bound // First element which is not less than val
#define ub upper_bound // First element greater than val
#define f first
#define s second

using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vll = vector<ll>;
using vvll = vector<vll>;
using vb = vector<bool>;
using vd = vector<double>;
using vs = vector<string>;
using vpii = vector<pair<int,int>>;
using vpll = vector<pair<ll,ll>>;

using pii = pair<int,int>;
using pll = pair<ll,ll>;

#define endl '\n'
#define re return
#define repz(i, a) for (ll i = 0; i < (a); i++)
#define vecin(n,v) for(ll i = 0; i < n; i++) cin>>v[i];
#define full(v) v.begin(),v.end()

const int N = 2e5+7;
vi adj[N];
vi a[2];
vi vals[3];
int col0 = 0, col1 = 0;

void dfs(int s, int par, int t)
{
  a[t].pb(s);
  for (int u : adj[s])
  {
    if (u==par)
      continue;
    dfs(u,s,t^1);
  }
}

void solve()
{
  int n;
  cin >> n;
  repz(i,n-1)
  {
    int x,y;
    cin >> x >> y;
    x--;
    y--;
    adj[x].pb(y);
    adj[y].pb(x);
  }

  dfs(0,-1,0);

  for (int i = 1; i <= n; i++)
    vals[i%3].pb(i);

  vi ans(n);

  for (int t = 0; t < 2; t++)
  {
    if ((int)a[t].size() <= (int)vals[0].size())
    {
      for (int v : a[t])
      {
        ans[v] = vals[0].back();
        vals[0].pop_back();
      }

      for (int v : a[t^1])
      {
        int k = 0;
        while (vals[k].empty())
          k++;
        ans[v] = vals[k].back();
        vals[k].pop_back();
      }
    
    for (int x : ans)
      cout << x << " ";
    re;
    }
  }

  for (int t = 0; t < 2; t++)
  {
    for (int v : a[t])
    {
      int k = t+1;
      if (vals[k].empty())
      {
        k = 0;
      }
      ans[v] = vals[k].back();
      vals[k].pop_back();
    }
  }

  for (int x : ans)
  {
    cout << x << " ";
  }
}

int main()
{
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);

  ll t = 1;
  //cin >> t;
  while (t--)
  {
    solve();
  }
}



Measured memory_bytes: 24300
#include <bits/stdc++.h>
using namespace std;
typedef long long llo;
#define mp make_pair
#define pb push_back
#define a first 
#define b second
//#define endl '\n' 


llo n,m;
llo val[100001];
vector<llo> adj[100001];
llo ss=0;
llo st=1;
void dfs(llo no,llo val2=1){
	val[no]=val2;
	ss+=1;
	for(auto j:adj[no]){
		if(val[j]==0){
			dfs(j,3-val2);
		}
		else{
			if(val[j]==val[no]){
				st=0;
			}
		}
	}
}
int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cin>>n>>m;
	for(llo i=0;i<m;i++){
		llo aa,bb;
		cin>>aa>>bb;
		aa--;
		bb--;
		adj[aa].pb(bb);
		adj[bb].pb(aa);
	}
	llo x=0;
	llo y=0;
	llo ans=0;
	llo coo=0;
	for(llo i=0;i<n;i++){
		if(val[i]==0){
			ss=0;
			st=1;
			dfs(i);
			if(ss==1){
				//ans+=2*n-1;
				coo+=1;
			}
			else{
				if(st){
					y+=1;
				}
				else{
					x+=1;
				}
			}
		}
	}
	if(coo>0){
		ans+=(n-coo)*2*coo;
		ans+=coo*coo;
	}
	ans+=x*x+2*x*y+2*y*y;
	cout<<ans<<endl;


	return 0;
}

Measured memory_bytes: 16648
import java.util.Arrays;
import java.util.Scanner;

public class Main {

  Scanner sc;

  Main() {
    sc = new Scanner(System.in);
  }

  int ni() {
    return sc.nextInt();
  }

  public static void main(String[] args) {
    new Main().run();
  }

  class Point {
    int x, y;
  }

  int[][] ofs = {
      {-1, 0},
      {0, 1},
      {1, 0},
      {0, -1}
  };
  int INF = 1 << 28;

  void run() {
    for (; ; ) {
      int h = ni();
      if (h == 0) {
        break;
      }
      int[][] field = new int[h][5];
      for (int i = 0; i < h; ++i) {
        for (int j = 0; j < 5; ++j) {
          field[i][j] = ni();
        }
      }

      int sum = 0;
      for (; ; ) {
        boolean flag = false;

        for (int i = h - 1; 0 <= i; --i) {
          for (int j = 0; j < 5; ++j) {
            int val = field[i][j];
            if (val == 0) {
              continue;
            }
            int cnt = 1;
            for (int k = j + 1; k < 5; ++k) {
              if (val == field[i][k]) {
                ++cnt;
              } else {
                break;
              }
            }
            if (cnt >= 3) {
              flag |= true;
              for (int k = j; k < 5; ++k) {
                if (val == field[i][k]) {
                  sum += field[i][k];
                  field[i][k] = 0;
                } else {
                  break;
                }
              }
            }
          }
        }
        if (!flag) {
          break;
        }

        for (int i = h - 1; 0 <= i; --i) {
          for (int j = 0; j < 5; ++j) {
            for (int k = i; k + 1 < h; ++k) {
              if (field[k + 1][j] != 0) {
                break;
              }
              field[k + 1][j] = field[k][j];
              field[k][j] = 0;
            }
          }
        }
      }

      System.out.println(sum);


    }
  }

  void debug(Object... os) {
    System.err.println(Arrays.deepToString(os));
  }
}

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



int main()
{
	int sratus = 1;
  	string s;
  	char t;
  	while(getline(cin, s)){
      	for (int i = 0; i < s.size(); i++){
          	if ( s[i] - 'A' >= 0 && 'Z' - s[i] >= 0 ){
              	t = s[i] - 'A' + 'a';
        		cout << t;
            }
        	else if ( s[i] - 'a' >= 0 && 'z' - s[i] >= 0 ){
          		t = s[i] - 'a' + 'A';
        		cout << t;
            }
          	else cout << s[i];
        }
    	cout << endl;
    }
    return 0;
}


Measured memory_bytes: 3176
using System;
using System.Collections.Generic;
using System.Linq;
using static Input;

public class Prog
{
    public struct Pair { public int x, y; public Pair(int x, int y) { this.x = x; this.y = y; } }
    public static void Solve()
    {
        int A = NextInt();
        int B = NextInt();
        Console.WriteLine(A <= 8 && B <= 8 ? "Yay!" : ":(");
    }
    public static void Main()
    {
        var sw = new System.IO.StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false };
        Console.SetOut(sw);
        Solve();
        Console.Out.Flush();
    }
}

public class Input
{
    public const long MOD = 1000000007;
    private static Queue<string> q = new Queue<string>();
    private static void Confirm() { if (q.Count == 0) foreach (var s in Console.ReadLine().Split(' ')) q.Enqueue(s); }
    public static int NextInt() { Confirm(); return int.Parse(q.Dequeue()); }
    public static long NextLong() { Confirm(); return long.Parse(q.Dequeue()); }
    public static string NextString() { Confirm(); return q.Dequeue(); }
    public static double NextDouble() { Confirm(); return double.Parse(q.Dequeue()); }
    public static int[] LineInt() { return Console.ReadLine().Split(' ').Select(int.Parse).ToArray(); }
    public static long[] LineLong() { return Console.ReadLine().Split(' ').Select(long.Parse).ToArray(); }
    public static string[] LineString() { return Console.ReadLine().Split(' ').ToArray(); }
    public static double[] LineDouble() { return Console.ReadLine().Split(' ').Select(double.Parse).ToArray(); }
}


Measured memory_bytes: 11220
#include<iostream>
#include <algorithm>
#include <vector>
#include <deque>
#include <set>
#include <map>
#include <queue>

using namespace std;
long long N,M,from,to,root;
map<long long ,vector<long long> > G;
map<long long ,vector<long long> > reverseG;

long long* parents;
long long* depths;

struct node{
    long long depth;
    long long index;
    long long parent;
};

auto c = [](node p1,node p2) {
        return p1.depth < p2.depth;
        };

priority_queue<node,vector<node>,decltype(c)> q1(c);

void wfs(long long start){
    q1.push({0,start,0});
    while(!q1.empty()){
        node n = q1.top();
        q1.pop();
        if (depths[n.index] < n.depth){
            depths[n.index] = n.depth;
            parents[n.index] = n.parent;

            for (int i = 0; i< G[n.index].size();i++){
                long long next = G[n.index][i];
                bool real_edge = true;
                for(int j = 0;j < reverseG[next].size();j++){
                    long long reverse_node = reverseG[next][j];
                    if (reverse_node != i && depths[reverse_node] == -1){
                        real_edge = false;
                    }
                }
                if (real_edge){
                    q1.push({n.depth+1,next,n.index});
                }
            }
        }
    }
}


int main()
{
    // 整数の入力
    cin >> N >> M;
    parents = new long long[N+1];
    depths = new long long[N+1];
    for (int i = 1; i<= N ; i++){
        parents[i] = 0;
        depths[i] = -1;
    }
    parents = new long long[N+1];
    for (int i= 1;i<= N - 1 + M;i++){
        cin >> from >> to;
        G[from].push_back(to);
        reverseG[to].push_back(from);
        parents[to] = -1;
    }

    for (int i = 1; i<= N ; i++){
        if (parents[i] == 0){
            root = i;
        }
    }

    wfs(root);
    for (int i = 1; i<= N ; i++){
        // cout << depths[i] << " ";
        cout << parents[i] << endl;
    }

    return 0;
}

Measured memory_bytes: 25196
#include<iostream>
#include<string>
#include<algorithm>
using namespace std;
int main(){
	int r;
	cin>>r;
	if(r<1200){
		cout<<"ABC"<<endl;
	}
	
	else if(1200<=r && r<2800){
		cout<<"ARC"<<endl;
	}
	
	else if(2800<=r){
		cout<<"AGC"<<endl;
	}
}

Measured memory_bytes: 256
N = int(input())

s_list = {"AC": 0, "TLE": 0, "WA": 0, "RE": 0}

# a, t, w, r = 0, 0, 0, 0

for i in range(N):
  s = input()
  if s == "AC":
    s_list["AC"] += 1
  elif s == "TLE":
    s_list["TLE"] += 1
  elif s == "WA":
    s_list["WA"] += 1
  else:
    s_list["RE"] += 1
    

print("AC x {}\nWA x {}\nTLE x {}\nRE x {}".format(s_list["AC"], s_list["WA"], s_list["TLE"], s_list["RE"]))

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

int main(){
  // 入力
  int X;
  cin >> X;
  
  // 500円玉が何枚使えるか
  int counter_500coin = X / 500;
  X -= 500 * counter_500coin;
  
  // 5円玉が何枚使えるか
  int counter_5coin = X / 5;
  
  // 得られる嬉しさ
  int utility = counter_500coin * 1000 + counter_5coin * 5;
  
  // 出力
  cout << utility << endl;
}

Measured memory_bytes: 256
N, U, V = map(int, input().split())
A = [[] for _ in range(N)]

import sys
import numpy as np
sys.setrecursionlimit(10**8)
for _ in range(N - 1):
    a, b = map(int, input().split())

    A[a - 1].append(b - 1)
    A[b - 1].append(a - 1)

C = [0] * N
D = [0] * N

def DFS(x, pre, cnt, C):
    C[x] = cnt
    cnt += 1
    for a in A[x]:
        if a == pre:
            continue

        DFS(a, x, cnt, C)


DFS(V - 1, -1, 0, C)
DFS(U - 1, -1, 0, D)

E = np.array(C) > np.array(D)
C = np.array(C)
ans = max(C[E]) - 1
print(ans)


Measured memory_bytes: 108992
#define _USE_MATH_DEFINES
#include <cstdio>
#include <iostream>
#include <sstream>
#include <fstream>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <complex>
#include <string>
#include <vector>
#include <array>
#include <list>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <bitset>
#include <numeric>
#include <limits>
#include <climits>
#include <cfloat>
#include <functional>
#include <iterator>
#include <memory>
#include <regex>
using namespace std;

int main()
{
    int n;
    cin >> n;
    vector<int> a(3), b(3);
    for(int j=0; j<3; ++j)
        cin >> a[j];
    for(int j=0; j<3; ++j)
        cin >> b[j];

    long long ans = n;
    for(int i=0; i<2; ++i){
        int m = (int)ans;
        vector<long long> dp(m+1, 0);
        for(int j=0; j<3; ++j){
            for(int x=m; x>=a[j]; --x){
                int y = x - a[j];
                dp[y] = max(dp[y], dp[x] + b[j]);
            }
        }
        for(int j=0; j<=m; ++j)
            ans = max(ans, dp[j] + j);
        a.swap(b);
    }
    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 195584
S = input()
topping = 0 #トッピング料金変数を初期化
#oが何文字あるか数えて、その文字数×１００がトッピング料金

for i in S:
    if i == "o":
        topping = topping + 1 
#print(topping)        
price = 700 +  100*topping
print(price)

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

int getIndex(std::vector<int> &vec, int searchElement) {
  for (int i = 0; i < vec.size(); i++) {
    if (vec[i] == searchElement) return i;
  }
  return -1;
}

int main() {
  //     | 5 |
  // | 4 | 1 | 3 | 6 |
  //     | 2 |
  //
  //     | 1 |
  // | 4 | 2 | 3 | 5 |
  //     | 6 |
  //
  //     | 1 |
  // | 2 | 3 | 5 | 4 |
  //     | 6 |
  //
  //     | 1 |
  // | 5 | 4 | 2 | 3 |
  //     | 6 |
  //
  //     | 1 |
  // | 3 | 5 | 4 | 2 |
  //     | 6 |
  //
  //     | 5 |
  // | 3 | 6 | 4 | 1 |
  //     | 2 |
  std::vector<std::vector<int>> dice = {{5, 3, 2, 4}, {1, 3, 6, 4},
                                        {1, 5, 6, 2}, {1, 2, 6, 5},
                                        {1, 4, 6, 3}, {5, 4, 2, 3}};
  std::vector<int> givenDice;
  for (int i = 0; i < 6; i++) {
    int buf;
    std::cin >> buf;
    givenDice.push_back(buf);
  }
  int q;
  std::cin >> q;
  while (q-- > 0) {
    int top, front;
    std::cin >> top >> front;
    int topIndex = getIndex(givenDice, top);
    int frontIndex = getIndex(givenDice, front);

    auto candicates = dice[topIndex];
    int candicateFrontIndex = getIndex(candicates, frontIndex + 1);
    int candicateRightIndex = candicateFrontIndex == 0
                                  ? candicates.size() - 1
                                  : candicateFrontIndex - 1;
    int rightIndex = candicates[candicateRightIndex] - 1;
    std::cout << givenDice[rightIndex] << std::endl;
  }

  return 0;
}



Measured memory_bytes: 3128
#define _CRT_SECURE_NO_WARNINGS
#include<iostream>
#include <string>
#include <stdio.h>


using namespace std;

int a = 0;

int main(){
	while (true)
	{
		char c[1000] = { 0 };
		scanf("%s", c);

		if (c[0] == '0') break;

		int i = 0;
		int sum = 0;

		while (c[i]) {
			sum += c[i] - '0';
			i++;
		}

		printf("%d\n", sum);

		/*for (int i = 0; i < s.size(); i++){
			a += s[i] - '0';
		}
		s = " ";
		a = 0;*/
		
	}

	return 0;
}


Measured memory_bytes: 3172
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int n;
int m[100005];
int a[100005];
int main()
{
    cin>>n;
    for(int i=1;i<=n;i++)
    {
        scanf("%d",&m[i]);
        a[i]=m[i]-m[i-1];
    }
    sort(m+1,m+n+1);
    int q=0;
    int cnt=n;
    for(int i=1;i<=n;i++)
    {
        if(a[i]&1)
        {
            q^=cnt;
        }
        if(a[i]!=a[i-1])
        {
            cnt--;
        }
    }
    if(!q)  cout<<"second";
    else      cout<<"first";
    return 0;
}




Measured memory_bytes: 1024
#include<stdio.h>

int main(void) {
	int n, a, b;
	scanf("%d %d %d", &n, &a, &b);
	if (a * n > b) {
		printf("%d\n", b);
	}
	else {
		printf("%d\n", a * n);
	}
	return 0;
}

Measured memory_bytes: 128
W,H,N=map(int,input().split())
leftW,leftH=0,0
rightW,rightH=W,H

for i in range(N):
    x,y,a=map(int,input().split())
    if a==1 and leftW<x:
        leftW=x
    elif a==2 and x<rightW:
        rightW=x
    elif a==3 and leftH<y:
        leftH=y
    elif a==4 and y<rightH:
        rightH=y
ansH=rightH-leftH
ansW=rightW-leftW
if ansH<0: ansH=0
if ansW<0: ansW=0
print(ansH*ansW)

Measured memory_bytes: 3064
using System;

namespace ChokudaiScanner
{
    class MainClass
    {
        static void Main()
        {
            Scanner cin = new Scanner();

            int K = cin.NextInt();
            int A = cin.NextInt();
            int B = cin.NextInt();
            string ans = "NG";

            for(int i = 1; i < B + 1; i++)
            {
                if (K * i >= A)
                {
                    if(K * i <= B)
                    {
                        ans = "OK";
                        break;
                    }

                }
            }
            Console.WriteLine(ans);
            

        }
    }

    class Scanner
    {
        string[] s;
        int i;

        char[] cs = new char[] { ' ' };

        public Scanner()
        {
            s = new string[0];
            i = 0;
        }

        public string Next()
        {
            if (i < s.Length) return s[i++];
            string st = Console.ReadLine();
            while (st == "") st = Console.ReadLine();
            s = st.Split(cs, StringSplitOptions.RemoveEmptyEntries);
            if (s.Length == 0) return Next();
            i = 0;
            return s[i++];
        }

        public string[] ArrayNext(int N)
        {
            string[] Array = new string[N];
            for (int i = 0; i < N; i++)
            {
                Array[i] = Next();
            }
            return Array;
        }

        public int NextInt()
        {
            return int.Parse(Next());
        }
        public int[] ArrayInt(int N, int add = 0)
        {
            int[] Array = new int[N];
            for (int i = 0; i < N; i++)
            {
                Array[i] = NextInt() + add;
            }
            return Array;
        }

        public long NextLong()
        {
            return long.Parse(Next());
        }

        public long[] ArrayLong(int N, long add = 0)
        {
            long[] Array = new long[N];
            for (int i = 0; i < N; i++)
            {
                Array[i] = NextLong() + add;
            }
            return Array;
        }

        public double NextDouble()
        {
            return double.Parse(Next());
        }


        public double[] ArrayDouble(int N, double add = 0)
        {
            double[] Array = new double[N];
            for (int i = 0; i < N; i++)
            {
                Array[i] = NextDouble() + add;
            }
            return Array;
        }
    }
}

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

using namespace std;

int main(){

  int n,m;
  cin >> n;
  vector<int> t(n);

  for (int i = 0; i < n; i++) {
    cin >> t.at(i);
  }
  int sum = 0;
  for (int i = 0; i < n; i++) {
    sum += t.at(i);
  }
  //cout << sum << endl;
  cin >> m;
  vector<int> p(m);
  vector<int> x(m);
  vector<int> ans(m);

  for (int i = 0; i < m; i++) {
    cin >> p.at(i) >> x.at(i);
  }

  for (int i = 0; i < m; i++) {
    ans.at(i) = sum - t.at(p.at(i)-1) + x.at(i);
    cout << ans.at(i) << endl;
  }

  return 0;

}


Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <vector>
#include <functional>
#include <queue>
#include <string>
#include <cstring>
#include <numeric>
#include <cstdlib>
#include <cmath>
#include <map>
#include <unordered_map>
#include <set>
using namespace std;

typedef long long ll;

#define INF 10e17
#define rep(i,n) for(long long i=0; i<n; i++)
#define repr(i,n,m) for(long long i=m; i<n; i++)
#define END cout << endl
#define MOD 1000000007
#define pb push_back
#define sorti(x) sort(x.begin(), x.end())
#define sortd(x) sort(x.begin(), x.end(), std::greater<long long>())
#define debug(x) std::cerr << (x) << std::endl;
#define roll(x) for (auto&& itr : x) { debug(itr); }

template <class T> inline void chmax(T &ans, T t) { if (t > ans) ans = t;}
template <class T> inline void chmin(T &ans, T t) { if (t < ans) ans = t;}

/*
  区別できるボール 1つずつが, 区別できる箱 kを1つ選ぶ。
  つまり、kC1 * n = k^n
*/

int main() {
  ll n, k;
  cin >> n >> k;
  ll cpy = 1;
  for (int i = 0; i < n; ++i) {
    cpy *= k;
    cpy %= MOD;
  }

  cout << cpy << endl;
}



Measured memory_bytes: 3108
from heapq import heappop,heappush

n,k = map(int,input().split())
a = [0] + list(map(int,input().split()))

ans = 0
if(a[1] != 1):
    ans += 1

links_c = [set() for _ in range(n+1)]
for i,ai in enumerate(a[2:],2):
    links_c[ai].add(i)

depth = [-1] * (n+1)
depth[1] = 0
stack = [1]
hq = []
while(stack):
    next = []
    while(stack):
        i = stack.pop()
        for j in links_c[i]:
            depth[j] = depth[i] + 1
            heappush(hq, (depth[j]*-1,j))
            next.append(j)
    stack = next[::]

while( hq[0][0]*-1 > k ):
    di,i = heappop(hq)
    if( depth[i] <= k ):
        continue

    for j in range(k-1):
        i = a[i]

    ans += 1
    links_c[a[i]].remove(i)
    stack = [i]
    while(stack):
        next = []
        while(stack):
            i = stack.pop()
            depth[i] = 1
            for j in links_c[i]:
                next.append(j)
        stack = next[::]

print(ans)


'''
首都の自己ループを除くと、首都を根として、
子→親の有向木になっている。

・首都のテレポート先は首都でないとダメ
→　長さ2以上の閉路を作るとうまくいかない

・首都以外は、首都までの距離をk以下にできればよい

もっとも根からの距離が遠い頂点xをとる。
xが根からの距離k以下　→　終了してOK
xが根からの距離k以上
→　xからk-1個離れた親を首都につなぎなおす
　そして再度最も遠い頂点を探す、を繰り返す。

'''

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

int main() {
 string str, sts, stt ;
  cin >> str >> sts >> stt ;
  string text , textb , textc;
  text = str.at(0) ;
  textb = sts.at(0) ;
  textc = stt.at(0) ;
  cout <<  text + textb + textc <<endl;
  }

Measured memory_bytes: 256
#include <iostream>
#include <stdio.h>
using namespace std;

int main(){
	int card[52] = {0};
	int n;
	cin >> n;
	for(int i = 0; i < n; i++){
		char c;
		int a;
		cin >> c >> a;

		if(c == 'S'){
			card[a-1] = 1;
		}else if(c == 'H'){
			card[a-1+13] = 1;
		}else if(c == 'C'){
			card[a-1+26] = 1;
		}else if(c == 'D'){
			card[a-1+39] = 1;
		}
	}

	for(int i = 0; i < 52; i++){
		if(card[i] == 0){
			if(i < 13){
				cout << "S " << i+1 << endl;
			}else if(i < 26){
				cout << "H " << (i%13)+1 << endl;
			}else if(i < 39){
				cout << "C " << (i%13)+1 << endl;
			}else{
				cout << "D " << (i%13)+1 << endl;
			}
		}
	}
	return 0;	
}


Measured memory_bytes: 3004