akhauriyash/Code-Regression huggingface dataset:
a,b,c,d = map(int,input().split())
e = b - a + 1
ans_ca = a//c
ans_cb = b//c
ans_c = ans_cb - ans_ca
if a%c== 0:
  ans_c += 1
  
ans_da = a//d
ans_db = b//d
ans_d = ans_db - ans_da
if a%d == 0:
  ans_d += 1

x = c
y = d
for i in range(b):
  n = y%x
  if n == 0:
    break
  y = x
  x = n
z = int(c*d/x)
ans_cda = a//z
ans_cdb = b//z
ans_cd = ans_cdb - ans_cda
if a%z== 0:
  ans_cd += 1
  
print(e-(ans_c+ans_d-ans_cd))

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using P = pair<int, int>;
using vi = vector<int>;
using vvi = vector<vector<int>>;
using vll = vector<ll>;
using vvll = vector<vector<ll>>;
const double eps = 1e-10;
const int MOD = 1000000007;
const int INF = 1000000000;
const ll LINF = 1ll<<50;
template<typename T>
void printv(const vector<T>& s) {
  for(int i=0;i<(int)(s.size());++i) {
    cout << s[i];
    if(i == (int)(s.size())-1) cout << endl;
    else cout << " ";
  }
}
int main() {
  cin.tie(0);
  cout << fixed << setprecision(10);
  int n, a, b; cin >> n >> a >> b;
  cout << min(n * a, b) << endl;
}


Measured memory_bytes: 256
#include <cstdio>
#include <algorithm>
using namespace std;
int A[200000];
int main() {
	int N, K;
	scanf("%d %d", &N, &K);
	for (int i = 0; i < N; ++i) scanf("%d", &A[i]);
	int x = 0;
	while (x < K && *min_element(A, A + N) < N) {
      	int psum[N + 1];
		fill_n(psum, N + 1, 0);
		for (int i = 0; i < N; ++i) ++psum[max(0, i - A[i])], --psum[min(N - 1, i + A[i]) + 1];
		for (int i = 1; i < N; ++i) psum[i] += psum[i - 1];
		for (int i = 0; i < N; ++i) A[i] = psum[i];
		++x;
	}
	if (x == K) {
		for (int i = 0; i < N; ++i) printf("%d ", A[i]);
	} else {
		for (int i = 0; i < N; ++i) printf("%d ", N);
	}
	return 0;
}

Measured memory_bytes: 3288
#include<iostream>
using namespace std;
int main()
{
    bool ifnot[101]={false};
    for(int i=1;i<10;i++)
        for(int j=1;j<10;j++)
        ifnot[i*j]=true;
    int N;
    cin>>N;
    if(ifnot[N])cout<<"Yes"<<endl;
    else cout<<"No"<<endl;
}


Measured memory_bytes: 504
#define _USE_MATH_DEFINES
#include <math.h>
#include <stdio.h>

int main(){
int a,b;
double c=0.0;
c=M_PI;
scanf("%lf",&c);
printf("%f %f\n",c*c*M_PI,2*c*M_PI);
return 0;
}


Measured memory_bytes: 2596
/*@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
Code author: Saurabh Singhal
Code copy karne vaale tera muh kaala
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@*/

#include<bits/stdc++.h>
#include<string>
#define mp(a,b) make_pair(a,b)
#define pb push_back
#define ppb pop_back

using namespace std;
typedef long long int ll;
typedef vector<int> vi_t;
typedef vector<ll> vll_t;
int t=1;
bool mycomp(const pair< int,pair<int,int> >&a,const pair< int,pair<int,int> >&b){
	if(a.first==b.first){
		return a.second.first<b.second.first;
	}
	return a.first<b.first;
}
string find(int p,int y){
	string ans1 = std::to_string(p);
	string ans2 = std::to_string(y);
	if(ans1.size()<6){
		reverse(ans1.begin(),ans1.end());
			while(ans1.size()<6){
				ans1+="0";
			}
			reverse(ans1.begin(),ans1.end());
	}
	if(ans2.size()<6){
		reverse(ans2.begin(),ans2.end());
			while(ans2.size()<6){
				ans2+="0";
			}
			reverse(ans2.begin(),ans2.end());
	}
	return ans1+ans2;
}
int  main(){
	// #ifndef ONLINE_JUDGE
 //    // for getting input from input.txt
 //    freopen("input.txt", "r", stdin);
 //    // for writing output to output.txt
 //    freopen("output.txt", "w", stdout);
	// #endif
	int n,m;
	cin>>m>>n;
	vector< pair< int,pair<int,int> > >v;
	for(int i=0;i<n;i++){
		int u,w;
		cin>>u>>w;
		v.pb(mp(u,mp(w,i)));
	}
	sort(v.begin(),v.end(),mycomp);
	vector<string>ans(n);
	int num=1,prev=-1;
	for(int i=0;i<n;i++){
		int p=v[i].first;
		// cout<<v[i].first<<" "<<v[i].second.first<<" "<<v[i].second.second<<endl;
		// cout<<p<<" "<<num<<endl;
		if(p!=prev){
			num=1;
			ans[v[i].second.second]=find(p,num);
		}
		else{
			ans[v[i].second.second]=find(p,num);
		}
		num++;
		prev=p;
	}
	for(int i=0;i<n;i++){
		cout<<ans[i]<<endl;
	}
}

Measured memory_bytes: 8180
#include<stdio.h>
#include<math.h>
int main(){
  double d[8];
  int i;
  while(scanf("%lf",&d[0])!=EOF){
    for(i=1;i<8;i++)scanf("%lf",&d[i]);
    //printf("%f\n",fabs((d[0]-d[2])*(d[4]-d[6])+(d[1]-d[3])*(d[5]-d[7])));
    if(fabs((d[0]-d[2])*(d[4]-d[6])+(d[1]-d[3])*(d[5]-d[7]))<0.000000000001)
      printf("YES\n");
    else printf("NO\n");
  }
  return 0;
}

Measured memory_bytes: 612
import java.util.*;
public 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("Draw");
    }else if (B == 1){
      System.out.println("Bob");
    }else if (A == 1){
      System.out.println("Alice");
    }else if(A < B) {
      System.out.println("Bob");
    }else{
      System.out.println("Alice");
    }
  }
}


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

int main() {
  long S, C;
  cin >> S >> C;
  long s = S;
  long c = C / 2;
  long tmp = min(s, c);
  long ans = 0;
  ans += tmp;
  S -= tmp;
  C -= tmp * 2;
  if (C <= 1) return cout << ans << "\n", 0;
  ans += C / 4;
  cout << ans << "\n";
}

Measured memory_bytes: 3644
#include<bits/stdc++.h>
using namespace std;
int main(){
    string s,t,u;
    cin>>s>>t>>u;
    string ans;
    string S,T,U;
    S = s[0]-'a'+'A';
    T = t[0]-'a'+'A';
    U = u[0]-'a'+'A';
    ans = S+T+U;
    cout<<ans<<endl;
}

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

int main() {
  int A, B;
  cin >> A >> B;
  int C;
  C = A - (A / 500) * 500;
  if (C > B){
  	cout << "No" << endl;
  }
  else {
    cout << "Yes" << endl;
  }
  }

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

int main(){
  int N,K;
  cin  >> N >> K;
  vector<int> exist(N,0);
  for(int i=0;i<K;i++){
    int d;
    cin >> d;
    vector<int> A(d);
    for(int i=0;i<d;i++){
      cin >> A.at(i);
      exist.at(A.at(i)-1)++;
    }
  }
  
  int count=0;
  for(int i=0;i<N;i++){
    if(exist.at(i)==0){
      count++;
    }
  }
  cout << count << endl;
}

Measured memory_bytes: 3604
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <stdbool.h>
#include <math.h>
#include <limits.h>

int main(void){
    int mod=1000000007;
    char s[100020];
    scanf("%s",s);
    long long ans[strlen(s)+1][4];
    ans[strlen(s)][3]=1,ans[strlen(s)][2]=0,ans[strlen(s)][1]=0,ans[strlen(s)][0]=0;
    for (int i=strlen(s)-1; i>=0; i--){
        if (s[i]=='?'){
            ans[i][3]=(ans[i+1][3]*3)%mod;
            ans[i][2]=(ans[i+1][2]*3+ans[i+1][3])%mod;
            ans[i][1]=(ans[i+1][1]*3+ans[i+1][2])%mod;
            ans[i][0]=(ans[i+1][0]*3+ans[i+1][1])%mod;
        } else if (s[i]=='A'){
            ans[i][3]=(ans[i+1][3])%mod;
            ans[i][2]=(ans[i+1][2])%mod;
            ans[i][1]=(ans[i+1][1])%mod;
            ans[i][0]=(ans[i+1][0]+ans[i+1][1])%mod;
        } else if (s[i]=='B'){
            ans[i][3]=(ans[i+1][3])%mod;
            ans[i][2]=(ans[i+1][2])%mod;
            ans[i][1]=(ans[i+1][1]+ans[i+1][2])%mod;
            ans[i][0]=(ans[i+1][0])%mod;
        } else if (s[i]=='C'){
            ans[i][3]=(ans[i+1][3])%mod;
            ans[i][2]=(ans[i+1][2]+ans[i+1][3])%mod;
            ans[i][1]=(ans[i+1][1])%mod;
            ans[i][0]=(ans[i+1][0])%mod;
        }
    }
    printf("%lld\n",ans[0][0]%mod);
	return 0 ;
}


Measured memory_bytes: 3328
#include <iostream>
#include <algorithm>
using namespace std ;
using ll = long long ;

int main(){
    ll a,b,c,x,y ;
    cin >> a >> b >> c >> x >> y ;
    ll ans = 0 ;
    if(a>2*c) a = 2*c ;
    if(b>2*c) b = 2*c ;
    if(a+b>2*c){
        ll z = min(x,y) ;
        ans += 2*c*z ;
        x -= z ;
        y -= z ;
    }
    ans += x*a ;
    ans += y*b ;
    cout << ans << endl ;
}


Measured memory_bytes: 256
using System;
using System.Linq;
using System.Collections.Generic;
class Program
{
    static void Main()
    {
        var nm = Array.ConvertAll(Console.ReadLine().Split(), int.Parse);
        var dic = new Dictionary<int, List<int>>();
        for (int i = 0; i < nm[0]; i++) dic[i] = new List<int>();
        for (int i = 0; i < nm[1]; i++)
        {
            var ab = Array.ConvertAll(Console.ReadLine().Split(), int.Parse).Select(x => x - 1).ToArray();
            dic[ab.Min()].Add(ab.Max());
            dic[ab.Max()].Add(ab.Min());
        }
        bool judge = false;
        for (int i = 0; i < dic[0].Count(); i++)
        {
            for (int j = 0; j < dic[dic[0][i]].Count(); j++)
            {
                if (dic[dic[0][i]][j] == nm[0] - 1) judge = true;
            }
        }
        Console.WriteLine(judge ? "POSSIBLE" : "IMPOSSIBLE");
    }
}

Measured memory_bytes: 43252
using System;
using System.Collections.Generic;
class Program
{
	static void Main(string[] args)
	{
		string[] str = Console.ReadLine().Split();
		int N = int.Parse(str[0]);
		int A = int.Parse(str[1]);
		int B = int.Parse(str[2]);
		int count = 0;
		for(var i=1;i<=N;i++){
			int aa = i/10000 + (i/1000)%10 + (i/100)%10 +(i/10)%10 + i%10;
			if(aa >= A && aa <= B){
				count += i;
			}
		}
		Console.WriteLine(count);
	}
}

Measured memory_bytes: 13140
#include <stdio.h>

int main(void) {
	int x[3];
	int temp = 0;
	scanf("%d %d %d", &x[0], &x[1], &x[2]);
	if(x[0] > x[1]) {
		temp = x[1];
		x[1] = x[0];
		x[0] = temp;
	}
	if(x[1] > x[2]) {
		temp = x[2];
		x[2] = x[1];
		x[1] = temp;
	}
	if(x[0] > x[1]) {
		temp = x[1];
		x[1] = x[0];
		x[0] = temp;
	}
	printf("%d %d %d\n", x[0], x[1], x[2]);
	return 0;
}

Measured memory_bytes: 596
#include<iostream>
#include<cmath>
#include<stdio.h>
#include<string.h>
#include<algorithm>
using namespace std;

int n;
int a[111];

int main()
{
    int i,j,k;

    cin>>n;
    for(i=1;i<=n;i++)
    {
        cin>>a[i];
    }

    int s=0;
    int la=-1;
    for(i=1;i<=n;i++)
    {
        if(la==a[i])
        {
            la=-1;
            s++;
        }
        else
        {
           la=a[i];
        }
    }

    cout<<s<<endl;

    return 0;
}


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

int main()
{
	int dist[100][100];

	int n, m;
	cin >> n >> m;
	vector<bool> edgeuse(m, false);
	vector<int> a(m);
	vector<int> b(m);
	vector<int> c(m);
	for(int i = 0; i< 100;i++) {
		for(int j = 0; j < 100; j++) {
			if(i==j)
				dist[i][j] = 0;
			else 
				dist[i][j] = 999999;
		}
	}
	for(int i = 0; i < m; i++) {
		cin >> a[i] >> b[i] >> c[i];
		a[i]--;b[i]--;
		dist[a[i]][b[i]] = c[i];
		dist[b[i]][a[i]] = c[i];
	}
	for(int k = 0; k < n; k++) {
		for(int i = 0; i < n; i++){
			for(int j =0; j < n; j++){
				dist[i][j] = min(dist[i][j], dist[i][k] + dist[k][j]);
			}
		}
	}
	int count = m;
	for(int i = 0; i< m; i++) {
		bool ok = false;
		for(int j = 0; j < n; j++) {
			if(dist[j][a[i]]+c[i] == dist[j][b[i]]) {
				ok = true;
				break;
			}
		}
		if(ok)
			count--;
	}
	cout << count << endl;
}

Measured memory_bytes: 256
/******************************************
 
******************************************/
#include <bits/stdc++.h>
using namespace std;
#define LL long long
#define N 100005
#define MOD 1000000007
#define dd double
#define rep(i, n) for(int i = 0; i < n; i++)
#define fin for(int i = 0; i < n; i++)

#define Rep(i,a,b) for(int i=a;i<b;i++)
#define Rep1(i,b) for(int i=1;i<=b;i++)
#define pb push_back
#define mp make_pair
#define clr(x) x.clear()
#define sz(x) ((int)(x).size())
#define F first
#define S second
 vector <int> vec[500006] ;   //Vector for maintaining adjacency list explained above
    int level[500006]; //To determine the level of each node
    bool vis[500006]; //Mark the node if visited 
int co[300005]={0};
 int par[150];int size[150]={0};
 


int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
//ios_base& scientific (ios_base& str);
// #ifndef ONLINE_JUDGE
//     freopen("C:\\Users\\shrey\\Documents\\New folder\\input.txt", "r", stdin);
//     freopen("C:\\Users\\shrey\\Documents\\New folder\\output.txt", "w", stdout);
// #endif
   
   string s,t;
   cin>>s>>t;
   int a[s.length()+1][t.length()+1]={0};
   for(int i=0;i<=s.length();i++){
   	a[i][0]=0;
   }
   for(int i=0;i<=t.length();i++){
   	a[0][i]=0;
   }
   for(int i=1;i<=s.length();i++){
   	for(int j=1;j<=t.length();j++){
   		if(s[i-1]==t[j-1]){

   			a[i][j]=a[i-1][j-1]+1;

   		}else {
   			a[i][j]=max(a[i][j-1],a[i-1][j]);
   		}
   	}
   }
   //for(int i=0;i<=s.length();i++){
   //	for(int j=0;j<=t.length();j++){
   //		cout<<a[i][j]<<" ";
   //	}cout<<endl;}
   	int li,lj;li=s.length();lj=t.length();
   	string st="";
   	while(a[li][lj]>0){
   		if(a[li][lj]>a[li-1][lj]&&a[li][lj]>a[li][lj-1]){
   			st+=s[li-1];
   			li-=1;lj-=1;
   		}else if(a[li][lj]==a[li-1][lj]){
   			li-=1;
   		}else if(a[li][lj]==a[li][lj-1]){
   			lj-=1;
   		}
   	}
   	for(int i=0;i<st.length();i++){
   		cout<<st[st.length()-i-1];
   	}cout<<endl;
   	 
return 0;
}


Measured memory_bytes: 48768
#include <stdio.h>
#include <math.h>
#define N 10000

int isprime(int);

int main()
{
  int n=0, i=0, flag=0;

  while(1){
    if(scanf("%d", &n) == EOF) break;
    flag += isprime(n);
  }
  printf("%d\n", flag);

  return 0;
}

int isprime(int x){
  int i;

  if(x == 2) return 1;
  if(x < 2 || x % 2 == 0) return 0;
  i = 3;
  while(i <= sqrt(x)){
    if(x % i == 0) return 0;
    i = i + 2;
  }
  return 1;
}

Measured memory_bytes: 596
import itertools

def sumdiag(board, k):
    if (k >= 0):
        s = 0
        for i in range(len(board) - k):
            s += board[i][i + k]
        return s
    else:
        k = -k
        s = 0
        for i in range(len(board) - k):
            s += board[i + k][i]
        return s
           
def fliplr(board):
    f_board = []
    for i in range(len(board)):
        f_board.append(board[i][::-1])
    return f_board

k = int(input())
qs = []
for _ in range(k):
    qs.append(list(map(int, input().split())))

for queen in itertools.permutations(range(8)):
    flag = 1
    for q in qs:
        if (queen[q[0]] != q[1]):
            flag = 0
    if (flag == 0):
        continue
    board = [[0 for i in range(8)] for j in range(8)]
    for i, qu in enumerate(queen):
        board[i][qu] = 1

    for k in range(-7,8):
        if (sumdiag(board, k=k) > 1):
            flag = 0
    f_board = fliplr(board)
    for k in range(-7, 8):
        if (sumdiag(f_board, k=k) > 1):
            flag = 0
    if (flag == 1):
        for i in range(8):
            for j in range(8):
                if (board[i][j] == 0):
                    print('.', end='')
                else:
                    print('Q', end='')
            print()
        break


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

int N;

vector<int> arr;

vector<vector<int> > cc;

int dp(int idx, int inc) {
    int &ret = cc[idx][inc];
    if(ret != -1) return ret;

    if(idx == N - 1) return ret = 1;

    if(inc) {
        if(arr[idx + 1] >= arr[idx]) return ret = dp(idx + 1, 1);
        else return ret = 1 + min(dp(idx + 1, 0), dp(idx + 1, 1));
    }
    else {
        if(arr[idx + 1] <= arr[idx]) return ret = dp(idx + 1, 0);
        else return ret = 1 + min(dp(idx + 1, 0), dp(idx + 1, 1));
    }
}

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

    arr.resize(N);

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

    cc = vector<vector<int> >(N, vector<int>(2, -1));
    printf("%d", min(dp(0, 0), dp(0, 1)));
}


Measured memory_bytes: 11264
#include <bits/stdc++.h>
#define int long long
#define chmin(x, y) x = min(x, y)
using namespace std;
const int INF = 1e18;

int n, ans;
int a[5010];
vector<int> G[5010];
int dp[5010][5010][2];
int to[5010][2];
int sz[5010];

void dfs(int v, int p){
    sz[v] = 1;
    if(a[v] > 0) dp[v][0][1] = a[v];
    else dp[v][0][0] = a[v];
    for(auto i : G[v]){
        if(i == p) continue;
        dfs(i, v);
        for(int j = 0; j < 5010; j++) to[j][0] = to[j][1] = INF;
        for(int j = 0; j < sz[v]; j++){
            for(int k = 0; k < sz[i]; k++){
                if(dp[i][k][0] < 0 || dp[i][k][1] < INF){
                    chmin(to[j + k + 1][0], dp[v][j][0]);
                    chmin(to[j + k + 1][1], dp[v][j][1]);
                }
                chmin(to[j + k][1], dp[v][j][1] + dp[i][k][1]);
                chmin(to[j + k][0], dp[v][j][0] + dp[i][k][1]);
                chmin(to[j + k][0], dp[v][j][1] + dp[i][k][0]);
                chmin(to[j + k][0], dp[v][j][0] + dp[i][k][0]);
            }
        }
        for(int j = 0; j < 5010; j++){
            dp[v][j][0] = to[j][0];
            dp[v][j][1] = to[j][1];
        }
        sz[v] += sz[i];
    }
}

signed main(){
    cin >> n;
    for(int i = 0; i < n; i++) cin >> a[i];
    for(int i = 0; i < n - 1; i++){
        int u, v;
        cin >> u >> v;
        u--; v--;
        G[u].push_back(v);
        G[v].push_back(u); 
    }
    for(int i = 0; i < 5010; i++) for(int j = 0; j < 5010; j++) dp[i][j][0] = dp[i][j][1] = INF;
    dfs(0, -1);
    for(int i = 0; i < n; i++){
        if(dp[0][i][0] < 0){
            cout << i << endl;
            return 0;
        }
        if(dp[0][i][1] < INF){
            cout << i << endl;
            return 0;
        }
    }
}

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

int main(){

  int N;
  cin >> N;
  vector<string> S(N);
  for(int i=0; i<N; i++){
    cin >> S.at(i);
  }
  
  int M;
  cin >> M;
  vector<string> T(M);
  for(int i=0; i<M; i++){
    cin >> T.at(i);
  }
  
  map<string,int> card;
  for(string x:S){
    if(card.count(x)){
      card.at(x)++;
    }
    else{
      card[x]=1;
    }
  }
  
  for(string x:T){
    if(card.count(x)){
      card.at(x)--;
    }
    else{
      card[x]=-1;
    }
  }
  
  int max_card = 0;
  for(string x:S){
    if(max_card < card.at(x)){
      max_card = card.at(x);
    }
  }

  cout << max_card << endl;
  
}

Measured memory_bytes: 3568
#include <bits/stdc++.h>
#define _GLIBCXX_DEBUG
#define all(x) (x).begin(), (x).end()
using namespace std;

int		main(void)
{
	vector<int> a(3);

	cin >> a[0] >> a[1] >> a[2];
	sort(all(a));
	cout << (a[2] - a[1] + a[1] - a[0]) << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define endl '\n'
#define all(v) (v).begin(),(v).end()
#define int long long
#define P pair<int,int>

signed main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr), cout.tie(nullptr);

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

    int ans = 0;
    ans += n * (n - 1) / 2;
    ans += m * (m - 1) / 2;
    cout << ans << endl;
}

Measured memory_bytes: 256
import java.io.*;
import java.util.*;
class Main{
	static final long MOD = 1_000_000_007; // 10^9+7
    static final int MAX = 2_147_483_646; // intMax 
    static final int INF = 1_000_000_000; // 10^9  
    public static void main(String[] args) throws Exception {
		hayami saori = new hayami();
		int[] n = new int[10];
		for(int i = 0;i < 4;i++){
			int num = saori.saori_hayami();
			n[num]++;
		}
		if(n[1] == 1 && n[4] == 1 && n[9] == 1 && n[7] == 1){
			System.out.println("YES");
		} else {
			System.out.println("NO");
		}
		
		saori.close();
    }
}

class hayami implements Closeable {
	private final InputStream in = System.in;
	private final byte[] hayami = new byte[1024];
	private int Hayami = 0;
	private int saori = 0;
	private boolean HayamiSaori() {
		if (Hayami < saori) {
			return true;
		}else{
			Hayami = 0;
			try {
				saori = in.read(hayami);
			} catch (IOException e) {
				e.printStackTrace();
			}
			if (saori <= 0) {
				return false;
			}
		}
		return true;
	}
	private int SaoriHayami() { 
		if (HayamiSaori()) {
            return hayami[Hayami++];
         }else{
             return -1;
         }
	}
	private static boolean hayami_saori(int hayami) { 
		return 33 <= hayami && hayami <= 126;
	}
	public boolean hayamisaori() { 
		while(HayamiSaori() && !hayami_saori(hayami[Hayami])) Hayami++; return HayamiSaori();
	}
	public String nextHayami() {
		if (!hayamisaori()) throw new NoSuchElementException();
		StringBuilder hayamin = new StringBuilder();
		int saori = SaoriHayami();
		while(hayami_saori(saori)) {
			hayamin.appendCodePoint(saori);
			saori = SaoriHayami();
		}
		return hayamin.toString();
	}
	public long saorihayami() {//nextLong
		if (!hayamisaori()) throw new NoSuchElementException();
		long hayami = 0;
		boolean misao = false;
		int saori = SaoriHayami();
		if (saori == '-') {
			misao = true;
			saori = SaoriHayami();
		}
		if (saori < '0' || '9' < saori) {
			throw new NumberFormatException();
		}
		while(true){
			if ('0' <= saori && saori <= '9') {
				hayami *= 10;
				hayami += saori - '0';
			}else if(saori == -1 || !hayami_saori(saori)){
				return misao ? -hayami : hayami;
			}else{
				throw new NumberFormatException();
			}
			saori = SaoriHayami();
		}
	}
	public int saori_hayami() {//nextInt
		long hayami = saorihayami();
		if (hayami < Integer.MIN_VALUE || hayami > Integer.MAX_VALUE) throw new NumberFormatException();
		return (int) hayami;
	}
	public double Hayamin() { //nextDouble
		return Double.parseDouble(nextHayami());
	}
	public void close() {
		try {
			in.close();
		} catch (IOException e) {
		}
    }
    
}

Measured memory_bytes: 32316
#include <iostream>
#include <algorithm>
#include <cstdio>
#include <cmath>
#include <vector>
#include <map>
#include <set>
#include <string>
#include <stack> // s.top()
#include <bitset>
#include <queue> // s.front()
using namespace std;

typedef long long Int;
typedef pair<Int,Int> P;
#define print(x) cout<<(x)<<endl

#define INF10 10000000000
#define INF5 100000
#define EPS 1e-10
#define MOD 1000000007



int main() {
	char x, y;
	cin >> x >> y;
	if (x < y)print('<'); else if (x > y)print('>'); else print('=');





	return 0;
}

Measured memory_bytes: 256
import Control.Monad
import Data.List

getNums = getLine >>= return . map read . words

solve n ps js = f n (sum ps) (reverse $ sort js)
 where
  f n m [] = n*m
  f n m (j:js) = (n*m) `max` f (n-1) (m+j) js

main = do
 (n:_) <- getNums
 when (n /= 0) $ do
  ps <- getNums
  js <- getNums
  print $ solve n ps js
  main

Measured memory_bytes: 24636
#include <iostream>
#include <vector>
#include <cstring>

using namespace std;
#define f first
#define s second
#define p pair<int,int>
#define P pair<ll,ll>
#define pb push_back
#define ll long long
#define ull unsigned long long
#define db double
#define zero(a) memset(a,0,sizeof(a))
#define inff(a,n) fill(a,a+n+1,inf)
#define all(a) a.begin(),a.end()
#define sz(a) int((a).size())
#define read(x) scanf("%d",&x)
#define read2(x,y) scanf("%d%d",&x,&y)
#define write(x) printf("%d\n",x)


const ll inf = 1e9;

int n, m, cnt, ans, flag = 1, a[1000000];
vector<int>v[1000000];

void dfs(int u, int fa)
{
	for (auto i : v[u])
	{
		if (i == fa)continue;
		if (a[i] == -1)
		{
			a[i] = (a[u] ^ 1);
			dfs(i, u);
		}
		else
		{
			if (a[i] == a[u])flag = 0;
		}
	}
}

int main()
{
	cin >> n >> m;
	for (int i = 0; i<m; i++)
	{
		int x, y;
		cin >> x >> y;
		v[x].pb(y);
		v[y].pb(x);
	}
	memset(a, -1, sizeof(a));
	a[1] = 0;
	dfs(1, 0);
	if (flag)
	{
		for (int i = 1; i <= n; i++)if (a[i])cnt++;
		cout << 1ll * cnt*(n - cnt) - m;
	}
	else
	{
		cout << 1ll * n*(n - 1) / 2 - m;
	}
	return 0;
}

Measured memory_bytes: 31616
#![allow(dead_code)]
fn read<T: std::str::FromStr>() -> T {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().parse().ok().unwrap()
}
fn read_vec<T: std::str::FromStr>() -> Vec<T> {
    read::<String>().split_whitespace()
        .map(|e| e.parse().ok().unwrap()).collect()
}
fn read_vec2<T: std::str::FromStr>(n: usize) -> Vec<Vec<T>> {
    (0..n).map(|_| read_vec()).collect()
}
fn main() {
    let (a, mut b, mut c) = {
        let t: Vec<i32> = read_vec();
        (t[0], t[1], t[2])
    };
    let k: i32 = read();
    for i in 0..k {
        if b <= a { b *= 2; }
        else if c <= b { c *= 2; }
    }
    println!("{}", if a < b && b < c { "Yes" } else { "No" });
}

Measured memory_bytes: 2128
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
using namespace std;

typedef long double ld;									// .
#define int long long
#define PB push_back
#define all(x) (x).begin(),(x).end()
#define ii pair <int,int>
#define mii map <int,int>
#define vi vector<int>
#define vii vector< ii >
#define F first
#define S second
#define rep(i,a,b)  for(int i=a;i<b;i++)
#define repd(i,a,b) for(int i=a; i>=b; --i)
#define sz(x) (int)((x).size())
#define mem(a,x) memset(a,x,sizeof(a))
const long double PI=3.141592653589793238462643383279502884197169399375105820974944;
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_set; // order_of_key // find_by_order()  

inline void io(){
#ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#endif
}

//const int mod = 998244353;
const int mod = 1e9+7;
const int inf = 1e18;
const int maxn = 1e6+5;

vector<int> fact(maxn);
int power(int a,int b) {int res=1;a%=mod; assert(b>=0); for(;b;b>>=1){if(b&1)res=res*a%mod;a=a*a%mod;}return res;}
void pre() {
    fact[0] = 1;
    for(int i = 1; i < maxn; i++) {
        fact[i] = fact[i - 1] * i % mod;
    }
}
int ncr(int n, int r) {
    if(n < r) return 0;
    int p = fact[n];
    int q = fact[r] * fact[n - r] % mod;
    p = p * power(q, mod - 2) % mod;
    return p;
} 
int add(int a, int b){
    return((a % mod + b % mod) % mod);
}
int subs(int a, int b){
    return((a % mod - b % mod + mod) % mod);
}
int mul(int a, int b){
    return(((a % mod) * (b % mod)) % mod);
}
int divi(int a, int b){
    return(mul(a, power(b, mod - 2)) % mod);
}
void solve(){
	int n; cin>>n;
	int ans = 0;
	rep(i, 1, 1000){
		int k = n - 3*i; 
		if(k < 0 ) continue;
		ans = add(ans, ncr(k+i-1, i-1));
	}
	cout<<ans;
}
signed main() 
{
    ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);// io();
    //cout<<setprecision(100);
    pre();
    int tc=1; //cin>>tc;
    while(tc--){
        solve();cout<<'\n';
    }
    return 0;
}


Measured memory_bytes: 11012
#include <iostream>
#include <vector>
#include <algorithm>
#include <queue>
#include <cmath>
#include <functional>
#include <bitset>
#define pb push_back
using namespace std; using ll=long long; using ld=long double; const int INF=1e9; const ll LINF=1e18; const double dINF = 1e18; const ld ldINF = 1e18; const double EPS = 1e-6;
template<typename T, typename U, typename O> void caut(T a, U b, O c){cout<<"("<<a<<","<<b<<","<<c<<") ";}
template<typename T, typename U> void caut(T a, U b){cout<<"("<<a<<","<<b<<") ";}
template<typename T> void caut(T a){cout<<"("<<a<<") ";}
using P=pair<double,int>;
const ll M = 1e9+7;

int main() {
  ll a; cin>>a;
  string s; cin>>s;
  ll an=0;
  an += a*(ll)(s[0]-'0')*100LL;
  an += a*(ll)(s[2]-'0')*10LL;
  an += a*(ll)(s[3]-'0');
  an /= 100;
  cout<<an<<endl;
}

Measured memory_bytes: 3596
n,k=(map(int,input().split()))
p=list(map(int,input().split()))
c=list(map(int,input().split()))
cnt=list(range(n))
ans=-(10**10)
for i in range(n):
    num=[0]
    num11=[]
    num2=p[cnt[0]]-1
    num3=cnt[0]
    cnt.remove(cnt[0])
    for j in range(n+1):
        cnt10=c[num2]
        num.append(num[-1]+cnt10)
        num11.append(cnt10)
        if num2==num3:
            break
        cnt.remove(num2)
        num2=p[num2]-1
    lnum=len(num)-1
    for j in range(lnum):
        num.append(num[-1]+num11[j])
    if num[-1]<0 or k<lnum:
        ans2=-(10**10)
        for j in range(lnum):
            cnt2=num[j]
            num10=0
            for l in range(min(lnum,k)):
                ans2=max(ans2,num[j+l+1]-cnt2)
        ans=max(ans,ans2)
    else:
        ans3=-(10**10)
        ans4=0
        ans5=-(10**10)
        for j in range(lnum):
            cnt2=num[j]
            num10=0
            num14=k%lnum
            for l in range(lnum):
                ans3=max(ans3,num[j+l+1]-cnt2)
                if num14>l:
                    ans5=max(ans5,num[j+l+1]-cnt2)
        ans6=k//lnum
        ans=max(ans,(ans6*num[lnum])+ans5,((ans6-1)*num[lnum])+ans3)
    if len(cnt)==0:
        break
print(ans)


Measured memory_bytes: 69128
#include <cstdio>
#include <algorithm>
using namespace std;
int main(){
    long long x,y,z;
    int k;
    scanf("%lld%lld%lld",&x,&y,&z);
    scanf("%d",&k);
    if(x>y)
        swap(x,y);
    if(x>z)
        swap(x,z);
    if(y>z)
        swap(y,z);
    while(k--){
        z=2*z;
    }
    printf("%lld\n",x+y+z);
    return 0;
}


Measured memory_bytes: 128
from enum import Enum
from queue import Queue
import collections

import sys
import math

BIG_NUM = 2000000000
MOD = 1000000007
EPS = 0.000000001

A,B = map(int,input().split())

if (A+B)%2 == 0:
    print(int((A+B)/2))
else:
    print('IMPOSSIBLE')


Measured memory_bytes: 4208
#include<cmath>
#include<cstdio>
#include<iostream>
using namespace std;
int main()
{
	long long x;
	cin>>x;
	long long a;
	for(a=0;;a++)
	{
		long long temp=pow(a,5)-x;
		long long b;
		if(temp<0) 
		{
			b=pow((double)-temp,0.2);
			if(pow(a,5)+pow(b,5)==x)
			{
				cout<<a<<' '<<-b<<endl;
				return 0;
			}
		}
		else 
		{
			b=pow((double)temp,0.2);
			if(pow(a,5)-pow(b,5)==x)
			{
				cout<<a<<' '<<b<<endl;
				return 0;
			}
		}
		
		
	}
}

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

int main() {
 int n;
  cin >>n;
  int ans=100;
  for (int i=0;i<n;i++){
    int preans=0;
    int a;
    cin >>a;
    while(a%2==0){
      preans++;
      a=a/2;
    }
    if(preans <= ans){
    ans=preans;
    }
  }
  cout << ans << endl;
}



Measured memory_bytes: 256
#0が1を3つ入力
a, b, c = map(int, input())

#aからcそれぞれが1と等しいかどうかを判断し、等しいのであれば順次iに1を足していく
i = 0

#aについて
if a==1:
    i += 1
    
#bについて
if b==1:
    i += 1    

#cについて
if c==1:
    i += 1
    
#出力
print(i)

Measured memory_bytes: 2940
#include <float.h>
#include <limits.h>
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>

// 内部定数
#define D_SIZE_MAX		105										// 最大サイズ

// 内部変数
static FILE *szpFpI;											// 入力
static int siW, siH;											// 幅・高さ
static char sc2Mass[D_SIZE_MAX][D_SIZE_MAX];					// マス
static int si2OCnt[D_SIZE_MAX][D_SIZE_MAX];						// 操作回数

// 内部変数 - テスト用
#ifdef D_TEST
	static int siRes;
	static FILE *szpFpA;
	static int siTNo;
#endif

// １行出力
int
fOutLine(
	char *pcpLine				// <I> １行
)
{
	char lc1Buf[1024];

#ifdef D_TEST
	lc1Buf[0] = '\0';
	fgets(lc1Buf, sizeof(lc1Buf), szpFpA);
	if (strcmp(lc1Buf, pcpLine)) {
		siRes = -1;
	}
#else
	printf("%s", pcpLine);
#endif

	return 0;
}

// 最小値 - 取得
int
fGetMinI(
	int piVal1					// <I> 値１
	, int piVal2				// <I> 値２
)
{
	if (piVal1 < piVal2) {
		return piVal1;
	}
	else {
		return piVal2;
	}
}

// 操作回数 - 取得
int
fGetOCnt(
	int piRow					// <I> 行
	, int piCol					// <I> 列
	, int piARow				// <I> 加算行
	, int piACol				// <I> 加算列
)
{
	// 白 -> 黒
	if (sc2Mass[piRow + piARow][piCol + piACol] == '.') {
		if (sc2Mass[piRow][piCol] == '#') {
			return si2OCnt[piRow + piARow][piCol + piACol] + 1;
		}
	}

	return si2OCnt[piRow + piARow][piCol + piACol];
}

// 実行メイン
int
fMain(
)
{
	int i, j;
	char lc1Buf[1024];

	// データ - 初期化
	memset(si2OCnt, 0, sizeof(si2OCnt));

	// 幅・高さ - 取得
	fgets(lc1Buf, sizeof(lc1Buf), szpFpI);
	sscanf(lc1Buf, "%d%d", &siH, &siW);

	// マス - 取得
	for (i = 0; i < siH; i++) {
		fgets(sc2Mass[i], sizeof(sc2Mass[0]), szpFpI);
	}

	// 操作回数 - 左上
	if (sc2Mass[0][0] == '#') {
		si2OCnt[0][0] = 1;
	}

	// 操作回数 - １行目
	for (i = 1; i < siW; i++) {
		si2OCnt[0][i] = fGetOCnt(0, i, 0, -1);
	}

	// 操作回数 - １列目
	for (i = 1; i < siH; i++) {
		si2OCnt[i][0] = fGetOCnt(i, 0, -1, 0);
	}

	// 操作回数 - ２行目２列目以降
	for (i = 1; i < siH; i++) {
		for (j = 1; j < siW; j++) {
			int liOCnt1 = fGetOCnt(i, j, -1, 0);
			int liOCnt2 = fGetOCnt(i, j, 0, -1);
			si2OCnt[i][j] = fGetMinI(liOCnt1, liOCnt2);
		}
	}

	return si2OCnt[siH - 1][siW - 1];
}

// １回実行
int
fOne(
)
{
	int liRet;
	char lc1Buf[1024];

	// 入力 - セット
#ifdef D_TEST
	sprintf(lc1Buf, ".\\Test\\T%d.txt", siTNo);
	szpFpI = fopen(lc1Buf, "r");
	sprintf(lc1Buf, ".\\Test\\A%d.txt", siTNo);
	szpFpA = fopen(lc1Buf, "r");
	siRes = 0;
#else
	szpFpI = stdin;
#endif

	// 実行メイン
	liRet = fMain();

	// 出力
	sprintf(lc1Buf, "%d\n", liRet);
	fOutLine(lc1Buf);

	// 残データ有無
#ifdef D_TEST
	lc1Buf[0] = '\0';
	fgets(lc1Buf, sizeof(lc1Buf), szpFpA);
	if (strcmp(lc1Buf, "")) {
		siRes = -1;
	}
#endif

	// テストファイルクローズ
#ifdef D_TEST
	fclose(szpFpI);
	fclose(szpFpA);
#endif

	// テスト結果
#ifdef D_TEST
	if (siRes == 0) {
		printf("OK %d\n", siTNo);
	}
	else {
		printf("NG %d\n", siTNo);
	}
#endif

	return 0;
}

// プログラム開始
int
main()
{

#ifdef D_TEST
	int i;
	for (i = D_TEST_SNO; i <= D_TEST_ENO; i++) {
		siTNo = i;
		fOne();
	}
#else
	fOne();
#endif

	return 0;
}



Measured memory_bytes: 1824
#include<stdio.h>
int main(){
  int i,j=1,n,num,count=0,len=1;
  scanf("%d",&n);
  num=n;
  while(num/10>0){
    num/=10;
    len++;
    j*=10;
  }
  int k=1;
  for(i=1;i<len;i=i+2){
    count+=9*k;
    k*=100;
  }
  if(len%2==1)
    count+=n+1-j;
  printf("%d\n",count);
  return 0;
}


Measured memory_bytes: 128
#include<stdio.h>

int main(){
  int S[10000],T[10000];
  int i,j,n,q,count=0;

  scanf("%d",&n);

  for(i=0;i<n;i++)
    scanf("%d",&S[i]);

  scanf("%d",&q);

  for(i=0;i<q;i++)
    scanf("%d",&T[i]);


  for(i=0;i<q;i++){
    for(j=0;j<n;j++){
      if(T[i] == S[j]){
        count++;
        break;
      }
    }
  }
  printf("%d\n",count);
  return 0;
}



Measured memory_bytes: 2048
# Let N be max{r_i} = 10^5.
# time complexity: O(NlglgN + Q)
# space complexity: O(N)

import sys
fin = sys.stdin.readline


def sieve(n):
    is_prime = [True] * (n + 1)
    prime_numbers = []
    is_prime[0] = False
    is_prime[1] = False
    for i in range(2, n + 1):
        if is_prime[i]:
            prime_numbers.append(i)
            for j in range(2 * i, n + 1, i):
                is_prime[j] = False
    return is_prime


Q = int(fin())
N = 10**5
queries = [[int(elem) for elem in fin().split()] for _ in range(Q)]
is_prime = sieve(N)
num_similar_prefix = [0] * (N + 1)
num_similar = 0
for i in range(1, N + 1):
    if is_prime[i] and is_prime[(i + 1) // 2]:
        num_similar += 1
    num_similar_prefix[i] = num_similar

for l, r in queries:
    if l == 0:
        num_similar = num_similar_prefix[r]
    else:
        num_similar = num_similar_prefix[r] - num_similar_prefix[l - 1]
    print(num_similar)


Measured memory_bytes: 66652
N, A, B = list(map(int, input().split()))

ok_nums = []
ok_nums_append = ok_nums.append

for i in range(N+1):
    i_s = str(i)

    if A <= sum(list(map(int, list(i_s)))) <= B:
        ok_nums_append(i)

print(sum(ok_nums))


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

int main() {
  int n;
  cin >> n;
  vector<int> a(n);
  for (auto &e: a) cin >> e;
  reverse(a.begin(), a.end());
  
  ll l=2, r=2;
  for (auto e: a) {

    ll ming = (l+e-1)/e;
    ll maxg = r/e;
    if (maxg < ming) {
      cout << -1 << endl;
      return 0;
    }
    l = ming * e;
    r = maxg * e + e - 1;
  }
  
  cout << l << " " << r << endl;
  
  return 0;
}
  

Measured memory_bytes: 640
#include <stdio.h>
int main(){
	int kai=0,n=0,a=0,b=0,c=0,d=0,point[1001]={0},j,i,saber[1001]={0},acher;
	scanf("%d",&n);
	kai=n*(n-1)/2;
	for(i=0;i<kai;i++){
		scanf("%d%d%d%d",&a,&b,&c,&d);
		if(c>d){
			j=a;
			point[j]=point[j]+3;
		}
		else if(c<d){
			j=b;
			point[j]=point[j]+3;
		}
		else{
			j=a;
			point[j]=point[j]+1;
			j=b;
			point[j]=point[j]+1;
		}
	}
		for(acher=1;acher<=n;acher++){
			saber[acher]=1;
			for(j=1;j<=n;j++){
				if(point[acher]<point[j]){
					saber[acher]=saber[acher]+1;
				}
			}
			printf("%d\n",saber[acher]);
		}
		
	return 0;
}


Measured memory_bytes: 2052
#include<stdio.h>
int main()
{
	int a[20], n, i, A=0;
	scanf("%d", &n);
	for(i = 0; i < n; ++i) {
		scanf("%d", &a[i]);
	}
	for(i = 1; i < n-1; ++i) {
		if(a[i-1] < a[i] && a[i] < a[i+1]) {
			A +=1;
		}
		if(a[i+1] < a[i]  && a[i] < a[i-1]) {
			A +=1;
		}
	}
	printf("%d\n", A);
	return 0;
}

	

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

int main(){
    int n,t;
    cin >> n >> t;
    int c,a;
    int ans=1e9;
    for(int i=0;i<n;i++){
        cin >> c >> a;
        if(a<=t && ans>c)ans=c;
    }
    if(ans<1e9)cout << ans << endl;
    else cout << "TLE" << endl;
}

Measured memory_bytes: 256
#include <cmath>
#include <iomanip>
#include <iostream>

using namespace std;

int main() {
    const double pi = 3.14159265358979323846264338327950288;

    int a, b, h, m;
    cin >> a >> b >> h >> m;

    double x = a * cos(h * pi / 6 + m * pi / 360) - b * cos(m * pi / 30);
    double y = a * sin(h * pi / 6 + m * pi / 360) - b * sin(m * pi / 30);
    cout << setprecision(12) << fixed << sqrt(x * x + y * y) << endl;
}


Measured memory_bytes: 4088
import java.util.Scanner;

public class Main{
	public static void main(String args[]){

		//????????¨?¨???????????????????
		Scanner sc = new Scanner(System.in);
		while(true){
			int intH = sc.nextInt();
			int intW = sc.nextInt();

			//??????H???W???0?????£???????????????????????????
			if((intH == 0) && (intW == 0)){
				break;
			}

			//??????
			//???????????????????????????
			for (int i = 0; i < intH; i++) {
				//String????????£?¨?????????????
				String A = "";
				//?¨?????????????????????????
				for (int j = 0; j < intW; j++) {
					//?????????????????¶??°??§?¨??????¶??°?????£??????
					if ((i % 2 == 0) && (j % 2 == 0)) {
						//String??????A???????????\??????
						A += "#";
					//???????????¶??°??§?¨?????\???°?????£??????
					}else if((i % 2 == 0) && (j % 2 == 1)){
						A += ".";

						//??????????\???°??§?¨??????¶??°?????£??????
					}else if((i % 2 == 1) && (j % 2 == 0)){
						A += ".";
						//??????????¨?????\???°?????£??????
					}else{
						A += "#";
					}
				}
				//?????????????????????
				System.out.println(A);
			}
			//???????????????????????£????????????
			System.out.println("");
		}
	}
}

Measured memory_bytes: 55348
#include<bits/stdc++.h>
using namespace  std ;
typedef long long  ll;
typedef pair<ll, ll> Pll;
#define F first
#define S second
#define MP make_pair
#define PB push_back
#define rad(X) cout << (X) << endl
#define ASH(X) cout << (X) << " "
#define debug(x) cout << #x << " " << x << endl;
#define debug2(x,y) cout << #x << " " << x << " " << #y << " " << y << endl;
#define FOR(I,A,B) for(ll I = (A); I <= (B); I++)
#define cir(I,B,A) for(ll I = (A); I >=(B); I--)
#define MS0(X) memset((X), 0, sizeof((X)))
#define MS1(X) memset((X), -1, sizeof((X)))
#define SORT(c) (sort(c.begin(),c.end()))
#define SORT_UNIQUE(c) (sort(c.begin(),c.end()), c.resize(distance(c.begin(),unique(c.begin(),c.end()))))
#define GET_POS(c,x) (lower_bound(c.begin(),c.end(),x)-c.begin())
#define CASES int ___T; cin >> ___T; for(int cs=1;cs<=___T;cs++)
#define FAST()  ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
template<typename T>T gcd(T x, T y){if(y==0)return x;else return gcd(y,x%y);}
ll fx[] = {1, 1, 0, -1, -1, -1, 0, 1};
ll fy[] = {0, 1, 1, 1, 0, -1, -1, -1};
//vector<ll>a,b,c;
map<ll,ll>m1,m2,m3;
ll DP[100005];

/************************************************/

void Execute()
{
      ll n, nb, k, q, a, b, c, l, r, d, x, y, p, m;
      std::cin >> n;
      ll ar[n];
      FOR(i,0,n-1) cin >> ar[i];

      DP[0] = 0;
      DP[1] = abs(ar[1] - ar[0]);

      FOR(i,2,n-1)
      {
            a = abs(ar[i] - ar[i-1]) + DP[i-1];
            b = abs(ar[i] - ar[i-2]) + DP[i-2];
        DP[i] = min(a,b);
      }
      std::cout << DP[n-1] << '\n';
}

int32_t main()
{
    //#ifndef ONLINE_JUDGE
    //freopen("input.txt", "r", stdin);
    //#endif

    FAST();
    //CASES

        Execute();

}


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

int main(void) {
    string n;

    cin.tie(0);
    ios::sync_with_stdio(false);
    cin >> n;
    if ((n[0] == n[1] && n[1] == n[2]) || (n[1] == n[2] && n[2] == n[3])) {
        cout << "Yes" << "\n";
    } else {
        cout << "No" << "\n";
    }

    return 0;
}

Measured memory_bytes: 256
object Main extends App {
  val n = io.StdIn.readLine().toInt
  val line = io.StdIn.readLine()
  val k = io.StdIn.readLine().toInt
  val ks = line(k - 1)
  println(line.foldLeft("")((acc, a) => if (a == ks) acc ++ a.toString else acc ++ "*"))
}

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

using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);

  int n;
  cin >> n;
  vector<int> a1(n),a2(n);
  for (int i = 0; i < n; ++i) cin >> a1[i];
  for (int i = 0; i < n; ++i) cin >> a2[i];
  vector<int> accum1(n), accum2(n);
  int sum = 0;
  for (int i = 0; i < n; ++i) {
    sum += a1[i];
    accum1[i] = sum;
  }
  sum = 0;
  for (int i = n-1; 0 <= i; --i) {
    sum += a2[i];
    accum2[i] = sum;
  }
  int ans = 0;
  for (int i = 0; i < n; ++i) {
    ans = max(ans, accum1[i] + accum2[i]);
  }
  cout << ans << "\n";
}


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

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

start = 0
money = 1000

for i in range(N - 1):
    if A[i + 1] > A[i]:
        buy = money // A[i]
        money -= A[i] * buy
        money += buy * A[i + 1]

print(money)


Measured memory_bytes: 9140
#include <iostream>

using namespace std;

int main(void){
    int a=0;
    int b=0;

    cin >> a >> b;

    if(a%3==0)cout << "Possible" << endl;
    else if(b%3==0)cout << "Possible" << endl;
    else if((a+b)%3==0)cout << "Possible" << endl;
    else cout << "Impossible" << endl;

    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <cstdlib>
#include <cmath>
#include <vector>
#include <map>
#include <set>
#include <algorithm>
#include <queue>
#include <stack>
#include <functional>
#include <bitset>
using namespace std;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<char> vc;
typedef vector<string> vs;
typedef vector<bool> vb;
typedef vector<double> vd;
typedef pair<ll,ll> P;
typedef vector<P> vpl;
#define rep(i,n) for(ll i=0; i<(n); i++)
#define REP(i,a,b) for(ll i=(a); i<(b); i++)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
const int inf = 1<<30;
const ll linf = 1LL<<62;
const int MAX = 510000;
ll dy[8] = {0,1,0,-1,1,-1,1,-1};
ll dx[8] = {1,0,-1,0,1,-1,-1,1};
const double pi = acos(-1);
const double eps = 1e-7;
template<typename T1,typename T2> inline bool chmin(T1 &a,T2 b){
	if(a>b){
		a = b; return true;
	}
	else return false;
}
template<typename T1,typename T2> inline bool chmax(T1 &a,T2 b){
	if(a<b){
		a = b; return true;
	}
	else return false;
}
template<typename T1,typename T2> inline void print2(T1 a, T2 b){cout << a << " " << b << endl;}
template<typename T1,typename T2,typename T3> inline void print3(T1 a, T2 b, T3 c){
	cout << a << " " << b << " " << c << endl;
}
const int mod = 1e9 + 7;

struct edge{
    ll to,dist;
};

typedef tuple<ll,ll,ll> tu;

int main(){
    ll n,m,l; cin >> n >> m >> l;
    vector<vector<edge>> G(n);
    rep(i,m){
        ll a,b,c; cin >> a >> b >> c; a--; b--;
        if(c > l) continue;
        G[a].push_back({b,c});
        G[b].push_back({a,c});
    }
    vvl ans(n,vl(n,inf));
    rep(i,n){
        vpl d(n,{0,inf});
        priority_queue<tu,vector<tu>,greater<tu>> pq;
        d[i] = make_pair(0,0);
        pq.emplace(0,0,i);
        while(!pq.empty()){
            ll u,used,times;
            tie(times,used,u) = pq.top(); pq.pop();
            if(d[u].second < times) continue;
            else if(d[u].second == times && d[u].first < used) continue;
            for(auto v : G[u]){
                bool f = (used + v.dist) > l;
                if(d[v.to].second < times + f) continue;
                ll use = 0;
                if(f) use = v.dist;
                else use = used + v.dist;
                if(d[v.to].second == times + f){
                    if(d[v.to].first > use){
                        d[v.to].first = use;
                        pq.emplace(d[v.to].second,use,v.to);
                    }
                }else{
                    d[v.to].second = times + f;
                    d[v.to].first = use;
                    pq.emplace(d[v.to].second,use,v.to);
                }
            }
        }
        rep(j,n) ans[i][j] = d[j].second;
    }
    ll q; cin >> q;
    while(q--){
        ll s,t; cin >> s >> t; s--; t--;
        if(ans[s][t] != inf) cout << ans[s][t] << endl;
        else cout << -1 << endl;
    }
}

Measured memory_bytes: 4924
// includes
#include <cstdio>
#include <cstdint>
#include <iostream>
#include <iomanip>
#include <string>
#include <queue>
#include <stack>
#include <vector>
#include <set>
#include <map>
#include <unordered_map>
#include <algorithm>
#include <utility>
#include <functional>
#include <cmath>
#include <climits>
#include <bitset>

// macros
#define ll long long int
#define pb push_back
#define mk make_pair
#define pq priority_queue
#define FOR(i, a, b) for(int i=(a); i<(b);++i)
#define rep(i, n) FOR(i, 0, n)

using namespace std;

//  types
typedef pair<int, int> P;
typedef pair<ll, int> Pl;
typedef pair<ll, ll> Pll;
 
// constants
const int inf = 1e9;
const ll linf = 1LL << 50;
const double EPS = 1e-10;

// solve

int main(int argc, char const* argv[])
{
  ll a, b;
  while(cin >> a && cin >> b){
    cout << (to_string(a + b).size()) << endl;
  }
	return 0;
}



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

int main() {
  string a,b;
  cin>>a>>b;
  if(a.size()>b.size()) cout<<"GREATER"<<endl;
  else if(a.size()<b.size()) cout<<"LESS"<<endl;
  else if(a>b) cout<<"GREATER"<<endl;
  else if(a<b) cout<<"LESS"<<endl;
  else cout<<"EQUAL"<<endl;
  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
using namespace std;
int main() {
	int k;
	string s;
	cin >> k >> s;
	for (int i = 0; i < k && i<s.size(); i++) {
		cout << s[i];
	}
	if (s.size() > k) {
		cout << "...";
	}
	cout << endl;
}

Measured memory_bytes: 3628
import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {

        Scanner sc = new Scanner(System.in);
        
        String C1 = sc.next();
        String C2 = sc.next();
        
        if(C1.charAt(0) == C2.charAt(2) && C1.charAt(1) == C2.charAt(1) && C1.charAt(2) == C2.charAt(0)){
            System.out.println("YES");
        }else{
            System.out.println("NO");
        }
    }
}


Measured memory_bytes: 23124
import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {
        Scanner sc = new Scanner(System.in);
        String str = sc.next();
        char[] array = str.toCharArray();
        int cnt = 0;
        for (int i = 0; i < array.length; i++) {
            if (i == 0 || i % 2 == 0) {
                if (array[i] == 'R' || array[i] == 'U' || array[i] == 'D') {
                    cnt++;
                }
            } else {
                if (array[i] == 'L' || array[i] == 'U' || array[i] == 'D') {
                    cnt++;
                }
            }
        }
        if (cnt == array.length) {
            System.out.println("Yes");
        } else {
            System.out.println("No");
        }
    }
}


Measured memory_bytes: 22740
import java.util.Scanner;


public class Main {
	public static void main(String[] args) throws Exception {
		try(Scanner sc = new Scanner(System.in)) {
			int r = sc.nextInt();
			int D = sc.nextInt();
			int x = sc.nextInt();
			for(int i=0; i<10; i++) {
				x = r*x - D;
				System.out.println(x);
			}
		}
	}

}

Measured memory_bytes: 22996