akhauriyash/Code-Regression huggingface dataset:
import sys
input = sys.stdin.readline
n,m = map(int, input().split())
es = [[] for _ in range(n)]
for i in range(m):
    a,b=map(int, input().split())
    es[a].append(b)

# strongly connected component
def scc(es): # DFSを2回行う
    n_node = len(es)
    esinv = [[] for _ in range(n_node)]
    for i in range(n_node):
        for e in es[i]:
            esinv[e].append(i)
    used = [False]*n_node
    dim = [len(es[i]) for i in range(n_node)]
    order = []
    for st in range(n_node): # DFS 1回目, postorderを求める
        if not used[st]:
            stack = [(st, 0)] # [(index, 既に辿ったエッジの数)]
            while stack:
                now, i = stack.pop() 
                if not i and used[now]:
                    continue
                else:
                    used[now] = True
                    if i < dim[now]: # nowから延びるエッジを辿りきってない
                        stack.append((now,i+1))
                        stack.append((es[now][i],0))
                    else: # nowから延びる全てのエッジを辿った
                        order.append(now)
    res = [-1]*n_node # 各ノードが所属するグループのidを保存
    used = [False]*n_node 
    cnt = -1 # idカウンター
    for st in order[::-1]:  # DFS 2回目, postorderの逆順から
        if not used[st]:    # 逆向き矢印を辿って通れるノードを記録していく
            cnt += 1
            stack = [st]
            res[st] = cnt
            used[st] = True
            while stack:
                now = stack.pop()
                for e in esinv[now]:
                    if not used[e]:
                        used[e] = True
                        res[e] = cnt
                        stack.append(e)
    n_group = cnt+1
    components = [[] for _ in range(n_group)]
    for i in range(n_node):
        components[res[i]].append(i)
    return res, components

res,compo= scc(es)
# print(res,compo)

row=max(res)+1

print(row)
for i in range(row):
    length = len(compo[i])
    print(length, *compo[i])

Measured memory_bytes: 250252
#include <iostream>
#include <algorithm>
#include <string>

using namespace std;

#define KIT 4

int main() {
	int n, mmm, i, j;
	int ad, su;
	int max;
	char mas;

	cin >> mmm;
	while (1) {
		cin >> mas;
		switch (mas) {
		case '+':
			cin >> n;
			mmm += n;
			break;
		case '-':
			cin >> n;
			mmm -= n;
			break;
		case '*':
			cin >> n;
			mmm *= n;
			break;
		case '/':
			cin >> n;
			mmm /= n;
			break;
		case '=':
			cout << mmm << endl;
			return 0;
			break;
		default:
			cout << "error input " << mas << endl;
			break;
		}
	}
	return 0;
}




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

int main(){
  string s;
  cin >> s;
  int n = sz(s);
  set<char> st;
  rep(i,n) st.insert(s[i]);
  if (n != 26) {
    for (char c = 'a'; c <= 'z'; c++) {
      if (!st.count(c)) {
        s += c;
        break;
      }
    }
    cout << s << endl;
  } else {
    vector<char> v;
    rep(i,n) v.push_back(s[i]);

    if (next_permutation(v.begin(), v.end())) {
      string res = "";
      rep(i,sz(v)) {
        res += v[i];
        if (v[i] != s[i]) break;
      }
      cout << res << endl;
    } else {
      cout << -1 << endl;
    } 
  }
  return 0;
} 

Measured memory_bytes: 256
x1,y1,x2,y2 = map(int,input().split())
x3 = y1+x2-y2
y3 =-x1+x2+y2
x4 = x1+y1-y2
y4 =-x1+y1+x2
print(x3,y3,x4,y4) 

Measured memory_bytes: 3060
#include<cstdio>
#include<iostream>
#include<cmath>
#include<algorithm>
#include<queue>
#include<vector>
#include<map>
#include<string>
using namespace std;
#define rep2(x,from,to) for(long long x=from;x<to;x++)
#define rep(x,to) rep2(x,0,to)
long long h;
long long n;
long long aa;
long long a;
int main()
{
    cin>>h;cin>>n;
    rep(i,n)
    {
        cin>>a;
        h-=a;
    }
    if(h>0)cout<<"No"<<endl;
    else cout<<"Yes"<<endl;
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
  int n,x;
  cin>>n>>x;
  vector<int> a(n);
  for(int i=0; i<n; i++){
    cin>>a.at(i);
  }
  sort(a.begin(),a.end());
  int ans=0;
  for(int i=0; i<n; i++){
    if(i==n-1){
      if(a.at(i)==x) ans++;
      else break;
    }
   else if(x>=a.at(i)) {
      x=x-a.at(i);
      ans++;
    }
  }
  cout<<ans<<endl;
}

Measured memory_bytes: 3648
#include <bits/stdc++.h>
using namespace std;
#define FOR(i, n) for(int i=0; i<int(n); i++)
#define RNG(i, f, t) for(int i=int(f); i<=int(t); i++)
#define REV(i, f, t) for(int i=int(f); i>=int(t); --i)
#define ALL(v) (v).begin(), (v).end()
bool RELAXED = false;
template<int,typename T> struct MINMAX{ T val; MINMAX(T val) : val(val) {} };
template<typename T> MINMAX<1,T> MAX(T val) { return MINMAX<1,T>(val); };
template<typename T> MINMAX<2,T> MIN(T val) { return MINMAX<2,T>(val); };
template<typename T, typename U> inline T& operator|=(T &lhs, MINMAX<1,U> rhs) { return lhs = (rhs.val > lhs ? (RELAXED=true,rhs.val) : (RELAXED=false,lhs)); }
template<typename T, typename U> inline T& operator|=(T &lhs, MINMAX<2,U> rhs) { return lhs = (rhs.val < lhs ? (RELAXED=true,rhs.val) : (RELAXED=false,lhs)); }
template<typename T> inline vector<T> readVector(int n) { vector<T> vec(n); FOR(i,n) cin>>vec[i]; return vec; }
template<typename T> void EXIT(T answer) { cout<<answer<<endl; exit(0); }
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef vector<pii> vpii;
typedef signed long long int ll;

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

    ll n; cin>>n;
    cout<<n*n<<endl;
    return 0;
}




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

int main(void) {
    int N;
    int A;

    cin >> N;

    vector <int> X(N,0);

    for(int i=1;i<N;i++) {
        cin >> A;
        X[A-1]++;
    }

    for(int i:X) {
        cout << i << "\n";
    }
    
    return 0;
}


Measured memory_bytes: 4048
#define HAVE_STRUCT_TIMESPEC
#include<bits/stdc++.h>
using namespace std;
int main(){
    long long a,b,x;
    cin>>a>>b>>x;
    if(2*x>=a*a*b){
        double deg=(2.0*a*a*b-2.0*x)/(1.0*a*a*a);
        printf("%.10f",180.0/acos(-1)*atan(deg));
    }
    else{
        double deg=1.0/(2.0*x/(1.0*a*b*b));
        printf("%.10f",180.0/acos(-1)*atan(deg));
    }
    return 0;//dfsdf
}


Measured memory_bytes: 256
/**
 * code generated by JHelper
 * More info: https://github.com/AlexeyDmitriev/JHelper
 * @author
 */

#include <iostream>
#include <fstream>

#include <bits/stdc++.h>
using namespace std;

typedef long long ll;
#define tr(container, it) \
        for (auto it = container.begin(); it != container.end(); it++)
#define scontains(c, x) ((c).find(x) != (c).end())   //O(log n)
#define contains(c, x) (find((c).begin(),(c).end(),x) != (c).end()) //O(n)
#define pll pair<ll,ll>
#define pii pair<int,int>
#define mll map<ll,ll>
#define intv(x, a, b)((x)>=a && (x)<=b)
#define  rep(i, begin, end) for (__typeof(end) i = (begin) - ((begin) > (end)); i != (end) - ((begin) > (end)); i += 1 - 2 * ((begin) > (end)))
#define  _for(i, end) for (__typeof(end) i = 0; i < (end); i += 1)
#define all(x) (x).begin(),(x).end()
//#define len(array)  (sizeof(array)/sizeof((array)[0]))
#define what_is(x) cerr << #x << " is " << x << endl;
#define error(args...) { string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); stringstream _ss(_s); istream_iterator<string> _it(_ss); err(_it, args); }
#define mod(x, m) ((((x) % (m)) + (m)) % (m))
const double PI = 2 * acos(.0);
const int INF = 0x3f3f3f3f;
const ll LLINF = 1000000000000000005LL;;
const ll MOD = (ll) (1e9) + 7;
void _mod(ll &x){x = mod(x, MOD);}
//const ll MOD = (ll) 998244353 ;
const double EPS = 1e-10;

template<typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val) {
    std::fill((T *) array, (T *) (array + N), val);
}


//#define int ll

class BMedianPyramidEasy {
public:
        int N, x;
        set<int > s;
void solve(std::istream& cin, std::ostream& cout) {
    cin >> N >> x;
    _for(i, 2 * N - 1)s.insert(i + 1);
    if (intv(x, 2, 2 * N - 2)) {

        cout << "Yes" << endl;
        if (N == 2)cout << "1\n2\n3\n";
        else {
            if (x < N) {
                _for(i, 4)s.erase(x - 1 + i);
                auto it = s.begin();
                _for(i, N - 2)cout << *it << endl, it++;
                cout << x + 1 << endl << x << endl << x - 1 << endl << x + 2 << endl;
                _for(i, N - 3)cout << *it << endl, it++;
            } else {
                _for(i, 4)s.erase(x + 1 - i);
                auto it = s.begin();
                _for(i, N - 2)cout << *it << endl, it++;
                cout << x - 2 << endl << x << endl << x + 1 << endl << x - 1 << endl;
                _for(i, N - 3)cout << *it << endl, it++;
            }
        }

    }
    else cout << "No\n";
}
};


#undef int
int main() {
	BMedianPyramidEasy solver;
	std::istream& in(std::cin);
	std::ostream& out(std::cout);
	solver.solve(in, out);
	return 0;
}


Measured memory_bytes: 10880
#include<bits/stdc++.h>
using namespace std;
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    
    int n,x,t;
    cin>>n>>x>>t;
    int ans=0;
    while(n>0)
    {
        n-=x;
        ans+=t;
    }
    cout<<ans<<'\n';
    
    
    
    
    
    return 0;
}

Measured memory_bytes: 3648
import java.lang.Integer.min

fun main (args:Array<String>){
    val N = readLine()!!.toInt()
    var S = readLine()!!

    for (s in S) {
        var plusInt = N
        if (s.toInt() + N > 'Z'.toInt()) {
            plusInt = ((s.toInt() + N) - 'Z'.toInt() - (s.toInt() - 'A'.toInt() + 1))
        }
        print((s.toInt() + plusInt).toChar())
    }
}


Measured memory_bytes: 37272
k = int(input())
if k % 7 == 0:
    L = 9 * k // 7
else:
    L = 9 * k
out = -1
s = 10
for i in range(L):
    if s % L == 1:
        out = i + 1
        break
    else:
        s = (s % L) * 10
print(out)


Measured memory_bytes: 9088
#include <iostream>
#define llint long long
#define mod 1000000007

using namespace std;

llint n, Q;
llint a[3005];
llint dp[3005][3005];
llint inv;

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

int main(void)
{
	cin >> n >> Q;
	for(int i = 1; i <= n; i++) cin >> a[i];
	inv = modpow(2, mod-2);
	
	for(int i = 1; i <= n; i++){
		for(int j = 1; j <= n; j++){
			if(a[i] > a[j]) dp[i][j] = 1;
		}
	}
	
	llint l, r;
	for(int q = 0; q < Q; q++){
		cin >> l >> r;
		if(l > r) swap(l, r);
		dp[l][r] = dp[r][l] = (dp[l][r]+dp[r][l])%mod*inv%mod;
		for(int i = 1; i <= n; i++){
			if(i == l || i == r) continue;
			dp[l][i] = dp[r][i] = (dp[l][i]+dp[r][i])%mod*inv%mod;
			dp[i][l] = dp[i][r] = (dp[i][l]+dp[i][r])%mod*inv%mod;
		}
	}
	
	llint ans = 0;
	for(int i = 1; i <= n; i++){
		for(int j = 1; j <= n; j++){
			if(i >= j) continue;
			ans += dp[i][j], ans %= mod;
		}
	}
	ans *= modpow(2, Q), ans %= mod;
	cout << ans << endl;
	
	return 0;
}

Measured memory_bytes: 70656
#include<iostream>
using namespace std;
char S[200]; int n;
long long dp[220][220];
int main() {
	cin >> n; dp[0][0] = 1;
	for (int i = 0; i < n; i++)cin >> S[i];
	for (int i = 0; i < n; i++) {
		for (int j = 0; j < n; j++) {
			if (dp[i][j] == 0)continue;
			if (S[i] == '-') {
				dp[i + 1][j] += dp[i][j];
			}
			if (S[i] == 'D') {
				if (j >= 1)dp[i + 1][j - 1] += dp[i][j] * j*j;
				dp[i + 1][j] += dp[i][j] * j;
			}
			if (S[i] == 'U') {
				dp[i + 1][j] += dp[i][j] * j;
				dp[i + 1][j + 1] += dp[i][j];
			}
			dp[i + 1][j] %= 1000000007;
			dp[i + 1][j + 1] %= 1000000007;
			dp[i + 1][j - 1] %= 1000000007;
		}
	}
	cout << dp[n][0] << endl;
	return 0;
}

Measured memory_bytes: 3448
n = int(input())
card = {}
for _ in range(n):
    t = input()
    if t not in card:
        card[t] = 1
    else:
        card[t] += 1
m = int(input())
for _ in range(m):
    t = input()
    if t not in card:
        card[t] = 1
    else:
        card[t] -= 1

ans = 0

for i in card.values():
    if i > ans:
        ans = i

print(ans)


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

using namespace std;
typedef long long int ll;
typedef pair <ll,ll> P;
#define REP(i, n) for(ll i = 0LL; i < (ll)(n); i++)
#define REPR(i, n) for(ll i = n-1; i >= 0LL; i--)
#define FOR(i, n, m) for(ll i = n; i < (ll)(m); i++)
#define PRINT(x) cout << x << endl
#define ALL(v) v.begin(), v.end()
#define INF (ll)1e18
#define INFD 1e18
#define PI 3.14159265358979
#define MOD 1000000007
#define vl vector<ll>

vector<ll> dx = {-1, 1, 0, 0};
vector<ll> dy = {0, 0, 1, -1};

ll gcd(ll a, ll b) { return b ? gcd(b,a%b) : a;}
ll lcm(ll a, ll b) { return a / gcd(a, b) * b; }


int main()
{
	ll N;
	cin >> N;

	vector<ll> C(N);
	REP(i, N) cin >> C[i];

	vector<ll> c;
	c.push_back(0);
	c.push_back(C[0]);
	REP(i, N-1) {
		if (C[i] != C[i+1]) {
			c.push_back(C[i+1]);
		}
	}
	vector<ll> dp(c.size()+1);
	dp[1] = 1;
	vector<ll> pre(1000000);
	pre[c[1]] = 1;
	// cout << "dp" << endl;
	// REP(j, dp.size()) cout << dp[j] << " ";
	// cout << endl;
	// cout << "pre" << endl;
	// REP(j, 10) cout << pre[j] << " ";
	// cout << endl;
	FOR(i, 2, dp.size()) {
		dp[i] = dp[i-1] + dp[pre[c[i]]];
		dp[i] %= MOD;
		pre[c[i]] = i;
		// cout << "dp" << endl;
		// REP(j, dp.size()) cout << dp[j] << " ";
		// cout << endl;
		// cout << "pre" << endl;
		// REP(j, 10) cout << pre[j] << " ";
		// cout << endl;
	}
	PRINT(dp.back());
	return 0;
}


Measured memory_bytes: 12912
#include<stdio.h>
int main(void){
  int x,i,n;
  scanf("%d",&x);
  for(i=1;i<=x;i++){
    i=i++;
    n=i;
    if(i%3==0){
      printf(" %d",i);
    }else if(i>30&&i<40){
      printf(" %d",i);
    }else if(i%10==3){
      printf(" %d",i);
    }else if(i>300&&i<400){
      printf(" %d",i);
    }else if(i%100==3){
      printf(" %d",i);
    }else if((i/10)%10==3){
      printf(" %d",i);
    }else if(i>3000&&i<4000){
      printf(" %d",i);
    }else if((i/10)%100==3){
      printf(" %d",i);
    }else if((i/100)%10==3){
      printf(" %d",i);
    }else if(i%1000==3){
      printf(" %d",i);
    }
  }
  puts("");
  return 0;
}



Measured memory_bytes: 2104
import java.io.InputStream;
import java.io.PrintStream;
import java.util.Arrays;
import java.util.Scanner;

public class Main {
	InputStream in = System.in;
	PrintStream out = System.out;

	public void _main(String[] args) {
		Scanner sc = new Scanner(in);

		int N = sc.nextInt();
		int[] H = nextIntArray(sc, N);

		sc.close();

		int[] a = new int[N];

		a[N - 1] = 0;
		for (int i = N - 2; i >= 0; i--) {
			if (H[i] >= H[i + 1]) {
				a[i] = a[i + 1] + 1;
			} else {
				a[i] = 0;
			}
		}

		out.println(max(a));

	}

	public static void main(String[] args) {
		new Main()._main(args);
	}

	@SuppressWarnings("unused")
	private int max(int[] arr) {
		if (arr == null || arr.length == 0) {
			throw new IllegalArgumentException(Arrays.toString(arr));
		}

		int candidate = arr[0];
		for (int i = 1; i < arr.length; i++) {
			candidate = candidate > arr[i] ? candidate : arr[i];
		}
		return candidate;
	}

	@SuppressWarnings("unused")
	private int[] nextIntArray(Scanner sc, int n) {
		int[] result = new int[n];
		for (int i = 0; i < n; i++) {
			result[i] = sc.nextInt();
		}
		return result;
	}
}


Measured memory_bytes: 50796
#include<bits/stdc++.h>
#define l(i,a,n)for(int i=a;i<n;i++)
#define pb push_back
#define in insert
#define mp make_pair
#define lw(v) sort(v.begin(),v.end());
#define hi(v) sort(v.begin(),v.end(),greater<long long>());
#define all(v) v.begin(),v.end()
#define filein freopen ("input.txt", "r", stdin)
#define fileout freopen ("output.txt", "w", stdout)
using namespace std;
int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
    long long t,r=1,r1=0,r2=0,k=0,a,b,c=1,m,d=0,n,e,f,x=0,g,p=0,q=0,y=0,z=0;
    vector<long long>v;
    vector<long long>u;
    set<long long>s;
    std::vector<int>::iterator it;
    string  s1,s2,s3,s4;
   cin>>n;
   l(i,1,10)
   {
       l(j,1,10)
       {
           if(i*j==n)
           {
               cout<<"Yes";
               return 0;
           }
       }
   }
   cout<<"No"<<endl;
}








Measured memory_bytes: 3652
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cmath>

using namespace std;
typedef long long ll;

int main()
{
    int a,b;
    cin >> a >> b;
    if(abs(a-b)>1){
        cout << max(a,b)*2-1;
    }else
        cout << a+b;

    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define int long long int
#define until(x) while(!(x))
#define unless(x) if(!(x))
#define all(x) (x).begin(),(x).end()

int p[9];
int q[9];
int32_t main(){
	int a,b;
	int n;
	cin>>n;
	for(int i=1;i<=n;i++){
		cin>>p[i];
	}
	for(int i=1;i<=n;i++){
		cin>>q[i];
	}
	int ar[9];
	for(int i=1;i<=n;i++){
		ar[i]=i;
	}
	int i=0;
	do{
		i++;
		if(equal(ar+1,ar+n+1,p+1)){
			a=i;
		}
		if(equal(ar+1,ar+n+1,q+1)){
			b=i;
		}
	}while(next_permutation(ar+1,ar+n+1));
	cout<<abs(a-b);
}


Measured memory_bytes: 256
#include <vector>
#include <list>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <cstring>

using namespace std;

#define INF 2140000000
#define MOD 1000000007

int main() {
	int n, q, k = 0;
	string s;

	cin >> n >> q >> s;

	vector<int> count(n+1,0);

	for (int i = 1; i < s.size(); ++i) {
		if (s[i - 1] == 'A' && s[i] == 'C')	{
			k++;
			count[i + 1] = k;
		}
		else {
			count[i + 1] = count[i];
		}
	}

	int l, r;

	while (q--) {
		cin >> l >> r;
		cout << count[r] - count[l] << endl;
	}


	return 0;
}

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

#include <iostream>
#include <bits/stdc++.h>
using namespace std;

typedef long long LL;
const LL A_MAX = 1e9;

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    LL N, counter = 0;
    cin >> N;
    set<LL> A;
    LL input;

    for (int i=0;i<N;i++)
    {
        set<LL>::iterator it;
        cin >> input;
        it = A.find(input);
        if (it!=A.end())
        {
            A.erase(it);
            counter --;
        } else{
            A.insert(input);
            counter++;
        }
    }
    cout << counter;
    cout.flush();
    return 0;
}


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


int main() {
   int a, b, c;
   int x;
   cin >> a >> b >> c >> x;
   
   int ans =0;
   
   for (int i=0; i<=a; i++) {
       int sum = 0;
       for (int j=0; j<=b; j++) {
           for (int k=0; k<=c; k++) {
              sum = 500 * i + 100 *j + 50 * k;
              if (sum == x) ans++;
           }
       }
   }
   
   cout << ans << endl;
    
}

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

int main() {
    int N,K;
    cin>>N>>K;
    vector<int>l(N);
    for(int i=0;i<N;i++){
        cin>>l.at(i);
    }
    int max=0;
    int longsum=0;
    int num=0;
    for(int j=0;j<K;j++){
        for(int k=0;k<N;k++){
            if(l.at(k)>=max){
                max=l.at(k);
                num=k;
            }    
        }
            l.at(num)=0;
            longsum+=max;
            max=0;
    }
    cout<<longsum;
return 0;}
/*
g++ code.cpp
./a.out
*/

Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<string.h>
#include<stdio.h>
#include<algorithm>
using namespace std;
int a[200100],b[200500];
long long minu(int x,int y)
{
	long long z=(long long)x-y;
	if (z<0) return -z;return z;
}
int main()
{
	int n,i;
	scanf("%d",&n);
	for (i=1;i<=n;i++)
	{
		scanf("%d",&a[i]);
		b[i]=a[i]-i;
	}
	sort(b+1,b+1+n);
	int tmp=(n+1)/2,minnum=b[tmp];
	long long ans=0;
	for (i=1;i<=n;i++)
	    ans+=abs(minnum-b[i]);
	//cout << minnum << endl;
	cout << ans;
	return 0;
}

Measured memory_bytes: 1792
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>

using namespace std;

typedef long long int ll;
typedef pair<ll, ll> P;
#define INF 10000000000000
#define rep(i, n) for(ll i = 0; i < (ll)(n); i++)
#define rep1(i, n) for(ll i = 1; i < (ll)(n); i++)
#define repN_1(i, n) for(ll i = 0; i < (ll)(n - 1); i++)
#define repM(i, n) for(ll i = (ll)(n - 1); i >= 0; i--)
#define repM1(i, n) for(ll i = (ll)(n - 1); i > 0; i--)
template<class T>bool chmax(T& a, const T& b) { if (a < b) { a = b; return 1; } return 0; }
template<class T>bool chmin(T& a, const T& b) { if (b < a) { a = b; return 1; } return 0; }

int main()
{
	cout << fixed << setprecision(18);

	ll h, w, k;
	cin >> h >> w >> k;

	char s[305][305];
	ll a[305][305];

	memset(a, 0, sizeof(a));

	rep(i, h) {
		rep(j, w)
			cin >> s[i][j];
	}

	ll count = 1;


	rep(i, h) {
		ll start = 0;
		bool f = false;
		rep(j, w) {
			if (s[i][j] == '#') {
				if (f) {
					for (int k = start; k < j; k++) {
						a[i][k] = count;
						ll m = i - 1;
						while (m >= 0) {
							if (a[m][k] == 0)
								a[m][k] = count;
							else
								break;
							m--;
						}
					}
					start = j;
					count++;
				}
				else
					f = true;
			}
		}
		if (f) {
			for (int k = start; k < w; k++) {
				a[i][k] = count;
				ll m = i - 1;
				while (m >= 0) {
					if (a[m][k] == 0)
						a[m][k] = count;
					else
						break;
					m--;
				}
			}
			count++;
		}
		if (!f && i > 0) {
			rep(j, w) {
				a[i][j] = a[i - 1][j];
			}
		}
	}

	rep(i, h) {
		rep(j, w) {
			cout << a[i][j];
			if (j != w - 1)
				cout << " ";
		}
		cout << endl;
	}

	return 0;
}

Measured memory_bytes: 1536
#include<bits/stdc++.h>
#define INF 2000000000
#define MOD 1000000007
#define EPS (1e-10)

using namespace std;


int main(int argc, char *argv[]) {

	string S; cin >> S;

	int stone_cnt = 0;
	long ans = 0;
	for (int i = 0; i < S.size(); i++) {
		if (S[i] == 'B') {
			stone_cnt++;	
		}
	}

	for (int i = 0; i < S.size(); i++) {
		if (S[i] == 'B') {
			ans += S.size() - stone_cnt + 1 - i-1;
			stone_cnt--;
		}
	}
	cout << ans << endl;
	
	return 0;
}


Measured memory_bytes: 3688
#include <bits/stdc++.h>
#include <cstring>
#include <limits>
using namespace std;
#define ll long long int
#define X first
#define Y second
#define fw(i, start, end) for (ll i = start; i < end; ++i)
#define fe(i, start, end) for (ll i = start; i <= end; ++i)
#define L(T)  \
    ll T;     \
    cin >> T; \
    while (T--)
#define FASTIO                   \
    ios::sync_with_stdio(false); \
    cin.tie(nullptr);            \
    cout.tie(nullptr);
#define endl '\n'

ll dp[3004][3004];
int a[3004];
ll solve(ll i, ll j)
{
    if (dp[i][j] != -1)
        return dp[i][j];
    if (i == j)
    {
        return dp[i][j] = a[i];
    }
    dp[i][j] = 0;
    dp[i][j] = max(a[i] - solve(i + 1, j), a[j] - solve(i, j - 1));
    return dp[i][j];
}
int main()
{
    FASTIO
    ll n;
    cin >> n;
    // ll s = 0;
    fw(i, 1, n + 1)
    {
        cin >> a[i];
        // s += a[i];
    }
    memset(dp, -1, sizeof dp);
    ll ans = solve(1, n);
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 74268
import java.util.Scanner


object Main {


  case class Bulb(k:Int, s:IndexedSeq[Int], p:Int)

  def read() = {
    val sc = new Scanner(System.in)
    val n, m = sc.nextInt()
    //0-origin
    val temp = IndexedSeq.fill(m){
      val k = sc.nextInt()
      val ss = IndexedSeq.fill(k)(sc.nextInt()-1)
      (k, ss)
    }
    val ps = IndexedSeq.fill(m)(sc.nextInt())
    val bulbs = IndexedSeq.tabulate(m)(i=> Bulb(temp(i)._1, temp(i)._2, ps(i)))
    (n, bulbs)
  }

  def solve(n:Int, bulbs:IndexedSeq[Bulb]): Int = {
    // スイッチ
    (for(pattern <- 0 until 1<<n)yield{
      val patternList = (0 until n).map(i => (pattern >> i) & 1)

      bulbs.forall(bulb =>
        bulb.s.map(s0 => patternList(s0)).sum %2 == bulb.p
        //patternList.map(i=> bulb.s(i)).sum %2 == bulb.p
      )
    }).count(p=>p)
  }

  def main(args: Array[String]): Unit = {
    val (n,bulbs) = read()
    println(solve(n, bulbs))
  }
}

Measured memory_bytes: 30364
#include<bits/stdc++.h>
using namespace std;
#define rep(i,x,y) for(int i=x;i<y;i++)
#define range(a) (a).begin(),(a).end()
#define print(A,x,n) rep(i,0,n){cout<<(i ? " ":"")<<A[i]x;}cout<<endl;
#define pprint(A,y,m,n) rep(j,0,m){print(A[j],y,n);}
const long mod=1e9+7;
const int size=2e5;
const int inf=1e9;
int main(){
	int N,M;cin>>N>>M;
	map<int,int> X[M];
	int sum[M] = {};int eve[M] = {};
	rep(i,0,N){
		int x; cin>>x;
		X[x % M][x / M] ++ ;
		sum[x % M] ++ ;
	}
	rep(i,0,M){
		for(pair<int,int> p:X[i]) eve[i] += p.second / 2;
	}
	int ans = sum[0] / 2;
	if(M % 2 == 0) ans += sum[M/2] / 2;
    //print(sum,,M);print(eve,,M);
	rep(i,1,(M+1)/2){
        int a = i, b = M - i;
		if(sum[a]-2*eve[a] > sum[b]-2*eve[b]) swap(a, b);
		if(sum[a] >= sum[b] - 2 * eve[b]) ans += sum[b] - eve[b] + (sum[a] + 2 * eve[b] - sum[b]) / 2;
		else ans += sum[a] + eve[b];
	}cout<<ans<<endl;
}

Measured memory_bytes: 10368
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define rrep(ri,n) for(int ri = (int)(n-1); ri >= 0; ri--)
#define rep2(i,x,n) for(int i = (int)(x); i < (int)(n); i++)
#define rrep2(ri,x,n) for(int ri = (int)(n-1); ri >= (int)(x); ri--)
#define repit(itr,x) for(auto itr = x.begin(); itr != x.end(); itr++)
#define rrepit(ritr,x) for(auto ritr = x.rbegin(); ritr != x.rend(); ritr++)
#define ALL(x) x.begin(), x.end()
using ll = long long;
using namespace std;

int main(){
  int n;
  cin >> n;
  map<int, int> mp;
  rep(i, n){
    int in;
    cin >> in;
    mp[in]++;
  }
  ll ans = 0;
  for(auto p : mp){
    if(p.first <= p.second) ans += p.second - p.first;
    else ans += p.second;
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 8036
#include <bits/stdc++.h>
using namespace std;
const int INF=2e5+5;
int n,m,a[INF],b[INF],k,ans,o;
long long sum;
int main(){
        cin>>n>>m>>k;
        for (int i=0; i<n; i++) {
                cin>>a[i];
                sum+=a[i];
        }
        o=n;
        for (int i=0; i<m; i++)
                cin>>b[i];
        for (int j=0; j<=m; j++) {
                while (sum>k && o>0) {sum-=a[o-1]; o--;}
                // o++;
                if (sum>k) break;
                // cout<<sum<<" "<<b[j]<<endl;
                ans=max(ans,j+o);
                if (j==m) break;
                sum+=b[j];
        }
        cout<<ans<<endl;
        return 0;
}


Measured memory_bytes: 5196
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <cmath>
#include <iomanip>
#include <stack>
#include <queue>
#include <numeric>
#define rep(i,n) for(int i=0;i<(n);i++)
#define pb push_back
#define mod 1000000007
typedef long long ll;
using namespace std;

int main(){
  int r,g,b;
  cin >> r >> g >> b;
  if((g*10+b) % 4 == 0) cout << "YES" << endl;
  else cout << "NO" << endl;
}


Measured memory_bytes: 256
let () = Scanf.scanf "%d %d %d\n" @@ fun n u v ->
  let es = Array.make n [] in
  for i = 0 to n - 2 do
    Scanf.scanf "%d %d\n" @@ fun a b ->
      es.(a - 1) <- b - 1 :: es.(a - 1);
      es.(b - 1) <- a - 1 :: es.(b - 1)
  done;
  let rec visit visited depth d u =
    if not visited.(u) then begin
      depth.(u) <- d;
      visited.(u) <- true;
      List.iter (visit visited depth (d + 1)) es.(u)
    end in
  let depthT = Array.make n 0 in
  let depthA = Array.make n 0 in
  visit (Array.make n false) depthT 0 (u - 1);
  visit (Array.make n false) depthA 0 (v - 1);
  Printf.printf "%d\n" @@
  Array.fold_left max min_int @@
  Array.init n @@ fun i ->
    if depthA.(i) < depthT.(i)
    then min_int
    else depthA.(i) - 1


Measured memory_bytes: 22656
#include <iostream>
#include <stdio.h>
#define ll long long
using namespace std;

int main()
{
    ll n;
    ll sum=0;
    scanf("%lld",&n);
    for(int i=1;i<=n;i++)
    {
        if(i%3!=0&&i%5!=0)
            sum+=i;
    }
    printf("%lld\n",sum);
    return 0;
}


Measured memory_bytes: 3804
s = gets.strip.split('').reverse.map {|c| c=='?' ? nil : c.to_i}
N = 13
MOD = 10**9+7

dp = Array.new(N,0)
dp[0]=1
#p dp

mul = 1
s.each do |cc|
  ndp = Array.new(N,0)

  if cc.nil?

    10.times do |num|
      b = num*mul
      N.times do |pre|
        ndp[(b+pre)%N] += dp[pre]
      end
    end

  else

    b = cc*mul
    N.times do |pre|
      ndp[(b+pre)%N] += dp[pre]
    end

  end

  dp = ndp.map {|e| e%MOD }
  mul = (mul*10)%N
#p dp
end

p dp[5]%MOD


Measured memory_bytes: 18684
#pragma GCC optimize("Ofast")  
#pragma GCC target("avx,avx2,fma")
#include<bits/stdc++.h>
using namespace std;
#define IO ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define int long long 
#define endl "\n"
#define all(x) (x).begin(),(x).end()
const int MOD = 1e9+7;
const int mxN = 2e5+3;

void solve(){
	int k;
	cin >> k;
	int p = k % 10;
	if(p % 2 == 0 or p == 5){
		cout << "-1" << endl;
		return;
	}
	
	int md = 7 % k;
	if(md == 0){
		cout << 1 << endl;
		return;
	}
	for(int i = 2; i <= k + 1; ++i){
		md *= 10;
		md %= k;
		md = (md + 7) % k;
		if(md == 0){
			cout << i << endl;
			return;
		}
	}
}

int32_t main(){
	IO;
	
	int nT = 1;
	//cin >> nT;
	for(int i = 1; i <= nT; ++i)
		solve();
	return 0;
}


Measured memory_bytes: 3648
#include <bits/stdc++.h>
using namespace std;
int main(){
	int n,p[100000];
	cin>>n;
	for(int i=0;i<n;i++){
		cin>>p[i];
	}
	int ans=0;
	for(int i=0;i<n;i++){
		if(p[i]==i+1){
			swap(p[i],p[i+1]);
			ans++;
			i=-1;
		}
	}
	cout<<ans<<endl;
}


Measured memory_bytes: 640
n, k = map(int, input().split())
h = list(map(int, input().split()))
dp = [0]*n
dp[1] = abs(h[1]-h[0])
for i in range(2,n):
  dp[i] = min([dp[j]+abs(h[i]-h[j]) for j in range(max(0,i-k),i)])
print(dp[n-1])

Measured memory_bytes: 20600
class cal():
    def __init__(self):
        self.sum = 0
    def N(self,T):
        for x in range(1,len(T)+1):
            nan = 2**(len(T[x:])-1)
            if nan < 1:
                nan = 1
            self.sum += int(T[:x]) * nan
            self.N(T[x:])
        return self.sum

T = cal()
print(T.N(input()))

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

int main(){
  int a,b,c,x,y;cin >> a >> b >> c >> x >> y;
  int ans = 0;
  ans += min(a+b,2*c)*min(x,y);
  if(x > y)ans += min(a,2*c) * (x-y);
  else ans += min(b,2*c)*(y-x);
  cout << ans << endl;
  return 0;
}

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

int main() {
  int N, Q;
  cin >> N;
  int A[N];
  map<int, int> m;
  long long res = 0;
  for (int i = 0; i < N; i++){
    cin >> A[i];
    m[A[i]]++;
    res += A[i];
  }
  cin >> Q;
  while (Q > 0) {
    int B, C;
    cin >> B >> C;
    res += (C-B)*m[B];
    m[C] += m[B];
    m[B] = 0;
    Q--;
    cout << res << endl;
  }
  return 0;
}


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

int main()
{
	int n;
	cin >> n;
	vector<ll> a(n);
	ll sum = 0;
	for (int i = 0; i < n; i++) {
		cin >> a[i];
		sum += a[i];
	}

	vector<ll> s(n);
	s[0] = a[0];
	for (int i = 1; i < n - 1; i++) s[i] = s[i - 1] + a[i];

	ll ans = INT_MAX;
	for (int i = 0; i < n - 1; i++) ans = min(ans, abs(s[i] - (sum - s[i])));
	cout << ans << endl;
}


Measured memory_bytes: 3328
def main():
    length, operation = map(int, input().split())
    direction = list(input())
    before = ""
    inverse = {"L": "R", "R": "L"}
    change = 0
    section = 0
    answer = 0
    for i in range(length):
        if not before == direction[i]:
            before = direction[i]
            section += 1
            if section % 2:
                change += 1
        if section % 2 == 0 and change <= operation:
            direction[i] = inverse[direction[i]]
    for i in range(1, length):
        if direction[i] == direction[i - 1]:
            answer += 1
    print(answer)


if __name__ == '__main__':
    main()



Measured memory_bytes: 4084
str = input()

mm = ["01", "02", "03", "04","05","06","07","08","09","10","11","12"]

mae = str[0:2]
ushiro = str[2:]

if mae in mm and ushiro in mm:
    print('AMBIGUOUS')
elif mae in mm:
    print('MMYY')
elif ushiro in mm:
    print('YYMM')
else:
    print('NA')


Measured memory_bytes: 3060
#include<bits/stdc++.h>
using namespace std;
//#include <boost/multiprecision/cpp_int.hpp>
//using namespace boost::multiprecision;

#define int long long int

signed main(){

ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
int t=1;
//cin>>t;
while(t--){
int n,m;
cin>>n>>m;
int arr[n];
int sum=0;
for(int i=0;i<m;i++){
    cin>>arr[i];sum+=arr[i];}

  if(sum>n)cout<<-1<<endl;
  else cout<<n-sum<<endl;


}


}



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

using namespace std;


using int64 = long long;
const int mod = 1e9 + 7;

const int64 infll = (1LL << 62) - 1;
const int inf = (1 << 30) - 1;

struct IoSetup {
  IoSetup() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(10);
    cerr << fixed << setprecision(10);
  }
} iosetup;


template< typename T1, typename T2 >
ostream &operator<<(ostream &os, const pair< T1, T2 > &p) {
  os << p.first << " " << p.second;
  return os;
}

template< typename T1, typename T2 >
istream &operator>>(istream &is, pair< T1, T2 > &p) {
  is >> p.first >> p.second;
  return is;
}

template< typename T >
ostream &operator<<(ostream &os, const vector< T > &v) {
  for(int i = 0; i < (int) v.size(); i++) {
    os << v[i] << (i + 1 != v.size() ? " " : "");
  }
  return os;
}

template< typename T >
istream &operator>>(istream &is, vector< T > &v) {
  for(T &in : v) is >> in;
  return is;
}

template< typename T1, typename T2 >
inline bool chmax(T1 &a, T2 b) { return a < b && (a = b, true); }

template< typename T1, typename T2 >
inline bool chmin(T1 &a, T2 b) { return a > b && (a = b, true); }

template< typename T = int64 >
vector< T > make_v(size_t a) {
  return vector< T >(a);
}

template< typename T, typename... Ts >
auto make_v(size_t a, Ts... ts) {
  return vector< decltype(make_v< T >(ts...)) >(a, make_v< T >(ts...));
}

template< typename T, typename V >
typename enable_if< is_class< T >::value == 0 >::type fill_v(T &t, const V &v) {
  t = v;
}

template< typename T, typename V >
typename enable_if< is_class< T >::value != 0 >::type fill_v(T &t, const V &v) {
  for(auto &e : t) fill_v(e, v);
}

template< typename F >
struct FixPoint : F {
  FixPoint(F &&f) : F(forward< F >(f)) {}

  template< typename... Args >
  decltype(auto) operator()(Args &&... args) const {
    return F::operator()(*this, forward< Args >(args)...);
  }
};

template< typename F >
inline decltype(auto) MFP(F &&f) {
  return FixPoint< F >{forward< F >(f)};
}

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

  if(N & 1) {
    cout << "No" << endl;
    return 0;
  }

  string T = S.substr(0, N / 2);
  string X = S.substr(N / 2);
  if(T == X) cout << "Yes\n";
  else cout << "No\n";


}


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

int main() {
	long long a, b, i, j;
	long long N,ans;
	cin >> N;
	long long judge = sqrt(N);
	ans = 10000000000000;
	for (i = 1; i <= judge; i++) {
		if (N % i == 0) {
			a = i;
			b = N / a;
		}
		j = a + b - 2;
		if (ans > j) ans = j;
	}
	cout <<ans << endl;
}


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

using namespace std;
using ll = long long;

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

	int res = 0;
	deque<int> dq;
	for (int i = 0; i < s.size(); ++i) {
		int x = (int)(s[i] - '0');
		if (dq.empty()) {
			dq.push_back(x);
			continue;
		}
		if (x != dq.back()) {
			res += 2;
			dq.pop_back();
		} else {
			dq.push_back(x);
		}
	}

	cout << res << endl;

	return 0;
}


Measured memory_bytes: 768
#include<bits/stdc++.h>
using namespace std;
#define flash ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define F first
#define S second
#define pb push_back
#define all(v) (v).begin(),(v).end() 
#define endl "\n"
#define int long long int
#define ll long long
#define ld long double
#define Yes() cout << "Yes" << endl
#define YES() cout << "YES" << endl
#define No() cout << "No" << endl
#define NO() cout << "NO" << endl
typedef pair<int, int> ii;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ii> vii;
typedef vector<string> vs;
typedef vector<bool> vb;
const int mod = 1000000007;
const int N=200005;
const int inf=1e18;


bool isPrime(ll n){if(n<2)return false;for(ll i=2;i*i<=n;++i){if(n%i==0){return false;}}return true;}
ll power(ll x,ll y){ll res=1;x=x;while(y>0){if(y&1)res=(res*x)%mod;y=y>>1;x=(x*x)%mod;}return res%mod;}
ll gcd(ll a,ll b){if (a==0)return b;return gcd(b%a,a);}

void fun(){
    #ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
    #endif
}


signed main(){
    flash;
    fun();
    int t=1;
    //cin>>t;
    while(t--){
        int n;
        cin>>n;
        vii s(n);
        vi a(n);
        vi b(n);
        for(int i=0;i<n;i++){
            cin>>s[i].F>>s[i].S;
            a[i]=s[i].F+s[i].S;
            b[i]=s[i].F-s[i].S;
        }
        sort(all(a));
        sort(all(b));
        cout<<max(abs(a[0]-a[n-1]),abs(b[0]-b[n-1]));
    }
    return 0;
}

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

int main()
{
	long long nm[101];
	int n;
	cin >> n;
	for (int i = 0;i < n;i++)
	{
		cin >> nm[i];
	}
	sort(nm, nm + n);
	cout << nm[n - 1] - nm[0] << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
using P = pair<int, int>;
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
#define all(x) x.begin(),x.end()
template<typename T> using min_priority_queue = priority_queue<T, vector<T>, greater<T>>;
template<typename T> T ceil(T a, T b) { return a/b + !!(a%b); }

string s;
ll solve(){
   ll ans=0;
   

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

    cin>>s;
    if(s[0]>='a'&&s[0]<='z'){
        cout<<'a'<<endl;
        return 0;
    }
    else cout<<'A'<<endl;
    //cout<<solve()<<endl;
    return 0;
}

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

using namespace std;

int main (void) {
    int A, B, H, M;
    cin >> A >> B >> H >> M;

    double short_angle = (360 / 12) * H + (360 / 12) * ((double)M / 60);
    double long_angle = (360 / 60) * M;
    double angle = max(long_angle, short_angle) - min(long_angle, short_angle);
    if ( angle == 180 ) {
        cout << A + B << endl;
        return 0;
    }
    if ( angle == 0 || angle == 360 ) {
        cout << max(A, B) - min(A, B) << endl;
        return 0;
    }
    if ( angle > 180 )
        angle = 360 - angle;


    double ans = sqrt(A * A + B * B - 2 * A * B * cos(angle * M_PI / 180));

    printf("%.10lf\n", ans);
    return 0;
}


Measured memory_bytes: 4072
import java.util.*;

public class Main {
	  public static void main(String args[]){
      	Scanner scan = new Scanner(System.in);
            
        String S = scan.next();
        String T = scan.next();
        int cnt = 0;
        
        for( int i = 0 ; i < 3 ; i++){
          if( S.substring(i,i+1).charAt(0) ==T.substring(i,i+1).charAt(0) )
            cnt++;
        }
            
        System.out.println(cnt);
	  }
}

Measured memory_bytes: 23764
#include <iostream>
using namespace std ; 
int main() 
{
	int A=5,B=7,C=5 ; 
	cin>>A>>B>>C ; 
	if (A==B)
	cout<<C<<endl ; 
	else if (A==C)
	cout<<B<<endl ;
	else 
	cout<<A<<endl ;
	
}

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

int main() {
  int s; cin>>s;
  vector<int> A(pow(10,6)+1);
  A[0]=s;
  int i=0;
  while (true) 
  {
    if (A[i]%2 == 0) 
    {
      A[i+1] = A[i]/2;
    }
    else 
    {
      A[i+1] = 3*A[i]+1;
    }
    i++;

    for (int j=0; j<i; j++) 
    {
      if (A[j] == A[i]) {
        cout << i+1 << endl;
        return 0;
      }
    }
  }
}

Measured memory_bytes: 4096
#include <iostream>
#include <fstream>
#include <cstdio>
#include <cmath>
#include <vector>
#include <string>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <deque>
#include <bitset>
#include <algorithm>
#include <complex>
#include <array>
#include <functional>
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 FORR(i,a,b) for (int i=a; i>=b; --i)
#define ALL(c) (c).begin(), (c).end()
 
typedef long long ll;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef vector<double> VD;
typedef vector<VI> VVI;
typedef vector<VL> VVL;
typedef vector<VD> VVD;
typedef pair<int,int> P;
typedef pair<ll,ll> PL;

template<typename T> void chmin(T &a, T b) { if (a > b) a = b; }
template<typename T> void chmax(T &a, T b) { if (a < b) a = b; }

int in() { int x; scanf("%d", &x); return x; }
ll lin() { ll x; scanf("%lld", &x); return x; }

int main() {
    int n;
    cin >> n;
    VI a(n);
    REP(i,n) a[i] = in();
    sort(ALL(a));
    ll ans = 0;
    REP(i,n) REP(j,n){
        if (i == j) continue;
        int l = abs(a[i] - a[j]) + 1, u = a[i] + a[j];
        int x = lower_bound(ALL(a), l) - a.begin();
        int y = lower_bound(ALL(a), u) - a.begin();
        ans += y - x;
        if (x <= i && i < y) ans--;
        if (x <= j && j < y) ans--;
    }
    ans /= 6;
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
	long long int n,c,sum=0;
	cin>>n;
	vector<long long int>v(n);
	v[0]=2;
	v[1]=1;
	sum=(v[0]+v[1]);
	if(n==1)cout<<1<<endl;
	else if(n==2)cout<<sum<<endl;
	else if(n>=3)
	{
		for(int i=3;i<=n;i++)
		{
			sum=(v[0]+v[1]);
			//cout<<sum<<endl;
			v[0]=v[1];
			v[1]=sum;
		}
		c=v[0]+v[1];
		cout<<c<<endl;
	}

	return 0;
}


Measured memory_bytes: 256
#pragma GCC optimize ("O3")
#pragma GCC target ("sse4")

#include<bits/stdc++.h>
using namespace std;

typedef long long ll;
typedef long double ld;
typedef double db;
typedef string str;

typedef pair<int,int> pi;
typedef pair<ll,ll> pl;
typedef pair<db,db> pd;

typedef vector<int> vi; 
typedef vector<ll> vl; 
typedef vector<db> vd; 
typedef vector<str> vs; 
typedef vector<pi> vpi;
typedef vector<pl> vpl; 
typedef vector<pd> vpd; 

#define mp make_pair
#define f first
#define s second
#define sz(x) (int)(x).size()
#define all(x) begin(x), end(x)
#define rall(x) (x).rbegin(), (x).rend() 
#define rsz resize
#define ins insert 
#define ft front() 
#define bk back()
#define pf push_front 
#define pb push_back
#define eb emplace_back 
#define lb lower_bound 
#define ub upper_bound 

#define FOR(i,a,b) for (int i = (a); i < (b); ++i)
#define F0R(i,a) FOR(i,0,a)
#define ROF(i,a,b) for (int i = (b)-1; i >= (a); --i)
#define R0F(i,a) ROF(i,0,a)
#define trav(a,x) for (auto& a: x)

const int MX  = 2e5+5; 
const int MOD = 1e9+7; // 998244353;
const ll  INF = 1e18; 
const ld  PI  = acos((ld)-1);

const int xd[4] = {1,0,-1,0}, yd[4] = {0,1,0,-1};
mt19937 rng((uint32_t)chrono::steady_clock::now().time_since_epoch().count()); 

template<class T> bool ckmin(T& a, const T& b) { 
	return b < a ? a = b, 1 : 0; 
}
template<class T> bool ckmax(T& a, const T& b) { 
	return a < b ? a = b, 1 : 0; 
} 

constexpr int pct(int x) { return __builtin_popcount(x); } // number of ones 
constexpr int bits(int x) { return 31-__builtin_clz(x); } // floor(log2(x)) 
template<class T> T cdiv(T a, T b) { return a/b+!(a<0||a%b == 0); } // division of a by b rounded up, assumes b > 0 

int fstTrue(function<bool(int)> f, int lo, int hi) {
	hi++; assert(lo <= hi); // assuming f is increasing
	while (lo < hi) { // find first index such that f is true 
		int mid = (lo+hi)/2; 
		f(mid) ? hi = mid : lo = mid+1; 
	} 
	return lo;
}

template<class T> void remDup(vector<T>& v) { 
	sort(all(v)); v.erase(unique(all(v)),end(v)); 
}

// DEBUG
void DBG() { cerr << "]" << endl; }
template<class H, class... T> void DBG(H h, T... t) {
	cerr << h; if (sizeof...(t)) cerr << ", ";
	DBG(t...); 
}
#define dbg(...) cerr << "LINE(" << __LINE__ << ") -> [" << #__VA_ARGS__ << "]: [", DBG(__VA_ARGS__)

// FILE I/O
void setIn(str S) { freopen(S.c_str(),"r",stdin); }
void setOut(str S) { freopen(S.c_str(),"w",stdout); }
void setIO(str S = "") {
	ios_base::sync_with_stdio(0); cin.tie(0); // fast I/O
	// cin.exceptions(cin.failbit); 
	// throws exception when do smth illegal
	// ex. try to read letter into int
	if (sz(S)) { setIn(S+".in"), setOut(S+".out"); } // for USACO
}

int32_t main() { 
	
	setIO();

    str x; cin >> x;

    cout << x << (x[sz(x)-1] == 's' ? "es" : "s") << "\n";


}	

Measured memory_bytes: 3644
(let ((m (read))
      (d (read))
      (ans 0))
  (loop for i from 1 upto m
        do (loop for j from 2 upto d
                 do (if (and (>= (rem j 10) 2) (>= (floor j 10) 2) (= i (* (rem j 10) (floor j 10)))) (incf ans))))
  (princ ans))


Measured memory_bytes: 13284
n,d = map(int,input().split())
pts = []
for i in range(n):
    pts.append( [ int(i) for i in input().split() ])
def dist(a,b):
    ans = 0
    for i in range(len(a)):
        ans += (a[i]-b[i])**2
    y = int((ans)**0.5)
    if y**2 == ans:
        return True
    else:
        return False
ans = 0
for i in range(n):
    for j in range(i+1,n):
        ans += dist(pts[i],pts[j])
print(ans)


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

typedef long long ll;
#define dou  double 
#define endl "\n"
const int MOD=1e9+7;
int main()
{
	int n,a,b,c,x,y,z,sum,count=0;
	cin >> n;
	int arr[n];
	for(int i=0;i<n;i++)
		cin >> arr[i];
	for(int i=0;i<n;i++){
		a=arr[i];
		x=i;
		//cout << a << endl;
		for(int j=i+1;j<n;j++){
			if(arr[j]!=a){
				b=arr[j];
				y=j;
				sum=a+b;
				//cout << b << ' ' << sum << endl;
				for(int k=j+1;k<n;k++){
					if(arr[k]!=a && arr[k]!=b){
						//cout << arr[k] << endl;
						if(arr[k]<sum){
							c=arr[k];
							z=k;
							if(a+c>b && b+c>a)
								count=count+1;
							//cout << a  << " "<< b << " " << c << " " <<  count << endl;
						}
					}
				}
			}
		}
	}						

	cout << count << endl;
	return 0;
}


	

Measured memory_bytes: 3560
#include <algorithm>
#include <bitset>
#include <cassert>
#include <chrono>
#include <climits>
#include <cmath>
#include <complex>
#include <cstring>
#include <deque>
#include <functional>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <unordered_map>
#include <unordered_set>
#include <vector>
#include <cstdint>
using namespace std;
typedef long long ll;
#define MP make_pair
#define PB push_back
#define inf 1000000007
#define mod 1000000007
#define rep(i,n) for(int i = 0; i < (int)(n); ++i)


int dp[5002][5002]={};
int main(){
    int n;
    string s;
    cin >> n >> s;
    
    rep(i,n){
        rep(j,n){
            if(i>j)continue;
            if(i==j)continue;
            if(s[i]==s[j]){
                dp[i+1][j+1] = dp[i][j]+1;
                if(i+dp[i+1][j+1]>=j){
                    dp[i+1][j+1] = j-i;
                }
            }
        }
    }
    int mx = 0;
    rep(i,n+1){
        rep(j,n+1){
            mx = max(mx,dp[i][j]);
        }
    }
    cout << mx << endl;
    return 0;
}

Measured memory_bytes: 96768
#include <iostream>
#include <vector>

using namespace std;

int main() {
    int n, a, b, c;
    cin >> n;
    vector<int> a_i, b_i, c_i;
    for (int i = 0; i < n; ++i) {
        cin >> a >> b >> c;
        a_i.push_back(a);
        b_i.push_back(b);
        c_i.push_back(c);
    }
    a = 0, b = 0, c = 0 ;
    for (int i = 0; i < n; ++i) {
        int next_a = a_i[i] + max(b, c);
        int next_b = b_i[i] + max(a, c);
        int next_c = c_i[i] + max(a, b);
        a = next_a;
        b = next_b;
        c = next_c;
    }
    cout << max(max(a, b), c) << "\n";
    return 0;
}


Measured memory_bytes: 1644
#include<iostream>
#include<algorithm>
#include<queue>
using namespace std;
int N,M;
priority_queue<int> lst;

int main(){
    cin>>N>>M;
    for(int i=0;i<N;i++){
        int tmp;cin>>tmp;
        lst.push(tmp);
    }
    for(int i=0;i<M;i++){
        int tmp = lst.top();lst.pop();
        tmp /= 2;
        lst.push(tmp);
    }
    long long sum=0;
    for(int i=0;i<N;i++){
        sum += lst.top();
        lst.pop(); 
    }
    cout<<sum<<endl;
    return 0;
}

Measured memory_bytes: 892
#include <iostream>

const int P = (int)1e9 + 7;

int solve(int n, int k) {
  int64_t ans = 0;
  for (int i = k; i <= n + 1; ++i) {
    int64_t max = (int64_t)i * (2 * n - i + 1) / 2;
    int64_t min = (int64_t)i * (i - 1) / 2;
    ans = (ans + max - min + 1) % P;
    // std::cout << "i = " << i << " f = " << max - min + 1 << std::endl;
  }
  return ans;
}

int main() {
  int n, k;
  std::cin >> n >> k;
  std::cout << solve(n, k) << std::endl;
  return 0;
}


Measured memory_bytes: 3636