akhauriyash/Code-Regression huggingface dataset:
parseInt(x) = parse(Int, x)
parseMap(x::Array{SubString{String},1}) = map(parseInt, x)

function main()
	n = parseInt.(split(readline()))
	x = Array{Int}(2, n[1])
	for i in 1:n[1]
		x[:,i] = readline() |> split |> x -> parseMap(x)
	end
	maxa = maximum(x[1,:])
	useb = Int[]
	for i in 1:n[1]
		if x[2,i] > maxa
			push!(useb, x[2,i])
		end
	end
	useb = sort(useb, rev=true)
	hp = n[2]
	count = 0
	for i in 1:length(useb)
		if hp > 0
			hp -= useb[i]
			count += 1
		end
	end
	if hp > 0
		if hp%maxa == 0
			count += div(hp, maxa)
		else
			count += div(hp, maxa)+1
		end
	end
	print(count)
end

main()

Measured memory_bytes: 181208
#include <stdio.h>

void zeroOrOneSwap(int& size, int arr[])
{
    bool swap = false;

    for (int i = 0; i < size; i++)
    {
        //printf("arr[i]: %d\n", arr[i]);
        
        if ((arr[i] != (i+1)) && swap)
        {
            printf("NO\n");
            return;
        }

        else if (arr[i] != (i+1))
        {
            int other = arr[arr[i]-1];
            
            // swap...
            if (other == (i+1))
            {
                //printf("other: %d\n", other);
                swap = true;
                arr[arr[i]-1] = arr[i];
                arr[i] = other;
            }

            else
            {
                printf("NO\n");
                return;
            }
        }
    }

    printf("YES\n");
}

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

    int arr[size];

    for (int i = 0; i < size; i++) scanf("%d", &arr[i]);

    zeroOrOneSwap(size, arr);

    return 0;
}

Measured memory_bytes: 128
#include <stdio.h>

int main(void)
{
	int a,b,c;
	int max=0;
	
	scanf("%d %d %d",&a,&b,&c);
	
	if(a>max){
		max=a;
	}
	if(b>max){
		max=b;
	}
	if(c>max){
		max=c;
	}
	
	printf("%d\n",a+b+c-max);
	
	return 0;
}

Measured memory_bytes: 128
N,M = map(int, input().split())
one2other = [0]*N
other2goal = [0]*N
for i in range(M):
    a,b = map(int, input().split())
    if a == 1:
        one2other[b-1] = 1
    if b == N:
        other2goal[a-1] = 1
for i in range(N):
    if one2other[i] == 1 and other2goal[i] == 1:
        print("POSSIBLE")
        exit()
print("IMPOSSIBLE")

Measured memory_bytes: 47960
using System;

public class Hello
{
    public static void Main()
    {
        var n = int.Parse(Console.ReadLine().Trim());
        var s = new string[n];
        var t = new int[n + 1];
        for (int i = 0; i < n; i++)
        {
            string[] line = Console.ReadLine().Trim().Split(' ');
            s[i] = line[0];
            t[i + 1] = t[i] + int.Parse(line[1]);
        }
        var x = Console.ReadLine().Trim();
        getAns(n, s, t, x);
    }
    static void getAns(int n, string[] s, int[] t, string x)
    {
        var w = Array.FindIndex(s, a => a == x);
        Console.WriteLine(t[n] - t[w + 1]);
    }
}


Measured memory_bytes: 13140
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
#define MAX 2000000
#define INFTY ( 1 << 30 )

int H, A[MAX+1];

void maxHeapify(int i) {
  int l, r, largest;
  l = i * 2;
  r = i * 2 + 1;
  if ( l <= H && A[l] > A[i] ) largest = l;
  else largest = i;

  if ( r <= H && A[r] > A[largest] ) largest = r;

  if ( i != largest ) {
    swap(A[i], A[largest]);
    maxHeapify(largest);
  }
}

int extract() {
  int maxv;
  if ( H < 1 ) return -INFTY;
  maxv = A[1];
  A[1] = A[H];
  H--;
  maxHeapify(1);
  
  return maxv;
}

void increaseKey(int i, int key) {
  if ( key < A[i] ) return;
  A[i] = key;
  while ( i > 1 && A[i/2] < A[i] ) {
    swap(A[i], A[i/2]);
    i = i/2;
  } 
}

void insert(int key) {
  H++;
  A[H] = -INFTY;
  increaseKey(H, key);
}

int main() {
  int key;
  char com[10];

  while ( 1 ) {
    scanf("%s", com);
    if ( com[0] == 'e' && com[1] == 'n' ) break;
    if ( com[0] == 'i' ) {
      scanf("%d", &key);
      insert(key);
    } else {
      printf("%d\n", extract());
    }
  }

  return 0;
}


Measured memory_bytes: 6616
#include <iostream>
#include <map>
#include <set>
#include <cmath>
#include <deque>
#include <queue>
#include <stack>
#include <regex>
#include <bitset>
#include <string>
#include <vector>
#include <iomanip>
#include <sstream>
#include <utility>
#include <iterator>
#include <algorithm>
#include <functional>
#define rep(i, n) for(int i = 0;i < n;i++)
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define ll long long
#define ull unsigned long long
#define MOD 1000000007
#define INF 9999999999
#define F first
#define S second

using namespace std;

typedef pair<int, int> pi;
typedef pair<int, pi> pp;

int dx[] = { 1, -1, 0, 0 };
int dy[] = { 0, 0, 1, -1 };
int gcd(int a, int b) { return b ? gcd(b, a%b) : a; }

ll n, m, A[1000001], B[1000001];
string s, t;
bool f(string s) {
	if (s[0] == s[1] && s[1] == s[2]) return 1;
	else return 0;
}
int main() {
	cin >> n;
	FOR(i, n, 1000) {
		string str = to_string(i);
		if (f(str)) {
			cout << i << endl;
			break;
		}
	}
	return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int[] a = new int[5];
        for (int i = 0; i < 5; i++) {
            a[i] = sc.nextInt();
        }
        sc.close();
        int min = 10;
        for (int i = 0; i < 5; i++) {
            int b = a[i] % 10;
            if (b != 0) {
                if (min > b) {
                    min = b;
                }
            }
        }
        int ans = 0;
        for (int i = 0; i < 5; i++) {
            if (a[i] % 10 == 0) {
                ans += a[i];
            } else {
                int c = a[i] / 10;
                int d = c * 10 + 10;
                ans += d;
            }
        }
        if (min != 10) {
            ans -= 10;
            ans += min;
        }
        System.out.println(ans);

    }
}

Measured memory_bytes: 23124
#include "bits/stdc++.h"
#define ll long long
#define ALL(x) x.begin(),x.end()
#define MOD (1000000000+7)
using namespace std;
#define PI 3.14159265359

int main(){
  ll N,M,K;
  cin>>N>>M>>K;
ll tmp;

  for(ll i=0;i<=N;i++){
    for(ll j=0;j<=M;j++){
      ll mm = min(i,j);
      tmp=N*M-M*i-N*j+i*j*2;
      if(tmp==K){
        cout<<"Yes"<<endl;
        return 0;
      }
    }
  }


cout<<"No"<<endl;
return 0;

}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
  int n;
  cin>>n;
vector<int>a(n);
  for(int i=0;i<n;i++){
cin>>a[i];
  }
  int s=0;
  sort(a.begin(),a.end());
  for(int i=0;i<n-1;i++){
    s+=a[i];
  }
  s+=a[n-1]/2;
  cout<<s;
}

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;
using P = pair< int, int >;

int main() {
    int H, W;
    cin >> H >> W;
    vector< vector< char > > field(H, vector< char >(W));
    rep(i, H) rep(j, W) cin >> field[i][j];

    // P(i,j)
    queue< P > que;
    vector< vector< int > > visit(H, vector< int >(W));
    rep(i, H) rep(j, W) {
        if (field[i][j] == '#') {
            que.push(P(i, j));
            visit[i][j] = 1;
        }
    }
    while (que.size() > 0) {
        P p = que.front();
        que.pop();
        int ci = p.first;
        int cj = p.second;
        vector< int > di = {0, 0, 1, -1};
        vector< int > dj = {1, -1, 0, 0};
        rep(k, 4) {
            int ni = ci + di[k];
            int nj = cj + dj[k];
            if (ni < 0 || H <= ni || nj < 0 || W <= nj) {
                continue;
            }
            if (visit[ni][nj] == 0) {
                visit[ni][nj] = visit[ci][cj] + 1;
                que.push(P(ni, nj));
            }
        }
    }
    int ans = 0;
    rep(i, H) rep(j, W) {
        if (visit[i][j] > ans) {
            ans = visit[i][j];
        }
    }
    cout << ans - 1 << endl;
}

Measured memory_bytes: 13456
use proconio::{fastout, input};
use std::io::*;
use std::str::FromStr;

use std::cmp::{max, min};
use std::collections::{BinaryHeap, HashMap, HashSet, VecDeque};

fn main() {
    input! {
        n: usize,
    }

    let mut ans = 0;
    for i in 1..=n {
        ans += (n - 1) / i;
    }
    println!("{}", ans);
}


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

int main(void){
    string s;
    cin >> s;

    char check[] = {'a', 'b', 'c', 'd','e', 'f', 'g', 'h','i', 'j', 'k', 'l','m', 'n', 'o', 'p','q', 'r', 's', 't','u', 'v', 'w', 'x','y','z'};
    int count;
    int none = 0;
    for(int i = 0; i < 26; i++){
        count = 0;
        for(int j = 0; j < s.length(); j++){
            if(check[i] == s[j])
                count++;
        }
        if(count == 0){
            cout << check[i] << endl;
            break;
        }
        none++;
    }

    if(none == 26)
        cout << "None" << endl;

    return 0;
}

Measured memory_bytes: 512
import sys
input = sys.stdin.readline

def main():
    N = int(input())
    A = list(map(int,input().split()))
    A.insert(0,0)

    B = [[] for i in range(N+1)]
    B[0] = 0

    for i in range(N, 0, -1):
        if 2*i > N:
            B[i] = A[i]
        else:
            B[i] = (A[i]+sum(B[i*2::(i-1)+1]))%2

    print(sum(B))
    for i in range(1, N+1,1):
        if B[i] == 1:
            print(i, end =" ")


if __name__ == "__main__":
    main()


Measured memory_bytes: 19156
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define repp(i,n,m) for (int i = m; i < (n); ++i)
#define repl(i,n) for (long long i = 0; i < (n); ++i)
#define reppl(i,n,m) for (long long i = m; i < (n); ++i)
using namespace std;
using ll = long long;
const int MOD = 1000000007;

int main(){
    int n; cin >> n;
    int* ar = new int[n];
    rep(i,n) cin >> ar[i];
    sort(ar, ar + n);
    //rep(i,n) cout << ar[i] << " "; cout << endl;
    int ans = 0;
    for (int i = n-1; i >= 2; i--){
        for (int j = i-1; j >= 1; j--){
            if (ar[j-1] > ar[i] - ar[j]){
                ans += &ar[j] - upper_bound(ar, ar + j ,ar[i] - ar[j]);
            }
        }
    }
    delete[] ar;
    cout << ans << endl;
}

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

bool isprime[1600000];

void solve(int n) {
  int left = n, right = n;
  for(int i = n; i > 0; --i) {
    if( isprime[i] ) {
      left = i;
      break;
    }
  }
  for(int i = n; i < 1600000; ++i) {
    if( isprime[i] ) {
      right = i;
      break;
    }
  }
  std::cout << right - left << std::endl;
}

int main() {

  for(int i = 0; i < 1600000; ++i) {
    isprime[i] = true;
  }
  isprime[0] = isprime[1] = false;
  for(int i = 2; i < 4000; ++i) {
    if( isprime[i] ) {
      for(int j = i + i; j < 1600000; j+=i) {
        isprime[j] = false;
      }
    }
  }

  for(;;) {
    int n;
    std::cin >> n;
    if( n == 0 ) break;

    solve(n);
  }

  return 0;
}
  

Measured memory_bytes: 4640
#include<bits/stdc++.h>
using namespace std;
string s;
unsigned long long a[210010];
unsigned long long ha()
{
    int len=s.size();
    unsigned long long x=0;
    for(int i=0;i<len;i++)
    {
        x=x*131+s[i];
    }
    return x;
}
int main()
{
    int n,ans=1;
    cin>>n;
    for(int i=1;i<=n;i++)
    {
        cin>>s;
        a[i]=ha();
    }
    sort(a+1,a+n+1);
    for(int i=2;i<=n;i++)
    {
        if(a[i]!=a[i-1])
        {
            ans++;
        }
    }
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 5184
from collections import defaultdict
import sys
input = sys.stdin.readline

N = int(input())
A = list(map(int, input().split()))
Q = int(input())

D = defaultdict(int)

for a in A:
    D[a] += 1

ans = sum(A)

for _ in range(Q):
    b, c = list(map(int, input().split()))
    D[c] += D[b]
    ans += c * D[b] - b * D[b]
    D[b] = 0
    print(ans)


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

int main(){
  int n,m;cin >> n >> m;
  int a[n][m],b[m];
  rep(i,n){rep(j,m)cin >> a[i][j];}
  rep(i,m)cin >> b[i];
  for(int i=0;i<n;++i){
    int ans = 0;
    for(int j=0;j<m;++j)ans += a[i][j]*b[j];
    cout << ans << endl;
  }
  return 0;
}


Measured memory_bytes: 3112
# python template for atcoder1
import sys
sys.setrecursionlimit(10**9)
input = sys.stdin.readline

S = input()[:-1]
ans = []
for c in S:
    if c == "B":
        if ans:
            ans.pop(-1)
    else:
        ans.append(c)
print("".join(ans))


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

int main(void){
	vector<int> a(3);
	for(int i=0;i<3;i++) cin >> a[i];
	sort(a.begin(),a.end());
	a.erase(unique(a.begin(),a.end()),a.end());
	cout << a.size() << endl;
	
	return 0;
}

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

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

    string str = "";
    while(n > 0) {
        int remain = n % 26 - 1;
        if (remain == -1) {
            str.push_back('z');
            n = n / 26 - 1;
        }
        else {
        str.push_back('a' + remain);
        n /= 26;}
    }
    reverse(str.begin(), str.end());
    cout << str << endl;
}

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

int main() {
    ll x, y;
    cin >> x >> y;
    if (x == 0) {
        if (y >= 0) cout << y << endl;
        else cout << abs(y)+1 << endl;
    }
    else if (x > 0) {
        if (y >= x) cout << y-x << endl;
        else if (y > 0) cout << 2+(x-y) << endl;
        else cout << 1+abs(abs(x)-abs(y)) << endl;
    }
    else if (x < 0) {
        if (y >= -x) cout << y-(-x)+1 << endl;
        else if (y > 0) cout << (-y-x)+1 << endl;
        else if (y == 0) cout << -x << endl;
        else if (y >= x) cout << y-x << endl;
        else cout << 1+(-y-(-x))+1 << endl;
    }
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<cstdio>
#include<algorithm>
#include<cstdlib>
#include<cmath>
#include<vector>
#include<utility>
#include<queue>
#include<stack>
#include<set>
#include<map>
#include<unordered_set>
#include<bitset>
using namespace std;
#define INF 2147483647
#define MODE 1
#ifdef MODE
#define DEB(X) cout<< #X <<": "<<X<<" ";
#define ARDEB(i,X) cout<< #X <<"["<<i<<"]: "<<X[i]<<" ";
#define END cout<<endl;
#else
#define DEB(X) {}
#define ARDEB(i,X) {}
#define END {}
#endif
typedef long long int ll;

int main(){
	string s;
	cin>>s;
	for(int i=0;i<26;i++){
		char a='a'+i;
		int count=0;
		for(int j=0;j<s.size();j++){
			if(s[j]==a)count++;
		}
		if(count%2==1){
			cout<<"No"<<endl;
			return 0;
		}
	}
	cout<<"Yes"<<endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<iomanip>
#include<cmath>
#include<algorithm>
using namespace std;
int main(){
    int n;
    double a[1000];
    double b[1000];
    double sum[5]={0,0,0,0,0};
    double ans[5]={0,0,0,0,0};
    cin>>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++){
        sum[1] += abs(a[i]-b[i]);
    }
    for(int i=0;i<n;i++){
        sum[2] += pow(a[i]-b[i],2);
    }
    for(int i=0;i<n;i++){
        sum[3] += pow(abs(a[i]-b[i]),3);
    }
    for(int i=0;i<n;i++){
        sum[4]=max(sum[4],abs(a[i]-b[i]));
    }
    for(int i=1;i<=3;i++){
        ans[i]=pow(sum[i],1.0*1/i);
    }
    ans[4]=sum[4];
    for(int i=1;i<=4;i++){
        cout<<fixed<<setprecision(30)<<ans[i]<<endl;
    }
    return 0;
}

Measured memory_bytes: 1344
#include<iostream>
using namespace std;
#define rep(i, n) for (int i=0; i < (int)(n); i++)
using ull = unsigned long long;
using ll = long long;

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

    if ((N/100==7) || ((N/10)%10==7) || ((N%10)==7)) cout << "Yes" << endl;
    else cout << "No" << endl;

    return 0;
}



Measured memory_bytes: 3624
#include<bits/stdc++.h>
using namespace std;
#define MOD 1000000007

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

  if(S == "RRR") cout << 3 << endl;
  else if(S == "SSS") cout << 0 << endl;
  else if(S == "RRS" || S == "SRR") cout << 2 << endl;
  else cout << 1 << endl;

  

}


Measured memory_bytes: 3568
#include <bits/stdc++.h>
#include <stdio.h>
#include<iostream>
#include<cstdio>
#include<bitset>
#include<algorithm>
#include<vector>
#include<list>
#include<queue>
#include<stack>
#include<string>
#include<string.h>
#include<cmath>
#include<utility>
#include<functional>
#include<map>
#include<set>
#include<cctype>
#include<fstream>
#include <numeric>
#include <iomanip>
#include <cstring> 
using namespace std;
using ll=long long;

#define FOR(i, a, b) for( int i=(a);i<=(b);i++)
#define RFOR(i, a, b) for( int i=(a);i>=(b);i--)
#define LFOR(i, a, b) for( long long int i=(a);i<=(b);i++)
#define LRFOR(i, a, b) for(long long int i=(a);i>=(b);i--)
#define MOD 1000000007
#define LLONG_MAXs 9223372036854775800

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

 
bool isPrimeNum( ll x ){ // 素数である場合 true を返す
  if( x <= 1 ){ // 1以下である場合は素数でないことがすぐにわかる
    return false;
  }
  // sqrt( double型 ) は引数の平方根を double型で返すので、int型でキャスト
  int n = (int)sqrt( (double)x );
  for( int i = 2; i <= n; i++ ){
    if( x % i == 0 ){ // 割り切る整数がある場合、即判定終了
      return false;
    }
  }
  return true; // 割り切る整数がない場合、素数である
}

constexpr ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
constexpr ll lcm(ll a,ll b){return a*b/gcd(a,b);}
constexpr ll abs(ll a,ll b){
if(a>=b)return a-b;
if(a<b)return b-a;
}
constexpr ll min(ll a,ll b){
if(a>=b)return b;
if(a<b)return a;
}

constexpr ll max(ll a,ll b){
if(a>=b)return a;
if(a<b)return b;
}

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

struct UnionFind {
    vector<int> par; // par[i]:iの親の番号　(例) par[3] = 2 : 3の親が2

    UnionFind(int N) : par(N) { //最初は全てが根であるとして初期化
        for(int i = 0; i < N; i++) par[i] = i;
    }

    int root(int x) { // データxが属する木の根を再帰で得る：root(x) = {xの木の根}
        if (par[x] == x) return x;
        return par[x] = root(par[x]);
    }

    void unite(int x, int y) { // xとyの木を併合
        int rx = root(x); //xの根をrx
        int ry = root(y); //yの根をry
        if (rx == ry) return; //xとyの根が同じ(=同じ木にある)時はそのまま
        par[rx] = ry; //xとyの根が同じでない(=同じ木にない)時：xの根rxをyの根ryにつける
    }

    bool same(int x, int y) { // 2つのデータx, yが属する木が同じならtrueを返す
        int rx = root(x);
        int ry = root(y);
        return rx == ry;
    }
};

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

  if(s.size()==1){
  cout<<0<<endl;



  return 0;
  }

  FOR(i,0,s.size()-2){
    if(s[i]!=s[i+1])ans++;
  }




  cout<<ans<<endl;



  return 0;
}
 


Measured memory_bytes: 512
N = int(input())

a = [0] * N
nums_count = 0
for num in range(1,N + 1):
    if num % 2 == 0:
        continue
    count = 0
    for i in range(1,num + 1):
        if num % i == 0:
            count += 1
    if count == 8:
        nums_count += 1

print(nums_count)




Measured memory_bytes: 2940
n, k = map(int, input().split())
A = [0] + list(map(int, input().split()))

if A[1] == 1:
    print(1)
    exit()

# 訪問順
B = [1]

# 訪問済み
C = [False] * (n + 1)
C[1] = True


while True:
    B.append(A[B[-1]])
    if C[B[-1]]:
        break
    C[B[-1]] = True

# print(B)

s = B.index(B[-1])

# print(B)
# print(len(B))

if k < s:
    print(B[k])
    exit()


B = B[B.index(B[-1]):-1]
print(B[(k - s) % len(B)])


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

int main() {
	int N;
	cin >> N;
	vector<int> d(N);
	rep(i,N) cin >> d[i];

	int ans = 0;
	rep(i,N)rep(k,i){
		ans += d[i]*d[k];
	}
	cout << ans << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#include<vector>
#include<string>
#include<algorithm>
#include<cmath>
 
#define fast ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define int long long int
#define mod 1000000007
#define inf 1e18+42
#define endl "\n"

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

#define rep(i,a,b) for(int i=a;i<b;i++)
#define repr(i,a,b) for(int i=a;i>=b;i--)
#define fori(it,A) for(auto it=A.begin();it!=A.end();it++)

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

int binpow(int,int);
void dfs( vector< vector<int> >&, int , vector<int>& );
void bfs( vector< vector<int> >&, int , vector<int>& );

void solve()
{
    int k;
    cin>>k;

    int sum = 0;

    rep(i,1,k+1)
    {
        rep(j,1,k+1)
        {
            rep(l,1,k+1)
            {
                sum += (__gcd(i,__gcd(j,l)));
            }
        }
    }

    cout<<sum<<endl;
}

signed main()
{
    fast;
    int t = 1;
    // cin>>t;

    while(t--)
    {
        solve();
    }
    return 0;
}

int binpow(int a, int b) {
    int res = 1;
    while (b > 0) {
        if (b & 1)
            res = res * a;
        a = a * a;
        b >>= 1;
    }
    return res;
}

void dfs ( vector< vector<int> > &v , int x , vector<int> &vis )
{
    vis[x] = 1;

    rep(i,0,v[x].size())
    {
        if( vis[v[x][i]] == 0 )
        {
            dfs(v,v[x][i],vis);
        }
    }
}

void bfs( vector< vector<int> > &v , int x , vector<int> &vis )
{
    queue<int> q;
    q.push(x);

    while( !q.empty() )
    {
        int p = q.front();
        q.pop();

        rep(i,0,v[p].size())
        {
            if ( vis[v[p][i]] == 0 )
            {
                vis[v[p][i]] = 1;
                q.push(v[p][i]);
            }
        }
    }
}

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

int main() {
    int n, o=0, e=0;
    cin >> n;
    vector<int> a(n);
    rep(i,n) {
        cin >> a[i];
        if (a[i]%2) o++;
        else e++;
    }

    if (o%2 && e) {
        cout << "NO" << endl;
    }
    else {
        cout << "YES" << endl;
    }
}


Measured memory_bytes: 768
#include<bits/stdc++.h>
#define ull unsigned long long
#define ll int64_t 
#define f(i,s,e) for(i=s;i<e;++i)
#define endl << "\n"
#define sp << " "
#define INF INFINITY
#define mset(a,b) memset(a,b,sizeof(a))
#define mod 1000000007
#define mp(a,b) make_pair(a,b)
#define F first
#define S second
#define all(x) x.begin(),x.end()
#define FAST_IO ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL)
#define PI acos(-1) 
#define pb(a) push_back(a)
#define pf(a) push_front(a)
#define eb(a) emplace_back(a)
#define print(x) for(auto it:x) cout<<it<<' '; cout<<"\n";

#pragma GCC target ("avx2")
#pragma GCC optimization ("O3")
#pragma GCC optimization ("unroll-loops")
using namespace std;

ll fpower(ll x,ll y)
{
	if(!y)
		return 1;
	return (y&1) ? x*fpower(x*x%mod,y/2)%mod : fpower(x*x%mod,y/2)%mod ;
}

int main()
{
	FAST_IO ;
	ll i,j,k,n;
	cin >> n;
	if(n<=1)
	{
		cout << "0\n";
		return 0 ;
	}
	cout << ( (fpower(10,n) + fpower(8,n))%mod - (2*fpower(9,n)%mod) + mod)%mod ;
	return 0;
}

/*
If u haven't come up with an approach yet ,skip this one
  Try this when feeling stuck -
  1. Int overflow, array bounds
  2. Special cases (n=1?)
  3. Prove your approach to yourself(mathematical induction,counter-intuitive or stronger test cases)
  4. Calm down and don't look at standings and stop thinking about rating and think about the question
  5. Just do it! 
*/ 

//Benq's advice - 
/* 
	And following advices are must for me -
	* do something instead of nothing and stay organized
	* WRITE STUFF DOWN 
*/

//#define _GLIBCXX_DEBUG 
// It will convert WA verdict to runtime error if that error is caused due to out of bound excess , declare it at the top
//#pragma GCC optimize "trapv" 
// It will convert WA to runtime error if WA was caused due to int overflow error,declare it anywhere

Measured memory_bytes: 3648
import math
N, D = map(int, input().split())
X = [list(map(int, input().split())) for _ in range(N)]
ans = 0
for i in range(N):
  for j in range(i+1, N):
    d = 0
    for k in range(D):
      d += (X[i][k]-X[j][k])**2
    d = math.sqrt(d)
    if d.is_integer():
      ans += 1

print(ans)

Measured memory_bytes: 38256
#include<iostream>
#include<algorithm>
#include<vector>
#include<string>
#include<utility>
#include<map>
#include<set>
#include<queue>
#include<bitset>
#include<math.h>
using namespace std;
typedef long long ll;
typedef pair<int,ll> P;
#define N (1000000000+7)
#define INF (ll)1e16
typedef long long ll;


int main(void){
    ll x,y;
    cin>>x>>y;
    if(x==y){
        cout<<0<<endl;
        return 0;
    }
    if(x==-y||-x==y){
        cout<<1<<endl;
        return 0;
    }
    if(x<y){
        if(x>=0)cout<<y-x<<endl;
        else{
            if(y<=0) cout<<y-x<<endl;
            else{
                if(-x<y)cout<<1+y+x<<endl;
                else cout<<1-y-x<<endl;
            }
        }
    }
    else{
        if(y>0)cout<<2-y+x<<endl;
        else{
            if(x==0)cout<<1-y<<endl;
            else{
                if(x>0){
                    if(x<-y)cout<<1-y-x<<endl;
                    else cout<<1+y+x<<endl;
                }
                else cout<<2+x-y<<endl;
            }
        }
    }
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define ld long double
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()
#define pqgreater(x) x, vector<x>, greater<x>
#define abs(x) (x>0?x:-x)
#define decimal(x) cout<<fixed<<setprecision(x)
#define gc getchar//_unlocked
#define pc putchar//_unlocked
const ll mod=998244353;
int solve(); void precomp();

#define multitest 0
#define usecase 0
int main(){ ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
	int t=1;
	if(multitest) cin>>t;
	precomp();
	for(int tc=1; tc<=t; tc++){
		if(multitest && usecase)
			cout<<"Case #"<<tc<<": ";
		solve();
	}
}
void precomp(){	
	return;
}
vector<ll>v;
int solve(){
	char a, b; cin>>a>>b;
	if(a==b) cout<<"H\n";
	else cout<<"D\n";
	return 0;
}

Measured memory_bytes: 256
N,K=map(int,input().split())
R,S,P=map(int,input().split())
T=input()

last=['' for i in range(K)]

ans=0
for i,c in enumerate(T):
    rem=i%K
    if c=='r':
        if last[rem]!='r':
            ans+=P
            last[rem]=c
        else:
            last[rem]=''    
    elif c=='s':
        if last[rem]!='s':
            ans+=R
            last[rem]=c
        else:
            last[rem]=''
    elif c=='p':
        if last[rem]!='p':
            ans+=S
            last[rem]=c
        else:
            last[rem]=''

print(ans)

Measured memory_bytes: 44656
#!/usr/bin/env ruby

numbers = []

numbers = gets.split.map(&:to_i)

1.upto(numbers[0]) do |index|
    if index % 3 == 0 then
        print " #{index}"
    else
        index.to_s.split("").each do |word|
            if word == "3"
                print " #{index}"
                break
            end
        end
    end
end
puts ""


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

#define rep(i, j) for (int i = 0; i < j; i++)
#define all(obj) (obj).begin(), (obj).end()
#define rall(obj) (obj).rbegin(), (obj).rend()
typedef long long int ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<vi> vvi;

template<class T,class U> void chmax(T& a, U b) {if(a<b)a=b;}
template<class T,class U> void chmin(T& a ,U b) {if(b<a)a=b;}

int main() {

    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.precision(10);
    cout << fixed;

    int n;
    cin >> n;
    vi a(n);
    rep(i, n) cin >> a[i];

    ll ans = 0;
    int cur = 1;
    rep(i, n) {
        if (a[i] == cur) {
            cur++;
        } else {
            ans++;
        }
    }

    if (ans == n) {
        cout << -1 << endl;
    } else {
        cout << ans << endl;
    }

    return 0;
}

Measured memory_bytes: 1152
#include <iostream>
#include <cstdio>
#include <string>
#include <cstring>
#include <algorithm>
#include <cmath>
#include <vector>
#include <queue>
#define pb push_back
using namespace std;
typedef pair<int,int> pii;

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

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


Measured memory_bytes: 256
#include <stdio.h>
int main()
{
	int i,j,f,a[3][3],b[3][3],c[3][3];
	for(i=0;i<3;i++)
		for(j=0;j<3;j++)
			scanf("%d",&c[i][j]);
	for(i=0;i<3;i++)
		for(j=0;j<2;j++)
		{
			a[i][j]=c[j+1][i]-c[j][i];
			b[i][j]=c[i][j+1]-c[i][j];
		}
	for(f=i=0;i<2;i++)
		for(j=0;j<2;j++)
			if(a[j][i]!=a[j+1][i]||b[j][i]!=b[j+1][i])
				f=1;
	if(f==0)
		printf("Yes\n");
	else
		printf("No\n");
	return 0;
}

Measured memory_bytes: 128
#include <vector>
#include <string>
#include <cstdio>

using namespace std;

string inputWord() {
    char buf[256];
    scanf("%s", buf);
    return buf;
}

string S;
vector<string> X;

int main() {
    S = inputWord();
    X = vector<string>({"SUN", "MON", "TUE", "WED", "THU", "FRI", "SAT"});
    for(int i=0; i<X.size(); ++i) if(X[i]==S) {
        printf("%d\n", 7-i);
    }
    return 0;
}


Measured memory_bytes: 3292
#include<iostream>

using namespace std;

string str;

string keys[] = {
    ".,!? ",
    "abc",
    "def",
    "ghi",
    "jkl",
    "mno",
    "pqrs",
    "tuv",
    "wxyz",
};

void solve() {
    cin>>str;
    char c = '\0';
    int cnt=-1;
    int num=0;

    for(int i=0;i<str.size();i++) {
        
        if(str[i]=='0') {
            if(cnt==-1) c='\0';
            else c=keys[num-1][cnt];
            if(c!='\0') cout<<(c);
            c='\0';
            cnt=-1;
            num=0;
        }
        else {
            num=str[i]-'0';
            cnt++;
            cnt%=keys[num-1].size();            
        }
    }
    cout<<endl;
}

int main() {
    int n;
    cin>>n;
    for(int i=0;i<n;i++) {
        solve();
    }

    return 0;
}

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

int main(){
  int n, x, sum=0, chpst=10000, ret=0;
  cin >> n >> x;
  for(int i=0; i<n; i++){
    int tmp;
    cin >> tmp;
    sum += tmp;
    chpst = chpst > tmp ? tmp : chpst;
  }
  ret += n;
  x -= sum;
  ret += x/chpst;
  cout << ret;
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0, i##_len = (n); i < i##_len; i++)
#define reps(i, s, n) for(int i = (s), i##_len = (n); i < i##_len; i++)
#define rrep(i, n) for(int i = (n) - 1; i >= 0; i--)
#define rreps(i, e, n) for(int i = (n) - 1; i >= (e); i--)
#define all(x) (x).begin(), (x).end()
#define sz(x) ((int)(x).size())
#define uniq(x) (x).erase(unique((x).begin(), (x).end()), (x).end())

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    int n;
    cin >> n;
    vector<int> a(n);
    rep(i, n) cin >> a[i];
    bool desc = false, asc = false;
    int ans = 1;
    
    rep(i, n - 1) {
        if (
            ((desc) && (a[i] < a[i + 1])) ||
            ((asc) && (a[i] > a[i + 1]))
        ) {
            desc = asc = false;
            ans++;
        }
        else if ((!desc) && (!asc)) {
            if (a[i] < a[i + 1]) {
                asc = true;
            }
            else if (a[i] > a[i + 1]) {
                desc = true;
            }
        }
    }
    
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 640
#include <iostream>
using namespace std;
int main(void){
    int a, b, c;
    int m = 0;
    cin >> a >> b >> c;
    if(a > b){
        m = a;
        a = b;
        b = m;
    }
    if(b > c){
        m = c;
        c = b;
        b = m;
    }   
    if(a > b){
        m = a;
        a = b;
        b = m;
    }
    cout << a << " " << b << " " << c << endl;
}


Measured memory_bytes: 3088
#include<iostream>

using namespace std;

int main(){

  long long x,a,b;
  cin >> x >> a >> b;
  if(b-a <= 0)
    cout << "delicious" << endl;
  else if(b-a > 0 && b-a <= x)
    cout << "safe" << endl;
  else
    cout << "dangerous" << endl;

}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define FOR0(i,n) for(i=0;i<n;i++)
#define FOR(i,j,n) for(i=j;i<n;i++)
#define FORD(i,j,k) for(i=j;i>=k;i--)
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define inf 1000000000
#define ninf -1000000000
#define endl '\n' 
#define she_told_me_dont_worry ios_base::sync_with_stdio (false) ; cin.tie(0) ; cout.tie(0) ;
// Use cout.flush() for interactive problems.
// Use this for increased stack size: g++ -o a.exe -Wl,--stack=256000000 -O2 source.cpp
inline long long  MAX2(long long  a, long long int b){return (a)>(b)?(a):(b);}
inline long long  MAX3(long long  a, long long  b,long long  c){return (a)>(b)?((a)>(c)?(a):(c)):((b)>(c)?(b):(c));}
inline long long  MIN2(long long  a, long long  b){return (a)<(b)?(a):(b);}
inline long long  MIN3(long long  a, long long b,long long c){return (a)<(b)?((a)<(c)?(a):(c)):((b)<(c)?(b):(c));}
using namespace std;
typedef long long ll;
typedef pair<int,int> ii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector< ii > vii;
int main()
{
    she_told_me_dont_worry
    string s;
    cin>>s;
    int i;
    bool is = false;
    FOR0(i, 3)
    {
        if(s[i] == s[i+1])
        {
            is = true;
            break;
        }
    }
    if(is) cout<<"Bad";
    else cout<<"Good";
    cerr <<endl<< "Time elapsed : " << clock() * 1000.0 / CLOCKS_PER_SEC << " ms" << '\n';
}

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

using namespace std;

#define arr array
#define ll long long
#define REP(i, n) for (int i = 0; (i) < (int)(n); ++ (i))
#define REP3(i, m, n) for (int i = (m); (i) < (int)(n); ++ (i))
#define REP_R(i, n) for (int i = (int)(n) - 1; (i) >= 0; -- (i))
#define REP3R(i, m, n) for (int i = (int)(n) - 1; (i) >= (int)(m); -- (i))
#define ALL(x) std::begin(x), std::end(x)
#define dump(x) cerr << #x " = " << x << endl

bool is_lowercase(char c) {
  return c>='a'&&c<='z';
}
bool is_uppercase(char c) {
  return c>='A'&&c<='Z';
}

char to_lowercase(char c) {
//  assert(is_uppercase(c));
  if (is_lowercase(c))
    return c;
  return c-'A'+'a';
}

char to_uppercase(char c) {
//  assert(is_lowercase(c));
  if (is_uppercase(c))
    return c;
  return c-'a'+'A';
}

char switch_case(char c) {
  if (is_uppercase(c)) {
    return to_lowercase(c);
  } else {
    return to_uppercase(c);
  }
}

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  constexpr char endl = '\n';

  string s;
  cin >> s;

  string ans=((s[2]==s[3] && s[4]==s[5])?"Yes":"No");

  cout << ans << endl;


  return 0;
}


Measured memory_bytes: 256
#include<cmath>
#include<queue>
#include<vector>
#include<iostream>

#define	mp	make_pair
#define	pb	push_back

using namespace std;

typedef	vector<int>			vi;
typedef	pair<double,int>	pdi;

const int inf=1000000000;
int n,id[1000],x[1000],y[1000];
double adj[1000][1000];

bool Dijkstra(int s,int g,int *path)
{
	double d[1000];
	bool visited[1000];
	for(int i=0;i<n;i++)	d[i]=inf,visited[i]=false,path[i]=-1;
	d[s]=0;
	priority_queue<pdi> pq;	pq.push(mp(0,s));
	while(!pq.empty()){
		pdi a=pq.top();	pq.pop();
		double dis=-a.first;
		int u=a.second;
		if(u==g)	return true;
		visited[u]=true;
		for(int v=0;v<n;v++){
			if(visited[v])	continue;
			if(dis+adj[u][v]<d[v]){
				d[v]=dis+adj[u][v];
				pq.push(mp(-d[v],v));
				path[v]=u;
			}
		}
	}
	return false;
}

void showPath(int s,int now,int *path,int *id)
{
	if(now==s){ cout<<id[s]; return; }
	showPath(s,path[now],path,id);
	cout<<' '<<id[now];
}

int main()
{
	for(;cin>>n,n;){
		for(int i=0;i<n;i++)	cin>>id[i]>>x[i]>>y[i];

		for(int i=0;i<n;i++)for(int j=0;j<n;j++)	adj[i][j]=(i==j?0:inf);
		for(int i=0;i<n;i++)for(int j=0;j<n;j++){
			int xx=x[i]-x[j],yy=y[i]-y[j];
			if(xx*xx+yy*yy<=50*50)	adj[i][j]=sqrt(xx*xx+yy*yy);
		}

		int m;	cin>>m;
		while(m--){
			int sid,gid;	cin>>sid>>gid;
			int s,g;
			for(int i=0;i<n;i++){
				if(id[i]==sid)	s=i;
				if(id[i]==gid)	g=i;
			}

			int path[1000];
			if(Dijkstra(s,g,path)){
				showPath(s,g,path,id);
				cout<<endl;
			}
			else	cout<<"NA"<<endl;
		}
	}

	return 0;
}

Measured memory_bytes: 0
#include <stdio.h>
#include <stdlib.h>
#define K 10000  //A[i]最大値

int *countingSort(int*, int); //入力された配列、ソート後の配列、入力の要素数

main(){
  int *arrA, *arrB;
  int n, i;

  scanf("%d", &n);
  arrA = (int *)malloc(sizeof(int)*n);
  for(i=0; i<n; i++) scanf("%d", arrA+i);

  arrB = countingSort(arrA, n);

  for(i=0; i<n-1; i++) printf("%d ", arrB[i]);
  printf("%d\n", arrB[i]);

  free(arrA);
  free(arrB);

  return 0;
}

int *countingSort(int *arrA, int n){
  int *arrB, arrC[K+1], i;
  arrB = malloc(sizeof(int)*n);

  arrC[0] = -1;
  for(i=1; i<=K; i++) arrC[i] = 0;
  
  for(i=0; i<n; i++){
    arrC[arrA[i]]++;
  }
  
  for(i=1; i<=K; i++){
    arrC[i] = arrC[i] + arrC[i-1];
  }

  /*  for(i=0; i<=K; i++){
    printf("arrC[%d] = %d\n", i, arrC[i]);
    }*/
  
  for(i=n-1; i>=0; i--){
    arrB[arrC[arrA[i]]] = arrA[i];
    arrC[arrA[i]]--;
  }

  return arrB;
}

Measured memory_bytes: 16124
#include<iostream>
#include<numeric>
#include<math.h>
#include<cmath>
#include<vector>
#include<map>
#include<algorithm>
using namespace std;
using ll = long long int;

int n;
vector<ll> a;
map<ll, int> num;


int main(void) {
	cin >> n;
	a = vector<ll>(n);
	ll tmp = 0;
	for (int i = 0; i < n; i++) {
		cin >> a[i];
		if (i == 0) {
			tmp = a[i];
		}
		else {
			tmp = tmp ^ a[i];
		}
	}

	string ret = "No";
	if (tmp == 0)
		ret = "Yes";

	cout << ret << endl;
	return 0;
}

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


int main()
{
	string s;
	cin>>s;
	string p;
	p=s;
	if(s[s.length()-1]=='s')
	{
	   p+="es";
	}
	else
	{
		p+='s';
	}
	cout<<p<<"\n";
}

Measured memory_bytes: 3620
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<queue>
#define ll long long
using namespace std;
int rdn()
{
  int ret=0;bool fx=1;char ch=getchar();
  while(ch>'9'||ch<'0'){if(ch=='-')fx=0;ch=getchar();}
  while(ch>='0'&&ch<='9')ret=ret*10+ch-'0',ch=getchar();
  return fx?ret:-ret;
}
int Mn(int a,int b){return a<b?a:b;}
const int N=2010,M=2e4+5; const ll INF=(ll)(2e9+5)*M;
int n,S,T,tot,hd[N],xnt=1,to[M],nxt[M],cap[M],w[M]; ll ans;
int info[N],pre[N];ll dis[N]; bool ins[N];
queue<int> q;
void add(int x,int y,int c,int z)
{
  to[++xnt]=y;nxt[xnt]=hd[x];hd[x]=xnt;cap[xnt]=c;w[xnt]=z;
  to[++xnt]=x;nxt[xnt]=hd[y];hd[y]=xnt;cap[xnt]=0;w[xnt]=-z;
}
bool spfa()
{
  for(int i=1;i<=tot;i++)dis[i]=-INF;
  dis[S]=0; info[S]=N*10; info[T]=0; q.push(S);
  while(q.size())
    {
      int k=q.front(); q.pop(); ins[k]=0;
      for(int i=hd[k],v;i;i=nxt[i])
	if(cap[i]&&dis[v=to[i]]<dis[k]+w[i])
	  {
	    dis[v]=dis[k]+w[i];
	    pre[v]=i; info[v]=Mn(cap[i],info[k]);
	    if(!ins[v])ins[v]=1,q.push(v);
	  }
    }
  return info[T];
}
void ek()
{
  int tp=info[T];
  for(int i=pre[T];i;i=pre[to[i^1]])
    {
      cap[i]-=tp; cap[i^1]+=tp;
      ans+=(ll)w[i]*tp;
    }
}
int main()
{
  n=rdn(); tot=4; S=++tot; T=++tot;
  for(int i=1,x,y,c;i<=n;i++)
    {
      x=rdn();y=rdn();c=rdn();
      tot++; add(S,tot,c,0);
      add(tot,1,c,x+y); add(tot,2,c,x-y);
      add(tot,3,c,-x+y); add(tot,4,c,-x-y);
    }
  for(int i=1,x,y,c;i<=n;i++)
    {
      x=rdn();y=rdn();c=rdn();
      tot++; add(tot,T,c,0);
      add(1,tot,c,-x-y); add(2,tot,c,-x+y);
      add(3,tot,c,x-y); add(4,tot,c,x+y);
    }
  while(spfa())ek();
  printf("%lld\n",ans);
  return 0;
}


Measured memory_bytes: 768
#include <bits/stdc++.h>
#define rep(i,n)for(int i=0;i<(n);i++)
using namespace std;
typedef long long ll;
typedef pair<int,int>P;

const int INF=0x3f3f3f3f;
const ll INFL=0x3f3f3f3f3f3f3f3f;
const int MOD=1000000007;

int h[200000];

int main(){
    int num;
    cin >> num;
    for(int i=0; i<num; i++)
        scanf("%d", &h[i]);
    int Max = 0;
    int cnt = 0;

    for(int i=num-1; i>=0; i--){
        if(i==num-1|h[i]<h[i+1]) cnt = 0;
        cnt++;
        Max = max(Max, cnt);
    }
    cout << Max-1 << endl;
    return 0;
}

Measured memory_bytes: 640
#include <iostream>
#include <algorithm>
#include <string>
#include <cstring>
#include <cstdio>
#include <cstdlib>
#include <set>

#define rep2(i, b, n) for(int i=b; i < n; ++i)
#define repm(i, b, n) for(int i=b; i > n; --i)
#define rep(i, n) rep2(i, 0, n)
#define sz(v) v.size()
#define mk(x, y) make_pair(x, y)
#define fst first
#define scd second
#define MEMSET(x, n) memset(x, n, sizeof(x))
#define MEMZERO(x) MEMSET(x, 0)
#define URU(y) (!(y % 4) && y % 100 || !(y % 400))

using namespace std;

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

struct Line
{
	double l;
	double r;
	int num;
};

enum Check
{
	LOW = 0,
	MID,
	HIGH,
};

double cross_product( float x1, float y1, float x2, float y2 )
{
	return ((x1 * y2) - (x2 * y1));
}

inline Check inRange( Line l, Line h, double x, double y, double w )
{
	double v1, v2;
	
	v1 = cross_product(w, (l.r - l.l), x, (y - l.l));
	v2 = cross_product(w, (h.r - h.l), x, (y - h.l));
	
	if (0 < v1 && 0 < v2) // 上
		return HIGH;
	if (0 > v1 && 0 > v2) // 下
		return LOW;
	else				  // 中
		return MID;
}

int main( void )
{
	int n, m, w, h, S;
	Line T[30010];
	int N1[30010], S1[30010];
	
	while ( cin >> n >> m >> w >> h >> S, n | m | w | h | S )
	{
		MEMZERO(T);
		
		rep2 (i, 1, (m + 1))
		{
			cin >> T[i].l >> T[i].r;
		}
		
		rep (i, n)
		{
			double x, y;
			cin >> x >> y;
			
			int low = 1, high = m;
			while (low <= high)
			{
				int mid = (low + high) / 2;
				Check c = inRange(T[mid-1], T[mid], x, y, (double)w);
				
				if (c == LOW)
					high = mid;
				else if (c == HIGH)
					low = mid + 1;
				else // c == Check::MID
				{
					++T[mid].num;
					break;
				}
			}
		}
		
		int ans = n, sum = 0;
		
		rep (i, (m + 1))
		{
			sum += T[i].num;
			N1[i] = sum;
			if (ans <= sum)
				break;
			if ((S * 2) <= (S1[i] = ((T[i].l + T[i].r) * w)))
			{
				ans = sum;
				break;
			}
		}
		// cout << ans << endl;
		
		rep2 (i, 0, m)
		{
			if (ans <= N1[i])
				break;
			sum = 0;
			repm (j, m, (i + 1))
			{
				sum += T[j].num;
				if (ans <= (N1[i] + sum))
					break;
				if ((S * 2) <= (((2 * h - (T[j-1].l + T[j-1].r)) * w) + S1[i]))
				{
					ans = N1[i] + sum;
					break;
				}
			}
		}

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

Measured memory_bytes: 2096
#include<stdio.h>
int main () {
int n,i,j,k,a,b,x[30][60];
char s[60][60],e[5];
scanf("%d",&n);
for(i=1;i<=n;i++){
scanf("%s",s[i]);
}
for(i=1;i<=26;i++){
for(j=1;j<=n;j++){
x[i][j]=0;
for(k=0;s[j][k]!='\0';k++){
if (s[j][k]=='a'+i-1) x[i][j]=x[i][j]+1;
}
}
}
for(i=1;i<=26;i++){
for(j=1;j<n;j++){
if (x[i][j]<x[i][j+1]) x[i][j+1]=x[i][j];
}
e[0]='a'+i-1;
for(k=1;k<=x[i][n];k++){
printf("%c",e[0]);
}
}
printf("\n");
return 0;
}

Measured memory_bytes: 128
from collections import Counter, defaultdict
import sys
sys.setrecursionlimit(10 ** 5 + 10)
# input = sys.stdin.readline
from math import factorial
import bisect
import math

def div(a, b):
    if a % b == 0:
        return a // b
    else:
        return (a // b) + 1

def main():
    num = list(map(int, input().split()))
    print(len(set(num)))




if __name__ == '__main__':
    main()


Measured memory_bytes: 38256
N = int(input())
A = input().split()
A = [int(A[i])-i for i in range(N)]
A = sorted(A)

s = 0
if N % 2 == 0:
  k = int(N/2)
  for i in range(N):
    s += abs(A[i]-A[k-1])
else:
  k = int((N+1)/2)
  for i in range(N):
    s += abs(A[i]-A[k-1])
print(s)

Measured memory_bytes: 26176
N = gets.to_i
edges = N.times.map{ [] }
$<.each{|s|
  from, to, dst = s.split.map &:to_i
  edges[from-1] << [to-1, dst]
  edges[to-1] << [from-1, dst]
}

visited = [false] * N


st = [[0, 0]]

while !st.empty?
  new_st = []
  st.each{|from, dst|
    next if visited[from]
    visited[from] = dst%2
    edges[from].each{|to, dst1|
      new_st << [to, dst + dst1]
    }
  }
  st = new_st
end

puts visited


Measured memory_bytes: 29972
#include "bits/stdc++.h"
using namespace std;
#define FOR(i,j,k) for(int (i)=(j);(i)<(int)(k);++(i))
#define rep(i,j) FOR(i,0,j)
#define each(x,y) for(auto &(x):(y))
#define mp make_pair
#define MT make_tuple
#define all(x) (x).begin(),(x).end()
#define debug(x) cout<<#x<<": "<<(x)<<endl
#define smax(x,y) (x)=max((x),(y))
#define smin(x,y) (x)=min((x),(y))
#define MEM(x,y) memset((x),(y),sizeof (x))
#define sz(x) (int)(x).size()
#define rt return
using dbl = double;
using ll = long long;
using pii = pair<int, int>;
using vi = vector<int>;
using vll = vector<ll>;

struct P {
    int x, y;
};
bool operator<(P p, P q) {
    return p.y * (q.x + q.y) < q.y * (p.x + p.y);
}

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

    int A, B, C, D, E, F;
    cin >> A >> B >> C >> D >> E >> F;

    vi wa(F + 1), sug(F + 1);
    wa[0] = sug[0] = 1;
    rep(i, F)if (i + 100 * A <= F && wa[i]) {
        wa[i + 100 * A] = 1;
    }
    rep(i, F)if (i + 100 * B <= F && wa[i]) {
        wa[i + 100 * B] = 1;
    }

    rep(i, F)if (i + D <= F && sug[i]) {
        sug[i + D] = 1;
    }
    rep(i, F)if (i + C <= F && sug[i]) {
        sug[i + C] = 1;
    }

    P ma{100 * A, 0};
    rep(i, F+1)rep(j, F+1) {
        if (i + j <= F && wa[i] && sug[j]) {
            if (j > i / 100 * E)continue;
            P p{ i,j };
            smax(ma, p);
        }
    }

    cout << ma.x + ma.y << ' ' << ma.y << endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <functional>
#pragma warning(disable:4996)
#pragma comment(linker, "/STACK:336777216")
using namespace std;
using namespace __gnu_pbds;
typedef long long ll;
#define  int long long int
typedef complex<long double> cd;
const long double pi=acos(-1);
typedef double db;
typedef long double ldb;
typedef pair <int, int> pii;
typedef pair <db, db> pdd;
typedef vector<int> vi;
typedef vector<vector<int> > matrix;
#define m1 make_pair
#define pb push_back
#define flush fflush(stdout)
#define IOS std::ios::sync_with_stdio(false); cin.tie(NULL);cout.tie(NULL);
#define reset(x,v) memset(x,v,sizeof(x))
#define sz(x) (int)(x.size())
#define ff first
#define ss second
#define endl "\n"
#define debug(x) (cerr << #x << ": " << x << "\n")
#define setbits(x) __builtin_popcount(x)
inline ll gcd(ll a,ll b){if(a==0) return b;return gcd(b%a,a);}
inline ll power(ll a,ll n,ll m){if(n==0)return 1;ll p=power(a,n/2,m);p=(p*p)%m;if(n%2) return (p*a)%m;else return p;}
const ll MOD =998244353;
const ll hell=1000000007;
const int INF = 1e17;
const ll LL_INF = 0x3f3f3f3f3f3f3f3f;

typedef tree<int, null_type, less<int>, rb_tree_tag,
tree_order_statistics_node_update>
ordered_set;
int sm[61][300005];
int32_t main()
{
    IOS;
    int n;
    cin>>n;
    int a[n+1];
    for(int i=1;i<=n;i++)
        cin>>a[i];
    for(int i=60;i>=0;i--)
    {
        if(a[n]&(1ll<<i))
        sm[i][n]++;
    }
    for(int i=n-1;i>=1;i--)
    {
        for(int j=0;j<=60;j++)
        {
            sm[j][i]=sm[j][i+1];
            if(1&(a[i]>>j))
                sm[j][i]++;
        }
    }
    int pr,z,ans=0;
    for(int i=1;i<n;i++)
    {
        pr=1;
        for(int j=0;j<=60;j++)
        {
            if(a[i]&1)
            {
                z=n-i-sm[j][i+1];
                z=(pr*z)%hell;
                ans=(ans+z)%hell;
            }
            else
            {
                z=sm[j][i+1];
                z=(z*pr)%hell;
                ans=(ans+z)%hell;
            }
            a[i]=a[i]>>1;
            pr=(pr*2)%hell;
        }
    }
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 145536