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

int h,w;
char B[510][510];
const int dx[4]={1,0,-1,0}, dy[4]={0,1,0,-1};
bool valid(int x, int y){ return 1<=x && x<=h && 1<=y && y<=w; }
int f(int x, int y){ return 410 * x + y; }
int U[410*410];
int find(int x){ return U[x]==x ? x : U[x]=find(U[x]); }
void unite(int x, int y){
	x=find(x), y=find(y);
	if(x==y) return;
	U[x]=y;
}
int main(){
	ios::sync_with_stdio(0), cin.tie(0);
	cin>>h>>w;
	for(int i=1; i<=h; i++) cin>>(B[i]+1);
	for(int i=1; i<=h; i++) for(int j=1; j<=w; j++){
		int u=f(i,j); U[u]=u;
	}
	for(int i=1; i<=h; i++) for(int j=1; j<=w; j++) for(int k=0; k<4; k++){
		int a=i+dx[k], b=j+dy[k];
		if(!valid(a,b)) continue;
		int u=f(i,j), v=f(a,b);
		if(B[i][j]!=B[a][b]) unite(u,v);
	}
	int cnt[410*410][2]={};
	for(int i=1; i<=h; i++) for(int j=1; j<=w; j++){
		int u=find(f(i,j)), k = (B[i][j]=='.') ? 0 : 1;
		cnt[u][k]++;
	}
	long long  ans=0;
	for(int i=1; i<=h; i++) for(int j=1; j<=w; j++){
		int u=f(i,j);
		if(u!=find(u)) continue;
//		cout<<i<<", "<<j<<": "<<cnt[u][0]<<' '<<cnt[u][1]<<'\n';
		ans += 1LL * cnt[u][0]*cnt[u][1];
	}
	cout<<ans<<'\n';
	return 0;
}

Measured memory_bytes: 2432
#include<bits/stdc++.h>
using namespace std;
int main(){
	string s;
	int c=0,f=0;
	cin>>s;
	for(int i=0;i<s.size();++i)
	{
		if(s[i]=='C')
		{
			c=1;
		}
		if(c==1&&s[i]=='F')
		{
			f=1;
		}
	}
	if(f==1) cout<<"Yes";
	else cout<<"No";
	return 0;
}

Measured memory_bytes: 256
fn read<T: std::str::FromStr>() -> T {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().parse().ok().unwrap()
}

fn read_vec<T: std::str::FromStr>() -> Vec<T> {
    read::<String>()
        .split_whitespace()
        .map(|e| e.parse().ok().unwrap())
        .collect()
}

fn read_vec2<T: std::str::FromStr>(n: u32) -> Vec<Vec<T>> {
    (0..n).map(|_| read_vec()).collect()
}

fn main() {
    let n: u32 = read();
    let data: Vec<Vec<i32>> = read_vec2(n - 1);
    for i in 0..n {
        let mut time = 0;
        for j in i..(n - 1) {
            if time < data[j as usize][1] {
                time = data[j as usize][1];
            } else if time % data[j as usize][2] == 0 {
            } else {
                time = time + data[j as usize][2] - (time % data[j as usize][2]);
            }
            time += data[j as usize][0];
        }
        println!("{}", time);
    }
}


Measured memory_bytes: 4352
#include <iostream>
using namespace std;
bool palindromic(int x);
int main()
{
    int A,B;
    cin >> A >> B;
    int cnt = 0;
    for(int i=A; i<=B; i++)
    {
        if(palindromic(i)==true){
        	cnt++;
        }
    }

    cout << cnt << endl;
	return 0;
}

bool palindromic(int x){ 
  int d[5];
  d[0] = x/10000; x -= d[0] * 10000;
  d[1] = x/1000; x -= d[1] * 1000;
  d[2] = x/100; x-= d[2] * 100;
  d[3] = x/10; x-= d[3] * 10;
  d[4] = x;

  if(d[0]==d[4] && d[1]==d[3]) return true;
  else return false;
}

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

int main()
{
    char s;
  	cin >> s;
  	if(s == 'a' || s == 'i' || s == 'u' || s == 'e' || s == 'o')
      cout << "vowel" << endl;
  	else
      cout << "consonant" << endl;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int te = sc.nextInt();
		int c[] = new int[n];
		int t[] = new int[n];

		for(int i=0;i<n;i++){
			c[i]=sc.nextInt();
			t[i]=sc.nextInt();
		}


		int ans = 99999;
		Boolean tle = true;
		for (int i = 0; i < n; i++) {
			if (t[i] <= te) {
				tle = false;
				if (c[i] < ans) {
					ans = c[i];
				}
			}
		}
		if (tle) {
			System.out.println("TLE");
		} else {
			System.out.println(ans);
		}

	}
}

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

#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORTASC(c) sort((c).begin(),(c).end())
#define SORTDESC(c,t) sort((c).begin(),(c).end(), std::greater<t>());
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

const double PI  = acos(-1.0);

using ll = long long;
using namespace std;

int main() {
    ll x, a;

    cin >> x >> a;

    cout << setprecision(20) << ((x<a) ? 0 : 10) << endl;

    return 0;
}

Measured memory_bytes: 256
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<climits>
#include<iostream>
#include<sstream>
#include<utility>
#include<map>
#include<vector>
#include<queue>
#include<algorithm>
#include<set>
#include<stack>
using namespace std;
typedef long long ll;
typedef pair<int,int>P;

int N,M,G[105][105],d[105][105],g[1005][3];

void wf()
{
	for(int k=0;k<N;k++)
		for(int i=0;i<N;i++)
			for(int j=0;j<N;j++)
				d[i][j]=min(d[i][j],d[i][k]+d[k][j]);
}

int main()
{
	scanf("%d%d",&N,&M);
	for(int i=0;i<N;i++)
		for(int j=0;j<N;j++)
			d[i][j]=i==j?0:100000000;
	for(int i=0;i<M;i++)
	{
		int a,b,c;
		scanf("%d%d%d",&a,&b,&c);
		a--;b--;
		d[a][b]=d[b][a]=c;
		d[a][b]=d[b][a]=c;
		g[i][0]=a;g[i][1]=b;g[i][2]=c;
	}
	int r=0;
	wf();
	for(int i=0;i<M;i++)
	{
		bool a=0;
		for(int s=0;s<N;s++)
			for(int t=0;t<N;t++)
			{
				if(s==t)continue;
				if(d[s][g[i][0]]+g[i][2]+d[g[i][1]][t]==d[s][t])
					a=1;
			}
		if(!a)r++;
	}
	printf("%d\n",r);
}


Measured memory_bytes: 384
#include "bits/stdc++.h"
using namespace std;
typedef long long int lint;
typedef pair<lint, lint> plint;
typedef pair<double long, double long> pld;
#define Alint(x) (x).begin(), (x).end()
#define SZ(x) ((lint)(x).size())
#define POW2(n) (1ll << (n))
#define FOR(i, begin, end) for(lint i=(begin),i##_end_=(end);i<i##_end_;i++)
#define IFOR(i, begin, end) for(lint i=(end)-1,i##_begin_=(begin);i>=i##_begin_;i--)
#define REP(i, n) FOR(i,0,n)
#define IREP(i, n) IFOR(i,0,n)
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 (b < a) { a = b; return 1; } return 0; }
template<typename T1, typename T2> pair<T1, T2> operator+(const pair<T1, T2>& l, const pair<T1, T2>& r) { return make_pair(l.first + r.first, l.second + r.second); }
template<typename T1, typename T2> pair<T1, T2> operator-(const pair<T1, T2>& l, const pair<T1, T2>& r) { return make_pair(l.first - r.first, l.second - r.second); }
const lint MOD = 1e9 + 7, MAX = 1e18, INF = -1e9;
typedef long double ld;

long double A;
double B;
int main() {
	cin.tie(0); ios_base::sync_with_stdio(false);
	string s;
	cin >> A >> s;
	cout << (lint)(A * (s[0] - '0') + A * (s[2] - '0') / 10 + A * (s[3] - '0') / 100);
}


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


#include "boost/multiprecision/cpp_int.hpp"
#include "boost/multiprecision/cpp_dec_float.hpp"
namespace mp = boost::multiprecision;
typedef mp::cpp_int LL;
typedef mp::number<mp::cpp_dec_float<1024>> DD;// 仮数部が1024ビットの浮動小数点数型(TLEしたら小さくする)

 
typedef long double dd;
#define i_7 (ll)(1E9+7)
//#define i_7 998244353
#define i_5 i_7-2
ll mod(ll a){
    ll c=a%i_7;
    if(c>=0)return c;
    return c+i_7;
}
typedef pair<ll,ll> l_l;
typedef pair<dd,dd> d_d;
ll inf=(ll)1E16;
#define rep(i,l,r) for(ll i=l;i<=r;i++)
#define rrep(i,r,l) for(ll i=r;i>=l;i--)
#define pb push_back
ll max(ll a,ll b){if(a<b)return b;else return a;}
ll min(ll a,ll b){if(a>b)return b;else return a;}
void Max(ll &pos,ll val){pos=max(pos,val);}//Max(dp[n],dp[n-1]);
void Min(ll &pos,ll val){pos=min(pos,val);}
void Add(ll &pos,ll val){pos=mod(pos+val);}
dd EPS=1E-12;
#define fastio ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define fi first
#define se second
#define endl "\n"  //インタラクティブで消す！！！！！！！！！！！！！！！！！！！！！
#define SORT(v) sort(v.begin(),v.end())
#define ERASE(v) v.erase(unique(v.begin(),v.end()),v.end())
#define POSL(v,x) (lower_bound(v.begin(),v.end(),x)-v.begin())
#define POSU(v,x) (upper_bound(v.begin(),v.end(),x)-v.begin())
template<class T,class S>
inline bool chmax(T &a, S b) {
    if(a < b) {
        a = b;
        return true;
    }
    return false;
}
template<class T,class S>
inline bool chmin(T &a, S b) {
    if(a > b) {
        a = b;
        return true;
    }
    return false;
}

void mod_print(ll k){
    ll P=50000;
    rep(y,1,P){
        ll x=mod(y*k);
        
        if(abs(x)<=P||x+P>=i_7){
            if(x+P>=i_7){
                x-=i_7;
            }
            cout<<x<<"/"<<y<<endl;
            //cout<<setprecision(5)<<(dd)x/(dd)y;
            return;
        }
    }
    cout<<"nun"<<endl;
}
#define all(c) c.begin(),c.end()
typedef vector<ll> vl;
//////////////////////////


int main(){fastio
    
    ll n,x,t;cin>>n>>x>>t;
    ll a=(n+x-1)/x;
    cout<<a*t<<endl;
    
    
    
    return 0;
}


Measured memory_bytes: 3644
#include <iostream>
#include <vector>
#include <string>
#include <numeric>
#include <iostream>
#include <cmath>
#include <algorithm>
#include <iomanip>
#include <queue>

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

int main() {
  int N;
  cin >> N;
  priority_queue<tuple<string, int, int>> q;
  
  rep(i, N){
    string tmp;
    int tmpP;
    cin >> tmp >> tmpP;
    q.push(make_tuple(tmp, -tmpP, i+1));
  }
  
  vector<int> ans;
  rep(i, N) {
    auto p = q.top();
    q.pop(); // 対象のpairを取り出す
    
    ans.push_back(get<2>(p));
  }
  
  rep(i,N) {
    cout << ans[N-i-1] <<endl;
  }
  
  return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
int cmpstr(const void *a,const void *b){
    const char *x = a, *y = b;
    //return strcmp(a,b) --> funciona também
    return strcmp(x,y);
}
int main(){
    int n,l,i;
    scanf("%d %d\n",&n,&l);
    char s[n][l+1];
    for(i=0;i<n;i++){
        scanf("%s\n",s[i]);
    }
    //ordenar as strings
    qsort(s,n,sizeof(s[0]),cmpstr);
    for(i=0;i<n;i++){
        printf("%s",s[i]);
    }
    printf("\n");
    return 0;
}


Measured memory_bytes: 252
main = (input) => {
  const [n, ...resultArr]  = input.trim().split('\n')
  const counts = {
    AC: 0,
    WA: 0,
    TLE: 0,
    RE: 0,
  };

  for(i = 0; i < resultArr.length; i++)
  {
    counts[resultArr[i]] += 1;
  }
  
  const countArr = Object.keys(counts)
    .map(key => `${key} x ${counts[key]}`)
  
  console.log(countArr.join('\n'))
}

main(require("fs").readFileSync("/dev/stdin", "utf8"));

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

public class Main {

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

		String str = sc.next();

		int rain = 0;
		int count = 0;
		for (int i = 0; i < 3; i++) {
			if (str.charAt(i)=='R') {
				count++;
			}
			else {
				if (count > rain) {
					rain = count;
				}
				count=0;
			}
		}
		if (count > rain) {
			rain = count;
		}
		System.out.println(rain);
	}

	private 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();
		}

	}
}


Measured memory_bytes: 32588
n,k=map(int,input().split())
a = list(map(int,input().split()))

#訪れた町
visited = [0]*n
visited[0]=1
root=[0]

next=a[0]-1
same=0
cnt=0
while cnt<k:
    if visited[next]==1:

        same=next

        root.append(next)

        index = root.index(same)

        break
    else:
        visited[next]=1
        root.append(next)

    next = a[next]-1
    cnt+=1

# print(visited)
# print(root)
# print(index)
if cnt==k:
    print(root[-1]+1)
    exit(0)

roops=len(root) - index -1 

if roops!=0:
    moves = index + ( (k-index)%roops )
else:
    moves= index

now=0

for i in range(moves):
    now=a[now]-1

print(now+1)




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

int main(){
    string s;
    cin >> s;
    if (s[0] == s[1] || s[1] == s[2] || s[2] == s[3] || s[3] == s[4]){
        cout << "Bad" << endl;
    }
    else
        cout << "Good" << endl;

}

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

using namespace std;

const int N=1e5;

pair<int,int> in[N];


int main()
{
    int n,m;
    scanf("%d%d",&n,&m);
    for(int i=0;i<m;i++)
        scanf("%d%d",&in[i].first,&in[i].second);
    sort(in,in+m);
    int l=in[0].first,r=in[0].second,ans=1;
    for(int i=1;i<m;i++){
        if (in[i].first<r)
            l=in[i].first,r=min(r,in[i].second);
        else
            ans++,l=in[i].first,r=in[i].second;
    }
    printf("%d",ans);
}


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

using namespace std;

typedef long long ll;

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    
    int n;
    cin >> n;
    
    int minimum = 201;
    int maximum = -201;
    vector<int> v(n);
    
    
    
    for(int i = 0; i < n; i++){
        cin >> v[i];
        minimum = min(minimum, v[i]);
        maximum = max(maximum, v[i]);
    }
    
    if(minimum == maximum){ //Todos os numeros do vetor sao iguais.
        cout << "0" << endl;
        return 0;
    }
    
    int left = minimum;
    int right = maximum;
    ll answer = 1e8;
    for(int a = minimum; a <= maximum; a++){
        ll cost = 0;
        for(int i = 0; i < n; i++){
            cost += ((v[i] - a)*(v[i] - a));
        }
        //cout << "Cost: " << cost << "\n";
        //cout << "Derived: " << derived << "\n\n";
        answer = min(answer, cost);
    }
    
    cout << answer << "\n";
    
    
    
    return 0;
}

Measured memory_bytes: 3636
#include <iostream>
using namespace std;
 
int main(){
 
 int x, y;
 bool ex=0;
  
  cin >>x >>y;
  
  for(int c=0;c<=50;c++){ 
    
    for(int t=0;t<=50;t++){
     
      if(c+t==x && 2*c+4*t==y){
        ex=1;
        break;
      }
      
    }
    
    if(ex==1){
      cout <<"Yes";
      break;
    }
  
  }
  
  if(ex==0)cout <<"No";
  
  return 0;
}

Measured memory_bytes: 3636
#include<bits/stdc++.h>
using namespace std;
int main(){
    string s;
    cin>>s;
    int l=s.size();
    int dif=999;
    for(int i=0;i<l-2;i++){
        int x=s[i]-48;
        int y=s[i+1]-48;
        int z=s[i+2]-48;
        int w=abs(753-(x*100+y*10+z));
        if(abs(w<dif))dif=abs(w);
    }
    cout<<dif<<endl;
    return 0;
}

Measured memory_bytes: 256
# coding: utf-8
N = int(input())
A = list(map(int, input().split()))
A.sort(reverse=True)
Aset = list(set(A))
Aset.sort(reverse=True)
a, b = 0, 0
L = []
cnt = 1
for i in range(1, N):
    if A[i] == A[i-1]:
        cnt += 1
    else:
        L.append(cnt)
        cnt = 1
if A[-1] == A[-2]:
    L.append(cnt)
idx = 0
for i in range(len(L)):
    if L[i] >= 4:
        a, b = Aset[i], Aset[i]
        break
    elif L[i] >= 2:
        a = Aset[i]
        idx = i + 1
        break
if b <= 0:
    for i in range(idx, len(L)):
        if L[i] >= 2:
            b = Aset[i]
            break
print(a * b)

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

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

    int A, B, C;

    cin >> A >> B >> C;

    int res = C - (A-B);
    if (res < 0){
        res = 0;
    }

    cout << res << endl;

    return 0;
}

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

int main(){
    int a,b;
    cin >> a >> b;
    if(a > 9 || b > 9){
        cout << -1 << endl;
        return 0;
    }
    cout << a * b << endl;
}

Measured memory_bytes: 3604
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <queue>
#include <cstring>
#include <vector>
#include <map>
#include <algorithm>
#include <cctype>
#include <cmath>
#include <bitset>
#include <set>
using namespace std;

#define REP(i,n) for(int i=0;i<(int)(n);i++)
#define RREP(i,n) for(int i=n-1;i>=0;i--)
#define FOR(i,k,n) for(int i=(k);i<(int)(n);i++)
#define all(i,n) (i),(i+n)

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

typedef pair<int, int> P;
typedef pair<string, int> SP;
typedef long long ll;

const int INF = 1e9;
const ll LLINF = 1e18;
const int MAX_V = 1e6+1;
const ll mod = 1000000007;

// --------------------------------------
int a, b, c;
int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);

  cin >> a >> b >> c;

  if(a != b && a != c && b != c) cout << "No" << endl;
  else if(a == b && a == c) cout << "No" << endl;
  else cout << "Yes" << endl;
}


Measured memory_bytes: 256
from collections import defaultdict, deque, Counter
from heapq import heappush, heappop, heapify
import math
import bisect
import random
from itertools import permutations, accumulate, combinations
import sys
import string
from bisect import bisect_left, bisect_right
from math import factorial, ceil, floor
from functools import reduce
import numpy as np

INF = float('inf')
def LI(): return list(map(int, sys.stdin.readline().split()))
def I(): return int(sys.stdin.readline())
def LS(): return sys.stdin.readline().split()
def S(): return sys.stdin.readline().strip()
def IR(n): return [I() for i in range(n)]
def LIR(n): return [LI() for i in range(n)]
def SR(n): return [S() for i in range(n)]
def LSR(n): return [LS() for i in range(n)]
def SRL(n): return [list(S()) for i in range(n)]
def MSRL(n): return [[int(j) for j in list(S())] for i in range(n)]
mod = 1000000007

#入力こっちの方が10倍早い
#import sys
input = sys.stdin.readline

# mainをかく
A,B=LI()
if A<B:
    print(0)
    exit()
if A-B*2>=0:
    print(A-B*2)
elif A-B*2<0:
    print(0)


Measured memory_bytes: 14304
#include<bits/stdc++.h>
#define ll long long
#define w cout 
#define e endl

using namespace std;

int main() {
	int n;
	cin >> n;
	int arr[n];
	int maxsofar = -1 , ans = 0;
	for(int i = 0 ; i < n ;i ++ ) {
		cin >> arr[i];
		if(arr[i] >= maxsofar) {
			ans++;
		}
		maxsofar = max(maxsofar , arr[i]);
	}
	w << ans;
}


Measured memory_bytes: 256
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <queue>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>

using namespace std;

#define dump(x)  cerr << #x << " = " << (x) << endl;
#define PB push_back
#define MP make_pair
#define ll long long

inline int toInt(string s){int v;istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x){ostringstream sout;sout<<x;return sout.str();}

bool are_same_sign(ll a, ll b) {
    return (a / abs(a)) * (b / abs(b)) > 0;
}

int main(){
    std::ios::sync_with_stdio(false);
    ll t[2] = {};
    ll a[2] = {};
    ll b[2] = {};
    cin >> t[0] >> t[1];
    cin >> a[0] >> a[1];
    cin >> b[0] >> b[1];
    ll first_part_diff = t[0] * (b[0] - a[0]);
    ll second_part_diff = t[1] * (b[1] - a[1]);
    // dump(first_part_diff)
    // dump(second_part_diff)
    if(!are_same_sign(first_part_diff, second_part_diff)) {
        ll cycle_diff = first_part_diff + second_part_diff;
        dump(cycle_diff)
        if(cycle_diff == 0) {
            cout << "infinity" << endl;
        } else {
            if(are_same_sign(cycle_diff, first_part_diff)) {
                cout << 0 << endl;
            } else {
                if(first_part_diff % cycle_diff == 0)
                {
                    cout << first_part_diff / cycle_diff * -1 * 2 << endl;
                } else {
                    cout << first_part_diff / cycle_diff * -1 * 2  + 1 << endl;
                }
            }
        }
        
    } else {
        cout << 0 << endl;
    }
}

Measured memory_bytes: 256
#include <stdio.h>  
#include <algorithm>  
#include <assert.h>
#include <bitset>
#include <cmath>  
#include <complex>  
#include <deque>  
#include <functional>  
#include <iostream>  
#include <limits.h>  
#include <map>  
#include <math.h>  
#include <queue>  
#include <set>  
#include <stdlib.h>  
#include <string.h>  
#include <string>  
#include <time.h>  
#include <unordered_map>  
#include <unordered_set>  
#include <vector>  
#define ll long long
#define rep2(i,a,b) for(ll i=a;i<=b;++i)
#define rep(i,n) for(ll i=0;i<n;i++)
#define rep3(i,a,b) for(ll i=a;i>=b;i--)
#define REP(e,v) for(auto e:v)
#define pii pair<int,int>
#define pll pair<ll,ll>
#define tii tuple<int,int,int>
#define pq priority_queue<int>
#define pqg priority_queue<int,vector<int>,greater<int>>
#define pb push_back
#define edge(v,a,b) v[a].pb(b);v[b].pb(a);
#define MAX_V 400010
#define vec vector<int>
#define vecll vector<ll>
#define vecpii vector<pii>
#define endl "\n"
#define ALL(c) (c).begin(),(c).end()
using namespace std;
int in() {int x;scanf("%d",&x);return x;}
ll lin() {ll x;scanf("%lld",&x);return x;}

#define INF 1e9+7
#define LLINF 1e18+7
ll MOD=1e9+7;
#define N 1055050

struct edge{
    int from,to;
    ll cost;
    bool operator<(const edge& e)const{
        return cost<e.cost;
    };
};
struct UnionFind{
    vector<int> par,sizes;
    UnionFind(int n):par(n+1),sizes(n+1,1){
        rep2(i,1,n)par[i]=i;
    }
    int find(int x){
        return (x==par[x]?x:par[x]=find(par[x]));
    }
    bool unite(int x,int y){
        x=find(x);y=find(y);
        if(x==y)return false;
        if(sizes[x]<sizes[y]){
            swap(x,y);
        }
        par[y]=x;
        sizes[x]+=sizes[y];
        return true;
    }
    bool same(int x,int y) {return (find(x)==find(y));}
    int size(int x) {return sizes[find(x)];}
};
vector<vector<pll>> G(N);
ll kruskal(vector<edge> &edges,int v){
    sort(ALL(edges),[](edge a,edge b){
        return a.cost<b.cost;
    });
    UnionFind u(v+1);
    ll ret=0;
    for(auto e:edges){
        if(u.unite(e.from,e.to)){
            ret+=e.cost;
            G[e.from].pb({e.to,e.cost});
            G[e.to].pb({e.from,e.cost});
        }
    }
    return ret;
}
ll n,m;
ll d[5000][5000];
void dfs(int from,int now,int par,ll MAX){
    d[from][now]=MAX;
    for(auto e:G[now]){
        if(e.first!=par){
            dfs(from,e.first,now,max(MAX,e.second));
        }
    }
    return ;
}
main(){
    n=in();
    m=lin();
    vector<edge> ed;
    rep(i,m){
        int a=in(),b=in(),c=lin();
        ed.pb(edge{a,b,c});
    }
    ll MST=kruskal(ed,n);
    rep2(i,1,n){
        dfs(i,i,0,0);
    }
    int q=in();
    rep(iii,q){
        int s=in(),t=in();
        cout<<MST-d[s][t]<<endl;
    }
}

Measured memory_bytes: 191208
#include <iostream>
#include <vector>
#include <queue>
#include <utility>
#include <tuple>
#include <climits>
#include <cstdlib>
using namespace std;

struct edge{
    int to, cost;
    edge(int to_, int cost_) : to(to_), cost(cost_){}
};
using Graph = vector<vector<edge>>;
using Real = long double;
struct state{
    Real cost;
    int city, rest_tickets;
    state(Real c, int city_, int r_t) : cost(c), city(city_), rest_tickets(r_t){}
    bool operator<(const state& other) const {
        return cost < other.cost;
    }
};

int n, m, p, a, b;
vector<int> t; // num. of horses

Real dijkstra(const Graph& G){
    priority_queue<state> pq;
    int rest_ticket = 0;
    for(int i = 0, j = 1; i < n; ++i, j <<= 1)
        rest_ticket |= j;
    vector<vector<Real>> d(m, vector<Real>(rest_ticket+1, INT_MAX)); // d[city num.][rest_tickets]
    d[a][rest_ticket] = 0.0;
    pq.push({0.0, a, rest_ticket});

    while(!pq.empty()){
        //cout << pq.size() << endl;
        Real cost = pq.top().cost; // 現在の状態に至るまでに要したコスト
        int u = pq.top().city; // 現在の街
        int r_t = pq.top().rest_tickets; // 残りのチケット
        pq.pop();

        // uがゴールならば，それ以上の遷移はないためcontinue
        if(u == b) continue;
        if(r_t == 0) continue;

        for(const auto& e : G[u]){
            // 残っているチケットを使った場合の次の状態をpqに追加する
            for(int i = 0, j = 1; i < n; ++i, j <<= 1){
                if(!(r_t & j)) continue; // 現在見ているチケットは使ったためcontinue
                int next_r_t = r_t ^ j;
                if(d[e.to][next_r_t] > cost + (Real)e.cost / t[i]){
                    d[e.to][next_r_t] = cost + (Real)e.cost / t[i]; // 次の状態のコストを更新
                    pq.push({d[e.to][next_r_t], e.to, next_r_t});
                }
            }
        }
    }

    Real ret = INT_MAX;

    for(const auto& e : d[b])
        ret = min(ret, e);

    return ret;
}

int main(){
    while(true){
        cin >> n >> m >> p >> a >> b;
        if(m == 0) break;
        a--; b--;
        t = vector<int>(n);

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

        Graph G(m); 
        for(int i = 0; i < p; ++i){
            int x, y, z;
            cin >> x >> y >> z;
            x--; y--;
            G[x].push_back({y, z});
            G[y].push_back({x, z});
        }

        Real d = dijkstra(G);

        if(d == (Real)INT_MAX) cout << "Impossible\n";
        else cout << d << endl;
    }

    return EXIT_SUCCESS;
}



Measured memory_bytes: 3384
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(n);++i)
#define all(a) (a).begin(),(a).end()
#define dunk(a) cout << (a) << endl
using namespace std;
typedef long long ll;

int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	int n, y;
	cin >> n >> y;

	for (int i = 0; i <= 2000; ++i) {
		for (int j = 0; j <= 2000; ++j) {
			if (i * 10000 + j * 5000 + (n - i - j) * 1000 == y && n - i - j >= 0) {
				cout << i << ' ' << j << ' ' << n - i - j << endl;
				return 0;
			}
		}
	}
	cout << -1 << ' ' << -1 << ' ' << -1 << endl;
	return 0;
}

Measured memory_bytes: 256
#include <algorithm>
#include <iostream>
#include <cstring>
#include <cstdio>
#include <queue>
using namespace std;

typedef long long s64;

inline int getint()
{
	static char c;
	while ((c = getchar()) < '0' || c > '9');

	int res = c - '0';
	while ((c = getchar()) >= '0' && c <= '9')
		res = res * 10 + c - '0';
	return res;
}

const int MaxN = 100000;
const s64 INF = 0x3f3f3f3f3f3f3f3fll;

int n, x, y, z;
s64 res = 0;

struct object
{
	int u, v;
	object() {}
	object(const int &_u, const int &_v)
		: u(_u), v(_v) {}

	friend inline bool operator<(const object &lhs, const object &rhs)
	{
		return lhs.u - lhs.v > rhs.u - rhs.v;
	}
};
object a[MaxN + 1];

priority_queue<int> q;

s64 cur;

s64 pre[MaxN + 1];
s64 suf[MaxN + 1];

inline void insert(int x, int lim)
{
	q.push(-x), cur += x;
	if (q.size() > lim)
		cur += q.top(), q.pop();
}

int main()
{
	cin >> x >> y >> z;
	n = x + y + z;
	for (int i = 1; i <= n; ++i)
	{
		int u = getint(), v = getint();
		int w = getint();
		u -= w, v -= w, res += w;

		a[i] = {u, v};
	}

	sort(a + 1, a + n + 1);

	cur = 0;
	for (int i = 1; i <= n; ++i)
	{
		insert(a[i].u, x);
		pre[i] = q.size() == x ? cur : -INF;
	}

	cur = 0;
	while (!q.empty())
		q.pop();
	for (int i = n; i >= 1; --i)
	{
		insert(a[i].v, y);
		suf[i] = q.size() == y ? cur : -INF;
	}

	s64 val = -INF;
	for (int i = 1; i < n; ++i)
		val = max(val, pre[i] + suf[i + 1]);

	cout << val + res << endl;

	return 0;
}

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
//#define INF 1145141919810893364
#define REP(i,n) for(int i=0;i<(n);++i)

std::vector<std::pair<long long,long long>> convex_hull(std::vector<std::pair<long long,long long>> P){
    if(P.size()<=1){
        return P;
    }
    std::vector<std::pair<long long,long long>> H,L,R;
    sort(P.begin(),P.end());
    
    //L
    for(int i=0;i<P.size();i++){
        int j=L.size();
        while(j>=2 && (L[j-1].first-L[j-2].first)*(P[i].second-L[j-2].second)<=(L[j-1].second-L[j-2].second)*(P[i].first-L[j-2].first)){
            L.pop_back();
            j--;
        }
        L.push_back(P[i]);
    }
    
    //H
    for(int i=P.size()-1;i>=0;i--){
        int j=H.size();
        while(j>=2 && (H[j-1].first-H[j-2].first)*(P[i].second-H[j-2].second)<=(H[j-1].second-H[j-2].second)*(P[i].first-H[j-2].first)){
            H.pop_back();
            j--;
        }
        H.push_back(P[i]);
    }
    
    
    R=L;
    for(int i=1;i<H.size()-1;i++){
        R.push_back(H[i]);
    }
    
    //REP(i,L.size()){cout << L[i].first <<" "<< L[i].second << endl;}cout << endl;
    //REP(i,H.size()){cout << H[i].first <<" "<< H[i].second << endl;}cout << endl;
    
    //REP(i,R.size()){cout << R[i].first <<" "<< R[i].second << endl;}
    
    return R;
}


signed main(void){
    int N;
    const double PI = 3.14159265358979;
    vector<pair<long long,long long>> P;
    map<pair<int,int>,int> M;
    double Ans[114]={};
    int x,y;
    cin >> N;
    REP(i,N){
        cin >> x >> y;
        P.push_back({x,y});
        M[{x,y}]=i;
    }
    P=convex_hull(P);
    //REP(i,P.size()){cout << P[i].first <<" "<< P[i].second << endl;}
    
    P.push_back(P[0]);
    double angle[114]={};
    REP(i,P.size()-1){
        double t=atan2(-(P[i+1].first-P[i].first),(P[i+1].second-P[i].second));
        angle[i]=t;
    }
    angle[P.size()-1]=angle[0];
    REP(i,P.size()-1){
        double k=angle[i+1]-angle[i];
        if(k<-PI)k+=2*PI;
        Ans[M[P[i+1]]]+=k;
    }
    
    //REP(i,P.size()-1){printf("%.8f\n",angle[i]);}
    
    double sum=0;
    REP(i,N){
        sum+=Ans[i];
    }
    
    REP(i,N){
        Ans[i]/=sum;
    }
    //printf("%.8f\n\n\n\n",sum/PI);
    REP(i,N){
        printf("%.8f\n",Ans[i]);
    }
    
    return 0;
}


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


int main(){
	int a;
	cin >> a;
	cout << a + a*a + a*a*a << endl;
	return 0;
}


Measured memory_bytes: 3592
//
// Created on 2020/09/08.
//


#include <iostream> // cout, endl, cin
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower
#include <math.h>
#include <ios>
#include <iomanip>
#include <numeric>

#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
typedef long long ll;
using namespace std;
const long long LINF =1e18;
const int INF = 1e9;
const long long mod = 1000000007;

struct mint {
    ll x; // typedef long long ll;
    mint(ll x=0):x((x%mod+mod)%mod){}
    mint operator-() const { return mint(-x);}
    mint& operator+=(const mint a) {
        if ((x += a.x) >= mod) x -= mod;
        return *this;
    }
    mint& operator-=(const mint a) {
        if ((x += mod-a.x) >= mod) x -= mod;
        return *this;
    }
    mint& operator*=(const mint a) {
        (x *= a.x) %= mod;
        return *this;
    }
    mint operator+(const mint a) const {
        mint res(*this);
        return res+=a;
    }
    mint operator-(const mint a) const {
        mint res(*this);
        return res-=a;
    }
    mint operator*(const mint a) const {
        mint res(*this);
        return res*=a;
    }
    mint pow(ll t) const {
        if (!t) return 1;
        mint a = pow(t>>1);
        a *= a;
        if (t&1) a *= *this;
        return a;
    }

    // for prime mod
    mint inv() const {
        return pow(mod-2);
    }
    mint& operator/=(const mint a) {
        return (*this) *= a.inv();
    }
    mint operator/(const mint a) const {
        mint res(*this);
        return res/=a;
    }
};

int main() {

    int n;
    cin>>n;
    vector<mint>num(n);
    vector<ll>l(n);
    mint s;
    for (int i = 0; i < n; ++i) {
        ll t;
        cin>>t;
        s += t;
        l[i]=t;
        num[i] = s;

    }
    mint sum;
    for (int i = 0; i < n; ++i) {
        sum += (num[n-1] - num[i]) * l[i];
    }

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


Measured memory_bytes: 6372
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define all(x) (x).begin(),(x).end()
const int mod=998244353,MAX=205,INF=1<<29;
vector<int> G[MAX];
int color[MAX];
int dis[MAX][MAX];
bool ok=true;
int N;

void BFS(int u){
    queue<int> Q;
    Q.push(u);
    
    while(!Q.empty()){
        int a=Q.front();Q.pop();
        for(int to:G[a]){
            if(color[to]==0){
                color[to]=3-color[a];
                Q.push(to);
            }else{
                if(color[to]==color[a]) ok=false;
            }
        }
    }
}

void floyd(){
    for(int k=0;k<N;k++){
        for(int i=0;i<N;i++){
            for(int j=0;j<N;j++){
                dis[i][j]=min(dis[i][k]+dis[k][j],dis[i][j]);
            }
        }
    }
}

int main(){

    cin>>N;
    
    for(int i=0;i<N;i++){
        for(int j=0;j<N;j++){
            dis[i][j]=INF;
            if(i==j) dis[i][j]=0;
        }
    }
    
    for(int i=0;i<N;i++){
        string S;cin>>S;
        for(int j=0;j<N;j++){
            if(S[j]=='1'){
                G[i].push_back(j);
                G[j].push_back(i);
                dis[i][j]=1;
                dis[j][i]=1;
            }
        }
    }
    
    color[0]=1;
    BFS(0);
    
    if(ok){
        floyd();
        
        int ans=0;
        for(int i=0;i<N;i++){
            for(int j=0;j<N;j++){
                ans=max(ans,dis[i][j]);
            }
        }
        
        cout<<ans+1<<endl;
    }else cout<<-1<<endl;
}




Measured memory_bytes: 768
#include <iostream>
#include <algorithm>
#include <vector>
using namespace std;
int main(void){
    int n, ans = 1e9;
    cin >> n;
    vector<int> x(n, 0);
    for(int i=0;i<n;i++) cin >> x[i];
    for(int c=1;c<=100;c++){
        int t = 0;
        for(int i=0;i<n;i++){
            t += (x[i]-c) * (x[i]-c);
        }
        if(ans > t) ans = t;
    }
    cout << ans << endl;
}


Measured memory_bytes: 256
import java.util.ArrayList;
import java.util.Scanner;


public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		boolean flag = false;
		ArrayList<Integer> goals = new ArrayList<Integer>();
		goals.add(111);
		goals.add(222);
		goals.add(333);
		goals.add(444);
		goals.add(555);
		goals.add(666);
		goals.add(777);
		goals.add(888);
		goals.add(999);
		
		if(goals.contains(n)){flag=true;}
		
		while(n<=999&&flag==false){
			n++;
			flag = goals.contains(n);
		}
		
		System.out.println(n);
	}
}

Measured memory_bytes: 23124
#include<bits/stdc++.h> 
using namespace std;
typedef long long ll;
template<typename T1,typename T2> bool chmin(T1 &a,T2 b){if(a<=b)return 0; a=b; return 1;}
template<typename T1,typename T2> bool chmax(T1 &a,T2 b){if(a>=b)return 0; a=b; return 1;}
int dx[4]={0,1,-1,0};
int dy[4]={1,0,0,-1};

// スタックオーバーフローの罠を解決する

signed main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout << fixed << setprecision(20);

    ll n;
    cin>>n;
    ll a[n],b[n],c[n];
    for(int i=0;i<n;i++)cin>>a[i];
    for(int i=0;i<n;i++)cin>>b[i];
    for(int i=0;i<n;i++)cin>>c[i];
    sort(a,a+n);
    sort(c,c+n);
    ll ans = 0;
    for(int i=0;i<n;i++){
        // b[i] > a && b[i] < c
        ll l = lower_bound(a,a+n,b[i]) - a;
        ll u = c+n - upper_bound(c,c+n,b[i]);
        ans += l*u;
    }
    cout << ans << endl;
}

Measured memory_bytes: 5992
#include <iostream>
using namespace std;
int main(void){
    // Your code here!
    int S;
    int a, b, c;
    a = 0;
    b = 0;
    c = 0;
    cin >> S;
    
    a = S / 3600;
    S = S - 3600 * a;
    b = S / 60;
    c = S - 60 * b;
    
    cout << a << ":" << b << ":" << c << endl;
}



Measured memory_bytes: 3104
#include<bits/stdc++.h>
using namespace std;
int main()
{

    long long a,b,c,d,i,sum=0;
    map<long long,long long>mp;
    map<long long,long long>:: iterator it;
    cin>>a;
    while(a--)
    {
        cin>>b;
        mp[b]++;


    }
     // for(it=mp.begin();it!=mp.end();it++)
    //cout<<it->first<<" "<<it->second<<endl;
    for(it=mp.begin();it!=mp.end();it++)
    {
        d=it->first;
        if(mp[d]<d)
            sum=sum+mp[d];
        else
            sum=sum+abs(mp[d]-d);
    }

    cout<<sum<<endl;




}


Measured memory_bytes: 6272
#include <iostream>
#include <cmath>
#include <stdio.h>
#include <algorithm>
#include <string>
#include <vector>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
#include <cstring>

using namespace std;

#define f first
#define s second
#define pb push_back
#define mp make_pair
#define ll long long
#define pii pair < int, int >
#define pll pair < long long, long long>
#define ull unsigned long long
#define vi vector <int>
#define sz(a) (int)a.size()
#define forit(it, s) for(__typeof(s.begin()) it = s.begin(); it != s.end(); it++)
#define all(a) a.begin(), a.end()
#define sqr(x) ((x) * (x))
#define fname "searching"

const int inf = (int)1e9;
const ll INF = (ll)1e18;
const double eps = 1e-9;
const double pi = acos(-1.0);
const int mod = (int)1e9 + 7;

int a, b, c;

int main(){
	// freopen("input.txt", "r", stdin);
	// freopen(fname".in", "r", stdin);
	// freopen(fname".out", "w", stdout);
	scanf("%d%d%d", &a, &b, &c);
	int x = a * 100 + b * 10 + c;
	if(x % 4 == 0)
		printf("YES\n");
	else
		printf("NO\n");
	return 0;
}

Measured memory_bytes: 256
from operator import itemgetter

N = int(input())
l = []
for i in range(N):
  a, b = map(int, input().split())
  s = [a-b, a+b]
  l.append(s)

l.sort(key = itemgetter(1))
cnt = 0
s = - 10 ** 10
for i in range(N):
  if l[i][0] >= s:
    s = l[i][1]
  else:
    cnt += 1
print(N-cnt)

Measured memory_bytes: 21408
//
//  second.cpp
//  CoderTest
//
//  Created by yuya on 2019/07/25.
//  Copyright © 2019 yuya. All rights reserved.
//

#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef pair <int,int> P;
#define all(x) (x).begin(), (x).end()
#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 INF 1000000
#define MOD 998244353



int main()
{
    int X;
    cin >> X;
    int a,b;
    a = X / 500;
    b = (X % 500) / 5;
    
    cout << 1000 * a + 5 * b << endl;;
    
    
    return 0;
}



Measured memory_bytes: 256
use std::cmp;
use std::i64::{MAX, MIN};
use std::io::BufRead;
use std::io;

fn main() {
    let stdin = io::stdin();
    let line = stdin.lock().lines().nth(1).unwrap().unwrap();
    let (min, max, sum) = line.split_whitespace()
        .map(|s| s.parse::<i64>().unwrap())
        .fold((MAX, MIN, 0), |(min, max, sum), x| {
            (cmp::min(min, x), cmp::max(max, x), sum + x)
        });
    println!("{} {} {}", min, max, sum);
}



Measured memory_bytes: 5064
#include <bits/stdc++.h>
#define x real()
#define y imag()
using namespace std;
typedef complex <double> point;
double cross(point a,point b){return a.x*b.y-a.y*b.x;}

double get_area(vector <point> &polygon){
  double res=0;
  for(int i=0;i<polygon.size();i++)
    res+=cross(polygon[i],polygon[(i+1)%polygon.size()])/2;
  return res;
}


int main(){
  int n;
  cin>>n;
  vector <point> po;
  for(int i=0,a,b;i<n;i++)cin>>a>>b,po.push_back(point(a,b));
  printf("%.1f\n",get_area(po));
  return 0;
}

Measured memory_bytes: 1228
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;

int main() {
  int N, C, K;
  vector<int> T;
  cin >> N >> C >> K;
  for (int i=0; i<N; i++) {
    int tmp;
    cin >> tmp;
    T.push_back(tmp);
  }
  sort(T.begin(), T.end());

  int ans = 1, c = 1, s = T[0], s_idx = 0;
  for (int i=1; i<N; i++) {
    if (T[i] - T[s_idx] <= K && c < C) {
      c++;
    } else {
      c = 1;
      ans++;
      s = T[i];
      s_idx = i;
    }
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 892
#[allow(unused_imports)]
use std::cmp::*;
use std::io::*;
use std::str::FromStr;

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

fn main() {
    let n = read();
    let h: Vec<u32> = (0..n).map(|_| read()).collect();

    let mut highest = 0;
    let mut ans = 0;
    for i in h {
        if i >= highest {
            ans += 1;
        }
        highest = max(highest, i);
    }

    println!("{}", ans);
}

Measured memory_bytes: 4352
#include<cstdio>
int main() {
    int s,k,a,b,c,u=0;
    scanf("%d%d",&k,&s);
    for(a=0;a<=k;a++){
        for(b=0;b<=k;b++){
            c=s-a-b;
            if(c<=k&&a<=k&&b<=k&&c>=0)
            ++u;
        }
    }
    printf("%d\n",u);
    return 0;
}

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

using namespace std;

#define REP(i,n) for(int i = 0; i < (int)(n); i++)
typedef long long ll;
typedef pair<int, int> pint;

int main() {
  int N; cin>>N;
  ll K, X = 0;	cin>>K;
  vector<ll> A(N);
  REP(i,N) cin>>A[i];
  vector<int> cnt(64, 0);
  REP(s,60) {
    REP(i,N) {
      if((A[i]>>s) & (ll)1) cnt[s]++;
    }
  }
  //  REP(i,60) cout << i << " " << cnt[i]  << endl;                                   

  for(int s = 60; s >= 0; s--) {
    int one = cnt[s];
    int	zero = N-cnt[s];
    if(zero > one) {
      ll work =	1LL << s;
      if(X + work <= K) X += work;
    }
  }
  //  cout << X << endl;                                                               
  ll ans = 0;
  REP(i,N) {
    ans	+= (A[i] ^ X);
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 1024
#include<stdio.h>
int main()
{
	long int N,sum,i,j,m;
	scanf("%ld",&N);
	long int T[N];
	for(i=1; i<=N; i++)
		scanf("%ld",&T[i]);
	scanf("%ld",&m);
	long int p[m], x[m];
		sum=0;
	for(i=1; i<=m; i++)
	{
		scanf("%ld %ld",&p[i],&x[i]);
		for(j=1; j<=N; j++){
		if(j==p[i])
		sum=sum+x[i];
		else
		sum=sum+T[j];
		}
		printf("%ld\n",sum);
		sum=0;
	}
	return 0;
}

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

int main(void){
  int N, R, T;
  cin >> N >> R >> T;
  int ans;
  vector<int> p(N);
  vector<int> student_pos(N, 0);
  vector<int> water_num(R, 0);
  vector<int> bottle_num(R, 0);
  vector<bool> student_water(N, false);
  for(int i=0; i < N; i++){
    cin >> p[i];
  }
  for(int t = 0; t < T; t++){
    for(int r = 0; r < R; r++){
      water_num[r] += bottle_num[r];
      bottle_num[r] = 0;
    }
    for(int i = 0; i < N; i++){
      student_pos[i] = (student_pos[i] + p[i]) % R;
      if(student_water[i] == true){
	bottle_num[student_pos[i]]++;
      }
      assert(water_num[student_pos[i]] >= 0);
      if(water_num[student_pos[i]] == 0){
	ans++;
      }else{
	water_num[student_pos[i]]--;
      }
      student_water[i] = true;
    }
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 1204
n = int(input())
s = str(n)
if s[-1]=='3':
  print('bon')
elif s[-1]=='0':
  print('pon')
elif s[-1]=='1':
  print('pon')
elif s[-1]=='6':
  print('pon')
elif s[-1]=='8':
  print('pon')
elif s[-1]=='2':
  print('hon')
elif s[-1]=='4':
  print('hon')
elif s[-1]=='5':
  print('hon')
elif s[-1]=='7':
  print('hon')
elif s[-1]=='9':
  print('hon')

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

using namespace std;

typedef long long ll;

int main()
{
    ll N, M;
    cin >> N >> M;
    ll left = 1;
    ll right = M + 1;
    ll _left = N - (M - 1);
    ll _right = N;
    while (1)
    {
        if (M % 2 == 1)
        {
            if (right - left == -1)
            {
                break;
            }
        }
        else
        {
            if (right - left == 0)
            {
                break;
            }
        }
        cout << left << " " << right << endl;
        left++;
        right--;
    }
    while (1)
    {
        if (M % 2 == 0)
        {
            if (_right - _left == -1)
            {
                break;
            }
        }
        else
        {
            if (_right - _left == 0)
            {
                break;
            }
        }
        cout << _left << " " << _right << endl;
        _left++;
        _right--;
    }
}

Measured memory_bytes: 3684
import math


def is_prime(target):
    dest = int(math.sqrt(target))
    for i in range(2, dest + 1):
        if target % i == 0:
            return False
    return True


N = int(input())
answer = []
for i in range(2, 55555):
    if is_prime(i) and i % 5 == 1:
        answer.append(i)
    if len(answer) == N:
        break

print(" ".join(map(str, answer)))


Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
#define repl(i, l, r) for (ll i = (l); i < (r); i++)
#define rep(i, n) repl(i, 0, n)
#define fi first
#define se second
#define all(x) (x).begin(), (x).end()
#define CST(x) cout << fixed << setprecision(x)
using ll = long long;
const ll MOD = 1000000007;
const int inf = 1e9 + 10;
const ll INF = 4e18 + 10;
const int dx[9] = {1, 0, -1, 0, 1, -1, -1, 1, 0};
const int dy[9] = {0, 1, 0, -1, 1, 1, -1, -1, 0};
int main() {
	cin.tie(0);
	cout.tie(0);
	ios::sync_with_stdio(false);

	ll n, k;
	cin >> n >> k;
	int a = 0, b = 0;
	rep(i, n) {
		int p;
		cin >> p;
		if (p % 2)
			a++;
		else
			b++;
	}
	if (k and !a)
		cout << 0 << endl;
	else if (!a) {
		ll ans = 1LL << n;
		cout << ans << endl;
	} else {
		ll ans = (1LL << n - 1);
		cout << ans << endl;
	}
	return 0;
}

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

int main() {

  string S;
  cin >> S;

  int N = S.size();

  string S1 = S;
  reverse(S1.begin(), S1.end());
  
  string S2 = S.substr(0, (N - 1) / 2);
  string S3 = S2;
  reverse(S3.begin(), S3.end());

  string S4 = S.substr((N + 3 - 1) / 2, N);
  string S5 = S4;
  reverse(S5.begin(), S5.end());

  string answer = "No";

  if (S == S1 && S2 == S3 && S4 == S5) {
    answer = "Yes";
  }

  cout << answer << endl;

  return 0;

}

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

int main() {
    int A, B, C;
    cin >> A >> B >> C;

    int cnt_5 = 0, cnt_7 = 0;
    
    if(A == 5) cnt_5++;
    else if(A == 7) cnt_7++;

    if(B == 5) cnt_5++;
    else if(B == 7) cnt_7++;

    if(C == 5) cnt_5++;
    else if(C == 7) cnt_7++;

    if(cnt_5 == 2 && cnt_7 == 1) cout << "YES" << endl;
    else cout << "NO" << endl;
}


Measured memory_bytes: 3504
#include <iostream>
#include <vector>
#include <cmath>
using namespace std;
#define REP(i, n) for(int i = 0; i < (int)(n); i++)

typedef vector<int> VI;

bool check(VI t, VI x, VI y, int n)
{
  REP(i, n) {
    int ct = t[i + 1] - t[i];
    int cx = x[i + 1] - x[i];
    int cy = y[i + 1] - y[i];
    int c_abs = abs(cx) + abs(cy);
    if (ct < c_abs || (ct % 2 != c_abs % 2))
      return false;
  }
  return true;
}

int main()
{
  int n;
  vector<int> t{0}, x{0}, y{0};
  bool ans = true;
  cin >> n;
  REP(i, n) {
    int t1, x1, y1;
    cin >> t1 >> x1 >> y1;
    t.push_back(t1);
    x.push_back(x1);
    y.push_back(y1);
  }
  if (check(t, x, y, n))
    cout << "Yes" << endl;
  else
    cout << "No" << endl;
}


Measured memory_bytes: 2796