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

int main()
{
    int rot;
    string str;
    cin >> rot >> str;

    for (string::iterator ptr = str.begin(); ptr != str.end(); ptr++)
    {
        char ch = ((char)*ptr - (char)'A' + rot) % 26 + 'A';
        cout << ch;
    }
    cout << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int n,m,dp[1001][1001];

int main(){
	cin >> n >> m;
	dp[0][1] = 1;
	for(int i = 1 ; i <= n ; i += 1){
		for(int j = 1 ; j <= m ; j += 1){
			char a;
			cin >> a;
			if(a == '.'){
				dp[i][j] = dp[i-1][j]+dp[i][j-1];
				if(dp[i][j] >= 1000000007){
					dp[i][j] -= 1000000007;
				}
			}
		}
	}
	cout << dp[n][m] << endl;
}

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

int main()
{
   int n;
   cin>>n;
   vector<long long>a(n);
   int i;
   for(i=0;i<n;i++)
   cin>>a[i];
   sort(a.begin(),a.end());
   long long sum=0;
   long temp=n/2;
   if(n%2==0)
   temp--;
   int index=n-1;
   while(temp--)
   {
    //   cout<<a[index]<<" ";
       sum+=a[index];
       index--;
   }
//   cout<<endl;
   index=n-2;
   temp=n/2;
   if(n%2==0)
   temp--;
   while(temp--)
   {
       sum+=a[index];
       index--;
   }
   index++;
   if(n%2==0)
   sum+=a[index];
   cout<<sum<<endl;
}

Measured memory_bytes: 4840
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> l_l;
typedef pair<int, int> i_i;
template<class T>
inline bool chmax(T &a, T b) {
    if(a < b) {
        a = b;
        return true;
    }
    return false;
}

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

#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
//const ll mod = 1000000007;
int N;
ll A[205000], B[205000];
priority_queue<l_l> que;

void add(int i) {
    if(A[i] == B[i]) return;
    ll a = B[(i+1)%N];
    chmax(a, B[(i+N-1)%N]);
    if(a <= B[i]) {
        que.push({B[i] - a, i});
    }
    return;
}

int main() {
    //cout.precision(10);
    cin.tie(0);
    ios::sync_with_stdio(false);
    cin >> N;
    for(int i = 0; i < N; i++) cin >> A[i];
    for(int i = 0; i < N; i++) cin >> B[i];
    for(int i = 0; i < N; i++) {
        if(B[i] < A[i]) {
            cout << -1 << endl;
            return 0;
        }
        add(i);
        /*
        ll a = B[(i+N-1)%N];
        chmin(a, B[(i+1)%N]);
        if(B[i] >= a) {
            que.push({B[i] - a, i});
        }
        */
    }
    ll ans = 0;
    while(!que.empty()) {
        l_l now = que.top();
        que.pop();
        int i = now.second;
        ll val = B[(i+N-1)%N] + B[(i+1)%N];
        ll num = B[i] / val;
        chmin(num, (B[i] - A[i]) / val);
        //cerr << i << " " << val << " " << num << endl;
        if(num == 0 && A[i] != B[i]) {
            cout << -1 << endl;
            return 0;
        }
        if(num == 0) continue;
        ans += num;
        B[i] -= val * num;
        add((i + 1) % N);
        add((i + N - 1) % N);
    }
    for(int i = 1; i <= N; i++) {
        if(A[i] != B[i]) {
            cout << -1 << endl;
            return 0;
        }
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 5620
#include <iostream>
#include <cstdio>

using namespace std;

long long int DP[5][10000];

int main(){
	
	long long int n, ans;
	
	for(int i = 0; i < 5; i++){
		for(int j = 0; j < 10000; j++){
			DP[i][j] = 0;
		}
	}
	
	DP[0][0] = 1;
	
	for(int i = 1; i < 5; i++){
		for(int j = 0; j < 10000; j++){
			for(int k = max(0, j - 1000); k <= j; k++){
				DP[i][j] += DP[i - 1][k];
			}
		}
	}
	
	while(true){
		cin >> n;
		if(cin.eof()){
			break;
		}
		cout << DP[4][n] << endl;
	}
	
	return 0;
}

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

int main(){
    long long x;
    scanf("%lld", &x);
    long long ans = 0;
    long long sum = 100;
    while(1){
        sum += sum * 0.01;
        ans++;
        if(sum >= x)break;
    }
    printf("%lld\n", ans);



}

Measured memory_bytes: 3832
#include <iostream>
#include <cstdlib>
#include <algorithm>
#include <cmath>
#include <vector>
#include <numeric> // accumulate(v.begin(), v.end(), 0)

using namespace std;
#define ll long long

int main(){
  string S;
  cin >> S;
  int count = 0;
  for(int i=1; i<S.size(); i++)
    if(S[i] != S[i-1])
      count++;
  cout << count << endl;
  return 0;
}


Measured memory_bytes: 512
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<queue>
#include<map>
#include<math.h>
#include<iomanip>
#include<set>
#include<numeric>
#include<cstring>
#include<cstdio>
#include<functional>
#include<bitset>
#include<limits.h>
#include<cassert>
#include<iterator>
#include<complex>
#include<stack>
#include<sstream>
using namespace std;
typedef  long long int lint;
typedef pair<int, int> IP;
typedef pair<lint, lint> LLP;
typedef pair<char, char>CP;
#define rep(i, n) for (int i = 0; i < n; i++)
#define repr(i, n) for (int i = n; i >= 0; i--)
#define sort(v) sort((v).begin(), (v).end())
#define reverse(v) reverse((v).begin(), (v).end())
#define upper(v,hoge) upper_bound(v.begin(),v.end(),hoge)
#define lower(v,hoge) lower_bound(v.begin(),v.end(),hoge)
#define llower(v,hoge) *lower_bound(v.begin(), v.end(), hoge)
#define lupper(v,hoge) *upper_bound(v.begin(), v.end(), hoge)
const lint MOD = pow(10, 9) + 7;

int main() {
	int N;
	cin >> N;
	deque<int>A;
	int a = 0;
	rep(i, N) {
		cin >> a;
		A.push_back(a);
	}
	vector<int>V;
	rep(i, N) {
		a = A.front();
		A.pop_front();
		V.push_back(a);
		sort(V);
		rep(i, V.size()) {
			cout << V[i];
			if (i != N - 1) {
				cout << ' ';
			}
		}
		rep(i, A.size()) {
			cout << A[i];
			if (i != A.size() - 1) {
				cout << " ";
			}
		}
		cout << endl;
	}
}


Measured memory_bytes: 3164
#include <iostream>

int gcd(int x, int y) {
  do {
    if (x < y)
      std::swap(x, y);
    x = x % y;
  } while (x != 0);
  return y;
}

int main() {
  int x, y;
  std::cin >> x >> y;
  std::cout << gcd(x, y) << std::endl;
}



Measured memory_bytes: 3104
#include <bits/stdc++.h>
#define ll long long
#define ford(i,a,b) for(int i=(a);i>=b;i--)
#define rep(i,a,b) for(int i=(a);(i)<(b);(i)++)
#define mpi map<int,int>
#define N 200005
#define pql priority_queue<ll>
#define all(v) (v).begin(),(v).end()
#define rall(v) (v).rbegin(),(v).rend()
using namespace std;
ll n,k,ans;
int main() {
	cin>>n>>k;
	for(ll i=k;i<=n+1;i++){
		ans+=i*(n-i+1+n)/2-i*(i-1)/2+1;
	}
	cout<<ans%1000000007;
	return 0;
}


Measured memory_bytes: 3636
#include <iostream>

using namespace std;

int main(){
    char S[5];
    int a=0,b=0;
    cin >>S;
    if(S[0]==S[1]){
        a++;
        if(S[0]==S[2]){
            cout <<"No"<<endl;
        }else{
            if(S[2]==S[3]){
                cout <<"Yes"<<endl;
            }else{
                cout <<"No"<<endl;
            }
        }
    }
    else{
        if(S[0]==S[2]){
            if(S[1]==S[3]){
                cout <<"Yes"<<endl;
            }else
            {
                cout <<"No"<<endl;
            }
            
        }else{
            if(S[1]==S[2]){
                if(S[0]==S[3]){
                    cout <<"Yes";
                }else{
                    cout <<"No";
                }
            }else{
                if(S[0]==S[2]){
                    cout <<"Yes";
                }
                else{
                    cout <<"No";
                }
            }
        }
    }
}

Measured memory_bytes: 256
#include<cstdio>
#include<iostream>
#include<cmath>

using namespace std;

int main(){
    long int a, b;
    cin >> a >> b;
    long int bin = 0;
    long int x = pow(2, 40);
    for(int i = 0; i < 40; i++){
        bin <<= 1;
        if (i != 39) {
            if (a / x != b / x) {
                long int dela = (a % x);
                long int delb = ((b + 1) % x);
                long int num = 0;
                if (dela <= (x / 2)) {
                    num += x / 2;
                }else{
                    num += x - dela;
                }
                if (delb > (x / 2)) {
                    num += delb - (x / 2);
                }
                if (num % 2 != 0) {
                    bin += 1;
                }
                x /= 2;
                // cout << num << '\n';
                // cout << bin << '\n';
            }else{
                long int dela = (a % x);
                long int delb = ((b + 1) % x);
                long int num = 0;
                if (delb > (x / 2)) {
                    num += delb - (x / 2);
                }
                if (dela > (x / 2)) {
                    num -= dela - (x / 2);
                }
                
                if (num % 2 != 0) {
                    bin += 1;
                }
                x /= 2;
                // cout << num << '\n';
                // cout << bin << '\n';      
            }
        }else{
            if ((b - a + 1) % 4 == 1) {
                if (a % 2 == 1) {
                    bin += 1;
                }
            }else if ((b - a + 1) % 4 == 2) {
                bin += 1;
            }else if ((b - a + 1) % 4 == 3) {
                if (a % 2 == 0) {
                    bin += 1;
                }
            }
            
            
            
            
        }
        

        

        
    }
    cout << bin << '\n';
    
}

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

int main()
{
unsigned long long int n,a,b,ans;
cin>>n>>a>>b;

ans=0;
if(a!=0){

unsigned long long int mod=n%(a+b);
ans+=(mod<a?mod:a);
ans+=((n-mod)/(a+b))*a;
}

cout<<ans<<endl;

    return 0;
}

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

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

#define endl '\n'
#define ff first
#define ss second
#define int long long
#define pb push_back
#define f(i,l,r) for(ll i=l;i<=r;i++)
#define rf(i,r,l) for(ll i=r;i>=l;i--)
#define Max 5000001
#define inf 2147483647
#define llinf 9223372036854775807
#define all(v) v.begin(),v.end()
#define bp(n) __builtin_popcountll(n)
#define fast ios_base::sync_with_stdio(false),cin.tie(NULL),cout.tie(NULL)

#define d0(a) cout<<a<<' ';
#define d1(a) cout<<a<<endl;
#define d2(a,b) cout<<a<<' '<<b<<endl;
#define d3(a,b,c) cout<<a<<' '<<b<<' '<<c<<endl;
#define d4(a,b,c,d) cout<<a<<' '<<b<<' '<<c<<' '<<d<<endl;
#define d5(a,b,c,d,e) cout<<a<<' '<<b<<' '<<c<<' '<<d<<' '<<e<<endl;
#define d6(a,b,c,d,e,f) cout<<a<<' '<<b<<' '<<c<<' '<<d<<' '<<e<<' '<<f<<endl;

const ll N=100,mod=1e9+7,bit=61;
const ld PI=acos(-1.00);

ll a,b,n;

ll fun(ll x)
{
    assert(x<=n);
    ll ans=((a*x)/b)-a*(x/b);
    return ans;
}

signed main()
{
    fast;

    ll t=1;
    //cin>>t;
    while(t--)
    {
        scanf("%lld %lld %lld",&a,&b,&n);
        ll ans=0;
        f(i,0,5000000)
        {
            ll x=i;
            ll k=min(b*x+b-1,n);
            ans=max(ans,fun(k));
        }
        printf("%lld\n",ans);
    }
    return 0;
}


















Measured memory_bytes: 3816
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<cmath>
#include<iostream>
#include<vector>
using namespace std;
const long long p=1000000007;
inline int cmp(pair<int,int> a,pair<int,int> b){
    if(a.first!=b.first){
    	return a.first<b.first;
	}
    return a.second>b.second;
}
int n,m,t,t2;
int a[100003],b[100003],d[100003];
pair<int,int> c[100003];
long long e[100003];
inline long long add(long long a,long long b){
    a+=b;
    return a>=p?a-p:a;
}
inline void add(int x,long long v){
    for(;x<=t2;x+=x&-x){
    	e[x]=add(e[x],v);
	}
}
inline long long sum(int x){
    long long s=0;
    for(;x;x-=x&-x){
    	s=add(s,e[x]);
	}
    return s;
}
int main(){
	cin>>n>>m;
    for(int i=1;i<=n;i++){
    	cin>>a[i];
	}
    for(int i=1;i<=m;i++){
    	cin>>b[i];
	}
    for(int i=1;i<=n;i++){
    	 if(a[i]>b[1]&&a[i]<b[m]){
            int x=lower_bound(b+1,b+m+1,a[i])-b;
            if(b[x]==a[i]){
            	continue;
			}
            c[++t]=pair<int,int>(a[i]-b[x-1],b[x]-a[i]);
            d[++t2]=b[x]-a[i];
        }
	}
    sort(d+1,d+t2+1);
    t2=unique(d+1,d+t2+1)-d-1;
    for(int i=1;i<=t;i++){
    	c[i].second=lower_bound(d+1,d+t2+1,c[i].second)-d;
	}
    sort(c+1,c+t+1,cmp);
    t=unique(c+1,c+t+1)-c-1;
    long long ans=1;
    for(int i=1;i<=t;i++){
        long long s=sum(c[i].second-1)+1;
        ans+=s;
        add(c[i].second,s);
    }
    ans%=p;
    cout<<ans%p<<endl;
    return 0;
}

Measured memory_bytes: 2560
#include <string.h>
#include <algorithm>
#include <queue>
#include <iostream>
#include <stdio.h>
#include <string>
#include <math.h>
using namespace std;
typedef long long int ll;
int pos = 1;
void change()
{
    const string path = "C:\\Users\\www34\\Desktop\\data_oi\\temp";
    string p, o;
    if (pos < 10)
    {
        p = path + "\\" + (char)(pos + '0') + ".in";
        o = path + "\\" + (char)(pos + '0') + ".out";
    }
    else
    {
        p = path + "\\" + "10" + ".in";
        o = path + "\\" + "10" + ".out";
    }
    pos++;
    freopen(&p[0], "r", stdin);
    //    freopen(&o[0], "w", stdout);
}
int a[2000], b[2000];
int dp[10000 + 5];
int main()
{
    int t = 1;
    while (t--)
    {
        //  change();
        int n, h;
        cin >> h >> n;
        for (int i = 1; i <= n; i++)
            cin >> a[i] >> b[i];
        for (int i = 1; i <= 10000; i++)
            dp[i] = 1e9;
        for (int i = 1; i <= n; i++)
        {
            for (int j = 1; j <= h; j++)
            {
                if (j - a[i] >= 0)
                    dp[j] = min(dp[j - a[i]] + b[i], dp[j]);
                else

                    dp[j] = min(dp[j], b[i]);
            }
        }
        cout << dp[h] << endl;
    }
    return 0;
}
/*
3
3 2 1
1 2 3 
*/

Measured memory_bytes: 888
#include <bits/stdc++.h>
#include <assert.h>
using namespace std;
using i64 = long long;

int main()
{
  i64 n;
  cin >> n;
  i64 ans = 1e18;
  for (i64 i = 1; i <= sqrt(n); i++)
    if (n % i == 0)
      ans = min(ans, i + n / i);
  cout << ans - 2 << endl;
  return 0;
}


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

int main(){
  long n; cin >> n;
  vector<vector<int>> a(n, vector<int>(60, 0));
  for(int i = 0; i < n; i++){
    long long A; cin >> A;
    for(int j = 0; j < 60; j++){
      if((A >> j) & 1) a.at(i).at(j) = 1;
    }      
  }
  vector<long> out(60);
  for(int i = 0; i < 60; i++){
    long sum = 0;
    for(int j = 0; j < n; j++){
      if(a.at(j).at(i) == 1) sum++;
    }
    out.at(i) = sum;
  }
  vector<long long> out2(60);
  for(int i = 0; i < 60; i++){
    out2.at(i) = out.at(i) * (n - out.at(i));
  }
  long long res = 0;
  long long two = 1;
  for(int i = 0; i < 60; i++){
    res += ((out2.at(i) % 1000000007) * (two % 1000000007)) % 1000000007;
    two *= 2;
    two = two;
  }
  cout << res % 1000000007;
}


Measured memory_bytes: 84352
#include <bits/stdc++.h>
using namespace std;
using vi = vector<int>;
using vb = vector<bool>;
using vc = vector<char>;
using vs = vector<string>;
using vvi = vector<vector<int>>;
using vvc = vector<vector<char>>;
using pii = pair<int, int>;
#define fix10 cout << fixed << setprecision(10);
#define rep(i,n) for(int i=0; i<(int)(n);i++)
#define MOD 1000000007
//ostringstream ss;
//ss << setw(6) << setfill('0') << ken;
//string s(ss.str());

int main(){
  int n,m;
  cin >> n >> m;
  vector<pii> data(m);
  vector<pii> copy(m);
  map<pii,string> mp;
  rep(i,m){
    cin >> data.at(i).first >> data.at(i).second;
    copy.at(i).first = data.at(i).first;
    copy.at(i).second = data.at(i).second;
  }
  sort(copy.begin(),copy.end());
  int num = 1;
  rep(i,m){
    int ken = copy.at(i).first;
    if(i == 0){
      ostringstream ss;
      ss << setw(6) << setfill('0') << ken;
      //string s(ss.str());
      ss << setw(6) << setfill('0') << num;
      string s(ss.str());
      mp[copy.at(i)] = s;
      num++;
      continue;
    }
    if(ken != copy.at(i-1).first) num = 1;
    ostringstream ss;
    ss << setw(6) << setfill('0') << ken;
    //string s(ss.str());
    ss << setw(6) << setfill('0') << num;
    string s(ss.str());
    mp[copy.at(i)] = s;
    num++;
  }
  rep(i,m){
    cout << mp.at(data.at(i)) << endl;
  }
}


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

int a, b, c, k;

int main() {
	cin >> a >> b >> c >> k;
	if (k <= a)
		cout << k << endl;
	else if (k <= a + b)
		cout << a << endl;
	else
		cout << a - (k - a - b) << endl;
}


Measured memory_bytes: 3520
N = int(input())
A = list(map(int, input().split()))

c = 0
for i in range(N):
    if i+1 == A[i]:
        if i == N-1:
            c += 1
            break
        a, b = A[i], A[i+1]
        A[i] = b
        A[i+1] = a
        c += 1
print(c)

Measured memory_bytes: 14008
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <climits>
#include <cmath>
#include <map>
#include <queue>
#include <iomanip>
using namespace std;
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++ )
#define repf(i,m,n) for(int (i)=m;(i)<n;(i)++)
#define all(v) (v).begin(), (v).end()
#define ll long long
#define vec(name,num) vector<ll> name((num),0);
#define op(i) cout<<(i)<<endl;
#define ip(i) cin>>(i);
#define opN cout<<"No"<<endl;
#define opY cout<<"Yes"<<endl;
#define opP cout<<"Possible"<<endl;
#define opI cout<<"Impossible"<<endl;
#define mat(name,fnum,snum); vector<vector<ll>> name((fnum),vector<ll>((snum),0));
#define matC(name,fnum,snum); vector<vector<char>> name((fnum),vector<char>((snum),0));
#define debugP int debug_point; cin>>debug_point;
#define FI first
#define SE second
const ll MOD= 1e9 + 7;
template <typename T>
void putv(vector<T>& V){
	// cout << "The elements in the vector are: " << endl;
	for(auto x: V)
		cout << x << " ";
	cout << endl;
}
ll pow_mod(ll fi,ll se,ll mod){
  if(se==0){
    return 1;
  }
  if(se%2){
    return pow_mod(fi,se-1,mod)*fi%mod;
  }
  ll t=pow_mod(fi,se/2,mod);
  return t*t%mod;
}
template <class T>
vector<T> getv(ll n){
	vector<T> Vector_temp;
	rep(i,n){
		T input;
		cin >> input;
		Vector_temp.emplace_back(input);
	}
	return Vector_temp;
}
ll gcd(ll c,ll b){
    while(1){
        if(c%b!=0){
        ll tmp=b;
        b=c%b;
        c=tmp;
        }else{
            return b;
        }
    }
}

vector<pair<int,int>> Dir={{-1,0},{1,0},{0,1},{0,-1}};
/* <3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3*/

bool isOK(ll idx,ll key,vector<ll>& a){
  if(a[idx]>=key)return true;
  return false;
}

ll binary_search(ll key,ll s,ll g,vector<ll>& a){
  ll ng=s-1;
  ll ok=(ll)g;
  while(abs(ok-ng)>1){
    ll mid=(ok+ng)/2;
    if(isOK(mid,key,a)) ok=mid;
    else ng=mid;
  }
  return ok;
}

int main(){
  ll n,m;
  cin>>n>>m;
  vec(a,n);
  vector<pair<ll,ll>> p(m);
  rep(i,n){
    cin>>a[i];
  }
  rep(i,m){
    cin>>p[i].second>>p[i].first;
  }
  sort(all(p));
  sort(all(a));
  ll s=0;
  ll g=a.size();
  ll ans=0;
  for(ll i=m-1;i>=0;i--){
    ll tmp=binary_search(p[i].first,s,g,a);
    if(tmp!=0){
      ans+=p[i].first*min(tmp-s,p[i].second);
      s=min(tmp,s+p[i].second);
      
    }else break;
  }
  repf(i,s,g){
    ans+=a[i];
  }
  op(ans);
  return 0;
}


Measured memory_bytes: 2560
import sys
from math import gcd
from functools import reduce
import numpy as np
    
read = sys.stdin.read
readline = sys.stdin.buffer.readline
sys.setrecursionlimit(10 ** 8)
INF = float('inf')
MOD = 10 ** 9 + 7


def lcm_base(a, b):
    return (a * b) // gcd(a, b)


def lcm_list(numbers):
    return reduce(lcm_base, numbers, 1)


def main():
    n, m = map(int, readline().split())
    a = np.array(input().split(), np.int64)
    a //= 2
    b = np.copy(a)
    while True:
        c = b % 2
        if c.sum() == 0:
            b //= 2
        elif c.sum() == n:
            break
        else:
            print(0)
            sys.exit()
    d = lcm_list(a)
    if d > 10 ** 9:
        ans = 0
    else:
        ans = (m // d) - (m // (d + d))
    print(ans)


if __name__ == '__main__':
    main()


Measured memory_bytes: 39688
#include<cstdio>
#include<cmath>
using namespace std;
const int M=1000000007;
int n,m;
long long ans=1;
int main(){
	scanf("%d%d",&n,&m);
	if(abs(n-m)>1){
		printf("0\n");
		return 0;
	}
	for(int i=1;i<=n;++i)ans=ans*i%M;
	for(int i=1;i<=m;++i)ans=ans*i%M;
	if(n!=m)printf("%lld\n",ans);
	else printf("%lld\n",2*ans%M);
	return 0;
}

Measured memory_bytes: 3188
a, b, c = map(int, input().split())
A = abs(b-c)
B = abs(a-c)
C = abs(a-b)
a = B+C
b = A+C
c = A+B

if a > b:
	if b > c:
		print(c)
	else:
		print(b)
else:
	if a > c:
		print(c)
	else:
		print(a)

Measured memory_bytes: 3064
#!/usr/bin/env python3
#ABC59 C
n = int(input())
a = list(map(int,input().split()))

ans1 = 0
s1 = 0
for i in range(n):
    s1 += a[i]
    if i % 2 == 0:
        if s1 > 0:
            continue
        else:
            ans1 += 1 - s1
            s1 = 1
    else:
        if s1 < 0:
            continue
        else:
            ans1 += s1 + 1
            s1 = -1
ans2 = 0
s2 = 0
for i in range(n):
    s2 += a[i]
    if i % 2 == 0:
        if s2 < 0:
            continue
        else:
            ans2 += s2 + 1
            s2 = -1
    else:
        if s2 > 0:
            continue
        else:
            ans2 += 1 - s2
            s2 = 1

print(min(ans1,ans2))


Measured memory_bytes: 63216
<?php
//error_reporting(0);
//$N = trim(fgets(STDIN));
list($N,$K) =  explode(" ",trim(fgets(STDIN)));

$ret = 0.0;
for($i=1;$i<=$N;$i++) {
  $tmp = 1.0/$N;
  $now = $i;
  while($now<$K) {
    $now*=2;
    $tmp/=2;
  }
  $ret+=$tmp;
}
printf("%.12f\n",$ret);


Measured memory_bytes: 4728
import java.util.Scanner;

public class Main {

	public static void main(String args[]) {

		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int K = sc.nextInt();

		if(K == 1) System.out.println(0);
		else System.out.println(N-K);
	}
}

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

typedef long long int int64;

int cmp(const void *a,const void *b){
  return *(int *)a-*(int *)b;
}

void run(void){
  int n,m;
  scanf("%d%d",&n,&m);
  int *x=(int *)calloc(m,sizeof(int));
  int i;
  for(i=0;i<m;i++) scanf("%d",x+i);
  qsort(x,m,sizeof(int),cmp);
  int *y=(int *)calloc(m-1,sizeof(int));
  for(i=0;i<m-1;i++) y[i]=x[i+1]-x[i];
  qsort(y,m-1,sizeof(int),cmp);
  int64 ans=0;
  for(i=0;i<m-n;i++) ans+=y[i];
  printf("%lld\n",ans);
}

int main(void){
  run();
  return 0;
}


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

int main(){
  int H,W;cin >> H >> W;
  vector<vector<int>> A(H,vector<int>(W));
  for(int i=0;i<H;i++){
    for(int j=0;j<W;j++){
      cin >> A[i][j];
    }
  }
  int N = 0;
  vector<vector<int>> OP(H*W,vector<int>(4));
  for(int i=0;i<H;i++){
    for(int j=0;j<W-1;j++){
      if(A[i][j]%2>0){
        OP[N][0]=i;
        OP[N][1]=j;
        OP[N][2]=i;
        OP[N][3]=j+1;
        N ++;
        A[i][j] --;
        A[i][j+1] ++;
      }
    }
    if(i<H-1&&A[i][W-1]%2>0){
      OP[N][0]=i;
      OP[N][1]=W-1;
      OP[N][2]=i+1;
      OP[N][3]=W-1;
      N ++;
      A[i][W-1] --;
      A[i+1][W-1] ++;
    }
  }
  cout << N << endl;
  for(int i=0;i<N;i++){
    cout << OP[i][0]+1 << " " << OP[i][1]+1 << " " << OP[i][2]+1 << " " << OP[i][3]+1 << endl;
  }
}

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

const int N = 200005;

int n, a[N], b[N];
long long ans = 0;
queue<int> q;

int adj(int u)
{
    return b[(u + n - 1) % n] + b[(u + 1) % n];
}

bool check(int u)
{
    return b[u] - adj(u) >= a[u];
}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    cin >> n;
    for (int i = 0; i < n; i++)
        cin >> a[i];
    for (int i = 0; i < n; i++)
    {
        cin >> b[i];
        if (check(i))
            q.push(i);
    }
    while (!q.empty())
    {
        int ind = q.front(); q.pop();
        int tmp = (b[ind] - (a[ind] > b[ind] % adj(ind) ? a[ind] : 0)) / adj(ind);
        b[ind] -= adj(ind) * tmp;
        ans += tmp;
        if (check((ind + n - 1) % n))
            q.push((ind + n - 1) % n);
        if (check((ind + 1) % n))
            q.push((ind + 1) % n);
    }
    for (int i = 1; i <= n; i++)
        if (b[i] != a[i])
            return cout << -1, 0;
    cout << ans;
}


Measured memory_bytes: 2944
#include <cstdio>
#define ll long long 
ll a,b;
ll mcd (ll a,ll b) 
{
       ll  temp; 
       while(b!=0)          
       {
               temp=a%b;
               a=b;            
               b=temp;
       }
       return a;            
}
 
ll lcm( ll a,ll b ) 
{
       return a/mcd(a,b)*b ;
}
 
int main()
{
	ll ans=1;int n;ll last;
	scanf("%d",&n);
	for (int i=1;i<=n;i++)
    {
    	scanf("%lld",&a);
    	ans=lcm(ans,a);
    }
    printf("%lld",ans);
}

Measured memory_bytes: 128
// Shinchan Loves Coding :)))
#include<bits/stdc++.h>
#include<map>
#include<set>
#include<stack>
using namespace std;

#define night_rider ios::sync_with_stdio(false);cin.tie(NULL);
#define int long long int
#define double long double
#define en "\n"
#define fi first
#define se second
#define MP make_pair
#define PB push_back
#define all(v) v.begin(),v.end()
#define allr(v) v.rbegin(),v.rend()
#define toUpper(x) transform(x.begin(), x.end(), x.begin(),::toupper);
#define toLower(x) transform(x.begin(), x.end(), x.begin(),::tolower);
typedef vector<int> vi;
typedef vector<vector<int>> vii;
typedef pair<int,int> pi;
typedef vector<pair<int,int>> pii;
bool secdes(const pair<int,int>&a , const pair<int,int>&b){if(a.se==b.se){return a.fi>b.fi;}else{return a.se>b.se;}}//second descending !
bool sir(const pair<int,int>&a , const pair<int,int>&b){if(a.fi==b.fi){return a.se>b.se;}else{return a.first>b.first;}}//first descending !
bool bysec(const pair<int,int>&a , const pair<int,int>&b){if(a.se==b.se){return a.fi<b.fi;} else{return a.se<b.se;}}//second ascending !

/*--------------------------------------------------------------------------------------------------------------------------------------------------------------*/

const int no=3e6+5;
const int modulo=1e9+7;
const int inf=1e18+9;
const int N=1001;
int a[no]={},b[no]={},cc[no]={},suma[no]={},mat[N][N]={{0}};
stack<int> S;
stack<int> ma;

/*--------------------------------------------------------------------------------------------------------------------------------------------------------------*/

int poww(int x, int y, int modulo) { int res=1;while(y) { if(y%2!=0) { res*=x;res%=modulo;y--; } else { x*=x;x%=modulo;y/=2; } } return res; }  //MODULAR EXPONENTIATION
bool comp(int a, int b) {
    return (a < b);   // MAXIMUM
    return (a > b);   // MINIMUM
}

/*--------------------------------------------------------------------------------------------------------------------------------------------------------------*/

vi adj[no],prime;
int used[no]={},q=1,t=1;
int dist[no]={},c_comp[no]={},siz;

void dfs(int node,int d) {
    used[node]=1;
    dist[d]+=1;
    for(int v : adj[node]) {
        if(!used[v]) {
            dfs(v,d+1);
        }
    }
}

/**/
void solve (){
    int n,x,m;
    string s;
    cin>>s;
    int res=0;
    for(int i=0 ; i<s.size() ; i++) {
        res+=(s[i]-'0');
    }
    if(res%9) cout<<"No"<<en;
    else cout<<"Yes"<<en;
}

void runn(){
        #ifndef ONLINE JUDGE
        freopen("input.txt","r",stdin);
        freopen("output.txt","w",stdout);
        #endif
    }

signed main()
{
    night_rider
    //runn();
    t=1;
    //cin>>t;
    q=t;
    while(t--){
        solve();
    }
}


Measured memory_bytes: 74092
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.StringTokenizer;

public class Main {
    int n;

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

    void run() {
        FastReader sc = new FastReader();
        n = sc.nextInt();
        solve();
    }

    void solve() {
        long[] dp = new long[n + 1];
        dp[0] = 2;
        dp[1] = 1;
        for (int i = 2; i <= n; i++) {
            dp[i] = dp[i - 1] + dp[i - 2];
        }
        System.out.println(dp[n]);
    }

    static class FastReader {
        BufferedReader br;
        StringTokenizer st;

        public FastReader() {
            br = new BufferedReader(new
                    InputStreamReader(System.in));
        }

        String next() {
            while (st == null || !st.hasMoreElements())
            {
                try
                {
                    st = new StringTokenizer(br.readLine());
                }
                catch (IOException e)
                {
                    e.printStackTrace();
                }
            }
            return st.nextToken();
        }

        int nextInt()
        {
            return Integer.parseInt(next());
        }

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

        double nextDouble()
        {
            return Double.parseDouble(next());
        }

        String nextLine() {
            String str = "";
            try
            {
                str = br.readLine();
            }
            catch (IOException e)
            {
                e.printStackTrace();
            }
            return str;
        }
    }
}


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

long sadness(int N, vector<long>& A, long b) {
  long ans = 0;
  for (int i = 0; i < N; i++) {
    ans += abs(A[i] - (b + i + 1));
  }
  return ans;
}

int main() {
  int N;
  cin >> N;
  vector<long> A(N), B(N);
  for (int i = 0; i < N; i++) {
    cin >> A[i];
    B[i] = A[i] - i - 1;
  }
  sort(B.begin(), B.end());
  cout << sadness(N, A, B[N/2]) << endl;
}

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

using namespace std;
#define ll long long
#define sint(a) scanf("%d",&a)
#define sint2(a,b) scanf("%d %d",&a,&b)
#define sll(a) scanf("%lld",&a)
#define sll2(a,b) scanf("%lld %lld",&a,&b)
#define mem(a,i) memset(a,i,sizeof(a))
#define pb push_back
const double pi=acos(-1);
const int mod=1e9+7;
const int maxn=1e6+10;
//int a[maxn],sum;
//int d[maxn];
//int c;
//int dfs(int v,int k)
//{
//    if(k==s)
//    {
//
//    }
//    for(int i=v+1;i<sum;i++)
//    {
//        if(a[v]+c<a[i])
//        {
//            b[i]=1;
//            dfs(a[i],k+1);
//            b[i]=0;
//        }
//
//    }
//}

int main()
{
    ll n,k;
    sll2(n,k);
    printf("%lld",min(n%k,abs(n%k-k)));
    return 0;
}


Measured memory_bytes: 256
#pragma GCC optimize("Ofast")
#include<bits/stdc++.h>
//#include<boost/multiprecision/cpp_int.hpp>
//#include<boost/multiprecision/cpp_dec_float.hpp>
//namespace mp=boost::multiprecision;
//#define mulint mp::cpp_int
//#define mulfloat mp::cpp_dec_float_100
using namespace std;
struct __INIT{__INIT(){cin.tie(0);ios::sync_with_stdio(false);cout<<fixed<<setprecision(15);}} __init;
#define max3(a,b,c) max(a,max(b,c))
#define min3(a,b,c) min(a,min(b,c))
constexpr int MOD=1000000007;
//constexpr int MOD=998244353;
#define INF (1<<30)
#define LINF (lint)(1LL<<56)
#define endl "\n"
#define rep(i,n) for(lint (i)=0;(i)<(n);(i)++)
#define reprev(i,n) for(lint (i)=(n-1);(i)>=0;(i)--)
#define Flag(x) (1<<(x))
#define Flagcount(x) __builtin_popcountll(x)
#define pint pair<int,int>
#define pdouble pair<double,double>
#define plint pair<lint,lint>
#define fi first
#define se second
typedef long long lint;
int dx[8]={1,1,0,-1,-1,-1,0,1};
int dy[8]={0,1,1,1,0,-1,-1,-1};
const int MAX_N=2e5+5;
//struct edge{lint to,num;};
//vector<int> bucket[MAX_N/1000];

typedef vector<vector<lint>> mat;

mat mtx{
    {1,0,1},//F(N-1),F(N-2),...,F(N-K)の係数
    {1,0,0},//1は単位元(ex.和なら0,ANDなら2^N-1)
    {0,1,0},//0は零元(ex.和やANDなら0,ORなら2^N-1?)
}; // K次正方行列

vector<lint> F{0,0,1}; //F(1)~F(K)の値

mat mul(mat &A,mat &B){
    mat C(A.size(),vector<lint>(B[0].size()));
    rep(i,A.size()) rep(j,B.size()) rep(k,B[0].size()){
        C[i][k]=(C[i][k]+A[i][j]*B[j][k])%MOD; //演算 適宜演算子を変える
    }
    return C;
}

mat powmat(mat A,lint n){
    mat B(A.size(),vector<lint>(A.size()));
    rep(i,A.size()) B[i][i]=1; //単位元
    while(n){
        if(n&1) B=mul(B,A);
        A=mul(A,A);
        n>>=1;
    }
    return B;
}

lint calc(lint n){ //F(N)の計算
    mat A=mtx;
    A=powmat(A,n-1);
    lint res=0; //零元
    rep(i,A.size()) res=(res+A[A.size()-1][i]*F[A.size()-1-i])%MOD;
    return res;
}

int main(void){
    int S;
    cin >> S;
    cout << calc(S) << endl;
}

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

using namespace std;

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

  int p;
  string s;
  map<string, map<int, int, greater<int>>> m;
  for (int i = 0; i < n; i++) {
    cin >> s >> p;
    m[s][p] = i + 1;
  }

  for (auto i = m.begin(); i != m.end(); i++) {
    for (auto j = i->second.begin(); j != i->second.end(); j++) {
      cout << j->second << endl;
    }
  }

  return 0;
}


Measured memory_bytes: 256
use text_io::*;
use std::process::exit;

fn main() {
    let a:usize = read!();
    let b:usize = read!();
    let mut c:usize = 1;
    if b == 1 {
        println!("0");
        exit(0)
    }
    for i in 0..30 {
        c += a-1;
        if b<=c {
            println!("{}",i+1);
            exit(0)
        }
    }
}

Measured memory_bytes: 2092
import collections
N = int(input())
a = list(map(int,input().split()))
ans = 0
c = collections.Counter(a)

key = list(c.keys())


for i in key:
  if i > c[i]:
    ans += c[i]
  elif i < c[i]:
    ans += c[i] - i
print(ans)

Measured memory_bytes: 69032
#include <stdio.h>
  
int  main(void){
         int h,w,i,j;
          while(1){
          scanf("%d %d",&h,&w);
           if( h==0 && w==0)
              break;
           for(i=1; i<=h; i++){
            for(j=1; j<=w; j++){
              if((i+j)%2 == 0)
              printf("#");
             else
              printf(".");
             }printf("\n");
            }printf("\n");
           }
            return 0;
}


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

#define repd(i,a,b) for (int i=(a);i<(b);i++)
#define rep(i,n) repd(i,0,n)
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
typedef long long ll;

const long long INF = 1LL << 60;

int main()
{
    int A, B;
    cin >> A >> B;
    int ans = 0, cnt = 1;

    while (cnt < B) {
        cnt = cnt - 1 + A;
        ans++;
    }

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

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

int main()
{
    int n; string s; cin >> n >> s;
    
    int ans = 0;
    for (int i = 0; i < n - 2; i++) {        
        if (s[i] == 'A' && s[i + 1] == 'B' && s[i + 2] == 'C') ans++;
    }

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

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <sstream>
#include <iomanip>
#define ll long long
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define min_3(a,b,c) min(a,min(b,c))
#define max_3(a,b,c) max(a,max(b,c))
#define nout(ans) cout << (ans) << "\n"
#define sout(ans) cout << (ans) << " "
using namespace std;

const double pi = 3.14159265359;
const ll INF = 1e12;
const ll MOD = 1e9 + 7;
const ll N = 2e5 + 5;
/*
Decimal Places: cout << fixed << setprecision(n) << ans << endl

String to integer:
stringstream dark(s);
int x = 0; dark >> x;
*/

bool compare(const pair<int, int>&i, const pair<int, int>&j)
{
    return i.second < j.second;
}


ll n, a[N], dp[N];

void solve()
{
    cin >> n; for (int i=1; i<=n; i++) cin >> a[i];
    dp[1] = 0; dp[2] = abs(a[2]-a[1]);
    for (int i=3; i<=n; ++i) {
        dp[i] = min(dp[i-1]+abs(a[i]-a[i-1]), dp[i-2] + abs(a[i]-a[i-2]));
    }nout(dp[n]);
}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL); cout.tie(NULL);
    int t = 1;
    //cin >> t;
    for (int i=1; i<=t; i++)
    {
        solve();
    }
    return 0;
}

Measured memory_bytes: 5192
def get_input():
    while True:
        try:
            yield ''.join(input())
        except EOFError:
            break

table = \
["afkpuz",\
 "bglqv.",\
 "chmrw?",\
 "dinsx!",\
 "ejoty "]

N = list(get_input())
for l in range(len(N)):
    str = N[l]
    ans = ""
    if len(str) % 2 == 1:
        ans = "NA"
    else:
        for i in range(0,len(str),2):
            x = str[i]
            y = str[i+1]
            if "1" <= x and x <= "6" and "1" <= y and y <= "5":
                ans = ans + table[int(y)-1][int(x)-1]
            else:
                ans = "NA"
                break

    print(ans)



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

#define ll long long int
//#define PI acos(1.0)

#define Bit_off(val,pos)       (val & (~(1<<pos)))
#define Bit_on(val,pos)        (val | (1<<pos))
#define Bit_toggle(val,pos)    (val ^ (1<<pos))
#define Bit_check(val,pos)     (bool)(val & (1<<pos))
#define odd_even(val)          (bool)(val & 1)
#define koita_1_ase(val)       (__builtin_popcount(val))

ll ar[500009],br[500009],cr[500009];
map<ll,ll>mp,mp1;
vector<ll>v;
string s,d;

int main()
{
    ll a,b,c,i,j,k,x,y,z,f,g,h;
    cin>>a>>b;
    x=0;
    for(i=1;i<=b;i++)
    {
        cin>>c;
        x+=c;
    }
    if(x>a)
    {
        cout<<"-1"<<endl;
    }
    else
    {
        cout<<(a-x)<<endl;
    }
}



Measured memory_bytes: 3600
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < (n); ++i)
#define all(x) (x).begin(),(x).end()
#define ln '\n'
constexpr long long MOD = 1000000007LL;
//constexpr long long MOD = 998244353LL;
typedef long long ll;
typedef unsigned long long ull; 
typedef pair<int, int> pii;
typedef pair<long long, long long> pll;
template<class T> inline bool chmax(T &a, T b) { if (a < b) { a = b; return true;} return false; }
template<class T> inline bool chmin(T &a, T b) { if (a > b) { a = b; return true;} return false; }
///////////////////////////////////////////////////////////////////////////////////////////////////

int main() {
    ios::sync_with_stdio(false); cin.tie(nullptr);
    int A,B; cin >> A >> B;
    string S; cin >> S;
    bool ok = true;
    rep(i,A+B+1) {
        if (i==A) {
            if (S[i] != '-') ok = false;
        } else {
            bool flag = false;
            rep(j,10) {
                if (S[i] == char(j+'0')) flag = true;
            }
            if (!flag) ok = false;
        }
    }

    cout << (ok ? "Yes" : "No") << ln;
}



Measured memory_bytes: 256
import sys
read = sys.stdin.read
readline = sys.stdin.buffer.readline
sys.setrecursionlimit(10 ** 8)
INF = float('inf')
MOD = 10 ** 9 + 7


def main():
    N, K = map(int, readline().split())
    A = list(map(int, readline().split()))
    for i in range(K,N):
        if A[i]<=A[i-K]:
            print('No')
        else:
            print('Yes')


if __name__ == '__main__':
    main()



Measured memory_bytes: 27872
#include <iostream>
#include <vector>
#include <algorithm>
#include <functional>
#include <queue>
#include <deque>
#include <string>
#include <stack>
#include <unordered_set>
#include <cmath>
#define endl '\n'
#define ll unsigned long long
//#define mod 1000000007
#define NCONS 101

using namespace std;

int main(void)
{
	cin.tie(NULL); ios_base::sync_with_stdio(false);
	int A, B, C, D; cin >> A >> B >> C >> D;
	int ret = min(B, D) - max(A, C);
	if (ret < 0)
		ret = 0;
	cout << ret;
	return 0;
}

Measured memory_bytes: 256
import Control.Monad
import Data.List (foldl', (\\), nub)

main = do
  n <- readLn
  ws <- replicateM n getLine
  if (ws \\ (nub ws) == []) && (foldl' (\a b -> a && check b) True $ zip ws (tail ws))
  then
    putStrLn "Yes"
  else
    putStrLn "No"
 where 
   check (a,b) = last a == head b

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

using namespace std;

string Input;
const int Mapdata[][2] = {
	{ 1, 2 },
	{ 6, 3 },
	{ 1, 6 },
	{ 4, 5 },
	{ 5, 2 },
	{ 2, 1 },
	{ 6, 6 },
};


void solve() {
	//cout << Input << endl;
	int size, next;

	size = Input.size();
	next = 0;
	for (int i = 0; i < size; ++i) {
		next = Mapdata[next][Input[i] - '0'];
	}
	cout << (next == 5 ? "Yes" : "No") << endl;
}

int main() {
	
	while (true) {
		cin >> Input;
		if (Input == "#") {
			break;
		}
		solve();
	}
	
	return 0;
}



Measured memory_bytes: 3164
#include <iostream>
#include <sstream>
#include <iomanip>
#include <stdio.h>
#include <string>
#include <cstdlib>
#include <vector>
#include <cmath>
#include <math.h>
#include <stdexcept>
#include <algorithm>
#include <set>
#include <map>
#include <stdlib.h>
#include <cctype>
#include <bitset>
using namespace std;
int main(){
    string S;
    cin >> S;
    int i,a = 0;
    for(i = 0;i < S.size();i++){
        a += S[i] - '0';
        a = a % 9;
    }
    if(a % 9 == 0){
        cout << "Yes" << endl;
    }
    else{
        cout << "No" << endl;
    }
}

Measured memory_bytes: 3724
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(n);i++)
#define all(x) (x).begin(), (x).end()
using ll = long long;
using namespace std;
template <typename T>
using vec = std::vector<T>;

int main() {
    ll N,M;
    cin >> N >> M;
    vec<ll> A(N);
    rep(i, N) cin >> A[i];
    map<ll,ll> mp;
    
    mp[0] = 1;
    ll now = 0;
    ll ans = 0;
    rep(i,N){
        now = (now + A[i])%M;
        ans += mp[now];
        ++mp[now];
    }
    cout << ans << endl;
}

Measured memory_bytes: 4992
#include<stdio.h>

int main(void)
{
	int n, sum1, sum2, f1, A, B;
	while(scanf("%d",&n) && n > 0)
	{
		sum1 = 0; sum2 = 0;
		for(f1 = 1; f1 <= n; f1++)
		{
			scanf("%d %d",&A,&B);
			if(A > B)
				sum1 += A + B;
			else if(A < B)
				sum2 += A + B;
			else
			{
				sum1 += A;
				sum2 +=B;
			}
		}
		printf("%d %d\n",sum1,sum2);
	}
	return 0;
}

Measured memory_bytes: 0
import math

n, q = map(int, input().split())

# make a list whose length is 2^i - 1.
n = 2 ** math.ceil(math.log(n, 2))
max_v = 2147483647

A = [max_v for i in range(2 * n - 1)]


def update(i, x):
    i += n - 1
    A[i] = x

    while i > 0:
        i = (i - 1) // 2
        A[i] = min(A[i * 2 + 1], A[i * 2 + 2])

def find(a, b, k, l, r):
    if r <= a or b <= l:
        return max_v
    if a <= l and r <= b:
        return A[k]
    else:
        vl = find(a, b, k * 2 + 1, l, (l + r) // 2)
        vr = find(a, b, k * 2 + 2, (l + r) // 2, r)
        return min(vl, vr)


for i in range(q):
    com, x, y = map(int, input().split())
    if com == 0:
        update(x, y)
    else:
        ans = find(x, y + 1, 0, 0, n)
        print(ans)

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

using namespace std;

int main() {
  string S;
  int K;
  cin >> S >> K;
  set<string> s;
  for (int i = 0; i < S.length(); i++) {
    for (int j = 1; j <= K; j++) {
      if (i + j > S.length()) break;
      s.insert(S.substr(i, j));
    }
  }
  auto ans = s.begin();
  for (int i = 0; i < K - 1; i++) {
    ans++;
  }
  cout << *ans << endl;

  return 0;
}
/* vim:set fdm=marker: */


Measured memory_bytes: 1664
#include <iostream>
#include <algorithm>

using namespace std;

int main(void) {
    int i, x[2];
    
    i = 1;
    cin >> x[0] >> x[1];

    
    while(x[0]!=0 || x[1]!=0) {
        sort(x, x+2);
        cout << x[0] << " " << x[1] << endl;
        cin >> x[0] >> x[1];
    }
    
    return 0;
}

Measured memory_bytes: 3136
import java.util.Scanner;

public class Main{

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

		int[] huda=new int[50];
		int[] hud2=new int[50];
		int[] hud3=new int[50];

		while(true){
			int n=s.nextInt();
			int r=s.nextInt();
			if(r==0&&n==0){
				break;
			}
			for(int i=0;i<n;i++){
				huda[i]=n-i;
			}
			for(int i=0;i<r;i++){
				int p=s.nextInt();
				int c=s.nextInt();

				if(p==1){
					continue;
				}
				for(int k=0;k<(c+p-1);k++){
					hud2[k]=huda[k];
				}

				for(int k=0;k<c;k++){
					//hud2[k]=huda[k];
					huda[k]=huda[p-1+k];
				}
				for(int k=0;k<p-1;k++){
					//hud3[k]=huda[c+k];
					huda[c+k]=hud2[k];
				}
				for(int k=0;k<(p-1+c-2*c);k++){

				}




				for(int j=0;j<n;j++){
		//			System.out.println(huda[j]+"..");
				}
			}
			System.out.println(huda[0]);
		}
	}
}

Measured memory_bytes: 38628
N = int(input())
c = [0]*N
s = [0]*N
f = [0]*N
for i in range(N-1):
    c[i], s[i], f[i] = map(int, input().split())
for i in range(N):
    t = 0
    for j in range(i, N-1):
        if t < s[j]:
            t = s[j]
        elif t % f[j] == 0:
            pass
        else:
            t = t + f[j] - t % f[j]
        t += c[j]
    print(t)

Measured memory_bytes: 3064
#define _USE_MATH_DEFINES
#define _CRT_SECURE_NO_WARNINGS

#include <iostream>
#include <string>
#include <sstream>
#include <iomanip>
#include <cmath>
#include <cstring>
#include <cstdlib>
#include <algorithm>
#include <stack>
#include <queue>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <utility>
#include <numeric>

using namespace std;

const uint64_t MOD = 1000000000 + 7;

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

	a *= 3;

	cout << (a + b) / 2 << endl;
}


Measured memory_bytes: 256
#include <stdio.h>


int main(void) {
	int a[4], b[4];
	int hit, blow;
	int i, j;
	
	while (1) {
		if( scanf("%d %d %d %d", &a[0], &a[1], &a[2], &a[3]) == EOF)
			break;
		if( scanf("%d %d %d %d", &b[0], &b[1], &b[2], &b[3]) == EOF)
			break;
		hit = blow = 0;
		for (i = 0; i < 4; i++)
			for (j = 0; j < 4; j++)
				if( a[i] == b[j])
					if( i == j) {
						hit++;
						break;
					} else {
						blow++;
						break;
					}
		printf("%d %d\n", hit, blow);
	}
	
	return 0;
}

Measured memory_bytes: 596
#include <bits/stdc++.h> 
#include <vector>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define size_of_array(array) (sizeof(array)/sizeof(array[0]))
using ll =long long;
using namespace std;
using Graph=vector<vector<int>>;
using Field=vector<vector<int>>;

int main(){
    int h,w,K;
    cin>>h>>w>>K;

    char c[6][6]={};
    int sum=0;
    int hh[6]={};
    rep(i,h){
        rep(j,w){
            cin>>c[i][j];
            if(c[i][j]=='#'){
                sum++;
                hh[i]++;
            }
        }
    }

    int ww[6]={};
    rep(i,w){
        rep(j,h){
            if(c[j][i]=='#')ww[i]++;
        }
    }

    int ans=0;
    rep(i,pow(2,h)){
        rep(j,pow(2,w)){
            int temp=sum;
            rep(k,h){
                if((i>>k)&1)temp-=hh[k];
            }
            rep(l,w){
                if((j>>l)&1){
                    temp-=ww[l];
                    rep(m,h){
                        if(((i>>m)&1) && c[m][l]=='#')temp++;
                    }
                }
            }
            if(temp==K)ans++;
        }
    }
    cout<<ans<<endl;
}



Measured memory_bytes: 4100
#include<bits/stdc++.h>
using namespace std;
int main(){
  int n,a,fi=INT_MAX,se=INT_MAX,th=INT_MAX;
  char s[10001][6],kari[11];
  scanf("%d",&n);
  for(int i=0;i<n;i++){
    scanf("%s",s[i]);
  }
  for(int i=0;i<n-1;i++){
    for(int j=i+1;j<n;j++){
      strcpy(kari,s[i]);
      strcat(kari,s[j]);
      a = atoi(kari);
      if(fi > a){
	th = se;
	se = fi;
	fi = a;
      } else if(se > a){
	th = se;
	se = a;
      } else if(th > a){
	th = a;
      }
      strcpy(kari,s[j]);
      strcat(kari,s[i]);
      a = atoi(kari);
      if(fi > a){
	th = se;
	se = fi;
	fi = a;
      } else if(se > a){
	th = se;
	se = a;
      } else if(th > a){
	th = a;
      }
    }
  }
  printf("%d\n",th);
  return (0);
}

Measured memory_bytes: 3200