akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;

int main() {
	int n, k;
	cin >> n >> k;
	int left = 1;
	int right = 1e9;
	vector<int> a(n);
	for (int i = 0; i < n; i++) {
		cin >> a[i];
	}
	int answer = 1e9;
	while (left <= right) {
		int mid = left + (right - left)/2;
		int cur = 0;
		for (int i = 0; i < n && cur <= k; i++) {
			cur += (a[i] - 1)/mid;
		}
		if (cur > k) {
			left = mid + 1;
		} else {
			answer = min(answer, mid);
			right = mid - 1;
		}
	}
	cout << answer << endl;
}


Measured memory_bytes: 3892
#include<stdio.h>

int main(){
	int num,a,b,digits,i;
	i=1;
	while(i<=200){
		digits=1;
		if(scanf("%d%d",&a,&b)==EOF)
			break;
		num=a+b;
		while((num=num/10)!=0)
			digits++;
		printf("%d\n",digits);
		i++;
	}
	return 0;
}

Measured memory_bytes: 600
//----------BHAVIK DIWANI(PICT_COMP)---------------
#include<bits/stdc++.h>
#include<stdlib.h>
#include<stdio.h>
#define test ll t; cin>>t; while(t--)
#define FOR(p,n) for(ll i=p;i<(ll)n;i++)
#define fastio ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define mod 1000000007
#define ll long long
#define int long long
#define ull unsigned long long
#define MAX 1000005
#define pb push_back
#define mkp make_pair
#define vi vector<int>
#define pii pair<int,int>
#define endl '\n'
#define vs vector<string>
#define mii map<int,int>
#define msi map<string,int>
#define vpii vector< pair<int, int > >
#define vpsi vector< pair< string ,int > >
#define forci(p,q) for(int i=p;i<q;i++)
ll gcd(ll a,ll b){ if(b==0) return a;    return gcd(b,a%b);}
ll lcm(ll a,ll b) { return (a/gcd(a,b)*b);}
ull power(ull a, ull b) {a %= mod;  ull res = 1;  while (b > 0) { if (b & 1) res = res * a % mod;  a = a * a % mod;  b >>= 1; }  return res%mod; }
ll modmul(ll x, ll y){return (x*y)%mod;}
ll modadd(ll x, ll y){return (x+y)%mod;}
ll modsub(ll x, ll y){return (x-y+mod)%mod;}
ll fact[1000007]={0};
void facto() {fact[0]=1;fact[1]=1;for(int i=2;i<100007;i++)fact[i]=(fact[i-1]*i)%mod;}
ll ncr(ll n,ll r) {ll res=1; res=fact[n]; res=(res*(power(fact[r],mod-2)))%mod; res=(res*(power(fact[n-r],mod-2)))%mod; return res;}
ll npr(ll n,ll r) {ll res=1; res=fact[n]; res=(res*(power(fact[n-r],mod-2)))%mod; return res;}
inline long long toint(const std::string &s) {std::stringstream ss; ss << s; long long x; ss >> x; return x;}
inline std::string tostring(long long number) {std::stringstream ss; ss << number; return ss.str();}
inline std::string tobin(long long x) {return std::bitset<63>(x).to_string();}
/*bool prime[MAX];
ull sieve(){memset(prime,true,sizeof(prime));for(ull p=2;p*p<MAX;p++){if(prime[p]==true){for(ull i=2*p;i<MAX;i+=p){prime[i]=false;}}}prime[0]=0;prime[1]=0;
}*/
using namespace std;
bool check(string s)
{
	int i=0, j=s.length()-1;
	bool ans=true;
	while(i<j && j>=0 && i<s.length())
	{
		if(s[i]!=s[j])
		{
			ans=false;
			break;
		}
		i++;
		j--;
	}
	return ans;
}
signed main()
{
	fastio;
	string s;
	cin>>s;
	int n=s.length();
	string a=s.substr(0,(n-1)/2);
	string b=s.substr((n+3)/2-1,n-(n+3)/2+1);
	bool x=check(s);
	bool y=check(a);
	bool z=check(b);
	if(x && y && z)
		cout<<"Yes";
	else
		cout<<"No";
}












Measured memory_bytes: 256
#include <cstdio>
#include <cstdlib>
#include <cassert>
#include <algorithm>
#include <functional>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <tuple>
#include <vector>
#define repi(i,a,b) for(ll i=(a);i<(b);++i)
#define rep(i,a) repi(i,0,a)
#define repdi(i,a,b) for(ll i=(a)-1;i>=(b);--i)
#define repd(i,a) repdi(i,a,0)
#define itr(it,a) for( auto it = (a).begin(); it != (a).end(); ++it )
#define all(a) (a).begin(), (a).end()
#define rall(a) (a).rbegin(), (a).rend()
#define endl '\n'
#define debug(x) std::cerr << #x << " = " << (x) << endl;

using ll = long long;
using P = std::pair<ll, ll>;

constexpr ll INF = 1ll<<60;

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

template<class S, class T>
std::ostream& operator<< ( std::ostream& out, const std::pair<S,T>& a )
{ std::cout << '(' << a.first << ", " << a.second << ')'; return out; }

template<class T>
std::ostream &operator<< ( std::ostream& out, const std::vector<T>& a )
{ std::cout << '['; rep( i, a.size() ){ std::cout << a[i]; if( i != a.size()-1 ) std::cout << ", "; } std::cout << ']'; return out; }

ll N, M;
std::vector<std::vector<P>> G;
std::vector<ll> dist;

void dijkstra( ll s, std::vector<std::vector<P>> &G, std::vector<ll> &dist )
{
  std::priority_queue<P, std::vector<P>, std::greater<P>> pque;

  dist.assign( N+10, INF );
  dist[s] = 0;

  pque.emplace( dist[s], s );

  while( !pque.empty() )
  {
    P p = pque.top(); pque.pop();
    ll d = p.first, v = p.second;

    if( dist[v] < d )
      continue;

    for( auto u : G[v] )
    {
      if( chmin( dist[u.first], dist[v]+u.second ) )
        pque.emplace( dist[u.first], u.first );
    }
  }

  return;
}

int main() {
  std::cin >> N >> M;

  G.resize( N );

  rep( i, N-1 )
    G[i+1].emplace_back( i, 0 );

  rep( i, M ) {
    ll L, R, C;
    std::cin >> L >> R >> C;
    --L; --R;

    G[L].emplace_back( R, C );
  }

  dijkstra( 0, G, dist );

  std::cout << (dist[N-1]==INF?-1:dist[N-1]) << endl;

  return 0;
}

Measured memory_bytes: 12864
#include <iostream>
#include <string>
#include <cstring>
#include <cstdio>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <numeric>
#include <cmath>

#define FOR(i, f, n) for(int (i) = (f); (i) < (n); (i)++)
#define RFOR(i, f, n) for(int (i) = (f); (i) >= (n); (i)--)
#define rep(i, n) for(int (i) = 0; (i) < (n); (i)++)
#define rrep(i, n) for(int (i) = (n); (i) >= 0; (i)--)
#define step(i, f, n, a) for(int (i) = (f); (i) < (n); (i)+=a)
#define rstep(i, f, n, a) for(int (i) = (f); (i) >= (n); (i)-=a)
#define p(...) printf(__VA_ARGS__); cout << endl;
#define gets(x) x; cin >> x;
#define puts(x) x; cout << x << endl;
#define list_input(x, n) x[(n)]; for(int (i) = 0; (i) < (n); (i)++) cin >> x[i];
#define lambda(a, b, c) [](const a, const b){ return c ;}
#define key(t, x, compare) [](const t& a, const t& b){ return a x compare b x ;}

using ll = long long;
using namespace std;

using pii = pair<int, int>;

int main(){
  ll x, result;
  gets(x)
  result = (x/11)*2;
  if (x%11 >= 7) {
    result += 2;
  }else if (x%11 >= 1) {
    result += 1;
  }
  puts(result)
}


Measured memory_bytes: 256
def main():
    k, a, b = list(map(int, input().split()))
    if b - a <= 2:
        print(k + 1)
    else:
        c = max(0, (k - (a - 1)) // 2)
        print((b - a) * c + k - 2 * c + 1)


if __name__ == '__main__':
    main()


Measured memory_bytes: 9024
#include <bits/stdc++.h>
#include <iostream>
#include <string>
#include <cstdlib> 
#include <string.h>
#include <vector>
#include <cstdio>
#include <iomanip>
#include <stack>
#include <set>
#include <map>
#include <list>
#include <ctime>
#include <algorithm>
#include <cmath>
#define PI 3.1415926535897932384626433832795l
#define IOS ios :: sync_with_stdio(false); cin.tie(0); cout.tie(0)
#define deci(n) cout<<fixed<<setprecision(n);
#define F first
#define S second
#define mk make_pair
#define pb push_back
#define ALPHA 27
#define ll long long int
#define ld long double
#define mmset(arr, n) memset(arr, n, sizeof arr)
#define debug(x) cerr << '#' << ' ' << x << '\n'
#define len(s) s.length()
#define ForA(i,a,b) for(int i = a; i < b; i++)
#define ForA1(i,a,b) for(int i = b - 1; i >= a; i--)
#define ForB1(i,a,b) for(int i = b; i > a; i--)
#define ForB(i,a,b) for(int i = a; i <= b; i++)
#define INT_SIZE 18 
#define maxn 100010

using namespace std;

const ll INF = (ll)(8e18);
const ll MOD = 1000000007;

int h[maxn], dp[maxn];

int main()
{
    IOS;  
    int n; cin >> n;
    ForB(i,1,n) cin >> h[i];
    dp[0] = MOD;
    dp[2] = abs(h[2] - h[1]);
    ForB(i,3,n){
        dp[i] = min(dp[i - 1] + abs(h[i] - h[i - 1]),
                    dp[i - 2] + abs(h[i] - h[i - 2]));
    }
    cout << dp[n] << '\n';
    #ifdef LOCAL_DEFINE
    cerr << "Time elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " s.\n";
    #endif
    return 0 ;
}


Measured memory_bytes: 1024
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        final int N = sc.nextInt(), M = sc.nextInt();
        if(N % 2 == 1){
            for(int i=1;i<=M;i++){
                System.out.println(i + " " + (N-i));
            }
        }else{
            int half = N/2;
            for(int i=1;i<=M;i++){
                if(i % 2 == 1) {
                    int j = i / 2 + 1;
                    System.out.println(j + " " + (N + 1 - j));
                }else{
                    int j = i / 2;
                    System.out.println((half - j) + " " + (half + j));
                }
            }
        }
    }
}


Measured memory_bytes: 46312
fn main() {
    let m = rv::<usize>()[0];
    let mut n=[0;10];
    for _ in 0..m {
        let dc=rv::<usize>();
        n[dc[0]]+=dc[1];
    }
    let mut t=0;
    let mut c=true;
    while c {
        c = false;
        for i in 1..10 { if n[i]>1 {
            c = true;
            let r = (10+i-1)/i;
            while n[i]>=r {
                let k = n[i]/r;
                let x = (i*r)/10+(i*r)%10;
                n[i]-=k*r;
                t += k*r;
                n[x]+=k;
            }
            if n[i]>1 {
                let k=n[i];
                n[i]=0;
                t += k-1;
                n[i*k]+=1;
            }
        }}
        for i in 1..10 { if n[i]==1 {
            for j in i+1..10 { if n[j]==1 {
                c=true;
                n[i]=0;
                n[j]=0;
                if i+j<10 {
                    n[i+j]+=1;
                    t+=1;
                }
                else {
                    let x = (i+j)/10+(i+j)%10;
                    n[x]+=1;
                    t+=2;
                }
                break;
            }}
        }}
        t += n[0];
        n[0] = 0;
    }
    println!("{}",t);
}
fn rl() -> String {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).unwrap();
    s
}
fn rv<T>() -> Vec<T>
  where T: std::str::FromStr, T::Err: std::fmt::Debug, {
    rl().split_whitespace().map(|x|x.parse::<T>().unwrap()).collect()
}

Measured memory_bytes: 4352
#include<bits/stdc++.h>
#define REP(i,n) for(int i=0;i<n;i++)
#define LOOP(i,x,n) for(int i=x;i<n;i++)
#define ALL(v) (v).begin(),(v).end()
#define PB push_back
#define MP make_pair
#define FR first
#define SC second
#define int long long
using namespace std;
const int MOD=1000000007;
const int INF=1000000009;

signed main(){
  int n;
  while(cin>>n,n){
    string s="";
    REP(i,n){
      string t;
      cin>>t;
      s+=t;
    }
    int ans=0;
    if(s.size()<=2)cout<<0<<endl;
    else{
      REP(i,s.size()-3){
        string t=s.substr(i,2);
        string u=s.substr(i+2,2);
        if((t=="lu"&&u=="ru")||(t=="ru"&&u=="lu"))ans++;
        if((t=="ld"&&u=="rd")||(t=="rd"&&u=="ld"))ans++;
      }
      cout<<ans<<endl;
    }
  }
  return 0;
}



Measured memory_bytes: 3148
#include <stdio.h>

int main(void)
{
	int i,a,b,c;
	int n,x,max;
	
	for(;;){
		int count=0;
		scanf("%d%d",&n,&x);
		if(n==0&&x==0){
			break;
		}
		
		for(a=1;a<=n;a++){
			for(b=a+1;b<=n;b++){
					for(c=b+1;c<=n;c++){
							max=a+b+c;
							if(max==x){
							count=count+1;	
							}
						}
					}
		}
			printf("%d\n",count);
	}
	return 0;
}

Measured memory_bytes: 600
H,W,D = map(int,input().split())

coords = [[0,0] for x in range(H*W)]
for i in range(H):
    row = input().split()
    for j in range(W):
        coords[int(row[j]) - 1] = [i,j]

dp = [[] for x in range(D)]
for i in range(D):
    temp = i
    while temp < H*W:
        if temp == i:
            dp[i].append(0)
        else:
            a = len(dp[i])
            dp[i].append(dp[i][a - 1] + abs(coords[temp][0] - coords[temp - D][0]) + abs(coords[temp][1] - coords[temp - D][1]))
        temp += D

Q = int(input())
for i in range(Q):
    L,R = map(int,input().split())
    L -= 1
    R -= 1
    print(dp[R%D][R//D] - dp[L%D][L//D])


Measured memory_bytes: 23456
n,m,x,y = map(int, input().split())
X = tuple(map(int, input().split()))
Y = tuple(map(int, input().split()))
for Z in range(x+1, y+1):
    ok = True
    for i in X:
        if i >= Z:
            ok = False
    for i in Y:
        if i < Z:
            ok = False
    if ok:
        print("No War")
        exit(0)
print("War")

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
int main(){
    int a, maxi=-1;
    vector <string> v;
    cin>>a;
    string tar;
    map <string, int> m;
    cin.ignore();
    for (int i=0; i<a; i++){
        getline (cin, tar);
        m[tar]++;
    }
    map <string, int> :: iterator it=m.begin();
    while (it!=m.end()){
        if (it->second>maxi){
            v.clear();
            maxi=it->second;
        }
        if (it->second==maxi){
            v.push_back(it->first);
        }
        it++;
    }
    sort (v.begin(), v.end());
    for (int i=0; i<v.size(); i++) cout<<v[i]<<endl;
}

Measured memory_bytes: 26868
#include<iostream>
#include<vector>
#include<algorithm>
#include<cstdio>
#include<string>
#include<stdio.h>
#include<stdlib.h>
#include<float.h>
#include<tuple>

using namespace std;
#define ll long long
#define rep(i,n) for(int i=0;i<n;i++)
const ll mod=1e9+7;



int main(void){
    ll N,minus=0,plus=0,total=0;
    bool allplus=true,allminus=true;
  cin>>N;
    vector<ll> numbers(N);
    
    rep(i,N){
        cin>>numbers.at(i);
        if(numbers.at(i)<=0) allplus=false;
        if(numbers.at(i)>0) allminus=false;
        total+=abs(numbers.at(i));
        
    }
    
    sort(numbers.begin(),numbers.end());
    
    if(allplus) total-=numbers.at(0)*2;
    if(allminus) total+=numbers.at(N-1)*2;
    cout<<total<<endl;
    if(allplus){
        ll now=numbers.at(0);
        for(int i=1;i<N-1;i++){
            cout<<now<<" "<<numbers.at(i)<<endl;
            now=now-numbers.at(i);
        }
        cout<<numbers.at(N-1)<<" "<<now<<endl;
        return 0;
    }
    if(allminus){
        reverse(numbers.begin(),numbers.end());
        ll now=numbers.at(0);
        rep(i,N-1) {
            cout<<now<<" "<<numbers.at(i+1)<<endl;
            now=now-numbers.at(i+1);
            
        }
        return 0;
    }
    ll nowx=numbers.at(0),nowy=numbers.at(N-1);
    for(int i=1;i<N-1;i++){
        if(numbers.at(i)<=0) {
            cout<<nowy<<" "<<numbers.at(i)<<endl;
            nowy-=numbers.at(i);
        }
        else{
            cout<<nowx<<" "<<numbers.at(i)<<endl;
            nowx-=numbers.at(i);
        }
    }
    cout<<nowy<<" "<<nowx<<endl;
    return 0;
}


Measured memory_bytes: 2688
#include<bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;i++)
#define lint long long
using namespace std;
lint q,x,y,f[100]={0,1,1},m=1000000007;
int main(){
	cin>>q;
	rep(i,97)f[i+3]=f[i+1]+f[i+2];
	rep(i,q){
		cin>>x>>y;
		if(x>y)swap(x,y);
		if(y<=2){
			cout<<1<<" ";
			cout<<(y==1?1:x==1?2:4)<<"\n";
			continue;
		}
		rep(j,100){
			if(x<f[j]||y<f[j+1]){
				cout<<j-2<<" ";
				lint a=x==1?2:1;
				rep(k,j-2){
					lint n=f[j-1]+f[j-3-k]*f[k+2],m=f[j]+f[j-2-k]*f[k+2];
					if(n<=x&&m<=y)a+=(y-m)/n+1;
				}
				if(f[j]<=x){
					a++;
					rep(k,j-2)a+=(x-f[j])/(f[j-2-k]*f[k+2]);
				}
				cout<<a%m<<"\n";
				break;
			}
		}
	}
}

Measured memory_bytes: 4312
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define ALL(x) (x).begin(), (x).end()
typedef long long ll;
typedef pair<int, int> pii;
const int INF = 1e9;
const int MOD = 1000000007;
const double PI = acos(-1);
int dx[4] = {0,1,0,-1};
int dy[4] = {1,0,-1,0};

void solve() {
	int h, w;
	cin >> h >> w;
	int n;
	cin >> n;
	vector<int> v(n);
	rep(i,n) cin >> v[i];
	vector<vector<int>> ans(h, vector<int>(w));
	int cur = 0;
	for (int i = 0; i < h; i++) {
		if (i % 2 == 0) {
			for (int j = 0; j < w; j++) {
				if (v[cur] == 0) ++cur;
				int t = v[cur];
				ans[i][j] = cur + 1;
				v[cur]--;
			}
		} else {
			for (int j = w - 1; j >= 0; j--) {
				if (v[cur] == 0) ++cur;
				int t = v[cur];
				ans[i][j] = cur + 1;
				v[cur]--;
			}
		}
	}
	rep(i,h) {
		rep(j,w) {
			cout << ans[i][j] << " ";
		}
		cout << "\n";
	}
}

int main() {
	solve();
	return 0;
}

Measured memory_bytes: 3644
((input: string): void => {
    let hoge: number[] = [Number(input)];
    const hEnd = (): number => { return hoge.slice(-1)[0]; }
    while (new Set(hoge).size == hoge.length) {
        let piyo: boolean = hEnd() % 2 == 0;
        hoge.push(piyo ? hEnd()/2 : (hEnd()*3)+1);
    }
    console.log(hoge.length);
})(require('fs').readFileSync('/dev/stdin', 'utf8'));

Measured memory_bytes: 7828
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ull unsigned long long
#define re register
#define pb push_back
#define fi first
#define se second
#define mp make_pair
#define lb long double
const int N=2e6+10;
const int mod1=998244353;
const int mod2=19260811;
void read(int &a)
{
    a=0;int d=1;char ch;
    while(ch=getchar(),ch>'9'||ch<'0')
        if(ch=='-')
            d=-1;
    a=ch^48;
    while(ch=getchar(),ch>='0'&&ch<='9')
        a=(a<<3)+(a<<1)+(ch^48);
    a*=d;
}
int cnt[11],n,m,k;
char s[11][N];
int solve(int x)
{
    int ans=0;
    for(re int i=1;i<n;i++) if(x&(1<<(i-1))) ans++;
    memset(cnt,0,sizeof(cnt));
    for(re int j=0;j<m;j++)
    {
        int num=0;
        cnt[num]+=s[0][j]-'0';
        for(re int i=1;i<n;i++)
        {
            if(x&(1<<(i-1))) num++;
            cnt[num]+=s[i][j]-'0';
        }
        bool f=0;
        for(re int i=0;i<=num;i++) if(cnt[i]>k) f=1;
        if(f)
        {
            ans++;
            memset(cnt,0,sizeof(cnt));
            num=0;
            cnt[num]+=s[0][j]-'0';
            for(re int i=1;i<n;i++)
            {
                if(x&(1<<(i-1))) num++;
                cnt[num]+=s[i][j]-'0';
            }
            for(re int i=0;i<=num;i++) if(cnt[i]>k) return 1e9;
        }
    }
    return ans;
}
int main()
{
    read(n),read(m),read(k);
    int ans=1e9;
    for(re int i=0;i<n;i++) scanf("%s",s[i]);
    for(re int i=0;i<(1<<(n-1));i++) ans=min(ans,solve(i));
    printf("%d",ans);
    return 0;
}

Measured memory_bytes: 16640
function main(input){
    d=input.split('');
    //console.log(d)
    var a='';
    for (var i=0;i<3;i++){
        var as=parseInt(d[i],10);
        a+=10-d[i];
    }
    console.log(a);


}

main(require('fs').readFileSync('/dev/stdin', 'utf8'));

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

#define SIZE 6

int main(void){
    int answer = 0;
    int H, W, K;
    char V[SIZE][SIZE];

    cin >> H >> W >> K;

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

    for(int maskH = 0; maskH < (1 << H); ++maskH){
        for(int maskW = 0; maskW < (1 << W); ++maskW){
            int black = 0;
            for(int i = 0; i < H; ++i){
                for(int j = 0; j < W; ++j){
                    if((((maskH >> i) & 1) == 0) && (((maskW >> j) & 1) == 0) && V[i][j] == '#'){
                        ++black;
                    }
                }
            }
            if(black == K) ++answer;
        }
    }

    cout << answer << endl;

}

Measured memory_bytes: 3636
N = int(input())
A = list(map(int,input().split()))
r = 0; sum_ = 0; res = 0; ans = 0
for l in range(N+1):
    for i in range(r,N):
        if res ^ A[i] == sum_ + A[i]:
            r += 1
            res += A[i]
            sum_ += A[i]
        else:
            break
    length = r - l
    ans += length
    if length == 0:
        r += 1
    else:
        res -= A[l]
        sum_ -= A[l]

print(ans)

Measured memory_bytes: 23560
#include <iostream>
#include <algorithm>
#include <cmath>
using namespace std;
int main()
{
  int A, B, C, K;
  cin >> A >> B >> C >> K;
  int ans = max(A, max(B, C));
  for (int i = 0; i < K; i++) {
  	ans = ans * 2;
  }
  ans = ans + A + B + C - max(A, max(B, C));
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 3528
import javax.swing.text.StringContent;
import java.util.*;

public class Main {

    /* チェックリスト
     * 結果はintの範囲を超えていませんか？(必要な時以外はlongを使いましょう)
     * TLEしそうな処理はありませんか？
     */
    public static void main(String args[]){
        Scanner sc = new Scanner(System.in);
        int n = Integer.parseInt(sc.nextLine());
        String[] as = sc.nextLine().split(" ");
        String[] bs = sc.nextLine().split(" ");
        String[] cs = sc.nextLine().split(" ");
        List<Integer> al = new ArrayList<Integer>();
        List<Integer> bl = new ArrayList<Integer>();
        List<Integer> cl = new ArrayList<Integer>();
        for(String a : as){
            al.add(Integer.parseInt(a));
        }
        for(String b : bs){
            bl.add(Integer.parseInt(b));
        }
        for(String c : cs){
            cl.add(Integer.parseInt(c));
        }
        long r = 0;
        long prev = -2;
        long goodMood = 0;
        for(int i : al){
            long rep = bl.get(i-1);
            r += rep;
            if(prev + 1 == i){
                r += goodMood;
            }
            prev = i;
            if(i != al.size()){
                goodMood = cl.get(i-1);
            }else{
                goodMood = 0;
            }
        }
        System.out.println(r);
    }
}

Measured memory_bytes: 25172
def prime_flags(n):
    is_prime = [True] * (n + 1)
    is_prime[0:2] = [False, False]
    i = 2
    while i * i <= n:
        if is_prime[i]:
            for j in range(i * i, n+1, i):
                is_prime[j] = False
        i += 1
    return is_prime

n = int(input())
primes = prime_flags(1000000)
for i in range(n, 1000000):
    if primes[i]:
        print(i)
        exit()

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

const int MAX=1e6+5;

int main() {
  int N,L;
  cin>>N>>L;
  vector<string>s(N);
  for(int i=0;i<N;i++){
    cin>>s[i];
  }
  sort(s.begin(),s.end());
  string t;
  for(int i=0;i<N;i++){
    t+=s[i];
  }
  cout<<t<<endl;
  return 0;  
}

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

ll gcd(ll a, ll b){
  if(b == 0){
    return a;
  }
  else{
    return gcd(b,(a%b));
  }
}
ll lcm(ll a,ll b){
  return a/gcd(a,b)*b;
}

int main() {
  int a,b;
  cin>>a>>b;
  if(a*500>=b){
    cout<<"Yes"<<endl;
    return 0;
  }
  cout<<"No"<<endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
	string a,b="CODEFESTIVAL2016";
	cin>>a;
	long long sum=0;
	for(int i=0;i<a.length();i++){
		if(a[i]!=b[i]){
			sum++;
		}
	}
	cout<<sum;
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll   long long int
#define T int t; cin>>t; while(t--)
#define fast ios_base::sync_with_stdio(false); cin.tie(NULL);cout.tie(NULL)
#define PI 3.141592653589793238462643383

long double dist(long double x, long double y){
    long double sx = (x*x);
    long double sy = (y*y);
    return sqrt(sx+sy);
}

int main (){
    fast;
    long double x,y;
    ll ans = 0;
    long double n,d;
    cin>>n>>d;
    for(int i=0;i<n;i++){
        cin>>x>>y;
        if(dist(x,y) <= d) ans++;
    }
    cout<<ans<<endl;
}











Measured memory_bytes: 3848
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define srep(i,s,t) for (int i = s; i < t; ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
using namespace std;
typedef long long int ll;
typedef pair<int,int> P;
#define yn {puts("Yes");}else{puts("No");}
#define MAX_N 200005
#define MAX 3005

struct Rectangle {int height; int pos;};

int getLargestRectangle(int size, int buffer[]){
    stack<Rectangle> S;
    int maxv = 0;
    buffer[size] = 0;

    for(int i = 0; i <= size; i++){
        Rectangle rect;
        rect.height = buffer[i];
        rect.pos = i;
        if(S.empty()){
            S.push(rect);
        }else{
            if(S.top().height < rect.height){
                S.push(rect);
            }else if(S.top().height > rect.height){
                int target = i;
                while(!S.empty() && S.top().height >= rect.height){
                    Rectangle pre = S.top(); S.pop();
                    int area = pre.height * (i - pre.pos);
                    maxv = max(maxv, area);
                    target = pre.pos;
                }
                rect.pos = target;
                S.push(rect);
            }
        }
    }
    return maxv;
}

int H, W;
int buffer[MAX][MAX];
int T[MAX][MAX];

int getLargestRectangle(){
    for(int j = 0; j < W; j++){
        for(int i = 0; i < H; i++){
            if(buffer[i][j]){
                T[i][j] = 0;
            }else{
                T[i][j] = (i > 0) ? T[i-1][j] + 1 : 1;
            }
        }
    }

    int maxv = 0;
    for(int i = 0; i < H; i++){
        maxv = max(maxv, getLargestRectangle(W, T[i]));
    }

    return maxv;
}


int main() {
    cin >> H >> W;
    rep(i,H)rep(j,W)cin >> buffer[i][j];

    int ans = getLargestRectangle();

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



Measured memory_bytes: 29588
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<string>
#include<cmath>
#include<map>
#include<stack>
#include<vector>
#include<queue>
#include<set>
#include<algorithm>
#define INF 0x3f3f3f3f
#define mod 1000000009
#define e  2.718281828459045
#define eps 1.0e18
#define PI acos(-1)
#define lowbit(x) (x&(-x))
#define memset(x,y) memset(x,y,sizeof(x))
#define lson i << 1,l,m
#define rson i << 1 | 1,m + 1,r
#define ll long long
using namespace std;
int main(){
	ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
	//freopen("text1.in","r",stdin);
	//freopen("text1.out","w",stdout);
	int a,b,c,d;
	cin>>a>>b>>c>>d;
	while(a>0 || c>0){
		c-=b;
		a-=d;
		if(c<=0) {
			cout<<"Yes"<<endl;
			break;
		}
		else if(a<=0){
			cout<<"No"<<endl;
			break;
		}
		
	} 
	
	return 0;
}


Measured memory_bytes: 3652
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
using pint = pair<int,int>;
ll mod = 1000000007,mod2 = 998244353;

void chmin(long long &a, long long b) { if (a > b) a = b; }
void chmax(long long &a, long long b) { if (a < b) a = b; }
const long long INF = 1LL<<60;
int gcd(int a,int b){
    if(b == 0) return a;
    else return gcd(b,a%b);
}

//重みある時
using Edge = pair<int,int>;
using Graph = vector<vector<Edge> >;

const int MAX = 1000010;
const int MOD = 1000000007;

long long fac[MAX], finv[MAX], inv[MAX];

// テーブルを作る前処理
void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}

// 二項係数計算
long long COM(int n, int k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

int main() {
    int X,Y;
    cin >> X >> Y;
    if((X+Y) %3 != 0){
        cout << 0 << endl;
        return 0;
    }
    COMinit();
    int n = (X+Y)/3,r = (2*Y-X)/3;
    cout << COM(n,r) << endl;
    return 0;
}

Measured memory_bytes: 23680
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using ull = unsigned long long;
using V = vector<int>;
using VV = vector<V>;
using VVV = vector<VV>;
using VL = vector<ll>;
using VVL = vector<VL>;
using VVVL = vector<VVL>;
template<class T> using VE = vector<T>;
template<class T> using P = pair<T, T>;
#define rep(i,n) for(int i=0;i<(n);i++)
#define rep1(i,n) for(int i=1;i<=(n);i++)
#define REP(i,k,n) for(int i=(k);i<(n);i++)
#define all(a) (a).begin(),(a).end()
#define output(x,y) cout << fixed << setprecision(y) << x << endl;
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; }
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; }
const ll MOD = 1e9 + 7;
// const ll MOD = 998244353;
ll upper = MOD + MOD;
ll under = -upper;
ll UPPER = MOD * MOD;
ll UNDER = -UPPER;
const long double pi = 3.141592653589793;
void add(ll &a, ll b) {
	a += b;
	a %= MOD;
}
int main() {
	int s;
	cin >> s;
	VL dp(s + 1, 0);
	dp[0] = 1;
	rep(i, s) {
		REP(j, 3, s + 1) {
			if (i + j > s) continue;
			add(dp[i + j], dp[i]);
		}
	}
	cout << dp[s] << endl;
	return 0;
}

Measured memory_bytes: 3604
#=
A:
- Julia version: 
- Author: abap
- Date: 2020-01-18
=#
H = parse(readline())
W = parse(readline())
N = parse(readline())
white = H * W
black  = 0
h = 0
w = 0
count = 0
for i in 1:100000
	count += 1
	if W - h > H - w
		w += 1
		black += W - h
	else
		h += 1
		black += H - w
	end
	if black >= N
		println(count)
		break
	end
end

Measured memory_bytes: 171292
#include <vector>
#include <iostream>
#include <cmath>
#include <string>
#include <cstring>
#include <algorithm>
#include <numeric>
using namespace std;

int main(){
  ios::sync_with_stdio(false);
  int n, a, b;
  cin >> n >> a >> b;
  int diff = b - a;

  if(diff % 2 == 0) {
    cout << "Alice";
  } else {
    cout << "Borys";
  }

  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <iomanip>
using namespace std;
#define reps(i,s,n) for(int i = s; i < n; i++)
#define rep(i,n) reps(i,0,n)
#define fi first
#define se second
#define mp make_pair
typedef long long ll;
typedef vector<ll> vec;
typedef vector<vec> mat;

ll N,M,H,W,K,A,B,L;
string S;
string alpha = "abcdefghijklmnopqrstuvwxyz";
string ALPHA = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
const ll MOD = 998244353;

int main(){
    cin>>A>>B;
    A += B;
    A%2 == 0 ? (cout<< A/2 <<endl) : (cout<< "IMPOSSIBLE"<<endl);
}


Measured memory_bytes: 256
#include <stdio.h>
int counter(int x){
    if(x==0) return 0;
    else return counter(x>>1)+(x&1);
}
int main(void){
    // Your code here!
    int n,i,j,k;
    scanf("%d",&n);
    int a[n],x[20][20],y[20][20];
    a[0]=0;
    for(i=0;i<n;i++){
        scanf("%d",&a[i]);
        for(j=0;j<a[i];j++)
            scanf("%d %d",&x[i][j],&y[i][j]);
    }
    int max=0;
    for(i=0;i<(1<<n);i++){
        char flag='T';
        for(j=0;j<n;j++){
            if(!(i&(1<<j))) continue;
            for(k=0;k<a[j];k++){
                if((i>>(x[j][k]-1)&1)^y[j][k]){
                    flag='F';
                    break;
                }
            }
        }
        if(flag=='T'){
            if(max<counter(i))
                max = counter(i);
        }
    } 
    printf("%d\n",max);
}


Measured memory_bytes: 128
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N = 1e4 + 10;
const int A = 1e6 + 10;
const int MOD = 1e9 + 7;
ll qpow(ll x, ll k) {
    ll r = 1;
    while(k) {
        if(k & 1) r = r * x % MOD;
        k >>= 1;
        x = x * x % MOD;
    }
    return r;
}
ll gcd(ll a, ll b) {
    return !b ? a : gcd(b, a%b);
}
ll a[N], mx[A], s[A];
typedef pair<int, int> pa;
vector<pa> v[N];
int main() {
    int n;
    cin >> n;
    for(int i = 0; i < n; i++) {
        cin >> a[i];
        ll x = a[i];
        for(int j = 2; 1LL*j*j <= x; j++) {
            ll c = 0;
            while(x % j == 0) {
                c++;
                x /= j;
            }
            mx[j] = max(mx[j], c);
            s[j] += c;
            v[i].push_back(pa(j, c));
        }
        if(x > 1) {
            mx[x] = max(mx[x], 1LL);
            s[x]++;
            v[i].push_back(pa(x, 1));
        }
    }
    ll g = 1;
    for(int i = 1; i < A; i++) {
        g = g * qpow(i, mx[i]) % MOD;
    }
    ll ans = 0;
    for(int i = 0; i < n; i++) {
        ll s = g;
        for(auto p : v[i]) {
            s = s * qpow(qpow(p.first, p.second), MOD - 2) % MOD;
        }
        ans += s;
        ans %= MOD;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 83840
def main():
    s = input()
    s = s.replace("BC", "D")
    #print(s)
    cnt_a = 0
    ans = 0
    for st in s:
        if st == "A":
            cnt_a += 1
        elif st == "D":
            ans += cnt_a
        else:
            cnt_a = 0
    print(ans)


if __name__ == "__main__":
    main()


Measured memory_bytes: 3500
program sequence_sum
  implicit none
  integer(8) :: n, num, k, tmp, a(0:100000) = 0
  integer :: x, m, b(0:100000) = 0, period, offset, rem, i
  read(*,*) n, x, m
  tmp = m
  if (n <= 2 * m) then
    num = x
    do k = 2, n
      x = mod(int(x, 8) * x, tmp)
      if (x == 0) exit
      num = num + x
    end do
    write(*,'(i0)') num
    stop
  end if
  a(1) = x
  b(x) = 1
  do i = 2, m + 1
    x = mod(int(x, 8) * x, tmp)
    a(i) = a(i - 1) + x
    if (b(x) > 0) then
      offset = b(x) - 1
      period = i - offset - 1
      exit
    end if
    b(x) = i
  end do
  num = (n - offset) / period
  rem = int(n - offset - num * period)
  write(*,'(i0)') (a(offset + period) - a(offset)) * num + a(offset + rem)
end program sequence_sum

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

int main() {
  int N;
  cin >> N;
  vector<int> v(N), c(N);
  for (int i=0; i<N; ++i) {
    cin >> v.at(i);
    c.at(i) = v.at(i);
  }
  
  sort(c.begin(), c.end(), greater<int>());
  for (int i=0; i<N; ++i) {
    if (v[i] != c[0]) {
      cout << c[0] << endl;
    } else {
      if (v[i] != c[1]) {
        cout << c[1] << endl;
      } else {
        cout << c[0] << endl;
      }
    }
  }
}

Measured memory_bytes: 3200
#include<stdio.h>
#include<stdbool.h>
#include<math.h>

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


int main(void){
	int n, m, x;
	int a[13][14];
	int c = 0;
	int ans = 0;
	int t[13];
	int INF = 1000000000;

	scanf("%d %d %d", &n, &m, &x);

	rep(i,n){
		rep(j,m+1){
			scanf("%d", &a[i][j]);
		}
	}

	int min = INF;


	rep(j,pow(2,n)){

		int u[13] = {0};
		int cost = 0;

		rep(i,n){
			t[i] = (j>>i) & 1;
		}
		rep(i,n){
			if(t[i]) 
				cost += a[i][0];
		}

		rep(i,n){
			rep(k,m){
				if(t[i])
				u[k] += a[i][k+1];
			}
		}

		bool ok = true;

		rep(i,m){
			if(u[i] < x){
				ok = false;
			} 
		}

		if(ok && cost < min){
			min = cost;
		}

	}

	if(min == INF)
		ans = -1;
	else
		ans = min;

	printf("%d", ans);

	return 0;
}

Measured memory_bytes: 2596
#include<iostream>
#include<cstdio>
#define MN 200000
#define mod 1000000007
using namespace std;
inline int read()
{
	int x=0,f=1;char ch=getchar();
	while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
	while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();}
	return x*f;
}
int n,m,a[MN+5],num[MN+5];
struct data{int x,num;
	data operator + (const data&b)
	{
		if(x==b.x) return (data){x,num+b.num};
		else return x<b.x?*this:b;	
	}
};
struct Tree{int l,r,val;data x;}T[MN*4+5];
void Build(int x,int l,int r)
{
	if((T[x].l=l)==(T[x].r=r)){T[x].x=(data){0,1};return;}
	int mid=l+r>>1;
	Build(x<<1,l,mid);Build(x<<1|1,mid+1,r);
	T[x].x=T[x<<1].x+T[x<<1|1].x;
}
inline void Mark(int x,int v){T[x].val+=v;T[x].x.x+=v;}
inline void pushdown(int x){Mark(x<<1,T[x].val),Mark(x<<1|1,T[x].val);T[x].val=0;}
void Modify(int x,int l,int r,int v)
{	
	if(T[x].l==l&&T[x].r==r) return Mark(x,v);
	int mid=T[x].l+T[x].r>>1;
	if(T[x].val) pushdown(x);
	if(r<=mid) Modify(x<<1,l,r,v);
	else if(l>mid) Modify(x<<1|1,l,r,v);
	else Modify(x<<1,l,mid,v),Modify(x<<1|1,mid+1,r,v);
	T[x].x=T[x<<1].x+T[x<<1|1].x; 
}
int main()
{
	n=read();m=read();Build(1,1,n);
	for(int i=1;i<=n;++i) ++num[a[i]=read()];
	for(int i=1;i<=n;++i) if(num[i]) Modify(1,max(1,i-num[i]+1),i,1);
	for(int i=1;i<=m;++i)
	{
		int x=read(),v=read();
		--num[a[x]];if(a[x]-num[a[x]]>0) Modify(1,a[x]-num[a[x]],a[x]-num[a[x]],-1);
		if(v-num[v]>0) Modify(1,v-num[v],v-num[v],1);++num[a[x]=v];
		printf("%d\n",T[1].x.x>0?0:T[1].x.num);
	}
	return 0;
}



Measured memory_bytes: 16640
#ifdef LOCAL111
	#define _GLIBCXX_DEBUG
#else
	#pragma GCC optimize ("O3")
	#define NDEBUG
#endif
// #define _USE_MATH_DEFINES
#include <bits/stdc++.h>
const int INF = 1e9;
using namespace std;
template<typename T, typename U> ostream& operator<< (ostream& os, const pair<T,U>& p) { os << '(' << p.first << ' ' << p.second << ')'; return os; }

#define endl '\n'
#define ALL(a)  (a).begin(),(a).end()
#define SZ(a) int((a).size())
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define RFOR(i,a,b) for (int i=(b)-1;i>=(a);i--)
#define REP(i,n)  FOR(i,0,n)
#define RREP(i,n) for (int i=(n)-1;i>=0;i--)
#ifdef LOCAL111
	#define DEBUG(x) cout<<#x<<": "<<(x)<<endl
	template<typename T> void dpite(T a, T b){ for(T ite = a; ite != b; ite++) cout << (ite == a ? "" : " ") << *ite; cout << endl;}
#else
	#define DEBUG(x) true
	template<typename T> void dpite(T a, T b){ return; }
#endif
#define F first
#define S second
#define SNP string::npos
#define WRC(hoge) cout << "Case #" << (hoge)+1 << ": "
template<typename T> void pite(T a, T b){ for(T ite = a; ite != b; ite++) cout << (ite == a ? "" : " ") << *ite; cout << endl;}
template<typename T> bool chmax(T& a, T b){if(a < b){a = b; return true;} return false;}
template<typename T> 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 U,typename... V>
typename enable_if<is_same<T, U>::value!=0>::type
fill_v(U &u,const V... v){u=U(v...);}

template<typename T,typename U,typename... V>
typename enable_if<is_same<T, U>::value==0>::type
fill_v(U &u,const V... v){
  for(auto &e:u) fill_v<T>(e,v...);
}

const array<int, 4> dx = {0, 1, 0, -1};
const array<int, 4> dy = {1, 0, -1, 0};


typedef long long int LL;
typedef unsigned long long ULL;
typedef pair<int,int> P;

void ios_init(){
	//cout.setf(ios::fixed);
	//cout.precision(12);
#ifdef LOCAL111
	return;
#endif
	ios::sync_with_stdio(false); cin.tie(0);
}

using Integer = long long;
const Integer mod = 1e9+7;

template <typename T>
long long gcd(T x, T y){
	return y==0 ? x : gcd(y, x%y);
}

template<typename T>
unordered_map<T,int> primeFactorizem(T x){
	unordered_map<T,int> res;
	for(T i = 2; i*i <= x; i++){
		while(x%i == 0){
			res[i]++;
			x /= i;
		}
	}
	if(x != 1) res[x]++;
	return res;
}

int main()
{
	ios_init();
	LL a, b;
	while(cin >> a >> b) {
		LL g = gcd(a, b);		
		auto pf = primeFactorizem(g);
		cout << SZ(pf) + 1 << endl;
	}
	return 0;
}


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

#define ll long long

using namespace std;

bool peli(string s)
{
    ll n = s.length();
    ll q=1;
for(ll i=0;i<=n/2;i++)
   {
       if(s[i] != s[n-1-i])
       {
           q=0;
           break;
       }
   }
   
   return q;
}

int main(){
   string s;
   cin>>s;
   ll n = s.length();
   
  string sleft = s.substr(0, (n-1)/2);
  string sright = s.substr(((n+3)/2)-1, n);
 // cout<<sleft<< " "<<sright<<" "<<peli(s)<<endl;
  if(peli(s) && peli(sleft) && peli(sright)) 
  
  {cout<<"Yes";}
  
  else{
      cout<<"No";
  }
   
   
   
    
    
}

Measured memory_bytes: 256
fn read<T: std::str::FromStr>() -> T {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().parse().ok().unwrap()
}
fn read_vec<T: std::str::FromStr>() -> Vec<T> {
    read::<String>().split_whitespace().map(|e| e.parse().ok().unwrap()).collect()
}

fn solve(n:i32, k:i32) -> i32 {
    // !!(n % k)
    if n % k == 0 { 0 } else { 1 }
}
fn main() {
    let nk = read_vec::<i32>();
    println!("{}", solve(nk[0], nk[1]));
}


Measured memory_bytes: 4352
#include <bits/stdc++.h>
#define M 1000000007
#define INF 999999999
#define EPS 1e-9
#define pb push_back
#define mp make_pair
#define SET(a) memset(a,-1,sizeof(a))
#define CLR(a) memset(a,0,sizeof(a))
#define MAX 1000005
#define fs first
#define sc second 
using namespace std;
typedef long long int ll;
typedef pair<ll,ll> ii;
typedef vector <ii> vii;
typedef vector <ll> vi;


int main()
{
 //freopen("input.txt","r",stdin);
//freopen("output.txt","w",stdout);
ios::sync_with_stdio(false);
 cin.tie(0);
 char str[500];
 cin>>str;
 cout<<str[0]<<strlen(str)-2<<str[strlen(str)-1];


return 0;

}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
  long long n,h[100005],cnt=0,kari=0;
  cin>>n;
  for(long long i=0;i<n;i++){
    cin>>h[i];
  }
  for(long long i=0;i<n-1;i++){
    if(h[i]>=h[i+1]){
      kari++;
      continue;
    }
    if(kari>cnt){
      cnt=kari;
    }
    kari=0;
  }
  if(kari>cnt){
    cnt=kari;
  }
  cout<<cnt<<"\n";
  return 0;
}


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

int main(){
  int n,m,x,y;
  cin >> n >> m >> x >> y;
  vector<int> xx(n);
  vector<int> yy(m);
  for(int i=0;i<n;++i) cin >> xx[i];
  for(int i=0;i<m;++i) cin >> yy[i];
  xx.push_back(x);
  yy.push_back(y);
  string ans = "No War";
  if(*max_element(xx.begin(),xx.end())>=*min_element(yy.begin(),yy.end())) ans = "War";

  cout << ans << endl;

  return 0;
}

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

int dist(int a, int b){
    int d;
    if(a>=b){
        d=a-b;
    }else{
        d=b-a;
    }
    return d;
}

int main(){
    int N,ini;

    scanf("%d",&N);
    int* A = new int[N+2];
    int* C = new int[N];

    A[0]=0;   
    for(int i=1;i<=N;i++){
        scanf("%d",&A[i]);
    }
    A[N+1]=0;

    ini=0;
    for(int i=0;i<=N;i++){
        ini=ini+dist(A[i],A[i+1]);
    }

    for(int i=1;i<=N;i++){
        C[i-1]=ini-dist(A[i-1],A[i])-dist(A[i],A[i+1])+dist(A[i-1],A[i+1]);
    }


    for(int i=0;i<=N-1;i++){
       printf("%d\n", C[i]);
    }


    return 0;
}

Measured memory_bytes: 2048
#include <bits/stdc++.h>
using namespace std;
void err() {
  cout << -1 << '\n';
  exit(0);
}
void dfs (int crr, int dpt, vector<vector<int>>& grh, long long& cnt) {
  cnt += dpt;
  for (int nxt : grh[crr]) {
    dfs(nxt, dpt + 1, grh, cnt);
  }
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n;
  cin >> n;
  vector<long long> d(n);
  map<long long, int> mp;
  for (int i = 0; i < n; i++) {
    cin >> d[i];
    mp[d[i]] = i;
  }
  sort(d.begin(), d.end());
  vector<long long> sz(n, 1);
  vector<int> prt(n);
  vector<vector<int>> grh(n);
  vector<pair<int, int>> edg;
  for (auto it = prev(d.end()); it != d.begin(); it--) {
    auto i = mp[*it];
    long long prtv = *it - n + 2LL * sz[i];
    auto jt = lower_bound(d.begin(), d.end(), prtv);
    if (jt == d.end() || *jt != prtv) err();
    auto p = mp[*jt];
    prt[i] = p;
    grh[p].push_back(i);
    if (i == prt[i]) err();
    sz[prt[i]] += sz[i];
    edg.emplace_back(min(i, prt[i]), max(i, prt[i]));
  }
  long long cnt = 0;
  int rt = mp[d[0]];
  dfs(rt, 0, grh, cnt);
  if (d[0] != cnt) err();
  sort(edg.begin(), edg.end());
  for (auto const & e : edg) {
    cout << e.first + 1 << ' ' << e.second + 1 << '\n';
  }
  return 0;
}


Measured memory_bytes: 18164
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
 
int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    int n,i;
    cin>>n;
    int a[n+1];
    for(i=1;i<=n;++i)
        cin>>a[i];
    int ans[n+1];
    ans[0] = 0;
    a[0] = INT_MAX;
    ans[1] = 0;
    for(i=2;i<=n;++i)
        ans[i] = min(ans[i-1]+abs(a[i-1]-a[i]),ans[i-2]+abs(a[i-2]-a[i]));
    cout<<ans[n];
}

Measured memory_bytes: 1024
import sys
sys.setrecursionlimit(10000000)


def main():
    N, x = map(int, input().split())
    A = [int(c) for c in input().split()]

    num = 0
    if A[0] > x:
        num += A[0] - x
        A[0] = x
    for i in range(1, N):
        if A[i - 1] + A[i] > x:
            num += A[i] + A[i - 1] - x
            A[i] = x - A[i - 1]
    print(num)
            


if __name__ == '__main__':
    main()


Measured memory_bytes: 63984
#include <bits/stdc++.h>
#define ll long long
#define mp make_pair
#define pb push_back
#define fi first
#define se second
#define ss(x) (int) x.size()
#define cat(x) cout << #x << " = " << x << endl
 
using namespace std;

int m;
ll d, c;
vector <ll> dig;
ll ans = 0;

int main() {
	scanf("%d", &m);
	for(int i = 1; i <= m; ++i) {
		scanf("%lld %lld", &d, &c);
		if(c & 1) {
			c -= 1;
			dig.pb(d);
		}
		while(c > 0) {
			ll dd = d + d;
			ans += c / 2;
			if(dd > 9)
				ans += c / 2;
			dd = dd % 10 + dd / 10;
			if(c & 1) {
				c -= 1;
				dig.pb(d);
			}
			d = dd;
			c /= 2;
		}
	}
	while(ss(dig) > 1) {
		int x = dig.back();
		dig.pop_back();
		int y = dig.back();
		dig.pop_back();
		int z = x + y;
		ans += 1;
		if(z > 9) {
			ans += 1;
		}
		z = z % 10 + z / 10;
		dig.pb(z);
	}
	
	printf("%lld", ans);
		
			
			
	
	
	return 0;
}


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

int main() {
  int64_t H, W;
  cin >> H >> W;

  if (H == 1 || W == 1) {
    cout << 1 << endl;
    return 0;
  }

  cout << ((H + 1) / 2) * ((W + 1) / 2) + (H / 2) * (W / 2) << endl;

  return 0;
}


Measured memory_bytes: 256
#include <stdio.h>

int main(void)
{
	int a,b[10001],c,i,x=0,j;
	scanf("%d",&a);
	for(i=0;i<a;i++){
		scanf("%d",&b[i]);
		for(j=0;j<10000;j++){
			if(b[i]%2==0){
				x++;
				b[i]=b[i]/2;
			}
			if(b[i]%2==1)break;
		}
	}
	printf("%d",x);
	return 0;
}

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

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

  int load[N];
  int a, b;
  
  for(int i=0; i<N; i++){
    load[i] = 0;
  }

  for(int i=0; i<M; i++){
    cin >> a >> b;
    load[a-1] += 1;
    load[b-1] += 1;
  }
  for(int j=0; j<N; j++){
    cout << load[j] << endl;
  }
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int i,j,k,ans,cnt,n,t,a[56];
int main(){
	char str[12];
	scanf("%s",&str);
	int n=strlen(str);
	ll ret=0;
	for (int S=0;S<1<<(n-1);S++){
		ll now=0,sum=0;
		for (int i=0;i<n;i++){
			now*=10LL;
			now+=str[i]-'0';
			if (i<n-1 && (S>>i&1)){
				sum+=now;
				now=0;
			}
		}
		sum+=now;
		ret+=sum;
	}
	cout<<ret;
	return 0;
}

Measured memory_bytes: 256
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, tan, asin, acos, atan, radians, degrees#, log2
from itertools import accumulate, permutations, combinations, combinations_with_replacement, product, groupby
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left, insort, insort_left
from fractions import gcd
from heapq import heappush, heappop
from functools import reduce
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def ZIP(n): return zip(*(MAP() for _ in range(n)))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10**9 + 7
#from decimal import *

S = input()
print(S.count("1"))

Measured memory_bytes: 10452
import java.util.Scanner;
import java.util.Stack;

class Main {

    public static void main(String[] args) {
        new Main().compute();
    }

    void compute() {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        int ans = 1;
        for (int i = 0; i < N; i++) {
            if (sc.nextInt() % 2 == 0) {
                ans *= 2;
            }
        }
        System.out.println((int) Math.pow(3, N) - ans);
    }
}


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

int main() {
  int n;
  cin >> n;
  vector<int> d(n);
  for (int i = 0; i < n; i++) cin >> d.at(i);
  sort(d.begin(), d.end());
  int cnt = n;
  for (int i = 1; i < n; i++)
    if (d.at(i) == d.at(i - 1)) cnt--;
  cout << cnt << endl;
}


Measured memory_bytes: 256