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

int main(){
    int n;
    cin >> n;
    vector<int> v(n+1);
    for(int i=0; i<n; i++) cin >> v[i];

    int cnt = 0;
    while(true){
        bool flag = true;
        for(int i=0; i<n; i++) if(v[i] != 0) flag = false;
        if(flag) break;

        int l = 0;
        for(int i=0; i<n; i++){
            if(v[i] != 0){
                l = i;
                break;
            }
        }

        int r = l;
        for(int i=l; i<n; i++){
            if(v[i] == 0) break;
            r = i;
        }

        for(int i=l; i<=r; i++) v[i]--;
        cnt++;
    }
    cout << cnt << endl;
    return 0;
}

Measured memory_bytes: 256
import itertools
N,M,Q = map(int,input().split())

li = [list(map(int,input().split())) for _ in range(Q)]
ans = 0
a = [i for i in range(1,M+1)]

for A in itertools.combinations_with_replacement(a,N):
    tmp = 0
    for l in li:
        if A[l[1]-1] - A[l[0]-1] == l[2]:
            tmp += l[3]
    else:
        ans = max(ans,tmp)
print(ans)

Measured memory_bytes: 9104
S = list(input())
l = [0]*(len(S) + 1)
for i in range(len(S)):
  if S[i] == "<":
    l[i + 1] = l[i] + 1
for i in range(len(S)):
  if S[-i - 1] == ">" and l[-i - 2] <= l[-i -1]:
    l[-i -2] = l[-i - 1] + 1
print(sum(l))

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

int main()
{
    long long A, B;
    cin >> A >> B;

    vector<long long> av;
    for(long long i = 1; i*i <= A; i++)
    {
        if(A % i == 0)
        {
            av.push_back(i);
            if(i*i != A) av.push_back(A/i);
        }
    }

    vector<long long> bv;
    for(long long i = 1; i*i <= B; i++)
    {
        if(B % i == 0)
        {
            bv.push_back(i);
            if(i*i != B) bv.push_back(B/i);
        }
    }

    vector<long long> cv;
    for(long long i = 0; i < av.size(); i++)
    {
        for(long long j = 0; j < bv.size(); j++)
        {
            if(av[i] == bv[j]) cv.push_back(av[i]);
        }
    }

    //sort(cv.begin(),cv.end());

    vector<long long> dv;
    for(long long i = 0; i < cv.size(); i++)
    {
        bool flag = true;
        if(cv[i] == 1) flag = true;
        else if(cv[i] == 2) flag = true;
        else if(cv[i] % 2 == 0) flag = false;
        else
        {
            for(long long j = 3; j*j <= cv[i]; j+=2)
            {
                if(cv[i] % j == 0)
                {
                    flag = false;
                    break;
                }
            }
        }
        if(flag == true) dv.push_back(cv[i]);
    }

    cout << dv.size() << endl;
    return 0;
}

Measured memory_bytes: 768
import scala.collection.mutable._
import io.StdIn.readInt
import io.StdIn.readLine

object Main extends App {
  val out = new java.io.PrintWriter(System.out)

  def calculate(q:Array[Int],d:Array[Array[Int]]):Int = {
    val ts = q(0)
    val te = q(1)
    val st = q(2)

    val a = d.filter(_(2) == st)
    val map = new HashMap[Int,Array[Int]]
    val log = new ListBuffer[Tuple2[Int,Int]]
    a.foreach(l => {
      if(l(3) == 1) map.put(l(1),l)
      else {
        val e = map(l(1))
        log += {( e(0), l(0) )}
        }
    })
    // println(log.mkString)

    val time = Array.ofDim[Boolean](721)
    log.foreach(t => {
      val s = math.max(ts, t._1) -540
      val e = math.min(te, t._2) -540
      (s until e).foreach(time(_) = true)
    })
    time.count(_ == true)
  }

  def solve(s:String):Unit = {
    // val Array(n, m) = s.split(" ").map(_.toInt)
    val r = readInt
    val d = Iterator.continually(readLine)
      .take(r)
      .map(_.split(" ").map(_.toInt))
      .toArray
    val q = readInt
    Iterator.continually(readLine)
      .take(q)
      .map(_.split(" ").map(_.toInt))
      .foreach(qd => out.println(calculate(qd,d)))
  }

  Iterator.continually(readLine)
    .takeWhile(_ != "0 0")
    .foreach(solve(_))
  
  out.flush
}


Measured memory_bytes: 57744
#include <bits/stdc++.h>
#define l_ength size
const int inf = (1<<30);
const int mod = 1000000007; // 998244353
using ll = long long;
using namespace std;

int main(){
	int n; cin >> n;
	vector<int> p(n);
	vector<int> q(n);
	for( auto &k : p ) cin >> k;
	for( auto &k : q ) cin >> k;
	vector<int> a(n);
    iota( a.begin(), a.end(), 1 );
	int lexp = -1, lexq = -1;
	int cnt = 0;
	do{
		bool pflag = true, qflag = true;
		for( int i = 0; i < n; ++i ){
			if( a[i] != p[i] ) pflag = false;
			if( a[i] != q[i] ) qflag = false;
		}
		if( pflag ) lexp = cnt;
		if( qflag ) lexq = cnt;
		++cnt;
    } while( next_permutation( a.begin(), a.end() ) );
	cout << abs(lexp-lexq) << endl;
}

Measured memory_bytes: 256
#include <iostream>

using namespace std;
#define MAX 100002

int main(void) {
  
  int n,m,x,y;
  int i;
  cin>>n>>m;

  int r[MAX];
  int a[MAX];

  r[1]=1;
  a[1]=1;
  for(i=2;i<=n;i++)r[i]=0,a[i]=1;
  
  for(i=1;i<=m;i++){
    cin>>x>>y;
    if(r[x])r[y]=1;
    if(a[x]==1)r[x]=0;
    a[x]--;
    a[y]++;
  }

  int count=0;

  for(i=1;i<=n;i++)
    if(r[i])count++;

  cout<<count;
  
  return 0;
}

Measured memory_bytes: 1024
import java.util.Scanner;

public class Main {
	static long ans = 0;

	public static void main(String[] args) throws Exception {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int m = sc.nextInt();
		boolean[][] path = new boolean[n + 1][n + 1];
		for (int i = 0; i < m; i++) {
			int a = sc.nextInt();
			int b = sc.nextInt();
			path[a][b] = true;
			path[b][a] = true;
		}
		sc.close();

		boolean[] flg = new boolean[n + 1];
		dfs(flg, path, 1);
		System.out.println(ans);
	}

	static void dfs(boolean[] flg, boolean[][] path, int node) {
		if (flg[node]) {
			return;
		}
		flg[node] = true;

		boolean judge = true;
		for (int i = 1; i < flg.length; i++) {
			if (!flg[i]) {
				judge = false;
				break;
			}
		}
		if (judge) {
			ans++;
			return;
		}

		for (int i = 1; i < path[node].length; i++) {
			if (path[node][i]) {
				boolean[] nextFlg = new boolean[flg.length];
				System.arraycopy(flg, 0, nextFlg, 0, flg.length);
				dfs(nextFlg, path, i);
			}
		}
	}
}


Measured memory_bytes: 23892
#include <bits/stdc++.h>
using namespace std;
#define X first
#define Y second
#define pb push_back
#define mp make_pair
typedef pair<int, int> ii;
typedef vector<int> vi;
typedef vector< ii > vii;
typedef long long LL;
struct node
{
	int val;
	node *left, *right;
	node(int a, node *b, node *c)
	{
		val = a;
		left = b;
		right = c;
	}
};
node* create(int *arr, int L, int R)
{
	if(L == R) return new node(arr[L], NULL, NULL);
	node *x = create(arr, L, (L+R)/2);
	node *y = create(arr, (L+R)/2+1, R);
	return new node(min(x->val, y->val), x, y);
}
int ask(node *p, int L, int R, int i, int j)
{
	if(i> R || j< L) return 1e9;
	if(i<= L && R<= j) return p->val;
	int x = ask(p->left, L, (L+R)/2, i, j);
	int y = ask(p->right, (L+R)/2+1, R, i, j);
	return min(x, y);
}
void update(node *p, int L, int R, int dat, int to)
{
	if(L> dat || R< dat) return;
	if(L == R)
	{
		p->val = to;
		return;
	}
	update(p->left, L, (L+R)/2, dat, to);
	update(p->right, (L+R)/2+1, R, dat, to);
	p->val = min(p->left->val, p->right->val);
}
int arr[200005];
int arr2[200005];
int mapper[200005];
struct chai
{
	int val;
	int left, right;
	bool operator < (chai other) const
	{
		return val> other.val;
	}
	chai(int a, int b, int c)
	{
		val = a;
		left = b;
		right = c;
	}
};
node *root1, *root2;
int n;
int getMin(int a, int b)
{
	if(a%2) return ask(root1, 1, n, a, b);
	return ask(root2, 1, n, a, b);
}
int main()
{
	scanf("%d", &n);
	for(int i = 1; i<= n; i++)
	{
		scanf("%d", arr+i);
		mapper[arr[i]] = i;
		arr2[i] = 1e9;
	}
	for(int i = 2; i<= n; i+=2)
	{
		arr2[i] = arr[i];
		arr[i] = 1e9;
	}
	root1 = create(arr, 1, n);
	root2 = create(arr2, 1, n);
	vi res;
	priority_queue<chai> pq;
	pq.push(chai(getMin(1, n), 1, n));
	for(int i = 2; i<= n; i+= 2)
	{
		chai here = pq.top(); pq.pop();
		int x = here.val;
		int L = here.left, R = here.right;
		//printf("%d: [%d, %d]\n", x, L, R);
		int add = mapper[x];
		int y;
		if(L%2) y = ask(root2, 1, n, add+1, R);
		else y = ask(root1, 1, n, add+1, R);
		//printf("%d\n", y);
		int add2 = mapper[y];
		res.pb(x); res.pb(y);
		if(L<= add-1) pq.push(chai(getMin(L, add-1), L, add-1));
		if(add+1<= add2-1) pq.push(chai(getMin(add+1, add2-1), add+1, add2-1));
		if(add2+1<= R) pq.push(chai(getMin(add2+1, R), add2+1, R));
	}
	for(auto x : res) printf("%d ", x);
	printf("\n");
	return 0;
}

Measured memory_bytes: 30364
import sys
sys.setrecursionlimit(12345678)
import itertools
from collections import Counter
from collections import defaultdict
from collections import deque
import bisect
from heapq import heappush, heappop


def main():
    a, b = map(int, input().split())
    if a > b:
        print(str(b) * a)
    else:
        print(str(a) * b)


if __name__ == '__main__':
    main()


Measured memory_bytes: 38256
import fractions
a,b,c,d = map(int,input().split())
ac = (a-1)//c
ad = (a-1)//d
bc = b//c
bd = b//d
saisyounum = int(c * d / fractions.gcd(c, d))
checknum = (b//saisyounum)-((a-1)//saisyounum)
ans = int((bc-ac)+(bd-ad)-checknum)
print(b-a-ans+1)

Measured memory_bytes: 5048
N = int(input())
A = list(map(int, input().split()))
B = list(map(int, input().split()))

ans = 0
for i in range(N):
    Q = min(A[i], B[i])
    A[i] -= Q
    ans += Q
    B[i] -= Q

    Q = min(A[i + 1], B[i])
    A[i + 1] -= Q
    ans += Q

print(ans)


Measured memory_bytes: 18476
#include <algorithm>
#include <iostream>
#include <vector>

using namespace std;

typedef long long ll;

#define MOD 1000000007

int main() {
  ll a, b, k;
  cin >> a >> b >> k;
  if (a + b <= k) {
    cout << 0 << " " << 0 << endl;
  } else {
    if (a > k) {
      cout << a - k << " " << b << endl;
    } else {
      cout << 0 << " " << b - (k - a) << endl;
    }
  }
  return 0;
}

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

int main() {
    int n;
    cin>>n;

    vector<int>a(n);
    rep(i,0,n){
        cin>>a[i];
    }

    int x=a[0];
    int count=1;

    rep(i,0,n-1){
        if(x==2){
            break;
        }
        x=a[x-1];
        count++;
    }

    if(count==n){
        cout<<-1<<endl;
    }
    else{
        cout<<count<<endl;
    }
}


Measured memory_bytes: 640
N, x = map(int, input().split())

if x in [1, 2 * N - 1]:
    print("No")
else:
    print("Yes")
    a = [None] * (2 * N - 1)
    unused = set(range(1, 2 * N))
    a[N - 1] = x
    a[N - 2] = x - 1
    a[N] = x + 1
    unused -= {x - 1, x, x + 1}
    if N - 3 >= 0 and x + 2 <= 2 * N - 1:
        a[N - 3] = x + 2
        unused -= {x + 2}
    if N + 1 < len(a) and x - 2 >= 1:
        a[N + 1] = x - 2
        unused -= {x - 2}
    for i in range(len(a)):
        if a[i] is None:
            a[i] = unused.pop()
    print(" ".join(map(str, a)))

Measured memory_bytes: 33124
import java.util.Arrays;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ
		Solve s= new Solve();
		s.solve();
	}

}
class Solve{
	 Scanner sc = new Scanner(System.in) ;

	 void solve() {
	 int N=sc.nextInt();
	 int[] d= new int[N];
	 for(int i=0;i<N;i++) {
		 d[i]=sc.nextInt();
	 }
	 Arrays.sort(d);
	 int half=(N/2)-1;

	 System.out.println(d[half+1]-d[half]);
	 


	 }
}

Measured memory_bytes: 50504
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define MOD 1000000007
#define all(ppp) ppp.begin(),ppp.end()
#define out(ppp) cout<<(ppp)<<endl
#define out1(ppp) cout<<(ppp) 
#define MAX_CHAR 256

#define FOR(i, a, b) for (int i=a; i<(b); i++)
#define F0R(i, a) for (int i=0; i<(a); i++)
#define FORd(i,a,b) for (int i = (b)-1; i >= a; i--)
#define F0Rd(i,a) for (int i = (a)-1; i >= 0; i--)
#define pb push_back

typedef long double ld;
typedef complex<ld> cd;
 
typedef pair<int, int> pi;
typedef pair<ll,ll> pl;
typedef pair<ld,ld> pd;
 
typedef vector<int> vi;
typedef vector<double> vd;
typedef vector<vi> vvi;
typedef vector<bool> vb;
typedef vector<ll> vl;
typedef vector<pi> vpi;
typedef vector<pl> vpl;
typedef vector<cd> vcd;
typedef vector<vpi> vvpi;

typedef set<pi> spi;

const int INF=INT_MAX;




int main(){
    int N,M;
    cin>>N>>M;
    vi A(N);
    int sum=0;
    F0R(i,N){
        cin>>A[i];
        sum+=A[i];
    }
    sort(all(A));
    reverse(all(A));
    int mini=sum/(4*M);
    for(int i=0;i<M;i++){
        if(A[i]*4*M<sum){
            cout<<"No"<<endl;
            return 0;
        }
    }
    cout<<"Yes"<<endl;
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main() {
int n,d,x,ans;
scanf("%d%d%d",&n,&d,&x);
while(n--) {
int w;
scanf("%d",&w);
ans+=1+(d-1)/w;
}
printf("%d\n",ans+x);
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<string>
#include<vector>
#include<cmath>
#include<map>
#include<iomanip>
#include<queue>
#include<stack>
#include<time.h>
#define rep(i,n)for(int i=0;i<n;i++)
#define int long long
#define ggr getchar();getchar();return 0;
#define prique priority_queue
#define mod 1000000007
#define inf 1e15
#define key 1e9
using namespace std;
typedef pair<int, int>P;
void yes() { cout << "Yay!" << endl; }
void no() { cout << ":(" << endl; }
template<class T> inline void chmax(T& a, T b) {
	a = std::max(a, b);
}
template<class T> inline void chmin(T& a, T b) {
	a = std::min(a, b);
}
bool prime(int n) {
	int cnt = 0;
	for (int i = 1; i <= sqrt(n); i++) {
		if (n % i == 0)cnt++;
	}
	if (cnt != 1)return false;
	else return n != 1;
}
int gcd(int x, int y) {
	if (y == 0)return x;
	return gcd(y, x % y);
}
int lcm(int x, int y) {
	return x / gcd(x, y) * y;
}
int kai(int x, int y) {
	int res = 1;
	for (int i = x - y + 1; i <= x; i++) {
		res *= i; res %= mod;
	}
	return res;
}
int mod_pow(int x, int y, int m) {
	int res = 1;
	while (y) {
		if (y & 1) {
			res = res * x % m;
		}
		x = x * x % m;
		y >>= 1;
	}
	return res;
}
int comb(int x, int y) {
	if (y > x)return 0;
	return kai(x, y)* mod_pow(kai(y, y), mod - 2, mod) % mod;
}
struct edge { int to, cost; };
int par[114514], rrank[114514];//親、木の深さ
void init(int n) {
	rep(i, n) {
		par[i] = i;
		rrank[i] = 0;
	}
}
int find(int x) {
	if (par[x] == x) {
		return x;
	}
	else return par[x] = find(par[x]);
}
void unite(int x, int y) {
	x = find(x);
	y = find(y);
	if (x == y)return;
	if (rrank[x] < rrank[y]) {
		par[x] = y;
	}
	else {
		par[y] = x;
		if (rrank[x] == rrank[y])rrank[x]++;
	}
}
bool same(int x, int y) {
	return find(x) == find(y);
}
int n;
int a[114];
signed main() {
	cin >> n;
	rep(i, n)cin >> a[i];
	int ans = 0;
	rep(i, n - 1) {
		if (a[i] - a[i + 1] > 0)ans += a[i] - a[i + 1];
	}
	cout << ans + a[n - 1] << endl;
	ggr
}



Measured memory_bytes: 256
n,x =map(int,input().split())
L=list(map(int,input().split()))
A = [0] * (n+1)
for i in range(1,n+1):
    A[i] = A[i-1] + L[i-1]
cnt=0
for i in range(n+1):
    if A[i] <= x:
        cnt+= 1
print(cnt)

Measured memory_bytes: 3064
#include <stdio.h>
#include <math.h>

 #define PI 3.14159265358979323846264338327950L

int main(void) {
int a, b, h, m;
scanf("%d%d%d%d", &a, &b, &h, &m);

 long double rad = PI * 2 * (
 (long double)h / 12.0 + ((long double)m / 60.0) / 12.0 - (long
double)m / 60.0);

 long double rsq = (long double)(a * a + b * b) - (long double)(2 * a *
b) * cosl(rad);

 printf("%20.20Lf\n", sqrtl(rsq));

 return 0;
 }

Measured memory_bytes: 2532
#include<iostream>
#include<algorithm>
#include<functional>
#include<cmath>
using namespace std;
long long  mod = 1000000007;
int an[100010] = { 0 };
char tmp[100010];
int main()
{
	char S[100010];
	cin >> S;
	int i = 0, l = 0, count = 0;
	while (S[i] != '\0') {
		if (S[i] == 'R' && S[i + 1] == 'L') {
			l = i;
			count = 0;
			while (S[l] == 'R') {
				an[i + (count % 2)]++;
				count++;
				l--;
			}
			l = i + 1;
			count = 1;
			while (S[l] == 'L') {
				an[i + (count % 2)]++;
				count++;
				l++;
			}
		}
		i++;
	}
	i = 0;
	while (S[i] != '\0') {
		cout << an[i] << " ";
		i++;
	}
}

Measured memory_bytes: 896
//------------------------------------------------------------------------------MANAS UNIYAL---------------------------------------------------------
//                                                                              NEVER GIVE UP
#include<bits/stdc++.h>
using namespace std;
#define fast ios_base::sync_with_stdio(false);	cin.tie(NULL);	cout.tie(NULL);
#define ll long long
#define pb push_back
#define fi first 
#define se second
#define pii pair<ll,ll>
#define INF 0x3f3f3f3f
#define LINF 98765432123456789
#define testcases() ll t; cin>>t; while(t--)
#define debug1(x) cout<<#x<<" "<<x<<"\n";
#define debug2(x,y) cout<<#x<<" "<<x<<" "<<#y<<" "<<y<<"\n";
#define debug3(x,y,z) cout<<#x<<" "<<x<<" "<<#y<<" "<<y<<" "<<#z<<" "<<z<<"\n";
#define debug4(w,x,y,z) cout<<#w<<" "<<w<<" "<<#x<<" "<<x<<" "<<#y<<" "<<y<<" "<<#z<<" "<<z<<"\n";
#define rep(i,start,end) for(ll i=start;i<end;i++)
#define sz(x) (ll)((x).size())
//----------------------------------------------------------------------------------------------------------------------------------------------------

int main()
{
	fast;
	int n,x;
	map<int,int> mp;
	cin>>n;
	for(int i=0;i<n-1;i++)
	{
		cin>>x;
		++mp[x];
	}
	for(int i=1;i<=n;i++)
	{
		if(mp.find(i) == mp.end())
			cout<<"0\n";
		else
			cout<<mp[i]<<"\n";
	}
	return 0;
}


Measured memory_bytes: 13000
while True:
    n,x = map(int,input().split())
    count = 0
    
    if n == 0 and x == 0:
    	break
        
    for i in range(1,n+1):
      for j in range(i+1,n+1):
        for k in range(j+1,n+1):
          if  i + j + k == x:
            count += 1

    print(count)


Measured memory_bytes: 5596
#include <stdio.h>

int main(void)
{
	int i;
	int sco;
	int h = 0;
	
	for(i = 0;i < 5;i++){
		scanf("%d",&sco);
		if(sco < 40){
			h += 40;
		}
		else {
			h += sco;
		}
	}
	
	printf("%d\n",h / 5);
	
	return(0);
}

Measured memory_bytes: 596
class Data:
    def __init__(self):
        self.datanum = 0
        self.datalen = 0


n, k = list(map(int, input().split(' ')))

data_list = []
for i in range(n):
    a, b = map(int, input().split(' '))
    data = Data()
    data.datanum = a
    data.datalen = b
    data_list.append(data)
sorted_list = sorted(data_list, key=lambda u: u.datanum)
output = 0
for data in sorted_list:
    output = data.datanum
    k -= data.datalen
    if k <= 0:
        break
print(output)


Measured memory_bytes: 29184
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

using namespace __gnu_pbds;
using namespace std;


#define fast ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define PSET(x,y) fixed<<setprecision(y)<<x
#define pb push_back
#define pii pair<int,int>
#define pf push_front
#define mp make_pair
#define vi vector<int>
#define vip vector<pair<int,int> >
#define ff first
#define ss second
#define int long long
#define mod 1000000007
#define BIG 998244353
#define s(t) scanf("%lld",&t)
#define p(t) printf("%lld\n",t)
#define mii map<int,int>
#define MSET(table,i) memset(table, i, sizeof(table))
#define endl '\n'
#define tc int t;cin>>t;while(t--)
#define pi  3.1415926358
#define bits(x) __builtin_popcountll(x)
#define minimum(a,n) min_element(a,a+n)-a
#define maximum(a,n) max_element(a,a+n)-a
#define pqbig priority_queue<int>
#define pqsmall priority_queue<pii,vector<pii>,greater<pii> >
#define all(v) v.begin(),v.end()
#define sitr set<int>:: iterator
#define spitr set<pii>:: iterator
#define mitr map<int,int>:: iterator

int toint(const string &s) {stringstream ss; ss << s; int x; ss >> x; return x;}
string tostring ( int number ) {stringstream ss; ss << number; return ss.str();}


typedef tree<pair<pii,pair<int,pii> >, null_type, less<pair<pii,pair<int,pii> > >, rb_tree_tag,
        tree_order_statistics_node_update>
        new_data_set;


#define trace1(x)                cerr<<#x<<": "<<x<<endl
#define trace2(x, y)             cerr<<#x<<": "<<x<<" | "<<#y<<": "<<y<<endl
#define trace3(x, y, z)          cerr<<#x<<":" <<x<<" | "<<#y<<": "<<y<<" | "<<#z<<": "<<z<<endl
#define trace4(a, b, c, d)       cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<endl
#define trace5(a, b, c, d, e)    cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<" | "<<#e<< ": "<<e<<endl
#define trace6(a, b, c, d, e, f) cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<" | "<<#e<< ": "<<e<<" | "<<#f<<": "<<f<<endl


int32_t main()
{
	fast;
	int l,r,d;cin>>l>>r>>d;
	int ans=0;
	for(int i=l;i<=r;i++)
	{
		if(i%d==0)
			ans++;
	}
	cout<<ans;
}

Measured memory_bytes: 3608
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <queue>
#include <cmath>
#include <stdlib.h>
#define ll long long
#define MOD_P 1000000007
#define PI 3.141592
using namespace std;



int main()
{
	int n;
	cin >> n;
	vector<int> rank(n);
	vector<pair<pair<string, int>,int>> res(n);

	for (int i = 0; i < n; i++) {
		pair<pair<string, int>, int> tmp;
		cin >> tmp.first.first >> tmp.first.second;
		tmp.first.second *= -1;
		tmp.second = i + 1;
		res[i] = tmp;
	}

	sort(res.begin(), res.end());

	for (int i = 0; i < n; i++) {
		printf("%d\n", res[i].second);
	}

	return 0;
}

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


int main()
{
    int t=1;
    //cin>>t;

    while( t-- )
    {
        ll a;
        string b;

        cin>>a>>b;

        ll c= (b[0]-'0')*100 + (b[2]-'0')*10 + (b[3]-'0');
        c=a*c;
        c=c/100;
        cout<<c;
    }
    return 0;
}


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

#define rep(i, n) REP(i, 0, n)
#define REP(i, x, n) for (int i = x; i < n; i++)
#define OP(x) cout << x << endl;

int main() {
    int h, n;
    cin >> h >> n;

    string ans = "No";
    rep(i, n){
        int a;
        cin >> a;
        h -= a;
        if(h <= 0){
            ans = "Yes";
            break;
        }
    }
    OP(ans);
}


Measured memory_bytes: 256
H, W = map(int, input().split())
s = []
for i in range(H):
    s.append(input())
for y in range(H-1):
    for x in range(W):
        if(s[y][x] == "#"):
            if(s[y-1][x] == "#" or s[y+1][x] == "#" or s[y][x-1] == "#" or s[y][x+1] == "#"):
                pass
            else:
                print("No")
                exit()
print("Yes")

Measured memory_bytes: 3064
// AOJ 0352: Forecast of Forces
// 2017.10.26

#include <stdio.h>

#define ABS(a) ((a)>=0?(a):-(a))
#define MAX(a,b) ((a)>=(b)?(a):(b))

int w, h;
long long map[1002][1002];
long long dp[1002][1002];

long long score(int r, int c)
{
	if ((r+c) & 1) return map[r+1][c] - (map[r+1][w] - map[r+1][c]);
	return (map[r+1][w] - map[r+1][c]) - map[r+1][c];
}

int main()
{
	int r, c, v;

	scanf("%d%d", &w, &h);
	for (r = 1; r <= h; r++) for (c = 1; c <= w; c++) {
		scanf("%d", &v);
		map[r][c] = map[r][c-1] + v;
	}
	for (r = h; r >= 0; r--) for (c = w; c >= 0; c--) {
		if (r == h) dp[r][c] = 0;
		else if (c == w) dp[r][c] = score(r, c) - dp[r+1][c];
		else dp[r][c] = MAX(-dp[r][c+1], score(r, c) - dp[r+1][c]);
	}
	printf("%lld\n", ABS(dp[0][0]));
	return 0;
}

Measured memory_bytes: 17516
#include<cstdio>
#include<algorithm>
using namespace std;
int vis[51];
int n;
int main()
{
	int a,b,m;
	scanf("%d%d",&n,&m);
	for(int i=1;i<=m;i++)
	{
		scanf("%d%d",&a,&b);
		vis[a]++;
		vis[b]++;
	}
	for(int i=1;i<=n;i++)
		printf("%d\n",vis[i]);
	return 0;
 } 

Measured memory_bytes: 128
#include<stdio.h>

int main(){
  int n;
  scanf("%d",&n);
  int i;
  int r[n];
  int l[n];

  for(i=0;i<n;i++){
    scanf("%d %d",&l[i],&r[i]);
  }

  
  int ans=0;

  for(i=0;i<n;i++){
    ans += r[i] -l[i] +1;
  }

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

  return 0;

}


Measured memory_bytes: 128
import java.util.*;
import java.io.*;

class Main {
    public static void main(String [] args) {
        Solver s = new Solver();
        s.solve();
    }
}

class Solver {
    Reader in = new Reader ();
    Writer out = new Writer ();

    long count(long x) {
        if(x <= 1) return x;
        return 1 + count(x / 2) * 2L;
    }
    void solve () {
        long h = in.nextLong();
        System.out.println(count(h));
    }
}

class Reader {
    private StringTokenizer a;
    private BufferedReader b;
    Reader () {
        a = null;
        try {
            b = new BufferedReader (new InputStreamReader (System.in)); // for file IO, replace this with new FileReader ("in.txt")
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
    public String next () {
        while(a == null || !a.hasMoreTokens()) {
            try {
                a = new StringTokenizer (b.readLine());
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
        return a.nextToken();
    }
    public int nextInt() {
        return Integer.parseInt(this.next());
    }
    public long nextLong () {
        return Long.parseLong(this.next());
    }
    public double nextDouble () {
        return Double.parseDouble(this.next());
    }
    public String nextLine() {
        try {
            return b.readLine();
        } catch (IOException e) {
            e.printStackTrace();
        }
        return "";
    }
}
class Writer {
    private PrintWriter a;
    private StringBuffer b;
    Writer () {
        try {
            a = new PrintWriter (System.out); // for file IO, replace this with new FileWriter ("out.txt")
        } catch (Exception e) {
            e.printStackTrace();
        }
        b = new StringBuffer ("");
    }
    public void write (Object s) {
        b.append(s);
    }
    public void writeln(Object s) {
        b.append(s).append('\n');
    }
    public void flush () {
        a.print(b);
        a.flush();
        a.close();
    }
}


Measured memory_bytes: 21460
from collections import deque
from copy import deepcopy
import heapq

n, k = map(int, input().split())
v = list(map(int, input().split()))
v_sorted = sorted(v)

ans = 0
for i in range(k+1):
    for nl in range(i+1):
        nr = min(k - nl, n-nl)
        ansl, ansr = 0, 0
        for n_trash in range(nl):
            ansll, ansrr = 0, 0
            hands = sorted(v[:nl-n_trash])
            for vv in hands:
                if vv < 0 and n_trash > 0:
                    n_trash -= 1
                else:
                    ansll += vv
            ansl = max(ansl, ansll)

        for n_trash in range(nr):
            ansrr = 0
            hands = sorted(v[-(nr-n_trash):])
            # print(hands, nr, n_trash)
            for vv in hands:
                if vv < 0 and n_trash > 0:
                    n_trash -= 1
                else:
                    ansrr += vv
            ansr = max(ansr, ansrr)
        # print(ansl, ansr)
        ans = max(ans, ansl + ansr)

print(ans)


Measured memory_bytes: 3572
#include<bits/stdc++.h>
#include<unordered_set>
#define FAST_IO   ios::sync_with_stdio(0),cin.tie(0),cout.tie(0)
#define Relocate freopen("./in.txt","r",stdin),freopen("./out.txt","w",stdout)
#define up(mi,a,b) for(mi=a;mi<=b;++mi)
#define down(mi,b,a) for(mi=b;mi>=a;--mi)
#define mfill(a,v) memset(a,v,sizeof(a))
#define INF 0x3f3f3f3f
#define MAX  2000005
#define v_n 5005
#define LL long long
#define ULL unsigned long long 
#define e_n 50005
#define eps 1e-12
#define Blen 32
const LL MOD = 998244353;
using namespace std;
int main(void)
{
	int i, j, k;
	FAST_IO;
	//Relocate;
	int a, b, c;
	LL R, G, B,N;
	cin >> R >> G >> B >> N;
	LL ans = 0;
	for (LL a = 0; a*R <= N; a++)
	{
		for (LL b = 0; b*G <= N; b++)
		{
			LL v = N - a * R - b * G;
			if (v >= 0 && v%B == 0)
			{
				ans++;
			}
		}
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
#!python3

import sys
iim = lambda: map(int, sys.stdin.readline().rstrip().split())

def resolve():
    S = input()
    T = input()

    i = 0
    for a, b in zip(S, T):
        if a != b:
            i += 1

    print(i)


if __name__ == "__main__":
    resolve()


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

using namespace std;

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

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

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

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

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

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

int n,m;
vector<pii> eses;

bool used[125][125];
int edge[125][125];

int dist[125];
bool visited[125];
vector<int> bef[125];

void dfs(int p,int t){
  if(p==t)return;
  for(int to : bef[p]){
    // printf("%d <- %d\n",p,to);
    used[p][to] = true;
    if(visited[to])continue;
    visited[to] = true;
    dfs(to,t);
  }
}

void dijk(int x){
  REP(i,n)dist[i] = 1e9;
  REP(i,n)bef[i].clear();
  REP(i,n)visited[i] = false;
  dist[x] = 0;
  REP(i,n){
    int p = 0;
    REP(j,n){
      if(visited[p] || (!visited[j] && dist[j]<dist[p]))p=j;
    }
    visited[p] = true;
    REP(to,n){
      if(visited[to])continue;
      if(edge[p][to]>1e9)continue;
      int w = edge[p][to];
      if(dist[p]+w <= dist[to]){
        if(dist[p]+w < dist[to])bef[to].clear();
        bef[to].push_back(p);
        dist[to] = dist[p]+w;
      }
    }
  }
  // REP(i,n)DEBUG(bef[i].size());
  REP(i,n)visited[i] = false;
  REP(i,n)dfs(i,x);
}

int main(){
  scanf("%d%d",&n,&m);
  REP(i,n)REP(j,n)edge[i][j] = 3 + 1e9;
  REP(i,m){
    int a,b,c;
    scanf("%d%d%d",&a,&b,&c);
    --a;--b;
    edge[a][b] = edge[b][a] = c;
    eses.push_back(pii(a,b));
  }
  REP(i,n)dijk(i);
  int ans = m;
  REP(i,m){
    int a = eses[i].first, b = eses[i].second;
    if(used[a][b] || used[b][a])ans--;
  }
  cout<<ans<<endl;
  return 0;
}


Measured memory_bytes: 384
#include<iostream>
#include<cstdlib>
#include<string>
#include<vector>
#include<map>
using namespace std;

void bubbleSort(vector<string> &v){
    int size = v.size(), i;
    bool changed = true;
    while(changed){
        changed = false;
        for(i = 0; i < size-1; i++){
            if((int)v[i].at(1) > (int)v[i+1].at(1)){
                string tmp = v[i];
                v[i] = v[i+1];
                v[i+1] = tmp;
                changed = true;
            }
        }
    }
}
void selectionSort(vector<string> &v){
    int size = v.size(), i, j, min;
    for(i = 0; i < size; i++){
        min = i;
        for(j = i; j < size; j++){
            min = (int)v[j].at(1) < (int)v[min].at(1) ? j : min;
        }
        if(i != min){
            string tmp = v[i];
            v[i] = v[min];
            v[min] = tmp;
        }
    }
}

void print(vector<string> &v){
    int i = 0;
    vector<string>::iterator ite = v.begin();
    while(ite != v.end()){
        if(i++ != 0)
            cout << " ";
        cout << *ite;
        ite++;
    }
    cout << endl;
}

bool isStable(map<int, string> &org, vector<string> &sorted){
    map<int, string>::iterator ite = org.begin();
    string s;
    vector<string>::iterator ites = sorted.begin();
    while(ites != sorted.end()){
        s.append(*ites);
        ites++;
    }
    while(ite != org.end()){
        string sub = (*ite).second;
        if(sub.size() >= 4 && s.find(sub) == string::npos){
            return false;
        }
        ite++;
    }
    return true;
}

void printStable(bool isStable){
    if(isStable)
        cout << "Stable" << endl;
    else
        cout << "Not stable" << endl;
}

int main(){
    int n, i;
    string s;
    vector<string> v;
    map<int, string> m;
    cin >> n;
    for(i = 0; i < n; i++){
        cin >> s;
        v.push_back(s);
        m[atoi(&(s.at(1)))].append(s);
    }
    vector<string> v2(v);
    bubbleSort(v2);
    print(v2);
    printStable(isStable(m, v2));
    selectionSort(v);
    print(v);
    printStable(isStable(m, v));
    return 0;
}

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

typedef long long int64;
using vi = vector<int>;
using vii = vector<vi>;
using pii = pair<int, int>;

#define ALL(c) (c).begin(), (c).end()
#define RALL(c) (c).rbegin(), (c).rend()
#define SZ(c) ((int)(c).size())

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

  int n, k;
  cin >> n >> k;
  string s; cin >> s;
  s[k - 1] = tolower(s[k - 1]);
  cout << s << endl;

  return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<cstdio>
#include<vector>
#include<cmath>
#include<algorithm>
#include<functional>
#include<iomanip>
#include<queue>
#include<ciso646>
#include<random>
#include<map>
#include<set>
#include<complex>
#include<bitset>
using namespace std;
typedef long long ll;
typedef unsigned int ui;
const ll MOD = (1e+9)+7;
const ll INF = (ll)1000000007 * 1000000007;
typedef pair<int, int> P;
#define stop char nyaa;cin>>nyaa;
#define rep(i,n) for(int i=0;i<n;i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define per1(i,n) for(int i=n;i>=1;i--)
#define Rep1(i,sta,n) for(int i=sta;i<=n;i++)
typedef long double ld;
typedef complex<ld> Point;
const ld eps = 1e-11;
const ld pi = acos(-1.0);
typedef pair<ll, ll> LP;
typedef pair<ld, ld> LDP;
typedef pair<ll,P> PP;
int main() {
	ll n; cin >> n;
	if (n == 0) {
		cout << '0' << endl; return 0;
	}
	string out;
	ll x = 1;
	rep(i, 32) {
		x *= (ll)2;
		if (n%x) {
			out.push_back('1');
			if (i % 2) {
				n += (x >> 1);
			}
			else {
				n -= (x>>1);
			}
		}
		else {
			out.push_back('0');
		}
	}
	reverse(out.begin(), out.end());
	bool f = true;
	int len = out.size();
	int chk=0;
	rep(i, len) {
		if (f&&out[i] == '0') {
			chk = i + 1;
		}
		else {
			f = false;
		}
	}
	Rep(i, chk, len) {
		cout << out[i];
	}
	cout << endl;
	return 0;
}

Measured memory_bytes: 256
import sys
import math
import itertools
import bisect
from copy import copy
from collections import deque,Counter
from decimal import Decimal
def s(): return input()
def i(): return int(input())
def S(): return input().split()
def I(): return map(int,input().split())
def L(): return list(input().split())
def l(): return list(map(int,input().split()))
def lcm(a,b): return a*b//math.gcd(a,b)
sys.setrecursionlimit(10 ** 9)
mod = 10**9+7

K = i()
print(K//2*(K-K//2))

Measured memory_bytes: 9916
#ifdef _DEBUG
#include "MyLib.h"
#else
#define main_B main
#include "bits/stdc++.h" 
#include <regex>
#define _USE_MATH_DEFINES
#include <math.h>
#define FOR(i,s,e) for (int i = int(s); i < int(e); ++i)
#define REP(i,e) FOR(i,0,e)
#define INF (INT_MAX/2)
#define EPS (1.0e-8)
#define LINF (LLONG_MAX/2)
const int MGN = 10;
const int ARY_SZ_MAX = 10000000;
using namespace std;
using ll = long long; using ull = unsigned long long;
using vi = vector<int>; using vvi = vector<vi>; using vvvi = vector<vvi>;
using vb = vector<bool>; using vvb = vector<vb>; using vvvb = vector<vvb>;
using vl = vector<ll>; using vvl = vector<vl>;
using vd = vector<double>; using vs = vector<string>;
using pii = pair<int, int>; using pll = pair<ll, ll>;
using psi = pair<string, int>;
// functions

#endif


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

    int N; cin >> N;
    vi A(N); REP(i, N) cin >> A[i];

    double sum = 0;
    REP(i,N) {
        sum += 1.0 / A[i];
    }

    double ans = 1 / sum;

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256
def solve():
    N = int(input())
    A = [0]*N
    B = [0]*N
    for i in range(N):
        A[i],B[i] = map(int, input().split())
    A.sort()
    B.sort(reverse=True)
    if N%2==1:
        mid = (N+1)//2-1
        ans = B[mid]-A[mid]+1
    else:
        mid1 = N//2-1
        mid2 = N//2
        ans = (B[mid1]+B[mid2])-(A[mid1]+A[mid2])+1
    return ans
print(solve())

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

int main()
{
  int K;
  cin >> K;
  
  if (K % 2 == 1)
    cout << (K / 2) * ((K / 2) + 1) << endl;
  else
    cout << (K / 2) * (K / 2) << endl;
    
  return 0;
}



Measured memory_bytes: 256
l,r = map(int,input().split())

ans = 2020
if l%2019==0 or r%2019==0 or (l // 2019 != r // 2019):
	ans = 0
else:
	for i in range(l,r):
		if ans == 0:
			break
		for j in range(i+1,r+1):
			# print(i,j)
			ans = min(ans,i*j%2019)
			if ans == 0:
				break
print(ans)

Measured memory_bytes: 3060
t = int(input())

def solve(n,a,b,c,d):
  mem = {0:0,1:d}
  def f(n):
    if n in mem:
      return mem[n]
    ret = n*d
    if n%2 == 0:
      ret = min(ret,a+f(n//2))
    else:
      ret = min(ret,a+d+f(n//2+1),a+d+f(n//2))
    
    if n%3 == 0:
      ret = min(ret,b+f(n//3))
    elif n%3 == 1:
      ret = min(ret,b+d+f(n//3))
    else:
      ret = min(ret,b+d+f(n//3+1))
    
    if n%5 == 0:
      ret = min(ret,c+f(n//5))
    elif n%5 == 1:
      ret = min(ret,c+d+f(n//5))
    elif n%5 == 2:
      ret = min(ret,c+d+d+f(n//5))
    elif n%5 == 3:
      ret = min(ret,c+d+d+f(n//5+1))
    else:
      ret = min(ret,c+d+f(n//5+1))
    mem[n] = ret
    return ret
  return f(n)
 
for _ in range(t):
  n,a,b,c,d = map(int,input().split())
  print(solve(n,a,b,c,d))

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

int n, k;

int r, s, p;

int main() {
	cin >> n >> k;
	cin >> r >> s >> p;
	string t;
	cin >> t;
	long long ans = 0;
	for (int i = 0; i < n; i++) {
		if (t[i] == 'r')
			ans += p;
		if (t[i] == 's')
			ans += r;
		if (t[i] == 'p')
			ans += s;	
	}
	for (int i = 0; i < n - k; i++) {
		if (t[i] == t[i + k]) {
			if (t[i] == 'r') 
				ans -= p;
			if (t[i] == 's')
				ans -= r;
			if (t[i] == 'p')
				ans -= s;
			t[i + k] = ' ';
		}	
	}
	cout << ans;
}


Measured memory_bytes: 512
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <queue>
#include <set>
#include <map>
#include <cmath>
using namespace std;
typedef long long i64;
typedef long double ld;
typedef pair<i64,i64> P;
#define rep(i,s,e) for(int i = (s);i <= (e);i++)

int n;
int m;
int s;
int t;

int a[101010];
int b[101010];
int c[101010];
i64 d[101010];

struct edge{
    int to;
    i64 cost;
};

int main(){
    cin >> n >> m >> s >> t;
    for(int i = 0;i < m;i++){
        cin >> a[i] >> b[i] >> c[i] >> d[i];
    }

    vector<vector<edge>> edges(n + 1,vector<edge>());

    for(int i = 0;i < m;i++){
        edges[a[i]].push_back({b[i],d[i]});
        edges[b[i]].push_back({a[i],d[i]});
        edges[a[i]].push_back({c[i],d[i]});
        edges[c[i]].push_back({a[i],d[i]});
        edges[b[i]].push_back({c[i],d[i]});
        edges[c[i]].push_back({b[i],d[i]});
    }

    priority_queue<P,vector<P>,greater<P>> que;

    vector<i64> dist(n + 1,(1LL << 61));
    que.push({0,s});
    dist[s] = 0;

    while(!que.empty()){
        int v = que.top().second;
        i64 di = que.top().first;
        que.pop();

        if(dist[v] < di) continue;

        for(auto & e : edges[v]){
            if(dist[e.to] > di + e.cost){
                dist[e.to] = di + e.cost;
                que.push({dist[e.to] , e.to});
            }
        }
    }

    cout << dist[t] << endl;
}


Measured memory_bytes: 25552
//#include <iostream>
#include <cstdio>
using namespace std;

int main()
{
    int x,a,b;
    while (scanf("%d%d%d", &x, &a, &b) == 3){
       if (b - a > 0 && b -a <= x)printf("safe\n");
       else if (b - a <= 0 )printf("delicious\n");
       else printf("dangerous\n");
    }
    return 0;
}


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

long long x, n, cnt[100005], ans, m;

int main () {
	cin>>n;
	
	for(int i=1; i<=n; i++){
		cin>>x;
		cnt[x-1]++;
		cnt[x]++;
		cnt[x+1]++;
		m=max(m, x);
	}
	
	for(int i=-1; i<=m+1; i++){
		if(cnt[i]>ans) ans=cnt[i];
	}
	cout<<ans<<endl;
}

Measured memory_bytes: 4212
#!/usr/bin/env python3


def dfs(li):
    if len(li) >= n:
        s = sum(d[i] for i in range(q) if li[b[i]] - li[a[i]] == c[i])
        return s
    res = 0
    for i in range(li[-1], m + 1):
        res = max(res, dfs(li + [i]))
    return res


n, m, q = map(int, input().split())
a = [0] * q
b = [0] * q
c = [0] * q
d = [0] * q
for i in range(q):
    a[i], b[i], c[i], d[i] = map(int, input().split())
    a[i] -= 1
    b[i] -= 1

ans = max(dfs([i]) for i in range(1, m + 1))
print(ans)


Measured memory_bytes: 9132
/*
ゼッケンと座標の組が1つ求まれば良いのだった
解説では「最初に1番のゼッケンをつけていた蟻」の座標とゼッケンを求めていた
実は「一番小さい座標にいる蟻」の座標とゼッケンはもっと簡単に求めることができる

時間経過によって「一番小さい座標にいる蟻」のゼッケンの番号は
蟻が時計回りに座標0を超えて来た時に1減り、反時計回りに座標0を超えたとき1増える
よって、すべての蟻がT秒間に座標0を通過する回数の合計がわかれば求めることができる
*/

#include <stdio.h>
#include <stdlib.h>
#define ll long long
#define rep(i,l,r)for(ll i=(l);i<(r);i++)
int upll(const void*a, const void*b){return*(ll*)a<*(ll*)b?-1:*(ll*)a>*(ll*)b?1:0;}
void sortup(ll*a,int n){qsort(a,n,sizeof(ll),upll);}

ll n,L,T;
ll ans[100010];
int main(){
	scanf("%lld%lld%lld",&n,&L,&T);
	ll cnt=0;
	rep(i,0,n){
		ll x,w;
		scanf("%lld%lld",&x,&w);
		if(w==1)x+=T;
		else x-=T;
		//座標0の点を何度通過したかを数える
		cnt-=x/L;
		x%=L;
		if(x<0){
			x+=L;
			cnt++;
		}
		ans[i]=x;
		cnt%=n;
	}
	sortup(ans,n);
	
	//一番小さい座標ans[0]にいる蟻はcnt番のゼッケンをつけている
	//0番のゼッケンをつけているのはans[-cnt]の蟻
	rep(i,0,n)printf("%lld\n",ans[(i-cnt+n)%n]);
}

Measured memory_bytes: 1900
#include <bits/stdc++.h> 
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
//typedef pair<ll, ll> P;
//typedef pair<int, pair<int, int>> P;
//typedef pair<ll, pair<int, int>> P;
typedef pair<ll,pair<ll,ll>> T;
ll INFL = 1000000000000000010;//10^18 = 2^60
int INF = 2147483600;//10^9
int INFM =100000000;
ll MOD  = 1000000007;
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};

vector<bool> visited(30);
void dfs(vector<P> edge, int now, int from){
    visited[now] = 1;
    for(int i = 0; i < edge.size(); i++){
        if(edge.at(i).first == now){
            if(visited[edge.at(i).second] == 1) continue;
            dfs(edge, edge.at(i).second, now);
        }
    }
}


bool connect(vector<P> edge){
    for(int i = 0; i < 30; i++){
        visited[i] = 1;
    }
    for(int i = 0; i < edge.size(); i++){
        visited[edge.at(i).first] = 0;
        visited[edge.at(i).second] = 0;
    }
    dfs(edge, edge.at(0).first, -1);
    
    for(int i = 0; i < 30; i++){
        if(visited[i] == 0)return 0;
    }
    return 1;
}

int main(){
    while(true){
        int n;
        cin >> n;
        if(n == 0)break;
        bool l = 1;
        vector<P> edge(0);
        for(int i = 0; i < n; i++){
            string s;
            cin >> s;
            edge.push_back({s.at(0) - 'a', s.back() - 'a'});
        }
        l = connect(edge);
        vector<int> cnt_in(30, 0);
        vector<int> cnt_out(30, 0);
        for(int i = 0; i < n; i++){
            cnt_in.at(edge.at(i).first)++;
            cnt_out.at(edge.at(i).second)++;
        }
        for(int i = 0; i < 30; i++){
            if(cnt_in.at(i) != cnt_out.at(i)) l = 0;
        }
        
        if(l){
            cout << "OK" << endl;
        }else{
            cout << "NG" << endl;
        }
    }
}



Measured memory_bytes: 5120
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll INF = 1e18;
const int inf = 1e9;
#define rep(i, a, b) for (int i = a; i < b; i++)
#define per(i, b, a) for (int i = a - 1; i >= b; i--)
using Graph = vector<vector<int>>;
using pint = pair<int, int>;
int dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};
int dxx[8] = {1, 1, 1, 0, 0, -1, -1, -1}, dyy[8] = {-1, 0, 1, -1, 1, -1, 0, 1};

// auto mod int
const int mod = 1000000007;
struct mint {
    ll x; // typedef long long ll;
    mint (ll x = 0) : x ((x % mod + mod) % mod) {}
    mint operator-() const { return mint (-x); }
    mint &operator+= (const mint a) {
        if ((x += a.x) >= mod) x -= mod;
        return *this;
    }
    mint &operator-= (const mint a) {
        if ((x += mod - a.x) >= mod) x -= mod;
        return *this;
    }
    mint &operator*= (const mint a) {
        (x *= a.x) %= mod;
        return *this;
    }
    mint operator+ (const mint a) const { return mint (*this) += a; }
    mint operator- (const mint a) const { return mint (*this) -= a; }
    mint operator* (const mint a) const { return mint (*this) *= a; }
    mint pow (ll t) const {
        if (!t) return 1;
        mint a = pow (t >> 1);
        a *= a;
        if (t & 1) a *= *this;
        return a;
    }
    // for prime mod
    mint inv() const { return pow (mod - 2); }
    mint &operator/= (const mint a) { return *this *= a.inv(); }
    mint operator/ (const mint a) const { return mint (*this) /= a; }
};
istream &operator>> (istream &is, const mint &a) { return is >> a.x; }
ostream &operator<< (ostream &os, const mint &a) { return os << a.x; }

// combination mod prime
struct combination {
    vector<mint> fact, ifact;
    combination (int n) : fact (n + 1), ifact (n + 1) {
        assert (n < mod);
        fact[0] = 1;
        for (int i = 1; i <= n; ++i) fact[i] = fact[i - 1] * i;
        ifact[n] = fact[n].inv();
        for (int i = n; i >= 1; --i) ifact[i - 1] = ifact[i] * i;
    }
    mint operator() (int n, int k) {
        if (k < 0 || k > n) return 0;
        return fact[n] * ifact[k] * ifact[n - k];
    }
} c (2005);
int main() {
    int n, k;
    cin >> n >> k;
    rep (i, 1, k + 1) {
        mint ans = c (k - 1, i - 1) * c (n - k + 1, i);
        cout << ans << "\n";
    }
}

Measured memory_bytes: 256
#include<cstring>
#include<iostream>
#include<algorithm>
#define rep(i,n) for (int i = 0; i < (n); ++i)
using ll = long long;
using namespace std;

int main() {
    int a, b, c, d;
    cin >> a >> b >> c;
    // aとbの入れ替え
    d = a;
    a = b;
    b = d;
    // aとcの入れ替え
    d = a;
    a = c;
    c = d;

    cout << a << " " << b << " " << c << endl;

    return 0;
}

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

int main() {
  int K, A, B;
  cin >> K >> A >> B;
  bool ans = false;
  for (int i = A; i <= B; i++) {
    if (i % K == 0) ans = true;
  }
  if (ans) cout << "OK" << endl;
  else cout << "NG" << endl;
return 0;
}

Measured memory_bytes: 3640
from collections import Counter
def prime_factorize(n):
    a = []
    while n % 2 == 0:
        a.append(2)
        n //= 2
    f = 3
    while f * f <= n:
        if n % f == 0:
            a.append(f)
            n //= f
        else:
            f += 2
    if n != 1:
        a.append(n)
    return a
def main():
    N = int(input())
    l = prime_factorize(N)
    c = Counter(l)
    r = 0
    ll = [0]
    for i in range(1, 100):
        ll.append(ll[-1] + i)
    for i in c.values():
        for j in range(100):
            if ll[j] > i:
                r += j - 1
                break
    return r

print(main())


Measured memory_bytes: 9464
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define MOD (int) (1e9+7)
#define INF (int) 2e9

int main(){
    int n, m;
    cin >> n >> m;
    priority_queue<int, vector<int>> q;

    rep(i, n){
        int a; cin >> a;
        q.push(a);
    }

    rep(i, m) {
        int t = q.top();
        q.pop();
        q.push(t/2);
    }

    ll ans = 0;
    while(!q.empty()){
        ll tmp = q.top();
        q.pop();
        ans += tmp;
    }
    cout << ans << endl;
    // printf("%d\n", N);
    return 0;
}

Measured memory_bytes: 892
def run(n):
    if n < 105:
        return 0
    elif n < 135:
        return 1
    elif n < 165:
        return 2
    elif n < 189:
        return 3
    elif n < 195:
        return 4
    else:
        return 5


def read_line():
    n = int(input())
    return n


def main():
    n = read_line()
    print(run(n))


if __name__ == '__main__':
    main()


Measured memory_bytes: 2940
n = int(input())
s = list(input())

result = 0
for i in range(1, n-1):
    x = list(set(s[:i]))
    y = list(set(s[i:]))
    temp = len(x+y) - len(set(x+y))
    if temp > result:
        result = temp

print(result)

Measured memory_bytes: 3060