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

typedef unsigned long long ull;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<double, double> pdd;
const ull mod = 1e9 + 7;
#define REP(i,n) for(int i=0;i<(int)n;++i)

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

template<class S, class T> ostream& operator << (ostream& os, const pair<S, T> v){
  os << "(" << v.first << ", " << v.second << ")"; return os;
}
template<class T> ostream& operator << (ostream& os, const vector<T> v){
  for(int i = 0; i < v.size(); i++){if(i > 0){os << " ";} os << v[i];} return os;
}
template<class T> ostream& operator << (ostream& os, const vector<vector<T>> v){
  for(int i = 0; i < v.size(); i++){if(i > 0){os << endl;} os << v[i];} return os;
}

const ll MS = 2;
const ll mods[] = {999999937ll, 1000000007ll}, base = 9973;
struct rolling_hash {
    int n;
    vector<ll> hs[MS], pw[MS];
    rolling_hash(){}
    rolling_hash(const string &s) {
        n = s.size();
        for (int i = 0; i < MS; i++) {
            hs[i].assign(n+1,0);
            pw[i].assign(n+1,0);
            hs[i][0] = 0;
            pw[i][0] = 1;
            for (int j = 0; j < n; j++) {
                pw[i][j+1] = pw[i][j]*base%mods[i];
                hs[i][j+1] = (hs[i][j]*base+s[j])%mods[i];
            }
        }
    }

    // hash number of segment [l, r)
    ll hash(int l, int r, int i) { return ((hs[i][r]-hs[i][l]*pw[i][r-l])%mods[i]+mods[i])%mods[i]; }

    bool match(int l1, int r1, int l2, int r2) {
        bool ret = 1;
        for (int i = 0; i < MS; i++) ret &= hash(l1,r1,i)==hash(l2,r2,i);
        return ret;
    }

    bool match(int l, int r, ll h[]) {
        bool ret = 1;
        for (int i = 0; i < MS; i++) ret &= hash(l,r,i)==h[i];
        return ret;
    }
};

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

    ll N;
    string S;
    cin >> N >> S;

    ll lb = -1;
    ll ub = N;
    rolling_hash rh(S);
    while(ub-lb>1){
    	ll m = (ub+lb)/2;

    	vector<bool> ok = {false, false};
    	REP(r, 2){
	    	multiset<ll> st;
	    	for(int i=m;i<N;i++){
	    		st.insert(rh.hash(i, i+m, r));
	    	}
	    	for(int i=0;i<N-m+1;i++){
	    		ll ha = rh.hash(i, i+m, r);
	    		auto itr = st.find(ha);
	    		if(itr!=st.end()) ok[r] = true;
	    		if(i+2*m>N) continue;
	    		ll ha2 = rh.hash(i+m, i+2*m, r);
	    		auto itr2 = st.find(ha2);
	    		if(itr2 != st.end()) st.erase(itr2);
	    	}
	    }

    	if(ok[0] && ok[1]) lb = m;
    	else ub = m;
    }
    cout << ub-1 << endl;
    return 0;
}

Measured memory_bytes: 640
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define mod 1000000007
#define endl "\n" 
#define p pair<int, int>
#define arrinp(i, a, start, end); for(ll i = start; i <= end; i++) cin >> a[i];
#define arrout(i, a, start, end); for(ll i = start; i <= end; i++) cout << a[i] << " ";
#define swap(a, b) {a = a + b; b = a - b; a = a - b;
#define forfront(i, start, end) for(ll i = start; i <= end; i++)
#define forback(i, start, end) for(ll i = start; i >= end; i--)
#define out(x) cout << x << " ";
#define outline(x) cout << x << endl;
#define sortvector(v) sort(v.begin(), v.end());
#define sortvectorrev(v) sort(v.rbegin(), v.rend());
char mat[10][10];
int h, w;
int solve(vector<int> row, vector<int> col)
{
    int count = 0;
    for(int x : row)
    {
        for(int i = 1; i <= w; i++)
        {
            if(mat[x][i] == '#') count++;
        }
    }
    for(int x : col)
    {
        for(int i = 1; i <= h; i++)
        {
            if(mat[i][x] == '#') count++;
        }
    }
    for(int x : row)
    {
        for(int y : col)
        {
            if(mat[x][y] == '#') count--;
        }
    }
    return count;
}
int main()
{
    #ifdef LOCAL
        freopen("input.txt", "r", stdin);
        freopen("output.txt", "w", stdout);
    #endif
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cin >> h >> w;
    int k;
    cin >> k;
    int black = 0;
    for(int i = 1; i <= h; i++)
    {
        for(int j = 1; j <= w; j++)
        {
            cin >> mat[i][j];
            if(mat[i][j] == '#') black++;
        }
    }
    if(black < k)
    {
        outline(0)
        return 0;
    }
    int ans = 0;
    for(int i = 0; i < pow(2, h); i++)
    {
        int temp = i;
        vector<int> rows, cols;
        for(int k = 1; k <= h; k++)
        {
            int rem = temp%2;
            temp /= 2;
            if(rem == 1)
            {
                rows.push_back(k);
            }
        }
        for(int j = 0; j < pow(2, w); j++)
        {
            temp = j;
            for(int k = 1; k <= w; k++)
            {
                int rem = temp%2;
                temp /= 2;
                if(rem == 1) cols.push_back(k);
            }
            int counter = solve(rows, cols);
            // for(int x : rows)
            //     out(x)
            // cout << endl;
            // for(int x : cols)
            //     out(x)
            // cout << endl;
            // outline(counter)
            if(counter == black - k) ans++;
            cols.clear();
        }
        rows.clear();
    }
    outline(ans)
    return 0;
}

Measured memory_bytes: 4036
#include <iostream>
#include <cstdio>
#include <cmath>
#include <ctime>
#include <cstdlib>
#include <cassert>
#include <vector>
#include <list>
#include <stack>
#include <queue>
#include <deque>
#include <map>
#include <set>
#include <bitset>
#include <string>
#include <algorithm>
#include <utility>
#define llint long long
#define inf 1e18
#define rep(x, s, t) for(llint (x) = (s); (x) < (t); (x)++)
#define Rep(x, s, t) for(llint (x) = (s); (x) <= (t); (x)++)
#define chmin(x, y) (x) = min((x), (y))
#define chmax(x, y) (x) = max((x), (y))
#define mod 1000000007

using namespace std;
typedef pair<llint, llint> P;

llint n;
P p[200005];
map<P, llint> mp;
set<P> S;

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

P normal(P p)
{
	llint dx = p.first, dy = p.second;
	if(dx == 0) return P(0, 1);
	if(dy == 0) return P(1, 0);
	if(dx < 0) dx *= -1, dy *= -1;
	llint g = gcd(abs(dx), abs(dy));
	dx /= g, dy /= g;
	return P(dx, dy);
}

P get(P p)
{
	if(p == P(1, 0)) return P(0, 1);
	swap(p.first, p.second);
	p.second *= -1;
	if(p.first < 0) p.first *= -1, p.second *= -1;
	return p;
}

llint modpow(llint a, llint n)
{
	if(n == 0) return 1;
	if(n % 2){
		return ((a%mod) * (modpow(a, n-1)%mod)) % mod;
	}
	else{
		return modpow((a*a)%mod, n/2) % mod;
	}
}

int main(void)
{
	ios::sync_with_stdio(0);
	cin.tie(0);
	
	cin >> n;
	
	llint m = 0;
	for(int i = 1; i<= n; i++){
		cin >> p[i].first >> p[i].second;
		if(p[i].first == 0 && p[i].second == 0){
			m++;
			continue;
		}
		mp[normal(p[i])]++;
	}
	for(auto it = mp.begin(); it != mp.end(); it++) S.insert(get(it->first));
	for(auto it = S.begin(); it != S.end(); it++) mp[*it];
	
	llint ans = 1;
	for(auto it = mp.begin(); it != mp.end(); it++){
		if(it->first.second <= 0) continue;
		P p = get(it->first);
		//cout << it->second << " " << mp[p] << endl;
		llint tmp = modpow(2, it->second) + modpow(2, mp[p]) + mod - 1; tmp %= mod;
		ans *= tmp, ans %= mod;
	}
	ans += m, ans %= mod;
	ans += mod-1, ans %= mod;
	cout << ans << endl;
	
	return 0;
}

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

int main(void)
{
    using namespace std;
    long int N, K;
    cin >> N >> K;

    if (K == 1) {
        printf("0\n");
    } else if (N > K) {
        long int tmp = N % K;
        printf("%ld", abs(tmp - K));
    } else {
        while (true) {
            if (N < abs(N - K)) {
                printf("%ld\n", N);
                break;
            } else {
                N = abs(N - K);
            }
        }
    }
}

Measured memory_bytes: 256
//	-*- mode: C++ -*-
//	Finding Missing Cards
//		Taro is going to play a card game. However, now he has only n cards, even though there should be 52 cards (he has no Jokers).
//
//		The 52 cards include 13 ranks of each of the four suits: spade, heart, club and diamond.
//
//	Input
//		In the first line, the number of cards n (n ≤ 52) is given.
//
//		In the following n lines, data of the n cards are given. Each card is given by a pair of a character and an integer which represent its suit and rank respectively. A suit is represented by 'S', 'H', 'C' and 'D' for spades, hearts, clubs and diamonds respectively. A rank is represented by an integer from 1 to 13.
//
//	Output
//		Print the missing cards. The same as the input format, each card should be printed with a character and an integer separated by a space character in a line. Arrange the missing cards in the following priorities:
//
//		Print cards of spades, hearts, clubs and diamonds in this order.
//		If the ranks are equal, print cards with lower ranks first.
//	Sample Input
//		47
//		S 10
//		S 11
//		S 12
//		S 13
//		H 1
//		H 2
//		S 6
//		S 7
//		S 8
//		S 9
//		H 6
//		H 8
//		H 9
//		H 10
//		H 11
//		H 4
//		H 5
//		S 2
//		S 3
//		S 4
//		S 5
//		H 12
//		H 13
//		C 1
//		C 2
//		D 1
//		D 2
//		D 3
//		D 4
//		D 5
//		D 6
//		D 7
//		C 3
//		C 4
//		C 5
//		C 6
//		C 7
//		C 8
//		C 9
//		C 10
//		C 11
//		C 13
//		D 9
//		D 10
//		D 11
//		D 12
//		D 13
//	Sample Output
//		S 1
//		H 3
//		H 7
//		C 12
//		D 8

#include <iostream>
#include <list>
#include <utility>
#include <algorithm>

void	initialize(std::list<std::pair<char, unsigned int>>	&l)
{
	for(unsigned int i = 0; i < 4; i++){
		char	c	{'\0'};
		switch(i){
		case 0:		c	= 'S';	break;
		case 1:		c	= 'H';	break;
		case 2:		c	= 'C';	break;
		default:	c	= 'D';	break;
		}

		for(unsigned int j = 0; j < 13; j++){
			l.push_back(std::make_pair(c, j + 1));
		}
	}
}

int main(int	argc,
		 char*	argv[])
{
	unsigned int	n	{0};
	std::list<std::pair<char, unsigned int>>	l;

	initialize(l);

	std::cin >> n;


	for(unsigned int i = 0; i < n; i++){
		char			c	{'\0'};
		unsigned int	u	{0};

		std::cin >> c >> u;

		auto	ite	= std::find(l.begin(), l.end(), std::make_pair(c, u));
		if(ite != l.end()){
			l.erase(ite);
		}
	}

	for(auto p : l){
		std::cout << p.first << ' ' << p.second << '\n';
	}

    return 0;
}



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

int main() {
  int a, b; cin >> a >> b;
  if (a == 1) a = 14;
  if (b == 1) b = 14;
  cout << (a == b ? "Draw" : (a > b ? "Alice" : "Bob")) << endl;
}

Measured memory_bytes: 256
#include<stdio.h>
#include<math.h>
int main(){
  int i,j,k,n,count1,count2=0;
  int A[10000];
  
  scanf("%d",&n);

  for(i=0;i<n;i++){
    
    scanf("%d",&A[i]);
    count1=0;
    
    for(j=1;j<=sqrt(A[i]);j++){
      if(count1==2) break;
      if(A[i]%j==0) count1++;
    }
    
    if(count1==1) count2++;
      }
  printf("%d\n",count2);
      
  return 0;
}



Measured memory_bytes: 2128
#include<iostream>
#include<cstdio>
using namespace std;
int main(){
	double x,p;
	while(cin>>p,p!=-1){
		x=p/2;
		while(max(x*x*x-p,p-x*x*x)>=0.00001*p){
			x=x-(x*x*x-p)/(3*x*x);
		}
		printf("%.6lf\n",x);
	}
	return 0;
}
	
	

Measured memory_bytes: 0
using System;
using System.Collections.Generic;
using System.Linq;
using System.IO;
using System.Text;
using static System.Math;
using static System.Console;

namespace CPLib
{
    class Atria
    {
        const long mod = 1000000000 + 7;
        static void Main(string[] args)
        {
            int[] s = ReadLine().Split(' ').Select(int.Parse).ToArray();
            int h = s[0];
            int w = s[1];
            for (int i = 0; i < h; i++)
            {
                string[] str = ReadLine().Split(' ');
                char x = (char)((int)'A'-1);
                for (int j = 0; j < w; j++)
                {
                    x++;
                    if (str[j] == "snuke")
                    {
                        WriteLine(x+""+(i+1));
                        return;
                    }
                }
            }
        }
    }
}


Measured memory_bytes: 11348
MOD = 10 ** 9 + 7
INF = 10 ** 11
import sys
sys.setrecursionlimit(100000000)

N,A,B,C = map(int,input().split())
L = [int(input()) for _ in range(N)]

ans = INF
def dfs(i,before,score):
    global ans
    if i == N:
        if all(length > 0  for length in before):
            x,y,z = before
            for _ in range(3):
                ans = min(ans,abs(x - A) + abs(y - B) + abs(z - C) + score - 30)
                x,y,z = y,z,x
    else:
        dfs(i + 1,before,score)
        for j in range(3):
            before[j] += L[i]
            dfs(i + 1,before,score + 10)
            before[j] -= L[i]
dfs(0,[0,0,0],0)
print(ans)

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
#define all(v) (v).begin(), (v).end()
#define lp(i, n) for (int i = 0; i < (n) ; ++i)
#define sz(v) (ll)(v).size()
#define int long long

int fast_pow(int a, int p, int mod) {
        if (p == 0) return 1;
        if (p == 1) return a % mod;
        int ans = fast_pow(a, p >> 1, mod);
        ans = (ans * ans) % mod;
        if (p & 1) ans = a * ans;
        return ans % mod;
}

int get(int c) {
        int nm= 0;
        while (c) {
                c&= (c- 1);
                nm++;
        }
        return nm;
}

void solve() {
        int n; cin >> n;
        string str; cin >> str;
        int f= 0, s= 0, z= 0;
        lp(i, str.size()) if (str[i]== '1') z++;
        f= z+ 1;
        s= z- 1;
        int an1= 0, an2= 0, an= 0;
        lp(i, str.size()) {
                if (str[i]== '1') {
                        an1+= fast_pow(2, n- (i+ 1), f);
                        if (s) an2+= fast_pow(2, n- (i+ 1), s);
                }
        }
        map<int, int> mp;
        for (int i = 1; i<= 200001; i++) {
                int cnt= 0, k= i;
                while (k!= 0) {
                        cnt++;
                        k%= get(k);
                }
                mp[i]= cnt;
        }

        for (int i= 0; i< n; i++) {
                if (str[i]== '0') {
                        an= ((an1+ fast_pow(2, n- (i+ 1), f)% f) + f)% f;
                        cout <<1+ mp[an]<< "\n";
                } else {
                        if (s== 0) {
                                an= 0;
                                cout <<"0\n";
                        } else{
                                an=  ((an2- fast_pow(2, n- (i+ 1), s)% s) + s)% s;
                                cout <<1+ mp[an]<< "\n";
                        }
                }

        }
}

int32_t main(){
ios::sync_with_stdio(0), cin.tie(NULL), cout.tie(NULL);
        int t = 1;
        //cin >> t;
        while ( t-- ) {
                solve();
        }
return 0;
}


Measured memory_bytes: 16228
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define mp make_pair
#define pb push_back
#define rep(i,n) for(int i=0;i<n;i++)
#define rep1(i,n) for(int i=1;i<=(int)(n);i++)


int main(){
  int n,m;
  cin >> n >> m;
  ll dp[(1<<n)][n];
  ll ndp[(1<<n)][n];
  
  rep(i,(1<<n)) rep(j,n){
    dp[i][j]=0;
    ndp[i][j]=0;    
  }
  dp[1][0]=1;
  ndp[1][0]=1;
  vector<int> g[n];
  rep(i,m){
    int a,b;
    cin >> a >> b;
    a--;b--;
    g[a].pb(b);
    g[b].pb(a);
  }
  rep(h,n-1){
    rep(i,(1<<n)) rep(j,n){
      if(i&1){
    	for(auto l:g[j]){
	      if(i&(1<<l)) continue;
	      //cout << i << " " << j << " " << l <<endl;
	      ndp[i|(1<<l)][l]+=dp[i][j];
	    }
      }
    }
    //cout << ndp[3][1] << endl;
    //    swap(dp, ndp);
    rep(i,(1<<n)) rep(j,n) dp[i][j]=ndp[i][j];
  }

  ll ans=0;
  rep(j,n) ans +=dp[(1<<n)-1][j];
  cout << ans << endl;
  
  return 0;

}


Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<map>
#include<set>
#include<cassert>
#include<cassert>
#include<unordered_map>
#include<unordered_set>
#include<functional>
#include<queue>
#include<stack>
#include<cstring>
#include<algorithm>
#include<cmath>
#include<sstream>
#include<iomanip>
#include<cstdio>
#include<cstdlib>
#include<numeric>
#include<random>
#include<chrono>
#include<bitset>
using namespace std;

#define all(x) (x).begin(), (x).end()
#define pb push_back
#define xx first
#define yy second
#define sz(x) (int)(x).size()
#define gc getchar
#define IO ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#define mp make_pair

#ifndef ONLINE_JUDGE
#  define LOG(x) (cerr << #x << " = " << (x) << endl)
#else
#  define LOG(x) ((void)0)
#endif

typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;

const double PI=3.1415926535897932384626433832795;
const ll INF = 1LL<<62;
const ll MINF = -1LL<<62;

template<typename T> T getint() {
	T val=0;
	char c;
	
	bool neg=false;
	while((c=gc()) && !(c>='0' && c<='9')) {
		neg|=c=='-';
	}

	do {
		val=(val*10)+c-'0';
	} while((c=gc()) && (c>='0' && c<='9'));

	return val*(neg?-1:1);
}

//mt19937 rng(chrono::steady_clock::now().time_since_epoch().count()); uniform_int_distribution<int>(0, n-1)(rng)


int main() {
	IO;
	int n;
	cin>>n;
	string t;
	cin>>t;
	for(auto &i:t) {
		i-='A';
		i+=n;
		i%=26;
		i+='A';
	}cout<<t<<"\n";
	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
using namespace std;
 
int main() {
    int n;
    cin >> n;
    int a[n];
    for(int i=0;i<n;i++){
      cin >> a[i];
    }
    int sum=0;
    for(int i=1;i<(n-1);i++){
      if(a[i-1]<a[i] && a[i]<a[i+1]) sum++;
      else if (a[i-1]>a[i] && a[i]>a[i+1]) sum++;
      else sum = sum;
    }
    cout << sum << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <cmath>
#include <complex>
#include <string>
#include <sstream>
#include <limits>
#include <numeric>
#include <algorithm>
#include <functional>

using namespace std;

const int MOD = 2019;

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

	int L, R;
	cin >> L >> R;

	int dist = R - L + 1;
	if (dist >= MOD)
	{
		cout << 0;
		return 0;
	}

	int result = MOD;
	for (int i = L; i <= R; i++)
	{
		for (int j = i + 1; j <= R; j++)
		{
			result = min(result, ((i % MOD) * (j % MOD)) % MOD);
		}
	}

	cout << result;

	return 0;
}


Measured memory_bytes: 256
import java.util.*;

public class Main {

	public static void main (String[] args) {
		Scanner sc = new Scanner(System.in);
		char[][] c = new char[2][];
		for (int i = 0; i < 2; i++) {
			c[i] = sc.next().toCharArray();
		}
		if (c[0][0] == c[1][2] && c[0][1] == c[1][1] && c[0][2] == c[1][0]) {
			System.out.println("YES");
		} else {
			System.out.println("NO");
		}
	}
}


Measured memory_bytes: 21972
//Dragon_warrior7(IITK)
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define nl cout << '\n'
#define sor(x) sort(x.begin(), x.end())
#define rev(v) reverse(v.begin(), v.end())
#define maxin(v) *max_element(v.begin(), v.end())
#define minin(v) *min_element(v.begin(), v.end())
#define sumall(vect) accumulate(vect.begin(), vect.end(), 0)
#define count(x,vect) count(vect.begin(), vect.end(), x)
#define lb(v, temp) lower_bound(v.begin(), v.end(), temp)
#define ub(v, temp) upper_bound(v.begin(), v.end(), temp)
#define fi first
#define se second
#define llmax 100000000000000000
#define deb(x) cout <<#x<<" "<< x << "\n"
#define pll pair<ll, ll> 
#define vll vector<ll> 
#define rub cout << "------------------------------------\n"
#define mn(a,b,c) min(a,min(b,c))
#define mx(a,b,c) max(a,max(b,c))
int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	ll n;
	ll k;
	cin>>n>>k;
	string s;
	cin>>s;
	vll v;
	v.pb(0);
	for(int i=1;i<n;i++)
	if(s[i]!=s[i-1])
	v.pb(i);
	//for(int i=0;i<v.size();i++)
	//deb(v[i]);
	while(k--)
	{
	    if(v.size()==1)
	    break;
	    if(v.size()==2)
	    {v.pop_back();break;}
	    else
	    {v.pop_back();v.pop_back();}
	}
	cout<<n-v.size();
}
	

Measured memory_bytes: 1480
#include "bits/stdc++.h"
using namespace std;
#define LL long long

void solve() {
   int n;
   cin>>n;
   int ar[n];
   int sum=0,sm=0;
   set<int>st;
    int p=0;
   for(int i=0;i<n;i++){
       cin>>ar[i];
       p+=ar[i];
   }
  
   int m=(p+n-1)/n; 
   int q=p/n; 
   for(int i=0;i<n;i++){
       sum+=pow((ar[i]-m),2);
       sm+=pow((ar[i]-q),2);
   }
   cout<<min(sum,sm)<<"\n";
}
  
int main()
{
    ios_base::sync_with_stdio(0);
	cin.tie(NULL);
	solve();
 	return 0; 
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define F first
#define S second
#define endl '\n'
#define lcm( a, b ) ((a)/__gcd(a,b)*(b))
#define MP make_pair
#define pb push_back
#define all(x) (x).begin(),(x).end()

using namespace std;

typedef long long LL;
typedef pair<int, int> P;
typedef pair<int, P> iP;
typedef pair< LL, LL > LP;

const int INF = INT_MAX;
const int MIN = INT_MIN;
const LL LINF = LLONG_MAX;
const int MOD = 1000000000 + 7;
const int SIZE = 300005;

vector< int > Div( int n ) {
    vector< int > ret;
    for( int i = 1; i * i <= n; ++i ) {
        if( n % i ) {
            ret.pb( i );
            if( i * i != n ) ret.pb( n / i );

        }
    }
    sort( all( ret ) );
    return ret;
}

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

    int n;
    cin >> n;
    LL a[SIZE];
    LL d = 0;
    for( int i = 0; i < n; ++i ) {
        cin >> a[i];
        d += a[i];

    }

    LL sum = 0;
    LL res = LINF;
    for( int i = 0; i < n - 1; ++i ) {
        sum += a[i];
        d -= a[i];
        res = min( res, llabs( sum - d ) );

    }
    cout << res << endl;
    return 0;
}



Measured memory_bytes: 2432
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define repm(i, m, n) for (int i = (m); i < (int)(n); i++)
#define repr(i, n) for (int i = (n); i > 0; i--)
#define all(vec) vec.begin(), vec.end()
using namespace std;

int main(){
  int n;
  cin >> n;
  vector<int> h(n);
  rep(i, n) cin >> h[i];
  
  //int ans = 0;
  string ans = "Yes";
  //string ans = "No";
  //string ans = "YES";
  //string ans = "NO";
  int temp = -100;
  rep(i, n){
    if (temp <= h[i] - 1) temp = h[i] - 1;
    else if (temp <= h[i]) temp = h[i];
    else ans = "No";
  }
  
  cout << ans << endl;
}

Measured memory_bytes: 640
n = gets.to_i
m = gets.to_i
cars = [m]
err = false

n.times do
  in_num, out_num = gets.split.map(&:to_i)
  m = m + in_num - out_num

  err = true if m.negative?

  cars << m
end

if err
  p 0
else
  p cars.max
end



Measured memory_bytes: 8976
#include <iostream> // cout, endl, cin
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> //tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower
#include <numeric>
using namespace std;

int main() {
    int A, B, C, D;
    cin >> A >> B >> C >> D;
    bool twl;
    while (true) {
        C -= B;
        if (C <= 0) {
            twl = true;
            break;
        }
        A -= D;
        if (A <= 0) {
            twl = false;
            break;
        }
    }
    cout << (twl ? "Yes" : "No") << endl;
}

Measured memory_bytes: 3624
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for (int i = 0; i < (n); i++)
#define repd(i,a,b) for (int i = (a); i < (b); i++)
#define INF LLONG_MAX
typedef long long ll;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }

int main(void)
{
  ll N, W;
	cin >> N >> W;
	ll weight[N];
	ll value[N];
	ll dp[N+1][W+1];

	rep(i, N) cin >> weight[i] >> value[i];
	rep(i, N+1) rep(j, W+1) dp[i][j] = 0;
	rep(i, N)
	{
		rep(j, W+1)
		{
			if(j>=weight[i]) chmax(dp[i+1][j], dp[i][j-weight[i]]+value[i]);
			chmax(dp[i+1][j], dp[i][j]);
		}
	}
    cout << dp[N][W] << endl;
}

Measured memory_bytes: 79104
#include <iostream>

#define REP(i,k,n) for(int i=k;i<n;i++)
#define rep(i,n) for(int i=0;i<n;i++)
#define MAX 1000000

using namespace std;

int prime[MAX];

int main()
{

	prime[0] = prime[1] = 0;

	REP(i,2,MAX)
	{
		prime[i] = 1;
	}

	REP(i,2,MAX)
	{
		if(prime[i])
		{
			for(int j = i*2;j < MAX;j += i)
			{
				prime[j] = 0;
			}
		}
	}



	int n;
	while(cin >> n && n)
	{
		int count = 0;
		int ans = 0;
		rep(i,MAX)
		{
			if(count == n) break;

			if(prime[i] == 1)
			{
				ans += i;
				count++;
			}
		}

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

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

using namespace std;

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n;
    cin >> n;
    set<int> sa;
    for (int i = 0; i < n; i++) {
        int a;
        cin >> a;
        sa.insert(a);
    }
    if ((int)sa.size() == n) {
        cout << "YES" << endl;
    } else {
        cout << "NO" << endl;
    }
    return 0;
}


Measured memory_bytes: 9600
import Control.Monad (replicateM,forM_)
import Data.Array (Array, assocs, accum, (!))
import Data.List (partition)
import qualified Data.Array.ST as STArr

type Wins = Array Int [Int]
type LoseCounts = Array Int Int

main = do
    n <- readLn 
    m <- readLn
    rels <- replicateM m (getLine >>= return . relation . map read . words)

    let
        (sorted,fixed) = solve n rels

    forM_ sorted print
    print (if fixed then 0 else 1)

    where
    relation [a,b] = (a,b)

solve :: Int -> [(Int,Int)] -> ([Int],Bool)
solve n rels = groups `seq` (concat groups, all (==1) $ map length groups)
    where
    groups = wins' `seq` lcs `seq` solve' wins' [1..n] lcs []
    wins' = wins n rels
    lcs = loseCounts n rels

    solve' _ [] _ acc = reverse acc
    solve' wins ns lcs acc = ns' `seq` lcs' `seq` nolose `seq`
                             solve' wins ns' lcs' (nolose:acc)
        where
        (nolose,ns') = partition (\n -> lcs!n == 0) ns
        lcs' = foldr decl lcs nolose
        decl n lcs = accum (-) lcs [(i,1)|i<-wins!n]

wins :: Int -> [(Int,Int)] -> Wins
wins n rels = STArr.runSTArray $ do
    arr <- STArr.newArray (1,n) []
    forM_ rels (update arr)
    return arr
    where
    update arr (a,b) = do
        bs <- STArr.readArray arr a
        STArr.writeArray arr a (b:bs)

loseCounts :: Int -> [(Int,Int)] -> LoseCounts
loseCounts n rels = STArr.runSTArray $ do
    arr <- STArr.newArray (1,n) 0
    forM_ rels (update arr)
    return arr
    where
    update arr (_,b) = do
        c <- STArr.readArray arr b
        STArr.writeArray arr b (c+1)

Measured memory_bytes: 78968
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<(n);i++)
using ll = long long;
using P = pair<int,int>;
int main(void) {
    int n, m; cin >> n >> m;
    cout << (n-1) * (m-1);
}


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

using namespace std;

int main(){
    long N;
    long ga, gb, sa, sb, ba, bb;
    cin >> N;
    cin >> ga >> sa >> ba >> gb >> sb >> bb;
    long cnt = N;
    
    for(long i = 0; i*ga <= N; i++){
        if(gb <= ga && i > 0) break;
        long K = N-i*ga;
        for(long j = 0; j*sa <= K; j++){
            if(sb <= sa && j > 0) break;
            if(bb > ba) {
                long k = (N-(i*ga+j*sa))/ba;
                cnt = max(cnt, N+i*(gb-ga)+j*(sb-sa)+k*(bb-ba));
            }
            else cnt = max(cnt, N+i*(gb-ga)+j*(sb-sa));
            //cout << N+i*(gb-ga) << endl;
        }
    }
    int N_ = N;
    N = cnt;
    if(N == N_){
        for(long i = 0; i*gb <= N; i++){
            if(ga <= gb && i > 0) break;
            long K = N-i*gb;
            for(long j = 0; j*sb <= K; j++){
                if(sa <= sb && j > 0) break;
                if(ba > bb){
                    long k = (N-(i*gb+j*sb))/bb;
                    cnt = max(cnt, N+i*(ga-gb)+j*(sa-sb)+k*(ba-bb));
                }
                else cnt = max(cnt, N+i*(ga-gb)+j*(sa-sb));
            }
        }
    }else{
        if(ga < gb){
            swap(ga, ba);
            swap(gb, bb);
        }else if(sa < sb){
            swap(sa, ba);
            swap(sb, bb);
        }
        for(long i = 0; i*gb <= N; i++){
            //if(ga <= gb && i > 0) break;
            long K = N-i*gb;
            long j = K/sb;
            cnt = max(cnt, N+i*(ga-gb)+j*(sa-sb));
        }
    }
    cout << cnt << endl;
}

Measured memory_bytes: 888
#!/usr/bin/env python3
import sys, math, fractions, itertools, collections


def solve(n: int, v: "List[int]"):
    o = v[1::2]
    e = v[::2]
    oc = collections.Counter(o).most_common()
    ec = collections.Counter(e).most_common()
    if len(oc) > 1:
        om1, om2 = oc[0], oc[1]
    else:
        om1, om2 = oc[0], (-1, 0)
    if len(ec) > 1:
        em1, em2 = ec[0], ec[1]
    else:
        em1, em2 = ec[0], (-1, 0)
    if om1[0] != em1[0]:
        print(n - om1[1] - em1[1])
    else:
        print(min(n-om1[1]-em2[1], n-om2[1]-em1[1]))
    return


# Generated by 1.1.4 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    n = int(next(tokens))  # type: int
    v = [ int(next(tokens)) for _ in range(n) ]  # type: "List[int]"
    solve(n, v)

if __name__ == '__main__':
    main()


Measured memory_bytes: 29644
#include<bits/stdc++.h>
using namespace std;
const int mod=1e9+7;
long long int quick_pow(int n,long long int base)
{
    long long int ans=1;
    while(n)
    {
        if(n&1)
        {
            ans*=base;
            ans%=mod;
        }
        n>>=1;
        base*=base;
        base%=mod;
    }
    return ans;
}
long long int C(int a,int b)
{
    //cout<<a<<"**"<<b<<endl;
    long long int fm=1;
    for(int i=1;i<=a;++i)
    {
        fm*=i;
        fm%=mod;
    }
    long long int fz=1;
    for(int i=b-a+1;i<=b;++i)
    {
        fz*=i;
        fz%=mod;
    }
    //cout<<fz<<" "<<fm<<endl;
    return fz*quick_pow(mod-2,fm)%mod;
}
int main()
{
    int n,a,b;
    cin>>n>>a>>b;
    long long int al=quick_pow(n,2)-1;
    long long int sub1=C(a,n)%mod;
    long long int sub2=C(b,n)%mod;
    //cout<<al<<" "<<sub1<<" "<<sub2<<endl;
    cout<<((al-sub1+mod)%mod-sub2+mod)%mod<<endl;
    return 0;
}


Measured memory_bytes: 256
n, m = map(int, input().split())
ab = [list(map(int, input().split())) for _ in range(n)]
cd = [list(map(int, input().split())) for _ in range(m)]
for a, b in ab:
    l = [abs(a-c)+abs(b-d) for c, d in cd]
    print(l.index(min(l))+1)


Measured memory_bytes: 3316
a, b, c=map(int, input().split())
if a > b:
    if b > c:
        print(c,b,a)
    else:
        if a > c:
            print(b,c,a)
        else:
            print(b,a,c)
else:
    if a > c:
        print(c,a,b)
    else:
        if b > c:
            print(a,c,b)
        else:
            print(a,b,c)



Measured memory_bytes: 5596
s = list(input())
n = len(s)
S = list(int(s[i]) for i in range(n))
if n %2 == 0:
  A = [0,1] * (n//2)
  B = [1,0] * (n//2)
else:
  A = [0,1] * (n//2) + [0]
  B = [1,0] * (n//2) + [1]

ansA = 0
ansB = 0
for i in range(n):
  ansA += abs(S[i]-A[i])
  ansB += abs(S[i]-B[i])
  
print(min(ansA,ansB))

Measured memory_bytes: 6936
# -*- coding: utf-8 -*-
import itertools

N = int(input())
pre_num_list = [int(i) for i in input().split()]
num_list = [[i-1, i, i+1] for i in pre_num_list]
target_list = list(itertools.product(*num_list))
counter = 0
odd_flag = 0
for item in target_list:
    even_flag = False # 偶数があったらTrueにする
    for each_num in item:
        if even_flag == False:
            if each_num % 2 == 0:
                even_flag = True
        else:
            continue
    if even_flag == True:
        counter += 1
    
print(counter)


Measured memory_bytes: 11252
#include<iostream>
#include<map>
#include<set>

using namespace std;

int main(){
    map<string,set<int> >m;
    set<string>s;
    string w;
    int p;
    while(cin>>w>>p){
        m[w].insert(p);
        s.insert(w);
    }
    set<int>::iterator it;
    set<string>::iterator st;
    for (st = s.begin(); st != s.end(); ++st){
        cout<<*st<<endl;
        it = m[*st].begin();
        if(m[*st].size()>1)
            for (; it != prev(m[*st].end(), 1); ++it)
                cout<<*it<<" ";
        cout<<*it<<endl;
    }
}

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

int main(int argc, char const *argv[])
{
    int n, k; cin >> n >> k;
    int p[1010];
    rep(i,n) cin >> p[i];
    sort(p,p+n);
    int ans = 0;
    rep(i,k) ans += p[i];
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 3604
#include<stdio.h>
#include<stdbool.h>
#define N 8
#define FREE -1
#define NOT_FREE 1

int row[N],col[N],dpos[2*N-1],dneg[2*N-1];

bool X[N][N];

void ini(){
    
int i;

  for(i=0;i<N;i++){
    row[i]=FREE;
    col[i]=FREE;
  }
  
for(i=0;i<2*N-1;i++){
  dpos[i]=FREE;
  dneg[i]=FREE;
}
}

void pB(){
int i,j;
for(i=0;i<N;i++){
  for(j=0;j<N;j++){
    if(X[i][j]){
      if(row[i]!=j)return;
    }
  }
}

  for(i=0;i<N;i++){
    for(j=0;j<N;j++){
      if(row[i]==j)printf("Q");
      else printf(".");
    }
    printf("\n");
  }
}

void recursive(int i){
  if(i==N){
    pB();
    return;
  }
  
  int j;
for(j=0;j<N;j++){
  if(NOT_FREE==col[j]||
    NOT_FREE==dpos[i+j]||
    NOT_FREE==dneg[i-j+N-1])continue;
row[i]=j;
col[j]=dpos[i+j]=dneg[i-j+N-1]=NOT_FREE;
recursive(i+1);
row[i]=col[j]=dpos[i+j]=dneg[i-j+N-1]=FREE;
}
}

int main(){
  ini();
int i,j;
  for(i=0;i<N;i++){
    for(j=0;j<N;j++)X[i][j]=false;
  }
  
int k;
scanf("%d",&k);
for(i=0;i<k;i++){
  int r,c;
  scanf("%d%d",&r,&c);
  X[r][c]=true;
}

recursive(0);

return 0;
}


Measured memory_bytes: 2652
#include <algorithm>
#include <cassert>
#include <cctype>
#include <chrono>
#define _USE_MATH_DEFINES
#include <cmath>
#include <cstdio>
#include <cstring>
#include <ctime>
#include <deque>
#include <functional>
#include <iostream>
#include <map>
#include <queue>
#include <random>
#include <set>
#include <sstream>
#include <string>
#include <tuple>
#include <vector>
using namespace std;

#define FOR(i,m,n) for(int i=(m);i<(n);++i)
#define REP(i,n) FOR(i,0,n)
#define ALL(v) (v).begin(),(v).end()

const int INF = 0x3f3f3f3f, MOD = 1000000007;
const long long LINF = 0x3f3f3f3f3f3f3f3fLL;
/*-----------------------------------------*/
// http://drken1215.hatenablog.com/entry/2018/07/27/124500
int main() {
  cin.tie(0); ios::sync_with_stdio(false);
  // freopen("input.txt", "r", stdin);

  int n, l, t; cin >> n >> l >> t;
  vector<int> x(n), w(n); REP(i, n) cin >> x[i] >> w[i];
  vector<int> coordinates(n);
  REP(i, n) {
    if (w[i] == 1) coordinates[i] = (x[i] + t) % l;
    else coordinates[i] = ((x[i] - t) % l + l) % l;
  }
  sort(ALL(coordinates));
  long long cnt = 0;
  REP(i, n) {
    if (w[i] == 1) {
      if (l - x[i] > t) continue;
      int rem = t - (l - x[i]);
      --cnt;
      cnt -= rem / l;
    } else {
      if (x[i] + 1 > t) continue;
      int rem = t - (x[i] + 1);
      ++cnt;
      cnt += rem / l;
    }
    // cout << i << ' ' << cnt << '\n';
    cnt %= n;
  }
  (cnt += n) %= n;
  vector<int> ans(n);
  int idx = 0;
  FOR(i, cnt, n) {
    ans[i] = coordinates[idx];
    ++idx;
  }
  REP(i, cnt) {
    ans[i] = coordinates[idx];
    ++idx;
  }
  REP(i, n) cout << ans[i] << '\n';
  return 0;
}


Measured memory_bytes: 2816
#include <stdio.h>
int main(){
	int a,b,x;
	scanf("%d %d",&a,&b);
	if ( ( a + b ) % 2 == 1 ) {
		x = ( a + b + 1 ) / 2;
	} else {
		x = ( a + b ) / 2;
	}
	printf("%d",x);
}

Measured memory_bytes: 128
#include<bits/stdc++.h>
using namespace std;
#define int long long
signed main(){
  int n;
  cin>>n;
  int A[n];
  for(int i=0;i<n;i++) cin>>A[i];
  int ans=0;
  bool flag=1;
  while(flag){
    flag=0;
    for(int j=n-1;j>0;j--){
      if(A[j]<A[j-1]){
	swap(A[j],A[j-1]);
	flag=1;
	ans++;
      }
    }
  }
  for(int i=0;i<n;i++){
  if(i) cout<<" ";
  cout<<A[i];
  
 }
  cout << endl;
  cout<<ans<<endl;
  return 0;
}



Measured memory_bytes: 3128
DBG = !true
n,m = gets.split.map{|z| z.to_i}
$str = gets.chomp!
$toa = Array.new(n).map{[]}
$tob = Array.new(n).map{[]}
puts "n #{n} m #{m} s #{$str}" if DBG
for i in 0...m
  x,y = gets.split.map{|z| z.to_i - 1}
  puts "x #{x} y #{y}" if DBG
  if $str[x] == 'A'
    $toa[y] << x
  else
    $tob[y] << x
  end
  if y != x
    if $str[y] == 'A'
      $toa[x] << y
    else
      $tob[x] << y
    end
  end
  puts "$toa #{$toa} $tob #{$tob}" if DBG
end
$toa.map!{|z| z.uniq}
$tob.map!{|z| z.uniq}
$bad = Array.new(n, false)
puts "setup done" if DBG

MAXD = 2000
def rem(i, d)
  return if $bad[i]
  $bad[i] = true
  proc = []
  mea = ($str[i] == 'A')
  for j in $toa[i]
    c = (mea ? $toa[j] : $tob[j])
    c.delete(i)
    proc << j if c.empty?
  end
  for j in $tob[i]
    c = (mea ? $toa[j] : $tob[j])
    c.delete(i)
    proc << j if c.empty?
  end
  if d < MAXD
    for x in proc
      rem(x, d+1)
    end
  end
end

found = true
chg = true
while chg
  chg = false
  found = false
  for i in 0...n
    next if $bad[i]
    if $toa[i].empty? || $tob[i].empty?
      chg = true if !$bad[i]
      rem(i, 0)
      puts "i #{i} $toa #{$toa} $tob #{$tob}" if DBG
    else
      found = true
    end
  end
end

print (found ? 'Yes' : 'No')


Measured memory_bytes: 68008
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
template <class T> using vec = vector<T>;
template <class T> using vvec = vector<vec<T>>;

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N;
    cin >> N;
    map<string,int> mp;
    for(int i=0;i<N;i++){
        string S;
        cin >> S;
        mp[S]++;
    }
    string J[4] = {"AC","WA","TLE","RE"};
    for(int i=0;i<4;i++){
        cout << J[i] << " x " << mp[J[i]] << "\n";
    }
}

Measured memory_bytes: 3648
# https://atcoder.jp/contests/abc047/tasks/arc063_a
# 連長圧縮すれば簡単
# 圧縮後の文字列長-1となる


# def run_length_encoding(s):
#     '''連長圧縮を行う
#     s ... iterable object e.g. list, str
#     return
#     ----------
#     s_composed,s_num,s_idx
#     それぞれ、圧縮後の文字列、その文字数、その文字が始まるidx'''
#     s_composed, s_sum = [], []
#     s_idx = [0]
#     pre = s[0]
#     cnt = 1
#     for i, ss in enumerate(s[1:], start=1):
#         if pre == ss:
#             cnt += 1
#         else:
#             s_sum.append(cnt)
#             s_composed.append(pre)
#             s_idx.append(i)
#             cnt = 1
#             pre = ss
#     s_sum.append(cnt)
#     s_composed.append(pre)
#     # assert len(s_sum) == len(s_composed)
#     return s_composed, s_sum, s_idx


def run_length_encoding(s):
    '''連長圧縮を行う
    s ... iterable object e.g. list, str
    return
    ----------
    s_composed,s_num,s_idx
    それぞれ、圧縮後の文字列、その文字数、その文字が始まるidx'''
    from itertools import groupby
    s_composed, s_sum = [], []
    s_idx = [0]
    for k, v in groupby(s):
        s_composed.append(k)
        # n = len(list(v))
        # s_sum.append(n)
        # s_idx.append(s_idx[-1] + n)

    # assert len(s_sum) == len(s_composed)
    return s_composed, s_sum, s_idx


S_composed, _, _ = run_length_encoding(input())
print(len(S_composed) - 1)


Measured memory_bytes: 77196
#include<bits/stdc++.h>
using namespace std;
int main(){
	int n;
	cin>>n;
	int a[n];
	int tot=0;
	int temp=0;
	for(int i=0;i<n;i++){
		cin>>a[i];
		tot+=a[i];
	}
	int diff=10000;
	for(int i=0;i<n;i++){
		temp+=a[i];
		if(abs(2*temp-tot)<diff){
			diff=abs(2*temp-tot);
		}
		
	}
	cout<<diff<<endl;
	return 0;
}

Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Collections;
using System.Collections.Specialized;
using System.Linq;
using System.Text;
using System.IO;
using System.Reflection;
using static System.Math;
using System.Numerics;
static class Program{
	const int mod=(int)1e9+7;
	const double eps=1e-11;
	static void Main(){
		Sc sc=new Sc();
		var n=sc.I;
		var t=sc.S;
		int ans=0;
		for(int i = 0,j=n-1;i<n;i++) {
			if(t[i]=='W'){
				while(i<j&&t[j]=='W'){
					j--;
				}
				if(i>=j){
					break;
				}
				ans++;
				j--;
			}
		}
		Console.WriteLine("{0}",ans);
	}
}
public class Sc{
	public int I{get{return int.Parse(Console.ReadLine());}}
	public long L{get{return long.Parse(Console.ReadLine());}}
	public double D{get{return double.Parse(Console.ReadLine());}}
	public string S{get{return Console.ReadLine();}}
	public int[] Ia{get{return Array.ConvertAll(Console.ReadLine().Split(),int.Parse);}}
	public long[] La{get{return Array.ConvertAll(Console.ReadLine().Split(),long.Parse);}}
	public double[] Da{get{return Array.ConvertAll(Console.ReadLine().Split(),double.Parse);}}
	public string[] Sa{get{return Console.ReadLine().Split();}}
	public object[] Oa{get{return Console.ReadLine().Split();}}
	public int[] Ia2{get{return Array.ConvertAll(("0 "+Console.ReadLine()+" 0").Split(),int.Parse);}}
	public int[] Ia3(string a,string b){return Array.ConvertAll((a+Console.ReadLine()+b).Split(),int.Parse);}
	public int[] Ia3(int a){return Array.ConvertAll((Console.ReadLine()+" "+a.ToString()).Split(),int.Parse);}
	public long[] La2{get{return Array.ConvertAll(("0 "+Console.ReadLine()+" 0").Split(),long.Parse);}}
	public long[] La3(string a,string b){return Array.ConvertAll((a+Console.ReadLine()+b).Split(),long.Parse);}
	public long[] La3(int a){return Array.ConvertAll((Console.ReadLine()+" "+a.ToString()).Split(),long.Parse);}
	public double[] Da2{get{return Array.ConvertAll(("0 "+Console.ReadLine()+" 0").Split(),double.Parse);}}
	public double[] Da3(string a,string b){return Array.ConvertAll((a+Console.ReadLine()+b).Split(),double.Parse);}
	public T[] Arr<T>(int n,Func<T> f){var a=new T[n];for(int i=0;i<n;i++){a[i]=f();}return a;}
	public T[] Arr<T>(int n,Func<int,T> f){var a=new T[n];for(int i=0;i<n;i++){a[i]=f(i);}return a;}
	public T[] Arr<T>(int n,Func<string[],T> f){var a=new T[n];for(int i=0;i<n;i++){a[i]=f(Console.ReadLine().Split());}return a;}
	public T[] Arr<T>(int n,Func<int,string[],T> f){var a=new T[n];for(int i=0;i<n;i++){a[i]=f(i,Console.ReadLine().Split());}return a;}
}

Measured memory_bytes: 28272
#include<iostream>
#include<cstdio>
#include<cstring>
#include <cstdlib>  
#include <math.h>
#include <cmath>
#include<complex>
#include<cctype>
#include<string>
#include<set>
#include<iomanip>
#include <map>
#include<algorithm>
#include <functional>
#include<vector>
#include<climits>
#include<stack>
#include<queue>
#include<bitset>
#include <deque>
#include <climits>
#include <typeinfo>
#include <utility> 
using namespace std;
using Complex = complex<double>;
using ll = long long;
template<typename T>using min_priority_queue = priority_queue<T, vector<T>, greater<T>>;
const ll inf = 1145141919810364364LL;
double PI = acos(-1.0);
#define all(x) (x).begin(),(x).end()
#define puts(x) cout << x << endl
#define rep(i,m,n) for(ll i = m;i < n;++i)
#define pb push_back
#define fore(i,a) for(auto &i:a)
#define rrep(i,m,n) for(ll i = m;i >= n;--i)


class UnionFind {
public:
	vector<int> r, p;

	UnionFind() {}
	UnionFind(int size) {
		r.resize(size, 0);
		p.resize(size, 0);
		rep(i, 0, size)makeSet(i);
	}

	void makeSet(int x) {
		p[x] = x;
		r[x] = 0;
	}

	bool same(int x, int y) {
		return findSet(x) == findSet(y);
	}

	void unite(int x, int y) {
		link(findSet(x), findSet(y));
	}

	void link(int x, int y) {
		if (r[x] > r[y]) {
			p[y] = x;
		}
		else {
			p[x] = y;
			if (x == y) {
				r[y]++;
			}
		}
	}


	int findSet(int x) {
		if (x == p[x]) {
			return x;
		}
		else {
			return p[x] = findSet(p[x]);
		}
	}
};


map<pair<int, int>, int>mp;
vector<int>E[202020],Et[202020];
int used[202020],sum[202020];
UnionFind un1 = UnionFind(202020);
UnionFind un2 = UnionFind(202020);
set<int>use;

void maketree(int now){
	used[now] = 1;
	fore(x, E[now]) {
		if (used[x] == 0 && !un2.same(now, x)) {
			un2.unite(now, x);
			Et[now].pb(x);
			Et[x].pb(now);
			maketree(x);
		}
	}
}

void dfs(int now,int p){
	
	fore(x, Et[now]) {
		if (x != p) {
			dfs(x,now);
			if (sum[x] == 1) {
				sum[now] ^= 1;
				sum[x] = 0;
				use.insert(mp[{x,now}]);
			}
		}
	}
}

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

	int N,M;
	cin >> N >> M;
	vector<pair<ll, ll>>p(N), c(M);
	vector<ll>a(N);
	for (int i = 0; i < N; i++) { cin >> p[i].first >> p[i].second; a[i] = p[i].first; }
	sort(all(p));
	sort(all(a));

	for (int i = 0; i < M; i++) {
		cin >> c[i].first >> c[i].second;
		ll l = c[i].first;
		ll r = c[i].second;
		if (l > p.back().first)continue;
		int idx1 = lower_bound(all(a),l)-a.begin();
		int idx2;
		if (r >= p.back().first)idx2 = N-1;
		else { idx2 = upper_bound(all(a), r) - a.begin(); idx2--; }
		if (idx1 > idx2)continue;
		idx2++;
		mp[{idx1, idx2}] = i + 1;
		mp[{idx2, idx1}] = i + 1;
		E[idx1].pb(idx2);
		E[idx2].pb(idx1);
		un1.unite(idx1,idx2);
	}
	sum[0] = p[0].second;
	for (int i = 1; i < N; i++)sum[i] = p[i].second^p[i-1].second;

	for (int i = 0; i < N; i++) {
		if (used[i])continue;
		maketree(i);
		if (un1.same(i, N)) {
			dfs(N,-1);
		}
		else {
			dfs(i,-1);
			if (sum[i] == 1) { puts(-1); return 0; }
		}
	}


	puts(use.size());
	fore(x, use)cout << x << " ";
	cout << endl;

	return 0;
}


Measured memory_bytes: 62336
/*
    Mbak Sana Dong
    Mbak Chaeyoung Dong
*/
#include<bits/stdc++.h>
#define ll long long int
using namespace std;
ll dp[200200];
int main()
{
    int n,i,j,k,x,y,ans,temp,curr,m;
    int tc;
    ll chaeng = 0;
    int p;
    cin >> n >> p;
    string s;
    cin >> s;
    s = " " + s;
    if(p == 2 || p == 5)
    {
        for(i=1;i<=n;i++)
        {
            curr = s[i] - '0';
            if(curr%p == 0) chaeng += i;
        }
    }
    else
    {
        map<ll,int> mp;
        ll now = 0;
        ll kali = 1;
        mp[0] = 1;
        for(i=n;i>0;i--)
        {
            curr = s[i] - '0';
            now = (now + curr*kali) % p;
            chaeng += mp[now];
            mp[now]++;
            kali *= 10;
            kali %= p;
        }
    }
    cout << chaeng << endl;
    return 0;
}


Measured memory_bytes: 1088
#include<iostream>
#include<algorithm>
#include<vector>
#include<functional>
#include<string>
#include<cmath>
#include<map>
#include<set>
#include<queue>
#include<stack>
#include<cstdio>
#include<numeric>
using namespace std;
using ll = long long;
int main(){
  int n;
  cin >> n;
  double ans = 3.14159;
  ans *= n * 2;
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 3788
#include <iostream>
#include <cmath>
#define MAX_NUMBER 1001

using namespace std;

int main () {
  // 最长公共子序列
  int n;
  string x, y;
  int lcs, c[MAX_NUMBER][MAX_NUMBER];

  cin >> n;

  for (int k = 0; k < n; k++) {
    cin >> x;
    cin >> y;

    x = " " + x;
    y = " " + y;
    lcs = 0;
    for (int i = 0; i < MAX_NUMBER; i++)
      for (int j = 0; j < MAX_NUMBER; j++)
        c[i][j] = 0;
    
    for (int i = 1; i < x.length(); i++) {
      for (int j = 1; j < y.length(); j++) {
        if (x[i] == y[j])
          c[i][j] = c[i - 1][j - 1] + 1;
        else
          c[i][j] = max(c[i - 1][j], c[i][j - 1]);
      }
    }

    cout << c[x.length() - 1][y.length() - 1] << endl;
  }

  return 0;
}


Measured memory_bytes: 7124
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
const ll mod = 1e9+7;
int main(){
    ll n;
    string s;
    cin >> n >> s;
    vector<ll> a(26);
    ll i,j;
    for(i=0;i<n;i++){
        a.at((int)(s.at(i)-'a'))++;
    }
    ll ans = 1;
    for(i=0;i<26;i++){
        ans=ans*(a.at(i)+1)%mod;
    }
    cout << ans-1 << endl;
    return 0;
}

Measured memory_bytes: 512
from collections import Counter, defaultdict

N = int(input())

# 素数のリスト
def createPrimeList(N, isTable=True):
    isPrime = [True] * (N + 1)
    isPrime[0] = False
    isPrime[1] = False
    for i in range(2, N):
        if not isPrime[i]:
            continue
        for p in range(i * 2, N, i):
            isPrime[p] = False
    return isPrime if isTable else [i for i in range(2, N) if isPrime[i]]

# 素因数分解(複数回)
primeList = createPrimeList(100, False)
def primeFactorization(N):
    primes = Counter()
    for p in primeList:
        while N % p == 0:
            N //= p
            primes[p] += 1
    return primes
primes = Counter()
for i in range(1, N + 1):
    primes += primeFactorization(i)

cnt = defaultdict(int)
for c in primes.values():
    c += 1
    for d in (3, 5, 15, 25, 75):
        if c >= d:
            cnt[d] += 1

ans = 0
ans += cnt[5] * (cnt[5] - 1) * (cnt[3] - 2) // 2
ans += cnt[25] * (cnt[3] - 1)
ans += cnt[15] * (cnt[5] - 1)
ans += cnt[75]
print(ans)


Measured memory_bytes: 3316