akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;

#define loop(n) for(int i = 0;i < (int)(n);++i)
#define rep(i,n) for(int i = 0;i < (int)(n);++i)
#define all(vec) (vec).begin(),(vec).end()
#define Sort(vec) sort(all(vec))
#define Rev(vec) reverse(all(vec))

using Graph = vector<vector<int>>;

namespace Input
{
                
    void input(){return;}
    template<typename First,typename... Rest> void input(First &first,Rest&... rest){
    std::cin >> first;
    input(rest...);
}
    
    void inputVec(){return;}
    template<typename First,typename... Rest> void inputVec(vector<First> &first,Rest&... rest){
        int N = first.size();
        for(int i = 0;i < N;i++){
            cin >> first[i];
        }
        inputVec(rest...);
    }
    
    template<typename First,typename Second> void inputTwoVec(vector<First> &first,vector<Second>& second){
        int N = first.size();
        for(int i = 0;i < N;i++){
            cin >> first[i] >> second[i];
        }
    }

    void inputGraph(Graph &g,int path_num,bool isdirected){
        for(int i = 0;i < path_num;i++){
            int a,b;
            cin >> a >> b;
            a--;b--;
            if(isdirected){
                g[a].push_back(b);
            }
            else{
                g[a].push_back(b);
                g[b].push_back(a);
            }
        }
    }
}

int N,M,Q;
vector<long long>a,b,c,d;
int res = -1;

void getScore(vector<int>&A){
    int ans = 0;
    for(int i = 0;i < Q;++i){
        if(A[b[i]] - A[a[i]] == c[i]){
            ans += d[i];
        }
    }
    res = max(res,ans);
}

void recursive(vector<int>&A){
    if(A.size() == N){
        getScore(A);
        return;
    }
    int pre = (A.empty() ? 0 : A.back());
    for(int i = pre;i <= M;++i){
        A.push_back(i);
        recursive(A);
        A.pop_back();
    }
}

void calculate(){
    /*
    Input::input(N,M,Q);
    a.resize(Q);b.resize(Q);
    c.resize(Q);d.resize(Q);
    rep(i,Q){
        cin >> a[i] >> b[i] >> c[i] >> d[i];
    }
    vector<int> A;
    recursive(A);
    cout << res << '\n';
    */
   long long A,B,N;
   Input::input(A,B,N);
   long long X = (N < B - 1 ? N : B - 1);
   cout << ceil(A * X / B) - A * ceil(X / B) << '\n';
}

int main(int,char**){
    calculate();    
}





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

int main(){
    string s;
    cin >> s;
    int c1 = 0, c2 = 0; //c1は0スタート、c2は1スタート
    for (int i = 0, lim = s.size(); i < lim; i++)
    {
        if (i % 2 == 0) {
            s[i] == '0' ? c2++ : c1++;
        }
        else {
            s[i] == '1' ? c2++ : c1++;
        }
    }
    cout << min(c1, c2) << endl;
}

Measured memory_bytes: 512
//             بسم الثالوث الاقدس
#include<iostream>	
#include<algorithm>
#include<cstdio>
#include<sstream>
#include<cmath>
#include<climits>
#include<string>
#include<iomanip>
#include<vector>
#include<stack>
#include<map>
#include<queue>
#include<set>
#include<fstream>
using namespace std;
//********************************************************************************************
//******************************************************************************************** 
/*
jesus help me.......
*/
typedef long long lld;
typedef char c;



/*
jesus help me.......
jesus help me.......
jesus help me.......
*/



int binarySearch(int arr[], int l, int r, int x)
{
	while (l <= r)
	{
		int m = l + (r - l) / 2;

		if (arr[m] == x)
			return m;

		if (arr[m] < x)
			l = m + 1;

		else
			r = m - 1;
	}

	return -1;

}





bool sortbysec(const pair<string, int> &a, const pair<string, int> &b)
{
	
	return (a.second > b.second);
}







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


	//freopen("keys.in", "r", stdin);

	int a, b;
	cin >> a >> b;
	if ((a*b) % 2 == 0)
		cout << "Even" << endl;
	else
		cout << "Odd" << endl;

	///system("pause");


	return 0;
}
/*
jesus help me.......
jesus help me.......
jesus help me.......
*/

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, n) for (ll i = 0; i < (ll)(n); ++i)
#define rep2(i, s, n) for (ll i = s; i < (ll)(n); i++)
#define repr(i, n) for (ll i = n; i >= 0; i--)
#define pb push_back
#define COUT(x) cout << (x) << endl
#define COUTF(x) cout << setprecision(15) << (x) << endl
#define ENDL cout << endl
#define DF(x) x.erase(x.begin())  // 先頭文字削除
#define ALL(x) x.begin(), x.end()
#define SORT(x) sort(ALL(x))
#define REVERSE(x) reverse(ALL(x))
#ifdef _DEBUG
#define debug(x) cout << "[debug] " << #x << ": " << x << endl
#else
#define debug(x)
#endif
using namespace std;
using ll = long long;
using ld = long double;
using vll = vector<ll>;
using P = pair<ll, ll>;
constexpr ll INF = 0x3f3f3f3f3f3f3f3f;
constexpr double PI = 3.141592653589793238462643383279;
ll getDigit(ll x) {
  return x == 0 ? 1 : log10(x) + 1;
}

ll gcd(ll x, ll y) {
  return y ? gcd(y, x % y) : x;
}

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

vector<P> factorize(ll n) {
  vector<P> result;
  for (ll i = 2; i * i <= n; ++i) {
    if (n % i == 0) {
      result.pb({i, 0});
      while (n % i == 0) {
        n /= i;
        result.back().second++;
      }
    }
  }
  if (n != 1) {
    result.pb({n, 1});
  }
  return result;
}

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

template <typename T>
void debugV(const vector<T> v) {
#ifdef _DEBUG
  rep(i, v.size()) {
    cout << i << ":" << v[i] << " ";
  }
  cout << endl;
#else
  (void)v;
#endif
}

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

  vll H(N);

  rep(i, N) {
    ll h;
    cin >> h;
    H[i] = h;
  }

  ll ans = 0;
  ll m = 0;
  ll max_index = 0;
  while (!H.empty()) {
    if (H.size() == 1) {
      ans += H[0];
      break;
    }
    m = 0;
    max_index = 0;
    rep(i, H.size()) {
      if (m < H[i]) {
        m = H[i];
        max_index = i;
      }
    }

    if (max_index == 0) {
      ll c = H[0];
      ll r = H[1];
      ans += c - r;
    } else if (max_index == (ll)H.size() - 1) {
      ll l = H[H.size() - 2];
      ll c = H[H.size() - 1];
      ans += c - l;
    } else {
      ll l = H[max_index - 1];
      ll c = H[max_index];
      ll r = H[max_index + 1];
      if (l < r) {
        ans += c - r;
      } else {
        ans += c - l;
      }
    }
    H.erase(H.begin() + max_index);
  }

  COUT(ans);

  return 0;
}

Measured memory_bytes: 256
#pragma GCC optimize ("O3")
#pragma GCC target ("avx")
#include <bits/stdc++.h>

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

using namespace std;
using ll = long long;

static const int INFTY = 1e5 + 1;

/**
 * main
 */
int main () {
  int A, B, M;
  cin >> A >> B >> M;

  vector<int> a(A);
  vector<int> b(B);
  int min_a = INFTY;
  int min_b = INFTY;

  REP(i, 0, A) {
    int input;
    scanf("%d", &input);
    a[i] = input;
    if (a[i] < min_a) min_a = a[i];
  }
  REP(i, 0, B) {
    int input;
    scanf("%d", &input);
    b[i] = input;
    if (b[i] < min_b) min_b = b[i];
  }

  int min_price = min_a + min_b;

  REP(i, 0, M) {
    int x, y, c;
    scanf("%d %d %d", &x, &y, &c);

    int t = a[x - 1] + b[y - 1] - c;
    if (t < min_price) min_price = t;
  }

  cout << min_price << '\n';
}


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

using namespace std;

// int helper(const vector<vector<int>>& nums,int start,int day,vector<int>& dp){
//     if(start==nums.size()) return 0;
//     int include = 0;
//     if(dp[day]!=-1) return dp[day];
//     if(day==0){
//         include = max(include,nums[start][1]+helper(nums,start+1,1,dp));
//         include = max(include,nums[start][2]+helper(nums,start+1,2,dp));
//     }else if(day==1){
//         include = max(include,nums[start][0]+helper(nums,start+1,0,dp));
//         include = max(include,nums[start][2]+helper(nums,start+1,2,dp));
//     }else{
//         include = max(include,nums[start][1]+helper(nums,start+1,1,dp));
//         include = max(include,nums[start][0]+helper(nums,start+1,0,dp));
//     }
//     dp[day] = include;
//     return include;
// }

int main(){
    int n;cin>>n;
    vector<vector<int>> nums(n,vector<int>(3));
    for(int i=0;i<n;i++){
        for(int x:{0,1,2}) cin>>nums[i][x];
    }
    vector<vector<int>> dp(n+1,vector<int>(3,0));
    int sol = 0;
    for(int start=nums.size()-1;start>=0;start--){
        for(int day = 2;day>=0;day--){
            if(day==0){
               dp[start][day] = max(dp[start][day],nums[start][1]+dp[start+1][1]);
               dp[start][day] = max(dp[start][day],nums[start][2]+dp[start+1][2]);
            }else if(day==1){
               dp[start][day] = max(dp[start][day],nums[start][0]+dp[start+1][0]);
               dp[start][day] = max(dp[start][day],nums[start][2]+dp[start+1][2]);
            }else{
               dp[start][day] = max(dp[start][day],nums[start][1]+dp[start+1][1]);
               dp[start][day] = max(dp[start][day],nums[start][0]+dp[start+1][0]);
            }
        }
    }
    for(int i:{0,1,2}){
        sol = max(sol,dp[0][i]);
    }
    cout<<sol;

}


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


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

  vector<int> A(N);

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

  int num_of_sorted_elements = 0;

  while(num_of_sorted_elements < N) {
    auto it = lower_bound(A.begin(), A.begin() + num_of_sorted_elements + 1, A[num_of_sorted_elements]);
    A.insert(it, A[num_of_sorted_elements]);
    A.erase(A.begin() + num_of_sorted_elements + 1);
    num_of_sorted_elements += 1;
    for(int i = 0; i < N; i++) {
      if(i == N - 1) {
        cout << A[i] << endl;
      }else {
        cout << A[i] << ' ';
      }

    }
  }


}

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

using namespace std;

vector<pair<int,int>> job;
int n,m;

int main(void){
    int res = 0;
    cin >> n >> m;
    job.resize(n);
    for(int i=0;i<n;++i)cin >> job[i].first >> job[i].second;
    sort(job.begin(),job.end());
    priority_queue<int> que;
    int i = 0;
    for(int j=1;j<=m;++j){
        while(i<n && job[i].first <= j){
            que.push(job[i].second);
            i++;
        }
        if(!que.empty()){
            res += que.top();
            que.pop();
        }
    }
    cout << res << endl;
}

Measured memory_bytes: 1660
import sys, re, os
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians, acos, atan, asin, log, log10
from itertools import permutations, combinations, product, accumulate
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from fractions import gcd
def debug(*args):
    if debugmode:
        print(*args)
def input(): return sys.stdin.readline().strip()
def STR(): return input()
def INT(): return int(input())
def FLOAT(): return float(input())
def MAP(): return map(int, input().split())
def S_MAP(): return map(str, input().split())
def LIST(): return list(map(int, input().split()))
def S_LIST(): return list(map(str, input().split()))
def lcm(a, b): return a * b // gcd(a, b)
sys.setrecursionlimit(10 ** 9)
inf = sys.maxsize
mod = 10 ** 9 + 7
dx = [0, 0, 1, -1, 1, -1, -1, 1]
dy = [1, -1, 0, 0, 1, -1, 1, -1]
debugmode = True

s = [int(i) for i in STR()]
ans = 0
for i in range(1, len(s)):
    if s[i] == s[i - 1]:
        s[i] = int(not s[i - 1])
        ans += 1
print(ans)


Measured memory_bytes: 66136
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <math.h>
#include <complex>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
#include <bitset>
#include <assert.h>
#include <numeric>
#include <iomanip>
#define rep(i, a, b) for (int(i) = (a); i < (b); i++)
using namespace std;

using ll = long long;

typedef pair<int, int> P;

const int INF = 100000000;
const int dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};
const ll MOD = 1000000007;

ll pow_mod(ll x, ll y, ll mod)
{
	ll ans=1;
	for(;y>0;y>>=1){
		if(y&1)(ans*=x)%=mod;
		(x*=x)%=mod;
	}
	return ans;
}

ll a,b,x,y,ecnt;

int main()
{
	cin.tie(0);
	ios::sync_with_stdio(false);
	//問題文中の添え字が0-indexか1-indexか確認!
	cin >> a >> b;
	(!(a % 2)) ? x = 0 : (x = a,ecnt++);
	(b % 2) ? y = 0 : (y = b,ecnt++);
	if((b-a+1-ecnt)%4){
		cout << ((x ^ y) ^ 1);
	}else{
		cout << (x ^ y);
	}
	return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

//Fishnet
public class Main{

	double EPS = 1.0e-8;
	double norm(Point p) {
		return Math.hypot(p.x, p.y);
	}
	double inp(Point p1, Point p2) {
		return p1.x*p2.x + p1.y*p2.y;
	}
	double extp(Point p1, Point p2) {
		return p1.x*p2.y - p2.x*p1.y;
	}
	Point sub(Point p1, Point p2) {
		return new Point(p1.x-p2.x, p1.y-p2.y);
	}
	int ccw(Point a, Point b, Point c) {
		Point p = sub(b, a);
		Point q = sub(c, a);
		if(extp(p, q) > EPS) return 1;		// counter clockwise
		if(extp(p, q) < -EPS)return -1;		// clockwise
		if(inp(p, q) < -EPS) return 2;		// c--a--b on line
		if(Math.abs(norm(p) - norm(q)) < EPS) return -2;	// a--b--c on line
		return 0;				// a--c--b(or a--c=b) on line 
	}
	Point crosspoint(Line l, Line m) {
		if(isParallel(l, m)){
			throw new IllegalArgumentException("parallel");
		}
		  double A = extp(sub(l.t, l.s), sub(m.t, m.s));
		  double B = extp(sub(l.t, l.s), sub(l.t, m.s));
		  if (Math.abs(A) < EPS && Math.abs(B) < EPS) return m.s; // same line
		  if (Math.abs(A) < EPS) assert(false); // !!!PRECONDITION NOT SATISFIED!!!
		  Point tp = sub(m.t, m.s);
		  return new Point(m.s.x + B/A*tp.x, m.s.y + B/A*tp.y);
	}
	boolean isParallel(Line l, Line m){
		Point a = new Point(l.t.x - l.s.x, l.t.y - l.s.y);
		Point b = new Point(m.t.x - m.s.x, m.t.y - m.s.y);
		if(Math.abs(Math.abs((a.x*b.x + a.y*b.y)/(Math.hypot(a.x, a.y)*Math.hypot(b.x, b.y)) - 1)) < EPS){
			return true;
		}
		return false;
	}
	class Point {
		public double x;
		public double y;
		public Point(double x_, double y_) {
			x = x_; y=y_;
		}
	}
	class Line {
		public Point s,t;
		public Line(Point s_, Point t_) {
			s = s_; t = t_;
		}
	}
	
	void run(){
		Scanner sc = new Scanner(System.in);
		for(;;){
			int n = sc.nextInt();
			if(n==0)break;
			Point[][] p = new Point[4][n];
			for(int i=0;i<n;i++)p[0][i] = new Point(sc.nextDouble(), 0);
			for(int i=0;i<n;i++)p[1][i] = new Point(sc.nextDouble(), 1);
			for(int i=0;i<n;i++)p[2][i] = new Point(0, sc.nextDouble());
			for(int i=0;i<n;i++)p[3][i] = new Point(1, sc.nextDouble());
			Line[] v = new Line[n+2];
			Line[] h = new Line[n+2];
			v[0] = new Line(new Point(0, 0), new Point(0, 1));
			for(int i=1;i<=n;i++)v[i] = new Line(p[0][i-1], p[1][i-1]);
			v[n+1] = new Line(new Point(1,0), new Point(1,1));
			h[0] = new Line(new Point(0, 0), new Point(1,0));
			for(int i=1;i<=n;i++)h[i] = new Line(p[2][i-1], p[3][i-1]);
			h[n+1] = new Line(new Point(0,1), new Point(1,1));
			double max = 0;
			for(int i=0;i<=n;i++)for(int j=0;j<=n;j++){
				Point p1 = crosspoint(h[i], v[j]);
				Point p2 = crosspoint(h[i+1], v[j]);
				Point p3 = crosspoint(h[i+1], v[j+1]);
				Point p4 = crosspoint(h[i], v[j+1]);
				max = Math.max(max, Math.abs(extp(p1, p2)+extp(p2, p3)+extp(p3, p4)+extp(p4, p1)));
			}
			System.out.printf("%.7f\n", max/2);
		}
	}
	
	public static void main(String[] args) {
		new Main().run();
	}
}

Measured memory_bytes: 13000
n, m, c = map(int, input().split())
b = list(map(int, input().split()))
ans = 0
for i in range(n):
    s = 0
    a = list(map(int, input().split()))
    for j in range(m):
        s += a[j] * b[j]
    if s > -c:
        ans += 1
print(ans)

Measured memory_bytes: 3064
import collections

def f(n,b):
    ret = int()
    while n > 0:
        ret += n%b
        n //= b
    return ret

def solve():
    n = int(input())
    s = int(input())
    b = int(2)
    while b*b <= n:
        if f(n,b) == s:
            print(b)
            return
        b+=1
    b = 0
    a = int(1)
    while a*a <= n-s:
        if (n-s)%a == 0 and\
        (n-s)//a >= a and\
        (s-a) >= 0 and\
        (n-s)//a >= (s-a):
            b = (n-s)//a+1
            # print(b,s-a)
        a+=1
    if b > 0:
        print(b)
        return
    if n == s:
        print(n+1)
        return
    print(-1)
    return



if __name__ == "__main__":
    solve()


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

using namespace std;

//#define int long long
#define FOR(i, j, k) for(int i = j; i < (int)k; ++i)
#define rep(i, j) FOR(i, 0, j)
#define INF (1 << 30)

typedef unsigned long long ull;
typedef pair<int, int> P;
typedef pair<P, int> Pi;

const int MOD = 1e9 + 7;
const int dy[] = {0, 0, 1, -1};
const int dx[] = {1, -1, 0, 0};

template <class T> void chmin(T& a, const T& b) { a = min(a, b); }
template <class T> void chmax(T& a, const T& b) { a = max(a, b); }

int w[100], v[100];
int dp[101][10001];

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

    int N, W;
    cin >> N >> W;
    rep(i, N) cin >> v[i] >> w[i];
    fill(dp[0], dp[0] + 100 * 100 + 1, INF);
    dp[0][0] = 0;
    rep(i, N) rep(j, 10001) {
        if(v[i] > j) dp[i + 1][j] = dp[i][j];
        else dp[i + 1][j] = min(dp[i][j], dp[i][j - v[i]] + w[i]);
    }
    int res = 0;
    rep(i, 10001) if(dp[N][i] <= W) res = i;
    cout << res << endl;
    return 0;
}

Measured memory_bytes: 7076
<?php
$n = (int)trim(fgets(STDIN));
$a = explode(' ', trim(fgets(STDIN)));

$total = 0;
for ($i = 0; $i < $n; $i++) {
    if ($i === 0) {
        $total += abs((int)$a[$i]);
        continue;
    }

    $total += abs((int)$a[$i - 1] - (int)$a[$i]);

    if ($i === $n - 1) {
        $total += abs((int)$a[$i]);
        break;
    }
}

for ($i = 0; $i < $n; $i++) {
    if ($i === 0) {
        if (($a[$i] > 0 && $a[$i + 1] - $a[$i] > 0) || ($a[$i] < 0 && $a[$i + 1] - $a[$i] < 0)) {
            echo $total . PHP_EOL;
        } else {
            echo $total - abs($a[$i]) - abs($a[$i] - $a[$i + 1]) + abs($a[$i + 1]) . PHP_EOL;
        }
        continue;
    }

    if ($i === $n - 1) {
        if (($a[$i] > 0 && $a[$i - 1] > $a[$i]) || ($a[$i] < 0 && $a[$i - 1] < $a[$i])) {
            echo $total . PHP_EOL;
        } else if (($a[$i] > 0 && $a[$i - 1] > 0) || ($a[$i] < 0 && $a[$i - 1] < 0)) {
            echo $total - abs($a[$i] - $a[$i - 1]) * 2 . PHP_EOL;
        } else {
            echo $total - abs($a[$i]) * 2 . PHP_EOL;
        }
        break;
    }

    if (($a[$i] > $a[$i - 1] && $a[$i + 1] > $a[$i])
        || ($a[$i] < $a[$i - 1] && $a[$i + 1] < $a[$i])
    ) {
        echo $total . PHP_EOL;
    } else {
        echo $total - abs($a[$i - 1] - $a[$i]) - abs($a[$i] - $a[$i + 1]) + abs($a[$i - 1] - $a[$i + 1]) . PHP_EOL;
    }
}

Measured memory_bytes: 14068
# BFS的にやるDAGの最長経路
from collections import deque
import sys
sys.setrecursionlimit(10 ** 7)
input = sys.stdin.readline

n, m = map(int, input().split())

g = [[] for _ in range(n)]
indeg = [0 for _ in range(n)]

for _ in range(m):
    x, y = map(int, input().split())
    g[x-1].append(y-1)
    # 入力を持つ点から始めても最長辺は作れない
    indeg[y-1] += 1

dp = [0 for _ in range(n)]
q = deque([])

# 最長辺の候補を入れる
for i in range(n):
    if indeg[i] == 0:
        q.append(i)

while q:
    v = q.popleft()
    for w in g[v]:
        indeg[w] -= 1
        if indeg[w] == 0:
            q.append(w)
            dp[w] = max(dp[w], dp[v] + 1)

print(max(dp))


Measured memory_bytes: 60848
import numpy as np
from collections import Counter
N = int(input())
A = list(map(int,input().split()))

B = np.array(A) - np.arange(1,N+1)
C = np.array(A) + np.arange(1,N+1)

cntB = Counter(B)
cntC = Counter(C)

ans = 0
for k,v in cntB.items():
    ans += v * cntC[-k]
print(ans)





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

int n;
int v[100];
int c[100];

int calc(int ans, int index){
    if(index >= n){
        return ans;
    }
    return max(calc(ans, index+1), calc(ans + v[index]-c[index], index+1));
}

int main(){
    cin >> n;
    for(int i = 0; i < n; i++){
        cin >> v[i];
    }
    for(int i = 0; i < n; i++){
        cin >> c[i];
    }
    cout << calc(0, 0) << endl;   
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define mp make_pair
#define pb push_back
#define IOS ios::sync_with_stdio(false); cin.tie(0);
#define sd(n) scanf("%d",&n)
#define sl(n) scanf("%lld",&n)
#define pd(n) printf("%d",n)
#define pl(n) printf("%lld",n)
#define sf(n) scanf("%f",&n)
#define pf(n) printf("%.12f",n)
#define psp printf(" ")
#define endc printf("\n")

using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int,int> pii;

const int maxn = 520;


int main() {
	IOS;; string s = "RYGB";
	int h,w,d; cin>>h>>w>>d;
	for (int i = 1; i <= h; i++) {
		for (int j = 1; j <= w; j++) {
			int a = i+j, b = i-j;
			a/=d; b=floor(b*1.0/d); a%=2; b=abs(b)%2;
			//cout<<i<<":"<<j<<" -> "<<a<<":"<<b<<endl;
			cout<<s[a*2 + b];
		}
		cout<<endl;
	}
}

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

int main (){
	int N, AC = 0, WA = 0, TLE = 0, RE = 0;
	scanf ("%d", &N);
	
	for (int i = 0; i < N; i++){
		char str[10];
		scanf ("%s", str);
	if (strcmp(str, "AC") == 0) { // "AC" - "AC" = 0
		AC++;
	}
	else if (strcmp(str, "WA") == 0) { // "AC" - "AC" = 0
		WA++;
	}
	else if (strcmp(str, "TLE") == 0) { // "AC" - "AC" = 0
		TLE++;
	}
	else if (strcmp(str, "RE") == 0) { // "AC" - "AC" = 0
			RE++;
		}
	}
	
	printf ("AC x %d\n", AC); 
	printf ("WA x %d\n", WA);
	printf ("TLE x %d\n", TLE);
	printf ("RE x %d\n", RE);
	
	return 0;
}

Measured memory_bytes: 1712
n = int(input())
base = []
i = 1
j = 1
i_6 = 6
i_9 = 9
dp = [float("inf")]*(n+1)
dp[0] = 0

base.append(1)

while i_6<=n:
  i_6 = 6**i
  base.append(i_6)
  i = i+1
  
while i_9<=n:
  i_9 = 9**j
  base.append(i_9)
  j = j+1
  
base.sort()
base_n = len(base)

for i  in range(1,n+1):
  for j in range(base_n):
    if 0 > i-base[j]:
      break
     
    temp = dp[i-base[j]]
    if temp < dp[i]:
      dp[i] = temp + 1
      
    
print(dp[n])

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

using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
ll s,w;
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    cin>>s>>w;
    if(w>=s)
        cout<<"unsafe";
    else
        cout<<"safe";
    return 0;
}


Measured memory_bytes: 3652
from collections import deque

h, w = map(int, input().split())
start_h, start_w = map(int, input().split())
goal_h, goal_w = map(int, input().split())

start_h += 1
start_w += 1
goal_h += 1
goal_w += 1

s = ["#"*(w+4)]
s.append("#"*(w+4))
for _ in range(h):
    s.append("##" + input() + "##")
s.append("#"*(w+4))
s.append("#"*(w+4))

ans = [[-1]*(w+4) for _ in range(h+4)]
for i in range(h+4):
    for j in range(w+4):
        if s[i][j] == "#":
            ans[i][j] = -2
ans[start_h][start_w] = 0

move1 = [(-1, 0), (1, 0), (0, -1), (0, 1)]
move2 = [(-2, -2), (-2, -1), (-2, 0), (-2, 1), (-2, 2),(-1, -2), (-1, -1), (-1, 0), (-1, 1), (-1, 2),(0, -2), (0, -1), (0, 0), (0, 1), (0, 2),(1, -2), (1, -1), (1, 0), (1, 1), (1, 2),(2, -2), (2, -1), (2, 0), (2, 1), (2, 2)]

yet = deque([(start_h, start_w)])
done = deque()

while len(yet) > 0:
    x1, y1 = yet.popleft()
    done.append((x1, y1))
    for (p, q) in move1:
        v1, v2 = x1+p, y1+q
        if ans[v1][v2] == -1: #"."でまだ辿り着いていないマス
            yet.append((v1, v2))
            ans[v1][v2] = ans[x1][y1]

    if len(yet) == 0:
        while len(done) > 0:
            x2, y2 = done.popleft()
            for (p, q) in move2:
                i, j = x2+p, y2+q
                if ans[i][j] == -1:
                    ans[i][j] = ans[x2][y2]+1
                    yet.append((i, j))

print(ans[goal_h][goal_w])


Measured memory_bytes: 91276
import java.io.*;

public class Main{
public static void main(String[] args){
	try{
	BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
	String str = br.readLine();
	int s = Integer.parseInt(str);

		if((0 <= s) && (s < 86400)){
		int hour = s/(60*60);
		int minute = s%(60*60)/60;
		int second = s%(60*60)%60;
		System.out.println(hour + ":" + minute + ":" + second);
		}
	}catch(IOException e){
	System.out.println(e);
	}
}
}

Measured memory_bytes: 16976
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i=0; i<(n); i++)
int main(){
  
    int n;
    cin >> n;
	
  	if(n == 1)
  		cout << "Hello World" << endl;
  	else{
		int a, b;
      	cin >> a >> b;
      	cout << a + b << endl;
    }
    return 0;
}


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

using namespace std;

int main()
{
    int n;
    cin >> n;
    vector<char> s(n);
    for (int i = 0; i < n; i++)
        cin >> s[i];

    int color = 0;
    for (int i = 0; i < n; i++)
    {
        if (s[i] == 'Y')
            color++;
    }
    cout << (color ? "Four" : "Three") << endl;
}

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

int mod = 1000000007;
int64_t large = 9223372036854775807;

int main()
{
    string S;
    cin >> S;
    sort(S.begin(), S.end());
    cout << (S[0] == S[1] && S[1] != S[2] && S[2] == S[3] ? "Yes" : "No");
}

Measured memory_bytes: 256
#include <algorithm>
#include <cstdio>
#include <iostream>
#include <cfloat>
#include <climits>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <queue>
#include <sstream>
#include <stack>
#include <time.h>
#include <vector>
#include <complex>
using namespace std;
int main(){
  int a,b,c;
  cin>>a>>b>>c;
  for (int i=0;;i++)
  for (int j1=0;j1<=i;j1++)
    for (int j2=0;j2<=i-j1;j2++)
      for (int j3=0;j3<=i-j1-j2;j3++)
        for (int q1=0;q1 <= i -j1 - j2 - j3;q1++)
          for (int q2=0;q2 <= i - j1 -j2 - j3 - q1;q2++)
            for (int q3=0;q3 <= i - j1 - j2 - j3 - q1 - q2;q3++)
              if (((a + j1 + j2 + q1 * 2) == (b + j1 + j3 + q2 * 2)) and ((b + j1 + j3 + q2 * 2) ==  (c + j2 + j3 + q3 * 2))){
                cout<<i;
                system ("pause");
                return 0;
              }
}

Measured memory_bytes: 504
# define _CRT_SECURE_NO_WARNINGS 1
# include <iostream>
# include <string>
# include <bitset>
# include <vector>
# include <algorithm>
# include <cstdlib>
# include <cstdio>
# include <cstring>
# include <cstdlib>
# include <iomanip>
# include <queue>
# include <sstream>
# include <climits>
# include <cmath>
# include <list>
# include <functional>
# include <string>
# include <ctime>
# include <set>
# include <map>
# include <stack>
using namespace std;
# define M_PI 3.141592
# define FOR(i,n) for(int i=0;i<(int)n;i++)
# define FORI(i,k,n) for(int i=k;i<(int)n;i++)
# define toRad 2.0*M_PI/360.0
# define inin(x) int x;cin>>x;
# define all(x) x.begin(),x.end()
# define debug(x) cout<<#x<<" :"<<x<<endl;
# define rep(i,n) for(int i=0;i<(int)n;i++)
# define EPS 1e-12
# define CHECK(i,a) FOR(i,a.size())cout<<#a<<"["<<i<<"] : "<<a[i]<<endl; 

int main()
{
	int y, x;
	while (cin >> y >> x&&y)
	{
		int a[600][600] = {};
		for (int i = 1; i <= y; i++)
		{
			for (int l = 1; l <= x; l++)
			{

				char z; cin >> z;
				if (z == '*')a[i][l] = 1;
			}
		}

		for (int i = 1; i <= y; i++)
		{
			for (int l = 1; l <= x; l++)
			{
				a[i][l] += a[i][l - 1];
			}
		}
		for (int i = 1; i <= x; i++)
		{
			for (int l = 1; l <= y; l++)
			{
				a[l][i] += a[l - 1][i];
			}
		}

		int ans = 0;
		for (int i = 1; i <= y; i++)
		{
			for (int l = 1; l <= x; l++)
			{
				bool ok = true;
				for (int I = y; I >= i&&ok; I--)
				{
					for (int L = l; L <=x&&ok; L++)
					{
						int c = a[I][L];
						c += a[i - 1][l - 1];
						c -= a[i - 1][L];
						c -= a[I][l - 1];
						if (c == 0)
						{
							int d = (I - i + 1)*(L - l + 1);
							ans = max(ans, d);
						}
						else
						{
							break;
						}
					}
				}

			}
		}
		cout << ans << endl;
	}

}

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

using namespace std;

int main()
{
    long n, t, a, t_ans=1, a_ans=1;
    cin>>n;
    for (int i=0; i<n; i++)
    {
        cin>>t>>a;
        long long m=max((t_ans+t-1)/t, (a_ans+a-1)/a);
        t_ans=t*m;
        a_ans=a*m;
    }
    cout<<t_ans+a_ans<<'\n';
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using lint = long long;
template<class T = int> using V = vector<T>;
template<class T = int> using VV = V< V<T> >;

using R = long double;
constexpr R pi = acos((R)-1), eps = 1e-10;

int sgn(R a) { return (a > eps) - (a < -eps); }
int sgn(R a, R b) { return sgn(a - b); }
using P = complex<R>;
istream& operator>>(istream& i, P& p) { R x, y; i >> x >> y; p = P(x, y); return i; }
ostream& operator<<(ostream& o, P p) { return o << fixed << setprecision(15) << real(p) << ' ' << imag(p); }
bool cmp(P p, P q) { return 2 * sgn(real(p), real(q)) + sgn(imag(p), imag(q)) < 0; }
bool eql(P p, P q) { return !cmp(p, q) and !cmp(q, p); }
R dot(P p, P q) { return real(conj(p) * q); }
R crs(P p, P q) { return imag(conj(p) * q); }
// -2: back, -1: cw, 0: on, 1: ccw, 2: front
int ccw(P p, P q) {
  int s = sgn(crs(p, q));
  if (s) return s;
  if (dot(p, q) < 0) return -2;
  if (dot(p, q - p) > 0) return 2;
  return 0;
}
int ccw(P o, P p, P q) { return ccw(p - o, q - o); }
struct L {
  P s, t;
  P vec() const { return t - s; }
  R abs() const { return std::abs(vec()); }
  R arg() const { return std::arg(vec()); }
};
int ccw(L s, P p) { return ccw(s.s, s.t, p); }

P proj(P p, L l) {
  P e = l.vec() / l.abs();
  return l.s + dot(p - l.s, e) * e;
}
P refl(P p, L l) { return (R)2 * proj(p, l) - p; }
R distPP(P p, P q) { return abs(q - p); }
R distPL(P p, L l) { return distPP(p, proj(p, l)); }
R distPS(P p, L s) {
  P q = proj(p, s);
  if (!ccw(s, q)) return distPP(p, q);
  return min(distPP(p, s.s), distPP(p, s.t));
}
R distLL(L l, L m) {
  if (sgn(crs(l.vec(), m.vec()))) return 0;
  return distPL(l.s, m);
}
R distLS(L l, L s) {
  if (ccw(l, s.s) * ccw(l, s.t) != 1) return 0;
  return min(distPL(s.s, l), distPL(s.t, l));
}
R distSS(L s, L t) {
  if (ccw(s, t.s) * ccw(s, t.t) <= 0 and ccw(t, s.s) * ccw(t, s.t) <= 0) return 0;
  return min({distPS(s.s, t), distPS(s.t, t), distPS(t.s, s), distPS(t.t, s)});
}
P intxn(L l, L m) {
  assert(sgn(crs(l.vec(), m.vec())));
  return l.s + crs(m.s - l.s, m.vec()) / crs(l.vec(), m.vec()) * l.vec();
}

// BEGIN CUt HERE
using G = V<P>;
R area(const G& g) {
  if ((int)g.size() < 3) return 0;
  R res = 0;
  P a = g.back();
  for (P b : g) {
    res += crs(a, b) / 2;
    a = b;
  }
  return res;
}
// -1: in, 0: on, 1: out
int contains(const G& g, P p) {
  assert(g.size() >= 3);
  int c = 0;
  P q = p + P(pi, 1), a = g.back();
  for (P b : g) {
    if (!ccw(a, b, p)) return 0;
    if (!sgn(distLS({p, q}, {a, b}))) {
      c += ccw(p, q, intxn({p, q}, {a, b})) >= 0;
    }
    a = b;
  }
  return c & 1 ? -1 : 1;
}
// END CUT HERE

int main() {
  cin.tie(nullptr); ios::sync_with_stdio(false);
  int n; cin >> n;
  G g(n); for (auto&& e : g) cin >> e;
  int q; cin >> q;
  while (q--) {
    P p; cin >> p;
    cout << 1 - contains(g, p) << '\n';
  }
}

// https://onlinejudge.u-aizu.ac.jp/status/users/risujiroh/submissions/1/CGL_3_A/judge/3574786/C++14


Measured memory_bytes: 3392
#include <bits/stdc++.h>
#define pb push_back
#define mp make_pair
#define pii pair <int, int>
#define fi first
#define sc second
#define ALL(x) x.begin(), x.end()
#define RALL(X) x.begin(), x.end()
#define FOR(i, n, k) for(i=0; i<n; i+=k)
#define FO(i, n, k) for(i=1; i<=n; i+=k)
#define CLEAR(a, b) memset(a, b, sizeof(a))
#define N 100005
#define mid ((l+r)/2)
#define dbg(x) (cerr << #x << " : " << x << endl)
#define endl "\n"
#define MOD 100000009

using namespace std;

typedef long long int lli;

int main(){
	ios_base::sync_with_stdio(false);
	map <string, lli> mp;
	int n;
	cin >> n;
	for(int i=0; i<n; i++){
		string a;
		cin >> a;
		sort(ALL(a));
		mp[a]++;
	}

	lli res=0;
	for(auto it=mp.begin(); it!=mp.end(); it++){
		res += (it->second) * (it->second - 1LL) / 2LL;
	}
	cout << fixed << res;
	return 0;
}

Measured memory_bytes: 11264
a,b = map(int, input().split())
c = []
if a == b:
    for i in range(a):
        c.append(a)
    print(int("".join(map(str, c))))
if a > b:
    for i in range(a):
        c.append(b)
    print(int("".join(map(str, c))))
if a < b:
    for i in range(b):
        c.append(a)
    print(int("".join(map(str, c))))
          


Measured memory_bytes: 3060
import java.util.Scanner;

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

        int R = sc.nextInt();

        String rating;

        if(R < 1200){
            rating = "ABC";
        } else if (R < 2800) {
            rating = "ARC";
        } else {
            rating = "AGC";
        }

        System.out.println(rating);
    }
}

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

int main() {
  int N;
  cin >> N;
  
  int a;
  a = N / 1000;
  
  int b;
  b = N % 10;
  
  if ((N - a * 1000) % 111 == 0){
    cout << "Yes" << endl;
    return 0;
  }
  
  
  if ((N - b) % 111 == 0){
    cout << "Yes" << endl;
    return 0;
  }
  
  else if ((N - a * 1000) % 111 != 0){
    cout << "No" << endl;
   return 0;
  }
  
	else if ((N - b) % 111 != 0){
      cout << "No" << endl;
      return 0;
}

}

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

int main () {
  int N, M;
  cin >> N >> M;
  vector<int> Road(N);
  
  for (int i = 0; i < M; i++) {
    int a, b;
    cin >> a >> b;
    Road.at(a-1) ++;
    Road.at(b-1) ++;
  }
  for (int i = 0; i < N; i++) {
    cout << Road.at(i) << endl;
  }
}

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

long int dp[100007][3];
int main(){
  long int n,a,b,c;

  scanf("%ld",&n);
 
  scanf("%ld%ld%ld",&a,&b,&c);
  
  dp[0][0]=a;
  dp[0][1]=b;
  dp[0][2]=c;

  
  for(int i=1;i<n;i++){
    scanf("%ld%ld%ld",&a,&b,&c);
    dp[i][0]=max(dp[i-1][1]+a,dp[i-1][2]+a);
    dp[i][1]=max(dp[i-1][0]+b,dp[i-1][2]+b);
    dp[i][2]=max(dp[i-1][0]+c,dp[i-1][1]+c);
  }
  
  printf("%ld\n",max(dp[n-1][0],max(dp[n-1][1],dp[n-1][2])));
  
  return 0;
}

Measured memory_bytes: 2560
N=int(input())
A=list(map(int,input().split()))
l=abs(A[0])
ans=0
for i in range(N-1):
  if A[i]<0:
    ans-=A[i]
    A[i+1]*=-1
  else:
    ans+=A[i]
  l=min(abs(A[i]),l)
if A[-1]<0:
  ans+=-A[-1]-min(l,abs(A[-1]))*2
else:
  ans+=A[-1]
print(ans)

Measured memory_bytes: 84968
#include <bits/stdc++.h>
using namespace std;
using ll = int64_t;
#define rep(i,n) for(int i = 0; i < ((int)(n)); i++)   // 0-indexed昇順

int main() {
    int N, A, B;
    cin >> N >> A >> B;
    if (A * N > B) {
        cout << B << endl;
    } else {
        cout << A * N << endl;
    }
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <array>
#include <set>
#include <cmath>
#include <string>
#include <queue>
#include <list>
#include <stack>
#include <unordered_map>
#include <algorithm>
#include <numeric>
#include <functional>
#include <cassert>
#include <cctype>  // std::islower(), std::isupper(), std::tolower, std::toupper
#include <iomanip> // std::std::setprecision(X)
#include <limits>  //std::numeric_limits<int>::max(), min()

typedef long long ll;

int main (void) {
  std::string N; std::cin >> N;
  if ( N[0] == N[1] && N[1] == N[2] ) {
    std::cout << "Yes" << std::endl;
    return 0;
  }

  if ( N[1] == N[2] && N[2] == N[3] ) {
    std::cout << "Yes" << std::endl;
    return 0;
  }

  std::cout << "No" << std::endl;

  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
struct Dice{
    int x[6];
    void input(){
        for(int i=0;i<6;i++){
            cin>>x[i];
        }
    }
    void rollforward(){
        int tmp=x[0];
        x[0]=x[1];
        x[1]=x[5];
        x[5]=x[4];
        x[4]=tmp;
    }
    void rollside(){
        int tmp=x[1];
        x[1]=x[3];
        x[3]=x[4];
        x[4]=x[2];
        x[2]=tmp;
    }
    bool operator==(Dice a){
        for(int i=0;i<6;i++){
            if(x[i]!=a.x[i])    return false;
        }
        return true;
    }
};
bool check(Dice a,Dice b){
    for(int i=0;i<4;i++){
        for(int j=0;j<4;j++){
            if(a==b)    return true;
            a.rollside();
        }
        a.rollforward();
    }
    a.rollside();
    a.rollforward();
    for(int i=0;i<4;i++){
        if(a==b)    return true;
        a.rollside();
    }
    a.rollforward();
    a.rollforward();
    for(int i=0;i<4;i++){
        if(a==b)    return true;
        a.rollside();
    }
    return false;
}
int main(){
    Dice a,b;
    a.input();  b.input();
    cout<<(check(a,b)?"Yes":"No")<<endl;
    return 0;
}


Measured memory_bytes: 3076
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;

namespace Contest
{
    class MainClass
    {
        public static void Main(string[] args)
        {
            int n = int.Parse(Console.ReadLine());
            var p = Console.ReadLine().Split().Select(int.Parse).ToArray();
            int ans = 0;
            for (int i = 1; i < n - 1; i++)
            {
                if (new[] { p[i - 1], p[i], p[i + 1] }.Max()!=p[i] && new[] { p[i - 1], p[i], p[i + 1] }.Min() != p[i])
                {
                    ans++;
                }
            }
            Console.WriteLine(ans);
        }
    }
}

Measured memory_bytes: 13396
#define DEBUG 1
#include <bits/stdc++.h>
#define loop(n) for (lint ngtkana_is_a_genius = 0; ngtkana_is_a_genius < lint(n); ngtkana_is_a_genius++)
#define rep(i, begin, end) for (lint i = lint(begin); (i) < lint(end); i++)
#define all(v) v.begin(), v.end()
#define rand(l, r) std::uniform_int_distribution<>(l, r)(mt)
using lint = long long;
auto mt = std::mt19937_64(std::random_device{}());
auto cmn = [](auto&& a, auto b){ if (a > b) {a = b; return true;} return false; };
auto cmx = [](auto&& a, auto b){ if (a < b) {a = b; return true;} return false; };
void debug_impl() { std::cerr << std::endl; }
template <typename Head, typename... Tail>
void debug_impl(Head head, Tail... tail) { std::cerr << " " << head; debug_impl(tail...); }
#if DEBUG
#define debug(...)\
    do {\
        std::cerr << std::boolalpha << "[" << #__VA_ARGS__ << "]:";\
        debug_impl(__VA_ARGS__);\
        std::cerr << std::noboolalpha;\
    } while (false)
#else
#define debug(...) {}
#endif

template < typename Container, typename Value = typename Container::value_type, std::enable_if_t<!std::is_same< Container, std::string >::value, std::nullptr_t> = nullptr>
std::istream& operator>> (std::istream& is, Container& v)
    { for (auto & x : v) { is >> x; } return is; }

template < typename Container, typename Value = typename Container::value_type, std::enable_if_t<!std::is_same< Container, std::string >::value, std::nullptr_t> = nullptr >
std::ostream& operator<< (std::ostream& os, Container const& v) {
 os << "{";
    for (auto it = v.begin(); it != v.end(); it++)
        {os << (it != v.begin() ? "," : "") << *it;}
    return os << "}";
}

int main() {
    std::cin.tie(0); std::cin.sync_with_stdio(false);
    int n; std::cin >> n;
    std::vector<int>a(n);
    std::cin>>a;
    std::sort(all(a));
    std::cout << ((a.end()==std::unique(all(a)))?"YES":"NO") << std::endl;
    return 0;
}

Measured memory_bytes: 1024
#include <stdio.h>
#include <math.h>

int main(){
  int S;
  scanf("%d",&S);

  int A = S/1000;
  int B = (S - A*1000)/100;
  int C = (S - A*1000 - B*100)/10;
  int D = (S - A*1000 - B*100 - C*10);


  if (A != B && B != C && C != D) {
    printf("Good\n");
  } else {
    printf("Bad\n");
  }
  return 0;
}


Measured memory_bytes: 128
#include<bits/stdc++.h>
using namespace std;
int main(){
  int N ;
  cin >> N;
  int p = N /1.08 ;
  int q = p*1.08;
  int r = (p+1)*1.08;
  int s = (p-1)*1.08;
  if(q== N){
    cout << p << endl;
    return 0;
  }
  else if(r == N){
    cout << p+1 << endl;
    return 0;
  }
  else if(s== N){
    cout << p-1 << endl;
    return 0;
  }
  else{
    cout << ":(" << endl;
  }
}



Measured memory_bytes: 256
#include<stdio.h>
int main()
{
	int a,b,c,d;
	scanf("%d%d%d%d",&a,&b,&c,&d);
	if(a-c<=d&&c-a<=d)
		{
			printf("Yes\n");
		}
	else if(a-c>d||c-a>d)
		{
			if(b-c<=d&&c-b<=d&&a-b<=d&&b-a<=d)
				printf("Yes\n");
			else 
				printf("No\n");
		}
	else if(a==b==c)
		printf("Yes\n");
	else
		printf("No\n");
	return 0;
	
}

Measured memory_bytes: 1664
class UnionFind():
    def __init__(self, n):
        self.n = n
        self.parents = [-1] * n

    def find(self, x):
        if self.parents[x] < 0:
            return x
        else:
            self.parents[x] = self.find(self.parents[x])
            return self.parents[x]

    def union(self, x, y):
        x = self.find(x)
        y = self.find(y)

        if x == y:
            return

        if self.parents[x] > self.parents[y]:
            x, y = y, x

        self.parents[x] += self.parents[y]
        self.parents[y] = x

    def size(self, x):
        return -self.parents[self.find(x)]

    def same(self, x, y):
        return self.find(x) == self.find(y)

    def members(self, x):
        root = self.find(x)
        return [i for i in range(self.n) if self.find(i) == root]

    def roots(self):
        return [i for i, x in enumerate(self.parents) if x < 0]

    def group_count(self):
        return len(self.roots())

    def all_group_members(self):
        return {r: self.members(r) for r in self.roots()}

    def __str__(self):
        return '\n'.join('{}: {}'.format(r, self.members(r)) for r in self.roots())


n, m = map(int, input().split())
uf = UnionFind(n)

for i in range(m):
    a, b = map(int, input().split())
    uf.union(a-1, b-1)
nux = 0
for r in uf.roots():
    nux = max(nux, uf.size(r))

print(nux)


Measured memory_bytes: 18316
inline long long in() {
  long long n = 0;
  char c = getchar_unlocked();
  while ('0' <= c && c <= '9') {
    n *= 10;
    n += (c - '0');
    c = getchar_unlocked();
  }
  return n;
}

int main() {
  long long I = in(), O = in(), T = in(), J = in(), L = in();
  long long n = (I&1?I-1:I) + (J&1?J-1:J) + (L&1?L-1:L);
  if (I && J && L) {
    long m = (I&1?I-1:I-2) + (J&1?J-1:J-2) + (L&1?L-1:L-2) + 3;
    printf("%lld", (n<m?m:n) + O);
  } else {
    printf("%lld", n + O);
  }
}

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

#define rep(i,n) for(int i=0; i<(n); i++)

using namespace std;

const int INF = 0xfffffff;

int N, M, R;
vector<int> z;

int dl[256][256], ds[256][256], dp[1024][256];

int main(){
	int N, M;
	while(cin >> N >> M, N|M){
		rep(i, 256) rep(j, 256) dl[i][j] = ds[i][j] = INF;
		rep(i, 1024) rep(j, 256) dp[i][j] = INF;
		z.clear();
		rep(i, M) {
			int x, y, t;
			char sl;
			cin >> x >> y >> t >> sl;
			x--; y--;
			if(sl == 'L') {
				dl[x][y] = min(dl[x][y], t);
				dl[y][x] = min(dl[y][x], t);
			} else {
				ds[x][y] = min(ds[x][y], t);
				ds[y][x] = min(ds[y][x], t);
			}
		}
		cin >> R;
		rep(i, R) {
			int tmp;
			cin >> tmp;
			tmp--;
			z.push_back(tmp);
		}
		//cout << "kita" << endl;
		//rep(i, z.size()) cout << z[i] << endl;
		//cout << "kita" << endl;
		rep(k, N) {
			rep(i, N) {
				rep(j, N) {
					if(i == j) {
						dl[i][j] = ds[i][j] = 0;
					}
					dl[i][j] = min(dl[i][j], dl[i][k] + dl[k][j]);
					ds[i][j] = min(ds[i][j], ds[i][k] + ds[k][j]);
				}
			}
		}
		rep(i, N) {
			dp[0][i] = ds[z[0]][i] + dl[i][z[0]];	
		}
		for(int i = 1; i < R; i++) {
			rep(j, N) {
				rep(k, N) {
					if(j != k) {
						dp[i][k] = min(dp[i][k], dp[i-1][j] + dl[z[i-1]][j] + ds[j][k] + dl[k][z[i]]);
					} else {
						dp[i][j] = min(dp[i][j], dp[i-1][j] + dl[z[i-1]][z[i]]);
					}
				}
			}
		}
		int ans = INF;
		rep(i, N) {
			ans = min(ans, dp[R-1][i]);
			//cout << dp[R-1][i] << endl;
		}
		cout << ans << endl;
	}
	return 0;
}

Measured memory_bytes: 2764
import sys, bisect, math, itertools, string, queue, copy
import numpy as np
import scipy
from collections import Counter,defaultdict,deque
from itertools import permutations, combinations
from heapq import heappop, heappush
from fractions import gcd
input = sys.stdin.readline
sys.setrecursionlimit(10**8)
mod = 10**9+7
def inp(): return int(input())
def inpm(): return map(int,input().split())
def inpl(): return list(map(int, input().split()))
def inpls(): return list(input().split())
def inplm(n): return list(int(input()) for _ in range(n))
def inplL(n): return [list(input()) for _ in range(n)]
def inplT(n): return [tuple(input()) for _ in range(n)]
def inpll(n): return [list(map(int, input().split())) for _ in range(n)]
def inplls(n): return sorted([list(map(int, input().split())) for _ in range(n)])

x = inp()
ans = 'No'
if x >= 30:
    ans = 'Yes'

print(ans)

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

int dp[100001] = {0};
vector<int> frog;

int rec(int n,int k) {
	if(n == 1) return abs(frog[1] - frog[0]);
	if(n <= 0) return 0;

	if(dp[n] != -1) return dp[n];
	int ans = INT_MAX;
	for(int i=1;i<=k;i++) {
		if(n - i >= 0) {
			int a = abs(frog[n] - frog[n-i]) + rec(n-i,k);
			ans = min(ans,a);
		}
	}
	return dp[n] = ans;
}

int main() {
	int n,k;
	cin >> n >> k;
	frog.resize(n);
	memset(dp,-1,sizeof(dp));
	for(auto &i:frog) cin >> i;
	cout << rec(n-1,k);
}

Measured memory_bytes: 11892
#include <iostream>

typedef long long ll;

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

#define debug(x) cout << #x << "=" << x << endl;

using namespace std;

#define N 10

int cost[N][N];

void warshall_floyd(){
  REP(k,N){
      REP(i,N){
          REP(j,N){
            cost[i][j] = min(cost[i][j], cost[i][k] + cost[k][j]);
          }
      }
  }
}

int main(void){

  int h,w;
  cin >> h >> w;

  REP(i,N){
    REP(k,N){
      cin >> cost[i][k];
    }
  }

  warshall_floyd();

  int a[h][w];

  REP(i,h){
    REP(k,w){
      cin >> a[i][k];
    }
  }

  long long ans = 0;

  REP(i,h){
    REP(k,w){

      if(a[i][k] == -1 || a[i][k] == 1) continue;
      
      ans += cost[a[i][k]][1];
    }
  }

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


Measured memory_bytes: 384
#define HOURS 0
#define MINUTES 1
#define SECONDS 2

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

int main(void)
{
	int a[2][3], b[2][3], c[2][3];
	int result[3];
	
	cin >> a[0][HOURS] >> a[0][MINUTES] >> a[0][SECONDS];
	cin >> a[1][HOURS] >> a[1][MINUTES] >> a[1][SECONDS];
	
	cin >> b[0][HOURS] >> b[0][MINUTES] >> b[0][SECONDS];
	cin >> b[1][HOURS] >> b[1][MINUTES] >> b[1][SECONDS];
	
	cin >> c[0][HOURS] >> c[0][MINUTES] >> c[0][SECONDS];
	cin >> c[1][HOURS] >> c[1][MINUTES] >> c[1][SECONDS];
	
	result[0] = (a[1][HOURS] * 3600 + a[1][MINUTES] * 60 + a[1][SECONDS]) - (a[0][HOURS] * 3600 + a[0][MINUTES] * 60 + a[0][SECONDS]);
	result[1] = (b[1][HOURS] * 3600 + b[1][MINUTES] * 60 + b[1][SECONDS]) - (b[0][HOURS] * 3600 + b[0][MINUTES] * 60 + b[0][SECONDS]);
	result[2] = (c[1][HOURS] * 3600 + c[1][MINUTES] * 60 + c[1][SECONDS]) - (c[0][HOURS] * 3600 + c[0][MINUTES] * 60 + c[0][SECONDS]);
	
	cout << result[0] / 3600 << " " << (result[0] % 3600) / 60 << " " << (result[0]) % 3600 % 60 << endl;
	cout << result[1] / 3600 << " " << (result[1] % 3600) / 60 << " " << (result[1]) % 3600 % 60 << endl;
	cout << result[2] / 3600 << " " << (result[2] % 3600) / 60 << " " << (result[2]) % 3600 % 60 << endl;
	
	return 0;
}

Measured memory_bytes: 1164