akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <string>
#include <cstdlib>
#include <cmath>
#include <vector>
#include <map>
#include <set>
#include <algorithm>
#include <queue>
#include <stack>
#include <functional>

using namespace std;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef pair<ll,ll> P;
typedef vector<P> vpl;
#define rep(i,n) for(ll i=0; i<(n); i++)
#define REP(i,a,b) for(ll i=(a); i<(b); i++)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
const int inf = 1<<30;
const ll linf = 1LL<<62;
const int MAX = 510000;
const int V = 100005;
ll dy[8] = {1,0,-1,0,1,-1,1,-1};
ll dx[8] = {0,1,0,-1,1,-1,-1,1};
const double pi = acos(-1);
template<typename T1,typename T2> inline void chmin(T1 &a,T2 b){if(a>b) a=b;}
template<typename T1,typename T2> inline void chmax(T1 &a,T2 b){if(a<b) a=b;}
template<typename T1,typename T2> inline void print2(T1 a, T2 b){cout << a << " " << b << endl;}
#define INT_MAX 1<<30
const int mod = 1e9+7;

int main(){
    string s; cin >> s;
    ll n = s.size();
    ll ans = 0;
    rep(i,n/2){
        if(s[i]!=s[n-i-1]) ans++;
    }
    cout << ans << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int,int> P;
typedef pair<ll, ll> Pll;
#define debug(var)  do{std::cout << #var << " : ";view(var);}while(0)
template<typename T> void view(T e){std::cout << e << std::endl;}
template<typename T> void view(const std::vector<T>& v){for(const auto& e : v){ std::cout << e << " "; } std::cout << std::endl;}
template<typename T> void view(const std::vector<std::vector<T> >& vv){ for(const auto& v : vv){ view(v); } }
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; }

const int MOD = 1000000007;
const int INF = 1e9;

const int mod = 1000000007;
const int inf = 1e9;
#define PI acos(-1);
int dx[4] = {1,-1,0,0};
int dy[4] = {0,0,1,-1};
int ddx[8] = {1,1,1,-1,-1,-1,0,0};
int ddy[8] = {0,1,-1,0,1,-1,1,-1};


int main(){
    int n;
    cin >> n;
    vector<ll> a(3*n);
    for(int i = 0; i < 3*n; i++) {
        cin >> a[i];
    }
    priority_queue<ll> q2;
    priority_queue<ll, vector<ll>, greater<ll>> q1;
    ll sumA = 0, sumB = 0;
    for(int i = 0; i < n; i++) q1.push(a[i]), sumA += a[i];
    for(int i = 2*n; i < 3*n; i++) q2.push(a[i]), sumB += a[i];
    vector<ll> A(3*n,0), B(3*n,0);
    A[n-1] = sumA;
    B[2*n] = sumB;
    for(int i = n; i < 2*n; i++) {
        int now = q1.top();
        if(now < a[i]){
            sumA = sumA + a[i] - now;
            q1.pop();
            q1.push(a[i]);
            A[i] = sumA;
        }else{
            A[i] = sumA;
        }
    }
    for(int i = 2*n-1; i >= n; i--) {
        int now = q2.top();
        if(now > a[i]) {
            sumB = sumB - now + a[i];
            q2.pop();
            q2.push(a[i]);
            B[i] = sumB;
        }else{
            B[i] = sumB;
        }
    }
    ll ans = -1e18;
    for(int i = n-1; i < 2*n; i++) {
        ll now = A[i] - B[i+1];
        chmax(ans, now);
    }
    cout << ans << endl;
}

Measured memory_bytes: 8948
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ld long double
#define REP(i,m,n) for(int i=(int)(m); i<(int)(n); i++)
#define rep(i,n) REP(i,0,n)
#define RREP(i,m,n) for(int i=(int)(m); i>=(int)(n); i--)
#define rrep(i,n) RREP(i,(n)-1,0)
#define all(v) v.begin(), v.end()
#define endk '\n'
const int inf = 1e9+7;
const ll longinf = 1LL<<60;
const ll mod = 1e9+7;
const ll mod2 = 998244353;
const ld eps = 1e-10;
template<typename T1, typename T2> inline void chmin(T1 &a, T2 b){if(a>b) a=b;}
template<typename T1, typename T2> inline void chmax(T1 &a, T2 b){if(a<b) a=b;}

ll gcd(ll x, ll y) {
  if(x > y)
    return gcd(y, x);
  else if(x == 0)
    return y;
  else
    return gcd(y % x, x);
}
ll lcm(ll x, ll y) {
  ll g = gcd(x, y);
  return g * (x / g) * (y / g);
}
int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int n; cin >> n;
  ll t=1, s=1;
  rep(i, n) {
    ll a, b; cin >> a >> b;
    ll m = longinf;
    if((t+a-1)/a*b >= s) chmin(m, (t+a-1)/a);
    if((s+b-1)/b*a >= t) chmin(m, (s+b-1)/b);
    t = a*m; s = b*m;
  }
  cout << t+s << endk;
  return 0;
}


Measured memory_bytes: 3656
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
const ll MOD = 1000000007;

int main(){
    ll H,W,N;
    cin >> H >> W >> N;
    ll r,c;
    cin >> r >> c;
    string S,T;
    cin >> S >> T;

    ll mrgn_l = c - 1, mrgn_r = W - c, mrgn_u = r - 1, mrgn_d = H - r;
    
    for(ll i = 0; i < N; i++){
        if(mrgn_l < 0 || mrgn_r < 0 || mrgn_u < 0 || mrgn_d < 0){
            cout << "NO" << "\n";
            return 0;
        }
        if(S[i] == 'L'){
            mrgn_l--;
        }
        else if(S[i] == 'R'){
            mrgn_r--;
        }
        else if(S[i] == 'U'){
            mrgn_u--;
        }
        else if(S[i] == 'D'){
            mrgn_d--;
        }
        //cout << mrgn_l << " " << mrgn_r << " "  << mrgn_u << " " << mrgn_d << "\n"; 
        if(mrgn_l < 0 || mrgn_r < 0 || mrgn_u < 0 || mrgn_d < 0){
            cout << "NO" << "\n";
            return 0;
        }
        if(T[i] == 'L'){
            if(mrgn_r < W - 1)
                mrgn_r++;
        }
        else if(T[i] == 'R'){
            if(mrgn_l < W - 1)
                mrgn_l++;
        }
        else if(T[i] == 'U'){
            if(mrgn_d < H - 1)
                mrgn_d++;
        }
        else if(T[i] == 'D'){
            if(mrgn_u < H - 1)
                mrgn_u++;
        }
        //cout << mrgn_l << " " << mrgn_r << " "  << mrgn_u << " " << mrgn_d << "\n" << "\n"; 
    }
    cout << "YES" << "\n";
    return 0;
} 


Measured memory_bytes: 776
#include <stdio.h>
#define maxn 200010
#define LL long long
#define mod 1000000007
LL a[maxn],sum,ans;
int main(){
	int n,i;
	scanf("%d",&n);
	for(i=1;i<=n;i++)scanf("%lld",&a[i]);
	for(i=2;i<=n;i++)sum=(sum+a[i])%mod;
	for(i=1;i<n;i++)ans=(ans+a[i]*sum)%mod,sum=((sum-a[i+1])%mod+mod)%mod;
	printf("%lld\n",ans);
	return 0;
}

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

import sys
import math


debug = False

def log(text):
    if debug:
        print(text)

def gcd(a, b):

    c = min(a, b)
    d = max(a, b)
    r = 0    
    while True:
        r = d % c
        if r == 0:
            break
        d = c
        c = r

    return c

def parse_input(lines_as_string = None):

    global debug
    lines = []
    if lines_as_string is None:
        debug = False
        lines.append(input())
    else:
        debug = True
        lines = [e for e in lines_as_string.split("\n")][1:-1]
    
    (k, ) = [int(e) for e in lines[0].split(" ")]

    return (k, )


def solve(k):

    result = 0
    mem = dict()
    for a in range(1, k+1):
        for b in range(1, k+1):
            for c in range(1, k+1):
                if (b, c) in mem:
                    d = mem[(b, c)] 
                else:
                    d = gcd(b, c)
                    mem[(b, c)] = d

                if (a, d) in mem:
                    e = mem[(a, d)] 
                else:
                    e = gcd(a, d)
                    mem[(a, d)] = e

                result = result + e
    
     
    return  result


def main():
    # 出力
    result = solve(*parse_input())
    if isinstance(result, list):
        for r in result:
            print("%s" % r, sep='')
    else:
        print("%s" % result, sep='')

if __name__ == '__main__':

    main()

Measured memory_bytes: 74112
#include <iostream>
#include <vector>
#include <utility>
#include <algorithm>
#include <cmath>
#include <string>
#include <map>

#define pb push_back
#define mp make_pair

using namespace std;

typedef vector<int> vi;
typedef pair<int, int> ii;
typedef vector<ii> vii;
typedef unsigned long long ull;
typedef long long ll;

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

  int res = 100000;
  for (int i = 0; i < s.size()-2; ++i) {
    int si = stoi(s.substr(i, 3));
    res = min(res, abs(753-si));
  }

  cout << res << endl;
  return 0;
}


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

bool is_prime(int x) {
    if (x <= 1) return false;
    else {
        for (int i=2; i*i<=x; i++) {
            if (x % i == 0) return false;
        }
        return true;
    }
}

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

    int p=x;
    while(!is_prime(p)) p++;

    cout << p << endl;
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define pb push_back
#define ppb pop_back
int a[10000];
int n;
int main()
{
	cin>>n;
	for (int i=1;i<=n;i++){
		cin>>a[i];
	}
	int s1=0;
	int s2=0;
	int mn=99999;
	for (int i=1;i<=n;i++){
		for (int j=1;j<=i;j++){
			s1+=a[j];
		}
		for (int j=i+1;j<=n;j++){
			s2+=a[j];
		}
		mn=min(mn,abs(s1-s2));
		s1=0;
		s2=0;
	}
	cout<<mn<<endl;
	return 0;
}



Measured memory_bytes: 256
from collections import deque
n = int(input())
v = [int(i) for i in input().split()]
v.sort()
vi = deque(v)
while len(vi) != 1:
	v0 = vi.popleft()
	v1 = vi.popleft()
	vadd = (v0+v1)/2
	vi.appendleft(vadd)
print(vi[0])

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

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

int w, h, cnt = -1;
int filed[21][21];

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

void bfs(int y, int x, int t, int d) {
    if (t > 10) return;
    int nx = x+dx[d], ny = y+dy[d];
    while (0 <= nx && nx < w && 0 <= ny && ny < h && filed[ny][nx] == 0) { nx += dx[d]; ny += dy[d]; }
    if (filed[ny][nx] == 3) {
        if (cnt == -1) cnt = t;
        else cnt = min(cnt, t);
        return;
    }
    if (nx == x+dx[d] && ny == y+dy[d]) return;
    else if (0 <= nx && nx < w && 0 <= ny && ny < h) {
        if (filed[ny][nx] == 1) {
            filed[ny][nx] = 0;
            for (int i = 0; i < 4; ++i) {
                bfs(ny-dy[d], nx-dx[d], t+1, i);
            }
            filed[ny][nx] = 1;
        }
    }
    return;
}

int main() {
    while (cin >> w >> h, (w||h)) {
        rep(i, 21) rep(j, 21) filed[i][j] = 0;
        int py, px;
        rep(y, h) rep(x, w) {
            cin >> filed[y][x];
            if (filed[y][x] == 2) {
                py = y; px = x;
                filed[y][x] = 0;
            }
        }
        cnt = -1;
        for (int i = 0; i < 4; ++i) {
            bfs(py, px, 1, i);
        }
        cout << cnt << endl;
    }
}

Measured memory_bytes: 2960
#include <cstring>
#include <iostream>
#include <numeric>
#include <bits/stdc++.h>
using namespace std;
int main(){
  int N;
  cin>>N;
  string s;
  cin>>s;
  long long counter=0;
  vector<int>R(4005);
  vector<int>G(4005);
  vector<int>B(4005);
  if(s.at(0)=='R'){
  R.at(0)=1;
  G.at(0)=0;
  B.at(0)=0;}
  else if(s.at(0)=='B'){
  R.at(0)=0;
  G.at(0)=0;
  B.at(0)=1;}
  else if(s.at(0)=='G'){
  R.at(0)=0;
  G.at(0)=1;
  B.at(0)=0;}
  for(int r=1; r<N;r++){
  if(s.at(r)=='R'){
  R.at(r)=R.at(r-1)+1;
  G.at(r)=G.at(r-1);
  B.at(r)=B.at(r-1);
  continue;}
  else if(s.at(r)=='G'){
  G.at(r)=G.at(r-1)+1;
  R.at(r)=R.at(r-1);
  B.at(r)=B.at(r-1);
  continue;}
  else if(s.at(r)=='B'){
  B.at(r)=B.at(r-1)+1;
  R.at(r)=R.at(r-1);
  G.at(r)=G.at(r-1);
  continue;}}
  for(int e=1; e<N-1;e++){
  if(s.at(e)=='R'){
  counter+=(B.at(e-1)*(G.at(N-1)-G.at(e)))+(G.at(e-1)*(B.at(N-1)-B.at(e)));
  continue;}
  else if(s.at(e)=='G'){
  counter+=(B.at(e-1)*(R.at(N-1)-R.at(e)))+(R.at(e-1)*(B.at(N-1)-B.at(e)));
  continue;}
  else{
  counter+=(R.at(e-1)*(G.at(N-1)-G.at(e)))+(G.at(e-1)*(R.at(N-1)-R.at(e)));}}
  long long i,j,k;
  for(i=1;i<N-1;i++ ){
  for(j=i-1;j>=0; j-- ){
  k=2*i-j;
  if(k>N-1){
  continue;}
  else if((s.at(i)!=s.at(j))&&(s.at(i)!=s.at(k))&&(s.at(j)!=s.at(k))&&N-1>=k){
  counter--;}}}
  cout<<counter<<endl;}


Measured memory_bytes: 3636
# -*- coding: utf-8 -*-
N = int(input())

def Sum(n):
    s = str(n)
    array = list(map(int, list(s)))
    return sum(array)

a=[]

a.append(Sum(N))

N_str = str(N)
N_str = list(map(int, list(N_str)))

"右端の数字を1下げたときの最大"
N_str = str(N)
N_str = list(map(int, list(N_str)))
N_str[0] = N_str[0] - 1
for i in range(1,len(N_str)):
    N_str[i] = 9
a.append(sum(N_str))

print(max(a))

Measured memory_bytes: 3064
#include <bits/stdc++.h>
typedef long long ll;
typedef long double ld;
const int INF = 1e9, MOD = 1e9 + 7, ohara = 1e6 + 10;
const ll LINF = 1e18;
using namespace std;

#define rep(i, n) for (int(i) = 0; (i) < (int)(n); (i)++)
#define rrep(i, a, b) for (int i = (a); i < (b); i++)
#define rrrep(i, a, b) for (int i = (a); i >= (b); i--)
#define all(v) (v).begin(), (v).end()
#define Size(n) (n).size()
#define Cout(x) cout << (x) << endl

ll n, cnt, ans, a[ohara], b[ohara], c, d, tmp, tmpp, m, h, w, x, y, sum, pos, k;
ld doua;
int dy[] = {1, 0, -1, 0};
int dx[] = {0, 1, 0, -1};
//int dy[]={-1,0,1,-1,1,-1,0,1};
//int dx[]={-1,-1,-1,0,0,1,1,1};
string alph("abcdefghijklmnopqrstuvwxyz"), s;
bool fl, used[ohara];
struct edge
{
    int to, cost;
};
vector<int> res;
vector<int> g[ohara];

//-------------------------↓↓↓↓↓↓------------------------

void dfs(int u)
{
    if (used[u])
        return;
    used[u] = true;
    for (auto &i : g[u])
        dfs(i);
    res.push_back(u);
}

void tsort()
{
    rep(i, n) dfs(i);
    reverse(all(res));
}

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

    cin >> n >> m;
    rep(i, m)
    {
        cin >> a[i] >> b[i];
        g[a[i]].push_back(b[i]);
    }
    tsort();
    //ans.size() == v ならソート成功。そうでなければ閉路が存在
    for (int i : res)
        Cout(i);
    return 0;
}



Measured memory_bytes: 27600
#include <stdio.h>

int main()
{
        int a, b, s, i, ii;

        while( EOF != scanf("%d %d", &a, &b) ){
                s = a + b;
                for(i=1, ii=0; i<=10000000; i*=10, ii++){
                        if( s < i ){
                                printf("%d\n", ii);
                                break;
                        }
                }
        }

        return 0;
}

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

int main(){
    int N;
    cin >> N ;
    int a[N];
    for (int i = 0; i < N; i++) {
        cin >> a[i];
    }
    for(int i = 0; i < N; i++){
        if(a[i]%2 == 0){
            if(a[i]%3 != 0 && a[i]%5 != 0){
                cout << "DENIED" << endl;
                return 0;
            }
        }
    }
    cout << "APPROVED" << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define fsp(x) fixed << setprecision(x)
#define xout cerr
const ll inf = LLONG_MAX;
const long double pi = acosl(-1);
void Yes() {cout << "Yes" << endl;}
void No() {cout << "No" << endl;}
void YES() {cout << "YES" << endl;}
void NO() {cout << "NO" << endl;}

int main() {
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
	//const ll p = 1e9 + 7;
	//const ll p = 998244353;

	ll x;
	cin >> x;
	ll ans = 1;
	while (x * ans % 360) ans++;
	cout << ans << endl;
}


Measured memory_bytes: 3612
#include <stdio.h>
#include <stdlib.h>
#include <iostream>
#include <sstream>
#include <string>
#include <vector>
#include <cstring>
#include <map>
#include <set>
#include <queue>
#include <math.h>
#include <algorithm>

using namespace std;

int main()
{
  int A, B;
  cin >> A >> B;
  if (A <= 5) {
    cout << 0 << endl;
  } else if (A <= 12) {
    cout << B / 2 << endl;
  } else {
    cout << B << endl;
  }
  return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;

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

		Scanner sc = new Scanner(System.in);
		int num = 0;
		String s = sc.next();
		for (int i = 0; i < 4; i++) {
			char c = s.charAt(i);
			if (c == '+') {
				num++;
			} else if (c == '-') {
				num--;
			}

		}
		System.out.println(num);

	}

}


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

int main(){
    ios::sync_with_stdio(false), cin.tie(nullptr);
    int N, M; cin >> N >> M;
    int left = 1, right = N;
    for(int i=0;i<M;i++){
        int l, r; cin >> l >> r;
        left = max(left, l);
        right = min(right, r);
    }
    cout << max(0, right-left+1) << endl;
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
#define INF 2e9
#define LINF 1e18
#define MOD 1000000007
#define PI 3.141592653589793
#define rep(i, n) for(ll i = 0; i < (ll)(n); i++)
#define input(x, n)for(ll i = 0; i <(ll)(n); i++)cin >> x[i];
#define until(i,n) for(ll i = 1; i <= (ll)(n); i++)
#define all(x) (x).begin(),(x).end()
#define dump(x) cout << #x << "=" << (x) << endl
#define YES(n) cout << ((n) ? "YES" : "NO") << endl
#define Yes(n) cout << ((n) ? "Yes" : "No") << endl

int main(){

    string s;
    ll cnt = 0;
    ll ans = 0;
    cin >> s;

    rep(i, s.length()){
        if(s[i] == 'A' || s[i] == 'C' || s[i] == 'G' || s[i] == 'T')cnt++;
        else {
            ans = max(cnt, ans);
            cnt = 0;
        }
    }

    ans = max(cnt, ans);
    cout << ans << endl;

}

Measured memory_bytes: 3592
#include<cstdio>
#include<algorithm>
int r[401][401];
int main(){
  int n,ma,mb,i,j,k;
  scanf("%d%d%d",&n,&ma,&mb);
  for(i=0;i<=10*n;i++){
    for(j=0;j<=10*n;j++){
      r[i][j]=-1;
    }
  }
  r[0][0]=0;
  for(i=0;i<n;i++){
    int a,b,c;
    scanf("%d%d%d",&a,&b,&c);
    for(j=10*i;j>=0;j--){
      for(k=0;k<=10*i;k++){
        if(r[j][k]>=0){
          r[j+a][k+b]=(r[j+a][k+b]==-1)?(r[j][k]+c):std::min(r[j+a][k+b],r[j][k]+c);
        }
      }
    }
  }
  int ans=-1;
  for(i=1;ma*i<=10*n&&mb*i<=10*n;i++){
    if(r[ma*i][mb*i]>=0){
      ans=(ans==-1)?r[ma*i][mb*i]:std::min(r[ma*i][mb*i],ans);
    }
  }
  printf("%d",ans);
  return 0;
}

Measured memory_bytes: 768
n, m = map(int, input().split())
cnt = [0 for i in range(n+1)]
for i in range(m):
    a, b = map(int, input().split())
    cnt[a] += 1
    cnt[b] += 1
if all([cnt[i]%2 == 0 for i in range(n)]):
    print('YES')
else:
    print('NO')


Measured memory_bytes: 4648
n=int(input())
s=[]
for i in range(n):
    t=input()#.rstrip()
    s.append(t)
#print(s)

for i in range(n):
    s[i]=sorted(s[i])

s=sorted(s)

ans=0
pos=0
while pos<=n-1:
    c=1
    while pos<=n-2 and s[pos]==s[pos+1]:
        c+=1
        pos+=1
    pos+=1
    ans+=c*(c-1)//2
print(ans)


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

#define MAXS    100010

int sl;
char s[MAXS];

int sn;
char neat[MAXS];
int pos[MAXS];

int check(void)
{
    int i;
    for(i = 1;i <= sn/2;++i)
        if(neat[i] != neat[sn-i])
            return 0;
    return 1;
}

int main(void)
{
    int i;
    scanf("%s", s+1); sl = strlen(s+1);
    if(1 == sl) puts("0");
    else
    {
        sn = 1;
        for(i = 1;i <= sl;++i)
            if('x' != s[i])
            {
                neat[sn] = s[i];
                pos[sn] = i;
                sn++;
            }
        pos[sn] = sl+1;
        if(check())
        {
            int cnt = 0;
            for(i = 1;i <= sn/2;++i)
                cnt += abs((pos[i]-pos[i-1])-(pos[sn-i+1]-pos[sn-i]));
            printf("%d\n", cnt);
        } else {
            puts("-1");
        }
    }
    return 0;
}


Measured memory_bytes: 768
#!/usr/bin/env python3

N, M = map(int, input().split())
plist = [[] for i in range(N)]
for i in range(M):
    p, S = input().split()
    # plist の i 番目の要素: 問題 i-1 に対する提出結果のリスト
    plist[int(p) - 1].append(str(S))
# print(N, M)
# print(plist)

count_AC = 0
sum_penalty = 0
for l in plist:
    penalty = 0
    if 'AC' in l:
        count_AC += 1
        penalty = l.index('AC')
    sum_penalty += penalty

print(count_AC, sum_penalty)


Measured memory_bytes: 20376
#include<iostream>
using namespace std;
int main(){
	int a,b,c,d;
	int s,t;
	
	cin>>a>>b>>c>>d;
	s=a+b+c+d;
	cin>>a>>b>>c>>d;
	t=a+b+c+d;
	
	if(s>=t){
		cout<<s<<endl;
	}else{
		cout<<t<<endl;
	}
	return 0;
}
	

Measured memory_bytes: 3112
#include <bits/stdc++.h>
#define For(i, a, b) for(int (i)=(a); (i)<(b); ++(i))
#define rFor(i, a, b) for(int (i)=(a)-1; (i)>=(b); --(i))
#define rep(i, n) For((i), 0, (n))
#define rrep(i, n) rFor((i), (n), 0)
#define fi first
#define se second
using namespace std;
typedef long long lint;
typedef pair<int, int> pii;

int n;
lint a[16][16], dp[1<<16];

lint dfs(int s){
    if(dp[s] > -1e18) return dp[s];
    lint ret = 0;
    rep(i, n)For(j, i+1, n)if(((s>>i)&1) && ((s>>j)&1)){
        ret += a[i][j];
    }
    for(int t=(s-1)&s; t>0; t=(t-1)&s){
        ret = max(ret, dfs(t) + dfs(s^t));
    }
    return dp[s] = ret;
}

int main(){
    scanf("%d", &n);
    rep(i, n)rep(j, n) scanf("%lld", &a[i][j]);
    rep(i, 1<<n) dp[i] = -1e18;
    printf("%lld\n", dfs((1<<n)-1));
}

Measured memory_bytes: 768
#include<iostream>
#include<cstdio>
#include<cstring>
#include<string>
#include<algorithm>
#include<cctype>
#include<cmath>
#include<cstdlib>
#include<queue>
#include<ctime>
#include<vector>
#include<set>
#include<map>
#include<stack>
using namespace std;
#define int long long
const int inf = 1e16+7;
int dp[200100][5],a[200100];
inline int wh2(int x){
	if(x==0)return 2;
	return x%2;
}
inline int wh1(int x){
	if(x==0)return 1;
	return (x%2)^1;
}
signed main(){
    int n,m,i,j,k;
    scanf("%lld",&n);
    for(i=1;i<=n;i++)scanf("%lld",&a[i]);
    for(i=1;i<=n;i++)
      for(j=0;j<5;j++)
        dp[i][j]=inf;
    for(i=0;i<5;i++)dp[0][i]=0;
    for(i=1;i<=n;i++){
      int wh=dp[i-1][0];
      dp[i][0]=wh+a[i];
      wh=min(wh,dp[i-1][1]);
      dp[i][1]=wh+wh2(a[i]);
      wh=min(wh,dp[i-1][2]);
      dp[i][2]=wh+wh1(a[i]);
      wh=min(wh,dp[i-1][3]);
      dp[i][3]=wh+wh2(a[i]);
      wh=min(wh,dp[i-1][4]);
      dp[i][4]=wh+a[i];
    }
    cout<<min(dp[n][2],min(dp[n][3],dp[n][4]))<<endl;
	return 0;
}


Measured memory_bytes: 9600
#include<iostream>
using namespace std;
#define df 0
typedef long int li;
#include<algorithm> // sort,reverse,min,lower_bound

li f(int a,int b,int k);
  
int main(){
  if(df) printf("*debug mode*\n");
  int n,a,b; cin >>n >>a >>b;
  li v[n];
  for(li& x: v) cin >>x;
  sort(v,v+n,less<li>());
  if(df){
    for(li x: v) printf("%ld ",x);
    printf("\n");
  }
  li sum=0;int flag=1;
  for(int i=n-1;i>=n-a;i--){
    sum+=v[i];
    if(v[i]!=v[n-1])flag=0;
  }
  printf("%.10lf\n",sum/(double)a);
  if(flag){
    int k=(v+n)-lower_bound(v,v+n,v[n-1]);
    printf("%ld\n",f(a,b,k));
  }else{
    li* l=lower_bound(v,v+n,v[n-a]);
    li* u=upper_bound(v,v+n,v[n-a]);
    if(df) printf("%d::a:%d(%d) k:%d\n",v[n-a],a-((v+n)-u),(v+n)-u,u-l);
    printf("%ld\n",f(a-((v+n)-u),a-((v+n)-u),u-l));
  }
}

li f(int a,int b,int k){
  li temp=1;
  for(int i=0;i<a;i++){
    (temp*=k-i)/=i+1;
  }
  li sum=temp;
  for(int i=a;i<b;i++){
    (temp*=k-i)/=i+1;
    sum+=temp;
  }
  return sum;
}

/// confirm df==0 ///


Measured memory_bytes: 256
# AOJ 0105 Book Index
# Python3 2018.6.17 bal4u

from collections import defaultdict
index = defaultdict(list)

while True:
	try: w, p = list(input().split())
	except EOFError: break
	index[w].append(p)

index = dict(sorted(index.items()))
for x in index:
	print(x)
	print(*sorted(map(int, index[x])))


Measured memory_bytes: 5992
fun main(args: Array<String>) {
    val n = readInputLine().toInt()
    val hs = readInputLine().split(" ").map{it.toInt()}.toList()
    
    println(dfs(hs, 0))
}

fun readInputLine(): String {
    return readLine()!!
}

fun split(list: List<Int>, height: Int): List<List<Int>> {
    val ret = mutableListOf<List<Int>>()
    
    var l = -1
    var splitting = false
    
    for ((i, e) in list.withIndex()) {
        if (!splitting && e > height) {
            l = i
            splitting = true
        } else if (splitting && e == height) {
            ret.add(list.subList(l, i))
            splitting = false
        }
    }
    
    if (splitting) {
        ret.add(list.subList(l, list.size))
    }
    
    return ret
}

fun dfs(list:List<Int>, height:Int): Int {
    var ret = 0
    val splitted = split(list, height)
    
    for (l in splitted) {
        ret += dfs(l, height + 1) + 1
    }
    
    return ret
}


Measured memory_bytes: 38452
#include <cstdio>
#include <iostream>
#include <string>
#include <vector>
#include <sstream>
#include <map>
#include <set>
#include <queue>
#include <algorithm>
#include <cmath>
#include <cstdlib>
#include <cstring>
#include <typeinfo>
#include <numeric>
#include <functional>
#include <unordered_map>
#include <bitset>


using namespace std;
using ll = long long;
using ull = unsigned long long;

const ll INF = 1e9;
const ll MOD = 1e9 + 7;

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



int t, n, d[130][130];
bool s[130][130];


void bfs(int x, int y, int k){
    if(k == 0)return;
    
    if(d[x + 1][y] + 1 < k && !s[x + 1][y]){
        d[x + 1][y] = k - 1;
        bfs(x + 1, y, k - 1);
    }
    if(d[x - 1][y] + 1 < k && !s[x - 1][y]){
        d[x - 1][y] = k - 1;
        bfs(x - 1, y, k - 1);
    }
    if(d[x + 1][y + 1] + 1 < k && !s[x + 1][y + 1]){
        d[x + 1][y + 1] = k - 1;
        bfs(x + 1, y + 1, k - 1);
    }
    if(d[x - 1][y - 1] + 1 < k && !s[x - 1][y - 1]){
        d[x - 1][y - 1] = k - 1;
        bfs(x - 1, y - 1, k - 1);
    }
    if(d[x][y + 1] + 1 < k && !s[x][y + 1]){
        d[x][y + 1] = k - 1;
        bfs(x, y + 1, k - 1);
    }
    if(d[x][y - 1] + 1 < k && !s[x][y - 1]){
        d[x][y - 1] = k - 1;
        bfs(x, y - 1, k - 1);
    }
}

int main() {
    int sx, sy;
    
    cin >> t >> n;
    
    while(t != 0 || n != 0){
        REP(i, 130){
            REP(j, 130){
                d[i][j] = -INF;
                s[i][j] = false;
            }
        }
        
        REP(i, n){
            int x, y;
            cin >> x >> y;
            s[x + 65][y + 65] = true;
        }
        
        cin >> sx >> sy;
        
        d[sx + 65][sy + 65] = t;
        bfs(sx + 65, sy + 65, t);
        
        int ans = 0;
        REP(i, 130){
            REP(j, 130){
                if(d[i][j] != -INF)ans++;
            }
        }
        
        cout << ans << endl;
        
        cin >> t >> n;
    }
}




Measured memory_bytes: 3172
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int n,d;
    cin>>n>>d;
    cout<<(n-1)/(d*2+1)+1<<'\n';
    return 0;
}
//1 2 3 4 5 6 7 8 9 10 11 12 13 14


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


int main() {
	// const double vol[4] = {0.25, 0.5, 1.0, 2.0};
	LL a[4],n;
	for (int i = 0; i < 4; i++) cin >> a[i];
	cin >> n;
	
	cout << n/2 * min(min(a[0]*8, a[1]*4), min(a[2]*2, a[3])) + n%2 * min(min(a[0]*4, a[1]*2), a[2]) << endl;
	
	return 0;
}

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

using namespace std;

int main() {
	int len;
	char c;
	string str;

	getline(cin, str);
	len = str.length();
	for (int i = 0; i < len; ++i) {
		c = str[i];
		if (isupper(c)) {
			str[i] = tolower(c);
		}
		else if(islower(c)) {
			str[i] = toupper(c);
		}
	}
	cout << str << endl;

	return 0;
}


Measured memory_bytes: 3184
import java.util.*;
public class Main{
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int a = sc.nextInt();
        int b = sc.nextInt();
        int max =Integer.MIN_VALUE;
        
        if(a+b > max){
            max =a+b;
        }
        if(a-b > max){
            max = a-b;
        }
        if(a*b > max){
            max = a*b;
        }
        System.out.println(max);
    }

}


Measured memory_bytes: 24020
#define _USE_MATH_DEFINES
#include<iostream>
#include<string>
#include<queue>
#include<cmath>
#include<map>
#include<set>
#include<list>
#include<iomanip>
#include<vector>
#include<random>
#include<functional>
#include<algorithm>
#include<stack>
#include<cstdio>
#include<cstring>
#include<bitset>
#include<unordered_map>
#include<climits>
#include<fstream>
#include<time.h>
#include<cassert>
#include<functional>
#include<numeric>
#include<tuple>

using namespace std;
using ll = long long;
using ld = long double;
#define int long long
#define all(a) (a).begin(),(a).end()
#define EPS (1e-7)
#define fs first
#define sc second
#define xx first
#define yy second.first
#define zz second.second
#define H pair<int, int>
#define P pair<int, pair<int, int>>
#define Q(i,j,k) mkp(i,mkp(j,k))
#define R pair<pair<int, int>, pair<int, int>>
#define S(i,j,k,l) mkp(mkp(i,j),mkp(k,l))
#define rep(i,n) for(int (i) = 0 ; (i) < (n) ; (i)++)
#define rng(i,s,n) for(int (i) = (s) ; (i) < (n) ; (i)++)
#define req(n,i) for(int (i) = (n) - 1 ; (i) >= 0 ; (i)--)
#define range(i,v) for(auto& (i) : v)
#define mkp make_pair
#define mem(x,k) memset(x,k,sizeof(x))
#define vec vector
#define pb emplace_back
#define lb lower_bound
#define ub upper_bound
#define crdcomp(b) sort(all((b)));(b).erase(unique(all((b))),(b).end())
#define getidx(b,i) lower_bound(all(b),(i))-b.begin()
#define ssp(i,n) (i==n-1?"\n":" ")
#define ctoi(c) (int)(c-'a')
#define itoc(c) (char)(c+'a')
#define itn int
#define pri_que priority_queue
#define pp(x,y) pb(H{x,y})
#define ppp(x,y,z) pb(Q(x,y,z))
#define pppp(x,y,z,w) pb(S(x,y,z,w))
#define cyes cout<<"Yes\n"
#define cno cout<<"No\n"
#define endl "\n"
const int mod = 1e9 + 7;
const int Mod = 998244353;
const ll inf = 3 * 1e18;
const int Inf = 15 * 1e8;
const vec<int>dx{ -1,1,0,0 }, dy{ 0,0,-1,1 };
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; }
ll read() { ll u, k = scanf("%lld", &u); return u; }
string reads() { string s; cin >> s; return s; }
H readh() { H u; ll k = scanf("%lld %lld", &u.fs, &u.sc); return u; }
void printh(H t) { printf("%lld %lld\n", t.fs, t.sc); }
bool inarea(H t, int h, int w) { return 0 <= t.fs && t.fs < h && 0 <= t.sc && t.sc < w; }
ll gcd(ll i, ll j) { return j ? gcd(j, i % j) : i; }
ll mod_pow(ll x, ll n, ll p) {
	ll res = 1;
	while (n > 0) {
		if (n & 1) res = res * x % p;
		x = x * x % p;
		n >>= 1;
	}
	return res;
}//x^n%p
ll bitcount(ll x) {
	int sum = 0; for (int i = 0; i < 60; i++)if ((1ll << i) & x) sum++;
	return sum;
}
/*const int fn_ = 1000005;
ll fact_[fn_], comp_[fn_];
ll comb(ll x, ll y, ll Mod = mod) {
	if (!fact_[0]) {
		fact_[0] = 1; comp_[0] = 1;
		for (int i = 1; i < fn_; i++) {
			fact_[i] = fact_[i - 1] * i % Mod;
			comp_[i] = mod_pow(fact_[i], Mod - 2, Mod);
		}
	}
	if (x < y) return 0;
	return fact_[x] * comp_[x - y] % Mod * comp_[y] % Mod;
}*/
//--------------------------------------------------------------
signed main() {
	int n, k;
	cin >> n >> k;
	int r = k, sum = 1;
	while (n >= r) {
		sum++, r *= k;
	}
	cout << sum << endl;
}

Measured memory_bytes: 256
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <algorithm>
#include <numeric>
#include <functional>
#include <sstream>
#include <iostream>
#include <iomanip>
#define _USE_MATH_DEFINES
#include <cmath>
#include <climits>
#include <cstdlib>
#include <cstring>
#include <cfloat>
#include <cmath>
#include <ctime>
#include <cassert>
#include <cctype>
#include <cstdio>
#include <cassert>
using namespace std;

#define EPS 1e-12
#define ull unsigned long long
#define ll long long
#define VI vector<ll>
#define PII pair<ll, ll> 
#define VVI vector<vector<ll> >
#define VVVI vector<vector<vector<ll>>>
#define VVVVI vector<vector<vector<vector<ll>>>>
#define REP(i,n) for(ll i=0,_n=(n);(i)<(ll)_n;++i)
#define REPR(i,n) for(ll i=(ll)(n)-1;0<=(i);--i)
#define RANGE(i,a,b) for(ll i=(ll)a,_b=(ll)(b);(i)<_b;++i)
#define RANGER(i,a,b) for(ll i=(ll)(b)-1,_a=(ll)(a);(_a)<=i;--i)
#define FOR(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)
#define ALL(c) (c).begin(), (c).end()
#define ALLR(c) (c).rbegin(), (c).rend()
#define PB push_back
#define MP(a, b) make_pair(a, b)
#define POPCOUNT __builtin_popcount
#define POPCOUNTLL __builtin_popcountll
#define CLEAR(table, v) memset(table, v, sizeof(table));
#define UNIFORM_DOUBLE(a, b) (((b-a)*(double)rand()/RAND_MAX)+a) // [a, b) 
#define UNIFORM_LL(a, b) (ll)UNIFORM_DOUBLE(a, b) // [a, b) 
#define IN(v, lo, hi) ((lo)<=(v) && (v)<(hi))
#define DD(v) cout<<#v<<": "<<v<<endl
#define FI first
#define SE second
template <typename T0, typename T1> std::ostream& operator<<(std::ostream& os, const map<T0, T1>& v) { for( typename map<T0, T1>::const_iterator p = v.begin(); p!=v.end(); p++ ){os << p->first << ": " << p->second << " ";} return os; }
template <typename T0, typename T1> std::ostream& operator<<(std::ostream& os, const pair<T0, T1>& v) { os << v.first << ": " << v.second << " "; return os; }
template <typename T> std::ostream& operator<<(std::ostream& os, const vector<T>& v) { for( int i = 0; i < (int)v.size(); i++ ) { os << v[i] << " "; } return os; }
template <typename T> std::ostream& operator<<(std::ostream& os, const set<T>& v) { vector<T> tmp(v.begin(), v.end()); os << tmp; return os; }
template <typename T> std::ostream& operator<<(std::ostream& os, const deque<T>& v) { vector<T> tmp(v.begin(), v.end()); os << tmp; return os; }
template <typename T> std::ostream& operator<<(std::ostream& os, const vector<vector<T> >& v) { for( int i = 0; i < (int)v.size(); i++ ) { os << v[i] << endl; } return os; }
template<typename T>void maxUpdate(T& a, T b) {a = max(a, b);}
template<typename T>void minUpdate(T& a, T b) {a = min(a, b);}
string YN(bool v) { return v ? "Yes":"No"; }
void uniq(VI& es) { sort(ALL(es)); es.erase(unique(ALL(es)), es.end()); }

#define INF (1LL<<60)

int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	VI x(4), y(4);
	while(cin>>x[0]>>y[0]>>x[1]>>y[1]) {
		ll ox=x[1]-x[0];
		ll oy=y[1]-y[0];
		// cost+90 sint+90 = -sint cost
		x[2]=x[1]-oy;
		y[2]=y[1]+ox;
		x[3]=x[0]-oy;
		y[3]=y[0]+ox;
		cout<<x[2]<<" "<<y[2]<<" "<<x[3]<<" "<<y[3]<<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 REP2(i,x,n) for(int i=x; i<(n); i++)
#define ALL(n) begin(n),end(n)
struct cww{cww(){ios::sync_with_stdio(false);cin.tie(0);}}star;
int main()
{
    string S;
    cin >> S;
    int N = S.size();
    REP( i, N )
    {
        S = S.substr( 0, S.size() - 1 );
        string A = S.substr( 0, S.size()/2 ); 
        string B = S.substr( S.size()/2, S.size()/2 );
        if( A == B )
        {
            cout << A.size() + B.size() << endl;
            return 0;
        }
    }
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int n,c[300001],d[300001],a[300001],b[300001];
inline int *calc(int x){return lower_bound(b,b+n,x);}
int main()
{
	cin>>n;
	for(int i=0;i<n;i++)cin>>c[i];
	for(int i=0;i<n;i++)cin>>d[i];
	int ans=0;
	for(int i=0;i<29;i++)
	{
		for(int j=0;j<n;j++)a[j]=c[j]%(2<<i),b[j]=d[j]%(2<<i);
		sort(b,b+n);
		int k=0;
		for(int j=0;j<n;j++)k^=calc((2<<i)-a[j])-calc((1<<i)-a[j])+calc((4<<i)-a[j])-calc((3<<i)-a[j]);
		ans^=(k&1)<<i;
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 4096
#include <bits/stdc++.h>
using namespace std;
int main(){
  int n;
  cin>>n;
  long int Y;
  cin>>Y;
  int x,y,z,all;
  all=0;
  
  for (int i=0; i<n+1;i++){
    if (all==Y)
      break;
    x=i;
    for (int j=0; j<n+1-i;j++){
      y=j;
      z=n-x-y;
      all=10000*x+5000*y+1000*z;
      if(all==Y){
        cout<<x<<' '<<y<<' '<<z<<endl;
        break;
      }
    }
  }
  
  if(all!=Y)
    cout<<-1<<' '<<-1<<' '<<-1<<endl;
}
      
      
  
  
    

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


void solve(long long N, long long M){
	if( N > M ) swap(N,M);
	if( M - N == 1 ){
		long long ans = 1;
		for(int i = 1 ; i <= N ; i++)
			ans *= i,ans %= 1000000007;
		for(int i = 1 ; i <= M ; i++)
			ans *= i,ans %= 1000000007;
		cout << ans << endl;
	}else if( M == N ){
		long long ans = 1;
		for(int i = 1 ; i <= N ; i++)
			ans *= i,
			ans %= 1000000007;
		ans *= ans;
		ans %= 1000000007;
		ans *= 2;
		ans %= 1000000007;
		cout << ans << endl;
	}else{
		cout << 0 << endl;
	}


}

int main(){
	long long M;
	long long N;
	scanf("%lld",&N);
	scanf("%lld",&M);
	solve(N, M);
	return 0;
}



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

int main(){
    int a,b,n=0;
    cin>>a>>b;

    if(a>=b)cout<<"1"<<endl;
    else{
        while(1){
            if(a*n>=b)break;
            n++;
        }
        cout<<n<<endl;
    }
    return 0;
}




Measured memory_bytes: 3108
#include <iostream>
#include <string>
#include <algorithm>
#include <functional>
#include <vector>
#include <utility>
#include <cstring>
#include <iomanip>
#include <numeric>
#include <cmath>
#include <queue>
using namespace std;
typedef long long ll;
const int INF = 1<<30; 
const int MOD = 1e9 + 7;
const int dx[] = {1, 0, -1, 0};
const int dy[] = {0, 1, 0, -1};
int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n;
    cin >> n;
    ll A[n + 1];
    ll sum = 0;
    for(int i = 0; i < n; i++)
    {
        int x;
        cin >> x;
        sum += x;
        A[i] = sum;
    }
    ll ans = 1LL<<50;
    for(int i = 0; i < n - 1; i++)
    {
        ll tmp = sum - A[i];
        ans = min(abs(A[i] - tmp), ans);
    }
    cout << ans << "\n";
    return 0;
}



Measured memory_bytes: 1792
N = int(input())
A = [int(input() )for i in range(N)]
first_max = 0
second_max = 0

#first_max_index = -1
#second_max_index = -1

for i in range(N):
    if A[i] > first_max:
        second_max = first_max
        first_max = A[i]
        #first_max_index = i
    elif A[i] > second_max:
        second_max = A[i]

for i in range(N):
    if A[i] == first_max:
        print(second_max)
    else:
        print(first_max)

Measured memory_bytes: 12532
#include <bits/stdc++.h>
#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 INF 2e9
#define ALL(v) v.begin(), v.end()
using namespace std;
typedef long long ll;
int main()
{
  int X, N;
  cin >> X >> N;
  vector<int> vec(N);
  vector<int> seq(101, 0);
  REP(i, N) {
    int x;
    cin >> x;
    seq[x]++;
  }
  int ans = 0;
  int dif = pow(10, 5);
  REP(i, 102) {
    if (seq[i]) {
      continue;
    }
    if (dif > abs(X - i)) {
      dif = abs(X - i);
      ans = i;
    }
  }
  
  cout << ans << endl;
  return 0;
}

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

vector<int>dist(200005, 0);
vector<int>visit(200005, 0);
vector<vector<int> >G(200005);

void bfs(){
    int s=1;
    visit[s]=1;
    queue<int> q;
    q.push(s);
    while(!q.empty()){
        int u=q.front();q.pop();
        for(int i=0;i<int(G[u].size());i++){
            int v =G[u][i];
            if(!visit[v]){
                visit[v]=1;
                dist[v] += dist[u];
                q.push(v);
            }
        }
    }
}

int main(){
    int n,q;
    cin>>n>>q;
    for(int i=0; i<n-1; i++){
        int x,y;
        cin>>x>>y;
        G[x].push_back(y);
        G[y].push_back(x);
    }

    for(int i=0; i<q; i++){
        int c, p;
        cin>>c>>p;
        dist[c] += p;
    }
    bfs();

    for(int i=1; i<=n; i++){
        cout<<dist[i]<<" ";
    }
    cout<<endl;
}



Measured memory_bytes: 16372
def turn(A, HP):
    return HP - A


def main():
    tHP, tA, aHP, aA = list(map(int, input().split()))

    while True:
        aHP = turn(tA, aHP)
        if aHP < 1:
            print('Yes')
            return
        tHP = turn(aA, tHP)
        if tHP < 1:
            print('No')
            return


if __name__ == "__main__":
    main()



Measured memory_bytes: 9168
#include <iostream>
#include <algorithm>
#include <vector>
#include <set>
#include <queue>
#include <map>
#include <string.h>
#include <math.h>
#include <stdio.h>
#include <deque>
#include <bits/stdc++.h>
//#include "testlib.h"
using namespace std;
#define ll long long
#define pii pair<int,int>
#define qi ios::sync_with_stdio(0)

bool debug=true;

/*    *************************************
	  * Written in New Computer           *
	  * The following code belongs to     *
	  * XiaoGeNintendo of HellHoleStudios *
	  *************************************
*/
template<typename T1,typename T2>ostream& operator<<(ostream& os,pair<T1,T2> ptt){
	os<<ptt.first<<","<<ptt.second;
	return os;
}
template<typename T>ostream& operator<<(ostream& os,vector<T> vt){
	os<<"{";
	for(int i=0;i<vt.size();i++){
		os<<vt[i]<<" ";
	}
	os<<"}";
	return os;
}

ll n,k;
int a[2005];
const ll mod=1e9+7;

int main(int argc,char* argv[]){
	qi;
	cin>>n>>k;
	for(int i=0;i<n;i++){
		cin>>a[i];
	}
	
	ll ans=0;
	for(int i=0;i<n;i++){
		ll shit=0;
		ll totshit=0;
		for(int j=0;j<n;j++){
			if(a[j]>a[i]){
				totshit++;
				if(j<i){
					shit++;
				}
			}
		}
		
		ll last=(shit+totshit*(k-1)%mod)%mod;
		ll tmp=(shit+last)%mod*k%mod*500000004%mod;
		ans+=tmp;
		ans%=mod;
	}
	cout<<ans<<endl;
	return 0;
}



Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cmath>
#include<cstring>
#include<vector>
using namespace std;
typedef long long ll;
#define REP(i, n) for (int i = 0; i < (int)(n); i++)
#define sc(x) scanf("%d",&x);
int main(){
    string s;
    cin >> s;
    int ans = 0;
    int cnt = 0;
    for (int i = 0; i < s.size(); i++){
        if (s[i] == 'g'){
            cnt += 1;
        }else{
            if (cnt > 0) cnt -= 1;
            else ans -= 1;
        }
    }
    ans += cnt / 2;
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 512
import math
K =int(input())
list =[]
for a in range(1,K+1) :
    for b in range(1,K+1) :  
        t = math.gcd(a,b)    #全ての場合についての最大公約数を求める
        for c in range(1,K+1) :
           list.append(math.gcd(t,c))  #リストに格納して、合計値を求める
print(sum(list))

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

# define REP(i,n) for (int i=0;i<(n);++i)
# define rep(i,a,b) for(int i=a;i<(b);++i)
# define p(s) std::cout << s ;
# define pl(s)  std::cout << s << endl;
# define printIf(j,s1,s2) cout << (j ? s1 : s2) << endl;
# define YES(j) cout << (j ? "YES" : "NO") << endl;
# define Yes(j) std::cout << (j ? "Yes" : "No") << endl;
# define yes(j) std::cout << (j ? "yes" : "no") << endl;
# define all(v) v.begin(),v.end()
# define showVector(v) REP(i,v.size()){p(v[i]);p(" ")} pl("")
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;}
typedef long long int ll;
typedef pair<ll,ll> P_ii;
typedef pair<double,double> P_dd;

template<class T>
vector<T> make_vec(size_t a){
    return vector<T>(a);
}

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

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

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


const int MOD = 1000000007;
const int inf=1e9+7;
const ll longinf=1LL<<60 ;

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

  int ans = max(A - 2 * B, 0);
  cout << ans << endl;

  return 0;
}

Measured memory_bytes: 256
n,k=map(int,input().split())
s=[]
p=998244353
for i in range(k):
    l,r=map(int,input().split())
    s.append([l,r])
k=len(s)
dp=[0]*(3*n)
dp[1]=1
dp[2]=-1
for i in range(1,n):
    dp[i]=(dp[i-1]+dp[i])%p
    for j in range(k):
        l,r=s[j][0],s[j][1]
        dp[i+l]=(dp[i+l]+dp[i])%p
        dp[i+r+1]=(dp[i+r+1]-dp[i])%p

dp[n]=dp[n-1]+dp[n]

print(dp[n]%p)



Measured memory_bytes: 72680
#include<cstdio>
#include<cstring>
using namespace std;
using ll = long long;
using ull = unsigned long long;

int main(){
    unsigned H, W, M;
    scanf("%u %u %u", &H, &W, &M);
    unsigned row[H], column[W], h[M], w[M], max_r = 0, max_c = 0;
    ull n_max_r = 0, n_max_c = 0;
    memset(row, 0, sizeof row);memset(column, 0, sizeof column);
    for (unsigned i = 0; i < M; i++){
        scanf("%u %u", h + i, w + i);
        h[i]--;w[i]--;
        row[h[i]]++;column[w[i]]++;
        if(max_r < row[h[i]]) max_r = row[h[i]];if(max_c < column[w[i]]) max_c = column[w[i]];
    }
    for (unsigned i = 0; i < H; i++){
        if(row[i] == max_r) n_max_r++;
    }
    for (unsigned i = 0; i < W; i++){
        if(column[i] == max_c) n_max_c++;
    }
    ull intersection = n_max_r*n_max_c;
    for (unsigned i = 0; i < M; i++){
        if(row[h[i]] == max_r && column[w[i]] == max_c) intersection--;
    }
    printf("%u\n", intersection ? max_r + max_c : (max_r + max_c - 1));
	return 0;
}

Measured memory_bytes: 6392
#include<cstdio>
#include<algorithm>
using namespace std;
const int N=1e5+10;
#define ll long long
ll stk[N],f[N],ans[N];
int n,top,q;
void solve(ll x,ll v){
    int k=upper_bound(stk+1,stk+top+1,x)-stk-1;
    if(!k){
        ans[1]+=v;ans[x+1]-=v;
        return ;
    }
    f[k]+=v*(x/stk[k]);solve(x%stk[k],v);
}
int main(){
    scanf("%d%d",&n,&q);stk[++top]=n;
    for(int i=1;i<=q;i++){
        ll x;scanf("%lld",&x);
        while(x<=stk[top]&&top)--top;
        stk[++top]=x;
    }
    f[top]=1;
    for(int i=top-1;i;i--)
        f[i]+=f[i+1]*(stk[i+1]/stk[i]),solve(stk[i+1]%stk[i],f[i+1]);
    ans[1]+=f[1];ans[stk[1]+1]-=f[1];
    for(int i=1;i<=n;i++)printf("%lld\n",ans[i]+=ans[i-1]);
}


Measured memory_bytes: 3968
// Java program For handling Input/Output 
import java.io.*; 
import java.util.*;
import java.math.*;
//import java.awt.*;

public class Main 
{ 
    FastReader sc;
    //actual logic
    void solve(){
        int n = sc.ni();
        int m = sc.ni();

        int p[] = new int[m];
        String s[] = new String[m];
        int z[] = new int[n];
        for(int i = 0;i < m;i++)
        {
            p[i] = sc.ni();
            s[i] = sc.ns();
            if(s[i].equals("AC"))
                z[p[i]-1] = 2;
        }

        int ac = 0, wa = 0;
        for(int i = 0;i < m;i++)
        {
            if(s[i].equals("AC"))
            {
                if(z[p[i]-1] == 2)
                {
                    ac++;
                    z[p[i]-1] = 1;
                }
            }
            else
            {
                if(z[p[i]-1] == 2)
                {
                    wa++;
                }
            }
        }

        System.out.println(ac + " " + wa);
    }
    
    //constructor
    Main()
    {
        try{  
            sc = new FastReader();
        }catch(Exception e){
            System.out.println(e);
        }
    }


    //main metohd
    public static void main(String[] args)
    { 
       new Main().solve();
   }
    //Utility methods

   static class FastReader{
    BufferedReader br;
    StringTokenizer st;
    FastReader(){
        br = new BufferedReader(new InputStreamReader(System.in));
        try{
            st = new StringTokenizer(br.readLine());
        }catch(Exception e){
            System.out.println(e);
        }
    }

    FastReader(String s){
        try{
            br = new BufferedReader(new FileReader(s));
            st = new StringTokenizer(br.readLine());
        }catch(Exception e){
            System.out.println(e);
        }
    }

    String ns(){
        if(!st.hasMoreTokens())
        {
            try{
                st = new StringTokenizer(br.readLine());
            }catch(Exception e){
                System.out.println(e);
            }    
        }
        return st.nextToken();

    }

    int ni(){
        return Integer.parseInt(ns());
    }

    long nl(){
        return Long.parseLong(ns());
    }

    double nd(){
        return Double.parseDouble(ns());
    }
}
}


Measured memory_bytes: 46932
#include <iostream>
#include <string>
#include <map>
#include <cstdio>
using namespace std;

int main(void) {
    int n;
    char order[8], str[16];
    map<string, bool> dict;

    scanf("%d", &n);
    for (int i = 0; i < n; i++) {
        scanf("%s %s", order, str);
        if (order[0] == 'i') {
            dict[string(str)] = true;
        } else {
            if (dict[string(str)]) {
                printf("yes\n");
            } else {
                printf("no\n");
            }
        }
    }

    return 0;
}

Measured memory_bytes: 45472