akhauriyash/Code-Regression huggingface dataset:
using System;
using System.Collections.Generic;
using System.Collections;
using System.Collections.Specialized;
using System.Linq;
using System.Text;
using System.IO;
using System.Reflection;
using static System.Math;
using System.Numerics;
static class Program{
	const int mod=(int)1e9+7;
	const double eps=1e-11;
	static void Main(){
		Sc sc=new Sc();
		var n=sc.L;
		n--;
		var ans="";
		while(n>=0) {
			ans=(char)(n%26+'a')+ans;
			n/=26;
			n--;
		}
		Console.WriteLine("{0}",ans);
	}
}
public class Sc{
	public int I{get{return int.Parse(Console.ReadLine());}}
	public long L{get{return long.Parse(Console.ReadLine());}}
	public double D{get{return double.Parse(Console.ReadLine());}}
	public string S{get{return Console.ReadLine();}}
	public int[] Ia{get{return Array.ConvertAll(Console.ReadLine().Split(),int.Parse);}}
	public long[] La{get{return Array.ConvertAll(Console.ReadLine().Split(),long.Parse);}}
	public double[] Da{get{return Array.ConvertAll(Console.ReadLine().Split(),double.Parse);}}
	public string[] Sa{get{return Console.ReadLine().Split();}}
	public object[] Oa{get{return Console.ReadLine().Split();}}
	public int[] Ia2{get{return Array.ConvertAll(("0 "+Console.ReadLine()+" 0").Split(),int.Parse);}}
	public int[] Ia3(string a,string b){return Array.ConvertAll((a+Console.ReadLine()+b).Split(),int.Parse);}
	public long[] La2{get{return Array.ConvertAll(("0 "+Console.ReadLine()+" 0").Split(),long.Parse);}}
	public long[] La3(string a,string b){return Array.ConvertAll((a+Console.ReadLine()+b).Split(),long.Parse);}
	public double[] Da2{get{return Array.ConvertAll(("0 "+Console.ReadLine()+" 0").Split(),double.Parse);}}
	public double[] Da3(string a,string b){return Array.ConvertAll((a+Console.ReadLine()+b).Split(),double.Parse);}
	public T[] Arr<T>(int n,Func<T> f){var a=new T[n];for(int i=0;i<n;i++){a[i]=f();}return a;}
	public T[] Arr<T>(int n,Func<int,T> f){var a=new T[n];for(int i=0;i<n;i++){a[i]=f(i);}return a;}
	public T[] Arr<T>(int n,Func<string[],T> f){var a=new T[n];for(int i=0;i<n;i++){a[i]=f(Console.ReadLine().Split());}return a;}
	public T[] Arr<T>(int n,Func<int,string[],T> f){var a=new T[n];for(int i=0;i<n;i++){a[i]=f(i,Console.ReadLine().Split());}return a;}
}

Measured memory_bytes: 27432
import java.util.Scanner

object Main {

  def gcd(a: Int, b: Int): Int = {
    if (b == 0) (a)
    else if (b > a) (gcd(b, a))
    else (gcd(b, a % b))
  }

  def solve(sc: => Scanner): Unit = {
    val A, B, C, D = sc.nextInt
    val X = math.abs(A - C)
    val Y = math.abs(B - D)
    println(X + Y - gcd(X, Y));
  }

  def main(args: Array[String]): Unit = {
    val sc: Scanner = new Scanner(System.in)
    solve(sc)
  }
}

Measured memory_bytes: 27452
#include <iostream>
#include <algorithm>
#include <functional>
#include <vector>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <string>
#include <numeric>
#include <cmath>

#define rep(i, n) for (int i = 0; i < n; i++)
using namespace std;
typedef long long ll;
using P = pair<ll, ll>;

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

const ll MOD = 1000000007;
const int INF = 1<<29;

int main(){
  int N; cin >> N;
  string S; cin >> S;

  bool flag = true;
  if (N % 2 != 0) flag = false;
  else{
    string pre, post;
    for (int i = 0; i < N / 2; ++i){
      pre += S[i];
    }
    for (int i = N / 2; i < N; ++i){
      post += S[i];
    }
    if (pre != post) flag = false;
  }
  if (flag) cout << "Yes" << endl;
  else cout << "No" << endl;
}


Measured memory_bytes: 256
//clear adj and visited vector declared globally after each test case
//check for long long overflow
//while adding and subs check if mod becomes -ve
//while using an integer directly in a builtin function add ll
//Mod wale question mein last mein if dalo ie. Ans<0 then ans+=mod;
//Dont keep array name as size or any other key word

#include <bits/stdc++.h> 
#include <ext/pb_ds/assoc_container.hpp>
#define int long long
#define IOS std::ios::sync_with_stdio(false); cin.tie(NULL);cout.tie(NULL);cout.precision(dbl::max_digits10);
#define pb push_back
#define mod 1000000007 //998244353
#define lld long double
#define mii map<int, int>
#define mci map<char, int>
#define msi map<string, int>
#define pii pair<int, int>
#define ff first
#define ss second 
#define all(x) (x).begin(), (x).end()
#define rep(i,x,y) for(int i=x; i<y; i++)    
#define fill(a,b) memset(a, b, sizeof(a))
#define vi vector<int>
#define setbits(x) __builtin_popcountll(x)
#define print2d(dp,n,m) for(int i=0;i<=n;i++){for(int j=0;j<=m;j++)cout<<dp[i][j]<<" ";cout<<"\n";}
typedef std::numeric_limits< double > dbl;
using namespace __gnu_pbds;
using namespace std;
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> indexed_set;
const long long N=200005, INF=2000000000000000000;
lld pi=3.1415926535897932;
int lcm(int a, int b)
{
    int g=__gcd(a, b);
    return a/g*b;
}
int power(int a, int b, int p)
    {
        if(a==0)
        return 0;
        int res=1;
        a%=p;
        while(b>0)
        {
            if(b&1)
            res=(res*a)%p;
            b>>=1;
            a=(a*a)%p;
        }
        return res;
    }
int par[N],siz[N];

int findset(int a)
{
    if(par[a]==a)
    return a;
    return par[a]=findset(par[a]);
}

void unionset(int a, int b)
{
    a=findset(a);
    b=findset(b);
    if(a==b)
    return;
    if(siz[a]>siz[b])
    swap(a, b);
    par[a]=b;
    siz[b]+=siz[a];
}
int32_t main()
{
    IOS;
    int n,m;
    cin>>n>>m;
    for(int i=1;i<=n;i++)
    {
        par[i]=i;
        siz[i]=1;
    }
    for(int i=0;i<m;i++)
    {
        int a,b;
        cin>>a>>b;
        unionset(a, b);
    }
    set <int> s;
    int ans=1;
    for(int i=1;i<=n;i++)
    {
        ans=max(ans, siz[i]);
    }
    cout<<ans;
}

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

int main(){
  int n, k;
  cin >> n >> k;
  vector<int> score(n);
  for(int i = 0; i < n; i++) cin >> score[i];
  
  for(int i = k; i < n; i++){
    if(score[i-k] < score[i]) cout << "Yes" << endl;
    else cout << "No" << endl;
  }
  
  return 0;
}

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

using namespace std;
 
typedef long long ll;
typedef long double ld;
typedef pair<int, int> Pii;
typedef pair<int, ll> Pil;
typedef pair<ll, ll> Pll;
typedef pair<ll, int> Pli;

#define fi first
#define se second

const ll MOD = 1e9 + 7;
const ll MOD2 = 998244353;
const ll MOD3 = 1812447359;
const ll INF = 1ll << 62;
const double PI = 2 * asin(1);

void yes() {printf("yes\n");}
void no() {printf("no\n");}
void Yes() {printf("Yes\n");}
void No() {printf("No\n");}
void YES() {printf("YES\n");}
void NO() {printf("NO\n");}

int main(){
  int M, D; cin >> M >> D;
  int ans = 0;
  for (int i = 2; i < 10; i++){
    for (int j = 2; j < 10; j++){
      if (i * j <= M && i * 10 + j <= D) {
        ans++;
      }
    }
  }
  cout << ans << endl;


  return 0;
}


Measured memory_bytes: 3660
#include <stdio.h>

int main()
{
  int a,b,c,tmp;
  scanf("%d%d%d",&a,&b,&c);
  if(a>b)
  {
    tmp=a;
    a=b;
    b=tmp;
  }
  if(b>c)
  {
    tmp=b;
    b=c;
    c=tmp;
  }
  if(a>b)
  {
    tmp=a;
    a=b;
    b=tmp;
  }
  printf("%d %d %d\n",a,b,c);
  return 0;
}



Measured memory_bytes: 2060
#define  _CRT_SECURE_NO_WARNINGS
#include "bits/stdc++.h"
#pragma comment (linker, "/STACK:526000000")

using namespace std;
typedef string::const_iterator State;
#define eps 1e-11L
#define MAX_MOD 1000000007LL
#define GYAKU 500000004LL

#define MOD 998244353LL
#define seg_size 262144*2LL
#define pb push_back
#define mp make_pair
typedef long long ll;
#define REP(a,b) for(long long (a) = 0;(a) < (b);++(a))
#define ALL(x) (x).begin(),(x).end()

unsigned long xor128() {
	static unsigned long x = 123456789, y = 362436069, z = 521288629, w = time(NULL);
	unsigned long t = (x ^ (x << 11));
	x = y; y = z; z = w;
	return (w = (w ^ (w >> 19)) ^ (t ^ (t >> 8)));
}

void init() {
	iostream::sync_with_stdio(false);
	cout << fixed << setprecision(10);
}

#define int ll
void solve() {
	int n;
	cin >> n;
	int cnt = 0;
	REP(i, n) {
		string s;
		cin >> s;
		if (s == "A") {
			cnt++;
		}
		else {
			cnt--;
		}
		if (cnt < 0) {
			cout << "NO" << endl;
			return;
		}
	}
	if (cnt != 0) {
		cout << "NO" << endl;
		return;
	}
	cout << "YES" << endl;
}
#undef int

int main() {
	init();
	solve();
}


Measured memory_bytes: 3228
#include <bits/stdc++.h>
// #include "ane.cpp"

const int INF  = 1e9;
const long long INFLL = 1e18;
const int NMAX = 100005;
const int MMAX = 100005;
const int KMAX = 1005;
const int MOD  = 1e9 + 7;
using namespace std;

// comment to disable debug functions
#define DEBUG

// frequently used macros

#if __cplusplus >= 201103L
#define ALL(v) begin(v),end(v)
#define SORT(v) sort(begin(v), end(v))
#define FIND(v,x) find(begin(v), end(v), (x))
#else
#define ALL(v) (v).begin(),(v).end()
#define SORT(v) sort(v.begin(), v.end())
#define FIND(v,x) find(v.begin(), v.end(), (x))
#endif

#define MEMNEXT(from, to) do{ memmove((to), (from), sizeof(from)); \
memset((from), 0, sizeof(from)); } while(0)
#ifdef DEBUG
#define DUMP(x) do{ std::cerr << (#x) << ": " << x << std::endl; }while(0)
#else
#define DUMP(x) do{}while(0)
#endif

// frequent used aliases
typedef long long ll;
typedef pair<int, int> p;
typedef pair<ll, int> pl;
typedef pair<ll, ll> pll;
typedef vector<int> vec;
typedef vector<ll> vecll;
typedef vector<vec> mat;
typedef vector<vecll> matll;

// frequently used constants
static const int di[] = {-1, 0, 1, -1, 1, -1, 0, 1};
static const int dj[] = {-1, -1, -1, 0, 0, 1, 1, 1};

// frequently used structs
struct edge{
  int to,cost;
};

// printf for debug
#ifndef DEBUG
void debug(const char* format, ...){}
#else
void debug(const char* format, ...){
  va_list arg;
  va_start(arg, format);
  vprintf(format, arg);
  va_end(arg);
}
#endif

// dump vector
#ifdef DEBUG
#define DUMPV(v, c) do{       \
  printf("%s: ", #v);         \
  for (int i = 0; i < (c); ++i) \
  {                           \
  cout << (v)[i] << " ";      \
  }                           \
  cout << endl;               \
} while(0)
#else
#define DUMPV(v,c)
#endif

// std::fill of multi dimensions
template<typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val){
  std::fill( (T*)array, (T*)(array+N), val );
}

// binary search
ll BSearch(ll _begin, ll _end, bool (*f)(int)){
  ll mid;
  while(_end - _begin > 1LL) {
  mid = (_begin + _end) / 2LL;
  if(f(mid)) {
    debug("BSearch: f(%d) == true\n", mid);
    _end = mid;
  }
  else
  {
    debug("BSearch: f(%d) == false\n", mid);
    _begin = mid;
  }
  }
  return _end;
}


ll N,M,K,A,B,C,D,E;
int dp[NMAX] = {};

string S;
vec v;

ll ans = 0;

void solve(){
  // main algorithm
  ans = max(0LL, -(B + A * (N-1)) + (A + B * (N-1)) + 1);
}
void debug(){
  // output debug information

}
void answer(){
  // output answer
  printf("%lld\n", ans);
}
int main(int argc, char const *argv[])
{
  // operate inputs

  // Fill(dp, -1);
  scanf("%lld%lld%lld", &N,&A, &B);
  solve();
  #ifdef DEBUG
  debug();
  #endif
  answer();

  return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
int Xturn[2005][2005];
int Xmin[2005][2005];
int Yturn[2005][2005];
int Ymax[2005][2005];
int min(int a, int b)
{
    return (a < b)?a:b;
}
int max(int a, int b)
{
    return (a > b)?a:b;
}
int abs(int a)
{
    return (a < 0)?-a:a;
}
int main()
{
    int N, Z, W;
    int Ax[2005], Ay[2005];
    int i, j;
    scanf("%d %d %d", &N, &Z, &W);
    Ax[N] = Z;
    Ay[N] = W;
    for (i = 0; i < N; i++)
    {
        scanf("%d", &Ax[N - 1 - i]);
        Ay[N - 1 - i] = Ax[N - 1 - i];
    }
    for (i = 0; i <= N; i++)
        for (j = 0; j <= N; j++)
            Xmin[i][j] = 1e9;
    for (i = 1; i <= N; i++)
    {
        for (j = 1; j <= i; j++)
        {
            if (i == 0 || j == 0)
                Xturn[i][j] = abs(Ax[i] - Ax[j]);
            else
                Xturn[i][j] = max(Ymax[j - 1][j], abs(Ax[0] - Ay[j]));
            if (j > 0)
                Xmin[i][j] = min(Xmin[i][j - 1], Xturn[i][j]);
            // printf("X%d ", Xturn[i][j]);
        }
        for (j = i + 1; j <= N; j++)
        {
            if (i == 0 || j == 0)
                Yturn[i][j] = abs(Ay[i] - Ay[j]);
            else
                Yturn[i][j] = min(Xmin[i][i - 1], abs(Ay[0] - Ax[i]));
            if (i > 0)
                Ymax[i][j] = max(Ymax[i - 1][j], Yturn[i][j]);
            // printf("Y%d ", Yturn[i][j]);
        }
        // printf("\n");
    }
    printf("%d", Xturn[N][N]);
}


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

//全くわからん
// ax + by = gcd(a, b) を満たす (x, y) が格納される
int extGCD(int a, int b, int &x, int &y) {
	
	if (b == 0) {
		x = 1;
		y = 0;
		return a;
	}

	int d = extGCD(b, a%b, y, x);

	y -= a / b * x;

	return d;
}

int main()
{
	int a, b, x, y;
	cin >> a >> b;

	extGCD(a, b, x, y);

	cout << x << " " << y << endl;

	return 0;
}


Measured memory_bytes: 3120
#include <bits/stdc++.h>
#define rep(i, a, b) for(int i = a; i < b; i++)
#define Rep(i, a, b) for(int i = a; i <= b; i++)
#define _GLIBCXX_DEBUG
#define Vl vector<ll>
#define Vs vector<string>
#define Vp vector<pair<ll, ll>>
#define ll long long
#define ALL(v) (v).begin(),(v).end()
using namespace std;  
const double pi = acos(-1.0);
const ll MOD = 1e9 + 7;
const ll INF = 1LL << 60;


int main() {
  ll n; cin >> n;
  string s1, s2; cin >> s1 >> s2;

  int i = 0;
  ll ans = 1;
  int f = -1; //直前が縦か横か 0:tate 1:yoko
  while(i < n){
    if(s1[i] == s2[i]){
      if(i == 0){
        ans *= 3;
      }else if(f == 0){
        ans *= 2;
      }else if(f == 1){
        ans *= 1;
      }
      f = 0;
      i++;
    }else{
      if(i == 0){
        ans *= 6;
      }else if(f == 0){
        ans *= 2;
      }else if(f == 1){
        ans *= 3;
      }
      f = 1;
      i += 2;
    }
    ans %= MOD;
  }
  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 256
#define _GLIBCXX_DEBUG
#include<algorithm>
#include<cmath>
#include<cstring>
#include<cstdio>
#include<iostream>
#include<vector>
#include<queue>
#include<deque>
#include<stack>
#include<set>
#include<map>
#include<string>
#include <bits/stdc++.h>
#define rep(i, n) for(int i = 0; i < (int)n; i++)
#define rep2(i,s,n) for(int i=s;i< (int)n; i++)
#define ll long long 
#define all(v) v.begin(),v.end()
using namespace std;
const ll inf = 1000000007;
int main() {
  ll n,a,b,c,d; cin >>n>>a>>b>>c>>d;
  string s; cin >>s;
  if(c<d){
    rep2(i,b,d-2){
      if(s[i]=='#'&&s[i+1]=='#'){
        cout <<"No"<<endl;
        return 0;
      }
    }
    rep2(i,a,c-2){
      if(s[i]=='#'&&s[i+1]=='#'){
        cout <<"No"<<endl;
        return 0;
      }
    }
    cout <<"Yes"<<endl;
  }else{
    rep2(i,b,d-2){
      if(s[i]=='#'&&s[i+1]=='#'){
        cout <<"No"<<endl;
        return 0;
      }
    }
    rep2(i,a,a-2){
      if(s[i]=='#'&&s[i+1]=='#'){
        cout <<"No"<<endl;
        return 0;
      }
    }
    rep2(i,b-2,d-1){
      if(s[i]=='.'&&s[i+1]=='.'&&s[i+2]=='.'){
        cout <<"Yes"<<endl;
        return 0;
      }
    }
    cout <<"No"<<endl;
  }
}

Measured memory_bytes: 640
#include<iostream>
#include<cstdio>
#include<cstring>
#include<string>
#include<stack>
#include<queue>
#include<set>
#include<map>
#include<vector>
#include<list>
#include<cmath>
#include<algorithm>
#include<bitset>
#define lson node<<1,st,mid
#define rson node<<1|1,mid+1,ed
#define mem(a,x) memset(a,x,sizeof(a))
#define me(a) memset(a,0,sizeof(a))
#define IOS ios::sync_with_stdio(false)
#define lowbit(x) x&(-x)
#define up(i,x,y) for(long long i=x;i<y;i++)
#define down(i,x,y) for(long long i=x;i>=y;i--)
#define in freopen("in.txt","r",stdin)
#define out freopen("out.txt","w",stdout)   
typedef long long ll;
const ll mod = 1e9+7;
const ll INF = 0x3f3f3f3f;
const ll maxn = 1e6 + 5;
const ll N=1e3+5;
const double pi = acos(-1.0);
const double eps=1e-9;
using namespace std;
 
int main(){
	// in;
	// out;
	ll a,b,n;
	cin>>a>>b>>n;
	ll x;
	if(b-1<=n) x=(ll) floor((b-1)*a*1.0/b)-a*floor((b-1)*1.0/b);
	else x=(ll) floor(n*a*1.0/b)-a*floor(n*1.0/b);
	cout<<x<<endl;
}

Measured memory_bytes: 3748
#include<iostream>
#include<algorithm>
#include<vector>
#include<queue>
using namespace std;
typedef long long ll;
#define chmin(a,b) a=min(a,b)
#define chmax(a,b) a=max(a,b)
#define all(x) x.begin(),x.end()
#define rep(i,n) for(int i=0;i<n;i++)
#define mod 1000000007
#define mad(a,b) a=(a+b)%mod
ll n;
bool ask(ll x){
	cout<<"?";
	rep(i,n)cout<<" "<<x+i+1;
	cout<<"\n"<<flush;
	string s;
	cin>>s;
	return s=="Red";
}
vector<ll> X,Y;
bool solve(ll x){
	bool ok=1;
	for(auto t:X)if(t==x)ok=0;
	cout<<"?";
	if(ok){
		for(auto t:X)cout<<" "<<t+1;
	}
	else{
		for(auto t:Y)cout<<" "<<t+1;
	}
	cout<<" "<<x+1<<"\n"<<flush;
	string s; cin>>s;
	return s=="Red";
}
int main(){
	cin>>n;
	bool vl=ask(0);
	ll l=0,r=n,mid;
	while(l<r-1){
		mid=(l+r)>>1;
		if(ask(mid)==vl)l=mid;
		else r=mid;
	}
	for(int i=r;i<l+n;i++)X.push_back(i);
	for(int i=0;i<2*n;i++){
		bool th=0;
		if(i==l)th=1;
		if(i==r+n-1)th=1;
		for(auto t:X)if(t==i)th=1;
		if(th==0)Y.push_back(i);
	}
	string ans="";
	rep(i,2*n){
		bool res=solve(i);
		if(res)ans+="R";
		else ans+="B";
	}
	cout<<"! "<<ans<<"\n"<<flush;
	
	
}


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

int main(){
    long long ans = 0;
    int n, a;
    scanf("%d", &n);
    int mn = 1e9;
    priority_queue<int> pq;
    for(int i=1;i<=n;i++){
        scanf("%d", &a);
        if(a > 0){
            ans += a;
            mn = min(mn, a);
        }
        else pq.push(-a);
    }
    if(pq.size()%2 == 0){
        while(!pq.empty()){
            int u = pq.top();
            pq.pop();
            ans += u;
        }
    }
    else{
        int last = 0;
        while(!pq.empty()){
            int u = pq.top();
            pq.pop();
            ans += u;
            last = u;
        }
        ans -= last;
        ans = max(ans+last-2*mn, ans-last);
    }

    printf("%lld\n", ans);
}

Measured memory_bytes: 892
#include <iostream>
#include <vector>
#include <string>
#include <cmath>
#include <utility>
#include <algorithm>
using namespace std;


int main(){
    
    int n, d;
    cin>>n>>d;
    
    vector<vector<int>> v(n, vector<int>(d));
    
    for(int i=0; i<n; i++){
        for(int j=0; j<d; j++){
            cin>>v[i][j];
        }
    }
    
    int cnt=0;
    for(int i=0; i<n-1; i++){
        for(int j=i+1; j<n; j++){
            long long int temp=0;
            
            for(int k=0; k<d; k++){
                temp+=(v[i][k]-v[j][k])*(v[i][k]-v[j][k]);
            }
            
            if(sqrt(temp)-int(sqrt(temp))<1e-6){
                cnt++;
            }
        }
    }
    
    cout<<cnt<<endl;
    
}


Measured memory_bytes: 256
import java.util.*;
 
public class Main{
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int q = sc.nextInt();
        char[] qc = sc.next().toCharArray();
        int data[] = new int[n+1];
        for(int i = 1;i<n;i++){
            data[i] = data[i-1];
            if(qc[i] == 'C'){
                if(qc[i-1] == 'A'){
                    data[i] = data[i-1] + 1;
                }
            }
        }
        int l[] = new int[q];
        int r[] = new int[q];
        for(int i = 0;i<q;i++){
            l[i] = Integer.parseInt(sc.next());
            r[i] = Integer.parseInt(sc.next());
        }
        for(int i = 0;i<q;i++){
            System.out.println(data[r[i]-1] - data[l[i]-1]);
        }
    }
}

Measured memory_bytes: 62748
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define zero_pad(num) setfill('0') << std::right << setw(num)
using namespace std;
using ll = long long;
using ld = long double;
using P = pair<int, int>;

struct UnionFind {
    vector<int> d;
    // コンストラクタ　親は-頂点数を保管
    UnionFind(int N) : d(N, -1) {}

    int find(int x) {
        if (d[x] < 0) {
            return x;
        }
        return d[x] = find(d[x]);
    }

    bool unite(int x, int y) {
        x = find(x);
        y = find(y);
        if (x == y) {
            return false;
        }
        if (d[x] > d[y]) {
            swap(x, y);
        }
        d[x] += d[y];
        d[y] = x;
        return true;
    }

    bool same(int x, int y) {
        return find(x) == find(y);
    }

    int size(int x) {
        return -d[find(x)];
    }
};

int main() {
    int n, m;
    cin >> n >> m;
    UnionFind uf(n);
    rep(i, m){
        int x, y, z;
        cin >> x >> y >> z;
        x--;
        y--;
        uf.unite(x, y);
    }

    int ans = 0;
    rep(i, n)if(uf.find(i) == i)ans++;
    cout << ans << endl;
}

Measured memory_bytes: 640
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#pragma GCC optimize("unroll-loops")
#pragma warning(disable : 4996)
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<queue>
#include<map>
#include<math.h>
#include<iomanip>
#include<set>
#include<numeric>
#include<cstring>
#include<cstdio>
#include<functional>
#include<bitset>
#include<limits.h>
#include<cassert>
#include<iterator>
#include<complex>
#include<stack>
#include<unordered_map>
#include<unordered_set>
#include<time.h>
#include<random>
#include<array>


using namespace std;

#define REP(i, n) for(int i = 0;i < n;++i)
#define REPR(i, n) for(int i = n-1;i >= 0;--i)
#define FOR(i, m, n) for(int i = m;i < n;++i)
#define FORR(i, m, n) for(int i = m-1;i >= n;--i)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define REVERSE(v,n) reverse(v,v+n);
#define VREVERSE(v) reverse(v.begin(), v.end())
#define ll long long
#define print(x) cout<<(x)<<'\n'
#define pe(x) cout<<(x)<<" "
#define DEBUG(x) cout<<#x<<": "<<x<<endl
#define lb(v,n) lower_bound(v.begin(), v.end(), (n))
#define ub(v,n) upper_bound(v.begin(), v.end(), (n))
//#define int long long
//#define double long double
#define all(x) (x).begin(), (x).end()
#define print_space(v) REP(i,v.size())cout << v[i] << ((i == v.size() - 1) ? "\n" : " ")
template<typename T1, typename T2> inline void chmin(T1 & a, T2 b) { if (a > b) a = b; }
template<typename T1, typename T2> inline void chmax(T1& a, T2 b) { if (a < b) a = b; }
typedef pair<int, int>P;
std::random_device rd;
std::mt19937 mt(rd());
constexpr int MOD = 1e9 + 7; constexpr int MAX = 200020;
const double pi = acos(-1); constexpr double EPS = 1e-8;
constexpr ll INF = 1e16;
typedef array<int, 3>arr3;


bool dp[4005000];
int cum[2020];
void solve() {
	int N; cin >> N;
	vector<int>A(N);
	REP(i, N) {
		cin >> A[i];
		cum[i + 1] = cum[i] + A[i];
	}
	int mid = (cum[N] + 1) / 2;
	dp[0] = true;

	REP(i, N) {
		int mn = min(mid, cum[i]+1);
		REPR(j, mn) {
			dp[j + A[i]] |= dp[j];
		}
	}
	FOR(i, mid, cum[N] + 1) {
		if (dp[i]) {
			print(i); return;
		}
	}
}

signed main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	//int q; cin >> q;
	//while (q--)
		solve();
}



Measured memory_bytes: 2304
#include "bits/stdc++.h"

using namespace std;
using ll = long long;
using ull = unsigned long long;

typedef pair< long long, long long > P;
typedef pair< long long, P > PP;
typedef pair< P, P > PPP;

const double DINF = 5e14, eps = 1e-10;
const long long MOD = 1e9 + 7, INF = 5e18;
const int di[4] = { 1,0,-1,0 }, dj[4] = { 0,1,0,-1 };

#define fr first
#define sc second
#define pb push_back
#define eb emplace_back
#define ALL(x) (x).begin(),(x).end()

int n, x, a[110], ans;

int main() {
	cin >> n >> x;
	for (int i = 0;i < n;i++)cin >> a[i];
	sort(a, a + n);
	for (int i = 0;i < n;i++) {
		if (i == n - 1 && x != a[i])break;
		if (x >= a[i])ans++, x -= a[i];
		else break;
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 256
#include<map>
#include<set>
#include<cmath>
#include<stack>
#include<queue>
#include<deque>
#include<ctime>
#include<vector>
#include<bitset>
#include<string>
#include<cstdio>
#include<numeric>
#include<utility>
#include<sstream>
#include<cstdlib>
#include<iomanip>
#include<cstring>
#include<iostream>
#include<algorithm>
#include<functional>
#include<unordered_map>
#define _USE_MATH_DEFINES
#define inf 999999999999999999
#define rep(i,n,m) for(lli i=(lli)(n);i<(lli)(m);++i)
#define reep(i,n,m) for(int i=(int)(n);i<=(int)(m);++i)
#define per(i,m,n) for(lli i=(int)(m)-1;i>=(int)(n);--i)
#define st(n) sort(n.begin(), n.end())
#define rev(n) reverse(n.begin(),n.end())
#define ou(S) cout << S << endl
#define pb(n) push_back(n)
#define ue(N) N.erase(unique(N.begin(),N.end()),N.end());
#define nou(S) cout << S
#define hou(S) cout << setprecision(30) << S << endl
#define vec(K,L,N,S) vector<L> K(N,S)
#define dv(K,L,N,M,S) vector<vector<L>> K(N,vector<L>(M,S))
#define tv(K,L,N,M,R,S) vector<vector<vector<L>>> K(N,vector<vector<L>>(M,vector<L>(R,S)))
#define pint pair<lli,lli>
#define paf(L,R) pair<L,R>
#define maxx 5100000
#define chmax(a, b) a = (((a)<(b)) ? (b) : (a))
#define chmin(a, b) a = (((a)>(b)) ? (b) : (a))
#define endl "\n"
typedef long long int lli;
typedef unsigned long long int uli;
const uli mod = 1e9 + 7;
using namespace std;
int main() {
    ios::sync_with_stdio(false);
    cin.tie(NULL);

    int d,ma=-1000000,num=0;
    cin >> d;
    vector<int> c(26);
    vector<vector<int>> s(d, vector<int>(26, 0));
    for(int i = 0; i < 26; ++i) {
        cin >> c[i];
    }
    for(int i = 0; i < d; ++i) {
        for(int j = 0; j < 26; ++j) {
            cin >> s[i][j];
        }
    }
    for(int i = 0; i < d; ++i) {
        for(int j = 0; j < 26; ++j) {
            if(ma < s[i][j]) {
                ma = s[i][j];
                num = j+1;
            }
        }
        cout << num << endl;
        num = 0;
        ma = -100000;
    }
}

Measured memory_bytes: 3708
import java.util.*;
class Main
{
    static int MOD = 1000000007;
    public static void main (String[] args)
    {
        Scanner sc = new Scanner(System.in);
        int h = sc.nextInt(), w = sc.nextInt(), ans = 0, x;
        int[][] c = new int[10][10];
        for(int i = 0; i < 10; i++)
            for(int j = 0; j < 10; j++)
                c[i][j] = sc.nextInt();
        for(int k = 0; k < 10; k++)
            for(int i = 0; i < 10; i++)
                for(int j = 0; j < 10; j++)
                    c[i][j] = Math.min(c[i][j], c[i][k] + c[k][j]);
        for(int i = 0; i < h; i++)
            for(int j = 0; j < w; j++)
                if((x = sc.nextInt())!= -1) ans += c[x][1];
        System.out.println(ans);
    }
}

Measured memory_bytes: 46324
package main

import (
	"bufio"
	"fmt"
	"io"
	"os"
	"strconv"
)

var (
	readString func() string
	readBytes  func() []byte
)

func init() {
	readString, readBytes = newReadString(os.Stdin)
}

func newReadString(ior io.Reader) (func() string, func() []byte) {
	r := bufio.NewScanner(ior)
	r.Buffer(make([]byte, 1024), int(1e+11))
	r.Split(bufio.ScanWords)

	f1 := func() string {
		if !r.Scan() {
			panic("Scan failed")
		}
		return r.Text()
	}
	f2 := func() []byte {
		if !r.Scan() {
			panic("Scan failed")
		}
		return r.Bytes()
	}
	return f1, f2
}

func readInt() int {
	return int(readInt64())
}

func readInt64() int64 {
	i, err := strconv.ParseInt(readString(), 10, 64)
	if err != nil {
		panic(err.Error())
	}
	return i
}

func readFloat64() float64 {
	f, err := strconv.ParseFloat(readString(), 64)
	if err != nil {
		panic(err.Error())
	}
	return f
}

func min(a, b int) int {
	if a < b {
		return a
	}
	return b
}

func max(a, b int) int {
	if a > b {
		return a
	}
	return b
}

func minInt64(a, b int64) int64 {
	if a < b {
		return a
	}
	return b
}

func maxInt64(a, b int64) int64 {
	if a > b {
		return a
	}
	return b
}

func abs(a int) int {
	if a < 0 {
		return -a
	}
	return a
}

func absInt64(a int64) int64 {
	if a < 0 {
		return -a
	}
	return a
}

func sum(a []int) int {
	var ret int
	for i := range a {
		ret += a[i]
	}
	return ret
}

func sumInt64(a []int64) int64 {
	var ret int64
	for i := range a {
		ret += a[i]
	}
	return ret
}

func sumFloat64(a []float64) float64 {
	var ret float64
	for i := range a {
		ret += a[i]
	}
	return ret
}

func gcdInt64(m, n int64) int64 {
	for m%n != 0 {
		m, n = n, m%n
	}
	return n
}

func lcmInt64(m, n int64) int64 {
	return m / gcdInt64(m, n) * n
}

// sort ------------------------------------------------------------

type int64Array []int64

func (s int64Array) Len() int           { return len(s) }
func (s int64Array) Swap(i, j int)      { s[i], s[j] = s[j], s[i] }
func (s int64Array) Less(i, j int) bool { return s[i] < s[j] }

type xxx struct {
	x int
}

type sortArray []xxx

func (s sortArray) Len() int           { return len(s) }
func (s sortArray) Swap(i, j int)      { s[i], s[j] = s[j], s[i] }
func (s sortArray) Less(i, j int) bool { return s[i].x < s[j].x }

// -----------------------------------------------------------------

var mod int64 = 1e9 + 7

func main() {
	n := readInt()
	k := readInt()
	dp := make([][]int64, n+1)
	for i := range dp {
		dp[i] = make([]int64, n+1)
		dp[i][0] = 1
	}

	for i := 1; i < n+1; i++ {
		for j := 1; j < n+1; j++ {
			if j > i {
				break
			}
			dp[i][j] = (dp[i-1][j] + dp[i-1][j-1]) % mod
		}
	}
	for i := 1; i <= k; i++ {
		ans := dp[n-k+1][i] * dp[k-1][i-1]
		fmt.Println(ans % mod)
	}
}


Measured memory_bytes: 21632
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
#pragma GCC target("sse2")
 
 
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
 
 
typedef tree<int,null_type,less_equal<int>,rb_tree_tag,tree_order_statistics_node_update>ordered_set;
 
#define int         long long
#define ll          long long
#define pb          push_back
#define pii         pair<int,int>
#define vi          vector<int>
#define vii         vector<pii>
#define mi          map<int,int>
#define mii         map<pii,int>
#define mp          make_pair
#define all(a)      (a).begin(),(a).end()
#define FF           first
#define SS           second
#define sz(x)       (int)x.size()
#define endl        '\n'
//#define hell          1000000007
#define rep(i,a,b)  for(int i=a;i<b;i++)
// mp::cpp_int
 
const int hell=1000000007;
 
 
int pw(int a,int b)
{
  int x=a;
  rep(i,1,b){a=a*x;
    a%=10000000000LL;}
  return a;
}
 
 ll power(ll a,ll b)
{
  if(b==0)return 1;
  if(b==1)return a%hell;
  ll t=power(a,b/2);
  t*=t;
  t%=hell;
   if(b&1)
   {
       t*=a;
       t%=hell;
   }
   return t;
 
}

int inverse(int a)
{
  return power(a,hell-2);
}
 
int gcd(int a,int b)
{   
  
  if(b==0)return a;
  return gcd(b-a%b,a%b);
}
 
bool cmp(pii a,pii b)
{
  return a.SS<b.SS;
}
 
 
int sum(int a,int b )
{
   int ans=a-a/b; 
   return ans;
}


 
int solve()
{  
 
 int l,r;
 cin>>l>>r;
 if(r-l>=2019)
 {
  cout<<0;
  return 0;
 }
 else
 { int x=2019;
  int ans=hell;
  rep(i,l,r+1)
  {
    rep(j,i+1,r+1)
    {
      ans=min(ans,(i*j)%x);
    }
  }
  cout<<ans;
 }


 return 0;
}
 
 
signed main()
{  int t=1;
//pri();
 ios::sync_with_stdio(false);
   cin.tie(0);
   cout.tie(0);
  
   cin.exceptions(cin.failbit);                                                                    

 

  clock_t time_req;
 
    // Without ung pow function
                                                                                                                   
 //cin>>t;
 
    int k=1;
     
   while(t--)
     {
      //cout<<"Case #"<<k<<":"<<" ";k++;
      solve();
     }
        exit(0);
 
         time_req = clock() - time_req;
    cout <<endl<< "Processor time taken is "
      << (double)time_req/CLOCKS_PER_SEC << " seconds" << endl;
 
 
    return 0;
}

Measured memory_bytes: 256
s=input()
t=''
i=0
while i<len(s):
  if s[i]=='A':
    t+='A'
    i+=1
  elif s[i]=='B':
    if i!=len(s)-1:
      if s[i+1]=='C':
        t+='B'
        i+=2
      else:
        t+='X'
        i+=1
    else:
      i+=1
  else:
    t+='X'
    i+=1
b=0
x=0
for i in range(len(t))[::-1]:
  if t[i]=='B':
    b+=1
  elif t[i]=='A':
    x+=b
  else:
    b=0
print(x)

Measured memory_bytes: 3500
#include <bits/stdc++.h>
#include <math.h>
#define rep(i, n) for(int i = 0; i < (n); i++)
#define rrep(i, n) for(int i = 0; i <= (n); i++)
using namespace std;
typedef long long ll;
const int MOD = 1000000007;
const ll INF = 1LL<<60;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
using Graph = vector<vector<int>>;


int main(){
    int K; cin >> K;
    string S; cin >> S;

    if (S.size() > K){
        string ans;
        rep(i,K){
            ans += S[i];
        }
        cout << ans + "..." << endl;
    }
    else{
        cout << S << endl;
    }
}

Measured memory_bytes: 3600
# -*- coding: utf-8 -*-
#ABC073C

def checkstr(sd,t,i):
	#sdのi文字目以降がtと等しいかチェック

	for j in range(0,len(t)):
		if(sd[j+i]!=t[j])and(sd[j+i]!='?'):
			return -1
	return i

sd = input()
t = input()

j=-1
for i in range(0,len(sd)-len(t)+1):
#	print(len(sd))
#	print(len(t))
#	print(len(sd)-len(t)-i)
	ret = checkstr(sd,t,len(sd)-len(t)-i)
	if(ret>=0):
		j=len(sd)-len(t)-i
		break

str_list = list(sd)
for i in range(0,len(sd)):
	if(str_list[i]=='?'):
		str_list[i]='a'
if(j!=-1):
	for i in range(0,len(t)):
		str_list[j+i]=t[i]

	sd_res = "".join(str_list)
	print(sd_res)
else:
	print("UNRESTORABLE")



Measured memory_bytes: 3064
n = int(input())
suits = [0] * n
ranks = [0] * n
orders = [0] * n
for i in range(n):
    suit, rank = input().split()
    suits[i] = suit
    ranks[i] = int(rank)
    orders[i] = i

def quicksort(p, r):
    if p < r:
        q = partition(p, r)
        quicksort(p, q-1)
        quicksort(q+1, r)

def partition(p, r):
    global suits, ranks, orders
    x = ranks[r]
    i = p - 1
    for j in range(p, r):
        if ranks[j] <= x:
            i += 1
            suits[i], suits[j] = suits[j], suits[i]
            ranks[i], ranks[j] = ranks[j], ranks[i]
            orders[i], orders[j] = orders[j], orders[i]
    i += 1
    suits[i], suits[r] = suits[r], suits[i]
    ranks[i], ranks[r] = ranks[r], ranks[i]
    orders[i], orders[r] = orders[r], orders[i]
    return i

quicksort(0, n-1)

for i in range(1, n):
    if ranks[i] == ranks[i-1] and orders[i] < orders[i-1]:
        print('Not stable')
        break
else:
    print('Stable')

for i in range(n):
    print(suits[i], ranks[i])



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

int main(){
    int a, b;
    cin >> a >> b;

    if(b < 0){
        if((b-a+1) % 2 == 0) cout << "Positive" << endl;
        else cout << "Negative" << endl;
    }
    else if(a > 0) cout << "Positive" << endl;
    else cout << "Zero" << endl;
    return 0;
}

Measured memory_bytes: 3576
'use strict';
(function(stdin) {
  //declare function
  var square = function(array) {
    var sharp = [];
    for (var i = 0, high = array[0]; i < high; i++) {
      var line = [];
      for (var j = 0, width = array[1]; j < width; j++) {
        line.push('#');
      }
      sharp[i] = line.join('');
    }
    return sharp.join('\n');
  };
  //declare variaable
  var inputs = stdin.toString().trim().split('\n');
  var wAndH = inputs.map(function(v) {
    return v.split(' ').map(Number);
  });
  var result = [];
  //main
  for (var k = 0, len = inputs.length; k < len; k++) {
    if (wAndH[k][0] === 0) {
      break;
    }
    if (wAndH[k][1] === 0) {
      break;
    }
    result.push(square(wAndH[k]));
  }
  //display
  console.log(result.join('\n\n')+'\n');
})(require('fs').readFileSync('/dev/stdin', 'utf8'));

Measured memory_bytes: 17204
from collections import deque
N = int(input())
Q = deque()

for _ in range(N):
    order = list(map(int,input().split()))
    if order[0] == 0:
        if order[1] == 0:
            Q.appendleft(order[2])
        else:
            Q.append(order[2])
    elif order[0] == 1:
        print(Q[order[1]])
    else:
        if order[1] == 0:
            Q.popleft()
        else:
            Q.pop()



Measured memory_bytes: 21980
require "set"

s = gets.to_s.chomp.bytes
x, y = gets.to_s.split.map{|t| t.to_i }

# p "FT".bytes # => [70, 84]
state = 0
yoko = []
tate = []
tmp = 0
s.each do |c|
  
  if c == 70
    tmp += 1
  else
    if state == 0
      yoko << tmp
    else
      tate << tmp
    end
    tmp = 0
    state = 1 - state
  end
end

if state == 0
  yoko << tmp
else
  tate << tmp
end

sx = sy = 0
if s[0] == 70
  sx = yoko.shift
end

yoko.sort!
tate.sort!

# yoko

hx = { sx => true }
# sx = Set[sx]
yoko.each do |d|
  t = {}
  hx.each do |k, v|
    t[k+d] = t[k-d] = true
  end
  hx.clear
  hx = t
end

hy = { sy => true }
sy
tate.each do |d|
  t = {}
  hy.each do |k, v|
    t[k+d] = t[k-d] = true
  end
  hy.clear
  hy = t
end

puts ( hx[x] && hy[y] ) ? "Yes" : "No"

Measured memory_bytes: 10360
#include <stdio.h>
#include <stdlib.h>

int main()
{
    int a,b,c;
    scanf ("%d %d",&a,&b);
	if(a<1||a>9||b<1||b>9)
    {
      printf("-1\n");
    }
    else
    {
      c=a*b;
      printf("%d",c);
    }
  return 0;
}


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

void out_grade(double M_500_time,double M_1000_time){
  if(M_500_time<35.50&&M_1000_time<71.0)cout<<"AAA"<<endl;
  else if(M_500_time<37.50&&M_1000_time<77.00)cout<<"AA"<<endl;
  else if(M_500_time<40.00&&M_1000_time<83.00)cout<<"A"<<endl;
  else if(M_500_time<43.00&&M_1000_time<89.00)cout<<"B"<<endl;
  else if(M_500_time<50.00&&M_1000_time<105.00)cout<<"C"<<endl;
  else if(M_500_time<55.00&&M_1000_time<116.00)cout<<"D"<<endl;
  else if(M_500_time<70.00&&M_1000_time<148.00)cout<<"E"<<endl;
  else cout<<"NA"<<endl;
}

int main(){
  double M_500_time,M_1000_time;
  while(cin>>M_500_time>>M_1000_time){
    out_grade(M_500_time,M_1000_time);
  }
}

Measured memory_bytes: 3140
board = []
ans = []
H, W = list(map(int, input().split()))

def get_mine_number(j, i):
    mine_num = 0
    for deltaj in [-1, 0, 1]:
        for deltai in [-1, 0, 1]:
            if not -1 < j + deltaj < H or not -1 < i + deltai < W:
                continue
            if deltaj == 0 and deltai == 0:
                continue
            if board[j+deltaj][i+deltai] == "#":
                mine_num += 1
    return str(mine_num)
        
        
    

def main():
    for i in range(H):
        board.append(input())
    for jind, line in enumerate(board):
        ansline = ""
        for iind, point in enumerate(line):
            if point == ".":
                ansline += get_mine_number(jind, iind)
            else:
                ansline += point
        ans.append(ansline)
    for l in ans:
        print(l)
    
main()

Measured memory_bytes: 3064
import Data.List
main = do
  [_,m] <- map (read::String->Int) . words <$> getLine
  items <- map (read::String->Int) . words <$> getLine
  let selectableitems = map (selectable items m) items
  putStrLn $ if m<=(length . filter (==True)) selectableitems then "Yes" else "No"

selectable items m item = if item*4*m < sum items then False else True

Measured memory_bytes: 4316
import java.util.*;

public class Main {
    private static Scanner scanner;

    public static int[] inputIntArray(int n) {
        int[] res = new int[n];
        for (int i = 0; i < n; ++i) {
            res[i] = scanner.nextInt();
        }

        return res;
    }

    // public static String[] <T> ToStringArray(T[] arr) {
    // String[] res = new String[arr.length];
    // for(int i = 0; i < arr.length; ++i) {
    // res[i] = String.valueOf(arr[i]);
    // }

    // return res;
    // }

    private static List<Integer> asIntergerList(int[] arr) {
        List<Integer> intList = new ArrayList<Integer>();
        for (int i = 0; i < arr.length; i++) {
            intList.add(arr[i]);
        }

        return intList;
    }

    private static int[][] deepCopy(int[][] arr) {
        int[][] res = new int[arr.length][];
        for (int i = 0; i < arr.length; ++i) {
            res[i] = arr[i].clone();
        }

        return res;
    }

    private static String asString(int[][] arr) {
        String str = new String();

        for (int i = 0; i < 2; ++i) {
            str += "" + arr[i][0] + arr[i][1] + arr[i][2] + arr[i][3];
        }

        return str;
    }

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

        while (true) {
            int n, r;

            n = scanner.nextInt();
            r = scanner.nextInt();

            if (n == 0 && r == 0) {
                return;
            }

            int[] arr = new int[n];

            for (int i = 0; i < n; ++i) {
                arr[i] = n - i;
            }

            for (int i = 0; i < r; ++i) {
                int p, c;

                p = scanner.nextInt();
                c = scanner.nextInt();
                --p;

                int[] newArr = new int[n];
                int index = 0;

                int[] e = Arrays.copyOfRange(arr, p, p + c);
                for (int j = 0; j < e.length; ++j) {
                    newArr[index] = e[j];
                    ++index;
                }

                e = Arrays.copyOfRange(arr, 0, p);
                for (int j = 0; j < e.length; ++j) {
                    newArr[index] = e[j];
                    ++index;
                }

                e = Arrays.copyOfRange(arr, p + c, arr.length);
                for (int j = 0; j < e.length; ++j) {
                    newArr[index] = e[j];
                    ++index;
                }

                arr = newArr;
            }

            System.out.println(arr[0]);
        }
    }

}



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

const ll MAX = 200000;
const ll INF = 1001001001;
const ll MOD = 1000000007;
const double PI=3.1415926535897932;

ll N, K, ans=0, tmp=0;
vector<ll> P;
vector<pair<ll,ll>> PS;
vector<vector<pair<ll,ll>>> G;
set<ll> ST;
string S;

void dijkstra() {
    priority_queue<pair<ll,ll>, vector<pair<ll,ll>>, greater<pair<ll,ll>>> PQ;
    PQ.push(make_pair(0, N));
    while(!PQ.empty()) {
        pair<ll,ll> pp = PQ.top();
        PQ.pop();
        if(P[pp.second]<=pp.first) continue;
        P[pp.second] = pp.first;
        for(int i=0;i<G[pp.second].size();i++) {
            if(P[G[pp.second][i].first]>P[pp.second]+G[pp.second][i].second) PQ.push(make_pair(P[pp.second]+G[pp.second][i].second, G[pp.second][i].first));
        }
    }
}

signed main(){
    cin >> N;
    G.resize(N+1);
    P.resize(N+1, INF);
    for(int i=0;i<N-1;i++) {
        ll a, b;
        cin >> a >> b;
        a--;
        b--;
        G[a].push_back(make_pair(b, 1));
        G[b].push_back(make_pair(a, 1));
    }
    cin >> K;
    for(int i=0;i<K;i++) {
        ll v, p;
        cin >> v >> p;
        v--;
        G[N].push_back(make_pair(v, p));
        PS.push_back(make_pair(v, p));
    }
    dijkstra();
    for(int i=0;i<K;i++) {
        P[PS[i].first] = PS[i].second;
    }
    /*
    for(int i=0;i<N;i++) {
        cout << i << " " << P[i] << endl;
    }
    */
    for(int i=0;i<N;i++) {
        for(int j=0;j<G[i].size();j++) {
            if(abs(P[i]-P[G[i][j].first])!=1) {
                cout << "No" << endl;
                return 0;
            }
        }
    }
    cout << "Yes" << endl;
    for(int i=0;i<N;i++) {
        cout << P[i] << endl;
    }
    return 0;
}

Measured memory_bytes: 17816
import java.io.InputStream;
import java.io.PrintStream;
import java.nio.charset.StandardCharsets;
import java.util.Scanner;

public class Main {

  public static void main(String[] args) {
    resolve(System.in, System.out);
  }

  static void resolve(InputStream is, PrintStream pw) {
    Scanner sc = new Scanner(is);
    String s = sc.next();
    char c = s.charAt(0);
    pw.println(new String(new byte[]{(byte) (c + 1)}, StandardCharsets.UTF_8));
  }
}


Measured memory_bytes: 22608
#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=a;i<b;i++)
#define rrep(i,a,b) for(int i=a;i>=b;i--)
#define fore(i,a) for(auto &i:a)
#define all(x) (x).begin(),(x).end()
//#pragma GCC optimize ("-O3")
using namespace std;

int main() {
  
  int a,b,c,d,x;
  string s,ss,sss;
  
  int ans = 0;
  string anss = "";
  
  cin >> a >> b >> c;
  
  int ab [] = {0 , 1 , 3 , 1 , 2 , 1 , 2 , 1 , 1 , 2 , 1 , 2 , 1};
  int result3 = std::max({a, b, c});
//--------------------------------------------------------------------------------

  if(a==b) ans = c;
  else if(a==c) ans = b;
  else ans = a;
  
  cout << ans << endl;

}

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

int main(){
  int a1,a2,b,num;
  while(cin>>a1>>a2>>b){
    num=0;
    for(int i=0;i<10;i++)
      if(a1!=i && a2!=i && b!=i)
	if(a1+a2+i<=20)num++;
    if(num>4)cout<<"YES"<<endl;
    else cout<<"NO"<<endl;
  }
  return 0;
}

Measured memory_bytes: 1152
import sys
n,m,k=map(int,input().split())
a = [int(i) for i in input().split()]
b = [int(i) for i in input().split()]

ans = 1
c = [0]
d = [0]
for i in range(1,n+1):
    c.append(c[i-1] + a[i-1])
    if(c[i] > k):
        c.pop()
        break
for i in range(1,m+1):
    d.append(d[i-1] + b[i-1])
    if(d[i] > k):
        d.pop()
        break


leng = len(c)
lend = len(d)
ans = leng - 1
temp = 0
for i in range(leng):
    p = c[leng-i-1]
    t = temp
    while(t < lend and p+d[t] <= k):
        t += 1
        if(t==lend):
            print(max(ans,leng-i-2+t))
            sys.exit()
    ans = max(ans,leng-i-2+t)
    temp = t

print(ans)

Measured memory_bytes: 120600
#include <cstdio>
#include <cstring>
#include <string>
#include <cmath>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <algorithm>
#define INF 100000000000000000.0
using namespace std;
struct edge {
	int to;
	double cost;
};
typedef pair<double, int> P;

int main()
{
	int n;
	long long int xs, ys, xt, yt;
	scanf("%lld %lld %lld %lld", &xs, &ys, &xt, &yt);
	scanf("%d", &n);
	long long int x[1002], y[1002], r[1002];
	x[0]=xs, y[0]=ys, x[n+1]=xt, y[n+1]=yt, r[0]=0, r[n+1]=0;
	for(int i=1; i<=n; i++){
		scanf("%lld %lld %lld", &x[i], &y[i], &r[i]);
	}
	vector<edge> e[1002];
	for(int i=1; i<=n+1; i++){
		for(int j=0; j<i; j++){
			edge e1;
			e1.cost=sqrt((double)((x[i]-x[j])*(x[i]-x[j])+(y[i]-y[j])*(y[i]-y[j])))-(double)r[i]-(double)r[j];
			if(e1.cost<0) e1.cost=0;
			e1.to=j;
			e[i].push_back(e1);
			e1.to=i;
			e[j].push_back(e1);
		}
	}
	priority_queue<P, vector<P>, greater<P> > que;
	double d[1002];
	fill(d, d+n+2, INF);
	d[0]=0;
	que.push(P(0, 0));
	while(!que.empty()){
		P p=que.top();
		que.pop();
		int v=p.second;
		if(d[v]<p.first) continue;
		for(int i=0; i<e[v].size(); i++){
			edge e1=e[v][i];
			if(d[e1.to]>d[v]+e1.cost){
				d[e1.to]=d[v]+e1.cost;
				que.push(P(d[e1.to], e1.to));
			}
		}
	}
	printf("%.10lf\n", d[n+1]);
	return 0;
}

Measured memory_bytes: 22128
import numpy as np
N, C = map(int, input().split())
XV = [list(map(int, input().split())) for i in range(N)]
# V_minus_X = [a[1]-a[0] for a in XV]

V_minus_X = [XV[i][1]-(XV[i][0]-XV[i-1][0])
             for i in range(1, N)]  # i==0なら見ない それ以外ならXV[i-1][0]足して上げる
V_minus_X.insert(0, XV[0][1]-XV[0][0])
cum_ = np.cumsum(V_minus_X)


V_minus_X_reverse = [XV[i][1]-(XV[i+1][0]-XV[i][0])
                     for i in range(0, N-1)]
V_minus_X_reverse.append(XV[-1][1]-(C-XV[-1][0]))
V_minus_X_reverse.reverse()
cum_reverse = np.cumsum(V_minus_X_reverse)
#print("cum", cum_)
m_ = []
m_reverse = []
maxim = 0
maxim_reverse = 0
maxim_where = 0
maxim_reverse_where = 0
# print("print")
for i in range(N-1):
    if maxim < cum_[i]:
        maxim = cum_[i]
        maxim_where = XV[i][0]
    if maxim_reverse < cum_reverse[i]:
        maxim_reverse = cum_reverse[i]
        maxim_reverse_where = C - XV[-i - 1][0]
    m_.append((maxim, maxim_where))
    m_reverse.append((maxim_reverse, maxim_reverse_where))

ans = 0
# print("print")
for i in range(N - 1):
    next = m_[i][0] + m_reverse[-i - 1][0] - \
        min(m_[i][1], m_reverse[-i - 1][1])
    # print(next)
    # print(cum_[i], m_reverse[-i - 1][0], min(XV[i][0], m_reverse[-i - 1][1]))
    ans = max(next, ans)

# print(m_reverse)
print(max(ans, max(cum_), max(cum_reverse)))


Measured memory_bytes: 65176