akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
#define maxn 100005
#define error {puts("-1");return 0;}
#define ll long long
using namespace std;

map <ll,int> mp;

struct edge{
	int to,nxt;
}e[maxn<<1];

struct node{
	ll dis;int id;
	bool operator < (const node &A) const {return dis>A.dis;}
}a[maxn];

struct uv{
	int u,v;
	bool operator < (const uv &A) const {return u==A.u?v<A.v:u<A.u;}
}ans[maxn];

int cnt,head[maxn],n;ll dis[maxn],size[maxn];

void add(int u,int v){
	e[++cnt]=(edge){v,head[u]};
	head[u]=cnt;
}

void dfs(int u,int fa,int dep){
	dis[a[n].id]+=dep;size[u]=1;
	for(int i=head[u];i;i=e[i].nxt){
		int v=e[i].to;
		if(v==fa) continue;
		dfs(v,u,dep+1);
		size[u]+=size[v];
	}
}

void dfs(int u,int fa){
	for(int i=head[u];i;i=e[i].nxt){
		int v=e[i].to;
		if(v==fa) continue;
		dis[v]=dis[u]+n-size[v]*2;
		dfs(v,u);
	}
}

int main(){
	scanf("%d",&n);
	for(int i=1;i<=n;i++){
		scanf("%lld",&a[i].dis);
		a[i].id=i;
		mp[a[i].dis]=i;
	}
	sort(a+1,a+n+1);
	for(int i=1;i<=n;i++) size[i]=1;
	for(int i=1;i<n;i++){
		int u=a[i].id;
		ll tmp=n-size[u]*2;
		if(tmp<=0||!mp.count(a[i].dis-tmp)) error
		int fa=mp[a[i].dis-tmp];
		size[fa]+=size[u];
		add(u,fa);add(fa,u);
		ans[i].u=min(u,fa);
		ans[i].v=max(u,fa);
	}
	sort(ans+1,ans+n);
	dfs(a[n].id,0,0);
	dfs(a[n].id,0);
	for(int i=1;i<=n;i++) if(dis[a[i].id]!=a[i].dis) error
	for(int i=1;i<n;i++) printf("%d %d\n",ans[i].u,ans[i].v);
}

Measured memory_bytes: 16640
#include<bits/stdc++.h>
using namespace std;
typedef vector<int> vi;
typedef vector< vi > vvi;
typedef pair<int, int> pii;  // pair<int, int> に pii という別名を付ける
typedef long long ll;

int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  int N;
  cin >> N;
  vi A(N);
  bool flag = true;
  for (int i = 0; i < N; i++) cin >> A.at(i);
  sort(A.begin(), A.end());
  for (int i = 0; i < N-1; i++){
    if(A.at(i) == A.at(i+1) ){
      flag = false;
      break;
    }
  }
  if(flag == true ){
    cout << "YES" << endl;
  }
  else{
    cout << "NO" << endl;
  }
}

Measured memory_bytes: 1152
//#pragma GCC optimize("O3")
#include <bits/stdc++.h>
#define int long long
#define x first
#define y second
#define inf 1000000000000000000
#define N 1000000007
#define speed ios_base::sync_with_stdio(0);cin.tie(0);
using namespace std;
template<class L,class R> ostream& operator<<(ostream& cout,pair<L, R> P)
{return cout<<'('<<P.x<<','<< P.y<<')';}
template<class T> ostream& operator<<(ostream& cout,vector<T> V)
{cout<<"[ ";for(auto v:V)cout<<v<<' ';return cout<<']';}

int  diff(string & s, string & t){
    
    int ret=0;for(int i=0;i<s.size();++i){
        if(s[i]!=t[i]){++ret;}
    }
    return ret;
}
//edge cases when n=1,m=1.wrong variable in loop.if<->while;merge resize;LLONG_MAX
signed main()
{
    //#ifndef ONLINE_JUDGE
    //freopen("input.txt","r",stdin);
    //#endif
    speed
    //global var
    string s, t;cin>>s>>t;
    int n=t.size();
    int ans=INT_MAX;
    for(int i=0;(i+n-1)<s.size();++i){
        string sub=s.substr(i,n);
        //cout<<sub<<"\n";
        ans=min(ans,diff(sub,t));
    }
    cout<<ans<<'\n';
}
//try thinking from a different angle after spending some time


Measured memory_bytes: 3660
//参考：http://ehafib.hatenablog.com/entry/2015/12/23/164517
//インクルード
#include<algorithm>//sort,二分探索,など
#include<bitset>//固定長bit集合
#include<cmath>//pow,logなど
#include<complex>//複素数
#include<deque>//両端アクセスのキュー
#include<functional>//sortのgreater
#include<iomanip>//setprecision(浮動小数点の出力の誤差)
#include<iostream>//入出力
#include<map>//map(辞書)
#include<numeric>//iota(整数列の生成),gcdとlcm(c++17)
#include<queue>//キュー
#include<set>//集合
#include<stack>//スタック
#include<string>//文字列
#include<unordered_map>//イテレータあるけど順序保持しないmap
#include<unordered_set>//イテレータあるけど順序保持しないset
#include<utility>//pair
#include<vector>//可変長配列

using namespace std;
typedef long long ll;

//マクロ
#define REP(i,n) for(ll i=0;i<(ll)(n);i++)
#define REPD(i,n) for(ll i=(ll)(n)-1;i>=0;i--)
#define FOR(i,a,b) for(ll i=(a);i<=(b);i++)
#define FORD(i,a,b) for(ll i=(a);i>=(b);i--)
#define ALL(x) (x).begin(),(x).end() //sortなどの引数を省略したい
#define SIZE(x) ((ll)(x).size()) //sizeをsize_tからllに直しておく
#define MAX(x) *max_element(ALL(x))
#define INF 1000000000000
#define MOD 10000007
#define PB push_back
#define MP make_pair
#define F first
#define S second

signed main(){
  int N;
  string S;
  cin >> N >> S;

  ll ans = 0;
  // for (int i = 0; i < N - 2; i++) {
  //   for (int j = i + 1; j < N - 1; j++) {
  //     if(S[i] == S[j]) continue;
  //     string tmp;
  //     if (j + (j - i) < S.length()) {
  //       tmp = S.substr(j + 1, j - i - 1) + S.substr(j + (j - i + 1));
  //     } else {
  //       tmp = S.substr(j + 1);
  //     }
  //     // cout << tmp << endl;
  //     char c;
  //     if (S[i] != 'R' && S[j] != 'R') c = 'R'; 
  //     if (S[i] != 'G' && S[j] != 'G') c = 'G'; 
  //     if (S[i] != 'B' && S[j] != 'B') c = 'B'; 
  //     ans += std::count(tmp.cbegin(), tmp.cend(), c);
  //   }
  // }

  ans = std::count(S.cbegin(), S.cend(), 'R');
  ans *= std::count(S.cbegin(), S.cend(), 'G');
  ans *= std::count(S.cbegin(), S.cend(), 'B');

  for (int j = 1; j < N - 1; j++) {
    for (int i = 1; i < N - 1; i++) {
      if (j + i < N && j - i >= 0) {
        if (S[j - i] != S[j] && S[j] != S[j + i] && S[j - i] != S[j + i]) ans--;
      } else {
        continue;
      }
    }
  }


  cout << ans << endl;

  return 0;
}

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

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

using namespace std;

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

	rep(i, s.size()) {
		if (s[i] == '0') ans += '0';
		else if (s[i] == '1') ans += '1';
		else {
			if ( !ans.empty())  ans.pop_back();
		}
	}

	cout << ans << '\n';

	return 0;

}

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

#define F first
#define S second
#define MP make_pair
#define PB emplace_back

using namespace std;

const int N = 1e6+100;

long long int wop(long long int x, long long int y) {
    long long int ret=1;
    for(;y>=1;y/=2) {
        if(y&1)ret*=x;
        x*=x;
    }
    return ret;
}

bool PA(string s) {
    for(int i = 0 ; i < s.size() ; i++ ) {
        if(s[i]!=s[s.size()-i-1])return 0;
    }
    return 1;
}

int main () {
    cout << setprecision(8) << fixed;
    long double x;
    cin >> x;
    long double x1=x/3;
    cout << x1*x1*x1;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
typedef long long ll;
#define rep(i, a, n) for (ll i = a; i < (ll)n; ++i)
using namespace std;

int main(void)
{
    cin.tie(0);
    cout.tie(0);
    ios::sync_with_stdio(false);
    ll n, k, state = 0;
    cin >> n >> k;
    vector<ll> v(n);
    deque<ll> dq;
    vector<bool> f(n, false);
    rep(i, 0, n) cin >> v[i], v[i]--;
    while (true)
    {
        if (f[state])
        {
            while (dq[0] != state)
            {
                --k, dq.pop_front();
                if (k == 0)
                {
                    cout << dq[0] + 1 << endl;
                    return 0;
                }
            }
            break;
        }
        dq.push_back(state);
        f[state] = true;
        state = v[state];
    }
    cout << dq[k % dq.size()] + 1 << endl;
}

Measured memory_bytes: 6240
N = int(input())
arr = list(map(int, input().split()))
new_arr = sorted(arr, reverse=True)

bob   = 0
alice = 0

for i in range(len(new_arr)):
    if i % 2 ==0:
        alice += new_arr[i]
    elif i % 2 ==1:
        bob += new_arr[i]

print(alice-bob)

Measured memory_bytes: 3060
# include <iostream>
# include <vector>
# define rep(i, n) for (int i = 0; i < (int)(n); i++)
using namespace std;

int main() {
    int n, m, _x, _y; cin >> n >> m >> _x >> _y;
    vector<int> x(n); rep (i, n) cin >> x[i];
    vector<int> y(m); rep (i, m) cin >> y[i];

    sort(x.begin(), x.end());
    sort(y.begin(), y.end());

    int x_max = max(_x, x.back());
    int y_min = min(_y, y.front());

    if (x_max < y_min) cout << "No War" << endl;
    else cout << "War" << endl;
    return 0;
}



Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <cstdio>
#include <cstring>
#include <vector>
#include <queue>

using namespace std;
long long a[200005], b[200005];

/*
 * |xi - xj| + |yi - yj|
 * 假设 xi > xj
 * xi - xj + yi - yj = (xi + yi) - (xj + yj)
 * 或
 * xi - xj + yj - yi = (xi - yi) - (xj - yj)
 */

int main() {
    int n;
    scanf("%d", &n);
    for (int i = 0; i < n; ++i) {
        int x, y;
        scanf("%d%d", &x, &y);
        a[i] = x + y;
        b[i] = x - y;
    }
    sort(a, a + n);
    sort(b, b + n);
    cout << max(a[n - 1] - a[0], b[n - 1] - b[0]) << endl;
    return 0;
}


Measured memory_bytes: 6340
import fractions
import math
from collections import deque
A,B = list(map(int,input().split()))
gcd = fractions.gcd(A,B)
def gcd_another(N):
    R = deque()
    for i in range(1,math.ceil(int(N**0.5))+1):
        if N % i == 0:
            R.append(i)
            if i != N // i:
                R.append(N//i)
    R = list(R)
    R.sort()
    return R
C = gcd_another(gcd)
C.pop(0)
total = 1
while C != []:
    i = C[0]
    C = [j for j in C if j % i != 0]
    total += 1
print(total)

Measured memory_bytes: 5336
#include<bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using namespace std;
using ll = long long;
using p = pair<int,int>;
const long long INF = 1ll << 60;


int main() {
  int M;cin >> M;
  int ans = 24 - M + 24;
  cout << ans << endl;

	return 0;
}



Measured memory_bytes: 3564
#define _CRT_SECURE_NO_WARNINGS

#include <stdio.h>
#include <iostream>
using namespace std;

int main() {
	int a, b,t,c,z=0;
	
	cin >> a>>b>>t;


	c = t / a;
	z = c * b;

	cout <<z;

	return 0;

}

Measured memory_bytes: 256
import sys
import itertools
# import numpy as np
import time
import math
import heapq
from collections import defaultdict
sys.setrecursionlimit(10 ** 7)
 
INF = 10 ** 18
MOD = 10 ** 9 + 7
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

# map(int, input().split())

N, K = map(int, input().split())
A = list(map(int, input().split()))

for i in range(K, N):
    if A[i] > A[i - K]:
        print("Yes")
    else:
        print("No")

Measured memory_bytes: 32444
#include<bits/stdc++.h>
using namespace std;
#define all(XQXQ) (XQXQ).begin(), (XQXQ).end()
#define rall(PNPN) (PNPN).rbegin(), (PNPN).rend()
#define ll long long
#define MO 1000000007
#define PB push_back
#define MP make_pair
#define MX 100005
#define times(ZZtimes) for(int XYZtimes=0;XYZtimes<ZZtimes;++XYZtimes)
#define MS(ZZtarget,ZZvalue) memset(ZZtarget,ZZvalue,sizeof(ZZtarget))
#define S(SCQW) scanf("%d",&SCQW)
#define SS(SCQW,ZSCQW) scanf("%d%d",&SCQW,&ZSCQW);
#define SSS(SCQW,ZSCQW,ZZSCQW) scanf("%d%d%d",&SCQW,&ZSCQW,&ZZSCQW)
#define SSSS(SCQW,ZSCQW,ZZSCQW,ZZZSCQW) scanf("%d%d%d%d",&SCQW,&ZSCQW,&ZZSCQW,&ZZZSCQW)
#define P(PRQW) printf("%d\n",PRQW)
#define eps 1e-8
#define PP(PRQW) printf("%d ",PRQW)
#define HAS(QPEU) !QPEU.empty()
#define rep(iW,JEJU,nW) for(int (iW)=JEJU;(iW)<(int)(nW);(iW)++)
#define FD(qeVECTORXMO,qeVALXMO) find(qeVECTORXMO.begin(),qeVECTORXMO.end(),qeVALXMO)!=qeVECTORXMO.end()
#define ST(qeVECTORXMO) sort(qeVECTORXMO.begin(),qeVECTORXMO.end())
#define ff first
#define ss second
#define x1 x1992WAZY
#define y1 y1992WALSR
#define x2 y1992WAHM
#define y2 y1992WADX
ll bigpow(ll a,ll b) {ll res=1;a%=MO;for(;b;b>>=1){if(b&1)res=res*a%MO;a=a*a%MO;}return res;}
void main2();int main(){
cin.tie(0);ios_base::sync_with_stdio(0);
main2();return 0;}

void main2() {
  ll N;
  cin >> N;
  ll cur = 2;
  cout << N << ":";
  while (N > 1) {
    while (N % cur == 0) {
      N /= cur;
      cout << " " << cur;
    }
    cur++;
    if (cur * cur > N) cur = N;
  } 
  cout << endl;
}

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

inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}

typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> P;
typedef long long ll;

#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define SORT(c) sort((c).begin(),(c).end())
#define REVERSE(c) reverse((c).begin(),(c).end())

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

const double EPS = 1e-10;
const double PI  = acos(-1.0);
const int INT_INF = 2147483647;
const long long LL_INF = 1LL<<60;
const long long MOD = 1000000007;

#define CLR(a) memset((a), 0 ,sizeof(a))

#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

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

bool judge(int d[3][3]){
    int n = 0;
    REP(i,3) n += d[i][0]&&d[i][1]&&d[i][2];
    REP(i,3) n += d[0][i]&&d[1][i]&&d[2][i];
    n += d[0][0]&&d[1][1]&&d[2][2];
    n += d[0][2]&&d[1][1]&&d[2][0];
    return n ? true : false;
}

int main(void){
    int A[3][3]; REP(i,3)REP(j,3) cin >> A[i][j];
    int N; cin >> N;
    VI b(N); REP(i,N) cin >> b[i];

    int d[3][3]; CLR(d);
    REP(i,3)REP(j,3){
        REP(k,N){
            if(A[i][j] == b[k]) d[i][j] = 1;
        }
    }
    cout << (judge(d) ? "Yes" : "No") << endl;
    return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int N = Integer.parseInt(scanner.next());
        int K = Integer.parseInt(scanner.next());
        int X = Integer.parseInt(scanner.next());
        int Y = Integer.parseInt(scanner.next());
        scanner.close();

        int sum = 0;
        if (N > K) {
            sum += K * X;
            sum += (N - K) * Y;
        } else {
            sum = N * X;
        }

        System.out.println(sum);
    }
}


Measured memory_bytes: 21844
import java.util.Scanner;
public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = Integer.parseInt(sc.next());
		int[] a = new int[n];
		long sumA = 0;
		long sumT = Integer.parseInt(sc.next());
		for (int i = 1; i < n; i++) {
			a[i] = Integer.parseInt(sc.next());
			sumA += a[i];
		}
		long diff = Math.abs(sumT - sumA);
		for (int i = 1; i < n - 1; i++) {
			sumT += a[i];
			sumA -= a[i];
			diff = Math.min(diff, Math.abs(sumT - sumA));
		}
		System.out.println(diff);
	}

}

Measured memory_bytes: 57420
S = input()
dp = [[0]*13 for i in range(len(S))]
MOD = 10**9+7

if S[0]=='?':
    for i in range(10):
        dp[0][i] = 1
else:
    dp[0][int(S[0])] = 1

for i,c in enumerate(S[1:]):
    for j in range(13):
        if c=='?':
            for k in range(10):
                nj = (j*10 + k) % 13
                dp[i+1][nj] += dp[i][j]
                dp[i+1][nj] %= MOD
        else:
            nj = (j*10 + int(c)) % 13
            dp[i+1][nj] += dp[i][j]
            dp[i+1][nj] %= MOD

print(dp[-1][5])

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

using namespace std;

#define INF 100000000
#define YJ 1145141919
#define INF_INT_MAX 2147483647
#define INF_LL_MAX 9223372036854775807
#define EPS 1e-10
#define MOD 1000000007
#define Pi acos(-1)
#define LL long long
#define ULL unsigned long long
#define LD long double

#define int long long

const int MAX_N = 1005;
int N;
deque<int> A;

void merge(int& i) {
    if(i == 0) {
        A.pop_front();

    } else if(i == A.size()-1) {
        A.pop_back();
        i--;
    } else {
        A[i] = A[i-1] + A[i+1];
        A.erase(A.begin() + i+1);
        A.erase(A.begin() + i-1);
        i--;
    }
}

bool used[MAX_N];

signed main()
{
    cin >> N;

    int l = 0, r = 0;
    A.resize(N);

    bool minusFlag = true;

    int aMax = -INF;
    int aIndex = -1;
    for(int i = 0; i < N; i++) {
        cin >> A[i];

        if(aMax < A[i]) {
            aMax = A[i];
            aIndex = i;
        }

        if(A[i] < 0) {
            continue;
        } else {
            minusFlag = false;
        }

        if(i%2 == 0) {
            l += A[i];
        } else {
            r += A[i];
        }
    }

    if(minusFlag) { //全部負
        cout << aMax << endl;
        vector<int> ope;
        for(int i = 0; i < aIndex; i++) {
            ope.push_back(1);
            A.pop_front();
        }
        for(int i = aIndex+1; i < N; i++) {
            ope.push_back(A.size());
            A.pop_front();
        }
        cout << ope.size() << endl;
        for(int o : ope) {
            cout << o << endl;
        }
        return 0;
    }

    cout << max(l, r) << endl;

    int startI = (l > r ? 0 : 1);

    vector<int> ope;

    for(int i = 0; i < A.size(); i++) {
        if(i%2 != startI || A[i] < 0) {
            ope.push_back(i+1);
            merge(i); i--;
            startI = (startI+1)%2;
        } else {
            break;
        }
    }
    // cerr << A.size() << endl;
    for(int i = A.size()-1; 0 <= i; i--) {
        if(i%2 != startI || A[i] < 0) {
            ope.push_back(i+1);
            merge(i); i++;
        } else {
            break;
        }
    }
    // cerr << A.size() << endl;

    for(int i = 0; i < A.size(); i++) {
        if(i%2 == 0 && A[i] >= 0) {
            used[i] = true;
        }
    }

    for(int i = A.size()-1; 0 <= i; i--) {
        if(!used[i]) {
            int j;
            for(j = i; 0 <= j; j--) {
                if(used[j]) {
                    break;
                }
            }
            j++;
            int k = i-j+1;
            int I = j+k/2;
            // cerr << I << endl;
            for(int ii = 0; ii < (k+1)/2; ii++) {
                ope.push_back(j + k/2 + 1 - ii);
                I = j+k/2-ii;
                merge(I);
            }
            
            i = j;
            // for(int a : A) {
            //     cerr << a << " ";
            // }
            // cerr << endl;
        }
    }

    cout << ope.size() << endl;
    for(int o : ope) {
        cout << o << endl;
    }

    // cerr << A.size() << endl;
    // cerr << A[0] << endl;

    return 0;
}

Measured memory_bytes: 256
#define _CRT_SECURE_NO_WARNINGS
#define _USE_MATH_DEFINES
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
void push(int, int,int []);
int pop(int, int[]);

int main() {
	char array[1000000];
	char *pt=array,*tok;
	int top=0,result[100],num,a,b;
	scanf("%[^\n]*s", pt);
	tok = strtok(pt, " ");
	while (tok!=NULL) {
		if (*tok == '+') {
			a = pop(--top, result);
			b = pop(--top, result);
			push(a + b, top++, result);
		}

		else if (*tok == '-') {
			b = pop(--top, result);
			a = pop(--top, result);
			push(a - b, top++, result);
		}
		
		else if (*tok == '*') {
			a = pop(--top, result);
			b = pop(--top, result);
			push(a * b, top++, result);
		}

		else {
			num = atoi(tok);
			push(num, top++, result);
		}
		tok = strtok(NULL, " ");
	}
	printf("%d\n",pop(--top,result));
	return 0;
}

void push(int n, int t, int a[]){
	a[t] = n;
}

int pop(int t, int a[]){
	return a[t];
}

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

#ifdef DEBUG
#define PRINT(x)\
    cout<<"func "<<__func__<<": line "<<__LINE__<<": "<<#x<<" = "<<(x)<<endl;
#define PRINTA(a,first,last)\
    cout<<"func "<<__func__<<": line "<<__LINE__<<": "<<#a<<"["<<(first)<<", "<<(last)<<")"<<endl;\
    for (int i=(first);i<(last);++i){cout<<#a<<"["<<i<<"] = "<<(a)[i]<<endl;}
#else
#define PRINT(x)
#define PRINTA(a,first,last)
#endif

#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 (int i=0;i<(n);i++)
#define RREP(i,n) for (int i=(n)-1;i>=0;i--)
#define pb push_back
#define mp make_pair
#define all(a) (a).begin(),(a).end()
#define MOD 1000000007

using namespace std;

template <class T>
struct edge
{
    int to;
    T cap;
    int rev;
    edge(int to, T cap, int rev) : to(to), cap(cap), rev(rev) {}
};

template <class T>
class graph
{
    private:
        const int number_of_nodes;
    public:
        vector<edge<T> > *edges;
        graph(int number_of_nodes) : number_of_nodes(number_of_nodes) {
            edges = new vector<edge<T> >[number_of_nodes];
        }
        ~graph() {
            delete [] edges;
        }
        int size() const {return number_of_nodes;}
        void make_edge(int u, int v, T cap) {
            edges[u].push_back(edge<T>(v, cap, edges[v].size()));
            edges[v].push_back(edge<T>(u, 0, edges[u].size() - 1));
        }
};

// Ford-Fulkerson algorithm
template <class T>
T maximum_flow(graph<T> &g, int source, int sink)
{
    bool *used = new bool[g.size()]();
    function<T(int, T)> dfs = [&](int u, T f) -> T {
        if (u == sink) {
            return f;
        }
        used[u] = true;
        for (edge<T> &e: g.edges[u]) {
            if (!used[e.to] && e.cap > 0) {
                T d = dfs(e.to, u == source ? e.cap : min(f, e.cap));
                if (d > 0) {
                    e.cap -= d;
                    g.edges[e.to][e.rev].cap += d;
                    return d;
                }
            }
        }
        return 0;
    };
    T result = 0;
    while (true) {
        fill (used, used + g.size(), 0);
        T flow = dfs(source, 0);
        if (flow == 0) {
            return result;
        }
        result += flow;
    }
    delete [] used;
    return result;
}

int main(void)
{
    int X, Y, E;
    cin >> X >> Y >> E;
    // 0,...,X-1 are nodes in X
    // X,...,X+Y-1 are nodes in Y
    // node X+Y is source
    // node X+Y+1 is sink
    graph<int> g(X + Y + 2);
    int source = X + Y;
    int sink = X + Y + 1;
    REP(i, E) {
        int x, y;
        cin >> x >> y;
        g.make_edge(x, y + X, 1);
    }
    REP(x, X) g.make_edge(source, x, 1);
    REP(y, Y) g.make_edge(y + X, sink, 1);
    cout << maximum_flow(g, source, sink) << endl;
    return 0;
}


Measured memory_bytes: 3300
#include <iostream>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <algorithm>
#include <string>
#include <cmath>
#include <cstdio>
#include <iomanip>
#include <fstream>
#include <cassert>
#include <cstring>
#include <unordered_set>
#include <unordered_map>
#include <numeric>
#include <ctime>
#include <bitset>
#include <complex>
#include <chrono>
#include <random>
#include <functional>

using namespace std;

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

	int x;
	cin >> x;
	if (x >= 30) {
		cout << "Yes\n";
	} else {
		cout << "No\n";
	}
}


Measured memory_bytes: 3096
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0; i<(n); i++)
#define all(n) begin(n),end(n)
using ll = long long;
using P = pair<int,int>;

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

Measured memory_bytes: 3592
#include <iostream>
#include <string>
#include <algorithm>
#include <cstdlib>
using namespace std;

int main(){
  string s;
  cin >> s;
  string not_x = "";
  for(int i = 0;i < s.size();i++){
    if(s[i] != 'x')not_x += s[i];
  }

  string not_x_reverse = not_x;
  reverse(not_x_reverse.begin(),not_x_reverse.end());

  bool flag = true;
  for(int i = 0;i < not_x.size();i++){
    if(not_x[i] != not_x_reverse[i]){
      flag = false;
      break;
    }
  }

  if(!flag){
    cout << -1 << endl;
  }
  else{
    int not_x_cnt = 0;
    int ans = 0;
    int now_left_pos = 0;
    int now_right_pos =s.size() - 1;

    while(not_x_cnt != (not_x.size() + 1)/2){


      int left_cnt = 0;
      for(int i = now_left_pos;i < s.size();i++){
        now_left_pos = i;
        if(s[i] == 'x')left_cnt++;
        else break;
      }

      int right_cnt = 0;
      for(int i = now_right_pos;i >= 0;i--){
        now_right_pos = i;
        if(s[i] == 'x')right_cnt++;
        else break;
      }

      ans += max(right_cnt - left_cnt,left_cnt - right_cnt);

      now_left_pos++;
      now_right_pos--;
      not_x_cnt++;
    }


    cout << ans << endl;
  }


}


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

int main() {
    ll n;
    cin >> n;
    ll x;
    ll ans = 0;
    for (ll i = 0; i < n; ++i) {
        cin >> x;
        while ((x & 1) == 0) {
            ++ans;
            x >>= 1;
        }
    }
    cout << ans << endl;
    return 0;
}

static int speedUp = []() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);
    return 0;
}();

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

int main(){
  int N;
  cin >> N;
  long int sum = 0;
  for(int i = 1; i <= N ; i++){
    if ( i % 3 != 0 && i % 5 != 0)
      sum = sum + i;
  }
  cout << sum << endl;
  return 0;
}

Measured memory_bytes: 3636
#include<bits/stdc++.h>
#define pb push_back
#define mp make_pair
#define ll long long
#define tin cin>>t;while(t--)
#define pii pair<int,int>
#define endl '\n'
#define MIN 1000000000
#define flash ios_base::sync_with_stdio(false),cin.tie(NULL),cout.tie(NULL)

using namespace std;

int dp[100001]={-1};
int func(int n,int k,int arr[])
{
	//cout<<n<<" "<<dp[n]<<endl;
	if(n<=0)
		return 0;
	if(n==1)
		return abs(arr[1]-arr[0]);
	if(dp[n]!=-1)
		return dp[n];

	int m=MIN;
	for(int i=1;i<=k;i++)
	{if(n-i>=0)
	m=min(func(n-i,k,arr)+abs(arr[n]-arr[n-i]),m);
	}
	//cout<<n<<" "<<dp[n]<<endl;
	dp[n]=m;
	return dp[n];
}


int main()
{
	int n,k;
	cin>>n>>k;
	int arr[n];
	for(int i=0;i<n;i++)
		cin>>arr[i];
	memset(dp,-1,sizeof(dp));
	cout<<func(n-1,k,arr);
}

Measured memory_bytes: 8832
#include <algorithm>
#include <iostream>
#include <cstdlib>
#include <limits.h>
#include <math.h>
#include <stdio.h>
#include <string>
#include <typeinfo>
#include <vector>
//#include <bits/stdc++.h>

using namespace std;
typedef long long ll;
typedef vector<bool> vb;
typedef vector<int> vi;
typedef vector<string> vs;
typedef vector<vector<bool>> vvb;
typedef vector<vector<int>> vvi;

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

int main()
{
  int a, b;
  cin >> a >> b;
  if(a*b%2==0){
    cout << "No" << endl;
  }else{
    cout << "Yes" << endl;
  }
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); i++)
#define FOR(i, a, b) for (int i = a; i < (b + a); i++)
#define W1 while (1)
#define COUT(x) cout << x << endl
using namespace std;
using ll = long long;
using ld = long double;
#define ALL(x) x.begin(),x.end()
#define P pair<int,int>
#define mod 1000000007
#define PB push_back
#define F first
#define S second

int main() {
  int x;
  int ans = 1;
  cin >> x;
  int border = 1800;
  W1 {
    if (x >= border) break;
    border -= 200;
    ans++;
  }
  COUT(ans);

  return 0;
}


Measured memory_bytes: 3596
#include<stdio.h>
int binarySearch(int *,int,int);
int main(){
  int n,q,b,count=0;
  int A[100000];
  int i;
  scanf("%d",&n);
  for(i=0;i<n;i++){
    scanf("%d",&A[i]);
  }
  scanf("%d",&q);
  for(i=0;i<q;i++){
    scanf("%d",&b);
    if(0 <= binarySearch(A,b,n))count++;
  }
  printf("%d\n",count);
  return 0;
}
int binarySearch(int *A,int key,int n){
  int NOT_FOUND=-1;
  int left=0,right=n,mid;
 
  while(left<right){
    mid=(left+right)/2;
    if(A[mid]==key)return mid;
    else if (key < A[mid])right=mid;
    else left=mid+1;
  }
  return NOT_FOUND;
}



Measured memory_bytes: 2104
#include <bits/stdc++.h>
using namespace std;
#define m_p make_pair
#define all(x) (x).begin(),(x).end()
#define sz(x) ((int)(x).size())
#define fi first
#define se second
typedef long long ll;
mt19937 rnd(chrono::steady_clock::now().time_since_epoch().count());
mt19937 rnf(2106);
const int N = 400005, INF = 100000008;

int n;
int x[N], y[N];
char u[N];

vector<pair<int, char> > v[N];
void clr()
{
    for (int i = 0; i < N; ++i)
        v[i].clear();
}

int ans = INF;
void go(vector<pair<int, char> > v, char l, char r, int g)
{
    sort(all(v));
    int t = -INF;
    for (int j = 0; j < v.size(); ++j)
    {
        if (v[j].se == l)
        {
            t = v[j].fi;
        }
        else if (v[j].se == r)
        {
            ans = min(ans, (v[j].fi - t) * g);
        }
    }
}

void solv()
{
    scanf("%d", &n);
    for (int i = 1; i <= n; ++i)
    {
        scanf("%d%d %c", &x[i], &y[i], &u[i]);
    }

    clr();
    for (int i = 1; i <= n; ++i)
    {
        v[x[i]].push_back(m_p(y[i], u[i]));
    }
    for (int i = 0; i < N; ++i)
    {
        go(v[i], 'U', 'D', 5);
    }

    clr();
    for (int i = 1; i <= n; ++i)
    {
        v[y[i]].push_back(m_p(x[i], u[i]));
    }
    for (int i = 0; i < N; ++i)
    {
        go(v[i], 'R', 'L', 5);
    }

    clr();
    for (int i = 1; i <= n; ++i)
    {
        v[x[i] - y[i] + 200000].push_back(m_p(x[i], u[i]));
    }
    for (int i = 0; i < N; ++i)
    {
        go(v[i], 'R', 'D', 10);
        go(v[i], 'U', 'L', 10);
    }

    clr();
    for (int i = 1; i <= n; ++i)
    {
        v[x[i] + y[i]].push_back(m_p(x[i], u[i]));
    }
    for (int i = 0; i < N; ++i)
    {
        go(v[i], 'R', 'U', 10);
        go(v[i], 'D', 'L', 10);
    }

    if (ans == INF)
        printf("SAFE\n");
    else
        printf("%d\n", ans);
}

int main()
{
    #ifdef SOMETHING
    freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);
    #endif // SOMETHING
    //ios_base::sync_with_stdio(false), cin.tie(0);
    solv();
    return 0;
}

//while ((double)clock() / CLOCKS_PER_SEC <= 0.9){}


Measured memory_bytes: 28204
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define fi first
#define se second
#define pb push_back
#define eb emplace_back
#define sz(x) (int)(x).size()
using namespace std;
using ll = long long;
using P = pair<int, int>;
using vi = vector<int>;
using vc = vector<char>;
using vb = vector<bool>;
using vs = vector<string>;
using vll = vector<long long>;
using vp = vector<pair<int, int>>;
using vvi = vector<vector<int>>;
using vvc = vector<vector<char>>;
using vvll = vector<vector<long long>>;
template<class T> inline bool chmax(T &a, T b) { if (a<b) {a=b; return 1;} return 0;}
template<class T> inline bool chmin(T &a, T b) { if (b<a) {a=b; return 1;} return 0;}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    
    int n;
    cin >> n;
    vi x(n);
    rep(i, n) {
        cin >> x[i];
    }
    vi y = x;
    sort(y.begin(), y.end());
    int idx = sz(y)/2;
    int a = y[idx-1];
    int b = y[idx];
    rep(i, n) {
        if (x[i] <= a) {
            cout << b << endl;
        } else {
            cout << a << endl;
        }
    }
}

Measured memory_bytes: 3840
#include <iostream>
#include <cmath>
#include <set>

using namespace std;

bool isPrime(int x){
    int root = sqrt(x);
    for (int i = 2; i <= root; ++i) if(x % i == 0) return false;
    return true;
}

int main() {
    int n, x, cnt = 0;
    cin >> n;
    for (int i = 0; i < n; ++i) {
        cin >> x;
        if (isPrime(x)) cnt++;
    }
    cout << cnt << endl;
    return 0;
}



Measured memory_bytes: 3096
#include<iostream>
#include<string>
#include<iomanip>
#include<cmath>
#include<vector>
#include<algorithm>

using namespace std;

#define int long long
#define endl "\n"

constexpr long long INF = (long long)1e18;
constexpr long long MOD = 1'000'000'007; 

string yn(bool f){return f?"Yes":"No";}
string YN(bool f){return f?"YES":"NO";}

#define MAX_VAL (int)(2e5)

long long fac[MAX_VAL], mmi[MAX_VAL];

void factorial_mod(){
	 fac[0]=fac[1]=1;
	for(long long i = 2; i < MAX_VAL; fac[i]%=MOD,i++)
		fac[i] = fac[i-1]*(i%MOD);
}

long long power_mod(long long x, long long n){
	long long ans = 1;
	for(;n;n>>=1,x*=x,ans%=MOD,x%=MOD)
		if(n&1)ans*=x;
	return ans%MOD;
}

void exgcd(int a, int b, int &x, int &y){
	if(b == 0){
		x = 1;
		y = 0;
		return ;
	}
	exgcd(b,a%b,y,x);
	y -= a/b * x;
}

void modular_multiplicatibe_inverse(){
	int x, y;  
	exgcd(fac[MAX_VAL-1],MOD,x,y);
	mmi[MAX_VAL-1] = x; //上も下もやっていることは同じ..ただpowerのほうが若干不便
	// mmi[MAX_VAL-1] = power_mod(fac[MAX_VAL-1],MOD-2);
	for(long long i = MAX_VAL-2; i >= 0; mmi[i]%=MOD,i--)
		mmi[i] = mmi[i+1]*((i+1)%MOD);
}

long long combination(long long n, long long r){
	return n < r ? 0 :fac[n]*(mmi[r]*mmi[n-r]%MOD)%MOD;
}

signed main(){
	cin.tie(nullptr);
	ios::sync_with_stdio(false);
	cout<<fixed<<setprecision(10);
	
	
	factorial_mod();
	modular_multiplicatibe_inverse();
	
	int ans = 0;
	int N, K;
	vector<int> A;
	
	cin>>N>>K;
	
	if(K == 1) {
		cout<<0<<endl;
		return 0;
	}
	
	A.resize(N);
	
	for(int i = 0; i < N; i++){
		cin>>A[i];
	}
	
	sort(A.begin(), A.end());
	
	for(int i = K-1, sum = 0; i < N; i++){
		sum += combination(i-1,K-2);
		sum %= MOD;
		int hoge = sum * A[i] % MOD;
		int fuga = sum * A[N-i-1] % MOD;
		
		// cout<<i<<" "<<N-i-1<<endl;
		// cout<<hoge<<" "<<fuga<<endl;
		// cout<<i-1<<" C "<<K-2<<" "<<combination(i-1,K-2)<<" sum = "<<sum<<endl;
		
		ans = (MOD + ans + hoge)%MOD;
		ans = (MOD + ans - fuga)%MOD;
		
	}
	
	
	
	cout<<ans<<endl;
	
	return 0;
}

Measured memory_bytes: 4224
#include<stdio.h>

int main(){
  int n,q,i,key,j,k=0,left,right,mid;
  scanf("%d",&n);
  int S[n];
  for(i=0;i<n;i++){
    scanf("%d",&S[i]);
  }
  scanf("%d",&q);
  int T[q];
  for(i=0;i<q;i++){
    scanf("%d",&T[i]);
  }
  for(j=0;j<q;j++){
    left = 0;
    right = n;
    key=T[j];
    while(left<right){
      mid = (left + right)/2;
      if(S[mid]==key){
	k++;
	break;
      }
      else if(key<S[mid]){
	right = mid;
      }
      else{
	left = mid + 1;
      }
    }
  }

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

  return 0;
}
      
      



Measured memory_bytes: 2280
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<iostream>
#include<vector>
#include<queue>
#include<cmath>
#include<map>
#include<set>
#define ll long long
#define F(i,a,b) for(int i=(a);i<=(b);i++)
#define mst(a,b) memset((a),(b),sizeof(a))
#define PII pair<int,int>
using namespace std;
template<class T>inline void read(T &x) {
    x=0; int ch=getchar(),f=0;
    while(ch<'0'||ch>'9'){if (ch=='-') f=1;ch=getchar();}
    while (ch>='0'&&ch<='9'){x=(x<<1)+(x<<3)+(ch^48);ch=getchar();}
    if(f)x=-x;
}
const int inf=0x3f3f3f3f;
const int maxn=3050;
int n,m;
int v[maxn],w[maxn],f[maxn][maxn];
int p[maxn],num;
int main()
{
	cin>>n>>m;
	int maxx=0,pos=0;
	for(int i=1;i<=n;i++) cin>>v[i]>>w[i];
	for(int i=n;i>=1;i--)
    {
        for(int j=0;j<=m-1;j++)
        {
            f[i][j]=f[i+1][j];
            if(j-v[i]>=0) f[i][j]=max(f[i][j],f[i+1][j-v[i]]+w[i]);
        }
    }
	int temp=m-1;
	for(int i=1;i<=n;i++)
    {
        if(temp-v[i]>=0&&f[i][temp]==f[i+1][temp-v[i]]+w[i])
        {
            temp-=v[i];
        }
        else p[++num]=w[i];
    }
	sort(p+1,p+num+1);
	cout<<f[1][m-1]+p[num]<<endl;
	return 0;
}


Measured memory_bytes: 36096
N = int(input())
ans = 0
for i in range(2, 10 ** 6 + 1):
    for x in range(1, 40):
        y = i ** x
        if N // y == N / y:
            ans += 1
            N = N // y
        else:
            while N // i == N / i:
                N = N // i
            break


if N > 10 ** 6:
    ans += 1
print(ans)

Measured memory_bytes: 65096
using System;
using System.Collections.Generic;

namespace ITP1_1_A
{
    class Program
    {

        static private int inputRow;
        static private int inputColumn;
        static private List<int> inputTable = new List<int>();
        static private List<string> outputTable = new List<string>();


        static void Main(string[] args)
        {   
                InputRowColumn();
                InputTable();
                OutputRowSum();
            int sum = 0;
            for (int i=0;i<inputColumn;i++)
            {  
                Console.Write(CalculateColumn(i)+" ");
                sum += CalculateColumn(i);
            }
            Console.WriteLine(sum);

        }
        static void InputRowColumn()
        {
            string[] num = Console.ReadLine().Split();
           
            inputRow = int.Parse(num[0]);
            inputColumn = int.Parse(num[1]);
        }

        static void InputTable()
        {
            for(int i=0;i<inputRow;i++)
            {
                string[] num = Console.ReadLine().Split();
                for(int j=0;j<inputColumn;j++)
                {
                    inputTable.Add(int.Parse(num[j]));
                }
            }
        }

        static void OutputRowSum()
        {
            int sum = 0;
            for(int i=0;i<inputRow*inputColumn;i++)
            {
                sum += inputTable[i];
                Console.Write(inputTable[i] + " ");
                if (i % inputColumn == inputColumn-1)
                {
                    Console.WriteLine(sum);
                    sum = 0;
                }
            }
            
        }

        static int CalculateColumn(int columnCount)
         {
            int sum = 0;
            for (int i = 0; i < inputRow * inputColumn; i++)
            {
                if (i % inputColumn == columnCount)
                {
                    sum += inputTable[i];
                }
            }
            return sum;
        }
    }
}



Measured memory_bytes: 17960
#coding:utf-8

n = int(input())
a = input()
b = input()
c = input()
ans = 0

for i in range(n):
  if a[i]==b[i] and b[i]==c[i] and c[i]==a[i]:
    continue
  elif a[i]==b[i] or b[i]==c[i] or c[i]==a[i]:
    ans += 1 
  else:
    ans += 2

print(ans)

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

#ifndef ONLINE_JUDGE 
const bool DEBUG = true;
#else
const bool DEBUG = false;
#endif

using ll = long long;
using ull = unsigned long long;

#define F first
#define S second
#define all(x) begin(x), end(x)

template <class T>
void read_vector(vector<T>& arr) {
	const int size = arr.size();
	for (int i = 0; i < size; ++i) cin >> arr[i];
}

void exec()
{
	int n, k;
	cin >> n >> k;

	vector<int> arr(n);
	read_vector(arr);

	vector<int> dp(n, INT_MAX);
	dp[0] = 0;

	for (int i = 0; i < n - 1; ++i) {
		for (int j = 1; j <= k; ++j) {
			if (i + j < n)
				dp[i + j] = min(dp[i + j], dp[i] + abs(arr[i] - arr[i + j]));
		}
	}

	cout << dp.back() << endl;
}

















int main()
{
	exec();

	return 0;
}

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

int main(){

    int t1,t2;
    ll a1,b1,a2,b2;
    cin>>t1>>t2;
    cin>>a1>>a2>>b1>>b2;
    if(a1<b1) swap(a1,b1),swap(a2,b2);

    ll s1=t1*a1+t2*a2;
    ll s2=t1*b1+t2*b2;
    if(s1==s2){
        printf("infinity\n");
        return 0;
    }
    if(s1>s2){
        printf("0\n");
        return 0;
    }
    ll len=t1*(a1-b1);
    ll d=s2-s1;

    ll ans=1+2*(len/d)-(len%d==0);
    printf("%lld\n", ans);

    return 0;
}

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

int main(void) {
	char ninput[10];
	char *ainput;
	int n;
	int *numbers;
	int i;
	
	fgets(ninput, sizeof(ninput), stdin);
	n = atoi(ninput);
	
	if (n <= 0){
		return 0;
	}
	
	ainput = (char *)malloc(sizeof(char) * 5 * n + 1);
	numbers = (int *)malloc(sizeof(int) * n);
	fgets(ainput, sizeof(char) * 5 * n + 1, stdin);
	
	numbers[0] = atoi(strtok(ainput, " "));
	for (i = 1; i < n; i++){
		numbers[i] = atoi(strtok(NULL, " "));
	}
	
	for (i = (n - 1); i >= 1; i--){
		printf("%d ", numbers[i]);
	}
	
	printf("%d\n", numbers[0]);
	
	free(ainput);
	free(numbers);
	return 0;
}

Measured memory_bytes: 564
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N=200005;
int n,n2,ne[N],g[N][26];
char s[N];
ll l,r;
ll cal(int now,ll m){
	if (m<=n)return g[m][now];
	ll l1=n,l2=n2,k,s1=g[l1][now],s2=g[l2][now];
	while (l1+l2<=m){
		k=l1;l1+=l2;l2=k;
		k=s1;s1+=s2;s2=k;
	}
	return s1+cal(now,m-l1);
}
int main(){
	scanf("%s",s+1);
	n=strlen(s+1)/2;
	ne[0]=-1;
	for (int i=1,j=-1;i<=n;i++){
		while (j>=0&&s[j+1]!=s[i])j=ne[j];
		j++;ne[i]=j;
	}
	n2=n-ne[n];
	for (int i=1;i<=n;i++){
		for (int j=0;j<26;j++)g[i][j]=g[i-1][j];
		g[i][s[i]-97]++;
	}
	scanf("%lld%lld",&l,&r);
	for (int now=0;now<26;now++)printf("%lld ",cal(now,r)-cal(now,l-1));
}


Measured memory_bytes: 12928
#include <iostream>
#include <algorithm>
#include <string>
using namespace std;
int main(void){
    // Your code here!
    int N,cnt=0,max=0;
    scanf("%d",&N);
    char S;
    for(int i=0;i<=N;i++){
        scanf("%c",&S);
        if(S=='I'){cnt+=1;}
        else if(S=='D'){cnt-=1;}
        if(cnt>max){max=cnt;}
        //cout<<S<<cnt<<endl;
    }
    cout<<max<<endl;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rb(x) ((x)&(-(x)))
using namespace std;
typedef long long ll;

const int MAXN = 200055;

struct BIT {
	ll d[MAXN];
	void upd(int x, ll r) {
		for(x += 5; x < MAXN; x += rb(x))
			if(d[x] < r) d[x] = r;
	}
	ll get(int x) {
		ll r = 0; for(x += 5; x; x -= rb(x))
			if(r < d[x]) r = d[x];
		return r;
	}
} bit;

int A[MAXN], B[MAXN];

int N;

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

	cin >> N;
	for(int i = 1; i <= N; i++) cin >> A[i];
	for(int i = 1; i <= N; i++) cin >> B[i];

	for(int i = 1; i <= N; i++) {
		ll t = bit.get(A[i]-1) + B[i];
		bit.upd(A[i], t);
	}

	cout << bit.get(N) << endl;
	return 0;
}

Measured memory_bytes: 3328
from collections import deque

n=int(input())
E=[[]for _ in range(n)]
L=[]
for i in range(n-1):
   a,b=map(int,input().split())
   E[a-1].append(b-1)
   L.append(b-1)

que=deque([0])
ans=[0]*n
while que:
   s=que.pop()
   color=1
   for ni in E[s]:
      if color==ans[s]:
         color+=1
      ans[ni]=color
      color+=1
      que.append(ni)
print(max(ans))
for ni in L:
   print(ans[ni])

Measured memory_bytes: 68256
#include <queue>
#include <iostream>
#include <cmath>
#include <cstdlib>
#include <algorithm>
#include <stack>
#include <string>
#include <vector>
#include <map>

using namespace std;

#define rep(i, n) for(int i = 0; i < (int)(n); i++)
typedef long long ll;
typedef vector<ll> vint;
typedef vector<string> vstr;
typedef pair<ll, ll> pint;
unsigned long long inf = (1LL << 62);
ll mod = 1000000007;

//bool operator< (pint a, pint b) {
	//return a.second < b.second;

//}



ll gcd(ll a, ll b) {

	if (b == 0)
		return a;

	return gcd(b, a % b);


}

ll max(ll a, ll b) {
	if (a < b) {
		return b;
	}
	else
		return a;

}

ll min(ll a, ll b) {
	if (a < b)
		return a;

	return b;
}




pint dx[4] = { {1, 0}, {-1, 0}, {0, 1}, {0, -1} };

vector<pint> list;










void floyd(int N, ll** d) {

	rep(k, N+1){
		rep(i, N+1) {
			if (d[i+1][k+1] == inf) continue;
			rep(j, N+1) {
				if (d[j+1][k+1] == inf) continue;

				d[i+1][j+1] = min(d[i+1][j+1], d[i+1][k+1] + d[j+1][k+1]);

			}

		}
	}




}


ll vis[100005];
ll d[100005];
vector<pint> M[100005];
vector<ll> anslist;
void dfs(ll K, ll dist) {

	d[K] = dist;
	vis[K] = 1;
	for (int i = 0; i < M[K].size(); i++) {
		if (vis[M[K][i].first] == 0) {
			dfs(M[K][i].first, dist + M[K][i].second);
		}
	}

}


ll a[10005];
ll ans[105][105];

int main() {
	ll H, W, N;


	cin >> H >> W >> N;


	rep(i, N) {
		cin >> a[i];
	}

	int index_x = 0, index_y = 0;


	rep(i, N) {
		rep(j, a[i]) {
			ans[index_x][index_y] = i + 1;

			if (index_x % 2 == 0) {
				if (index_y == W - 1)
					index_x += 1;
				else
					index_y += 1;
			}
			else {
				if (index_y == 0)
					index_x += 1;
				else
	             index_y -= 1;
			}


		}
	}

	rep(i, H) {
		rep(j, W) {
			cout << ans[i][j] << " ";
		}
		cout << endl;
	}


	return 0;
}

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

using namespace std;

typedef unsigned long long ull;
typedef long long ll;
typedef pair<int, int> ii;
typedef vector<ii> vii;
typedef vector<int> vi;
typedef vector<ll> vll;

#define PI (2*acos(0.0))
#define eps 1e-9
#define pb push_back
#define endl "\n"
#define watch(x) cout << (#x) << " is " << (x) << endl;
#define show(v) for(int fi = 0; fi < v.size(); fi++) cout << v[fi] << " "; cout << endl;
#define showpair(v) for(int fi = 0; fi < v.size(); fi++) cout << v[fi].first << " " << v[fi].second << endl;
#define ff first
#define ss second
#define fu cout << "lol" << endl;
#define precision(n) cout << fixed << setprecision(n);
#define lb lower_bound
#define up upper_bound
#define vscan for(i = 0;i<n;i++){cin>>in; v.pb(in);}
#define all(a) a.begin(), a.end()
#define min3(a,b,c) min(a,min(b,c))
#define max3(a,b,c) max(a,max(b,c))
#define mem(a,val) memset(a,val,sizeof(a))
#define loop(i,n) for(i = 0; i < n; i++)
#define TC() ull T; cin>>T; while(T--)
#define IN(x) {scanf("%d",&x);}
#define LL(x) {scanf("%lld",&x);}
#define CC(x) {scanf("%c",&x);}
#define pfl(x) printf("%d\n",x)
#define pfll(x) printf("%lld\n",x)
#define newl puts("")
#define space printf(" ")
#define MOD 1000000007
#define speed ios_base::sync_with_stdio(false); cin.tie(NULL);

int main()
{
    ll i = 0, j = 0, cs = 0, in;
    ll n, k; cin>>n>>k;
    ll ans = 0;
    for(i = k; i <= n+1; i++){
        ll x = i*(i-1) / 2;
        ll a = (n-i)*(n-i+1)/2;
        ll b = n*(n+1)/2;
        ll y = (b-a) - x + 1;
        ans += y;
        ans %= MOD;
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 3588
#include<bits/stdc++.h>
using namespace std;
using Int = long long;
template<typename T1,typename T2> inline void chmin(T1 &a,T2 b){if(a>b) a=b;}
template<typename T1,typename T2> inline void chmax(T1 &a,T2 b){if(a<b) a=b;}

//INSERT ABOVE HERE
signed main(){
  Int n,m;
  cin>>n>>m;
  vector<Int> bs(n,0);
  for(Int i=0;i<m;i++){
    Int k;
    cin>>k;
    for(Int j=0;j<k;j++){
      Int v;
      cin>>v;
      v--;
      bs[v]|=(1<<i);      
    }    
  }
  Int tgt=0;
  for(Int i=0;i<m;i++){
    Int p;
    cin>>p;
    tgt|=(p<<i);
  }
  
  Int s=1<<n;
  Int ans=0;
  for(Int b=0;b<s;b++){
    Int res=0;
    for(Int i=0;i<n;i++)
      if((b>>i)&1) res^=bs[i];
    if(tgt==res) ans++;
  }
  
  cout<<ans<<endl;
  return 0;
}


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

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


Measured memory_bytes: 256
times = []
sum = 0
minimum = 0
# 一つずつ調理にかかる時間をtimesに格納する。
(1..5).each do
    time = gets.chomp.to_i
    # 調理時間が10の単位ならsumにそのまま足す
    if time% 10 == 0
        sum = sum + time
    # 調理時間が10の単位以外の場合timesに格納する
    else
    times << time
    end
end
# timesの1つ1つの値の一桁目を確認する。
find_min = []
(0..times.length-1).each do |n|
    first_digit = times[n]%10
    find_min << first_digit
end
minimum = find_min.min
# timesから1の桁が一番小さい数字を削除する。複数あっても、一つ目が削除され、ループは終了する。
(0..times.length-1).each do |m|
    if times[m]%10 == minimum
        sum = sum + times[m]
        times.delete_at(m)
        break
    end
end
# 残った数字を1の桁で繰り上げる。
(0..times.length-1).each do |l|
    time_for_cooking = times[l].to_f/10
    sum = sum + time_for_cooking.ceil*10
end
puts sum
# (0..times.length-1).each do |m|

# 全部足す
#puts minimum

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

int main()
{
    int x1,x2,x3,x4,y1,y2,y3,y4;
    cin >> x1 >> y1 >> x2 >> y2;
    x3 = x2-(y2-y1);
    y3 = y2+(x2-x1);
    x4 = x3-(y3-y2);
    y4 = y3+(x3-x2);
    cout << x3 << " " << y3 << " " << x4 << " " << y4 << endl;
    return 0;
}


Measured memory_bytes: 256
from collections import defaultdict

N, M = map(int, input().split())
P = list(map(int, input().split()))
E = defaultdict(list)

for _ in range(M):
    x, y = map(int, input().split())
    E[x].append(y)
    E[y].append(x)

visited = [False] * (N+1)
connected = []
for i in range(1, N+1):
    if visited[i]:
        continue
    visited[i] = True
    temp = [i]
    stack = [v for v in E[i]]
    while stack:
        v = stack.pop()
        if visited[v]:
            continue
        visited[v] = True
        temp.append(v)
        stack += E[v]
    connected.append(temp)

ans = 0
for cn in connected:
    ans += len(set(cn) & set([P[i-1] for i in cn]))
print(ans)

Measured memory_bytes: 48364
S = input()
K = int(input())

ans1 = 0
prev = '#'
for i in range(len(S)):
    if S[i] == prev:
        ans1 += 1
        prev = '#'
    else:
        prev = S[i]

if prev != S[0]:
    print(ans1 * K)
    exit()

ans2 = 0
for i in range(len(S)):
    if S[i] == prev:
        ans2 += 1
        prev = '#'
    else:
        prev = S[i]

if prev == S[0]:
    print(ans1 + ans2 * (K-1))
else:
    print(ans1 * (K - K // 2) + ans2 * (K // 2))


Measured memory_bytes: 38384