akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
typedef long long ll;
typedef pair<int, int> P;

int main() {
    string s; cin >> s;
    int N = s.size();
    int pcnt = 0;
    rep(i, N){
        if(s[i] == 'p')pcnt++;
    }

    int at = N/2;
    cout << at-pcnt << endl;

    return 0;
}

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

int main(){
    int money; cin >> money;
    int sum=0;
    while (money>=500){
        sum+=1000;
        money-=500;
    }
    while (money>=5){
        sum+=5;
        money-=5;
    }
    cout << sum << endl;
    return 0;
}

Measured memory_bytes: 256
//Author: master19
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
#define ll long long int
#define ff first 
#define ss second 
#define pb push_back
#define endl "\n"
#define PI acos(-1.0)
#define mod 1000000007LL // fixed...
#define modd 1000000007LL // Can be changed for global use
#define yes cout << "YES\n"
#define no cout << "NO\n"
#define Yes cout << "Yes\n"
#define No cout << "No\n"
#define all(arr) arr.begin(),arr.end()
#define x(arr) arr.begin(),arr.end()
#define ulli unsigned long long int
#define assign(x,val) memset(x,val,sizeof(x))
#define prec(val, dig) fixed << setprecision(dig) << val
#define Sort(arr) sort(arr.begin(), arr.end())
#define lower(str) transform(str.begin(), str.end(), str.begin(), ::tolower);
#define upper(str) transform(str.begin(), str.end(), str.begin(), ::toupper);
#define crap ios_base :: sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define get(arr, num) vector < ll > arr(num); for(int i=0; i<num; i++)cin >> arr[i];
#define get_set(arr, num, st, type) set < type > st; for(int i=0; i<num; i++) st.insert(arr[i]);
#define put(arr, num) for(int i=0; i<num; i++)cout << arr[i] << " "; cout << endl;
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update > new_ds; 
ll lets_do_it();
// pi xy[] = {{-1, 0}, {1, 0} , {0, -1}, {0, 1}};
// pi dig[] = {{-1, -1}, {-1, 1}, {1, 1}, {1, -1}};
// bool isValid(ll x, ll y, ll row, ll col){
//     return ((x>=0) && (y >=0)  && (x < row) && (y < col));
// }
int main(int argc, const char** argv) {
    crap;
    ll test = 1;
    // cin >> test;
    for(int loop=0; loop<test; loop++){
        // cout << "Case #" << (loop+1) << ": "; 
        lets_do_it();
    }
    return 0;
}
ll lets_do_it(){
    // Your code goes by here !!
    ll num;
    cin >> num;
    if(num <= 599)
        cout << "8\n";
    else if(num <= 799) 
        cout <<"7\n";
    else if(num <= 999)
        cout << "6\n";
    else if(num <= 1199)
        cout <<"5\n";
    else if(num <= 1399)
        cout << "4\n";
    else if(num <= 1599)
        cout << "3\n";
    else if(num <= 1799)
        cout << "2\n";
    else 
        cout << "1\n";











    return 0;
}


Measured memory_bytes: 3640
#include <stdio.h>

int main(void){
  int a, b, c;
  int rect = 0, diamd = 0;

  while(scanf("%d,%d,%d", &a, &b, &c) != EOF){
    if(a == b)  diamd++;
    if(a*a+b*b == c*c)  rect++;
  }
  printf("%d\n%d\n", rect, diamd);
  return 0;
}

Measured memory_bytes: 596
#include <iostream>
#include <vector>

using namespace std;

class student {
public:
    vector<int> st, ed;
    int cnt;
    student() { cnt = 0; }
};

int main()
{
    int N; // PC数
    int M; // 学生数

    while (cin >> N >> M, N || M) {
        int r;  // 利用記録数
        int q;  // 質問数
        vector<student> std(M + 1);

        // 登録
        cin >> r;
        for (int i = 0; i < r; i++) {
            int t, n, m, s;  // s(1: ログイン, 0: ログアウト), 時刻tにPCnで学生mが
            cin >> t >> n >> m >> s;

            if (s == 1) { // ログイン
                if (std[m].cnt == 0) {  // まだログインしていない
                    std[m].st.push_back(t);
                }
                std[m].cnt++;
            }
            else { // ログアウト
                if (std[m].cnt == 1) 
                    std[m].ed.push_back(t);
                std[m].cnt--;
            }
        }

        // 質問
        cin >> q;
        for (int i = 0; i < q; i++) {
            int ts, te, m;
            int ans = 0;

            cin >> ts >> te >> m;

            for (int j = 0; j < std[m].st.size(); j++) {
                if (std[m].ed[j] <= ts)
                    continue;
                if (std[m].st[j] >= te)
                    break;
                
                if (std[m].st[j] <= ts && std[m].ed[j] >= te) {
                    ans += te - ts;
                    break;
                }
                if (std[m].st[j] <= ts && std[m].ed[j] < te)
                    ans += std[m].ed[j] - ts;
                else if (std[m].st[j] >= ts && std[m].ed[j] >= te) {
                    ans += te - std[m].st[j];
                    break;
                }
                else if (std[m].st[j] >= ts && std[m].ed[j] < te) 
                    ans += std[m].ed[j] - std[m].st[j];
            }
            cout << ans << endl;
        }
    }

    return 0;
}

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

int main() {
  
  string s;
  cin >> s;
  
  if (s == "Sunny") cout << "Cloudy" << endl;
  if (s == "Cloudy") cout << "Rainy" << endl;
  if (s == "Rainy") cout << "Sunny" << endl;
  
}


Measured memory_bytes: 256
import java.util.Scanner;


public class Main {

	/**
	 * @param args
	 */
	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ

		Scanner scan = new Scanner(System.in);
		String[] str = scan.nextLine().split(" ");

		for(int i = 0; i < str.length; i++){
			System.out.print(str[i].toUpperCase().charAt(0));
		}
	}

}


Measured memory_bytes: 20820
#include <iostream>
#include <vector>
#include <cmath>
using namespace std;

const long MOD = 1'000'000'007;

int main() {
	long n, x, t; cin >> n >> x >> t;
	long ans = ceil((double)n / (double)x) * t;
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 3252
def main():
  x, n = map(int, input().split())
  arr = set(map(int, input().split()))

  i = 0
  while True:
    if x - i not in arr:
      print(x - i)
      return

    if x + i not in arr:
      print(x + i)
      return

    i += 1



main()


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

long N, K, num[200010];

int main () {

    scanf("%ld %ld", &N, &K);

    for (int i = 1; i <= N; i++) {
        num[i%K]++;
    }

    long ans = 0;

    for (long ma = 0; ma < K; ma++) {
        long mb = (K - ma) % K;
        long mc = (K - ma) % K;

        if ((mb + mc) % K != 0) continue;

        ans += num[ma] * num[mb] * num[mc];
    }

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

    return 0;
}


Measured memory_bytes: 1024
package main

import "fmt"

func main() {
	var N int
	var sec [9]int
	fmt.Scan(&N)
	a := make([]int, N)
	for i := 0; i < len(a); i++ {
		fmt.Scan(&a[i])
	}
	for _, v := range a {
		switch {
		case 1 <= v && v < 400:
			sec[0]++
		case 400 <= v && v < 800:
			sec[1]++
		case 800 <= v && v < 1200:
			sec[2]++
		case 1200 <= v && v < 1600:
			sec[3]++
		case 1600 <= v && v < 2000:
			sec[4]++
		case 2000 <= v && v < 2400:
			sec[5]++
		case 2400 <= v && v < 2800:
			sec[6]++
		case 2800 <= v && v < 3200:
			sec[7]++
		case 3200 <= v:
			sec[8]++
		}
	}
	var colors int
	for i := 0; i < 8; i++ {
		if sec[i] > 0 {
			colors++
		}
	}
	if colors > 0 {
		fmt.Println(colors, colors+sec[8])
	} else {
		fmt.Println(1, sec[8])
	}
}


Measured memory_bytes: 512
#わざわざ累積和で
n = int(input())
a = list(map(int,input().split()))
b = list(map(int,input().split()))
last = a[0] + sum(b)
ans = last
for i in range(1,n):
  last -= b[i-1]
  last += a[i]
  if last > ans:
    ans = last
print(ans)

Measured memory_bytes: 3064
#include <iostream>
#include <string>
#include <vector>
#include <climits>
#include <set>
#include <algorithm>
#include <unordered_map>
#include <queue>
#include <iomanip>
#include <map>
#include <utility>
#include <numeric>
#include <chrono>
#include <ctime>
#include <bitset>

#define rep(i,n) for(int i=0; i<(int)(n); i++)
#define P pair<int, int>
#define debug(x) cerr << #x << ": " << x << ", "
#define debugln(x) cerr << #x << ": " << x << '\n'

using namespace std;
using ll = long long;
const ll mod = 1e9+7;

vector<int> graph[100005];
vector<bool> used(100005);
vector<int> ans;
bool finished = false;

void dfs(int a) {
  if (finished) return;
  if (a != 1) {
    ans.push_back(a);
  }
  used.at(a) = true;
  bool flag = true;
  for(auto e : graph[a]) {
    //debugln(e);
    if (used.at(e)) continue;
    flag = false;
    dfs(e);
  }
  if (flag) {
    finished = true;
    return;
  }
}

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

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

  rep(i, m) {
    int a, b; cin >> a >> b;
    graph[a].push_back(b);
    graph[b].push_back(a);
  }

  dfs(1);
  reverse(ans.begin(), ans.end());
  ans.push_back(1);
  finished = false;
  dfs(1);

  cout << ans.size() << endl;
  for(auto e : ans) {
    cout << e << ' ';
  }
  cout << endl;
}

Measured memory_bytes: 11128
module app;

import core.bitop;

import std.algorithm;
import std.array;
import std.bigint;
import std.container.rbtree;
import std.conv;
import std.stdio;
import std.string;
import std.traits;

struct Input
{
	long n, a, b;
}

void parseInput(T)(out Input input, T file)
{
	with (file) with (input)
	{
		auto ar = readln().strip().split().map!(to!long).array();
		n = ar[0];
		a = ar[1];
		b = ar[2];
	}
}

auto main2(Input* input)
{
	with (input)
	{
		auto q = n / (a + b);
        auto r = n % (a + b);
        return q * a + min(a, r);
	}
}

alias retType = ReturnType!main2;
static if (!is(retType == void))
{
	unittest { writeln("begin unittest"); }
	auto _placeholder_ = ReturnType!main2.init;

	unittest // example1
	{
		string example =
`8 3 4`;
		if (example.empty) return;
		Input input = void;
		parseExample(input, example);
		auto result = main2(&input);
		printResult(result);
		assert(result == 4);
	}

	unittest // example2
	{
		string example =
`8 0 4`;
		if (example.empty) return;
		Input input = void;
		parseExample(input, example);
		auto result = main2(&input);
		printResult(result);
		assert(result == 0);
	}

	unittest // example3
	{
		string example =
`6 2 4`;
		if (example.empty) return;
		Input input = void;
		parseExample(input, example);
		auto result = main2(&input);
		printResult(result);
		assert(result == 2);
	}

	unittest { writeln("end unittest"); }

	void parseExample(out Input input, string example)
	{
		struct Adapter
		{
			string[] _lines;
			this(string input) { _lines = input.splitLines(); }
			string readln() { auto line = _lines[0]; _lines = _lines[1..$]; return line; }
		}
		parseInput(input, Adapter(example));
	}
}

void printResult(T)(T result)
{
	static if (isFloatingPoint!T) writefln("%f", result);
	else writeln(result);
}

void main()
{
	Input input = void;
	parseInput(input, stdin);
	static if (is(retType == void))
		main2(&input);
	else
	{
		auto result = main2(&input);
		printResult(result);
	}
}


Measured memory_bytes: 256
fun main(args:Array<String>){
        var n = readLine()!!.toInt()
        var h = readLine()!!.split(" ").map{it.toInt()}

        var mx = 0
        var cant = false
        for(i in 0..n-1){
                if(mx-1>h[i]) cant = true
                if(h[i]>mx) mx = h[i]
        }

        if(cant) println("No")
        else println("Yes")
}

Measured memory_bytes: 57460
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define printVec(v) printf("{"); for (const auto& i : v) { std::cout << i << ", "; } printf("}\n");
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
using namespace std;
using P = pair<int,int>;
using ll = long long;
const ll INF = 1LL<<60;
const double PI = 3.1415926535897932;
const int MOD = 1e9 + 7;

//cin.tie(0);ios::sync_with_stdio(false);
int main() {
  ll a;
  double b;
  cin >> a >> b;
  ll x = b * 100 + 0.0005;
  ll mul = a * x / 100;

  cout << mul << endl;
  return 0;
}


Measured memory_bytes: 3624
#!/usr/bin/env python
import sys
import re
from collections import deque, defaultdict
from itertools import combinations, combinations_with_replacement
import bisect
from math import factorial, sqrt, log, ceil, floor
sys.setrecursionlimit(1000000)


def main():
    #N, M = map(int, input().split())
    #N, K = map(int, input().split())
    #ps = list(map(int, input().split()))

    N = int(input())

    ds = []
    for n in range(12):
        k = 11 - n
        threshold = sum([26 ** i for i in range(k+1)])
        d = 0
        if N >= threshold:
            for j in range(26):
                if N >= threshold + 26 ** k * j:
                    d = j
            d += 1
            N -= 26 ** k * d
        ds.append(d)

    chars = 'abcdefghijklmnopqrstuvwxyz'
    result = ''
    for n in range(12):
        if ds[n] > 0:
            result += chars[ds[n]-1]

    print(result)


if __name__ == '__main__':
    main()


Measured memory_bytes: 9860
#include <bits/stdc++.h>
using namespace std;
#define REP(i, a, b) for (int i = (int)(a); i < (int)(b); i++)
#define rep(i, n) REP(i, 0, n)
#define rrep(i, n) for (int i = (int)(n-1); i >= 0; i--)
#define sz(x) int(x.size())
#define bitsz(x) int(__builtin_popcount(x))
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define pb(x) push_back(x)
#define INF 1e9
#define LINF 1e18
#define mod 1000000007
template<class T> inline bool chmax(T &a, const T &b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T &a, const T &b) { if (a > b) { a = b; return 1; } return 0; }
template < typename T > inline string toString( const T &a ) { ostringstream oss; oss << a; return oss.str(); };
typedef long long ll;
typedef pair<int, int> P;
typedef pair<ll, ll> LP;
const int di[4] = {1,0,-1,0};
const int dj[4] = {0,1,0,-1};


int main() {
    char a; cin >> a;
    if ('A'<=a && a<='Z') cout << "A" << endl;
    else cout << "a" << endl;
}

Measured memory_bytes: 3560
N, M = [int(i) for i in input().split()]


def check(a):
    b = M - 2 * a
    if b < 0:
        return False
    return b // 2 + N >= a

left, right = 0, M
while right - left > 1:
    mid = (left + right) // 2
    if check(mid):
        left = mid
    else:
        right = mid
print(left)

Measured memory_bytes: 3060
#include<stdlib.h>
#define N 100009
typedef long long LL;
int n,i,a[N],b[N],c[N];LL ans=0;
#define rp for(i=0;i<n;i++)

int up(int*a,int*b){return*(int*)a-*(int*)b;}
int dn(int*a,int*b){return*(int*)b-*(int*)a;}
int compA(int x,int y){return a[y]>=x?1:0;}
int compC(int x,int y){return c[y]<=x?1:0;}
LL BS(int x,int n,int c){
  int O=n,X=-1,mid=n/2;
  while(O-X>1){mid=(O+X)/2;c?(compA(x,mid)?(O=mid):(X=mid)):(compC(x,mid)?(O=mid):(X=mid));}
  return O;
}

int main(){
  scanf("%d",&n);
  rp scanf("%d",a+i);qsort(a,n,4,up);
  rp scanf("%d",b+i);qsort(b,n,4,up);
  rp scanf("%d",c+i);qsort(c,n,4,dn);
  rp ans+=BS(b[i],n,1)*BS(b[i],n,0);
  printf("%lld",ans);
}

Measured memory_bytes: 3280
import java.util.Scanner;
class Main{
    public static void main(String[] args) {
        Scanner scn=new Scanner(System.in);
        String a = scn.next();
        String b = scn.next();
        int cnt=0;
        for(int i=0;i<a.length();i++){
            if(a.charAt(i)==b.charAt(i)) cnt++;
        }
        System.out.println(cnt);
    }
}

Measured memory_bytes: 23764
/*   ꧁༒☬महाकाल☬༒꧂ ꧁༒ঔमहाकालঔ༒꧂
                   
                   ঔৣ۝महाकालᴳᵒᵈ۝ঔৣ            
 
 */ 
#include<bits/stdc++.h>
using namespace std;
//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_policy.hpp>
//using namespace __gnu_pbds;
//template <typename T, typename cmp=less<T>> using oset =tree<T, null_type, cmp, rb_tree_tag, tree_order_statistics_node_update>;
#define ll long long 
#define mod 1000000007
#define fast ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define _it iterator
#define all(_x) _x.begin(),_x.end()
#define f first
#define s second
#define inf 100000000000000000
#define pb push_back
void mahakal(){
	#ifndef ONLINE_JUDGE
	freopen("input.txt","r",stdin);
	freopen("output.txt","w",stdout);
	freopen("error.txt","w",stderr);
	#endif
}
int main(){
//	mahakal(),fast;
	
	ll n ;
	cin>> n ;
	ll mn = inf;
	for(ll i=1;i*i<=n ;i++){
		if(n%i==0){
			mn = min(mn , i+n/i);
		}
	}
	cout<<mn-2<<endl;


	return 0;
}

Measured memory_bytes: 256
#include <map>
#include <set>
#include <cmath>
#include <queue>
#include <stack>
#include <cctype>
#include <cstdio>
#include <string>
#include <vector>
#include <cstdlib>
#include <cstring>
#include <sstream>
#include <iostream>
#include <algorithm>
#include <functional>

#define INF (2 << 28)
#define fr first
#define sc second
using namespace std;

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

unsigned short dp[5011][5011];

int main(){
  
  int n, m;

  cin >> n >> m;
  for(int i = 0; i < m; i++){
    int a, b, c; cin >> a >> b >> c;
    dp[a][b] = c + 1;
  }

  
  for(int i = 1; i <= n; i++){
    for(int j = 1; j <= i; j++){
      if(dp[i][j]){
        dp[i + 1][j] = max< unsigned short >(dp[i + 1][j], dp[i][j] - 1);
        dp[i + 1][j + 1] = max< unsigned short >(dp[i + 1][j + 1], dp[i][j] - 1);
      }
    }
  }
  ll sum = 0;
  for(int i = 1; i <= n; i++){
    for(int j = 1; j <= i; j++){
      if(dp[i][j]) sum++;
    }
  }
  cout << sum << endl;
}

Measured memory_bytes: 48944
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using st = string;
using P = pair<int, int>;
#define mrep(i, m, n) for(int i = m; i < n; i++)
#define rep(i, n) mrep(i, 0, n)
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)

int main() {
    int a, b, c, n;
    cin >> a >> b >> c >> n;
    int cardA = a, cardB = b, cardC = c;
    int cnt = 0;
    while(cardA >= cardB){
        cardB *= 2;
        cnt++;
    }
    while(cardB >= cardC){
        cardC *= 2;
        cnt++;
    }
    if(cnt <= n) cout << "Yes" << endl;
    else cout << "No" << endl;
}

Measured memory_bytes: 3592
#include "bits/stdc++.h"

/*

bush did 9/11 ecks deeeeee
░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░██████░░░░░░░░░░░░░░░░
░░██████████░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░███████░░░░░░░░░░░░░░░░░░
░░██ ███ ███░░░░░█▌░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░████████░░░░░░░░░░░░░░░░░░░░
░░██████████░██████████░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░█████████░░░░░░░░░░░░░░░░░▌░░░░
░░██ ███ ███░██ ███ ███░░░░░░░░░░░░░░░░░░░░░░░░░░░░◐◐◐█████████▀▀▀▀▀▀🔥 ░░░░░░░░███░░░░
░░██████████░██████████░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░█████████░░░░░░░░░░░░░░░░░░░▌░░░░░
░░██ ███ ███░██ ███ ███░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░█████████░░░░░░░░░░░░░░░░░░░█▌░░░░
░░██████████░██████████░░░░░░░░░░░▄▄▀██████████████████████████████████████████████████
░░██ ███ ███░██ ███ ███░░░░░░▄▄▄████▄████████ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ █████
░░██████████░██████████░░░░░░░▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀█████████▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀
░░██ ███ ███░██ ███ ███░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░█████████░░░░░░░░░░░░░░░░░░░░░░
░░██████████░██████████░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░◐◐◐█████████▀▀▀▀▀▀🔥░░░░░░░░░░░░░░
░░██ ███ ███░██ ███ ███░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░█████████░░░░░░░░░░░░░░░░░░░░
░░██████████░██████████░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░█████████░░░░░░░░░░░░░░░░░░░
░░██ ███ ███░██ ███ ███░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░████████░░░░░░░░░░░░░░░░░░
░░██████████░██████████░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░███████░░░░░░░░░░░░░░░░░
░░██ ███ ███░██ ███ ███░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░██████░░░░░░░░░░░░░░░░
░░██████████░██████████░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░█████░░░░░░░░░░░░░░░

*/

#define chinky bigounce
#define speedup ios_base::sync_with_stdio(0); cin.tie(NULL); cout.tie(NULL);
#define endl "\n"
#define mp make_pair
#define pb push_back
#define f first
#define s second
#define mst(X,val) memset((X),(val),sizeof(X))
#define usaco(in,out) ifstream fin(in); ofstream fout(out)
#define all(X) (X).begin(), (X).end()
#define sz(X) ((int)X.size())
#define pii pair<int,int>
typedef long long ll;
using namespace std;
const int maxn = 2e6 + 10;
const int maxval = 1e9 + 10;

ll a[maxn], dp[maxn];

int main() {
	speedup
	
	ll n; cin >> n;
	for (ll i = 0; i < n; i++) {
		cin >> a[i];
		
	}
	dp[0] = 0;
	dp[1] = abs(a[1]-a[0]);
	dp[2] = abs(a[2]-a[0]);
	
	for (ll i = 0; i < n; i++) {
		dp[i+1] = min(dp[i+1],dp[i]+abs(a[i]-a[i+1]));
		dp[i+2] = dp[i] + abs(a[i]-a[i+2]);
	}
	cout << dp[n-1];
}



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

int main() 
{ 
// スペース区切りの整数の入力 
int a,b; 
cin >> a >> b; 
// 文字列の入力 

if((a+b)%2==1)
{
  cout << "IMPOSSIBLE";
}
else
{
  cout << (a+b)/2;
}
  
return 0; 

} 

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
    int a,b,c,d,e,k;
    string S;
    cin>>a>>b>>c>>d>>e>>k;
    if(e-a>k){
        cout<<":("<<endl;
    }
    else cout<<"Yay!"<<endl;
}


Measured memory_bytes: 256
from itertools import*
import math
from collections import*
from heapq import*
from bisect import bisect_left,bisect_right
from copy import deepcopy
inf = float("inf")
mod = 10**9+7
from functools import reduce
import sys
sys.setrecursionlimit(10**7)


n,q = list(map(int,input().split()))
lines = sys.stdin.readlines()
stx = []
for line in lines[:n]:
    s,t,x = map(int,line.split())
    stx.append((x,s,t))
stx.sort()
D = list(map(int,lines[n:]))
ans = [-1]*q
skip = [-1]*q
for x,s,t in stx:
    ss = bisect_left(D,s-x)
    tt = bisect_left(D,t-x)
    while ss < tt:
        if skip[ss] == -1:
            ans[ss]=x
            skip[ss]=tt
            ss += 1
        else:
            ss = skip[ss]
print('\n'.join(map(str,ans)))

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

using namespace std;
using ll = long long;
using vll = vector<ll>;
using vvll = vector<vll>;

#define REP(i, n, m) for(ll i=n; i<(ll)m; ++i)
#define IREP(i, n, m) for(ll i=n-1; i>=m; --i)
#define rep(i, n) REP(i, 0, n)
#define irep(i, n) IREP(i, n, 0)
#define all(v) v.begin(), v.end()

ll gcd(ll n, ll m){
    while(true){
        if(n<m) swap(n, m);
        if(!m) break;
        n %= m;
    }
    return n;
}

int main(){
    ll a, b;
    cin >> a >> b;

    ll gcd_ab = gcd(a, b);
    set<ll> s;
    ll n = gcd_ab;
    REP(i, 2, sqrt(gcd_ab)+2){
        while(n%i==0){
            s.insert(i);
            n /= i;
        }
    }
    s.insert(1);
    s.insert(n);
    ll count = s.size();
    cout << count << endl;
}


Measured memory_bytes: 256
from collections import Counter,defaultdict,deque
import sys,heapq,bisect,math,itertools,string,queue
sys.setrecursionlimit(10**8)
mod = 10**9+7
def inp(): return int(sys.stdin.readline())
def inpl(): return list(map(int, sys.stdin.readline().split()))
def inpl_str(): return list(sys.stdin.readline().split())
def inpln(n): return list(int(sys.stdin.readline()) for i in range(n))

k,s = inpl()
res = 0
for i in range(k+1):
    for j in range(k+1):
        if 0 <= s-i-j <= k:
            res += 1
print(res)


Measured memory_bytes: 41448
#include <iostream>

using namespace std;

int main() {
	int n; cin >> n;
	int cnt = 0;
	bool f = false;
	for (int i = 0; i < n; ++i) {
		int d1, d2; cin >> d1 >> d2;
		if (d1 == d2) ++cnt;
		else cnt = 0;
		if (cnt == 3) f = true;
	}
	cout << (f ? "Yes" : "No") << endl;

	return 0;
}

Measured memory_bytes: 3632
#include <bits/stdc++.h>
using namespace std;
/*{{{*/  //template
#define rep(i,n) for(int i=0;i<(int)(n);i++)
constexpr int INF = numeric_limits<int>::max()/2;
constexpr long long LINF = numeric_limits<long long>::max()/3;
#define mp make_pair
#define pb push_back
#define eb emplace_back
#define fi first
#define se second
#define all(v) (v).begin(),(v).end()
#define sz(x) (int)(x).size()
#define debug(x) cerr<<#x<<":"<<x<<endl
#define debug2(x,y) cerr<<#x<<","<<#y":"<<x<<","<<y<<endl
//struct fin{ fin(){ cin.tie(0); ios::sync_with_stdio(false); } } fin_;
struct Double{ double d; explicit Double(double x) : d(x){} };
ostream& operator<<(ostream& os,const Double x){ os << fixed << setprecision(20) << x.d; return os; }
template<typename T> ostream& operator<<(ostream& os,const vector<T>& vec){ os << "["; for(const auto& v : vec){ os << v << ","; } os << "]"; return os; }
template<typename T,typename U> ostream& operator<<(ostream& os,const pair<T,U>& p){ os << "(" << p.first << ","<< p.second <<")"; return os; }
template<typename T> ostream& operator<<(ostream& os,const set<T>& st){ os<<"{"; for(T v:st) os<<v<<","; os <<"}"; return os; }
template<typename T,typename U> inline void chmax(T &x,U y){ if(y>x) x = y; }
template<typename T,typename U> inline void chmin(T &x,U y){ if(y<x) x = y; }
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef vector<vi> vvi;
ll gcd(ll a,ll b){ if(b==0) return a; else return gcd(b,a%b); }
//constexpr double eps = 1e-14; 
constexpr double eps = 1e-10; 
constexpr ll mod = 1e9+7;
const int dx[]={1,0,-1,0} ,dy[] = {0,1,0,-1};
/*}}}*/

vector<int> ids;
vector<int> G[100005];

int dfs(int root,int idx){
    if(ids[idx] == 1){
        return root;
    }else{
        int y = ids[idx];
        int x = ids[idx+1];
        G[root].push_back(root+1);
        int ret = dfs(root+1,idx+1);
        for(int i=0;i<y-x-1;i++){
            G[root].push_back(++ret);
        }

        return ret;
    }
}

int main(){
    string s; 
    cin >> s;
    int n = s.size();
    string ss = s.substr(0,n-1);
    string ss2 = ss;
    reverse(all(ss));
    if(ss != ss2){
        cout << -1 << endl;
        return 0;
    }

    if(s[n-1] == '1' or s[0] == '0'){
        cout << -1 << endl;
        return 0;
    }

    for(int i=0;i<n;i++){
        if(s[i] == '1') ids.push_back(i+1);
    }

    reverse(all(ids));

    int last = dfs(0,0);

    for(int i=0;i<n;i++){
        for(int j=0;j<G[i].size();j++){
            cout << i + 1 <<  " " << G[i][j] + 1 << endl;
        }
    }
    cout << 1 << " " << n << endl;
}


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

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

#define INF 1 << 30
#define REP(i,n) for(ll i=0; i<(int)(n); i++)
#define FOR(i,k,n) for(ll i=(k);i<(int)(n);i++)

int n;
ll a[1000];

vector<ll> b[2];
typedef pair<int,pii> ppii;//どの種類か、どこからどこまでか

vector<int> ans;

int main(){
  cin >> n;
  REP(i,n) cin >> a[i];
  ll ma0 = 0;
  ll ma1 = 0;
  for(int i = 0; i < n; i+=2){
    if(a[i] > 0){
      ma0 += a[i];
      b[0].push_back(i);
    }
  }
  for(int i =1; i <n;i+=2){
    if(a[i]>0){
      ma1 += a[i];
      b[1].push_back(i);
    }
  }
  if(b[0].size() == 0 && b[1].size() == 0){
    ll ma3 = a[0];
    int in = 0;
    REP(i,n){
      if(ma3 < a[i] ){
        ma3 = a[i];
        in = i;
      }
    }
    for(int i = n;i>in+1;i--) ans.push_back(i);
    REP(i,in) ans.push_back(1);

    cout << ma3 << endl;
    cout << ans.size() <<endl;
    REP(i,ans.size()) cout << ans[i] <<endl;
    return 0;
  }
  int t;
  ll ma;
  if(ma0<ma1){
    ma = ma1;
    t = 1;
  }else{
    ma = ma0;
    t = 0;
  }
  for(int i = n;i>b[t][b[t].size()-1]+1;i--) ans.push_back(i);
  REP(i,b[t][0]) ans.push_back(1);
  FOR(i,1,b[t].size()){
    for(int j = (b[t][i]-b[t][i-1])/2+1; j>=2;j--) ans.push_back(j);
  }
  cout << ma <<endl;
  cout << ans.size() << endl;
  REP(i,ans.size()) cout << ans[i] <<endl;
}


Measured memory_bytes: 256
#include <algorithm>
#include <bitset>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <fstream>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>

using namespace std;

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

/*
    freopen("input","r",stdin);
    freopen("output","w",stdout);
*/

int solve(string A, string B) {
	int N = A.size();
    set<int> G;
    for (int i = 0;i < N;i++) {
    	if (B[i] == '1') {
    		G.insert(i - N);
    		G.insert(i);
    		G.insert(i + N);
    	}
    }
    int sol = 1E9;
    for (int r = 0;r < N;r++) {
    	vector<PP> T;
    	int num = r;
    	for (int j = 0;j < N;j++) {
    		if (A[j] == B[(j + r) % N]) continue;
    		// Check whether 1 exist in [j, j + r]
    		num++;
    		auto it = G.lower_bound(j);
    		if (*it <= j + r) continue;
    		it = G.lower_bound(j + r);
    		// Go right
    		int R = *it - (j + r);
    		it = G.lower_bound(j);
    		it--;
    		// Go left
    		int L = j - *it;
    		T.push_back(make_pair(L, R));
    	}
    	sort(T.begin(), T.end());
    	set<int> tmp;
    	if (T.size() == 0) sol = min(sol, num);
    	for (int i = T.size() - 1;i >= 0;i--) {
    		int j = T[i].first;
    		if (tmp.size() == 0) sol = min(sol, 2 * j + num);
    		else {
    			auto it = tmp.end();
    			it--;
    			sol = min(sol, 2 * (j + *it) + num);
    		}
    		tmp.insert(T[i].second);
    	}
    }
    return sol;
}

int main() {
    ios::sync_with_stdio(false);
    string A, B;
    cin >> A >> B;
    // Check
    int g = 0;
    for (int i = 0;i < A.size();i++) {
    	if (A[i] == '1') g |= 2;
    	if (B[i] == '1') g |= 1;
    }
    if (g == 2) {
    	cout << -1 << endl;
    	return 0;
    }
    int sol = solve(A, B);
    for (int i = 0;i < A.size() / 2;i++) {
    	swap(A[i], A[A.size() - 1 - i]);
    	swap(B[i], B[B.size() - 1 - i]);
    }
    sol = min(sol, solve(A, B));
    cout << sol << endl;
    return 0;
}

Measured memory_bytes: 512
#include <iostream>

using namespace std;

const long long mod = 1e9 + 7;

int main()
{
    int n;
    cin >> n;
    long long a;
    long long cnt = 0;
    long long ans = 1;
    for (int i = 0 ; i < n; ++i) {
        cin >> a;
        ++cnt;
        if (a < cnt * 2 - 1) {
            ans = (ans * cnt) % mod;
            --cnt;
        }
    }
    for (long long i = 1; i <= cnt; ++i) {
        ans = (ans * i) % mod;
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 384
#include<deque>
#include<queue>
#include<vector>
#include<algorithm>
#include<iostream>
#include<set>
#include<cmath>
#include<tuple>
#include<string>
#include<chrono>
#include<functional>
#include<iterator>
#include<random>
#include<unordered_set>
#include<unordered_map>
#include<array>
#include<map>
#include<bitset>
#include<iomanip>
#include<list>
using namespace std;
typedef long long int llint;
typedef long double lldo;
#define mp make_pair
#define mt make_tuple
#define pub push_back
#define puf push_front
#define pob pop_back
#define pof pop_front
#define fir first
#define sec second
#define res resize
#define ins insert
#define era erase
#define RE return 0
//ios::sync_with_stdio(false);
//std::cin.tie(0);
//<< setprecision(20)
const llint mod=1e9+7;
const llint big=1e15+100;
const long double pai=3.141592653589793238462643383279502884197;
const long double ena=2.71828182845904523536;
const long double eps=1e-7;
template <class T,class U>void mineq(T& a,U b){if(a>b){a=b;}}
template <class T,class U>void maxeq(T& a,U b){if(a<b){a=b;}}
template <class T> void soun(T& ar)
{sort(ar.begin(),ar.end());ar.erase(unique(ar.begin(),ar.end()),ar.end());}
llint gcd(llint a,llint b){if(a%b==0){return b;}else{return gcd(b,a%b);}}
llint lcm(llint a,llint b){return a/gcd(a,b) *b;}
//I need 10 minite to read this problem in English.
int main(void){
	int n,i,j;cin>>n;
	vector<int>c(n-1);
	vector<int>s(n-1);
	vector<int>f(n-1);
	for(i=0;i<n-1;i++){cin>>c[i]>>s[i]>>f[i];}
	for(i=0;i<n;i++){
		int gen=0;
		for(j=i;j<n-1;j++){
			gen=((gen+f[j]-1)/f[j])*f[j];
			maxeq(gen,s[j]);
			gen+=c[j];
		}
		cout<<gen<<endl;
	}
	RE;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define LL long long
#define PII pair<int,int>
#define PIL pair<int,LL>
#define PLI pair<LL,int>
#define PIII pair<int,PII>
#define PLL pair<LL,LL>
#define PLII pair<LL,PII>
#define VI vector<int>
#define VVI vector<VI>
#define VL vector<LL>
#define VVL vector<VL>
#define VPII vector<PII>
#define FF first
#define SS second
#define MP make_pair
#define PB push_back
#define all(x) x.begin(),x.end()
#define watch(x) cout<<(#x)<<" = "<<(x)<<'\n'
#define mset(a,v) memset(a,v,sizeof(a))
#define setp(x) cout<<fixed<<setprecision(x)
#define EPS 0.00000000001
#define PI acos(-1)
#define loop(i,b,n) for(int i=b;i<n;++i)
#define rev_loop(i,b,n) for(int i=b;i>=n;--i)
using namespace std;

const int MOD = 1e9 + 7;
const LL MX = 5010;
const LL INF = 2e18;

int p[MX];
LL c[MX];

LL cal(int i,int k)
{
    LL mx = -INF, sum = 0;
    int vis[MX] = {0};
    vis[i] = 1;
    int id = i,mxi = -1, k1 = k, nm = 0;

    while(k1--)
    {
        ++nm;
        id = p[id];
        if(vis[id] == 0)
        {
            sum += c[id]; vis[id] = 1;
            if(mx < sum) {mx = sum; mxi = nm;}
        }
        else if(id == i)
        {
            sum += c[i];
            if(mx < sum) {mx = sum; mxi = nm;}
            int m = k/nm, rem = k % nm;
            if(rem >= mxi) mx = max(mx,(sum*m) + mx);
            else if(m) mx = max(mx,(sum*(m-1)) + mx);

            sum = m * sum;
            mx = max(mx,sum);
            id = i;
            while(rem--)
            {
                id = p[id];
                sum += c[id];
                mx = max(mx,sum);
            }
            break;
        }
        else
        {
            LL ans1 = 0;
            int id1 = i, nm1 = 0;
            while(1)
            {
                ++nm1;
                id1 = p[id1];
                ans1 += c[id1];
                if(id1 == id) break;
            }

            ans1 += cal(id,k-nm1);
            mx = max(mx,ans1);
            break;
        }
    }

    return mx;
}

int main()
{
    //ofstream out("output.txt");
    //ifstream in("input.txt");
    ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);

    int n,k;
    cin>>n>>k;
    loop(i,1,n+1) cin>>p[i];
    loop(i,1,n+1) cin>>c[i];

    LL ans = -INF;
    loop(i,1,n+1)
    {
        ans = max(ans,cal(i,k));
    }

    cout<<ans<<'\n';

    /*
    int t,n;
    cin>>t;
    while(t--)
    {
        cin>>n;
        int a[n];
        loop(i,0,n)
        {
            cin>>a[i];
        }
    }
    */

    /*
    int n;
    cin>>n;
    int a[n];
    loop(i,0,n)
    {
        cin>>a[i];
    }
    */

    /*
    cout<<ans<<'\n';

    if(f) cout<<"YES\n";
    else cout<<"NO\n";

    if(f) cout<<"Yes\n";
    else cout<<"No\n";
    */

    return 0;
}


Measured memory_bytes: 3712
#include<bits/stdc++.h>
using namespace std;
using Graph=vector<vector<int>>;
#define rep(i,n) for(int i=0;i<(int)(n);i++)
typedef long long ll;
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;
}
ll gcd(ll x,ll y){
    if(x<y) swap(x,y);
    //xの方が常に大きい
    ll r;
    while(y>0){
        r=x%y;
        x=y;
        y=r;
    }
    return x;
}
int main(){
    ll N;cin>>N;
    if(N%2==0||N%5==0){
        cout<<-1<<endl;
    }
    else{
        if(N%7==0){
            N=N/7;
        }
        ll MOD=9*N;
        ll res=10;
        ll TIMES=10000000;
        bool flag=false;
        for(ll i=0;i<TIMES;i++){
            if(res%MOD==1){
                cout<<i+1<<endl;
                flag=true;
                break;
            }
            res=(res*10)%MOD;
        }
        if(flag==false){
            cout<<-1<<endl;
        }

    }
}

Measured memory_bytes: 3628
// Radewoosh's solution
#include <bits/stdc++.h>
#define ll long long
#define IOS ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define mp make_pair
#define pb push_back
#define endl "\n"
#define mod 1000000007

using namespace std;

int main()
{
	double a,b,t,ans=0;
	cin>>a>>b>>t;
	double c = a;
	t=t+0.5;
	while(c<=t)
	{
		ans+=b;
		c+=a;
	}
	cout<<ans<<endl;
	return 0;
}


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

using namespace std;

const int Nmax = 2e5 + 5;

queue<int> q;
int a[Nmax], b[Nmax];
int n; 
long long nr_op = 0;
bool inQ[Nmax];


static int nxt(int x)
{
    return (x < n ? x + 1 : 1);
}

static int prv(int x)
{
    return (x > 1 ? x - 1 : n);
}

void check(int i)
{
    if(!inQ[i] && b[i] - (b[prv(i)] + b[nxt(i)]) >= a[i])
        q.push(i), inQ[i] = 1;
}

void solve()
{
    int i;
    for(i=1; i<=n; ++i)
        check(i);
    
    while(q.size())
    {
        int x = q.front();
        q.pop();
        inQ[x] = 0;
        
        int curr = (b[x] - a[x]) / (b[prv(x)] + b[nxt(x)]);
        assert(curr);
        nr_op += curr;
        b[x] -= curr * (b[prv(x)] + b[nxt(x)]);
        
        check(x);
        check(nxt(x));
        check(prv(x));
    }

    for(i=1; i<=n; ++i) 
        if(a[i] != b[i]) 
        {
            cout << -1 << '\n';
            return;
        }

    cout << nr_op << '\n';
}

int main()
{
 //   freopen("input", "r", stdin);
    cin.sync_with_stdio(false); cin.tie(0);

    cin >> n;
    int i;
    for(i=1; i<=n; ++i) cin >> a[i];
    for(i=1; i<=n; ++i) cin >> b[i];
    
    solve();

    return 0;
}


Measured memory_bytes: 2432
#include<bits/stdc++.h>
#define LL long long
#define N 100005
#define M 20*N
#define db(x) cout<<#x<<"="<<x<<endl;
using namespace std;
struct node{
	int cnt;
	LL sum;
};
struct edge {
	int to,nxt,c,d;
} e[N<<1];
int n,q,head[N],dis[N];
int rt[N],tot;
int lson[M],rson[M],cnt[M];
LL sum[M];
int fa[N][18],dep[N];
void link(int s,int t,int c,int d,int n) {
	e[n]=(edge)<%t,head[s],c,d%>;
	head[s]=n;
}
void insert(int &nt,int ot,int l,int r,int x,int k) {
	nt=++tot;
	lson[nt]=lson[ot];
	rson[nt]=rson[ot];
	cnt[nt]=cnt[ot]+1;
	sum[nt]=sum[ot]+k;
	if(l==r)return;
	int mid=l+r>>1;
	if(x<=mid)insert(lson[nt],lson[ot],l,mid,x,k);
	else insert(rson[nt],rson[ot],mid+1,r,x,k);
}
node query(int u,int v,int lca,int l,int r,int x){
	if(l==r)return (node)<%cnt[u]+cnt[v]-2*cnt[lca],sum[u]+sum[v]-2*sum[lca]%>;
	int mid=l+r>>1;
	if(x<=mid)return query(lson[u],lson[v],lson[lca],l,mid,x);
	else return query(rson[u],rson[v],rson[lca],mid+1,r,x);
}
void dfs(int x,int f,int c,int d) {
	fa[x][0]=f,dep[x]=dep[f]+1;
	if(x!=1)dis[x]=dis[f]+d;	
	if(x!=1)insert(rt[x],rt[f],1,n,c,d);
	for(int i=head[x]; i; i=e[i].nxt) {
		int to=e[i].to;
		if(to==f)continue;
		dfs(to,x,e[i].c,e[i].d);
	}
}
int Lca(int a,int b) {
	if(dep[a]>dep[b])swap(a,b);
	int s=dep[b]-dep[a];
	for(int i=0; 1<<i<=n; i++)if(s&(1<<i))b=fa[b][i];
	if(a==b)return a;
	for(int i=17; i>=0; i--)if(fa[a][i]!=fa[b][i])a=fa[a][i],b=fa[b][i];
	return fa[a][0];
}
int main() {
	scanf("%d%d",&n,&q);
	for(int i=1; i<n; i++) {
		int s,t,c,d;
		scanf("%d%d%d%d",&s,&t,&c,&d);
		link(s,t,c,d,(i<<1)-1);
		link(t,s,c,d,i<<1);
	}
	dfs(1,0,0,0);
	for(int i=1; 1<<i<=n; i++)
		for(int j=1; j<=n; j++)fa[j][i]=fa[fa[j][i-1]][i-1];
	while(q--) {
		int x,y,u,v;
		scanf("%d%d%d%d",&x,&y,&u,&v);
		int lca=Lca(u,v);
		node now=query(rt[u],rt[v],rt[lca],1,n,x);
		printf("%lld\n",dis[u]+dis[v]-2*dis[lca]+(1ll*now.cnt*y-now.sum));
	}
	return 0;
}


Measured memory_bytes: 54144
import java.util.*;

public class Main {

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

	public void execute() {
		Scanner sc = new Scanner(System.in);

		int[] c = new int[4];

		for (int i = 0; i < 3; i++) {
			int a = sc.nextInt();
			int b = sc.nextInt();
			c[a - 1]++;
			c[b - 1]++;
		}

		boolean isPath = true;

		for (int n : c) {
			if (n < 1 || n >= 3) {
				isPath = false;
				break;
			}
		}

		System.out.println(isPath ? "YES" : "NO");
		sc.close();
	}

}


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

// types
typedef long long ll;
typedef long double ld;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef pair<ld,ld> pdd;
typedef vector<ll> vll;

// macros
#define ALL(a) a.begin(),a.end()
#define SZ(a) ((int)a.size())
#define FI first
#define SE second
#define REP(i,n) for(int i=0;i<((int)n);i++)
#define REP1(i,n) for(int i=1;i<((int)n);i++)
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define PB push_back
#define EB emplace_back
#define MP(a,b) make_pair(a,b)
#define SORT_UNIQUE(c) (sort(c.begin(),c.end()), c.resize(distance(c.begin(),unique(c.begin(),c.end()))))
#define GET_POS(c,x) (lower_bound(c.begin(),c.end(),x)-c.begin())
#define Decimal fixed<<setprecision(20)
#define INF 1000000000
#define LLINF 1000000000000000000LL

// constants
const int inf = 1e9;
const ll linf = 1LL << 50;
const double eps = 1e-10;
const int MOD = 1e9 + 7;
const int dx[4] = {-1, 0, 1, 0};
const int dy[4] = {0, -1, 0, 1};

int main(){
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  
  ll a,b,c;
  cin >> a >> b >> c;
  if(a <=c && c<=b)
    cout << "Yes" << endl;
  else
    cout << "No" << endl;
}

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

using namespace std;

int main()
{
	std::ios_base::sync_with_stdio(false);
	std::cin.tie(NULL);
	int S , W ; 
	cin >> S >> W ; 
	if(S > W)
	{
		cout << "safe" ; 
	} 
	else
		cout << "unsafe" ; 
	
}



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

int main() {
	int m, h;
	string str,cpy;

	while (1) {
		cin >> str;
		if (str == "-")
			break;

		cpy = str;
		cin >> m;

		for (int i = 0;i < m;i++) {
			cin >> h;

			for (int j = 0;j < str.length() - h;j++)
				cpy[j] = str[j+h];

			for (int j = str.length() - h;j < str.length();j++)
				cpy[j] = str[j - str.length() + h];

			for (int j = 0;j < str.length();j++)
				str[j] = cpy[j];
		}
		cout << str << endl;
	}
	return 0;
}

Measured memory_bytes: 1212
#include<iostream>
#include<vector>
#include<algorithm>
#include<queue>
#include<cstring>
#include<cstdio>
using namespace std;
queue<pair<int,int> >q;
int n,m,nn;
vector<pair<int,int> >v[100010];
vector<int>nv[300010];
bool vis[300010];
int cur[100010];
vector<int>col[1000010];
vector<int>res;
void dfs(int x,int c)
{
	vis[x]=true;
	res.push_back(x);
	for(int i=cur[x];i<v[x].size();i++)
	{
		if(v[x][i].first!=c)break;
		cur[x]++;
		int y=v[x][i].second;
		if(vis[y])continue;
		dfs(y,c);
	}
}
int main()
{
	scanf("%d%d",&n,&m);
	nn=n;
	for(int i=1;i<=m;i++)
	{
		int x,y,c;
		scanf("%d%d%d",&x,&y,&c);
		v[x].push_back(make_pair(c,y));
		v[y].push_back(make_pair(c,x));
		col[c].push_back(x);
		col[c].push_back(y);
	}
	for(int i=1;i<=n;i++)
	{
		sort(v[i].begin(),v[i].end());
	}
	for(int i=1;i<=1000000;i++)
	{
		if(!col[i].size())continue;
		for(int j=0;j<col[i].size();j++)
		{
			vis[col[i][j]]=false;
		} 
		for(int j=0;j<col[i].size();j++)
		{
			int x=col[i][j];
			if(vis[x])continue;
			res.clear();
			dfs(x,i);
			nn++;
			for(int k=0;k<res.size();k++)
			{
				nv[nn].push_back(res[k]);
				nv[res[k]].push_back(nn);
			}
		}
	}
	memset(vis,false,sizeof(vis));
	q.push(make_pair(1,0));
	vis[1]=true;
	while(!q.empty())
	{
		int x=q.front().first,w=q.front().second;
		q.pop();
		if(x==n)
		{
			printf("%d",w/2);
			return 0;
		}
		for(int i=0;i<nv[x].size();i++)
		{
			int y=nv[x][i];
			if(vis[y])continue;
			vis[y]=true;
			q.push(make_pair(y,w+1));
		}
	}
	printf("-1");
	return 0;
} 

Measured memory_bytes: 55808
import sys

class UnionFind:
    def __init__(self, N:int):
        """N: 大きさ
        size: 連結成分の大きさ
        """
        self.par = [i for i in range(N)]
        self.size = [1]*N
        self.rank = [1]*N

    def root(self, x:int)->int:
        """根を求める"""
        if self.par[x] == x: # if root
            return x
        else:
            self.par[x] = self.root(self.par[x]) # 経路圧縮
            return self.par[x]

    def is_same(self, x:int, y:int)->bool:
        """x と y が同じ集合に属するか否か"""
        return self.root(x)==self.root(y)

    def unite(self, x:int, y:int):
        """y を x の属する集合に併合"""
        root_x = self.root(x)
        root_y = self.root(y)
        if root_x == root_y: return
        if self.rank[root_x] == self.rank[root_y]:
            self.rank[root_x] += 1
        elif self.rank[root_x]<self.rank[root_y]:
            root_x,root_y = root_y,root_x
        # 短いほう(y)を長いほう(x)にくっつける
        self.par[root_y] = root_x
        self.size[root_x] += self.size[root_y]
        self.size[root_y] = 0 # もういらない

    def get_size(self, x:int)->int:
        """xの属するグループのサイズ"""
        return self.size[self.root(x)]

if __name__ == "__main__":
    N,Q = map(int, sys.stdin.readline().split())
    UNITE,SAME = 0,1
    uf = UnionFind(N)
    for _ in range(Q):
        com,x,y = map(int, sys.stdin.readline().split())
        if com==UNITE:
            uf.unite(x, y)
        else: # same
            print(int(uf.is_same(x, y)))



Measured memory_bytes: 6848
#include <iostream>
#include <vector>
#include <tuple>
#include <algorithm>

using namespace std;

int main() {
  int N, M;
  cin >> N >> M;
  vector<tuple<long long, int>> AB;
  for(int i = 0; i < N; i++) {
    long long a;
    int b;
    cin >> a >> b;
    AB.push_back(make_tuple(a, b));
  }
  sort(AB.begin(), AB.end());
  int sum{};
  long long money{};
  auto it = AB.begin();
  while(sum < M){
    auto a = get<0>(*it);
    auto b = get<1>(*it);
    b = min(b, M - sum);
    money += (long long)(a * b);
    sum += b;
    it++;
  }
  cout << money << endl;
}


Measured memory_bytes: 2420
#include<bits/stdc++.h>
#define LL long long
#define mod 1000000007
#define maxn 100010
using namespace std; 

int ans[maxn];

int main(){
	string s;
	cin >> s;
	memset(ans, 0, sizeof ans);
	int now = 0;
	for(int i = 0; i < s.size(); ++i){
		if(s[i] == 'R'){
			now++;
		}
		else{
			for(int j = i - now; j < i; ++j){
				if((10000000 - (i - j)) % 2 == 0){
					ans[i]++;
				}
				else{
					ans[i - 1]++;
				}
			}
			now = 0;
		}
	} 
	for(int i = s.size() - 1; i >= 0; --i){
		if(s[i] == 'L'){
			now++;
		}
		else{
			for(int j = i + 1; j <= i + now; ++j){
				if((10000000 - (j - i)) % 2 == 0){
					ans[i]++;
				}
				else{
					ans[i + 1]++; 
				}
			}
			now = 0;
		}
	} 
	for(int i = 0; i < s.size(); ++i){
		cout << ans[i] << " ";
	}
	cout << endl;
	return 0;
}



Measured memory_bytes: 1024
#include <iostream>
#include <sstream>
#include <algorithm>
#include <string>
#include <vector>
#include <stack>
#include <set>
#include <queue>
#include <map>
#include <numeric>
#include <functional>
#include <math.h>

using namespace std;

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

#define INF ((int)1e9)
#define INFLL ((ll)1e18)
#define MOD (1000000007LL)


int main(int argc, const char * argv[]) {
    ios_base::sync_with_stdio(false);
    int A, B, C, D;
    cin >> A >> B >> C >> D;
    
    while (1) {
        C -= B;
        if (C <= 0) {
            cout << "Yes" << endl;
            break;
        }
        A -= D;
        if (A <= 0) {
            cout << "No" << endl;
            break;
        }
    }

    return 0;
}


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

#define ll long long int

int main() {
  ll n, k, c;
  cin >> n >> k >> c;
  string s;
  cin >> s;
  vector<ll> l, r;
  ll prev = -1;
  for(ll i = 0; i < s.size(); i++) {
    if(s[i] == 'o' && (prev == -1 || i - prev > c)) {
      prev = i;
      l.push_back(i);
      // cout << i << endl;
      if(l.size() == k)	break;
    }
  }
  prev = -1;
  for(ll i = s.size() - 1; i >= 0; i--) {
    if(s[i] == 'o' && (prev == -1 || prev - i > c)) {
      prev = i;
      r.push_back(i);
      // cout << i << endl;
      if(r.size() == k)	break;
    }
  }
  ll i = 0, j = 0;
  reverse(r.begin(), r.end());
  for(int i = 0; i < l.size(); i++) {
      if(l[i] == r[i])
        cout << (l[i] + 1) << " ";
  }
}

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

using namespace std;

using i64 = int64_t;

const i64 MOD = 1e9+7;

const i64 INF = 1e18+7;


signed main(){
    set<int> s;
    string t;
    cin >> t;
    for(auto& x : t){
        if(s.find(x) != s.end()){
            cout << "no" << endl;
            return 0;
        }
        s.insert(x);
    }
    cout << "yes" << endl;
}


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

int main(void) {
	const string dd("TLURD");
	string boin("aiueo");
	string siin("kstnhmyrw");

	string str;

	cin >> str;
	int N = str.size();

	for (int i = 0; i < N; i+=2) {
		int num = str[i] - '0';
		char d = str[i + 1];

		// ん
		if (num == 0 && d == 'U') {
			cout << "nn";
			continue;
		}
		
		// を, わ
		if (num == 0 && d == 'D') {
			cout << "wo";
			continue;
		}
		if (num == 0 && d == 'T') {
			cout << "wa";
			continue;
		}

		char b = boin[dd.find(d)];

		// 母音のみ
		if (num == 1) {
			cout << b;
			continue;
		}

		// その他
		char s = siin[num - 2];
		cout << s << b;
	}

	cout << endl;
	

	return 0;
}

Measured memory_bytes: 1188