akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <string>
#include <cstring>
#include <deque>
#include <list>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <complex>
#include <cmath>
#include <limits>
#include <cfloat>
#include <climits>
#include <ctime>
#include <cassert>
#include <numeric>
#include <fstream>
#include <functional>
#include <bitset>
#define chmin(a, b) ((a)=min((a), (b)))
#define chmax(a, b) ((a)=max((a), (b)))
#define fs first
#define sc second
#define eb emplace_back
using namespace std;

typedef long long ll;
typedef pair<int, int> P;
typedef tuple<int, int, int> T;

const ll MOD=1e9+7;
const ll INF=1e18;
const double pi=acos(-1);
const double eps=1e-10;

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

int main(){
    int a, b; cin>>a>>b;
    if(a != b) cout << max(a, b) * 2 - 1 << endl;
    else cout << a * 2 << endl;
}

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

// エイリアス
using  ll = long signed long;
using ull = long unsigned long;
using  ld = long double;
using   P = pair<int, int>;
using llP = pair<ll, ll>;
using DoP = pair<double, double>;

// 汎用マクロ
#define ALL(a) (a).begin(), (a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define rep(i, n) for (int i = 0; i < n; ++i)
#define FOREACH(i,q) for (auto &i : q)
#define UNIQUE(v) do { sort((v).begin(), (v).end()); (v).erase(unique((v).begin(), (v).end()), (v).end()); } while (false)
#define SZ(x) ((int)(x).size())
template <class T>inline bool chmin(T &a, const T b) {if (a > b) { a = b; return true;} return false;}
template <class T>inline bool chmax(T &a, const T b) {if (a < b) { a = b; return true;} return false;}
template <class T>inline void line_out(const vector<T> vec) {int n = SZ(vec); rep(i, n) { cout << vec[i]; if(i < n-1) cout << " ";}cout << endl;}
const int di[] = {0, 1, 0, -1, 1, 1, -1, -1};
const int dj[] = {1, 0, -1, 0, 1, -1, 1, -1};
const int INF = 1 << 28;
const ll INF64 = 1ll << 55;
const int mod = 1000000007;
//const int mod = 998244353;
struct mint
{
  ll x; // typedef long long ll;
  mint(ll x = 0) : x((x % mod + mod) % mod) {}
  mint operator-() const { return mint(-x); }
  mint &operator+=(const mint a)
  {
    if ((x += a.x) >= mod)
      x -= mod;
    return *this;
  }
  mint &operator-=(const mint a)
  {
    if ((x += mod - a.x) >= mod)
      x -= mod;
    return *this;
  }
  mint &operator*=(const mint a)
  {
    (x *= a.x) %= mod;
    return *this;
  }
  mint operator+(const mint a) const
  {
    mint res(*this);
    return res += a;
  }
  mint operator-(const mint a) const
  {
    mint res(*this);
    return res -= a;
  }
  mint &operator++()
  {
    if ((x += 1) >= mod)
      x -= mod;
    return *this;
  }
  mint &operator--()
  {
    if ((x += mod - 1) >= mod)
      x -= mod;
    return *this;
  }
  mint operator*(const mint a) const
  {
    mint res(*this);
    return res *= a;
  }
  mint pow(ll t) const
  {
    if (!t)
      return 1;
    mint a = pow(t >> 1);
    a *= a;
    if (t & 1)
      a *= *this;
    return a;
  }

  // for prime mod
  mint inv() const
  {
    return pow(mod - 2);
  }
  mint &operator/=(const mint a)
  {
    return (*this) *= a.inv();
  }
  mint operator/(const mint a) const
  {
    mint res(*this);
    return res /= a;
  }
};

int main()
{
  string s; cin >> s;
  int n = s.size();
  string t = "";
  for(auto c : s) if(c != 'x') t += c;
  int m = t.size();
  string t1 = t.substr(0, m/2);
  string t2 = t.substr(m-m/2, m/2); reverse(ALL(t2));
  if(t1 != t2) {
    cout << -1 << endl;
    return 0;
  }
  int count = 0;
  vector<int> vec;
  rep(i, n) {
    if(s[i] == 'x') ++count;
    else {
      vec.push_back(count);
      count = 0;
    }
  }
  vec.push_back(count);
  int ans = 0;
  rep(i, SZ(vec)/2) ans += abs(vec[i]-vec[SZ(vec)-1-i]);
  cout << ans << endl;
}


Measured memory_bytes: 4180
import sys
sys.setrecursionlimit(15000)
x,y,a,b,c = map(int,input().split())
p = list(sorted(map(int,input().split()),reverse=True))[:x] # x
q = list(sorted(map(int,input().split()),reverse=True))[:y] # y
r = list(sorted(map(int,input().split()),reverse=True))
print(sum(sorted(p+q+r,reverse=True)[:x+y]))

Measured memory_bytes: 109420
#include<iostream>
#include<iomanip>
#include<string>
#include<array>
#include<cmath>
#include<vector>
#include<utility>
#include<algorithm>
#include<ctype.h>
using namespace std;


int main() {
	long long int a,b,c;
	cin >> a >> b;
	for (int i = 1; i <= a ;i++) {
		if ((i*b)%a==0) {
			cout << i*b << endl;
			return 0;
		}
	}
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define FOR(i, a, b) for(int i=a; i<b; i++)
#define REP(i, n) FOR(i, 0, n)
using namespace std;

int main() {
    int H, W;
    cin >> H >> W;
    string str[H+2];
    FOR(i, 1, H+1) {
        cin >> str[i];
        str[i].insert(str[i].begin(), '#');
        str[i] += '#';
    }
    REP(i, W+2) {
        str[0] += '#';
        str[H+1] += '#';
    }
    REP(i, H+2) {
        cout << str[i] << "\n";
    }
}

Measured memory_bytes: 256
from subprocess import*
with open('Main.java','w')as f:f.write(r"""
import java.util.Scanner;
public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = Integer.parseInt(sc.next());
		int[] a = new int[n];
		for (int i = 0; i < n; i++)
			a[i] = Integer.parseInt(sc.next());
		int diff = 0;
		long c = 0;
		for (int i = 0; i < n; i++) {
			diff += a[i];
			if (i % 2 == 0) {
				if (diff <= 0) {
					c += -diff + 1;
					diff = 1;
				}
			}
			else {
				if (diff >= 0) {
					c += diff + 1;
					diff = -1;
				}
			}
		}
		long ans = c;
		c = 0;
		diff = 0;
		for (int i = 0; i < n; i++) {
			diff += a[i];
			if (i % 2 != 0) {
				if (diff <= 0) {
					c += -diff + 1;
					diff = 1;
				}
			}
			else {
				if (diff >= 0) {
					c += diff + 1;
					diff = -1;
				}
			}
		}
		ans = Math.min(ans, c);
		System.out.println(ans);
	}
}
""")
call(('javac','Main.java'))
call(('java','Main'))

Measured memory_bytes: 103508
n = int(input())

m = 0
i = 1
while True:
    m += i
    if m == n:
        print('Yes')
        print(i+1)
        break
    elif m > n:
        print('No')
        exit()
    i += 1

ans = [[1], [1]]
max_ = 0
if i == 1:
    print('1 1')
    print('1 1')
else:
    max_a = 1
    for i_ in range(1, i):
        adds = list(range(max_a+1, max_a+1+len(ans)))
        for j, add in enumerate(adds):
            ans[j].append(add)
        ans.append(adds)
        max_a = adds[-1]
    for a in ans:
        print(str(len(a))+' '+' '.join(map(str, a)))

Measured memory_bytes: 9204
N = int(input())
S = [input() for i in range(N)]
str_dict = {}
answer = []

for i in range(N):
  if S[i] not in str_dict.keys():
    str_dict[S[i]] = 1
  else:
    str_dict[S[i]] += 1
else:
  max_val = max(str_dict.values())
  for i in str_dict:
    if str_dict[i] == max_val:
      answer.append(i)
  else:
    answer.sort()
    for i in range(len(answer)):
      print(answer[i])
  

Measured memory_bytes: 35220
from math import ceil
n = int(input())
p_array = [int(x) for x in input().split()]
p_dict = {}
for i, j in enumerate(p_array):
    p_dict[i + 1] = j
flags = [False for x in range(n)]
for i, j in p_dict.items():
    flags[i - 1] = i == j

cnt = sum([1 & x for x in flags])
now = False
duplicate = 0
for flag in flags:
    if flag:
        duplicate += 1
        now = True
    else:
        cnt -= duplicate-ceil(duplicate/2) if duplicate >= 2 else 0
        duplicate = 0
        now = False
else:
    cnt -= duplicate-ceil(duplicate/2) if duplicate >= 2 else 0

print(cnt)


Measured memory_bytes: 20704
#include <iostream>
#include <cstdio>
#include <cstring>
#include <vector>
#include <algorithm>
#include <cmath>

using namespace std;

#define mp make_pair
#define pb push_back
#define ll long long

#define maxN 100011
#define inf (17 * maxN)


const int mask = (1 << 30) - 1;

int n, i, x, y;
vector<int> list[maxN];
int conf[maxN];

void solve(int node, int root) {
    int mand, mor, pos;

    mand = 0;
    mor = 0;

    for (auto to : list[node]) {
        if (to == root) continue;
        solve(to, node);

        mand |= (mor & conf[to]);
        mor |= conf[to];
    }


    for (pos = 0; (1 << pos) <= mand; pos++);
    for (; (1 << pos) & mor; pos++);

    mor |= 1 << pos;
    for (pos--; pos >= 0; pos--) mor &= mask ^ (1 << pos);
    conf[node] = mor;
}

int main()
{
    //freopen("test.in","r",stdin);

    scanf("%d", &n);
    for (i = 1; i < n; i++) {
        scanf("%d%d", &x, &y);
        list[x].pb(y);
        list[y].pb(x);
    }

    solve(1, 0);

    int ans = 0;
    for (; (1 << ans) <= conf[1]; ans++);

    printf("%d", ans - 1);


    return 0;
}


Measured memory_bytes: 11776
#include<bits/stdc++.h>
#define st first
#define nd second

using ll = long long ;
using namespace std;
using pii = pair<int,int>;

int main(){
	int a, b, c;
	scanf("%d %d %d",&a, &b,&c);
	printf("%d %d %d",c, a, b);

}

Measured memory_bytes: 256
#include <stdio.h>
#include <algorithm>
using namespace std;

#define maxn 100010
int  main()
{
	int m,n;
	int num[maxn];
	int i;
	int min;
	int temp;
	while(scanf("%d %d",&m,&n)!=EOF)
	{
		for(i=1;i<=m;i++)
		{
			scanf("%d",&num[i]);
		}
		sort(num+1,num+1+m);
		min=1000000009;
		for(i=1;i<=m-n+1;i++)
		{
			temp=num[i+n-1]-num[i];
			if(temp<min){
				min=temp;
			}
		}
		printf("%d\n",min);
	}
}

Measured memory_bytes: 640
n,m = map(int,input().split())
num = [-1]*n
for i in range(m):
  s,c = map(int,input().split())
  if n!=1 and s==1 and c==0:
    print(-1)
    exit()
  if num[s-1]==-1: num[s-1] = c
  elif num[s-1]!=c:
    print(-1)
    exit()
for i in range(n):
  if num[i] == -1: num[i] = 0
if num[0] == 0 and len(num)!=1: num[0] = 1
for i in range(n):
  print(num[i],end='')

Measured memory_bytes: 3064
program Dice
implicit none
integer::N,n1,n2,c,i

read *,N
c=0

do i=1,N
read *,n1,n2
if ( n1 == n2 ) then
 c=c+1
else
 c=0
end if
if ( c >= 3 ) exit
end do

if ( c >= 3 ) then
 print *,"Yes"
else
 print *,"No"
end if

end program Dice


Measured memory_bytes: 2856
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Scanner;
 
public class Main{
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        boolean [] number = new boolean[1000001];
        number[0] = false;
        number[1] = false;
        for(int i=2;i<=1000000;i++) {
            number[i] = true;
        }
        for(int i=2;i<=500000;i++) {
            for(int j=2;j<=1000000/i;j++) {
                number[i*j] = false;
            }
        }
        while(true) {
            int n = sc.nextInt();
            int p = sc.nextInt();
            if(n==-1 && p==-1) break;
//          long [] ans = new long[120];
//          for(int i=0;i<100;i++) {
//              ans[i] = 2000000;
//          }
             
            int [] prime = new int[1000001];
            for(int i=0,j=2;j<=1000000;j++) {
                if(number[j]) {
                    prime[i] = j;
                    i++;
                }
            }
 
             
            /*for(int i=0;i<a;i++) {
                System.err.printf(prime[i]+" ");
            }*/
                 
            
            List<Integer> ans=new ArrayList<Integer>();
            int a = 0;
            while(prime[a]<=n) a++;
             
            for(int i=a;i<a+p;i++) {
                for(int j=i;j<a+p;j++) {
                    ans.add( prime[i] + prime[j]);
                }
            }
//           for(int i=0;i<120;i++) {
//                  System.err.print(ans[i]+" ");
//              }
//              System.err.println();
            Collections.sort(ans);
            //System.err.println(ans);
             
            System.out.println(ans.get(p-1));
        }
    }
}


Measured memory_bytes: 435780
#include<iostream>
#include<algorithm>
#include<string>
#include<vector>
#include<cstring>
#include<queue>
#include<tuple>
#include<utility>
#include<map>
#include<math.h>
#include<iomanip>
#include<stdio.h>
#include<stdlib.h>
using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
#define FOR(i, a, b) for (int i=a; i<(b); i++)
#define range(a) a.begin(), a.end()
#define endl "\n"
#define Yes() cout << "Yes" << endl
#define No() cout << "No" << endl
using Graph = vector<vector<int>>;
const unsigned long long mod = 1e9 + 7;
const long long INF = 1LL<<60;
const int dx[4]={1,0,-1,0};
const int dy[4]={0,1,0,-1};
void chmin(long long &a, long long b) { if (a > b) a = b; }
void chmax(long long &a, long long b) { if (a < b) a = b; }

int main(void){
	ios::sync_with_stdio(0);
	cin.tie(0);
	string S;	cin>>S;
	int sum=0;
	FOR(i,0,S.size()){
		sum+=S.at(i) -'0';
	}

	if(sum%9==0)	Yes();
	else No();

    return 0;
}



Measured memory_bytes: 3760
#include <bits/stdc++.h>
#define repz(i, z, n) for (decltype(n) i = (z); i < (n); i++)
#define rep(i, n) for (decltype(n) i = 0; i < (n); i++)

#define REPZ(i, z, n) for (decltype(n) i = (z); i <= (n); i++)
#define REP(i, n) for (decltype(n) i = 0; i <= (n); i++)
#define ALL(v) v.begin(), v.end()
#define SIZE(v) ((ll)(v).size())
#define MAX(v) (*max_element(ALL(v)))
#define MIN(v) (*min_element(ALL(v)))
#define INF 1000000000000  // 1E+12

// 略
#define PB push_back
#define F first
#define S second
#define MP make_pair
#define READ cin >>
#define PRINT cout <<
#define PYES cout << "YES" << endl
#define pyes cout << "Yes" << endl
#define POK cout << "OK" << endl
#define PNO cout << "NO" << endl
#define pno cout << "No" << endl
#define PNG cout << "NG" << endl
#define ret return 0

using namespace std;

// デバッグ用
void debug_out() { cout << endl; }
template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
  cout << H << " ";
  debug_out(T...);
}

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

#ifdef _DEBUG
#define debug(...) debug_out(__VA_ARGS__)
#else
#define debug(...)
#endif

// typedef
typedef long long ll;
typedef unsigned long long ul;
typedef long double ld;
typedef pair<ll, ll> pl;

// const
// 円周率
const ld pi = acos(-1);
// mod用
// 1E+9 +7
const ll mod = (ll)1e+9 + 7;
// 1s間で可能なループ回数2E+8回
// ll        最大値2147483647         〜2E+9
// long long  最大値9223372036854775807〜9E+18
// 総和accumulate
// 単純リストvector<type> push_back
// 連想配列map<key,value> insert,
// 集合set<type>
// pair キーとバリューを格納 firstとsecondでアクセス
// 小数点指定 cout << fixed << setprecision(15) << endl;
// to_string<->stoi
// stoll(longlong)
// stod(double)
// deep copy v1->v2 copy(v1.begin(), v1.end(), back_inserter(v2) );
// 大文字65-90(-32)
// 小文字97-122(+32)
//  priority_queue<pair<ll, ll>, vector<pair<ll, ll>>, greater<pair<ll, ll>>>
//  ba;
signed main() {
  // faster
  // C言語流の入出力は使用できない
  ios::sync_with_stdio(false);
  std::cin.tie(nullptr);
  ll n;
  cin >> n;
  vector<ll> h(n);
  vector<ll> dp(n, INF);
  rep(i, n) cin >> h[i];
  dp[0] = 0;
  repz(i, 0, n) {
    ll newi = i + 1, newi2 = i + 2;
    if (newi < n) chmin(dp[newi], dp[i] + abs(h[newi] - h[i]));
    if (newi2 < n) chmin(dp[newi2], dp[i] + abs(h[newi2] - h[i]));
  }
  cout << dp[n - 1] << endl;

  ret;
}


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

int main(void) {
    int n, i, j, k, cnt;
    char dir;
    map<char, int> dtoi;
    dtoi['N'] = 0; dtoi['E'] = 1; dtoi['S'] = 2; dtoi['W'] = 3;
    int dx[4] = {0, 1, 0, -1};
    int dy[4] = {1, 0, -1, 0};

    while (1) {
        cin >> n;
        if (!n) break;

        int field[21][21];
        int x = 10, y = 10;

        for (i = 0; i < 21; i++) {
            for (j = 0; j < 21; j++) {
                field[i][j] = 0;
            }
        }

        for (k = 0; k < n; k++) {
            cin >> i >> j;
            field[i][j] = 1;
        }

        cin >> n;
        for (k = 0; k < n; k++) {
            cin >> dir >> i;
            for (j = 0; j < i; j++) {
                x += dx[dtoi[dir]];
                y += dy[dtoi[dir]];
                field[x][y] = 0;
            }
        }

        bool flag = true;
        for (i = 0; i < 21; i++) {
            for (j = 0; j < 21; j++) {
                if (field[i][j]) {
                    flag = false;
                    break;
                }
            }
            if (!flag) break;
        }
        if (flag) cout << "Yes" << endl;
        else cout << "No" << endl;
    }
    return 0;
}

Measured memory_bytes: 1188
// 20
/****************************************************
https://searleser97.gitlab.io/algorithms/template.cpp
****************************************************/

#include <bits/stdc++.h>
using namespace std;
#define endl '\n'
#define forr(_, x, n) for (int _ = x; _ > n; _--)
#define fos(_, x, n, s) for (int _ = x; _ < n; _ += s)
#define forn(_, x, n) fos(_, x, n, 1)
#define rep(_, n) forn(_, 0, n)
#define fi first
#define se second
#define pb push_back
#define pairii pair<int, int>
#define all(x) x.begin(), x.end()
#define cerr(s) cerr << "\033[48;5;196m\033[38;5;15m" << s << "\033[0m"
// typedef __int128_t lli;
typedef long long int li;
typedef long double ld;
// 12
void _main(int tc) {
  int n;
  cin >> n;

  vector<int> v(n);
  rep(i, n) cin >> v[i];

  int ans = 1 << 30;
  forn(i, -100, 101) {
    int aux = 0;
    rep(j, n) {
      aux += (v[j] - i) * (v[j] - i);
    }
    ans = min(ans, aux);
  }
  cout << ans << endl;
}

int main() {
  ios_base::sync_with_stdio(0), cin.tie(0);
  _main(0); return 0;
  int tc;
  cin >> tc;
  rep(i, tc) _main(i + 1);
}

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

typedef long long ll;
const ll MOD = 1e9 + 7;
const ll inf = 1LL<<60;
const double eps = 1e-9;
typedef long long ll;

int main()
{
    int n;
    cin >> n;
    vector <int> a(n, 0);
    for (int i = 0; i < n; i++) cin >> a[i];
    ll m = inf, sum;
    for (int i = -100; i <= 100; i++) {
        sum = 0;
        for (int j = 0; j < n; j++) sum += (i-a[j])*(i-a[j]);
        m = min(m, sum);
    }
    cout << m << endl;
    return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
#include <string.h>
#include <algorithm>
#include <iostream>
#include <math.h>
#include <assert.h>
#include <vector>
#include <complex>

using namespace std;
typedef long long ll;
typedef unsigned int uint;
typedef unsigned long long ull;
typedef complex<double> Point;
static const double EPS = 1e-9;
static const double PI = acos(-1.0);

#define REP(i, n) for (int i = 0; i < (int)(n); i++)
#define FOR(i, s, n) for (int i = (s); i < (int)(n); i++)
#define FOREQ(i, s, n) for (int i = (s); i <= (int)(n); i++)
#define FORIT(it, c) for (__typeof((c).begin())it = (c).begin(); it != (c).end(); it++)
#define MEMSET(v, h) memset((v), h, sizeof(v))

double d;

int main() {
  int n;
  while (scanf("%d %lf\n", &n, &d), d != 0 && n != 0) {
    Point p(0, 0);
    Point vect(0, 1);
    REP(i, n) {
      double sl, sr, t;
      scanf("%lf %lf %lf", &sl, &sr, &t);
      sl *= 2 * PI / 360;
      sr *= 2 * PI / 360;
      //cout << sl << " "<< sr << endl;
      if (sl == sr) {
        p += vect * sl * t;
      } else {
        double s = sr - sl > 0 ? 1 : -1;
        double theta = s * t * (sr - sl) / (2 * d);
        double r = (sl * t) / theta + s * d;
        //cout << theta << " " << r << " " << sl * t / theta << " " << sr * t / theta << endl;
        Point center = p + r * vect * Point(0, s);
        Point R = p - center;
        p = center + R * Point(cos(theta), sin(theta) * s);
        vect *= Point(cos(theta), sin(theta) * s);
      }
    }
    printf("%.3f\n%.3f\n", p.real() + EPS, p.imag() + EPS);
  }
}

Measured memory_bytes: 0
n = input()
a = list(map(int,input().split()))
count = 0
flag = True
while flag:
    for i in range(len(a)):
        if a[i] % 2 != 0:
            print(count)
            flag = False
            break
    else:
        count += 1
        a = [ i / 2 for i in a]
    


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

int main(){
  int column, row, res;

  cin >> column >> row;

  int matrix[101][101], vector_a[101];


  for(int i = 1; i <= column; i++){
    for(int j = 1; j <= row; j++){
      cin >> matrix[i][j];
    }
  }

  for(int i = 1; i <= row; i++){
    cin >> vector_a[i];
  }

  for(int i = 1; i <= column; i++){
    res = 0;
    for(int j = 1; j <= row; j++){
      res += matrix[i][j] * vector_a[j];
    }
    cout << res << endl;
  }
  return 0;
}

Measured memory_bytes: 1196
#include <bits/stdc++.h>
using namespace std;
using ll         = long long;
constexpr ll MOD = 1000000007;
#define REP(i, n) for (ll i = 0; i < (n); i++)
#define REP2(i, x, n) for (ll i = x; i < (n); i++)
const long long INF = numeric_limits<long long>::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;
}
vector<ll> getNums(ll N) {
    vector<ll> num(N);
    REP(i, N) {
        cin >> num[i];
    }
    return num;
}
int main() {
    string S;
    cin >> S;

    ll count = 0;
    ll cMax  = 0;
    for (const auto& c : S) {
        if (c == 'R')
            count++;
        else {
            chmax(cMax, count);
            count = 0;
        }
    }

    cout << max(cMax, count) << endl;
    return 0;
}

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

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

#define REP(i, n) for(int i=0; i<(n); ++i)
#define FOR(i, a, b) for(int i=(a); i<(b); ++i)
#define FORR(i, a, b) for(int i=(b)-1; i>=(a); --i)

#define DEBUG(x) cout<<#x<<": "<<(x)<<'\n'
#define DEBUG_VEC(v) cout<<#v<<":";REP(i, v.size())cout<<' '<<v[i];cout<<'\n'
#define ALL(a) (a).begin(), (a).end()

template<typename T> inline void CHMAX(T& a, const T b) {if(a<b) a=b;}
template<typename T> inline void CHMIN(T& a, const T b) {if(a>b) a=b;}

constexpr ll MOD=1000000007ll;
// constexpr ll MOD=998244353ll;
#define FIX(a) ((a)%MOD+MOD)%MOD

const double EPS=1e-11;
#define EQ0(x) (abs((x))<EPS)
#define EQ(a, b) (abs((a)-(b))<EPS)

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  // cout<<setprecision(10)<<fixed;
  int x;
  cin>>x;
  REP(i, x+1){
    if(100*i<=x && x<=100*i+5*i){
      cout<<1<<'\n';
      return 0;
    }
  }
  cout<<0<<'\n';
  return 0;
}

Measured memory_bytes: 256
require 'pp'

n = gets.to_i
l_n = gets.split.map(&:to_i)

cnt = 0
(0..(n-1)).to_a.combination(3) do |x|
    a, b, c = l_n[x[0]], l_n[x[1]], l_n[x[2]]
    if a == b || b == c || c == a
        next
    elsif a + b > c && b + c > a && c + a > b
        #pp x
        cnt += 1
    end
end

    
puts cnt

        

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

#define rep(i,n) for(int i = 0; i < n; i++)
#define Rep(i,n) for(int i = 1; i <= n; i++)
#define sz(x) int(x.size())
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()
#define YesorNo(a) printf(a ? "Yes\n" : "No\n")
#define endl '\n'
#define fi first
#define se second
using ll = long long;
using P = pair<int,int>;
using Pl = pair<ll,ll>;
template<class T> using V = vector<T>;
const int dx[] = {0,1,0,-1,1,1,-1,-1};
const int dy[] = {1,0,-1,0,1,-1,-1,1};
const int inf = (1<<30)-1;
const ll infll = (1LL<<62)-1;
ll ceil(const ll &a, const ll &b){return ((a)+(b)-1)/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; }


struct UnionFind { // UnionFindTree
  vector<int> d;
  UnionFind(int n): d(n,-1) {}
  int find(int x) {
    if(d[x] < 0) return x;
    return d[x] = find(d[x]);
  }
  bool unite(int x, int y) {
    x = find(x);
    y = find(y);
    if(x == y) return false;
    if(-d[x] < -d[y]) swap(x,y);
    d[x] += d[y];
    d[y] = x;
    return true;
  }
  bool same(int x, int y) { return find(x) == find(y); }
  int size(int x) { return -d[find(x)]; }
};


int main(){

    int n, q;
    cin >> n >> q;
    UnionFind uf(n);
    rep(i,q) {
        int d, a, b;
        cin >> d >> a >> b;
        if(d == 0) 
            uf.unite(a,b);
        else 
            cout << uf.same(a,b) << endl;
    }
}


Measured memory_bytes: 3164
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <algorithm>

using namespace std;

int main() {
  int a, b, c;
  scanf("%d%d%d", &a, &b, &c);
  printf("%d\n", b / a < c ? b / a : c);
}

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

int main(){
  int H, W;
  cin >> H >> W;
  vector<vector<int>> A(H,vector<int>(W));
  for(int i = 0; i < H; ++i)
    for(int j = 0; j < W; ++j)
      cin >> A[i][j];
  int ans = 1e9;
  for(int i = 0; i < H; ++i){
    for(int j = 0; j < W; ++j){
      int t = 0;
      for(int k = 0; k < H; ++k){
        for(int l = 0; l < W; ++l){
          t += min(abs(i-k),abs(j-l))*A[k][l];
        }
      }
      ans = min(ans,t);
    }
  }
  cout << ans << endl;
}



Measured memory_bytes: 3156
#include <iostream>
#include <string>
#include <vector>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <algorithm>
#include <cstdio>
#include <cstdlib>
#include <cmath>
using namespace std;

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

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

// 4近傍、8近傍
int dx[] = {1, 0, -1, 0, 1, -1, -1, 1};
int dy[] = {0, 1, 0, -1, 1, 1, -1, -1};

int main() {
  // 入力
  int N;
  cin >> N;
  int c[N-1], s[N-1], f[N-1];
  for (int i = 0; i < N - 1; i++) cin >> c[i] >> s[i] >> f[i];

  for (int i = 0; i < N - 1; i++) {
    int ans = s[i] + c[i];
    for (int j = i + 1; j < N - 1; j++) {
      if (ans < s[j]) {
        ans = s[j];
      } else {
        while (ans % f[j] != 0) ans++;
      }
      ans += c[j];
    }
    cout << ans << endl;
  }
  cout << 0 << endl;

  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<cmath>
#include<set>

using namespace std;

int main()
{
	int r, D, x2000;
	cin >> r >> D >> x2000;

	for (int i = 2001; i <= 2010; i++) {
		x2000 = r * x2000 - D;
		cout << x2000 << endl;
	}
}


Measured memory_bytes: 3600
#include <bits/stdc++.h>
#include <math.h>
#define REP(i, n) for(int i = 0; i < (n); i++)
#define ALL(v) (v).begin(), (v).end()
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
const int INF = 1001001001;
const int mINF = -1001001001;


int main() {
  string s,p;
  cin >> s >> p;
  s = s + s;
  if(s.find(p) == string::npos) {
   cout << "No" << endl;
  } else {
    cout << "Yes" << endl;
  }
  return 0;
}



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

int main() {
  int a,b,c,d,e,f;
  cin >> a >> b >> c >> d >> e >> f;
  vector<bool>dpw(31,false);
  dpw[0] = true;
  rep(i,0,31){
    if(!dpw[i]) continue;
    if(i+a <= 30) dpw[i+a] = true;
    if(i+b <= 30) dpw[i+b] = true;
  }
  vector<int>w;
  rep(i,0,31) if(dpw[i] && i != 0) w.push_back(i*100);
  
  vector<bool>dps(3000+1,false);
  dps[0] = true;
  rep(i,0,dps.size()){
    if(!dps[i]) continue;
    if(i+c < dps.size()) dps[i+c] = true;
    if(i+d < dps.size()) dps[i+d] = true;
  }
  vector<int>s;
  rep(i,0,dps.size()) if(dps[i]) s.push_back(i);
  
  int as,ss;
  double den = 0;
  rep(i,0,w.size()){
    rep(j,0,s.size()){
      double wa = w[i],su = s[j];
      if(100*s[j] <= e*w[i] && w[i]+s[j] <= f && su/(wa+su) >= den){
        as = w[i]+s[j];
        ss = s[j];
        den = su/(wa+su);
      }
    }
  }
  cout << as << " " << ss << endl;
}

Measured memory_bytes: 3592
import java.util.Scanner;
 public class Main{
   public static void main(String[]args){ 
     Scanner sc = new Scanner(System.in);
     	String s = sc.next();
     	String t = sc.next();
     	int a = sc.nextInt();
     	int b = sc.nextInt();
     	String u = sc.next();
     if(u.equals(s)){
       System.out.println((a-1)+" "+b);
     }else if(u.equals(t)){
       System.out.println(a+" "+(b-1));
     }
   }
 }

Measured memory_bytes: 21588
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int ar[1010];
    for(int i=0;i<=100;i++)
    {
        ar[i]=i;
    }
    for(int i=1;i<=100;i++)
    {
        ar[i]+=ar[i-1];
    }
    int n;
    while(cin>>n)
    {
        cout<<ar[n]<<endl;
    }

    return 0;
}


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

int main() {
  string S, T;
  cin >> S >> T;
  int A, B;
  cin >> A >> B;
  
  string U;
  cin >> U;
  if (U == S) A--;
  if (U == T) B--;
  
  cout << A << " " << B << endl;
  
}

Measured memory_bytes: 256
#include <map>
#include <queue>
#include <string>
#include <vector>
#include <utility>
#include <iostream>
#include <algorithm>

#define INF (1 << 29)

using namespace std;

int BFS(string S, string T) // S --> T
{
	map<string, int> D; D[S] = 1;

	queue<pair<string, int> > que; que.push(make_pair(S, 1));

	if (S == T) { return 0; }

	while (!que.empty())
	{
		string S2 = que.front().first;

		int dist = que.front().second; que.pop();

		for (int i = 0; i < T.size() - 1; i++)
		{
			string S3 = S2;

			swap(S3[i], S3[i + 1]);

			if (S3 == T) { return dist; }

			if (D[S3] == 0)
			{
				D[S3] = dist + 1;

				que.push(make_pair(S3, dist + 1));
			}
		}
	}

	return INF;
}

int main()
{
	int N, M;

	cin >> N >> M;

	vector<int> B(N); for (int i = 0; i < N; i++) { cin >> B[i]; }
	vector<int> R(M); for (int i = 0; i < M; i++) { cin >> R[i]; }

	string S, T1, T2;

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

	for (int i = 0; i < M; i++)
	{
		for (int j = 0; j < R[i]; j++) 
		{
			T1 += i % 2 + 48;
			T2 += (i + 1) % 2 + 48;
		}
	}

	int res1 = BFS(S, T1);
	int res2 = BFS(S, T2);

	cout << min(res1, res2) << endl;

	return 0;
}

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

typedef unsigned long long ull;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<double, double> pdd;
const ull mod = 1000000000 + 7;
#define REP(i,n) for(int i=0;i<(int)n;++i)

const int MAX_V = 1000;
const int INF = INT_MAX/3;

struct edge{
    int to, cap, rev;
    edge(int to, int cap, int rev): to(to), cap(cap), rev(rev) {}
};

struct graph{
    vector<edge> G[MAX_V];
    bool visited[MAX_V];

    void add_edge(int from, int to, int cap){
        G[from].push_back((edge){to, cap, G[to].size()});
        G[to].push_back((edge){from, cap, G[from].size()-1});
    }

    int ford_fulkerson(int s, int t){
        int flow = 0;
        int f = 1;
        while(f!=0){
            memset(visited, false, sizeof(visited));
            f = dfs(s, t, INF);
            flow += f;
        }
        return flow;
    }

    int dfs(int v, int t, int f){
        visited[v] = true;
        if(v==t) return f;
        for(int i=0;i<G[v].size();i++){
            edge &e = G[v][i];
            if(!visited[e.to] && e.cap > 0){
                int d = dfs(e.to, t, min(f, e.cap));
                if(d>0){
                    e.cap -= d;
                    G[e.to][e.rev].cap += d;
                    return d;
                }
            }
        }
        return 0;
    }

    void print_graph(int V){
        for(int i=0;i<V;i++){
            printf("vertex: %d\n", i);
            for(int j=0;j<G[i].size();j++){
                printf("to: %d, cap: %d\n", G[i][j].to, G[i][j].cap);
            }
            cout << endl;
        }
    }
};

int main(){
    int H, W;
    cin >> H >> W;
    string s;
    graph gr;
    int sx, sy, tx, ty;
    REP(i, H){
        cin >> s;
        REP(j, W){
            if(s[j]=='o'){
                gr.add_edge(i, H+j, 1);
            }else if(s[j]=='S'){
                gr.add_edge(H+W, i, INF);
                gr.add_edge(H+W, H+j, INF);
                sx = i;
                sy = j;
            }else if(s[j]=='T'){
                gr.add_edge(i, H+W+1, INF);
                gr.add_edge(H+j, H+W+1, INF);
                tx = i;
                ty = j;
            }
        }
    }
    if(sx==tx || sy==ty){
        cout << -1 << endl;
        return 0;
    }
    ll res = gr.ford_fulkerson(H+W, H+W+1);
    cout << res << endl;
    return 0;
}

Measured memory_bytes: 640
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<string>
#include<cstring>
#include<cmath>
#include<vector>
#include<map>
#include<stack>
#include<set>
#include<cstdlib>
#include<deque>
#include<queue>
#include<bitset>
#include<functional>
#include<utility>
#include<list>
#include<iomanip>
#include<ctime>
#include<cassert>
#define rep(i,n) for(int i=0;i<(int)(n);i++)
using namespace std;
const int INF=1e9+1;
int a[111],ans=INF,mx,mi;
int main()
{
	int n;
	cin>>n;
	for(int i=0;i<n;i++)
	{
		cin>>a[i];
		mi=min(mi,a[i]);
		mx=max(mx,a[i]);
	}
	for(int i=mi;i<=mx;i++)
	{
		int tmp=0;
		for(int j=0;j<n;j++)
		{
			tmp+=(a[j]-i)*(a[j]-i);
		}
		ans=min(ans,tmp);
	}
	cout<<ans<<endl;
	return 0;
}


Measured memory_bytes: 256
import java.util.*;
import java.io.*;
import java.math.BigInteger; 

 public class Main{
// taking inputs
static BufferedReader s1;
static BufferedWriter out;
static String read() throws IOException{String line="";while(line.length()==0){line=s1.readLine();continue;}return line;}
static int int_v (String s1){return Integer.parseInt(s1);}
static long long_v(String s1){return Long.parseLong(s1);}
static int[] int_arr() throws IOException{String[] a=read().split(" ");int[] b=new int[a.length];for(int i=0;i<a.length;i++){b[i]=int_v(a[i]);}return b;}
static long[] long_arr() throws IOException{String[] a=read().split(" ");long[] b=new long[a.length];for(int i=0;i<a.length;i++){b[i]=long_v(a[i]);}return b;}
static void assign(){s1=new BufferedReader(new InputStreamReader(System.in));out=new BufferedWriter(new OutputStreamWriter(System.out));}
// ends

//......................................@uthor_Alx..............................................


//  (Binary lifting)LCS implementation <O(NlogN,logN)>...<preprocessing,query>
//static int l,time;
//static int[][] f; // f[n][l]..
//static int[] tin, tout;
//static List<Integer>[] adj;
/*	return tin[u]<=tin[v]&&tout[u]>=tout[v]; 
}
static void dfs(int u, int p){
	tin[u]=time++;
	f[u][0]=p;
	for(int i=1;i<=l;i++){
		f[u][i]= f[f[u][i-1]][i-1];
	}

	for(int v: adj[u]){
		if(v!=p) dfs(v,u);
	}
	tout[u]=time++;
}
static int lca(int u, int v){
	if(ok(u,v)){return u;}
	if(ok(v,u)){return v;}

	for(int i=l;i>=0;i--){
		if(!ok(f[u][i],v)){
			u=f[u][i];
		}
	}
	return f[u][0];
}*/

public static void main(String[] args) throws  IOException{
	        		  assign();
              int[] arr1=int_arr();
              int k=arr1[0],n=arr1[1];
              int[] arr=int_arr();
              int max=0;
              for(int i=1;i<n;i++){
              	max=Math.max(max,Math.abs(arr[i]-arr[i-1]));
              }
              int x=k-arr[n-1]+arr[0];
              max=Math.max(max,x);
              out.write(k-max+"");
              out.flush();
	        		 
	        	}
	       
	          
	        }

	    

	
  





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

int main(void)
{ 
 long A, B, K;
 
  scanf("%ld %ld %ld", &A, &B, &K);
  if((A + B) < K)
  {
    printf("0 0\n");
  }
  else if((A - K) >= 0)
  {
    A = A - K;
    printf("%ld %ld", A, B);
  }
  else
  {
    B = B + A - K;
    printf("0 %ld", B);
  }
  return 0;
}


Measured memory_bytes: 128
#include <iostream>
#include <vector>
using namespace std;
typedef long long ll;
#define MOD 1000000007

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

  auto pow = [](ll a, int n) {
    ll res = 1;
    while (n) {
      if (n & 1) res = res * a % MOD;
      a = a * a % MOD;
      n >>= 1;
    }
    return res;
  };

  vector<ll> table(n+2), invTable(n+2);
  table[0] = 1;
  for (int i = 1; i <= n+1; i++) {
    table[i] = table[i-1] * i % MOD;
  }
  invTable[n+1] = pow(table[n+1], MOD-2);
  for (int i = n+1; i > 0; i--) {
    invTable[i-1] = invTable[i] * i % MOD;
  }

  auto comb = [&](int n, int r) {
    if (n < r) return 0LL;
    ll a = invTable[n-r] * invTable[r] % MOD;
    return table[n] * a % MOD;
  };

  vector<int> v(n+2);
  int l, r;
  for (int i = 1; i <= n+1; i++) {
    int a; cin >> a; a--;
    if (v[a]) {
      l = v[a];
      r = i;
    }
    else v[a] = i;
  }

  for (int k = 1; k <= n+1; k++) {
    int ans = comb(n+1, k) - comb(l+n-r, k-1);
    cout << (ans < 0 ? ans + MOD : ans) << endl;
  }
}

Measured memory_bytes: 3200
#include <iostream>
#include <vector>
#include <sstream>

using namespace std;

int main() {

  stringstream ss;

  int n = 1;
  cin >> n;
  ss << n;
  string str;
  ss >> str;

  for ( size_t i = 0; i < str.size(); i++ ) {
    if ( str[i] == '1' ) { str[i] = '9'; continue; }
    if ( str[i] == '9' ) { str[i] = '1'; continue; }
  }

  cout << str << endl;

  return 0;
}




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

int main()
{
    int h, w;
    int ans_h, ans_w;
    string mas[30][30];

    cin >> h >> w;
    for (int i = 0; i < h; i++) {
        for (int j = 0; j < w; j++) {
            cin >> mas[i][j];
        }
    }

    ans_h = 0;
    ans_w = 0;
    while (ans_h < h && mas[ans_h][ans_w] != "snuke") {
        ans_w = 0;
        while(ans_w < w && mas[ans_h][ans_w] != "snuke") {
            ans_w++;
        }

        if (mas[ans_h][ans_w] != "snuke") {
            ans_h++;
        }
    }


    printf("%c%d\n", 'A' + (char)ans_w, ans_h + 1);
    
    return 0;
}


Measured memory_bytes: 256
import scala.collection.mutable._
import io.StdIn.readLine

object Main extends App {
  val map = new HashMap[String,Int]
  val s = readLine.split(" ")
  s.foreach(e => {
    if(!map.contains(e)) map.put(e,1)
    else map.put(e,map(e)+1)
  })
  val maxF = map.maxBy(_._2)._1
  val maxL = s.map(e => (e.length, e)).max._2

  println(maxF + " " + maxL)
}


Measured memory_bytes: 43860
# -*- coding: utf-8 -*-
# input
s = input()
# calc
n = len(s)
int_s = []
for i in range(n):
    int_s.append(int(s[i]))
ans = 0
for i in range(n):
    for j in range(i, n):
        value = 0
        for k in range(j - i + 1):
            value += (10 ** k) * int_s[j - k]
        # i, jの位置によってansに足す値を場合分け
        if i == 0:
            if j == n - 1:
                ans += value
            else:
                ans += value * (2 ** (n + i - j - 2))
        elif j == n - 1:
            ans += value * (2 ** (n + i - j - 2))
        else:
            ans += value * (2 ** (n + i - j - 3))
# output
print(ans)

Measured memory_bytes: 3064
import java.util.*;

public class Main {
  public static void main(String[] args ) throws Exception {
    Scanner sc = new Scanner(System.in);
    int A = sc.nextInt();
    int B = sc.nextInt();
    int C = sc.nextInt();
    int X = sc.nextInt();
    
    int res = 0;
    for (int a=0; a<=A; a++) {
        for (int b=0; b<=B; b++) {
            int c = (X - (a * 500 + b * 100)) / 50;
            if (c >= 0 && c <= C) res++;
        }
    }
    
    System.out.println(res);
  }
}


Measured memory_bytes: 21844
n, k = map(int, input().split())
a = list(map(lambda x: int(x) - 1, input().split()))
ts = [[] for _ in range(n)]

p = 0
t = 0
while True:
    ts[p].append(t)
    if t == k:
        print(p + 1)
        exit()
    if len(ts[p]) == 2:
        if (k - ts[p][0]) % (ts[p][1] - ts[p][0]) == 0:
            print(p + 1)
            exit()
    p = a[p]
    t += 1


Measured memory_bytes: 115532
import std.stdio, std.conv, std.functional, std.string;
import std.algorithm, std.array, std.container, std.range, std.typecons;
import std.bigint, std.numeric, std.math, std.random;
import core.bitop;

string FMT_F = "%.10f";

static File _f;
void file_io(string fn) { _f = File(fn, "r"); }
static string[] s_rd;
T _RD(T = long)() { while(!s_rd.length) s_rd = readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }
T _RD(T = long)(File f) { while(!s_rd.length) s_rd = f.readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }
T[] _RDA(T = long)(T fix = 0) { auto r = readln.chomp.split.to!(T[]); r[] += fix; return r; }
T[] _RDA(T = long)(File f, T fix = 0) { auto r = f.readln.chomp.split.to!(T[]); r[] += fix; return r; }
T RD(T = long)() { if (_f.isOpen) return _RD!T(_f); else return _RD!T; }
T[] RDA(T = long)(T fix = 0) { if (_f.isOpen)  return _RDA!T(_f, fix); else return _RDA!T(fix); }

size_t[] MAKE_IDX(alias less = "a < b", Range)(Range range) { auto idx = new size_t[](range.length); makeIndex!(less)(range, idx); return idx;}
size_t MIN_POS(alias less = "a < b", Range)(Range range) { auto r = minPos!(less)(range); return range.length - r.length; }

void chmin(T)(ref T x, T y) { x = min(x, y); } void chmax(T)(ref T x, T y) { x = max(x, y); }
bool inside(T)(T x, T b, T e) { return x >= b && x < e; }
T lcm(T)(T x, T y) { return x * (y / gcd(x, y)); }

//long mod = 10^^9 + 7;
long mod = 998_244_353;
//long mod = 1_000_003;
void moda(T)(ref T x, T y) { x = (x + y) % mod; }
void mods(T)(ref T x, T y) { x = ((x + mod) - (y % mod)) % mod; }
void modm(T)(ref T x, T y) { x = (x * y) % mod; }
void modpow(T)(ref T x, T y) { if (!y) { x = 1; return; } auto t = x; x.modpow(y>>1); x.modm(x); if (y&1) x.modm(t); }
void modd(T)(ref T x, T y) { x.modm(y.modpow(mod - 2)); }

void main()
{
	auto R = RD;

	writefln(FMT_F, 2*R*3.14159);
	stdout.flush;
	debug readln;
}


Measured memory_bytes: 3020
#include<bits/stdc++.h>
#define line cout<<endl;
#define space cout<<" ";
#define fast ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define PI 3.141592653589793238
typedef long long int ll;

using namespace std;

const int N = 1e9+7;

vector<ll> v(100005);
ll dp[100005];


ll findans(ll n,ll k)
{
    ll mini = INT_MAX;
    if(n==0)
    {
        return 0;
    }

    if(dp[n]!=-1)
        return dp[n];

    for(int i=n-1;i>=max(n-k,(ll)0);i--)
    {
      //   cout<<"n is: "<<n<<" "<<" i is: "<<i<<endl;
         mini = min(mini,abs(v[i]-v[n])+findans(i,k));
        // cout<<"mini in: "<<mini<<" n is: "<<n<<" "<<" is is: "<<i<<" v of i: "<<v[i]<<" v of n: "<<v[n]<<endl;
    }

    return dp[n] = mini;


}

ll findans_iterative(ll n,ll k)
{
    dp[0] = 0;
    dp[1] = abs(v[0]-v[1]);
    ll mini;
    for(int i=2;i<n;i++)
    {
        mini = INT_MAX;
        for(int j=i-1;j>=max(i-k,(ll)0);j--)
        {
            mini = min(mini,dp[j]+abs(v[i]-v[j]));
        }

        dp[i] = mini;
    }

    return dp[n-1];
}


void solve()
{
    memset(dp,-1,sizeof(dp));
    ll n,k;
    cin>>n;
    cin>>k;

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


   // ll ans = findans(n-1,k);
   ll ans = findans_iterative(n,k);
    cout<<ans;

}


int main()
{
   ll t;
   t = 1;
  // cin>>t;

   while(t--)
   {
       solve();
       cout<<endl;
   }




}














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

int main() 
{
    ll n, k;
    cin >> n >> k;
    ll a[n];
    rep(i,n) {
        cin >> a[i];
        a[i]--;
    }

    if (k<n) {
        ll cur = 0;
        rep(i,k) cur = a[cur];
        cout << ++cur << endl;
        return 0;
    }


    int current = 0;
    int target = 0;
    set<ll> B;
    vector<int> C;
    bool ok = false;
    ll chain = 0;
    do {
        if (B.find(a[current]) != B.end()) {
            B.clear();
            C.clear();
            ok = true;
            target = current;
        }
        if (!ok) chain++;
        B.insert(a[current]);
        C.push_back(a[current]);
        current = a[current];
        
    } while (!ok || current != target);
    
    ll x = (k-(chain-B.size()+1))%(B.size());
    ll ans = C[x];
    ans++;

    cout << ans << endl;

    return 0;
}


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

int main(void){
  int A,B,C,X;
  int answer = 0;
  cin >> A >> B >> C >> X;
  for(int i = 0; i <= A; i++){
    for(int j = 0; j <= B; j++){
      for(int k = 0; k <= C; k++){
        int price = 500*i + 100*j + 50*k;
        if(price == X){
          answer++;
        } 
      }
    }
  }
  cout << answer;
  return 0;
}

Measured memory_bytes: 256
S = input()

count = 0
boo = False
if S[0] != 'A':
    print ('WA')
else:
    if S[1].islower() == False:
        print('WA')
    else:
        if S[-1].islower() == False:
            print ('WA')
        else:
            for str_ in S[2:-1]:
                if str_ == 'C':
                    count += 1
                else:
                    if str_.islower() == True:
                        pass
                    else:
                        boo = True

            if count == 1 and boo == False:
                print ('AC')
            else:
                print ('WA')


Measured memory_bytes: 3060
#include <algorithm>
#include <iostream>

using namespace std;

int main(int argc, char* argv[])
{
  int N; cin >> N;

  int ans; cin >> ans;
  for (int i = 1; i < N; i++) {
    int A; cin >> A;
    ans = __gcd(ans, A);
  }

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


Measured memory_bytes: 256
_x = input()
x = []
for i in _x:
    x.append(i)
count = 0

# 今まで確認してきたものはスタックに入れる
# スタックの頂上がSで次の入力がTならスタックをポップ
stack = []
i = 0
while i < len(x):
    if len(stack) > 0 and stack[-1] == "S" and x[i] == "T":
        del stack[-1]
    else:
        stack.append(x[i])
    i += 1
print(len(stack))
# print(stack)


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

#define INF 1e18
#define REP(i, n) for (int i=0; i<n; i++)
#define print(x) cout << x << endl
#define debug(x) cout << #x << " = "<< x << endl

const double PI=3.141592653589793238462643383279502884197169399375105820974944;

typedef long long ll;

using namespace std;

void solve() {
    int N;
    cin >> N;
    vector<int> a(N);
    REP(i, N) cin >> a[i];
  
    int M;
    if (N % 2 == 0) {
        M = N; 
    } else {
        M = N-1;
    }
    vector<int> b;
    REP(i, M/2) {
        b.push_back(a[M-1-i*2]);
    }
    REP(i, M/2) {
        b.push_back(a[i*2]);
    }
    if (N % 2 != 0) {
        b.push_back(a[N-1]);
        reverse(b.begin(), b.end());
    }
    REP(i, b.size()) {
        cout << b[i];
        if (i == b.size()-1) {
            cout << endl;
        } else {
            cout << " ";
        }
    }
}

signed main() {
    solve();
}


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

int main(){
	cin.tie(0);
   	ios::sync_with_stdio(false);
	
	ll N,K,S;
	cin>>N>>K>>S;
    vector<ll> A(N);
    rep(i,K){
        A[i]= S;
    }
    for(int i=0;i<N-K;i++){
        if(S!=1){
            A[N-i-1] = S-1;
        }else{
            A[N-i-1] = 2;
        }
    }
    rep(i,N-1){
        cout<<A[i]<<" ";
    }
    cout<<A[N-1]<<"\n";

	return 0;
}

Measured memory_bytes: 2176
def main():
  n = int(input())
  a = list(input_list())
  sa = sum(a)
  ans = 10**10
  r = 0
  for v in list(a)[:-1]:
    r += v
    ans = min(ans, abs(sa - (2*r)))
  print(ans)

def input_list():
  return map(int, input().split())

def input_list_str():
  return map(str, input().split())

def lcm_base(x, y):
    return (x * y) // fractions.gcd(x, y)

def lcm_list(numbers):
    return reduce(lcm_base, numbers, 1)

def gcd(*numbers):
    return reduce(fractions.gcd, numbers)

def gcd_list(numbers):
    return reduce(fractions.gcd, numbers)

import math
import fractions
from functools import reduce
main()

Measured memory_bytes: 103756
#include <bits/stdc++.h>
#define ll long long

using namespace std;

const int N = 123456;

ll a[N];
ll dp[N];
ll h[N];

int main() {
  int n;
  scanf("%d", &n);
  for (int i = 0; i < n; i++) {
    cin >> a[i];
  }
  sort(a, a + n);
  for (int i = 1; i <= n; i++) {
    dp[i] = dp[i - 1] + a[i - 1];
    if (2 * dp[i] >= a[i]) {
      h[i] = 1;
    }
  }
  int i = n;
  ll cnt = 0;
  while (h[i]) {
    cnt++;
    i--;
  }
  cout << cnt << endl;
  return 0;
}



Measured memory_bytes: 2560
#include <iostream>
#include <string>
#include <cmath>
#include <algorithm>

using namespace std;

int main()
{
	long long N;
	long long ans = 1;
	
	cin >> N;

	for (int i = 1;i <= sqrt(N);i++)
	{
		if (N % i == 0)
		{
			long long A = i;
			long long B = N / i;

			ans = to_string(max(A, B)).size();
		}
	}

	cout << ans << endl;

	return 0;
}


Measured memory_bytes: 256