akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
#define fr first
#define sc second
#define pb push_back
#define ll long long
#define maxheap priority_queue<int>
#define minheap priority_queue<int,vector<int>,greater<int>>
const double pi = acos(-1.0);
const double eps = 1e-6;
using namespace std;

const int N = 3e5 + 1;
int R, C;
int n;
vector <pair <int, ll> > g[2 * N];
bool used[2 * N];
ll mn1, mn2;
ll a[N];

bool dfs(int v){
    used[v] = true;
    if (v <= R) mn1 = min(mn1, a[v]);
    else mn2 = min(mn2, a[v]);
    
    for (auto to : g[v]){
        
        if (used[to.fr]){

            if (a[to.fr] + a[v] != to.sc){
                 return false;
            }
        }
        else{
            a[to.fr] = to.sc - a[v];
            if (!dfs(to.fr)) return false;    
        }
    }
    return true;
}

void solve(){   
    cin >> R >> C;
    cin >> n;
    
    for (int i = 1; i <= n; i++){
        int x, y;
        ll c;
        cin >> x >> y >> c;
        g[x].pb({R + y, c});
        g[R + y].pb({x, c});
    }
    
    for (int i = 1; i <= R + C; i++){
        if (used[i]) continue;
        mn1 = 1e17, mn2 = 1e17;
        
        if (!dfs(i) || mn1 + mn2 < 0){
            cout << "No" << endl;
            return;
        }
    }
    cout << "Yes" << endl;
    



}       
int main(){
    ios::sync_with_stdio(NULL), cin.tie(0), cout.tie(0);
    cout.setf(ios::fixed), cout.precision(5);
    //freopen("input.txt", "r", stdin);//freopen("output1.txt", "w", stdout);
    //freopen("icecream.in","r",stdin);// freopen("exam.out", "w", stdout);
    int step;
    step = 1;
    //cin >> step;
    for (int i = 1; i <= step; i++){
         solve();
    }
}

Measured memory_bytes: 29348
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <functional>
#include <numeric>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <utility>
#include <sstream>
#include <complex>
#include <fstream>

using namespace std;

#define FOR(i,a,b) for(long long i=(a);i<(b);i++)
#define REP(i,N) for(long long i=0;i<(N);i++)
#define ALL(s) (s).begin(),(s).end()
#define fi first
#define se second

#define PI acos(-1.0)
#define INF 10e15+9
#define EPS 1e-10
#define MAX_N 100100
#define MAX_M 100100

typedef long long ll;
typedef pair<ll, ll> P;
typedef pair<double, double> PD;
typedef pair<string, ll> PS;
typedef vector<ll> V;
typedef pair<P, char> PC;

int n, x = 0;
P muki[] = { P(1, 0), P(-1, 1), P(0, 1), P(1, -1) };

int main(){
	while (cin >> n&&n){
		int field[100][100];
		REP(i, 100)REP(j, 100)field[i][j] = 0;
		P pos = P(0, 0);
		bool f = 1;
		int cnt = 0, mode = 0;
		while (1){
			cnt++;
			field[pos.second][pos.first] = cnt;
			if (pos.first == n - 1 && pos.second == n - 1)break;

			pos.first += muki[mode].first;
			pos.second += muki[mode].second;
			if (mode == 0){
				if(f) mode++;
				else mode = 3;
			}
			else if (mode == 1){
				if (f&&pos.first == 0){
					if (pos.second == n - 1)f = 0;
					if(f)mode++;
					else mode--;
				}
				else if (!f&&pos.second == n - 1){
					mode--;
				}
			}
			else if (mode == 2){
				if(f) mode++;
				else mode--;
			}
			else{
				if (f&&pos.second == 0){
					if (pos.first == n - 1)f = 0;
					if(f) mode = 0;
					else mode--;
				}
				else if (!f&&pos.first == n - 1){
					mode--;
				}
			}
		}
		x++;
		cout << "Case " << x << ":" << endl;
		REP(i, n){
			REP(j, n){
				printf("%3d", field[i][j]);
			}
			cout << endl;
		}
	}
}

Measured memory_bytes: 1240
#include <stdio.h>

int main(){
	int N,X;
	scanf("%d%d",&N,&X);
	int i,input,sum=0,min=1001;
	for(i=0;i<N;i++){
		scanf("%d",&input);
		sum+=input;
		if(input<min){
			min=input;
		}	
	}
	int output=N+(X-sum)/min; 
	printf("%d",output);
	
	return 0;
} 

Measured memory_bytes: 128
#include <bits/stdc++.h>
 
using namespace std;
typedef unsigned long long ull;
typedef long long ll;
typedef pair<ll, ll> pii;
 
#define REP(a,b,c) for(ll (a)=(b);(a)<(c);(a)++)
#define PER(a,b,c) for(ll (a)=(b);(a)>=(c);(a)--)
 
void in(ll &x){ cin >> x; }
void pin(ll &x, ll &y){ cin >> x, y; }


int main(){
    ll N,M,K,a,b,p,q,x,y,z;
    string s;
    cin >> s;
    if(s=="AAA" || s=="BBB"){
        cout << "No" << endl;
        return 0;
    }
    cout << "Yes" << endl;
    return 0;
}

Measured memory_bytes: 256
#![allow(unused_imports)]
#![allow(unused_variables)]
#![allow(non_snake_case)]
#![allow(dead_code)]
#![allow(deprecated)]

use std::cell::{Cell, Ref, RefCell, RefMut};
use std::cmp::{max, min, Ordering};
use std::collections::*;
use std::fmt::{Debug, Formatter, Write as FmtWrite};
use std::io::{stderr, stdin, BufRead, Write};
use std::mem::{replace, swap};
use std::ops::*;
use std::rc::Rc;
use std::usize;

const MOD_10_9_7: u64 = 1_000_000_007;
const INF: i64 = 1_000_000_000_000;
const MIN_INF: i64 = -1_000_000_000_000;

/// FYI: https://github.com/vain0x/scan-bench
#[allow(unused_macros)]
macro_rules! read {
    ([$t:ty] ; $n:expr) =>
        ((0..$n).map(|_| read!([$t])).collect::<Vec<_>>());
    ($($t:ty),+ ; $n:expr) =>
        ((0..$n).map(|_| read!($($t),+)).collect::<Vec<_>>());
    ([$t:ty]) =>
        (rl().split_whitespace().map(|w| w.parse().unwrap()).collect::<Vec<$t>>());
    ($t:ty) =>
        (rl().parse::<$t>().unwrap());
    ($($t:ty),*) => {{
        let buf = rl();
        let mut w = buf.split_whitespace();
        ($(w.next().unwrap().parse::<$t>().unwrap()),*)
    }};
}

fn rl() -> String {
    let mut buf = String::new();
    stdin().read_line(&mut buf).unwrap();
    buf.trim_right().to_owned()
}

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

fn a() {
    let (n, a, b) = read!(usize, usize, usize);
    println!("{}", min(n * a, b));
}

fn b() {
    let s: String = read!(String);

    let n: i32 = s.parse().unwrap();
    let mut f = 0;
    for c in s.chars() {
        let d = c as i32 - 48;
        f += d;
    }

    println!("{}", if n % f == 0 { "Yes" } else { "No" });
}

fn main() {
    //    a();
    b();
}


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

#define irep(i,n) for(int i = 0; i < (int)(n); i++)
#define irep2(i,a,n) for(int i = (int)(a); i <= (int)(n); i++)
#define lrep(i,n) for(long long  i = 0; i < (long long)(n); i++)
#define lrep2(i,a,n) for(long long i = (long long)(a); i <= (long long)(n); i++)
#define irrep(i,n) for(int i = (int)(n-1); i > -1; i--)
#define irrep2(i,a,n) for(int i = (int)(n); i >= (int)(a); i--)

typedef long long ll;
typedef std::vector<int> v_int;
typedef std::vector<v_int > v2_int;
typedef std::vector<ll> v_ll;
typedef std::vector<v_ll > v2_ll;
typedef std::vector<std::string> v_string;
typedef std::vector<v_string > v2_string;
typedef std::vector<bool> v_bool;
typedef std::vector<v_bool > v2_bool;
typedef std::pair<ll, ll> pll;
typedef std::pair<int, int> pii;

const double PI = 3.1415926535897932;
const int INF = (int)1e9;
const ll LINF = 1e18;
const ll MOD = 998244353;
const int dr[4] = {1, 0, -1, 0};
const int dc[4] = {0, 1, 0, -1};

using namespace std; 

template<typename T, typename U> inline
ostream& operator<<(ostream &o, pair<T,U> &p)
{
    return o << "{" << p.first << "," << p.second << "}";
}

template<typename T> inline
ostream& operator<<(ostream &os, vector<T> &v)
{
    int len = v.size();
    for(int i = 0; i < len; i++) { 
        os << v[i];
        if(i != len-1) { os << ","; } 
    } 
    return os;
}

int main(void)
{
    int n;
    cin >> n;
    
    vector<pll> a(n);
    irep(i, n) {
        ll x, l;
        cin >> x >> l;
        a[i] = make_pair(x+l, x-l);
    }

    sort(a.begin(), a.end());
    
    int ans = 0;
    ll prev = -2 * LINF;

    irep(i, n) {
        if(prev > a[i].second) {
            continue; 
        }
        ans++;
        prev = a[i].first;
    }
    cout << ans << endl;
    return 0;
}

/*atcoder*/


Measured memory_bytes: 1792
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;

int main() {
  ll n;
  cin >> n;
  vector<string> s(n);
  for (int i = 0; i < n; i++)
    cin >> s[i];

  map<char, int> m;
  for (int i = 0; i < n; i++) {
    map<char, int> t;
    for (int j = 0; j < s[i].size(); j++) {
      if (i == 0 || m[s[i][j]] > 0) t[s[i][j]]++;
    }

    if (i == 0) {
      m = t;
      continue;
    }
    for (auto v : m) {
      if (t[v.first] == 0) {
        m.erase(v.first);
        continue;
      }
      if (v.second > t[v.first]) { m[v.first] = t[v.first]; }
    }
  }
  string ans = "";
  for (auto v : m) {
    for (int i = 0; i < v.second; i++)
      ans += v.first;
  }
  sort(ans.begin(), ans.end());
  cout << ans << endl;
}

Measured memory_bytes: 256
#include"bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef vector<int> vi;

void swap(int a, int b) {
	int tmp = a;
	a = b;
	b = tmp;
}

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

	int a[105];
	int ans = 0;

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


	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 3632
n,l = map(int,input().split())
aji = [0]*n
for i in range(n):
  aji[i] = l+i
if aji[n-1]<0:
  print(sum(aji[0:n-1]))
elif aji[n-1]>=0 and aji[0]<=0:
  print(sum(aji))
else:
  print(sum(aji[1:n]))  


Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
const int MAX = 200000;

int main() {
    int n, num = 0;
    cin >> n;
    int l, r;

    for(int i=0; i<n; i++) {
        cin >> l >> r;
        num += r - l + 1;
    }
    cout << num << endl;
}

Measured memory_bytes: 3536
#include <bits/stdc++.h>
 
#define rep(i,n) for(ll i=0;i<n;++i)
#define all_map(pos,mp) for(ll pos=mp.begin();pos!=mp.end();pos -++)
#define ALL(a) (a).begin(),(a).end()

using namespace std;
using ll  = long long;
using pll = pair<ll, ll>;

const ll MOD  = 1e9 + 7;
const ll LINF = 1LL << 62;
const int INF = 1e9 + 7;

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

    vector<ll> a(n);
    rep(i, n)cin >> a[i];

    vector<ll> ctop(1, -1);
    for(ll ai : a){
        if(ai <= ctop.front()){
            ctop.insert(ctop.begin(), ai);
        }
        else {
            ll pos = lower_bound(ALL(ctop), ai) - ctop.begin() - 1;

            ctop[pos] = ai;
        }
    }

    cout << ctop.size() << endl;   
}

Measured memory_bytes: 4996
n=int(raw_input())
a=[]
b=[]
for i in xrange(n):
    A,B=map(int,raw_input().split())
    a.append(A)
    b.append(B)
ans=0
for i in xrange(n-1,-1,-1):
    if (a[i]+ans)%b[i]!=0:
        ans+=b[i]-(a[i]+ans)%b[i]
print ans

Measured memory_bytes: 9012
#include<cstdio>
#include<cmath>
#include<algorithm>
using namespace std;
int main()
{
	int a,b,c,d;
	while(~scanf("%d%d%d%d",&a,&b,&c,&d))
	{
		long long x,y;
		x = a*b;
		y = c*d;
		printf("%lld\n",max(x,y));
	}
return 0;
}

Measured memory_bytes: 128
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
#include<bits/stdc++.h>
#define speedX ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL)
using namespace std;
#define ONLINE_JUDGE
#ifndef ONLINE_JUDGE
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
	cout<< name << " : " << arg1 << endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
	const char* comma = strchr(names + 1, ',');cout.write(names, comma - names) << " : " << arg1<<" | ";__f(comma+1, args...);
}
int begtime = clock();
#define end_time() cout << "\n\nTime of execution: " << (clock() - begtime)*1000/CLOCKS_PER_SEC << " ms\n\n";
#else
#define trace(...)
#define end_time()
#endif


#define int long long 
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<pii, int> piii;
typedef vector<int> vi;
typedef vector<pii> vii;
inline bool equals(ld a, ld b) {return fabs(a - b) < 1e-9;}
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define ff first
#define ss second
#define uset unordered_set
#define umap unordered_map
#define all(x) x.begin(), x.end()
#define mod 1000000007


void solve(){
	int n;
	cin>>n;
	vector<int> v;
	set<int> s;
	for(int i = 0; i<n; i++){
		int a;
		cin>>a;
		v.pb(a);
		s.insert(a);
	}
	if(v.size()==s.size()) cout<<"YES\n";
	else cout<<"NO\n";
}
signed main(){
	speedX;
	#ifndef ONLINE_JUDGE
        freopen("input.txt", "r", stdin);
        freopen("output.txt", "w", stdout);
    #endif
	int t=1;
	//cin>>t;
	while(t--){
		solve();
	}
	end_time();
	return 0;
}

Measured memory_bytes: 11248
#include<iostream>
#include<cstdio>
#include<algorithm>
using namespace std;
const int N=100005;
int A,B,n;
int a[N],b[N];
int x[N],y[N],c[N];
int main()
{
	scanf("%d%d%d",&A,&B,&n);
	for(int i=1;i<=A;i++)
		scanf("%d",&a[i]);
	for(int i=1;i<=B;i++)
		scanf("%d",&b[i]);
	int ans=(*min_element(a+1,a+A+1))+(*min_element(b+1,b+B+1));
	for(int i=1;i<=n;i++)
	{
		scanf("%d%d%d",&x[i],&y[i],&c[i]);
		ans=min(ans,a[x[i]]+b[y[i]]-c[i]);
	}
	printf("%d",ans);
	return 0;
}

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

typedef long long ll;
typedef long double ld;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef pair<ld,ld> pdd;
typedef vector<ll> vll;
typedef vector<ld> vld;
typedef vector<pll> vpl;
typedef vector<vll> vvll;

#define ALL(a) a.begin(),a.end()
#define SZ(a) ((int)a.size())
#define FI first
#define SE second
#define REP(i,n) for(int i=0;i<((int)n);i++)
#define REP1(i,n) for(int i=1;i<((int)n);i++)
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define PB push_back
#define EB emplace_back
#define MP(a,b) make_pair(a,b)
#define SORT_UNIQUE(c) (sort(c.begin(),c.end()), c.resize(distance(c.begin(),unique(c.begin(),c.end()))))
#define GET_POS(c,x) (lower_bound(c.begin(),c.end(),x)-c.begin())
#define yes cout<<"Yes"<<endl
#define YES cout<<"YES"<<endl
#define no cout<<"No"<<endl
#define NO cout<<"NO"<<endl
#define Decimal fixed<<setprecision(20)
#define INF 1000000000
#define LLINF 1000000000000000000LL

const int inf = 1e9;
const ll linf = 1LL << 50;
const double eps = 1e-10;
const int MOD = 998244353;
const int dx[4] = {-1, 0, 1, 0};
const int dy[4] = {0, -1, 0, 1};


ll mpow(ll m, ll p){
  ll power = m;
  ll res = 1;
  while(p>0){
    if(p&1)
      res = res*power%MOD;
    power = (power*power)%MOD;
    p /= 2;
  }

  return res;
}

ll mod_inv(ll m){
  return mpow(m, MOD-2);
}

struct COM{
  vll fact, fact_inv;
  COM(ll n): fact(n+1,1), fact_inv(n+1,1){
    for(ll i=1; i<=n; i++)
      fact[i] = fact[i-1]*i%MOD;

    fact_inv[n] = mod_inv(fact[n]);
    for(ll i=n; i>=1; i--)
      fact_inv[i-1] = fact_inv[i]*i%MOD;
  }

  ll calc(ll n, ll k){
    if(k<0 || n<k)
      return 0;
    ll res = fact[n]*fact_inv[n-k]%MOD*fact_inv[k]%MOD;
    return res;
  }
};


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

  ll n,a,b,k;
  cin>>n>>a>>b>>k;

  COM com(n);
  ll ans=0;
  for(ll i=0; i<=n; i++){
    if((k-a*i)%b==0)
      ans=(ans+com.calc(n,i)*com.calc(n,(k-a*i)/b)%MOD)%MOD;
  }

  cout<<ans<<endl;


}



Measured memory_bytes: 7928
import java.util.Scanner;

public class Main 
{
	static Scanner scan = new Scanner(System.in);

	public static void main(String[] args) 
	{
		while(true)
		{
			int n = scan.nextInt();
			if(n != 0)
			{
				new DataSet(n);
			}
			else
			{
				return;
			}
		}
	}
	
	public static class DataSet
	{
		int no; //number of votes
		int[] vote = new int[26]; //Mr. A = 0, ... Mr. B = 1, ... //vote[0] = vote on A
		int ans;
		int firstPlaceVotes = 0;
		int firstPlaceHolder = -1;
		int secondPlaceVotes = 0;
		int secondPlaceHolder = -1;
		boolean answered = false;
		
		public DataSet(int n)
		{
			this.no = n;
			
			for(int i = 0; i < no; i++)
			{
				String svote = scan.next();
				int wildVotes = no - (i+1); //votes we don't know yet
				int cand = svote.charAt(0)-65;
				
				vote[cand] += 1;
				
//				if(cand != firstPlaceHolder)
				{
					if(vote[cand] > firstPlaceVotes)
					{
						//current first becomes second place if they're different
						if(firstPlaceHolder != cand)
						{
							secondPlaceHolder = firstPlaceHolder;
							secondPlaceVotes = firstPlaceVotes;
						}
						
						//guy becomes first place
						firstPlaceVotes = vote[cand];
						firstPlaceHolder = cand;
					}
					else if(vote[cand] > secondPlaceVotes && cand != firstPlaceHolder)
					{
						//update current second
//						if(cand == firstPlaceVotes) {System.out.println("WUT");}
						secondPlaceHolder = cand;
						secondPlaceVotes = vote[cand];
					}
				}
				
				if(secondPlaceHolder>=0)secondPlaceVotes = vote[secondPlaceHolder];
				
//				System.out.println("first place " + firstPlaceHolder + ", " + firstPlaceVotes);
//				System.out.println("2nd place " + secondPlaceHolder + ", " + secondPlaceVotes);
//				System.out.println(wildVotes + " wild votes");
				
				if(firstPlaceVotes > secondPlaceVotes + wildVotes && answered == false)
				{
//					System.out.println("first place " + firstPlaceVotes);
//					System.out.println("2nd place " + secondPlaceVotes);
					//done
					int code = (firstPlaceHolder+65);
					char candChar = (char)code;
					System.out.println(candChar + " " + (i+1));
					
					answered = true;
				}
			}
			
			if(firstPlaceVotes == secondPlaceVotes)
			{
				//tie
				System.out.println("TIE");
				return;
			}
			else
			{
			}
		}
	}

}



Measured memory_bytes: 46164
#include<iostream>

using namespace std;
int main()
{
	string s;
	cin >> s;
	int tmp[26] = {0};
	for(int i=0; i<s.size(); i++){
		tmp[s[i] - 'a']++;
	}
	for(int i=0; i<26; i++){
		if(tmp[i] > 1){
			cout << "no" << endl;
			return 0;
		}
	}
	cout << "yes" << endl;
	
	return 0;
}


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

typedef long long ll;

int main()
{
    int n,i,m;
    cin >> n >> m;
    priority_queue<int> a;
    int b;
    for(i = 0;i < n;++i){
        cin >> b;
        a.push(b);
    }

    for(i = 0;i < m;++i){
        b = a.top();
        a.pop();
        b /= 2;
        a.push(b);
    }
    ll ans = 0;
    while(!a.empty()){
        b = a.top();
        a.pop();
        ans += b;
    }

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

Measured memory_bytes: 892
import java.util.*;
import java.io.*;
import java.lang.*;

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

        String a = sc.next();

        if (a.contains("AB") || a.contains("BA"))
            System.out.println("Yes");
        else
            System.out.println("No");
    }
}


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

#define ll long long
#define fornum(A,B,C) for(A=B;A<C;++A)
#define pii pair<int,int>
#define pll pair<ll,ll>

using namespace std;

/////////////////////////////////////////////////////
ll N, K;
ll A[202020];
ll pli;

ll i, j, k;

bool bs(ll a){
    ll i, j, k = 0;
    if(a>=0){
        k = pli * (N - pli);
        i = 0, j = 0;
        for (i = pli - 1; i > 0;--i)
        {
            while(j<i&&A[i]*A[j]>a){
                ++j;
            }
            if(j==i)
                break;
            k += i - j;
        }

        j = N - 1;
        fornum(i,pli,N){
            while(j>i&&A[i]*A[j]>a){
                --j;
            }
            if(j==i)
                break;
            k += j - i;
        }
    }else{
        k = 0;
        j = pli;
        fornum(i,0,pli){
            while(j<N&&A[i]*A[j]>a){
                ++j;
            }
            k += N - j;
        }
    }
    //printf("%lld %lld\n", a, k);
    return k >= K;
}
int main(){
    scanf("%lld%lld", &N, &K);
    fornum(i,0,N){
        scanf("%lld", &A[i]);
    }
    sort(A, A + N);
    fornum(pli,0,N){
        if(A[pli]>=0){
            break;
        }
    }

    ll l = 0, r = 2e18;
    while(l<r){
        //printf("%lld,%lld:", l-(ll)1e18, r-(ll)1e18);
        ll c = (l + r) / 2;
        if(bs(c-(ll)1e18)){
            r = c;
        }else{
            l = c + 1;
        }
    }
    l -= (ll)1e18;
    printf("%lld", l);
    return 0;
}

Measured memory_bytes: 1792
import sys
def input():
    return sys.stdin.readline()[:-1]
N = int(input())
S = list(input())
s = len(S)
for i in range(s):
    k = ord(S[i])-64 + N
    if k>26:
        k -= 26
    S[i] = chr(k+64)
print(''.join(S))

Measured memory_bytes: 3316
N = int(input())
d_array = list(map(int, input().split()))
#小さい順に並べ替え
list.sort(d_array)
#真ん中の要素の差を取るとそれが答え
ans = d_array[N // 2] - d_array[N // 2 - 1]
print(ans)

Measured memory_bytes: 14428
import scala.io.StdIn

object Main extends App {
  val n = StdIn.readInt
  val a = StdIn.readLine.split(" ").map(_.toLong)
  val sum = a.sum
  val initial = ((a.head-(sum-a.head)).abs, a.head)

  val ans = a.tail.init./:(initial)((acc, i) => {
      val x = acc._2 + i
      val y = sum - x
      val xy = math.min((x-y).abs, acc._1)
      (xy, x)
    })._1

  println(ans)
}

Measured memory_bytes: 59088
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        char[] s = sc.next().toCharArray();
        int ans = 0;
        for (int i = 0; i < s.length; i++) {
            if(s[i] == '1') {
                ans++;
            }
        }
        System.out.println(ans);
    }
}

Measured memory_bytes: 35428
#include<iostream>
#include<vector>
#include<string>
#include<deque>
#include<unordered_map>
#include<unordered_set>
#include<queue>
#include<algorithm>
#include<cmath>
#include<numeric>
using namespace std;
typedef long long LL;

const int MOD = 1e9+7;
// void mergeSort(vector<int> &a,int l,int r,LL &re){
//     if(l>r) return;
//     int m = (r+l)/2;
//     mergeSort(a,l,m,re);
//     mergeSort(a,m+1,r,re);

// }

void solve(){
    int n;
    cin>>n;
    int pre = 1e9+7;
    int ans = 0;
    for(int i=0;i<n;i++){
        int x;
        cin>>x;
        if(x<=pre) ans++;
        pre = min(pre,x);
    }
    cout<<ans<<endl;
}

int main(){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int T = 1;
    while(T--){
        solve();
    }
    return 0;
}

Measured memory_bytes: 256
import std.algorithm;
import std.range;
import std.stdio;
import std.math;
import std.array;
import std.string;
import std.conv;

/// 数列の読み込み
auto readNums(T = int)() {
	return readln().chomp.split.map!(to!T).array;
}

void main() {
	const nums = readNums();
	immutable n = nums[0];
	immutable m = nums[1];
	size_t[int] result;
	foreach(i; 0 .. n) {
		const knums = readNums();
		immutable k = knums[1];
		foreach(fav; knums[1 .. $]) {
			++result[fav];
		}
	}
	writefln("%s", result.byValue.count(n));
}

Measured memory_bytes: 256
n = int(input())
li = list(map(int, input().split()))
li.sort()
c = 0
for i in range(n):
    for j in range(n):
        for k in range(n):
            if li[i] == li[j] or li[j] == li[k] or li[k] == li[i]:
                continue
            else:
                if li[i]+li[j] > li[k] and li[k]+li[j] > li[i] and li[i]+li[k] > li[j]:
                    c += 1
print(c//6)

Measured memory_bytes: 68468
#include<bits/stdc++.h>
#define st first
#define nd second
#define pb push_back
#define pf push_front
#define ppb pop_back
#define ppf pop_front
#define umax(x,y) x=max(x,y)
#define umin(x,y) x=min(x,y)
#define ll long long 
#define ii pair<int,int>
#define iii pair<ii,int>
#define iiii pair<ii,ii>
#define sz(x) ((int) x.size())
#define orta ((bas+son)/2)
#define all(x) x.begin(),x.end()
#define pw(x) (1ll<<(x))
#define inf 10000000000000000
#define MOD 1000000007	
#define N 200005
#define M 100005
#define LOG 20
#define KOK 5880
#define EPS 0.00000001
using namespace std;

char s[N];
map<char,int> cnt;

int main(int argc,char* argv[]) {

	int n;

	scanf("%d %s",&n,s+1);

	for(int i=1;i<=n;i++) cnt[s[i]]++;
	
	int ans=1;

	for(auto x:cnt) ans=(ll)ans*(x.nd+1)%MOD;

	printf("%d",(ans-1+MOD)%MOD);

}

Measured memory_bytes: 384
n1 = int(input())
nums1 = list(map(int, input().split()))
n2 = int(input())
nums2 = list(map(int, input().split()))

def binary_search(nums1, n1, key):
    L,R = 0, n1
    while L < R:
        pivot = (L + R) // 2
        if nums1[pivot] == key:
            return True

        if key > nums1[pivot]:
            L = pivot + 1
        else:
            R = pivot
    return False

output = 0
nums1.append(None)
for key in nums2:
    if binary_search(nums1, n1, key):
        output += 1

print(output)


Measured memory_bytes: 16712
#include <iostream>
#include <iomanip>
#include <ios> 
#include <vector>
#include <string>
#include <algorithm>
#include <functional>
#include <queue>
#include <stack>
#include <set>
#include <cmath>
#include <bitset>
#include <map>
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define rep1(i,n) for(int i=1;i<=(int)(n);i++)
#define sz(c) ((int)(c).size())

using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
//const int MAX=;



int main(){
	int N,M,C;
	cin>>N>>M>>C;
	int B[20];
	rep(i,M)cin>>B[i];
	int ans=0;
	rep(j,N){
		int ct=C;
		rep(i,M){
			int a;
			cin>>a;
			ct+=a*B[i];
		}
		if(ct>0)ans++;
	}
	cout<<ans;
}

Measured memory_bytes: 256
from collections import defaultdict, Counter
from itertools import product, groupby, count, permutations, combinations
from math import pi, sqrt
from collections import deque
from bisect import bisect, bisect_left, bisect_right
from string import ascii_lowercase
from functools import lru_cache
import sys
sys.setrecursionlimit(10000)
INF = float("inf")
YES, Yes, yes, NO, No, no = "YES", "Yes", "yes", "NO", "No", "no"
dy4, dx4 = [0, 1, 0, -1], [1, 0, -1, 0]
dy8, dx8 = [0, -1, 0, 1, 1, -1, -1, 1], [1, 0, -1, 0, 1, 1, -1, -1]


def inside(y, x, H, W):
    return 0 <= y < H and 0 <= x < W


def ceil(a, b):
    return (a + b - 1) // b


def main():
    N, i = map(int, input().split())
    print(N - i + 1)


if __name__ == '__main__':
    main()


Measured memory_bytes: 4332
#include<deque>
#include<queue>
#include<vector>
#include<algorithm>
#include<iostream>
#include<set>
#include<cmath>
#include<tuple>
#include<string>
#include<chrono>
#include<functional>
#include<iterator>
#include<random>
#include<unordered_set>
#include<array>
#include<map>
#include<iomanip>
#include<assert.h>
#include<bitset>
#include<stack>
#include<memory>
using namespace std;
using namespace std::chrono;
typedef long long int llint;
typedef double lldo;
#define mp make_pair
#define mt make_tuple
#define pub push_back
#define puf push_front
#define pob pop_back
#define pof pop_front
#define fir first
#define sec second
#define res resize
#define ins insert
#define era erase
/*
cout<<fixed<<setprecision(20);
cin.tie(0);
ios::sync_with_stdio(false);
*/
const llint mod=998244353;
const llint big=2.19e15+1;
const long double pai=3.141592653589793238462643383279502884197;
const long double eps=1e-15;
template <class T,class U>bool mineq(T& a,U b){if(a>b){a=b;return true;}return false;}
template <class T,class U>bool maxeq(T& a,U b){if(a<b){a=b;return true;}return false;}
llint gcd(llint a,llint b){if(a%b==0){return b;}else return gcd(b,a%b);}
llint lcm(llint a,llint b){if(a==0){return b;}return a/gcd(a,b)*b;}
template<class T> void SO(T& ve){sort(ve.begin(),ve.end());}
template<class T> void REV(T& ve){reverse(ve.begin(),ve.end());}
template<class T>llint LBI(vector<T>&ar,T in){return lower_bound(ar.begin(),ar.end(),in)-ar.begin();}
template<class T>llint UBI(vector<T>&ar,T in){return upper_bound(ar.begin(),ar.end(),in)-ar.begin();}
int main(void){
	int a,b,c;cin>>a>>b>>c;
	cout<<a+b+c+9*max(a,max(b,c))<<endl;
	return 0;
}

Measured memory_bytes: 256
//header{{{
#include<bits/stdc++.h>
  
using namespace std;
 
#define rep(i,n) for(int i=0;i<(n);++i)
#define reps(i,n) for(int i=1;i<=(n);++i)
#define all(x) (x).begin(),(x).end()
#define Fixed fixed << setprecision(12)
#define int int64_t
using pii = pair<int,int>;
constexpr int INF  = 0x3f3f3f3f;
constexpr long long LINF = 0x3f3f3f3f3f3f3f3fLL;
constexpr int mod = 1e9+7; 
constexpr int MOD = 998244353;

template <class A, class B> inline bool chmax(A &a, const B &b) { return b > a && (a = b, true); }
template <class A, class B> inline bool chmin(A &a, const B &b) { return b < a && (a = b, true); }

template <class T> using min_heap = priority_queue<T,vector<T>,greater<T> >;
template <class T> using max_heap = priority_queue<T>;
template <class A, class B> using umap = unordered_map<A,B>;
  
int gcd(int a,int b){ return b ? gcd(b,a % b) : a;}
int lcm(int a,int b){ return a / gcd(a,b) * b;}

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

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

    int n,m;
    cin >> n >> m;

    if(n == m) cout << "Yes\n";
    else cout << "No\n";

    return 0;
}


Measured memory_bytes: 256
/*
[ ( ^ _ ^ ) ]
*/
// problem: atc/abc164_a
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define INF 1000000000



int main() {
    int s, w;
    scanf("%d%d", &s, &w);
    if(w>=s) {
        printf("unsafe");
    } else {
        printf("safe");
    }
}


Measured memory_bytes: 3720
N=gets.to_i
A=gets.split.map(&:to_i).reverse

data = Array.new(N, 0)
ans=[]

N.times do |i|
  num = N-i
  t = N/num
  if t < 2
    data[i] = A[i]
    ans << num if data[i] == 1
  else
    m = num
    sum = 0
    (t-1).times do
      m += num
      sum += data[N-m]
    end
    data[i] = 1 if sum % 2 != A[i]
    ans << num if data[i] == 1
  end
end

size = ans.size
if size == 0
  puts 0
else
  puts size
  puts ans.reverse.join(" ")
end


Measured memory_bytes: 24516
#include <bits/stdc++.h>
using namespace std;
constexpr auto MOD = 1000000007;
constexpr int INF = 1e9;
constexpr long long LINF = 1e18;
#define rep(i, n) for (int i = 0; i < (n); i++)
typedef long long ll;
typedef pair<int, int> PII;
typedef pair<ll, ll> PLL;
typedef vector<int> VI;
typedef vector<ll> VLL;

string s;
long long n, m;

int main()
{
  string t, ans;
  ans = "";
  cin >> n >> s >> t;
  for (int i = 0; i < n; i++)
  {
    ans += s[i];
    ans += t[i];
  }
  cout << ans << endl;
}


Measured memory_bytes: 256
#pragma GCC optimize(2)
#include<bits/stdc++.h>
#define rb(a,b,c) for(int a=b;a<=c;++a)
#define rl(a,b,c) for(int a=b;a>=c;--a)
#define LL long long
#define IT iterator
#define PB push_back
#define II(a,b) make_pair(a,b)
#define FIR first
#define SEC second
#define FREO freopen("check.out","w",stdout)
#define rep(a,b) for(int a=0;a<b;++a)
#define SRAND mt19937 rng(chrono::steady_clock::now().time_since_epoch().count())
#define random(a) rng()%a
#define ALL(a) a.begin(),a.end()
#define POB pop_back
#define ff fflush(stdout)
#define fastio ios::sync_with_stdio(false)
#define R(a) cin>>a
#define R2(a,b) cin>>a>>b
#define check_min(a,b) a=min(a,b)
#define check_max(a,b) a=max(a,b)
using namespace std;
const int INF=0x3f3f3f3f;
typedef pair<int,int> mp;
/*}
*/
int h,w,a[200000+1],b[200000+1];
multiset<int> s;
set<mp> se;
int main(){
	R2(h,w);
	rb(i,1,h)
		R2(a[i],b[i]);
	rb(i,1,w)
		s.insert(0),se.insert(II(i,i));
	set<mp> :: IT l,r,nex;
	rb(i,1,h){
		l=se.lower_bound(II(a[i],-INF));
		r=se.upper_bound(II(b[i],INF));
		if(r!=se.begin()&&l!=se.end()&&l!=r){
			r--;
			int save=(*r).SEC;
			while(1){
//				cout<<"E:"<<(*l).FIR<<","<<(*l).SEC<<endl;
				if(l==r){
					s.erase(s.lower_bound((*l).FIR-(*l).SEC));
					se.erase(l);
					if(b[i]!=w){
						se.insert(II(b[i]+1,save));
//						cout<<"I:"<<b[i]+1<<","<<save<<endl;
						s.insert(b[i]+1-save);
					}
					break;
				}
				l++;
				nex=l;
				l--;
				s.erase(s.lower_bound((*l).FIR-(*l).SEC));
				se.erase(l);
				l=nex;
			}
			
		}
		if(s.empty()) cout<<"-1\n";
		else cout<<(*s.begin())+i<<endl;
	}
	return 0;
}


Measured memory_bytes: 23924
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <numeric>
#include <cmath>
#include <unordered_map>

using namespace std;
using ll = long long;

void _cin(){} template <class Head, class... Tail> void _cin(Head&& head, Tail&&... tail){ cin >> head; _cin(forward<Tail>(tail)...); }
void _cout(){ cout << "\n"; } template <class Head, class... Tail> void _cout(Head&& head, Tail&&... tail){ cout << head; _cout(forward<Tail>(tail)...); }
int gcd(int a, int b){ return (b == 0) ? a : gcd(b, a % b); }
template<typename S, typename T> ostream& operator<<(ostream &os, const pair<S, T> &p){ cout << "[" << p.first << ", " << p.second << "]"; return os; }

#define Sq(x) (x)*(x)
#define For(i, n) for(int i = 0; i < (n); i ++)
#define For1(i, n) for(int i = 1; i <= (n); i ++)
#define Rep(n) For(_, n)
#define Range(c) c.begin(), c.end()
#define RevRange(c) c.rbegin(), c.rend()
#define Contains(c, x) (find(Range(c), x) != c.end())
#define Search(rb, re, x) distance(rb, find(rb, re, x))
#define Sort(a) sort(Range(a))
#define DeSort(a) sort(RevRange(a))
#define Reverse(c) reverse(Range(c))
#define Unique(a) a.erase(unique(Range(a)), a.end())
#define Cusum(T, xs, sxs) vector<T> sxs(xs.size()+1); For(i, (int)xs.size()) sxs[i+1] = sxs[i] + xs[i]
#define Cin(T, ...) T __VA_ARGS__; _cin(__VA_ARGS__)
#define Cins(T, n, xs) vector<T> xs(n); For(i, n) cin >> xs[i]
#define Cins2(T, n, xs, ys) vector<T> xs(n), ys(n); For(i, n) cin >> xs[i] >> ys[i]
#define Cins3(T, n, xs, ys, zs) vector<T> xs(n), ys(n), zs(n); For(i, n) cin >> xs[i] >> ys[i] >> zs[i]
#define Cinss(T, n, m, xs) Vec2(T, n, m, xs); For(i, n) For(j, m) cin >> xs[i][j]
#define Cinm(T, n, map) unordered_map<T, int> map; Rep(n){ Cin(T, x); map[x] ++; }
#define Cout(...) _cout(__VA_ARGS__)
#define Couts(xs) { for(const auto &e : xs) cout << e << " "; cout << "\n"; }
#define Coutyn(cond) Cout((cond) ? "yes" : "no")
#define CoutYn(cond) Cout((cond) ? "Yes" : "No")
#define CoutYN(cond) Cout((cond) ? "YES" : "NO")
#define vc vector
#define Mini(a, x) a = min(a, x)
#define Maxi(a, x) a = max(a, x)

// constexpr int MOD = 1e9+7;

int main(void){
    Cin(int, n);
    Cins(int, n, a);
    
    ll sum = 0;
    For(i, n) sum += a[i];
    ll m = (ll)n*(n+1)/2;
    if(sum % m != 0){
        Cout("NO");
        return 0;
    }
    ll k = sum / m;
    ll c = 0;
    For(i, n){
        ll s = k - (a[(i+1)%n]-a[i]);
        if(s < 0 || s % n != 0){
            Cout("NO");
            return 0;
        }
        c += s / n;
    }
    CoutYN(c == k);
}




Measured memory_bytes: 640
#include<iostream>
#include<cstdio>
#include<string>
#include<algorithm>
#include<utility>
#include<numeric>
#include<vector>
#include<map>
#include<unordered_map>
#include<set>
#include<tuple>
#include<stack>
#include<queue>
#include<functional>
#include<iterator>
#include<cmath>
#include<cctype>

using namespace std;

typedef long long ll;
typedef pair<int,int> P;

const int INF = 1e9;
const ll LINF = 1e18;

struct edge{int to,cost;};

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

	int n,k;
	cin >> n >> k;

	ll a=n/k,b=n%k;
	//cout << a << " " << b << "\n";
	ll ans=0;
	if(k%2 == 0){
		if(b >= k/2) ans += (a+1)*(a+1)*(a+1);
		else ans += a*a*a;
	}
	ans += a*a*a;

	cout << ans << "\n";


	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
//#include <boost/multiprecision/cpp_ll.hpp>
//typedef boost::multiprecision::cpp_ll ll;
typedef long double dd;
#define i_7 (ll)(1E9+7)
//#define i_7 998244353
#define i_5 i_7-2
ll mod(ll a){
    ll c=a%i_7;
    if(c>=0)return c;
    return c+i_7;
}
typedef pair<ll,ll> l_l;
ll inf=(ll)1E16;
#define rep(i,l,r) for(ll i=l;i<=r;i++)
#define pb push_back
ll max(ll a,ll b){if(a<b)return b;else return a;}
ll min(ll a,ll b){if(a>b)return b;else return a;}
void Max(ll &pos,ll val){pos=max(pos,val);}//Max(dp[n],dp[n-1]);
void Min(ll &pos,ll val){pos=min(pos,val);}
void Add(ll &pos,ll val){pos=mod(pos+val);}
dd EPS=1E-9;
string alp="abcdefghijklmnopqrstuvwxyz";
#define endl "\n"
#define fastio ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);


int main(){fastio
    ll n;cin>>n;
    ll L[n];rep(i,0,n-1)cin>>L[i];
    sort(L,L+n);
    ll l,r,mid;
    ll ans=0;
    rep(i,0,n-3){
        rep(j,i+1,n-2){
            l=j;
            r=n;
            while(r-l>1){
                mid=(r+l)/2;
                if(L[mid]<L[i]+L[j]){
                    l=mid;
                }else{
                    r=mid;
                }
            }
            ans+=(l-j);
        }
    }
    cout<<ans<<endl;
    
    return 0;
}



Measured memory_bytes: 256
def f(n,xyh):
	for i in range(n):
		if xyh[i][2]:
			xs,ys,hs=xyh[i]

	for Cx in range(101):
		for Cy in range(101):
			H=hs+abs(xs-Cx)+abs(ys-Cy)
			
			for i in range(n):
				if xyh[i][2] != max(H-abs(xyh[i][0]-Cx)-abs(xyh[i][1]-Cy),0):
					break
			else:
				return '{} {} {}'.format(Cx,Cy,H)

if __name__=="__main__":
	x=int(input())
	data=[[int(j) for j in input().split()] for i in range(x)]
	print(f(x,data))


Measured memory_bytes: 3064
#include <iostream>

using namespace std;

string a, b;
string c;
string d;

int main()
{
    cin >> a >> b;
    int ok = 0;

    int len = a.size();
    int lb = b.size();
    int i, j, h;
    for(i = 0; i < a.size(); i ++)
    {
        if(i + lb <= len)
        {
            int pos = 1;
            for(j = i; j < i + lb; j ++)
            {
                if(a[j] != '?' && a[j] != b[j - i])
                    pos =0;
            }
            //cout << i << " " << pos << "\n";

            if(pos == 1)
            {
                d = a;
                    for(j = i; j < i + lb; j ++)
                    {
                           d[j] = b[j - i];
                    }
                    for(j = 0; j < len; j ++)
                        if(d[j] == '?')
                            d[j] = 'a';

                if(ok)
                {
                    if(c.compare(d) > 0)
                        c = d;
                }

                if(ok == 0)
                {
                   // cout << "BAGA " << d << "\n";

                    ok = 1;
                    c = d;
                }
            }
        }
    }

    if(ok == 1)

    cout << c << "\n";
    else
        cout << "UNRESTORABLE\n";

    return 0;
}


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

using namespace std;

#define F first
#define S second

int main() {
    string s, t;
    int i, j, pi, pj;

    cin >> s >> t;

    int n = (int)s.size();
    int m = (int)t.size();

    vector<vector<int>> dp(n + 1, vector<int>(m + 1));
    vector<vector<pair<int, int>>> bp(n + 1, vector<pair<int, int>>(m + 1, {-1, -1}));

    for (int i = 1; i <= n; i++)
        for (int j = 1; j <= m; j++) {
            if (dp[i][j] < dp[i - 1][j]) {
                dp[i][j] = dp[i - 1][j];
                bp[i][j] = {i - 1, j};
            }
            if (dp[i][j] < dp[i][j - 1]) {
                dp[i][j] = dp[i][j - 1];
                bp[i][j] = {i, j - 1};
            }
            if (s[i - 1] == t[j - 1] && dp[i][j] < 1 + dp[i - 1][j - 1]) {
                dp[i][j] = 1 + dp[i - 1][j - 1];
                bp[i][j] = {i - 1, j - 1};
            }
        }

    string ans;
    i = n, j = m;

    while (1) {
        pi = bp[i][j].F, pj = bp[i][j].S;
        if (pi == -1 && pj == -1)
            break;
        if (pi == i - 1 && pj == j - 1)
            ans.push_back(s[i - 1]);
        i = pi, j = pj;
    }

    reverse(ans.begin(), ans.end());
    cout << ans << '\n';

    return 0;
}

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

int main() {
    string s, t;
    cin>>s>>t;
    int n = s.size(), m = t.size();
    vector<vector<int> > dp(n+1, vector<int>(m+1));
    for(int i = 1; i<=n; i++) {
        for(int j = 1; j<=m; j++) {
            dp[i][j] = max(dp[i-1][j], dp[i][j-1]);
            if(s[i-1] == t[j-1]) {
                dp[i][j] = max(dp[i][j], 1 + dp[i-1][j-1]);
            }
        }
    }
    string ans = "";
    int i = n, j = m;
    while(i && j) {
        if(s[i-1] == t[j-1]) {
            ans = s[i-1] + ans;
            i--;
            j--;
        } else if(dp[i-1][j] > dp[i][j-1]) {
            i--;
        } else {
            j--;
        }
    }
    cout<<ans<<"\n";
}


Measured memory_bytes: 38948
#include<bits/stdc++.h>
#define ll long long
#define For(i,x,y) for(int i=x;i<=y;i++)
#define Rep(i,x,y) for(int i=x;i>=y;i--)
#define Forn(i,x,y) for(int i=x;i<y;i++)
#define oo 1000000
#define zyy 1000000007
#define M 100
#define N 200005
using namespace std;
inline ll read(){ll x=0,f=0;char ch=getchar();for(;ch<'0'||ch>'9';ch=getchar()) if(ch=='-') f=1;for(;ch>='0'&&ch<='9';ch=getchar()) x=(x<<1)+(x<<3)+ch-48;return f?-x:x;}
inline void write(ll x){if(x<10) putchar(x+48);else write(x/10),putchar(x%10+48);}
inline void writeln(ll x){if(x<0) putchar('-'),x=-x;write(x);putchar('\n');}
ll n,m;
int main(){
	n=read();m=read();
	if(m<=n*2) writeln(m/2);
	else{
		m-=n*2;
		writeln(n+m/4);
	}
	return 0;
}

Measured memory_bytes: 256
N,K = map(int, input().split())
a = input()
l = [0]*(N-1)
for n,(i , j) in enumerate(zip(a,a[1:])):
    if i == "A" and j == "C":
        l[n] +=1
l = [0]+ l
for i,n in enumerate(l[:-1]):
    l[i+1] +=l[i]
for i in range(K):
    ta,tb = map(int, input().split())
    print(l[tb-1]-l[ta-1])

Measured memory_bytes: 53852
#include<iostream>
using namespace std;
int main(){
    int N,A,B,C,X;
    int y[100];
    const int ans = -1;
    while(1){
        int count = -1,n,k=0;
        cin >> N >> A >> B >> C >> X;
        n = N;
        if(N==0&&A==0&&B==0&&C==0&&X==0)break;
        for(int i = 0;i<N;i++){
            cin >> y[i];
        }
        while(n!=0){
            if(X==y[k]){
                k++;
                n--;
            }
            X = (A*X+B)%C;
            count++;
            if(count>10000)break;
        }
        if(count <= 10000){
            cout << count <<endl;
            //cout << ans << endl;
        }else{
            cout << ans << endl;
            //cout << count <<endl;
        }
    }
    return 0;
}


Measured memory_bytes: 3096
n=int(input())
mod=998244353
A=[]
for i in range(n):
  A.append(int(input()))
t=sum(A)
DP=[[0]*(t) for _ in range(n+1)]
DP[0][0]=1
for i in range(n):
  a=A[i]
  for j in range(t):
    DP[i+1][j]=(2*DP[i][j]+DP[i][max(0,j-a)])%mod

DP2=[[0]*(t) for _ in range(n+1)]
DP2[0][0]=1
for i in range(n):
  a=A[i]
  for j in range(t):
    if j>=a:
      DP2[i+1][j]=(DP2[i][j]+DP2[i][j-a])%mod
    else:
      DP2[i+1][j]=DP2[i][j]

ans=1
for i in range(n):
  ans=(ans*3)%mod
if t%2==1:
  print((ans-3*DP[n][t//2+1])%mod)
else:
  print((ans-3*DP[n][t//2]+3*DP2[n][t//2])%mod)



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

int main() {
	int n;
	cin>>n;
	
	string s;
	cin>>s;
	for(int i=0;i<s.size();i++){
		if(s[i]+n<='Z')s[i]=char(s[i]+n);
		else{
			int temp='Z'-s[i];
			int x=n;
			x-=temp;
			s[i]=char('A'+x-1);
			
		}
	}
	cout<<s<<endl;
	return 0;
}

Measured memory_bytes: 256
"""
B
"""
import sys

A=[list(map(int,input().split())) for i in range(3)]
N=int(input())
B=[int(input()) for i in range(N)]
flag=[[0]*3 for i in range(3)]

for b in B:
    for i in range(3):
        for j in range(3):
            if A[i][j]==b:
                flag[i][j]=1

for i in range(3):
    cnt=0
    for j in range(3):
        cnt+=flag[i][j]
    if cnt==3:
        print("Yes")
        sys.exit()

for i in range(3):
    cnt=0
    for j in range(3):
        cnt+=flag[j][i]
    if cnt==3:
        print("Yes")
        sys.exit()

cnt=0
for i in range(3):
    cnt+=flag[i][i]
if cnt==3:
    print("Yes")
    sys.exit()

cnt=0
for i in range(3):
    cnt+=flag[i][2-i]
if cnt==3:
    print("Yes")
    sys.exit()

print("No")

Measured memory_bytes: 38256
#include<bits/stdc++.h>
#define N 100005
using namespace std;
typedef pair<int,int> P;
int n, m;
vector<int> G[N];
int d[N];
set<P> used;
long long odd,even;

void dfs(int x,int dep){

  d[x]=dep;
  
  for(int i=0;i<G[x].size();i++){
    
    int nx=G[x][i];

    if(d[nx]!=-1) continue;

    used.insert(P(min(x,nx),max(x,nx)));
    
    dfs(nx,dep+1);
  }
  
}

int main(){
  
  cin>>n>>m;
  
  int A, B;
  
  for(int i=0;i<m;i++){
    scanf("%d %d",&A,&B);
    G[A-1].push_back(B-1);
    G[B-1].push_back(A-1);
  }
  
  memset(d,-1,sizeof(d));
  
  d[0]=0;
  
  for(int i=0;i<G[0].size();i++)

    if(d[G[0][i]]==-1) dfs(G[0][i],1);

  bool flag=false;
  
  for(int i=0;i<n;i++)
    for(int j=0;j<G[i].size();j++){
      
      int ni=G[i][j];
      
      if(used.count(P(min(i,ni),max(i,ni)))) continue;

      if((d[i]+d[ni])%2==0) flag=true;
    }

  long long ans=0;

  for(int i=0;i<n;i++)
    if(d[i]%2) odd++;
    else even++;

  ans+=odd*even;

  if(flag){
    ans+=odd*(odd-1)/2;
    ans+=even*(even-1)/2;
  }

  ans-=m;

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


Measured memory_bytes: 12928
import java.io.*;
import java.util.*;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        PrintStream out = new PrintStream(System.out);
        String a, b;

        a = sc.next();
        b = sc.next();

        if (a.equals("H")) {
            if (b.equals("H")) {
                out.println("H");
            }
            if (b.equals("D")) {
                out.println("D");
            }
        }
        if (a.equals("D")) {
            if (b.equals("H")) {
                out.println("D");
            }
            if (b.equals("D")) {
                out.println("H");
            }
        }

        sc.close();

    }
}

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

int main(){
  int n,k;
  cin>> n >> k;
  
  double ans=0;
  int restmax=n;
  for (int i=0; restmax>0; i++){
    int num=restmax-ceil(k/pow(2,i))+1;
    if (num>0){
      ans+=num*pow(0.5,i)/n;
      restmax-=num;
    }
  }
  cout<<fixed<<setprecision(10);
  cout<< ans << endl;
}

Measured memory_bytes: 256
//https://qiita.com/tanakh/items/0ba42c7ca36cd29d0ac8 より
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
    ($($r:tt)*) => {
        let s = {
            use std::io::Read;
            let mut s = String::new();
            std::io::stdin().read_to_string(&mut s).unwrap();
            s
        };
        let mut iter = s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
}

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

macro_rules! read_value {
    ($iter:expr, ( $($t:tt),* )) => {
        ( $(read_value!($iter, $t)),* )
    };
    ($iter:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($iter, $t)).collect::<Vec<_>>()
    };
    ($iter:expr, chars) => {
        read_value!($iter, String).chars().collect::<Vec<char>>()
    };
    ($iter:expr, usize1) => {
        read_value!($iter, usize) - 1
    };
    ($iter:expr, $t:ty) => {
        $iter.next().unwrap().parse::<$t>().expect("Parse error")
    };
}

// ここまで

fn run() {
    input! {
        n: usize,
        s: chars,
    }
    let mut a = vec![0; 3 * n];
    for (a, c) in a.iter_mut().zip(s.iter()) {
        *a = match *c {
            'R' => 0,
            'B' => 1,
            'G' => 2,
            _ => unreachable!(),
        };
    }
    const MOD: u64 = 998244353;
    let mut ans = 1;
    let mut cnt = vec![0; 3];
    //0a1b2c
    for i in 0..(3 * n) {
        let a = a[i];
        let b = (a + 1) % 3;
        let c = (a + 2) % 3;
        if cnt[a] >= cnt[b] && cnt[a] >= cnt[c] {
        } else if cnt[a] < cnt[b] && cnt[a] < cnt[c] {
        } else {
            let v = std::cmp::max(cnt[b], cnt[c]) - cnt[a];
            ans = ans * v % MOD;
        }
        cnt[a] += 1;
    }
    let mut cnt = vec![0; 3];
    for i in (0..(3 * n)).rev() {
        let a = a[i];
        let b = (a + 1) % 3;
        let c = (a + 2) % 3;
        if cnt[a] >= cnt[b] && cnt[a] >= cnt[c] {
        } else if cnt[a] < cnt[b] && cnt[a] < cnt[c] {
        } else {
            let v = std::cmp::max(cnt[b], cnt[c]) - cnt[a];
            ans = ans * v % MOD;
        }
        cnt[a] += 1
    };
    for i in 1..(n + 1) {
        ans = ans * i as u64 % MOD;
    }
    println!("{}", ans);
}

fn main() {
    run();
}


Measured memory_bytes: 10492