akhauriyash/Code-Regression huggingface dataset:
//hinagata.cpp
/*includes*/
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cstdlib>
#include <cmath>
#include <stdio.h>
#include <numeric>
#include <iomanip>
#include <limits>
/*namespace*/
using namespace std;
using ll= long long;
/*define macro*/
#define REP(i,n) for(int i=0;i<(n);i++)
#define REPi(i,a,b) for(int i=(a);i<(b);i++)
#define REPRi(i,a,b) for(int i=(a);i>(b);i--)
#define ALL(x) (x).begin(),(x).end()

int main(){
    int N,M;
    cin>>N>>M;
    vector<int> P(M);
    vector<string> S(M);
    REP(i,M){
        cin>>P[i]>>S[i];
    }
    //inputend
    vector<int> AC(N,0);
    vector<int> WA(N,0);
    ll wa_num=0;
    REP(i,M){
        if(S[i]==string("WA")&&AC[P[i]-1]!=1){
            WA[P[i]-1]+=1;
        }else if(S[i]==string("AC")&&AC[P[i]-1]!=1){
            AC[P[i]-1]=1;
            wa_num+=WA[P[i]-1];
        }
    }
    int ac_num=count(ALL(AC),1);
    cout<<ac_num<<endl;
    cout<<wa_num<<endl;
}

Measured memory_bytes: 6912
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
template<class T> bool INRANGE(T x,T a,T b) { return a<=x&&x<=b; }
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;
}

#define REP(i,n) for(int i=0;i<(n);++i)
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define ALL(v) (v).begin(),(v).end()
#define RALL(a) (a).rbegin(), (a).rend()
#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(nullptr);
    ios::sync_with_stdio(false);


    int N, M, C;
    cin >> N >> M >> C;
    vi A(M), B(M);

    REP(i,M) cin >> B[i];

    int ans = 0;
    REP(i,N){
        REP(i,M) cin >> A[i];
        int product = 0;
        REP(i,M) product += A[i]*B[i];
        if (product>-C) ans++;
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define debug(x) cerr << __LINE__ << " : " << #x << " = " << (x) << endl;
#define REP(i,n) for(int i=0;i<(int)(n);i++)
#define FOR(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define FORR(i,a,b) for(int i=(int)(b)-1;i>=(int)(a);i--)
#define CHMIN(a,b) (a) = min((a),(b))
#define CHMAX(a,b) (a) = max((a),(b))

//(0)6,(1)36,(2)216,(3)1296,(4)7776,(5)46656     1,9,81,729,6561,59049

int main()
{
    long int n;
    int six[7]={};
    int nin[6]={};
    int ktime=0;
    int time=0;
    int min=114514;
    scanf("%ld",&n);
    long int ksa=n;
    long int sa;
    long int div;
    while(ksa>=0)
    {
        time=ktime;
        sa=ksa;
        div=9;
        REP(j,6)
        {
            nin[j]=(sa%div)/(div/9);
            time+=nin[j];
            div*=9;
        }
        if(min>time)min=time;
        ktime++;
        ksa-=6;
        six[0]++;
        REP(i,6)
        {
            if(six[i]==6)
            {
                six[i]=0;
                six[i+1]+=1;
                ktime-=5;
            }
        }
        if(six[6]==1)break;
    }
    printf("%d\n",min);
    return 0;
}

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

using i64 = int64_t;

constexpr i64 MOD = 1e9 + 7;

int main(){
    i64 n, k;
    cin >> n >> k;
    vector<i64> v;
    for(int i=0;i<n;++i){
        i64 a;
        cin >> a;
        v.push_back(a);
    }
    i64 ans = 0;
    for(int i=0;i<n;++i){
        for(int j=i+1;j<n;++j){
            if(v[i] > v[j])ans++;
        }
    }
    ans *= (k*(k+1)/2)%MOD;
    ans %= MOD;

    i64 ans2 = 0;
    for(int i=n-1;i>=0;--i){
        for(int j=i-1;j>=0;--j){
            if(v[i] > v[j])ans2++;
        }
    }
    ans2 *= (k*(k-1)/2)%MOD;
    ans2 %= MOD;
    ans += ans2;
    ans %= MOD;
    cout << ans << endl;

    return 0;
}


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

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef pair<int, int> ii;
typedef pair<ll, int> li;
typedef pair<int, ll> il;
typedef vector<ii> vii;
typedef vector<il> vil;
typedef vector<li> vli;

#define F            first
#define S            second
#define pb(x)        push_back(x)
#define mp(a,b)      make_pair(a,b)
#define mt(a,b,c)    make_tuple(a,b,c)
#define sz           size()
#define all(A)       A.begin(), A.end()
#define mem(a, b)    memset(a, b, sizeof(a))   // all elements of A are b=0 or b=-1 else don't work
#define f0(i,b)      for(ll i=0;i<(b);i++)
#define f1(i,b)      for(ll i=1;i<=(b);i++)
#define f2(i,a,b)    for(ll i=(a);i<=(b);i++)
#define f3(i,b,a)    for(ll i=(b);i>=(a);i--)
#define rep(i,a,b,c) for(ll i=(a);i!=(b);i+=(c))

#define mod          10000007
#define PI           acos(-1.0)
#define MAX3(a,b,c)  max(a,max(b,c))

/*------------------------Bitmask-------------------------------*/
#define bitOn(N,pos)      (N | (1LL<<(pos)))
#define bitOff(N,pos)     (N & (~(1LL<<(pos))))
#define bitCheck(N,pos)   ((bool)(N & (1LL<<(pos))))
#define bitFlip(a,k)      (a^(1LL<<(k)))

#define whilee(i,t)  while(i!=t)
#define  sl(a)       scanf("%lld",&a)
#define  pl(a)       printf("%lld\n",a)

//x = 1e18 means 10^18
//for(auto it =A.begin(); it!=A.end(); it++)
//sort(A.begin(),A.end()); //sort(A, +n, greater<int>());
//binary_search(A.begin(),A.end(),x);
//reverse(A.begin(), A.end());
//cout << *max_element(A.begin(), A.end());
//cout << *min_element(A.begin(), A.end());
//count(A.begin(), A.end(), X); //counts the occurrences of X
//distance(A.begin(),A.end());  //distance between first to last element
//accumulate(A.begin(), A.end(), 0); //add
//next_permutation(A.begin(), A.end());
//prev_permutation(A.begin(), A.end());
//swap(S[0], T[0]);

//scanf("%lld",&x);
//printf("%lld\n",x);
//printf("%I64d\n", a);
//while (scanf("%lld %lld", &a, &b) == 2)
//printf("Case %lld: %lld\n", t++, a);

/*----------------------- Graph Moves---------------------------*/
// int dx[] = {1,-1,0,0} , dy[] = {0,0,1,-1};  // 4 Direction
// int dx[] = {0,0,1,-1,-1,1,-1,1} , dy[] = {-1,1,0,0,1,1-1,-1};  // 8 Direction // Kings Move
// int dx[] = {1,-1,1,-1,2,2,-2,-2} , dy[] = {2,2,-2,-2,1,-1,1,-1};  // Knight Direction
// int dx[] = {2,-2,1,1,-1,-1} , dy[] = {0,0,1,-1,1,-1};  // Hexagonal Direction

//vector <ll> A;
//deque <ll> A;
//queue <ll> A;
//stack <ll> A;
//list <int> A;
//set <ll> A;
//map <ll,ll> A;
//unordered_map <ll, ll> A;
//pair <ll,ll> A ;
//tuple <ll, ll, ll> A;
//vector <pair <ll,ll>> A;
//bitset<32> bset1;
//bool ok = true;
//char ch;
//string S, T, U;

ll i=0, j=0, k=0, a, b, c, d, e, f, g, h, l, m, n, o, p, q, r, s, t=1, u, v, w, x, y, z, maxx=INT_MIN, minn=INT_MAX, ans=0, sum=0, flag=0, cnt=0;

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);//NULL
    cout.tie(nullptr);//NULL

    cin>>n>>k;
    ll A[n];
    f0(i,n)
    {
        cin>>A[i];
    }
    sort(A,A+n);
    f0(i,k)
    {
        ans+=A[i];
    }
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 3656
#include <bits/stdc++.h>
#include <boost/range/algorithm.hpp>
using namespace std;

void print() { std::cout << std::endl; }
template <class Head, class... Tail> void print(Head &&head, Tail &&... tail) {
    std::cout << head;
    if(sizeof...(tail) != 0)
        std::cout << " ";
    print(std::forward<Tail>(tail)...);
}
template <class T> void print(std::vector<T> &vec) {
    for(auto &a : vec) {
        std::cout << a;
        if(&a != &vec.back())
            std::cout << " ";
    }
    std::cout << std::endl;
}
template <class T> void print(std::vector<std::vector<T>> &df) {
    for(auto &vec : df) {
        print(vec);
    }
}

int main() {
    int n, l;
    cin >> n >> l;

    vector<int> azi(n);
    for(int i = 0; i < n; i++) {
        azi[i] = l + i;
    }

    int allPie = accumulate(azi.begin(), azi.end(), 0);
    int dif = INT32_MAX;
    int result;

    for(int i = 0; i < n; i++) {
        vector<int> madeAzi = azi;
        madeAzi[i] = 0;
        int madePie = accumulate(madeAzi.begin(), madeAzi.end(), 0);
        int madeDif = abs(allPie - madePie);

        if(dif > madeDif) {
            dif = madeDif;
            result = madePie;
        }
    }

    print(result);
}


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

#define int             long long int
#define ld              long double
#define ff              first
#define ss              second
#define mp              make_pair
#define pb              push_back
#define endl            "\n"

#define si              set <int>
#define vi              vector <int>
#define pii             pair <int, int>
#define vpii            vector <pii>
#define mii             map <int, int>
#define que_max         priority_queue <int>
#define que_min         priority_queue <int, vi, greater<int>>

#define loop(i,s,e)     for(int i=s;i<e;i++)
#define rloop(i,e,s)    for(int i=e;i>=s;i--)
#define mset(a,f)       memset(a,f,sizeof(a))


#define M               1000000007
#define sz(x)           ((int) x.size())
#define all(p)          p.begin(), p.end()

#define bug(...)        __f (#__VA_ARGS__, __VA_ARGS__)
#define print(a)        for (auto x : a) cout << x << " "; cout << endl
#define Print(a,x,y)    for (int i=x; i<y; i++) cout<< a[i]<< " "; cout << endl

inline int power(int a, int b)
{
	int x = 1;
	while (b)
	{
		if (b & 1) x *= a;
		a *= a;
		b >>= 1;
	}
	return x;
}

template <typename Arg1>
void __f (const char* name, Arg1&& arg1) { cout << name << " : " << arg1 << endl; }
template <typename Arg1, typename... Args>
void __f (const char* names, Arg1&& arg1, Args&&... args)
{
	const char* comma = strchr (names + 1, ',');
	cout.write (names, comma - names) << " : " << arg1 << " | "; __f (comma + 1, args...);
}

const int N = 3e5 + 7;
vector <vi > adj;
bool vis[N];




void solve()
{
	int a, b, c;
	cin >> a >> b >> c;
	set<int>s;
	s.insert(a);
	s.insert(b);
	s.insert(c);
	if (s.size() == 2) cout << "Yes";
	else cout << "No";
	return;

}

int32_t main()
{
	ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);


	cout << setprecision(9) << fixed;

	int t = 1;
	//cin >> t;
	while (t--)
	{
		solve();
	}


	return 0;
}

Measured memory_bytes: 256
import java.util.*;
class Main{
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int a = sc.nextInt();
        int b = sc.nextInt();
        int c = sc.nextInt();
        int t = 0;
        int k = 0;
        for(int i = a;i <= b;i++){
            t = c % i;
            if(t == 0){
                k++;
            }
        }
        System.out.println(k);
    }
}



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

int main(){
  int n,m;
  string s;
  cin >> n >> m >> s;
  m--;
  if(s[m]=='A') s[m]='a';
  else if(s[m]=='B') s[m]='b';
  else s[m]='c';
  cout << s << endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
using namespace std;
int main()
{
int a,b;
while(cin >> a >> b){
int x=1;
int ans=0;
while(x<=a+b){
x=x*10;
ans++;
}
printf("%d\n",ans);
}
return 0;
}

Measured memory_bytes: 1144
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
    from math import floor, ceil
    #from operator import itemgetter

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

    w,h,n = map(int, input().split())
    l,r,u,d = 0, w, h, 0
    for _ in range(n):
        x,y,a = map(int, input().split())
        if a==1:
            l = max(l, x)
        if a==2:
            r = min(r, x)
        if a==3:
            d = max(d, y)
        if a==4:
            u = min(u, y)
    if l < r and d < u:
        print((r-l)*(u-d))
    else:
        print(0)

if __name__ == '__main__':
    main()

Measured memory_bytes: 3316
#include <iostream>
#include <stdio.h>
#include <bits/stdc++.h>
#include <math.h>
#include <string>
#include <sstream>
#define ll long long
#define F first
#define S second
#define pb push_back
#define ld long double
#define pll pair<long long,long long>
#define pld pair<long double,long double>
#define ios     ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
using namespace std;
ll mod=1000000007;
ll gcd (ll a,ll b)
{
    if(b==0)
        return a;
    else
        return gcd(b,a%b);
}
ll fastexp(ll x ,ll n)
{
    ll result =1;
    while(n>0)
    {
        if(n%2==1)
            result*=x;
        x*=x;
        n=n/2;
    }
    return result;
}

ll modularExp(ll x,ll n,ll mod)
{
    ll result=1;
    while(n>0)
    {
        if(n%2==1)
            result=(result*x)%mod;
        x=((x%mod)*(x%mod))%mod;
        n=n/2;
    }
    return (result)%mod;
}
bool isPrime(ll n)
{
    for(ll i=2;i*i<=n;i++)
        if(n%i==0)
            return false;
    return true;
}
bool mycomp(pll &a,pll &b)
{
    if(a.F!=b.F)
        return a.F < b.F;
    else
        return a.S < b.S;
}

void solve()
{
     string s;
     cin>>s;
     ll n=s.length();
     vector<ll> dp(2019);
     dp[s[0]-'0']=1;
     ll i,j;
     ll ans=0;
     for(i=1;i<n;i++)
     {
          ll d = s[i]-'0';
          vector<ll> dpc(2019);
          dpc[d]=1;
          for(j=0;j<2019;j++)
          {
               if(dp[j] > 0)
               {
                    ll r =(10*j + d)%2019;
                    dpc[r]+=dp[j];
                    if(r==0)
                         ans+=dp[j];
               }
          }
          dp=dpc;
     }
     cout<<ans;
}


int main()
{
    ios;
    ll t;
    t=1;
//    cin>>t;
    while(t--)
        solve();
}



Measured memory_bytes: 3760
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
#define IOS ios_base::sync_with_stdio(false); cin.tie(0);
#define pb push_back
#define pf push_front
#define PI acos(-1)
#define EPS 1e-5
#define sz(v) ((int)(v).size())
#define all(v) v.begin(),v.end()
#define forn(i, n) for(ll i=0;i<(ll)n;i++)
#define fi first
#define se second
 

int main() {
	string s;
	cin >> s;
	int q;
	cin >> q;
	bool reversed = false;
	deque<char> d(all(s));
	while(q--) {
		int t;
		cin >> t;
		if(t==1)
			reversed = !reversed;
		else {
			int f;
			cin >> f;
			char ch;
			cin >> ch;
			if(f == 1) {
				if(reversed)
					d.pb(ch);
				else d.pf(ch);
			} else {
				if(reversed)
					d.pf(ch);
				else d.pb(ch);
			}
		}
	}
	string res(d.begin(), d.end());
	if(reversed) reverse(all(res));
	cout << res << endl;

	return 0;
}



Measured memory_bytes: 3956
#include <stdio.h>
#include <stdlib.h>
int main(){
  int n;
  int sat;
  int *a,*b,*c;
  scanf("%d",&n);
  a=(int*)malloc(n*sizeof(int));
  b=(int*)malloc(n*sizeof(int));
  c=(int*)malloc((n-1)*sizeof(int));
  for (int i=0;i<n;i++) scanf("%d",&a[i]);
  for (int i=0;i<n;i++) scanf("%d",&b[i]);
  for (int i=0;i<n-1;i++) scanf("%d",&c[i]);
  sat=0;
  for (int i=0;i<n;i++) sat+=b[a[i]-1];
  for (int i=0;i<n-1;i++){
    if (a[i+1]-a[i]==1) sat+=c[a[i]-1];
  }
  printf("%d\n",sat);
  free(a);
  free(b);
  free(c);
  return 0;
} 

Measured memory_bytes: 128
#include<stdio.h>
#include<stdlib.h>

void screen(int[] ,int);

int main()
{
int i,j;//counter
int N,A[100];
int v;
  
scanf("%d",&N);

for(i=0;i<N;i++)
  {
//     printf("//////////1////////\n");
scanf(" %d",&A[i]);
}
//printf("//////////2////////\n");

screen(A,N);
for(i=1;i<N;i++)
  {
v=A[i];
j=i-1;
while(j>=0 && A[j]>v)
  {
A[j+1] = A[j];
j--;
}
A[j+1] = v;
screen(A,N);
}

return 0;
}

void screen(int A[],int N)
{
int i;
for(i=0;i<N;i++)
  {
if(i<N-1)
  {
printf("%d ",A[i]);
}
 else if(i==(N-1))
   {
printf("%d",A[i]);
break;
}
}

printf("\n");
}



Measured memory_bytes: 2032
using System;

namespace AOJ
{
    class Program
    {
        static void Main()
        {
            while(true)
            {
                string line = Console.ReadLine();
                int[] num = TypeConverter.arrayStrToInt(line.Split(' '));

                if (num[0] == 0 && num[1] == 0)
                    break;

                Array.Sort(num);
                Console.WriteLine(num[0].ToString() + " " + num[1].ToString());
            }
        }
    }

    class TypeConverter
    {
        static public int[] arrayStrToInt(string[] str)
        {
            return Array.ConvertAll<string, int>(str,
                delegate(string value)
                {
                    return int.Parse(value);
                }
            );
        }

        static public string[] arrayIntToStr(int[] x)
        {
            return Array.ConvertAll<int, string>(x,
                delegate(int value)
                {
                    return value.ToString();
                }
            );
        }
    }
}

Measured memory_bytes: 5892
#include <bits/stdc++.h>
#define rep(i,a,b) for(int i=a;i<(b);++i)
#define erep(i,a,b) for(int i=a;i<=(int)(b);++i)
#define per(i,a,b) for(int i=(a);i>(b);--i)
#define eper(i,a,b) for(int i=(a);i>=b;--i)
#define fore(x, a) for(auto &x : a)
#define pb push_back
#define mp make_pair
#define INF 100100100100
#define inf 2001001001
#define MOD 1000000007
#define ALL(x) begin(x),end(x)
using namespace std;
using ll = long long;
using pii = pair<int,int>;
using vii = vector<int>;
using vll = vector<ll>;
template<class T>using vv = vector<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; }
template<class T>void show(const vector<T> &a) { for (int i = 0; i < (int)a.size(); ++i) cout << a[i] << (i != (int)a.size()-1 ? " " : "\n"); }
template<class T>T gcd(T a, T b){ return b ? gcd(b, a % b) : a; }
template<class T>T lcm(T a, T b){ return a / gcd(a, b) * b; }
int dy[]={0, 1, -1, 0};
int dx[]={1, 0, 0, -1};

string s; 
int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
    cin >> s;
    int n = s.size();
    rep(bit, 0, (1 << n)) {
      int sum = s[0] - '0';
      rep(i, 1, n) {
        if ((bit >> i) & 1) sum += s[i] - '0';
        else sum -= s[i] - '0';
      }
      if (sum == 7) {
        cout << s[0];
        rep(i, 1, n) {
          if ((bit >> i) & 1) cout << '+';
          else cout << '-';
          cout << s[i];
        }
        cout << "=7" << endl;
        return 0;
      }
    }
    return 0;
}



Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	
	long long n, m;
	cin >> n >> m;
	vector<long long> v(n);
	
	
	cin >> v[0];
	long long k = v[0];
	
	for (int i = 1; i < n; ++i){
		cin >> v[i];
		
		k = v[i] * k / __gcd(v[i], k);
	}
	bool p = true;
	for (int i = 0; i < n; ++i){
		if (k / v[i] % 2 == 0){
			p = false;
			break;
		}
	}
	
	if (!p){
		cout << 0;
	}
	else{
		k /= 2;
		
		cout << m / k / 2 + m / k % 2;
	}
}


Measured memory_bytes: 1024
def get_i() #空白区切の入力を数値(整数)の配列で返す
  return gets.chomp.split(" ").map(&:to_i)
end
def get_f() #空白区切の入力を数値(実数)の配列で返す
  return gets.chomp.split(" ").map(&:to_f)
end
def get() #空白区切の入力を文字列の配列で返す
  return gets.chomp.split(" ")
end
def get_nsp() #入力されたものを一文字ずつに区切った文字列の配列で返す
  return gets.chomp.split("")
end
def yn_judge(bool,y="Yes",n="No") #boolに真偽を投げることで、trueならy、falseならnの値を出力する
  return bool ? y : n 
end
def array(size,n=1,init=nil) #nに配列の次元数、sizeに配列の大きさ、initに初期値を投げることでその配列を返す
  if n==1
    return Array.new(size){init}
  else
    return Array.new(n).map{Array.new(size){init}}
  end
end

n=gets.to_i
MAX_COOR=1000
table=array(MAX_COOR+1,MAX_COOR+1,0)
n.times do
  x1,y1,x2,y2=get_i
  table[x1][y1]+=1
  table[x1][y2]-=1
  table[x2][y1]-=1
  table[x2][y2]+=1
end
max=table[0][0]
MAX_COOR.times do|i|
    table[i+1][0]+=table[i][0]
    max=table[i+1][0] if max<table[i+1][0]
    table[0][i+1]+=table[0][i]
    max=table[0][i+1] if max<table[0][i+1]
end
MAX_COOR.times do|y|
  MAX_COOR.times do|x|
    table[x+1][y+1]=table[x+1][y+1]+table[x+1][y]+table[x][y+1]-table[x][y]
    max=table[x+1][y+1] if max<table[x+1][y+1]
  end
end
puts max


Measured memory_bytes: 14852
n, k = map(int,input().split())
s = list(input())
cn = [0]*(n-1)
for i in range(n-1):
    if s[i] == s[i+1]:
        cn[i] = 1
if (n-1 - sum(cn)) <= 2*k:
    print(n-1)
else:
    print(sum(cn)+k*2)


Measured memory_bytes: 4652
var
	H,W,i,j,ans,X,Y:Longint;
	D:Array[0..1001,0..1001]of Longint;
	S:String;
begin
	readln(H,W);
	for i:=0 to 1001 do begin
		D[0,i]:=1000000000;
		D[i,0]:=1000000000;
		D[H+1,i]:=1000000000;
		D[i,W+1]:=1000000000;
	end;
	for i:=1 to H do begin
		readln(S);
		for j:=1 to W do begin
			if S[j]='#'then D[i,j]:=0 else begin
				X:=D[i-1,j];
				Y:=D[i,j-1];
				if X<Y then D[i,j]:=X+1 else D[i,j]:=Y+1;
			end;
		end;
	end;
	for i:=H downto 1 do for j:=W downto 1 do begin
		X:=D[i+1,j];
		Y:=D[i,j+1];
		if X<Y then inc(X)else X:=Y+1;
		if D[i,j]>X then D[i,j]:=X;
		if ans<D[i,j]then ans:=D[i,j];
	end;
	writeln(ans);
end.

Measured memory_bytes: 4156
fun main(args: Array<String>) {
    var n = readLine()!!.toInt()
    var cnt = 1
    var kari = -1

    while(n != 0) {
        if(cnt == 3) break
        if(n % 10 == kari) {
            cnt++
        } else {
            kari = n % 10
            cnt = 1
        }
        n /= 10
    }

    print(if(cnt == 3) "Yes" else "No")
}

Measured memory_bytes: 31796
def C():
    a,b,h,m = list(map(int, input().split()))
    import math
    h_r = 2*math.pi*(h+m/60)/12
    m_r = 2*math.pi*m/60
    r = abs(h_r-m_r)
    print(math.sqrt(a**2 + b**2 - 2*a*b*math.cos(r)))
C()

Measured memory_bytes: 9292
#include <cmath>
#include <iostream>
#include <vector>
#include <queue>
#include <map>
#include <set>
#include <algorithm>
#include <utility>
#include <iomanip>

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

using namespace std;

typedef pair<int, int> P;

const int INF = 1e15;
const int MOD = 1e9+7;

signed main(){
    int q, h, s, d, n;
    cin >> q >> h >> s >> d >> n;

    q *= 4;
    h *= 2;

    int one = min(q, min(h, s));

    if(one < d / 2.0){
        cout << one * n << endl;
        return 0;
    }

    int ans = n / 2 * d;
    ans += n % 2 * one;

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 504
from collections import deque
S = deque(list(input()))
T = deque(list(input()))

# print('s t', S, T)

for i in range(len(S)):
    if S == T:
        print('Yes')
        exit()
    s = S.pop()
    S.appendleft(s)
if S == T:
    print('Yes')
    exit()
print('No')


Measured memory_bytes: 3316
#include <stdio.h>

void kurai(int a[], int n){
  int i = 0;
  while(n > 0){
    a[i] = n % 10;
    n /= 10;
    i++;
  }
}

int main(void){
  int ary[5];
  int a, b;
  scanf("%d%d", &a, &b);
  int i;
  int count = 0;
  for(i = a; i <= b; i++){
    kurai(ary, i);
    if(ary[4] == ary[0] && ary[3] == ary[1]) count++;
  }
  printf("%d\n", count);
  return 0;
}

Measured memory_bytes: 128
#include<bits/stdc++.h>
#define F first
#define S second
#define endl '\n'
#define MP make_pair
#define pb push_back

using namespace std;

typedef pair<int, int> P;
typedef pair<int, P> i_P;
typedef long long LL;

static const int INF = INT_MAX;
static const int MIN = INT_MIN;
static const LL L_INF = LLONG_MAX;
static const int MOD = 1000000000 + 7;
static const int SIZE = 100005;

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

    double n, k;
    cin >> n >> k;

    vector< double > p;
    double tmp = 1.0;
    int pos = 1;
    while( tmp < 100005 ) {
        p.pb( tmp );
        tmp *= 2;
        ++pos;

    }
    p.pb( tmp );

    double res = 0.0;
    pos = 0;
    tmp = n;
    while( n > 0 ) {
        while( p[pos] * n < k ) ++pos;
        res += ( 1.0 / tmp ) * ( 1.0 / p[pos] );
        --n;
    }

    printf( "%.9lf\n", res );

    return 0;
}



Measured memory_bytes: 256
import java.util.*;
import java.util.stream.Collectors;
import java.io.*;
import java.nio.charset.StandardCharsets;

public class Main {
	public static void main(String[] args) throws IOException {
		InputStreamReader reader = new InputStreamReader(System.in, StandardCharsets.UTF_8);
		BufferedReader in = new BufferedReader(reader);
		Main ins = new Main(in);
		ins.calc();
		ins.showResult();
	}

	Main(BufferedReader in) throws IOException {
		char a = in.readLine().charAt(0);
		int i = (int) a;
		if (i >= 65 && i <= 90) {
			System.out.println("A");
		} else {
			System.out.println("a");
		}

	}

	void calc() {
	}

	void showResult() {
	}
}


Measured memory_bytes: 32452
import sys

read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines
sys.setrecursionlimit(10 ** 9)
INF = 1 << 60
MOD = 1000000007


def main():
    N = int(readline())

    def rec(n, used):
        ans = 0
        if used == 7:
            ans += 1
        for i, d in enumerate((3, 7, 5)):
            if 10 * n + d <= N:
                ans += rec(10 * n + d, used | (1 << i))
        return ans

    print(rec(0, 0))
    return


if __name__ == '__main__':
    main()


Measured memory_bytes: 9188
#include <bits/stdc++.h>
#define rep(i, n) for(int i=0; i<(n); ++i)
#define chmin(x,y) x = min(x,y)
#define chmax(x,y) x = max(x,y)
using namespace std;
using Graph = vector<vector<int>>;
typedef long long ll;
typedef pair<int, int> P;
const int inf = 1<<21;
const ll INF = 1LL << 60;
const ll mod = 1e9+7;

int dp[4000][7000];

int main() {
    int n, t;
    cin >> n >> t;
    vector<P> AB(n);
    rep(i, n) cin >> AB[i].first >> AB[i].second;
    sort(AB.begin(), AB.end());
    rep(j, 7000) dp[0][j] = 0;
    dp[1][0] = 0;

    // 配るdp
    /*
        i番目までで時間j以内に食べたものの最高満足度
        配るdpで注文を再現 jで注文したものはj+AB[i-1].firstで食べ終わる
        jをt未満に限定
    */
   int ans = 0;
    rep(i, n+1)rep(j, t){
        if(i==0) continue;
        dp[i][j+AB[i-1].first] = max(dp[i-1][j+AB[i-1].first], dp[i-1][j] + AB[i-1].second);
        chmax(dp[i][j], dp[i-1][j]);
    }

    rep(i, n+1)rep(j, 7000){
        chmax(ans, dp[i][j]);
    }

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

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

dic = defaultdict(list)
n, q = map(int, input().split())

for i in range(n-1):
    a, b = map(int, input().split())
    dic[a].append(b)

tree = [0]*n

for i in range(q):
    p, x = map(int, input().split())
    tree[p-1] += x

todo = deque([1])
while todo:
    root = todo.popleft()
    count = tree[root-1]
    children = dic[root]
    for to in children:
        tree[to-1] += count
        todo.append(to)

print(' '.join(map(str, tree)))


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

using namespace std;

typedef unsigned long long ll;

vector<ll> weight, val;
int n;

ll dp[100005][101];

ll value(ll w, int i) {

    if (i == n) return 0;
    if (dp[w][i] != 0)  return dp[w][i];

    ll option1 = 0, option2 = 0;
    
    if (weight[i] <= w) {
        option1 = val[i] + value(w-weight[i], i+1);
    }

    option2 = value(w, i+1);
    dp[w][i] =  max(option1, option2);
    return dp[w][i];
}

int main()
{
	ios::sync_with_stdio(0);cin.tie(0);	cout.tie(0);
	
    ll w;
    cin >> n >> w;

    weight.resize(n);
    val.resize(n);

    for (int i = 0; i < n; i++)	{
        cin >> weight[i] >> val[i];
    }

    ll ans = value(w, 0);

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


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

int main() {
    int ans = 0;
    string str;
    cin >> str;
    rep(i, str.length()) if(str.at(i) == '1') ans++;
    cout << ans << endl;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

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

	    int a=gi();
	    //int b=gi();
	    //int c=gi();



        System.out.println("ABC" + a);
//        if (a%3==0 || b%3==0 || ((a+b)%3==0) ) {
//        	System.out.print("Possible");
//        }else {
//            System.out.print("Impossible");
//        }


	}

	// 文字列として入力を取得
	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());
	}
}

Measured memory_bytes: 38432
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int n = scanner.nextInt();
        int[] h = new int[n];
        int[] curH = new int[n];
        
        for (int i = 0; i < n; i++) {
            h[i] = scanner.nextInt();
        }
        int count = 0;
        outer:
        while (true) {
            int start = 0, end = 0;
            for (start = 0; start < n; start++) {
                if (curH[start] < h[start]) {
                    break;
                }
            }
            if (start >= n) {
                break;
            }
            count++;
            int i;
            for (i = start; i < n; i++) {
                if (curH[i] < h[i]) {
                    curH[i]++;
                } else {
                    break;
                }
            }
        }
        
        System.out.println(count);
    }
}


Measured memory_bytes: 23380
n,i;
ea[2<<17],eb[2<<17],next[2<<17],first[1<<17];
long M,dp1[1<<17],dp2[1<<17],L[2<<17],R[2<<17]={1};
dfs1(u,p,id)
{
	dp1[u]=1;
	id=first[u];
	while(id)
	{
		if(eb[id]!=p)
		{
			dfs1(eb[id],u);
			dp1[u]=dp1[u]*-~dp1[eb[id]]%M;
		}
		id=next[id];
	}
}
make();
dfs2(u,p,x,id)
{
	dp2[u]=dp1[u]*x%M;
	make(first[u],p,x);
	id=first[u];
	while(id)
	{
		if(eb[id]!=p)
		{
			dfs2(eb[id],u,L[id]*R[next[id]]%M+1);
		}
		id=next[id];
	}
}
make(i,p,x,t)
{
	if(i)
	{
		L[i]=x;
		t=eb[i]!=p?-~dp1[eb[i]]:1;
		make(next[i],p,1L*t*x%M);
		R[i]=R[next[i]]*t%M;
	}
}
main(u,v)
{
	scanf("%d%d",&n,&M);
	for(i=0;~scanf("%d%d",&u,&v);)
	{
		i++;
		ea[i]=u;
		eb[i]=v;
		i++;
		ea[i]=v;
		eb[i]=u;
	}
	for(i=1;i<2*n-1;i++)
	{
		next[i]=first[ea[i]];
		first[ea[i]]=i;
	}
	dfs1(1,0);
	dfs2(1,0,1);
	for(i=1;i<=n;i++)printf("%d\n",dp2[i]);
}

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

int main(){
  
  int N;
  cin >> N;
  vector<int> vals(N-1);
  rep(i,N-1) cin >> vals[i];
  
  int sum = 0;
  int pre = 0;
  int cur = 0;
  for(int i = 0; i < N; i++) {
    if (i == 0) 
      sum += vals[0];
    else if (i < N-1)
      sum += min(vals[i-1],vals[i]);
    else
      sum += vals[i-1];
  }
  
  cout << sum << endl;
  return 0;
}


Measured memory_bytes: 256
// Problem : A - ><
// Contest : AtCoder - AtCoder Grand Contest 040
// URL : https://atcoder.jp/contests/agc040/tasks/agc040_a
// Memory Limit : 1024 MB
// Time Limit : 2000 ms
// Powered by CP Editor (https://github.com/cpeditor/cpeditor)

/*⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀
⠀⠀⠀⠀⣠⣶⡾⠏⠉⠙⠳⢦⡀⠀⠀⠀
⠀⠀⠀⣴⠿⠏⠀⠀⠀⠀⠀⠀⢳⡀⠀
⠀⠀⢠⣟⣋⡀⢀⣀⣀⡀⠀⣀⡀⣧⠀
⠀⠀⢸⣯⡭⠁⠸⣛⣟⠆⡴⣻⡲⣿⠀
⠀⠀⣟⣿⡭⠀⠀⠀⠀⠀⢱⠀⠀⣿⠀
⠀⠀⠙⢿⣯⠄⠀⠀⠀⢀⡀⠀⠀⡿⠀⠀
⠀⠀⠀⠀⠹⣶⠆⠀⠀⠀⠀⠀⡴⠃⠀⠀
⠀⠀⠀⠀⠀⢸⣷⡦⢤⡤⢤⣞⣁⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀
⠀⠀⢀⣤⣴⣿⣏⠁⠀⠀⠸⣏⢯⣷⣖⣦⡀⠀⠀⠀⠀⠀⠀
⢀⣾⣽⣿⣿⣿⣿⠛⢲⣶⣾⢉⡷⣿⣿⠵⣿⠀⠀⠀⠀⠀⠀
⣼⣿⠍⠉⣿⡭⠉⠙⢺⣇⣼⡏⠀⠀⠀⣄⢸⠀⠀⠀⠀⠀⠀
⣿⣿⣧⣀⣿.........⣀⣰⣏⣘⣆⣀⠀
*/
#include <bits/stdc++.h> 
#pragma GCC optimize ("O3")
#pragma GCC target ("sse4")
 
#include <bits/stdc++.h>
#include <ext/pb_ds/tree_policy.hpp>
// #include <ext/pb_ds/assoc_container.hpp>
 
 
using namespace std;
using namespace __gnu_pbds;
 
typedef long long ll;
typedef long double ld;
typedef complex<ld> cd;
 
typedef pair<int, int> pi;
typedef pair<ll,ll> pl;
typedef pair<ld,ld> pd;
 
typedef vector<int> vi;
typedef vector<ld> vd;
typedef vector<ll> vl;
typedef vector<pi> vpi;
typedef vector<pl> vpl;
typedef vector<cd> vcd;
 
#define l00p(i, a, b) for (int i=a; i<(b); i++)
#define loop(i, a) for (int i=0; i<(a); i++)
#define rep1(i,a,b) for (int i = (b)-1; i >= a; i--)
#define rep(i,a) for (int i = (a)-1; i >= 0; i--)
#define trav(a,x) for (auto& a : x)
#define uid(a, b) uniform_int_distribution<int>(a, b)(rng)

#define sz(x) (int)(x).size()
#define mp make_pair
#define pb push_back
#define f first
#define s second
#define lb lower_bound
#define ub upper_bound
#define all(x) x.begin(), x.end()
#define ins insert
#define imax INT_MAX
#define imin INT_MIN
//#define MOD 998244353
 
template<class T> bool ckmin(T& a, const T& b) { return b < a ? a = b, 1 : 0; }
template<class T> bool ckmax(T& a, const T& b) { return a < b ? a = b, 1 : 0; }

mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

 
const int MOD = 1000000007;
const char nl = '\n';
const ll INF = 1e18;
const int MX = 100001; //check the limits, dummy

int main() {
	 
	ios_base::sync_with_stdio(0); cin.tie(0); 
	string s;
	cin>>s;
	int n=sz(s)+1;
	vi a(n);
	loop(i,n-1)
	{
		if(s[i]=='<')
		ckmax(a[i+1],a[i]+1);
		
	}
	rep(i,n-1)
	{
		if(s[i]=='>')
		ckmax(a[i],a[i+1]+1);
	}
	ll sum=0;
	loop(i,n+1)
	sum+=a[i];
	cout<<sum<<nl;
	
	return 0;
}
// read the question correctly (ll vs int)
// template by bqi343

Measured memory_bytes: 5864
#include <iostream>
#include <vector>
#include <algorithm>
#include <functional>

using namespace std;

int main() {
	int in;
	vector<int> s;
	while (cin >> in ) s.push_back(in);
	
	sort(s.begin(), s.end(), greater<int>());
	
	for (int i=0; i<(int)s.size(); i++) {
		cout << s[i];
		if (i<(int)s.size()-1) cout << " ";
	} 
	cout << endl;

	return 0;
}

Measured memory_bytes: 1216
n = int(input())
a = list(map(int, input().split()))
a = [0] + a + [0]
b = [abs(a[i] - a[i+1]) for i in range(n+1)]
sum = sum(b)
for i in range(n):
    print(sum - b[i] - b[i+1] + abs(a[i+2] - a[i]))

Measured memory_bytes: 14048
#include <cmath>
#include <cstdio>
#include <vector>
#include <iostream>
#include <algorithm>
#include<bits/stdc++.h>
using namespace std;
int main()
{
     long long int n,a;
        string s;
        cin>>n;
        while(n!=0)
        {
                a=n%26;
                if(a==0)
                {
                        s.push_back(122);
                        n=n/26-1;
                }
                else
                {
                        s.push_back(a+96);
                       n=n/26;
                }
        }
        reverse(s.begin(),s.end());
        cout<<s<<endl;
}

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

int main() 
{
int n;
ll k;
cin>>n>>k;
vector<int>visit(n+1);
vector<int>arr(n+1);
for(int i=1;i<=n;i++)
{
      cin>>arr[i];    
}
int pos=1;
int len=0;
while(visit[pos]==0)
{     
          visit[pos]=1;
          pos=arr[pos];
          len++;
}
int pos1=arr[pos];
int cycle=1;
while(pos1!=pos)
{
          pos1=arr[pos1];
          cycle++;
}
 
int j;
if(k<=(len-cycle))
{
          j=k;
          pos=1;
}
else
{
          k=(k-(len-cycle));
          j=k%cycle;
}
 
while(j--)
{
          pos=arr[pos];
}
cout<<pos<<endl;
}

Measured memory_bytes: 4836
#include <cmath>
#include <cstdio>
#include <vector>
#include <iostream>
#include <algorithm>
#include <queue>
#include <string>
#include <set>
#include <map>
#define REP(i,n) for(ll i = 0; i < (ll)n; i++)
#define INF 1000000000000000
using namespace std;
typedef long long ll;
typedef double db;
typedef string str;

int main(){
  str s,t;
  cin >> s >> t;
  int n = s.length();
  map<char,int> mp_s;
  int group_s[n];
  REP(i,n){
    if(mp_s[s[i]]==0){
      mp_s[s[i]]=i+1;
    }
    group_s[i]=mp_s[s[i]];
  }
  map<char,int> mp_t;
  int group_t[n];
  REP(i,n){
    if(mp_t[t[i]]==0){
      mp_t[t[i]]=i+1;
    }
    group_t[i] = mp_t[t[i]];
  }
  REP(i,n){
    if(group_s[i]!=group_t[i]){
      cout << "No" << endl;
      return 0;
    }
  }
  cout << "Yes" << endl;
  return 0;
}


Measured memory_bytes: 2312
import java.util.*;
public class Main {
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);                                                                               
        int x = sc.nextInt();
	int t = sc.nextInt();                                                                          
	if(x>=t) System.out.println(x-t);
	else System.out.println(0);
        }
}




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

using namespace std;
using ll = long long;

const int MOD = 998244353;

class Edge{
public:
    ll from,to, value;
    Edge(int f,int t, int c){
        from = f;
        to = t;
        value = c;
    }
};

int main(){
    ll N;cin >> N;
    int cnt = 0;
    for(int i = 1;i <= N/2;i++){
        if(i == N-i){
            continue;
        }
        cnt++;
    }
    cout<<cnt<<endl;
}


Measured memory_bytes: 256
#include<functional>
#include<algorithm>
#include<exception>
#include<stdexcept>
#include<streambuf>
#include<iterator>
#include<string.h>
#include<stdlib.h>
#include<typeinfo>
#include<valarray>
#include<iostream>
#include<sstream>
#include<istream>
#include<stdio.h>
#include<climits>
#include<clocale>
#include<complex>
#include<csetjmp>
#include<csignal>
#include<cstdarg>
#include<cstddef>
#include<ctype.h>
#include<cassert>
#include<cstdlib>
#include<utility>
#include<cstring>
#include<numeric>
#include<ostream>
#include<cwctype>
#include<fstream>
#include<iomanip>
#include<math.h>
#include<bitset>
#include<cctype>
#include<string>
#include<vector>
#include<limits>
#include<locale>
#include<memory>
#include<cerrno>
#include<time.h>
#include<iosfwd>
#include<cfloat>
#include<cstdio>
#include<cwchar>
#include<cmath>
#include<ctime>
#include<deque>
#include<queue>
#include<stack>
#include<list>
#include<ios>
#include<map>
#include<set>
#include<new>
#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define pii pair<int,int>
#define rep(i,n) for(int i=0;i<(n);i++)
#define rep1(i,n) for(int i=1;i<=(n);i++)
#define MP make_pair
using namespace std;
typedef long long ll;
const int INF=1e9+7;
string s;
int main()
{
	//freopen("input.in","r",stdin);
	//freopen("output.out","w",stdout);
	cin>>s;
	if (s[0]==s[1]&&s[1]==s[2]||s[1]==s[2]&&s[2]==s[3])
	{
	    cout<<"Yes";
	    return 0;
	}
	cout<<"No";
	return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
main(){
	int n,div,ans=0;
	cin>>n;
	for(int i=1;i<=n;i++){
		div=0;
		if(i%2!=0){
			for(int j=1;j<=i;j++){
				if(i%j==0)div++;
			}
		}
		if(div==8)ans++;
	}
	cout<<ans;
	return 0;
}

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

//repetition
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i, n) for(int i = 0; i < (int)(n); i++)

//container util
#define all(x) (x).begin(),(x).end()

//typedef
typedef long long ll;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<ll> VLL;
typedef vector<VLL> VVLL;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef pair<ll, ll> PLL;


//conversion
inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}

long long gcd( long long m, long long n ){

  if ( n == 0) return m;
  return gcd(n,m%n);
}//gcd

long long lcm( long long m, long long n ){
  // 引数に０がある場合は０を返す
  if ( ( 0 == m ) || ( 0 == n ) ) return 0;

  return ((m / gcd(m, n)) * n); // lcm = m * n / gcd(m,n)
}//lcm

int main(){
  ll x[2],y[2];
  cin >> x[0] >> y[0] >> x[1] >> y[1];
  cout << abs(x[1]-x[0]) + abs(y[1] - y[0]) - gcd(abs(x[1]-x[0]),abs(y[1] - y[0]))  << endl;
  return 0;
}


Measured memory_bytes: 256
import java.util.Arrays;
import java.util.Scanner;

public class Main {
	
	static void swap(Integer[] array, int a, int  b) {
		int temp = array[a];
		array[a] = array[b];
		array[b] = temp;
	}
	
	public static void main(String[] args) {
		Scanner scanner = new Scanner(System.in);
		
		Integer[] array = new Integer[3];
		
		for (int i = 0; i < 3; i++) {
			array[i] = new Integer(scanner.nextInt());
		}
		
		swap(array, 0, 1);
		swap(array, 0, 2);
		
		
		System.out.println(array[0] + " " + array[1] + " " + array[2]);
	}

}


Measured memory_bytes: 26876
N = int(input())
def cn(X, n):
    if (int(X/n)):
        return cn(int(X/n), n)+str(X%n)
    return str(X%n)
def su(n):
  ans = 0
  for chara in n:
    ans += int(chara)
  return ans
lis = []
i = 0
while i <= N:
  lis.append(su(cn(i,6))+su(cn(N-i,9)))
  i += 1
print(min(lis))

Measured memory_bytes: 3864
#!/usr/bin/env python3
import sys


def solve(S: str, T: str):
    def diff(si):
        d = 0
        for i, t in enumerate(T):
            d += S[si+i] != t
        return d
    return min(diff(si) for si in range(0, len(S)-len(T)+1))

# Generated by 1.1.7.1 https://github.com/kyuridenamida/atcoder-tools
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    S = next(tokens)  # type: str
    T = next(tokens)  # type: str
    print(solve(S, T))

def test():
    import doctest
    doctest.testmod()

if __name__ == '__main__':
    #test()
    main()


Measured memory_bytes: 9128
#include<iostream>
using namespace std;
int main()
{
    int N;
    int W;
    cin>>N>>W;
    int v[N];
    int w[N];
    for (int i = 0; i < N; i++)   
        cin>>v[i]>>w[i];
        
    int DP[N+1][W+1];

    for (int j = 0; j <= W; j++)
        DP[N][j]=0;
    
    for (int i =N-1; i>=0; i--)
        for (int j = 0; j <=W; j++)
            if(j<w[i])
                DP[i][j]=DP[i+1][j];
            else
            {   if(DP[i][j-w[i]]+v[i]>DP[i+1][j-w[i]]+v[i])
                    {
                    if(DP[i+1][j]>DP[i][j-w[i]]+v[i])
                        DP[i][j]=DP[i+1][j];
                     else DP[i][j]=DP[i][j-w[i]]+v[i];
                    }
                else
                    {
                    if(DP[i+1][j]<DP[i+1][j-w[i]]+v[i])
                        DP[i][j]=DP[i+1][j-w[i]]+v[i];
                    else DP[i][j]=DP[i+1][j];
                    }
            }
    cout<<DP[0][W]<<endl;
    return 0;
        
        
    
    
    
}


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

using namespace std;

#define REP(i, n) for(int i = 0; i < (n); i++)
#define SORT(v, n) sort(v, v+n);
#define SSORT(v, n) sort(v, v+n, greater<int>())

int main(){
	int n;
	cin >> n;
	int h[n];
	int maxm = 0;
	int ans = 0;
	for(int i=0; i<n; i++) cin >> h[i];
	for(int i=0; i<n; i++) {
		if(h[i]>=maxm){
			maxm = h[i];
			ans++;
		}
	}
	cout << ans << endl;

}

Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
using ll = long long;
using Pii = pair<int, int>;
using Pll = pair<ll, ll>;
#define rep(i, begin, n) for (int i = begin; i < n; i++)
#define repe(i, begin, n) for (int i = begin; i <= n; i++)
#define repr(i, begin, n) for (int i = begin; i > begin - n; i--)
#define repre(i, begin, end) for (int i = begin; i >= end; i--)

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

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

const int inf = INT_MAX;
const int MOD = 1000000007;
const long long INF = LLONG_MAX;

// -------------------------------------------------------

ll N, M;

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

  if (abs(N - M) > 1) {
    cout << 0;
    return 0;
  }

  ll dog = 1;
  repe(i, 1, N) {
    dog *= i;
    dog %= MOD;
  }

  ll ape = 1;
  repe(i, 1, M) {
    ape *= i;
    ape %= MOD;
  }

  ll ans = dog * ape % MOD;
  if (N == M) {
    ans *= 2;
    ans %= MOD;
  }
  cout << ans;
}


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

int func(int n){
  int sum = 0;
  while(n>0){
    sum += n%10;
    n /= 10;
  }
  return sum;
}

int main(){
  int N;
  cin >> N;
  int sum;
  sum = func(N);
  if(N%sum == 0 ){
    cout << "Yes" << endl;
  }else{
    cout << "No" << endl;
  }
}

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

int main() {
  string s;
  cin >> s;
  int ans = 0;
  rep(i, s.size()) {
    if (s[i] == 'R') ans++;
  }
  if (s == "RSR") ans = 1;

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

Measured memory_bytes: 3620
H, W = map(int, input().split())
INF = 10**15
c = []
for i in range(10):
    tmp = list(map(int, input().split()))
    c.append(tmp)

for k in range(10):
    for i in range(10):
        for j in range(10):
            c[i][j] = min(c[i][j], c[i][k]+c[k][j])
count = [0]*10
for i in range(H):
    tmp = list(map(int, input().split()))
    for t in tmp:
        if t != -1:
            count[t] += 1

ans = 0
for i in range(10):
    ans += count[i] * c[i][1]

print(ans)
    


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

int main()
{
    int n, m;
    cin >> n >> m;
    vector<vector<int>> a(m, vector<int>(n));
    rep(i, m) {
        int k;
        cin >> k;
        rep(j, k) {
            int s;
            cin >> s;
            s--;
            a[i][s] = 1;
        }
    }
    vector<int> p(m);
    rep(i, m) cin >> p[i];
    int ans = 0;
    rep(i, 1 << n) {
        bool ok = true;
        rep(j, m) {
            int cnt = 0;
            rep(k, n) {
                if (a[j][k] == 1 && (i & 1 << k)) cnt++;
            }
            if (cnt % 2 != p[j]) ok = false;
        }
        if (ok) ans++;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3636
#include <iostream>
#include <vector>
#include <fstream>
#include <algorithm>
#include <iomanip>
#include <map>
#include <queue>
#include <stack>
#include <set>
#include <ctime>
#include <iterator>
#include <sstream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
using namespace std;


int main()
{
    vector<bool> v(1e4+1,true);
    v[0]=v[1]=false;
    vector<int> primes;
    for(int c=2;c<1e4+1;c++)
    {
        if(!v[c]) continue;
        primes.push_back(c);
        for(int c2=c+c;c2<1e4+1;c2+=c) v[c2]=false;
    }

    int N;
    cin>>N;
    int sum = 0;
    for(int c=0;c<N;c++)
    {
        int a;
        cin>>a;
        for(int c2=0;c2<primes.size();c2++)
        {
            if(a%primes[c2] == 0 && a!= primes[c2]) goto nop;
        }
        sum ++;
        nop:;
    }
    cout<<sum<<endl;
}

Measured memory_bytes: 1236
#include <iostream>
#include <string>

using namespace std;
 
int main()
{
    int num, count = 0;
    string ans;
    cin >> num >> ans;
    while(--num >= 0){
        string S;
        cin >> S;
        bool flag = false;
        //全探索
        for(int i = 0; i < S.size()-ans.size()+1; i++){
        	//j文字飛ばしで見る
            for(int j = 1; j < S.size(); j++){
                string L;
                //おんなじ文字列できたらflag立てる
                for(int k = i; k < S.size(); k += j){
                    L += S[k];
                    if(L == ans){
                        flag = true;
                        break;
                    }
                }
            }
        }
        if(flag){count++;}
    }
 
    cout << count << endl;
 
    return 0;
}

Measured memory_bytes: 1212
x, n = gets.split("\s").map(&:to_i)

if n == 0
  p x
else
  p = gets.split("\s").map(&:to_i)
  nums = (0..101).to_a

  nums = (nums - p) + (p - nums)
  result = -1

  nums.each do |n|
    result = n if (x-n).abs < (x-result).abs
  end

  p result
end

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

int main() {
  
  ll	a, b, c, d;
  ll	x, y;
  ll	pac, pad, pbc, pbd;
  ll	m;
  
  cin >> a >> b >> c >> d;
  
  pac = a * c;
  pad = a * d;
  pbc = b * c;
  pbd = b * d;
  
  m = max({pac, pad, pbc, pbd});

  cout << m << endl;
  return 0;
}

Measured memory_bytes: 3632
#include <bits/stdc++.h>
#define int long long
#define ld long double

using namespace std;

void solve(){
    int n;
    cin >> n;
    vector < int > a(n), pref(n);
    for(int i = 0; i < n; ++i){
        cin >> a[i];
        if(i){
            pref[i] = pref[i - 1] + a[i];
        } else{
            pref[i] = a[i];
        }
    }
    map < int, int > c;
    int ans = 0;
    for(int i = 0; i < n; ++i){
        if(pref[i] == 0)ans++;
        ans += c[pref[i]];
        c[pref[i]]++;
    }
    cout << ans << "\n";
}




signed main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    int t = 1;
    #ifdef DEBUG
        freopen("input.txt", "r", stdin);
        freopen("output.txt", "w", stdout);
        cin >> t;
    #endif
    for(int i = 0; i < t; ++i){
        solve();
    }
}


Measured memory_bytes: 15872