akhauriyash/Code-Regression huggingface dataset:
//
//  main.cpp
//  CoderProj
//
//  Created by Minoru Hayashi on 2020/04/04.
//  Copyright © 2020 Minoru Hayashi. All rights reserved.
//
//  ABC129
//
//

#include <bits/stdc++.h>
using namespace std;

#define REP(i,n) for (int i=0; i<(n); i++)
#define REP2(i,x,n) for (int i=x; i<(n); i++)
#define ALL(n) begin(n), end(n)

using ll = long long;

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

// const ll INF = 1LL<<60;
// const int INF = 1<<29;
 const ll MOD = 1000000007;
//#define __DBG__


void solve(void){
  
  int N, M;
    
  cin >> N >> M;
  
  vector<int> A(M,0);
  vector<bool> B(N+1,1);
  vector<ll> dp(N+1,0);  // number until i
  
  REP(i,M){
    cin >> A[i];
    B[A[i]]=0;
  }
  
  dp[0]=1LL;
  if(B[1]){dp[1]=1LL;}
  
  bool flag=true;
  
  REP2(i,2,N+1){
    if(B[i]==0){dp[i]=0;continue;}
    dp[i]=(dp[i-2]+dp[i-1])%MOD;
    if(dp[i]==0){flag=false; break;}
//    cout << i << ":" << dp[i] << endl;
  }
  
  if(flag){
    cout << dp[N] << endl;
  }
  else
  {
    cout << "0" << endl;
  }
  
  return;
}

#define TESTCASES 1

int main(int argc, const char * argv[]) {

    cin.tie(0);
    ios::sync_with_stdio(false);

    REP(i,TESTCASES){
      solve();
    }
 
    return 0;
}



Measured memory_bytes: 1408
#include <bits/stdc++.h>
#include <random>
using namespace std;
using ll = long long;
using ull = unsigned long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vl = vector<ll>;
using vvl = vector<vl>;
using Pt = pair<int, int>;

int main()
{
	int N;
	ll D;
	cin >> N >> D;
	D *= D;
	int ct = 0;
	for (int i = 0; i < N; ++i)
	{
		ll X, Y;
		cin >> X >> Y;
		X *= X;
		Y *= Y;
		if (X + Y <= D)
		{
			++ct;
		}
	}
	cout << ct << endl;

	return 0;
}

Measured memory_bytes: 3632
#include <bits/stdc++.h>
#define ALL(a)  (a).begin(),(a).end()
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
typedef pair<long long, long long> Pll;
typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef vector<long long> vll;
typedef vector<vector<long long>> vvll;
template <typename T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template <typename T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
const long long INF = 1LL << 60;
const int INT_INF = 1LL << 30;

int main(){
  int N, K;
  cin >> N >> K;
  vi x(N);
  for(int i = 0; i < N; i++){
    cin >> x.at(i);
  }
  int l, r;
  int ans = INT_INF;
  for(int i = 0; i + K - 1 < N; i++){
    l = i;
    r = i + K - 1;
    chmin(ans, min(abs(x.at(l)), abs(x.at(r))) + x.at(r) - x.at(l));
  }
  cout << ans << endl;
}

Measured memory_bytes: 640
s=list(input())
t=list(input())
s.sort()
t.sort(reverse=True)
if len(s) < len(t):
  len = len(s)
  flg_s=1
else:
  len = len(t)
  flg_s=0
for i in range(len):
  if ord(s[i]) < ord(t[i]):
    print('Yes')
    exit(0)
  elif ord(s[i]) > ord(t[i]):
    print('No')
    exit(0)
if flg_s == 1:
  print('Yes')
else:
  print('No')

Measured memory_bytes: 3064
def main():
    import sys
    input = sys.stdin.readline
    sys.setrecursionlimit(10**7)
    from collections import Counter, deque
    #from collections import defaultdict
    from itertools import combinations, permutations, accumulate, groupby, product
    from bisect import bisect_left,bisect_right
    from heapq import heapify, heappop, heappush
    import math

    #inf = 10**17
    #mod = 10**9 + 7

    n = int(input())
    s = input().rstrip()
    l, r = 0, 0
    res = 0
    while r < n:
        r += 1
        if not s[l:r] in s[r:]:
            l += 1
            res = max(res, r-l)
    print(res)

if __name__ == '__main__':
    main()

Measured memory_bytes: 3316
n,m = map(int, input().split())
a = set([int(input()) for _ in range(m)])

mod = 10**9+7
dp = [0]*(n+1)
dp[0]=1
if 1 not in a:
    dp[1]=1
for i in range(2,n+1):
    if i in a :
        continue
    else:
        dp[i]= dp[i-1] + dp[i-2]
        dp[i]%= mod


print(dp[n])

Measured memory_bytes: 13192
#include<bits/stdc++.h>
#define rint register int
using namespace std;
inline int read(){
	int s=0,f=1; char c=getchar();
	while(c<'0'||c>'9'){if(c=='-')f=0;c=getchar();}
	while(c>='0'&&c<='9') s=(s<<1)+(s<<3)+(c^48),c=getchar();
	return f?s:-s;
}
int n,a[200010],b[200010];
int f[200010][210];
long long ans;
void ST_prework(){
	for(rint i=1;i<=n;++i) f[i][0]=a[i];
	int t=log2(n)+1;
	for(rint j=1;j<t;++j)
		for(rint i=1;i<=n-(1<<j)+1;++i)
			f[i][j]=min(f[i][j-1],f[i+(1<<j-1)][j-1]);
}
int ST_query(int l,int r){
	int k=log2(r-l+1);
	return min(f[l][k],f[r-(1<<k)+1][k]);
}
void sol(int l,int r){
	if(l>r) return;
	if(l==r){
		ans+=a[l];
		return;
	}
	int num=ST_query(l,r);
	ans+=1LL*(r-b[num]+1)*(b[num]-l+1)*num;
//		cout<<ans<<' '<<num1<<' '<<b[num1]<<' '<<l<<' '<<r<<' '<<endl;
	sol(l,b[num]-1); sol(b[num]+1,r);
}
int main(){
//	freopen("a.in","r",stdin);
	n=read();
	for(rint i=1;i<=n;++i) a[i]=read(),b[a[i]]=i;
	ST_prework(); sol(1,n);
	printf("%lld",ans);
	return 0;
}

Measured memory_bytes: 172160
fn main() {
    const MOD: u64 = 998244353;

    let (n, s): (usize, usize) = {
        let mut buf = String::new();
        std::io::stdin().read_line(&mut buf).unwrap();
        let mut iter = buf.split_whitespace();

        let n: usize = iter.next().unwrap().parse().unwrap();
        let s: usize = iter.next().unwrap().parse().unwrap();
        (n, s)
    };

    let a: Vec<usize> = {
        let mut buf = String::new();
        std::io::stdin().read_line(&mut buf).unwrap();
        buf.split_whitespace().map(|x| x.parse().unwrap()).collect()
    };

    let mut dp: Vec<Vec<u64>> = vec![vec![0; s + 1]; n + 1];
    dp[0][0] = 1;

    for i in 0..n {
        for j in 0..(s + 1) {
            dp[i + 1][j] += dp[i][j] * 2;
            dp[i + 1][j] %= MOD;

            if j + a[i] <= s {
                dp[i + 1][j + a[i]] += dp[i][j];
                dp[i + 1][j + a[i]] %= MOD;
            }
        }
    }

    println!("{}", dp[n][s]);
}

Measured memory_bytes: 72460
#include<stdio.h>
#include <sysexits.h>
#include<stdlib.h>
#include<math.h>
int main(void){
  int j,tmp,sum,x[5],i,mod[5],s[5],k;
  for(i=0;i<5;i++){
    if(scanf("%d",&x[i])>1){
    exit(0);
  }
  }
  sum=0;
   for(i=0;i<5;i++){
      mod[i]=x[i]%10;
      s[i]=x[i]/10;
   }
   for(i=0;i<5;i++){
     if(mod[i]==0){
     sum=sum+(s[i])*10;
     }
   else{
  sum=sum+(s[i]+1)*10;
   }
   }
   for (i=0; i<5; i++) {
    for (j=i+1; j<5; j++) {
      if (mod[i] > mod[j]) {
        tmp =  mod[i];
        mod[i] = mod[j];
        mod[j] = tmp;
      }
    }
  }
    for(i=0;i<5;i++){
      if(mod[i]>0){
        k=i;
        break;
      }
    }
    sum=sum+mod[k]-10;
    if(mod[4]==0){
      sum=sum+10;
    }
    printf("%d",sum);
  return 0;
}


Measured memory_bytes: 128
#include <bits/stdc++.h>
#define rep(i,cc,n) for(int i=cc;i<=n;++i)
#define drep(i,cc,n) for(int i=cc;i>=n;--i)
#define sz(s) (int)(s.size())
#define vecprint(v) rep(i,0,v.size()-1)cout << v[i] << " ";cout << endl;
#define arrprint(v,n) rep(i,0,n-1)cout << v[i] << " ";cout << endl;
#define matprint(v,n,m) rep(i,0,n-1){rep(j,0,m-1){cout << v[i][j] << " ";}cout << endl;}
#define SORT(v) sort(v.begin(), v.end())
#define REV(v) reverse(v.begin(), v.end())
using namespace std;
const int mod=1000000007;
const int INF=1001001001;
typedef long long ll;
typedef pair<int,int> P;
template<typename T>
using priority_queue_rev = priority_queue<T, vector<T>, greater<T>>; //小さいものから取り出す

int main(){
    int n,m;
    cin >> n >> m;
    rep(i,1,m){
        int a;
        cin >> a;
        n -= a;
    }
    n = max(-1,n);

    cout << n << endl;
//  printf("%.10f\n",ans);

    return 0;
}

Measured memory_bytes: 3632
#pragma GCC optimize ("O3")
#pragma GCC target ("tune=native")
#pragma GCC target ("avx")

#include <bits/stdc++.h>

// 汎用マクロ
#define ALL_OF(x) (x).begin(), (x).end()
#define REP(i,n) for (long long i=0, i##_len=(n); i<i##_len; i++)
#define RANGE(i,is,ie) for (long long i=(is), i##_end=(ie); i<=i##_end; i++)
#define DSRNG(i,is,ie) for (long long i=(is), i##_end=(ie); i>=i##_end; i--)
#define UNIQUE(v) { sort((v).begin(), (v).end()); (v).erase(unique((v).begin(), (v).end()), (v).end()); }
template<class T> bool chmax(T &a, const T &b) {if (a < b) {a = b; return true;} return false; }
template<class T> bool chmin(T &a, const T &b) {if (a > b) {a = b; return true;} return false; }
#define INF 0x7FFFFFFF
#define LINF 0x7FFFFFFFFFFFFFFFLL
#define Yes(q) (q ? "Yes" : "No")
#define YES(q) (q ? "YES" : "NO")
#define DUMP(q) cerr << "[DEBUG] " #q ": " << (q) << " at " __FILE__ ":" << __LINE__ << endl
#define DUMPALL(q) { cerr << "[DEBUG] " #q ": ["; REP(dumpall_i, (q).size()) { cerr << q[dumpall_i] << (dumpall_i == (q).size() - 1 ? "" : ", "); } cerr << "] at " __FILE__ ":" << __LINE__ << endl; }
template<class T> T gcd(const T &a, const T &b) { return a < b ? gcd(b, a) : b ? gcd(b, a % b) : a; }
template<class T> T lcm(const T &a, const T &b) { return a / gcd(a, b) * b; }

// gcc拡張マクロ
#define popcount __builtin_popcount
#define popcountll __builtin_popcountll

// エイリアス
using  ll = long long;
using ull = unsigned long long;
using  ld = long double;
using namespace std;

// モジュール


// 処理内容
int main() {
    
    ll x, a; cin >> x >> a;
    cout << (x < a ? 0 : 10) << endl;
    
}

Measured memory_bytes: 256
#include <stdio.h>
int main(int argc, const char * argv[])
{
    int a, b, c, x;
    scanf("%d %d %d", &a, &b, &c);
    if(a > b){
        x=a,a=b,b=x;
    }if(b > c){
        x=b,b=c,c=x;
    }if(a > b){
        x=a,a=b,b=x;
    }
    printf("%d %d %d\n", a, b, c);
    return 0;
}

Measured memory_bytes: 596
import sys
import math
import collections
import bisect
import itertools
import decimal

# import numpy as np

# sys.setrecursionlimit(10 ** 6)
INF = 10 ** 20
MOD = 10 ** 9 + 7
# MOD = 998244353

ni = lambda: int(sys.stdin.readline().rstrip())
ns = lambda: map(int, sys.stdin.readline().rstrip().split())
na = lambda: list(map(int, sys.stdin.readline().rstrip().split()))
na1 = lambda: list(map(lambda x: int(x) - 1, sys.stdin.readline().rstrip().split()))


# ===CODE===

def main():
    n = ni()
    a = na()

    tmp = len(a)

    # 素数列挙
    def Eratosthenes(n):  # N以下のすべての値に対して素数を返す
        a = [[] for _ in range(n + 1)]
        if n >= 2:
            for i in range(2, n + 1):
                if len(a[i]) == 0:
                    for j in range(i, n + 1, i):
                        a[j].append(i)
        return a

    l = max(a)
    p = Eratosthenes(l)
    cnt = [0 for _ in range(l + 1)]

    pc = True
    tc = True

    for ai in a:
        for pi in p[ai]:
            cnt[pi] += 1
            if cnt[pi] >1:
                pc = False
            if cnt[pi] == n:
                tc = False
                break


    if pc:
        print("pairwise coprime")
    elif tc:
        print("setwise coprime")
    else:
        print("not coprime")

if __name__ == '__main__':
    main()


Measured memory_bytes: 305520
#include <stdio.h>
 
int main() {
    int r,c;
    int i,j;
 
    while (1) {
        scanf("%d%d",&r,&c);
        if (r == 0 && c == 0) {
            break;
        }
        for (i = 0;i != r;++i) {
            for (j = 0;j != c;++j) {
                printf((i + j)%2 == 0 ? "#" : ".");
            }
            printf("\n");
        }
        printf("\n");
    }   
    return 0;
}


Measured memory_bytes: 2104
#include <iostream>
#include <vector>
#include <queue>
#include <algorithm>
#include <cmath>
#include <bitset>
#include <iomanip>
#include <stack>
#include <list>
#include <map>
#include <unordered_map>
#include <chrono>
#include <numeric>
using namespace std;
using ll = long long;
const ll INF = (ll)1e18+1;
const ll DIV = 1000000007;
//#define TEST
int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
#ifdef TEST
    chrono::system_clock::time_point start, end;
    start = chrono::system_clock::now();
#endif
    long K;
    cin >> K;
    long even = K / 2;
    long odd = K / 2 + K % 2;
    cout << even * odd << endl;
#ifdef TEST
    end = chrono::system_clock::now();
    cerr << static_cast<double>(chrono::duration_cast<chrono::microseconds>(end - start).count() / 1000.0) << "[ms]" << endl;
#endif
    return 0;
}

Measured memory_bytes: 3556
#include <iostream>
#include <algorithm>
#include <string>
#include <string.h>
#include <stdlib.h>
#include <math.h>
#include <vector>
#include <queue>

using namespace std;

#define REP(i, s) for (int i = 0; i < s; ++i)
#define ALL(v) (v.begin(), v.end())
#define COUT(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << endl
#define EACH(i, s) for (__typeof__((s).begin()) i = (s).begin(); i != (s).end(); ++i)

int main()
{
    long long n;
    cin>>n;
    long long cnt=n-1;
    long long ans=0;
    long long tmp=1;//余り
    while(cnt>0){
        if (tmp==n){
            break;
        }
        if ((n-tmp)/tmp<=tmp){
            break;
        }
        if ((n-tmp)%tmp==0){//(n-tmp)/tmpは割る数
            ans+=(n-tmp)/tmp;
        }
        tmp++;
        cnt--;
    }
    cout<<ans<<endl;


    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
struct P
{
    //string r;
    int x,y,z;

    bool operator<(const P &a)const{
       // if(y!=a.y)
       // return y>a.y;
       return x>a.x;
//        return z>a.z;
    }
};

vector<P> v[5555];
//bitset<4001000> b;
int a,c,i,b,k,d,n,m,e;//dy[15]={0,1,0,-1,-1,1,-1,1},dx[15]={1,0,-1,0,1,1,-1,-1};//
int l[115555];
int o[115400];
int dx[10]={0,1,0,-1},dy[10]={1,0,-1,0},dz[10]={0,0,0,0,1,-1};

long long x,y,z,mod=1000000007;
P u[111111];
double j[111];

stack<int> s;
queue<P> q;
//'1'==49;
//'A'==65;
//'a'==97;
//unordered_
map<int,int > p;
//list<int> l;
string r;
//char r[333][333];


bool as(P a,P b)
{
    if(a.x!=b.x) return a.x<b.x;
    return a.y>b.y;
}

int main()
{
    scanf("%d %d",&a,&b);
    for(int t=1;t<=a;o[t]=1,t++);
    l[1]=1;
    for(int t=1;t<=b;t++)
    {
        scanf("%d %d",&n,&m);
        o[n]--;
        o[m]++;
        if(l[n]) l[m]=1;
        if(!o[n]) l[n]=0;
    }
    for(int t=1;t<=a;k+=l[t],t++);
    printf("%d ",k);
}


Measured memory_bytes: 1152
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace AtCoderGC003 {
  class AtCoderGC003 {
    static void Main(string[] args) {
      new AtCoderGC003().solveA();
    }

    private void solveA() {
      string s = Console.ReadLine();
      int N=0, S=0, W=0, E=0; 
      int l = s.Length;
      
      for(int i=0; i<l;i++){
        if(s[i] == 'N') N++;
        if(s[i] == 'S') S++;
        if(s[i] == 'W') W++;
        if(s[i] == 'E') E++;
      }
      
      if((N>0 && S==0) || (N==0 && S>0)) 
        Console.WriteLine("No");
      else if((W>0 && E==0) || (W==0 && E>0))
      Console.WriteLine("No");
      else
        Console.WriteLine("Yes");
    }//end M.
 }
}

Measured memory_bytes: 2776
#include <stdio.h>
#include <math.h>
#define MAX 105
#define INF 1e8

int n, M[MAX][MAX], P[MAX];

void minMult(){
	int b, i, j, k, q;
	for (i=1; i<n; i++)
		M[i][i] = 0; 
	for (b=2; b<=n; b++){
		for (i=1; i<=n-b+1; i++){
			j = i+b-1;
			M[i][j] = INF;
			for (k=i; k<=j-1; k++){
			//	printf("%d %d %d\n",i,j,k);
				q = (M[i][k] + M[k+1][j] + (P[i-1]*P[k]*P[j]));
				if (q < M[i][j])
					M[i][j] = q;
			//	printf("%d %d %d %d %d\n",P[i-1],P[k],P[j], q, M[i][j]);	
			}
		}
	}
}

int main(void) {
	int r,c, i,j;
	
	scanf("%d", &n);
	for(i=0; i<n+1; i++){
		scanf("%d %d", &r, &c);
		if(i<n)
			P[i] = r;
		else P[i] = c;
	}
	

	minMult();
	// for(i=1; i<n+1; i++){
	// 	for(j=1; j<n+1; j++)
	// 		printf("%d ", M[i][j]);
	// }
	
	printf("%d\n",M[1][n]);
	
	return 0;
}



Measured memory_bytes: 2112
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll INF = 1e18,MOD = 1e9 + 7;
const int INT_INF = 1e9,INT_MOD=1e9+7;
#define rep(i, N) for(int i = 0; i < N; i++)
typedef pair<int, int> Pi;
typedef pair<double, double> P;
signed main(){
    string s;cin>>s;
    rep(i,s.size())cout<<"x";

    return 0;
}

Measured memory_bytes: 256
import java.util.AbstractMap;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Queue;
import java.util.Scanner;
import java.util.concurrent.ArrayBlockingQueue;

public class Main {

     static Scanner scanner;

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

         int N=gi();
         int M=gi();
         int[] a=new int[M];
         int[] b=new int[M];
         boolean[] f=new boolean[N+1];
         Map<Integer, List<Integer>> m=new HashMap<Integer, List<Integer>>();

         for (int i=0; i<M;i++) {
             a[i]=gi();
             b[i]=gi();
             if (m.containsKey(a[i])) {
            	 List<Integer> l=m.get(a[i]);
            	 l.add(b[i]);
             } else {
            	 List<Integer> l=new ArrayList<Integer>();
            	 l.add(b[i]);
            	 m.put(a[i], l);
             }
             if (m.containsKey(b[i])) {
            	 List<Integer> l=m.get(b[i]);
            	 l.add(a[i]);
             } else {
            	 List<Integer> l=new ArrayList<Integer>();
            	 l.add(a[i]);
            	 m.put(b[i], l);
             }
         }

         Queue<Integer> q=new ArrayBlockingQueue<Integer>(N);

         long ans=1;
         for (int i=1; i<=N;i++) {
             if (f[i]==false) {
            	 f[i]=true;
            	 q.add(i);
            	 int tmp=1;
            	 while(!q.isEmpty()) {
            		 int p=q.poll();
            		 List<Integer> l=m.get(p);
            		 if(l==null) continue;
            		 for (int j=0; j<l.size();j++) {
            			 int p2=l.get(j);
            			 if(f[p2]==false) {
            				 f[p2]=true;
            				 q.add(p2);
            				 tmp++;
            			 }
            		 }
            	 }
            	 ans=Math.max(ans, tmp);
             }
         }
         System.out.println(ans);

     }

     public static class Pair<K, V> extends AbstractMap.SimpleEntry<K, V> implements Comparable<Pair<K, V>> {
    	    /** serialVersionUID. */
    	    private static final long serialVersionUID = 6411527075103472113L;

    	    public Pair(final K key, final V value) {
    	        super(key, value);
    	    }

    	    @Override
    	    public int compareTo(Pair<K, V> o) {

    	        Comparable key = (Comparable)this.getKey();
    	        Comparable key2 = (Comparable)o.getKey();

    	        return key.compareTo(key2);
    	    }

    	}
     // 文字列として入力を取得
     public static String gs() {
          return scanner.next();
     }

     // intとして入力を取得
     public static int gi() {
          return Integer.parseInt(scanner.next());
     }

     // longとして入力を取得
     public static long gl() {
          return Long.parseLong(scanner.next());
     }

     // doubleとして入力を取得
     public static double gd() {
          return Double.parseDouble(scanner.next());
     }
}

Measured memory_bytes: 105112
N = int(input())
a = list(map(int, input().split()))

average = sum(a) / len(a)

min_diff = abs(a[0] - average)
ans = 0
for i, x in enumerate(a):
    if min_diff > abs(x - average):
        min_diff = abs(x - average)
        ans = i

print(ans)


Measured memory_bytes: 3060
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
struct node{ 
  int key;
  struct node *next;
  struct node *prev;
};
typedef struct node * NodePointer;
NodePointer nil;
NodePointer listSearch(int key){
  NodePointer i;
  for(i=nil;i->next!=nil;i=i->next){
  if(i->next->key==key)return i->next;
  }
  return NULL;
} 
void init(){
  nil = malloc(sizeof(struct node));
  nil->next = nil; 
  nil->prev = nil;
}
void printList(){ 
  NodePointer cur = nil->next;
  int isf = 1;
  while(1){
    if ( cur == nil ) break;
    if ( isf == 0) printf(" "); 
    printf("%d", cur->key);
    cur = cur->next; isf = 0; 
  } 
  printf("\n");
}
void deleteNode(NodePointer t){
  t->next->prev=t->prev;
  t->prev->next=t->next;
  free(t);
}
void deleteFirst(){ 
  NodePointer t = nil->next;
  if ( t == nil )return;
  deleteNode(t);
}
void deleteLast(){
  NodePointer i;
  i=nil->prev;
  deleteNode(i);
}
void delete(int key){
  NodePointer i; 
  i=listSearch(key);
  if(i!=NULL)deleteNode(i);
} 
void insert(int key){ 
  NodePointer x;
  x = malloc(sizeof(struct node));
  x->key = key;
  x->next=nil->next;
  nil->next->prev=x;
  nil->next=x;
  x->prev=nil;
}
int main(){ 
  int key, n, i;
  int size = 0; 
  char com[20]; 
  int np = 0, nd = 0;
  scanf("%d", &n); //命令の数nを受け取っている
  init();
  for ( i = 0; i < n; i++ ){//各命令の処理を行う
    scanf("%s%d", com, &key);
    if ( com[0] == 'i' ) {//命令の頭文字がiの時点でinsert命令確定
      insert(key);
      np++;
      size++;
    } 
    else if ( com[0] == 'd' ) {//命令の頭文字がdの時はdelete,deleteFirst,deleteLastの三パターン考えられる
      if (strlen(com) > 6){//六文字目によってdeleteFirst,deleteLastの判定を分岐させている
		if ( com[6] == 'F' ) deleteFirst();
		else if ( com[6] == 'L' ) deleteLast();
      }
      else { delete(key); nd++; } 
    size--; }
  }
  printList(); 
  return 0;
}



Measured memory_bytes: 33052
#include<stdio.h>
int Binary_Search(int,int,int*);
int main()
{
  int i,count=0;
  int n,s[100000],q,t;
  
  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);
    count += Binary_Search(t,n,s);
  }    
  
  printf("%d\n",count);

  return 0;
}

int Binary_Search(int k,int n,int s[])
{
  int left=0,right=n,mid;

  while(left < right) {
    mid = (left+right)/2;
    if(s[mid] == k) return 1;
    if(s[mid]< k) left = mid+1;
    else right = mid;
  }
  return 0;
}

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

int main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    cout.precision(12);
    cout.setf(ios_base::fixed, ios_base::floatfield);
    
    string s;
    cin >> s;
    int a = 0;
    int64_t ans = 0;
    int i = 0;
    s.push_back('X');
    while(i<s.size()){
        if(s[i]=='A'){
            a++;
            i++;
        }else if(s[i]=='B'){
            if(s[i+1]=='C'){
                ans += a;
                i += 2;
            }else{
                a = 0;
                i++;
            }
        }else{
            a = 0;
            i++;
        }
    }

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

Measured memory_bytes: 720
A,B,C=(input().split())
K = int(input())
A = int(A)
B = int(B)
C = int(C)
for i in range(K):
    if B > C or C == B:
        C = C*2
    elif A > B or B == A:
        B = B*2
if A < B and B < C:
    print("Yes")
else:
    print("No")

Measured memory_bytes: 9184
def g(A,l,m,r):
 global c
 L,R=A[l:m]+[1e9],A[m:r]+[1e9]
 i=j=0
 for k in range(l,r):
  if L[i]<R[j]:A[k]=L[i];i+=1
  else:A[k]=R[j];j+=1
  c+=1
def s(A,l,r):
 if l+1<r:
  m=(l+r)//2
  s(A,l,m);s(A,m,r)
  g(A,l,m,r)
c=0
n=int(input())
A=list(map(int,input().split()))
s(A,0,n)
print(*A)
print(c)


Measured memory_bytes: 61660
def main():
    n, *abc = map(int, open(0).read().split())
    dp = [[0, 0, 0] for _ in range(n + 1)]
    for i, (a, b, c) in enumerate(zip(abc[::3], abc[1::3], abc[2::3]), 1):
        x, y, z = dp[i - 1]
        dp[i] = [a + max(y, z), b + max(z, x), c + max(x, y)]

    ans = max(dp[-1])
    print(ans)


if __name__ == '__main__':
    main()


Measured memory_bytes: 37128
W,H,x,y,r = map (int,input().split())

if (x-r) < 0 or (x+r) > W or (y-r) < 0 or (y+r) > H :
  print('No')
elif(x-r) >= 0 and (x+r) <= W and (y-r) >= 0 and (y+r) <= H :
  print('Yes')


Measured memory_bytes: 5596
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define inf 1001001001001001001
#define mod 1000000007
#define mod2 998244353
#define pi acos(-1)
#define all(v) v.begin(),v.end()

int main(){
    string s;cin>>s;
    string tmp="";
    int max=0;
    for(int i=0;i<s.size();i++){
        if(s.at(i)=='A'||s.at(i)=='C'||s.at(i)=='G'||s.at(i)=='T'){
            tmp+=s.at(i);
        }else{
            if(max<tmp.size()){
                max=tmp.size();
            }
            tmp="";
        }
    }
    if(max<tmp.size()){
        max=tmp.size();
    }
    cout<<max<<endl;
}

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

int main() {
  int h, w;
  cin >> h >> w;
  vector<string> s(h);
  for (int i = 0; i < h; i++) cin >> s[i];

  vector<int> dx, dy;
  dx = {1, 1, 1, 0, 0, -1, -1, -1};
  dy = {-1, 0, 1, -1, 1, -1, 0, 1};
  vector<vector<int> > a(h, vector<int>(w));

  for (int i = 0; i < h; i++) {
    for (int j = 0; j < w; j++) {
      if (s[i][j] == '#') {
        for (int k = 0; k < 8; k++) {
          int x = i + dx[k], y = j + dy[k];
          if (x >= 0 && x <= h - 1 && y >= 0 && y <= w - 1) a[x][y]++;
        }
      }
    }
  }

  for (int i = 0; i < h; i++) {
    for (int j = 0; j < w; j++) {
      if (s[i][j] != '#')
        cout << a[i][j];
      else
        cout << '#';
    }
    cout << endl;
  }
}

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

int64_t mod = 1000000007;
int64_t large = 9223372036854775807;
double PI = 3.141592653589793;

int ketasu(int64_t N)
{
    int64_t d = 0;
    while (N != 0)
    {
        N /= 10;
        d++;
    }
    return d;
}

int main()
{
    int A, B;
    cin >> A >> B;
    int ans = A * pow(10, ketasu(B)) + B;
    bool x = false;
    for (int i = 1; i * i <= ans; i++)
        if (i * i == ans)
            x = true;
    cout << (x ? "Yes" : "No");
}

Measured memory_bytes: 256
pub 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()
}

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

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

pub fn read_col<T: std::str::FromStr>(n: usize) -> Vec<T> {
    (0..n).map(|_| read()).collect()
}

fn f(u: usize, p: usize, c: u64, edges: &Vec<Vec<(usize, u64)>>, depth: &mut Vec<u64>) {
    depth[u as usize] = c;
    for v in &edges[u] {
        if v.0 == p {
            continue;
        }
        f(v.0, u, c + v.1, edges, depth);
    }
}

fn main() {
    let hw: Vec<usize> = read_vec();
    let h = hw[0];
    let w = hw[1];
    let n: usize = read();
    let avec: Vec<usize> = read_vec();

    let mut mat: Vec<Vec<usize>> = vec![vec![0; w]; h];
    let mut color = 0;
    let mut cnt = avec[color];
    let mut b = true;
    for i in 0..h {
        for j1 in 0..w {
            let j;
            if b {
                j = j1;
            } else {
                j = w - 1 - j1;
            }
            if cnt == 0 {
                color += 1;
                cnt = avec[color];
            }
            mat[i][j] = color + 1;
            cnt -= 1;
        }
        b = !b;
    }

    for i in 0..h {
        for j in 0..w {
            print!("{}", mat[i][j]);
            if j < w - 1 {
                print!(" ");
            } else {
                println!("");
            }
        }
    }
}


Measured memory_bytes: 4352
#include <bits/stdc++.h>
#define debug(x) cerr << #x << ": " << x << '\n';
using namespace std;
using ll = long long;
using P = pair<int, int>;
const int INF = (int)1e9;
const int MOD = (int)1e9 + 7;

int main(void){
	int A, B, T;
	cin >> A >> B >> T;

	cout << B * (T / A) << '\n';

	return 0;
}

Measured memory_bytes: 256
var input = require('fs').readFileSync('/dev/stdin', 'utf8');
var Arr=(input.trim()).split("\n");
for(i=0;i<Arr.length;i++){
   var arr=Arr[i].split(" ").map(Number);
   (function(x1, y1, x2, y2, x3, y3, x4, y4){
      var k1;
      var k2;
      if(x2-x1!==0)k1=((y2-y1)/(x2-x1));
      else k1=Infinity;
      if(x4-x3!==0)k2=(y4-y3)/(x4-x3);
      else k2=Infinity;
      var ans="NO";
      if(k1==0 && k2==Infinity)ans="YES";
      if(k2==0 && k1==Infinity)ans="YES";
      if(Math.abs(k1*k2+1)<1.0e-8)ans="YES";
      console.log(ans);
   }).apply(null,arr);
}

Measured memory_bytes: 7644
import java.util.LinkedList;
import java.util.Scanner;
import java.util.Iterator;

class Graph {
	private int totalVertex;
	private LinkedList<LinkedList<Integer>> adjList;
	//adjacency list of edges
	public Graph() { totalVertex = 0; }
	public void loadAdjList() {
		Scanner in = new Scanner(System.in);
		totalVertex = in.nextInt();
		adjList = new LinkedList<LinkedList<Integer>>();
		for(int i = 0; i < totalVertex; i ++) {
			LinkedList<Integer> tmp = new LinkedList<Integer>();
			int idx1 = in.nextInt() - 1;
			int degree = in.nextInt();
			//System.out.println("mark idx1 = " + idx1 + " degree = " + degree);
			for(int j = 0; j < degree; j ++) {
				int idx2 = in.nextInt() - 1;
				tmp.add(idx2);
			}	
			adjList.add(tmp);
		}
		in.close();
	}
	public void printAdjMatrix() {
		Integer[][] adjMatrix = new Integer[totalVertex][totalVertex];
		//complete the following
		for(int i = 0; i < adjList.size(); i++) {
			for(int j = 0; j < totalVertex; j++) {
				adjMatrix[i][j] = 0;
			}
		}
		for(int i = 0; i < adjList.size(); i++) {
			for(int j = 0; j < adjList.get(i).size(); j++) {
				adjMatrix[i][adjList.get(i).get(j)] = 1;				
			}
		}	
		for(int i = 0; i < adjList.size(); i++) {
			for(int j = 0; j < totalVertex; j++) {
				if(j == totalVertex - 1) {
					System.out.print(adjMatrix[i][j]);
				}
				else {
					System.out.print(adjMatrix[i][j] + " ");
				}				
			}
			System.out.println();
		}
	}
	
	public void printDFS() {
        int[] d = new int[totalVertex];
        int[] f = new int[totalVertex];
        int timestamp = 1;
        for (int i = 0; i < totalVertex; i++) {
            if (d[i] == 0) {
                timestamp = DFS(i, timestamp, d, f) + 1;
            }
        }
        for (int i = 0; i < totalVertex; i++) {
            System.out.println((i + 1) + " " + d[i] + " " + f[i]);
        }
    }
	
    public int DFS(int v, int time, int[] d, int[] f) {
        d[v] = time;
        
        LinkedList<Integer> list = adjList.get(v);
        for (Integer i : list) {
            if (d[i] == 0) {
                time++;
                time = DFS(i, time, d, f);
            }
        }
        f[v] = time + 1;
        return time + 1;
    }
}

//change class name GraphRepresentation to Main() for submission to AIZU
public class Main{
	public static void main(String argv[]) {
		Graph g = new Graph();
		g.loadAdjList();
		//g.printAdjMatrix();
		g.printDFS();
	}
}


Measured memory_bytes: 28300
#include <cctype>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <functional>
#include <iostream>
#include <iterator>
#include <limits>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <cctype>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <functional>
#include <iostream>
#include <iterator>
#include <limits>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
#include <array>
#include <initializer_list>
#include <random>
#include <regex>
#include <tuple>
#include <unordered_map>
#include <unordered_set>
#include <cassert>
using namespace std;

char s[222222];
int dat[222222];
int vis[222222];
unordered_map<int, vector<int>> pos;
unordered_map<int, vector<int>> parent;

int getparent(vector<int> &vt, int t)
{
    return vt[t] == t ? t : vt[t] = getparent(vt, vt[t]);
}

void merge(vector<int> &vt, int a, int b)
{
    a = getparent(vt, a);
    b = getparent(vt, b);
    vt[min(a, b)] = max(a, b);
}

int main()
{
    scanf("%s", s + 1);

    int len = strlen(s + 1);

    pos[0].push_back(0);

    for (int i = 1; i <= len; i++)
    {
        dat[i] = dat[i - 1] ^ (1 << (s[i] - 'a'));
        pos[dat[i]].push_back(i);
    }

    for (auto &e : pos)
    {
        parent[e.first].resize(e.second.size() + 1);
        for (int j = 0; j <= e.second.size(); j++) parent[e.first][j] = j;
    }

    queue<int> que;

    for (int x : pos[0])
    {
        vis[x] = 1;
        que.push(x);
    }

    for (int i = 0; i < 26; i++)
    {
        if (pos.count(1 << i) == 0) continue;
        for (int x : pos[1 << i])
        {
            vis[x] = 1;
            que.push(x);
        }
    }

    while (que.empty() == false)
    {
        int x = que.front(); que.pop();

        for (int i = 0; i < 26; i++)
        {
            int nxt = dat[x] ^ (1 << i);
            if (pos.count(nxt) == 0) continue;

            int p = upper_bound(pos[nxt].begin(), pos[nxt].end(), x) - pos[nxt].begin();

            for (p = getparent(parent[nxt], p); p < pos[nxt].size(); merge(parent[nxt], p, p + 1), p = getparent(parent[nxt], p))
            {
                int y = pos[nxt][p];
                if (vis[y] == 0)
                {
                    vis[y] = vis[x] + 1;
                    que.push(y);
                }
            }
        }
    }

    printf("%d\n", vis[len]);
}


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

int q(const int *a,const int *b)
{
    return *a-*b;
}

int main(void)
{
    int n,i;
    scanf("%d%d",&n,&i);
    printf("%d",n-i+1);
    return 0;
}

Measured memory_bytes: 128
n=int(input())
a=list(map(int,input().split()))
total=0
x=0
for i in range(n):
    total+=a[i]
min_num=100000000000
for i in range(n-1):
    x=x+a[i]
    y=total-x
    min_num=min(min_num,abs(x-y))
print(min_num)


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

long long lcd(long long p, long long q) {
	long long upper, lower, r;

	if (p >= q) upper = p, lower = q;
	else upper = q, lower = p;
	r = upper % lower;
	if (r)return lcd(lower, r);
	else return lower;
}

int main(void) {
	int n;
	long long t[101] = { 0 };
	long long ans;

	scanf("%d", &n);
	for (int i = 0; i < n; i++) scanf("%lld", &t[i]);
	
	ans = t[0];
	for (int i = 1; i < n; i++) {
		ans = ans * (t[i] / lcd(ans, t[i]));
	}
	printf("%lld", ans);
	return 0;
}


Measured memory_bytes: 128
parseInt(x) = parse(Int, x)

function main()
    n,q = split(readline())
    n = parseInt(n)
    q = parseInt(q)
    # -----------Union-Find-----------
    par=Vector{Int}([i for i=1:n])
    siz=ones(Int,n)
    function root(x::Int)
        index=par[x]
        while par[index]!=index
            index=par[index]
        end
        return index
    end
    function unite(x::Int,y::Int)
        rx,ry=root(x),root(y)
        if rx==ry
            return 0
        elseif rx>ry
            rx,ry=ry,rx
        end
        par[ry]=rx
        siz[rx]+=siz[ry]
    end
    function same(x::Int,y::Int)
        isequal(root(x),root(y))
    end
    # --------------------------------
    for i=1:q
        t,u,v = split(readline())
        t = parseInt(t) + 1
        u = parseInt(u) + 1
        v = parseInt(v) + 1
        if t==1
            unite(u,v)
        else
            println(same(u,v) ? 1 : 0)
        end
    end
end

main()


Measured memory_bytes: 208088
package main

import "fmt"

func check(b byte) string {
	switch b {
	case 'a', 'i', 'u', 'e', 'o':
		return "vowel"
	}
	return "consonant"
}

func main() {
	var word string
	fmt.Scan(&word)
	fmt.Println(check(word[0]))
}


Measured memory_bytes: 512
#include <iostream>

using namespace std;
using ll = long long;

#define out(v) cout<<v<<"\n"

int main() {
  cin.tie(0); ios::sync_with_stdio(false);
  ll Q, H, S, D;
  cin >> Q >> H >> S >> D;
  int N;
  cin >> N;

  ll unit = min(4*Q, min(2*Q+H, min(2*H, S)));
  ll ans = 0;
  if (2 * unit > D) {
    ans += (N / 2) * D;
    ans += unit * (N % 2);
  } else {
    ans += unit * N;
  }
  out(ans);

  return 0;
}


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

#define pb push_back
#define pob pop_back
#define pf push_front
#define pof pop_front
#define eb emplace_back
#define rep(i, a, b) for (long i = (a); i <= (b); ++i)
#define per(i, a, b) for (long i = (a); i >= (b); --i)
#define mmst(v) memset(v, 0, sizeof(v))

template<typename T1,typename T2> inline void chmin(T1 & a, T2 b) { if (a > b) a = b; }
template<typename T1,typename T2> inline void chmax(T1 & a, T2 b) { if (a < b) a = b; }

const long kMax2 = 109;
const long kMax3 = 1009;
const long kMax4 = 10009;
const long kMax5 = 100009;
const long kMax6 = 1000009;
const long kMax9 = 1000000010;
const long kInfI = 0x3F3F3F3F;
const float kInfF = 1e15;
const long long kMod = 1000000007;

const long long kMAX = 1000000000;

using namespace std;
using ll = long long;

inline int readInt() {
  char c = getchar();
  while(!isdigit(c) && c != '-') c = getchar();
  int sigma = 1;
  if (c == '-') {
    sigma = -1;
    c = getchar();
  }
  int x = 0;
  while (isdigit(c)) {
    x = x * 10 + c - '0';
    c = getchar();
  }
  return x * sigma;
}

template <class T>
void PrintVector(const vector<T> & v) {
  for (const auto & e: v) {
    cout << e << endl;
  }
}

template <class T>
void PrintVector(const vector<T> & v, int n) {
  rep(i, 0, n - 1) {
    cout << v[i] << endl;
  }
}

int main() {
  long n, m, k, x, y, a, b;
  string s;
  ll ans;
  cin >> n;
  cout << n * n << endl;
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
int main(int argc, char* argv[])
{
	int N;
	cin>>N;
	vector<int> L;
	for (int i=0;i<2*N;i++){
		int l;
		cin>>l;
		L.push_back(l);
	}
	sort(L.begin(),L.end());
	int sum=0;
	for (int i=0;i<2*N;i+=2){
		sum += L[i];
	}
	cout<<sum<<endl;
	return 0;
}

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

int main(){
    int N;
    cin>>N;
    vector<long long> d;
    long long sum=0;
    long long asum=0;

    for(int i=0;i<N;i++){
        long long x;
        cin>>x;
        sum+=x;
        d.push_back(x);
        if(i%2==0) asum+=x;
    }

    vector<long long> ans;
    ans.push_back(2*asum-sum);

    for(int i=0;i<N-1;i++){
        ans.push_back(2*d.at(i)-ans.at(i));
    }

    for(int i=0;i<N;i++) cout<<ans.at(i)<<' ';
    cout<<endl;


}

Measured memory_bytes: 3060
import java.util.*;
public class Main {
	  public static void main(String[] args){
		  Scanner sc = new Scanner(System.in);
		  int n = sc.nextInt();
		  int m = sc.nextInt();
		  int k[]=new int[n];
		  int h[]=new int[m];;
		  int count[]=new int[n];;
		  for(int i=0;i<n;i++){
			  k[i] = sc.nextInt();
		  }			
		  for(int j=0;j<m;j++){
			  h[j]=sc.nextInt();
		  }
		  for(int a=0;a<m;a++){
			  
			  for(int b=0;b<n;b++){
				  if(k[b]<=h[a]){count[b]++;
				  break;
			  }  
			 }
		  }
			  int max = 0;
			  int event =0;
			  for (int i = 0; i<n;i++){
			  if(max<=count[i]){
				  max=count[i];
				  event=i+1;}
			  }
			  System.out.println(event);		
	 }
}
	

Measured memory_bytes: 32108
N, M = map(int, input().split())

L = []
R = []
for i in range(M):
    l,r = map(int, input().split())
    L.append(l)
    R.append(r)

L_max = max(L)
R_min = min(R)

if L_max > R_min:
    print(0)
else:
    print(R_min-L_max+1)


Measured memory_bytes: 85636
import Control.Monad
 
import Data.Ord
import Data.List
import Data.Function
import Data.Maybe

import qualified Data.ByteString.Char8 as BS

import Debug.Trace

tuplify2 :: [a] -> (a, a)
tuplify2 (x:y:_) = (x, y)
tuplify2 _ = undefined

readInt = read :: String -> Integer
readIntTuple = tuplify2 . map readInt . words
readIntList = map readInt . words

getInt = readInt <$> getLine
getIntList = readIntList <$> getLine
getIntMatrix = map readIntList . lines <$> getContents
getIntTuple = readIntTuple <$> getLine
getIntTuples = map readIntTuple . lines <$> getContents

indicesToBools xs = orderedIndicesToBooleans [0..] (sort xs)
  where
    orderedIndicesToBooleans _ []            = repeat False
    orderedIndicesToBooleans (x:xs) yall@(y:ys)
      | x == y    = True  : orderedIndicesToBooleans xs ys
      | otherwise = False : orderedIndicesToBooleans xs yall

main = do
  [n,m] <- getIntList
  as <- concat <$> getIntMatrix
  let combos = 0 : 1 : zipWith3 f (tail (indicesToBools as)) combos (tail combos)
  print $ combos !! (fromIntegral n+1)

-- ある段への移動方法の組み合わせ数を求める
-- a: その段が壊れている
-- prevCombo: 前の段への組み合わせ数
-- prevPrevCombo: 前の前の段への組み合わせ数
f isBroken prevCombo prevPrevCombo
  | isBroken  = 0
  | otherwise = (prevCombo + prevPrevCombo) `mod` 1000000007

Measured memory_bytes: 14588
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;
using static System.Console;
using static System.Math;
using static MyIO;
using static MyUtil;

public class F
{
	public static void Main() => (new Solver()).Solve();
}


public class Solver
{
	public void Solve()
	{
		long[] T = GetLongs(2);
		long[] A = GetLongs(2);
		long[] B = GetLongs(2);

		long P = (A[0] - B[0]) * T[0];
		long Q = (A[1] - B[1]) * T[1];
		if(P + Q == 0)
		{
			WriteLine("infinity");
			return;
		}
		long ans = (P < 0) ? solve(P, Q) : solve(-P, -Q);
		WriteLine(ans);
	}

	private long solve(long P, long Q)
	{
		if(P + Q < 0)
			return 0;

		long S = (-P) / (P + Q);
		long T = (-P) % (P + Q);
		return (T == 0) ? 2 * S : 2 * S + 1;
	}
}

public static class MyIO
{
	private static string[] args = null;
	private static int num = -1;
	private static int used = -1;

	private static string getArg()
	{
		if(used == num)
		{
			args = Console.ReadLine().Split(' ');
			num = args.Length;
			used = 0;
		}
		return args[used++];
	}

	public static int GetInt() => int.Parse(getArg());
	public static long GetLong() => long.Parse(getArg());
	public static double GetDouble() => double.Parse(getArg());
	public static string GetString() => getArg();
	public static char GetChar() => getArg()[0];
	public static int[] GetInts(int N) => Enumerable.Range(0, N).Select(_ => GetInt()).ToArray();
	public static long[] GetLongs(int N) => Enumerable.Range(0, N).Select(_ => GetLong()).ToArray();
	public static double[] GetDoubles(int N) => Enumerable.Range(0, N).Select(_ => GetDouble()).ToArray();
	public static string[] GetStrings(int N) => Enumerable.Range(0, N).Select(_ => GetString()).ToArray();
}

public static class MyUtil
{
	public static void chmax<T>(ref T x, T y) where T : IComparable<T>
	{
		if(x.CompareTo(y) < 0)
			x = y;
	}

	public static void chmin<T>(ref T x, T y) where T : IComparable<T>
	{
		if(x.CompareTo(y) > 0)
			x = y;
	}

	public static void swap<T>(ref T x, ref T y)
	{
		T tmp = x;
		x = y;
		y = tmp;
	}
}

Measured memory_bytes: 13396
#include <iostream>
#include <cmath>
#include <algorithm>
#include <vector>
#include <list>
#include <numeric>
#include <cstdio>


using namespace std;

int main() {

    int N, M;
    cin >> N >> M ;

    vector<int> L(100000);
    int l;
    for (int i = 0; i < N; i++) {
        scanf("%d", &l);
        L[i] = l;
    }

    sort(L.begin(), L.end());

    vector<int>::iterator itr;
    
    for (int i = 0; i < M; i++) {
        int max_L = L.back();
        if (max_L == 0) {
            break;
        }

        max_L /= 2;
        itr = lower_bound(L.begin(), L.end(), max_L);
        L.insert(itr, max_L);
        L.pop_back();
    }

    long long ans = accumulate(L.begin(), L.end(), 0LL);

    cout << ans << '\n';

}


Measured memory_bytes: 1024
def f(a, b):
    return (a // b + int(a % b != 0)) * b


n = int(input())
a = [list(map(int, input().split())) for _ in range(n)]
ans = 0
for i in range(n - 1, -1, -1):
    ans += f(ans + a[i][0], a[i][1]) - a[i][0] - ans
print(ans)

Measured memory_bytes: 27380
#include <stdio.h>
#include <iostream>
#include <map>
#include <memory.h>
#include <vector>
#include <deque>
#include <algorithm>
  
// Shabdan Batyrkulov
  
using namespace std;
  
#define pb push_back
#define fr first
#define sc second
#define mk make_pair
#define ll long long
#define ld long double
#define vi vector <int>
#define pii pair <int, int>
#define OK puts("OK");                                                                           
                                                                                                
const int N = (int)1e5 + 7;                                                                 
const int inf = (int)1e9 + 7;
const int MAX = (int)1e2 + 7;

int main () {                                        
	string a, b, c; cin >> a >> b >> c;
	int n1, n2, n3;
	n1 = a.size();
	n2 = b.size();
	n3 = c.size();
	for (int i = 0; i < min(n2, n3); i++) {
		if (a[n1 - 1] == b[i]) {
			if (b[n2 - 1] == c[i])  {
				puts("YES");
				return 0;
			}
		}
	}	
	puts("NO");
}    


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

int main() {
	int N;
	cin >> N;
	vector<pair<int,int>> nset(N);
	
	for (int i=0;i<N;i++){
		nset.at(i).second=i;
		cin >>nset.at(i).first;
	}
	
	sort(nset.begin(),nset.end());
	reverse(nset.begin(),nset.end());
	
	for (int i= 0;i<N;i++){
		if(i!=nset.at(0).second){
			cout << nset.at(0).first<<endl;
		}
		else {
			cout << nset.at(1).first<<endl;
		}
	}
	
	
}


Measured memory_bytes: 3200
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int maxn = 500;
int n;
ll f[maxn + 1][maxn + 1][maxn + 1], ans = 1e18;
ll s[maxn + 10][maxn + 10], t[maxn + 10][maxn + 10], a[maxn + 10][maxn + 10];

void upd(ll &x, ll y) {
	x = min(x, y);
}

int main() {
	scanf("%d", &n);
	for (int i = 1; i <= n; ++i)
		for (int j = 1; j <= n; ++j) {
			if (i != j) scanf("%lld", &a[i][j]);
			s[i][j] = s[i][j - 1] + a[i][j];
			t[i][j] = t[i - 1][j] + a[i][j];
		}
	memset(f, 0x3f, sizeof f);
	f[1][1][1] = 0;
	for (int i = 1; i < n; ++i)
		for (int j = 1; j <= i; ++j)
			for (int k = 1; k <= j; ++k) {
				upd(f[i + 1][j][k], f[i][j][k] + t[i][i + 1] - t[j - 1][i + 1] + s[i + 1][k - 1]);
				upd(f[i + 1][i + 1][j], f[i][j][k] + s[i + 1][j - 1]);
				upd(f[i + 1][i + 1][i + 1], f[i][j][k] + s[i + 1][i]);
			}
	for (int i = 1; i <= n; ++i)
		for (int j = 1; j <= i; ++j)
			ans = min(ans, f[n][i][j]);
	printf("%lld", ans);
}


Measured memory_bytes: 988800
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(k,i,n) for(ll i=k;i<n;++i)
const ll mod=1e9+7;
int main(void){
    ll s;
    cin>>s;
    ll f[s+1];
    rep(0,i,s+1)f[i]=0;
    f[0]=1;
    rep(0,i,s+1){
        rep(3,j,s+1)if(i+j<s+1)f[i+j]=(f[i]+f[i+j])%mod;
    }
    cout<<f[s];
}


Measured memory_bytes: 3580
#include <iostream>
using namespace std;
int main() {
	int a,c;
	c = 0;
	cin >> a;
	int a100 = a / 100;
	if (a100 == 1) {
		c++;
		a -= 100;
	}
	int a10 = a / 10;
	if (a10 == 1) {
		c++;
		a -= 10;
	}
	if (a == 1) {
		c++;
	} 
	cout << c << endl;
	return 0;
}

Measured memory_bytes: 256
#include <iostream> 
#include<vector>
#include<algorithm>
#include<map>
#include<set>
#include<queue>
#include<iomanip>
#include<sstream>
#include<cmath>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define req(i,n) for(int i = 1;i <=  n; i++)
#define rrep(i,n) for(int i = n -1;i >= 0;i--)
typedef long long int ll;
typedef long double ld;
const ll inf = (1LL << 60);
const int MOD = 1000000007;
template<typename A, size_t N, typename T>
void Fill(A(&array)[N], const T & val) {
    std::fill((T*)array, (T*)(array + N), val);
}
ll n, m, k, a[50], b[50], c[50], d[50], ans = inf,sum;
int main() {
    cin >> n >> k; vector<int> x(n);
    rep(i, n) cin >> x[i];
    rep(i, n - k + 1) {
        sum = min(abs(x[i]),abs(x[i+k - 1])) + abs(x[i + k -1]- x[i]);
        ans = min(ans, sum);
    }cout << ans << endl;
}

Measured memory_bytes: 640
#include<stdio.h>

void spin_w(int x[]){
  int sai1[6],i;

  for(i=0;i<6;i++){
    sai1[i]=x[i];
  } 

  sai1[0]=x[2];
  sai1[2]=x[5];
  sai1[3]=x[0];
  sai1[5]=x[3];

  for(i=0;i<6;i++){
    x[i]=sai1[i];
  }

}

void spin_s(int x[]){
int sai1[6],i;

  for(i=0;i<6;i++){
    sai1[i]=x[i];
  } 
  sai1[0]=x[4];
  sai1[1]=x[0];
  sai1[4]=x[5];
  sai1[5]=x[1];

  for(i=0;i<6;i++){
    x[i]=sai1[i];
  }

}


int main(){
 
  int i,a=0,j,sai1[6];
  char dic[101];
  for(i=0;i<6;i++){
    scanf("%d",&sai1[i]);
  }
  scanf("%s",dic);
  
  for(i=0;i<=100;i++){
    if(dic[i]=='\0')break;
    
    if(dic[i]=='W'){
      spin_w(sai1);
    }else if(dic[i]=='E'){
      for(j=0;j<3;j++){
	spin_w(sai1);
      }
    }else if(dic[i]=='S'){
      spin_s(sai1);

    }else if(dic[i]=='N'){
      for(j=0;j<3;j++){
	spin_s(sai1);
      }
    }
  }
  printf("%d\n",sai1[0]);
  return 0;
}

Measured memory_bytes: 1028