akhauriyash/Code-Regression huggingface dataset:
#include <algorithm>
#include <array>
#include <bitset>
#include <cassert>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <limits>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdint.h>
#include <tuple>
#include <utility>
#include <vector>

using namespace std;

typedef long long ll;
typedef unsigned int uint;
typedef unsigned long long ull;
static const double EPS = 1e-12;
static const double PI = acos(-1.0);
static const ll MOD = 1000000007;

#define FOR(i, a, b) for (int i = (int)(a); i < (int)(b); i++)
#define REP(i, n) for (int i = 0; i < (int)(n); i++)
#define ALL(a) (a).begin(), (a).end()
#define DEBUG(x) cout << #x << ": " << x << endl

void solve(long long X) {
  ll y = 100;
  int i = 0;
  while (y < X) {
    y = (ll)(y * 1.01);
    i++;
  }
  cout << i << endl;
}

int main() {
  long long X;
  scanf("%lld", &X);
  solve(X);
  return 0;
}


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

int n, m, r, q;
int memo[10005][1270] = {0};
int sum[10005][1270] = {0};

void order();

int main() {
  while(1) {
    cin >> n >> m;
    if(n + m == 0) break;
    cin >> r;
    for(int i = 0; i < r; ++i) {
      int t, x, y, s;
      cin >> t >> x >> y >> s;
      --y;
      if(s)
        ++memo[y][t];
      else
        --memo[y][t];
    }
    order();
    cin >> q;
    for(int i = 0; i < q; ++i) {
      int from, to, num;
      cin >> from >> to >> num;
      --num;
      cout << sum[num][to - 1] - sum[num][from - 1] << endl;
    }
    for(int i = 0; i < m; ++i)
      for(int j = 0; j <= 1261; ++j)
        memo[i][j] = sum[i][j] = 0;
  }
  return 0;
}

void order() {
  for(int i = 0; i < m; ++i)
    for(int j = 1; j <= 1261; ++j) {
      memo[i][j] += memo[i][j - 1];
      sum[i][j] = sum[i][j - 1];
      if(memo[i][j] > 0) ++sum[i][j];
    }
}


Measured memory_bytes: 99172
import sys
from collections import defaultdict

n, k = map(int, input().split())
sushi = []
for line in sys.stdin.readlines():
    t, d = map(int, line.split())
    sushi.append((d, t))
sushi.sort(reverse=True)

deli = 0
cnt = defaultdict(lambda: 0)
using = sushi[:k]

for d, t in sushi[:k]:
    deli += d
    cnt[t] += 1

types = len(cnt)
ans = deli + types ** 2

for d, t in sushi[k:]:
    if cnt[t] > 0:
        continue
    d2, t2 = None, None
    while using:
        d2, t2 = using.pop()
        if cnt[t2] > 1:
            break
    else:
        break
    cnt[t2] -= 1
    cnt[t] += 1
    types += 1
    deli += d - d2
    ans = max(ans, deli + types ** 2)

print(ans)


Measured memory_bytes: 24832
import java.io.*;

class Main{
	public static void main(String[]args)throws IOException{
		
		BufferedReader br=
			new BufferedReader(new InputStreamReader(System.in));
		
		String str=br.readLine();

		String[] num=str.split(" ");

		int a=Integer.parseInt(num[0]);
		int b=Integer.parseInt(num[1]);
		int c=Integer.parseInt(num[2]);
		
		int tmp;
		
		if(a>c){
			tmp=a;
			a=c;
			c=tmp;
		}
		if(a>b){
			tmp=a;
			a=b;
			b=tmp;
		}
		if(b>c){
			tmp=b;
			b=c;
			c=tmp;
		}
		System.out.println(a+" "+b+" "+c);
	}
}

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

int main() {
  int A, B, C, K;
  cin >> A >> B >> C >> K;
  
  if ( A >= K ){
    cout << K << endl;
  }
  else if ( A + B >= K){
    cout << A << endl;
  }
  else {
    cout << A - ( K - ( A + B )) << endl;
  }
}



Measured memory_bytes: 3632
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<iomanip>
#include<math.h>
#include<complex>
#include<queue>
#include<deque>
#include<stack>
#include<map>
#include<set>
#include<bitset>
#include<functional>
#include<assert.h>
#include<numeric>
using namespace std;
#define REP(i,m,n) for(int i=(int)(m) ; i < (int) (n) ; ++i )
#define rep(i,n) REP(i,0,n)
using ll = long long;
constexpr int inf=1e9+7;
constexpr ll longinf=1LL<<60 ;
constexpr ll mod=1e9+7 ;


string res;

int counter;

int query(string& s){
    ++counter;
    cout<<"? "<<s<<endl;
    int ret;
    cin>>ret;
    return ret;
}

const int m = 62;
int cnt[62][200], n;
string ans, cha;

void solve(int l, int r){
    if(l+1==r){
        rep(i,m)if(cnt[i][r]!=cnt[i][l]){
            ans[l]=cha[i];
            return;
        }
    }
    int mid=(l+r)/2;
    int sum = 0, num = 0;
    vector<int> c(m);
    int j = -1;
    vector<int> rem;
    REP(i,0,m){
        if(cnt[i][l]==cnt[i][r]){
            cnt[i][mid]=cnt[i][l];
            sum -= cnt[i][l];
            j=i;
        }
        else rem.push_back(i);
    }
    if(j == -1){
        for(auto i : rem){
            if(i == 0)continue;
            string s(n, 'a');
            REP(k,0,mid)s[k]=cha[i];
            c[i] = query(s) - n + cnt[0][n];
            sum += c[i];
            num++;
        }
        assert((mid+sum)%(num+1)==0);
        int ret = (mid + sum)/(num + 1);
        cnt[0][mid]=cnt[0][0]+ret;
        REP(i,1,m){
            if(cnt[i][l]==cnt[i][r]){
                continue;
            }
            cnt[i][mid]=cnt[i][0]-c[i]+ret;
        }
    }
    else {
        sum += cnt[j][l];
        for(auto i : rem){
            if(i == rem.back()){
                c[i] = (rem.size()+1)*cnt[j][mid] - sum - mid;
                continue;
            }
            string s(n, cha[j]);
            REP(k,0,mid)s[k]=cha[i];
            c[i] = query(s) - n + cnt[j][n];
            sum += c[i];
        }
        for(auto i : rem){
            cnt[i][mid]=cnt[i][0]-c[i]+cnt[j][mid];
        }
    }
    solve(l,mid);
    solve(mid,r);
}

int main(){
    rep(i,26)cha += 'a'+i;
    rep(i,26)cha += 'A'+i;
    rep(i,10)cha += '0'+i;
    vector<int> c(m); 
    rep(i,m){
        string s(128,cha[i]);
        c[i]=query(s);
        n += 128 - c[i];
    }
    rep(i,m)cnt[i][n]=128-c[i];
    ans.resize(n, '-');
    solve(0,n);
    if(counter>761){
        cout<<3<<endl;
    }
    cout<<"! "<<ans<<endl;
}


Measured memory_bytes: 3768
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstring>
#include <queue>
#include <vector>
#include <set>
using namespace std;
int read()
{
	char a=getchar();int res=0,f=1;
	while(a<'0'||a>'9'){if(a=='-')f=-1;a=getchar();}
	while(a>='0'&&a<='9')res=res*10+a-'0',a=getchar();
	return res*f;
}
const int inf=0x3f3f3f3f;
struct TR{
	int l,r;
	int tag,max;
}tr[300005*4];
#define ls ro<<1
#define rs ro<<1|1
void build(int ro,int lt,int rt)
{
	tr[ro].l=lt; tr[ro].r=rt;
	tr[ro].max=tr[ro].tag=0;
	if(lt==rt) return ;
	int mid=(lt+rt)>>1;
	build(ls,lt,mid); build(rs,mid+1,rt);
}
void ins(int ro,int lt,int rt,int c)
{
	if(lt>rt) return ;
	if(tr[ro].l==lt&&tr[ro].r==rt)
		tr[ro].tag+=c,tr[ro].max+=c;
	else {
		int mid=(tr[ro].l+tr[ro].r)>>1;
		if(rt<=mid) ins(ls,lt,rt,c); else if(lt>mid) ins(rs,lt,rt,c);
		else ins(ls,lt,mid,c),ins(rs,mid+1,rt,c);
		tr[ro].max=tr[ro].tag+max(tr[ls].max,tr[rs].max);
	}
}
#undef ls
#undef rs
struct P{
	int x,y;
}p[300005];
bool comy(P a,P b){return a.y<b.y;}
struct N{
	int id,v;
	N(){}
	N(int a,int b):id(a),v(b){}
}q1[300005*2],q2[300005*2];
int n,m,K,ans=0;
void work()
{
	sort(p+1,p+1+K,comy);
	int t1=0,t2=0,mid=n>>1;
	q1[++t1]=N(-1,mid); q1[++t1]=N(0,0);
	q2[++t2]=N(-1,mid+1); q2[++t2]=N(0,n);
	build(1,0,K); ins(1,0,0,n);
	for(int i=1;i<=K;i++){
		ans=max(ans,(tr[1].max+p[i].y)*2);
		if(p[i].x<=mid){
			while(t1&&p[i].x>q1[t1].v){
				ins(1,q1[t1-1].id+1,q1[t1].id,q1[t1].v-p[i].x);
				t1--;
			} q1[++t1]=N(i-1,p[i].x);
		} else {
			while(t2&&p[i].x<q2[t2].v){
				ins(1,q2[t2-1].id+1,q2[t2].id,p[i].x-q2[t2].v);
				t2--;
			} q2[++t2]=N(i-1,p[i].x);
		} q1[++t1]=N(i,0); q2[++t2]=N(i,n);
		ins(1,i,i,n-p[i].y);
	} ans=max(ans,(tr[1].max+m)*2);
}
int main()
{
	n=read(); m=read(); K=read();
	for(int i=1;i<=K;i++)
		p[i].x=read(),p[i].y=read();
	work();
	for(int i=1;i<=K;i++)
		swap(p[i].x,p[i].y);
	swap(n,m);
	work(); printf("%d\n",ans);
	return 0;
}

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

int main(){
  int N; cin >> N; string S; cin >> S;
  if( N % 2 == 1){ cout << "No" << endl; return 0;}
  
  if( S.substr(0,N/2) == S.substr(N/2,N/2)){ cout << "Yes" << endl; return 0;}
  else{ cout << "No" << endl; return 0;
      }
}

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

typedef long long ll;
const ll MOD = 1e9 + 7;
const ll inf = 1LL<<60;
const double eps = 1e-9;

int main()
{
    int sx, sy, tx, ty;
    cin >> sx >> sy >> tx >> ty;

    for (int i = 0; i < ty-sy; i++) cout << "U";
    for (int i = 0; i < tx-sx; i++) cout << "R";
    for (int i = 0; i < ty-sy; i++) cout << "D";
    for (int i = 0; i < tx-sx; i++) cout << "L";
    cout << "L";
    for (int i = 0; i < ty-sy+1; i++) cout << "U";
    for (int i = 0; i < tx-sx+1; i++) cout << "R";
    cout << "DR";
    for (int i = 0; i < ty-sy+1; i++) cout << "D";
    for (int i = 0; i < tx-sx+1; i++) cout << "L";
    cout << "U" << endl;    
    return 0;
}

Measured memory_bytes: 256
import java.util.*;

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

    int n = sc.nextInt();
    int[] d = new int[n];
    int ans = 0;
    
    for (int i = 0; i < n; i++) {
      d[i] = sc.nextInt();
      for (int j = 0; j < i; j++) {
        ans += d[j] * d[i];
      }
    }
    
    System.out.println(ans);
  }
}


Measured memory_bytes: 23508
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <string>
#include <cstring>
#include <deque>
#include <list>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <complex>
#include <cmath>
#include <limits>
#include <cfloat>
#include <climits>
#include <ctime>
#include <cassert>
#include <numeric>
using namespace std;

#define rep(i,a,n) for(int (i)=(a); (i)<(n); (i)++)
#define repq(i,a,n) for(int (i)=(a); (i)<=(n); (i)++)
#define repr(i,a,n) for(int (i)=(a); (i)>=(n); (i)--)
#define all(v) begin(v), end(v)
#define pb(a) push_back(a)
#define fr first
#define sc second
#define INF 2000000000
#define int long long int

#define X real()
#define Y imag()
#define EPS (1e-10)
#define EQ(a,b) (abs((a) - (b)) < EPS)
#define EQV(a,b) ( EQ((a).X, (b).X) && EQ((a).Y, (b).Y) )
#define LE(n, m) ((n) < (m) + EPS)
#define LEQ(n, m) ((n) <= (m) + EPS)
#define GE(n, m) ((n) + EPS > (m))
#define GEQ(n, m) ((n) + EPS >= (m))

typedef vector<int> VI;
typedef vector<VI> MAT;
typedef pair<int, int> pii;
typedef long long ll;

typedef complex<double> P;
typedef pair<P, P> L;
typedef pair<P, double> C;

int dx[]={1, -1, 0, 0};
int dy[]={0, 0, 1, -1};
int const MOD = 1000000007;
ll mod_pow(ll x, ll n) {return (!n)?1:(mod_pow((x*x)%MOD,n/2)*((n&1)?x:1))%MOD;}
int madd(int a, int b) {return (a + b) % MOD;}
int msub(int a, int b) {return (a - b + MOD) % MOD;}
int mmul(int a, int b) {return (a * b) % MOD;}
int minv(int a) {return mod_pow(a, MOD-2);}
int mdiv(int a, int b) {return mmul(a, minv(b));}

namespace std {
    bool operator<(const P& a, const P& b) {
        return a.X != b.X ? a.X < b.X : a.Y < b.Y;
    }
}

int n, k;
int num[100010], sum[100010];

signed main() {
    cin >> n >> k;
    vector<pii> v;
    repq(i,1,n) {
        int a, b;
        cin >> a >> b;
        v.push_back(pii(a, b));
    }
    sort(v.begin(), v.end());

    repq(i,1,n) {
        num[i] = v[i-1].first;
        sum[i] = sum[i-1] + v[i-1].second;
        // printf("debug: i = %lld, num = %lld, sum = %lld\n", i, num[i], sum[i]);
    }
    int idx = lower_bound(sum, sum+(n+1), k) - sum;
    cout << num[idx] << endl;
    return 0;
}

Measured memory_bytes: 3440
#include<bits/stdc++.h>
using namespace std;
long long a,b,c,d;
int main()
{
	cin>>a>>b>>c>>d;
	a--;
	printf("%lld",b-a-b/c+a/c-b/d+a/d+b/(c*d/__gcd(c,d))-a/(c*d/__gcd(c,d)));
}

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

int main(void){
    
    int h,w;
    
    cin >> h >> w;
    
    string s[50];
    int i,j;
    
    for(i=0;i<h;++i){
        cin >> s[i];
        //cout << s[i] <<endl;
    }
    
    int dx[8] = {-1,0,1,-1,1,-1,0,1};
    int dy[8] = {1,1,1,0,0,-1,-1,-1};
    
    for(i=0;i<h;++i){
        for(j=0;j<w;++j){
            
            if(s[i][j]=='#')continue;
            
            int num = 0;
            
            for(int d=0;d<8;++d){
                
                //int num = 0;
                int nx = i+dx[d];
                int ny = j+dy[d];
                
                if(nx<0 || nx>=h)continue;
                if(ny<0 || ny>=w)continue;
                if(s[nx][ny]=='#')num++;
                
            }
            
            s[i][j]=('0'+num);
            
        }
    }
    
    for(i=0;i<h;++i) cout << s[i] << endl;
    
    return 0;
    
}


Measured memory_bytes: 256
import math
from operator import itemgetter
N,D,A=map(int,input().split())
l=[]
for i in range(N):
  k=tuple(map(int,input().split()))
  l.append(k)
l.sort(key=itemgetter(0))
S=[0]*N
ma=[0]*N
tmp=N-1
for i in reversed(range(N)):
  x=l[i][0]
  for j in reversed(range(0,tmp)):
    if abs(l[j][0]-(x-D))>D:
      ma[i]=j+1
      tmp=j+1
      break
  else:
    ma[i]=0
    tmp=0
ans=0
S[0]=math.ceil(l[0][1]/A)
for i in range(1,N):
  h=l[i][1]
  left=S[ma[i]-1] if ma[i]>0 else 0
  right=S[i-1]
  sum_=(right-left)*A
  if h<=sum_:
    S[i]=S[i-1]
    continue
  time=math.ceil((h-sum_)/A)
  S[i]=time+S[i-1]
print(S[N-1])

Measured memory_bytes: 102616
N,M = [int(i) for i in input().split()]
point = []
for i in range(N):
    point.append(list(map(int, input().split())))
point = [list(i) for i in zip(*point)]

beauty=point[0]
taste=point[1]
popularity=point[2]
D = 0
goodcake=[0 for i in range(N)]
for i in range(2):
    for j in range(2):
        for k in range(2):
            for l in range(N):
                goodcake[l] = (1-2*i)*(beauty[l])+(1-2*j)*(taste[l])+(1-2*k)*(popularity[l])
            goodcake = sorted(goodcake)
            D = max(D,abs(sum(goodcake[0:M])))
print(D)

Measured memory_bytes: 3316
#include<bits/stdc++.h>
#define N 5005
using namespace std;
int n,k;
char a[N],ans[N],now[N];

bool leq(char *a,char *b) 
{
	for(int i=0;i<n;++i)
	{
		if(a[i] < b[i]) return true;
		if(a[i] > b[i])	return false;
	}
	return false;
}
int main()
{
	scanf("%d%d%s",&n,&k,a);
	k = min(k,30);
	for(int i=0;i<n;++i) ans[i] = 'z';
	int mn = 'z',len = 0,mx = 0;
	for(int i=0;i<n;++i) if(mn > a[i]) mn = a[i];
	for(int i=0;i<n;++i)
	{
		if(mn != a[i]) len = 0; else ++len;
		mx = max(mx,len);
	}
	len = 0;
	for(int i=0;i<n;++i)
	{
		if(mn != a[i]) len = 0; else ++len;
		if(i == n - 1 && a[i] == mn)
		{
			int tmp = min(n,(1<<k) * len);
			for(int j=0;j<tmp;++j) now[j] = mn;
			for(int j=tmp,k=n - len - 1;j<n;++j,--k) now[j] = a[k];
			if(leq(now,ans)) for(int j=0;j<n;++j) ans[j] = now[j];
		}
		if(len == mx)
		{
			int tmp = min(n,(1<<(k-1)) * len);
			for(int j=0;j<tmp;++j) now[j] = mn;
			for(int j=tmp,k=i+1;j<n;++j,++k) now[j] = a[k < n ? k : 2 * n - k - 1];
			if(leq(now,ans)) for(int j=0;j<n;++j) ans[j] = now[j];
		}
	}
	for(int i=0;i<n;++i) printf("%c",ans[i]);
	return 0;
}

Measured memory_bytes: 256
import heapq

n,m = map(int,input().split())
a = list(map(lambda x: int(x)*(-1),input().split()))
heapq.heapify(a)

for i in range(m):
    tmp_min = heapq.heappop(a)
    heapq.heappush(a,(-1)*(-tmp_min//2))
print(-sum(a))

Measured memory_bytes: 14180
#define _USE_MATH_DEFINES
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cctype>
#include <clocale>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <deque>
#include <fstream>
#include <functional>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <list>
#include <map>
#include <queue>
#include <regex>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <tuple>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>

using namespace std;

#define IOS ios::sync_with_stdio(false); cin.tie(0);
#define FOR(i, s, n) for(int i = (s), i##_len=(n); i < i##_len; ++i)
#define FORS(i, s, n) for(int i = (s), i##_len=(n); i <= i##_len; ++i)
#define VFOR(i, s, n) for(int i = (s); i < (n); ++i)
#define VFORS(i, s, n) for(int i = (s); i <= (n); ++i)
#define REP(i, n) FOR(i, 0, n)
#define REPS(i, n) FORS(i, 0, n)
#define VREP(i, n) VFOR(i, 0, n)
#define VREPS(i, n) VFORS(i, 0, n)
#define RFOR(i, s, n) for(int i = (s), i##_len=(n); i >= i##_len; --i)
#define RFORS(i, s, n) for(int i = (s), i##_len=(n); i > i##_len; --i)
#define RREP(i, n) RFOR(i, n, 0)
#define RREPS(i, n) RFORS(i, n, 0)
#define ALL(v) (v).begin(), (v).end()
#define SORT(v) sort(ALL(v))
#define RSORT(v) sort(ALL(v), greater<decltype(v[0])>())
#define SZ(x) ((int)(x).size())
#define PB push_back
#define EB emplace_back
#define MP make_pair
#define MT make_tuple
#define BIT(n) (1LL<<(n))
#define UNIQUE(v) v.erase(unique(ALL(v)), v.end())

using ll = long long;
using ui = unsigned int;
using ull = unsigned long long;
using Pi_i = pair<int, int>;
using VB = vector<bool>;
using VC = vector<char>;
using VD = vector<double>;
using VI = vector<int>;
using VLL = vector<ll>;
using VS = vector<string>;
using VSH = vector<short>;
using VULL = vector<ull>;

const int MOD = 1000000007;
const int INF = 1000000000;
const int NIL = -1;
const double EPS = 1E-10;

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




ll gcd(ll a, ll b){
    if(!b) return a;
    if(a % b) return gcd(b, a % b);
    return b;
}

ll lcm(ll a, ll b){
    ll g = gcd(a, b);
    return a / g * b;
}

int main(){
    ll N, M; cin >> N >> M;
    VLL a(N);
    REP(i, N) cin >> a[i];
    ll l = a[0];
    FOR(i, 1, N){
        l = lcm(l, a[i]);
        if(l > 2*M){
            cout << 0 << endl;
            return 0;
        }
    }
    l /= 2;
    REP(i, N){
        if(!(l % a[i])){
            cout << 0 << endl;
            return 0;
        }
    }
    /*if(!(l % 2)){
        cout << 0 << endl;
        return 0;
    }*/
    ll ans = ((M/l) + 1) / 2;
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 1024
using System;
class Program
{
	static void Main(string[] args)
	{
		string[] a = Console.ReadLine().Split(' ');
		int n = int.Parse(a[0]);
		int k = int.Parse(a[1]);
		string[] d = Console.ReadLine().Split(' ');
		int e = 0;
		for (int i = 0; i < k; i++)
		{
			e += int.Parse(d[i]);
		}
		int f = e;
		for (int i = 0; i < n-k; i++)
		{
			f -= int.Parse(d[i]);
			f += int.Parse(d[i + k]);
			if (f>e)
			{
				e = f;
			}
		}
		double g;
		g = (e + k) / (double)2;		
		Console.WriteLine(g);
	}
}


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

int digsum(string n) {
    int res = 0;
    for(const auto s : n){
        res += s - '0';
    }
    return res;
}

int main(){

    while(true){
        string x;
        cin >> x;
        if(x[0] - '0' == 0){
            break;
        }
        cout << digsum(x) << endl;
    }

    return 0;
}


Measured memory_bytes: 3184
//package src.com.jetman.atcoder;

import java.util.*;

/**
 * @description:
 * @author: Jetman
 * @create: 2020-08-29 14:39
 **/
public class Main {

    Scanner sc = new Scanner(System.in);

    long MOD = 998244353L;

    long dp[];

    private void slove() {

        long n = sc.nextLong();
        long x = sc.nextInt();
        long m = sc.nextInt();

        int[] flag = new int[(int)m+1];
        int index = 1;
        long tmp = x;
        flag[(int)x] = 1;
        long sum = x;
        int lun = 0;
        long start = 0;
        long[] allSum = new long[100003];
        allSum[1] = x;
        while (true) {
            if (index == n) {
                break;
            }
            tmp = (tmp*tmp)%m;
            index++;
            if (flag[(int)tmp] > 0) {
                lun = index - flag[(int)tmp];
                start = tmp;
                break;
            }
            flag[(int)tmp] = index;
            sum = (sum+tmp);
            allSum[index] = allSum[index-1] + tmp;
        }

        if ((long)index < n) {
            x = start;
            n = n-index+1;
            sum = sum + ((allSum[index-1] - allSum[index-lun-1]) * (n/lun));
            long nu = n%lun;
            tmp = x;
            for (int i = 0; i < nu; i++) {
                sum = (sum+(tmp));
                tmp = (tmp*tmp)%m;
            }
        }
        System.out.println(sum);



    }

    private void build(Map<Integer, List<Integer>> edge, int l, int r) {
        List<Integer> list = edge.getOrDefault(l, new ArrayList<>());
        list.add(r);
        edge.put(l,list);
    }


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


Measured memory_bytes: 36976
//高知能系Vtuberの高井茅乃です。
//Twitter: https://twitter.com/takaichino
//YouTube: https://www.youtube.com/channel/UCTOxnI3eOI_o1HRgzq-LEZw

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

#define INF INT_MAX
#define LLINF LLONG_MAX
#define REP(i,n) for(int i=0;i<n;i++)
#define REP1(i,n) for(int i=1;i<=n;i++)
#define MODA 1000000007 

template <typename T>
std::istream& operator>>(std::istream& is, std::vector<T>& vec) {
    for (T& x: vec) { is >> x; }
    return is;
}

int main() {
	ll ans = 0;
	ll tmp;
	int n; cin >> n;
	int co[1000001] = {};
	REP(i, n){
		cin >> tmp;
		co[tmp]++;
	}
	REP1(i, 1000000){
		if(co[i] == 0) continue;
		if(co[i] == 1) ans ++;
		int target = i;
		for(int gen = target; gen <= 1000000; gen += target ){
			co[gen] = 0;
		}
	}
	cout << ans << endl;
}

Measured memory_bytes: 7552
#input of int(split by space)
def get_i()
  return gets.chomp.split(" ").map(&:to_i)
end
#input of float(split by space)
def get_f()
  return gets.chomp.split(" ").map(&:to_f)
end
#input of string(split by space)
def get()
  return gets.chomp.split(" ")
end
#input of string(split per one character)
def get_nsp()
  return gets.chomp.split("")
end
#yes or no decision
def yn_judge(bool,y="Yes",n="No")
  return bool ? y : n 
end
#create of array
def array(size1,init=nil,size2=-1)
  if size2==-1
    return Array.new(size1){init}
  else
    return Array.new(size2){Array.new(size1){init}}
  end
end

def max(a,b)
    return a>b ? a : b
end

def min(a,b)
    return a>b ? b : a
end

INF=Float::INFINITY

S=get_nsp
N=S.size
ans=0
cnt=0
S.each do|s|
    if s=="B"
        cnt+=1
    else
        ans+=cnt
    end
end
puts ans

Measured memory_bytes: 16764
#include<iostream>
#include<vector>
#include<algorithm>
#include<cmath>
#include<string>
#include<map>
#include<set>
#include<queue>

using namespace std;

#define rep(i, n) for(int i = 0; i < n; i++)
#define repn(i, n) for(int i = 1; i <= n; i++)
#define repr(i, n) for(int i = (n-1); i >= 0; i--)
#define all(x) (x).begin(), (x).end()
#define lint long long

int main(){
    lint n, k; cin >> n >> k;
    lint ans;
    if(k % 2 == 0){
        lint p = n / k;
        lint q = 2 * n / k - p;
        ans = p*p*p + q*q*q;
    }
    else{
        lint p = n / k;
        ans = p*p*p;
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;

class Program
{
    public static void Main( )
    {
        var input = Console.ReadLine( ).Split( ).Select( int.Parse ).ToArray( );
        int N = input[ 0 ];
        int M = input[ 1 ];
        long ans = 0;

        if ( N == 1 && M == 1 ) ans = 1;
        else if ( N == 1 || M == 1 ) ans = Math.Max( N, M ) - 2;
        else if ( N > 2 && M > 2 ) ans = 1L * ( N - 2 ) * ( M - 2 );
        Console.WriteLine(ans);
    }
}

Measured memory_bytes: 27772
#include <iostream>
#include <vector>
#include <stack>
#include <algorithm>
using namespace std;

typedef pair<int, int> P;

int to_d(int x, int y, int R, int C)
{
    if (y == 0)
        return x;
    else if (x == R)
        return y + R;
    else if (y == C)
        return (R - x) + R + C;
    else
        return (C - y) + R + C + R;
}

int main()
{
    int R, C, N;
    cin >> R >> C >> N;

    vector<P> d;

    int x1, y1, x2, y2;
    for (int i = 0; i < N; i++) {
        cin >> x1 >> y1 >> x2 >> y2;
        if ((x1 == 0 || x1 == R || y1 == 0 || y1 == C)
                && (x2 == 0 || x2 == R || y2 == 0 || y2 == C)) {
            d.push_back(P(to_d(x1, y1, R, C), i));
            d.push_back(P(to_d(x2, y2, R, C), i));
        }
    }

    sort(begin(d), end(d));

    stack<int> s;
    for (P di : d) {
        int i = di.second;
        if (s.empty() || s.top() != i)
            s.push(i);
        else
            s.pop();
    }

    if (s.empty())
        cout << "YES" << endl;
    else
        cout << "NO" << endl;
}

Measured memory_bytes: 2420
import sys
input = sys.stdin.readline

n=int(input())
l=[['0']*10 for _ in range(n)]
for i in range(n):
        a=str(input())
        for j in range(10):
                l[i][j]=a[j]
        l[i].sort()
l.sort()

c=0
d=[]
for j in range(n-1):
        if l[j]==l[j+1] and j==n-2:
                c+=2
                d.append(c)
        elif l[j]==l[j+1]:
                c+=1
        else:
                c+=1
                d.append(c)
                c=0
aa=0
for k in range(len(d)):
        aa+=d[k]*(d[k]-1)//2
print(aa)

Measured memory_bytes: 20648
N, M = list(map(int, input().split()))
A = [input() for i in range(N)]
B = [input() for i in range(M)]

ans = "No"

for i in range(N-M+1):
    for j in range(N-M+1):
        t = [k[j:j+M] for k in A[i:i+M]]
        if t == B:
            ans = "Yes"
 
print(ans)


Measured memory_bytes: 3060
#include <iostream>
#include <vector>
#include <string>
#include <cmath>
#include <algorithm>
#include <utility>
#include <queue>
#include <set>
#include <map>
#include <deque>
#include <iomanip>
#include <cstdio>
#include <stack>

using namespace std;
typedef  long long ll;
typedef pair<int,int> PII;
typedef vector<int> VI;
typedef vector<VI> VVI;
#define  MP make_pair
#define  PB push_back
#define inf  1000000007
#define rep(i,n) for(int i=0;i<(int)(n);++i)

vector<ll> dev;
vector<int> id;

void prime_factor(ll N){
	for(ll i=2;i*i<=N;i++){
		int cnt = 0;
		while(N%i == 0){
			cnt++;
			N /= i;
		}
		if(cnt){
			dev.push_back(i);
			id.push_back(cnt);
		}
	}
	if(N != 1){
		dev.push_back(N);
		id.push_back(1);
	}
	return;
}

#define MAX_N 200005
#define MOD 1000000007

//どこかでmake()することを忘れずに
ll inv[MAX_N],fac[MAX_N],finv[MAX_N];

void make()
{
	fac[0] = fac[1] = 1;
	finv[0] = finv[1] = 1;
	inv[1] = 1;
	for(int i=2;i<MAX_N;i++){
		inv[i] = MOD - inv[MOD%i] * (MOD/i) % MOD;
		fac[i] = fac[i-1] * (ll) i % MOD;
		finv[i] = finv[i-1] * inv[i] % MOD;
	}
}

ll comb(int a,int b)
{
	if(a<b){
		return 0;
	}
	return fac[a] * (finv[b] * finv[a-b] % MOD) % MOD;
}

int main(){
    ll n,m;
    cin >> n >> m;
    prime_factor(m);
    make();
    ll ans = 1;
    rep(i,dev.size()){
        ans *= comb(n+id[i]-1,id[i]);
        ans %= MOD;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 4992
#include<iostream>
#include<string>
#include<algorithm>

using namespace std;

int main() {
	int MOD = 1000000007;
	int factor[1001] = {};
	long long n, ans = 1;
	cin >> n;
	for (int i = 2; i <= n; i++) {
		int divide = 2;
		int num = i;
		while (num != 1) {
			if (!(num % divide))factor[divide]++,num /= divide;
			else divide++;
		}
	}
	for (int i = 2; i <= n; i++) {
		ans = ans * (factor[i] + 1);
		ans %= MOD;
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
#pragma comment(linker, "/stack:247474112")
#pragma GCC optimize("Ofast")

#include <bits/stdc++.h>
#define REP(i, n) for(ll i = 0; i < n; ++i)
#define RANGE(i, x, n) for(ll i = x; i < n; ++i)
using namespace std;
typedef long long ll;
const int INF = 0x3f3f3f3f;

void accelerate()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
}

int n, q;
string s;
vector<pair<char, char>> Q;

bool Cr(int k)
{
    int pos = k;
    REP(i, q) {
        char c, d;
        c = Q[i].first;
        d = Q[i].second;
        if(d == 'R') {
            if(s[pos] == c) {
                if(pos == n-1) {
                    return true;
                }else {
                    ++pos;
                }
            }
        }else {
            if(s[pos] == c) {
                if(pos == 0) continue;
                else --pos;
            }
        }
    }
    return false;
}

bool Cl(int k)
{
    int pos = k;
    REP(i, q) {
        char c, d;
        c = Q[i].first;
        d = Q[i].second;
        if(d == 'R') {
            if(s[pos] == c) {
                if(pos == n-1) {
                    continue;
                }else {
                    ++pos;
                }
            }
        }else {
            if(s[pos] == c) {
                if(pos == 0) return true;
                else --pos;
            }
        }
    }
    return false;
}

int main()
{
    accelerate();
    cin >> n >> q;
    cin >> s;
    Q.resize(q);
    REP(i, q) {
        char c, d;
        cin >> c >> d;
        Q[i].first = c;
        Q[i].second = d;
    }

    int l, r, m;
    l = 0, r = n;
    m = (l+r)>>1;
    int ans = n;
    while(r - l > 1) {
        if(Cr(m)) {
            r = m;
        }else {
            l = m;
        }
        m = (l+r)>>1;
    }
    if(Cr(l)) {
        cout << 0 << endl;
        return 0;
    }else if(r == n) {
        ans = n;
    }else {
        ans = r;
    }

    l = 0, r = n;
    m = (l+r) >> 1;
    while(r - l > 1) {
        if(Cl(m)) {
            l = m;
        }else {
            r = m;
        }
        m = (l+r)>>1;
    }
    if(Cl(l)) {
        if(l+1 > ans) {
            cout << 0 << endl;
            return 0;
        }else {
            cout << ans - l - 1 << endl;
            return 0;
        }
    }else {
        cout << ans << endl;
        return 0;
    }
}


Measured memory_bytes: 976
#include "bits/stdc++.h"
using namespace std;
long long S(long long N) {
	long long tmp = N, sum = 0;
	while (tmp != 0) {
		sum += tmp % 10;
		tmp /= 10;
	}
	return sum;
}
int main() {
	long long N;
	cin >> N;
	if (N % S(N) == 0) cout << "Yes" << endl;
	else cout << "No" << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define int long long
#define endl '\n'
#define FOR(i, a, n) for (int i = (a); i < (n); ++i)
#define REP(i, n) FOR(i, 0, n)
using namespace std;

signed main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);

    int N;
    cin >> N;
    vector<int> S(1 << N), used(1 << N, false);
    REP (i, 1 << N) cin >> S[i];
    sort(S.begin(), S.end());
    used.back() = 1;
    REP (i, N) {
        multiset<int> st;
        for (int j = (1 << N) - 1; j >= 0; --j) {
            if (used[j]) st.insert(S[j]);
        }
        for (int j = (1 << N) - 1; j >= 0; --j) {
            if (used[j]) continue;
            auto it = st.upper_bound(S[j]);
            if (it == st.end()) continue;
            used[j] = 1;
            st.erase(it);
            if (st.empty()) break;
        }
        if (!st.empty()) {
            cout << "No" << endl;
            return 0;
        }
    }
    cout << "Yes" << endl;
}

Measured memory_bytes: 10496
//B
#include <bits/stdc++.h>
using namespace std;
#define LL long long
#undef INT_MIN
#undef INT_MAX
#define INT_MIN -2147483648
#define INT_MAX 2147483647
#define LL_MIN -9223372036854775808
#define LL_MAX 9223372036854775807
int main(){
    int N;
    cin >> N;
    string S;
    cin >> S;
    int ans = 0;
    for(int i=0; i<N-1; i++){
        int c = 0;
        set<char> tmp;
        set<char> tmp2;
        for(int j=0; j<i+1; j++){
            tmp.insert(S[j]);
        }
        for(int j=i+1; j<N; j++){
            if(tmp.count(S[j])>=1 && tmp2.count(S[j])==0) c++;
            tmp2.insert(S[j]);
        }
        //cout << c << endl;
        ans = max(ans, c);
    }
    cout << ans << endl;
    
    return 0;
}

Measured memory_bytes: 256
n = int(input())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
if sum(B) > sum(A):
    print(-1)
else:
    donor = []
    acceptance = []
    for a, b in zip(A, B):
        if a > b:
            donor.append(a-b)
        elif a < b:
            acceptance.append(b-a)
    donor.sort()

    ans = 0
    stock = 0
    for x in acceptance:
        ans += 1
        while stock < x:
            stock += donor.pop()
            ans += 1
        else:
            stock -= x
    print(ans)


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

#ifndef LOCAL_
#define fprintf if( false ) fprintf
#endif // LOCAL_
#define dump() fprintf(stderr, "#%s.%d\n", __func__, __LINE__);
#define dumpl(x1) fprintf(stderr, "#%s.%d (%s) = (%ld)\n", __func__, __LINE__, #x1, x1);
#define dumpll(x1, x2) fprintf(stderr, "#%s.%d (%s, %s) = (%ld, %ld)\n", __func__, __LINE__, #x1, #x2, x1, x2);
#define dumplll(x1, x2, x3) fprintf(stderr, "#%s.%d (%s, %s, %s) = (%ld, %ld, %ld)\n", __func__, __LINE__, #x1, #x2, #x3, x1, x2, x3);
#define dumpd(x1) fprintf(stderr, "#%s.%d (%s) = (%lf)\n", __func__, __LINE__, #x1, x1);
#define dumpdd(x1, x2) fprintf(stderr, "#%s.%d (%s, %s) = (%lf, %lf)\n", __func__, __LINE__, #x1, #x2, x1, x2);
#define loop for(;;)
typedef std::vector<long> LI;
typedef std::queue<long> QI;
#define rep(i,n) for(long i = 0; i < (long)n; ++i)
const double pi = M_PI;
const long mod = 1000000007;

template<typename T> void scan1(T& x) { fprintf(stderr, "unknown type\n"); }
template<> void scan1(long& x) { if( scanf("%ld", &x) < 0 ) exit(0); }
template<> void scan1(std::string& x) { if( not ( std::cin >> x ) ) exit(0); }
void scan() {}
template<typename Head, typename... Tail>
void scan(Head& x, Tail&... xs) {
  scan1(x); scan(xs...);
}

struct Solver {
   Solver() { fprintf(stderr, "--------Solver begin--------\n"); }
   ~Solver() { fprintf(stderr, "--------Solver end--------\n"); }
   std::vector<long> ds[112345];
   long n;
   void solve() {
      scan(n);
      for(long i = 0; i < n - 1; ++i) {
         long x, y; scan(x, y);
         ds[x].push_back(y);
         ds[y].push_back(x);
      }
      std::vector<bool> visited(n+1, false);
      std::vector<long> prev(n+1, -1);
      QI q;
      q.push(1);
      while( not q.empty() ) {
         long t = q.front(); q.pop();
         visited[t] = true;
         for(long next : ds[t]) {
            if( visited[next] ) continue;
            q.push(next);
            prev[next] = t;
         }
      }
      dump();
      LI path;
      long t = n;
      loop {
         path.push_back(t);
         if( t == 1 ) break;
         t = prev[t];
      }
      std::reverse(path.begin(), path.end());
      for(long x : path) {
         dumpl(x);
      }
      std::vector<long> color(n+1, 0);
      long aa = path[((long)path.size()-1)/2];
      long bb = path[((long)path.size()-1)/2+1];
      color[aa] = 1;
      color[bb] = 2;
      q.push(aa);
      q.push(bb);
      while( not q.empty() ) {
         long t2 = q.front(); q.pop();
         visited[t2] = true;
         for(long next : ds[t2]) {
            if( color[next] != 0 ) continue;
            q.push(next);
            color[next] = color[t2];
         }
      }
      long cs[3] = {};
      for(long c : color) {
         cs[c] += 1;
      }
      puts(cs[1] > cs[2] ? "Fennec" : "Snuke");
   }
};

int main() {
   loop std::unique_ptr<Solver>(new Solver())->solve();
}



Measured memory_bytes: 8436
#include<stdio.h>
int main()
{
	int a,b;
	scanf("%d %d",&a,&b);
	if(a-b>=a*b&&a-b>a+b||a-b>a*b&&a-b>=a+b)
		printf("%d",a-b);
	else if(a+b>=a*b&&a+b>a-b||a+b>a*b&&a+b>=a-b)
		printf("%d",a+b);
	else if(a+b<=a*b&&a*b>a-b||a+b<a*b&&a*b>=a-b)
		printf("%d",a*b);
	else
		printf("%d",a+b);
	return 0;
}

Measured memory_bytes: 128
#pragma GCC optimize ("O3")
#pragma GCC target ("sse4")
 
#include <bits/stdc++.h>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/assoc_container.hpp>
 
using namespace std;
using namespace __gnu_pbds;
 
typedef long long ll;
typedef long double ld;
typedef complex<ld> cd;
 
typedef pair<int, int> pi;
typedef pair<ll,ll> pl;
typedef pair<ld,ld> pd;
 
typedef vector<int> vi;
typedef vector<ld> vd;
typedef vector<ll> vl;
typedef vector<pi> vpi;
typedef vector<pl> vpl;
typedef vector<cd> vcd;
 
template <class T> using Tree = tree<T, null_type, less<T>, rb_tree_tag,tree_order_statistics_node_update>;
 
#define FOR(i, a, b) for (int i=a; i<(b); i++)
#define F0R(i, a) for (int i=0; i<(a); i++)
#define FORd(i,a,b) for (int i = (b)-1; i >= a; i--)
#define F0Rd(i,a) for (int i = (a)-1; i >= 0; i--)
 
#define sz(x) (int)(x).size()
#define mp make_pair
#define pb push_back
#define f first
#define s second
#define lb lower_bound
#define ub upper_bound
#define all(x) x.begin(), x.end()
 
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
 
const int MOD = 1000000007;
const ll INF = 1e18;
const int MX = 100001; //check the limits, dummy
 
int main() {
	ios_base::sync_with_stdio(0); cin.tie(0);    
	
    int N, T; cin >> N >> T;
    int A[N], B[N]; F0R(i, N) cin >> A[i] >> B[i];
 
    int dp[T][2];
    F0R(i, T) F0R(j, 2) dp[i][j] = 0;
    F0R(x, N) {
        F0Rd(i, T) {
            if (i + A[x] < T) {
                dp[i+A[x]][0] = max(dp[i+A[x]][0], dp[i][0] + B[x]);
                dp[i+A[x]][1] = max(dp[i+A[x]][1], dp[i][1] + B[x]);
            }
            dp[i][1] = max(dp[i][1], dp[i][0] + B[x]);
        }
    }
 
    cout << dp[T-1][1] << endl;
	
	return 0;
}
 
// read the question correctly (ll vs int)
// 

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <math.h>
using namespace std;
int main(){
    int s;
    cin>>s;
    vector<int>a={s};
    set<int>b;
    int i=0;
    while(!b.count(a.at(i))){
        b.insert(a.at(i));
        if(a.at(i)%2==0){a.push_back(a.at(i)/2);}
        else{a.push_back(3*a.at(i)+1);}
        i++;
    }
    
    cout<<i+1<<endl;
    return 0;
}

Measured memory_bytes: 256
#include <algorithm>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <ctime>
#include <iostream>
#include <sstream>
#include <functional>
#include <map>
#include <set>
#include <unordered_map>
#include <unordered_set>
#include <bitset>
#include <string>
#include <cstring>
#include <vector>
#include <queue>
#include <stack>
#include <deque>
#include <list>
#include <numeric>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<ll,ll> P;
typedef pair<P,ll> PPI;
typedef pair<ll,P> PIP;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<P> vp;
#define PQ(T) priority_queue<T,vector<T>,greater<T>>
#define PQ2(T) priority_queue<T>
const double PI = 3.14159265358979323846;
const double EPS = 1e-12;
const ll INF = 1LL<<29;
const ll mod = 1e9+7;
#define REP(i,a,b) for(ll (i)=a;(i)<(ll)(b);++(i))
#define rep(i,n) REP(i,0,n)
#define rep1(i,n) REP(i,1,n+1)
#define repd(i,n,d) for(ll (i)=0;(i)<(ll)(n);(i)+=(d))
#define all(v) (v).begin(), (v).end()
#define pb(x) push_back(x)
#define mp(x,y) make_pair((x),(y))
#define mset(m,v) memset((m),(v),sizeof(m))
#define chmin(x,y) ((x)=min((x),(y)))
#define chmax(x,y) ((x)=max((x),(y)))
#define fst first
#define snd second
#define UNIQUE(x) (x).erase(unique(all(x)),(x).end())
#define DEBUG(x) cerr<<"line ("<<__LINE__<<")  "<<#x<<": "<<x<<endl;
template<class T> ostream &operator<<(ostream &os, const vector<T> &v){int n=v.size();rep(i,n)os<<v[i]<<(i==n-1?"":" ");return os;}

int main(){
	ll a, b;
	cin>>a>>b;
	cout<<(a%500<=b?"Yes":"No")<<endl;
	return 0;
}


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

using namespace std;
typedef long long ll;
typedef long double ld;
#define REP(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define REPR(i,n) for(int i=n; i>-1; --i)
#define ALL(a) (a).begin(),(a).end()
#define FILL(a,n,x); REP(i,(n)){ (a)[i]=(x); }
#define CINA(a,n); REP(i,(n)){ cin >> (a)[i]; }
#define FILL2(a,n,m,x); REP(i,(n)){ REP(j,(m)){(a)[i][j]=(x);} }
#define CINA2(a,n,m); REP(i,(n)){ REP(j,(m)){cin >> (a)[i][j];} }
#define Liny "Yes\n"
#define Linn "No\n"
#define LINY "YES\n"
#define LINN "NO\n"

#define umap unordered_map
//cout << setfill('0') << right << setw(4) << 12; // "0012"
int keta(ll x){ if(x<10){return 1;} else{return keta(x/10) + 1;}}
int keta_wa(ll x){ if(x<10){return x;} else{return keta_wa(x/10) + x%10;} }
int ctoi(char c){ return ( (c>='0' && c<='9')? c - '0': 0 );}
int __stoi(string s){ return atoi(s.c_str()); }
ll sum(ll a[],ll N){ return accumulate(a,a+N,0LL);}
ll gcd(ll a,ll b){if(a<b)swap(a,b); return b?gcd(b,a%b):a;}
ll lcm(ll a,ll b){if(a<b){swap(a,b);} return a/gcd(a,b)*b;}
template<class T> void chmax(T& a, T b){ if(a<b){a=b;} }
template<class T> void chmin(T& a, T b){ if(a>b){a=b;} }

int main(){
  ll N,K; cin>>N>>K;
  ll R,S,P; cin>>R>>S>>P;
  string t; cin>>t;
  umap<char,int> mp;
  mp['r'] = P;
  mp['s'] = R;
  mp['p'] = S;
  
  ll ans = 0;
  char state = 'x';
  REP(start,K){
    for(int i=start;i<N;i += K){
      char c = t[i];
      if(i==start){
        ans += mp[ c ];
        state = t[i];
      }else{
        if(c==state){
          state = 'x';
        }else{
          ans += mp[ c ];
          state = c;
        }
      }
    }
  }
  cout << ans <<"\n";
}

Measured memory_bytes: 512
n,m = map(int,input().split())

left_max = -1
right_min = n+1

for i in range(m):
    s,t = map(int,input().split())
    left_max = max(left_max,s)
    right_min = min(right_min, t)
    
print(max(0, right_min - left_max +1))

Measured memory_bytes: 3060
// https://atcoder.jp/contests/abc151/tasks/abc151_d

#include "algorithm"
#include "bitset"
#include "cmath"
#include "functional"
#include "iomanip"
#include "iostream"
#include "map"
#include "numeric"
#include "queue"
#include "set"
#include "string"
#include "vector"
#define rep(i, to) for (ll i = 0; i < (to); ++i)
#define rep1(i, to) for (ll i = 1; i <= (to); ++i)
#define repf(i, from, to) for (ll i = from; i < (to); ++i)
#define repr(i, from) for (ll i = from - 1; i >= 0; --i)
#define all(vec) vec.begin(), vec.end()
#define unless(cond) if (!(cond))
#define fi first
#define se second
using namespace std;
typedef long long ll;
template <typename T>
using V = vector<T>;
using VL = V<ll>;
using VVL = V<VL>;
template <typename T, typename U>
using P = pair<T, U>;
using PL = P<ll, ll>;
using VPL = V<PL>;
template <typename T>
inline bool chmax(T& a, T b);
template <typename T>
inline bool chmin(T& a, T b);
void print_ints(vector<ll> v);
template <typename T>
void drop(T a);

const ll INF = 1e18;

ll H, W;
V<string> mat;

VPL directions = {{1, 0}, {-1, 0}, {0, 1}, {0, -1}};

ll get_max(ll h, ll w) {
  if (mat[h][w] == '#') return 0;

  VVL visited(H, VL(W));

  VPL q;
  q.push_back({h, w});
  visited[h][w] = 1;

  ll res = 0;

  while (q.size() > 0) {
    VPL nq(0);

    for (auto pa : q) {
      ll ph = pa.fi;
      ll pw = pa.se;

      for (auto d : directions) {
        ll nh = ph + d.fi;
        ll nw = pw + d.se;

        unless(0 <= nh && nh < H && 0 <= nw && nw < W) continue;
        unless(mat[nh][nw] == '.') continue;
        if (visited[nh][nw]) continue;
        visited[nh][nw] = 1;
        nq.push_back({nh, nw});
      }
    }

    res++;
    q = nq;
  }

  res--;
  return res;
}

void solve() {
  cin >> H >> W;

  mat = V<string>(H);

  rep(i, H) { cin >> mat[i]; }

  ll res = 0;

  rep(h, H) rep(w, W) chmax(res, get_max(h, w));

  cout << res << endl;
}

struct exit_exception : public std::exception {
  const char* what() const throw() { return "Exited"; }
};

#ifndef TEST
int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);

  try {
    solve();
  } catch (exit_exception& e) {
  }

  return 0;
}
#endif

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

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

void print_ints(vector<ll> v) {
  rep(i, v.size()) {
    if (i > 0) {
      cout << " ";
    }

    cout << v[i];
  }

  cout << endl;
}

template <typename T>
void drop(T res) {
  cout << res << endl;
  throw exit_exception();
}


Measured memory_bytes: 256
#include<stdio.h>
int main(void)
{
	int N,a;
	scanf("%d",&N);
	a=N%10;
	if(a==2||a==4||a==5||a==7||a==9){
		printf("hon\n");
	}
	if(a==0||a==1||a==6||a==8){
		printf("pon\n");
	}
	if(a==3){
		printf("bon\n");
	}
	return 0;
}
	
	

Measured memory_bytes: 1604
def calc_combination(n, s, max_digit):
    if n == 1:
        if max_digit < s:
            return 0
        else:
            return 1
    if n * (n - 1) / 2 > s:
        return 0
    total = 0
    max_digit = min(s, max_digit)
    for i in range(n-1, max_digit+1):
        total += calc_combination(n-1, s-i, i-1)
    return total

while True:
    n, s = map(int, input().split())
    if n == s == 0:
        break
    print(calc_combination(n, s, 9))

Measured memory_bytes: 5604
#include <vector>
#include <algorithm>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <iostream>
#include <cstdio>
#include <cmath>
#include <cstring>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
typedef double db;
ll w,h;
ll vx[4]={1,0,-1,0};
ll vy[4]={0,1,0,-1};
ll ice[100][100];
ll dfs(ll y,ll x){
	ll amax=0;
	for(ll i=0;i<4;i++){
		ll nx=x+vx[i];
		ll ny=y+vy[i];
		if(0<=nx&&nx<w&&0<=ny&&ny<h&&ice[ny][nx]){
			ice[ny][nx]=0;
			amax=max(amax,dfs(ny,nx));
			ice[ny][nx]=1;
		}
	}
	return amax+1;
}

ll ans;
int main()
{while(1){
	ans=0;
	scanf("%lld%lld",&w,&h);
	if(!w) return 0;
	for(ll i=0;i<h;i++) for(ll j=0;j<w;j++) scanf("%lld",&ice[i][j]);
	for(ll i=0;i<h;i++) for(ll j=0;j<w;j++){
		if(!ice[i][j]) continue;
		ice[i][j]=0;
		ans=max(ans,dfs(i,j));
		ice[i][j]=1;
	}
	printf("%lld\n",ans);
}}

Measured memory_bytes: 3172
#include<iostream>
using namespace std;
struct D{int a,b,c;};
int main()
{
  int a,b,c,N,i,j,w,x,y,z,m[303];
  D t[1001];
  for(;cin>>a>>b>>c>>N,a;){
    for(i=j=0;i++<301;)m[i]=2;
    for(i=0;i<N;i++){
      cin>>w>>x>>y>>z;
      D d={w,x,y};
      if(z)m[w]=m[x]=m[y]=1;
      else t[j++]=d;
    }
    for(i=j;i-->0;){
      if((m[t[i].a]&1)+(m[t[i].b]&1)+(m[t[i].c]&1)==2){
	m[t[i].a]&=1;
	m[t[i].b]&=1;
	m[t[i].c]&=1;
      }
    }
    for(i=0;i++<a+b+c;)cout<<m[i]<<endl;
  }
}

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

int main(){
  cin.tie(0);
 	ios::sync_with_stdio(false);
  int n, m;
  cin >> n;
  vector<int> a(n);
  for(int i = 0; i < n; i++){
    cin >> a[i];
  }
  cin >> m;
  vector<int> b(m);
  for(int i = 0; i < m; i++){
    cin >> b[i];
  }
  vector<int> v;
  set_union(begin(a), end(a), begin(b), end(b), inserter(v, end(v)));
  for(int i = 0; i < v.size(); i++){
    cout << v[i] << "\n";
  }
  return 0;
}



Measured memory_bytes: 6472
#include <stdio.h>
#include <stdlib.h>
int main(){
  int n,s1,s2;
  
   scanf("%d",&n);
  s1=n/100;
  s2=n%100;  
    if((s1==0||s1>12)&&(s2>12||s2==0))
      printf("NA");
    else if((1<=s1&&s1<=12)&&(1<=s2&&s2<=12))
      printf("AMBIGUOUS");
    else if((1<=s1&&s1<=12)&&(s2>12||s2==0))
      printf("MMYY");
  else
    printf("YYMM");
}

Measured memory_bytes: 128
import java.util.Scanner;

public class Main {
	public static void main(String[] args) throws Exception {
		Scanner sc = new Scanner(System.in);
		int H = sc.nextInt();
		int W = sc.nextInt();
		int h = sc.nextInt();
		int w = sc.nextInt();
		System.out.print((H - h) * (W - w));
	}
}


Measured memory_bytes: 21844
a = [int(input()) for i in range(5)]

a.sort(key= lambda x: x%10)
ans = 0
cnt = 0
for i in range(5):
  if cnt == 0 and a[i] % 10 != 0:
    ans += a[i]
    cnt += 1
  else:
    ans += -(-a[i] // 10)*10

print(ans)

Measured memory_bytes: 3060
#include <cstring>
#include <cstdint>
#include <iostream>
#include <string>
#include <memory>
#include <queue>
#include <stack>
#include <limits>
#include <list>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <utility>
#include <sstream>
#include <random>
#include <functional>
#include<algorithm>
#include <array>
#include<random>
using namespace std;

int main() {
	uint64_t N;
	string s;
	cin >> N >> s;
	vector<uint64_t> e(N + 1), w(N + 1);
	e[0] = 0;
	for (size_t i = 0; i < N; i++)
	{
		e[i + 1] = e[i];
		if (s[i] == 'W')++e[i + 1];
	}
	w[N] = 0;
	for (size_t i = 0; i < N; i++)
	{
		w[N - (i + 1)] = w[N - i];
		if (s[N - i] == 'E')++w[N - (i + 1)];
	}
	uint64_t ans = numeric_limits<uint64_t>::max();
	for (size_t i = 0; i < N; i++)
	{
		ans = min(ans, e[i] + w[i]);
	}
	cout << ans;
	return 0;
}

Measured memory_bytes: 5380