akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define REP(i, j, n) for (int i = j; i < (int)(n); i++)
#define brep(i, n) for (int i = n; i > 0; i--)
#define BREP(i, j, n) for(int i = n; i > j; i--)
#define TEST cout << "PASS" << endl
#define all(x) (x).begin(),(x).end()
typedef long long ll;
typedef pair<int, int> P;
const int INF = 1e9 + 1e6 + 1e3 + 1;
const ll INFL = 1001001001001;
const ll MOD = 1e9 + 7;
const double PI = 3.141592653589793;

int main(){
    int a, b, q;
    cin >> a >> b >> q;
    ll s[100002], t[100002];
    fill(s, s + 100002, INFL);
    fill(t, t + 100002, 2*INFL);
    rep(i, a) cin >> s[i+1];
    rep(i, b) cin >> t[i+1];
    sort(s+1, s + a+1);
    sort(t+1, t + a+1);
    s[0] = -INFL;
    t[0] = -2 * INFL;

    rep(i, q){
        ll x;
        cin >> x;
        auto itrs = lower_bound(s, s + a+2, x);
        auto itrt = lower_bound(t, t + b+2, x);
        
        ll temple_a = *prev(itrt, 1);
        ll temple_b = *itrt;
        ll shrine_a = *prev(itrs, 1);
        ll shrine_b = *itrs;
        ll ans = min(max(shrine_b-x, temple_b-x), max(x-shrine_a, x - temple_a));
        
        if(shrine_a < temple_a && shrine_b < temple_b){
            ans = min(ans, min(2*shrine_b - x - temple_a, shrine_b + x - 2 * temple_a));
        }else if(temple_a < shrine_a && temple_b < shrine_b){
            ans = min(ans, min(2*temple_b - x - shrine_a, x + temple_b - 2 * shrine_a));
        }
        cout << ans << endl;
        
    }
}

Measured memory_bytes: 5172
/* cerberus97 - Hanit Banga */

#include <iostream>
#include <iomanip>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <vector>
#include <algorithm>

using namespace std;

#define pb push_back
#define fast_cin() ios_base::sync_with_stdio(false); cin.tie(NULL)

typedef long long ll;
typedef long double ld;
typedef pair <int, int> pii;
typedef pair <ll, ll> pll;

const int N = 1e5 + 10;

vector<int> code(int n);

int main() {
	fast_cin();
	int n, a, b;
	cin >> n >> a >> b;
	int ctr = 0;
	for (int i = 0; i < n; ++i) {
		ctr += (a & (1 << i)) != (b & (1 << i));
	}
	if (ctr % 2 == 0) {
		cout << "NO\n";
		return 0;
	}
	cout << "YES\n";
	vector<int> start = {0, 1};
	for (int i = 1; i < n; ++i) {
		vector<int> temp = code(i);
		for (auto &j : temp) {
			j |= (1 << i);
			j ^= start.back();
		}
		int ones = __builtin_popcount(temp.back());
		if (ones < ctr) {
			for (int k = 0; k < i - 1; ++k) {
				if (!(start.back() & (1 << k))) {
					for (auto &p : temp) {
						p ^= start.back();
						if (((p >> (i - 1)) & 1) != ((p >> k) & 1)) {
							p ^= (1 << (i - 1));
							p ^= (1 << k);
						}
						p ^= start.back();
					}
					break;
				}
			}
		}
		for (auto &j : temp) {
			start.pb(j);
		}
	}
	for (int i = 0; i < n; ++i) {
		bool b1 = (start[0] & (1 << i)) == (start.back() & (1 << i));
		bool b2 = (a & (1 << i)) == (b & (1 << i));
		if (b1 != b2) {
			for (int j = i + 1; j < n; ++j) {
				bool temp = (start[0] & (1 << j)) == (start.back() & (1 << j));
				if (temp != b1) {
					for (auto &p : start) {
						if (((p >> (i)) & 1) != ((p >> j) & 1)) {
							p ^= (1 << (i));
							p ^= (1 << j);
						}
					}
					break;
				}
			}
		}
	}
	for (auto &i : start) {
		cout << (i ^ a) << ' ';
	}
	cout << endl;
}

vector<int> code(int n) {
	if (n == 1) {
		return {0, 1};
	}
	vector<int> l = code(n - 1);
	vector<int> r = l;
	reverse(r.begin(), r.end());
	for (auto &i : r) {
		l.pb(i + (1 << (n - 1)));
	}
	return l;
}

Measured memory_bytes: 1648
#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;
#define int long
signed main(){
  int n,m,r=0;
  vector<int> v;
  cin>>n;
  for(int i=1;i*i<=n;++i){
    if(n%i==0){
      v.push_back(i);
      if(i!=n/i)v.push_back(n/i);
    }
  }
  sort(v.begin(),v.end());
  for(auto q:v){
    m=n/q-1;
    if(q>=m)break;
    r+=m;
  }
  cout<<r;
  return 0;
}


Measured memory_bytes: 384
#include<bits/stdc++.h>
#define N 110
using namespace std;
int a[N][N],b[N][N],c[N][N];
int e[N][N];
int rm[N],M;
bool vis[N];
vector<int> g[N][N];
bool DFS(int i,int n){
	vis[i]=true;
	for(int j=0;j<n;j++){
		if(e[i][j] && (rm[j]<0|| !vis[rm[j]] && DFS(rm[j],n))){
			rm[j]=i;
			return true;
		}
	}
	return false;
}
void find_match(int n){
	memset(rm,-1,sizeof(rm));
	for(int i=0;i<n;i++){
		memset(vis,0,sizeof(vis));
		assert(DFS(i,n));
	}
	for(int i=0;i<n;i++){
		e[rm[i]][i]--;
	}
}
int main(){
	int n,m;
	scanf("%d%d",&n,&m);
	for(int i=0;i<n;i++){
		for(int j=0;j<m;j++){
			scanf("%d",&a[i][j]);
			a[i][j]--;
			e[a[i][j]/m][i]++;
			g[i][a[i][j]/m].push_back(a[i][j]);
		}
	}
	for(int j=0;j<m;j++){
		find_match(n);
		for(int i=0;i<n;i++){
			c[j][i]=b[i][j]=g[i][rm[i]].back();
			g[i][rm[i]].pop_back();
		}
	}
	for(int j=0;j<m;j++) sort(c[j],c[j]+n);
	for(int i=0;i<n;i++){
		for(int j=0;j<m;j++){
			printf("%d%c",b[i][j]+1,j==m-1?'\n':' '); 
		}
	}
	for(int i=0;i<n;i++){
		for(int j=0;j<m;j++){
			printf("%d%c",c[j][i]+1,j==m-1?'\n':' '); 
		}
	}
	return 0;
}


Measured memory_bytes: 1152
#include<bits/stdc++.h>
#define ll long long int 
#define pb push_back
#define mp make_pair
#define ff first
#define se second
using namespace std;
int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	ll n;
	cin>>n;
	if(n==22){
	    cout<<"Christmas Eve Eve Eve";
	}
	if(n==23){
	    cout<<"Christmas Eve Eve";
	}
	if(n==24){
	    cout<<"Christmas Eve";
	}
	if(n==25){
	    cout<<"Christmas";
	}
}

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

#define DUMP(x) cerr << #x << "=" << x << endl
#define DUMP2(x, y) cerr<<"("<<#x<<", "<<#y<<") = ("<<x<<", "<<y<<")"<< endl
#define BINARY(x) static_cast<bitset<16> >(x)

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

#define in_range(x, y, w, h) (0<=(int)(x) && (int)(x)<(int)(w) && 0<=(int)(y) && (int)(y)<(int)(h))
#define ALL(a) (a).begin(),(a).end()

typedef long long ll;
const int INF   = 1e9;
const ll  INFLL = 1e18;
typedef pair<int, int> PII;
int dx[4]={0, -1, 1, 0}, dy[4]={-1, 0, 0, 1};

const int MAX = 10000;
bool dp[MAX];

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

    int N; cin >> N;
    vector<int> S(N);
    rep(i, N) cin >> S[i];

    dp[0] = true;

    rep(i, N) {
        for (int j=MAX; j>=0; j--) {
            if (dp[j]) {
                dp[j+S[i]] = true;
            }
        }
    }

    int ans = 0;
    rep(i, MAX) {
        if (dp[i] && i%10 != 0) ans = max(ans, i);
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main ()
{
    int a, b, c, x, i, j, k, cnt=0;
    cin>>a>>b>>c>>x;
    for (i=0; i <= a && 500*i<=x; i++)
    {
        for (j=0; j <= b && 100*j+500*i<=x; j++)
        {
            for (k=0; k <= c && 50*k+100*j+500*i<=x; k++)
            {
                if (500*i+100*j+50*k==x)
                {
                    cnt++;
                }
            }
        }
    }

    cout<<cnt;
    return 0;
}

Measured memory_bytes: 256
//libraries
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/detail/standard_policies.hpp>

//namespace
using namespace std;
using namespace __gnu_pbds;

//typedef
typedef tree<long long,null_type,less<long long>,rb_tree_tag,tree_order_statistics_node_update> ordered_set;
typedef tree<long long,null_type,greater<long long>,rb_tree_tag,tree_order_statistics_node_update> ordered_set1;
typedef long long ll;
typedef long double ld;
typedef pair<int,int> pii;
typedef pair<long,long> pll;

//define
#define inp(X) cin>>X;
#define inp_long(X) long long X; cin>>X;
#define inp_arr(A,N) long long A[N]; for(long long int i=0;i<N;i++) {cin>>A[i];}
#define sz(A) A.size()
#define pb push_back
#define pf push_front
#define fi first
#define se second
//#define endl '\n'
#define vect(A) vector<long long> A;
#define inp_vect(A,N); vect(A);for(long long i=0;i<N;i++){long long q; cin>>q; A.push_back(q);}
#define forin(i,a,b) for(long long i=a;i<=b;i++)
#define forde(i,a,b) for(long long i=a;i>=b;i--)
#define fio ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);

const long long inf=(long long)1e18;
const long long MOD=(long long)(1e9+7);

ll power(ll x,ll y)
{
    if (y == 0)
        return 1;
    ll p = power(x, y/2) % MOD;
    p = (p * p) % MOD;

    return (y%2 == 0)? p : (x * p) % MOD;
}
ll modInverse(ll a)
{
   return power(a,MOD-2);
}
ll gcd(ll a, ll b) 
{ 
    if (a == 0) 
        return b; 
    return gcd(b % a, a); 
} 

//ll z[1000001]={0};

int main()
{
    /*
    #ifndef ONLINE_JUDGE
       freopen ("input.txt" , "r" , stdin);
		// freopen ("OUTPUT.txt" , "w" , stdout);
	#endif
    */
    fio;
    ll n;
    cin>>n;
    if(n%2)
    {
        cout<<"0"<<endl;
    }
    else
    {
        ll pw=0;
        ll t=10;
        ll p=log10(n)/log10(5);
        ll ans=0;
        while(pw<p)
        {
            
            ll x=(t*pow(5,pw));
            ans+=n/x;
            //cout<<x<<" ";
            pw++;
        }
        cout<<ans<<endl;
    }
    
}

Measured memory_bytes: 512
def main():
    n, m, q = map(int, input().split())
    trains = [[0 for _ in range(n + 1)] for _ in range(n + 1)]
    for _ in range(m):
        l, r = map(int, input().split())
        trains[l][r] += 1
    for i in range(n + 1):
        for j in range(1, n + 1):
            trains[i][j] += trains[i][j - 1]
    for _ in range(q):
        p, q = map(int, input().split())
        ans = 0
        for i in range(p, q + 1):
            ans += trains[i][q] - trains[i][p - 1]
        print(ans)


if __name__ == '__main__':
    main()


Measured memory_bytes: 73528
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int A=0, B=0, N=0;
  cin >> N;
  vector<int> card(N);
  for(int i; i < N ; i++){
    cin >> card.at(i);
  }
  sort(card.begin(), card.end());
  reverse(card.begin(), card.end());
  for(int i; i < N ; i++){
    if(2*i>=N){
      break;
    }
    else{
      A+=card.at(2*i);
    }
    if(1+2*i>=N){
      break;
    }
    else{
      B+=card.at(1+2*i);
    }
  }
  cout << A-B << endl;
}

Measured memory_bytes: 256
import java.util.*;
public class Main{
	public static void main(String args[]){
    	Scanner sc=new Scanner(System.in);
      	int size=sc.nextInt();
      	int[]  arr=new int[size];
      	for(int i=0;i<size;i++) arr[i]=sc.nextInt();
      	if(size==1) {System.out.println(0); return;}
      	if(size==2) {System.out.println(arr[size-1]-arr[size-2]);return;}
      	int[] nums=new int[size];
      	nums[0]=0;
     	nums[1]=(int)Math.abs(arr[1]-arr[0]);
      	for(int i=2;i<size;i++){
          
        	nums[i]=(int)Math.min((int)Math.abs(arr[i]-arr[i-1])+nums[i-1],(int)Math.abs(arr[i]-arr[i-2])+nums[i-2]);
        }
      System.out.println(nums[size-1]);
    }
}

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

namespace TBCA
{
    class Program
    {
        static void Main(string[] args)
        {
            var line = Console.ReadLine().Split(' ').ToArray();

            var A = int.Parse(line[0]);
            var B = int.Parse(line[1]);
            var C = int.Parse(line[2]);

            if(C > A && C < B)
            {
                Console.WriteLine("Yes");
            }
            else if(A > C && B < C)
            {
                Console.WriteLine("Yes");
            }
            else 
            {
                Console.WriteLine("No");
            }
        }
    }
}


Measured memory_bytes: 13268
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <vector>
#include <string>
#include <sstream>
#include <algorithm>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <typeinfo>
#include <math.h>
#include <iomanip>
#include <limits>
#include <functional>

using namespace std;
using ll = long long;
const ll res = 1000000007;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)

int main() {
	int n, k, ans=0;
	cin >> n >> k;
	vector<int> d(k), N(n, 0), a(n);

	rep(i, k) {
		cin >> d[i];
		rep(j, d[i]) {
			cin >> a[j];		
		}
		rep(j, d[i]) {
			N[a[j] - 1]++;
		}
	}
	rep(i, n) {
		if (N[i]==0)
			ans++;
	}
	cout << ans << endl;
}

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

int main() {
  int n;
  cin>>n;
  vector<int>p(n);
  for(int i=0;i<n;i++) cin>>p[i];
  int ans=0;
  int posi=0;
  while(posi<n){
    if(p[posi]==posi+1){
      ans++;
      posi+=2;
    }
    else posi++;
  }
  cout<<ans<<endl;
}



Measured memory_bytes: 640
#include<cstdio>
#include<vector>
#include<utility>
using namespace std;
typedef long long ll;
int n,v,u;
ll w,dis[100001];
vector<pair<int,int> > g[100001];

void dfs(int x,int y){
    for(int i=0;i<g[x].size();i++){
        if(g[x][i].first!=y){
            dis[g[x][i].first]=g[x][i].second+dis[x];
            dfs(g[x][i].first,x);
        }
    }
}

int main(){
    scanf("%d",&n);
    for(int i=0;i<n-1;i++){
        scanf("%d %d %lld",&v,&u,&w);
        g[u].push_back(make_pair(v,w));
        g[v].push_back(make_pair(u,w));
    }
    dfs(1,-1);
    for(int i=1;i<=n;i++){
        printf("%lld\n",dis[i]%2);
    }
}

Measured memory_bytes: 9472
#include <bits/stdc++.h>
#include<math.h>
using namespace std;
#define int long long int
#define endl "\n"
#define PI 3.14159265
const int MOD=1e9+7;
//const int mod=1e9+7;
const int INF =LONG_LONG_MAX;
inline int gcd(int a,int b){if(a==0) return b;return gcd(b%a,a);}
inline int pow(int a,int n,int mod){if(n==0)return 1;int p=pow(a,n/2,mod);p=(p%mod*p%mod)%mod;if(n%2) return (p%mod*a%mod)%mod;else return p;}
inline int add(int a, int b){
	a += b;
	if(a >= MOD)a -= MOD;
	return a;
}

inline int sub(int a, int b){
	a -= b;
	if(a < 0)a += MOD;
	return a;
}
int32_t main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);

    int n,k;
    cin>>n>>k;
    int a[n];
    for(int i=0;i<n;i++){cin>>a[i];}
    int dp[n+1][k+1];
    int pre[n+1][k+1];

    for(int i=0;i<=n;i++)
    {
        for(int j=0;j<=k;j++)
        {
            dp[i][j]=0;


            if(j==0){dp[i][j]=1;pre[i][j]=dp[i][j];continue;}
            if(i==0){dp[i][j]=0;pre[i][j]=1;continue;}

            /*  for(int k=0;k<=min(a[i-1],j);k++)
              {
              //    dp[i][j]+=dp[i-1][j-k];
              }*/
              //int d=min(a[i-1],j);
              //dp[i][j]=(pre[i-1][j]%mod-((j-d-1)>=0?pre[i-1][j-d-1]:0)%mod)%mod;
              int first = (j - a[i-1] - 1 >= 0)? pre[i - 1][j - a[i-1] - 1] : 0;
			int last = pre[i - 1][j];
             dp[i][j] = add(dp[i][j], sub(last, first));
              //if(j==0);
               //pre[i][j]=(pre[i][j-1]%mod+dp[i][j]%mod)%mod;
               pre[i][j] = add(pre[i][j - 1], dp[i][j]);
        }
    }
   /* for(int i=0;i<=n;i++)
    {
        for(int j=0;j<=k;j++)
        {
            cout<<dp[i][j]<<" ";
        }
        cout<<endl;
    }
    cout<<endl;
    for(int i=0;i<=n;i++)
    {
        for(int j=0;j<=k;j++)
        {
            cout<<pre[i][j]<<" ";
        }
        cout<<endl;
    }*/
    cout<<dp[n][k]%MOD<<endl;

    return 0;
}


Measured memory_bytes: 158080
n = int(input())
abc = []
for _ in range(n):
    t = [ int(x) for x in input().split() ]
    abc.append(t)

dp = [ [0]*3 for _ in range(n+1) ]

for i in range(n):
    for j in range(3):
        for k in range(3):
            if j == k:
                continue
            dp[i+1][j] = max(dp[i+1][j], dp[i][k] + abc[i][j])

print(max(dp[n]))


Measured memory_bytes: 74072
from fractions import gcd
A,B = map(int,input().split())
g = gcd(A,B)

from collections import Counter
def factorize(n):
    d = Counter()
    m = 2
    while m*m <= n:
        while n%m == 0:
            n //= m
            d[m] += 1
        m += 1
    if n > 1:
        d[n] += 1
    return d

fs = factorize(g)

print(len(fs) + 1)

Measured memory_bytes: 5048
#include<bits/stdc++.h>
using namespace std;
int se(char s){
    int r;
    if(s=='a'||s=='t'||s=='g'||s=='r'||s=='f'||s=='v'||s=='c'||s=='e'||s=='d'||s=='s'||s=='w'||s=='x'||s=='q'||s=='z'||s=='b')r=1;
    else r=0;
    return r;
}
int main(){
    string s;
    int i,r,j,sum;
    while(cin>>s,s!="#"){
    j=se(s[0]);
    sum=0;
    for(int i=1;i<s.size();i++){
        r=se(s[i]);
        if(j!=r){sum++;
        j=r;}
    }
    cout<<sum<<endl;
    }
    return 0;
}
 

Measured memory_bytes: 1184
//code by lynmisakura.wish to be accepted!
#include <iostream>
#include <limits.h>
#include <algorithm>
#include <bitset>
#include <cctype>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <functional>
#include <iomanip>
 
#include <list>
#include <map>
#include <numeric>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>
#include <queue>
#include <unordered_map>
#include <unordered_set>
 
/***************************/
using namespace std;
 
typedef long long ll;
typedef vector<ll> vi;
typedef vector<long long> vl;
typedef pair<ll, ll> pi;
typedef vector<pair<ll, ll> > vpi;
 
//const long long INF = 1LL << 55;
 
#define itn ll
#define pb push_back
#define mp make_pair
#define eb emplace_back
#define ss second
#define ff first
#define dup(x,y) ((x) + (y) - 1)/(y)
#define mins(x,y) x = min(x,y)
#define maxs(x,y) x = max(x,y)
#define all(x) (x).begin(),(x).end()
#define Rep(n) for(ll i = 0;i < n;i++)
#define rep(i,n) for(ll i = 0;i < n;i++)
#define flush fflush(stdout)
#define rrep(i,n) for(ll i = n - 1;i >= 0;i--)
#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() )
#define ioboost cin.tie(0);ios::sync_with_stdio(false);cout<<fixed<<setprecision(20)
ll gcd(ll a, ll b) { return b ? gcd(b, a%b) : a; }
ll qp(ll a, ll b) { ll ans = 1; do { if (b & 1)ans = 1ll * ans*a; a = 1ll * a*a; } while (b >>= 1); return ans; }
ll qp(ll a, ll b, ll mo) { ll ans = 1; do { if (b & 1)ans = 1ll * ans*a%mo; a = 1ll * a*a%mo; } while (b >>= 1); return ans; }
const int MaxN=10000010,mod=998244353;
int fac[MaxN*2],ifac[MaxN*2];
long long inv(int a,int p=mod){return a==1?1:(1+p*(a-inv(p%a,a)))/a%p;}
int C(int n,int m){return m<0||m>n?0:1ll*fac[n]*ifac[m]%mod*ifac[n-m]%mod;}
 
#define _GLIBCXX_DEBUG
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl


int main(void){
    string s;cin >> s;
    if(s.size() == 2){
        if(s[0] == s[1])cout << "1 2" << endl;
        else cout << "-1 -1" << endl;
        return 0;
    }
    for(int i = 0;i < s.size() - 2;i++){
        if(s[i] == s[i+1] or s[i] == s[i+2] or s[i+1] == s[i+2]){
            cout << i+1 << " " << i+3 << endl;
            return 0;
        }
    }
    cout << -1 << " " << -1 << endl;
    return 0;
}



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

typedef struct queue{
  char name[10];
  int t;
} P;

P Q[LEN];
int head,tail,n;

void enqueue(P x){
  Q[tail]=x;
  tail=(tail+1)%LEN;
}

P dequeue(){
  P x =Q[head];
  head=(head+1)%LEN;
  return x;
}

int main()
{
  int elaps=0,c;
  int i,q;
  P u;
  scanf("%d %d",&n,&q);
  for(i=1;i<=n;i++){
    scanf("%s%d",Q[i].name,&Q[i].t);
  }
  head=1; tail=n+1;

  while(head!=tail){
    u=dequeue();
    c=min(q,u.t);
    u.t -=c;
    elaps +=c;
    if(u.t >0) enqueue(u);
    else cout<<u.name<<" "<<elaps<<endl;
  }
  return 0;
}



Measured memory_bytes: 4672
#include<iostream>
#include<cstdio>
#include<string>
#include<math.h>
#include<algorithm>
#include<vector>
#include<iomanip>
#include<map>
#include<numeric>
#include<queue>
#include<functional>
#include<cassert>
#include<set>
#define rep(a,b) for(int a=0;a<b;++a)
#define REP(a,b,c,d) for(int a=b;a<c;a+=d)
#define yes cout<<"Yes"<<endl
#define no cout<<"No"<<endl
#define mod 1000000007
using namespace std;
using ll = long long;
using p_i = pair<int, int>;
int main() {
	string S; cin >> S;
	bool n = false, w = false, s = false, e = false;
	rep(i, S.size()) {
		if (S[i] == 'S')s = true;
		else if (S[i] == 'E')e = true;
		else if (S[i] == 'N')n = true;
		else if (S[i] == 'W')w = true;
	}
	if (s == n && w == e)yes;
	else no;
	cin >> S;
}

Measured memory_bytes: 256
#include <cstdio>
#include <cmath>
#include <iostream>
#include <ctime>
#include <cstdlib>
#include <vector>
#include <cstring>
#include <algorithm>
#include <utility>

using namespace std;

int main () {
    int n;
    cin >> n;
    int mochi[n];
    for(int i=0;i<n;i++){
        cin >> mochi[i];
    }
    int tmp[n];
    int tmp_i=0;
    int cnt = 0;
    for(int i=0;i<n;i++){
        cnt = 0;
        for(int j=0;j<tmp_i;j++){
            if(tmp[j] == mochi[i]){
                cnt++;
            }
        }
        if(cnt>0){
            continue;
        }else{
            tmp[tmp_i]=mochi[i];
            tmp_i++;
        }
    }

    cout << tmp_i << "\n";

}


Measured memory_bytes: 256
#/*
    AUTHOR:shivam51
    IIESTS
*/
  #include<bits/stdc++.h>
  using namespace std;
  //
  #define add accumulate
  #define ll long long int
  #define ff first
  #define ss second
  #define pb push_back
  #define mp make_pair
  #define vll vector<ll>
  #define lb lower_bound
  #define ub upper_bound
  #define pll pair<ll,ll>
  #define vpll vector<pll>
  #define all(v) v.begin(), v.end()
  #define rep(i,k,n) for(int i=k;i<n;i++)
  #define hs ios_base::sync_with_stdio(false);cin.tie(NULL);
  const ll mod=1e9+7;
  const ll MAX=1e5;
  //
  //
  int solve(){
  	string str;
  	cin>>str;
  	str+=' ';
  	ll ans=0;
  	int arr[2];
  	arr[0]=0;
  	arr[1]=0;
  	rep(i,0,str.length()-1){
  		if(str[i]=='A')
  			++arr[0];
  		else if(str[i]=='B'&&str[i+1]=='C'){
  			i+=1;
  			ans+=arr[0];
  		}
  		else{
  			// ans+=(arr[0]*arr[1]);
  			arr[0]=0;
  			// arr[1]=0;
  		}
  	}
  	cout<<ans;
  }
	int main(){ 
		hs;
		ll t;
		// cin>>t;
		t=1;
		while(t--){
			solve();
			cout<<'\n';
		}
    return 0; 
} 

Measured memory_bytes: 720
#include<iostream>
using namespace std;
int main(){
	int n;
	cin >> n;
	string s;
	cin >> s;
	int ans=0;
	int tmp=0;
	for(int i=0;i<n;i++){
		if(s[i]=='I') tmp++;
		else tmp--;
		if(ans<tmp) ans=tmp;
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> pa;
const ll MOD = 1e9 + 7;

#define eb emplace_back
#define all(x) (x).begin(), (x).end()
#define rep(i, n) for (int i = 0; i < (n); i++)
#define repr(i, n) for (int i = (n)-1; i >= 0; i--)
#define repe(i, l, r) for (int i = (l); i < (r); i++)
#define reper(i, l, r) for (int i = (r)-1; i >= (l); i--)

void init() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(15);
}
//-----------------------------------------------------------//

int main() {
    init();
    int X, Y;
    cin >> X >> Y;
    if (X % Y == 0)
        cout << -1 << endl;
    else
        cout << X << endl;

    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define _GLIBCXX_DEBUG
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep2(i, s, n) for (int i = s; i < (int)(n); i++)
#define Clear(a) a = decltype(a)();
typedef long long ll;
typedef pair<int,int> p;
//const ll big=998244353;
const ll big=1000000007;
const int dx[4]={1,0,-1,0};
const int dy[4]={0,1,0,-1};
ll max(ll x,ll y){
if(x>y)return x;
else return y;
}
ll min(ll x,ll y){
if(x<y)return x;
else return y;
}
ll expm(ll x,ll y){
    if(y==0)return 1;//0^0=1
    if(x==1||x==0)return x;
    if(y%2==1)return (expm(x,y-1)*x)%big;
    ll t=expm(x,y/2);
    return (t*t)%big;
}
ll exp(ll x,ll y){
    if(y==0)return 1;//0^0=1
    if(x==1||y==0)return x;
    if(y%2==1)return exp(x,y-1)*x;
    ll t=exp(x,y/2);
    return t*t;
}
ll inv(ll x){
    return expm(x,big-2);
}

ll f(vector<ll> &a){
    vector<ll> sums(61);
    ll len=a.size();
    rep(i,len){
        bitset<61> now(a[i]);
        rep(j,61){
            sums[j]+=now[j];
        }
    }
    
    ll ans=0;
    ll pows=1;
    rep(i,61){
        ans+=(pows*(sums[i]*((len-sums[i])%big)%big)%big)%big;
        ans%=big;
        pows*=2;
        pows%=big;
    }
    return ans;
}

int main(){
    ios::sync_with_stdio(false);
    std::cin.tie(nullptr);
    cout << fixed << setprecision(10);
    /*--------------------------------*/

    int n;cin >> n;
    vector<ll> a(n);
    rep(i,n)cin >> a[i];
    /*a xor b==a+b-2*(a&b)
    a&b+a&c+...
    */
   ll ans=0;
   rep(i,n)ans=(ans+a[i]*(n-1))%big;
   cout << f(a) << endl;
}


Measured memory_bytes: 5532
#include <iostream>
#include <cmath>
#include <iomanip>

const int MAX_N = 6;
const double DEGREE_60 = M_PI / 3.0;

struct Point {
  double x;
  double y;
};

void printPoint(struct Point *p) {
  std::cout.setf(std::ios_base::scientific, std::ios_base::floatfield);
  std::cout << std::fixed << std::setprecision(6) << p->x << " " << p->y << std::endl;
}

void rotatePoint(struct Point *b, struct Point *p) {
  double x = (p->x - b->x) * std::cos(DEGREE_60) - (p->y - b->y) * std::sin(DEGREE_60) + b->x;
  double y = (p->x - b->x) * std::sin(DEGREE_60) + (p->y - b->y) * std::cos(DEGREE_60) + b->y;

  p->x = x;
  p->y = y;
}

double getDividingPoint(double p1, double p2, double k, double l) {
  return (p1 * l + p2 * k) / (k + l);
}

void printKochCurve(struct Point p1, struct Point p2, int c, int n) {
  if (c > n) {
    return;
  }

  const double k = 1.0;
  const double l = 2.0;

  struct Point s = {getDividingPoint(p1.x, p2.x, k, l) , getDividingPoint(p1.y, p2.y, k, l)};
  struct Point t = {getDividingPoint(p1.x, p2.x, l, k) , getDividingPoint(p1.y, p2.y, l, k)};
  
  struct Point u = {t.x , t.y};
  rotatePoint(&s, &u);

  printKochCurve(p1, s, c + 1, n);
  printPoint(&s);

  printKochCurve(s, u, c + 1, n);  
  printPoint(&u);

  printKochCurve(u, t, c + 1, n);  
  printPoint(&t);
  
  printKochCurve(t, p2, c + 1, n);
}

int main(void) {
  int n = 0;

  std::cin >> n;

  struct Point p1 = {0.0, 0.0};
  struct Point p2 = {100.0, 0.0};  

  printPoint(&p1);
  printKochCurve(p1, p2, 1, n);
  printPoint(&p2);

  return 0;
}

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

const int SIZE=2010;
int L[SIZE][SIZE],R[SIZE][SIZE];
int U[SIZE][SIZE],D[SIZE][SIZE];

signed main()
{
    int H,W; cin>>H>>W;
    vector<string> s(H);
    for(int i=0;i<H;i++){
	cin>>s[i];
    }

    for(int i=0;i<H;i++){
	int cnt=0;
	for(int j=0;j<W;j++){
	    if(s[i][j]=='#') cnt=0;
	    else{
		L[i][j]=cnt;
		cnt++;
	    }
	}
    }
    for(int i=0;i<H;i++){
	int cnt=0;
	for(int j=W-1;j>=0;j--){
	    if(s[i][j]=='#') cnt=0;
	    else{
		R[i][j]=cnt;
		cnt++;
	    }
	}
    }
    for(int j=0;j<W;j++){
	int cnt=0;
	for(int i=0;i<H;i++){
	    if(s[i][j]=='#') cnt=0;
	    else{
		U[i][j]=cnt;
		cnt++;
	    }
	}
    }
    for(int j=0;j<W;j++){
	int cnt=0;
	for(int i=H-1;i>=0;i--){
	    if(s[i][j]=='#') cnt=0;
	    else{
		D[i][j]=cnt;
		cnt++;
	    }
	}
    }
    int ans=0;
    for(int i=0;i<H;i++){
	for(int j=0;j<W;j++){
	    if(s[i][j]=='#') continue;
	    ans=max(ans,L[i][j]+R[i][j]+U[i][j]+D[i][j]+1);
	}
    }
    cout<<ans<<endl;
}


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

int main() {
  int n;
  cin >> n;
  int ans = 0;
  int m = 1 << 30;
  for (int i = 0; i < n; i++) {
    int p;
    cin >> p;
    if (m >= p) {
      ans++;
    }
    m = min(m, p);
  }
  cout << ans << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <stdio.h>
#include <math.h>

bool isPrime (int num) {
    if (num < 2) return false;
    else if (num == 2) return true;
    else if (num % 2 == 0) return false;
    
    double sqrt_num = sqrt(num);
    for (int i = 3; i <= sqrt_num; i+= 2) {
        if ( num % i == 0 ) return false;
    }
    
    return true;
}

int main() {
    int n = 0, sum = 0;
    scanf("%d", &n);
    
    for ( int i = 0; i < n; i++ ) {
        int tmp = 0;
        std::cin >> tmp;
        sum +=  isPrime(tmp);
    }
    
    printf("%d\n", sum);
    
    return 0;
}

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

using namespace std;

int main()
{
  string s;
  bool flag=true;
  
  cin>>s;
  
  for(int i=0;i<s.length();i++)
  {
    //kisuu
    if((i+1)%2==1)
    {
		if(s[i]=='L')
        {
          flag=false;
        }
    }
    else
    {
      if(s[i]=='R')
      {
        flag=false;
      }
    }
  }
  
  if(flag==true)
  {
    cout<<"Yes"<<endl;
  }
  else
  {
	cout<<"No"<<endl;
  }
  
  return 0;
}
          

Measured memory_bytes: 256
//		HYSO SERIOUS? WHY SO SERIOUS                            RIOUS? WHY SO SERIOUS? WHYSO SERIO
//		 ERIOUS? WHY SO SERIOUS ? WHY                          WHY SO SERIOUS? WHY SOSERIOUSWHYS
//		       OSERIOUS? WHY SO SERIOU         SERIOUS        ERIOUS? WHY SO SERIOUS? WHYS
//		          WHY SO SERIOUS? WHY SOSERIOUS? WHYSOSERIOUS? WHY SO SERIOUS?WHY SO SE
//		           ERIOUS? WHY SO SERIOUS? WHY SO SERIOUS? WHY SO SERIOUS? WHY SOSERIO
//		           WHY SO SERIOUS? WHY SO SERIOUS? WHY SO SERIOUS? WHY SO SERIOUS? WH
//		            SERIOUS?WHYSO SERIOUS? WHY SO SERIOUS? WHY SO SERIOUS? WHYSO SE
//		              ?WHYSOSERIOUS?WHY SO SERIOUS? WHY SO SERIOUS?WHYSO SERIOUS?
//		                           OSERIOUS? WHY SO SERIOUS?WHYSOSER
//		                                 HYSOSERIOUS?WHYSOSERI
//		                                     SOSERIOUS?W
//		                                         SER
//		                                          W


#include <iostream>
#include <queue>
#include <tuple>
#include <vector>
using namespace std;
#include<bits/stdc++.h>
#include <algorithm>
#define ll long long int
#define read(a) long long int a; cin>>a;
#define readstr(s) string s; cin>>s;
#define readarr(a,l) long long int a[l]={0}; for(ll i=0;i<l;i++) cin>>a[i];
#define loop(i,a,b) for(ll i=a;i<b;i++)
#define rloop(i,a,b) for(ll i=a;i>b;i--)
#define ff first
#define ss second
#define readmtrx(i,j,a,b) ll arr[a][b]={0};for(ll i=0;i<a;i++)for(ll j=0;j<b;j++) cin>>arr[i][j];
#define v(pi) vector<ll>pi
#define vp(pi) vector<pair<ll,ll>>pi
#define fast ios_base::sync_with_stdio(false);cin.tie(0);
#define pb(p) push_back(p)
#define mp make_pair
#include <cmath>
#include <map>
#include <string>
#define mi(lol) map<ll,ll>lol
#define fsort(vec) sort(vec.begin(),vec.end())
#define rsort(vec) sort(vec.begin(),vec.end(),compare)
#define inf ll inf=INT_MAX
//sorting according to the second element vector 

bool compare(pair<ll,ll> p,pair<ll,ll> q){
	return p.second < q.second;	
}

//   example:-
//   sort(vec.begin(),vec.end(),compare);


ll knapsack(ll *wt, ll *val, ll a, ll sum){
	ll dp[a+1][sum+1]={0};
	memset(dp,0, sizeof dp); 
	loop(i,0,a+1){
		dp[i][0]=0;
	}
	loop(j,0,sum+1){
		dp[0][j]=0;
	}
	loop(i,1,a+1){
		loop(j,1,sum+1){
			if(j>=wt[i-1]){
				dp[i][j]=max(val[i-1]+dp[i-1][j-wt[i-1]],dp[i-1][j]);
			}
			else dp[i][j]=dp[i-1][j];
		}
	}
	return dp[a][sum];
}

int main() {
	fast;
	read(a)
	read(b)
	ll val[a]={0};
	ll arr[a]={0};
	loop(i,0,a){
		cin>>arr[i]>>val[i];
	}
	cout<<knapsack(arr,val,a,b)<<endl;
	return 0;
}


Measured memory_bytes: 79232
#include <iostream>
using namespace std;
int main(){
    int a,b,c,d,R,L;
    cin>>a>>b>>c>>d;
    L=a+b;
    R=c+d;
    if(L>R){
        cout<<"Left"<<endl;

    }
    else if(L<R){
        cout<<"Right"<<endl;
    }
    else{
        cout<<"Balanced"<<endl;
    }
}

Measured memory_bytes: 384
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
using ll = long long;

ll MOD = 1000000007;

vector<ll> mfact(1,1);
ll extGCD(ll a, ll b, ll &x, ll &y){
    if(b == 0){
        x = 1;
        y = 0;
        return a;
    }
    ll g = extGCD(b, a%b, y, x);
    y -= a/b * x;
    return g;
}
ll minv(ll a){
    ll x;ll y;
    extGCD(a, MOD, x, y);
    if(x<0){
        x+= ((-x)/MOD+1)*MOD;
        x %= MOD;
    }
    return x;
}

ll mpow(ll a,ll b){
    ll res = 1;
    while(b > 0){
        if(b%2==1)res=(res*a)%MOD;
        b/=2;
        a = (a*a)%MOD;
    }
    return res;
}

ll mfactorial(ll a){
    if(mfact.size()-1 >= a)return mfact[a];
    for(ll i = mfact.size();i<=a;i++){
        mfact.push_back((i * mfact[i-1])%MOD);
    }
    return mfact[a];
}

ll mcomb(ll n, ll r){
    return (((mfactorial(n) * minv(mfactorial(r)))%MOD) * minv(mfactorial(n-r)))%MOD;
}

int main(){
    ll K;cin>>K;
    if(K == 1){
        cout<<1<<endl;
        return 0;
    }
    if(10 % K == 0){
        cout<<"-1"<<endl;
        return 0;
    }

    int a = 7;
    for(ll i = 1;i < 10000000;i++){
        if(a % K == 0){
            cout<<i<<endl;
            return 0;
        }
        a = (a * 10 + 7) % K;
    }
    cout<<"-1"<<endl;
}

Measured memory_bytes: 3636
#include <iostream>
#include <stdio.h>
#include <bits/stdc++.h>
#include <queue>
#include <math.h>
#include <bitset>
#define INF 100000000000
#define N 100001
#define ll long long
using namespace std;

int main(){
    ll n,k;
    cin>>n>>k;
    ll sum=0;
    
    if (k%2==1){
        ll count=0;
        for (ll i=1; i<=n; i++){
            if (i%k==0) count++;
        }
        sum=count*count*count;
    }
    
    else{
        ll count1=0;
        ll count2=0;
        for (ll i=1; i<=n; i++){
            if (i%k==0) count1++;
            if (i%k==k/2) count2++;
        }
        sum+=count1*count1*count1;
        sum+=count2*count2*count2;
    }
    
    cout<<sum<<endl;
}

Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
typedef long long lint;
typedef vector<lint> LIV;
#define rep(i,n) for(int i=0;i<n;++i)
#define MAXN 100010
#define MAXM 1100000
#define all(v) v.begin(),v.end()
#define inf 2147483647
#define linf 1152921504606846976

int main(){
	lint a,b,k,c=0;cin>>a>>b>>k;
	for(int i=min(a,b);i>=0;--i){
		if(a%i==0&&b%i==0)++c;
		if(c==k){
			cout<<i<<endl;
			return 0;
		}
	}
}

//sub-EOF


Measured memory_bytes: 256
import sys
x, n = map(int, input().split())
if n == 0:
    print(x)
    sys.exit()
p = tuple(map(int, input().split()))
for i in range(100):
    if (x-i in p) == False:
        print(x-i)
        break
    if (x+i in p) == False:
        print(x+i)
        break

Measured memory_bytes: 9176
// A - Christmas Eve Eve Eve
// https://atcoder.jp/contests/abc115/tasks/abc115_a

use std::io::*;
use std::str::*;

fn main() {
    let mut in_str = String::new();
    stdin().read_line(&mut in_str).ok();
    let num = u64::from_str(&in_str.trim_right()).expect("error parsing input");

    let out_str = match num {
        25 => "Christmas",
        24 => "Christmas Eve",
        23 => "Christmas Eve Eve",
        22 => "Christmas Eve Eve Eve",
        _  => ""
    };

    println!("{}", out_str);
}


Measured memory_bytes: 4352
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <cctype>
#include <cassert>
#include <climits>
#include <string>
#include <bitset>
#include <cfloat>
#include <random>
#include <iomanip>
#include <unordered_set>
#pragma GCC optimize("Ofast")
using namespace std;
typedef long double ld;
typedef long long int ll;
typedef unsigned long long int ull;
typedef vector<int> vi;
typedef vector<char> vc;
typedef vector<bool> vb;
typedef vector<double> vd;
typedef vector<string> vs;
typedef vector<ll> vll;
typedef vector<pair<int,int> > vpii;
typedef vector<pair<ll,ll> > vpll;
typedef vector<vector<int> > vvi;
typedef vector<vector<char> > vvc;
typedef vector<vector<string> > vvs;
typedef vector<vector<ll> > vvll;
typedef map<int,int> mii;
typedef set<int> si;
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define arep(i,v) for(auto i : v)
#define irep(it, stl) for(auto it = stl.begin(); it != stl.end(); it++)
#define drep(i,n) for(int i = (n) - 1; i >= 0; --i)
#define fin(ans) cout << (ans) << '\n'
#define STLL(s) strtoll(s.c_str(), NULL, 10)
#define mp(p,q) make_pair(p, q)
#define pb(n) push_back(n)
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define Sort(a) sort(a.begin(), a.end())
#define Rort(a) sort(a.rbegin(), a.rend())
#define MATHPI acos(-1)
#define itn int
// #define endl '\n';
#define fi first
#define se second
#define NONVOID [[nodiscard]]
constexpr int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
constexpr int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};
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 T> inline void dump(T &v){irep(i, v){cout<<*i<<((i==--v.end())?'\n':' ');}}
inline string getline(){string s; getline(cin,s); return s;}
inline void yn(const bool b){b?fin("yes"):fin("no");}
inline void Yn(const bool b){b?fin("Yes"):fin("No");}
inline void YN(const bool b){b?fin("YES"):fin("NO");}
struct io{io(){ios::sync_with_stdio(false);cin.tie(0);}};
const int INF = INT_MAX;
constexpr ll LLINF = 1LL<<60;
constexpr ll MOD = 1000000007;
constexpr double EPS = 1e-9;



int main() {

    string s,t;
    cin>>s>>t;
    Yn(s==t.substr(0,t.size()-1));
}

Measured memory_bytes: 3620
#include<iostream> 
#include<vector> 
#include<string> 
#include<cstdlib> 
#include<cmath> 
#include<map> 
#include<set> 
#include<iomanip>
#include<iterator> 
#include<sstream> 
using namespace std; 
int main() 
 { 
    long long n,i,p,j,s,k,total=0;
    cin>>n; 
    for(i=1;i<=(n-1);i++) 
    { 
        for(j=1;j<=(n-1);j++)
        {
            if((i*j)<n)
            {
                total++;
            }
            else
            {
                break;
            }
        }
    }
    cout<<total<<endl;
    return 0;
}

Measured memory_bytes: 3640
from math import floor, ceil
a, b = map(int, input().split())

a1 = ceil(12.5 * a)
if a % 2 == 0:
    a2 = floor(12.5 * (a + 1))
else:
    a2 = 12.5 * (a + 1) - 1

b1 = 10 * b
b2 = 10 * (b + 1) - 1

if b2 < a1 or a2 < b1:
    print(-1)
else:
    print(max(a1, b1))

Measured memory_bytes: 3064
from collections import Counter,defaultdict,deque
from heapq import heappop,heappush
from bisect import bisect_left,bisect_right 
import sys,math,itertools,fractions,pprint
sys.setrecursionlimit(10**8)
mod = 10**9+7
INF = float('inf')
def inp(): return int(sys.stdin.readline())
def inpl(): return list(map(int, sys.stdin.readline().split()))

n = inp()
a = []
b = []
for _ in range(n):
    x,y = inpl()
    a.append(x+y)
    b.append(x-y)
print(max(max(a)-min(a), max(b)-min(b)))

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

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

using namespace std;

using ll = long long;
using P = pair<int, int>;

int main() {
  int n;
  cin >> n;
  vector<int> b(n - 1);
  rep(i, n - 1) {
    cin >> b.at(i);
  }
  int res = 0;
  rep(i, n) {
    int x;
    if (i == 0) {
      x = b.at(0);
    } else if (i == n - 1) {
      x = b.at(n - 2);
    } else {
      x = min({b.at(i - 1), b.at(i)});
    }
    res += x;
  }
  cout << res << endl;
  return 0;
}


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

#define FOR(i,a,b) for(int i = (a); i < (b); i++)
#define RFOR(i,b,a) for(int i = (b) - 1; i >= (a); i--)
#define ITER(it, a) for(typeof(a.begin()) it = a.begin(); it != a.end(); it++)
#define FILL(a, value) memset(a, value, sizeof(a))

#define SZ(a) (int) a.size()
#define ALL(a) a.begin(),a.end()
#define PB push_back
#define MP make_pair

typedef long long LL;
typedef vector<int> VI;
typedef pair<int, int> PII;

const double PI = acos(-1.0);
const LL INF = 1000 * 1000 * 1000 + 7;
const LL LINF = INF * (LL)INF;

const int MAX = 50;

LL DP[MAX][2];

int main()
{
	//freopen("in.txt", "r", stdin);
	//ios::sync_with_stdio(false); cin.tie(0);

	int n, p;
	scanf("%d%d", &n, &p);

	DP[0][0] = 1;

	FOR (i, 0, n)
	{
		int x;
		scanf("%d", &x);

		DP[i+1][0] = DP[i][0];
		DP[i+1][1] = DP[i][1];

		DP[i+1][x & 1] += DP[i][0];
		DP[i+1][(x & 1) ^ 1] += DP[i][1];
	}

	LL res = DP[n][p];

	cout<<res<<endl;
}


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

int main(){
 int base;
  cin >> base;
 int num;
  int amari;
  amari = base % 10;
  num = num + amari;
  base = base / 10;
  amari = base %10;
  num = num + amari;
  base = base / 10;
  amari = base % 10;
  num = num + amari;
  
  cout << num << endl;
  
}

Measured memory_bytes: 256
#include <cstdio>
#include <cstring>
#include <iostream>
#include <string>
#include <cmath>
#include <bitset>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <algorithm>
#include <complex>
#include <unordered_map>
#include <unordered_set>
#include <random>
#include <cassert>
#include <fstream>
#include <utility>
#include <functional>
#include <time.h>
#include <stack>
#include <array>
#define popcount __builtin_popcount
using namespace std;
typedef long long int ll;
typedef pair<int, int> P;
int myon(char c){
	if(c=='r') return 2;
	else if(c=='s') return 0;
	else return 1;
}
int main()
{
	int n, k;
	cin>>n>>k;
	int r[3];
	cin>>r[0]>>r[1]>>r[2];
	string t;
	cin>>t;
	int ans=0;
	for(int i=0; i<k; i++){
		string u;
		for(int j=i; j<n; j+=k) u+=t[j];
		int m=u.size();
		vector<vector<int>> dp(3, vector<int>(m, 0));
		dp[myon(u[0])][0]=r[myon(u[0])];
		for(int j=1; j<m; j++){
			for(int l=0; l<3; l++){
				for(int p=0; p<3; p++){
					if(p==l) continue;
					if(myon(u[j])==l) dp[l][j]=max(dp[l][j], dp[p][j-1]+r[l]);
					else dp[l][j]=max(dp[l][j], dp[p][j-1]);
				}
			}
		}
		ans+=max({dp[0][m-1], dp[1][m-1], dp[2][m-1]});
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 2176
import sys
sys.setrecursionlimit(10**7)
n_ver, n_edge = map(int,input().split())
ad_ls = [[] for _ in range(n_ver)]
for i in range(n_edge):
    a,b = map(int,input().split())
    a -= 1
    b -= 1
    ad_ls[a].append(b)
    ad_ls[b].append(a)
done_ls = [0] * n_ver
def dfs(ver):
    done_ls[ver] = 1
    num = 0
    if done_ls == [1] * n_ver:
        done_ls[ver] = 0
        return 1
    for nex in ad_ls[ver]:
        if done_ls[nex]:
            continue
        num += dfs(nex)
    done_ls[ver] = 0
    return num
print(dfs(0))


Measured memory_bytes: 9000
import sys

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

def main():
	N = II()
	S = IS()
	if(N % 2 != 0):
		print("No")
	else:
		if(S[:N//2] == S[N//2:-1]):
			print("Yes")
		else:
			print("No")

main()

Measured memory_bytes: 3064
#include <cstdio>
#include <iostream>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <cmath>
#include <queue>
using namespace std;
const int N=200010;
typedef long long ll;
int T[N];
ll v[N];
int findr(int x){
    if(T[x]==-1) return x;
    int p=findr(T[x]);
    v[x]+=v[T[x]];
    return T[x]=p;
}
int main(){
    int n,m,i,x,y,z,p,q;
    scanf("%d %d",&n,&m);
    memset(T,-1,sizeof(T));
    for(i=1;i<=m;i++){
        scanf("%d %d %d",&x,&y,&z);
        p=findr(x);q=findr(y);
        if(p==q){
            if(v[y]!=v[x]+z){puts("No");return 0;}
        }
        else T[q]=p,v[q]=v[x]-v[y]+z;
    }
    printf("Yes");
    return 0;
}


Measured memory_bytes: 1792
#include <bits/stdc++.h>
using namespace std;
int main(){
 
int A[9];
int N,num;
bool count =false;
for(int i=0;i<9;i++){
    cin>>A[i];
}
cin>>N;
for(int i=0;i<N;i++){
    cin>>num;
    for(int j=0;j<9;j++){
        if(A[j]==num){
            A[j]=0;
        }
    } 
}
if(A[0]==0&&A[4]==0&&A[8]==0){
   count=true;
}
else if(A[2]==0&&A[4]==0&&A[6]==0){
   count=true;
}
for(int i=0;i<3;i++){
    if(A[i]==0&&A[i+3]==0&&A[i+6]==0){
   count=true;
    }
}
for(int i=0;i<7;i+=3){
    if(A[i]==0&&A[i+1]==0&&A[i+2]==0){
   count=true;
    }
}

if(count){
    cout<<"Yes"<<endl;
}
else{
cout<<"No"<<endl;
}
return 0;
 
}

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

bool is_palindrome(string s) {
	string t = s;
	reverse(t.begin(), t.end()); // tを左右逆にする
	return s == t; // 左右逆にしたものと等しければ回文
}

int main() {
	string s;
	cin >> s;
	if (is_palindrome(s) && is_palindrome(s.substr(0, s.size()/2))) {
		cout << "Yes" << endl;
	} else {
		cout << "No" << endl;
	}
}

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

int main()
{
  string S, T;
  cin >> S >> T;

  for (int i = S.size() - T.size(); i >= 0; --i) {
    
    bool ok = true;
    for (int j = 0; j < T.size(); ++j) {
      if (S[i + j] == '?' || S[i + j] == T[j]) {
	continue;
      }
      ok &= false;
    }

    if (ok) {
      for (int j = 0; j < T.size(); ++j) {
	S[i + j] = T[j];
      }
      for (int j = 0; j < S.size(); ++j) {
	if (S[j] == '?') {
	  S[j] = 'a';
	}
      }
      
      cout << S << endl;
      return 0;
    }
  }
  cout << "UNRESTORABLE" << endl;
  
  return 0;
}


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

using namespace std;

const int mod = 1e9 + 7;

int dp[70005], prefiksy[70005];

int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    int n, k;
    cin >> n >> k;
    vector<pair<int, int> > przedzialy;
    for (int i = 1; i * i <= n; i++){
        int l = n / (i + 1) + 1;
        int r = n / i;
        if ((long long)l * l > n)
            przedzialy.emplace_back(l, r - l + 1);
        przedzialy.emplace_back(i, 1);
    }
    sort(przedzialy.begin(), przedzialy.end());
    n = przedzialy.size();
    for (int i = 0; i < n; i++)
        dp[i] = przedzialy[i].second;
    for (int i = 1; i < k; i++){
        for (int j = 0; j < n; j++)
            prefiksy[j + 1] = ((long long)prefiksy[j] + dp[j]) % mod;
        for (int j = 0; j < n; j++)
            dp[j] = ((long long)prefiksy[n - j] * przedzialy[j].second) % mod;
    }
    int suma = 0;
    for (int i = 0; i < n; i++)
        suma = (long long)(suma + dp[i]) % mod;
    cout << suma << "\n";
    return 0;
}

Measured memory_bytes: 4280
#include<bits/stdc++.h>
using namespace std;
typedef long long LL;
const int P=1e9+7,maxn=(1<<16)+5;
int n,m,a[20];
LL f[20][maxn],fac[maxn],inv[maxn],fac_inv[maxn],ans;
LL C(int n,int m){
  if(n<0||m<0||n<m) return 0;
  return fac[n]*fac_inv[m]%P*fac_inv[n-m]%P;
}
int main(){
  scanf("%d%d",&n,&m);
  fac[0]=1; for(int i=1;i<=(1<<n);i++) fac[i]=fac[i-1]*i%P;
  inv[1]=1; for(int i=2;i<=(1<<n);i++) inv[i]=(LL)(P-P/i)*inv[P%i]%P;
  fac_inv[0]=1; for(int i=1;i<=(1<<n);i++) fac_inv[i]=fac_inv[i-1]*inv[i]%P;
  for(int i=1;i<=m;i++) scanf("%d",&a[i]);
  sort(a+1,a+1+m,greater<int>());
  f[0][0]=1;
  for(int i=0;i<=m-1;i++)
    for(int s=0;s<=(1<<n)-1;s++)
      if(f[i][s]){
	(f[i+1][s]+=f[i][s])%=P;
	for(int j=0;j<=n-1;j++)
	  if(!((s>>j)&1))
	    (f[i+1][s|(1<<j)]+=f[i][s]*C((1<<n)-a[i+1]-s,(1<<j)-1)%P*fac[1<<j]%P)%=P;
      }
  for(int s=0;s<=(1<<n)-1;s++){
    int sz=0; for(int i=0;i<=n-1;i++) if((s>>i)&1) sz++;
    ans=(ans+f[m][s]*fac[(1<<n)-1-s]*((sz&1)?-1:1))%P;
  }
  printf("%d\n",(ans*(1<<n)%P+P)%P);
  return 0;
}


Measured memory_bytes: 9984
#include <bits/stdc++.h>
#define mod 1000000007
using namespace std;
typedef long long ll;
#define LL long long 
ll je[200010];
ll x,y;
LL Gcd(LL a, LL b, LL &x, LL &y)
{
    if(b==0)
	{
        x=1;
        y=0;
        return a;
    }
    LL gcd=Gcd(b,a%b,x,y);
    LL tmp=x;
    x=y;
    y=tmp-(a/b)*y;
    return gcd;
}
LL C(LL m,LL n)
{
    Gcd(je[m]*je[n-m]%mod,mod,x,y);
    return je[n]*(x+mod)%mod;
}
int main()
{
	LL H,W,A,B;
    je[0]=1;
    for(LL i=1;i<200005;i++)
        je[i]=(je[i-1]*i)%mod;
    scanf("%lld%lld%lld%lld",&H,&W,&A,&B);
    LL ans=0;
    for(LL i=B+1;i<=W;i++)
    {
        LL tmp=(C(H-A-1,i-1+H-A-1)*C(W-i,W-i+A-1))%mod;
        ans=(ans+tmp)%mod;
    }
    printf("%lld",ans);
    return 0;
}


Measured memory_bytes: 1792
import java.util.Scanner;

class Main
{
    public static void main(String[] args)
    {
      Scanner sc = new Scanner(System.in);
      int n = sc.nextInt();
      int[] a = new int[30];
      int[] b = new int[30];
      int[] c = new int[30];
      for (int i=0; i<n; i++) a[i] = sc.nextInt();
      for (int i=0; i<n; i++) b[i] = sc.nextInt();
      for (int i=0; i<n-1; i++) c[i] = sc.nextInt();
      int count = 0;
      for (int i=0; i<n; i++) {
        count += b[a[i]-1];
        if(i>0 && a[i]-a[i-1]==1) {
          count += c[a[i-1]-1];
        }
      }
      System.out.println(count);
    }
}



Measured memory_bytes: 25172