akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,k,n) for(int i = (k); i < (n); i++)
#define REP(i,n) FOR(i,0,n)
#define ALL(a) begin(a),end(a)
#define MS(m,v) memset(m,v,sizeof(m))
#define D10 fixed<<setprecision(10)
typedef vector<int> vi;
typedef vector<string> vs;
typedef pair<int, int> P;
typedef long long ll;
const int INF = 114514810;
const int MOD = 1000000007;
const double EPS = 1e-10;
typedef double weight;
struct edge
{
	int to; weight cost;
	bool operator < (const edge& e) const { return cost < e.cost; }
	bool operator >(const edge& e) const { return cost > e.cost; }
};
typedef vector<vector<edge>> Graph;
int dx[] = { -1, 0, 0, 1 }; int dy[] = { 0, -1, 1, 0 };
template<class T> T &chmin(T &a, const T &b) { return a = min(a, b); }
template<class T> T &chmax(T &a, const T &b) { return a = max(a, b); }
bool valid(int x, int y, int h, int w) { return (x >= 0 && y >= 0 && x < h&&y < w); }
int place(int x, int y, int w) { return w*x + y; }
///*************************************************************************************///
///*************************************************************************************///
///*************************************************************************************///

int h, w;
vs fld;

bool isend()
{
	REP(i, h)REP(j, w) if (fld[i][j] != '.'&&fld[i][j] != '*') return false;
	return true;
}

bool check(char c)
{
	int ux = INF, uy = INF, lx = -1, ly = -1;
	REP(i, h)REP(j, w)
	{
		if (fld[i][j] == c)
		{
			chmin(ux, i); chmin(uy, j);
			chmax(lx, i); chmax(ly, j);
		}
	}
	if (ux == INF) return false;

	bool f = true;
	REP(i, h)REP(j, w)
	{
		if (i >= ux&&i <= lx&&j >= uy&&j <= ly)
		{
			if (fld[i][j] != c&&fld[i][j] != '*') f = false;
		}
		else
		{
			if (fld[i][j] == c) f = false;
		}
	}
	if (f)
	{
		for (int i = ux; i <= lx; i++)for (int j = uy; j <= ly; j++)
		{
			fld[i][j] = '*';
		}
	}
	return f;
}

int main()
{
	int n; cin >> n;
	while (n--)
	{
		cin >> h >> w;
		fld.clear();
		fld.resize(h);
		REP(i, h) cin >> fld[i];
		bool update = true;
		bool f = false;
		while (update)
		{
			update = false;
			if (isend())
			{
				f = true;
			}
			REP(i, 26)
			{
				char c = 'A' + i;
				if (check(c)) update = true;
			}
		}
		puts(f ? "SAFE" : "SUSPICIOUS");
	}
	return 0;
}

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

#define hell                         1000000007
#define lcm(a,b)                     (a*b)/__gcd(a,b)
#define ll                           long long
#define vll                          vector<ll>
#define vi                           vector<int>
#define pll                          vector< pair<ll,ll> >
#define pb                           push_back
#define mp                           make_pair
#define all(v)                       v.begin(),v.end()
#define lbnd                         lower_bound
#define ubnd                         upper_bound
#define bs                           binary_search
#define F                            first
#define S                            second
#define rep(i,a,b)                   for(i=a;i<b;i++)
#define parr(a,n)                    for(ll it=0;it<n;it++) cout<<a[it]<<" ";cout<<endl;
#define pcont(a)                     for(auto it:a) cout<<it<<" ";cout<<endl;
#define ret(x)                       return cout<<x,0;
#define endl                           '\n'

/*constants*/
#define MAXN                         100005
#define PI                           3.14159265358979323846

/*debug*/
#define TRACE
#ifdef TRACE
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
    template <typename Arg1>void __f(const char* name, Arg1&& arg1){ std::cout << name << " : " << arg1 << '\n';}
    template <typename Arg1, typename... Args>void __f(const char* names, Arg1&& arg1, Args&&... args){const char* comma = strchr(names + 1, ','); std::cout.write(names, comma - names) << " : " << arg1<<" | ";__f(comma+1, args...);}
#else
#define trace(...)
#endif

using namespace std;


int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);cout.tie(NULL);
	
	ll i,j,n,m,k,cnt=0,ans=0,t=1;
	cin>>n;
	map<string,ll> mm;
	rep(i,0,n){
		string s;
		cin>>s;
		sort(all(s));
		mm[s]++;
	}	
	for(auto it:mm) ans+=((it.S)*(it.S-1))/2;
		ret(ans)
	return 0;
}

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

#define cn count
#define pb push_back
#define in insert
#define fs first
#define sc second
#define sz size
#define len length
#define forn(i, n) for (ll i = 0; i < (ll) (n); ++i)
#define forni(i, n) for (ll i = 1; i < (ll) (n); ++i)
#define IO ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0)

using namespace std;
using ll = long long;
const ll inf = 1e9+7; 
const double PI =  3.141592653589793;

int main(){
	IO;
	ll n;
	string s;
	cin>>n>>s;
	char c1;
	forn(i, s.len()){
		s[i] = (s[i]+n)%91;
		if(s[i]<'A') s[i]+='A';
	}
	
	cout<<s<<"\n";
	return 0;
}


// _   .-')                .-. .-')                 .-')                                               
//( '.( OO )_              \  ( OO )               ( OO ).                                             
// ,--.   ,--.).-'),-----. ,--. ,--.  .-'),-----. (_)---\_) ,--. ,--.     .-----.  ,-.-')  .-'),-----. 
// |   `.'   |( OO'  .-.  '|  .'   / ( OO'  .-.  '/    _ |  |  | |  |    '  .--./  |  |OO)( OO'  .-.  '
// |         |/   |  | |  ||      /, /   |  | |  |\  :` `.  |  | | .-')  |  |('-.  |  |  \/   |  | |  |
// |  |'.'|  |\_) |  |\|  ||     ' _)\_) |  |\|  | '..`''.) |  |_|( OO )/_) |OO  ) |  |(_/\_) |  |\|  |
// |  |   |  |  \ |  | |  ||  .   \    \ |  | |  |.-._)   \ |  | | `-' /||  |`-'| ,|  |_.'  \ |  | |  |
// |  |   |  |   `'  '-'  '|  |\   \    `'  '-'  '\       /('  '-'(_.-'(_'  '--'\(_|  |      `'  '-'  '
// """    """     """""""" """  """"      """""""  """""""  """"""""      """"""   """         """""""



Measured memory_bytes: 3664
S = input()
n = len(S)
S = int(S, 2)

A = '0b'
B = '0b'
for i in range(n):
    if i % 2 == 0:
        A += '0'
        B += '1'
    else:
        A += '1'
        B += '0'

ans = min(bin(S ^ int(A, 0)).count('1'), bin(S ^ int(B, 0)).count('1'))
print(ans)

Measured memory_bytes: 3444
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll INF = 1LL << 60;
const ll MOD = 1e9+7;
 
int main(){
  int a, b;
  cin >> a >> b;
  
  if(a>=13) cout << b << endl;
  else if(a>=6 && a<=12) cout << b/2 << endl;
  else if(a<=5) cout << 0 << endl;
  return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
#include<algorithm>
#include<functional>
using namespace std;
int main(void) 
{
	int N;
	char a[110];
	int countr = 0;
	int countb = 0;
	scanf("%d", &N);
	scanf("%s", a);
	for (int i = 0; i < N; i++) {
		if (a[i] == 'R') {
			//printf("%c", a[i]);
			countr++;
		}
		else{
			//printf("%c", a[i]);
			countb++;
		}
		//printf("%d %d\n", countr, countb);
	}

	if (countr > countb) {
		printf("Yes");
	}
	else {
		printf("No");
	}
	return 0;
}



Measured memory_bytes: 128
import java.util.Scanner;
public class Main {

	public static void main(String[] args) {
		// TODO Auto-generated method stub
		Scanner scan = new Scanner(System.in);
		int num = scan.nextInt();
		if (num <= 999) {
			System.out.println("ABC");
		} else System.out.println("ABD");
		scan.close();
	}

}

Measured memory_bytes: 21844
n,k = map(int,input().split())
s = input()

def judge(str):
    cnt = 0
    t = None
    for i in range(len(str)):
        if str[i] == t:
            cnt+=1
            t = str[i]
        else: t = str[i]
    return cnt

ans=min(judge(s)+2*k,n-1)
print(ans)

Measured memory_bytes: 39408
using System;
using System.Linq;
public class Test{
  public static void Main(){
    int[] n=System.Console.ReadLine().Trim().Split(' ').Select(x=>int.Parse(x)).ToArray();
    int[] m={n[0]*n[1],n[2]};
    System.Console.WriteLine(m.Min());
  }
}

Measured memory_bytes: 13396
def op(xs):
    """
    >>> op("122244")
    '113224'
    >>> op("44444444444")
    '114'
    """
    ys = ''
    last = 0
    r = 0
    for i, x in enumerate(xs):
        if xs[last]== x:
            r+=1
        else:
            ys = ys + "%d%s"%(r, xs[last])
            r = 1
            last = i
    ys = ys + "%d%s"%(r, xs[last])
    return ys

def mut(n, xs):
    """
    >>> mut(5, '11')
    '13112221'
    """
    for i in xrange(n):
        xs = op(xs)
    return xs
def chunk(f):
    """
    """
    while True:
        line = f.readline()
        n = line.strip()
        n = int(n)
        if n == 0:
            raise StopIteration
        line = f.readline()
        xs = line.strip()
        yield mut(n, xs)

import sys
for c in chunk(sys.stdin):
    print c

Measured memory_bytes: 4304
#include <cstdio>
#include <string>
#include <vector>
#include <algorithm>
#include <iostream>
#include <cctype>
#include <cassert>

using namespace std;

string str;
int cnt;

int digit(){
    assert(isdigit(str[cnt]));
    int n=str[cnt++]-'0';
    return n;
}
int number(){
    int n=digit();
    while(cnt<str.size()&&isdigit(str[cnt])){
        n*=10;
        n+=digit();
    }
    return n;
}
int term(void);
int fact(void);

int exp(void){
    int s0=term();
    while(cnt<str.size()){
        char op=str[cnt];
        if(op!='+'&&op!='-')
            break;
        cnt++;
        int s1=term();
        switch(op){
            case '+':
                s0+=s1;
                break;
            case '-':
                s0-=s1;
                break;
            default:
                assert(0);
        }
    }
    return s0;
}
int term(void){
    int s0=fact();
    while(cnt<str.size()){
        char op=str[cnt];
        if(op!='*'&&op!='/')
            break;
        cnt++;
        int s1=fact();
        switch(op){
            case '*':
                s0*=s1;
                break;
            case '/':
                s0/=s1;
                break;
            default:
                assert(0);
        }
    }
    return s0;
}

int fact(void){
    if(str[cnt]=='('){
        cnt++;
        int n=exp();
        assert(str[cnt]==')');
        cnt++;
        return n;
    }
    return number();
}

int main(void){
    int n;
    cin>>n;
    for(int i=0;i<n;i++){
        cin>>str;
        cnt=0;
        cout<<exp()<<endl;
    }
}

Measured memory_bytes: 1204
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (int)(n); i++)
#define REP(i,n) for (int i = 1; i < (int)(n); i++)
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(),x.rend()
#define debug(var) do{cout << #var << " : "; view(var);}while(0)
template<class T> bool chmin(T &a, T b) {if(a>b) {a=b;return 1;}return 0;}
template<class T> bool chmax(T &a, T b) {if(a<b) {a=b;return 1;}return 0;}
using namespace std;
template<class T> void view(T e) {cout << e << endl;}
template<class T> void view(const vector<T> &v) {for(const auto &e : v){cout << e << " ";} cout << endl;}
template<class T> void view(const vector<vector<T>> &vv) {for(const auto &v : vv){view(v);}}
using vint = vector<int>;
using vvint = vector<vector<int>>;
using ll = long long;
using vll = vector<ll>;
using vvll = vector<vector<ll>>;
using P = pair<int,int>;
const int inf = 1<<30;
const ll inf_l = 1LL<<61;
const int MAX = 1e5;

int main() {
    int n; cin >> n;
    string ans;
    rep(i,n) ans += "ACL";
    cout << ans << endl;
}

Measured memory_bytes: 3536
import sys, math
import io, os
#data = io.BytesIO(os.read(0,os.fstat(0).st_size)).readline
from bisect import bisect_left as bl, bisect_right as br, insort
from heapq import heapify, heappush, heappop
from collections import defaultdict as dd, deque, Counter
# from itertools import permutations,combinations
def data(): return sys.stdin.readline().strip()
def mdata(): return list(map(int, data().split()))
def outl(var): sys.stdout.write('\n'.join(map(str, var)) + '\n')
def out(var): sys.stdout.write(str(var) + '\n')
from decimal import Decimal
# from fractions import Fraction
# sys.setrecursionlimit(100000)
mod = 998244353
INF=float('inf')



n=int(input())
BIT = [0]*(n+1)
d1=dd(int)
d2=dd(int)
d=dd(int)
for i in range(n):
    x,y=mdata()
    d1[x]=y
    d2[y]=x
    d[x]=i
l2=list(range(1,n+1))
l1=l2[::-1]
ans=[0]*n
while l1:
    set1=set()
    s=0
    mx=l1[-1]
    my=d1[l1[-1]]
    set1.add(l1.pop())
    while len(set1)!=s:
        s=len(set1)
        while l2 and l2[-1]>=my:
            set1.add(d2[l2[-1]])
            mx=max(mx,d2[l2.pop()])
        while l1 and l1[-1]<=mx:
            set1.add(l1[-1])
            my=min(my,d1[l1.pop()])
    l=len(set1)
    for i in set1:
        ans[d[i]]=l
outl(ans)

Measured memory_bytes: 99608
#include <iostream>
#include <cstdio>


using namespace std;

int main(void)
{
	int num;
	cin >> num;

	int p1 = 0, p2 = 0, p3 = 0, p4 = 0, p5 = 0, p6 = 0;
	float tmp;

	for (int i = 0; i < num; i++)
	{
		cin >> tmp;

		if (tmp < 165.0)
			p1++;
		else if (165.0 <= tmp && tmp < 170.0)
			p2++;
		else if (170.0 <= tmp && tmp < 175.0)
			p3++;
		else if (175.0 <= tmp && tmp < 180.0)
			p4++;
		else if (180.0 <= tmp && tmp < 185.0)
			p5++;
		else
			p6++;

	}

	cout << "1:";
	for (int i = 0; i < p1; i++)
		cout << "*";
	cout << endl;

	cout << "2:";
	for (int i = 0; i < p2; i++)
		cout << "*";
	cout << endl;

	cout << "3:";
	for (int i = 0; i < p3; i++)
		cout << "*";
	cout << endl;

	cout << "4:";
	for (int i = 0; i < p4; i++)
		cout << "*";
	cout << endl;

	cout << "5:";
	for (int i = 0; i < p5; i++)
		cout << "*";
	cout << endl;

	cout << "6:";
	for (int i = 0; i < p6; i++)
		cout << "*";
	cout << endl;

}

Measured memory_bytes: 1228
#include <bits/stdc++.h>
#define MP make_pair
#define F first
#define PB push_back
#define S second
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
const int mod = (int)1e9 + 7;
const int maxn = 1e5 + 4;
const int inf = (int)1e9;

ll a[maxn], b[maxn];

int main() {
	ios_base::sync_with_stdio(false);
	int n;
	cin >> n;
	ll ans = 0;
	for (int i = 0; i < n; i++)
		cin >> a[i] >> b[i];
	for (int i = n - 1; i >= 0; i--) {
		a[i] += ans;
		ll k = (b[i] - (a[i] % b[i])) % b[i];
		ans += k;
	}
	cout << ans << endl;
}


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

typedef long long ll;

template<typename T>
void out(T x) { cout << x << endl; exit(0); }
#define watch(x) cout << (#x) << " is " << (x) << endl

const int maxn = 1e6 + 5;

int n, a[maxn];

int main() {
  ios_base::sync_with_stdio(false); cin.tie(0);  cout.tie(0);
cin>>n;
  for (int i=0; i<n; i++) cin>>a[i];
  sort(a,a+n);
  vector<int> dp;
  for (int i=0; i<n; i++) {
    auto iter = lower_bound(dp.begin(), dp.end(), a[i]);
    if (iter == dp.end()) {
      dp.push_back(a[i]);
    } else {
      *iter = a[i];
    }
  }
  cout<<dp.size()<<endl;
    
  

  return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<string>
#include<vector>
#include<map>
#include<set>
#include<cstdio>
#include<cstring>
#include<queue>
#include<deque>
#include<stack>
#include<ctime>
#include<cmath>
#include<complex>
#include<cstdlib>
#include<iomanip>
#include<utility>
#include<cctype>
#include<bitset>
using namespace std;

int a[200005];
int mp[200005];
int tot;
int n,k;

int main(){
	cin>>n>>k;
	for(int i=0;i<n;i++) scanf("%d",a+i);
	for(int i=0;i<n;i++) mp[a[i]]++;
	sort(mp,mp+n);
	reverse(mp,mp+n);
	for(int i=0;i<k;i++) tot+=mp[i];
	cout<<n-tot<<endl;
	return 0;
}

Measured memory_bytes: 1792
#include <stdio.h>
int main(void)
{
  long x;
  long uresisa1,uresisa2;
  scanf("%ld", &x);
  uresisa1 = x / 500;
  uresisa2 = (x-500*uresisa1)/5;
  printf("%ld", 1000*uresisa1+5*uresisa2);

  return 0;

}

Measured memory_bytes: 1732
//#include <bits/stdc++.h>
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstdlib>
#include <string>
#include <vector>
#include <map>
#include <queue>

using namespace std;

typedef long long ll;
typedef vector<int> vint;
typedef vector<vector<int> > vvint;
typedef vector<long long> vll, vLL;
typedef vector<vector<long long> > vvll, vvLL;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) for(int i=0;i<n;++i)
#define mod (ll)(1e9+7)
#define FIX(a) ((a)%mod+mod)%mod
#define ALL(obj) (obj).begin(), (obj).end()
#define rALL(obj) (obj).rbegin(), (obj).rend()
#define INF 1000000000 //1e9
#define LLINF 2000000000000000000LL //2e18
#define fi first
#define se second
#define pb push_back
int dy[]={0, 0, 1, -1};
int dx[]={1, -1, 0, 0};

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int a,b;
    char c;
    cin >> a >> c >> b;
    if(c=='+'){
        cout << a+b << endl;
    }else{
        cout << a-b << endl;
    }

    return 0;
}

Measured memory_bytes: 3584
#include<iostream>
#include<string>

using namespace std;
string s;
int n;
void calc(string &p,int k){
    //cout << p << " " << k << endl;
    if(k>=s.size())return;
    if(p.size()>n)return;
    if(s[k]==')')return;
    if(s[k]<='Z'&&s[k]>='A'){
        p.push_back(s[k]);
        calc(p,k+1);
        return;
    }
    string x;
    int z = k;
    bool flag = 0;
    for(int i=k;;i++){
        if(s[i]=='('){
            z = i;
            flag = 1;
            break;
        }
        if(s[i]<='Z'&&s[i]>='A'){
            z = i-1;
            break;
        }
        x.push_back(s[i]);
    }
    int d=0;
        if(s[z]=='(')d++;
        int r;
        for(int i=z+1;;i++){
            if(s[i]=='('){
                d++;
            }
            if(s[i]==')'){
                d--;
            }
            if(d==0){
                r = i;  
                break;
            }
        }
    if(flag){
        int y = stoi(x);
        for(int j=0;j<y;j++){
            if(p.size()>n)return;
            calc(p,z+1);
        }
        if(p.size()>n)return;
        if(p.size()<=n){
            calc(p,r+1);
        }
    }else{
        int y = stoi(x);
        for(int i=0;i<y;i++){
            p.push_back(s[r]);
        }
        if(p.size()<=n){
            calc(p,r+1);
        }
    }
   
    return;
}


int main(){   
    while(cin >> s >> n&&s!="0"){
        string p;
        calc(p,0);
        if(p.size()<=n){
            cout << 0 << endl;
        }else{
            cout << p[n] << endl;
        }
    }
    return 0;
}


Measured memory_bytes: 4980
def solve(n,k):
  counter = 0
  for i in range(n,k,-1):
    theValue = n//i * (i-k) + max(n%i-k+1,0)
    if (k == 0):
      theValue = max(theValue-1, 0)
    counter += theValue
  return counter

c = list(map(int, input().split()))
print(solve(c[0], c[1]))

Measured memory_bytes: 3060
from collections import Counter
n = int(input())
v = list(map(int, input().split()))
odd = [v[2*i] for i in range(n//2)]
even = [v[2*i+1] for i in range(n//2)]

co = Counter(odd)
ce = Counter(even)
co = co.most_common()
ce = ce.most_common()
if co[0][0] == ce[0][0]:
  if (len(co)>1) and (len(ce)>1):
    ans = min(n//2-co[1][1]+n//2-ce[0][1], n//2-co[0][1]+n//2-ce[1][1])
  elif len(co) > 1:
    ans = n//2 - co[1][1]
  elif len(ce) > 1:
    ans = n//2 - ce[1][1]
  else:
    ans = n//2
else:
  ans = n//2-co[0][1] + n//2-ce[0][1]
print(ans)

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

int main() {
  int N;
  cin >> N;
  double T, A;
  cin >> T >> A;
  int H[N];
  cin >> H[0];
  double nearest{T - H[0] * 0.006};
  int ans{0};
  for (int i{1}; i < N; ++i) {
    cin >> H[i];
    double t = T - H[i] * 0.006;
    if (abs(nearest - A) > abs(t - A)) {
      nearest = t;
      ans = i;
    }
  }

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


Measured memory_bytes: 384
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define f(k,n) for(auto i =k; i<n; i++)
#define IOS ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie();
#define test ll t; cin>>t;
 
int main(){
    ll L; 
    cin>>L;
    double k = L*(1.0)/3.0;
    printf("%.12f\n",k*k*k);
    //cout<<k*k*k<<endl;
    return 0;
}


Measured memory_bytes: 256
n, l = gets.split.map(&:to_i)

if l >= 0 then
  puts (l+1..(n+l-1)).inject(:+)
elsif (l < 0) && (n+l > 0) then
  puts (l..(n+l-1)).inject(:+)
else
  puts (l..(n+l-1)).inject(:+)-(n+l-1)
end

Measured memory_bytes: 1788
#include <algorithm>
#include <iostream>
#include <queue>
#include <utility>
#include <vector>

using namespace std;

typedef pair<int, int> P;

const long long LINF = 1e15;
int n, m;
vector<P> edge[1100];
vector<int> redge[1100];
long long dist[1100];
bool done[1100][2];

void bfs() {
  queue<int> q;
  q.push(0);
  done[0][0] = true;
  
  while (q.size()) {
    int u = q.front();
    q.pop();
    for (P np: edge[u]) {
      int v = np.first;
      if (done[v][0]) continue;
      q.push(v);
      done[v][0] = true;
    }
  }
  
  q.push(n-1);
  done[n-1][1] = true;
  
  while (q.size()) {
    int u = q.front();
    q.pop();
    for (int v: redge[u]) {
      if (done[v][1]) continue;
      q.push(v);
      done[v][1] = true;
    }
  }
}
  

int main() {
  cin >> n >> m;
  for (int i = 0; i < m; i++) {
    int a, b, c;
    cin >> a >> b >> c;
    a--, b--;
    edge[a].push_back(P(b, -c));
    redge[b].push_back(a);
  }
  
  bfs();
  
  for (int i = 1; i < n; i++) {
    dist[i] = LINF;
  }
  
  for (int loop = 0; loop < n-1; loop++) {
    for (int u = 0; u < n; u++) {
      for (P p: edge[u]) {
        int v = p.first, d = p.second;
        dist[v] = min(dist[v], dist[u] + d);
      }
    }
  }
  
  for (int loop = 0; loop < n-1; loop++) {
    for (int u = 0; u < n; u++) {
      for (P p: edge[u]) {
        int v = p.first, d = p.second;
        if (dist[v] > dist[u] + d) {
          dist[v] = dist[u] + d;
          if (done[v][0] and done[v][1]) {
            cout << "inf" << endl;
            return 0;
          }
        }
      }
    }
  }
  
  cout << -dist[n-1] << endl;
  return 0;
}

Measured memory_bytes: 384
import java.util.Scanner;
class Main {
	
	public static void main(String[] args) {
		Scanner scanner = new Scanner(System.in);
		
		while(true){ 
		int H = scanner.nextInt();
		int W = scanner.nextInt();
		
		if ( H == 0 && W == 0 ){
			break;
			}
			else{
				int smallh;
				int smallw;
				
				for( smallh = 0; smallh < H; smallh++  ) {
					
					for( smallw = 0; smallw < W; smallw++ ) {
						if(smallw == 0 || smallw == W-1 || smallh == 0 || smallh == H-1){
						System.out.print("#");
						}else{
						System.out.print(".");
						}					
				 }
				 System.out.println();
			}	
		}
		System.out.println();
		}
	}
}

Measured memory_bytes: 34224
#include <bits/stdc++.h>
using namespace std;
#define int long long
using ll=long long;
using vi=vector<int>;
using pii=pair<int,int>;
#define ALL(c) begin(c),end(c)
#define RALL(c) rbegin(c),rend(c)
#define ITR(i,b,e) for(auto i=(b);i!=(e);++i)
#define FORE(x,c) for(auto &x:c)
#define REPF(i,a,n) for(int i=a,i##len=(int)(n);i<i##len;++i)
#define REP(i,n) REPF(i,0,n)
#define REPR(i,n) for(int i=(int)(n);i>=0;--i)
#define SZ(c) ((int)c.size())
#define CONTAIN(c,x) (c.find(x)!=end(c))
#define OUTOFRANGE(y,x,h,w) (y<0||x<0||y>=h||x>=w)
#define dump(...)
const int DX[9]={0,1,0,-1,1,1,-1,-1,0},DY[9]={-1,0,1,0,-1,1,1,-1,0};
#define INF (1001001001)
#define INFLL (1001001001001001001ll)
template<class T> ostream& operator << (ostream &os,const vector<T> &v) {
    ITR(i,begin(v),end(v)) os<<*i<<(i==end(v)-1?"":"\n"); return os; }
template<class T> istream& operator >> (istream &is,vector<T> &v) {
    ITR(i,begin(v),end(v)) is>>*i; return is; }
template<class T> istream& operator >> (istream &is, pair<T,T> &p) {
    is>>p.first>>p.second; return is; }
template<class T>bool chmax(T &a,const T &b) {if(a<b) {a=b;return 1;} return 0;}
template<class T>bool chmin(T &a,const T &b) {if(b<a) {a=b;return 1;} return 0;}
//------------------------------------------------------------------------------
struct before_main_function {
    before_main_function() {
        #ifdef int
            #undef INF
            #define INF INFLL
            #define stoi stoll
        #endif
        cin.tie(0);ios::sync_with_stdio(false);
        cout<<setprecision(15)<<fixed;
        // #define endl "\n"
    }
} before_main_function;
//------------------8<------------------------------------8<--------------------

signed main() {
    int x,t;
    cin>>x>>t;
    cout<<max(0ll,x-t)<<endl;
    return 0;
}


Measured memory_bytes: 256
<?php
$que=[];
$head=0;
$tail=0;
list($N,$Q)=explode(' ',trim(fgets(STDIN)));
for($i=0;$i<$N;$i++) $que[$tail++]=(explode(' ',trim(fgets(STDIN))));
$TIME=0;
while($head!=$tail){
  $task=$que[$head++];
  if($task[1]<=$Q){
    echo $task[0],' ',$TIME+$task[1],PHP_EOL;
    $TIME+=$task[1];
  }
  else{
    $task[1]-=$Q;
    $que[$tail++]=$task;
    $TIME+=$Q;
  }
}

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

using namespace std;

const int M = 998244353;
int n, m, k;
long long kaijo[220000];
long long ans;

long long mpw(long long a, int n) {
  if (n == 0) return 1;
  if (n % 2) return mpw(a, n-1) * a % M;
  return mpw(a*a%M, n/2);
}

int main() {
  cin >> n >> m >> k;
  
  kaijo[0] = 1;
  for (int i = 1; i < 210000; i++) {
    kaijo[i] = kaijo[i-1] * i % M;
  }
  
  ans = m * mpw(m-1, n-1) % M;
  for (int i = 1; i <= k; i++) {
    ans += m * kaijo[n-1] % M * mpw(kaijo[i], M-2) % M * mpw(kaijo[n-i-1], M-2) % M * mpw(m-1, n-i-1) % M;
    ans %= M;
  }
  
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 5280
#include<bits/stdc++.h>
using namespace std;
int here,a,ans,n,m,sugo[10000],ccc;
bool flag=false;

int main(){

    while(1){

    for(int i=0;i<9999;i++)sugo[i]=0;
    cin >> n >> m;
    here=1;
    flag=false;
    if(n==0&&m==0)break;
    for(int i=1;i<=n;i++)cin >> sugo[i];
    for(int i=1;i<=m;i++){
        cin >> a;
        here+=a;
        here+=sugo[here];
        //printf("i=%d here=%d\n",i,here);
         if(here>=n&&flag==false){
            ccc=i;
            flag=true;
        }
    }
     cout << ccc << endl;
    }

return 0;
}

Measured memory_bytes: 3004
#include<stdio.h>
#include<math.h>
#include<limits.h>
#define MAX 100000


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

 return b;
}



int main(){
 int n,q,i,com,j,mini;
 int x,y;
 int A[MAX];
 int B[MAX];
 int b,L,R;

 scanf("%d %d",&n,&q);
 b=floor(sqrt(n));

 for(i=0;i<n;i++){
   A[i]=INT_MAX;
   B[i]=INT_MAX;
 }


 for(i=0;i<q;i++){

   scanf("%d %d %d",&com,&x,&y);

   if(com==0){/*update*/
     A[x]=y;
     mini=A[(x/b)*b];
     R=min((x/b+1)*b-1,n-1);
     for(j=(x/b)*b+1;j<=R;j++)mini=min(mini,A[j]);
     B[x/b]=mini;

   }

   else if(com==1){/*find*/
     if(x==y)printf("%d\n",A[x]);

     else{
       L=x/b; R=y/b; mini=INT_MAX;
       if(L==R){
         for(j=x;j<=y;j++)mini=min(mini,A[j]);
         printf("%d\n",mini);
       }else{
         for(j=x;j<(L+1)*b;j++)mini=min(mini,A[j]);
         for(j=L+1;j<R;j++)mini=min(mini,B[j]);
         for(j=R*b;j<=y;j++)mini=min(mini,A[j]);
         printf("%d\n",mini);
       }
     }

   }

 }


return 0;
}


Measured memory_bytes: 2544
#include<bits/stdc++.h>
using namespace std;
int a,b,c,d,y,t,f;
int main(){
    while(1){
        f=0;
        t=0;
        d=0;
        cin>>a;
        if(a==0)return 0;
        for(y=1;y<13;y++){
            cin>>b>>c;
            d+=b-c;
            if(y==12&&d<a){t=13;}
            if(d>=a&&f==0){t=y;f++;}
        }
        if(t==13){cout<<"NA"<<endl;}else
                 {cout<<t<<endl; }
    }




}

Measured memory_bytes: 3072
package main
 
import(
  "fmt"
  "bufio"
  "os"
  "strings"
  "strconv"
  "log"
)
 

func main(){
    W,H,x,y,r := 0,0,0,0,0
    fmt.Scan(&W)
    fmt.Scan(&H)
    fmt.Scan(&x)
    fmt.Scan(&y)
    fmt.Scan(&r)
    if x < 0 || y < 0{
      fmt.Println("No")
    }else if W >= (x+r) && (x+r) >= 0 && H >= (y+r) && (y+r) >= 0{
      fmt.Println("Yes")
    }else{
      fmt.Println("No")
    }
}


var sc = bufio.NewScanner(os.Stdin)

func Rr() []string {
  sc.Scan()
  slice := strings.Split(sc.Text(), " ")
  return slice
}



//入力関係ライブラリ(Atcoder:yamanobori_oldさんのもの)
func make_liner(maxByte int) *bufio.Scanner {
  liner := bufio.NewScanner(os.Stdin)
  liner.Buffer(make([]uint8, 0, 8192), maxByte)
  return liner
}
func word_spliter() *bufio.Scanner {
  words := make_liner(8192) 
  words.Split(bufio.ScanWords)
  return words
}

func eGetLine(r *bufio.Scanner) string {
  if r.Scan() {
    return r.Text()
  }
  err := r.Err()
  if err != nil {
    log.Fatal(err)
  }
  // EOF
  return ""
}

func eGetInt(r *bufio.Scanner) int {
  line := eGetLine(r)
  return eAtoi(line)
}

func eAtoi(s string) int {
  n, err := strconv.Atoi(s)
  if err != nil {
    log.Fatal(err)
  }
  return n
}


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

int T;
string S;
vector<int> sep;
int ans;
bool rejected;

int stoi(int s, int t){
    int res = 0;
    for(int i=s; i<t; i++)
        res = res * 10 + S[i]-'0';
    
    return res;
}

string itos(int s, int t){
    return S.substr(s, t-s);
}

void dfs(int s, vector<int> split, int sum){
    //????????????
    int tans = sum + stoi(s, S.size());
    if(tans <= T){
        if(ans == tans)
            rejected = true;
        if(ans < tans){
            ans = tans;
            rejected = false;
            sep = split;
        }
    }
    
    //????????????
    for(int i=s+1; i<S.size(); i++){
        auto tsplit = split;
        tsplit.push_back(i);
        dfs(i, tsplit, sum + stoi(s, i));
    }
}

void solve(){
    dfs(0, {}, 0);
    
    if(ans == -1){
        cout << "error" << endl;
    }else if(rejected){
        cout << "rejected" << endl;
    }else{
        cout << ans;
        sep.insert(sep.begin(), 0);
        sep.push_back(S.size());
        for(int i=1; i<sep.size(); i++){
            cout << " " << itos(sep[i-1], sep[i]);
        }
        cout << endl;
    }
}

int main(){
    while(cin >> T >> S, T){
        ans = -1;
        rejected = false;
        sep.clear();
        solve();
    }
    
    return 0;
}

Measured memory_bytes: 3124
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define REP(i,m,n) for(int i=(int)(m); i<(int)(n); i++)
#define rep(i,n) REP(i,0,n)
#define RREP(i,m,n) for(int i=(int)(m); i>=(int)(n); i--)
#define rrep(i,n) RREP(i,n-1,0)
#define REPL(i,m,n) for(ll i=(ll)(m); i<(ll)(n); i++)
#define repl(i,n) REPL(i,0,n)
#define all(v) v.begin(), v.end()
const int inf = 1e9+7;
const ll longinf = 1LL<<60;
const ll mod = 1e9+7;

vector<vector<int>> G;
int l;
int id;
void dfs(int tmp, int par, int depth) {
  if(par != -1 && G[tmp].size() == 1) {
    if(depth > l) {
      l = depth;
      id = tmp;
      return;
    }
  }
  for(int ne: G[tmp]) if(ne != par) dfs(ne, tmp, depth+1);
}
int main() {
  int N;
  cin >> N;
  G = vector<vector<int>>(N);
  rep(i, N-1) {
    int a, b;
    cin >> a >> b;
    --a; --b;
    G[a].push_back(b);
    G[b].push_back(a);
  }
  int root;
  rep(i, N) if(G[i].size() == 1) root = i;
  dfs(root, -1, 0);
  dfs(id, -1, 0);
  if(l%3==1) cout << "Second" << endl;
  else cout << "First" << endl;
  return 0;
}


Measured memory_bytes: 20608
#include<bits/stdc++.h>
 
using namespace std;
 
 
#define int long long
 

void solve()
{
    	   
 int n; cin>>n;
 int a[n]; for(int i=0;i<n;i++)cin>>a[i];
 
 int dp[n];
 dp[0]=0;
 dp[1]=abs(a[1]-a[0]);
 for(int i=2;i<n;i++)
 {
     dp[i]=min(dp[i-1]+abs(a[i]-a[i-1]),dp[i-2]+abs(a[i]-a[i-2]));
 }
 cout<<dp[n-1];
  
 
}
 
 
 signed main()
 {
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    
    
    
    
    int T; 
    T=1;
    //cin>>T;
    while(T--)
    {
          solve();
    }
    
    
        return 0;
	
}

Measured memory_bytes: 5192
#include <bits/stdc++.h>
using namespace std;
#define IOS ios::sync_with_stdio(0); cin.tie(nullptr); cout.tie(0)
#define endl "\n"
#define int long long
typedef vector<int> vi;
#define all(x) x.begin(),x.end()
#define FOR(i,a,b) for(int i=(a);i<=(b);i++)
#define FORD(i,a,b) for(int i=(a);i>=(b);i--)
#define pii              pair <int,int>
#define DEBUG(x) cerr << '>' << #x << ':' << x << endl;
typedef long long ll;
//#pragma comment(linker, "/STACK:667772160")
#define in_range(x, y, r, c) ((x >= 0 && x < r && y >= 0 && y < c))

const double eps=1e-9;
const int MOD=1e9+7;
const int N=2*1e5+30;
const int inf = 1e17+995;

template< class T > T gcd(T a, T b) { return (b != 0 ? gcd<T>(b, a%b) : a); }
template< class T > T lcm(T a, T b) { return (a / gcd<T>(a, b) * b); }
template <typename T> T exp(T b, T p){T x = 1;while(p){if(p&1)x=(x*b);b=(b*b);p=p>>1;}return x;}
inline int ones(int n) { int res = 0; while(n && ++res) n-=n&(-n); return res; }
inline bool EQ(double a, double b) { return fabs(a-b) < 1e-9; }
void boostIO() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
}
int dp[1111][1111],r,c;
char grid[1111][1111];
int go(int row,int col){
    if(row==r and col==c)
        return 1;
    if(grid[row][col]=='#'||row>r || col>c)
        return 0;
    int & ret=dp[row][col];
    if(ret!=-1)
        return ret;
    ret=0;
    //2 choice take the down direction or take the right direction
    //right
    ret+=go(row,col+1);
    ret%=MOD;
    // down
    ret+=go(row+1,col);
    ret%=MOD;
    return ret;
}
int32_t main() {
    boostIO();
cin>>r>>c;
    for (int i = 0; i < r; ++i) {
        for (int j = 0; j < c; ++j) {
            cin>>grid[i+1][j+1];
        }
    }
    memset(dp,-1, sizeof(dp));
    int ans=go(1,1);
    cout<<ans;
}

Measured memory_bytes: 11136
H, W, N = map(int, input().split())
from collections import defaultdict as dd
Grid =  dd(lambda:0) #3*3正方形を左上のマスで区別。値は正方形内の黒塗りの個数
Draw = lambda x,y:[(x-i,y-j) for i in range(3) for j in range(3) if 0<=x-i<H-2 and 0<=y-j<W-2] #塗りつぶしたマスを含む正方形の座標のリストを返す関数
for _ in range(N):
    a, b = map(int, input().split())
    for x,y in Draw(a-1,b-1): #Gridの更新
        Grid[x,y] += 1
Ans = [(H-2)*(W-2)-len(Grid) if i == 0 else sum(v==i for v in Grid.values()) for i in range(10)]         
for ans in Ans:
    print(ans)

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

#define rep(i, n) REP(i, 0, n)
#define repr(i, n) for (int i = (n); i >= 0; i--)
#define ALL(v) v.begin(), v.end()
#define MSG(a) cout << #a << " " << a << endl;
#define REP(i, x, n) for (int i = x; i < n; i++)
#define OP(m) cout << m << endl
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pii;

int main()
{
    ll n, x;
    cin >> n >> x;

    vector<ll> a(n), b(n);
    rep(i, n) cin >> a[i];

    if (a[0] > x)
        b[0] = x;
    else
        b[0] = a[0];
    rep(i, n - 1)
    {
        if (b[i] + a[i + 1] <= x)
            b[i + 1] = a[i + 1];
        else
            b[i + 1] = x - b[i];
    }

    ll sum = 0;
    rep(i, n) sum += a[i], sum -= b[i];

    OP(sum);

    return 0;
}

Measured memory_bytes: 1792
#include <bits/stdc++.h>
#define endl "\n"
using namespace std;
typedef long long int lli;
const lli N=1e6+5;
bool prime[N];

int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);
    lli i,j;
    memset(prime, true, sizeof(prime));
    
    for(i=2;i<N;i++)
    {
        if(prime[i])
        {
            for(j=2*i;j<N;j+=i)
            {
                prime[j]=false;
            }
        }
    }
    
    lli n;
    cin>>n;
    lli ans=0,div=1,cur;
    
    for(i=2;i<=sqrt(n);i++)
    {
        if(prime[i])
        {
            lli okk=0,num=n;
            while(num%i==0)
            {
                okk++;
                num/=i;
                div*=i;
            }
            
            cur=okk;
            for(j=1;;j++)
            {
                if(cur>=j)
                {
                    cur-=j;
                    ans++;
                }
                else break;
            }
        }
    }
    n/=div;
    if(n!=1) ans++;
    
    cout<<ans;
    return 0;
}

Measured memory_bytes: 4672
#include<iostream>
#include<cstdint>
template<typename T>
void fin(T const& t){ std::cout << t << std::endl; exit(0); }

int main() {
  std::cin.tie(0); std::ios::sync_with_stdio(false);
  int64_t X, Y; std::cin >> X >> Y;
  int ans = 1;
  while(X*2 <= Y){
    ++ans;
    X*=2;
  }
  fin(ans);
  return 0;
}


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

int main()
{
    int y, m, d;
    char c1, c2;;
    cin >> y >> c1 >> m >> c2 >> d;
    if ((y<2019) || y==2019 && m <= 4) cout << "Heisei" << endl;
    else cout << "TBD" << endl;
}

Measured memory_bytes: 256
Scanf.scanf "%d" (fun n ->
    let l = Array.init n (fun _ -> Scanf.scanf " %d" (fun l -> l)) in
    Array.sort compare l;
    let sum = Array.fold_left (+) 0 l - l.(n - 1) in
    print_endline @@ if sum > l.(n - 1) then "Yes" else "No"
)

Measured memory_bytes: 384
#include<bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using namespace std;
typedef long long ll;
const bool debug = false;
int main(){
    ll n,m,k;
    cin >> n >> m >> k;
    vector<ll> a(n),b(m);
    rep(i,n) cin >> a.at(i);
    rep(i,m) cin >> b.at(i);
    vector<ll> ta(n+1),tb(m+1);
    rep(i,n){
        ta.at(i+1) = ta.at(i) + a.at(i);
    }
    rep(i,m) {
        tb.at(i+1) = tb.at(i) + b.at(i);
    }
    if(debug){
        rep(i,n+1) cout << ta.at(i) << " ";
        cout << endl;
        rep(i,m+1) cout << tb.at(i) << " ";
        cout << endl;
    }
    int ans = 0;
    rep(i,n+1) {
        ll lk = k-ta.at(i);
        if(lk < 0) continue;
        int l=-1,r=m+1;
        while(l+1<r){
            int x = (l+r)/2;
            if(tb.at(x) <= lk) l = x;
            else r = x;
        }
        if(debug) cout << i << " " << l << endl;
        ans = max(ans, i+l);
    }
    cout << ans << endl;
    return 0;
}

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

template<class T> void vin(vector<T>& v, int n) {
    v.resize(n);
    for (int i = 0; i < n; ++i) {
        cin >> v[i];
    }
}

ll N, M;
ll x[1010], y[1010], z[1010];

int main() {
    cin >> N >> M;
    rep(i, N) {
        cin >> x[i] >> y[i] >> z[i];
    }
    ll ans = 0;
    rep(i, 2) rep(j, 2) rep(k, 2) {
        vector<ll> v(N);
        rep(a, N) {
            ll tmp = 0;
            tmp += x[a] * (i ? 1 : -1) + y[a] * (j ? 1 : -1) + z[a] * (k ? 1 : -1);
            v[a] = tmp;
        }
        sort(v.rbegin(), v.rend());
        ll tmp = 0;
        rep(i, M) tmp += v[i];
        ans = max(ans, tmp);
    }
    cout << ans << endl;
    return 0;
}


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


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

}

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

int main(void) {
	string s; cin >> s;
	int i, j;
	for (i = s.size() - 2; i >= 2; i -= 2) {
		bool a = true;
		for (j = 0; j < i / 2; j++) {
			if (s[j] != s[j + i/2]) {
				a = false;
			}
		}
		if (a) { cout << i << endl; break; }
	}

	return 0;
}



Measured memory_bytes: 256
#include <cstdio>
#include <cstring>

using namespace std;

const int N = 5e5 + 500;
const int ALP = 26;

int n, dp[N][ALP + 1], q;
int par[N][ALP];
char s[N];

int main(){
    scanf("%s", s);
    n = strlen(s);
    for(int i = 0;i <= ALP;i++)
        dp[n][i] = n + 1, dp[n + 1][i] = n + 1;
    dp[n][ALP] = n;
    for(int i = 0;i < ALP;i++){
        par[n][i] = n; par[n + 1][i] = n + 1;
    }
    for(int i = n - 1;i >= 0;i--){
        int k = s[i] - 'a';
        dp[i][k] = i + 1;
        for(int j = k + 1;j <= ALP;j++){
            dp[i][j] = dp[dp[i][j - 1]][j - 1];
        }
        for(int j = 0;j < k;j++){
            dp[i][j] = dp[dp[i][ALP]][j];
        }
        par[i][0] = dp[i][ALP];
        for(int j = 1;j < ALP;j++)
            par[i][j] = par[par[i][j - 1]][j - 1];
    }
    scanf("%d", &q);
    for(int i = 0;i < q;i++){
        int l, r; scanf("%d%d", &l, &r);
        l--, r--;
        for(int k = ALP - 1;k >= 0;k--){
            if(par[l][k] <= r + 1)
                l = par[l][k];
        }
        printf((l == r + 1) ? "Yes\n" : "No\n");
    }
}




Measured memory_bytes: 104576
n=int(input())
s=input()
#半分全列挙+bit全探索だ！！！！！！天才！！！！！！！！！
left={}
right={}
sl=s[:n]
sr=s[n:]
for i in range(1<<(n)):
  lr=lb=""
  rr=rb=""
  for j in range(n):
    if i&(1<<j):
      lr+=sl[j]
      rr+=sr[j]
    else:
      lb+=sl[j]
      rb+=sr[j]
  l=lr+","+lb
  r=(rr+","+rb)[::-1]
  if l in left:left[l]+=1
  else:left[l]=1
  if r in right:right[r]+=1
  else:right[r]=1
ans=0
for i in left:
  if i in right:ans+=left[i]*right[i]
print(ans)

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

int main() {
    int N, M; cin >> N >> M;
    int l = 1, r = 1+M;
    while (r - l > 0) {
        cout << l << ' ' << r << endl;
        l++; r--;
    }
    l = M+2; r = (M+2)+(M-1);
    while (r - l > 0) {
        cout << l << ' ' << r << endl;
        l++; r--;
    }
}

Measured memory_bytes: 3632
#include <iostream>
#include <string>
#include <sstream>
#include <algorithm>
#include <vector>
#include <utility>
#include <functional>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <deque>
#include <ctime>
  
using namespace std;
  
#define rep(i,n) REP(i,0,n)
#define REP(i,s,e) for(int i=(s); i<(int)(e); i++)
#define pb push_back
#define mp make_pair
#define all(r) (r).begin(),(r).end()
#define rall(r) (r).rbegin(),(r).rend()
#define fi first
#define se second
#define println(X) cout<<X<<endl;
#define DBG(X) cout<<#X<<" : "<<X<<endl;
  
typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vii;
typedef vector<ll> vl;
typedef vector<vl> vll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
 
const int INF = 1e9;
const ll LINF = 1e18;
const ll MOD = 1e9 + 7;
double EPS = 1e-8;
const double PI = acos(-1);

int main(){
	int n;
	while(cin>> n && n){
		map<char, int> m;
		int ans = -1;
		char ans_c;
		rep(i, n){
			char c;
			cin>>c;
			if(ans != -1) continue;
			m[c]++;
			auto check = [&] {
				priority_queue<int> q;
				q.push(0);
				for(auto& p:m){
					q.push(p.se);
				}
				int a = q.top();	q.pop();
				int b = q.top();	q.pop();
				for(auto& p:m){
					if(p.se == a) ans_c = p.fi;
				}
				return a > b + n - i -1;
			};
			if(check()){
				ans = i + 1;
				//ans_c = c;
			}
		}
		if(ans == -1) cout<<"TIE" << endl;
		else cout << ans_c << " " << ans << endl;
	}
}

Measured memory_bytes: 3164
use proconio::input;
use proconio::marker::Chars;

pub fn make_ascii_lowercase_chars() -> Vec<char> {
    let base = 0x61;
    make_chars(base..base + 26)
}
pub fn make_ascii_uppercase_chars() -> Vec<char> {
    let base = 0x41;
    make_chars(base..base + 26)
}
fn make_chars(range: std::ops::Range<u8>) -> Vec<char> {
    range.into_iter().map(char::from).collect::<Vec<_>>()
}
pub fn rotate_ascii_lowercase_char(ch: char, n: isize) -> char {
    assert!(ch.is_ascii_lowercase());
    rotate_char(ch, n, 0x61, 26)
}
pub fn rotate_ascii_uppercase_char(ch: char, n: isize) -> char {
    assert!(ch.is_ascii_uppercase());
    rotate_char(ch, n, 0x41, 26)
}
fn rotate_char(ch: char, n: isize, base: u8, m: u8) -> char {
    let m = m as isize;
    let ch_pos = ch as u8 - base;
    let offset = if n >= 0 {
        (ch_pos as isize + n) % m
    } else {
        (m - (ch_pos as isize - n.abs()).abs() % m) % m
    } as u8;
    char::from(base + offset)
}

fn main() {
    input! {
        mut s: Chars,
        k: usize
    };

    let mut rest = k;
    for i in 0..s.len() {
        if rest == 0 {
            break;
        }
        let ch = s[i];
        let pos = ch as usize - 0x61;
        if pos == 0 {
            continue;
        }
        let c = 26 - pos;
        if c <= rest {
            s[i] = 'a';
            rest -= c;
        }
    }
    if rest > 0 {
        let i = s.len() - 1;
        s[i] = rotate_ascii_lowercase_char(s[i], rest as isize);
    }
    let res = s.into_iter().collect::<String>();
    println!("{}", res);
}


Measured memory_bytes: 2568
#include <bits/stdc++.h>
#define ALL(v) (v).begin(), (v).end()
#define INF 1e9
#define pb push_back
#define REP(i,n) for(int i=0; i<(n); i++)
#define REP2(i,x,n) for(int i=x; i<(n); i++)
using namespace std;
typedef long long ll;
typedef long double ld;
using pil = pair<ll, ll>;
template<class T>using numr=std::numeric_limits<T>;
#define MOD 1000000007
#define MOD2 998244353
const double PI=3.14159265358979323846;

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    int r;
    
    cin >> r;
    float ans = 2 * r * PI;
    cout << ans <<endl;

}

Measured memory_bytes: 3764
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <iostream>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <stack>
#include <queue>
#define rep(i,l,r) for(int i=(l);i<=(r);++i)
#define per(i,r,l) for(int i=(r);i>=(l);--i)
using namespace std;
const int maxn=5e4+10,N=1e6+10;
int P,Q,n,m,g,f[maxn*6],u[maxn],v[maxn],w[maxn],s,t,x,ans,S,T;
bool PSC[2][N];
int gfa(int x){return (f[x]^x)?(f[x]=gfa(f[x])):x;}
void merge(int u,int v){
    int fx=gfa(u),fy=gfa(v);
    if(fx^fy) f[fx]=fy;
    else return;
}
int main(){
    scanf("%d%d%d%d",&n,&m,&Q,&P);g=P;
    rep(i,1,n*6) f[i]=i;
    rep(i,1,m){
        scanf("%d%d%d",&u[i],&v[i],&w[i]);
        if(i>1) g=__gcd(g,abs(w[i]-w[i-1]));
    }
    P=__gcd(P,3*g);t=w[1]%g;
    //printf("%d\n",P);
    rep(i,1,m){
        int W=(w[i]-t)/g%3;
        rep(j,0,2){
            merge((u[i]-1)*6+j*2+1,(v[i]-1)*6+(2*j+W)%3*2+2);
            merge((u[i]-1)*6+j*2+2,(v[i]-1)*6+(2*j+W)%3*2+1);
            merge((v[i]-1)*6+j*2+1,(u[i]-1)*6+(2*j+W)%3*2+2);
            merge((v[i]-1)*6+j*2+2,(u[i]-1)*6+(2*j+W)%3*2+1);
        }
    }
    for(int i=0,j=t;i<P*2;++i,j=j*2%P) PSC[i&1][j]=1;
    while(Q--){
        scanf("%d%d%d",&S,&T,&x);x%=P;ans=0;
        rep(i,0,2) rep(j,0,1) if(gfa(6*(T-1)+1)==gfa(6*(S-1)+i*2+j+1)) 
            ans|=PSC[j][(x+t+(3-i)*g)%P];
        puts(ans?"YES":"NO");
    }
    return 0;
}

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

#define rep(i, n) for(int i = 0; i < (n); ++i)
#define For(i, a, b) for(int i = (a); i < (b); ++i)
#define all(x) (x).begin(),(x).end()
typedef long long lint;
typedef vector<int> vint;
typedef vector<long long> vlint;
typedef vector<string> vstr;
typedef vector<char> vchar;
typedef vector<vector<long long>> vlint2;


lint gcd(lint x, lint y){
    if (x == 0) return y;
    return gcd(y % x, x);
};

lint lcm(lint x, lint y){
    return x * y / gcd(x, y);
};

lint powint(lint x, lint y){
    int ret = 1;
    for (int i=0; i < y; i++) ret *= x;
    return ret;
};

lint powmod(lint x, lint y, lint m){
    if (y == 0) return 1;
    return ((powint(powmod(x, y>>1, m), 2) % m) * powint(x, (y & 1))) % m;
};

lint comb(lint n, lint r, lint m){
    if (n < r) return 0;

    if (n-r < r) r = n-r;
    int ret = 1; int d = 1;
    for (int i = n-r+1; i < n+1; i++) ret = (ret * i) % m;
    for (int i = 1; i < r+1; i++) d = (d * i) % m;
    ret *= powmod(d, m-2, m);
    return ret % m;
};

lint min_arr(vector<lint> x){
    lint y = x[0];
    rep(i, x.size()){
        y = min(y, x[i]);
    }
    return y;
};

int mod = 1000000007;
vector<int> dx = {1, 0, 0, -1, 1, 1, -1, -1};
vector<int> dy = {0, -1, 1, 0, 1, -1, 1, -1};

map<char, long long> counter(string s){
    map<char, long long> count;
    rep(i, s.size()){
        count[s[i]] ++;
    }
    return count;
};

int main() {
    lint n, k;
    cin >> n >> k;
    lint r = n/k;
    lint ans = n - r * k;
    lint ans1 = abs(n - (r + 1) * k);
    cout << min(ans, ans1) << endl;



}



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

n = int(input())
a = list(map(int, input().split()))
b = [0]*n
for i in range(n, 0, -1):
    temp = 0
    if n//i == 1:
        b[i-1] = a[i-1]
    else:
        for j in range(2, n+1):


            if i*j > n:
                break
            temp += b[i*j-1]
        if a[i-1] == 1:
            b[i-1] = 1 - temp%2
        else:
            b[i-1] = temp%2
print(sum(b))
for i in range(n):
    if b[i] == 1:
        print(i+1, "", end="")
print()

Measured memory_bytes: 7364
/*
 * cpp_filepath
 */

// C++ 14
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <cstring> // memset
#include <cassert>
using namespace std;
#define ll long long
#define loop(__x, __start, __end) for(int __x = __start; __x < __end; __x++)
template <class T> ostream & operator << (ostream & out, vector<T> const & v) {
  for (auto &&a: v) out << a << " "; out << endl; return out;
}
template <class T> void dump(T &a) { cout << a << endl; }
void solve();
int main() { solve(); return 0; }


void solve() {
  int a, b, c, d;
  cin >> a >> b >> c >> d;
  cout << min(a, b) + min(c, d) << endl;
}


Measured memory_bytes: 256