akhauriyash/Code-Regression huggingface dataset:
#include<stdio.h>
#include<stdlib.h>

int main(void){

	int add=0,number;
	char num[2];

	num[0]=getchar();
	if(num[0]=='0')
		return 0;
	while(1){
		if(num[0]=='\n'){
			printf("%d\n",add);
			num[0]=getchar();
			if(num[0]=='0')
				break;
			add=0;
		}
		number=atoi(num);
		add+=number;
		num[0]=getchar();
	}
	return 0;
}

Measured memory_bytes: 524
#define _GLIBCXX_DEBUG
#include <iostream>
#include <cstdio>
#include <bits/stdc++.h>//"geometry.cpp"
#include <iomanip>//"cout<<fixed<<setprecision(n)<<sth<<endl;"
#include <queue>
#include <string>//"reverse((s's iterator), (s's iterator))"
#include <vector>
#include <utility>
#include <set>
#include <map>
#include <algorithm>//"lower_bound(it,it,v)", "next_permutation(a,a+n)"
#include <functional>//"greater<T>" Ex. sort(a,a+n,greater<int>());
#include <cmath>//"abs", "sqrt"
using namespace std;
#define pb push_back//Can be used for STRING
#define fi first
#define sc second
#define mp make_pair
#define is insert
typedef pair<int,int> pii;//Add other types in the same way.

const int f=32;

string lltostr(long long n){
	string ret;
	while(n>0){
		ret.pb('0'+n%10);
		n/=10;
	}
	reverse(ret.begin(),ret.end());
	return ret;
}

int main(){
	long long s,i=0,m=10,d=1;
	string ans;
	cin>>s;
	while(true){
		long long a=min((m-i-1)/15,s/(f+d*8));
		s-=(f+d*8)*a;
		i+=15*a;
		if(i+14<m) a=(f+d*8);
		else if(i+13<m) a=(f+d*8+1);
		else if(i+11<m) a=(f+d*8+2);
		else if(i+8<m) a=(f+d*8+3);
		else if(i+7<m) a=(f+d*8+4);
		else if(i+4<m) a=(f+d*8+5);
		else if(i+2<m) a=(f+d*8+6);
		else a=(f+d*8+7);
		if(a>=s) break;
		s-=a;
		m*=10;
		d+=1;
		i+=15;
	}
	while(ans.size()<s+20){
		++i;
		if(i%15==0) ans+="FizzBuzz";
		else if(i%3==0) ans+="Fizz";
		else if(i%5==0) ans+="Buzz";
		else ans+=lltostr(i);
	}
	cout<<ans.substr(s-1,20)<<endl;
}

Measured memory_bytes: 3152
/*
	ワーシャル-フロイド法(無向グラフ)
										*/

#include <bits/stdc++.h>
using namespace std;
const long long INF = 1L<<60;

long long V, E;
vector<vector<long long>> d;
struct Edge {
	long long from;
	long long to;
	long long cost;
};

vector<Edge> es;
vector<long long> d2;

void warshall_floyd(){
	for(long long k = 0; k < V; k++){
		for(long long i = 0; i < V; i++){
			for(long long j = 0; j < V; j++){
				if(i == j){
					d[i][j] = 0;
				}else{
					d[i][j] = min(d[i][j], d[i][k] + d[k][j]);
				}
			}
		}
	}
}

bool find_negative_loop() {
	for(long long i = 0; i < V; i++) d2[i] = 0;
	for(long long i = 0; i < V; i++){
		for(long long j = 0; j < E; j++){
			Edge e = es[j];
			if(d2[e.to] > d2[e.from] + e.cost){
				d2[e.to] = d2[e.from] + e.cost;
				if(i == V - 1) return true;
			}
		}
	}
	return false;
}

int solve() {
	cin >> V >> E;
	d2.resize(V);
	d.resize(V, vector<long long>(V));
	for(long long i = 0; i < V; i++){
		for(long long j = 0; j < V; j++){
			d[i][j] = INF;
		}
	}
	for(long long i = 0; i < E; i++) {
		long long a, b, cost;
		cin >> a >> b >> cost;
		Edge e = {a, b, cost};
		es.push_back(e);
		d[a][b] = cost;
	}
	if(find_negative_loop()){
		cout << "NEGATIVE CYCLE" << endl;
		return 0;
	}
	warshall_floyd();
	for(long long i = 0; i < V; i++){
		for(long long j = 0; j < V; j++){
			if(d[i][j] >= INF - 1000000000000){
				if(j == V-1){
					cout << "INF";
				}else{
					cout << "INF" << " ";
				}
			}else{
				if(j == V-1){
					cout << d[i][j];
				}else{
					cout << d[i][j] << " ";
				}
			}
		}
		cout << endl;
	}
	return 0;
}

int main() {
	cout << std::fixed << std::setprecision(10);
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
	return solve();
}



Measured memory_bytes: 3516
#include <bits/stdc++.h>
using namespace std;
 
using ll = long long int;
using ull = unsigned long long int;
using P = pair<ll, ll>;
using P3 = pair<ll, P>;
using PP = pair<P ,P>;
constexpr ll MOD = ll(1e9+7);
constexpr int IINF = INT_MAX;
constexpr ll LLINF = LLONG_MAX;
constexpr int MAX_N = int(1e6) + 5;
constexpr double EPS = 1e-8;
constexpr int di[] = {0, 1, 0, -1}, dj[] = {1, 0, -1, 0};
#define REP(i, n) for (int i = 0; i < n; i++)
#define REPR(i, n) for (int i = n; i >= 0; i--)
#define SORT(v) sort((v).begin(), (v).end())
#define SORTR(v) sort((v).rbegin(), (v).rend())
#define ALL(v) (v).begin(), (v).end()
 
vector<vector<int> > g;

double dp[605][2], dp2[605];

int main(){
    int n, m;
    cin >> n >> m;
    g.resize(n);
    for(int i=0;i<m;i++){
        int s, t;
        cin >> s >> t;
        s--; t--;
        g[s].push_back(t);
    }
    for(int i=0;i<n-1;i++){
        dp[i][0] = dp[i][1] = 1e5;
    }
    for(int i=n-2;i>=0;i--){
        double sum = 0.0, maxi = 0.0, dif = 0.0;
        for(auto from : g[i]){
            double tmp = dp[from][0]+1;
            sum += tmp;
            maxi = max(maxi, tmp);
            dif = max(dif, dp[from][0]-dp[from][1]);
        }
        dp[i][0] = min(dp[i][0] ,sum/double(g[i].size()));
        dp[i][1] = dp[i][0];
        if(g[i].size()>=2){
            dp[i][1] = min(dp[i][1], (sum-maxi)/double(int(g[i].size())-1));
        }
    
    }
    dp2[0] = 1.0;
    for(int i=0;i<n;i++){
        for(auto to : g[i]){
            dp2[to] += dp2[i]/double(g[i].size());
        }
    }
    double ans = 1e5;
    for(int i=0;i<n;i++){
        ans = min(ans, dp[0][0]+(dp[i][1]-dp[i][0])*dp2[i]);
    }
    printf("%.10lf\n",ans);
    return 0;
}

Measured memory_bytes: 1408
/* ex 7_1
   nabe9393 */

#include<stdio.h>

typedef struct point{
    int x_elem;
    int y_elem;
}point;

//qを中心にしてpを回す
point shift_point(point p, point q){
  point r;
  //複素数平面を考えて、各頂点をその他の頂点を中心に回転させる
  //cos270°+isin270°=-i
  r.x_elem = q.x_elem + p.y_elem - q.y_elem;
  r.y_elem = q.y_elem - p.x_elem + q.x_elem;
  return r;
}

int main(void){
  //各頂点の構造体
  point point_1,point_2,point_3,point_4;
  //入力
  scanf("%d %d",&point_1.x_elem,&point_1.y_elem);
  scanf("%d %d",&point_2.x_elem,&point_2.y_elem);

  //各頂点の計算
  point_3=shift_point(point_1, point_2);
  point_4=shift_point(point_2, point_3);
  
  //出力
  printf("%d %d %d %d\n", point_3.x_elem,point_3.y_elem,point_4.x_elem,point_4.y_elem);
  return 0;
}

Measured memory_bytes: 1704
import java.util.*;

public class Main{

	public static void main(String[] args){

		Scanner sc = new Scanner(System.in);
        int x  = sc.nextInt();
        int y  = sc.nextInt();
        
        if(y % 2 != 0){
           System.out.println("No");
        }else if((y == 2 || y == 4) && x == 1){
           System.out.println("Yes");
        }else{
          int kame = x*4-y;
          int turu = y-x*2;
          if(kame >=0 && turu >=0 ){
            System.out.println("Yes");
          }else{
            System.out.println("No");
          }
        }
        
	}
}

Measured memory_bytes: 35632
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <climits>
#include <vector>
#include <string>
#include <queue>
#include <deque>
#include <list>
#include <stack>
#include <set>
#include <map>
#include <algorithm>

#define int long long
#define MOD7 1000000007
#define MOD9 1000000009

#define rep(i, n) for (int i = 0; i < (n); i++)
#define REP(i, a, n) for (int i = (a); i <= (n); i++)
#define all(a) (a).begin(), (a).end()

using namespace std;

int dx[4] = { 1, 0, -1, 0 };
int dy[4] = { 0, -1, 0, 1 };

int nextInt() {int a; cin >> a; return a;}
char nextChar() {char a; cin >> a; return a;}
double nextDouble() {double a; cin >> a; return a;}
string nextString() {string a; cin >> a; return a;}

void inputVector(vector<int> &v, int &n) {rep(i,n){v.push_back(nextInt());}}
void inputVector(vector<double> &v, int &n) {rep(i,n){v.push_back(nextDouble());}}
void inputVector(vector<string> &v, int &n) {rep(i,n){v.push_back(nextString());}}

bool isprime[1000010];

signed main() {
    rep(i, 1000010) isprime[i] = true;
    isprime[1] = false;
    for (int i = 2; i <= 1000000; i++) {
	if (!isprime[i]) continue;
	for (int j = 2 * i; j <= 1000000; j += i) {
	    isprime[j] = false;
	}
    }

    int a, d, n;
    while (cin >> a >> d >> n) {
	if (!a) break;
	if (isprime[a]) n--;
	while (n) {
	    a += d;
	    if (isprime[a]) n--;
	}
	cout << a << endl;
    }

    return 0;
}

Measured memory_bytes: 4012
<?php

while (true) {
    fscanf(STDIN, "%d %d", $H, $W);

    if (0 == $H && 0 == $W) break;

    for ($i = 0; $i < $H; $i++) {
        for ($j = 0; $j < $W; $j++) {
            $n = ($i%2) + $j;

            echo is_even($n) ? '#' : '.';
        }

        echo "\n";
    }

    echo "\n";
}

function is_even($n)
{
    return 0 == $n % 2;
}

Measured memory_bytes: 6588
#include <algorithm>
#include <iterator>
#include <iostream>
#include <iomanip>
#include <cassert>
#include <utility>
#include <string>
#include <vector>
#include <limits>
#include <queue>
#include <cmath>
#include <map>
#include <set>

using namespace std;

using ll = long long;

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

    vector<double> p(n);

    for(int i = 0; i < n; ++i)
        cin >> p[i];

    vector<vector<double> > dp(n + 1, vector<double>(n + 1));
    dp[0][0] = 1.0;


    for(int i = 1; i < n + 1; ++i)
        dp[i][0] = dp[i - 1][0] * (1.0 - p[i - 1]);

    for(int i = 1; i < n + 1; ++i) {
        for(int j = 1; j < i + 1; ++j) {
            double pos = p[i - 1];
            double neg = 1.0 - pos;
            dp[i][j] = dp[i - 1][j] * neg + dp[i - 1][j - 1] * pos;
        }
    }

    /*
    for(int i = 0; i < n + 1; ++i) {
        copy(dp[i].begin(), dp[i].end(), ostream_iterator<double>(cout, " "));
        cout << endl;
    }
    */

    double out = 0.0;
    for(int j = n / 2 + 1; j < n + 1; ++j)
        out += dp[n][j];

    cout << fixed << setprecision(12) << out << endl;

    return 0;
}


Measured memory_bytes: 70784
#include<iostream>
#include<algorithm>
#include<string>
#include<functional>
#include<utility>
#include<stack>
#include<queue>
#include<cmath>
#include<list>
#include<cstdint>
#include<vector>
#include<map>
#include<deque>
#define rep(i,rept)	for(ll i = 0; i<rept;i++)
typedef long long ll;
const ll MOD = 1e9 + 7;
using namespace std;

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

	int a = 0, size = 0;
	std::string str[100] = {};

	bool okada = true;

	cin >> a;
	cin >> str[0];

	for (int i = 1; i < a; i++) {
		cin >> str[i];

		if (a == 2) {
			cout << "No" << endl;
			return 0;
		}


		if (i > 1 && str[i][0] != str[i - 1][size - 1]) {
			cout << "No" << endl;
			return 0;
		}

		size = str[i].size();
	}

	for (int i = 0; i < a - 1; i++) {
		for (int j = i + 1; j < a; j++) {
			if (str[i] == str[j]) {
				cout << "No" << endl;
				return 0;
			}
		}
	}
	cout << "Yes" << endl;
	return 0;
}

Measured memory_bytes: 256
declare var process: any;
process.stdin.resume();
process.stdin.setEncoding("utf8");
process.stdin.on("data", function(chunk: any) {
  var lines = chunk
    .toString()
    .split("\n")[0]
    .split(" ");
  if (parseInt(lines[0]) + parseInt(lines[1]) >= parseInt(lines[2])) {
    console.log("Yes");
  } else {
    console.log("No");
  }
});


Measured memory_bytes: 7500
import sys 
sys.setrecursionlimit(10**8)

def search_unseen(fr,to,cost):  
  cost_from_k[to] += cost_from_k[fr] + cost
  for n_to,n_cost in es[to]:
    if cost_from_k[n_to] == 0 and k!=n_to:
      search_unseen(to, n_to, n_cost)

n = int(input())
es = {i:[] for i in range(n)}
for i in range(n-1):
  a,b,c = map(int,input().split())
  es[a-1].append((b-1,c))
  es[b-1].append((a-1,c))      
      
q,k = map(int,input().split())
xy = [list(map(int,input().split())) for _ in range(q)]
k -=1

cost_from_k = [0]*n      
search_unseen(k, k, 0)

for x,y in xy:
  print(cost_from_k[x-1] + cost_from_k[y-1])      

Measured memory_bytes: 164524
MOD = 10**9 + 7
n, m = map(int, input().split())

ban = [False] * (n + 1)

for i in range(m):
    a = int(input())
    ban[a] = True

dp = [0] * (n+1)
dp[0] = 1
for i in range(n):
    dp[i] %= MOD
    if(ban[i]):dp[i] = 0
    if i + 1 <= n:
        dp[i+1] += dp[i]
    if i + 2 <= n:
        dp[i+2] += dp[i]

print(dp[n] % MOD)

Measured memory_bytes: 7668
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cfloat>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <fstream>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <memory>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>

// c++11
#include <array>
#include <tuple>
#include <unordered_map>
#include <unordered_set>

#define mp make_pair
#define mt make_tuple
#define rep(i, n) for (int i = 0; i < (n); i++)

using namespace std;

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

const int INF = 1 << 29;
const ll LL_INF = 1LL << 60;
const double EPS = 1e-9;
const ll MOD = 1000000007;

const int dx[] = {1, 0, -1, 0}, dy[] = {0, -1, 0, 1};
int N, Q;

int parent(int p)
{
    if (p % N == 0)
    {
        return p / N - 1;
    }
    return p / N;
}
void path(int p, int q)
{
    // cerr << "root = "  << p << endl;
    if (N == 1){
        printf("%d\n", min(p, q) + 1);
        return ;
    }
    while (p != q)
    {
        if (p < q)
        {
            swap(p, q);
        }
        p = parent(p);
        // p = max(p, 0);
    }
    printf("%d\n", p+1);
}
int main()
{

    scanf("%d %d", &N, &Q);
    for (int i = 0; i < Q; i++)
    {
        int a, b;
        scanf("%d %d", &a, &b);
        a--, b--;
        
        path(a, b);
        // cerr << a << " " << b << endl;
    }
    return 0;
}


Measured memory_bytes: 1280
import java.util.Scanner;
class Main
{
	public static void main(String args[])
	{
		Scanner sc=new Scanner(System.in);
        int n=sc.nextInt();
        int k=sc.nextInt();
        String s=sc.next();

        System.out.println(s.substring(0,k-1)
            +(s.substring(k-1,k)).toLowerCase()+s.substring(k,n));
    }
}

Measured memory_bytes: 21844
W = [int(x) for x in input().split()]
if W[0] ==1:
    if W[1] ==1:
        print(1000000)
    elif W[1] ==2:
        print(500000)
    elif W[1] ==3:
        print(400000)
    else:
        print(300000)
elif W[0] ==2:
    if W[1] ==1:
        print(500000)
    elif W[1] ==2:
        print(400000)
    elif W[1] ==3:
        print(300000)
    else:
        print(200000)
elif W[0] ==3:
    if W[1] ==1:
        print(400000)
    elif W[1] ==2:
        print(300000)
    elif W[1] ==3:
        print(200000)
    else:
        print(100000)
else:
    if W[1] ==1:
        print(300000)
    elif W[1] ==2:
        print(200000)
    elif W[1] ==3:
        print(100000)
    else:
        print(0)

Measured memory_bytes: 3064
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner in = new Scanner(new BufferedReader(new InputStreamReader(System.in)));
		int n = in.nextInt();
		int[][] hp = getIntArr(in, n, 3);
		int r = solve(n, hp);
		System.out.println(r);
		in.close();
	}

	private static int solve(int n, int[][] hp) {
		int ma = 0;
		int mb = 0;
		int mc = 0;
		for (int i = 0; i < hp.length; i++) {
			int a = Math.max(mb, mc) + hp[i][0];
			int b = Math.max(ma, mc) + hp[i][1];
			int c = Math.max(mb, ma) + hp[i][2];
			ma = a;
			mb = b;
			mc = c;
		}
		return Math.max(Math.max(ma, mb), mc);
	}

	static String str(int[] a) {
		String[] str = new String[a.length];
		for (int i = 0; i < a.length; i++) {
			str[i] = a[i] + "";
		}
		return String.join(" ", str);
	}

	static int[] getIntArr(Scanner in, int size) {
		int[] arr = new int[size];
		for (int i = 0; i < size; i++) {
			arr[i] = in.nextInt();
		}
		return arr;
	}

	static int[][] getIntArr(Scanner in, int row, int col) {
		int[][] arr = new int[row][];
		for (int i = 0; i < row; i++) {
			arr[i] = getIntArr(in, col);
		}
		return arr;
	}

	static char[] getCharArr(Scanner in, int size) {
		char[] arr = in.next().toCharArray();
		return arr;
	}

	static String[] getStringArr(Scanner in, int size) {
		String[] arr = new String[size];
		for (int i = 0; i < size; i++) {
			arr[i] = in.next();
		}
		return arr;
	}

	static Map<Integer, List<Integer>> getEdges(Scanner in, int size, boolean directed) {
		Map<Integer, List<Integer>> edges = new HashMap<>();
		for (int i = 0; i < size; i++) {
			int from = in.nextInt();
			int to = in.nextInt();
			if (!edges.containsKey(from)) {
				edges.put(from, new ArrayList<Integer>());
			}
			edges.get(from).add(to);
			if (!directed) {
				if (!edges.containsKey(to)) {
					edges.put(to, new ArrayList<Integer>());
				}
				edges.get(to).add(from);
			}

		}
		return edges;
	}
}


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

#define si(a) scanf("%d",&a)
#define sl(a) scanf("%lld",&a)
#define sd(a) scanf("%lf",&a)
#define sc(a) scahf("%c",&a);
#define ss(a) scanf("%s",a)
#define pi(a) printf("%d\n",a)
#define pl(a) printf("%lld\n",a)
#define pc(a) putchar(a)
#define ms(a) memset(a,0,sizeof(a))
#define repi(i, a, b) for(register int i=a;i<=b;++i)
#define repd(i, a, b) for(register int i=a;i>=b;--i)
#define reps(s) for(register int i=head[s];i;i=Next[i])
#define ll long long
#define ull unsigned long long
#define vi vector<int>
#define pii pair<int,int>
#define mii unordered_map<int,int>
#define msi unordered_map<string,int>
#define lowbit(x) ((x)&(-(x)))
#define ce(i, r) i==r?'\n':' '
#define pb push_back
#define fi first
#define se second
#define all(x) x.begin(),x.end()
#define INF 0x3f3f3f3f
#define pr(x) cout<<#x<<": "<<x<<endl
using namespace std;

inline int qr() {
    int f = 0, fu = 1;
    char c = getchar();
    while (c < '0' || c > '9') {
        if (c == '-')fu = -1;
        c = getchar();
    }
    while (c >= '0' && c <= '9') {
        f = (f << 3) + (f << 1) + c - 48;
        c = getchar();
    }
    return f * fu;
}

int n, now, a;

int main() {
    n = qr();
    ll ans = 0;
    repi(i, 1, n) {
        a = qr();
        ans += max(0, now - a);
//        pr(max(0,a-now));
        now = max(now, a);
//        pr(now);
    }
    pl(ans);
    return 0;
}

Measured memory_bytes: 3760
#include <iostream>
#include<cstdlib>
#include<queue>
#include<set>
#include<vector>
#include<string>
#include<algorithm>
#include<stack>
#include<map>
#include<cstdio>
using namespace std;
#define rep(i,a) for(int i=0;i<a;i++)
#define mp make_pair
#define pb push_back
#define P pair<int,int>
#define ll __int64
//#define ll long long
int n;


int main(){
	bool ok=1;
	int nx=0,ny=0,nt=0;

	cin>>n;
	rep(i,n){
		int t,x,y;	
		cin>>t>>x>>y;
		if(abs(nx+ny-x-y)>t||abs(abs(t-nt)-abs(nx+ny-x-y))%2)ok=0;
		nx=x,ny=y,nt=t;
	}
	if(ok)cout<<"Yes"<<endl;
	else cout<<"No"<<endl;
	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;

void solve(){
    string s1,s2;
    cin>>s1>>s2;
    int n1=s1.length(),n2=s2.length();
    vector<vector<pair<int,pair<int,int>>>> dp(n1+1,vector<pair<int,pair<int,int>>>(n2+1,make_pair(INT_MIN,make_pair(0,0))));
    dp[0][0]={0,{0,0}};
    for(int i=0;i<n1;i++){
        for(int j=0;j<n2;j++){
            if(s1[i]==s2[j]) dp[i+1][j+1]=max(dp[i+1][j+1],make_pair(1+dp[i][j].first,make_pair(i,j)));
            dp[i+1][j]=max(dp[i+1][j],make_pair(dp[i][j].first,make_pair(i,j)));
            dp[i][j+1]=max(dp[i][j+1],make_pair(dp[i][j].first,make_pair(i,j)));
        }
    }
    pair<int,pair<int,int>> pm=make_pair(0,make_pair(0,0));
    for(int i=0;i<=n1;i++){
        for(int j=0;j<=n2;j++)
        pm=max(pm,make_pair(dp[i][j].first,make_pair(i,j)));
    }
    
    string ans="";
    pair<int,int> cur=pm.second;
    
    while(cur.first!=0 && cur.second!=0){
        pair<int,int> prev=dp[cur.first][cur.second].second;
        if(prev==make_pair(cur.first-1,cur.second-1)) ans+=s1[prev.first];
        cur=prev;
    }
    reverse(ans.begin(),ans.end());
    cout<<ans;
}

int main() {
	// your code goes here
	//freopen("inptmp0.txt","r",stdin);
	int T;
	
	//cin>>T;
	T=1;
	while(T--){
	    solve();
	}
	return 0;
}


Measured memory_bytes: 108768
#include <iostream>
#include<bits/stdc++.h>
#define ll long long int
#define lld long double
#define F first
#define S second
#define f(i,a,b) for(int i=a;i<=b;i++)
#define g(i,a,b) for(int i=a;i>=b;i--)
#define pb push_back
#define mh make_heap
#define ph push_heap
#define pq priority_queue
#define bits(x) __builtin_popcountll(x)
#define op(x) cout<<"Case #"<<x<<": "
#define op1(x) cout<<"Scenario #"<<x<<": "
#define endl "\n"
using namespace std;
const ll mod = 1000000007;
const ll INF = 1e18;
const int N = 18;




void solve(int t)
{
	string s;
	cin >> s;

	int ans = 0;
	for (auto i : s)
	{
		ans = (ans * 10 + (i - '0')) % 9;

	}

	if (ans == 0)
	{
		cout << "Yes" << endl;
	}
	else
	{
		cout << "No" << endl;
	}


}


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





	int t = 1;
	//cin >> t;



	for (int i = 1; i <= t; i++)
	{
		solve(i);

	}
}

Measured memory_bytes: 3780
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
#define mfill(x,y) memset(x,y,sizeof(x))
#define all(v) v.begin(), v.end()
#define in(x,y,h,w) if(0<=x&&x<h&&0<=y&&y<w)
#define y0 y12345
#define y1 y54321

#ifdef LOCAL
#define debug(...) fprintf(stderr,__VA_ARGS__)
#else
#define debug(...) 42
#endif

using ul = unsigned long;
using ll = long long;
using P = pair<int, int>;
using vint = vector<int>;using vvint = vector<vector<int>>;
using vll = vector<ll>;using vvll = vector<vector<ll>>;
template<class T>bool chmax(T &a, const T &b){if(a<b){a=b;return 1;}return 0;}
template<class T>bool chmin(T &a, const T &b){if(a>b){a=b;return 1;}return 0;}
template <class T>void initvv(vector<vector<T> > &v, int a, int b, const T &t = T()){
	v.assign(a, vector<T>(b, t));
}
template <class T>T gcd(T &a, T &b){if(a<b){swap(a,b);} T r = a%b; while(r!=0){a=b;b=r;r=a%b;} return b;}

vint dx = {-1, 0, 1, 0}, dy = {0, -1, 0, 1};
vint dx8 = {-1, -1, -1, 0, 1, 1, 1, 0}, dy8 = {-1, 0, 1, 1, 1, 0, -1, -1};

string s;
int n;

vvint d;
int inf = -10000000;

int dp(int pos, int pa){
	if(pos == n) return 0;
	if(d[pos][pa] != inf)return d[pos][pa];
	int ret = dp(pos+1, pa) - (s[pos]=='g'?0:1);
	if(pa + 1 <= pos - pa)chmax(ret, dp(pos+1, pa+1) + (s[pos]=='g'?1:0));
	//ret += dp(pos+1, pa) - (s[pos]=='g'?0:1);
	return d[pos][pa]=ret;
}

int main() {
	cin.tie(0);
   	ios::sync_with_stdio(false);
	debug("debug test\n");
   	int m;cin>>s;n = s.length();
	//initvv(d, n+1, n+1, inf);
	//cout << dp(0, 0) << endl;
	ll ans = 0;
	rep(i, n){
		if(s[i]=='p')ans--;
	}
	cout << ans + (ll)n/2;
	
	return 0;
}


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

using namespace std;
#define all(x) (x).begin(), (x).end()
#define rep(i, n) for (int i = 0; i < (n); i++)
#define endl "\n"
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

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

ll get(ll x, vector<ll> &D) {
    ll M = D.size();
    if ((x + 100000000000LL) % 2 == 1) {
        return ((1LL << M) - 1 - x) / 2;
    } else {
        return (1LL << (M - 1)) | ((1LL << (M - 1)) - (x + 1)) / 2;
    }
}
 
void solve() {
    ll N;
    cin >> N;
    vector<pii> P;
    set<ll> S;
    for (int i = 0; i < N; i++) {
        ll x, y;
        cin >> x >> y;
        P.push_back({x + y, x - y});
        S.insert((x + y + 1000000000000LL) % 2);
        S.insert((x - y + 1000000000000LL) % 2);
    }
 
    if (S.size() == 2) {
        cout << "-1" << endl;
        return;
    }
 
    ll M = 39;
    vector<ll> D(M);
    for (int i = 0; i < M; i++) {
        D[i] = 1LL << i;
    }
 
    vector<ll> D_ = D;
 
    if (*S.begin() % 2 == 0) {
        D_.push_back(1);
        M++;
    }
 
    cout << D_.size() << endl;
    for (int i = 0; i < D_.size(); i++) {
        cout << D_[i];
        if (i + 1 != D_.size()) {
            cout << " ";
        }
    }
    cout << endl;
    
    for (int i = 0; i < N; i++) {
        ll k1 = get(P[i].first, D_);
        ll k2 = get(P[i].second, D_);
        for (ll i = 0; i < M; i++) {
            ll k = ((k1 >> i & 1) << 1) | (k2 >> i & 1);
            if (k == 0) {
                cout << "R";
            } else if (k == 1) {
                cout << "U";
            } else if (k == 2) {
                cout << "D";
            } else {
                cout << "L";
            }
        }
        cout << endl;
    }
}
 
int main() {
    std::cin.tie(0);
    std::ios::sync_with_stdio(false);
    cout.setf(ios::fixed);
    cout.precision(16);
    solve();
    return 0;
}

Measured memory_bytes: 384
import java.io.*;
import java.util.*;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		PrintWriter out = new PrintWriter(System.out);
		// ------------------------------------------------
		int n = Integer.parseInt(sc.next());
		String s = sc.next(), t = sc.next();
		String ret = "";
		for (int i = 0; i < n; i++) {
			ret += s.charAt(i);
			ret += t.charAt(i);
		}
		out.println(ret);

		// ------------------------------------------------
		sc.close();
		out.flush();
	}
}

Measured memory_bytes: 27088
#include<bits/stdc++.h>
#define IOS ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define endl "\n"
#define pb push_back
#define mp make_pair
#define int long long
#define mod 1000000007
#define DEBUG cout<<"Hello1\n";
#define all(v) (v).begin(),(v).end()
#define clr(x) memset(x,0,sizeof(x))
#define deb(...) debug(#__VA_ARGS__, __VA_ARGS__);
const int N = 1e6 + 5;
const double pi =  acosl(-1);
const long long inf = 1e18 + 5;
using namespace std;
template<typename T> void debug(string s, T x) {cout << s << " = " << x << "\n";}
template<typename T, typename... Args> void debug(string s, T x, Args... args) {cout << s.substr(0, s.find(',')) << " = " << x << " | "; debug(s.substr(s.find(',') + 2), args...);}
template<class T> void print_container(T &container) { for (auto &t : container) { cout << t << " ";} cout << endl;}
template<class T> void printArr(T &a , int n) { for (int i = 0; i < n; i++) {cout << a[i] << " ";} cout << endl;}
typedef long long ll;
typedef pair<int, int> pii;

//Template Ends
int n;
string 	a;

void solve() {
	cin >> n >> a;

	int ans = 0;

	int low = 0, high = n - 1;

	while (low < high) {
		while (low < n && a[low] == 'R') {
			low++;
		}
		while (high >= 0 && a[high] == 'W') {
			high--;
		}

		if (low < high) {
			ans++;
			swap(a[low], a[high]);
		}
	}

	cout << ans << endl;

}

int32_t main() {
	IOS;

	solve();

	return 0;
}




Measured memory_bytes: 3736
n, m = map(int, input().split())
k = [i for i in range(1, n + 1)]
v = [0] * n
d = dict(zip(k, v))

for _ in range(m):
    a, b = map(int, input().split())
    d[a] += 1
    d[b] += 1

for x in d.values():
    print(x)  
    

Measured memory_bytes: 9184
//
// Created on 2018/12/02.
//
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;

#define REP(i,n) for(int i=0;i<(n);++i)
#define RREP(i,n) for(int i=(n)-1;i>=0;--i)
#define FOR(i,m,n) for(int i=m;i<(n);++i)
#define RFOR(i,m,n) for(int i=(n)-1;i>=(m);--i)
#define ALL(v) (v).begin(),(v).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define UNIQUE(v) v.erase(unique(ALL(v)),v.end());
#define dump(x) cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" \
                      << " " << __FILE__ << endl;
template<class T> bool INRANGE(T x,T a,T b) { return a<=x&&x<=b; }

#define PB push_back
#define INF 1000000001ll
#define MOD 1000000007ll
#define EPS 1e-9

const int dx[8] = { 1,1,0,-1,-1,-1,0,1 };
const int dy[8] = { 0,1,1,1,0,-1,-1,-1 };

typedef vector<int> vi;
typedef vector<string> vs;
typedef vector<ll> vl;
typedef vector<vi> vvi;
typedef vector<vl> vvl;
typedef vector<vs> vvs;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

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

    int n;
    cin >> n;

    if (n == 7 || n == 5 || n == 3 ) cout << "YES" << endl;
    else cout << "NO" << endl;

    return 0;

}

Measured memory_bytes: 256
import sys
input = sys.stdin.readline
from bisect import bisect_left

class SegmentTree:
    def __init__(self, n, ele, segfun):
        #####単位元######要設定0or1orinf
        self.ide_ele = ele
        self.segfun = segfun
        ####################
        self.n = n
        self.N0 = 1 << n.bit_length()
        self.data = [self.ide_ele] * (self.N0 * 2)

    def update_add(self, l, r, val):
        l += self.N0
        r += self.N0
        while l < r:
            if l & 1:
                self.data[l] += val
                l += 1
            if r & 1:
                self.data[r - 1] += val
                r -= 1
            l //= 2
            r //= 2

    def update(self, l, r, val):
        l += self.N0
        r += self.N0
        while l < r:
            if l & 1:
                self.data[l] = self.segfun(self.data[l], val)
                l += 1
            if r & 1:
                self.data[r - 1] = self.segfun(self.data[r - 1], val)
                r -= 1
            l //= 2
            r //= 2

    def query(self, i):
        i += len(self.data) // 2
        ret = self.data[i]
        while i > 0:
            i //= 2
            ret = self.segfun(ret, self.data[i])
        return ret

n,q = map(int,input().split())
chk = []
for i in range(n):
  s,t,x = map(int,input().split())
  chk.append((s-x,t-x,x))
d = [int(input()) for i in range(q)]
seg = SegmentTree(q,10**9+1,lambda a, b: min(a,b))

for a,b,x in chk:
  L = bisect_left(d,a)
  R = bisect_left(d,b)
  seg.update(L,R,x)
  
for i in range(q):
  m = seg.query(i)
  if m == 10**9+1:
    print(-1)
  else:
    print(m)

Measured memory_bytes: 115292
#include <iostream>
#include <cmath>
#include <algorithm>
#include <string>
#include <vector>
#include <stack>
#include <map>

using namespace std;

void solve()
{
	unsigned long long int a, b, x;
	cin >> a >> b >> x;
	unsigned long long int ans = 0;
	if (b == 0)
	{
		ans = 1;
	}
	else
	{
		ans = b / x + 1;
	}
	if (a == 0)
	{
		ans -= 0;
	}
	else
	{
		ans -= (a - 1) / x + 1;
	}
	cout << ans << endl;
}

int main()
{
	solve();
	return(0);
}

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

const int64_t MOD= 1000000007;
const int Nfac= 2000007;
#define MEMORY 0 // 1/0: 階乗を配列に格納をする前処理をする/しない
/* 剰余環 Z_n */
struct mint{ // Z_n に関する演算(n:素数の場合は除算も)をサポートする構造体
  int64_t rep; // 出力すべき代表元 rep \in {0,1,..,MOD- 1}
  mint(int64_t x=0): rep(((x%MOD)+ MOD)% MOD){}
  mint operator-() const { return mint(-rep);}
  mint& operator+=(const mint& x){
    rep+= x.rep; 
    if(rep>= MOD) rep-= MOD;
    return *this;
  }
  mint& operator-=(const mint& x){
    rep-= x.rep;
    if(rep< 0) rep+= MOD;
    return *this;
  }
  mint& operator*=(const mint& x){
    rep*= x.rep; rep%= MOD;
    return *this;
  }
  mint operator+(const mint x) const {
    mint ans(*this);
    ans+= x;
    return ans;
  }
  mint operator-(const mint x) const {
    mint ans(*this);
    ans-= x;
    return ans;
  }
  mint operator*(const mint x) const {
    mint ans(*this);
    ans*= x;
    return ans;
  }

  mint pow(int64_t d) const{ // d \geq 0
    if(d==0) return 1;
    else{
      mint ans= pow(d>>1);
      ans*= ans;
      if(d&1){ ans*= *this; }

      return ans;
    }
  }

  // MOD が素数(<=> Z_n が体)のとき
  mint inv() const{
    return pow(MOD-2);
  }
  mint& operator/=(const mint& x){
    *this *= x.inv();
    return *this;
  }
  mint operator/(const mint x) const {
    mint ans(*this);
    ans/= x;
    return ans;
  }
};

/* 階乗,二項係数 */
#if (MEMORY==1)
// 前処理として,階乗を配列に格納をするver.
vector<mint> mfac(Nfac+1), ifac(Nfac+1);
void fact_modp_init(int N= Nfac){
  mfac.at(0)= 1;
  mint buf;
  for(int i=1; i<=N; i++){
    buf= i;
    mfac.at(i)= mfac.at(i-1)* buf;
  }

  ifac.at(N)= mfac.at(N).inv();
  for(int i=N; i>0; i--){
    buf= i;
    ifac.at(i-1)= ifac.at(i)* buf;
  }
}
#else
// 前処理を回避するver.
void fact_modp_init(int N= Nfac){}
mint mfac(int N){
  mint ans= 1;
  mint buf;
  for(int i=1; i<=N; i++){
    buf= i;
    ans*= buf;
  }

  return ans;
}
#endif
mint choose_modp(int n, int k){
  if(n < 0 || min(n,n-k) < 0) return 0;
  else{
#if (MEMORY==1)
    return mfac.at(n)* ifac.at(k)* ifac.at(n-k);
#else
    return mfac(n)* mfac(k).inv()* mfac(n-k).inv();
#endif
  }
}
// ^^^ テンプレここまで ^^^
mint route(int r, int c){
  return choose_modp(r+c, c);
}

int main() { // S= f(r_2 +1, c_2 +1)- f(r_2 +1, c_1)- f(r_1, c_2 +1)+ f(r_1, c_1)
  int r1,c1,r2,c2;
  cin >> r1 >> c1 >> r2 >> c2;

  fact_modp_init(r2+c2+2);
  mint ans= route(r2+1, c2+1)- route(r2+1, c1)- route(r1, c2+1)+ route(r1, c1);

  cout << ans.rep << endl;
}

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

using namespace std;

int C(int N, int M, int K, vector<long long>& A, vector<long long>& B) {
	for (int i = 1; i < N; i++)
		A[i] += A[i - 1];
	for (int i = 1; i < M; i++)
		B[i] += B[i - 1];
	
	int read = distance(B.begin(), upper_bound(B.begin(), B.end(), K));
	for (int i = 0; i < N; i++) {
		if (A[i] > K)
			break;
		int books = distance(B.begin(), upper_bound(B.begin(), B.end(), K - A[i]));
		read = max(i + 1 + books, read);
	}

	return read;
}

int main() {
	int N, M, K;
	cin >> N >> M >> K;
	vector<long long> A(N), B(M);
	for (int i = 0; i < N; i++)
		cin >> A[i];
	for (int i = 0; i < M; i++)
		cin >> B[i];
	cout << C(N, M, K, A, B);
	return 0;
}

Measured memory_bytes: 6424
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i, n) for(i = 0; i < n; i++)
//2D::rep(i,j)rep(j,j)cin>>bin[i][j];
//vector<int> a(n)
#define A1 cout<<"No"<<endl
#define A2 cout<<"Yes"<<endl
#define A3 cout<<ans<<endl
#define AA(i) cout<<i<<endl
const int U=2e5+5;
const ll MOD=998244353;
const int INF = 1001001001;
#define size 200010

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

int main(){
  int K; cin >> K;
  int i,j,k;
  ll ans = 0;
  for(i=1;i<=K;i++){
    for(j=1;j<=K;j++){
      for(k=1;k<=K;k++){
        ans += gcd(gcd(i,j),k);
      }
    }
  }
  AA(ans);
  return 0;
}

Measured memory_bytes: 3628
#include <algorithm>
#include <iostream>
#include <iomanip>
#include <numeric>
#include <cassert>
#include <vector>
#include <cmath>
#include <queue>
#include <set>
#include <map>
#define syosu(x) fixed<<setprecision(x)
using namespace std;
typedef long long ll;
typedef unsigned int uint;
typedef unsigned long long ull;
typedef pair<int,int> P;
typedef pair<double,double> pdd;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<string> vs;
typedef vector<P> vp;
typedef vector<vp> vvp;
typedef vector<pll> vpll;
typedef pair<int,P> pip;
typedef vector<pip> vip;
const int inf=1<<30;
const ll INF=1ll<<60;
const double pi=acos(-1);
const double eps=1e-8;
const ll mod=998244353;
const int dx[4]={-1,0,1,0},dy[4]={0,-1,0,1};

#include<atcoder/convolution>
using namespace atcoder;

ll Pow(ll n,ll p){
	ll r=1;
	for(;p>0;p>>=1){
		if(p&1) r=(r*n)%mod;
		n=(n*n)%mod;
	}
	return r;
}

const int MAX=1000005;
ll F[MAX],FF[MAX];

void Init(){
	F[0]=1;
	FF[0]=1;
	for(int i=1;i<MAX;i++) F[i]=F[i-1]*i%mod;
	for(int i=1;i<MAX;i++) FF[i]=FF[i-1]*(2*i-1)%mod;
}

ll Div(ll n,ll m){
	return n*Pow(m,mod-2)%mod;
}

ll nCk(ll n,ll k){
	return Div(F[n],F[n-k]*F[k]%mod);
}

const int M=1000001;
int n,a[M],two[M];

int main(){
	two[0]=1;
	for(int i=1;i<M;i++) two[i]=two[i-1]*2%mod;
	Init();
	cin>>n;
	for(int i=0;i<2*n;i++){
		int x;
		cin>>x;
		a[x]++;
	}
	vvl b;
	b.push_back(vl(1,1));
	for(auto i:a) if(i>1){
		vl c(i/2+1);
		for(int j=0;j<=i/2;j++){
			c[j]=nCk(i,2*j)*FF[j]%mod;
		}
		b.push_back(c);
	}
	while(b.size()>1){
		int m=b.size();
		vvl b_;
		for(int i=0;i<m/2;i++){
			vl c=convolution(b[2*i],b[2*i+1]);
			b_.push_back(c);
		}
		if(m%2==1) b_.push_back(b.back());
		b=b_;
	}
	ll m=b[0].size(),res=0;
	for(int i=0;i<m;i++){
		ll t=b[0][i]*FF[n-i]%mod;
		if(i%2==1) (t*=mod-1)%=mod;
		(res+=t)%=mod;
	}
	cout<<res<<endl;
}

Measured memory_bytes: 26680
#18:20
n,q = map(int,input().split())
s = input()
ac = [0]
for i in range(1,n):
  if s[i-1:i+1] == 'AC':
    ac.append(ac[-1] + 1)
  else:
    ac.append(ac[-1])
ac.append(0)
#print(ac)
for _ in range(q):
  l,r = map(int,input().split())
  print(ac[r-1]-ac[l-1])

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

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    string s;
    int k;
    cin >> s >> k;
    long long i = 0;
    for (auto ch: s) {
        if (ch == '1') {
            i++;
        } else {
            cout << ch << endl;
            return 0;
            /*long long j = 1;
            while (i + j * (ch - '0') < k) {
                j *= (ch - '0');
            }
            i += j;*/
        }
        if (k <= i) {
            cout << ch << endl;
            return 0;
        }
    }

}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <utility>
#include <set>
#include <map>
#include <cmath>
#include <queue>
#include <cstdio>
#define rep(i,n) for(int i = 0; i < n; ++i)
#define rep1(i,n) for(int i = 1; i <= n; ++i)
#define F first
#define S second
using namespace std;
template<class T>bool chmax(T &a, const T &b) { if(a < b){ a = b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if(a > b){ a = b; return 1; } return 0; }
using ll = long long;
using pi = pair<int,int>;
int main()
{
  int r; cin >> r;
  cout << r*r << "\n";
  return 0;
}


Measured memory_bytes: 3544
#import sys
MOD = 10 ** 9 + 7
#input = sys.stdin.readline
import math

import itertools

#import bisect

import copy


def sosuhante(n):
    for k in range(2, int(math.sqrt(n))+1):
        if n% k ==0:
            return False
    return True
def cmb(n, r):
    if n - r < r: r = n - r
    if r == 0: return 1
    if r == 1: return n

    numerator = [n - r + k + 1 for k in range(r)]
    denominator = [k + 1 for k in range(r)]

    for p in range(2,r+1):
        pivot = denominator[p - 1]
        if pivot > 1:
            offset = (n - r) % p
            for k in range(p-1,r,p):
                numerator[k - offset] /= pivot
                denominator[k] /= pivot

    result = 1
    for k in range(r):
        if numerator[k] > 1:
            result *= int(numerator[k])

    return result

def kingaku(a,b,n):
    keta=len(str(n))
    return a*n+b*keta

def my_index(l, x, default=False):
    if x in l:
        return l.index(x)
    else:
        return default

#    h,w,a,b = map(int, input().split())
#    c = [[0 for j in range(n)] for i in range(n)]
def main():
    h,n=map(int,input().split())
    a = list(map(int,input().split()))
    if sum(a)>=h:
        print("Yes")
    else:
        print("No")


if __name__ == "__main__":
    main()

Measured memory_bytes: 14528
#include <bits/stdc++.h>
#define read freopen("in.txt", "r", stdin)
#define write freopen("out.txt", "w", stdout)
#define ll long long
using namespace std;
int main()
{
   int n;
   string s;
   cin>>n>>s;
   for(auto i:s){
    int a = i+n;
    if(a>90)
        a=64+(a-90);
    cout<<char(a);
   }
}


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

using namespace std;

int main(void){
    int n;

    cin >> n;
    
    vector<int> a(n,0);

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

    int ans=0;

    int max_a = 0;
    for(int i=0; i<n; i++){
        if(i+1 < a[i]){
            ans++;
            continue;
        }
        if(max_a >= a[i]){
            ans++;
            continue;
        }
        if(max_a+2 <= a[i]){
            ans++;
            continue;
        }
        max_a = a[i];
    }
    if(ans >= n){
        ans = -1;
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 1024
import java.util.*;
public class Main{
	public static void main(String[] args){
    	Scanner sc = new Scanner(System.in);
      long n = sc.nextLong();
      long m = sc.nextLong();
      long x = Math.min(n,m/2);
      n -= x;
      m -= x*2;
      x += Math.max(0,m/4);
      System.out.println(x);
    }
}


Measured memory_bytes: 22740
import java.io.*;
import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {
        BufferedReader buffer = new BufferedReader(new InputStreamReader(System.in));
        StringBuilder sb = new StringBuilder();
        String [] inp = buffer.readLine().split(" ");
        int n = Integer.parseInt(inp[0]), k = Integer.parseInt(inp[1]);
        inp = buffer.readLine().split(" ");
        int [] prices = new int[n];
        for (int pos = 0; pos < n; pos++)
            prices[pos] = Integer.parseInt(inp[pos]);
        Arrays.sort(prices);
        int sum = 0;
        for (int pos = 0; pos < k; pos++) {
            sum += prices[pos];
        }
        sb.append(sum);
        System.out.println(sb);
    }
}


Measured memory_bytes: 32912
#include <iostream>
#include <algorithm>
#include <iomanip>
#include <string>
#include <vector>
#include <math.h>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#define PI 3.14159265359
typedef long long ll;
const int MOD = 1e9+7;
const ll LLINF = 7e18;
using namespace std;

ll par[200001];
ll ran[200001];
ll siz[200001];
 
void init(int n){
	for (int i = 0; i <= n; i++){
		par[i] = i;
		ran[i] = 0;
		siz[i] = 1;
	}
}
int find(int x){
	if (par[x] == x){
		return x;
	}else{
		par[x] = find(par[x]);
		return par[x];
	}
}
void unite(int x, int y){
	x = find(x);
	y = find(y);
	if (x == y) return;
 
	if (ran[x] < ran[y]){
		par[x] = y;
		siz[y] += siz[x];
	}else{
		par[y] = x;
		siz[x] += siz[y];
		if (ran[x] == ran[y]) ran[x]++;
	}
}
bool same(int x, int y){
	return find(x) == find(y);
}
int size(int x){
	return siz[find(x)];
}

int main(){
	int n, m;
	cin >> n >> m;
	init(n);
	for (int i = 0; i < m; i++){
		int a, b;
		cin >> a >> b;
		unite(a, b);
	}
	int ans = 0;
	for (int i = 1; i <= n; i++){
		ans = max(ans, size(i));
	}
	cout << ans << endl;
	return 0;
}



Measured memory_bytes: 8320
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.Arrays;
import java.util.StringTokenizer;

public class Main {
	public static void main(String[] args) {
		FastScanner sc = new FastScanner(System.in);
		int n = sc.nextInt();
		long[] a = new long[n];
		long[] b = new long[n];
		for(int i = 0; i < n; i++) {
			a[i] = sc.nextLong();
			b[i] = a[i];
		}
		Arrays.sort(a);

		int index = n/2;
		if(n % 2 == 0) {
			for(int i = 0; i < n; i++) {
				long x = a[index];
				if(b[i] >= x) {
					x = a[index - 1];
				}
				System.out.println(x);
			}
		}else {
			for(int i = 0; i < n; i++) {
				double x = a[index];
				double y = a[index + 1];
				double ans = 0;
				if(b[i] == x) {
					x = a[index - 1];
				}else if(y <= b[i]) {
					y = a[index - 1];
				}
				ans = (x+y)/2;
				System.out.println(ans);
			}
		}
	}

	static class FastScanner {
		private BufferedReader reader = null;
	    private StringTokenizer tokenizer = null;
	    public FastScanner(InputStream in) {
	        reader = new BufferedReader(new InputStreamReader(in));
	        tokenizer = null;
	    }

	    public String next() {
	        if (tokenizer == null || !tokenizer.hasMoreTokens()) {
	            try {
	                tokenizer = new StringTokenizer(reader.readLine());
	            } catch (IOException e) {
	                throw new RuntimeException(e);
	            }
	        }
	        return tokenizer.nextToken();
	    }

	    public String nextLine() {
	        if (tokenizer == null || !tokenizer.hasMoreTokens()) {
	            try {
	                return reader.readLine();
	            } catch (IOException e) {
	                throw new RuntimeException(e);
	            }
	        }

	        return tokenizer.nextToken("\n");
	    }

	    public long nextLong() {
	        return Long.parseLong(next());
	    }

	    public int nextInt() {
	        return Integer.parseInt(next());
	    }

	    public double nextDouble() {
	         return Double.parseDouble(next());
	     }

	    public int[] nextIntArray(int n) {
	        int[] a = new int[n];
	        for (int i = 0; i < n; i++)
	            a[i] = nextInt();
	        return a;
	    }

	    public long[] nextLongArray(int n) {
	        long[] a = new long[n];
	        for (int i = 0; i < n; i++)
	            a[i] = nextLong();
	        return a;
	    }
	}
}


Measured memory_bytes: 63260
#include <stdio.h>

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

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

int a[20];

int main()
{
    int n, l, i;
    while(scanf("%d", &n)==1){
        l = 0;
        scanf("%d", &a[0]);
        scanf("%d", &a[1]);
        l = lcm(a[0], a[1]);
        for(i=2; i<n; i++){
            scanf("%d", &a[i]);
            l = lcm(l, a[i]);
        }
        printf("%d\n", l);
    }
    return 0;
}

Measured memory_bytes: 1024
#define _GLIBCXX_DEBUG
// header {{{
#include <bits/stdc++.h>
using namespace std;
#define CPP_STR(x) CPP_STR_I(x)
#define CPP_CAT(x,y) CPP_CAT_I(x,y)
#define CPP_STR_I(args...) #args
#define CPP_CAT_I(x,y) x ## y
#define ASSERT(expr...) assert((expr))
using i8  = int8_t;
using u8  = uint8_t;
using i16 = int16_t;
using u16 = uint16_t;
using i32 = int32_t;
using u32 = uint32_t;
using i64 = int64_t;
using u64 = uint64_t;
using f32 = float;
using f64 = double;
using f80 = __float80;
// }}}
constexpr i64 INF = 1'010'000'000'000'000'017LL;
constexpr i64 MOD = 1'000'000'007LL;
constexpr f64 EPS = 1e-12;
constexpr f64 PI = 3.14159265358979323846;
// util {{{
#define FOR(i, start, end) for(i64 i = (start), CPP_CAT(i,xxxx_end)=(end); i < CPP_CAT(i,xxxx_end); ++i)
#define REP(i, n) FOR(i, 0, n)
#define ALL(f,c,...) (([&](decltype((c)) cccc) { return (f)(std::begin(cccc), std::end(cccc), ## __VA_ARGS__); })(c))

template<typename C>
i64 SIZE(const C& c) { return static_cast<i64>(c.size()); }
template<typename T, size_t N>
i64 SIZE(const T (&)[N]) { return static_cast<i64>(N); }
template<typename T, typename U, typename Comp=less<>>
bool chmax(T& xmax, const U& x, Comp comp={}) {
    if(comp(xmax, x)) {
        xmax = x;
        return true;
    }
    return false;
}

template<typename T, typename U, typename Comp=less<>>
bool chmin(T& xmin, const U& x, Comp comp={}) {
    if(comp(x, xmin)) {
        xmin = x;
        return true;
    }
    return false;
}
// }}}

// init {{{
struct ProconInit {
    static constexpr int IOS_PREC = 15;
    static constexpr bool AUTOFLUSH = false;

    ProconInit() {
        cin.tie(nullptr);
        ios::sync_with_stdio(false);
        cout << fixed << setprecision(IOS_PREC);
        if(AUTOFLUSH)
            cout << unitbuf;
    }
} PROCON_INIT;
// }}}

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

signed main() {
    i64 n;
    cin>>n;
    
    cout<< (n-1)*(n)/2 << endl;
    // cout << ans << endl;
    return 0;
}

Measured memory_bytes: 384
while 1:
    try:
        v = [0]*101
        a, b = map(int, input().split())
        v[a] += 1
        v[b] += 1

        while 1:
            a, b = map(int, input().split())
            if a == 0:
                break
            v[a] += 1
            v[b] += 1

        flag = 0
        for num in v[3:]:
            if num % 2 == 1:
                flag = 1

        if v[1] % 2 and v[2] % 2 and (not flag):
            print('OK')
        else:
            print('NG')

    except:
        break



Measured memory_bytes: 5604