akhauriyash/Code-Regression huggingface dataset:
fun main() = abc165c()

@OptIn(ExperimentalStdlibApi::class)
fun abc165c() {

    val (n, m, q) = readLine()!!.split(' ').map { it.toInt() }
    val abcdList = (1..q).map {
        readLine()!!.split(' ').map { it.toInt() }.let { Abcd(it[0] - 1, it[1] - 1, it[2], it[3]) }
    }

    val answer = combinationsWithReplacement(listOf(1), n, m).map { list ->
        abcdList.filter { (a, b, c) -> list[b] - list[a] == c }.sumBy { it.d }
    }.max()

    println(answer)
}

private fun combinationsWithReplacement(list: List<Int>, n: Int, max: Int): List<List<Int>> {
    return if (list.size < n) (list.last()..max).map { combinationsWithReplacement(list + it, n, max) }.flatten()
    else listOf(list)
}

private data class Abcd(val a: Int, val b: Int, val c: Int, val d: Int)


Measured memory_bytes: 68688
#include<bits/stdc++.h>
using namespace std;
int main()
{
	int ans=0;
	string s,num="CODEFESTIVAL2016";
	cin>>s;
	for(int i=0;i<=s.size();i++)
		if(s[i]!=num[i])ans++;
	cout<<ans<<endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long
#define pb push_back
#define mp make_pair
#define PI acos(-1.0)
#define INF 1000000000
#define pow10 tipa_pow10
using namespace std;
const int mod = 1000 * 1000 * 1000 + 7;
ll ans = 0 , ans2;
int n , a , b;
vector<int> diff;
int main()
{
    ios_base::sync_with_stdio(0);
    bool egual = true;
    cin >> n;
    ll stepsLeft = 0;
    while(n--)
    {
        cin >> a >> b;
        ans += b;
        if(a != b)
            egual = false;
        if(a <= b)
        {
            stepsLeft += b - a;
        }
        else
            diff.pb(b);
    }
    sort(diff.begin() , diff.end());
    if(!egual)
        cout << ans - diff[0];
    else
        cout << 0;


}


Measured memory_bytes: 384
#include <cmath>
#include <math.h>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <algorithm>
#define maxn 1000030
using namespace std;
inline void read(int &x) {
    char ch;
    bool flag = false;
    for (ch = getchar(); !isdigit(ch); ch = getchar())if (ch == '-') flag = true;
    for (x = 0; isdigit(ch); x = x * 10 + ch - '0', ch = getchar());
    x = flag ? -x : x;
}
inline void write(int x) {
    static const int maxlen = 100;
    static char s[maxlen];
    if (x < 0) {   putchar('-'); x = -x;}
    if (!x) { putchar('0'); return; }
    int len = 0; for (; x; x /= 10) s[len++] = x % 10 + '0';
    for (int i = len - 1; i >= 0; --i) putchar(s[i]);
}


int n;
int a[maxn];
int tot4=0;
int tot2=0;
int tot0=0;
int main(){
    read(n);
    for (int i=1;i<=n;i++)
    {
        read(a[i]);
        if (a[i]%4==0)
            tot4++;
        else
            if (a[i]%2==0)
                tot2++;
            else
                tot0++;
    }
    //printf("%d %d %d\n",tot4,tot2,tot0);
    if (  (tot4>=tot0)|| ( (tot4==tot0-1)&& (tot2==0)) )
        puts("Yes");
    else
        puts("No");
    return 0;
}


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

int main(){
    int n;
    cin >> n;
    vector<vector<pair<int,int>>> tr(n+1);
    rep(i,n-1){
        int a,b,c;
        cin >> a >> b >> c;
        tr.at(a).push_back({b, c});
        tr.at(b).push_back({a, c});
    }
    vector<int> cols(n+1);
    vector<int> visited(n+1);
    queue<int> q;
    cols.at(1) = 0;
    visited.at(1) = true;
    q.push(1);
    while(q.size()){
        auto x = q.front(); q.pop();
        for(auto p : tr.at(x)){
            if(visited.at(p.first)) continue;
            if(p.second % 2 == 0) cols.at(p.first) = cols.at(x);
            else cols.at(p.first) = (cols.at(x)+1) % 2;
            visited.at(p.first) = true;
            q.push(p.first);
        }
    }
    rep(i,n){
        cout << cols.at(i+1) << endl;
    }
    return 0;
}

Measured memory_bytes: 7168
#include <iostream>
#include <string>
#include <cmath>
#include <cfloat>

using namespace std;

int main()
{
	int n, t, a;
	cin >> n >> t >> a;
	int *h = new int[n];
	for (int i = 0; i < n; i++) {
		cin >> h[i];
	}

	double min = DBL_MAX;
	int index = 0;
	for (int i = 0; i < n; i++) {
		if (abs(a - (t - 0.006*h[i])) < min) {
			index = i;
			min = abs(a - (t - 0.006*h[i]));
		}
	}

	cout << (index+1) << endl;
}



Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<cstring>
using namespace std;
vector<int> list[100000];
int N, M, E;
int match[100000];
bool used[100000];
int x, y;
 
//?????°???????¢??????????
bool DFS(int V) {
    used[V] = true;
    for (int i = 0; i < list[V].size(); i++) {
        int u = list[V][i]; int w = match[u];
        if (w < 0 || !used[w] && DFS(w)) {
            match[V] = u;
            match[u] = V;
            return true;
        }
    }
    return false;
}
 
int supermatching() {
    int r = 0;
    memset(match, -1, sizeof(match));
    for (int j = 0; j < N + M; j++) {
        if (match[j] < 0) {
            memset(used, 0, sizeof(used));
            if (DFS(j)) { r++; }
        }
    }
    return r;
}
 
int main() {
    cin >> N >> M >> E;
    for (int i = 0; i < E; i++) {
        cin >> x >> y;
        y += N;
        list[y].push_back(x);
        list[x].push_back(y);
    }
    cout << supermatching() << endl;
    return 0;
}

Measured memory_bytes: 6068
#include <stdio.h>

int main(void) {
    int W, H, x, y, r;
    
    scanf("%d %d %d %d %d", &W, &H, &x, &y, &r);
    
    if(x - r >= 0 && x + r <= W){
        if(y - r >= 0 && y + r <= H){
            printf("Yes\n");
        }else{
            printf("No\n");
        }
    }else{
        printf("No\n");
    }
	return 0;
}



Measured memory_bytes: 2084
// Code for B - Count Balls
#include <iostream>
using namespace std;

int main() {
	long long N, A, B;
	cin >> N >> A >> B;
	long long d, r;
	d = N / (A + B);
	r = N % (A + B);
	long long ra = min(A, r);
	long long result = d * A + ra;
	cout << result;
	return 0;
}

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

int A[20];

bool solve( int x, int y, int num ){
  if( y==0 ){
    return true;
  }
  if( x==num ){
    return false;
  }

  bool ret = solve(x+1, y, num) || solve(x+1, y-A[x], num);

  return ret;
}

int main(){
 int n;
 cin >> n;
 for( int i=0; i<n; i++ ){
   cin >> A[i];
 }

 int q;
 cin >> q;
 int m;
 for( int j=0; j<q; j++ ){
   cin >> m;
   if( solve(0, m, n) ){
     cout << "yes" << endl;
   }else{
     cout << "no" << endl;
   }
 }

 return 0;
}


Measured memory_bytes: 3088
//#pragma GCC optimize("Ofast")
//#pragma GCC optimize("unroll-loops")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using db = double;
using ld = long double;
template<typename T> using V = vector<T>;
template<typename T> using VV = vector<vector<T>>;
#define fs first
#define sc second
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define eb emplace_back
#define lb lower_bound
#define ub upper_bound
#define all(v) (v).begin(),(v).end()
#define siz(v) (ll)(v).size()
#define rep(i,a,n) for(ll i=a;i<(ll)(n);++i)
#define repr(i,a,n) for(ll i=n-1;(ll)a<=i;--i)
#define ENDL '\n'
typedef pair<int,int> Pi;
typedef pair<ll,ll> PL;
constexpr ll mod = 1000000007;
constexpr ll INF = 1000000099;
constexpr ll LINF = (ll)(1e18 +99);
const vector<ll> dx={-1,1,0,0},dy={0,0,-1,1};
template<typename T,typename U> inline bool chmin(T& t, const U& u){if(t>u){t=u;return 1;}return 0;}
template<typename T,typename U> inline bool chmax(T& t, const U& u){if(t<u){t=u;return 1;}return 0;}
template<typename T> inline T gcd(T a,T b){return b?gcd(b,a%b):a;}
template<typename T,typename Y> inline T mpow(T a, Y n) {
  T res = 1;
  for(;n;n>>=1) {
    if (n & 1) res = res * a;
    a = a * a;
  }
  return res;
}



signed main(){
  cin.tie(0);ios::sync_with_stdio(false);
  cout<<fixed<<setprecision(20);
  ll a,b,c;cin>>a>>b>>c;
  if(c-a-b>=0 && 4ll*a*b<c*c+a*a+b*b+2ll*(a*b-a*c-b*c))cout<<"Yes"<<ENDL;
  else cout<<"No"<<ENDL;
}
//! ( . _ . ) ! 
//CHECK overflow,vector_size,what to output?

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

#define FOR(i,a,b) for(int i = (a); i < (b); ++i)
#define REP(i,n) FOR(i,0,n)
using ll = long long;
using vi = vector<int>;
using vvi = vector<vector<int>>;
using mii = map<int, int>;
using msi = map<string, int>;
using pii = pair<int, int>;

struct Edge {
    int to;     // 辺の行き先
    int weight; // 辺の重み
    Edge(int t, int w) : to(t), weight(w) { }
};
using vve = vector<vector<Edge>>;

int main()
{
    ios::sync_with_stdio(false);

    int N;
    cin >> N;
    vve graph(N);
    REP(i, N - 1) {
        int u, v, w;
        cin >> u >> v >> w;
        --u; --v;
        graph[u].push_back(Edge(v, w));
        graph[v].push_back(Edge(u, w));
    }
    vi ans(N, -1);
    queue<int> q;
    ans[0] = 0;
    q.push(0);
    while(!q.empty()) {
        int v = q.front();
        q.pop();
        for(auto n : graph[v]) {
            int u = n.to;
            int w = n.weight;
            if(ans[u] != -1) continue;
            ans[u] = (ans[v] + w) % 2;
            q.push(u);
        }
    }
    for(auto n : ans) {
        cout << n << endl;
    }

    return 0;
}

Measured memory_bytes: 6784
# ライブラリのインポート
#import re #正規表現
import sys
#import heapq
#import collections
#import math

def main():
    y = ""
    for x in sys.stdin: y += x
    a = list(y.strip("\n").split(" "))
    print(max(a, key=a.count), max(a, key=len))
    
if __name__ == '__main__':
    main()



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


int main(){
    int X, A;
    cin >> X >> A;

    if(X < A){
        cout << 0 << endl;
    }else{
        cout << 10 << endl;
    }

    return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
#include <string.h>

char aa[500][500];
int markc[500];
int markr[500];

int main()
{
	int a, b;
	int ww;
	scanf("%d %d ", &a, &b);
	for (int i = 0; i < a; i++)
	{
		ww = 0;
		for (int j = 0; j < b; j++)
		{
			aa[i][j] = getchar();
			if ((aa[i][j]) == '#')
				ww = 1;
		}
		getchar();
		if (!ww) markr[i] = 1;
	}
	for (int j = 0; j < b; j++)
	{
		ww = 0;
		for (int i = 0; i < a; i++)
		{
			if ((aa[i][j]) == '#')
				ww = 1;
		}
		if (!ww) markc[j] = 1;
	}
	for (int i = 0; i < a; i++)
	{
		if (markr[i]) continue;
		for (int j = 0; j < b; j++)
		{
			if (!markc[j])
				putchar(aa[i][j]);
		}
		puts("");
	}
			
	return 0;
}


Measured memory_bytes: 256
import bisect,collections,copy,heapq,itertools,math,string
import sys
def input() : return sys.stdin.readline().strip()
def INT()   : return int(input())
def MAP()   : return map(int,input().split())
def LIST()  : return list(MAP())

x = INT()
i = 1
while(x-i>0):
    x -= i
    i += 1
print(i)

Measured memory_bytes: 10072
import sys
def LI(): return list(map(int,sys.stdin.readline().rstrip().split()))  #空白あり
def LS2(): return list(sys.stdin.readline().rstrip())  #空白なし

N,K = LI()
S = LS2()

S[K-1] = S[K-1].lower()

print(''.join(S))

Measured memory_bytes: 61908
#include <algorithm>
#include <cstdio>
#include <iostream>
#include <string>
#include <vector>
using namespace std;

int main(){
  int n;
  cin >> n;
  for(int times=0; times<n; ++times){
    string s;
    cin >> s;

    int L=0, R=0;
    int k=0;
    //??????????????°???????????????
    for(int i=0; i<s.size(); ++i){
      if(s[i]=='[') L++;
      else if(s[i]==']') R++;
      k=max(k,(L-R));
    }

    vector< vector<int> > q(5000);

    L=0, R=0;
    //??????????????°???????????????
    for(int i=0; i<s.size(); ++i){
      if(s[i]=='[') L++;
      else if(s[i]==']'){
        R++;
        if(q[L-R+2].size()!=0){
          sort(q[L-R+2].begin(), q[L-R+2].end());

          int ins=0;
          for(int i=0; i<=q[L-R+2].size()/2; ++i){
            if(L-R+2==k) ins+=q[L-R+2][i]/2+1;
            else ins+=q[L-R+2][i];
          }
          //printf("dep = %d,ins = %d\n", L-R+1, ins);
          q[L-R+2].resize(0);
          q[L-R+1].push_back(ins);
        }
      }
      else{ //??°???
        int st=i;
        while(s[i+1]!=']') i++;
        //string tmp = s.substr(st,i-st+1);
        q[L-R].push_back(atoi(s.substr(st,i-st+1).c_str()));

      }
    }

    cout << q[1].front() <<endl;
  }
}

Measured memory_bytes: 1392
#include<bits/stdc++.h>
#define int long long
using namespace std;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (a>b) { a=b; return 1; } return 0; }

template<int mod> class ModInt
{   
private:
    int val;
public:
    int value(){ return val; }
    ModInt(int x=0){ val=x%mod; }
    ModInt pow(int n){
        ModInt res(1),x(val);
        while(n>0){ if(n&1) res*=x; x*=x; n>>=1; }
        return res;
    }
    ModInt inv(){ return pow(mod-2); }
    ModInt& operator+=(ModInt rhs){ val+=rhs.val; if(val>=mod) val-=mod; return *this; }
    ModInt& operator-=(ModInt rhs){ val+=mod-rhs.val; if(val>=mod) val-=mod; return *this; }
    ModInt& operator*=(ModInt rhs){ val=val*rhs.val%mod; return *this; }
    ModInt& operator/=(ModInt rhs){ *this*=rhs.inv(); return *this; }
    ModInt operator+(ModInt rhs){ return ModInt(val)+=rhs; }
    ModInt operator-(ModInt rhs){ return ModInt(val)-=rhs; }
    ModInt operator*(ModInt rhs){ return ModInt(val)*=rhs; }
    ModInt operator/(ModInt rhs){ return ModInt(val)/=rhs; }
};

template<typename T> class BiCoef
{
public:
    vector<T> fact,ifact,inv;
    BiCoef(int N):fact(N+1),ifact(N+1),inv(N+1){
        fact[0]=ifact[N]=inv[0]=1;
        for(int i=1;i<=N;i++) fact[i]=fact[i-1]*i;
        ifact[N]/=fact[N];
        for(int i=N-1;i>=0;i--) ifact[i]=ifact[i+1]*(i+1);
        for(int i=1;i<=N;i++) inv[i]=ifact[i]*fact[i-1];
    }
    T comb(int n,int k){
        if(n<0 or k<0 or n<k) return 0;
        return fact[n]*ifact[k]*ifact[n-k];
    }
};

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

    int H,W,N; cin>>H>>W>>N;
    vector<pair<int,int>> p(N);
    for(int i=0;i<N;i++){
        int r,c; cin>>r>>c;
        p[i]={r,c};
    }
    sort(p.begin(),p.end());
    vector<int> r(N),c(N);
    for(int i=0;i<N;i++){
        r[i]=p[i].first;
        c[i]=p[i].second;
    }

    using mint=ModInt<1000000007>;
    BiCoef<mint> bc(H+W);
    auto func=[&](int r1,int c1,int r2,int c2)
    {
        if(r1>r2 or r1>r2) return mint(0);
        else{
            int dr=r2-r1;
            int dc=c2-c1;
            return bc.comb(dr+dc,dr);
        }
    };

    vector<vector<mint>> dp(N,vector<mint>(2));
    for(int i=0;i<N;i++){
        for(int j=0;j<i;j++){
            dp[i][1]+=dp[j][0]*func(r[j],c[j],r[i],c[i]);
        }
        dp[i][0]=func(1,1,r[i],c[i])-dp[i][1];
    }

    mint ans=func(1,1,H,W);
    for(int i=0;i<N;i++){
        ans-=dp[i][0]*func(r[i],c[i],H,W);
    }
    cout<<ans.value()<<endl;
    return 0;
}

Measured memory_bytes: 7168
S=input()

nc=-1
nf=-1
for i in range(len(S)):
    if S[i]=='C':
        nc=i
        break
for i in range(len(S)):
    if S[i]=='F':
        nf=i

print('Yes' if nc < nf and nc>=0 and nf>=1 else 'No')

Measured memory_bytes: 9112
#include<functional>
#include<algorithm>
#include<iostream>
#include<utility>
#include<string>
#include<vector>
#include<cmath>
#include<stack>
#include<queue>
#include<deque>
#include<map>
#define rep(i,n) for(int i=0;i<n;i++)
#define loop(i,x,n) for(int i=x;i<n;i++)
#define pb push_back
#define pf push_front
#define int long long
using namespace std;
const int INF=1000000007;
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};


signed main(){
  int x;
  cin>>x;
  int temp=0;
  rep(i,x+1){
    temp+=i;
    if(temp>=x){
      cout<<i<<endl;
      break;
    }
  }
  return 0;
}




Measured memory_bytes: 256
import os
import sys
from collections import deque

if os.getenv("LOCAL"):
    sys.stdin = open("_in.txt", "r")

sys.setrecursionlimit(2147483647)
INF = float("inf")
IINF = 10 ** 18
MOD = 10 ** 9 + 7

N, M = list(map(int, sys.stdin.readline().split()))
AB = [list(map(int, sys.stdin.readline().split())) for _ in range(M)]
graph = [[] for _ in range(N + 1)]

for a, b in AB:
    graph[a].append(b)


def cycle_size(from_v):
    """
    from_v に戻ってくるまでのステップ数
    :param from_v:
    :return:
    """
    parents = [None] * len(graph)
    seen = [False] * len(graph)
    que = deque([(from_v, 0)])
    while que:
        v, d = que.pop()
        for u in graph[v]:
            if seen[u]:
                continue
            seen[u] = True
            que.appendleft((u, d + 1))
            parents[u] = v
            if u == from_v:
                return d + 1, parents
    return INF, parents


min_v = None
min_size = INF
min_parents = None
for v in range(1, N + 1):
    size, parents = cycle_size(v)
    if size < min_size:
        min_v = v
        min_size = size
        min_parents = parents

if min_size < INF:
    print(min_size)
    print(min_v)
    v = min_parents[min_v]
    while v != min_v:
        print(v)
        v = min_parents[v]
else:
    print(-1)


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

int main(void) {
	int N;
	scanf("%d", &N);
	int amari = N % 1000;
	int ans = 0;
	if (amari == 0) {
		ans = 0;
	} else {
		ans = 1000 - amari;
	}
	printf("%d", ans);

	return 0;
}


Measured memory_bytes: 3828
#include <bits/stdc++.h>
using namespace std;
using i64 = int64_t;
using vi = vector<i64>;
using vvi = vector<vi>;

int main() {
    string s, t;
    cin >> s >> t;
    s += s;
    int n = t.size();
    for (int i = 0; i < n; i++) {
        if (s.substr(i, n) == t) {
            cout << "Yes" << endl;
            return 0;
        }
    }
    cout << "No" << endl;
}

Measured memory_bytes: 256
H=int(input())

def func(a):
    res=0
    for i in range(a):
        res+=int('1'+'0'*i,2)
    return res

bin_H=format(H,'b')
len_bin_H=len(bin_H)
s_bin='1'+'0'*(len_bin_H-1)

ans=func(len_bin_H)
print(ans)

Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
int main()
{
    int n, m, c, cnt = 0, score, a;
    cin >> n >> m >> c;
    vector<int> b(m);
    //vector<vector<int>> a(n, vector<int>(m));
    for (int i = 0; i < m; i++)
    {
        cin >> b[i];
    }
    for (int i = 0; i < n; i++)
    {
        score = 0;
        for (int j = 0; j < m; j++)
        {
            cin >> a;
            score += a * b[j];
        }
        if(score+c>0){
            cnt++;
        }
    }
    cout << cnt;
    return 0;
}

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

int main() {
  string N;
  cin >> N;
   
  string a,b,c,d;
  a = N.at(0);
  b = N.at(1);
  c = N.at(2);
  d = N.at(3);
  
  if ((a == b && b == c) || (b == c && c == d))
    cout << "Yes" << endl;
  else
    cout << "No" << endl;
}

Measured memory_bytes: 636
#include <cstdio>
#include <algorithm>

using namespace std;

int main ()
{
    long long a, b, c, d, e, ca, cd, ce;
    scanf ("%lld %lld %lld %lld %lld", &a, &b, &c, &d, &e);
    ca = a;
    cd = d;
    ce = e;

    int nr = 0;

    if (a & 1LL) ++nr;
    a /= 2LL;
    a *= 4LL;

    b *= 2LL;

    if (d & 1LL) ++nr;
    d /= 2LL;
    d *= 4LL;

    if (e & 1LL) ++nr;
    e /= 2LL;
    e *= 4LL;

    a += b + d + e;
    if (nr == 3) a += 6LL;

    a /= 2LL;
    swap (a, ca);
    d = cd;
    e = ce;

    if (a && d && e)
    {
        a = (a - 1LL) / 2LL;
        a *= 4LL;

        d--;
        e--;
        a += 6LL;

        d /= 2LL;
        d *= 4LL;

        e /= 2LL;
        e *= 4LL;

        a += b + d + e;
        a /= 2LL;
    }

    else a = -200000000000000000LL;

    printf ("%lld\n", max (a, ca));

    return 0;
}


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

typedef long long ll;
typedef long double ld;
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<pii> vpii;
typedef pair<ll,ll> pll;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<pll> vpll; 

#define fastio ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define test() int t;cin>>t;while(t--)
#define forn(i,f,n) for(int i=f;i<f+n;i++)
#define rforn(i,l,n) for(int i=l;i>l-n;i--)
#define all(v) v.begin(),v.end()
#define prin(V) for(auto v:V) cout<<v<<" ";cout<<endl
#define take(V,f,n) for(int i=f;i<f+n;i++) cin>>V[i]
#define what(x) cerr<<#x<<" = "<<x<<endl
#define KStest() int t,t1;cin>>t;t1=t;while(t--)
#define KScout cout<<"Case #"<<t1-t<<": "

const int MOD = 1e9+7,MAX = 1e5+5;
/////////////////FastExp///////////////////
ll powN(ll a,ll p)
{
	if(p==0) return 1;
	ll z=powN(a,p/2);
	z=(z*z)%MOD;
	if(p%2) z=(z*a)%MOD;
	return z;
}
/////////////////FastExp///////////////////
//////////////////Sieve////////////////////
vector<bool> is_prime(MAX+1, true);
void Sieve()
{
	is_prime[0] = is_prime[1] = false;
	int i,j;
	for (i = 2; i*i <= MAX; i++) 
	{
    	if (is_prime[i]) 
    	{
        	for (j = i * i; j <= MAX; j += i)
            {
				is_prime[j] = false;
    		}
    	}
	}
}
//////////////////Sieve////////////////////

int main()
{
	int k;
	cin>>k;
	ll ans=0;
	for(int i=1;i<=k;i++)
	{
		for(int j=1;j<=k;j++)
		{
			for(int l=1;l<=k;l++)
			{
				ans+=__gcd(i,__gcd(j,l));
			}
		}
	}
	cout<<ans<<endl;
}		

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

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> P;
typedef pair<ll, pair<ll, ll> > P3;

const ll MOD = ll(1e9 + 7);
const ll LLINF = LLONG_MAX;
const int IINF = INT_MAX;
const int MAX_N = int(3e5) + 5;
const double EPS = 1e-8;
int dx[] = {1, 0, -1, 0}, dy[] = {0, 1, 0, -1};
#define SORT(v) sort((v).begin(), (v).end())
#define SORTR(v) sort((v).rbegin(), (v).rend())
#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++)

int main() {
    int n, i = 0, sum = 0;
    cin >> n;
    while(sum<n){
        i++;
        sum += i;
    }
    REP(j,i){
        if(sum-n == j+1)continue;
        cout << j+1 << endl;
    }
    return 0;
}


Measured memory_bytes: 256
#include<cstdio>
#include<algorithm>
using namespace std;
bool fin = false;
int cnt1,cnt2,cnt3;//鋭角 直角 鈍角
int num[3];
void solve(){
  sort(num,num+3);
  if(fin || num[0] + num[1] <= num[2]){
    fin = true;
    return;
  }
  if(num[0] * num[0] + num[1] * num[1] < num[2] * num[2])
    cnt3++;
  else if(num[0] * num[0] + num[1] * num[1] == num[2] * num[2])
    cnt2++;
  else
    cnt1++;
}
int main(){
  cnt1 = cnt2 = cnt3 = 0;
  while(scanf("%d",&num[0]) != EOF){
    scanf("%d %d",&num[1],&num[2]);
    solve();
  }
  printf("%d %d %d %d\n",cnt1+cnt2+cnt3,cnt2,cnt1,cnt3);
}





Measured memory_bytes: 2792
#include<stdio.h>
#include<string.h>
#include<math.h>
int main(void)
{
	int a,s[5000],d[5000],f,g,h,q,j,i,k,z;
	scanf("%d",&a);
	while(a!=0){
		for(i=0;i<a;i++)
			s[i]=0;d[i]=0;
		k=0;
		h=a;
		q=a;
		for(i=0;i<a;i++)
			scanf("%d",&s[i]);
		for(i=1;i<=a*2;i++){
			f=1;
			for(j=0;j<a;j++){
				if(s[j]==i){
					f=0;
					break;
				}
			}
			if(f==1){
				d[k]=i;
				k++;
			}
		}
		for(i=0;i<a;i++){
			for(j=i+1;j<a;j++){
				if(s[i]>s[j]){
					f=s[i];
					s[i]=s[j];
					s[j]=f;
				}
			}
		}
	/*	for(i=0;i<a;i++)
			printf("%d %d\n",s[i],d[i]);*/
		f=0;
		g=0;
		while(1){
		//	printf("%d %d %d\n",g,f,z);
			z=0;
			for(i=0;i<a;i++){
				if(f==0){
					if(g==0){
						if(s[i]!=0){
							g=s[i];
							s[i]=0;
							f=1;
							q--;
							z=1;
							break;
						}
					}
					else if(g>0){
						if(g<s[i]){
							g=s[i];
							s[i]=0;
							f=1;
							q--;
							z=1;
							break;
						}
					}
				}
				else if(f==1){
					if(g==0){
						if(d[i]!=0){
							g=d[i];
							d[i]=0;
							f=0;
							h--;
							z=1;
							break;
						}
					}
					else if(g>0){
						if(g<d[i]){
							g=d[i];
							d[i]=0;
							f=0;
							h--;
							z=1;
							break;
						}
					}
				}
			}
			if(z==0){
				f=(f+1)%2;
				g=0;
			}
			if(h==0||q==0)	break;
		}
		printf("%d\n%d\n",h,q);
		scanf("%d",&a);
	}
	return 0;
}

Measured memory_bytes: 2564
#include<iostream>
using namespace std;
int main(){
  int A_1,A_2,A_3;
  cin >> A_1;
  cin >> A_2;
  cin >> A_3;
  int sum = A_1 + A_2 + A_3;
  if(sum >= 22) cout << "bust" << endl;
  if(sum < 22) cout << "win" << endl;
  return 0;
}


Measured memory_bytes: 256
#include<iostream>
using namespace std;
int main(){
    int a, b, c;
    cin >> a >> b >> c;
    
    if(a < b){
        if(b < c) cout << "Yes" << endl;
        else cout << "No" << endl;
    }
    else cout << "No" << endl;
    
    return 0;
}


Measured memory_bytes: 3096
#include <bits/stdc++.h>
#include <algorithm>
#include <math.h>
#include <cstring>

#define test(t) while(t--)
#define fo(i,k,n) for(int i=k;i<n;i++)
#define refl(a,x) for(auto& a:x)
#define MIN(a,b)  (a>b?b:a)
#define ll  long long int
#define MOD 1e9 + 7
#define in  cin>>
#define out cout<<
#define en "\n"
#define sp " "
#define fi first
#define se second
#define fast()  ios_base::sync_with_stdio(false);cin.tie(0);
#define pb push_back
#define lb lower_bound
#define ub upper_bound
//typedef pair<int,int> pai;
//typedef pair<char,int> pac;



/*bool f(int x,int y){

return x>y;
}*/


using namespace std;


void solve(){ll n;float m;
             in n>>m;
             float a[n];
             float sum =0;
             fo(i,0,n){
             in a[i];
             sum +=a[i];
             }
             //sort(a,a+n);
             float form =sum/(4*m);
             ll cnt=0;
             fo(i,0,n){
             if(a[i]>=form){
                cnt +=1;
             }

             }
             if(cnt>=m)
                out "Yes"<<en;
             else
                out "No"<<en;
}


int main(){ fast()
             //freopen("input.txt","r",stdin);
	         //freopen("output.txt","w",stdout);
             ll t=1;
            //cin>>t;
            test(t){
            solve();
            }

return 0;}


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


using namespace std;

const double PI = 3.14159265358979323846;
typedef long long ll;
const double EPS = 1e-9;
#define rep(i, n) for (int i = 0; i < (n); ++i)
//#define rep(i, n) for (ll i = 0; i < (n); ++i)
const ll INF = 10e17;
#define cmin(x, y) x = min(x, y)
#define cmax(x, y) x = max(x, y)
#define ret() return 0;

double equal(double a, double b) {
    return fabs(a - b) < DBL_EPSILON;
}

std::istream &operator>>(std::istream &in, set<string> &o) {
    string a;
    in >> a;
    o.insert(a);
    return in;
}

std::istream &operator>>(std::istream &in, queue<int> &o) {
    ll a;
    in >> a;
    o.push(a);
    return in;
}

typedef pair<ll, ll> P;

bool contain(set<int> &s, int a) { return s.find(a) != s.end(); }

//ofstream outfile("log.txt");
//outfile << setw(6) << setfill('0') << prefecture << setw(6) << setfill('0') << rank << endl;
// std::cout << std::bitset<8>(9);
//const ll mod = 1e10;

typedef priority_queue<ll, vector<ll>, greater<ll> > PQ_ASK;


int main() {
    int k, a, b;
    cin >> k >> a >> b;
    for (int i = a; i <= b; i++) {
        if (i % k == 0) {
            cout << "OK" << endl;
            ret();
        }
    }
    cout << "NG" << endl;
}



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

int main() {
  int n, a, y, z;
  cin >> n;
    y = 0;
  z = 10000;
  while (n > 0 ){
    cin >> a;
    y = 0;    
    while( a % 2 == 0){
          a = a / 2;
          y++;}
     if ( z > y){z = y;} 
    n = n - 1;
  }
  cout << z << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, srt, end) for (long long i = (srt); i < (long long)(end); i++)
#define VL vector<ll>
#define VS vector<string>
#define VB vector<bool>
#define VP vector<pair<ll,ll>>
#define VVL vector<vector<ll>>
#define VVP vector<vector<pair<ll,ll>>>
#define PL pair<ll,ll>
#define ALL(v) (v).begin(), (v).end()
 

int main(){
	VL A(3);
    cin>>A[0]>>A[1]>>A[2];
    sort(A.begin(),A.end());
    if(A[0]+A[1]==A[2])cout<<"Yes";
    else cout<<"No";
    return 0;

}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <boost/multiprecision/cpp_int.hpp>

#define rep(i,a,b) for(ll i=a;i<b;i++)
#define rrep(i,b,a) for(int i=b;i>=a;i--)
#define fori(a) for(auto i : a )
#define all(a) begin(a), end(a)
#define set(a,b) memset(a,b,sizeof(a))
#define sz(a) a.size()
double pi=acos(-1);
#define ll long long
#define ull unsigned long long
#define pb push_back
#define PF push_front //deque
// #define mp make_pair
#define pq priority_queue
const ll mod=1000000007;
#define f first
#define s second
#define pii pair< ll, ll >
#define vi vector<int>
#define vpii vector<pii>
#define debug(v) for(auto i:v) cout<<i<<" ";
#define tc int t; cin >> t; while(t--)

using namespace boost::multiprecision;
using namespace std;
void optimizeIO(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
}


const int N=1000005;
ll fact[N],invfact[N];
ll power(ll x,ll y){
  if(y<=0) return 1LL;
  ll z=power(x,y/2);
  if(y%2) return (((z*z)%mod)*x)%mod;
  return (z*z)%mod;
}

void pre(){
  fact[0]=invfact[0]=invfact[1]=fact[1]=1;
  rep(i,2,N) fact[i]=(i*fact[i-1])%mod;
  rep(i,2,N) invfact[i]=(invfact[i-1]*power(i,mod-2))%mod;
}
ll nCr(ll n,ll k){ return (((fact[n]*invfact[n-k])%mod)*invfact[k])%mod; }



const int N1=1e6+1;
vector<int> isprime(N1,1),prime;
void seive(){
  rep(i,2,sqrt(N1)+1){
      if(isprime[i]){
        for(int j=i*i;j<N1;j+=i) isprime[j]=0;
        prime.pb(i);
      }
  }
  rep(i,sqrt(N1)+1,N1) if(isprime[i]) prime.pb(i);
}



struct dsu {
    vector<int> par, rank;
    dsu(int n): par(n+1), rank(n+1) {
        for (int i = 0; i <= n; i++) {
            par[i] = i;
            rank[i]= 1;
        }
    }
    int root(int a) {
        if (a == par[a]) return a;
        return par[a] = root(par[a]);
    }
    void merge(int a, int b) {
        a = root(a);
        b = root(b);
        if (a == b) return;
        if (rank[a] > rank[b]) swap(a, b);
        par[b] = a;
    }
    set<int> parent(int n){
        set<int> s;
        for(int i=1;i<=n;i++){
            s.insert(root(i));
        }
        return s;
    }
};

void solve(){
  ll n,m;
  cin>>n>>m;
  ll ans=0;
  if(n==1 && m==1 ) ans=1;
  else if(n==1) ans=m-2;
  else if(m==1) ans=n-2;
  else ans=(n-2)*(m-2);
  cout<<ans<<endl;
}

int main(){
    optimizeIO();
    int r=1;
    {solve();}
}


Measured memory_bytes: 7044
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cstring>

#include <iostream>
#include <complex>
#include <string>
#include <algorithm>
#include <numeric>
#include <vector>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <unordered_map>
#include <unordered_set>

#include <functional>
#include <cassert>

typedef long long ll;
using namespace std;

#ifndef LOCAL
#define debug(x) ;
#else
#define debug(x) cerr << __LINE__ << " : " << #x << " = " << (x) << endl;

template <typename T1, typename T2>
ostream &operator<<(ostream &out, const pair<T1, T2> &p) {
  out << "{" << p.first << ", " << p.second << "}";
  return out;
}

template <typename T>
ostream &operator<<(ostream &out, const vector<T> &v) {
  out << '{';
  for (const T &item : v) out << item << ", ";
  out << "\b\b}";
  return out;
}
#endif

#define mod 1000000007 //1e9+7(prime number)
#define INF 1000000000 //1e9
#define LLINF 2000000000000000000LL //2e18
#define SIZE 200010

typedef long double Real;

pair<Real, pair<int, bool> > flowers[SIZE];
Real alpha[SIZE], beta[SIZE];

Real calcCost(Real pw, Real sumA, Real sumB, Real l, Real r) {
  l = max(l, (Real)0.0);
  sumA += pw;

  if (l > r) return 1e20;

  if (sumA < 0) {
    return r * sumA + sumB;
  } else {
    return l * sumA + sumB;
  }
}

bool solve() {
  int N;
  int pw, vw, pf, vf, th;

  scanf("%d", &N);

  if (N == 0) return false;

  scanf("%d", &pw);

  Real sumA = 0, sumB = 0;

  for (int i=0; i<N; i++) {
    scanf("%d%d%d%d", &vw, &pf, &vf, &th);

    Real limit = 1e20;

    //alpha * x + beta = cost
    alpha[i] = -(Real)vw * pf / vf;
    beta[i] = (Real)th * pf / vf;

    bool add = vw < 0; //alpha[i] > 0;

    if (!add) { // alpha[i] < 0
      sumA += alpha[i];
      sumB += beta[i];

      //消去位置
      if (th >= 0 && vw == 0) // beta[i] >= 0 && alpha[i] == 0
        limit = 1e20;
      if (th < 0 && vw == 0) // beta[i] < 0 && alpha[i] == 0
        limit = -1;

      if (th >= 0 && vw != 0) // beta[i] >= 0 && alpha[i] < 0
        limit = -beta[i] / alpha[i];
      if (th < 0 && vw != 0) // beta[i] < 0 && alpha[i] < 0
        limit = -1;

    } else {
      //追加位置

      if (th < 0) // beta[i] < 0 && alpha[i] > 0
        limit = -beta[i] / alpha[i];
      else // beta[i] > 0 && alpha[i] > 0
        limit = -1;
    }

    flowers[i] = {limit, {i, add}};
  }

  sort(flowers, flowers+N);

  Real ans = 1e30;
  Real prev = 0;

  for (int i=0; i<N; i++) {
    Real limit = flowers[i].first;
    int idx = flowers[i].second.first;
    bool add = flowers[i].second.second;

    if (prev > 1e15) break;

    ans = min(ans, calcCost(pw, sumA, sumB, prev, limit));

    //debug(sumA); debug(sumB); debug(prev); debug(calcCost(pw, sumA, sumB, prev, limit));

    if (add) {
      sumA += alpha[idx];
      sumB += beta[idx];
    } else {
      sumA -= alpha[idx];
      sumB -= beta[idx];
    }

    prev = limit;
  }

  printf("%.10lf\n", (double)ans + 1e-11);

  return true;
}

int main(){

  while(solve());

  return 0;
}



Measured memory_bytes: 9424
#include<bits/stdc++.h>
#define ll long long
#define maxn 2005
using namespace std;
int arr[maxn],idxs[maxn];
ll dp[maxn][maxn];
int main() {
	ios::sync_with_stdio(0);
	cin.tie(0);
	int n;
	cin >> n;
	for(int i=1;i<=n;i++)
		cin >> arr[i] , idxs[i] = i;
	sort(idxs+1,idxs+1+n,[=](int a,int b)->bool
		{return arr[a] > arr[b];});
	
	dp[0][0] = 0;
	for(int i=1;i<=n;i++) {
		int pos = idxs[i] , coe = arr[idxs[i]];
		for(int j=0;j<=i;j++) {
			ll a = 0  , b = 0;
			if(j != 0)	a = (ll)coe * abs(pos - j) + dp[i - 1][j - 1];
			if(j != i)	b = (ll)coe * abs(pos - (n - (i - j) + 1)) + dp[i - 1][j];
			dp[i][j] = max(a,b);
		}
	}
	cout << *max_element(dp[n]+1,dp[n]+1+n) << endl;
	return 0;
}


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

int main() {
  long long a,b,c,d;
  long long ans;
  cin>>a>>b>>c>>d;
  if(a>=0&&c>=0){
    //x=b
    ans = b*d;
  }
  else if(a>=0&&d<0){
    ans = a*d;
  }
  else if(c>=0&&b<0){
    ans = b*c;
  }
  else if(b<0&&d<0){
    ans = a*c;
  }
  else if(b<0||d<0){
    ans = a*c;
  }
  else{
    long long k1 = a*c;
    long long k2 = b*d;
    ans = max(k1,k2);
    if(ans<0){
      ans = 0;
    }
  }
  cout<<ans;
}

Measured memory_bytes: 3632
from string import ascii_lowercase
S = input()
N = len(S)
if N < 26:
    for char in ascii_lowercase:
        if char in S: continue
        print(S + char)
        exit()
if S == 'zyxwvutsrqponmlkjihgfedcba':
    print(-1)
    exit()
for i in range(N - 1, -1, -1):
    for j in range(N - 1, i, -1):
        if S[i] < S[j]:
            print(S[:i] + S[j])
            exit()


Measured memory_bytes: 9856
#include <iostream>
#include <string>

int main()
{
	std::string A;

	std::cin >> A;

	int B;
	int C;
	int D = 1000;

	for (int i = 0; i <= A.size() - 3; i++) {
		B = std::stoi(A.substr(i, 3));
		if (B <= 753) {
			C = 753 - B;
		}
		else {
			C = B - 753;
		}

		if (C < D) {
			D = C;
		}
	}

	std::cout << D << std::endl;

	return 0;
}

Measured memory_bytes: 256
import sys
from collections import defaultdict

sys.setrecursionlimit(10 ** 6)
int1 = lambda x: int(x) - 1
p2D = lambda x: print(*x, sep="\n")
def II(): return int(sys.stdin.readline())
def MI(): return map(int, sys.stdin.readline().split())
def LI(): return list(map(int, sys.stdin.readline().split()))
def LLI(rows_number): return [LI() for _ in range(rows_number)]
def SI(): return sys.stdin.readline()[:-1]


inf=10**16
n=II()
xyu=[SI().split() for _ in range(n)]
dir="LRDU"
xyu=[(int(x),int(y),dir.index(u)) for x,y,u in xyu]
xyu.sort()

ans=inf
# 左向き
ytox=defaultdict(int)
hu=defaultdict(list)
sei=defaultdict(list)
for x,y,u in xyu:
    if u==1:
        ytox[y]=x
    if u==2:hu[x+y]=[x,y]
    if u==3:sei[x-y]=[x,y]
    if u==0:
        if y in ytox:
            ans=min(ans,(x-ytox[y])*5)
        if x+y in hu:
            ans=min(ans,abs(x-hu[x+y][0])*10)
        if x-y in sei:
            ans=min(ans,abs(x-sei[x-y][0])*10)

# 右
hu=defaultdict(list)
sei=defaultdict(list)
for x,y,u in xyu[::-1]:
    if u==3:hu[x+y]=[x,y]
    if u==2:sei[x-y]=[x,y]
    if u==1:
        if x+y in hu:
            ans=min(ans,abs(x-hu[x+y][0])*10)
        if x-y in sei:
            ans=min(ans,abs(x-sei[x-y][0])*10)

xyu.sort(key=lambda x:x[1])
ytox=defaultdict(int)
hu=defaultdict(list)
sei=defaultdict(list)
for x,y,u in xyu:
    if u==3:
        ytox[x]=y
    if u==2:
        if x in ytox:
            ans=min(ans,(y-ytox[x])*5)

if ans==inf:print("SAFE")
else:print(ans)


Measured memory_bytes: 210376
//   _/                _/                 _/_/_/   _/
//_/_/_/_/   _/_/   _/_/_/_/   _/_/    _/       _/_/
// _/     _/    _/   _/     _/    _/  _/_/_/     _/
//_/     _/    _/   _/     _/    _/  _/    _/   _/
// _/_/   _/_/       _/_/   _/_/      _/_/     _/
#include<iostream>
#include<algorithm>
#include<cmath>
#include<iomanip>
#include<set>
#include<map>
#include<queue>
#include<vector>
using namespace std;
typedef long long ll;
const int MOD=1e9+7;
const double pi=3.14159265358979323846;
const int inf=1e9;
const ll INF=5e18;
typedef pair<int,int> P;
int main() {
  cin.tie(0),cout.tie(0);
  ios::sync_with_stdio(false);
  int q,l,r,a[100005]={};
  bool f[100005]={};
  cin >> q;
  for(int i=2; i<=100000; i++) {
    if(!f[i]) {
      for(int j=i*2; j<=100000; j+=i) {
        f[j]=true;
      }
    }
  }
  for(int i=3; i<=100000; i+=2) {
    if(!f[i]&&!f[(i+1)/2]) {
      a[i]=1;
    }
  }
  for(int i=1; i<=100000; i++) {
    a[i]+=a[i-1];
  }
  while(q--) {
    cin >> l >> r;
    cout << a[r]-a[l-1] << endl;
  }
}

Measured memory_bytes: 1152
import java.util.*;
public class Main{
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        String a = sc.next();
        String b = sc.next();
	for(int i = 0; i < a.length(); i++){
	    if(a.equals(b)){
		System.out.println("Yes");
		return;
	    }
	    a = a + a.charAt(0);
	    a = a.substring(1);
	}
	System.out.println("No");
    }
}


Measured memory_bytes: 21716
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define mp make_pair
#define mod 1000000007

int main()
{
	ll n,m,x,y,r,a,b,i;
     cin>>n>>m>>a>>b;
     x=INT_MIN,y=INT_MAX;
     for(i=0;i<n;i++)
     {
          cin>>r;
          x=max(x,r);
     }
     for(i=0;i<m;i++)
     {
          cin>>r;
          y=min(y,r);
     }
     x++;
     a++;
     if(x<=y and (y>=a and x<=b))
     std::cout << "No War" << '\n';
     else
     std::cout << "War" << '\n';
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
#define rep(i, n) for (ll i = 0; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()
#define m1(x) memset(x,-1,sizeof(x))
const int INF = 1e9 + 1;
const ll MOD = 1e9 + 7;
const double PI = 3.1415926535897932384626433832795028841971693993751058209749445923078164062862089986280348253421170679821480865132823066470938446095505822317253594081284811174502841027019385211055596446229489549303819644288109756659334461284756482337867831652712019091456485669234603486104543266482133936072602491412737245870066063155881748815209209628292540917153643678925903600113305305488204665213841469519415116094330572703657595919530921861173819326117931051185480744623799;


int main(){
  int n;
  char c[10000];
  cin >> n;
  string s;
  cin >> s;
  rep(i, s.size()) c[i] = s.at(i);
  rep(i, s.size()){
    c[i] = (c[i] - 'A' + n) % 26 + 'A';
    cout << c[i];
  }
  cout << endl;
}
  

Measured memory_bytes: 256
fn run() {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).unwrap();
    let mut it = s.trim().split_whitespace();
    let mut n: i64 = it.next().unwrap().parse().unwrap();
    let k: i64 = it.next().unwrap().parse().unwrap();
    n %= k;
    let ans = std::cmp::min(n, k - n);
    println!("{}", ans);
}

fn main() {
    run();
}

Measured memory_bytes: 4352
#include <bits/stdc++.h>
using namespace std;
    int i,j,y,x=1,m1,m2,m3;
    string a,b,c;
    bool t=0;

int main()
{
    cin>>a>>b>>c;
    while(t==0)
    {
        if(x==1)
        {
            if(m1==a.size())
            {
                cout<<"A"<<endl;
                t=1;
                return 0;
            }
            if(a[i]=='b')
                x=2;
            else if(a[i]=='c')
                x=3;
            else
                x=1	;
            m1++;
            i++;

        }
        if(x==2)
        {
            if(m2==b.size())
            {
                cout<<"B"<<endl;
                t=1;
                return 0;
            }
            if(b[j]=='a')
                x=1;
            else if(b[j]=='c')
                x=3;
            else
                x=2;
            m2++;
            j++;


        }
        if(x==3)
        {
            if(m3==c.size())
            {
                cout<<"C"<<endl;
                t=1;
                return 0;
            }
            if(c[y]=='a')
                x=1;
            else if(c[y]=='b')
                x=2;
            else
                x=3;
            m3++;
            y++;

        }
    }
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long int
#define yorn(f) cout<<((f)?"Yes":"No")<<endl;
#define YORN(f) cout<<((f)?"YES":"NO")<<endl;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(), (x).end()
#define put(x) cout << x << endl;
#define println(x) cout << x << endl;
using namespace std;
signed main()
{
    int n;
    cin >> n;
    vector<int> a(n);
    rep(i, n) cin >> a[i];
    vector<int> b(n);
    rep(i, n) cin >> b[i];
    vector<int> c(n-1);
    rep(i, n-1) cin >> c[i];

    ll sum = 0;
    int prev = -1;
    rep(i, n) {
        sum += b[a[i] - 1];
        if (prev >= 0 && a[i] - prev == 1) {
            sum += c[prev - 1];
        }
        prev = a[i];
    }

    put(sum)

    return 0;
}

Measured memory_bytes: 3612
use std::io::prelude::*;
use std::io::stdin;
use std::str::FromStr;

fn main() {
    let _n: usize = read();
    let k: usize = read();
    let mut s: Vec<char> = read::<String>().chars().collect();

    s[k - 1] = (s[k - 1] as u8 + 32) as char;

    println!("{}", s.iter().map(|x| *x).collect::<String>());
}

#[allow(dead_code)]
fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let token: String = stdin
        .lock()
        .bytes()
        .map(|b| b.unwrap() as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().unwrap()
}


Measured memory_bytes: 4352
#include<iostream>
#include<algorithm>

using namespace std;


int n, r[109], c[109];
long long dp[109][109];

const long long MAX = __LONG_LONG_MAX__;

int main(){
  cin >> n;
  for(int i=0;i<n;i++){
    for(int j=0;j<n;j++)dp[i][j] = MAX;
  }
  for(int i=0;i<n;i++)cin >> r[i] >> c[i];
  for(int i=0;i<n;i++)dp[i][i] = 0;
  for(int i=1;i<n;i++){
    for(int j=0;j+i<n;j++){
      for(int k=0;k<i;k++){
        dp[j][j+i] = min(dp[j][j+i], dp[j][j+k]+dp[j+k+1][j+i] + r[j]*c[j+k]*c[j+i]);
      }
    }
  }
  cout << dp[0][n-1] << endl;
}


Measured memory_bytes: 3144
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0; i<(n); i++)
int n, h, w, ans, a, b;
int main(){
	scanf("%d%d%d", &n, &h, &w);
	rep(i,n){
		scanf("%d%d", &a, &b);
		if(a >= h && b >= w) ans++;
	}
	printf("%d\n", ans);
}

Measured memory_bytes: 256
h, w = map(int, input().split())
grid = []
for i in range(h):
    temp = list(input())
    if set(temp) != {'.'}:
        grid.append(temp)


transpose = [list(x) for x in zip(*grid)]

ans = []
for l in transpose:
    if set(l) != {'.'}:
        ans.append(l)

ans = [list(x) for x in zip(*ans)]
for l in ans:
    print(''.join(l))


Measured memory_bytes: 3316
#include<iostream>

using namespace std;

const long long INF = 1e18;

int main(){
    int n, k; cin >> n >> k;
    int a[n+10];
    for (int i=0; i<n; i++){
        cin >> a[i];
    }
    long long dp[101000];
    for (int i=0; i<101000; i++){
        dp[i] = INF;
    }
    dp[0] = 0;

    for (int i=0; i<n; i++){
        for (int j=1; j<=k && i+j < n; j++){
            dp[i+j] = min(dp[i+j], dp[i]+abs(a[i]-a[i+j]));
        }
    }

    cout << dp[n-1] << endl;
    
    return 0;
}

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

int main()
{
	int N;
	cin >> N;
	vector<string> S( N );
	for( int i = 0; i < N; i++ ) {
		cin >>S[i];
	}

	map<string, int> mp;
	int ma = 0;
	for( int i = 0; i < N; i++ ) {
		mp[ S[i] ]++;
		ma = max( ma, mp[ S[i] ] );
	}
	vector<string> ans;
	for( auto it = mp.begin(); it != mp.end(); it++ ) {
		if( it->second == ma ) {
			ans.push_back( it->first );
		}
	}

	for( int i = 0; i < ans.size(); i++ ) {
		cout << ans[i] << endl;
	}
}


Measured memory_bytes: 28404
<?php
fscanf(STDIN, "%s", $S);
$a = [];
$ans = 0;
for ($i = 0; $i < strlen($S); $i++) {
    if ($S[$i] == 'B') {
        $a[] = $i;
    }
}
$cursor = strlen($S) - 1;
for ($i = 0; $i < count($a); $i++) {
    $ans += $cursor - $a[$i];
    $cursor--;
}
echo $ans;


Measured memory_bytes: 12788
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> l_l;
typedef pair<int, int> i_i;
template<class T>
inline bool chmax(T &a, T b) {
    if(a < b) {
        a = b;
        return true;
    }
    return false;
}

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

#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
//const ll mod = 1000000007;

int main() {
    //cout.precision(10);
    cin.tie(0);
    ios::sync_with_stdio(false);
    string S;
    int K;
    cin >> S >> K;
    for(int i = 0; i < S.size(); i++) {
        if(S[i] == 'a') continue;
        int delta = 'z' - S[i];
        delta++;
        if(K < delta) continue;
        K -= delta;
        S[i] = 'a';
    }
    K %= 26;
    while(K--) {
        S.back()++;
        if(S.back() == 'z' + 1) S.back() == 'a';
    }
    cout << S << endl;
    return 0;
}


Measured memory_bytes: 592
#include <stdio.h>
int main () {
	
	int n,x,j, count = 0, save = 1;
	scanf("%d %d", &n, &x);
	
	
	for(int i = 0; i < n; i++){
		scanf("%d", &j);
		count = count + j;
		if(count <= x){
			save++;
		}
	}
	
	printf("%d", save);
	
	
	
	return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/assoc_container.hpp>

using namespace std;
using namespace __gnu_pbds;
 
typedef long long ll;
typedef long double ld;
typedef complex<ld> cd;

typedef pair<int, int> pi;
typedef pair<ll,ll> pl;
typedef pair<ld,ld> pd;

typedef vector<int> vi;
typedef vector<ld> vd;
typedef vector<ll> vl;
typedef vector<pi> vpi;
typedef vector<pl> vpl;
typedef vector<cd> vcd;

template <class T> using Tree = tree<T, null_type, less<T>, rb_tree_tag,tree_order_statistics_node_update>;

#define FOR(i, a, b) for (int i=a; i<(b); i++)
#define F0R(i, a) for (int i=0; i<(a); i++)
#define FORd(i,a,b) for (int i = (b)-1; i >= a; i--)
#define F0Rd(i,a) for (int i = (a)-1; i >= 0; i--)

#define sz(x) (int)(x).size()
#define mp make_pair
#define pb push_back
#define f first
#define s second
#define lb lower_bound
#define ub upper_bound
#define all(x) x.begin(), x.end()

const int MOD = 1000000007;
const ll INF = 1e18;
const int MX = 100001;
const ld PI = 4*atan((ld)1);

int n;
cd p[100];

pd inter(pd a, pd b) {
    return {max(a.f,b.f),min(a.s,b.s)};
}

pd bet(pd a, pd b) {
    if (a.s-a.f < b.s-b.f) return b;
    return a;
}

pd get(int a, int b) {
    auto x = arg(p[b]-p[a]);
    return {x-PI/2,x+PI/2};
}

void solve(int ind) {
    pd z = {-1,-1};
    F0R(i,n) if (i != ind) {
        pd t = get(ind,i);
        if (z.f == -1) z = t;
        else z = bet(inter(z,t),bet(inter(z,{t.f+2*PI,t.s+2*PI}),inter(z,{t.f-2*PI,t.s-2*PI})));
    }
    cout << fixed << setprecision(8) << max((ld)0,(z.s-z.f)/2/PI) << "\n";
}

int main() {
    ios_base::sync_with_stdio(0); cin.tie(0);
    cin >> n;
    F0R(i,n) {
        int x,y; cin >> x >> y;
        p[i] = cd(x,y);
    }
    F0R(i,n) solve(i);
}

// read the question correctly (is y a vowel? what are the exact constraints?)
// look out for SPECIAL CASES (n=1?) and overflow (ll vs int?) ARRAY OUT OF BOUNDSS

Measured memory_bytes: 256