akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;
#define SPEED ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define pb push_back
#define ll long long
int main()
{
    SPEED
    ll n;ll k;
    cin >> n >> k;
    vector<ll> send(n+1);

    for (ll i = 1; i <= n; ++i)
    {
        cin >> send[i];
    }

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

    vector<ll> path;

    ll start = 1;
    visited[start] = 1;
    path.push_back(start);
    ll destination = send[start];

    while(visited[destination]!=1)
    {
        visited[destination] = 1;
        path.push_back(destination);
        start = destination;
        destination = send[start];
    }

    ll cycle_len;
    ll cycle_start_poll = destination;
    ll start_to_cycle_start_poll_dist;

    for (ll i = 0; i < path.size(); ++i)
    {
        if (path[i]==destination)
        {
            start_to_cycle_start_poll_dist = i;
            cycle_len = path.size() - i;
            break;
        }
    }

    if (k<=start_to_cycle_start_poll_dist)
    {
        cout << path[k];
    }
    else
    {
        k -= start_to_cycle_start_poll_dist;

        ll y = k%cycle_len;

        start_to_cycle_start_poll_dist += y;

        cout << path[start_to_cycle_start_poll_dist];
    }


    return 0;
}

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

int main(){
  int a,b,c;
  cin>>a>>b>>c;
  double PI=acos(-1);//円周率
  double rad = c * PI / 180;
  double S=0.5*a*b*sin(rad);
  double h=2*S/a;
  double L=sqrt(a*a+b*b-2*a*b*cos(rad))+a+b;
  cout<<fixed<<setprecision(12)<<S<<endl;
  cout<<fixed<<setprecision(12)<<L<<endl;
  cout<<fixed<<setprecision(12)<<h<<endl;
  return 0;
}


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

int main() {
    int n;
    while (cin >> n) {
        set<string> ss;
        for (int i = 0; i < n; i++) {
            string id;
            cin >> id;
            ss.insert(id);
        }
        int m;
        cin >> m;
        bool isOpen = false;
        for (int i = 0; i < m; i++) {
            string id;
            cin >> id;
            if (ss.find(id) == ss.end()) {
                cout << "Unknown " << id << endl;
            } else {
                if (isOpen) {
                    cout << "Closed by " << id << endl;
                } else {
                    cout << "Opened by " << id << endl;
                }
                isOpen = !isOpen;
            }
        }
    }
}

Measured memory_bytes: 1232
/******************************************************************************

                              Online C++ Compiler.
               Code, Compile, Run and Debug C++ program online.
Write your code in this editor and press "Run" button to compile and execute it.

*******************************************************************************/

#include <bits/stdc++.h>

using namespace std;

int main()
{
    int n;
    cin>>n;
    
    int ar[n+1];
    for(int i=0;i<n;i++)
    cin>>ar[i];
    
    int x=n-1;
    
    priority_queue<double,vector<double>,greater<double>>pq;
    
    for(int i=0;i<n;i++)
    pq.push(ar[i]);
    
    while(pq.size()>1)
    {
        double x=pq.top();
        pq.pop();
        double y=pq.top();
        pq.pop();
        
        double tmp = (x+y)/2.0;
        
        pq.push(tmp);
    }
    
    cout<<fixed<<setprecision(12)<<pq.top()<<endl;
    
    return 0;
}


Measured memory_bytes: 256
use std::io::{self, Read};

fn solve() {
    let mut buffer = String::new();
    io::stdin().read_to_string(&mut buffer).unwrap();
    let v: Vec<&str> = buffer.trim().split(' ').collect();
    assert!(v.len() == 2);
    let h = v[0].parse::<i64>().unwrap();
    let l = v[1].parse::<i64>().unwrap();
    println!("{} {}", h*l, (h+l)*2);
}

fn main() {
    solve();
}



Measured memory_bytes: 5028
#include<bits/stdc++.h>
using namespace std;
int main()
{
    long long n;
    char t;
    cin>>n;
    if(n<1200)
     t='B';
    else if(n<2800)
        t='R';
    else t='G';
    cout<<"A"<<t<<"C"<<endl;
    return 0;
}


Measured memory_bytes: 256
n, k = map(int, input().split())

ans = 0
for i in range(1,n+1):
    if i<k:
        cnt = 0
        tmp = i
        while tmp < k:
            tmp*=2
            cnt+=1
        ans += (1/n*0.5**cnt)
    else:
        ans += 1/n
print(ans)

Measured memory_bytes: 3060
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner scanner = new Scanner(System.in);
		int a = scanner.nextInt(),b = scanner.nextInt(),c = scanner.nextInt();
		if(a == b){
			System.out.println(c);
		}else if(a == c){
			System.out.println(b);
		}else{
			System.out.println(a);
		}
	}

}


Measured memory_bytes: 22612
#include <bits/stdc++.h>              
using namespace std;                 
using ll = long long;               
using vl = vector<ll>;              
using vvl = vector<vl>;            
using pll = pair<ll,ll>;                 
using vb = vector<bool>;                 
const ll oo = 0x3f3f3f3f3f3f3f3fLL;      
const double eps = 1e-9;                 
#define sz(c) ll((c).size())             
#define all(c) begin(c),end(c)           
#define mp make_pair                     
#define mt make_tuple                    
#define pb push_back                     
#define eb emplace_back                  
#define xx first                         
#define yy second                       
#define has(c,i) ((c).find(i) != end(c))
#define FOR(i,a,b) for (int i=(a); i<(b); i++)       
#define FORD(i,a,b) for (int i=int(b)-1; i>=(a); i--)
#define DB(X) ({ if(1) cerr << "DB: " << (#X) << " = " << (X) << endl; })

int main() { 
  ios::sync_with_stdio(false); 
  string s;
  cin >> s;
  ll k;
  cin >> k;
  ll n = sz(s);
  FOR(i,0,n){
    if(s[i] != 'a' && 'z' - s[i] + 1 <= k){
      k -= 'z' - s[i] + 1;
      s[i] = 'a';
    }
  }
  k %= 26;
  s[n-1] += k;
  cout << s << endl;
}

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

#undef _P
#define _P(...) (void)printf(__VA_ARGS__)
#define FOR(x,to) for(x=0;x<(to);x++)
#define FORR(x,arr) for(auto& x:arr)
#define ITR(x,c) for(__typeof(c.begin()) x=c.begin();x!=c.end();x++)
#define ALL(a) (a.begin()),(a.end())
#define ZERO(a) memset(a,0,sizeof(a))
#define MINUS(a) memset(a,0xff,sizeof(a))
//-------------------------------------------------------

void solve() {
	int i,j,k,l,r,x,y; string s;
	
	int X;
	cin>>X;
	cout<<8-(X-400)/200<<endl;
}


int main(int argc,char** argv){
	string s;int i;
	if(argc==1) ios::sync_with_stdio(false), cin.tie(0);
	FOR(i,argc-1) s+=argv[i+1],s+='\n'; FOR(i,s.size()) ungetc(s[s.size()-1-i],stdin);
	cout.tie(0); solve(); return 0;
}


Measured memory_bytes: 3652
//#include "pch.h"
#include <iostream>
#include<string>
#include<algorithm>
#include<iomanip>

using namespace std;


int main() {
	while (1) {
		string a;
		cin >> a;
		if (a == "0")break;
		int N[1010];
		
		int ans=0;

		for (int i = 0; i < a.size(); i++) {
			N[i] = a[i] - '0';
			ans += N[i];
		}

		cout << ans<<endl;
	}
	
}





Measured memory_bytes: 3196
def makefac(n):
    global faclist
    faclist = [1, 1]
    for i in range(2, n + 1):
        faclist.append(faclist[-1] * i % MOD)
    return None
def mcomb(n, r):#nCr % MOD
    return faclist[n] * pow(faclist[r],MOD - 2, MOD) * pow(faclist[n-r], MOD - 2, MOD)
def mperm(n, r):#nPr % MOD
    return faclist[n] * pow(faclist[n-r],MOD - 2, MOD)

N, M = map(int, input().split())
MOD = 10 ** 9 + 7
makefac(M)
ans = mperm(M, N)
for k in range(1, N + 1):
    ans += ((-1)**k * mcomb(N, k) * mperm(M - k, N - k)) % MOD
ans = ans * mperm(M, N) % MOD
print(ans)


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

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

int main() {
	int n;
	cin >> n;
	pair<int, int> now = make_pair(0, 0);
	int pre = 0;
	rep(i, n) {
		int t, x, y;
		cin >> t >> x >> y;
		int d = abs(now.first - x) + abs(now.second - y);
		if(d > t - pre || (d - (t - pre)) % 2 != 0) {
			cout << "No" << endl;
			return 0;
		}
		now = make_pair(x, y);
		pre = t;
	}
	cout << "Yes" << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define IO_OP std::ios::sync_with_stdio(0); std::cin.tie(0);
#define F first
#define S second
#define V vector
#define PB push_back
#define MP make_pair
#define EB emplace_back
#define ALL(v) (v).begin(), (v).end()
#define debug(x) cerr << #x << " is " << x << endl

using namespace std;

typedef long long ll;
typedef pair<int, int> pi;
typedef V<int> vi;

const int INF = 1e9 + 7;

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

signed main()
{
	IO_OP;
	
	int h, w, k, x1, y1, x2, y2;
	cin >> h >> w >> k;
	cin >> x1 >> y1 >> x2 >> y2;
	x1--, y1--, x2--, y2--;
	V<V<char>> a(h, V<char>(w));
	V<V<int>> d(h, V<int>(w, INF));
	for(int i = 0; i < h; i++)
		for(int j = 0; j < w; j++)
			cin >> a[i][j];
	d[x1][y1] = 0;
	queue<pi> q;
	q.push({x1, y1});
	while(q.size()) {
		int x = q.front().F, y = q.front().S; q.pop();
		for(int i = 0; i < 4; i++) {
			for(int j = 1; j <= k; j++) {
				int xx = x + dx[i] * j, yy = y + dy[i] * j;
				if(xx < 0 || xx >= h || yy < 0 || yy >= w || a[xx][yy] == '@' || d[xx][yy] < d[x][y] + 1) break;
				if(d[xx][yy] > d[x][y] + 1) {
					d[xx][yy] = d[x][y] + 1;
					q.push({xx, yy});
				}
			}
		}

	}
	if(d[x2][y2] == INF) cout << -1 << endl;
	else cout << d[x2][y2] << endl;

}





Measured memory_bytes: 11968
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace CADDi2018forBeginnersA___1222
{
    class Program
    {
        static readonly int targetNum = 2;


        static void Main(string[] args)
        {
            char[] input = Console.ReadLine().ToCharArray();
            int count = 0;
            foreach (var v in input)
            {
                if (int.Parse(v.ToString()) == targetNum)
                {
                    count++;
                }
            }

            Console.WriteLine(count);
        }
    }
}


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

typedef pair <int, int> ii;

const int Maxn = 22;
const int Inf = 1000000000;
const int Maxd = 4;
const int dy[Maxd] = {-1, 0, 1, 0};
const int dx[Maxd] = {0, -1, 0, 1};

int n, m;
char B[Maxn][Maxn];
int dist[Maxn][Maxn];
int res;

void Solve(int r, int c)
{
    fill((int*)dist, (int*)dist + Maxn * Maxn, Inf);
    dist[r][c] = 0;
    queue <ii> Q; Q.push(ii(r, c));
    while (!Q.empty()) {
        ii v = Q.front(); Q.pop();
        res = max(res, dist[v.first][v.second]);
        for (int i = 0; i < Maxd; i++) {
            ii u = ii(v.first + dy[i], v.second + dx[i]);
            if (0 <= u.first && u.first < n && 0 <= u.second && u.second < m &&
                B[u.first][u.second] == '.' && dist[v.first][v.second] + 1 < dist[u.first][u.second]) {
                    dist[u.first][u.second] = dist[v.first][v.second] + 1;
                    Q.push(u);
                }
        }
    }
}

int main()
{
    scanf("%d %d", &n, &m);
    for (int i = 0; i < n; i++)
        scanf("%s", &B[i]);
    for (int i = 0; i < n; i++)
        for (int j = 0; j < m; j++) if (B[i][j] == '.')
            Solve(i, j);
    printf("%d\n", res);
    return 0;
}


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

using namespace std;

using ll = long long;

// 0~nまでのi桁目に1は何回出てくるか
ll solve(ll n, ll i) {
  if (n == 0) {
    return 0;
  }

  // 0が何個続くか
  ll rep_0 = pow(2, i);
  ll dv = (n + 1) / (rep_0 * 2);
  ll md = (n + 1) % (rep_0 * 2);
  ll ans = dv * rep_0;
  if (md > rep_0) {
    ans += md - rep_0;
  }

  return ans;
}

int main(int argc, const char *argv[]) {
  ll a, b;
  cin >> a >> b;

  ll ans = 0;
  for (ll i = 0, pow2 = 1; i <= 40; ++i, pow2 *= 2) {
    ll cnt = solve(b, i) - solve(a - 1, i);
    ans += pow2 * (cnt % 2);
  }

  cout << ans << '\n';
}

Measured memory_bytes: 512
import java.io.*;
import java.util.*;

class Main{
    public static void main(String[] args){
	BufferedReader sc=new BufferedReader(new InputStreamReader(System.in));
	try {
	    String[] st;
	    while(true){
		int n = Integer.valueOf(sc.readLine());
		if(n==0)
		    break;
		int max=0, min=0, now=0;
		st = sc.readLine().split(" ");
		for(int j=0; j<5; j++)
		    now+=Integer.valueOf(st[j]);
		max = now; min = now;
		for(int i=1; i<n; i++){
		    now = 0;
		    st = sc.readLine().split(" ");
		    for(int j=0; j<5; j++)
			now+=Integer.valueOf(st[j]);
		    if(now>max) max = now;
		    if(now<min) min = now;
		}
		System.out.println(max+" "+min);
	    }
	}catch(Exception e){
	    System.out.println("Error");
	}
    }
}

Measured memory_bytes: 25140
#include <stdio.h>

void Do(int N, int M, int X){
  int i, j, r, l;
  int A[M];
  for(i = 0;i < M;i++) scanf("%d", &A[i]);
  r = l = 0;
  for(i = X - 1;i > 0;i--){
    for(j = 0;j < M;j++){
      if(A[j] == i){
	r++;
	break;
      }
      if(A[j] > i) break;
    }
  }
  for(i = X + 1;i <= N;i++){
    for(j = M - 1;j >= 0;j--){
      if(A[j] == i){
	l++;
	break;
      }
      if(A[j] < i) break;
    }
  }
  if(r > l) printf("%d\n", l);
  else printf("%d\n", r);
}
  
int main(void){
  int N, M, X;
  scanf("%d %d %d", &N, &M, &X);
  Do(N, M, X);
  return 0;
}


Measured memory_bytes: 128
#include<map>
#include<set>
#include<queue>
#include<cmath>
#include<cstdio>
#include<vector>
#include<string>
#include<cstring>
#include<iostream>
#include<algorithm>
#define lc (x<<1)
#define rc (x<<1|1)
#define gc getchar()//(p1==p2&&(p2=(p1=buf)+fread(buf,1,size,stdin),p1==p2)?EOF:*p1++)
#define mk make_pair
#define pi pair<int,int>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
const int N=2e5+10,size=1<<20;

//char buf[size],*p1=buf,*p2=buf;
template<class o> void qr(o &x) {
	char c=gc; x=0; int f=1;
	while(!isdigit(c)){if(c=='-')f=-1; c=gc;}
	while(isdigit(c)) x=x*10+c-'0',c=gc;
	x*=f;
}
template<class o> void qw(o x) {
	if(x/10) qw(x/10);
	putchar(x%10+'0');
}
template<class o> void pr1(o x) {
	if(x<0)x=-x,putchar('-');
	qw(x); putchar(' ');
}
template<class o> void pr2(o x) {
	if(x<0)x=-x,putchar('-');
	qw(x); puts("");
}

int n,m,q,a[N],b[N],c[N],d[N],w[N],ans;

void dfs(int x,int i) {
	if(x>n) {
		int s=0;
		for(int i=1;i<=q;i++)
			s+=d[i]*(w[b[i]]-w[a[i]]==c[i]);
		ans=max(ans,s);
		return ;
	}
	for(	;i<=m;i++) w[x]=i,dfs(x+1,i);
}


int main() {
	qr(n); qr(m); qr(q);
	for(int i=1;i<=q;i++) qr(a[i]),qr(b[i]),qr(c[i]),qr(d[i]);
	dfs(1,1);
	pr2(ans);
	return 0;
}



Measured memory_bytes: 3656
n = int(input())
a = list(input())
b = list(input())
c = list(input())

count = 0
for i in range(n):
    seta = set()
    seta.add(a[i])
    seta.add(b[i])
    seta.add(c[i])
    count += len(seta) - 1
print(count)

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

int N,M;
vector<int> paths[100010],lis;
bool isin[100010],used[100010];

void toposo(int now){
	if(used[now]) return;
	used[now]=true;
	for(vector<int>::iterator it=paths[now].begin();it!=paths[now].end();it++){
		if(!used[*it])toposo(*it);
	}
	lis.push_back(now);
}

int main(){
	cin>>N>>M;
	int a,b;
	for(int i=1;i<=M;i++){
		cin>>a>>b;
		paths[a].push_back(b);
		isin[b]=true;
	}
	int cnt=0;
	vector<int> aaa;
	for(int i=1;i<=N;i++){
		if(!isin[i]){
			aaa.push_back(i);
		}
	}

	fill(used,used+100010,false);
	for(vector<int>::iterator it=aaa.begin();it!=aaa.end();it++){
		cout<<"";//debug
		toposo(*it);
	}
	int res=0;
	for(int i=N-1;i>0;i--){
		bool hog=false;
		for(vector<int>::iterator it=paths[lis[i]].begin();it!=paths[lis[i]].end();it++){
			if((*it)==lis[i-1]) hog=true;
		}
		if(!hog) res=1;
	}
	for(int i=N-1;i>=0;i--){
		cout<<lis[i]<<endl;
	}
	cout<<res<<endl;
	return 0;
}

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

int main(int argc, char *argv[]) {
    int r,s,p;
    cin >> r >> s >> p;
    vector<int> v;
    for (int i = 0; i < p; i++) {
        int a,b;
        cin >> a >> b;
        v.push_back(abs(b - s) + (b <= s) + r - a + 1);
    }
    int pp = 0;
    sort(v.begin(),v.end());
    for (int i = 0; i < v.size(); i++) {
        if (pp < v[i]) {
            pp = v[i];
        } else {
            pp++;
        }
    }
    cout << pp << endl;
    return 0;
}



Measured memory_bytes: 4876
#include <bits/stdc++.h>
#define FOR(i,a,b) for (int i=(a);i<(b);i++)
#define FORR(i,a,b) for (int i=(a);i>=(b);i--)
#define pb push_back

using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef set<int> si;
const int inf = 1e9;
const int mod = 1e9+7;

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

  cin >> X;
  X *= 2;
  double s = sqrt(X);
  int q = floor(s);
  if(q * q + q < X) q++;
  cout << q << endl;
}


Measured memory_bytes: 892
#include<stdio.h>
#include<stdlib.h>


long long int n;
long long int a[100001];
long long int b[100001];

long long int cmp(const void *c, const void *b){
    return *(long long int*)c - *(long long int*)b;
}

int main(){
	long long int i,j;
	long long int q,w,e,r,t,y;
	
	scanf("%lld",&n);
	for(i=0;i<n;i++){
		scanf("%lld",&a[i]);
	}
	
	qsort(a,n,sizeof(long long int),cmp);
	
	b[0]=a[0];
	for(i=1;i<n;i++){
		b[i] = a[i]+b[i-1];
	}
	
	q=0;
	for(i=n-1-1;i>=0;i--){
		if(b[i]*2>=a[i+1]){
			q++;
		}else{
			break;
		}
	}
	
	printf("%lld\n",q+1);
	return 0;
}

Measured memory_bytes: 1788
#include<stdio.h>
#include<string.h>
#include<iostream>
#include<stdlib.h>
using namespace std;

struct Node
{
    int key;
    Node *prev,*next;
};

Node *nil;

Node* listSearch(int key)
{
    Node *cur=nil->next;
    while(cur !=nil && cur->key!=key)
    {
        cur = cur->next;
    }
    return cur;
}

void init(){
    nil=(Node*)malloc(sizeof(Node));
    nil->next=nil;
    nil->prev=nil;
}

void printList()
{
    Node *cur = nil->next;
    int isf = 0;
    while(true)
    {
        if(nil == cur) break;
        if(isf++ > 0) printf(" ");
        printf("%d",cur->key);
        cur = cur->next;
    }
    printf("\n");
}

void deleteNode(Node *t)
{
    if(t==nil) return;
    t->prev->next=t->next;
    t->next->prev=t->prev;
    free(t);
}

void deleteFirst()
{
    deleteNode(nil->next);
}

void deleteKey(int key)
{
    deleteNode(listSearch(key));
}

void deleteLast()
{
    deleteNode(nil->prev);
}

void insert(int key)
{
    Node * x = (Node *)malloc(sizeof(Node));
    x->key=key;
    x->next=nil->next;
    nil->next->prev=x;
    nil->next=x;
    x->prev=nil;


}

int main()
{
    int key,n,i;
   // int size = 0;
    char com[20];
  //  int np = 0,nd = 0;
    scanf("%d",&n);
    init();
    for(i=0;i<n;i++)
    {
        scanf("%s%d",com,&key);
        if(com[0]=='i')
        {
            insert(key);//np++;size++;
        }
        else if(com[0]=='d')
        {
            if(strlen(com)>6)
            {
                if(com[6]=='F')deleteFirst();
                else if(com[6]=='L')deleteLast();
            }else{
                deleteKey(key);
            //nd++;
            }
           // size--;
        }
    }
    printList();
    return 0;
}

Measured memory_bytes: 34392
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <numeric>
#include <string>
using namespace std;


int main(){
  long long n, x;
  cin >> n >> x;
  long long length[n + 1], sum_p[n + 1];
  sum_p[0] = 1;
  length[0] = 1;
  for (int i = 1; i <= n; i++){
    sum_p[i] = sum_p[i - 1] * 2 + 1;
    length[i] = length[i - 1] * 2 + 3;
  }
  long long answer = 0;
  for (int i = n - 1; i >= 0; i--){
    if (x >= length[i] * 2 + 2){
      answer += sum_p[i] * 2 + 1;
      break;
    }
    else if (x > length[i] + 2){
      answer += sum_p[i] + 1;
      x -= length[i] + 2;
    }
    else if (x == length[i] + 2){
      answer += sum_p[i] + 1;
      break;
    }
    else if (x == length[i] + 1){
      answer += sum_p[i];
      break;
    }
    else if (x > 1){
      x -= 1;
    }
  }
  cout << answer << endl;
  return 0;
}


Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
ull B = 100000007;
ll mod = 1000000007;
int INF = 0x3f3f3f3f;

struct L {
    int v;
    int id;
    bool operator<(const L& b) {
        return v > b.v;
    }
};

int main(){
    int x, y;
    cin >> x >> y;
    int a, b, c;
    cin >> a >> b >> c;
    vector<L> arr;
    int tv;
    for(int i = 0; i < a; ++i) {
        cin >> tv;
        arr.push_back({tv, 0});
    }
    for(int i = 0; i < b; ++i) {
        cin >> tv;
        arr.push_back({tv, 1});
    }
    for(int i = 0; i < c; ++i) {
        cin >> tv;
        arr.push_back({tv, 2});
    }
    sort(arr.begin(), arr.end());
    ll sum = 0;

    int total = x + y;
    int count[3] = {0, 0, 0};

    for(int i = 0; i < total; ++i) {
        sum += arr[i].v;
        count[arr[i].id]++;
    }

    if(count[0] > x) {
        int reduce = count[0] - x;
        for(int i = total - 1; i >= 0 && reduce != 0; --i) {
            if(arr[i].id == 0) {
                sum -= arr[i].v;
                reduce--;
            }
        }
        for(int i = total; i <= arr.size() && reduce < count[0] - x; ++i) {
            if(arr[i].id != 0) {
                sum += arr[i].v;
                reduce++;
            }
        }
    }

    if(count[1] > y) {
        int reduce = count[1] - y;
        for(int i = total - 1; i >= 0 && reduce != 0; --i) {
            if(arr[i].id == 1) {
                sum -= arr[i].v;
                reduce--;
            }
        }
        for(int i = total; i <= arr.size() && reduce < count[1] - y; ++i) {
            if(arr[i].id != 1) {
                sum += arr[i].v;
                reduce++;
            }
        }
    }

    cout << sum << endl;


    return 0;
}



Measured memory_bytes: 6384
import math
while True:
    n = int(input())
    if n == 0:
        break
    s = list(map(int,input().split())) #複数読み込みリストに格納
    m = sum(s) / float(n) #nの浮動小数点型で割る
    print("{0:.8f}".format(math.sqrt(sum([(x-m)**2 for x in s])/n)))
    #math.sqrt()で√


Measured memory_bytes: 5716
#include <bits/stdc++.h>
#define int long long int
#define MOD(x) ((x % MOD_N) + MOD_N) % MOD_N
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define FORE(i,a,b) for(int i=(a);i<=(b);++i)
#define RFOR(i,a,b) for(int i=(b)-1;i>=(a);--i)
#define RFORE(i,a,b) for(int i=(b);i>=(a);--i)
#define REP(i,n) FOR(i,0,n)
#define RREP(i,n) RFOR(i,0,n)
#define ALL(c) (c).begin(),(c).end()
#define RALL(c) (c).rbegin(),(c).rend()
#define SORT(c) sort(ALL(c))
#define RSORT(c) sort(RALL(c))
#define SIZE(c) (int)((c).size())
#define EACH(i,v) for(auto i=v.begin();i!=v.end();++i)
#define REACH(i,v) for(auto i=v.rbegin();i!=v.rend();++i)
#define LB(c,x) distance((c).begin(),lower_bound(ALL(c),x))
#define UB(c,x) distance((c).begin(),upper_bound(ALL(c),x))
#define COUNT(c,x) (upper_bound(ALL(c),x)-lower_bound(ALL(c),x))
#define UNIQUE(c) SORT(c); (c).erase(unique(ALL(c)),(c).end());
#define COPY(c1,c2) copy(ALL(c1),(c2).begin())
#define EXIST(s,e) (bool)((s).find(e)!=(s).end())
#define PB push_back
#define MP make_pair
#define DUMP(x)  cerr<<#x<<" = "<<(x)<<endl;
#define NL cerr<<endl;
using namespace std;
template<typename T,typename U> using P=pair<T,U>;
template<typename T> using V=vector<T>;
template<typename T>bool chmax(T&a,T b){if(a<b){a=b;return true;}return false;}
template<typename T>bool chmin(T&a,T b){if(a>b){a=b;return true;}return false;}
template<typename T>T sum(vector<T>&v){return accumulate(ALL(v),T());}
template<typename T>T sum(vector<T>&v,int a,int b){return accumulate(v.begin()+a,v.begin()+b,T());}
template<typename T>T max(vector<T>&v){return *max_element(ALL(v));}
template<typename T>T min(vector<T>&v){return *min_element(ALL(v));}
template<typename T>T max_index(vector<T>&v){return distance((v).begin(),max_element(ALL(v)));}
template<typename T>T min_index(vector<T>&v){return distance((v).begin(),min_element(ALL(v)));}

struct edge { int to, cost; };

template<typename T>auto&operator<<(ostream&s,const vector<T>&v){s<<"[";bool a=1;for(auto e:v){s<<(a?"":" ")<<e;a=0;}s<<"]";return s;}
template<typename T,typename U>auto&operator<<(ostream&s,const pair<T,U>&p){s<<"("<<p.first<<","<<p.second<<")";return s;}
template<typename T>auto&operator<<(ostream&s,const set<T>&st){s<<"{";bool a=1;for(auto e:st){s<<(a?"":" ")<<e;a=0;}s<<"}";return s;}
template<typename T,typename U>auto&operator<<(ostream&s,const map<T,U>&m){s<<"{";bool a=1;for(auto e:m){s<<(a?"":" ")<<e.first<<":"<<e.second;a=0;}s<<"}";return s;}

const int INF = 1e18;
const int MOD_N = 1e9+7;

signed main()
{
   int n, m; cin >> n >> m;
   V<int> num(n);
   REP(i, m) {
      int a, b;
      cin >> a >> b;
      a--; b--;
      num[a]++; num[b]++;
   }

   bool all_even = true;
   REP(i, n) {
      if (num[i] % 2 == 1) all_even = false;
   }

   cout << (all_even ? "YES" : "NO") << endl;

   return 0;
}


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

using namespace std;

#define int long long
#define tie() ios_base :: sync_with_stdio(0); cin.tie(0) ; cout.tie(0)
#define err(x) cerr << #x << " is : " << x << endl
#define mem(a , v)   memset(a , v , sizeof a)
#define all(v) v.begin() , v.end()
#define endl '\n'


const int N = 1e5 + 20;
const int mod = 1e9 + 7;
string SMAX = "3234566667";



bool operator < (string &a  , string &b)
{
      if(a.size() < b.size())
            return true;
      if(a.size() > b.size())
            return false;
      for(int i = 0 ; i < a.size();  i++)
      {
            if(a[i] > b[i])
                  return false;
            if(a[i] < b[i])
                  return true;
      }
      return false;
}


bool operator > (string &a  , string &b)
{
      if(a.size() > b.size())
            return true;
      if(a.size() < b.size())
            return false;
      for(int i = 0 ; i < a.size();  i++)
      {
            if(a[i] > b[i])
                  return true;
            if(a[i] < b[i])
                  return false;
      }
      return false;
}


char low(char c)
{
      return (c < '0') ? '0' : c;
}

char high(char c)
{
      return c > '9' ? '9' : c;
}

vector <string> ans;

void rec(string &s , int idx = -1)
{
      if(s > SMAX)
            return;
      if(!s.empty())
            ans.push_back(s);

      if(idx == -1)
      {
            for(char i = '1' ; i <= '9' ; i++)
            {
                  s += i;
                  rec(s , idx + 1);
                  s.pop_back();
            }
            return;
      }

      char l = low(s[idx] - 1);
      char h = high(s[idx] + 1);
      for(char i = l ; i <= h; i++)
      {
            s += i;
            rec(s , idx + 1);
            s.pop_back();
      }

      return;
}


int32_t main()
{
      tie();
      int t = 1;
      //cin >> t;
      string s = "";
      rec(s);
      sort(all(ans) , [&](string &a , string &b)
      {
            return a < b;
      });
      while(t--)
      {
            int k;
            cin >> k;
            k--;
            cout << ans[k] << endl;
      }
      return 0;
}


Measured memory_bytes: 7364
#include <iostream>
#include <queue>
#include <stdio.h>
#include <map>
#include <string>
#include <algorithm>

using namespace std;

typedef pair<string, int> P;

const int INF = 100000000;

//&#36755;入
string a;

//移&#21160;方向
int op[4] = {-1, 1, -4, 4};

map<string, int> dp;                        //保存从string&#21464;到"01234567"的int

//&#35745;算从"01234567"&#36716;&#25442;到其他序列所需的最小&#27493;数
void bfs(){
    //初始化
    queue<P> que;
    que.push(P("01234567", 0));
    dp["01234567"] = 0;
    //&#23485;度&#20248;先搜索
    while(!que.empty()){
        P p = que.front();
        que.pop();
        string s = p.first;
        int cur = p.second;
        for(int i = 0; i < 4; i ++){
            //&#26500;造下一次交&#25442;
            int next = cur + op[i];
            string str = s;
            swap(str[cur], str[next]);
            map<string, int>::iterator it = dp.find(str);
            //判断是否可移&#21160;以及是否&#35775;&#38382;&#36807;
            if(0 <= next && next < 8 
                && !(cur == 3 && next == 4) && !(cur == 4 && next == 3) 
                && it == dp.end()){

                que.push(P(str, next));
                dp[str] = dp[s] + 1;
            }
        }
    }
}

void solve(){
    //&#21024;除空格
    a.erase(remove(a.begin(), a.end(), ' '), a.end());
    // remove：去除容器中的所有的' ' 
    // 函数返回新区&#38388;最后一个元素的下一个位置
    cout<<dp[a]<<endl;
}

int main(){
    //先逆向&#26500;造所有情况，后直接&#35835;取&#36755;入用例的&#32467;果
    bfs();
    while(getline(cin, a)){
        solve();
    }
    return 0;
}

Measured memory_bytes: 3440
#include <bits/stdc++.h>
#define sz(v)   ((int)(v).size())
#define  all(v)    ((v).begin()),((v).end())
#define  allr(v)    ((v).rbegin()),((v).rend())
#define   pb         push_back
#define   mp         make_pair
#define    clr(v,d)      memset( v, d ,sizeof(v))
#define     PI                       acos(-1)
typedef  long long     ll ;
typedef  unsigned long long ull;
const double eps= (1e-9);
using namespace std;
int dcmp(long double a,long double b){   return fabsl(a-b)<=eps ? 0: (a>b)? 1:-1  ;}
int getBit(ll num, int idx) {return ((num >> idx) & 1ll) == 1;}
int setBit1(int num, int idx) {return num | (1<<idx);}
ll setBit0(ll num, int idx) {return num & ~(1ll<<idx);}
ll flipBit(ll num, int idx) {return num ^ (1ll<<idx);}
void GO(){ ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);}
int countNumBit1(int mask) {int ret=0; while (mask) 	{mask &= (mask-1);++ret;	}return ret;}
const int N=100+5;

int main(){
    GO();
    ll x,k,d;
    cin>>x>>k>>d;
    if(x==0){
        if(k%2==0){
            cout<<x<<"\n";
        }
        else{
            cout<<d<<"\n";
        }
        return 0;
    }
    ll mi;
    if(x>0){
      mi=x+d;
      ll F= x/d;
      if(k>F){
        k-=F;
        x= x%d;
        if(k%2==0){
        mi=min(mi,x);
        x-=d;
        x-=d;
        mi=min(mi,llabs(x));
        }
        else{
        x-=d;
        mi=min(mi,llabs(x));
        }
      }
      else if(k==F){
        k-=F;
        x%=d;
        mi=min(mi,x);
      }
      else{
        x= x- k*d;
        mi=min(mi,x);
      }
    }
    else{
        mi= llabs(x-d);

        ll F= llabs(x/d);
        if(k>F){
            x%=d;
            k-=F;
            if(k%2==0){
                mi=min(mi,llabs(x));
                x+=d;
                x+=d;
                mi=min(mi,llabs(x));
            }
            else{
                x+=d;
                mi=min(mi,llabs(x));
            }

        }
        else if(k==F){
            x%=d;
            mi=min(mi,llabs(x));
        }
        else{
            x= x+k*d;
            mi=min(mi,llabs(x));
        }

    }
    cout<<mi<<"\n";

}
































































































































































































































































































Measured memory_bytes: 3588
#include<bits/stdc++.h>
using namespace std;
#define  ft  ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define  ll  long long
#define  pi  pair<int,int>
#define  pb  push_back
#define  F   first
#define  S   second
#define  B   begin()
#define  E   end()
const int N=2e5+3;
//string s,p;
//vector<int>v;
//map<int,int>mp;

int main()
{
    ft
    int t,i,j,n,m,l,r;
    cin>>n;
    l=(ceil(n*1.0/1000.0)*1000)-n;
    cout<<l<<"\n";
    return 0;
}


Measured memory_bytes: 3652
// B - Not Found
#include <bits/stdc++.h>
using namespace std;
#define rp(i,s,e) for(int i=(s);i<(e);++i)

int main(){
	string S; cin>>S;
	int n = 'z'-'a';
	vector<bool> A(n+1, false);
	rp(i, 0, S.size()) A[S[i]-'a'] = true;
	int ix;
	for(ix = 0; ix<A.size(); ++ix) if(!A[ix]) break;
	if(ix < A.size()) printf("%c\n", ix+'a');
	else puts("None");
}

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

using namespace std;



int main()
{
    int x,a,b;

    cin>>x>>a>>b;

    if(b-a <= 0)
        cout<<"delicious"<<endl;
    else if(b-a<=x)
        cout<<"safe"<<endl;
    else
        cout<<"dangerous"<<endl;

    return 0;
}

Measured memory_bytes: 256
import math


K = int(input())

ans = 0
for i in range(1, K + 1):
    for j in range(1, K + 1):
        if i == j:
            continue
        ans += math.gcd(i, j)


ans = ans * 3

for i in range(1, K + 1):
    ans += i

six = 0
for i in range(1, K - 1):
    for j in range(i + 1, K):
        for k in range(j + 1, K + 1):
            tmp = math.gcd(i, j)
            six += math.gcd(tmp, k)
            
ans = ans + six * 6
print(ans)


Measured memory_bytes: 68120
H,W = map(int,input().split())
alt = []
if H%3==0 or W%3==0:
    print(0)
elif H==2 or W == 2:
    print(1)
else:
    S1 = (H//3)*W
    S2 = (H-(H//3))*(W//2)
    S3 = H*W-S1-S2
    alt.append([S1,S2,S3])
    S1 = ((H//3)+1)*W
    S2 = (H-(H//3)-1)*(W//2)
    S3 = H*W-S1-S2
    alt.append([S1,S2,S3])
    S1 = (W//3)*H
    S2 = (W-(W//3))*(H//2)
    S3 = H*W-S1-S2
    alt.append([S1,S2,S3])
    S1 = ((W//3)+1)*H
    S2 = (W-(W//3)-1)*(H//2)
    S3 = H*W-S1-S2
    alt.append([S1,S2,S3])
    if H%3==1:
        S1 = W*(H//3)
        S2 = W*(H//3)
        S3 = W*((H//3)+1)
    else:
        S1 = W*(H//3)
        S2 = W*((H//3)+1)
        S3 = W*((H//3)+1)
    alt.append([S1,S2,S3])
    if W%3==1:
        S1 = H*(W//3)
        S2 = H*(W//3)
        S3 = H*((W//3)+1)
    else:
        S1 = H*(W//3)
        S2 = H*((W//3)+1)
        S3 = H*((W//3)+1)
    alt.append([S1,S2,S3])
    print(min([max(i)-min(i) for i in alt]))

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

int sx, sy;
int tx, ty;
// ans = 2*2*(tx-sx+1)+(ty-sy+1)
int main(){
    cin >> sx >> sy;
    cin >> tx >> ty;

    int dx = tx - sx;
    int dy = ty - sy;

    // first cycle
    for(int i = 0; i < dx; i++) cout << "R";
    for(int i = 0; i < dy; i++) cout << "U";
    for(int i = 0; i < dx; i++) cout << "L";
    for(int i = 0; i < dy+1; i++) cout << "D";

    // second cycle
    for(int i = 0; i < dx+1; i++) cout << "R";
    for(int i = 0; i < dy+1; i++) cout << "U";
    cout << "LU";
    for(int i = 0; i < dx+1; i++) cout << "L";
    for(int i = 0; i < dy+1; i++) cout << "D";
    cout << "R";

    return 0;
}

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

void Main() {
  long long n, a, b;
  cin >> n >> a >> b;

  long long ans = n / (a + b) * a;
  long long amari = n % (a + b);
  if (amari <= a) ans += amari;
  else ans += a;
  cout << ans << endl;
}

int main() {
  std::cin.tie(nullptr);
  std::ios_base::sync_with_stdio(false);
  std::cout << std::fixed << std::setprecision(15);
  Main();
  return 0;
}


Measured memory_bytes: 256
import java.util.*;

import static java.lang.System.*;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        int M = sc.nextInt();

        PriorityQueue<Entry> pq = new PriorityQueue<Entry>(N, new EntryComparator());
        for (int i = 0; i < M; i++) {
            Entry entry = new Entry(sc.nextInt(), sc.nextInt());
            pq.add(entry);
        }

        Entry entry = pq.poll();
        int maxB = entry.b;

        int ans = 1;
        while(!pq.isEmpty()){
            entry = pq.poll();
            if(entry.a >= maxB){
                ans++;
                maxB = entry.b;
            } else {
                maxB = Math.min(entry.b, maxB);
            }
        }

        out.println(ans);
    }

    // 昇順
    static class EntryComparator implements Comparator<Entry> {
        @Override
        public int compare(Entry t1, Entry t2) {
            if (t1.a >= t2.a){
                return 1;
            }
            return -1;
        }
    }

    static class Entry {
        public int a;
        public int b;

        public Entry(int a, int b){
            this.a = a;
            this.b = b;
        }
    }
}


Measured memory_bytes: 87796
S[1<<17],T[1<<17];
a,b,c;
main(d){
	for(scanf("%S%S%*d",S+1,T+1);S[d]|T[d];++d)
		S[d]=S[d-1]+S[d]%4,
		T[d]=T[d-1]+T[d]%4;
	for(;~scanf("%d%d%d%d",&a,&b,&c,&d);)
		puts((S[b]-S[a-1]-T[d]+T[c-1])%3?"NO":"YES");
}

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

typedef long long ll;

int main() {
    ll h, w, m;
    cin >> h >> w >> m;
    vector<pair<int, int>> bombs(m);
    vector<int> h_count(h), w_count(w);
    for (ll i = 0; i < m; i++) {
        ll hi, wi;
        cin >> hi >> wi;
        hi--;
        wi--;
        bombs[i] = {hi, wi};
        h_count[hi]++;
        w_count[wi]++;
    }
    vector<int> h_orig = h_count, w_orig = w_count;
    sort(h_count.begin(), h_count.end());
    sort(w_count.begin(), w_count.end());
    ll h_max = h_count[(int)h_count.size()-1];
    ll w_max = w_count[(int)w_count.size()-1];
    ll h_len = h_count.end() - lower_bound(h_count.begin(), h_count.end(), h_max);
    ll w_len = w_count.end() - lower_bound(w_count.begin(), w_count.end(), w_max);
    ll c = 0;
    for (ll i = 0; i< m; i++) {
        auto p = bombs[i];
        if (h_orig[p.first] + w_orig[p.second] == h_max + w_max)
            c++;
    }
    if (c < h_len * w_len)
        cout << h_max + w_max;
    else
        cout << h_max + w_max - 1;
    return 0;
}

Measured memory_bytes: 10376
#include<stdio.h>

const int N = 100+2;
char a[N][N];
int w,h;
const char INVALID_CHAR = '_';

void destroj(int i,int j, char c)
{
	if(i<0 || j<0 || i>=h || j>= w)
		return;
	if(a[i][j] != c)
		return;
	a[i][j] = INVALID_CHAR;

	const int di[] = {-1,1,0,0};
	const int dj[] = {0,0,1,-1};
	for(int index = 0; index < 4; ++index)
		destroj(i+di[index],j+dj[index],c);
}

int main(void)
{
	int i,j;
	while(scanf("%d%d", &h,&w),h)
	{
		for(i = 0; i < h; ++i)
			scanf("%s",a[i]);
		int v = 0;
		for(i = 0; i < h; ++i)
			for(j = 0; j < w; ++j)
			{
				if(a[i][j] != INVALID_CHAR)
				{
					destroj(i,j,a[i][j]);
					++v;
				}
			}
		printf("%d\n",v);
	}
	return 0;
}

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

int main()
{
    int n, k;
    cin >> n >> k;
    vector<int> f(n);
    for (int i = 0; i < n; i++)
    {
        cin >> f[i];
    }
    sort(f.begin(), f.end());
    int ans = 0;
    for (int i = 0; i < k; i++)
    {
        ans += f[i];
    }
    cout << ans << endl;
}

Measured memory_bytes: 3596
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using Edge = pair<int, int>;
using Graph = vector<vector<Edge>>;
#define REP(i, n) for (int i = 0; i < (n); ++i)
#define SORT(v) sort((v).begin(), (v).end())
#define RSORT(v) sort((v).rbegin(), (v).rend())
const ll MOD = 1000000007;
const ll nmax = 8;
const ll INF = 1e9;
bool graph[nmax][nmax];
vector<vector<ll>> dist = vector<vector<ll>>(nmax, vector<ll>(nmax, INF));
void warshall_floyd(ll n)
{
    for (size_t i = 0; i < n; i++)
    {
        for (size_t j = 0; j < n; j++)
        {
            for (size_t k = 0; k < n; k++)
            {
                dist[j][k] = min(dist[j][k], dist[j][i] + dist[i][k]);
            }
        }
    }
}

class UnionFind
{
public:
    vector<ll> Parent;

    UnionFind(ll N)
    {
        Parent = vector<ll>(N, -1);
    }
    ll find(ll A)
    {
        if (Parent[A] < 0)
            return A;
        return Parent[A] = find(Parent[A]);
    }

    ll size(ll A)
    {
        return -Parent[find(A)];
    }

    bool Union(ll A, ll B)
    {
        A = find(A);
        B = find(B);
        if (A == B)
        {
            return false;
        }
        if (size(A) < size(B))
            swap(A, B);

        Parent[A] += Parent[B];
        Parent[B] = A;

        return true;
    }
};

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

ll lcm(ll a, ll b)
{
    ll g = gcd(a, b);
    return a / g * b;
}

ll mulMod(ll a, ll b)
{
    return (((a % MOD) * (b % MOD)) % MOD);
}

ll powMod(ll a, ll p)
{
    if (p == 0)
    {
        return 1;
    }
    else if (p % 2 == 0)
    {
        ll half = powMod(a, p / 2);
        return mulMod(half, half);
    }
    else
    {
        return mulMod(powMod(a, p - 1), a);
    }
}

ll ceil(ll a, ll b)
{
    return (a + b - 1) / b;
}
vector<bool> prime(100010, true);
vector<ll> ruiseki(100010, 0);

void solve(long long Q, std::vector<long long> l, std::vector<long long> r)
{
    for (int i = 2; i <= 100000; i++)
    {
        if (prime[i])
        {
            for (int j = i + i; j <= 100000; j += i)
            {
                prime[j] = false;
            }
        }
    }

    for (int i = 3; i <= 100000; i++)
    {
        if (prime[i] && prime[(i + 1) / 2])
        {
            ruiseki[i]++;
        }
    }

    for (int i = 3; i <= 100000; i++)
    {
        ruiseki[i] += ruiseki[i - 1];
    }

    for (int i = 0; i < Q; i++)
    {
        cout << ruiseki[r[i]] - ruiseki[l[i] - 1] << endl;
    }
}

int main()
{
    long long Q;
    scanf("%lld", &Q);
    std::vector<long long> l(Q);
    std::vector<long long> r(Q);
    for (int i = 0; i < Q; i++)
    {
        scanf("%lld", &l[i]);
        scanf("%lld", &r[i]);
    }
    solve(Q, std::move(l), std::move(r));
    return 0;
}


Measured memory_bytes: 2944
#include <bits/stdc++.h>
#include <math.h>
#define _GLIBCXX_DEBUG
#define _LIBCPP_DEBUG 0

using namespace std;
#define ll long long
#define rep(i,n) for (int i = 0; i < n; i++)
#define rrep(i,n) for (int i = n-1; i >= 0; i--)
#define MOD (1000000007)
#define vi vector<int>
#define vl vector<ll>
#define vb vector<bool>
#define vvi vector<vi>
#define vvl vector<vl>
#define pii pair<int, int>
#define pli pair<ll, int>a
#define pb push_back
#define sz(x) int(x.size())

#define mp make_pair
#define all(a) (a).begin(),(a).end()

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

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

ll keta(ll n){
  string s = to_string(n);
  ll num = s.size();
  return num;
}

const ll INF = 1LL << 60;

const int dh[4] = {1,0,-1,0};
const int dw[4] = {0,1,0,-1};

struct Edge{
  int to;
  int weight;
  Edge(int t, int w) : to(t), weight(w){}
};
using Graph = vector<vector<Edge>>;
using P = pair<ll, int>;

class UnionFind{
public:
  vi Parent;
  UnionFind(int n){
    Parent = vi(n,-1);
  }

  int root(int a){
    if(Parent[a] < 0) return a;
    else return Parent[a] = root(Parent[a]);
  }

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

  bool merge(int a, int b){
    a = root(a);
    b = root(b);
    if(a == b) return false;

    if(size(a) < size(b)) swap(a,b);
    Parent[a] += Parent[b];
    Parent[b] = a;

    return true;
  }
};

class Factrial{
public:
  vl Fac;
  Factrial(int MAX){
    Fac = vl(MAX+1);
    rep(i,MAX) {
      if(i == 0) Fac[i+1] = 1;
      else Fac[i+1] = ((i+1)*Fac[i])%MOD;
    }
  }
};

int main(){
  int n,m; cin >> n >> m;
  vi p(m); vector<string> s(m);
  rep(i,m) cin >> p[i] >> s[i];
  rep(i,m) p[i]--;
  vector<pair<bool, int>> AC(n,mp(false,0));
  rep(i,m) {
    if(s[i] == "AC") AC[p[i]].first = true;
    else{
      if(!AC[p[i]].first) AC[p[i]].second++;
    }
  }
  int ans = 0;
  int WA = 0;
  rep(i,n){
    if(AC[i].first){
      ans++;
      WA += AC[i].second;
    }
  }

  cout << ans << " " << WA << endl;
}

Measured memory_bytes: 6912
using System;

namespace C___Divide_the_Problems
{
    class Program
    {
        static void Main (string[] args)
        {
            var n = int.Parse (Console.ReadLine ());
            var input = Console.ReadLine ().Split (' ');
            var d = new int[n];
            for (var i = 0; i < n; i++)
            {
                d[i]=int.Parse (input[i]);
            }
            Array.Sort(d);
            Console.WriteLine (d[n / 2] - d[n / 2 - 1]);
        }
    }
}

Measured memory_bytes: 18912
#define _USE_MATH_DEFINES
#include <iostream>
#include <string>
#include <list>
#include <vector>
#include <queue>
#include <algorithm>
#include <climits>
#include <cstring>
#include <cmath>
#include <stack>
#include <iomanip>
#include <tuple>
#include <functional>

#define int long long
#define CONTAINS(v,n) (find((v).begin(), (v).end(), (n)) != (v).end())
#define SORT(v) sort((v).begin(), (v).end())
#define RSORT(v) sort((v).rbegin(), (v).rend())
#define ARY_SORT(a, size) sort((a), (a)+(size))
#define MAX(a,b) (((a) > (b)) ? (a) : (b))
#define MIN(a,b) (((a) < (b)) ? (a) : (b))
#define REMOVE(v,a) v.erase(remove(v.begin(), v.end(), a), v.end())
#define REP(i,n) for (int (i) = 0; (i) < (n); (i)++)
using namespace std;

int N, M;
vector<int> lr[301];
vector<int> xs[301];

int dp[301][301][301];

int mod = 1000000007;

int func(int r, int g, int b)
{
	if (dp[r][g][b] >= 0)
	{
		return dp[r][g][b];
	}

	int max = MAX(r, MAX(g, b));

	int size = lr[max].size();
	for (int i = 0; i < size; i++)
	{
		int l = lr[max][i];
		int x = xs[max][i];
		int cnt = (r >= l) + (g >= l) + (b >= l);
		REP(j, 3)
		{
			if (x == j + 1)
			{
				if (cnt != x)
				{
					dp[r][g][b] = 0;
					return 0;
				}
			}
		}
	}

	if (max == N)
	{
		dp[r][g][b] = 1;
		return 1;
	}

	int sum = 0;
	sum += func(max + 1, g, b);
	sum += func(r, max + 1, b);
	sum += func(r, g, max + 1);
	sum %= mod;
	dp[r][g][b] = sum;
	return sum;
}

signed main()
{
	cin >> N >> M;
	REP(i, M)
	{
		int l, r, x;
		cin >> l >> r >> x;
		lr[r].push_back(l);
		xs[r].push_back(x);
	}

	memset(dp, -1, sizeof(dp));

	cout << func(0, 0, 0) << endl;
}

Measured memory_bytes: 213376
#include <iostream>
#include <cmath>
#include <algorithm>
#include <string> //文字列
#include <iomanip> //doubleの桁数指定 setprecision()
#include <list> //前後に数値を入れれる配列
#include <map> //map
#include <vector> //vecror

#define REP(i,m,n) for(ll i = (ll) (m);i < (ll) (n);i++) //forの短縮
#define rep(i,n) REP(i,0,n) //REPが0の時
#define ll long long int

using namespace std;

double PI = acos(-1); //円周率
ll mod = 1e9 + 7;


//提出コード↓

ll n;
bool J = false;

int main() {
	cin >> n;
	
	while (n) {
		if (n % 10 == 7) J = true;
		n /= 10;
	}
	if (J) cout << "Yes" << endl;
	else cout << "No" << endl;

	
	return 0;
}



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

int main(){
    string s;
    cin>>s;
    int N = s.size();

    vector<ll> val(2019,0);
    ll kake = 1;
    ll cur = 0;
    ll mod = 2019;

    val[cur]++;

    for(int i=0; i<N; i++){
        cur = (cur + (s[N-1-i] - '0') * kake )% mod;
        kake = (kake*10) % mod;
        val[cur]++;
    }

    ll ans = 0;

    for(int i = 0; i<mod; i++) ans += val[i]*(val[i]-1)/2;

    cout<<ans<<endl;

    return 0;
}

Measured memory_bytes: 3740
#include<bits/stdc++.h>
using namespace std;
#define F(i,s,e) for(int i=s;i<e;++i)

int main()
{
    int n;
    cin >> n;
    string s,t;
    cin >> s >> t;
    string a;
    F(i,0,n){
        a+=s[i];
        a+=t[i];
    }
    cout << a << endl;
    return 0;
}

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

int main() {
    long long H, W;
    cin >> H >> W;

    if(H == 1 || W == 1) {
        cout << 1 << endl;
    } else {
        cout << (H * W + 1) / 2 << endl;
    }

}


Measured memory_bytes: 256
N = int(input())
A = list(map(int, input().split()))
B = [A[0]]

for a in A:
    if B[-1] != a:
        B.append(a)

N = len(B)
ans = 1
prev = -1
for i in range(1, N - 1):
    if B[i - 1] < B[i] and B[i + 1] < B[i]:
        if i - prev > 1:
            ans += 1
            prev = i
    elif B[i - 1] > B[i] and B[i + 1] > B[i]:
        if i - prev > 1:
            ans += 1
            prev = i

print(ans)

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

int main()
{
    stack<int> s1;
    stack<pair<int, int> > s2;
    char c;
    int ans = 0;

    for (int i = 0; cin >> c; i++)
    {
        if (c == '\\')
        {
            s1.push(i);
        }
        else if (c == '/' && s1.size() > 0)
        {
            int j = s1.top();
            s1.pop();
            int a = i - j;
            ans += a;
            while (s2.size() > 0 && s2.top().first > j)
            {
                a += s2.top().second;
                s2.pop();
            }
            s2.push(pair<int, int>(j, a));
        }
    }

    cout << ans << endl;
    int ary[s2.size()];
    int size = s2.size();
    cout << size;
    for (int i = 0; i < size; i++)
    {
        ary[i] = s2.top().second;
        s2.pop();
    }

    for (int i = 1; i <= size; i++)
    {
        cout << ' ';
        cout << ary[size - i];
    }
    cout << endl;
}


Measured memory_bytes: 3188