akhauriyash/Code-Regression huggingface dataset:
class SegmentTree():
    '''
    非再帰
    segment tree
    '''

    def __init__(self, n, func, init=float('inf')):
        '''
        n->配列の長さ
        func:func(a,b)->val,　func=minだとRMQになる
        木の高さhとすると,
        n:h-1までのノード数。h段目のノードにアクセスするために使う。
        data:ノード。
        parent:k->child k*2+1とk*2+2
        '''
        self.n = 2**(n-1).bit_length()
        self.init = init
        self.data = [init]*(2*self.n)
        self.func = func

    def set(self, k, v):
        '''
        あたいの初期化
        '''
        self.data[k+self.n-1] = v

    def build(self):
        '''
        setの後に一斉更新
        '''
        for k in reversed(range(self.n-1)):
            self.data[k] = self.func(self.data[k*2+1], self.data[k*2+2])

    def update(self, k, a):
        '''
        list[k]=aに更新する。
        更新ぶんをrootまで更新
        '''
        k += self.n-1
        self.data[k] = a

        while k > 0:
            k = (k-1)//2
            self.data[k] = self.func(self.data[k*2+1], self.data[k*2+2])

    def query(self, l, r):
        '''
        [l,r)のfuncを求める
        '''
        L = l+self.n
        R = r+self.n
        ret = self.init
        while L < R:
            if R & 1:
                R -= 1
                ret = self.func(ret, self.data[R-1])
            if L & 1:
                ret = self.func(ret, self.data[L-1])
                L += 1
            L >>= 1
            R >>= 1
        return ret


N = int(input())
S = input()
Q = int(input())
queries = [list(input().split()) for _ in range(Q)]


def a2n(a):
    return ord(a)-ord("a")


def createInp(a):
    return 1 << a2n(a)


Seg = SegmentTree(len(S), lambda x, y: x | y, init=0)
for i, s in enumerate(S):
    Seg.set(i, createInp(s))
Seg.build()

for q, l, r in queries:
    if q == "1":
        Seg.update(int(l)-1, createInp(r))
    else:
        print(bin(Seg.query(int(l)-1, int(r))).count('1'))


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

int main() {
    int A, B; std::cin >> A >> B;
    if (A % 3 == 0 || B % 3 == 0 || (A + B) % 3 == 0)
        std::cout << "Possible\n";
    else 
        std::cout << "Impossible\n";
}


Measured memory_bytes: 256
d=[0]*13
d[0]=1
m=1
mmod=1
t=input()[::-1]
mod=10**9+7
zero=[0]*13

for c in t:
    e=zero[:]
    if c=="?":
        for i in range(10):
            for j in range(13):
                k=(i*m+j)%13
                e[k]+=d[j]
                e[k]%=mod
    else:
        for j in range(13):
            k=(int(c)*m+j)%13
            e[k]+=d[j]
            e[k]%=mod
    d=e
    m=10*m%13
print(d[5])



Measured memory_bytes: 45088
import sys

read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines
sys.setrecursionlimit(10 ** 9)
INF = 1 << 60
MOD = 1000000007


def main():
    N, *H = map(int, read().split())

    ans = 0
    while True:
        changed = changed2 = False
        for i in range(N):
            if H[i] > 0:
                H[i] -= 1
                changed = True
                changed2 = True
            else:
                if changed:
                    ans += 1
                    changed = False
        if changed:
            ans += 1
        if not changed2:
            break

    print(ans)
    return


if __name__ == '__main__':
    main()


Measured memory_bytes: 9192
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using V = vector<ll>;
#define _GLIBCXX_DEBUG
#define rep(i, a, b) for(int i = a; i < b; i++)
#define ALL(v) v.begin(), v.end()

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


Measured memory_bytes: 256
/*
এইসব বৃত্ত থাকুক। থাকুক আমার কড়া পাহারা। তারপরও অসাবধানে ঢুকে পড়ুক কিছু মানুষ। 
তারপর চলে যাইতে চাইলে চলে যাক। বলব, ভালো থাকবেন। আবার দেখা হবে।
*/

#include <bits/stdc++.h>
using namespace std;

#define EPS (1e-9)
#define ll long long int
#define ull unsigned long long
#define pi (acos(-1.0))
#define endl "\n"
#define all(v) v.begin(),v.end()
#define printa(a,L,R) for(int i=L;i<R;i++) cout<<a[i]<<(i==R-1?'\n':' ')
#define precise(n) cout << fixed << setprecision(n)
#define show(a) cout << (#a) << " is " << (a) << endl;
#define pcase cout<<"Case "<<++cs<<": "
#define FAST ios_base::sync_with_stdio(0); cin.tie(0);
const int mod=1e9+7;
const int mx=1e5+10;
ll binpow(ll base, ll exp){ll res = 1;while(1){ if(exp&1) res*=base;exp>>=1;if(!exp)break;base*=base;}return res;}
	int n,m;
	string s[1005];
 int dp[1005][1005];

 int func(int i,int j)
 {
 	if(i>=n||j>=m) return 0;
 	if(i==n-1&&j==m-1) return 1;
 	if(s[i][j]=='#') return 0;

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

 	int x,y;
 	 x=func(i+1,j);
 	 y=func(i,j+1);
 	 return dp[i][j]=(x+y)%mod;

 }

int main(int argc, char const *argv[])
{
	FAST
	cin >> n >> m;
	for (int i = 0; i < n; ++i )
	{
			cin >> s[i];
	}
	memset(dp,-1,sizeof(dp));

	cout << func(0,0) << endl;


    
	
	

	return 0;
}

Measured memory_bytes: 5376
#include <bits/stdc++.h>
using namespace std;
int main(){
  int K, N; cin >> K >> N;
  int pos[N] = {}, Mrange = 0;
  for(int i = 0; i < N; i++) cin >> pos[i];
  for(int i = 0; i < N; i++) Mrange = max((pos[(i + 1) % N] + K - pos[i]) % K, Mrange);
  cout << K - Mrange << endl;
  return 0;
}

Measured memory_bytes: 1024
#include <algorithm>
#include <array>
#include <cassert>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <limits>
#include <map>
#include <numeric>
#include <queue>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>
#define FOR(i,a,b) for (int i=(a),for_##i##_max=(b);i<=(for_##i##_max);++i)
#define RFOR(i,a,b) for (int i=(a),rfor_##i##_min=(b);i>=(rfor_##i##_min);--i)
#define REP(i,n) for (int i=0,rep_##i##_len=(n);i<(rep_##i##_len);++i)
#define RREP(i,n) for (int i=(n)-1;i>=0;--i)

namespace { // Basics

template<typename T>
void chmin(T &x, T y) {
  x = std::min(x, y);
}

template<typename T>
void chmax(T &x, T y) {
  x = std::max(x, y);
}

template<typename T>
__attribute__((unused))
const auto minimum = static_cast<T const &(*)(T const &, T const &)>(std::min);

template<typename T>
__attribute__((unused))
const auto maximum = static_cast<T const &(*)(T const &, T const &)>(std::max);

template<typename T>
__attribute__((unused))
T constexpr infty = std::numeric_limits<T>::max / 3;
template<>
__attribute__((unused))
auto constexpr infty<int> = 1'100'100'100;
template<>
__attribute__((unused))
auto constexpr infty<long long int> = 100'500'400'300'200'100LL;

using lli = long long int;
using ld = long double;

} // namespace

using namespace std;

template <typename T>
struct node_t {
  T key;
  node_t *lc, *rc;
  explicit node_t(T v): key(v), lc(nullptr), rc(nullptr) {}
};

template <typename T>
void insert(node_t<T> *&t, T v) {
  using ptr_t = node_t<T> *;
  ptr_t z = new node_t<T>(v);
  ptr_t y = nullptr;
  ptr_t x = t;
  while (x) {
    y = x;
    if (z->key < x->key) {
      x = x->lc;
    } else {
      x = x->rc;
    }
  }
  if (!y) {
    t = z;
  } else if (z->key < y->key) {
    y->lc = z;
  } else {
    y->rc = z;
  }
}

template <typename T>
void inorder_walk(node_t<T> *t) {
  using ptr_t = node_t<T> *;
  stack<tuple<ptr_t, bool>> stk;
  stk.emplace(t, false);
  while (!stk.empty()) {
    ptr_t ptr; bool op;
    tie(ptr, op) = stk.top(); stk.pop();
    if (!ptr) { continue; }
    if (op) {
      cout << " " << ptr->key;
    } else {
      stk.emplace(ptr->rc, false);
      stk.emplace(ptr, true);
      stk.emplace(ptr->lc, false);
    }
  }
  cout << endl;
}

template <typename T>
void preorder_walk(node_t<T> *t) {
  using ptr_t = node_t<T> *;
  stack<ptr_t> stk;
  stk.push(t);
  while (!stk.empty()) {
    auto const ptr = stk.top(); stk.pop();
    if (!ptr) { continue; }
    cout << " " << ptr->key;
    stk.push(ptr->rc);
    stk.push(ptr->lc);
  }
  cout << endl;
}

int main() {
  using Tree = node_t<lli> *;
  Tree tree = nullptr;
  int M; cin >> M;
  REP(query, M) {
    string S; cin >> S;
    if (S[0] == 'i') {
      lli K; cin >> K;
      insert(tree, K);
    } else {
      inorder_walk(tree);
      preorder_walk(tree);
    }
  }
  return 0;
}



Measured memory_bytes: 18632
#include <iostream>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <algorithm>
#include <string>
#include <vector>
using namespace std;
typedef long long ll;
int ans=0;
int main(void){
	int i,j,n;
	cin>>n;
	for(i=0;i<=30;++i){
	  for(j=0;j<=30;++j){
	    if(i*7+j*4==n){
	      cout<<"Yes\n";
	      return 0;
	    }
	  }
	}
	cout<<"No\n";
	return 0;
}

Measured memory_bytes: 256
#include<iostream>

using namespace std;
#define rep(i, n) for ( int i = 0; i < n; i++ )
#define MAX 200
#define INFTY (1<<21)
int n, m, T[MAX][MAX], P[MAX][MAX];

void valid(int sx, int sy, int &lx, int &ly ){
    int ax = -1, ay;
    rep(y, m) rep(x, m){
	if ( P[x][y] == -1 ) continue;
	if ( P[x][y] != T[sx+x][sy+y] ) return;
	if ( ax == -1 ) {ay = y; ax = x;}
    }
    if ( ay < ly || (ay == ly && ax < lx) ) {ly = sy+ay; lx = sx+ax; }
}

bool rotate(int sx, int sy){
    int tmp[MAX][MAX];
    int ly = INFTY, lx;
    rep(r, 4){
	valid(sx, sy, lx, ly);
	rep(y, m) rep(x, m) tmp[x][y] = P[x][y];
	rep(y, m) rep(x, m) P[y][m-x-1] = tmp[x][y];
    }
    if ( ly == INFTY ) return false;
    cout << lx+1 << " " << ly+1 << endl;
    return true;
}

void compute(){
    rep(y, n-m+1) rep(x, n-m+1) if ( rotate(x, y) ) return;
    cout << "NA" << endl;
}

main(){
    while( cin >> n >> m && n ){
	rep(y, n) rep(x, n) cin >> T[x][y];
	rep(y, m) rep(x, m) cin >> P[x][y];
	compute();
    }
}

Measured memory_bytes: 1036
N,M = map(int,input().split())
A = []
B = []
C = []
D = []
ans = []

for i in range(N):
    a,b = map(int,input().split())
    A.append(a)
    B.append(b)

for j in range(M):
    c,d = map(int,input().split())
    C.append(c)
    D.append(d)

for i in range(N):
    item = abs(A[i]-C[0])+abs(B[i]-D[0])
    index = 1
    for j in range(M):
        if item > abs(A[i]-C[j])+abs(B[i]-D[j]):
            item = abs(A[i]-C[j])+abs(B[i]-D[j])
            index = j+1
    ans.append(index)

for i in range(len(ans)):
    print(ans[i])

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

int main(void){
  int ans = 0;
  int N, M; cin >> N >> M;
  vector<int> pre(N, true);
  vector<int> v;
  for(int i = 0; i < M; i++){
    int a; cin >> a;
    pre[i] = false;
  }
  while(1){
    v = vector<int>( pre.size() / 2, true);
    for(int i = 0; i < pre.size(); i+=2){
      if(pre[i] == false && pre[i+1] == false){
        v[i/2] = false;
      } else if(pre[i] == false || pre[i+1] == false){
      
      } else{
        ans++;
      }
    }

    if(v.size() == 1) break;
    pre = v;
  }
  cout << ans << endl;
}

Measured memory_bytes: 3080
#include 	<stdio.h>

#define		STRL		12

typedef struct
{
	char	name[STRL];
	int		time;
}QUEUE;

int		main(void)
{
	int		n, q;
	int		pre = 0;
	int		rear = 0;
	int		cnt = 0;
	int		size;

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

	size = 2*n;
	QUEUE	Queue[size];

	for( rear = 0; rear < n; rear++ )
	{
		scanf("%s %d",Queue[rear].name, &Queue[rear].time);
	}
	while( pre != rear )
	{
		if( Queue[pre].time <= q )
		{
			cnt += Queue[pre].time;
			printf("%s %d\n",Queue[pre].name,cnt );
		}
		else
		{
			cnt += q;
			Queue[pre].time -= q;
			Queue[rear] = Queue[pre];
			rear = (rear + 1) % size;
		}
		pre = (pre +1) % size;
	}
	return 0;
}

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

#define PI 3.141592
int n;

void koch(int count,double lx,double ly,double rx,double ry){
	
	if(count == 0) return;
	
	double lx1 = lx + (rx - lx) / 3;
	double ly1 = ly + (ry - ly) / 3;
	double rx1 = rx - (rx - lx) / 3;
	double ry1 = ry - (ry - ly) / 3;
	// 物理A1の回転行列思い出して、どうぞ
	double cx = lx1 + (rx1 - lx1) * cos(PI / 3) - (ry1 - ly1) * sin(PI / 3);
	double cy = ly1 + (rx1 - lx1) * sin(PI / 3) + (ry1 - ly1) * cos(PI / 3);
	
	koch(count - 1, lx, ly, lx1, ly1);
	printf("%f %f\n", lx1, ly1);
	koch(count - 1, lx1, ly1, cx, cy);
	printf("%f %f\n", cx, cy);
	koch(count - 1, cx, cy, rx1, ry1);
	printf("%f %f\n", rx1, ry1);
	koch(count - 1, rx1, ry1, rx, ry);
	
}

int main(void){
	double lx = 0;
	double ly = 0;
	double rx = 100;
	double ry = 0;
	scanf("%d",&n);
	printf("%f %f\n", lx, ly);
	koch(n,0,0,100,0);
	printf("%f %f\n", rx, ry);
	return 0;
}


Measured memory_bytes: 2120
import java.util.Scanner;

public class Main{
    public static void main(String args[]){
        Scanner input = new Scanner(System.in);
        while(input.hasNextLine()){
            String word = input.next();
            if(word.compareTo("-") == 0)
                break;
            int times = input.nextInt();
            for(int i = 0; i < times; i ++ ){
                int num = input.nextInt();
                String sub_1 = word.substring(0, num);
                String sub_2 = word.substring(num, word.length());
                word = sub_2 + sub_1;
            }
            System.out.println(word);
        }
    }
}


Measured memory_bytes: 26224
#include <bits/stdc++.h>
using namespace std;
#define ll long long int
#define rep(i,s,f) for(i=s;i<f;i++)
#define print(v) for(auto &z:v) cout<<z<<' ';cout<<'\n'
#define hi cout<<'h'<<'i'<<'\n' 
#define pb push_back
#define pii pair<int,int>
#define F first
#define S second
#define B begin()
#define E end()
#define all(v) v.B,v.E
#define sz(v) (int)((v).size())
#define vi vector<int>
#define vii vector<pair<int,int>>
#define boost ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#define clk1 clock_t start_time=clock()
#define clk2 cout<<(clock()-start_time)/(double)CLOCKS_PER_SEC
#define clean(arr) memset(arr,0,sizeof(arr))
#define mod 1000000007
#define mod2 998244353
#define space 100005
//<<fixed << setprecision(9)
vector<vi> Q;
ll ans=0;
vi arr;
int n,m;
void rec(int last,int cur)
{
    int i;
    if(cur==n+1)
    {
        ll temp=0;
        for(auto &z:Q)
        {
            if((arr[z[1]-1]-arr[z[0]-1]) ==z[2])temp+=z[3];
        }
        ans=max(ans,temp);
        return ;
    }
    rep(i,last,m+1) 
    {
        arr.pb(i);
        rec(i,cur+1);
        arr.pop_back();
    }
}
int main()
{
    int i,j,t;
    boost;
    int q;
    cin>>n>>m>>q;
    while(q--)
    {
        vi v(4);
        rep(i,0,4)cin>>v[i];
        Q.pb(v);
    }
    rec(1,1);
    cout<<ans;
    return 0;
}



Measured memory_bytes: 3664
// Problem : G - Longest Path
// Contest : Educational DP Contest
// URL : https://atcoder.jp/contests/dp/tasks/dp_g
// Memory Limit : 1024 MB
// Time Limit : 2000 ms
// Powered by CP Editor (https://github.com/cpeditor/cpeditor)
//#pragma GCC optimize "trapv"//  WA to RE int!!
#include <bits/stdc++.h>
#define FOR(i,n) for(long long int i=0;i<n;i++)
#define FORR(i,n) for(long long int i=n;i>=0;i--)
#define pb push_back
#define vlli vector<long long int>
#define slli set<long long int>
#define mlli map<long long int,long long int>
#define lli long long int 
#define test lli tt1234; cin>>tt1234;while(tt1234--)
#define endl "\n"
#define all(zz) zz.begin(),zz.end()
#define rep(i, begin, end) for (__typeof(end) i = (begin) - ((begin) > (end)); i != (end) - ((begin) > (end)); i += 1 - 2 * ((begin) > (end)))
#define error(x) cerr << #x <<" is " << x << endl;
#define fast ios_base::sync_with_stdio(false);cin.tie(NULL);
#define fint fast;test
#define set(a,x) memset(a,x,sizeof(a))
#define L(x)	((x)<<1)
#define R(x)	(((x)<<1)+1)
#define MOD 1000000007
using namespace std;
const int nax=1e5+5;
vector<int> edges[nax];
int in_degree[nax];
int dist[nax];
bool visited[nax];

void dfs(int a){
	assert(!visited[a]);
	visited[a]=true;
	for(int b:edges[a]){
		dist[b]=max(dist[b],dist[a]+1);
		--in_degree[b];
		if(in_degree[b]==0){
			dfs(b);
		}
	}
}

void solve(){
	int n,m;
	cin>>n>>m;
	while(m--){
		int a,b;
		cin>>a>>b;
		edges[a].pb(b);
		++in_degree[b];
	}
	rep(i,1,n+1){
		if(!visited[i] && in_degree[i]==0){
			dfs(i);
		}
	}
	int answer=0;
	rep(i,1,n+1) answer=max(answer,dist[i]);
	cout<<answer;
	
}


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



Measured memory_bytes: 9728
#include <bits/stdc++.h>
typedef long long ll;
using namespace std;
const int N =2e5+10 , M = 5e5+10, OO = 0x3f3f3f3f ,  MOD = 1e9+7;
const double EPS = 1e-3;
#define M_PI 3.14159265358979323846
#define clr(arr,val) memset(arr , val , sizeof (arr))
#define loop(i,n) for(int i = 0;i < int(n);i++)
#define rloop(i,n) for(int i = int(n)-1;i >= 0;i--)
#define range(i,a,b) for(int i = int(a);i <= int(b);i++)
#define pb push_back
#define F first
#define S second
#define all(v) ((v).begin()) , ((v).end())
#define sz(v)  ((int)((v).size()))
typedef pair <int,int> pii ;
typedef vector < pii > vii ;
int dx[]={1,0,-1,0};int dy[]={0,1,0,-1}; //4 Direction
//int dx[]={1,1,0,-1,-1,-1,0,1};int dy[]={0,1,1,1,0,-1,-1,-1};//8 direction
//int dx[]={2,1,-1,-2,-2,-1,1,2};int dy[]={1,2,2,1,-1,-2,-2,-1};//Knight Direction
//int dx[6]={2,1,-1,-2,-1,1};int dy[6]={0,1,1,0,-1,-1}; //Hexagonal Direction
//freopen("input.txt", "r", stdin);
//freopen("output.txt", "w", stdout);

ll a , b;




int main(){


    //ios_base::sync_with_stdio(0);
    //cin.tie(0);cout.tie(0);

	scanf("%lld %lld" ,&a,&b);
	
	cout << ((1ll*a*b)/__gcd(a , b)) << "\n";





    return 0;
}

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

#define ll long long 
#define inf 0x3f3f3f3f
#define infll 0x3f3f3f3f3f3f3f3f
#define all(x) (x).begin(),(x).end()
#define f(i, a, b) for (int i=a; i<(signed)(b); ++i)
#define pc __builtin_popcount // counts number of 1's in bin(num)

const double pi = 2*acos(0.0);
//__gcd(n1, n2);
//cout << fixed;
//cout << setprecision(6); //fixes # of dp


int dp[110][100][2];

int main(){
	ios::sync_with_stdio(0);
	cin.tie(0);
    cout.tie(0);
	
    string s; int k;
    cin >> s >> k;
    dp[0][0][0] = 1;
    f(i, 0, s.length()) {
        int tmp = s[i] - '0';
        f(j, 0, 5) {
            f(l, 0, 2) {
                for (int d = 0; d <= (l ? 9 : tmp); ++d) {
                    dp[i + 1][j + (d != 0)][l || (d < tmp)] += dp[i][j][l];
                }
            }
        }
    }
    cout << dp[s.size()][k][0] + dp[s.size()][k][1] << endl;
    

}   








Measured memory_bytes: 384
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0; i < n; i++)
#define ALL(v) (v).begin(), (v).end()

using namespace std;
using ll = long long;

int main()
{
  int K, X; cin >> K >> X;
  for (int i = X-(K-1); i <= X+K-1; ++i) {
    cout << i;
    if (i != X+K-1) cout << " ";
  }
  cout << endl;
}

Measured memory_bytes: 256
//include
//------------------------------------------
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <queue>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <fstream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <string>
#include <cstring>
#include <ctime>
#include <climits>
#include <limits>

using namespace std;

//conversion
//------------------------------------------
inline int toInt(string s) { int v; istringstream sin(s); sin >> v; return v; }
template<class T> inline string toString(T x) { ostringstream sout; sout << x; return sout.str(); }

//math
//-------------------------------------------
template<class T> inline T sqr(T x) { return x * x; }

//typedef
//------------------------------------------
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef long long LL;

//container util
//------------------------------------------
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define EXISTch(s,c) ((((s).find_first_of(c)) != std::string::npos)? 1 : 0)//cがあれば1 if(1)
#define SORT(c) sort((c).begin(),(c).end())

#define REP(i,n) for(int i=0;i<(int)n;++i)
#define FOR(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)

//constant
//--------------------------------------------
const double EPS = 1e-10;
const double PI = acos(-1.0);
const int INF = (int)1000000007;
const LL MOD = (LL)1000000007;//10^9+7
const LL INF2 = (LL)100000000000000000;//10^18

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

	for (int i = 1; i < 10; i++) {
		for (int j = 1; j < 10; j++) {
			if (i*j == n) {
				cout << "Yes" << endl;
				return 0;
			}
		}
	}

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

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <iomanip>
#include <algorithm>
#define ll long long
#include <unordered_map>
using namespace std;

int main() {
  ll N, cnt = 0;
  cin >> N;
  vector<ll> L(N), T(3);
  for(ll i = 0; i < N; i++) cin >> L.at(i);
  
  for(ll i = 0; i < N - 2; i++) {
    for(ll j = i + 1; j < N - 1; j++) {
      for(ll k = j + 1; k < N; k++) {
        if((L.at(i) != L.at(j)) && (L.at(i) != L.at(k)) && (L.at(j) != L.at(k))) {
          T.at(0) = L.at(i);
          T.at(1) = L.at(j);
          T.at(2) = L.at(k);
          sort(T.begin(), T.end());
          if(T.at(0) + T.at(1) > T.at(2)) cnt++;
        }
      }
    }
  }
  
  cout << cnt << endl;
}

Measured memory_bytes: 3624
#!/usr/bin/bash

read n;
ans=0
for i in `seq 1 ${n}`
do
    tmp=0
    for j in `seq 1 ${i}`
    do
	if [ $((($i)%($j))) -eq 0 ]; then
	    tmp=$((${tmp}+1))
	fi	
    done
    if [ ${tmp} -eq 8 ]; then
	if [ $(($i%2)) -eq 1 ]; then
	    ans=$((${ans}+1))
	fi
    fi   
done
echo $ans


Measured memory_bytes: 792
#include <iostream>
#include <cmath>
using namespace std;
int main()
{
    int a,b,c;
    cin >> a >> b >> c;
    if(abs(a - b) > abs(a - c))
    {
        cout << "B\n";
    }
    else
    {
        cout << "A\n";
    }
    return 0;
}

Measured memory_bytes: 256
n,m,l=map(int,input().split())
A=[[0 for _ in range(m)] for _ in range(n)]
B=[[0 for _ in range(l)] for _ in range(m)]
C=[[0 for _ in range(l)] for _ in range(n)]

for i in range(n):
    A[i]=list(map(int,input().split()))
for i in range(m):
    B[i]=list(map(int,input().split()))

for i in range(n):
        for j in range(l):
            save=0
            for k in range(m):
                save+=A[i][k]*B[k][j]
            C[i][j]=save
            if j==0:
                print(C[i][j],end="")
            else:
                print("",C[i][j],end="")
        print()


Measured memory_bytes: 7164
import java.util.HashMap;
import java.util.Map;
import java.util.Scanner;
import java.util.stream.IntStream;

/**
 * https://atcoder.jp/contests/abc168/submissions/14643189 を参考に作成
 */
public class Main {

	private static final long MOD = 1_000_000_007L;

	public static void main(String[] args) {
		try (Scanner scanner = new Scanner(System.in)) {
			int n = scanner.nextInt();
			int zero = 0;
			Tupple zeroTupple = new Tupple();
			Map<String, Tupple> map = new HashMap<>();
			map.put("0", zeroTupple);
			// p2[i] = 2^i mod MOD の配列
			long[] p2 = new long[n + 1];
			p2[0] = 1;
			IntStream.rangeClosed(1, n).forEach(i -> p2[i] = p2[i - 1] * 2 % MOD);
			for (int i = 0; i < n; i++) {
				long a = scanner.nextLong(), b = scanner.nextLong();
				if ((0 == a) && (0 == b)) {
					zero++;
				} else if (0 == a) {
					zeroTupple.a++;
				} else if (0 == b) {
					zeroTupple.b++;
				} else {
					if (b < 0) {
						a = -a;
						b = -b;
					}
					long gcd = gcd(Math.abs(a), Math.abs(b));
					a /= gcd;
					b /= gcd;
					String key = (a > 0) ? a + "/" + b : b + "/" + (-a);
					Tupple tupple = map.get(key);
					if (null == tupple) {
						tupple = new Tupple();
						map.put(key, tupple);
					}
					if (a > 0) {
						tupple.a++;
					} else {
						tupple.b++;
					}
				}
			}
			long answer = 1L;
			for (Tupple tupple : map.values()) {
				answer = answer * (p2[tupple.a] + p2[tupple.b] - 1) % MOD;
			}
			answer = (answer + zero + MOD - 1) % MOD;
			System.out.println(answer);
		}
	}

	/**
	 * mとnの最大公約数を返す
	 * 
	 * @param m
	 * @param n
	 * @return mとnの最大公約数
	 */
	private static long gcd(long m, long n) {
		if (0 == n) {
			return m;
		}
		return gcd(n, m % n);
	}

	/**
	 * aとbを格納するクラス
	 */
	private static class Tupple {
		int a = 0;
		int b = 0;
	}
}


Measured memory_bytes: 94880
/***
**   AUTHOR::ASHUTOSH MOUDGIL
***/


#include<bits/stdc++.h>
using namespace std;

#define pb push_back
#define mp make_pair
#define IOS ios_base::sync_with_stdio(false); cin.tie(NULL);
#define F first
#define S second
#define int long long
//#define ll long long
#define all(x) x.begin(),x.end()
#define rsort(x) sort(all(x)); reverse(all(x));
#define endl '\n'
#define gcd(a,b) __gcd((a),(b))
#define lcm(a,b) ((a)*(b))/gcd((a),(b))
#define vi vector<int>
#define vlli vector<long long>
#define pii pair<int,int>
#define mod 1000000007
#define LMAX 1e18
#define deb(x) cout<<#x<<" : "<<x<<endl;


void mymain(){
    int n;
    cin >> n;
    int o=0;
    for(int i=1;i<=n;i++)
        if(i&1)
        o++;
    cout <<fixed<<setprecision(10)<< double(o)/n << endl;
}

signed main(){
IOS;
///freopen("input.txt", "r", stdin);
///freopen("output.txt", "w", stdout);
int t=1;
///cin>>t;

for(int tt=0;tt<t;tt++){
   ///cout << "Case #" << tt+1 <<": ";
   mymain();
   }
return 0;
}


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

inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}

template<class T> inline T sqr(T x) {return x*x;}

typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef long long LL;
typedef unsigned long long ULL;

#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())

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

const double EPS = 1e-10;
const double PI  = acos(-1.0);

#define CLR(a) memset((a), 0 ,sizeof(a))

#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

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

int main() {
  int t[4];

  cin >> t[0] >> t[1] >> t[2] >> t[3];
  int sum = 0;
  REP(i, 4) sum += t[i];

  int x = sum / 60;
  int y = sum % 60;

  cout << x << endl;
  cout << y << endl; 
}

Measured memory_bytes: 1160
from collections import defaultdict   
def C():
    N, M = map(int, input().split())
    H = [int(n) for n in input().split()]
    isGood = [True for i in range(len(H))]
    for i in range(M):
        A, B = map(int, input().split())
        if H[A-1] >= H[B-1]:
            isGood[B-1] = False
        if H[B-1] >= H[A-1]:
            isGood[A-1] = False
    count = 0
    for b in isGood:
        if b:
            count += 1
    print(count)

C()

Measured memory_bytes: 20528
#include<iostream>
#include<queue>
#include<utility>
#include<algorithm>
using namespace std;
#define N_MAX 100001
typedef pair<int,int> P;

int main(){
  int N,R,L;
  int d,t,x;
  int time[N_MAX]={0};
  int score[N_MAX]={0};
  cin >> N >> R >> L;
  priority_queue<P> que;
  for(int i=1;i<=N;i++){
    que.push(P(0,N-i));
  }
  int now = 0;
  for(int j=0;j<R;j++){
    cin >> d >> t >> x;
    P p1 = que.top();
    while(score[N-p1.second] != p1.first){
      que.pop();
      p1 = que.top();
    }
    time[N-p1.second] += t - now;
    now = t;
    score[d] += x;
    que.push(P(score[d],N-d));
  }
  P p1 = que.top();
  while(score[N-p1.second] != p1.first){
    que.pop();
    p1 = que.top();
  }
  time[N-p1.second] += L - now;
  priority_queue<P> que2;
  for(int i=1;i<=N;i++){
    que2.push(P(time[i],N-i));
  }
  p1 = que2.top();
  cout << N - p1.second << endl;
}

Measured memory_bytes: 11196
l, r = gets.split.map(&:to_i)

min = 2019
(l..r - 1).each do |i|
  (i + 1..r).each do |j|
    m = (i * j) % 2019
    min = m if m < min
    if min == 0
      puts 0
      exit
    end
  end
end

puts min


Measured memory_bytes: 1788
/*#include <boost/multiprecision/cpp_dec_float.hpp>
#include <boost/multiprecision/cpp_int.hpp>

#include <boost/rational.hpp>
*/
#include <bits/stdc++.h>
using namespace std;
#define _GLIBCXX_DEBUG
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
using ll = long long;
using ld = long double;
#define rep2(i, s, n) for (ll i = (s); i < (ll)(n); i++)
#define rep3(i, n) for (ll i = 1; i < (ll)(n+1); i++)
#define rep4(i, s, n) for (ll i = (s); i < (ll)(n+1); i++)
#define repr(i,n) for (ll i = (n-1); i>=0;i--)
#define repr3(i,n) for(ll i = (n);i>0;i--)
#define repr4(i,s,n) for(ll i = (n);i>=(s);i--)
#define stlen(s) ll s.size()-1
#define all(v) v.begin(), v.end()
#define cout(n) cout<<std::fixed<<std::setprecision(n)
using Graph = vector<vector<int>>;
using Graphw = vector<vector<pair<ll,ll>>>;
#define INF1  INT_MAX;
#define INF2  LLONG_MAX;
#define PI  3.14159265358979323846;
#define MOD 1000000007;
/*
namespace mp = boost::multiprecision;
// 任意長整数型
using Bint = mp::cpp_int;
// 仮数部長が32の浮動小数点数型
using Real32 = mp::number<mp::cpp_dec_float<32>>;
// 仮数部長が1024の浮動小数点数型
using Real1024 = mp::number<mp::cpp_dec_float<1024>>;
// 有理数型
using Rat = boost::rational<Bint>;
*/




int main() {
int r;
cin>>r;
cout<<r*r<<endl;
return 0;
}

Measured memory_bytes: 3632
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,copy,functools

sys.setrecursionlimit(10**7)
inf = 10**20
eps = 1.0 / 10**10
mod = 998244353
dd = [(-1,0),(0,1),(1,0),(0,-1)]
ddn = [(-1,0),(-1,1),(0,1),(1,1),(1,0),(1,-1),(0,-1),(-1,-1)]

def LI(): return list(map(int, sys.stdin.readline().split()))
def LLI(): return [list(map(int, l.split())) for l in sys.stdin.readlines()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def S(): return input()
def pf(s): return print(s, flush=True)
def pe(s): return print(str(s), file=sys.stderr)
def JA(a, sep): return sep.join(map(str, a))
def JAA(a, s, t): return s.join(t.join(map(str, b)) for b in a)


def main():
    s = S()
    for i in range(len(s)-1):
        if s[i] == s[i+1]:
            return 'Bad'

    return 'Good'


print(main())



Measured memory_bytes: 5076
fun main(args: Array<String>) {
    val s = readLine()!!
    val t = readLine()!!

    val sb=StringBuilder()
    for(i in 0..t.lastIndex){
        sb.append(s[i]).append(t[i])
    }
    if(s.length>t.length)sb.append(s.last())
    println(sb)

}

Measured memory_bytes: 31804
#include<stdio.h>
int main(){
    int H,W,N,ANS;
    int K=1,c=1;
    scanf("%d %d %d",&H,&W,&N);
    if(H>=W){
        K=H;
    }else{
        K=W;
    }
    for(c=1;c<N;c++){
        ANS=K*c;
        if(ANS>=N){
            break;
        }else{

        }

    }

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

Measured memory_bytes: 128
#include <iostream>
#include <algorithm>
#include <utility>
#include <string>
#include <vector>
#include <set>
#include <stack>
#include <queue>
#include <map>
#include <math.h>
#include <string.h>
#include <iomanip>
#include <numeric>
#include <cstdlib>
#include <cstdint>
#include <cmath>
#include <functional>
#include <limits>
#include <cassert>
#include <bitset>

using namespace std;

/* template */

using ll = long long;

void debug_out() { std::cout << endl; }
 
template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
  cout << H << " ";
  debug_out(T...);
}

#ifdef LOCAL
#define debug(...) cout << "debug: "; debug_out(__VA_ARGS__)
#else
#define debug(...) 
#endif

#define rep(i, a, n) for (int i = (int)(a); i < (int)(n); i++)
#define rrep(i, a, n) for (int i = ((int)(n-1)); i >= (int)(a); i--)
#define Rep(i, a, n) for (long long i = (long long)(a); i< (long long)(n); i++)
#define RRep(i, a, n) for (long long i = ((long long)(n-1ll)); i>=(long long)(a); i--)
#define all(v) (v).begin(),(v).end()
#define rall(v) (v).rbegin(),(v).rend()

template <typename T>
std::ostream& operator<<(std::ostream& os, std::vector<T> vec) {
  for (std::size_t i = 0; i < vec.size(); i++)os << vec[i] << (i + 1 == vec.size() ? "" : " ");
  return os;
}

struct Edge{
    int to;
    int weight;
    Edge(int t, int w) : to(t), weight(w){ }
};

struct edge{
    int from;
    int to;
    int weight;
    edge(int f,int t,int w) : from(f), to(t), weight(w){ }
};


using Graph = vector<vector<Edge>>;
using graph = vector<vector<int>>;
using edges = vector<edge>;

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

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

template <class T>
T lcm(T a, T b){
    return (a*b)/gcd(a,b);
}

bool isPalindrome(string s){
    string t = s;
    reverse(all(t));
    return s==t;
}

constexpr ll INF = 1e18+7;

vector<int> dx = {-1,0,1,0};
vector<int> dy = {0,-1,0,1};

/* template */


int main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    int n; cin >> n;
    vector<int> b(n,0);
    rep(i,0,n-1){
        int a; cin >> a;
        a--;
        b[a]++;
    }
    rep(i,0,n){
        cout << b[i] << endl;
    }
}

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

int nr, nc;
vector<vector<char>> grid(20, vector<char>(20));
vector<vector<bool>> seen(20, vector<bool>(20, false));

class C {
public:
    int x, y, d;
    C(int a, int b, int c) {
        x = a;
        y = b;
        d = c;
    }
};

int main() {
  cin>>nr>>nc;
  for (int i = 0; i < nr; ++i) {
    for (int j = 0; j < nc; ++j) {
      cin >> grid[i][j];
    }
  }
/*
  for (int i = 0; i < nr; ++i) {
      for (int j = 0; j < nc; ++j) {
          cout << grid[i][j];
      }
      cout << endl;
  }
*/

  int ans = 0;
  for (int i = 0; i < nr; ++i) {
      for (int j = 0; j < nc; ++j) {
          if (grid[i][j] == '#') continue;

          queue<C> q;
          q.push(C(i, j, 0));
          seen[i][j] = true;
          int local_best = 0;
          while (q.size()) {
              C e = q.front(); q.pop();
              local_best = max(local_best, e.d);
              if (e.x > 0 && grid[e.x-1][e.y] == '.' && !seen[e.x-1][e.y]) {
                  q.push(C(e.x-1, e.y, e.d+1));
                  seen[e.x-1][e.y] = true;
              }
              if (e.x < nr - 1 && grid[e.x+1][e.y] == '.' && !seen[e.x+1][e.y]) {
                  q.push(C(e.x+1, e.y, e.d+1));
                  seen[e.x+1][e.y] = true;
              }
              if (e.y > 0 && grid[e.x][e.y-1] == '.' && !seen[e.x][e.y-1]) {
                  q.push(C(e.x, e.y-1, e.d+1));
                  seen[e.x][e.y-1] = true;
              }
              if (e.y < nc - 1 && grid[e.x][e.y+1] == '.' && !seen[e.x][e.y+1]) {
                  q.push(C(e.x, e.y+1, e.d+1));
                  seen[e.x][e.y+1] = true;
              }
          }

          ans = max(ans, local_best);
          for (int k = 0; k < nr; ++k)
              for (int l = 0; l < nc; ++l)
                  seen[k][l] = false;
      }
  }
  cout << ans << endl;


  return 0;
}


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

int main() {
  long long n,l,b,ans;
  cin>>n>>l>>b;
  long long a[n];
  for(int i=0;i<n;i++){
    long long k;
    cin>>k;
    a[i]=k;
  }
  if(n==1)ans=abs(a[0]-b);
  else{
    ans=max(abs(a[n-1]-a[n-2]),abs(a[n-1]-b));
  }
  cout<<ans<<endl;
}


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

using namespace std;

vector<string> split(const string &s, char delim) {
  vector<string> elems;
  string item;
  for (char ch: s) {
    if (ch == delim) {
      if (!item.empty()) {
        elems.push_back(item);
      }
      item.clear();
    }
    else {
      item += ch;
    }
  }
  if (!item.empty()) {
    elems.push_back(item);
  }
  return elems;
}

string to_str_with_zero(int i, int w) {
  ostringstream sout;
  sout << std::setfill('0') << std::setw(w) << i;
  string s = sout.str();
  return s;
}

int letter_to_int(char c) {
  return tolower(c) - 'a';
}

bool array_equal(vector<int> a1, vector<int>a2) {
  if (a1.size() != a2.size()) {
    return false;
  }
  for (int i=0; i<a1.size(); i++) {
    if (a1.at(i) != a2.at(i)) {
      return false;
    }
  }
  return true;
}

int gcd(int a, int b) {
  if (a == b) {
    return a;
  }
  else if (a > b) {
    return gcd(a - b, b);
  }
  else {
    return gcd(a, b - a);
  }
}

char int_to_char(int a) {
  if (a == -1) {
    return 'z';
  }
  else {
    return 'a' + a;
  }
}

long nCr(int n, int r) {
    long ans = 1;
    for (int i = n; i > n - r; --i) {
        ans = ans*i;
    }
    for (int i = 1 ; i < r + 1; ++i) {
        ans = ans / i;
    }
    return ans;
}

long long modinv(long long a, long long m) {
    long long b = m, u = 1, v = 0;
    while (b) {
        long long t = a / b;
        a -= t * b; swap(a, b);
        u -= t * v; swap(u, v);
    }
    u %= m; 
    if (u < 0) u += m;
    return u;
}

int main() {
  std::cout << std::setprecision(9);
  int n;
  cin >> n;

  vector<int> h(n);
  for(int i=0; i<n; i++) {
    cin >> h.at(i);
  }
  int ans = 0;
  int count = -1;
  int max = 0;
  for(int i=n-1; i>=0; i--) {
    if(h.at(i) >= max) {
      count++;
      max = h.at(i);
    }
    else {
      if(ans < count) {
        ans = count;
      }
      count = 0;
      max = h.at(i);
    }
  }
  if(ans < count) {
    ans = count;
  }
  cout << ans << endl;
}

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

int main(){
	char c[3][3];
	for(int i=0;i<3;i++)
		for(int j=0;j<3;j++)
			cin >> c[i][j];
	for(int i=0;i<3;i++)
		for(int j=0;j<3;j++)
			if(i==j) cout << c[i][j];
	cout << endl;

}


Measured memory_bytes: 256
#include<stdio.h>
#include<vector>
#include<algorithm>
#include<string>
#include<iostream>
#include<set>
using namespace std;
typedef long long ll;
ll mod = 998244353;
ll dp[303030][3][3][2];
set<string>se;
void dfs(string s)
{
	if (se.find(s) != se.end())return;
	se.insert(s);
	for (int i = 0; i < s.size() - 1; i++)
	{
		if (s[i] != s[i + 1])
		{
			string z = s;
			z[i] = z[i + 1] = int('a') + int('b') + int('c') - s[i] - s[i + 1];
			dfs(z);
		}
	}
}
int main()
{
	string s;
	cin >> s;
	se.clear();
	for (int i = 0; i <= s.size(); i++)for (int j = 0; j < 3; j++)for (int k = 0; k < 3; k++)for (int l = 0; l < 2; l++)dp[i][j][k][l] = 0;
	if (s.size() <= 3)
	{
		dfs(s);
		printf("%d\n", se.size());
	}
	else
	{
		bool f1 = false, f2 = false;
		int cnt = 0;
		for (int i = 0; i < s.size(); i++)cnt += s[i] - 'a';
		for (int i = 0; i < s.size() - 1; i++)
		{
			if (s[i] != s[i + 1])f1 = true;
			else f2 = true;
		}
		cnt %= 3;
		if (!f1)printf("1\n");
		else
		{
			dp[1][0][0][0] = dp[1][1][1][0] = dp[1][2][2][0] = 1;
			for (int i = 1; i < s.size(); i++)
			{
				for (int j = 0; j < 3; j++)
				{
					for (int k = 0; k < 3; k++)
					{
						for (int l = 0; l < 3; l++)
						{
							if (k == l)
							{
								dp[i + 1][(j + l) % 3][l][1] += dp[i][j][k][0] + dp[i][j][k][1];
							}
							else
							{
								dp[i + 1][(j + l) % 3][l][0] += dp[i][j][k][0];
								dp[i + 1][(j + l) % 3][l][1] += dp[i][j][k][1];
							}
						}
					}
				}
				for (int j = 0; j < 3; j++)for (int k = 0; k < 3; k++)for (int l = 0; l < 2; l++)dp[i + 1][j][k][l] %= mod;
			}
			ll ans = 0;
			for (int i = 0; i < 3; i++)ans += dp[s.size()][cnt][i][1];
			if (!f2)ans++;
			printf("%lld\n", ans%mod);
		}
	}
}


Measured memory_bytes: 29188
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <string>
using namespace std;



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

    int a[3 * N];

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

    sort(a, a + 3 * N);
    

    for(int i = 0,  j = 3 * N - 2; i < j; j -= 2, i++)
    {
        ans += a[j];
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 1408
#include <iostream>
#include <algorithm>
#include <iterator>
#include <utility>
#include <unordered_map>
#include <vector>
#include <string>

using namespace std;

int main() {
  int N;
  cin >> N;
  vector<string> c(N);
  copy_n(istream_iterator<string>(cin), N, c.begin());
  vector<string> c_bk(c);
  
  // bubble sort
  for (int i = 0; i < N; ++i) {
    for (int j = N - 1; i < j; --j) {
      if (c[j][1] < c[j - 1][1]) swap(c[j - 1], c[j]);
    }
  }
  copy(c.begin(), prev(c.end()), ostream_iterator<string>(cout, " "));
  cout << c.back() << endl;
  cout << "Stable" << endl;

  c.assign(c_bk.begin(), c_bk.end());

  // selection sort
  bool stable = true;
  for (int i = 0; i < N; ++i) {
    int minj = i;
    int eqj = i;
    for (int j = i + 1; j < N; ++j) {
      if ((c[j][1] < c[minj][1])) minj = j;
      if ((i == eqj) && (c[i][1] == c[j][1])) eqj = j;
    }
    swap(c[i], c[minj]);
    stable &= ((i == eqj) || (minj <= eqj));
  }
  copy(c.begin(), prev(c.end()), ostream_iterator<string>(cout, " "));
  cout << c.back() << endl;
  cout << (stable ? "Stable" : "Not stable") << endl;

  return 0;
}



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

using namespace std;

typedef long long llint;

int main() {
  int n, m;
  llint k;
  cin >> n >> m >> k;
  vector<llint> a(n), b(m);
  for (int i = 0; i < n; i++) {
    cin >> a[i];
  }
  for (int i = 0; i < m; i++) {
    cin >> b[i];
  }
  vector<llint> asum(n + 1, 0), bsum(m + 1, 0);
  for (int i = 0; i < n; i++) {
    asum[i + 1] = asum[i] + a[i];
  }
  for (int i = 0; i < m; i++) {
    bsum[i + 1] = bsum[i] + b[i];
  }
  int ans = 0;
  for (int i = 0; i <= n; i++) {
    llint l = k - asum[i];
    if (l < 0) continue;
    int j = upper_bound(bsum.begin(), bsum.end(), l) - bsum.begin();
    j--;
    ans = max(ans, i + j);
  }
  cout << ans << endl;

  return 0;
}

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

int main() {
  int A, B, pr;
  cin >> A >> B;
  if (A >= 13) {
    pr = B;
  }
  else if (A >= 6) {
    pr = B / 2;
  }
  else {
    pr = 0;
  }
  cout << pr << endl;
}

Measured memory_bytes: 256
# D
N, M = map(int, input().split())

res = 1

# brute force
for i in range(1, min(10**5, M+1)):
    if M % i == 0:
        if i >= N:
            res = max(res, M // i)
        if M // i >= N:
            res = max(res, i)
print(res)

Measured memory_bytes: 3060
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); i++)
using namespace std;
int main()
{
    int n;
    cin >> n;
    vector<int> p(n);
    rep(i, n) cin >> p[i];
    int ans = 0;
    rep(i, n - 2) if ((p[i]-p[i+1])*(p[i + 2]-p[i+1]) <0) ans++;
    cout << ans << endl;

}

Measured memory_bytes: 256
import java.util.ArrayDeque;
import java.util.Arrays;
import java.util.Queue;
import java.util.Random;
import java.util.Scanner;
 


public class Main {
	private static Scanner sc = new Scanner(System.in);
	//result = Math.pow(num1, num3)
	//StringBuffer str = new StringBuffer(hoge1);
	//String hoge2 = str.reverse().toString();
	//map.containsKey(A)

	//Map<String, Integer> map = new HashMap<String, Integer>(n);
	/*for ( キーのデータ型 key : マップの名前.keySet() ) {
		データのデータ型 data = マップの名前.get( key );
		
		// keyやdataを使った処理;
	}*/
	//int i = Integer.parseInt(s);
	//Queue<String> qq=new ArrayDeque<>(); //add,poll,peek
	//Deque<String> qq=new ArrayDeque<>();//push,pop,peek
	//ArrayList<String> cc = new ArrayList<>(n);
	//Collections.sort(list);
	//Array.sort(list);   cc.contains(tmp)
	//Arrays.asList(c).contains("a")
	//list.set(1,"walk");//1 1 2 3 5
	//static long mod =1000000007;
	//static 	ArrayList<Integer> cc = new ArrayList<>(100);
	
	
	
	
	public static void main(String[] args) {
		//int N=sc.nextInt();for(int i=0;i<N;i++) {}
		//int a[]=new int[N];
		//Ae2+Be2=Ce2
		
		String S=sc.next();
		
		char a[]=S.toCharArray();
		
		int x[]=new int[200];
		
		for(int i=0;i<4;i++) {
			x[a[i]]++;
			
		}
		boolean xx=true;
		for(int i=0;i<200;i++) {
			if(x[i]!=0&&x[i]!=2)xx=false;
		}
		if(xx)p("Yes");
		else p("No");
		
		
		
		}
		
		
	
	
	
	public static long lcm(long a, long b) {
        return a / gcd(a, b) * b;
	}
	
	public static long gcd(long a, long b) {
        return b == 0 ? a: gcd(b, a % b);
	}

	


	
	static void p(String ans) {System.out.println(ans);};
	static void p(int ans) {System.out.println(ans);};
	static void p() {System.out.println();};
	static void p(long ans) {System.out.println(ans);};
	static void p(double ans) {System.out.println(ans);};
	
}
	


Measured memory_bytes: 21716
//2020 4.17

#include <stdio.h>
#include <string.h>
#define N 36

typedef struct{
    char mark;
    int num;
}card;

void BubbleSort(card *,int);
void SelectionSort(card *,int);
void cmp(card *,card *,int);

int main()
{
    int i,j=0;
    int a;
    card A[N],B[N];
    char b; //空白を入れるためだけのもの

    scanf("%d",&a);
    scanf("%c",&b); //aの後の改行も文字に含まれるのでscanf。
    for(i=0;i<a;i++)
    {
    scanf("%c%d",&A[i].mark,&A[i].num);
    scanf("%c",&b);
    }

       for(i=0;i<a;i++)
    {
        B[i]=A[i];
    }

    BubbleSort(A,a);
    
    SelectionSort(B,a);

    cmp(A,B,a);

    return 0;
}

void BubbleSort(card *A,int a)
{
    int cnt1=0,cnt=0;
    card temp;
    int i,j;
 while(1)
    {
        j=a-1;
        if(cnt1==j) break;
        while(j>=1)
        {
        if( A[j].num < A[j-1].num)
        {
            temp = A[j];
            A[j] = A[j-1];
            A[j-1] = temp;
        }
        j--;
        }
        cnt1++;
    }
    for(i=0;i<a;i++)
    {
        if(i==0) printf("%c%d",A[i].mark,A[i].num);
        else printf(" %c%d",A[i].mark,A[i].num);
    }
    printf("\nStable");
    printf("\n");
return;
}

void SelectionSort(card *B,int a)
{
    int i,j;
    int min,temp,flag=0;
    card temp2;
    
    for(i=0;i<a;i++)
    {
        min = B[i].num;
    for(j=i+1;j<a;j++)
    {
        if(min>B[j].num) {min = B[j].num; temp = j; flag=1;}
    }

    if(flag==1)
    {
    temp2 = B[i];
    B[i].num = min;
    B[i].mark = B[temp].mark;
    B[temp] = temp2;
    flag=0;
    }
    }
    for(i=0;i<a;i++)
    {
        if(i==0) printf("%c%d",B[i].mark,B[i].num);
        else printf(" %c%d",B[i].mark,B[i].num);
    }
    printf("\n");
    return;
}

void cmp(card *A,card *B,int a)
{
    int res,flag=0;
    int i;
    for(i=0;i<a;i++)
    {
    if(A[i].mark==B[i].mark) flag=0;
    else {flag=1; break;}
    }
    if(flag==1) {printf("Not stable\n");
    }else {printf("Stable\n");}
    return;
}


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

using ll = long long int;

const int MAX = (int)(1e5 + 5);
const ll INF = (ll)(1e10 + 5);

const int MAX_N = (int)(1e5 + 5);

int n;
ll a[MAX_N];

multiset<ll> mst;

int main(void) {
  // Here your code !
  scanf("%d", &n);

  for (int i = 0; i < n; ++i) {
    scanf("%lld", &(a[i]));
  }

  for (int i = 0; i < n; ++i) {
    auto ptr = mst.upper_bound(a[i] - 1);

    if (mst.empty() || ptr == mst.begin()) {
      mst.insert(a[i]);
      continue;
    }

    auto prv = prev(ptr);
    mst.erase(prv);
    mst.insert(a[i]);
  }

  printf("%d\n", mst.size());

  return 0;
}


Measured memory_bytes: 5760