akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> pll;
typedef vector<ld> vd;
typedef vector<ll> vll;
typedef vector<string> vstr;
typedef vector<vll> vvll;
typedef vector<vvll> vvvll;
typedef vector<pair<ll, ll>> vpll;
typedef priority_queue<ll, vector<ll>, greater<ll>> spqll;  // 小さい順に取り出し
typedef priority_queue<ll, vector<ll>, less<ll>> bpqll;     // 大きい順に取り出し

#define REP(i, n) for (ll i = 0; i < (ll)(n); i++)
#define FOR(i, a, b) for (ll i = (ll)a; i < (ll)b; i++)
#define IREP(i, v) for (auto i = (v).begin(); i != (v).end(); ++i)
#define FI first
#define SE second
#define MP make_pair
#define MT make_tuple
#define PB push_back
#define TS to_string
#define NP next_permutation
#define ALL(v) (v).begin(), (v).end()
#define SZ(x) (ll) x.size()
#define endl "\n"


ll INF = 1e9;
ll MOD = 1000000007;
ll LINF = 1e18;
ld EPS = 1e-9;
ld PI = M_PI;
vll dx = {1, 0, -1, 0, 1, -1, -1, 1};
vll dy = {0, 1, 0, -1, 1, 1, -1, -1};
ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a;} //最大公約数
ll lcm(ll a, ll b) { return a / gcd(a, b) * b;}     //最小公倍数

void yes(){ cout << "Yes" << endl;}
void no(){ cout << "No" << endl;}

//-----------------------------------------
ll timer;
vll pre, par, low, seen;
vvll graph;

void init(ll N){
  pre.resize(N); par.resize(N);
  low.resize(N); seen.resize(N,0);
  graph.resize(N,vll());
  timer = 1;
}
void dfs(ll cur, ll pas){

  pre[cur] = low[cur] = timer;
  timer++;

  seen[cur] = 1;

  for(ll i=0;i<graph[cur].size();i++){
    ll next = graph[cur][i];
    if(!seen[next]){
      par[next] =  cur;

      dfs(next, cur);
      low[cur] = min(low[cur], low[next]);
    }
    else if(next != pas){
      low[cur] = min(low[cur], pre[next]);
    }
  }
}

void art_point(ll N, set<ll> &arp){
  seen.resize(N,0);
  timer = 1;
  dfs(0,-1);

  ll np = 0;
  for(ll i=1;i<N;i++){
    ll p = par[i];
    if(p == 0) np++;
    else if(pre[p] <= low[i]) arp.insert(p);
  }
  if(np > 1) arp.insert(0);

}
//-----------------------------------------

int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << fixed << setprecision(10);

  ll v, e;
  cin >> v >> e;
  init(v);
  REP(i,e){
    ll a, b;
    cin >> a >> b;
    graph[a].push_back(b);
    graph[b].push_back(a);
  }
  set<ll> st;
  art_point(v,st);
  IREP(i,st) cout << (*i) <<endl;

  return 0;
}




Measured memory_bytes: 5348
using System;
using System.Collections.Generic;
using System.Linq;

namespace abc150_b
{
    class Program
    {
        static void Main(string[] args)
        {
            int N = int.Parse(Console.ReadLine());
            string S = Console.ReadLine();
            int count = 0;
            for (int i  = 0; i < N - 2; i++)
            {
                if (S.Substring(i, 3) == "ABC")
                {
                    count++;
                }
            }
            Console.WriteLine(count);
        }
    }
}


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

int main () {
	
	int n=0, k=0, aux=0;

	scanf("%d %d", &n, &k);

	if (n%2 == 1) aux=1;
	aux += n/2;

	//printf(" %d %d %d\n", n, k, aux);

	if (aux >= k) printf("YES\n");
	else printf("NO\n");

	return 0;
}

Measured memory_bytes: 256
package main

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

var sc = bufio.NewScanner(os.Stdin)
var out = bufio.NewWriter(os.Stdout)

func main() {
	buf := make([]byte, 1024*1024)
	sc.Buffer(buf, bufio.MaxScanTokenSize)
	sc.Split(bufio.ScanWords)
	defer out.Flush() // !!!!caution!!!! you must use Fprint(out, ) not Print()
	/* --- code --- */
	a, b := nextInt(), nextInt()
	if a%2 == 0 || b%2 == 0 {
		fmt.Fprintln(out, "Even")
	} else {
		fmt.Fprintln(out, "Odd")
	}
}

// -*-*-*-*-*-*-*-*-
// * I/O utilities *
// -*-*-*-*-*-*-*-*-

func next() string {
	sc.Scan()
	return sc.Text()
}

func nextInt() int {
	a, _ := strconv.Atoi(next())
	return a
}

func nextFloat64() float64 {
	a, _ := strconv.ParseFloat(next(), 64)
	return a
}

func nextInts(n int) []int {
	ret := make([]int, n)
	for i := 0; i < n; i++ {
		ret[i] = nextInt()
	}
	return ret
}
func nextFloats(n int) []float64 {
	ret := make([]float64, n)
	for i := 0; i < n; i++ {
		ret[i] = nextFloat64()
	}
	return ret
}
func nextStrings(n int) []string {
	ret := make([]string, n)
	for i := 0; i < n; i++ {
		ret[i] = next()
	}
	return ret
}

func chars(s string) []string {
	ret := make([]string, len([]rune(s)))
	for i, v := range []rune(s) {
		ret[i] = string(v)
	}
	return ret
}

// PrintOut with util device
func PrintOut(src interface{}, joinner string) {
	switch reflect.TypeOf(src).Kind() {
	case reflect.Slice:
		s := reflect.ValueOf(src)
		for idx := 0; idx < s.Len(); idx++ {
			fmt.Fprintf(out, "%v", s.Index(idx))
			if idx < s.Len()-1 {
				fmt.Fprintf(out, "%s", joinner)
			} else {
				fmt.Fprintln(out)
			}
		}
	default:
		fmt.Fprintln(out, "fuck")
	}
}


Measured memory_bytes: 640
#include <stdio.h>
int main (void)
{
	int S,h,m,s,a,b,c,d;
	
	scanf("%d\n",&S);
	
	a=S/3600;
	b=S%3600;
	c=b/60;
	d=b%60;
	
	printf("%d:%d:%d\n",a,c,d);
	
	return 0;
}

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

int main() {
  int n;

  while (cin >> n, n) {
    vector<vector<int>> v(n);
    for (int i = 0; i < n; ++i) {
      for (int j = 0; j < n; ++j) {
        char c;
        cin >> c;
        v[i].push_back(c == '.');
      }
    }

    int ans = 0;
    for (int i = 1; i < n; ++i) {
      for (int j = 1; j < n; ++j) {
        if (v[i][j]) v[i][j] = min({v[i - 1][j - 1], v[i - 1][j], v[i][j - 1]}) + 1;
        ans = max(ans, v[i][j]);
      }
    }

    cout << ans << endl;
  }
}

Measured memory_bytes: 6740
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int s[]={0,111,222,333,444,555,666,777,888,999};
int main()
{
    int n;
    cin>>n;
    for(int i=1;i<=9;i++){
        if(s[i]>n){
            cout<<s[i]<<endl;
            break;
        }
        if(s[i]==n){
            cout<<s[i]<<endl;
            break;
        }
    }
    //if(n==999)cout<<999<<endl;
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define bug cout<<"AIkahne aise"<<endl
ll A[5000001];
vector<ll>v;
vector<pair<ll,ll> >v2;
/*void sieve()
{
    for(ll i=3; i<=2000; i+=2)
    {
        for(ll j=i*i; j<=4000000; j+=i)
            A[j]=1;
    }
    v.push_back(2);
    for(ll i=3; i<=4000000; i+=2)
        if(A[i]==0)
            v.push_back(i);
}*/
int main()
{
ll a,b,c;
cin>>a>>b>>c;
if(c>=min(a,b)&&c<=max(a,b))
{
    cout<<"Yes"<<endl;
}
else
    cout<<"No"<<endl;
return 0;
}


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

#define rep(i,n) for(int i = 0; i < (n); i++)
#define rrep(i,n) for(int i = (n)-1; i >= 0; i--)
#define rep1(i,n) for(int i = 1; i <= (n); i++)
#define rrep1(i,n) for(int i = (n); i > 0; i--)

#define ll long long
#define pi pair<int, int>
#define pll pair<ll, ll>

#define MOD 1000000007
#define INF 1000000000000000LL

using namespace std;

int main(){
  ll x,y,a,b,c;cin>>x>>y>>a>>b>>c;
  vector<ll>p(a), q(b), r(c);
  rep(i, a)cin>>p[i];
  rep(i, b)cin>>q[i];
  rep(i, c)cin>>r[i];

  sort(p.rbegin(), p.rend());
  sort(q.rbegin(), q.rend());
  sort(r.begin(), r.end());

  priority_queue<ll, vector<ll>, greater<ll>>pq;

  rep(i, x)pq.push(p[i]);
  rep(i, y)pq.push(q[i]);

  rep(i, c){
    pq.push(r[i]);
    pq.pop();
  }

  ll result=0;
  while(pq.size()){
    result+=pq.top();
    pq.pop();
  }

  cout<<result<<endl;

  return 0;
}

Measured memory_bytes: 4724
def main():
    n = int(input())
    s = input()

    cnt = 0
    for i in range(10):
        for j in range(10):
            for k in range(10):
                ii = s.find(str(i))
                if ii == -1:
                    continue
                jj = s[ii+1:].find(str(j))
                if jj == -1:
                    continue
                jj += ii+1
                kk = s[jj+1:].find(str(k))
                if kk == -1:
                    continue
                cnt += 1


    print(cnt)


main()

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

#define l long
#define ll long long
#define pb push_back
#define vb vector<bool>
#define vi vector<int>
#define vll vector<ll>
#define MOD 998244353
#define nl "\n"
#define sp " "
#define gcd __gcd
#define pf printf
#define sf scanf

int main()
{
    int n,k,temp,a;
    cin>>n>>k;
    set<int> d;
    for(int i = 0; i < k; i++){
        cin>>temp;
        while(temp--){
            cin>>a;
            d.insert(a);
        }
    }
    cout<<n-d.size()<<nl;
}

Measured memory_bytes: 3636
x,k,d = map(int, input().split())
x = abs(x)
a= x//d
b = x%d
if a>=k:
  print(x-k*d)
  exit(0)
c = abs(b-d)
if (k-a)%2==0:
  print(b)
else:
  print(c)

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

#define sc(x) scanf("%lld",&x)
#define pf(x,y) printf("%lld %lld", x,y)
#define pfn printf("\n")
#define fr(i,a,n) for(i = a ; i < n ; i++)



int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	li d,t,s;
	cin >> d >> t >> s;
	if(d<=s*t){
		cout << "Yes"<<endl;
	}
	else{
		cout << "No" << endl;
	}
	



	return 0;
}


Measured memory_bytes: 3552
N = int(input())
A = [int(input()) for _ in range(N)]
ans = 0
if A[0] != 0:
    print(-1)
    exit()

for i in range(1, N):
    if A[i] - A[i-1] > 1:  # 前の数に+1することでしか数を生成することができないため、2以上離れている場合は無理
        print(-1)
        exit()

now = A[0]
for i in range(1, N):
    if A[i] == now+1:
        ans += 1
        now = A[i]
    else:
        ans += A[i]
        now = A[i]
print(ans)


Measured memory_bytes: 11052
#include <bits/stdc++.h>
using namespace std;
#define e1 first
#define e2 second
#define pb push_back
#define mp make_pair
#define boost ios_base::sync_with_stdio(false)
#define eb emplace_back
#define OUT(x) {cout << x; exit(0); }
#define FOR(i,a,b) for(int i=(a);i<=(b);++i)
#define scanf(...) scanf(__VA_ARGS__)?:0
typedef long long int ll;
typedef unsigned long long ull;
typedef pair <int, int> PII;
typedef pair <ll, ll> PLL;
typedef pair <PLL, int> PLLI;
typedef pair <PLL, PLL> PP;
typedef pair <PII, int> PPI;
typedef pair <ll, int> PLI;
typedef unsigned int ui;
const int inf = 1e9+9;
const ll MOD = 1e9+696969;
const long long INF = 1e18+3;
#define maxn 2010
vector <int> v[maxn];
int odl[maxn][maxn], n, k;
bitset <maxn> tab[maxn];

void dfs(int x, int par, int st)
{
	for (auto u : v[x])
		if (u != par) 
		{
			odl[st][u] = odl[st][x] + 1;
			dfs(u, x, st);
		}
}

int res;

void check(int x)
{
	int ret = 0;
	FOR(i, 1, n)
		if (odl[x][i] > k / 2) ++ret;
	res = min(res, ret);
}

void check(int x, int y)
{
	int ret = 0;
	FOR(i, 1, n)
	{
		int mn = min(odl[x][i], odl[y][i]);
		if (mn > k / 2) ++ret;
	}
	res = min(res, ret);
}

int main()
{
	boost;
	cin >> n >> k;
	FOR(i, 2, n)
	{
		int a, b;
		cin >> a >> b;
		v[a].pb(b);
		v[b].pb(a);
	}
	FOR(i, 1, n)
		dfs(i, i, i);
	res = n + 1;
	if (k % 2 == 0)
	{
		FOR(i, 1, n) check(i);
	}
	else
	{
		FOR(i, 1, n)
			for (auto u : v[i]) check(i, u);
	}
	
	cout << res;
}


Measured memory_bytes: 16256
#include <cstdio>
#include <iostream>
#include <vector>
#include <queue>
#include <string>
#include <utility>
#include <map>
#include <set>
#include <algorithm>
#include<cmath>

#define rep(i, a, b) for (int i=a; i <b; i++)
#define F first
#define S second

using namespace std;

typedef long long ll;
typedef vector< int > vi;


int main() {
    int n, k;
    scanf("%d %d", &n, &k);
    vector< int > a(n);
    rep(i, 0, n) {
        scanf("%d", &a[i]);
    }
    int dist = 0;
    int dist1, dist2;
    
    int mindist = 10000000000;
    for (int i=0; i<n -k+1; i++) {
            dist1 = abs(a[i]) + abs( a[i] - a[i+k-1] );
            dist2 = abs(a[i+k-1]) + abs( a[i] - a[i+k-1] );

            if (dist1 < dist2) {
                dist = dist1;
            } else {
                dist = dist2;
            }
            
            if (mindist > dist) {
                mindist = dist;
            }
    }

    printf("%d\n", mindist);
    return 0;
}

Measured memory_bytes: 640
#pragma GCC optimize ("Ofast")
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
#define FOR(i, a, b) for (int i=(a); i<(b); i++)
#define FORD(i, a, b) for (int i=(a); i>(b); i--)
#define PPC(x) __builtin_popcount(x)
#define MSB(x) (31 - __builtin_clz(x))
#define SZ(x) ((int)(x).size())
#define BACK(x) prev((x).end())
#define HASK(x, y) ((x).find(y) != (x).end())
#define pb push_back
#define ALL(x) (x).begin(), (x).end()
#define ithBit(m, i) ((m) >> (i) & 1)
#define ft first
#define sd second
#define kw(a) ((a) * (a))
#ifdef DEBUG
#include "debug.h"
#else
#define dbg(...) 0
#endif
using namespace std;
 
const int maxN = 1 << 19, mod = 1000000007;

int T[maxN], n;
long long pref[maxN];

pair <long long, long long> getSum(int x)
{
	long long ret = 0, num = 0;
	FOR(i, 1, n+1)
	{
		int j = lower_bound(T+1, T+n+1, x-T[i]) - T;
		if (j == n+1)
			continue;
		j--;
		ret += pref[n] - pref[j];
		ret += 1ll * T[i] * (n-j);
		num += n-j;
	}
	return {ret, num};
}

void solve()
{
	long long m;
	scanf ("%d%lld", &n, &m);
	
	FOR(i, 1, n+1)
		scanf ("%d", T+i);
	sort(T, T+n+1);
	FOR(i, 1, n+1)
		pref[i] = pref[i-1] + T[i];
	
	int a = 1, b = maxN;
	while (b - a > 1)
	{
		int c = (a + b) / 2;
		getSum(c).sd >= m ? a = c : b = c;
	}
	
	auto res = getSum(b);
	dbg(res); dbg(b);
	m -= res.second;
	res.ft += m * a;
	printf("%lld\n", res.ft);
}
 
int main()
{
	int t = 1;
	//scanf ("%d", &t);
	FOR(tid, 1, t+1)
	{
		//printf("Case #%d: ", tid);
		solve();
	}
	return 0;
}
 





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

int main(){
  int n;
  cin>>n;
  vector<int>b(n-1);
  vector<int>a(n);
  for(int i=0;i<n-1;i++){
    cin>>b[i];
  }
  a[0]=b[0];
  for(int i=1;i<=n-2;i++){
    a[i]=min(b[i],b[i-1]);
  }
  a[n-1]=b[n-2];
  int num=0;
  for(int i=0;i<n;i++){
    num+=a[i];
  }
  cout<<num<<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(){
    int n,x,y;
    cin >> n >> x >> y;
    vector <int> ans(n);
    queue <int> q;
    int qq,k;

    vector <int> ans2(n+2,-1),ans3(n+2,-1);
    ans3[0]=0;
    ans3[n+1]=0;
    rep(i,n){
        q.push(i+1);
        ans2=ans3;
        ans2[i+1]=0;
        while(q.size()!=0){
           qq=q.front();
           q.pop();
           k=ans2[qq];
           if(ans2[qq-1]==-1){
               ans2[qq-1]=k+1;
               q.push(qq-1);
           }
           if(ans2[qq+1]==-1){
               ans2[qq+1]=k+1;
               q.push(qq+1);
           }
           if(qq==x and ans2[y]==-1){
               ans2[y]=k+1;
               q.push(y);
           }
           if(qq==y and ans2[x]==-1){
               ans2[x]=k+1;
               q.push(x);
           }
        }
        rep(j,n){
            ++ans[ans2[j+1]];
        }

    }
    
    rep(i,n-1){
        cout << ans[i+1]/2 << endl;
    }

    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define _overload3(_1,_2,_3,name,...) name
#define _rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(int i=int(a);i<int(b);++i)
#define REP(...) _overload3(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)

#define ALL(x) (x).begin(),(x).end()
typedef long long ll;

#define y0 y3487465
#define y1 y8687969
#define j0 j1347829
#define j1 j234892
#define next asdnext
#define prev asdprev

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

  cout << (N[0] == '7' || N[1] == '7' || N[2] == '7' ? "Yes" : "No") << endl;

  return 0;
}

Measured memory_bytes: 3628
n = int(input())
a = list(map(int, input().split()))
ans = 0
s = sum(a)
al = []

sum1 = 0

for i in range(0,n):
        # if i == 1:
        #         sum1 = sum(a[0:i])
        # else:
        #         sum1 += a[i]
        sum1 += a[i]
        sum2 = s - sum1
        # print("sum1:"+str(sum1))
        # print("sum2:"+str(sum2))
        al.append(abs(sum1 - sum2))
        if sum1 == sum2:
                print(0)
                exit()

minDiffIdx = al.index(min(al))

# print("---")
# print(minDiffIdx)
# print("---")

tmp1 = sum(a[0:minDiffIdx])
tmp2 = sum(a[minDiffIdx:])
# print(tmp1)
# print(tmp2)
diff1 = abs(tmp1 - tmp2)

tmp3 = sum(a[0:minDiffIdx + 1])
tmp4 = sum(a[minDiffIdx + 1:])
# print(tmp3)
# print(tmp4)
diff2 = abs(tmp3 - tmp4)
print(min(diff1, diff2))

# d1 = diff1
# d2 = diff2

# if d1 < d2:
#         for i in range(n//2):
#                 if a[i] > 1:
#                         d1 -= a[i]
#                 if d1 < 0:
#                         ans += diff1 + d1
#                         break
#                 elif d1 == 0:
#                         ans += diff1
#                         break
#         if 
# else:


Measured memory_bytes: 26060
#include <iostream>
#include <bits/stdc++.h>
#include <vector>
#include <algorithm>
typedef long long int ll;
using namespace std;
#define P 1000000007
#define rep(i,n) for(i=0;i<n;++i)
#define repp(i,a,n) for(i=a;i<n;++i)
#define repr(i,a,n) for(i=a;i>=n;--i)
#define pb push_back
#define mp make_pair
#define fi first
#define se second



int main() 
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    ll m,n,i,f=0,j,ans=0,k,x,r,l,t;
    long double a,b;
    cin >> a >> b ;
    long double res=a*b;
    ans=(ll)res;
    cout << ans ;
    return 0;
}

Measured memory_bytes: 3748
#include<set>
#include<map>
#include<stack>
#include<queue>
#include<deque>
#include<cmath>
#include<cstdio>
#include<cctype>
#include<string>
#include<vector>
#include<cstdlib>
#include<cstring>
#include<sstream>
#include<iostream>
#include<algorithm>
#define MAXN 100000
#define hlq 1000000007
#define pii pair<int,int>

using namespace std;
int d[MAXN+80];
long long ans,a,b;
int main()
{
	int n,i;
	scanf("%d",&n);
	cin>>a>>b;
	for(i=1;i<=n;i++)
		scanf("%d",d+i);
	for(i=1;i<n;i++)
		ans+=min(a*(d[i+1]-d[i]),b);
	cout<<ans;
	return 0;
}

Measured memory_bytes: 640
#include <iostream>

using namespace std;

main(){
  double in;
  long long min=999999999;
  long long max=-999999999;
  while(cin >> in){
    long long tmp=(long long)(in*100.0);
    if(min>tmp) min=tmp;
    if(max<tmp) max=tmp;
  }

  double ans=(double)(max-min)/100.0;
  printf("%.1f\n", ans);
  return 0;
}

Measured memory_bytes: 0
/**

    WARNING
          This Code Sucks
                        Just Like My Life :(

**/
#pragma GCC optimize ("O3")
#pragma GCC optimize ("unroll-loops")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
//#pragma comment(linker, "/STACK:1024000000,1024000000")
#include <bits/stdc++.h>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/rope>

using namespace std;
using namespace __gnu_pbds;
using namespace __gnu_cxx;
template<class T> using orderd_set = tree<T, null_type, less<T>, rb_tree_tag,tree_order_statistics_node_update>;
const int N = 1e5 + 5;
const int mod = 1e9 + 7;

int n, cost[N], dp[N];
int main(){
    scanf("%d",&n);
    for(int i = 1 ; i <= n ; i++)
        scanf("%d",&cost[i]);
    dp[1] = 0;
    dp[2] = abs(cost[1]-cost[2]);
    for(int i = 3; i <= n ; i++)
        dp[i] = min(dp[i-1] + abs(cost[i] - cost[i-1]), dp[i-2] + abs(cost[i] - cost[i - 2]));
    printf("%d",dp[n]);
    return 0;
}


Measured memory_bytes: 1024
n = input()    
m = n.split()
p = [int(i) for i in m]
n = input()    
m = n.split()
P = [int(i) for i in m]
n = input()
list = [""]*p[1]
for i, value in enumerate(n):
    list[i%p[1]] =list[i%p[1]] + value
A = 0
for i in list:
    able = [True,True,True]
    for j in i:
        if j == "r":
            if able[2]:
                A = A + P[2]
                able = [True,True,False]
            else:
                able = [True,True,True]
        if j == "s":
            if able[0]:
                A = A + P[0]
                able = [False,True,True]
            else:
                able = [True,True,True]
        if j == "p":
            if able[1]:
                A = A + P[1]
                able = [True,False,True]
            else:
                able = [True,True,True]

print(A)

Measured memory_bytes: 6132
#include<stdio.h>
int main(){
    int N, M,i,j;
    int h[1500][1500] = { 0 }, l[1500] = { 0 }, t[1500] = { 0 };
    scanf("%d%d",&N,&M);
    for (i = 0; i < N; i++){
        scanf("%d",&l[i]);
    }
    for (j = 0; j < M; j++){
        scanf("%d",&t[j]);
    }
    for (j = 0; j < N; j++){
        for (i = j; i < j + M-N+1; i++){
            if (j == 0){
                h[j][i] = l[j] * t[i];
                if (h[j][i] >= h[j][i - 1] && i != 0){
                    h[j][i] = h[j][i - 1];
                }
            }
            else{
                h[j][i] = h[j - 1][i - 1] + l[j] * t[i];
                if (h[j][i] >= h[j][i - 1] && i != j){
                    h[j][i] = h[j][i - 1];
                }
            }
        }
    }
    printf("%d\n",h[N - 1][M - 1]);
    return 0;
}

Measured memory_bytes: 11544
import java.util.Scanner;

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

		try (Scanner sc = new Scanner(System.in)) {
			while (sc.hasNextBigDecimal()) {

				double v = sc.nextDouble();
				double t = v / 9.8;
				double y = t * t * 4.9;
				double n = Math.ceil((y + 5) / 5);

				System.out.println((int) n);
			}
		}
	}
}

Measured memory_bytes: 28260
#define _DEBUG
#include "bits/stdc++.h"
#define CHOOSE(a) CHOOSE2 a
#define CHOOSE2(a0,a1,a2,a3,a4,x,...) x
#define debug_1(x1) cout<<#x1<<": "<<x1<<endl
#define debug_2(x1,x2) cout<<#x1<<": "<<x1<<", "#x2<<": "<<x2<<endl
#define debug_3(x1,x2,x3) cout<<#x1<<": "<<x1<<", "#x2<<": "<<x2<<", "#x3<<": "<<x3<<endl
#define debug_4(x1,x2,x3,x4) cout<<#x1<<": "<<x1<<", "#x2<<": "<<x2<<", "#x3<<": "<<x3<<", "#x4<<": "<<x4<<endl
#define debug_5(x1,x2,x3,x4,x5) cout<<#x1<<": "<<x1<<", "#x2<<": "<<x2<<", "#x3<<": "<<x3<<", "#x4<<": "<<x4<<", "#x5<<": "<<x5<<endl
#ifdef _DEBUG
#define debug(...) CHOOSE((__VA_ARGS__,debug_5,debug_4,debug_3,debug_2,debug_1,~))(__VA_ARGS__)
#else
#define debug(...)
#endif
#define rep(index,num) for(int index=0;index<(int)num;index++)
#define rep1(index,num) for(int index=1;index<=(int)num;index++)
#define brep(index,num) for(int index=(int)num-1;index>=0;index--)
#define brep1(index,num) for(int index=(int)num;index>0;index--)
#define scan(argument) cin>>argument
#define prin(argument) cout<<argument<<endl
#define kaigyo cout<<endl
#define eps 1e-7
#define mp(a1,a2) make_pair(a1,a2)
#define ALL(a) (a).begin(),(a).end()
#define rALL(a) (a).rbegin(),(a).rend()
typedef long long ll;
typedef long double ld;
using namespace std;
typedef pair<ll,ll> pll;
typedef pair<int,int> pint;
typedef vector<int> vint;
typedef vector<ll> vll;
typedef vector<pint> vpint;
typedef vector<pll> vpll;
ll INFl=(ll)1e+18+1;
int INF=1e+9+1;
int main(){
	string S;
	scan(S);
	if(S=="AAA"||S=="BBB") prin("No");
	else prin("Yes");
	return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
using ll=long long;
ll a,b,c,i,j,k,l,m,n,ans,tmp,hoge,fuga,piyo;
ll x[10010],y[10010];
string s,str;
int main(){
  cin>>n>>k;
  n=n%k;
  if(n>abs(n-k)){
    cout<<abs(n-k);
  }else{
    cout<<n;
  }
  return 0;
}

Measured memory_bytes: 256
short*p,v[][104];main(c,n,m,i,y){for(;m=scanf("%d %[^\n] %[^\n]",&n,v,v+1)*n;printf(m>n?"NA\n":"%d\n",m))for(i=2;i--;m=c)for(c=0,y=n;y-->1&c<m;y+=y==n|*p&2?2:*p&p[-1]&1?0:~!++c)p=y+v[c+i&1];}

Measured memory_bytes: 0
#include <bits/stdc++.h>
using namespace std;
bool good(int v){
	vector<int> k;
  while(v) k.push_back(v % 10), v /= 10;
  vector<int> nk = k;
  reverse(nk.begin(), nk.end());
  return nk == k;
}
int main(){
  int a, b; cin >> a >> b;
  int ans = 0;
  for(int i = a; i <= b; i++) ans += good(i);
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
#include <array>
#include <vector>
#include <deque>
#include <queue>
#include <set>
#include <unordered_set>
#include <map>
#include <unordered_map>
#include <string>
#include <algorithm>
#include <numeric>
#include <functional>
#include <iterator>
#include <tuple>
#include <utility>
#include <limits>
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <cstdint>
#include <cassert>

using namespace std;

#define FOR(i, start, end) for(int i = (start); i < (end); ++i)
#define REP(i, n) FOR(i, 0, n)

int T;

int N;
bool B[2][10004];

void solve()
{
    // y, x
    int dp[3][10004] = {};
    // from, to, books
    int cost[3][3][4] = {
        {{ 1, 2, 4, 4 }, { 2, 2, 3, 3 }, { 3, 3, 3, 3 }},
        {{ 2, 2, 3, 3 }, { 1, 2, 2, 3 }, { 2, 3, 2, 3 }},
        {{ 3, 3, 3, 3 }, { 2, 3, 2, 3 }, { 1, 4, 2, 4 }}
    };

    dp[0][0] = 0;
    dp[1][0] = 1;
    dp[2][0] = 2;

    FOR(i, 1, N+2) {
        int books = B[0][i-1] | (B[1][i-1] << 1);
        REP(to, 3) {
            int cands[3];
            REP(from, 3) {
                cands[from] = dp[from][i-1] + cost[from][to][books];
            }
            dp[to][i] = *min_element(begin(cands), end(cands));
        }
    }

    cout << dp[0][N+1] - 1 << "\n";
}

int main()
{
    cin >> T;

    REP(_, T) {
        cin >> N;
        memset(B, 0, sizeof(B));
        REP(y, 2) {
            REP(i, 2*N) {
                char c;
                cin >> c;
                if(c == 'Y') {
                    int x = (i+1) / 2;
                    B[y][x] = true;
                }
            }
        }

        solve();
    }

    return 0;
}

Measured memory_bytes: 3224
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
const ll INF = 1e12;
const ll MOD = 1000000000 + 7;
#define PB push_back
#define PF push_front
#define fi first
#define se second
#define pii pair<int, int>
#define pll pair<ll, ll>
#define vi vector<int>
#define vpi vector<pii>
#define vll vector<ll>
#define vpl vector<pll>
#define vvi vector<vector<int>>
#define vvl vector<vector<ll>>
#define mii map<int, int>
#define mci map<char, int>
#define MX(x) *max_element(all(x))
#define MN(x) *min_element(all(x))
#define ios ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0)
#define pr_d(x) cout << fixed << setprecision(15) << x << endl
#define ud(c, x) distance(c.begin(), upper_bound(all(c), x))
#define ld(c, x) distance(c.begin(), lower_bound(all(c), x))
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define rep2(i, a, b) for (int i = (a); i < (b); ++i)
#define rep3(i, n) for (int i = (n - 1); i >= 0; --i)
#define rep4(i, a, b) for (int i = (a); i > (b); --i)
#define pb push_back
#define out(x) cout << x << "\n"
bool odd(int i) { return i % 2; }

#define all(v) v.begin(), v.end()
#define size(x) int(x.size())

int gcd(int a, int b) { return __gcd(a, b); }
int lcm(int a, int b) { return a * (b / gcd(a, b)); }
void Yes_No(bool f) {
  if (f)
    printf("Yes\n");
  else
    printf("No\n");
}
void YES_NO(bool f) {
  if (f)
    printf("YES\n");
  else
    printf("NO\n");
}

template <typename T>
void deb1(T x) {
  cout << "debug: " << x << "\n";
}

template <typename T>
bool chmax(T& a, const T& b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}
template <typename T>
bool chmin(T& a, const T& b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}
//-------------------ここから回答する-----------------------

void solve(void) {
  ll x, k, d;
  cin >> x >> k >> d;
  x = abs(x);

  ll cta = x / d;
  ll dist = x - cta * d;
  if (cta > k)
    out(x - d * k);
  else if ((k - cta) % 2 == 0)
    out(dist);
  else
    out(abs(dist - d));
}

int main(void) { solve(); }

Measured memory_bytes: 3612
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 scanner = new Scanner(System.in);
		int N = scanner.nextInt();
		int L = scanner.nextInt();
		String target = "";
		List<String> stringList = new ArrayList<>();
		for (int i = 0; i <= N; i++) {
			String inputStr = scanner.nextLine();
			stringList.add(inputStr);
		}
		Collections.sort(stringList);
		for (int i = 0; i <= N; i++) {
			target += stringList.get(i);
		}
		System.out.println(target);
	}
}



Measured memory_bytes: 25044
S = input()

l,r = 0, len(S)-1
cnt = 0

while l<r:
  if S[l] == S[r]:
    l, r = l+1, r-1
  elif S[l] == 'x':
    l += 1
    cnt += 1
  elif S[r] == 'x':
    r -= 1
    cnt += 1
  else:
    print(-1)
    exit(0)
    
print(cnt)

Measured memory_bytes: 3316
import java.io.PrintWriter

fun next() = readLine()!!
fun nextInt() = next().toInt()
fun nextLong() = next().toLong()
fun nextDouble() = next().toDouble()
fun nextList() = next().split(" ")
fun nextIntList() = nextList().map(String::toInt)
fun nextLongList() = nextList().map(String::toLong)
fun nextDoubleList() = nextList().map(String::toDouble)

val pw = PrintWriter(System.out)
fun print(s: Any = "") = pw.print(s)
fun println(s: Any = "") = pw.println(s)

fun main(args: Array<String>) {
    main()
    pw.flush()
}

fun main() {
    val (N, K) = nextIntList()
    val X = nextLongList().sorted()
    var ans = Long.MAX_VALUE
    var l = 0
    while (l + K - 1 < N) {
        val xl = X[l]
        val xr = X[l + K - 1]
        val d = if (xl * xr >= 0) {
            Math.max(Math.abs(xl), Math.abs(xr))
        } else {
            xr - xl + Math.min(xl * (-1), xr)
        }
        ans = ans.coerceAtMost(d)
        l++
    }
    println(ans)
}

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

using namespace std;

int main(){
    int n;
    cin >> n;
    vector<string> s(n);
    rep(i,n) cin >> s[i];
    sort(s.begin(),s.end());
    int max = 0;
    int now = 1;
    s.push_back("");
    
    // check max
    for(int i=1; i<s.size(); i++){
        if(s[i-1]==s[i]){
            now++;
        }else{
            if(now > max) max = now;
            now = 1;
        }
    }
    
    // listing
    now = 1;
    vector<string> elected;
    for(int i=1; i<s.size(); i++){
        if(s[i-1]==s[i]){
            now++;
        }else{
            if(now == max) elected.push_back(s[i-1]);
            now = 1;
        }
    }
    
    rep(i,elected.size()) cout << elected[i] << endl;
    
    return 0;
}

Measured memory_bytes: 18916
s = input()
ls = set()
ans = 1
ls.add(s[0])
check = True
string = ""
for i in range(1,len(s)):
    if check:
        string += s[i]
    if not string in ls:
        ls = {}
        ls[string] = False
        ans += 1
        string = ""
print(ans)

Measured memory_bytes: 42332
f=lambda:[*map(int,input().split())]
n,h=f()
A,B=[],[]
for _ in range(n):
  a,b=f()
  A+=[a]
  B+=[b]
m=max(A)
B.sort()
c=0
while h>0 and B and B[-1]>m:
  h-=B.pop()
  c+=1
print(c--h//m*(h>0))

Measured memory_bytes: 17020
#include<iostream>
#include<string>
#include<cstdio>
#include<queue>
using namespace std;
typedef pair<int, int> P;

string str;

int main()
{
  int a,b,c,d;
  int i,j;
  int s[10][10]={};
  int h,w;
  int x;//??£?¶???????????????°
  int cnt;
  int k;

  while(1){

    cin>>str;
    if(str[0]=='#')break;
    cin>>a>>b>>c>>d;
    h=0;
    i=0;
    j=0;
    cnt=0;
    k=0;
    w=0;

    while(i<str.size()){

      if(str[i]>='1' && str[i]<='9'){
	x=str[i]-'0';
	for(;x>0;x--){
	  s[k][cnt]=0;
	  cnt++;
	}
      }else if(str[i]=='b'){
	s[k][cnt]=1;
	cnt++;
      }else if(str[i]=='/'){
	if(k==0)
	  w=cnt;
	cnt=0;
	k++;
	h++;
      }
	i++;

    }//endwhile

    s[a-1][b-1]=0;
    s[c-1][d-1]=1;

    for(i=0;i<h+1;i++){
      x=0;
      for(j=0;j<w;j++){
	if(s[i][j]){//???????????????b?????°???
	  if(x){
	    cout<<x;
	    x=0;
	  }
	  cout<<'b';
	
	}else
	  x++;
	
      }//endforj
      if(x)
	cout<<x;
      if(i<h)
	cout<<'/';
    }//endfori
    cout<<endl;

  }//endwhile1


}

Measured memory_bytes: 3140
#include <cstdio>

int main(){
	while(1){
		int h, w;
		scanf(" %d %d", &h, &w);
		if(h==0 && w==0) break;
		
		for(int i=0; i<h; ++i){
			for(int j=0; j<w; ++j){
				if( (i+j)%2==0 ) printf("#");
				else printf(".");
			}
			printf("\n");
		}
		printf("\n");

	}
	return 0;
}



Measured memory_bytes: 2600
#include <iostream>
#include <deque>

int dist[100001];

int main() {
	int k;
	std::cin >> k;

	std::deque<int> que;
	que.push_back(1);
	dist[1] = 1;

	while (!que.empty()) {
		int v = que.back();
		que.pop_back();

		if (v == 0) {
			std::cout << dist[0] << std::endl;
			return 0;
		}

		const int a = (v * 10) % k, b = (v + 1) % k;
		if (dist[a] == 0 || dist[a] > dist[v]) {
			dist[a] = dist[v];
			que.push_back(a);
		}
		if (dist[b] == 0 || dist[b] > dist[v]) {
			dist[b] = dist[v] + 1;
			que.push_front(b);
		}
	}
}

Measured memory_bytes: 896
s = list(input())
n = len(s)

for i in range(2**(n-1)):
    ans = int(s[0])
    formura = s[0]
    for j in range(1,n):
        if (i >> j-1) & 1 == 1:
            ans += int(s[j])
            formura += "+" + s[j]
        else:
            ans -= int(s[j])
            formura += "-" + s[j]
    if ans == 7:
        print(formura + "=7")
        break

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

using namespace std;
#define FOR(i, a, b) for (int i = (a); i < (b); i++) 
#define REP(i, n) for (int i = 0; i < (n); i++)

int main(int argc, char const *argv[])
{
    int R; cin >> R;
    if (R < 1200) cout << "ABC\n";
    else if (R < 2800) cout << "ARC\n";
    else cout << "AGC\n";
    return 0;
}


Measured memory_bytes: 256
#define _USE_MATH_DEFINES
#define _CRT_SECURE_NO_WARNINGS

#include <iostream>
#include <string>
#include <sstream>
#include <iomanip>
#include <cmath>
#include <cstring>
#include <cstdlib>
#include <algorithm>
#include <stack>
#include <queue>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <bitset>
#include <utility>
#include <numeric>

using namespace std;

using ll = long long;
using ull = unsigned long long;

const ll inf = (ll)1e9;
const ll mod = (ll)1e9 + 7;

int main()
{
	ll n, x;
	cin >> n >> x;

	vector<ll> a(n);
	for (ll i = 0; i < n; i++)
	{
		cin >> a.at(i);
	}

	ull sum = 0;

	for (ll i = 0; i < n; i++)
	{
		if (i > 0)
		{
			if (a.at(i) + a.at(i - 1) > x)
			{
				ll d = a.at(i) + a.at(i - 1);
				sum += d - x;
				a.at(i) = x - a.at(i - 1);
			}
		}
		else
		{
			if (a.at(0) > x)
			{
				sum += a.at(0) - x;
				a.at(0) = x;
			}
		}
	}

	cout << sum << endl;
}

Measured memory_bytes: 1024
#pragma GCC optimize("O3")
#include <bits/stdc++.h>
#define ll long long
#define rep(i,n) for(ll i=0;i<(n);i++)
#define pll pair<ll,ll>
#define pq priority_queue
#define pb push_back
#define eb emplace_back
#define fi first
#define se second
#define ios ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0);
#define lb(c,x) distance(c.begin(),lower_bound(all(c),x))
#define ub(c,x) distance(c.begin(),upper_bound(all(c),x))

using namespace std;

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 ll INF=1e15;

int main(){
    ll a,b,c;
    cin >> a >> b >> c;
    ll k;
    cin >> k;
    rep(i,k){
        if(b<=a){
            b*=2;
            continue;
        }
        if(c<=b){
            c*=2;
            continue;
        }
    }
    if(a<b && b<c) cout << "Yes" << endl;
    else cout << "No" << endl;
    return 0;
}

Measured memory_bytes: 3620
#include<bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
#define int long long
using namespace __gnu_pbds;
using namespace std;
template <typename T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

string a[25];
int n,m;
int bfs(pair<int,int>p1,pair<int,int>p2)
{
   queue<pair<int,int> >qq;
   qq.push(p1);
   int mm[25][25]={};
   int dis[25][25]={};
   mm[p1.first][p1.second]=1;
   while(!qq.empty())
   {
      pair<int,int>pp=qq.front();
      qq.pop();
      if(pp.first>1)
      {
         if(a[pp.first-1][pp.second]=='.' && mm[pp.first-1][pp.second]==0)
         {
            dis[pp.first-1][pp.second]=dis[pp.first][pp.second]+1;
            qq.push({pp.first-1,pp.second});
            mm[pp.first-1][pp.second]=1;
         }
      }
      if(pp.first<n)
      {
         if(a[pp.first+1][pp.second]=='.'&& mm[pp.first+1][pp.second]==0)
         {
            dis[pp.first+1][pp.second]=dis[pp.first][pp.second]+1;
            qq.push({pp.first+1,pp.second});
            mm[pp.first+1][pp.second]=1;
         }
      }
      if(pp.second>1)
      {
         if(a[pp.first][pp.second-1]=='.'&& mm[pp.first][pp.second-1]==0)
         {
            dis[pp.first][pp.second-1]=dis[pp.first][pp.second]+1;
            qq.push({pp.first,pp.second-1});
            mm[pp.first][pp.second-1]=1;
         }
      }
      if(pp.second<m)
      {
         if(a[pp.first][pp.second+1]=='.'&& mm[pp.first][pp.second+1]==0)
         {
            dis[pp.first][pp.second+1]=dis[pp.first][pp.second]+1;
            qq.push({pp.first,pp.second+1});
            mm[pp.first][pp.second+1]=1;
         }
      }
   }
   return dis[p2.first][p2.second];
}

signed main()
{
     ios_base::sync_with_stdio(false);
     cin.tie(NULL);  
//  #ifndef ONLINE_JUDGE
//     freopen ("INPUT.txt" , "r" , stdin);
//     freopen ("OUTPUT.txt" , "w" , stdout);
//  #endif

// -------------------------------------Code starts here---------------------------------------------------------------------     

   cin>>n>>m;
   for(int i=1;i<=n;i++)
   {
      cin>>a[i];
      a[i]="$"+a[i];
   }
   int mx=0;
   pair<int,int>ind1,ind2;
   for(int i=1;i<=n;i++)
   {
      for(int j=1;j<=m;j++)
      {
      for(int k=1;k<=n;k++)
      {
         for(int l=1;l<=m;l++)
         {
            if(a[i][j]=='.' && a[k][l]=='.')
            {
               int z=bfs({i,j},{k,l});
               if(z>=mx)
               {
                  mx=z;
                  ind1={i,j};
                  ind2={k,l};
               }
            }
         }

      }

      }

      }

   cout<<mx;
// -------------------------------------Code ends here------------------------------------------------------------------
     clock_t clk;
 	clk = clock();
 
    clk = clock() - clk;
 	cerr << fixed << setprecision(6) << "Time: " << ((double)clk)/CLOCKS_PER_SEC << "\n";
 	return 0;
 }

Measured memory_bytes: 256
#include "iostream"
#include "vector"
#include "string"
#include "algorithm"
#include "math.h"
#include "cstring"
#include "stack"
#include "queue"

using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<vector<int> > mat;

int main()
{
  int n;
  cin >> n;
  ll a[200100];
  for (int i = 0; i < n; i++)
  {
    cin >> a[i];
  }
  ll sum[200100];
  sum[0] = 0;
  for (int i = 0; i < n; i++)
  {
    sum[i + 1] = sum[i] + a[i];
  }
  sort(sum, sum + n + 1);
  ll ans = 0;
  ll check = 0;
  for (int i = 0; i < n; i++)
  {
    if (sum[i] == sum[i + 1])
    {
      check++;
      ans += check;
    }
    else
    {
      check = 0;
    }
  }
  cout << ans << "\n";
}

Measured memory_bytes: 3328
/*2019/10/02 */
/*template*/
#include<stdio.h>
#include<stdlib.h>
#include<math.h>
#include<string.h>
#define MOD 1000000007
#define MIN 999999999
#define MAX -999999999
typedef long long int ll;
typedef unsigned long long int ull;
void llswap(ll *x,ll *y){ll tmp;tmp=*x;*x=*y;*y=tmp;}
void swap(int *x,int *y){int tmp;tmp=*x;*x=*y;*y=tmp;}
int rmax(int x,int y){return x>y?x:y;}
int rmin(int x,int y){return x>y?y:x;}
ll llrmax(ll x,ll y){return x>y?x:y;}
ll llrmin(ll x,ll y){return x>y?y:x;}
int asc(const void *a,const void *b){if(*(int*)a < *(int*)b)return -1;else if(*(int*)a == *(int*)b)return 0;else return 1;}
int desc(const void *a,const void *b){if(*(int*)a < *(int*)b)return 1;else if(*(int*)a == *(int*)b)return 0;else return -1;}
int llasc(const void *a,const void *b){if(*(ll*)a < *(ll*)b)return -1;else if(*(ll*)a == *(ll*)b)return 0;else return 1;}
int lldesc(const void *a,const void *b){if(*(ll*)a < *(ll*)b)return 1;else if(*(ll*)a == *(ll*)b)return 0;else return -1;}
int gcd(int x,int y){if(y==0)return x;return gcd(y,x%y);}
/*
int asc_t(const void *a,const void *b){if((struct_t*)a->member < (struct_t*)b->member)return -1;else if((struct_t*)a->member == (struct_t*)b->member)return 0;else return 1;}
int desc_t(const void *a,const void *b){if((struct_t*)a->member < (struct_t*)b->member)return 1;else if((struct_t*)a->member == (struct_t*)b->member)return 0;else return -1;}
*/

int main(){
    int n,a[200000];

    scanf("%d",&n);
    for(int i=0;i<n;i++){
        scanf("%d",&a[i]);
    }
    qsort(a,n,sizeof(int),asc);
    int min=a[0],min_i=0;
    int cnt=0;
    while(1){
        cnt=0;
        for(int i=0;i<n;i++){
            if(min_i==i)continue;
            a[i]%=min;
            if(a[i]==0){
                cnt++;
                continue;
            }
            if(min>a[i]){
                min=a[i];
                min_i=i;
            }
        }
        if(cnt==n-1){
            break;
        }
    }
    /*
    for(int i=0;i<n;i++){
        printf("%d ",a[i]);
    }
    */
    
    printf("%d\n",min);
    return 0;
}

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

using namespace std;

typedef long long ll;

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

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

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

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

    vector<int> A(N + 1, 0);
    for (int i = 0; i < N; i++) {
        cin >> A[i + 1];
    }

    vector<int> L(N + 1, 0);
    for (int i = 1; i <= N; i++) {
        L[i] = gcd(L[i - 1], A[i]);
    }

    vector<int> R(N + 1, 0);
    for (int i = 1; i <= N; i++) {
        R[i] = gcd(R[i - 1], A[N - i + 1]);
    }

    int ans = 0;
    for (int i = 0; i < N; i++) {
        chmax(ans, gcd(L[i], R[N - i - 1]));
    }

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 1408
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <string>
#include <cmath>
#include <stack>
#include <vector>
#include <map>
#include <set>
#include <iostream>


using namespace std;


int c[5];
int counts[14];
int countscounts[5];

bool IsFourCard()
{
	return countscounts[4] == 1;
}
bool IsFullHouse()
{
	return countscounts[3] == 1 && countscounts[2] == 1;
}
bool IsStraight()
{
	for (int i = 0; i < 4; ++i)
	{
		if (c[i]+1 != c[i+1])
		{
			int t[] = { 1, 10, 11, 12, 13 };
			for (int j = 0; j < 5; ++j)
			{
				if (c[j] != t[j])
					return false;
			}
			return true;
		}
	}
	return true;
}
bool IsThreeCard()
{
	return countscounts[3] == 1;
}
bool IsTwoPair()
{
	return countscounts[2] == 2;
}
bool IsOnePair()
{
	return countscounts[2] == 1;
}
bool IsNull()
{
	return true;
}

int main()
{
	bool (*judge[])() = { IsFourCard, IsFullHouse, IsStraight
		, IsThreeCard, IsTwoPair, IsOnePair, IsNull };
	char* names[] = { "four card", "full house", "straight"
		, "three card", "two pair", "one pair", "null" };

	while (scanf("%d,%d,%d,%d,%d", c, c+1, c+2, c+3, c+4) != EOF)
	{
		sort(c, c+5);
		memset(counts, 0, sizeof(counts));
		memset(countscounts, 0, sizeof(countscounts));
		for (int i = 0; i < 5; ++i)
			++counts[c[i]];
		for (int i = 1; i < 14; ++i)
			++countscounts[counts[i]];

		for (int i = 0; i < sizeof(judge)/sizeof(judge[0]); ++i)
		{
			if (judge[i]())
			{
				puts(names[i]);
				break;
			}
		}
	}
	return 0;
}

Measured memory_bytes: 0
#include<bits/stdc++.h>
using namespace std;
using i64 = int_fast64_t;
#define rep(i, N) for(int (i) = 0; (i) < (N); (i)++)
#define all(v) (v).begin(), (v).end()
#define eb emplace_back
#define Cout(s) cout << s << endl
string Yes(bool b) {if(b){return "Yes";} else {return "No";}}
string YES(bool b) {if(b){return "YES";} else {return "NO";}}


int main(){
	int N;
	cin >> N;
	pair<i64,i64> MIN = {0, 1000000};
	rep(i, N){
		i64 A, B;
		cin >> A >> B;
		if(MIN.first < A) {
			MIN.first = A;
			MIN.second = B;
		}
	}

	Cout(MIN.first + MIN.second);
}


Measured memory_bytes: 256
import java.util.*;

class Main{
	public static void main(String args[]){
    Scanner sc = new Scanner(System.in);
    String str = sc.next();
    // /*
    if(str.equals("Sunny"))System.out.println("Cloudy");
    else if(str.equals("Cloudy"))System.out.println("Rainy");
    else if(str.equals("Rainy"))System.out.println("Sunny");
    // */
}
}


Measured memory_bytes: 20692
#include <iostream>
#include <algorithm>
#include <cmath>

using namespace std;

int a[50];

int main()
{
    int N;

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

    int maxval = *max_element(a, a + N);
    int minval = *min_element(a, a + N);

    if(minval >= 0)
    {
        cout << N - 1 << endl;
        for (int i = 1; i < N;i++)
        {
            cout << i << " " << i + 1 << endl;
        }
    }
    else if(maxval <= 0)
    {
        cout << N - 1 << endl;
        for (int i = N; i > 1; i--)
        {
            cout << i << " " << i - 1 << endl;
        }
    }
    else
    {
        cout << 2 * (N - 1) << endl;
        if(abs(maxval) >= abs(minval))
        {
            int maxi = distance(a, max_element(a, a + N)) + 1;
            for (int i = 1; i <= N; i++)
            {
                if(maxi == i)
                {
                    continue;
                }
                cout << maxi << " " << i << endl;
            }
            for (int i = 1; i < N; i++)
            {
                cout << i << " " << i + 1 << endl;
            }
        }
        else
        {
            int mini = distance(a, min_element(a, a + N)) + 1;
            for (int i = 1; i <= N; i++)
            {
                if (mini == i)
                {
                    continue;
                }
                cout << mini << " " << i << endl;
            }
            for (int i = N; i > 1; i--)
            {
                cout << i << " " << i - 1 << endl;
            }
        }
    }

    return 0;
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
using lint = long long int;
struct fast_ios { fast_ios(){ cin.tie(0); ios::sync_with_stdio(false); cout << fixed << setprecision(20); }; } fast_ios_;
#define FOR(i, begin, end) for(int i=(begin),i##_end_=(end);i<i##_end_;i++)
#define REP(i, n) FOR(i,0,n)
#define dbg(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ") " << __FILE__ << endl;


lint solve(int H, int W, int K)
{
    lint ret = 0;
    REP(dh, H - 1)
    {
        FOR(w, 1, W)
        {

            lint R = 2 * K - 2 + gcd(W, dh) - 1LL * w * dh;
            if (R < 0) break;

            lint lo = min<lint>(R / W, H - 1 - dh); // hs <= lo なら必ず成立
            lint hi = min<lint>((R + W * 2) / W, H - dh); // hs >= hi なら必ず不成立

            lint ret_tmp = lo;
            FOR(hs, lo + 1, hi)
            {
                lint x = hs * W - gcd(w, hs) - gcd<int>(W - w, hs + dh);
                if (x <= R) ret_tmp++;
            }
            ret += ret_tmp * (1 + (dh != 0));
        }
    }
    return ret * 2;
}

int main()
{
    int W, H, K;
    cin >> W >> H >> K;
    lint ret = solve(W, H, K) + solve(H, W, K);
    cout << ret << '\n';
}


Measured memory_bytes: 3660