akhauriyash/Code-Regression huggingface dataset:
#include "bits/stdc++.h"

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

typedef long long LL;
typedef unsigned long UL;

using namespace std;


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

	int a, b, k;
	cin >> a >> b >> k;

	int count = 0;
	int i = min(a, b) + 1;

	while (1)
	{
		--i;
		if (a % i == 0 && b % i == 0)
		{
			++count;

			if (count == k)
			{
				cout << i << endl;
				return 0;
			}
		}
	}
}


Measured memory_bytes: 256
#include<iostream>
using namespace std;
const int MOD = 1000000007;
int main(){
	int S;
	cin>>S;
	
	int dp[S+1][S+1]={0};
	int ans=0;
	
	for(int i=0;i<=S;i++){
		for(int j=0;j<=S;j++){
			dp[j][i]=0;
		}
	}
	dp[0][0]=1;
	for(int i=0;i<S;i++){
		for(int j=0;j<=S-3;j++){
			dp[i+1][j+3]=dp[i][j]%MOD+dp[i+1][j+2]%MOD;
			dp[i+1][j+3]%=MOD;
		}
	}
	for(int i=0;i<=S;i++){
		ans+=dp[i][S]%MOD;
		ans%=MOD;
	}
	cout<<ans;
	return 0;
}

Measured memory_bytes: 19136
N = int(input())
dh = [[] for i in range(N)]
du = [[] for i in range(N)]
for i in range(N):
    t = int(input())
    for j in range(t):
        x, y = map(int, input().split())
        if y == 1: dh[i].append(x-1)
        else: du[i].append(x-1)

best = 0
def check(bitmask):
    global best
    isH = [False for i in range(N)]
    isU = [False for i in range(N)]
    
    for i in range(N):
        if bitmask % 2:
            isH[i] = True
        else:
            isU[i] = True
        bitmask //= 2
    
    valid = True
    for i in range(N):
        if isU[i]: continue
        for t in dh[i]:
            if isU[t]: valid = False
        for t in du[i]:
            if isH[t]: valid = False

    if valid: best = max(best, sum(isH))

for i in range(pow(2, N)): check(i)

print(best)


Measured memory_bytes: 47196
import java.util.*;
class Main {
	static int w;
	static int h;
	static int xs;
	static int ys;
	static int xg;
	static int yg;
	static int[][] map;
	static int co;
	public static void main(String[] args) {
		Scanner stdIn = new Scanner(System.in);
		
		while (true) {
			w = stdIn.nextInt();
			h = stdIn.nextInt();
			if (w == 0 && h == 0){
				break;
			}
			map = new int[h][w];
			xs = stdIn.nextInt();
			ys = stdIn.nextInt();
			xg = stdIn.nextInt();
			yg = stdIn.nextInt();
			int n = stdIn.nextInt();
			for (int i = 0; i < n; i++) {
				int c = stdIn.nextInt();
				int d = stdIn.nextInt();
				int x = stdIn.nextInt();
				int y = stdIn.nextInt();

				if (d == 0) {
					for (int j = y - 1; j < y + 1; j++) {
						for (int k = x - 1; k < x + 3; k++) {
							map[j][k] = c;
						}
					}
				} else {
					for (int j = y - 1; j < y + 3; j++) {
						for (int k = x - 1; k < x + 1; k++) {
							map[j][k] = c;
						}
					}
				}
			}
			boolean ans;
			co = map[ys-1][xs-1];
			ans = solv(xs - 1, ys - 1);
			System.out.println((ans) ? "OK" : "NG");
		}
	}
	
	static boolean solv(int x, int y) {
		
		if(x < 0 || y < 0 || x >= w || y >= h) return false;
		if(map[y][x] != co) return false;
		if(y == yg-1 && x == xg-1) return true;
		map[y][x] = -1;
 		if(solv(x+1,y)) return true;
		if(solv(x-1,y)) return true;
		if(solv(x,y+1)) return true;
		if(solv(x,y-1)) return true;
		
		return false;
	}
}

Measured memory_bytes: 24036
//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
#include <numeric>
typedef long long Int;
#define rep(i,a,b) for(Int i=a;i<b;++i)
#define rrep(i,a,b) for(Int i=a;i>=b;--i)
using namespace std;

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

    int A, B; cin >> A >> B;
    cout << (A+B)%24 << endl;
}


Measured memory_bytes: 256
n = int(input())
testimony = [[[], []] for _ in range(n)]
honest_a = []
for i in range(n):
    a = int(input())
    for _ in range(a):
        x, y = map(int, input().split())
        testimony[x - 1][y].append(i)
max_honest = 0


def honest(unkind: set, stack: list, s: int, max_num: int,testimony):
    if s < n:
        unkind0 = unkind.copy()
        unkind1 = unkind.copy()
        stack.append(0)
        for i in testimony[s][1]:
            unkind0.add(i)
        max_num = honest(unkind0, stack, s + 1, max_num,testimony)
        stack.pop()

        stack.append(1)
        for i in testimony[s][0]:
            unkind1.add(i)
        max_num = honest(unkind1, stack, s + 1, max_num,testimony)
        stack.pop()
        return max_num
    else:
        count = 0
        for i in range(n):
            if stack[i]:
                count += 1
                if i in unkind:
                    return max_num
        return max(count, max_num)


print(honest(set(), [], 0, 0,testimony))

Measured memory_bytes: 3064
#include <bits/stdc++.h>
#define rep(i,n) for(long long i=0; i<(n); i++)
#define int long long
#define mod 1000000007
#define F first
#define S second
#define P pair<long long,long long>
#define all(a) a.begin(),a.end()
#define INF 1000000000000000000
using namespace std;
signed main(void){
    vector<vector<int>>C(51,vector<int>(51,1));//Combination
    for(int i=1;i<51;i++){
        for(int j=1;j<i;j++){
        C[i][j]=C[i-1][j-1]+C[i-1][j];
    }
    }
    //rep(i,51)rep(j,i){
      //  cout<<i<<':'<<j<<' '<<C[i][j]<<' '<<endl;
    //}
    
    int n,a,b;cin>>n>>a>>b;
    vector<int>W(n);rep(i,n)cin>>W[i];
    sort(all(W),greater<int>());
    double sum=0;
    rep(i,a)sum+=W[i];
    cout << fixed << setprecision(10);
    cout<<sum/a<<endl;
    int com=W[0];
    int l=n;
    rep(i,n)if(W[i]<com){l=i;break;}
    if(a<n&&com!=W[a]){
        int count=0;int x;
        for(int i=0;i<n;i++){
            if(W[i]==W[a-1])count++;
        }
        rep(i,n){
            if(W[i]==W[a-1]){x=i;break;}
        }
        cout<<C[count][a-x]<<endl;
    }
    else{
        int ans=0;
        for(int i=a;i<=min(l,b);i++)ans+=C[l][i];
        cout<<ans<<endl;
    }
}

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

int main(){
  int n; cin >> n;
  vector<int> h(n); for(int i = 0;i < n;i++) cin >> h.at(i);
  
  int max = h.at(0);
  int count = 1;
  
  for(int i = 1; i < n; i++){
    if(h.at(i) >= max) {
      count++;
      max = h.at(i);
    }
  }
  cout << count <<endl;
}

Measured memory_bytes: 256
#include<stdio.h>
 
int main(){
 	char N[4];
   scanf("%s",N);
   for(int i=0;i<3;i++){
      if(N[i] =='7'){
      	printf("Yes");
         return 0;
      }     
    }
  printf("No");
  return 0; 
}


Measured memory_bytes: 1732
def main():
    num = int(input())
    data = list(map(int, input().split()))

    saikyo, hutu, dame = 0, 0, 0
    for ele in data:
        if ele % 4 == 0:
            saikyo += 1
        elif ele % 2 == 0:
            hutu += 1
        else:
            dame += 1

    flg = 1
    if saikyo + 1 < dame:
        flg = 0
    if dame == saikyo + 1 and hutu > 0:
        flg = 0

    if flg:
        print('Yes')
    else:
        print('No')




if __name__ == '__main__':
    main()

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

typedef long long LL;
typedef pair<int, int> PII;
typedef vector<int> VI;
#define MP make_pair
#define PB push_back
#define X first
#define Y second

#define FOR(i, a, b) for(int i = (a); i < (b); ++i)
#define RFOR(i, b, a) for(int i = (b) - 1; i >= (a); --i)
#define ALL(a) a.begin(), a.end()
#define SZ(a) (int)((a).size())
#define FILL(a, value) memset(a, value, sizeof(a))
#define debug(a) cout << #a << " = " << a << endl;

template<typename T> void setmax(T& x, T y) {x = max(x, y);}
template<typename T> void setmin(T& x, T y) {x = min(x, y);}

const double PI = acos(-1.0);
const LL INF = 1e9 + 47;
const LL LINF = INF * INF;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

int main()
{
	ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
	
	int n;
	cin >> n;
	int ans = 0;
	vector<vector<PII>> a(n);
	FOR(i, 0, n) 
	{
		int k;
		cin >> k;
		a[i].resize(k);
		FOR(j, 0, k) cin >> a[i][j].X >> a[i][j].Y, --a[i][j].X;
	}
	
	FOR(mask, 1, 1 << n)
	{
		bool ok = true;
		FOR(i, 0, n) if (mask & (1 << i))
			for(auto j: a[i]) if (mask & (1 << j.X)) ok &= j.Y;
			else ok &= !j.Y;
		
		if (ok) setmax(ans, __builtin_popcount(mask));
	}
	
	cout << ans << endl;
	
	cerr << "Time elapsed: " << clock() / (double)CLOCKS_PER_SEC << endl;
	return 0;
}



Measured memory_bytes: 256
// Problem : C - Count Order
// Contest : AtCoder Beginner Contest 150
// URL : https://atcoder.jp/contests/abc150/tasks/abc150_c
// Memory Limit : 1024.000000 MB 
// Time Limit : 2000.000000 milisec 
// Powered by CP Editor (https://github.com/coder3101/cp-editor2)

#include<bits/stdc++.h>
using namespace std;
 
#define int long long
#define IOS ios::sync_with_stdio(false); cin.tie(nullptr);
 
const int N = 3e5+5;
const int MOD = 1e9+7;

int32_t main()
{
    	IOS;
	int n;
	cin >> n;
	vector<int> a(n), b(n), v(n);
	for(int i = 0; i < n; i++)
		cin >> a[i];
	for(int i = 0; i < n; i++)
		cin >> b[i];
	for(int i  = 0; i <n; i++)
		v[i] = i+1;
	int cnt1 = -1, cnt2 = -1, cnt = 1;
	if(a == v)
		cnt1 = 1;
	if(b == v)
		cnt2 = 1;
	while(cnt1 < 1 or cnt2 < 1)
	{
		next_permutation(v.begin(), v.end());
		cnt++;
		if(a == v)
			cnt1 = cnt;
		if(b == v)
			cnt2  = cnt;
	}
	cout << abs(cnt1-cnt2);
    	return 0;
}

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

int main() {

    int M, D;
    cin >> M >> D;

    int count = 0;
    for (int m = 1; m <= M; m++) {
        for (int d = 22; d <= D; d++) {
            if (d/10 >= 2 && d%10 >= 2 && (d/10)*(d%10) == m) count++;
        }
    }

    cout << count << endl;

    return 0;
}


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

int main()
{
    string s;
    long sum = 0;

    cin >> s;

    for (int i = 0; i < s.size();i++)
    {
        sum += s[i] - '0';
    }

//    string s;
//    cin>>s;
//    long long sum=0;
//    for(int i=0;i<s.size();i++)sum+=s[i]-'0';
    
    if((sum % 9) == 0)
    {
        cout << "Yes" << endl;
    }
    else
    {
        cout << "No" << endl;
    }
    
    return 0;
}

Measured memory_bytes: 3692
#include <stdio.h>

int main() {
  int n, a[200005];
  long long int k;
  scanf("%d %lld", &n, &k);

  for(int i = 1; i <= n; i++) {
    scanf("%d", &a[i]);
  }
  long long int counter = 0;
  int visited[200005] = {0};
  int route[200005] = {0};
  int heiro[200005] = {0};
  int nowplace = 1;
  int flag = 0;
  visited[1] = 1;

  while(route[0] < k) {
      route[++route[0]] = nowplace;
      nowplace = a[nowplace];
      if(visited[nowplace]) {
          int count = 0;
          heiro[++heiro[0]] = route[route[0]];
          while(route[route[0] - count] != nowplace) {
              count++;
              heiro[++heiro[0]] = route[route[0] - count];
            }
            flag = 1;
            break;
            
            } else {
                visited[nowplace] = 1;
            }
    }
    
    if(flag) {
        int ans = heiro[heiro[0] - (k - route[0]) % heiro[0]];
        printf("%d\n", ans);
    } else {
        printf("%d\n", nowplace);
    }
    return 0;
}


Measured memory_bytes: 4852
use std::io::*;
use std::str::FromStr;
use std::cmp::min;

fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let stdin = stdin.lock();
    let token: String = stdin
        .bytes()
        .map(|c| c.expect("faild to read char") as char)
        .take_while(|c| !c.is_whitespace())
        .collect();
    token
        .parse()
        .ok()
        .expect("faild to parse token")
}

fn main(){
    let l: u64 = read();
    let r: u64 = read();
    if l + 2019 < r{
        println!("0");
        return;
    }
    let mut ans = 2020;
    for i in l..(r + 1) {
        for j in l..(r + 1) {
            if i == j {
                continue;
            }
            //println!("{}", (i + j) % 2019);
            ans = min(ans, (i * j) % 2019);
        }
    }
    println!("{}", ans);
}


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

int main() {
    int x,y;
    cin >> x >> y;
    for(int i=0; i<=100; i++){
        for(int j=0; j<=100; j++){
            if(i+j==x && 2*i+4*j==y){
                cout << "Yes" << endl;
                return 0;
            }
        }
    }
    cout << "No" << endl;
    return 0;

}


Measured memory_bytes: 3624
#include <iostream>
#include <string>
int main() {
	std::string str,s,t;
	std::cin >> str;
	int x = 0,y = 0;

	s = str.substr(0, 2);
	t = str.substr(2, 2);
	x = stoi(s);
	y = stoi(t);
	if (x == 0 && y == 0) {
		std::cout << "NA" << std::endl;
	}else if (x == 0 && y > 12) {
		std::cout << "NA" << std::endl;
	}
	else if(x > 12 && y == 0) {
		std::cout << "NA" << std::endl;
	}
	else if(x == 0 && y <= 12) {
		std::cout << "YYMM" << std::endl;
	}
	else if (x == 0 && y <= 12) {
		std::cout << "YYMM" << std::endl;
	}
	else if(x <= 12 && y == 0) {
		std::cout << "MMYY" << std::endl;
	}
	else if(x > 12 && y <= 12) {
		std::cout << "YYMM" << std::endl;
	}
	else if (x <= 12 && y > 12) {
		std::cout << "MMYY" << std::endl;
	}
	else if (x <= 12 && y <= 12) {
		std::cout << "AMBIGUOUS" << std::endl;
	}
	else if (x > 12 && y > 12) {
		std::cout << "NA" << std::endl;
	}
}

Measured memory_bytes: 256
# -*- coding: utf-8 -*-
from sys import stdin


# 3
# cat dog
# fish fish
# lion tiger

n = int(stdin.readline().rstrip())
p_taro = 0
p_hanako = 0

for i in range(n):
  cardsput = stdin.readline().rstrip().split()
  if (cardsput[0] == cardsput[1]):
    p_taro += 1
    p_hanako += 1
  elif (cardsput[0] < cardsput[1]):
    p_hanako += 3
  else:
    p_taro += 3

else:
  print("{0} {1}".format(p_taro, p_hanako))


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

int main() {
    int N,K;
    cin >> N >> K;
    while(K-N >=0)
    {
        cin >> K;
    }
    
    vector<int> h(N);
    for (int i = 0; i < N; i++)
        cin >> h[i];
    sort(h.begin(), h.end());

    int possMin= INT_MAX;
    vector<int> diff(N-1);
    
    for (int i = 0; i+K < N+1 ; i++)
    {    
        diff[i] = h[i+K-1] - h[i];
        possMin = min(possMin,diff[i]);
    }

    cout << possMin;
    return 0;
}

Measured memory_bytes: 1024
#include<iostream>
#include<stdio.h>
#include<vector>
#include<algorithm>
#include<set>
#include<string>
#include<map>
#include<string.h>
#include<complex>
#include<math.h>
#include<queue>
#include <functional>
#include<time.h>
#include <stack>
#include<iomanip>
using namespace std;
#define rep(i,a,n) for(int i=(a);i<(n);i++)
#define ll long long
#define llint long long int
#define sort(s) sort(s.begin(),s.end())
#define reverse(v)  reverse(v.begin(), v.end());
#define Yes(ans) if(ans)cout<<"Yes"<<endl; else cout<<"No"<<endl;
#define YES(ans) if(ans)cout<<"YES"<<endl; else cout<<"NO"<<endl;
#define hei(a) vector<a>
#define whei(a) vector<vector<a>>
#define UF  UnionFind
#define rt (a); return (a); 
#define Pint pair<int,int>
#define keta(a)  fixed << setprecision(a)
constexpr auto INF = 1000000000;
constexpr auto mod = 1000000007;
//辞書順はnext_permutation( begin( v ), end( v ) );やで！
int gcd(int a, int b) {
	if (b > a)swap(a, b);
	if (a % b == 0)return b;
	return gcd(b, a % b);
}
int ans = 0;
int s[10][10];
int k[10];
int p[10];
void bit(int m, int n, int d) {
	stack<string> st;
	st.push("");
	while (!st.empty()) {
		string now = st.top();
		st.pop();
		if (now.size() == n) {
			bool w = true;
			rep(i, 0, d) {
				int x = 0;
				rep(j, 0, k[i])if (now[s[i][j] - 1] == '1')x++;
				if (x % 2 != p[i])w = false;
			}
			if (w)ans += 1;
		}
		else {
			for (int i = m - 1; i >= 0; i--) {
				string next = now + to_string(i);
				st.push(next);
			}
		}
	}
}
;
int main() {
	llint a, b, c;
	cin >> a >> b >> c;
	ll ans = min({ a * b * (c % 2), a * c * (b % 2),c * b * (a % 2) });
	cout << ans << endl;
	return 0;

}


Measured memory_bytes: 256
import java.util.*;
public class Main {
	
	static int mod = (int)1e9+7;
	
	public static void main(String[] args) {		
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int A[] = new int[N+1];
		int B[] = new int[N];
		for(int i=0;i<N+1;i++)A[i]=sc.nextInt();
		for(int i=0;i<N;i++)B[i]=sc.nextInt();
		sc.close();
		long ans = 0;
		for(int i=0;i<N;i++) {
			if(B[i]>A[i]) {
				ans += A[i];
				int remain = B[i]-A[i];
				//余力で次の町
				int nextBeat = Math.min(A[i+1], remain);
				ans += nextBeat;
				A[i+1] -= nextBeat;

			}else {
				ans += B[i];
			}
		}
		System.out.println(ans);
	}
}

Measured memory_bytes: 64712
import sys
 
stdin = sys.stdin

mod = 1000000007
inf = 1 << 60
 
ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
ns = lambda: stdin.readline().rstrip()
nas = lambda: stdin.readline().split()

a, b = na()
print(max(a * 2 - 1, b * 2 - 1, a + b))

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

const int tonari[4][2] = {{0,1},{1,0},{0,-1},{-1,0}};

int main()
{
    int H, W;
    cin >> H >> W;
    char mp[H][W+5];
    for(int i = 0; i < H; ++i) cin >> mp[i];

    for(int i = 0; i < H; ++i) {
        for(int j = 0; j < W; ++j) {
            if(mp[i][j] == '#') {
                bool flag = false;
                for(int k = 0; k < 4; ++k) {
                    int nx = i + tonari[k][0];
                    int ny = j + tonari[k][1];
                    if(0 <= nx && nx < H && 0 <= ny && ny < W && mp[nx][ny] == '#') {
                        flag = true;
                    }
                }
                if(!flag) {
                    cout << "No" << endl; 
                    return 0;
                }
            }
        }
    }

    cout << "Yes" << endl;
    return 0;
}

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


int main(){
  string s;
  cin >>s;
  map<char,int> mp;
  for(char a='a';a<='z';++a){
    mp[a]++;
  }
  int n=s.size();
  for(int i=0;i<n;++i){
    mp[s[i]]++;
  }
  bool ok=false;
  char ans;
  for(auto p : mp){
    if(p.second==1){
      ok=true;
      ans=p.first;
      break;
    }
  }
  if(ok) cout << ans << endl;
  else cout << "None" << endl;

  return 0;
}


Measured memory_bytes: 3712
#include <iostream>
#include <string>
#include <vector>
#include <deque>
#include <queue>
#include <algorithm>
#include <set>
#include <map>
#include <bitset>
#include <cmath>
#include <functional>
#include <iomanip>
#define vll vector<ll>
#define vvv vector<vvl>
#define vvi vector<vector<int> >
#define vvl vector<vector<ll> >
#define vv(a, b, c, d) vector<vector<d> >(a, vector<d>(b, c))
#define vvvl(a, b, c, d) vector<vvl>(a, vvl(b, vll (c, d)));
#define rep(c, a, b) for(ll c=a;c<b;c++)
#define re(c, b) for(ll c=0;c<b;c++)
#define all(obj) (obj).begin(), (obj).end()
typedef long long int ll;
typedef long double ld;
//typedef __int128_t lll;
using namespace std;

int main(int argc, char const *argv[]) {
  ll a, b, c;std::cin >> a >> b >> c;
  std::cout << c << " " << a << " " << b << '\n';
  return 0;
}


Measured memory_bytes: 888
R,G,B,N = map(int,input().split())
cnt = 0
for r in range(N//R+1):
    for g in range(N//G+1):
        if  (N - r*R - g*G) < 0:
            break
        if  (N - r*R - g*G)%B == 0 :
            cnt +=1
            #print(r,g,(N - r*R - g*G)//B)
print(cnt)

Measured memory_bytes: 9184
#include <iostream>
#include <vector>
#include <algorithm>
#include <set>
#include <map>
#include <queue>
#include <assert.h>
#include <numeric>
#include <math.h>
#include <climits>

using namespace std;
#define REP(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define all(x) (x).begin(),(x).end()
typedef long long ll;
typedef unsigned long long ull;

template <typename T>
T gcd(T a, T b) {
    if(a < b) gcd(b, a);
    if (b == 1) return 1;
    T r;
    while ((r=a%b)) {
        a = b;
        b = r;
    }
    return b;
}

#define MOD (1000000000+7)

bool _less(pair<int, int> a, pair<int, int> b) {
    return a.second < b.second;
}

int main() {
    int N;
    cin >> N;
    vector<pair<int, int> > W(N);
    REP(i, N) {
        int a, b;
        cin >> a >> b;
        W[i] = make_pair(a, b);
    }
    
    sort(W.begin(), W.end(), _less);
    int t = 0;
    
    for (int i = 0; i < W.size(); i++) {
        auto w = W[i];
        t += w.first;
        if (t > w.second) {
            cout << "No" << endl;
            return 0;
        }
    }
    cout << "Yes" << endl;
}


Measured memory_bytes: 1792
#include<iostream>
    #include<string>
    #include<algorithm>
    #include<vector>
    #include<cmath>
    using namespace std;
    long long n, m, a, b, c, dist[2000];
    vector<pair<long long, long long>>x[3000];
    int main()
    {
        cin >> n >> m;
        for (int i = 0; i < m; i++)
        {
            cin >> a >> b >> c;
            a--;
            b--;
            x[a].push_back(make_pair(b, c));
        }
        for (int i = 0; i < n; i++)dist[i] = -(1LL << 60);
        dist[0] = 0;
        long long P = dist[n - 1];
        for (int i = 0; i < 8 * n; i++)
        {
            for (int j = 0; j < n; j++)
            {
                for (pair<long long, long long> k : x[j])
                {
                    dist[k.first] = max(dist[k.first], dist[j] + k.second);
                }
            }
            if (P != dist[n - 1] && i >= 5 * n)
            {
                cout << "inf" << endl;
                return 0;
            }
            P = dist[n - 1];
        }
        cout << dist[n - 1] << endl;
        return 0;
    }

Measured memory_bytes: 384
import heapq


N, M = map(int, input().split())
A = list(map(int, input().split()))

A = [a * -1 for a in A]

heapq.heapify(A)
for _ in range(M):
    a = heapq.heappop(A)
    heapq.heappush(A, (-a // 2) * (-1))

print(-sum(A))


Measured memory_bytes: 14180
#include <iostream>
#include <vector>
using namespace std;
int main(){
  int x;
  cin >> x;
  // vector<int> dp(x, -1);
  // dp[0] = 0;
  // int cur_bound = 0;
  // for(int i = 0; i < x; i++){
  //   for(int j = cur_bound; j < cur_bound + )
  // }
  int sum = 0;
  for(int i = 1; i <= x; i++){
    sum += i;
    if(sum >= x){
      cout << i << endl;
      return 0;
    }
  }
}


Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main(){
    long long l,r,i,j,a,ans=2019;
    cin >> l >> r;
    for (i=0;i<=r/2019;i++){
        a=i*2019;
        if (a>=l&&a<=r){
            if (a+2019<=r)
                ans=0;
            else
                ans=1;
            cout << ans << endl;
            return 0;
        }
    }
    for (i=l;i<r;i++){
        for (j=i+1;j<=r;j++){
            a=i*j%2019;
            if (a<ans)
                ans=a;
        }
    }
    cout << ans << endl;
    return 0;
}


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

using namespace std;

#ifdef ACMTUYO
struct RTC{~RTC(){cerr << "Time: " << clock() * 1.0 / CLOCKS_PER_SEC <<" seconds\n";}} runtimecount;
#define DBG(X) cerr << #X << " = " << X << '\n';
#else
struct RTC{};
#define DBG(X)
#endif

#define fast_io() ios_base::sync_with_stdio(false)
#define mp make_pair
#define mt make_tuple
#define pb push_back
#define eb emplace_back
#define sz(x) ((int)(x).size())
#define all(c) (c).begin(),(c).end()
#define forn(i, n) for (int i = 0; i < (n); i++)
typedef long long int number;
const int maxn = 100010;
vector<int> g[maxn];
int p[maxn];
int main() {
  int n, m;
  scanf("%d %d", &n, &m);
  for (int i = 1; i <= n; i++) {
    scanf("%d", p + i);
  }
  while (m--) {
    int x, y;
    scanf("%d %d", &x, &y);
    g[x].pb(y);
    g[y].pb(x);
  }
  vector<bool> vis(n + 1, false);
  int answer = 0;
  for (int i = 1; i <= n; i++) {
    if (!vis[i]) {
      set<int> elems, pos;
      queue<int> q;
      q.push(i);
      vis[i] = true;
      while (!q.empty()) {
        int u = q.front();
        q.pop();
        elems.insert(p[u]);
        pos.insert(u);
        for (int v: g[u]) {
          if (!vis[v]) {
            q.push(v);
            vis[v] = true;
          }
        }
      }
      for (int e: pos) {
        if (elems.count(e)) {
          answer++;
        }
      }
    }
  }
  printf("%d\n", answer);
  return 0;
}

Measured memory_bytes: 15488
#pragma region template
#include "bits/stdc++.h"
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
const long long MOD = 1e9+7, MAX = 1e18, larg = 1e5, INF = -1e9;
long long A,B,C,D,E,F,G,H,I,J,K,L,N,M,O,P,Q,S,T,U,V,W,x,y,z;
long long max_value = INF, max_index = -1;
typedef long long ll;
typedef pair<ll, ll> Pa;

template <std::int_fast64_t Modulus> class modint {
  using u64 = std::int_fast64_t;
public:
  u64 a;
  constexpr modint(const u64 x = 0) noexcept : a(x % Modulus) {}
  constexpr u64 &value() noexcept { return a; }
  constexpr const u64 &value() const noexcept { return a; }
  constexpr modint operator+(const modint rhs) const noexcept {
    return modint(*this) += rhs;
  }
  constexpr modint operator-(const modint rhs) const noexcept {
    return modint(*this) -= rhs;
  }
  constexpr modint operator*(const modint rhs) const noexcept {
    return modint(*this) *= rhs;
  }
  constexpr modint operator/(const modint rhs) const noexcept {
    return modint(*this) /= rhs;
  }
  constexpr modint &operator+=(const modint rhs) noexcept {
    a += rhs.a;
    if (a >= Modulus) {
      a -= Modulus;
    }
    return *this;
  }
  constexpr modint &operator-=(const modint rhs) noexcept {
    if (a < rhs.a) {
      a += Modulus;
    }
    a -= rhs.a;
    return *this;
  }
  constexpr modint &operator*=(const modint rhs) noexcept {
    a = a * rhs.a % Modulus;
    return *this;
  }
  constexpr modint &operator/=(modint rhs) noexcept {
    u64 exp = Modulus - 2;
    while (exp) {
      if (exp % 2) {
        *this *= rhs;
      }
      rhs *= rhs;
      exp /= 2;
    }
    return *this;
  }
};
#pragma endregion

int Left[200000];
int Right[200000];
int main() {
    cin >> N >> K >> C;
    string s;
    cin >> s;
    int count = 0;
    for(int i=0;i<s.size();i++){
        if(s[i] == 'o'){
            Left[count] = i;
            i += C;
            count++;
            if(count == K) break;
        }
    }
    count--;
    for(int i=s.size() - 1;i>=0;i--){
        if(s[i] == 'o'){
            Right[count] = i;
            i -= C;
            count--;
            if(count == -1) break;
        }
    }
    rep(i, K){
        if(Left[i] == Right[i]) cout << Left[i] + 1 << endl;
    }
} 



Measured memory_bytes: 3332
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
int main()
{
    string s,t;
    cin>>s>>t;
    int cnt=0;
    for(int i=0;i<3;i++)
    {
        if(s[i]==t[i])
            cnt++;
    }
    cout<<cnt<<'\n';
}

Measured memory_bytes: 256
#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;
  cin >> n;
 vll a(n+1);
 rep(i,0,n+1) cin >> a[i];
  
 vll s(n+2,0);
 repr(i,n+2,1) s[i-1]=s[i]+a[i-1]; 
  
 vll b(n+1);
 if(a[0]>1) {
   cout << -1 << endl; 
   return;
 }
 b[0]=1-a[0];
  
 rep(d,1,n+1){
  b[d]=min(2*b[d-1]-a[d],s[d+1]);
  if(b[d]<0) {
    cout << -1 << endl;
    return; 
  }
 }
 ll ans=0; 
 rep(i,0,n+1) {
   ans+=a[i]+b[i];
 }
  cout << ans << endl; 
}
int main(){
   cin.tie(nullptr);
  ios::sync_with_stdio(false);
  solve();
}  

Measured memory_bytes: 5500
def makelist(n, m):
    return [[0 for _ in range(m)] for _ in range(n)]

# n
# a, b = map(int, input().split())
# s = input()

N = int(input())
W = list(map(int, input().split()))
ans = sum(W)
l = 0
r = ans

for i in range(N):
    l += W[i]
    r -= W[i]
    ans = min(ans, abs(l-r))
print(ans)



Measured memory_bytes: 38384
#include<iostream>
#include<cmath>
#include<cstring>
#include<cstdio>
#include<string>
#include<algorithm>
#include<queue>
#include<stack>
#include<vector>
using namespace std;
#define ll long long
#define inf 0x3f3f3f3f3f3f3f3f
#define mod 1000000009
#define lson l,m,rt<<1
#define rson m+1,r,rt<<1|1
#define max 100010
int n;
vector<pair<int, int> >G[max];
bool visit[max];
ll d[max];
void dijkstra(int k)
{
	memset(visit, false, sizeof(visit));
	memset(d, inf, sizeof(d));
	priority_queue<pair<int, int> >PQ;
	d[k] = 0;
	visit[k] = true;
	PQ.push(make_pair(0, k));
	while (!PQ.empty())
	{
		pair<int, int>f = PQ.top();
		PQ.pop();
		int u = f.second;
		visit[u] = true;
		if (d[u]<f.first*(-1))
			continue;
		for (int j = 0; j<G[u].size(); j++)
		{
			int v = G[u][j].first;
			if (visit[v] == true)
				continue;
			if (d[v]>d[u] + G[u][j].second)
			{
				d[v] = d[u] + G[u][j].second;
				PQ.push(make_pair(d[v] * (-1), v));
			}
		}
	}
}
int main()
{
	//freopen("Text.txt","r",stdin);
	int u, v, c, q, k;
	scanf("%d", &n);
	for (int i = 1; i<n; i++)
	{
		scanf("%d%d%d", &u, &v, &c);
		G[u].push_back(make_pair(v, c));
		G[v].push_back(make_pair(u, c));
	}
	scanf("%d%d", &q, &k);
	dijkstra(k);
	for (int i = 1; i <= q; i++)
	{
		scanf("%d%d", &u, &v);
		printf("%lld\n", d[u] + d[v]);
	}
	return 0;
}

Measured memory_bytes: 8948
#include<bits/stdc++.h>
#define rep(i,n) for(int i=1;i<=n;i++)
#define chmin(x,y) x = min(x,y)
#define PI 3.14159265359
#define INF 100100100100

typedef long long ll;
using namespace std;

int main(){
  double a, b, x;
  double h;
  cin >> a >> b >> x;

  if(a*a*b/2 >= x) cout << setprecision(9) << 360 * atan((a*b*b)/(2*x))/(2*PI) << endl;
  else{
    double t = 2*(a*a*b -x)/(a*a*a);
    cout << setprecision(9) << 360 * atan(t) /(2*PI) << endl;
  }

  return 0;
}


Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main() {
    long long a , b , c;
    cin>>a>>b>>c;
    if(c == 1){
        cout<<(b - a + 1)<<"\n";
        return 0;
    }
    long long f = b / c, s = (a - 1) / c;
    long long ans = f - s;
    if(a == 0)ans++;
    cout<<ans<<"\n";
}


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

using namespace std;

long long a[I], b[I], n;

int main()
{
    cin >> n;
    for(int i = 1; i <= n; i ++){
        cin >> a[i];
    }
    for(int i = 2; i <= n; i ++){
        if(i == 2) b[i] = abs(a[i] - a[i - 1]) + b[i - 1];
        else b[i] = min(abs(a[i] - a[i - 2]) + b[i - 2], abs(a[i] - a[i - 1]) + b[i - 1]);
    }
    cout << b[n] << endl;
    return 0;
}


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

#define all(v) v.begin(), v.end()
typedef long long ll;
const int INT_INF = 1e9;
const ll INF = 1LL << 30;

int main() {
    int n, k; cin >> n >> k;
    map<int, int> s;
    for(int i = 0; i < k; i++){
        int d; cin >> d;
        for(int j = 0; j < d; j++){
            int k; cin >> k;
            s[k]++;
        }
    }
    cout << n - s.size() << endl;
}


Measured memory_bytes: 3632
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <queue>
#include <functional>
#include <cstring>
#include <cstdlib>
#include <cmath>
using namespace std;

int main() {
    const int M = 1000000007;
    int n;
    cin >> n;
    vector<int> x(n);
    for (int i = 0; i < n; i++) {
        cin >> x[i];
    }

    int64_t r = 1;
    int d = 0;
    for (int i = 0; i < n; i++) {
        int j = i - d;
        if (i == n - 1) {
            for (int k = j; k >= 0; k--) {
                r = (r * (k + 1)) % M;
            }
            break;
        }
        if (x[i] <= j * 2) {//次のやつがこのターンではゴールできない
            r = (r * (j + 1)) % M;
            d++;
            j--;
        }
    }

    cout << r << endl;

    return 0;
}


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

int main() {
  int a, b, c, d;
  cin >> a >> b >> c >> d;
  
  int taka = 0, ao = 0;
  while (c > 0) {
    c -= b;
    taka++;
  }
  
  while (a > 0) {
    a -= d;
    ao++;
  }
  
  if (taka <= ao)
    cout << "Yes" << endl;
  else
    cout << "No" << endl;
  
  return 0;
}

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

using namespace std;

vector < int > g[10];

void dfs(int v, set < int > s, int cnt)
{
    s.insert(v);
    cnt++;
    
    for (int i = 0; i < (int)g[v].size(); i++) 
    {
        int to = g[v][i];
        
        if (s.find(to) == s.end())
        {
            s.insert(to);
            dfs(to, s, cnt);
            s.erase(to);
        }
    }
    
    if (cnt == 4)
    {
        cout << "YES";
        exit(0);
    }
}

int main()
{   
    for (int i = 1; i <= 3; i++) 
    {
        int x, y; cin >> x >> y; 
        
        g[x].push_back(y);
        g[y].push_back(x);
    }
    
    for (int i = 1; i <= 4; i++)
    {
        set < int > s;
        
        dfs(i, s, 0);
    }
    
    cout << "NO";
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
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;
}
typedef long long int ll;

#define ALL(v) (v).begin(), (v).end()
#define RALL(v) (v).rbegin(), (v).rend()
#define endl "\n"
const double EPS = 1e-7;
const int INF = 1 << 30;
const ll LLINF = 1LL << 60;
const double PI = acos(-1);
const int MOD = 1000000007;
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};

//-------------------------------------

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    string s;
    cin >> s;
    if(s[2] == s[3] && s[4] == s[5]) {
        cout << "Yes" << endl;
    } else {
        cout << "No" << endl;
    }
}

Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<cstring>
#include<vector>
#include<algorithm>
#include<cmath>
using namespace std;
#define INF 0x3f3f3f3f
const int maxn=110;
#define _rep(i,a,b) for(int i=(a);i<=(b);++i)
int n,a[maxn],ans=INF;

int main()
{
    #ifdef __LOCAL__
        freopen("1.in","r",stdin);
        freopen("1.out","w",stdout);
    #endif
    cin>>n;
    _rep(i,1,n)
        cin>>a[i];
    _rep(i,1,100)
    {
        int num=0;
        _rep(j,1,n)
            num+=(a[j]-i)*(a[j]-i);
        ans=min(ans,num);
    }
    cout<<ans;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <set>
#include <queue>
#include <stack>
#include <tuple>
#include <cmath>
#include <iomanip>
#include <map>
#include <cstring>
#include <functional>
#include <cctype>
#include <locale>
#define ll long long
#define rep(i,n) for(int i=0;i<(n);i++)
#define rrep(i,n) for(int i=n-1;i>=0;i--)
#define fi first
#define se second
#define pb push_back
#define ALL(a) (a).begin(),(a).end()
using namespace std;
template<typename T1,typename T2> inline void chmin(T1 &a,T2 b){if(a>b) a=b;}
template<typename T1,typename T2> inline void chmax(T1 &a,T2 b){if(a<b) a=b;}
typedef pair<int,int> P;
typedef pair<long long,long long> Pll;
#define fout(num) cout << fixed << setprecision(20) << (num) << endl
//s[i]=tolower(s[i]); islower(s[i]); cout << tolower(s[i])はバグ
//vector<vector<ll>> dp(n,vector<ll>(n))
//2-dim:vector<vector<Type>> vv(n, vector<Type>(m, d));
//3-dim:vector<vector<vector<Type>>> vvv(n, vector<vector<Type>>(m, vector<Type>(l, d)));
struct Unionfind{
    vector<int> data;
    Unionfind(int size):data(size, -1) {}
    bool unite(int x, int y){
        x=root(x);
        y=root(y);
        if(x!=y){
            if(data[y] < data[x]) swap(x, y);
            data[x] += data[y];
            data[y] = x;
        }
        return x!=y;
    }
    bool same(int x, int y){
        return root(x) == root(y);
    }
    int root(int x){
        return (data[x] < 0) ? x : data[x]=root(data[x]);
    }
    int size(int x){
        return -data[root(x)];
    }
};
signed main(){
    std::cin.tie(nullptr);
    std::ios_base::sync_with_stdio(false);
    int n,q; cin >> n >> q;
    Unionfind uni(n);
    rep(i,q){
        int x,a,b; cin >> x >> a >> b;
        if(x==0){
            uni.unite(a,b);
        }else{
            cout << (uni.same(a,b)?1:0) <<  endl;
        }
    }
}




Measured memory_bytes: 3864
#include <iostream>
#include <algorithm>
#include <string>
using namespace std;
typedef long long ll;


int main(void){
  int k,i,j,dp[2][105][4]={};
  string n;
  
  cin >> n >> k;
  
  dp[1][0][0]=1;
  for (i=1;i<=n.size();i++){
    dp[0][i][0]=1;
    for (j=1;j<=3;j++){
      if (n[i-1]!='0') dp[1][i][j]=dp[1][i-1][j-1];
      else dp[1][i][j]=dp[1][i-1][j];
      dp[0][i][j]+=dp[0][i-1][j]+dp[0][i-1][j-1]*9;
      if (n[i-1]!='0') dp[0][i][j]+=dp[1][i-1][j]+dp[1][i-1][j-1]*max(0,n[i-1]-'1');
    }
  }
  
  cout << dp[0][n.size()][k]+dp[1][n.size()][k] << endl;
  
  return 0;
}

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

using namespace std;
using namespace atcoder;
 
#ifdef DEBUG
    #include "debug.h"
    #define dump(...)                                                              \
        DUMPOUT << "  " << string(#__VA_ARGS__) << ": "                            \
                << "[" << to_string(__LINE__) << ":" << __FUNCTION__ << "]"        \
                << endl                                                            \
                << "    ",                                                         \
            dump_func(__VA_ARGS__)
#else
    #define dump(...)
#endif

template<typename T>
vector<T> make_v(size_t a){return vector<T>(a);}

template<typename T,typename... Ts>
auto make_v(size_t a,Ts... ts){
  return vector<decltype(make_v<T>(ts...))>(a,make_v<T>(ts...));
}

template<typename T,typename V>
typename enable_if<is_class<T>::value==0>::type
fill_v(T &t,const V &v){t=v;}

template<typename T,typename V>
typename enable_if<is_class<T>::value!=0>::type
fill_v(T &t,const V &v){
  for(auto &e:t) fill_v(e,v);
}

#define int long long
#define rep(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define YES puts("YES")
#define Yes puts("Yes")
#define NO  puts("NO")
#define No  puts("No")
#define ALL(v) (v).begin(), (v).end()
int gcd(int a, int b) { return b ? gcd(b, a % b) : a; }
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 (a>b) { a=b; return 1; } return 0; }

/*
#define mod 1000000007 /*/
#define mod 998244353 //*/

typedef pair<int, int> P;
//#define INF (1LL<<60)

using mint = modint998244353;

struct S{
    mint val;
    int size;
};
using F = int;

const S INF = {8e18,0};
const F ID = 8e18;

mint tenpower[200001], ones[200001];

S op(S a, S b){ return {a.val * tenpower[b.size] + b.val, a.size + b.size}; }
S e(){ return {0,0}; }
S mapping(F f, S x){
    if(f==ID) return x;
    return {ones[x.size]*f, x.size};
}
F composition(F f, F g){ return (f == ID ? g : f); }
F id(){ return ID; }

void solve(){
    
    int N, Q;
    cin >> N >> Q;
    
    tenpower[0] = 1;
    ones[0] = 0;
    rep(i,200001){
        tenpower[i+1] = tenpower[i] * 10;
        ones[i+1] = ones[i] * 10 + 1;
    }
    vector<S> v(N, {1,1});
    atcoder::lazy_segtree<S, op, e, F, mapping, composition, id> seg(v);
    
    while(Q--){
        int L, R, D;
        cin >> L >> R >> D;
        L--; R--;
        seg.apply(L, R+1, D);
        cout << seg.prod(0, N).val.val() << endl;;
    }
    
    
}


signed main(){
    cout << fixed << setprecision(18);
    cerr << fixed;
    solve();
}


Measured memory_bytes: 18348
//#if 1
//#include"pch.h"
//#define _CRT_SECURE_NO_WARNINGS
//#endif
#include<stdio.h>
#include<stdlib.h>
#include<cmath>
#include<math.h>
#include<string>
#include<string.h>
#include<algorithm>
#include<iostream>
using namespace std;
int main() {
	long long N, K,ans = 0;
	long long d[200000];
	cin >> N >> K;
	for (int i = 0; i < K; i++) {
		d[i] = 0;
	}
	for (int i = 1; i <= N; i++) {
		d[i%K]++;
	}
	ans += d[0] * d[0] * d[0];
	for (int i = 1; i < K; i++) {
		if ((2 * K - 2 * i) == K)ans += d[i] * d[K - i] * d[K - i];
	}
	cout << ans << endl;
	return(0);
}

Measured memory_bytes: 1792
#include <iostream>
#include <cmath>
#include <algorithm>
#include <bitset>
#include <iomanip>
#include <cstdio>
#include <new>
#include <vector>
#include <cstdlib>

using namespace std;

int fanc(int N) {
	while (N >= 100) {
		N -= 100;
	}
	while (N >= 10) {
		N -= 10;
	}
	return N;
}

int main() {

	int N;
	cin >> N;


	int x = fanc(N);

	if (x == 9) {
		cout << "hon" << endl;
	}
	else if (x == 8) {
		cout << "pon" << endl;
	}
	else if (x ==7) {
		cout << "hon" << endl;
	}
	else if (x ==6) {
		cout << "pon" << endl;
	}
	else if (x == 5) {
		cout << "hon" << endl;
	}
	else if (x == 4) {
		cout << "hon" << endl;
	}
	else if (x == 3) {
		cout << "bon" << endl;
	}
	else if (x == 2) {
		cout << "hon" << endl;
	}
	else if (x == 1) {
		cout << "pon" << endl;
	}
	else if (x == 0) {
		cout << "pon" << endl;
	}

}

Measured memory_bytes: 3600
#include <stdio.h>

int r, c;
int tange_sakura[100][100];

int main(void) {
	int i, j;
	int oohasi_ayaka, minase_inori = 0;
	if (scanf("%d%d", &r, &c) != 2) return 1;
	for (i = 0; i < r; i++) {
		for (j = 0; j < c; j++) {
			if (scanf("%d", &tange_sakura[i][j]) != 1) return 1;
		}
	}
	for (i = 0; i < r; i++) {
		oohasi_ayaka = 0;
		for (j = 0; j < c; j++) {
			printf("%d ", tange_sakura[i][j]);
			oohasi_ayaka += tange_sakura[i][j];
		}
		printf("%d\n", oohasi_ayaka);
	}
	for (j = 0; j < c; j++) {
		oohasi_ayaka = 0;
		for (i = 0; i < r; i++) oohasi_ayaka += tange_sakura[i][j];
		printf("%d ", oohasi_ayaka);
		minase_inori += oohasi_ayaka;
	}
	printf("%d\n", minase_inori);
	return 0;
}




Measured memory_bytes: 2112
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int, int> P;
typedef pair<ll, ll> Pll;
using Graph = vector<vector<int>>;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define Rep(i, k, n) for (int i = k; i < (int)(n); i++)
#define RRep(i, k, n) for (int i = k; i > (int)(n); i--)
#define COUT(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << endl
#define ALL(a)  (a).begin(),(a).end()
#define rALL(a)  (a).rbegin(),(a).rend()
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; }
const long long INF = 1LL << 60;
const int MOD = 1000000007;
const double PI = acos(-1); //3.14~
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};

struct UnionFind {
    vector<int> par;

    UnionFind(int n) : par(n, -1) { }
    void init(int n) { par.assign(n, -1); }

    int root(int x) {
        if (par[x] < 0) return x;
        else return par[x] = root(par[x]);
    }

    bool issame(int x, int y) {
        return root(x) == root(y);
    }

    bool merge(int x, int y) {
        x = root(x); y = root(y);
        if (x == y) return false;
        if (par[x] > par[y]) swap(x, y); // merge technique
        par[x] += par[y];
        par[y] = x;
        return true;
    }

    int size(int x) {
        return -par[root(x)];
    }
};

int main()
{
    ll n, m; cin >> n >> m;
    vector<ll> A(m), B(m);
    rep(i, m)
    {
        cin >> A[i] >> B[i]; A[i]--; B[i]--;
    }

    UnionFind uf(n); // 根
    ll cur = n * (n - 1) / 2;
    vector<ll> ans;
    rep(i, m)
    {
        ans.push_back(cur);

        int a = A[m - 1 - i], b = B[m - 1 - i];
        if (uf.issame(a, b)) continue;

        ll sa = uf.size(a), sb = uf.size(b);
        cur -= sa * sb;
        uf.merge(a, b);
    }
    reverse(ALL(ans));
    rep(i, ans.size()) cout << ans[i] << endl;
}

Measured memory_bytes: 4212
/**
 *    author:  tourist
 *    created: 16.01.2020 23:11:52       
**/
#include <bits/stdc++.h>

using namespace std;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int a, b;
  cin >> a >> b;
  cout << (a - 1) * (b - 1) << '\n';
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main() {
    int n, m;
    cin >> n >> m;

    long long ac = 0;
    long long wa = 0;

    vector<long long> wrong(n, 0);
    vector<bool> isac(n, 0);

    for(int i = 0; i < m; ++i) {
        int p;
        string s;
        cin >> p >> s;

        --p;

        if(!isac[p]) {
            if(s == "AC") {
                isac[p] = true;
                wa += wrong[p];
                ac++;
            } else {
                wrong[p]++;
            };
        };
    }
    cout << ac << " " << wa << endl;
    return 0;
}


Measured memory_bytes: 1024
module IntMap = Map.Make (struct
  type t = int
  let compare = compare
end)

let () = Scanf.scanf "%d\n" @@ fun n ->
  let es = Array.make n [] in
  let xs =
    if n = 1 then
      Scanf.scanf "\n%d\n" @@ Array.make 1
    else begin
      for i = 1 to n - 1 do
        Scanf.scanf "%d " @@ fun p ->
          es.(p - 1) <- i :: es.(p - 1)
      done;
      Array.init n @@ fun _ -> Scanf.scanf "%d " @@ fun x -> x
    end in
  let rec solve v =
    let xys = List.map (fun u -> xs.(u), solve u) es.(v) in
    let most = List.fold_right (fun (x, y) -> ( + ) @@ max x y) xys 0 in
    let least = List.fold_right (fun (x, y) -> ( + ) @@ min x y) xys 0 in
    if xs.(v) < least then raise Not_found
    else IntMap.fold (fun _ -> min)
      (List.fold_left (fun m (w, v_) ->
        let le, _, _ = IntMap.split (xs.(v) - least - w + 1) m in
        IntMap.fold (fun w' v' m ->
          IntMap.add (w + w')
            (max (v_ + v') @@
              try IntMap.find (w + w') m
              with Not_found -> min_int) m) le m) (IntMap.singleton 0 most) @@
        List.map (fun (x, y) -> abs (x - y), ~- (abs (x - y))) xys) max_int in
  print_endline @@
  try ignore (solve 0); "POSSIBLE"
  with Not_found -> "IMPOSSIBLE"



Measured memory_bytes: 4992
import java.util.Scanner;
public class Main {
	public static void main(String[]args){
		Scanner sc = new Scanner(System.in);
		int p1 = sc.nextInt();
		int p2 = sc.nextInt();
		int p3 = sc.nextInt();
		int j1 = sc.nextInt();
		int j2 = sc.nextInt();
		int pmin = 0;
		int jmin = 0;
		int set = 0;
		pmin = Math.min(p1, p2);
		pmin = Math.min(pmin, p3);
		jmin = Math.min(j1, j2);
		set = pmin+jmin-50;
		System.out.println(set);
	}
}

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

typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;

typedef vector<int> vi;
typedef pair<int, int> ii;
typedef vector<ii> vii;
typedef vector<vi> vvi;
typedef vector<vii> vvii;

#define INF INT_MAX
#define MOD 1000000007
#define all(x) x.begin(), x.end()

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

    string A; cin >> A;
    if(A[0] != A[1] or A[1] != A[2] or A[0] != A[2]) cout << "Yes" << endl;
    else cout << "No" << endl;

    return 0;
}

Measured memory_bytes: 256
#include<algorithm>
#include<cstdio>
#include<iostream>
#include<cstdlib>
#include<cmath>
using namespace std;
int main()
{
	int n,m;
	scanf("%d%d",&n,&m);
	int x=sqrt(m);
	int ans=0;
	for(int i=x;i>=1;i--)
	{
		if(m%i==0)
		{
			if((m/i)>=n)
				ans=max(ans,i);
			if((i)>=n)
				ans=max(ans,m/i);
		}
	}
	printf("%d",ans);
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <numeric>
#include <set>
#include <map>
#include <string>
#include <stack>
#include <queue>
#include <cmath>
#include <cstdio>
#include <istream>
#include <sstream>
#include <iomanip>
using namespace std;

typedef ostringstream oss;
typedef istringstream iss;

struct Node{
	int dis;
	int p;
};

bool myless(const Node& n1, const Node& n2) {
	return n1.p > n2.p;
}

int main(void) {
	int N, money;
	while (cin >> N >> money, N) {
		vector<Node> node(N);
		for (int i = 0; i < N; i++) {
			cin >> node[i].dis >> node[i].p;
		}

		sort(node.begin(), node.end(), myless);
		
		for (int i = 0; i < N; i++) {
			if (!money) {
				break;
			}
			if (money > node[i].dis) {
				money -= node[i].dis;
				node[i].dis = 0;
			}else {
				node[i].dis -= money;
				money = 0;
			}
		}

		int sump = 0;
		for (int i = 0; i < N; i++) {
			sump += node[i].dis * node[i].p;
		}
		cout << sump << endl;
	}

	return 0;
}

Measured memory_bytes: 1292
n, m = map(int, input().split())
h = list(map(int, input().split()))
li = list(range(1,n+1))
ab = [list() for _ in range(m)]

p = []

ih = dict(zip(li, h))

for i in range(m):
    a, b = map(int,input().split())
    c = ih[a]
    d = ih[b]
    if c>d:
        p.append(b)
    elif d>c:
        p.append(a)
    else:
        p.append(a)
        p.append(b)

print(n-len(set(p)))

Measured memory_bytes: 36060