akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<iomanip>
#include<math.h>
#include<complex>
#include<queue>
#include<deque>
#include<stack>
#include<map>
#include<set>
#include<bitset>
using namespace std;
#define REP(i,m,n) for(int i=(int)m ; i < (int) n ; ++i )
#define rep(i,n) REP(i,0,n)
typedef long long ll;
typedef pair<int,int> pint;
typedef pair<ll,int> pli;
const int inf=1e9+7;
const ll longinf=1LL<<60 ;
const ll mod=1e9+7 ;
using namespace std;

ll dp[200020];
ll ch[26][200020];

int main(){
  string s;
  cin >> s;
  int n=s.size();
  for(int i=1;i<=n;i++){
    for(char c='a';c<='z';c++){
      ch[c-'a'][i]=ch[c-'a'][i-1];
    }
    ch[s[i-1]-'a'][i]++;
  }
  for(int i=1;i<=n;i++){
    dp[i]=dp[i-1]+(i-1)-ch[s[i-1]-'a'][i-1];
  }
  cout << dp[n]+1 << endl;
  return 0;
}

Measured memory_bytes: 42884
#include<bits/stdc++.h>
using namespace std;
#define fast ios_base::sync_with_stdio(false);cin.tie(NULL)
typedef long long ll;
typedef double dd;
#define pb push_back
#define mp make_pair
#define endl "\n"
#define M 1000000007
#define pi acos(-1)
/*ll power(ll a,ll b)
{
    ll res = 1;
    while(b > 0)
    {
        if(b & 1)
            res = (res*a)%M;
        a = (a*a)%M;
        b = b >> 1;
    }
    return res;
}*/
/*ll modinv(ll a)
{
   return power(a,M - 2); 
}*/
/*vector<ll> primes(ll n)
{
    bool *sieve = new bool[n + 1];
    ll i,j;
    vector<ll> v;
    for(i = 3; i <= n; i+=2)
        sieve[i] = true;
    sieve[2] = true;
    for(i = 3; i*i <= n; i+=2)
    {
        if(sieve[i])
            for(j = i*i; j <= n; j+=i)
                sieve[j] = false;
    }
    if(n >= 2)
    {
        v.pb(2);
        for(i = 3; i <= n; i+=2)
        {
            if(sieve[i])
                v.pb(i);
        }
    }
    return v;
}*/

/*class graph{
public:
    vector<ll> *g;
    ll n;
    graph(ll v)
    {
        n = v + 1;
        g = new vector<ll> [n];
    }
    void addegde(ll f,ll s)
    {
        g[f].pb(s);
        g[s].pb(f);
    }
    void dfs(bool *visited,ll sv)
    {
        visited[sv] = true;
        for(auto x: g[sv])
        {
            if(!visited[x])
            {
                dfs(visited,x);
            }
        }
    }
    void bfs(ll sv){
       queue<ll> q;
       bool visited[n] = {};
       q.push(sv);
       visited[sv] = true;
       while(!q.empty())
       {
           ll node = q.front();
           q.pop();
           for(auto x : g[node])
           {
               if(!visited[x])
               {
                   visited[x] = true;
                   q.push(x);
               }
           }
       }
    }
};*/
int main()
{
    fast;
   
    ll i,j,t,c = 0,k;
    ll n,d;
    cin >> n >> d;
    ll a[n][d];
    for(i = 0 ; i < n; i++)
      for(j = 0;  j < d; j++)
        cin >> a[i][j];
    ll temp = 0;
    for(i = 0; i < n; i++)
    {
      for(j = i + 1; j < n; j++)
      {
        temp = 0;
        for(k = 0; k < d; k++)
          temp += ((a[i][k] - a[j][k])*(a[i][k] - a[j][k]));
        double d = sqrt(temp);
        if(d == (long long)d)
          c++;
      }
    }
    cout<<c<<endl;
    return 0;
}



Measured memory_bytes: 256
import java.util.*;
public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt(), M = sc.nextInt();
		int S[] = new int[N];
		int T[] = new int[M];
		for(int i=0;i<N;i++)S[i]=sc.nextInt();
		for(int i=0;i<M;i++)T[i]=sc.nextInt();
		sc.close();
		
		int mod = (int)1e9+7;
		long dp[][] = new long[N+1][M+1];
		long sum[][] = new long[N+2][M+2];
		dp[0][0]=1;sum[1][1]=1;
		for(int i=0;i<=N;i++) {
			for(int j=0;j<=M;j++) {
				if(i==0&&j==0)continue;
				if(i>0&&j>0&&S[i-1]==T[j-1]) dp[i][j] = sum[i][j];					
				sum[i+1][j+1] = (sum[i][j+1]+sum[i+1][j]-sum[i][j]+dp[i][j])%mod;
				if(sum[i+1][j+1]<0)sum[i+1][j+1]+=mod;
			}
		}
		long ans = sum[N+1][M+1];
		System.out.println(ans);
	}
}


Measured memory_bytes: 128308
#include <iostream>
#include <map>

using namespace std;

int main() {
    int N;
    cin >> N;
    
    map<int, int> mp;
    mp[2]++;
    for(int n=3; n<=N; n++) {
        bool flag=true;
        int tmp=n;
        // int i=2;
        // while(i*i<=n) {
        //     while(tmp%i==0) {
        //         mp[i]++;
        //         tmp/=i;
        //         flag=false;
        //     }
        //     i++;
        // }
        
        for(auto itr=mp.begin(); itr!=mp.end(); itr++) {
            if(n%(itr->first)==0) {
                while(tmp>1 && tmp%(itr->first)==0) {
                    itr->second++;
                    tmp/=(itr->first);
                }
                flag = false;
            }
        }
        if(flag) {
            mp[n]++;
        }
    }

    // for(auto itr=mp.begin(); itr!=mp.end(); itr++) {
    //     cout << itr->first << " : " << itr->second << endl;
    // }

    int ans=0;
    for(auto itr=mp.begin(); itr!=mp.end(); itr++) {
        if((itr->second)>=74) ans++;
    }
    
    for(auto itr=mp.begin(); itr!=mp.end(); itr++) {
        if((itr->second)<24) continue;
        
        for(auto jtr=mp.begin(); jtr!=mp.end(); jtr++) {
            if(jtr==itr) continue;
            if((jtr->second)<2) continue;

            ans++;
        }
    }

    for(auto itr=mp.begin(); itr!=mp.end(); itr++) {
        if((itr->second)<14) continue;
        
        for(auto jtr=mp.begin(); jtr!=mp.end(); jtr++) {
            if(jtr==itr) continue;
            if((jtr->second)<4) continue;

            ans++;
        }
    }

    for(auto itr=mp.begin(); itr!=mp.end(); itr++) {
        if((itr->second)<4) continue;
        
        for(auto jtr=itr; jtr!=mp.end(); jtr++) {
            if(jtr==itr) continue;
            if((jtr->second)<4) continue;

            for(auto ktr=mp.begin(); ktr!=mp.end(); ktr++) {
                if(ktr==itr) continue;
                if(ktr==jtr) continue;
                if((ktr->second)<2) continue;
                
                ans++;
            }
        }
    }

    cout << ans << endl;

    return 0;
    
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
#define rep(i, n) for (ll i = 0; i < n; i++)
#define FOR(i, a, b) for (ll i = a; i < b; i++)
#define len(v) ll(v.size())
#define fi first
#define se second

template <class T>
void cout_vec(const vector<T> &vec){
  for(auto itr:vec) cout<<itr<<' ';
  cout<<endl;
}

template <class T>
void cout_vec2(const vector<vector<T>> &vec){
  rep(i,vec.size()){
    rep(j,vec[i].size()){
      cout<<vec[i][j]<<' ';
    }
    cout<<endl;
  }
}

typedef pair<ll,ll> P;
const ll mod=1e9+7;
const ll inf=1e15;

int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  ll n,W;
  cin>>n>>W;
  vector<vector<ll>> w(4);
  ll x,y;
  cin>>x>>y;
  w[0].push_back(y);
  rep(i,n-1){
    ll a,b;
    cin>>a>>b;
    w[a-x].push_back(b);
  }
  rep(i,4) sort(begin(w[i]),end(w[i]),greater<ll>());
  ll ans=0;
  rep(i,w[0].size()+1)rep(j,w[1].size()+1)rep(k,w[2].size()+1)rep(l,w[3].size()+1){
    ll weight=x*i+(x+1)*j+(x+2)*k+(x+3)*l;
    if(weight>W) continue;
    ll cnt=0;
    rep(x,i) cnt+=w[0][x];
    rep(x,j) cnt+=w[1][x];
    rep(x,k) cnt+=w[2][x];
    rep(x,l) cnt+=w[3][x];
    ans=max(ans,cnt);
  }
  cout<<ans<<endl;
}

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

int main() {
	long int sum=0;
	long int n,i;
	cin>>n;
	long int a[n];
	for(i=0;i<n;i++)
		{   cin>>a[i];
			 sum+=(a[i]-1);
		}	
	cout<<sum<<'\n';	
	// your code goes here
	return 0;
}

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

typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
#define endl '\n';
#define FASTER ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
const ll POSITIVE_INFINITY = 9223372036854775807;
const ll NEGATIVE_INFINITY = -9223372036854775807;
const ll MOD = 1000000007;
const ld PI = acos(-1.0);

template <typename T> inline T bigMod(T A,T B,T M = MOD){A %= M;T ret = 1;while(B){if(B & 1) ret = (ret * A) % M;A = (A * A) % M;B = B >> 1;}return ret;}
template <typename T> inline T invMod (T A,T M = MOD){return bigMod(A,M-2,M);}

const int N = 200005;

int main(){
  FASTER;
  int n;
  cin >> n;
  vector<int>ar(n);
  for (int i = 0; i < n; i++){
    cin >> ar[i];
  }
  int mn = n + 1;
  int ans = 0;
  for (int i = 0; i < n; i++){
    mn = min(mn, ar[i]);
    if (ar[i] <= mn){
      ans++;
    }
  }
  cout << ans << "\n";
  return 0;
}

Measured memory_bytes: 1024
#include <iostream>
#include <vector>

using namespace std;

int main() {
    string s;
    cin >> s;
    vector<int> answer(s.length(), 0);
    int r = 0, l = 0;
    for (int i = 0, length = s.length(); i < length; ++i) {
        if (s[i] == 'R') ++r;
        if (i > 0 && s[i - 1] == 'R' && s[i] == 'L') {
            while (i + l < length && s[i + l] == 'L') ++l;
            answer[i - 1] = r / 2 + l / 2 + (r % 2);
            answer[i] = r / 2 + l / 2 + (l % 2);
            i += l - 1;
            r = 0, l = 0;
        }
    }
    for (int i = 0, size = answer.size(); i < size; ++i) {
        cout << answer[i];
        if (i < size - 1) cout << " ";
    }
    cout << endl;
}


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

using namespace std;

const int inf = (int)1e9 + 7;

int n, ans;
pair<int, int> mx;
vector<pair<int, int> > interval;

pair<int, int> operator + (const pair<int, int>& a, const pair<int, int>& b) {
    return { max(a.first, b.first), min(a.second, b.second) };
}

int main() {
    scanf(" %d", &n);
    interval.assign(n, {} );
    for (int i = 0; i < n; ++i) {
        int l, r; scanf(" %d %d", &l, &r);
        interval[i] = { l, r };
    }

    auto it = max_element(interval.begin(), interval.end() );
    mx = *it; interval.erase(it);


    sort(interval.begin(), interval.end(), [&](pair<int, int> i, pair<int, int> j) { return i.second < j.second; });

    int mxInterval = 0;
    for (auto _ : interval) mxInterval = max(mxInterval, _.second - _.first + 1);
    ans = max(ans, mxInterval + max(0, min(interval[0].second, mx.second) - mx.first + 1) );

//    cerr << mx.first << ' ' << mx.second << '\n';
//    for (auto _ : interval) cerr << _.first << ' ' << _.second << '\n';

    pair<int, int> pref = { -inf, inf };
    int prv = 0;
    for (int i = 0; i < (int)interval.size(); ++i) {
        while (prv < (int)interval.size() && interval[prv].second < interval[i].second) {
            pref = pref + interval[prv];
            ++prv;
        }
        if (prv) {
            ans = max(ans, max(0, interval[i].second - mx.first + 1) + max(0, pref.second - pref.first + 1) );
        }
    }
    while (prv < (int)interval.size() ) {
        pref = pref + interval[prv];
        ++prv;
    }
    ans = max(ans, max(0, mx.second - mx.first + 1) + max(0, pref.second - pref.first + 1) );

    cout << ans;

    return 0;
}
/*
455073228 459494089
455108441 512701454
455817105 523506955
456475528 529149798
456580262 636471526
456651538 774276744
457293701 800549465
457368248 814532746
457667152 974637457
*/


Measured memory_bytes: 1024
#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
using namespace std;
 
const int MAXN = 1000 + 10;

long long ans;

void gcd(long long a, long long b) {
    if (a % b == 0) {
        ans += b * (a/b) * 2 - b;
        return;
    }
    ans += b * (a/b) * 2;
    gcd(b, a%b);
}

int main() {
    long long N, X;
    while (scanf("%lld%lld", &N, &X) != EOF) {
        ans = N;
        gcd(X, N-X);
        printf("%lld\n", ans);
    }
    return 0;
}

Measured memory_bytes: 256
a, b, c, d = map(int, input().split())
if c-a > d:
    if 0 <= b-a <= d and 0 <= c-b <= d:
        print('Yes')
    else:
        print('No')
elif -d <= c-a <= d:
    print('Yes')
elif c-a < -d:
    if 0 <= a-b <= d and 0 <= b-c <= d:
        print('Yes')
    else:
        print('No')


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

int main()
{
    int N, X, m;
    cin >> N >> X;
    int min = 1000;
    for (int i = 0; i < N; i++)
    {
        cin >> m;
        X -= m;
        if (m < min)
            min = m;
    }

    cout << N + X / min << endl;
}

Measured memory_bytes: 256
import java.io.PrintWriter;
import java.util.Scanner;
import java.util.Stack;

public class Main {

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

	public static void main(String[] args) {

		Scanner scan = new Scanner(System.in);
		PrintWriter out = new PrintWriter(System.out);

		MainLoop : while(true){
			int w = Integer.parseInt(scan.next());
			int h = Integer.parseInt(scan.next());
			if(w==0) break;
			byte[][] map = new byte[h][w];

			int sx = Integer.parseInt(scan.next())-1;
			int sy = Integer.parseInt(scan.next())-1;
			int gx = Integer.parseInt(scan.next())-1;
			int gy = Integer.parseInt(scan.next())-1;
			int n = Integer.parseInt(scan.next());
			for (int i = 0; i < n; i++) {
				byte c = scan.nextByte();
				int d = Integer.parseInt(scan.next());
				int x = Integer.parseInt(scan.next())-1;
				int y = Integer.parseInt(scan.next())-1;
				for (int j = 0; j < (d==0 ? 2 : 4) ; j++)
					for (int j2 = 0; j2 < (d==0 ? 4 : 2) ; j2++)
						map[j+y][j2+x] = c;

			}

			if(map[sy][sx]==0){
				out.println("NG");
				continue;
			}
			int color = map[sy][sx];
			Stack<int[]> stk = new Stack<int[]>();
			stk.push(new int[]{sx,sy});

			while(!stk.isEmpty()){
				int[] pos = stk.pop();
				map[pos[1]][pos[0]]=0;
				if(pos[0]==gx && pos[1]==gy){
					out.println("OK");
					continue MainLoop;
				}

				for (int i = 0; i < 4; i++) {
					int nx = pos[0]+dx[i],ny = pos[1]+dy[i];
					if(nx>=0 && nx<w && ny>=0 && ny<h && color==map[ny][nx])
						stk.push(new int[]{nx,ny});
				}
			}
			out.println("NG");
		}

		out.flush();
	}
}

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

#define abs(a) (a) < 0 ? (-(a)) : (a)
int main() {
	long A;
	long V;
	long B;
	long W;
	long T;
	scanf("%ld", &A);
	scanf("%ld", &V);
	scanf("%ld", &B);
	scanf("%ld", &W);
	scanf("%ld", &T);
	long dif = abs(A - B);
	long sotai = V - W;
	if (sotai <= 0) {
		printf("NO\n");
		return 0;
	}

	long kyori = sotai * T;

	if (dif <= kyori)
		printf("YES\n");
	else
		printf("NO\n");

	return 0;
}


Measured memory_bytes: 1648
#include <stdint.h>
#include <cstdlib>
#include <cstring>
#include <string>
#include <map>
#include <vector>
#include <iostream>
#include <bitset>
#include <array>
#include <stdio.h>
using namespace std;

# define MAX 1000
uint64_t D0[MAX]={0}, HP[MAX]={0}, HN[MAX]={0}, VP[MAX]={0}, VN[MAX]={0};
uint64_t Cmap[MAX][20] = {};

int Mayer(size_t M, size_t N, string &a, string &b){
    unsigned int tmax = (M - 1) >> 6;
    unsigned int tlen = M - tmax * 64;
    // cout << "M:" << M << " " << "N:" << N << endl;
    // cout << "tmax:" << tmax << endl;
    // cout << "tlen:" << tlen << endl;

    for(size_t i = 0; i < tmax; ++i) {
        for(size_t j = 0; j < 64; ++j) Cmap[a[i * 64 + j]][i] |= (1L << j);
    }

    for(size_t i = 0; i < tlen; ++i){
        Cmap[a[tmax * 64 + i]][tmax] |= (1L << i);
        // printf("%c\n", a[tmax * 64 + i]);
    }

    int D = tmax * 64 + tlen;

    uint64_t top = (1L << (tlen - 1));  
    uint64_t lmb = (1L << 63);
    for(size_t i = 0; i < tmax; ++i) VP[i] = ~0;
    for(size_t i = 0; i < tlen; ++i) VP[tmax] |= (1L << i);

    for(size_t i = 0; i < N; ++i) {
        uint64_t *PM = Cmap[b[i]];
        for(int r = 0; r <= tmax; ++r) {
            uint64_t X = PM[r];
            if(r > 0 && (HN[r - 1] & lmb)) X |= 1L;
            D0[r] = (((X & VP[r]) + VP[r]) ^ VP[r]) | X | VN[r];
            HP[r] = VN[r] | ~(D0[r] | VP[r]);
            HN[r] = D0[r] & VP[r];
            X = (HP[r] << 1L);
            if(r == 0 || HP[r - 1] & lmb) X |= 1L;
            VP[r] = (HN[r] << 1L) | ~(D0[r] | X);
            if(r > 0 && (HN[r - 1] & lmb)) VP[r] |= 1L;
            VN[r] = D0[r] & X;
        }
        if(HP[tmax] & top) ++D;
        else if(HN[tmax] & top) --D;
    }

    // free(D0), free(HP), free(HN), free(VP), free(VN);
    return D;
}


int main() {
    string str1, str2;
    std::cin >> str1 >> str2;
    if(str1.length() > str2.length()){
        string tmp = str1;
        str1 = str2;
        str2 = tmp;
    }

    // int res = edit_distance_fixed_<1000, string, 1000>(str1,str2);
    int res = Mayer(str1.length(), str2.length(), str1, str2);
    std::cout << res << std::endl;
    return 0;
}





Measured memory_bytes: 3228
def gcd(a, b):
    if a < b:
        a, b = b, a
    if b == 0:
        return a
    c = a % b
    return gcd(b, c)

n = int(input())
a = [int(i) for i in input().split(" ")]

b = gcd(a[0], a[1])
for i in range(2,n):
  b = gcd(b,a[i])
print(b)

Measured memory_bytes: 14252
#include"bits/stdc++.h"
//#include<bits/stdc++.h>
using namespace std;
#define print(x) cout<<x<<endl;
#define rep(i,a,b) for(int i=a;i<b;i++)
typedef long long ll;
const ll mod = LLONG_MAX;

int n, a;
int x[52];
ll dp[52][52][3000] = {};

int main() {
	cin >> n >> a;
	rep(i, 0, n)cin >> x[i];
	dp[0][0][0] = 1;
	rep(i, 0, n) {
		rep(j, 0, n) {
			rep(k, 0, 3000) {
				dp[i + 1][j + 1][x[i] + k] += dp[i][j][k];
				dp[i + 1][j][k] += dp[i][j][k];
			}
		}
	}
	ll ans = 0;
	rep(i, 1, n + 1)ans += dp[n][i][i*a];
	print(ans);
	return 0;
}

Measured memory_bytes: 61184
#include <bits/stdc++.h>
using namespace std;
#define REP(i,N) for(int i=0;i<N;++i)
#define MAX_I INT_MAX //1e9
#define MIN_I INT_MIN //-1e9
#define MAX_UI UINT_MAX //1e9
#define MAX_LL LLONG_MAX //1e18
#define MIN_LL LLONG_MIN //-1e18
#define MAX_ULL ULLONG_MAX //1e19
  typedef long long ll;
  typedef pair<int,int> PII;
  typedef pair<char,char> PCC;
  typedef pair<ll,ll> PLL;
  typedef pair<char,int> PCI;
  typedef pair<int,char> PIC;
  typedef pair<ll,int> PLI;
  typedef pair<int,ll> PIL; 
  typedef pair<ll,char> PLC; 
  typedef pair<char,ll> PCL; 

bool comp(const PII& l, const PII& r){
  return (double)l.second/l.first > (double)r.second/r.first;
}

int main(void){
  //ios::sync_with_stdio(false);
  //cin.tie(0);
  //cout << setprecision(15);

  ll N;cin >> N;
  vector<PLL> x(3);
  cin >> x[0].first >> x[1].first >> x[2].first;
  cin >> x[0].second >> x[1].second >> x[2].second;
  vector<PLL> v,w;
  REP(i,3){
    if((double)x[i].second/x[i].first > 1)v.push_back(x[i]);
    else if((double)x[i].second/x[i].first < 1) w.push_back(x[i]);
  }
  if(v.size()>=2){
    int M = v.size();
    //dp[i+1][j]:i番目まで見て,j個ある時の変換後の最大数
    ll dp[M+1][N+1];
    REP(j,N+1) dp[0][j] = N;
    REP(i,M){
      REP(j,N+1){
        if(j < v[i].first){
          dp[i+1][j] = dp[i][j];
        }else{
          dp[i+1][j] = max(dp[i][j], dp[i+1][j-v[i].first] + v[i].second - v[i].first);
        }
      }
    }
    N = dp[M][N];
  }else if(v.size()==1){
    ll n = N/v[0].first;
    N += n*(v[0].second - v[0].first);
  }

  if(w.size()>=2){
    int M = w.size();
    //dp[i+1][j]:i番目まで見て,j個ある時の変換後の最大数
    vector<vector<ll> > dp(M+1,vector<ll>(N+1));
    REP(j,N+1) dp[0][j] = N;
    REP(i,M){
      REP(j,N+1){
        if(j < w[i].second){
          dp[i+1][j] = dp[i][j];
        }else{
          dp[i+1][j] = max(dp[i][j], dp[i+1][j-w[i].second] + w[i].first - w[i].second);
        }
      }
    }
    N = dp[M][N];

  }else if(w.size()==1){
    ll n = N/w[0].second;
    N += n*(w[0].first - w[0].second);
  }

  cout << N << endl;
  return 0;
}


Measured memory_bytes: 773504
#include<stdio.h>
#include<iostream>
#include<iomanip>
#include<string>
#include<vector>
#include<queue>
#include<stack>
#include<map>
#include<set>
#include<algorithm>
#include<string>
#include<math.h>
#include<numeric>
#include<complex>
#include<ctype.h>

using namespace std;
typedef long long ll;

#define REP(i,n) for(int i=0;i<n;++i)
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define ALL(v) (v).begin(), (v).end()
#define p(s) cout<<(s)<<endl
#define p2(s, t) cout << (s) << " " << (t) << endl
#define pn(s) cout << (#s) << " " << (s) << endl

const ll mod = 1e9 + 7;
const ll inf = 1e18;

void pV(vector<ll> A){
    cout << "[vector]";
    for(int i=0; i<A.size(); i++){
        cout << A[i] << " ";
    }
    cout << endl;
}

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    // input
    string S;
    cin >> S;

    // 後端のBを切り取る（終端はWとする）
    int L = S.size();
    for(int i=S.size()-1; i>=0; i--){
        if(S[i]=='B'){
            L--;
        }else{
            break;
        }
    }

    if(L<=0){
        // Bしかないやん
        p(0);
        return 0;
    }

    int whiteIndex = L - 1;
    int blackIndex = L - 1;

    ll answer = 0;

    // search white
    while(true){
        while(S[whiteIndex] != 'W'){
            whiteIndex--;
            if(whiteIndex == -1){
                p(answer);
                return 0;
            }
        }
        while(S[blackIndex] != 'B'){
            blackIndex--;
            if(blackIndex == -1){
                p(answer);
                return 0;
            }
        }
        swap(S[whiteIndex], S[blackIndex]);
        answer += (whiteIndex - blackIndex);
    }

    return 0;
}

Measured memory_bytes: 720
#include "bits/stdc++.h"
using namespace std;

int main(){
    int a,b;
    cin>> a>>b;
    int ans=0;
    if(a>b){
        ans=a;
        a--;
    }else{
        ans=b;
        b--;
    }
    if(a>b){
        ans+=a;
    }else{
        ans+=b;
    }
    cout<<ans<<"\n";
    return(0);
}

Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <utility>
#include <cmath>
#include <random>
#include <vector>
#include <map>
#include <set>
#include <deque>
#include <queue>
#include <stack>
#include <string>
#include <algorithm>
using namespace std;

#define rep(i,n) for(int i = 0; i<n; ++i)
#define REP(i,n) for(int i = 1; i<=n; ++i)
#define all(x) begin(x),end(x)
#define show(obj) {for(auto x:obj)cout<<x<<' ';cout<<endl;}
#define line "----------"
typedef long long ll;
typedef pair<int,int> ip;
typedef pair<ll,ll> lp;
const int inf = 1001001000;
const ll INF = 1LL<<60;
const int MOD = (int)1e9 + 7;

int main(){
	int N;cin>>N;
	vector<int> A(N), B(N),need(N);
	rep(i,N)cin>>A[i]>>B[i];
	ll ans = 0;
	for(int i = N-1; i>=0; --i){
		ll t = (A[i] + ans)%B[i];
		if(t == 0)t = B[i];
		ll e_ans = B[i] - t;
		ans += e_ans;
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 1536
#include <iostream>
#include <stdio.h>
#include <stdlib.h>
#include <algorithm>
#include <cassert>
#include <string>
//#include <bits/stdc++.h>
using namespace std;
const int N = 1e6 + 9, M = 1e7, OO = 0x3f3f3f3f, eps = 0.001;
#define IO() assert(freopen("in.in", "rt", stdin)), assert(freopen("out.out", "wt", stdout))
#define ll long long int
#define FastIO() ios::sync_with_stdio(false), cin.tie(0);
void printar(int arr[], int n)
{
    for (int i = 0; i < n; i++)
    {
        cout << arr[i] << " ";
    }
    cout << endl;
}
// template <typename... T>
// void debug(T &... args)
// {
//     ((cerr << args << " "), ...);
//     cerr << endl;
// }
// struct COMPARE {
//   bool operator()(pair<string,ll> const& P1, pair<string,ll> const& P2)
//     {

//         return P1.first < P2.second;
//     }
// };
// priority_queue<pair<string,ll>,vector<pair<string,ll>>,COMPARE >pq;
ll gcd(ll a, ll b){
    if (a == 0)
        return b;
    return gcd(b % a, a);
}
int main()
{
    // icpctraining
    // 3
    // 1 7 11
    // IO();
    FastIO();
    ll n, x, z; cin >> n >> x;
    ll arr[n];
    for(int i = 0; i < n; i++)
    {
        cin >> z;
        arr[i] = abs(z - x);
    }
    ll cnt = arr[0];
    for(int i = 1; i < n; i++)
    {
        cnt = gcd(cnt, arr[i]);
    }
    cout << cnt << endl;
    return 0;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using vi=vector<int>;using vvi=vector<vi>;using vl=vector<ll>;
using P=pair<int,int>;using PL=pair<ll,ll>;using vp=vector<P>;
const int INF=1<<30,MOD=1000000007;const ll LINF=1ll<<60;
#define _ol3(_1,_2,_3,name,...) name
#define _rep(i,n) _repi(i,0,n)
#define _repi(i,a,b) for(int i=a,i##_l=(b);i<i##_l;++i)
#define REP(...) _ol3(__VA_ARGS__,_repi,_rep,)(__VA_ARGS__)
#define REPR(i,n) for(int i=n-1;i>=0;--i)
#define REPA(i,v) REP(i,v.size())
#define all(v) (v).begin(),(v).end()
#define bit(n) (1ll<<(n))
#define clamp(n,mi,ma) max(min(n,ma),mi)
#define uniq(v) sort(all(v));v.erase(unique(all(v)),v.end())
#define pb push_back
#define F first
#define S second
#define endl '\n'
#define cho(n,a,b) cout<<((n)?a:b)<<endl
#define YES(n) cho(n,"YES","NO")
#define Yes(n) cho(n,"Yes","No")
#define Poss(n) cho(n,"Possible","Impossible")
template<class T>bool chmax(T&a,const T&b){if(a<b){a=b;return 1;}return 0;}
template<class T>bool chmin(T&a,const T&b){if(a>b){a=b;return 1;}return 0;}
template<class T>ostream&operator<<(ostream&o,const vector<T>&v){for(auto&&i:v)o<<i<<' ';return o;}
template<class T>istream&operator>>(istream&i,vector<T>&v){for(T&j:v)i>>j;return i;}
template<class T,class U>ostream&operator<<(ostream&o,const pair<T,U>&p){return o<<p.F<<' '<<p.S;}
template<class T,class U>istream&operator>>(istream&i,pair<T,U>&p){return i>>p.F>>p.S;}
template<class T>ostream&operator<<(ostream&o,const set<T>&v){for(auto&&i:v)o<<i<<' ';return o;}
template<class T>ostream&operator<(ostream&o,const T&t){return o<<t;}
template<class T>istream&operator>(istream&i,T&t){return i>>t;}
#ifndef LOCAL
struct ostdmy{
template<class T>ostdmy&operator<<(const T&t){return*this;}
template<class T>ostdmy&operator<(const T&t){return*this;}};ostdmy cer_;
#define cerr cer_
#endif
int main(){
    cin.tie(0);ios::sync_with_stdio(0);
    int n,m;
    cin>n>m;
    vi cs(n+1);
    REP(i,m){
        int l,r;
        cin>l>r;
        cs[l-1]++;
        cs[r]--;
    }
    int c=0;
    int ans=0;
    REP(i,n){
        c+=cs[i];
        cerr<c<',';
        if(c==m)ans++;
    }
    cout<ans<endl;
    return 0;
}


Measured memory_bytes: 640
#include <stdio.h>
#include <math.h>
int main(){
	double x1,x2;
	double y1,y2;
	scanf("%lf %lf",&x1,&y1);
	scanf("%lf %lf",&x2,&y2);
	x1-=x2;
	y1-=y2;
	printf("%lf\n",sqrt(x1*x1+y1*y1));
	return 0;
}



Measured memory_bytes: 2056
#include <stdio.h>

#define MIN(x, y) ((x) > (y) ? (y) : (x))
#define REP(x, y) for((x) = 0;(x) < (y);++(x))

int main(){
  int n, i, j, k, min;
  while(scanf("%d", &n) && n){
    min = 100000;
    n /= 100;
    REP(i, 26) REP(j, 17) REP(k, 11)
      if(i * 2 + j * 3 + k * 5 == n)
        min = MIN(min, (i / 5) * 1520 + (i % 5) * 380 + (j / 4) * 1870 + (j % 4) \
* 550 + (k / 3) * 2244 + (k % 3) * 850);
    printf("%d\n", min);
  }
  return 0;
}

Measured memory_bytes: 600
if __name__ == "__main__":
  n, k, q = list(map(int, input().split()))
  A = [k-q]*n
  for _ in range(q):
    a = int(input())
    A[a-1] += 1

  for i in range(n):
    print("Yes\n" if A[i]>0 else "No\n")

Measured memory_bytes: 6608
from sys import setrecursionlimit

setrecursionlimit(10 ** 6)


def floor_sum(n, m, a, b):
    ans = 0
    if a >= m:
        ans += (n - 1) * n * (a // m) // 2
        a %= m
    if b >= m:
        ans += n * (b // m)
        b %= m

    y_max = (a * n + b) // m
    x_max = y_max * m - b
    if y_max == 0:
        return ans
    ans += (n - (x_max + a - 1) // a) * y_max
    ans += floor_sum(y_max, a, m, (a - x_max % a) % a)
    return ans


T, *queries = map(int, open(0).read().split())
for q in zip(*[iter(queries)] * 4):
    print(floor_sum(*q))


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

string a, b;

int main(void){
	cin >> a >> b;
	int n, m;
	n = a.size();
	m = b.size();
	if(n > m) cout << "GREATER" << endl;
	else if(n < m) cout << "LESS" << endl;
	else{
		if(a > b) cout << "GREATER" << endl;
		else if(a < b) cout << "LESS" << endl;
		else cout << "EQUAL" << endl;
	}
	return 0;
}


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

signed main(){
  int N, M; cin >> N >> M;
  vector<int> box(100010, 1), visit(100010, false);
  visit[1] = true;
  for(int i = 0; i < M; i++){
    int x, y; cin >> x >> y;
    box[x]--; box[y]++;
    if(visit[x]) visit[y] = true;
    if(box[x] == 0) visit[x] = false;
  }
  int ans = 0;
  for(int i = 0; i < box.size(); i++){
    if(visit[i]) ans++;
  }
  cout << ans << endl;
}

Measured memory_bytes: 1792
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<map>
#include<math.h>
#include<queue>
#include<deque>
#include<stack>
#include<cstdio>
#include<utility>
using namespace std;
using ll = long long;
using pii = pair<int, int>;
const int INF = 1e9;
int main() {
	int N;
	cin >> N;
	vector<ll>vx(N), vy(N), vh(N);
	ll X= -1; ll Y = -1; ll H=-1;
	int si = -1;
	for (int i = 0; i < N; ++i) {
		cin >> vx[i] >> vy[i] >> vh[i];
		if (vh[i] > 0) {
			si = i;
		}
	}
	for (ll x = 0; x <= 100; ++x) {
		for (ll y = 0; y <= 100; ++y) {
			ll h = vh[si] + abs(x - vx[si]) + abs(y - vy[si]);
			bool can = true;
			for (int i = 0; i < N; ++i) {
				if(vh[i] > 0 && h != vh[i] + abs(x - vx[i]) + abs(y - vy[i]) ){
					can = false;
				}
				if (vh[i] == 0 && h > abs(x - vx[i]) + abs(y - vy[i])) {
					can = false;
				}
			}
			if (can) {
				H = h; X = x; Y = y;
			}
		}
	}
	cout << X << " " << Y << " " << H << endl;
	return 0;
}


Measured memory_bytes: 256
#include <cstdio>
#include <cstring>
#include <vector>
#include <map>
#include <functional>
#include <algorithm>
using namespace std;

int main() {
	int dummy;
	//int N, K;
	//dummy = scanf("%d %d", &N, &K);

	//vector<pair<int, int>> vp;
	map<int, int> mi;

	int tmp1, tmp2;
	for (int i = 0; i < 3; i++) {
		dummy = scanf("%d %d", &tmp1, &tmp2);
		//vp.push_back(make_pair(min(tmp1, tmp2), max(tmp1, tmp2)));
		mi[tmp1]++;
		mi[tmp2]++;
	}

	int count = 0;
	for (int i = 1; i < 5; i++) {
		if (mi[i] % 2) count++;
	}

	if (count == 0 || count == 2) printf("YES\n");
	else printf("NO\n");

	return 0;
}


Measured memory_bytes: 256
#include <cstring>
#include <cassert>
#include <utility>
#include <iostream>
#include <cstdio>
#include <iomanip>
#include <bitset>
#include <chrono>
#include <cstdlib>
#include <functional>
#include <tuple>
#include <climits>
#include <limits>
#include <deque>
#include <list>
#include <array>
#include <stack>
#include <queue>
#include <random>
#include <complex>
#include <string>
#include <vector>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <algorithm>
 
#define init ios::sync_with_stdio(0); cin.tie(NULL);cout.tie(NULL);
#define setpr(x) cout << setprecision((x))
#define PI atan(1)*4
#define fi first
#define se second
#define pb push_back
#define eb emplace_back
#define lb lower_bound
#define ub upper_bound
#define mk(a , b) { min((a) , (b)) , max((a) , (b)) }
#define flush cout.flush()
#define all(v) v.begin(),v.end()
#define rall(v) v.rbegin(),v.rend()
#define endc "\n"
#define MOD 998244353
#define meme(x) memset((x), 0, sizeof((x)))
#define memo(x) memset((x),-1, sizeof((x)))
 
using namespace std;

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

// #define int ll

ll egcd(ll a, ll b, ll &x, ll &y){
    if (a == 0LL){  
        x = 0LL;  
        y = 1LL;  
        return b;  
    }
    ll xx, yy;
    ll val = egcd(b % a, a, xx, yy);  
    x = yy - (b / a) * xx;  
    y = xx;  
    return val;
}

ll gcd(ll a, ll b){
    while(true){
        if(a>b)
            swap(a,b);
        if (a == 0) 
            return b; 
        ll p = b % a  , q = a;
        a = p;
        b = q;
    }
}
 
ll powerMod(ll x,ll y){
    ll res = 1;
    x %= MOD;
    while(y > 0){
        if(y & 1)res = (res*x)%MOD;
        y = y >> 1;
        x = (x * x)%MOD;
    }
    return res%MOD;
}

//  ==========     //\\       //||     ||====//||
//      ||        //  \\        ||     ||   // ||
//      ||       //====\\       ||     ||  //  ||
//      ||      //      \\      ||     || //   ||
//  ========== //        \\  ========  ||//====|| 
//  code

void solve(){
    ll n,i,j,k,l,p,w;
    cin >> n >> w;
    vector< vector<ll> > dp(n + 1, vector<ll>(w + 1, 0));
    vector<ll> weights(n), values(n);
    for(i = 0; i < n; i++){
        cin >> weights[i] >> values[i];
    }

    for(i = 0; i < n; i++){
        for(j = 1; j <= w; j++){
            dp[i + 1][j] = dp[i][j];
            if(j >= weights[i]){
                dp[i + 1][j] = max(dp[i + 1][j], dp[i][j - weights[i]] + values[i]);
            }
        }
    }
    cout << dp[n][w] << endc;
}

int32_t main(){
    init;
    int t = 1;
    // cin >> t;
    while(t--){
        solve();
    }
    return 0;
}


Measured memory_bytes: 83156
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <set>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define reps(i, s, n) for (int i = s; i < (int)(n); i++)
#define out(x) cout << x << endl
#define INF 1000000;
#include <map>
#include <math.h>
 
using ll = long long;
using namespace std;

ll n, k;
const ll mod = 1000000007;

int main(){
   string a, b, c;
   cin >> a >> b >> c;
   if(a[a.size()-1]==b[0] && b[b.size()-1]==c[0]) out("YES");
   else out("NO");
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int n;
    cin >> n;
    int ara[n+7];
    for(int i=0; i<n; i++)
    {
        cin >> ara[i];
    }
    for(int i=1; i<n; i++)
    {
        cout << ara[0];
        for(int t=1; t<n; t++)
            cout << " " << ara[t];
        cout << '\n';
        int key=ara[i];
        int j=i-1;
        while(j>=0 and ara[j]>key)
        {
            ara[j+1]=ara[j];
            j--;
        }
        ara[j+1]=key;
    }
    cout << ara[0];
    for(int t=1; t<n; t++)
        cout << " " << ara[t];
    cout <<'\n';
    return 0;
}

Measured memory_bytes: 3080
import java.util.*;
	import java.util.Map.Entry;
	 
	 
	 class Main {
		 static int mod =  (int) (Math.pow(10,9)+7);
//		 static int mod =  (int) 998244353;
		 static List<ArrayList<Integer>> list= new ArrayList<ArrayList<Integer>>();
		 static int a_dist[];
		 public static void main(String[] args) {
	    	
	        Scanner sc = new Scanner(System.in);
	        
	        int N = sc.nextInt();
	        String S = sc.next();
	        char[] c1 = S.toCharArray();
	        char[] c = new char[N];
	        for(int i=0;i<N;i++) {
	        	c[i]=c1[N-i-1];
	        }
	        int cnt=0;
	        for(int i=0;i<N;i++) {
	        	if(c[i]=='1')cnt++;
	        }
	        long[][] m = new long[N][2];
	        m[0][1]=1;
	        m[0][0]=1;
	        long sum1=0;
	        long sum2=0;
	        for(int i=0;i<N;i++) {
	        	if(cnt==1)m[i][0]=0;
	        	else m[i][0]=pow(2,i,(cnt-1));
	        	m[i][1]=pow(2,i,(cnt+1));
	        	if(c[i]=='1') {
		        	sum2=sum2+m[i][1];	        		
		        	sum1=sum1+m[i][0];
	        	}
	        }
	        
	        int H = 200005;
	        long[] a = new long[H];
	        a[1]=1;
	        for(int i=1;i<H;i++) {
	        	int t=0;
	        	for(int j=0;j<20;j++) {
	        		t=t+(i>>j)%2;
	        	}
        		t=i%t;
        		a[i]=a[t]+1;
	        }
	        
	        
	        
	        long[] ans = new long[N];
	        for(int i=0;i<N;i++) {
	        	int t;
	        	if(c[N-i-1]=='1') {
	        		if(cnt==1)ans[i]=0;
	        		else{
	        			t=(int)((sum1-m[N-i-1][0])%(cnt-1));
		        		ans[i]=a[t]+1;
	        		}
	        	} else {
	        		t=(int)((sum2+m[N-i-1][1])%(cnt+1));
	        		ans[i]=a[t]+1;
	        	}
	        }
	        for(int i=0;i<N;i++) {
	        	System.out.println(ans[i]);
	        }
	        
	        

		 }
			public static long pow(long a,long n,long mod) {
			    long res=1;
			    while (n>0) {
			        if ((n-n/2*2)==1) {
			            res=(res*a)%mod;
			        }
			        a=(a*a)%mod;
			        n>>=1;
			    }
			    return res;
			}
	}

Measured memory_bytes: 59468
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.io.IOException;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        InputReader in = new InputReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        CReplacingInteger solver = new CReplacingInteger();
        solver.solve(1, in, out);
        out.close();
    }

    static class CReplacingInteger {
        PrintWriter out;
        InputReader in;

        public void solve(int testNumber, InputReader in, PrintWriter out) {
            this.out = out;
            this.in = in;
            long n = nl();
            long k = nl();
            long div = n / k;
            long num1 = n - div * k;
            long num2 = num1 - k;
            pn(Math.min(Math.abs(num1), Math.min(Math.abs(num2), Math.min(Math.abs(num1 - k), Math.abs(num2 - k)))));

        }

        long nl() {
            return in.nextLong();
        }

        void pn(long zx) {
            out.println(zx);
        }

    }

    static class InputReader {
        private InputStream stream;
        private byte[] buf = new byte[1024];
        private int curChar;
        private int numChars;

        public InputReader(InputStream stream) {
            this.stream = stream;
        }

        public int read() {
            if (numChars == -1)
                throw new UnknownError();
            if (curChar >= numChars) {
                curChar = 0;
                try {
                    numChars = stream.read(buf);
                } catch (IOException e) {
                    throw new UnknownError();
                }
                if (numChars <= 0)
                    return -1;
            }
            return buf[curChar++];
        }

        public long nextLong() {
            return Long.parseLong(next());
        }

        public String next() {
            int c = read();
            while (isSpaceChar(c))
                c = read();
            StringBuffer res = new StringBuffer();
            do {
                res.appendCodePoint(c);
                c = read();
            } while (!isSpaceChar(c));

            return res.toString();
        }

        private boolean isSpaceChar(int c) {
            return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
        }

    }
}



Measured memory_bytes: 23380
#include<iostream>
using namespace std;
int main()
{
	//// 整数の入力
	//int a;
	//cin >> a;
	//// スペース区切りの整数の入力
	//int b, c;
	//cin >> b >> c;
	//// 文字列の入力
	//string s;
	//cin >> s;
	//// 出力
	//cout << (a + b + c) << " " << s << endl;


	int N;
	cin >> N;

	cout << (800 * N) - N / 15 * 200;
	return 0;
}

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

int main() {
  string S;
  
  cin >> S;
  
  if(S.at(2)==S.at(3) && S.at(4)==S.at(5)){
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
// #include <ext/pb_ds/assoc_container.hpp>
// #include <ext/pb_ds/tree_policy.hpp>
 
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,avx2,tune=native")
#pragma GCC optimize("-ffloat-store")
 
#define int  long long
#define rep(i,begin,end) for(__typeof(end)i=(begin)-((begin)>(end));i!=(end)-((begin)>(end));i+=1-2*((begin)>(end)))
#define F first
#define S second
#define sz(x) ((int)x.size())
#define pb push_back
#define pf push_front
#define eb emplace_back
#define all(v) (v).begin(), (v).end()
#define mod 1000000007
#define what_is(x) cerr << #x << " is " << x <<"\n";
#define sortA(v) sort(v.begin(), v.end())
#define sortD(v) sort(v.rbegin(), v.rend())
#define PI 3.14159265358979323846
#define vout(a) for(auto x:a) cout<<x<<" ";
#define INF 1000000000000000 //1e16
 
// #define ordered_set tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update>
 
 
// using namespace __gnu_pbds;
using namespace std;
 
using ll  = long long;
using vi  = vector<int>;
using vvi = vector<vi>;
using pii = pair<int,int>;
using vii = vector<pii>;
using mi  = multiset<int>;
using mii = multiset<pii>;
 
int lcm(int a,int b) {return (a*(b/__gcd(a,b)));}

int findSumofProduct(vi arr,int n) 
{ 
    int suffix_sum = arr[n - 1]; 
  
    // Finding product of array  
    // elements and suffix sum. 
    int res = 0; 
    for (int i = n - 2; i >= 0; i--)  
    { 
  
        res += ((suffix_sum%mod) * arr[i])%mod; 
        res%=mod;
  
        // finding suffix sum 
        suffix_sum += arr[i];
        suffix_sum%=mod; 
    } 
  
    return (res+mod)%mod; 
} 

void solve()
{
    int n,m,t,i,k,r,l,s,u,v,w,j,pos,sum=0,flag=0,count=0;
    string S,T,U; 
    int d;
    cin>>n;
    vi a(n);
    rep(i,0,n) cin>>a[i];
    cout<<findSumofProduct(a,n)%mod;
}


signed main()
{
    #ifndef ONLINE_JUDGE 
       freopen("input.txt","r",stdin);
       freopen("output.txt","w",stdout);
    #endif
    ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
    int t=1;
    // cin>>t;
    while(t--)
    {
        solve();
        if(t)cout<<"\n";
    }
    return 0;
}

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

static const int N=100;

int main()
{
    int n;
    int p[N+1],m[N+1][N+1];
    cin>>n;
    for(int i=1;i<=n;i++)
    {
        cin>>p[i-1]>>p[i];
    }
    for(int i=1;i<=n;i++)m[i][i]=0;
    for(int l=2;l<=n;l++)
    {
        for(int i=1;i<=n-l+1;i++)
        {
            int j=i+l-1;
            m[i][j]=(1<<21);
            for(int k=i;k<=j-1;k++)
            {
                m[i][j]=min(m[i][j],m[i][k]+m[k+1][j]+p[i-1]*p[k]*p[j]);
            }
        }
    }

    cout<<m[1][n]<<endl;
 	return 0;
}



Measured memory_bytes: 3116
#include <iostream>

using namespace std;

const int MAX_T = 100;
int K, T;
int max_a = 0;

void receiveInput(){
  cin >> K >> T;
  int a;
  for(int i = 0; i < T; i++){
    cin >> a;
    if(a > max_a){
      max_a = a;
    }
  }
  return ;
}

int solve(){
  if(max_a <= K / 2){
    return 0;
  }else{
    return 2*max_a - K - 1;
  }
}

int main(){
  receiveInput();
  cout << solve() << endl;
  return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
int main ()
{
int a, b, c;
scanf("%d%d%d",&a,&b,&c);
if (a>b && a>c)
{if (b>c){printf("%d %d %d\n",c,b,a);}
else{printf("%d %d %d\n",b,c,a);}}
if (b>c && b>a)
{if (a>c){printf("%d %d %d\n",c,a,b);}
else{printf("%d %d %d\n",a,c,b);}}
if (c>a && c>b)
{if (a>b){printf("%d %d %d\n",b,a,c);}
else{printf("%d %d %d\n",a,b,c);}}
return 0;
}

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

using namespace std;

typedef long long ll;

int main()
{
	int a,b,c;
	cin>>a>>b>>c;

	ll sum = a+b+c;

	ll maxi = max({a,b,c});

	//If the parity is same
	if(sum%2==maxi%2)
	{
		cout<<(3*maxi-sum)/2<<'\n';
	}
	else
	{
		cout<<(3*(maxi+1)-sum)/2<<'\n';
	}


	return 0;
}

Measured memory_bytes: 256
alphabet = ["A","B","C","D","E","F","G","H","I","J","K","L","M","N","O","P","Q","R","S","T","U","V","W","X","Y","Z"]
N = int(input())
S = input()
ans = ""
for i in range(len(S)):
  x = alphabet.index(S[i])
  if x + N >= 26:
    y = x + N -26
  else:
    y = x + N
  ans += alphabet[y]
print(ans)

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

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

typedef pair<int,int>Pi;
typedef pair<long long,long long>P;
typedef pair<long long,P>PP;
typedef pair<P,P>PPP;

const long long MOD=1e9+7;
const long long INF=5e18;
const int di[4]={1,0,-1,0};
const int dj[4]={0,1,0,-1};

#define fr first
#define sc second
#define pb push_back
#define eb emplace_back
#define ALL(x) (x).begin(),(x).end()
#define ALLR(x) (x).rbegin(),(x).rend()

string s;

void input(){
	cin>>s;
	return;
}

void solve(){
	if((int)(s[6]-'0')>4||(int)(s[5]-'0')==1){
        cout<<"TBD"<<endl;
    }
    else{
        cout<<"Heisei"<<endl;
    }
	return;
}

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

Measured memory_bytes: 256
#!/usr/bin/env python3

import math

H, W = map(int,input().split())
if H == 1 or W ==1:
    print(1)
elif H%2 == 0 and W%2 ==0:
    print(H//2 * W//2 *2)
elif H%2 == 1 and W%2 ==1:
    print(math.ceil(H*W/2))
else:
    print(H*W//2)

Measured memory_bytes: 38256
use std::io;

fn procon_read<T: std::str::FromStr>() ->  Vec<T> {
	let mut buf = String::new();
	io::stdin().read_line(&mut buf).expect("");
	let iter = buf.split_whitespace();
	let mut v: Vec<T> = Vec::new();
	for i in iter {
		v.push(i.parse().ok().unwrap());
	}
	v
}

fn main() {
	let v:Vec<i32> = procon_read();
	let r = v[0];
	let v:Vec<i32> = procon_read();
	let g = v[0];
	println!("{}", 2*g - r);
}

Measured memory_bytes: 4352
a,b,c,d,e,f = map(int, input().split(' '))

w = 0
s = 0
ratio = 0

for i in range((f // (b*100))+1):
    for j in range(((f-(i*b*100))//(a*100))+1):
        if i == 0 and j == 0:
            continue
        smax = min(f-(j*a+i*b)*100,(j*a+i*b)*e)
        sm = 0
        for k in range((smax//d)+1):
            sm = max(sm, k*d+c*((smax-(k*d))//c))
        if ratio <= sm/((j*a+i*b)*100+sm):
            ratio = sm/((j*a+i*b)*100+sm)
            w = (j*a+i*b)*100
            s = sm


print("%i %i" %(w+s,s))


Measured memory_bytes: 3064
#include<iostream>
using namespace std;
int main(){
  long long n,m,cnt=0;
  cin >> n >> m;
  if(n*2<=m){
    m-=n*2;
    cnt+=n;
  }else{
    cnt+=m/2;
    m=m%2;
  }
  if(m>=4){
    cnt+=m/4;
  }
  cout << cnt << endl;
 }


Measured memory_bytes: 256
#include <cstdio>

using namespace std;

int main () {
	int n;
	scanf("%d",&n);
	for (long long i=1;i<=3500;i++) {
		for (long long j=1;j<=3500;j++) {
			//printf("%lld\n",4*i*j-n*(i+j));
			if (4*i*j-n*(i+j)==0) continue;
			if ((n*i*j)%(4*i*j-n*(i+j))==0) {
				long long ans=(n*i*j)/(4*i*j-n*(i+j));
				if (ans<=0) continue;
				printf("%lld %lld %lld\n",i,j,ans);
				return 0;
			}
		}
	}
	return 0;
}


Measured memory_bytes: 128
// g++ -std=c++11 temp.cpp
#include <bits/stdc++.h>
using namespace std;

#define FOR(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define REP(i,n) FOR(i,0,n)
#define EACH(itr,v) for(auto itr:v)
#define pb(s) push_back(s)
#define mp(a,b) make_pair(a,b)
#define all(x) (x).begin(),(x).end()
#define dbg(x) cout<<#x"="<<x<<endl

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

#define INF INT_MAX/3

#define MAX_N 1000

int n,L;
int a[100000];
vector<int> ans;
int sum = 0;

int main(){
	cin>>n>>L;
	REP(i,n){
		cin>>a[i];
	}
	REP(i,n-1){
		if(a[i]+a[i+1]>=L){
			cout<<"Possible"<<endl;
			for(int j = 0; j < i; j++) cout<<j+1<<endl;
			for(int j = n-1; j > i; j--) cout<<j<<endl;
			return 0;
		}
	}
	cout<<"Impossible"<<endl;
	return 0;
}



Measured memory_bytes: 1152
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (n); i++)
#define repi(i, s, n) for (int i = (s); i < (n); i++)
#ifdef LOCAL
#define INPUT_FILE                    \
  ifstream in("abc175/abc175_c.txt"); \
  cin.rdbuf(in.rdbuf());
#define print_vec(v)                        \
  rep(l, v.size()) { cout << v[l] << " "; } \
  cout << endl;
#else
#define INPUT_FILE
#define print_vec(v)
#endif
#define CIN_OPTIMIZE \
  cin.tie(0);        \
  ios::sync_with_stdio(false);
typedef pair<int, int> P;
typedef long long ll;
typedef pair<ll, ll> pl;
const int INF = 100100100;
const ll LINF = 1e18 + 100;
const int MOD = 1e9 + 7;

int main() {
  INPUT_FILE CIN_OPTIMIZE;

  ll X, K, D;
  cin >> X >> K >> D;

  ll ans = 0;

  X = abs(X);
  ll n = min(K, X / D);

  K -= n;
  X -= n * D;

  if (K % 2 == 0) {
    cout << X << endl;
  } else {
    cout << D - X << endl;
  }

  return 0;
}

Measured memory_bytes: 3628
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#include <limits.h>
#include <map>
#include <vector>
#include <deque>
#include <list>
#include <stack>
#include <queue>
#include <set>
#include <algorithm>
#include <iostream>
#include <iterator>
#include <memory>

using namespace std;

#if 1
#define PRINT(x) { cout << #x << ": " << (x) << endl; }
#define PRINT_CONTAINER(x)  { cout << #x << ": ";                       \
        for (size_t ix = 0; ix < (x).size(); ++ix) cout << (x)[ix] << ", "; \
        cout << endl; }
#else
#define PRINT(x)
#define PRINT_CONTAINER(x)
#endif

typedef pair<int, int> p;

int n;
vector<int> a;
vector<int> b;

int main(int argc, char *argv[]) {
    scanf("%d", &n);
    int total = 0;
    a.push_back(0);
    for (int i = 0; i < n; ++i) {
        int tmp;
        scanf("%d", &tmp);
        a.push_back(tmp);
        total += abs(tmp - a[i]);
    }
    total += abs(a.back());
    a.push_back(0);
    for (int i = 1; i <= n; ++i) {
        int d = abs(a[i + 1] - a[i]) + abs(a[i] - a[i - 1]) - abs(a[i + 1] - a[i - 1]);
        printf("%d\n", total - d);
    }
    return 0;
}


Measured memory_bytes: 1784