akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;
inline void rd(int &x){
  int k, m=0;
  x=0;
  for(;;){
    k = getchar_unlocked();
    if(k=='-'){
      m=1;
      break;
    }
    if('0'<=k&&k<='9'){
      x=k-'0';
      break;
    }
  }
  for(;;){
    k = getchar_unlocked();
    if(k<'0'||k>'9'){
      break;
    }
    x=x*10+k-'0';
  }
  if(m){
    x=-x;
  }
}
inline void wt_L(char a){
  putchar_unlocked(a);
}
inline void wt_L(int x){
  char f[10];
  int m=0, s=0;
  if(x<0){
    m=1;
    x=-x;
  }
  while(x){
    f[s++]=x%10;
    x/=10;
  }
  if(!s){
    f[s++]=0;
  }
  if(m){
    putchar_unlocked('-');
  }
  while(s--){
    putchar_unlocked(f[s]+'0');
  }
}
int main(){
  int N, res;
  rd(N);
  res = 800*N - 200 * (N/15);
  wt_L(res);
  wt_L('\n');
  return 0;
}
// cLay varsion 20190721-1

// --- original code ---
// {
//   int N, res;
//   rd(N);
//   res = 800N - 200 * (N/15);
//   wt(res);
// }


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
#define ll long long
#define rep(i,n) for (int i = 0; i < (n); i++)

int cnt_digits(ll N){
 int digits=0;

 while(N>0){
 N/=10;
 digits++;
 }

 return digits;
 }
int main() {
  ll N;
  cin >> N;
  int ans=1e9;
  int cnt=0;
  int temp=0;
  for(ll i=1;i*i<=N;i++){
    if((N)%i==0){
      string A = to_string(i);
      string B = to_string(N/i);
      temp=max(A.size(),B.size());
      ans=min(ans,temp);
    }

  }
  cout << ans << endl;
}


Measured memory_bytes: 3652
#define _CRT_SECURE_NO_WARNINGS
#include<algorithm>
#include<cmath>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<functional>
#include<iomanip>
#include<iostream>
#include<list>
#include<map>
#include<queue>
#include<set>
#include<stack>
#include<string>
#include<utility>
#include<vector>

#define ll long long
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)   FOR(i,0,n)
#define FORR(i,a,b) for(int i=(a);i>=(b);--i)
#define REPR(i,n)   FORR(i,n,0)

using namespace std;

const int NMAX = 100000;
int istriangle[100001] = { 0 };
void make_triangle() {
	int k = 1;
	while (k*(k + 1) / 2 <= NMAX) {
		istriangle[k*(k + 1) / 2] = k + 1;
		k++;
	}
}


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

	if (istriangle[N] == 0) {
		cout << "No" << endl;
	}
	else {
		int m = istriangle[N];
		vector<vector<int>>S(m);
		int cnt = 1;
		REP(i, m - 1) {
			FOR(j, i + 1, m) {
				S[i].push_back(cnt);
				S[j].push_back(cnt);
				cnt++;
			}
		}
		cout << "Yes" << endl;
		cout << m << endl;
		REP(i, m) {
			cout << m - 1;
			for (auto itr = S[i].begin();itr < S[i].end();++itr) {
				cout << " " << *itr;
			}
			cout << endl;
		}

	}


	return 0;
}

Measured memory_bytes: 2688
#include<bits/stdc++.h>
using namespace std;
const int inf=0x3f3f3f3f;
int n,minn=inf;
int main()
{
	ios::sync_with_stdio(false);
	cin>>n;
	for (int i=1;i<n;i++)
	{
	  int a=i,b=n-i;
	  int sum=0;
	  while (a)
	  {
	  	sum+=a%10;
		a/=10; 
	  }
	  while (b)
	  {
	  	sum+=b%10;
		b/=10; 
	  }
	  minn=min(sum,minn);
	}
	cout<<minn<<endl;
	return 0;
} 

Measured memory_bytes: 256
N, M, K = map(int, input().split())

result = 0
p = 998244353
fact = [1, 1]  # fact[n] = (n! mod p)
factinv = [1, 1]  # factinv[n] = ((n!)^(-1) mod p)
inv = [0, 1]  # factinv 計算用


def cmb(n, r, p):
    if (r < 0) or (n < r):
        return 0
    r = min(r, n - r)
    return fact[n] * factinv[r] * factinv[n - r] % p


for i in range(2, N + 1):
    fact.append((fact[-1] * i) % p)
    inv.append((-inv[p % i] * (p // i)) % p)
    factinv.append((factinv[-1] * inv[-1]) % p)

for k in range(K + 1):
    c = cmb(N - 1, k, p)
    m = M % p
    n = pow(M - 1, N - k - 1, p)
    result = (result + c * m * n) % p

print(result)

Measured memory_bytes: 32704
#include<stdio.h>
int main(){
    int a,b,ans;
    scanf("%d",&a);
    scanf("%d",&b);
    if(a==1 && b==2){
        ans=3;
    }
    if(a==1 && b==3){
        ans=2;
    }
    if(a==2 && b==1){
        ans=3;
    }
    if(a==2 && b==3){
        ans=1;
    }
    if(a==3 && b==1){
        ans=2;
    }
    if(a==3 && b==2){
        ans=1;
    }
    printf("%d",ans);
    return 0;
}

Measured memory_bytes: 128
#include <iostream>
#include <math.h>
#include <algorithm>
#include <string>
#include <vector>

#include <cstring>
#include <set>
#include <map>
#include <queue>
#include <utility>

using namespace std;

typedef long long LL;

#define dump(c) { for (auto it = c.begin(); it != c.end(); ++it) if (it == c.begin()) cout << *it; else cout << ' ' << *it; cout << endl; } 


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

    LL ans = 0;

    LL currH = 0;;
    int currL = 0;
    for (int i = 0; i < N; ++i) {
        LL h;
        cin >> h;
        if (currH < h) {
            if (ans < currL) {
                ans = currL;
            }
            currL = 0;
        } else {
            ++currL;
        }
        currH = h;
    }
    if (ans < currL) {
        ans = currL;
    }

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 256
# -*- coding: utf-8 -*-
import fractions
a, b, c, d = map(int, input().split())

# cとdの最小公倍数
cd = int((c*d)/fractions.gcd(c, d))
# a未満で条件を満たす整数の個数
cnt_a = a-1
# b以下で条件を満たす整数の個数
cnt_b = b

cnt_a -= ((a-1) // c) + ((a-1) // d) - ((a-1) // cd)
cnt_b -= (b // c) + (b // d) - (b // cd)
print(cnt_b - cnt_a)


Measured memory_bytes: 5048
#include <bits/stdc++.h>
#define rep(i,n)for(long long i=0;i<(long long)(n);i++)
#define all(a) a.begin(), a.end()
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> P;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
 
const ll MOD=1e9+7;
const ll INF=1e18;
const int MAX=510000;
const double pi=acos(-1);
int dx[8] = {1,0,-1,0,1,1,-1,-1};
int dy[8] = {0,1,0,-1,-1,1,1,-1};
// int d[13]={0,31,28,31,30,31,30,31,31,30,31,30,31};


int main(){
  cin.tie(0);
  ios::sync_with_stdio(false); 
  
  int n;
  cin >> n;
  ll a=1,b=1;
  rep(i,n){
    ll l,r;
    cin >> l >> r;
      ll m = max((a+l-1)/l,(b+r-1)/r);
      a = l*m;
      b = r*m;
  }
  cout << a + b << endl;
  return 0;
}


Measured memory_bytes: 3656
#include <iostream>
#include <string>
using namespace std;
 
bool chk[244140624]; //5^12
int n;
string ins, s;
 
int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    
    cin >> n;
    for(int i=0; i<n; i++) {
        cin >> ins >> s;
        // ?????????????????????????????????h??????????????????
        int h = 0; 
        for (int i=0, l=s.size(); i<l; ++i) {
        	h *= 5;
            if (s[i] == 'A')
                h += 1;
            else if (s[i] == 'C')
                h += 2;
            else if (s[i] == 'G')
                h += 3;
            else
                h += 4;
        }
        
        if (ins[0] == 'i') {
            chk[h] = true;
        } 
        else {
            cout << (chk[h] ? "yes\n" : "no\n");
        }
    }
    return 0;
}

Measured memory_bytes: 10688
#include <stdio.h>

int main(void)
{
  int x, y, sw;
  
  while(1){
    scanf("%d %d", &x, &y);
    
    if(x == 0 && y == 0)
      break;
      
    if(x > y){
      sw = x;
      x = y;
      y = sw;
    }
    
    printf("%d %d\n", x, y);
  }
  return 0;
}

Measured memory_bytes: 1684
#include<bits/stdc++.h>
using namespace std;
int f[100001];
int main() {
    string s;
    int n,m;
    cin>>n>>m;
    cin>>s;
    for(int i=0;i<n-1;i++) {
        if(s[i]=='A'&&s[i+1]=='C') {
            f[i+1]=f[i]+1;
        }
        else f[i+1]=f[i];
    }
    for(int i=0;i<m;i++) {
        int a,b;
        cin>>a>>b;
        cout<<f[b-1]-f[a-1]<<endl;
    }
    return 0;
}

Measured memory_bytes: 1408
#include<iostream>
#include<bits/stdc++.h>
#include<string>
using namespace std;
int main()
{
  int n ;
  cin >> n  ;
  vector<int> v(n) ;
  vector<int> c(n) ;
  
  for(int i=0;i<n;i++){
    cin >> v[i] ;
  }
  
  for(int i=0;i<n;i++){
    cin >> c[i] ;
  }
  
  
  int gain = 0 ;
  for(int i=0;i<n;i++){
    if(v[i]>c[i]){
      gain += v[i]-c[i] ;
    }
  }
  
  cout << gain << endl ;
  return 0 ;
}




Measured memory_bytes: 256
/*
    Author: Nguyen Tan Bao
    Status:
    Idea:
*/

#include <bits/stdc++.h>
#define FI first
#define SE second
#define EPS 1e-9
#define ALL(a) a.begin(),a.end()
#define SZ(a) int((a).size())
#define MS(s, n) memset(s, n, sizeof(s))
#define FOR(i,a,b) for (int i = (a); i <= (b); i++)
#define FORE(i,a,b) for (int i = (a); i >= (b); i--)
#define FORALL(it, a) for (__typeof((a).begin()) it = (a).begin(); it != (a).end(); it++)
//__builtin_ffs(x) return 1 + index of least significant 1-bit of x
//__builtin_clz(x) return number of leading zeros of x
//__builtin_ctz(x) return number of trailing zeros of x

using namespace std;
using ll = long long;
using ld = double;
typedef pair<int, int> II;
typedef pair<II, int> III;
typedef complex<ld> cd;
typedef vector<cd> vcd;

const ll MODBASE = 1000000007LL;
const int MAXN = 3010;
const int MAXM = 1000;
const int MAXK = 16;
const int MAXQ = 200010;

int n, m, p, a[MAXN][MAXN];
ll dp[MAXN][MAXN][4];

int main() {
    ios::sync_with_stdio(0);
    cin.tie(nullptr);
    cin >> n >> m >> p;
    FOR(i,1,p) {
        int x, y, v;
        cin >> x >> y >> v;
        a[x][y] = v;
    }
    FOR(i,0,n) FOR(j,0,m) FOR(k,0,3) dp[i][j][k] = -1e18;
    dp[1][1][1] = a[1][1];
    dp[1][1][0] = 0;
    FOR(i,1,n)
        FOR(j,1,m)
            if (i == 1 && j == 1) continue;
            else {
                FOR(k,0,3) dp[i][j][k] = dp[i][j-1][k];
                FOR(k,0,3) dp[i][j][0] = max(dp[i][j][0], dp[i-1][j][k]);
                if (a[i][j]) {
                    FOR(k,1,3) dp[i][j][k] = max(dp[i][j][k], dp[i][j-1][k-1] + a[i][j]);
                    FOR(k,0,3) dp[i][j][1] = max(dp[i][j][1], dp[i-1][j][k] + a[i][j]);
                }
            }
    cout << max(max(dp[n][m][0], dp[n][m][1]), max(dp[n][m][2], dp[n][m][3]));
    return 0;
}


Measured memory_bytes: 321036
import java.util.*;
public class Main {
    public static void main(String args[]) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        if (n == 1) System.out.println("Hello World");
        else {
            int a = sc.nextInt(), b = sc.nextInt();
            System.out.println(a + b);
        }
    }
}

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

int H, W;
vector<string> field;
vector<vector<int>> step;
queue<vector<int>> tovisit;
vector<int> dx = { 0, 0, -1, 1 };
vector<int> dy = { 1, -1, 0, 0 };

void bfs() {
  int y = tovisit.front().at(0);
  int x = tovisit.front().at(1);
  tovisit.pop();
  for (int i = 0; i < 4; i++) {
    int ny = y + dy.at(i);
    int nx = x + dx.at(i);
    if (ny < 0 || ny >= H || nx < 0 || nx >= W) continue;
    if (field.at(ny).at(nx) == '#') continue;
    if (step.at(ny).at(nx) != -1) continue;
    step.at(ny).at(nx) = step.at(y).at(x) + 1;
    tovisit.push({ ny, nx });
  }
}

int main() {
  cin >> H >> W;
  for (int i = 0; i < H; i++) {
    string s;
    cin >> s;
    field.push_back(s);
    step.push_back(vector<int>(W, -1));
  }
  int block = 0;
  for (int i = 0; i < H; i++) {
    for (int j = 0; j < W; j++) {
      if (field.at(i).at(j) == '#') block++;
    }
  }
  tovisit.push({ 0, 0 });
  step.at(0).at(0) = 1;
  while (!tovisit.empty()) bfs();
  int distance = step.at(H-1).at(W-1);
  if (distance == -1) cout << -1 << endl;
  else cout << H*W - distance - block << endl;
}

Measured memory_bytes: 256
#include <iostream>
using namespace std;
int A[2][100];
int main(){
  int N;
  cin >> N;
  for(int i=0;i<2;i++){
  	for(int k=0;k<N;k++)cin >> A[i][k];
  }
  int gsum=A[0][0];
  for(int i=0;i<N;i++){
  	gsum+=A[1][i];
  }
  
  int gmax=gsum;
  for(int k=1;k<N;k++){
    gsum=gsum-A[1][k-1]+A[0][k];
  	gmax=max(gmax,gsum);
  }
  
  cout << gmax << endl;
  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <iomanip>
#include <cmath>
#include <stdio.h>
#include <queue>
#include <deque>
#include <cstdio>
#include <set>
#include <map>
#include <bitset>
#include <stack>
#include <cctype>
using namespace std;
int main() {
	long long n;
	cin >> n;
	long long ans = 0;
	for (long long i = 1; i * i < n; i++) {
		if ((n - i) % i == 0 && (n - i) / i > i) {
			ans += (n - i) / i;
		}
	}
	cout << ans << endl;
	return 0;
}

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

using namespace std;

const int maxn = 1e5 + 9;
long long result[maxn];

class dsu {
public:
	vector<int> parent, size;
	dsu(int n) : parent(n + 1), size(n + 1, 1) {
		for (int i = 0; i < n + 1; i++) {
			parent[i] = i;
		}
	}
	int find(int u) {
		if (u == parent[u]) return u;
		return parent[u] = find(parent[u]);
	}
	bool same(int u, int v) {
		u = find(u); v = find(v);
		return (u == v);
	}
	void merge(int u, int v) {
		u = find(u); v = find(v);
		if (same(u, v)) return;
		parent[u] = v;
		size[v] += size[u];
		size[u] = 0;
	}
	int get_size(int u) {
		u = find(u);
		return size[u];
	}
};

int main() {
	ios::sync_with_stdio(0);
	cin.tie(0); cout.tie(0);
	
	int n, m;
	cin >> n >> m;
	vector<pair<int, int>> edges;
	for (int i = 0; i < m; i++) {
		int a, b;
		cin >> a >> b;
		edges.push_back(make_pair(a, b));
	}
	long long inf = n * (n - 1LL) * 1LL / 2LL, tmp = inf;
	dsu uf(n);
	for (int i = 0; i < m; i++) {
		result[m - i - 1] = tmp;
		pair<int, int> edge = edges[m - i - 1];
		if (uf.same(edge.first, edge.second)) {
			continue;
		}
		int a = uf.get_size(edge.first), b = uf.get_size(edge.second);
		tmp += a * (a - 1LL) * 1LL / 2LL;
		tmp += b * (b - 1LL) * 1LL / 2LL;
		uf.merge(edge.first, edge.second);
		int size = uf.get_size(edge.first);
		tmp -= size * (size - 1LL) * 1LL / 2LL;
	}
	for (int i = 0; i < m; i++) {
		cout << result[i] << '\n';
	}
	
	return 0;
}


Measured memory_bytes: 3700
n,x=map(int,input().split())
a=list(map(int,input().split()))

ans=0
for i in range(n-1):
    left=a[i]
    right=a[i+1]
    if left+right<=x:
        continue
    eat=(left+right)-x
    ans+=eat
    a[i+1]=max(0, right-eat)
print(ans)


Measured memory_bytes: 14064
#include <iostream>
#include <iomanip>
#include <vector>
#include <string>
#include <cmath>
#include <map>
#include <climits>
#include <cassert>
#include <algorithm>
#include <utility>

using namespace std;
using Int = long long int;
using UInt = unsigned long long int;
using VI = vector<long long int>;
using VVI = vector<vector<long long int> >;

// 二つの値の最大値を求める関数
Int Max(const Int a, const Int b) {
    if (a >= b) {
        return a;
    } else {
        return b;
    }
}
// 分数の Ceil を求める関数
UInt Ceil(const UInt a, const UInt b) {
    if (a % b == 0) {
        return a / b;
    } else {
        return a / b + 1;
    }
}

int main(void) {
    Int h, w, n;
    cin >> h >> w >> n;
    cout << Ceil(n, Max(h, w)) << endl;
    return 0;
}


Measured memory_bytes: 3616
#include<bits/stdc++.h>
#define ll long long int
#define ull unsigned long long 
#define ff first
#define ss second
#define fast ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define pb push_back 
#define mp make_pair
#define inf 2000000009
#define mod 1000000007
using namespace std;
#define matrix vector<vector<ll > > 
matrix mul(matrix a ,matrix b)
{
	ll k1=a.size(),k2=a[0].size(),k3=b[0].size();
	matrix c(k1,vector<ll> (k3));
	for(ll i=0;i<k1;i++)
	{
		for(ll j=0;j<k3;j++)
		{
			for(ll k=0;k<k2;k++)
				c[i][j]=(c[i][j]+ (a[i][k]%mod)*(b[k][j]%mod)) %mod;
		}
	}
	return c;
}

matrix pow(matrix a,ll n)
{
	if(n==1)
		return a;
	if(n%2)
		return mul(a,pow(a,n-1));
	matrix x=pow(a,n/2);
	return mul(x,x);
}

int main()
{ 
    fast;
    ll n,k;
    cin>>n>>k;

    vector<vector<ll> > adj(n,vector<ll>(n));
    for(ll i=0;i<n;i++)
    	for(ll j=0;j<n;j++)
    		cin>>adj[i][j];

    	vector<vector<ll> > v=pow(adj,k);
    	ll ans=0;
    	for(ll i=0;i<n;i++)
    		for(ll j=0;j<n;j++)
    			ans=(ans+v[i][j])%mod;

    		cout<<ans<<endl;
 }

Measured memory_bytes: 2944
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <numeric>
#include <map>
#include <iomanip>
#include <limits.h>
#include <cmath>
#include <stdio.h>

using namespace std;    
typedef long long ll;
typedef pair<ll, ll> pll;
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
const bool DEBAG = false;
ll dp[100001][13]; // dp[i][k] i 桁目まで使ったとき，あまりが k になる組み合わせの数
const ll mod = 1000000007;

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

    
    
    for(int i = 0; i < 100001; i++){
        for(int j = 0; j < 13; j++){
            dp[i][j] = 0;
        }
    }

    dp[0][0] = 1;
    for(int i = 0; i < s.size(); i++){
        int c;
        if(s[i] == '?') c = -1;
        else c = s[i] - '0';

        if(c == -1){
            for(int j = 0; j < 10; j++){
                for(int ki = 0; ki < 13; ki++){
                    dp[i + 1][ (ki * 10 + j) % 13 ] += dp[i][ki];
                }  
            }
        }
        else{
            for(int ki = 0; ki < 13; ki++){
                dp[i + 1][ (ki * 10 + c) % 13 ] += dp[i][ki];
            }              
        }
        for(int ki = 0; ki < 13; ki++){
            dp[i + 1][ ki ] %= mod;
        }              


    }

    cout << dp[s.size()][5] << endl;
    
}

Measured memory_bytes: 10624
import sys


def main():
    n, m = map(int, sys.stdin.readline().split())
    g = [[] for i in range(n)]
    deg = [0] * n
    lines = sys.stdin.read().splitlines()
    for line in lines:
        l, r, d = map(int, line.split())
        g[l - 1].append((r - 1, d))
        deg[r - 1] += 1
    dis = [-1] * n
    for i in range(n):
        if deg[i]:
            continue
        stack = list([i])
        dis[i] = 0
        while len(stack):
            v = stack[-1]
            stack.pop()
            for u, d in g[v]:
                if dis[u] == -1:
                    dis[u] = dis[v] + d
                    stack.append(u)
    for v in range(n):
        for u, d in g[v]:
            if dis[v] + d != dis[u]:
                print('No')
                return
    print('Yes')


if __name__ == '__main__':
    main()


Measured memory_bytes: 55268
#include <iostream>
#include <sstream>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <string>
#include <vector>
#include <list>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <bitset>
#include <numeric>
#include <climits>
#include <cfloat>
using namespace std;

int main()
{
    for(;;){
        int n;
        cin >> n;
        if(n == 0)
            return 0;

        vector<int> a(n);
        for(int i=0; i<n; ++i)
            cin >> a[i];
        sort(a.begin(), a.end());

        long long ret = 0;
        long long tmp = 0;
        for(int i=0; i<n; ++i){
            ret += tmp;
            tmp += a[i];
        }
        cout << ret << endl;
    }
}

Measured memory_bytes: 0
nlist = []
xlist = []

while(1):
    n, x = map(int, input().split())
    if n == 0 and x == 0:
        break
    nlist.append(n)
    xlist.append(x)

for n, x in zip(nlist, xlist):
    cnt = 0
    for i in range(1, n+1):
        for j in range(i+1, n+1):
            k = x - i - j
            if j < k <= n:
                cnt += 1
    print(cnt)


Measured memory_bytes: 5600
#include <bits/stdc++.h>
    using namespace std;
     
    int main() {
    	int n, m;
    	cin >> n >> m;
     
    	vector<string> vs(n, "");
     
    	for (int i = 0; i < m; ++i) {
    		int p;
    		string s;
    		cin >> p >> s;
    		p--;
     
    		vs[p] += s;
    	}
     
    	int ans = 0, pena = 0;
    	for (int i = 0; i < n; ++i) {
    		int sz = (int)vs[i].size();
    		bool ac = false;
    		for (int j = 0; j < sz; j+=2) {
    			string s = vs[i].substr(j, 2);
    			if(s == "AC") ac = true;
    		}
    		if (!ac) continue;
    		for (int j = 0; j < sz; j+=2) {
    			string s = vs[i].substr(j, 2);
    			if (s == "WA") pena++;
    			else if (s == "AC") {
    				ans++;
    				break;
    			}
    		}
    	}
     
    	printf("%d %d\n", ans, pena);
    	return 0;
    }

Measured memory_bytes: 5760
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vvvi = vector<vvi>;
using vll = vector<ll>;
using vvll = vector<vll>;
using vvvll = vector<vvll>;
using vs = vector<string>;
using pll = pair<ll, ll>;
using vp = vector<pll>;
#define rep(i, n) for (int i = 0; i < (n); i++)
#define repr(i, a, b) for (int i = (a); i < (b); i++)
#define ALL(a) (a).begin(), (a).end()
#define SZ(x) ((int)(x).size())
#define PRINT(V) for (auto v:(V)) {cerr << v << " ";} cerr << endl
#define dump(x) cerr << #x << " : " << (x) << endl
#define dump2(x, y) cerr << "(" << #x << ", " << #y << ") = (" << x << ", " << y << ")" << endl
inline ll GCD(ll a, ll b){return b ? GCD(b, a % b) : a;}
const ll MOD = 1000000007;
const ll INF = 100000000000000000LL;
/* END OF TEMPLATE */

int main(){
    cin.tie(0); ios::sync_with_stdio(false);
    ll p, q, r;
    cin >> p >> q >> r;
    cout << min({p+q, q+r, r+p}) << endl;
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int x,y;
    cin>>x>>y;
    if(y%2!=0)
        cout<<"No";
    else
    {
        if(y>x*4 || y<x*2)
            cout<<"No";
        else
            cout<<"Yes";
    }
  return 0;
}


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

#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>  // Including tree_order_statistics_node_update

using namespace __gnu_pbds;
using namespace std;

#define sz(a) int((a).size())
#define pb push_back
#define mp make_pair
#define all(c) (c).begin(), (c).end()
#define tr(c, i) for (__typeof((c).begin()) i = (c).begin(); i != (c).end(); i++)
#define present(c, x) ((c).find(x) != (c).end())
#define cpresent(c, x) (find(all(c), x) != (c).end())
#define minei(x) min_element(x.begin(), x.end()) - (x).begin()
#define maxei(x) max_element(x.begin(), x.end()) - (x).begin()
#define LSOne(S) (S & (-S))

#define uns(v) sort((v).begin(), (v).end()), v.erase(unique(v.begin(), v.end()), v.end())
#define acusum(x) accumulate(x.begin(), x.end(), 0)
#define acumul(x) accumulate(x.begin(), x.end(), 1, multiplies<int>());
#define bits(x) __builtin_popcount(x)
#define oo INT_MAX
#define inf 1000000000
#define MAXN 1000007
#define MOD 1000000007

const double pi = acos(-1.0);
const double eps = 1e-11;

typedef long long ll;
typedef pair<int, int> ii;
typedef vector<ii> vii;
typedef vector<int> vi;
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> indexed_set;

int main() {
    std::ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    int k;
    cin >> k;
    map<int, ll> currentGCD;
    ll res = 0;
    for (int i = 1; i <= k; i++) {
        for (int j = 1; j <= k; j++) {
            currentGCD[__gcd(i, j)]++;
        }
    }
    for (int i = 1; i <= k; i++) {
        for (auto it : currentGCD) {
            res += (__gcd(i, it.first) * it.second);
        }
    }
    cout << res << endl;

    return 0;
}


Measured memory_bytes: 3632
from collections import deque

def main():
  N = int(input())
  arr = list(map(float, input().split()))

  dp = [[0] * (N + 1) for _ in range(N + 1)]
  dp[0][0] = 1.0

  for i in range(N):
    for k in range(i + 1):
      dp[i + 1][k + 1] += dp[i][k] * arr[i]
      dp[i + 1][k] += dp[i][k] * (1.0 - arr[i])
  
  ans = 0.0
  for i in range(N // 2 + 1, N + 1):
    ans += dp[N][i]
  
  print(ans)



if __name__ == "__main__":
  main()

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

#define FAST_IO                       \
    ios_base::sync_with_stdio(false); \
    cin.tie(NULL);                    \
    cerr.tie(NULL);

#define dbg(x) cerr << #x << " = " << x << ",  ";
#define vw(v)                        \
    cerr << endl                     \
         << endl                     \
         << (#v) << " is: " << endl; \
    for (int B : (v))                \
    {                                \
        cerr << B << " ";            \
    }                                \
    cerr << endl
#define check(x) cerr << "here " << (x) << "?" << endl

#define rep(i, a, b) for (long long i = (a); i < (b); i++)
#define per(i, a) for (long long i = (a - 1); i >= 0; i--)

#define all(x) (x).begin(), (x).end()
#define rv(x) (x).rbegin(), (x).rend()
#define pb push_back

typedef long long ll;
ll const INF = 2147483647, R_INF = 9223372036854775807, MOD = 1e9 + 7;

//const int N =
void self_max(ll &x, ll y)
{
    x = max(x, y);
}
int main()
{
    FAST_IO
    int n, target;
    cin >> n >> target;

    vector<pair<int, int>> v(n);
    for (auto &i : v)
        cin >> i.first >> i.second;

    vector<ll> DP(target + 1, 0);
    rep(i, 0, n)
    {
        per(j, target + 1)
        {
            if (j - v[i].first >= 0)
            {
                self_max(DP[j], DP[j - v[i].first] + v[i].second);
            }
        }
    }
    per(i, target + 1) if (DP[i]) return cout << DP[i], 0;
}

Measured memory_bytes: 1024
#include <iostream>
#include <cstdio>
#include <set>
using namespace std;

int main(){
    long long n;
    cin >> n;
    set<string> T;

    string pre_word;

    for(long long i = 0; i < n; i++){
        string word;
        cin >> word;
        if(i == 0){
            T.insert(word);
            pre_word = word;
            continue;
        }

        if(T.find(word) != T.end()){
            printf("No\n");
            return 0;
        }
        else{
            if(word[0] != pre_word[pre_word.size()-1]){
                printf("No\n");
                return 0;
            }
            else{
                T.insert(word);
                pre_word = word;
            }
        }
    }

    printf("Yes\n");
    return 0;
}

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

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> P;
typedef vector<ll> V;
typedef complex<double> Point;

#define PI acos(-1.0)
#define EPS 1e-10
const ll INF = 1e16;
const ll MOD = 1e9 + 7;

#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define rep(i,N) for(int i=0;i<(N);i++)
#define ALL(s) (s).begin(),(s).end()
#define EQ(a,b) (abs((a)-(b))<EPS)
#define EQV(a,b) ( EQ((a).real(), (b).real()) && EQ((a).imag(), (b).imag()) )
#define fi first
#define se second
#define N_SIZE (1LL << 20)
#define NIL -1

ll n;
ll dp[110][10100];

int main(){
	cin >> n;
	vector<ll> s(n);
	rep(i,n)cin >> s[i];
	dp[0][0] = true;
	rep(i,n){
		rep(j,10100){
			if(j+s[i] >= 10100)continue;
			dp[i+1][j+s[i]] |= dp[i][j];
			dp[i+1][j] |= dp[i][j];
		}
	}
	for(int i = 10099;i >= 0;i--){
		if(dp[n][i] && (i%10)){
			cout << i << endl;
			return 0;
		}
	}
	cout << 0 << endl;
}

Measured memory_bytes: 8320
#include <bits/stdc++.h>
#define rep(i, n) for (int i=0; i<(int)(n); i++)
#define all(v) v.begin(), v.end()
#define allR(v) v.rbegin(), v.rend()
#define PRINT(v) for (auto x : (v)) cout <<x <<" " ; cout <<endl;
using namespace std;
using ll = long long;
using Graph = vector<vector<int>>;
typedef pair<int,int> Pi;
const ll MOD = 1000000007;
const ll INF = 10000000000000000;
const int inf = 1001001001;
vector<int> x4 = {0, 1, 0, -1}, x8 = {0, 1, 1, 1, 0, -1, -1, -1};
vector<int> y4 = {1, 0, -1, 0}, y8 = {1, 1, 0, -1, -1, -1, 0, 1};
template<class T> inline bool chmin(T& a, T b){if (a>b){a = b; return true;}return false;}
template<class T> inline bool chmax(T& a, T b){if (a<b){a = b; return true;}return false;}
template<class T> inline T powerM(T a,T b){if (b==0) return 1;
T tmp = powerM(a,b/2); if (b%2==0) return tmp*tmp%MOD; else return tmp*tmp%MOD*a%MOD; }
template<class T> inline T power(T a,T b,T m=numeric_limits<T>::max()){ if (b==0) return 1;
  T tmp = power(a,b/2,m); if (b%2==0) return tmp*tmp%m; else return tmp*tmp%m*a%m; }
template<class T> inline T gcd(T a, T b){if (b==0) return a; return gcd(b, a%b);}
template<class T> inline T lcm(T a, T b){return a / gcd(a,b) * b;}
// ax+by=gcd(a,b)を解く
template<class T> inline T extgcd(T a,T b,T &x,T &y){if (b==0){x=1; y=0; return a;} T d=extgcd(b,a%b,y,x); y -= a/b*x; return d;}
void hey(){ cout <<"hey" <<endl; }

template<class T> struct edge { int to; T cost;};


// 素因数分解O(√n)--------------------------------------------
template<class T> void prime_factor(T n, map<ll,T> &res){
  for (ll i=2; i*i<=n; i++){ while (n%i==0){ res[i]++; n/=i; } }
  if (n!=1) res[n]+=1;
}

int main() {
  ll N,P; cin >>N >>P;
  map<ll,ll> primes;
  prime_factor(P, primes);
  ll res = 1;
  for (auto p : primes){
    ll k = p.first;
    ll v = p.second;
    v /= N;
    res *= power(k, v);
  }
  cout <<res <<endl;
}

Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Runtime.InteropServices;
using System.Text;

namespace AtCoder
{
	class Program
	{
		static void Main(string[] args)
		{
			Question.Exec();
		}
	}

	public static class Question
	{
		public static void Exec()
		{
			var array = Console.ReadLine().Split(' ').Select(i => int.Parse(i)).ToArray();
			int A = array[0];
			int B = array[1];
			if (B % A == 0) {
				Console.WriteLine($"{A + B}");
			} else {
				Console.WriteLine($"{B - A}");
			}

			Console.ReadKey();
		}
	}
}

Measured memory_bytes: 13396
from collections import Counter


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

# R = [None] * (N + 1)
# R[N] = Counter()

R = Counter()
cnt = 0
for n in range(N - 1, 0, -1):
    R[(n + 1) - A[n]] += 1
    c = A[n - 1] + ((n - 1) + 1)
    cnt += R[c]

# ans = 0
# for i, Ai in enumerate(A):
#     # n < a
#     # c0 = i - a
#     # l = L[i][c0]

#     # n >= a
#     c1 = Ai + (i + 1)
#     r = R[i + 1][c1]

#     ans += r

print(cnt)


Measured memory_bytes: 109500
A = list(input())
backet = [0] * (ord('z') - ord('a') + 1)

for a in A:
  backet[ord(a) - ord('a')] += 1
n = len(A)
ans = n*(n-1)//2 + 1
for b in backet:
  ans -= b*(b-1)//2
print(ans)


Measured memory_bytes: 4840
#include<iostream>
#include<vector>
using namespace std;
int N;
int A[2<<17];
vector<int>G[2<<17];
int dp[2<<17];
int ans[2<<17];
void dfs(int u,int p,int R)
{
	int l=0,r=R;
	while(r-l>1)
	{
		int m=l+r>>1;
		if(dp[m]<A[u])l=m;
		else r=m;
	}
	int pre=dp[r];
	dp[r]=A[u];
	ans[u]=R==r?R++:R-1;
	for(int v:G[u])if(v!=p)dfs(v,u,R);
	dp[r]=pre;
}
main()
{
	cin>>N;
	for(int i=0;i<N;i++)cin>>A[i];
	for(int i=1;i<N;i++)
	{
		int u,v;cin>>u>>v;u--,v--;
		G[u].push_back(v);
		G[v].push_back(u);
	}
	for(int i=1;i<=N;i++)dp[i]=2e9;
	dfs(0,-1,1);
	for(int i=0;i<N;i++)cout<<ans[i]<<endl;
}


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

#define long long long int

using namespace std;

int main(){
    ios::sync_with_stdio(false);

    long n;
    cin >> n;
    long ans = LONG_LONG_MAX;
    for(long i = 1; i * i <= n; i++){
        long j = n / i;
        if(j * i == n){
            ans = min(ans, j+i-2);
        }
    }
    cout << ans;

    return 0;
}


Measured memory_bytes: 256
from operator import itemgetter
n=int(input())
info=[]
for i in range(n):
    s,p=input().split()
    info.append([s,int(p),i+1])
info=sorted(info)
memo=info[0][0]
l=[]
for k in range(n):
    if memo==info[k][0]:
        l.append(info[k][2])
    else:
        for j in range(len(l)):
            print(l[-1-j])
        l=[info[k][2]]
        memo=info[k][0]
for j in range(len(l)):
    print(l[-1-j])


Measured memory_bytes: 3064
#include <bits/stdc++.h>
#define all(v) (v).begin(), (v).end()
typedef long long int lint;
using namespace std;

//累積和
// vectorっぽく使う
template <typename T>
struct cumulative_sum {
    // data[i]:元の数列
    vector<T> data;
    // sum[i]:[0,i)の和
    vector<long long int> sum;
    //要素数を指定して初期化
    cumulative_sum(const int n) {
        data.assign(n, 0);
    }
    T& operator[](const int k) {
        return data[k];
    }
    // dataに基づいてsumを構築
    void build() {
        sum.assign(data.size() + 1, 0);
        for (int i = 0; i < (int)data.size(); i++) {
            sum[i + 1] = sum[i] + data[i];
        }
    }
    //[a,b)の和を求める
    long long int query(const int a, const int b) {
        return sum[b] - sum[a];
    }
};

int main() {
    lint n, k;
    cin >> n >> k;
    cumulative_sum<lint> a(n);
    for (int i = 0; i < n; i++) {
        cin >> a[i];
    }
    a.build();
    vector<lint> b;
    for (int left = 0; left <= n; left++) {
        for (int right = left + 1; right <= n; right++) {
            b.push_back(a.query(left, right));
        }
    }
    lint ans = 0;
    for (int i = 45; i >= 0; i--) {
        // k個のandでiビット目を立てられるか見る
        int num_bit = 0;
        for (int j = 0; j < b.size(); j++) {
            if (b[j] & ((lint)1 << i)) {
                num_bit++;
            }
        }
        if (num_bit >= k) {
            //粛清
            for (int j = 0; j < b.size(); j++) {
                if ((b[j] & ((lint)1 << i)) == 0) {
                    b[j] = 0;
                }
            }
            ans += (lint)1 << i;
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 6516
#include<bits/stdc++.h>
using namespace std;
typedef  long long ll;
using vll=vector<ll>;
using vvll=vector<vll>;
using vi=vector<int>;
using vvi=vector<vector<int>>;
using vb=vector<bool>;
using pii=pair<int,int>;
using vpii=vector<pair<int,int>>;
using plli=pair<ll,int>;
using vplli=vector<pair<ll,int>>;
using pllll=pair<ll,ll>;
using vpllll=vector<pair<ll,ll>>;

template<class T> inline bool chmin(T& a, T b) {if (a > b) {a = b;return true;}return false;}
template<class T> inline bool chmax(T& a, T b) {if (a < b) {a = b;return true;}return false;}

//pow(llpow,modpow)
template<class T> ll llpow(ll x,T n){ll ans=1;if(x==0)ans=0;while(n){if(n&1)ans*=x;x*=x;n>>=1;}return ans;}
long long modpow(long long a, long long n, long long mod) {long long res = 1;while (n > 0) {if (n & 1) res = res * a % mod;a = a * a % mod;n >>= 1;}return res;}
//最大公約数
template<class T> inline T gcd(T x,T y){if(y==0)return x; else {return gcd(y,x%y);}}
//最小公倍数
template<class T> inline T lcm(T x,T y){return x/gcd(x,y)*y;}
//逆元
long long modinv(long long a, long long m) {long long b = m, u = 1, v = 0;while (b) {long long t = a / b;a -= t * b; swap(a, b);u -= t * v; swap(u, v);}u %= m;if (u < 0) u += m;return u;}

#define rep(i, begin_i, end_i) for (ll i = (ll)begin_i; i < (ll)end_i; i++)
//試験導入
#define irep(i, end_i, begin_i) for (ll i = (ll)begin_i-1; i >= (ll)end_i; i--)

long long INF = 1LL<<60;
ll dp[210][210];
int main( ){
    rep(i,0,210)rep(j,0,210)if(i!=j)dp[i][j]=INF;else dp[i][j]=0;
    int n;
    cin>>n;
    int m;
    cin>>m;
    int R;
    cin>>R;
    rep(i,0,n){
        dp[i][i]=0;
    }
    vi r;
    rep(i,0,R){
        int v;
        cin>>v;
        v--;
        r.push_back(v);
    }
    sort(r.begin(),r.end());
    rep(i,0,m){
        int a,b;
        cin>>a>>b;
        a--,b--;
        ll c;
        cin>>c;
        dp[a][b]=c;
        dp[b][a]=c;
    }
    rep(i,0,n){
        rep(j,0,n){
            rep(k,0,n){
                chmin(dp[j][k],dp[j][i]+dp[i][k]);
            }
        }
    }
    ll res=INF;
     do{
        ll  ans=0;
        rep(i,0,R-1){
        ans+=dp[r[i]][r[i+1]];
        }
        chmin(res,ans);
    }while(next_permutation(r.begin(),r.end()));
    cout<<res<<endl;
    return 0;
}




Measured memory_bytes: 640
#include<bits/stdc++.h>
using ll = long long;
const ll INF_LL = 1000000000000;
#define fir first
#define sec second

ll ceil(ll a, ll b){
    return (a + b - 1) / b;
}


int main()
{
    int n;
    ll t,a;
    std::cin >> n >> t >> a;
    std::vector<ll> X(n), Y(n);
    for(int i = 0;i < n - 1; i++)std::cin >> X[i] >> Y[i];

    for(int i = 0; i < n - 1; i++){
        ll x = X[i], y = Y[i];
        ll bai = std::max(ceil(t,x), ceil(a,y));
        t = x * bai;
        a = y * bai;
        
    }
    std::cout << t + a << std::endl;
}


Measured memory_bytes: 256
// 問題の URL を書いておく
// https://atcoder.jp/contests/abc129/tasks/abc129_d

#include <algorithm>
#include <array>
#include <bitset>
#include <cmath>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <vector>

using namespace std;

//#define ENABLE_PRINT

#if defined(ENABLE_PRINT)

#define Print(v) \
do {\
    cout << #v << ": " << v << endl; \
}while(0)

#define PrintVec(v) \
do {\
    for(int __i = 0; __i < v.size(); ++__i) \
    { \
        cout << #v << "[" << __i << "]: " << v[__i] << endl; \
    }\
}while(0)

#else

#define Print(v) ((void)0)
#define PrintVec(v) ((void)0)

#endif

#define rep(i, n) for(int i = 0; i < (int)(n); ++i)

using ll = int64_t;

int main(int, const char**)
{
    int h, w;
    cin >> h >> w;
    vector<string> g(h);
    rep(i, h)
    {
        cin >> g[i];
    }
    vector<vector<vector<int>>> c(h, vector<vector<int>>(w, vector<int>(2, 0)));

    rep(i, h)
    {
        int count = 0;
        rep(j, w + 1)
        {
            if(j == w || g[i][j] == '#')
            {
                rep(k, count)
                {
                    c[i][j - k - 1][0] = count;
                }
                count = 0;
            }
            else
            {
                count++;
            }
        }
    }

    rep(i, w)
    {
        int count = 0;
        rep(j, h + 1)
        {
            if(j == h || g[j][i] == '#')
            {
                rep(k, count)
                {
                    c[j - k - 1][i][1] = count;
                }
                count = 0;
            }
            else
            {
                count++;
            }
        }
    }

    int ans = 0;
    rep(i, h)
    {
        rep(j, w)
        {
            ans = max(ans, c[i][j][0] + c[i][j][1] - 1);
        }
    }
    cout << ans << endl;

#if 0
    rep(i, h)
    {
        rep(j, w)
        {
            cout << c[i][j][0];
        }
        cout << endl;
    }

    rep(i, h)
    {
        rep(j, w)
        {
            cout << c[i][j][1];
        }
        cout << endl;
    }
#endif
    return 0;
}


Measured memory_bytes: 229768
#include <iostream>
#include <cmath>

using namespace std;

int main(){
  long long N; cin>>N;
  int ans=1;
  while(1){
    if(((ans+1)*(ans+1))>N){
      break;
    }
    ans++;
  }

  cout<<ans*ans<<endl;

  return 0;
}


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

#define rep(i, n) for (int i = 0; i < (n); i++)

using namespace std;

using ll = long long;

vector<pair<int, int>> factor(int n) {
  vector<pair<int, int>> res;
  for (int i = 2; i * i <= n; i++) {
    if (n % i == 0) {
      int ex = 0;
      while (n % i == 0) {
        ex++;
        n /= i;
      }
      res.push_back({i, ex});
    }
  }
  if (n != 1) res.push_back({n, 1});
  return res;
}

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n;
  cin >> n;
  const int mx = 1000010;
  vector<int> cnt(mx, 0);
  rep(i, n) {
    int a;
    cin >> a;
    vector<pair<int, int>> f = factor(a);
    for (auto&& [n, ex] : f) {
      cnt[n]++;
    }
  }
  bool pair = true, set = true;
  for (int i = 0; i < mx; i++) {
    if (cnt[i] > 1) pair = false;
    if (cnt[i] == n) set = false;
  }
  if (pair) {
    cout << "pairwise coprime";
  } else if (set) {
    cout << "setwise coprime";
  } else {
    cout << "not coprime";
  }
  return 0;
}

Measured memory_bytes: 7156
#include <bits/stdc++.h>
using namespace std;
#define int long long
template <typename T> void read(T &x) {
    x=0;int f=1;char c=getchar();
    while(c<'0'||c>'9'){if(c=='-')f=-1;c=getchar();}
    while(c>='0'&&c<='9') x =(x<<1)+(x<<3)+c-'0',c=getchar();x *= f;
}
const int N=1e5+10;
int n,val[N];
vector<int>edge[N];
void dfs(int x,int fa){
	int sum=0,mx=0;
	if(edge[x].size()==1)return;
	for(int i=0;i<edge[x].size();i++){
		int v=edge[x][i];
		if(v==fa)continue;
		dfs(v,x);sum+=val[v];mx=max(mx,val[v]);
	}
	if(val[x]>sum||sum>2*val[x]){
		puts("NO");exit(0);
	}
	if(sum-val[x]>sum-mx){
		puts("NO");exit(0);
	}
	val[x]-=sum-val[x];
	return;
}
signed main(){
	read(n);
	for(int i=1;i<=n;i++)read(val[i]);
	for(int i=1;i<n;i++){
		int u,v;
		read(u);read(v);edge[u].push_back(v);edge[v].push_back(u);
	}
	if(n==2){
		if(val[1]==val[2])return puts("YES")*0;
		else return puts("NO")*0;
	}
	int x=1;
	while(edge[x].size()==1)x++;
	dfs(x,0);
	if(val[x]!=0)return puts("NO")*0;
	else return puts("YES")*0;
	return 0;
}


Measured memory_bytes: 13184
#include <bits/stdc++.h>
#define Int int64_t

using namespace std;
using P = pair<int, int>;

int main() {
	vector<P> v(3);
	for (int i = 0; i < 3; ++i) {
		int a;
		cin >> a;
		v[i] = P(a, i + 1);
	}
	sort(v.begin(), v.end());

	if (v[1].second == 3) { cout << "Yes" << endl; }
	else { cout << "No" << endl; }

	return 0;
}


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

int N;
vector<int> D;
int ans=0;

int dp[2][(1<<24)];

int calc(int a,int b){
  int c=abs(a-b);
  return min(c,24-c);
}
                      
int main(){
  cin>>N;
  for(int i=0;i<N;i++){
    int x;
    cin>>x;
    D.push_back(x);
  }

  sort(D.begin(),D.end());
  
  if(N+1>24 || D[0]==0){ // N>23
    cout<<0<<endl;
    return 0;
  }
  
  // N<=23
  dp[0][1]=1;
  
  for(int i=0;i<N;i++){

    int ai=i%2;
    int bi=1-ai;
    
    for(int bit=0;bit<(1<<24);bit++)dp[bi][bit]=0;
    
    for(int bit=0;bit<(1<<24);bit++){
      if(dp[ai][bit]==0)continue;
      int a=D[i];
      int b=12-a + 12;
      if( (bit&(1<<a)) == 0 )dp[bi][bit|(1<<a)]=1;
      if(b<24 && (bit&(1<<b)) == 0 )dp[bi][bit|(1<<b)]=1;
    }
  }

  int ans=0;
  for(int i=0;i<(1<<24);i++){
    //    if( __builtin_popcount(i) != N+1 )continue;

    if( dp[ N%2 ][ i ]==0)continue;
    //    cout<<i<<endl;
    
    int mini=1e9;
    for(int a=0;a<24;a++)
      if(i>>a&1)
        for(int b=0;b<a;b++)
          if(i>>b&1)
            mini=min(mini, calc(a,b) );
    ans=max(ans,mini);
  }
  
  cout<<ans<<endl;
  return 0;
}


Measured memory_bytes: 131328
# abc104_b.py
S = input()
upper_cnt=0
for i,c in enumerate(S):
    if (i==0 and c!="A") or S[2:-1].count("C")!=1 or (i==1 and not c.islower()):
        print('WA')
        exit()
    if i>=1 and c.isupper():
         upper_cnt+=1
    if upper_cnt >1:
        print('WA')
        exit()
print('AC')



Measured memory_bytes: 3064
#define _USE_MATH_DEFINES

#include <iostream>
#include <iomanip>
#include <string>
#include <vector>
#include <algorithm>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <cmath>
using namespace std;

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


const int BIG_NUM = 1e8;
const ll INF = 1000000000000000000;

const int ALPHABET = 26;

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

	vector<int> a(n);
	vector<int> b(m);

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

	for (int i = 0; i < m; i++) {
		cin >> b[i];
	}

	vector<ll> sa(1);
	vector<ll> sb(1);

	for (int i = 0; i < n; i++) {
		sa.emplace_back(sa[i] + a[i]);

		if (sa[i + 1] > k) {
			break;
		}
	}
	for (int i = 0; i < m; i++) {
		sb.emplace_back(sb[i] + b[i]);
		if (sb[i + 1] > k) {
			break;
		}
	}

	int ans = 0;
	for (int i = sa.size()-1; i >= 0; i--) {
		int j = (upper_bound(sb.begin(), sb.end(), k - sa[i]) - sb.begin())-1;

		ans = max(ans, i + j);
	}

	cout << ans << endl;
	

}

Measured memory_bytes: 9508
import collections

n = int(input())
a= list(map(int,input().split()))
c = collections.Counter(a)

mx = 0

for item, value in c.items():
    mx += value * (value-1) // 2

for i in range(len(a)):
    ans = mx

    t = c[a[i]]
    ans -= t * (t-1) //2
    ans += (t-1)*(t-2) //2
    print(ans)


Measured memory_bytes: 26780
n = gets.to_i
t, a = gets.split.map(&:to_i)
h = gets.split.map(&:to_i)

diff = Float::INFINITY
ans = nil

h.each_with_index do |hh, i|
  current_diff = (a - (t - hh*0.006)).abs 
  if current_diff < diff
    diff = current_diff
    ans = i+1
  end
end

puts ans

Measured memory_bytes: 1788
import java.util.*;

public class Main {

  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);

    // 累積和
    int n = sc.nextInt();
    int[] w = new int[n];
    int[] data = new int[n+1];
    int min = 100;

    for (int i = 0; i < n; i++) {
      w[i] = sc.nextInt();
    }

    for (int i = 1; i < n+1; i++) {
      data[i] = data[i-1] + w[i-1];
    }

    // for (int i = 0; i < n+1; i++) {
    //   System.out.println(data[i]);
    // }

    for (int i = 0; i < n+1; i++) {
      int s1 = data[i];
      int s2 = data[n] - data[i];
      // System.out.println(s1+"    "+s2);
      int abs = Math.abs(s1-s2);
      min = Math.min(min,abs);
    }

    System.out.println(min);
  }

}


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

using ll = long long;
using Vi = vector<int>;
using Vl = vector<ll>;
using Pii = pair<int, int>;
using Pll = pair<ll, ll>;

constexpr int I_INF = numeric_limits<int>::max();
constexpr ll L_INF = numeric_limits<ll>::max();

//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

using Tup = tuple<ll, ll, ll>;

void solve() {
    ll L;
    cin >> L;

    ll Ltmp = L;
    ll n = 0;
    while (Ltmp > 0) {
        Ltmp /= 2;
        ++n;
    }
    --n;

    vector<Tup> edges;
    ll base = 1;
    for (ll i = 0; i < n; i++) {
        edges.emplace_back(i, i + 1, 0);
        edges.emplace_back(i, i + 1, base);
        base <<= 1;
    }

    base >>= 1;
    ll h = base * 2 - 1;

    for (ll i = n - 1; i >= 0; i--) {
        ll t = L - base;
        if (t > h) {
            edges.emplace_back(i, n, t);
            L = t;
        }
        base >>= 1;
    }

    cout << n + 1 << " " << edges.size() << "\n";
    for (const auto& [a, b, c] : edges) {
        cout << a + 1 << " " << b + 1 << " " << c << "\n";
    }
}

//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

int main() {
#ifdef FASTIO
    cin.tie(0), cout.tie(0);
    ios::sync_with_stdio(false);
#endif
#ifdef FILEINPUT
    ifstream ifs("./in_out/input.txt");
    cin.rdbuf(ifs.rdbuf());
#endif
#ifdef FILEOUTPUT
    ofstream ofs("./in_out/output.txt");
    cout.rdbuf(ofs.rdbuf());
#endif
    solve();
    cout << flush;
    return 0;
}

Measured memory_bytes: 3668
n, p = map(int, input().split())
s = input()
ans = 0
# p == 2,5
if 10 % p == 0:
    for r in range(n):
        if int(s[r]) % p == 0:
            ans += r + 1
    print(ans)
    exit()

d = [0 for _ in range(n + 1)]
ten = 1

for i in range(n - 1, -1, -1):
    a = int(s[i]) * ten % p
    d[i] = (d[i + 1] + a) % p
    ten *= 10
    ten %= p

cnt = [0 for _ in range(p)]
for i in range(n, -1, -1):
    ans += cnt[d[i]]
    cnt[d[i]] += 1

#print(d)

print(ans)


Measured memory_bytes: 11208
#include<bits/stdc++.h>
using namespace std;
int main(){
    int N,Q ; cin >> N >> Q;
    string S ; cin >> S;
    vector<int> place(N , 0);
    vector<int> l(Q);
    vector<int> r(Q);
    
    for(int i = 0 ; i < N - 1 ; i++){
        if(S.substr(i , 2) == "AC"){
            place[i + 1] ++;
        }
    }
    for(int j = 0 ; j < N ; j++){
        place[j + 1] += place[j];
    }
    for(int k = 0 ; k < Q ; k++){
        cin >> l[k] >> r[k];
        cout << place[r[k] - 1] - place[l[k] -1] << endl;
    }
}

Measured memory_bytes: 2176