akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define REP(i,b,n) for(int i=b;i<(int)n;i++)
#define rep(i,n) REP(i,0,n)
#define all(obj) (obj).begin(),(obj).end()
const ll mod = 1e13+7;
ll x[100005];
int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n,k;cin>>n>>k;
    ll maxi=mod;
    rep(i,n)cin>>x[i];
    rep(i,n-k+1){
        ll tmp=min(abs(x[i]),abs(x[i+k-1]))+x[i+k-1]-x[i];
        if(maxi>tmp)maxi=tmp;
    }
    cout<<maxi<<endl;
    return 0;
}


Measured memory_bytes: 1024
//omajinai c++
#include <iostream>
#include<cmath>
#include<vector>
#include <algorithm>
#include <limits>
#include <numeric>
#include <type_traits>
#include <map>
#include <string>
#include <iomanip>
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()
#define itn int
typedef long long ll;
constexpr auto mod = 1000000007;
using namespace std;
int main() {
  int x;
  cin>>x;
  int ans=0;
  int y=x/500;
  ans+=y*1000;
  int rem=x-y*500;
  ans+=(rem/5)*5;
  cout<<ans;
}


Measured memory_bytes: 256
n, d = gets.chomp.split.map(&:to_i)
area = n.times.map { gets.chomp.split.map(&:to_i) }

def dis(l, k)
  x = l.zip(k).map do |a, b|
    (a - b) ** 2
  end.inject(:+)
  Math.sqrt(x)
end

count = 0
0.upto(n - 1) do |i|
  (i + 1).upto(n - 1) do |j|
    x = dis(area[i], area[j])
    count += 1 if x == x.to_i
  end
end

puts count


Measured memory_bytes: 1788
N, M = map(int, input().split())
ans = ['-1'] * N

if N == 1 and M == 0:
    ans = 0
    print(ans)
    exit()

for i in range(M):
    s, c = map(int, input().split())
    if ans[s-1] == str(c):
        continue
    elif ans[s-1] == '-1':
        ans[s-1] = str(c)
    else:
        ans = -1
        print(ans)
        exit()

if N >= 2 and ans[0] == '0':
    ans = -1
    print(ans)
    exit()
elif ans[0] == '-1':
    ans[0] = '1'

ans = ''.join(ans).replace('-1', '0')

print(ans)

Measured memory_bytes: 3192
#include <iostream>

int main(){
	int n, m;
	std::cin >> n >> m;

	for(int i = 0; i < m; ++i){
		int a;
		std::cin >> a;
		n -= a;
	}

	if(n < 0){
		std::cout << -1 << std::endl;
		return 0;
	}

	std::cout << n << std::endl;

	return 0;
}


Measured memory_bytes: 3632
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define rep(i,n) for (int i=0; i<(int)(n); ++i)
#define rep0(i,n) for (int i=0; i<=(int)(n); ++i)
#define rep1(i,n) for (int i=1; i<=(int)(n); ++i)
#define rrep(i,n) for (int i=(int)(n)-1; i>=0; --i)
#define ALL(a) (a).begin(), (a).end()
#define RALL(a) (a).rbegin(), (a).rend()
using ll = long long;
using vi = vector<int>;
using vl = vector<ll>;
using vb = vector<bool>;
template<typename T> using Graph = vector<vector<T>>;
template<typename T> using Spacial = vector<vector<vector<T>>>;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
const int MOD = 1e9+7;
const int MOD2 = 998244353;
const double EPS = 1e-9;
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};

template<typename T> struct is_pair : false_type{};
template<typename T1, typename T2> struct is_pair<pair<T1, T2>> : true_type{};
template<typename T> struct is_vector : false_type{};
template<typename T> struct is_vector<vector<T>> : true_type{};

template<typename T1, typename T2>
istream &operator >> (istream &istr, pair<T1, T2> &p) {
  istr >> p.first >> p.second;
  return istr;
} 
template<typename T1, typename T2>
ostream &operator << (ostream &ostr, const pair<T1, T2> &p) {
  ostr << p.first << " " << p.second;
  return ostr;
}
template<typename T>
ostream &operator << (ostream &ostr, const vector<T> &vec) {
  if (vec.empty()) return ostr;
  bool vp = is_vector<T>() || is_pair<T>();
  ostr << vec.front();
  for (auto itr = ++vec.begin(); itr != vec.end(); ++itr) {
    ostr << (vp ? "\n" : " ") << *itr;
  }
  return ostr;
}

template<typename T1, typename T2>
inline bool chmax(T1 &a, T2 b) { return a < b && (a = b, true); }
template<typename T1, typename T2>
inline bool chmin(T1 &a, T2 b) { return a > b && (a = b, true); }

int modpow(int a, long long n, int mod = MOD) {
  int ret = 1;
  do {
    if (n & 1) ret = 1LL * ret * a % mod;
    a = 1LL * a * a % mod;
  } while (n >>= 1);
  return ret;
}

template<typename T>
T GCD(T a, T b) { return b ? GCD(b, a%b) : a; }
template<typename T>
T LCM(T a, T b) { return a / GCD(a, b) * b; }

template<typename T1, typename T2>
bool CompareBySecond(pair<T1, T2> a, pair<T1, T2> b) {
  return a.second != b.second ? a.second < b.second : a.first < b.first;
}
template<typename T>
bool CompareBySlope(pair<T, T> a, pair<T, T> b) {
// counterclockwise from 12 o'clock direction
  if (a.first * b.first < 0) return a.first < b.first;
  if (a.first == 0) return a.second >= 0 || b.first > 0;
  if (b.first == 0) return b.second < 0 && a.first < 0;
  return a.second * b.first < a.first * b.second;
}


/* -------- <templates end> -------- */


void solve() {
  int k, x; cin >> k >> x;
  if (500 * k >= x) cout << "Yes\n";
  else cout << "No\n";
}


/* -------- <programs end> -------- */


signed main() {
  cin.tie(nullptr);
  ios::sync_with_stdio(false);
  cout << fixed << setprecision(12);
  solve();
  return 0;
}


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

#define pb              push_back
#define pi              acos(-1.0)
#define loop(i,a,n)     for(int i=a;i<n;i++)
#define rloop(i,n,a)    for(int i=n;i>=a;i--)
#define ll              long long int
#define ff              first
#define ss              second
#define pii             pair<ll,ll>
#define sc1(a)          scanf("%d",&a)
#define sc2(a,b)        scanf("%d %d",&a,&b)
#define sc3(a,b,c)      scanf("%d %d %d",&a,&b,&c)
#define all(v)          v.begin(),v.end()
#define ms(a,b)         memset(a,b,sizeof a)
#define FastIO          ios_base::sync_with_stdio(0);cin.tie(0),cout.tie(0)
#define fileout         freopen("output.txt","w",stdout)
#define filein          freopen("input.txt","r",stdin)
#define inf             2e9+5
#define Q               int q;cin>>q;while(q--)
#define check           cout<<"HI"<<endl;

//int x[]= {-1,0,0,1};
//int y[]= {0,-1,1,0};

using namespace std;

int main()
{
    
    int n,s=0;
    sc1(n);

    int a[n+5];
    sc1(a[0]);
    s=a[0];
    loop(i,1,n)
    {
        sc1(a[i]);
        if(a[i]>a[i-1])s+=a[i]-a[i-1];
    }
    cout<<s<<endl;


    
}













Measured memory_bytes: 3688
#include <bits/stdc++.h>
#include<utility>
using namespace std;
 
int gcd(int n , int m){
	int r;
	while((r = n%m) != 0){
		n = m;
		m = r;
	}
	return m;
}	
 
int main(){
	int N , M;
	cin >> N >> M;
	string S , T;
	cin >> S >> T;
	int g = gcd(N , M);
	int a = N/g , b = M/g;
	
	int flag = 0;
	for(int x=0;x<g;x++){
		if(S[a*x] != T[b*x]){
			flag = 1;
		}
	}
	long long int G = g;
	long long int A = a;
	long long int B = b;
	long long int lcm = G*A*B;
	if(flag == 1){
		cout << -1 << endl;
	}else{
		printf("%lld" , lcm);
	}
	return 0;
}

Measured memory_bytes: 512
#include <stdio.h>

int main()
{
	int N;
	scanf("%d", &N);
	if (N < 105) printf("0\n");
	else if (N < 135) printf("1\n");
	else if (N < 165) printf("2\n");
	else if (N < 189) printf("3\n");
	else if (N < 195) printf("4\n");
	else printf("5\n");
	fflush(stdout);
	return 0;
}

Measured memory_bytes: 1636
#pragma GCC optimize(2)
#include<bits/stdc++.h>
using namespace std;
#define rint register int
#define rep(i,l,r) for(rint i=l;i<=r;i++)
#define per(i,l,r) for(rint i=l;i>=r;i--)
#define ll long long
#define ull unsigned long long
#define pii pair<int,int>
#define pll pair<ll,ll>
#define pb push_back
#define fir first
#define sec second
#define mset(s,t) memset(s,t,sizeof(s))
template<typename T1,typename T2>void ckmin(T1 &a,T2 b){if(a>b)a=b;}
template<typename T1,typename T2>void ckmax(T1 &a,T2 b){if(a<b)a=b;}
template<typename T>T gcd(T a,T b){return b?gcd(b,a%b):a;}
int read(){
  int x=0,f=0;
  char ch=getchar();
  while(!isdigit(ch))f|=ch=='-',ch=getchar();
  while(isdigit(ch))x=10*x+ch-'0',ch=getchar();
  return f?-x:x;
}
const int N=3000005;
int a[N],n,k;
ll maxx[N],dp[N];
#define ls (u<<1)
#define rs (u<<1|1)
void update(int u,int l,int r,int pos,ll x){
  if(l==r){
    maxx[u]=max(maxx[u],x);
    return;
  }
  int mid=l+r>>1;
  if(pos<=mid)update(ls,l,mid,pos,x);
  else update(rs,mid+1,r,pos,x);
  maxx[u]=max(maxx[ls],maxx[rs]);
}
ll query(int u,int l,int r,int ql,int qr){
  if(ql<=l&&r<=qr)return maxx[u];
  int mid=l+r>>1;ll ret=0;
  if(ql<=mid)ret=max(ret,query(ls,l,mid,ql,qr));
  if(qr>mid)ret=max(ret,query(rs,mid+1,r,ql,qr));
  return ret;
}
int main(){
  n=read(),k=read();
  if(k<0)k=-k;
  for(int i=1;i<=n;i++){
    a[i]=read();
  }
  for(int i=1;i<=n;i++){
    dp[i]=1+query(1,-300000,300000,max(-300000,a[i]-k),min(300000,a[i]+k));
    update(1,-300000,300000,a[i],dp[i]);
  }
  printf("%d\n",maxx[1]);
  return 0;
}


Measured memory_bytes: 15528
#include <bits/stdc++.h>
using namespace std; 
#define int int64_t
#define itn int
#define fi first
#define se second
signed main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int k,sum=7;
  int ans=-1;
  cin>>k;
  for(int i=0;i<=k;i++){
    if(i==0) sum%=k;
    else{
      sum*=10;
      sum+=7;
      sum%=k;
    }
    if(sum==0){
      ans=i+1;
      break;
    }
  }
  cout<<ans<<"\n";
}


Measured memory_bytes: 3608
#include <iostream>
#include <string>
#include <iomanip>
#include <ios>
using namespace std;
int main(void){
  string s;
  cin >> s;
  
  long long k;
  cin >> k;
  
  long long n = s.length();
  long long count = 1;
  long long ans = 0;
  long long anst = 0;
  char check = s[0];
  bool same = true;
  for(long long i=1;i<n;i++){
      if(check != s[i]) same = false;
  }
  if(same) cout << (n * k) / 2 << endl;
  else{
  for(long long i=1;i<n;i++){
    if(s[i] == s[i-1]){
        count++;
    } 
    if(s[i] != s[i-1] || i == n-1){
      ans += count / 2;
      count = 1;
    }
  }
  count = 1;
  
  string t = s + s;
  for(long long i=1;i<n * 2;i++){
    if(t[i] == t[i-1]){
        count++;
    } 
    if(t[i] != t[i-1] || i == n * 2 - 1){
      anst += count / 2;
      count = 1;
    }
  }
  
    long long d = anst - 2 * ans;
    ans *= k;
    
    cout << ans + (k - 1) * d << endl;
  }
    
    return 0;
  }

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

const int NM_MAX = 1500;
const int WH_MAX = 1000;
const int PT_MAX = NM_MAX * WH_MAX;

// 一方の端を 0 に正規化し、
// もう一方の長さの先の点を数える
array<int, PT_MAX> nw, nh;

int main() {
    int n, m;
    while (cin >> n >> m, n || m) {
        vector<int> dw(n), dh(m);
        for (int& x : dw) cin >> x;
        for (int& x : dh) cin >> x;
        nh.fill(0);
        nw.fill(0);
        for (int i = 0; i < n; i++) {
            int s = 0;
            for (int j = i; j >= 0; j--) {
                s += dw[j];
                nw[s]++;
            }
        }
        for (int i = 0; i < m; i++) {
            int s = 0;
            for (int j = i; j >= 0; j--) {
                s += dh[j];
                nh[s]++;
            }
        }
        int cnt = 0;
        for (int i = 0; i < NM_MAX * WH_MAX; i++) {
            cnt += nw[i] * nh[i];
        }
        cout << cnt << endl;
    }
    return 0;
}

Measured memory_bytes: 12920
#include<iostream>
#include<vector>
#include<algorithm>

using namespace std;


int main(){
	
	string s;
	//long X,t,sub;
	cin >> s;
	
	//if(sub<=0)sub=0;
	for(int i=0;i<s.size();i+=2){
	
		cout<< s[i];
	}
	cout << endl;
}

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

static const long long M = (long long) 1e9 + 7ll;

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

    long long A09, A0, A9, Ano;
    long long A09p, A0p, A9p, Anop;

    Ano=8; A09=0; A0=1; A9=1;

    for(int i=2; i<=N; i++){

        Anop=Ano; A09p=A09; A0p=A0; A9p=A9;

        A09 = (A09p*10 + A9p + A0p) % M;
        A9 = ( A9p*9 + Anop ) % M;
        A0 = ( A0p*9 + Anop ) % M;
        Ano= ( Anop*8 ) % M;

    }

    cout << A09 << endl;

    return 0;
}

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

int main() {
    int n, m, result = 0;
    cin >> n >> m;
    vector<int> graph[n + 1];
    int p[n + 1];
    for (int i = 1; i <= n; i++) {
        cin >> p[i];
    }
    for (int x, y; cin >> x >> y; ) {
        graph[x].emplace_back(y);
        graph[y].emplace_back(x);
    }
    bool visited[n + 1] = {};
    for (int i = 1; i <= n; i++) {
        if (!visited[i]) {
            visited[i] = true;
            stack<int> stack;
            stack.emplace(i);
            vector<int> index, value;
            do {
                auto top = stack.top();
                index.emplace_back(top);
                value.emplace_back(p[top]);
                stack.pop();
                for (int j : graph[top]) {
                    if (!visited[j]) {
                        visited[j] = true;
                        stack.emplace(j);
                    }
                }
            } while (!stack.empty());
            sort(begin(value), end(value));
            for (int j : index) {
                if (binary_search(begin(value), end(value), j)) {
                    result++;
                }
            }
        }
    }
    cout << result;
    return 0;
}


Measured memory_bytes: 7084
#include <algorithm>
#include <cfloat>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <functional>
#include <iostream>
#include <map>
#include <memory>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>
#include <iomanip>
using namespace std;
 
typedef long long ll;
 
#define sz size()
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define all(c) (c).begin(), (c).end()
#define rep(i,a,b) for(ll i=(a);i<(b);++i)
#define per(i,a,b) for(ll i=(b-1);i>=(a);--i)
#define clr(a, b) memset((a), (b) ,sizeof(a))
#define ctos(c) string(1,c)
#define print(x) cout<<#x<<" = "<<x<<end
 
int main(void) {
	ll a,b;
	cin>>a>>b;
	cout << (a*b-b-a+1) << endl;
	return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<vector>
using namespace std;
int main() {
	int N,ans=0;
	int judge;
	cin >> N;
	vector<int> H(N);
	for (int i = 0; i < N; i++) {
		cin >> H[i];
	}
	for (int i = 0; i < N; i++) {
		judge = 0;
		for (int k = 0; k < i; k++) {
			if (H[i] < H[k]) {
				break;
			}
			else judge++;
			
		}
		if (judge == i) {
			ans++;
		}
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 384
package main

import (
	"fmt"
	"math"
)

func GCD(a, b int) int {
	if(b == 0) {
		return a
	} else {
		return GCD(b, a%b)
	}
}

func main(){
	var a, b int
	var ans int
	fmt.Scanf("%d%d", &a, &b)
	a = int(math.Abs(float64(a)))
	b = int(math.Abs(float64(b)))
	ans = GCD(a,b)
	fmt.Printf("%d\n", ans)
}



Measured memory_bytes: 1172
#include <iostream>
#include <fstream>
#include <cstdio>
#include <cassert>
#include <complex>
#include <cmath>
#include <algorithm>
#include <vector>
#include <string>
#include <cstdlib>
#include <cstring>
#include <iomanip>
#include <numeric>
#include <sstream>
#include <ctime>
#include <cctype>
#include <set>
#include <map>
#include <queue>
#include <bitset>
#include <deque>
#include <stack>
#include <memory.h>
using namespace std;
#define mp make_pair
int n;
int a[100005];
int ans;
int main()
{
	cin>>n;
	for(int i=0;i<n;i++){
		cin>>a[i];
		while(a[i]%2==0){
			a[i]/=2;
			ans++;
		}
	}
	cout<<ans;
    return 0;
}

Measured memory_bytes: 256
N,M= map(int, input().split())
p = [0] * M
S = [0] * M
for i in range(M):
    p[i], S[i] = map(str, input().split())
    
AC_list=[0]*N
pena=[0]*N
for i in range(M):
    if S[i]=='AC':
        AC_list[int(p[i])-1]+=1
    else:
        if AC_list[int(p[i])-1]==0:
            pena[int(p[i])-1]+=1
num=0
num1=0
for i in range(N):
    if AC_list[i]!=0:
        num+=1
        num1+=pena[i]
print(num ,num1)

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

int main()
{
  int N, K;
  cin >> N >> K;
  unordered_set<int> D(K);
  int d;
  for (int i = 0; i < K; i++)
  {
    cin >> d;
    D.insert(d);
  }

  int n = N++;
  int r = 0;
  while (n)
  {
    r += D.count(n % 10);
    n /= 10;
  }
  while (r)
  {
    n = N++;
    r = 0;
    while (n)
    {
      r += D.count(n % 10);
      n /= 10;
    }
  }

  cout << N - 1 << endl;

  return 0;
}

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

#define rep(i,a,b) for(int i=a;i<b;i++)
#define int long long
const int inf = 100100100100100009;
const int mod = 1000000007;

vector<vector<int>> warshaint_floyd(vector<vector<int>> edges,int v){
    vector<vector<int>> ret = edges;
    rep(k,0,v){
        rep(i,0,v){
            rep(j,0,v){
                if(ret[i][k] == inf || ret[k][j] == inf) continue;
                ret[i][j] = min(ret[i][j],ret[i][k] + ret[k][j]);
            }
        }
    }
    return ret;
}

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

    int n, m; cin >> n >> m;
    vector<vector<int>> arr(n, vector<int>(n,inf));

    rep(i,0,m){
        int f, t, c; cin >> f >> t >> c; f--; t--;
        arr[f][t] = c; arr[t][f] = c;
    }

    vector<vector<int>> wf = warshaint_floyd(arr, n);

    int ans = 0;
    rep(i,0,n){
        rep(j,i+1,n){
            if(arr[i][j] < inf && arr[i][j] > wf[i][j]) ans++;
        }
    }
    cout << ans << endl;




}   

Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define rep(i, n) for(int i = 0; i < (n); ++i)
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define ALL(v) (v).begin(), (v).end()
#define ios() ios::sync_with_stdio(0); cin.tie(0); cout.tie(0)
using ll = long long;
using ull = unsigned long long;
using vi = vector<int>;
using vvi = vector<vi>;
using pii = pair<int,int>;
constexpr ll MOD = 1e9+7;
constexpr ll INF = 1LL << 60;
constexpr int Inf = 1e9;
inline int in() {int x; cin >> x; return x;}
template <typename T> inline void out(const T& x) {cout << x << endl;}
template <class T> inline bool chmin(T &a, T b){if (a > b){a = b;return 1;}return 0;}
template <class T> inline bool chmax(T &a, T b){if (a < b){a = b;return 1;}return 0;}
//UP = 0;RIGHT = 1; DOWN = 2; LEFT =3;
const int dx[] = {0, 1, 0, -1, 1, -1, 1, -1}, dy[] = {1, 0, -1, 0, 1, -1, -1, 1};
int gcd(int a, int b)
{
  if (a < b)
    gcd(b, a);
  if(b==0) return a;
  int r;
  while ((r = a % b))
  {
    a = b;
    b = r;
  }
  return b;
}
void eratos(bool * isPrime,int max){
  fill(isPrime,isPrime + max,true);
  isPrime[0] = false; 
  isPrime[1] = false; 
  for(int i=2; i<=max/i; ++i) 
      if(isPrime[i]) 
          for(int j=2; j<=max/i; ++j) 
              isPrime[i*j] = false;    
}
//

signed main()
{
  ios();
  
  int N;
  cin >> N;
  vi A(N);
  rep(i,N)
  {
    cin >> A[i];
  }  
  vi L(N+1),R(N+1);
  L[0] = 0;
  R[N] = 0;
  rep(i,N)
  {
    L[i+1] = gcd(L[i],A[i]); 
  }
  for(int i = N;i>0;i--)
  {
    R[i-1] = gcd(R[i],A[i-1]);
  }
  int ans = 0;
  rep(i,N)
  {
    chmax(ans,gcd(L[i],R[i+1]));
  }
  cout << ans << endl;
}


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

#define ll long long

#define rep(i,a,b) for(ll i=a;i<b;i++)
#define repb(i,a,b) for(ll i=a;i>=b;i--)
#define alll(it,A) for(it=A.begin();it!=A.end();it++)

#define err1(a) cout<<#a<<" "<<a<<endl
#define err2(a,b) cout<<#a<<" "<<a<<" "<<#b<<" "<<b<<endl
#define err3(a,b,c) cout<<#a<<" "<<a<<" "<<#b<<" "<<b<<" "<<#c<<" "<<c<<endl

#define mp make_pair
#define pb push_back
#define all(A)  A.begin(),A.end()
#define ft first
#define sd second

#define pll pair<ll,ll>
#define V vector<ll>
#define S set<ll>

const ll N=100005;
const ll M = 1000000007;

ll dp[3005][3005];

int main()
{
    ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
    string a,b,s;
    cin>>a>>b;
    ll n,m;
    n=a.length();m=b.length();
    rep(i,1,n+1) rep(j,1,m+1){
    	if(a[i-1]==b[j-1])	dp[i][j]=max(dp[i-1][j-1]+1,dp[i][j]);
    	else dp[i][j]=max(dp[i-1][j],dp[i][j-1]);
    }
    ll i=n,j=m;
    while(i+j){
    	if(i && dp[i][j]==dp[i-1][j])	i--;
    	else if(j && dp[i][j]==dp[i][j-1]) j--;
    	else s=s+a[i-1],i--,j--;
    }
    reverse(all(s));
    cout<<s;
    return 0;
}


Measured memory_bytes: 70656
#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")

#define REP(i, n) for (int i = 0; i < n; i++)
#define FOR(i, m, n) for (int i = m; i < n; i++)
#define ALL(v) v.begin(), v.end()

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

int main() {
    int K;
    string S;
    cin >> K >> S;
    if (K < S.size()) {
        REP(i, K) {
            cout << S[i];
        }
        cout << "...";
    } else {
        cout << S;
    }
    cout << endl;
    return 0;
}


Measured memory_bytes: 3628
#define _USE_MATH_DEFINES

#include <stdio.h>
#include <iostream>
#include <algorithm>
#include <cmath>
#include <string>
#include <utility>
#include <climits>
#include <vector>
#include <map>
#include <queue>
#include <set>
using namespace std;

#define ll long long
const int MOD = 1000000007;//10^9+7
const string SPACE = " ";

ll powsur(ll a, ll b, ll p) {

	if (b == 0) {

		return 1;

	}
	else if (b % 2 == 0) {

		ll d = powsur(a, b / 2, p);
		return ((d%p)*(d%p)) % p;

	}
	else {

		return ((a%p)*powsur(a, b - 1, p) % p) % p;

	}

}
//pは素数,aのb乗をpで割った余り

ll CMOD(ll n, ll r, ll p) {

	ll a = 1, b = 1, c = 1, re;
	for (int i = 1; i <= n; i++) {

		a *= i;
		a = a%p;

	}
	for (int i = 1; i <= r; i++) {

		b *= i;
		b = b%p;

	}
	for (int i = 1; i <= n - r; i++) {

		c *= i;
		c = c%p;

	}
	b = powsur(b, p - 2, p);
	c = powsur(c, p - 2, p);
	re = ((a%p)*(b%p)) % p;
	re = ((re%p)*c%p) % p;

	return re;

}
//pは素数,(nCr)%p

ll gcd(ll a, ll b) {

	if (a > b) {

		ll tmp = a;
		a = b;
		b = tmp;

	}
	ll r;
	r = b%a;
	if (r == 0)return a;
	else return gcd(r, a);

}
//最大公約数

ll lcm(ll a, ll b) {

	return (a / gcd(a, b))*b;

}
//最小公倍数

ll MAX(ll a, ll b) {

	if (a > b)return a;
	else return b;

}
//MAX

int main() {

	int N, A;

	cin >> N >> A;

	if (N % 500 <= A)cout << "Yes" << endl;
	else cout << "No" << endl;

	return 0;
}

Measured memory_bytes: 256
import fractions
a, b = map(int, input().split())
n = fractions.gcd(a, b)
k = int(n**0.5)
cnt = 1
for i in range(2, k + 1):
    if n == 1:
        break
    elif n % i == 0:
        while n % i == 0:
            n //= i
        cnt += 1
if n != 1:
    cnt += 1
print(cnt)


Measured memory_bytes: 5048
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<(int)(n);++i)
#define repone(i,n) for(int i=1;i<(int)(n);++i)
#define repo(i,o,n) for(int i=o;i<(int)(n);++i)
#define Rep(j,n) for(int j=0;j<(int)(n);++j)
#define Repo(j,o,n) for(int j=o;j<(int)(n);++j)
#define Repone(j,n) for(int j=1;j<(int)(n);++j)
#define all(v) (v).begin(),(v).end()
#define rall(v) (v).rbegin(),(v).rend()
#define int long long
#define pb(a) push_back(a)
#define eraser(v,i) (v).erase(v.begin()+(i))
#define pbpair(a,b) push_back(make_pair(a,b))
#define Little 1
const long long INF = 1LL<<60;
#define pairint pair<int,int>
signed main(){
  int x=0,y=0,z=0,w=1,n=11,m=0,o=0;
  std::cin >> x>>y;
  std::cout << x*y << '\n';
}


Measured memory_bytes: 3568
#include<bits/stdc++.h>
#include<string.h>
 
typedef long long int ll;
#define all(x) (x).begin(), (x).end()
 
using namespace std;

int nxt() {
    int x;
    cin >> x;
    return x;
}

ll nxtl(){
    ll x;
    cin>>x;
    return x;
}
 
void SieveOfEratosthenes(int n,vector <int> &primes) 
{ 
    // Create a boolean array "prime[0..n]" and initialize 
    // all entries it as true. A value in prime[i] will 
    // finally be false if i is Not a prime, else true. 
    bool prime[n+1]; 
    memset(prime, true, sizeof(prime)); 
  
    for (int p=2; p*p<=n; p++) 
    { 
        // If prime[p] is not changed, then it is a prime 
        if (prime[p] == true) 
        { 
            // Update all multiples of p greater than or  
            // equal to the square of it 
            // numbers which are multiple of p and are 
            // less than p^2 are already been marked.  
            for (int i=p*p; i<=n; i += p) 
                prime[i] = false; 
        } 
    } 
  
    // Print all prime numbers 
    for (int p=2; p<=n; p++) 
       if (prime[p]) 
          primes.push_back(p);
} 
 
ll max(ll a,ll b)
{
    if(a>b)
        return a;
    return b;
}
 
ll power(ll x, ll y,ll mod) 
{ 
    ll temp; 
    if( y == 0) 
        return 1; 
    temp = power(x, y/2,mod); 
    if (y%2 == 0) 
        return (temp*temp)%mod; 
    else
        return (((x*temp)%mod)*temp)%mod; 
}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    double x;
    cin>>x;
    //cout<<x<<endl;
    cout<<setprecision(15)<<2*x*3.141592653589793<<endl;
    
    
    
    return 0;   
}




 
 


Measured memory_bytes: 3804
N = int(input())
town_names = dict()
assessments = []
for x in range(N):
  if x!=N:
    SP = input().split()
    assessments.append(SP[1])
    town_names.setdefault(SP[0],[]).append(assessments.index(SP[1])+1)
  else:
    break
result = []
for t in sorted(town_names):
  tmp = []
  for pointer in town_names[t]:
    tmp.append(assessments[pointer-1])
  for x in sorted(tmp, reverse=True,key=int):
    result.append(assessments.index(x)+1)
  tmp = []
for x in result:
  print(x)


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

using namespace std;

typedef long double ld;
typedef unsigned long long ull;
typedef long long ll;

int p[200005];

int main()
{
    int n,x; cin >> n;
    for(int i=1;i<=n;++i) cin >> x , p[x] = i ;
    int p1 = 0, p2 = 0;
    vector<int> v;
    for(int i=2;i<=n;++i)
    {
        if(p[i]<p[i-1]) v.push_back(i-1);
    }
    int aftermid = 0,beforemid = 0;
    vector<int> sol;
    for(int i=v.size()-1;i>=0;--i)
    {
        if(i==v.size()-1) sol.push_back(v[v.size()-1]);
        if(i>0) sol.push_back(n-v[i] + v[i-1]);
        else sol.push_back(n - v[i]);
    }
    if(sol.size()>1) sort(sol.begin(),sol.end()),cout << sol[0] << endl;
    else cout << 0;
    return 0;
}







Measured memory_bytes: 3316
n = int(input())
a = list(map(int, input().split()))
s = [0] * (n + 1)

for i in range(n):
    s[i + 1] = s[i] + a[i]

ans = 3e9
for i in range(n - 1):
    ans = min(ans, abs((s[n] - s[i + 1]) - s[i + 1]))
print(ans)

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

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef set<int> si;

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

    string s, t;
    cin >> s >> t;
    sort(s.begin(), s.end());
    sort(t.begin(), t.end(), greater<char>());
    if (s < t)
        cout << "Yes" << endl;
    else
        cout << "No" << endl;

    return 0;
}

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

#ifdef LOCAL
#define debug(var) cerr << (#var) << " = " << (var) << endl;
#else
#define debug(var)
#endif

void init() {
  ios_base::sync_with_stdio(0);
  cin.tie(0); cout.tie(0);
}

const int N = 323;

char a[N][N];
int ans[N][N];

void solve() {
  int h, w, k; scanf("%d%d%d", &h, &w, &k);
  for (int i = 0; i < h; ++i) {
    for (int j = 0; j < w; ++j) {
      scanf(" %c", a[i]+j);
      a[i][j] = a[i][j] == '#';
    }
  }
  int piece = 1;
  for (int i = 0; i < h; ++i) {
    bool first = true, empty = true;
    for (int j = 0; j < w; ++j) {
      if (a[i][j]) {
	empty = false;
	break;
      }
    }
    if (empty) continue;
    for (int j = 0; j < w; ++j) {
      if (a[i][j]) {
	if (first) {
	  first = false;
	  ans[i][j] = piece;
	} else {
	  ans[i][j] = ++piece;
	}
      } else {
	ans[i][j] = piece;
      }
    }
    ++piece;
  }
  for (int i = 0; i < h-1; ++i)
    for (int j = 0; j < w; ++j)
      if (!ans[i+1][j])
	ans[i+1][j] = ans[i][j];
  for (int i = h-1; i > 0; --i)
    for (int j = 0; j < w; ++j)
      if (!ans[i-1][j])
	ans[i-1][j] = ans[i][j];
  for (int i = 0; i < h; ++i) {
    for (int j = 0; j < w; ++j) {
      printf("%d ", ans[i][j]);
    }
    puts("");
  }   
}

int main() {
  init();
  int t = 1; //scanf("%d", &t);
  while (t--) {
    solve();
  }
  return 0;
}


Measured memory_bytes: 1280
using System;
using System.Linq;

class prog{
  static void Main(){
    
    string S = Console.ReadLine();
    string T = Console.ReadLine();
    bool judge = false;
    
    for(int i = 0; i < S.Length; i++){
      if(S == T) judge = true;
      S = S.Substring(S.Length - 1) + S.Substring(0,S.Length - 1);
    }
    
    Console.WriteLine(judge ? "Yes" : "No");
    
  }
}

Measured memory_bytes: 11092
#include <iostream>
#include <math.h>
#include<bits/stdc++.h> 
using namespace std;
double distance(int x1,int y1,int x2,int y2){
    double d=pow((pow(x1-x2,2)+pow(y1-y2,2)),0.5);
    return d;
}

int main() {
	// your code goes here
	int n,i,j;
	cin>>n;
	int x[n],y[n];
	
	for(i=0;i<n;i++){
	    cin>>x[i]>>y[i];
	}
	int a=1;
	for(i=0;i<n;i++){
	    a*=(n-i);
	}
	int b=1;
	for(i=0;i<n-1;i++){
	    b*=(n-1-i);
	    
	}
	double sum=0;
	for(i=0;i<n;i++){
	    for(j=i+1;j<n;j++){
	        sum+=distance(x[i],y[i],x[j],y[j]);
	    }
	}
	double avg=(sum*2*b)/a;
	cout<<fixed<<setprecision(10)<<avg<<endl;
	
	
	
	return 0;
}


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

using namespace std;


int main(int argc, char* argv[]){
	int N, x;
	scanf("%d", &N);

	vector<int> A;

	for (int i=0; i < N; i++) {
		scanf("%d", &x);
		A.push_back(x);
	}
	
	sort(A.begin(), A.end());

	int ans = 0;
	for (auto L=A.begin(); L != A.end(); L++) {
		for (auto R=L+1; R != A.end(); R++) {
			int mn = (*R) - (*L) + 1;
			int mx = (*R) + (*L) - 1;

			ans += (upper_bound(R + 1, A.end(), mx) - lower_bound(R + 1, A.end(), mn));
		}
	}

	printf("%d\n", ans);
	return 0;
}

Measured memory_bytes: 256
#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
using namespace std;
const int maxtime=2e9;
int num[10];
int f[50][50],dis[50][50];
struct Q{
	double t;
}q[50][512];
struct S{
	int ind,state;
}s[50000],ss[50000];
int sp,ssp;
char inpt[100];
int main(){
	int i,j,n,m,p,a,b,x,y,z,ind,state,t,l;
	double pt;
	while(scanf("%d%d%d%d%d",&n,&m,&p,&a,&b)==5){
		if(n==0&&m==0&&p==0&&a==0&&b==0) break;
		getchar();
		
		fgets(inpt,sizeof(inpt),stdin);
		t=0,l=0;
		for(j=0;inpt[j]!='\n';j++){
			if(inpt[j]<='9'&&inpt[j]>='0') t=t*10+inpt[j]-'0';
			else num[l++]=t,t=0;
		}
		num[l]=t;
		
		for(i=1;i<=m;i++) f[i][0]=0;
		for(i=0;i<p;i++){
			fgets(inpt,sizeof(inpt),stdin);
			t=0,l=0;
			for(j=0;inpt[j]!='\n';j++){
				if(inpt[j]<='9'&&inpt[j]>='0') t=t*10+inpt[j]-'0';
				else{
					if(l==0) x=t;
					else y=t;
					t=0,++l;
				} 
			}
			z=t;
			f[x][++f[x][0]]=y,f[y][++f[y][0]]=x;
			dis[x][f[x][0]]=z,dis[y][f[y][0]]=z;
		}
		
		int k=1<<n;
		for(i=1;i<=m;i++) for(j=0;j<k;j++) q[i][j].t= maxtime;
		q[a][0].t=0;
		sp=0,s[sp].ind=a,s[sp++].state=0;
		while(1){
			ssp=0;
			for(i=0;i<sp;i++){
				ind=s[i].ind,state=s[i].state;
				for(j=1;j<=f[ind][0];j++){
					for(z=0;z<n;z++){
						if((1<<z)&state) continue;
						pt=q[ind][state].t+(0.0+dis[ind][j])/num[z];
						if(pt<q[f[ind][j]][state+(1<<z)].t){
							q[f[ind][j]][state+(1<<z)].t=pt;
							ss[ssp].ind=f[ind][j],ss[ssp++].state=state+(1<<z);
						}
					}
				}
			}
			if(!ssp) break;
			for(i=0;i<ssp;i++) s[i].ind=ss[i].ind,s[i].state=ss[i].state;sp=ssp;
		}
		
		// Check
		double mintime=maxtime;
		for(i=0;i<k;i++){
			if(mintime>q[b][i].t) mintime=q[b][i].t;
		}
		if(mintime==maxtime) puts("Impossible");
		else printf("%.3f\n",mintime);
		/*
		for(i=1;i<=m;i++){
			cout<<"i:"<<i<<endl;
			for(j=0;j<k;j++) cout<<j<<' '<<q[i][j].t<<endl;
		}
		 * */
	}
	
	return 0;
}


Measured memory_bytes: 3432
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <cmath>
#include <map>
#include <queue>
#include <iomanip>
#include <set>
#include <tuple>
#define mkp make_pair
#define rep(i,n) for(int i = 0; i < (n); ++i)
using namespace std;
typedef long long ll;
const ll MOD=1e9+7;

int H,W,K;
string board[303];

int ans[303][303];

int main(){
  cin>>H>>W>>K;
  rep(i,H) cin>>board[i];

  int num=1;
  int lu=0;
  for(int i=0;i<H;i++){
    int val=-1;
    int lef=0;
    for(int j=0;j<W;j++){
      if(board[i][j]=='#'){
        for(int k=lu;k<=i;k++){
          for(int l=lef;l<=j;l++){
            ans[k][l]=num;
          }
        }
        num++;
        lef=j+1;
        val=num;
      }
    }

    if(val!=-1) lu=i+1;
  }

  for(int i=0;i<H;i++){
    for(int j=0;j+1<W;j++){
      if(ans[i][j+1]==0) ans[i][j+1]=ans[i][j];
    }
  }

  for(int j=0;j<W;j++){
    for(int i=0;i+1<H;i++){
      if(ans[i+1][j]==0) ans[i+1][j]=ans[i][j];
    }
  }

  for(int i=0;i<H;i++){
    for(int j=0;j<W;j++){
      cout<<ans[i][j]<<" ";
    }
    cout<<endl;
  }

  return 0;
}


Measured memory_bytes: 1280
a,b,c = sorted(map(int, raw_input().split()))
count = 0

if (c-a)%2 and (c-b)%2:
    c-=1
    count = (c-a+c-b)/2 + 1
elif (c-a)%2==(c-b)%2==0:
    count = (c-a+c-b)/2
else:
    count = (c-a + c-b + 1)/2 + 1

print count
    


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

double p[3009], dp[3009][3009], ans;
int n, vis[3009][3009];

double call(int i, int j)
{
    if(vis[i][j])
        return dp[i][j];
    vis[i][j] = 1;

    if(!i && !j)
        return dp[i][j] = 1;

    if(!j)
        dp[i][j] = call(i-1, j) * (1 - p[i]);
    else if (i < j)
        return 0;
    else
        dp[i][j] = call(i-1, j) * (1 - p[i]) + call(i-1, j-1) * p[i];

    return dp[i][j];
}

int main()
{
    int i;
    cin >> n;
    for(i = 1; i <= n; i++)
        cin >> p[i];

    for(i = n/2 + 1; i <= n; i++)
        ans += call(n, i);

    cout << fixed << setprecision(9) << ans;
}


Measured memory_bytes: 104576
#include <bits/stdc++.h>
typedef long long ll;
typedef long double ld;
const int INF=1e9,MOD=1e9+7,ohara=1e6+10;
const ll LINF=1e18;
using namespace std;

#define rep(i,n) for(int (i)=0;(i)<(int)(n);(i)++)
#define rrep(i,a,b) for(int i=(a);i<(b);i++)
#define rrrep(i,a,b) for(int i=(a);i>=(b);i--)
#define all(v) (v).begin(), (v).end()
#define Size(n) (n).size()
#define Cout(x) cout<<(x)<<endl
#define doublecout(a) cout<<fixed<<setprecision(15)<<a<<endl;
#define Cerr(x) cerr<<(x)<<endl
#define fi first
#define se second
#define P pair<ll,ll> 
#define m_p make_pair
#define V vector<ll> 

ll n,cnt,ans,a[ohara],b[ohara],c,d,tmp,tmpp,m,h,w,x,y,sum,pos,k;
ld doua;
int dy[]={1,0,-1,0};
int dx[]={0,1,0,-1};
//int dy[]={-1,0,1,-1,1,-1,0,1};
//int dx[]={-1,-1,-1,0,0,1,1,1};
string alph("abcdefghijklmnopqrstuvwxyz"),s;
bool fl;
struct edge{int to,cost;};

//-------------------------↓↓↓↓↓↓------------------------

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

    cin>>n;
    rep(i,n)cin>>a[i]>>b[i];
    tmp=*max_element(a,a+n);
    rep(i,n){
        if(tmp==a[i])ans=a[i]+b[i];
    }
    Cout(ans);
    return 0;
}


Measured memory_bytes: 5760
using System;
class Program
{
    static void Main(string[] args)
    {
        string[] input = Console.ReadLine().Split(' ');
        var N = int.Parse(input[0]);
        var A = int.Parse(input[1]);
        var B = int.Parse(input[2]);

        Console.WriteLine(Math.Min(N * A, B));
    }
}


Measured memory_bytes: 13140
#include <bits/stdc++.h>
#define ALL(obj) begin(obj), end(obj)
#define debug(x) cerr << #x << ": " << x << '\n'
using namespace std;
template <class T>
vector<T> make_vec(size_t a) {
    return vector<T>(a);
}
template <class T, class... Ts>
auto make_vec(size_t a, Ts... ts) {
    return vector<decltype(make_vec<T>(ts...))>(a, make_vec<T>(ts...));
}
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 (b < a) {
        a = b;
        return 1;
    }
    return 0;
}

using ll = long long;
using ull = unsigned long long;
const int INF = 1e9;
// const int MOD = 1e9 + 7;
/*  prime_factor(n)
    入力：整数 n
    出力：nの素因数分解
    計算量：O(√n)前後
*/
template <typename T>
vector<pair<T, T>> prime_factor(T n) {
    vector<pair<T, T>> ret;
    for (T i = 2; i * i <= n; i++) {
        T tmp = 0;
        while (n % i == 0) {
            tmp++;
            n /= i;
        }
        ret.push_back(make_pair(i, tmp));
    }
    if (n != 1) ret.push_back(make_pair(n, 1));
    return ret;
}

int main() {
    ll X;
    cin >> X;
    for (ll a = 0; a < 300; a++) {
        ll tmp = 1;
        for (int i = 0; i < 5; i++) {
            tmp *= a;
        }
        ll b = tmp - X;
        if (b == 1 || b == -1) {
            cout << a << " " << b << endl;
            return 0;
        }
        ll babs = abs(b);
        vector<pair<ll, ll>> pf = prime_factor(babs);
        bool flag = true;
        for (auto p : pf) {
            if (p.second % 5 != 0) flag = false;
        }
        if (flag) {
            ll ans = 1;
            for (auto p : pf) {
                for (int i = 0; i < p.second / 5; i++) {
                    ans *= p.first;
                }
            }
            if (b > 0) {
                cout << a << " " << ans << endl;
            } else {
                cout << a << " " << -ans << endl;
            }
            return 0;
        }
    }
}


Measured memory_bytes: 7196
main :: IO ()
main = do
  let
    f :: Int -> Int -> Int
    f k m = (2 * k) `min` (m - 1)
  [n, k] <- map read . words <$> getLine :: IO [Int]
  let
    step :: Char -> [Bool] -> [Bool]
    step 'L' rest = False : rest
    step 'R' rest = True : rest
    step _ _ = []
  ds <- foldr step [] <$> getContents :: IO [Bool]
  let
    (m, s) = foldl step (1, 0) . (zipWith (==) <$> id <*> tail) $ ds :: (Int, Int)
      where
        step :: (Int, Int) -> Bool -> (Int, Int)
        step (m, s) b | b         = (m, s + 1)
                      | otherwise = (m + 1, s)
  print $ s + f k m


Measured memory_bytes: 5064
H, W, h, w = map(int, input().split())
rem = H * W - (H - H % h) * (W - W % w)
if rem == 0:
    print('No')
    exit()
x = (H // h * W // w + rem) // rem
if abs(x) > 10**9 or abs(-(h * w - 1) * x - 1) > 10**9:
    print('No')
    exit()
print('Yes')
a = [[x] * W for _ in range(H)]
for i in range(h-1, H, h):
    for j in range(w-1, W, w):
        a[i][j] = -(h * w - 1) * x - 1
for row in a:
    print(*row)


Measured memory_bytes: 77148
n = int(input())
t, a = map(int, input().split())
h = list(map(int, input().split()))

temp_diff = 10**10
ans = 0

for i in range(n):
    temp = abs(a-(t-h[i]*0.006))
    if temp < temp_diff:
        temp_diff = temp
        ans = i+1

print(ans)

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

typedef unsigned long long ull;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<double, double> pdd;
const ull mod = 1e9 + 7;
#define REP(i,n) for(int i=0;i<(int)n;++i)

//debug
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

template<class S, class T> ostream& operator << (ostream& os, const pair<S, T> v){
  os << "(" << v.first << ", " << v.second << ")"; return os;
}
template<class T> ostream& operator << (ostream& os, const vector<T> v){
  for(int i = 0; i < (int)v.size(); i++){if(i > 0){os << " ";} os << v[i];} return os;
}
template<class T> ostream& operator << (ostream& os, const vector<vector<T>> v){
  for(int i = 0; i < (int)v.size(); i++){if(i > 0){os << endl;} os << v[i];} return os;
}

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

    ll N;
    string S;
    cin >> N >> S;
    REP(i, S.size()){
    	ll ind = ((S[i]-'A')+N)%26;
    	cout << char('A'+ind);
    }
    cout << endl;
    return 0;
}

Measured memory_bytes: 256
// ?????¬???????????¬?????? (define int long long ?????????)

#include <iostream>
#include <iomanip>
#include <cstdio>
#include <string>
#include <cstring>
#include <deque>
#include <list>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <complex>
#include <cmath>
#include <limits>
#include <cfloat>
#include <climits>
#include <ctime>
#include <cassert>
#include <numeric>
#include <functional>
using namespace std;

#define rep(i,a,n) for(int (i)=(a); (i)<(n); (i)++)
#define repq(i,a,n) for(int (i)=(a); (i)<=(n); (i)++)
#define repr(i,a,n) for(int (i)=(a); (i)>=(n); (i)--)

template<typename T> void chmax(T &a, T b) {a = max(a, b);}
template<typename T> void chmin(T &a, T b) {a = min(a, b);}
template<typename T> void chadd(T &a, T b) {a = a + b;}

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

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

const int INF = 1 << 25;
int R, C;
int board[20][10010];
int inv[20][10010];

int main() {
    while(cin >> R >> C, R || C) {
        rep(i,0,R) rep(j,0,C) {
            cin >> board[i][j];
            inv[i][j] = board[i][j] ^ 1;
        }

        int ans = 0;
        rep(bit,0,1<<R) {
            vector<int> cnt(C);
            rep(i,0,R) {
                // ?????£????????????
                if(bit >> i & 1) {
                    rep(j,0,C) {
                        cnt[j] += inv[i][j];
                    }
                }
                // ?????£??????????????????
                else {
                    rep(j,0,C) {
                        cnt[j] += board[i][j];
                    }
                }
            }

            int tmp = 0;
            rep(i,0,C) {
                tmp += max(cnt[i], R - cnt[i]);
            }
            ans = max(ans, tmp);
        }
        cout << ans << endl;
    }
    return 0;
}

Measured memory_bytes: 3796
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines


n,m = map(int,readline().split())
d = [-1]
d += list(map(int,readline().split()))
uv = list(map(int,read().split()))

inf = 10**9
bw = ['?'] * (n+1)
edge_cost = [inf] * (m+1)

links = [dict() for _ in range(n+1)]
links_same =[[-1,-1] for _ in range(n+1)]
roots = set()
for i in range(1,m+1):
    u,v = uv[(i-1)*2 : i*2]
    if(d[u]==d[v]):
        links_same[u] = [v,i]
        links_same[v] = [u,i]
        roots.add(u)
        roots.add(v)
    elif(d[u] < d[v]):
        links[u][v] = i
    else:
        links[v][u] = i

for root in roots:
    if(bw[root] != '?'):
        continue

    stack = [root]
    root2 = links_same[root][0]
    if(bw[root2] == 'B'):
        bw[root] = 'W'
    elif(bw[root2] == 'W'):
        bw[root] = 'B'
    else:
        bw[root] = 'B'
        bw[root2] = 'W'
        stack.append(root2)
    edge_cost[links_same[root][1]] = d[root]

    while(stack):
        i = stack.pop()
        for j,e in links[i].items():
            if(bw[j] != '?'):
                continue
            bw[j] = bw[i]
            edge_cost[e] = d[j] - d[i]
            stack.append(j)

if(bw.count('?')!=1):
    print(-1)
    exit()

print(''.join(bw[1:]))
print('\n'.join(map(str,edge_cost[1:])))

Measured memory_bytes: 177452
N, A, B, C = map(int, input().split())
l = [int(input()) for _ in range(N)]

ret = float('inf')

def mp(x, target) :
    ret = -10
    long = 0
    for i in range(N) :
        if x & 1 :
            ret += 10
            long += l[i]
        x >>= 1
    ret += abs(long - target)
    return ret

for i in range(1, 1 << N) :
    for j in range(1, 1 << N) :
        if i & j :
            continue
        for k in range(1, 1 << N) :
            if i & k or j & k :
                continue
            ret = min(ret, mp(i, A) + mp(j, B) + mp(k, C))

print(ret)

Measured memory_bytes: 48492
#include <stdio.h>

int main (){

    int G, N;
    scanf("%d %d", &G, &N);
    int z = 1;

for (int i = 0; i < G; i++) {
        if (2 * z <= z + N) {
            z *= 2;
        } else {
            z += N;
        }
    }
    printf("%d", z);


    return 0;
}

Measured memory_bytes: 1680
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define ll long long
#define fi first
#define se second
#define pb push_back
#define rep(i, s, n) for (int i = s; i < n; i++)
#define rrep(i, s, n) for (int i = (n)-1; i >= (s); i--)
#define REP(i,n) for(int i = 0;i < n; i++)
#define all(a) a.begin(),a.end()
typedef pair<int,int>pint;
typedef vector<int>vint;
typedef vector<pint>vpint;
const long long MOD = 1000000007, INF = 1e18;
 
#define endl '\n'
#define IOS() ios_base::sync_with_stdio(0);cin.tie(0)
 
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;}
template<typename T>vector<T>
make_v(size_t a){return vector<T>(a);}
template<typename T,typename... Ts>
auto make_v(size_t a,Ts... ts){
	return vector<decltype(make_v<T>(ts...))>(a,make_v<T>(ts...));
}
 
template<typename T,typename V>
typename enable_if<is_class<T>::value==0>::type
fill_v(T &t,const V &v){t=v;}
 
template<typename T,typename V>
typename enable_if<is_class<T>::value!=0>::type
fill_v(T &t,const V &v){
	for(auto &e:t) fill_v(e,v);
}

/*bool operator<(const data &d)const{
	return hoge;
}*/

int N,M,S,G1,G2;
int d[111][111];
void warshall_floyd(int n) { // nは頂点数
  for (int i = 0; i < n; i++)      // 経由する頂点
    for (int j = 0; j < n; j++)    // 開始頂点
      for (int k = 0; k < n; k++)  // 終端
        d[j][k] = min(d[j][k], d[j][i] + d[i][k]);
}

int solve(){
	S--;G1--;G2--;
	rep(i,0,101)rep(j,0,101){
		if(i==j)d[i][j] = 0;
		else d[i][j] = INF;
	}
	rep(i,0,M){
		int a,b,c;
		cin>>a>>b>>c;
		a--;b--;
		d[a][b] = c;
	}
	warshall_floyd(N);
	int ret = INF;
	rep(i,0,N){
		int t = 0;
		t += d[S][i];
		t += d[i][G1];
		t += d[i][G2];
		chmin(ret,t);
	}
	return ret;
}
 
signed main(){
	IOS();
	vector<int>ans;
	while(cin>>N>>M>>S>>G1>>G2,N||M||S||G1||G2){
		auto t = solve();
		ans.push_back(t);
	}
	for(auto e:ans){
		cout<<e<<endl;
	}
}


Measured memory_bytes: 3284
#include<bits/stdc++.h>
using namespace std;
#define int long long int
const int mxN =150000;
int32_t main(){
  ios_base::sync_with_stdio(0);
   cin.tie(0); cout.tie(0);

        int n; cin>>n;
        int m[n][3];
        int dp[n][3];
        for(int i=0;i<n;i++) for(int j=0;j<3;j++) cin>>m[i][j],dp[i][j]=m[i][j];
        
//		for(int i=0;i<3;i++) dp[n-1][i]=m[n-1][i];	
        for(int i=n-2;i>=0;i--){
        	for(int j=0;j<3;j++)
        	{
        		 
        		 dp[i][j]+=max(dp[i+1][(j+1)%3],dp[i+1][(j+2)%3]);
			}
		}	
		
		cout<<max( max(dp[0][0],dp[0][1]),dp[0][2]);
  



 return 0;}



Measured memory_bytes: 4992
#include <iostream>
#include <string>
#include <stdio.h>
#include <set>
#include <map>
#include <vector>
#include <algorithm>
#include <cmath>
#include <cfloat>
#include <math.h>
#include <stack>
#include <queue>
#include <cstdio>
#include <iomanip>

using namespace std;

#define ll long long
#define rep(i, n) for (int i = 0; i < n; i++)
// #define req(j, n) for (ll j = 1; j < (n+1); j++)
// #define rer(k, n) for (ll k = 1; k < (n+1); k++)


int main()
{
    int N;
    int ans;
    string digit;
    string keta;
    int kete;
    cin >> N;
    if (N < 1000) {
        ans = 1000 - N;
    } else if (N % 1000 == 0) {
        ans = 0;
    } else {
        digit = to_string(N);
        keta = digit[0];
        keta = keta + "000";
        kete = stoi(keta);
        ans = kete + 1000 - N;
    }
    cout << ans << endl;
}

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

#define rep(i, n) for(int i = 0; i<(n); i++)
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
using namespace std;
typedef long long ll;

struct UnionFind {
    vector<int> par;

    UnionFind(int n) : par(n, -1) {}

    void init(int n) { par.assign(n, -1); }

    int root(int x) {
        if (par[x] < 0) return x;
        else return par[x] = root(par[x]);
    }

    bool issame(int x, int y) {
        return root(x) == root(y);
    }

    bool merge(int x, int y) {
        x = root(x);
        y = root(y);
        if (x == y) return false;
        if (par[x] > par[y]) swap(x, y); // merge technique
        par[x] += par[y];
        par[y] = x;
        return true;
    }

    int size(int x) {
        return -par[root(x)];
    }
};

int main() {
    int N, M;
    cin >> N >> M;
    vector<int> a(M), b(M);
    rep(i, M) {
        cin >> a[i] >> b[i];
        a[i]--;
        b[i]--;
    }

    int ans = 0;
    rep(i, M) {
        UnionFind uf(N);
        rep(j, M) {
            if (i == j) continue;
            uf.merge(a[j], b[j]);
        }

        if (!uf.issame(a[i], b[i])) ans++;
    }

    cout << ans << endl;
}

Measured memory_bytes: 256