akhauriyash/Code-Regression huggingface dataset:
n,x = map(int,input().split())
l = list(map(int,input().split()))
count = []
for i in range(n+1):
  if i == 0:
    d =0
  else:
    d += l[i-1]
  count.append(d)
      
print(len([i for i in count if i <= x]))

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

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

def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def S(): return input()
def pf(s): return print(s, flush=True)


def main():
    a,b = LI()
    return (a-1)*(b-1)



print(main())


Measured memory_bytes: 5464
import java.util.Scanner;

public class Main {
	public static void main (String args[]) throws Exception{
		Scanner scan = new Scanner(System.in);
		long n = scan.nextLong();
		long m = scan.nextLong();
		long s = 0;
		long ans = -1;
		
		for(int i= 0; i < m; i++) {
			s = s + scan.nextLong();
		}
		
		if(s <= n) {
			ans = n - s;
		}
		
		System.out.println(ans);
	}
}

Measured memory_bytes: 39032
#include<iostream>
#include<string>

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

    double x[N];
    std::string u[N];
    double yen = 0;
    for(int i = 0; i < N; i++){
        std::cin >> x[i] >> u[i];
        if(u[i] == "BTC")yen += x[i] * 380000.0;
        else yen += x[i];
    }
    std::cout << yen;
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#pragma region atcoder
/*#include <atcoder/modint>
using namespace atcoder;
using mint = modint1000000007;*/
//These are for segment tree
/*int op(int a, int b){return max(a, b);}
int e(){return -1;}
bool f(int v){ return v < target;}
*/
#pragma endregion
#pragma region macros
using ll = long long;
using vi = vector<int>;
using vs = vector<string>;
using vl = vector<ll>;
using vb = vector<bool>;
using vvi = vector<vector<int>>;
using vvl = vector<vector<ll>>;
#define rep(i, n) for(int i = 0; i < n; i++)
#define rrep(i, n) for(int i = n - 1; i >= 0; i--)
#define all(x) (x).begin(), (x).end()
#define sz(x) ((int)(x).size())
#pragma endregion
#pragma region debug for var, v, vv
#define debug(var)  do{std::cout << #var << " : ";view(var);}while(0)
template<typename T> void view(T e){std::cout << e << std::endl;}
template<typename T> void view(const std::vector<T>& v){for(const auto& e : v){ std::cout << e << " "; } std::cout << std::endl;}
template<typename T> void view(const std::vector<std::vector<T> >& vv){cout << endl;int cnt = 0;for(const auto& v : vv){cout << cnt << "th : "; view(v); cnt++;} cout << endl;}
#pragma endregion

const ll mod = 1000000007;
const int inf = 1001001001;
const ll INF = 1001001001001001001;
const int MAX = 2000005;

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; }
ll modpow(ll a, ll p){ll ret = 1; while(p){if(p & 1){ret = ret * a % mod;} a = a * a % mod; p >>= 1;} return ret;}

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

/*-----------------------------------------------------------------------------------------------------*/
int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	string s; cin >> s;
	int a, b; cin >> a >> b;
	vi x, y;
	int idx = 0;
	rep(i, sz(s)){
		if(s[i] == 'F') a--;
		if(s[i] != 'F' || i == sz(s) - 1){
			idx = i;
			break;
		}
	}
	a = abs(a), b = abs(b);
	int cnt = 0;
	bool now_x = false;
	for(int i = idx + 1; i < sz(s); i++){
		if(s[i] == 'F') cnt++;
		if(s[i] == 'T' || i == sz(s) - 1){
			if(cnt == 0){
				if(now_x) now_x = false;
				else now_x = true;
				continue;
			}
			if(now_x){
				x.push_back(cnt);
				now_x = false;
				cnt = 0;
			}
			else{
				now_x = true;
				y.push_back(cnt);
				cnt = 0;
			}
		}
	}
	vector<vector<bool>> dpx(sz(x) + 1, vb(20000, false)), dpy(sz(y) + 1, vb(20000, false));
	dpx[0][10000] = true; dpy[0][10000] = true;
	rep(i, sz(x)){
		rep(j, 19000){
			if(j - x[i] >= 0 && dpx[i][j - x[i]]) dpx[i + 1][j] = true;
			if(j + x[i] <= 19999 && dpx[i][j + x[i]]) dpx[i + 1][j] = true;
		}
	}
	rep(i, sz(y)){
		rep(j, 19000){
			if(j - y[i] >= 0 && dpy[i][j - y[i]]) dpy[i + 1][j] = true;
			if(j + y[i] <= 19999 && dpy[i][j + y[i]]) dpy[i + 1][j] = true;
		}
	}
	if(dpx[sz(x)][10000 + a] && dpy[sz(y)][10000 + b]) cout << "Yes" << endl;
	else cout << "No" << endl;

}

Measured memory_bytes: 13236
#include<vector>
#include<cmath>
#include<map>
#include<cstdlib>
#include<iostream>
#include<sstream>
#include<fstream>
#include<string>
#include<algorithm>
#include<cstring>
#include<cstdio>
#include<set>
#include<stack>
#include<bitset>
#include<functional>
#include<ctime>
#include<queue>
#include<deque>
#include<complex>
#include<cassert>
using namespace std;
#define pb push_back
#define pf push_front
typedef long long lint;
typedef complex<double> P;
#define mp make_pair
#define fi first
#define se second
typedef pair<int,int> pint;
#define All(s) s.begin(),s.end()
#define rAll(s) s.rbegin(),s.rend()
#define REP(i,a,b) for(int i=a;i<b;i++)
#define rep(i,n) REP(i,0,n)
int main()
{
	int a,b,c,x,y;cin>>a>>b>>c>>x>>y;
	//cout<<a<<b<<c<<x<<y<<endl;
	if(a+b<=c*2){
		cout<<a*x+b*y<<endl;return 0;
	}
	int out=a*x+b*y;out-=min(x,y)*(a+b-c*2);
	cout<<min(out,max(x,y)*2*c)<<endl;
}


Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;

namespace MyProject
{
    class Program
    {
        static void Main(string[] args)
        {
#if Local
            var sw = new Stopwatch();
            sw.Start();
            Console.SetIn(new StreamReader("input.in"));
#endif

            var solver = new Solver();
            solver.Solve();
#if Local
            Console.WriteLine($"{sw.ElapsedMilliseconds}ms");
#endif
        }
    }

    class Solver
    {
        public void Solve()
        {
            var item = Console.ReadLine().Split().Select(elem => long.Parse(elem)).ToArray();
            var a = item[0];
            var b = item[1];
            var c = item[2];

            var d = c - a - b;
            var answer = (d > 0 && 4 * a * b < d * d) ? "Yes" : "No";

            Console.WriteLine(answer);
        }
    }
}


Measured memory_bytes: 13268
import math

l = int(input()) - 1
n = int(math.log2(l + 1) + 1)
res = []
for i in range(n - 1):
    res.append([i + 1, i + 2, 0])
    res.append([i + 1, i + 2, 2 ** i])
i = n - 2
while l > 2 ** (n - 1) - 1:
    t = l - 2 ** i + 1
    if t > 2 ** (n - 1) - 1:
        res.append([i + 1, n, t])
        l = t - 1
    i -= 1
print(n, len(res))
for i in range(len(res)):
    print(res[i][0],res[i][1],res[i][2])


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

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

  vector<int> L(M);
  vector<int> R(M);

  for(int i = 0; i < M; i++){
    cin >> L.at(i) >> R.at(i);
  }

  int Lmax = *max_element(L.begin(), L.end());
  int Rmin = *min_element(R.begin(), R.end());

  int ans = Rmin - Lmax + 1;

  cout << (ans > 0 ? ans : 0) << endl;
}


Measured memory_bytes: 1024
#include<stdio.h>
#include<algorithm>
int main() {
	
	//freopen("input.txt", "r", stdin);
	//freopen("output.txt", "w", stdout);

	int N,M;

	scanf("%d %d", &N, &M);

	if(N*M%2==0){
		printf("No");
	}
	else {
		printf("Yes");
	}
}

Measured memory_bytes: 128
n, a, b = map(int, input().split())
m = 10 ** 9 + 7
def comb(n, r):
  bot = top = 1
  for i in range(r):
    top *= n - i
    top %= m
  for i in range(r):
    bot *= i + 1
    bot %= m
  return top*pow(bot, m-2, m)

print((pow(2, n, m) - 1 - comb(n, a) - comb(n, b)) % m)
                

Measured memory_bytes: 38640
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <cmath>
#include <set>
using namespace std;
int main(){
    long long n;
    cin >> n;
    long long a = -2;
    vector<int> ans;
    if(n==0){
        cout << 0 << endl;
    }else{
    while(n != 0){
        if(n%a == 0){
            ans.push_back(0);
        }else{
            ans.push_back(1);
            n = n + a/2;
        }
        a = a * -2;
    }
    for(int i = 0;i<ans.size();i++){
        cout << ans[ans.size()-1-i];
    }
    cout << endl;
    }
}

Measured memory_bytes: 256
import std.stdio, std.string, std.conv;
import std.range, std.algorithm, std.array, std.typecons;
import std.math, std.numeric;



void main() {
    int n; scan(n);
    auto a = readln.split.to!(int[]);
    auto psum = new long[](n + 1);
    foreach (i ; 1 .. n + 1) {
        psum[i] = psum[i-1] + a[i-1];
    }
    psum.sort().group.map!(x => 1L * x[1] * (x[1] - 1) / 2).sum(0L).writeln;
}




void scan(T...)(ref T args) {
    import std.stdio : readln;
    import std.algorithm : splitter;
    import std.conv : to;
    import std.range.primitives;

    auto line = readln().splitter();
    foreach (ref arg; args) {
        arg = line.front.to!(typeof(arg));
        line.popFront();
    }
    assert(line.empty);
}



void fillAll(R, T)(ref R arr, T value) {
    static if (is(typeof(arr[] = value))) {
        arr[] = value;
    }
    else {
        foreach (ref e; arr) {
            fillAll(e, value);
        }
    }
}


Measured memory_bytes: 11396
#include <stdio.h>
//0,1,/b
//jika 0 taro di kanan
//jika 1 taro di kanan
//jika /b kalo ksoog gpp,kalo ada remove


int main(){
char s[15]; // untuk cek 
scanf("%s",s);
int idx = 0; //diset array ke 0 dulu
char s2[15]; //untuk nampung array baru
	for(int i=0;s[i] != '\0';i++){
		if(s[i] == '0'){
			s2[idx] = '0'; //tambah 0 di s2[0] nanti tmbh idx seiring loop
			idx++;  //kalau sudah  nambah index array
		}
		else if (s[i] == '1'){
			s2[idx] = '1';
			idx++;
		}
		else if (s[i] == 'B'){
			if(idx != 0){ //kalau indexnya tidak kosong maka
				idx--;	//mundur ke  index sblmnya
				s2[idx] = ' ';
				   //hapus index sblmnya			
			}
		}
	}
	printf("%s",s2);
	return 0;
}

Measured memory_bytes: 2132
#include <iostream>
#include <cstring>
#include <vector>
#include <algorithm>
#include <cmath>
#include <stack>
using namespace std;
int n;
long long int x[100003];
long long int v[100003];
long long int ls[100003];
long long int rs[100003];
long long int c;
int main()
{
    scanf("%d%lld", &n, &c);
    for(int i=1;i<=n;i++)
    {
        scanf("%lld%lld", &x[i], &v[i]);
    }
    x[n+1] = c;
    long long int cur = 0;
    for(int i=1;i<=n;i++)
    {
        cur += v[i] - (x[i] - x[i-1]);
        ls[i] = max(ls[i-1], cur);
    }
    cur = 0;
    for(int i=n;i;i--)
    {
        cur += v[i] - (x[i+1] - x[i]);
        rs[i] = max(rs[i+1], cur);
    }
    long long int ans = max(ls[n], rs[1]);
    for(int i=1;i<=n;i++)
    {
        ans = max({ls[i] + rs[i+1] - x[i], rs[i] + ls[i-1] - (c - x[i]), ans});
    }
    printf("%lld\n", ans);
}

Measured memory_bytes: 3328
#include <bits/stdc++.h>  // g++ -std=c++14 -o a a.cpp

using namespace std;

typedef pair<int, int> P;
typedef long long ll;
#define rep(i, n) for(int i = 0; i < (n); i++)
#define repto(i, n) for(int i = 0; i <= (n); i++)
#define all(c) (c).begin(), (c).end()
#define uniq(c) c.erase(unique(all(c)), (c).end()) // ユニークなvectorにする。連続した値を除去して切り出す。
#define _1 first
#define _2 second
#define pb push_back
#define INF 1145141919
#define MOD 1000000007
#define DEBUG(x) cout << #x << ": " << x << endl;

__attribute__((constructor))
void initial() {
  cin.tie(0);
  ios::sync_with_stdio(false);
}

int main() {
  int b1, b2, b3;
  cin >> b1 >> b2 >> b3;
  if (b3) {
    cout << "Open" << endl;
    return 0;
  }

  if (b1 && b2) {
    cout << "Open" << endl;
    return 0;
  }

  cout << "Close" << endl;
}



Measured memory_bytes: 3228
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const double EPS = 1e-9;
typedef vector<int> vint;
typedef pair<int, int> pint;
#define rep(i, n) REP(i, 0, n)
#define ALL(v) v.begin() , v.end()
#define REP(i, x, n) for(int i = x; i < n; i++)


int main(){
    int n, t, a, ans; cin >> n >> t >> a;
    float maxi = 1000000;
    rep(i, n){
        int h; cin >> h;
        float temp = t - (h * 0.006);
        if(abs(a - temp) < abs(a - maxi)) maxi = temp, ans = i + 1;
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
using System;
using System.Linq;

namespace _164_a
{
    internal class SheepAndWolves
    {
        private static void Main(string[] args)
        {
            var sw = Console.ReadLine()?.Split(' ').Select(int.Parse).ToArray();
            if (sw == null) return;

            var s = sw[0];
            var w = sw[1];

            Console.WriteLine(w >= s ? "unsafe" : "safe");
        }
    }
}


Measured memory_bytes: 28236
#include <bits/stdc++.h>
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define RFOR(i,a,b) for(int i=(b) - 1;i>=(a);i--)
#define REP(i,n) for(int i=0;i<(n);i++)
#define RREP(i,n) for(int i=n-1;i>=0;i--)

#define PB push_back
#define MP make_pair
#define ALL(a) (a).begin(),(a).end()
#define RALL(a) (a).rbegin(),(a).rend()
#define CLR(a) memset(a,0,sizeof(a))
#define SET(a,c) memset(a,c,sizeof(a))

#define DEBUG(x) cout<<"#x"<<": "<<x<<endl

using namespace std;

typedef long long int ll;
typedef vector<int> vi;
typedef vector<ll> vl;

const ll INF = INT_MAX/3;
const ll MOD = 1000000007;
const double EPS = 1e-14;
const int dx[] = {1,0,-1,0} , dy[] = {0,1,0,-1};


struct node{
    int level;
    string name;
    int index;
    vector<node> children;
};
vector<node> v;

void dfs(int num,node& n){
    if(n.level != -1){
	REP(i,n.level) cout << ".";
	cout << n.name << endl;
    }
    REP(i,n.children.size()){
	node next = v[n.children[i].index];
	dfs(next.index,next);
    }
}

int main(){
    int n;
    cin >> n;
    v = vector<node>(n+1);
    v[0] = (node){-1,"",-1,vector<node>()};
    FOR(i,1,n+1){
	int k;
	string m;
	cin >> k >> m;
	v[i] = (node){v[k].level+1,m,i,vector<node>()};
	v[k].children.PB(v[i]);
    }

    dfs(0,v[0]);

    return 0;
}

Measured memory_bytes: 1656
#include<bits/stdc++.h>
#define ll long long int
using namespace std;
ll N, Q, a, b, c, sum, i;
map<ll,ll>fre;
int main()
{
    cin >> N;
    for(i=0;i<N;i++)
    {
        cin >> a;
        fre[a]++;
        sum += a;
    }
    cin >> Q;
    for(i=0;i<Q;i++)
    {
        cin >> a >> b;
        sum += (fre[a]*b-fre[a]*a);
        fre[b] += fre[a];
        fre[a] = 0;
        cout << sum << endl;
    }
}


Measured memory_bytes: 9488
#define LOCAL
#define _USE_MATH_DEFINES
#include <array>
#include <cassert>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <iomanip>
#include <string>
#include <sstream>
#include <vector>
#include <queue>
#include <stack>
#include <list>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <algorithm>
#include <complex>
#include <cmath>
#include <numeric>
#include <bitset>
#include <functional>
#include <random>
#include <ctime>
#include <climits>
using namespace std;
using ll = long long;
#define rep(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define all(x) (x).begin(),(x).end()
#define bit(n) (1LL<<(n))

int main() {
  ll A, B, C, K;
  cin >> A >> B >> C >> K;

  if (K < A)
  {
    cout << K << endl;
  }
  else if (A <= K && K < A+B)
  {
    cout << A << endl;
  }
  else if (A+B <= K)
  {
    cout << A - (K-A-B) << endl;
  }

  return 0;
}

Measured memory_bytes: 3172
#include<stdio.h>

void gcd(int a, int b){
    if (a%b==0){
        printf("%d\n",b);
        return 0;
    }
    gcd(b,a%b);
}

int main(void){
    int a, b;
    scanf("%d",&a);
    scanf("%d",&b);
    gcd(a,b);
}


Measured memory_bytes: 2092
N, K = map(int, input().split())
A = list(map(int, input().split()))

chk = [0]*(N+1)
town = 1
rt = []
roop = 0

while True:
    if chk[town] == 1:
        break
    rt.append(town)
    chk[town] = 1
    town = A[town-1]

if K <= rt.index(town):
    print(rt[K])
else:
    roop = (K-rt.index(town)) % (len(rt)-rt.index(town))
    print(rt[rt.index(town)+roop])

Measured memory_bytes: 32376
/**
	* Author   : Sriram M
	* Date     : 
	* Semester : 5
	* SSN College of Engineering Chennai
    Aug Challenge
**/

#include <bits/stdc++.h>
 
using namespace std;
 
int main()
{
    #ifndef ONLINE_JUDGE 
  
        // For getting input from input.txt file 
        freopen("input.txt", "r", stdin); 
      
        // Printing the Output to output.txt file 
        freopen("output.txt", "w", stdout); 
      
    #endif

    string n;
    
    cin >> n;
    long long sum = 0;
    long long size = n.length();
    for (long long int i = 0; i < size; ++i)
    {
        // cout << n[i] << endl;
        sum += int(n[i] - '0');
    }

    if(sum%9 == 0) cout << "Yes" << endl;
    else cout << "No" << endl;

    return 0;
}


Measured memory_bytes: 3696
#include <bits/stdc++.h>
using namespace std;
#ifdef _DEBUG
#define _GLIBCXX_DEBUG
#include "dump.hpp"
#else
#define dump(...)
#endif

//#define int long long
// typedef __int128_t Int;
#define DBG 1
#define rep(i, a, b) for (int i = (a); i < (b); i++)
#define rrep(i, a, b) for (int i = (b)-1; i >= (a); i--)
#define loop(n) rep(loop, (0), (n))
#define all(c) begin(c), end(c)
const int INF =
    sizeof(int) == sizeof(long long) ? 0x3f3f3f3f3f3f3f3fLL : 0x3f3f3f3f;
const int MOD = (int)(1e9) + 7;
const double PI = acos(-1);
const double EPS = 1e-9;
template <class T> bool chmax(T &a, const T &b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}
template <class T> bool chmin(T &a, const T &b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}

// isBipartite ? =======================================================
vector<vector<int>> g;
vector<int> color;
bool isBipartite_proc(int, int);
bool isBipartite() {
  color.resize(g.size(), 0);
  rep(i, 0, g.size()) {
    if (color[i] == 0) {
      if (!isBipartite_proc(i, 1))
        return false;
    }
  }
  return true;
}
bool isBipartite_proc(int v, int c) {
  color[v] = c;
  for (auto u : g[v]) {
    if (color[u] == c)
      return false;
    if (color[u] == 0 and !isBipartite_proc(u, -c))
      return false;
  }
  return true;
}
//======================================================================
void dfs(int v, int c, int &x, int &y) {
  color[v] = c;
  (c == 1 ? x++ : y++);
  for (auto u : g[v]) {
    if (color[u] == 0)
      dfs(u, -c, x, y);
  }
}
vector<pair<int, int>> partial() {
  color.assign(g.size(), 0);
  vector<pair<int, int>> ret;
  rep(i, 0, g.size()) {
    if (color[i] == 0) {
      int x = 0, y = 0;
      dfs(i, 1, x, y);
      ret.push_back(make_pair(x, y));
    }
  }
  return ret;
}
signed main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << fixed << setprecision(12);

  int N, M;
  cin >> N >> M;
  g.resize(N);
  vector<vector<int>> v(N, vector<int>(N, 1));
  rep(i, 0, N) v[i][i] = 0;
  rep(i, 0, M) {
    int a, b;
    cin >> a >> b;
    a--, b--;
    v[a][b] = v[b][a] = 0;
  }
  rep(i, 0, N) rep(j, 0, N) {
    if (v[i][j])
      g[i].push_back(j);
  }

  if (!isBipartite()) {
    cout << -1 << endl;
    return 0;
  }

  auto p = partial();

  set<pair<int, int>> s;
  s.insert(make_pair(0, 0));
  for (auto x : p) {
    set<pair<int, int>> tmp;
    for (auto y : s) {
      tmp.insert(make_pair(x.first + y.first, x.second + y.second));
      tmp.insert(make_pair(x.first + y.second, x.second + y.first));
    }
    swap(s, tmp);
  }
  int ans = INF;
  for (auto y : s) {
    chmin(ans, y.first * (y.first - 1) / 2 + y.second * (y.second - 1) / 2);
  }
  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 4992
#include <queue>
#include <iostream>
using namespace std;
int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    string s;
    int temp;
    priority_queue<int> pq;
    while(true){
        cin>>s;
        if(s.size()<5)return 0;
        else if(s[0]=='i'){
            cin>>temp;
            pq.push(temp);
        }
        else {
            cout<<pq.top()<<endl;
            pq.pop();
        }
    }
}


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

using namespace std;

string str;
int pos;
int P, Q, R;

int formula() {
	int res = -1;
	if (str[pos] == '-') {
		++pos;
		int a = formula();
		res = 2 - a;
	}
	else if (str[pos] == '(') {
		++pos;
		int a = formula();
		char c = str[pos];
		++pos;
		int b = formula();
		++pos;

		if (c == '*') {
			res = min(a, b);
		}
		else {
			res = max(a, b);
		}
	}
	else if (str[pos] == 'P') {
		res = P;
		++pos;
	}
	else if (str[pos] == 'Q') {
		res = Q;
		++pos;
	}
	else if (str[pos] == 'R') {
		res = R;
		++pos;
	}
	else if (isdigit(str[pos])) {
		res = str[pos] - '0';
		++pos;
	}
	else {
		assert(false);
	}
	return res;
}

int parse(string s) {
	str = s;
	pos = 0;
	return formula();
}

int main() {
	string s;
	while ( cin >> s, s != "." ) {
		int ans = 0;
		for (int p = 0; p < 3; ++p) for (int q = 0; q < 3; ++q) for (int r = 0; r < 3; ++r) {
			P = p, Q = q, R = r;
			if ( parse(s) == 2 ) {
				++ans;
			}
		}
		cout << ans << endl;
	}
}

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

int main() {
  int x, y;
  cin >> x >> y;
  int a[] = {0, 1, 2, 1, 3, 1, 3, 1, 1, 3, 1, 3, 1};
  cout << (a[x]==a[y]?"Yes":"No") << endl;
}


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

// 総数を1000000007（素数）で割った余り
const long long mod = 1e9 + 7;

using ll = long long;
using pii  = pair<int, int>;
using pll = pair<ll, ll>;
#define ull unsigned long long
#define ld long double
#define vi vector<int>
#define vll vector<ll>
#define vc vector<char>
#define vs vector<string>
#define vpii vector<pii>
#define vpll vector<pll>

#define rep(i, n) for (int i = 0, i##_len = (n); i < i##_len; i++)
#define rep1(i, n) for (int i = 1, i##_len = (n); i <= i##_len; i++)
#define repr(i, n) for (int i = ((int)(n)-1); i >= 0; i--)
#define rep1r(i, n) for (int i = ((int)(n)); i >= 1; i--)

#define sz(x) ((int)(x).size())
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()

#define SORT(v, n) sort(v, v + n);
#define VSORT(v) sort(v.begin(), v.end());
#define RSORT(x) sort(rall(x));
#define pb push_back
#define mp make_pair

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

ull gcd(ull a, ull b) { return b ? gcd(b, a % b) : a; }
ull lcm(ull a, ull b) { return a / gcd(a, b) * b; }

int main(){
    string s;
    cin >> s;
    set<char> st;
    rep(i, 3) {
        st.insert(s[i]);
    }
    if (int(st.size()) == 2) cout << "Yes" << endl;
    else cout << "No" << endl;
    return 0;
}



Measured memory_bytes: 256
#include <cmath>
#include<iostream>
#include<vector>
#include<algorithm>
#include<functional>
#include<queue>
#include<set>
#include<map>
#include<bitset>
#include<iomanip>
#include<stack>
#include<set>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
ll mod = 1000000007;
ll a[200005];
int main() {
	ll n, k;
	cin >> n >> k;
	for (int i = 0; i < n; i++) {
		cin >> a[i];
	}
	vector<int>s;
	vector<int>ord(n + 1, -1);
	int c = 1, l = 0;
	{
		int v = 1;
		while (ord[v] == -1) {
			ord[v] = s.size();
			s.push_back(v);
			v = a[v - 1];
		}
		c = s.size() - ord[v];
		l = ord[v];
	}
	if (k < l) {
		cout << s[k] << endl;
	}
	else {
		k -= l;
		k %= c;
		cout << s[l + k] << endl;
	}
	return 0;
}


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

int n,a,mn=1001,mx=-1;
int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);

	cin>>n;
	for(int i=0;i<n;i++){
		cin>>a;
		if(mn>a){
			mn=a;
		}
		if(mx<a){
			mx=a;
		}
	}
	cout<<mx-mn;
	return 0;
}

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

char a[5], c[5];
int d[5];

int main(){
  scanf("%s", a);
  for(int i = 0; i < 4; i++) {
    d[i] = a[i] - '0';
  }
  for(int i = 0; i < 2; i++) {
    int tm1 = d[0] + d[1]*(i*2-1);
    c[0] = i ? '+' : '-';
    for(int j = 0; j < 2; j++) {
      int tm2 = tm1 + d[2]*(j*2-1);
      c[1] = j ? '+' : '-';
      for(int k = 0; k < 2; k++) {
        int tm3 = tm2 + d[3]*(k*2-1);
        c[2] = k ? '+' : '-';
        if(tm3 == 7){
          return 0*printf("%d%c%d%c%d%c%d=7\n", d[0], c[0], d[1], c[1], d[2], c[2], d[3]);
        }
      }
    }
  }
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <math.h>
#include <algorithm>
#include <stdint.h>
#include <queue>
#include <bitset>
#include <iomanip>

#define PI (3.14159265358979323846)
#define INF (1e+9)
#define DIV_NUM (1000000007)

using namespace std;

// ★升目探索のdfs
int w_size, h_size;
typedef char Graph[501][501];
Graph graph;
bool seen[501][501];

void dfs(const Graph& G, int v, int w) {
	// そのセルに対する処理
	seen[v][w] = true;

	// そのセルからつながるセルに処理を移行
	if (v + 1 < h_size) {
		if (!seen[v + 1][w] && G[v + 1][w] == '1') {
			//[v+1][w]に対する処理
			dfs(G, v + 1, w);
		}
		if (w + 1 < w_size) {
			if (!seen[v + 1][w + 1] && G[v + 1][w + 1] == '1') {
				//[v+1][w+1]に対する処理
				dfs(G, v + 1, w + 1);
			}
		}
		if (w - 1 >= 0) {
			if (!seen[v + 1][w - 1] && G[v + 1][w - 1] == '1') {
				//[v+1][w-1]に対する処理
				dfs(G, v + 1, w - 1);
			}
		}
	}
	if (v - 1 >= 0) {
		if (!seen[v - 1][w] && G[v - 1][w] == '1') {
			//[v-1][w]に対する処理
			dfs(G, v - 1, w);
		}

		if (w + 1 < w_size) {
			if (!seen[v - 1][w + 1] && G[v - 1][w + 1] == '1') {
				//[v-1][w+1]に対する処理
				dfs(G, v - 1, w + 1);
			}
		}
		if (w - 1 >= 0) {
			if (!seen[v - 1][w - 1] && G[v - 1][w - 1] == '1') {
				//[v-1][w-1]に対する処理
				dfs(G, v - 1, w - 1);
			}
		}
	}
	if (w + 1 < w_size) {
		if (!seen[v][w + 1] && G[v][w + 1] == '1') {
			//[v][w+1]に対する処理
			dfs(G, v, w + 1);
		}
	}
	if (w - 1 >= 0) {
		if (!seen[v][w - 1] && G[v][w - 1] == '1') {
			//[v][w-1]に対する処理
			dfs(G, v, w - 1);
		}
	}
}

int main()
{
    while (true) {

		cin >> w_size >> h_size;

        if (w_size == 0 && h_size == 0) break;

		// input data
		for (int i = 0; i < h_size; i++) {
			for (int j = 0; j < w_size; j++) {
				cin >> graph[i][j];
				seen[i][j] = false;
			}
		}

		// count islands
		int count = 0;
		for (int i = 0; i < h_size; i++) {
			for (int j = 0; j < w_size; j++) {
				if (graph[i][j] == '1' && seen[i][j] == false) {
					dfs(graph, i, j);
					count++;
				}
			}
		}
		cout << count << endl;
    }

    return 0;
}





Measured memory_bytes: 3408
#include <bits/stdc++.h>
using namespace std;
int main(){
    int x[5];
    scanf("%d %d %d %d %d",&x[0],&x[1],&x[2],&x[3],&x[4]);
    for(int i=0;i<5;i++){
        if(x[i]==0){
            printf("%d",i+1);
            break;
        }
    }
    return 0;
}

Measured memory_bytes: 3756
import java.util.Scanner;
import java.util.Arrays;
import java.util.ArrayDeque;
import java.util.Queue;
import java.util.LinkedList;

public class Main {

    public static void main(String[] args) {
        new Main().solve();
    }

    void solve() {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        int a[] = new int[N];
        int color[] = new int[9];
        Arrays.fill(color, 0);
        for (int i = 0; i < N; i++) {
            a[i] = sc.nextInt();
        }
        Arrays.sort(a);
        for (int i = 0; i < N; i++) {
            if (a[i] > 0 && a[i] < 400) {
                color[0]++;
                continue;
            }
            if (a[i] > 399 && a[i] < 800) {
                color[1]++;
                continue;
            }
            if (a[i] > 799 && a[i] < 1200) {
                color[2]++;
                continue;
            }
            if (a[i] > 1199 && a[i] < 1600) {
                color[3]++;
                continue;
            }
            if (a[i] > 1599 && a[i] < 2000) {
                color[4]++;
                continue;
            }
            if (a[i] > 1999 && a[i] < 2400) {
                color[5]++;
                continue;
            }
            if (a[i] > 2399 && a[i] < 2800) {
                color[6]++;
                continue;
            }
            if (a[i] > 2799 && a[i] < 3200) {
                color[7]++;
                continue;
            }
            color[8]++;
        }
        int ans = 0;
        for (int i = 0; i < 8; i++) {
            if (color[i] > 0) {
                ans++;
            }
        }
        if (ans == 0) {
            System.out.print("1 ");
        } else {
            System.out.print(ans + " ");
        }
        System.out.println(ans + color[8]);
    }

}


Measured memory_bytes: 21844
import java.io.*;

public class Main {
    
    public static void main(String[] args) {
        
        BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
        
        try {
            
            boolean flag = true;
            while (flag) {
                
                String[] line = reader.readLine().split(" ");
                int x = Integer.parseInt(line[0]);
                int y = Integer.parseInt(line[1]);
                final int END = 0;
                
                if (x == END && y == END) {
                    flag = false;
                } else {
                    int big   = Math.max(x, y);
                    int small = Math.min(x, y);
                    System.out.println(small + " " + big);
                }
                
            }
            
        } catch (NumberFormatException e) {
            
            e.printStackTrace();
            
        } catch (IOException e) {

            e.printStackTrace();

        }
        
    }
    
}

Measured memory_bytes: 27184
#include<stdio.h>
#include<stdlib.h>
#include<string.h>

int i,j,k,l,n,ans=0,flag[1000000];

int main(){
	while(scanf("%d",&n)!=EOF){
		memset(flag,0,sizeof(int)*n);
		for(i=2;i<=n;i++){
			if(flag[i]==0){
				for(j=i;j<=n;j+=i){
					flag[j]=1;
				}
				ans++;
			}
		}
		printf("%d\n",ans);
		ans=0;
	}
	return 0;
}

Measured memory_bytes: 4312
def main():
    from sys import setrecursionlimit, stdin, stderr
    from os import environ
    from collections import defaultdict, deque, Counter
    from math import ceil, floor
    from itertools import accumulate, combinations, combinations_with_replacement
    from bisect import bisect_left,bisect_right
    setrecursionlimit(10**6)
    dbg = (lambda *something: stderr.write("\033[92m{}\033[0m".format(str(something)+'\n'))) if 'TERM_PROGRAM' in environ else lambda *x: 0
    input = lambda: stdin.readline().rstrip()
    LMIIS = lambda: list(map(int,input().split()))
    II = lambda: int(input())
    P = 10**9+7
    INF = 10**18+10

    D = II()
    C = LMIIS()
    S = []
    for i in range(D):
        S.append(LMIIS())
    T = [0]*D
    for i in range(D):
        T[i] = II()
    

    M = II()
    Q = []
    for i in range(M):
        Q.append(LMIIS())
    satisfaction = 0
    last_helds = []
    for i in range(26):
        last_helds.append([-1])

    satisfactions = [0] * D
    for i,t in enumerate(T):
        last_helds[t-1].append(i)
        for j in range(26):
            satisfaction -= C[j] * (i-last_helds[j][-1])
        satisfaction += S[i][t-1]
    
    for i in range(26):
        last_helds[i].append(D)

    for d,q in Q:
        old = T[d-1]

        satisfaction -= S[d-1][old-1]
        satisfaction += S[d-1][q-1]

        old_idx = bisect_left(last_helds[old-1],d-1)
        dbg(last_helds[old-1],d-1,old_idx)
        x = last_helds[old-1][old_idx - 1]
        y = last_helds[old-1][old_idx + 1]
        dbg('old x,y',d-1,x,y,(1+(y-1-(d-1)))*(y-(d-1)-1)//2,(1+(d-1)-x-1)*((d-1)-x-1)//2,(1+ y-x-1)*(y-x-1)//2)
        satisfaction += C[old-1] * ((1+(y-1-(d-1)))*(y-(d-1)-1)//2  + (1+(d-1)-x-1)*((d-1)-x-1)//2)
        satisfaction -= C[old-1] * ((1+ y-x-1)*(y-x-1)//2)
        
        new_idx = bisect_left(last_helds[q-1],d-1)
        dbg(last_helds[q-1],d-1,new_idx)
        x = last_helds[q-1][new_idx-1]
        y = last_helds[q-1][new_idx]
        satisfaction += C[q-1]*((1+y-x-1)*(y-x-1)//2)
        satisfaction -= C[q-1]*((1+(d-1)-x-1)*((d-1)-x-1)//2+(1+y-(d-1)-1)*(y-(d-1)-1)//2)
        

        last_helds[old-1].pop(old_idx)
        dbg('insert')
        dbg(last_helds[q-1])
        last_helds[q-1].insert(new_idx,d-1)
        dbg(last_helds[q-1])
        T[d-1] = q

        print(satisfaction)



    
main()

Measured memory_bytes: 87488
import itertools

n = int(input())
s = list(input())

ans = 0


for i in range(10):
    for j in range(10):
        for k in range(10):
            flag1 = 0
            flag2 = 0
            
            for l in range(n):
                if flag1 == 0 and s[l] == str(i):
                    flag1 = 1
                    continue
                
                if flag1 == 1 and flag2 == 0 and s[l] == str(j):
                    flag2 = 1
                    continue
                
                if flag1 == 1 and flag2 == 1 and s[l] == str(k):
                    ans += 1
                    break
                
print(ans)


Measured memory_bytes: 46428
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define mod 1000000007
#define endl "\n"
#define pb push_back
#define w(x) int x; cin>>x; while(x--)
#define f(i,n) for(ll i=0;i<n;i++)
#define ff first
#define ss second
const ll INF = 1e18 + 5;

void ganekasar()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
}

ll accumulate(vector<ll> v, ll s, ll e)
{
    ll sum = 0;

    for(ll i=s; i<=e; i++)
        sum += v[i];

    return sum;
}

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

    vector<ll> a(n);

    ll dp[n][n];

    f(i,n) cin>>a[i];

    for(ll L = n-1; L >= 0; L--)
    {
        for(ll R = L; R < n; R++)
        {
            if(L == R)
                dp[L][R] = 0;
            else
            {
                dp[L][R] = INF;

                ll sum = accumulate(a, L, R);

                for(ll i = L; i < R; i++)
                    dp[L][R] = min(dp[L][R], dp[L][i] + dp[i+1][R] + sum);
            }
        }
    }
    
    cout<< dp[0][n-1] <<endl;

    return 0; 
} 

Measured memory_bytes: 4852
#!/usr/bin/env python3
# atcoder 
# Türkler var mı?
# Herkese memnün oldum
import sys
import math

readline = sys.stdin.buffer.readline
iimr = lambda: map(int, sys.stdin.buffer.readline().rstrip().split())
#sys.setrecursionlimit(10 ** 8)



class atcoder():
    def __init__(self):
        pass

    def çözmek(self):
        N, K = map(int, sys.stdin.readline().split())
        x = [0] * N
        y = [0] * N

        for i in range(N):
           x[i], y[i] = map(int, sys.stdin.readline().split())
        res = []
        res.append(self.関数(N, K, x, y))
        print(*res)	
    
    def 関数(self, n, k, x, y):
        res = 0
        for i in range(n):
            res +=  math.sqrt((x[i] ** 2) + (y[i] ** 2)) <= k
                
        return res 

if __name__ == "__main__":
    ima = atcoder()
    ima.çözmek()



Measured memory_bytes: 24660
#include <stdio.h>

int main(void)
{
	char s[256], ss[256];
	int  i, n, a, x;
	scanf("%s", s);
	a = 0;
	
	for(i=0; s[i] != 0x00; i++);
    n = i;
	
	for(i=0; i<n; i++){
    ss[i] = s[n-1-i];
	}
	
	for(i=0; i<n; i++)
	if (strncmp(&s[i],&ss[i],1)==0){
		
	}else{
		a++;
	}
	a = a/2;

	printf("%d", a);

  
  return 0;
}

Measured memory_bytes: 128
using System;
using System.Collections;
using System.Collections.Generic;
using System.Text;


public class B
{
	public static void Main()
	{
		string[] args;
		
		args = Console.ReadLine().Split(' ');
		int N = Int32.Parse(args[0]);
		int M = Int32.Parse(args[1]);
		int X = Int32.Parse(args[2]);

		args = Console.ReadLine().Split(' ');
		int numLeft = 0;
		for(int i = 0; i < M; i++)
		{
			if(Int32.Parse(args[i]) > X)
				break;
			numLeft++;
		}

		Console.WriteLine(Math.Min(numLeft, M - numLeft));
	}
}





Measured memory_bytes: 13140
#include <cmath>
#include <iostream>
#include <vector>
#include <queue>
#include <deque>
#include <map>
#include <set>
#include <stack>
#include <tuple>
#include <bitset>
#include <algorithm>
#include <functional>
#include <utility>
#include <iomanip>

#define int long long int
#define rep(i, n) for(int i = 0; i < (n); ++i)
#define ALL(x) (x).begin(), (x).end()
#define SZ(x) ((int)(x).size())
#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() )

using namespace std;

typedef pair<int, int> P;

const int INF = 1e15;
const int MOD = 1e9+7;

template <typename T>
using vector2 = vector<vector<T>>;
template <typename T>
vector2<T> initVec2(size_t n0, size_t n1, T e = T()){
    return vector2<T>(n0, vector<T>(n1, e));
}

template <typename T>
using vector3 = vector<vector<vector<T>>>;
template <typename T>
vector3<T> initVec3(size_t n0, size_t n1, size_t n2, T e = T()){
    return vector3<T>(n0, vector2<T>(n1, vector<T>(n2, e)));
}

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

    int r, g, b, n;
    cin >> r >> g >> b >> n;
    int ans = 0;
    rep(i, 3001){
        rep(j, 3001){
            int sum = r * i + g * j;
            if(sum > n){
                continue;
            }
            if((n - sum) % b){
                continue;
            }
            ans++;
        }
    }
    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 888
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <stack>
#include <queue>
#include <cmath>
#include <tuple>
#include <cstdio>
#include <bitset>
#include <sstream>
#include <iterator>
#include <numeric>
#include <map>
#include <cstring>
#include <set>
#include <functional>
#include <iomanip>

using namespace std;

#define DEBUG_ //!!提出時にコメントアウト!!
#ifdef DEBUG_
	#define dump(x)  cerr << #x << " = " << (x) << endl;
#else
	#define dump(x)  ;
#endif

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define SZ(x) ((int)(x).size())
#define pb push_back
#define eb emplace_back

//#define int long long

typedef long long LL;
typedef vector<int> VI;
typedef vector<LL> VL;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef pair<LL, LL> PLL;

template <typename T>
std::string printVector(const std::vector<T> &data)
{
    std::stringstream ss;
    std::ostream_iterator<T> out_it(ss, ", ");
    ss << "[";
    std::copy(data.begin(), data.end() - 1, out_it);
    ss << data.back() << "]";
    return ss.str();
}

const int MOD = 1e9+7;
const LL LINF = 1001002003004005006ll;
const int INF = 1001001001;

signed main(int argc, char const *argv[])
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int A,B; cin >> A >> B;
    char masu[100][100] = {};
    REP(i,50) REP(j,100) masu[i][j] = '#';
    FOR(i,50,100) REP(j,100) masu[i][j] = '.';

    vector<PII> wkouho,bkouho;

    REP(i,500){
        int h = i / 50 * 2;
        int w = i % 50 * 2;
        wkouho.eb(PII(h,w));
    }
    REP(i,500){
        int h = 99 - (i/50*2);
        int w = i % 50 * 2;
        bkouho.eb(PII(h,w));
    }

    REP(i,A-1){
        int h = wkouho[i].first;
        int w = wkouho[i].second;
        masu[h][w] = '.';
    }
    REP(i,B-1){
        int h = bkouho[i].first;
        int w = bkouho[i].second;
        masu[h][w] = '#';
    }
    cout << "100 100" << endl;
    REP(i,100){
        REP(j,100){
            cout << masu[i][j];
        }
        cout << endl;
    }


}


Measured memory_bytes: 256
import sys
from collections import deque
import copy
import math
def get_read_func(fileobject):
    if fileobject == None :
        return raw_input
    else:
        return fileobject.readline

def bin_search(S, x):
    L = 0
    R = len(S) - 1

    while 1:
        M = (L + R)/2
        if (R - L) <= 1:
            if abs(S[R] - x) < abs(S[L] - x):
                return (R, L)
            elif abs(S[R] - x) > abs(S[L] - x):
                return (L, R)
            else:
                if L != R:
                    return (L, R)
                else:
                    return (L, R)
        if x == S[L]:
            return (L, R)
        if x == S[R]:
            return (R, R)
        if S[M] < x:
            L = M
        else:
            R = M



def main():
    if len(sys.argv) > 1:
        f = open(sys.argv[1])
    else:
        f = None
    read_func = get_read_func(f);
    input_raw = read_func().strip().split()
    [A, B, Q] = [int(input_raw[0]), int(input_raw[1]), int(input_raw[2])]

    jinja = []
    for i in range(A):
        input_raw = read_func().strip().split()
        jinja.append(long(input_raw[0]))
    tera = []
    for i in range(B):
        input_raw = read_func().strip().split()
        tera.append(long(input_raw[0]))

    for i in range(Q):
        input_raw = read_func().strip().split()
        x = long(input_raw[0])
        dist1 = [2**63-1 for i in range(2)]
        z = bin_search(jinja, x)
        for j in range(len(z)):
            if z[j] != -1:
                dist1[j] = abs(jinja[z[j]] - x)
                y = bin_search(tera, jinja[z[j]])
                dist1[j]  += abs(tera[y[0]] - jinja[z[j]])

        dist2 = [2**63-1 for i in range(2)]
        z = bin_search(tera, x)
        for j in range(len(z)):
            if z[j] != -1:
                dist2[j] = abs(tera[z[j]] - x)
                y = bin_search(jinja, tera[z[j]])
                dist2[j]  += abs(jinja[y[0]] - tera[z[j]])
        print min(min(dist1), min(dist2))



if __name__ == '__main__':
    main()


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

pair<int,int> bd[50][10]; // (間違い数, 経過時間)

void clear() {
    for (int i=0; i<50; ++i) {
        for (int j=0; j<10; ++j) {
            bd[i][j] = make_pair(0, -1);
        }
    }
}

int main() {
    int M, T, P, R;
    while (cin >> M >> T >> P >> R, M) {
        clear();
        for (int i=0; i<R; ++i) {
            int m, t, p, j;
            cin >> m >> t >> p >> j;
            if (j) bd[t-1][p-1].first ++;
            else bd[t-1][p-1].second = m;
        }
        vector<tuple<int,int,int>> scores(T); // (正解数, -所要時間, チーム番号)
        for (int i=0; i<T; ++i) {
            scores[i] = make_tuple(0, 0, i+1);
            for (int j=0; j<P; ++j) {
                if (bd[i][j].second < 0) continue;
                get<1>(scores[i]) -= bd[i][j].second + bd[i][j].first * 20;;
                get<0>(scores[i]) ++;
            }
        }
        sort(scores.rbegin(), scores.rend());

        for (int i=0; i<T; ++i) {
            if (i == 0) {
                cout << get<2>(scores[i]);
            } else {
                bool tie = get<0>(scores[i-1]) == get<0>(scores[i]) && get<1>(scores[i-1]) == get<1>(scores[i]);
                cout << (tie ? "=" : ",") << get<2>(scores[i]);
            }
        }
        cout << endl;
    }
    return 0;
}


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

public class Main {
    public static void main(String[] args) throws Exception {
        BufferedReader r = new BufferedReader(new InputStreamReader(System.in));
        int n = readInt(r);
        
        if (n <= 1) {
            output(-1);
            return;
        } else {
            int r_i = readInt(r);
            int r_j = readInt(r);
            int delta = r_j - r_i;
            int maxDelta = delta;
            
            if (r_i > r_j) {
                r_i = r_j;
            }

            for (int i = 0;i < (n -2);i++) {
                r_j = readInt(r);
                delta = r_j - r_i;
                if (delta > maxDelta) {
                    maxDelta = delta;
                }

                if (r_i > r_j) {
                    r_i = r_j;
                }
            }
            
            output(maxDelta);
        }
    }

    public static void output(int x) {
        System.out.println(x);
    }

    public static int readInt(BufferedReader r) throws Exception {
        return Integer.parseInt(r.readLine());
    }
}

Measured memory_bytes: 42052
#include <bits/stdc++.h>
        using namespace std;
         
        int main(){
         string S;
          cin>>S;
          int A,B,C;
          A=0;
          B=0;
          C=0;
          for(int i=0; i<3 ; i++){
          	if(S.at(i) == 'a'){
          	A++;
          	}
          	if(S.at(i) == 'b'){
          	B++;
          	}
          	if(S.at(i) == 'c'){
          	C++;
          	}



          
          }
          if(A==1 && B==1 && C==1){
          cout<<"Yes"<<endl;
          }else{
          cout<<"No"<<endl;
          }
        }

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

int main()
{
    string s, t;
    cin >> s >> t;
    vector<int> places[26];
    size_t slen = s.size();
    for (size_t i = 0; i < slen; i++)
    {
        places[s[i] - 'a'].push_back(i);
    }

    size_t tlen = t.size();
    long long int n = 1;
    int cur = -1;
    for (size_t i = 0; i < tlen; i++)
    {
        int ci = t[i] - 'a';
        if (places[ci].size() == 0)
        {
            cout << -1 << endl;
            return 0;
        }

        vector<int>::iterator it;
        it = upper_bound(places[ci].begin(), places[ci].end(), cur);
        if (it == places[ci].end())
        {
            cur = places[ci][0];
            n++;
            continue;
        }
        else
        {
            cur = *it;
        }
    }

    long long int i = (n - 1) * slen + cur + 1;
    cout << i << endl;
}

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

using namespace std;

int main(void)
{
    int N;
    cin >> N;
    vector<int> a(N);
    for(int i = 0; i < N; ++i)
    {
        cin >> a[i];
    }

    sort(a.begin(), a.end(), greater<int>());

    int ans = 0;
    int sign = 1;
    for(auto& e : a)
    {
        ans += sign * e;
        sign *= -1;
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

class Node{
	Integer parent = null;
	public Node(int v) {
		this.value = v;
	}
	int value = 0;
	Node left = null;
	Node right = null;
} 

public class Main {
	
	private static Scanner src;
	public static Node root;
	public static void main(String[] args) {
		src = new Scanner(System.in);
		int n = src.nextInt();
		for(int i = 0; i < n; i++) {
			String next = src.next();
			if(next.equals("insert")) {
				insert(root, src.nextInt());
			}
			else if(next.equals("find")) {
				System.out.println(find(root, src.nextInt()));
			}
			else if(next.equals("print")) {
				inorder(root); System.out.println();
				preorder(root); System.out.println();
			}
		}

	}
	private static String find(Node n, int v) {
		if(n == null) {return "no";}
		else if (n.value == v) {return "yes";}
		else if (v < n.value) {return find(n.left, v);}
		else {return find(n.right, v);}
	}
	private static void insert(Node n, int v) {
		if(n == null) {n = new Node(v); if(root == null) {root = n;} return;}
		if(v > n.value) { if(n.right == null ) { n.right = new Node(v);} else {insert(n.right, v);} }
		else { if(n.left == null ) { n.left = new Node(v);} else {insert(n.left, v);} }
		return;
	}

	private static void postorder(Node n) {
		if(n.left != null) postorder(n.left);
		if(n.right != null) postorder(n.right);
		System.out.print(" " + n.value);
	}
	private static void inorder(Node n) {
		if(n.left != null) inorder(n.left);
		System.out.print(" " + n.value);
		if(n.right != null) inorder(n.right);
	}
	private static void preorder(Node n) {
		System.out.print(" " + n.value);
		if(n.left != null) preorder(n.left);
		if(n.right != null) preorder(n.right);
	}
}



Measured memory_bytes: 207356
#include <iostream>
#define rep(i, n) for(i = 0; i < n; i++)
using namespace std;

int n, m;
int l, r;
int imos[100010];

int main() {
	int i;
	
	cin >> n >> m;
	rep(i, m) {
		cin >> l >> r;
		l--;
		imos[l]++;
		imos[r]--;
	}
	rep(i, n) imos[i + 1] += imos[i];
	
	int ans = 0;
	rep(i, n) {
		if (imos[i] == m) ans++;
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 640
#include<iostream>
#include<cstdio>
#include<cmath>
using namespace std;
typedef long long int LL;
LL su[100005][2];
LL d[100005][2][2];
int main(){
	LL a,b,c;
	LL ff[5]={0};
	LL x,y;
	int i,j,k;
	LL n,t;
	LL s=0;
	cin>>n>>t;
	for(i=0;i<n;i++){
		cin>>su[i][0]>>su[i][1];
	}
	a=0,b=0,c=0;
	for(i=0;i<n;i++){
		c+=su[i][1];
		b=c-su[i][0];
		d[i+1][0][0]=d[i][0][0]>b?d[i][0][0]:b;
		b=c-su[i][0]*2;
		d[i+1][0][1]=d[i][0][1]>b?d[i][0][1]:b;
	}
	a=0,b=0,c=0;
	for(i=n-1;i>=0;i--){
		c+=su[i][1];
		b=c-(t-su[i][0]);
		d[i][1][0]=d[i+1][1][0]>b?d[i+1][1][0]:b;
		b=c-(t-su[i][0])*2;
		d[i][1][1]=d[i+1][1][1]>b?d[i+1][1][1]:b;
	}
	for(i=0;i<=n;i++){
		//printf("%d %d %d %d\n",d[i][0][0],d[i][0][1],d[i][1][0],d[i][1][1]);
		a=d[i][0][0]+d[i][1][1];
		if(s<a)s=a;
		a=d[i][0][1]+d[i][1][0];
		if(s<a)s=a;
	}
	cout<<s<<endl;
	return 0;
}
		


Measured memory_bytes: 4992