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

#define fs first
#define sc second
#define pb emplace_back
#define mp make_pair
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()

const int32_t inf = 1001001001;
const int64_t infll = 1001001001001001001ll;
const int dx[] = {0, -1, 1, 0, -1, 1, -1, 1}, dy[] = {-1, 0, 0, 1, -1, -1, 1, 1};

template <typename T> using vector2d = vector<vector<T>>;

// clang-format off
template <typename T> void sort(vector<T> &v) { sort(all(v)); }
ostream &operator<<(ostream &os, __int128_t value) { if (ostream::sentry(os)) { __uint128_t tmp = value < 0 ? -value : value; char buffer[64]; char *d = end(buffer); do { --d; *d = "0123456789"[tmp % 10]; tmp /= 10; } while (tmp != 0); if (value < 0) { --d; *d = '-'; } int len = end(buffer) - d; if (os.rdbuf()->sputn(d, len) != len) { os.setstate(ios_base::badbit); }} return os; }
istream &operator>>(istream &is, __int128_t &value) { string in; is >> in; value = 0; for (const char &c : in) { if ('0' <= c && c <= '9') value = 10 * value + (c - '0'); } if (in[0] == '-') value *= -1; return is; }
ostream &operator<<(ostream &os, __uint128_t value) { if (ostream::sentry(os)) { char buffer[64]; char *d = end(buffer); do { --d; *d = "0123456789"[value % 10]; value /= 10; } while (value != 0); int len = end(buffer) - d; if (os.rdbuf()->sputn(d, len) != len) { os.setstate(ios_base::badbit); }} return os; }
istream &operator>>(istream &is, __uint128_t &value) { string in; is >> in; value = 0; for (const char &c : in) { if ('0' <= c && c <= '9') value = 10 * value + (c - '0'); } return is; }
template <typename T> ostream &operator<<(ostream &os, vector<T> &v) { os << v[0]; for (int i = 1; i < v.size(); ++i) os << " " << v[i]; return os; }
template <typename T> istream &operator>>(istream &is, vector<T> &v) { for (T &in : v) is >> in; return is; }
template <typename T1, typename T2> ostream &operator<<(ostream &os, pair<T1, T2> p) { os << p.fs << " " << p.sc; return os; }
template <typename T1, typename T2> istream &operator>>(istream &is, pair<T1, T2> &p) { is >> p.fs >> p.sc; return is; }

struct IoSetup { IoSetup(){ cin.tie(0); ios::sync_with_stdio(0); cout << fixed << setprecision(10); cerr << fixed << setprecision(10); } } iosetup;

inline int64_t in() { int64_t x = 0; cin >> x; return x; }
template <typename T1, typename T2> inline bool chmax(T1 &a, T2 b) { return a < b && (a = b, true); }
template <typename T1, typename T2> inline bool chmin(T1 &a, T2 b) { return a > b && (a = b, true); }
// clang-format on

signed main(int argc, char *argv[]) {
  string s;
  cin >> s;

  int ans = s.size();
  for (int i = 0; i < s.size() - 1; ++i) {
    if (s[i] != s[i + 1]) chmin(ans, max(i + 1, (int)s.size() - i - 1));
  }

  cout << ans << endl;
}


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

typedef long long ll;

const ll MOD = 1e9 + 7;

int main() {
    ll N, K;
    cin >> N >> K;
    vector<vector<ll>> a(N, vector<ll>(2));
    rep(i,N) cin >> a[i][0] >> a[i][1];
    sort(a.begin(), a.end());
    rep(i,N) {
        K -= a[i][1];
        if (K <= 0) {
            cout << a[i][0] << endl;
            break;
        }
    }
}

Measured memory_bytes: 5760
#include<algorithm>
#include<typeinfo>
#include<stdlib.h>
#include<string.h>
#include<iostream>
#include<iomanip>
#include<cstdio>
#include<cmath>
#include<string>
#include<vector>
#include<queue>
#include<stack>
#include<map>
#include<set>
#include<iterator>
#include<functional>
#include<bitset>
#include<stack>
#define e exp(1)
#define eps 0.01
#define pi acos(-1)
using namespace std;
typedef long long ll;
const int maxn = 1e5 + 10;
string s[3];
int n;
int main() {
    while (cin >> n) {
        for (int i = 0; i < 3; ++i)
            cin >> s[i];
        int ans = 0;
        for (int i = 0; i < n; ++i) {
            map<char, int>mp;
            int num = 0;
            for (int j = 0; j <3; ++j) {
                mp[s[j][i]]++;
                num = max(num, mp[s[j][i]]);
            }
            ans += (3 - num);
        }
        cout << ans << endl;
    }
    return 0;
}

Measured memory_bytes: 256
import java.util.*;
public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		int s = sc.nextInt();
  		long nums[] = new long[s]; 
      	long stack_num;
      	long pos = 0;
      	
      	for(int i = 0;i < s; i++){
        	nums[i] = sc.nextLong();
        }
      
      	for(long num: nums){
          while(num % 2 == 0){
            num /= 2;
            pos++;
          }
        }
 		
      	System.out.println(pos);
        
	}
}


Measured memory_bytes: 48064
object Main extends App {
  val n = scala.io.StdIn.readLine.toInt
  val h = scala.io.StdIn.readLine.split(" ").map(_.toInt)

  val ans = h.toList.zipWithIndex.count { tmp =>
    val subh = h.slice(0, tmp._2)
    //println(tmp)
    //println(subh.deep)
    //println(subh.toList.forall(_ >= tmp._1))

    subh.toList.forall(_ <= tmp._1)
  }

  println(ans)
}


Measured memory_bytes: 25428
N, M = map(int, input().split())
P = [0] * (N + 1)
S = [0] * (N + 1)
for i in range(M):
  x, p = input().split()
  s = int(x)
  if P[s] == 0:
    if p == 'AC':
      P[s] = 1
    else:
      S[s] += 1
A = sum([S[i] for i in range(N + 1) if P[i] == 1])
print(P.count(1), A)


Measured memory_bytes: 5528
from collections import deque

N, M = map(int, input().split())

graph = [[] for _ in range(N)]

for i in range(M):
    u, v = map(int, input().split())
    graph[u - 1].append(v - 1)

S, T = map(int, input().split())
S -= 1
T -= 1

q = deque([(S, 0)])
visited = [[0]*3 for _ in range(N)]
visited[S][0] = 1

flg = True
res = -1
while q and flg:
    v = q.popleft()
    for n_v in graph[v[0]]:
        n_dist = v[1] + 1
        if n_v == T and n_dist % 3 == 0:
            res = n_dist // 3
            flg = False
            break
        if not visited[n_v][n_dist % 3]:
            visited[n_v][n_dist % 3] = 1
            q.append((n_v, n_dist))

print(res)

Measured memory_bytes: 94836
#include<stdio.h>
int main(){
    long long int n, m, l, i, j, k, sum;
    long long int a[105][105], b[105][105], res[105][105];
    scanf("%lld %lld %lld",&n, &m, &l);
    for(i=0;i<n;i++){
        for(j=0;j<m;j++){
            scanf("%lld", &a[i][j]);
        }
    }
    for(i=0;i<m;i++){
        for(j=0;j<l;j++){
            scanf("%lld", &b[i][j]);
        }
    }
    sum = 0;

    for(i=0;i<n;i++){
        for(j=0;j<l;j++){
            for(k=0;k<m;k++){
                sum += a[i][k] * b[k][j];
            }
            res[i][j] = sum;
            sum = 0;
        }
    }

    for(i=0;i<n;i++){
        for(j=0;j<l-1;j++){
            printf("%lld ", res[i][j]);
        }
        printf("%lld\n", res[i][j]);
    }

return 0;
}



Measured memory_bytes: 2112
#include <bits/stdc++.h>
 using namespace  std;
#define mp make_pair
#define pb push_back
#define ff first
#define ss second
const double pi=3.1415926535897932384626433832;
const long long mod=1e9+7;
//long long primeset[5000000]={};
typedef complex<double> cd;
typedef long long ll;
typedef double ld;
//#define For(i,0,n) for(long long i = 0 ; i<n ;i++) 
cd fast_exp(cd a, long long b)
{
	if (b == 0)
		return 1;
	
	cd res = fast_exp(a, b / 2);
		
	res = res * res;
	
	if (b % 2 == 1)
		res = res * a;
	
	return res;
}

long long fastexpon(long long a,long long b,long long mod)
{
	if(b==0)
		return 1;
	
	long long res=fastexpon(a,b/2,mod);
	
	res=(res*res)%mod;
	if(b%2==1)
		res= (res * a)%mod;

	return res;
}


//template ends here







const int N=1e5+1;
int res[N]={};
int n;
int k;



int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	cin>>n>>k;
	int a[n];
	for(int i=0 ;i<n ;i++)
		cin>>a[i];
	for(int i=0 ; i<=k ;i++)
	{
		if(i < a[0])
			res[i]=2;
		else if(i==a[0])
			res[i]=1;
		else
		{
			int check=0;
			for(int j=0 ;j<n ;j++)
			{
				if(i - a[j] >= 0)
				{
					if(res[i-a[j]]==2)
						check=1;
				}
			}

			if(check==1)
				res[i]=1;
			else
				res[i]=2;
		}
	}

	if(res[k]==1)
		cout<<"First\n";
	else
		cout<<"Second\n";

	//cout<<'\n'<<"time elapsed: "<<clock()*1000.0 / CLOCKS_PER_SEC<<" ms"<<'\n';
	return 0;
}

Measured memory_bytes: 640
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define rep(i,n) for(ll i=0;i<n;++i)
#define INF (1ll<<60)
#define mod 1000000007
#define P pair<ll,ll>
#define Graph vector<vector<ll>>
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; }

ll n,M,R;

void dijkstra(vector<vector<P>> &G,ll start,vector<ll> &dist,vector<ll> &prev){
    priority_queue<P,vector<P>,greater<P>> que;
    que.push({0,start});
    
    prev.assign(n,-1);
    dist.assign(n,INF);
    dist[start]=0;

    while(que.size()){
        P now=que.top();
        que.pop();
        if(dist[now.second]<now.first) continue;//今、最短距離でないなら無視する

        for(auto next:G[now.second]){
            if(dist[next.first]>dist[now.second]+next.second){//最短になる場合
                dist[next.first]=dist[now.second]+next.second;//最短距離更新
                que.push(make_pair(dist[next.first],next.first));
            
                prev[next.first]=now.second;//now.secondを通って、nextに到着
            }
        }
    }
}

vector<ll> get_path(vector<ll> &prev,int goal){//経路復元
    vector<ll> path;
    for (ll cur=goal;cur!=-1;cur=prev[cur]){
        path.push_back(cur);
    }
    reverse(path.begin(),path.end());//逆順なのでひっくり返す
    return path;
}

int main(){
    cin>>n>>M>>R;
    vector<ll> r(R);
    rep(i,R){
        cin>>r[i];
        r[i]--;
    }

    vector<vector<P>> G(n);
    rep(i,M){
        ll a,b,c;cin>>a>>b>>c;
        a--;b--;

        G[a].push_back({b,c});
        G[b].push_back({a,c});
    }

    sort(r.begin(),r.end());//next_permutationで全探索したいが、昇順ソートしておかないと、途中からの順列になるので全探索不可
    vector<vector<ll>> MINdist(n,vector<ll>(n));//それぞれの頂点からの最短距離を格納
    for(ll i=0;i<R;i++){
        vector<ll> dist,prev;
        dijkstra(G,r[i],dist,prev);
        for(auto j:r){
            MINdist[r[i]][j]=dist[j];//i->jのmin
        }
    }


    ll ans=INF;
    do{
        ll sum=0;
        rep(i,R-1){
            sum+=MINdist[r[i]][r[i+1]];
        }
        chmin(ans,sum);
    }while(next_permutation(r.begin(),r.end()));

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

Measured memory_bytes: 4740
#include<bits/stdc++.h>
using namespace std;
#pragma GCC optimization_level 3
using ll = long long;
constexpr ll INF = 1'010'000'000'000'000'017LL;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(v) v.begin(), v.end()

int main(){
	string s;
	cin>>s;
	if (s[0]!=s[1])
	{
		cout<<"Yes";
	} else if (s[1]!=s[2])
	{
		cout<<"Yes";
	} else
	{
		cout<<"No";
	}
	
	
	
}


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

int main()
{
    /*
    std::ifstream in("input.txt");
    std::cin.rdbuf(in.rdbuf());
    */

    int n;
    ll d;
    cin >> n >> d;
    int ans = 0;
    rep(i, n)
    {
        ll x, y;
        cin >> x >> y;
        if (x * x + y * y <= d * d)
            ans++;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3624
#pragma GCC optimize("-O3")
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
void Main();
#ifdef ConanYu
#include "local.hpp"
#else
#define debug(...) do { } while(0)
int main() {
  ios::sync_with_stdio(false), cin.tie(0), cout.tie(0);
  Main();
}
#endif


void Main() {
  int n; cin >> n;
  string s, t; cin >> s;
  for(int i = 0; i < n; i++) {
    if(i == 0 || s[i] != s[i - 1]) {
      t += s[i];
    }
  }
  cout << t.size() << "\n";
}


Measured memory_bytes: 592
package main

import (
	"fmt"
	"sort"
)

type arr []int

func (a arr) Len() int {
	return len(a)
}

func (a arr) Swap(i, k int) {
	a[i], a[k] = a[k], a[i]
}

func (a arr) Less(i, k int) bool {
	return a[i] > a[k]
}

func main() {
	var n, k int
	fmt.Scan(&n, &k)
	h := make([]int, n, n)
	for i := range h {
		fmt.Scan(&h[i])
	}
	sort.Sort(arr(h))
	s := int64(0)
	for i := k; i < n; i++ {
		s += int64(h[i])
	}
	fmt.Println(s)
}


Measured memory_bytes: 7168
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <vector>
#include <functional>
#include <queue>
#include <string>
#include <cstring>
#include <numeric>
#include <cstdlib>
#include <cmath>
#include <map>
#include <unordered_map>
#include <set>
using namespace std;

typedef long long ll;

#define INF 10e17 // 4倍しても(4回足しても)long longを溢れない
#define rep(i,n) for(int i=0; i<n; i++)
#define rep_r(i,n,m) for(int i=m; i<n; i++)
#define END cout << endl
#define MOD 1000000007
#define pb push_back
#define sorti(x) sort(x.begin(), x.end())
#define sortd(x) sort(x.begin(), x.end(), std::greater<ll>())
#define debug(x) std::cerr << (x) << std::endl;
#define roll(x) for (auto itr : x) { debug(itr); }

template <class T> inline void chmax(T &ans, T t) { if (t > ans) ans = t;}
template <class T> inline void chmin(T &ans, T t) { if (t < ans) ans = t;}

using pl = pair<ll, ll>;

int main() {
  ll n, m;
  cin >> n >> m;
  vector<ll> a(n), aft;
  map<ll, ll> cb;
  rep(i, n) {
    cin >> a[i];
  }
  rep(i, m) {
    ll p, t;
    cin >> p >> t;
    cb[t] += p;
  }

  sorti(a);
  
  ll cnt = 0;
  bool flag = false;
  auto itr = cb.rbegin();
  for (; itr != cb.rend(); ++itr) {
    ll lim = itr->second, num = itr->first;
    
    for (int j = 0; j < lim; ++j) {
      cnt += 1;
      aft.push_back(num);
      // cout << lim << " " << num << endl;
      if (cnt == n) {
        flag = true;
        break;
      }
    }

    if (flag) break;
  }
  
  for (int i = 0; i < cnt; ++i) {
    // cout << aft[i] << " " << a[i] << endl;
    if (aft[i] > a[i]) {
      a[i] = aft[i];
    }
  }
  ll ans = 0;
  for (auto&& itr : a) {
    // cout << itr << endl;
    ans += itr;
  }
  cout << ans << endl;
}


Measured memory_bytes: 8444
import sys
from collections import deque
from heapq import heapify, heappop, heappush

def decide_next_dst(cost, order):
    d = 0
    c = 1000000000000000000
    for key in order:
        if cost[key] < c:
            d = key
            c = cost[key]
    return d

def solve():
    inf = 10000000000
    input = sys.stdin.readline
    
    V, E = map(int, input().split())
    edge = dict()
    wf = dict()
    next_id = dict() #iからjに行くときにiの次に訪れる地点
    for i in range(V):
        edge[i] = dict()
        wf[i] = dict()
        next_id[i] = dict()
        for j in range(V):
            edge[i][j] = (0 if i == j else inf)
            next_id[i][j] = j
            wf[i][j] = (0 if i == j else inf)

    for _ in range(E):
        u, v, d = map(int, input().split())
        edge[u - 1][v - 1] = d
        edge[v - 1][u - 1] = d
        wf[u - 1][v - 1] = d
        wf[v - 1][u - 1] = d

    #全頂点最短経路と目的の頂点に向かうとき次に行くべき頂点の復元
    for k in range(V): 
        for i in range(V):
            for j in range(V):
                if wf[i][j] > wf[i][k] + wf[k][j]:
                    wf[i][j] = wf[i][k] + wf[k][j]
                    next_id[i][j] = next_id[i][k] 

    T = int(input())
    order = set()
    stuck_order = set()

    command = [None] * T
    heading = 0 #次に向かう地点
    dist_left = 0 #次に向かう地点までの残り距離
    final_dist = 0
    stuck_cost = [0] * V
    cost = [0] * V

    for t in range(T):
        N = int(input()) #注文の発生
        if N == 1:
            new_id, dst = map(int, input().split())
            stuck_order |= {dst - 1}
            stuck_cost[dst - 1] += t ** 2

        if dist_left > 0: #移動中の場合そのまま移動を続ける
            command[t] = heading + 1
            dist_left -= 1
        
        else:
            if heading == 0: #店にいるときの処理
                if len(stuck_order) == 0: 
                    command[t] = -1
                    continue
                else:
                    order |= stuck_order
                    for key in order: 
                        cost[k] += stuck_cost[k]
                        stuck_cost[k] = 0
                    stuck_order = set()
        
            if heading in order and heading > 0: #顧客のいる場所で荷物を積み下ろすとき
                order -= {heading} 
                cost[heading] = 0

            current_id = heading #現在地の更新
            if len(order) > 0: #まだ配達すべき荷物があるとき
                if current_id == final_dist: #目的地に到着したときは残りの荷物で先に運ぶべき荷物を選ぶ
                    final_dist = decide_next_dst(cost, order)      
            else: final_dist = 0 #荷物が無いので店に戻る
                
            heading = next_id[current_id][final_dist]
            dist_left = edge[current_id][heading] - 1
            command[t] = heading + 1

    for i in range(T): print(command[i])
if __name__ == "__main__":
    solve()

Measured memory_bytes: 36340
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Scanner;

public class Main {
	static private class Pat {
		List<Integer> of = new ArrayList<Integer>();;
	}

	static Pat[] pat = new Pat[26];

	public static void main(String[] args) {
		Scanner in = new Scanner(new BufferedReader(new InputStreamReader(System.in)));
		String s = in.next();
		String t = in.next();
		for (int i = 0; i < pat.length; i++)
			pat[i] = new Pat();
		getPat(s);
		System.out.println(solve(t, s.length()));
	}

	private static long solve(String t, int slen) {
		long ans = 0;
		int d = 0;
		for (int i = 0; i < t.length(); i++) {
			int dn = searchPat(t.charAt(i), d);
			if (dn == 0)
				return -1;
			if (dn < 0) {
				ans += slen;
				d = 0;
				i--;
			} else
				d = dn;
		}
		return ans + d;
	}

	private static int searchPat(char c, int d) {
		int p = c - 'a';
		if (pat[p].of.isEmpty())
			return 0;
		int end = pat[p].of.size();
		if (pat[p].of.get(end - 1) <= d)
			return -1;
		return searchBin(p, d, 0, end);
	}

	private static int searchBin(int p, int d, int s, int e) {
		if (s == e)
			return pat[p].of.get(s);
		int m = (s + e) / 2;
		if (pat[p].of.get(m) > d)
			return searchBin(p, d, s, m);
		else
			return searchBin(p, d, m + 1, e);
	}

	private static void getPat(String s) {
		for (int i = 0; i < s.length(); i++)
			pat[s.charAt(i) - 'a'].of.add(i + 1);
	}
}

Measured memory_bytes: 30124
#include<bits/stdc++.h>
using namespace std;
#define REP(i,n) for(int i=0;i<(n);i++)
#define REP2(i,a,b) for(int i=(a);i<(b);i++)
#define ALL(v) (v).begin(),(v).end()
#define INF 2e9
typedef long long ll;

int main()
{
  int n;
  cin>>n;
  map<char,ll> mp;
  REP(i,n){
    string s;
    cin>>s;
    if(s[0]=='M' || s[0]=='A' || s[0]=='R' || s[0]=='C' || s[0]=='H') mp[s[0]]++;
  }

  cout<<mp['M']*mp['A']*mp['R']+mp['M']*mp['A']*mp['C']+mp['M']*mp['A']*mp['H']+mp['M']*mp['R']*mp['C']+mp['M']*mp['R']*mp['H']+mp['M']*mp['C']*mp['H']+mp['A']*mp['R']*mp['C']+mp['A']*mp['R']*mp['H']+mp['A']*mp['C']*mp['H']+mp['R']*mp['C']*mp['H']<<endl;
  
  return 0;
}

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


class Program
{
    static void Main(string[] args)
    {
        // 入力
        //var s = Console.ReadLine();
        //var n = int.Parse(Console.ReadLine());
        int[] nm = Console.ReadLine().Split().Select(int.Parse).ToArray();
        var n = nm[0];
        var m = nm[1];
        int[] a = Console.ReadLine().Split().Select(int.Parse).ToArray();

        var sum = a.Sum();
        Array.Sort(a);
        Array.Reverse(a);
        var ans = "Yes";
        for (int i = 0; i < m; i++)
        {
            var tmp = a[i] * 4 * m;
            if (sum > tmp)
            {
                ans = "No";
                break;
            }
        }

        // 出力
        Console.WriteLine(ans);
    }
}

Measured memory_bytes: 13396
#include <bits/stdc++.h>
#include <math.h>
#include <cmath>

using namespace std;
using ll =long long;
using vi = vector<int>; 
using vvi = vector<vi>; 
using vl = vector<ll>; 
using vvl = vector<vl>; 
using vs = vector<string>;
using vvs = vector<vs>; 
using vc = vector<char>;
using vvc = vector<vc>; 
using vb = vector<bool>;
using vvb = vector<vb>; 

#define rep(i,n) ;for( int i =0; i < n ; i ++)
#define all(a) a.begin(),a.end()
#define pb(a) push_back(a)
#define pd(a) printf("%.10f\n",a)
#define mem(a) memset(a,0,sizeof(a))
#define f(i,a,b) for(int i=a;i<b;i++)
#define pri(a)  printf("%.14lf\n",a);
#define MOD 1000000007
bool is_int_lround(double x){
  return std::lround(x)==x;
}
ll keta(ll x){
  ll n=0;
  while(x>0){
    x /=10 ;
    n ++;
  }
  return n;
}

ll conbi(int n,int m){
  
  cin>>n>>m;
  vector<ll> a(100);
  a[0] =1;
  for(int i=0;i<14;i++){
    a[i+1]=a[i]*(i+1);
  }
  return a[n] /(a[m] *a[n-m]);
}

long long modpow(long long a, long long n, long long mod) {
    long long res = 1;//繰り返し二乗法
    while (n > 0) {
        if (n & 1) res = res * a % mod;
        a = a * a % mod;
        n >>= 1;
    }
    return res;
}
ll kaijoMOD(ll x){
  ll z=1;
  if(x==0){
    return 1;
  }
  while(x>0){
    z *=x;
    z %=MOD;
    x--;
  }
  return z;
}
ll yakusu_num(ll n){
  vl yakusu(n+1,1);
  for(ll i=2;i*i<=n;i++){ 
    while(n%i==0){
      n /=i;
      yakusu[i]++;
    }
  }
  if(n!=1)yakusu[n]++;
  ll num=1;
  for(ll i=0;i<=n;i++){
    num*=yakusu[i];
  }
  return num;
}

int H,W;
vs s(50);
vi dv ={-1,0,1,0};vi du={0,-1,0,1};
int cnt=1;
int dfs(int u,int v){
  s[u][v]='.';
  
  rep(i,4){
   
      int nu =u +du[i],nv=v+dv[i];
      if(nu<0||nu>=H||nv<0||nv>=W)continue;
      if(s[nu][nv]=='.')continue;
      cnt ++;
      dfs(nu,nv);
    
  }
  return cnt;

}
int keta_wa(int x){
  int tot=0;
  while(x>0){
    tot +=x%10;
    x/=10;
  }
  return tot;
}

//vc alp ={'a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z'};
//vc Alp ={'A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z'};
//cout<<""<<endl;
int main(){
  int N ;
  string s;
  cin>> s ;
  bool ok=false;
  rep(i,3){
    if(s[i]=='7'){
      cout<<"Yes"<<endl;
      ok=true;
      break;
    }
  }
  if(!ok){
   cout<<"No"  <<endl;
  }
}
   





Measured memory_bytes: 3588
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int, int>;

int Q;
int p[100010], p2[100010];

int main() {
  cin.tie(0);
  ios_base::sync_with_stdio(false);
  cout << fixed << setprecision(10);
  
  for (int i = 2; i < 100010; i++) {
    p[i] = 1;
    for (int j = 2; j * j <= i; j++) {
      if (i % j == 0) p[i] = 0;
    }
  }
  for (int i = 0; i < 100010; i++) {
    if (p[i] && p[(i + 1) / 2]) p2[i] = 1;
  }
  for (int i = 1; i < 100010; i++) {
    p2[i] += p2[i - 1];
  }
  cin >> Q;
  for (int i = 0; i < Q; i++) {
    int l, r;
    cin >> l >> r;
    cout << p2[r] - p2[l - 1] << endl;
  }

  return 0;
}

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

const ll INF = LLONG_MAX;

struct Edge {//グラフ
    ll to, cap, rev;
    Edge(ll _to, ll _cap, ll _rev) {
        to = _to; cap = _cap; rev = _rev;
    }
};
typedef vector<Edge> Edges;
typedef vector<Edges> Graph;
void add_edge(Graph& G, ll from, ll to, ll cap, bool revFlag, ll revCap) {
    G[from].push_back(Edge(to, cap, (ll)G[to].size()));
    if (revFlag)G[to].push_back(Edge(from, revCap, (ll)G[from].size() - 1));//最小カット計算時逆辺は0にする
}

void Dijkstra(Graph& G, ll s, vector<ll>& d) {//O(|E|log|V|)
    d.resize(G.size());
    rep(i, d.size())d[i] = INF;
    d[s] = 0;
    priority_queue<P, vector<P>, greater<P>> q;
    q.push(make_pair(0, s));
    while (!q.empty()) {
        P a = q.top();
        q.pop();
        if (d[a.second] < a.first)continue;
        rep(i, G[a.second].size()) {
            Edge e = G[a.second][i];
            if (d[e.to] > d[a.second] + e.cap) {
                d[e.to] = d[a.second] + e.cap;
                q.push(make_pair(d[e.to], e.to));
            }
        }
    }
}

char grid[1010][1010];
int group[1010][1010];
int h,w,ch,cw,dh,dw;

void dfs(int i, int j, int &gr){
  if(i<0 || i>=h || j<0 || j>=w) return;
  if(grid[i][j]=='#') return;
  if(group[i][j]!=-1) return;
  group[i][j]=gr;
  dfs(i+1,j,gr);
  dfs(i-1,j,gr);
  dfs(i,j+1,gr);
  dfs(i,j-1,gr);
}

int di[]={-2,-2,-2,-2,-2, -1,-1,-1,-1, 0,0,  1,1,1,1,   2,2,2,2,2};
int dj[]={-2,-1,0,1,2,    -2,-1,1,2,   -2,2, -2,-1,1,2, -2,-1,0,1,2};

int main(){
  cin>>h>>w>>ch>>cw>>dh>>dw;
  ch--;cw--;dh--;dw--;
  rep(i,h)rep(j,w){
    cin>>grid[i][j];
    group[i][j]=-1;
  }
  int tmp=0;
  rep(i,h)rep(j,w){
    if(grid[i][j]!='#' && group[i][j]==-1){
      dfs(i,j,tmp);
      tmp++;
    }
  }
  Graph g(tmp);
  set<P> st;
  rep(pi,h)rep(pj,w){
    if(grid[pi][pj]=='#') continue;
    rep(i,20){
      int ni=pi+di[i], nj=pj+dj[i];
      if(ni<0 || ni>=h || nj<0 || nj>=w) continue;
      if(grid[ni][nj]=='#') continue;
      int fir=group[pi][pj], sec=group[ni][nj];
      if(fir == sec) continue;
      st.insert(make_pair(min(fir,sec),max(fir,sec)));
    }
  }
  for(auto x : st){
    int a,b;
    tie(a,b)=x;
    add_edge(g,a,b,1,true,1);
  }
  vector<ll> d;
  int s=group[ch][cw];
  Dijkstra(g,s,d);
  if(d[group[dh][dw]]==INF) cout<<-1<<endl;
  else cout<<d[group[dh][dw]]<<endl;
}


Measured memory_bytes: 37564
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <sstream>
#include <queue>
#include <deque>
#include <bitset>
#include <iterator>
#include <list>
#include <stack>
#include <map>
#include <unordered_map>
#include <set>
#include <unordered_set>
#include <functional>
#include <numeric>
#include <utility>
#include <limits>
#include <time.h>
#include <math.h>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <assert.h>

using namespace std;

typedef long long ll;
typedef vector<long long> vi;
typedef pair<long long, long long> ii;
typedef vector<pair<long long, long long>> vii;
typedef stringstream ss;
ll mil() {return numeric_limits<long long>::min();}
ll mal() {return numeric_limits<long long>::max();}

#define R3(i, a, b) for(long long i=(a); i<(b); ++i)
#define R2(i, b) for(long long i=0; i<(b); ++i)
#define R1(b) for(long long i=0; i<(b); ++i)
#define RR(i, a, b) for(long long i=a; i>b; --i)
#define PB(x) push_back(x)
#define MP(x, y) make_pair(x, y)

// build: ctrl + f9

// run: shift + f10
// debug: shift + f9
// sanitize: shift + f11

int main(int argc, char **argv) {
    ll N, M;

    cin >> N >> M;

    vector<ll> cis(N, -1);

    R1(M) {
        ll s, c;
        cin >> s >> c;
        if(cis[s-1] < 0) {
            cis[s-1] = c;
        }
        else if(cis[s-1] >= 0 && cis[s-1] != c) {
            cout<< -1 << endl;
            return 0;
        }
    }

    ll tot = 0;

    ll nonNullCis = 0;
    R1(N) {
      nonNullCis += cis[i] >= 0 ? 1 : 0;
    }

    if(cis[0] == 0 && N > 1) {
        cout << -1 << endl;
        return 0;
    }


    if(N == 1) {
        tot = cis[0] < 0 ? 0 : cis[0];
    }
    else {
        R1(N) {
            tot*=10;
            tot += cis[i] < 0 ? (i != 0 ? 0 : 1) : cis[i];
        }
    }


    cout << tot << endl;
}

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

using namespace std;

int main() {
	int n;
	cin >> n;
	vector <vector<int>> g(n + 1, vector<int>(n - 1));
	for (int i = 1; i <= n; i++) {
		for (int j = 0; j < n - 1; j++) {
			cin >> g[i][j];
		}
	}
	vector <int> pointer(n + 1);
	map <pair<int, int>, int> now;
	queue <pair<int, int>> simple;
	queue <pair<int, int>> future;
	for (int i = 1; i <= n; i++) {
		int v = i, u = g[i][pointer[i]];
		if (v > u) swap(v, u);
		now[{v, u}]++;
	}
	for (auto q : now) {
		if (q.second == 2) {
			future.push(q.first);
			//~ cout << q.first.first << " " << q.first.second << endl;
		}
	} 
	//~ cout << endl;
	int games = 0;
	for (int i = 0; i <= n * (n - 1) / 2; i++) {
		simple = future;
		future = queue<pair<int, int>>();
		if (simple.empty()) {
			if (games == n * (n - 1) / 2) {
				cout << i;
				return 0;
			} else {
				cout << -1;
				return 0;
			}
		}
		while (!simple.empty()) {
			int v = simple.front().first;
			int u = simple.front().second;
			//~ cout << v << " " << u << "\n";
			simple.pop();
			games++;
			now.erase({v, u});
			pointer[v]++;
			pointer[u]++;
			if (pointer[v] < n - 1) {
				int w = v;
				int p = g[v][pointer[v]];
				if (w > p) swap(w, p);
				//~ cout << "w " << w << " p " << p << endl;
				now[{w, p}]++;
				if (now[{w, p}] == 2) {
					future.push({w, p});
				}
			}
			if (pointer[u] < n - 1) {
				int w = u;
				int p = g[u][pointer[u]];
				if (w > p) swap(w, p);
				//~ cout << "w " << w << " p " << p << endl;
				now[{w, p}]++;
				if (now[{w, p}] == 2) {
					future.push({w, p});
				}
			}
		}
	}
	return 0;
}


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

int a[100005];
int b[100005];

int main(){
    int A, B, M;
    scanf("%d%d%d", &A, &B, &M);

    int minA = 1012345678;
    for(int i = 0; i < A; i ++){
        scanf("%d", &a[i]);
        minA = min(minA, a[i]);
    }

    int minB = 1012345678;
    for(int i = 0; i < B; i ++){
        scanf("%d", &b[i]);
        minB = min(minB, b[i]);
    }

    int minT = minA + minB;
    for(int i = 0; i < M; i ++){
        int x, y, c;
        scanf("%d%d%d", &x, &y, &c);
        minT = min(minT, a[x-1]+b[y-1]-c);
    }

    printf("%d", minT);
    return 0;
}


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

int main() {
  int r, c;
  cin >> r >> c;
  vector<vector<int> > sheet(r + 1, vector<int>(c + 1, 0));
  for (int i = 0; i < r; ++i) {
    int sum = 0;
    for (int j = 0; j < c; ++j) {
      cin >> sheet.at(i).at(j);
      sum += sheet.at(i).at(j);
    }
    sheet.at(i).at(c) = sum;
  }

  for (int j = 0; j < c + 1; ++j) {
    int sum = 0;
    for (int i = 0; i < r; ++i) {
      sum += sheet.at(i).at(j);
    }
    sheet.at(r).at(j) = sum;
  }

  for (int i = 0; i < r + 1; ++i) {
    for (int j = 0; j < c + 1; ++j) {
      cout << sheet.at(i).at(j);
      if (j == c) cout << endl;
      else cout << " ";
    }
  }

  return 0;
}


Measured memory_bytes: 3212
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx")
#pragma GCC optimize("unroll-loops")
//#pragma warning(disable : 4996)

#ifdef _MSC_VER
#include <intrin.h>
#define __builtin_popcount __popcnt
#define __builtin_popcountll __popcnt64
#endif

#include <limits.h>
#include <math.h>
#include <time.h>

#include <algorithm>
#include <array>
#include <bitset>
#include <cassert>
#include <complex>
#include <cstdio>
#include <cstring>
#include <functional>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <map>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <vector>

using namespace std;

#define REP(i, n) for (int i = 0; i < (n); ++i)
#define REPR(i, n) for (int i = n - 1; i >= 0; --i)
#define FOR(i, m, n) for (int i = m; i < n; ++i)
#define FORR(i, m, n) for (int i = m - 1; i >= n; --i)
#define SORT(v, n) sort(v, v + n);
#define VSORT(v) sort(v.begin(), v.end());
#define REVERSE(v, n) reverse(v, v + n);
#define VREVERSE(v) reverse(v.begin(), v.end())
#define ll long long
#define print(x) cout << (x) << '\n'
#define pe(x) cout << (x) << " "
#define DEBUG(x) cout << #x << ": " << x << endl
#define lb(v, n) lower_bound(v.begin(), v.end(), (n))
#define ub(v, n) upper_bound(v.begin(), v.end(), (n))
#define int long long
#define double long double
#define all(x) (x).begin(), (x).end()
#define print_space(v) REP(i, v.size()) cout << v[i] << ((i == v.size() - 1) ? "\n" : " ")
template <typename T1, typename T2> inline void chmin(T1& a, T2 b) {if (a > b) a = b;}
template <typename T1, typename T2> inline void chmax(T1& a, T2 b) {if (a < b) a = b;}
void fail() { cout << -1 << endl; exit(0); }

typedef pair<int, int> pii; typedef pair<long long, long long> pll;
std::random_device rd;
std::mt19937 mt(rd());
constexpr ll MOD = 998244353;
constexpr int MAX = 100050;
const double pi = acos(-1);
constexpr double EPS = 1e-8;
constexpr ll LINF = 1e18 + 1; constexpr int INF = 1e9 + 1;
const int dx[4] = { 0,0,-1,1 }, dy[4] = { 1,-1,0,0 };

void solve() {
	int X; cin >> X;
	FOR(k, 1, 100000) {
		if (X*k % 360 == 0) {
			print(k); return;
		}
	}
} 





signed main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	//mt.seed((int)(time(0)));
	//int q;
	//cin >> q;
	//while (q--)
	solve();
}



Measured memory_bytes: 3652
#!/bin/usr/env python3

n,k = map(int,input().split())

total = 0

for i in range(1,n+1):
    memo_05 = 1
    memo_cnt = 0
    a = i
    while(a < k):
        a *= 2
        memo_cnt += 1
    if memo_cnt > 0:
        for j in range(memo_cnt):
            memo_05 *= 0.5

    total += (1/n) * memo_05

print(total)
    
        


Measured memory_bytes: 3060
#include<iostream>
#include<algorithm>
#include<vector>
#include<string>
#include<cmath>
#include<map>
#include<stack>
#include<queue>
#include<bitset>

#define ipair pair<int,int>
#define rep(i,n) for(i=0;i<n;i++)

using namespace std;

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

int main() {
	long long n;
	string ans;

	cin >> n;

	while (n != 0) {
		if (n % 2 != 0) {
			ans = "1" + ans;
			n--;
		}
		else {
			ans = "0" + ans;
		}
		n /= -2;
	}

	if (ans == "")ans = "0";

	cout << ans;

	return 0;
}


Measured memory_bytes: 256
# 久々の幅優先探索……

import queue

n = int(input())
edges = [list(map(int, input().split())) for _ in range(n-1)]
num_0_mod_3 = n // 3
num_2_mod_3 = (n+1) // 3
num_1_mod_3 = (n+2) // 3


def add_edge(u, v ):
    G[u].append(v)
    G[v].append(u)

G = [[] for _ in range(n)] #グラフの隣接リスト表現
for edge in edges:
    add_edge(edge[0]-1, edge[1]-1)

num_distance_even = 0
num_distance_odd = 0

q = queue.Queue()
q.put(0)

distance = [-1] * n
distance[0] = 0
num_distance_even += 1

for v in G[0]:
    q.put(v)

while(q.qsize() > 0):
    now = q.get()
    for v in G[now]:
        if distance[v] >= 0:
            pass
        else:
            q.put(v)
            distance[v] = distance[now] + 1
            if (distance[v] & 1):
                num_distance_odd += 1
            else:
                num_distance_even += 1

# print(distance)
# print(num_distance_even, num_distance_odd)

ans = [-1] * n

index_one = 1
index_two = 2
index_zero = 3

if num_distance_even >= num_1_mod_3 + num_2_mod_3:
    # evenに120 oddに0

    for i in range(n):
        if (distance[i] & 1) == 1:
            ans[i] = index_zero
            index_zero += 3
        else:
            if (index_one <= n):
                ans[i] = index_one
                index_one += 3
            elif (index_two <= n):
                ans[i] = index_two
                index_two += 3
            else:
                ans[i] = index_zero
                index_zero += 3


elif num_distance_odd >= num_1_mod_3 + num_2_mod_3:
    # evenに0 oddに012
    for i in range(n):
        if (distance[i] & 1) == 0:
            ans[i] = index_zero
            index_zero += 3
        else:
            if (index_one <= n):
                ans[i] = index_one
                index_one += 3
            elif (index_two <= n):
                ans[i] = index_two
                index_two += 3
            else:
                ans[i] = index_zero
                index_zero += 3


else:
#     num_distance_even <= num_distance_odd * 2 and num_distance_odd <= num_distance_even * 2:
    # evenを2、oddを1、適宜0
    for i in range(n):
        if (distance[i] & 1) == 1:
            if (index_one <= n):
                ans[i] = index_one
                index_one += 3
            else:
                ans[i] = index_zero
                index_zero += 3
        else:
            if (index_two <= n):
                ans[i] = index_two
                index_two += 3
            else:
                ans[i] = index_zero
                index_zero += 3


print(' '.join(list(map(str, ans))))


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

const long long MOD = 1000000007;
const long long INF = 1LL << 60;
const int INT_INF = 1000000000;

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

int main()
{
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  int N, K;
  cin >> N >> K;
  ll ans = 0;
  if (K == 0)
  {
    ans = pow(N, 2);
  }
  else
  {
    for (int i = K + 1; i <= N; i++) // b
    {
      ans += (i - K) * (N / i) + max(0, N % i - (K - 1));
    }
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <queue>
#include <vector>
#include <map>
#include <stack>
#include <set>

using namespace std;

typedef long long LL;
typedef pair<int , int> P2;
typedef pair<pair<int , int> , int> P3;
typedef pair<pair<int , int> , pair<int , int> > P4;
#define Fst first
#define Snd second
#define PB(a) push_back(a)
#define MP(a , b) make_pair((a) , (b))
#define M3P(a , b , c) make_pair(make_pair((a) , (b)) , (c))
#define M4P(a , b , c , d) make_pair(make_pair((a) , (b)) , make_pair((c) , (d)))
#define repp(i,a,b) for(int i = (int)(a) ; i < (int)(b) ; ++i)
#define repm(i,a,b) for(int i = (int)(a) ; i > (int)(b) ; --i)

LL N;;
deque<int> Q;
int a[111];
int m;

int main(){
	scanf("%lld" , &N);
	++N;
	while(N > 1){
		if(N % 2 == 0){
			++a[m];
			N /= 2;
		} else {
			++m;
			--N;
		}
	}
	int z = 0;
	repm(i,m,-1){
		repp(j,0,a[i]){
			Q.push_back(++z);
		}
		if(i != 0) Q.push_front(++z);
	}
	printf("%d\n" , z * 2);
	while(!Q.empty()){
		printf("%d " , Q.front());
		Q.pop_front();
	}
	repp(i,1,z+1){
		printf("%d%c" , i , i == z ? '\n' : ' ');
	}
	return 0;
}


Measured memory_bytes: 256
# coding: utf-8
# Your code here!

a = int(input())
b = int(input())
c = int(input())
d = int(input())
e = int(input())

cooking_time = [a,b,c,d,e]

l = [x%10 for x in cooking_time]
if sum(l)==0:
    mindiv10=0
else:
    mindiv10 = min(list(filter(lambda n:n>0, l)))

# search
last_food = 0
for x in cooking_time:
    if x%10 == mindiv10:
        last_food = x
        
cooking_time.remove(last_food)

time = 0
for x in cooking_time:
    time += x + (0 if x%10==0 else 10-x%10)

time += last_food

print(time)

Measured memory_bytes: 3064
fun main(args: Array<String>) {
    val (x, y) = readLine()!!.split(' ').map { it.toInt() }
    for (i in 0..x) {
        val leg = 2 * i + 4 * (x - i)
        if (leg == y) {
            println("Yes")
            return
        }
    }
    println("No")
}

Measured memory_bytes: 36272
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using p = pair<int, int>;
#define INF 1001001001
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define repX(i, n ,x) for (int i = x; i < (int)(n); i++)
#define repBack(i, n) for (int i = n; i >= 0; i--)
#define dup(x,y) (((x)+(y)-1)/(y))

int main() {
    int K;
    int A,B;
    cin >> K;
    cin >> A >> B;
    int x = (B / K)*K;
    if(A<=x && x <= B){
        cout << "OK" << endl;
    }else cout << "NG" << endl;

    return 0;
}

Measured memory_bytes: 3624
import math

def sosuu(n):
    for i in range(2, int(math.sqrt(n)) + 1):
        if n % i == 0:
            return False

    return True
    

N = int(input())
A = N
while(1):
	B = sosuu(A)
	if B == False:
		A +=1
	elif B == True:
		print(A)
		break

Measured memory_bytes: 3060
from collections import Counter 
from itertools import combinations
n=int(input())
s=[]
count=0
for _ in range(n):
    si=list(input())
    if si[0]=="M" or si[0]=="R" or si[0]=="A" or si[0]=="C" or si[0]=="H":

        s.append(si[0])
s_counter=Counter(s)
s_key=s_counter.keys()
if len(s_key)>=3:
    for i,j,k in combinations(s_key,3):
        count+=s_counter[i]*s_counter[j]*s_counter[k]
print(count)

Measured memory_bytes: 10044
#include <iostream>
#include <string>
#include <map>
using namespace std;
int main(){
      string s,nmax,gmax;
      map<string,int> m;
      map<string,int>::iterator it;
      int nm=-1,gm=-1;
      while(cin>>s){
            if(nm<(int)s.length()){
                  nm = (int)s.length();
                  nmax = s;
            }
            if(m.count(s))m[s]++;
            else m[s]=0;
      }
      for(it = m.begin();it!=m.end();it++){
            if(gm<it->second){
                  gm = it->second;
                  gmax = it->first;
            }
      }
      cout <<gmax<<' '<<nmax<<endl;
}

Measured memory_bytes: 1192
N = int(input())
D,X = map(int,input().split())
con = 0
for i in range(N):
  a = int(input())
  if a != 1:
    for i in range(1 , D + 1):
      if i % a == 1:
        con += 1
  elif a == 1:
    con += D
print(X + con)
      
  

Measured memory_bytes: 9048
/*      ###########################
        #  Author : Pranay Garg   #
        #  College : SGSITS       #
        ###########################
*/      
#include<bits/stdc++.h>
#define ll long long int
#define ironman ios_base::sync_with_stdio(false);cin.tie(NULL);
#define MOD 1000000007
#define endl '\n'
using namespace std;
void fastio()
{
    ironman
    #ifndef ONLINE_JUDGE
        freopen("input.txt", "r", stdin);
        freopen("output.txt", "w", stdout);
        freopen("error.txt","w",stderr);
    #endif
}
ll parent[100005];
ll find(ll a)
{
    std::vector<ll> v;
    while(parent[a]>0)
    {
        v.push_back(a);
        a = parent[a];
    }
    for(ll i=0;i<v.size();i++)
        parent[v[i]] = a;
    return a;
}
bool prime[100005];
void SieveOfEratosthenes(int n) 
{  
    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; 
        } 
    } 
}  
void union1(ll a, ll b)
{
    a = find(a);
    b = find(b);
    if(a!=b)
    {
        parent[a] = min(parent[a],parent[b]);
        parent[b] = a;
    }
}  
ll n;
std::vector<pair<ll,pair<ll,ll> > > arr(100005);
ll dp[100005][3];
ll solve(ll i,ll prev)
{
    if(i==n)
        return 0;
    if(prev!=-1 && dp[i][prev]!=-1)
        return dp[i][prev];
    if(prev==0)
    {
        ll a = arr[i].second.first+solve(i+1,1);
        ll b = arr[i].second.second+solve(i+1,2);         
        dp[i][prev] = max(a,b);
        return max(a,b);
    }
    else if(prev==1)
    {
        ll a = arr[i].first+solve(i+1,0);
        ll b = arr[i].second.second+solve(i+1,2);
        dp[i][prev] = max(a,b);         
        return max(a,b);        
    }
    else if(prev==2)
    {
        ll a = arr[i].second.first+solve(i+1,1);
        ll b = arr[i].first+solve(i+1,0);
        dp[i][prev] = max(a,b);         
        return max(a,b);
    }
    else if(prev==-1)
    {
        ll a = arr[i].second.first+solve(i+1,1);
        ll b = arr[i].second.second+solve(i+1,2);
        ll c = arr[i].first+solve(i+1,0);
        //dp[i][prev] = max(a,max(b,c));         
        return max(a,max(b,c));
    }
}
int main()
{
    //fastio();
    memset(dp,-1,sizeof(dp));
    cin >> n;
    for(ll i=0;i<n;i++)
    {
        cin >> arr[i].first >> arr[i].second.first >> arr[i].second.second;
    }
    cout << solve(0,-1) << endl;
}

Measured memory_bytes: 9600
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
char f[305][305];
char now[305][305];
int n;
int mp[305][305];
bool check()
{
        for (int i = 1; i <= n; i++)
        {
                for (int j = 1; j <= n; j++)
                {
                        if (now[i][j] != now[j][i])
                        {
                                return false;
                        }
                }
        }
        return true;
}
int main()
{
        //freopen("out.txt", "w", stdout);
        int anser = 0;
        int dx, dy;
        int flag = 0;
        cin >> n;
        for (int i = 1; i <= n; i++)
        {
                scanf("%s", f[i] + 1);
        }
        for (int i = 0; i < n; i++)
        {
                for (int j = 0; j < n; j++)
                {
                        flag = 0;
                        if (mp[i][j])
                        {
                                continue;
                        }
                        for (int k = 1; k <= n; k++)
                        {
                                for (int w = 1; w <= n; w++)
                                {
                                        dx = (k + i);
                                        dy = (j + w);
                                        if (dx > n)
                                        {
                                                dx -= n;
                                        }
                                        if (dy > n)
                                        {
                                                dy -= n;
                                        }
                                        now[dx][dy] = f[k][w];
                                }
                        }
                        if (check())
                        {
                                flag = 1;
                        }
                        for (int k = 0; k <= n; k++)
                        {
                                dx = i + k;
                                dy = j + k;
                                if (max(dx, dy) >= n)
                                {
                                        break;
                                }
                                mp[dx][dy] = 1;
                                if (flag)
                                {
                                        anser++;
                                }
                        }
                }
        }
        cout << anser << endl;
}


Measured memory_bytes: 768
#include <bits/stdc++.h>
using namespace std;
#define _GLIBCXX_DEBUG
#define rep(i,n) for(long long i = 0; i < (n); ++i)
#define ll long long
#define P pair<ll,ll>
#define all(v) (v).begin(),(v).end()

const ll mod = 1e9+7;
const ll INF = 1e18;
const double pi = acos(-1.0);

int main(void)
{
    ll n,m;
    cin>>n>>m;
    ll ans=0;
    vector<P> a(n);
    rep(i,n){
        ll x,y;
        cin>> x>> y;
        a[i] = {x,y};
    }
    sort(all(a));
    for(auto x:a){
        ans += min(x.second,m)*x.first;
        m-=min(x.second,m);
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 4844
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N=2e5+20;
ll n,t,a[N];
ll mx[N];
map<ll,ll> cnt;
int main()
{
	while(cin>>n>>t)
	{
		for(int i=1;i<=n;i++)
			scanf("%d",&a[i]);
		cnt.clear();
		memset(mx,0,sizeof(mx));
		ll dif=0,ans=0;
		for(int i=n;i>=1;i--)
		{
			mx[i]=max(a[i],mx[i+1]);		
			cnt[a[i]]++;
			if(mx[i]-a[i]>dif)
			{
				ans=1;
				dif=mx[i]-a[i];
			}
			else if(mx[i]-a[i]==dif)
				ans++;
		}
		cout<<ans<<endl;
	}
	return 0;
}

Measured memory_bytes: 8832
n,k=map(int,input().split())
x = [int(i) for i in input().split()]

ans = abs(300000000)
for i in range(n-k+1):
    l = x[i]
    r = x[i+k-1]
    if r<0:
        ans=min(ans,-l)
    elif l>0:
        ans=min(ans,r)
    else:
        ans=min(ans,-2*l+r)
        ans=min(ans,2*r-l)
print(ans)

Measured memory_bytes: 14384
#include <stdio.h>

int main(void){
	int a, b, c;
	int i;
	scanf("%d %d %d", &a, &b, &c);
	if(b<a){
		i = a;
		a = b;
		b = i;
	}
	if(c<b){
		i = b;
		b = c;
		c = i;
	}
	if(b<a){
		i = a;
		a = b;
		b = i;
	}
	printf("%d %d %d\n", a, b, c);
	
	return(0);
}

Measured memory_bytes: 596