akhauriyash/Code-Regression huggingface dataset:
# ABC165 C

import itertools

def main():
    n, m, q = map(int, input().split())
    List = []
    for i in range(q):
        a, b, c, d = map(int, input().split())
        List.append([a, b, c, d])
    
    max_total = 0

    for A in list(itertools.combinations_with_replacement(range(1, m+1),n)):
        total = 0
        for abcd in List:
            if A[abcd[1]-1] - A[abcd[0]-1] == abcd[2]:
                total += abcd[3]
        #print(total)
        if total >= max_total:
            max_total = total
    
    print(max_total)

if __name__ == '__main__':
    main()

Measured memory_bytes: 21624
#include<iostream>
#include<algorithm>
using namespace std;
int main(){
	int a,b,c,i,sum,tf=0;
	cin>>a>>b>>c;
	sum=a;
	for(i=0;i<10000;i++){
		if(sum%b==c){
			tf=1;
			break;
		}
		sum+=a;
	}
	if(tf==0)cout<<"NO"<<endl;
	else cout<<"YES"<<endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <set>
#include <map>
#include <vector>
#include <algorithm>
#include <iomanip>
#include <climits>
#include <numeric>
#include <cmath>
#include <queue>
#include <sstream>
#include <string.h>
#include <bitset>

using namespace std;
typedef long long ll;

int main() {
  int n, q;
  cin >> n >> q;
  vector<tuple<int, int, int>> e(n);
  for (int i = 0; i < n; i++) {
    cin >> get<1>(e[i]) >> get<2>(e[i]) >> get<0>(e[i]);
  }
  sort(e.begin(), e.end());
  
  set<pair<int, int>> s;
  for (int i = 0; i < q; i++) {
    int x;
    cin >> x;
    s.insert({x, i});
  }
  
  vector<ll> l(q, -1);
  for (int i = 0; i < n; i++) {
    auto start = s.lower_bound({get<1>(e[i]) - get<0>(e[i]), 0});
    auto end = s.lower_bound({get<2>(e[i]) - get<0>(e[i]) - 1, q});
    
    for (auto it = start; it != end; it++) {
      l[it->second] = get<0>(e[i]);
    }
    s.erase(start, end);
  }
  for (int i = 0; i < q; i++) {
    cout << l[i] << endl;
  }
  return 0;
}


Measured memory_bytes: 15232
def sim(s, to)
  ss = s

  res = 0
  while ss.chars.uniq.size > 1
    new_ss = ""
    (0...(ss.size-1)).each do |i|
      if ss[i] == to || ss[i+1] == to
        new_ss << to
      else
        new_ss << ss[i]
      end
    end
    ss = new_ss
    res += 1
  end
  
  res
end

s = gets.chomp
ans = 100000
s.chars.uniq.each do |c|
  ans = [ans, sim(s, c)].min
end
puts ans

Measured memory_bytes: 1788
#include <bits/stdc++.h>
#include <cstdlib>
using namespace std;
#define ll long long
#define MAX 100005
#define pb push_back
#pragma comment(linker, "/stack:200000000")
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
const double PI  =3.141592653589793238463;
long long MOD = 1000000007;
vector<int>adj[100005];
int stringToInteger(string x){
    int gg=0;
    stringstream geek(x);
    geek >> gg;
    return gg;
}

ll powmod(ll a,ll b,ll m)
{
    ll ans=1;
    while(b>0){ if(b%2)
        {ans*=a; ans%=m;}
         b/=2; a=a*a; a=a%m;
        }
        return ans%m;
}
ll gcd(ll a,ll b)
{

    return __gcd(a,b);
}
ll mulmod(ll a,ll b,ll m)
{  ll ans=0;
    a %=m;
    while (b>0)
    {       if(b&1) ans = (ans + a) % m;
        a = (a * 2)%m;
        b /= 2;
    }
    return ans % m;
}

ll pow(ll a, ll b, ll MOD)
{
 ll x=1,y=a;
 while(b > 0)
 	{
 		if(b%2 == 1)
 	{
 		x=(x*y);
 		if(x>MOD) x%=MOD;
 	}
 	y = (y*y);
 	if(y>MOD) y%=MOD;
 	b /= 2;
 	}
 return x;
}

int main()
{
    string s;
    cin>>s;
    stack<char>st;
    ll ans=0;
    st.push(s[0]);
    int n=s.length();
    for(int i=1;i<n;i++)
    {
        if(!st.empty()&&s[i]!=st.top())
        { st.pop(); ans+=2;
        }
        else st.push(s[i]);
    }
    cout<<ans<<"\n";
}



Measured memory_bytes: 2816
#include<bits/stdc++.h>
#define int long long
#define pii pair<int,int>
#define pb push_back
#define ub upper_bound
#define lb lower_bound
#define all(x) x.begin(),x.end()
#define ld long double
#define fast  ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
using namespace std;
signed main(){
    fast;
    string s;
    cin>>s;
    int cnt = 0;
    int ans = 0;
    for(int i = 0;i<3;i++){
    	if(s[i] == 'R'){
    		cnt++;
    		ans = max(ans,cnt);
    	}
    	else{
    		cnt = 0;
    	}
    }
    cout<<ans;
}

Measured memory_bytes: 3648
#include <bits/stdc++.h>
#define pb push_back
#define vt vector
#define ll long long
using namespace std;

const int INF = 1e9 +5;
const ll LLINF = 1e18 +5;

int i4[4] = {1,0,-1,0};
int j4[4] = {0,1,0,-1};

int digitSum(int n)
{
    int ret = 0;
    while(n)
    {
        ret += n%10;
        n /= 10;
    }
    return ret;
}
void solve()
{
    int n;
    cin >> n;
    int ans = INF;
    for(int i = 1; i < n;i++)
    {
        ans = min(ans,digitSum(i)+digitSum(n-i));
    }
    cout << ans << "\n";
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
solve();

  return 0;
}


Measured memory_bytes: 3524
#include<stdio.h>
int main(){
char s[100000];
  int count;
  int i;
  
  
scanf("%s",s);
  for(i=1;s[i];i++){
  if(s[i-1]==s[i]){
    count++;
  if(s[i]=='0')
    s[i]='1';
    else
      s[i]='0';
  }
  }
  printf("%d",count);
return 0;
}

Measured memory_bytes: 256
#include "stdio.h"


main(){

  int H, W;
  int i, j;

  scanf("%d %d", &H, &W);

  while(H != 0 || W != 0){

    for(i = 0; i < H; i++){
      for(j = 0; j < W; j++)printf("#");
      printf("\n");
    }
    printf("\n");

    scanf("%d %d", &H, &W);
  }


  return 0;

}



Measured memory_bytes: 2052
#include<bits/stdc++.h>
#define int long long
using namespace std;
string lcs(string s,string t){	
	int x=s.size(), y=t.size();
	int arr[x+1][y+1];
	for(int i=0;i<=x;++i){
		for(int j=0;j<=y;++j){
			if(i==0 || j==0)
			arr[i][j]=0;
			else if(s[i-1]==t[j-1])
			arr[i][j]=1+arr[i-1][j-1];
			else 
			arr[i][j]=max(arr[i-1][j],arr[i][j-1]);
		}
	}
	string ret="";
	int i=x,j=y;
	while(i>0 && j>0){
		if(arr[i][j]-arr[i-1][j-1]==1 && s[i-1]==t[j-1]){
			ret+=s[i-1];
			i--; j--;
		}else if(arr[i][j]==arr[i-1][j]){
			i--; 
		}else 
		j--;
	}
	reverse(ret.begin(),ret.end());
	return ret;
}
void knapsack(){
	int n,w;
	cin>>n>>w;
	int we[n],val[n];
	for(int i=0;i<n;++i)
	cin>>we[i]>>val[i];
	bool poss[100005];
	int wei[100005];
	for(int i=0;i<100005;++i){
		poss[i]=false;
		wei[i]=LLONG_MAX;
	}
	poss[0]=true;
	wei[0]=0;
	for(int i=0;i<n;++i){
		for(int j=100004;j>=0;--j){
			if(j<val[i])
			break;
			if(poss[j-val[i]]){
				poss[j]=true;
				wei[j]=min(wei[j],wei[j-val[i]]+we[i]);
			}
		}
	}	
	for(int i=100004;i>=0;--i){
		if(poss[i] && wei[i]<=w){
			cout<<i;
			return ;
		}
	}
}
void solve(){
	int n; cin>>n;
	vector<int> v(n); 
	for(int i=0;i<n;++i)
	cin>>v[i];
	sort(v.begin(),v.end());
	int f=v[n-1];
	for(int i=1;i*i<=f;++i){
		 if(f%i==0){ 
			 int ano=f/i;
			 if(ano!=i)
			 {
				 for(int j=n-1;j>=0;--j)
				 if(v[j]==ano){ v[j]=-1; break;}
				 for(int j=n-1;j>=0;--j)
				 if(v[j]==i){ v[j]=-1; break;}
			 }
			 else
			 	 for(int j=n-1;j>=0;--j)
				 if(v[j]==ano){ v[j]=-1; break;}
		}
	}
	sort(v.begin(),v.end());
	int pp=v.size();
	cout<<f<<" "<<v[pp-1];
}
int32_t main(){
	knapsack();
	return 0;
}


Measured memory_bytes: 1152
#include <cstdio>
#include <algorithm>	
#include <iostream>
#include <vector>
#include <queue>
#include <cstring>
#include <cmath>
#define all(x) (x).begin(),(x).end()
using namespace std;
typedef long long LL;
typedef unsigned int uii;
typedef pair<int,int> pii;
typedef unsigned long long uLL; 
typedef vector<int> vi; 



int main(int argc, char const *argv[])
{
#ifndef ONLINE_JUDGE
	// freopen("out.txt", "w", stdout);
#endif
	int n;
	cin >> n;
	string s, t;
	cin >> s >> t;
	for(int i = 0; i < n; ++i) {
		cout << s[i] << t[i];
	}
	cout << endl;
	return 0;
}

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

using namespace std;

template<typename T>
long long modpow(const T n,const T p,const T mod);
template<typename T>
long long modinv(const T n,const T mod);
template<typename T>
bool chmax(T &a,const T &b);
template<typename T>
bool chmin(T &a,const T &b);

long long inf=1000000007;

int main(){
	long long n,a,b;
	cin>>n>>a>>b;
	long long ans=modpow((long long)2,n,inf)-1;
	
	long long ncr=1;
	
	for(long long i=n;i>n-a;i--){
	    ncr*=i;
	    ncr%=inf;
	}
	
	for(long long i=1;i<=a;i++){
	    ncr*=modinv(i,inf);
	    ncr%=inf;
	}
	
	ans-=ncr;
	if(ans<0) ans+=inf;
	ncr=1;
	
	for(long long i=n;i>n-b;i--){
	    ncr*=i;
	    ncr%=inf;
	}
	
	for(long long i=1;i<=b;i++){
	    ncr*=modinv(i,inf);
	    ncr%=inf;
	}
	
	ans-=ncr;
	if(ans<0) ans+=inf;
	
	cout<<max(ans,(long long)0)<<endl;
	
	return 0;
}

template<typename T>
long long modpow(const T n,const T p,const T mod){
	if(p==0) return 1;
	if(p%2==0){
		long long a=modpow(n,p/2,mod);
		return a*a%mod;
	}
	if(p%2==1) return (modpow(n,p-1,mod)*n)%mod;
	cerr<<"ERROR"<<endl;
	return 1;
}

template<typename T>
long long modinv(const T n,const T mod){
	return modpow(n,mod-2,mod);
}

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

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



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

int main(){

    long N;
    cin >>N;
    long ans=0;
    for(long i=1; i<=N; i++){
        if( i%3!=0 && i%5!=0 ){
            ans += i;
        }else{
            continue;
        }
    }

    cout << ans << endl;

    return 0;
}

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

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

    vector<int> h(n);
    for (int i = 0; i < n; i++)
    {
        cin >> h[i];
    }
    
    int ans = 0;
    while (*max_element(h.begin(), h.end()) != 0)
    {
        int i = 0;
        while (i < n)
        {
            if (h[i] == 0)
            {
                i++;
            }

            else 
            {
                ans++;
                while (i < n && h[i] != 0)
                {
                    h[i]--;
                    i++;
                }
                
            }
        }
        
    }
    
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
int f(char a,char b,char c){
  if(a==b)return b-c?1:0;
  if(b==c)return c-a?1:0;
  if(c==a)return a-b?1:0;
  return 2;
}
int main(){
  int n=0,i;
  char a[100010],b[100010],c[100010];
  scanf("%*d %s %s %s",a,b,c);
  for(i=0;a[i];i++)n+=f(a[i],b[i],c[i]);
  printf("%d\n",n);
  return 0;
}


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

int main(void){
    long long int a,b,x,ans,a2,b2;
    cin>>a>>b>>x;
    if(x==1){
        cout<<b-a+1<<endl;
        return 0;
    }
    if(a%x==0) a2=a;
    else a2=a+x-a%x;
    b2=b-b%x;
    if(b2>=a2){
        ans=1+(b2-a2)/x;
    }else{
        ans=0;
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 256
#include<iostream>
using namespace std;
int main()
{
    ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
    int x, k;
    cin >> k >> x;
    for(int i = max(-1000000, x-k+1); i <= min(1000000, x+k-1); i++)
        cout << i << ' ';
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
const int INF = 1000000007;
 
int main(){
  int N;
  cin >> N;
  int A[N];
  for(int i=0;i<N;i++) cin >> A[i];
  sort(A, A+N);
  if(A[0] == 0 && A[N-1] == 0){
    cout << "Yes" << endl;
    return 0;
  }
  if(N % 3 != 0){
    cout << "No" << endl;
    return 0;
  }
  if(A[0] == A[N/3-1] && A[N/3] == A[2*N/3-1] && A[2*N/3] == A[N-1]){
    if((A[0] ^ A[N/3] ^ A[2*N/3]) == 0){
      cout << "Yes" << endl;
      return 0;
    }
  }
  cout << "No" << endl;
}


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

using namespace std;

#define all(c) (c).begin(), (c).end()
#define rep(i, n) for (int i = 0; i < (int)(n); i++)

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

int n, r;
vector<int> p, c;
void ops(vector<int> &card, int p, int c) {
    auto tmp = card;
    p--;
    rep(i, c) {
        card[i] = tmp[i + p];
    }
    rep(i, p) {
        card[i + c] = tmp[i];
    }
}
void solve() {
    vector<int> card(n);
    rep(i, n) card[i] = n - i;
    rep(i, r) {
        ops(card, p[i], c[i]);
        // rep(i, n) cout << card[i] << " ";
        // cout << endl;
    }
    cout << card[0] << endl;
}
int main() {
    while (cin >> n >> r, n) {
        p.resize(r);
        c.resize(r);
        rep(i, r) cin >> p[i] >> c[i];
        solve();
    }

    return 0;
}

Measured memory_bytes: 3084
#include <bits/stdc++.h>
#define INF 1000000000
using namespace std;

int main()
{
  while (true)
  {
    int H;
    cin >> H;
    if (H == 0)
    {
      return 0;
    }
    vector<vector<int>> mp(5, vector<int>(H * 2, -1));
    for (int i = 0; i < H; ++i)
    {
      for (int j = 0; j < 5; ++j)
      {
        cin >> mp.at(j).at(H - 1  - i);
      }
    }
    int ans = 0;
    while (true)
    {
      bool didnt_erase = true;
      for (int i = H - 1; i >= 0; --i)
      {
        int cnt = 0;
        int now = - 1;
        for (int j = 0; j < 5; ++j)
        {
          if (mp.at(j).at(i) == -1)
          {
            if (cnt > 2)
            {
              ans += cnt * mp.at(j - 1).at(i);
              // cout << cnt * mp.at(j - 1).at(i) << endl;
              for (int k = 0; k < cnt; ++k)
              {
                mp.at(j - k - 1).erase(mp.at(j - k - 1).begin() + i);
              }
              didnt_erase = false;
            }
            now = -1;
            cnt = 0;
            continue;
          }
          else if (now == mp.at(j).at(i))
          {
            cnt += 1;
          }
          else
          {
            if (cnt > 2)
            {
              ans += cnt * mp.at(j - 1).at(i);
              // cout << cnt * mp.at(j - 1).at(i) << endl;
              for (int k = 0; k < cnt; ++k)
              {
                mp.at(j - k - 1).erase(mp.at(j - k - 1).begin() + i);
              }
              didnt_erase = false;
            }
            cnt = 1;
            now = mp.at(j).at(i);
          }
        }
        if (cnt > 2)
        {
          ans += cnt * mp.at(4).at(i);
          // cout << cnt * mp.at(4).at(i) << endl;
          for (int k = 0; k < cnt; ++k)
          {
            mp.at(4 - k).erase(mp.at(4 - k).begin() + i);
          }
          didnt_erase = false;
        }
      }
      if (didnt_erase)
      {
        break;
      }
    }
    // for (int i = 0; i < mp.size(); ++i)
    // {
    //   for (int j = 0; j < mp.at(i).size(); ++j)
    //   {
    //     cout << mp.at(i).at(j);
    //   }
    //   cout << endl;
    // }
    cout << ans << endl;
  }
}



Measured memory_bytes: 3040
#include <bits/stdc++.h>
using namespace std;
using P = pair<int, int>;

int main() {
	int n;
	cin >> n;
	map<int, int> cnt;
	for (int i = 0; i < n; i++) {
		int a;
		cin >> a;
		if (cnt.count(a)) {
			cnt[a]++;
		} else {
			cnt.emplace(a, 1);
		}
	}
	int ans = 0;
	for (auto x : cnt) {
		int diff = x.second - x.first;
		ans += (diff < 0) ? x.second : diff;
	}
	cout << ans << endl;
}

Measured memory_bytes: 7928
#include<stdio.h>
#include<string.h>
int main()
{
	char s[100],t[100],x;
	int i,n,d=0,j;
	scanf("%s%s",&s,&t);
	n=strlen(s);
	for(i=0;i<n;i++)
	{
		if(strcmp(s,t)==0)
		{
			d=1;
			break;
		}
		else
		{
			x=s[n-1];
			for(j=n-2;j>=0;j--)
			{
				s[j+1]=s[j];
			}
			s[0]=x;
		}
	}
	if(d==1)printf("Yes\n");
	else printf("No\n");
	return 0;
}

Measured memory_bytes: 128
x,k,d=map(int,input().split())

def counta(x,k,d):
    #xcnt=0
    x=abs(x)
    if d<2*x:
        ans=x//d
        #amari=x%d
        if ans>k:
            print(abs(x-k*d))
            return
        k=k-ans
        x=x-ans*d
        if k%2==0:
            print(x)
            return
        else:
            print(abs(x-d))
            return
    else:
        if k%2==0:
            print(x)
            return
        else:
            print(abs(x-d))
            return
counta(x,k,d)

Measured memory_bytes: 9204
#include<bits/stdc++.h>
using namespace std;
int N;
int W;
int H;

void paint_x(int area, int direct, vector<vector<int>>& mass){
	if(direct == 1){
		for(int i = 0; i < area ; i++){
			for(int j = 0; j < H;j++){
				mass.at(j).at(i)=1;
			}
		}
	}
	if(direct ==2){
		for(int i = W-1; i >= area; i--){
			for(int j = 0; j<H; j++){
				mass.at(j).at(i) = 1;
			}
		}
	}
}

void paint_y(int area, int direct, vector<vector<int>>& mass){
	if(direct == 3){
		for(int i = 0; i < area ; i++){
			for(int j = 0; j < W;j++){
				mass.at(i).at(j)=1;
			}
		}
	}
	if(direct ==4){
		for(int i = H-1; i >= area; i--){
			for(int j = 0; j<W; j++){
				mass.at(i).at(j) = 1;
			}
		}
	}
}

int main(){
	cin >> W >> H >> N;
	vector<vector<int>> mass(H, vector<int>(W, 0));
	vector<int> a(N);
	vector<vector<int>> xy(N, vector<int>(2));
	for(int i = 0; i <N; i++){
		cin >> xy.at(i).at(0) >> xy.at(i).at(1) >> a.at(i);
		switch (a.at(i)) {
			case 1:
			paint_x(xy.at(i).at(0), 1, mass);
			break;
			case 2:
			paint_x(xy.at(i).at(0), 2, mass);
			break;
			case 3:
			paint_y(xy.at(i).at(1), 3, mass);
			break;
			case 4:
			paint_y(xy.at(i).at(1), 4, mass);
			break;
		}
	}
	int c=0;
	for(int i =0; i<H; i++){
		for(int j = 0; j<W; j++){
			if(mass.at(i).at(j)==0) c++;
		}
	}
	cout << c << endl;
}


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

#define ll long long
#define INF 99999999
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()

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

    if(a>b) rep(i,a) cout << b;
    else if(a<b) rep(i,b) cout << a;
    else rep(i,min(a,b)) cout << a;
    cout << endl;
    


}


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

    int main(){
        ll N;
        cin >> N;
        ll A[N];
        rep(i, N) cin>>A[i];

        sort(A, A+N);

        ll ans=0;
        ll conf=0;
        ll conf_pre=0;
        queue<ll> q;
        rep(i, N){
            if(i==0){
                q.push(A[N-i-1]);
                continue;
            }else{
                if(i%2==0 || i==1){
                    conf_pre=q.front();
                    q.pop();
                }
                conf=A[N-i-1];
                //cout<<conf_pre<<endl;
                ans+=conf_pre;
                q.push(A[N-i-1]);
            }
        }
        cout<<ans<<endl;
        return 0;
    }

Measured memory_bytes: 5816
#include<iostream>
using namespace std;
int main() {
	int n, m, e, j, ans[10000000],an;
	an = 0;
	while(1) {
		cin >> n;
		if (n == 0) {
			goto b;
		}
		for (int i = 1; i <= n; i++) {
			an = an+1;
			cin >> m >> e >> j;
			if (m == 100 || e == 100 || j == 100) {
				ans[an] = 1;
				goto a;
			}
			if (m + e >= 180) {
				ans[an] = 1;
				goto a;
			}
			if(m+e+j>=240){
				ans[an] = 1; 
				goto a;
			}
			if (m + e + j >= 210) {
				ans[an] = 2;
				goto a;
			}
			if (m + e + j >= 150) {
				if (m >= 80 || e >= 80) {
					ans[an] = 2;
					goto a;
				}
			}
			ans[an] = 3;
		a:;
		}
	}
b:;
	for (int i = 1; i <= an; i++) {
		if (ans[i] == 1) {
			cout << "A" << endl;
		}
		if (ans[i] == 2) {
			cout << "B" << endl;
		}
		if (ans[i] == 3) {
			cout << "C" << endl;
		}
	}
}


Measured memory_bytes: 3072
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define rrep(i,n) for(int i=(int)(n-1);i>=0;i--)
#define FOR(i,n,m) for(int i=n;i<=(int)(m);i++)
#define RFOR(i,n,m) for(int i=(int)(n);i>=m;i--)
#define all(x) (x).begin(),(x).end()
#define sz(x) int(x.size())
#define get_unique(x) x.erase(std::unique(all(x)), x.end());
typedef long long ll;
const int INF = 1e9;
const int MOD = 1e9+7;
const ll LINF = INT_MAX;
const double PI=acos(-1);
using namespace std;
vector<int> dx={1,0,-1,0};
vector<int> dy={0,1,0,-1};
template<class T>
vector<T> make_vec(size_t a){
    return vector<T>(a);
}
template<class T, class... Ts>
auto make_vec(size_t a, Ts... ts){
    return vector<decltype(make_vec<T>(ts...))>(a, make_vec<T>(ts...));
}//区間加算・区間和クエリ
struct LasySegmentTree {
    int n;
    vector<ll> node, lazy;
    
    LasySegmentTree(vector<ll> v) {
        int sz=sz(v);
        n=1;
        while(n<sz) n*=2;
        node.resize(2*n-1);
        lazy.resize(2*n-1);
        
        rep(i,sz) node[i+n-1]=v[i];
        rrep(i,n-2) node[i]=node[i*2+1]+node[i*2+2];
    }
    
    void eval(int k,int l,int r) {
        if(lazy[k]!=0) {
            node[k]+=lazy[k];
            if(r-l>1) {
                lazy[2*k+1]+=lazy[k]/2;
                lazy[2*k+2]+=lazy[k]/2;
            }
        }
        lazy[k]=0;
    }
    
    void add(int a,int b,ll x,int k=0,int l=0,int r=-1) {
        if(r<0) r=n;
        eval(k,l,r);
        if(b<=l || r<=a) return;
        
        if(a<=l && r<=b) {
            lazy[k]+=(r-l)*x;
            eval(k,l,r);
        }
        else {
            add(a,b,x,2*k+1,l,(l+r)/2);
            add(a,b,x,2*k+2,(l+r)/2,r);
            node[k]=node[2*k+1]+node[2*k+2];
        }
    }
    
    ll getsum(int a,int b,int k=0,int l=0,int r=-1) {
        if(r<0) r=n;
        if(b<=l || r<=a) return 0;
        
        eval(k,l,r);
        if(a<=l && r<=b) return node[k];
        ll vl=getsum(a,b,2*k+1,l,(l+r)/2);
        ll vr=getsum(a,b,2*k+2,(l+r)/2,r);
        return vl+vr;
    }
};

int main() {
    int n,q;
    cin>>n>>q;
    vector<ll> v(n,0);
    LasySegmentTree segt(v);
    while(q--) {
        int query;
        cin>>query;
        if(query==0) {
            int s,t;
            ll x;
            cin>>s>>t>>x;
            s--;t--;
            segt.add(s,t+1,x);
        }
        else {
            int i;
            cin>>i;
            cout<<segt.getsum(i-1,i)<<endl;
        }
    }
}



Measured memory_bytes: 8448
#include<stdio.h>
#define max(a,b) ((a)>(b)?(a):(b))
typedef long long int ll;
#define MOD 1000000007
int main() {
    int n;
    scanf("%d",&n);
    long a[200000];
    long sum=0;
    long ans=0;
  	for (int i=0;i<n;i++) {
        scanf("%ld",&a[i]);
        ans=(ans+sum*a[i])%MOD;
        sum=(sum+a[i])%MOD;
    }
    printf("%lld",ans);
    return 0;
}

Measured memory_bytes: 3260
#include<bits/stdc++.h>
#define re register
#define inc(i,j,k) for(re int i=j;i<=k;i++)
using namespace std;
const int N=2005;
inline int read(){
	int x=0;
	char ch=getchar();
	while(ch<'0'||ch>'9') ch=getchar();
	while('0'<=ch&&ch<='9') x=x*10+ch-'0',ch=getchar(); 
	return x;
}
int n,k,a[N],b[N],ans,res;
vector<int> to[N];
void get(int u,int f,int d){
	if(d>k/2) res++;
	for(re int i=0;i<to[u].size();i++){
		int v=to[u][i];
		if(v==f) continue;
		get(v,u,d+1);
	}
}
int main(){
	n=read(),k=read();ans=n;
	inc(i,2,n){
		a[i]=read(),b[i]=read();
		to[a[i]].push_back(b[i]);
		to[b[i]].push_back(a[i]);
	}
	if(k&1){
		inc(i,2,n) res=0,get(a[i],b[i],0),get(b[i],a[i],0),ans=min(ans,res);
	}
	else{
		inc(i,1,n) res=0,get(i,0,0),ans=min(ans,res);
	}
	printf("%d",ans);
}

Measured memory_bytes: 512
// AOJ 0330: Halting Problem
// 2017.10.25 bal4u@uu

#include <stdio.h>
#include <stdlib.h>
#include <string.h>

#define ADDV	1
#define ADDC	2
#define SUBV	3
#define SUBC	4
#define SETV	5
#define SETC	6
#define IFV		7
#define HALT	8

typedef struct { int lin, cmd, v1, v2, v3, con, to; } T;
T pgm[52]; int n;

int tr['z'+1];
char var[26]; int sz;
int lin[1002];
char tmp[110][26];
char mk[51][16][16][16][16][16];

int check(int v)
{
	if (v < 0 || v >= 16) return 0;
	return 1;
}

int varid(char x)
{
	int r;
	if (tr[x] < 0) r = sz++, tr[x] = r;
	else r = tr[x];
	return r;
}

int main()
{
	int i, pc, cnt;
	char cmd, b1[10], b2[10], b3[10];
	T *tp;

	memset(tr, -1, sizeof(tr)), memset(lin, -1, sizeof(lin)), sz = 0;
	scanf("%d", &n);
	for (tp = pgm, i = 0; i < n; i++, tp++) {
		scanf("%d%s", &tp->lin, b1); lin[tp->lin] = i, cmd = *(b1+1);
		if (cmd == 'A') tp->cmd = HALT;
		else if (cmd == 'D' || cmd == 'U') {
			scanf("%s%s%s", b1, b2, b3);
			tp->v1 = varid(*b1), tp->v2 = varid(*b2);
			if (*b3 >= 'a') {
				tp->cmd = (cmd == 'D') ? ADDV : SUBV;
				tp->v3 = varid(*b3);
			} else {
				tp->cmd = (cmd == 'D') ? ADDC : SUBC;
				tp->con = atoi(b3);
			}
		} else if (cmd == 'E') {
			scanf("%s%s", b1, b2);
			tp->v1 = varid(*b1);
			if (*b2 >= 'a') {
				tp->cmd = SETV;
				tp->v2 = varid(*b2);
			} else {
				tp->cmd = SETC;
				tp->con = atoi(b2);
			}
		} else {		// IF
			scanf("%s%d", b1, &tp->to);
			tp->cmd = IFV, tp->v1 = varid(*b1);
		}
	}
	pc = 0, cnt = 0;
	while (1) {
		if (mk[pc][var[0]][var[1]][var[2]][var[3]][var[4]]) { puts("inf"); return 0; }
		mk[pc][var[0]][var[1]][var[2]][var[3]][var[4]] = 1;
		tp = pgm+pc;
		if (tp->cmd == ADDV) {
			if (!check(var[tp->v2] + var[tp->v3])) break;
			var[tp->v1] = var[tp->v2] + var[tp->v3];
		} else if (tp->cmd == ADDC) {
			if (!check(var[tp->v2] + tp->con)) break;
			var[tp->v1] = var[tp->v2] + tp->con;
		} else if (tp->cmd == SUBV) {
			if (!check(var[tp->v2] - var[tp->v3])) break;
			var[tp->v1] = var[tp->v2] - var[tp->v3];
		} else if (tp->cmd == SUBC) {
			if (!check(var[tp->v2] - tp->con)) break;
			var[tp->v1] = var[tp->v2] - tp->con;
		} else if (tp->cmd == SETV) {
			if (!check(var[tp->v2])) break;
			var[tp->v1] = var[tp->v2];
		} else if (tp->cmd == SETC) {
			if (!check(tp->con)) break;
			var[tp->v1] = tp->con;
		} else if (tp->cmd == HALT) break;
		
		if (tp->cmd == IFV && var[tp->v1] != 0) {
			if (lin[tp->to] < 0) break;
			pc = lin[tp->to];
		} else {
			pc++;
			if (pc == n) break;
		}
	}
	for (i = 'a'; i <= 'z'; i++) if (tr[i] >= 0) printf("%c=%d\n", i, var[tr[i]]);
	return 0;
}

Measured memory_bytes: 45904
#include<stdio.h>
#include<math.h>
int main()
{
   int n,i,m,j,a[102],b,c,d,x,tmp,sum=0;
   while(scanf("%d",&n)!=EOF)
   {
   	scanf("%d%d",&d,&x);
   	for(int i=0;i<n;i++)
   	{
   		scanf("%d",&a[i]);
   	}
   	int t=0;   	
		for(int i=0;i<n;i++)
		{
			tmp=a[i];
			if(tmp<d)
			{
				tmp+=1;
				m+=2;
			}
			else{
				++m;
				continue;
				}
			while(tmp<d){
			tmp+=a[i];
			if(tmp<=d)
				++m;
			else break;
			}
		}
		printf("%d",m+x);
	}
    return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i=0; i<(n); ++i)
#define REP(i, d, n) for(int i=(d); i<(n); ++i)
#define all(v) v.begin(), v.end()
using ll = long long;
using P = pair<int, int>;

int main() {

    int n, k;
    cin >> n >> k;
    vector<double> p(n);
    rep(i, n){
        cin >> p[i];
    }

    vector<double> cum(n+1);
    rep(i, n){
        cum[i+1] = cum[i] + (p[i]+1) / 2; 
    }

    double ans = 0;
    for(int i=0; i<n-k+1; ++i){
        ans = max(ans, cum[i+k]-cum[i]);
    }

    cout << fixed << setprecision(7) << ans << endl;

    return 0;
}


Measured memory_bytes: 3328
// 過去イチで酷い実装、いつかリファクタリングしたい
import java.io.IOException;
import java.io.BufferedReader;
import java.io.InputStreamReader;

class Main {
    public static void main(String[] args) throws IOException {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        String line;

        while ((line = br.readLine()) != null) {
            String[] input = line.split(" ");
            int p = Integer.parseInt(input[0]);
            int q = Integer.parseInt(input[1]);
            String qs = ""; // 商の羅列
            int[] rs = new int[81]; // 余りの羅列
            int pos = 0;
            StringBuilder second = new StringBuilder(); // 循環部を表示するため
            boolean isLoop = false;

            p -= (p / q) * q; // p < qにする
            rs[pos] = p;

            wh: while (true) {
                int sho = (10 * p) / q;
                p = (10 * p) % q;

                if (p == 0) {
                    qs = qs + sho;
                    break;
                }

                int i;
                for (i = pos; i >= 0; i--) {
                    if (rs[i] == p) {
                        qs = qs + sho;

                        int marklength = qs.length() - i;
                        for (int j = 0; j < i; j++) {
                            second.append(" ");
                        }
                        for (int j = 0; j < marklength; j++) {
                            second.append("^");
                        }
                        isLoop = true;
                        break wh;
                    }
                }

                qs = qs + sho;
                rs[++pos] = p;
            }

            if (isLoop) {
                System.out.println(qs);
                System.out.println(second.toString());
            } else {
                System.out.println(qs);
            }

        }
    }
}


Measured memory_bytes: 26364
#include <bits/stdc++.h>
  using namespace std;
#define ll long long
#define fw(p) for(int w=0;w<(p);w++)
#define fx(p) for(int x=0;x<(p);x++)
#define fy(p) for(int y=0;y<(p);y++)
#define fz(p) for(int z=0;z<(p);z++)
#define fyg(p,g) for(int y=(g);y<(p);y++)
#define fzg(p,g) for(int z=(g);z<(p);z++)
#define ce(d) cout<<d<<endl;
#define vecp(p) int aa;cin>>aa;(p).push_back(aa);
#define vecpl(p) long long aa;cin>>aa;(p).push_back(aa);
#define vecps(p) string aa;cin>>aa;(p).push_back(aa);
#define vecp2(p) int ab;cin>>ab;(p).push_back(ab);
#define vecpl2(p) long long ab;cin>>ab;(p).push_back(ab);
#define vecps2(p) string ab;cin>>ab;(p).push_back(ab);
#define set0(k,n) for(int nn=0;nn<(n);nn++){ (k).push_back(0); }
#define sorts(c) sort((c).begin(),(c).end());
#define reverses(c) reverse((c).begin(),(c).end());
#define vec(b) vector<int> (b);
#define vecl(b) vector<long long> (b);
#define vecs(b) vector<string> (b);
#define vecsize(b,size) vector<int> (b)((size));
#define pb(b,a) (b).push_back((a));
#define doublece(a,b) cout<<(a)<<' '<<(b)<<endl;
#define pairs(s) vector<pair<int,int>> (s);
#define pairsl(s) vector<pair<ll,ll>> (s);
#define pairss(s) vector<pair<string,string>> (s);
#define pairsp(s) int aa,bb;cin>>aa>>bb;(s).push_back(make_pair(aa,bb));
#define pairspl(s) int aa,bb;cin>>aa>>bb;(s).push_back(make_pair(aa,bb));
#define pairsps(s) int aa,bb;cin>>aa>>bb;(s).push_back(make_pair(aa,bb));
#define pairsREV(s) (s).push_back(make_pair(bb,aa));
#define pairslREV(s) (s).push_back(make_pair(bb,aa));
#define pairssREV(s) (s).push_back(make_pair(bb,aa));
#define MOD 1000000007

int main() {
	
int N;
cin>>N;
ce(N/3)

}

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

using dbl=double;
using P=complex<dbl>;
const dbl pi=acos(-1);
const dbl INF=1e9;

const int BASE=2;
const int LOOP1=50;
const int LOOP2=10;
const int LOOP3=8;

int main(){
    int n,k;
    cin>>n>>k;

    vector<P> ps(n);
    for(int i=0;i<n;i++){
        int x,y;
        cin>>x>>y;
        ps[i]=P(x,y);
    }

    auto calc=[&](P c){
        vector<dbl> vec;
        for(auto p:ps) vec.push_back(abs(c-p));
        sort(vec.begin(),vec.end());
        return accumulate(vec.end()-k,vec.end(),dbl(0));
    };

    P res={0,0};

    dbl diff=100;
    for(int _=0;_<LOOP1;_++){
        for(int _=0;_<LOOP2;_++){
            int best=0;
            dbl tmpScore=INF;
            for(int k=0;k<LOOP3;k++){
                P to=res+diff*exp(P(0,1)*P(2*pi*k/LOOP3,0));
                dbl score=calc(to);
                if(score<tmpScore){
                    tmpScore=score;
                    best=k;
                }
            }
            res+=diff*exp(P(0,1)*P(2*pi*best/LOOP3,0));
        }
        diff/=BASE;
    }
    cout<<fixed<<setprecision(10);
    cout<<calc(res)<<endl;
    return 0;
}


Measured memory_bytes: 3664
#include<iostream>
#include<algorithm>
#include<vector>
#include<stack>
#include<queue>
#include<cstdio>
#include<climits>
#include<cmath>
#include<cstring>
#include<string>
#include<complex>
#include<cfloat>
#include<cassert>

#define f first
#define s second
#define mp make_pair

#define REP(i,n) for(int i=0; i<(int)(n); i++)
#define FOR(i,c) for(__typeof((c).begin()) i=(c).begin(); i!=(c).end(); i++)
#define ALL(c) (c).begin(), (c).end()
#define EPS (1e-10)
using namespace std;

typedef unsigned int uint;
typedef long long ll;
typedef complex<double> P;

#define PI (3.1415926535)
#define EPS (1e-10)

int main(){
  double a,b;
  P pos(0.0,0.0);
  P ang(0.0,1.0);
  while(scanf("%lf,%lf",&a,&b), a+b){
    double th = - (b / 180.0) * PI;
    pos = pos + ang * a;
    ang = ang * P(cos(th), sin(th));
  }
  cout << (int)pos.real() << endl << (int)pos.imag() << endl;
  return 0;
}

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

int main(){
	ll a,b,c,d;
	cin>>a>>b>>c>>d;
	
	ll ans=b-a+1;
	ll cc=b/c-(a-1)/c;
	ll dd=b/d-(a-1)/d;
	
	ll n=min(c,d);
	ll i=2;
	ll LCM=1;
	while(1){
		if(c%i==0&&d%i==0){
			LCM*=i;
			c/=i;
			d/=i;
		}
		else i++;
		if(i>sqrt(n)) break;
	}
	LCM=LCM*c*d;
	
	ll cd=b/(LCM)-(a-1)/(LCM);
	
	cout << ans-cc-dd+cd << endl;
}

Measured memory_bytes: 256
import java.util.*;

public class Main{
  Scanner sc = new Scanner(System.in);
  StringBuilder sb = new StringBuilder();

  int H;
  int[] A;

  public static void main(String[] args){
    Main main = new Main();
    main.in();    
    main.buildMaxHeap();
    main.out();
  }

  public void in(){
    H = sc.nextInt();
    A = new int[H + 1];
    for(int i = 1;i < A.length;i++){
      A[i] = sc.nextInt();
    }
  }
  public void maxHeapify(int i){
    int right = (2 * i) + 1;
    int left = 2 * i;
    int largest;
    int tmp;

    if(left <= H && A[left] > A[i]){
      largest = left;
    }
    else {
      largest = i;
     }
     if(right <= H && A[right] > A[largest]){
       largest = right;
     }
     if(largest != i){
       tmp = A[i];
       A[i] = A[largest];
       A[largest] = tmp;
       maxHeapify(largest);
     } 
  }
  public void out(){
    for(int i = 1;i < A.length;i++){
      sb.append(" ").append( Integer.toString(A[i]) );
    }
    System.out.println(sb.toString());
  }
  public void buildMaxHeap(){
    for(int i = (H / 2);i >= 1;i--){
      maxHeapify(i);
    }
  }
 
}


Measured memory_bytes: 167764
#include <bits/stdc++.h>
 using namespace std;
 #define rep(i,N) for(int i=0;i<int(N);++i)
 using ll = long long;
 const int INF = 2147483647;
 const ll MOD = 1000000007;
 // const ll INF = 1000000000000000000LL;

  vector<bool> Eratosthenes(const int N)
  {
      vector<bool> is_prime(N+1);
      for(int i=0;i<=N;i++)
      {
          is_prime[i] = true;
      }
      vector<int> P;
      for(int i=2;i<=N;i++)
      {
          if(is_prime[i])
          {
              for(int j=2*i;j<=N;j+=i)
              {
                  is_prime[j] = false;
              }
          }
      }
      return is_prime;
  }

int main() {
	int n = 1e5;
	int q;
	cin >> q;
	vector<int> l(q);
	vector<int> r(q);
	rep(i,q){
		cin >> l[i] >> r[i];
	}
	auto is_prime = Eratosthenes(n);
	is_prime[1] = 0;
	// is_prime[0] = false;
	// for(int i=1;i<20;i++){
	// 	cout << i << ':' << is_prime[i] << endl;
	// }
	vector<int> similar(n+1);
	for(int i=3;i<=n;i+=2){
		similar[i] = similar[i-2];
		if(is_prime[i]&&is_prime[(i+1)/2])
			similar[i]++;
	}
	// for(int i=2;i<20;i++){
	// 	cout << i  << ':' << similar[i] << endl;
	// }
	vector<int> ans(n);
	rep(i,q){
		// cout << similar[r[i]] << endl;
		// cout << similar[l[i]] << endl;
		ans[i] = similar[r[i]] - similar[l[i]-2];
	}
	rep(i,q) cout << ans[i] << endl;
	return 0;
}


Measured memory_bytes: 4836
#include <bits/stdc++.h>
#define REP(i,n) for(ll i = 0; i < (ll)n; i++)
#define FOR(i,a,b) for (ll i=(a);i<(ll)b; i++)
#define ALL(obj) (obj).begin(),(obj).end()
#define INF 1000000000000000
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; }
using namespace std;
typedef long long ll;
typedef double db;
typedef string str;
typedef pair<ll,ll> p;
const int MOD = 1000000007;

void print(const std::vector<int>& v)
{
  std::for_each(v.begin(), v.end(), [](int x) {
    std::cout << x << " ";
  });
  std::cout << std::endl;
}

int main ()
{
  int N;cin>>N;
  vector<ll> H(N);
  REP(i,N) cin>>H[i];
  int cnt = 1;
  for (int i = 1; i < N; i++)
  {
    int flag = 0;
    for (int j = 0; j < i; j++)
    {
      if(H[j]>H[i]){
          flag++;
          }
    }
    if(flag==0){
      cnt++;
    }
  }
  
  cout<<cnt<<endl;
  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <vector>
#include <deque>
#include <queue>
#include <set>
#include <map>
#include <limits>
#include <cmath>
#include <iomanip>
#include <functional>
#include <random>
#include <boost/multiprecision/cpp_int.hpp>

using namespace std;
using ll = long long;

int main()
{
    // 整数の入力
    ll a;
    cin >> a;
    ll pay = 1000 * ((a + 1000 - 1)/1000);
    cout << pay -a  << endl;
    return 0;
}

Measured memory_bytes: 3636
#include<bits/stdc++.h>
#define SIZE 100
using namespace std;

bitset<SIZE+1> isPrime;
vector<int> primes;

void generate(){
	isPrime.set();
	isPrime[0] = isPrime[1] = false;
	for(int i=2;i<=SIZE;i++)
		if(isPrime[i]){
			primes.push_back(i);
			for(int j=2*i;j<=SIZE;j+=i)
				isPrime[j] = false;
		}
}

vector<int> factors;

vector<int> divisorsMultiple;

void process(int x){
	int id = 0;	
	int pf = primes[id];
	while(pf * pf <= x){
		while(x%pf == 0){
			factors[pf]++;
			x /= pf;
		}	
		pf = primes[++id];
	}
	if(x != 1)
		factors[x]++;
}

int dp[1000][1000];

int thatNumbers(int idx,int product){
	if(product == 75)
		return 1;
	if(product > 75)
		return 0;
	if(dp[idx][product] != -1)
		return dp[idx][product];
	int N = divisorsMultiple.size();	
	if(idx == N)
		return 0;

	int ans = 0;
	for(int i=1;i<=divisorsMultiple[idx];i++)
		ans += thatNumbers(idx+1,product*i);	

	return dp[idx][product] = ans;
}

int main(){
	generate();
	int N;
	cin>>N;
	factors.assign(SIZE+1,0);
	for(int i=1;i<=N;i++)
		process(i);

	int x;

	for(int i=0;i<=SIZE;i++){
		x = factors[i];
		if(x)
			divisorsMultiple.push_back(x+1);
		
	}


	for(int i=0;i<1000;i++)
		for(int j=0;j<1000;j++)
			dp[i][j] = -1;

	
	cout<<thatNumbers(0,1);

	cout<<"\n";
	return 0;
}

Measured memory_bytes: 4096
n = int(input())
a = [[], []]

for i in range(0, 2):
    a[i] = [int(i) for i in input().split(" ")]

s1 = 0
s2 = sum(a[1])
mx = 0

for i in range(0, n):
    s1 += a[0][i]
    m = s1 + s2
    if mx < m:
        mx = m
    s2 -= a[1][i]

print(mx)

Measured memory_bytes: 3064
import java.util.*

fun main(arr:Array<String>) {
    val (n,k) = readLine()!!.split(" ").map { it.toInt() }
    val candles = readLine()!!.split(" ").map { it.toLong() }

    var total = 0L
    for(i in (1 until k)) {
        total += candles[i] - candles[i-1]
    }
    var ans = total + Math.min(Math.abs(candles[0]), Math.abs(candles[k-1]))
    for(i in (1..n-k)) {
        total -= candles[i] - candles[i-1]
        total += candles[i+k-1] - candles[i-1+k-1]
        ans = Math.min(ans, total + Math.min(Math.abs(candles[i]), Math.abs(candles[i+k-1])))
    }
    println(ans)
}


Measured memory_bytes: 50232
/*
      author  : nishi5451
      created : 15.08.2020 13:11:41
*/

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


int main(){
    int n;
    cin >> n;
    string s;
    cin >> s;

    rep(i,s.size()){
        int k = (s[i]-'A'+n)%26;
        s[i]='A'+k;
    }
    cout << s << endl;
    return 0;
}

Measured memory_bytes: 3624
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <math.h>
#define MOD 1000000007
typedef long long ll;
using namespace std;

int main(){
  string s;
  cin>>s;
  int n;
  n=s.size();

  int ans=100;
  for(int i=0;i<26;i++){
    char c='a'+i;
    int ma=0,count=0;
    for(int i=0;i<n;i++){
      if(s[i]==c){
        ma=max(ma,count);
        count=0;
      }else{
        count++;
      }
    }
    ma=max(ma,count);
    ans=min(ans,ma);
  }
  cout<<ans<<endl;
  return 0;
}


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

#define int         long long
#define uint        unsigned int
#define ld          long double
#define showoff     ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define pb          push_back
#define pii         pair<int,int>
#define FOR(i,a,b)  for(int i=a;i<b;++i)
#define RFOR(i,a,b) for(int i=a;i>b;--i)
#define f           first
#define se          second
#define maxn        200005
#define all(v)      v.begin(),v.end()
#define sz(x)       (int)x.size()
#define mod         1000000007
#define pqueue      priority_queue<int>
#define pdqueue     priority_queue< int,vector<int> ,greater< int >>

using namespace std;


//mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

/*int power(int a,int n)
{
    if(n == 1)return a%mod;
    if(n == 0)return 1;
    if(n&1)return ((a%mod)*(power((a*a)%mod,n>>1))%mod)%mod;
    return power((a*a)%mod,n>>1)%mod;
}
*/
const int md = 998244353;
int dp[100005][5],a[100005],b[100005],c[100005];


signed main()
{
    showoff;
    int n;
    cin >> n;
    FOR(i,1,n+1){
    cin >> a[i] >> b[i] >> c[i];
    }
    FOR(i,1,n+1){
    dp[i][1] = max(dp[i-1][2],dp[i-1][3])+a[i];
    dp[i][2] = max(dp[i-1][1],dp[i-1][3])+b[i];
    dp[i][3] = max(dp[i-1][1],dp[i-1][2])+c[i];
    }
    cout << max(max(dp[n][1],dp[n][2]),dp[n][3]);
    return 0;
}


Measured memory_bytes: 6528
#include<bits/stdc++.h>
using namespace std;
#define MOD 1000000007
#define gt(n) scanf("%d", &n)
#define gtll(n) scanf("%ld", &n)
#define out(n) printf("%d", n)
#define outll(n) printf("%ld", n)
#define loop(n) for(int i=0; i<n; i++)
#define MAXX 1001
#define mem(x, y) memset(x, y, sizeof(x))
#define loop1(n) for(int i=1; i<=n; i++)
#define ll long long
#define pb push_back
#define pi acos(-1)
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
//(only in c)char[33];itoa(n,buffer,base);printf("%s",buffer);
#define dec_to_bin(n) std::string binary = std::bitset<64>(n).to_string();
#define fast ios_base::sync_with_stdio(false),cin.tie(NULL)
#define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>
int main()
{
    fast;
    int n,x;
    cin>>n>>x;
    int l[n+7];
    int d[n+7];
    for(int i=1; i<=n; i++)
    {
        cin>>l[i];
    }
    d[1]=0;
    int c=1;
    for(int i=2; i<=n+1; i++)
    {
        d[i]=d[i-1]+l[i-1];
        if(d[i]<=x)c++;
        else break;
    }
    cout<<c<<endl;
    return 0;
}


Measured memory_bytes: 256
use proconio::derive_readable;
use proconio::input;

#[derive_readable]
#[derive(Debug, Clone, Copy)]
struct Query {
    a: usize,
    b: usize,
    c: usize,
    d: i32,
}

fn main() {
    input! {
        n: usize,
        m: usize,
        q: usize,
        qu: [Query; q]
    };
    let mut qb = vec![Vec::new(); 11];
    for q in qu.iter() {
        qb[q.b].push(q);
    }
    let mut ans = 0;
    let mut queue = std::collections::VecDeque::new();
    queue.push_back((0_usize, 0_i32, vec![1_usize]));

    while !queue.is_empty() {
        let (i, s, seq) = queue.pop_front().unwrap();
        ans = std::cmp::max(ans, s);
        if i == n {
            continue;
        }
        for j in seq[i] ..= m {
            let mut seq = seq.clone();
            seq.push(j);
            let s = qb[i + 1].iter().fold(s, |s, q| {
                if seq[q.b] - seq[q.a] == q.c {
                    s + q.d
                } else {
                    s
                }
            });
            let state = (i + 1, s, seq);
            queue.push_back(state);
        }
    }
    println!("{:?}", ans);
}


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

int main() {
  int N;
  cin >> N;
	
  for(int i = 0; i < N; i++){
	string A;
    cin >> A;
    if(A == "Y"){
    	cout << "Four" << endl;
      	break;
    }else if(i == N - 1){
    	cout << "Three" << endl;	
    }
  }
 

}


Measured memory_bytes: 256
import java.util.*;

public class Main {

    public static void main(String[] args) {
        // write your code here
        Scanner sc = new Scanner(System.in);

        int x = sc.nextInt();

        ArrayList<Integer> list = divisor(x);

        for (Integer v: list
             ) {
            int max = v;
            int min = 0;
            long ba = ((long)Math.pow(max, 5));
            long bb = ((long)Math.pow(min, 5));
            boolean isUp = ba - bb < x;
            while (true) {
                long a = ((long)Math.pow(max, 5));
                long b = ((long)Math.pow(min, 5));
                long minus = a - b;
                if (minus == x) {
                    System.out.println(max + " " + min);
                    return;
                }
                if (isUp && minus > x) {
                    break;
                }
                if (!isUp && minus < x) {
                    break;
                }
                if (isUp) {
                    max++;
                    min++;
                } else {
                    max--;
                    min--;
                }
            }
        }
    }

    /**
     * (正の)約数列挙O(√n)
     * @param n
     * @return	nの約数列(sortはされてないよ)
     */
    public static ArrayList<Integer> divisor(int n){
        ArrayList<Integer> ret = new ArrayList<Integer>();
        for(int i=1; i*i <= n; i++){
            if( n % i == 0){
                ret.add(i);
                //n=PQ+0→ PもQも約数. ただし、Q=Pは↑で登録済みなので登録しない
                if( i != n/i ) ret.add(n/i);
            }
        }
        return ret;
    }
}

Measured memory_bytes: 38816
#include <iostream>
#include <vector>
#include <algorithm>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <string>
#include <cstdio>
#include <cstdlib>
#include <string>
#include <cstring>
#include <cmath>
#include <climits>
#include <ctime>
#include <fstream>
#include <functional>
#include <unordered_map>
#include <unordered_set>
#define endl '\n'
//#define ll long long
#define mod 1000000007
#define NCONS 100001
//#define NCONS 100001
//#define NCONS 1001
//#define NCONS 101
#define MCONS 2001
#define LIMIT 1000000000
#define TRUE 1
#define FALSE 0
#define toRadian(degree) ((degree) * (M_PI / 180.))
#define toDegree(radian) ((radian) * (180. / M_PI))
#define int long long
//#define double long double
using namespace std;
struct Point{int x; int y;};
struct PPoint{Point x; Point y;};
typedef long long ll;

int gcd(int a, int b) { if(a < b) swap(a, b); if(b <= 0) return a; return gcd(b, a % b); }

#define YYYY cout << "YES" << endl
#define NNNN cout << "NO" << endl
#define yyyy cout << "Yes" << endl
#define nnnn cout << "No" << endl

vector<int> idx[50];

int32_t main(void)
{
    cin.tie(NULL); ios_base::sync_with_stdio(false);
    string s, t; cin >> s >> t;
    
    for(int i = 0; i < s.size(); i++)
    {
        idx[s[i]-'a'].push_back(i);
    }
    
    for(auto ch : t)
    {
        if(idx[ch-'a'].empty())
        {
            cout << -1 << endl; exit(0);
        }
    }
    
    
    int s_ptr = idx[t[0]-'a'][0];
    int ret = s_ptr + 1;
    
    for(int i = 1; i < t.size(); i++)
    {
        auto ch = t[i];
        auto ptr = lower_bound(idx[ch-'a'].begin(), idx[ch-'a'].end(), s_ptr + 1);
        
        int diff = 0;
        
        
        if(ptr == idx[ch-'a'].end())
        {
            diff = s.size() - (s_ptr - idx[ch-'a'][0]);
            s_ptr = idx[ch-'a'][0];
        }
        else
        {
            auto index = *ptr;
            diff = index - s_ptr;
            s_ptr = index;
        }
        
    //    cout << diff << endl;
        ret += diff;
    }
    
    
    cout << ret << endl;
    
    
    return 0;
}


Measured memory_bytes: 1736