akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <vector>
#include <algorithm>
#include <cstdio>
#include <cmath>
#include <set>

#define X first
#define Y second

using namespace std;

pair<int, int> c[200010];

int sgn(int a) {
   if (a == 0) return 0;
   return (a < 0) ? -1 : 1;
}

int LIS (vector<pair<int, int> > vec) {
   set<int> s;
   for (int i = 0 ; i < vec.size() ; ++i) {
      if (s.empty()) s.insert(vec[i].Y);
      else {
         set<int>::iterator it = s.lower_bound(vec[i].Y);
         if (it != s.end()) s.erase(it);
         s.insert(vec[i].Y);
      }
   }
   return s.size();
}

const double pi = acos(-1);
int main() {
   int x1, y1, x2, y2;
   scanf("%d %d %d %d", &x1, &y1, &x2, &y2);
   if (x1 > x2) {
      swap(x1, x2);
      swap(y1, y2);
   }
   int n;
   scanf("%d", &n);
   for (int i = 0 ; i < n ; ++i) {
      scanf("%d %d", &c[i].X, &c[i].Y);
   }
   sort (c, c + n);
   vector<pair<int, int> > vec;
   for (int i = 0 ; i < n ; ++i) {
      if (c[i].X >= x1 && c[i].X <= x2 && 
            sgn(c[i].Y - y1) * sgn(c[i].Y - y2) <= 0) {
         vec.push_back(c[i]);
      }
   }
   int k = 0;
   if (y1 < y2) k = LIS(vec);
   else {
      reverse(vec.begin(), vec.end());
      k = LIS(vec);
   }

   double ans = 100.0 * (abs(x1 - x2) + abs(y1 - y2));
   if (k == min(abs(x1 - x2), abs(y1 - y2)) + 1) {
      ans -= (k - 1) * (20 - 5 * pi);
      ans += (10 * pi - 20);
   }
   else {
      ans -= k * (20 - 5 * pi);
   }
   printf("%0.12f\n", ans);
}


Measured memory_bytes: 14320
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cmath>
#include<vector>
#include<map>
#include<set>
#include<string>
#include<queue>
#include<stack>
#include<complex>
using namespace std;
#define MOD 1000000007
#define MOD2 998244353
#define INF (1<<29)
#define LINF (1LL<<60)
#define EPS (1e-10)
#define PI 3.1415926535897932384626433832795028
typedef long long Int;
typedef pair<Int, Int> P;
typedef long double Real;
typedef complex<Real> CP;



int main(){
    string str;
    int k;
    cin >> k >> str;

    if (k >= str.size()) {
        cout << str << endl;
    } else {
        cout << str.substr(0, k) << "..." << endl;
    }
    
    return 0;
}

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

int main() {
    int h, n;
    cin >> h >> n;
    for (int i = 0; i < n; i++) {
        int a;
        cin >> a;
        h -= a;
    }
    cout << (h <= 0 ? "Yes" : "No") << endl;
}

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

int main(void){
	while(1){
		int n; cin >> n;
		if(n == 0)return 0;

		vector<int> v;
		for (int i = 0; i < n; ++i){
			int t; cin >> t;
			v.push_back(t);
		}

		int cnt = 0;
		for (int i = 0; i < n; ++i){
			for (int j = 0; j < n - i - 1; ++j){
				if(v[j] > v[j + 1]){
					swap(v[j], v[j + 1]);
					cnt++;
				}
			}
		}
		cout << cnt << endl;
	}
}

Measured memory_bytes: 3072
#include <stdio.h>
#include <math.h>

int main(){
  int H,W,i,j;

  /*
  while(1){

    scanf("%d %d",&H,&W);

    if(H == 0 && W == 0){
      break;
    }

    for(i = 0;i < H;i++){
      if(i % 2 == 0){
	for(j = 0;j < W;j++){
	  if(j % 2 == 0){
	    printf("#");
	  }
	  else{
	    printf(".");
	  }
	}
      }

      else{
	for(j = 0;j < W;j++){
	  if(j % 2 == 0){
	    printf(".");
	  }
	  else{
	    printf("#");
	  }
	}
      }
      printf("\n");
    }
    printf("\n");
  }
  */
  while(1){
    scanf("%d %d",&H,&W);
    if(H == 0 && W == 0){
      break;
    }
    for(i = 0;i < H;i++){
      for(j = 0;j < W;j++){
	if( (i+j) % 2 == 0)  printf("#");
	else printf(".");
      }
      printf("\n");
    }
      printf("\n");
  }
  return 0;

}

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

#define rep(i, n) for(int i = 0; i < (n); i++)
using ll = long long;
constexpr ll INF = 1000000000;

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

using namespace std;
int main() {
	int n; cin >> n;
	
	vector<int>a(n);
	rep(i, n)cin >> a[i];

	vector<int>s(10);

	rep(i, n) {
		if (1 <= a[i] && a[i] < 400)s[0]++;
		if (400 <= a[i] && a[i] < 800)s[1]++;
		if (800 <= a[i] && a[i] < 1200)s[2]++;
		if (1200 <= a[i] && a[i] < 1600)s[3]++;
		if (1600 <= a[i] && a[i] < 2000)s[4]++;
		if (2000 <= a[i] && a[i] < 2400)s[5]++;
		if (2400 <= a[i] && a[i] < 2800)s[6]++;
		if (2800 <= a[i] && a[i] < 3200)s[7]++;
		if (3200 <= a[i])s[8]++;
	}
	int count = 0;
	
	rep(i, 8) {
		if (s[i] > 0) {
			count++;
		}
	}
	
	if (count == 0) {
		cout << 1 << ' ' << s[8] << endl;
	}
	else {
		cout << count << ' ' << count + s[8] << endl;
	}
}

Measured memory_bytes: 256
#include<stdio.h>
int main()
{
    int N, i, a, b, c;
    scanf("%d", &N);
    for(i=1;i<=N;i++)
    {
        scanf("%d %d %d", &a,&b,&c);
        if(a*a == b*b+c*c || b*b == a*a+c*c || c*c == a*a+b*b)
        {
            printf("YES\n");
        }
        else
        {
            printf("NO\n");
        }
    }

    return 0;

}



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

using namespace std;
const int MN = 1e5+7;

int dp[MN], n, h[MN];

int main()
{
    int k;
    cin >> n >> k;
    for(int i = 0; i < n; i++){
        cin >> h[i];
    }
    for(int i = 1; i < n; i++){
        dp[i] = 1e9+7;
        for(int x = 1; x <= k; x++){
            if(i >= x){
                dp[i] = min(dp[i], dp[i-x] + abs(h[i] - h[i-x]));
            }
        }
    }
    cout << dp[n-1];
}


Measured memory_bytes: 1024
#include<bits/stdc++.h>
#define REP(i,n) for(int i = 0; i < (n); ++i)
using namespace std;
typedef long long int ll;
const ll MOD = 1000000007;

int digsum(int n) {
  int res = 0;
  while(n > 0) {
    res += n%10;
    n /= 10;
  }
  return res;
}

int main() {
  int n, a, b, s, sum = 0;
  cin >> n >> a >> b;
  for (int i = 1; i <= n; ++i) {
    s = digsum(i);
    if (a <= s && s <= b) sum += i;
  }
  cout << sum << endl;
  return 0;
}

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

long long MOD = 998244353;
vector<long long> F, RF, R;

long long Comb(long long A, long long B) {
	return (F[A] * ((RF[A - B] * RF[B]) % MOD)) % MOD;
}

long long Calc(long long A, long long B) {
	if (B == 0) return 1;
	if (B % 2 == 0) {
		long long C = Calc(A, B / 2);
		return (C * C) % MOD;
	}
	return (A * Calc(A, B - 1)) % MOD;
}

int main() {
	long long N, NG = 0;
	cin >> N;
	F.resize(N + 1), RF.resize(N + 1), R.resize(N + 1);
	F[0] = F[1] = RF[0] = RF[1] = R[0] = R[1] = 1;
	for (int i = 2; i <= N; i++) {
		F[i] = (F[i - 1] * i) % MOD;
		R[i] = MOD - (R[MOD % i] * (MOD / i)) % MOD;
		RF[i] = (RF[i - 1] * R[i]) % MOD;
	}
	for (int X = N / 2 + 1; X <= N; X++) {
		int Y = N - X;
		long long COUNT = Comb(N, X);
		COUNT *= Calc(2, Y);
		COUNT %= MOD;
		NG = (NG + COUNT) % MOD;
	}
	cout << (Calc(3, N) - NG * 2 + MOD * 2) % MOD << endl;
}

Measured memory_bytes: 234624
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <queue>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>

using namespace std;

#define dump(x)  cerr << #x << " = " << (x) << endl;
#define PB push_back
#define MP make_pair
#define ll long long

inline int toInt(string s){int v;istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x){ostringstream sout;sout<<x;return sout.str();}

int main(){
    std::ios::sync_with_stdio(false);
    int a, b, c, d;
    cin >> a >> b >> c >> d;
    while(true)
    {
        c -= b;
        if(c <= 0)
        {
            cout << "Yes" << endl;
            break;
        }
        a -= d;
        if(a <= 0)
        {
            cout << "No" << endl;
            break;
        }
    }
}

Measured memory_bytes: 3660
from collections import deque
k,n = map(int, input().split())
a = list(map(int, input().split()))

mx = 0 
for i in range(n):
    if i == n-1:
        if mx < (k - a[n-1])+a[0]:
            mx=k-a[n-1]+a[0]
    else:
        if mx < a[i+1]-a[i]:
            mx = a[i+1] -a[i]
print(k-mx)



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

struct pos {
	int x;
	int y;
};

int main() {
	int n;
	std::cin >> n;
	std::vector<pos> v(n);
	for (int i = 0; i < n; i++) {
		std::cin >> v[i].x >> v[i].y;
	}
	std::sort(v.begin(), v.end(), 
		[](pos p0, pos p1) {
		if (p0.x < p1.x) return true;
		if (p0.x > p1.x) return false;
		if (p0.y < p1.y) return true;
		return false;
	});
	for (int i = 0; i < n; i++) {
		std::cout << v[i].x << " " << v[i].y << std::endl;
	}
}


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

int N;
#define MAX_N 200000
int A[MAX_N], B[MAX_N];
set<int> known;
long long res;

int main() {
  cin >> N;
  for(int i = 0; i < N; ++i) {
    cin >> A[i]; --A[i]; B[A[i]] = i;
  }
  known.insert(-1); known.insert(N);
  for(int i = 0; i < N; ++i) {
    long long mid = B[i];
    auto it = known.upper_bound(mid); long long hi = *it;
    --it; long long lo = *it;
    known.insert(mid);
    res += (i + 1) * (mid - lo) * (hi - mid);
  }
  cout << res << endl;
  return 0;
}


Measured memory_bytes: 11392
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define repf(i,a,n) for(int i = (int)(a); i < (int)(n); i++)

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

int main(){
    bool ansb = true;
    int ansi = 0;
    int p = 0;
    int a,n,k;
    vector<int> v;
    cin >> n ;
    rep(i,n){
        cin >> a;
        v.push_back(a);
    }
    sort(v.begin(),v.end());
    if(n%2!=0){
        ansi = 0;
    }else{
        ansi =v[(v.size()/2)] - v[(v.size()/2)-1];
    }
    cout << ansi << endl;
    
}

Measured memory_bytes: 892
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main {

	public static void main(String[] args) throws IOException {
		BufferedReader input =new BufferedReader (new InputStreamReader (System.in));
		String str = input.readLine( );

		while(str.contains("BB") || str.contains("WW")){
			if(str.contains("BB")){
				str = str.replace("BB", "B");
			}else{
				str = str.replace("WW", "W");
			}
		}
		System.out.println(str.length()-1);

	}
}


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

int main(){
	static int a[200003] = {}; int N; cin >> N;
	int id = 0;
	for(int i = 1 ; i <= N ; ++i){
		cin >> a[i];
		if(a[id] < a[i]) id = i;
	}
	for(int i = 1 ; i <= N ; ++i)
		if(i != id) cout << a[id] << endl;
		else{
			int p = 0;
			for(int j = 1 ; j <= N ; ++j)
				if(id != j && a[p] < a[j]) p = j;
			cout << a[p] << endl;
		}
	return 0;
}


Measured memory_bytes: 2432
from collections import defaultdict

N = int(input())
A = [int(input()) - 1 for _ in range(N)]

pushed = defaultdict(int)

def main(start=0):
     count = 0
     ls = start
     while True:
          if ls == 1:
               return count
          elif pushed[ls] != 0:
               return -1

          pushed[ls] += 1
          count += 1
          ls = A[ls]

print(main())

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


using namespace std;
typedef long long ll;
#define REP(i,n) for(int i=0; i<int(n); i++)
#define FOR(i,m,n) for(int i=int(m); i<int(n); i++)
#define ALL(obj) (obj).begin(),(obj).end()
#define VI vector<int>
#define VLL vector<long long>
#define VVI vector<vector<int>>
#define VVLL vector<vector<long long>>
#define VC vector<char>
#define VS vector<string>
#define VVC vector<vector<char>>
#define VB vector<bool>
#define VVB vector<vector<bool>>
#define fore(i,a) for(auto &i:a)

typedef pair <int, int> P;
template<class T> bool chmax(T &a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> bool chmin(T &a, T b) { if (a > b) { a = b; return true; } return false; }
const int  INF = 1 << 29;
const ll INFL = 1LL << 60;
const ll mod = 1000000007;




int main() {

	string s;
	cin >> s;
	
	bool b = true;


	VLL a;
	char c = s[0];
	int cur = 1;
	REP(i, s.size() - 1) {
		if (s[i + 1] != c) {
			a.push_back(cur);
			cur = 1;
			c = s[i+1];
		}
		else cur++;
	}
	a.push_back(cur);


	ll ans = 0;
	if (s[0] == '>') {
		ans += a[0] * (a[0] + 1) / 2;
	}
	int i = 0;
	if (s[0] == '>')i++;
	for (; i <a.size(); i++) {
		if (i + 1 == a.size()) {
			ans += a[i] * (a[i] + 1) / 2;
		}
		else {
			if (a[i] < a[i + 1]) {
				swap(a[i], a[i + 1]);
			}
			ans += a[i] * (a[i] + 1) / 2;
			ans += a[i + 1] * (a[i + 1] - 1) / 2;

			i++;
		}

	}
	cout << ans << endl;



}

Measured memory_bytes: 3068
#include <iostream>
#include <cstdio>
#include <cmath>
#include <algorithm>
#include <numeric>
#define rep(i, m, n) for(int i = m;i < n;i++)
#define repr(i, m, n) for(int i = m;i >= n;i--)
#define SORT(v, n) sort(v, v+n);
#define INF 999999999
using namespace std;

const int limit = 50;

int n, m;
bool vis[limit];
bool gra[limit][limit] = {false};
int a[limit] = {0};
int b[limit] = {0};

void dfs(int v){
    vis[v] = true;
    rep(v2, 0, n){
        if(gra[v][v2] == false) continue;
        if(vis[v2] == true) continue;
        dfs(v2);
    }
    return;
}

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

    //グラフ管理のため隣接行列を生成
    rep(i, 0, m){
        cin >> a[i] >> b[i];
        a[i]--;
        b[i]--;
        gra[a[i]][b[i]] = true;
        gra[b[i]][a[i]] = true;
    }

    /*
    //ここはデバグ用（隣接行列を表示）
    rep(i, 0, n){
        rep(j, 0, n) cout << gra[i][j] << " ";
        cout << endl;
    }
    */

    //以下、橋を調べる処理
    int ans = 0;
    rep(i, 0, m){
        //辺を消去
        gra[a[i]][b[i]] = false;
        gra[b[i]][a[i]] = false;

        //探索（旗立て）
        dfs(0);

        //訪問履歴を調査
        bool bridge = false;
        rep(j, 0, n) if(vis[j] == false) bridge = true;
        //このようにしてboolをかませて判定するのが良い。なぜならば一辺を消したときに
        //島が2つ以上できる可能性があるからである。

        if(bridge) ans += 1;

        //隣接行列を初期化
        gra[a[i]][b[i]] = true;
        gra[b[i]][a[i]] = true;

        //visitedを初期化
        rep(k, 0, n) vis[k] = false;
    }
    cout << ans << endl;

    return 0;

}


Measured memory_bytes: 256
#include<stdio.h>

int main(void){


	int n,risi,money=100000;
	
	
	
	int i;

	scanf("%d",&n);

	for(i=0;i<n;i++){
		risi = money*(5.0/100.0);

		money+=risi;

		if(money % 1000 != 0){
			money -= money%1000;
			money += 1000;
		}

	}

	printf("%d\n",money);

	return 0;
}

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


using namespace std;
int main(void){
    int N,X;
    int m[101];
    cin>>N>>X;
    int rem=X;
    for(int i=0;i<N;i++){
        cin>>m[i];
        rem-=m[i];
    }
    sort(m,m+N);
    printf("%d",N+rem/m[0]);
    
}

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

int main() {
  string s;
  cin >> s;
  cout << s.at(0) << s.at(1) << s.at(2) << s.at(3) << s.at(4) << ' ' << s.at(6) << s.at(7) << s.at(8) << s.at(9) << s.at(10) << s.at(11) << s.at(12) << ' ' << s.at(14) << s.at(15) << s.at(16) << s.at(17) << s.at(18) << endl;
}

Measured memory_bytes: 256
N, M = map(int, input().split())
status = [True]*(N+2)
for _ in range(M):
    status[int(input())] = False

dp = [0]*(N+2)
dp[0] = 1
for i in range(N):
    dp[i] = dp[i] % (10**9 + 7)
    if status[i+1]:
        dp[i+1] += dp[i]
    if status[i+2]:
        dp[i+2] += dp[i]

print(dp[N] % (10**9+7))


Measured memory_bytes: 45272
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>

using namespace std;
using ll = long long;

int main() {
	int A, B;
	cin >> A >> B;
	A--;
	B--;

	int h = 100, w = 100;

	vector<string> s(h);

	for (int i = 0; i < h; i++) {
		//メモリ確保
		s[i].resize(w);
		for (int j = 0; j < w; j++) {
			if (i < h / 2) s[i][j] = '#';
			else s[i][j] = '.';
		}
	}
	//変更する位置
	int x, y;
	for (int i = 0; i < A; i++) {
		x = i % 50 * 2;
		y = i / 50 * 2;
		s[y][x] = '.';
	}

	for (int i = 0; i < B; i++) {
		x = i % 50 * 2;
		y = h - 1 - i / 50 * 2;
		s[y][x] = '#';
	}

	cout << h << " " << w << endl;
	for(int i = 0; i < h; i++) cout << s[i] << endl;
	return 0;
}

Measured memory_bytes: 256
# B - バイナリハックイージー
def main():
    s = list(input())
    val = []

    for i in s:
        if len(val) == 0 and i == 'B':
            continue
        elif i == 'B':
            val.pop(-1)
        else:
            val.append(i)
    else:
        print(''.join(val))
 
    
if __name__ ==  "__main__":
    main()

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

int main() {
  string s; cin >> s;
  int q; cin >> q;
  int flag = 1;

  rep(i,q) {
    int fn; cin >> fn;
    if ( fn == 1 ) flag *= -1;
    else {
      int sn; cin >> sn;
      string tmp; cin >> tmp;
      if ( sn == 1 ) {
        if ( flag == 1 ) s.insert(0,tmp);
        else s+=tmp;
      }
      else {
        if ( flag == 1 ) s+=tmp;
        else s.insert(0,tmp);
      }
    }
  }
  if ( flag == -1 ) reverse(s.begin(), s.end());
  cout << s << endl;
    
  return 0;
}


Measured memory_bytes: 900
#!/usr/bin/env pypy
import heapq

N, M = map(int, input().split())
A = list(map(int, input().split()))
A = list(map(lambda x: x*(-1), A))  # 各要素を-1倍

heapq.heapify(A)

if N == 1:
    MAX = heapq.heappop(A)//2**M 
    if MAX < 0:
        print(0)
    else:
        print(MAX)
    exit()

cnt = 0
while M > 0:
    MAX = heapq.heappop(A)
    if MAX % 2 == 0:
        heapq.heappush(A, MAX//2)
    else:
        heapq.heappush(A, MAX//2+1)

    M -= 1

print(-sum(A))


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

using namespace std;

const int N = 1e7 + 10;

char s[N];
int st[N], tp = 0;

int main() {
  scanf("%s", s + 1);
  int n = strlen(s + 1);
  for (int i = 1; i <= n; i++) {
    if (s[i] == 'T' && tp && s[st[tp]] == 'S') {
      tp--;
    } else {
      st[++tp] = i;
    }
  }
  printf("%d\n", tp);
  return 0;
}

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

int main()
{
  int n;
  string a, b, c;
  cin >> n >> a >> b >> c;
  int i;
  int ans = 0;
  for(i = 0; i < n; i++)
  {
    if(a.at(i) != b.at(i) && a.at(i) != c.at(i) && b.at(i) != c.at(i))ans += 2;
    else if(a.at(i) != b.at(i) || a.at(i) != c.at(i) || b.at(i) != c.at(i))ans++;
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <sstream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <ctime>
#include <cstring>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <map>
#include <set>
#include <bitset>
#include <numeric>
#include <utility>
#include <iomanip>
#include <algorithm>
#include <functional>
using namespace std;

typedef long long ll;
typedef vector<int> vint;
typedef vector<long long> vll;
typedef pair<int,int> pint;
typedef pair<long long, long long> pll;

#define MP make_pair
#define PB push_back
#define ALL(s) (s).begin(),(s).end()
#define EACH(i, s) for (__typeof__((s).begin()) i = (s).begin(); i != (s).end(); ++i)
#define COUT(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << 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; }
template<class T1, class T2> ostream& operator << (ostream &s, pair<T1,T2> P) 
{ return s << '<' << P.first << ", " << P.second << '>'; }
template<class T> ostream& operator << (ostream &s, vector<T> P) 
{ for (int i = 0; i < P.size(); ++i) { if (i > 0) { s << " "; } s << P[i]; } return s; }
template<class T1, class T2> ostream& operator << (ostream &s, map<T1,T2> P) 
{ EACH(it, P) { s << "<" << it->first << "->" << it->second << "> "; } return s; }



int n, m, h, k;
int s[1100];

int main() {
    while (cin >> n >> m >> h >> k) {
        if (n == 0) break;
        vector<pint> bou(m);
        for (int i = 0; i < n; ++i) cin >> s[i];
        for (int i = 0; i < m; ++i) {
            cin >> bou[i].second >> bou[i].first;
            --bou[i].second;
        }
        sort(ALL(bou));
        
        vint goal(n), now(n);
        for (int i = 0; i < n; ++i) goal[i] = now[i] = i;
        for (int i = 0; i < m; ++i) {
            swap(goal[bou[i].second], goal[bou[i].second+1]);
        }
        vint each(n);
        for (int i = 0; i < n; ++i) each[goal[i]] = i;
        
        int def = 0;
        for (int i = 0; i < k; ++i) def += s[each[i]];
        
        int res = def;
        for (int i = 0; i < m; ++i) {
            int p1 = now[bou[i].second], p2 = now[bou[i].second+1];
            int ddef = def;
            if (p1 < k) ddef = ddef - s[each[p1]] + s[each[p2]];
            if (p2 < k) ddef = ddef - s[each[p2]] + s[each[p1]];
            chmin(res, ddef);
            
            swap(now[bou[i].second], now[bou[i].second+1]);
        }
            
        cout << res << endl;
    }
    return 0;
}


Measured memory_bytes: 2060
# -*- coding: utf-8 -*-

import sys
from collections import defaultdict
from itertools import accumulate

def input(): return sys.stdin.readline().strip()
def list2d(a, b, c): return [[c] * b for i in range(a)]
def list3d(a, b, c, d): return [[[d] * c for j in range(b)] for i in range(a)]
def list4d(a, b, c, d, e): return [[[[e] * d for j in range(c)] for j in range(b)] for i in range(a)]
def ceil(x, y=1): return int(-(-x // y))
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(N=None): return list(MAP()) if N is None else [INT() for i in range(N)]
def Yes(): print('Yes')
def No(): print('No')
def YES(): print('YES')
def NO(): print('NO')
sys.setrecursionlimit(10 ** 9)
INF = 10 ** 18
MOD = 10 ** 9 + 7

N, K = MAP()
# 全要素-1した状態で作る
A = [(a-1)%K for a in LIST()]

# 累積和
acc = [0] + list(accumulate(A))
acc = [a%K for a in acc]

cnt = defaultdict(int)
ans = 0
for i, a in enumerate(acc):
    # 自分より前に出現した自分と同じ値、を答えに足す
    ans += cnt[a]
    # 度数分布に自分を加える
    cnt[a] += 1
    # K個以上前の値は減らす
    if i - K + 1 >= 0:
        cnt[acc[i-K+1]] -= 1
print(ans)


Measured memory_bytes: 42516
//#include <bits/stdc++.h>
#include <iostream>
#include <fstream>
#include <vector>
#include <string>
#include <cmath>
#include <algorithm>
#include <map>
#include <iomanip>
#include <stdlib.h>
#include <stdio.h>
#include <queue>
#include <deque>
#include <set>
#include <stack>
#include <time.h>
 
using namespace std;
 
typedef long long ll;
typedef long double ld;
typedef pair<int, int> Pii;
typedef pair<int, ll> Pil;
typedef pair<ll, ll> Pll;
typedef pair<ll, int> Pli;

#define fi first
#define se second
#define mp make_pair
 
const ll MOD = 1e9 + 7;
const ll MOD2 = 998244353;
const ll INF = 1ll << 60;
const double PI = 2 * asin(1);

void yes() {printf("yes\n");}
void no() {printf("no\n");}
void Yes() {printf("Yes\n");}
void No() {printf("No\n");}
void YES() {printf("YES\n");}
void NO() {printf("NO\n");}

double A, B, C, theta, X;

int main(){
  scanf("%lf%lf%lf", &A, &B, &X);

  if (A * A * B <= 2 * X){
    C = 2 * B - 2 * X / (A * A);
    theta = atan(C / A) / (PI / 2) * 90;
  }else{
    C = 2 * X / (A * B);
    theta = atan(B / C) / (PI / 2) * 90;
  }

  printf("%.10lf\n", theta);
  return 0;
}


Measured memory_bytes: 384
#include <cstdio>
#include <cstring>
#define MAXN 100013
using namespace std;
char s[MAXN];
int cnt,n,k;
int main(){
    scanf("%d%d",&n,&k);
    scanf("%s",s);
    for(register int i=1;i<n;++i)
    	cnt=cnt+(s[i]==s[i-1]);
    cnt=cnt+2*k;
    if(cnt>n-1)printf("%d",n-1);
    else printf("%d",cnt);
    return 0;
}

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

vector<int> greedy(int k, int c, string &s) {
    vector<int> res(k);
    int cur = 0;
    for (int i = 0; i < k; ++i) {
        while (s[cur] == 'x') ++cur;
        res[i] = cur;
        cur += c + 1;
    }
    return res;
}

int main() {
    int n, k, c;
    string s;
    cin >> n >> k >> c >> s;
    vector<int> left = greedy(k, c, s);
    reverse(s.begin(), s.end());
    vector<int> right = greedy(k, c, s);
    for (int i = 0; i < k; ++i) {
        right[i] = n - right[i] - 1;
    }
    reverse(right.begin(), right.end());
    for (int i = 0; i < k; ++i) {
        if (left[i] == right[i]) cout << left[i] + 1 << '\n';
    }
}


Measured memory_bytes: 3332
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i,n) for(int i = 0; i < (n); i++)
#define INF 2 << 29
#define MOD 1000000007
#define Yes(f) puts((f)? "Yes" : "No")
#define YES(f) puts((f)? "YES" : "NO")
int gcd(int a, int b) {
	if (b != 0)return gcd(b, a % b);
	return a;
}
int lcm(int a, int b) {
	return a / gcd(a, b) * b;
}
using Graph = vector<vector<int>>;

int main(){
	int n; cin >> n;
	map<int, int> m;
	rep(i, n){
		int a; cin >> a;
		m.insert(map<int,int>::value_type(a, i + 1));
	}
	for(auto itr = m.begin(); itr != m.end(); itr++){
		cout << itr->second << " ";
	}
}

Measured memory_bytes: 5504
N = int(input())
S = [str(input()) for i in range(N)]

num = 0 
strings = ['AC', 'WA', 'TLE', 'RE']
num_list = [0]*len(strings)
for i in range(N):
    if S[i] in strings:
        num_list[strings.index(S[i])] += 1
for i in range(len(strings)):
    print(strings[i], ' x ', num_list[i])

Measured memory_bytes: 16160
#include <fstream>
#include <sstream>
#include <iostream>
#include <cmath>
#include <vector>
#include <queue>
#include <map>
#include <utility>
#include <algorithm>
using namespace std;

vector<string> split(const string &str, char delim){
  istringstream iss(str); string tmp; vector<string> res;
  while(getline(iss, tmp, delim)) res.push_back(tmp);
  return res;
}

int main() {
  string snt;
  getline(cin, snt);

  vector<string> words = split(snt, ' ');
  words[0][0] = tolower( words[0][0] );

  // for (int i = 0; i < words.size(); i++)
  //   cout << words[i] << endl;

  map<string, int> cnt;

  int M = words.size();
  int l;
  int mx_len = 0;
  for (int i = 0; i < M; i++) {
    // 最頻値
    if (cnt.count(words[i])) {
      cnt[ words[i] ]++;
    } else {
      cnt[ words[i] ] = 0;
    }
    // 最大長さの単語
    if (words[i].length() > mx_len) {
      mx_len = words[i].length();
      l = i;
    }
  }

  int f;
  int mx_f = 0;
  for (int i = 0; i < M; i++) {
    if (mx_f < cnt[ words[i] ]) {
      f = i;
      mx_f = cnt[ words[i] ];
    }
  }

  cout << words[f] << " " << words[l] << endl;
}

Measured memory_bytes: 1204
#include<iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <math.h>
#define cinf(n,x) for(int i=0;i<(n);i++) cin >> x[i];
typedef long long int ll;
using namespace std;
ll mod=1e9+7;
int main(){
	string s; cin>>s;
	int cntw=0;
	int n=s.size();
	ll ans=0;
	for(int i=0;i<n;i++){
		if(s[i]=='W'){
			cntw++;
			ans+=i;
		}
	}
	for(int i=1;i<cntw;i++){
		ans-=i;
	}
	cout << ans << endl;

}


//操作が行えない状態
//WWBBBのような配置になったらお終い！


Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std; inline void fileio(const char* in, const char* out) { freopen(in, "r", stdin); freopen(out, "w", stdout); } 
#define TD typedef
#define forx(i,n) for(int i = 0; i < (n); ++i)
TD long long ll; TD long double ld; TD pair<int,int> pii; TD pair<ll, ll> pll; TD vector<int> VI; TD vector<bool> VB; TD vector<ll> VL;
const char nl = '\n'; const int INF = 0x3f3f3f3f; const ll LINF = 0x3f3f3f3f3f3f3f3fll; const ld EPS = 1e-9, PI = acos(-1);
#define ff first
#define ss second

namespace Nums {
// iterate over digits of a number, from right to left
  #define for_digits(d, number) for (ll _=(number); _; ) for (int d = _%10; _; d=(_/=10)%10)
// b^e % mod
  ll modpow(ll b, int e, int mod) { ll res = 1; for (; e>0; e>>=1, b=b*b%mod) { if (e&1) res = res*b % mod; } return res; }
// nCr
  ll nCr(ll n, ll r) {
    if (r>n) return 0;
    if (r<<1>n) r=n-r;
    if (!r) return 1;
    ll res=n;
    for (int i = 2; i <= r; ++i) {
      res = res * (n-i+1) / i;
    } return res;
  }
// solves: ax + by = gcd(a,b)
// return: { gcd, x, y };
// source: https://en.wikibooks.org/wiki/Algorithm_Implementation/Mathematics/Extended_Euclidean_algorithm#Iterative_algorithm_3
  template <typename T>
  tuple<T,T,T> egcd(T a, T b) {
    T gcd = b, x = 0, y = 1, x_ = 1, y_ = 0;
    while (a) {
      b = gcd / a;
      swap(gcd, a); a %= gcd;
      swap(y, y_); y_ -= b * y;
      swap(x, x_); x_ -= b * x;
    }
    return {gcd, x, y};
  }
// chinese remainder theorem
  
}

int main() {
  atexit([](){ cerr << "Time: " << (ld)clock() / CLOCKS_PER_SEC << nl; });
  ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
  // Emily <3
  int n;
  cin >> n;
  vector<string> strs(n);
  forx(i,n) {
    cin >> strs[i];
    sort(strs[i].begin(), strs[i].end());
  }
  sort(strs.begin(), strs.end());
  
  /*
  cerr << "sorted:" << nl;
  for(string s : strs) {
    cerr << s << nl;
  }
  */

  string cur = "";
  ll cnt = 1;
  ll ans = 0;
  for (string& s : strs) {
    if (cur == s) {
      cnt++;
    } else {
      cur = s;
      ans += Nums::nCr(cnt, 2);
      cnt = 1;
    }
  }
  ans += Nums::nCr(cnt, 2);
  cout << ans << nl;
  
  return 0;
}



Measured memory_bytes: 5760
var x = require('fs').readFileSync('/dev/stdin', 'utf8');
var arr = x.split(/\s/);
a = arr[0];
b = arr[1];
c = arr[2];
var count = 0;
for (i = 1 ; i <= c; i++) {
  if ((c%i == 0) && (a <= i) && (i <= b))
    count++;
}
console.log(count);




Measured memory_bytes: 15360
def linearSearch(S,t):
    L = S + [t]
    i = 0
    while L[i] != t: i += 1
    if i == len(L)-1: return 0
    else            : return 1

if __name__=='__main__':
    n=int(input()) 
    S=list(map(int,input().split()))
    q=int(input()) 
    T=list(map(int,input().split()))
    cnt = 0
    for t in T: cnt += linearSearch(S,t)
    print(cnt)

Measured memory_bytes: 8560
open Scanf
open Printf

let rec f i x s =
	if 0 == x then
		s
	else
		let ss = s^"Case "^(string_of_int i)^": "^(string_of_int x)^"\n" in
		let c = read_int() in
		f (i+1) c ss;;
let ptc =
	let c = read_int() in
	f 1 c "";;

printf "%s" ptc;;

Measured memory_bytes: 9260
import collections
n = int(input())
v = list(map(int, input().split()))

odd = []
even = []

for i in range(n):
  if i % 2 == 0:
    odd.append(v[i])
  else:
    even.append(v[i])

oddm = collections.Counter(odd)
evenm = collections.Counter(even)

odd1 = oddm.most_common()[0]
even1 = evenm.most_common()[0]

if (odd1 == even1) and (oddm.most_common()[0][1] + evenm.most_common()[0][1] == n):
  ans = n//2
else:
  if odd1 != even1:
    ans = n - oddm.most_common()[0][1] - evenm.most_common()[0][1] 
  else:
    p1 = ans = n - oddm.most_common()[1][1] - evenm.most_common()[0][1] 
    p2 = ans = n - oddm.most_common()[0][1] - evenm.most_common()[1][1] 
    ans = min(p1, p2)
    
print(ans)

Measured memory_bytes: 83972
#include <iostream>
#include <cmath>
#include <vector>
#include <iomanip>
#include <set>
using namespace std;
using ll = long long;

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

// https://scrapbox.io/pocala-kyopro/Union-Find
class UnionFind {
public:
    vector<int> Parent;

    UnionFind(int n) {
        Parent = vector<int> (n, -1);
    }

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

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

    bool connect(int a, int b) {
        a = root(a);
        b = root(b);
        if(a == b) return false;
        if(size(a) < size(b)) swap(a, b);
        Parent[a] += Parent[b];
        Parent[b] = a;
        return true;
    }
};



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

    UnionFind uf(n);

    for(int i = 0; i < m; i++) {
        int a, b;
        cin >> a >> b;
        --a; --b;

        uf.connect(a, b);
    }


    set<int> s;
    for(int i = 0; i < n; i++) s.insert(uf.root(i));

    cout << s.size() - 1 << endl;

    return 0;
}

Measured memory_bytes: 7660
#include <bits/stdc++.h>
using namespace std;
#define IO ios_base::sync_with_stdio(false); cin.tie(NULL);

#define endl '\n'
#define D(x) cout << #x << " = " << (x) << endl;

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

  vector<int> v(n + 1);
  for (int i = 1; i <= n; ++i) cin >> v[i];

  int mx = *max_element(v.begin(), v.end());
  int ans = 0;

  for (int h = 1; h <= mx; ++h) {
    for (int i = 1; i <= n; ++i) {
      if (v[i - 1] < h and v[i] >= h) {
        ans += 1;
      }
    }
  }

  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 256
import java.util.*;

public class Main {
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int a = sc.nextInt(),b=sc.nextInt(),c=sc.nextInt();
        if(c%gcd(a,b)==0)System.out.println("YES");
        else System.out.println("NO");
    }
    public static int gcd(int a,int b){
        int max = 1;
        for(int i = 1;i<=Math.min(a,b);i++){
            if(a%i==0&&b%i==0)if(i>max)max=i;
        }
        return max;
    }
}

Measured memory_bytes: 35796
#include <stdio.h>

int H, W;
int A[25][25];
int B[25][25];

int min(int a, int b)
{
  return (a < b) ? a : b;
}

int calcNW(int row, int col )
{
  int i, j, d;
  d = 0;
  for (i = row - 1; i >= 0; i--)
  {
    for (j = col - 1; j >= 0; j--)
    {
      B[i][j] = min(B[i][j + 1], B[i + 1][j]) + 1;
      d += B[i][j] * A[i][j];
    }
  }

  return d;  
}

int calcNE(int row, int col)
{
  int i, j, d;
  d = 0;
  for (i = row - 1; i >= 0; i--)
  {
    for (j = col + 1; j < W; j++)
    {
      B[i][j] = min(B[i][j - 1], B[i + 1][j]) + 1;
      d += B[i][j] * A[i][j];
    }
  }

  return d;
}

int calcSW(int row, int col)
{
  int i, j, d;
  d = 0;
  for (i = row + 1; i < H; i++)
  {
    for (j = col - 1; j >= 0; j--)
    {
      B[i][j] = min(B[i][j + 1], B[i - 1][j]) + 1;
      d += B[i][j] * A[i][j];
    }
  }

  return d;
}

int calcSE(int row, int col)
{
  int i, j, d;
  d = 0;
  for (i = row + 1; i < H; i++)
  {
    for (j = col + 1; j < W; j++)
    {
      B[i][j] = min(B[i][j - 1], B[i - 1][j]) + 1;
      d += B[i][j] * A[i][j];
    }
  }

  return d;
}

int calcTotal(int row, int col)
{
  int d, i, j;
  
  for (i = 0; i < H; i++)
  {
    for (j = 0; j < W; j++)
    {
      B[i][j] = 0;
    }
  }

  d = 0;
  d += calcNW(row, col);
  d += calcNE(row, col);
  d += calcSW(row, col);
  d += calcSE(row, col);

  return d;
}

int main()
{
  int i, j, min, d; 

  scanf("%d %d", &H, &W);

  for (i = 0; i < H; i++)
  {
    for (j = 0; j < W; j++)
    {
      scanf("%d", &A[i][j]);
    }
  }

  min = (1 << 21);
  d = 0;

  for (i = 0; i < H; i++)
  {
    for (j = 0; j < W; j++)
    {
      d = calcTotal(i, j);
      if (d < min) min = d;
    }
  }

  printf("%d\n", min);

  return 0;
}


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

int main() {
  int w, h, n, x, y, a; cin >> w >> h >> n;
  int max_x = w, max_y = h, min_x = 0, min_y = 0;

  for(int i = 0; i < n; i++) {
    cin >> x >> y >> a;
    switch(a) {
      case 1: min_x = max(x, min_x); break;
      case 2: max_x = min(x, max_x); break;
      case 3: min_y = max(y, min_y); break;
      case 4: max_y = min(y, max_y); break;
    }
  }
  int s = max_x - min_x, t = max_y - min_y;
  cout << (s > 0 && t > 0 ? s*t : 0) << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
struct Fast {
    Fast() {
        cin.tie(0);
        ios::sync_with_stdio(false);
        cout << fixed << setprecision(20);
    }
} fast;

void yes() {
    cout << "Yes" << endl;
    exit(0);
}
void no() {
    cout << "No" << endl;
    exit(0);
}
#define REP(i, n) for (long long i = 0; i < (n); i++)

int main() {
    long long n, h, w;
    cin >> h >> w >> n;
    vector<long long> as(n);
    for (int i = 0; i < n; i++) {
        cin >> as[i];
    }
    vector<long long> wall(h, w);
    vector<vector<int>> ans(h);
    int now = 0;
    REP(i, n) {
        for (int j = 0; j < as[i]; j++) {
            ans[now].push_back(i + 1);
            wall[now]--;
            if (wall[now] == 0) {
                now++;
            }
        }
    }
    REP(i, h) {
        if (i % 2 == 1) {
            reverse(ans[i].begin(), ans[i].end());
        }
    }
    REP(i, h) {
        REP(j, w) { cout << ans[i][j] << " "; }
        cout << endl;
    }
}

Measured memory_bytes: 384
using System;

namespace ConsoleApp3
{
    class Program
    {
        static void Main(string[] args)
        {

            string[] Inp1 = Console.ReadLine().Split(' ');
            int N = int.Parse(Inp1[0]);

            string[] Inp2 = Console.ReadLine().Split(' ');

            var X = new int[N + 1];

            for (int h = 1; h <= N; h++)
            {
                X[h] = int.Parse(Inp2[h - 1]);
            }


            int ScoreA = 0;
            int ScoreB = 0;
            int A = 0;
            int B;
            //最大値がAに入る。

            for (int j= N;j > 0;j--)
            {

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

                    if (A < X[i])
                    {
                        B = A;
                        A = X[i];
                        X[i] = B;
                    }

                    if (i >= 2)
                    {
                        X[i - 1] = X[i];
                    }

                }
                //Console.WriteLine(A);

                if (j % 2 == 0)
                {
                    ScoreB += A;
                    
                }
                else
                {
                    ScoreA += A;
                }

                A = 0;

            }

            int Ans;

            if(ScoreA > ScoreB)
            {
                Ans = ScoreA - ScoreB;
            }
            else
            {
                Ans = ScoreB - ScoreA;

            }

            Console.WriteLine(Ans);
        }
    }
}


Measured memory_bytes: 13140
#include<iostream>
using namespace std;
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
int A[100000][2];
int main(){
	IOS;
	int n;
	cin >> n;
	for (int i = 0; i < n; i++){
		cin >> A[i][0];
		A[i][1] = -1;
	}
	A[0][1] = 0;
	for (int i = 0; i < n; i++){
		for (int j = i; (j <= i + 2) && (j < n); j++){
			int x = abs(A[i][0] - A[j][0]);
			if (A[j][1] == -1) A[j][1] = x + A[i][1];
			else{
				if (A[j][1]> x + A[i][1]) A[j][1] = x + A[i][1];
			}
		}
	}
	cout << A[n - 1][1] << endl;
}

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

#define ll long long
#define ARR_SIZE 510000
#define MOD ((ll)1e9 + 7)

ll modpow(ll n, ll r){
    ll res = 1;
    while(r>0){
        if(r%2==1) res = res*n%MOD;
        n = n*n%MOD;
        r /= 2;
    }
    return res;
}

ll modinv(ll n){
    return modpow(n, MOD-2);
}

ll fact[ARR_SIZE] = {1, 1};
ll factinv[ARR_SIZE] = {1, 1};

ll comb(ll n, ll r){
    return (fact[n] * factinv[r] %MOD) * factinv[n-r] %MOD;
}

ll perm(ll n, ll r){
    return fact[n] * factinv[n-r] %MOD;
}

int main(){
    int n, m;
    scanf("%d %d", &n, &m);
    // end input

    for(int i=2;i<ARR_SIZE;i++){
        fact[i] = fact[i-1]*i%MOD;
    }
    factinv[ARR_SIZE-1] = modinv(fact[ARR_SIZE-1]);
    for(int i=ARR_SIZE-1;i>0;i--){
        factinv[i-1] = factinv[i]*i%MOD;
    }

    ll ans = 0;
    for(int i=0;i<=n;i++){
        ll t1 = comb(n,i)*perm(m,i)%MOD;
        ll t2 = modpow(perm(m-i, n-i), 2);
        ans += t1*t2%MOD * modpow(-1, i);

        ans = (ans%MOD + MOD)%MOD;
    }
    printf("%lld\n", ans);
    return 0;
}

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

using namespace std;
typedef long long ll;

const ll MAX = (ll)1e5 + 55;
vector<vector<ll>> dp(110, vector<ll>(MAX, -1));
vector<ll> cost(MAX, 0);
vector<ll> w(MAX, 0);

ll func(ll n, ll c)
{
    if (c <= 0)
    {
        return 0;
    }
    if (n <= 0)
    {
        return (ll)1 << 40;
    }
    if (dp[n][c] != -1)
    {
        return dp[n][c];
    }
    else
    {

        ll m = func(n - 1, c);
        if (c - cost[n] >= 0)
        {
            m = min(m, func(n - 1, c - cost[n]) + w[n]); // lesser wt without/with inclusion of nth item
        }
        dp[n][c] = m;
        return dp[n][c];
    }
}

int main()
{
    ll n, wt;
    cin >> n >> wt;
    ll s = 0;
    for (int x = 1; x <= n; x++)
    {
        cin >> w[x];
        cin >> cost[x];
        s += cost[x];
    }

    for (int x = 0; x <= s; x++)
    {
        func(n, x);
    }
    ll INDEX = 0;
    for (ll x = 1; x <= n; x++)
    {
        for (ll y = 0; y <= s; y++)
        {
            if (dp[x][y] <= wt && dp[x][y] != -1)
            {
                INDEX = max(INDEX, y);
            }
        }
    }
    cout << INDEX << endl;
}

Measured memory_bytes: 88048
#include <bits/stdc++.h>
using namespace std;
int main(){
	char a[6];
	for(int i=0;i<6;i++) cin>>a[i];
	if(a[0]==a[5]&&a[1]==a[4]&&a[2]==a[3]) cout<<"YES";
	else cout<<"NO";
	return 0;
}


Measured memory_bytes: 256
module.exports=function(t){var e={};function r(n){if(e[n])return e[n].exports;var i=e[n]={i:n,l:!1,exports:{}};return t[n].call(i.exports,i,i.exports,r),i.l=!0,i.exports}return r.m=t,r.c=e,r.d=function(t,e,n){r.o(t,e)||Object.defineProperty(t,e,{enumerable:!0,get:n})},r.r=function(t){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(t,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(t,"__esModule",{value:!0})},r.t=function(t,e){if(1&e&&(t=r(t)),8&e)return t;if(4&e&&"object"==typeof t&&t&&t.__esModule)return t;var n=Object.create(null);if(r.r(n),Object.defineProperty(n,"default",{enumerable:!0,value:t}),2&e&&"string"!=typeof t)for(var i in t)r.d(n,i,function(e){return t[e]}.bind(null,i));return n},r.n=function(t){var e=t&&t.__esModule?function(){return t.default}:function(){return t};return r.d(e,"a",e),e},r.o=function(t,e){return Object.prototype.hasOwnProperty.call(t,e)},r.p="",r(r.s=0)}([function(t,e,r){"use strict";var n=r(1);r(2)(n.readFileSync("/dev/stdin","utf8"))},function(t,e){t.exports=require("fs")},function(t,e,r){"use strict";var n=r(3),i=r(5);t.exports=function(t){var e=new n(t);i(e)}},function(t,e,r){"use strict";var n=r(4);t.exports=class{constructor(t){var e=t.trim().split(/\s+/g);this.inp=new n(e)}inr(){return this.inp.deq()}in(){return parseInt(this.inp.deq(),10)}fin(){this.inp.clear()}}},function(t,e,r){"use strict";t.exports=class{constructor(){var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:[];this.size=t.length,this.items=t,this.ind=0}enq(t){this.size+=1,this.items.push(t)}deq(){var t=this.items[this.ind];return this.size-=1,this.ind+=1,t}clear(){this.items=[],this.size=0,this.ind=0}}},function(t,e,r){"use strict";t.exports=function(t){for(var e=t.in(),r=new Array(e),n=0;n<e;n++)r[n]=t.in();r.sort(function(t,e){return t-e});for(var i=0,o=-1,s=0;s<e-1;s++)(i+=r[s])<r[s+1]/2&&(o=s);var u=e-1-o;console.log(u)}}]);

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

#define int long long
typedef vector<int>vint;
typedef pair<int,int>pint;
typedef vector<pint>vpint;
#define rep(i,n) for(int i=0;i<(n);i++)
#define reps(i,f,n) for(int i=(f);i<(n);i++)
#define all(v) (v).begin(),(v).end()
#define each(it,v) for(__typeof((v).begin()) it=(v).begin();it!=(v).end();it++)
#define pb push_back
#define fi first
#define se second
template<typename A,typename B>inline void chmin(A &a,B b){if(a>b)a=b;}
template<typename A,typename B>inline void chmax(A &a,B b){if(a<b)a=b;}

const double PI=acos(-1);
const double EPS=1e-6;
typedef complex<double>Point;
Point in(){
    double x,y;
    scanf("%lf%lf",&x,&y);
    return Point(x,y);
}

int N;
Point P[333];

signed main(){

    Point r=polar(1.0,PI/2);
    while(scanf("%lld",&N),N){
        rep(i,N)P[i]=in();

        int ma=1;
        rep(i,N)rep(j,N){
            if(abs(P[i]-P[j])+EPS>2.0)continue;
            Point b=(P[i]+P[j])*0.5;
            Point v=(P[i]-P[j]);
            v*=1.0/abs(v);
            for(double d:{-1.0,1.0}){
                Point u=v*d*sqrt(1.0-norm((P[i]-P[j])/2.0))*r;
                Point p=b+u;
                int cnt=0;
                rep(k,N)if(abs(P[k]-p)<1.0+EPS)cnt++;
                chmax(ma,cnt);
            }
        }
        printf("%lld\n",ma);
    }
    return 0;
}
\

Measured memory_bytes: 3268
#include<bits/stdc++.h>
#define ll long long
#define pb push_back
using namespace std;
//const N = 2e6, inf = 1e18;

string a, b;
vector<string>v;
vector<string>ans;
int main()
{
    map<string, ll>mp;
    map<string, ll>tak;
    ll n, m, k;
    cin>>n;
    ll mx = 0;
    for(int i = 0; i < n; i++)
    {
        string s;
        cin>>s;
        v.pb(s);
        mp[s]++;
        mx = max(mx, mp[s]);
    }
    for(int i = 0; i < n; i++)
    {
        if(mp[v[i]] == mx && !tak[v[i]]) ans.pb(v[i]);
        tak[v[i]] = 1;
    }
    sort(ans.begin(), ans.end());
    for(int i = 0; i < ans.size(); i++) cout<<ans[i]<<"\n";
    return 0;
}


Measured memory_bytes: 40816
#include<iostream>
#include <cstdio>
#include <cmath>
#include <cstring> 
#include <algorithm>
#include <string>
using namespace std;
#define ll long long
#define M(x) memset(x,0,sizeof(x))
int main() 
{
	int n;
	cin>>n;
	for(int i=0;i<n;i++)
	{
		cout<<"ACL";
	}
	cout<<endl;
	return 0;
}

Measured memory_bytes: 3032
n, m = map(int, input().split())
a = [0] * m
b = [0] * m
for i in range(0, m):
    a[i], b[i] = map(int, input().split())


def solve():
    # b[i]の値でソートする
    bridges = sorted(list(zip(a, b)), key=lambda tup: tup[1])

    ans, tmp = 0, 1

    for bi in range(0, len(bridges)):
        # まだ橋を撤去していなかったら
        # 最も右端の端を撤去する
        if tmp <= (bridges[bi])[0]:
            tmp = (bridges[bi])[1]
            ans += 1


    print(ans)

def main():
    solve()

if __name__ == "__main__":
    main()

Measured memory_bytes: 20608
#include <iostream>
#include <string>
#include <algorithm>
#include <memory.h>
#define FULL ((1 << 26) - 1)
using namespace std;

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

	string s;
	cin >> s;
    reverse(s.begin(), s.end());

	int arr[10000] = {FULL};
	char mem[10000][26];
    memset(mem, -1, sizeof(mem));
	int exist[26] = {};

	for (int i = 0; i < s.size(); ++i) {
		int& t = exist[s[i] - 'a'];
		if (arr[t] == FULL) {
			t++;
			for (int j = 0; j < 26; ++j) {
				if (!(arr[t] & (1 << j))) {
					mem[t + 1][s[i] - 'a'] = j;
					break;
				}
			}
            arr[t] |= (1 << (s[i] - 'a'));
		}
		else {
			for (int j = 0; j < 26; ++j) {
				if (!(arr[t] & (1 << j))) {
					mem[t + 1][s[i] - 'a'] = j;
					break;
				}
			}
		}
	}

	int len = 0;
	while (arr[len] == FULL) {
		len++;
	}

	string ans;
	int start;
	for (int i = 0; i < 26; ++i) {
		if (!(arr[len] & (1 << i))) {
			start = i;
			ans.push_back(start + 'a');
			break;
		}
	}

	while (len > 1) {
        if (mem[len][start] == -1) {
            ans.push_back('a');
		    start = 0;
        }
        else {
            ans.push_back(mem[len][start] + 'a');
		    start = mem[len][start];
        }
		len--;
	}

	cout << ans;
}

Measured memory_bytes: 916