akhauriyash/Code-Regression huggingface dataset:
import sys
from bisect import bisect_right


def calculate_score(c):
    global D, last, S
    rst = 0
    _last = last[c]
    for d in range(1, D + 1):
        down = C[c] * (d - _last[d])
        up = S[d][c] if _last[d] == d else 0
        rst += up - down
    return rst


Z = 26
D = int(input())
C = list(map(int, input().split()))

S = [tuple([0] * Z)] + [tuple(map(int, input().split())) for _ in range(D)]
T = [None] + [int(input()) - 1 for _ in range(D)] # 

M = int(input())
Q = [tuple(map(lambda x: int(x) - 1, s.split())) for s in sys.stdin.readlines()]


last = [[0] * (D + 1) for _ in range(Z)]  # last[i][d]
V = [0] * Z  # 各コンテストiごとの得点を保管しておく

# 初期状態でのlastを求める
for d in range(1, D + 1):
    t = T[d]
    for i in range(Z):
        last[i][d] = last[i][d - 1]
    last[t][d] = d
# 各コンテストiごとに得点を求める
for i in range(Z):
    V[i] = calculate_score(i)

# 初期状態での得点
score = sum(V)

for d, q in Q:
    d += 1  # Qだけ0-indexなので補正
    p = T[d]

    # d日目の開催が p -> q に変わる
    # まず, last[p]を更新する. 更新箇所はd日目 ~ 次の開催日直前
    e = bisect_right(last[p], d)
    for j in range(d, e):
        last[p][j] = last[p][j - 1]

    # 次に, last[q]を更新する. 更新箇所はd日目 ~ 次の開催日直前
    old = last[q][d]
    e = bisect_right(last[q], old)
    for j in range(d, e):
        last[q][j] = d

    # まず, 変更前のp, qの値を引く
    score -= V[p] + V[q]

    # 変更後のp, qの値を計算し, 全体に足す
    V[p] = calculate_score(p)
    V[q] = calculate_score(q)
    score += V[p] + V[q]
    print(score)

    # Tを更新
    T[d] = q

Measured memory_bytes: 100704
import sys


def solve():
    input = sys.stdin.readline
    mod = 10 ** 9 + 7
    n = int(input().rstrip('\n'))
    a = list(map(int, input().rstrip('\n').split()))
    for i in range(n):
        a[i] -= i + 1
    a.sort()
    t = a[n // 2]
    mt = 0
    for v in a:
        mt += abs(t - v)
    print(mt)


if __name__ == '__main__':
    solve()


Measured memory_bytes: 79952
import java.util.Arrays;
import java.util.Comparator;
import java.util.Scanner;

public class Main {

	static Scanner sc = new Scanner(System.in);
	public static void main(String[] args) {
		Integer[] nums = new Integer[5];

			for (int i = 0; i < 5; i++) {
				nums[i] = sc.nextInt();
			}

			Arrays.sort(nums, Comparator.reverseOrder());

			for (int i = 0; i < 5; i++) {
				String sp = (i < 4) ? " " : "\n";
				System.out.print(nums[i] + sp);
			}


	}

}


Measured memory_bytes: 26004
// Problem Link: https://atcoder.jp/contests/aising2020/tasks/aising2020_e
// Tutorial Link: https://img.atcoder.jp/aising2020/editorial.pdf

#include<bits/stdc++.h>
 
using namespace std;
 
#define LL long long
#define pb push_back
#define pLL pair<LL,LL>
#define ff first
#define ss second
#define rep(i,a,b) for(LL i=a;i<=b;++i)
#define repb(i,a,b) for(LL i=a;i>=b;--i)
#define ld double
#define mp make_pair
#define vLL vector<LL>
#define vpLL vector<pLL>
#define vld vector<ld>
#define pld pair<ld,ld>
#define vpld vector<pld>
#define SLL set<LL>
#define SpLL set<pLL>
#define FIO ios::sync_with_stdio(false)
#define mod 1000000007

LL t, n;
vpLL l, r;

priority_queue<LL> pq;

inline LL process(vpLL& v) {
	LL cur = 0, ret = 0;
	sort(v.begin(), v.end());
	for(auto [k, val]: v) {
		if(k != cur) {
			if(!pq.empty()) while(pq.size() > cur) pq.pop();
			cur = k;
		}
		pq.push(-val);
	}
	while(pq.size() > cur) pq.pop();
	while(!pq.empty()) {
		ret -= pq.top();
		pq.pop();
	}
	return ret;
}

int main()
{
	FIO;
	cin >> t;
	while(t--) {
		cin >> n;
		LL ans = 0;
		l.clear();
		r.clear();
		rep(i,1,n) {
			LL k, v1, v2;
			cin >> k >> v1 >> v2;
			if(k == n) {
				ans += v1;
				continue;
			}
			ans += min(v1, v2);
			if(v1 > v2) l.pb(mp(k, abs(v1-v2)));
			else if(v1 < v2) r.pb(mp((n-k), abs(v1-v2)));
		}

		ans += process(l);
		ans += process(r);
		
		cout << ans << "\n";
	}
}

Measured memory_bytes: 8100
#include<bits/stdc++.h>
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define rep2(i, m, n) for(int i = (int)(m); i < (int)(n); i++)
#define rep_inv(i, n, m) for(int i = (int)(n); i > (int)(m); i--)
using namespace std;
using ll = long long;
using vl = vector<ll>;
using vc = vector<char>;
using vvl = vector<vl>;
using vvc = vector<vc>;
using pll = pair<ll, ll>;
using vpll = vector<pll>;

int main(){
  string T;
  cin >> T;

  rep(i, T.size()){
    if(T[i] == '?') T[i] = 'D';
  }

  cout << T << endl;
  
  return 0;
}


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

int main() {
    int K, N; cin >> K >> N;
    vector<int64_t> A(N);
    for(auto &e : A) cin >> e;
    A.push_back(A.front() + K);
    int64_t sum = 0;
    rep(i, N) sum += A[i + 1] - A[i];
    int64_t ans = sum;
    rep(i, N) ans = min(ans, sum - (A[i + 1] - A[i]));
    cout << ans << '\n';
    return 0;
}


Measured memory_bytes: 4864
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main(){
    string s, t;
    cin >> s >> t;
    int N = s.size();
    int M = t.size();

    string ans = "~";
    for(int i = 0; i <= N-M; i++){
        string s2 = s;
        bool ok = true;
        for(int j = 0; j < M; j++){
            if(s[i+j] != '?' && s[i+j] != t[j]){
                ok = false;
            }
            s2[i+j] = t[j]; 
        }
        if(ok){
            replace(s2.begin(), s2.end(), '?', 'a');
            ans = min(s2, ans);
        }
    }
    if(ans == "~") cout << "UNRESTORABLE" << endl;
    else cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256
import java.util.ArrayDeque;
import java.util.ArrayList;
import java.util.Deque;
import java.util.Scanner;
public class Main {
	public static void main(String[] args)throws Exception{
		Scanner stdIn=new Scanner(System.in);
		int N=stdIn.nextInt();
		int M=stdIn.nextInt();
		ArrayList<ArrayList<Integer>> A=new ArrayList<ArrayList<Integer>>();
		Deque <Integer> Q=new ArrayDeque<Integer>();
		int ans[]=new int[N];
		boolean visit[]=new boolean[N];
		for(int i=0;i<N;i++){
			A.add(new ArrayList<Integer>());
		}
		for(int i=0;i<M;i++){
			int a=stdIn.nextInt()-1;
			int b=stdIn.nextInt()-1;
			ArrayList<Integer> c=new ArrayList<Integer>();
			c=A.get(a);c.add(b);A.set(a,c);
			c=A.get(b);c.add(a);A.set(b,c);
		}
		Q.add(0);visit[0]=true;
		while(Q.size()>0){
			int a=Q.poll();
			for(int i=0;i<A.get(a).size();i++){
				int b=A.get(a).get(i);
				if(visit[b]==false){
					ans[b]=a;visit[b]=true;Q.add(b);
				}
			}
		}
		System.out.println("Yes");
		for(int i=1;i<N;i++){
			System.out.println(ans[i]+1);
		}
	}
}


Measured memory_bytes: 75136
#include <bits/stdc++.h>
#define F first
#define S second
#define PB push_back
#define MP make_pair
#define sqr(a) a*a


using namespace std;
typedef unsigned long long ull;
typedef long long ll;
typedef vector<int> vi;
typedef vector<bool> vb;
typedef pair<int,int> pi;


int main() {
    ios::sync_with_stdio(0);
    cin.tie(0);
    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);
    int h, n;
    cin >> h >> n;
    ll res = 0, el;
    for(int i = 0; i < n; ++i){
        cin >> el;
        res += el;
    }
    if(h <= res){
        cout << "Yes";
    }else{
        cout << "No";
    }
}

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

int main(){
    int n, m;
    
    cin >> n >> m;
    
    if(n < 10 && m < 10){
        cout << n*m << endl;
    }
    
    else{
        cout << -1 << endl;
    }
    
    
    
    
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <cmath>
#include <string>
using namespace std;
int main() {
	int a, b, c, d;
	cin >> a >> b >> c >> d;
	if (a + b > c + d)
		cout << "Left" << "\n";
	else if (a + b < c + d)
		cout << "Right" << "\n";
	else
		cout << "Balanced" << "\n";
}

Measured memory_bytes: 3620
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<(n);i++)
using ll = long long;
using P = pair<int,int>;
void Yes() {
    cout << "Yes" << endl;
}
void No() {
    cout << "No" << endl;
}
int main(void) {
    int n; cin >> n;
    if(n/10==9 || n%10==9) Yes();
    else No();
}


Measured memory_bytes: 256
import java.util.*;
//import java.util.stream.Collectors;

public class Main{
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		
		String s = sc.next();
		String t = sc.next();
		int a = Integer.parseInt(sc.next());
		int b = Integer.parseInt(sc.next());
		if(sc.next().equals(s)){
			a--;
		}else{
			b--;
		}
		System.out.println(a + " " + b);
	}
}


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

vector<long long> PrimeFactorize(long long n) {
    vector<bool> prime(round(sqrt(n)) + 1, 1);
    vector<long long> ans;
    for (long long i = 2; i * i <= n; i++) {
        if (prime[i]) {
            for (long long j = 2 * i; j * j <= n; j += i) {
                prime[j] = 0;
            }
            while (n % i == 0) {
                ans.push_back(i);
                n /= i;
            }
        }
    }
    if (n != 1) ans.push_back(n);
    return ans;
}

void solve(long long N) {
    auto ps = PrimeFactorize(N);

    map<long long, int> m;
    for (auto &p : ps) {
        m[p]++;
    }

    int ans = 0;
    for (auto &pp : m) {
        int cur = 1;
        while (pp.second >= cur) {
            ans++;
            pp.second -= cur;
            cur++;
        }
    }

    cout << ans << endl;
}

// Generated by 1.1.7.1 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
int main() {
    long long N;
    scanf("%lld", &N);
    solve(N);
    return 0;
}


Measured memory_bytes: 3908
/* Official House */
#include <stdio.h>

int main(int argc, char ** argv){
        int n;                          /* # of records */
        int b, f, r, v;                 /* b:building, f:floor, r:room, v:v? */
        int count[4][3][10] = {0};      /* # of residences */
        int i;                          /* loop counter */

/* Get # of records */
        scanf ("%d", &n);
        /* printf("%d",  n); /* For Debug */

/* Read records and count */
        for (i = 0; i < n; i++) {
                scanf   ("%d%d%d%d",    &b, &f, &r, &v);
                /* printf ("%d %d %d %d\n", b,  f,  r,  v); /* For Debug */

                count[b-1][f-1][r-1] = count[b-1][f-1][r-1] + v;
                /* printf ("%d\n",  count[b-1][f-1][r-1]); /* For Debug */
        }

/* Print out # of residences */
        for (b = 0; b <  4; b++) {
        for (f = 0; f <  3; f++) {
        for (r = 0; r < 10; r++) {
                printf(" %d", count[b][f][r]); /* Residence list for a floor */
        }
                printf("\n"); /* Line feed between floors */
        }
                if (b != 3) printf("####################\n");
        }
return 0;
}

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

int main() {
  int N, number, a, b, c, d;

  cin >> N;
  
  number = N;//N=1119
  a = (number / 1000);//a=1
  b = (number % 1000)/100;//b=(119)/100
  c = (number % 100)/10;
  d = (number % 10);
  
  //cout << a << "," << b << "," << c << "," << d << endl;
  
 /* if(a < 1 || a > 9){
    cout << "No" << endl;
  }
  else*/ if(a == b && b == c) {
    cout << "Yes" << endl;
  }
  else if(b == c && c == d){
    cout << "Yes" << endl;
  }
  else{
    cout << "No" << endl;
  }

}

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

class Procon
{
    public Procon() { }
    static void Main(string[] agrs)
    {
        new Procon().Do();
    }

    Scanner cin;

    public void Do()
    {
        cin = new Scanner();
        int A = cin.nextInt();
        int B = cin.nextInt();

        if (A <= 8 && B <= 8)
        {
            Console.WriteLine("Yay!");
            return;
        }
        Console.WriteLine(":(");
    }
}

class Scanner
{
    string[] s;
    int i;
    int max_i;

    public Scanner()
    {
        s = new string[0];
        max_i = 0;
        i = 0;
    }

    public string nextString()
    {
        if (i >= s.Length)
        {
            s = Console.ReadLine().Split(' ');
            max_i = s.Length;
            i = 0;
            if (max_i == 0)
            {
                return "";
            }
            return s[i++];
        }
        else
        {
            return s[i++];
        }
    }

    public int nextInt()
    {
        return int.Parse(nextString());
    }


    public long nextLong()
    {
        return long.Parse(nextString());
    }

    public double nextDouble()
    {
        return double.Parse(nextString());
    }

    public string[] arrayString()
    {
        return Console.ReadLine().Split(' ');
    }

    public int[] arrayInt()
    {
        string[] str = Console.ReadLine().Split(' ');
        int[] array = new int[str.Length];
        for (int i = 0; i < str.Length; i++)
        {
            array[i] = int.Parse(str[i]);
        }
        return array;
    }

    public long[] arrayLong()
    {
        string[] str = Console.ReadLine().Split(' ');
        long[] array = new long[str.Length];
        for (int i = 0; i < str.Length; i++)
        {
            array[i] = long.Parse(str[i]);
        }
        return array;
    }

    public double[] arrayDouble()
    {
        string[] str = Console.ReadLine().Split(' ');
        double[] array = new double[str.Length];
        for (int i = 0; i < str.Length; i++)
        {
            array[i] = double.Parse(str[i]);
        }
        return array;
    }
}

Measured memory_bytes: 11092
#include <bits/stdc++.h>
#define FOR(i,a,b) for (int i = (a); i < (b); ++i)
#define RFOR(i,a,b) for (int i = (b)-1; i >= (a); --i)
#define rep(i,n) FOR(i,0,(n))
#define REPS(i,n) FOR(i,1,(n)+1)
#define RREP(i,n) RFOR(i,0,(n))
#define ALL(x) (x).begin(),(x).end()
#define RALL(x) (x).rbegin(),(x).rend()
#define DEBUG(x)  cout << #x << " = " << (x) << endl;
#define SORT(x) sort(ALL(x));
#define RSORT(x) sort(RALL(x));
#define SUM(x) accumulate(ALL(x),0);
#define fi first
#define se second
#define pb push_back
#define eb emplace_back
#define sz(x) (int)(x).size()
#define bn(x) ((1<<x)-1)
#define dup(x,y) (((x)+(y)-1)/(y))
using namespace std;
using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vll = vector<ll>;
using pii = pair<int, int>;
using tiii = tuple<int, int, int>;
const ll mod = 1e9+7;
const int INF = (1<<30)-1;
const ll INFLL = (1LL<<62)-1;
const int dx[4] = {1,0,-1,0};
const int dy[4] = {0,1,0,-1};
//cout << fixed << setprecision(10);

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }

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

int n;
char s[100005];
ll dp[100005][13];

int main () {
  int i, j, ki;
  ll res = 0;

  scanf("%s", s);
  n = strlen(s);

  dp[0][0] = 1;
  rep(i,n) {
    // i文字目
    int c;
    if (s[i] == '?') c = -1;
    else c = s[i] - '0';

    rep(j,10) {
      if (c != -1 && c != j) continue;
      // c == '?' || c == j
      // i+1文字目としてjを追加
      rep(ki,13) {
        // 先頭i番目までの13で割ったときの余りがkiの状態からi+1番目にjを追加すると、
        // 先頭i+1番目までの13で割ったときの余りが(ki*10+j)%13になる
        dp[i+1][(ki*10+j)%13] += dp[i][ki];
      }
    }
    rep(j,13) dp[i+1][j] %= mod;
  }
  res = dp[n][5];

  cout << res << endl;
  return 0;
}

Measured memory_bytes: 10496
#include <iostream>
#include <cmath>
#include<vector>
#define rep(i,n) for(int i=0;i<(n);i++)
using namespace std;
typedef long long ll;
int main() {
	int n;
	cin >> n;
	vector<int>x(n);
	
	rep(i, n)	cin >> x[i];
	int max = -1;
	rep(i, n){
		if (max <= x[i] - 1){
			max = x[i] - 1;
		}
		else if (max <= x[i]){
			max = x[i];
		}
		else{
			cout << "No" << endl;
			return 0;
		}
	}
	cout << "Yes" << endl;
	return 0;
}

Measured memory_bytes: 640
#include<cstdio>
#include<cstring>

int main() {
  char ch1[1001];
  int A[1001] = {};
  
  for( int i = 0; i <1001; i++) {
    scanf("%s", ch1);
    if( ch1[0] == '0') break;
    for( int j = 0; 1; j++) {
      if( ch1[j] == '\0') break;
      A[i] += ch1[j] - '0';
    }
  }
 
  for( int i = 0; 1; i++) {
    if( A[i] == '\0') break;
    printf("%d\n", A[i]);
  }

  return 0;
}

Measured memory_bytes: 2760
#include<cstdio>
#include<iostream>
#include<cstdlib>
#include<cmath>
#include<vector>
#include<map>
#include<algorithm>

using namespace std;

int find_r(vector<int>& h, int l)
{
    for (int i = l; i < h.size(); i++) {
        if (h[i] == 0) {
            return i - 1;
        }
    }

    return h.size() - 1;
}

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

    vector<int> h(n, 0);
    for (int i = 0; i < n; i++) {
        cin >> h[i];
    }

    int count = 0;
    for (int i = 0; i < n - 1; i++) {
        while (h[i] > 0) {
            int r = find_r(h, i);
            for (int j = i; j <= r; j++) {
                h[j]--;
            }
            count++;
        }
    }

    cout << count + h[n - 1] << endl;

    return 0;
}


Measured memory_bytes: 256
import java.util.*;

public class Main{
    public static void main(String args[]){
        Scanner input = new Scanner(System.in);
        int a = input.nextInt();
        int b = input.nextInt();
        int c = input.nextInt();
        int min, mid, max;
        if (a < b){
            if (a < c){
                min = a;
                if (b < c){
                    mid = b;
                    max = c;
                }
                else {
                    mid = c;
                    max = b;
                }
            }
            else {
                min = c;
                mid = a;
                max = b;
            }
        }
        else{
            if (b < c){
                min = b;
                if(a > c){
                    mid = c;
                    max = a;
                }
                else{
                    mid = a;
                    max = c;
                }
            }
            else{
                min = c;
                mid = b;
                max = a;
            }
        }
    System.out.println(min+" "+mid+" "+max);
    }
}


Measured memory_bytes: 26164
#include <bits/stdc++.h>
using namespace std;
#define int long long

signed main(){
	int N, K, M = 62, i, j;
	scanf("%lld%lld", &N, &K);
	vector<vector<int>> A(M, vector<int>(N, -1));
	for(j = 0; j < N; j++){
		scanf("%lld", &A[0][j]);
		A[0][j]--;
	}
	for(i = 1; i < M; i++){
		for(j = 0; j < N; j++){
			A[i][j] = A[i - 1][A[i - 1][j]];
		}
	}
	int now = 0;
	for(i = 0; i < M; i++){
		if((K | (1ll << i)) == K){
			now = A[i][now];
		}
	}
	printf("%lld\n", now + 1);
	return 0;
}

Measured memory_bytes: 101740
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>	
#include<map>
#include<set>
#include<utility>
#include<cmath>
#include<cstring>
#include<queue>
#include<cstdio>
#include<sstream>
#define loop(i,a,b) for(int i=a;i<b;i++) 
#define rep(i,a) loop(i,0,a)
#define pb push_back
#define mp make_pair
#define all(in) in.begin(),in.end()
const double PI=acos(-1);
const double EPS=1e-8;
const int inf=1e9;
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int,int> pii;
int eulerPhi(int n){
	int out=n;
	for(int i=2;i*i<=n;i++){
		if(n%i==0){
			out-=out/i;
			while(n%i==0)n/=i;
		}
	}
	if(n>1)out-=out/n;
	return out;
}
int main(){
	int n;
	cin>>n;
	cout<<eulerPhi(n)<<endl;
}

Measured memory_bytes: 1160
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.StringTokenizer;

public class Main {
	
	public static void main(String[] args) throws IOException {
		MyScanner sc = new MyScanner();
		PrintWriter out = new PrintWriter(System.out);
		long A = sc.nextLong();
		long V = sc.nextLong();
		long B = sc.nextLong();
		long W = sc.nextLong();
		long T = sc.nextLong();
		long dif = Math.abs(A - B);
		long max = (V - W) * T;
		out.println(dif <= max ? "YES" : "NO");
		
		out.flush();
	}
	
	static class MyScanner {
		private BufferedReader br;
		private StringTokenizer tokenizer;
		
		public MyScanner() {
			br = new BufferedReader(new InputStreamReader(System.in));
		}
		
		public String next() {
			while (tokenizer == null || !tokenizer.hasMoreTokens()) {
				try {
					tokenizer = new StringTokenizer(br.readLine());
				} catch (IOException e) {
					throw new RuntimeException(e);
				}
			}
			return tokenizer.nextToken();
		}
		
		public int nextInt() {
			return Integer.parseInt(next());
		}
		
		public long nextLong() {
			return Long.parseLong(next());
		}
	}
}


Measured memory_bytes: 32416
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <cmath>
#include <set>
#include <sstream>
#include <bitset>
#include <stack>
#include <cstdlib>

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)

typedef long long ll;

using namespace std;

int main() {
    
    int n,d,x;
    cin >> n >> d >>x;
    
    vector<int> a(n);
    int cnt=0;
    
    FOR(i, 0, n){
        cin >> a[i];
        
        int y=0;
        while(a[i]*y+1<=d){
            cnt++;
            y++;
        }
    }
    
    cout << cnt+x << endl;
    return 0;
}


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

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

#define ALL(a)  begin((a)),end((a))
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define EB emplace_back
#define MP make_pair
#define SZ(a) int((a).size())
#define SORT(c) sort(ALL((c)))
#define RSORT(c) sort(RALL((c)))
#define UNIQ(c) (c).erase(unique(ALL((c))), end((c)))

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)

#define FF first
#define SS second
template<class S, class T>
istream& operator>>(istream& is, pair<S,T>& p){
  return is >> p.FF >> p.SS;
}
template<class S, class T>
ostream& operator<<(ostream& os, const pair<S,T>& p){
  return os << p.FF << " " << p.SS;
}
template<class T>
void maxi(T& x, T y){
  if(x < y) x = y;
}
template<class T>
void mini(T& x, T y){
  if(x > y) x = y;
}


const double EPS = 1e-10;
const double PI  = acos(-1.0);
const LL MOD = 1e9+7;
const int INF = 1e9;

struct Edge{
  int to, cost;

  Edge(int t, int c = 0): to(t), cost(c)
  {}
  bool operator>(const Edge& rhs) const{
	return cost > rhs.cost;
  }
  bool operator<(const Edge& rhs) const{
	return cost < rhs.cost;
  }

};
using Graph =  vector< vector<Edge> >;

void Dijkstra(const Graph& G, vector<int>& d, int s){
  using Type = pair<int,int>;
  priority_queue<Type, vector<Type>, greater<Type> > pq;
  fill(d.begin(), d.end(), INF);
  d[s] = 0;
  pq.push(MP(0,s));

  while(!pq.empty()){
	Type pii = pq.top();
	pq.pop();
	int v = pii.second;
	if(d[v] < pii.first) continue;
	for(const auto& e: G[v]){
	  if(d[e.to] > d[v] + e.cost){
		d[e.to] = d[v] + e.cost;
		pq.push(MP(d[e.to], e.to));
	  }
	}
  }
}


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

  int V, E, R;
  cin >> V >> E >> R;
  Graph G(V);
  for(int i=0;i<E;++i){
	int s, t, d;
	cin >> s >> t >> d;
	G[s].emplace_back(t, d);
  }

  vector<int> dist(V);
  Dijkstra(G, dist, R);
  REP(i,V){
	if(dist[i] == INF) cout << "INF" << endl;
	else cout << dist[i] << endl;
  }
  
  return 0;
}

Measured memory_bytes: 13060
import sys
def input(): return sys.stdin.readline().strip()
def mapint(): return map(int, input().split())
sys.setrecursionlimit(10**9)

N, M = mapint()
from bisect import bisect_left
def make_divisors(n):
    lower_divisors , upper_divisors = [], []
    i = 1
    while i*i <= n:
        if n % i == 0:
            lower_divisors.append(i)
            if i != n // i:
                upper_divisors.append(n//i)
        i += 1
    return lower_divisors + upper_divisors[::-1]

div = [1]+make_divisors(M)
div.sort()
g = div[bisect_left(div, N)]
print(M//g)


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


int main() {
  long n,k;
  cin>>n>>k;
  vector<long>a(n);
  
  rep(i,n){
    cin>>a.at(i);
    
  }
  sort(a.begin(),a.end());
  long ans=0;
  rep(i,k){
    ans+=a.at(i);
  }
  
  cout<<ans<<endl;
}




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

import sys
from operator import itemgetter

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

N = INT()
LR = []
for i in range(N):
    x, l = MAP()
    LR.append((x-l, x+l-1))

LR.sort(key=itemgetter(1))
cur = -INF
cnt = 0
for l, r in LR:
    if cur < l:
        cur = r
        cnt += 1
print(cnt)


Measured memory_bytes: 18280
/**
 *    author:  tourist
 *    created: 15.01.2020 15:11:38       
**/
#include <bits/stdc++.h>

using namespace std;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  string s, t;
  cin >> s >> t;
  vector<int> ps(s.size() + 1);
  for (int i = 0; i < (int) s.size(); i++) {
    ps[i + 1] = ps[i] + (s[i] == 'A' ? 1 : 2);
  }
  vector<int> pt(t.size() + 1);
  for (int i = 0; i < (int) t.size(); i++) {
    pt[i + 1] = pt[i] + (t[i] == 'A' ? 1 : 2);
  }
  int tt;
  cin >> tt;
  while (tt--) {
    int a, b, c, d;
    cin >> a >> b >> c >> d;
    int x = ps[b] - ps[a - 1];
    int y = pt[d] - pt[c - 1];
    cout << (x % 3 == y % 3 ? "YES" : "NO") << '\n';
  }
  return 0;
}


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

void fnInput(vector<string>& rvsGrid)
{
  int nHigh, nWide;
  cin >> nHigh >> nWide;

  rvsGrid.resize(nHigh);
  for (int ny = 0; ny < nHigh; ny++)
    cin >> rvsGrid[ny];
}

int fnRepaint(int ny, int nx, const vector<string>& cnrvsGrid)
{
  if (   ny >= 0  && ny < cnrvsGrid.size()
      && nx >= 0  && nx < cnrvsGrid[ny].size())
    if (cnrvsGrid[ny][nx] == '#')
      return 1;
    else;

  return 0;
}

int fnGridRepaint(const vector<string>& cnrvsGrid)
{
  const vector<int> cnvnDy = {-1,  0,  1,  0};
  const vector<int> cnvnDx = { 0, -1,  0,  1};

  for (int ny = 0; ny < cnrvsGrid.size(); ny++)
    for (int nx = 0; nx < cnrvsGrid[ny].size(); nx++)
      if (cnrvsGrid[ny][nx] == '#')
      {
        bool bReslt = false;
        for (int i = 0; i < cnvnDy.size(); i++)
          if (fnRepaint(ny + cnvnDy[i], nx + cnvnDx[i], cnrvsGrid))
            bReslt = true;

        if (!bReslt)  return 0;
      }

  return 1;
}

int main()
{
  vector<string> vsGrid;

  fnInput(vsGrid);
  if (fnGridRepaint(vsGrid))  cout << "Yes" << endl;
  else                        cout << "No"  << endl;

  return 0;
}

Measured memory_bytes: 256
import java.util.Arrays;
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        @SuppressWarnings("resource")
        Scanner sc = new Scanner(System.in);
        int k = sc.nextInt();
        int n = sc.nextInt();
        int[] a = new int[n];
        for (int i = 0 ; i < n ; i++) {
            a[i] = sc.nextInt();
        }
        int[] b = new int[n];
        for (int i = 0 ; i < n - 1 ; i++) {
            b[i] = a[i + 1] - a[i];
        }
        b[n - 1] = k - a[n - 1] + a[0];
        Arrays.sort(b);
        System.out.println(k - b[n - 1]);
    }

}

Measured memory_bytes: 74400
nim,mike,kite=map(int,input().split())
x1=0
y1=0
x2=nim
y2=mike
for i in range(kite):
    x,y,a=map(int,input().split())
    if a==1:
        x1=max(x1,x)
    elif a==2:
        x2=min(x2,x)
    elif a==3:
        y1=max(y1,y)
    elif a==4:
        y2=min(y2,y)
print(max(0,(x2-x1))*max(0,(y2-y1)))

Measured memory_bytes: 3064
using System;
using System.Diagnostics;
using System.Collections.Generic;
using System.Linq;

class Program
{
    static void Main()
    {
        string[] cin = Console.ReadLine().Split();
        int n = int.Parse(cin[0]);
        int a = int.Parse(cin[1]);
        int b = int.Parse(cin[2]);
        long ans = 0;
        for (int i = 1; i <= n; i++)
        {
            int tmp = 0;
            for (int j = 0; j < 5; j++)
            {
                tmp += i / (int)Math.Pow(10, j) % 10;
            }
            if (a <= tmp && tmp <= b) ans += i;
        }
        Console.WriteLine(ans);
    }
}

Measured memory_bytes: 13140
import java.io.*;
import java.util.*;
import java.math.*;
public class Main {
 
    public static void main(String[] args) throws java.io.IOException{
        Scanner scan = new Scanner(System.in);
        int ans=0;
        while(scan.hasNext()){
        if(isPalindrome(scan.nextLine()))ans++;
        }
        System.out.println(ans);

    }
    
    public static boolean isPalindrome(String str){
    	String[] strs = str.split("\\B");
    	
    	String restr ="";
    	for(int i=(strs.length) - 1;i>=0;i--){
    		
			restr+=strs[i]; //逆順に再結合
		}
    	
    	
    	if(restr.equals(str))return true;
    	else return false;
    }
}

Measured memory_bytes: 11000
<?php
fscanf(STDIN, "%d %d", $X, $Y);

if ((2 * $X - $Y) % 3 != 0 or (2 * $Y - $X) % 3 != 0) {
    echo 0;
    die();
}


$a = intdiv(2 * $X - $Y, 3);
$b = intdiv(2 * $Y - $X, 3);

$P = 10**9 + 7;
$N = 10000;
$finv_t = [1, 1];
$fac = [1, 1];
$inv[1] = 1;

for ($i=2; $i<$a+$b+1; $i++) {
    $fac[] = $fac[$i-1] * $i % $P;
    $inv[] = $P - $inv[$P%$i] * intdiv($P, $i) % $P;
    $finv_t[] = $finv_t[$i-1] * $inv[$i] % $P;
}


$ans = $fac[$a+$b] * ($finv_t[$a] * $finv_t[$b] % $P) % $P;
echo $ans;

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

using namespace std;

int main() {
    
    int n;
    int a[100];

    std::cin >> n;

    for (int i = 0; i < n; i++) {
        std::cin >> a[i];
    }

    reverse(a, a + n);

    for (int i = 0; i < n; i++) {
        std::cout << a[i];
        if (i != n - 1) {
            std::cout << " ";
        }
    }

    std::cout << std::endl;

    return 0;
}


Measured memory_bytes: 3104
#include <bits/stdc++.h>
#define rep(i, n) for(int i=0; i<(n); ++i)
#define rep1(i,n) for(int i=1; i<=(n); ++i)
#define repi(i,a,b) for(int i=a; i<=(b); ++i)
#define rrep(i,n) for(int i=(n-1); i>=0; --i)
#define ALL(obj) (obj).begin(), (obj).end()
#define RALL(obj) (obj).rbegin(), (obj).rend()
#define pb push_back
#define mp make_pair
#define to_s to_string
#define sz(v) (int)v.size()
#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() )
#define pr(x) cout<<(x)<<'\n'
#define debug(x) cout << #x << ": " << (x) << '\n'
#define yes "Yes"
#define no "No"
using namespace std;
using ll = long long;
using Edge = pair<int,long long>;
using Graph = vector<vector<Edge>>;
typedef pair<int,int> P;
struct aaa{aaa(){ cin.tie(0); ios::sync_with_stdio(0); cout<<fixed<<setprecision(20);};}aaaaaaa;
int MOD = 1e9 + 7;
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
ll lcm(ll a,ll b){return (a*b)/gcd(a,b);}
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};


int main(){
    int r;
    cin >> r;
    pr(r*r);
}

Measured memory_bytes: 256
def main():
    import sys
    input=sys.stdin.readline
    mod=10**9+7
    n,k=map(int,input().split())
    ans=0
    for x in range(k,n+2):
        ans=(ans+x*(n-x+1)+1)%mod
    print(ans)
if __name__ == '__main__':
    main()

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

int main(){
    int a, b, c, d;
    cin >> a >> b >> c >> d;

    while(a>0 && c>0){
        c = c-b;
        if(c<=0){
            cout << "Yes" << endl;
            break;
        }
        a = a-d;
        if(a<=0){
            cout << "No" << endl;
        }
    }
}

Measured memory_bytes: 3516
#include <stdio.h>

int main() {
  int n;
  long long int sum = 0;
  scanf("%d", &n);

  for(int i = 1; i <= n; i++) {
    if(i % 3 != 0 && i % 5 != 0) {
      sum += i;
    }
  }
  printf("%lld\n", sum);
  return 0;
}

Measured memory_bytes: 1688
#include <bits/stdc++.h>
#define lol long long
#define vec vector
using namespace std;
int main(){
    int n,m,ans=0;
    string s;
    cin>>n>>m>>s;
    for(int i=0;i<=n+m;i++){
        if(i<n){
            if(s[i]=='-'){
                ans=1;
                break;
            }
        }
        else if(i==n){
            if(s[i]!='-'){
                ans=1;
                break;
            }
        }
        else{
            if(i==n+m){
                if(s[i+1]>='0' && s[i+1]<='9' || s[i+1]=='-'){
                    ans=1;
                    break;
                }
            }
            if(s[i]=='-'){
                ans=1;
                break;
            }
        }
    }
    if(ans==1) cout<<"No\n";
    else cout<<"Yes\n";
    return(0);
}

Measured memory_bytes: 3584
import java.util.Scanner;
public class Main{
    int max,min,sa;
    
    public void solve(){
       Scanner sc=new Scanner(System.in);
        for(int i=0;i<7;i++){
             max=sc.nextInt();
             min=sc.nextInt();
             sa=max-min;
             System.out.println(sa);
        }
       }
    
    public static void main(String[] args){
        Main obj=new Main();
        obj.solve();
    }
}

Measured memory_bytes: 17336
import java.util.*;
 
public class Main{
  public static void main(String[]args){
    Scanner sc = new Scanner(System.in);
    String S = sc.nextLine();
    char a = S.charAt(0);
    char b = S.charAt(1);
    char c = S.charAt(2);
    char d = S.charAt(3);
    String ans = "";
    if(a == b || b == c || c == d){
      ans = "Bad";
    }else{
      ans = "Good";
    }
    System.out.println(ans);
  }
}

Measured memory_bytes: 23252
using System;
using System.Collections.Generic;
using System.Linq;

public static class Solution
{
    static int K;
    static int[] A;

    // [ok,ng) or (ng,ok]
    static int Search(int ok, int ng)
    {
        while (Math.Abs(ok - ng) > 1)
        {
            var mid = (ok + ng) / 2;
            if (Solve(mid))
            {
                ok = mid;
            }
            else
            {
                ng = mid;
            }
        }
        return ok;
    }

    static bool Solve(int max)
    {
        var rem = K;
        foreach (var a in A)
        {
            var div = a / max;
            if (a % max == 0)
            {
                div--;
            }

            rem -= div;
            if (rem < 0)
            {
                return false;
            }
        }
        return true;
    }

    public static void Main()
    {
        var vals = Console.ReadLine().Split(' ').Select(int.Parse).ToArray();
        var N = vals[0];
        K = vals[1];
        A = Console.ReadLine().Split(' ').Select(int.Parse).ToArray();

        var answer = Search((int)1e9, 0);
        Console.WriteLine(answer);
    }
}

Measured memory_bytes: 44732
#include<bits/stdc++.h>
#define _GLIBCXX_DEBUG
#define rep(i, n) for(int i = 0; i < (n); ++i)
using namespace std;
typedef long long ll;
template<class T> istream& operator >> (istream& s, vector<T>& v)
{ for (T& x: v) { s >> x; } return s;}
void yes(){ cout << "YES" << endl; }
void no(){ cout << "NO" << endl; }

int main(){
    int x; cin >>x;
    if(x == 3 || x == 5 || x == 7) yes();
    else no();
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define fi first
#define se second
#define all(x) (x).begin(), (x).end()
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define repp(i, a, b) for (int i = a; i <= (b); ++i)
#define repr(i, a, b) for (int i = a; i >= (b); --i)
typedef long long ll;
const int INF = 1001001001;
const ll LINF = 1001001001001001001ll;
const int MOD = 1000000007;

template <class T>
inline bool chmin(T& a, T b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}

template <class T>
inline bool chmax(T& a, T b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}

int main() {
  string w;
  cin >> w;

  sort(all(w));
  if (w.size() % 2) {
    cout << "No" << endl;
  } else {
    for (int i = 0; i < w.size(); i += 2) {
      if (w[i] != w[i + 1]) {
        cout << "No" << endl;
        return 0;
      }
    }
    cout << "Yes" << endl;
  }
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <cstdlib>
#define MAXN 100005
#define ll long long
using namespace std;
ll a[MAXN], b[MAXN], c[MAXN];
ll n;
template <typename T> inline void read(T &x) {
    char c; bool flag = 0; x = 0;
    c=getchar();
    while(c > '9' || c < '0') {if(c=='-') flag = 1; c = getchar();}
    while(c <= '9' && c >= '0'){x = x*10+c-48; c = getchar();}
    if(flag) x = x*(-1);    
}

inline void init() {
    read(n);
    for(int i = 1; i <= n; i++) read(a[i]);
    for(int i = 1; i <= n; i++) read(b[i]);
    for(int i = 1; i <= n; i++) read(c[i]);
}

inline ll searcha(ll x) {
    if(x <= a[1]) return 0;
    ll l = 1, r = n, mid;
    while(l <= r) {
        mid = (l+r) >> 1;
        if(a[mid] >= x) r = mid - 1;
        else l = mid + 1;
    }
    if(r < 0) r = 0;
    return r;
}
inline ll searchc(ll x) {
    if(x >= c[n]) return 0;
    ll l = 1, r = n, mid;
    while(l <= r) {
        mid = (l+r) >> 1;
        if(c[mid] > x) r = mid - 1;
        else l = mid + 1;
    }
    return n-r;
}
int main() {
    ll ans = 0, loc1, loc2;
    init();
    sort(a+1, a+1+n);
    sort(c+1, c+1+n);
    for(int i = 1; i <= n; i++) {
        loc1 = searcha(b[i]);
        loc2 = searchc(b[i]);
        ans += loc1*loc2;
    }
    cout << ans << "\n";
    return 0;
}


Measured memory_bytes: 2560
#include<cstdio>
#include<algorithm>
#include<cstring>
using namespace std;
namespace io{
    #define re register
    #define ll long long
    #define inf 0x3f3f3f3f
    #define il inline 
    #define in1(a) read(a)
    #define in2(a,b) in1(a),in1(b)
    #define in3(a,b,c) in2(a,b),in1(c)
    #define in4(a,b,c,d) in2(a,b),in2(c,d)
    il void readl(ll &x){
        x=0;ll f=1;char c=getchar();
        while(c<'0'||c>'9'){if(c=='-')f=-f;c=getchar();}
        while(c>='0'&&c<='9'){x=x*10+c-'0';c=getchar();}
        x*=f;
    }
    il void read(int &x){
        x=0;int f=1;char c=getchar();
        while(c<'0'||c>'9'){if(c=='-')f=-f;c=getchar();}
        while(c>='0'&&c<='9'){x=x*10+c-'0';c=getchar();}
        x*=f;
    }
}using namespace io;
#define N 105
int n;
double a[N];
int main(){
	double sum=0;
	read(n);
	for(re int i=1;i<=n;i++) scanf("%lf",&a[i]),sum+=1.0/a[i];
	printf("%lf",1.0/sum);
	return 0;
}

Measured memory_bytes: 128
#include<bits/stdc++.h>
#define ll          long long
#define pb          push_back
#define vi          vector<ll int>
#define all(a)      (a).begin(),(a).end()
#define F           first
#define S           second
#define hell        1000000007
#define lbnd        lower_bound
#define ubnd        upper_bound
#define sll            set<ll int>
#define msll        multiset<ll int>
#define io    ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
using namespace std;

ll n,val[105],w[105],maxw;
ll dp[105][100005];

ll go(ll i, ll abtak){
    if(i>n) return 0;

    if(dp[i][abtak]!=-1) return dp[i][abtak];
    ll ans=-1e17;
    ans=max(ans,go(i+1,abtak));
    if(abtak+w[i]<=maxw) ans=max(ans,val[i]+go(i+1,abtak+w[i]));

    return dp[i][abtak]=ans;
}

int main()
{
    io
    ll i,j;
    memset(dp,-1,sizeof dp);
    cin>>n>>maxw;
    for(i=1;i<=n;i++) cin>>w[i]>>val[i];

    cout<<go(1,0);

    return 0;
}

Measured memory_bytes: 82304
#include<iostream>
#include<string>
#include<cstdio>
#include<cmath>
#include<cstring>
#include<algorithm>
#include<vector>
#include<functional>
#include<iomanip>
#include<queue>
#include<cassert>
#include<tuple>
#include<set>
#include<map>
#include<list>
#include<bitset>
#include<utility>
#include<numeric>

#define pb push_back
#define mp make_pair
#define all(a)  (a).begin(),(a).end()
#define dwn(a)  (a).begin(),(a).end(), greater<int>()
#define rep(i, m) for (int i = 0; i < m; i++)
#define REP(i, n, m) for (int i = n; i < m; i++)
#define V vector<int>
#define VV vector<V>
#define VVV vector<VV>

using namespace std;

typedef long long ll;
typedef pair<int, int> P;

const int dx[4] = { 1, 0, -1, 0 };
const int dy[4] = { 0, 1, 0, -1 };
const int INF = (int)1e9;
const ll inf = (ll)1e18;
const ll MOD{ (ll)1e9 + 7 };
const long double EPS = 1e-10;

int main() {
	string s = "CODEFESTIVAL2016";
	string t;
	cin >> t;
	int cnt = 0;
	for (int i = 0; i < (int)s.size(); i++) {
		if (s[i] != t[i]) {
			cnt++;
		}
	}
	cout << cnt << endl;
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <vector>
#include <cmath>
#include <algorithm>
#include <iomanip>
#include <cstring>
#define rep(i, N) for (int i = 0; i < (int)N; i++)
using namespace std;
typedef long long ll;
const ll LLINF = 9223372036854775807;
const ll MOD = 1000000007;
const int N_MAX = pow(10,3);

bool IsPrime[N_MAX+1];

void sieve() {
  rep(i, N_MAX+1) IsPrime[i] = true;
  IsPrime[0] = false;
  IsPrime[1] = false;
  for (int i=2; i*i<=N_MAX; i++) {
    if (IsPrime[i]) {
      for (int j=2; i*j<=N_MAX; j++) {
        IsPrime[i*j] = false;
      }
    }
  }
}

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

  ll result = 1;
  for(int i=1; i<=N; i++) {
    if (!IsPrime[i]) continue;
    int tmp = N, tmp_r = 1;
    while (tmp>=1) {
      tmp /= i;
      tmp_r += tmp;
    }
    result = (result*tmp_r) % MOD;
  }
  cout << result << endl;
  return 0;
}

Measured memory_bytes: 256
n = gets.to_i
while n>0 do
	s = gets.split(nil)
	a = s[0].to_i
	b = s[1].to_i
	c = s[2].to_i
	
	d = b*b+c*c-a*a
	e = a*a+c*c-b*b
	f = a*a+b*b-c*c
	
	#print(d,e,f,"\n")
	
	flg = 0
	
	if d==0 then
		print("YES\n")
		flg=1
	end
	
	if e==0 then
		print("YES\n")
		flg=1
	end
	
	if f==0 then
		print("YES\n")
		flg=1
	end
	
	if flg==0
		print("NO\n")
	end
	
	n=n-1
end


Measured memory_bytes: 6112
#include <bits/stdc++.h>
#define rep(i, a, n) for(int i = a; i < n; i++)
#define repb(i, a, b) for(int i = a; i >= b; i--)
#define all(a) a.begin(), a.end()
#define o(a) cout << a << endl
// #define int long long
using namespace std;
typedef pair<int, int> P;
 
int n;
int a[1010];
int dp[1010][1010];
int dp2[1010] = {};

//[l, r)
int f(int l, int r){
    if(dp[l][r] != -1) return dp[l][r];
    int res = 0;
    if(l == r) res = 1;
    for(int i = l + 2; i < r; i += 2){
        if(f(l, i) == 1 && f(i, r) == 1) res = 1;
    }
    // o(1);
    if(abs(a[l] - a[r - 1]) <= 1 && f(l + 1, r - 1) == 1) res = 1;
    dp[l][r] = res;
    return res;
}

signed main(){
    while(cin >> n && n){
        rep(i, 0, n) cin >> a[i];
        // rep(i, 0, 310) rep(j, 0, 310) dp[i][j] = -1;
        // rep(i, 0, 310) dp2[i] = 0;
        memset(dp, -1, sizeof(dp));
        memset(dp2, 0, sizeof(dp2));
        rep(i, 0, n){
            dp2[i + 1] = max(dp2[i], dp2[i + 1]);
            for(int j = i + 2; j <= n; j += 2){ 
                // o(f(i, j));               
                if(f(i, j) == 1){
                    dp2[j] = max(dp2[j], dp2[i] + j - i); 
                    // o(1);
                }               
            }
        }
        cout << dp2[n] << endl;
    }
}

Measured memory_bytes: 6968
# include <iostream>
# include <algorithm>
#include <array>
# include <cassert>
#include <cctype>
#include <climits>
#include <numeric>
# include <vector>
# include <string>
# include <set>
# include <map>
# include <cmath>
# include <iomanip>
# include <functional>
# include <tuple>
# include <utility>
# include <stack>
# include <queue>
# include <list>
# include <bitset>
# include <complex>
# include <chrono>
# include <random>
# include <limits.h>
# include <unordered_map>
# include <unordered_set>
# include <deque>
# include <cstdio>
# include <cstring>
#include <stdio.h>
#include<time.h>
#include <stdlib.h>
#include <cstdint>
#include <cfenv>
#include<fstream>
//#include <bits/stdc++.h>
using namespace std;
using LL = long long;
using ULL = unsigned long long;
long long MOD = 1000000000 + 7;// ;//1000000000 + 7 998244353 924844033 1000000000 + 9;
constexpr long long INF = numeric_limits<LL>::max();
constexpr long long DINF = 1000000000000;
const double PI = acos(-1);
#define fir first
#define sec second
#define thi third
#define debug(x) cerr<<#x<<": "<<x<<'\n'
typedef pair<LL, LL> Pll;
typedef pair<double, double> Dll;
typedef pair<LL, pair<LL, LL>> Ppll;
typedef pair<LL, pair<LL, bitset<100001>>> Pbll;
typedef pair<LL, pair<LL, vector<LL>>> Pvll;
typedef pair<LL, LL> Vec2;
struct Tll { LL first, second, third; };
struct Fll { LL first, second, third, fourth; };
typedef pair<LL, Tll> Ptll;
#define rep(i,rept) for(LL i=0;i<rept;i++)
#define Rrep(i,mf) for(LL i=mf-1;i>=0;i--)
void YN(bool f) {
	if (f)
		cout << "YES" << endl;
	else
		cout << "NO" << endl;
}
void yn(bool f) {
	if (f)
		cout << "Yes" << endl;
	else
		cout << "No" << endl;
}
struct Edge { LL to, cost; };
struct edge {
	LL from, to, cost;
};
vector<vector<Edge>>g;
vector<edge>ed;
vector<Pll>pv;
map<LL, LL>ma;
set<LL>st;
int di[4][2] = { { 0,1 },{ 1,0 },{ 0,-1 },{ -1,0 } };
LL n, m, k, p, q, w, h, ans, cnt, sum, a[310000], b[310000];
string str;
bool f[11000];
char c[1100][1100];
int main() {
	cin >> w >> h;
	cin >> n >> m;
	double ss = w * h;
	ss /= 2;
	cout << ss << " ";
	if (min(n, (w - n))*h == w*min((h - m), h)&&ss== w * min((h - m), h))
		cout << 1 << endl;
	else
		cout << 0 << endl;
	return 0;
}

Measured memory_bytes: 256
#include <algorithm>
#include <cstdlib>
#include <iomanip>
#include <iostream>
#include <map>
#include <math.h>
#include <queue>
#include <stdio.h>
#include <stdlib.h>
#include <string>
#include <time.h>
#include <vector>

using namespace std;

#define ll long long
#define ld long double
#define INF 1e15

struct Edge {
    int to;
    ll cost;
    Edge(int t, ll c) {
        to = t;
        cost = c;
    }
};

int N, M;
vector<vector<Edge>> graph;

int main() {
    cin >> N >> M;
    graph = vector<vector<Edge>>(N);
    for (int i = 0; i < M; i++) {
        int a, b, c;
        cin >> a >> b >> c;
        a--;
        b--;
        graph[a].push_back(Edge(b, -c));
    }

    vector<ll> d(N, INF);
    d[0] = 0;

    for (int i = 0; i <= N * 2; i++) { //やけくそ
        for (int v = 0; v < N; v++) {
            for (Edge e : graph[v]) {
                if (d[v] != INF && d[e.to] > d[v] + e.cost) {
                    d[e.to] = d[v] + e.cost;
                    if (i >= N && e.to == N - 1) {
                        cout << "inf" << endl;
                        return 0;
                    }
                }
            }
        }
    }
    if (d[N - 1] == INF) {
        cout << "inf" << endl;
        return 0;
    }

    cout << -d[N - 1] << endl;
    return 0;
}


Measured memory_bytes: 384
n = int(input())
ln =list(map(int, input().split()))
a = 1

for i in sorted(ln):
    if a > 10**18 or a == 0:
        break
    else:
        a = a*i
        
    
    
if a> 10**18:
    print('-1')
else :
    print(a)
    

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


int A[100],B[100];
int main(){
	int n,k,x,cnt=0;
	cin >> n >> k >> x;
	
	for(int i=0;i<=n;i++){
		int ans=0;
		for(int j=0;j<k;j++){
			if(i==0) cin >> A[j];
			else{
				cin >> B[j];
				ans+=A[j]*B[j];
			}
		}
		if(i!=0 && ans+x>0) cnt++;
	}
	
	cout << cnt << endl;
	return 0;
}

Measured memory_bytes: 256