akhauriyash/Code-Regression huggingface dataset:
#include <cstdio>
#include <algorithm>
#include <iostream>
#include <string>

using namespace std;

typedef long long LL;

const int P = 1e9 + 7, N = 200005;

int fact[N], invf[N];

int C(int n, int m) {
	return (LL)fact[n] * invf[m] % P * invf[n - m] % P;
}

int pow_mod(int a, int b) {
	int res = 1;
	while (b) {
		if (b & 1) res = (LL)res * a % P;
		a = (LL)a * a % P;
		b >>= 1;
	}
	return res;
}

int main() {
	fact[0] = fact[1] = 1;
	for (int i = 2; i < N; ++i) {
		fact[i] = (LL)fact[i - 1] * i % P;
	}
	for (int i = 0; i < N; ++i) {
		invf[i] = pow_mod(fact[i], P - 2);
	}
	int h, w, a, b;
	scanf("%d%d%d%d", &h, &w, &a, &b);
	int ans = C(h + w - 2, h - 1);
	int len = h + w - 2;
	for (int i = 0; i < b; ++i) {
		ans = (ans + P - (LL)C(h - a - 1 + i, i) * C(len - (h - a - 1 + i) - 1, a - 1) % P) % P;
	}
	printf("%d\n", ans);
	return 0;
}



Measured memory_bytes: 1792
#include<cstdio>
#include<queue>
#include<algorithm>
#include<string.h>
#include<math.h>
#include<set>
#include<stack>
#include<queue>
#include<map>
#include<iostream>
using namespace std;
int  main(){
	long long n,a,b;
	scanf("%lld%lld%lld",&n,&a,&b);
	long long ans=0,t=n/(a+b),t1=n-t*(a+b);
	ans=t*a;
	ans+=min(a,t1);
	printf("%lld\n",ans);
}




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

const int MAX_ELTS = 100;
const int MAX_POIDS = 100*1000;

struct item
{
	int poids;
	long long int valeur;

	bool operator < ( const item &autre) const
	{
		return ( poids < autre.poids );
	}
};

long long int maxVal[MAX_POIDS][MAX_ELTS];
item elements[MAX_ELTS];
int nbElts, poidsMax;

long long int maxRemplissage(int pos, int W)
{
	if ( maxVal[W][pos] != -1)
		return maxVal[W][pos];
	if ( W == 0 || pos == nbElts)
		return 0;
	maxVal[W][pos] = maxRemplissage(pos+1, W);
	if (elements[pos].poids <= W) 
		maxVal[W][pos] = max(maxVal[W][pos], elements[pos].valeur + maxRemplissage(pos+1, W-elements[pos].poids));
	return maxVal[W][pos];
}

int main()
{
	scanf("%d %d", &nbElts, &poidsMax);
	for (int j=0; j<= poidsMax; j++)
	{
		maxVal[j][nbElts] = 0;
		for (int i=0; i<nbElts; i++)
			maxVal[j][i] = -1;
	}

	for (int i=0; i<nbElts; i++)
		scanf("%d %lld", &elements[i].poids, &elements[i].valeur);
	sort(elements, elements + nbElts);
	printf("%lld\n", maxRemplissage(0, poidsMax));
}

Measured memory_bytes: 78336
import java.util.*;
class Main {
	public static void main (String[] args) throws java.lang.Exception {
		Scanner sc = new Scanner(System.in);
		while(true) {
			int a = sc.nextInt();
			String d = sc.next();
			int b = sc.nextInt();
			if(d.equals("?")) break;
			if(d.equals("+")) System.out.println(a + b);
			if(d.equals("-")) System.out.println(a - b);
			if(d.equals("*")) System.out.println(a * b);
			if(d.equals("/")) System.out.println(a / b);
		}
	}
}


Measured memory_bytes: 26300
#include<bits/stdc++.h>
using namespace std;
#define rg register
#define LL long long
#define __space putchar(' ')
#define __endl putchar('\n')
template <typename qwq> inline void read(qwq &x)
{
	x = 0;
	rg int f = 1;
	rg char c = getchar();
	while (c < '0' || c > '9')
	{
		if (c == '-') f = -1;
		c = getchar();
	}
	while (c >= '0' && c <= '9')
	{
		x = (x << 1) + (x << 3) + (c ^ 48);
		c = getchar();
	}
	x *= f;
}
template <typename qaq> inline void print(qaq x)
{
	if (x < 0)
	{
		putchar('-');
		x = -x;
	}
	if (x > 9) print(x / 10);
	putchar(x % 10 + '0');	
}
const int maxn = 2333;
int n, m, a, b, tmpb, tmpa, flag;
int Map[maxn][maxn];
int col[maxn];
int main()
{
	read(n), 
	read(m), 
	read(a), 
	read(b);
	tmpb = b, 
	tmpa = a;
	begin:
	for (rg int i = 1; i <= n; ++i)
	{
		rg int tot = 0;
		for (rg int j = 1; j <= m; ++j)
		{
			if (col[j] < b) Map[i][j] = 1, ++tot, ++col[j];
			if (tot == a) break; 
		}
		if (tot != a && tot != m - a)
		{
			++flag;
			break;
		}
		if (i == n)
		{
			rg bool isOk = true;
			for (rg int j = 1; j <= m; ++j)
			{
				if (col[j] != b && col[j] != n - b)
				{
					isOk = false;
					++flag;
					break;
				}
			}
			if (isOk) flag = 0;
		}
	}
	if (flag)
	{
		if (flag == 1) b = n - tmpb, a = tmpa;
		if (flag == 2) b = tmpb, a = m - tmpa;
		if (flag == 3) b = n - tmpb, a = m - tmpa;
		if (flag == 4)
		{
			print(-1);
			return 0;
		}
		for (rg int i = 1; i <= n; ++i)
		{
			for (rg int j = 1; j <= m; ++j)
			{
				col[j] = 0;
				Map[i][j] = 0;
			}
		}
		goto begin;
	}
	for (rg int i = 1; i <= n; ++i)
	{
		for (rg int j = 1; j <= m; ++j)
		{
			print(Map[i][j]);
		}
		__endl;
	}
	return 0;
}

Measured memory_bytes: 11136
S = input()
A = int(S[0:2])
B = int(S[2:4])
Ayy = 0
Amm = 0
Byy = 0
Bmm = 0
if A == 0:
    Ayy = 1
elif A <= 12:
    Ayy = 1
    Amm = 1
else:
    Ayy = 1

if B == 0:
    Byy = 1
elif B <= 12:
    Byy = 1
    Bmm = 1
else:
    Byy = 1

if Amm:
    if Bmm:
        print('AMBIGUOUS')
    elif Byy:
        print('MMYY')
    else:
        print('NA')
elif Ayy:
    if Bmm:
        print('YYMM')
    else:
        print('NA')
else:
    print('NA')

Measured memory_bytes: 3064
from collections import*
from heapq import*
n,*a=map(int,open(0).read().split())
q=[-t for t in Counter(a).values()]
heapify(q)
while q[0]<-1:
    p=heappop(q)
    if p<-2:
        heappush(q,p+2)
    else:
        heappush(q,p+1)
        r=heappop(q)
        if r<-1:
            heappush(q,r+1)
print(len(q))

Measured memory_bytes: 17716
N = int(input())
nums = [int(i) for i in input().split(' ')]

count = 0
m = 0
target = -1
for i in range(N):
    if nums[i] < 0:
        count += 1
    if abs(nums[i]) < m or target == -1:
        target = i
        m = abs(nums[i])
pos = [abs(i) for i in nums]
if count % 2 != 0:
    pos[target] = -abs(pos[target])

print(sum(pos))


Measured memory_bytes: 14412
#![allow(non_snake_case, unused_imports)]

// Input
macro_rules! input { (source = $s:expr, $($r:tt)*) => { let mut iter = $s.split_whitespace(); let mut next = || { iter.next().unwrap() }; input_inner!{next, $($r)*} }; ($($r:tt)*) => { let stdin = std::io::stdin(); let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock())); let mut next = move || -> String{ bytes.by_ref().map(|r|r.unwrap() as char).skip_while(|c|c.is_whitespace()).take_while(|c|!c.is_whitespace()).collect() }; input_inner!{next, $($r)*} }; }
macro_rules! input_inner { ($next:expr) => {}; ($next:expr, ) => {}; ($next:expr, $var:ident : $t:tt $($r:tt)*) => { let $var = read_value!($next, $t); input_inner!{$next $($r)*} }; ($next:expr, mut $var:ident : $t:tt $($r:tt)*) => { let mut $var = read_value!($next, $t); input_inner!{$next $($r)*} }; }
macro_rules! read_value { ($next:expr, ( $($t:tt),* )) => { ( $(read_value!($next, $t)),* ) }; ($next:expr, [ $t:tt ; $len:expr ]) => { (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>() }; ($next:expr, [ $t:tt ]) => { { let len = read_value!($next, usize); (0..len).map(|_| read_value!($next, $t)).collect::<Vec<_>>() } }; ($next:expr, chars) => { read_value!($next, String).chars().collect::<Vec<char>>() }; ($next:expr, bytes) => { read_value!($next, String).into_bytes() }; ($next:expr, usize1) => { read_value!($next, usize) - 1 }; ($next:expr, $t:ty) => { $next().parse::<$t>().expect("Parse error") }; }

// Module
use std::cmp::{min,max};
use std::collections::{HashSet,HashMap,BTreeMap,VecDeque};

// Functions

// Main
fn main(){
    input!{
        S: chars,
    }
    let mut ans = "Yes";
    for i in 0..S.len(){
        if i%2==0{
            if S[i]=='L'{
                ans = "No";
            }
        }else{
            if S[i]=='R'{
                ans = "No";
            }
        }
    }
    println!("{}", ans);
}


Measured memory_bytes: 4352
#include <stdio.h>
#include <algorithm>
#include <assert.h>
#include <bitset>
#include <cmath>
#include <complex>
#include <deque>
#include <functional>
#include <iostream>
#include <limits.h>
#include <map>
#include <math.h>
#include <queue>
#include <set>
#include <stdlib.h>
#include <string.h>
#include <string>
#include <time.h>
#include <unordered_map>
#include <unordered_set>
#include <vector>
#include <chrono>
#include <random>
#include <time.h>
#include <cstdio>
#include <list>
#define ll long long
#define rep2(i,a,b) for(ll i=a;i<=b;i++)
#define rep(i,n) for(ll i=0;i<n;i++)
#define rep3(i,a,b) for(ll i=a;i>=b;i--)
#define REP(e,v) for(auto e:v)
#define pii pair<int,int>
#define pll pair<ll,ll>
#define tii tuple<int,int,int>
#define pq priority_queue<int>
#define pqg priority_queue<int,vector<int>,greater<int>>
#define pb push_back
#define edge(v,a,b) v[a].pb(b);v[b].pb(a);
#define vec vector<int>
#define vecll vector<ll>
#define vecstr vector<string>
#define vecch vector<char>
#define vecpii vector<pii>
#define bs binary_search
#define All(c) (c).begin(),(c).end()
using namespace std;
int in() {int x;scanf("%d",&x);return x;}
string strin(){string s;cin>>s;return s;}
char chin(){char c;cin>>c;return c;}
ll lin() {ll x;scanf("%lld",&x);return x;}


int main(){
    int n=in(),k=in();
    string s=strin();
    vec a(n),b(n+2,0);
    rep(i,n)a[i]=s.at(i)=='0'?0:1;
    int index=0;
    b[0]=s.at(0)=='1'?1:-1;
    rep2(i,1,n-1){
        if(a[i]==1&&b[index]>0)b[index]++;
        else if(a[i]==0&&b[index]<0)b[index]--;
        else if(a[i]==1&&b[index]<0)b[++index]=1;
        else if(a[i]==0&&b[index]>0)b[++index]=-1;
    }
    int cnt0=0;
    rep(i,b.size()){
        if(b[i]<0)cnt0++;

    }
    if(k>=cnt0){
        cout<<n<<endl;
        return 0;
    }
    ll ans=0;
    vecll c(n+1);
    c[0]=0;
    rep(i,n){
        c[i+1]=c[i]+abs(b[i]);
    }
    int p=b[0]>0?1:2;
    for(int i=p;i+2*k<n+1;i+=2){
        ans=max(ans,c[i+2*k]-c[i-1]);
    }
    ans=max(ans,c[2*k]);
    cout<<ans<<endl;
}

Measured memory_bytes: 2048
n,k,s=map(int,input().split())
if s==1:print(*(([1]*k)+([2]*(n-k))));exit()
if k==n:print(*[s]*n);exit()
if s%2==0:
  ans=[s//2]*(k+1)
  if s<10**8:ans+=(n-len(ans))*[10**9]
  else:ans+=(n-len(ans))*[1]
else:
  ans=[]
  for i in range(k+1):
    ans.append(s//2)
    if i%2==0:ans[-1]+=1
  if s<10**8:ans+=(n-len(ans))*[10**9]
  else:ans+=(n-len(ans))*[1]
print(*ans)

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

int main(){
  int n;
  cin >> n;
  vector<int> a(n+1);
  for(int i=0; i<n; i++) cin >> a[i];
  sort(a.begin(), a.end());
  bool f=true;
  for(int i=0; i<n; i++) if(a[i]==a[i+1]) f=false;
  if (f) cout << "YES" << endl;
  else cout << "NO" << endl;
    
}

Measured memory_bytes: 4008
#include<bits/stdc++.h>
#define int long long int
#define mod 1000000007
#define inf 1e18
#define fo(i,y,n,inc)	for(int i=y;i<n+y;i+=inc)
#define cin(t) int t;cin>>t
#define w(t) while(t--)
#define nl cout<<endl;
#define pii pair<int,int>
#define mp make_pair
#define pb push_back
#define ft(i) (i&(-1*i))
#define arrIn(arr,size)		for(int i=0;i<size;i++){cin>>arr[i];}
#define arrOut(arr,size,seperater)	for(int i=0;i<size;i++){cout<<arr[i]<<seperater;}
using namespace std;

int max(int a, int b) {
	if (a > b)
		return a;
	return b;
}

int min(int a, int b) {
	if (a < b)
		return a;
	return b;
}

int powmd(int a, int b) {
	if (b == 1)	return a;
	if (b == 0)	return 1;

	int half = powmd(a, b / 2);
	int ans = half * half;
	ans %= mod;
	if (b & 1) {
		ans *= a;
	}
	ans %= mod;
	return ans;
}

void fastIO() {
	ios_base::sync_with_stdio(false);
	cin.tie(NULL); cout.tie(NULL);
}

struct flower {
	int height, beauty;
};

int solve(flower arr[], int n) {

	vector<int> dp(n, 0);
	dp[0] = arr[0].beauty;
	map<int, int> m;
	m[arr[0].height] = dp[0];
	int ans = dp[0];
	for (int i = 1; i < n; i++) {
		dp[i] = arr[i].beauty;
		auto it = m.upper_bound(arr[i].height);
		if (it != m.begin()) {
			it--;
			dp[i] += it->second;
		}
		m[arr[i].height] = dp[i];

		it = m.upper_bound(arr[i].height);
		while (it != m.end() and it->second <= dp[i]) {
			auto temp = it;
			temp++;
			m.erase(it);
			it = temp;
		}
		ans = max(ans, dp[i]);
	}
	return ans;
}


int32_t main() {

	fastIO();

	int n;
	cin >> n;

	flower arr[n];
	for (int i = 0; i < n; i++) {
		cin >> arr[i].height;
	}
	for (int i = 0; i < n; i++) {
		cin >> arr[i].beauty;
	}

	cout << solve(arr, n) << endl;

	return 0;
}

// cout << "Case #" << i << ": " << answer << endl;

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

int main(){
    int N;
    cin >> N;
    int a[N];
    for(int i = 0; i < N; ++i){
        cin >> a[i];
    }
       int flag = 0;
    int ans = 1;
    int t = 0;
    for(int i = 0; i < N; ++i){
       
        if(a[t] == 2){
            flag = 1;
            break;
        }
        t = a[t] - 1; 
        ans++;
    }

    if(!flag)ans = -1;

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


Measured memory_bytes: 640
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<string>
#include<ctime>
#include<set>
#include<map>
#include<stack>
#include<queue>
#include<vector>
#include<iostream>
#include<algorithm>
using namespace std;

struct node {
	int a, b;
}S[1000];

bool cmp(node x, node y) {
	if (x.b > y.b) {
		return true;
	}
	else {
		return false;
	}
}

int main() {
	int a[10], b[10];
	while (cin >> S[0].a) {
		int sum = 0;
		for (int i = 1; i < 5; i++) {
			cin >> S[i].a;
		}
		for (int i = 0; i < 5; i++) {
			if (S[i].a % 10 == 0) {
				S[i].b = 10;
			}
			else {
				S[i].b = S[i].a % 10;
			}
		}
		sort(S, S + 5, cmp);
		for (int i = 0; i < 4; i++) {
			if (S[i].b != 0) {
				sum = sum + S[i].a + (10 - S[i].b);
			}
			else {
				sum = sum + S[i].a;
			}
		}
		sum += S[4].a;
		cout << sum << endl;
	}
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main{
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);        
        while(true){            
            int m = sc.nextInt();
            int f = sc.nextInt();
            int r = sc.nextInt();
            if(m == -1 && f == -1 && r == -1) break;

            if(m == -1 || f == -1){
                System.out.println("F");
            }else if(m + f >= 80){
                System.out.println("A");
            }else if(m + f < 80 && m + f >= 65){
                System.out.println("B");
            }else if(m + f < 65 && m + f >= 50){
                System.out.println("C");      
            }else if(m + f < 50 && m + f >= 30 && r >= 50) {
                System.out.println("C");               
            }else if(m + f < 50 && m + f >= 30 && r < 50){
                System.out.println("D");
            }else if(m + f < 30) {
                System.out.println("F");
            }
            
        }
        sc.close();
    }
}


Measured memory_bytes: 26288
import java.util.Scanner;

public class Main {
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    int h = sc.nextInt(),w = sc.nextInt();
    int[][] res = new int[h][w];
    int ctn;
    String buff;

    for(int i=0;i<h;i++){
      ctn = -1;
      buff = sc.next();
      for(int j=0;j<w;j++){
        switch(buff.charAt(j)){
          case 'c':
            ctn = 0;
            res[i][j] = ctn++;
            break;
          case '.':
            res[i][j] = ctn;
            if(ctn != -1) ctn++;
            break;
        }
      }
    }

    for(int i = 0;i<h;i++){
      for(int j = 0;j<w;j++){
        System.out.print(res[i][j]);
        if(j != w - 1) System.out.print(" ");
      }
      System.out.println();
    }
  }
}

Measured memory_bytes: 36548
n=int(input())
a=list(map(int,input().split()))
b=list(map(int,input().split()))
c=list(map(int,input().split()))
ans=sum(b)
for i in range(n-1):
    if a[i+1]-a[i]==1:
        ans+=c[a[i]-1]
print(ans)

Measured memory_bytes: 9132
#include <bits/stdc++.h>
using namespace std;
#define REP(i, a, b) for (int i = (int)(a); i < (int)(b); i++)
#define rep(i, n) REP(i, 0, n)
#define rrep(i, n) for (int i = (int)(n-1); i >= 0; i--)
#define sz(x) int(x.size())
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define INF 2e9
#define LINF 1e18
template<class T> inline bool chmax(T &a, const T &b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T &a, const T &b) { if (a > b) { a = b; return 1; } return 0; }
typedef long long ll;
typedef pair<int, int> P;

int main() {
    string s; cin >> s;
    string ans = "";
    rep(i,3) {
        if (s[i] == '1') ans.push_back('9');
        else ans.push_back('1');
    }
    rep(i,3) {
        cout << ans[i];
    }
    cout << endl;
}

Measured memory_bytes: 256
#define rep(i, m, n) for(int i = m; i < n; i++)
#define repM(i, m, n) for(int i = n-1; i>=m; i--)
#define all(x) (x).begin(),(x).end()
typedef long long ll; using namespace std;
//typedef pair<int,int> pii;
// d = distance(lower_bound(all(x)), upper_bound(all(x)));
int INF = 1e9;
ll m = 1e9+7;
#include <iostream>
#include <vector>
#include <cmath>
#include <algorithm>
#include <queue>

int main(){
  ll N, K; cin >> N >> K; int g[2001]; fill(g, g+2001, 0);
  int a[N]; rep(i, 0, N) {cin >> a[i]; g[a[i]]++;}
  if (N==1) {cout << 0 << endl; return 0;}
  int g2[2001]; g2[0] = 0; g2[1] = 0; int b=0;
  rep(i, 0, N-1) {
    rep(j, i+1, N) {
      b += a[i] > a[j];
    }
  }
  rep(i, 2, 2001) g2[i] = g2[i-1] + g[i-1]; ll an=0, kk = (ll)K*(K-1)/2 % m;
  rep(i, 1, 2001) {
    an = (an + kk * g[i] * g2[i]) % m;
    //cout << "(" << kk * g[i] * g2[i] << ")";
    //cout << "(" << g[i] << ","<<g2[i]<<")";
  }
  //cout << an << endl;
  an = (an + b * K) % m;
  cout << an << endl;
}

Measured memory_bytes: 256
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for (int i = 0;i < (n);i++)
using ll = long long;
const ll MOD=1000000007;



int main() 
{
  string s,t; cin>>s>>t;
  sort(s.begin(),s.end());
  sort(t.rbegin(),t.rend());
  if(s<t) {cout<<"Yes"<<endl; return 0;}
  cout<<"No"<<endl;
  return 0;
}

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

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

  int ans1 = 0, ans2 = 0;
  for (int i = 0; i < S.size(); ++i) {
    if (S[i] == ('0' + i % 2)) ans1++;
    else ans2++;
  }

  cout << min(ans1, ans2) << endl;
}


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

#define ll long long
#define endl "\n"
#define FAST ios_base::sync_with_stdio(false); cin.tie(NULL);
#define M 1000000007

void solve()
{	
	ll n,k,ans=0;
	cin>>n>>k;
	ll cnt[1001]={0};
	for(ll i=0;i<k;i++)
	{
		ll d;
		cin>>d;
		for(ll j=0;j<d;j++)
		{
			ll x;
			cin>>x;
			cnt[x]=1;
		}
	}
	for(ll i=1;i<=n;i++)
	{
		if(cnt[i]==0)
		{
			ans++;
		}
	}
	cout<<ans;
}

int main()
{
	FAST
	ll t=1;
	//cin>>t;
	for(ll i=0;i<t;i++) solve();
	return 0;
}


Measured memory_bytes: 3644
def execute() :
    n = int(input())
    p = [[int(i) for i in input().split()] for i in range(n)]
    
    for posX in range(101) :
        for posY in range(101) :
            needH = -1
    
            for i in range(n) :
                x, y, h = p[i]
                if h > 0 :
                    tmp = h + abs(posY-y) + abs(posX-x)
                    if needH == -1 :
                        needH = tmp
                    else :
                        if needH != tmp :
                            needH = -2
                            break
            if needH == -2 : 
                continue
    
            for i in range(n) :
                x, y, h = p[i]
                if h == 0 :
                    dist =  abs(posY-y) + abs(posX - x)
                    if needH > dist :
                        needH = -2
                        break
            if needH == -2 : 
                continue
            
            return (posX, posY, needH)

result = execute()     
print(result[0], result[1], result[2])


Measured memory_bytes: 3064
#include<bits/stdc++.h>
using namespace std;
int main()
{
	int n;
	cin>>n;
	long long sum=0;
	if(n>=500){
	sum+=((n/500)*1000);
	n-=((n/500)*500);
	}
	sum+=(n-(n%5));
	cout<<sum;
}

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

int main() {
  int N, L, R, Sam=0;
  
   cin >> N;
  
   for (int i = 0; i < N; i++) {
  cin >>L >>R;
  Sam += R-L+1; 
  }
  cout << Sam << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int n;
void dfs(string s,char now)
{
//	cout <<s<<" "<<now<<endl;
	if(s.size()==n)
	{
		cout <<s<<endl;
		return ;
	}
	for(char i='a';i<now;i++)
	dfs(s+i,now);
	dfs(s+now,now+1);
}
int main()
{
	cin >>n;
	dfs("",'a');
	return 0;
} 

Measured memory_bytes: 1536
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i,val) for(int i = 0; i < val; i++)

const long long INF = 1LL << 60;
const ll MOD = ll(1e9)+7;

bool has_key(unordered_map<string, ll> &m, string s){
    if (m.find(s) == m.end()){
        return false;
    }
    else{
        return true;
    }
}


bool vector_find(std::vector<ll> vec, ll number) {
  auto itr = std::find(vec.begin(), vec.end(), number);
  size_t index = std::distance( vec.begin(), itr );
  if (index != vec.size()) {
    return true;
  }
  else {
    return false;
  }
}


void recursive_comb(int *indexes, int s, int rest, std::function<void(int *)> f) {
  if (rest == 0) {
    f(indexes);
  } else {
    if (s < 0) return;
    recursive_comb(indexes, s - 1, rest, f);
    indexes[rest - 1] = s;
    recursive_comb(indexes, s - 1, rest - 1, f);
  }
}


void foreach_comb(int n, int k, std::function<void(int *)> f) {
  int indexes[k];
  recursive_comb(indexes, n - 1, k, f);
}

bool compare_by_b(pair<ll, ll> a, pair<ll, ll> b) {
    if(a.second != b.second){
        return a.second < b.second;
    }else{
        return a.first < b.first;
    }
}

ll count_black(vector<vector<string>> C) {

  ll num = 0;
  for (ll i = 0; i < C.size(); i++) {
    for (ll j = 0; j < C.at(i).size(); j++) {
      if (C.at(i).at(j) == "#") num++;
    }
    
  }

  return num;
  
}

vector<vector<string>> paint(vector<vector<string>> C, vector<ll> x, vector<ll> y) {

  vector<vector<string>> C_painted = C;

  for (ll i = 0; i < x.size(); i++) {
    if(x.at(i) == 1) {
      for (ll j = 0; j < C_painted.size(); j++) {
        C_painted.at(j).at(i) = "r";
      }
    }
  }

  for (ll i = 0; i < y.size(); i++) {
    if(y.at(i) == 1) {
      for (ll j = 0; j < C_painted.at(0).size(); j++) {
        C_painted.at(i).at(j) = "r";
      }
    }
  }

  return C_painted;
  
}

vector<vector<ll>> vec_x;

void sublistx(vector<ll> tmp, ll n) {
    if (n == 0) {
      vec_x.push_back(tmp);
    }
    if (n > 0) {
      vector<ll> tmp0 = tmp;
      vector<ll> tmp1 = tmp;
      tmp0.push_back(0);
      tmp1.push_back(1);
      sublistx(tmp0, n - 1);
      sublistx(tmp1, n - 1);
    }
}

vector<vector<ll>> vec_y;

void sublisty(vector<ll> tmp, ll n) {
    if (n == 0) {
      vec_y.push_back(tmp);
    }
    if (n > 0) {
      vector<ll> tmp0 = tmp;
      vector<ll> tmp1 = tmp;
      tmp0.push_back(0);
      tmp1.push_back(1);
      sublisty(tmp0, n - 1);
      sublisty(tmp1, n - 1);
    }
}


int main() {

  ll H, W, K;

  cin >> H >> W >> K;

  vector<vector<string>> C(H, vector<string>(W));

  for (ll i = 0; i < H; i++) {
    string str_tmp;
    cin >> str_tmp;

    for (ll j = 0; j < str_tmp.size(); j++) {
      C.at(i).at(j) = str_tmp.at(j);
    }
  }


  ll ans = 0;

  vector<ll> tmp;

  sublisty(tmp, H);
  sublistx(tmp, W);

  for (ll i = 0; i < vec_x.size();i++) {
    
    for (ll j = 0; j < vec_y.size(); j++) {
      vector<vector<string>> tmp = paint(C, vec_x.at(i), vec_y.at(j));

      
      if(count_black(tmp) == K) ans++;

    }
  }
  
  
  
  

 
  


  cout << ans << endl;

  return 0;
}

Measured memory_bytes: 3660
#include<bits/stdc++.h>
#define rep(i,n) for(ll i=0;i<n;++i)
#define rrep(i,n) for(int i=n-1;i>=0;--i)
#define yesno(flg) if(flg){cout<<"YES"<<endl;}else{cout<<"NO"<<endl;}
#define MAX_N 1002
#define i197 1000000007
#define Vi vector<int>
#define Vl vector<long long>
#define pb(a) push_back(a)

using namespace std;

typedef long long ll;
typedef pair<ll,ll> P1;
typedef pair<int,int> Pi;
typedef pair<double,Pi> Pdi;
typedef pair<ll,int>Pli;
typedef pair<P1,ll> P2;
const ll INF=10000000000000000001;
int dy[]={0, 0, 1, -1};
int dx[]={1, -1, 0, 0};
struct Road{double cost;int a,b;};
struct edge{int to,cost;};
struct pos{
	int x,y,cost;
};

int main() {

	ll a,b,v,w,t;
	cin>>a>>v;
	cin>>b>>w;
	cin>>t;

	if(a>b){
		if(a-v*t<=b-w*t)cout<<"YES"<<endl;
		else cout<<"NO"<<endl;
	}else{
		if(a+v*t>=b+w*t)cout<<"YES"<<endl;
		else cout<<"NO"<<endl;
	}

	return 0;
}


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

using namespace std;

#define EACH(i,a) for (auto& i : a)
#define FOR(i,a,b) for(int i=(int)a;i<(int)b;++i)
#define RFOR(i,a,b) for(int i=(int)b-1;i>=(int)a;--i)
#define REP(i,n) FOR(i,0,n)
#define RREP(i,n) RFOR(i,0,n)
#define ALL(a) (a).begin(),(a).end()
#define debug(x) cerr << #x << ":" << x << endl;
#define OK(ok) cout << (ok ? "AC" : "WA") << endl;
typedef long long ll;

void CINT(){}
template <class Head,class... Tail>
void CINT(Head&& head,Tail&&... tail) {
  cin >> head; CINT(move(tail)...);
}
#define CIN(...) int __VA_ARGS__;CINT(__VA_ARGS__)
#define LCIN(...) ll __VA_ARGS__;CINT(__VA_ARGS__)
#define SCIN(...) string __VA_ARGS__;CINT(__VA_ARGS__)

const int INF = 1e9 + 1;
const int MOD = 1e9 + 7;
const int MAX_N = 1e5 + 1;

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

  SCIN(S);
  bool ok = true;
  ok &= (S[0] == 'A');

  int cnt = 0;
  FOR(i, 2,  S.size() - 1) {
    if ('C' == S[i]) cnt++;
  }
  ok &= (cnt == 1);
  
  REP(i, S.size()) {
    if (S[i] == 'A' || S[i] == 'C') continue;
    ok &= (S[i] >= 'a' && S[i] <= 'z');
  }

  OK(ok);
  
  return 0;
}



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

int main(void){
  int l;
  int r;
  scanf("%d", &l);
  scanf("%d", &r);
  int p = l % 2019;
  int q = r % 2019;
  int min = 2147483647;
  int i = 0;
  int j = 0;
  int ans = 0;
  for(i=l;i<r;i++){
    //printf("\n%d", i);
    for(j=i+1;j<=r;j++){
      //printf("\n%d", i);
      if(i%2019==0){
        printf("%d", 0);
        return 0;
      }else if(j%2019==0){
        printf("%d", 0);
        return 0;
      }
      ans = ((i % 2019) * (j % 2019)) % 2019;
      if(ans < min){
        min = ans;
      }
    }
  }
  printf("\n%d", min);
}

Measured memory_bytes: 128
n, m = gets.split.map(&:to_i)
ab = n.times.map {gets.split.map(&:to_i)}.sort_by{|e| e[0]}

@heap = Array.new(n+1, 0)
@l = 0

def enque(x)
    @l += 1
    @heap[@l] = x
    i = @l
    while i > 1 && @heap[i] > @heap[i/2]
        @heap[i], @heap[i/2] = @heap[i/2], @heap[i]
        i /= 2
    end
end

def deque
    if @l == 0
        0
    elsif @l == 1
        @l = 0
        x, @heap[1] = @heap[1], 0
        x
    else
        x, @heap[1], @heap[@l] = @heap[1], @heap[@l], 0
        @l -= 1
        i = 1
        while i*2 <= @l
            j = @heap[i*2] > @heap[i*2+1] ? i*2 : i*2+1
            break if @heap[i] >= @heap[j]
            @heap[i], @heap[j] = @heap[j], @heap[i]
            i = j
        end
        x
    end
end

ans = 0
0.upto(m) do |i|
    enque(ab.shift[1]) while !ab.empty? && ab[0][0] <= i
    ans += deque
end

puts ans

Measured memory_bytes: 14712
#include<bits/stdc++.h>
#define task "MAXFRAME"

#define nguyen_dz the_best
#define ll long long
#define ld long double
#define pb push_back
#define endl "\n"
#define ff first
#define ss second
#define pll pair<ll,ll>
#define YES cout <<"YES"<<endl;
#define NO cout <<"NO"<<endl;
#define Yes cout <<"Yes"<<endl;
#define No cout<<"No" <<endl;


using namespace std;
const ll  maxn= 4e6+100;

ll a[maxn];
ll dp[maxn];
int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    //freopen("test.txt","r",stdin);
    if (fopen(task".INP","r"))
    {
        freopen(task".INP", "r", stdin);
        freopen(task".OUT", "w", stdout);
    }
   ll n;
   cin>> n;
   for (int i=0;i<=n;i++)
   {
       cin>>a[i];
   }
   ll res=1;

   for (int i=0;i<=n;i++)
   {
       //  ans=ans+res;
     //    cout <<res<<endl;
     dp[i]=res;
       if (res<a[i])
       {
           cout <<-1;
           return 0;
       }
       else
       {
           res-=a[i];
       }
     //  cout <<res<<endl;
  // if(i!=n) ans=ans+res+a[i];
       res*=2;
       ll p =min(i+1,60);
       res=min(res,1ll<<p);

   //   if (i!=n)

   }
   //ans/=2;
   ll nw=0;
   ll ans=0;
  for (int i=n;i>=0;i--)
  {

      nw+=a[i];
      ans=ans+min(nw,dp[i]);
  }
  cout <<ans;


}



Measured memory_bytes: 5176
#include<iostream>
#include<vector>
#include<string>
#define rep(i, start, end) for (int i = (int)start; i < (int)end; ++i)
#define rrep(i, start, end) for (int i = (int)start - 1; i >= (int)end; --i)
#define all(x) (x).begin(), (x).end()
using namespace std;
using ll = long long;
template<typename T> inline bool chmax(T& a, T b) {if (a < b) {a = b; return true;} return 0;}
template<typename T> inline bool chmin(T& a, T b) {if (a > b) {a = b; return true;} return 0;}

ll f(ll X) {
    return X * X * X * X * X;
}

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll X;
    cin >> X;
    for (ll a = -200; a <= 200; ++a) {
        for (ll b = -200; b <= 200; ++b) {
            if (f(a) - f(b) == X) {
                cout << a << ' ' << b << endl;
                return 0;
            }
        }
    }
    return 0;
}

Measured memory_bytes: 3692
n = int(input())

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

count = 0

for i in range(n-2):
    maxim = max(ps[i], ps[i+1], ps[i+2])
    minim = min(ps[i], ps[i+1], ps[i+2])
    
    if ps[i] + ps[i+1] + ps[i+2] - maxim - minim == ps[i+1]:
        count += 1

print(count)

Measured memory_bytes: 38384
#define _USE_MATH_DEFINES
#include <algorithm>
#include <bitset>
#include <cstdio>
#include <functional>
#include <iostream>
#include <cfloat>
#include <climits>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <time.h>
#include <vector>
#include <random>
using namespace std;

#define rep(i, N) for (int i = 0; i < N; i++)
#define pb push_back

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> i_i;
typedef pair<int, ll> i_ll;
typedef pair<ll, int> ll_i;
typedef pair<double, int> d_i;
typedef pair<ll, ll> ll_ll;
typedef pair<double, double> d_d;
struct edge { int u, v; ll w; };

ll MOD = 1000000007;
ll _MOD = 1000000009;
int INF = INT_MAX / 10;
double EPS = 1e-10;
double PI2 = M_PI * 2;

int main() {
	string s; cin >> s;
	s[5] = s[13] = ' ';
	cout << s << endl;
}


Measured memory_bytes: 764
//! ----------------------------------------------
//! Framework <https://github.com/vain0x/procon>
//!
//! See the bottom of file for solution.
//! ----------------------------------------------

#![allow(unused_imports)]
#![allow(non_snake_case)]

use std::cell::RefCell;
use std::cmp::{max, min, Ordering};
use std::collections::*;
use std::fmt::{Debug, Display, Formatter, Write as FmtWrite};
use std::io::{stderr, stdin, BufRead, Write};
use std::mem::{replace, swap};
use std::ops::*;
use std::rc::Rc;

/// Print values to standard error if debug mode.
#[allow(unused_macros)]
macro_rules! debug {
    ($($e:expr),*) => {
        #[cfg(debug_assertions)]
        $({
            let (e, mut err) = (stringify!($e), stderr());
            writeln!(err, "\x1B[33m{}\x1B[0m = {:?}", e, $e).unwrap()
        })*
    };
}

/// Read from standard input and parse each word.
/// - `read!(T, U, ..)` parses a line as a tuple of words.
/// - `read![[T]]` parses a line as an array of words.
/// - `read![..; N]` parses `N` lines, using `read!(..)` repeatedly.
#[allow(unused_macros)]
macro_rules! read {
    ([$t:ty] ; $n:expr) =>
        ((0..$n).map(|_| read!([$t])).collect::<Vec<_>>());
    ($($t:ty),+ ; $n:expr) =>
        ((0..$n).map(|_| read!($($t),+)).collect::<Vec<_>>());
    ([$t:ty]) =>
        (rl().split_whitespace().map(|w| w.parse().unwrap()).collect::<Vec<$t>>());
    ($($t:ty),*) => {{
        let buf = rl();
        let mut w = buf.split_whitespace();
        ($(w.next().unwrap().parse::<$t>().unwrap()),*)
    }};
}

/// Read a line from standard input.
#[allow(dead_code)]
fn rl() -> String {
    let mut buf = String::new();
    stdin().read_line(&mut buf).unwrap();

    #[allow(deprecated)]
    buf.trim_right().to_owned()
}

// -----------------------------------------------
// Solution
// -----------------------------------------------

fn main() {
    let N = read!(usize);
    let A = read![[i64]];

    let mut freq = HashMap::new();
    for i in 0..N {
        *freq.entry(A[i]).or_insert(0) += 1_usize;
    }

    let mut s = 0;
    for (_, v) in &freq {
        s += v * (v - 1) / 2;
    }

    for k in 0..N {
        let f = freq[&A[k]];

        let mut x = s;
        x -= f * (f - 1) / 2;

        if f >= 2 {
            x += (f - 1) * (f - 2) / 2;
        }

        println!("{}", x);
    }
}


Measured memory_bytes: 17876
// #define _GLIBCXX_DEBUG // for STL debug (optional)
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <string>
#include <cstring>
#include <deque>
#include <list>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <complex>
#include <cmath>
#include <limits>
#include <cfloat>
#include <climits>
#include <ctime>
#include <cassert>
#include <numeric>
#include <fstream>
#include <functional>
#include <bitset>
using namespace std;
using ll = long long int;
using int64 = long long int;
 
template<typename T> void chmax(T &a, T b) {a = max(a, b);}
template<typename T> void chmin(T &a, T b) {a = min(a, b);}
template<typename T> void chadd(T &a, T b) {a = a + b;}
 
int dx[] = {0, 0, 1, -1};
int dy[] = {1, -1, 0, 0};
const int INF = 1LL << 29;
const ll LONGINF = 1LL << 60;
const ll MOD = 1000000007LL;

struct Elem {
    ll pos, cost, hp;
    Elem() {}
    Elem(ll a, ll b, ll c) : pos(a), cost(b), hp(c) {}
    bool operator<(const Elem &e) const {
        if(cost != e.cost) return cost > e.cost;
        return hp < e.hp;
    }
};

ll L;
vector<int> calc(const vector< vector< pair<ll, ll> > > &G, int s) {
    int N = G.size();
    vector< pair<ll, ll> > dist(N, make_pair(INF, INF));
    dist[s] = make_pair(0, L);

    priority_queue<Elem> que;
    que.emplace(s, 0, L);
    while(que.size()) {
        Elem cur = que.top(); que.pop();
        for(auto e : G[cur.pos]) {
            ll to, d; tie(to, d) = e;
            if(d > L) continue;

            bool chg = (cur.hp - d < 0);
            ll n_cost = cur.cost + chg;
            ll n_hp = chg ? L - d : cur.hp - d;

            ll x_cost, x_hp; tie(x_cost, x_hp) = dist[to];
            if(make_pair(n_cost, -n_hp) < make_pair(x_cost, -x_hp)) {
                dist[to] = make_pair(n_cost, n_hp);
                que.emplace(to, n_cost, n_hp);
            }
        }
    }

    vector<int> ans(N);
    for(int i=0; i<N; i++) ans[i] = dist[i].first == INF ? -1 : dist[i].first;
    return ans;
}

int main() {
    ll N, M; cin >> N >> M >> L;
    vector< vector< pair<ll, ll> > > G(N);
    for(int i=0; i<M; i++) {
        ll u, v, c; cin >> u >> v >> c;
        u--; v--;
        G[u].emplace_back(v, c);
        G[v].emplace_back(u, c);
    }

    vector< vector<int> > dist(N);
    for(int i=0; i<N; i++) dist[i] = calc(G, i);

    int Q; cin >> Q;
    while(Q--) {
        int u, v; cin >> u >> v; u--; v--;
        cout << dist[u][v] << endl;
    }
    return 0;
}


Measured memory_bytes: 3200
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>	
#include<map>
#include<set>
#include<utility>
#include<cmath>
#include<cstring>
#include<queue>
#include<stack>
#include<cstdio>
#include<sstream>
#include<iomanip>
#define loop(i,a,b) for(int i=a;i<b;i++) 
#define rep(i,a) loop(i,0,a)
#define pb push_back
#define mp make_pair
#define all(in) in.begin(),in.end()
#define shosu(x) fixed<<setprecision(x)
using namespace std;
//kaewasuretyuui
typedef long long ll;
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<pii> vp;
typedef vector<vp> vvp;
typedef vector<string> vs;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef pair<int,pii> pip;
typedef vector<pip>vip;
const double PI=acos(-1);
const double EPS=1e-2;
const int inf=1e8;
#define MOD 1000000007
// a^b mod MOD
ll powmod(ll a,ll b){
	ll out=1;
	ll p=a%MOD;
	while(b){
		if(b&1)out=out*p%MOD;
		p=p*p%MOD;
		b>>=1;
	}
	return out;
}
// nCr
vector<ll>d;
ll nCr(ll n,ll r){
	ll out=1;
	r=min(r,n-r);
	if(r<0)return 0;
	for(ll i=n;i>n-r;i--)out=out*(i%MOD)%MOD;
	ll t=d[r];//1;
//	for(ll i=2;i<=r;i++)t=t*i%MOD;
	return out*powmod(t,MOD-2)%MOD;
}
int main(){
	d=vector<ll>(210000);
	d[0]=d[1]=1;
	for(ll i=2;i<210000;i++)d[i]=d[i-1]*i%MOD;
	ll n,m,x;
	cin>>n>>m>>x;
	ll out=0;
	for(ll i=0;i<x+1;i++){
		ll t=1;
		(t*=(nCr(n+2*i,i)-nCr(n+2*i,i-1)+MOD)%MOD)%=MOD;
		(t*=(nCr(m+2*(x-i),x-i)-nCr(m+2*(x-i),x-i-1)+MOD)%MOD)%=MOD;
		(t*=nCr(n+m+2*x,n+2*i))%=MOD;
		(out+=t)%=MOD;
	}
	cout<<out<<endl;
}
/*
int main(){
	int d[]={0,1,1,0};//kyosi
	vvd w(2,vd(4,0.5));//weight
	int x[]={1,2};//input
	int cnt=10000;
	while(cnt--){
		vd y(4);
		rep(i,4)rep(j,2)y[i]+=w[j][i]*x[j];
		double E=0;
		rep(i,4)E-=(d[i]*log(y[i])+(1-d[i])*log(1-y[i]));
		//BP
		rep(i,2)rep(j,4)w[i][j]-=EPS*(y[j]-d[j])*x[i]*(exp(-y[j])/pow(1+exp(-y[j]),2));

//		cout<<cnt<<endl;
//		rep(i,2){rep(j,4)cout<<" "<<shosu(9)<<w[i][j];cout<<endl;}
//		cout<<endl;
	}
	rep(i,2){rep(j,4)cout<<" "<<shosu(9)<<w[i][j];cout<<endl;}
	cout<<endl;
	rep(i,4)cout<<" "<<shosu(9)<<w[0][i]*x[0]+w[1][i]*x[1];
	cout<<endl;
}
//*/	

Measured memory_bytes: 5848
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
using namespace std;
#define rep(i, n) for(int(i) = 0; (i) < (n); (i)++)
#define FOR(i, m, n) for(int(i) = (m); (i) < (n); (i)++)
#define All(v) (v).begin(), (v).end()
#define pb push_back
#define MP(a, b) make_pair((a), (b))
typedef long long ll;
const int INF = 1 << 30;
const ll LINF = 1LL << 60;
const int MOD = 1e9 + 7;

int main() {
    int N;
    cin >> N;
    vector<int> A(N);
    vector<pair<int, int>> op;
    rep(i, N) cin >> A[i];
    int m = 0;
    int idx = 0;
    rep(i, N) {
        if(abs(A[i]) > m) {
            m = abs(A[i]);
            idx = i;
        }
    }
    int cnt = 0;
    rep(i, N) {
        if(i == idx)
            continue;
        A[i] += A[idx];
        op.pb(MP(idx + 1, i + 1));
        cnt++;
    }
    if(A[idx] < 0) {
        for(int i = N - 1; i >= 1; i--) {
            A[i - 1] += A[i];
            op.pb(MP(i + 1, i));
            cnt++;
        }
    } else {
        rep(i, N - 1) {
            A[i + 1] += A[i];
            op.pb(MP(i + 1, i + 2));
            cnt++;
        }
    }
    cout << cnt << endl;
    rep(i, op.size()) { cout << op[i].first << " " << op[i].second << endl; }
    return 0;
}

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

#undef _P
#define _P(...) (void)printf(__VA_ARGS__)
#define FOR(x,to) for(x=0;x<(to);x++)
#define FORR(x,arr) for(auto& x:arr)
#define ITR(x,c) for(__typeof(c.begin()) x=c.begin();x!=c.end();x++)
#define ALL(a) (a.begin()),(a.end())
#define ZERO(a) memset(a,0,sizeof(a))
#define MINUS(a) memset(a,0xff,sizeof(a))
//-------------------------------------------------------

int N;
string S;

int mi[256];

void solve() {
	int i,j,k,l,r,x,y; string s;
	
	FOR(i,256) mi[i]=101010;
	
	cin>>N;
	FOR(i,N) {
		int cnt[256]={};
		cin>>S;
		FORR(c,S) cnt[c]++;
		FOR(j,256) mi[j]=min(mi[j],cnt[j]);
	}
	
	string R;
	FOR(i,256) {
		FOR(j,mi[i]) R+=(char)i;
	}
	cout<<R<<endl;
	
}


int main(int argc,char** argv){
	string s;int i;
	if(argc==1) ios::sync_with_stdio(false), cin.tie(0);
	FOR(i,argc-1) s+=argv[i+1],s+='\n';
	FOR(i,s.size()) ungetc(s[s.size()-1-i],stdin);
	solve(); return 0;
}


Measured memory_bytes: 256
#include<iostream>/*入出力関連ヘッダファイル*/
#include<string>
using namespace std;/*標準名前空間を利用する。cinやcoutはこれによって利用可能になる*/

int N,K;
string S;

int main(void) {
  cin >> N;
  cin >> S;
  cin >> K;
  for(int i=0; i<N; i++){
    if(S[i]!=S[K-1]){
      S[i]='*';
    }
  }
  
  cout << S << endl;
  return 0;
}

Measured memory_bytes: 256
N = int(input())
red_ps  = []
blue_ps = []
for i in range(N):
    red_ps.append(list((map(int,input().split()))))
for i in range(N):
    blue_ps.append(list((map(int,input().split()))))
    
red_ps.sort(key = lambda p: p[0], reverse = True)
blue_ps.sort(key = lambda p: p[1], reverse = False)

count = 0

for blue_p in blue_ps:
    for i,red_p in enumerate(red_ps):
        if red_p[0] < blue_p[0] and red_p[1] < blue_p[1]:
            count += 1
            red_ps.pop(i)
            break

print(count)

Measured memory_bytes: 3064
n, m = map(int, raw_input().split())
cnt = [1]*(n+1)
red = [0, 1] + [0]*n
for i in xrange(m):
    x, y = map(int, raw_input().split())
    cnt[y] += 1
    if red[x]:
        red[y] = 1
    cnt[x] -= 1
    if cnt[x] == 0:
        red[x] = 0
print sum(red)

Measured memory_bytes: 4996
import heapq as hq

n,m = map(int, input().split())
a = list(map(int, input().split()))
b = list(map(lambda x: x*(-1), a))
hq.heapify(b)
for  _ in range(0,m):
    max = hq.heappop(b)*(-1)
    max = (-1)*(max // 2)
    hq.heappush(b, max)

print(-sum(b))

Measured memory_bytes: 14180
#include "bits/stdc++.h"
#include <iostream>
#include <string.h>
#include <stdio.h>
#include <map>
#include <vector>
#include <math.h>
#include <algorithm>
#include <queue>
#include <set>
#include <tuple>
using namespace std;

#define FOR(i,init,a) for(int i=init; i<a; i++)
#define rep(i,a) FOR(i,0,a)
#define rrep(i,a) for(int i=a; i>=0; i--)
#define rep1(i,a) for(int i=1; i<=a; i++)
#define cout1(a) cout << a << endl;
#define cout2(a,b) cout << a << " " << b << endl;
#define cout3(a,b,c) cout << a << " " << b << " " << c << endl;
#define cout4(a,b,c,d) cout << a << " " << b << " " << c << " " << d << endl;
#define mem(a,n) memset( a, n, sizeof(a))
#define all(a) a.begin(),a.end()
#define chmin(a,b) a=min(a,b);
#define chmax(a,b) a=max(a,b);

typedef long long ll;
typedef long double ld;
typedef pair<int,int> pii;
typedef vector<int> V;
typedef vector<V> VV;
typedef vector<VV> VVV;
const int INF = 1e9;
const int MOD = 1e9+7;
const ll LLINF = 1e18;
static const double pi = 3.141592653589793;

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    int N;
    cin>>N;
    
    int cnt=0;
    while(N>0){
        cnt+=N%10;
        N/=10;
    }
    cout1(cnt)
}

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

public class Main {


    public static void main(String[] args) throws IOException {
        Scanner sc = new Scanner();
        PrintWriter out = new PrintWriter(System.out);
        int a = sc.nextInt(), b = sc.nextInt();
        int sockets = 1;
        int ans = 0;
        while (sockets < b) {
            sockets += a - 1;
            ans++;
        }
        out.println(ans);
        out.flush();
        out.close();
    }

    static class Scanner {
        BufferedReader br;
        StringTokenizer st;

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

        String next() throws IOException {
            while (st == null || !st.hasMoreTokens())
                st = new StringTokenizer(br.readLine());
            return st.nextToken();
        }

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

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

        Integer[] nextIntegerArray(int n) throws IOException {
            Integer[] ans = new Integer[n];
            for (int i = 0; i < n; i++)
                ans[i] = nextInt();
            return ans;
        }

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

        int[] nextIntArray(int n) throws IOException {
            int[] ans = new int[n];
            for (int i = 0; i < n; i++)
                ans[i] = nextInt() - 1;
            return ans;
        }

    }


}

Measured memory_bytes: 21076
#include <algorithm>
#include <boost/optional.hpp>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <functional>
#include <iostream>
#include <limits>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <string>
#include <tuple>
#include <type_traits>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>

#define REP(i, n) for(int i = 0, i##_MACRO = (n); i < i##_MACRO; i++)
#define RANGE(i, a, b) for(int i = (a), i##_MACRO = (b); i < i##_MACRO; i++)
#define EACH(e, a) for(auto&& e : a)
#define ALL(a) std::begin(a), std::end(a)
#define RALL(a) std::rbegin(a), std::rend(a)
#define FILL(a, n) memset((a), n, sizeof(a))
#define FILLZ(a) FILL(a, 0)
#define INT(x) (static_cast<int>(x))

using namespace std;

using ll = long long;
using VI = vector<int>;
using VI2D = vector<vector<int>>;

constexpr int INF = 2e9;
constexpr double EPS = 1e-10;
constexpr double PI = acos(-1.0);

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

template <typename T>
constexpr int sign(T x) {
	return x < 0 ? -1 : x > 0 ? 1 : 0;
}

template <>
constexpr int sign(double x) {
	return x < -EPS ? -1 : x > EPS ? 1 : 0;
}

template <typename T, typename U>
constexpr void chmax(T& m, U x) {
	m = max(m, x);
}

template <typename T, typename U>
constexpr void chmin(T& m, U x) {
	m = min(m, x);
}

template <typename T>
constexpr T square(T x) {
	return x * x;
}

bool is_palindrome(string s) {
	int n = s.size();
	REP(i, n / 2) {
		if(s[i] != s[n - i - 1]) {
			return false;
		}
	}
	return true;
}

bool check(string s) {
	int n = s.size();
	return is_palindrome(s) && is_palindrome(s.substr(0, (n - 1) / 2)) &&
		   is_palindrome(s.substr((n + 3) / 2 - 1));
}

int main() {
	string s;
	cin >> s;
	cout << (check(s) ? "Yes" : "No") << endl;
	return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
template <class A, class B> inline bool chmax(A &a, const B &b) { return b > a && (a = b, true); }
template <class A, class B> inline bool chmin(A &a, const B &b) { return b < a && (a = b, true); }
typedef long long ll;
typedef vector<int> vint;
typedef pair<int, int> pint;
typedef vector<long long> vlong;
typedef vector<string> vstring;
#define _GLIBCXX_DEBUG
#define vpush(a,x) a.push_back(x);
#define rep(i, n) REP(i, 0, n)
#define all(v) v.begin(), v.end()
#define REP(i, x, n) for(int i = x; i < n; i++)
const int INF = 1 << 30;
const int dx[] = {1,0,-1,0,1,1,-1,-1};
const int dy[] = {0,-1,0,1,1,-1,-1,1};
#define stp(x)  setprecision(x)
int main(){
  cin.tie(nullptr);
  ios::sync_with_stdio(false);
  int n;
  cin>>n;
  vint t(n+1),x(n+1),y(n+1);
  t[0]=0;
  x[0]=0;
  y[0]=0;
  REP(i,1,n+1){
    cin>>t[i]>>x[i]>>y[i];
  }
  REP(i,1,n+1){
    int kyo=abs(x[i]-x[i-1])+abs(y[i]-y[i-1]);
    int time=t[i]-t[i-1];
    if(kyo>time){
      cout<<"No"<<'\n';
      return(0);
    }
    else if(kyo==time){
    }
    else{
      if((time-kyo)%2!=0){
        cout<<"No"<<'\n';
        return(0);
      }
    }
  }
  cout<<"Yes"<<'\n';
  return(0);
}


Measured memory_bytes: 1408