akhauriyash/Code-Regression huggingface dataset:
import java.util.*;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int m = sc.nextInt();
		int[] p = new int[m];
		String s[] = new String[m];
		for (int i = 0; i < m; i++) {
			p[i] = sc.nextInt();
			s[i] = sc.next();
		}
		sc.close();
		int[] pen = new int[n];
		boolean[] aca = new boolean[n];
		for (int i = 0; i < n; i++) {
			pen[i] = -1;
		}

		for (int i = 0; i < m; i++) {
			int tmp = p[i] - 1;
			if (s[i].equals("WA")) {
				if (!aca[tmp]) {
					pen[tmp] = pen[tmp] == -1 ? 1 : pen[tmp] + 1;
				}
			} else {
				pen[tmp] = pen[tmp] == -1 ? 0 : pen[tmp];
				aca[tmp] = true;
			}
		}

		int ac = 0;
		int wa = 0;
		for (int i = 0; i < n; i++) {
			if (pen[i] >= 0) {
				if (aca[i])
					wa += pen[i];
			}
			if (aca[i]) {
				ac++;
			}
		}
		System.out.println(ac + " " + wa);

	}

	public static long modFactorial(long n, long mod) {
		long ans = 1;
		for (int i = 1; i <= n; i++) {
			ans *= i;
			ans %= mod;
		}
		return ans;
	}

	public static int arrayMax(int[] array) {
		int ans = Integer.MIN_VALUE;
		for (int i = 0; i < array.length; i++) {
			if (array[i] > ans)
				ans = array[i];
		}
		return ans;
	}

	public static int[] arrayInt(Scanner sc, int n) {
		int[] array = new int[n];
		for (int i = 0; i < n; i++) {
			array[i] = sc.nextInt();
		}
		return array;
	}

	public static long[] arrayLong(Scanner sc, int n) {
		long[] array = new long[n];
		for (int i = 0; i < n; i++) {
			array[i] = sc.nextLong();
		}
		return array;
	}

	public static double[] arrayDouble(Scanner sc, int n) {
		double[] array = new double[n];
		for (int i = 0; i < n; i++) {
			array[i] = sc.nextDouble();
		}
		return array;
	}
}


Measured memory_bytes: 71740
/*
 * a.c
 *
 *  Created on: 2017/06/13
 *      Author: AWV060608
 */

#include	<stdio.h>

#define		MXRC		100+1

int		main(void)
{
	int		r, c;
	int		hyou[MXRC][MXRC];
	int		i, j;
	int		x;
	int		sum;

	scanf("%d",&r);
	scanf("%d",&c);

	for(i=0; i<r; i++)
	{
		for(j=0; j<c; j++)
		{
			scanf("%d",&x);
			hyou[i][j] = x;
		}
	}
	sum = 0;
	for(i=0; i<r; i++)
	{
		for(j=0; j<c; j++)
		{
			sum = sum + hyou[i][j];
			printf("%d ",hyou[i][j]);
		}
		hyou[i][c] = sum;
		printf("%d\n",sum);
		sum = 0;
	}
	sum = 0;
	for(j=0; j<c+1; j++)
	{
		for(i=0; i<r; i++)
		{
			sum = sum + hyou[i][j];
		}
		printf("%d",sum);
		if( j != c )
		{
			printf(" ");
		}
		sum = 0;
	}
	printf("\n");
	return 0;
}

Measured memory_bytes: 644
/*  ***  In The Name of God ... ***  */ 
#include <bits/stdc++.h>
 
using namespace std;
 
typedef long long ll;
typedef long double ld;
 
 
#define int long long
#define all(v) v.begin() , v.end()

template<typename T> inline bool smin(T &a, const T &b){ return b < a ? a = b,1:0;}
template<typename T> inline bool smax(T &a, const T &b){ return a < b ? a = b,1:0;}
 
const int N = 50 + 10 , maxn = 50 * 50 + 10 ; 
 
int n , a [ N ] , A , dp [ N ] [ maxn ] [ N ] ;  
 
int32_t main()
{
	ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
	cin >> n >> A ;
	for ( int i = 1 ; i <= n ; i++ )
		cin >> a [ i ] ;
	dp [ 0 ] [ 0 ] [ 0 ]++ ; 
	dp [ 1 ] [ 0 ] [ 0 ]++ ; 
	dp [ 1 ] [ a [ 1 ] ] [ 1 ]++ ; 
	for ( int i = 2 ; i <= n ; i++ ) {
		for ( int j = maxn - 1 ; j >= 0 ; j-- ) {
			for ( int t = 0 ; t <= i ; t++ ) {
				dp [ i ] [ j ] [ t ] = dp [ i - 1 ] [ j ] [ t ] ;
				if ( j - a [ i ] >= 0 && t )
					dp [ i ] [ j ] [ t ] += dp [ i - 1 ] [ j - a [ i ] ] [ t - 1 ] ;
			}
		}
	}
	int ans = 0 ;
	for ( int i = 0 ; i < maxn ; i++ ) {
		for ( int j = 1 ; j <= n ; j++ ) {
			if ( j * A == i ) { 
				ans += dp [ n ] [ i ] [ j ] ;
			}
		}
	}
	cout << ans << '\n' ; 
}


Measured memory_bytes: 59648
import math

N = int(input())
a = list(map(int, input().split()))

bases = []
i = 1
while True:
    i = i * 2
    if i < 1000000000:
        bases.append(i)
    else:
        break

bases.reverse()

ans = 0
for ai in a:
    for i, base in enumerate(bases):
        if ai % base == 0:
            ans += len(bases) - i
            break

print(ans)


Measured memory_bytes: 4148
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
#define rep(i, n) for(int i = 0; i < n; i++)
#define REP(i, a, b) for(int i = a; i < b; i++)
#define all(x) x.begin(), x.end()
#define fi first
#define se second
#define pb push_back
#define debug(x) cerr <<__LINE__<< ": " << #x << " -> " << x << endl
#define debug_vec(v) cerr<<__LINE__<<": "<<#v<<" -> ";rep(i,v.size())cerr<<" "<<v[i];cerr<<endl
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
const int INF = (1<<30) - 1;
const ll LINF = (1LL<<60) - 1;

int n, m, q;
int ans;
int A[60], B[60], C[60], D[60];

int calc(vector<int> &X) {
    int ret = 0;
    rep(i, q) {
        if (X[B[i]] - X[A[i]] == C[i]) ret += D[i];
    }
    return ret;
}

void dfs(vector<int> X) {
    if (X.size() == n) {
        chmax(ans, calc(X));
        return;
    }
    int a = 1;
    if (!X.empty()) a = X.back();

    REP(i, a, m + 1) {
        auto vec = X;
        vec.push_back(i);
        dfs(vec);
    }
    return;
}

void solve() {
    cin >> n >> m >> q;
    rep(i, q) {
        cin >> A[i] >> B[i] >> C[i] >> D[i];
        A[i]--; B[i]--;
    }
    vector<int> Z;
    dfs(Z);
    cout << ans << endl;
}

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


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

#define REP(i, n) for (int i = 0; i < (n); i++)
#define FOR(i, init, n) for(int i = init; i < (n); i++)
#define ALL(obj) (obj).begin(), (obj).end()
#define fi first
#define se second

using namespace std;
using ll = long long int;
using P = pair<int, int>;
using T = tuple<int, int, int>;
using edge = struct
{
    int to, cost;
};

const int MOD = 1e9 + 7;
const int iINF = 1e9;
const long long int llINF = 1e18;
const double PI = acos(-1.0);

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

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

    int N, M, Q;
    cin >> N >> M >> Q;

    list<int> lis;

    REP(i, N) lis.push_back(i);

    auto now = lis.begin();

    REP(i, M)
    {
        int input;
        cin >> input;

        if(input % 2 == 0)
        {
            REP(j, input)
            {
                if(now == --lis.end())
                    now = lis.begin();
                else
                    now++;
            }
        }
        else
        {
            REP(j, input)
            {
                if(now == lis.begin())
                    now = --lis.end();
                else
                    now--;
            }
        }

        if(now == --lis.end())
        {
            lis.pop_back();
            now = lis.begin();
        }
        else
            now = lis.erase(now);
    }

    REP(i, Q)
    {
        int input;
        cin >> input;
        cout << binary_search(ALL(lis), input) << endl;
    }


    

    return 0;
}


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

using namespace std;

#define ALL(x) (x).begin(), (x).end()
#define ALLTRUE(xs) all_of(ALL(xs),[](bool x){return x;})
#define AND(x,y,z) set_intersection((x).begin(),(x).end(),(y).begin(),(y).end(),inserter((z),(z).end()))
#define ANYTRUE(xs) any_of(ALL(xs),[](bool x){return x;})
#define CONCAT(x,y) (x).insert((x).end(),(y).begin(),(y).end())
#define DUMP(xs) for (auto x:xs) cout<<x<<' ';cout<<endl
#define FOR(i,a,b) for (int i=(int)(a);i<(int)(b);++i)
#define OR(x,y,z) set_union((x).begin(),(x).end(),(y).begin(),(y).end(),inserter((z),(z).end()))
#define OUT(x) cout<<x<<endl
#define REP(i,n) FOR(i,0,n)

typedef long long ll;
typedef pair<ll, ll> P;
typedef vector<int> VECINT;
typedef vector<ll> VECLL;

int main() {
  ll N;cin>>N;

  // マイナスが偶数コナラ全てプラスにできる
  // マイナスが奇数個なら、どれかひとつだけマイナスにしてそれ以外をプラスにする
  // どれかひとつ = 絶対値が小さい
  ll total = 0;
  ll minus_cnt = 0;
  ll abs_min = LLONG_MAX;
  REP(i,N) {
    ll a;cin>>a;
    if (a<0) minus_cnt++;
    a = abs(a);
    total += a;
    abs_min = min(abs_min,a);
  }
  (minus_cnt%2==0) ? OUT(total) : OUT(total-abs_min*2);

  return 0;
}

Measured memory_bytes: 384
import java.io.{BufferedOutputStream, BufferedReader, InputStreamReader, PrintWriter}

import scala.annotation.tailrec

object Main {
  def main(args: Array[String]): Unit = {
    val in = new BufferedReader(new InputStreamReader(System.in))
    val out = new PrintWriter(new BufferedOutputStream(System.out))
    val Array(n, m, q) = in.readLine().split("\\s+").map(_.toInt)
    val queries = Array.fill(q) {
      in.readLine().split("\\s+").map(_.toInt)
    }

    val as = Array.fill(n)(1)
    var completed = false
    var cursor = 0
    var maxScore = Integer.MIN_VALUE

    @tailrec
    def next(): Boolean = {
      if(cursor < n - 1 && as(cursor) < as(cursor + 1) || cursor == n - 1 && as(cursor) < m) {
        as(cursor) += 1
        for(i <- 0 until cursor) {
          as(i) = 1
        }
        if(cursor > 0) {
          cursor -= 1
        }
        true
      } else if (cursor < n - 1) {
        cursor += 1
        next()
      } else {
        false
      }
    }

    while (!completed) {
      var score = 0
      for (query <- queries) {
        if (as(query(1) - 1) - as(query(0) - 1) == query(2)) {
          score += query(3)
        }
      }
      maxScore = Math.max(maxScore, score)

      if(!next()) {
        completed = true
      }
    }

    out.println(maxScore)
    out.flush()
  }
}


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

#define int long long

int e[111][111],d[111];
int used[111];

signed main(){
  int n;
  cin>>n;
  int INF=1LL<<55LL;
  for(int i=0;i<n;i++)
    for(int j=0;j<n;j++)
      e[i][j]=INF;
  for(int i=0;i<n;i++){
    int u,k;
    cin>>u>>k;
    for(int j=0;j<k;j++){
      int v,c;
      cin>>v>>c;
      e[u][v]=min(e[u][v],c);
    }
  }
  memset(used,0,sizeof(used));
  for(int i=0;i<n;i++) d[i]=INF;
  d[0]=0;
  while(1){
    int u=-1;
    for(int i=0;i<n;i++){
      if(used[i]) continue;
      if(d[i]==INF) continue;
      if(u<0||d[i]<d[u]) u=i;
    }
    if(u<0) break;
    used[u]=1;
    for(int i=0;i<n;i++){
      d[i]=min(d[i],d[u]+e[u][i]);
    }
  }
  for(int i=0;i<n;i++) cout<<i<<" "<<d[i]<<endl;
  return 0;
}


Measured memory_bytes: 3100
#include <bits/stdc++.h>
using namespace std;
/* typedef */
typedef long long ll;
typedef pair<int, int> pii;
/* constant */
const int INF = 1 << 30;
const ll LINF = 1LL << 50;
const int NIL = -1;
const int MAX = 10000;
const int mod = 1000000007;
const double pi = 3.141592653589;
/* global variables */
/* function */
/* main */
int main(){
    int N, T;
    cin >> N >> T;
    vector<pii> v(N);
    int a, b;
    for (int i = 0; i < N; i++) {
        cin >> a >> b;
        v[i] = pii(a, b);
    }
    sort(v.begin(), v.end());

    vector<vector<int> > dp(N + 1, vector<int>(T+1));
    for (int i = 0; i < N; i++) {
        for (int j = 0; j < T; j++) {
            int k = j - v[i].first;
            if (k >= 0)
                dp[i+1][j] = max(dp[i][j], dp[i][k] + v[i].second);
            else dp[i+1][j] = dp[i][j];
        }
        dp[i+1][T] = max(dp[i][T], dp[i][T - 1] + v[i].second);
    }
    cout << dp[N][T] << '\n';
}

Measured memory_bytes: 35584
N = int(input())
p = list(map(int,input().split()))
cnt = 0
cur = 0
for i in range(N):
    if p[i] == i+1:
        cur += 1
    else:
        cnt += cur//2 + cur%2
        cur = 0

cnt += cur//2 + cur%2
print(cnt)

Measured memory_bytes: 14008
#include <stdio.h>
#include <math.h>
#include <string.h>
#include <stdlib.h>
int main(void)
{
	//変数の宣言
	int n;
	char s[610][310];
	char dummy;
	
	//よく使う変数
	int i,j,k,l;
	int flag=0;
	long int ans=0;
	int count=0;
	int temp,temp1,temp2;
	int max,min;
	int len;
	//データの読み込み
	
	scanf("%d",&n);
	
	for(i=0;i<n;i++){
		scanf("%c",&dummy);
		for(j=0;j<n;j++){
			scanf("%c",&s[i][j]);
			s[i+n][j]=s[i][j];
		}
	}
	
	
//	printf("nは%dです\n", n);
//	printf("データの読み込み終了\n");
	//実際の処理
	
	for(i=0;i<n;i++){
		flag=1;
		for(j=0;j<n;j++){
			for(k=0;k<n;k++){
				if(s[j+i][k]!=s[k+i][j]){
					flag=0;
				}
			}
		}
		if(flag==1){
			ans++;
		}
	}
	
	
	
//	printf("計算部分終了\n");
	//出力
	
	printf("%d",ans*n);
	
//	printf("結果の出力終了\n");
	
	return 0;
	
}



Measured memory_bytes: 384
def is_ok(val, N, d):
    if val < 0:
       return True
    val_s = str(val)
    if len(val_s) != N:
        return False
    for s, c in d.items():
        # print("val_s = {}, s = {}, c = {}".format(val_s, s, c))
        if int(val_s[s-1]) != c:
            return False
    return True

N, M = map(int, input().split())

d = {}
flag = True

for i in range(M):
    s, c = map(int, input().split())
    if s in d.keys() and d[s] != c:
        print("-1")
        exit()
    d[s] = c

# res = binary_search(N, d, -1, 10 ** 4, is_ok)

for i in range(0, 10 ** 4):
    if is_ok(i, N, d):
        print(i)
        exit()

print("-1")

Measured memory_bytes: 65056
#include<bits/stdc++.h>
#include<string>
using namespace std;
string s;
int i,l,x,cnt;

int main(){
	std::ios::sync_with_stdio(false);
	cin>>s;
	l=s.length();
	x=0; cnt=0;
	for (i=0; i<=l-1; ++i){
		if (x==0){
			++x;
			if (s[i]=='p') --cnt; 
		}
		else
		if (x>0) {
			--x;
			if (s[i]=='g') ++cnt;
		}
	}
	cout<<cnt;
}

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

int main() {
unsigned long long a,b,e,f,l;
	while(cin>>a>>b){
		e=a;
		f=b;
		while(1){
		if(e>f){
			e=e-f;
		}
	    if(f>e){
	    	f=f-e;
	    }
	    if(f==e){
	    	l=e;
	    	cout<<l<<" "<<(a*b)/l<<endl;
	    	;break;
	    }
		}
	}
	return 0;
}

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

int N, L;
int t[101], h[101];

// k := 人の番号, money := 自販機の中の金額
// T := 自販機の中の10円玉の数, H *= 自販機の中の100円玉の数
int f(int k, int money, int T, int H){
	if( t[k] ){ // 10円玉を支払う
		t[k]--;
		T++;
		money += 10;
		if( T > L ){ return k+1; }
		
		if( money >= 90 ){
			if( (money-90)/10 > T ){ return k+1; }
			
			T -= (money-90)/10;
			t[k] += (money-90)/10;
			money = 0;
		}
		return f( (k+1)%N, money, T, H );
	}else if( h[k] ){ // 100円玉を支払う
		h[k]--;
		H++;
		money += 100;
		if( (money-90)/10 > T ){ return k+1; }
		
		T -= (money-90)/10;
		t[k] += (money-90)/10;
		money = 0;
		return f( (k+1)%N, money, T, H );
	}else{
		return k+1;
	}
}

int main(){
	int T, H;
	cin >> N >> T >> H >> L;
	for(int i=0 ; i < N ; i++ ){
		cin >> t[i] >> h[i];
	}
	int ans = f(0,0,T,H);
	cout << ans << endl;
}

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

using ll = int64_t;
#define int ll

#define FOR(i, a, b) for (int i = int(a); i < int(b); i++)
#define REP(i, b) FOR(i, 0, b)
#define MP make_pair
#define PB push_back
#define EB emplace_back
#define ALL(x) x.begin(), x.end()

using pi = pair<int, int>;
using vi = vector<int>;
using ld = long double;

template <class T, class U>
ostream &operator<<(ostream &os, const pair<T, U> &p) {
  os << "(" << p.first << "," << p.second << ")";
  return os;
}

template <class T> ostream &operator<<(ostream &os, const vector<T> &v) {
  os << "{";
  REP(i, (int)v.size()) {
    if (i)
      os << ",";
    os << v[i];
  }
  os << "}";
  return os;
}

ll read() {
  ll i;
  scanf("%" SCNd64, &i);
  return i;
}

void printSpace() { printf(" "); }

void printEoln() { printf("\n"); }

void print(ll x, int suc = 1) {
  printf("%" PRId64, x);
  if (suc == 1)
    printEoln();
  if (suc == 2)
    printSpace();
}

string readString() {
  static char buf[3341000];
  scanf("%s", buf);
  return string(buf);
}

char *readCharArray() {
  static char buf[3341000];
  static int bufUsed = 0;
  char *ret = buf + bufUsed;
  scanf("%s", ret);
  bufUsed += strlen(ret) + 1;
  return ret;
}

template <class T, class U> void chmax(T &a, U b) {
  if (a < b)
    a = b;
}

template <class T, class U> void chmin(T &a, U b) {
  if (b < a)
    a = b;
}

const int mod = 1e9 + 7;
const int inf = 1e9 + 5;

signed main() {
  int x = read();
  int sum = 0, ans = 0, i = 1;
  while (sum < x) {
    sum += i++;
    ans++;
  }
  print(ans);
}


Measured memory_bytes: 256
S = input()

if len(S) % 2 == 0:
    count = 0
    for i in range(int(len(S) // 2)):
        if S[i] != S[- 1 - i]:
            count += 1
else:
    count = 0
    for i in range(int(len(S) // 2)):
        if S[i] != S[- 1 - i]:
            count += 1

print(count)

Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
int main(void) {
  int N;
  cin >> N;
  bool isFour = false;
  for (int i = 0; i < N; i++) {
    string s;
    cin >> s;
    if (s == "Y") isFour = true;
  }
  if (isFour) cout << "Four" << endl;
  else cout << "Three" << endl;
  return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<cstring>
using namespace std;
int main()
{
    char s[100000];
    cin>>s;
    long long t=strlen(s);
    if(s[0]==s[strlen(s)-1]){
    	if(t%2==1) cout<<"Second"<<endl;
    	else cout<<"First"<<endl;
	}
	else{
		if(t%2==0) cout<<"Second"<<endl;
    	else cout<<"First"<<endl;
	}
    return 0;
}

Measured memory_bytes: 384
N = int(input())
d = {}
for i in range(N):
  key = input()
  if key in d:
    d[key] += 1
  else:
    d[key] = 1
d_max = max(d.values())
l_max = [kv[0] for kv in d.items() if kv[1] == d_max]
l_max.sort()
for ch in l_max:
  print(ch)

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


int main(){

  int n;
  cin>>n;
  ll sum = 0;
  rep(i,n){
    if(i%3 != 0 && i%5 !=0){
      sum+=i ;
    }

  }
  cout<<sum<<endl;
}


Measured memory_bytes: 3652
#include <iostream>
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<vector>
#include<cmath>
#include<queue>
#include<string>
#include<set>
#include<map>
#include<bitset>
#include<stack>
#define UP(i,l,h) for(int i=l;i<h;i++)
#define DOWN(i,h,l) for(int i=h-1;i>=l;i--)
#define W(a) while(a)
#define MEM(a,b) memset(a,b,sizeof(a))
#define INF 0x3f3f3f3f3f3f3f3f
#define LL long long
#define MAXN 100010
#define SIZE 95
#define EPS 1e-10
#define MOD 1000000007

using namespace std;

int main(){
    int n;
    scanf("%d",&n);
    int x;
    int four=0,two=0,one=0;
    UP(i,0,n){
        scanf("%d",&x);
        if(x%4==0){
            four++;
        }else if(x%2==0){
            two++;
        }else{
            one++;
        }
    }
    if(two>=1){
        one++;
    }
    one-=(four+1);
    if(one>0){
        puts("No");
    }else{
        puts("Yes");
    }
}


Measured memory_bytes: 256
#include<iostream>
#include<bits/stdc++.h>
#define vSumMax 100010
#define nMax 110
#define wMax 1000000000
using namespace std;
int dp[vSumMax][nMax]={INT_MAX};
bool vals[vSumMax][nMax]={0};
int fun(int r,int i,vector<int>&w,vector<int>&v,int n)
{
  if(r<=0)
  return 0;
  if(i==n)
  return wMax;
  if(vals[r][i])
  return dp[r][i];
  vals[r][i]=1;
  dp[r][i]=min(fun(r,i+1,w,v,n),w[i]+fun(r-v[i],i+1,w,v,n));
  return dp[r][i];
}
int util(vector<int>&w,vector<int>&v,int W)
{
  int n=w.size(),vSum=0;
  for(auto val:v)
  vSum+=val;
  for(int i=vSum;i>=0;i--)
  {
    if(fun(i,0,w,v,n)<=W)
    return i;
  }
  return 0;
}
int main()
{
  int n,W;
  cin>>n>>W;
  vector<int> w,v;
  for(int i=0;i<n;i++)
  {
    int tw,tv;
    cin>>tw>>tv;
    w.push_back(tw);
    v.push_back(tv);
  }
  int ans=util(w,v,W);
  cout<<ans<<endl;
  return 0;
}


Measured memory_bytes: 53504
#include <bits/stdc++.h>
using namespace std;
 
const int N = 2e4 + 7;
int t = 20001;
int p[N], a[N], b[N];
int n; 
 
int main() {
	cin >> n;
	for (int i = 1; i <= n; i++){
		cin >> p[i]; 
	} 
	for (int i = 1; i <= n; i++) {
 		a[i] = i * 2 * t;
		b[i] = (n - i + 1) * 2 * t; 
	} 
	for (int i = 2; i <= n; i++) {
		b[p[i]] += i;
	}
	for (int i = 1; i <= n; i++)
		cout << a[i] << " ";
	cout << endl;
	for (int i = 1; i <= n; i++)
		cout << b[i] << " ";	
		
 
}	

Measured memory_bytes: 896
import sys
sys.setrecursionlimit(10**7) #再帰関数の上限,10**5以上の場合python
import math
from copy import copy, deepcopy
from copy import deepcopy as dcp
from operator import itemgetter
from bisect import bisect_left, bisect, bisect_right#2分探索
#bisect_left(l,x), bisect(l,x)#aはソート済みである必要あり。aの中からx未満の要素数を返す。rightだと以下
from collections import deque
#deque(l), pop(), append(x), popleft(), appendleft(x)
#q.rotate(n)で → にn回ローテート
from collections import Counter#文字列を個数カウント辞書に、
#S=Counter(l),S.most_common(x),S.keys(),S.values(),S.items()
from itertools import accumulate,combinations,permutations#累積和
#list(accumulate(l))
from heapq import heapify,heappop,heappush
#heapify(q),heappush(q,a),heappop(q) #q=heapify(q)としないこと、返り値はNone
#import fractions#古いatcoderコンテストの場合GCDなどはここからimportする
from functools import lru_cache#pypyでもうごく
#@lru_cache(maxsize = None)#maxsizeは保存するデータ数の最大値、2**nが最も高効率
from decimal import Decimal

def input(): 
    x=sys.stdin.readline()
    return x[:-1] if x[-1]=="\n" else x
def printl(li): _=print(*li, sep="\n") if li else None
def argsort(s, return_sorted=False): 
    inds=sorted(range(len(s)), key=lambda k: s[k])
    if return_sorted: return inds, [s[i] for i in inds]
    return inds
def alp2num(c,cap=False): return ord(c)-97 if not cap else ord(c)-65
def num2alp(i,cap=False): return chr(i+97) if not cap else chr(i+65)
def matmat(A,B):
    K,N,M=len(B),len(A),len(B[0])
    return [[sum([(A[i][k]*B[k][j]) for k in range(K)]) for j in range(M)] for i in range(N)]
def matvec(M,v):
    N,size=len(v),len(M)
    return [sum([M[i][j]*v[j] for j in range(N)]) for i in range(size)]
def T(M):
    n,m=len(M),len(M[0])
    return [[M[j][i] for j in range(n)] for i in range(m)]
def main():
    mod = 1000000007
    #w.sort(key=itemgetter(1),reversed=True)  #二個目の要素で降順並び替え

    #N = int(input())
    #N, K = map(int, input().split())
    #A = tuple(map(int, input().split())) #1行ベクトル
    #L = tuple(int(input()) for i in range(N)) #改行ベクトル
    #S = tuple(tuple(map(int, input().split())) for i in range(N)) #改行行列

    s=input()
    N=len(s)
    f=1
    if s[-1]=="1" or s[0]=="0":
        f=0
    for i in range(1,N//2+1):
        if s[i-1]!=s[N-i-1]:
            f=0
            break
    if not f:
        print(-1)
        return
    
    il=[]
    edge=[]
    for i in range(1,N//2+1):
        if s[i-1]=="0":
            il.append(i)
        else:
            for j in il:
                edge.append((i,j))
            il=[i]
    i=N//2+1
    for j in il:
        edge.append((i,j))
    j=i
    for i in range(N//2+2,N+1):
        edge.append((j,i))

    for e in edge:
        print(*e)







if __name__ == "__main__":
    main()

Measured memory_bytes: 90372
n = gets.to_i
a = Array.new(n) { Array.new(2) }
n.times do |i|
  a[i][0], a[i][1] = gets.split.map(&:to_i)
end

max = 0
maxi = 0
n.times do |i|
  if a[i][0] > max
    max = a[i][0]
    maxi = i
  end
end

p a[maxi][0] + a[maxi][1]


Measured memory_bytes: 9340
#include<stdio.h>
#include<string.h>
#define N 36
  
typedef struct{
  char mark;
  int value;
}card;

void BubbleSort(card *c,int n){
  int i,j;
  card tmp;
  for(i=0;i<n;i++){
    for(j=n-1;j>i;j--){
      if(c[j].value<c[j-1].value){
	tmp = c[j];
	c[j]=c[j-1];
	c[j-1]=tmp;
      }
    }
  }
}
void SelectionSort(card *c,int n){
  int i,j,min;
  card tmp;
  for(i=0;i<n;i++){
    min = i;
    for(j=i;j<n;j++){
      if(c[j].value<c[min].value){
	min = j;
      }
    }
    tmp = c[i];
    c[i]=c[min];
    c[min]=tmp;
  }
}


int main(){
  int n, i;
  card c1[N], c2[N];
  int flag =0;
  scanf("%d", &n);
  for(i=0;i<n;i++){
    scanf(" %c%d",&c1[i].mark,&c1[i].value);
  }

  for(i=0;i<n;i++) c2[i]=c1[i];

  BubbleSort(c1,n);
  
  for(i=0;i<n-1;i++) printf("%c%d ",c1[i].mark,c1[i].value);
  printf("%c%d\n",c1[n-1].mark,c1[n-1].value);
  printf("Stable\n");

  SelectionSort(c2,n);
  for(i=0;i<n-1;i++) printf("%c%d ",c2[i].mark,c2[i].value);
  printf("%c%d\n",c2[n-1].mark,c2[n-1].value);
  
for(i=0;i<n;i++) if(c1[i].mark!=c2[i].mark) flag++;
  if(flag==0) printf("Stable\n");
  else printf("Not stable\n");

  return 0;
}

Measured memory_bytes: 608
#pragma 03
#pragma GCC target("avx")
#pragma GCC optimization ("unroll-loops")
#define _CRT_SECURE_NO_WARNINGS
#include <bits/stdc++.h>
#include <unordered_map>
#include <unordered_set>
using namespace std;
#define int long long
#define eb emplace_back
#define ef emplace_front
#define rep(i, x, n) for (int i = x; i < n; ++i)
#define mp make_pair
#define fi first
#define se second
#define ii pair<int, int>
#define endl '\n'
#define vi vector<int>
#define vii vector<pair<int, int>>
#define reverse(s) reverse(s.begin(), s.end())
#define ld long double
#define vs vector<string>
#define inf INT_MAX
#define vc vector<char>
#define fastio ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define vb vector<bool>
#define lb(a, x) lower_bound(a.begin(), a.end(), x)
#define ub(a, x) upper_bound(a.begin(), a.end(), x) 
#define vvi vector<vi>
#define mine(a) min_element(a.begin(),a.end())
#define maxe(a) max_element(a.begin(), a.end())
#define iota(a,i) iota(a.begin(),a.end(),i)
#define fileopen(filename) if (fopen(filename".INP", "r")) {freopen(filename".INP", "r", stdin);freopen(filename".OUT", "w", stdout);}
bool cmp(ii x, ii y) {
    if (x.first != y.first) return x.first > y.first;
    return x.second < y.second;
}
signed main() {
    fileopen("");
    fastio;
    int n;
    cin >> n;
    vii a(n + 1);
    vi ans(n + 1, 0);
    rep(i, 1, n + 1) {
        cin >> a[i].first;
        a[i].second = i;
    }
    a[0] = mp(inf, 0);
    sort(a.begin(), a.end(), cmp);
    /*for (ii i : a) cout << i.first << " " << i.second << endl;*/
    int sum = a[1].first, cnt = 1;
    ii pos = a[1];
    rep(i, 2, n + 1) {
        if (a[i].first < pos.first) {
            ans[pos.second] += sum - a[i].first * cnt;
            ++cnt;
            sum = a[i].first * cnt;
            if (a[i].second < pos.second) pos = a[i];
            else pos.first = a[i].first;
        }
        else {
            ++cnt;
            sum += a[i].first;
        }
    }
    ans[pos.second] += sum;
    rep(i, 1, n + 1) cout << ans[i] << endl;
}

Measured memory_bytes: 5552
#include <iostream>
#include <unordered_set>

using namespace std;

int main(){
    unordered_set<int> s;
    int N;
    int a;
    cin >> N;
    for(int i=0; i<N; i++){
        cin >> a;
        auto itr = s.find(a);
        if(itr == s.end()){
            s.insert(a);
        }else{
            s.erase(a);
        }
    }
    cout << s.size();
    return EXIT_SUCCESS;
}

Measured memory_bytes: 4388
#include<stdio.h>
#include<string.h>
#include<algorithm>
#include<stdlib.h>
#include<set>
//#include<math.h>
//#include<queue>
//#include<iostream>
using namespace std;

#define LL long long
LL a,b;
int main()
{
	scanf("%lld%lld",&a,&b);
	int ans=0;
	for (LL i=a;i<=b;i*=2) ans++;
	printf("%d\n",ans);
	return 0;
}

Measured memory_bytes: 128
#include <stdio.h>

int main()
{
    int w, h, x, y, r;
    
    scanf("%d %d %d %d %d", &w, &h, &x, &y, &r);
    
    if (x >= r && x + r <= w && y >= r && y + r <= h){
        printf("Yes\n");
    }else{
        printf("No\n");
    }
    
    return 0;
}

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

//#define int long long
typedef long long ll;

typedef unsigned long long ul;
typedef unsigned int ui;
const ll mod = 1000000007;
const ll INF = mod * mod;
const int INF_N = 1e+9;
typedef pair<int, int> P;
#define stop char nyaa;cin>>nyaa;
#define rep(i,n) for(int i=0;i<n;i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define per1(i,n) for(int i=n;i>=1;i--)
#define Rep1(i,sta,n) for(int i=sta;i<=n;i++)
#define all(v) (v).begin(),(v).end()
typedef pair<ll, ll> LP;
typedef long double ld;
typedef pair<ld, ld> LDP;
const ld eps = 1e-12;
const ld pi = acos(-1.0);
//typedef vector<vector<ll>> mat;
typedef vector<int> vec;

//繰り返し二乗法
ll mod_pow(ll a, ll n, ll m) {
	ll res = 1;
	while (n) {
		if (n & 1)res = res * a%m;
		a = a * a%m; n >>= 1;
	}
	return res;
}

struct modint {
	ll n;
	modint() :n(0) { ; }
	modint(ll m) :n(m) {
		if (n >= mod)n %= mod;
		else if (n < 0)n = (n%mod + mod) % mod;
	}
	operator int() { return n; }
};
bool operator==(modint a, modint b) { return a.n == b.n; }
modint operator+=(modint &a, modint b) { a.n += b.n; if (a.n >= mod)a.n -= mod; return a; }
modint operator-=(modint &a, modint b) { a.n -= b.n; if (a.n < 0)a.n += mod; return a; }
modint operator*=(modint &a, modint b) { a.n = ((ll)a.n*b.n) % mod; return a; }
modint operator+(modint a, modint b) { return a += b; }
modint operator-(modint a, modint b) { return a -= b; }
modint operator*(modint a, modint b) { return a *= b; }
modint operator^(modint a, int n) {
	if (n == 0)return modint(1);
	modint res = (a*a) ^ (n / 2);
	if (n % 2)res = res * a;
	return res;
}

//逆元(Eucledean algorithm)
ll inv(ll a, ll p) {
	return (a == 1 ? 1 : (1 - p * inv(p%a, a)) / a + p);
}
modint operator/(modint a, modint b) { return a * modint(inv(b, mod)); }

const int max_n = 1 << 18;
modint fact[max_n], factinv[max_n];
void init_f() {
	fact[0] = modint(1);
	for (int i = 0; i < max_n - 1; i++) {
		fact[i + 1] = fact[i] * modint(i + 1);
	}
	factinv[max_n - 1] = modint(1) / fact[max_n - 1];
	for (int i = max_n - 2; i >= 0; i--) {
		factinv[i] = factinv[i + 1] * modint(i + 1);
	}
}
modint comb(int a, int b) {
	if (a < 0 || b < 0 || a < b)return 0;
	return fact[a] * factinv[b] * factinv[a - b];
}
using mP = pair<modint, modint>;

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




void solve() {
    string s; cin >> s;
    int n = s.size();
    int sc=0, res=0;
    rep(i, n){
        if(s[i] == 'S'){
            sc++;
        }else{
            if(sc > 0){
                sc--;
                res++;
            }
        }
    }
    cout << n-2*res << endl;
}

signed main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  //cout << fixed << setprecision(10);
  //init_f();
  //init();
  //int t; cin >> t; rep(i, t)solve();
  solve();
//   stop
    return 0;
}


Measured memory_bytes: 4816
//
// Inversion Number of array a
//   a_i > a_j となる (i < j) の組の個数を数えます
//
// verified
//   AOJ Course ALDS1_5_D Recursion / Divide and Conquer - The Number of Inversions
//    http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=ALDS1_5_D&lang=jp
//


#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;

template <class Abel> struct BIT {
    const Abel UNITY_SUM = 0;						// to be set
    vector<Abel> dat;
    
    /* [1, n] */
    BIT(int n) : dat(n + 1, UNITY_SUM) { }
    void init(int n) { dat.assign(n + 1, UNITY_SUM); }
    
    /* a is 1-indexed */
    inline void add(int a, Abel x) {
        for (int i = a; i < (int)dat.size(); i += i & -i)
            dat[i] = dat[i] + x;
    }
    
    /* [1, a], a is 1-indexed */
    inline Abel sum(int a) {
        Abel res = UNITY_SUM;
        for (int i = a; i > 0; i -= i & -i)
            res = res + dat[i];
        return res;
    }

    /* [a, b), a and b are 1-indexed */
    inline Abel sum(int a, int b) {
        return sum(b - 1) - sum(a - 1);
    }
    
    /* debug */
    void print() {
        for (int i = 1; i < (int)dat.size(); ++i) cout << sum(i, i + 1) << ",";
        cout << endl;
    }
};

template<class T> long long inversion_number(const vector<T> &a) {
    int n = (int)a.size();
    vector<T> b = a;
    sort(b.begin(), b.end());
    b.erase(unique(b.begin(), b.end()), b.end());

    long long res = 0;
    BIT<int> bit(n);
    for (int i = 0; i < n; ++i) {
        int order = lower_bound(b.begin(), b.end(), a[i]) - b.begin();
        ++order;
        res += bit.sum(order+1, n+1);
        bit.add(order, 1);
    }
    return res;
}



int main() {
    int n; cin >> n;
    vector<int> a(n); for (int i = 0; i < n; ++i) cin >> a[i];
    cout << inversion_number(a) << endl;
}  



Measured memory_bytes: 5228
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using u32 = uint32_t;
using vi = vector<int>;    using vvi = vector<vi>;
using vb = vector<bool>;   using vvb = vector<vb>;
using vl = vector<ll>;     using vvl = vector<vl>;
using vd = vector<double>; using vvd = vector<vd>;

#define MAXC(c, x) (c = max(c, x))
#define MINC(c, x) (c = min(c, x))

#define REP(i,n) for(auto i = 0 * (n), i##_len = (n); i < i##_len; ++i)
#define ALL(c) (c).begin(), (c).end()
#define FOR(i,s,n) for(ll i=s, i##_len=(ll)(n); i<i##_len; ++i)
#define TEN(x) ((ll)1e##x)
const ll mod = TEN(9) + 7;

const ll INF = 1e9;

int main() {
	#ifdef INPUT_FROM_FILE
	ifstream cin("sample.in");
	ofstream cout("sample.out");
	#endif
	cin.tie(0);
	ios_base::sync_with_stdio(false);
	cout << fixed << setprecision(50);
	ll n, m; cin >> n >> m;
	vvl path(n);
	ll head, tail;
	REP(i, m) {
		ll u, v; cin >> u >> v;
		path[u - 1].push_back(v - 1);
		path[v - 1].push_back(u - 1);
		head = u - 1;
		tail = v - 1;
	}
	vb used(n, false);
	used[head] = used[tail] = true;
	
	deque<ll> p;
	p.push_back(head); p.push_back(tail);
	while (true) {
		bool b = true;
		for (auto to : path[head]) if (!used[to]) {
			used[to] = true;
			p.push_front(to);
			head = to;
			b = false;
			break;
		}
		if (b) break;
	}

	while (true) {
		bool b = true;
		for (auto to : path[tail]) if (!used[to]) {
			used[to] = true;
			p.push_back(to);
			tail = to;
			b = false;
			break;
		}
		if (b) break;
	}

	cout << p.size() << endl;
	REP(i, p.size()) {
		cout << p[i] + 1 << (i == p.size() - 1 ? "" : " ");
	}
	cout << endl;
}


Measured memory_bytes: 7168
#include <bits/stdc++.h>
#define REP(i,n) for (int i = 0; i < (n); i++)
#define ALL(a) a.begin(), a.end()
#define RALL(a) a.rbegin(), a.rend()
using namespace std;
using ll = long long;
const ll MOD = 1000000007;
const ll INF = MOD * MOD;

int main() {

    int a, b;
    cin >> a >> b;
    
    if(a+b < 10) cout << a+b << endl;
    else cout << "error" << endl;
    
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <algorithm>
#include <cstdio>
#include <utility>
#include <string>
#include <cmath>
#include <cstdlib>
#include <cstring>
#include <deque>
#include <numeric>

using namespace std;

typedef uint64_t u64;
typedef int64_t s64;
typedef uint32_t u32;
typedef int32_t s32;
typedef vector<s32> vs32;
typedef vector<u32> vu32;
typedef vector<s64> vs64;
typedef vector<u64> vu64;

const double PI=3.14159265358979323846;

#define MAX(x, y) ((x) < (y) ? (y) : (x))
#define MIN(x, y) ((x) > (y) ? (y) : (x))

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

#define CEIL(x, y) (((x) + (y) - 1) / (y))
#define MOD 1000000007ULL

#define IN(l, r, x) ((l) <= (x) && (x) < (r))


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

    int n, q;
    cin >> n >> q;

    vector< vs32 > g(n);
    int a, b;
    rep (i, n - 1)
    {
        cin >> a >> b;
        --a; --b;
        g[a].push_back(b);
        g[b].push_back(a);
    }

    vs32 ans(n, 0);
    rep (i, q)
    {
        cin >> a >> b;
        --a;
        ans[a] += b;
    }

    vector< bool > reached(n, false);
    queue<int> que;
    que.push(0);
    while (!que.empty())
    {
        int u = que.front(); que.pop();
        reached[u] = true;

        for (auto v : g[u])
        {
            if (reached[v]) continue;
            ans[v] += ans[u];
            que.push(v);
        }
    }

    rep (i, n)
    {
        if (i > 0) cout << " ";
        cout << ans[i];
    }
    cout << "\n";
    return 0;
}



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

int main()
{
	int h, w;
	char s[101][101];
	int t[100][100];

	cin >> h >> w;

	for (int i = 0; i < h; i++)
		cin >> s[i];

	for (int i = 0; i < h; i++) {
		int j = 0;
		while (s[i][j] == '.') {
			t[i][j] = -1;
			j++;
		}
		while (j < w) {
			while (s[i][j] == 'c') {
				t[i][j] = 0;
				j++;
			}
			int u = 1;
			while (s[i][j] == '.') {
				t[i][j] = u;
				j++;
				u++;
			}
		}
	}

	for (int i = 0; i < h; i++) {
		for (int j = 0; j < w - 1; j++)
			cout << t[i][j] << " ";
		cout << t[i][w - 1] << endl;
	}

	return 0;
}


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

int trans(char c){
  if(c=='a')return 0;
  if(c=='b')return 1;
  if(c=='c')return 2;
  if(c=='d')return 3;
  if(c=='e')return 4;
  if(c=='f')return 5;
  if(c=='g')return 6;
  if(c=='h')return 7;
  if(c=='i')return 8;
  if(c=='j')return 9;
  if(c=='k')return 10;
  if(c=='l')return 11;
  if(c=='m')return 12;
  if(c=='n')return 13;
  if(c=='o')return 14;
  if(c=='p')return 15;
  if(c=='q')return 16;
  if(c=='r')return 17;
  if(c=='s')return 18;
  if(c=='t')return 19;
  if(c=='u')return 20;
  if(c=='v')return 21;
  if(c=='w')return 22;
  if(c=='x')return 23;
  if(c=='y')return 24;
  if(c=='z')return 25;
  return -1;
}

int main(){
  string w;
  std::cin >> w;
  int i=0;
  int al[26]={};
  do {
    al[trans(w[i])]++;
    i++;
  } while(i!=w.length());

  bool succes=true;
  for (int i = 0; i < 26; i++) {
    if(al[i]%2==1)succes=false;
  }

  if(succes==true)std::cout << "Yes" << '\n';
  else std::cout << "No" << '\n';


return 0;
}


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

using namespace std;

#define ll long long

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

	vector < ll > x(N), y(N), h(N);
	for (int i = 0; i < N; i++) {
		cin >> x[i] >> y[i] >> h[i];
	}

	for (int i = 0; i <= 100; i++) {
		for (int j = 0; j <= 100; j++) {
			ll height = 0;
			for (int k = 0; k < N; k++) {
				if (h[k] != 0) {
					height =
					    h[k] + abs(x[k] - i) + abs(y[k] -
								       j);
					break;
				}
			}
			bool isValid = true;

			for (int k = 0; k < N; k++) {
				ll hh =
				    max(height - abs(x[k] - i) - abs(y[k] - j),
					0LL);
				if (hh != h[k]) {
					isValid = false;
					break;
				}
			}
			if (isValid) {
				cout << i << " " << j << " " << height << endl;
			}
		}
	}

	return 0;
}


Measured memory_bytes: 256
import sys
sys.setrecursionlimit(300000)
from bisect import bisect_right, bisect_left

def I(): return int(sys.stdin.readline())
def MI(): return map(int, sys.stdin.readline().split())
def MI0(): return map(lambda s: int(s) - 1, sys.stdin.readline().split())
def LMI(): return list(map(int, sys.stdin.readline().split()))
def LMI0(): return list(map(lambda s: int(s) - 1, sys.stdin.readline().split()))
MOD = 10 ** 9 + 7
INF = float('inf')


X, N = MI()
if N == 0:
    print(X)
    exit()
else:
    P = LMI()
P.sort()
ng = set(P)
m = INF
ans = -1
l, r = min(X - 1, P[0]), max(X + 1, P[-1] + 1)
for i in range(l - 100, r + 100):
    if i in ng:
        continue
    if abs(X - i) < m:
        m = abs(X - i)
        ans = i
print(ans)




Measured memory_bytes: 62148
#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;
int main() {
	int N;
	int ans = 0;
	cin >> N;
	vector<int> V(N), C(N), d(N);
	for (int i = 0; i < N; i++) {
		cin >> V[i];
	}
	for (int i = 0; i < N; i++) {
		cin >> C[i];
	}
	for (int i = 0; i < N; i++) {
		d[i] = V[i] - C[i];
	}

	for (int i = 0; i < N; i++) {
		if (d[i] > 0) {
			ans += d[i];
		}
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <string>
#include <algorithm>
#include <utility>
#include <cmath>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#define rep(i, n) for(int i = 0; i < n; i++)
using namespace std;
typedef long long ll;
const ll mod = 1000000007;

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

    ll w[n], v[n];
    rep(i, n) {
        cin >> w[i] >> v[i];
    }

    vector<vector<ll>> dp(n+1, vector<ll>(W+1));

    rep(i, n) {
        rep(j, W+1) {
            if(j < w[i]) {
                dp[i+1][j] = dp[i][j];
            }
            else {
                dp[i+1][j] = max(dp[i][j], dp[i][j-w[i]] + v[i]);
            }
        }
    }

    cout << dp[n][W] << endl;
    return 0;
}

Measured memory_bytes: 80256
#include <iostream>
#include <string>
using namespace std;
int main(){
  int n, m;
  cin >> n >> m;
  int key[n], pen[n];
  for(int i=0; i<n; i++){
    key[i]=0;
    pen[i]=0;
  }
  int p, cor=0, pensum=0;
  string s;
  for(int i=1; i<=m; i++){
    cin >> p >> s;
    if(key[p-1]==1) continue;
    if(s=="AC") {
      cor++;
      key[p-1]=1;
      pensum+=pen[p-1];
    }
    else{
      pen[p-1]++;
    }
  }
  cout << cor << " " << pensum;
  return 0;
}


Measured memory_bytes: 1024
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <map>
#include <queue>
#define rep(i,cc,n) for(int i=cc;i<=n;++i)
#define drep(i,cc,n) for(int i=cc;i>=n;--i)
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
const long long INF = 1LL <<60;
typedef long long ll;
using namespace std;
 
ll gcd(ll a, ll b) {
    if (b==0) return a;
    else return gcd(b, a%b);
}
 
ll lcm(ll a, ll b) {
    return a * b / gcd(a, b);
}
 
ll choose2(ll n){
    return n*(n-1)/2;
}
 
int main() {
    int x;
    cin>>x;
    vector<int> ans;
    ans.push_back(1);
    rep(i,2,x){
        int ex = 2;
        while(1){
            ll tmp = pow(i,ex);
            if(tmp > x) break;
            else ans.push_back(tmp);
            ex++;
        }
    }
    sort(ans.begin(),ans.end());
    cout<<ans[ans.size()-1]<<endl;
    return 0;
}

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

#define rep(i, n) REP(i, 0, n)
#define REP(i,k,n) for(int i = k; i < n; i++)
#define mmax(start, end) *max_element(start, end)
#define mmin(start, end) *min_element(start, end)
#define argmax max_element
#define argmin min_element
#define push push_back
#define pop pop_back
#define ALL(x) (x).begin(), (x).end()

typedef long long ll;
typedef string str;

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

template<class T = ll> T in() {
    T _in;
    cin >> _in;
    return _in;
}

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

    int N = in<int>();
    int A[200000];
    rep(i, N)
        cin >> A[i];

    int right = 1;
    ll ans = 0;
    ll sum = A[0];
    for(int left = 0; left < N; left++) {
        while (right < N && (right <= left || ((sum^A[right]) == sum+A[right]))) {
           // (rightを進めたり部分列の和積を変えたりする)
           sum += A[right++];
        }

        // rightが伸びきった部分列でansに答えを追記
        ans += right - left;
        // cout << left+1 << " " << right+1 << endl;

        if (right == left) {
            right++; // 追いついたらrightを進める
        } else {
            // (leftを進めることによる部分列の変更など)
            sum -= A[left];
        }
    }

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 1024
import math
from itertools import permutations

def solve():
    n = int(input())
    cord = [list(map(int, input().split())) for _ in range(n)]
    # print(cord)
    dist = {}
    for i in range(n):
        for j in range(n):
            if i == j: continue
            d = math.sqrt(pow(cord[i][0] - cord[j][0], 2) + pow(cord[i][1] - cord[j][1], 2))
            dist[(i, j)] = d
    # print(dist)
    sm = 0
    for cnt, i in enumerate(permutations(range(n))):
        # print(i)
        for j in range(1, n):
            # print('aaa', i[j-1], i[j])
            d = dist[(i[j-1], i[j])]
            # print(d)
            sm = sm + d
    print(sm / (cnt+1))


if __name__ == '__main__':
    solve()


Measured memory_bytes: 3064
# -*- coding: utf-8 -*-
n = int(input())
arr = [int(i) for i in input().split(" ")]
l = len(arr)
count = 0
for i in range(0, l-2):
    m = arr[i+1]
    tmp = [arr[i], arr[i+1], arr[i+2]]
    tmp.sort()
    if m == tmp[1]:
        count += 1
print(count)


Measured memory_bytes: 3060
<?php
$s = trim(fgets(STDIN));
$str = str_split($s);

for($i=0; $i<count($str); $i++){
    $result = array_keys($str, $str[$i]);
    if(count($result) != 2){
        echo "No";
        exit;
    }
}
echo "Yes";
?>

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

#include <string>
int main(){
    string s,t;cin >> s >> t;
    int maxi = 0;
    for(int i=0; i<s.size()-t.size()+1; i++) {
        int count = 0;
        for(int j=0; j<t.size(); j++) {
            if(s.at(i+j)==t.at(j)) count++;
        }
        maxi = max(maxi,count);
        if(maxi == t.size()) break;
    }
    cout << t.size()-maxi << endl;
}

Measured memory_bytes: 3624
#include <cstdio>
#include <string>
#include <unordered_set>
const int MAXS = 15;
std::unordered_set<std::string> seen;
char S[MAXS];
int N;

int main() {
  scanf("%d", &N);
  seen.clear();
  seen.reserve(N);
  for (int i = 0; i < N; ++i) {
    scanf(" %s", S);
    seen.insert(S);
  }
  printf("%lu\n", seen.size());
  return 0;
}

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

#define fi first
#define se second
#define pb push_back
#define sz(a) (int)(a).size()
using ll = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using vi = vector<int>;
using vvi = vector<vi>;
using vll = vector<ll>;
using vvll = vector<vll>;

const ll MOD = 1e9 + 7;
const ll INF = 1e18;
const ll IINF = INT_MAX;

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    int a, b, c, k;
    cin >> a >> b >> c >> k;
    int ans = min(a, k);
    k -= min(a, k);
    k -= min(b, k);
    ans -= min(c, k);
    cout << ans << '\n';
    return 0;
}

Measured memory_bytes: 3664
import sys
input=sys.stdin.readline
n,m=map(int,input().split())
tr=[[] for i in range(n+1)]
for i in range(m):
  a,b=map(int,input().split())
  if a!=1 and b!=n:
    continue
  tr[a].append(b)
  tr[b].append(a)
for i in range(2,n):
  if len(tr[i])==2:
    print("POSSIBLE")
    break
else:
  print("IMPOSSIBLE")


Measured memory_bytes: 37688
#include <iostream>
#include <vector>
#include <limits.h>
#include <algorithm>
#include <string>
#include <math.h>
#include <limits.h>
#include <queue>
#include <map>
#include <set>
#include <iomanip>
#include <bitset>
#include <cassert>
#include <random>
#include <functional>
#include <stack>
#include <iomanip>
#include <cassert>
//#include <boost/multiprecision/cpp_int.hpp>
using namespace std;
const long long MOD = 1e9 + 7;
typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> pll;
typedef pair<ld, ll> pdl;
typedef pair<ld, ld> pdd;
//typedef boost::multiprecision::cpp_int bigint;

ld T, X;

int main() {
	cin >> T >> X;
	cout << setprecision(12) << T / X << endl;
	return 0;
}

Measured memory_bytes: 256
/*|In The Name Of Allah|*/

#include <bits/stdc++.h>

using namespace std;

const int N = 1e5+5;

const int mod = 1e9+7;

int n;
int m;
vector < int > profit[N];

int main(){
    scanf("%d%d" , &n , &m);
    for(int i = 1; i <= n; i++){
        int a , b;
        scanf("%d%d" , &a , &b);
        if(a > m)
            continue;
        profit[m - a].push_back(b);
    }
    int ans = 0;
    priority_queue < int > best;
    for(int i = m-1; i >= 0; i--){
        for(auto v : profit[i]){
            best.push(v);
        }
        if(best.size()){
            ans += best.top();
            best.pop();
        }
    }
    printf("%d\n" , ans);
}





Measured memory_bytes: 5632
#include<bits/stdc++.h>
#define int long long
#define PB push_back
#define FI first
#define SE second
using namespace std;
static const int MAX_N = 1<<17;
static const int inf = 1ll<<6;
typedef pair<int,int> PII;

int N;
vector<PII> V;

class Segment{
public:
    int dp[2*MAX_N];
    int n;

    void init(int n_){
        n=1;
        while(n<n_)n*=2;
        for(int i=0;i<2*n-1;++i)dp[i]=-inf;
    }

    void update(int k,int a){
        k+=n-1;
        dp[k]=a;
        while(k>0){
            k=(k-1)/2;
            dp[k]=max(dp[2*k+1],dp[2*k+2]);
        }
    }

    int query(int a,int b,int k,int l,int r){
        if(r<=a||b<=l)return -inf;
        if(a<=l&&r<=b)return dp[k];
        else{
            int vl=query(a,b,2*k+1,l,(l+r)/2);
            int vr=query(a,b,2*k+2,(l+r)/2,r);
            return max(vl,vr);
        }
    }
};

int res;

signed main(){
    cin>>N;
    Segment seg;
    seg.init(N);
    int MAX=N*(N+1)/2;
    for(int i=0;i<N;++i){
        int a;
        cin>>a;
        V.PB(PII(a,-i));
    }
    sort(V.begin(),V.end());
    for(int i=0;i<N;++i){
        int j=-V[i].SE;
        seg.update(j,V[i].FI);
        seg.update(j,max(seg.dp[j+seg.n-1],seg.query(0,j,0,0,seg.n)+V[i].FI));
    }
    cout<<MAX-seg.dp[0]<<endl;
}

Measured memory_bytes: 5144
#include <stdio.h>

int main(void) {
	int a,b,c;
	scanf("%d%d%d",&a,&b,&c);
	if(a<=b && b<=c){
		printf("%d %d %d\n",a,b,c);
	}else if(a<=c && c<=a){
		printf("%d %d %d\n",a,c,b);
	}else if(b<=a && a<=c){
		printf("%d %d %d\n",b,a,c);
	}else if(b<=c && c<=a){
		printf("%d %d %d\n",b,c,a);
	}else if(c<=a && a<=b){
		printf("%d %d %d\n",c,a,b);
	}else if(c<=b && b<=a){
		printf("%d %d %d\n",c,b,a);
	}
	return 0;
}

Measured memory_bytes: 596