akhauriyash/Code-Regression huggingface dataset:
N = int(input())
for i in range(N):
    x,y,z = map(int,input().split())
    if x>y and x>z:
        s = y**2+z**2
        u = x**2
        if s==u:
            print("YES")
        else:
            print("NO")
    elif y>x and y>z:
        s = x**2+z**2
        u = y**2
        if s==u:
            print("YES")
        else:
            print("NO")
    else:
        s = x**2+y**2
        u = z**2
        if s==u:
            print("YES")
        else:
            print("NO")
    i += 1



Measured memory_bytes: 5592
#include <cstdio>
#include <set>
#include <iostream>
#include <vector>
#include <algorithm>
#include <queue>
#include <cmath>
#include <map>
#include <stack>
#include <deque>
#include <iomanip>
using namespace std;

#define ll long long
#define ld long double
#define M_PI 3.14159265358979323846264338327950288
const int N = 998244353;

ll count(int x, int y, int a, int b, vector<vector<int> > &dp) {
    if (x < a || y < b) return 0;
    if (dp[x][y] != -1) return dp[x][y];

    ll val = count(x - 1, y, a, b, dp) * y % N;
    val = (val + count(x, y - 1, a, b, dp) * x) % N;
    val = (val - count(x - 1, y - 1, a, b, dp) * (x - 1) * (y - 1)) % N;
    val = (val + N) % N;
    
    return dp[x][y] = val;
}

void solve() {
    int a, b, c, d;
    cin >> a >> b >> c >> d;

    vector<vector<int> > dp(3001);
    for (int i = 0; i < 3001; ++i) {
        dp[i].resize(3001, -1);
    }

    dp[a][b] = 1;
    cout << count(c, d, a, b, dp);
}

int main(){
    int tt = 1;
    // cin >> tt;
    while(tt--) {
        solve();
    }
    return 0;
}

Measured memory_bytes: 39412
import java.io.PrintWriter;
import java.util.Scanner;

public class Main{
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		PrintWriter out = new PrintWriter(System.out);

		//入力
		int a = sc.nextInt();
		int b = sc.nextInt();
		int c = sc.nextInt();
		sc.close();

		//処理
		boolean f = (b - a == c - b);

		//出力	
		out.println(f ? "YES" : "NO");
		out.flush();
	}
}

Measured memory_bytes: 22612
import java.util.ArrayList;
import java.util.Collections;
import java.util.Iterator;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int data;
		int cnt = 0;
		int alice = 0;
		int bob = 0;
		ArrayList<Integer> lists = new ArrayList<Integer>();

		//リストに追加
		//		for (int list : lists) {
		//			lists.add(sc.nextInt());
		//		}
		for (int i = 0; i < n; i++) {
			lists.add(sc.nextInt());
		}

		//ソート
		Collections.sort(lists, Collections.reverseOrder());
		//		Arrays.sort(lists, Collections.reverseOrder());

		//ソートしたものを表示
		Iterator<Integer> it = lists.iterator();
		while (it.hasNext()) {
			data = it.next();
			//			System.out.println(data);
			if (cnt % 2 == 0) {
				alice = alice + data;
				cnt++;
			} else {
				bob = bob + data;
				cnt++;
			}
		}

		System.out.println(alice - bob);
	}

}


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

int main(){
	long long N;
	cin >> N;
	long long a=1, b=1, c=1,ans;
	for (long long i = 0; i < N; i++)
	{
		a *= 10;
		b *= 9;
		c *= 8;
		a = a % (1000000000 + 7);
		b = b % (1000000000 + 7);
		c = c % (1000000000 + 7);
	}
	b = 2 * b % (1000000000 + 7) ;
	ans = a - b + c;
	if (ans < 0) ans += 1000000000 + 7;
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 3588
#[allow(unused_imports)]
use std::cmp::{max, min, Ordering};
#[allow(unused_imports)]
use std::collections::{HashMap, HashSet, BinaryHeap, VecDeque, BTreeSet, BTreeMap};
#[allow(unused_imports)]
use std::iter::FromIterator;
#[allow(unused_imports)]
use std::io::stdin;

mod util {
    use std::io::stdin;
    use std::str::FromStr;
    use std::fmt::Debug;

#[allow(dead_code)]
    pub fn line() -> String {
        let mut line: String = String::new();
        stdin().read_line(&mut line).unwrap();
        line.trim().to_string()
    }

#[allow(dead_code)]
    pub fn gets<T: FromStr>() -> Vec<T>
        where
        <T as FromStr>::Err: Debug,
        {
            let mut line: String = String::new();
            stdin().read_line(&mut line).unwrap();
            line.split_whitespace()
                .map(|t| t.parse().unwrap())
                .collect()
        }
}

#[allow(unused_macros)]
macro_rules! get {
    ($t:ty) => {
        {
            let mut line: String = String::new();
            stdin().read_line(&mut line).unwrap();
            line.trim().parse::<$t>().unwrap()
        }
    };
    ($($t:ty),*) => {
        {
            let mut line: String = String::new();
            stdin().read_line(&mut line).unwrap();
            let mut iter = line.split_whitespace();
            (
                $(iter.next().unwrap().parse::<$t>().unwrap(),)*
            )
        }
    };
    ($t:ty; $n:expr) => {
        (0..$n).map(|_|
                    get!($t)
                   ).collect::<Vec<_>>()
    };
    ($($t:ty),*; $n:expr) => {
        (0..$n).map(|_|
                    get!($($t),*)
                   ).collect::<Vec<_>>()
    };
    ($t:ty ;;) => {
        {
            let mut line: String = String::new();
            stdin().read_line(&mut line).unwrap();
            line.split_whitespace()
                .map(|t| t.parse::<$t>().unwrap())
                .collect::<Vec<_>>()
        }
    };
}

#[allow(unused_macros)]
macro_rules! debug {
    ($($a:expr),*) => {
        println!(concat!($(stringify!($a), " = {:?}, "),*), $($a),*);
    }
}

fn main() {
    let (n,c,k) = get!(usize, u64, u64);
    let mut ts = get!(u64; n);
    ts.sort();

    let mut b = ts[0] + k;
    let mut n = 0;
    let mut ans = 1;

    for &t in &ts {
        if b>=t && n < c {
            n +=1;
        } else {
            ans += 1;
            n = 1;
            b = t +k;
        }
    }

    println!("{}", ans);
}


Measured memory_bytes: 4352
#include <stdio.h>
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>	
#include <cmath>
#include <string>
#include<math.h>//���炵���̂Œ���
#define rep(i,n) for(int i=0;i<n;i++)
#define all(x) (x).begin(),(x).end()
#define sz(x) (int)(x).size()
#define Cout(s) cout<<s<<endl
using namespace std;
typedef long long ll;
string Yes(bool b) { if (b) { return "Yes"; } else { return "No"; } }
string YES(bool b) { if (b) { return "YES"; } else { return "NO"; } }
//================================================

int a = 1, b = 0, c, d, n, k = 0, ans = 0;
string s, t;
int mod = 1000000007;

int main()
{
	cin >> n;
	vector<int> a(n); rep(i, n)cin >> a[i];
	int ans = 1;
	rep(i, n) {
		if (a[i] % 2 == 0)
			ans *= 2;
	}
	cout << pow(3, n) - ans << endl;

	return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
int main()
{
	ll N,K,S;
	cin>>N>>K>>S;
	for(ll i=0;i<N;i++)
	{
		if(i<K) cout<<S<<" ";
		else
		{
			ll m=1e9;
			if(S==m)
			{
				cout<<S-1<<" ";
			}
			else
			{
				cout<<S+1<<" ";
			}
		}
	}
	return 0;
}

Measured memory_bytes: 1280
#include<iostream>
    #include<cstdio>
    #include<cstring>
    #include<algorithm>
    using namespace std;
    int n;
    char a[300010];
    int w[300010],e[300010];
    int ans=0x7fffffff;
    int main()
    {
    	scanf("%d",&n);
    	for(int i=0;i<=n;i++)
    	{
    		scanf("%c",&a[i]);
    		if(a[i]=='W') w[i]=w[i-1]+1,e[i]=e[i-1];
    		else e[i]=e[i-1]+1,w[i]=w[i-1];
    	}
    	for(int i=1;i<=n;i++)
    		ans=min(ans,w[i-1]+e[n]-e[i]);
    	printf("%d",ans);
    	return 0;
    }

Measured memory_bytes: 2944
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
int main(){
  string o,e;
  cin>>o>>e;
  if(o.size()>e.size()){
    rep(i,e.size()){
      cout<<o[i];
      cout<<e[i];
    }
    cout<<o[o.size()-1]<<endl;
  }
  else{
    rep(i,o.size()){
      cout<<o[i];
      cout<<e[i];
    }
    cout<<endl;
  }
}

Measured memory_bytes: 3616
#include<bits/stdc++.h>
using namespace std;
const int dx[4]={1,0,-1,0};
const int dy[4]={0,1,0,-1};
int h,w;
vector<string> field;
int main()
{
  cin>>h>>w;
  field.resize(h);
  vector<vector<int>> matrix(h,vector<int>(w,-1));
  for(int i=0;i<h;i++){
    cin>>field[i];
  }
  queue<pair<int,int>> next;
  for(int i=0;i<h;i++){
    for(int j=0;j<w;j++){
      if(field[i][j]=='#'){
        matrix[i][j]=0;
        next.push(make_pair(i,j));
      }
    }
  }
  while(next.size()!=0){
    int x=next.front().first,y=next.front().second;
    for(int i=0;i<4;i++){
      int nx=x+dx[i],ny=y+dy[i];
      if(nx<0||nx>=h||ny<0||ny>=w) continue;
      if(matrix[nx][ny]>=0) continue;
      matrix[nx][ny]=matrix[x][y]+1;
      next.push(make_pair(nx,ny));
    }
    next.pop();
  }
  int ans=0;
  for(int i=0;i<h;i++){
    for(int j=0;j<w;j++){
      ans=(matrix[i][j]>ans? matrix[i][j]:ans);
    }
  }
  cout<<ans;
}

Measured memory_bytes: 13456
#include<stdio.h>
#include<bits/stl_algobase.h>
#include<bits/stl_algo.h>
int n,l[200],ans;
main()
{
	scanf("%d",&n);
	for(register int i=0;i<2*n;++i)scanf("%d",l+i);
	std::__sort(l,l+2*n,__gnu_cxx::__ops::__iter_less_iter());
	for(register int i=0;i<2*n;i+=2)ans+=l[i];
	printf("%d\n",ans);
}/**/

Measured memory_bytes: 128
#include<iostream>
#include<vector>
#include<algorithm>
#define ite iterator
#define s begin
#define f end
using namespace std;
int main(){
    int n;
    while(cin>>n,n){
        vector<int>C[2];
        vector<bool>L(2*n);
        for(int i=0;i<n;i++){
            int d;
            cin>>d;
            C[0].push_back(d);
            L[d-1]=true;
        }
        for(int i=0;i<2*n;i++){
            if(!L[i])C[1].push_back(i+1);
        }
        for(int i=0;i<2;i++)sort(C[i].s(),C[i].f());
        int field=0;

        while(true){
            bool f=false;
            for(int i=0;i<2;i++){
                bool ac=true;
                for(vector<int>::ite j=C[i].s();j!=C[i].f();j++){
                    if(field<*j){
                        ac=false;
                        field=*j;
                        C[i].erase(j);
                        break;
                    }
                }
                if(C[i].empty()){
                    f=true;
                    break;
                }
                if(ac)field=0;

            }
            if(f)break;
        }
        cout<<C[1].size()<<endl<<C[0].size()<<endl;




    }


    return 0;
}

Measured memory_bytes: 1220
import java.util.Scanner;

//Stable Sort
public class Main {

	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		int num = scan.nextInt();

		//準備
		Card[] card = new Card[num];
		for (int i = 0; i < num; i++) {
			card[i] = Card.newInstance(scan.next());
		}

		Card[] bubbleBefore = copyCard(card);
		Card[] selectBefore = copyCard(card);
		
		//バブルソート
		Card[] bubbleAfter = bubbleSort(bubbleBefore, num);
		//バブルソート出力
		System.out.print(bubbleAfter[0]);
		for (int i = 1; i < num; i++) {
			System.out.print(" " + bubbleAfter[i].toString());
		}
		System.out.println();
		System.out.println(stableCheck(bubbleAfter,card));

		//セレクションソート
		Card[] selectAfter = selectionSort(selectBefore,num);
		//セレクトソート出力
		System.out.print(selectAfter[0]);
		for (int i = 1; i < num; i++) {
			System.out.print(" " + selectAfter[i].toString());
		}
		System.out.println();
		System.out.println(stableCheck(selectAfter,card));
	}

	/**
	 * バブルソート
	 * 
	 * @param A
	 *            ソートする配列
	 * @param N
	 *            ソートする個数
	 * @return 昇順にソートされた配列
	 */
	public static Card[] bubbleSort(Card[] A, int N) {
		boolean flag = true;
		while (flag) {
			flag = false;
			for (int j = N - 1; j >= 1; j--) {
				if (A[j].getNumber() < A[j - 1].getNumber()) {
					Card tmp;
					tmp = A[j];
					A[j] = A[j - 1];
					A[j - 1] = tmp;
					flag = true;
				}
			}
		}
		return A;
	}



	/**
	 * セレクションソート。一番小さい値を選択して入れ替える。
	 * 
	 * @param A配列
	 * @param N配列の数
	 * @return入れ替え後の配列
	 */
	public static Card[] selectionSort(Card[] A, int N) {

		for (int i = 0; i < N; i++) {
			int mini = i;
			for (int j = i; j < N; j++) {
				if (A[j].getNumber() < A[mini].getNumber()) {
					mini = j;
				}
			}
			if (mini != i) {
				Card tmp;
				tmp = A[i];
				A[i] = A[mini];
				A[mini] = tmp;
			}

		}

		return A;
	}

	public   static String stableCheck(Card[] Aftersort, Card[] Input){
		int i;
		int temae_no_card_no_ichi=-1;
		int ato_no_card_no_ichi =-1;
		for(i=0;i<Input.length-1;i++){
			if((Aftersort[i].getNumber())==(Aftersort[i+1].getNumber())){
				for(int j = 0; j < Input.length;j++){
					if(Aftersort[i].toString().equals(Input[j].toString())){//H5 =H5
					 temae_no_card_no_ichi = j;//aftersorti = 0 // 2 
					}
					if(Aftersort[i+1].toString().equals(Input[j].toString())){
						 ato_no_card_no_ichi = j;//1  sort4  //3
					}
					
				
					
				}
				if((temae_no_card_no_ichi > ato_no_card_no_ichi)){
					return "Not stable";
				}
			}
		}
		return "Stable";

	}
	
	public static Card[] copyCard(Card[] card){
		
		Card[] copycard =  new Card[card.length];
		for (int i = 0; i < card.length; i++) {
			copycard[i] = Card.newInstance(card[i].toString());
		}
		return copycard;
	}



	private static class Card {
		private String mark;
		private int number;

		private Card(String str) {
			mark = str.substring(0, 1);
			number = Integer.valueOf(str.substring(1));
		}

		public static Card newInstance(String str) {
			return new Card(str);
		}

		public int getNumber() {
			return number;
		}

		public String getMark() {
			return mark;
		}

		@Override
		public String toString() {
			return mark + number;
		}
	}

}



Measured memory_bytes: 27908
#include <bits/stdc++.h>
using namespace std;
int main()
{
    ios::sync_with_stdio(0);
    int n;
    cin>>n;
    int p=n;
    int x=0;
    while(p!=0)
    {
        x+=p%10;
        p/=10;
    }
    if(n%x==0)
        cout<<"Yes";
    else
        cout<<"No";
    return 0;
}

Measured memory_bytes: 256
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define ll long long
#define all(x) (x).begin(),(x).end()
template<class T> inline bool chmax(T& a, T b) {if (a < b) {a = b;return true;}return false;}
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
const int INF = 1000000000;

int main() {
    ll N;
    cin >> N;
    vector<ll>A(N);
    map<ll,ll>counter;
    ll current_sum = 0;
    for (ll i=0; i<N; i++){
        cin >> A[i];
        current_sum += A[i];
        counter[A[i]]++;
    }
    ll Q;
    cin >> Q;
    for (ll i=0; i<Q; i++){
        ll bi, ci;
        cin >> bi >> ci;
        current_sum -= bi * counter[bi];
        current_sum += ci * counter[bi];
        counter[ci] += counter[bi];
        // bi != ci
        counter[bi] = 0;
        cout << current_sum << endl;
    }

}

Measured memory_bytes: 10092
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int A, B;
  cin >> A >> B;
 
  int a = A * B;
  
  if( a % 2 == 0 ){
    cout << "Even" << endl;
  } else {
    cout << "Odd" << endl;
  }
}

Measured memory_bytes: 256
import java.util.Scanner;

class Problem {
    private int H;
    private int W;
    private int h;
    private int w;

    Problem() {
        Scanner sc = new Scanner(System.in);
        H = sc.nextInt();
        W = sc.nextInt();
        h = sc.nextInt();
        w = sc.nextInt();
    }

    int solve() {
        return H * W - (h * W + w * H - h * w);
    }
}

public class Main {
    public static void main(String[] args) {
        System.out.println(new Problem().solve());
    }
}


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

using namespace std;

typedef long long ll;
typedef vector<ll> v1;
typedef vector<v1> v2;
typedef unordered_map<ll,unordered_map<ll,ll>> graph;

const ll mod = 1000000007;
const ll INF = 1ll << 20;

ll n;
ll m;
ll a[1 << 20];
ll b[1 << 20];
ll am,bm;

int main(){
  cin >> n;
  for(ll i = 0;i < n;i++) cin >> a[i];
  for(ll i = 0;i < n;i++) cin >> b[i];
  m = accumulate(b,b+n,0ll)-accumulate(a,a+n,0ll);
  am = m;
  bm = m;
  for(ll i = 0;i < n;i++){
    if(a[i] < b[i]){
      if((b[i]-a[i])%2 == 0){
        am -= (b[i]-a[i])/2;
      }else{
        bm--;
        am -= (b[i]+1-a[i])/2;
      }
    }else if(a[i] > b[i]){
      bm -= a[i]-b[i];
    }
  }
  if(am >= 0 && bm >= 0 && bm == 2*am) cout << "Yes" << endl;
  else cout << "No" << endl;

}


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

int GetDigitSum(int tmp) {
  int sum = 0;
  while (tmp) {
    sum += tmp % 10;
    tmp /= 10;
  }
  return sum;
}

int main() {
  
  int N; cin >> N;
  
  int S = GetDigitSum(N);
  
  if (N % S == 0) cout << "Yes" << endl;
  
  else cout << "No" << endl;
  
}

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

fn read<T: FromStr>() -> T {
  let stdin = stdin();
  let stdin = stdin.lock();
  let token: String = stdin
    .bytes()
    .map(|c| c.expect("failed to read char") as char) 
    .skip_while(|c| c.is_whitespace())
    .take_while(|c| !c.is_whitespace())
    .collect();
  token.parse().ok().expect("failed to parse token")
}

fn main() {
  let (_, s): (usize, String) = (read(), read());
  let mut c = 0;
  
  for i in 0..s.len()-2 {
    c += if &s[i..i+3] == "ABC" { 1 } else { 0 };
  }
  
  println!("{}", c);
}

Measured memory_bytes: 4352
#include<stdio.h>
int main(){
int n,k;
scanf("%d %d",&n,&k);
int h[n],s;
for(int i=0;i<n;i++){
    scanf("%d",&h[i]);
    if(h[i]>=k){
      s++;
    }
}
printf("%d",s);
return 0;
}

Measured memory_bytes: 512
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define IOS ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
 
ll mod = 1e9+7;
ll INF = 1e17;
/*ll gcd(ll a,ll b)
{
    if(a==0)
    return(b);
    return(gcd(b%a,a));
}*/
/*ll power(ll a,ll b,ll p)
{
	ll res=1;
	a%=p;
	while(b>0)
	{
		if(b&1)
		res=res*a%p;
		a=a*a%p;
		b>>=1;
	}
	return(res);
}*/
/*void dfs(ll x)
{
	vis[x]=true;
	for(ll i=0;i<v[x].size();i++)
	{
		if(vis[v[x][i]]==false)
		dfs(v[x][i]);
	}
}*/
/*ll b_search(ll arr[],ll n,ll s)
{
	ll l=0,r=n-1;
	while(l<=r)
	{
		ll mid=l+(r-l)/2;
		if(arr[mid]==s)
		return(mid);
		if(arr[mid]<s)
		l=mid+1;
		else
		r=mid-1;
	}
	return(-1);
}*/
 
void solve()
{
	ll n,m;
	cin>>n>>m;
	if(n==m)
	cout<<"Yes"<<endl;
	else
	cout<<"No"<<endl;
}
 
int main()
{
	IOS
	ll t=1;
	//cin>>t;
	while(t--)
	{
		solve();
	}
    return(0);
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll MOD = 1e9 + 7;
const int inf = 1e9;
const ll INF = 1e18;
const double pi = 3.14159265358979323846;
#define rep(i,n) for(ll i=0;i<n;i++)

int main(){
	int n;cin>>n;
	int a[n];a[0]=0;
	rep(i,n){
		a[i+1]=a[i]+(i+1);
		//cout<<a[i+1]<<"\n";
		if(a[i+1]>=n){
			int k=a[i+1]-n;
			rep(j,i+2){
				if(j!=k&&j!=0) cout<<j<<"\n";
			}
			return 0;
		}
	}
}

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

namespace AtCoder.Contest.B
{
	static class Program
	{
		public static void Main(string[] args)
		{
			var sw = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false };
			Console.SetOut(sw);

			var cin = new Scanner();

			long a = cin.NextLong();
			long b = cin.NextLong();
			long x = cin.NextLong();
			Console.WriteLine(b / x - a / x + (a % x == 0 ? 1 : 0));

			Console.Out.Flush();
		}
	}

	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 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: 13140
#include<bits/stdc++.h>
#define fastio ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define int long long
#define ll long long
#define pb push_back
#define mp make_pair
#define fi first
#define se second
using namespace std;

const int N = 1e5+6;
int n, ar[N]; bool ok = true;
vector <int> adj[N];

int dfs(int v, int p){
  if (p != -1 && adj[v].size() == 1) return ar[v];
  int sum = 0, mx = 0;
  for (auto u : adj[v]){
    if (u == p) continue;
    int tmp = dfs(u, v);
    sum += tmp;
    mx = max(mx, tmp);
  }
  if (sum > ar[v]*2 || ar[v] > sum || mx > ar[v]) ok = false;
  return ar[v]*2 - sum;
}

signed main(){
	cin >> n;
	for (int i=1; i<=n; i++) cin >> ar[i];
	if (n == 2){
		if (ar[1] == ar[2]) cout << "YES"; else cout << "NO";
		return 0;
	}
	for (int i=1; i<n; i++){
		int u, v; cin >> u >> v;
		adj[u].pb(v);
		adj[v].pb(u);
	}
	int d;
	bool ans = false;
	for (int i=1; i<=n; i++){
		if (adj[i].size() >= 2){
			d = i;
			break;
		} 
	}
	ans = (dfs(d, -1) == 0 && ok);
	if (ans) cout << "YES"; else cout << "NO";
}

Measured memory_bytes: 15116
#include<cstdio>
#include<iostream>

int main(void)
{
	int n,m; //宝の個数、移動回数
	int i; //for変数
	int math[21][21]; //宝の位置、ある場所は1,ない場所は0
	int x,y;
	int a,b; 
	char d; //方角
	int l; //移動量
	int count; //見つけた宝の数
	int yL,xL;
	
	for(;;)
	{
		count=0;
		x=10,y=10;
		xL=x,yL=y;
		scanf("%d",&n);
		if(n==0) break;
		for(a=0; a<21; a++)
		{
			for(b=0; b<21; b++)
			{
				math[a][b]=0;
			}
		}
		for(i=0; i<n; i++)
		{
			scanf("%d  %d",&a,&b);
			math[a][b]=1;
		}
		
		scanf("%d",&m);
		for(i=0; i<m; i++)
		{
			scanf("%s %d",&d,&l);
			
			if(math[10][10]==1)
			{
				count++;
				math[10][10]=0;
			}	
			if(d=='N')
			{
				yL+=l;
				for(y=y+1; y<=yL; y++)
				{
					if(math[x][y]==1)
					{
						count+=1;
						math[x][y]=0;
					}
				}
				y--;
			}
			else if(d=='E')
			{
				xL+=l;
				for(x=x+1; x<=xL; x++)
				{
					if(math[x][y]==1)
					{
						count+=1;
						math[x][y]=0;
					}
				}
				x--;
			}
			else if(d=='S')
			{
				yL-=l;
				for(y=y-1; y>=yL; y--)
				{
					if(math[x][y]==1)
					{
						count+=1;
						math[x][y]=0;
					}
				}
				y++;
			}
			else if(d=='W')
			{
				xL-=l;
				for(x=x-1; x>=xL; x--)
				{
					if(math[x][y]==1)
					{
						count+=1;
						math[x][y]=0;
					}
				}
				x++;
			}
		}
		
		if(count==n) printf("Yes\n");
		else printf("No\n");
	}
	
	return 0;
}

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


int main(){
  ll n,t;
  cin>>n>>t;
  vector<ll>a(n);
  vector<P>b(n);

  rep(i,n)cin>>a[i];
  ll l=1000000001;
  ll now=0;
  ll p=0;
  rep(i,n){

    if(l>a[i]){
      l=min(l,a[i]);
      now=i;
    }
    p=a[i]-l;
    b[i]=make_pair(p,now);
  }
  sort(b.rbegin(),b.rend());
  ll ans=0;
  ll no=b[0].first;
  while(no==b[ans].first){

    ans++;
  }
  cout<<ans;
}


Measured memory_bytes: 1792
#include <bits/stdc++.h>
using namespace std;
#define ll long long int
#define endl '\n'
#define pb push_back
#define mod 1000000007
#define all(v) v.begin(),v.end()
#define mm memset
#define PI 3.14159265358979323846264338327950288419716939937510
#define MAXI (ll)2e5+3
#define M 998244353 
void solve(){

  ll n,m,K;
  cin>>n>>m>>K;
  ll a[n],b[m];
  for(int i=0;i<n;i++){
    cin>>a[i];
  }
  for(ll i=0;i<m;i++){
    cin>>b[i];
  }
  ll ans=0;
  if(a[0]<=K){
    ans=max(1LL,ans);
  }
  if(b[0]<=K){
    ans=max(1LL,ans);
  }
  for(ll i=1;i<n;i++){
    a[i]=a[i-1]+a[i];
    if(a[i]<=K){
      ans=max(i+1,ans);
    }
  }
  for(ll i=1;i<m;i++){
    b[i]=b[i-1]+b[i];
    if(b[i]<=K){
      ans=max(i+1,ans);
    }
  }
  ll i=0,j=m-1;
  while(i<n){

    ll curr=a[i];
    while(j>=0 && b[j]+curr>K){
      j--;
    }
    if(j<0){
      break;
    }
      ans=max(ans,i+j+2);
    i++;
  }
  cout<<ans<<endl;
}
int main(){

  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  ll t=1;
  //cin>>t;
  for(ll i=0;i<t;i++){
    solve();
  }
  return 0;
} 

Measured memory_bytes: 6764
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define MAX (ll)3501
ll N;

int main(){
	cin >> N;
	// cout << "hello";
	for(ll h=1; h<MAX; h++) for(ll w=1; w<MAX; w++){
		ll x = N*h*w;
		ll y = 4*h*w - N*w - N*h;
		if(y!=0 && x%y == 0 && (ll)x/y < MAX && x/y>0){
			cout << h << " " << w << " " << (ll)x/y << endl;
			return 0;
		}
	}
}

Measured memory_bytes: 256
#include<cstdio>
#include<cstring>
#include<algorithm>
#define MAXN 300000
#define INF 1000000000000000000LL
using namespace std;
typedef long long LL;
int N;
LL T[MAXN+5],sum[MAXN+5];
LL L[MAXN+5],R[MAXN+5];
int que[MAXN+5];
LL f[MAXN+5],h[MAXN+5],g[MAXN+5],ans[MAXN+5];
LL GetY(int j)
{
	return 1LL*f[j]+(1LL*j*j-1LL*j)/2LL+sum[j];
}
void Rev(LL seq[])
{
	for(int i=1;i<=N/2;i++)
		swap(seq[i],seq[N-i+1]);
}
void DP()
{
	int s=0,t=0;
	que[t++]=0;
	fill(f+1,f+1+N,-INF);
	for(int i=1;i<=N;i++)
	{
		while(s<t-1)
		{
			int j1=que[t-2],j2=que[t-1];
			LL y1=GetY(j1),y2=GetY(j2);
			if((y1-y2)>1LL*i*(1LL*j1-1LL*j2))
				t--;
			else
				break;
		}
		int j=que[t-1];
//		printf("fro:%d to:%d\n",j,i);
		f[i]=f[j]+((1LL*i-1LL*j)*(1LL*i-1LL*j+1LL))/2LL-(1LL*sum[i]-1LL*sum[j]);
		f[i]=max(f[i],f[i-1]);
		while(s<t-1)
		{
			int j1=que[t-2],j2=que[t-1];
			LL y1=GetY(que[t-2]),y2=GetY(que[t-1]),y3=GetY(i);
			if((1LL*y1-1LL*y2)*(1LL*j2-1LL*i)<(1LL*y2-1LL*y3)*(1LL*j1-1LL*j2))
				que[--t]=0;
			else
				break;
		}
		que[t++]=i;
	}
}
void MergeSort(int l,int r)
{
	if(l==r)
	{
		if(l!=0)
			g[l]=max(g[l],L[l-1]+R[l+1]+1LL-(sum[l]-sum[l-1]));
		else
			g[l]=0;
		return;
	}
	int mid=(l+r)/2;
	int s=0,t=0;
	for(int i=l;i<=mid;i++)
	{
		f[i]=L[i];
		while(s<t-1)
		{
			int j1=que[t-2],j2=que[t-1];
			LL y1=GetY(que[t-2]),y2=GetY(que[t-1]),y3=GetY(i);
			if((1LL*y1-1LL*y2)*(1LL*j2-1LL*i)<(1LL*y2-1LL*y3)*(1LL*j1-1LL*j2))
				que[--t]=0;
			else
				break;
		}
		que[t++]=i;
	}
	for(int i=mid+1;i<=r;i++)
	{
		while(s<t-1)
		{
			int j1=que[t-2],j2=que[t-1];
			LL y1=GetY(j1),y2=GetY(j2);
			if((y1-y2)>1LL*i*(1LL*j1-1LL*j2))
				t--;
			else
				break;
		}
		int j=que[t-1];
//		if(i==3)
//			printf("fro:%d\n",j);
		h[i]=f[j]+((1LL*i-1LL*j)*(1LL*i-1LL*j+1LL))/2LL-(1LL*sum[i]-1LL*sum[j])+R[i+1];
	}
	for(int i=r-1;i>=mid+1;i--)
		h[i]=max(h[i],h[i+1]);
	for(int i=mid+1;i<=r;i++)
		g[i]=max(g[i],h[i]);
	MergeSort(l,mid);MergeSort(mid+1,r);
}
int main()
{
	fill(ans+1,ans+1+MAXN,-INF);
	scanf("%d",&N);
	for(int i=1;i<=N;i++)
		scanf("%lld",&T[i]);
	for(int i=1;i<=N;i++)
		sum[i]=sum[i-1]+T[i];
	//处理初始DP
	//处理前缀DP数组 
	DP();
	for(int i=1;i<=N;i++)
		L[i]=f[i];
	//处理后缀DP数组 
	Rev(T);
	for(int i=1;i<=N;i++)
		sum[i]=sum[i-1]+T[i];
	DP();
	for(int i=1;i<=N;i++)
		R[i]=f[N-i+1];
	Rev(T);
	for(int i=1;i<=N;i++)
		sum[i]=sum[i-1]+T[i];
	//处理完成 
	//开始CDQ分治(计算必须选择某个元素的最大值)
	//先从左往右算贡献
	fill(f+1,f+1+N,-INF);
	fill(h+1,h+1+N,-INF);
	fill(g+1,g+1+N,-INF);
	MergeSort(0,N);
	for(int i=1;i<=N;i++)
		ans[i]=max(ans[i],g[i]);
	//再从右往左算贡献 
	Rev(T);
	for(int i=1;i<=N;i++)
		sum[i]=sum[i-1]+T[i];
	for(int i=1;i<=N;i++)
		swap(L[i],R[N-i+1]);
	fill(f+1,f+1+N,-INF);
	fill(h+1,h+1+N,-INF);
	fill(g+1,g+1+N,-INF);
	MergeSort(0,N);
	for(int i=1;i<=N;i++)
		ans[i]=max(ans[i],g[N-i+1]);
	Rev(T);
	for(int i=1;i<=N;i++)
		sum[i]=sum[i-1]+T[i];
	for(int i=1;i<=N;i++)
		swap(L[i],R[N-i+1]);
	//预处理完成 
	//开始回答询问
	int M,P;
	LL X;
	scanf("%d",&M);
	for(int i=1;i<=M;i++)
	{
		scanf("%d %lld",&P,&X);
		LL ansn=max(L[P-1]+R[P+1],ans[P]-X+T[P]);
		printf("%lld\n",ansn);
	}
	return 0;
}
/*
4
3 5 1 6
5
2 1
4 2
3 1
1 1

*/

Measured memory_bytes: 22400
N = int(input())
H = list(map(int, input().split()))
cnt = 0
while max(H) > 0:
    m = max(H)
    mi = H.index(m)

    # right
    for i in range(mi+1, N):
        m = min(m, H[i])
        H[i] = max(0, H[i]-m)

    m = H[mi]
    # left
    for i in range(mi-1, -1, -1):
        m = min(m, H[i])
        H[i] = max(0, H[i]-m)

    cnt += H[mi]
    H[mi] = 0
    # print(H)
print(cnt)


Measured memory_bytes: 39152
import heapq
def naive():
    N = int(input())
    a = list(map(int,input().split()))
    b = list(map(int,input().split()))
    hantei = [1]*N
    for i,(x,y) in enumerate(zip(a,b)):
        if x<y:
            hantei[i] = 0
        if x>y:
            print(-1)
            exit()
    # a == b となるidxの数。これがNでwhileから抜ける
    rest = sum(hantei)
    t = []
    for i,val in enumerate(b):
        heapq.heappush(t, (-val,i))
    res = 0
    while rest < N:
        now = heapq.heappop(t)
        abc = -now[0]
        idx = now[1]
        newval = abc - b[(idx-1)%N] - b[(idx+1)%N]
        b[idx] = newval
        # print(b)
        if a[idx] > newval:
            res = -1
            break
        elif a[idx] == newval:
            hantei[idx] = 0
            rest += 1
        res += 1
        heapq.heappush(t, (-newval,idx))
    print(res)
def naive2():
    N = int(input())
    a = list(map(int,input().split()))
    b = list(map(int,input().split()))
    hantei = [1]*N
    for i,(x,y) in enumerate(zip(a,b)):
        if x<y:
            hantei[i] = 0
        if x>y:
            print(-1)
            exit()
    # a == b となるidxの数。これがNでwhileから抜ける
    rest = sum(hantei)
    t = []
    for i,val in enumerate(b):
        if val==a[i] or val==1:
            continue
        heapq.heappush(t, (-val,i))
    res = 0
    while rest < N:
        now = heapq.heappop(t)
        abc = -now[0]
        idx = now[1]
        left = b[(idx-1)%N]
        right = b[(idx+1)%N]
        step = left+right
        if abc <= step:
            res = -1
            break
        sub_cnt = (abc-1)//step
        if (abc-a[idx])%step==0 and (abc-a[idx])//step < sub_cnt:
            res += (abc-a[idx])//step
            hantei[idx] = 0
            b[idx] = a[idx]
            rest += 1
            continue
        if sub_cnt <= 0:
            res = -1
            break
        diff = sub_cnt*step
        b[idx] -= diff
        # print(b)
        if a[idx] > b[idx]:
            res = -1
            break
        elif a[idx] == b[idx]:
            hantei[idx] = 0
            rest += 1
            res += sub_cnt
            continue
        res += sub_cnt
        heapq.heappush(t, (-b[idx],idx))
    print(res)

naive2()

Measured memory_bytes: 123152
#include <iostream>
#include <set>
#include <iomanip>
#include <math.h>
#include <algorithm>
#include <functional>
#include <stdio.h>
#include <vector>
#include <string>
#include <map>
#define rep(i, n) for (int (i) = 0; (i) < (int)(n); (i)++)
//#define rep(i, n) for(int (i) = 0, TmP = (n); (i) < (int)TmP ; ++(i))
#define asort(v, n) sort((v), (v + n)) //Using array
#define vsort(v) sort((v).begin(), (v).end()) // Using vector
#define vint vector<int>
typedef long long ll;

using namespace std;

signed main(){
  string s;
  cin >> s;
  int l = s.length();

  rep(i, (l - 1) / 2){
    if(s[i] != s[l - i - 1]){
      cout << "No" << endl;
      //cout << s[i] << " " << s[l - i - 1] << endl;
      return 0;
    }
  }

  rep(i, (l - 1) / 4){
    if(s[i] != s[l - i  - 1 - ((l + 1) / 2)]){
      cout << "No" << endl;
      //cout << s[i] << " " << s[l - i - 1 - ((l + 1) / 2)] << endl;
      return 0;
    }
  }

  rep(i, (l - 1) / 4){
    if(s[l - i - 1] != s[i + ((l + 2) / 2)]){
      cout << "No" << endl;
      //cout << s[i + ((l + 2) / 2)] << " " << s[l - i - 1] << endl;
      return 0;
    }
  }

  cout << "Yes" << endl;
}


Measured memory_bytes: 256
class StronglyConnectedComponents():
    def __init__(self, n):
        self.n = n
        self.graph = [[] for _ in range(n)]
        self.rev = [[] for _ in range(n)]

    def add_edge(self, fr, to):
        self.graph[fr].append(to)
        self.rev[to].append(fr)

    def scc_id(self):
        group = [-1] * self.n
        vis = [0] * self.n
        order = []
        for s in range(self.n):
            if vis[s]: continue
            stack = [s]
            vis[s] = True
            while stack:
                node = stack.pop()
                for adj in self.graph[node]:
                    if vis[adj]: continue
                    vis[adj] = True
                    stack.append(node)
                    stack.append(adj)
                    break
                else:
                    order.append(node)
        cnt = 0
        for s in order[::-1]:
            if group[s] != -1: continue
            stack = [s]
            group[s] = cnt
            while stack:
                node = stack.pop()
                for adj in self.rev[node]:
                    if group[adj] != -1: continue
                    group[adj] = cnt
                    stack.append(adj)
            cnt += 1
        return group, cnt

    def scc(self):
        group, cnt = self.scc_id()
        res = [[] for _ in range(cnt)]
        for i in range(self.n):
            res[group[i]].append(i)
        return res

import sys
input = sys.stdin.buffer.readline

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

scc = StronglyConnectedComponents(N)

for _ in range(M):
    a, b = map(int, input().split())
    scc.add_edge(a, b)

res = scc.scc()
print(len(res))

for r in res:
    print(len(r), *r)

Measured memory_bytes: 244224
import java.util.*;
public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
      	String s = sc.next();
     
      	String str[] = new String[3];
          str[0] = s.substring(0,1);
      		str[1] = s.substring(1,2);
      str[2] = s.substring(2,3);
          
      int min = 0;
      int c = 0;
      for(int i=0;i<3;i++){
        if("R".equals(str[i])){
          c++;
        }else{
          if(c>min) {
            min = c;
            c = 0;
          }
        }
      }
        
        if(c> min) min = c;
        System.out.println(min);
      
      }
}



Measured memory_bytes: 35528
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int a[310000];
    int n,m;
    scanf("%d%d",&n,&m);
    if(n&1)
    {
        for(int i=1; i<=m; i++)
        {
            a[i]=(n+1)/2;
        }
        int last=m;
        for(int i=1; i<=m/2; i++)
            if(a[last]==1) last--;
            else
            {
                a[last]--;
                for(int j=last+1; j<=m; j++)
                    a[j]=n;
                last=m;
            }

        for(int i=1; i<=last; i++)
        {
            printf("%d ",a[i]);
        }
        //printf("%d\n",a[m]);
    }
    else
    {
        printf("%d ",n/2);
        for(int i=2; i<=m; i++)
        {
            printf("%d ",n);
        }
        //printf("%d\n",n);
    }
    return 0;
}


Measured memory_bytes: 3456
#include <bits/stdc++.h>
using namespace std;
#define FOR(i, begin, end) for(ll i=(begin);i<(end);i++)
#define REP(i, n) FOR(i,0,n)
#define IFOR(i, begin, end) for(ll i=(begin)-1;i>=(end);i--)
#define IREP(i, n) IFOR(i,n,0)
#define SORT(a) sort(a.begin(), a.end())
#define ISORT(a) sort(a.begin(), a.end(),greater<ll>())
#define REVERSE(a) reverse(a.begin(), a.end())
#define debug(x) cout << #x << "=" << x << endl;
#define vdebug(v) cout << #v << "=(" << v[0]; FOR(i_debug, 1, v.size()){ cout << "," << v[i_debug]; } cout << ")" << endl;
#define mdebug(m) cout << #m << "=" << endl; REP(i_debug, m.size()){ REP(j_debug, m[i_debug].size()){ cout << m[i_debug][j_debug] << ","; } cout << endl;}
#define Lower_bound(v, x) distance(v.begin(), lower_bound(v.begin(), v.end(), x))
#define Upper_bound(v, x) distance(v.begin(), upper_bound(v.begin(), v.end(), x))
#define Max(a, b) a = max(a, b)
#define Min(a, b) a = min(a, b)

#define ll long long
#define f first
#define s second
#define mp make_pair
#define pb push_back
#define INF 1000000000000000000

using vec = vector<ll>;
using mat = vector<vec>;
using Pii = pair<ll, ll>;
using PiP = pair<ll, Pii>;
using PPi = pair<Pii, ll>;
using bvec = vector<bool>;
using Pvec = vector<Pii>;


template<typename T> void readv(vector<T> &a) { REP(i, a.size()) cin >> a[i]; }
void readv_m1(vector<int> &a) { REP(i, a.size()) {cin >> a[i]; a[i]--;} }

ll mod = 1000000007;

int main()
{
	ll N;
	cin >> N;
	vec A(N);
	REP(i, N) {
		cin >> A[i];
	}

	double ans = 1;
	double denom = 0;
	REP(i, N) {
		ans *= A[i];
	}
	
	REP(i, N) {
		denom += ans/A[i];
	}

	ans /= denom;

	cout << ans << endl;


	return 0;
}

Measured memory_bytes: 256
#include<algorithm>
#include<climits>
#include<cmath>
#include<iomanip>
#include<iostream>
#include<list>
#include<map>
#include<numeric>
#include<queue>
#include<set>
#include<stack>
#include<utility>
#include<vector>

#define lint long long
#define REP(i, x, n) for(int i = x ; i < n ; i++)
#define rep(i, n) REP(i, 0, n)
#define repr(i, n) for(int i = n - 1 ; i >= 0 ; i--)
#define SORT(c) sort((c).begin(), (c).end())
#define SORT_INV(c) sort((c).begin(), (c).end(), greater<int>())
#define IINF (int)(1e9+10)
#define LLINF (lint)(1e18+10)

using namespace std;

int main(){
    int n, a, b;
    cin >> n >> a >> b;
    vector<lint> v(n);
    rep(i, n){
        cin >> v[i];
    }
    sort(v.begin(), v.end(), greater<lint>());
    double ave = 0;
    rep(i, a){
        ave += v[i];
    }
    ave = ave / (double)(a);
    int cnt1 = 0, cnt2 = 0;
    rep(i, n){
        if(v[i] == v[a-1]){
            cnt1++;
        }
        if(v[i] > v[a-1]){
            cnt2++;
        }
    }
    lint comb[55][55] = {{0}};
    for(lint i = 0 ; i <= 50 ; i++){
        for(lint j = 0 ; j <= i ; j++){
            if(j == 0){
                comb[i][j] = 1;
            }else{
                comb[i][j] = comb[i-1][j-1] + comb[i-1][j];
            }
        }
    }
    lint cnt = 0;
    if(cnt2 == 0){
        for(int i = a ; i <= min(cnt1, b) ; i++){
            cnt += comb[cnt1][i];
        }
    }else{
        cnt = comb[cnt1][a-cnt2];
    }
    cout << fixed << setprecision(8) << ave << endl << cnt << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using  namespace std;
int main()
{
    int a;
    cin>>a;
    string s;
    cin>>s;
    set<int>se;
    int cnt=0;
    for(int i=0;i<a;i++)
    {
        if(s[i]!=s[i+1])
            cnt++;
    }
    cout<<cnt<<endl;

}

Measured memory_bytes: 512
A, B = map(int, input().split())
S = input()
Slist = list(map(ord, S))
del (Slist[A])

if S[A] == '-':
    if max(Slist) <= 57 and min(Slist) >= 48:
        print('Yes')
    else:
        print('No')
else:
    print('No')


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

int main() {
    
    cin.tie(NULL), cout.tie(NULL);
    
    string S;
    cin >> S;
    
    if(S == "zyxwvutsrqponmlkjihgfedcba")
    {
        cout << -1 << "\n";
        return 0;
    }
    
    if(S.size() < 26)
    {
        for(int j=0; j<26; j++)
        {
            int flag = 0;
            
            for(int k=0; k<S.size(); k++)
                flag |= (S[k] - 'a' == j);
            
            if(flag == 0)
            {
                S.push_back((char)('a' + j));
                
                cout << S << "\n";
                return 0;
            }
        }
    }
    
    int mask = (1<<26) - 1;
    
    for(int j=25; j>=0; j--)
    {
        int done = 0;
        int x = S[j] - 'a' + 1;
        
        for(int k=x; k<26; k++)
        {
            if(((1<<k) & mask) == 0)
            {
                S[j] = (char) (k + 'a');
                done = 1;
                break;
            }
        }
        
        if(done)
            break;
        
        if(x > 25 || (mask & (1<<x)))
            S[j] = '*';
        else
        {
            S[j] = (char) (x + 'a');
            break;
        }
        
        mask -= (1<<(x-1));
    }
    
    for(int j=0; S[j] != '*'; j++)
        cout << S[j];
    cout << "\n";
    
    return 0;
}


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

int main(){
  int n,k;
  string s;
  cin >> n >> k >> s;
  if(s[k-1] == 'A') s[k-1] = 'a';
  if(s[k-1] == 'B') s[k-1] = 'b';
  if(s[k-1] == 'C') s[k-1] = 'c';
  cout << s << endl;
  return 0;
}


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


int dp[100];

//最大公約数
ll gcd(ll x, ll y){
  if(x % y == 0) return y;
  return gcd(y, x % y);
}
//最小公倍数
ll lcm(ll x, ll y){
  return x * y / gcd(x, y);
}
//フィボナッチ数列
//配列dpを-1で初期化する
int fib(int n){
  if(n == 0 || n == 1) return dp[n] = 1;
  if(dp[n] != -1) return dp[n];
  return dp[n] = fib(n - 1) + fib(n - 2);
}
//階乗計算(factorial)
int fact(int n){
  if(n = 1) return 1;
  return n * fact(n - 1);
}
//累乗計算(Exponentiation)
//x**y
ll expo(int x, int y){
  ll ans = 1;
  rep(i, y){
    ans *= x;
  }
  return ans;
}
//桁数
int keta(ll x){
  if(x == 0) return 1;
  int res = 0;
  while(x){
    x /= 10;
    res++;
  }
  return res;
}


int main(){
  int n, x;
  cin >> n >> x;
  vector<int> l(n);
  rep(i, n) cin >> l[i];

  int d = 0;
  int cnt = 1;
  while(d + l[cnt-1] <= x && cnt <= n){
    d += l[cnt-1];
    cnt++;
  }
  cout << cnt << endl;
}


/*





















*/


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

public class Main {
	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		String s = scan.next();
		int a = 0;
		char[] c = new char[s.length()];
		for (int i = 0; i < s.length(); i++) {
			c[i] = s.charAt(i);
		}
		/*char文字を数値に変換してのバゲット法*/
		int num = 0;
		Arrays.sort(c);//ソート
		char A = 'a';//aの文字コード受け取り
		a = A;
		int[] buget = new int[26];
		for (int i = 0; i < s.length(); i++) {//文字を数値に変換してバゲット法
			buget[c[i]-a]++;//多分ここで各文字からaのコードが引かれて0~25の数になる
		}
		for (int i = 0; i < 26; i++) {//バゲットの中身を確認
			if (buget[i] == 0) {
				char ans = (char)(i+a);
				System.out.println(ans);
              	return;
			}
		}
		System.out.println("None");
	}
}


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


int main(){
    int A,B,C;
    int ABC[3];
    for(int i = 0; i < 3; i++) cin >> ABC[i];
    // int num = extent<decltype(ABC), 0>::value;
    sort(ABC,ABC+3, greater<int>());
    // cout << ABC[0] << endl;
    int max = ABC[0];
    int min = ABC[2];
    int middle = ABC[1];
    int numOfOp1 = max - middle;
    // cout << "max is " << max << " and min is " << min << " and middle is " << middle << endl;
    if((middle - min) % 2 == 0){
        // cout << "differ is multiple of 2" << endl;
        cout << (numOfOp1) + ((max - (min + numOfOp1)) / 2);
    }else {
        cout << (numOfOp1) + ((max - (min + numOfOp1)) / 2) + 2;
    }

}




Measured memory_bytes: 256
#include <iostream>
#include<cstring>
using namespace std;
int use[9];

int c[9][9];
int way(int start,int k,int n)
{

    if(k==1){return 1;}
    use[start]=1;

    int ans=0;
  /*      int t[9][9];
        memset(t,0,sizeof(t));
        if(connect[start][j]){
            memcpy(t,connect,(n+1)*(n+1));
            for(int k=1;k<n;k++){
                t[1][k]=t[n][k];
                t[k][1]=t[k][n];
            }
        }*/
    for(int j=1;j<=n;j++){
        if(use[j]==0&&c[start][j])
        {
            //cout<<start<<"->";
            ans+=way(j,k-1,n);

        }
       //else cout<<"end"<<endl;
       // else cout<<"c["<<start<<"]["<<j<<"]="<<c[start][j]<<endl;
    }
    use[start]=0;
    return ans;
}
int main()
{
   int m,n;
    memset(c,0,sizeof(c));
    memset(use,0,sizeof(use));
    cin>>n>>m;
    int a,b;
    while(m--){
        cin>>a>>b;
        c[a][b]=c[b][a]=1;
    }

    cout<<way(1,n,n);

    return 0;
}


Measured memory_bytes: 256
#include <map>
#include <set>
#include <list>
#include <cmath>
#include <queue>
#include <stack>
#include <cstdio>
#include <string>
#include <vector>
#include <complex>
#include <cstdlib>
#include <cstring>
#include <numeric>
#include <sstream>
#include <iostream>
#include <algorithm>
#include <functional>
  
#define mp       make_pair
#define pb       push_back
#define all(x)   (x).begin(),(x).end()
#define rep(i,n) for(int i=0;i<(n);i++)
  
using namespace std;
  
typedef    long long          ll;
typedef    unsigned long long ull;
typedef    vector<bool>       vb;
typedef    vector<int>        vi;
typedef    vector<vb>         vvb;
typedef    vector<vi>         vvi;
typedef    pair<int,int>      pii;
  
const int INF=1<<29;
const double EPS=1e-9;
  
const int dx[]={1,0,-1,0,1,1,-1,-1},dy[]={0,-1,0,1,1,-1,-1,1};

bool ok(std::vector<vector<int> > &map, int x, int y) {
    int H = map.size();
    int W = map[0].size();
    if (x < 0 || x >= W || y < 0 || y >= H) return false;
    return true;
}

void color(std::vector<vector<int> > &map, int i, int j) {
    if (map[i][j] == -1) return;
    map[i][j] = -1;

    for (int k = 0; k < 8; k++) {
        int px = j + dx[k];
        int py = i + dy[k];
        if (!ok(map, px, py)) continue;
        if (map[py][px] == 0) continue;
        if (map[py][px] == 1) {
            color(map, py, px);
        }
    }
}

int main(int argc, char const *argv[]) {
    int W, H;
    while(cin >> W >> H) {
        if (W == 0 && H == 0) break;
        std::vector<vector<int> > map(H, vector<int>(W, 0));
        for (int i = 0; i < H; i++) {
            for (int j = 0; j < W; j++) {
                cin >> map[i][j];
            }
        }
        int count = 0;
        for (int i = 0; i < H; i++) {
            for (int j = 0; j < W; j++) {
                if (map[i][j] == 1) {
                    count++;
                    color(map, i, j);
                }
            }
        }
        cout << count << endl;
    }
    return 0;
}

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

using namespace std;

const int Nmax = 1e5+5;
vector<int> v[Nmax];
int n, A[Nmax], i, x, y;
bool used[Nmax];

int dfs(int node)
{
    used[node] = 1;
    if(v[node].size()==1) return A[node];

    int edge = A[node] << 1, nr;

    for(auto it : v[node])
        if(!used[it])
        {
            nr = dfs(it);
            edge -= nr;
            if(nr>A[node] || nr==-1 || edge<0) return -1;
        }

    if(edge>A[node]) return -1;
    return edge;
}

int main()
{
    // freopen("input", "r", stdin);
  //  freopen("output", "w", stdout);

    scanf("%d", &n);
    for(i=1; i<=n; ++i) scanf("%d", &A[i]);

    if(n==2)
    {
        printf("%s\n", A[1]==A[2] ? "YES" : "NO");
        return 0;
    }

    for(i=1; i<n; ++i)
    {
        scanf("%d%d", &x, &y);
        v[x].push_back(y);
        v[y].push_back(x);
    }

    for(i=1; i<=n; ++i)
        if(v[i].size()>=2)
        {
            printf("%s\n", dfs(i) ? "NO" : "YES");
            return 0;
        }

    return 0;
}


Measured memory_bytes: 10240
class comb():
  F = [1, 1]
  Fi = [1, 1]
  I = [0, 1]
  def __init__(self, num, mod):
    self.MOD = mod
    for i in range(2, num + 1):
      self.F.append((self.F[-1] * i) % mod)
      self.I.append(mod - self.I[mod % i] * (mod // i) % mod)
      self.Fi.append(self.Fi[-1] * self.I[i] % mod)
  def com(self, n, k):
    if n < k: return 0
    if n < 0 or k < 0: return 0
    return self.F[n] * (self.Fi[k] * self.Fi[n - k] % self.MOD) % self.MOD

def nasu(k, b):
  if k < b:
    return 0
  m = k - b
  return com.com((m + b - 1), m)

N, K = list(map(int, input().split()))
MOD = 10 ** 9 + 7

V = [0, 0, 0]
com = comb(N, MOD)
 
if K == N:
  V[0] = 1
V[1] = nasu(N - K, 1)
V[2] = nasu(N - K, 2)

for i in range(1, K + 1):
  t = com.com(K - 1, i - 1) 
  ans = t * (V[0] + V[2]) % MOD
  ans = (ans + t * V[1] * 2) % MOD
  print(ans)
  V[0] = V[1]
  V[1] = V[2]
  V[2] = nasu(N - K, i + 2)


Measured memory_bytes: 3572