akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include<algorithm>
#include<cmath>
#include<vector>
#include<map>
using namespace std;
typedef pair<double, double> P;
#define EPS 1e-10

struct Line{
	int a, b, c;
	Line(int x1, int y1, int x2, int y2){//ax+by+c=0
		a = y2 - y1;
		b = x1 - x2;
		c = y1*x2 - x1*y2;
	}
};

P cross(Line l1, Line l2){
	double a = l1.a, b = l1.b, c = l1.c;
	double d = l2.a, e = l2.b, f = l2.c;
	double y = (a*f - c*d) / (b*d - a*e);
	double x = (b*f - c*e) / (a*e - b*d);
	return P(x, y);	
}

typedef Line L;

double dist(P p1, P p2){
	return hypot(p1.first - p2.first, p1.second - p2.second);	
}

int main(){
	int n;
	double x1, x2, y1, y2;
	while(cin >> n, n){
		int res = 1;
		vector<Line> lines;
		lines.push_back(L(-100, -100, -100, 100));
		lines.push_back(L(-100, -100, 100, -100));
		lines.push_back(L(100, 100, -100, 100));
		lines.push_back(L(100, 100, 100, -100));
		for(int i = 0;i < n;i++){
			cin >> x1 >> y1 >> x2 >> y2;
			lines.push_back(L(x1, y1, x2, y2));
			vector<P> cp;
			for(int j = 0;j < lines.size() - 1;j++){
				P tmp = cross(lines[j], lines.back());
				if(-100-EPS <= tmp.first && tmp.first <= 100+EPS && -100-EPS <= tmp.second && tmp.second <= 100+EPS){
					cp.push_back(tmp);
					for(int k = 0;k < cp.size() - 1;k++){
						if(dist(cp[k], cp.back()) <= EPS){
							cp.pop_back();
							break;
						}
					}
				}
			}
			res += cp.size() - 1;
		}
		cout << res << endl;
	}
	return 0;
}

Measured memory_bytes: 1252
// AOJ DPL_3_B Largest Rectangle
// 2018.5.12 bal4u
 
#include <stdio.h>

#if 1
#define gc() getchar_unlocked()
#else
#define gc() getchar()
#endif
 
int in()
{
    int n = 0, c = gc();
    do n = 10*n + (c & 0xf), c = gc(); while (c >= '0');
    return n;
}

typedef struct { int lp, h; } STACK;
STACK stack[1500]; int top;

int maxRectInHistogram(int n, int *h)
{
	int i, s, ans;

	h[n] = 0;
	
	ans = 0;
	stack[0].lp = -1, stack[0].h = -1, top = 0;
	for (i = 0; i <= n; i++) {
		if (h[i] == stack[top].h) continue;
		if (h[i] > stack[top].h) {
			stack[++top].lp = i, stack[top].h = h[i];
		} else {
			while (h[i] < stack[top].h) {
				s = stack[top].h*(i-stack[top].lp);
				top--;
				if (s > ans) ans = s;
			}
			stack[++top].h = h[i];
		}
	}
	return ans;
}

int h[1402][1402];
char map[1402][1402];

int main()
{
	int H, W, r, c, t, ans;

	H = in(), W = in();
	for (r = 0; r < H; r++) for (c = 0; c < W; c++) {
		map[r][c] = gc() & 1; gc();
	}
	
	for (c = 0; c < W; c++) {
		t = 0;
		for (r = 0; r < H; r++) {
			if (map[r][c]) t = 0;
			else h[r][c] = ++t;
		}
	}
	
	ans = 0;
	for (r = H-1; r >= 0; r--) {
		t = maxRectInHistogram(W, h[r]);
		if (t > ans) ans = t;
		if (ans >= W*r) break;
	}
	printf("%d\n", ans);
	return 0;
}



Measured memory_bytes: 9996
#include <bits/stdc++.h>
using namespace std;
string s;
int main(){
	ios::sync_with_stdio(0), cin.tie(0);
	cin>>s;
	if(s[0] == 'S')cout<<"Cloudy\n";
	else if(s[0] == 'C') cout<<"Rainy\n";
	if(s[0] == 'R')cout<<"Sunny\n";
}


Measured memory_bytes: 256
S=input()
if S[0]==S[1] and S[2]==S[3] and S[0]!=S[2]:
  print('Yes')
elif S[0]==S[2] and S[1]==S[3] and S[0]!=S[1]:
  print('Yes')
elif S[0]==S[3] and S[1]==S[2]and S[0]!=S[1]:
  print('Yes')
else:
  print('No')

Measured memory_bytes: 3064
#include<bits/stdc++.h>
#define ll long long int
#define M 1000000007
#define mod 998244353
#define mp(x,y) make_pair(x,y)
#define pb(x) push_back(x)
#define pi pair<ll,ll>
#define endl "\n"
using namespace std;
const ll N=500010;

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);

    ll a,b,c,k;
    cin>>a>>b>>c>>k;
    ll ans=min(a,k);
    k-=min(a,k);
    k-=min(b,k);
    ans-=min(c,k);
    cout<<ans;

    return (0);
}


Measured memory_bytes: 3612
import sys
from collections import defaultdict, deque
import bisect
from heapq import *
from math import factorial, ceil, floor
from collections import defaultdict
import itertools
sys.setrecursionlimit(200000)
input = sys.stdin.readline

# N, M, = map(int, input().split())
# N = int(input())
# L = [int(v) for v in input().split()]
# L = [[int(v) for v in input().split()] for _ in range(N)]
# L = [int(input()) for _ in range(N)]
# L = [list(input().strip())  for _ in range(N)]
# S = input().strip()

X, = map(int, input().split())

for i in range(-1000, 1000):
    for j in range(-1000, 1000):
        if i ** 5 - j ** 5 == X:
            print(i, j)
            exit(0)


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

int main() {
  int N;
  cin >> N;
  for (int X = 1; X <= 50000; X++) {
    if (X * 108 / 100 == N) {
      cout << X << endl;
      break;
    }
    else if (X == 50000) {
      cout << ":(" << endl;
      break;
    }
  }
}


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

int main() {
  int a,b;
  cin>>a>>b;
  
  if(a>b){
    int t;
    t=a;
    a=b;
    b=t;
  }
  
  if(a==b){
    cout<<2*a<<endl;
  }
  else{
    cout<<2*b-1<<endl;
  }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n) FOR(i,0,n)
#define repr(i,n) for(int i=(n)-1;0<=i;--i)
#define each(e,v) for(auto&& e:(v))
#define all(v) begin(v),end(v)
#define dump(x) cerr<<#x<<": "<<(x)<<endl
using namespace std;
using vint = vector<int>;
using ll = long long;
using vll = vector<ll>;
template <class T> void chmin(T& a, const T& b) { a = min(a, b); }
template <class T> void chmax(T& a, const T& b) { a = max(a, b); }
void yes() { cout << "Yes" << endl; exit(0); }
void no() { cout << "No" << endl; exit(0); }

int main() {
    int d, g; cin >> d >> g;
    vint p(d), c(d);
    rep(i, d) {
        cin >> p[i] >> c[i];
    }

    int ans = 1 << 29;

    rep(bit, 1 << (d + 1)) {
        int score = 0, cnt = 0;
        rep(i, d) {
            int mask = 1 << i;
            if((bit & mask) != 0) {
                score += p[i] * (100 * (i+1)) + c[i];
                cnt += p[i];
            }
        }
        if(score < g) {
            repr(i, d) {
                if((bit & (1 << i)) != 0) continue;
                int n = min(p[i], (g - score) / (100 * (i+1)));
                cnt += n;
                score += n * (100 * (i+1));
                if(n == p[i]) score += c[i];
                if(g <= score) break;
            }
        }
        chmin(ans, cnt);
    }
    cout << ans << endl;
}


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

typedef long long ll;


int d[200];
bool table[200][200];

void init(){
    for(int i=0;i<200;i++){
        d[i]=-1;
        for(int j=0;j<200;j++){
            table[i][j]=false;
        }
    }
}

void bfs(int itr, int dis, int n){
    d[itr] = dis;
    for(int i=0;i<n;i++){
        if(table[itr][i]&&(d[i]<0||d[i]>dis+1)){
            bfs(i, dis+1,n);
        }
    }
}

void solve(int n){
    bfs(0,0,n);
}

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

    init();
    int n;
    cin >> n;
    int u,k,v;
    for(int i=0;i<n;i++){
        cin >> u >> k;
        for(int j=0;j<k;j++){
            cin >> v;
            table[u-1][v-1]=true;
        }
    }

    solve(n);

    for(int i=0;i<n;i++){
        cout << i+1 << " " << d[i] << endl;
    }

    return 0;
}



Measured memory_bytes: 3208
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <string>

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

using ll = long long;
const int INF = 1145141919;

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

    int N, K;
    std::cin >> N >> K;
    int h[N];
    for(int i=0; i<N; ++i){
        std::cin >> h[i];
    }

    int dp[N];
    for(int i=0; i<N; ++i) dp[i]=INF;
    dp[0] = 0;
    for(int i=1; i<N; ++i){
        for(int j=1; j<=K; ++j){
            if(i-j>=0) chmin(dp[i], dp[i-j]+abs(h[i]-h[i-j]));
        }
    }

    std::cout << dp[N-1];

    return 0;
}


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

static const int MAX=100;
static const int WHITE=0;
static const int GRAY=1;
static const int BLACK=2;

int n,M[MAX][MAX];

int prime(){
  int u,mincost;
  int d[MAX],p[MAX],color[MAX];

  for(int i=0;i<n;i++){
    d[i]=INT_MAX;
    p[i]=-1;
    color[i]=WHITE;
  }

  d[0]=0;

  while(1){
    mincost=INT_MAX;
    u=-1;
    for(int i=0;i<n;i++){
      if(color[i]!=BLACK&&d[i]<mincost){
	mincost=d[i];
	u=i;
      }
    }
 
    if(mincost==INT_MAX) break;
    
    color[u]=BLACK;

    for(int i=0;i<n;i++){
      if(color[i]!=BLACK&&M[u][i]!=INT_MAX){
	if(M[u][i]<d[i]){
	  d[i]=M[u][i];
	  p[i]=u;
	  color[i]=GRAY;
	}
      }
    }
  }

  int sum=0;
  for(int i=0;i<n;i++) sum+=d[i];

  return sum;
}

int main(){
  cin>>n;

  for(int i=0;i<n;i++){
    for(int j=0;j<n;j++){
      int e;
      cin>>e;
      if(e==-1) M[i][j]=INT_MAX;
      else M[i][j]=e;
    }
  }
  cout<<prime()<<endl; 
  return 0;
}

Measured memory_bytes: 1200
#include <stdio.h>
#define N 200000

int Max(int i,int j){return i>j?i:j;}
int Min(int i,int j){return i<j?i:j;}

int main()
{
	int i,n,a[N];
	scanf("%d",&n);
	for(i=0;i<n;i++)
	scanf("%d",&a[i]);
	int maxv=-2000000000;
	int minv=a[0];
	for(i=1;i<n;i++)
	{
		maxv=Max(maxv,a[i]-minv);
		minv=Min(minv,a[i]);
	}
	printf("%d\n",maxv);
}


Measured memory_bytes: 2576
#include <cstdio>
#include <iostream>
#include <cmath>
#include <cstring> 
#include <sstream>
#include <algorithm>
#include <cstdlib>
#include <map>
#include <queue>
#include <utility>
#include <vector>
#include <set>
#include <memory.h>
#include <iomanip>
#include <bitset>
#include <list>
#include <stack>
 
using namespace std;

#define mod 1000000007

int main()
{
    string s;
    cin >> s;
    int ans = 0;
    int canpnum = 0;
    int occurgnum = 0;
    for(int i = 0; i < s.length(); i++){
        if(s[i] == 'g'){
            canpnum++;
        } else {
            if(canpnum > 0){
                canpnum--;
            } else {
                ans--;
            }
        }
    }
    ans += canpnum / 2;
    cout << ans << endl;
    return 0;
}

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

int main()
{
	int x[10000] = { 0 }, i = 1;

	cin >> x[i];

	while (x[i]){
		i++;
		cin >> x[i];
	} 

	for (int j = 1; j < i; j++)
		cout << "Case " << j << ": " << x[j] << endl;

    return 0;
}

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

const ll mod = 1000000007;
int main() {
  ll m, n;
  cin >> m >> n;
  ll ans = 1;
  while (n > 0) {
    if (n & 1) ans = ans * m % mod;
    m = m * m % mod;
    n >>= 1;
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 3104
#include<iostream>
using namespace std;
int main()
{
    int arr[32] = {1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51};
    int n;
    cin >> n;
    cout << arr[n - 1];
}


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

public class Main {

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

  public void run() {

    try(BufferedReader br = new BufferedReader(new InputStreamReader(System.in))) {

      int q = Integer.parseInt(br.readLine());
      StringBuilder buf  = new StringBuilder();

      for(int i=0; i<q; i++) {
        buf.append( deriveLcs(br.readLine(), br.readLine()) )
           .append("\n");
      }

      System.out.print(buf);
    }
    catch (IOException e) {
      System.out.println("IOException!");
    }
  }

  private int deriveLcs(String seqX, String seqY) {
    int m = seqX.length();
    int n = seqY.length();
    int size = m > n ? m+1 : n+1;
    int[][] subSeq = new int[size][size];
    int maxSubSeq = 0;

    for(int i=1; i<=m; i++) subSeq[i][0] = 0;
    for(int j=1; j<=n; j++) subSeq[0][j] = 0;

    for(int i=1; i<=m; i++) {
      for(int j=1; j<=n; j++) {
        if(seqX.charAt(i-1) == seqY.charAt(j-1))
          subSeq[i][j] = subSeq[i-1][j-1] + 1;
        else
          subSeq[i][j] = Math.max(subSeq[i-1][j], subSeq[i][j-1]);

        maxSubSeq = Math.max(maxSubSeq, subSeq[i][j]);
      }
    }

    return maxSubSeq;
  }
}


Measured memory_bytes: 64544
use proconio::*;
use proconio::marker::*;

fn run() {
    input! {
        h: usize,
        w: usize,
        src: (Usize1, Usize1),
        dst: (Usize1, Usize1),
        mut s: [Chars; h],
    }
    for s in s.iter_mut() {
        for _ in 0..2 {
            s.insert(0, '#');
            s.push('#');
        }
    }
    for _ in 0..2 {
        s.insert(0, vec!['#'; w + 4]);
        s.push(vec!['#'; w + 4]);
    }
    let h = h + 4;
    let w = w + 4;
    let src = (src.0 + 2, src.1 + 2);
    let dst = (dst.0 + 2, dst.1 + 2);
    let mut used = vec![vec![false; w]; h];
    used[src.0][src.1] = true;
    let mut que = std::collections::VecDeque::new();
    que.push_back(src);
    for i in 0.. {
        if que.is_empty() {
            println!("-1");
            return;
        }
        let mut a = vec![];
        while let Some((x, y)) = que.pop_front() {
            a.push((x, y));
            for d in [!0, 0, 1, 0, !0].windows(2) {
                let x = x + d[0];
                let y = y + d[1];
                if !used[x][y] && s[x][y] != '#' {
                    used[x][y] = true;
                    que.push_back((x, y));
                }
            }
        }
        if used[dst.0][dst.1] {
            println!("{}", i);
            return;
        }
        for (x, y) in a {
            for p in [!1, !0, 0, 1, 2].iter() {
                for q in [!1, !0, 0, 1, 2].iter() {
                    let x = x + *p;
                    let y = y + *q;
                    if !used[x][y] && s[x][y] != '#' {
                        used[x][y] = true;
                        que.push_back((x, y));
                    }
                }
            }
        }
    }
}

fn main() {
    run();
}


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

import sys
import math


debug = False

def log(text):
    if debug:
        print(text)

def parse_input(lines_as_string = None):

    global debug
    lines = []
    if lines_as_string is None:
        debug = False
        # for line in sys.stdin:
        #     lines.append(line)
        lines.append(input())
    else:
        debug = True
        lines = [e for e in lines_as_string.split("\n")][1:-1]

    
    (h1, m1, h2, m2, k) = [int(e) for e in lines[0].split(' ')]

    return (h1, m1, h2, m2, k)

def solve(h1, m1, h2, m2, k):
 
    mins = (h2 * 60 + m2) - (h1 * 60 + m1)

    result = max(mins - k, 0)


    return result

def main():
    # 出力
    result = solve(*parse_input())
    if isinstance(result, list):
        for r in result:
            print("%s" % r, sep='')
    else:
        print("%s" % result, sep='')

if __name__ == '__main__':

    main()
	

Measured memory_bytes: 62080
n = int(input())

cnt = [[0] * 10 for _ in range(10)]
for i in range(1, n+1):
    cnt[int(str(i)[0])][int(str(i)[-1])] += 1

res = 0
for i in range(1, 10):
    for j in range(1, 10):
        res += cnt[i][j] * cnt[j][i]

print(res)

Measured memory_bytes: 41580
my ($A, $B) = split(/ /,<STDIN>);
chomp($B);

my $num = 0;
foreach my $t (${A}..${B}){
        my $N = int(length($t)/2);
        my $i = 0;
        my $j = -1;
        my $flg = 1;
        foreach (0..$N-1) {
                if ($flg) {
                        if (substr($t, $i, 1) ne substr($t, $j, 1)) {
                                $flg = 0;
                        }
                        $i++;
                        $j--;
                }
        }
        $num++ if ($flg);
}
print $num;

Measured memory_bytes: 512
#include <algorithm>
#include <cassert>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
using namespace std;
typedef long long ll;

#define rep(i, n) for(ll i = 0; i < n; i++)
#define REP(i, n) for(ll i = 1; i < n + 1; i++)
#define PI 3.14159265359
#define EPS 0.0000000001
#define MOD 1000000007
//cout << std::fixed << std::setprecision(15) << y << endl;


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

    ll a[N];
    ll sum = 0;
    rep(i, N){
        cin >> a[i];
        sum += a[i];
    }
    sort(a, a + N, greater<ll>());

    ll AP = 0;
    rep(i, N){
        if(i % 2 == 0){
            AP += a[i];
        }
    }

    cout << AP - (sum - AP) << endl;
    
    return 0;
}

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

using ll = long long int;

const int MAX = (int)(1e5 + 5);
const ll INF = (ll)(1e10 + 5);

const int MAX_N = (int)(1e5 + 5);

int n;
ll c;

ll x[MAX_N], v[MAX_N];
ll acc_v[MAX_N];
ll fwd[MAX_N], bwd[MAX_N];

ll ans;

void prepare() {
  for (int i = 1; i <= n; ++i) {
    acc_v[i] = v[i] + acc_v[i - 1];
  }

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

  // clock forward
  fwd[0] = 0LL;

  for (int i = 1; i <= n; ++i) {
    ll cur = acc_v[i] - x[i];

    int last_ind = i - 1;

    fwd[i] = max(fwd[last_ind], cur);
  }

  // clock backward
  bwd[0] = 0LL;

  for (int i = n; i >= 1; --i) {
    ll cur = (acc_v[n] - acc_v[i - 1]) - (c - x[i]);

    int last_ind = (i == n) ? 0 : i + 1;

    bwd[i] = max(bwd[last_ind], cur);
  }
}

int main(void) {
  // Here your code !
  scanf("%d %lld", &n, &c);

  for (int i = 1; i <= n; ++i) {
    scanf("%lld %lld", &(x[i]), &(v[i]));
  }

  prepare();

  ans = -1LL;

  ans = max(ans, fwd[n]);  // only forward
  ans = max(ans, bwd[1]);  // only backward

  // forward then backward
  for (int i = 1; i <= n; ++i) {
    ll fst_cost = x[i] * 2;
    ll fst_gain = acc_v[i];

    int opposite_ind = (i == n) ? 0 : i + 1;

    ll cur = fst_gain - fst_cost + bwd[opposite_ind];

    ans = max(ans, cur);
  }

  // backward then forward
  for (int i = n; i >= 1; --i) {
    ll fst_cost = (c - x[i]) * 2;
    ll fst_gain = (acc_v[n] - acc_v[i - 1]);

    int opposite_ind = i - 1;

    ll cur = fst_gain - fst_cost + fwd[opposite_ind];

    ans = max(ans, cur);
  }

  printf("%lld\n", ans);

  return 0;
}


Measured memory_bytes: 4224
#include <bits/stdc++.h>
#define endl '\n'
using namespace std;
int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
	set<string> s;
	string a;
	int n;
	cin >> n;
	while(n--){
		cin >>  a;
		s.insert(a);
	}
	cout << s.size();
    return 0;
}

Measured memory_bytes: 19244
#include <bits/stdc++.h>
#define endl "\n"
using namespace std;
#define ll long long
#define ld long double
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define repo(i,n) for(int i = 1; i < (int)(n); i++)
#define pb push_back
#define mp make_pair
#define np next_permutation
#define fi first
#define se second
#define all(x) (x).begin(),(x).end()
#define uniq(v) v.erase(unique(v.begin(),v.end()),v.end())
#define lb(v,x) (lower_bound(v.begin(),v.end(),x)-v.begin())
#define ub(v,x) (upper_bound(v.begin(),v.end(),x)-v.begin())
using Pair = pair<ll,pair<int,int>>;
#define pq priority_queue<Pair, vector<Pair>, greater<Pair>> 
const ll mod=1000000007;
//const ll mod=998244353;
const ld pi=acos(-1.0);
const ll INF = 1LL<<61;
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 gcd(ll x, ll y) { return y ? gcd(y, x % y) : x; }
ll lcm(ll x, ll y) { return x / gcd(x, y) * y; }
//intの最大値2147483647 ≒ 2×10^9
//long longの最大値9223372036854775807 ≒ 9×10^18
//'大文字'+=32;    で小文字に
//  cout << fixed << setprecision (20);   小数点以下2０桁まで
//実行時間制約2秒では２×10^8回くらいまで計算できる



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

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

  vector<pair<pair<int,int>,ll>> p(m);
  rep(i,m){
    ll a,b,c;
    cin>>a>>b>>c;
    a--;b--;
    p[i]={{a,b},-c};
  }

  vector<ll> d(n,INF);
  d[0]=0;
  rep(i,n-1){
    rep(j,m){
      if(d[p[j].fi.fi]==INF) continue;
      chmin(d[p[j].fi.se],d[p[j].fi.fi]+p[j].se);
    }
  }

  ll ans=d[n-1];

  vector<bool> neg(n,false);
  rep(i,n){
    rep(j,m){
      int a=p[j].fi.fi;
      int b=p[j].fi.se;
      ll c=p[j].se;
      if(d[a]==INF) continue;
      if(chmin(d[b],d[a]+c)){
        neg[b]=true;
      }
      if(neg[a]) neg[b]=true;
    }
  }


  if(neg[n-1]) cout << "inf" << endl;
  else cout << -ans << endl;
  return 0;

}

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

int main(void) {
  int i, N, OK = 0, max = 0;
  char S[300001] = {0};
  scanf("%d%s", &N, S);
  for (i=1; i < N ;i++) {
    if (S[i] == 'W') OK++;
  }
  if (OK+1 > max) max = OK+1;
  if (S[0] == 'E') OK++;

  for (i=1; i < N-1 ;i++) {
    if (S[i] == 'E') OK++;
    else OK--;
    if (S[i+1] == 'E') OK++;
    if (OK > max) max = OK;
    if (S[i+1] == 'E') OK--;
  }
  printf("%d\n", N - max);
  return 0;
}


Measured memory_bytes: 512
#include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <complex>
#include <cstring>
#include <cstdlib>
#include <string>
#include <cmath>
#include <queue>
using namespace std;

#define REP(i,n) for(int i=0;i<(int)n;++i)
#define FOR(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)
#define ALL(c) (c).begin(), (c).end()
#define INF 1<<30

int main() {
  int n;
  while(cin>>n,n) {
    string f[n];
    int w[n],s[n];
    int x[n];
    REP(i,n) {
      cin >> f[i] >> w[i] >> s[i];
      x[i] = i;
    }
    int ans[n];
    double ansg = INF;
    do {
      int sum = 0;
      int ct;
      for (ct=n-2; ct>=0; --ct) {
        sum += w[x[ct+1]];
        if (s[x[ct]] < sum)
          break;
      }
      if (ct >= 0) continue;
      
      // REP(i,4) {
      //   cout << x[i] << " ";
      // }
      // cout << endl;
      double g = 0, hoge = 0;
      REP(i,n) {
        g += w[x[i]] * (i+1);
        hoge += w[x[i]];
      }
      g /= hoge;
      // cout << g << endl;
      if (ansg > g) {
        ansg = g;
        memcpy(ans,x,sizeof(x));
      }
    } while(next_permutation(x, x+n));
    REP(i,n)
      //     cout << ans[i] << " ";
     cout << f[ans[i]] << endl;
  }
}

Measured memory_bytes: 912
#include <bits/stdc++.h>
#define rep(i , n) for (int i = 0; i < (int)(n); i++)
#define INF 1e9;
using namespace std;
using ll = long long;
int main() {
    int a , b;
    cin >> a >> b;
    if(a + b == 15){
        cout << '+' << endl;
    }
    if(a * b == 15){
        cout << '*' << endl;
    }
    if(!(a + b == 15 || a * b == 15)){
        cout << 'x' << endl;
    }
}

Measured memory_bytes: 3592
#include<iostream>
#include<vector>
#include<cstdio>
#include<string>
#include<cmath>
#include<math.h>
#include<algorithm>
#include<string.h>
#include <iomanip>
#include <sstream>
using namespace std;

int main() {
  int ans = 0;
  vector<int> A(3);
  for(int i = 0; i < 3; i++){
    cin >> A[i];
  }
   sort(A.begin(), A.end());

  ans = abs(A[2] - A[1]);
  ans += abs(A[1] - A[0]);

  cout << ans << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <array>
#include <deque>
#include <stack>
#include <queue>
#include <list>
#include <map>
#include <set>
#include <unordered_map>
#include <unordered_set>
#include <algorithm>
#include <numeric>
#include <utility>
#include <cmath>
#include <iomanip>
#include <cassert>
#include <complex>
#include <bitset>
#include <functional>

using namespace std;
using ll=long long int;

int main() {
    int n;
    cin >> n;
    vector<int> a(n);
    for (auto &e: a) cin >> e;
    map<ll, ll> m;

    ll ans = 0;
    ll cur = 0;
    m[0] = 1;
    for (int i = 0; i < n; ++i) {
        cur += a[i];
        ans += m[cur];
        m[cur]++;
    }

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 13568
#include <bits/stdc++.h>
#include <vector>
#include <numeric>
#define PI 3.14159265358979323846
#define MAXINF (1e18L)
#define INF (1e9L)
#define EPS (1e-9)
#define MOD ((ll)(1e9+7))
#define REP(i, n) for(int i=0;i<int(n);++i)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define RREP(i, n) for(int i=int(n)-1;i>=0;--i)
#define ALL(v) v.begin(),v.end()
#define FIND(v,x) (binary_search(ALL(v),(x)))
#define SORT(v) sort(ALL(v))
#define RSORT(v) sort(ALL(v));reverse(ALL(v))
#define DEBUG(x) cerr<<#x<<": "<<x<<endl;
#define DEBUG_VEC(v) cerr<<#v<<":";for(int i=0;i<v.size();i++) cerr<<" "<<v[i]; cerr<<endl
#define Yes(n) cout<<((n)?"Yes":"No")<<endl
#define YES(n) cout<<((n)?"YES":"NO")<<endl
#define pb push_back
#define fi first
#define se second
using namespace std;
template<class A>void pr(A a){cout << (a) << endl;}
template<class A,class B>void pr(A a,B b){cout << a << " "  ;pr(b);}
template<class A,class B,class C>void pr(A a,B b,C c){cout << a << " " ;pr(b,c);}
template<class A,class B,class C,class D>void pr(A a,B b,C c,D d){cout << a << " " ;pr(b,c,d);}
template<class T> inline bool chmin(T& a, T b){return a>b ? a=b, true : false;}
template<class T> inline bool chmax(T& a, T b){return a<b ? a=b, true : false;}
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll,ll> pll;

int main(void)
{
    int N,W;
    cin >> N >> W;
    vector<int> w(N), v(N);
    REP(i, N) cin >> w[i] >> v[i];

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

    Rep(j, 1, N+1){
        Rep(i, 1, W+1){
            chmax(dp[i][j], dp[i][j-1]);
            if(i-w[j-1]>=0){
                chmax(dp[i][j], dp[i-w[j-1]][j-1]+v[j-1]);
            }
        }
    }

    pr(dp[W][N]);
}

Measured memory_bytes: 82304
# encoding:utf-8
import copy
import random
import bisect #bisect_left　これで二部探索の大小検索が行える
import fractions #最小公倍数などはこっち
import math
import sys
import collections
 
mod = 10**9+7
sys.setrecursionlimit(mod) # 再帰回数上限はでdefault1000
 
d = collections.deque()
def LI(): return list(map(int, sys.stdin.readline().split()))
 

"""
3
1 1 2
のパターンが例外だった
"""

N = int(input())
A = LI()
A.sort()

table = [0 for i in range(10 ** 6 + 1)]
cnt = 0

cc = collections.Counter(A)
duplicate = []
for key in cc.keys():
    if cc[key] > 1:
        duplicate.append(key)

for a in A:
    if table[a] != 0:
        pass
    else:
        if a not in duplicate:
            cnt += 1
        for i in range(1, 10 ** 6 + 1):
            if a * i > 10 ** 6:
                break
            table[a * i] = 1

print(cnt)


Measured memory_bytes: 174652
// https://atcoder.jp/contests/abc176/tasks/abc176_e
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define REP(i, n) FOR(i, 0, n)
#define FOR(i, s, n) for (int i = (s), i##_len = (n); i < i##_len; ++i)
#define ALL(obj) (obj).begin(), (obj).end()
#define ALLR(obj) (obj).rbegin(), (obj).rend()
#define CEIL(a, b) ((a - 1) / b + 1)

void solve() {
    int H, W, M;
    cin >> H >> W >> M;
    vector<int> X(M), Y(M), row(H), col(W);
    REP(i, M) {
        int x, y;
        cin >> x >> y;
        x--, y--;
        row[x]++;
        col[y]++;
        X[i] = x;
        Y[i] = y;
    }
    vector<int> R, C;
    int maxr = -1, maxc = -1;
    REP(i, H) {
        if (row[i] > maxr)
            maxr = row[i], R.clear(), R.push_back(i);
        else if (row[i] == maxr)
            R.push_back(i);
    }
    REP(i, W) {
        if (col[i] > maxc)
            maxc = col[i], C.clear(), C.push_back(i);
        else if (col[i] == maxc)
            C.push_back(i);
    }
    // vector -> set
    unordered_set<int> vr(ALL(R)), vc(ALL(C));

    int cnt = 0;
    REP(i, M) {
        if (vr.count(X[i]) && vc.count(Y[i]))
            cnt++;
    }
    if (cnt == (int)(R.size() * C.size())) {
        cout << maxr + maxc - 1 << endl;
    } else {
        cout << maxr + maxc << endl;
    }
}

signed main() {
    cin.tie(nullptr)->sync_with_stdio(false);
    solve();
}


Measured memory_bytes: 41004
MODULO = 1000000007


def solve(n, xs):
    dp = [0] * (n + 1)
    dp[0] = 1
    dp[1] = 1 if 1 not in xs else 0
    for i in range(2, n + 1):
        if i in xs:
            dp[i] = 0
        else:
            if i - 1 not in xs:
                dp[i] += dp[i - 1]
            if i - 2 not in xs:
                dp[i] += dp[i - 2]
        dp[i] %= MODULO
    return dp[n]
         


def main():
    n, m = (int(z) for z in input().split())
    xs = {int(input()) for _ in range(m)}
    res = solve(n, xs)
    print(res)


if __name__ == "__main__":
    main()

Measured memory_bytes: 11884
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(i=0;i<n;i++)
#define foreach(c,itr) for(__typeof(c)::iterator itr=c.begin();itr!=c.end();itr++)
typedef long long ll;
typedef long double ld;
int i,j;

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

    int x;
    cin>>x;
    if(x==1)cout<<0<<endl;
    if(x==0) cout<<1<<endl;
	return 0;
}


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

int main() {
    int N;
    int count = 0;
    bool isThree = false;
    cin >> N;

    for(int i=0; i<N; i++)
    {
        int d1,d2;
        cin >> d1 >> d2;
        
        if(d1 == d2) count += 1;
        else count = 0;
        if(3 <= count) isThree = true;
    }

    if(isThree) cout << "Yes" << endl;
    else cout << "No" << endl;
    return 0;
}

Measured memory_bytes: 3628
#!/usr/bin/env python
# coding: utf-8

def ri():
    return int(input())

def rl():
    return list(input().split())

def rli():
    return list(map(int, input().split()))

def main():
    n = ri()
    lh = rli()
    for i in range(len(lh)-1):
        if lh[i+1] > lh[i]:
            lh[i+1] -= 1
        if lh[i+1] < lh[i]:
            print("No")
            return
    print("Yes")


if __name__ == '__main__':
    main()


Measured memory_bytes: 14484
N, M = map(int,input().split())
l = []
for i in range(M):
    l.append(list(map(int, input().split())))

def get_unique_list(seq):
    seen = []
    return [x for x in seq if x not in seen and not seen.append(x)]

#print(l)
ul = get_unique_list(l)

n1 = [x for x in ul if x[0] == 1]
n2 = [x for x in ul if x[0] == 2]
n3 = [x for x in ul if x[0] == 3]

ans = 0
if len(n1) > 1:
    ans = -1
elif len(n2) > 1:
    ans = -1
elif len(n3) > 1:
    ans = -1
else:
    if len(n1) > 0:
        s1 = n1[0][1]
        if N>1 and s1==0:
            ans = -1
    else:
        s1 = 0
    if len(n2) > 0:
        s2 = n2[0][1]
    else:
        s2 = 0
    if len(n3) > 0:
        s3 = n3[0][1]
    else:
        s3 = 0
    if ans == -1:
        ans = -1
    else:
        if N==1:
            ans = s1
        elif N==2:
            ans = s1*10 + s2
            if ans < 10:
                ans = ans + 10
        else:
            ans = s1*100 + s2*10 + s3
            if ans < 100:
                ans = ans + 100

print(ans)


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

int main(int argc, char const *argv[])
{
	long long int in_num,in;
	while(~scanf("%lld",&in_num)){
		long long int ans=0;
		int less_zero=0;
		long long int minn=1<<31-1;
		for (int i = 0; i < in_num; ++i)
		{
			scanf("%lld",&in);
			if (in<0)
			{
				less_zero++;
				in*=-1;
			}
			ans+=in;
			//printf("minn=%lld, in=%lld\n",minn,in );
			if (minn>in)
			{
				minn=in;
			}
		}
		if (less_zero%2)
		{
			ans-=2*minn;
		}
		printf("%lld\n",ans);
	}
	return 0;
}

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

using namespace std;
#define int long long
#define FOR(i, o, n) for (auto i = (o); (i) < (n); ++(i))
#define REP(i, n) FOR(i, 0, n)
#define REPR(i, n) for (auto i = (n)-1; (i) >= 0; --i)
#define REPI(itr, v) for (auto itr = v.begin(); itr != v.end(); ++itr)
#define REPIR(itr, v) for (auto itr = v.rbegin(); itr != v.rend(); ++itr)
#define fi first
#define se second
#define CR cerr<<endl;
#define V2(name, h, w) vector<vector<int> > name((h), vector<int>(w));
signed main(){
	int A, B, C; cin >> A >> B >> C;
	FOR(i, 1, B+1){
		if(A*i % B == C){
			cout << "YES" << endl;
			return 0;
		}
	}
	cout << "NO" << endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<string>
#include<cstring> 
#include<cassert>
#include<cmath>
#include<sstream>
#include<fstream>
#include<map>
#include<set>
#include<vector>
#include<queue>
#include<stack>
#include<bitset>
using namespace std;
int n;
void solve(long long ga,long long sa,long long ba,long long gb,long long sb,long long bb,long long &ma){
	if(sa<ba){
		swap(sa,ba);
		swap(sb,bb);
	}
	if(ga<sa){
		swap(ga,sa);
		swap(gb,sb);
	}
	for(long long g=0;g<=((ga>=gb)?0:n);g++){
		if(n-g*ga<0) break;
		for(long long s=0;s<=((sa>=sb)?0:n);s++){
			if(n-g*ga-s*sa>=0){
				long long re=n-g*ga-s*sa,b=0;
				if(ba<bb){
					b=re/ba;
					re-=b*ba;
				}
				long long now=re+g*gb+s*sb+b*bb;
				ma=max(now,ma);
			}
			else{
				break;
			}
		}
	}
}
int main(){
	long long ga,sa,ba,gb,sb,bb;
	cin>>n>>ga>>sa>>ba>>gb>>sb>>bb;
	long long ma=n;
	solve(ga,sa,ba,gb,sb,bb,ma);
	n=ma;
	solve(gb,sb,bb,ga,sa,ba,ma);
	cout<<ma;
}

Measured memory_bytes: 256
import sys

N = int(input())
T = [[0 for i in range(3)] for j in range(N)]
for i in range(3):
    T = [[0,0,0]]
for i in range(1,N+1):
    row = input().split()
    for j in range(len(row)):
        row[j] = int(row[j])
    T.append(row)

for i in range(N):
    dist = abs(T[i+1][1]-T[i][1]) + abs(T[i+1][2]-T[i][2])
    time = T[i+1][0]- T[i][0]

    if dist > time or (dist - time) % 2 == 1:
        print("No")
        sys.exit()

print("Yes")


Measured memory_bytes: 77276
#include <string>
#include <vector>
#include <iostream>

using namespace std;

bool is_leap(int y)
{
	return y % 400 == 0 || (y % 4 == 0 && y % 100 != 0);
}

long long countday(int y, int m, int d)
{
	long long daycount = 0;

	for (int i = 1; i < y; i++)
	{
		if (is_leap(i))
		{
			daycount += 366;
		}
		else
		{
			daycount += 365;
		}
	}

	for (int i = 1; i < m; i++)
	{
		if (i == 2 && is_leap(y) == false)
		{
			daycount += 28;
		}
		else if (i == 2)
		{
			daycount += 29;
		}
		else if (i == 4 || i == 6 || i == 9 || i == 11)
		{
			daycount += 30;
		}
		else
		{
			daycount += 31;
		}
	}

	daycount += d;

	return daycount;
}

vector<int> to_day(int daycount)
{
	int y = 1, m = 1, d = 0;

	for (int i = 0; i < daycount; i++)
	{
		d++;

		if (m == 2)
		{
			if (is_leap(y) == true)
			{
				if (d == 30)
				{
					m = 3; d = 1;
				}
			}
			else
			{
				if (d == 29)
				{
					m = 3; d = 1;
				}
			}
		}
		else if (m == 4 || m == 6 || m == 9 || m == 11)
		{
			if (d == 31)
			{
				m++; d = 1;
			}
		}
		else if(m == 12)
		{
			if (d == 32)
			{
				y++; m = 1; d = 1;
			}
		}
		else
		{
			if (d == 32)
			{
				m++; d = 1;
			}
		}
	}

	return{ y, m, d };
}

int main()
{
	string S;

	while (true)
	{
		cin >> S;

		if (S == "#") { break; }

		int dotcount = 0;

		for (int i = 0; i < S.size(); i++)
		{
			if (S[i] == '.')
			{
				dotcount++;
			}
		}

		if (dotcount == 2)
		{
			int y = 0, m = 0, d = 0;

			int i = 0;

			while (true)
			{
				if (S[i] == '.')
				{
					i++; break;
				}
				
				y *= 10; y += (S[i] - 48);

				i++;
			}

			while (true)
			{
				if (S[i] == '.')
				{
					i++; break;
				}
				
				m *= 10; m += (S[i] - 48);

				i++;
			}

			while (i < S.size())
			{
				d *= 10; d += (S[i] - 48);

				i++;
			}

			long long daycount = countday(y, m, d) - 734858;

			cout << (daycount / 144000) % 13 << '.' << (daycount / 7200) % 20 << '.' << (daycount / 360) % 20 << '.' << (daycount / 20) % 18 << '.' << daycount % 20 << endl;
		}
		else
		{
			int b = 0, ka = 0, t = 0, w = 0, ki = 0;

			int i = 0;

			while (true)
			{
				if (S[i] == '.')
				{
					i++; break;
				}

				b *= 10; b += (S[i] - 48);

				i++;
			}
			
			while (true)
			{
				if (S[i] == '.')
				{
					i++; break;
				}

				ka *= 10; ka += (S[i] - 48);

				i++;
			}

			while (true)
			{
				if (S[i] == '.')
				{
					i++;  break;
				}

				t *= 10; t += (S[i] - 48);

				i++;
			}

			while (true)
			{
				if (S[i] == '.')
				{
					i++; break;
				}

				w *= 10; w += (S[i] - 48);

				i++;
			}

			while (i < S.size())
			{
				ki *= 10; ki += (S[i] - 48);

				i++;
			}

			int daycount = b * 144000 + ka * 7200 + t * 360 + w * 20 + ki + 734858;

			vector<int> west = to_day(daycount);

			cout << west[0] << '.' << west[1] << '.' << west[2] << endl;
		}
	}

	return 0;
}

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

#define int long long
signed main()
{
    int n, x, y;
    cin >> n >> x >> y;
    map<int,int> a;
    for(int i = 1; i < n; i++){
        for(int j = i + 1; j <= n; j++){
            int k = min({abs(j- i), abs(x - i) + 1 + abs(j - y), abs(y - i) + 1 + (j - x)});
            a[k]++;
        }
    }
    for(int i = 1; i < n; i++){
        cout << a[i] << endl;
    }
}


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

#define REPI(i, n) for(int i = 0; i < n; i++)
#define REPJ(j, n) for(int j = 0; j < n; j++)

using ll = long long;
using namespace std;

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

    int a, b, c, x, ans = 0; cin >> a >> b >> c >> x;

    REPI(i, a + 1)
        REPJ(j, b + 1)
            for(int k = 0; k <= c; k++)
                if(i * 500 + j * 100 + k * 50 == x)
                    ans++;

    cout << ans;
}


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

#define endl '\n'
#define int ll
using namespace std;
typedef long long ll;

const int N = 100005;

int vn, en;
int indeg[N];
vector<int> graph[N];
ll dist[N];

void init();
void process();

int32_t main()
{
    ios::sync_with_stdio(false); cin.tie(0);
    init();
    process();
    cout.flush();
    return 0;
}

void init()
{
    cin >> vn >> en;
    for(int i = 0; i < en; i++)
    {
        int f, t; cin >> f >> t;
        graph[f].push_back(t);
        indeg[t]++;
    }
}

void process()
{
    queue<int> q;
    for(int i = 1; i <= vn; i++) if(indeg[i] == 0) q.push(i);
    while(!q.empty())
    {
        int f = q.front(); q.pop();
        for(auto t:graph[f]) 
        {
            dist[t] = max(dist[t], dist[f]+1);
            if(--indeg[t] == 0) q.push(t);
        }
    }
    ll mx = 0;
    for(auto d:dist) mx = max(mx, d);
    cout << mx << endl;
}



Measured memory_bytes: 7296
#include <bits/stdc++.h>
 
using namespace std;
 
typedef long long ll;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef pair<ll,ll> P;
typedef vector<P> vp;
typedef vector<string> vs;
typedef vector<bool> vb;

const ll mod=1e9+7;
const ll inf=1e16;

#define rep(i,m,n) for(ll i=m;i<n;i++)
#define repr(i,m,n) for(ll i=m-1;i>=n;i--)
#define fi first
#define se second
#define chmax(x,y) x=max(x,y)
#define chmin(x,y) x=min(x,y)
#define eb(x) emplace_back(x)
#define all(x) x.begin(),x.end()
#define gll greater<ll>()



void solve(){
  ll n,k;
  cin >> n >> k;

  
  ll res=0;
  rep(i,k,n+2){
   res+=i*(2*n-i+1)/2-i*(i-1)/2+1;
   res%=mod; 
    
  }
  
 cout << res << endl;
}

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

Measured memory_bytes: 3656
x1,y1,x2,y2=map(int,input().split())
p1,p2=complex(x1,y1),complex(x2,y2)
a=p2-p1
dis=(x1-x2)**2+(y1-y2)**2
for i in range(int(input())):
    p=complex(*map(int,input().split()))
    b=p-p1
    co=(a.real*b.real+a.imag*b.imag)/dis
    ans=p+2*(co*a-b)
    print(ans.real,ans.imag)


Measured memory_bytes: 5688
import collections
n=int(input())
a=collections.Counter(input())
for i in range(n-1):
    s=collections.Counter(input())
    a=a&s
ans=""
k=a.keys()
v=a.values()
for i,j in zip(k,v):
    ans+=i*j
print("".join(sorted(ans)))
    

Measured memory_bytes: 9400
#include<bits/stdc++.h>
using namespace std;
int main(){
  int N;
  cin>>N;
  int tmp=0;
  for(int i=1;i<=N;i++){
    if(i%2!=0)tmp++;
  }
  double ans=(double)tmp/N;
  cout<<fixed<<setprecision(10)<<ans<<endl;
}

Measured memory_bytes: 256
def main():
    n, m = map(int, input().split())
    ABs = [list(map(int, input().split())) for _ in range(n)]

    ABs = sorted(ABs)
    Count = 0
    ans = 0
    for i in range(n):
        if Count == m:
            break
        if ABs[i][1] + Count <= m:
            ans += ABs[i][0] * ABs[i][1]
            Count += ABs[i][1]
        else:
            o = m - Count
            ans += ABs[i][0] * o
            Count += o

    print(ans)


if __name__ == "__main__":
    main()


Measured memory_bytes: 28652
#include <stdio.h>
#include <string.h>

int main(void){
  char *temp,sentense[100],repeat[210],search[100],i,snt_len,srch_len,judge=1;

  scanf("%s",sentense);
  scanf("%s",search);
  strcpy(repeat,sentense);
  snt_len=strlen(sentense);
  srch_len=strlen(search);
  strcat(repeat,sentense);
  temp=repeat;
  for(i=0;i<snt_len;i++){
    judge=strncmp(temp,search,srch_len);
    if(judge==0)
      break;
    temp++;
  }
  if(judge==0)
    printf("Yes\n");
  else
    printf("No\n");
  
  return(0);
}

Measured memory_bytes: 548
#include<cstdio>
#include<iostream>
#include<cstring>
using namespace std;
int n,m,a[60][60],b[60][60];
char s[60];
int main()
{
	scanf("%d%d",&n,&m);
	for(int i=1;i<=n;i++)
	{
		scanf("%s",s);
		for(int j=1;j<=n;j++)
		  a[i][j]=s[j-1];
	}
	for(int i=1;i<=m;i++)
	{
		scanf("%s",s);
		for(int j=1;j<=m;j++)
		  b[i][j]=s[j-1];
	}
	for(int i=1;i<=n-m+1;i++)
	  for(int j=1;j<=n-m+1;j++)
	  {
	  	bool f=1;
	  	for(int k=1;k<=m;k++)
	  	  for(int p=1;p<=m;p++)
	  	    if(a[i+k-1][j+p-1]!=b[k][p])
	  	    {
	  	    	f=0;break;
	  	    }
	  	if(f)
	  	{
	  		printf("Yes");
	  		return 0;
	  	}
	  }
	printf("No");
	return 0;
}

Measured memory_bytes: 256
#include<cstdio>
#define max(a,b) a>b?a:b
using namespace std;
int main() {
	int a,b,s;
	scanf("%d%d",&a,&b);
	s=max(a+b,a-b);
	s=max(a*b,s);
	printf("%d",s);
	return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i,n) for(int (i)=0;(i)<(int)(n);++(i))
#define all(x) (x).begin(),(x).end()
#define pb push_back
#define fi first
#define se second
#define dbg(x) cout<<#x" = "<<((x))<<endl
template<class T,class U> ostream& operator<<(ostream& o, const pair<T,U> &p){o<<"("<<p.fi<<","<<p.se<<")";return o;}
template<class T> ostream& operator<<(ostream& o, const vector<T> &v){o<<"[";for(T t:v){o<<t<<",";}o<<"]";return o;}

int main()
{
    int r,g,b;
    cin >>r >>g >>b;
    cout << (((100*r+10*g+b)%4==0)?"YES":"NO") << endl;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<int(n);i++)
#define rep1(i,n) for(int i=1;i<=int(n);i++)
#define per(i,n) for(int i=int(n)-1;i>=0;i--)
#define per1(i,n) for(int i=int(n);i>0;i--)
#define foreach(i,n) for(auto &&i:n)
#define all(x) (x).begin(),(x).end()
#define SORT(x) sort(all(x))
#define GSORT(x) sort(all(x), greater<int>())
#define REV(x) reverse(all(x))
#define MAX(x) *max_element(all(x))
#define MIN(x) *min_element(all(x))
#define LOWitr(x, n) lower_bound(all(x), n)
#define UPRitr(x, n) upper_bound(all(x), n)
#define cii(x) int x;cin >> x
#define cill(x) LL x;cin >> x
#define cis(x) string x;cin >> x
#define co(x) cout << x << endl
#define dump(x)  cout << #x << " = " << (x) << endl
#define truecheck assert
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define fastcin() cin.tie(0);ios::sync_with_stdio(false)
using namespace std;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef long long LL;
typedef long long int64;
template<class T,class U>bool chmax(T &a, const U &b) { if (a<b) { a=b; return true; } return false; }
template<class T,class U>bool chmin(T &a, const U &b) { if (b<a) { a=b; return true; } return false; }
const int INF = 1e9, MOD = 1e9 + 7;
const LL LLINF = 1e16;

int main() {
    fastcin();
    cout << fixed << setprecision(10);
    cii(a);
    cii(b);
    int ans = (a <= 9 && b <= 9)
            ?a * b
            :-1;
    co(ans);
    return 0;
}

Measured memory_bytes: 256
import java.io.*;
import java.util.*;
public class Main {

	public static void main(String[] args){
		Scanner sc=new Scanner(System.in);
		while(sc.hasNextLine()) {
			String a =sc.nextLine();
			char[] o=a.toCharArray();
			for(int i=0;i<26;i++){
				//System.out.println();
				for(int j =0;j<o.length;j++){
					if(o[j]>='a'&&o[j]<='z'){
						if(o[j]=='z'){
							o[j]='a';
						}else{
							o[j]++;
						}	
					}
				}
				String ans=String.valueOf(o);
				// System.out.println(ans);
				if(ans.contains("this")||ans.contains("that")||ans.contains("the")){
					System.out.println(ans);
					break;
				}


			}
		}
	}
}

Measured memory_bytes: 17980
using System;
using System.Linq;
using System.Collections;
using System.Collections.Generic;
using static System.Console;
class Program
{
    static void Main()
    {
        //入力
        //int n = 100;
        /*
        long n = long.Parse(Console.ReadLine());
        long[] input = new long[5];
        for(int a = 0; a < 5; a++)
        {
            input[a]=long.Parse(Console.ReadLine());
        }
        */
        int[] input = Console.ReadLine().Split().Select(i => int.Parse(i)).ToArray();
        Console.WriteLine((int)input[0]*input[1]/2);


        /*
        //処理速度計測
        var sw = new System.Diagnostics.Stopwatch();
        sw.Start();
        //解法
 
        //処理速度表示
        sw.Stop();
        TimeSpan ts = sw.Elapsed;
        Console.WriteLine((int)(Math.Floor((ts).TotalMilliseconds))+"ms");
        */
        Console.ReadLine();

    }
}

Measured memory_bytes: 13268
#include <bits/stdc++.h>
using namespace std;
#define rep(i,e) for(int i= 0; i< (int)(e); i++)
#define reps(i,s,e) for(int i = s; i < (int)(e); i++)
#define repr(i,s,e) for(int i = s; i > (int)(e); i--)
# define pb push_back
typedef long long ll;
const ll INF = 1LL << 60;

int main(){
    int n,a,b,c,d;
    cin >> n >> a >> b >> c >> d;
    string s;
    cin >> s;
    string ans = "Yes";
    //a->b must possible
    reps(i,a-1,b-1){
        if(s[i]=='#' && s[i+1]=='#'){
            ans = "No";
            break;
        }
    }
    //c->d must possible
    reps(i,c-1,d-1){
        if(s[i]=='#' && s[i+1]=='#'){
            ans = "No";
            break;
        }
    }
    //jump must be possible
    if(ans == "Yes"){
        /*
        if(a < b && b < c && c < d){
            reps(i,b-1,c-2){
                if(s[i-1]=='.' && s[i]=='.' && s[i+1]=='.'){
                    jump_flag = "Yes";
                    break;
                }
            }
        }*/
        if(a < b && b < d && d < c){
            string jump_flag = "No";
            reps(i,b-1,d){
                if(s[i-1]=='.' && s[i]=='.' && s[i+1]=='.'){
                    jump_flag = "Yes";
                    break;
                }
            }
            if(jump_flag == "No"){
                ans = "No";
            }
        }
    }
    cout << ans;
}

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

int N;
int a[100000], b[100000], c[1000000];
int dp[100000][3];

signed main() {
  cin >> N;
  for(int i=0; i<N; i++) cin >> a[i] >> b[i] >> c[i];

  dp[0][0] = a[0];
  dp[0][1] = b[0];
  dp[0][2] = c[0];

  for(int i=1; i<N; i++) {
    dp[i][0] = a[i] + max(dp[i-1][1], dp[i-1][2]);
    dp[i][1] = b[i] + max(dp[i-1][0], dp[i-1][2]);
    dp[i][2] = c[i] + max(dp[i-1][0], dp[i-1][1]);
  }

  printf("%d\n", max(max(dp[N-1][0],dp[N-1][1]),dp[N-1][2]));
}


Measured memory_bytes: 2560
#include<iostream>
#include<stdio.h>
#include<string>
#include<cmath>
#include<vector>
#include<algorithm>
#pragma warning(disable: 4996)
#define rep(i,n) for(int i = 0; i < (n); i++)
using namespace std;;
using ll = long long;

int main() {
	int N;
	cin >> N;
	vector<int> A(N);
	vector<int> flag;
	int cnt = 0;
	rep(i, N) {
		cin >> A[i];
		if (A[i] % 2 == 0) { flag.push_back(A[i]); cnt++; }
	}
	int ch = 0;
	bool ans = false;
	rep(i, cnt) {
		if (flag[i] % 3 == 0 || flag[i] % 5 == 0) {
			ch++;
		}
	}
	if (ch == cnt) {
		ans = true;
	}
	puts(ans ? "APPROVED" : "DENIED");
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(){
  int a,b; cin >> a >> b;
  if(b>a) swap(a,b);
  if(abs(a-b)%2!=0) {
    cout << "IMPOSSIBLE" << endl;
    return 0;
  }
  cout << (a+b)/2 << endl;
}

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

# AtCoder Beginner Contest
# Problem A

if __name__ == '__main__':
    number = list(map(int, input()))

    for i in range(0, 10):
        if (number.count(i) >= 3) and (number[1] == i and number[2] == i):
            print('Yes')
            break
    else:
        print('No')


Measured memory_bytes: 2940