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

struct Edge {
  int to;
  int weight;
  Edge(int t, int w) : to(t), weight(w) {}
};
using ll = long long;
ll depth[100010];
using Graph = vector<vector<Edge>>;

void dfs(Graph &graph, int currentPoint, int parentPoint, ll totalWeight) {
  depth[currentPoint] = totalWeight;

  for (int i = 0; i < graph[currentPoint].size(); i++) {
    Edge e = graph[currentPoint][i];
    if (e.to == parentPoint) continue;

    dfs(graph, e.to, currentPoint, totalWeight + e.weight);
  }
}

// see: https://qiita.com/drken/items/4a7869c5e304883f539b
int main() {
  int N;
  cin >> N;

  Graph graph(N);

  for (int i = 0; i < N - 1; i++) {
    int from, to, weight;
    cin >> from >> to >> weight;
    from--, to--;

    graph[from].push_back(Edge(to, weight));
    graph[to].push_back(Edge(from, weight));
  }

  int Q, K;
  cin >> Q >> K;

  // K から from, to までのスコアを計算
  dfs(graph, K - 1, -1, 0);

  for (int i = 0; i < Q; i++) {
    int from, to;
    cin >> from >> to;
    from--, to--;

    cout << (depth[from] + depth[to]) << endl;
  }
}

Measured memory_bytes: 14336
/*

宣告——
汝身听吾号令，托付吾之命运于汝之剑，
应圣杯之召，若汝遵从此意志此理，回应吧。
在此起誓，吾愿成就世间一切之善行，吾愿诛尽世间一切之恶行。
汝为身缠三大言灵之七天，从抑止之轮显现吧，天秤之守护者！

*/
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<cassert>
#include<cmath>
#include<vector>
#include<queue>
#define ll long long
using namespace std;
inline int read(){
	int re=0,flag=1;char ch=getchar();
	while(!isdigit(ch)){
		if(ch=='-') flag=-1;
		ch=getchar();
	}
	while(isdigit(ch)) re=(re<<1)+(re<<3)+ch-'0',ch=getchar();
	return re*flag;
}
int n,a[200010],b[200010],x[500010],rk[500010],pos[500010];
inline bool cmp(int l,int r){
	return x[l]<x[r];
}
int main(){
//	freopen("in.in","r",stdin);
	n=read();int i;ll tota=0,totb=0;
	for(i=1;i<=n;i++){
		a[i]=read();b[i]=read();
		x[i]=a[i];x[i+n]=b[i];
		rk[i]=i;rk[i+n]=i+n;
		tota+=a[i];totb+=b[i];
	}
	sort(rk+1,rk+n*2+1,cmp);
	ll ans=min(tota,totb),sum=0,tmp=0,cur;
	for(i=1;i<=n*2;i++) pos[rk[i]]=i;
	for(i=1;i<=n;i++) sum+=x[rk[i]];
//	cout<<tota<<' '<<totb<<' '<<tmp<<'\n';
	for(i=1;i<=n;i++){
		if(x[i]>x[i+n]) cur=i;
		else cur=i+n;
		if(pos[cur]<n) tmp=0;
		else if(i==((rk[n]-1)%n+1)) tmp=x[cur]-x[rk[n-1]];
		else tmp=x[cur]-x[rk[n]];
//		cout<<"choose "<<i<<' '<<sum<<' '<<tmp<<' '<<rk[pos[i]]<<' '<<rk[pos[i+n]]<<'\n';
		ans=min(ans,sum+tmp);
	}
	printf("%lld\n",ans);
}

Measured memory_bytes: 5760
#include <bits/stdc++.h>
using namespace std;
 
#define ll long long
#define vvi vector< vector<int> >
#define vi vector<int>
#define All(X) X.begin(),X.end()
#define FOR(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define REP(i,n) for(int i=0;i<(int)(n);i++)
#define pb push_back
#define pii pair<int,int>
#define mp make_pair
#define shosu(X) fixed << setprecision(X)
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(){
  int sum[501][501];
  int n, m, q;
  cin >> n >> m >> q;
  int data[501][501];
  REP(i, 501) REP(j, 501) data[i][j] = 0;
  REP(i, 501) REP(j, 501) sum[i][j] = 0;
  REP(i, m){
    int l, r;
    cin >> l >> r;
    data[l][r]++;
  }
  int oldsum = 0;
  FOR(i, 1, 501){
    FOR(j, 1, 501){
      sum[i][j] = sum[i][j-1] + sum[i-1][j] - sum[i-1][j-1] + data[i][j];
    }
  }
  
  REP(i, q){
    int pp, qq;
    cin >> pp >> qq;
    cout << sum[qq][qq] - sum[pp-1][qq] - sum[qq][pp-1] + sum[pp-1][pp-1] << endl;
  }
}

Measured memory_bytes: 2944
import sys
input = sys.stdin.readline
sys.setrecursionlimit(200000)


def read():
    N = input().strip()
    return N,


def solve(N):
    c = N[-1]
    if c == "3":
        return "bon"
    elif c in ["0", "1", "6", "8"]:
        return "pon"
    return "hon"


if __name__ == '__main__':
    inputs = read()
    outputs = solve(*inputs)
    if outputs is not None:
        print("%s" % str(outputs))


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

#define rep(i, n) for(int (i)=0; (i)<(n); (i)++)
#define FILL0(x) memset(x,0,sizeof(x))

using namespace std;

typedef long long ll;
typedef pair<ll, ll> P;

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()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout << fixed << setprecision(20);


    int N, K;
    cin >> N >> K;

    int p[N];
    rep(i, N)
    {
        cin >> p[i];
    }

    sort(p, p+N);


    int ans=0;
    rep(i, K)
    {
        ans+=p[i];
    }

    cout << ans << endl;

    return 0;


}

Measured memory_bytes: 3640
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cmath>
#define ll long long
using namespace std;
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
int main(){
	ll a,b;cin>>a>>b;
	if(a<b)swap(a,b);
	ll g=gcd(a,b);ll ans=0;ll fu=g;
	for(int i=2;i<=sqrt(g);i++){
		if(g%i)continue;
		ans++;
		while(g%i==0)g/=i;
	}
	if(g > 1) ans ++;
	cout<<ans+1;
	return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
int main()
{
    char line[201];
    int i;
    fgets(line,201,stdin);
    for(i=0; line[i]!='\n'; i++)
    {
        if(line[i]>='a' && line[i]<='z')
            line[i]=line[i]-32;
        printf("%c",line[i]);
    }
    printf("\n");
    return 0;
}



Measured memory_bytes: 1976
import sys
input = lambda: sys.stdin.readline().rstrip()

def main():
    n, m = map(int, input().split())
    drinks = list()
    ans = 0
    for _ in range(n):
        drinks.append(list(map(int, input().split())))
    drinks = sorted(drinks, key=lambda x: x[0])
    for drink in drinks:
        if drink[1] >= m:
            ans += drink[0] * m
            break
        else:
            ans += drink[0] * drink[1]
            m -= drink[1]
    print(ans)
            
if __name__ == '__main__':
    main()

Measured memory_bytes: 29244
import heapq

X,Y,A,B,C=map(int,input().split())
plist=list(map(int,input().split()))
qlist=list(map(int,input().split()))
rlist=list(map(int,input().split()))

plist.sort(reverse=True)
qlist.sort(reverse=True)
rlist.sort(reverse=True)
plist2=plist[:X]
qlist2=qlist[:Y]
rlist2=rlist[:X+Y]

hp=[]
for p in plist2:
  heapq.heappush(hp,p)
hq=[]
for q in qlist2:
  heapq.heappush(hq,q)
  
for r in rlist2:
  if hp[0]<hq[0]:
    if r>hp[0]:
      heapq.heappop(hp)
      heapq.heappush(hp,r)
  else:
    if r>hq[0]:
      heapq.heappop(hq)
      heapq.heappush(hq,r)
      
#print(hp)
#print(hq)
print(sum(hp)+sum(hq))


Measured memory_bytes: 23360
import std.algorithm, std.conv, std.range, std.stdio, std.string;

void main()
{
  auto rd = readln.split.map!(to!int);
  auto w = rd[0], h = rd[1], x = rd[2], y = rd[3], r = rd[4];
  writeln(x >= r && x <= w - r && y >= r && y <= h - r ? "Yes" : "No");
}

Measured memory_bytes: 2488
import java.util.Scanner;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

public class Main {
    public static void main(String[] args) {

        Scanner sc = new Scanner(System.in);
        String S = sc.next();

        Pattern p = Pattern.compile("[ACGT]++");
        Matcher m = p.matcher(S);

        int max = 0;
        while (m.find()) {
            if ( max < m.group().length() ) max = m.group().length();
        }
        System.out.println(max);

    }

}

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

using namespace std;

typedef pair<int,int> ii;

#define int long long

int n,k;
int a[311];
int f[311][311];

int dp(int pos,int cur)
{
	if (pos >= n+1)
	{
		if (cur >= n-k)
			return 0;
		return 1e18;
	}	
	if (f[pos][cur] != -1)
		return f[pos][cur];
	int z = 1e18;
	z = min(z,dp(n+1,cur));
	for (int j=pos+1;j<=n;j++)
		z = min(z,dp(j,cur+1) + max(0LL,a[j] - a[pos]));		
	return f[pos][cur] = z;	
}

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

	cin >> n >> k;
	for (int i=1;i<=n;i++)
		cin >> a[i];
	for (int i=0;i<=300;i++)
		for (int j=0;j<=300;j++)
			f[i][j] = -1;
	cout << dp(0,0);
}       	

Measured memory_bytes: 1024
#include <bits/stdc++.h>
#include <iomanip> 
using namespace std; 
#define rep(i,a,b)		for(long int i=a;i<=b;i++)
#define MOD 1e9+7

long long int solve(int n)
{
	long long a[n+1];
	a[0]=2,a[1]=1;
	for(int i=2;i<=n;i++)
		a[i]=a[i-1]+a[i-2];
	return a[n];
}
int n;
int main() 
{ 
	ios::sync_with_stdio(false);
    cin.tie(NULL);  
    
    
	cin>>n;
	cout<<solve(n);
}
	

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

	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ
		Scanner scan=new Scanner(System.in);
		int L=scan.nextInt();
		int R=scan.nextInt();
		int d=scan.nextInt();
		int count=0;
		for(int i=L;i<=R;i++) {
			if(i%d==0) {
				count+=1;
			}
		}
		System.out.println(count);
	}

}


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

int p1,p2,a[300005],b[300005];
set<pair<int,int> > st;
vector<int> v1,v2;

int main()
{
	int h,w,m;
	cin>>h>>w>>m;
	
	while(m--)
	{
		int x,y;
		cin>>x>>y;
		st.insert(make_pair(x,y));
		a[x]++;
		b[y]++;
		
		if(a[x]>p1) v1.clear(),p1=a[x];
		if(a[x]==p1) v1.push_back(x);
		
		if(b[y]>p2) v2.clear(),p2=b[y];
		if(b[y]==p2) v2.push_back(y);
	}
	
	for(int i=0;i<v1.size();i++)
	 for(int j=0;j<v2.size();j++)
	  if(st.find(make_pair(v1[i],v2[j]))==st.end())
	  {
	  	cout<<p1+p2<<endl;
	  	return 0;
	  }
	
	cout<<p1+p2-1<<endl;
	return 0;
}

Measured memory_bytes: 21876
mod = 1000000007
eps = 10**-9


def main():
    import sys
    import heapq
    input = sys.stdin.buffer.readline

    def dijkstra(adj, start):
        # adj: [[to, cost] * vertices], 0th index must be empty
        inf = 1 << 60
        dist = [inf] * len(adj)
        dist[start] = 0
        q = []
        heapq.heappush(q, (0, start))
        while q:
            min_dist, v_from = heapq.heappop(q)
            if min_dist > dist[v_from]:
                continue
            v_tos = adj[v_from]
            for v_to, cost in v_tos:
                if min_dist + cost < dist[v_to]:
                    dist[v_to] = min_dist + cost
                    heapq.heappush(q, (dist[v_to], v_to))
        return dist

    N, M, S = map(int, input().split())
    K = 5001
    adj = [[] for _ in range(N * K + 1)]
    for _ in range(M):
        u, v, a, b = map(int, input().split())
        for j in range(a, K):
            uu = (u-1) * K + j + 1
            vv = (v-1) * K + (j-a) + 1
            adj[uu].append((vv, b))
            uu = (u - 1) * K + (j-a) + 1
            vv = (v - 1) * K + j + 1
            adj[vv].append((uu, b))
    for i in range(1, N+1):
        c, d = map(int, input().split())
        for j in range(K-1):
            adj[(i-1) * K + j + 1].append(((i-1) * K + min(j+c, K-1) + 1, d))

    S = min(5000, S)
    dist = dijkstra(adj, S + 1)
    for v in range(2, N+1):
        ans = 10**18
        for j in range(K):
            ans = min(ans, dist[(v-1) * K + j + 1])
        print(ans)


if __name__ == '__main__':
    main()


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

int main(void) {
	int H, N;
	cin >> H >> N;

	int sum = 0;
	for (int i = 0; i < N; ++i) {
		int a;
		cin >> a;
		sum += a;
	}

	cout << ((sum >= H) ? "Yes\n" : "No\n");
	return 0;
}


Measured memory_bytes: 256
n = gets.to_i
x = gets.split.map(&:to_f)
y = gets.split.map(&:to_f)
max, p1, p2, p3 = 0, 0, 0, 0;
max_array = []
n.times do |i|
  q = (x[i] - y[i]).abs
  max = q if q > max
  p1 += q
  p2 += q ** 2
  p3 += q ** 3
end
puts "#{p1}\n#{Math.sqrt(p2)}\n#{p3 ** Rational(1, 3)}\n#{max}"

Measured memory_bytes: 6220
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
typedef vector<int> VI;

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 (a>b) { a=b; return 1; } return 0; }
#define _overload3(_1,_2,_3,name,...) name
#define _rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(int i=int(a);i<int(b);++i)
#define rep(...) _overload3(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)
#define all(x) (x).begin(),(x).end()

const int mod = 1e9+7;




int main() {
    int n;
    cin >> n;
    vector<int> a(n);
    rep (i, n) {
        cin >> a[i];
    }
    int ans = 0;
    rep (i, n) {
        if (i % 2 == 0 && a[i] % 2 != 0) {
            ans++;
        }
    }
    cout << ans << endl;
}




Measured memory_bytes: 3592
#include<stdio.h>

void run(void) {
	int i, j, s, flag = 0, N;
	scanf("%d", &N);
	for(i = 0; i <= N/4 && flag == 0; ++i) {
		for(j = 0; j <= N/7 && flag == 0; ++j) {
			s = 4*i + 7*j;
			if(s == N) {
				flag = 1;
				printf("Yes");
			}
		}
	}
	if(flag == 0) printf("No\n");
}
int main() {
	run();
	return 0;
}

Measured memory_bytes: 128
/**
 * 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

struct rest{
        int id;
        string s;
        int price;
         bool operator <(const rest r){
            if(r.s == s)return price > r.price;
            return s < r.s;
        }
    };
class BGuidebook {
public:
    rest R[101];

void solve(std::istream& cin, std::ostream& cout) {
    int N;
    cin >> N;
    _for(i,N){
        string s;
        int p;
        cin >> s >> p;
        R[i] = {i+1, s, p};
    }
    sort(R, R+N);
    _for(i,N)cout << R[i].id << endl;
}
};


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


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <cmath>
#include <vector>
#include <queue>
#include <set>
#include <map>

#define rep(i,n) for(int i=0;i<n;i++)
#define ll long long int
#define MAX 1000000007

using namespace std;

struct UnionFind{
  vector<int> par,num;

  UnionFind(int N) : par(N),num(N){
    for(int i=0;i<N;i++){
      par[i] = i;
      num[i] = 1;
    }
  }

  int root(int x){
    if(par[x] == x) return x;
    return par[x] = root(par[x]);
  }

  void unite(int x, int y){
    int rx = root(x);
    int ry = root(y);
    if(rx == ry) return;
    par[rx] = ry;
    num[ry] = num[ry]+num[rx]; 
  }

  int get_num(int x){
    int rx = root(x);
    return num[rx];
  }

  bool same(int x, int y){
    int rx = root(x);
    int ry = root(y);
    return rx == ry;
  }
};

ll modpow(ll a, ll n, ll p){
  if(n == 0){
    return 1;
  }
  if(n%2 == 0){
    ll root = modpow(a,n/2,p);
    return (root * root+p) %p;
  }
  else{
    return (a*modpow(a,n-1,p)+p)%p;
  }
}
ll fact[220000], fact_inv[220000];

ll comb(ll n, ll m, ll p){
  return (fact[n]*fact_inv[m])%p*fact_inv[n-m]%p;
}

int main(void){
  int n,m,k;
  cin >> n >> m >> k;
  ll p = 998244353;

  fact[0]=1;
  // 階乗の計算
  rep(i, n) fact[i+1]=fact[i]*(i+1)%p;
  fact_inv[n] = modpow(fact[n],p-2,p);
  // 逆元の計算
  for(int i=n-1;i>=0;i--)fact_inv[i]=fact_inv[i+1]*(i+1)%p;

  ll ans = 0;
  for(int i=0;i<=k;i++){
    ll work = modpow(m-1,n-1-i,p)*comb(n-1,i,p);
    work %= p;
    ans += work;
    ans %= p;
  }
  ans = (ans*m)%p;

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


Measured memory_bytes: 6684
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <iomanip>
#include <cmath>
#include <vector>
#include <queue>
#include <map>
#include <set>
#include <time.h>

#define loop(i, num)  for (int i = 0; i < num; i++)

using namespace std;

string dat;

int main() {
    
    cin >> dat;
    
    int num = 0, sum = 0;
    
    loop (i, dat.size()) {
        
        num *= 10;
        
        num += dat[i] - '0';
        
        sum += dat[i] - '0';
        
    }
    
    cout << (num % sum ? "No" : "Yes") << endl;
    
}


Measured memory_bytes: 256
#include<stdio.h>

int main(void)
{
  int n,fx=0,t;
  scanf("%d",&n);
  t=n;
  while(t!=0){
    fx=fx+t%10;
    t=t/10;
  }
  if((n%fx)==0){
    puts("Yes");
  }else{
    puts("No");
  }
  return 0;
}


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

#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP0(i, n) for (int i = 0, i##_len = (n); i < i##_len; ++i)
#define REP1(i, n) for (int i = 1, i##_len = (n); i <= i##_len; ++i)

typedef long long LL;
typedef pair<int, int> pii;

const int INTINF = 1e9;
const LL LLINF = 1e18;

void solve()
{
    int N;
    cin >> N;
    vector<int> a(N);

    REP0(i, N)
    {
        cin >> a[i];
    }
    LL ans = LLINF;

    { // 偶数番目までの累積を正にする
        LL ans_e = 0;
        LL sign[2] = {1, -1};
        LL cumsum = 0;
        REP0(i, N)
        {
            cumsum += a[i];
            if (cumsum * sign[i % 2] <= 0)
            {
                ans_e += abs(cumsum) + 1;
                cumsum = sign[i % 2];
            }
        }
        ans = min(ans_e, ans);
    }

    { // 奇数番目までの累積を正にする
        LL ans_o = 0;
        LL sign[2] = {-1, 1};
        LL cumsum = 0;
        REP0(i, N)
        {
            cumsum += a[i];
            if (cumsum * sign[i % 2] <= 0)
            {
                ans_o += abs(cumsum) + 1;
                cumsum = sign[i % 2];
            }
        }
        ans = min(ans_o, ans);
    }
    cout << ans << endl;
}

int main(int argc, char const *argv[])
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    std::cout << std::fixed << std::setprecision(10);
    solve();
    return 0;
}

Measured memory_bytes: 640
#include <iostream>
#include <bits/stdc++.h>
#include <vector>
#include <algorithm>
typedef long long int ll;
using namespace std;
#define P 1000000007
#define rep(i,n) for(i=0;i<n;++i)
#define repp(i,a,n) for(i=a;i<n;++i)
#define repr(i,a,n) for(i=a;i>=n;--i)
#define pb push_back
#define mp make_pair
#define fi first
#define se second

ll binpowmod(ll a, ll b, ll m) {
    a %= m;
    ll res = 1;
    while (b > 0) {
        if (b & 1)
            res = res * a % m;
        a = a * a % m;
        b >>= 1;
    }
    return res;
}

ll binpow(ll a, ll b) {
    ll res = 1;
    while (b > 0) {
        if (b & 1)
            res = res * a;
        a = a * a;
        b >>= 1;
    }
    return res;
}

ll modInverse(ll n, ll p)
{
    return binpowmod(n, p-2, p);
}

int main() 
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    ll t,m,n,i,f=0,j,ans=0;
    cin >> n ;
    ll a[n+1];
    map<ll,ll> ma,mm;
    repp(i,1,n+1)
    {
        cin >> a[i] ;
        ma[a[i]+i]++;
        if(i>a[i])
        {
            mm[i-a[i]]++;
        }
    }
    for(i=1;i<=n;++i)
    {
        ans+=mm[i+a[i]];
    }
    //ans/=2;
    cout << ans ;
    return 0;
}

Measured memory_bytes: 30552
T = list(input())+["a"]
for i in range(len(T)):
    s = T[i:i+2]
    if "?" not in s:
        continue
    else:
        if s == ["?","?"]:
            T[i:i+2] = ["P","D"]
        elif s[0] == "?":
            if s[1] == "D":
                T[i] = "P"
            else:
                T[i] = "D"
        if s[1] == "?":
            if s[0] == "P":
                T[i+1] = "D"
            elif i == len(T)-2:
                T[i+1] == "D"
print("".join(T[:-1]))



Measured memory_bytes: 12076
//encoding:utf-8
//#include <iostream> //c++
//#include<stack> //スタックに関して　最新のデータから捨てる
//#include<queue> //キューに関して　最古のデータから捨てる
//#include<math.h>
//#include<vector>
//#include<algorithm> //sort とかにいる
#include<bits/stdc++.h>//vector,algorithm,que
#include<time.h> //時間にかんして

#define ll long long
#define MOD 1000000007
#define INF (1<<29)
using namespace std;
int main(){
  ll N;
  ll ag,as,ab;
  ll bg,bs,bb;
  cin >> N;
  cin>>ag>>as>>ab;
  cin>>bg>>bs>>bb;
  vector<ll> dp(N+1);
  ll g_v = bg-ag;
  ll s_v = bs - as;
  ll b_v = bb - ab;
  if(g_v>0){
    for(int i=ag;i<N+1;i++){
      dp[i] = max(dp[i],dp[i-ag]+g_v);
    }
  }
  if(s_v>0){
    for(int i=as;i<N+1;i++){
      dp[i] = max(dp[i],dp[i-as]+s_v);
    }
  }
  if(b_v>0){
    for(int i=ab;i<N+1;i++){
      dp[i] = max(dp[i],dp[i-ab]+b_v);
    }
  }
  ll tmp = 0;
  for(int i=0;i<N+1;i++){
    tmp = max(tmp,dp[i]);
  }
  ll M = N+tmp;
  vector<ll> dp2(M+1);
  g_v = -bg + ag;
  s_v = -bs + as;
  b_v = -bb + ab;

  if(g_v>0){
    for(int i=bg;i<M+1;i++){
      dp2[i] = max(dp2[i],dp2[i-bg]+g_v);
    }
  }
  if(s_v>0){
    for(int i=bs;i<M+1;i++){
      dp2[i] = max(dp2[i],dp2[i-bs]+s_v);
    }
  }
  if(b_v>0){
    for(int i=bb;i<M+1;i++){
      dp2[i] = max(dp2[i],dp2[i-bb]+b_v);
    }
  }
  tmp = 0;
  for(int i=0;i<M+1;i++){
    tmp = max(tmp,dp2[i]);
  }
  ll ans = M+tmp;
  cout<<ans<<endl;

  return 0;
}


Measured memory_bytes: 195584
def myAnswer(N:int,H:list) -> int:
   now = H.pop(0)
   counter = 0
   MAX = 0
   for h in H:
      if(now >= h):
         counter +=1
      else:
         MAX = max(counter,MAX)
         counter = 0
      now = h
   return max(MAX,counter)

def modelAnswer():
   tmp=1
def main():
   N = int(input())
   H = list(map(int,input().split()))
   print(myAnswer(N,H[:]))

if __name__ == '__main__':
   main()

Measured memory_bytes: 14224
D, N = map(int, input().split())
res = 0

if D == 0:
    for i in range(N):
        res += 1
elif D == 1:
    for i in range(N):
        res += 100
elif D == 2:
    for i in range(N):
        res += 10000

if N == 100:
    if D == 0:
        print(101)
    elif D == 1:
        print(10100)
    else:
        print(1010000)
else:
    print(res)

Measured memory_bytes: 3060
import java.io.IOException;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.Scanner;

class Main {
    public static void main (String[] args) throws IOException {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

        String dataset;
        StringBuilder sb = new StringBuilder("");
        while ((dataset = br.readLine()) != null) {
            char[] arr = dataset.toCharArray();
            while (!isDecoded(arr)) {
                shift(arr);
            }
            sb.append(arr);
            sb.append('\n');
        }

        System.out.print(sb);
    }

    private static char[] shift(char[] arr) {
        for (int i = 0; i < arr.length; i++) {
            if (arr[i] != ' ' && arr[i] != '.') {
                if (arr[i] == 'z') {
                    arr[i] = 'a';
                } else {
                    arr[i]++;
                }
            }
        }
        return arr;
    }

    private static boolean isDecoded(char[] arr) {
        for (int i = 0; i < arr.length - 3; i++) {
            if (arr[i] == 't' && arr[i+1] == 'h') {
                if (arr[i+2] == 'e' ||
                arr[i+2] == 'a' && arr[i+3] == 't' ||
                arr[i+2] == 'i' && arr[i+3] == 's') {
                    return true;
                }
            }
        }
        if (arr[arr.length-3] == 't' && arr[arr.length-2] == 'h' && arr[arr.length-1] == 'e') {
            return true;
        }
        return false;
    }
}

Measured memory_bytes: 24024
L = list(map(int,input().split()))
q = L[0]//(L[1]+L[2])
mod = L[0]%(L[1]+L[2])
if mod > L[1]:
    print(q*L[1]+L[1])
elif L[1]==0:
    print(0)
else:
    print(q*L[1]+mod%L[1])

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

long long int dp[3001][3001];

long long int solve(long long int a[],int n,int i,int j)
{
	if(i>j)
	{
		return(0);
	}
	if(dp[i][j]!=-1)
	{
		return(dp[i][j]);
	}
	long long int op1=a[i]+min(solve(a,n,i+2,j),solve(a,n,i+1,j-1));
	long long int op2=a[j]+min(solve(a,n,i+1,j-1),solve(a,n,i,j-2));
	return(dp[i][j]=max(op1,op2));
}
int main(int argc, char const *argv[])
{
	int n,i,j;
	cin>>n;
	long long int a[n];
	long long int sum=0;
	for(i=0;i<n;i++)
	{
		cin>>a[i];
		sum+=a[i];
	}
	for(i=0;i<=3000;i++)
	{
		for(j=0;j<=3000;j++)
		{
			dp[i][j]=-1;
		}
	}
	cout<<2*solve(a,n,0,n-1)-sum;
	return 0;
}






Measured memory_bytes: 70784
#include<bits/stdc++.h>
typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
#define repr(i,n) for(int i=n;i>=0;i--)
#define For(i,m,n) for(int i=m;i<n;i++)
#define Forr(i,m,n) for(int i=m;i>n;i--)
#define Sort(a) sort(a.begin(),a.end())
#define pb push_back
#define vll vector<ll>
#define vvll vector<vector<ll>>
#define INF 999999999999

int main(){
  int r; cin>>r;
  cout<<3*r*r<<endl;
  return 0;
}


Measured memory_bytes: 256
//Don't have to see. start------------------------------------------
var read = require('readline').createInterface({
  input: process.stdin, output: process.stdout
});
var obj; var inLine = [];
read.on('line', function(input){inLine.push(input);});
read.on('close', function(){
  obj = init(inLine);
  console.error('\n↑入力 ↓出力');
  Main();
});
function makeClone(obj){return (obj instanceof Set) ? new Set(Array.from(obj)) : JSON.parse(JSON.stringify(obj));}
function nextInt(){return myconv(next(),1);} function nextStrArray(){return myconv(next(),2);}
function nextIntArray(){return myconv(next(),4);} function nextCharArray(){return myconv(next(),6);}
function next(){return obj.next();} function hasNext(){return obj.hasNext();}
function init(input){  
  return {
    list : input, index : 0, max : input.length,
    hasNext : function(){return (this.index < this.max);},
    next : function(){if(this.hasNext()){return this.list[this.index++];}else{throw 'ArrayIndexOutOfBoundsException ‚There is no more input';}}
  };
}
function myout(s){console.log(s);}
function myerr(s){console.error('debug:' + require('util').inspect(s,false,null));}
//param "no" is
//unknown or outlier : return i. 1: parseInt.
//2: split space. 4: split space and parseInt.
//6: split 1 character. 7: split 1 character and parseInt.
//8: join space. 9: join nextline. 0: join no character.
function myconv(i,no){try{switch(no){case 1:return parseInt(i);case 2:return i.split(' ');case 4:return i.split(' ').map(Number);case 6:return i.split('');case 7:return i.split('').map(Number);case 8:return i.join(' ');case 9:return i.join('\n');case 0:return i.join('');default:return i;}}catch(e){return i;}}

//Don't have to see. end------------------------------------------
function Main(){
  var one = nextIntArray();
  var H = one[0];
  var W = one[1];
  var M = one[2];
  var hCount = new Array(H);
  var wCount = new Array(W);
  for(var i = 0; i < H; i++){
    hCount[i] = {
      count : 0,
      no : i
    };
  }
  for(var i = 0; i < W; i++){
    wCount[i] = {
      count : 0,
      no : i
    };
  }
  var mlist = new Set();
  for(var i = 0; i < M; i++){
    var tmp = nextIntArray();
    var l = tmp[0] - 1;
    var r = tmp[1] - 1;
    mlist.add(l + ":" + r);
    hCount[l].count++;
    wCount[r].count++;
  }
  hCount.sort(function(a,b){
    return b.count - a.count;
  });
  wCount.sort(function(a,b){
    return b.count - a.count;
  });
  var hMax = hCount[0].count;
  var wMax = wCount[0].count;
  var output = hMax + wMax - 1;
  var isOK = false;
  for(var i = 0; i < hCount.length; i++){
    if(isOK){
      break;
    }
    if(hCount[i].count < hMax){
      break;
    }
    for(var j = 0; j < wCount.length; j++){
      if(wCount[j].count < wMax){
        break;
      }
      if(!mlist.has(hCount[i].no + ":" + wCount[j].no)){
        output++;
        isOK = true;
        break;
      }
    }
  }
  myout(output);
}

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

using namespace std;

string n;

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

    cin >> n;

    if(n[0] == '7' || n[1] == '7' || n[2] == '7')
        cout << "Yes";
    else
        cout << "No";

    return 0;
}


Measured memory_bytes: 3608
#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>;

int main()
{
    int n;
    cin >> n;
    int a;
    vector<P> s(n+1);
    
    for (int i = 1; i <= n; i++) {
        cin >> a;
        s[i].first = a;
        s[i].second = i;
    }
    sort(s.begin(), s.end());
    for (int i = 1; i <= n; i++) {
        cout << s[i].second << " ";
    }
    printf("\n");

    return 0;
}

Measured memory_bytes: 4008
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int, int>;
using vi = vector<int>;
using vl = vector<ll>;
#define rep(i, n) for(ll i = 0;i < n;i++)
#define all(i) i.begin(), i.end()
template<class t, class u> bool cmax(t& a, u b) { if (a<b) {a = b; return true;} else return false; }
template<class t, class u> bool cmin(t& a, u b) { if (a>b) {a = b; return true;} else return false; }

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

  int n;
  cin >> n;
  vector<vi> c(3, vi(n));
  rep(i, n) {
    rep(j, 3) {
      cin >> c[j][i];
    }
  }

  vector<vi> dp(3, vi(n));

  rep(i, 3) {
    dp[i][0] = c[i][0];
  }

  rep(i, n-1) {
    rep(j, 3) {
      rep(k, 3) {
        if (j != k) {
          cmax(dp[k][i+1], dp[j][i] + c[k][i+1]);
        }
      }
    }
  }

  int ans = 0;
  rep(i, 3) {
    cmax(ans, dp[i][n-1]);
  }
  cout << ans << endl;
}


Measured memory_bytes: 3064
N, M = map(int, input().split())
A = []
B = []
# for _ in range(N):
#     A.append(list(input()))
# for _ in range(M):
#     B.append(list(input()))

for _ in range(N):
    A.append(input())
for _ in range(M):
    B.append(input())

for i in range(N - M + 1):
    for j in range(N - M + 1):
        # match
        flag = True
        for k in range(M):
            for l in range(M):
                if A[i + k][j + l] == B[k][l]:
                    pass
                else:
                    flag = False
                    break

            if not flag:
                break

        if flag:
            break

    if flag:
        break

if flag:
    print("Yes")
else:
    print("No")


Measured memory_bytes: 3064
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i = 0;i<n;i++)
#define erep(i,n) for(int i = 0;i<=n;i++)
#define rep1(i,n) for(int i = 1;i<n;i++)
typedef long long ll;
#define vint vector<int>
#define vstring vector<string>
#define vll vector<ll>
#define vbool vector<bool>
#define INF 100000000

ll gcm(ll a,ll b);

int main(){
  ll n,x;
  cin >> n >> x;
  vll A(n);
  rep(i,n){
    ll a;
    cin >> a;
    A[i] = abs(a-x);
  }
  ll ans = A[0];
  rep1(i,n){
    ans = gcm(ans,A[i]);
  }
  cout << ans << endl;
}

ll gcm(ll a,ll b){
  if(a < b) swap(a,b);
  if(b == 0) return a;
  return gcm(a%b,b);
}

Measured memory_bytes: 1024
n,a,b,c,d=[int(i) for i in input().split()]

for i in range(n):
  u= i * d - (n-1-i)*c
  l= i * c - (n-1-i)*d
  if a+l<= b <=a+u or a-u<=b<=a-l:
      print('YES')
      break
else:
  print('NO')


Measured memory_bytes: 3064
#include <stdio.h>

int main(void) {

  int x[3000], y[3000];
  int tmp, i, j=0, k;

  for(i=0;i<3000;i++){
    scanf("%d %d", &x[j], &y[j]);
    if( x[j] == 0 && y[j] == 0 ){
      break;
    }
    j++;
  }

  for(k=0;k<j;k++){
    if(x[k] > y[k]){
      tmp = y[k]; //If x is larger than y, swap x for y.
      y[k] = x[k];
      x[k] = tmp;
    }
    printf("%d %d\n", x[k], y[k]);

  }


  return 0;
}


Measured memory_bytes: 2044
def insertionSort(A, N):
    for i in range(1, N):
        v = A[i]
        j = i-1
        while j >= 0 and A[j] > v :
            A[j+1] = A[j]
            j = j - 1
        A[j+1] = v
        print(*A)

N = int(input())
A = list(map(int, input().split()))
print(*A)
insertionSort(A, N)


Measured memory_bytes: 5980
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <cmath>
#include <vector>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <queue>
#include <ctime>
#include <cassert>
#include <complex>
#include <string>
#include <cstring>
#include <chrono>
#include <random>
#include <queue>
#include <bitset>
#include <stack>
#include <iomanip>
using namespace std;
#define all(x) x.begin(), x.end()
typedef vector <int> vi;
typedef pair<int,int> ii;
typedef long long ll;
typedef long double ld;
const int mod = 1e9 + 7;
const ll inf = 3e18 + 5;
int add(int a, int b) { return (a += b) < mod ? a : a - mod; }
int mul(int a, int b) { return 1LL * a * b % mod; }
int sub(int a, int b) { return (a -= b) < 0 ? a + mod : a; }
int ctz(int x) { return __builtin_ctz(x); }
int clz(int x) { return __builtin_clz(x); }

int main(){
  ios_base::sync_with_stdio(false); cin.tie(0);
  #ifdef LOCAL
  freopen("input.txt", "r", stdin);
  freopen("output.txt", "w", stdout);
  #endif

  int n;
  cin >> n;
  vector <vi> c(10, vi(10));
  for(int i = 1; i <= n; i++){
    int num = i;
    vi digs;
    while(num > 0){
      digs.push_back(num % 10);
      num /= 10;
    }
    c[digs.front()][digs.back()]++;
  }
  int res = 0;
  for(int i = 0; i <= 9; i++){
    for(int j = 0; j <= 9; j++){
      res += c[i][j] * c[j][i];
    }
  }
  cout << res;
}

Measured memory_bytes: 256
#include <iostream>
//#include <iomanip>
#include <string>
#include <vector>
#include <algorithm>
#include <utility>
#include <set>
#include <map>
#include <queue>
//#include <deque>
//#include <bitset>
#include <math.h>
using namespace std ;
using ll = long long ;
//using ld = long double ;
using vll = vector<ll> ;
using vvll = vector<vll> ;
using vc = vector<char> ;
using vvc = vector<vc> ;
//using vb = vector<bool> ;
//using vvb = vector<vb> ;
using pll = pair<ll,ll> ;
#define all(v) v.begin(),v.end()
ll mod = 1000000007 ;
//long double pie = acos(-1) ;
ll INF = 1000000000000 ;

//void yorn(bool a){if(a) cout << "Yes" << endl ; else cout << "No" << endl ;}
//void YorN(bool a){if(a) cout << "YES" << endl ; else cout << "NO" << endl ;}
ll gcd(long long a,long long b){if(b==0) return a ; return gcd(b,a%b) ;}
ll lcm(long long a,long long b){return a/gcd(a,b)*b ;}
//ll sa(long long a,long long b){if(a>b) return a-b ; return b-a ;}
//void fix_cout(){cout << fixed << setprecision(20) ;}
void chmax(ll &a,ll b){	if(a<b) a = b ;}
void chmin(ll &a,ll b){ if(a>b) a = b ;}

int main(){
    ll n ; cin >> n ;
    vll a(n) ;
    for(auto &i:a) cin >> i ;
    ll g = 0 ;
    for(int i=0;i<n;i++) g = gcd(g,a[i]) ;
    if(g!=1){
        cout << "not coprime" << endl ;
        return 0 ;
    }
    vll p(1e6+1,1) ;
    for(int i=2;i<=1e6;i++){
        if(p[i]==1){
            p[i] = i ;
            ll pos = i*2 ;
            while(pos<=1e6){
                p[pos] = i ;
                pos += i ;
            }
        }
    }
    vll use(1e6+1,0) ;
    for(int i=0;i<n;i++){
        ll num = a[i] ;
        while(num!=1){
            use[p[num]]++ ;
            ll tmp = num ;
            while(num!=1&&p[num]==p[tmp]) num /= p[num] ;
        }
    }
    bool ok = true ;
    for(int i=0;i<=1e6;i++) ok &= (use[i]<=1) ;
    cout << (ok?"pairwise coprime":"setwise coprime") << endl ;
}


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

vector<pair<ll,int>> factorize(ll n) {
  vector<pair<ll,int>> res;
  for (ll i = 2; i*i <= n; ++i) {
    if (n % i) continue;
    res.emplace_back(i,0);
    while (n%i == 0) {
      n /= i;
      res.back().second++;
    }
  }
  if (n != 1) res.emplace_back(n,1);
  return res;
}

int main() {
    ll x;
    cin >> x;
    while (true) {
      vector<pair<ll,int>> v = factorize(x);
      if (v.size()==1 && v[0].second == 1) break;
      x++;
    }
    if (x == 1) cout << 2 << endl;
    cout << x << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define DIGIT 10
using namespace std;
int main() {
  string N, answer, x;
  int K, M;
  vector<bool> D(DIGIT,true);
  for (cin >> N >> K; K; K--) {
    cin >> M;
    D[M] = false;
  }
  for (int i = 0; i < N.length(); i++) {
    if (D[N[i]-'0']) {
      answer.push_back(N[i]);
    } else {
      bool valid = false;
      for (char c = N[i]+1; c < DIGIT+'0'; c++) {
        if (D[c-'0']) {
          answer.push_back(c);
          valid = true;
          break;
        }
      }
      if (valid) {
        cout << answer;
        for (char c = '0'; c < DIGIT+'0'; c++) {
          if (D[c-'0']) {
            cout << string(N.length()-answer.length(),c);
            return 0;
          }
        }
      } else {
        for (char c = '1'; c < DIGIT+'0'; c++) {
          if (D[c-'0']) {
            cout << c;
            for (char c = '0'; c < DIGIT+'0'; c++) {
          		if (D[c-'0']) {
            		cout << string(N.length(),c);
            		return 0;
          		}
        	}
          }
        }
      }
    }
  }
  cout << answer;
}

Measured memory_bytes: 256
from collections import Counter
n = int(input())
a = list(map(int, input().split()))

new_list = list()

for x in range(n):
    num = a[x]
    num_plus = num + 1
    num_minus = num - 1
    new_list.append(num_plus)
    new_list.append(num_minus)
    new_list.append(num)

d = dict(Counter(new_list))

print(max(d.values()))


Measured memory_bytes: 30420
#ceilevenoddformula
import math
import bisect
import copy
import time
from collections import Counter
#map(int,input().split())
#int(x) for x in input().split()
a,b,c=map(int,input().split())
k=int(input())
for i in range(k):
	if a>=b:
		b*=2
	elif b>=c:
		c*=2
if b>a and c>b:
	print('Yes')
else:
	print('No')






























Measured memory_bytes: 68832
#pragma GCC optimize ("Ofast")

#include <bits/stdc++.h>
using namespace std;
using LL = long long int;
#define incID(i, l, r) for(int i = (l)    ; i <  (r); ++i)
#define decID(i, l, r) for(int i = (r) - 1; i >= (l); --i)
#define incII(i, l, r) for(int i = (l)    ; i <= (r); ++i)
#define decII(i, l, r) for(int i = (r)    ; i >= (l); --i)
#define inc(i, n)  incID(i, 0, n)
#define dec(i, n)  decID(i, 0, n)
#define inc1(i, n) incII(i, 1, n)
#define dec1(i, n) decII(i, 1, n)
#define inID(v, l, r) ((l) <= (v) && (v) <  (r))
#define inII(v, l, r) ((l) <= (v) && (v) <= (r))
#define PB push_back
#define EB emplace_back
#define MP make_pair
#define MT make_tuple
#define FI first
#define SE second
#define FR front()
#define BA back()
#define ALL(v) v.begin(), v.end()
#define RALL(v) v.rbegin(), v.rend()
auto setmin   = [](auto & a, auto b) { return (b <  a ? a = b, true : false); };
auto setmax   = [](auto & a, auto b) { return (b >  a ? a = b, true : false); };
auto setmineq = [](auto & a, auto b) { return (b <= a ? a = b, true : false); };
auto setmaxeq = [](auto & a, auto b) { return (b >= a ? a = b, true : false); };
#define SI(v) static_cast<int>(v.size())
#define RF(e, v) for(auto & e: v)
#define until(e) while(! (e))
#define if_not(e) if(! (e))
#define ef else if
#define UR assert(false)
#define IN(T, ...) T __VA_ARGS__; IN_(__VA_ARGS__);
void IN_() { };
template<typename T, typename ... U> void IN_(T &  a, U &  ... b) { cin >> a; IN_(b ...); };
template<typename T                > void OUT(T && a            ) { cout << a << endl; }
template<typename T, typename ... U> void OUT(T && a, U && ... b) { cout << a << " "; OUT(b ...); }

// ---- ----

const int M = 10'000;
int A[M], B[M], aa, bb, mi, sum;
map<int, int,    less<int>> mA;
map<int, int, greater<int>> mB;
int main() {
	until(getchar_unlocked() == '\n') { }
	while(true) {
		char c = getchar_unlocked();
		if(c == '(' || c == ')') {
			sum += (c == '(' ? +1 : -1);
			setmin(mi, sum);
		} else {
			int a = -mi, b = sum - mi;
			if(a <= b) { if(a < M) { A[a] += sum; setmax(aa, a); } else { mA[a] += sum; } }
			else       { if(b < M) { B[b] += sum; setmax(bb, b); } else { mB[b] += sum; } }
			mi = 0, sum = 0;
			if(c == EOF) { break; }
		}
	}
	
	incII(i, 0, aa) {
		setmin(mi, sum - i);
		sum += A[i];
	}
	for(auto [i, Ai]: mA) {
		setmin(mi, sum - i);
		sum += Ai;
	}
	for(auto [i, Bi]: mB) {
		sum += Bi;
		setmin(mi, sum - i);
	}
	decII(i, 0, bb) {
		sum += B[i];
		setmin(mi, sum - i);
	}
	puts(mi >= 0 && sum == 0 ? "Yes" : "No");
}


Measured memory_bytes: 3644
#include <bits/stdc++.h>
using namespace std;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<string> vs;
typedef vector<bool> vb;
typedef vector<vb> vvb;
typedef pair<int, int> pii;
typedef long long ll;
typedef unsigned long long ull;
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(), (a).rend()
#define pb push_back
#define mp make_pair
#define loop(i,a,b) for(ull i=(a);i<ull(b);++i)
#define rep(i,n) loop(i,0,n)
#define iter(i,c) for(auto i=(c).begin(); i!=(c).end(); ++i)
#define riter(i,c) for(auto i=(c).rbegin(); i!=(c).rend(); ++i)
const double eps = 1e-10;
const double pi = acos(-1.0);
const double inf = (int)1e8;

int main(){
  int a,b;
  while(cin>>a>>b){
    cout << a+b << endl;
  }
  return 0;
}

Measured memory_bytes: 3036
#include <cstdio>
#include <cmath>
#include <complex>
using namespace std;

typedef complex<double> Point;

#define X real()
#define Y imag()

int n;
Point ps[2];
double rs[2];

int main() {
  scanf("%d", &n);
  while (n--) {
    for (int i=0; i<2; i++) {
      double x, y;
      scanf("%lf%lf%lf", &x, &y, &rs[i]);
      ps[i] = Point(x, y);
    }

    Point dp = ps[0]-ps[1];
    double d = sqrt(dp.X*dp.X+dp.Y*dp.Y);
    if (d > rs[0]+rs[1]) puts("0");
    else if (rs[1] > rs[0] + d) puts("-2");
    else if (rs[0] > rs[1] + d) puts("2");
    else puts("1");
  }
}

Measured memory_bytes: 2576
# -*- coding: utf-8 -*-


def main():
    from collections import Counter
    from itertools import combinations

    a = Counter(input())
    ans = 1

    # KeyInsight
    # 何も操作しない場合が1通り
    # 異なる文字(a-z)を2つ選ぶ組み合わせ

    # 以下の場合だと，組み合わせは増えない．
    # 例2：abcda．1文字目と5文字目の場合，2文字目と4文字目の場合の並びは同じ．
    # See:
    # https://www.youtube.com/watch?v=9OiB8ot3a0w
    for i, j in combinations(a.values(), 2):
        ans += i * j

    print(ans)


if __name__ == '__main__':
    main()


Measured memory_bytes: 3756
n = int(input())
arr = list(map(int, input().split()))

i = 1
j = n-2
forSum = arr[0]
revSum = arr[-1]

while(i <= j):
    if(forSum < revSum):
        forSum += arr[i]
        i += 1
    else:
        revSum += arr[j]
        j -= 1


print(abs(forSum-revSum))

Measured memory_bytes: 26764
#include <iostream>
#include <string>
#include <algorithm>
#include <utility>
#include <cmath>
#include <vector>
#include <queue>
#include <set>
#include <map>
#define rep(i, n) for(int i = 0; i < n; i++)
using namespace std;
typedef long long ll;
const ll mod = 1000000007;

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

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

    vector<vector<int>> visited(h, vector<int>(w));
    vector<vector<int>> color(h, vector<int>(w));  // color[i][j] : (i,j)が白のとき0、黒のとき1

	rep(i, h) {
		string s;
        cin >> s;
        rep(j, w) {
            if(s[j] == '#') {
                color[i][j] = 1;
            }
        }
	}

	ll ans = 0;
	rep(i, h) {
		rep(j, w) {
            
            if(visited[i][j]) {
                continue;
            }

            ll black = 0, white = 0;

			queue<pair<int, int>> Q;

            visited[i][j] = 1;
			Q.push(make_pair(i,j));

			while(!Q.empty()) {

				auto p = Q.front();
				Q.pop();

				int x = p.first;
                int y = p.second;

				if(color[x][y]) {
                    black++;
                } 
				else {
                    white++;
                } 

				rep(k, 4) {
                    
					int nx = x + dx[k];
                    int ny = y + dy[k];

                    if(nx < 0 || h <= nx || ny < 0 || w <= ny) {
                        continue;
                    }

                    if(color[x][y] == color[nx][ny]) {
                        continue;
                    }

                    if(visited[nx][ny]) {
                        continue;
                    }

                    visited[nx][ny] = 1;
					Q.push(make_pair(nx,ny));
				}

			}

			ans += black*white;
		}
	}

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

Measured memory_bytes: 1536
#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;
constexpr ll INF = (1LL << 55);
int main(){
  int n, k;
  cin >> n >> k;
  vector<int> a(n);
  rep(i,n) cin >> a[i];

  vector<ll> cum(n+1,0), pcum(n+1,0);

  for (int i = 0; i < n; i++) {
    cum[i + 1] = cum[i] + a[i];
    pcum[i + 1] = pcum[i] + max(0, a[i]);
  }

  ll res = -INF;

  for (int i = 0; i + k <= n; i++) {
    int r = i + k;
    ll tmp = max(0LL, cum[r] - cum[i]);
    tmp += pcum[i] + pcum[n] - pcum[r];
    res = max(res, tmp);
  }
  cout << res << endl;
  return 0;
} 

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

#define rep(i, n) for (int i = 0; i < n; ++i)
#define all(x) (x).begin(),(x).end()
#define endl "\n"

using ll = long long;
using P = pair<int,int>;
using mp =  map<int,int>;

const int MOD = 1e9 + 7;

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

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

    ll tot = 0;
    ll ans = 0;
    vector<int> over;
    rep(i, n){
        if(a[i] < b[i]){
            tot += b[i] - a[i];
            ans++;
        }
        if(a[i] > b[i]){
            over.push_back(a[i]-b[i]);
        }
    }
    sort(all(over), greater<int>());

    if(ans == 0) {
        cout << ans << endl;
        return 0;
    }
    for (auto& p : over) {
        ans++;
        tot -= p;
        if(tot < 0){
            break;
        }
    }
    if(tot > 0) {
        cout << -1 << endl;
    }else{
        cout << ans << endl;
    }


    return 0;
}


Measured memory_bytes: 1408
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<iomanip>
#include<math.h>
#include<complex>
#include<queue>
#include<deque>
#include<stack>
#include<map>
#include<set>
#include<bitset>
#include<functional>
#include<assert.h>
#include<numeric>
using namespace std;
#define REP(i, m, n) for (int i = (int)(m); i < (int)(n); ++i)
#define rep(i, n) REP(i, 0, n)
using ll = long long;
const int inf = 1e9 + 7;
const ll longinf = 1LL << 60;
const ll mod = 1e9 + 7;



string s;
int a;


int main(){

	cin >> s;
	for (int i = 0; i < 4; i++){
		if (s[i] == '+')a++;
		else a--;
	}

	cout << a << endl;

	return 0;
}


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

#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define ALL(obj) (obj).begin(), (obj).end()
#define INF 1e9
#define LINF 1e18
typedef long long ll;


int main() {
    ll N, K; cin >> N >> K;
    ll ans = K;
    REP(i,N-1){
        ans *= K-1;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3620
s = list(str(input()))
n = len(s)

i = 0
ans = "Yes"
while(i<((n-1)//2)):
  if s[i] != s[n-1-i]:
    ans = "No"
    break
  elif s[i] != s[(n-1)//2-1-i] or s[(n+3)//2-1+i] != s[n-1-i]:
    ans = "No"
    break
  i += 1
print(ans)

Measured memory_bytes: 3060