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

const int NMAX = 2e5 + 5;
int n, m, sol, nr;
bool vis[NMAX];
vector<int> graph[NMAX];

void dfs(int nod) {
    vis[nod] = 1;
    nr++;
    for(int i = 0; i < (int)graph[nod].size(); i++) {
        int next = graph[nod][i];
        if(!vis[next]) {
            dfs(next);
        }
    }
}

int main() {
    cin >> n >> m;
    while(m--) {
        int x, y;
        cin >> x >> y;
        graph[x].push_back(y);
        graph[y].push_back(x);
    }
    for(int i = 1; i <= n; i++) {
        if(!vis[i]) {
            nr = 0;
            dfs(i);
            sol = max(nr, sol);
        }
    }
    cout << sol;
    return 0;
}

Measured memory_bytes: 20960
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import accumulate, permutations, combinations, product
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left
from fractions import gcd
from heapq import heappush, heappop
from scipy.sparse import csr_matrix
from scipy.sparse.csgraph import floyd_warshall

def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
MOD = 10 ** 9 + 7

N, T = MAP()
A = LIST()

lis = []
tmp = A[0]
tmp_max = 0
for i in range(N):
	if tmp > A[i]:
		tmp = A[i]
		lis.append(tmp_max)
		tmp_max = 0
	else:
		tmp_max = max(tmp_max, A[i]-tmp)
lis.append(tmp_max)

print(lis.count(max(lis)))


Measured memory_bytes: 30128
#include<bits/stdc++.h>
typedef long long ll;
using namespace std;
int INF = 1LL << 30;
int MOD = 1e9+7;
void print(int n){
    for(int i = sizeof(n)*8-1;i >= 0;i--){
        printf("%d%s",n&(1<<i)?1:0,i?"":"\n");
    }
}
main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll N,K;
    cin >> N >> K;
    vector<ll> A(N),B(N);
    for(int i = 0;i < N;i++)cin >> A[i] >> B[i];
    ll maxs = 0;
    ll t = K;
    for(ll i = 1;i <= K*2;i <<= 1){
        ll sum = 0;
        
        for(int j = 0;j < N;j++){
//            if((A[j] | t) == t)sum += B[j];
            if((A[j] & t) == A[j])sum += B[j];
        }
        
//        print((int)t);
        maxs = max(maxs,sum);
        if(!(K & i))continue;
        t -= i;
        t = t | (i-1);
    }
    if(K == 0){
        for(int i = 0;i < N;i++)if(A[i] == 0)maxs += B[i]; 
    }
    cout << maxs << endl;
}

Measured memory_bytes: 1792
#include <iostream>
#include <vector>
using namespace std;
const int N = 100005;
vector<int> to[2 * N];
typedef unsigned long long ull;
int cntx, cnty;
bool visited[N * 2];
void dfs(int v) {
	if (visited[v]) {
		return;
	} 
	visited[v] = true;
	if (v < N) {
		cntx++;
	}
	else {
		cnty++;
	}
	for (int u : to[v]) {
		dfs(u);
	}
	return;
}
int main()
{
	int n, i, a, b;
	cin >> n;
	for (i = 0; i < n; i++) {
		cin >> a >> b;
		b += N;
		to[a].push_back(b);
		to[b].push_back(a);
	}
	ull ans = 0;
	for (i = 1; i < 2 * N; i++) {
		if (visited[i]) continue;
		cntx = cnty = 0;
		dfs(i);
		ans += (ull)cntx * (ull)cnty;
	}
	cout << ans - n << endl;
}

Measured memory_bytes: 10240
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using static System.Console;

class Program
{
    static void Main(string[] args)
    {
        var K = int.Parse(ReadLine());
        var odd = (K + 1) / 2;
        var even = K / 2;

        var ans = odd * even;

        WriteLine(ans);
    }
}

static class ArrayDeconstructExtensions
{
    public static void Deconstruct<T>(this T[] a, out T i1, out T i2) => (i1, i2) = (a[0], a[1]);
    public static void Deconstruct<T>(this T[] a, out T i1, out T i2, out T i3) => (i1, i2, i3) = (a[0], a[1], a[2]);
    public static void Deconstruct<T>(this T[] a, out T i1, out T i2, out T i3, out T i4) => (i1, i2, i3, i4) = (a[0], a[1], a[2], a[3]);
    public static void Deconstruct<T>(this T[] a, out T i1, out T i2, out T i3, out T i4, out T i5) => (i1, i2, i3, i4, i5) = (a[0], a[1], a[2], a[3], a[4]);
}


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

int main(){
    int n;
    int a[100005],c[100005];
    cin>>n;
    int p=0;
    int cnt=0;
    c[0]=0;
    for(int i=1;i<=n;i++){
        cin>>a[i];
        cnt+=abs(a[i]-p);
        p=a[i];
        c[i]=p;
    }
    cnt+=abs(a[n]);
    a[n+1]=0;
    for(int i=1;i<=n;i++){
        int zz=abs(c[i-1]-a[i])+abs(a[i]-a[i+1]);
        int xx=abs(c[i-1]-a[i+1]);
        cout<<cnt-zz+xx<<endl;
    }
}

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

int main() {
  int H, W;
  cin >> H >> W;
  vector<vector<char>> A(H, vector<char>(W));
  for (int h = 0; h < H; h++)
    for (int w = 0; w < W; w++)
      cin >> A[h][w];
  
  vector<vector<char>> tmp(H, vector<char>(W, '-'));
  vector<vector<char>> ans(H, vector<char>(W, '-'));
  

  int row = 0;
  for (vector<char> a : A) {
    bool all_yes = true;
    for (char c : a)
      if (c != '.') all_yes = false;
    if (!all_yes){
      tmp.at(row) = a;
      row++;
    }
  }

  int col = 0;
  for (int w = 0; w < W; w++) {
    bool all_yes = true;
    for (int h = 0; h < H; h++){
      if (tmp.at(h).at(w) == '#') all_yes = false;
    }
    if (!all_yes){
      for (int h = 0; h < H; h++)
        ans.at(h).at(col) = tmp.at(h).at(w);
      col++;
    }
  }
    
  for (vector<char> a : ans){
    for (char c : a)
      if (c != '-') cout << c;
    cout << endl;
  }
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <cstdio>
#include <string>
#include <cstring>
#include <vector>
#include <utility>
#include <functional>
#include <cmath>
#include <map>
#define rep(i,n)for(int i=0;i<(n);i++)
using namespace std;
typedef long long ll;

int main() {
	int n, a, b, c, d; cin >> n >> a >> b >> c >> d;
	cout << min((n + a - 1) / a*b, (n + c - 1) / c*d) << endl;
}


Measured memory_bytes: 3132
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define f(i,a,b) for(int i=a;i<=b;i++)
#define rep(i,a) for(int i=0;i<a;i++)
#define pb push_back
#define F first
#define S second
#define pii pair<int,int>
#define tests int t1234;cin>>t1234;for(int i1234=1;i1234<=t1234;i1234++)
#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);
const int N=1000010;

int32_t main() {
    fastio;
    string s;cin>>s;
    int n=s.size();
    int i=0,j=n-1;int ans=0;
    while(i<j){
        if(s[i]!=s[j])ans++;
        i++;j--;
    }
    cout<<ans<<endl;

}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define N 200005
#define ll long long
using namespace std;
ifstream in("in.txt");
int main(){
    ll x;
    cin>>x;
    ll r=(x/500)*1000;
    x%=500;
    cout<<r+(x/5)*5;
    return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
#define LEN 100005
 
typedef struct{
  char name[100];
  int t;
}P;

void enqueue(P);
P dequeue(void);

P Q[LEN+1];
int head=0,tail=0,n;
 
int main(){
  int elaps = 0;
  int i,q,sum;
  P u;
 
  scanf("%d%d",&n,&q);
  for ( i = 1; i <= n; i++){
    scanf("%s",Q[i].name);
    scanf("%d",&Q[i].t);
  }

  head = 1;
  tail = n+1;
  
  while( head != tail )
    {
      u = dequeue();
      if( u.t <= q && u.t != 0)
	{
	  elaps = elaps + u.t;
	  printf("%s %d\n",u.name,elaps);
	}
      else if( u.t > q)
	{
	  u.t = u.t - q;
	  enqueue(u);
	  elaps = elaps + q;
	}
    }

  return 0;
}

void enqueue(P x)
{
  Q[tail] = x;
  if( tail + 1 == LEN )
    tail = 0;
  else 
    tail++;
}

P dequeue()
{
  P x;
  x = Q[head];
  if( head + 1 == LEN )
    head = 0;
  else   
    head++;
  return x;
}

Measured memory_bytes: 10756
#include<bits/stdc++.h>
#define ll long long
#define mod (ll)1000000007
using namespace std;
int a[6] = {0,1,2,3,4,5};
int dp[7][100][1002];
int rec(int pos, int x, int rem){
    if(pos == 6){
        if(rem == 0 && x == 0)
            return 1;
        return 0;
    }

    if(dp[pos][x][rem]!=-1) return dp[pos][x][rem];
    int ans = 0;
    if(rem > 0){
        if(x >= a[pos]){
            ans |= (rec(pos, x-a[pos], rem-1) | rec(pos+1, x-a[pos], rem-1)); 
        }
        
        ans |= rec(pos+1, x, rem);
    }
    else
        ans |= rec(pos+1, x, rem);


    dp[pos][x][rem] = ans;

    return ans;
}
int main()
{
    long long x;
    cin>>x;
    int q = x/100;
    x%=100;

    // if(x == 0)
    //     cout<<1<<"\n";
    // else{
        memset(dp,-1,sizeof(dp));
        cout<<rec(0,x,q)<<"\n";
    // }
    return 0;
}


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

using namespace std;

long long n, k, a[3005], dp[3005][3005];

int main(){
    ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
    cin >> n;
    for (int i = 0; i < n; i++) cin >> a[i];
    for (int l = n - 1; l >= 0; l--){
        for (int r = l; r < n; r++){
            dp[l][r] = l == r? a[l] : max(a[l] - dp[l + 1][r], a[r] - dp[l][r - 1]);
        }
    }
    cout << dp[0][n - 1];
    return 0;
}

Measured memory_bytes: 70016
#include <algorithm>
#include <iostream>
#include <cstdio>
#include <map>
#include <set>
#include <sstream>
#include <string>
#include <vector>
#include <complex>
#include <queue>
using namespace std;
typedef long long ll;
//typedef pair<int, int> P;
#define ISEQ(c) (c).begin(), (c).end()

namespace Ps{
	const double EPS = 1e-8;
	const double INF = 1e12;

	typedef complex<double> P;
#define X real()
#define Y img()

	double cross(const P& a, const P& b) {
		return imag(conj(a)*b);
	}
	double dot(const P& a, const P& b) {
		return real(conj(a)*b);
	}

	int ccw(const P& a, P b, P c) {
		b -= a; c-= a;
		if (cross(b, c) > 0) return 1;
		if (cross(b, c) < 0) return -1;
		if (dot(b, c) < 0) return 2;
		if (norm(b) < norm(c)) return -2;
		return 0;
	}

	double pfmod(double v, double MOD) {
		return fmod(fmod(v,MOD)+MOD,MOD);
	}
	double AbsArg(double a) {
		double ret = pfmod(max(a,-a),2*M_PI);
		return min(ret,2*M_PI-ret);
	}


	struct L : public vector<P> {
		L(const P &a, const P &b) {
			push_back(a); push_back(b);
		}
	};

	bool isIntersect(const L &s, const L &t) {
		return ccw(s[0],s[1],t[0])*ccw(s[0],s[1],t[1]) <= 0 and ccw(t[0], t[1], s[0])*ccw(t[0],t[1],s[1]) <= 0;
	}
}
using namespace Ps;

double G[1010][1010];


double d[1010];
bool used[1010];

void dijkstra(int s, int n) {
	fill(d, d+1010, INF);
	fill(used, used+1010, false);
	d[s] = 0;

	while (true) {
		int v = -1;
		for (int u = 0; u < n; u++) {
			if (!used[u] and (v == -1 or d[u] < d[v])) v = u;
		}

		if (v == -1) break;
		used[v] = true;

		for (int u = 0; u < n; u++) {
			d[u] = min(d[u], d[v]+G[v][u]);
		}
	}
}

int main() {
	int na, nb;
	cin >> na >> nb;
	vector<int> xa(na), ya(na), xb(nb), yb(nb);
	for (int i = 0; i < na; i++) {
		cin >> xa[i] >> ya[i];
	}
	for (int i = 0; i < nb; i++) {
		cin >> xb[i] >> yb[i];
	}
	L la(P(xa[0],ya[0]),P(xa[1],ya[1]));
	L lb(P(xb[0],yb[0]),P(xb[1],yb[1]));
	
	for (int i = 0; i < na; i++) {
		for (int j = i+1; j < na; j++) {
			if (isIntersect(lb, L(P(xa[i],ya[i]),P(xa[j],ya[j])))) {
				G[j][i] = G[i][j] = INF;
			} else {
				G[j][i] = G[i][j] = hypot(xa[i]-xa[j],ya[i]-ya[j]);
			}
		}
		G[i][i] = INF;
	}
	dijkstra(0, na);
	double res = d[1] + abs(lb[0]-lb[1]);

	for (int i = 0; i < nb; i++) {
		for (int j = i+1; j < nb; j++) {
			if (isIntersect(la, L(P(xb[i],yb[i]),P(xb[j],yb[j])))) {
				G[j][i] = G[i][j] = INF;
			} else {
				G[j][i] = G[i][j] = hypot(xb[i]-xb[j],yb[i]-yb[j]);
			}
		}
		G[i][i] = INF;
	}
	dijkstra(0, nb);
	res = min(res, d[1]+abs(la[0]-la[1]));
	if (res >= INF) cout << -1 << endl;
	else
		printf("%.20f\n",res); 

}

Measured memory_bytes: 9140
#include<bits/stdc++.h>
using namespace std;
const long long mod= 1e9+7;
char s[100007];
long long dp[100007][17];
int main(){
    cin>>s+1;
    int n=strlen(s+1);
    dp[0][0]=1;
    for(int i=1;i<=n;++i)
        for(int k=0;k<=9;++k)
            for(int j=0;j<=12;++j)
                if(s[i]=='?'||s[i]==k+'0')
                    dp[i][(k+j*10%13)%13]=(dp[i][(k+j*10%13)%13]+dp[i-1][j])%mod;
    cout<<dp[n][5];
    return 0;
}


Measured memory_bytes: 13568
function Main(input) {
	input = input.trim().split(" ");
  var list1 = input[0].slice(0,1);
  var list2 = input[1].slice(0,1);
  var list3 = input[2].slice(0,1);
  console.log(list1 + list2 + list3);
  
}

Main(require("fs").readFileSync("/dev/stdin", "utf8"));


Measured memory_bytes: 7372
#include <bits/stdc++.h>
using namespace std;
///////////////////////////////////////////
const long long int INF = 1LL<<60;
const long long int Mod = 1000000007;
using ll = long long int; using ci = const int;
using vi = vector<int>;  using Vi = vector<long long int>;
using P = pair<int, int>;  using PLL = pair<ll, ll>;
using matrix = vector<vector<ll>>;
#define pb(x) push_back(x)
#define mp(x,y) make_pair(x,y)
#define all(x) (x).begin(),(x).end()
#define rp(i,N) for(ll i = 0; i < (ll)N; i++)
#define repi(i,a,b) for(ll i = ll(a); i < ll(b); ++i)
template<class T>bool chmax(T &former, const T &b) { if (former<b) { former=b; return true; } return false; }
template<class T>bool chmin(T &former, const T &b) { if (b<former) { former=b; return true; } return false; }
template<class T>T sqar(T x){ return x*x; }//sqrt(x)は平方根;
#define Sort(v) std::sort(v.begin(), v.end(), std::greater<decltype(v[0])>()) //降順でVをソート
#define p_queue(v) priority_queue<v, vector<v>, greater<v> >
template<class T> inline void princ(T x){cout<<x<<" ";}; 
template<class T> inline void print(T x){cout<<x<<"\n";};
template<class T> inline void Yes(T condition){ if(condition) cout << "Yes" << endl; else cout << "No" << endl; }
template<class T> inline void YES(T condition){ if(condition) cout << "YES" << endl; else cout << "NO" << endl; }
///////////////////////////////////////////////////////////////////////////////////

void solve(){
    int x;
    cin >> x;
    if(x<600)print(8);
    else if(x<800) print(7);
    else if(x<1000) print(6);
    else if (x<1200) print(5);
    else if (x<1400) print(4);
    else if (x<1600) print(3);
    else if (x<1800) print(2);
    else if (x<2000) print(1);
    return;
}
int main(){
    cin.tie(0);ios::sync_with_stdio(false);
    std::cout<<std::fixed<<std::setprecision(30);
    solve();
    return 0;
}

Measured memory_bytes: 3604
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define io ios_base::sync_with_stdio(false); cin.tie(NULL);
#define pb push_back
#define endl '\n'
#define mod 1000000007
#define inf 1000000000000000000
const int sz = 100002;
int n, k;
vector<int>a;
int main() {
	io
	int a,b,c,k;
	cin>>a>>b>>c>>k;
	if(a >= k) cout<<k<<endl;
	else {
		int sum = a;
		k -= a;
		//cout<<k<<endl;
		if(b >= k) cout<<sum;
		else {
			k -= b;
			sum -= k;
			cout<<sum;
		}
	}
}




Measured memory_bytes: 3640
#include<bits/stdc++.h>
#define Rint register int
#define MP make_pair
#define fi first
#define se second
#define PB push_back
using namespace std;
typedef long long LL;
typedef pair<int, int> pii; // 注意必要时改类型
typedef vector<int> vi;
template<typename T>
inline void read(T &x){
    int ch = getchar(); x = 0;
    bool f = false;
    double d = 1;
    for(;ch != '-' && (ch < '0' || ch > '9');ch = getchar());
    if(ch == '-'){f = true; ch = getchar();}
    for(;ch >= '0' && ch <= '9';ch = getchar()) x = x * 10 + ch - '0';
    if(ch == '.') for(ch = getchar();ch >= '0' && ch <= '9';ch = getchar()) x += (ch - '0') * (d *= 0.1);
    if(f) x = -x;
}
template<typename T>
inline bool chkmax(T &a, const T &b){if(a < b) return a = b, 1; return 0;}
template<typename T>
inline bool chkmin(T &a, const T &b){if(a > b) return a = b, 1; return 0;}
const int N = 103;
int n, m, dp[N][N];
char str[N];
bool a[N][N];
int main(){
    read(n); read(m);
    for(Rint i = 1;i <= n;++ i){
        scanf("%s", str + 1);
        for(Rint j = 1;j <= m;++ j) a[i][j] = str[j] == '#';
    }
    memset(dp, 0x7f, sizeof dp);
    dp[1][1] = a[1][1];
    for(Rint i = 1;i <= n;++ i)
        for(Rint j = 1 + (i == 1);j <= m;++ j){
            if(i > 1){
                if(a[i][j]) chkmin(dp[i][j], dp[i - 1][j] + !a[i - 1][j]);
                else chkmin(dp[i][j], dp[i - 1][j]);
            }
            if(j > 1){
                if(a[i][j]) chkmin(dp[i][j], dp[i][j - 1] + !a[i][j - 1]);
                else chkmin(dp[i][j], dp[i][j - 1]);
            }
        }
    printf("%d\n", dp[n][m]);
}

Measured memory_bytes: 256
#include"bits/stdc++.h"
using namespace std;
typedef unsigned long long ull;
typedef long long ll;
#define INF 1e+9


int main() {
	int n;
	int a[200001];
	cin >> n;
	fill(a, a + 200001, 0);
	for (int i = 0; i < n - 1; i++) {
		int x;
		cin >> x;
		a[x - 1]++;
	}
	for (int i = 0; i < n; i++) {
		cout << a[i] << endl;
	}
	return 0;
}

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

using namespace std;
using ll = long long;

//container util
#define SORT(c) sort((c).begin(),(c).end())

//repetition
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)

//print
#define pv(val) cerr << #val << '=' << (val) << endl

const int INF = 1e9;

int main(void){

	int A, B, C; cin >> A >> B >> C;
	int ans = min(C, B/A);

	cout << ans << endl;
	


	return 0;

}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef long double ld;
typedef pair<ll,ll> p2;
void solve(){
  ll x;
  cin>>x;
  cout<<1000*(x/500)+5*((x%500)/5);
}
int main(){
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  ll q=1;
  for(ll i=1;i<=q;i++)
    solve();
}

Measured memory_bytes: 256
a,b,c,d = [int(i) for i in input().split()]
i = 0
while 1:
    if a <= 0:
        print("No")
        break
    elif c <= 0:
        print("Yes")
        break
    if i % 2 == 0:
        c = c - b
    else :
        a = a - d
    i = i + 1

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

using namespace std;

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
  int N;
  cin >> N;
  vector<int> d(N);
  for (int i = 0; i < N; ++i) {
    cin >> d[i];
  }
  int sum_ = 0;
  for (int i = 0; i < N; ++i) {
    for (int j = i + 1; j < N; ++j) {
      sum_ += d[i] * d[j];
    }
  }
  cout << sum_ << endl;
}


Measured memory_bytes: 256
H,W,M = map(int,input().split())

h_target = [0]*(H+1)
w_target = [0]*(W+1)
target = []

for _ in range(M):
    h,w = map(int,input().split())
    target.append((h,w))
    h_target[h] += 1
    w_target[w] += 1

max_h = max(h_target)
max_w = max(w_target)

num_max_h = 0
num_max_w = 0

for i in h_target:
    if i == max_h:
        num_max_h += 1

for i in w_target:
    if i == max_w:
        num_max_w += 1

total = num_max_h*num_max_w
point = 0

for i,j in target:
    if h_target[i] == max_h and w_target[j] == max_w:
        point += 1

if point == total:
    print(max_h+max_w-1)
else:
    print(max_h+max_w)

Measured memory_bytes: 54160
h, w = map(int, input().split())
a=[ list(input()) for _ in range(h)]
dp=[1]+[0]*(w-1)
for i in range(h):
    dp[0]=int(dp[0]==1 and a[i][0]=='.')
    for j in range(1,w): dp[j]=(int(a[i][j]=='.')*(dp[j]+dp[j-1]) % 1000000007 )
print(dp[-1])

Measured memory_bytes: 13812
#include "iostream"
#include <vector>
#include <algorithm>
#include <math.h>
using namespace std;

vector<int> prim_factorization (int a){
    vector<int> factors = {};
    for (int i = 2; i <= a; i++){
        while (a % i == 0) {
            factors.push_back(i);
            a /= i;
        }
    }
    return factors;
}

vector<int> common_prim_factors (vector<int> A, vector<int> B) {
    for (u_int i = 0; i < A.size(); i++){
        for (u_int j = 0; j < B.size(); j++){
            if (A.at(i) == B.at(j)) {
                B.erase(B.begin() + j);
                break;
            }
        }
    }
    A.insert(A.end(), B.begin(), B.end());
    return A;
}

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

    auto factorsOfA = prim_factorization(A);
    auto factorsOfB = prim_factorization(B);
    // cout << "factors of A: ";
    // for (u_int i = 0; i < factorsOfA.size() ; i++){
    //     cout << factorsOfA.at(i) << ", ";
    // }
    // cout << endl;
    // cout << "factors of B: ";
    // for (u_int i = 0; i < factorsOfB.size() ; i++){
    //     cout << factorsOfB.at(i) << ", ";
    // }
    // cout << endl;
    // cout << "common factors: ";
    auto common_factors = common_prim_factors(factorsOfA, factorsOfB);
    long long  answer=1;
    for (u_int i = 0; i < common_factors.size(); i++){
        // cout << common_factors.at(i) << ", ";
        answer *= common_factors.at(i);
    }
    // cout << endl;
    cout << answer << endl;
    return 0;
}

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

using namespace std;

using ull = unsigned long long;

ull gcd(ull u, ull v) {
  ull shift;

  if (u == 0)
    return v;

  if (v == 0)
    return u;

  shift = __builtin_ctzll(u | v);
  u >>= __builtin_ctzll(u);

  do {
    v >>= __builtin_ctzll(v);
    if (u > v) {
      ull t = v;
      v     = u;
      u     = t;
    }
    v = v - u;
  } while (v != 0);
  return u << shift;
}

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

  std::vector<ull> vec(n);
  std::vector<ull> left(n);
  std::vector<ull> right(n);

  for (size_t i = 0; i < n; i++) {
    cin >> vec[i];
  }

  ull p1 = 0, p2 = 0;
  for (size_t i = 0, j = n - 1; i < n; i++) {
    p1       = gcd(vec[i], p1);
    p2       = gcd(vec[j], p2);
    left[i]  = p1;
    right[j] = p2;
    j--;
  }

  ull mval = max(right[1], left[n - 2]);
  mval = max(p1, mval);
  
  auto m = n - 1;

  for (size_t i = 1; i < m; i++) {
    mval = max(mval, gcd(left[i - 1], right[i + 1]));
  }

  cout << mval << endl;

  return 0;
}


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

#define FOR(i, a, b) for(int i=(a); i<(b); i++)
#define RFOR(i, a, b) for(int i=(a); i>=(b); i--)
#define rep(i, n) FOR(i, 0, n)
#define rrep(i, n) RFOR(i, n, 0)
#define dump(x)  cout << #x << " = " << (x) << endl;

typedef long long ll;
typedef pair<int, int> ii;
const int mod = 1e9+7;
const ll INF = 1e18;
const int inf = 1e9;

void solve()
{
  int a,b; cin>>a>>b;
  if (a==1) a=14;
  if (b==1) b=14;
  if (a>b) cout << "Alice" << endl;
  else if (a<b) cout << "Bob" << endl;
  else cout << "Draw" << endl;
}

int main()
{
  solve();
  return 0;
}


Measured memory_bytes: 256
import sys
lines = sys.stdin.read().split("\n")
n, m = map(int, lines[0].split())

ac_flags = [0] * (n + 1)
wa_counter = [0] * (n + 1)

ac_count = 0
wa_count = 0
for line in lines[1:-1]:
    p, s = line.split()
    p = int(p)
    if ac_flags[p] == 0:
        if s == "AC":
            ac_flags[p] = 1
            ac_count += 1
            wa_count += wa_counter[p]
        else:
            wa_counter[p] += 1

print ac_count, wa_count


Measured memory_bytes: 10488
import java.util.*;

public class Main {
    public static void main(String[] args) {
        
        Scanner sc = new Scanner(System.in);
        
        int N = sc.nextInt();
        
        int count = 0;
        for(int i = 0; i < N; i++){
            
            int r = sc.nextInt();
            int l = sc.nextInt();
            count += l - r + 1;
        }
        System.out.println(count);
        
        sc.close();
    }
}


Measured memory_bytes: 25288
n, m, k = map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
book_a = [0] * (n + 1)
book_b = [0] * (m + 1)

for i in range(n):
    book_a[i+1] = book_a[i] + a[i]

for j in range(m):
    book_b[j + 1] = book_b[j] + b[j]

r = m
ans = 0

for i in range(n + 1):
    if book_a[i] > k:
        break
    while book_a[i] + book_b[r] > k:
        r -= 1
    ans = max(ans, i + r)

print(ans)

Measured memory_bytes: 47492
#include<stdio.h>
int main()
{
	long long int l,r,n,c=0,i;
	scanf("%lld %lld %lld",&l,&r,&n);
	for(i=l;i<=r;i++)
	{
		if(i%n==0)
		{
			c++;
		}
	}
	printf("%lld\n",c);
}

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

using namespace std;

#define fi first
#define se second
#define eb emplace_back
#define mt make_tuple
#define all(x) (x).begin(), (x).end() 
#define MOD 1000000007

typedef long long ll;
typedef pair <int, int> ii;
typedef pair <ll, ll> pll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef long double ld;

const ll INF=LLONG_MAX;

string s[4] = {"AC", "WA", "TLE", "RE"};
int cnt[4];

int main()
{
    ios_base::sync_with_stdio(0); cin.tie(0);
    //freopen("input.txt","r",stdin); freopen("output.txt","w",stdout);
	int n; cin >> n;
	string x;
	while(n--){
		cin >> x;
		for(int i=0;i<4; i++){
			if(x==s[i])cnt[i]++;
		}
	}
	for(int i=0; i<4; i++){
		cout << s[i] << " x " << cnt[i] << endl;
	}
}
	
// READ & UNDERSTAND
// ll, int overflow, array bounds, memset(0)
// special cases (n=1?), n+1 (1-index)
// do smth instead of nothing & stay organized
// WRITE STUFF DOWN


Measured memory_bytes: 3644
A = list(map(int, input().split()))
maxA = max(A)
minA = min(A)
midA = sum(A) - maxA - minA
count = 0

count = maxA - midA
minA += count

while minA < maxA - 1:
    minA += 2
    count += 1
    
if minA == maxA:
    print(count)
else:
    print(count + 2)

Measured memory_bytes: 3060
#include<cstdio>
#include<algorithm>
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)

const int MX=1500*1000+1;
int n,m,H[1500],W[1500];
int h[MX],w[MX],sh,sw;

void comb(int *A,int *a,int k,int mx)
{
	fill_n(a,mx+1,0);
	rep(i,k)
	{
		int len=0;
		for(int j=i;j<k;j++)len+=A[j],a[len]++;
	}
}

int main()
{
	while(scanf("%d%d",&n,&m),n)
	{
		sh=sw=0;
		rep(i,n)scanf("%d",H+i),sh+=H[i]; comb(H,h,n,sh);
		rep(i,m)scanf("%d",W+i),sw+=W[i]; comb(W,w,m,sw);
		
		int ans=0;
		rep(i,min(sw,sh)+1)ans+=h[i]*w[i];
		printf("%d\n",ans);
	}
	return 0;
}

Measured memory_bytes: 4716
#include<stdio.h>
#include<iostream>
#include<string.h>
#include<algorithm>
#include<queue>
#include<stack>
#include<math.h>
#include<map>
typedef long long int ll;
using namespace std;
#define maxn 0x3f3f3f3f
const int mm=1e6;
ll d[mm];
int main()
{
	ll n,m,i,j; string s,ss,sss;
    double k,kk;
    cin>>k;
    kk=(k/3)*(k/3)*(k/3);
    printf("%f",kk);
    

}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <array>
#include <vector>
#include <queue>
#include <stack>
#include <list>
#include <set>
#include <map>
#include <algorithm>
#include <cmath>
#include <iomanip>

#define FOR(i, a, b) for(decltype(b) i = (a); i < (b); ++i)
#define REP(i, n) FOR(i, 0, n)

typedef long long ll;
typedef unsigned long long ull;
typedef unsigned int uint;

using namespace std;

#ifdef INPUT
#include <sstream>
stringstream input(R"(
2 3
2 55
2 77
2 99
)");
#define cin input
#endif

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

	vector<int> c(n);

	vector<int> q(m);
	map<int, int> p;
	map<int, int> r;

	for (auto& i : q)
	{
		int x;
		cin >> x >> i;
		p[i] = x;
	}

	for (auto& i : p)
	{
		r[i.first] = ++c[i.second - 1];
	}

	for (auto& i : q)
	{
		printf("%06d%06d\n", p[i], r[i]);
	}

	return 0;
}


Measured memory_bytes: 12280
s=input()
l=len(s)
a=[1]*(l+1)
c=[]
x=0
while(x<=l-1):
  if(a[x]==1):
    a[x]=0
    k=0
    b=[x]
    t=s+s[x]
    for i in range(x+1,l+1):
      if(t[x]==t[i]):
        b.append(k)
        a[i]=0
        k=0
      else:
        k+=1
    c.append(max(b))
  x+=1
print(min(c))

Measured memory_bytes: 3064
#include <stdio.h>
#include <iostream>
using namespace std;

int main()
{
    int n, a, cnt;
    cin >> n >> a;
    if (n < 500)
    {
        cnt = n;
    }
    else
    {
        cnt += n % 500;
    }
    if (cnt <= a)
    {
        cout << "Yes" << endl;
    }
    else
    {
        cout << "No" << endl;
    }
}


Measured memory_bytes: 256
#FT robot
s=input()
gx,gy=map(int,input().split())
lists=list(s.split("T"))
xlist=[]
ylist=[]
if s[0]=="T":
    for i in range(len(lists)):
        if i%2==0:
            xlist.append(len(lists[i]))
        else:
            ylist.append(len(lists[i]))
elif s[0]=="F":
    for i in range(len(lists)):
        if i%2==0:
            xlist.append(len(lists[i]))
        else:
            ylist.append(len(lists[i]))
    gx-=xlist[0]
    del xlist[0]
Xsum=sum(xlist)
Ysum=sum(ylist)


if (Xsum+gx)%2!=0 or (Ysum+gy)%2!=0:
    print("No")   
else:
    gx1=(Xsum+gx)//2
    gx2=(Xsum-gx)//2
    gy1=(Ysum+gy)//2
    gy2=(Ysum-gy)//2
    dpx=[[False for i in range(Xsum+2)] for j in range(len(xlist)+2)]
    dpy=[[False for i in range(Ysum+2)] for j in range(len(ylist)+2)]
    #dpx[i][j]でi番目のカードまでを足して、値ｊを取れるか判定する
    dpx[0][0]=True
    dpy[0][0]=True
    for i in range(len(xlist)):
        for j in range(Xsum+2):
            dpx[i+1][j]=dpx[i][j-xlist[i]] or dpx[i][j]
    for i in range(len(ylist)):
        for j in range(Ysum+2):
            dpy[i+1][j]=dpy[i][j-ylist[i]] or dpy[i][j]    
    #ここまではあってそうなことがわかった
    flag1=False
    if 0<= gy1<= Ysum:   
        if dpy[len(ylist)][gy1]:
            flag1=True
    flag2=False
    if 0<=gy2<= Ysum :
        if dpy[len(ylist)][gy2]:
            flag2=True
    flag3=False
    if 0<=gx1<= Xsum:
        if dpx[len(xlist)][gx1]:
            flag3=True
    flag4=False
    if 0<=gx2<= Xsum:
        if dpx[len(xlist)][gx2]:
            flag4=True
    if (flag1 or flag2) and (flag3 or flag4):
        print("Yes")
    else:
        print("No")                                                      

Measured memory_bytes: 111836
N = int(input())
H = list(map(int, input().split()))

cost = [0]*N
cost[1] = abs(H[0] - H[1])

for k in range(2, N):
    cost[k] = min(cost[k-1] + abs(H[k-1] - H[k]), cost[k-2] + abs(H[k-2] - H[k]))


print(cost[-1])

Measured memory_bytes: 13980
def solve(string):
    n = len(string)

    def op(string, ans, forward=True):
        count = 0
        check = "R" if forward else "L"
        sign, base = 2 * forward - 1, (n - 1) * (1 - forward)
        for i, a in enumerate(string[::sign]):
            if a == check:
                count += 1
            elif count > 0:
                ans[base + sign * i] += count // 2
                ans[base + sign * (i - 1)] += (count + 1) // 2
                count = 0
        return ans

    ans = op(string, [0] * n, True)
    return " ".join([str(a) for a in op(string, ans, False)])


if __name__ == '__main__':
    print(solve(input()))


Measured memory_bytes: 10492
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define loop(i,a,b) for (int i=a; i<b; ++i)

ll choose(ll n, ll k) //k<=3
{
    if (k==0) return 1;
    if (k>n) return 0;
    ll num=1, den=1;
    for (int i=0; i<k; ++i) num*=(n-i);
    for (int i=1; i<=k; ++i) den*=i;
    return (num/den);
}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    string s;
    cin >> s;
    ll K;
    cin >> K;
    ll ans=0;    
    int n=s.length();
    ll nonzero=0;
    loop(i,0,n)
    {
        int d1 = s[i]-'0';
        if (d1==0) continue;
        // cout << d1 << " " << nonzero << endl;
        d1--;
        if (K-nonzero-1 >=0 ) {
            ans += (d1*pow(9, K-nonzero-1)*choose(n-i-1, K-nonzero-1));
        }
        if (K-nonzero >=0 ) {
            ans += (pow(9, K-nonzero)*choose(n-i-1, K-nonzero));
        }
        nonzero++;
    }
    if (nonzero==K) ans++;
    cout << ans << "\n";
    return 0;
}

Measured memory_bytes: 384
#include <algorithm>
#include <iostream>
#include <utility>
#include <vector>
#include <map>

using namespace std;

struct Data {
  int id, a;
  Data() {}
  Data(int id, int a): id(id), a(a) {}
};

int uid(Data &d, int to) {
  return 2*d.a + (to%2);
}

int main() {
  int n;
  cin >> n;
  vector<Data> la;
  for (int i = 0; i < n; ++i) {
    int a;
    cin >> a;
    la.emplace_back(i, a);
  }
  sort(
    la.begin(),
    la.end(),
    [](const Data& lhs, const Data& rhs) { return lhs.a < rhs.a; }
  );
  map<int, int> count;
  for (int i = 0; i < n; ++i) { 
    Data &d = la[i];
    count[uid(d, i)] += 1;
  }
  int ans = 0;
  for (int i = 0; i < n; ++i) { 
    Data &d = la[i];
    int id = uid(d, d.id);
    if (count.find(id) == count.end()) {
      ++ans;
      continue;
    }
    if (count[id] == 0) {
      ++ans;
      continue;
    }
    // cerr << id << " " << count[id] << endl;
    --count[id];
  }
  cout << ans/2 << endl;

  return 0;
}


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

int main() {
	int a;
	cin >> a;
	set <int> A;
	while (A.count(a)==0){
	    A.insert(a);
	    if (a%2==1){
	        a=3*a+1;
	    }
	    else a/=2;
	}
	cout << A.size()+1 << endl;
}


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

for i in range(N):
    if A[i] == 0:
        if A[i+1] >= B[i]:
            cnt += B[i]
            A[i+1] -= B[i]
            continue
        else:
            cnt += A[i+1]
            A[i+1] = 0
            continue
    if A[i] >= B[i]:
        cnt += B[i]
        continue
    else:
        cnt += A[i]
        B[i] -= A[i]
        if A[i+1] >= B[i]:
            cnt += B[i]
            A[i+1] -= B[i]
            continue
        else:
            cnt += A[i+1]
            A[i+1] = 0

print(cnt)

Measured memory_bytes: 82020
flag=0
s = input()
a = [str(c) for c in s]
for i in range(int((len(s)-1)/2)):
  if a[i]!=a[int((len(s)+1)/2+i)] or a[i]!=a[int((len(s)-1)/2-1-i)]:
    flag=1
    break
if flag==0:
  print("Yes")
else:
  print("No")

Measured memory_bytes: 3060
#include<bits/stdc++.h>
using namespace std;
int main(void){
  int a=0,b;
  char c;
  string s;
 cin >> s;
  for(int i = 0;i < s.size();i++){
    if(s.at(i) == '1'){
      a++;
    }
  }
  cout << a;
}

Measured memory_bytes: 256
using System;
using System.Text;
using static System.Console;
namespace a755
{
    class a755
    {
        static void Main(string[] args)
        {
            long x = long.Parse(ReadLine());
            long op = 0;
            long c = 357;
            while (c <= x)
            {
                bool hit3 = false;
                bool hit5 = false;
                bool hit7 = false;
                bool hitX = false;

                for (int i = 1; (long)Math.Pow(10, i - 1) <= c; i++)
                {
                    IsNumber357((c - c / (long)Math.Pow(10, i) * (long)Math.Pow(10, i)) / (long)Math.Pow(10, i - 1), ref hit3, ref hit5, ref hit7, ref hitX);
                    if (hitX)
                    {
                        if (i == 1)
                        {
                            c = c + 2;
                            break;
                        }
                        else
                        {
                            c = c + (long)Math.Pow(10, i - 1);
                            break;
                        }
                    }

                }

                if (!hitX)
                {
                    if (hit3 && hit5 && hit7)
                    {
                        op = ++op;
                    }
                    c = c + 2;
                }
            }
            WriteLine(op);
        }

        static void IsNumber357(long c, ref bool hit3, ref bool hit5, ref bool hit7, ref bool hitX)
        {
            switch (c)
            {
                case 3:
                    hit3 = true;
                    break;
                case 5:
                    hit5 = true;
                    break;
                case 7:
                    hit7 = true;
                    break;
                default :
                    hitX = true;
                    break;
            }
        }
    }
}

Measured memory_bytes: 11220
#include<bits/stdc++.h>
using namespace std;
using ll  = long long;
using vl  = vector<ll>;
using vi  = vector<int>;
#define _GLIBCXX_DEBUG
#define IO_STREAM cin.tie(0);ios::sync_with_stdio(false)
#define all(x) x.begin(),x.end()
#define rep(i,sta,end) for(ll i=sta;i<end;++i)
#define lcm(a,b) (a)/__gcd((a),(b))*(b)
#define pb push_back
#define INF 1000000000000000LL
const ll MOD = 1000000007;
const double PI = acos(-1);
//||
#define DBG(a,b,c,d) //cout<<a<<" "<<b<<" "<<c<<" "<<d<<" "<<endl
//DBG("","","","");

signed main(){
	IO_STREAM;
	int N,R;
	cin>>N>>R;
	ll ans;
	if(N>=10){
		ans=R;
	}
	else{
		ans=R+100*(10-N);
	}
	cout<<ans<<endl;
	return 0;
}


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

using namespace std;

//void solve1() {
//	int N;
//	cin >> N;
//
//	//calculate
//	string ans = "No";
//	if (N >= 21) {
//		ans = "Yes";
//	} else {
//		if (N % 4 == 0) {
//			ans = "Yes";
//		} else {
//			for (int i = 0; i < 2; ++i) {
//				N -= 7;
//				if (N < 0) {
//					ans = "No";
//					break;
//				} else if (N % 4 == 0) {
//					ans = "Yes";
//					break;
//				}
//			}
//		}
//	}
//
//	//print
//	cout << ans << '\n';
//}
//
//void solve2() {
//	int N;
//	cin >> N;
//
//	//calculate
//	int ans = 0;
//
//	//print
//	cout << ans << '\n';
//}
//
//void solve3() {
//	int N;
//	cin >> N;
//
//	//calculate
//	string ans = "";
//	do {
//		if (N % 2 == 0) {
//			N /= -2;
//			ans = "0" + ans;
//		} else {
//			N -= 1;
//			N /= -2;
//			ans = "1" + ans;
//		}
//	} while (N != 0);
//
////print
//	cout << ans << '\n';
//}

void solve4() {
//	int N_MAX = 100000;
	int N, M, A;
	cin >> N >> M;
	int sum = 0;
	map<long long, int> mp;
	mp[0] = 1;
	long long ans = 0;
	for (int i = 0; i < N; ++i) {
		cin >> A;
		sum += A;
		sum %= M;
		ans += mp[sum];
		mp[sum]++;
	}
//	for (const auto& x : mp) {
//		std::cout << x.first << " => " << x.second << "\n";
//	}

//print
	cout << ans << '\n';
}

int main() {
	solve4();
	return 0;
}


Measured memory_bytes: 4224
#include <bits/stdc++.h>
#define rep(i,a,n) for (int i=a;i<n;i++)
#define per(i,a,n) for (int i=n-1;i>=a;i--)
#define fi first
#define se second
using namespace std;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int,int> ii;
typedef pair<double,double> dd;
typedef pair<char,char> cc;
typedef vector<ii> vii;
typedef long long ll;
typedef pair<ll, ll> l4;
typedef long double ld;
typedef pair<ld,ld> ldd;
const ld pi = acosl(-1);
const int maxn = 2010;
const ll mod = 998244353;
const ll inf = 1e18;
const ld eps = 1e-10;

string s;
int main() {
    cin >> s;
    int len = s.length();
    int ok = len%2;
    if (len%2 == 0) {
        char c = s[len/2];
        s = s.substr(0,len/2)+c+s.substr(len/2);
    }
    char c = s[len/2];
    int i = 0;
    while (i <= len/2 && s[len/2-i]==c && s[len/2+i]==c) i++;
    i--;
    printf("%d\n",len/2+ok+i);
}


Measured memory_bytes: 512
#include <bits/stdc++.h>
using intl = long long;
using itnl = long long;
using itn = int;
using ld = long double;
using namespace std;
#define rep(i, n) for(intl i = 0; i < (intl)(n); i++)
#define rrep(i, n) for(intl i = (intl)(n); i >= 0; i--)
#define repi(i, a, b) for(intl i = (intl)(a); i < (intl)(b); i++)
#define rrepi(i, a, b) for(intl i = (intl)(a); i >= (intl)(b); i--)
#define max(a, b) ((a) > (b) ? (a) : (b))
#define min(a, b) ((a) < (b) ? (a) : (b))
#define all(x) (x).begin(),(x).end()
#define m0(x) memset(x,0,sizeof(x))
#define m1(x) memset(x,1,sizeof(x))
#define fill(x,y) memset(x,y,sizeof(x))
#define alength(a) (sizeof(a) / sizeof(a[0]))
#define cin(i, a) rep(i, alength(a))cin >> a[i]
#define ccin(i, j, a) rep(i, alength(a))rep(j, alength(a[i]))cin >> a[i][j]
#define debug(x) cout << #x << ":" << x << endl
#define rdebug(i,x) rep(i, alength(x))cout << #x << "[" << i << "]:" << x[i] << endl
#define sqrt sqrtl
#define itn int
#define double ld
#define pb push_back
#define mp make_pair
const intl INF = 1e9;
const intl MOD = 1e9+7;
const ld eps = 1.0e-14;//-9
void fp(bool f){cout << (f ? "Yes" : "No") << endl;}
void fp(bool f, string s, string t){cout << (f ? s : t) << endl;}
intl kai(intl k){
    intl a = 1;
    for(int i = 2; i <= k; i++){
        a *= i;
    }
    return a;
}
intl gcd(intl a, intl b){
    if(!b)return a;
    return gcd(b, a % b);
}
intl lcm(intl a,intl b){
    return a / gcd(a, b) * b;
}
intl digit10(intl a){
    intl b = 0;
    do{
        a /= 10;
        b++;
    }while(a);
    return b;
}
signed main(){
    cout << fixed << setprecision(10);
    intl n;
    cin >> n;
    intl a[n];
    cin(i,a);
    sort(a,a+n,greater<>());
    intl b[2];
    m0(b);
    rep(i,n){
        b[i%2] += a[i];
    }
    cout << b[0] - b[1] << endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
using namespace std;
int main() {
    string S;
    cin >> S;
    int64_t len = S.size(), ans = 0;
    vector<int64_t> v1(len + 1, 0), v2(len + 1, 0);
    for (int32_t i = 0, cnt = 0; i < len; ++i) v1[i + 1] = cnt = S[i] == '<' ? cnt + 1 : 0;
    for (int32_t i = len - 1, cnt = 0; i >= 0; --i) v2[i] = cnt = S[i] == '>' ? cnt + 1 : 0;
    for (int32_t i = 0; i < len + 1; ++i) ans += max(v1[i], v2[i]);
    cout << ans << endl;
}


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

int main(void) {
	int R;
	cin >> R;
	if (R>=2800) {
		cout << "AGC" << endl;
	} else if (R>=1200) {
		cout << "ARC" << endl;
	} else {
		cout << "ABC" << endl;
	}
	return 0;
}


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

int main() {

	int n, m; cin >> n >> m;	
	vector<pair<int, int>> pa;
	vector<vector<int>> c(n);
	for (int i = 0; i < m; i++) {
		int a, b; cin >> a >> b;
		a--;
		pa.push_back({ a,b });
		c[a].push_back(b);
	}
	for (int i = 0; i < c.size(); i++) {
		sort(c[i].begin(), c[i].end());		
	}
	for (int i = 0; i < m; i++) {
		int x = pa[i].second;
		// int index = find(c[pa[i].first].begin(), c[pa[i].first].end(), x) - c[pa[i].first].begin();
		int index = upper_bound(c[pa[i].first].begin(), c[pa[i].first].end(), x) - c[pa[i].first].begin() - 1;
		cout << setw(6) << setfill('0') << pa[i].first + 1 << setw(6) << setfill('0') << index + 1 << endl;
	}	
	return 0;
}

Measured memory_bytes: 9544
import java.io.BufferedReader;
import java.io.FileReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.StringTokenizer;
 
public class Main {
	static ArrayList<Integer> primes;
	static int[] isComposite;

	static void sieve(int N)	// O(N log log N) 
	{
		isComposite = new int[N+1];					
		isComposite[0] = isComposite[1] = 1;			// 0 indicates a prime number
		primes = new ArrayList<Integer>();

		for (int i = 2; i <= N; ++i) 					//can loop till i*i <= N if primes array is not needed O(N log log sqrt(N)) 
			if (isComposite[i] == 0) 					//can loop in 2 and odd integers for slightly better performance
			{
				primes.add(i);
				if(1l * i * i <= N)
					for (int j = i * i; j <= N; j += i)	// j = i * 2 will not affect performance too much, may alter in modified sieve
						isComposite[j] = 1;
			}   
	}
	public static void main(String[] args) throws IOException {
		MScanner sc = new MScanner(System.in);
		//BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
		PrintWriter pw=new PrintWriter(System.out);
		int n=sc.nextInt();
		int[]in=new int[n];int dif=0;
		for(int i=0;i<n;i++) {
			in[i]=sc.nextInt();
			if(in[i]!=i+1)dif++;
		}
		if(dif==0 || dif==2) {
			pw.println("YES");
		}
		else {
			pw.println("NO");
		}
		
		
		pw.close();
		pw.flush();
 
	}
	static int gcd(int a, int b) {

		if (b == 0)
			return a;
		return gcd(b, a % b);
	}
    static class MScanner {
		StringTokenizer st;
		BufferedReader br;
 
		public MScanner(InputStream system) {
			br = new BufferedReader(new InputStreamReader(system));
		}
 
		public MScanner(String file) throws Exception {
			br = new BufferedReader(new FileReader(file));
		}
 
		public String next() throws IOException {
			while (st == null || !st.hasMoreTokens())
				st = new StringTokenizer(br.readLine());
			return st.nextToken();
		}
 
		public String nextLine() throws IOException {
			return br.readLine();
		}
 
		public int nextInt() throws IOException {
			return Integer.parseInt(next());
		}
 
		public double nextDouble() throws IOException {
			return Double.parseDouble(next());
		}
 
		public char nextChar() throws IOException {
			return next().charAt(0);
		}
 
		public Long nextLong() throws IOException {
			return Long.parseLong(next());
		}
 
		public boolean ready() throws IOException {
			return br.ready();
		}
 
		public void waitForInput() throws InterruptedException {
			Thread.sleep(3000);
		}
	}
}

Measured memory_bytes: 23124
#include <algorithm>
#include <cmath>
#include <deque>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <utility>
#include <vector>
#define MOD 1000000007
using namespace std;
typedef long long ll;
#include <cstring>

int main() {
  int n, k;
  cin >> n >> k;
  vector<int> a(n);
  for (int i = 0; i < n; i++) {
    cin >> a[i];
  }
  for (int i = 0; i + k < n; i++) {
    if (a[i] < a[i + k]) {
      cout << "Yes" << endl;
    } else {
      cout << "No" << endl;
    }
  }
}

Measured memory_bytes: 4048
#include <bits/stdc++.h>
// #pragma GCC optimize("Ofast")
// #pragma GCC target("avx,avx2,fma")
// #pragma GCC optimize("unroll-loops")
using namespace std;
typedef long long ll;

bool ok[100005];

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

    string s; cin >> s;
    int n = s.length();
    s = " " + s;

    bool gd = true;
    for (int i = 1; i <= n - 1; i++) {
        gd &= s[i] == s[n - i];
    }
    gd &= s[1] == '1' && s[n] == '0';
    if (!gd) {
        cout << -1 << endl;
        return 0;
    }

    s[n] = '1';

    int nxt = 0;
    for (int i = 1; i < n; i++) {
        while (nxt <= i || s[nxt] == '0')
            nxt++;
        cout << i << " " << nxt << endl;
    }
}

Measured memory_bytes: 1664
#include <iostream>
#include <algorithm>
#include <math.h>
#include <vector>
using namespace std;

int main(){
    string a;
    int ans = 0;
    cin >> a;
    
    for(int i = 0; i < 3; i++)
    {
        
        if (a[i] == '1') {
            ans++;
        }
        
    }
    cout << ans << endl;
    
    
}

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

int main(){
    int n, point_taro = 0, point_hanako = 0;
    string Taro, Hanako;

    cin >> n;
    for(int i = 0; i < n; i++){
        cin >> Taro >> Hanako;
        if(Taro > Hanako){
            point_taro += 3;
        }else if(Taro == Hanako){
            point_taro++;
            point_hanako++;
        }else{
            point_hanako += 3;
        }
    }
    
    cout << point_taro << " " << point_hanako << endl;
    return 0;
}




Measured memory_bytes: 3152
package main

import (
	"bufio"
	"fmt"
	"io"
	"os"
	"strconv"
)

func main() {
	fmt.Println(resolve(parseProblem(os.Stdin)))
}

func parseProblem(r io.Reader) (int, int, []int) {
	const (
		initialBufSize = 100000
		maxBufSize     = 1000000
	)
	buf := make([]byte, initialBufSize)

	sc := bufio.NewScanner(r)
	sc.Buffer(buf, maxBufSize)
	sc.Split(bufio.ScanWords) // bufio.ScanLines
	n, m := scanInt(sc), scanInt(sc)
	var as []int
	for i := 0; i < n; i++ {
		as = append(as, scanInt(sc))
	}
	return n, m, as
}

func primeCount(n, p int) (count int) {
	num := n
	for num%p == 0 {
		num /= p
		count++
	}
	return
}

func resolve(_, m int, as []int) int {
	l := as[0] / 2
	d := primeCount(as[0], 2)
	for i := 1; i < len(as); i++ {
		if d != primeCount(as[i], 2) {
			return 0
		}
		l = lcm(l, as[i]/2)
	}
	return ((m / l) + 1) >> 1
}

func lcm(a, b int) int {
	return a * b / gcd(a, b)
}
func gcd(a, b int) int {
	for b > 0 {
		t := a / b
		a, b = b, a-t*b
	}
	return a
}

// snip-scan-funcs
func scanInt(sc *bufio.Scanner) int {
	sc.Scan()
	i, _ := strconv.Atoi(sc.Text())
	return int(i)
}
func scanString(sc *bufio.Scanner) string {
	sc.Scan()
	return sc.Text()
}


Measured memory_bytes: 6784
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        String s = sc.next();
        long k = sc.nextLong();
        for (int i = 0; i < s.length(); i++) {
            char c = s.charAt(i);
            if ('1' == c) {
                continue;
            }
            if (k < i + 1) {
                System.out.println(1);
            } else {
                System.out.println(c);
            }
            return;
        }
        System.out.println(1);
    }

}


Measured memory_bytes: 22736
import math
n,g = map(int,input().split())
lis = []
sum = []
for i in range(n):
  a,b = map(int,input().split())
  lis.append([a,b])
  sum.append((i+1)*100*a+b)
def ans(x,y):
  if y <= 0:return 10 ** 12
  nu = min(math.ceil(x/(100 * y)),lis[y-1][0])
  num = 100 * y * nu
  if nu == lis[y-1][0]:num += lis[y-1][1]
  if num >= x:cou = nu
  else:cou = nu +ans(x-num,y-1)
  return min(cou,ans(x,y-1))

print(ans(g,n))

Measured memory_bytes: 3064