akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include<string>
#include<cmath>
#include<algorithm>
#include<cctype>
#include<queue>
#include<deque>
#include<regex>
#include<stack>
#include<stdio.h>
#include<vector>
#include<set>
#include<map>
#include<iomanip>

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

typedef int long long ll;
using namespace std;
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};
const ll MOD = 1e9 + 7;
static const int MAX = 100;
static const int INF = (1 << 23);
ll modpow(ll a,ll b){
    ll ret = 1;
    while(b>0){
        if(b&1)ret = (ret*a)%MOD;
        a = (a*a)%MOD;
        b = b>>1;
    }
    return ret;
}

ll combmod(ll n,ll r){
    ll nn = 1;
    ll rr = 1;
//    if(n-r<r){
//        r=n-r;
//    }
    rep(i,r){
        nn *= (n-i);
        nn %=MOD;
        rr *= (r-i);
        rr %=MOD;
    }
    return nn*modpow(rr,MOD-2)%MOD;

}
int main() {
    ll n,m,k;
    cin>>n>>m>>k;
    ll ans1 = 0;
    ll ans2 = 0;
    ll nm2 = (n*m)-2;
    nm2%=MOD;
    nm2 = combmod(nm2,(k-2));


    for(int i=0;i<n;i++){
        ll a = (n-i)*(i);
        a%=MOD;
        a*=(m*m)%MOD;
        a%=MOD;
        a *= nm2;
        a%=MOD;
        ans1 +=a;
        ans1%=MOD;
    }
   // cout<<ans1<<endl;

    for(int i=0;m-i>0;i++){
        ll a = (m-i)*(i);
        a%=MOD;
        a*=(n*n)%MOD;
        a%=MOD;
        a *= nm2;
        a%=MOD;
        ans2 += a;
        ans2%=MOD;
    }
    //cout<<ans2<<endl;
    cout<<(ans1+ans2)%MOD<<endl;







    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <stack>
#include <queue>
using namespace std;
typedef long long int ll;

int main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    int n,m; cin >> n >> m;
    if(n==4){
        cout << 1 << " " << 2 << endl;
        return 0;
    }
    if(n==6){
        if(m==1){
            cout << 1 << " " << 2 << endl;
        }
        else{
            cout << 1 << " " << 2 << endl;
            cout << 3 << " " << 5 << endl;
        }
        return 0;
    }
    if(n%2==0){
        vector<bool> used(n+1,0);
        int p=(n-1)/2;
        if(p%2)p--;
        printf("%d %d\n",p/2,p/2+p);
        used[p/2]=1;
        used[p/2+p]=1;
        m--;
        if(m==0)return 0;
        int q=1;
        p-=2;
        int qq;
        while(p>=2){
            printf("%d %d\n",q,q+p);
            qq=q+p;
            used[q]=1;
            used[q+p]=1;
            p-=2;
            q++;
            m--;
            if(m==0)return 0;
        }
        p=(n-1)/2;
        if(p%2==0)p--;
        qq++;
        while(p>=1){
            for(int i=qq;i<=n;i++){
                if(!used[i]&&!used[i+p]){
                    printf("%d %d\n",i,i+p);
                    used[i]=1;
                    used[i+p]=1;
                    m--;
                    if(m==0)return 0;
                    break;
                }
            }
            p-=2;
        }

    }
    else{
        for(int i=1;i<=m;i++){
            printf("%d %d\n",i,n-i);
        }
    }
}


Measured memory_bytes: 3744
#ifndef DEBUG
#pragma GCC optimize("Ofast,no-stack-protector,unroll-loops,fast-math")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4.1,sse4.2,avx,popcnt,tune=native")
#endif // DEBUG
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstring>
#include <cstdlib>
#include <vector>
#include <set>
#include <queue>
#include <stack>
#include <map>
#include <string>
#include <stack>
using namespace std;
typedef long long ll;
inline ll read()
{
    int ch=getchar(),f=1;
    ll ans=0;
    for(;ch<'0'||ch>'9';ch=getchar())
        if(ch=='-')f=0;
    for(;ch>='0'&&ch<='9';ch=getchar())
        ans=(((ans<<2)+ans)<<1)+(ch^'0');
    return f?ans:-ans;
}
int n;
const int maxn=200005;
vector<int> e[maxn];
int q;
int val[maxn];
void dfs(int u,int fa)
{
    val[u]+=val[fa];
    for(int v:e[u])
        if(v!=fa)
    {
        dfs(v,u);
    }
}
int main()
{
    n=read();q=read();
    for(int i=1;i<n;++i)
    {
        int u=read(),v=read();
        e[u].push_back(v);
        e[v].push_back(u);
    }
    while(q--)
    {
        int p=read(),x=read();
        val[p]+=x;
    }
    dfs(1,0);
    for(int i=1;i<=n;++i)
        printf("%d ",val[i]);
    puts("");
    //cout << "Hello world!" << endl;
    return 0;
}


Measured memory_bytes: 20736
#include <bits/stdc++.h>
  
using namespace std;
  
#define rep(i,n) REP(i,0,n)
#define REP(i,s,e) for(int i=(s); i<(int)(e); i++)
#define pb push_back
#define all(r) r.begin(),r.end()
#define rall(r) r.rbegin(),r.rend()
#define fi first
#define se second
  
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
 
const int INF = 1e9;
const ll MOD = 1e9 + 7;
double EPS = 1e-8;

const int MAX_N = 1e5+10;
struct Edge{ int to, cost; };
vector<Edge> es[MAX_N];

ll dist[MAX_N];

void f(int cur, int par, ll cost) {
	dist[cur] = cost;
	for(auto& e : es[cur]) {
		if(e.to == par) continue;
		f(e.to, cur, cost + e.cost);
	}
}

int main(){
	int n;
	cin >> n;
	rep(i, n-1) {
		int a, b, c;
		cin >> a >> b >> c;
		a--; b--;
		es[a].pb({b, c});
		es[b].pb({a, c});
	}
	int q, k;
	cin >> q >> k;
	k--;
	f(k, -1, 0LL);
	rep(i, q) {
		int a, b;
		cin >> a >> b;
		a--; b--;
		cout << dist[a] + dist[b] << endl;
	} 
}


Measured memory_bytes: 12800
#include<bits/stdc++.h>
using namespace std;
int main(){
double W,H,x,y;
  cin>>W>>H>>x>>y;
  double ans=(W*H)/2;
  if(x==W/2 && y==H/2)
  cout<<ans<<" "<<1<<endl;
  else
    cout<<ans<<" "<<0<<endl;
  
 return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h> 
using namespace std;
typedef long long ll;
const int MM = 1000000000;
const int MOD = MM + 7;
const int MAX = 510000;
#define rep(i, n) for(ll i=0; i<n; i++)
#define Rep(i, j, n) for(ll i=j; i<n; i++)
#define all(vec) vec.begin(), vec.end()
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;}
const ll INF = 1LL << 60;

int main() {
    string s, t; cin >> s >> t;
    int cnt = 0;
    rep(i, s.size()) {
        if(s[i] == t[i]) cnt++;
    }
    cout << s.size() - cnt << endl;
}

Measured memory_bytes: 3916
// Created by Nandu Vinodan
#include "bits/stdc++.h"

#define db1(x) cout<<#x<<"="<<x<<'\n'
#define db2(x,y) cout<<#x<<"="<<x<<","<<#y<<"="<<y<<'\n'
#define db3(x,y,z) cout<<#x<<"="<<x<<","<<#y<<"="<<y<<","<<#z<<"="<<z<<'\n'
#define rep(i,a,n) for(int i=a;i<=(n);++i)
#define repD(i,a,n) for(int i=a;i>=(n);--i)
#define pb(a) push_back(a)
#define eb(a) emplace_back(a)
#define vi vector<int>
#define pi pair<int, int>
#define INF INT_MAX
#define _INF INT_MIN
#define TC 0

using namespace std;
using ll = long long;

void testcase() {
    int l; cin >> l;

    double val = (double)l/3.0;

    double res = val * val * val;
	

	printf("%.7f", res);
}

int main() {
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    int t=1;
    if (TC)
        cin>>t;
    while(t--) {
        testcase();
    }
    return 0;
}

Measured memory_bytes: 256
a = gets.chomp.to_i
b = gets.chomp.to_i
c = gets.chomp.to_i
x = gets.chomp.to_i
ans = 0
(0..a).each do |n_500|
  (0..b).each do |n_100|
    (0..c).each do |n_50|
      ans += 1 if 500 * n_500 + 100 * n_100 + 50 * n_50 == x
    end
  end
end
puts ans


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

const int MOD = 1e9+7;

void add_self(int& a, int b) {
    a += b;
    if(a > MOD) {
        a -= MOD;
    }
}

int main()
{
    int h, w;
    cin >> h >> w;
    char a[h][w];
    for(int i = 0; i < h; i++) {
        for(int j = 0; j < w; j++) {
            cin >> a[i][j];
        }
    }
    vector<vector<int>> dp(h, vector<int>(w));
    dp[0][0] = 1;
    for(int i = 0; i < h; i++) {
        for(int j = 0; j < w; j++) {
            if(a[i][j] == '.') {
                if(i < h-1) {
                    add_self(dp[i+1][j], dp[i][j]);
                }
                if(j < w-1) {
                    add_self(dp[i][j+1], dp[i][j]);
                }
            }
        }
    }
    cout << dp[h-1][w-1] << endl;
}


Measured memory_bytes: 5120
#include <bits/stdc++.h>
#define all(x) (x).begin(), (x).end()
using namespace std;
typedef long long int64;
const double PI = 3.14159265358979323846;
const double EPS = 1e-12;
const int INF = 1<<29;
const long long  INFL = 1e18;
const int MOD = 1000000007;
const int MAX = 210000;
const int MAX_NUM = 999999999;
void solve() {
	int a, b; cin >> a >> b;
	if (a % 3 == 0 || b % 3 == 0 || (a + b) % 3 == 0) {
		cout << "Possible" << endl;
		return;
	}
	cout << "Impossible" << endl;
	return;
}
int main() {
	solve();
	return 0;
}

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

#ifdef DEBUG
#define FAST ;
#else
#define FAST ios::sync_with_stdio(0);cin.tie(0);
#define endl '\n'
#endif
#define _ <<' '<<
#define Fr(i, s, e) for(auto i = s; i < e; ++i)
#define Ft first
#define Sd second
using ll = long long;
using pii = pair<int, int>;
constexpr ll MAX = 1e6+5;
constexpr ll INF = 2134567890;
constexpr ll MOD = 998244353;

ll fpow(ll b, ll a, ll MOD = MOD) {
    b %= MOD;
    ll r = 1;
    for(; a; b=b*b%MOD, a>>=1)
        a&1 && (r = r*b%MOD);
    return r;
}

signed main() {
    FAST;

    int x;
    cin >> x;
    int *c = new int[x+100]();
    c[0] = c[1] = 1;
    vector<int> P{};
    Fr(i, 2, x+100) {
        if (!c[i]) c[i] = 1, P.emplace_back(i);
        for(const int &p: P) {
            if (p*i >= x+100) break;
            c[p*i] = p;
        }
    }
    cout << *lower_bound(P.begin(), P.end(), x) << endl;

}


Measured memory_bytes: 768
#include <bits/stdc++.h>
using namespace std;
int main(){
  string N;
  cin >> N;
  if(N == "abc" || N == "acb" || N == "bac" || N == "bca" || N == "cab" || N == "cba"){
    cout << "Yes" << endl;
  }
  else {
    cout << "No" << endl;
  }
}

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

int main() {
    string s;
    cin >> s;

    string res = "AC";
    int C_cnt = 0;
    if (s.at(0) == 'A') {
        for (int i = 1; i < s.size(); i++) {
            if (s.at(i) == 'C') {
                if (2 <= i && i <= (s.size()-2)) {
                    C_cnt++;
                } else {
                    res = "WA";
                }
            } else {
                if (!('a' <= s.at(i) && s.at(i) <= 'z')) res = "WA";
            }
        }
        if (C_cnt != 1) res = "WA";
    } else {
        res = "WA";
    }
    
    cout << res << endl; 

    return 0;
}


Measured memory_bytes: 3600
#include <iostream>

using namespace std;
/** Problem0085 : Joseph's Potato **/
int main()
{
	int n, m, ans, idx;
	bool live[1000];
	
	while (cin >> n >> m && (n!=0 && m!=0)) {
		for (int i=0; i<1000; i++) live[i]=true;
		
		ans = 0; idx=0;
		for (int i=0; i<n; i++) {
			for (int j=0; j<m; j++) {
				while (live[(++idx)%n]!= true);
			}
			live[idx%n] = false;
		}
		cout << ((idx%n)==0 ? n : idx%n) << endl;
	}
	return 0;
}

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

int main()
{
	int i, j, H, W;
	char a[102][102] = {};
	scanf("%d %d", &H, &W);
	for (i = 1; i <= H; i++) scanf("%s", &(a[i][1]));
	
	for (i = 1; i <= H; i++) {
		if (a[i][0] == -1) continue;
		for (j = 1; j <= W; j++) {
			if (a[0][j] == 0 && a[i][j] == '#') break;
		}
		if (j > W) a[i][0] = -1;
	}
	for (j = 1; j <= W; j++) {
		if (a[0][j] == -1) continue;
		for (i = 1; i <= H; i++) {
			if (a[i][0] == 0 && a[i][j] == '#') break;
		}
		if (i > H) a[0][j] = -1;
	}
	
	for (i = 1; i <= H; i++) {
		if (a[i][0] == -1) continue;
		for (j = 1; j <= W; j++) {
			if (a[0][j] == 0) printf("%c", a[i][j]);
		}
		printf("\n");
	}
	fflush(stdout);
	return 0;
}

Measured memory_bytes: 128
#include <stdio.h>
#define N 251


typedef struct{
  int key, lk, rk, pk;
}Node;

void Insert(int);

Node node[N];
int size;
	    
int main () {
  int n = 0, i, m = 0;


  scanf("%d",&n);


  for(i = 1 ; i <= n ; i++) {
    scanf("%d",&m);
    Insert(m);
  }


  for(i = 1 ; i <= n ; i++) {
    printf("node %d: key = %d, ",i,node[i].key);

    if(i != 1) {
      printf("parent key = %d, ",node[node[i].pk].key);
    }

    if(2 * i <= n) printf("left key = %d, ",node[node[i].lk].key);
    if(2 * i + 1 <= n) printf("right key = %d, ",node[node[i].rk].key);

    printf("\n");
  }


  return 0;
}


void Insert(int n) {
  int i;

  size++;

  node[size].key = n;
  node[size].lk = size * 2;
  node[size].rk = size * 2 + 1;
  node[size].pk = size / 2;
}




Measured memory_bytes: 2052
#include <iostream>

bool isPalindromic[10002];
int A[10002], B[10002];

int main(){
    for(int i=0;i<=10001;i++){
        std::string s = std::to_string(i);
        bool f = true;
        for(int j=0;j<s.size();j++){
            if(s[j] != s[s.size()-1-j]){f = false; break;}
        }
        if(f){isPalindromic[i] = true;}
    }
    
    int prev;
    for(int i=0;i<=10001;i++){
        if(isPalindromic[i]){prev = i;}
        A[i] = prev;
    }

    for(int i=10001;i>=0;i--){
        if(isPalindromic[i]){prev = i;}
        B[i] = prev;
    }
    
    int N;
    std::cin >> N;

    if(std::abs(N-A[N]) <= std::abs(N-B[N])){
        std::cout << A[N]<< std::endl;
    }else{
        std::cout << B[N]<< std::endl;
    }
    
}

Measured memory_bytes: 1316
/**
*
* Author: Mouhanad
* Lang: GNU C++14
*
**/
#include<bits/stdc++.h>
using namespace std;

#define F first
#define S second
#define ii pair < int , int >
#define LS pair < ll , string >
typedef long long ll;
const int inf = 1<<30;
const int N =1100;
int n , a[N] ;
ll  k ;
char al[N];
int main ( ){
    scanf("%s",al);
    n = strlen(al);
    scanf("%lld",&k);
    vector <ll> sz ;
    int cur = 1;
    al[n] = '#';
    int cnt = 0 ;
    for  (int i = 1; i <= n ; i++ ){
           if ( al[i] != al[i-1] ){
            sz.push_back(cur);
            cnt++;
            cur = 1 ;continue;
           }
           cur++;
    }
    if ( cnt == 1 ){
        printf("%lld",k*sz[0]/2);
        return 0;
    }

    ll l = sz[0] , r = 0 ;
    if ( sz.size() != 1 ) r = sz.back();
    ll ANS =0 ;
    for ( int i = 1 ; i < sz.size()-1 ; i++ ){

        ANS += sz[i]/2*k;
    }

    if ( al[0] == al[n-1] ) {
        ANS += ((l+r)/2)*(k-1);
        ANS += l/2 + r/2 ;
    }else ANS += l/2*k + r/2*k ;
    printf("%lld\n",ANS);
return 0 ;
}


Measured memory_bytes: 256
#include <iostream>

int main() {
        int n, m, l;
        std::cin >> n >> m >> l;
        long long int a[n][m], b[m][l], c[n][l];

        for(int i=0; i<n; i++){
                for(int j=0; j<m; j++){
                        std::cin >> a[i][j];
                }
        }

        for(int j=0; j<m; j++){
                for(int k=0; k<l; k++){
                        std::cin >> b[j][k];
                }
        }

        for(int i=0; i<n; i++){
                for(int k=0; k<l; k++){
                        long long int sum = 0;
                        for(int j=0; j<m; j++){
                                sum += a[i][j] * b[j][k];
                        }
                        c[i][k] = sum;
                }
        }

        for(int i=0; i<n; i++){
                for(int k=0; k<l; k++){
                        std::cout << c[i][k] << std::flush;
                        if(k!=l-1) std::cout << ' ' << std::flush;
                        else if(k==l-1)std::cout << std::endl;
                }
        }
}

Measured memory_bytes: 3312
#include <bits/stdc++.h>
#define all(x) begin(x), end(x)
#define dbg(x) cerr << #x << " = " << x << endl
#define _ << ' ' <<
using namespace std;
using ll = long long;
using vi = vector<int>;

int a[100000];
int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n;
    cin >> n;
    for (int i = 0; i < n; ++i)
        cin >> a[i];

    n = unique(a, a + n) - a;
    int sol = 1;
    for (int i = 1; i < n - 1; ++i)
        if ((a[i - 1] < a[i]) != (a[i] < a[i + 1]))
            sol++, ++i;
    cout << sol;
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define REP(i, n) for (int i = 0; i < (int)(n); i++)
#define REP2(i, n) for (int i = 1; i <= (int)(n); i++)
#define FOR(i, m, n) for (int i = m; i n; i++)
#define SORT(x) sort(x.begin(), x.end())
#define REVE(x) reverse(x.begin(), x.end())
#define all(x) (x).begin(), (x).end()
struct initon
{
    initon()
    {
        cin.tie(0);
        ios::sync_with_stdio(false);
    };
};
int k=0,n=0, m=0, l=0,a=0, b=0, c=0, d=0,ans=0,ans2=0,x=0,y=0;
string s,t,S;
signed main() {
    cin >> a>>b;
    //cin >> x >> y;
    //cin >> s >> t;
     ans=max(a,b);
     if(ans-1>=min(a,b))cout << ans*2-1;
     else cout <<ans+min(a,b);
}


Measured memory_bytes: 3628
li = list()
for i in range(5):
  li.append(int(input()))

lili = list()
  
for i in li:
  num = list(map(int, str(i)))
  if num[-1] == 0:
    num[-1] = 10
  lili.append(num[-1])

index = lili.index(min(lili))
ans = 0
for i, l in enumerate(li):
  if i == index:
    ans += l
  else:
    ans += l
    ans += 10-lili[i]

print(ans)
    


      

Measured memory_bytes: 3064
import java.util.Scanner;
public class Main{
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        int count = 0;
        int tmp = 0;
        int num[] = new int[N];
        for(int i = 0 ; i < N ; i++)
            num[i] = sc.nextInt();
        for(int i = 0 ; i < N - 1; i++)
        {
            for(int j = N - 1 ; j > i ; j--)
            {
                if(num[j] < num[j - 1])
                {
                    tmp = num[j];
                    num[j] = num[j-1];
                    num[j-1] = tmp;
                    count++;
                }
            }
        }
        for(int i = 0 ; i < N - 1 ; i++)
            System.out.print(num[i] + " ");
        System.out.println(num[N-1]);
        System.out.println(count);
    }
}


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

using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;

typedef int _loop_int;
#define REP(i,n) for(_loop_int i=0;i<(_loop_int)(n);++i)
#define FOR(i,a,b) for(_loop_int i=(_loop_int)(a);i<(_loop_int)(b);++i)
#define FORR(i,a,b) for(_loop_int i=(_loop_int)(b)-1;i>=(_loop_int)(a);--i)

#define DEBUG(x) cout<<#x<<": "<<x<<endl
#define DEBUG_VEC(v) cout<<#v<<":";REP(i,v.size())cout<<" "<<v[i];cout<<endl
#define ALL(a) (a).begin(),(a).end()

#define CHMIN(a,b) a=min((a),(b))
#define CHMAX(a,b) a=max((a),(b))

// mod
const ll MOD = 1000000007ll;
#define FIX(a) ((a)%MOD+MOD)%MOD

// floating
typedef double Real;
const Real EPS = 1e-11;
#define EQ0(x) (abs(x)<EPS)
#define EQ(a,b) (abs(a-b)<EPS)
typedef complex<Real> P;

int main(){
  int n;
  cin>>n;
  vi t(n);
  REP(i,n)cin>>t[i];
  int s = accumulate(ALL(t),0);
  int m;
  cin>>m;
  REP(i,m){
    int p,x;
    cin>>p>>x;
    cout << (s - t[p-1] + x) << endl;
  }
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <vector>
#include <set>
#include <string>
#include <queue>
#include <algorithm>
#include <map>
#include <cmath>
#include <numeric>
#include <list>
#include <stack>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <tuple>

#define rep(i, n) for (int i = 0; i < (n); i++)
#define rep1(i, n) for (int i = 1; i <= (n); i++)
#define show(a, n) rep(i,n) {cout<<a[i]<<' ';} cout<<endl;

using namespace std;
typedef vector<int> vi;
typedef pair<int, int> pii;
typedef long long ll;
typedef vector<ll> vll;
typedef pair<long long, long long> pll;

const int INF = 1 << 30;
const long long INFL = 1LL << 62;
const int MOD = 1000000007;
const int MAX = 100000;
const int N = 100010;

int main() {
//	cout << fixed << setprecision(15);
	string s;
	cin >> s;
	if(s.size() % 2 == 1) {
		cout << "No" << endl;
		return 0;
	}
	bool ok = true;
	for(int i = 0; i < s.size(); i += 2) {
		if(s.substr(i, 2) != "hi") {
			ok = false;
		}
	}
	cout << (ok ? "Yes" : "No") << endl;
}


Measured memory_bytes: 256
#include <cstdio>
#include <iostream>
#include <vector>
#include <map>
#include <unordered_map>
#include <set>
#include <unordered_set>
#include <string>
#include <cstring>
#include <sstream>
#include <algorithm>
#include <functional>
#include <queue>
#include <stack>
#include <cmath>
#include <iomanip>
#include <list>
#include <tuple>
#include <bitset>
#include <ciso646>
#include <cassert>

using namespace std;

#define int long long
#define double long double

typedef pair<int, int> P;
typedef tuple<int, int, int> T;

template<class T> string tostr(T x) { stringstream o; o << x; return o.str(); }
template<class T> T sqr(T x) { return x*x; }
template<class T> T mypow(T x, int n) { T r = 1; while (n > 0) { if (n & 1)r = r*x; x = x*x; n >>= 1; }return r; }

int toint(string s) { int v; stringstream i(s); i >> v; return v; }
bool check(int x, int y, int w, int h) { return x >= 0 && y >= 0 && w > x && h > y; }
int gcd(int a, int b) { return b ? gcd(b, a%b) : a; }
int lcm(int a, int b) { return a / gcd(a, b) * b; }

#define REP(i,a,b)	for(int (i) = (a);i < (b);(i)++)
#define rep(i,n)	REP(i,0,n)
#define PER(i,a,b)	for(int (i) = (a-1);i >= (b);(i)--)
#define per(i,n)	PER(i,n,0)
#define each(i,n)	for(auto &i : n)
#define clr(a)		memset((a), 0 ,sizeof(a))
#define mclr(a)		memset((a), -1 ,sizeof(a))
#define all(a)		(a).begin(),(a).end()
#define sz(a)		(sizeof(a))
#define dump(val) 	cerr << #val " = " << val << endl;
#define dum(val)	cerr << #val " = " << val;
#define Fill(a,v)	fill((int*)a,(int*)(a+(sz(a)/sz(*(a)))),v)

const int dx[8] = { +1,+0,-1,+0,+1,+1,-1,-1 };
const int dy[8] = { +0,-1,+0,+1,-1,+1,-1,+1 };
const int mod = 1e9 + 7;
const int INF = 1e17 + 9;

signed main() {
	cin.tie(0);
	ios_base::sync_with_stdio(false);

	int n;
	cin >> n;
	string s;
	cin >> s;

	int ans = 0, count = 0;
	each(c, s) {
		if (c == 'I')count++;
		if (c == 'D')count--;
		ans = max(count, ans);
	}
	cout << ans << endl;

	return 0;
}

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

int main()
{
    char a[20], b[20], c[20];

    scanf("%s %s %s", &a, &b, &c);

    if (a[strlen(a)-1] == b[0] && b[strlen(b)-1] == c[0]){
        printf("YES");
    }else {
        printf("NO");
    }

    return 0;
}


Measured memory_bytes: 1700
#include <algorithm>
#include <iostream>
#include <vector>
#include <map>
#include <cstdio>
#include <string>
#include <cmath>
#include <queue>
#include <tuple>
#include <bitset>
#include <cassert>
#include <chrono>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <random>
#include <set>
#include <stack>
#include <time.h>

//#include <bits/stdc++.h>
#define maxs(x,y) x = max(x,y)
#define mins(x,y) x = min(x,y)
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define repr(i, n) for (int i = (n) - 1; i >= 0; i--)
#define FOR(i,i0,n) for(int (i)=(i0);(i)<(n);(i)++)
#define FORR(i,i0,n) for(int (i)=(n)-1; (i)>=(i0);(i)--)
#define SORT(x) sort(x.begin(),x.end())
#define SORTR(x) sort(x.begin(),x.end(),greater<vector<int>>())

#define fi first
#define se second
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define mt make_tuple

using namespace std;
using ll = long long;
typedef std::pair<int, int> pii;
typedef std::pair<int, double> pid;
typedef std::vector<int> vi;
typedef std::vector<pii> vii;

#define PI 3.14159265358979323846264338327950L
const int mod = 9999;




void solve(){
    
    ll n,x,m;
    cin >> n >> x >> m;
    
    ll ans = 0;
    ll cur = x;
    
    ll seen[100001] = {};
    ll seenwhere[100001] = {};
    if (x==0){
        cout << 0;
        return;
    }
    
    ll cnt = 0;
    while(n){
        cnt++;
        n--;

        ans += cur;
        cur = ((1LL*cur*cur)%m);
        
        if (seen[cur]){
            ll r = n/(cnt-seenwhere[cur]);
            n %= (cnt-seenwhere[cur]);
            ans += 1LL*r*(ans - seen[cur]);
        }
        seenwhere[cur] = cnt;
        seen[cur] = ans;
    }

    

    
    cout << ans;
}




int main() {
    int T;
    
    T = 1;
    //cin >> T;
    
    while (T--) {
        solve();
        cout << endl;
    }
}




Measured memory_bytes: 5192
#include <set>
#include <cstdio>
#include <queue>
#define REP(i,n) for(int i=0; i<(int)(n); i++)

inline int getInt(){ int s; scanf("%d", &s); return s; }

#define IN(x,s,g) ((x) >= (s) && (x) < (g))
#define ISIN(x,y,w,h) (IN((x),0,(w)) && IN((y),0,(h)))

using namespace std;

int g[100][100];

int dx[2][6] = {
  {1, 1, 0, -1, 0, 1},
  {1, 0, -1, -1, -1, 0}
};
int dy[2][6] = {
  {0, 1, 1, 0, -1, -1},
  {0, 1, 1, 0, -1, -1}
};

int main(){
  int w = getInt();
  int h = getInt();
  int ans = 0;

  REP(i,h) REP(j,w) g[i][j] = getInt();

  queue<pair<int, int> > q;

  REP(i,h) REP(j,w) if(g[i][j] == 0){
    if(i == 0 || i == h - 1 || j == 0 || j == w - 1){
      q.push(make_pair(i, j));
      g[i][j] = 2;
    }
  }

  while(q.size()){
    int x = q.front().second;
    int y = q.front().first;
    q.pop();

    REP(i,6){
      int yy = y + dy[y % 2][i];
      int xx = x + dx[y % 2][i];
      if(ISIN(xx, yy, w, h) && g[yy][xx] == 0){
        q.push(make_pair(yy, xx));
        g[yy][xx] = 2;
      }
    }
  }

  REP(i,h) REP(j,w) if(g[i][j] == 1){
    int cnt = 0;
    REP(k,6){
      int y = i + dy[i % 2][k];
      int x = j + dx[i % 2][k];
      if(!ISIN(x, y, w, h) || g[y][x] == 2)
        cnt++;
    }
    ans += cnt;
  }

  printf("%d\n", ans);

  return 0;
}

Measured memory_bytes: 0
#include <bits/stdc++.h>
#define int long long
#define fi first
#define se second
#define pb push_back
#define fastcin() ios_base::sync_with_stdio(0); cin.tie(0)
#define all(x) (x).begin(), (x).end()
#define heap priority_queue
using namespace std;
typedef pair<int, int> ii;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

const int maxn = 400; 
int n, a[maxn][maxn], ans; 

void ex() {
	cout << -1; 
	exit(0); 
}

signed main()
{
	cin >> n;
	vector<pair<int, ii> > v; 
	for(int i = 1; i <= n; i++) {
		for(int j = 1; j <= n; j++) {
			cin >> a[i][j]; 
			if(i < j) v.pb({a[i][j], {i, j}});
		}
	}
	for(int i = 1; i <= n; i++) 
		for(int j = 1; j <= n; j++)
			if(a[i][j] != a[j][i]) 
				ex(); 
				
	sort(all(v), [](pair<int, ii> x, pair<int, ii> y) {
		return x.fi < y.fi; 
	}); 
	for(auto x : v) {
		int d = x.fi, u = x.se.fi, v = x.se.se; 
		bool ok = 0; 
		for(int k = 1; k <= n; k++) 
			if(k != u and k != v) {
				if(a[u][k] + a[k][v] < a[u][v]) ex(); 
				if(a[u][k] + a[k][v] == a[u][v]) {
					ok = 1; 
					break; 
				}
			}
		if(!ok) ans += d; 
	} 
	cout << ans; 
}


Measured memory_bytes: 2424
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
const ll MOD=(ll)1e9+7;
const ll INF=(ll)1e18+10;
const double PI=acos(-1);

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; }
int dy[]={-1,1,0,0};
int dx[]={0,0,-1,1};

int main() {
    int N,K; cin>>N>>K;
    int ans=0;
    while(N>0){
        ans+=1;
        N/=K;
    }
    cout<<ans<<endl;
    return 0;
}


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

int main() {
  int x;
  cin >> x;
  int mod100 = x % 100;
  int n = x / 100;
  if (mod100 / 5 < n) {
    cout << 1 << endl;
  } else if (mod100 % 5 == 0 && mod100 / 5 <= n) {
    cout << 1 << endl;
  } else {
    cout << 0 << endl;
  }
  return 0;
}


Measured memory_bytes: 256
// clang-format off
#include <bits/stdc++.h>

#define mp make_pair
#define fst first
#define snd second
#define forn(i,n) for (int i = 0; i < int(n); i++)
#define forn1(i,n) for (int i = 1; i <= int(n); i++)
#define popcnt __builtin_popcount
#define ffs __builtin_ffs
#define ctz __builtin_ctz
#define clz __builtin_clz
#define all(a) (a).begin(), (a).end()
 
using namespace std;

using uint = unsigned int;
using ll = long long;
using ull = unsigned long long;
using pii = pair<int,int>;
using pli = pair<ll,int>;
using pil = pair<int,ll>;
using pll = pair<ll,ll>;
template <typename T> using vec = vector<T>;
using vi = vec<int>;
using vl = vec<ll>;
template <typename T> using que = queue<T>;
template <typename T> using deq = deque<T>;

template <typename T> T id(T b) {return b;};
template <typename T> void chmax(T &x, T y) {if (x < y) x = y;}
template <typename T> void chmin(T &x, T y) {if (x > y) x = y;}
template <typename S, typename K> bool contains(S &s, K k) { return s.find(k) != s.end(); }
void fastio() { ios_base::sync_with_stdio(false); cin.tie(nullptr); }
constexpr ll TEN(int n) { if (n == 0) return 1LL; else return 10LL*TEN(n-1); }
// clang-format on

const int MAX_N = 200000;
string s;
int t[MAX_N];

int main() {
    fastio();

    cin >> s;
    int n = s.size();
    transform(all(s), t, [](char c) { return c - '0'; });

    map<int, ll> cnt;
    cnt[0] = 1;

    int d = 1;
    int cur = 0;
    for (int i = n - 1; i >= 0; i--) {
        cur = (d * t[i] + cur) % 2019;
        cnt[cur]++;
        d = 10 * d % 2019;
    }

    ll ans = 0;
    for (auto [x, k] : cnt) {
        ans += k * (k - 1) / 2;
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 4520
#include<iostream>
#include<cstring>
#include<ctype.h>
using namespace std;

int main() {
    char S[10];
    cin >> S;

    int L = strlen(S);
    int c = 0;
    for (int i = 0; i < L; i++) {
        if (i == 0) {
            if(S[i] != 'A') {
                cout << "WA" << endl;
                return 0;
            }
        } else if (2 <= i && i < L - 1) {
            if (S[i] == 'C') c++;
            if (c > 1) {
                cout << "WA" << endl;
                return 0;
            }
        } else {
            if(islower(S[i]) == false) {
                cout << "WA" << endl;
                return 0;
            }
        }
    }
    if (c == 0) {
        cout << "WA" << endl;
        return 0;
    }

    cout << "AC" << endl;

    return 0;
}

Measured memory_bytes: 256
import math

ABN = list(map(int, input().split()))

#xがBの倍数であれば全体が0
#その一個手前が最大値

if (ABN[2] >= ABN[1]):
    print(math.floor(ABN[0] * (ABN[1] - 1) / ABN[1]))
else:
    print(math.floor(ABN[0] * ABN[2] / ABN[1]) - ABN[0] * math.floor(ABN[2] / ABN[1]))

Measured memory_bytes: 62100
h, w = map(int, input().split())
a = [0 for _ in range(26)]
for i in range(h):
    s = input()
    for j in range(w):
        a[ord(s[j]) - ord('a')] += 1
b = [0, 0, 0]
for i in range(26):
    if a[i] == 0:
        continue
    if a[i] % 4 == 0:
        b[2] += 1
    elif a[i] %2 == 0:
        b[1] += 1
    else:
        b[0] += 1
if h % 2 and w % 2:
    print("Yes" if b[1] <= (h+w-2) // 2 and b[0] == 1 else "No")
elif h % 2 and w % 2 == 0:
    print("Yes" if b[1] <= w // 2 and b[0] == 0 else "No")
elif h % 2 == 0 and w % 2:
    print("Yes" if b[1] <= h // 2 and b[0] == 0 else "No")
else:
    print("Yes" if b[1] == b[0] == 0 else "No")

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define INF 1LL<<62
#define inf 1000000007 

int main() {
	ll n,m;
	cin>>n>>m;
	map<ll,ll>a;
	for(ll i=0;i<n;i++){
		ll now;
		cin>>now;
		a[now]++;
	}
	for(ll i=0;i<m;i++){
		ll x,y;
		cin>>x>>y;
		a[y]+=x;
	}
	ll cnt=n;
	ll ans=0;
	auto itr=a.end();
	itr--;
	while(cnt>0){
		ll num=itr->first;
		ll now=itr->second;
		itr--;
		ans+=num*min(now,cnt);
		cnt-=now;
	}
	cout <<ans;
	return 0;
}

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

using namespace std;

#define int long long

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

const int IINF =  0x3f3f3f3f;
const ll LINF = 0x3f3f3f3f3f3f3f3fLL;
const int INF = sizeof(int) == sizeof(long long) ? LINF : IINF;
const ll MOD = 1e9+7;

#define for_(i,a,b) for(int i = (a);i < (b);i++)
#define rfor_(i,a,b) for(int i = (b)-1;i >= (a);i--)

#define rep(i,n) for_(i,0,n)
#define rrep(i,n) rfor_(i,0,n)

#define pb push_back
//#define eb emplace_back
#define mp make_pair
#define ft first
#define sd second

#define all(a) (a).begin(), (a).end()
#define sz(a) (int)(a).size()
#define rev(a) reverse(all(a))

#define endl '\n'

const int limit = 100007;

int n;
char a[200004];

int w[26];
int c;
int l;

signed main(){
  cin.tie(0);
  cout.tie(0);
  ios_base::sync_with_stdio(false);
  
  cin>>a;
  n = strlen(a);
  
  rep(i, n) {
    w[a[i]-'a']++;
  }
  
  /*
  for_(i, 1, n-1) {
    l=1;
    while(i-l>=0 && i+l<n) {
      if(a[i-l] == a[i+l])c++;
      l++;
    }
  }
  
  for_(i, 0, n-1) {
    l=0;
    while(i-l>=0 && i+l+1<n) {
      if(a[i-l] == a[i+l+1])c++;
      l++;
    }
  }
  */
  
  rep(i, 26)c += w[i]*(w[i]-1)/2;
  
  cout<<(n*(n-1)/2 - c + 1)<<endl;
  
  return 0;
}


Measured memory_bytes: 512
// code.begin();
#include<bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
using namespace std;
#define pb push_back 
#define what_is(x) cerr<<#x<<" is "<<x<<endl;
#define print(v) for(auto i:v) cout<<i<<" ";cout<<endl;
#define my_time ios_base::sync_with_stdio(false);cin.tie(NULL);
#define ll long long 
#define endl "\n"
#define MOD 1000000007
const long long int INF=1e18;
#define mod 1000000007
#pragma GCC target ("avx2")
#pragma GCC optimization ("O3")
#pragma GCC optimization ("unroll-loops")
typedef tree<int, null_type, less<int>, rb_tree_tag, 
             tree_order_statistics_node_update> 
    ordered_set; 
//find_by_order(x)
//order_of_key(x)  


int power(int x,unsigned int y)
{
    int res=1;
    
    while(y>0)
    {
        // if y is odd multiply with result
        if(y&1)
        res=res*x;
        
        y=y>>1; // y=y/2;
        x=x*x;
        
    }
    return res;
}

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

ll  max3(ll  a, ll  b, ll c)
{
    return max(c, max(a, b));
}
int min3(int a, int  b, int  c)
{
    return min(a, min(b, c));
}

int  powermod(int  x, int  y, int p )
{
    int res = 1;
    while (y > 0)
    {
        if (y & 1)
            res = (res * x) % p;
        y = y >> 1;
        x = (x * x) % p;
    }
    return res % p;
}
int logg(int  a)
{
    int  x = 0;
    while (a > 1)
    {
        x++;
        a /= 2;
    }
    return x;
}


int modinv(int x)
{
    return powermod(x, mod - 2, mod);
}



int  main(){
	my_time;



int t;
t=1;
//cin>>t;int test=0;
while(t--)
{
	
	int n;
	cin>>n;
	
	ll sum=0;
	
	int arr[n];
	for(int i=0;i<n;i++)
	{
		cin>>arr[i];
	}
	
	for(int i=1;i<n;i++)
	{
		if(arr[i]<arr[i-1])
		{
			sum+=abs(arr[i]-arr[i-1]);
			arr[i]=arr[i-1];
		}
	}
	cout<<sum<<endl;
	
	
}
    return 0;
}


//code.end();





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

int main()
{
    int e, y;

    cin >> e >> y;

    if( e == 0 )
    {
        if( y <= 1911 )
            cout << "M" << y - 1868 + 1 << endl;
        else if( y <= 1925 )
            cout << "T" << y - 1912 + 1 << endl;
        else if( y <= 1988 )
            cout << "S" << y - 1926 + 1 << endl;
        else
            cout << "H" << y - 1989 + 1 << endl;
    }
    else if( e == 1 )
        cout << y + 1867 << endl;
    else if( e == 2 )
        cout << y + 1911 << endl;
    else if( e == 3 )
        cout << y + 1925 << endl;
    else if( e == 4 )
        cout << y + 1988 << endl;
    else;

    return 0;
}


Measured memory_bytes: 3104
#include<iostream>

using namespace std;

int main()
{
  int ans,X;
  ans=0;
  cin>>X;
  
  while(X>=500)
  {
    ans+=1000;
    X-=500;
  }
  
  while(X>=5)
  {
    ans+=5;
    X-=5;
  }
  cout<<ans;
}
    


Measured memory_bytes: 256
#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <fstream>
#include <vector>
#include <set>
#include <algorithm>
#include <queue>
#include <string> 
#include <map>
#include <iomanip>
#include <list>
#include <stack>
#include <bitset>
#include <cmath>
using namespace std;


typedef int INT;
#define int long long

int c[2000];

INT main()
{
	ios::sync_with_stdio(false);
	cin.tie(NULL); cout.tie(NULL);
	int n, k, q;
	cin >> n >> k >> q;
	vector <int> a(n);
	for (int i = 0; i < n; i++)
		cin >> a[i]; 
	vector <int> b = a;

	sort(b.begin(), b.end());
	int cur = -1;
	for (int i = 0; i < n; i++)
	{
		vector <int> v;
		int vb = b[i];
		for (int j = 0; j < n; j++)
			c[j] = a[j];
		int l = -1, r = -1;
		for (int j = 0; j < n; j++)
		{
			if (a[j] >= vb)
			{
				if (l == -1)
					l = j;
			}
			else
			{
				if (l != -1)
				{
					r = j - 1;
					sort(c + l, c + r + 1);
					for (int u = l; u <= r - k + 1; u++)
					{
						v.push_back(c[u]);
					}
					l = -1;
				}
			}
		}
		if (l != -1)
		{
			r = n - 1;
			sort(c + l, c + r + 1);
			for (int u = l; u <= r - k + 1; u++)
			{
				v.push_back(c[u]);
			}
			l = -1;
		}
		sort(v.begin(), v.end());
		if (v.size() >= q)
		{
			if (cur == -1 || v[q - 1] - v[0] < cur)
				cur = v[q - 1] - v[0];
		}
	}
	cout << cur;


	return 0;
}

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

int main(){
    int n,k,r,s,p;
    string t;
    cin >> n >> k >> r >> s >> p >> t;
    vector<char> hand(n,'n');
    int ans=0;
    for(int i=0;i<n;i++){
        int point;
        char now_hand;
        if(t[i]=='r'){
            point=p;
            now_hand='p';
        }else if(t[i]=='s'){
            point=r;
            now_hand='r';
        }else if(t[i]=='p'){
            point=s;
            now_hand='s';
        }
        if(i-k>=0&&hand[i-k]==now_hand){
            point=0;
            now_hand='n';
        }
        ans+=point;
        hand[i]=now_hand;
    }
    cout << ans << endl;
}

Measured memory_bytes: 3848
#include<iostream>
using namespace std;
int main() {
	float syo, dai, c;
	dai = -1;
	syo = 1999999;
	while (cin >> c) {
		if (dai <= c) {
			dai = c;
		}
		if (syo >= c) {
			syo = c;
		}
	}
	cout << dai - syo << endl;
}


Measured memory_bytes: 3232
L = 1000
@memo = Array.new(4) {[]}

def doit(s, n = 1)
  return (s <= L) ? 1 : 0 if n == 4
  return @memo[n][s] if @memo[n][s]
  co = 0
  a = (s <= L) ? s : L
  (0..a).each do |i|
    co += doit(s - i, n + 1)
  end
  @memo[n][s] = co
end

$<.readlines.map(&:to_i).each do |s|
  puts doit(s)
end


Measured memory_bytes: 7012
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define REP(i,m,n) for(int i=(int)(m); i<(int)(n); i++)
#define rep(i,n) REP(i,0,n)
#define RREP(i,m,n) for(int i=(int)(m); i>=(int)(n); i--)
#define rrep(i,n) RREP(i,n-1,0)
#define all(v) v.begin(), v.end()
const int inf = 1e9+7;
const ll longinf = 1LL<<60;
const ll mod = 1e9+7;

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int n, m; cin >> n >> m;
  ll p = pow(2, m);
  ll t = 1900 * m + 100 * (n-m);
  cout << t*p << "\n";
  return 0;
}


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

#define ll long long

int main()
{
  	ios::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);

	ll a, b;
	scanf("%lld %lld", &a, &b);
	if(a < 6)
	{
		b = 0;
	}
	else if(a >= 6 && a <= 12)
	{
		b /= 2;
	}
	printf("%lld\n", b);
	return 0;
}

Measured memory_bytes: 3752
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
const int MOD = 1e9+7;


int main(){
  
  string s; cin>>s;
  int ans{};
  if(s.at(1)=='R'){
    if(s.at(0)=='R'&&s.at(2)=='R'){
      cout << 3 << endl;
    }
    else if(s.at(0)=='R'||s.at(2)=='R'){
      cout << 2 << endl;
    }
    else cout << 1 << endl;
  }
  else{
    if(s.at(0)=='R'||s.at(2)=='R'){
      cout << 1 << endl;
    }
    else cout << 0 << endl;
  }
  
  
}


Measured memory_bytes: 3624
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<vector>
#include<map>
using namespace std;
bool comp(int a,int b)
{
    return a>b;
}
int main()
{
    int n;
    cin >> n;
    vector<long long> ni(n);
    vector<long long> ni2(n);
    int t;
    long long k=0;
    for(t=0;t<n;t++)
        cin >> ni[t];
    while(1)
    {
        long long a=0;
        for(t=0;t<n;t++)
        {
            ni2[t] = ni[t]/n;
            a += ni2[t];
            ni[t] %= n;
        }
        if(a == 0)  break;
        k += a;
        for(t=0;t<n;t++)
        {
            int t1;
            for(t1=0;t1<n;t1++)
            {
                if(t != t1)
                    ni[t] += ni2[t1];
            }
        }
    }
    cout << k << endl;
    return 0;
}


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

using namespace std;

#define ll long long
#define pb push_back
#define mp make_pair
#define fst first
#define snd second

int main()
{
    string s;
    cin >> s;

    map<string, int> m;
    m["SUN"] = 7;
    m["MON"] = 6;
    m["TUE"] = 5;
    m["WED"] = 4;
    m["THU"] = 3;
    m["FRI"] = 2;
    m["SAT"] = 1;
    cout << m[s];

    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, n) for (ll i = 0; i < ll(n); i++)
#define rrep(i, n) for (int i = (n); i >= 0; i--)
#define loop(i, r, n) for (int i = (r); i < (n); i++)
#define pb push_back
#define all(in) in.begin(),in.end()

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 (b < a) { a = b; return 1; } return 0; }

using ll = long long;
using namespace std;
// cout << fixed << setprecision(10）<<  << endl;

int main() {
    ll n, x, m; cin >> n >> x >> m;
    vector<ll> sub(m,0ll);
    ll save = x;

    map<ll,ll> check;

    rep(i,n){
        if (save == 0) {
            ll ans = 0ll;
            rep(j,m) ans += sub[j];
            cout << ans << endl;
            return 0;
        }
        sub[i] = save;
        check[save]++;
        save = save * save % m;
        if (check[save] > 0ll) {
            ll id = -1;
            rep(j,m) if(sub[j] == save) { id = j; break; }
            ll ans = 0;
            rep(j,id) ans += sub[j];
            ll roop = 0;
            for (ll j = id; j <= i; j++) roop += sub[j];
            n -= id;
            ans += roop * (n / (i + 1 - id));
            n %= (i + 1 - id);
            rep(j,n) ans += sub[id+j];
            cout << ans << endl;
            return 0;
        }
    }
    ll ans = 0;
    rep(i,n) ans += sub[i];
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 7216
#include <stdio.h>

int main(){
  int a,b, maior=-2147428648;
  scanf("%d%d",&a,&b);
  if((a+b)>maior)
    maior = a+b;
  if((a-b)>maior)
    maior = a-b;
  if((a*b)>maior)
    maior = a*b;
  printf("%d\n",maior);
  return 0;
}


Measured memory_bytes: 128
using System;

public class Program
{
    private int H, W, N;
    private int[] A;

    public void Solve()
    {
        var sc = new Scanner();
        H = sc.NextInt();
        W = sc.NextInt();
        N = sc.NextInt();
        A = sc.IntArray();

        int index = 0;

        int[][] ans = new int[H][];
        for (int i = 0; i < H; i++)
        {
            ans[i] = new int[W];
        }

        int cnt = 0;
        for (int i = 0; i < H * W; i++)
        {
            int h = i / W;
            int w = i % W;
            if (h % 2 == 1)
            {
                w = W - 1 - w;
            }

            ans[h][w] = index + 1;
            cnt++;
            if (cnt >= A[index])
            {
                cnt = 0;
                index++;
            }
        }

        for (int i = 0; i < H; i++)
        {
            Console.WriteLine(string.Join(" ", ans[i]));
        }
    }

    public static void Main(string[] args)
    {
        new Program().Solve();
    }
}

class Scanner
{
    public Scanner()
    {
        _pos = 0;
        _line = new string[0];
    }

    const char Separator = ' ';
    private int _pos;
    private string[] _line;

    #region スペース区切りで取得

    public string Next()
    {
        if (_pos >= _line.Length)
        {
            _line = Console.ReadLine().Split(Separator);
            _pos = 0;
        }

        return _line[_pos++];
    }

    public int NextInt()
    {
        return int.Parse(Next());
    }

    public long NextLong()
    {
        return long.Parse(Next());
    }

    public double NextDouble()
    {
        return double.Parse(Next());
    }

    #endregion

    #region 型変換

    private int[] ToIntArray(string[] array)
    {
        var result = new int[array.Length];
        for (int i = 0; i < array.Length; i++)
        {
            result[i] = int.Parse(array[i]);
        }

        return result;
    }

    private long[] ToLongArray(string[] array)
    {
        var result = new long[array.Length];
        for (int i = 0; i < array.Length; i++)
        {
            result[i] = long.Parse(array[i]);
        }

        return result;
    }

    private double[] ToDoubleArray(string[] array)
    {
        var result = new double[array.Length];
        for (int i = 0; i < array.Length; i++)
        {
            result[i] = double.Parse(array[i]);
        }

        return result;
    }

    #endregion

    #region 配列取得

    public string[] Array()
    {
        if (_pos >= _line.Length)
            _line = Console.ReadLine().Split(Separator);

        _pos = _line.Length;
        return _line;
    }

    public int[] IntArray()
    {
        return ToIntArray(Array());
    }

    public long[] LongArray()
    {
        return ToLongArray(Array());
    }

    public double[] DoubleArray()
    {
        return ToDoubleArray(Array());
    }

    #endregion
}

Measured memory_bytes: 13396
from functools import reduce
from math import floor, ceil

# 入力
K = int(input())
A = list(map(int, input().split()))

# ラウンドKから1まで順に、子どもたちの人数として考えられる最小の値と最大の値を求める
R = reduce(
    lambda acc, a: (
        acc if acc[0] > acc[1] else
        (
            a * ceil(acc[0] / a),
            a * (floor(acc[1] / a) + 1) - 1
        )
    ),
    reversed(A),
    (2, 2)
)

# 出力
ans = -1 if R[0] > R[1] else ' '.join(map(str, R))
print(ans)


Measured memory_bytes: 14648
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<int,int>;
#define rep(i,n) for(ll i = 0; i < (ll)(n); i++)
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 (b<a) { a=b; return 1; } return 0; }
const ll INF = 1LL << 60;
vector<int> to[1005];
int n, m;

vector<int> bfs(int sv){
    vector<ll> dist(n,INF), pre(n,-1);
    queue<int> q;
    dist[sv] = 0;
    q.push(sv);
    while(!q.empty()){
        int v = q.front(); q.pop();
        for(auto tv : to[v]){
            if(dist[tv]!=INF) continue;
            dist[tv] = dist[v] + 1;
            pre[tv] = v;
            q.push(tv);
        }
    }
    pair<ll,int> best(INF, -1);
    rep(v,n){
        if(v==sv) continue;
        //cout << "v:" << v << " sv:" << sv << endl;
        for(auto u : to[v]){
            if(u==sv){
                //cout <<"v:" << u << " " << dist[v] <<  endl;
                if(dist[v]<best.first) best = make_pair(dist[v], v);
            }
        }
    }
    //cout << "best:" << best.first << " " << best.second << endl;
    if(best.first == INF) {return vector<int>(n+1);}
    vector<int> res;
    int v = best.second;
    while(v!=-1){
        res.push_back(v);
        //cout <<"sv:" << sv << "v:" << v << endl;
        v = pre[v];
    }
    //for(auto r : res) cout << "r:" << r << endl;
    return res;
}
int main(){
    cin >> n >> m;
    rep(i,m){
        int a,b;
        cin >> a >> b;
        a--; b--;
        to[a].push_back(b);
    }
    vector<int> ans(n+1);
    rep(s,n){
        auto now = bfs(s);
        if(now.size()<ans.size()) ans = now;
    }
    if(ans.size()==n+1){
        cout << -1 << endl;
        return 0;
    }
    cout << ans.size() << endl;
    for(auto v : ans){
        cout << v+1 << endl;
    }
    return 0;
}

Measured memory_bytes: 384
#include <iostream>
#include <algorithm>
#include <cmath>
#include <vector>
#include <complex>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <iomanip>
#include <assert.h>
#include <array>
#include <cstdio>
#include <cstring>
#include <random>
#include <functional>
#include <numeric>
#include <bitset>

using namespace std;

struct before_main{before_main(){cin.tie(0); ios::sync_with_stdio(false);}} before_main;

#define REP(i,a,b) for(int i=a;i<(int)b;i++)
#define rep(i,n) REP(i,0,n)
#define all(c) (c).begin(), (c).end()
#define zero(a) memset(a, 0, sizeof a)
#define minus(a) memset(a, -1, sizeof a)
template<class T1, class T2> inline bool minimize(T1 &a, T2 b) { return b < a && (a = b, 1); }
template<class T1, class T2> inline bool maximize(T1 &a, T2 b) { return a < b && (a = b, 1); }

typedef long long ll;
int const inf = 1<<29;

int main() {

  int N, m; cin >> N >> m;
  int v[1111] = {};
  rep(i, m) {
    int c, d; cin >> c >> d;
    REP(x, c, d) {
      v[x] ++;
    }
  }

  int ans = N+1;

  rep(i, 1111) {
    if(v[i]) {
      ans += 2;
    }
  }

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

Measured memory_bytes: 3224