akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
int main() {
  int A, B,C, D;
  cin >> A >> B >> C >> D;
  
  int lower = max(A, C);
  int upper = min(B, D);
  
  if(lower > upper) cout << 0 << endl;
  else cout << upper - lower << endl;
  
  
  return 0;
}

Measured memory_bytes: 256
# include<bits/stdc++.h>
# include<unordered_map>
# include<unordered_set>
//# include<prettyprint.hpp>
using namespace std;
# define ll long long
int main(){
    ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
    ll n, m; cin >> n >> m;
    vector<ll> h(n);
    for(ll i = 0; i < n; i++) cin >> h[i];
    vector<set<ll> > d(n);
    for(ll i = 0; i < m; i++){
        ll u, v; cin >> u >> v;
        u--, v--;
        d[u].insert(h[v]);
        d[v].insert(h[u]);
    }
    ll ans = 0;
    for(ll i = 0; i < n; i++){
        if (d[i].size() == 0){
            ans++;
            continue;
        }
        auto ptr = d[i].end();
        ptr--;
        if (*ptr < h[i]) ans++;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 17984
#include <bits/stdc++.h>
#define FOR(i,k,n)  for(int i = (k);i < (n);++i)
#define REP(i,n)    FOR(i,0,n)
#define ALL(x)      begin(x),end(x)

using namespace std;
using vecint = vector<int>;
using ll = int64_t;

int main()
{
  int n;
  cin>>n;
  vecint a(n);
  REP(i,n) cin>>a[i];
  sort(ALL(a));
  int cnt = 0;
  auto itr_last = end(a);
  vector<bool> enable(n, true);
  for (int i = 29; i >= 0; --i) {
    auto itr_first = lower_bound(ALL(a), 1<<i);
    int old = -1;
    int offset = 0;
    for (auto itr = itr_first; itr != itr_last; ++itr) {
      int index = itr - begin(a);
      if (!enable[index]) continue;
      enable[index] = false;
      int b = (1<<(i+1)) - *itr;
      auto p = equal_range(ALL(a), b);
      if (*itr == old) {
        p.first += offset;
      } else {
        offset = 0;
      }
      for (auto itr2 = p.first; itr2 != p.second; ++itr2) {
        int j = itr2 - begin(a);
        if (enable[j]) {
          enable[j] = false;
          ++cnt;
          break;
        }
        ++offset;
      }
      old = *itr;
    }
    itr_last = itr_first;
  }
  cout << cnt << endl;
  return 0;
}


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

int main () {
	int n;
	cin >> n; 
	string s; 
	cin >> s;
	int ans = 0;
	for(int i = 0; i <= n - 3; i++) {
		string a, b, c;
		a = s[i];
		b = s[i + 1];
		c = s[i + 2];
		string news = a + b + c;
		if(news == "ABC") ans += 1;
	}
	cout << ans;
	return 0;
}

Measured memory_bytes: 256
import numpy as np

N,D = input().split()
N = int(N)
D = int(D)
count = 0

for i in range(N): 
    x,y = input().split()
    x = int(x)
    y = int(y)
    d = np.sqrt(x**2+y**2)

    if d <= D:
        count += 1 

print(count)  


Measured memory_bytes: 26512
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
using namespace std;
int main(){
	int A,B;
	cin>>A>>B;
	if(A>B)cout<<2*A-1<<endl;
	else if(A==B)cout<<2*A<<endl;
	else if(B>A)cout<<2*B-1<<endl;
	return 0;
}


Measured memory_bytes: 256
use std::io;
use std::collections::*;

fn solve(){
    let mut buf = String::new();
    io::stdin().read_line(&mut buf).unwrap();
    buf.clear();
    io::stdin().read_line(&mut buf).unwrap();
    let a = buf
                .trim()
                .split_whitespace()
                .map(|x| x.parse::<i32>().unwrap())
                .collect::<Vec<i32>>();
    let n = a.len();
    let mut map = HashMap::new();
    for &item in &a{
        *(map.entry(item).or_insert(0))+=1;
    }
    let mut res = 0i64;
    for (_,&val) in &map{
        let val = val as i64;
        res+=(val-1)*val/2;
    }
    for i in 0..n{
        let item = a[i];
        println!("{}",res-map[&item]+1);
    }
}


fn main(){
    let mut t_cases = 1;
    // let mut buf = String::new();
    // io::stdin().read_line(&mut buf);
    // t_cases = buf.trim().parse::<i32>();
    for _ in 0..t_cases{
        solve();
    }
}

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

ll gcd(ll a, ll b){
  if(b == 0){
    return a;
  }
  else{
    return gcd(b,(a%b));
  }
}
ll lcm(ll a,ll b){
  return a/gcd(a,b)*b;
}

int main(){
  int n,k;
  cin>>n>>k;
  vector<double> vec(n);
  for(int i=0;i<n;i++){
    cin>>vec.at(i);
    vec.at(i)=(vec.at(i)+1)/2;
  }
  double p=0,q=0;
  for(int i=0;i<k;i++){
    q+=vec.at(i);
  }
  p=q;
  for(int i=0;i<n-k;i++){
    q-=vec.at(i);
    q+=vec.at(i+k);
    p=max(p,q);
  }
  cout<<fixed<<setprecision(10);
  cout<<p<<endl;  
}

Measured memory_bytes: 1792
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i=0; i<(n); i++)
int main()
{
    int n[5], k;
    rep(i, 5)	
  		cin >> n[i];
	cin >> k;
  
  	sort(n, n+5);
  	if(n[4] - n[0] <= k)
      cout << "Yay!" << endl;
  	else
	  cout << ":(" << endl;
    return 0;
}


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

using namespace std;

//FILE *fi=freopen("1.txt","r",stdin);

int n,ma=0;
vector<string> vt;
map<string,int> m;

void nhap()
{
    scanf("%d",&n);
    for (int i=1;i<=n;++i)
    {
        string s;
        cin>>s;
        m[s]++;
        if (m[s]>ma)
        {
            ma=m[s];
            vt.clear();
        }
        if (ma==m[s])
            vt.push_back(s);
    }
    sort(vt.begin(),vt.end());;
    for (auto i:vt)
        cout<<i<<"\n";
}

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


Measured memory_bytes: 26736
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time,queue,copy

sys.setrecursionlimit(10**7)
inf=10**20
mod=10**9+7
dd=[(-1,0),(0,1),(1,0),(0,-1)]
ddn=[(-1,0),(-1,1),(0,1),(1,1),(1,0),(1,-1),(0,-1),(-1,-1)]

def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def I(): return int(sys.stdin.readline())
def LS(): return sys.stdin.readline().split()
def S(): return input()

def main():
  n=I()

  if n==0:
    return 0

  ans=''
  while n!=0:
    if n%2==0:
      ans='0'+ans
    else:
      ans='1'+ans
    n//=2
    n=-n

  return ans

# main()
print(main())


Measured memory_bytes: 5840
package main

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

// const abcd = "abcdefghijklnmopqrstuvwxyz"
// const ABCD = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"

// var dy = [...]int{1, 1, 0, -1, -1, -1, 0, 1}
// var dx = [...]int{0, 1, 1, 1, 0, -1, -1, -1}

// var dx = [...]int{0, 1, 0, -1}
// var dy = [...]int{1, 0, -1, 0}

var inf int = 1e13
var mod = 1000000007

// ---------------------------------------------------------
func main() {
	log.SetFlags(log.Lshortfile)
	next := newScanner()
	n := next.Int()
	a := make([]int, n)
	for i := 0; i < n; i++ {
		a[i] = next.Int()
	}
	maxa := max(a...)
	mina := min(a...)
	ans := "Yes"
	if maxa-mina >= 2 {
		ans = "No"
	} else {
		if maxa-mina == 0 {
			if a[0] == n-1 || 2*a[0] <= n {
				ans = "Yes"
			} else {
				ans = "No"
			}
		} else {
			var x, y int
			for i := 0; i < n; i++ {
				if a[i] == maxa-1 {
					x++
				} else {
					y++
				}
			}
			if x < maxa && 2*(maxa-x) <= y {
				ans = "Yes"
			} else {
				ans = "No"
			}
		}
	}

	fmt.Println(ans)
}

// ---------------------------------------------------------

// Pair is liked C++ pair
type Pair struct {
	a, b int
}

// Pairs is sorted by []Pair struct
type Pairs []Pair

func (p Pairs) Len() int {
	return len(p)
}
func (p Pairs) Swap(i, j int) {
	p[i], p[j] = p[j], p[i]
}

func (p Pairs) Less(i, j int) bool {
	if p[i].a < p[j].a {
		return true
	} else if p[i].a == p[j].a {
		return p[i].b < p[j].b
	}
	return false
}

// -------------------------------
func in(c, a, z int) bool {
	return c >= a && c < z
}

func btoi(b bool) int {
	if b {
		return 1
	}
	return 0
}

func itob(a int) bool {
	if a == 0 {
		return false
	}
	return true
}

func max(a ...int) int {
	r := a[0]
	for i := 0; i < len(a); i++ {
		if r < a[i] {
			r = a[i]
		}
	}
	return r
}

func sum(a ...int) int {
	r := a[0]
	if len(a) > 1 {
		for i := 1; i < len(a); i++ {
			r += a[i]
		}
	}
	return r
}

func min(a ...int) int {
	r := a[0]
	for i := 0; i < len(a); i++ {
		if r > a[i] {
			r = a[i]
		}
	}
	return r
}

func minmax(a, b int) (int, int) {
	if a > b {
		return b, a
	}
	return a, b
}

func abs(a int) int {
	if a < 0 {
		return -a
	}
	return a
}

// ---------- buffered scanner -----------------------------------------
type scanner struct {
	r   *bufio.Reader
	buf []byte
	p   int
}

func newScanner() *scanner {
	rdr := bufio.NewReaderSize(os.Stdin, 10000)
	return &scanner{r: rdr}
}
func (s *scanner) next() string {
	s.pre()
	start := s.p
	for ; s.p < len(s.buf); s.p++ {
		if s.buf[s.p] == ' ' {
			break
		}
	}
	result := string(s.buf[start:s.p])
	s.p++
	return result
}
func (s *scanner) Line() string {
	s.pre()
	start := s.p
	s.p = len(s.buf)
	return string(s.buf[start:])
}
func (s *scanner) Int() int {
	v, _ := strconv.Atoi(s.next())
	return v
}
func (s *scanner) Int64() int64 {
	v, _ := strconv.ParseInt(s.next(), 10, 64)
	return v
}
func (s *scanner) pre() {
	if s.p >= len(s.buf) {
		s.readLine()
		s.p = 0
	}
}
func (s *scanner) readLine() {
	s.buf = make([]byte, 0)
	for {
		l, p, e := s.r.ReadLine()
		if e != nil {
			panic(e)
		}
		s.buf = append(s.buf, l...)
		if !p {
			break
		}
	}
}


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

const int INF = 1e9;

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

    map<string, vector<pair<int, int> > > m;
    vector<string> vs;

    for (int i=0; i<n; i++) {
        string s;
        int p;
        cin>>s>>p;
        m[s].push_back(make_pair(p, i));
        if (find(vs.begin(), vs.end(), s) == vs.end()) {
            vs.push_back(s);
        }
    }
    sort(vs.begin(), vs.end());

    for (string s: vs) {
        vector<pair<int, int> > v = m[s];
        sort(v.begin(), v.end());
        reverse(v.begin(), v.end());
        for (auto p: v) {
            cout<<p.second+1<<endl;
        }
    }
}

Measured memory_bytes: 384
from  collections import Counter
H, W = map(int, input().split())
A = []
C = Counter()
for i in range(H):
    A.append(input())
    C += Counter(A[i])

if(H%2 == 0 and W%2 == 0):
    for l in C:
        if(C[l]%4):
            print("No")
            exit()
    print("Yes")
elif(H%2 and W%2):
    t = 0
    for l in C:
        if(C[l]%2):
            t += 1
            C[l] -= 1
    if(t != 1):
        print("No")
        exit()

    t = 0
    for l in C:
        if(C[l]%4):
            t += 1

    if((H+W-2)//2-t >= 0 and ((H+W-2)//2-t)%2 == 0):
        print("Yes")
    else:
        print("No")
else:
    t = 0
    r = H*(W%2) + W*(H%2)
    for l in C:
        if(C[l]%2):
            print("No")
            exit()
        elif(C[l]%4):
            t += 1
    if(r//2-t >= 0 and (r//2-t)%2 == 0):
        print("Yes")
    else:
        print("No")            


Measured memory_bytes: 3444
#include<iostream>
#include<queue>
using namespace std;
struct Work{
	string s;
	int time;
};

int main(){
	int n,q;
	cin>>n>>q;
	queue<Work> Q;
	for(int i=0;i<n;i++){
		Work w;
		cin>>w.s>>w.time;
		Q.push(w);
	}
	
	int cur=0;
	while(!Q.empty()){
		Work tmp=Q.front();
		Q.pop();
		if(tmp.time<=q){
			cur+=tmp.time;
			cout<<tmp.s<<" "<<cur<<endl;
		}
		else{
			cur+=q;
			tmp.time-=q;
			Q.push(tmp);
		}
	}
	return 0;
}


Measured memory_bytes: 6336
#include<iostream>
#include<string>
using namespace std;
int main()
{
  // 入力
  int n, k;
  string s;
  cin >> n >> k >> s;
  k--;
  s[k] = s[k] + ('a'-'A');
    
  // 出力
  cout << s << endl;

  return 0;
}

Measured memory_bytes: 256
#include <iostream>

#include<math.h>

#include<stdio.h>

#include<string.h>

#include<vector>

#include<algorithm>



typedef long long ll;

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

#define rep1(i, n) for(int i=1; i < (int)(n); i++)

#define all(x) (x).begin(),(x).end()

#define fill(x,y) memset(x,y,sizeof(x))

#define debug1(i) cout << i << '\n'

#define debug2(i,j) cout << i << j << '\n'

#define MAX 1<<20



using namespace std;


long long N=0, M=0, L, r, s;
long long p[MAX], q[MAX];
double d, e, f, g, h;
vector<long long > vec1, vec2;
char word[MAX];


int main() {
	cin >> word;
	for (int i = 0; word[i] != '\0'; i++) {
		if (word[i] == '0')N++;
		else M++;
	}
	cout << 2 * min(N, M);
}

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

int main() {
  int n, k;
  cin>>n>>k;
  int ans = 1;
  for (int i=0; i<n; i++) {
    if (ans * 2 < ans + k) {
      ans *= 2;
    } else {
      ans += k;
    }
  }
  cout<<ans<<endl;
}

Measured memory_bytes: 256
N,K=map(int,input().split())
p=[int(i)-1 for i in input().split()]
q=[int(i)-1 for i in input().split()]
def inv(seq):
    res=[0 for i in range(N)]
    for i in range(N):
        res[seq[i]]=i
    return res
def times(seq1,seq2):
    res=[0 for i in range(N)]
    for i in range(N):
        res[i]=seq1[seq2[i]]
    return res
md=[[0 for i in range(N)] for i in range(6)]
for i in range(N):
    md[0][i]=p[i]
    md[1][i]=q[i]
for i in range(2,6):
    md[i]=times(md[i-1],inv(md[i-2]))
A=times(times(times(q,inv(p)),inv(q)),p)
T=(K-1)//6
def expseq(seq,k):
    if k==0:
        return [i for i in range(N)]
    elif k==1:
        return seq
    elif k%2==0:
        return expseq(times(seq,seq),k//2)
    else:
        return times(expseq(times(seq,seq),k//2),seq)
tmp=expseq(A,T)
ans=times(times(tmp,md[(K-1)%6]),inv(tmp))
print(" ".join([str(i+1) for i in ans]))


Measured memory_bytes: 38732
import java.io.BufferedReader;
import java.io.InputStreamReader;

public class Main{
	public static void main(String[] args)throws Exception{
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		
		while(true){
			String line = br.readLine();
			String[] str = line.split(" ");
			int a = Integer.parseInt(str[0]);
			int b = Integer.parseInt(str[2]);
			if(str[1].equals("?")){
		 		break;
			}
			
			if(str[1].equals("+")){
				System.out.println(a + b);
			} else if(str[1].equals("-")){
				System.out.println(a - b);
			} else if(str[1].equals("*")){
				System.out.println(a * b);
			} else if(str[1].equals("/")){
				System.out.println(a / b);
			}
		}
	}
}

Measured memory_bytes: 24344
#include <stdio.h>
#include <stdio.h>
int main()
{
    int n,sum,a,b;
    sum=0;
    while(~scanf("%d",&n))
    {

        if(n==1)
            printf("Hello World\n");
        else
        {


            scanf("%d\n%d",&a,&b);


            sum=a+b;
            printf("%d\n",sum);
        }
    }
}




Measured memory_bytes: 128
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
#pragma GCC target("sse2")

#include<bits/stdc++.h>
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>
using namespace std;

#define int         long long
#define ll          long long
#define pb          push_back
#define pii         pair<int,int>
#define vi          vector<int>
#define vii         vector<pii>
#define mi          map<int,int>
#define mii         map<pii,int>
#define mp          make_pair
#define all(a)      (a).begin(),(a).end()
#define FF           first
#define SS           second
#define sz(x)       (int)x.size()
#define endl        '\n'
//#define hell          1000000007
#define rep(i,a,b)  for(int i=a;i<b;i++)
// mp::cpp_int
#define pp pair<pii,pii>
const int hell =1000000007;




int solve( ){

int n;
cin>>n;
int a[n][3];
rep(i,0,n)
{
  rep(j,0,3)cin>>a[i][j];
}

int dp[n][3];

rep(i,0,3)dp[0][i]=a[0][i];

rep(i,1,n)
{
  dp[i][0]=a[i][0]+max(dp[i-1][1],dp[i-1][2]);
  dp[i][1]=a[i][1]+max(dp[i-1][0],dp[i-1][2]);
  dp[i][2]=a[i][2]+max(dp[i-1][0],dp[i-1][1]);

}

int mn=0;
rep(i,0,3)mn=max(mn,dp[n-1][i]);
cout<<mn;


return 0;
}

signed main()
{  int t=1;
 ios::sync_with_stdio(false);
   cin.tie(0);
   cout.tie(0);
   cin.exceptions(cin.failbit);


  clock_t time_req;

    // Without using pow function
    time_req = clock();
    
//cin>>t;

    int k=1;
   while(t--)
     {
       //cout<<"case #"<<k<<":"<<" ";k++;
      solve();
     }

         time_req = clock() - time_req;
 //cout << "Processor time taken is "
   // << (double)time_req/CLOCKS_PER_SEC << " seconds" << endl;


    return 0;
}

Measured memory_bytes: 4992
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;

int n;
bool flg;

void rec(vector<int> c,int sum,vector<int> &vv){
  if(sum == 0){
    flg = true;
    return;
  }

  for(int i = 1 ; i <= 13 ; i++){     

    if(c[i] && sum % i == 0){
      int m = i;
      vv.push_back(i);
      c[i]--;
      rec(c,sum-m,vv);
      if(flg) return;
      vv.pop_back();
      c[i]++;
    }

  }
}

int main(){
  while(cin >> n ,n){
    int sum = 0,a;
    vector<int> c(14,0);

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

    flg = false;    
    vector<int> v;
    rec(c,sum,v);
    

    if(v.size()){
      int s = (int)v.size();
      for(int i = 0 ; i < s ; i++){
	if(!i) cout << v[s-1-i];
	else cout << " " << v[s-1-i];
      }
      cout << endl;
    }
    else{
      cout << "No" << endl;
    }
  }

  return 0;
}

Measured memory_bytes: 1228
#include <iostream>
#include <algorithm>
using namespace std;
const int maxn = 200007;
int n,a[maxn],b[maxn];
int main(int argc, char const *argv[])
{
    cin>>n;
    int maxn = 1000000009;
    int ok = 0;
    long long sum = 0;
    for(int i=1;i<=n;i++)
    {
        cin>>a[i]>>b[i];
        sum+=a[i];
        if(a[i]>b[i])
        {
            if(maxn>b[i])maxn=b[i];
        }
    }
    if(maxn==1000000009)cout<<0<<endl;
    else cout<<sum-maxn<<endl;
    return 0;
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
#define FIN ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);

int main() {FIN
	
	int k, a, b;
	cin >> k;
	cin >> a >> b;
	if ((b / k) - ((a - 1) / k) > 0)
		cout << "OK\n";
	else
		cout << "NG\n";
	return 0;
}


Measured memory_bytes: 3648
#include <bits/stdc++.h>
using namespace std;
int main(void){
    int N,K,l,i=0;
    cin >> N >> K;
    vector<int>H(N);
    while(cin >> l){
        H[i]=l;
        i++;
    }
    if(K>=N){
        cout << 0 << endl;
    }else{
        sort(H.begin(),H.end());
        long long ans=0;
        for(int j=0;j<N-K;j++){
            ans += H[j];
        }cout << ans << endl;
    }
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
 
#define ios ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define ll long long
#define endl '\n'
#define pii pair<ll int, ll int>
#define all(a) (a).begin(), (a).end()
#define F first
#define S second
#define pb push_back
#define mp make_pair
#define repi(i, n) for(ll i=0; i<n; i++)
#define rep(i, a, b) for(ll i=a; i<=b; i++)
#define M 1000000007
#define INF 1e10

using namespace std;

int main() {
    ios
    ll n;
    cin>>n;
    if(n>=30) cout<<"Yes";
    else cout<<"No";
    return 0;
}

Measured memory_bytes: 3640
from itertools import accumulate, count

n = int(input())

cumsum_ = accumulate(count(1))
cumsum = []
for x in cumsum_:
    if x >= n:
        cumsum.append(x)
        break
    else:
        cumsum.append(x)

x = cumsum[-1] - n
for i in range(1, len(cumsum)+1):
    if i != x:
        print(i)

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


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

ll lcm(ll x,ll y){
    return x/gcd(x,y)*y;
}
int main(){
    ll a,b,c,d;
    cin>>a>>b>>c>>d;
    --a;
    ll r1 = b-b/c-b/d+b/lcm(c,d);
    ll r2 = a-a/c-a/d+a/lcm(c,d);
    cout<<r1-r2<<endl;
    return 0;
}

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

int chain[200200];

int main() {
	int n, c = 0;
	std::cin >> n;
	int ans = 0;
	for(int i = 0; i < n; i++) {
		int t;
		std::cin >> t;
		chain[t] = 1 + chain[t - 1];
		ans = std::max(ans, chain[t]);
	}
	std::cout << n - ans << std::endl;
}

Measured memory_bytes: 1024
def main():
    n, m = map(int, input().split())
    e = [set() for _ in range(n)]
    for _ in range(m):
        u, v = map(lambda x: int(x) - 1, input().split())
        e[u].add(v)
        e[v].add(u)

    ans = 0
    for _ in range(m):
        count = 0
        for i, x in enumerate(e):
            if len(x) == 1:
                j = x.pop()
                e[j] -= {i}
                count += 1
        if count:
            ans += count
        else:
            print(ans)
            exit()


if __name__ == "__main__":
    main()


Measured memory_bytes: 3064
#include <bits/stdc++.h>
#include <iostream>
#include <algorithm>
#include <cmath>
#include <vector>
#include <map>
#include <set>
#include <string>

#define ui uint_fast64_t

using namespace std;

int main()
{
    ui n, c;
    cin >> n;
    vector <ui> ao;
    multiset<ui> aset;
    auto itr_v = ao.begin();
    ui tmp;
    for (auto i = 0; i < n; i++){
        cin >> tmp;
        ao.push_back(tmp);
        aset.insert(tmp);
    }
    
    map <ui, ui> acount;
    ui ac = 0;
    for(auto i = 0; i < n; i++){
        c = aset.count(i+1);
        ac += (pow(c, 2) - c)/2;
        acount[i+1] = c;
    }
    string text = "";
    for (auto i = 0; i < n; i++){
        text += to_string(ac - acount[ao[i]]+1) + "\n";
    }
    cout << text;
    return 0;
}


Measured memory_bytes: 30192
#include <bits/stdc++.h>
using namespace std;
int main() {
  char a;
  cin>>a;
  if(a=='a'||a=='i'||a=='u'||a=='e'||a=='o'){
    cout<<"vowel"<<endl;
  }else{
    cout<<"consonant"<<endl;
  }
  return 0;
}

Measured memory_bytes: 256
s=input()
count=0 
if(s[0]==s[1]==s[2]=='R'):
    print('3')
elif(s[0]==s[1]==s[2]=='S'):
    print('0')
elif(s[0]==s[1]=='R' and s[2]=='S'):
    print('2')
elif(s[1]==s[2]=='R' and s[0]=='S'):
    print('2')
else:
    print('1')
    

Measured memory_bytes: 9004
list = []
while True:
    H, W = map(int, input().split())
    if H == 0 and W == 0:
        break
    list.append([H, W])


for i in range(len(list)):
    for j in range(list[i][0]):
        if j == 0:#最初の行
            print(list[i][1]*'#')
        
        elif j == list[i][0]-1:#最後の行
            print(list[i][1]*'#')
        
        else:
            print('#', (list[i][1]-2)*'.', '#', sep = '')
    
    print('')


Measured memory_bytes: 5636
let n = read_int ()
let s = read_line ()

let rec f i ans =
  if i = 4 then print_endline "-1"
  else
    let rec g j t =
      if j = n then t = i
      else
        let f0 = t lsr 1
        and f1 = t land 1 in
        let f2 = f0 lxor if s.[j] = 'o' then 0 else 1 in
        (
          ans.(j) <- if f2 = 0 then 'S' else 'W';
          g (j + 1) (((f1 lxor f2) lsl 1) lor f2)
        )
    in
    if g 0 i then
      let rec h j =
        if j < n - 1 then (
          print_char ans.(j);
          h (j + 1)
        )
      in (print_char ans.(n-1); h 0)
    else f (i + 1) ans

let () = f 0 (Array.make n ' ')


Measured memory_bytes: 3584
import std.algorithm;
import std.array;
import std.conv;
import std.math;
import std.range;
import std.stdio;
import std.string;
import std.typecons;

int readint() {
    return readln.chomp.to!int;
}

int[] readints() {
    return readln.split.map!(to!int).array;
}

long calc(int k, int[][] ps) {
    ps.sort!((a, b) => a[0] < b[0]); // x 座標でソート

    long ans = long.max;
    auto n = ps.length;
    for (int i = 0; i < n; i++) {
        for (int j = i + 1; j < n; j++) {
            if (j - i + 1 < k)
                continue;

            // 範囲内(i .. j)の点を y 座標でソート
            int[] ys;
            for (int m = i; m <= j; m++)
                ys ~= ps[m][1];
            ys.sort();

            int[] us;
            for (int m = 0; m < ys.length; m++) {
                if (us.length >= k)
                    us = us[1 .. $];
                us ~= ys[m];

                if (us.length >= k) { // k 個の点を含むので長方形の面積を計算
                    long x = ps[j][0] - ps[i][0];
                    long y = us[$ - 1] - us[0];
                    ans = min(ans, x * y);
                }
            }
        }
    }
    return ans;
}

void main() {
    auto nk = readints;
    int n = nk[0], k = nk[1];

    int[][] ps;
    for (int i = 0; i < n; i++) {
        auto p = readints;
        ps ~= p;
    }
    writeln(calc(k, ps));
}


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

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

int main(){
  int n,k;
  const int max_n = 1000;
  cin >> n >> k;
  int p[max_n + 1];
  for(int i = 0; i < n; i++) cin >> p[i];

  sort(p, p+n);
  int ans = 0;
  for(int i = 0; i < k; i++){
    ans += p[i];
  }

  cout << ans << endl;

  return 0;
}

Measured memory_bytes: 3640
# include <bits/stdc++.h>
# define rep(i, n) for(int i=0, i##_len=(n); i<i##_len; ++i)
using namespace std;
static const bool TAKAHASHI_TURN = false;
static const bool AOKI_TURN = true;

class Monster {
public:
    Monster() = default;

    void attack(Monster& enemy) {
        enemy.m_hitPoint -= min(enemy.m_hitPoint, m_attackPoint);
    }

    bool isDead() {
        return m_hitPoint == 0;
    }

    void read() {
        cin >> m_hitPoint >> m_attackPoint;
    }

    void print() {
        cout << m_hitPoint << " " << m_attackPoint << endl;
    }

private:
    int m_hitPoint;
    int m_attackPoint;
};

int main() {
    Monster takahashi, aoki;
    takahashi.read();
    aoki.read();

    bool turn = TAKAHASHI_TURN;
    for (; !takahashi.isDead() and !aoki.isDead(); turn = !turn)
    {
        switch (turn)
        {
            case TAKAHASHI_TURN:
                takahashi.attack(aoki);
                break;
            case AOKI_TURN:
                aoki.attack(takahashi);
                break;
        }
    }

    cout << (aoki.isDead() ? "Yes" : "No") << endl;

    return 0;
}



Measured memory_bytes: 3536
#include <bits/stdc++.h>
#define FOR(i, k, n) for(int i = (k); i < (n); i++)
#define FORr(i, k, n) for(int i = (k); i >= (n); i--)
#define REP(i, n) FOR(i, 0, n)
#define REPr(i, n) FORr(i, n, 0)
#define ALL(x) (x).begin(), (x).end()
#define chmin(x, y) x = min(x, y)
#define chmax(x, y) x = max(x, y)
using namespace std;
using ll = long long;

int main(void){
  int a, b;
  cin >> a >> b;
  int ans = a+b;
  chmax(ans, a-b);
  chmax(ans, a*b);
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
using System;

namespace abc091A
{
    class MainClass
    {
        public static void Main(string[] args)
        {
            string[] str = Console.ReadLine().Split();
            int A = int.Parse(str[0]);
            int B = int.Parse(str[1]);
            int C = int.Parse(str[2]);
            if (A + B >= C)
                Console.WriteLine("Yes");
            else
                Console.WriteLine("No");
        }
    }
}


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

main() {
  char c;
  cin >> c;
  if (c == 'a' || c == 'i' || c == 'u' || c == 'e' || c == 'o') {
    cout << "vowel" << endl;
  } else {
    cout << "consonant" << endl;
  }
}


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


int main()
{
   int a,b,c,d;cin>>a>>b>>c>>d;

  int flag= 0;
   while(a>0){
    c-=b;
    a-=d;

    if(c<=0){flag=1;
    break;
    }
   }
   if(flag==1)cout<<"Yes";
   else cout<<"No";

    return 0;
}


Measured memory_bytes: 3644
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int count =0;
		for (int i=0;i<N;i++) {
			int temp = sc.nextInt();
			if (temp%2==1) {
				count ++;
			}
		}
		if (count%2==0) {
			System.out.println("YES");
		} else {
			System.out.println("NO");
		}
	}
}


Measured memory_bytes: 57328
open System
let p = stdin.ReadLine().Split()|>Array.map int
let a=p.[0]
let b=p.[1]
[<EntryPoint>]
let main argv =
    match (a+b)%2=0 with
    |true -> printfn "%d" ((a+b)/2)
    |false -> printfn "%s" "IMPOSSIBLE"
    0


Measured memory_bytes: 14044
#include"bits/stdc++.h"
using namespace std;
using ll=long long;
template<class T=ll>inline T in(istream&is=cin){T ret;is>>ret;return ret;}
template<class T>inline auto vec2(typename vector<T>::size_type h,typename vector<T>::size_type w,T v=T()){return vector<vector<T>>(h,vector<T>(w,v));}
template<class RandomAccessIterator>inline void psortb(RandomAccessIterator first,RandomAccessIterator last){using P=pair<decltype(first->first),decltype(first->second)>;sort(first,last,[](const P&p1,const P&p2){return p1.second<p2.second||(p1.second==p2.second&&p1.first<p2.first);});}

int main()
{
    ll n=in();
    map<string,ll>m;
    for(ll i=0;i<n;++i){
        ++m[in<string>()];
    }
    cout<<"AC x "<<m["AC"]<<endl;
    cout<<"WA x "<<m["WA"]<<endl;
    cout<<"TLE x "<<m["TLE"]<<endl;
    cout<<"RE x "<<m["RE"]<<endl;
}


Measured memory_bytes: 3632
N = int(input())
T, A = map(int, input().split())
H = list(map(int, input().split()))
L = []
for i in range(N):
  score = abs(A - (T - H[i] * 0.006))
  L.append(score)
m = min(L)
print(L.index(m)+1)

Measured memory_bytes: 3060
#include<iostream>

using namespace std;
int main(){
    int n, x, l;
    cin >> n>> x;
    int count = 0;
    int d = 0;
    while (d <= x && count < n + 1){
        count++;
        cin >> l;
        d += l;
    }
    cout << count << endl;
    return 0;
}

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

#define watch(x) cout << (#x) << " is " << (x) << endl
#define fr(i,n) for(int i=0; i<n; i++)
#define rep(i, st, en) for(int i=st; i<=en; i++)
#define repn(i, st, en) for(int i=st; i>=en; i--)
#define sq(a) (a*a)
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
ll mod = 1e9+7;

const int nax = 3005;
ll a[nax];
vector<vector<ll>> dp;

ll recurse(int st, int en, bool turn){
    if(st > en) return 0ll;
    if(~dp[st][en]) return dp[st][en];

    ll &z = dp[st][en];
    ll lt = recurse(st + 1, en, !turn);
    ll rt = recurse(st, en - 1, !turn);
    if(turn) {
        lt += a[st];
        rt += a[en];
        return z = max(lt, rt);
    } else {
        lt -= a[st];
        rt -= a[en];
        return z = min(lt, rt);
    }
}

void solve(){
    int n;
    cin>>n;
    dp.resize(n, vector<ll>(n, -1));
    fr(i, n) cin>>a[i];
    cout<<recurse(0, n-1, 1);   /// bool turn = 1, 0 for second player
}

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

    ll t = 1;
    //  cin>>t;
    while(t--){
        solve();
    }

    return 0;
}



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

using namespace std;
#define rep(i,n) for(int i=1;i<n;i++)
#define ll long long int

int main(){
  int n;
  cin>>n;
  ll X;
  cin>>X;
  ll x[n];
  cin>>x[0];
  ll ans=abs(x[0]-X);
    
  rep(i,n){
    cin>>x[i];
    ans=__gcd(ans,abs(x[i]-X));
  }
  cout<<ans<<endl;


  return 0;
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
#define puts(i) cout<<i<<endl
#define pi 3.14159265358979323846264338
using ll = long long;
using P = pair<int,int>;

ll divisor=998244353;
int main(){
	double a,b,h,m;
	cin>>a>>b>>h>>m;
	double ans=sqrt(a*a+b*b-2*a*b*cos(pi*(h/6+m/360-m/30)));
	cout<<setprecision(20)<<ans<<endl;
}


Measured memory_bytes: 4192
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> ii;
typedef vector<ll> vi;
typedef long double ld;

#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define INF ll(1e18)
#define MOD (ll)1e9+7
#define print(a); for(auto x:a)cout<<x<<" "; cout<<"\n";
#define mset(a); memset(a,0,sizeof(a));

int main(){
	ios_base::sync_with_stdio(0);cin.tie(0);
    string s;cin>>s;
    if(s[1]=='B')cout<<"ARC\n";
    else cout<<"ABC\n";
}


Measured memory_bytes: 3672
#include <stdio.h>
#define INF 10000000

  int mat[100][100];
  int a[100];
  int num;

void matrix();

  int main(){

    int b,i;
    scanf("%d",&num);
    for(i=0;i<num;i++){
      scanf("%d%d",&a[i],&b);
    }
    a[i]=b;
    matrix();
    printf("%d\n",mat[1][num]);
    return 0;
  }

  void matrix(){
    int i,j,k,q,l;

    for(i=1;i<=num;i++){
      mat[i][i] = 0;
    }
    for(l=2;l<=num;l++){
      for(i=1;i<=num-l+1;i++){
        j= i+l-1;
        mat[i][j]= INF;
        for(k=i;k<j;k++){
          q= mat[i][k] + mat[k+1][j] + a[i-1] * a[k] * a[j];
          if(mat[i][j] > q) mat[i][j] = q;
        }
      }
    }
  }

Measured memory_bytes: 636
/* Granding */
#include <stdio.h>

int main()
{
    int m, f, r, i;
    for(i=0;; i++){
        scanf("%d %d %d", &m, &f, &r);
        if(m==-1 && f==-1 && r==-1){
         break;
        }
        if(m==-1 || f==-1){
             printf("F\n");
        }
        else if(m+f >= 80){
             printf("A\n");
        }
        else if(m+f >= 65 && m+f < 80){
             printf("B\n");
        }
        else if(m+f >= 50 && m+f < 65){
             printf("C\n");
        }
        else if(m+f >= 30 && m+f < 50 && r >= 50){
             printf("C\n");
        }
        else if(m+f >= 30 && m+f < 50){
             printf("D\n");
        }
        else{
            printf("F\n");
        }
    }
}


Measured memory_bytes: 2100
def digit_sum(n:int) -> int:
    res = n
    ans = 0
    while res>0:
        ans = ans + res%10
        res = res//10
        
    return ans

N,A,B = map(int, input().split())
ans = 0

for i in range(1,N+1):
    if digit_sum(i) >= A and digit_sum(i) <= B:
        ans += i
    
print(ans)

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

int main()
{
    int n;
    cin >> n;
    map<long long, int> l;
    for (auto i = 0; i < n; i++)
    {
        long long a_i;
        cin >> a_i;
        auto itr = l.find(a_i);
        if(itr != l.end()){
            l[a_i] += 1;
        }else{
            l[a_i] = 1;
        }
    }

    int ans = 0;

    auto begin = l.begin(), end = l.end();
    for (auto iter = begin; iter != end; iter++) {
        // first: key, second: value
        if(iter->second % 2 == 1){
            ans += 1;
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 6528
#include <iostream>
#include <string>
#include <vector>
#include <stdio.h>
#include <algorithm>
#define _USE_MATH_DEFINES
#include <cmath>
#include <numeric>
#include <iomanip>
#include <deque>
#include <tuple>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <unordered_map>
#include <sstream>
#include <stdexcept>
#include <boost/multiprecision/cpp_int.hpp>
#include <boost/multiprecision/cpp_dec_float.hpp>

#define rep(i, x) for (int i = 0; i < (int)(x); i++)
#define FOR(i, a, done) for (int i = (a); i < (done); ++i)
#define all(a) (a).begin(), (a).end()
#define F first
#define S second
#define x first
#define y second
#define pb push_back
#define pf push_front
#define debug(a) cout << (a) << endl
namespace mp = boost::multiprecision;
using cpp_int = mp::cpp_int;
using ll = long long;
using namespace std;

ll M = 1000000007;
void solve()
{
	ll h,w;
	cin>>h>>w;
	ll ans=0;
	if(h==1 or w==1){
		ans=1;
		cout<<ans<<endl;
		return ;
	}
	if(w%2==0){
		ans=h*(w/2);
	}else{
		if(h%2==0){
			ans=h*w/2;
		}else{
			ans=h*w/2+1;
		}
	}
	cout<<ans<<endl;
	
}

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


Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <cmath>
#include <vector>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <queue>
#include <ctime>
#include <cassert>
#include <complex>
#include <string>
#include <cstring>
#include <chrono>
#include <random>
#include <queue>
#include <bitset>
#include <stack>
#include <functional>

#ifdef LOCAL
    #define eprintf(...) fprintf(stderr, __VA_ARGS__)
#else
    #define eprintf(...) 42
#endif

#define rep(i, n) for(int i = 0, i##_len = (n); i < i##_len; ++i)
#define repp(i, m, n) for(int i = m, i##_len = (n); i < i##_len; ++i)
#define reprev(i, n) for(int i = (n-1LL); i >= 0; --i)
#define all(x) (x).begin(), (x).end()
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; }
template <class T> T gcd(T a, T b) { return b ? gcd(b, a % b) : a; }
using namespace std;

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

int main(void)
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n;
    cin >> n;
    vector<int> p(n), invp(n);
    rep (i, n) {
        cin >> p[i];
        p[i]--;
        invp[p[i]] = i;
    }
    vector<int> inv_left(n - 1), inv_right(n - 1);
    rep (i, n - 1) {
        if (i == 0) inv_left[0] = (invp[0] > invp[1] ? 0 : -1);
        else inv_left[i] = (invp[i] > invp[i + 1] ? i : inv_left[i - 1]);
    }
    reprev (i, n - 1) {
        if (i == n - 2) inv_right[n - 2] = (invp[n - 2] > invp[n - 1] ? n - 2 : n - 1);
        else inv_right[i] = (invp[i] > invp[i + 1] ? i : inv_right[i + 1]);
    }
    int ans = n - 1;
    rep (i, n) eprintf("%d ", invp[i]); eprintf("\n");
    rep (i, n - 1) { // 0-i,i+1-n-1
        if (invp[i] > invp[i + 1]) continue;
        eprintf("%d/%d: ", i, i + 1);
        int tmp = 0;
        tmp += inv_left[i] + 1;
        tmp += n - (inv_right[i] + 1);
        eprintf(" -> %d\n", tmp);
        chmin(ans, tmp);
    }
    cout << ans << "\n";
    return 0;
}

Measured memory_bytes: 3456
#include <bits/stdc++.h>
using namespace std;
const int N = 100 + 5;
int a[N];
int main()
{
	int n;
	cin >> n;
	double sum = 0.00;
	for(int i = 0; i < n; i++){
		cin >> a[i];
		sum += (1.00/a[i]);
	}
	sum = 1.00 / sum;
	cout << sum << endl;
	return 0;
 } 

Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstdlib>
#include<cmath>
#include<cstring>
#include<string>
using namespace std;
int L,R,t[2030];
int main()
{
  cin>>L>>R;
  if(R-L>=5000){cout<<0<<endl; return 0;}
  for(int i=L;i<=R;i++)
    for(int j=i+1;j<=R;j++) t[1ll*i*j%2019]=1;
  for(int i=0;i<2019;i++) if(t[i]==1) {cout<<i; break;}
  return 0;
}

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

int main(){
  int a,b,c;
  cin >> a >> b >>c;
  if(a > c&& c> b){
    cout << "Yes" << endl;
  }else if(b > c && c > a){
    cout << "Yes" << endl;
  }else{
    cout << "No" << endl;
  }
}

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

dp = [0] * (W+1)

for i in range(N):
    w, v = map(int, input().split())
    for j in reversed(range(W+1)):
        if 0 <= j - w < W:
            dp[j] = max(dp[j-w] + v, dp[j])
print(max(dp))

Measured memory_bytes: 74480
#ifdef __APPLE__
#include <iostream>
#include <vector>
#include <utility>
#include <stack>
#include <queue>
#include <set>
#include <algorithm>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <random>
#else
#include <bits/stdc++.h>
#endif

using namespace std;
#define rep(i,a,n) for (int i=a;i<n;i++)
#define per(i,a,n) for (int i=n-1;i>=a;i--)
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define fi first
#define se second
#define SZ(x) ((int)(x).size())
#define tc(t) for (int tc=1; tc<=t; tc++)
typedef vector<int> VI;
typedef vector<long long int> VLLI;
typedef vector<pair<int, int> > VPI;
typedef long long ll;
typedef pair<int,int> PII;
typedef pair<ll, ll> PLL;
mt19937 mrand(random_device{}()); 
const ll mod=1000000007;
int rnd(int x) { return mrand() % x;}
ll powmod(ll a,ll b) {ll res=1;a%=mod; assert(b>=0); for(;b;b>>=1){if(b&1)res=res*a%mod;a=a*a%mod;}return res;}
ll gcd(ll a,ll b) { return b?gcd(b,a%b):a;}
ll modInverse (ll a) {ll p = mod - 2; return powmod(a, p);}
// head

int main() {
    int k, a, b;
    cin >> k >> a >> b;
    for (int i = a; i <= b; i++) {
        if ((i%k) == 0) {
            cout << "OK" << "\n";
            return 0;
        }
    }
    cout << "NG" << "\n";
}



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

int main() {
  int N, M, A = 0, P = 0, foo = -1;
  string grade;
  cin >> N >> M;
  vector<string> vec(N, "WJ");
  vector<int> v(N);
  
  for (int i = 0; i < M; i++) {
    cin >> foo;
    foo--;
  	cin >> grade;
    if (grade == "AC") {
      if (vec.at(foo) == "AC") continue;
      P += v.at(foo);
      A++;
      vec.at(foo) = "AC";
    } else if (grade == "WA") {
      if (vec.at(foo) == "AC") continue;
      v.at(foo)++;
    }
  }
  
  cout << A << " " << P << endl;
}

Measured memory_bytes: 6144
using System;
using System.Collections.Generic;
using System.Linq;

public class Solution
{
    static int Solve(string s, int i, char[] t, char[] dir)
    {
        var n = s.Length;
        var p = i;
        for (int j = 0; j < t.Length; j++)
        {
            var c = t[j];
            if (s[p] == c)
            {
                if (dir[j] == 'L')
                {
                    p--;
                    if (p < 0)
                    {
                        return -1;
                    }
                }
                else
                {
                    p++;
                    if (p >= n)
                    {
                        return 1;
                    }
                }
            }
        }
        return 0;
    }

    // [ok,ng) or (ng,ok]
    static int Search(string s, int ok, int ng, char[] t, char[] dir)
    {
        while (Math.Abs(ok - ng) > 1)
        {
            var mid = (ok + ng) / 2;
            if (Solve(s, mid, t, dir) == 0)
            {
                ok = mid;
            }
            else
            {
                ng = mid;
            }
        }
        return ok;
    }

    public static void Main()
    {
        var vals = Console.ReadLine().Split(' ').Select(int.Parse).ToArray();
        var n = vals[0];
        var q = vals[1];
        var s = Console.ReadLine();
        var t = new char[q];
        var dir = new char[q];
        for (int i = 0; i < q; i++)
        {
            var strs = Console.ReadLine().Split(' ');
            t[i] = strs[0][0];
            dir[i] = strs[1][0];
        }

        var max = Search(s, 0, n, t, dir);
        var min = Search(s, n, 0, t, dir);

        if(max <= min)
        {
            Console.WriteLine(0);
            return;
        }
        Console.WriteLine(max - min + 1);
    }
}

Measured memory_bytes: 18784
#include <bits/stdc++.h>
using namespace std;
#define ff first
#define ss second
using ll = long long; using ld = long double; const char nl = '\n';
/* -*- -*- -*- -*- -*- -*- -*- -*- -*- -*- -*- -*- -*- -*- -*- -*- -*- -*- -*- -*- -*- -*- -*- */

#include <bits/extc++.h>
namespace pbds =  __gnu_pbds;
template <typename key, typename val=pbds::null_type, typename comp=less<key>>
using ostree=pbds::tree<key,val,comp,pbds::rb_tree_tag,pbds::tree_order_statistics_node_update>;
using vi = vector< int >; using vll = vector< ll >;
#define all(x) std::begin(x), std::end(x)
mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());
template <typename...Args, template<typename...> typename T> string to_string(T<Args...> const&);
string to_string(string const&s){return '"'+s+'"';}
string to_string(char const &c) {return to_string(string(1,c));}
string to_string(char const *c) {return to_string(string(c));}
string to_string(bool const &b) {return (b ? "1" : "0");}
template<typename... Args> string to_string(pair<Args...> const&p)
{return "("+to_string(p.first)+", "+to_string(p.second)+")";}
template <typename...Args, template<typename...> typename T> string to_string(T<Args...> const&S)
{string s = "{"; for(auto const& e: S)s+=" "+to_string(e);s+=" }"; return s;}
template<typename Tail> void debug_out(Tail t) {cerr<<" "<<to_string(t)<<" ]"<<endl;}
template<typename Head, typename... Tail> void debug_out(Head h, Tail... t)
{cerr << " " << to_string(h) << ","; debug_out(t...);}
#define pr(...) cerr<<"["<<(#__VA_ARGS__)<<"] : [", debug_out(__VA_ARGS__)
template <typename T> void dbr(T lb, T ub)
{cerr<<'{';for(auto it=lb; it!=ub; it++)cerr<<' '<<to_string(*it); cerr<<" }"<<endl;}
template<typename T, typename Comp=less<T>> bool smin(T &mem, T const&v, Comp const&cmp=Comp())
{return cmp(v, mem) ? mem = v, true : false;}
template<typename T, typename Comp=less<T>> bool smax(T &mem, T const&v, Comp const&cmp=Comp())
{return cmp(mem, v) ? mem = v, true : false;}
/* -*- -*- -*- -*- -*- -*- -*- -*- -*- -*- -*- -*- -*- -*- -*- -*- -*- -*- -*- -*- -*- -*- -*- */

int const N = 300100;
int n, m;
int s, t;
vi g[N];
int q[N], dist[N];

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

  cin >> n >> m;
  for(int u,v,i=1; i<=m; i++) {
    cin >> u >> v; u--, v--;
    for(int i=0,j=1; i<3; i++,j=(j+1)%3) {
      int p = 3 * u + i;
      int q = 3 * v + j;
      g[ p ].emplace_back( q );
    }
  }
  cin >> s >> t; s--, t--, s*=3, t*=3;

  fill(dist, dist+n*3, n*4);
  int ql = 0, qr = 0;
  q[qr++] = s;
  dist[s] = 0;
  for(; ql<qr; ) {
    int u = q[ql++];
    for(int v: g[u]) {
      if( dist[v] == 4*n ) {
        q[qr++] = v;
        dist[v] = dist[u] + 1;
      }
    }
  }


  if( dist[t] == 4*n ) {
    cout << -1 << endl;
  } else {
    cout << dist[t] / 3 << endl;
  }

}
/* -*- -*- -*- -*- -*- -*- -*- -*- -*- -*- -*- -*- -*- -*- -*- -*- -*- -*- -*- -*- -*- -*- -*- */


Measured memory_bytes: 19072
#include<bits/stdc++.h>
using namespace std;
int main(){
  int h,w;
  char c;
  int a[101][101];
  cin >> h >> w;
  for(int i=0; i<h; i++){
    for(int j=0; j<w; j++){
      cin >> c;
      if(c =='c') a[i][j] = 0;
      else a[i][j] = -1;
    }
  }
  for(int i=0; i<h; i++){
    int count=0,x=1;
    for(int j=0; j<w; j++){
      if(a[i][j]==0){
        while(1){
          if(a[i][j+x]==0 || j+x > w-1){
            x=1;
            count = 0;
            break;
          }
          count++;
          a[i][j+x]=count;
          x++;
        }
      }
    }
  }
  for(int i=0; i<h; i++){
    for(int j=0; j<w; j++){
      if(j>0) cout << " " << a[i][j];
      else cout << a[i][j];
    }
    cout << endl;
  }
  return 0;
}



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

int main(){
  const double pi = 3.141592653589;
  cout << fixed << setprecision(12);
  double r;
  cin >> r;
  double area = (r * r) * pi;
  double cir = (2 * r) * pi;
  cout << area << " " << cir << endl;
}



Measured memory_bytes: 3288
#include <stdio.h>
#include <cstdio>
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <cmath>
#include <iomanip>
#include <queue> 
#include <tuple>
#include <map>
 
using namespace std;

typedef long long ll;

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

    int N, M;

    cin >> N >> M;

    vector<int> S(N + 1, -1);

    for(int i = 0; i < M; i++) {
        int s, c;
        cin >> s >> c;
        if(S[s] != -1 && S[s] != c) {
            cout << -1 << endl;
            return 0;
        }
        S[s] = c;
    }

    if(N > 1 && S[1] == 0) {
        cout << -1 << endl;
        return 0;
    }

    for(int i = 1; i <= N; i++) {
        if(i == 1) {
            if(S[i] == -1) {
                if(N > 1) cout << 1;
                else cout << 0;
            } else {
                cout << S[i];
            }
        } else {
            if(S[i] == -1) {
                cout << 0;
            } else {
                cout << S[i];
            }
        }
    }
}


Measured memory_bytes: 256
/**
*    created: 21.06.2020 02:45:51
**/
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
#define int long long
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep2(i, s, n) for (int i = (s); i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()
#define pcnt(bit) __builtin_popcount(bit)
#define mod 1000000007
#define pi acos(-1.0)
using namespace std;

signed main() {

    cin.tie(0);
    ios_base::sync_with_stdio(false);

    int a, b;
    cin >> a >> b;
    if (a % 2 == 0 || b % 2 == 0) cout << "No" << endl;
    else cout << "Yes" << endl;
    return 0;
}

Measured memory_bytes: 3536