akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define rrep(i,n) for(int i=(int)(n-1);i>=0;i--)
#define FOR(i,n,m) for(int i=n;i<=(int)(m);i++)
#define RFOR(i,n,m) for(int i=(int)(n);i>=m;i--)
#define all(x) (x).begin(),(x).end()
#define sz(x) int(x.size())
typedef long long ll;
const int INF = 1e9;
const int MOD = 1e9+7;
const ll LINF = 1e18;
const double PI=3.14159265358979323846;
using namespace std;
vector<int> dy={1,0,-1,0};
vector<int> dx={0,1,0,-1};
template<class T>
vector<T> make_vec(size_t a){
    return vector<T>(a);
}
template<class T, class... Ts>
auto make_vec(size_t a, Ts... ts){
    return vector<decltype(make_vec<T>(ts...))>(a, make_vec<T>(ts...));
}

int n,m;
vector<vector<int>> graph;

vector<int> bfs(int s) {
    vector<int> d(3*n,INF);
    queue<int> q;
    
    q.push(s);
    d[s]=0;
    
    while(sz(q)) {
        int now=q.front(); q.pop();
        for(int x:graph[now]) {
            if(d[x]!=INF) continue;
            q.push(x);
            d[x]=d[now]+1;
        }
    }
    
    return d;
}

int main() {
    cin>>n>>m;
    graph.resize(3*n);
    rep(i,m) {
        int u,v;
        cin>>u>>v;
        u--;v--;
        graph[3*u].push_back(3*v+1);
        graph[3*u+1].push_back(3*v+2);
        graph[3*u+2].push_back(3*v);
    }
    
    int s,t;
    cin>>s>>t;
    s--;t--;
    
    auto d = bfs(3*s);
    cout<<(d[3*t]==INF ? -1 : d[3*t]/3)<<endl;
}


Measured memory_bytes: 17792
#include "bits/stdc++.h"
using namespace std;
#define long int64_t

struct Solver {
	Solver() {
		ios::sync_with_stdio( false );
	}

	void solve() {
		long a, b, c;
		cin >> a >> b >> c;

		long x = c - a - b;
		cout << (x > 0 && x*x > 4*a*b ? "Yes" : "No") << endl;
	}
};

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


Measured memory_bytes: 256
#include<iostream>
#include<iomanip>
#include<string>
#include<algorithm>
#include<cmath>
#include<vector>
using namespace std;
int main(){
    int n,m,sum=0;
    cin>>n;
    int t[n];
    for(int i=0;i<n;i++){
        cin>>t[i];
        sum+=t[i];
    }
    cin>>m;
    int p[m],x[m];
    for(int i=0;i<m;i++) cin>>p[i]>>x[i];
    for(int i=0;i<m;i++){
        cout<<sum-(t[p[i]-1]-x[i])<<endl;
    }
    
    return 0;
}

Measured memory_bytes: 256
//Achen
#include<algorithm>
#include<iostream>
#include<cstring>
#include<cstdlib>
#include<cstdio>
#include<vector>
#include<cmath>
#include<queue>
#include<ctime>
#include<set>
#define For(i,a,b) for(register int i=(a);i<=(b);i++)
#define Rep(i,a,b) for(register int i=(a);i>=(b);i--)
#define Formylove return 0
const int N=2e5+7;
typedef long long LL;
typedef double db;
using namespace std;
int n,m,k,ans;

template<typename T> void read(T &x) {
    char ch=getchar(); T f=1; x=0;
    while(ch!='-'&&(ch<'0'||ch>'9')) ch=getchar();
    if(ch=='-') f=-1,ch=getchar();
    for(;ch>='0'&&ch<='9';ch=getchar()) x=x*10+ch-'0'; x*=f;
}

struct node {
	int x,y;
	friend bool operator <(const node&A,const node&B) {
		return A.x<B.x||(A.x==B.x&&A.y<B.y);
	}
}p[N];

int main() {
	//freopen("1.in","r",stdin);
	read(n); read(m); read(k);
	For(i,1,k) {
		read(p[i].x); 
		read(p[i].y);
	}
	sort(p+1,p+k+1);
	int bsx=0,bsy=0;
	ans=n;
	For(i,1,k) {
		if(p[i].x-bsx>p[i].y-bsy) {
			ans=min(ans,p[i].x-1); break;
		}
		if(p[i].x-bsx==p[i].y-bsy) 	bsx++;
	}
	printf("%d\n",ans);
   	Formylove;
}


Measured memory_bytes: 1792
#include<bits/stdc++.h>
using namespace std;
#define F first
#define S second
typedef long long ll;
const ll maxn = 1e5+100,mod = 1e9+7,INF = 1ll<<62;
int main(){
	ll a[3];
	cin>>a[0]>>a[1]>>a[2];
	if(a[0]==a[1]){
		cout<<a[2];
		return 0;
	}
	if(a[1]==a[2]){
		cout<<a[0];
		return 0;
	}
	if(a[0]==a[2]){
		cout<<a[1];
		return 0;
	}
}


Measured memory_bytes: 256
#include <stdio.h>
#include <math.h>

int main(void){
    int x,y,z;
    char op;
    
    while(1){
        scanf("%d %c %d\n",&x,&op,&y);
        if(op == '+'){
            z = x + y;
        }else if(op == '-'){
            z = x - y;
        }else if(op == '*'){
            z = x * y;
        }else if(op == '/'){
            z = x / y;
        }else{
            break;
        }
        printf("%d\n",z);
    }
    
    return 0;
}

Measured memory_bytes: 1792
#include <iostream>
#include <iomanip>
#include <ios> 
#include <vector>
#include <string>
#include <algorithm>
#include <functional>
#include <queue>
#include <stack>
#include <set>
#include <cmath>
#include <bitset>
#include <map>
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define rep1(i,n) for(int i=1;i<=(int)(n);i++)
#define sz(c) ((int)(c).size())

using namespace std;
typedef long long ll;
typedef vector<int> vi;
//const int MAX=1;

int main(){
	int N;
	cin>>N;
	double ans=0;
	rep(i,N){
		double x;
		string S;
		cin>>x>>S;
		if(S[0]=='J')ans+=x;
		else ans+=x*380000.0;
	}
	cout<<ans;
}

Measured memory_bytes: 256
from collections import Counter
from heapq import heappop,heappush

N = int(input())
V = list(map(int, input().split()))
odd = Counter(V[::2])
odd[10**6] = 0
even = Counter(V[1::2])
even[10**6] = 0
heapodd = []
heapeven = []
for k,v in odd.items():
    heappush(heapodd,(-v,k))
for k,v in even.items():
    heappush(heapeven,(-v,k))

vo1,odd1 = heappop(heapodd)
vo2,odd2 = heappop(heapodd)
ve1,even1 = heappop(heapeven)
ve2,even2 = heappop(heapeven)

if odd1 != even1:
  print(N + vo1 + ve1)
else:
  print(min(N+ve1+vo2,N+vo1+ve2))

Measured memory_bytes: 101896
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
		         int line []= new int [N];
		         double tos=0.0;

				 for(int i=0;i<N;i++) {
				 line[i]  =sc.nextInt();

				 tos+=(double)1/line[i];

				 }

		System.out.println(1/tos);



	}



}

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

#define ll long long
#define ar array

int main(){
    ios::sync_with_stdio(0);
    cin.tie(0);
    int x, ans = 0;
    cin >> x;
    if (x/500){
        ans += (x/500)*1000, x -= (x/500)*500;
    }
    if (x/5){
        ans += (x/5)*5, x -= (x/5)*5;
    }

    cout << ans;


}

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

int main(void){
    int w, h, n;
    cin >> w >> h >> n;
    
    int x, y, a;
    bool g[100][100] = {{false}};
    int i, j, k;
    for(i = 1; i <= n; i++){
        cin >> x >> y >> a;
        if(a == 1){
            for(j = 0; j < h; j++){
                for(k = 0; k < x; k++){
                    g[j][k] = true;
                }
            }
        }else if(a == 2){
            for(j = 0; j < h; j++){
                for(k = x; k < w; k++){
                    g[j][k] = true;
                }
            }
        }else if(a == 3){
            for(j = h - 1; j >= h - y; j--){
                for(k = 0; k < w; k++){
                    g[j][k] = true;
                }
            }
        }else{
            for(j = h - y - 1; j >= 0; j--){
                for(k = 0; k < w; k++){
                    g[j][k] = true;
                }
            }
        }
    }
    
    
    int cnt = 0;
    for(i = 0; i < h; i++){
        for(j = 0; j < w; j++){
            if(g[i][j]){
                cnt++;
            }
        }
    }
    
    cout << h * w - cnt << endl;
    
    return 0;
}


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

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

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

const int inf = 1000000007;
const int MOD = 1000000007;
const long long INF = 1000000000000000007;

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

ll A, B, Q;
ll s[101010], t[101010], x[101010];

ll solve(ll x)
{
    auto esi = upper_bound(s, s + A + 2, x);
    auto eti = upper_bound(t, t + B + 2, x);
    ll res = INF;
    for (int i = 0; i <= 1; i++)
    {
        for (int j = 0; j <= 1; j++)
        {
            ll shrine = s[esi - s - i];
            ll temple = t[eti - t - j];
            ll a = abs(shrine - x) + abs(temple - shrine);
            ll b = abs(temple - x) + abs(shrine - temple);
            chmin(res, a);
            chmin(res, b);
        }
    }
    return res;
}

int main()
{
    cin >> A >> B >> Q;
    s[0] = -INF;
    repe(i, 1, A)
    {
        cin >> s[i];
    }
    s[A + 1] = INF;
    t[0] = -INF;
    repe(i, 1, B)
    {
        cin >> t[i];
    }
    t[B + 1] = INF;
    rep(i, 0, Q)
    {
        cin >> x[i];
    }
    rep(i, 0, Q)
    {
        cout << solve(x[i]) << endl;
    }
}


Measured memory_bytes: 3712
import fractions
n=int(input())
a=list(map(int,input().split()))

l=[0]*(n+1)
r=[0]*(n+1)
for i in range(n):
  l[i+1]=fractions.gcd(l[i],a[i])
for i in reversed(range(n)):
  r[i]=fractions.gcd(r[i+1],a[i])

A=[fractions.gcd(l[i],r[i+1]) for i in range(n)]
print(max(A))

Measured memory_bytes: 16112
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define space " "
#define MOD (long long) 1000000007
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename T> void __f(const char* variable_name, T&& value){cout << variable_name << ": " << value << endl;}
template <typename T1, typename... T2> void __f(const char* names, T1&& arg1, T2&&... args){const char* comma = strchr(names + 1, ',');cout.write(names, comma - names) << ": " << arg1 << " |";__f(comma + 1, args...);}

const ll N = 2e3 + 5;
vector<ll> gph[N];
ll n, x, y;

void solve(){
    cin >> n >> x >> y;
    for(int i = 1; i <= n - 1; i++){
        gph[i].push_back(i+1);
        gph[i+1].push_back(i);
    }
    gph[x].push_back(y);
    gph[y].push_back(x);
    unordered_map<ll, ll> m;
    for(int src = 1; src <= n - 1; src++){
        vector<bool> vis(n, false);
        queue<ll> q;
        q.push(src);
        q.push(0);
        vis[src] = true;
        ll dist = 1;
        while(!q.empty()){
            ll u = q.front();
            // trace(u, dist);
            q.pop();
            if(!u){
                dist++;
                if(q.size() != 0)
                    q.push(0);
                continue;
            }
            for(auto v : gph[u]){
                if(!vis[v]){
                    // trace(u, v, dist);
                    if(src < v){
                        m[dist]++;
                    }
                    q.push(v);
                    vis[v] = true;
                }
            }
        }
    }
    for(int i = 1; i <= n - 1; i++)
        cout << m[i] << endl;
}

int main(){
    ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
    ll t = 1;
    // cout << "\n\nBLAH BLAH BLAH\n\n";
    // cin >> t;
    while(t--){
        solve();
    }
    return 0;
}

Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
double PI=3.14159265358979323846264338327950L;
int main()
{
	int a,b,h,m;
	cin>>a>>b>>h>>m;
	double ah=(PI/6.0)*h+((PI/6.0)/60.0)*m;
	double am=(PI/30.0)*m;
	double theta=abs(ah-am);
	// double x=b*cos(theta);
	// double y=b*sin(theta);
	// cout<<x<<" "<<y<<endl;
	// cout<<theta*180/PI<<endl;
	// x=(x-a);
	// cout<<x<<" "<<y<<endl;
	// cout<<setprecision(20)<<sqrt(x*x+y*y)<<endl;

	cout<<setprecision(20)<<sqrt(a*a+b*b-2*a*b*cos(theta))<<endl;
	return 0;
}

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

int main(){
  int n,x,t; cin >> n >> x >> t;
  int p = n/x;
  int v = n%x;
  if(v == 0)cout << p * t;
  else{
    cout << (p+1) * t;
  }
  cout << endl;
  return 0;
}

Measured memory_bytes: 3628
#include<bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define pb push_back
#define mp make_pair
#define IOS ios_base::sync_with_stdio(false),cin.tie(0);
#define F first
#define S second
using namespace std;
typedef long long ll;
ll a,b,c,d;
const ll maxn=200005;
const ll mod=1e9+7;
typedef pair<ll,ll> pii;
ll num[100005];
ll n,k,x,y;
string s;
int main()
{
    //IOS
    while(cin>>a>>b>>c>>d)
    {
        ll ansb,ansa;
        a--;
        ansb=b;ansa=a;
        ansb-=b/c+b/d;
        //cout<<ansb<<"\n";
        ll tmp=c*d/__gcd(c,d);
        ansb+=b/tmp;
        //cout<<ansb<<"\n";
        ansa-=a/c+a/d;
        //cout<<ansa<<"\n";
        ansa+=a/tmp;
        //cout<<ansa<<"\n";
        cout<<ansb-ansa<<"\n";
    }


}


Measured memory_bytes: 256
#include <bits/stdc++.h>
const int INF=1e9,MOD=1e9+7;
const long long LINF=1e18;
using namespace std;
#define int long long
//template
int dp[3005][3005];
//main
signed main(){
  int N;string s;cin>>N>>s;
  memset(dp,0,sizeof(dp));
  for(int i=0;i<N;i++)dp[0][i+1]=1;
  for(int i=0;i<N-1;i++){
    if(s[i]=='<'){
      for(int j=0;j<N;j++){dp[i][j+1]+=dp[i][j];dp[i][j+1]%=MOD;}
      for(int k=0;k<N;k++)dp[i+1][k+1]=(dp[i][N]-dp[i][k+1]+MOD)%MOD;
      /*
      for(int j=0;j<N;j++){
        for(int k=0;k<j;k++){
          dp[i+1][k]+=dp[i][j];
          dp[i+1][k]%=MOD;
        }
      }
      */
    }
    else{
      for(int j=0;j<N;j++){dp[i][j+1]+=dp[i][j];dp[i][j+1]%=MOD;}
      for(int k=0;k<=N-i-2;k++)dp[i+1][k+1]=(dp[i][k+1]-dp[i][0]+MOD)%MOD;
      /*
      for(int j=0;j<N;j++){
        for(int k=0;k<N-(i-1)-j-2;k++){
          dp[i+1][j+k]+=dp[i][j];
          dp[i+1][j+k]%=MOD;
        }
      }
      */
    }
  }
  cout<<dp[N-1][0+1]<<endl;
}


Measured memory_bytes: 70784
from collections import deque

def main():
    n = int(input())
    adj = [[]for i in range(n+1)]
    ab = [list(map(int, input().split())) for i in range(n-1)]
    for a, b in ab:
        adj[a].append(b)
        adj[b].append(a)
    # dequeを使ったキューによるBFS
    # 子をindexで、親ノードを要素で
    # 今回は彩色のためにどんな順番でpopされたかも保持しておく
    order  = []
    parent = [None] * (n+1)
    q = deque([1])
    while q:
        par = q.popleft()
        order.append(par)
        for chl in adj[par]:
            if chl == parent[par]:
                continue
            parent[chl] = par
            q.append(chl)
    # 彩色
    # 親と同じにならないように若い番号を割り当てて行く
    cl = [None] * (n+1)
    for par in order:
        # 親の色
        pc = cl[par]
        # 彩色は1以上k以下
        color = 1
        for chl in adj[par]:
            # 隣接リストの親は無視
            if chl == parent[par]:
                continue
            # 親の色と同じなら色を変える
            if pc == color:
                color += 1
            # カラーリストに子indexにcolorを入れる
            cl[chl] = color
            #　他の子は色を変える必要がある
            color += 1
    # 木グラフなので単純に次数最大で考えて問題ない
    g = max([len(i) for i in adj]) 
    print(g)   
    for a, b in ab:
        # 親子関係が逆転しない出力ならこれでいいがそうとも限らない 
        if parent[a] != b:
            print(cl[b])
        else:
            print(cl[a])    
    
if __name__ == '__main__':
    main()

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

using namespace std;

typedef long long LL;
typedef pair< int, int > P;
typedef pair< LL, LL > LP;
typedef pair< int, P > iP;
typedef pair< P, P > PP;

static const int INF = INT_MAX;
static const LL LINF = LLONG_MAX;
static const int MIN = INT_MIN;
static const LL LMIN = LLONG_MIN;
static const int MOD = 1000000007;

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

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    
    int h, w;
    cin >> h >> w;
    string s[h];
    for( int i = 0; i < h; ++i ) {
        cin >> s[i];

    }

    for( int i = 0; i < h; ++i ) {
        cout << s[i] << endl << s[i] << endl;

    }

    return 0;
}


Measured memory_bytes: 256
#pragma GCC optimize("O3")
#include <bits/stdc++.h>
using namespace std;

//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_policy.hpp>
//using namespace __gnu_pbds;

//template<class T> using oset=tree<T,null_type,less<T>,rb_tree_tag,tree_order_statistics_node_update>;
//template<class T> using omultiset=tree<T,null_type,less_equal<T>,rb_tree_tag,tree_order_statistics_node_update>;

//find_by_order
//order_of_key

#define f first
#define s second
#define pb push_back
#define all(a) a.begin(),a.end()

typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef vector<ll> vl;
typedef vector<int> vi;
typedef vector<bool> vb;
typedef vector<vi> vvi;
typedef vector<vl> vvl;
typedef vector<pii> vii;
typedef vector<pll> vll;

ll a,b,c,d;
map<ll,ll> ans;

ll solve(ll n) {
    if (ans.find(n) != ans.end())
        return ans[n];
    if (!n)
        return 0;
    if (n == 1)
        return d;
    ll mn=1e18;
    if (n <= mn/d)
        mn=d*n;
    if (n%2 == 0)
        mn=min(mn,solve(n/2)+a);
    else {
        mn=min(mn,d*(n%2)+a+solve(n/2));
        mn=min(mn,d*(2-n%2)+a+solve(1+n/2));
    }
    if (n%3 == 0)
        mn=min(mn,solve(n/3)+b);
    else {
        mn=min(mn,d*(n%3)+b+solve(n/3));
        mn=min(mn,d*(3-n%3)+b+solve(1+n/3));
    }
    if (n%5 == 0)
        mn=min(mn,solve(n/5)+c);
    else {
        mn=min(mn,d*(n%5)+c+solve(n/5));
        mn=min(mn,d*(5-n%5)+c+solve(1+n/5));
    }
    ans[n]=mn;
    return mn;
}



int main() {
    ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
    int t; cin >> t;
    while(t--) {
        ans.clear();
        ll n;
        cin >> n >> a >> b >> c >> d;
        cout << solve(n) << "\n";
    }
}


Measured memory_bytes: 4348
#include <bits/stdc++.h>
using namespace std;
using lint = long long;
const lint mod = 1e9 + 7;
#define all(x) (x).begin(), (x).end()
#define bitcount(n) __builtin_popcountl((lint)(n))
#define fcout cout << fixed << setprecision(15)
#define highest(x) (63 - __builtin_clzl(x))
template<class T> inline void YES(T condition){ if(condition) cout << "YES" << endl; else cout << "NO" << endl; }
template<class T> inline void Yes(T condition){ if(condition) cout << "Yes" << endl; else cout << "No" << endl; }
template<class T = string, class U = char>int character_count(T text, U character){ int ans = 0; for(U i: text){ ans += (i == character); } return ans; }
lint power(lint base, lint exponent, lint module){ if(exponent % 2){ return power(base, exponent - 1, module) * base % module; }else if(exponent){ lint root_ans = power(base, exponent / 2, module); return root_ans * root_ans % module; }else{ return 1; }}
struct position{ int y, x; }; position mv[4] = {{0, -1}, {1, 0}, {0, 1}, {-1, 0}}; // double euclidean(position first, position second){ return sqrt((second.x - first.x) * (second.x - first.x) + (second.y - first.y) * (second.y - first.y)); }
template<class T, class U> string to_string(pair<T, U> x){ return to_string(x.first) + "," + to_string(x.second); } string to_string(string x){ return x; }
template<class itr> void array_output(itr start, itr goal){ string ans; for(auto i = start; i != goal; i++) ans += to_string(*i) + " "; if(!ans.empty()) ans.pop_back(); cout << ans << endl; }
template<class itr> void cins(itr first, itr last){ for(auto i = first; i != last; i++){ cin >> (*i); } }
template<class T> T gcd(T a, T b){ if(a && b){ return gcd(min(a, b), max(a, b) % min(a, b)); }else{ return a; }} template<class T> T lcm(T a, T b){ return a / gcd(a, b) * b; }
struct combination{ vector<lint> fact, inv; combination(int sz) : fact(sz + 1), inv(sz + 1){ fact[0] = 1; for(int i = 1; i <= sz; i++){ fact[i] = fact[i - 1] * i % mod; } inv[sz] = power(fact[sz], mod - 2, mod); for(int i = sz - 1; i >= 0; i--){ inv[i] = inv[i + 1] * (i + 1) % mod; } } lint C(int p, int q) const{ if(q < 0 || p < q) return 0; return (fact[p] * inv[q] % mod * inv[p - q] % mod); } };
template<class itr> bool next_sequence(itr first, itr last, int max_bound){ itr now = last; while(now != first){ now--; (*now)++; if((*now) == max_bound){ (*now) = 0; }else{ return true; } } return false; }

int main(){
    string S;
    cin >> S;
    if(S == "Sunny"){
        cout << "Cloudy" << endl;
    }else if(S == "Cloudy"){
        cout << "Rainy" << endl;
    }else{
        cout << "Sunny" << endl;
    }
}

Measured memory_bytes: 256
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <stdbool.h>

int main()
{
    int n, k, l[50];
    scanf("%d%d", &n, &k);
    int i, j, tmp = 0;
    int ans = 0;
    for (i=0; i<n; i++)
    {
        scanf("%d", &l[i]);
    }
    for (i=n-2; i>=0; i--)
    {
        for (j=0; j<=i; j++)
        {
            if(l[j] > l[j+1]) {
                tmp = l[j+1];
                l[j+1] = l[j];
                l[j] = tmp;
            }
        }
    }
    for (i=n-1; i>=n-1-(k-1); i--)
    {
        ans += l[i];
    }
    printf("%d\n", ans);
    return 0;
}


Measured memory_bytes: 128
#include <iostream>
#include <iomanip>
#include <vector>
#include <algorithm>
#include <numeric>
#include <functional>
#include <cmath>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <sstream>
#include <string>
#define repd(i,a,b) for (int i=(int)(a);i<(int)(b);i++)
#define rep(i,n) repd(i,0,n)
#define all(x) (x).begin(),(x).end()
#define mod 1000000007
#define inf 2000000007
#define mp make_pair
#define pb push_back
typedef long long ll;
using namespace std;
template <typename T>
inline void output(T a, int p) {
    if(p) cout << fixed << setprecision(p)  << a << "\n";
    else cout << a << "\n";
}
// end of template

int main() {
    cin.tie(0);
    ios::sync_with_stdio(0);
    // source code]
    string s;
    cin >> s;
    vector<int> cnt(4, 0);
    rep(i, s.size()){
        if(s[i] == 'N') cnt[0] = 1;
        if(s[i] == 'S') cnt[1] = 1;
        if(s[i] == 'E') cnt[2] = 1;
        if(s[i] == 'W') cnt[3] = 1;
    }
    if((cnt[0] + cnt[1]) % 2 == 0 && (cnt[2] + cnt[3]) % 2 == 0){
        output("Yes", 0);
    }
    else{
        output("No", 0);
    }
    
    return 0;
}

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

#define pb push_back
#define ll long long int
#define mod 100000
#define for1(k,n) for(ll i=k;i<n;i++)
#define for2(k,n) for(ll j=k;j<n;j++)
#define E cout<<endl
#define max 100000




int main()
{
#ifndef ONLINE_JUDGE
	clock_t tStart = clock();
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif
	ios_base:: sync_with_stdio(false);
	cin.tie(0);
//////////////////////////////////////start...............

	int n, data;
	vector <int> vec;

	cin >> n;
	for1(0, n)
	{
		cin >> data;
		vec.pb(data);
	}
	int xmin = *min_element(vec.begin(), vec.end());
	int xmax = *max_element(vec.begin(), vec.end());

	//cout << xmin << " " << xmax << endl;
	ll ans = 99999999999; ll sum;
	for (int j = xmin; j <= xmax; j++) {
		sum = 0;
		int s;
		for1(0, n)
		{	s = vec[i] - j;
			sum = sum + (s * s);

		}
		if (sum < ans)
			ans = sum;
	}



	cout << ans;


/////////////////////////////end.......................................
#ifndef ONLINE_JUDGE
	cout << "\nDone in " << (double) clock() / CLOCKS_PER_SEC << "sec" << endl;
#endif
	return 0;

}

//c v a s selecting text or x for selecting cut
//ctrl+d after selecting text to select same type
//ctrl+shift+d for copy and paste the line below it
//ctrl+del to delete a text
//ctrl+left to jump left of line or vice versa
//ctrl+shift+"/"  to comment whole block and vice versa for undo
//ctrl+"/" for commenting a line

/*
when N <= 10, then both O(N!) and O(2N) are ok (for 2N probably N <= 20 is ok too)
when N <= 100, then O(N3) is ok (I guess that N4 is also ok, but never tried)
when N <= 1.000, then N2 is also ok
when N <= 1.000.000, then O(N) is fine (I guess that 10.000.000 is fine too, but I never tried in contest)
finally when N = 1.000.000.000 then O(N) is NOT ok, you have to find something better…*/

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

typedef long long   signed int LL;
typedef long long unsigned int LU;

#define incID(i, l, r) for(int i = (l)    ; i <  (r); i++)
#define incII(i, l, r) for(int i = (l)    ; i <= (r); i++)
#define decID(i, l, r) for(int i = (r) - 1; i >= (l); i--)
#define decII(i, l, r) for(int i = (r)    ; i >= (l); i--)
#define  inc(i, n) incID(i, 0, n)
#define inc1(i, n) incII(i, 1, n)
#define  dec(i, n) decID(i, 0, n)
#define dec1(i, n) decII(i, 1, n)

#define inII(v, l, r) ((l) <= (v) && (v) <= (r))
#define inID(v, l, r) ((l) <= (v) && (v) <  (r))

#define PB push_back
#define EB emplace_back
#define MP make_pair
#define FI first
#define SE second
#define PQ priority_queue

#define  ALL(v)  v.begin(),  v.end()
#define RALL(v) v.rbegin(), v.rend()
#define  FOR(it, v) for(auto it =  v.begin(); it !=  v.end(); ++it)
#define RFOR(it, v) for(auto it = v.rbegin(); it != v.rend(); ++it)

template<typename T> bool   setmin(T & a, T b) { if(b <  a) { a = b; return true; } else { return false; } }
template<typename T> bool   setmax(T & a, T b) { if(b >  a) { a = b; return true; } else { return false; } }
template<typename T> bool setmineq(T & a, T b) { if(b <= a) { a = b; return true; } else { return false; } }
template<typename T> bool setmaxeq(T & a, T b) { if(b >= a) { a = b; return true; } else { return false; } }
template<typename T> T gcd(T a, T b) { return (b == 0 ? a : gcd(b, a % b)); }
template<typename T> T lcm(T a, T b) { return a / gcd(a, b) * b; }

// ---- ----

int x, y, z;

int main() {
	cin >> x >> y >> z;
	
	cout << (x - z) / (y + z) << endl;
	
	return 0;
}


Measured memory_bytes: 256
var lines = [];
var readline = require('readline');

var rl = readline.createInterface({
    input: process.stdin,
    output: process.stdout,
});

rl.on('line', function (x) {
    lines.push(x);
});

rl.on('close', function () {
    var N = Number(lines[0]);

    var D = Number(lines[1].split(" ")[0])
    var X = Number(lines[1].split(" ")[1])
    lines.shift(); lines.shift();

    var A = lines.map(i => Number(i));
    var ans = X;

    for (var i = 0; i < N; i++) {
        var d = 1; var k = 1;
        while (d <= D) {
            ans += 1;
            d = A[i] * k + 1;
            k++;
        }
    }
    console.log(ans)
});

Measured memory_bytes: 20936
import java.io.*;
import java.util.*;
public class Main {
	public static void main(String[] args) throws Exception {
		MScanner sc=new MScanner(System.in);
		PrintWriter pw=new PrintWriter(System.out);
		int n=sc.nextInt();
		int[]a=sc.takearr(n);
		int[]b=sc.takearr(n);
		int[]aa=new int[n],bb=new int[n];
		for(int i=0;i<n;i++) {
			aa[i]=a[i]^a[(i+1)%n];
			bb[i]=b[i]^b[(i+1)%n];
		}
		boolean yes=true;
		int i=0;
		while(i<n && bb[0]!=aa[i])i++;
		if(i<n) {
			for(int j=0;j<n;j++) {
				if(bb[j]!=aa[i%n]) {
					yes=false;break;
				}
				i++;
			}
		}
		else {
			yes=false;
		}
		if(yes) {
			for(int o=0;o<n;o++) {
				if(aa[o]==bb[0]) {
					pw.println(o+" "+(a[o]^b[0]));
				}
			}
		}
		
		pw.flush();
	}
	static class MScanner {
		StringTokenizer st;
		BufferedReader br;
		public MScanner(InputStream system) {
			br = new BufferedReader(new InputStreamReader(system));
		}
 
		public MScanner(String file) throws Exception {
			br = new BufferedReader(new FileReader(file));
		}
 
		public String next() throws IOException {
			while (st == null || !st.hasMoreTokens())
				st = new StringTokenizer(br.readLine());
			return st.nextToken();
		}
		public int[] takearr(int n) throws IOException {
	        int[]in=new int[n];for(int i=0;i<n;i++)in[i]=nextInt();
	        return in;
		}
		public long[] takearrl(int n) throws IOException {
	        long[]in=new long[n];for(int i=0;i<n;i++)in[i]=nextLong();
	        return in;
		}
		public Integer[] takearrobj(int n) throws IOException {
	        Integer[]in=new Integer[n];for(int i=0;i<n;i++)in[i]=nextInt();
	        return in;
		}
		public Long[] takearrlobj(int n) throws IOException {
	        Long[]in=new Long[n];for(int i=0;i<n;i++)in[i]=nextLong();
	        return in;
		}
		public String nextLine() throws IOException {
			return br.readLine();
		}
 
		public int nextInt() throws IOException {
			return Integer.parseInt(next());
		}
 
		public double nextDouble() throws IOException {
			return Double.parseDouble(next());
		}
 
		public char nextChar() throws IOException {
			return next().charAt(0);
		}
 
		public Long nextLong() throws IOException {
			return Long.parseLong(next());
		}
 
		public boolean ready() throws IOException {
			return br.ready();
		}
 
		public void waitForInput() throws InterruptedException {
			Thread.sleep(3000);
		}
	}
}


Measured memory_bytes: 70692
#include <bits/stdc++.h>
#define FAST ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
typedef long long ll;
typedef long double ld;
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define mod 1000000007
#define inf 1000000000000000000
#define autoit(x,it) for(auto it = x.begin(); it != x.end(); it++)
#define rep(n) for(ll i = 0; i < n; i++)
#define repi(i,n) for(ll i = 0; i < n; i++)

#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp> 
using namespace __gnu_pbds; 

#define ordered_set tree<pair<ll,ll>, null_type,less<pair<ll,ll>>, rb_tree_tag,tree_order_statistics_node_update> 

using namespace std;

int main()
{
   FAST/**/
   
   string s;
   cin>>s;
   
   ll n = s.length();
   vector<ll> v;
   rep(n)
        v.pb(s[i]-'0');
   ll dp[n][2];
   rep(n)
        repi(j,2)
            dp[i][j] = inf;
   for(ll j=0;j<10;j++)
   {
       if(j<v.back())
           dp[n-1][0] = min(dp[n-1][0],2*j+10-v.back());
       
       else
       {
           //dp[n-1][0] = min(dp[n-1][0],2*j-v.back());
           dp[n-1][1] = min(dp[n-1][1],2*j-v.back());           
           
       }
   }
   
   for(ll i=n-2;i>-1;i--)
   {
       for(ll j=0;j<10;j++)
       {
           if(j<v[i])
               dp[i][0] = min({dp[i][0],dp[i+1][0]+2*j+9-v[i],dp[i+1][1]+2*j+10-v[i]});
           else if(j == v[i])
           {
               dp[i][0] = min({dp[i][0],dp[i+1][0]+2*j+9-v[i]});
               dp[i][1] = min(dp[i+1][1] + j,dp[i][1]);
           }
           else
           {
               dp[i][1] = min({dp[i][1],dp[i+1][0]+j+j-1-v[i],dp[i+1][1]+j+j-1-v[i]});
           }
       }
   }
   
   ll ans = min(dp[0][1],dp[0][0]+1);
   cout<<ans;
   
   return 0;        
}  
   

Measured memory_bytes: 25872
#include<bits/stdc++.h>
 
#define ll long long 
# define skorost ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL) 

using namespace std ;
 
ll z , o , ans ;

ll N = 1e4 + 15820 ;

int main(){ skorost ;

	int n , m ;

	cin >> n >> m ;

	n -- ;

	n = ( n * ( n + 1 ) ) / 2 ;

	m -- ;

	m = ( ( m ) * ( m + 1 ) / 2 ) ;

	cout << n + m << endl ;	

}

Measured memory_bytes: 256
#pragma GCC optimize("Ofast")
#pragma comment(linker, "/stack:200000000")
#include "bits/stdc++.h"
#define ll long long
#define pb push_back
#define fr first
#define sc second
using namespace std;

const int mnx = 2e6 + 9;
const int mod = 1e9 + 7;
const ll inf = 1e15 + 4;

ll n, a[mnx], k;

void solve(){
	cin >> n;

	if(n == 3){
		cout << "2 5 63\n";
		return;
	}

	if(n == 4){
		cout << "2 3 4 9\n";
		return;
	}

	for(int i = 1; i <= 30000; i++){
		if(i % 2 == 0 || i % 3 == 0 || i % 5 == 0 || i % 7 == 0){
			a[++k] = i;
		}
	}

	while(true){
		random_shuffle(a + 1, a + k + 1);

		ll sum = a[1], gcd = a[1];

		for(int i = 2; i <= n; i++){
			sum += a[i];
			gcd = __gcd(gcd, a[i]);
		}

		if(sum % 210 != 0) continue;
		if(gcd != 1) continue;

		for(int i = 1; i <= n; i++){
			cout << a[i] << ' ';
		}
		return;
	}
}

int main(){
//    ios_base::sync_with_stdio(0);
//    cin.tie(0), cout.tie(0);
//	srand(time(0));
    int tt = 1;
//    cin >> tt;
    while(tt--){
        solve();
    }
    return 0;
}

/**

14 8
1 1 1 1 1 4 2 7 3 3 3 3 3 3

6 8
8 2 8 3 6 7
1
5
1 7 6 5 4
**/

























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

using namespace std;

#define ll long long;

int main()
{
    int a, b, k;
    cin >> a >> b >> k;

    int n = 1;

    vector<int> v;
    while( n <= a && n <= b)
    {
        if( a % n == 0   && b % n == 0)v.push_back(n);
        n++;
    }
    sort(v.begin(), v.end());
    reverse(v.begin(), v.end());

    cout << v[k-1] << endl;

    return 0;
}



Measured memory_bytes: 256
#include <iostream>
#include <math.h>
#include <numeric>
#include <vector>
#include <algorithm>

using namespace std;
#define n_max 100000
#define N_max 100


int main()
{
    int W, H, N; 
    int x[N_max], y[N_max], a[N_max];
    int l[2] = {0, N}, r[2] = {0, N};

    cin >> W >> H >> N;

    l[1] = W; 
    r[1] = H; 

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

    for(int i = 0; i < N; i ++) {
        if(a[i] == 1 && l[0] < x[i]) {
            l[0] = x[i];
        } else if (a[i] == 2 && l[1] > x[i]) {
            l[1] = x[i];
        } else if (a[i] == 3 && r[0] < y[i]) {
            r[0] = y[i];
        } else if (a[i] == 4 && r[1] > y[i]) { 
            r[1] = y[i];
        }
    }
#if 0
    cout << "l0 " << l[0] << ", l1 " <<  l[1] << endl;
    cout << "r0 " << r[0] << ", r1 " <<  r[1] << endl;

    cout << l[1] - l[0] << endl;
    cout << r[1] - r[0] << endl;
#endif
    if(((l[1] - l[0]) > 0) && ((r[1] - r[0]) > 0)) {
        cout << (l[1] - l[0]) * (r[1] - r[0]) << endl;
    } else {
        cout << 0;
    }

    return 0;
}


Measured memory_bytes: 256
N = int(input())
lst = {}
for i in range(N):
    base = 0
    s = input()
    for j in range(10):
        base += 10**(ord(s[j])-ord('A'))
    if base not in lst:
        lst[base] = 0
    lst[base] += 1
ans = 0
for v in lst.values():
    ans += v*(v-1)/2
print(int(ans))

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

signed main() {
  int n;
  cin>>n;
  int a=2;
  int b=1;
  int c;
  for(int i=0;i<n;i++){
    c=a+b;
    a=b;
    b=c;
  }
  cout<<a<<endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <math.h>
using namespace std;
typedef long long ll;
typedef long double ld;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
const ll mod = 1000000007;
const ll INF = 1001001001;
const ll LINF = 1001001001001001001;

void prvec(vector<ll> vec){
    ll n = vec.size();
    rep(i,n) cout << i << " " << vec.at(i) << "\n";
}

void pr2d(vector<vector<ll>> vvec){
    ll h = vvec.size();
    ll w = vvec.at(0).size();
    rep(i,h){
        rep(j,w){
            cout << vvec.at(i).at(j) << " ";
        }
        cout << "\n";
    }
}

int main(){
    ll n ; cin >> n;
    vector<ll> a(n);
    rep(i,n) cin >> a.at(i);
    sort(a.rbegin(),a.rend());
    ll comf = a.at(0);
    ll cnt = 2;
    ll cur = a.at(1);
    ll nownumber_cnt = 1;
    for(int i=2;i<n;i++){
        if(a.at(i)==cur){
            nownumber_cnt++;
        }else{
            ll stk = nownumber_cnt * 2;
            if(cnt+stk>=n){
                comf += cur * (n-cnt);
                cnt = n;
                break;
            }else{
                comf += cur * stk;
                cnt += stk;
            }
            nownumber_cnt = 1;
            cur = a.at(i);
        }
    }
    if(cnt!=n){
        comf += cur*(n-cnt);
    }
    cout  << comf << endl;
    return 0;
}

Measured memory_bytes: 4836
fn main() {
	let v: Vec<f64> = read_vec();
	let (n, m, d) = (v[0], v[1], v[2]);
	
	if d == 0.0 {
		println!("{}", (m-1.0)/n);
	} else {
		println!("{}", (m-1.0)*2.0*(n-d)/n/n);
	}
}

fn read_vec<T: std::str::FromStr>() -> Vec<T> {
    let mut buf = String::new();
    std::io::stdin().read_line(&mut buf).unwrap();
    buf.trim().split_whitespace().map(|e|
        e.parse().ok().unwrap()
    ).collect()
}

Measured memory_bytes: 4352
#define _CRT_SECURE_NO_WARNINGS
#include <bits/stdc++.h>
#include <chrono>
#include <random>

using namespace std;

#define int long long
#define ll long long
//#define double long double
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()

const int INF = 2e9;
const int MB = 20;
const int MOD = 1e9 + 7;

void solve() {
    int a, b;
    cin >> a >> b;
    for (int x = 1; x <= 1e6; x++) {
        int one = (double)x * 0.08;
        int two = (double)x * 0.1;
        if (one == a && two == b) {
            cout << x;
            return;
        }
    }
    cout << -1;
}
signed main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);
    solve();
}

Measured memory_bytes: 256
# # Make IO faster
# import sys
# input = sys.stdin.readline

# # get single (or) multiple str
# X = input()

# # get single int
# N = int(input())
# # get multiple int (e.g., 2)
# X, Y = map(int, input().split())
# # get multiple int (e.g., 2) for N lines
# XY = [list(map(int, input().split())) for _ in range(N)]

# from IPython import embed; embed(); exit();

# 全部入り
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import accumulate, permutations, combinations, product
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left
from fractions import gcd
from heapq import heappush, heappop
from functools import reduce
import numpy as np
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def ZIP(n): return zip(*(MAP() for _ in range(n)))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7

X = INT()
A = INT()
B = INT()

print((X - A) % B)


Measured memory_bytes: 27140
#define _CRT_SECURE_NO_WARNINGS
#define _USE_MATH_DEFINES

#include <bits/stdc++.h>
using namespace std;
using i32 = int32_t; using i64 = int64_t; using f64 = double_t; using str = string;
template <typename T> using vec = vector<T>;
template <typename T> using heap = priority_queue<T, vec<T>, greater<T>>;
#define times(n, i) for (i32 i = 0; i < (n); ++i)
#define range(n, m, i) for (i32 i = (n); i < (m); ++i)
#define upto(n, m, i) for (i32 i = (n); i <= (m); ++i)
#define downto(n, m, i) for (i32 i = (n); i >= (m); --i)
#define stepup(n, m, s, i) for (i32 i = (n); i <= (m); i+=(s))
#define stepdown(n, m, s, i) for (i32 i = (n); i >= (m); i-=(s))
#define foreach(xs, x) for (auto &x : (xs))
#define all(xs) (xs).begin(), (xs).end()
#define sortall(xs) sort(all(xs))
#define reverseall(xs) reverse(all(xs))
#define uniqueall(xs) (xs).erase(unique(all(xs)), (xs).end())
#define maximum(xs) (*max_element(all(xs)))
#define minimum(xs) (*min_element(all(xs)))
#define even(x) (((x) & 1) == 0)
#define odd(x) (((x) & 1) == 1)
#define append emplace_back
const i64 MOD = 1000000007;

struct fenwicktree {
    i32 n;
    vec<i64> data;
    fenwicktree(i32 size) : n(size), data(size+1, 0) { }
    void add(i32 i, i64 x) { for (++i; i<=n; i += (i&-i)) data[i] += x; }
    i64 sum(i32 i) { i64 acc = 0; for (++i; 0<i; i -= (i&-i)) acc += data[i]; return acc; }
};

i32 n, m;
i32 l[300001], r[300001];
vec<i32> c[100001];

i32 main()
{
    cin >> n >> m;
    times(n, i) {
        cin >> l[i] >> r[i];
        c[r[i]-l[i]].append(i);
    }

    fenwicktree tree = fenwicktree(m+2);
    i32 shorter = 0;
    upto(1, m, d) {
        foreach(c[d-1], i) {
            shorter++;
            tree.add(l[i], 1);
            tree.add(r[i]+1, -1);
        }
        i32 ans = n-shorter;
        stepup(0, m, d, pos) {
            ans += tree.sum(pos);
        }
        cout << ans << endl;
    }

    return 0;
}

Measured memory_bytes: 9472
#include <iostream>
using namespace std;
int main (){
  long long n;
  cin >> n;
  
  long long ans = 0;
  if (n >= 11) {
        ans+=n/11;
        ans+=n/11;
  }
 // if (n == 0) 
  n-=n/11*11;
  
  if (n > 6) ans+=2;
  else if (n <= 6 && n > 0) ans++;
  
  cout<<ans;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define syosu(x) fixed<<setprecision(x)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> P;
typedef pair<double,double> pdd;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<string> vs;
typedef vector<P> vp;
typedef vector<vp> vvp;
typedef vector<pll> vpll;
typedef pair<int,P> pip;
typedef vector<pip> vip;
const int inf=1<<30;
const ll INF=1ll<<60;
const double pi=acos(-1);
const double eps=1e-8;
const ll mod=1e9+7;
const int dx[4]={-1,0,1,0},dy[4]={0,-1,0,1};

int n;
string s;
vi a;

int main(){
	cin>>s;
	n=s.size();
	a=vi(n+1,-inf);
	for(int i=0;i<=n;i++){
		if((i==0||s[i-1]=='>')&&(i==n||s[i]=='<')) a[i]=0;
	}
	for(int i=0;i<n;i++) if(s[i]=='<') a[i+1]=max(a[i+1],a[i]+1);
	for(int i=n-1;i>=0;i--) if(s[i]=='>') a[i]=max(a[i],a[i+1]+1);
	ll res=0;
	for(auto i:a) res+=i;
	cout<<res<<endl;
}

Measured memory_bytes: 2820
# util functions

# debug
$debugFlag = ( ARGV[0] != nil )
p "==== DEBUG MODE ====" if $debugFlag

def pd(str)
  p str if $debugFlag
end

def printd(str)
  print str if $debugFlag
end

# input
inputs = []
lc = 0
while l = $stdin.gets do
  if false
    inputs << l.chomp.split(" ").map(&:to_s)
  else
    inputs << l.chomp.split(" ").map(&:to_i)
  end
  lc += 1
end

# input check
if $debugFlag
  p "--- INPUT (begin) ---"
  inputs.each do |l_i|
    p l_i
  end
  p "--- INPUT (end) ---"
  print "\n"
end

nn = inputs[0][0]

# body
if $debugFlag
end

puts nn*nn*nn

Measured memory_bytes: 1788
#include<stdio.h>
 
#define N 100
#define INF 1000000
 
int x,A[N],B[N][N],C[N][N],D[N];
 
void funk(int,int);
 
int main() {
  int i,j,k;
 
  scanf("%d",&x);
 
  for(i = 0; i < x; i++) {
    scanf("%d",&k);
    scanf("%d",&A[k]);
    for(j = 0; j < A[k]; j++) {
      scanf("%d",&B[k][j]);
      scanf("%d",&C[k][j]);
    }
  }
 
  for(i = 0; i < x; i++) {
    D[i] = INF;
  }
 
  funk(0,0);
 
  for(i = 0; i < x; i++) {
    printf("%d %d\n",i,D[i]);
  }
 
  return 0;
}
 
void funk(int x,int y) {
  int i;
  D[x] = y;
  for(i = 0; i < A[x]; i++) {
    if(D[B[x][i]] > y + C[x][i]) {
      funk(B[x][i],y + C[x][i]);
    }
  }
}


Measured memory_bytes: 2104
import sys


N = int(input())
num_V = 0
for i in range(1, N + 1):
    tmp = i * (N - (i - 1))
    num_V += tmp

num_E = 0
for s in sys.stdin.readlines():
    u, v = map(int, s.split())
    if u > v:
        u, v = v, u
    tmp = u * (N - (v - 1))
    num_E += tmp

print(num_V - num_E)


Measured memory_bytes: 23108
#include <iostream>
#include <cstdio>
#define _USE_MATH_DEFINES
#include <math.h>
#include <vector>

using namespace std;

void solve()
{
	int H, W;
	while (cin >> H >> W, H || W)
	{
		for (int i = 0; i < H; ++i)
		{
			for (int j = 0; j < W; ++j)
			{
				if ((i + j) % 2)
				{
					cout << ".";
				}
				else
				{
					cout << "#";
				}
			}
			cout << endl;
		}
		cout << endl;
	}
}

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

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

#include <cmath>
#include <cstdio>
#include <vector>
#include <iostream>
#include <algorithm>
#include <iterator>
#include <map>
#include <queue>
#define mp make_pair
#define pb push_back
#define p push
#define FOR(a,c) for(int a = 0;a<c;a++)
#define ll long long
#define abs(x) (x<0 ? (-x) : x)
#define getI(a) scanf("%d",&a)
#define getII(a,b) scanf("%d %d",&a,&b)
#define getIII(a,b,c) scanf("%d%d%d",&a,&b,&c)
#define getL(a) scanf("%lld",&a)
#define getLL(a,b) scanf("%lld %lld",&a,&b)
#define getLLL(a,b,c) scanf("%lld%lld%lld",&a,&b,&c)
#define BEND(c) (c).begin(),(c).end()
#define fi first
#define se second
#define PI 3.1415926535897932384626
#define getS(a) scanf("%s",a)
#define pfi(a) printf("%d",a);
#define pfii(a,b) printf("%d%d",a,b);
#define pfl(a) printf("%lld",a);
#define pfll(a,b) printf("%lld%lld",a,b);
#define SIZE 1000000007

using namespace std;

typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef vector<vector<ll>> vvl;
typedef vector<long long> vl;
typedef vector<pair<int,int>> vpi;
typedef vector<pair<long long,long long>> vpl;
typedef vector<vector<pair<long long,long long>>> vvpl;
typedef vector<bool> vb;
typedef pair<int,int> pii;
typedef pair <ll,ll> pll;
const  double eps = 1e-10;
const ll LINF = 1001002003004005006ll;
const int INF = 1001001001;
const int MX = 200005;
/*ios_base::sync_with_stdio(false);cin.tie(0);*/

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

long long fast_exp(long long n,long long k){
    if(k == 0)
        return 1;
    if(k==1)
        return n;

    long long temp = fast_exp(n,k>>1);

    if((k&1)==1)
        return (n*temp*temp)%SIZE;
    return (temp*temp)%SIZE;

}

int main() {
   ll t;
   cin >> t;
   vl vec(t);
   ll tmp = 9999999999;
   ll count = 0;
    for (ll  i = 0; i <t ; ++i) {
        cin>>vec[i];


    }
    ll sum =0;
    vl vec2(t);
    for (ll i = 0; i <t ; ++i) {
        cin>>vec2[i];
     //   sum+=vec2[i];

    }
    vl cc(t-1);
    for (ll i = 0; i <t-1 ; ++i) {
        cin>>cc[i];
    }

    for (ll i = 0; i <t ; ++i) {
       sum+=vec2[vec[i]-1];
       if (i  > 0 && vec[i] == vec[i-1]+1){
           sum+=cc[vec[i-1]-1];
       }
        //cout <<sum<<"\n";
    }
   // cout <<sum<<"\n";

    cout <<sum;
    return 0;
}



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

val br = BufferedReader(InputStreamReader(System.`in`))
val out = PrintWriter(System.out)

fun main() {
    br.use { out.use {
        solve()
        out.flush()
    } }
}

fun solve() {
    /** O(n) */
    fun <T>elementCountMap(list: List<T>): Map<T, Long> {
        val countMap = mutableMapOf<T, Long>()
        for (e in list) {
            countMap[e] = (countMap[e] ?: 0) + 1
        }
        return countMap
    }

    val n = readInteger()
    val ss = Array(n) { br.readLine()!!.toCharArray().sorted().toString() }.sorted()
    val countMap = elementCountMap(ss)
    var ans = countMap.values.fold(0L) { acc, v -> acc + (v * (v - 1) / 2) }
    out.println(ans)
}

fun readInteger() = Integer.parseInt(br.readLine())
fun readLong() = java.lang.Long.parseLong(br.readLine())
fun readStringList() = br.readLine()!!.split(' ')
fun readIntegerList() = readStringList().map(Integer::parseInt)
fun readLongList() = readStringList().map(java.lang.Long::parseLong)
fun readDoubleList() = readStringList().map(java.lang.Double::parseDouble)


Measured memory_bytes: 70136
#include<iostream>
#include <string> 
#include <vector>  
#include<math.h>
#include <algorithm>
#include<iomanip>
#define INF 1000000000
#define LM 55555
#define LL long long
using namespace::std;


long long x[100000],y[100000],z[100000], b, c,now, N, K, M, ans, A[100000], AA[100000];
string S, s[100];
bool h, k[100];
char cc;

LL gcd(LL a, LL b) {
	LL temp;
	while ((temp = a%b) != 0) {
		a = b;
		b = temp;
	}
	return b;
}
int main() {
	cin >> N;
	if (N < 1200) { 
		cout << "ABC" << endl;
		return 0;
	}
	if (N < 2800) {
		cout << "ARC" << endl;
		return 0;
	}
	cout << "AGC" << endl;
	return 0;

}

Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main(){
    int N, ans, i, Max;
    ans = 1;
    cin >> N;
    int M[30];
    for(i=0;i<N;i++){
        cin >> M[i];
    }

    Max = M[0];
    
    for( i = 0; i < N-1; i++)
    {
        if (M[i+1] >= Max) {
            ans += 1;
            Max = M[i+1];
        }
    }
    

    cout << ans << endl;
}

Measured memory_bytes: 256