akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include<algorithm>
#include<vector>
#include<string>
#include<cmath>
#include<cstdio>
#include<queue>
#include<deque>
#include<map>
using namespace std;
typedef pair<int,int> ii;
typedef long long ll;
typedef pair<ll,ll> pll;
const int INF=1e9;
const ll MOD=1e9+7;

ll gcd(ll x,ll y){
    if(y==0) return 0;
    return gcd(y,x%y);
}

int dis2(int x1,int y1,int x2,int y2){
    return (x1-x2)*(x1-x2)+(y1-y2)*(y1-y2);
}

int main(){
    int n;cin>>n;
    vector<int> d(n);
    map<int,int> cnt;
    for(int i=0;i<n;i++){
        cin>>d[i];
        cnt[d[i]]++;
    }
    int m;cin>>m;
    int t;
    for(int i=0;i<m;i++){
        cin>>t;
        if(cnt[t]==0){
            cout<<"NO"<<endl;
            return 0;
        }else cnt[t]--;
    }
    cout<<"YES"<<endl;
    return 0;
}

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

#define ll long long
#define endl "\n"

int main ()
{

	ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    #define int ll
    //freopen("input.txt", "r", stdin); 
    //freopen("output.txt", "w", stdout);
	
	int ans = 0;
	map <int, int> mp;
	
	mp[1] = 300000;
	mp[2] = 200000;
	mp[3] = 100000;
	
	int a, b;
	cin >> a >> b;
	
	ans = mp[a] + mp[b];
	
	if (a == 1 and b == 1){
		ans += 400000;
	}
	
	cout << ans << endl;
			
	return 0;

}

Measured memory_bytes: 3668
import java.util.*;
public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int a = sc.nextInt();
        int b = sc.nextInt();
        int c = sc.nextInt();
        if (a < b) {
            if (b < c) {
                System.out.println("Yes");
            }
            else
                System.out.println("No");
        }
        else
            System.out.println("No");
    }
}


Measured memory_bytes: 26388
import           Control.Applicative
import           Control.Monad

solve :: [(Int, Char)]
      -> [(Int, Int)]
      -> [(Int, Char)]
      -> [Int]
solve _ ps [] = fmap snd (reverse ps)
solve ds ps (x@(n, '\\'):xs) = solve (x : ds) ps xs
solve [] ps (x@(n, '/'):xs) = solve [] ps xs
solve ((m, _):ds) ps (x@(n, '/'):xs) = solve ds (newp : pr) xs
  where
    (pl, pr) = span ((>= m) . fst) ps
    newp = (n, (n - m) + sum (fmap snd pl))
solve ds ps (x:xs) = solve ds ps xs

main :: IO ()
main = do
    xs <- getLine
    let areas = solve [] [] (zip [0 ..] xs)
    print $ sum areas
    putStrLn . unwords $ fmap show (length areas : areas)



Measured memory_bytes: 8144
#include<stdio.h>
int main()
{
  int a,b,r,c;

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

  if(a < b){
    c = a;
    a = b;
    b = c;  
  }
  
  r = a % b;
  
  while(r!=0){
    a = b;
    b = r;
    r = a % b;
  }

  printf("%d\n",b);
  
  return 0;
}
  

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

namespace ABC075
{
    class C
    {
        static bool[] visited;
        static bool[,] connect;
        static int N;
        static int M;
        static void Main(string[] args)
        {
            int[] input = Console.ReadLine().Split().Select(int.Parse).ToArray();
            N = input[0];
            M = input[1];

            connect = new bool[N, N];
            visited = new bool[N];

            int[] a = new int[M];
            int[] b = new int[M];
            for (int i = 0; i < M; i++)
            {
                input = Console.ReadLine().Split().Select(int.Parse).ToArray();
                a[i] = input[0] - 1;
                b[i] = input[1] - 1;
                connect[a[i], b[i]] = true;
                connect[b[i], a[i]] = true;
            }

            int res = 0;
            for (int i = 0; i < M; i++)
            {
                connect[a[i], b[i]] = false;
                connect[b[i], a[i]] = false;
                for (int j = 0; j < N; j++) visited[j] = false;

                dfs(0);

                bool bridge = false;
                for (int j = 0; j < N; j++)
                {
                    if (visited[j] == false) bridge = true;
                }
                if (bridge) res++;

                connect[a[i], b[i]] = true;
                connect[b[i], a[i]] = true;
            }
            Console.WriteLine(res);
        }

        static void dfs(int n)
        {
            visited[n] = true;
            for (int i = 0; i < N; i++)
            {
                if (connect[n, i] == false) continue;
                if (visited[i] == true) continue;
                dfs(i);
            }
        }
    }
}


Measured memory_bytes: 13396
import java.util.*;
import java.lang.*;
import java.io.*;
public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        String s = sc.next();
        int N = s.length();
        //AtCoDeer should play "Paper" as much as possible
        int score = 0;
        for(int n=0;n<N;n++){
        	int atHand = (n%2==0) ? 0 : 1;
        	int topHand = (s.charAt(n)=='g') ? 0 : 1;
        	score += (atHand-topHand);
        }
        System.out.println(score);
    }
}


Measured memory_bytes: 26768
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <math.h>
using namespace std;

unsigned GetDigit(unsigned num){
    return std::to_string(num).length();
}
long long int fact(long long int k){
    if(k==1) return 1;
    else return fact(k-1)*10;
}
int main()
{
    long long int N;
    long long int A[10][10];
    cin >> N;
    
    for(int i=1; i<=9; i++){
        for(int j=1; j<=9; j++){
            A[i][j] = 0;
        }
    }
    
    long long int digit;
    long long int div;
    for(long long int i=1; i<=N; i++){
        digit = GetDigit(i);
        div = fact(digit);
//        cout << "div:" << div << endl;;
        A[i/div][i%10]++;
    }
//    if(N >= 9){
//        for(int i=1; i<=9; i++){
//            A[i][i]++;
//        }
//    }
//    else{
//        for(int i=1; i<=N; i++){
//            A[i][i]++;
//        }
//    }
    
    
    long long int count=0;
    for(int i=1; i<=9; i++){
        for(int j=1; j<=9; j++){
//            cout << i << " " << j << " " << A[i][j] << endl;
            count += A[i][j] * A[j][i];
        }
    }

    cout << count << endl;
    return 0;
}


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

using namespace std;
using ll = long long;

int const N = 200 * 1000 + 16;

int a[N];
int n, k;

struct node {
  ll x;
  int s = 1;
  int y = rand();

  node* l = 0;
  node* r = 0;

  node(ll v) {
    x = v;
  }

  ~node() {
    delete l;
    delete r;
  }

  node* upd() {
    s = 1;
    s += l ? l->s : 0;
    s += r ? r->s : 0;
    return this;
  }
};

struct treap {
  node* root = 0;

  ~treap() {
    delete root;
  }

  node* join(node* l, node* r) {
    if(not l) return r;
    if(not r) return l;

    if(l->y < r->y) {
      l->r = join(l->r, r);
      return l->upd();
    } else {
      r->l = join(l, r->l);
      return r->upd();
    }
  }

  pair<node*,node*> split(node* p, ll x) {
    if(not p) return make_pair(nullptr,nullptr);

    if(x < p->x) {
      auto t = split(p->l, x);
      p->l = t.second;
      t.second = p->upd();
      return t;
    } else {
      auto t = split(p->r, x);
      p->r = t.first;
      t.first = p->upd();
      return t;
    }
  }

  void insert(ll x) {
    auto t = split(root, x);
    root = join(t.first, join(new node(x), t.second));
  }

  int query(ll x) {
    auto t = split(root, x);
    int cnt = t.first ? t.first->s : 0;
    root = join(t.first, t.second);
    return cnt;
  }
};

int main() {
  cin.tie(0);
  cin.sync_with_stdio(0);

  cin >> n >> k;
  copy_n(istream_iterator<int>(cin), n, a);

  treap t;
  t.insert(0);
  ll ans = 0;
  ll sum = 0;
  for(int i = 0; i < n; ++i) {
    sum += a[i];
    ll v = sum - 1ll * i * k - k;
    ans += t.query(v);
    t.insert(v);
  }

  cout << ans << endl;
}

Measured memory_bytes: 10368
#coding : utf8

"""
@param {int}
@return {bool}
"""
def calcDistance(a,b,c,d):

    if( abs(a-c) <= d ):
        return True
    elif( abs(a-b) <= d and abs(b-c) <= d ):
        return True
    else:
        return False

if __name__ == '__main__':
    a,b,c,d = map(int, input().split())

    if(calcDistance(a,b,c,d)):
        print("Yes")
    else:
        print("No")


Measured memory_bytes: 3060
from collections import *
import sys
inp = raw_input

def err(s):
    sys.stderr.write('{}\n'.format(s))

def ni():
    return int(inp())

def nl():
    return [int(_) for _ in inp().split()]

N = ni()
A = nl()

out = [0]*N
fail = False
B = []
for i in range(N-1, -1, -1):
    j = i + 1
    S = 0
    for k in range(i, N, j):
        S += out[k]
    if S%2 != A[i]:
        out[i] = 1
        B.append(j)
print(len(B))
if len(B):
    print(' '.join(map(str, B)))



Measured memory_bytes: 27340
#include <iostream>
#include <algorithm>
#include <string>
#include <string.h>
#include <stdlib.h>
#include <math.h>
#include <vector>
#include <queue>
#include <stack>
#include <cmath>
#include <map>
#include <iomanip>
#include <set>
using namespace std;

#define rep(i, s) for (int i = 0; i < s; ++i)
#define all(v) (v.begin(), v.end())
#define COUT(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << endl
#define EACH(i, s) for (__typeof__((s).begin()) i = (s).begin(); i != (s).end(); ++i)
#define VEC(a, n) vector<int>a(n)
#define PQ(a) priority_queue<int>a
#define PQmin(a) priority_queue< int, :vector<int>, greater<int> >a
#define PAIR pair<int, int>
/*
sort(sp.begin(), sp.end(), [](PAIR l, PAIR r){
        return l.first<r.first || (l.first==r.first && l.second > r.second);
        });
*/

typedef long long  ll;

#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))

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

int main() {
    int n,w;
    cin>>n>>w;
    vector<int>a(n);//重さ
    vector<int>b(n);//価値
    int val = 0;
    for(int i=0;i<n;i++){
        int x,y;
        cin>>x>>y;
        a.at(i)=x;
        b.at(i)=y;
        val+=b.at(i);
    }
    vector<vector<int> >dp(n+1,vector<int>(val+10));
    for(int i=0;i<n+1;i++){
        for(int j=0;j<=val;j++){
            dp.at(i).at(j)=INF;
        }
    }
    dp.at(0).at(0)=0;
    for(int i=0;i<n;i++){
        for(int j=0;j<=val;j++){
            if(j-b.at(i)>=0){
                if(dp.at(i).at(j-b.at(i)) + a.at(i) <= w){
                    chmin(dp.at(i+1).at(j),dp.at(i).at(j-b.at(i)) + a.at(i));
                }
            }
            chmin(dp.at(i+1).at(j),dp.at(i).at(j));
        }
    }
    int ans=0;
    for(int i=0;i<n+1;i++){
        for(int j=0;j<=val;j++){
            if(dp.at(i).at(j)<=w){
                ans=max(ans,j);
            }
        }
    }
    cout<<ans<<endl;
    // for(int i=0;i<n+1;i++){
    //     for(int j=0;j<=val;j++){
    //         cout<<dp.at(i).at(j);
    //     }
    //     cout<<endl;
    // }





    return 0;
}


Measured memory_bytes: 40192
/*
Character Drawing Adapted from FAKEUPDATE.NET
		   _    _____         _
		   \`,""   ,'7"r-..__/ \
		  ,'\ `, ,',','    _/   \
		 /   \, 7 / /     (   \ |
		J     \/ j  L______\  / |
		L   __JF"""/""\"\_,    /
		L,-"| O|  f O |  L_  _/
		F   \_ /  \__/   `-  j|
			.-'    `"""    ,' |          _..====.._
			\__/         r"_  A        ,' _..---.._`,
			 `-.______,,-L// / \  ___,' ,'_..:::.. `,`,
					  j   / / / 7"    `-<""=:'  '':. \ \
					 /   <,' /  F  . i , \   `,    :T W I
					 |    \,'  /    >X<  |     \   :| | L
					 |     `._/    ' ! ` |      I  :| |  G
					  \           \     /       |  :H T  |
					 __>-.__   __,-\   |        |  S P   |
					/     /|   | \  \  \_       | 'A R   |
				   /   __/ |   |  L  L   \      K./ /    L
				  /   |    |   4  I  I    |    E./ /   ,'
				 J    \    I    L F  I    |    // / _,'
		_________|     |   F    |J   F    |   //_/-'
		\   __   |    /   J     |/  J     |  /="
		\\  \_\  \__,' \  F     |   F     |
		\\\_____________\/      F__/      F
		 \\| 计算机编程 |_____/  (______/
		  \/从入门到入土/
*/
#include <iostream>
#include <cstdlib>
#include <iomanip>
#include <cmath>
#include <string>
#include <cstring>
#include <algorithm>
#include <vector>
#include <sstream>
#include <set>
#include <queue>
#include <stack>
#include <cctype>
#include <map>
#include <climits>
#include <bitset>
#include <functional>
using namespace std;
#define MATH_PI 3.14159265358979323846
int main(){
	ios::sync_with_stdio(false);
	string sInput;
	int i;
	cin >> sInput;
	for (i = 1; i <= sInput.length(); ++i){
		if (i % 2 != 0)
			cout << sInput[i - 1];
	}
	cout << endl;
endapp:
	//system("pause > nul");
	return 0;
}

Measured memory_bytes: 592
#include "bits/stdc++.h"
#include <iostream>
#include <string.h>
#include <stdio.h>
#include <map>
#include <vector>
#include <math.h>
#include <algorithm>
#include <queue>
#include <set>
#include <tuple>
using namespace std;

#define FOR(i,init,a) for(int i=init; i<a; i++)
#define rep(i,a) FOR(i,0,a)
#define rrep(i,a) for(int i=a; i>=0; i--)
#define rep1(i,a) for(int i=1; i<=a; i++)
#define cout1(a) cout << a << endl;
#define cout2(a,b) cout << a << " " << b << endl;
#define cout3(a,b,c) cout << a << " " << b << " " << c << endl;
#define cout4(a,b,c,d) cout << a << " " << b << " " << c << " " << d << endl;
#define mem(a,n) memset( a, n, sizeof(a))
#define all(a) a.begin(),a.end()
#define chmin(a,b) a=min(a,b);
#define chmax(a,b) a=max(a,b);

typedef long long ll;
typedef long double ld;
typedef pair<int,int> pii;
typedef vector<int> V;
typedef vector<V> VV;
typedef vector<VV> VVV;
const int INF = 1e9;
const int MOD = 1e9+7;
const ll LLINF = 1e18;
static const double pi = 3.141592653589793;

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    int N;
    cin>>N;
    
    int ans=N,mx=0;
    for(int i=N;i>0;i--){
        int tmp=i,cnt=0;
        while(tmp%2==0) tmp/=2,cnt++;
        if(mx<cnt) mx=cnt,ans=i;
    }
    cout1(ans)
}

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

#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define rep(i,n) FOR(i,0,n)
#define f first
#define s second
#define pb push_back
#define mp make_pair
#define INF 1000000000000000
#define MAX (int)(1e6)+1
#define MOD 1000000007

using namespace std;

typedef long long int lli;
typedef pair<int,int> pii;
typedef pair<lli,int> pwi;
typedef pair<lli,lli> plli;
typedef vector<int> vi;
typedef vector<lli> vlli;
typedef vector< vector<pair<int,lli > > > wGraph;
typedef vector<vector<int> > graph;
//typedef vector<vector<int> > matrix;

int main(){

    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout<<std::fixed;
    cout<<std::setprecision(2);

    int n,m;
    cin>>n>>m;

    vi cards(n+1,0);
    rep(i,m){
        int a,b;
        cin>>a>>b;
        cards[a-1]++;
        cards[b]--;
    }

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


    int res = 0;
    rep(i,n){
        if(cards[i] >= m) res++;
    }

    cout<<res<<endl;

    return 0;

}


Measured memory_bytes: 640
n, k = map(int, input().split())
his = list(map(int, input().split()))
his_sort = sorted(his)
an = 0
if k > 0:
  for i in range(k):
    his_sort.pop()
    if len(his_sort) == 0:
      break
if len(his_sort) > 0:
  for j in range(n - k):
    an += his_sort[j]
print(an)


Measured memory_bytes: 26764
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  double A, B, C;
  int D;
  cin >> A >> B;
  C = (A + B)/2;
  D = (int)C;
  if ( C-D != 0 ) {
    D = D + 1;
  }
  cout << D << endl;
}

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

from collections import Counter
d = []

for _ in range(n):
    a,b = map(int,input().split())
    for k in range(3):
        for l in range(3):
            if 0 < a-k < h-1 and 0 < b-l < w-1:
                d.append((a-k,b-l))

dd = Counter(d)
ddd = list(dd.values())

ans = [0]*10

for i in range(1,10):
    ans[i] = ddd.count(i)

ans[0] = (h-2)*(w-2) - sum(ans)

for x in ans:
    print(x)

Measured memory_bytes: 159808
#include <iostream>
#include <string>
#include <queue>
#include <utility>
#include <algorithm>
#include <numeric>
#include <set>
#include <climits>
#include <map>

using namespace std;

string grid[100];

int main(){
  int H;
  int W;

  map <char, int> char_counts;
  cin >> H >> W;
  for(int i = 0; i < H; i++){
    cin >> grid[i];
  }

  for(int i = 0; i < H; i++){
    for(int j = 0; j < W; j++){
      if(char_counts.find(grid[i][j]) == char_counts.end()){
        char_counts[grid[i][j]] = 1;
      } else {
        char_counts[grid[i][j]] ++;
      }
    }
  }

  int odd_count = 0;
  int two_mod_count = 0;
  for(auto it = char_counts.begin(); it != char_counts.end(); it++){
    char_counts[it->first] %= 4;
    if(char_counts[it->first] % 2 != 0){
      odd_count ++;
    }
    if(char_counts[it->first] == 2 || char_counts[it->first] == 3){
      two_mod_count ++;
    }
  }

  if(H % 2 == 0 && W % 2 == 0){
    if(odd_count > 0 || two_mod_count > 0){
      cout << "No" << endl;
    } else {
      cout << "Yes" << endl;
    }
  } else if(H % 2 == 1 && W % 2 == 0){
    if(odd_count > 0 || two_mod_count > W / 2){
      cout << "No" << endl;
    } else {
      cout << "Yes" << endl;
    }
  } else if(H % 2 == 0 && W % 2 == 1) {
    if(odd_count > 0 || two_mod_count > H / 2){
      cout << "No" << endl;
    } else {
      cout << "Yes" << endl;
    }
  } else {
    if(odd_count != 1 || two_mod_count > W / 2 + H / 2){
      cout << "No" << endl;
    } else {
      cout << "Yes" << endl;
    }
  }

  return 0;
}


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

fn main() {
  let input = {
    let mut buf = vec![];
    stdin().read_to_end(&mut buf);
    unsafe { String::from_utf8_unchecked(buf) }
  };
  let mut lines = input.split('\n');

  let (n, m) = {
    let line = lines.next().unwrap();
    let mut iter = line.split(' ').map(|s| s.parse::<usize>().unwrap());

    (iter.next().unwrap(), iter.next().unwrap())
  };

  let mut list: Vec<(u32, u32)> = lines.by_ref().take(n)
    .map(|l| (l.parse().unwrap(), 0)).collect();

  for line in lines.take(m) {
    let b = line.parse().unwrap();
    let &mut (_, ref mut n) = list.iter_mut().find(|&&mut (i, _)| i <= b).unwrap();
    *n += 1;
  }

  let (i, _) = list.into_iter().enumerate()
    .max_by_key(|&(_, (_, n))| n).unwrap();

  println!("{}", i + 1);
}



Measured memory_bytes: 5028
#include <algorithm>
#include <iostream>
#include <vector>

using namespace std;

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

	vector<int> lines;
	for(int i = 1; i <= w; i++)
		lines.push_back(i);

	int n;
	cin >> n;

	for(int i = 0; i < n; i++)
	{
		int a, b;
		scanf("%d,%d", &a, &b);
		swap(lines[a-1], lines[b-1]);
	}

	for(auto line : lines)
		cout << line << endl;

	return 0;
}

Measured memory_bytes: 1252
import java.util.*;
public class Main {
    public static void main(String[] args) throws java.io.IOException{
        Scanner scan = new Scanner(System.in);
        int n= scan.nextInt();
        int out =0;
        int point=0;
        int runner=0;
        while(true){
        	if(n==0)break;
        	String input =scan.next();
        	if(input.equals("HIT")){runner++;if(runner==4){runner=3;point++;}}
        	else if(input.equals("OUT"))out++;
        	else {point +=runner+1;runner =0;}
        	
        	if(out==3){
        		System.out.println(point);
        		out=point=runner=0;
        		n--;
        		continue;
        	}
        	
        	
        }
      

  }
  }

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


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

struct edge {int to; ll cost; };

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

ll calc(ll h){
  if(h==1) return 1;
  else return 1+2*calc(h/2);
}
 
int main(){
  ll h;
  cin >> h;
  ll ans = calc(h);
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 3504
package main

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

var (
	N, K, ans int
)

func main() {
	readVariables()
	for b := 1; b <= N; b++ {
		if K == 0 {
			ans = N * N
			break
		}
		diff := MaxInt((N/b)*(b-K), 0) + MaxInt(N%b-K+1, 0)
		// fmt.Println(b, diff)
		ans += diff
	}
	fmt.Println(ans)
}

func readVariables() {
	N, K = nextInt(), nextInt()
}

/* Template */

var scanner *bufio.Scanner

func init() {
	Max := 1001001
	scanner = bufio.NewScanner(os.Stdin)
	scanner.Buffer(make([]byte, 0, Max), Max)
	scanner.Split(bufio.ScanWords)
}

//nextInt converts next token from stdin and returns integer value.
//nextInt panics when conversion into an integer fails.
func nextInt() int {
	if !scanner.Scan() {
		panic("No more token.")
	}
	num, err := strconv.Atoi(scanner.Text())
	if err != nil {
		panic("nextInt(): cannot convert to int: " + scanner.Text())
	}
	return num
}

func nextStr() string {
	if !scanner.Scan() {
		panic("No more token.")
	}
	return scanner.Text()
}

// MinInt returns minimum argument
func MinInt(x, y int) int {
	if x < y {
		return x
	} else {
		return y
	}
}

//MaxInt returns maximum argument
func MaxInt(x, y int) int {
	if x < y {
		return y
	} else {
		return x
	}
}

//AbsInt returns |x| for x
func AbsInt(x int) int {
	if x < 0 {
		return -x
	}
	return x
}

//ModPow calculates integer power with modulo operation
//if modulo <= 1, it powers w/o module operation
//if base < 0, return value might be negative too.
func ModPow(base, exponent, modulo int) (result int) {
	result = 1
	for exponent > 0 {
		if exponent%2 == 1 {
			result *= base
			if modulo > 1 {
				result %= modulo
			}
		}
		base *= base
		if modulo > 1 {
			base %= modulo
		}
		exponent /= 2
	}
	return
}

//Gcd
func Gcd(vals ...int) (result int) {
	if len(vals) == 0 {
		return
	}
	result = vals[0]
	for i := 1; i < len(vals); i++ {
		result = gcd(result, vals[i])
	}
	return
}

func gcd(x, y int) int {
	x, y = AbsInt(x), AbsInt(y)
	for y > 0 {
		x, y = y, x%y
	}
	return x
}

//Lcm
func Lcm(vals ...int) (result int) {
	if len(vals) == 0 {
		return
	}
	result = vals[0]
	for i := 1; i < len(vals); i++ {
		result = lcm(result, vals[i])
	}
	return
}

func lcm(x, y int) int {
	return x * y / gcd(x, y)
}


Measured memory_bytes: 640
#include<iostream>
#include<algorithm>
#include<string>
#include<cstring>
#include<queue>
#include<stack>
#include<deque>
#include<map>
#include<unordered_map>
#include<set>
#include<cmath>
#include<random>

//#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp> 
using namespace std;
using namespace __gnu_pbds;

#define ordered_set tree<int, null_type,less_equal<int>, rb_tree_tag,tree_order_statistics_node_update>
#define pb push_back
#define ff first
#define ss second
#define endl '\n'
#define ALL(v) (v).begin() , (v).end()
#define fast ios::sync_with_stdio(false); cin.tie(NULL);
const double eps = 1e-6;

/////////////////////////////////////////////

void __print(int x) {cerr << x;}
void __print(long x) {cerr << x;}
void __print(long long x) {cerr << x;}
void __print(unsigned x) {cerr << x;}
void __print(unsigned long x) {cerr << x;}
void __print(unsigned long long x) {cerr << x;}
void __print(float x) {cerr << x;}
void __print(double x) {cerr << x;}
void __print(long double x) {cerr << x;}
void __print(char x) {cerr << '\'' << x << '\'';}
void __print(const char *x) {cerr << '\"' << x << '\"';}
void __print(const string &x) {cerr << '\"' << x << '\"';}
void __print(bool x) {cerr << (x ? "true" : "false");}

template<typename T, typename V>
void __print(const pair<T, V> &x) {cerr << '{'; __print(x.first); cerr << ','; __print(x.second); cerr << '}';}
template<typename T>
void __print(const T &x) {int f = 0; cerr << '{'; for (auto &i: x) cerr << (f++ ? "," : ""), __print(i); cerr << "}";}
void _print() {cerr << "]\n";}
template <typename T, typename... V>
void _print(T t, V... v) {__print(t); if (sizeof...(v)) cerr << ", "; _print(v...);}
#ifndef ONLINE_JUDGE
#define debug(x...) cerr << "[" << #x << "] = ["; _print(x)
#else
#define debug(x...)
#endif

////////////////////////////////

#define int long long

void solve(){

	string s;
	cin>>s;
	int n = s.size();
	map<int,int> mp;

	mp[0] = 1;
	int res = 1;
	int prev = 0;
	int ans = 0;
	for(int i = n-1 ; i >=0 ; --i){

		int val = res*(s[i]-'0') + prev;

		res*=10;
		val%=2019;

		prev = val;
		res%=2019;

		ans += mp[val];
		mp[val]++;
	}

	cout<<ans<<endl;
}

signed main(){

    fast;
    //freopen("output.txt" , "w" , stdout);
    int t = 1;
   // cin>>t;
    for(int i = 1 ; i <= t; ++i){

    	solve();
    }
}


Measured memory_bytes: 3796
#include                        <bits/stdc++.h>
#include                        <ext/pb_ds/assoc_container.hpp>
#define lb                      lower_bound
#define ub                      upper_bound
#define fe(x)                   (*(x.begin()))
#define le(x)                   (*(x.rbegin()))
#define pb                      push_back
#define load(node,n)            bool operator < (const node &n) const
#define fbo(x,id)               (*(x.find_by_order(id)))
#define ook(y)                  order_of_key(y)
#define all(x)                  (x).begin(),(x).end()
#define FOR(i,n)                for(int i = 1; i<=n; i++)
#define REP(i,n)                for(int i = 0; i<n;  i++)
#define TT                      long long TC;  scanf("%lld",&TC);  while(TC--)
#define read                    freopen("input.txt","r",stdin)
#define write                   freopen("output.txt","w",stdout)
#define set(x)                  tree<x,null_type,less<x>,rb_tree_tag,tree_order_statistics_node_update>
using                           namespace __gnu_pbds;
using                           namespace std;
typedef                         long long ll;
typedef                         pair<ll,ll> pll;
typedef                         pair<int,int> pii;


#define mx 10000005



main(){
//read;

ll n,x,m;
cin>>n>>x>>m;


bool fl = 0;
int cnt = 0;
ll j = 0;

vector<ll> v = {x};
set<ll>st;
st.insert(x);

for(ll i = 2;  ; i++){
    ll p = le(v);
    p = (p*p)%m;
    v.pb(p);
    if(st.count(p)) break;
    st.insert(p);
}

ll p = le(v);
ll id,sum = 0;

for(ll i = 0; i<v.size() ; i++)
    if(v[i]==p) {
        id = i;
        for(ll j = i+1; j<v.size(); j++)
            sum+=v[j];
        break;
    }

ll len = v.size() - id - 1;

ll ans = 0;


if(n<=(int)v.size()){
    ll w = 0;
    for(ll i = 0; i<n; i++) w+=v[i];
    cout<<w;
    return 0;
}
v.pop_back();

ll w = 0;

for(ll j:v) w+=j;

p = (n-(ll)v.size())/len;
n = n - (p*len + v.size());
p*=sum;

w+=p;



for(ll j = 0; j<n   ; j++)
    w+=v[j+id];

cout<<w;


return 0;
}



Measured memory_bytes: 6000
#include<iostream>
#include<string>
#include<vector>
#include<queue>
#include<algorithm>
#include<map>
#include<set>
#include<cmath>
#include<iomanip>
#include<stack>
#include<string.h>
#include<cstring>
typedef long long ll;
#define rep(i,n) for(int i=0;i<(n);i++)
#define pb push_back
#define sz(a) (int)a.size()
using namespace std;

ll inf = 1e9 + 7;

vector<vector<int>> to;
vector<bool> seen;

void dfs(int now) {
	seen[now] = true;
	rep(i, sz(to[now])) {
		if (!seen[to[now][i]]) dfs(to[now][i]);
	}
}

int main() {
	int n, m;
	cin >> n >> m;
	to.resize(n);
	seen = vector<bool>(n, false);
	rep(i, m) {
		int xi, yi, zi;
		cin >> xi >> yi >> zi;
		xi--; yi--;
		to[xi].push_back(yi);
		to[yi].push_back(xi);
	}
	int ans = 0;
	rep(i, n) {
		if (!seen[i]) {
			ans++;
			dfs(i);
		}
	}
	cout << ans << endl;
}

Measured memory_bytes: 8832
import math

a,b,C = map(float,input().split())

h = b * math.sin(math.pi*C/180)
S = a * h /2
L = a + b +(a**2 + b**2 - 2*a*b*math.cos(math.pi*C/180))**(0.5)

print(S,L,h)

Measured memory_bytes: 7784
#include <iostream>
#include <vector>

struct Node
{
    int key, parent, left_key, right_key;
};

int main()
{
    int n;
    std::cin >> n;
    std::vector<int> vec(n + 1);
    for (size_t i = 1; i < n + 1; i++)
    {
        std::cin >> vec.at(i);
    }
    for (size_t i = 1; i < n + 1; i++)
    {
        std::cout << "node " << i << ": "
                  << "key = " << vec.at(i) << ", ";
        if (i / 2 > 0)
        {
            std::cout << "parent key = " << vec.at(i / 2) << ", ";
        }
        if (2 * i < n + 1)
        {
            std::cout << "left key = " << vec.at(2 * i) << ", ";
        }
        if (2 * i + 1 < n + 1)
        {
            std::cout << "right key = " << vec.at(2 * i + 1) << ", ";
        }
        std::cout << std::endl ;
    }
}


Measured memory_bytes: 3088
#include<iostream>
#include<algorithm>
using namespace std;
int main() {
	int far;
	int *shop;
	int n;
	int worktime;
	int answer;
	int point;
	int j;
	while (cin >> far&&far != 0) {
		answer = 0;
		cin >> n;
		cin >> worktime;
		shop = new int[n+1];
		shop[0] = 0;
		shop[n] = 1000000000;
		for (int i = 1; i < n; ++i) {
			cin >> shop[i];
		}
		sort(shop, shop + n+1);
		for (int i = 0; i < worktime; ++i) {
			cin >> point;
			for (j = 0; shop[j] < point; ++j);
			if (j == n) {
				answer += min(point - shop[j - 1], far - point);
			}
			else {
				answer += min(point - shop[j - 1], shop[j] - point);
			}
		}
		cout << answer << endl;
		delete[] shop;
	}
	return 0;
}

Measured memory_bytes: 3252
//#include<bhaai.h>
#include<bits/stdc++.h>
using namespace std;
#define to int64_t
#define mo 1000000007
#define fr(a,e) for(int i=a;i<=e;i++)
#define yah_faster_baby ios_base::sync_with_stdio(0);cin.tie(0);

to ans,n,k,m,r[100005],p[100005];
//vector <int> v[100005];
//char s[100005];
int main()
 {  yah_faster_baby
	to t;
    cin>>t;
    if(t>=30)
    cout<<"Yes\n";
    else
    cout<<"No\n";
	return 0;
}



Measured memory_bytes: 3588
#include <bits/stdc++.h>
using namespace std;
//
#define ll long long
#define ull unsigned long long
#define pb push_back
#define mx 100010
#define pi acos(-1)
#define endl '\n'
#define Fast                          \
    ios_base::sync_with_stdio(false); \
    cin.tie(0);                       \
    cout.tie(0)
//
int main()
{
    ll a, b, i, l, j, k, c, count = 0;
    string s;

    cin >> a >> b;
    for (i = a; i <= b; i++)
    {
        s = to_string(i);
        l = s.length();

        j = 0;
        k = l;
        k--;
        c = 0;
        while (k >= 0)
        {
            if (s[j] == s[k])
            {
                c++;
            }
            j++;
            k--;
        }
        if (c == l)
            count++;
    }
    cout << count << endl;
}


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

char getGrade(int m,int f,int r){
    int sum =m+f;
    char grade;
    if(m==-1||f==-1){
        grade='F';
    }else if(80<=sum){
        grade='A';
    }else if(65<=sum && sum<80){
        grade='B';
    }else if(50<=sum && sum<65){
        grade='C';
    }else if(30<=sum && sum<50){
        if(50<=r)grade='C';
        else grade='D';
    }else if(sum<30){
        grade = 'F';
    }
    
    return grade;
}

int main(){
    int m,f,r;
    while(1){
        cin >> m >>f>>r;
        if(m==-1 && f==-1 && r==-1)break;
        cout << getGrade(m,f,r)<<endl;
    }
    
    return 0;
}


Measured memory_bytes: 3100
#include<iostream>
#include<vector>
#include<algorithm>

using namespace std;
int main()
{
	int N,M,X,Y,x[110],y[110];
	cin >> N >> M >> X >> Y;
	for(int i=0; i<N; i++){
		cin >>x[i];
	}
	for(int i=0; i<M; i++){
		cin >> y[i];
	}
	sort(x,x+N);
	sort(y,y+M);
	if(x[N-1] < y[0] && X < y[0] && x[N-1] < Y){
		cout << "No War" << endl;
	}else{
		cout << "War" << endl;
	}
	
	return 0;
}



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

using namespace std;

typedef long long ll;

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

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

int main() {
	ll N, M;
	string S, T;
	cin >> N >> M >> S >> T;

	ll l = lcm(N, M);
	if (gcd(N, M) == 1) {
		if (S.front() != T.front())cout << -1 << endl;
		else cout << l << endl;
	}
	else {
		if (N > M)swap(S, T), swap(N, M);
		for (int i = 0; i < gcd(N, M); i++) {
			if (S[i * (lcm(N, M) / M)] != T[i * lcm(N, M) / N]) {
				cout << -1 << endl;
				return 0;
			}
		}
		cout << l << endl;
	}
	return 0;
}

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

int main()
{
	int i,gakuseki,tmp=-1;
	double W,L;
	double BMI;
	while(scanf("%d,%lf,%lf",&gakuseki,&W,&L))
	{
		if(tmp==gakuseki)
			break;
            tmp=gakuseki;
	    BMI=W/L/L;
	  
	   if(BMI>=25)
           cout<<gakuseki<<endl;
	}
	
return 0;



}

Measured memory_bytes: 1232
#include<bits/stdc++.h>
using namespace std;
#define MOD 1000000007

int main() {
  
  long long N,K;
  cin >> N >> K;

  vector<int> A(N);
  for(int i = 0;i < N;i++) cin >> A[i];

  int num = 0,idx = 0,t = 0;
  vector<int> n(N,0);
  for(int i = 0;i < N;i++) {
    n[idx]++;
    idx = A[idx]-1;
    num++;
    if(n[idx] != 0) {
      t = idx;
      break;
    }
  }

  int r = 0;
  do{
    r++;
    idx = A[idx]-1;
  }while(idx != t);

  if(K >= num) K -= num;
  else {
    idx = 0;
    while(K--) idx = A[idx]-1;
    cout << idx+1 << endl;
    return 0;
  }

  if(r != 0) K %= r;

  while(K--) {
    idx = A[idx]-1;
  }

  cout << idx+1 << endl;
  



}


Measured memory_bytes: 4832
#include <cstdio>
#include <cstring>
#include <iostream>
#include <string>
#include <cmath>
#include <bitset>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <algorithm>
#include <complex>
#include <unordered_map>
#include <unordered_set>
#include <random>
#include <cassert>
#include <fstream>
#include <utility>
#include <functional>
#include <time.h>
#include <stack>
#include <array>
#include <list>
#define popcount __builtin_popcount
using namespace std;
typedef long long int ll;
typedef pair<int, int> P;

int main()
{
	ll a, b, c, k;
    cin>>a>>b>>c>>k;
    if(k<=a) cout<<k<<endl;
    else if(k<=a+b) cout<<a<<endl;
    else cout<<a-(k-a-b)<<endl;
	return 0;
}


Measured memory_bytes: 3632
#include <bits/stdc++.h>
using namespace std;
//関数
const long INF=1000000000000000;

int main(void){
    string S;
    cin>>S;
    for(int i=0;i<3;i++){
        if(S.at(i)==S.at(i+1)){
            cout<<"Bad"<<endl;
            return 0;
        }
    }
    
    cout<<"Good"<<endl;
}

Measured memory_bytes: 256
N, M, C = map(int, input().split())
B = list(map(int, input().split()))
A = [list(map(int, input().split())) for _ in range(N)]
X = 0
for i in range(N):
  Y = C
  for j in range(M):
    Y += A[i][j]*B[j]
  if Y > 0:
    X += 1
print(X)

Measured memory_bytes: 2940
#include <iostream>
#include <cstdio>
#include <map>
#include <vector>
using namespace std;

int n,ans;
map<int,int> note;
vector<int> v;

int main() {
	scanf("%d",&n);
	for (int i=1,a; i<=n; ++i) {
		scanf("%d",&a);
		if (note.count(a))
			note.erase(a);
		else {
			note[a]=1;
			v.push_back(a);
		}
	}
	for (int i=0; i<v.size(); ++i)
		if (note.count(v[i])) {
			++ans;
			note.erase(v[i]);
		}
	printf("%d\n",ans);
	return 0;
}

Measured memory_bytes: 5368
#include<iostream>
using namespace std;
#include<string>
#include<strstream>
#include<sstream>
#include<algorithm>
#include<math.h>
#include<iomanip>
int main()
{
	string s, t;
	cin >> s >> t;
	sort(s.begin(), s.end());
	sort(t.begin(), t.end(), greater<int>());
	if (t > s)
		cout << "Yes";
	else
		cout << "No";
}

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

int main(){
    
    vector<vector<int>> c(3, vector<int>(3));
    for(int i=0; i<3; i++){
        for(int j=0; j<3; j++){
            cin >> c.at(i).at(j);
        }
    }

    string ans="Yes";
    if(c.at(1).at(0)-c.at(0).at(0)!=c.at(1).at(1)-c.at(0).at(1)||c.at(1).at(2)-c.at(0).at(2)!=c.at(1).at(1)-c.at(0).at(1)) ans="No";
    if(c.at(2).at(0)-c.at(1).at(0)!=c.at(2).at(1)-c.at(1).at(1)||c.at(2).at(2)-c.at(1).at(2)!=c.at(2).at(1)-c.at(1).at(1)) ans="No";
    if(c.at(0).at(1)-c.at(0).at(0)!=c.at(1).at(1)-c.at(1).at(0)||c.at(2).at(1)-c.at(2).at(0)!=c.at(1).at(1)-c.at(1).at(0)) ans="No";
    if(c.at(0).at(2)-c.at(0).at(1)!=c.at(1).at(2)-c.at(1).at(1)||c.at(2).at(2)-c.at(2).at(1)!=c.at(1).at(2)-c.at(1).at(1)) ans="No";

    cout << ans << endl;
}

Measured memory_bytes: 3632
while True:
    string = input()
    numbers = list(map(int, string.split(' ')))
    if numbers[0] == 0 and numbers[1] == 0:
        break
    for i in range(numbers[0]):
        if i == 0 or i == numbers[0] - 1:
            for j in range(numbers[1]):
                print('#', sep='', end='')
        else:
            print('#', sep='', end='')
            for j in range(numbers[1] - 2):
                print('.', sep='', end='')
            print('#', sep='', end='')
        print()
    print()


Measured memory_bytes: 7000
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Map;
import java.util.Scanner;
import java.util.TreeMap;

public class Main {

	public static void main(String[] args) {

		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int K = sc.nextInt();

		Map<Integer, Integer> amap = new TreeMap<>();

		for (int i = 0; i < N; i++) {
			Integer a = sc.nextInt();

			if (!amap.containsKey(a)) {
				amap.put(a, 1);
			} else {
				amap.put(a, amap.get(a) + 1);
			}
		}

		List<Integer> vallist = new ArrayList<>(amap.values());
		//List<Entry<Integer, Integer>> listEntries = new ArrayList<Entry<Integer, Integer>>(amap.entrySet());

		Collections.sort(vallist);

		int cnt = 0;
		if (amap.size() > K) {
			for (int i = 0; i < amap.size() - K; i++) {
				cnt += vallist.get(i);
			}
		}
		System.out.println(cnt);
	}
}



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

int main()
{
    string S;
    while ( cin >> S, S[0] != '-' ) {
        string T;
        int num = 0, pos;
        if ( (pos = S.find('.')) != (int)string::npos ) {
            num = S.size() - pos - 1;
        }
        for ( int i = 0; i < S.size(); i++ ) {
            if ( S[i] != '.' ) {
                T += S[i];
            }
        }

        int val = atoi(T.c_str()) * 16;
        bool flag = true;
        int g = 1;
        for ( int i = 0; i < num; i++ ) {
            if ( (val % (g * 10)) != 0 ) {
                flag = false;
            }
            g *= 10;
        }
        if ( val >= g * 4096 ) {
            flag = false;
        }
        if ( flag ) {
            val /= g;
            string ans;
            for ( int i = 0; i < 4; i++ ) {
                ans += (char)(((val & (1 << i)) >> i) + '0');
            }
            ans += '.';
            for ( int i = 4; i < 12; i++ ) {
                ans += (char)(((val & (1 << i)) >> i) + '0');
            }
            reverse(ans.begin(), ans.end());
            cout << ans << endl;
        } else {
            cout << "NA" << endl;
        }
    }
    return ( 0 );
}



Measured memory_bytes: 3152
#include <iostream>
#include <vector>
#include <algorithm>
#include <fstream>
#include <string>
#include <math.h>
#include <cstdlib>
#include <istream>
#include <sstream>
#include <cctype>
#define fore(i,x,y) for(ll i=(x);i<(y);i++)
#define disp(a) cout << a << endl;
typedef long long ll;
using namespace std;
int main()
{
	int N,A;
	cin >> N >> A;
	if (N % 500 <= A) {
		cout << "Yes" << endl;
	}
	else {
		cout << "No" << endl;
	}
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define pii pair<int, int>
#define fir first
#define sec second
#define ll long long
using namespace std;
const int MAXN = 2e5 + 7;
int n, p[MAXN], val[MAXN], cnt[MAXN];
pii e;
bool vis[MAXN];
vector<int>G[MAXN];
int getmex(int u)
{
    int res = 0;
    for (int v : G[u]) if (val[v] != -1) cnt[val[v]]++;
    for (int x = 0; x <= n; x++) if (cnt[x] == 0)
    {
        res = x;
        break;
    }
    for (int v : G[u]) if (val[v] != -1) cnt[val[v]]--;
    return res;
}
void dfs(int u)
{
    vis[u] = 1;
    for (int v : G[u])
    {
        if (vis[v]) 
        {
            if (val[v] == -1) e = {u, v};
            continue; 
        }
        dfs(v);
    }
    val[u] = getmex(u);
}
int main() 
{
    scanf("%d", &n);
    for (int i = 1; i <= n; i++) 
    {
        scanf("%d", &p[i]);
        G[p[i]].push_back(i);
    }
    memset(val, -1, sizeof(val));
    for (int i = 1; i <= n; i++) if (val[i] == -1) dfs(i);
    val[e.fir] = getmex(e.fir);
    int u = p[e.fir];
    while (u != e.fir)
    {
        val[u] = getmex(u);
        u = p[u];
    } 
    if (getmex(e.fir) == val[e.fir]) puts("POSSIBLE");
    else puts("IMPOSSIBLE");
    
    return 0;
}

Measured memory_bytes: 20480
#include<stdio.h>
#include<stdlib.h>
#include<math.h>

int *A;
int h;

int left(int i){
  return i * 2;
}

int right(int i){
  return (i * 2) + 1;
}

void maxHeapify(int *A,int i){
  int l,r,largest,a;
  l = left(i);
  r = right(i);

  if(l <= h && A[l] > A[i]){
    largest = l;
  }
  else{
    largest = i;
  }
  if(r <= h && A[r] > A[largest]){
    largest = r;
  }

  if(largest != i){
    a = A[i];
    A[i] = A[largest];
    A[largest] = a;
    maxHeapify(A,largest);
  }
}


void buildMaxHeap(int *A,int length){
  int i,g;
  double f;
  f = floor(length / 2);
  g = (int)f;
  for(i = g;i >= 1;i--){
    maxHeapify(A,i);
  }
}

int main(){
  int i;

  scanf("%d",&h);

  A = malloc(sizeof(int)*(h+1));

  for(i = 1;i < h+1;i++){
    scanf("%d",&A[i]);
  }

  buildMaxHeap(A,h);

  for(i = 1;i < h+1;i++){
    printf(" %d",A[i]);
  }
  printf("\n");

  return 0;
}

Measured memory_bytes: 2556
#pragma GCC optimize ("Ofast")
#include <bits/stdc++.h>
#define FOR(i, a, b) for (int i=(a); i<(int)(b); i++)
#define FORD(i, a, b) for (int i=a; i>(int)(b); i--)
#define PPC(x) __builtin_popcount(x)
#define pb push_back
#define ALL(x) (x).begin(), (x).end()
#define ft first
#define sd second
#ifdef DEBUG
#include "debug.h"
#else
#define dbg(...) 0
#endif
using namespace std;

const int maxN = 1 << 17;

string T[maxN];
int W[maxN];

int main()
{
	int n, res = 0;
	cin >> n;
	FOR(i, 0, n)
		cin >> T[i] >> W[i], res += W[i];
	string x;
	cin >> x;
	
	FOR(i, 0, n)
	{
		res -= W[i];
		if (T[i] == x)
			break;
	}
	
	cout << res << "\n";
	return 0;
}


Measured memory_bytes: 1280
#include <iostream>
#include <vector>
#include <math.h>
#include <cmath>
#include <map>
#include <algorithm>
#include <string>
using namespace std;

int main() {
	long long int N; cin >> N;
	vector<long long>A(N);
	long long int Amax = 1, Maxat = 0;
	for (int i = 0; i < N; i++) {
		cin >> A.at(i);
		if (A.at(i) > Amax) {
			Maxat = i;
			Amax = A.at(i);
		}
	}
	long long int Bmax = 1;
	for (int i = 0; i < N; i++) {
		if (i == Maxat) {
			for (int j = 0; j < N; j++) {
				if (Bmax < A.at(j) && j != Maxat) {
					Bmax = A.at(j);
				}
			}
			cout << Bmax << endl;
		} else {
			cout << Amax << endl;
		}
	}
}

Measured memory_bytes: 3200
#include <bits/stdc++.h>
#define LL __int128
#define ll long long
#define sc(a) scanf("%d", &a)
#define sc2(a, b) scanf("%d%d", &a, &b)
#define sc3(a, b, c) scanf("%d%d%d", &a, &b, &c)
#define scl(a) scanf("%lld", &a)
#define scl2(a, b) scanf("%lld%lld", &a, &b)
#define ss(a) scanf("%s", a)
#define mem(a, b) memset(a, b, sizeof(a))
#define ios ios::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#define PII pair<int, int>
using namespace std;
const int maxn=2e3+10;
const ll mod=1e9+7;
ll dp[maxn];//n  la_num;
int vis[maxn];
int main(){
	ll n;
	cin>>n;
	memset(dp,0,sizeof(dp));
	memset(vis,1,sizeof(vis));
	for(int i=3;i<=n;i++){
		dp[i]=1;
	}
	for(int i=3;i<=n;i++){
		for(int j=3;j+i<=n;j++){
			dp[i+j]=(dp[i+j]+dp[i])%mod;
		}
	}
	cout<<dp[n]<<endl;
	return 0 ;
}

Measured memory_bytes: 3616
import sys

X, K, D = map(int, sys.stdin.readline().split())

if K*D <= abs(X):
    if 0 <= X:
        print(X - K*D)
    else:
        print(abs(X + K*D))
else:
    dist = abs(X)
    a = dist // D
    # 残りの移動回数
    r = K - a
    if 0 <= X:
        pos1 = X - a * D
        pos2 = pos1 - D
    else:
        pos1 = X + a * D
        pos2 = pos1 + D

    if r % 2 == 1:
        print(abs(pos2))
    else:
        print(abs(pos1))

Measured memory_bytes: 9116
import java.util.Arrays;
import java.util.Scanner;

public class Main {
    static Scanner in = new Scanner(System.in);

    public static void main(String[] args) {
        int N = in.nextInt();
        int[] c = new int[9];
        Arrays.fill(c, 0);
        for(int i = 0; i < N; i++){
            c[Math.min(in.nextInt() / 400, 8)]++;
        }
        int sum = 0;
        for(int i = 0; i < 8; i++){
            sum += c[i] == 0 ? 0 : 1;
        }
        System.out.println((sum == 0 ? 1 : sum) + " " + (sum + c[8]));
    }
}

Measured memory_bytes: 21844
n,m,x,y = map(int,input().split())
xl = list(map(int, input().split()))
yl = list(map(int, input().split()))
xl.sort()
yl.sort()
z = []
for i in range(x+1,y+1):
    z.append(i)
i = 0
while len(z) > i:
    if z[i] <= xl[n-1] or z[i] <= x:
        z.pop(i)
        continue
    if yl[0] < z[i] or y < z[i]:
        z.pop(i)
        continue
    i += 1
    if len(z) == 0:
        break
if len(z) > 0:
    print("No War")
else:
    print("War")


Measured memory_bytes: 3064
from collections import deque
N = int(input())
A = deque(map(int, input().split()))
mod = 10**9 + 7
M = len(bin(max(A))) - 2
ans = 0
bitlist = [1]
for k in range(M):
    bitlist.append(bitlist[-1]*2%mod)
counter = [0 for _ in range(M)]

for k in range(N):
    a = A.pop()
    c = 0
    while c < M:
        b = a & 1
        if b == 0:
            ans += counter[-c-1]*bitlist[c]%mod
            ans %= mod
        else:
            ans += (k-counter[-c-1])*bitlist[c]%mod
            ans %= mod
            counter[-c-1] += 1
        c += 1
        a >>= 1
print(ans)




Measured memory_bytes: 119308
//#include <bits/stdc++.h>
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstdlib>
#include <string>
#include <vector>
#include <map>
#include <queue>

using namespace std;

typedef long long ll;
typedef vector<int> vint;
typedef vector<vector<int> > vvint;
typedef vector<long long> vll, vLL;
typedef vector<vector<long long> > vvll, vvLL;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) for(int i=0;i<n;++i)
#define mod (ll)(1e9+7)
#define FIX(a) ((a)%mod+mod)%mod
#define ALL(obj) (obj).begin(), (obj).end()
#define rALL(obj) (obj).rbegin(), (obj).rend()
#define INF 1000000000 //1e9
#define LLINF 2000000000000000000LL //2e18
#define fi first
#define se second
#define pb push_back
int dy[]={0, 0, 1, -1};
int dx[]={1, -1, 0, 0};

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int h,w;
    cin >> h >> w;
    int n;
    cin >> n;
    vint a(n);
    REP(i,n) cin >> a[i];
    vvint ans(h,vint(w));
    bool f = true;
    int x=0,y=0;
    REP(i,n){
        REP(j,a[i]){
            ans[y][x] = i+1;
            if(f){
                if(x+1>=w){
                    y++;
                    f = false;
                }else{
                    x++;
                }
            }else{
                if(x-1<0){
                    y++;
                    f = true;
                }else{
                    x--;
                }
            }
        }
    }
    REP(i,h){
        REP(j,w-1){
            cout << ans[i][j] << " ";
        }
        cout << ans[i][w-1] << "\n";
    }

    return 0;
}

Measured memory_bytes: 3696
#include <iostream>
#include <algorithm>
#include <cmath>
using namespace std;
int main () {
	int a, b, c;
	cin >> a >> b >> c;
	if(a == b && a != c) {
		cout << "Yes" << "\n";
	}else if(a == c && a != b) {
		cout << "Yes" << "\n";
	}else if(b == c && b != a) {
		cout << "Yes" << "\n";
	}else {
		cout << "No" << "\n";
	}
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <vector>
#include <stack>
#include <queue>
#include <map>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>

using namespace std;

int Partition(int *A, int p, int r) {
	int x = A[r];
	int i = p - 1;
	for (int j = p; j < r; j++) {
		if (A[j] <= x) {
			i++;
			swap(A[i], A[j]);
		}
	}
	swap(A[i+1], A[r]);
	return i + 1;
}

void quickSort(int *A, int p, int r) {
	int q = Partition(A, p, r);
	int ifs = 1;
	for (int i = p; i <= r; i++) {
		if (ifs == 0)
			cout << " ";
		if (i == q)
			cout << "[" << A[i] << "]";
		else
			cout << A[i];
		ifs = 0;
	}
	cout << endl;
}

int main() {
	int n;
	cin >> n;
	int *A = new int[n];
	for (int i = 0; i < n; i++)
		cin >> A[i];
	quickSort(A, 0, n - 1);
	delete[] A;
	return 0;
}

Measured memory_bytes: 1532