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

int main( )
{
    int a, b;
    cin >> a >> b;
    if (max(a, b) > 8)
    {
        cout << ":(\n";
    }
    else
    {
        cout << "Yay!\n";
    }
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
#include <cmath>
#include <vector>
#include <ctype.h>
#include <stdlib.h>
#include <map>
using namespace std;

int main()
{
	long long X;
	cin >> X;
	long long total = 100;
	
	int i = 0;
	while(total < X){
		 total += total / 100;
		 //cout << total << endl;
		i++;
	}
	cout << i << endl;
}




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

namespace ConsoleApp3
{
    internal class Class2
    {
        private static void Main(string[] args)
        {
            var nk = Console.ReadLine().Split(" ").Select(int.Parse).ToList();
            var n = nk[0];
            var k = nk[1];

            var iya = new HashSet<int>(Console.ReadLine().Split(" ").Select(int.Parse));

            while (n.ToString().Select(x => int.Parse(x.ToString())).Any(iya.Contains))
            {
                n += 1;
            }

            Console.WriteLine(n);
        }
    }
}

Measured memory_bytes: 44580
#include <cstdio>
#include <iostream>
#include <algorithm>
#include <queue>
#include <map>

inline int read()
{
	int data = 0, w = 1; char ch = getchar();
	while (ch != '-' && (ch < '0' || ch > '9')) ch = getchar();
	if (ch == '-') w = -1, ch = getchar();
	while (ch >= '0' && ch <= '9') data = data * 10 + (ch ^ 48), ch = getchar();
	return data * w;
}

const int N(2e6 + 10), M(1e5 + 10);
struct edge { int to, c; };
std::vector<std::pair<int, int> > F[N];
std::vector<edge> G[N];
std::deque<int> Q;
std::map<int, int> map[M];
int n, m, C, cur, dis[N], vis[N];

void add_edge(int x, int y, int c)
{
	G[x].push_back((edge) {y, c});
	G[y].push_back((edge) {x, c});
}

int main()
{
	n = read(), m = read();
	for (int i = 1, a, b, c; i <= m; i++)
		a = read(), b = read(), C = std::max(C, c = read()),
		F[c].push_back(std::make_pair(a, b));
	for (int i = 1; i <= C; i++) for (auto j : F[i])
	{
		if (!map[j.first][i]) map[j.first][i] = ++cur;
		if (!map[j.second][i]) map[j.second][i] = ++cur;
		add_edge(map[j.first][i], map[j.second][i], 0);
	}
	for (int i = 1; i <= n; i++)
		{ ++cur; for (auto j : map[i]) add_edge(j.second, cur, 1); }
	for (int i = 1; i <= cur; i++) dis[i] = 0x3f3f3f3f;
	for (auto j : map[1]) Q.push_back(j.second), vis[j.second] = 1, dis[j.second] = 2;
	while (!Q.empty())
	{
		int x = Q.front(); Q.pop_front();
		for (auto i : G[x]) if (dis[i.to] > dis[x] + i.c)
			dis[i.to] = dis[x] + i.c, (i.c ? Q.push_back(i.to) : Q.push_front(i.to));
	}
	int ans = 0x3f3f3f3f;
	for (auto j : map[n]) ans = std::min(ans, dis[j.second]);
	printf("%d\n", ans == 0x3f3f3f3f ? -1 : ans / 2);
	return 0;
}


Measured memory_bytes: 147072
N,K =[int(i) for i in input().split(' ')]

A = [int(i) for i in input().split(' ')]
"""
index_1 = -1

for i in range(len(A)):
    #print(index_1)
    if A[i]==1:
        index_1 = i
        break

ans = 0
if index_1%(K-1)==0:
    ans += index_1 // (K-1)
else:
    ans += index_1 //(K-1) + 1

if (N-index_1 -1)%(K-1)==0:
    ans += (N - index_1-1) // (K-1)
else:
    ans += (N - index_1 -1) //(K-1) + 1
    
print(ans)
"""
ans =0
if (N-1)%(K-1) ==0:
    ans = (N-1)//(K-1)
else:
    ans = (N-1)//(K-1) +1
print(ans)


Measured memory_bytes: 13880
#include <bits/stdc++.h>
 
#define _overload(_1,_2,_3,name,...) name
#define _rep(i,n) _range(i,0,n)
#define _range(i,a,b) for(int i=(int)(a);i<(int)(b);++i)
#define rep(...) _overload(__VA_ARGS__,_range,_rep,)(__VA_ARGS__)
 
#define _rrep(i,n) _rrange(i,n,0)
#define _rrange(i,a,b) for(int i=(int)(a)-1;i>=(int)(b);--i)
#define rrep(...) _overload(__VA_ARGS__,_rrange,_rrep,)(__VA_ARGS__)
 
#define _all(arg) begin(arg),end(arg)
#define uniq(arg) sort(_all(arg)),(arg).erase(unique(_all(arg)),end(arg))
#define bit(n) (1LL<<(n))
 
// #define DEBUG
 
#ifdef DEBUG
    #define dump(...) fprintf(stderr, __VA_ARGS__)
#else
    #define dump(...)
#endif
 
template<class T>bool chmax(T &a, const T &b) { return (a<b)?(a=b,1):0;}
template<class T>bool chmin(T &a, const T &b) { return (b<a)?(a=b,1):0;}
 
using namespace std;
using ll=long long;
using vi=vector<int>;
using vll=vector<ll>;
 
const double EPS = 1e-10;
const double PI = acos(-1.0);
const int inf = INT_MAX;
const ll INF = LLONG_MAX;
const ll MOD = 1000000007LL;
const int dx[4]={1,0,-1,0};
const int dy[4]={0,1,0,-1};
 
ll extgcd(ll a,ll b,ll& x,ll& y){x=1,y=0;ll g=a;if(b!=0) g=extgcd(b,a%b,y,x),y-=a/b*x;return g;}
ll ADD(const ll &a, const ll &b, const ll mod=MOD) { return (a+b)%mod;}
ll SUB(const ll &a, const ll &b, const ll mod=MOD) { return (a-b+mod)%mod;}
ll MUL(const ll &a, const ll &b, const ll mod=MOD) { return (1LL*a*b)%mod;}
ll DIV(const ll &a, const ll &b, const ll mod=MOD) {ll x,y; extgcd(b,mod,x,y);return MUL(a,(x+mod)%mod,mod);}
 
int main(void){
    cin.tie(0);
    ios::sync_with_stdio(false);

    int A, B, K; cin >> A >> B >> K;

    int cnt = 0;
    rrep(i, 101, 1){
        if(A % i == 0 and B % i == 0){
            cnt++;
        }
        if(cnt == K){
            cout << i << endl;
            break;
        }
    }

    return 0;
}


Measured memory_bytes: 256
a,b,c = gets.split.map(&:to_f)
puts 1.0/2.0 * a *b*Math::sin(c/180 *Math::PI)
puts a + b + Math::sqrt(a**2+b**2 - 2.0*a*b*Math::cos(c/180*Math::PI))
puts b * Math::sin(c/180*Math::PI)

Measured memory_bytes: 9000
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main(){
    ios_base:: sync_with_stdio(false);
    cin.tie(NULL); cout.tie(NULL);
    vector<ll> cnt(9,0);
    ll n;cin>>n;
    for(ll i=0,x;i<n;i++){
         cin>>x;
         if(x<=399)cnt[0]++;
         else if(x<=799)cnt[1]++;
         else if(x<=1199)cnt[2]++;
         else if(x<=1599)cnt[3]++;
         else if(x<=1999)cnt[4]++;
         else if(x<=2399)cnt[5]++;
         else if(x<=2799)cnt[6]++;
         else if(x<=3199)cnt[7]++;
         else cnt[8]++;
    }
    ll mn = 0;
    for(ll i=0;i<8;i++)mn+=(cnt[i]>0);
    if(mn>=1)cout<<mn<<" "<<mn+cnt[8];
    else cout<<1<<" "<<cnt[8];
}


Measured memory_bytes: 256
//It doesn't matter how slow you go, Unless you don't stop.
#include<iostream>
#include<algorithm>
#include<bitset>
 
#include<cmath>
#include<cstring>
#include<climits>
 
#include<deque>
#include<queue>
#include<vector>
#include<set>
#include<map>
#include<unordered_set>
#include<unordered_map>
 
#include<fstream>
#include<chrono>
using namespace std;
 
typedef long long LL;
typedef pair<LL,LL> p64;
typedef vector<LL> v64;
typedef map<LL,LL> mp64;
 
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define rep(i,s,e) for(long long i=s;i<=e;i++)
#define brep(i,s,e) for(long long i=s;i>=e;i--)
#define all(x) x.begin(),x.end()
#define mem(x,y) memset(x,y,sizeof(x))
#define DANGER std::ios::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL)
 
void solve()
{
     int xred,ygreen,a,b,c;
     cin>>xred>>ygreen>>a>>b>>c;
     int need = xred+ygreen;
     vector<pair<int,int>> red;
     vector<pair<int,int>> green;
     vector<pair<int,int>> nope;
     priority_queue<pair<int,int>> p;
     for(int i=0;i<a;i++)
     {
         int x;cin>>x;
         red.pb(mp(x,1));
         p.push(mp(x,1));
     }
     for(int i=0;i<b;i++)
     {
         int x;cin>>x;
         green.pb(mp(x,2));
         p.push(mp(x,2));
     }
     for(int i=0;i<c;i++)
     {
         int x;cin>>x;
         nope.pb(mp(x,3));
         p.push(mp(x,3));
     }
     LL res=0;
     int bal=0;
     while(!p.empty())
     {

        //  cout<<p.top().first<<" "<<p.top().second<<endl;
        //  p.pop();
        if(!need)
        {
            break;
        }
        int x = p.top().second;
        if(x == 1)
        {
            if(xred>0)
            {
                res += p.top().first;
                xred--;
                need--;
            }
        }
        else if(x == 2)
        {
            if(ygreen>0)
            {
                res += p.top().first;
                ygreen--;
                need--;
            }
        }
        else
        {
            res += p.top().first;
            bal++;
            need--;
        }
        p.pop();
     }
     cout<<res<<endl;
     

}
 
int main()
{
    DANGER;
    ofstream out("output.txt");
 
    auto start = chrono::high_resolution_clock::now();
    
    LL t = 1;
    // cin>>t;
    rep(test,1,t)
    {
        solve();
    }
    
    auto stop = chrono::high_resolution_clock::now();
    // auto duration = chrono::duration_cast<chrono::milliseconds>(stop - start); 
    // cout << "Time taken by function: " << duration.count() << " milliseconds" << endl;
}

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

int main()
{
    int n;
    cin >> n;
    int ans = 0;
    vector<int> a(n);
    for(int i=0;i<n;i++){
        cin >> a[i];
    }
    sort(a.begin(),a.end());
    int tmp = 1;
    for(int j=n-1;j>=0;j--){
        ans = ans + a[j]*tmp;
        tmp = tmp*(-1);
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
n,a,b = map(int,input().split())

s = list(input())

t = 0

kt = 0

j = 1

for i in s:
    if i == "c":
        print("No")
        ++j
    elif i == "a":
        if t < a+b:
            print("Yes")
            t += 1
            j += 1
        else:
            print("No")
            j += 1
    else:
        if t < a+b and kt < b:
            print("Yes")
            t += 1
            kt += 1
            j += 1
        else:
            print("No")
            j += 1

Measured memory_bytes: 4708
#include <iostream>
#include <vector>
#include <algorithm>
#include <utility>
#define llint long long

using namespace std;
typedef pair<llint, llint> P;
typedef pair<llint, P> E;

struct UnionFind{
	int size;
	vector<int> parent;
	
	UnionFind(){}
	UnionFind(int size){
		this->size = size;
		parent.resize(size+1);
		init();
	}
	void init(){
		for(int i = 0; i <= size; i++) parent[i] = i;
	}
	int root(int i){
		if(parent[i] == i) return i;
		return parent[i] = root(parent[i]);
	}
	bool same(int i, int j){
		return root(i) == root(j);
	}
	void unite(int i, int j){
		int root_i = root(i), root_j = root(j);
		if(root_i == root_j) return;
		parent[root_i] = root_j;
	}
};

llint n;
P x[100005], y[100005];
vector<E> vec;
UnionFind uf(100005);

int main(void)
{
	cin >> n;
	for(int i = 1; i <= n; i++){
		cin >> x[i].first >> y[i].first;
		x[i].second = y[i].second = i;
	}
	sort(x+1, x+n+1);
	sort(y+1, y+n+1);
	
	for(int i = 1; i < n; i++){
		vec.push_back(E(x[i+1].first-x[i].first, P(x[i].second, x[i+1].second)));
		vec.push_back(E(y[i+1].first-y[i].first, P(y[i].second, y[i+1].second)));
	}
	sort(vec.begin(), vec.end());
	
	llint ans = 0;
	for(int i = 0; i < vec.size(); i++){
		llint w = vec[i].first, u = vec[i].second.first, v = vec[i].second.second;
		if(uf.same(u, v)) continue;
		ans += w;
		uf.unite(u, v);
	}
	cout << ans << endl;
	
	return 0;
}

Measured memory_bytes: 12016
#include <iostream>
#include <sstream>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <string>
#include <vector>
#include <list>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <bitset>
#include <numeric>
#include <climits>
#include <cfloat>
using namespace std;

class Edge
{
public:
    int to, cost;
    Edge(){};
    Edge(int to0, int cost0){to = to0; cost = cost0;}
};

void shortestPath(const vector<vector<Edge> >& edges, int start, vector<int>& dist)
{
    dist.assign(edges.size(), INT_MAX);
    dist[start] = 0;
    priority_queue<pair<int,int> ,vector<pair<int,int> >, greater<pair<int,int> > > q;
    q.push(make_pair(0, start));

    while(!q.empty()){
        pair<int, int> p = q.top();
        q.pop();
        int v = p.second;
        if(dist[v] < p.first)
            continue;
        for(unsigned i=0; i<edges[v].size(); ++i){
            Edge e = edges[v][i];
            if(dist[v] + e.cost < dist[e.to]){
                dist[e.to] = dist[v] + e.cost;
                q.push(make_pair(dist[e.to], e.to));
            }
        }
    }

    replace(dist.begin(), dist.end(), INT_MAX, -1);
}

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

    vector<vector<Edge> > edges(n);
    for(int i=0; i<m; ++i){
        int a, b, c, d;
        char z;
        cin >> a >> z >> b >> z >> c >> z >> d;
        edges[a-1].push_back(Edge(b-1, c));
        edges[b-1].push_back(Edge(a-1, d));
    }

    int x1, x2, y1, y2;
    char z;
    cin >> x1 >> z >> x2 >> z >> y1 >> z >> y2;

    vector<int> dist1, dist2;
    shortestPath(edges, x1-1, dist1);
    shortestPath(edges, x2-1, dist2);

    int ret = y1 - y2 - dist1[x2-1] - dist2[x1-1];
    cout << ret << endl;
}

Measured memory_bytes: 0
import math

def get_runlength(s): # ex) s = 'RRLLLLRLRLRLRR'
    ret = []
    count = 1
    for i in range(len(s)):
        if i == len(s) - 1:
            ret.append((s[i], count))
            continue
        if s[i] == s[i + 1]:
            count += 1
        else:
            ret.append((s[i], count))
            count = 1
    return ret

s = input()
n = len(s)
ch = [1] * n

# 以下だと時間計算量がO(N^2)になってしまう。
# for _ in range(10 ** 100):
#     tmp = [0] * n
#     for i in range(n):
#         if i == 0:
#             tmp[1] += ch[0]
#         elif i == n - 1:
#             tmp[n - 2] += ch[n - 1]
#         else:
#             if s[i] == "R":
#                 tmp[i + 1] += ch[i]
#             else:
#                 tmp[i - 1] += ch[i]
#     ch = tmp

# for i in ch:
#     print(i + " ")

"""
    10^100 回移動を行うということは、すなわち「十分な回数」「偶数回」移動をする
    ということである。
    文字列を
    RR...RLL...L の塊の分解することができる。たとえば

    RRLRL は RRL と RL に分解でき、十分な移動のあとはそれらの境界 LR の間を行き来する。
    また、偶数回の移動後、子どもたちがいるマスははじめ子どもたちがいたマスの偶奇と一致する。
    それを利用して実装していく

    例: RRLLLLRLRRLL
"""
# 最終的なこどもたちの数
ch = [0] * len(s)
# runlength を計算
rl = get_runlength(s)

i = 0
pos = 0
while i < len(rl):
    r, l = rl[i], rl[i + 1]
    # R の右端
    ch[pos + r[1] - 1] = math.floor(l[1] / 2) + math.floor((r[1] + 1) / 2)
    # L の左端
    ch[pos + r[1]] = math.floor(r[1] / 2) + math.floor((l[1] + 1) / 2)
    i += 2
    pos += r[1] + l[1]

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


Measured memory_bytes: 17636
def solve():
    N,K = map(int,input().split())
    V = list(map(int,input().split()))

    ans = -float('inf')
    for left in range(min(N,K)+1):
        for right in range(min(N,K)-left+1):
            took = V[:left] + V[-1:-(right+1):-1]
            took.sort()
            sm = sum(took)
            for put in range(K-(left+right)):
                if len(took) == put:
                    break
                if took[put] >= 0:
                    break
                sm += abs(took[put])
            
            ans = max(ans,sm)
    
    print(ans)
if __name__ == '__main__':
    solve()

Measured memory_bytes: 41068
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define F first
#define S second
#define pii pair<int, int>
#define eb emplace_back
#define all(v) v.begin(), v.end()
#define rep(i, n) for (int i = 0; i < n; ++i)
#define rep3(i, l, n) for (int i = l; i < n; ++i)
#define chmax(a, b) a = max(a, b)
#define chmin(a, b) a = min(a, b)
#define out(a) cout << a << endl
#define SZ(v) (int)v.size()
#define inf (int)(1e9+7)

int main() {
    ll l[87] = {0};
    l[0] = 2;
    l[1] = 1;
    rep3(i, 2, 87) l[i] = l[i - 1] + l[i - 2];
    int n; cin >> n;
    out(l[n]);
}




Measured memory_bytes: 256
l,r=map(int,input().split())
if r-l>=2019:
  print(0)
else:
  a=2019
  for i in range(l,r):
    for j in range(i+1,r+1):
      a=min((i%2019)*(j%2019)%2019,a)
  print(a)

Measured memory_bytes: 3060
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
const int mod=1000000007;
const double PI = 3.14159265359;
#define mxe(v) *max_element(v.begin(),v.end())
#define mne(v) *min_element(v.begin(),v.end())
#define INF 1000000000000
#define pb push_back
#define pf push_front
#define ppb pop_back
#define ppf pop_front
#define mp make_pair
#define lb lower_bound
#define ub upper_bound
#define FOR(i,n) for(int i=0;i<(n);i++)
#define FORA(i,a,b) for(int i=(a);i<=(b);i++)
#define FORD(i,a,b) for(int i=(a);i>=(b);i--)
#define FAST ios_base::sync_with_stdio(false);cin.tie(NULL);
#define count_1(n)  __builtin_popcountll(n)
#define parity(n)   __builtin_parityll(n)   //Even parity 0 as output
void show    (int a[], int arraysize) { for (int i = 0; i < arraysize; ++i)  {cout << a[i] << " ";}	cout<<endl;}
int gcd(int a, int b) { if (b == 0) return a; return gcd(b, a % b);}
void sieve(int n)
{
    bool prime[n+1];
    memset(prime, true, sizeof(prime));

    for (int p=2; p*p<=n; p++)
    {
        if (prime[p] == true)
        {
            for (int i=p*p; i<=n; i += p)
                prime[i] = false;
        }
    }
    for (int p=2; p<=n; p++)
       if (prime[p])
          cout << p << " ";
}
int main()
{FAST
int x1,x2,x3,x4,x5;
cin>>x1>>x2>>x3>>x4>>x5;
if(x1==0)
{
	cout<<"1\n";
}
if(x2==0)
{
	cout<<"2\n";
}
if(x3==0)
{
	cout<<"3\n";
}
if(x4==0)
{
	cout<<"4\n";
}
if(x5==0)
{
	cout<<"5\n";
}
return  0;
}






Measured memory_bytes: 3612
/*
   Push yourself, because no one else is going to do it for you.
*/
#include <bits/stdc++.h>
#define fast_io ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define set_zero(a) memset(a,0,sizeof(a));
#define ll long long int
#define PI 2 * acos(0.0)
#define MAX 10000000000000000
#define in(a) scanf("%d",&a);
#define out(a) printf("%d",a);
#define INF 1000000 
#define M 1000000007
using namespace std;
bool comp(ll a, ll b) 
{ 
    return (a < b); 
} 
int main(){ 
   fast_io
   ll a,b;
   cin>>a>>b;
   if(a >= 1 && a <= 9 && b >= 1 && b <= 9){
      cout<<a*b<<endl;
   }
   else{
      cout<<-1<<endl;
   }
   return 0; 
}  

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

using namespace std;
typedef long long ll;

#define REP(i, n) for (ll i = 0; i < (n); i++)
#define REPR(i, n) for (ll i = (n); i >= 0; i--)
#define FOR(i, m, n) for (ll i = (m); i < (n); i++)
#define FORR(i, m, n) for (ll i = (m); i >= (n); i--)
#define INF 1e9
#define ALL(x) (x).begin(), (x).end()
#define SZ(x) ((ll)(x).size())
#define SORT(x) sort((x).begin(), (x).end())
#define dump(x) cerr << #x << " = " << (x) << endl
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" \
                      << " " << __FILE__ << endl

int main(int argc, char const *argv[])
{
    ll a, b, k;
    cin >> a >> b >> k;
    ll c;
    if (a > b)
        c = a;
    else
        c = b;
    ll d = 0;
    FORR(i, c, 1)
    {
        if (a % i == 0 && b % i == 0)
        {
            d++;
            if (d == k)
            {
                cout << i << endl;
                return 0;
            }
        }
    }
    return 0;
}


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

int main(){
  int W, H, x, y, r;
  cin >> W >> H >> x >> y >> r;
  if (r <= x && r <= y && W - r >= x && H - r >= y) {
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }
  return 0;
}



Measured memory_bytes: 3092
#include<bits/stdc++.h>
using namespace std;
int main() {
  int N, K;
  cin >> N >> K;
  vector<int> p(N);

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

  sort(p.begin(), p.end());
  int sum = 0;

  for(int i = 0; i < K; i++) {
    sum += p[i];
  }

  cout << sum;
  return 0;
  }

Measured memory_bytes: 3620
#include <bits/stdc++.h>
/* S.size() s.substr(l,r=s.size()-l) -> l文字目からr文字分
__gcd()　lower_bound(a+l,a+r,x)-a でindex
// 配列  -> min/max({}) 
// vector-> *min_element(a+l,a+r)  *忘れず lとrで[l,r) 
//reverse(a+l,a+r)   配列aの[l,r)を逆順に strはreverse(all(s))
//sort(a+l,a+r,greater <int>()) 配列aの[l,r)昇順sort,大きい順はgreater<type>()
//vectorならall(v)
clock()/CLOCKS_PER_SEC で秒数
vector v.push_back(x),v.pop_back()
q.push(x),front()で先頭を返す,pop()で削除, size(),empty()
<deque>(push/pop)_(front/back)/fornt/back/insert/
priority_queue 宣言は priority_queue< Type, vector<Type>, greater<Type>> Q1; 
// pq.push(x),top()で参照 pop()で削除   greaterで最小 lessで最大がtopに*/
using namespace std;
#define all(v) (v).begin(), (v).end()
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define print(i) std::cout << (i) << '\n'
#define rrep(i,n) for(int (i)=(n)-1;(i)!=-1;(i)--)
#define vep(i,v) for(auto (i)=v.begin();(i)<(v.end());(i)++)
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; }
inline long long ceildiv(long long a, long long  b) { return (a+b-1)/b; }
typedef pair<long long,long long> P;
typedef pair<int,int> PI;
using Graph = std::vector<std::vector<int> >;
const long long inf = 10e17;
const long long mod = 1000000007;
//int |x|<=2*10**9     long |x|<= 9*10**18
//printf(".(小数点以下の桁数)lf(double時、float ならf)")
#define ll long long
struct edge{ll from,to,cost;};
edge es[2200];
ll d[2200];
int n,m;

ll path(int s){
    rep(i,n+1){d[i]=-inf;}
    d[s]=0;
    int cnt=0;
    
    ll pre=-inf;
    while (true){
        bool update=false;
        rep(i,m){
            edge e=es[i];
            if (d[e.from]!=-inf &&d[e.to]<d[e.from]+e.cost){
                d[e.to]=d[e.from]+e.cost;update=true;
            }
        } if(!update)return d[n];
        cnt++;
        if (d[n]>pre)pre=d[n];
        if(cnt>=n+1){
         rep(i,m){
            edge e=es[i];
            if (d[e.from]!=-inf &&d[e.to]<d[e.from]+e.cost){
                d[e.to]=d[e.from]+e.cost;
            }
        } if (pre<d[n])return -inf-10;else{return pre;}
        }
    }
} 
int main(){
cin>>n>>m;
rep(i,m){ll a,b,c;cin>>a>>b>>c;edge x;x.from=a;x.to=b;x.cost=c;es[i]=x;}
ll ans=path(1);
if (ans==-inf-10){print("inf");}else{print(ans);}
}


Measured memory_bytes: 384
use std::vec::Vec;

fn read<T: std::str::FromStr>() -> T {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().parse().ok().unwrap()
}

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

fn read_touple<T: std::str::FromStr + Copy>() -> (T, T, T) {
  let v: Vec<T> = read_vec();
  assert_eq!(v.len(), 3);
  (v[0], v[1], v[2])
}

fn main() {
    let (x, y, z) = read_touple::<usize>();
    println!("{} {} {}", z, x, y);
}


Measured memory_bytes: 4352
#include <bits/stdc++.h>
#define FI first
#define SE second
#define EPS 1e-9
#define ALL(a) a.begin(),a.end()
#define SZ(a) int((a).size())
#define MS(s, n) memset(s, n, sizeof(s))
#define FOR(i,a,b) for (int i = (a); i <= (b); i++)
#define FORE(i,a,b) for (int i = (a); i >= (b); i--)
#define FORALL(it, a) for (__typeof((a).begin()) it = (a).begin(); it != (a).end(); it++)
#define WHATIS(x) cout << #x << " is " << x << endl;
#define ERROR(args...) { string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); stringstream _ss(_s); istream_iterator<string> _it(_ss); err(_it, args); }
//__builtin_ffs(x) return 1 + index of least significant 1-bit of x
//__builtin_clz(x) return number of leading zeros of x
//__builtin_ctz(x) return number of trailing zeros of x

using namespace std;
using ll = long long;
using ld = double;
typedef pair<int, int> II;
typedef pair<II, ll> III;
typedef complex<ld> cd;
typedef vector<cd> vcd;

void err(istream_iterator<string> it) {}
template<typename T, typename... Args>
void err(istream_iterator<string> it, T a, Args... args) {
    cout << *it << " = " << a << endl;
    err(++it, args...);
}

const ll MODBASE = 1000000007LL;
const int MAXN = 100010;
const int MAXM = 35;
const int MAXK = 510;
const int MAXQ = 200010;

int n, m, pos[MAXN];
vector<II> a[MAXN];
bool visit[MAXN], co = true;

void dfs(int u) {
    visit[u] = true;
    FOR(i,0,SZ(a[u])-1) {
        int v = a[u][i].FI;
        int c = a[u][i].SE;
        if (visit[v]) {
            if (pos[v] != pos[u] + c) co = false;
        }
        else {
            pos[v] = pos[u] + c;
            dfs(v);
        }
    }
}

int main() {
    ios::sync_with_stdio(0);
    cin.tie(nullptr);
    cin >> n >> m;
    FOR(i,1,m) {
        int u, v, c;
        cin >> u >> v >> c;
        a[u].emplace_back(II(v, c));
        a[v].emplace_back(II(u, -c));
    }
    FOR(i,1,n)
        if (!visit[i]) dfs(i);
    if (!co) cout << "No";
    else cout << "Yes";
    return 0;
}

Measured memory_bytes: 12160
import math


def compute_prime_factor(n: int) -> None:
    global prime_factors
    sqrt_n = int(math.sqrt(n)) + 1
    for i in range(2, sqrt_n + 1):
        if 0 == (n % i):
            prime_factors.append(i)
            compute_prime_factor(n // i)
            return
    if 1 != n:
        prime_factors.append(n)
        return


if __name__ == "__main__":
    n = int(input())
    prime_factors = []  # type: ignore
    compute_prime_factor(n)

    print(f"{n}: " + " ".join([str(elem) for elem in prime_factors]))



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

public class AtCoderA
{
    static void Main()
    {
        var sc = new Scanner();

        long k = sc.NextLong();

        string answer = "";

        for (int i = 0; i < k; i++)
        {
            answer += "ACL";
        }

        Console.WriteLine(answer);
    }

    class Scanner
    {
        private string[] _line;
        private int _index;
        private const char Separator = ' ';

        public Scanner()
        {
            _line = new string[0];
            _index = 0;
        }

        public string Next()
        {
            while (_index >= _line.Length)
            {
                _line = Console.ReadLine().Split(Separator);
                _index = 0;
            }

            return _line[_index++];
        }

        public int NextInt() => int.Parse(Next());
        public long NextLong() => long.Parse(Next());
        public double NextDouble() => double.Parse(Next());
        public decimal NextDecimal() => decimal.Parse(Next());
        public char NextChar() => Next()[0];
        public char[] NextCharArray() => Next().ToCharArray();

        public string[] Array()
        {
            _line = Console.ReadLine().Split(Separator);
            _index = _line.Length;
            return _line;
        }

        public int[] IntArray() => Array().Select(int.Parse).ToArray();
        public long[] LongArray() => Array().Select(long.Parse).ToArray();
        public double[] DoubleArray() => Array().Select(double.Parse).ToArray();
        public decimal[] DecimalArray() => Array().Select(decimal.Parse).ToArray();
    }
}


Measured memory_bytes: 27116
X, Y = map(int, input().split())

def mod_Combination(n, k, mod):
    def ext_gcd(a, b):
        if b == 0:
            return a, 1, 0
        else:
            d,x,y = ext_gcd(b,a%b)
            x-=(a//b)*y 
        return d,y,x
    p,q=1,1
    for i in range(n-k+1, n+1):
        p=(p*i)%mod
    for i in range(2, k+1):
        q=(q*i)%mod
    return int(p*(ext_gcd(q, mod)[1]%mod)%mod)

if X > Y:
    X, Y = Y, X

a = (2*X - Y)/3
b = (2*Y - X)/3

if (X+Y)%3 != 0:
    ans = 0

elif a<0 or b<0:
    ans = 0

else:
    ans = mod_Combination(int(a + b), int(a), 10**9 + 7)

print(ans)


Measured memory_bytes: 3188
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<iomanip>
#include<math.h>
#include<complex>
#include<queue>
#include<deque>
#include<stack>
#include<map>
#include<set>
#include<bitset>
#include<functional>
#include<assert.h>
#include<numeric>
using namespace std;
#define REP(i,m,n) for(int i=(int)m ; i < (int) n ; ++i )
#define rep(i,n) REP(i,0,n)
typedef long long ll;
typedef pair<int,int> pint;
typedef pair<ll,int> pli;
const int inf=1e9+7;
const ll longinf=1LL<<60 ;
const ll mod=1e9+7 ;

int main(){
	int a,b,c;
	cin>>a>>b>>c;
	cout<<a+b+c-max({a,b,c})<<endl;
	return 0;
}

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

const int MOD = 1000000007;
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);

  int n, m;
  cin >> n >> m;
  vector<int> dp(n + 1, 0);
  rep(i, 0, m) {
    int a;
    cin >> a;
    dp[a] = -1;
  }

  dp[0] = 1;
  rep(i, 1, n + 1) {
    if (dp[i] == -1)
      continue;
    if (dp[i - 1] == -1 && dp[i - 2] == -1) {
      cout << 0 << endl;
      return 0;
    }

    if (i == 1)
      dp[i] = dp[i - 1];
    else {
      if (dp[i - 1] == -1)
        dp[i] = dp[i - 2];
      else if (dp[i - 2] == -1)
        dp[i] = dp[i - 1];
      else
        dp[i] = dp[i - 1] + dp[i - 2];
    }

    dp[i] %= MOD;
  }

  cout << dp[n] << endl;
}


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

int main() {
  int n, x;
  cin >> n >> x;
  vector<int> li(n);
  for (int i = 0; i < n; i++) cin >> li.at(i);
  
  int ans = 1;
  int d = 0;
  for (int l : li) {
    d += l;
    if (d > x) break;
    ans++;
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.InputStreamReader;

public class Main {
	public static void main(String[] args) throws Exception {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		int n = Integer.parseInt(br.readLine());
		int[][] f = new int[n][10];
		for (int i = 0; i < n; i++) {
			String[] sa = br.readLine().split(" ");
			for (int j = 0; j < 10; j++) {
				f[i][j] = Integer.parseInt(sa[j]);
			}
		}
		int[][] p = new int[n][11];
		for (int i = 0; i < n; i++) {
			String[] sa = br.readLine().split(" ");
			for (int j = 0; j < 11; j++) {
				p[i][j] = Integer.parseInt(sa[j]);
			}
		}
		br.close();

		long ans = Long.MIN_VALUE;
		int end = 1 << 10;
		for (int i = 1; i < end; i++) {
			long val = 0;
			for (int k = 0; k < n; k++) {
				int cnt = 0;
				for (int j = 0; j < 10; j++) {
					if (f[k][j] == 1 && (i >> j & 1) == 1) {
						cnt++;
					}
				}
				val += p[k][cnt];
			}
			ans = Math.max(ans, val);
		}
		System.out.println(ans);
	}
}


Measured memory_bytes: 23892
using System;

namespace AtCoderProblems
{
    class MainClass
    {
        public static void Main(string[] args)
        {
            string[] str = Console.ReadLine().Split(' ');
            var n = int.Parse(str[0]);
            var x = int.Parse(str[1]);
            var t = int.Parse(str[2]);

            if(n % x == 0)
            {
                Console.WriteLine((n / x) * t);

            }
            else
            {
                Console.WriteLine((n / x + 1) * t);
            }

            
        }
    }
}


Measured memory_bytes: 27420
/**
 *    author:  otera    
**/
#include<iostream>
#include<string> 
#include<cstdio>
#include<cstring>
#include<vector>
#include<cmath>
#include<algorithm> 
#include<functional>
#include<iomanip>
#include<queue>
#include<deque>
#include<ciso646>
#include<random>
#include<map>
#include<set>
#include<complex>
#include<bitset>
#include<stack>
#include<unordered_map>
#include<utility>
#include<cassert>
using namespace std;

#define int long long
typedef long long ll;
typedef unsigned long long ul;
typedef unsigned int ui;
typedef long double ld;
const int inf=1e9+7;
const ll INF=1LL<<60 ;
const ll mod=1e9+7 ;
#define rep(i,n) for(int i=0;i<n;i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define per1(i,n) for(int i=n;i>=1;i--)
#define Rep1(i,sta,n) for(int i=sta;i<=n;i++)
typedef complex<ld> Point;
const ld eps = 1e-8;
const ld pi = acos(-1.0);
typedef pair<int, int> P;
typedef pair<ld, ld> LDP;
typedef pair<ll, ll> LP;
#define fr first
#define sc second
#define all(c) c.begin(),c.end()
#define pb push_back
#define debug(x)  cerr << #x << " = " << (x) << endl;
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; }

void solve() {
	int n; cin >> n;
    static int dp[100100][3];
    rep(i, 100100) {
        rep(j, 3) {
            dp[i][j] = -INF;
        }
    }
    int x; char c;
    cin >> x;
    dp[0][0] = x;
    rep(i, n - 1) {
        cin >> c >> x;
        if(c == '+') {
            chmax(dp[i + 1][0], dp[i][0] + x);
            chmax(dp[i + 1][1], dp[i][1] - x);
            chmax(dp[i + 1][0], dp[i][1] + x);
            chmax(dp[i + 1][2], dp[i][2] + x);
            chmax(dp[i + 1][1], dp[i][2] + x);
            chmax(dp[i + 1][0], dp[i][2] + x);
        } else {
            chmax(dp[i + 1][0], dp[i][0] - x);
            chmax(dp[i + 1][1], dp[i][0] - x);
            chmax(dp[i + 1][0], dp[i][1] - x);
            chmax(dp[i + 1][1], dp[i][1] + x);
            chmax(dp[i + 1][2], dp[i][1] + x);
            chmax(dp[i + 1][0], dp[i][2] - x);
            chmax(dp[i + 1][1], dp[i][2] + x);
            chmax(dp[i + 1][2], dp[i][2] - x);
        }
    }
    cout << *max_element(dp[n - 1], dp[n - 1] + 3) << endl;
}

signed main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	//cout << fixed << setprecision(10);
	//int t; cin >> t; rep(i, t)solve();
	solve();
    return 0;
}

Measured memory_bytes: 5980
import java.util.*

fun main(args: Array<String>) {
    val sc = Scanner(System.`in`)
    val n = sc.nextInt()
    val k = sc.nextInt()
    val p = (0 until n).map { sc.next().toInt() }
    println(problem171b(n, k, p))
}

fun problem171b(n: Int, k: Int, p: List<Int>): Int {
    return p.sorted().take(k).sum()
}

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

int main(int argc, const char * argv[]) {
    int a,b;
    string str;
    cin >> a >> b ;
   
    if(a>b){
        str = " > ";
        
    }else if(a<b){
            
        str = " < ";
        
    }else{
        str = " == ";
    }
        
    
    cout << "a" << str  << "b" << endl;
    
    return 0;
}

Measured memory_bytes: 1192
import java.util.*;

public class Main
{
  static long oo = (long)1e18;
  public static void main(String[] args)
  {
	Scanner in = new Scanner(System.in);
    int n = in.nextInt();
    int w = in.nextInt();
    long[] W = new long[n];
    int[] V = new int[n];
    for (int i = 0; i < n; i++)
    {
      W[i] = in.nextLong();
      V[i] = in.nextInt();
    }
    
    long[] min = new long[1000*100+1];
    Arrays.fill(min, oo);
    min[0] = 0;
    for (int i = 0; i < n; i++)
      for (int v = 1000*100-V[i]; v >= 0; v--)
          min[v+V[i]] = Math.min(min[v+V[i]], W[i]+min[v]);
    
    int best = 1000*100;
    for (; best >= 0; best--)
      if (min[best] <= w)
        break;
    System.out.println(best);        
    in.close();
  }
}

Measured memory_bytes: 23636
#include<bits/stdc++.h>
#define IO ios::sync_with_stdio(false), cin.tie(0)
#define INF 0x3f3f3f3f
typedef long long ll;
using namespace std;

int main()
{
	IO;
	string s;
	cin>>s;
	for(int i=0;i<s.length();i++){
		if(s[i]=='7'){
			cout<<"Yes"<<endl;
			return 0;
		}
	} 
	cout<<"No"<<endl;
 	return 0;
}







Measured memory_bytes: 3652
using System;
using System.Collections.Generic;
using System.Linq;
using static Input;

public class Prog
{
    private const int INF = 1000000007;
    private const long INFINITY = 9223372036854775807;
    private struct Pair { public int x, y; public Pair(int xx, int yy) { x = xx; y = yy; } }
    private static int[] dx = { 1, 0, -1, 0 };
    private static int[] dy = { 0, -1, 0, 1 };
    public static void Main()
    {
        int N = NextInt();
        int[] A = LineInt();
        Dictionary<int, int> d = new Dictionary<int, int>();
        for (int i = 0; i < N; i++)
        {
            if (!d.ContainsKey(A[i])) d[A[i]] = 0;
            d[A[i]]++;
        }
        if (d.Keys.Count() % 2 == 1) Console.WriteLine(d.Keys.Count());
        else Console.WriteLine(d.Keys.Count() - 1);
    }
}

public class Input
{
    private static Queue<string> q = new Queue<string>();
    private static void Confirm() { if (q.Count == 0) foreach (var s in Console.ReadLine().Split(' ')) q.Enqueue(s); }
    public static int NextInt() { Confirm(); return int.Parse(q.Dequeue()); }
    public static long NextLong() { Confirm(); return long.Parse(q.Dequeue()); }
    public static char NextChar() { Confirm(); return char.Parse(q.Dequeue()); }
    public static string NextString() { Confirm(); return q.Dequeue(); }
    public static double NextDouble() { Confirm(); return double.Parse(q.Dequeue()); }
    public static int[] LineInt() { return Console.ReadLine().Split(' ').Select(int.Parse).ToArray(); }
    public static long[] LineLong() { return Console.ReadLine().Split(' ').Select(long.Parse).ToArray(); }
    public static string[] LineString() { return Console.ReadLine().Split(' ').ToArray(); }
    public static double[] LineDouble() { return Console.ReadLine().Split(' ').Select(double.Parse).ToArray(); }
}


Measured memory_bytes: 24288
#include<stdio.h>
#include<iostream>
#include<stdlib.h>
#include<math.h>
#include<stdbool.h>
#include<vector>
#include<algorithm>
#include<string>
typedef long long ll;
using namespace std;

int main(void) {
	int n, a;
	cin >> n >> a;
	cout << n*n - a << endl;
	return 0;
}

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

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

int main() {
    vector<vector<int>> c(3,vector<int> (3));
    rep(i,3){
        rep(j,3){
            cin >> c[i][j];
        }
    }
    
    rep(i,101){
        rep(j,101){
            rep(k,101){
                int b1 = c[0][0] - i;
                int b2 = c[0][1] - i;
                int b3 = c[0][2] - i;
                if(b1 == c[1][0] - j && b1 == c[2][0] - k && b2 == c[1][1] - j && b2 == c[2][1] - k && b3 == c[1][2] - j && b3 == c[2][2] - k){
                    cout << "Yes" << endl;
                    return 0;
                }
            }
        }
    }

    cout << "No" << endl;
    return 0;
}

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

int main(){
  long x,memo=100,ans=0; cin>>x;

  while(memo<x){
    memo=memo+memo/100;
    ans++;
  }
  
  cout<<ans<<endl;

}

Measured memory_bytes: 3632
/*
─────────────────────
───────────████████──
──────────███▄███████
──────────███████████
──────────███████████
──────────██████─────
──────────█████████──
█───────███████──────
██────████████████───
███──██████████──█───
███████████████──────
███████████████──────
─█████████████───────
──███████████────────
────████████─────────
─────███──██─────────
─────██────█─────────
─────█─────█─────────
─────██────██────────
─────────────────────
*/
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/detail/standard_policies.hpp>

#define int long long
#define read(a) int a; cin >> a;
#define readb(a, b) int a, b; cin >> a >> b;
#define readc(a, b, c) int a, b, c; cin >> a >> b >> c;
#define reads(s) string s; cin >> s;
#define readarr(a, n) int a[(n) + 1] = {}; fori (i, 1, (n)) {cin >> a[i];}
#define readmat(a, n, m) int a[n + 1][m + 1] = {}; fori (i, 1, n) {fori (j, 1, m) cin >> a[i][j];}

#define print(a) cout << a << endl;
#define printarr(a, n) fori (i, 1, n) cout << a[i] << " "; cout << endl;
#define printv(v) for (int i: v) cout << i << " "; cout << endl;
#define printmat(a, n, m) fori (i, 1, n) {fori (j, 1, m) cout << a[i][j] << " "; cout << endl;} cout << endl;
#define all(v) v.begin(), v.end()
#define sz(s) (int)(s.size())
#define pb push_back
#define fi first
#define se second
#define rz resize
#define fori(i, a, b) for (int i = (a); i <= (b); i++)
#define ford(i, a, b) for (int i = (a); i >= (b); i--)
#define endl '\n'
#define setprec(x) cout << fixed << setprecision(x)
 
using namespace std;
using namespace __gnu_pbds; 
 
typedef tree<long long,null_type,less<long long>,rb_tree_tag,tree_order_statistics_node_update> ordered_set;
typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef pair<int, int> pii;
typedef vector<pair <int, int>> vpi;
typedef vector < vector <int> > vvi;
 
const int INF = 4e18;
const int mod = 1e9+7; 

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


    //start from here

    readb(n, m); readarr(h, n);

    vvi adj(n+1);

    fori (i, 1, m)
    {
    	readb(x, y);
    	adj[x].pb(y);
    	adj[y].pb(x);
    }

    int cnt = 0;

    fori (i, 1, n)
    {
    	bool flag = true;
    	for (int x : adj[i])
    		if(h[x] >= h[i]) flag = false;

    	if(flag) cnt++;
    }

    cout << cnt;

    return 0;
}


Measured memory_bytes: 9760
import java.util.*;

@SuppressWarnings("unchecked")
class Main{

    void solve(){
        Scanner sc = new Scanner(System.in);

        int INF = Integer.MAX_VALUE/2;

        while(true){
            int w = sc.nextInt(), h = sc.nextInt();
            if(w==0 && h==0) break;
            ArrayList[] list = new ArrayList[5];
            for(int i=0; i<5; i++) list[i] = new ArrayList<int[]>();

            int sx = 0, sy = 0, gx = 0, gy = 0;
            for(int i=0; i<h; i++){
                char[] line = sc.next().toCharArray();
                for(int j=0; j<w; j++){
                    if(line[j]=='S'){ sx = j; sy = i;}
                    else if(line[j]=='G'){ gx = j; gy = i;}
                    else if(Character.isDigit(line[j])) list[line[j]-'1'].add(new int[]{j, i});
                }
            }

            int num = 0, min = INF;
            for(int start=0; start<5; start++){
                int[][] dp = new int[5][];
                int idx = (start+1) % 5;
                while(idx!=start){
                    dp[idx] = new int[list[idx].size()];
                    Arrays.fill(dp[idx], INF);
                    for(int j=0; j<list[idx].size(); j++){
                        int[] xy = (int[])list[idx].get(j);
                        if(idx==(start+1)%5){
                            dp[idx][j] = Math.min(dp[idx][j], Math.abs(sx - xy[0]) + Math.abs(sy - xy[1]));
                            continue;
                        }
                        int before = (idx+4) % 5;
                        for(int k=0; k<list[before].size(); k++){
                            int[] xy2 = (int[])list[before].get(k);
                            int dist = dp[before][k] + Math.abs(xy[0] - xy2[0]) + Math.abs(xy[1] - xy2[1]);
                            if((idx+1)%5==start){
                                dist += Math.abs(gx - xy[0]) + Math.abs(gy - xy[1]);
                                if(dist<min){
                                    min = dist;
                                    num = start+1;
                                }
                            }
                            dp[idx][j] = Math.min(dp[idx][j], dist);
                        }
                    }
                    idx = (idx + 1) % 5;
                }
            }
            if(min==INF) System.out.println("NA");
            else System.out.println(num+" "+min);
        }
    }

    public static void main(String[] args){
        new Main().solve();
    }
}

Measured memory_bytes: 72436
fun main() {
    val S = readLine()!!
    var max = 0
    var cnt = 0
    for (i in 0..2) {
        var t = S[i].toString()
        if (t == "R") {
            cnt ++
        } else {
            if (cnt > max) {
                max = cnt
            }
            cnt = 0
        }
    }
    if (cnt > max) {
        max = cnt
    }
    println(max)
}

Measured memory_bytes: 34472
A, B, N = map(int, input().split())
Ymax=0
if A*N < B:
  print(0)
elif N<B:
  Ymax = A*N // B
  print(Ymax)
else:
  x = B-1
  Ymax = A*x//B - A*(x//B)
  print(Ymax)

Measured memory_bytes: 9176
# encoding: utf-8
N = int(input())
A = list(map(int, input().split()))

def mydiff(a, b): return (a - b) if a > b else (b - a)


dist = mydiff(A[0], 0)
diffs = [0] * N
for i in range(N):
    if i == 0:
        diffs[i] =  mydiff(A[i], 0) + mydiff(A[i + 1], A[i]) - mydiff(A[i + 1], 0)
        dist += mydiff(A[i + 1], A[i])
    elif i == N - 1:
        diffs[i] =  mydiff(A[i], A[i - 1]) + mydiff(0, A[i]) - mydiff(0, A[i - 1])
    else:
        dist += mydiff(A[i + 1], A[i])
        diffs[i] =  mydiff(A[i], A[i - 1]) + mydiff(A[i + 1], A[i]) - mydiff(A[i + 1], A[i - 1])
dist += mydiff(0, A[-1])

for i in range(N): print(dist - diffs[i])

Measured memory_bytes: 14048
#include<iostream>
#include<cstdio>
const int N=305;
int n;
char s[N][N];
int main() {
    scanf("%d",&n);
    for(int i=0;i<n;i++) scanf("%s",s[i]);
    int ans=0;
    for(int k=0;k<n;k++) {
        bool f=true;
        for(int i=0;i<n;i++) for(int j=0;j<n;j++) f=f&&(s[(i+k)%n][j]==s[(j+k)%n][i]);
        ans+=f*n;
    }
    printf("%d\n",ans);
    return 0;
}


Measured memory_bytes: 384
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <numeric>
#include <cmath>

using namespace std;

int main(void) {
    int N, K;
    cin >> N >> K;
    vector<int> p(N);
    for(int i=0; i<N; i++) {
        cin >> p[i];
    }

    sort(p.begin(), p.end());
    cout << accumulate(p.begin(), p.begin()+K, 0) << endl;
    return 0;
}


Measured memory_bytes: 3628
n = gets.to_i
xys = n.times.map do
  a = gets.to_i
  a.times.map { gets.split.map(&:to_i) }
end

ans = 0

(1 << n).times do |bit|
  count = 0

  xys.each_with_index do |xy, i|
    next if bit[i] == 0

    if xy.all? { |x, y| bit[x - 1] == y }
      count += 1
    else
      count = 0
      break
    end
  end

  ans = count if count >= ans
end

puts ans


Measured memory_bytes: 1916
#include <cstdio>
#include <algorithm>
#include <string>

int main() {
    char buf[128];
    scanf("%s", buf);
    std::string w=buf;

    for (char c='a'; c<='z'; ++c) {
        if (std::count(w.begin(), w.end(), c) & 1)
            return !printf("No\n");
    }

    printf("Yes\n");
    return 0;
}


Measured memory_bytes: 256
#include <stdio.h>

void sort(int *a, int *b) {
  if (*a < *b) {
    *a += *b;
    *b = *a - *b;
    *a -= *b;
    return;
  } else {
    return;
  }
}

int GCD(int a, int b) {
  int j, i = 1;
  
  if (a == 1 || b == 1) {
    //printf("a = %d b = %d\n", a, b);
    return 1;
  }
  
  for (j = 2; j <= a; j++) {
    if (a % j == 0 && b % j == 0) {
      
      a /= j;
      b /= j;
      i *= j;
      
      //printf("j = %d i = %d a = %d b = %d\n", j, i, a, b);
      
      i *= GCD(a, b);
      
      break;
    }
  }
  
  return i;
}

int LCM(int a, int b, int c) {
  int i;
  
  if (a % b == 0) return a; 
  
  i = (a / c) * (b / c) * c;
  
  return i;
}

int main() {
  
  int a, b;
  int n, m;
  
  while (1) {
    if (scanf("%d %d", &a, &b) == EOF) break;
    
    
    sort(&a, &b);
    //printf("%d %d\n", a, b);
    
    n = GCD(a, b);
    
    m = LCM(a, b, n);
    
    //printf("n = %d, m = %ld\n", n, m);
    printf("%d %d\n", n, m);
  }
  return 0;
}

Measured memory_bytes: 0
#include<bits/stdc++.h>
using namespace std;
const int maxn=200005;
struct edge {
	int next,to,v;
} e[maxn];
int h[maxn],col[maxn],n,cnt;
void addedge(int x,int y,int z) {
	e[++cnt].next=h[x];
	e[cnt].to=y;
	e[cnt].v=z;
	h[x]=cnt;
}
void dfs(int u,int fa,int now) {
	//cout<<u<<' '<<fa<<' '<<now<<endl;
	col[u]=now;
	for(register int i=h[u]; i; i=e[i].next) {
		int j=e[i].to;
		if(j==fa) {
			continue;
		}
		dfs(j,u,e[i].v%2==1?(now^1):now);
	}
}
int main() {
	int x,y,z;
	scanf("%d",&n);
	for(register int i=1; i<n; i++) {
		scanf("%d%d%d",&x,&y,&z);
		addedge(x,y,z);
		addedge(y,x,z);
	}
	dfs(1,0,0);
	for(register int i=1; i<=n; i++) {
		printf("%d\n",col[i]);
	}
	return 0;
}

Measured memory_bytes: 9032
n = gets.chop.to_i
a = gets.chop.split.map(&:to_i)


def gcd(m,n)
  m,n = n,m % n while n > 0
  m
end

ans = 1000000000

n.times do |index|
  if index == 0 then
    ans = gcd(a[index], a[index+1])
  else
    ans = gcd(a[index], ans)
  end
end

puts ans


Measured memory_bytes: 9476
#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>;

bool isprime(int x) {
  bool flag = true;
  for (int i = 2; i < x; i++) {
    if (x % i == 0) flag = false;
  }
  return flag;
}

int main() {
  int x;
  cin >> x;
  while (!isprime(x)) x++;
  cout << x << endl;
  return 0;
}


Measured memory_bytes: 3604
#include<bits/stdc++.h>
#define mod 1000000007
#define ll long long int
#define ar array
#define mp make_pair
using namespace std;

int main()
{
	ios::sync_with_stdio(false);
	cin.tie(NULL);
	int a,b,c;
	cin>>a>>b>>c;
	if(a+c==2*b)
		cout<<"YES"<<endl;
	else
		cout<<"NO"<<endl;
	return 0;
}

Measured memory_bytes: 256