akhauriyash/Code-Regression huggingface dataset:
def main():
    n, x = (int(z) for z in input().split())
    els = [int(el) for el in input().split()]
    ds = [0] * (n + 1)
    for i in range(1, n + 1):
        ds[i] = ds[i - 1] + els[i - 1]
    res = sum(d <= x for d in ds)
    print(res)


if __name__ == "__main__":
    main()

Measured memory_bytes: 3064
import functools
N = int(input())
T = []
for i in range(N):
  T.append(int(input()))
def gcd(A, B):
  while(True):
    if A and B:
      if A > B:
        A = A % B
      else:
        B = B % A
    else:
      return max(A, B)
 
def lcm(A, B):
  return (A // gcd(A, B)) * B
 
print(functools.reduce(lcm, sorted(T, reverse=True)))

Measured memory_bytes: 3572
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstring>

using namespace std;
typedef long long ll;

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

  int p, h;
  cin >> p >> h;
  int ho[h + 1];
  int flag = 0;
  for(int i = 0; i < h; i++){
    cin >> ho[i];
  }
    int tmp = 0;
    int sum = 0;
    for(int i = h - 1; i >= 0; i--){
      tmp = ho[i] - ho[i - 1];
      if(tmp > sum){
        sum = tmp;
      }
    }
    int fir = p - sum;
    int sec = ho[h - 1] - ho[0];
    cout << min(fir, sec);

  return 0;
}


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

void solve(std::istream &ist, std::ostream &ost)
{
    /* ------- 宣言と入力 ------- */

    int S, W;
    ist >> S >> W;

    /* ------- 計算 ------- */

    if (W >= S)
    {
        cout << "unsafe" << endl;
    }
    else
    {
        cout << "safe" << endl;
    }
}

#ifndef WOMAIN
int main()
{
    solve(std::cin, std::cout);
    return 0;
}
#endif


Measured memory_bytes: 3632
import java.util.Scanner;

public class Main {

    /**
     * @param args the command line arguments
     */
    public static void main(String[] args) {
        // TODO code application logic here
        Scanner sc = new Scanner(System.in);
        String w = sc.next();
        int num[] = new int[26];
        for (int i = 0; i < w.length(); i++) {
            for (char c = 'a'; c < 'z' + 1; c++) {
                if(w.charAt(i) == c){
                    num[c - 'a']++;
                }
            }
        }
        for (int i = 0; i < num.length; i++) {
            if(num[i] % 2 != 0){
                System.out.println("No");
                System.exit(0);
            }
        }
        System.out.println("Yes");
    }
    
}

Measured memory_bytes: 9424
#include <iostream>
#include <vector>
#include <utility>
#include <queue>
#include <map>

using namespace std;

typedef long long ll;

int main() {
    int n;  cin >> n;   ll t;   cin >> t;
    vector<ll> a(n);
    for (int i = 0; i < n; i++)
        cin >> a[i];

    ll x = max(a[n-1] - a[n-2], (ll)0);
    ll inf = max(a[n-1], a[n-2]);
    int c = 1;
    map<ll,int> m;
    m[a[n-1]]++;    m[a[n-2]]++;

    for (int i = n-3; i >= 0; i--) {
        if (inf - a[i] > x) {
            x = inf - a[i];
            c = m[inf];
            m[a[i]]++;
        }
        else if (inf - a[i] == x)   {
            c++;
            m[a[i]]++;
        }
        else {
            m[a[i]]++;
        }
        inf = max(inf, a[i]);
    }

    cout << c << endl;
    return 0;
}

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

int d[3][4]={{0,4,5,1},{0,2,5,3},{4,2,1,3}};//d,u,l,r

void dice(int a[6], int n){
	int tmp = a[d[n][0]];
	a[d[n][0]] = a[d[n][1]];
	a[d[n][1]] = a[d[n][2]];
	a[d[n][2]] = a[d[n][3]];
	a[d[n][3]] = tmp;
}

int check(int a[6], int b[6]){
	for(int i = 0;i < 6;i++)if(a[i] != b[i])return 0;
	return 1;
}

int func(int a[6], int b[6]){
	for(int i = 0;i < 6;i++){
		for(int j = 0;j < 4;j++){
			dice(b, 0);
			if(check(a, b))return 1;
		}
		if(i%2 == 0)dice(b, 1);
		else dice(b, 2);
	}
	return 0;
}

int main(){
	int a[6], b[6];
	for(int i = 0;i < 6;i++)cin >> a[i];
	for(int i = 0;i < 6;i++)cin >> b[i];
	
	if(func(a, b))cout << "Yes" << endl;
	else cout << "No" << endl;
	
	return 0;
}

Measured memory_bytes: 3100
#include <iostream>
#include <stdio.h>
#include <vector>
#include <algorithm>
#include <cmath>
#define rep(i,cc,n) for(int i=cc;i<=n;++i)
#define drep(i,cc,n) for(int i=cc;i>=n;--i)
typedef long long ll;
using namespace std;
int main(){
    ll n;
    int k;
    cin>>n>>k;
    int h[n];
    ll cnt = 0;
    rep(i,0,n-1){
        cin>>h[i];
        if(h[i]>=k) cnt++;
    }
    cout<<cnt<<endl;
    return 0;
}

Measured memory_bytes: 640
import java.util.*;
public class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    int n = sc.nextInt();
    int k = sc.nextInt();
    int compare = k;
    int count = 1;
    while(compare <= n){
      compare *= k;
      count++;
    }
    System.out.println(count);
  }
}


Measured memory_bytes: 21844
//
//  main.cpp
//  HelloWorld
//
//  Created by purple on 2020/04/13.
//  Copyright © 2020 Purple. All rights reserved.
//

#include <iostream>
#include <algorithm>
#include <string>
#include <fstream>

using namespace std;

int main(int argc, const char * argv[]) {
    // insert code here...

    
    int n;
    cin >> n;
    int a[n-1];
    
    for(int i=0; i< n-1; i++)  cin >> a[i];
    
    int ans[n];
    for(int i=0; i< n; i++)  ans[i] = 0;
    
    int tmp = 0;
    for (int i=0; i<n-1; i++){
        tmp = a[i] ;
        ans[tmp]++;
    }
    
    for(int i=1; i<n; i++)
        cout << ans[i] << endl;
    cout << 0 << endl;
    
    
    return 0;
    
}


Measured memory_bytes: 5144
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <queue>
#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;

typedef long long ll;
typedef unsigned long long ull;

static const double EPS = 1e-8;
static const double PI = 4.0 * atan(1.0);
static const double PI2 = 8.0 * atan(1.0);

#define REP(i,n)	for(int i=0;i<(int)n;++i)
#define ALL(c)		(c).begin(),(c).end()
#define CLEAR(v)	memset(v,0,sizeof(v))
#define MP(a,b)		make_pair((a),(b))
#define ABS(a)		((a)>0?(a):-(a))
#define FOR(i,s,n)	for(int i=s;i<(int)n;++i)

int N, K, D;
bool d[10];

int main(int argc, char **argv) {
	cin >> N >> K;
	CLEAR(d);
	REP(i, K) {
		cin >> D;
		d[D] = true;
	}
	int res = N;
	while (true) {
		bool f = true;
		int t = res;
		for (; t > 0; t /= 10) f &= !d[t % 10];
		if (f) break;
		++res;
	}
	cout << res << endl;
	return 0;
}


Measured memory_bytes: 256
/* 
	Author: ankrypt
*/

#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

using namespace std;
using namespace __gnu_pbds;
template<class T> using oset=tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

#define MOD 1000000007
#define ll long long int
#define u64 unsigned long long int
#define ff first
#define ss second
#define all(x) x.begin(), x.end() 
#define ub upper_bound
#define lb lower_bound
#define MAX_INT 15
#define fi(a, b, c, d) for(int a = b; a < c; a += d)
#define fl(a, b, c, d) for(ll a = b; a < c; a += d)
#define fei(a, b, c, d) for(int a = b; a <= c; a += d)
#define fel(a, b, c, d) for(ll a = b; a <= c; a += d)
#define quit exit(0)

ll N, M, A, B, C;
ll arr[MAX_INT], arr1[MAX_INT], data[MAX_INT];
vector<ll> V;

int main() {
	scanf("%lld", &N);
	ll sum = 0;
	fei(i, 1, N, 1) {
		fei(j, 1, N, 1) {
			fei(k, 1, N, 1) {
				sum += __gcd(i, __gcd(j, k));
			}
		}
	}	
	printf("%lld", sum);
	return 0;
}
/*
	Powered by Buggy Plugin
*/




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

int main() {
  long long N;
  cin>>N;
  long long i=1;
  long long ans=0;
  while(pow(5,i)<=N){
    long long z=pow(5,i);
    ans+=N/(z*2);
    i++;
  }
  if(N%2==0) cout<<ans<<endl;
  else cout<<0<<endl;
}

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

template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }

using ll = long long;

const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
const ll INF = 1LL<<60;
const ll mod = 1000000007LL;


int main() {
  ll N;
  cin>>N;
  vector<ll> a(N),b(N);
  for(ll i = 0LL; i < N; i++) scanf("%lld",&a[i]);
  for(ll i = 0LL; i < N; i++) scanf("%lld",&b[i]);
  queue<ll> c,d;
  map<ll,ll> mc,md;
  for(ll i = 0LL; i < N-1LL; i++){
    ll A = a[i]^a[i+1];
    ll B = b[i]^b[i+1];
    c.push(A);
    d.push(B);
    mc[A]++;
    md[B]++;
  }
  c.push(a[N-1]^a[0]);
  d.push(b[N-1]^b[0]);
  mc[a[N-1]^a[0]]++;
  md[b[N-1]^b[0]]++;
  ll cnt = 0LL;
  ll start=INF, goal=INF;
  bool can = true;
  if(mc!=md) can=false;
  if(can){
    for(ll i = 0LL; (i < N&&cnt<2); i++){
      if(c==d&&cnt<2){
        if(cnt==0) start = i;
        if(cnt==1) goal=i;
        cnt++;
      }
      c.push(c.front());
      c.pop();
    }
    ll t = start;
    while(t<N){
      printf("%lld %lld\n",t,(a[t]^b[0]));
      t+=(goal-start);
    }
  }
}


Measured memory_bytes: 29952
#include<bits/stdc++.h>
using namespace std;
#define arep(i,x,n) for(long long i=int(x);i<(int)(n);i++)
#define rep(i,n) for(long long i = 0;i < n;++i)
#define rrep(i,n) for(long long i=int(n);i>0;i--)
#define fs first
#define sc second
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define pi 3.141592653589793
#define eps 0.00000001
#define INF 1e9+5  
using ll = long long; 
using P=pair<int,int>;
using lP=pair<ll,ll>;
using fP=pair<double,double>;
using PPI=pair<P,int>;
//ll const mod=998244353;
ll const mod=1e9+7;
const ll MAX=1000005;
using vi=vector<int>;
using vl=vector<ll>;
using vc=vector<char>;
using vd=vector<double>;
using vs=vector<string>;
using vp=vector<P>;
using vb=vector<bool>;
using vvi =vector<vector<int>>;
using vvl =vector<vector<ll>>;
using vvd=vector<vector<double>>;
using vvc=vector<vector<char>>;
using vvp =vector<vector<P>>;
using vvb=vector<vector<bool>>;
template <typename T>
bool chmax(T &a, const T b){if(a < b){a = b; return true;} return false;}
template <typename T>
bool chmin(T &a, const T b){if(a > b){a = b; return true;} return false;}


int main(){
    int n;
    cin>>n;
    int a=0;
    int tmp=n;
    while(tmp>0){
        a+=tmp%10;
        tmp/=10;
    }
    if(n%a==0)cout<<"Yes"<<endl;
    else cout<<"No"<<endl;
    return 0;
}

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

#define REP(i, x, n) for (int i = x; i < (int)(n); i++)
#define rep(i, n) REP(i, 0, n)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define sz(x) (int)(x.size())
#define popcount(x) __builtin_popcount(x)
#define popcountll(x) __builtin_popcountll(x)
#define uniq(x) x.erase(unique(x.begin(), x.end()), x.end())
#define F first
#define S second
#define mp make_pair
#define eb emplace_back
#define pii pair<int, int>
#define pll pair<ll, ll>

using namespace std;

typedef long long ll;

/* --- INFやMODの値が適切か確認する --- */
// const int INF = 1 << 30;
// const ll INF = 1LL << 60;
// const ll MOD = 1000000007;

int main() {
  ll n;
  cin >> n;
  if (n % 2)
    cout << "0" << endl;
  else {
    ll ans = 0;
    ll v = 5;
    while (v <= n) {
      ans += n / v / 2;
      v *= 5;
    }
    cout << ans << endl;
  }
}


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

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

    int n,m;
    cin>>n>>m;
    int x[n];
    for(int i=0;i<n;i++){
        cin>>x[i];
    }
    sort(x,x+n);
    vector<int> a[m]={};
    for(int i=0;i<n;i++){
        a[x[i]%m].push_back(x[i]);
    }
    ll ans=a[0].size()/2;
    for(int i=1;i<=m/2;i++){
        int b;
        if(i!=m-i) b=min(a[i].size(),a[m-i].size());
        else b = a[i].size()/2;
        ans += b;
        if(i==m-i) b*=2;
        if(a[i].size()-b){
            int c=a[i].size()-b;
            int j=1;
            while(j<a[i].size() && c>1){
                if(a[i][j] == a[i][j-1]){
                    ans++;
                    j+=2;
                    c-=2;
                }
                else j++;
            }
        }
        if(i!=m-i && a[m-i].size()-b){
            int c=a[m-i].size()-b;
            int j=1;
            while(j<a[m-i].size() && c>1){
                if(a[m-i][j] == a[m-i][j-1]){
                    ans++;
                    j+=2;
                    c-=2;
                }
                else j++;
            }
        }
        cerr<<i<<" "<<ans<<endl;
    }
    cout<<ans<<endl;

    
}

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

using namespace std;

int n,c,k,T[200000],ans;

int main()
{
	scanf("%d%d%d",&n,&c,&k);
	for(int i=1;i<=n;i++)
		scanf("%d",&T[i]);
	sort(T+1,T+1+n);
	int tot=1,tmp=T[1];
	for(int i=2;i<=n;i++)
	{
		if(T[i]>tmp+k)
		{
			ans++; tmp=T[i]; tot=0;
		}
		if(tot>=c)
		{
			ans++; tmp=T[i]; tot=0;
		}
		tot++;
	}
	cout<<ans+1<<endl;
}

Measured memory_bytes: 640
import java.util.Scanner;

public class Main {

	public static long gcd(long a, long b) {
		long n = a % b;
		if(n == 0) {
			return(b);
		}
		return gcd(b, n);
	}

	public static long lcm(long a, long b) {
		long g = gcd(a, b);
		return(a / g * b);
	}

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		long ans = 1;

		for(int i = 0; i < N; i++) {
			long T = sc.nextLong();
			ans = lcm(T, ans);
		}

		System.out.println(ans);
		sc.close();
	}
}


Measured memory_bytes: 21972
from sys import stdin
N = int(input())
A= [int(x) for x in stdin.readline().rstrip().split()]

mindif = 2020202020*200000
right = sum(A)
left = 0

for i in range(N):
    right -= A[i]
    left += A[i]
    if mindif > abs(right-left):
        mindif =  abs(right-left)

print(mindif)


Measured memory_bytes: 80932
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace みんプロ
{
    class C
    {
        static ulong[] kab;
        static void Main(string[] args)
        {
            kab = Console.ReadLine().Split().Select(ulong.Parse).ToArray();
            ulong ans = 0;
            if (kab[1] >= kab[2] - 1 || kab[0] <= kab[1]) { ans = kab[0] + 1; }
            else
            {
                if ((kab[0] - kab[1] - 1) % 2 == 0)
                {
                    ans = kab[2];
                    ans += (kab[2] - kab[1]) * ((kab[0] - kab[1] - 1) / 2);
                    /*for (int i = 0; i < kab[0] - kab[1] - 1; i+=2)
                    {
                        ans += kab[2] - kab[1];
                    }*/
                }
                else
                {
                    ans = kab[2];
                    ans += (kab[2] - kab[1]) * ((kab[0] - kab[1] - 2) / 2);
                    ans++;
                    /*for (int i = 0; i < kab[0] - kab[1] - 3; i+=2)
                    {
                        ans += kab[2] - kab[1];
                    }
                    ans++;*/
                }
            }
            Console.WriteLine(ans);
        }
    }
}


Measured memory_bytes: 13396
#include <stdio.h>
#define MAX_N 100001

int p[MAX_N];

int main(void)
{
    int n;
    scanf("%d", &n);
    for (int i = 1; i <= n; i++)
        scanf("%d", &p[i]);
    int cnt = 0;
    for (int i = 1; i <= n; i++) {
        if (p[i] == i) {
            cnt++;
            if (i < n && p[i + 1] == i + 1) i++;
        }
    }
    printf("%d\n", cnt);
    return 0;
}

Measured memory_bytes: 512
#pragma GCC optimize("O3")
#include <bits/stdc++.h>
#define ll long long
#define rep(i,n) for(ll i=0;i<(n);i++)
#define pll pair<ll,ll>
#define pii pair<int,int>
#define pq priority_queue
#define pb push_back
#define eb emplace_back
#define fi first
#define se second
#define endl '\n'
#define ios ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0);
#define lb(c,x) distance(c.begin(),lower_bound(all(c),x))
#define ub(c,x) distance(c.begin(),upper_bound(all(c),x))

using namespace std;


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

const ll INF=1e9+7;


int main(){
    ll n;
    cin >> n;
    vector<ll> a(3*n);
    rep(i,3*n){
        cin >> a[i];
    }
    ll ans=0;
    sort(a.begin(),a.end());
    for(ll i=3*n-2;i>=n;i-=2){
        ans+=a[i];
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 5644
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <map>
#include <sstream>
#include <queue>
#include <deque>
#define ll long long
#define MP make_pair
#define PII pair<int, int>
#define F first
#define S second
using namespace std;
int n;
ll a[100010];
int t=0;
ll res=0;
ll mn=1e18;
int main()
{
	cin >>n;
	for (int i=0;i<n;i++)
	{
		cin >>a[i];
		res+=abs(a[i]);
		mn=min(abs(a[i]),mn);
		if (a[i]<0) t++;
	}
	if (t%2) cout <<res-2*mn;
	else cout <<res;
	return 0;
}

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

struct Card
{
    char suit;
    int value;
};

int main()
{
    int N;
    cin >> N;
    Card card[N];
    Card card2[N];

    for (int i = 0; i < N; i++)
    {
        cin >> card[i].suit >> card[i].value;
    }

    for (int i = 0; i < N; i++)
    {
        card2[i] = card[i];
    }

    // BubbleSort
    bool flag = true;
    for (int sortIndex = 0; flag; sortIndex++)
    {
        flag = false;
        for (int i = N - 1; i > sortIndex; i--)
        {
            if (card[i - 1].value > card[i].value)
            {
                swap(card[i - 1], card[i]);
                flag = true;
            }
        }
    }

    // Selection Sort
    for (int i = 0; i < N; i++)
    {
        int minIndex = i;
        for (int j = i + 1; j < N; j++)
        {
            if (card2[j].value < card2[minIndex].value)
            {
                minIndex = j;
            }
        }
        if (minIndex != i)
        {
            swap(card2[minIndex], card2[i]);
        }
    }

    // Judge slection sort result stabel?
    bool isStable = true;
    for (int i = 0; i < N; i++)
    {
        if (card[i].suit != card2[i].suit)
        {
            isStable = false;
            break;
        }
    }

    // print bubble sort
    for (int i = 0; i < N; i++)
    {
        if (i > 0)
            cout << " ";
        cout << card[i].suit << card[i].value;
    }
    cout << endl;
    cout << "Stable" << endl;

    // print selection sort
    for (int i = 0; i < N; i++)
    {
        if (i > 0)
            cout << " ";
        cout << card2[i].suit << card2[i].value;
    }
    cout << endl;
    if (isStable)
    {
        cout << "Stable" << endl;
    }
    else
    {
        cout << "Not stable" << endl;
    }
}



Measured memory_bytes: 3116
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
#define rep(i,n) for(ll i=0;i<(n);i++)
char maze[20][20];
bool reached[20][20];
ll w,h;
void search(ll x,ll y){
  if(x<0 || w<=x || y<0 || h<=y) return;
  if(maze[y][x]=='#') return;
  if(reached[y][x]) return;
  reached[y][x]=true;
  search(x-1,y);
  search(x+1,y);
  search(x,y-1);
  search(x,y+1);
}
int main(){
  while(1){
    cin>>w>>h;
    if(w==0 && h==0) break;
    rep(i,h) rep(j,w) reached[i][j]=false;
    ll sx,sy;
    rep(i,h) rep(j,w) cin>>maze[i][j];
    rep(i,h) rep(j,w){
      if(maze[i][j]=='@'){
        sx=j;
        sy=i;
      }
    }
    search(sx,sy);
    ll ans=0;
    rep(i,h) rep(j,w) if(reached[i][j]) ans++;
    cout<<ans<<endl;
  }
}


Measured memory_bytes: 3100
import java.util.*;

class Main{
    public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
			int a = sc.nextInt();
			int b = sc.nextInt();
			if(a < b) System.out.println("a < b");
			else if(a > b) System.out.println("a > b");
			else System.out.println("a == b");
    }
}


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

#define rep(i,j,n) for(int i=(j);i<(n);i++)
#define erep(i,j,n) for(int i=(j);i<=(n);i++)
#define all(i) i.begin(),i.end()
#define rall(i) i.rbegin(),i.rend()
#define INF 1e9
const int mod = 1e9+7;

typedef vector<int> vi;
typedef vector<string> vs;
typedef vector<vi> vvi;
typedef pair<int, int> pi;
typedef long long i64;

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

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

  int ans = 0;
  bool b = (a[0] <= a[1]);
  rep(i, 1, n) {
    if((b && a[i - 1] <= a[i]) || (!b && a[i - 1] >= a[i])) {
      continue;
    }

    ans++;
    i++;
    while(i < n && a[i - 1] == a[i]) i++;
    b = (a[i - 1] < a[i]);
  }
  cout << ans + 1 << endl;
}


Measured memory_bytes: 640
#include <stdio.h>

int main() {
    int a,b,c,i, divisors;

    scanf("%d %d %d", &a, &b, &c);

    for (i = a; i <= b; i++) {
        if (c % i == 0)
            divisors++;
    }

    printf("%d\n", divisors);

    return 0;
}


Measured memory_bytes: 1832
N = int(input())
# F[y][x]: y行目、x文字目
F = [list(map(int, input().split())) for _ in range(N)]
# P[y][x]: y行目、x文字目
P = [list(map(int, input().split())) for _ in range(N)]

max_num = -10000001 * 1000
sum = 0

for i in range(1024):
    if i == 0:
        continue
    b = bin(i)
    for n in range(N):
        f = F[n]
        s = ""
        for _n in range(10):
            s += str(f[_n])
        s = "0b" + s
        and_num = int(b, 0) & int(s, 0)
        match_nums = list(format(and_num, 'b'))
        match_num = 0
        for _n in match_nums:
            if int(_n) == 1:
                match_num += 1
        sum += P[n][match_num]
    if sum > max_num:
        max_num = sum
    sum = 0
print(max_num)


Measured memory_bytes: 3064
#include <stdio.h>
#include <stdlib.h>
#include <stdbool.h>
#include <string.h>
#include <math.h>
#define Max(a, b) ((a) > (b) ? (a) : (b))
#define Min(a, b) ((a) > (b) ? (b) : (a))
#define REP(i, n) for(int i = 0; i < n; i++)
typedef long long ll;

struct katana { int id, x; };

int sort(const void *a, const void *b){
  struct katana *A = (struct katana *)a, *B = (struct katana *)b;
  return A->x - B->x;
}

int
main(int argc, char *argv[])
{
  int n, h; struct katana k[200000];
  scanf("%d %d", &n, &h);
  for(int i = 0; i < n; i++){
    scanf("%d %d", &(k[2 * i].x), &(k[2 * i + 1].x));
    k[2 * i].id = 0; k[2 * i + 1].id = 1;
  }

  qsort(k, 2 * n, sizeof(struct katana), sort);

  int j = 2 * n - 1; int ans = 0;
  while(h > 0){
    if(k[j].id == 1){
      h -= k[j].x;
      ans++;
    }else{
      ans += (h - 1) / k[j].x + 1;
      break;
    }
    j--;
  }

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

  return 0;
}
  


Measured memory_bytes: 3324
#include <bits/stdc++.h>
#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 rep2(i,j,n) for(int j=i;j<n;j++)
#define rep3(i,j,n) for(int j=i;j<=n;j++)
#define rrep(i,n) for(int i=n-1;i>=0;i--)
#define sp(n) cout << fixed << setprecision(n)
typedef long long ll;
using namespace std;
int main(void){
    int n;cin>>n;
    vector<vector<int>> a(n);
    rep(i,n-1){
        int y=i+1;
        int x;cin>>x;x--;
        a[x].push_back(y);
    }
    rep(i,n){
        cout<<a[i].size()<<endl;
        //rep(j,a[i].size())cout<<a[i][j]<<" ";
        cout<<endl;
    }
}


Measured memory_bytes: 13992
//
/*==========================================================*/
/*    Template ver 2017-0720    |    Created by JollyBee    */
/* DOMINUS pascit me, et nihil mihi deerit (Psalmorum 23:1) */
/*==========================================================*/
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef vector<pii> vii;
const double EPS=(double)1e-9;
const double PI=(double)acos(-1.0);
#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define pob pop_back
#define pf push_front
#define pof pop_front
#define FOR(i,n) for(int i=0;i<n;i++)
#define REPP(i,l,r,c) for(int i=l;i<=r;i+=c)
#define REP(i,l,r) REPP(i,l,r,1)
#define FORD(i,n) for(int i=n-1;i>=0;i--)
#define REVV(i,l,r,c) for(int i=l;i>=r;i-=c)
#define REV(i,l,r) REVV(i,l,r,1)
//random
int irand(int lo, int hi){
    return (((double)rand())/(RAND_MAX+1.0)) * (hi-lo+1) + lo;
}
//ll to string
string toString(ll x) {
    stringstream ss;
    ss << x;
    return ss.str();
}
//string to ll
ll toNumber(string S) {
    ll ret;
    sscanf(S.c_str(),"%lld",&ret);
    return ret;
}
// std::fill(start, end, value);
// for(auto it: DS){}

const int INF=(int)2e9;
const ll MOD=(ll)1e9+7;
/*==========================================================*/
/*                     END OF TEMPLATE                      */
/* DOMINUS pascit me, et nihil mihi deerit (Psalmorum 23:1) */
/*==========================================================*/

int main(){
    int n; scanf("%d", &n);
    printf("%d\n", n*n*n);
    return 0;
}


Measured memory_bytes: 256
M1,D1=map(int,input().split())
M2,D2=map(int,input().split())
if M1!=12:
    if M2-M1==1:
        print(1)
    else:
        print(0)
elif M1==12:
    if M2==1:
        print(1)
    else:
        print(0)

Measured memory_bytes: 2940
#include<bits/stdc++.h>
#define ll long long
#define in(x) scanf("%d",&x)
using namespace std;

int main()
{

    int n,i,j,ans=0,cnt;
    string p,q,s;
    cin>>n;
    for(i=0; i<n; i++)
    {
        cin>>s;
        p+=s;
    }
    for(i=0; i<n; i++)
    {
        cin>>s;
        q+=s;
    }
    if(p==q)
        ans=0;
    else if(p<q)
    {
        do
        {
            if(p==q)
                break;
             ans++;
        }
        while(next_permutation(p.begin(),p.end()));
    }
    else
    {
        do
        {
            if(p==q)
                break;
            ans++;
        }
        while(next_permutation(q.begin(),q.end()));
    }
    cout<<ans<<"\n";
    return 0;
}



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

int main() {
  vector<vector<int>> bingo(3, vector<int>(3));
  rep(i,3) rep(j,3) cin >> bingo.at(i).at(j);
  vector<vector<bool>> card(3, vector<bool>(3, false));
  int n;
  cin >> n;
  vector<int> vec(n);
  rep(i,n) cin >> vec.at(i);
  rep(i,n) rep(j,3) rep(k,3) if(bingo.at(j).at(k) == vec.at(i)) card.at(j).at(k) = true;
  bool ans = false;
  rep(i,3) {
    bool ok = true;
    rep(j,3) if(!card.at(i).at(j)) ok = false;
    if(ok) ans = true; 
  }
  rep(i,3) {
    bool ok = true;
    rep(j,3) if(!card.at(j).at(i)) ok = false;
    if(ok) ans = true; 
  }
  bool ok1 = true;
  rep(i,3) {
    if(!card.at(i).at(i)) ok1 = false;
  }
  if(ok1) ans = true;
  bool ok2 = true;
  rep(i,3) {
    if(!card.at(i).at(2-i)) ok2 = false;
  }
  if(ok2) ans = true;
  if(ans) cout << "Yes" << endl;
  else cout << "No" << endl;
}

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

#define rng(i, a, b) for (int i = int(a); i < int(b); i++)
#define rep(i, b) rng(i, 0, b)
#define gnr(i, a, b) for (int i = int(b) - 1; i >= int(a); i--)
#define per(i, b) gnr(i, 0, b)

using namespace std;

using ll = long long;
using P = pair<int, int>;

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


Measured memory_bytes: 3632
#include<iostream>
#include<cstdio>
#define md 1000000007
using namespace std;

int n,i,cl[200005];
long long dp[200005],cnt[200005];

inline char Getchar()
{
    static char buff[1000000],*p,*end=p;
    if(p==end)
      end=buff+fread(p=buff,1,1000000,stdin);
    return *(p++);
}
template<typename T>void read(T &x)
{
    static char rc;static int flag;
    x=0;rc=Getchar();flag=1;
    while(!isdigit(rc))
      flag=(rc=='-'?-1:1),rc=Getchar();
    while(isdigit(rc))
      x=x*10+rc-'0',rc=Getchar();
    x*=flag;
}

void work(int x)
{
	while(cl[x]==cl[x-1])
		x--;
	cnt[cl[x]]=(cnt[cl[x]]+dp[x-1])%md;
}

int main()
{
	read(n);
	for(i=1;i<=n;i++)
		read(cl[i]);
	dp[0]=1;
	for(i=1;i<=n;i++)
	{
		dp[i]=(dp[i-1]+cnt[cl[i]]*(cl[i]!=cl[i-1]))%md;
		if(i!=1&&cl[i]!=cl[i-1])
			work(i-1);
	}
	cout<<dp[n];
	return 0;
}

Measured memory_bytes: 5120
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<functional>
#include<vector>
#include<queue>
#include<stack>
#include<set>
#include<map>
using namespace std;
#define MOD 1000000007
#define f(i,n) for(int i=0;i<(int)(n);i++)
#define N 200000


int main() {
	char a[N];
	f(i, N)a[i] = 0;
	int n, k;
	int x, y, z;
	int s, ans;
	bool v = true;
	ans = 0;
	scanf("%d", &n);
		scanf("%s",a);
	f(i, 10) {
		f(j, 10) {
			f(ii, 10) {
				k = 0;
				f(jj, n) {
					if (k == 0 && a[jj] == ('0' + i))k++;
					else if (k == 1 && a[jj] == ('0' + j))k++;
					else if (k == 2 && a[jj] == ('0' + ii))k++;
					if (k > 2) {
						ans++;
						break;
}
				}
			}
		}
}
	printf("%d\n", ans);


	return 0;
}

Measured memory_bytes: 384
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int N = scanner.nextInt();
        int[] A = new int[N];
        int[] B = new int[N];
        int[] C = new int[N-1];

        for (int i = 0; i < N; i++) A[i] = scanner.nextInt();
        for (int i = 0; i < N; i++) B[i] = scanner.nextInt();
        for (int i = 0; i < N - 1; i++) C[i] = scanner.nextInt();

        int res = B[A[0] - 1];
        for (int i = 1; i < A.length; i++) {
            res += B[A[i] - 1];
            if (A[i] - A[i - 1] == 1) res += C[A[i - 1] - 1];
        }

        System.out.println(res);
    }
}


Measured memory_bytes: 21968
#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;
    cin >> n;
    vector<int> h(n);
    rep(i, n) {
        cin >> h[i];
    }

    int maxv = h[n-1];
    for (int i = n-2; i > 0; i--)
    {
        if (h[i]-1 > maxv) {
            cout << "No" << endl;
            return 0;
        }
        maxv = min(maxv, h[i]);
    }
    cout << "Yes" << endl;
    return 0;
}

Measured memory_bytes: 640
from collections import defaultdict,deque
import sys,heapq,bisect,math,itertools,string,queue,copy,time
import numpy as np
sys.setrecursionlimit(10**8)
INF = float('inf')
mod = 10**9+7
eps = 10**-7
def inp(): return int(sys.stdin.readline())
def inpl(): return list(map(int, sys.stdin.readline().split()))
def inpl_str(): return list(sys.stdin.readline().split())

def pair(n):
    return n*(n-1) // 2

n = inp()
tempcons = 0
ans = 0

Slist = sorted([sorted(input()) for i in range(n)])
for i in range(n-1):
    if Slist[i] == Slist[i+1]:
        tempcons += 1
    else:
        ans += pair(tempcons+1)
        tempcons = 0
ans += pair(tempcons+1)

print(ans)

Measured memory_bytes: 34560
N = int(input())
w = [input() for _ in range(N)]

fl = True
for i in range(1,N):
    if w.count(w[i])>1:
        fl = False
    if w[i-1][-1]==w[i][0]:
        continue
    else:
        fl = False
print('Yes') if fl else print('No')

Measured memory_bytes: 3060
/*
*          Name : chaitanya
*
*     Institute : ANITS,Visakhapatnam
*
*/
#include<cstdio>
#include<iostream>
#include<sstream>
#include<fstream>
#include<iomanip>
#include<algorithm>
#include<cmath>
#include<complex>
#include<cstring>
#include<vector>
#include<list>
#include<queue>
#include<stack>
#include<set>
#include<map>
#include<bitset>
#include<numeric>
#include<limits>
#include<climits>
#include<cfloat>
#include<functional>
#include<iterator>
#include <random>
#define infy  1000000000
#define all(x) begin(x),end(x)
#define ll long long int
#define ff first
#define ss second
#define pb push_back
const ll mod = 1000000007;
#pragma GCC optimization ("O3")
const int N = 1000010;
using namespace std;
vector<string> vec_splitter(string s) {
  s += ',';
  vector<string> res;
  while(!s.empty()) {
    res.push_back(s.substr(0, s.find(',')));
    s = s.substr(s.find(',') + 1);
  }
  return res;
}
void debug_out(
vector<string> __attribute__ ((unused)) args,
__attribute__ ((unused)) int idx, 
__attribute__ ((unused)) int LINE_NUM) { cerr << endl; } 
template <typename Head, typename... Tail>
void debug_out(vector<string> args, int idx, int LINE_NUM, Head H, Tail... T) {
  if(idx > 0) cerr << ", "; else cerr << "Line(" << LINE_NUM << ") ";
  stringstream ss; ss << H;
  cerr << args[idx] << " = " << ss.str();
  debug_out(args, idx + 1, LINE_NUM, T...);
}
#ifndef ONLINE_JUDGE
#define debug(...) debug_out(vec_splitter(#__VA_ARGS__), 0, __LINE__, __VA_ARGS__)
#else
#define debug(...) 42
#endif
ll lcm(ll a,ll b)
{
  return (a*b)/__gcd(a,b);
}
int main()
{
  // int x = -1, y = 10000;
  // double z = 0.2;
  // string s2 = "beginner1010";
  // long long b = 1LL << 60;
    
  // // debug(x, y, z, s, b);
    
  // double aux = 1010.0;
  // string code = "code";
    
  // debug(code + "forces",-aux / 10 * 2.3);
  // freopen("input.txt","r",stdin);
  // freopen("output.txt","w",stdout);
  //ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
  string n;
  cin >> n;
  for (int i = 0; i < n.size(); ++i)
  {
    cout << "x";
  }
  return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<utility>
#include<map>
#include<queue>
#include<set>
#include<bitset>
#include<stdio.h>
#include<deque>
using namespace std;
#define rep(i, n) for(int i = 0; i < n; i++)
typedef long long ll;
 
int main()
{
    ll a, b, c;
    cin >> a >> b >> c;
    if(a+b <= c){
        cout << 0 << " " << 0 << endl;
    }
    else{
        if(a < c){
            c -= a;
            a = 0;
            b -= c;
            cout << a << " " << b << endl;
        }
        else{
            cout << a-c << " " << b << endl;
        }
    }
    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <algorithm>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <vector>
using namespace std;
 
#define clr(x, y) memset(x, y, sizeof(x))
#define forn(i, n) for(int i = 0; i < n; i++)
#define LL long long
const int mod = 1e9 + 7;
const int inf = 1e9;


int main() {
    //freopen("in", "r", stdin);
    int a, b, c;     
    scanf("%d%d%d", &a, &b, &c);
    if(a == b && a != c) puts("Yes");
    else if(a == c && a != b) puts("Yes");
    else if(b == c && b != a) puts("Yes");
    else puts("No");
    return 0;
}

Measured memory_bytes: 256
#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(){
  string s;
  cin>>s;
  vector<ll> a;
  char pre='<';
  ll c=0;
  for(ll i=0;i<s.size();i++){
    if(s[i]==pre){
      c++;
    }
    else{
      a.push_back(c);
      pre = s[i];
      c=1;
    }
  }
  a.push_back(c);

  ll las = s.size();
  las--;
  if(s[las]=='<'){
    a.push_back(0);
  }

  vector<ll> ans;
 


  for(ll i=0;i<a.size();i+=2){
    ll tmp = max(a[i],a[i+1]);
    for(ll j=0;j<a[i];j++){
      ans.push_back(j);
    }
    ans.push_back(tmp);
    for(ll j=0;j<a[i+1]-1;j++){
      ans.push_back(a[i+1]-1-j);
    }
  }

   if(s[las]=='>'){
    ans.push_back(0);
  }
ll tmp1=0;
  for(ll i=0;i<ans.size();i++){
tmp1+=ans[i];
//cout<<ans[i]<<endl;
  }
cout<<tmp1<<endl;

}


Measured memory_bytes: 8312
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Scanner;

class Main {

	static int n;
	static double[] x1, y1, x2, y2;
	static double sx, sy, gx, gy;
	static ArrayList<Integer>[] g;

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int q = sc.nextInt();
		while (q-- > 0) {
			long x0, y0, x1, y1, x2, y2, x3, y3;
			x0 = sc.nextLong();
			y0 = sc.nextLong();
			x1 = sc.nextLong();
			y1 = sc.nextLong();
			x2 = sc.nextLong();
			y2 = sc.nextLong();
			x3 = sc.nextLong();
			y3 = sc.nextLong();
			Point p0 = new Point(x0, y0);
			Point p1 = new Point(x1, y1);
			Point p2 = new Point(x2, y2);
			Point p3 = new Point(x3, y3);
			if (linesIntersect(p0, p1, p2, p3)) {
				System.out.println(1);
			} else {
				System.out.println(0);
			}
		}

	}

	static class Point {
		long x, y;
		int id;

		public Point(long x, long y) {
			this.x = x;
			this.y = y;
		}
	}

	static boolean linesIntersect(Point s1, Point d1, Point s2, Point d2) {
		long prd1 = crossProduct(s1, d1, s1, d2) * crossProduct(s1, d1, s1, s2);
		long prd2 = crossProduct(s2, d2, s2, s1) * crossProduct(s2, d2, s2, d1);
		if (prd1 == 0 && prd2 == 0) {
			if (((s2.x - s1.x) * (s2.x - d1.x) <= 0 && (s2.y - s1.y) * (s2.y - d1.y) <= 0)
					|| ((d2.x - s1.x) * (d2.x - d1.x) <= 0 && (d2.y - s1.y) * (d2.y - d1.y) <= 0)
					|| ((s1.x - s2.x) * (s1.x - d2.x) <= 0 && (s1.y - s2.y) * (s1.y - d2.y) <= 0)
					|| ((d1.x - s2.x) * (d1.x - d2.x) <= 0 && (d1.y - s2.y) * (d1.y - d2.y) <= 0)) {
				return true;
			} else
				return false;
		} else
			return prd1 <= 0 && prd2 <= 0;
	}

	static long crossProduct(Point s1, Point d1, Point s2, Point d2) {
		return (d1.x - s1.x) * (d2.y - s2.y) - (d1.y - s1.y) * (d2.x - s2.x);
	}

	static void tr(Object... objects) {
		System.out.println(Arrays.deepToString(objects));
	}
}

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

using namespace std;

int main() {
	int N, L;
	cin >> N >> L;
	vector<string>S(N);

	for (int i = 0; i < N;i++) {
		cin >> S[i];
	}
	sort(S.begin(), S.end());

	for (int i = 0; i < N; i++) {
		cout << S[i];
	}

	cout << endl;
	return 0;
}

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

int main(){
	char s[30];

	scanf("%[^\n]", s);
	int tam = strlen(s);
	for (int i = 0;i < tam;i++) {
		if(s[i] == ','){
			printf(" ");
		}else{
			printf("%c", s[i]);
		}
	}
	puts("");
	return 0;
}


Measured memory_bytes: 128
#include <iostream>
#include <set>
#include <map>

using namespace std;

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

int main(int argc, char* argv[]) {
  long long A, B;
  cin >> A >> B;

  long long n = gcd(A, B);

  map<long long, long long> m;
  for (long long i = 2; i * i < n; ++i) {
    if (n % i == 0) {
      m[i] = 0;
      while (n % i == 0) {
        ++m[i];
        n /= i;
      }
    }
  }
  if (n > 1)
    m[n] = 1;

  long long ret = 1;
  for (map<long long, long long>::iterator i = m.begin(); i != m.end(); ++i) {
    ret += 1;
  }

  cout << ret << endl;

  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstring>
#include <cstdio>
#define maxn 100005

using namespace std;

int a[maxn],b[maxn],A,B,M,x[maxn],y[maxn],c[maxn];

int main()
{
    scanf("%d%d%d",&A,&B,&M);
    for (int i=0;i<A;i++) scanf("%d",&a[i]);
    for (int i=0;i<B;i++) scanf("%d",&b[i]);
    for (int i=0;i<M;i++) scanf("%d%d%d",&x[i],&y[i],&c[i]);

    int mina=0x7fffffff,minb=0x7fffffff;
    for (int i=0;i<A;i++) mina=min(mina,a[i]);
    for (int i=0;i<B;i++) minb=min(minb,b[i]);
    int ans=mina+minb;
    for (int i=0;i<M;i++) ans=min(a[x[i]-1]+b[y[i]-1]-c[i],ans);
    printf("%d\n",ans);
    return 0;
}


Measured memory_bytes: 2176
#include<iostream>
#include<string>
using namespace std;
int main()
{
  string s;
  cin >> s;
  if(s=="Sunny")
    cout << "Cloudy" << endl;
  else if(s=="Cloudy")
    cout << "Rainy" << endl;
  else
    cout << "Sunny" << endl;
  return 0;
}


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

int main(){
  int x,a,b;
  cin>>x>>a>>b;
  if(abs(x-a)>abs(x-b)){
    cout<<"B"<<endl;
  }else{
    cout<<"A"<<endl;
  }
  return 0;
}

Measured memory_bytes: 3572
import sys,collections as cl,bisect as bs
sys.setrecursionlimit(100000)
input = sys.stdin.readline
mod = 10**9+7
Max = sys.maxsize
def l(): #intのlist
    return list(map(int,input().split()))
def m(): #複数文字
    return map(int,input().split())
def onem(): #Nとかの取得
    return int(input())
def s(x): #圧縮
    a = []
    aa = x[0]
    su = 1
    for i in range(len(x)-1):
        if aa != x[i+1]:
            a.append([aa,su])
            aa = x[i+1]
            su = 1
        else:
            su += 1
    a.append([aa,su])
    return a
def jo(x): #listをスペースごとに分ける
    return " ".join(map(str,x))
def max2(x): #他のときもどうように作成可能
    return max(map(max,x))
def In(x,a): #aがリスト(sorted)
    k = bs.bisect_left(a,x)
    if k != len(a) and a[k] ==  x:
        return True
    else:
        return False
"""
def nibu(x,n,r):
    ll = 0
    rr = r
    while True:
        mid = (ll+rr)//2

    if rr == mid:
        return ll
    if (ここに評価入れる):
        rr = mid
    else:
        ll = mid+1
"""


x,y = m()

if x % y == 0:
    print(-1)
else:
    print(x)

Measured memory_bytes: 38676
/* ITP1_6_C */
#include <stdio.h>

#define FLOOR 3
#define ROOM 10

/* ?????????????????¢??° */
void init_array(short array[FLOOR][ROOM])
{
	int ii, jj;
	
	for( ii = 0; ii < FLOOR; ii++ )
	{
		for( jj = 0; jj < ROOM; jj++ )
		{
			array[ii][jj] = 0;
		}
	}
}

/* ??\?±??????°????¨???? */
void set_occupants(short array[FLOOR][ROOM], short f, short r, short v)
{
	short floor_index = f - 1;
	short room_index = r - 1;
	array[floor_index][room_index] += v;
}

/* ?????¢??¨?????¢??° */
void print(short array[FLOOR][ROOM])
{
	short ii, jj;
	for( ii = 0; ii < FLOOR; ii++ )
	{
		for( jj = 0; jj < ROOM; jj++ )
		{
			printf(" %hd", array[ii][jj]);
		}
		printf("\n");
	}
}

/* #?¨????20?????¨???????¨?????????¨???*/
void print_pound_line()
{
	printf("####################\n");
}

/* ???????????¢??° */
int main(void)
{
	// ??¬???1?????±
	short residence1[FLOOR][ROOM];
	init_array(residence1);
	
	// ??¬???2?????±
	short residence2[FLOOR][ROOM];
	init_array(residence2);
	
	// ??¬???3?????±
	short residence3[FLOOR][ROOM];
	init_array(residence3);
	
	// ??¬???4?????±
	short residence4[FLOOR][ROOM];
	init_array(residence4);
	
	// ?????±??°?????????
	short n = 0;
	scanf("%hd\n", &n);
	
	short ii;
	
	// ?????±??°????????\????????????
	short b = 0, f = 0, r = 0, v = 0;
	for( ii = 0; ii < n; ii++ )
	{
		scanf("%hd", &b);
		scanf("%hd", &f);
		scanf("%hd", &r);
		scanf("%hd", &v);
		
		switch( b )
		{
		case 1:	// ??¬???1?????\?±??????°?????±????¨????
			set_occupants(residence1, f, r, v);
			break;
		case 2:	// ??¬???2?????\?±??????°?????±????¨????
			set_occupants(residence2, f, r, v);
			break;
		case 3:	// ??¬???3?????\?±??????°?????±????¨????
			set_occupants(residence3, f, r, v);
			break;
		case 4:	// ??¬???4?????\?±??????°?????±????¨????
			set_occupants(residence4, f, r, v);
			break;
		default:
			break;
		}
	}
	
	// ?????±?????¨????????????
	print(residence1);
	print_pound_line();
	
	print(residence2);
	print_pound_line();
	
	print(residence3);
	print_pound_line();
	
	print(residence4);
	
	return 0;
}

Measured memory_bytes: 612
N = int(input())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
C = list(map(int, input().split()))
ans = 0
ans += sum(B)
for i in range(N-1):
    if A[i]+1 == A[i+1]:
        ans += C[A[i]-1]
print(ans)

Measured memory_bytes: 3064
#include<iostream>
#include<algorithm>
#include<string>
#include<vector>
#include<cmath>
#include<map>
#include<iomanip>
#include<queue>
#include<stack>
#include<time.h>
#define rep(i,n)for(ll i=0;i<n;i++)
#define ll long long
#define ggr getchar();getchar();return 0;
#define prique priority_queue
#define inf 1145141919364364
#define double long double
using namespace std;
typedef pair<ll, ll>P;
bool prime(int n) {
	int cnt = 0;
	for (int i = 1; i <= sqrt(n); i++) {
		if (n % i == 0)cnt++;
	}
	if (cnt != 1)return false;
	else return n != 1;
}
ll gcd(ll x, ll y) {
	if (y == 0)return x;
	return gcd(y, x % y);
}
ll lcm(ll x, ll y) {
	return x * y / gcd(x, y);
}
map<ll, ll>mp;
signed main() {
	ll a, b, ans = 0;
	cin >> a >> b;
	ll l = gcd(a, b);
	for (ll i = 2; i * i <= l; i++) {
		while (l % i == 0) {
			mp[i]++;
			l /= i;
		}
	}
	if (l != 1)mp[l] = 1;
	for (auto x : mp) {
		if (x.second)ans++;
	}
	cout << ans + 1 << endl;
	ggr
}

Measured memory_bytes: 256
#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 <cmath>
#include <limits>
using namespace std;
#define rep(i, n) for (int i = 0; i < (n); i++)
#define mod 1000000007
#define fst first
#define pb push_back
// ABC146B first AC
int main()
{
    string s, s2;
    cin  >> s;
    reverse(s.begin(), s.end());
    for(int i = 0; i < s.size(); i++){
        //sの逆を作る
        s2[i] = s[i];
    }
    //sの並びを戻す。
    reverse(s.begin(),s.end());
    //差異のカウント(つまりハグ)
    int diff = 0;
    for(int i = 0; i < s.size(); i++){
            if(s[i] != s2[i]){
                diff++;
            }
      }
      int ans = diff / 2;
      cout << ans << 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 h = sc.nextInt();
		int w = sc.nextInt();
		sc.nextLine();
		char[][] a = new char[h][w];
		for (int i = 0; i < h; i++) {
			a[i] = sc.nextLine().toCharArray();
		}

		int[][] l = new int[h][w];
		int[][] r = new int[h][w];
		int[][] t = new int[h][w];
		int[][] b = new int[h][w];
		for (int i = 0; i < h; i++) {
			int count = 0;
			for (int j = 0; j < w; j++) {
				if (a[i][j] == '#') count = 0;
				else {
					l[i][j] = count++;
				}
			}

			count = 0;
			for (int j = w - 1; j >= 0; j--) {
				if (a[i][j] == '#') count = 0;
				else {
					r[i][j] = count++;
				}
			}
		}

		for (int j = 0; j < w; j++) {
			int count = 0;
			for (int i = 0; i < h; i++) {
				if (a[i][j] == '#') count = 0;
				else t[i][j] = count++;
			}

			count = 0;
			for (int i = h - 1; i >= 0; i--) {
				if (a[i][j] == '#') count = 0;
				else b[i][j] = count++;
			}
		}

		int answer = 0;
		for (int i = 0; i < h; i++) {
			for (int j = 0; j < w; j++) {
				//System.out.print(l[i][j] + r[i][j] + t[i][j] + b[i][j]);
				//System.out.print("  ");
				answer = Math.max(answer, l[i][j] + r[i][j] + t[i][j] + b[i][j] + 1);
			}
			//System.out.println();
		}

		System.out.println(answer);
	}
}


Measured memory_bytes: 123332
#include<iostream>
#include<algorithm>
#include<string>
#include<vector>
#include<fstream>
using namespace std;

int main() {
	string a, b, c;
	cin >> a >> b >> c;
	int x = a.length();
	int y = b.length();
	if (a[x - 1] == b[0] && b[y - 1] == c[0])
	{
		cout << "YES";
	}
	else
	{
		cout << "NO";
	}
}


Measured memory_bytes: 256
import java.util.*;

public class Main{
	public static void main(String args[]){
		Scanner sc = new Scanner(System.in);
		int K = sc.nextInt();
		int N = sc.nextInt();
		int a[] = new int[N + 1];
		for(int i = 0; i < N; i++){
			a[i] = sc.nextInt();
		}
		a[N] = K + a[0];
		
		Arrays.sort(a);
		int max = Integer.MIN_VALUE;
		for(int i = 0; i < N; i++){
			int dis = a[i + 1] - a[i];
			max = Math.max(max, dis);
		}
		System.out.println(K - max);
		
	}
}

Measured memory_bytes: 64924