akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;
int main(){
    int h,w;
    cin>>h>>w;
    vector<vector<char>>s(h,vector<char>(w));
    for(int i=0;i<h;i++){
        for(int j=0;j<w;j++)cin>>s[i][j];
    }
    int m=0;
    for(int sx=0;sx<h;sx++){
        for(int sy=0;sy<w;sy++){
                    vector<vector<int>>dist(h,vector<int>(w,1000));//startからの距離
                    if(s[sx][sy]=='#')continue;
                    dist[sx][sy]=0;
                    int maxdist=0;
                    queue<int>x;
                    queue<int>y;
                    x.push(sx);
                    y.push(sy);
                    while(x.size()>0){
                        int xf=x.front();
                        int yf=y.front();
                        maxdist=max(maxdist,dist[xf][yf]);
                        if(xf<h-1 && s[xf+1][yf]=='.' && dist[xf+1][yf]==1000){//x正方向
                            x.push(xf+1);
                            y.push(yf);
                            dist[xf+1][yf]=dist[xf][yf]+1;
                        }
                        if(yf<w-1 && s[xf][yf+1]=='.' && dist[xf][yf+1]==1000){//y正方向
                            x.push(xf);
                            y.push(yf+1);
                            dist[xf][yf+1]=dist[xf][yf]+1;
                        }
                        if(xf>0 && s[xf-1][yf]=='.' && dist[xf-1][yf]==1000){//x負方向
                            x.push(xf-1);
                            y.push(yf);
                            dist[xf-1][yf]=dist[xf][yf]+1;
                        }
                        if(yf>0 && s[xf][yf-1]=='.' && dist[xf][yf-1]==1000){//y負方向
                            x.push(xf);
                            y.push(yf-1);
                            dist[xf][yf-1]=dist[xf][yf]+1;
                        }
                        x.pop();
                        y.pop();
                    }
                    m=max(m,maxdist);
        }
    }
    cout<<m<<endl;
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define endl "\n" 
#define pi acos(-1)
#define ll long long 
using namespace std;
void solve();
int main(){
	//att();//sirra();
	int q=1;//cin>>q;
	while(q--){
		solve();
	}
}
void solve(){
	int n,ac(0),wa(0),tle(0),re(0);
  	string s1("AC"),s2("WA"),s3("TLE"),s4("RE"),s;
  cin>>n;
  for(int i=0;i<n;i++){
    cin>>s;
    if(s==s1)
      ac++;
    else if(s==s2)
      wa++;
    else if(s==s3)
      tle++;
    else
      re++;
  }
  cout<<s1<<" x "<<ac<<endl;
  cout<<s2<<" x "<<wa<<endl;
  cout<<s3<<" x "<<tle<<endl;
  cout<<s4<<" x "<<re<<endl;
}


Measured memory_bytes: 3600
#include <set>
#include <map>
#include <list>
#include <queue>
#include <stack>
#include <cmath>
#include <ctime>
#include <cstdio>
#include <vector>
#include <string>
#include <bitset>
#include <cctype>
#include <cstdlib>
#include <cstring>
#include <utility>
#include <numeric>
#include <complex>
#include <sstream>
#include <fstream>
#include <iomanip>
#include <cassert>
#include <iostream>
#include <iterator>
#include <algorithm>
using namespace std;
typedef long long ll;
const double EPS = 1e-9;
typedef vector<int> vint;
typedef pair<int, int> pint;
#define rep(i, n) REP(i, 0, n)
#define ALL(v) v.begin(), v.end()
#define MSG(a) cout << #a << " " << a << endl;
#define REP(i, x, n) for(int i = x; i < n; i++)
template<class T, class C> void chmax(T& a, C b){ a>b?:a=b; }
template<class T, class C> void chmin(T& a, C b){ a<b?:a=b; }

int main(){
  string S; cin>>S;
  if(S=="ABC") cout<<"ARC"<<endl;
  else cout<<"ABC"<<endl;
}

Measured memory_bytes: 3608
# coding=utf-8

n = int(input())
s = list(map(int, input().split()))
for i in range(1, n):
    s[i] += s[i-1]

ans = 0
s = sorted(s)
i = 0
while True:
    mid = 0
    for j in range(i+1, n):
        if s[j] == s[i]:
            mid += 1
            ans += mid
        else:
            break
    if s[i] == 0:
        ans += mid+1
    i += mid
    i += 1
    if i >= n:
        break
print(ans)


Measured memory_bytes: 90064
#include <algorithm>
#include <iostream>
#include <string>
#include <random>
#include <cassert>
#include <cstring>
#include <chrono>

using namespace std;

typedef long long ll;

int main()
{
  int n, a, b;
  cin >> n >> a >> b;
  if ((a + b) % 2 == 0) {
    cout << "Alice\n";
  } else {
    cout << "Borys\n";
  }
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
 
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define endl "\n"
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define rrep(i, n) for(int i = ((int)(n)-1); i >= 0; i--)
#define all(x) (x).begin(),(x).end()
 
using namespace std;
using ll = long long;
 
struct edge { int to, cost; };
 
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int,int> P;
 
const int INF = 1e9;
const double EPS = 1e-10;
const int MOD = 1e9+7;
const double PI = acos(-1.0);

const int mx4[] = {0,1,0,-1};
const int my4[] = {1,0,-1,0};
const int mx8[] = {0,1,1,1,0,-1,-1,-1};
const int my8[] = {1,1,0,-1,-1,-1,0,1};

int main()
{
	int n,k;
	cin >> n >> k;
	vi v(n);
	rep(i,n) cin >> v[i];

	ll ans = 0;
	for(int left = 0; left <= min(n,k); left++){
		for(int right = 0; right <= min(n,k); right++){
			if(left+right > min(n,k)) break;
			vi num;
			for(int i = 0; i < left; i++) num.emplace_back(v[i]);
			for(int i = 0; i < right; i++) num.emplace_back(v[n-1-i]);
			sort(all(num));
			for(int i = 0; i < num.size() && num[i] < 0 && i < k-left-right; i++){
				num[i] = 0;
			}
			ll sum = 0;
			for(int i = 0; i < num.size(); i++) sum += num[i];
			ans = max(ans,sum);
		}
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#include<iostream>
#include<string>
#include<cmath>
#include<cstdio>
#include<cctype>
#include<cstring>
#include<iomanip>
#include<cstdlib>
#include<ctime>
#include<set>
#include<map>
#include<utility>
#include<queue>
#include<vector>
#include<stack>
#include<sstream>
#include<algorithm>
/************************************************/
#define rep(i,n) for(int i=0;i<n;i++)
#define m_p make_pair
#define pb push_back
#define fr first
#define se second
#define forn(i,a,n) for(int i=a;i<n;i++)
#define foreach(i,c) for(__typeof(c.begin())i=(c.begin());i!=(c).end();i++)
#define pii pair<int,int>
#define vi vector<int>
#define ll long long
#define sz(s) s.size()
#define all(s) s.begin(),s.end()
#define zero(x) memset(x,0,sizeof(x))
#define vii vector<pair<int,int> >
#define mpis map<int,string>
#define mpii map<int,int>
#define mpsi map<string,int>
#define re return
#define mod 1000000007
/************************************************/
using namespace std;

long long get(){
	char c=getchar();
	long long x=0LL;
	while(c<'0'||c>'9')
	c=getchar();
	while(c>='0'&&c<='9'){
		x*=10LL;
		x+=(c-'0');
		c=getchar();
	}
	return x;
}
int a,b,c,k;
int main(){
	ios::sync_with_stdio(0);
	cin>>a>>b>>c>>k;
	while(k&&b<=a){
		b*=2;
		k--;
	}
	if(b<=a){
		cout<<"No";
		re 0; 
	}
	while(k&&c<=b){
		c*=2;
		k--;
	}
	if(c<=b){
		cout<<"No";
		re 0; 
	}
	cout<<"Yes";
	re 0;
}

Measured memory_bytes: 3644
//min, max, sum
#include <stdio.h>

int main(void)
{
    int n;
    int i, min, max;
    long sum;
    scanf("%d%d",&n,&i);
    min = max = sum = i;
    for (; n>1; n--)
    {
        scanf("%d",&i);
        if (i < min)
        {
            min = i;
        }
        if (i > max)
        {
            max = i;
        }
        sum += i;
    }
    printf("%d %d %ld\n",min,max,sum);
    //printf("%d %d",n,i);
    return 0;
}



Measured memory_bytes: 2124
s = input()
b = ''
ans = [-1,-1]
for i in range(len(s)):
    a = s[i]
    if a == b:
        ans = [i,i+1]
    b = s[i]
b = ''
for i in range(0,len(s),2):
    a = s[i]
    if a == b:
        ans = [i-1,i+1]
    b = s[i]
b = ''
for i in range(1,len(s),2):
    a = s[i]
    if a == b:
        ans = [i-1,i+1]
    b = s[i]

print(*ans)

Measured memory_bytes: 3188
a = int(input())
b = int(input())
if a == 1:
  if b == 2:
    print(3)
  elif b == 3:
    print(2)
elif a == 2:
  if b==1:
    print(3)
  elif b==3:
    print(1)
elif a==3:
  if b==1:
    print(2)
  elif b== 2:
    print(1)

Measured memory_bytes: 3060
#include <bits/stdc++.h>
#include <math.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep2(i, s, n) for (int i = (s); i < (int)(n); i++)
using ll = long long;
using vec = vector<ll>;
using vec2 = vector<vector<ll>>;
ll inf = pow(2, 62);

int main(){
    ll x,k,d;cin >> x >> k >> d;
    x = abs(x);
    //折り返しなし
    ll ans = 0;
    if(x/d >= k){
        ans = x - k*d;
    }else{
        ll e = x/d;
        k = k - e;
        x = x - d*e;
        if(k%2 == 0){
            ans = x;
        }else{
            ans = abs(x-d);
        }
    }
    cout << ans << endl;
}


Measured memory_bytes: 3544
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
//#define int long long

template <class T>
bool INRANGE(T x, T a, T b) { return a <= x && x <= b; }
template <class T>
bool chmax(T &a, const T &b) {if (a < b){ a = b; return 1;} return 0;}
template <class T>
bool chmin(T &a, const T &b) {if (a > b){ a = b; return 1;}return 0;}
template <class T>
void printv(vector<T> v) {for (T t : v) {cout << t << " ";}cout << '\n';}

#define REP(i, n) for (int i = 0; i < (n); ++i)
#define RREP(i, n) for (int i = (n); i >= 0; --i)
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define RFOR(i, a, b) for (int i = (a); i >= (b); --i)
#define ALL(v) (v).begin(), (v).end()
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" \
                      << " " << __FILE__ << endl;

typedef vector<int> vi;
typedef vector<string> vs;
typedef vector<vi> vvi;
typedef pair<int, int> pii;

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

    string s;
    cin >> s;

    map<char, int> m;

    for (char c : s){
        m[c]++;
    }

    if (m.size() == 2) cout << "Yes" << endl;
    else cout << "No" << endl;

    return 0;
}


Measured memory_bytes: 256
import collections
def prime_factorize(n):
    a = []
    while n % 2 == 0:
        a.append(2)
        n //= 2
    f = 3
    while f * f <= n:
        if n % f == 0:
            a.append(f)
            n //= f
        else:
            f += 2
    if n != 1:
        a.append(n)
    return a

n=int(input())
m=prime_factorize(n)
M=m[::-1]
#print(m)
if m==[n]:print(n-1)
else:
    a=int(n**(1/2))
    l=[]
    for i in range(1,a+1):
        if n%i==0:
            l.append(i)
    #print(l)
    ans=(l[-1]-1)+(n//l[-1]-1)
    print(ans)



Measured memory_bytes: 40404
import Data.Char (digitToInt)

main :: IO ()
main = solve . map (read :: String -> Int) . words <$> getLine >>= print

f :: Int -> Int
f d | d1 > 1 && d2 > 1 = product $ map digitToInt $ show d
    | otherwise        = 0
    where
        d1 = d `div` 10
        d2 = d `mod` 10

solve :: [Int] -> Int
solve [m, d] = length [0 | x <- [1..m], y <- [1..d], x == f y]

Measured memory_bytes: 764
#include <iostream>
#include <cmath>
#include <vector>
#define rep(i,n) for(int i=0;i<(n);++i)

using namespace std;
typedef long long ll;




int main(){
 
    int ans[26];
    int tmp[26];
    int n;
    cin>>n;
    
    
    rep(i,26)ans[i]=0;
    
    
    rep(i,n){
        string s;
        cin>>s;
        rep(i,26)tmp[i]=0;
        
        for(int j=0;j!=s.size();++j){
           int a= s[j]-'a';
            ++tmp[a];
        }
        if(i==0){
            rep(j,26){ans[j]=tmp[j];};
        }else{
            rep(j,26){ans[j]=ans[j]<=tmp[j]?ans[j]:tmp[j];};
        }
        
    }

    rep(i,26){
        for(int j=0;j<ans[i];++j){
            if(ans[j]!=100){
               cout<<(char)('a'+i);
            }
        }
    }
    
    cout<<endl;
}


Measured memory_bytes: 3560
#include <cstdio>
const int mod = 1000000007;
const int inv2 = 500000004;
int n, m, dp[5009][5009]; char s[5009];
int main() {
	scanf("%d %s", &n, s); while (s[m]) m++; dp[0][0] = 1;
	for (int i = 1; i <= n; i++) {
		for (int j = 0; j <= i; j++) {
			dp[i][j] = dp[i - 1][j + 1] + (j != 0 ? dp[i - 1][j - 1] >= inv2 ? dp[i - 1][j - 1] * 2 - mod : dp[i - 1][j - 1] * 2 : dp[i - 1][0]);
			if (dp[i][j] >= mod) dp[i][j] -= mod;
		}
	}
	for (int i = 0; i < m; i++) dp[n][m] = 1LL * dp[n][m] * inv2 % mod;
	printf("%d\n", dp[n][m]);
	return 0;
}

Measured memory_bytes: 96384
#include<stdio.h>

int main(void){

char str[1010];

int i,sum;

scanf("%s",str);

while(str[0]!='0'){

i=0;

sum=0;

while(str[i]){

sum+=str[i]-'0'; i++;

}

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

scanf("%s",str);

}

return 0;

} 

Measured memory_bytes: 536
//#define _GLIBCXX_DEBUG

#include<bits/stdc++.h>
#define PI 3.14159265359
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
const int INF= 1e9+5;
typedef long long ll;
typedef vector<int> vi;
typedef vector<vector<int>>vvi;

int main(){
  ll n,k;
  cin>>n>>k;
  vector<ll>x(n);
  rep(i,n)cin>>x[i];
  ll MIN=INF;
  ll ans;
  for(int i=0;i+k-1<n;i++){
    ll l=x[i];
    ll h=x[i+k-1];
    if(l<=0 && h<=0)ans=max(abs(l),abs(h));
    else if(l>=0 && h>=0)ans=max(abs(l),abs(h));
    else ans=min(abs(l),abs(h))*2+max(abs(l),abs(h));
    MIN=min(ans,MIN);
  }
  cout<<MIN<<endl;
}
    

Measured memory_bytes: 1024
import java.util.Scanner;

class Main{
 public static void main(String args[]){
   Scanner sc = new Scanner(System.in);
   int a = sc.nextInt();
   int b = sc.nextInt();
   int c = sc.nextInt();
   int d = sc.nextInt();
   boolean flag=false;
   
   for(int i=0;;i++){
   c=c-b;
   if(c<=0){
   flag=true;
   break;}
   a=a-d;
   if(a<=0){
   break;}
   }

   if(flag){
     System.out.println("Yes");
   }else{
     System.out.println("No");
   }
 
 }
}


Measured memory_bytes: 35680
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner scanner = new Scanner(System.in);
		int N = scanner.nextInt();
		int K = scanner.nextInt();
		if (N % K == 0)
			System.out.println(0);
		else
			System.out.println(1);
		scanner.close();
	}
}

Measured memory_bytes: 23892
#include<iostream>
#include<algorithm>
#include<vector>

#define rep(i, n) for(int i = 0; i < n; i++)
typedef long long typeLong;

using namespace std;

const int INF = 100;

int main()
{

	for (int i = 0; i < 50; i++) {
		int m, f, r;
		cin >> m >> f >> r;

		if (m == -1 && f == -1 && r == -1)break;
		if (m == -1 && f == -1 && r == -1)break;

		//中間もしくは期末と再試験不参加はF
		if ((m == -1 || f == -1) && r == -1) {
			cout << "F" << endl;
			continue;
		}

		int sum = m + f;
		if (sum >= 80) {
			cout << "A";
		}
		else if (sum >= 65) {
			cout << "B";
		}
		else if (sum >= 50 || r >= 50) {
			cout << "C";
		}
		else if (sum >= 30) {
			cout << "D";
		}
		else {
			cout << "F";
		}

		cout << endl;
	}

	return 0;
}



Measured memory_bytes: 3096
package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
)

func main() {
	sc := NewScanner()
	N := sc.NextInt()
	A := sc.NextMap()

	for i := 1; i <= N; i++ {
		fmt.Println(A[i])
	}
}

type Scanner struct {
	r   *bufio.Reader
	buf []byte
	p   int
}

func NewScanner() *Scanner {
	rdr := bufio.NewReaderSize(os.Stdin, 1000)
	return &Scanner{r: rdr}
}
func (s *Scanner) Next() string {
	s.pre()
	start := s.p
	for ; s.p < len(s.buf); s.p++ {
		if s.buf[s.p] == ' ' {
			break
		}
	}
	result := string(s.buf[start:s.p])
	s.p++
	return result
}
func (s *Scanner) NextLine() string {
	s.pre()
	start := s.p
	s.p = len(s.buf)
	return string(s.buf[start:])
}
func (s *Scanner) NextInt() int {
	v, _ := strconv.Atoi(s.Next())
	return v
}
func (s *Scanner) NextInt64() int64 {
	v, _ := strconv.ParseInt(s.Next(), 10, 64)
	return v
}

func (s *Scanner) NextFloat() float64 {
	v, _ := strconv.ParseFloat(s.Next(), 64)
	return v
}

func (s *Scanner) NextIntArray() []int {
	s.pre()
	start := s.p
	result := []int{}
	for ; s.p < len(s.buf)+1; s.p++ {
		if s.p == len(s.buf) || s.buf[s.p] == ' ' {
			v, _ := strconv.ParseInt(string(s.buf[start:s.p]), 10, 0)
			result = append(result, int(v))
			start = s.p + 1
		}
	}

	return result
}
func (s *Scanner) NextInt64Array() []int64 {
	s.pre()
	start := s.p
	result := []int64{}
	for ; s.p < len(s.buf)+1; s.p++ {
		if s.p == len(s.buf) || s.buf[s.p] == ' ' {
			v, _ := strconv.ParseInt(string(s.buf[start:s.p]), 10, 64)
			result = append(result, v)
			start = s.p + 1
		}
	}
	return result
}

func (s *Scanner) NextMap() map[int]int {
	s.pre()
	start := s.p
	mp := map[int]int{}
	for ; s.p < len(s.buf); s.p++ {
		if s.buf[s.p] == ' ' {
			v, _ := strconv.Atoi(string(s.buf[start:s.p]))
			mp[v]++
			start = s.p + 1
		}
	}
	v, _ := strconv.Atoi(string(s.buf[start:s.p]))
	mp[v]++

	return mp
}

func (s *Scanner) pre() {
	if s.p >= len(s.buf) {
		s.readLine()
		s.p = 0
	}
}
func (s *Scanner) readLine() {
	s.buf = make([]byte, 0)
	for {
		l, p, e := s.r.ReadLine()
		if e != nil {
			panic(e)
		}
		s.buf = append(s.buf, l...)
		if !p {
			break
		}
	}
}


Measured memory_bytes: 15928
/*Function Template*/
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef pair<ll,ll> pint;
const int MAX = 510000;
const int MOD = 1000000007;
#define rep(i, n) for(ll i = 0; i < (n); i++)
#define Rep(i, n) for(ll i = 1; i < (n); i++)
#define ALL(a)  (a).begin(),(a).end()
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
ll fac[MAX], finv[MAX], inv[MAX];


template<class T> inline bool chmin(T& a, T b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}
template<class T> inline bool chmax(T& a, T b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}
// テーブルを作る前処理
void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (ll i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }

}
ll Len(ll n) {
  ll s=0;
  while(n!=0) s++, n/=10;
  return s;
}


ll Sint(ll n) {
  ll m=0,s=0,a=n;
  while(a!=0) s++, a/=10;
  for(ll i=s-1;i>=0;i--) m+=n/((ll)pow(10,i))-(n/((ll)pow(10,i+1)))*10;
  return m;
}


ll Svec(vector<ll> v){
  ll n=0;
  for(ll i=0;i<v.size();i++) n+=v[i];
  return n;
}


ll GCD(ll a,ll b) {
  return b ? GCD(b,a%b) : a;
}


ll LCM(ll a,ll b){
  return a/GCD(a,b)*b;
}


ll Factorial(ll n){
  ll m=1;
  while(n>=1) m*=n,n--;
  return m;
}

void runlength(string s,vector<pair<char,ll>> &p){
  ll x=1;
  if(s.size()==1){
    p.push_back(pair<char,ll>(s[0],1));
  }
  for(ll i=0;i<s.size()-1;i++){
    if(s[i]==s[i+1]){
      x++;
      if(i==s.size()-2){
        p.push_back(pair<char,ll>(s[i],x));
      }
    }else{
      p.push_back(pair<char,ll>(s[i],x));
      x=1;
      if(i==s.size()-2){
        p.push_back(pair<char,ll>(s[s.size()-1],x));
      }
    }
  }
}




ll COM(ll n,ll k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

const int MAX_N=100010;
vector<bool> sieve_of_eratosthenes(){
  vector<bool> isPrime(MAX_N+1,true);
  for(int i=2;i<=MAX_N;i++){
    if(isPrime[i]){
      for(int j=2*i;j<=MAX_N;j+=i){
        isPrime[j]=false;
      }
    }
  }
  return isPrime;
}

vector<pint> prime_factorize(ll n){
  vector<pint> ans;
  for(ll i=2;i<=sqrt(n);i++){
    if(n%i!=0) continue;
    ll tmp=0;
    while(n%i==0){
      n/=i;
      tmp++;
    }
    ans.push_back(make_pair(i,tmp));
  }
  if(n!=1) ans.push_back(make_pair(n,1));
  return ans;
}

/*↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓*/
int main() {
  IOS;
  ll a,b;
  cin>>a>>b;
  ll tmp=GCD(a,b);
  vector<pint> v=prime_factorize(tmp);
  cout<<v.size()+1<<endl;
}



Measured memory_bytes: 256
#include<map>
#include<iostream>
#include<deque>
#include<algorithm>
#include<string>
#include<cctype>
#include<iomanip>
#include<vector>
#include<queue>
 
using namespace std;
#define REP(i,b,e) for(int i=(int)b;i<(int)e;i++)
#define rep0(i,n) REP(i,0,n)
#define rep1(i,n) REP(i,1,n+1)
 
#define shosu setprecision(10)
 
typedef long long ll;
ll longinf=1ll<<60;
int inf=1<<29;

int N;
 
int main(){
    cin>>N;
    if(N<1200) cout<<"ABC"<<endl;
    else if(N<2800) cout<<"ARC"<<endl;
    else cout<<"AGC"<<endl;
    return 0;
}

Measured memory_bytes: 768
n = int(input())
xy = []
flag = "f"
for i in range(0,n):
    X,Y = map(int,input().split())
    xy.append((X,Y))
    if i == 0:
        m = (X+Y)%2
    if m != (X+Y)%2:
        flag = "t"
if flag == "t":
    print(-1)
    exit()

d = [2**i for i in range(31,-1,-1)]

if m == 0:
    d.append(1)

print(len(d))
for i in range(0,len(d)):
    print(d[i],end = " ")
print()
for i in range(0,n):
    x,y = xy[i]
    w = ""
    for j in range(0,len(d)):
        if y <= x and  y >= -x:
            w += "R"
            x -= d[j]
        elif y >= x and y >= -x:
            w += "U"
            y -= d[j]
        elif y > x and y < -x:
            w += "L"
            x += d[j]
        else:
            w += "D"
            y += d[j]
    print(w)


Measured memory_bytes: 3316
use std::io;
use std::io::prelude::*;

fn main() {
    let stdin = io::stdin();
    let mut input = String::new();
    stdin.lock().read_line(&mut input).expect("read line!");
    println!("{}", solve(input.trim().to_string()));
}

fn solve(mut input: String) -> u32 {
    if input.len() % 2 == 0 {
        input.pop();
    }
    while let Some(_) = input.pop() {
        let l = input.len();
        if &input[0..l / 2] == &input[l / 2..] {
            return l as u32;
        }
        input.pop();
    }
    0
}


Measured memory_bytes: 4352
from operator import le, ge

n = int(input())

a_list = list(map(int, input().split()))
prev_a = a_list[0]
cmp = None
cmps = [le, ge]
ans = 1
for a in a_list[1:]:
    if cmp is None:
        if prev_a < a:
            cmp = cmps[0]
        elif prev_a > a:
            cmp = cmps[1]
    else:
        if not cmp(prev_a, a):
            ans += 1
            cmp = None
    prev_a = a

print(ans)


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

int main()
{
	int N,K;
	ll c=0,d=0;
	cin >> N >> K;

	for(int i=1;i<=N;i++)
	{
		if(i%K==0)c++;
		if(K%2==0&&i%K==K/2)d++;
	}
	cout<<(c*c*c)+(d*d*d)<<endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <string>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <algorithm>
#include <numeric>
#include <cmath>
#include <cassert>

using namespace std;
typedef long long LL;
template <typename F, typename S> std::ostream& operator<<(ostream& os, const pair<F,S>& p) {
    os << "(" << p.first << "," << p.second << ")"; return os; }
template <typename T> ostream& operator<<(ostream& os, const vector<T>& v) {
    os << "["; for(const T& a: v){ os << a << ", "; } os << "]"; return os; }
template <typename K, typename V> ostream& operator<<(ostream& os, const map<K,V>& m) {
    os << "{"; for(const auto& p: m){ os << p.first <<":"<< p.second << ", "; } os << "}"; return os; }


// import here

int main(){
    LL n;
    cin >> n;
    vector<LL> p(n);
    vector<LL> idx(n);
    for(LL i = 0; i < n; ++i){
        cin >> p[i];
        idx[p[i]-1] = i;
    }
    LL ans = 0;
    set<LL> used;
    used.insert(idx[n-1]);
    used.insert(-2);
    used.insert(-1);
    used.insert(n);
    used.insert(n+1);
    for(LL i = n-2; i >= 0; --i){
        auto it = used.lower_bound(idx[i]);
        LL r1 = min(n, *it);
        LL r2 = min(n, *used.lower_bound(r1+1));
        LL l1 = max<LL>(-1, *(--it));
        LL l2 = max<LL>(-1, *(--it));
        LL cnt = (r2-r1)*(idx[i]-l1) + (l2-l1)*(idx[i]-r1);
        ans += cnt * (i+1);
        //cerr << (i+1) << ", " << cnt << endl;
        used.insert(idx[i]);
    }
    cout << ans << endl;
    return 0;
}



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

using namespace std;
#define ll long long
const long double EPS = 1e-8;
const long double PI = acos(-1);
const int N = 1e4 + 9;
int n, m;
ll mem[N][N];
char arr[N][N];
const int mod = 1e9+7;
int main() {
    cin >> n >> m;
    for (int i = 0; i < n; i++) {
        for (int j = 0; j < m; j++) {
            cin >> arr[i][j];
        }
    }
    mem[0][0] = 1;
    for (int i = 0; i < n; i++) {
        for (int j = 0; j < m; j++) {
            if(arr[i][j]=='#')continue;
            if (i != 0)mem[i][j] = (mem[i][j] + mem[i - 1][j]) % mod;
            if (j != 0)mem[i][j] = (mem[i][j] + mem[i][j - 1]) % mod;
        }
    }
    cout << mem[n-1][m-1] << endl;
}


Measured memory_bytes: 89344
def main():
	N, K = map(int,input().split())
	ans = 0
	for b in range(1, N+1):
		ans += (N//b)*max(0, b-K) + max(0, N%b-K+1)
	if K == 0:
		ans -= N

	print(ans)


if __name__ == '__main__':
    main()

Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
#define dbg(x) #x "=" << x << " "
#define fore(i,a,b) for(int i=a,gon=b;i<gon;++i)
#define pb push_back
#define F first
#define S second
typedef double lf;
typedef long long ll;
typedef pair<int, int> pii;

int count(int n, int f) {
    int cnt = 0;
    while (n) {
        cnt += n/f;
        n /= f;
    }
    return cnt;
}

int main() {
    ios::sync_with_stdio(0);
    cin.tie(0);
    #ifdef LOCAL
        freopen("in.txt", "r", stdin);
        //freopen("out.txt", "w", stdout);
    #else
        #define endl '\n'
    #endif
    int n, M = 1e9+7;
    cin >> n;
    vector<int> primes, mark(n+1, 1);
    fore(i,2,n+1) if (mark[i]) {
        primes.pb(i);
        for (int j = i*2; j <= n; j += i) {
            mark[j] = false;
        }
    }
    ll ans = 1;
    for (auto &p : primes) {
        ans = (ans * (count(n, p)+1)) % M;
    }
    cout << ans << endl;
}


Measured memory_bytes: 256
#include<algorithm>
#include<cstdio>
#define mxn 100010
using namespace std;
const int inf=1e9;
int n,rt,sl,fh,res,ans,a[mxn],f[mxn],g[mxn],dp[mxn];
int t,h[mxn];
struct Tre
{
	int to,nxt;
}e[mxn<<1];
int rd()
{
	sl=0;fh=1;
	char ch=getchar();
	while(ch<'0'||'9'<ch) {if(ch=='-') fh=-1; ch=getchar();}
	while('0'<=ch&&ch<='9') sl=sl*10+ch-'0',ch=getchar();
	return sl*fh;
}
void add(int u,int v)
{
	e[++t]=(Tre){v,h[u]};h[u]=t;
	e[++t]=(Tre){u,h[v]};h[v]=t;
}
void dfs1(int u,int fa)
{
	int v;f[u]=0;g[u]=a[u];
	for(int i=h[u];i;i=e[i].nxt)
		if((v=e[i].to)!=fa)
		{
			dfs1(v,u);
			f[u]+=f[v]+g[v];
			g[u]+=g[v];
		}
}
void dfs2(int u,int fa)
{
	int v,w=0;dp[u]=0;
	for(int i=h[u];i;i=e[i].nxt)
		if((v=e[i].to)!=fa)
			if(f[v]+g[v]>f[w]+g[w])
				w=v;
	int mx=f[w]+g[w];
	if(mx*2<=f[u]) return (void)(dp[u]=f[u]/2);
	dfs2(w,u);
	dp[u]=f[u]-mx+min(dp[w],(mx*2-f[u])/2);
}
void solve()
{
	dfs1(rt,0);
	if(f[rt]&1) return ;
	dfs2(rt,0);
	if(f[rt]!=dp[rt]*2) return ;
	if(dp[rt]<ans) ans=dp[rt];
}
int main()
{
	n=rd();ans=inf;
	for(int i=1;i<=n;++i) scanf("%1d",a+i);
	for(int i=1;i<n;++i) add(rd(),rd());
	for(int i=1;i<=n;++i) rt=i,solve();
	printf("%d\n",ans<inf?ans:-1);
	return 0;
}

Measured memory_bytes: 384
# include <iostream>
# include <algorithm>
#include <array>
# include <cassert>
#include <cctype>
#include <climits>
#include <numeric>
# include <vector>
# include <string>
# include <set>
# include <map>
# include <cmath>
# include <iomanip>
# include <functional>
# include <tuple>
# include <utility>
# include <stack>
# include <queue>
# include <list>
# include <bitset>
# include <complex>
# include <chrono>
# include <random>
# include <limits.h>
# include <unordered_map>
# include <unordered_set>
# include <deque>
# include <cstdio>
# include <cstring>
using namespace std;
using LL = long long;
using ULL = unsigned long long;
constexpr long long MOD = 1000000000 + 7;
constexpr long long INF = 1e17 - 10;
const double PI = acos(-1);
typedef pair<LL, LL> Pll;
typedef pair<LL, pair<LL, LL>> Ppll;
typedef pair<LL, pair<LL, bitset<100001>>> Pbll;
typedef pair<LL, pair<LL, vector<LL>>> Pvll;
typedef pair<LL, LL> Vec2;
struct Tll { LL first, second, third; };
typedef pair<LL, Tll> Ptll;
#define rep(i,rept) for(LL i=0;i<rept;i++)
#define Mfor(i,mf) for(LL i=mf-1;i>=0;i--)
struct Edge { LL to, cost; };
LL h, w, n, m, s[100000], t, k, p, q, ans = 0, d[100000];
int main() {
	cin >> n;
	cout << 0 << endl;
	string str;
	cin >> str;
	if (str == "Vacant")
		return 0;
	d[0] = (str == "Male" ? 1 : 2);
	d[n] = d[0];
	int high = n, low = 0, midle = (high + low) / 2;
	while (true) {
		midle = (high + low) / 2;
		cout << midle << endl;
		cin >> str;
		if (str == "Vacant")
			return 0;
		d[midle] = (str == "Male" ? 1 : 2);
		if (low % 2 == midle % 2)
			if (d[low] == d[midle]) {
				low = midle;
			}
			else high = midle;
		else 	if (d[low] == d[midle]) {
			high = midle;
		}
		else low = midle;
	}
	return 0;
}

Measured memory_bytes: 852
#include <bits/stdc++.h>
#define DEBUG fprintf(stderr, "Passing [%s] line %d\n", __FUNCTION__, __LINE__)
#define File(x) freopen(x".in","r",stdin); freopen(x".out","w",stdout)
#define int long long

using namespace std;

typedef long long LL;
typedef pair <int, int> PII;
typedef pair <int, PII> PIII;

template <typename T>
inline T gi()
{
	T f = 1, x = 0; char c = getchar();
	while (c < '0' || c > '9') {if (c == '-') f = -1; c = getchar();}
	while (c >= '0' && c <= '9') x = x * 10 + c - '0', c = getchar();
	return f * x;
}

const int INF = 0x3f3f3f3f, N = 300003, M = N << 1, mod = 1000000007;

int n, m, k, ans;
int fac[N * 3], inv[N * 3], f[M];

inline int qpow(int a, int b)
{
	int res = 1;
	while (b)
	{
		if (b & 1) res = res * a % mod;
		a = a * a % mod, b >>= 1;
	}
	return res;
}

inline int C(int a, int b)
{
	if (a < b || a < 0 || b < 0) return 0;
	return fac[a] * inv[b] % mod * inv[a - b] % mod;
}

signed main()
{
	//File("");
	n = gi <int> (), m = gi <int> (), k = gi <int> ();
	fac[0] = 1;
	for (int i = 1; i <= n + m + k; i+=1) fac[i] = fac[i - 1] * i % mod;
	inv[n + m + k] = qpow(fac[n + m + k], mod - 2);
	for (int i = n + m + k - 1; i >= 0; i-=1) inv[i] = inv[i + 1] * (i + 1) % mod;
	f[0] = 1;
	for (int i = 1; i <= m + k; i+=1) f[i] = ((2 * f[i - 1] % mod - C(i - 1, i - 1 - k) + mod) % mod - C(i - 1, m) + mod) % mod;
//	for (int i = 1; i <= m + k; i+=1) cout << f[i] << endl;
	for (int i = 0; i <= m + k; i+=1)
	{
//		cout << f[i] << ' ' << qpow(3, m + k - i) << ' ' << C(n - 1 + i, n - 1) << endl;
		ans = (ans + (f[i] * qpow(3, m + k - i) % mod * C(n - 1 + i, n - 1) % mod) % mod) % mod;
	}
	printf("%lld\n", ans);
	return 0;
}


Measured memory_bytes: 22524
#!usr/bin/env python3
from collections import defaultdict,deque
from heapq import heappush, heappop
from itertools import permutations
import sys
import math
import bisect
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def I(): return int(sys.stdin.readline())
def LS():return [list(x) for x in sys.stdin.readline().split()]
def S():
    res = list(sys.stdin.readline())
    if res[-1] == "\n":
        return res[:-1]
    return res
def IR(n):
    return [I() for i in range(n)]
def LIR(n):
    return [LI() for i in range(n)]
def SR(n):
    return [S() for i in range(n)]
def LSR(n):
    return [LS() for i in range(n)]

sys.setrecursionlimit(1000000)
mod = 1000000007

def solve():
    n,m = LI()
    ans = [1]*m
    for i in range(n):
        q = LI()
        for j in q[1:]:
            ans[j-1] += 1
        for j in range(m):
            ans[j] -= 1
    res = 0
    for i in ans:
        if i == 1:
            res += 1
    print(res)    
    return

#Solve
if __name__ == "__main__":
    solve()


Measured memory_bytes: 38384
#include <bits/stdc++.h>
#define all(v) (v).begin(), (v).end()
#define pb push_back
#define REP(i,n) for(int i=0; i<(n); i++)
#define REP2(i,x,n) for(int i=x; i<(n); i++)
using namespace std;
using ll = long long;
using ld = long double;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
template<class T>using numr=std::numeric_limits<T>;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
const int INF = 1e9;
const ll LLINF = 1e16;
const int MOD = 1000000007;
const int MOD2 = 998244353;

int main() {
    ios::sync_with_stdio(false);cin.tie(0);
    int x,y;
    cin >> x >> y;
    for(int i=0;i<=x;i++){
        int j= x-i;
        if(2*i+4*j==y) {
            cout << "Yes"<<endl;
            return 0;
        }
    }
    cout << "No" <<endl;
}

Measured memory_bytes: 3576
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
ll max(ll a, ll b){
    if(a>b)
	return a;
    return b;
}

int main(){
    int n,k;
    cin>>n>>k;
    if(k==1)
	cout<<"0"<<endl;
    else
	cout<<n-k<<endl;

}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
	public static void main(String[] args){
		try(Scanner sc = new Scanner(System.in)) {
			
			int d = sc.nextInt();
			int t = sc.nextInt();
			int s = sc.nextInt();
			
			System.out.println(d <= t * s ? "Yes" : "No");
		}
	}

}

Measured memory_bytes: 35812
while(True):
    n = input()
    if n == '0': break
    line = input()
    qs = line.split(" ")
    up = 0
    down = 0
    cnt = 0
    for q in qs:
        if q == "lu" or q == "ru" :
            up += 1
            down = 0
        else:
            down += 1
            up = 0
        if up==2 or down == 2:
            cnt += 1
    print(cnt)



Measured memory_bytes: 5572
#include<iostream>
#include<array>
#include<string>

int main(){
  int N,L;
  std::cin >> N >> L;
  std::string *S;
  S = new std::string [N];
  for (int i = 0; i < N; ++i){
    std::cin >> S[i];
    //std::cout << S[i] <<std::endl;
  }//標準入出力からN,L,Sを受け取る
  //std::cout << S <<std::endl;

  for (int M = 0; M < N; ++M){
    int a = M;
    for (int j = M; j < N; ++j){
      int result = S[a].compare(S[j]);//j番目の文字列引く0番目の文字列
      //std::cout << S[a] << S[j] <<S[a].compare(S[j]) <<std::endl;
      if (result > 0){
        a = j;
      }
      else {
      }
      //std::cout << a <<std::endl;
    }
    //std::cout << a <<std::endl;

    std::string b;
    for (int k = N-1; k > -1; --k){
      if (k == a){
        b = S[a];//
        //std::cout << b << std::endl;
      }
      else if ((k < a)&&(k > M-1)){
        S[k+1] = S[k];//最大のxより前は１つ後ろに
        //std::cout << S[k+1] <<std::endl;
      }
        else{}//最大のxより後はそのまま

}
S[M] = b;//最大の文字列を先頭に出した
  //std::string T = "";
  //for (int l = 0; l < N; ++l){
  //  T = T + S[l];

  //std::cout << T << std::endl;
}



  std::string T = "";
  for (int l = 0; l < N; ++l){
    T = T + S[l];
  }
  std::cout << T << std::endl;
delete[] S;

return 0;
}

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

#define endl '\n'
#define fi first
#define se second
#define MOD(n,k) ( ( ((n) % (k)) + (k) ) % (k))
#define forn(i,n) for (int i = 0; i < n; i++)
#define forr(i,a,b) for (int i = a; i <= b; i++)
#define all(v) v.begin(), v.end()
#define pb(x) push_back(x)

using namespace std;

typedef long long ll;
typedef long double ld;
typedef pair<int, int> ii;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ii> vii;

const int MX = 200005, mod = 1000000007;
int dp[MX], ant[MX], a[MX], n;

int main () {
	ios_base::sync_with_stdio(0); cin.tie(0);
	
	cin >> n;
	for (int i = 1; i <= n; i++)
		cin >> a[i];

	dp[0] = 1;
	for (int i = 1; i <= n; i++) {
		dp[i] = dp[i-1];
		if (ant[a[i]] && ant[a[i]] < i - 1)
			(dp[i] += dp[ant[a[i]]]) %= mod;
		ant[a[i]] = i;
	}
	cout << dp[n] << endl;

	return 0;
}


Measured memory_bytes: 2560
#include <algorithm>
#include <bitset>
#include <cmath>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <stack>
#include <string>
#include <utility>
#include <vector>

#define repd(i, a, b) for (ll i = (a); i < (b); i++)
#define rep(i, n) repd(i, 0, n)
typedef long long ll;

using namespace std;

template <typename T> void output(T, int);
int gcd(int a, int b);

ll comb(ll a, ll b) {
    ll ans = 1;
    rep(i, b) { ans = ans * (a - i) / (i + 1); }
    return ans;
}

int main() {
    // source
    ll n, a, b;
    cin >> n >> a >> b;
    ll v[n];
    rep(i, n) { cin >> v[i]; }
    ll pat = 0;
    sort(v, v + n, greater<ll>());
    ll sum_temp = 0;
    rep(i, a) { sum_temp += v[i]; }
    double ans = (double)sum_temp / a;

    ll last = v[a - 1];
    ll last_l, last_r;
    rep(l1, n) {
        if (v[l1] == last) {
            last_r = l1;
        }
        if (v[n - l1 - 1] == last) {
            last_l = n - l1 - 1;
        }
    }

    repd(l0, a, b + 1) {
        if (v[l0 - 1] != last) {
            break;
        }
        if (v[0] != last && l0 != a) {
            break;
        }
        pat += comb(last_r - last_l + 1, l0 - last_l);
    }

    printf("%.6f\n", ans);
    cout << pat << endl;
    return 0;
}

template <typename T> void output(T a, int precision) {
    if (precision > 0) {
        cout << setprecision(precision) << a << "\n";
    } else {
        cout << a << "\n";
    }
}

template <typename T> T min(T a, T b) {

    if (a < b) {
        return a;
    } else {
        return b;
    }
}

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


Measured memory_bytes: 256
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define ALL(v) v.begin(), v.end()
typedef long long ll;

#include <atcoder/dsu>
#include <bits/stdc++.h>

using namespace std;
using namespace atcoder;

int main(){
  int n,q;
  cin>>n>>q;
  
  dsu d(n);
  rep(i,q){
    int c,u,v;
    cin>>c>>u>>v;
    if(c==0) d.merge(u,v);
    if(c==1) cout<<d.same(u,v)<<endl;
  }
  
  return 0;
}

Measured memory_bytes: 3908
#include <iostream>

using namespace std;

int main()
{
    //N
    //A1 A2 … AN
    // get a integer
    int n;
    cin >> n;
    int spots[n+2];
    spots[0] = 0;
    int total = 0;
    for(int i=1; i<=n; i++){
        cin >> spots[i];
        total += abs(spots[i]-spots[i-1]);
    }
    spots[n+1]=0;
    total += abs(spots[n+1]-spots[n]);
    
    for(int i=1; i<=n; i++){
        int cost = total - abs(spots[i]-spots[i-1]) - abs(spots[i+1]-spots[i]) + abs(spots[i+1]-spots[i-1]);
        cout << cost << endl;
    }
    return 0;
}

Measured memory_bytes: 1664
n = int(input())
x = [list(map(int, input().split())) for i in range(n)]

for i in range(n-2):
    if x[i][0] == x[i][1] and x[i+1][0] == x[i+1][1] and x[i+2][0] == x[i+2][1]:
        print("Yes")
        exit()
print("No")

Measured memory_bytes: 9096
#include <iostream>
#include <algorithm>
#include <cmath>
using namespace std;
int main(){
    long double h,s,t,a,ans;
    long int n;
    cin >> n >> t >> a;
    s=1000001;
    long int x[n];
    for(int i=0;i<n;i++){
        h=s;
        cin >> x[i];
        s=t-(x[i]*0.006);
        s=abs(s-a);
        s=min(s,h);
        if(s!=h){
            ans = i;
        }
    }
    cout << ans+1;
    return 0;
}

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

#define rep(i,x,y) for(int i=(x);i<(y);++i)
#define debug(x) #x << "=" << (x)

#ifdef DEBUG
#define _GLIBCXX_DEBUG
#define print(x) std::cerr << debug(x) << " (L:" << __LINE__ << ")" << std::endl
#else
#define print(x)
#endif

const int inf=1e9;
const int64_t inf64=1e18;
const double eps=1e-9;

template <typename T> ostream &operator<<(ostream &os, const vector<T> &vec){
    os << "[";
    for (const auto &v : vec) {
    	os << v << ",";
    }
    os << "]";
    return os;
}

using i64=int64_t;

i64 gcd(i64 a,i64 b){
	if(b==0) return a;
	return gcd(b,a%b);
}
i64 lcm(i64 a,i64 b){
	return a/gcd(a,b)*b;
}

void solve(){
    int n,m;
    cin >>  n >> m;
    vector<int> a(n);
    rep(i,0,n) cin >> a[i];
    int ans=0;
    i64 l=lcm(n,m);
    vector<int> v;
    rep(i,0,l){
        v.push_back(a[i%n]);
        if(v.size()==m){
            int mi=inf,ma=0;
            rep(j,0,m){
                mi=min(mi,v[j]);
                ma=max(ma,v[j]);
            }
            ans+=ma-mi;
            v.clear();
        }
    }
    cout << ans << endl;
}

int main(){
    std::cin.tie(0);
    std::ios::sync_with_stdio(false);
    cout.setf(ios::fixed);
    cout.precision(10);
    solve();
    return 0;
}

Measured memory_bytes: 3120
#include <bits/stdc++.h>
#define INF 0x3f3f3f
#define PI 3.1415926535897932384626433832795
#define MOD 1000000007
#define PB push_back
#define F first
#define S second
#define FOR(i,k) for(int i=0; i<k; i++)
#define RFOR(i,k) for(int i=k; i>=0; i--)
#define CIN(a) int a; cin>>a;
#define CIN2(a,b) int a,b; cin>>a>>b;
#define CIN3(a,b,c) int a,b,c; cin>>a>>b>>c;
#define CIN4(a,b,c,d) int a,b,c,d; cin>>a>>b>>c>>d;
#define CINV(n,a) VI a; FOR(i,n) {int x; cin>>x; a.PB(x);}
#define CINV2(n,a,b) VI a,b; FOR(i,n) {int x,y; cin>>x>>y; a.PB(x); b.PB(y);}
#define ALL(x) x.begin(), x.end()
#define INS(x) inserter(x, x.begin())
#define D(x) cout<<#x<<": "<<(x)<<endl
#define DV(x) cout<<#x<<": "; for(auto &d:x) cout<<d<<" "; cout<<endl
#define DM(x) for(auto &p:x) cout<<p.F<<":"<<p.S<<" "; cout<<endl
#define OUT(x) cout<<(x)<<endl
#define OUTV(x) for(auto &d:x) cout<<d<<" "; cout<<endl
#define OUTG(x) for(auto &v:x) { for(auto &u:v) cout<<u; cout<<endl; }

using namespace std;
typedef long long ll;
typedef pair<int,int> PII;
typedef vector<int> VI;
typedef vector<string> VS;
typedef vector<PII> VPII;
typedef vector<VI> GI;
typedef vector<vector<char> > GC;
typedef map<char,int> MC;
typedef map<int,int> MI;
typedef map<string,int> MS;

void amin(auto &x, auto y) { if(y < x) x = y; }
void amax(auto &x, auto y) { if(x < y) x = y; }
auto mod(auto x, auto m) { return ((x % m) + m) % m; }
int sz(const auto &x) { return (int)x.size(); }
int Safe(const VI &x, int i) { return i<0 || i>=x.size() ? 0 : x[i]; }
bool Find(const auto &x, auto y) { return x.find(y) != x.end(); }
bool IsSameSign(auto a, auto b) { return ((a>=0) ^ (b<0)); }
bool IsPrime(int n) { if (n <= 1)  return false; if (n <= 3)  return true; if (n
%2 == 0 || n%3 == 0) return false; for (int i=5; i*i<=n; i=i+6) if (n%i == 0 || 
n%(i+2) == 0) return false; return true; }
PII operator+(const PII &l, const PII &r) { return {l.F+r.F, l.S+r.S}; }
bool IsInBounds(const PII p, int Y, int X) { return p.F >=0 && p.F < Y && p.S >=
0 && p.S < X; }
VPII nb = {{0,1}, {1,0}, {0,-1}, {-1,0}};

int main() {
  CIN2(a,b);
  
  GC g(100, vector<char>(100));
  FOR(y, sz(g)) {
    FOR(x, sz(g[0])) {
      g[y][x] = y < 50 ? '.' : '#';
    }
  }

  int wy=0, wx=0;
  int by=51, bx=0;
  FOR(i, b-1) {
    g[wy][wx] = '#';
    wx += 2;
    if(wx >= sz(g[0])) {
      wx=0;
      wy+=2;
    }
  }

  FOR(i, a-1) {
    g[by][bx] = '.';
    bx += 2;
    if(bx >= sz(g[0])) {
      bx=0;
      by+=2;
    }
  }
  cout<<"100 100"<<endl;
  OUTG(g);
}


Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main() {
	long long int a, b, m, n, tmp;
	while(cin >> a >> b) {
		if(a > b) {
			m = a;
			n = b;
		} else {
			m = b;
			n = a;
		}
		while(n != 0) {
			tmp = n;
			n = m % n;
			m = tmp;
		}
		tmp = a * b / m;
		cout << m << " " << tmp << endl;
	}
	return 0;
}

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

int main() {
  int N, K;
  cin >> N >> K;
  
  int res = 1;
  for (int i = 0; i < N; i++) {
    if (res > K) {
      res += K;
    }
    else {
      res *= 2;
    }
  }
  
  cout << res << endl;
}

Measured memory_bytes: 256
process.stdin.resume();
process.stdin.setEncoding('utf8');

var lines = [];
var reader = require('readline').createInterface({
  input: process.stdin,
  output: process.stdout
});
reader.on('line', (line) => {
  lines.push(line);
});
reader.on('close', () => {
  var N = lines[0];

  var sum = 0;
  sum += (N.match( /1/g ) || [] ).length * 1;
  sum += (N.match( /2/g ) || [] ).length * 2;
  sum += (N.match( /3/g ) || [] ).length * 3;
  sum += (N.match( /4/g ) || [] ).length * 4;
  sum += (N.match( /5/g ) || [] ).length * 5;
  sum += (N.match( /6/g ) || [] ).length * 6;
  sum += (N.match( /7/g ) || [] ).length * 7;
  sum += (N.match( /8/g ) || [] ).length * 8;
  sum += (N.match( /9/g ) || [] ).length * 9;
  
  var result = 'No';
  if (sum % 9 === 0) result = 'Yes';
  console.log(result);
});

Measured memory_bytes: 37024
#include <bits/stdc++.h>
 
#define int         long long
#define uint        unsigned int
#define ld          long double
#define showoff     ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define pb          push_back
#define pii         pair<int,int>
#define FOR(i,a,b)  for(int i=a;i<b;++i)
#define RFOR(i,a,b) for(int i=a;i>b;--i)
#define f           first
#define se          second
#define maxn        200005
#define all(v)      v.begin(),v.end()
#define sz(x)       (int)x.size()
#define mod         1000000007
#define pqueue      priority_queue<pii>
#define pdqueue     priority_queue< int,vector<int> ,greater< int >>
 
using namespace std;
 
 
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
 
 
int power(int a,int n)
{
    a %= mod;
    if(n == 1)return a;
    if(n == 0)return 1;
    if(n%2)return (a*(power((a*a)%mod,n/2)%mod))%mod;
    return power((a*a)%mod,n/2)%mod;
}

const int inf = (int) 1e18;
 
int inverse(int x){
    return power(x,mod-2)%mod;//little fermat....
}


void solve(){
    string s,t;
    cin >> s >> t;
    bool fo = 1;
    for(int i = 0;i < sz(s);++i)if(s[i] != t[i])fo = 0;
    if(fo)cout << "Yes\n";
else cout << "No\n";
    
}

signed main()   
{
    showoff;
    int T = 1;
    //cin >> T;
    FOR(t,1,T+1){
       solve();
       cout << "\n";
    }
    return 0;
}
//*->for large size of matrix take int not long long if possible......
//*->always take maximum as inf for safer side ...


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

int main(){
	ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0);
	int a,b,c,k;cin>>a>>b>>c>>k;
	while(a>=b && k>0){b*=2;k--;}
	while(b>=c && k>0){c*=2;k--;}
	// cout<<a<<" "<<b<<" "<<c<<endl;
	if(a<b && b<c)cout<<"Yes\n";
	else cout<<"No\n";
	return 0;
}

Measured memory_bytes: 3580
#http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=ITP1_9_C
n = gets.to_i

taro = 0
hanako = 0
n.times.each do
    t,h = gets.split
    taro += 3 if t > h
    hanako += 3 if h > t
    taro += 1 if h == t
    hanako += 1 if h == t
end

puts [taro,hanako].join(" ")

Measured memory_bytes: 6108
#include <algorithm>
#include <bitset>
#include <cmath>
#include <cstring>
#include <deque>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <vector>

#define mod 1000000007
#define INF2 9999999999
#define INF (1 << 30)
#define rep(i, n) for(int(i) = 0; (i) < (n); (i)++)

using namespace std;
using ll = __int64_t;

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

//約数列挙(1を含む)
vector<ll> divisor(ll n){
    vector<ll> res;
    for(ll i = 1; i*i <= n; i++){
        if(n % i == 0){
            res.push_back(i);
            if(i*i != n) res.push_back(n/i);
        }
    }
    return res;
}

int hoge(string s){
    int res = 0;
    for(int i = 0; i < s.length()-2; i++){
        if(s[i] == 'A' && s[i+1] == 'B'){
            res++;
        }
    }
    return res;
}

void solve(){
    int n, ab=0, a=0, b=0, res=0;
    string s;
    cin >> n;

    for(int i = 0; i < n; i++){
        cin >> s;
        res += hoge(s);
        if(s[0] == 'B' && s[s.length()-1] == 'A'){
            ab++;
        }else if(s[0] == 'B'){
            a++;
        }else if(s[s.length()-1] == 'A'){
            b++;
        }
    }

    if(ab == 0){
        res += min(a, b);
    }else{
        if(a+b > 0){
            res += ab + min(a, b);
        }else{
            res += ab-1;
        }
    }
    cout << res << endl;
}

int main() {
    solve();
    return 0;
}

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

ll max2val(ll a, ll b) {
    if (a > b) {
        return a;
    }
    else {
        return b;
    }
}

int main() {
 vector<char> a={'q','w','e','r','t','y','u','i','o','p','a','s','d','f','g','h','j','k','l','z','x','c','v','b','n','m'};
 char b; cin>>b;
 rep(i,a.size()){
     if(b==a[i]){cout<<'a'<<endl;
     return 0;}
 }
 cout<<'A'<<endl;
 }



Measured memory_bytes: 3620