akhauriyash/Code-Regression huggingface dataset:
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <vector>
#include <queue>
#include <map>
#include <iterator>
#include <cmath>
#include <set>
#include <deque> 
#include <string>


using namespace std;

struct Point {
	long long x, y;
};

Point pts[200010];

long long n;

//|x1 - x2| + |y1 - y2|
//绝对值根据正负向，共四种情况，分情况讨论
//(x1 + y1) - (x2 + y2)
//(x1 - y1) - (x2 - y2)
//(-x1 + y1) - (-x2 + y2)
//(-x1 - y1) - (-x2 - y2)

int main()
{
	scanf("%lld", &n);
	
	for (int i = 0 ; i < n ; i++) {
		scanf("%lld%lld", &(pts[i].x), &(pts[i].y));
	}
	
	long long maxDist = 0;

	long long maxCoord, minCoord;
	long long curCoord;
	long long curDist;
	
	//x1+y1
	maxCoord = pts[0].x + pts[0].y;
	minCoord = pts[0].x + pts[0].y;
	for (int i = 1 ; i < n ; i++) {
		curCoord = pts[i].x + pts[i].y;
		if (maxCoord < curCoord) maxCoord = curCoord;
		if (minCoord > curCoord) minCoord = curCoord;
	}
	curDist = maxCoord - minCoord;
	if (maxDist < curDist) maxDist = curDist;
	
	//x1-y1
	maxCoord = pts[0].x - pts[0].y;
	minCoord = pts[0].x - pts[0].y;
	for (int i = 1 ; i < n ; i++) {
		curCoord = pts[i].x - pts[i].y;
		if (maxCoord < curCoord) maxCoord = curCoord;
		if (minCoord > curCoord) minCoord = curCoord;
	}
	curDist = maxCoord - minCoord;
	if (maxDist < curDist) maxDist = curDist;
	
	
	//-x1+y1
	maxCoord = -pts[0].x + pts[0].y;
	minCoord = -pts[0].x + pts[0].y;
	for (int i = 1 ; i < n ; i++) {
		curCoord = -pts[i].x + pts[i].y;
		if (maxCoord < curCoord) maxCoord = curCoord;
		if (minCoord > curCoord) minCoord = curCoord;
	}
	curDist = maxCoord - minCoord;
	if (maxDist < curDist) maxDist = curDist;
	
	//-x1-y1
	maxCoord = -pts[0].x - pts[0].y;
	minCoord = -pts[0].x - pts[0].y;
	for (int i = 1 ; i < n ; i++) {
		curCoord = -pts[i].x - pts[i].y;
		if (maxCoord < curCoord) maxCoord = curCoord;
		if (minCoord > curCoord) minCoord = curCoord;
	}
	curDist = maxCoord - minCoord;
	if (maxDist < curDist) maxDist = curDist;
	
	printf("%lld\n", maxDist);

	return 0;
}




Measured memory_bytes: 4860
#include <stdio.h>
int main(void){
	
	int h,w,i,j;
	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++){
				printf("#");
			}
			printf("\n");
		}
		printf("\n");
	}
	
	return 0;
}


Measured memory_bytes: 2052
#include <iostream>
#include <fstream>
#include <string>


using namespace std;

int main(){
#ifdef CIN
	ifstream cin("input.txt");
	ofstream cout("output.txt");

#endif

	int h, w;

	while (true)
	{

		cin >> h >> w;

		if (h == 0 && w == 0) break;

		for (int i = 1; i <= h; i++)
		{
			for (int j = 1; j <= w; j++)
			{
				switch((j+i) % 2) {
				case 0:
					cout << "#";
					break;
				case 1:
					cout << '.';
					break;
				}
			}
			cout << endl;
		}
		cout << endl;
	}


}

Measured memory_bytes: 1152
#include <iostream>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <utility>
#include <algorithm>
#include <cmath>
#include <climits>
#include <iomanip>
#include <queue>
#include <stack>

using namespace std;

typedef long long ll;

int main() {
    long long a;
    string s;
   
    cin >> a >> s;
    ll b = 0;
    for (int i = 0; i < s.size(); i++) {
        if (i != 1) {
        b *= 10;
        b += s[i]-'0';
        }
    }

    
    cout << a * b / 100  << endl;

    return 0;
}

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

using namespace std;
int main(){
	string s;
	cin>>s;
	int ans=0;;
	for(int i=0;i<s.size();i++){
		int cnt=0;
		while(s[i]=='R'){
			cnt++;
			i++;
		}
		ans=max(ans,cnt);
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 3592
#include<cstdio>
#include<vector>
#include<algorithm>
using namespace std;

const int INF = 1000000000;

struct edge{int to,cap,rev;};

vector<edge> G[100];
bool used[100];

void add_edge(int from,int to,int cap){
	G[from].push_back((edge){to,cap,G[to].size()});
	G[to].push_back((edge){from,0,G[from].size()-1});
}

int dfs(int v,int t,int f){
	if(v==t) return f;
	used[v] = true;
	for(int i=0;i<G[v].size();i++){
		edge &e = G[v][i];
		if(!used[e.to]&&e.cap>0){
			int d = dfs(e.to,t,min(e.cap,f));
			if(d>0){
				e.cap -= d;
				G[e.to][e.rev].cap += d;
				return d;
			}
		}
	}
	return 0;
}

int max_flow(int s,int t){
	int flow = 0;
	while(true){
		fill(used,used+100,false);
		int f = dfs(s,t,INF);
		if(f>0) flow += f;
		else return flow;
	}
}

int main(){
	int v,e;
	scanf("%d%d",&v,&e);
	for(int i=0;i<e;i++){
		int u,v,c;
		scanf("%d%d%d",&u,&v,&c);
		add_edge(u,v,c);
	}
	printf("%d\n",max_flow(0,v-1));
}

Measured memory_bytes: 2792
/*
  AOJ 2362
  Title:Chicken or the Egg
  @kankichi573
*/
#include <stdio.h>

char s[7001];
char solve(char *s)
{
  char pc,c,ret;
  int wl,maxwl;

  pc=' ';maxwl=0;wl=0;pc=*s;
  while(1)
   {
      c=*s;
      if(c=='e')
	s += 3;
      else if(c=='c')
	s += 7;

      wl++;
      
      if(pc==c || !c)
	{
	if(wl>maxwl)
	  {
	    ret=pc;
	    maxwl=wl;
	    //printf("ret=%c [%d]\n",ret,wl);
	  }
	wl =0;
	}
      if(!c)
	break;
      pc=c;
   }
  return(ret);
}

main()
{
  char ret;

  scanf("%s",&s[0]);
  ret=solve(s);

  if(ret=='e')
    printf("egg\n");
  else if(ret=='c')
    printf("chicken\n");
  else
    printf("error ret=%c\n",ret);
  return(0);
}

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

int main()
{
    int m, f, r, sum;
    char grade;
    while(true)
    {
        cin >> m >> f >> r;
        if(m == -1 && f == -1 && r == -1){ break; }

        sum = m + f;
        if(m == -1 || f == -1){ grade = 'F'; }
        else if(sum >= 80)    { grade = 'A'; }
        else if(sum >= 65)    { grade = 'B'; }
        else if(sum >= 50)    { grade = 'C'; }
        else if(sum >= 30)
        {
            if(r >= 50)       { grade = 'C'; }
            else              { grade = 'D'; }
        }
        else                  { grade = 'F'; }
        cout << grade << endl;
    }

    return 0;
}

Measured memory_bytes: 3088
n = int(input())
csf = []

for i in range(n - 1):
    csf.append(list(map(int, input().split())))

for i in range(n - 1):
    t = 0
    for j in range(i, n - 1):
        t = max(t, csf[j][1])
        if t % csf[j][2] > 0:
            t += csf[j][2] - t % csf[j][2]
        t += csf[j][0]
    print(t)
print(0)

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

int main() {
	long long int x, y;
	cin >> x >> y;
	if (x == 2 || y == 2) cout << 0;
	else if (x == 1 || y == 1) cout << abs(x * y - 2);
	else cout << (x - 2) * (y - 2);
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, a) for(int i=0; i<a; i++)
#define rep1(i, a, b) for(int i=a; i<b; i++)
#define MOD 1000000007;
using ll = long long;
using namespace std;

int main(){
    int n, m;
    cin >> n >> m;
    vector<vector<ll>> a(n, vector<ll>(m, 0)), dp(n, vector<ll>(m, 0));
    for(int i=0; i<n; i++){
        string s;
        cin>>s;
        rep(j, s.length()){
            if(s[j]=='.')
                a[i][j] = 0;
            else
                a[i][j] = 1;
        }
    }
    rep(i, n)
        rep(j, m){
            if(a[i][j])
                dp[i][j]=0;
            else if(!i&&!j)
                dp[i][j]=1;
            else if(!j)
                dp[i][j] = dp[i-1][j];
            else if(!i)
                dp[i][j] = dp[i][j-1];
            else
                dp[i][j] = (dp[i-1][j]+dp[i][j-1])%(ll)MOD;
        }
    cout<<dp[n-1][m-1];
}

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

int main()
{
    int h, w;
    cin >> h >> w;
    vector<vector<char>> a(h+2, vector<char>(w+2));

    rep(i, h + 2)
    {
        rep(j, w + 2)
        {
            a[i][j] = '#';
        }
    }

    for (int i = 1; i <= h; i++)
    {
        for (int j = 1; j <= w; j++)
        {
            cin >> a[i][j];
        }
    }



    rep(i,h+2)
    {
        rep(j,w+2)
        {
            cout << a[i][j];
        }
        cout << endl;
    }
    cout << endl;
    return 0;
}


Measured memory_bytes: 256
import sys
n,m=map(int,input().split())
if m==0:
  if n==1:
    print(0)
  elif n==2:
    print(10)
  elif n==3:
    print(100)
  sys.exit()
A=[0]*n
B=[[0]*2 for i in range(m)]
for i in range(m):
  B[i]=list(map(int,input().split()))
B.sort()
if n!=1 and B[0]==[1,0]:
  print(-1)
  sys.exit()
if n==1 and B[0]==[1,0]:
  print(0)
  sys.exit()
for i in range(m-1):
  if B[i][0]==B[i+1][0]:
    if B[i][1]!=B[i+1][1]:
      print(-1)
      sys.exit()
for i in range(m):
  A[B[i][0]-1]=B[i][1]
if A[0]==0:
  A[0]=1
ans=0
for i in range(n):
  ans=ans+A[i]*10**(n-i-1)
print(ans)

Measured memory_bytes: 3064
n = int(input())
t, x, y = 0, 0, 0
ans = "No"

for i in range(n):
 tn, xn, yn = list(map(int, input().split()))
 if tn%2 != (xn+yn)%2: break
 if abs(x-xn)+abs(y-yn)>tn-t: break
 t, x, y = tn, xn, yn
 if i==n-1: ans="Yes"

print(ans)

Measured memory_bytes: 3060
#include<iostream>

using namespace std;

int solve(int n){
  if(n == 1) return 0;
  int m = 1;
  for(int i=2; i*i<n; ++i){
    if(n%i == 0){
      m += i;
      if(i != n/i) m += n/i;
    }
  }
  return m;
}

int main(){
  int n, m;
  while(1){
    cin >> n;
    if(!n) break;
    m = solve(n);
    if(n == m) cout << "perfect number" << endl;
    else if(n < m) cout << "abundant number" << endl;
    else cout << "deficient number" << endl;
  }
  return 0;
}

Measured memory_bytes: 1156
N = int(input())
S = []
for s in range(N):
  S.append(input())
print('AC', end=' ') 
print('x', end=' ')
print(S.count('AC'))

print('WA', end=' ') 
print('x', end=' ')
print(S.count('WA'))

print('TLE', end=' ') 
print('x', end=' ')
print(S.count('TLE'))

print('RE', end=' ') 
print('x', end=' ')
print(S.count('RE'))


Measured memory_bytes: 16320
#include <iostream>
#include <cstdio>
#include <vector>
#include <queue>
#include <string>
#include <cmath>
#include <algorithm>

using namespace std;

#define pb push_back
#define mp make_pair
#define ff first
#define ss second

typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<ll, ll> pii;
typedef vector<pii> vii;
typedef priority_queue<ll> pq;

const int MOD = 1e9+7;
const int INF = 2e9;
const int MAX_N = 1;

int N, ans = INF;
vi ABC(3);

int main() {
  cin >> N >> ABC[0] >> ABC[1] >> ABC[2];
  vi lens(N);
  for (int i = 0; i < N; i++) cin >> lens[i];

  for (int s = 0; s < pow(4, N); s++) {
    int S = s;
    vi meth(N), used(4, 0);
    vvi ABC_set(3);
    for (int i = 0; i < N; i++) {
      meth[i] = S & 3;
      S /= 4;
      if (meth[i] != 0) {
        ABC_set[meth[i]-1].pb(i);
      }
    }
    if (ABC_set[0].empty() || ABC_set[1].empty() || ABC_set[2].empty()) continue;

    int cost = 0;
    for (int i = 0; i < 3; i++) {
      int len = 0;
      for (int j = 0; j < ABC_set[i].size(); j++) {
        len += lens[ABC_set[i][j]];
      }
      cost += 10 * ((int)ABC_set[i].size() - 1);
      cost += abs(ABC[i] - len);
    }
    ans = min(ans, cost);
  }

  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 384
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define endl "\n"
int main(){
	#ifndef ONLINE_JUDGE
    // for getting input from input.txt
    freopen("input.txt", "r", stdin);
    // for writing output to output.txt
    freopen("output.txt", "w", stdout);
#endif
       ios_base::sync_with_stdio(false);
       cin.tie(0);
   int a , b;
   cin>>a>>b;
   if(a< 2*b){ 
   	cout<<0<<endl; 
   }
   else{
   	cout<<a - 2*b <<endl;  
   }
   return 0;
}

Measured memory_bytes: 3636
#include<iostream>
#include<string>
#include<cstdio>
#include<vector>
#include<cmath>
#include<algorithm>
#include<functional>
#include<iomanip>
#include<queue>
#include<ciso646>
#include<random>
#include<map>
#include<set>
#include<complex>
#include<bitset>
#include<stack>
#include<unordered_map>
#include<utility>
#include<tuple>
using namespace std;
typedef long long ll;
typedef unsigned int ui;
const ll mod = 1000000007;
const ll INF = (ll)1000000007 * 1000000007;
typedef pair<int, int> P;
#define stop char nyaa;cin>>nyaa;
#define rep(i,n) for(int i=0;i<n;i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define Per(i,sta,n) for(int i=n-1;i>=sta;i--)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define per1(i,n) for(int i=n;i>=1;i--)
#define Rep1(i,sta,n) for(int i=sta;i<=n;i++)
typedef long double ld;
typedef complex<ld> Point;
const ld eps = 1e-8;
const ld pi = acos(-1.0);
typedef pair<ll, ll> LP;

int n,m;
ll a[100010],S=0;

void solve(){
    cin >> n >> m;
    priority_queue<ll> que;
    rep(i,n){
        cin >> a[i];
        que.push(a[i]);
        S+=a[i];
    }
    rep(i,m){
        ll s=que.top();
        que.pop();
        S+=s/2-s;
        s/=2;
        que.push(s);
    }
    cout << S << endl;
    
}

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout << fixed << setprecision(50);
    solve();
}

Measured memory_bytes: 1912
#include <iostream>
#include <algorithm>
#include <utility>
#include <vector>
#include <string>
#include <queue>

using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
#define REP(i, n) for (int i = 0; i < (n); i++)
#define RREP(i, n) for (int i = (n) - 1; i >= 0; i--)
#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define RFOR(i, a, b) for (int i = (a); i > (b); i--)
#define ALL(a) (a).begin(), (a).end()

int N, A[100000];
vector<pii> result;

int rec(queue<int>& p, queue<int>& n) {
    if (p.size() == 1) {
        int ret = A[p.front()];
        while (!n.empty()) {
            int v = n.front(); n.pop();
            result.push_back({ret, A[v]});
            ret -= A[v];
        }
        return ret;
    }

    int h = p.front(); p.pop();
    int r = rec(n, p);
    result.push_back({A[h], r});
    return A[h] - r;
}

int main() {
    bool all_positive = true, all_negative = true;
    cin >> N;
    REP(i, N) {
        cin >> A[i];
        all_positive &= A[i] > 0;
        all_negative &= A[i] <= 0;
    }
    sort(A, A + N);

    int s = 0, e = N;
    queue<int> p, n;
    if (all_positive) {
        n.push(0);
        s = 1;
    }
    if (all_negative) {
        p.push(N - 1);
        e = N - 1;
    }
    FOR(i, s, e) {
        if (A[i] > 0) p.push(i);
        else n.push(i);
    }

    cout << rec(p, n) << endl;
    for (auto p : result) cout << p.first << " " << p.second << endl;
    return 0;
}

Measured memory_bytes: 8052
#include <bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define countof(array) (sizeof(array) / sizeof(array[0]))
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = (n)-1; i >= 0; --i)
#define srep(i,n,s) for(int i = s; i < (n); ++i)
#define rsrep(i,n,s) for(int i = (n)-1; i >= s; --i)
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
#define aall(a) (a), (a)+countof(a)//for array sorting
#define raall(a) (a), (a)+countof(a), greater<>()
#define show(x) cout<<#x<<" = "<<x<<endl;
#define vfind(v, a) find(all(v), a) != v.end()
#define yn(f) { if (f) puts("YES"); else puts("NO"); }
#define yns(f) { if (f) puts("Yes"); else puts("No"); }
#define show_ary(...) { cout<<#__VA_ARGS__<<" = "; for (const auto& x : (__VA_ARGS__)) { cout<<x<<" "; } cout<<endl; }
#define show_pair(...) cout<<#__VA_ARGS__<<" = "<<endl; for (const auto& x : (__VA_ARGS__)) { cout<<"  "<<x.fi<<" : "<<x.se<<endl; }
#define out_ary(...) { for (const auto& x : (__VA_ARGS__)) { cout<<x<<" "; } cout<<endl; }
#define argmax(v) distance((v).begin(), max_element(all(v)))
#define argmin(v) distance((v).begin(), min_element(all(v)))
#define vmax(v) *max_element(all(v))
#define vmin(v) *min_element(all(v))
typedef long long int ll;
typedef pair<int, int> P;
typedef vector<P> vpair;
typedef vector<int> vint;
typedef vector<ll> vll;
typedef vector<double> vdouble;
typedef vector<string> vstr;
typedef vector<bool> vbool;
typedef vector<vint> vvint;
typedef vector<vll> vvll;
typedef vector<vstr> vvstr;
typedef vector<vbool> vvbool;
const ll LINF = 2000000000000000000ll;
const int INF = 1000000100;
const ll MOD = 1e9+7;

int main() {
    string s;
    cin >> s;
    int z = 0, o = 0;
    rep(i, s.length()) {
        if (s[i] == '0') z++;
        else o++;
    }
    int ans = min(z, o) * 2;
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 512
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>

using namespace std;

int main() {
	int n;

LABEL:	while (cin >> n, n) {
		vector<pair<int, int> > island(n);
		int max = 0;
		int a, b;
		for (int i = 0; i < n; i++) {
			cin >> a >> b;
			island[i] = make_pair(b, a);
			max += a;
		}
		sort(island.begin(), island.end());

		int i;
		for (i = n-1; i >= 0; i--) {
			if (island[i].first < max) {
				cout << "No" << endl;
				goto LABEL;
			}
			max -= island[i].second;
		}
		cout << "Yes" << endl;
	}
	return 0;
}

Measured memory_bytes: 3008
import java.io.InputStream;
import java.io.PrintStream;
import java.util.*;
import java.util.stream.Collectors;
import java.util.stream.IntStream;

public class Main {

  public static void main(String[] args) {
    solve(System.in, System.out);
  }

  static void solve(InputStream is, PrintStream os) {
    Scanner sc = new Scanner(is);

    /* read */
    String s = sc.next();

    os.println(search(s));

  }
  private static long search(String s) {

    int n = s.length();

    long sum = 0;
    int j = 0;
    while (j < n){

      if (s.charAt(j) != 'A') {
        j++;
        continue;
      }

      // for each, find A
      // found A

      int aCount = 0;
      int i = j;
      while (i < n && (s.charAt(i) == 'A' || i < n - 1 && (s.charAt(i) == 'B' && s.charAt(i + 1) == 'C'))) {
        if (s.charAt(i) == 'A') {
          aCount++;
          i++;
        } else {
          sum += aCount;
          i += 2;
        }
      }
      j = i;
    }
    return sum;
  }
//  private static long search(String s) {
//
//    s = s.replaceAll("BC", "D");
//
//    int n = s.length();
//
//    long sum = 0;
//    int j = 0;
//    while (j < n){
//
//      if (s.charAt(j) != 'A') {
//        j++;
//        continue;
//      }
//
//      // for each, find A
//      // found A
//
//      int aCount = 0;
//      int i = j;
//      while (i < n && (s.charAt(i) == 'A' || s.charAt(i) == 'D')) {
//        if (s.charAt(i) == 'A') {
//          aCount++;
//        }
//        if (s.charAt(i) == 'D') {
//          sum += aCount;
//        }
//        i++;
//      }
//      j = i;
//    }
//    return sum;
//  }
}

Measured memory_bytes: 28020
#include <iostream>
#include <cstdlib>
#include <string>
#include <vector>
#include <stack>
#include <map>
#include <set>
#include <algorithm>
#include <numeric>
#include <math.h>
#include <stdio.h>
#include <ctype.h>
#include <ios> 
#include <iomanip>
using namespace std;

#define N_MAX   (100000)
#define LL_MAX_NUM (1LL<<60)
#define INF 1e7

typedef long long ll;
typedef long long int lli;

int main() {
	int N, ans; cin >> N;
    ans = 0;
    for (int i = 1; i <= N; i++)
    {
        if ((i >= 1 && i <= 9) || (i >= 100 && i <= 999) || (i >= 10000 && i <= 99999))
        {
            ans++;
        }
    }
    cout << ans << endl;
	return 0;
}

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

//define gcd and lcm (using 64bit)
ll gcd(ll a,ll b){
    if (a < b) {
        //^はxor(bitwise operator)。以下三行でswap(a,b)を行っている。
        a ^= b;
        b ^= a;
        a ^= b;
    }
    //only when b==0,this program finds that b means false and returns a.
    return b ? gcd(b, a % b) : a;
}

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


int main(){
    string s,t;
    cin>>s>>t;
    int ans=0;
    rep(i,3){
        if(s[i]==t[i]) ans++;
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
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<typename T> using min_priority_queue = priority_queue<T, vector<T>, greater<T>>;
const ll INF = 1LL<<60;
const ll MOD = 1e9 + 7;


int main() {
    ll N,K;
    cin >> N >> K;
    vector<ll> vec;
    map<ll,ll> mp;
    for (ll i = 0;i<N;i++) {
        ll a,b;
        cin >> a >> b;
        mp[a] += b;
    }
    ll cnt=0;
    for (pair<ll,ll> p : mp) {
        cnt += p.second;
        if (cnt >= K) {
            cout << p.first << endl;
            break;
        }
    }


}

Measured memory_bytes: 4224
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
const ll MOD = 1000000007;

int main(){
    int A,B;
    cin >> A >> B;
    
    if((A+B)%2 != 0)
        cout << "IMPOSSIBLE" << "\n";
    else
    cout << (A+B)/2 << "\n";
    return 0;
}


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

long long int sum(long long int x) {
  long long int sum = 0;
  for(int i = 0; i < x + 1; i++)
    sum = sum + i;
  return sum;
}

int main() {
  long long int N;
  cin >> N;
  cout << sum(N) - sum(N / 3) * 3 - sum(N / 5) * 5 + sum(N / 15) * 15 << endl;
}

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

using namespace std;

int main(void) {
    int A, B;
    cin >> A >> B;
    
    int ans = 0;
    for (int i = 0; i < 2; i++) {
        if (A < B) {
            ans += B;
            B--;
        } else {
            ans += A;
            A--;
        }
    }

    cout << ans << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < n; i++)
#define REPR(i, n) for (int i = n; i >= 0; i--)
#define FOR(i, m, n) for (int i = m; i < n; i++)
#define ALL(v) v.begin(), v.end()
using namespace std;
typedef long long ll;
typedef long double ld;
int main()
{
  int n;
  string s;
  cin >> n >> s;
  vector<int> west(n+1,0), east(n+1,0);

  FOR(i,1,n+1){
    west[i] = west[i-1] + (s[i-1]=='W' ? 1 : 0);
    east[i] = east[i-1] + (s[i-1]=='E' ? 1 : 0);
  }
  
  int res = n;
  REP(i,n){
    int west_n = west[i] - west[0];
    int east_n = east[n] - east[i+1];
    res = min(res, west_n + east_n);
  }
  
  cout << res << endl;
  return 0;
}


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

int main(){
    int n;
    cin >> n;
    vector<pair<int, int>> x(n);
    for (int i = 0; i < n; i++) x[i].second = i + 1;
    for (int i = 0; i < n; i++) cin >> x[i].first;
    sort(x.begin(), x.end());
    for (int i = 0; i < n; i++) {
        cout << x[i].second;
        if (i != n - 1) cout << " ";
    }
    cout << endl;
}

Measured memory_bytes: 1536
import java.util.Scanner;

public class Main {
	static class Matryoshka {
		int h, r;
		int degree;
		Matryoshka neighbor[];
		int cost;

		Matryoshka(int h, int r) {
			this.h = h;
			this.r = r;
			this.degree = 0;
			this.cost = 1;
		}

		static public Matryoshka[] cat(Matryoshka a[], Matryoshka b[]) {
			Matryoshka x[] = new Matryoshka[a.length + b.length];
			for (int i = 0; i < a.length; i++) {
				x[i] = a[i];
			}
			for (int i = 0; i < b.length; i++) {
				x[a.length + i] = b[i];
			}
			return x;
		}
	}

	public static void main(String args[]) {
		Scanner sc = new Scanner(System.in);
		int n, m;
		Matryoshka a[], b[];
		int max;

		while (true) {
			max = 1;
			n = sc.nextInt();
			if (n == 0) {
				break;
			}
			a = new Matryoshka[n];
			for (int i = 0; i < n; i++) {
				int h = sc.nextInt();
				int r = sc.nextInt();
				a[i] = new Matryoshka(h, r);
			}
			m = sc.nextInt();
			b = new Matryoshka[m];
			for (int i = 0; i < m; i++) {
				int h = sc.nextInt();
				int r = sc.nextInt();
				b[i] = new Matryoshka(h, r);
			}

			a = Matryoshka.cat(a, b);
			n = n + m;

			for (int i = 0; i < n; i++) {
				a[i].neighbor = new Matryoshka[n];
			}
			for (int i = 0; i < n; i++) {
				for (int j = 0; j < n; j++) {
					if (a[i].h < a[j].h && a[i].r < a[j].r) {
						a[j].neighbor[a[j].degree] = a[i];
						a[j].degree++;
					}
				}
			}

			boolean flag = true;
			while (flag) {
				flag = false;
				for (int i = 0; i < n; i++) {
					for (int j = 0; j < a[i].degree; j++) {
						if (a[i].neighbor[j].cost < a[i].cost + 1) {
							a[i].neighbor[j].cost = a[i].cost + 1;
							flag = true;
						}
					}
				}
			}
			for (int i = 0; i < n; i++) {
				if (max < a[i].cost) {
					max = a[i].cost;
				}
			}

			System.out.println(max);
		}
	}
}

Measured memory_bytes: 12000
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll INF = 1LL<<60;
#define all(x) (x).begin(),(x).end()
#define REP(i,n) for(int i=0;i<(n);++i)
#define FOR(i,k,n) for(int i=(k);i<(n);++i)

int main() {
    int H,W; cin >> H >> W;
    vector<string> maze(H);
    REP(i,H) cin >> maze[i];
    int K = H*W;
    ll G[K][K];
    REP(i,K){
        REP(j,K) G[i][j] = INF;
        G[i][i] = 0;
    }
    vector<int> di = {1,0,-1,0}, dj = {0,1,0,-1};
    REP(i,H)REP(j,W){
        if(maze[i][j]=='#') continue;
        REP(k,4) {
            int ni = i + di[k];
            int nj = j + dj[k];
            if(0<=ni && ni<H && 0<=nj && nj<W && maze[ni][nj]=='.') G[W*i+j][W*ni+nj] = 1;
        }
    }
    REP(k,K)REP(i,K)REP(j,K) G[i][j] = min(G[i][j],G[i][k]+G[k][j]);
    ll ans = 0;
    REP(i,K)REP(j,K) {
        if(maze[i/W][i%W]=='.'&& maze[j/W][j%W]=='.' && G[i][j]!=INF) ans = max(ans,G[i][j]);
    }
    cout << ans << endl;
  //REP(i,K){REP(j,K)cout<<G[i][j]<<" ";cout<<endl;}cout<<endl;
  return 0;
}

Measured memory_bytes: 1536
using System;

namespace AOJ0027
{
    class Program
    {
        static void Main(string[] args)
        {
            int[] DoM = { 31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 };

            while (true)
            {
                string input = Console.ReadLine();
                string[] num = input.Split(' ');
                int count = 0;
                string output = "";

                if (int.Parse(num[0]) == 0)
                {
                    break;
                }

                for (int i = 0; i < int.Parse(num[0]) - 1; i++)
                {
                    count += DoM[i];
                }

                count += int.Parse(num[1]);

                switch (count % 7)
                {
                    case 1:
                        output = "Thursday";
                        break;
                    case 2:
                        output = "Friday";
                        break;
                    case 3:
                        output = "Saturday";
                        break;
                    case 4:
                        output = "Sunday";
                        break;
                    case 5:
                        output = "Monday";
                        break;
                    case 6:
                        output = "Tuesday";
                        break;
                    case 0:
                        output = "Wednesday";
                        break;
                }

                Console.WriteLine(output);
            }
        }
    }
}

Measured memory_bytes: 8760
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <stack>
#include <queue>
#include <set>
#include <cmath>
#include <map>
#include <fstream>
#include <iterator>
// #include "prettyprint.hpp"

using namespace std;
using ll = long long;

vector<int> calc_prime_number(int upper_num)
{
    vector<int> is_prime(upper_num, 1); // 0 is not prime number.
    is_prime[0] = 0;
    is_prime[1] = 0;
    for (int i = 2; i < upper_num; ++i)
    {
        if (!is_prime[i])
        {
            continue;
        }
        for (int j = i * 2; j < upper_num; j += i)
        {
            is_prime[j] = 0;
        }
    }
    return is_prime;
}

int main()
{
    int MAX = 100100;
    auto is_prime = calc_prime_number(MAX);
    // cout << is_prime << endl;

    vector<int> a(MAX, 0);
    for (int i = 0; i < MAX; ++i)
    {
        if (i % 2 == 0)
        {
            continue;
        }
        if (is_prime[i] && is_prime[(i + 1) / 2])
        {
            a[i] = 1;
        }
    }

    vector<int> s(MAX + 1, 0);
    for (int i = 0; i < MAX; ++i)
    {
        s[i + 1] = s[i] + a[i];
    }
    int Q;
    cin >> Q;

    for (int q = 0; q < Q; ++q)
    {
        int l, r;
        cin >> l >> r;
        ++r;

        cout << s[r] - s[l] << endl;
    }
}


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

#define rep(i, n) for (int i = 0; i < (n); i++)
using namespace std;
typedef long long ll;
const int N = 2 * 1e5 + 3;

int main() {
  vector<char> cfront(N), cback(N);
  string s;
  int q, t, f, cnt = 0, fi = 0, bi = 0;
  char c;
  cin >> s >> q;
  rep(i, q) {
    cin >> t;
    if (t == 1)
      cnt++;
    else {
      cin >> f >> c;
      if (f == 1) {
        if (cnt % 2 == 0)
          cfront[fi] = c, fi++;  // s = c + s;
        else
          cback[bi] = c, bi++;  // s = s + c;
      } else {
        if (cnt % 2 == 0)
          cback[bi] = c, bi++;  // s = s + c;
        else
          cfront[fi] = c, fi++;  // s = c + s;
      }
    }
  }
  cfront.resize(fi + 1);
  cback.resize(bi + 1);
  if (cnt % 2 != 0) {
    for (int i = bi - 1; i >= 0; --i) cout << cback[i];
    reverse(s.begin(), s.end());
    cout << s;
    rep(i, fi) cout << cfront[i];
  } else {
    for (int i = fi - 1; i >= 0; --i) cout << cfront[i];
    cout << s;
    rep(i, bi) cout << cback[i];
  }

  return 0;
}


Measured memory_bytes: 1280
"""
author : halo2halo
date : 16, Jan, 2020
"""

import sys
import numpy as np

read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(10 ** 7)

a, b, c = map(int, readline().decode('utf8').split())
print(a * b // 2)


Measured memory_bytes: 12476
#include <iostream>
#include <map>
#include <vector>
#include <cmath>
#include <string>
#include <cstring>
#include <algorithm>
#include <climits>
#include <stack>
#include <queue>
#include <set>
#include <cctype>
#include <bitset>
#include <type_traits>

#include <list>
using namespace std;

#define REP(i, n) for (int i = 0; i < (n); ++i)
#define rep(i, a, b) for (int i = a; i < (b); ++i)
#define YES(j) cout << (j ? "YES" : "NO") << endl;
#define Yes(j) std::cout << (j ? "Yes" : "No") << endl;
#define yes(j) std::cout << (j ? "yes" : "no") << endl;

int main(void)
{
    int a, b;
    cin >> a >> b;
    rep(i, 1, 10000)
    {
        int ax = i * 0.08;
        int bx = i * 0.1;
        if (ax == a and bx == b)
        {
            cout << i << endl;
            return 0;
        }
    }
    cout << "-1" << endl;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main{
    public static void main(String[] args){
	Scanner sc= new Scanner(System.in);
	int n = sc.nextInt();
	int i=1;
	
	while(true){
		int x = i;
		if(x%3==0 || x%10==3 || (x/10)%10==3 || (x/100)%10==3|| (x/1000)%10==3){
			System.out.print(" "+x);
		}
		i++;
		if(i>n){
			break;
		}}	
	System.out.println();
}}

Measured memory_bytes: 28560
import * as fs from 'fs';

const input = fs.readFileSync('/dev/stdin', 'utf8');
// const input = fs.readFileSync('./input.txt', 'utf8');

_b(input);

function _b(input: string) {
  let min = 1000;

  const [S, T] = input.split('\n');

  for (let i = 0; i <= S.length - T.length; i++) {
    min = Math.min(min, distance(T, S.substr(i, T.length)));
  }

  console.log(min);
}

function distance(l: string, r: string) {
  if (l.length !== r.length) {
    throw new Error('not match ' + l.length + ' ' + r.length);
  }
  let n = 0;
  for (let i = 0; i < l.length; i++) {
    if (l[i] !== r[i]) {
      n++;
    }
  }
  return n;
}


Measured memory_bytes: 32244
#!/usr/bin/env python3

from typing import Iterable


def calc(a: int, b: int) -> int:
    return a ** 5 - b ** 5


def fifthroot(i: int) -> int:
    return int(pow(i, 1 / 5))


def search_b(x, a) -> (bool, int):
    b = int(pow(abs(a ** 5 - x), 1 / 5))
    if x == a ** 5 - b ** 5:
        return True, b
    elif x == a ** 5 + b ** 5:
        return True, -b
    else:
        return False, 0


def main() -> None:
    X = ri()
    predict = fifthroot(X)
    for a in range(predict - 100, predict + 100):
        success, b = search_b(X, a)
        if success:
            break
    wm((a, b))


def r() -> str:
    return input().strip()


def ri() -> int:
    return int(r())


def rmi(delim: str = ' ') -> int:
    return tuple(map(int, input().split(delim)))


def w(data) -> None:
    print(data)


def wm(data: Iterable) -> None:
    print(' '.join(list(map(str, data))))


if __name__ == '__main__':
    main()


Measured memory_bytes: 10544
import java.util.Scanner;

class Main{

public static void main(String args[]){

Scanner scan =new Scanner(System.in);

int a =scan.nextInt();

int b =scan.nextInt();

int c =scan.nextInt();

if(a<=b && a<c && b<c){System.out.println(a+" "+b+" "+c);}

else if(a<=b && a<c && c<b){System.out.println(a+" "+c+" "+b);}

else if(c<=a && c<b && a<b){System.out.println(c+" "+a+" "+b);}

else if(c<=a && c<b && b<a){System.out.println(c+" "+b+" "+a);}

else if(b<=a && b<c && a<c){System.out.println(b+" "+a+" "+c);}

else{System.out.println(b+" "+c+" "+a);}

}}


Measured memory_bytes: 26240
X, K, D = map(int, input().split())
dis = 0

if X < 0:
    X *= -1

quotient = X // D

if quotient >= K:
    dis = X - K * D
else:
    remainder = X % D
    if remainder < D - remainder:
        dis = remainder
        if (K - quotient) % 2 != 0:
            dis = D-remainder
    else:
        dis = D - remainder
        if (K - quotient) % 2 == 0:
            dis = remainder

print(dis)


Measured memory_bytes: 8968
def solve():
    from sys import stdin
    f_i = stdin
    
    N = int(f_i.readline())
    K = int(f_i.readline())
    S = str(N)
    
    
    import numpy as np
    # dp[digit][below flag][number of non-0]
    dp = np.zeros((len(S) + 1, 2, K + 1), dtype=int)
    dp[0][0][0] = 1
    digits = (int(c) for c in S)
    
    for i, d in enumerate(digits):
        for j in (0, 1):
            for k in range(K):
                if j:
                    dp[i+1][j][k+1] += dp[i][j][k] * 9
                    dp[i+1][j][k] += dp[i][j][k]
                else:
                    if d:
                        dp[i+1][1][k+1] += dp[i][j][k] * (d - 1)
                        dp[i+1][j][k+1] += dp[i][j][k]
                        dp[i+1][1][k] += dp[i][j][k]
                    else:
                        dp[i+1][j][k] += dp[i][j][k]
                    
    ans = np.sum(dp[:, :, K])
    
    print(ans)

solve()

Measured memory_bytes: 12508
import sys
n, q = map(int, sys.stdin.readline().split())
processes = []
for i in range(n):
    name, time =sys.stdin.readline().split()
    processes += [[name, int(time)]]

progress = 0

while len(processes):
    new_processes = []
    for target in processes:
        if target[1] > q:
            target[1] -= q
            progress += q
            new_processes += [target]
        else:
            progress += target[1]
            print(target[0], progress)
    processes = new_processes

Measured memory_bytes: 16728
package main

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

var sc = bufio.NewScanner(os.Stdin)

func getInt() int {
	sc.Scan()
	n, _ := strconv.Atoi(sc.Text())
	return n
}

func getFloat() float64 {
	sc.Scan()
	n, _ := strconv.ParseFloat(sc.Text(), 64)
	return n
}

func main() {
	sc.Split(bufio.ScanWords)
	n, _ := getInt(), getInt()

	a := make(map[int]int, n)

	for i := 0; i < n; i++ {
		k := getInt()
		for j := 0; j < k; j++ {
			t := getInt()
			a[t]++
		}
	}

	ans := 0
	for _, v := range a {
		if v == n {
			ans++
		}
	}
	fmt.Println(ans)

}


Measured memory_bytes: 640
/********************    I am only one, but still I am one.    **************************************/
/**************    I cannot do everything, but still I can do something.    *************************/
/***   And because I cannot do everything I will not refuse to do the something that I can do.    ***/
#include<bits/stdc++.h>
#define int long long
#define endl '\n'
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define bug1( x ) {cerr << (#x) <<"="<< x << endl;}
#define bug2( x , y ) {cerr << (#x) <<"="<< (x) << "    " << (#y) << "="<< (y) << endl;}
#define bug3( x , y , z ) {cerr << (#x) <<"="<<(x) << "    " << (#y) <<"="<< (y) << "    " << (#z) <<"="<< (z) << endl;}
#define bug4( x , y , z , w) {cerr << (#x) <<"="<<(x) << "    " << (#y) <<"="<< (y) << "    " << (#z) <<"="<< (z) << "    " << (#w) <<"="<< w << endl;}
#define bug5( x , y , z , w ,p) {cerr << (#x) <<"="<<(x) << "    " << (#y) <<"="<< (y) << "    " << (#z) <<"="<< (z) << "    " << (#w) <<"="<< w << "    " << (#p) <<"="<< p << endl;}
#define bug6( x , y , z , w ,p , q) {cerr << (#x) <<"="<<(x) << "    " << (#y) <<"="<< (y) << "    " << (#z) <<"="<< (z) << "    " << (#w) <<"="<< w << "    " << (#p) <<"="<< p << "    " << (#q) <<"="<< q << endl;}
#define bugn( x , n ) {cerr << (#x) <<":";for(int i=0;i<n;i++)cerr << x[i] <<"  "; cerr << endl;}
#define bugnm( x , n , m ) {cerr << (#x)<<endl;for(int i=0;i<n;i++){cerr << "Row #" << i<< ":";for(int j=0;j<m;j++)cerr << x[i][j] << "   ";cerr << endl;}}
typedef long long ll;
typedef long double ld;
using namespace std;

struct box{
	int v,d,c;
};
const int maxn = 1e5+5;
vector<int>g[maxn],lst(maxn),clr(maxn);
int vis[maxn][11];
vector<box>q(maxn);
int n,m,t;
void dfs(int u,int d,int c){
	if( vis[u][d] )return; // O( 10 * ( n+m) )
	vis[u][d]=1;
	if( !clr[u] ){
		clr[u] = c;
	}
	if(d == 0 )return;
	for(auto v:g[u]){
		dfs(v,d-1,c);
	}
}
int32_t main(){
	IOS
	cin>>n>>m;
	for(int i=1;i<=m;i++){
		int u,v;cin>>u>>v;
		g[u].push_back(v);
		g[v].push_back(u);
	}
	cin>>t;
	for(int i=1;i<=t;i++){
		cin>>q[i].v>>q[i].d>>q[i].c;
	}
	reverse(q.begin()+1,q.begin()+t+1);
	memset(vis,0,sizeof(vis));
	for(int i=1;i<=t;i++){
		dfs(q[i].v,q[i].d,q[i].c);
	}
	for(int i=1;i<=n;i++){
		cout << clr[i] << endl;
	}
	
	
}
/*
 * long long or int?
 * index out of bound? 
 * Tested on own test case?corner?
 * Make more general solution.
 * Read Read Read Read ....
 */


Measured memory_bytes: 21868
import java.util.Scanner;
import java.util.Random;

public class Main{
    public static void main(String[] args){
        Scanner sc =new Scanner(System.in);
        int a=sc.nextInt();
        int b=sc.nextInt();
        int e=b%2;
        int c=0;
        int flg=0;
        if(e==0 && a!=0 && b!=0){
            for(int i=0; i<=a; i++){
                c=4*(a-i)+2*i;
                if(b==c){
                    flg=1;
                }
            }
            if(flg==1){
                System.out.println("Yes");
            }else{
                System.out.println("No");
            }
        }else{
            System.out.println("No");
        }
    }
}

Measured memory_bytes: 35708
import java.util.*;
public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		// 整数の入力
		int a = sc.nextInt();
        int i,ans = 0;
      
        for(i = 0;i < a;i++){
          ans += sc.nextInt() - 1;
        }
      	
      	System.out.println(ans);
    }
}

Measured memory_bytes: 40680
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner in = new Scanner(System.in);
		int N = in.nextInt();
		int[] A = new int[N + 2];
		A[0] = 0;
		A[N + 1] = 0;
		for (int i = 1; i <= N; i++) {
			A[i] = in.nextInt();
		}
		int[] B = new int[N + 1];
		int sum = 0;
		for (int i = 0; i <= N; i++) {
			B[i] = Math.abs(A[i] - A[i + 1]);
			sum += B[i];
		}
		for (int i = 1; i <= N; i++) {
			int ans = sum;
			ans = ans + Math.abs(A[i - 1] - A[i + 1]) - (B[i] + B[i - 1]);
			System.out.println(ans);
		}
		in.close();
	}
}

Measured memory_bytes: 63776
def gcd(a, b):
    while b:
        a, b = b, a % b
    return a

def lcm(a, b):
    return a * b // gcd(a, b)

def div2(x):
    c = 0
    while x%2==0:
        x //= 2
        c+=1
    return c

def test():
    N, M = map(int, input().split())
    a = list(map(int, input().split()))
    for i in range(N):
        if a[i]%2 == 1:
            return 0
        a[i] //= 2

    t = div2(a[0])
    for i in range(N):
        if div2(a[i]) != t:
            return 0
        a[i] >>= t
    M >>= t

    L = a[0]
    for i in range(1, N):
        L = lcm(L, a[i])
        if L > M:
            return 0

    ans = (M-L)//(2*L)+1
    return ans

print(test())

Measured memory_bytes: 63984
/*------------------------------------
........Bismillahir Rahmanir Rahim....
..........created by Abdul Aziz.......
------------------------------------*/
#include <iostream>
#include <algorithm>
#include <stdio.h>
#include <cmath>
#include <vector>
#include <set>
#include <list>
#include <stack>
#include <map>
#include <cstring>
#include <unordered_map>
#include <queue>
#include <functional>
#define   mod  998244353
#define   int  long long 
#define   ld   long double
#define   pb   push_back
#define   vi   vector<int> 
#define   co(x)  cout << x << '\n' 
#define   dbg(x)  cerr << #x << " = " << x << '\n' 
#define   bitcount(x)  (int)__builtin_popcount(x) 
#define   sz(x)  (int)x.size()
#define   all(a) a.begin(),a.end() 
#define   ff   first
#define   ss   second
#define   pii  pair<int,int> 
#define   lcm(a,b) (a*b)/__gcd(a,b) 
using namespace std;

int  n, m, ans = 0 ; 
int  a[1001][3]; 

signed main()
{
    cin >> n >> m ; 
    for (int i=1;i<=n;i++) cin >> a[i][0] >> a[i][1] >> a[i][2] ; 
    for (int i=0;i<8;i++){
        int cur[n+1];
        for (int j=1;j<=n;j++){
            int sum = 0 ; 
            for (int bit=0;bit<3;bit++){
                if (i / (1<<bit) % 2 == 0)  sum += a[j][bit] ; 
                else  sum -= a[j][bit] ; 
            }
            cur[j] = sum ; 
        }
        sort(cur+1,cur+n+1,greater<int> ());
        int s = 0 ;
        for (int j=1;j<=m;j++){
            s += cur[j] ; 
        }
        ans = max(ans, s) ; 
    }
    co ( ans ) ; 
    return 0;
}
/* 
3 2 
1 -2 3 
3 -5 -1 
1 2 3 
 
*/ 


Measured memory_bytes: 3652
#include <iostream>
#include <cmath>

using namespace std;

int main() 
{
	long long int A;
	long double B;
  	cin >> A >> B;
  	
  	B = round(B * 100.00);
    long long int r = (A * B) / 100;
  	
  	cout << r << '\n';
}

Measured memory_bytes: 3760
n, m = [int(x) for x in input().split()]
h_list = [0] + [int(x) for x in input().split()]

temp_list = [1] * (n + 1)
temp_list[0] = 0
for _ in range(m):
    a, b = [int(x) for x in input().split()]
    if h_list[a] <= h_list[b]:
        temp_list[a] = 0
    if h_list[b] <= h_list[a]:
        temp_list[b] = 0
print(sum(temp_list))

Measured memory_bytes: 20116
/*input
3 4 10 40
*/

#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp> 

#define rep(i,j,n) for(i=j;i<n;i++)
#define repi(i,j,n) for(i=j;i>n;i--)
#define inf 100001
#define M 1000000007
#define pie 3.141592653589793238
#define ll long long
#define ld long double
#define vll vector<long long>
#define vi vector<int>
#define pll pair<long long,long long>
#define pii pair<int,int>
#define vpii vector<pair<int,int> >
#define vpll vector<pair<long long,long long> >
#define pb push_back
#define pf pop_front
#define F first
#define S second
#define endl '\n'

using namespace std;
using namespace __gnu_pbds; 

template<typename T>
using ordered_set=tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;


ll power(ll a,ll m,ll mod){
	ll ans=1;
	while(m){
		if(m%2){
			ans*=a;
			ans%=(mod);
		}
		a=(a*a)%(mod);
		m>>=1;
	}
	return ans;
}


void init(ll* a,ll n,ll val){
	for(ll i=0;i<n;i++)
		a[i]=val;
}



int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);	
	ll t=1,i,j;
	ld a,b,h,m;
	cin>>a>>b>>h>>m;
	h*=5;
	h+=(m/60.0)*5;
	ld k=min(abs(m-h),60-abs(m-h));
	k*=6;	
	//cout<<h<<endl;
	//cout<<(b-(double)a*(cos(pie/180.0*k)))<<endl;
	cout<<setprecision(10)<<sqrt(pow((b-(double)a*(cos(pie/180.0*k))),2)+pow((double)a*(sin(pie/180.0*k)),2))<<endl;
	return 0;
}




Measured memory_bytes: 4184
#include<stdio.h>
#include<stdlib.h>
#include<iostream>
#include<string>
#include<algorithm>
#include<vector> 
#include<limits>
#include<numeric>
#include<type_traits>
#include<math.h>
#include<fstream>
#include<set>
using namespace std;
typedef long long ll;

#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define repi(i,a,b) for(int i = (int)(a); i < (int)(b); i++)
#define out(str) cout << str << endl
#define ALL(a) (a).begin(),(a).end()
#define INF (1<<29)

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; }

int N,ans;

int main(){
    cin>>N;
    int p[N];
    rep(i,N)cin>>p[i];
    rep(i,N-2){
        if(p[i+1]!=min(p[i],min(p[i+1],p[i+2]))&&p[i+1]!=max(p[i],max(p[i+1],p[i+2])))ans++;
    }
    out(ans);

    
    
}


Measured memory_bytes: 256
import java.util.*;

public class Main {
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        String s1 = sc.next();
        String s2 = sc.next();

        String VH = "";
        for (int i=0; i<n; i++) {
            if (s1.charAt(i) == s2.charAt(i)) {
                VH += "V";
            } else {
                VH += "H"; i++;
            }
        }
        //System.out.println(VH);

        long total = 3;
        if (VH.charAt(0) == 'H') {
            total *= 2;
        }
        int m;
        for (int i=1; i<VH.length(); i++) {
            if (VH.charAt(i) == 'H') {
                if (VH.charAt(i-1) == 'H') {
                    m = 3;
                } else {
                    m = 2;
                }
            } else {
                if (VH.charAt(i-1) == 'H') {
                    m = 1;
                } else {
                    m = 2;
                }
            }
            //System.out.println(total + " x " + m);
            total *= m;
        }
        System.out.println(total % 1000000007);
    }
}


Measured memory_bytes: 23764
#include <bits/stdc++.h>
using namespace std;
#define all(x) (x).begin(),(x).end()
#define YES() printf("YES\n")
#define NO() printf("NO\n")
#define isYES(x) printf("%s\n",(x) ? "YES" : "NO")
#define Yes() printf("Yes\n")
#define No() printf("No\n")
#define isYes(x) printf("%s\n",(x) ? "Yes" : "No")
#define isIn(x,y,h,w) (x >= 0 && x < h && y >= 0 && y < w)

#define int long long
//using ll = long long;
using P = pair<int,int>;

ostream &operator<<(ostream &os,const P &p){ return os << "(" << p.first << "," << p.second << ")"; }

template<class T> T &chmin(T &a,const T &b){ return a = min(a,b); }
template<class T> T &chmax(T &a,const T &b){ return a = max(a,b); }
 
const int INF=1e+18;
const double EPS=1e-9;
const int MOD=1000000007;

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

signed main(){
	int n,k,r[3],ans = 0,win[100010];
	string t;
	cin >> n >> k >> r[0] >> r[1] >> r[2] >> t;
	for(int i = 0;i < n;i++){
		if(t[i] == 'r') win[i] = 2;
		else if(t[i] == 's') win[i] = 0;
		else win[i] = 1;
	}
	int dp[100010][3] = {};
	for(int i = 0;i < n;i++){
		for(int j = 0;j < 3;j++){
			for(int l = 0;l < 3;l++){
				if(j != l){
					chmax(dp[i][l],(i >= k ? dp[i - k][j] : 0) + r[l] * (win[i] == l));
				}
			}
		}
	}
	for(int i = 0;i < k;i++){
		int ma = 0;
		for(int j = 0;j < 3;j++) chmax(ma,dp[n - i - 1][j]);
		ans += ma;
	}
	cout << ans << endl;
}

Measured memory_bytes: 3584
import math

N,A,B=list(map(int,input().split()))
arr=[]
h_sum=0
for i in range(N):
    h=int(input())
    arr.append(h)
    h_sum+=h

max_=max(arr)//B+1
min_=h_sum//(A+B*(N-1))

d=A-B

while min_!=max_:
    mid=(max_+min_)//2
    
    sum_=0
    for x in arr:
        y=(x-mid*B)
        if y<=0:
            continue
        sum_+=math.ceil(y/d)
        
    if sum_<=mid:
        max_=mid
    else:
        min_=mid+1

print(min_)

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

int main(){
 int n;
 cin >> n;
 int l[n];
 for(int j=0;j<n;++j){
  cin >> l[j];
 }
 for(int i=n-1;i>=1;--i){
  cout << l[i] << " ";
 }
 cout << l[0] << endl;
 return 0;
}

Measured memory_bytes: 3076