akhauriyash/Code-Regression huggingface dataset:
// https://beta.atcoder.jp/contests/arc095/submissions/2351037

#include<iostream>
#include<string>
using namespace std;

int pair_h[12], pair_w[12];
int H, W;
string S[12];
bool solo_h, solo_w;

bool able_w(int w){
    if(w == W){
        return true;
    }else if(pair_w[w] != -1){
        return able_w(w + 1);
    }else{
        bool ret = false;
        for(int i = w + 1; i < W; i++){
            if(pair_w[i] != -1){
                continue;
            }

            bool is_pair = true;
            for(int j = 0; j < H; j++){
                if(S[j][w] != S[pair_h[j]][i]){
                    is_pair = false;
                }
            }
            if(is_pair){
                pair_w[w] = i;
                pair_w[i] = w;

                ret = ret || able_w(w + 1);

                pair_w[i] = pair_w[w] = -1;
            }
        }
        if(W % 2 != 0 && !solo_w){
            bool is_pair = true;
            for(int j = 0; j < H; j++){
                if(S[j][w] != S[pair_h[j]][w]){
                    is_pair = false;
                }
            }
            if(is_pair){
                solo_w = true;
                pair_w[w] = w;
                ret = ret || able_w(w+1);
                pair_w[w] = -1;
                solo_w = false;
            }
        }
        return ret;
    }
}

bool search_h(int h){
    if(h == H){
        return able_w(0);
    }else if(pair_h[h] != -1){
        return search_h(h+1);
    }else{
        bool ret = false;

        for(int i = h + 1; i < H; i++){
            if(pair_h[i] != -1){
                continue;
            }

            pair_h[h] = i;
            pair_h[i] = h;

            ret = ret || search_h(h + 1);

            pair_h[h] = -1;
            pair_h[i] = -1;
        }

        if(H % 2 != 0 && !solo_h){
            pair_h[h] = h;
            solo_h = true;
            ret = ret || search_h(h + 1);
            pair_h[h] = -1;
            solo_h=false;
        }
        return ret;
    }
}
            


bool able_to_symmetrize(){
    return search_h(0);
}

int main(){
    cin >> H >> W;
    for(int h = 0; h < H; h++){
        cin >> S[h];
    }

    for(int i = 0; i < 12; i++){
        pair_h[i] = -1;
        pair_w[i] = -1;
    }

    cout << (able_to_symmetrize() ? "YES" : "NO" ) << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <map>
#include <string>
#include <list>
#include <algorithm>

using namespace std;

typedef unsigned long long u64;

int gcd(int a, int b)
{
	while (b != 0)
	{
		int r = a % b;
		a = b;
		b = r;
	}

	return a;
}

int main()
{
	u64 n, m;
	string s, t;

	cin >> n >> m;
	cin >> s >> t;
	
	int g = gcd(n, m);
	
	u64 l = n * m / g;
	u64 p = l / n;
	u64 q = l / m;
	u64 v = p * q;

	for (u64 i = 0; i < l; i += v )
	{
		if (s[i / p] == t[i / q])
		{
			continue;
		}

		cout << -1 << endl;
		return 0;
	}

	cout << l << endl;

	return 0;
}

Measured memory_bytes: 512
from collections import namedtuple

Data = namedtuple("Data", "name weight limit")


def search(food_list, select_list, total_weight):
    if len(food_list) == 0:
        return select_list

    limit = select_list[len(select_list) - 1].limit

    for lp, food in enumerate(food_list):

        if total_weight <= limit:

            select_list.append(food)
            food_list.remove(food)
            total_weight -= food.weight

            search(food_list, select_list, total_weight)

            if len(food_list) == 0:
                return select_list
            else:
                select_list.pop()
                food_list.insert(lp, food)
                total_weight += food.weight

    return None


while True:
    input_count = int(input())

    if input_count == 0:
        break

    input_data = [input().split(" ") for _ in range(input_count)]
    input_data = [Data(item[0], int(item[1]), int(item[2])) for item in input_data]

    input_data.sort(key=lambda x: (x.weight, x.limit), reverse=True)

    total_weight = sum([item.weight for item in input_data])

    result = search(input_data, [Data("sentinel", 0, 999999)], total_weight)
    del result[0]

    output = [item.name for item in result]
    print("\n".join(output))



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

using ll = long long;
#define rep(i,n) for(int i = 0; i < (n); i++)
#define rrep(i,n) for(int i = (n); i > 0; i--)
#define print(n) cout << n << endl

int main(){
    cin.tie(0);
    ios_base::sync_with_stdio(false);
    
    int n;
    cin >> n;
    ll ans = 0;
    while(n>=500){
        ans += 1000;
        n -= 500;
    }
    while(n>=5){
        ans += 5;
        n -= 5;
    }
    print(ans);
    return 0;
}

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

int main(){
  int n,a,b;
  cin >> n >> a >> b;
  if(n*a > b){
    cout << b << endl;
  }
  else if(n*a < b){
    cout << n*a << endl;
  }
  else{
    cout << n*a << endl;
  }
}

Measured memory_bytes: 256
package main

import "fmt"

func main() {
	var n, a, b int
	fmt.Scanf("%d %d %d", &n, &a, &b)
	k := n / (a + b)
	l := n % (a + b)
	blue := k * a
	if l >= a {
		blue += a
	} else {
		blue += l
	}
	fmt.Println(blue)
}


Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REP(i,n) FOR(i,0,n)
#define ALL(v) (v).begin(),(v).end()
#define fi first
#define se second
template<typename A, typename B> inline bool chmax(A &a, B b) { if (a<b) { a=b; return 1; } return 0; }
template<typename A, typename B> inline bool chmin(A &a, B b) { if (a>b) { a=b; return 1; } return 0; }
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<int, pii> pip;
const ll INF = 1e9+100;
const ll MOD = 1e9+7;
const double EPS  = 1e-10;
const bool debug = 0;
//---------------------------//

int N;
bool c[2][13];

int main(){
	cin >> N;
	
	while (N--) {
		memset(c, 0, sizeof(c));
		FOR(i, 1, 14) if (i != 7) c[1][i] = true;
		REP(i, 6) {
			int f; scanf("%d", &f);
			c[0][f] = true;
			c[1][f] = false;
		}
		
		if (c[0][1] && c[0][13]) puts("no");
		else if (!c[0][1] && !c[0][13]) puts("yes");
		else {
			bool turn = false; // false: ??????, true: ??????
			int l = 6, r = 8;
			while (l >= 1 && r <= 13) {
				if (turn ^ c[0][1]) { // ?????????????????????
					if (c[turn][l]) l--; 
					else if (c[turn][r]) r++;
				}
				else { // ?????????????????????
					if (c[turn][r]) r++;
					else if (c[turn][l]) l--;
				}
				
				turn ^= 1;
			}
			
			if ((c[0][1] && l == 0) || (c[0][13] && r == 14)) puts("yes");
			else puts("no");
		}
	}
	return 0;
}

Measured memory_bytes: 3164
#include<iostream>
using namespace std;
#define rep(i,a) for(int i = 0 ; i < a ; i ++)
#define loop(i,a,b) for(int i = a ; i < b ; i ++)
const int M = (1e6);
int p[M];
void isPrime(){
  rep(i,M)p[i] = true;
  p[0] = p[1] = false;
  loop(i,2,M){
    if(p[i])
      for(int j = i + i ; j < M ; j += i)
	p[j] = false;
  }
}
int main(void){
  isPrime();
  int n;
  while(cin>>n){
    int i = n - 1;
    while(!p[i--]);cout<<++i<<" ";
    i = n + 1;
    while(!p[i++]);cout<<--i<<endl;
  }
}

Measured memory_bytes: 5064
#include <iostream>
#include <vector>
#include <cmath>

using namespace std;
int main(void){
  int n;
  cin >> n;
  vector <int> a(n);
  vector <int> b(n,0);
  for(int i=0; i<n; i++){
    cin >> a[i];
    b[a[i]]++;
  }


  if(n%2==1){
    if(b[0]!=1){cout << 0 << endl;return 0;}
    for(int i=1; i<n; i++){
      if(i%2==1){
        if(b[i]!=0){cout << 0 << endl;return 0;}
      }else{
        if(b[i]!=2){cout << 0 << endl;return 0;}
      }
    }
  }

  if(n%2==0){
    for(int i=0; i<n; i++){
      if(i%2==1){
        if(b[i]!=2){cout << 0 << endl;return 0;}
      }else{
        if(b[i]!=0){cout << 0 << endl;return 0;}
      }
    }
  }
  long long ans=1;

  for(int i=0; i<n/2; i++){
    ans*=2;
    ans%=1000000007;
  }
  cout << ans << endl;

}


Measured memory_bytes: 1024
(defstruct p (i 0 :type integer) (city nil :type symbol) (point 0 :type integer))
(defparameter *initial* (make-p))
(defun f ()
  (declare (optimize (speed 3) (safety 0)))
  (let* ((n (read))
         (arr (make-array `(,n) :element-type 'p :initial-element *initial* :adjustable nil))
         (_ (loop #:for i #:from 1 to n
                  #:for city symbol = (read)
                  #:for point integer = (read)
                  #:do (setf (svref arr (1- i))
                             (make-p :i i :city city :point point))))
         (sorted1 (sort arr #'> :key #'p-point))
         (sorted2 (stable-sort sorted1 #'string< :key #'p-city)))
    (loop #:for p #:across sorted2
          #:do (progn (princ (p-i p)) (terpri)))))
(f)

Measured memory_bytes: 18660
# cook your dish here
import sys,math
try:sys.stdin,sys.stdout=open('input.txt','r'),open('out.txt','w')
except:pass
from sys import stdin,stdout;mod=int(1e9 + 7);from statistics import mode
from collections import *;from math import ceil,floor,inf,factorial,gcd,log2,sqrt,log
ii1=lambda:int(stdin.readline().strip())
is1=lambda:stdin.readline().strip()
iia=lambda:list(map(int,stdin.readline().strip().split()))
isa=lambda:stdin.readline().strip().split()
# print('{:.3f}'.format(1),round(1.123456789,4))
# sys.setrecursionlimit(500000)
def lcm(a,b): return (a*b)//gcd(a,b)
def setbits(n):return bin(n).count('1')
def resetbits(n):return bin(n).count('0')
def modinv(n,p):return pow(n,p-2,p)
def ncr(n,r):
    num,den=1,1;r=min(n,n-r)
    for i in range(r):num*=(n-i);den*=(i+1)
    return num//den
def ncr_p(n, r, p):
    num,den=1,1;r=min(r,n-r)
    for i in range(r):num = (num * (n - i)) % p ;den = (den * (i + 1)) % p
    return (num * modinv(den,p)) % p
def isPrime(num) :
    if num<=1:return False
    if num==2 or n==3:return True
    if (num % 2 == 0 or num % 3 == 0) :return False
    m = int(num**0.5)+1
    for i in range(5,m,6):
        if (num % i == 0 or num % (i + 2) == 0) :return False
    return True
def bin_search(s, low, high, val):
    while low <= high:
        mid = low + (high - low) // 2;
        if s[mid] == val:return mid
        elif s[mid] < val:low = mid + 1
        else:high = mid - 1
    return -1
def sumofdigit(num):
    count=0;
    while num : count+=num % 10;num //= 10;
    return count;
def inputmatrix():
    r,c=iia();mat=[0]*r;
    for i in range(r):mat[i]=iia();
    return r,c,mat;
def prefix_sum(n,s):
    for i in range(1,n):s[i]+=s[i-1]
    return s;
def binomial(n, k):
    if 0 <= k <= n:
        ntok = 1;ktok = 1
        for t in range(1, min(k, n - k) + 1):ntok *= n;ktok *= t;n -= 1
        return ntok // ktok
    else:return 0
def divisors(n):
    res = [];
    for i in range(1,ceil(sqrt(n))+1):
        if n%i == 0:
            if i==n//i:res.append(i)
            else:res.append(i);res.append(n//i)
    return res;

# coding start heres
MAX = ii1()
factor = [0]*(MAX + 1);
def primefactor():
    factor[1] = 1;
    for i in range(2,MAX):
        factor[i] = i;
    for i in range(4,MAX,2):
        factor[i] = 2;
    i = 3;
    while(i * i < MAX):
        if (factor[i] == i):
            j = i * i;
            while(j < MAX):
                if (factor[j] == j):
                    factor[j] = i;
                j += i;
        i+=1;
def fun(n):
    if (n == 1):
        return 1;
    ans = 1;
    dup = factor[n];
    c = 1;
    j = int(n / factor[n]);
    while (j > 1):
        if (factor[j] == dup):
            c += 1;
        else:
            dup = factor[j];
            ans = ans * (c + 1);
            c = 1;
        j = int(j / factor[j]);
    ans = ans * (c + 1);
    return ans;

if __name__ == "__main__":
    primefactor()
    sum=0
    for i in range(1,MAX):
        a=fun(i)
        sum+=a
    print(sum)


Measured memory_bytes: 86904
#include<bits/stdc++.h>
#define ll long long int
#define ld long double
#define ss second
#define ff first
#define Mem(x,val) memset(x,val,sizeof x)
#define pb push_back
#define all(v) v.begin(),v.end()
#define unik(v)  v.erase(unique(v.begin(),v.end()),v.end())
#define cerr(x) cerr << __LINE__ << " th Line : " << #x << " = " << x << "\n"
#define debug(a,b) cerr << #a<<" = "<<a<<"   |   "<<#b<<" = "<<b<<'\n'
#define endl '\n'
#define SZ(a) ((int)a.size())
using namespace std;
typedef pair<int, int> pi;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<pi> vpi;
typedef vector<pll> vpll;
const ll mod = 1e9 + 7;
const int MX = 300+10;

int main()
{
   ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    
   int n;
   cin>>n;
   int ac=0,wa=0,tle=0,re=0;
   vector<string>s(n);
   for(int i=0;i<n;i++){
	   cin>>s[i];
	   if(s[i]=="AC")ac++;
	   else if(s[i]=="WA")wa++;
	   else if(s[i]=="TLE")tle++;
	   else re++;
   }
   cout<<"AC x "<<ac<<endl;
   cout<<"WA x "<<wa<<endl;
   cout<<"TLE x "<<tle<<endl;
   cout<<"RE x "<<re<<endl;
	   
   return 0;
}


Measured memory_bytes: 6364
#include <iostream>

int main() {
  int r,D, x2000;
  std::cin >> r >> D >> x2000;
  unsigned long long xi = x2000;
  for (int i=1;i<=10;i++){
    xi = r*xi - D;
    std::cout << xi << std::endl;
  }
  return 0;
}


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

int main()
{

    long long ans = 100000;
    int n;
    cin >> n;
    for(int i=0;i<n;i++)
    {
        ans = ans*105/100;

        if(ans % 1000 > 0) ans = ((ans/1000)+1)*1000;
        else ans = (ans /1000)*1000;

    }
    cout << ans << endl;

    return 0;
}

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

vector<string> split(const string &s, char remove) {
    istringstream stream(s);
    string field;
    vector<string> ans;
    while (getline(stream, field, remove)) {
        ans.emplace_back(field);
    }
    return ans;
}

int main() {
    string s;
    cin >> s;
    ll ans = 0;

    auto sum = [](string x) {
        auto v = split(x, '+');
        ll ret = 0;
        for (auto &&i : v) {
            ret += stoll(i);
        }
        return ret;
    };

    auto dfs = [&](auto f, int now, string formula) {
        if (now == s.size()) {
            ans += sum(formula);
            return;
        }
        f(f, now + 1, formula + string{s[now]});
        f(f, now + 1, formula + "+" + string{s[now]});
    };

    dfs(dfs, 1, {s[0]});
    cout << ans << endl;

    return 0;
}

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

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

    Scanner cin;

    public void Do()
    {
        cin = new Scanner();
        string S = cin.nextString();

        int count0 = 0;
        int count1 = 0;

        for (int i = 0; i < S.Length; i++)
        {
            if (S[i] == '0')
            {
                count0++;
            }
            if (S[i] == '1')
            {
                count1++;
            }
        }

        Console.WriteLine(2 * Math.Min(count0, count1));
    }
}

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: 13176
#include <bits/stdc++.h>
using namespace std;

int main() {
    int h,w;
    cin >> h >> w;
    string s;
    for(int i=0;i<h;i++){
        for(int j=0;j<w;j++){
            cin >> s;
            if(s == "snuke"){
                cout << (char)('A'+j) << 1+i;
            }
        }
    }
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <math.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
typedef long long ll;
 
 
int main() {
	int N, K;
	int ans = 0;

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

	for (int i = 0; i < N; i++) {
		if(h[i] >= K) ans++;
	}	

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

Measured memory_bytes: 640
#include <functional>
#include <algorithm>
#include <iostream>
#include <iomanip>
#include <cstring>
#include <string>
#include <vector>
#include <random>
#include <bitset>
#include <queue>
#include <cmath>
#include <stack>
#include <set>
#include <map>
typedef long long ll;
using namespace std;
const ll MOD = 1000000007LL;

int n, m, a, b, ans = 0;
vector<bool> visited(8, false);
vector<vector<int>> graph(8);

void dfs(int cur) {
    visited[cur] = true;

    bool all_visited = true;
    for (int i = 0; i < n; i++) {
        if (!visited[i]) {
            all_visited = false;
        }
    }

    if (all_visited) ans++;

    for (int ch : graph[cur]) {
        if (visited[ch]) continue;
        dfs(ch);
    }

    visited[cur] = false;
}

int main() {
    cin >> n >> m;
    for (int i = 0; i < m; i++) {
        cin >> a >> b;
        a--; b--;
        graph[a].push_back(b);
        graph[b].push_back(a);
    }

    dfs(0);

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


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

int main(void) {
    int N, M;
    cin >> N >> M;
    vector< int > A(M), B(M);
    for (int i = 0; i < M; i++) {
        cin >> A[i] >> B[i];
    }
    vector< vector< int > > s(N + 10);
    for (int i = 0; i < M; i++) {
        s[A[i]].push_back(B[i]);
        s[B[i]].push_back(A[i]);
    }
    vector< int > d(N + 10, N + 10);
    for (int i = 0; i <= N; i++) {
        d[i] = -1;
    }
    d[1] = 0;
    int dist = 0;
    queue< int > q;
    q.push(1);
    vector< int > p(N + 10);
    while (!q.empty()) {
        int n = q.front();
        q.pop();
        ++dist;
        for (int &x : s[n]) {
            if (d[x] == -1) {
                d[x] = dist;
                q.push(x);
                p[x] = n;
            }
        }
    }
    printf("Yes\n");
    for (int i = 2; i <= N; i++) {
        printf("%d\n", p[i]);
    }
    return 0;
}


Measured memory_bytes: 12244
while True:
    a, op, b = input().split()
    a = int(a)
    b = int(b)
    
    if op == '?':
        break
    
    if op == '+':
        print(a + b)
    
    if op == '-':
        print(a - b)
    
    if op == '*':
        print(a *b)
    
    if op == '/':
        print(a // b) 

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

int main()
{
	double xa1, ya1, xa2, ya2, xb1, yb1, xb2, yb2;
	while (cin >> xa1 >> ya1 >> xa2 >> ya2 >> xb1 >> yb1 >> xb2 >> yb2)
	{
		if (xa1<=xb2 && xb1<=xa2 && ya1<=yb2 && yb1<=ya2)
		{
			cout << "YES" << endl;
		}
		else
		{
			cout << "NO" << endl;
		}

	}
	return 0;
}

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

#define rep2(x,fr,to) for(int x=(fr);x<(to);x++)
#define rep(x,to) for(int x=0;x<(to);x++)
#define repr(x,fr,to) for(int x=(fr);x>=(to);x--)
#define all(c) c.begin(),c.end()
#define sz(v) (int)v.size()

using namespace std;
typedef long long  ll; typedef vector<int> VI; typedef pair<int,int> pii; typedef vector<ll> VL; const int MD = 1e9 + 7;
void dbg(){cerr<<"\n";} template <class F,class ...S> void dbg(const F& f, const S&...s){cerr <<f <<": "; dbg(s...);}

int main()
{
	cin.tie(0); ios_base::sync_with_stdio(false);
	int l, r, d;
	cin >>l >>r >>d;
	int ans =0;
	rep2(i, l, r+1) if(i%d==0) ans++;
	cout <<ans <<"\n";
	return 0;
}


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

using ll = long long;
using pii = pair<int, int>;

template <typename T> constexpr T inf;
template <> constexpr int inf<int> = 1e9;
template <> constexpr ll inf<ll> = 1e18;
template <> constexpr double inf<double> = 1e18;

template<typename T>
std::vector<T> table(int n, T v) { return std::vector<T>(n, v); }
 
template <class... Args>
auto table(int n, Args... args) {
    auto val = table(args...);
    return std::vector<decltype(val)>(n, std::move(val));
}


int main() {
    string s;
    cin >> s;
    if(s == "zyxwvutsrqponmlkjihgfedcba") {
        cout << -1 << endl;
        return 0;
    }
    if(s.size() == 26) {
        auto tmp = s;
        next_permutation(begin(s), end(s));
        string ans;
        for(int i = 0; i < 26; ++i) {
            ans += s[i];
            if(s[i] != tmp[i]) {
                break;
            }
        }
        s = ans;
    } else {
        for(char c = 'a'; c <= 'z'; ++c) {
            if(s.find(c) == string::npos) {
                s += c;
                break;
            }
        }
    }
    cout << s << endl;
}

Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
const ll MOD = 1e9 + 7;
using PII = pair<ll, ll>;
#define FOR(i,a,n) for(ll i=(ll)a; i<(ll)n; ++i)
#define REP(i,n) FOR(i,0,n)



int main() {
	int N, M, MD, K;
	cin >> N >> M >> MD >> K;
	vector<vector<pair<int, long long int>>>rev_edge(N + 1);
	for (int i = 0; i < M; i++) {
		int l, r, k;
		cin >> l >> r >> k;
		rev_edge[r].push_back({ l,k });
	}
	vector<vector<long long int>>dis(MD, vector<long long int>(N + 1,MOD*MOD));
	for (int i = 0; i < MD; i++) {
		for (int j = i; j <= N; j += MD) {
			dis[i][j] = 0;
		}
		priority_queue<pair<long long int, int>, vector<pair<long long int, int>>, greater<pair<long long int, int>>>PQ;
		for (int j = 0; j <= N; j++) {
			if (dis[i][j] == MOD*MOD) continue;
			PQ.push({ dis[i][j],j });
		}
		while (!PQ.empty()) {
			int cn = PQ.top().second;
			long long int c = PQ.top().first;
			PQ.pop();
			for (auto j : rev_edge[cn]) {
				if (dis[i][j.first]>c + j.second) {
					dis[i][j.first] = c + j.second;
					PQ.push({ dis[i][j.first],j.first });
				}
			}
		}
	}
	long long int ans = 0;
	for (int i = 0; i < K; i++) {
		int a, b, c;
		cin >> a >> b >> c;
		long long int add = 0;
		for (int j = 0; j < MD; j++) {
			add = max(add, c - dis[j][a] - dis[j][b]);
		}
		ans += add;
	}
	cout << ans << endl;
}


Measured memory_bytes: 16844
#include<bits/stdc++.h>
#include<vector>
#include<string>
#include<algorithm>
#include<cmath>
 
#define fast ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define int long long int
#define mod 1000000007

#define out1(a) cout<<#a<<" "<<a<<endl
#define out2(a,b) cout<<#a<<" "<<a<<" "<<#b<<" "<<b<<endl
#define out3(a,b,c) cout<<#a<<" "<<a<<" "<<#b<<" "<<b<<" "<<#c<<" "<<c<<endl

#define ft first
#define sd second
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(),(x).end()
 
using namespace std;

signed main()
{
    fast;
    int x,y,a,b,c;
    cin>>x>>y>>a>>b>>c;

    vector<int> v1(a);
    vector<int> v2(b);
    vector<int> v3(c);

    for ( int i = 0 ; i < v1.size() ; i++ )
    {
        cin>>v1[i];
    }

    for ( int i = 0 ; i < v2.size() ; i++ )
    {
        cin>>v2[i];
    }

    for ( int i = 0 ; i < v3.size() ; i++ )
    {
        cin>>v3[i];
    }

    sort(all(v1));
    sort(all(v2));
    sort(all(v3));
    vector<int> ans;
    for ( int i = 0 ; i < x ; i++ )
    {
        ans.pb(v1[v1.size()-1-i]);
    }
    for ( int i = 0 ; i < y ; i++ )
    {
        ans.pb(v2[v2.size()-1-i]);
    }
    for ( int i = 0 ; i < min(x+y,(int)v3.size()) ; i++ )
    {
        ans.pb(v3[v3.size()-1-i]);
    }

    sort(all(ans));
    int sum = 0;
    for ( int i = 0 ; i < x+y ; i++ )
    {
        sum += ans[ans.size()-1-i];
    }

    cout<<sum<<endl;
    return 0;
}

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

#define rep(i,n) for(int i=0;i<n;i++)
#define REP(i,s,n) for(int i=(s);i<=(n);i++)
#define repr(i,n) for(int i=n-1;i>=0;i--)
#define REPR(i,s,n) for(int i=(s);i>=(n);i--)
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
#define Eunique(v) v.erase(unique(all(v)),v.end())
#define Eback(s) s.erase(s.end()-1,s.end())
#define rev(v) reverse(all(v))
#define minvec(v) *min_element(all(v))
#define maxvec(v) *max_element(all(v))
#define sumvec(v) accumulate(all(v),0)
#define mapmax(v) v.rbegin()->first
#define mapmin(v) v.begin()->first
#define pb push_back
#define pf push_front
#define m_p make_pair
#define DOUBLE fixed << setprecision(15)
#define OK puts("OK")
#define OK1 puts("OK1")
#define OK2 puts("OK2")
#define SIZE(s) (int)s.size()
#define INF ((1LL<<62)-(1LL<<31))
#define zero(x,n) setw(x) << setfill('0') << n

typedef long long ll;

typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<long long> vll;
typedef vector<vll> vvll;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef vector<char> vc;
typedef vector<vc> vvc;
typedef vector<bool> vb;
typedef vector<vb> vvb;
typedef vector<string> vs;

typedef pair<ll,ll> pll;
typedef pair<int,int> pii;
typedef vector<pair<int,int>> vpii;
typedef vector<pair<ll,ll>> vpll;

const double pi = acos(-1.0);
const int mod=1000000007;
const int mod2=998244353;

template<class A, class B>
ostream& operator<<(ostream& ost, const pair<A, B>&p) {
	ost << "{" << p.first << ", " << p.second << "} ";
	return ost;
}

template<class T>
ostream& operator<<(ostream& ost, const vector<T>&v) {
	ost << "{";
	for (int i = 0; i<(int)v.size(); i++) {
		if (i)ost << " ";
		ost << v[i];
	}
	ost << "} \n";
	return ost;
}

template<class A, class B>
ostream& operator<<(ostream& ost, const map<A, B>&v) {
	ost << "{";
	for (auto p:v) {
		ost << "{" << p.first << ", " << p.second << "} ";
	}
	ost << "} ";
	return ost;
}

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

void YES(bool b) {cout << (b?"YES\n":"NO\n");}
void Yes(bool b) {cout << (b?"Yes\n":"No\n");}
void yes(bool b) {cout << (b?"yes\n":"no\n");}
void Yay(bool b) {cout << (b?"Yay!\n":":(\n");}

long long powmod(long long a,long long b){
    long long c=1;
    while(b>0){
        if(b&1) c=a*c%mod;
        a=a*a%mod;
        b>>=1;
    }
    return c;
}

ll gcd(ll x, ll y) {return __gcd(x,y);}
ll lcm(ll x, ll y) {return x/__gcd(x,y)*y;}

int main()
{
	ll n,ans=0;
	cin >> n;
	for(ll i=1;i<=n;i++){
		if(i%3!=0 && i%5!=0) ans+=i;
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 3632
// vim: shiftwidth=2 expandtab foldmethod=marker

// include {{{
#include <algorithm>
#include <iostream>
#include <iomanip>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <unordered_set>
#include <map>
#include <unordered_map>
#include <queue>
#include <stack>
#include <cmath>
#include <utility>
#include <cstdlib>
#include <random>
#include <chrono>
#include <limits>
// }}}

// debug(...) {{{
#ifdef LOCAL_DEBUG
#include "./debug.h"
#else
bool debug_enabled = false;
#define debug(...)
#define debugn(...)
#define debug_reset()
#endif

// }}}

// bin {{{
template<class T>
std::string bin(int bits, const T& x) {
  char buf[bits + 1];
  buf[bits] = '\0';
  for(int i = 0; i < bits; i++) {
    if((x >> i) & 1) {
      buf[bits - i - 1] = '1';
    } else {
      buf[bits - i - 1] = '0';
    }
  }
  return std::string(buf);
}
std::string bin(int x) {
  if(x < 0) return bin(32, x);
  for(int i = 4; i < 31; i++) {
    int y = 1 << i;
    if(x < y) return bin(i, x);
  }
  return bin(32, x);
}
// }}}

// misc {{{
using namespace std;
template<class T, class U>

using umap = unordered_map<T, U>;
template<class T>
using uset = unordered_set<T>;

typedef long long ll;

#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++)

template<class T>
void sort(T& arr) { // {{{
  std::sort(arr.begin(), arr.end());
} // }}}
template<class T, class By>
void sort_by(T& arr, By by) { // {{{
  std::sort(arr.begin(), arr.end(), [by](auto l, auto r){return  by(l) < by(r); });
} // }}}

template<class T>
void reverse(T& arr) { // {{{
  std::reverse(arr.begin(), arr.end());
} // }}}

class Random { // {{{
  public:
  std::uniform_int_distribution<> uniform_int;
  std::mt19937 rnd;
  std::bernoulli_distribution bern_dist;
  int uniform(int l, int r) {
    return uniform_int(rnd, std::uniform_int_distribution<>::param_type(l, r));
  }
  int next(int N) {
    return uniform(0, N - 1);
  }
  int bern(double p) {
    return bern_dist(rnd, std::bernoulli_distribution::param_type(p));
  }
}; // }}}

template <class A>
ostream& out_vec(const vector<A>& x, const string& sep) { // {{{
  rep(i, x.size()) {
    cout << x[i];
    if(i < x.size() - 1)
      cout << sep;
  }
  return cout;
} // }}}
// }}}

// modulo {{{
ll modpow(ll a, ll n, ll mod) {
    ll res = 1;
    while (n > 0) {
        if (n & 1) res = res * a % mod;
        a = a * a % mod;
        n >>= 1;
    }
    return res;
}

ll modplus(ll a, ll b, ll mod) {
  ll x = ((a % mod) + (b % mod)) % mod;
  if(x < 0) x += mod;
  return x;
}

ll modminus(ll a, ll b, ll mod) {
  return modplus(a, -b, mod);
}

// }}}

// main {{{
void solve();
int main() {
  cout << setprecision(20);
  solve();
}
// }}}

void solve() {
  int N;
  cin >> N;
  vector<int> L(N);
  rep(i, N) cin >> L[i];

  sort(L.begin(), L.end());

  int ans = 0;
  rep(i, N - 2) {
    rep2(j, i + 1, N - 1) {
      int a = L[i];
      int b = L[j];
      int k = j + 1;
      while(k < N && L[k] < a + b) {
        int c = L[k];
        if(a < b + c && b < c + a) {
          ans++;
        }
        k++;
      }
    }
  }
  cout << ans << endl;
}


Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<algorithm>
#include<numeric>

int main(){
    
    int n;

    std::cin >> n;

    std::vector<int> l(n);

    for(auto&& e : l){
        std::cin >> e;
    }

    std::sort(l.begin(), l.end());

    if(std::accumulate(l.begin(), l.end() - 1, 0) > l.back()){
        std::cout << "Yes" << std::endl;
    }else{
        std::cout << "No" << std::endl;
    }
    
    return 0;
}


Measured memory_bytes: 256
class Node:
    id = None
    parent = None
    left = None
    right = None
    sibling = -1
    depth = None
    height = None

    def __str__(self):
        degree = None
        _type = None

        return 'node {}: parent = {}, sibling = {}, degree = {}, depth = {}, height = {}, {}'.format(self.id, self.parent, self.sibling, self.get_degree(), self.depth, self.height, self.get_type())

    def get_degree(self):
        degree = 0
        if self.left is not None:
            degree += 1
        if self.right is not None:
            degree += 1
        return degree

    def get_type(self):
        if self.parent == -1:
            return 'root'
        if self.get_degree() == 0:
            return 'leaf'
        else:
            return 'internal node'


def set_depth(node_id, depth):
    if node_id is None:
        return

    global T
    T[node_id].depth = depth
    set_depth(T[node_id].left, depth + 1)
    set_depth(T[node_id].right, depth + 1)


def set_height(node_id):
    global T

    h1, h2 = 0, 0
    if T[node_id].left is not None:
        h1 = set_height(T[node_id].left) + 1
    if T[node_id].right is not None:
        h2 = set_height(T[node_id].right) + 1

    T[node_id].height = max(h1, h2)

    return max(h1, h2)


n = int(input())
T = []
root = 0

for i in range(n):
    T.append(Node())

for i in range(n):
    _ = list(map(int, input().split()))
    _id = _[0]
    left = _[1]
    right = _[2]
    if left == -1:
        left = None
    if right == -1:
        right = None

    T[_id].id = _id
    T[_id].left = left
    T[_id].right = right

    if left is not None:
        T[left].parent = _id
    if right is not None:
        T[right].parent = _id

    if left is not None and right is not None:
        T[left].sibling = right
        T[right].sibling = left

for i in range(n):
    if T[i].parent is None:
        T[i].parent = -1
        root = i
        break

set_depth(root, 0)
set_height(root)


for i in range(n):
    print(T[i])



Measured memory_bytes: 5612
#include<iostream>
#include<algorithm>
#include<vector>
#include<string>
#include<utility>
#include<map>
#include<set>
#include<queue>
#include<bitset>
#include<math.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
#define N (1000000000+7)
#define INF (ll)1e16
typedef long long ll;
char board[1010][1010];
int d[1010][1010];
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};
int h,w;
bool check(int i, int j) {
	return (i >= 0) && (i < h) && (j >= 0) && (j < w) && ((board[i][j] == '.'));
}

int main(void){
    cin>>h>>w;
    queue<P>que;
    for(int i=0;i<h;i++){
        for(int j=0;j<w;j++){
            cin>>board[i][j];
            if(board[i][j]=='#'){
                d[i][j]=0;
                que.push(P(i,j));
            }
            else d[i][j]=100000000;
        }
    }
    while(!que.empty()){
        P p=que.front();
        que.pop();
        int nx=p.first;
        int ny=p.second;
        for(int i=0;i<4;i++){
            int px=nx+dx[i];
            int py=ny+dy[i];
            if(check(px,py)){
                if(d[px][py]>d[nx][ny]+1){
                    d[px][py]=d[nx][ny]+1;
                    que.push(P(px,py));
                }
            }
        }
    }
    int ans=0;
    for(int i=0;i<h;i++){
        for(int j=0;j<w;j++){
            ans=max(ans,d[i][j]);
        }
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 13456
#include<iostream>
#include<iomanip>
#include<math.h>
#include<vector>
#include<algorithm>
#include<set>
#include<map>
#include<queue>
#include<stack>
#include<string>
#define INF 1000000000ll
#define MOD 1000000007ll
#define EPS 1e-8
#define REP(i,m) for(long long i=0; i<m; ++i)
#define FOR(i,n,m) for(long long i=n; i<m; ++i)
#define ALL(v) v.begin(),v.end()
#define pb push_back
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
typedef long double ld;
typedef vector<int> vi;
typedef vector<vector<int> > vii;
typedef vector<long long> vl;
typedef vector<vector<long long> > vll;
typedef vector<P> vp;
typedef vector<vector<P> > vpp;

int main() {
	int n;
	cin>>n;
	vl a(n);
	REP(i,n) cin>>a[i];
	vector<ll> c(1e5+1,0);
	REP(i,n) {
		++c[a[i]];
		++c[a[i]+1];
		++c[a[i]+2];
	}
	ll res=0;
	REP(i,1e5+1) {
		res=max(res,c[i]);
	}
	cout<<res<<endl;
}



Measured memory_bytes: 1792
#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;

#define CHECK_AND_FILL(x,y,v) do {if(0<=x&&x<10&&0<=y&&y<10) v[x][y]++; }while(0);

int main() {
    vector<vector<int> > v(10, vector<int>(10, 0));

    int x, y, size;
    char c1, c2;
    while(cin >> x >> c1 >> y >> c2 >> size) {
        if(size == 1) {
            for(int dx = -1; dx <= 1; ++dx) 
                for(int dy = -1; dy <= 1; ++dy) 
                    if(abs(dx)+abs(dy) <= 1) CHECK_AND_FILL(x+dx, y+dy, v);
        }
        else if(size == 2) {
            for(int dx = -1; dx <= 1; ++dx) 
                for(int dy = -1; dy <= 1; ++dy) 
                    CHECK_AND_FILL(x+dx, y+dy, v);
        }
        else if(size == 3) {
            for(int dx = -2; dx <= 2; ++dx) 
                for(int dy = -2; dy <= 2; ++dy) 
                    if(abs(dx)+abs(dy) <= 2) CHECK_AND_FILL(x+dx, y+dy, v);
        }
    }

    int thick = 0;
    int white = 0;
    for(int i = 0; i < 10; ++i)
        for(int j = 0; j < 10; ++j) {
            thick = max(thick, v[i][j]);
            if(v[i][j] == 0) ++white;
        }

    cout << white << endl;
    cout << thick << endl;
    return 0;
}

Measured memory_bytes: 0
// #pragma GCC target("avx2")
#pragma GCC optimize("O3", "unroll-loops")
 
// #include <bits/extc++.h>
// using namespace __gnu_pbds;
 
#include <bits/stdc++.h>
using namespace std;
 
#define int long long
#define double long double
// template <typename T>
// using pbds_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
using pii = pair<int, int>;
template<typename T>
using prior = priority_queue<T, vector<T>, greater<T>>;
template<typename T>
using Prior = priority_queue<T>;
 
#define X first
#define Y second
#define ALL(x) (x).begin(), (x).end()
#define eb emplace_back
#define pb push_back
 
#define fastIO() ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0)
#define RANDOM() random_device __rd; \
                 mt19937 __gen = mt19937(__rd()); \
                 uniform_int_distribution<int> __dis(1, 1E8); \
                 auto rnd = bind(__dis, __gen)
 
const int INF = 1E18;
const int mod = 1E9 + 7;
 
int32_t main() {
    fastIO();
    
    int a, b, k;
    cin >> a >> b >> k;
    
    set<int> nums;
    for (int i = 0; i < k; ++i) nums.insert(a + i), nums.insert(b - i);
    
    for (auto x : nums) {
        if (a <= x and x <= b) cout << x << "\n";
    }
    
    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<bitset>
using namespace std;
const int N=705;
int n,m,a[N][N],s[2],c[N],ans=1e9;
bool v[N],flg;
bitset<N>b;
int read()
{
    int r=0,f=1;
    char p=getchar();
    while(p>'9'||p<'0')
    {
        if(p=='-')
            f=-1;
        p=getchar();
    }
    while(p>='0'&&p<='9')
    {
        r=r*10+p-48;
        p=getchar();
    }
    return r*f;
}
void dfs(int u,int col)
{
    c[u]=col;
    v[u]=1;
    s[col]++;
    for(int i=1;i<=n;i++)
        if(i!=u&&!a[u][i])
        {
            if(!v[i])
                dfs(i,col^1);
            else if(c[i]!=col^1)
                flg=1;
        }
}
int main()
{
    n=read(),m=read();b[0]=1;
    for(int i=1;i<=m;i++)
    {
        int x=read(),y=read();
        a[x][y]=a[y][x]=1;
    }
    for(int i=1;i<=n;i++)
        if(!v[i])
        {
            s[0]=s[1]=0;
            dfs(i,0);
            b=(b<<s[0])|(b<<s[1]);
        }
    if(flg==1)
    {
        puts("-1");
        return 0;
    }
    for(int i=0;i<=n;i++)
        if(b[i])
            ans=min(ans,i*(i-1)/2+(n-i)*(n-i-1)/2);
    printf("%d\n",ans);
    return 0;
}

Measured memory_bytes: 2176
import java.util.*;
import java.lang.Math;

class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);

    int a = Integer.parseInt(sc.next());
    int b = Integer.parseInt(sc.next());

    if ( a > 9 || b > 9) {
      System.out.println("-1");
    } else {
      System.out.println(a * b);
    }
  }
}

Measured memory_bytes: 23124
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<assert.h>
#pragma GCC optimize("O3")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#define rep(i,N) for(int i=0;i<(int)N;i++)
int N,x,y,sw,pw3=1,A[531441],B[531441],S[200001];
char T[200001];
char* replace(char* s,const char* before,const char* after)
{
  assert(s!=(char*)NULL);assert(before!=(char*)NULL);assert(after!=(char*)NULL);
  const size_t szb=strlen(before),sza=strlen(after);
  char* pt=s;
  if(szb==0)return s;
  for(;;)
  {
    pt=strstr(pt,before);if(pt==(char*)NULL)break;const char* remain=pt+szb;
    memmove(pt+sza,remain,strlen(remain)+1);
    memcpy(pt,after,sza);
    pt+=sza;
  }
  return s;
}
signed main(void)
{
  x=scanf("%d %s",&N,T);
  replace(T,"SS","");if(T[0]=='\n')return 0;
  rep(i,N)
  {
    rep(j,pw3)rep(k,3)B[j+k*pw3]=k;sw=0;
    rep(j,strlen(T))
    {
      if(T[j]=='R')
      {
        y=S[j];
        rep(k,3){x=y+k*pw3;if(B[x]+sw==2)S[j]=x;B[x]+=sw+1;B[x]%=3;}
      }
      if(T[j]=='S')sw^=1;
    }
    rep(j,pw3){y=A[j];rep(k,3){x=j+k*pw3;A[x]=y+(sw?3-B[x]:B[x])%3*pw3;}}
    pw3*=3;
  }
  rep(i,pw3)printf("%d%c",A[i],i+1==pw3?'\n':' ');
}

Measured memory_bytes: 9040
from collections import deque
from heapq import heappush, heappop
que = deque()
q = []
N = 100
for i in range(N):
    heappush(q, (5*i, 0, i))
M = 17
S = [-1]*M
T = [0]*N
while q:
    t = None
    while q and (t is None or q[0][0] == t):
        t, c, i = heappop(q)
        if c == 0:
            que.append(i)
        else:
            for j in range(M):
                if S[j] == i:
                    S[j] = -1

    while que:
        i = que[0]
        m = 5 if i % 5 == 1 else 2

        cnt = 0; j = -1
        for k in range(M):
            if S[k] == -1:
                cnt += 1
                if cnt == m:
                    j = k-m+1
                    break
            else:
                cnt = 0
        if j == -1:
            break
        for k in range(m):
            S[j + k] = i
        T[i] = t - 5*i
        que.popleft()
        heappush(q, (t + (17*(i%2) + 3*(i%3) + 19), 1, i))
open(1, 'w').writelines(["{}\n".format(T[v]) for v in map(int, open(0).read().split())])


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

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


Measured memory_bytes: 5940
/*
これを入れて実行
g++ code.cpp
./a.out
 */

#include <iostream>
#include <vector>
#include <string>
#include <queue>
#include <algorithm>
#include <utility>
#include <set>
#include <map>
#include <cmath>
#include <tuple>
#include <iomanip>

using namespace std;
typedef long long ll;
typedef long double ld;

int dy4[4] = {-1, 0, +1, 0};
int dx4[4] = {0, +1, 0, -1};
int dy8[8] = {-1, -1, 0, 1, 1, 1, 0, -1};
int dx8[8] = {0, 1, 1, 1, 0, -1, -1, -1};

const long long INF = 1LL << 60;
const ll MOD = 1e9 + 7;

bool greaterSecond(const pair<int, int>& f, const pair<int, int>& s){
    return f.second > s.second;
}

ll gcd(ll a, ll b){
	if (b == 0)return a;
	return gcd(b, a % b);
}

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

ll nCr(ll n, ll r){
    if(r == 0 || r == n){
        return 1;
    } else if(r == 1){
        return n;
    }
    return (nCr(n - 1, r) + nCr(n - 1, r - 1));
}

ll nPr(ll n, ll r){
    r = n - r;
    ll ret = 1;
    for (ll i = n; i >= r + 1; i--) ret *= i;
    return ret;
}

//-----------------------ここから-----------

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

    vector<ll> t(n), a(n);
    for(int i = 0; i < n; i++) cin >> t[i] >> a[i];

    ll nowt = t[0];
    ll nowa = a[0];
    for(int i = 1; i < n; i++){
        ll tmp = max(ceil((ld)nowt / (ld)t[i]), ceil((ld)nowa / (ld)a[i]));
        nowt = tmp * t[i];
        nowa = tmp * a[i];
    }
    cout << nowa + nowt << endl;
}

Measured memory_bytes: 256
#include <stdio.h>

int main(void)
{
    int n;
	int h, m, s;
	
	scanf("%d", &n);

	h = n / 3600;
	m = (n % 3600) / 60;
	s = n % 60;
	printf("%d:%d:%d\n", h, m, s );

	return 0;
}

Measured memory_bytes: 592
#include <iostream>
#include <functional>
#include <algorithm>
#include <bits/stdc++.h>
using namespace std;
int main(){
    int N;
    
    //string S[30000];
    cin >> N;
    vector<string> S(N);
    for(int i=0; i<N; i++)cin >> S.at(i);
    //sort(S, S+N, greater<string>());
    sort(S.begin(), S.end());
    S.erase(unique(S.begin(), S.end()), S.end());
    cout << S.size() << endl;
    
}

Measured memory_bytes: 9600
# -*- coding: utf-8 -*-
import sys
from collections import deque, defaultdict
from math import sqrt, factorial, gcd
# def input(): return sys.stdin.readline()[:-1] # warning not \n
# def input(): return sys.stdin.buffer.readline().strip() # warning bytes
# def input(): return sys.stdin.buffer.readline().decode('utf-8')


def solve():
    n = int(input())
    pos = 0
    i = 0
    while pos < n:
        i += 1
        pos += i
    print(min(n, i))

t = 1
# t = int(input())
for case in range(1,t+1):
    ans = solve()


"""

abc

"""


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

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

  int i;
  if((S.size()+1)!=T.size()){
  	cout<<"no"<<endl;
    return 0;
  }
  for(i=0;i<S.size();i++){
    if(S.at(i)!=T.at(i)){
      cout<<"No"<<endl;
      return 0;
    }
  }
  
  cout<<"Yes"<<endl;
}

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

using namespace std;
typedef long long ll;

int main() {
	int a, b, k;
	cin >> a >> b >> k;
	
	int cnt = 0;
	
	for(int i = min(a,b); i >= 1; i--) {
		if((a%i==0) && (b%i==0)) {
			cnt++;
			if(cnt == k) {
				cout << i;
				return 0;
			}
		}
	}
	
	return 0;
}

Measured memory_bytes: 256
import java.util.Collections;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;
import java.util.Scanner;
import java.util.Set;

public class Main {
    public static void main(String[] args) {
        try (Scanner sc = new Scanner(System.in);) {
            new Main().solve(sc);
        }
    }

    void solve(Scanner sc) {
        int n = sc.nextInt();
        int m = sc.nextInt();
        Map<Integer, Set<Integer>> shipMap = new HashMap<>();
        for (int i = 0; i < m; i++) {
            int a = sc.nextInt();
            int b = sc.nextInt();
            shipMap.computeIfAbsent(a, e -> new HashSet<Integer>()).add(b);
        }

        Set<Integer> toSet = shipMap.getOrDefault(1, Collections.emptySet());
        for (Integer i : toSet) {
            Set<Integer> toSet2 = shipMap.getOrDefault(i, Collections.emptySet());
            if (toSet2.contains(n)) {
                System.out.println("POSSIBLE");
                return;
            }
        }
        System.out.println("IMPOSSIBLE");
    }
}


Measured memory_bytes: 155636
import sys

#fp = open("input.txt", "r")
fp = sys.stdin

def operate(string):
    count = 0
    prev = ""
    ret = ""
    flg = True
    for c in string:
        if flg or c == prev:
            flg = False
            count += 1
        else:
            ret += str(count) + prev
            count = 1
        prev = c
    ret += str(count) + prev
    #print ret
    return ret
            

while True:
    n = int(fp.readline()[:-1])
    if n == 0:
        break

    orig = fp.readline()[:-1]

    for i in xrange(n):
        orig = operate(orig)

    print orig

Measured memory_bytes: 4292
#include <bits/stdc++.h>
using namespace std;
template<typename VAL>
struct SegT {
  using CAL = function<VAL(VAL, VAL)>;
  int len; vector<VAL> seg; const CAL f; const VAL u;
  SegT(int n, const CAL f, const VAL &u) : f(f), u(u) {
    for(len=1; len<n; ){ len<<=1; }
    seg.assign(2*len, u);
  }
  void set(int k, const VAL &x) { seg[len+k]=x; }
  void build(){ for(int k=len-1; k>0; k--) { seg[k]=f(seg[2*k], seg[2*k+1]); } }
  void update(int k, const VAL &x) {
    k+=len; seg[k]=x;
    while(k>>=1) { seg[k]=f(seg[2*k+0], seg[2*k+1]); }
  }
  VAL query(int a, int b){
    VAL L=u, R=u;
    for(a+=len, b+=len; a<b; a>>=1, b>>=1) {
      if(a&1) L=f(L, seg[a++]);
      if(b&1) R=f(seg[--b], R);
    }
    return f(L, R);
  }
};

int gcd(int a, int b){ 
  if(a==-1){ return b; }
  if(b==-1){ return a; }
  if(b){ return gcd(b, a%b); }else{ return a; }
}

int main(){
  int N, i; cin >> N; SegT<int> T(N, gcd, -1);
  for(i=0; i<N; i++){ int a; cin >> a; T.set(i, a); }
  T.build();
  int ans=max(T.query(1, N), T.query(0, N-1));
  for(i=1; i<N-1; i++){ ans=max(ans, gcd(T.query(0, i), T.query(i+1, N))); } 
  cout << ans << "\n";
}

Measured memory_bytes: 1280
#include<iostream>
using namespace std;
int main(){
  char n[3];
  cin >> n;
  if(n[0]=='7'){
    cout << "Yes";
  }
  else if(n[1]=='7' ){
    cout << "Yes";
  }
  else if(n[2]=='7' ){
    cout << "Yes";
  }

  else{
    cout << "No";
  }
  return 0;
}

Measured memory_bytes: 3632