akhauriyash/Code-Regression huggingface dataset:
/*
**   Contest : AtCoder Beginner Contest 173
**   Problem : D - Chat in a Circle
**
**    Author : Dhiraj Govindvira
**      Date : 05-Jul-2020 ~ Sunday
**      Time : 08:42:00 PM
*/

#if __has_include("D:/dhiraj/Programming/debug.h")
    #include "D:/dhiraj/Programming/debug.h"
#else
    #include <bits/stdc++.h>
    using namespace std;
    #define d(...) 11
    #define cerr if(0) cerr
#endif

// Macro --------------------------------------------------------------------

#define ll                  long long int
#define FOR(i, a, b, s)     for(ll i = (a); ((s)>0 ? i<(b) : i>(b)); i += (s))
#define FOR1(b)             FOR(i, 0, b, 1)
#define FOR2(i, b)          FOR(i, 0, b, 1)
#define FOR3(i, a, b)       FOR(i, a, b, (a) <= (b) ? 1 :-1)
#define FOR4(i, a, b, s)    FOR(i, a, b, s)
#define GET5(a, b, c, d, e, ...) e
#define FORC(...)           GET5(__VA_ARGS__, FOR4, FOR3, FOR2, FOR1)
#define loop(...)           FORC(__VA_ARGS__)(__VA_ARGS__)
#define all(x)              x.begin(),x.end()
#define rall(x)             x.rbegin(),x.rend()
#define endl                '\n'

// Template -----------------------------------------------------------------

// multiple input
template <typename... T> 
inline void inp(T&... args) {
    ((cin>>args), ...);
}
// scan vector
template <typename T> 
inline istream &operator>>(istream &in, vector<T> &a) {
    for(auto &x : a) in >> x;
    return in;
}
// scan pair
template <typename T, typename U> 
inline istream &operator>>(istream &in, pair<T,U> &a) {
    in >> a.first >> a.second; 
    return in;
}

// Solve --------------------------------------------------------------------

void solve(int &T)
{
    ll n;
    cin>>n;
    
    vector<ll> a(n);
    cin>>a;

    sort(rall(a));
    vector<ll> b;
    loop(n)
    {
        b.push_back(a[i]);
        if(i) b.push_back(a[i]);
    }
    d(b);
    
    ll ans = 0;
    loop(n-1) ans += b[i];
    cout<<ans<<endl;
}

// Main ---------------------------------------------------------------------

int main()
{
    #ifdef Dhiraj
        freopen("D:/dhiraj/Programming/i1.txt","r",stdin);
        freopen("D:/dhiraj/Programming/o1.txt","w",stdout);
    #endif

    ios::sync_with_stdio(false);
    cin.tie(0);

    int t = 1;
    for(int i=1; i<=t; i++)
    {
        cerr<<"Case #"<<i<<"\n";
        solve(i);
    }
    return 0;
}

Measured memory_bytes: 8940
#include <stdio.h>
#include <string.h>
char s[110];
int main(){
	int k,n,i;
	scanf("%d%s",&k,s+1);
	n=strlen(s+1);
	if(n<=k)printf("%s\n",s+1);
	else{
		for(i=1;i<=k;i++)printf("%c",s[i]);
		printf("...\n");
	}
  return 0;
}

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

long long comb(long long n, long long r){
    return std::min(n - r, r) * n;
}


int main()
{
    int n; std::cin >> n;
    std::vector<long long> a(n);
    for(int i = 0; i < n; i++)std::cin >> a[i];
    std::sort(a.begin(),a.end());
    long long max = 0;
    std::pair<long long, long long> max_set;

    for(int i = 0; i < n-1; i++){
        if(max <= comb(a[n - 1], a[i])){
            max_set.first = a[n - 1];
            max_set.second = a[i];
            max = comb(a[n - 1], a[i]);
        }
    }
    std::cout << max_set.first << " " << max_set.second << std::endl;

}

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

int main(){
	int x,y,z;
    cin>>x>>y>>z;
    int p=(x-2*z)%(y+z);
    int ans=(x-2*z)/(y+z);
    if(p>=y) ans++;
    cout<<ans;
}
  

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

int sort(const void *a,const  void *b)
{
    return *(int *)a - *(int *)b;
}

int main()
{
    int N,i,j;
    scanf("%d",&N);
    int X[N],tmp[N];
    for(i=0;i<N;i++){
        scanf("%d",&X[i]);   
        tmp[i] = X[i];            
    }

    qsort(X,N,sizeof(int),sort);
    
    for(i=0;i<N;i++){
        if( tmp[i] <= X[N/2-1] ){
            printf("%d\n",X[N/2]);
        }else{
            printf("%d\n",X[N/2-1]);
        }
    }

    return 0;

}

Measured memory_bytes: 3692
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <math.h>
#include <iomanip>
#include <cmath>
#include <queue>
#include <stack>
#include <cstdlib>
using namespace std;
#define int long long
#define rep(i,n) for(int i=0;i<n;i++)
#define pie 3.141592653589793238462643383279
#define INF 1000000007
#define ggr getchar(); getchar();return 0;
int gcd(int x, int y) {
	if (y == 0)return x;
	return gcd(y, x%y);
}
int lcm(int x, int y) {
	return x / gcd(x, y)*y;
}

int n, m, k[30], a[30][30], mu;

signed main() {
	cin >> n >> m;
	vector<int> ta(m + 3);
	rep(i, n) {
		cin >> k[i];
		rep(j, k[i]) {
			cin >> a[i][j];
			ta[a[i][j]]++;
		}
	}
	rep(i, ta.size()) {
		if (ta[i] == n)mu++;
	}
	cout << mu << endl;
	ggr
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define mk make_pair
#define fs first
#define sc second
using namespace std;
typedef long long ll;
typedef long double ld;
ll mem[4010][4010], rd[4010], bl[4010], n;
const ll mod=998244353;
ll dp(int x, int red){
    if(x==2*n){
        return 1;
    }
    if(mem[x][red]!=-1){
        return mem[x][red];
    }
    ll res;
    res=(ll)((bl[x]-x+red+1)>0)*dp(x+1, red)+(ll)((rd[x]-red)>0)*dp(x+1, red+1);
    res%=mod;
    mem[x][red]=res;
//    cout<<x<<" "<<red<<" "<<res<<endl;
    return res;
}
char s[40010];
int main(){
    scanf("%s", s);
    n=strlen(s);
//    reverse(s, s+n);
    for(int i=0; i<2*n; ++i){
        rd[i+1]=rd[i];
        bl[i+1]=bl[i];
        if(i<n){
            if(s[i]=='0'){
                rd[i+1]+=2;
            }
            else if(s[i]=='1'){
                rd[i+1]+=1;
                bl[i+1]+=1;
            }
            else{
                bl[i+1]+=2;
            }
        }
    }
    memset(mem, -1, sizeof mem);
    ll ans=dp(1, 0);
    cout<<ans<<endl;
    return 0;
}





Measured memory_bytes: 126208
N=int(input())
a=[]
for i in range(N):
    a.append(int(input()))

L_max=[0]*(N+1)
R_max=[0]*(N+1)

L=0
for i in range(N):
    L=max(L,a[i])
    L_max[i]=L

R=0
for i in range(N):
    R=max(R,a[-i-1])
    R_max[i]=R

for j in range(N):
    print(max(L_max[j-1],R_max[N-j-2]))



Measured memory_bytes: 15636
#include <iostream>
#include <cstdio>
#include <cmath>
#include <string>
using namespace std;

string func(int s, int l){
	double h = s*30.0 + l/2.0, m = l*6;
	int ang = abs(h - m);
	if(ang > 180) ang = 360 - ang;
	
	if(0 <= ang && ang < 30)return "alert";
	if(90 <= ang && ang <= 180)return "safe";
	return "warning";
}
 
int main() {
	int n, s, l; cin >> n;
	char c;
	while(n--) {
		cin >> s >> c >> l;
		cout << func(s, l) << endl;
	}
  	return 0;
}

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

public class Main {
    public static void main(String[] args) {
        try (InputReader in = new InputReader(); PrintWriter out = new PrintWriter(System.out)) {
            new Main().solve(in, out);
            out.flush();
        }
    }

    private void solve(InputReader in, PrintWriter out) {
        long n = in.nextLong();
        long min = Long.MAX_VALUE;
        for (long i = 0; i < 5; i++) {
            min = Math.min(in.nextLong(), min);
        }

        out.println((long) Math.ceil((double) n / min) + 4);
    }
}

class InputReader implements AutoCloseable {
    private final Scanner sc = new Scanner(System.in);

    String next() {
        return this.sc.next();
    }

    int nextInt() {
        return Integer.parseInt(this.sc.next());
    }

    long nextLong() {
        return Long.parseLong(this.sc.next());
    }

    double nextDouble() {
        return Double.parseDouble(this.sc.next());

    }

    @Override
    public void close() {
        this.sc.close();
    }
}


Measured memory_bytes: 21972
#include<iostream>
#include<bits/stdc++.h>
#include<algorithm>
using namespace std;
using ll=long long;
int main()
{
    int a,b,c,rafi=0,ans;
    cin>>a>>b>>c;
    a=a-b;
    rafi=a%c;
    cout<<rafi<<endl;
    return 0;
}


Measured memory_bytes: 256
{-# LANGUAGE BangPatterns #-}
{-# LANGUAGE OverloadedStrings #-} 
import Data.Text.Lazy as T
import Data.Text.Lazy.IO as TIO
import Data.Monoid
import Data.List

main = do
  input <- TIO.getContents
  let ls = T.lines input 
      n = ls !! 0
      l :: [Int]
      l =   fmap ( read .T.unpack) $ T.words $ ls !! 1      
      (!s0,!s2,!s4) = Prelude.foldl f (0,0,0) l
        where f  (s0,s2,s4) a  | (a `mod` 4) == 0 = (s0, s2, s4 + 1)
                               | (a `mod` 2 ) == 0 =  (s0, s2 + 1, s4)
                               | otherwise =  (s0 + 1, s2 , s4)
      getR (s0,s2,s4) | (s0<=s4) || ( s0 == s4+1 && s2 == 0 ) = "Yes"  
                      | otherwise = "No"
  Prelude.putStr $  getR (s0,s2,s4)

Measured memory_bytes: 7804
N=int(input())
A = [int(input()) for i in range(N)]
A.sort()

l = 0
m = 1
ans = 0

for l in range(N-1):
	if A[l] == A[l+1]:
		m += 1
	else:
		ans += m%2
		m = 1
if A[N-1] != A[N-2]:
	ans += 1
else:
	ans += m%2
print(ans)

Measured memory_bytes: 7388
#include <bits/stdc++.h>
using namespace std;
using lint = long long int;
using P = pair<int, int>;
using PL = pair<lint, lint>;
#define FOR(i, begin, end) for(int i=(begin),i##_end_=(end);i<i##_end_;i++)
#define IFOR(i, begin, end) for(int i=(end)-1,i##_begin_=(begin);i>=i##_begin_;i--)
#define REP(i, n) FOR(i,0,n)
#define IREP(i, n) IFOR(i,0,n)
#define ALL(a)  (a).begin(),(a).end()
constexpr int MOD = 1000000007;
constexpr int INF = 2147483647;
void yes(bool expr) {cout << (expr ? "Yes" : "No") << "\n";}
int main()
{
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  int N;
  cin >> N;
  vector<lint> A(N);
  REP(i,N) {
    double x;
    cin >> x;
    A[i] = (lint)(x * 1000000000LL + 0.5);
  }
  lint ans = 0;
  vector<vector<lint>> num(19, vector<lint>(19));
  REP(x, 19) REP(y, 19) num[x][y] = pow(2LL, (lint)x) * pow(5LL, (lint)y);
  vector<vector<lint>> cnt(19, vector<lint>(19));
  REP(i, N) {
    lint tmp = A[i];
    lint s = 0;
    lint t = 0;
    while(tmp > 0 && tmp%2 == 0) {
      s++;
      tmp /= 2;
    }
    while(tmp > 0 && tmp%5 == 0) {
      t++;
      tmp /= 5;
    }
    ans += cnt[18-min(18LL, s)][18-min(18LL, t)];
    IREP(x, 19) IREP(y, 19) {
      if(A[i]%num[x][y] == 0) {
        cnt[x][y]++;
      }
    }
  } 
  cout << ans << endl;
}

Measured memory_bytes: 4996
n = int(input())
a = list(map(int, input().split()))

k = 0

for i in range(0, n):
    minj = i
    for j in range(i, n):
        if a[j] < a[minj]:
            minj = j
    if i != minj:
        k += 1
        t = a[i]
        a[i] = a[minj]
        a[minj] = t
for i in range(0, n - 1):
    print(a[i], end=' ')
print(a[n - 1])
print(k)


Measured memory_bytes: 5608
import Data.List

cnv l = sortBy (\[i0,v0] [i1,v1] -> let cv = compare v1 v0
                                        ci = compare i0 i1
                                    in
                                      if ci /= EQ
                                      then ci
                                      else cv ) l

ans' _ [] _ = []
ans' n (l:ls) c =
  let a = take l $ takeWhile (\[i,_] -> i == n) c
      c'= dropWhile (\[i,_] -> i == n) c
  in
    a ++ (ans' (n+1) ls c')

ans m l c =
  let c'= cnv c
      a = ans' 1 l c'
      t = take m $ sortBy (\[_,v0] [_,v1] -> compare v1 v0) a
      s = sum $ map (\[_,v] -> v) t
  in
    s

main = do
  [_,m,_] <- fmap (map read . words) getLine :: IO [Int]
  l <- fmap (map read . words) getLine :: IO [Int]
  c <- fmap (map (map read) . map words . lines) getContents :: IO [[Int]]
  let o = ans m l c
  print o



Measured memory_bytes: 94212
#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() {
    int64_t n, a, b;
    cin >> n >> a >> b;
    int64_t ans = 0;
    while (a != b) {
        if ((b - a) % 2 == 0) {
            ans += (b - a) / 2;
            break;
        }
        if (a - 1 < n - b) {
            int64_t move = a - 1;
            a -= move;
            b -= move;
            ans += move;
            if (a == b) break;
        }
        else {
            int64_t move = n - b;
            b += move;
            a += move;
            ans += move;
            if (a == b) break;
        }
        if (a == 1 && (b - a) % 2 == 1) {
            b--;
            ans++;
            if (a == b) break;
        }
        if (b == n && (b - a) % 2 == 1) {
            a++;
            ans++;
            if (a == b) break;
        }
    }
    cout << ans << endl;
}

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

int main(){
    int a[5];
    for (int i =0; i < 5; i++) {
        cin >> a[i];
    }
    int k;
    cin >> k;
    sort(a, a+5);
    if ( (a[4]-a[0]) <= k ) cout << "Yay!" << endl;
    else cout << ":(" << endl;
    return 0;
}

Measured memory_bytes: 256
#ifdef _MSC_VER
#include <__msvc_all_public_headers.hpp>
#undef min
#undef max
#include "atcoder/all"
#else
#define NDEBUG
#include <atcoder/all>
#include <bits/stdc++.h>
#endif

using namespace std;
using namespace atcoder;
using large = long long;

int op(int a, int b) { return max(a, b); }
int e() { return 0; }

int main()
{
    int n, k;
    cin >> n >> k; // 300'000
    auto a = vector<int>(n);
    for (auto& a_i : a) {
        cin >> a_i;
    }

    auto maxlen = segtree<int, op, e>(300'005);

    for (int i = 0; i < n; ++i) {
        auto x = a[i];
        auto l = max(0, x - k);
        auto u = min(300'000, x + k);
        auto len = maxlen.prod(l, u + 1) + 1;
        if (maxlen.get(x) < len) {
            maxlen.set(x, len);
        }
    }

    cout << maxlen.all_prod() << endl;
    return 0;
}


Measured memory_bytes: 9632
import sys
sr = lambda: sys.stdin.readline().rstrip()
ir = lambda: int(sr())
lr = lambda: list(map(int, sr().split()))
from collections import Counter
def resolve():
    N, K, C = lr()
    S = [i+1 for i, s in enumerate(sr()) if s == 'o']
    l = [S[0]]
    for i in S[1:]:
        if l[-1]+C >= i or len(l) > K:
            continue
        l.append(i)
    S = S[::-1]
    r = [S[0]]
    for i in S[1:]:
        if r[-1]-C <= i or len(r) > K:
            continue
        r.append(i)
    r = r[::-1]
    for i in range(K):
        if l[i] == r[i]:
            print(l[i])
resolve()

Measured memory_bytes: 66888
#include <bits/stdc++.h>
using namespace std;
 
bool SecondCompare(const pair<int,int> &a,const pair<int,int> &b)
{
       return a.second<b.second;
}
 
bool SecondCompareDes(const pair<int,int> &a,const pair<int,int> &b)
{
       return a.second>b.second;
}
 
long long x;
long long ans;
int main(){
    cin >> x;
    ans = x/11;
    ans*= 2;
    if(x%11 != 0){
        if(x%11 <= 6)   ++ans;
        else ans += 2;
    }
    cout << ans << endl;
}

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

#define REP(i,s,n) for(int i=s;i<n;i++)
#define rep(i,n) REP(i,0,n)

using namespace std;

int n,k,w[100010];

bool check(int x){
  int cnt = 1,sum=0;
  rep(i,n){
    if( w[i] > x ) return false;
    if( sum + w[i] <= x ) sum += w[i];
    else{
      sum = w[i];
      cnt++;
    }
  }
  return cnt <= k;
}

int main(){
  cin >> n >> k;
  rep(i,n) cin >> w[i];
  int L=0,R=100000*10000+10,M=0;
  while(L+1<R){
    M = ( L + R ) / 2;
    if( check(M) ) R = M;
    else           L = M;
  }
  cout << R <<endl;
  return 0;
}

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

int main(){
  
int a,b,c,X,sum,count;

cin >> a >> b >> c >> X;
count=0;

    for(int i=0; i<=a; i++){
        for(int j=0; j<=b; j++){
            for(int k=0; k<=c; k++){
                sum=i*500+j*100+k*50;
                if(sum == X)count++;
            }
        }
    }

    cout<< count <<endl;
}

Measured memory_bytes: 256
package main

import (
	"fmt"
)

func main() {
	var N int
	fmt.Scan(&N)
	heights := scanNums(N)
	cnt := 1

MNTS:
	for i := 1; i < N; i++ {
		for j := 0; j < i; j++ {
			if heights[j] > heights[i] {
				continue MNTS
			}
		}
		cnt++
	}

	fmt.Println(cnt)
}

func scanNums(length int) (nums []int) {
	var num int
	for i := 0; i < length; i++ {
		fmt.Scan(&num)
		nums = append(nums, num)
	}
	return
}


Measured memory_bytes: 512
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int m = sc.nextInt();
        if (n == m) {
            System.out.println("Yes");
            return;
        }
        System.out.println("No");
    }

}


Measured memory_bytes: 23508
#include <bits/stdc++.h>
#define fi first
#define se second
#define pii pair<int,int>
#define mp make_pair
#define pb push_back
#define space putchar(' ')
#define enter putchar('\n')
#define eps 1e-10
#define MAXN 100005
//#define ivorysi
using namespace std;
typedef long long int64;
typedef unsigned int u32;
typedef double db;
template<class T>
void read(T &res) {
    res = 0;T f = 1;char c = getchar();
    while(c < '0' || c > '9') {
	if(c == '-') f = -1;
	c = getchar();
    }
    while(c >= '0' && c <= '9') {
	res = res * 10 +c - '0';
	c = getchar();
    }
    res *= f;
}
template<class T>
void out(T x) {
    if(x < 0) {x = -x;putchar('-');}
    if(x >= 10) {
	out(x / 10);
    }
    putchar('0' + x % 10);
}
int K,N;
char s[MAXN];
void Solve() {
    scanf("%s",s + 1);
    read(K);
    N = strlen(s + 1);
    for(int i = 1 ; i <= N ; ++i) {
	int t = s[i] - 'a';
	if(t != 0) {
	    if(K >= 26 - t) {s[i] = 'a';K -= (26 - t);}
	}
    }
    K %= 26;
    int t = s[N] - 'a';
    t = (t + K) % 26;
    s[N] = 'a' + t;
    for(int i = 1 ; i <= N ; ++i) {
	putchar(s[i]);
    }
    enter;
}

int main() {
#ifdef ivorysi
    freopen("f1.in","r",stdin);
#endif
    Solve();
    return 0;
}


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

int n;
vector<int> a(100);

void insertionSort(vector<int> a, int n){
    for (int i = 1; i<n; i++){
        int v = a[i];
        int j = i-1;
        while (j >= 0 && a[j] > v){
            a[j+1] = a[j];
            j--;
        }
        a[j+1] = v;
        rep(j, n-1){
            cout << a[j] << " ";
        }
        cout << a[n-1] <<endl;
    }
}

int main(){
    cin>>n;
    rep(i, n) cin>>a[i];
    rep(i, n-1){
        cout << a[i] << " ";
    }
    cout << a[n-1] <<endl;
    insertionSort(a, n);
    return 0;
}


Measured memory_bytes: 3152
#include <iostream>
#include <vector>
#include <string>
#include <cmath>
#include <numeric>
#include <algorithm>
//#include <iomanip> : 表示桁数

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

int N;
string S;
string ans = "Yes";

int main() {
	cin >> N >> S;
	if (N % 2 == 0) {
		rep(i, (N / 2)) {
			if (S[i] != S[i + (N/2)]) {
				ans = "No";
				break;
			}
		}
	}
	else {
		ans = "No";
	}

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


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, n) for(int i = 0; i < n; ++i)
#define rrep(i, n) for(int i = n-1; i >= 0; --i)
#define fi first
#define se second
using namespace std;
typedef long long lint;
typedef unsigned int uint;
typedef unsigned long long ulint;
typedef long double ldouble;
using pii = pair<int, int>;
using pli = pair<lint, lint>;
using pdd = pair<double, double>;
using pld = pair<ldouble, ldouble>;
using v1i = vector<int>;
using v1li = vector<lint>;
using v2i = vector<vector<int>>;
using v2li = vector<vector<lint>>;
using v3i = vector<vector<vector<int>>>;
using v3li = vector<vector<vector<lint>>>;
using v1b = vector<bool>;
using v2b = vector<vector<bool>>;
using v3b = vector<vector<vector<bool>>>;
constexpr lint mod1 = 1e9+7;

int main() {
  int h, w, m = 0;
  cin >> h >> w;
  v2i a(h, v1i(w)), b(h, v1i(w));
  rep(i, h) rep(j, w){
    cin >> a[i][j];
    m = max(m, a[i][j]);
  }
  rep(i, h) rep(j, w){
    cin >> b[i][j];
    m = max(m, b[i][j]);
  }
  v3b dp(h, v2b(w, v1b((h+w)*m+1, 0)));
  rep(i, h) rep(j, w){
    if(i == 0 && j == 0) dp[i][j][abs(a[i][j]-b[i][j])] = 1;
    else if(i == 0){
      rep(k, (h+w)*m+1) if(dp[i][j-1][k]){
        dp[i][j][k+abs(a[i][j]-b[i][j])] = 1; dp[i][j][abs(k-abs(a[i][j]-b[i][j]))] = 1;
      }
    }
    else if(j == 0){
      rep(k, (h+w)*m+1) if(dp[i-1][j][k]){
        dp[i][j][k+abs(a[i][j]-b[i][j])] = 1; dp[i][j][abs(k-abs(a[i][j]-b[i][j]))] = 1;
      }
    }
    else{
      rep(k, (h+w)*m+1){
        if(dp[i][j-1][k]){
        dp[i][j][k+abs(a[i][j]-b[i][j])] = 1; dp[i][j][abs(k-abs(a[i][j]-b[i][j]))] = 1;
        }
        if(dp[i-1][j][k]){
        dp[i][j][k+abs(a[i][j]-b[i][j])] = 1; dp[i][j][abs(k-abs(a[i][j]-b[i][j]))] = 1;
        }
      }
    }
  }
  rep(i, (h+w)*m+1) if(dp[h-1][w-1][i]){
    cout << i << endl;
    break;
  }
  return 0;
}

Measured memory_bytes: 10752
//Volume0-0060
import java.util.*;

public class Main {

	public static void main(String[] args) {
		
		//declare
		String[] s;
		int C1,C2,C3,less;
		
		//input
		Scanner sc = new Scanner(System.in);
		while(sc.hasNext()){
			s = sc.nextLine().split("\\s");
			C1 = Integer.parseInt(s[0]);
			C2 = Integer.parseInt(s[1]);
			C3 = Integer.parseInt(s[2]);

			//calculate
			less=0;
			for(int i=1;i<=10;i++){
				if(i != C1 &&
				   i != C2 &&
				   i != C3 &&
				   i + C1 + C2 <= 20 ){
						less++;
				}
			}
			
			//output
			if   (3 < less){System.out.println("YES");}
			else           {System.out.println("NO"); }
		}
	}
}

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

struct T
{
	int x1, x2, x3, x4;
};

int main() {
	int h, w;
	cin >> h >> w;
	int a[h][w];
	for (int i = 0; i < h; i++) {
		for (int j = 0; j < w; j++) {
			cin >> a[i][j];
		}
	}
	vector<T> ans;
	for (int i = 0; i < h; i++) {
		for (int j = 0; j < w-1; j++) {
			if (a[i][j] & 1) {
				a[i][j]--;
				a[i][j+1]++;
				ans.push_back({i+1, j+1, i+1, j+2});
			}
		}
	}
	for (int i = 0; i < h-1; i++) {
		int j = w-1;
		if (a[i][j] & 1) {
			a[i][j]--;
			a[i+1][j]++;
			ans.push_back({i+1, j+1, i+2, j+1});
		}
	}
	cout << ans.size() << endl;
	for (T e : ans) {
		cout << e.x1 << ' ' << e.x2 << ' ' << e.x3 << ' ' << e.x4 << endl;
	}
	return 0;
}

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

using namespace std;

typedef long double ld;
typedef long long ll;

#define sz(x) (int)(x).size()
#define pb push_back
#define mp make_pair
#define f first
#define s second

int x, n;
vector<int> vis(300, false);
vector<int> v;
int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cin >> x >> n;
    v.assign(n, 0);
    for(int i = 0; i < n; ++i){
        cin >> v[i];
        vis[v[i]] = true;
    }
    int z = 0;
    while(vis[x - z] && vis[x + z]) z++;
    if(!vis[x - z]) cout << x - z;
    else cout << x + z;
    return 0;
}

Measured memory_bytes: 3656
#include <iostream>
#include <vector>
#include <cmath>
using namespace std;

int main() {
    int N, T, A;
    cin >> N >> T >> A;

    vector<double> H(N);
    for (int i=0; i<N; i++) { cin >> H[i]; }

    int res = 0;
    double min = 1000000000;
    for (int i=0; i<N; i++) {
        double temperature_ave = T - H[i] * 0.006;
        double diff = abs(A - temperature_ave);
        if (diff < min) {
            min = diff;
            res = i;
        }
    }
    cout << ++res << endl;
}

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

int main()
{
    int N;
    cin >> N;
    vector<long long> A(N);
    vector<long long> B(N);
    vector<long long> C(N);
    for (int i=0; i<N; i++) cin >> A[i];
    for (int i=0; i<N; i++) cin >> B[i];
    for (int i=0; i<N; i++) cin >> C[i];
    sort(A.begin(), A.end());
    sort(B.begin(), B.end());
    sort(C.begin(), C.end());

    long long ans = 0;
    for (int i=0 ; i<N; i++)
    {
        long long target_B = B[i];
        long int A_upper = lower_bound(A.begin(), A.end(), target_B) - A.begin();
        long int C_lower = lower_bound(C.begin(), C.end(), target_B +1) - C.begin();
        ans += A_upper * (N - C_lower);
    }

    cout << ans << endl;
}


Measured memory_bytes: 5644
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
int acs(const void *a, const void *b) { 
  return *(int*)a - *(int*)b;
} /* 1,2,3,4.. */
int des(const void *a, const void *b) {
  return *(int*)b - *(int*)a;
} /* 8,7,6,5.. */
int cmp_char(const void *a, const void *b) { 
  return *(char*)a - *(char*)b;
} /* a,b,c,d.. */
int cmp_str(const void *a, const void *b) {
  return strcmp(*(const char **)a, *(const char **)b);
} /* aaa,aab.. */
#define min(a,b) (a < b ? a : b)
#define max(a,b) (a > b ? a : b)
#define rep(i, l, r) for (int i = l; i < r; i++)
#define MAX 200001
#define MOD 1000000007
#define INF 1000000009
typedef long long int lli;

int main(void) {
  int n, m;
  scanf("%d %d", &n, &m);
  int s[MAX] = {0}, e[MAX] = {0};
  rep(i, 0, m) {
    int a, b;
    scanf("%d %d", &a, &b);
    if ( a == 1 ) s[b] = 1;
    if ( b == n ) e[a] = 1;
  }
  rep(i, 2, n) {
    if ( s[i] && e[i] ) {
      printf("POSSIBLE\n");
      return 0;
    }
  }
  printf("IMPOSSIBLE\n");
  return 0;
}


Measured memory_bytes: 1664
import bisect
n=int(input())
s=input()
r=[]
g=[]
b=[]
for i in range(n):
  if s[i]=='R':
    r.append(i)
  elif s[i]=='G':
    g.append(i)
  else:
    b.append(i)
ans=len(r)*len(g)*len(b)
r.append(n*4)
g.append(n*4)
b.append(n*4)
for i in g:
  for j in b:
    a=i+j
    if a%2==0 and r[bisect.bisect_left(r, a//2)]==a//2:
      ans-=1
for i in r:
  for j in b:
    a=i+j
    if a%2==0 and g[bisect.bisect_left(g, a//2)]==a//2:
      ans-=1
for i in g:
  for j in r:
    a=i+j
    if a%2==0 and b[bisect.bisect_left(b, a//2)]==a//2:
      ans-=1
print(ans+3)

Measured memory_bytes: 9336
#include <iostream>
#include <stdio.h>
#include <cmath>
#include <algorithm>
#include <climits>
#include <vector>
#include <iomanip>
#include <string>
#include <queue>
#include <numeric>
#include <functional>
#include <array>
#include <map>
#include <set>

#define INF 1000000007 //1000000000000000003
#define MOD 1000000007
#define MAX 2000005

#define ll long long

//printf("%.10f", );
//cout << fixed << setprecision(10) << heikin << endl;
//vector<vector<int>> data(3, vector<int>(4, -1));
//left + 1 < top

using namespace std;
using P = pair<int, int>;
using Pc = pair<double, int>;
using T = tuple<int, int, int>;
using edge = struct { int to; long long dist; };
const double PI = 3.141592653589793;
long long fact[MAX], inv[MAX];
int dx[] = { -1,0,1,0 };
int dy[] = { 0,-1,0,1 };

//////////////////////////////////

vector<vector<int>> bingo(3, vector<int>(3));
vector<vector<int>> tree(100005);
int color[100005];
map<P, int>colorMap;
int m = 0;

struct BridgeInfo {
	int town1;
	int town2;
	int year;
	BridgeInfo(int t1, int t2, int y) {
		town1 = t1;
		town2 = t2;
		year = y;
	}
};

struct People {
	int index;
	int town;
	int year;
	People(int i, int t, int y) {
		index = i;
		town = t;
		year = y;
	}
};

bool compare_by_second(pair<int, int> a, pair<int, int> b) {
	if (a.second != b.second) {
		return a.second < b.second;
	}
	else {
		return a.first < b.first;
	}
}

struct UnionFind {
	vector<int>uf;

	UnionFind(int size) :uf(size, -1) {};

	int root(int target) {
		if (uf[target] < 0)return target;
		else return uf[target] = root(uf[target]);
	}

	void merge(int a, int b) {
		a = root(a);
		b = root(b);
		if (a == b)return;
		if (uf[b] < uf[a])swap(a, b);
		uf[a] += uf[b];
		uf[b] = a;
	}
};

ll CalcPow(ll num, ll power) {
	if (power == 0)return 1;
	if (power % 2 == 0) {
		ll half = CalcPow(num, power / 2);
		return (half * half) % MOD;
	}
	else return (num * CalcPow(num, power - 1)) % MOD;
}

ll combination(ll all, ll select) {
	if (all < select) return 0;
	if (all < 0 || select < 0) return 0;
	return fact[all] * (inv[select] * inv[all - select] % MOD) % MOD;
}

void initCombination(int max) {
	fact[0] = fact[1] = 1;
	for (int i = 2; i <= max; ++i) {
		fact[i] = fact[i - 1] * i % MOD;
	}

	inv[max] = CalcPow(fact[max], MOD - 2);
	for (int i = max - 1; 0 <= i; --i) {
		inv[i] = (inv[i + 1] * (i + 1)) % MOD;
	}
}

int main() {

	int X, Y, Z;
	cin >> X >> Y >> Z;
	cout << Z << " " << X << " " << Y << endl;
}



Measured memory_bytes: 2560
#include <iostream>
#include <cmath>
#include <utility>
#include <vector>
#include <queue>

using namespace std;

typedef pair<int,int> pii;
typedef long long ll;
#define mp make_pair
#define x first
#define y second

vector<int> veki[100003];
queue<int> q;
int bio[100003];

int main () {
	int n,m;
	cin>>n>>m;
	for(int i=0;i<m;i++){
		int a,b;
		cin>>a>>b;
		veki[a].push_back(b);
		veki[b].push_back(a);
	}
	q.push(1);
	bio[1]=1;
	while(!q.empty()){
		int v=q.front();
		q.pop();
		for(int i=0;i<veki[v].size();i++){
			if(bio[veki[v][i]]) continue;
			bio[veki[v][i]]=v;
			q.push(veki[v][i]);
		}
	}
	cout<<"Yes"<<endl;
	for(int i=2;i<=n;i++){
		cout<<bio[i]<<endl;
	}



return 0;
}



Measured memory_bytes: 10404
#include <bits/stdc++.h>
using namespace std;
//#pragma GCC optimize("Ofast")
#define rep(i,n) for(long long i=0;i<(long long)(n);i++)
#define REP(i,k,n) for(long long i=k;i<(long long)(n);i++)
#define all(a) a.begin(),a.end()
#define eb emplace_back
#define lb(v,k) (lower_bound(all(v),k)-v.begin())
#define ub(v,k) (upper_bound(all(v),k)-v.begin())
#define fi first
#define se second
#define pi M_PI
#define PQ(T) priority_queue<T>
#define SPQ(T) priority_queue<T,vector<T>,greater<T>>
using ll=long long;
using P=pair<ll,ll>;
using PP=tuple<ll,ll,ll>;
using S=multiset<ll>;
using vi=vector<ll>;
using vvi=vector<vi>;
using vvvi=vector<vvi>;
const ll inf=1001001001001001;
const int INF=1001001001;
const int mod=1000000007;
const double eps=1e-10;
template<class T> bool chmin(T&a,T b){if(a>b){a=b;return true;}return false;}
template<class T> bool chmax(T&a,T b){if(a<b){a=b;return true;}return false;}
template<class T> void out(T a){cout<<a<<'\n';}
template<class T> void outp(T a){cout<<'('<<a.fi<<','<<a.se<<')'<<'\n';}
template<class T> void outvp(T v){rep(i,v.size())cout<<'('<<v[i].fi<<','<<v[i].se<<')';cout<<'\n';}
template<class T> void outv(T v){rep(i,v.size()){if(i)cout<<' ';cout<<v[i];}cout<<'\n';}
template<class T> void outvv(T v){rep(i,v.size())outv(v[i]);}
template<class T> bool isin(T x,T l,T r){return (l)<=(x)&&(x)<=(r);}
template<class T> void YesNo(T b){if(b)out("Yes");else out("No");}
void decimal(int x){cout<<fixed<<setprecision(x);}
//ll GCD(ll a,ll b){if(b==0) return a; return GCD(b,a%b);}
//ll LCM(ll a,ll b){return(a/GCD(a,b))*(b/GCD(a,b))*GCD(a,b);}
ll POW(ll a,ll b){a%=mod;if(b==0)return 1;if(b&1)return a*POW(a,b-1)%mod;ll k=POW(a,b/2);return k*k%mod;}
vi calc(ll x){vi res;while(x>0){res.eb(x%10);x/=10;}reverse(all(res));return res;}

void solve(){
  int x,n;
  cin>>x>>n;
  if(n==0){
    out(x); return;
  }
  vi p(n);
  rep(i,n) cin>>p[i];
  set<int> s;
  rep(i,n){
    s.insert(p[i]);
  }
  rep(i,100){
    if(!s.count(x-i)){
      out(x-i); return;
    }
    if(!s.count(x+i)){
      out(x+i); return;
    }
  }
}

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


Measured memory_bytes: 3652
#include <iostream>
#include <stdio.h>
#include <algorithm>
#include <cmath>
#include <string>
#include <vector>
#include <iomanip>
#include <queue>
#include <deque>
#include <map>
#include <unordered_map>
#define rep(i,n) for(int i=0;i<n;i++)
#define repn(i,n) for(int i=1;i<=n;i++)
#define repr(e,x) for(auto& e:x)
using namespace std;
typedef long long ll;
typedef long double ld;
//typedef pair<ll,ll> P;
//ll const INF=1001001001;
//ll const INF=1001001001001001001;
ll const MOD=1000000007;

int N;
int C[501];
int S[501];
int F[501];

int main(){
    cin>>N;
    rep(i,N-1) cin>>C[i]>>S[i]>>F[i];

    rep(i,N){
        int ans=S[i];
        rep(j,N-i-1){
            int wait=(F[i+j]-ans%F[i+j])%F[i+j];
            ans+=wait;
            if(ans<S[i+j]) ans=S[i+j];
            ans+=C[i+j];
        }
        cout<<ans<<endl;
    }
}

Measured memory_bytes: 3628
#include <iostream>
using namespace std;
int main(void){
    // Your code here!
    int h,m,s;
    
    cin >> s;
    
    h = s/3600; s = s % 3600;
    m = s/60; s = s % 60;
    
    cout << h << ":" << m << ":" << s << endl;
    
    return 0;
}



Measured memory_bytes: 3100
#!/usr/bin/env python3

MOD = 10 ** 9 + 7

def main():
    n, m = map(int, input().split())
    x = list(map(int, input().split()))
    y = list(map(int, input().split()))
    print(eq6_1(x) * eq6_1(y) % MOD)

def eq6_1(x):
    n = len(x)
    res = 0
    for j in range(n):
        res += j * x[j]
        res %= MOD
    for i in range(n):
        res -= (n - i - 1) * x[i]
        res %= MOD
    return res

if __name__ == "__main__":
    main()


Measured memory_bytes: 18576
#include <cstdio>
#include<iostream>
#include<cmath>
#include<queue>
#include<algorithm>
#include<cstring>
#include<string>
#include<vector>
#define MAXN 100003
int a[MAXN];
using namespace std;



int main(){
    int n;
    cin >> n;
    for(int i=0; i<n; i++){
        cin >> a[i];
    }
    sort(a, a+n);
    int cnt;
    vector<int> vi;
    for(int i=0; i<n-1;){
        int index=i;
        cnt = 1;
        while(a[index]==a[index+1]){
            cnt++;
            index++;
        }
        i = i+cnt;

        if(cnt%2==0) vi.push_back(0);
        else vi.push_back(1);
    }
    int ans=0;
    for(int i=0; i<vi.size(); i++){
        if(vi[i] == 1)
            ans++;
    }
    if(a[n-1]!=a[n-2]) ans++;
    cout << ans;

    return 0;
}


Measured memory_bytes: 1276
#include <bits/stdc++.h>
using namespace std;
struct ios_accelerate { ios_accelerate() { ios::sync_with_stdio(false); cin.tie(nullptr); } } CALL;

#define REP(i, n) for(auto (i) = (n)*0; (i) < (n); (i)++)
#define RNG(i, a, b) for(auto (i) = (a); (i) < (b); (i)++)
#define RBF(i, v) for(auto& (i) : (v))
#define ALL(x) (x).begin(), (x).end()

using LL = long long;
using UL = unsigned long;
using ULL = unsigned long long;
template<typename T> using V = vector<T>;
template<typename T> using VV = vector<vector<T>>;
template<typename T> using P = pair<T, T>;

const double PI = 3.141592653589793;
const int MOD = 1000000007;
const LL INF64 = static_cast<LL>(1e18) + 2;
const int INF = static_cast<int>(1e9) + 2;

template<typename T> inline void upsort(vector<T>& x) { sort(x.begin(), x.end()); }
template<typename T> inline void downsort(vector<T>& x) { sort(x.begin(), x.end(), greater<T>()); }
template<typename T> inline void col(T x) { cout << x << '\n'; }
template<> inline void col(double x) { cout << fixed << setprecision(12) << x << '\n'; }

signed main() {
	int n;
	cin >> n;
	string s;
	map<string, int> poll;
	int pmax = 0;
	REP(i, n) {
		cin >> s;
		if (poll.find(s) == poll.end()) {
			poll[s] = 1;
		}
		else {
			poll[s]++;
		}
		pmax = max(pmax, poll[s]);
	}

	RBF(p, poll) {
		if (p.second == pmax) {
			col(p.first);
		}
	}

	return 0;
}


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

using namespace std;

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

  int N, W;
  cin >> N >> W;
  vector<int> w(N);
  vector<long long> v(N);

  for (int i = 0; i < N; ++i) {
    cin >> w[i] >> v[i];
  }

  vector<vector<long long>> dp(W+1, vector<long long>(N));

  for (int i = 1; i <= W; ++i) {
    dp[i][0] = (i >= w[0]) ? v[0] : 0;
    for (int j = 1; j < N; ++j) {
      if (w[j] > i)
        dp[i][j] = dp[i][j-1];
      else
        dp[i][j] = max(dp[i][j-1], dp[i-w[j]][j-1] + v[j]);
    }
  }

  cout << dp[W][N-1] << '\n';

  return 0;
}


Measured memory_bytes: 82304
N = int(input())
R = []
G = []
B = []
s =input()
ans = 0
for i in range(N):
    if s[i] == "R":
        R.append(i)
    elif s[i] == "G":
        G.append(i)
    else:
        B.append(i)
sB = set(B)
ans = len(R) * len(G) * len(B)
for r in R:
    for g in G:
        i = min(r,g)
        j = max(r,g)
        sa = j - i
        if i - sa in sB:
            ans -= 1
        if j + sa in sB:
            ans -= 1
        if (i + j) / 2 in sB:
            ans -= 1
print(ans)

Measured memory_bytes: 9340
//#pragma comment(linker, "/STACK:134217728")

#include <iostream>
#include <sstream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <memory>
#include <cctype>
#include <cstring>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
#include <algorithm>
#include <numeric>
using namespace std;

typedef long long Int;
typedef pair<int,int> PII;
typedef vector<int> VInt;

#define FOR(i, a, b) for(i = (a); i < (b); ++i)
#define RFOR(i, a, b) for(i = (a) - 1; i >= (b); --i)
#define CLEAR(a, b) memset(a, b, sizeof(a))
#define SIZE(a) int((a).size())
#define ALL(a) (a).begin(),(a).end()
#define PB push_back
#define MP make_pair

int main()
{
	int n;
	cin >> n;
	vector<pair<string, int>> v(n);
	int i;
	FOR(i, 0, n) cin >> v[i].first >> v[i].second;
	string s;
	cin >> s;
	FOR(i, 0, n)
		if (v[i].first == s)
			break;
	int res = 0;
	FOR(i, i + 1, n)
		res += v[i].second;

	cout << res << endl;
	return 0;
};


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

int main(){
	int n;
	cin>>n;
	map<int,int> d;
	for(int i=0;i<n;i++){
		int a;
		cin>>a;
		d[a]++;
	}
	
	int m;
	cin>>m;
	for(int i=0;i<m;i++){
		int b;
		cin>>b;
		d[b]--;
		if(d[b]<0){
			cout<<"NO"<<endl;
			return 0;
		}
	}
	
	cout<<"YES"<<endl;
	
	
	return 0;
}

Measured memory_bytes: 9600
n = int(input())
s = list(map(str, input().split()))

count = [0] * 4

for i in range(n):
    if(s[i] == 'G'):
        count[0] = 1
    elif(s[i] == 'W'):
        count[1] = 1
    elif(s[i] == 'P'):
        count[2] = 1
    elif(s[i] == 'Y'):
        count[3] = 1

total = 0
for i in range(4):
    total += count[i]

if(total == 3):
    print('Three')
elif(total == 4):
    print('Four')

Measured memory_bytes: 3064
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define INF 2e9
#define MOD 1000000007
#define ALL(v) v.begin(), v.end()
using namespace std;
typedef long long ll;
using P = pair<int,int>;
  
int main()
{
  int N;
  cin >> N;

  int B[N]={0};
  vector<int> A(N-1);
  REP(i, N-1){
    cin >> A[i];
    B[A[i]-1]++;
  }
  
  REP(i,N){
    cout << B[i] << endl;
  }
}

Measured memory_bytes: 4788
#include <iostream>
#include <vector>
 
using namespace std;
 
int main(int argc, char* argv[]) {
  vector<int> dice;
 
  for (int i = 0; i < 6; i++) {
    int in; cin >> in;
    dice.push_back(in);
  }
   
  string action; cin >> action;
  int len = action.length();
 
  int d[6] = {1, 5, 3, 2, 4, 6};  // top, N, E, S, W, bottom
  for (int i = 0; i < len; i++) {
      int top = d[0];
      int N = d[1];
      int E = d[2];
      int S = d[3];
      int W = d[4];
      int bottom = d[5];
      if (action[i] == 'N') {
    d[5] = N; d[3] = bottom; d[1] = top; d[0] = S;
      } else if (action[i] == 'S') {
    d[5] = S; d[3] = top; d[1] = bottom; d[0] = N;
      } else if (action[i] == 'E') {
    d[2] = top; d[4] = bottom; d[5] = E; d[0] = W;  
      } else if (action[i] == 'W') {
    d[2] = bottom; d[4] = top; d[5] = W; d[0] = E;      
      }
  }
 
  cout << dice[d[0]-1] << endl;
  return 0;
}
 

Measured memory_bytes: 3160
#include <bits/stdc++.h>
#include <boost/multiprecision/cpp_int.hpp>
#include <boost/range/adaptor/reversed.hpp>

using namespace std;
typedef long long int ll;

#define PI (acos(-1))
#define REP(i,n) for(ll (i)=0;(i)<(n);(i)++)

#define dump(x)  cerr << #x << " = " << (x) << endl;
#define dumparr(x) cerr << #x ; for(auto elem: x){cerr << " " << elem;} cerr << endl;
#define dumppairs(x) cerr << #x ; for(auto elem: x){cerr << "(" << elem.first << " " << elem.second << ") ";} cerr << endl;
#define dumpline cerr << "**********************" << endl;
#define dumpwline(x) cerr << "******** " << #x << "=" << (x) << " ********" << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;
#define ARRAY_LENGTH(array) (sizeof(array) / sizeof(array[0]))

int main(void){
    ll n; cin >> n;
    string s; cin >> s;
    string new_s;
    for(auto c: s){
        if (c + n > 'Z'){
            new_s.push_back(c+n-26);
        } else {
            new_s.push_back(c+n);
        }
    }
    cout << new_s << endl;
    return 0;
}

Measured memory_bytes: 256
//#define _GLIBCXX_DEBUG
#include<bits/stdc++.h>
//#include<cstdio>//"scanf("%lf",&(double));printf("%f",(double));"
//#include<iomanip>//"cout<<fixed<<setprecision(n)<<sth<<endl;"
//#include<string>//"reverse(s's it,s's it)"
//#include<functional>//"greater<T>" "sort(a,a+n,greater<int>());""
//#include<cmath>//"abs" "sqrt"
//#include<numeric>//"accumulate(inputit,inputit,init,(optional) object)"
//#include<algorithm>//"lower_bound(it,it,v)" "next_permutation(a,a+n)"
//"reverse(v's it,v's it)"(v: vector)
//#include<cassert>//"assert(cond);": error if cond doesn't hold.
using namespace std;
#define pb push_back//also for STRING
#define fi first
#define sc second
#define mp make_pair
#define is insert//also use as v.is(v's it,w's it,w's it);//Be careful in topcoder
#define ps push//stack,(priority) queue,//Be careful in topcoder.
#define fr front//queue//for priority, use top().//Be careful in topcoder.
typedef long long ll;//not necessarily//Be careful in topcoder.
typedef pair<int,int> pii;//Be careful in topcoder.
//Add other types in the same way.
const ll M=1000000007;//can be changed
int mod(int a){	return (a+M)%M;	}//M can be a variable
void plmod(ll &a,ll b){	a=(a+b+M)%M;	return;	}
void mnmod(ll &a,ll b){	a=(a-b+M)%M;	return;	}
void mlmod(ll &a,ll b){	a=(a*b)%M;  	return;	}
//Caution! you may need sth larger than "+M"!
void chmax(ll &a,ll b){	a=max(a,b);	return;	}
void chmin(int &a,int b){	a=min(a,b);	return;	}
//These 2 could be better in long long

#define MAX_N 100000

ll x[MAX_N],v[MAX_N],l[MAX_N],r[MAX_N];

int main(){
	int n;
	ll c;
	scanf("%d%lld",&n,&c);
	for(int i=0;i<n;++i) scanf("%lld%lld",&x[i],&v[i]);
	ll s=0;
	for(int i=0;i<n;++i){
		s+=v[i];
		if(i==0) l[0]=max(0ll,s-x[0]);
		else l[i]=max(l[i-1],s-x[i]);
	}
	s=0;
	for(int i=n-1;i>=0;--i){
		s+=v[i];
		if(i==n-1) r[n-1]=max(0ll,s-c+x[n-1]);
		else r[i]=max(r[i+1],s-c+x[i]);
	}
	s=0;
	ll ans=max(l[n-1],r[0]);
	for(int i=0;i<n-1;++i){
		s+=v[i];
		chmax(ans,s-2*x[i]+r[i+1]);
	}
	s=0;
	for(int i=n-1;i>0;--i){
		s+=v[i];
		chmax(ans,s-2*(c-x[i])+l[i-1]);
	}
	printf("%lld\n",ans);
}

Measured memory_bytes: 3328
#include <bits/stdc++.h>
using namespace std;
using Int = long long;
int main()
{
    int N, M; cin >> N >> M;
    vector<vector<bool>> G(N, vector<bool>(N));
    for (int i = 0; i < M; i++) {
        int a, b; cin >> a >> b; a--, b--;
        G[a][b] = G[b][a] = true;
    }
    vector<int> color(N);
    bool fail = false;
    auto recur = [&](auto rec, int node, int t, int& a, int& b) -> void {
        if (fail || color[node] == -t) { fail = true; return; }
        if (color[node] != 0) return;
        color[node] = t;
        if (t > 0) a++; else b++;
        for (int i = 0; i < N; i++) {
            if (node != i && G[node][i] == false) {
                rec(rec, i, -t, a, b);
            }
        }
    };
    vector<pair<int, int>> A;
    int t = 0;
    for (int i = 0; i < N; i++) {
        if (color[i] != 0) continue;
        int a = 0, b = 0;
        recur(recur, i, ++t, a, b);
        A.emplace_back(a, b);
    }
    if (fail) {
        cout << -1 << endl;
    } else {
        vector<bool> dp(N), dp2(N);
        dp[A[0].first] = dp[A[0].second] = true;
        for (int i = 1; i < A.size(); i++) {
            dp2 = vector<bool>(N);
            for (int j = N-1; j >= 0; j--) {
                if (j - A[i].first >= 0) dp2[j] = dp2[j] | dp[j - A[i].first];
                if (j - A[i].second >= 0) dp2[j] = dp2[j] | dp[j - A[i].second];
            }
            swap(dp, dp2);
        }
        for (int i = N/2; i < N; i++) {
            if (dp[i]) {
                int n = i;
                int m = N - n;
                cout << n*(n-1)/2 + m*(m-1)/2 << endl;
                break;
            }
        }
    }
    return 0;
}

Measured memory_bytes: 384
#include<cstdio>
#include<cstdlib>
#include<algorithm>
#include<iostream>
#include<queue>
#include<vector>
#include <bitset>
using namespace std;
#define INF 1000000000000
#define MAX 1000000000000000000
#define MOD 1000000007
typedef long long ll;
typedef pair<ll,int> P;
typedef pair< pair<int,int>, int> p; 
#define bit(n,k) ((n>>k)&1) /*nのk bit目*/

//https://kyopro-friends.hatenablog.com/entry/2019/01/12/231035

bool flag[110000];
vector<int> V[110000];
ll dp[110000][2];

void f(int i){
    if(flag[i]) return;
    flag[i]=true;
    dp[i][0]=1;
    dp[i][1]=1;
    for(int j=0;j<(int)V[i].size();j++){
        int x=V[i][j]; //xはiの子供候補
        if(flag[x]) continue;
        f(x);
        dp[i][0]=(dp[i][0]*(dp[x][0]+dp[x][1])%MOD)%MOD;;
        dp[i][1]=dp[i][1]*dp[x][0]%MOD;;
    }
}

int main(){
    for(int i=0;i<110000;i++){
        flag[i]=false;
    }
    int N;
    cin>>N;
    for(int i=0;i<N-1;i++){
        int a,b;
        cin>>a>>b;
        V[a].push_back(b);
        V[b].push_back(a);
    }
    
    f(1);
    cout<<(dp[1][0]+dp[1][1])%MOD<<endl;
}


Measured memory_bytes: 13184
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main {

	public static void main(String[] args) throws IOException {
		//??????
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		String str;
		int N, debt;
		while ((str = br.readLine()) != null){
			N = Integer.parseInt(str);
			debt = 100000;
			for (int i = 0; i < N; i++) {
				debt = debt  / 1000 * 1050;
				if ((debt % 1000) != 0) {
					debt = debt + (1000 - debt % 1000);
				}
			}
			System.out.println(debt);
		}
	}

}

Measured memory_bytes: 24268
# a,bの最大公約数
def gcd(a, b):
    while b:
        a, b = b, a % b
    return a

# a,bの最小公倍数
def lcm(a, b):
    return a * b // gcd(a, b)


n,m = map(int,input().split())
s = input()
t = input()

lc = lcm(n,m)

dic = {}

for i in range(len(s)):
    dic[lc//n*i] = s[i]
for i in range(len(t)):
    if lc//m*i in dic:
        if dic[lc//m*i] != t[i]:
            print(-1)
            exit()

print(lc)

Measured memory_bytes: 15268
#include <vector>
#include <iostream>
#include <algorithm>
#include <functional>
using namespace std;
int main() {
	int N, K;
	cin >> N >> K;
	vector<int> A(N);
	for (int i = 0; i < N; ++i) cin >> A[i];
	int ans = 0;
	for (int i = 0; i <= N; ++i) {
		for (int j = i; j <= N; ++j) {
			if (N - (j - i) > K) continue;
			vector<int> v;
			for (int k = 0; k < N; ++k) {
				if (k < i || j <= k) {
					v.push_back(A[k]);
				}
			}
			sort(v.begin(), v.end(), greater<int>());
			int rem = K - (N - (j - i));
			while (!v.empty() && rem > 0 && v.back() < 0) {
				v.pop_back();
				--rem;
			}
			int sum = 0;
			for (int k : v) sum += k;
			ans = max(ans, sum);
		}
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define REP(i,n) for(int (i)=0;(i)<(n);(i)++)
using namespace std;
typedef long long ll;
const ll mod = 1e9+7;
#define all(x) (x).begin(),(x).end()

template<class T> inline void chmin(T& a, T b) {
    if (a > b) {
        a = b;
    }
}

template<class T> inline void chmax(T& a, T b) {
    if (a < b) {
        a = b;
    }
}

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    std::cout<<std::fixed<<std::setprecision(10);
    ll N,M,V,P;
    cin >> N >> M >> V >> P;
    vector<ll> A(N);
    REP(i,N)cin >> A[i];
    sort(all(A),greater<ll>());
    ll answer = 0;
    if(V-1<P){
        answer = P;
        for(ll i = P;i<N;i++){
            if(A[P-1] <=A[i] + M)answer++;
        }
    }else{
        answer = P-1;
        vector<ll> SUM(N);
        SUM[P-1] = A[P-1];
        for(ll i = P;i<N;i++){
            SUM[i] = SUM[i-1] + A[i];
        }
        for(ll i = P-1;i<N-V+P;i++){
            if(A[i]+M>=A[P-1]){
                answer++;
            }else{
                break;
            }
        }
        for(ll i = N-V+P;i<N;i++){
            if((A[i]+M)*(1+i-P) >= SUM[i-1]+M*(V-N-P+i+1)&&A[i]+M>=A[P-1]){
                answer++;
            }else{
                break;
            }
        }
    }
    cout <<answer<< "\n";
}

Measured memory_bytes: 1792
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <queue>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <fstream>
#include <cstdlib>
#include <ctime>
#include <string>
#include <cstring>
#include <fstream>
#include <random>
#include <tuple>
#include <climits>

using namespace std;


int main() {
    string s;
    cin>>s;
    if ((s[0] == s[1] && s[1] == s[2] ) || (s[1] == s[2] && s[2] == s[3])) cout<<"Yes\n";
    else cout<<"No\n";
}

Measured memory_bytes: 256