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

#define rep(i,n) for(i = 0;i < n;++i)
#define all(v) v.begin(), v.end()
using ll = long long;

int main()
{
    ll i,j;
    ll n;
    cin >> n;
    unordered_map <string,ll> mp;
    for(i = 0;i < n;++i){
        string s;
        cin >> s;
        if(mp.count(s)) continue;
        else{
            mp[s] = 0;
        }
    }
    cout << mp.size() << endl;


    return 0;
}

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

int main() {
  int N;
  cin>>N;
  vector<double>a(N);
  for(int i=0;i<N;i++){
    cin>>a.at(i);
  }
  sort(a.begin(),a.end());
  double ans=a.at(0);
  for(int i=1;i<N;i++){
    ans+=a.at(i);
    ans/=2;
  }
  cout<<ans<<endl;
    
}

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

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<ll, ll> P;

#define EACH(i,a) for (auto& i : a)
#define FOR(i,a,b) for (ll i=(a);i<(b);i++)
#define RFOR(i,a,b) for (ll i=(b)-1;i>=(a);i--)
#define REP(i,n) for (ll i=0;i<(n);i++)
#define RREP(i,n) for (ll i=(n)-1;i>=0;i--)
#define debug(x) cout<<#x<<": "<<x<<endl
#define pb push_back
#define ALL(a) (a).begin(),(a).end()

const ll linf = 1e18;
const int inf = 1e9;
const double eps = 1e-12;
const double pi = acos(-1);

template<typename T>
istream& operator>>(istream& is, vector<T>& vec) {
    EACH(x,vec) is >> x;
    return is;
}
template<typename T>
ostream& operator<<(ostream& os, vector<T>& vec) {
    REP(i,vec.size()) {
        if (i) os << " ";
        os << vec[i];
    }
    return os;
}
template<typename T>
ostream& operator<<(ostream& os, vector< vector<T> >& vec) {
    REP(i,vec.size()) {
        if (i) os << endl;
        os << vec[i];
    }
    return os;
}

int main() {
    std::ios::sync_with_stdio(false);
    std::cin.tie(0);
    string s; cin >> s;
    cout << s.substr(0, 4) << " " << s.substr(4) << endl;
}


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

int main(int argc, char const *argv[]) {
	int tensu[5], ave = 0;

	for (int i = 0; i < 5; ++i)
	{
		cin >> tensu[i];
		if (tensu[i] < 40)
		{
			tensu[i] = 40;
		}
		ave += tensu[i];
	}

	ave /= 5;

	cout << ave << endl;

	return 0;
}

Measured memory_bytes: 1160
#include<bits/stdc++.h>
using namespace std;
int main()
{
   //freopen("inputfile.txt","r",stdin);
   int n;cin>>n;
   set <int> s[n];
   bool flag = false;
   for(int i=0;i<n;i++)
   {
       int a,b;cin>>a>>b;
       s[i].insert(a);s[i].insert(b);
        if(i>1 && flag==false)
        {
            if(s[i].size()==1 && s[i-1].size()==1 && s[i-2].size()==1) flag = true;
        }
   }
   if(flag==true)cout<<"Yes"<<endl;
   else cout<<"No"<<endl;
    return 0;
}


Measured memory_bytes: 3620
#include<stdio.h>

int main(void){
    int i,j,k,n,b,f,r,v;
    static int count[4][3][10];
    scanf("%d",&n);
    
    for(i=0;i<n;i++){
        scanf("%d%d%d%d",&b,&f,&r,&v);
        count[b-1][f-1][r-1]+=v;
    }
    
    for(i=0;i<4;i++){
        for(j=0;j<3;j++){
            for(k=0;k<10;k++)
                printf(" %d",count[i][j][k]);
            printf("\n");
        }
        if(i<3) printf("####################\n");
    }
    return 0;
}



Measured memory_bytes: 2048
#
# 　　  ⋀_⋀　 
#　　  (･ω･)  
# .／ Ｕ ∽ Ｕ＼
#  │＊　合　＊│
#  │＊　格　＊│ 
#  │＊　祈　＊│ 
#  │＊　願　＊│ 
#  │＊　　　＊│ 
#      ￣
#
import sys
sys.setrecursionlimit(10**6)
input=sys.stdin.readline
from math import floor,ceil,sqrt,factorial,log #log2ないｙｐ
from heapq import heappop, heappush, heappushpop
from collections import Counter,defaultdict,deque
from itertools import accumulate,permutations,combinations,product,combinations_with_replacement
from bisect import bisect_left,bisect_right
from copy import deepcopy
inf=float('inf')
mod = 10**9+7
def pprint(*A): 
    for a in A:     print(*a,sep='\n')
def INT_(n): return int(n)-1
def MI(): return map(int,input().split())
def MF(): return map(float, input().split())
def MI_(): return map(INT_,input().split())
def LI(): return list(MI())
def LI_(): return [int(x) - 1 for x in input().split()]
def LF(): return list(MF())
def LIN(n:int): return [I() for _ in range(n)]
def LLIN(n: int): return [LI() for _ in range(n)]
def LLIN_(n: int): return [LI_() for _ in range(n)]
def LLI(): return [list(map(int, l.split() )) for l in input()]
def I(): return int(input())
def F(): return float(input())
def ST(): return input().replace('\n', '')
def main():
    X=I()
    boo = [1]+[0]*X
    A = [100,101,102,103,104,105]
    for a in A:
        for i in range(X+1):
            if i-a>=0 and boo[i-a]:
                boo[i]=True
    print(int(boo[X]))
if __name__ == '__main__':
    main()

Measured memory_bytes: 5108
import java.util.Scanner;

public class Main {

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

		int l = sc.nextInt();
		int r = sc.nextInt();

		long min = 9999;

		for (long i = l; i < r; i++) {
			for (long j = i + 1; j <= r; j++) {
				long num = (i * j) % 2019;
				if (min > num) {
					min = num;
					if (min == 0) {
						System.out.println(min);
						return;
					}
				}
			}
		}

		System.out.println(min);

	}

}


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

using namespace std;

int n, m, q;

vector <int > a;

vector <vector <int>> abcd;

int ans = 0;

void brute() {
	if ((int)a.size() == n) {
		int res = 0;
		for (int j = 0; j < q; j++) {
			int u = abcd[j][0];
			int v = abcd[j][1];
			int c = abcd[j][2];
			int d = abcd[j][3];
			if (a[v] - a[u] == c) {
				res += d;
			}
		}
		ans = max(ans, res);
		return;
	}
	if (a.size() == 0) {
		for (int i = 1; i <= m; i++) {
			a.push_back(i);
			brute();
			a.pop_back();
		}
	}
	else {
		for (int i = a.back(); i <= m; i++) {
			a.push_back(i);
			brute();
			a.pop_back();
		}
	}
}

int main() {
	cin >> n >> m >> q;
	abcd.resize(q, vector <int> (3));
	for (int i = 0; i < q; i++) {
		for (int j = 0; j < 4; j++) {
			cin >> abcd[i][j];
		}
		abcd[i][0]--;
		abcd[i][1]--;
	}
	brute();
	cout << ans;
	return 0;
}


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

using namespace std;

const int maxN = 200009;
int lstB = 0, N, K, a[2][maxN];

int main ()
{
//freopen ("input", "r", stdin);
//freopen ("output", "w", stdout);

scanf ("%d %d", &N, &K);
for (int i=1; i<=N; i++)
    scanf ("%d", &a[0][i]);
for (int i=1; i<=K; i++)
{
    for (int j=0; j<=N; j++)
        a[i & 1][j] = 0;
    for (int j=1; j<=N; j++)
    {
        int d = a[(i & 1) ^ 1][j];
        a[i & 1][max (j - d, 0)] ++;
        a[i & 1][min (j + d + 1, N + 1)] --;
    }
    bool ok = 1;
    for (int j=1; j<=N; j++)
        a[i & 1][j] += a[i & 1][j - 1],
        ok &= (a[i & 1][j] == a[(i & 1) ^ 1][j]);
    lstB = i & 1;
    if (ok)
        break;
}
for (int i=1; i<=N; i++)
    printf ("%d%c", a[lstB][i], " \n"[i == N]);
return 0;
}


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

AC = 0
WA = 0


was = [0]*(N+1)
acs = [0]*(N+1)

for i in range(M):
	p,s = input().split()
	p = int(p)

	if s == "AC":

		if acs[p] == 0:

			AC += 1
			WA += was[p]
			acs[p] = 1
			
	else:
		was[p] += 1

print(AC,WA)

Measured memory_bytes: 4596
#include <cstdio>
#include <cmath>

int abs(int x){
	if(x<0)return -x;
	return x;
}

#define INF 5e4
int extgcd(int a,int b,int &x,int &y){
	int d=a;
	if(b!=0){
		d=extgcd(b,a%b,y,x);
		y-=(a/b)*x;
	}else{
		x=1;
		y=0;
	}
	return d;
}

int a,b,d;

int main(void){
	while(1){
		scanf("%d %d %d",&a,&b,&d);
		if(a+b+d==0)break;
		int x=INF,y=INF;
		for(int i=0;i<=50000;i++){
			int k=(d-a*i)/b;
			if(k>=0){
				if(a*i+b*k==d){
					if(i+k<x+y){
						x=i;
						y=k;
					}else if(i+k==x+y && a*i+b*k<x*a+b*y){
						x=i;
						y=k;
					}
				}
			}
			k=(d+a*i)/b;
			if(k>=0){
				if(b*k==d+a*i){
					if(i+k<x+y){
						x=i;
						y=k;
					}else if(i+k==x+y && a*i+b*k<x*a+b*y){
						x=i;
						y=k;
					}
				}
			}
			k=(a*i-d)/b;
			if(k>=0){
				if(b*k+d==a*i){
					if(i+k<x+y){
						x=i;
						y=k;
					}else if(i+k==x+y && a*i+b*k<x*a+b*y){
						x=i;
						y=k;
					}
				}
			}
		}
		printf("%d %d\n",x,y);
	}
	return 0;
}

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

using namespace std;

template<typename Weight>
struct Dinic {
    struct Edge {
        int src, dst, rev;
        Weight weight;
        Edge(int f, int t, Weight cap, int rev = 0) :
            src(f), dst(t), rev(rev), weight(cap) {}
    };

    int n;
    vector<vector<Edge>> adj;
    static const Weight INF = numeric_limits<Weight>::max();

    Dinic(int _n) : n(_n), adj(n) {}

    void add_edge(const int src, const int dst, const Weight cap = INF) {
        adj[src].emplace_back(Edge(src, dst, cap, adj[dst].size()));
        adj[dst].emplace_back(Edge(dst, src, 0, adj[src].size() - 1));
    }

    Weight MaximumFlow(const int s, const int t) {
        Weight flow = 0;
        while(true) {
            vector<int> level(n, -1), iter(n);
            Bfs(s, level);
            if(level[t] == -1) break;
            for (Weight f = 0; (f = Dfs(s, t, INF, level, iter)) > 0; )
                flow += f;
        }
        return flow;
    }

    void Bfs(const int s, vector<int> &level){
        queue<int> que;
        for (level[s] = 0, que.push(s); !que.empty(); ) {
            const int v = que.front(); que.pop();
            for (auto &e : adj[v])
                if(0 < e.weight && level[e.dst] == -1){
                    level[e.dst] = level[v] + 1;
                    que.push(e.dst);
                }
        }
    }

    Weight Dfs(int v, int t, Weight flow, vector<int> &level, vector<int> &iter) {
        if(v == t) return flow;
        for ( ; iter[v] < (int)adj[v].size(); ++iter[v]) {
            Edge &e = adj[v][iter[v]];

            if(0 < e.weight && level[v] < level[e.dst]){
                Weight d = Dfs(e.dst, t, min(flow, e.weight), level, iter);
                if(0 < d){
                    e.weight -= d;
                    adj[e.dst][e.rev].weight += d;
                    return d;
                }
            }
        }
        return 0;
    }
};

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

    vector<string> hasu(h);
    for (auto &&x : hasu) cin >> x;

    const int s = h + w, t = h + w + 1;
    Dinic<int> g(h + w + 2);

    pair<int, int> ss, tt;
    for (int i = 0; i < h; ++i) {
        for (int j = 0; j < w; ++j) {
            if (hasu[i][j] == 'o') {
                g.add_edge(i, h + j, 1);
                g.add_edge(h + j, i, 1);
            }
            else if (hasu[i][j] == 'S') {
                g.add_edge(s, i);
                g.add_edge(s, h + j);
                ss = make_pair(i, j);
            }
            else if (hasu[i][j] == 'T') {
                g.add_edge(i, t);
                g.add_edge(h + j, t);
                tt = make_pair(i, j);
            }
        }
    }

    if (ss.first == tt.first || ss.second == tt.second) return -1;

    int res = g.MaximumFlow(s, t);
    return (res < g.INF ? res : -1);
}

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

    cout << Solve() << endl;

    return 0;
}


Measured memory_bytes: 1152
/*input
2017/01/31
*/
#include <bits/stdc++.h>

using namespace std;

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


#define FileIn(file) freopen(file, "r", stdin)
#define FileOut(file) freopen(file, "w", stdout)
#define syso(n) cout<<n<<endl;
#define sysom(message, n) cout<<message<<n<<endl;
#define all(c) c.begin(), c.end() 
#define tr(container, it) \
for(typeof(container.begin()) it = container.begin(); it != container.end(); it++) 
#define present(container, element) (container.find(element) != container.end())  //map, set
#define cpresent(container, element) (find(all(container),element) != container.end()) //vector
#define what_is(x) cout << #x << " is " << x << endl; 


ll gcd(ll a, ll b){
    if (b==0) return a;
    return gcd(b, a%b);
} 

ll lcm(ll fir, ll sec){
	return (fir*sec)/(gcd(fir, sec));
}


const int MOD = 1e9 + 7;
const string small_alphabets = "abcdefghijklmnopqrstuvwxyz";
const int month_days[12] = {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
// --
// -- 
// -- 
// std::cout << std::fixed;
// std::cout << std::setprecision(5) << f << '\n';


int main(){
	string s;
	cin>>s;
	s[3] = '8';
	cout<<s<<endl;
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define FOR(i, a, n) for(ll i = (ll)a; i < (ll)n; i++)
#define FORR(i, n) for(ll i = (ll)n - 1LL; i >= 0LL; i--)
#define rep(i, n) FOR(i, 0, n)
#define ALL(x) begin(x), end(x)
using namespace std;
using ll = long long;
constexpr ll Mod = 998244353;
constexpr ll mod = 1e9 + 7;
constexpr ll inf = 1LL << 60;
const double PI = acos(-1);
template <typename T1, typename T2> inline bool chmax(T1 &a, T2 b) {
    return a < b && (a = b, true);
}
template <typename T1, typename T2> inline bool chmin(T1 &a, T2 b) {
    return a > b && (a = b, true);
}
/*-------------------------------------------*/

char c[20][20];
int h, w, d[20], e[20];

bool solve(int x) {
    if(x >= w) return true;
    if(~e[x]) return solve(x + 1);
    int t = 0;
    FOR(i, x, w) t ^= !~e[i];
    FOR(i, x, w) if(!~e[i]) {
        e[x] = i;
        e[i] = x;
        bool ok = true;
        rep(j, h) if(c[j][x] != c[d[j]][i]) ok = false;
        if(i == x && ok && t && solve(x + 1)) return true;
        if(i != x && ok) return solve(x + 1);
        e[x] = e[i] = -1;
    }
    return false;
}

bool dfs(int x) {
    if(x >= h) return solve(0);
    if(~d[x]) return dfs(x + 1);
    int t = 0;
    FOR(i, x, h) t ^= !~d[i];
    FOR(i, x, h)
    if(!~d[i]) {
        d[x] = i;
        d[i] = x;
        if((t || i != x) && dfs(x + 1)) return true;
        d[x] = d[i] = -1;
    }
    return false;
}

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

    memset(d, -1, sizeof(d));
    memset(e, -1, sizeof(e));

    cin >> h >> w;
    rep(i, h) cin >> c[i];

    cout << (dfs(0) ? "YES\n" : "NO\n");

    return 0;
}

Measured memory_bytes: 3652
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstring>
#include <string>
#include <cmath>
#include <vector>
#include <queue>
#include <set>
#include <climits>
#include <utility>
typedef long long ll;
using namespace std;

struct Unionfind2 {
	vector<int> par;
  vector<int> size;

	Unionfind2(int n) {
		par.resize(n);
    size.resize(n);
		for (int i = 0;i < n;i++) {
			par[i] = i;
      size[i] = 1;
		}
	}

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

	bool same(int a, int b) {
		return root(a) == root(b);
	}

	void unite(int a, int b) {
		int A = root(a);
		int B = root(b);
		if (A == B)return;

    if(size[A]>size[B])swap(A,B);
    size[B] += size[A];
		par[A] = B;
	}

  int getSize(int a){
    return size[root(a)];
  }
};

int main(int argc, char *argv[]) {
  int n, m, i, a, b;

  cin >> n >> m;
  Unionfind2 tree(n);

  for(i=0;i<m;i++){
    cin >> a >> b;
    a--, b--;
    tree.unite(a,b);
  }

  int ans = 1, size;;
  for(i=0;i<n;i++){
    size = tree.getSize(i);
    if(ans<size){
      ans = size;
    }
  }

  cout << ans << endl;

  return 0;
}


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

int main() {
    int n, k, r, s, p;
    string t;
    cin >> n >> k >> r >> s >> p >> t;
    
    auto winHand = [&](char you) {
        if (you == 'r') return 'p';
        else if (you == 's') return 'r';
        else return 's';
    };
    
    auto winPoint = [&](char you) {
        if (you == 'r') return p;
        else if (you == 's') return r;
        else return s;
    };
    
    auto rest = [&](char a, char b) {
        if (a == 'r' && b == 'r') return 's';
        else if (a == 'r' && b == 's') return 'p';
        else if (a == 'r' && b == 'p') return 's';
        else if (a == 's' && b == 's') return 'r';
        else if (a == 's' && b == 'r') return 'p';
        else if (a == 's' && b == 'p') return 'r';
        else if (a == 'p' && b == 'p') return 's';
        else if (a == 'p' && b == 'r') return 's';
        else return 'r';
    };
    
    int ans = 0;
    string you;
    for (int j = 0; j < n; ++j) you.push_back('0');
    for (int i = 0; i < n; ++i) {
        if (i - k < 0) {
            you[i] = winHand(t[i]);
            ans += winPoint(t[i]);
        } else {
            if (winHand(t[i]) == you[i - k]) {
                if (i + k < n) {
                    you[i] = rest(you[i - k], winHand(t[i + k]));
                    ans += 0;
                }
            } else {
                you[i] = winHand(t[i]);
                ans += winPoint(t[i]);
            }
        }
    }
    cout << ans << endl;
}


Measured memory_bytes: 640
# 全探索
# 証言が矛盾していないかどうかをチェックする
# 証言の妥当性のみを見れば良い感じ？
N = int(input())
X = []
Y = []
A = []
for i in range(N):
    a = int(input())
    A.append(a)
    b = []
    X_ = []
    Y_ = []

    for j in range(a):
        x, y = list(map(int, input().split()))
        X_.append(x)
        Y_.append(y)
        
    X.append(X_)
    Y.append(Y_)

# bit探索
ans = []
for i in range(2**N):
    a = [0] * N
    cnt = 0
    for j in range(N):
        if i & (1 << j):
            a[j] = 1

    for j in range(N):
        flag = False
        if a[j] == 1:
            for k in range(A[j]):
                if a[X[j][k]-1] != Y[j][k]:
                    flag = True
                    break
        if flag:
            break
    
    if flag == False:
        ans.append(a.count(1))

print(max(ans))

Measured memory_bytes: 3504
# coding: utf-8

# In[1]:

import sys
input = sys.stdin.readline
N = int(input())
A = list(map(int, input().split()))


# In[2]:

#import copy
#import numpy as np
try:
    from fractions import gcd
except:
    from math import gcd


# In[ ]:

# 左からn個の最大公約数を求める O(n)
# 右からn個の最大公約数を求める O(n)
# n個目を抜いた最大公約数は n-1個目までの公約数とn+1個目からの公約数との公約数


# In[3]:

lg = [1]*(N)
rg = [1]*(N)
ans = 0


# In[4]:

#print(lg)
#print(rg)
#print(A)


# In[5]:

lg[0] = A[1]
rg[0] = A[N-2]
lg[1] = A[0]
rg[1] = A[N-1]
#print(lg, rg)
for i in range(1, N-1):
    #print(i)
    lg[i+1] = gcd(lg[i], A[i])
    #print(lg[i], A[i])
    rg[i+1] = gcd(rg[i], A[N-1-i])
    #print(rg[N-1-i], A[N-1-i])
#print(lg, rg)

for i in range(N):
    #print(i, lg[i], rg[N-i-1])
    tmp = gcd(lg[i], rg[N-i-1])
    #print(tmp)
    if ans < tmp:
        ans = tmp
    #print(ans)


# In[6]:

print(ans)


# In[ ]:

"""
[42 54 69 92 12 23]のとき
 1 [54 69 92 12 23]の最大公約数
 2 [42 69 92 12 23]
 3 [42 54 92 12 23]
 4 [42 54 69 12 23]

"""



Measured memory_bytes: 14072
package main

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

var scanner = bufio.NewScanner(os.Stdin)

func scanInt() int {
	scanner.Scan()
	a, err := strconv.Atoi(scanner.Text())
	if err != nil {
		fmt.Println(err)
	}
	return a
}

type To struct {
	e int
	w int
}

func makeLengths(n int, to map[int][]To, l []int) {
	l[0] = 0
	var impl func(p, gp int)
	impl = func(p, gp int) {
		if to[p] == nil {
			return
		}
		for _, nextTo := range to[p] {
			if nextTo.e == gp {
				continue
			}
			l[nextTo.e] = nextTo.w + l[p]
			impl(nextTo.e, p)
		}
	}
	impl(0, -1)
}

func main() {
	scanner.Split(bufio.ScanWords)

	n := scanInt()

	to := map[int][]To{}

	for i := 0; i < n-1; i++ {
		u := scanInt()
		v := scanInt()
		w := scanInt()

		if to[u-1] == nil {
			to[u-1] = []To{{e: v - 1, w: w}}
		} else {
			to[u-1] = append(to[u-1], To{e: v - 1, w: w})
		}

		if to[v-1] == nil {
			to[v-1] = []To{{e: u - 1, w: w}}
		} else {
			to[v-1] = append(to[v-1], To{e: u - 1, w: w})
		}
	}

	l := make([]int, n)
	makeLengths(n, to, l)

	for i := range l {
		if l[i]%2 == 0 {
			fmt.Println(0)
		} else {
			fmt.Println(1)
		}
	}
}

Measured memory_bytes: 38656
#include<iostream>
#include<stdio.h>
#include<cstring>
#include<cmath>
#include<vector>
#include<set>
#include<map>
#include<algorithm>
#include<unordered_map>
#define ll long long 
#define dd double
using namespace std;
 
int main()
{
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  int n;
  cin>>n;
  int w[n];
  int i;
  for(i=0;i<n;i++){
     cin>>w[i];
  }
  
  vector<int> v;
  int s1,s2;
  int t;
  for(t=0;t<n;t++){
  	s1=0;
  	s2=0;
  	for(i=0;i<=t;i++){
  		s1=s1+w[i];
	  }
    for(i=t+1;i<n;i++){
    	s2=s2+w[i];
	}
  	
   v.push_back(abs(s1-s2));
  	
  }
  
  sort(v.begin(),v.end());
  cout<<*v.begin()<<endl;
  
  return 0;
}

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

using namespace std;

#define ll long long

char resp[5];

char query(ll x) {
	printf("? %lld\n", x);
	fflush(stdout);
	scanf("%s", resp);
	return resp[0];
}
ll p10[13];
ll bs(int len) {
	ll start = p10[len], End = p10[len + 1] - 1, ans = 0;
	while (start <= End) {
		auto mid = (start + End) / 2;
		if (query(mid) == 'N') {
			ans = mid;
			start = mid + 1;
		}
		else End = mid - 1;
	}
	return ans;
}
void Finish(ll val) {
	printf("! %lld\n", val);
	fflush(stdout);
	exit(0);
}
int main() {
	//freopen("oj.in", "r", stdin);
	p10[0] = 1;
	for (int i = 1; i <= 11; ++i)
		p10[i] = p10[i - 1] * 10;
	int len = 1;
	for (int i = 10; i >= 1; --i) {
		ll curr = p10[i];
		if (query(curr) == 'Y') {
			len = i;
			break;
		}
	}
	auto mayb = bs(len + 1);
	if (mayb == 0) {
		for (int i = 1; i <= 10; ++i) {
			if (query(p10[i] - 1) == 'Y') {
				Finish(p10[i - 1]);
			}
		}

	}
	else {
		mayb = mayb / 10 + 1;
		if (mayb / 100 == 0 && mayb % 10 == 0) {
			if (query(mayb / 10) == 'Y')mayb /= 10;
		}
		Finish(mayb);
	}
	return 0;
}


Measured memory_bytes: 596
function Main(input) {
  var N = parseInt(input[0], 10);
  var H = input.slice(1).map(h => parseInt(h, 10));
  var current = H[0];

  for (i = 1; i < N; i++) {
    if (current === H[i]) {
      current = H[i];
    } else if (current <= H[i] - 1) {
      current = H[i] - 1;
    } else {
      return console.log('No');
    }
  }
  console.log('Yes');
}

Main(require("fs").readFileSync("/dev/stdin", "utf8").trim().split(/\n|\s/));

Measured memory_bytes: 26816
k,n = map(int, input().split())
lst = list(map(int, input().split()))

maxDis = (k-lst[-1]) + lst[0]
for i in range(n-1):
  if lst[i+1] - lst[i] > maxDis:
    maxDis = lst[i+1] - lst[i]
print(k-maxDis)

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

int main(){
  int n;
  cin >> n;
  int a,b,c,d;
  a = n / 1000;
  b = (n % 1000)/100;
  c = (n % 100)/10;
  d = n % 10;
  char op1 = '+',op2 = '+',op3 = '+';
  if(a+b+c+d == 7){
    cout << a << op1 << b << op2 << c << op3 << d << "=7" << endl;
  }else if(a+b+c-d == 7){
    op3 = '-';
    cout << a << op1 << b << op2 << c << op3 << d << "=7" << endl;
  }else if(a+b-c+d == 7){
    op2 = '-';
    cout << a << op1 << b << op2 << c << op3 << d << "=7" << endl;
  }else if(a+b-c-d == 7){
    op2 = op3 = '-';
    cout << a << op1 << b << op2 << c << op3 << d << "=7" << endl;
  }else{
    op1 = '-';
    if(a-b+c+d == 7){
      cout << a << op1 << b << op2 << c << op3 << d << "=7" << endl;
    }else if(a-b+c-d == 7){
      op3 = '-';
      cout << a << op1 << b << op2 << c << op3 << d << "=7" << endl;
    }else if(a-b-c+d == 7){
      op2 = '-';
      cout << a << op1 << b << op2 << c << op3 << d << "=7" << endl;
    }else if(a-b-c-d == 7){
      op2 = op3 = '-';
      cout << a << op1 << b << op2 << c << op3 << d << "=7" << endl;
    }
  }

  //cout << a << op1 << b << op2 << c << op3 << d << "=7" << endl;
  return 0;
}


Measured memory_bytes: 256
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cfloat>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <memory>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <sstream>
#include <deque>
#include <complex>
#include <stack>
#include <queue>
#include <cstdio>
#include <cctype>
#include <cstring>
#include <ctime>
#include <iterator>
#include <bitset>
#include <numeric>
#include <list>
#include <iomanip>
#include <cassert>

#if __cplusplus >= 201103L
#include <array>
#include <tuple>
#include <initializer_list>
#include <unordered_set>
#include <unordered_map>
#include <forward_list>

#define cauto const auto&
#define ALL(v) begin(v),end(v)
#else
#define ALL(v) (v).begin(),(v).end()
#endif

using namespace std;


namespace{
typedef long long LL;
typedef pair<int,int> pii;
typedef pair<LL,LL> pll;

typedef vector<int> vint;
typedef vector<vector<int> > vvint;
typedef vector<long long> vll, vLL;
typedef vector<vector<long long> > vvll, vvLL;

#define VV(T) vector<vector< T > >

template <class T>
void initvv(vector<vector<T> > &v, int a, int b, const T &t = T()){
	v.assign(a, vector<T>(b, t));
}

template <class F, class T>
void convert(const F &f, T &t){
	stringstream ss;
	ss << f;
	ss >> t;
}


#define REP(i,n) for(int i=0;i<int(n);++i)
#define RALL(v) (v).rbegin(),(v).rend()


#define MOD 1000000007LL
#define EPS 1e-8

const int INF = 1010101010;

void mainmain(){
	int n, ma, mb;
	cin >> n >> ma >> mb;
	
	vector<int> dp(10000, INF);
	for(int i = 0; i < n; ++i){
		int a, b, c;
		cin >> a >> b >> c;
		int t = a * mb - b * ma;
		if(t > 0){
			for(int j = 9999 - t; j >= 0; --j){
				dp[j] = min(dp[j], dp[j - t] + c);
			}
		}
		else{
			for(int j = 0; j - t < 10000; ++j){
				dp[j] = min(dp[j], dp[j - t] + c);
			}
		}
		dp[5000 + t] = min(dp[5000 + t], c);
	}
	
	int ans = dp[5000];
	if(ans == INF){ ans = -1; }
	cout << ans << endl;
}



}
int main() try{
//	ios::sync_with_stdio(false);
	cout << fixed << setprecision(10);
	cerr << fixed << setprecision(4);
	mainmain();
}
catch(...){}


Measured memory_bytes: 384
fn main() {
    let mut sc = Scanner::new();
    let n: usize = sc.read();
    let dist: Vec<Vec<u64>> = (0..n).map(|_| (0..n).map(|_| sc.read()).collect()).collect();

    for k in 0..n {
        for i in 0..n {
            for j in 0..n {
                if dist[i][j] > dist[i][k] + dist[k][j] {
                    println!("-1");
                    return;
                }
            }
        }
    }

    let mut sum = 0;
    for i in 0..n {
        for j in (i + 1)..n {
            let mut check = true;
            for k in 0..n {
                if k == i || k == j { continue; }
                if dist[i][j] == dist[i][k] + dist[k][j] {
                    check = false;
                    break;
                }
            }
            if check {
                sum += dist[i][j];
            }
        }
    }

    println!("{}", sum);
}

struct Scanner {
    ptr: usize,
    length: usize,
    buf: Vec<u8>,
    small_cache: Vec<u8>,
}

impl Scanner {
    fn new() -> Scanner {
        Scanner { ptr: 0, length: 0, buf: vec![0; 1024], small_cache: vec![0; 1024] }
    }

    fn load(&mut self) {
        use std::io::Read;
        let mut s = std::io::stdin();
        self.length = s.read(&mut self.buf).unwrap();
    }

    fn byte(&mut self) -> u8 {
        if self.ptr >= self.length {
            self.ptr = 0;
            self.load();
            if self.length == 0 {
                self.buf[0] = b'\n';
                self.length = 1;
            }
        }

        self.ptr += 1;
        return self.buf[self.ptr - 1];
    }

    fn is_space(b: u8) -> bool { b == b'\n' || b == b'\r' || b == b'\t' || b == b' ' }

    fn read<T>(&mut self) -> T where T: std::str::FromStr, T::Err: std::fmt::Debug, {
        let mut b = self.byte();
        while Scanner::is_space(b) {
            b = self.byte();
        }

        for pos in 0..self.small_cache.len() {
            self.small_cache[pos] = b;
            b = self.byte();
            if Scanner::is_space(b) {
                return String::from_utf8_lossy(&self.small_cache[0..(pos + 1)]).parse().unwrap();
            }
        }

        let mut v = self.small_cache.clone();
        while !Scanner::is_space(b) {
            v.push(b);
            b = self.byte();
        }
        return String::from_utf8_lossy(&v).parse().unwrap();
    }
}



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

typedef long long ll;

const ll mod = 1e9 + 7;

int s[2005];
int t[2005];

ll dp[2005][2005];
ll sum[2005][2005];

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

  for(int i = 1; i <= n; i++) cin >> s[i];
  for(int i = 1; i <= m; i++) cin >> t[i];

  dp[0][0] = 1;
  
  for(int i = 0; i <= n; i++) sum[i][0] = 1;
  for(int i = 0; i <= m; i++) sum[0][i] = 1;
  
  for(int i = 1; i <= n; i++) {
    for(int j = 1; j <= m; j++) {
      if(s[i] == t[j]) dp[i][j] = sum[i-1][j-1];
      sum[i][j] = (sum[i-1][j] + sum[i][j-1] - sum[i-1][j-1] + dp[i][j] + mod) % mod;
    }
  }

 

  cout << sum[n][m] % mod << endl;
}


Measured memory_bytes: 62848
#include <iostream>
using namespace std;
int main()
{
	long long int pnum;
	long long city[5];
	scanf("%lld",&pnum);
	scanf("%lld",&city[0]);
	long long mintime=city[0];
	for(int i=1; i<5; i++)
	{
		scanf("%lld",&city[i]);
		mintime=mintime>city[i] ? city[i] : mintime;
	}
	long long answer;
	answer=((pnum-1)/mintime)+5;

	printf("%lld\n",answer);
	
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main () {
  int n,sum=0,a,ret=0;
  scanf ("%d",&n);
  for (int i = 0; i < n; i++) {
  	scanf ("%d",&a);
    ret += sum*a;
    sum += a;
  }
  printf ("%d\n",ret);
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
typedef long long ll;
#define _GLIBCXX_DEBUG
#define int long long
using namespace std;
#define REP(i, n) for (ll i = 0; i < (ll)(n); i++)
#define REPR(i, n) for (ll i = (ll)(n)-1; i >= 0; i--)
#define FOR(i, a, b) for (ll i = a; i <= (ll)(b); i++)
#define FORD(i, a, b) for (ll i = a; i >= (ll)(b); i--)
#define ALL(x) (x).begin(), (x).end()
#define SIZE(x) ((ll)(x).size())
#define MAX(x) *max_element(ALL(x))
#define MAXIN(x) max_element(ALL(x)) - x.begin();
#define MIN(x) *min_element(ALL(x))
#define MININ(x) min_element(ALL(x)) - x.begin();
#define INF 1000000000000
#define MOD 1000000007

#define MAXR 100000
#define PI 3.14159265358979323846
using namespace std;

signed main() {
    int a;
    cin >> a;
    vector<int> A(a);
    vector<int> B(a) ;
    REP(i, a){
        cin >> A[i];
        cin >> B[i];
    }

    int sameCount = 0;

    REP(i,a){

        if(A[i] == B[i]){
            sameCount++;
        }else{
            sameCount = 0;
        }
        if(sameCount >= 3){
            cout << "Yes" <<endl ;
            return 0;
        }

    }

    cout << "No" <<endl ;

    return 0;
    return 0;
}

Measured memory_bytes: 3620
#include <iostream>
#include <iomanip>
#include <cmath>
#include <vector>
#include <string>
#include <algorithm>

using namespace std;
static const int Max = 200000;

int main()
{
	int n;

	cin >> n;
	int maxv = -1000000000;
	int minp,temp;
	
	cin >> minp;

	for (int i = 0; i < (n - 1); i++) {
		cin >> temp;
		maxv = max(maxv, temp - minp);
		minp = min(minp, temp);
	}

	cout << maxv << endl;

	return 0;
}


Measured memory_bytes: 3104
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define l long
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define ff first
#define ss second
#define pii pair <int,int>
#define pll pair <ll,ll>
#define testcase() int t; cin>>t; while(t--)

ll M = 1e9 + 7;
ll powerm(ll x,ll y){ ll res=1; while(y){ if(y&1) res=(res*x)%M; y=y>>1; x=(x*x)%M;} return res%M; }
ll power(ll x,ll y){ ll res=1; while(y){ if(y&1) res=(res*x); y=y>>1; x=(x*x);} return res; }
ll max3(ll a,ll b,ll c){ return max( max(a,b),c ); }
ll gcd(ll a,ll b){if(b>a)return gcd(b,a); if(b==0)return a; return gcd(b,a%b);}


int main() {
	
	//ifstream cin("input.txt");
	//ofstream cout("output.txt");
	ios_base::sync_with_stdio(false); 
    cin.tie(NULL); 
	
	int a[3]; for(int i=0;i<3;i++) cin>>a[i];
	int k; cin>>k;
	int ans = 0;
	if(k<a[0]){ cout<<k; return 0; }
	ans += a[0];
	k -= a[0];
	if(k<a[1]){ cout<<ans; return 0; }
	k -= a[1];
	ans -= k;
	cout<<ans;
	
	return 0;
}


Measured memory_bytes: 3652
#include<iostream>
#include<vector>
#include<string>

int main(){
    int n;
    std::cin >> n;
    std::vector<int> a(n), b(n), c(n - 1);
    for(int i = 0; i < n; i++) std::cin >> a[i];
    for(int i = 0; i < n; i++) std::cin >> b[i];
    for(int i = 0; i < n - 1; i++) std::cin >> c[i];
    int cost = b[a[0] - 1];
    for(int i = 1; i < n; i++){
        cost += b[a[i] - 1];
        if(a[i - 1] + 1 == a[i]) cost += c[a[i - 1] - 1];
    }
    std::cout << cost << std::endl;
    return 0;
}


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

char s[50][50];
int main(){
  int h,w,ans;
  ans=0;
  cin>>h>>w;
  for(int i=0;i<h+2;i++){
    for(int j=0;j<w+2;j++){
      s[i][j]='.';
    }
  }
  for(int i=1;i<h+1;i++){
    for(int j=1;j<w+1;j++){
      cin>>s[i][j];
    }
  }
  for(int i=1;i<h+1;i++){
    for(int j=1;j<w+1;j++){
      if (s[i][j]=='#'){
        if (s[i-1][j]=='.' && s[i+1][j]=='.' && s[i][j+1]=='.' && s[i][j-1]=='.' ){
          ans+=1;
        }

      }
    }
  }
  if (ans>=1){
    cout<<"No";}
    else{
      cout<<"Yes";}
    }
  


Measured memory_bytes: 256
#include <iostream>

int main() {
  int A, B, C;
  std::cin >> A >> B >> C;
  for (int n = 1; n < B + 1; n++) {
    if (n*A%B == C) {
      std::cout << "YES" << std::endl;
      return 0;
    }
  }
  std::cout << "NO" << std::endl;
  return 0;
}

Measured memory_bytes: 256
import math
from functools import reduce

k = int(input())

ans = 0

ab = [math.gcd(a,b) for a in range(1, k+1) for b in range(1, k+1)]

for gcd_ab in ab:
    for c in range(1, k+1):
        ans += math.gcd(gcd_ab,c)

print(ans)



Measured memory_bytes: 9840
from sys import exit, setrecursionlimit, stderr
from functools import reduce
from itertools import *
from collections import defaultdict
from bisect import bisect
from heapq import heappush, heappop

setrecursionlimit(10**6)

def read():
  return int(input())

def reads():
  return [int(x) for x in input().split()]

n, m, s, t = reads()
s, t = s-1, t-1
esyen = [[] for _ in range(n)]
essnk = [[] for _ in range(n)]

for _ in range(m):
  u, v, a, b = reads()
  u, v = u-1, v-1
  esyen[u].append((a, v))
  esyen[v].append((a, u))
  essnk[u].append((b, v))
  essnk[v].append((b, u))

INF = 10**15

def dijkstra(s, edges):
  que = []
  d = [INF] * n
  d[s] = 0
  heappush(que, (0, s))

  while len(que) > 0:
    (c, v) = heappop(que)
    if d[v] < c:
      continue
    for (cc, w) in edges[v]:
      if d[w] > d[v] + cc:
        d[w] = d[v] + cc
        heappush(que, (d[w], w))
  
  return d

ds = dijkstra(s, esyen)
dt = dijkstra(t, essnk)

scores = [0] * n
for i in range(n):
  scores[i] = 10**15 - (ds[i] + dt[i])

amax = [10**15] * n
amax[-1] = scores[-1]
for i in range(n-2, -1, -1):
  amax[i] = max(amax[i+1], scores[i])

for i in range(n):
  print(amax[i])

Measured memory_bytes: 82916
#include <bits/stdc++.h>
using namespace std;
int a[300],b[300];
int ans=10000000;
int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	int n;
	cin>>n;
	cin>>a[0];
	b[0]=a[0];
	for(int i=2; i<2*n; i+=2) {
		cin>>a[i];
		b[i]=b[i-2]+a[i];
	}
	for(int i=1; i<=2*n; i+=2) {
		ans=min(abs(b[i-1]*2-b[2*n-2]),ans);
	}
	cout<<ans;
}

Measured memory_bytes: 256
A, B, C, D = gets.split.map(&:to_i)

takahashi_life_time = A % D == 0 ? A / D : A / D + 1
aoki_life_time = C % B == 0 ? C / B : C / B + 1

if takahashi_life_time < aoki_life_time
  puts 'No'
else
  puts 'Yes'
end

Measured memory_bytes: 14356
# -*- coding: utf-8 -*-
import sys 
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
N = int(readline())
A = list(map(int,readline().split()))

ans1 = 0
ans2 = 0
S1 = 0
S2 = 0
# 偶数項-,奇数項を+にする
for i in range(N):
    S1 += A[i]
    S2 += A[i]
    if i & 1: 
        if S1 >= 0:
            ans1 += S1+1
            S1 = -1
        if S2 <= 0:
            ans2 += 1-S2
            S2 = 1
    else: 
        if S1 <= 0:
            ans1 += 1-S1
            S1 = 1
        if S2 >= 0:
            ans2 += S2+1
            S2 = -1
print(min(ans1,ans2))   

Measured memory_bytes: 18340
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <vector>
#include <cmath>
using namespace std;

int N; vector<int> a;
void input()
{
    cin>>N;
    a.resize(N);
    for(int i=0;i<N;++i) cin>>a[i];
}

void solve()
{
    int ans=0;
    for(int i=0;i<N;i+=2){
        if(a[i]%2==1) ++ans;
    }
    cout<<ans<<endl;
}

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

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

using namespace std;

int main(){
    int cnt = 0;
    char p = '\0', c;
    
    for (int i = 0; i < 3; i++) {
        cin >> c;
        if (c == 'R' && c == p)
            cnt++;
        else if(c == 'R')
            cnt = 1;

        p = c;
    }

    cout << cnt << endl;
        
    return 0;
}

Measured memory_bytes: 3640
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
#define inf 1072114514
#define llinf 1145141919810364364
#define mod 1000000007

int max(int a,int b){if(a>b){return a;}return b;}
int min(int a,int b){if(a<b){return a;}return b;}
int zt(int a,int b){return max(a,b)-min(a,b);}
int round(int a,int b){if((a%b)*2 >= b){return (a/b)+1;}return a/b;}
int ceil(int a,int b){if(a%b==0){return a/b;}return (a/b)+1;}
int gcd(int a,int b){int c;while(b!=0){c=a%b;a=b;b=c;}return a;}
int lcm(int a,int b){int c=gcd(a,b);a/=c;return a*b;}
int nCr(int a,int b){int i,r=1;for(i=1;i<=b;i++){r*=(a+1-i);r/=i;}return r;}
int fact(int a){int i,r=1;for(i=1;i<=a;i++){r*=i;}return r;}
int pow(int a,int b){int i,r=1;for(i=1;i<=b;i++){r*=a;}return r;}
long long llmax(long long a,long long b){if(a>b){return a;}return b;}
long long llmin(long long a,long long b){if(a<b){return a;}return b;}
long long llzt(long long a,long long b){return llmax(a,b)-llmin(a,b);}
long long llround(long long a,long long b){if((a%b)*2 >= b){return (a/b)+1;}return a/b;}
long long llceil(long long a,long long b){if(a%b==0){return a/b;}return (a/b)+1;}
long long llgcd(long long a,long long b){long long c;while(b!=0){c=a%b;a=b;b=c;}return a;}
long long lllcm(long long a,long long b){long long c=llgcd(a,b);a/=c;return a*b;}
long long llnCr(long long a,long long b){long long i,r=1;for(i=1;i<=b;i++){r*=(a+1-i);r/=i;}return r;}
long long llfact(long long a){long long i,r=1;for(i=1;i<=a;i++){r*=i;}return r;}
long long llpow(long long a,long long b){long long i,r=1;for(i=1;i<=b;i++){r*=a;}return r;}
double dbmax(double a,double b){if(a>b){return a;}return b;}
double dbmin(double a,double b){if(a<b){return a;}return b;}
double dbzt(double a,double b){return dbmax(a,b)-dbmin(a,b);}
int sortfncsj(const void *a,const void *b){if(*(int *)a>*(int *)b){return 1;}if(*(int *)a==*(int *)b){return 0;}return -1;}
int sortfnckj(const void *a,const void *b){if(*(int *)a<*(int *)b){return 1;}if(*(int *)a==*(int *)b){return 0;}return -1;}
int llsortfncsj(const void *a,const void *b){if(*(long long *)a>*(long long *)b){return 1;}if(*(long long *)a==*(long long *)b){return 0;}return -1;}
int llsortfnckj(const void *a,const void *b){if(*(long long *)a<*(long long *)b){return 1;}if(*(long long *)a==*(long long *)b){return 0;}return -1;}
int dbsortfncsj(const void *a,const void *b){if(*(double *)a>*(double *)b){return 1;}if(*(double *)a==*(double *)b){return 0;}return -1;}
int dbsortfnckj(const void *a,const void *b){if(*(double *)a<*(double *)b){return 1;}if(*(double *)a==*(double *)b){return 0;}return -1;}

int main(void){
    int i,n,k,r=0,x;
    scanf("%d%d",&n,&k);
    for(i = 1;i <= n;i++){
        scanf("%d",&x);
        r+=(min(x,k-x));
    }
    printf("%d\n",r*2);
    return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace  std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define ll long long

int main(){
  int N;
  cin >> N;
  vector<int> A(N);
  rep(i, N){
    cin >> A[i];
  }
  
  int ans = 0;
  while (true){
    if ( *max_element(A.begin(), A.end()) == 0) break;
    
    int i = 0;
    while (i < N){
      if (A[i] == 0) i++;
      else {
        ans++;
        while (i < N && A[i] > 0) {
          --A[i];
          i++;
        }
      }
    }
  }
    
  cout << ans << endl;
          
}

Measured memory_bytes: 256
#include <iostream>
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <queue>
#include <vector>
#include <algorithm>
#include <map>


int main(){
  int N, M;
  scanf("%d",&N);
  scanf("%d",&M);
  std::vector<int > p(M);
  std::vector<std::string > S(M);
  for (int i=0; i<M; i++){
    scanf("%d",&p[i]);
    p[i]--;
    std::cin >> S[i];
  }

  std::vector<bool > ac(N, false);
  std::vector<bool > ac_final(N, false);
  int err = 0;
  for (int i=0; i<M; i++){
    if (S[i]=="AC"){
      ac_final[p[i]] = true;
    }
  }

  for (int i=0; i<M; i++){
    if (S[i]=="AC"){
      ac[p[i]] = true;
    } else {
      if (!ac[p[i]] && ac_final[p[i]]){
      err++;
      }
    }
  }

  int ok = 0;
  for (int i=0; i<N; i++){
    //std::cout <<"ac_final["<<i<<"]="<<ac_final[i]<<std::endl;
    if (ac_final[i]){
      ok++;
    }
  }
  std::cout << ok << " " << err << std::endl;
  return 0;
}


Measured memory_bytes: 3072
n, m, c = map(int, input().split())
b = [int(x) for x in input().split()]
a = []
cnt = 0
for i in range(n):
    ar = [int(x) for x in input().split()]
    a.append(ar)
for i in range(n):
    sc = 0
    for j in range(m):
        sc += b[j]*a[i][j]
    sc += c
    if sc > 0:
        cnt += 1

print(cnt)


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

const int MAX_N = 200005;
int N, K;
int a[MAX_N], b[MAX_N];

vector<int> sliding_window(int* arr, int len, int win)
{
	vector<int> res(len, 0);
	deque<int> que;
	for(int i=0;i<len;++i){
		while(!que.empty() && arr[que.back()]>=arr[i]) que.pop_back();
		que.push_back(i);
		if(que.front() == i-win) que.pop_front();
		if(i>=win-1) res[i]=arr[que.front()];
	}
	return res;
}

void solve()
{
	for(int i=0;i<N;++i) b[i]=-a[i];
	auto min_e = sliding_window(a, N, K-1);
	auto max_e = sliding_window(b, N, K-1);
	vector<int> L(N);
	L[0]=1;
	for(int i=1;i<N;++i) L[i]=(a[i]>a[i-1]?L[i-1]+1:1);
	int ans = 0;
	bool f = false;
	for(int i=K-1;i<N;++i){
		if(L[i]>=K){
			if(!f){
				ans++;
				f = true;
			}
		}else if(!(i>=K && a[i-K] < min_e[i-1] && a[i] > -max_e[i-1])){
			ans++;
		}
	}
	cout << ans << '\n';
}

int main()
{
	cin >> N >> K;
	for(int i=0;i<N;++i) cin >> a[i];
	solve();
	return 0;
}

Measured memory_bytes: 4336
#include <iostream>
#include <algorithm>
#include <iomanip>
#include <string>
#include <vector>
#include <math.h>
#include <queue>
#include <deque>
#include <stack>
#include <map>
const int MOD = 1e9+7;
#define PI 3.14159265359
typedef long long ll;
using namespace std;

int n;
string s;

bool is_ok(){
	for (int i = 0; i < n-1; i++){
		if (s[i] == 'W' && s[i+1] == 'R'){
			return false;
		}
	}
	return true;
}

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

	if (is_ok()){
		cout << 0 << endl;
		return 0;
	}
	int coun = 0, ans = 0;
	for (int i = 0; i < n; i++){
		if (s[i] == 'R') coun++;
	}
	for (int i = 0; i < coun; i++){
		if (s[i] == 'W') ans++;
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 3732
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(x) x.begin(), x.end()
using namespace std;
typedef long long ll;
typedef pair<int, int> pair;
const int inf = 1000000000; //10^9
const ll inff = 1000000000000000000; //10^18

int main(){
    int a, b, k;
    cin >> a >> b >> k;

    vector<int> w(0);
    for(int i = 1; i <= min(a,b); i++) if(a%i == 0 && b%i == 0) w.push_back(i);
    reverse(all(w));

    cout << w[k-1] << endl;

    return 0;
}

Measured memory_bytes: 3628
import java.util.PriorityQueue;
import java.util.Queue;
import java.util.Scanner;
import java.util.Arrays;
import java.util.Comparator;

class Main
{
    public static void main(String[] args)
    {
      Scanner sc = new Scanner(System.in);
      int n = sc.nextInt();
      int m = sc.nextInt();
      long[] price = new long[n];
      int sum = 0;
      Queue<Integer> q = new PriorityQueue<>(Comparator.reverseOrder());
      for (int i=0; i<n; i++) {
        int a = sc.nextInt();
        q.offer(a);
      }
      
      for (int i=0;i<m;i++) {
        int a = q.poll();
        a /= 2;
        q.offer(a);
      }
      
      long ans = 0;
      for(int i=0; i<n; i++) {
        ans += q.poll();
      }
      
      System.out.println(ans);
      
    }
}



Measured memory_bytes: 64100
#include <stdio.h>

int main(void){
	
	char S[10];
	scanf("%s",S);
	if(S[0] == 'Y'&&S[1] == 'A'&&S[2] == 'K'&&S[3] == 'I')
	printf("Yes");
	else
	printf("No");
	
	
	return 0;}

Measured memory_bytes: 128
n = int(input())
values = list(map(int,input().split()))
costs = list(map(int,input().split()))
d=[]
for i in range(n):
    d.append(values[i]-costs[i])
d.sort(reverse=True)

ans =0 
for e in d:
    if e>0:
        ans += e
    else:break
print(ans)


Measured memory_bytes: 3060
#include <bits/stdc++.h>
#define rep(i, n) for (ll i = 0; i < n; ++i)
using ll = long long;
using namespace std;
const int INF = 1e9;

int main() {
    int sx, sy, tx, ty;
    cin >> sx >> sy >> tx >> ty;

    rep(i, tx - sx) cout << "R";
    rep(i, ty - sy) cout << "U";

    rep(i, tx - sx) cout << "L";
    rep(i, ty - sy) cout << "D";

    cout << "D";
    rep(i, tx - sx + 1) cout << "R";
    rep(i, ty - sy + 1) cout << "U";

    cout << "LU";
    rep(i, tx - sx + 1) cout << "L";
    rep(i, ty - sy + 1) cout << "D";

    cout << "R" << endl;

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <unordered_set>
using namespace std;
#define ll long long
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define repeat(i,s,n) for(int (i)=s; (i)<(n); (i)++)
#define revrep(i,n) for(int (i)=(n)-1;i>=0; i--)

int f(char ch) {
  return static_cast<int>(ch-'0');
}

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout<<setprecision(std::numeric_limits<float>::max_digits10);
  string s;
  cin>>s;
  int a=10000;
  rep(i,s.size()-2) {
    int b = f(s[i])*100+f(s[i+1])*10+f(s[i+2]);
    //cout << b << endl;
    a=min(a,abs(753-b));
  }
  cout << a << endl;
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define FOR(i, m, n) for (int i = m; i < (n); i++)
#define RFOR(i, m, n) for (int i = (m - 1); i >= 0; i--)
#define REP(i, n) FOR(i, 0, n)
#define RREP(i, n) RFOR(i, n, 0)
#define ALL(v) v.begin(), v.end()
#define RALL(v) v.rbegin(), v.rend()
using namespace std;
typedef long long ll;
const int mod = 1e9 + 7;

ll gcd(ll x, ll y) { return y ? gcd(y, x % y) : x; }

ll factorial(ll n) {
  ll answer = 1;
  while (n > 1) {
    answer *= n;
    answer %= mod;
    n--;
  }
  return answer;
}

ll combination(ll n, ll r) {
  return factorial(n) / (factorial(r) * factorial(n - r));
}

ll permutation(ll n, ll r) { return factorial(n) / factorial(n - r); }

int main() {
  int w, h, n;
  cin >> w >> h >> n;
  vector<int> xx = {0, w}, yy = {0, h};

  REP(i, n) {
    int x, y, a;
    cin >> x >> y >> a;
    if (a == 1) {
      xx[0] = max(xx[0], x);
    } else if (a == 2) {
      xx[1] = min(xx[1], x);
    } else if (a == 3) {
      yy[0] = max(yy[0], y);
    } else {
      yy[1] = min(yy[1], y);
    }
  }
  int xAbs = max(xx[1] - xx[0], 0);
  int yAbs = max(yy[1] - yy[0], 0);
  int anser = xAbs * yAbs;
  cout << anser << endl;
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
const int64_t INF = (1LL << 62);

int main()
{
  int N, t = 0;
  double v;
  cin >> N;
  vector<double> T(N), maxv(40010, INF);
  maxv[0] = 0;
  for (int i = 0; i < N; i++)
    cin >> T.at(i);
  for (int i = 0; i < N; i++)
  {
    cin >> v;
    for (int j = 0; j <= T.at(i) * 2; j++)
    {
      maxv.at(t + j) = min(v, maxv.at(t + j));
    }
    t += T.at(i) * 2;
  }
  maxv[t] = 0;
  for (int i = 1; i <= t; i++)
    maxv[i] = min(maxv[i], maxv[i - 1] + 0.5);
  for (int i = t - 1; i >= 0; i--)
    maxv[i] = min(maxv[i], maxv[i + 1] + 0.5);
  double ans = 0;
  for (int i = 1; i <= t; i++)
    ans += ((maxv[i - 1] + maxv[i]) * 0.5) / 2.0;
  cout << fixed << setprecision(15) << ans << endl;
}


Measured memory_bytes: 512
using System;

namespace Payment
{
    class Program
    {
        

        static void Main(string[] args)
        {
            string inD0 = Console.ReadLine();
           int N = int.Parse(inD0);
            int M = N % 1000;
            if (M == 0)
            {
                Console.WriteLine(0);
            }
            else
            {
                Console.WriteLine(1000 - M);
            }
        }
    }
}


Measured memory_bytes: 27532