akhauriyash/Code-Regression huggingface dataset:
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<queue>
#include<vector>
using namespace std;
struct bian{int nxt,to;}bi[4040];
int n,m,head[2020],num,tot,f[2020],d[2020],dep[2020],cnt[2020],ans,c[4040];
inline void add(int from,int to){bi[++num]=bian{head[from],to};head[from]=num;}
pair<int,int>b[4040],l[4040];
vector<int>E[2020];
vector<pair<int,int> >E1[4040];
bool bj[4040];
queue<int>q;
void ADD(int x,int y,int C)
{
//	printf("%d %d %d\n",x,y,C);
	E1[x].push_back(make_pair(y,C));
	E1[y].push_back(make_pair(x,C));
}
void dfs(int v,int fa)
{
	dep[v]=dep[fa]+1;f[v]=fa;
	for(int i=head[v],u;i;i=bi[i].nxt)
	{
		u=bi[i].to;
		if(u==fa)continue;
		dfs(u,v);++d[v];
	}
	if(!d[v])q.push(v);
}
void work(int x,int y,int id)
{
	while(x!=y)
	{
		if(dep[x]>dep[y])++cnt[x],E[x].push_back(id),x=f[x];
		else ++cnt[y],E[y].push_back(id),y=f[y];
	}
}
void erase(int x)
{
	int b1=0,b2=0,u,v;
	for(auto p:E[x])
		if(!bj[p])
		{
			if(!b1)b1=p;
			else if(!b2)
			{
				b2=p;
				u=l[b1].first==x?l[b1].second:l[b1].first;
				v=l[b2].first==x?l[b2].second:l[b2].first;
				if(u==v)ADD(b1,b2,(l[b1].first!=x)==(l[b2].first!=x));
				else
				{
					++tot;
				//	printf("%d %d\n",u,v);
					if(l[b1].first==x)ADD(b1,tot,1);
					else u=l[b1].first,ADD(b1,tot,0);
					if(l[b2].first==x)ADD(b2,tot,0);
					else ADD(b2,tot,1);
					l[tot]=make_pair(u,v);work(u,v,tot);
				}
				bj[b1]=bj[b2]=1;
			}
		}
	for(auto p:E[x])
		if(!bj[p])
		{
			if(l[p].first==f[x]||l[p].second==f[x])continue;
			else
			{
				if(l[p].first==x)l[p].first=f[x];
				else l[p].second=f[x];
			}
		}
}
void dfs1(int v,bool C)
{
	c[v]=C+1;
	for(auto u:E1[v])if(!c[u.first])dfs1(u.first,C^u.second);
}
int main()
{
	scanf("%d %d",&n,&m);
	int x,y;
	for(int i=1;i<n;++i)
	{
		scanf("%d %d",&x,&y);
		add(x,y),add(y,x);
	}
	dfs(1,0);
	for(int i=1;i<=m;++i)scanf("%d %d",&b[i].first,&b[i].second),work(b[i].first,b[i].second,i),l[i]=b[i];tot=m;
	for(int i=1;i<=n;++i)ans+=min(cnt[i],2);
	printf("%d\n",ans);
	while(!q.empty())
	{
		x=q.front();q.pop();
		erase(x);
		--d[f[x]];
		if(!d[f[x]])q.push(f[x]);
	}
	for(int i=1;i<=tot;++i)if(!c[i])dfs1(i,0);
	for(int i=1;i<=m;++i)
	{
		if(c[i]==2)swap(b[i].first,b[i].second);
		printf("%d %d\n",b[i].first,b[i].second);
	}
	return 0;
}

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

int main (void){
    int N, K;
    cin >> N >> K;
    if (N % 2 != 0){
        if (N / 2 + 1 >= K) { 
            cout << "YES";
        }
        else cout << "NO";
       
    }
    else {
        if (N / 2 >= K) cout << "YES";
        else cout << "NO";
    }
    cout << endl;
}

Measured memory_bytes: 256
until (n = $stdin.gets.to_i) == 0
  data = Array.new(n + 1).map{Array.new(n + 1)}

  n.times do |i|
    num = $stdin.gets.chomp.split(" ").map(&:to_i)
    num.size.times do |j|
      data[i][j] = num[j]
    end
  end

  total = 0
  n.times do |i|
    sumV = 0
    sumH = 0
    n.times do |j|
      sumV += data[j][i]
      sumH += data[i][j]
    end
    data[n][i] = sumV
    data[i][n] = sumH
    total += sumH
  end
  data[n][n] = total

  (n+1).times do |i|
    (n+1).times do |j|
      printf "%5d", data[i][j]
    end
    puts ""
  end
end

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

#define ALL(a) (a).begin(), (a).end()
#define FOR(i, s, n) for (int i = (s); i < (n); i++)
#define rep(i, n) FOR(i, 0, n)
#define repi(i, n) FOR(i, 1, n + 1)
#define pp(v) cerr << #v "=" << (v) << endl;
#define ppa(v) cerr << "- " << #v << endl; rep(i,v.size()) cerr << #v << "[" << i << "] = " << v[i] << endl;
#define div_ceil(a,b) ((a) + ((b) - 1)) / (b)
#define UNIQUE(v) v.erase( unique(ALL(v)), v.end() );
#define INF 0x3f3f3f3f
#define LLINF 1000111000111000111LL
#define MOD 1000000007
#define TIME system("date +%M:%S.%N")
using Graph = vector<vector<int>>;
using ll = long long;
template<class T> T gcd(const T &a, const T &b) { return a < b ? gcd(b, a) : b ? gcd(b, a % b) : a; }
template<class T> T lcm(const T &a, const T &b) { return a / gcd(a, b) * b; }

int main() {
  int n;cin>>n;
  vector<pair<int,int>> a(n);
  vector<int> ans(n);
  rep(i,n) {
    int x;cin>>x;
    a[i] = make_pair(x,i);
  }
  sort(ALL(a));
  rep(i,n) {
    if (i < n/2) ans[a[i].second] = a[n/2].first;
    else ans[a[i].second] = a[n/2-1].first;
  }
  rep(i,n) {
    cout << ans[i] << endl;
  }
}


Measured memory_bytes: 4480
#include <bits/stdc++.h>
#define ll long long
#define double long double
#define rep(i,n) for(int i=0;i<(n);i++)
#define REP(i,n) for(int i=1;i<=(n);i++)
#define mod (ll)(1e9+7)
#define inf (ll)(3e18+7)
#define P pair<int,int>
#define PiP pair<int,pair<int,int>>
#define all(x) x.begin(),x.end()
using namespace std;

int main() {
  bool c=true;
  string s;
  cin >> s;
  REP(i, s.size()) {
     if(i % 2 == 0) {
       if(s[i-1] == 'R' && s[i-1] != 'U' && s[i-1] != 'D') c=false;
     }else{
       if(s[i-1] == 'L' && s[i-1] != 'U' && s[i-1] != 'D') c=false;
     }
  }
  if(c) cout << "Yes";
  else cout << "No";
}

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

bool solve(const vector<string>& w) {
    const int n = w.size();
    for(int i = 0; i < n-1; i++) {
        if(w[i].back() != w[i+1].front()) {
            return false;
        }
    }
    for(int i = 0; i < n; i++) {
        for(int j = i + 1; j < n; j++) {
            if(w[i] == w[j]) {
                return false;
            }
        }
    }
    return true;
}
vector<string> input()  {
    int n; cin >> n;
    vector<string> w(n);
    for(int i = 0; i < n; i++) {
        cin >> w[i];
    }
    return w;
}
int main() {
    const vector<string> w = input();
    if(solve(w)) {
        cout << "Yes" << endl;
    } else {
        cout << "No" << endl;
    }
}


Measured memory_bytes: 256
n, m = map(int, input().split())
x = sorted(list(map(int, input().split())))
y = sorted(list(map(int, input().split())))
tx = 0
ty = 0
sx = 0
sy = 0
for i in range(n):
  tx += i * x[i] - sx
  sx += x[i]
for i in range(m):
  ty += i * y[i] - sy
  sy += y[i]
print(tx * ty % 1000000007)


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

using namespace std;

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

const int N = 1e5 + 5;

vector <string> v;
string s,big;
int n;

string get(int x) {
  string ret;
  for (int i = 0 ; i < x ; i++)
    ret.push_back(s[i]);
  bool asd = false;
  for (char i = s[x] + 1 ; i <= 'z' ; i++) {
    bool flag = true;
    for (int j = 0 ; j < ret.size() ; j++)
      if (ret[j] == i)
        flag = false;
    if (flag) {
      asd = true;
      ret.push_back(i);
      break;
   }
  }
  if (asd == false)
    return " ";
  return ret;
}


int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL); cout.tie(NULL);
  cin >> s;
  n = s.size();
  if (n == 26) {
    string ans;
    for (int i = 0 ; i < 26 ; i++) {
      auto tut = get(i);
      if (tut > s && (ans.size() == 0 || ans > tut))
        ans = tut;
    }
    if (ans.size() == 0)
      cout << "-1\n";
    else
      cout << ans << endl;
    return 0;
  }
  else {
    for (char i = 'a' ; i <= 'z' ; i++) {
      bool flag = true;
      for (int j = 0 ; j < n ; j++)
        if (s[j] == i)
          flag = false;
      if (flag) {
        s.push_back(i);
        break;
      }
    }
    cout << s << endl;
  }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const static ll INF = 1e9;


int main(){
    ll N; cin >> N;
    vector<ll> A(N); for(ll i = 0; i < N; i++) cin >> A[i];
    sort(A.begin(), A.end());
    vector<ll> D(N); D[0] = A[0];
    for(ll i = 1; i < N; i++) D[i] = D[i-1] + A[i];

    ll ans = 1;

    for(ll i = N-2; i >= 0; i--){
        if(2*D[i] >= A[i+1]) ans++;
        else break;
    }
    cout << ans << endl;


}

Measured memory_bytes: 1792
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef vector<long long> vll;

int main()
{
	ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
    ll a,b,c,d;
    cin>>a>>b>>c>>d;
    ll A=a*b;
    ll B=c*d;
    if(A>B)
    {
        cout<<A<<endl;
    }
    else
    {
        cout<<B<<endl;
    }

  return 0;
}



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

using namespace std;
using ll = long long;
using ld = long double;

#define ALL(x) begin(x), end(x)
#define REP(i, n) for (size_t i = 0, i##_len = (n); i < i##_len; ++i)

void solve(ll A, ll B, ll K) {
  int c{};
  for (auto i = min(A, B); i; --i) {
    if (A % i == 0 && B % i == 0) ++c;
    if (c == K) {
      cout << i << endl;
      return;
    }
  }
}

int main() {
  ll A;
  cin >> A;
  ll B;
  cin >> B;
  ll K;
  cin >> K;
  solve(A, B, K);
  return 0;
}


Measured memory_bytes: 256
//Bottom up solution
//Space complexity = O(W)
#include <bits/stdc++.h>
#define ll long long
using namespace std;

int main(){
	ll N, W;
	cin>>N>>W;
	std::vector<ll> wt(N);
	std::vector<ll> v(N);
	std::vector<ll> memo(W+1,0);
	for(int i=0; i<N; i++){
		cin>>wt[i]>>v[i];
	}
	for(int i=0; i<=N; i++){
		for(int w = W; w >= wt[i]; w--){
			memo[w] = std::max(memo[w], v[i] + memo[w-wt[i]]);
		}
	}
	cout<<memo[W];
	return 0;
}

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

class Program
{
	static void Main(string[] args)
	{
		var a = new int[26];
		var S = Console.ReadLine();
		for (int i = 0; i < S.Length; i++)
		{
			a[S[i] - 'a']++;
		}
		for (int i = 0; i < 26; i++)
		{
			if (a[i] == 0)
			{
				Console.WriteLine((char)('a' + i));
				return;
			}
		}
		Console.WriteLine("None");
	}
}

Measured memory_bytes: 13116
#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <algorithm>
#include <cstring>
#include <vector>
#include <map>
#include <cmath>
 
#define rep(i,n) for(int i = 0;i < (n);i++)
#define all(x) (x).begin(),(x).end()
#define pb(x) push_back(x)
#define mp(a,b) make_pair(a,b)

using namespace std;

typedef long long int ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<pair<int, int> > vpi;
typedef vector<pair<ll, ll> > vpl;

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
  int a, b, c, d;
  cin >> a >> b >> c >> d;
  int ans = min(b, d) - max(a, c);
  if(ans > 0){
    cout << ans << endl;
  }else{
    cout << 0 << endl;
  }
	return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

    /**
     * @param args the command line arguments
     */
    public static void main(String[] args) {
        
        Scanner s = new Scanner(System.in);
        int n = s.nextInt();
        
        double pSum = 0;
        
        for (int i = 0; i < n; i ++) {
            int in = s.nextInt();
            pSum += 1.0 / in;
        }
        
        System.out.println(1.0 / pSum);
    }
    
}


Measured memory_bytes: 21844
#include <iostream>
using namespace std;
int main() {
  char b;
  cin >> b;
  char ans;
  switch(b) {
    case 'A': ans = 'T'; break;
    case 'T': ans = 'A'; break;
    case 'C': ans = 'G'; break;
    case 'G': ans = 'C'; break;
    default: ans = ' ';
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int shibaku(int p , int money){
  //2種類(1000円共通)
  for(int j=0;money-5000*j>=0;j++){
 	 if(p==j+(money-5000*j)/1000){
     	cout<<0<<" "<<j<<" "<<p-j<<endl;
       	return 0;
 	 }else if(p==j+(money-10000*j)/1000 && money-10000*j>=0){
       cout<<j<<" "<<0<<" "<<p-j<<endl;
       	return 0;
     }
  }
  return 1;
}
void check(int money,int p){
  int a=p-2,b=1,c=1;
  bool bl=true;
  while(bl){
    int y=10000*a+5000*b+1000*c;
    if(y==money){
    	cout<<a<<" "<<b<<" "<<c<<endl;
    	bl=false;
    } else if(a==1){
       cout<<-1<<" "<<-1<<" "<<-1<<endl;;
       bl=false;
    }else if(b==1){
      a--;
      c=1;
      b=p-a-1;
    }else if(b!=1){
      b--;
      c++;
    }
   
  }
}
  
	

int main(){
  int n,y;//n：お札の枚数y:申告金額
  cin>>n>>y;
  if(y%1000!=0){//yは1000の倍数
    cout<<-1<<" "<<-1<<" "<<-1<<endl;
  }else if(n>y/1000){
    cout<<-1<<" "<<-1<<" "<<-1<<endl;
  }else if(y%1000==0 &&n==y/1000){
      cout<<0<<" "<<0<<" "<<n<<endl;
  }else if(y%5000==0&&n==y/5000){
      cout<<0<<" "<<n<<" "<<0<<endl;
  }else if(y%10000==0&&n==y/10000){
      cout<<n<<" "<<0<<" "<<0<<endl;
  }else{
    int num=shibaku(n,y);

    if(num!=0){
      check(y,n);
    }
  }
}
    
    
    
  

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

int main(){
    int n,x;
    cin >> n >> x;
    vector<int> l(n),d(n);
    for(int i=0;i<n;i++) cin >> l[i];
    int count=0;
    d[0]=0;
    int i,j=0;
    for(i=1;i<n+1;i++){
        d[i]=d[i-1]+l[i-1];
        if(d[i]<=x) j++;
    }
    cout << j+1 << endl;
    }


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < n; i++)
#define REPR(i, n) for (int i = n; i >= 0; i--)
#define FOR(i, m, n) for (int i = m; i < n; i++)
#define ALL(v) v.begin(), v.end()
using namespace std;
typedef long long ll;
typedef long double ld;
const ll MOD = 998244353;

ll modpow(ll a, ll n) {
  ll res = 1;
  while(n > 0) {
    if(n & 1) res = res * a % MOD;
    a = a * a % MOD;
    n >>= 1;
  }
  return res;
}

int main()
{
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
	int n;
	cin >> n;
    vector<int> d(n);
	map<int, ll> mp;
	int d_max = 0;
	REP(i,n){ 
	  cin >> d[i];
	  mp[d[i]]++;
	  d_max = max(d_max, d[i]);
	}
	if(mp[0]!=1 || d[0]!=0){
	  cout << "0\n";
	  return 0;
	}
  
	ll ans = 1;
	FOR(i, 1, d_max+1){
      if(mp[i]==0){
        cout << "0\n";
        return 0;
      }
      ll tmp = modpow(mp[i-1], mp[i]);
      ans = (ans * tmp) % MOD;
	}
	cout << ans << '\n';
	return 0;
}



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

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

  long long ans;
  int i;
  bool ver;
  if(s1[0]==s2[0]){
    ans=3;
    i=1;
    ver = true;
  }
  else{
    ans=6;
    i=2;
    ver=false;
  }
  
  for (i=i; i < n; i++)
  {
    if(s1[i]==s2[i]){
      if(ver){
        ans*=2;
      }
      else{
        ver=true;
      }
    }
    else{
      if(ver){
        ans*=2;
        ver=false;
      }
      else{
        ans*=3;
      }
      i++;
    }
    ans%=1000000007;
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
    const long long inf=1000000000000;
    int n,m,l;
    cin>>n>>m>>l;
    int a[m],b[m],c[m];
    long long dist[n][n];
    for(int i=0;i<n;i++){
        for(int j=0;j<n;j++){
            if(i==j)dist[i][j]=0;
            else dist[i][j]=inf;
        }
    }
    for(int i=0;i<m;i++){
        cin>>a[i]>>b[i]>>c[i];
        dist[a[i]-1][b[i]-1]=c[i];
        dist[b[i]-1][a[i]-1]=c[i];
    }
    for(int k=0;k<n;k++)for(int i=0;i<n;i++)for(int j=0;j<n;j++)dist[i][j]=min(dist[i][j],dist[i][k]+dist[k][j]);
    long long charge[n][n];
    for(int i=0;i<n;i++){
        for(int j=0;j<n;j++){
            if(dist[i][j]<=l)charge[i][j]=1;
            else charge[i][j]=inf;
        }
    }
    for(int k=0;k<n;k++)for(int i=0;i<n;i++)for(int j=0;j<n;j++)charge[i][j]=min(charge[i][j],charge[i][k]+charge[k][j]);
    int q;
    cin>>q;
    int s[q],t[q];
    for(int i=0;i<q;i++){
        cin>>s[i]>>t[i];
        s[i]--;
        t[i]--;
    }
    for(int i=0;i<q;i++){
        if(charge[s[i]][t[i]]!=inf)cout<<charge[s[i]][t[i]]-1<<endl;
        else cout<<"-1"<<endl;
    }
    return 0;
}


Measured memory_bytes: 6168
from sys import exit
A,B,C = [int(n) for n in input().split()]
# N = int(input())
# a = [int(input()) for _ in range(N)]
# S = str(input())
# L = len(S)
# T = str(input())
# exit()
if A != B and B == C:
    print(A)
elif A == B and B != C:
    print(C)
else:
    print(B)


Measured memory_bytes: 2940
#include<bits/stdc++.h>
using namespace std;
int main(){
string s;
cin>>s;
int l=s.size();
if(l%2==0){
    cout<<"No"<<endl;
}
else{
int n1=(l-1)/2;
int n2=(l+3)/2;
string s1="",s2="";
int c1=0,c2=0;
for(int i=0;i<n1;i++){
 if(s[i]==s[(n1-1)-i]) {
   c1++;
 }
}
for(int i=n2-1;i<l;i++){
 if(s[i]==s[(l-1)-i]) {
   c2++;
 }
}
if(c1==(n1-1)+1 && c2==(l-n2)+1){
  cout<<"Yes"<<endl;
}
else{
  cout<<"No"<<endl;
}
}




}




Measured memory_bytes: 256
import sys
import time
#import copy
from collections import deque, Counter, defaultdict
#from fractions import gcd
input = sys.stdin.readline
sys.setrecursionlimit(10**6)

h, w= list(map(int,input().split()))

s=[list(input().strip()) for i in range(h)]

dis=[[0]*w for i in range(h)]
visited = [[0]*w for i in range(h)]

total_point=0
for i in range(h):
    for u in range(w):
        if s[i][u]==".":
            total_point+=1

def bfs(y, x):
    q = deque([])
    q.append((y, x, -1))
    while len(q):
        
        y, x, d = q.popleft()
        if visited[y][x]==0:
            dis[y][x] = d+1
            visited[y][x] = 1
            if y==h-1 and x==w-1:
                break
            
            dx = [0, -1 ,0 ,1]
            dy = [-1 ,0 ,1 ,0]
            for i in range(4):
                
                nx = x + dx[i]
                ny = y + dy[i]
                if nx<0 or ny<0 or nx>=w or ny>=h or visited[ny][nx]==1 or s[ny][nx]=="#":
                    continue
                q.append((ny, nx, dis[y][x]))
bfs(0,0)
if visited[h-1][w-1]==0:
    print(-1)
else:
    print(total_point-dis[h-1][w-1]-1)

Measured memory_bytes: 3440
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <iomanip>
#include <stack>
#include <algorithm>
#include <iostream>
#include <string>
#include <map>

using namespace std;


int main() {

    int N;
    cin >> N;

    vector<vector<int>> vs(10);

    for (int j = 0; j < 10; ++j) {
        vs[j].resize(10);
        vs[j].assign(10, 0);
    }

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

        string s = to_string(i);
        int f = s[0] - '0';
        int l = s[s.size() - 1] - '0';

        vs[f][l] += 1;
    }
    long sum = 0;
    for (int i = 0; i < 10; ++i) {
        for (int j = 0; j < 10; ++j) {
            sum += vs[i][j] * vs[j][i];
        }
    }

    cout << sum << "\n";

    return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;
import java.util.stream.IntStream;

public class Main {
	public static void main(String[] args) {
		// TODO Auto-generated method stub
		Scanner sc = new Scanner(System.in);
		int N = Integer.parseInt(sc.next());

		long ans = IntStream.rangeClosed(1, N).filter(s -> !((10 <= s && s <= 99) || (1000 <= s && s <= 9999) || s == 100000)).count();

		System.out.println(ans);

		sc.close();
	}
}


Measured memory_bytes: 27344
// #include <bits/stdc++.h>
#include <iostream>
#include <vector>
#include <map>
#include <algorithm>
using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
#define all(x) (x).begin(),(x).end()
#define sz(x) ((int)(x).size())

template<typename T>
T mod(T a, T b){
    return (a + b) % b;
}

template<typename T>
T gcd(T a, T b){
    if (b == 0) return a;
    return gcd(b, a % b);
}

ll lcm(ll a, ll b){
    return a * b / gcd(a,b);
}

// n を素因数分解
map<ll, ll> factor(ll n){
    map<ll, ll> mp;
    for (ll i = 2; i*i <= n; i++) {
        while (n % i == 0) {
            mp[i]++;
            n /= i;
        }
    }

    if (n > 1) {
        mp[n]++;
    }

    return mp;
}

// 文字列に "hoge" が含まれているか
// string str = "hogepiyo";
// if (str.find("hoge") != string::npos) {
//     cout << "文字列が含まれています" << endl;
// }

// char to string
// char c = 'a';
// string str = {c};

void solve(){
    int A, B, Q;
    cin >> A >> B >> Q;

    vector<ll> s(A), t(B), x(Q);
    for (int i = 0; i < A; i++) cin >> s[i];
    for (int i = 0; i < B; i++) cin >> t[i];
    for (int i = 0; i < Q; i++) cin >> x[i];

    sort(all(s));
    sort(all(t));
    // sort(all(x));

    for (int idx = 0; idx < Q; idx++) {
        ll ans = 100000000000;
        auto upa = lower_bound(all(s), x[idx]);
        auto loa = upper_bound(all(s), x[idx]); loa--;
        auto upb = lower_bound(all(t), x[idx]);
        auto lob = upper_bound(all(t), x[idx]); lob--;

        // auto enda = s.end(), endb = t.end();
        ll pos = x[idx];
        if (upa != s.end() && upb != t.end() && 
                pos <= *upa && pos <= *upb) {
            if (*upb <= *upa) ans = min(ans, *upa - pos);
            else ans = min(ans, *upb - pos);
        }

        if ( lob >= t.begin() && upa != s.end() &&
                *lob <= pos && pos <= *upa ) {
            ans = min(ans, min(abs(pos - *lob), abs(pos - *upa))*2 + max(abs(pos - *lob), abs(pos - *upa)) );
        }

        if ( loa >= s.begin() && upb != t.end() &&
                *loa <= pos && pos <= *upb) {
            ans = min(ans, min(abs(pos - *loa), abs(pos - *upb))*2 + max(abs(pos - *loa), abs(pos - *upb)) );
        }

        if ( loa >= s.begin() && lob >= t.begin() ) {
            if (*loa <= *lob) {
                ans = min(ans, abs(pos - *loa));
            } else {
                ans = min(ans, abs(pos - *lob));
            }
        }
        cout << ans << endl;
    }


    return;
}

int main(int argc, char const* argv[])
{
    solve();
    return 0;
}


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

#define fast_cin() ios_base::sync_with_stdio(false); cin.tie(NULL)
using namespace std;
long long maxv = 1e9;

int main()
{
    int N;
    cin>>N;
    int A;
    int maxi=INT_MIN;
    int total=0;
    for(int i=0;i<N;i++){
        cin>>A;
        total+=A;
        if(A>maxi){
            maxi=A;
        }
    }
    if(total-maxi>maxi){
        cout<<"Yes";
    }else{
        cout<<"No";
    }
    return 0;
}

Measured memory_bytes: 3624
#include<bits/stdc++.h>
using namespace std;
#define Elhabashy ios::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
void input()
{
#ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
#endif
}
const int N=1e5+5,mod=1e9+7;
typedef long long ll;
ll n,ans;
map<int,ll>mp;
int main()
{
    Elhabashy
    input();

    cin>>n;
    cout<<(n>=30?"Yes":"No");

}


Measured memory_bytes: 3572
#include <bits/stdc++.h>
using namespace std;
#define pii pair<int,int>
#define pll pair<long long, long long >
#define ll long long
#define lcm(a,b) (a)/__gcd((a),(b))*(b)
#define pb push_back
#define mp make_pair
#define x first
#define y second
#define maxn 100000000000000000
#define endl '\n'
#define trace(x) cerr << #x << ": " << x << endl;
#define trace2(x, y) cerr << #x << ": " << x << " | " << #y << ": " << y << endl;
#define trace3(x, y, z) cerr << #x << ": " << x << " | " << #y << ": " << y << " | " << #z << ": " << z << endl;
#define trace4(a, b, c, d)cerr << #a << ": " << a << " | " << #b << ": " << b << " | " << #c << ": " << c << " | " << #d << ": " << d << endl;
int mod(int x,int y)
{
  int s;
  s = abs(x)/y;
  if(x<0)s--;
  return x-y*s;
}
int dir8[2][8] = {{1,-1,0,0,1,-1,1,-1},{0,0,1,-1,1,-1,-1,1}};
int dir4[2][4] = {{1,-1,0,0},{0,0,1,-1}};
ll m,n,row,col;
ll ara[405];
ll dp[405][405];
ll sum[405];
void solve()
{
  scanf("%lld",&n);
  for(int w=0;w<n;w++)
  {
    scanf("%lld",&ara[w]);
    if(w==0)sum[w]=ara[w];
    else sum[w] = sum[w-1]+ara[w];
  }
  for(int i=0;i<n;i++)
  {
    for(int j=0;j+i<n;j++)
    {
      if(i == 0)dp[j][j] = 0;
      else
      {
        if(j-1 >=0)row = sum[j+i] - sum[j-1];
        else row = sum[j+i];
        for(int k =0; k < i; k++)
        {
          m = dp[j][j+k]+dp[j+k+1][j+i];
          col = (k==0)? m : min(col,m);
        }
        dp[j][j+i] = row + col;
      }
    }
  }
  cout << dp[0][n-1] << endl;


}
void test()
{
  int t;
  //scanf("%d",&t);
  t = 1;
  for(int test=1;test<=t;test++)
  {
    solve();
  }
}
int main()
{
  test();
  return 0;
}


Measured memory_bytes: 1536
#include <stdio.h>

int main(){
  int l,r,d;
  int i,count=0;
  scanf("%d %d %d",&l,&r,&d);

  for(i=l;i<=r;i++){
    if(i%d==0){
      count++;
    }
  }
  printf("%d\n",count);
  return 0;
}


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

using namespace std;

#define INF 100000000
#define YJ 1145141919
#define INF_INT_MAX 2147483647
#define INF_LL_MAX 9223372036854775807
#define EPS 1e-10
#define Pi acos(-1)
#define LL long long
#define ULL unsigned long long
#define LD long double

using namespace std;

#define MAX_N 300005

int N;

LL A[MAX_N];

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

  LL ans = 0;

  LL L = 0, R = 0;
  priority_queue<LL> RQue; //使っているもの
  priority_queue<LL, vector<LL>, greater<LL>> RGQue; //使っていないもの

  map<LL, int> RMap; //右側の値で使っているもののマップ
  map<LL, int> RGMap;

  priority_queue<LL, vector<LL>, greater<LL>> LQue;

  for (int i = 0; i < N; i++) {
    L += A[i];
    LQue.push(A[i]);
  }
  for (int i = N; i < 3*N; i++) {
    R += A[i];
    RQue.push(A[i]);
    RMap[A[i]]++;
  }

  while(RQue.size() > N){
    R -= RQue.top();
    RMap[RQue.top()]--;
    RGQue.push(RQue.top());
    RQue.pop();
  }

  ans = L - R;

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

    //左側更新
    LL LMin = LQue.top();
    if(LMin < A[i]){
      L -= LMin;
      L += A[i];
      LQue.pop();
      LQue.push(A[i]);
    }

    //右側更新
    if(RMap[A[i]] != 0){
      RMap[A[i]]--;
      R -= A[i];

      //使っていないものから一番小さいものを取得
      LL tmpR = 1145141919810;
      while(true){
        tmpR = RGQue.top();
        RGQue.pop();
        if(RGMap[tmpR] == 0){
          break;
        }
        RGMap[tmpR]--;
      }

      R += tmpR;
      RQue.push(tmpR);

      RMap[tmpR]++;
    }
    else{
      RGMap[A[i]]++;
    }

    ans = max(ans, L-R);

  }

  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 24432
n,x = map(int,input().split())
a_list = list(map(int,input().split()))
a_list.sort()
count = 0
for i in range(n):
    x = x - a_list[i]
    count += 1
    if x <= 0:
        break


if x == 0:
    print(count)
else:
    print(count-1)

Measured memory_bytes: 3060
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int MOD=1000000007;
#define INF 1LL<<30
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define all(x) (x).begin(),(x).end()


int main(){
    int n,m;
    cin>>n>>m;
    vector<int> num(n,1);
    vector<bool> red(n,false);

    red[0]=true;
    rep(i,m){
        int x,y;
        cin>>x>>y;
        x--,y--;
        if(red[x]) red[y]=true;
        num[x]--;
        num[y]++;
        if(num[x]==0) red[x]=false;
    }

    int ans=0;
    rep(i,n){
        if(red[i]) ans++;
    }

    cout<<ans<<endl;
}


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

int main() {
  int n, t = 0, h = 0;
  string st, sh;
  cin >> n;
  while (n--) {
    cin >> st >> sh;
    if (st > sh) {
      t += 3;
    } else if (st < sh) {
      h += 3;
    } else {
      t++; h++;
    }
  }
  cout << t << " " << h << "\n";
}


Measured memory_bytes: 3060
def cc
    n,k = gets.chomp.split(/\s/).map{|x| x.to_i}
    an = gets.chomp.split(/\s/).map{|x| x.to_i}

    if k == 2
        puts n-1
    elsif k == n
        puts 1
    elsif k > n/2
        puts 2
    else
        m = n-k
        cnt = 1
        while m > 0
            m -= k-1
            cnt += 1
        end
        puts cnt
    end
end

cc


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

using namespace std;

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n, a, b;
    string s;
    cin >> n >> a >> b >> s;
    int now = 0, now2 = 0, x = a + b;
    for (int i = 0; i < n; i++) {
        if (s[i] == 'a') {
            if (now < x) {
                cout << "Yes\n";
                now++;
            } else {
                cout << "No\n";
            }
        } else if (s[i] == 'b') {
            if (now < x && now2 < b) {
                cout << "Yes\n";
                now++;
                now2++;
            } else {
                cout << "No\n";
            }
        } else {
            cout << "No\n";
        }
    }
    return 0;
}

Measured memory_bytes: 848
#include<stdio.h>
int main (void)
{
	int n;
	int s;
	int cnt;
	
	scanf("%d",&n);
	while(n!=0){
		cnt=0;
		s=1000-n;
		while(s>=500){
			s=s-500;
			cnt++;
		}
		while(s>=100){
			s=s-100;
			cnt++;
		}
		while(s>=50){
			s=s-50;
			cnt++;
		}
		while(s>=10){
			s=s-10;
			cnt++;
		}
		while(s>=5){
			s=s-5;
			cnt++;
		}
		while(s>=1){
			s=s-1;
			cnt++;
		}
		printf("%d\n",cnt);
		scanf("%d",&n);
	}
	return 0;
}

Measured memory_bytes: 1028
using System;
using System.Collections.Generic;
using System.Linq;
using static Input;

public class Prog
{
    private const int INF = 1000000007;
    private const long INFINITY = 9223372036854775807;
    private struct Pair { public int x, y; }
    public static void Main()
    {
        int N = NextInt();
        double[] p = LineDouble();
        double[,] dp = new double[N + 1, N + 1];
        dp[0, 0] = 1.0;
        for (int i = 0; i < N; i++)
            for (int j = 0; j <= i; j++)
            {
                dp[i + 1, j] += dp[i, j] * (1 - p[i]);
                dp[i + 1, j + 1] += dp[i, j] * p[i];
            }
        double ans = 0.0;
        for (int i = (int)Math.Ceiling(N / 2.0); i <= N; i++) ans += dp[N, i];
        Console.WriteLine(ans);
    }
}

public class Input
{
    private static Queue<string> q = new Queue<string>();
    private static void Confirm() { if (q.Count == 0) foreach (var s in Console.ReadLine().Split(' ')) q.Enqueue(s); }
    public static int NextInt() { Confirm(); return int.Parse(q.Dequeue()); }
    public static long NextLong() { Confirm(); return long.Parse(q.Dequeue()); }
    public static char NextChar() { Confirm(); return char.Parse(q.Dequeue()); }
    public static string NextString() { Confirm(); return q.Dequeue(); }
    public static double NextDouble() { Confirm(); return double.Parse(q.Dequeue()); }
    public static int[] LineInt() { return Console.ReadLine().Split(' ').Select(int.Parse).ToArray(); }
    public static long[] LineLong() { return Console.ReadLine().Split(' ').Select(long.Parse).ToArray(); }
    public static string[] LineString() { return Console.ReadLine().Split(' ').ToArray(); }
    public static double[] LineDouble() { return Console.ReadLine().Split(' ').Select(double.Parse).ToArray(); }
}


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

using namespace std;
typedef long long ll;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef vector<VI> VVI;
typedef vector<VL> VVL;
typedef pair<int, int> P;
typedef pair<ll, ll> PL;
#define FOR(i, a, b) for(int i = 0; i < (a); ++i)
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define all(obj) (obj).begin(), (obj).end()
#define rall(obj) (obj).rbegin(), (obj).rend()
#define debug(x) cout << #x << ": " << x << endl
#define out(x) cout << x << endl
//#define int long long int
const int MOD = 1000000007;
const ll LINF = (ll)1e18 - 1;
const int INF = 1e9 - 1;
const double EPS = 0.000000001;
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};

void print(const vector<int> &v) {
  for(auto x : v) {
    cout << x << " ";
  }
  cout << endl;
}

signed main()
{
  cin.tie(0);
  ios::sync_with_stdio(false);
  int a;
  string s;
  cin >> a;
  cin >> s;
  a < 3200 ? out("red") : out(s);
  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define REP(i,st,ed) for(register int i=st,i##end=ed;i<=i##end;++i)
#define DREP(i,st,ed) for(register int i=st,i##end=ed;i>=i##end;--i)
typedef long long ll;
template<typename T>inline bool chkmin(T &x,T y){return (y<x)?(x=y,1):0;}
template<typename T>inline bool chkmax(T &x,T y){return (y>x)?(x=y,1):0;}
inline int read(){
	int x;
	char c;
	int f=1;
	while((c=getchar())!='-' && (c>'9' || c<'0'));
	if(c=='-') f=-1,c=getchar();
	x=c^'0';
	while((c=getchar())>='0' && c<='9') x=(x<<1)+(x<<3)+(c^'0');
	return x*f;
}
inline ll readll(){
	ll x;
	char c;
	int f=1;
	while((c=getchar())!='-' && (c>'9' || c<'0'));
	if(c=='-') f=-1,c=getchar();
	x=c^'0';
	while((c=getchar())>='0' && c<='9') x=(x<<1ll)+(x<<3ll)+(c^'0');
	return x*f;
}
const int maxn=700+10,inf=0x3f3f3f3f;
int co[maxn],tot1,tot2,n,m;
bitset<maxn> f,g,G[maxn];
void dfs(int x){
	if(co[x]==0) tot1++;
	else tot2++;
	REP(i,1,n) if(G[x][i]==0){
		if(co[i]!=-1 && (co[i]^co[x])==0){
			printf("-1\n");
			exit(0);
		}
		if(co[i]==-1){
			co[i]=(co[x]^1);
			dfs(i);
		}
	}
}
int main(){
	n=read(),m=read();
	REP(i,1,n) G[i][i]=1;
	while(m--){
		int x=read(),y=read();
		G[x][y]=1,G[y][x]=1;
	}
	REP(i,1,n) co[i]=-1;
	f[0]=1;
	REP(i,1,n) if(co[i]==-1){
		tot1=tot2=0;
		co[i]=0;
		dfs(i);
		g.reset();
		g|=(f<<tot1);
		g|=(f<<tot2);
		f=g;
	}
	int ans=inf;
	REP(i,1,n) if(f[i]) chkmin(ans,i*(i-1)/2+(n-i)*(n-i-1)/2);
	printf("%d\n",ans);
	return 0;
}


Measured memory_bytes: 384
input = require('fs').readFileSync('/dev/stdin', 'utf8')
lines = input.split('\n')
line = lines.shift().split(' ')
H = line[0] * 1
W = line[1] * 1 
line = lines.shift().split(' ')
h = line[0] * 1
w = line[1] * 1 
console.log(H * W - h*W - w*H + h * w)


Measured memory_bytes: 7372
"""

https://atcoder.jp/contests/agc047/tasks/agc047_e

まず2進数に直す

a[3] = a+b
a[4] = 0
a[5] = 1

100 <= n < 131 常に置いておく



"""

ans = []

def add(i,j,k):
    ans.append (("+",i,j,k))
    lis[k] = lis[i] + lis[j]

def slt(i,j,k):
    ans.append (("<",i,j,k))
    if lis[i] < lis[j]:
        lis[k] = 1
    else:
        lis[k] = 0

def make_binary(start):
    for i in range(start,start+31):
        if i == start:
            slt(4,3,i) #1が入る
        else:
            add(i-1,i-1,i)

def make_binary2(start):
    for i in range(start,start+64):
        if i == start:
            slt(4,3,i) #1が入る
        else:
            add(i-1,i-1,i)
            
def mul(i,j,k): #15,16
    add(i,j,15)
    slt(5,15,k)

A = 15
B = 2
lis = [0] * 200000
lis[0] = A
lis[1] = B

add(0,1,3) #lis[3] = a+b
slt(4,3,5) #lis[5] = 1
make_binary2(100)

#Aを分解する
make_binary(200)
for i in range(230,199,-1):
    add(0,4,11) #11にコピー
    add(11,5,11) #11 = A+1
    slt(i,11,10)
    add(10,i+100,i+100)
    for j in range(i-200):
        add(10,10,10)
        #print (lis[10])

    for j in range(i-1,199,-1):
        add(10,j,j)

#print (lis[300:331])

#Bを分解する

make_binary(400)
for i in range(430,399,-1):
    add(1,4,11) #11にコピー
    add(11,5,11) #11 = B+1
    slt(i,11,10)
    add(10,i+100,i+100)
    for j in range(i-400):
        add(10,10,10)

    for j in range(i-1,399,-1):
        add(10,j,j)

#掛け算をする 300~330 A / 500~530 B

for ii in range(300,331):
    i = ii-300
    for jj in range(500,531):
        j = jj - 500

        mul(ii,jj,600)
        #print (lis[ii],lis[jj],lis[600])
        for k in range(i+j):
            add(600,600,600)
        add(600,2,2)

print (len(ans))
for i in ans:
    print (*i)

Measured memory_bytes: 83440
import java.util.*;

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

        int N = sc.nextInt();
        int X = sc.nextInt();
        int[] ms = new int[N];

        for (int i = 0; i < N; i++) {
            ms[i] = sc.nextInt();
        }
        Arrays.sort(ms);
        int sum = 0;
        for (int m : ms) {
            sum += m;
        }
        int num = (X - sum + ms[0]) / ms[0];
        System.out.println(num + N - 1);
    }
}


Measured memory_bytes: 25172
import numpy as np
n,m = map(int,input().split())

p = []
s = []
ans_a = np.zeros(n)
ans_p = np.zeros(n)

for i in range(m):
    pi ,si = map(str,input().split())
    p.append(int(pi))
    s.append(si)

for i in range(m):
    if s[i] == "AC":
        ans_a[p[i]-1] = 1
    elif ans_a[p[i]-1] == 0:
        ans_p[p[i]-1] += 1

for i in range(n):
    if ans_a[i] == 0:
        ans_p[i] = 0

print(int(np.sum(ans_a)),int(np.sum(ans_p)))


Measured memory_bytes: 23736
n,k = map(int,input().split())
L = list(map(int,input().split()))
LL = []
for i in range(n):
    kitai = L[i]*(L[i]+1)//2/L[i]
    LL.append(kitai)
#print(LL)
k_sum = sum(LL[:k])
num = []
num.append(k_sum)
for i in range(1,n-k+1):
    k_sum += (LL[k+i-1] - LL[i-1])
    #print(LL[k+i-1],LL[i-1])
    num.append(k_sum)
print(max(num))

Measured memory_bytes: 25604
#
 
#include<stdio.h>
 
int main(void) {
    int a, b;
    scanf("%d %d", &a, &b);
 
    int area = a*b;
    int c = a * 2 + b * 2;
     
    printf("%d %d\n", area, c);
 return 0;
}

Measured memory_bytes: 1024
N = int(input())
F = [list(map(int, input().split())) for i in range(N)]
P = [list(map(int, input().split())) for j in range(N)]
m = -float("INF")
for i in range(1, 1024):
    n = 0
    for j in range(N):
        c = 0
        for k in range(10):
            if i >> k & 1:
                if F[j][k] == 1:
                    c += 1
        n += P[j][c]
    m = max(m, n)
print(m)


Measured memory_bytes: 3064
#include<bits/stdc++.h>
using namespace std;
set<char>s1,s2;
char s[110];
int n,ans;
int main(){
	scanf("%d",&n);
	scanf("%s",s+1);
	for(int i=0;i<=n;i++){
		int t=0;
		s1.clear();
		s2.clear();
		for(int j=1;j<=i;j++)
			s1.insert(s[j]);
		for(int j=i+1;j<=n;j++)
			s2.insert(s[j]);
		for(set<char>::iterator it=s1.begin();it!=s1.end();it++)
			if(s2.count(*it))t++;
		ans=max(ans,t);
	}
	printf("%d",ans);
}

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


#define min(X,Y) ((X) < (Y) ?  (X) : (Y))

long long a[210000];


int main() {
    int n;
    scanf("%d",&n);
    for (int i=0;i<n;++i) {
        long long z;
        scanf("%Ld",&z);
        a[i] = (i == 0) ? z : z + a[i-1];
    }
    long long  mm = llabs(a[n-1] - 2 * a[0]);
    for (int i=0;i<n-1;++i) {
        mm = min(mm, llabs(a[n-1] - 2 * a[i]));
    }
    printf("%Ld\n",mm);
    return 0;
}


Measured memory_bytes: 1664
#include<iostream>
#include<iomanip>
#include<cmath>
#include<string>
#include<cstring>
#include<vector>
#include<list>
#include<algorithm>
#include<map>
#include<set>
#include<queue>
#include<stack>
using namespace std;
typedef long long ll;
#define fi first
#define se second
#define mp make_pair
#define mt make_tuple
#define pqueue priority_queue
const int inf=1e9+7;
const ll mod=1e9+7;
const ll mod1=998244353;
const ll big=1e18;
const double PI=2*asin(1);

int main() {
  ll N, K;
  cin>>N>>K;
  vector<ll> A(N), F(N);
  for(int i=0;i<N;++i) cin>>A[i];
  for(int i=0;i<N;++i) cin>>F[i];
  sort(A.begin(), A.end());
  sort(F.begin(), F.end(), greater<ll>());
  ll l=0, r=big, m;
  ll tmp;
  while(l<r) {
    m = (l+r)/2;
    tmp = 0;
    for(int i=0;i<N;++i) {
      if(A[i]*F[i]<=m) continue;
      if((A[i]*F[i]-m)%F[i]==0) tmp += (A[i]*F[i]-m)/F[i];
      else tmp += (A[i]*F[i]-m)/F[i]+1;
    }
    if(tmp>K) l = m+1;
    else r = m;
  }
  cout<<l<<endl;
}



Measured memory_bytes: 6428
S = input()
Q = int(input())
q = []
for i in range(Q):
    a = input().split(" ")
    if len(a) == 1:
        q.append([int(a[0])])
    else:
        q.append([int(a[0]), int(a[1]), a[2]])

#print(S)
#print(q)

def switch(s):
    d = ""
    for i in range(len(s)):
        d += s[len(s) - i - 1]
    return d

H = ""
B = ""

direction = 1 #通常の向き　-1:反対方向

for t in range(len(q)):
    T = q[t]
    if T[0] == 1:
        direction *= -1
    else:
        F = T[1]
        C = T[2]
        if F == 1:
            if direction == 1:
                H += C
            else:
                B += C
        else:
            if direction == 1:
                B += C
            else:
                H += C

if direction == 1:
    print(switch(H) + S + B)
else:
    print(switch(B) + switch(S) + H)

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

#define ll                 long long
#define ull                unsigned long long
#define ld                 long double
#define fastio             ios_base::sync_with_stdio(false);cin.tie(NULL);
#define NO                 cout << "NO" << endl
#define YES                cout << "YES" << endl
#define vec                vector<ll>
#define pi                 pair<ll, ll>
#define intarr(arr, n)     ll arr[n]; for (ll i = 0; i < n; i++) cin >> arr[i]
#define intvec(v, n)       for (ll i = 0; i < n; i++) { ll x;cin >> x; v.pb(x);}
#define loop(i, a, b, c)   for (ll i = a; i < b; i += c)
#define pb                 push_back
#define mkp                make_pair
#define print(a, n, m)     for (ll i = n; i < m; i++) {  cout << a[i] << " "; }  cout << endl
#define endl               "\n"
#define mod2               998244353
#define mod                1000000007
#define mem(dp, a)         memset(dp, a, sizeof(dp));
#define all(v)             v.begin(), v.end()
#define ump                unordered_map<ll, ll>
#define ff                 first
#define ss                 second
#define PI                 3.14159265358979
#define minh               priority_queue<ll>
#define maxh               priority_queue<ll,vector<ll>,greater<ll>>
#define flush              cout<<flush


ll Ceil(ll a, ll b)
{
  if (a % b == 0)
    return a / b;
  else
    return a / b + 1;
}

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

ll inv(ll a)
{
  ll p = mod;
  ll b = p - 2, ans = 1;
  for (; b > 0; a = a * a % p, b >>= 1)
    if (b & 1)
      ans = ans * a % p;
  return ans;
}

ll ncrmod(ll n, ll m)
{
  ll p = mod;
  if (m > n)
    return 0;
  ll up = 1, down = 1;
  for (ll i = n - m + 1; i < n + 1; i++)
    up *= i, up %= p;
  for (ll i = 1; i < m + 1; i++)
    down *= i, down %= p;
  return up * inv(down) % p;
}

ll powmod(ll a, ll n)
{
  if (!n)
    return 1;
  ll pt = powmod(a, n / 2);
  pt *= pt, pt %= mod;
  if (n & 1)
    pt *= a, pt %= mod;
  return pt;
}

// void factorize(long long int n)
// {
//   ll count = 0;

//   while (!(n % 2)) {
//     n >>= 1;
//     count++;
//   }

//   if (count)
//   {
//     sum2 += count;
//   }

//   for (long long i = 3; i <= sqrt(n); i += 2) {
//     count = 0;
//     while (n % i == 0) {
//       count++;
//       n = n / i;
//     }
//     if (count)
//     {
//       if (i & 1)sum += count;
//     }
//   }
//   if (n > 2)
//   {
//     sum++;
//   }
// }

string s = "";
void func(ll n) {
  if (n == 0) return;
  if (n >= 1 and n <= 26) {
    s += n - 1 + 'a';
    return;
  }
  ll div = n / 26;
  if (div != 0 and n % 26 == 0) {
    func(div - 1);
    func(26);
  }
  else {
    func(div);
    func(n % 26);
  }
}
void solve()
{
  ll n;
  cin >> n;
  func(n);
  cout << s;
}
int main()
{
#ifndef ONLINE_JUDGE
  freopen("input.txt", "r", stdin);
  freopen("output.txt", "w", stdout);
#endif

  fastio;
  ll t;
  t = 1;
  //cin >> t;
  while (t--)
  {
    solve();
  }

  cerr << "\nTime elapsed: " << 1000 * clock() / CLOCKS_PER_SEC << "ms\n";

  return 0;
}

Measured memory_bytes: 3640
#include <stdio.h>
#include<stdlib.h>
#include<string.h>

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

int main()
{
	int n;
	int a[100];
	int cnt = 0;
	scanf("%d", &n);
	for(int i=0;i<n;i++)
		scanf("%d", &a[i]);
	for (int i = 1; i < n - 1; i++) {
		if (((a[i] < a[i - 1]) && (a[i] > a[i + 1])) || ((a[i] > a[i - 1]) && (a[i] < a[i + 1])))
			cnt++;
	}
	printf("%d", cnt);
}

Measured memory_bytes: 128
object Main extends App{
  import java.io.{BufferedOutputStream, BufferedReader, InputStreamReader, PrintWriter}
  val in=new BufferedReader(new InputStreamReader(System.in))
  val out = new PrintWriter(new BufferedOutputStream(System.out))
  val n = in.readLine().toInt
  val m = scala.collection.mutable.HashMap[String,Int]()
  for{i <- ( 1 to n )}{
    val s=in.readLine()
    m(s) = if(m.contains(s)) 0 else 0
  }
  out.println(m.toSeq.size)
  out.flush()
}

Measured memory_bytes: 83624
# coding: utf-8
N, Q = map(int, input().split())
S = input()
c = 0
lst = [0] * N
for i in range(N - 1):
    if S[i] == 'A' and S[i + 1] == 'C':
        c += 1
    lst[i + 1] = c
for _ in range(Q):
    a, b = map(int, input().split())
    print(lst[b - 1] - lst[a - 1])

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

int main() {
  int N, K;
  cin >> N >> K;
  int A[N];
  for(int i=0; i<N; i++) cin >> A[i];
  
  vector<int> count(N,0);
  for(int i=0; i<N; i++){
    count[A[i]-1]++;
  }
  
  sort(count.begin(),count.end(),greater<int>());
  
  int ans=0;
  for(int i=K; i<N; i++) ans+=count[i];
  
  cout << ans << endl;
}


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

typedef long long ll;

int main() {
    int N, T, s = 0, t, ans = 0;
    cin >> N >> T;
    rep(i, N) {
        cin >> t;
        ans += min(t - s, T);
        s = t;
    }
    cout << ans + T << endl;
}

Measured memory_bytes: 256
def slove():
    import sys
    input = sys.stdin.readline
    n = int(input().rstrip('\n'))
    mt = 10 ** 10
    for i in range(1, n):
        s = sum(list(map(int, list(str(i)))))
        t = sum(list(map(int, list(str(n - i)))))
        mt = min(mt, s + t)
    print(mt)


if __name__ == '__main__':
    slove()


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

ll gcd(ll a,ll b){ return b?gcd(b,a%b):a; }
ll lcm(ll a,ll b){ return a/gcd(a,b)*b; }

int n,q,l,r;
ll p[100100];
ll sum[100100], len[100100];
bool use[100100];
const ll mod = 1e9+7;
ll par_sum[50][100100];

ll n_, c[1<<20];

void init(int n){
  n_ = 1;
  while(n_<n)n_*=2;

  for(int i=n_-1;i<2*n_-1;i++){
    if(i-n_+2<=n)c[i] = len[i-n_+2];
    else c[i] = 1;
  }

  for(int i=n_-2;i>=0;i--){
    c[i] = lcm(c[2*i+1],c[2*i+2]);
  }
}

ll query(int a,int b,int k,int l,int r){
  if(r<=a || b<=l)return 1;
  if(a<=l && r<=b)return c[k];
  ll vl = query(a,b,k*2+1,l,(l+r)/2);
  ll vr = query(a,b,k*2+2,(l+r)/2,r);
  return lcm(vl,vr);
}

int main(){
  scanf("%d%d",&n,&q);
  for(int i=1;i<=n;i++)scanf("%lld",p+i);

  memset(use,0,sizeof(use));

  for(int i=1;i<=n;i++){
    if(!use[i]){
      ll now = p[i];
      ll tmplen = 1, tmpsum = i;
     
      while(now!=i){
	tmplen++; (tmpsum += now) %= mod;
	now = p[now];
      }

      now = i;
      while(!use[now]){
	use[now] = true;
	len[now] = tmplen;
	sum[now] = tmpsum;
      }
    }
  }

  for(int i=1;i<=40;i++){
    par_sum[i][0] = 0;
    for(int j=1;j<=n;j++){
      if(len[j]==i)par_sum[i][j] = (par_sum[i][j-1] + sum[j]) % mod;
      else par_sum[i][j] = par_sum[i][j-1];
    }
  }

  init(n);

  for(int i=0;i<q;i++){
    scanf("%d%d",&l,&r);
    ll cycle = query(l-1,r,0,0,n_);

    ll res = 0;
    for(int i=1;i<=40;i++){
      res += (((cycle/i)%mod)*(((par_sum[i][r]-par_sum[i][l-1])%mod+mod)%mod))%mod;
      res %= mod;
    }

    cout << res << endl;
  }
}

Measured memory_bytes: 40720
/**
 * Dont raise your voice, improve your argument.
 * --Desmond Tutu
 */

#include <bits/stdc++.h>
using namespace std;

const bool ready = [](){
    ios_base::sync_with_stdio(false); cin.tie(0);
    cout << fixed << setprecision(12);
    return true;
}();

const double PI = acos(-1);
using ll= long long;
#define int ll
#define all(v) (v).begin(), (v).end()
#define fori(n) for(int i=0; i<int(n); i++)

#define cini(i) int i; cin>>i;
#define cins(s) string s; cin>>s;
#define cind(d) double d; cin>>d;
#define cinai(a,n) vi a(n); fori(n) { cin>>a[i]; }
#define cinas(s,n) vs s(n); fori(n) { cin>>s[i]; }
#define cinad(a,n) vd a(n); fori(n) { cin>>a[i]; }

using pii= pair<int, int>;
using pdd= pair<double, double>;
using vd= vector<double>;
using vb= vector<bool>;
using vi= vector<int>;
using vvi= vector<vi>;
using vs= vector<string>;

void solve() {
    cini(n);
    cini(m);
    cini(k);

    cinai(a,n);
    vi preA(n+1);
    for(int i=0; i<n; i++) 
        preA[i+1]=preA[i]+a[i];

    cinai(b,m);
    vi preB(m+1);
    for(int i=0; i<m; i++) 
        preB[i+1]=preB[i]+b[i];

    int ans=0;
    for(int i=0; i<=n && preA[i]<=k; i++) {
        int inc=distance(preB.begin(), upper_bound(all(preB), k-preA[i]));
        ans=max(ans, i+inc-1);
    }
    cout<<ans<<endl;
}

signed main() {
    solve();
}

// FIRST THINK, THEN CODE
// DO NOT JUMP BETWEEN PROBLEMS


Measured memory_bytes: 9532
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
int n;
long long a[200005], ans = 1e18, sm, ps;
int main(){
	scanf("%d", &n);
	rep(i,n){
    	scanf("%lld", a+i);
    	sm += a[i];
    }
	rep(i,n-1){
    	ps += a[i];
		ans = min(ans, abs(sm - ps*2));
    }
	printf("%lld\n", ans);
}

Measured memory_bytes: 1792
import sys
IS = lambda: sys.stdin.readline().rstrip()
II = lambda: int(IS())
MII = lambda: list(map(int, IS().split()))

def main():
    s = IS()
    minv = 10**5
    for i in range(len(s)-2):
        d = int(s[i:i+3])
        minv = min(minv, abs(753-d))
    print(minv)


if __name__ == '__main__':
    main()


Measured memory_bytes: 2940