akhauriyash/Code-Regression huggingface dataset:
s=input()
ans=[0]*len(s)
s+='R'
f='R'
c=0
a=0
for i in range(len(s)):
  if f=='R':
    if s[i]==f:
      c+=1
    else:
      f=s[i]
      a=i
      ans[a]+=c//2
      ans[a-1]+=c-(c//2)
      c=1
  else:
    if s[i]==f:
      c+=1
    else:
      f=s[i]
      ans[a-1]+=c//2
      ans[a]+=c-(c//2)
      c=1
for i in range(len(ans)):
  print(ans[i])

Measured memory_bytes: 4864
N = gets.chomp.to_i
problems = gets.chomp.split.map(&:to_i).sort

an_ans = problems[N/2]
if problems[N/2 - 1] == an_ans
  puts 0
else
  uniq_problems = problems.uniq
  puts((uniq_problems[uniq_problems.find_index(an_ans) - 1]...an_ans).count)
end


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

using namespace std;

const long long int INF = 1E9 + 1;

int main(){
	int n,k;
	cin>>n>>k;
	int mxN = 1e5 + 2;
	
	int ar[mxN];
	
	int dp[mxN];
	
	for(int i = 0; i<n; i++){
		int x;
		cin>>x;
		ar[i] = x;
	}
	
	dp[0] = 0;
	dp[1] = abs(ar[0] - ar[1]);
	
	for(int i = 2 ; i<n; i++){
		int m = max(0, i-k);
		dp[i] = INF;
		for(int j = 1; i-j >= m; j++){
			dp[i] = min(dp[i], dp[i-j] + abs(ar[i] - ar[i-j]));		
		}
		//dp[i] = min(dp[i-1] + abs(ar[i] -ar[i-1]),dp[i-2] + abs(ar[i] -ar[i-2]));
	}
	cout<<dp[n-1];
}
		


Measured memory_bytes: 4392
#include<bits/stdc++.h>
#define rep(i,n) for(i=0; i<n; ++i)
#define lim 100000
typedef long long ll;
using namespace std;
int main(void){
  int i,x,y,a,b,c; cin>>x>>y>>a>>b>>c;
  vector<ll> p(lim,0),q(lim,0),r(lim,0);
  rep(i,a) cin>>p[i]; sort(p.rbegin(),p.rend()); p[x]=0;
  rep(i,b) cin>>q[i]; sort(q.rbegin(),q.rend()); q[y]=0;
  rep(i,c) cin>>r[i]; sort(r.rbegin(),r.rend());
  int s=0,t=0,u=0,m;
  ll c1=0,c2=0,c3=0;
  rep(i,a+b+c){
    m=max(p[s],max(q[t],r[u]));
    if(p[s]==m&&s<x) c1+=p[s++];
    else if(q[t]==m&&t<y) c2+=q[t++];
    else c3+=r[u++];
    if(s+t+u==x+y) break;
  }
  cout<<c1+c2+c3;
  return 0;
}

Measured memory_bytes: 5616
using System;
using System.Collections.Generic;
using static System.Math;
using System.Linq;
using System.Text;
 
class DandA {
    static void Main(string[] args) {
        string s = ReadLineStr();
        bool rtn = true;
        for (int i =0; i < s.Length; i++) {
            if (i % 2 != 0 && s.Substring(i, 1) == "R") {
                rtn = false;
            } else if (i % 2 == 0 && s.Substring(i, 1) == "L") {
                rtn = false;
            }
        }
        if (rtn) {
            Console.WriteLine("Yes");
        } else {
            Console.WriteLine("No");
        }
    }
 
    static string Alphabet = "ABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZ";
    static string[] strAry = new string[] {"L", "R", "U", "D"}; 
  
    static private string ReadLineStr() {return Console.ReadLine();}
    static private int ReadLineInt() {return int.Parse(Console.ReadLine());}
    static private long ReadLineLong() {return long.Parse(Console.ReadLine());}
    static private double ReadLineDouble() {return double.Parse(Console.ReadLine());}
    static private string[] ReadLineStrArray() {return Console.ReadLine().Trim().Split();}
    static private int[] ReadLineIntArray() {return Console.ReadLine().Trim().Split().Select(a => int.Parse(a)).ToArray();}
    static private long[] ReadLineLongArray() {return Console.ReadLine().Trim().Split().Select(a => long.Parse(a)).ToArray();}
    static private double[] ReadLineDoubleArray() {return Console.ReadLine().Trim().Split().Select(a => double.Parse(a)).ToArray();}
    static private decimal[] ReadLineDecimalArray() {return Console.ReadLine().Trim().Split().Select(a => decimal.Parse(a)).ToArray();}
    static private string[][] ReadMLineStrArray(int arg) { return new int[arg].Select(_ => Console.ReadLine().Split()).ToArray();}
    static private int[][] ReadMLineIntArray(int arg) { return new int[arg].Select(_ => Console.ReadLine().Split().Select(int.Parse).ToArray()).ToArray();}
 
    static private bool IsPrime(int num) {
        if (num < 2) return false;
        if (num == 2) return true;
        else if (num % 2 == 0) return false;
        double sqrtNum = Math.Sqrt(num);
        for (int i = 3; i <= sqrtNum; i += 2) {
            if (num % i == 0) return false;
        }
        return true;
    }
}

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

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr); cout.tie(nullptr);
  int r; cin >> r; if (r < 1200) cout << "ABC"; else if (r < 2800) cout << "ARC"; else cout << "AGC";
  return 0;
}

Measured memory_bytes: 256
def selection_sort(A):
    cnt = 0
    for i in range(0, len(A)):
        min = i
        for j in range(i + 1, len(A)):
            if A[min] > A[j]:
                min = j
        if min != i:
            A[i], A[min] = A[min], A[i]
            cnt += 1
    print(' '.join(map(str, A)))
    print(cnt)


if __name__ == '__main__':
    n = int(input())
    l = list(map(int, input().split()))
    selection_sort(l)



Measured memory_bytes: 5600
#include <stdio.h>
int main(void) {
    int kind,i,sum,t1,t2;
    while (1) {
        scanf("%d",&kind);
        if (kind==0) break;
        sum=0;
        t1=kind*(kind-1)/2;
        for (i=0; i<t1; i++) {
            scanf("%d",&t2);
            sum+=t2;
        }
        printf("%d\n",sum/(kind-1));
    }
    return 0;
}

Measured memory_bytes: 600
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cstdlib>
#include<vector>
#include<string>
#include<sstream>
#include<cmath>
#include<numeric>
#include<map>
#include<stack>
#include<queue>
using namespace std;
int main(void) {
  int s; double w, h;
  while( scanf("%d,%lf,%lf", &s, &w, &h) != EOF ){
    if( w / (h*h) >= 25 ) cout << s << endl;
  }

  return 0;
}






// EOF

Measured memory_bytes: 3136
#include <bits/stdc++.h>
typedef long long ll;
using namespace std;
const int N = 200001;
vector<int> cnt;
vector<int> col;
vector<vector<int>> coladj;
vector<vector<int>> adj;
map<pair<int, int>, int> dir;
vector<int> sz;
vector<int> lst;
vector<int> active_child;
int n;

void dfs(int u, int p = -1){
  sz[u] = 1;
  int c = col[u];
  cnt[c]++;
  int oldlst = lst[c];
  coladj[oldlst].push_back(u);
  dir[{oldlst, u}] = active_child[oldlst];
  lst[c] = u;
  for(auto el : adj[u]){
    if(el == p)continue;
    active_child[u] = el;
    dfs(el, u);
    sz[u] += sz[el];
  }
  lst[c] = oldlst;
}
ll solve(int u){

  ll res = 0;
  int tot = sz[u] - 1;
  map<int, int> szs;
  for(auto el : adj[u]){
    if(sz[el] < sz[u])
      szs[el] = sz[el];
  }

  for(auto el : coladj[u]){
    res += solve(el);
    szs[dir[{u, el}]] -= sz[el];
  }
  for(auto el : szs)
    res += 1ll * el.second * el.second + el.second;
  return res;
}
int main()
{
//  freopen("in.txt", "r", stdin);
//  freopen("out.txt", "w", stdout);
  cin >> n;
  cnt.resize(n);
  coladj.resize(2 * n);
  adj.resize(2 * n);
  sz.resize(2 * n);
  lst.resize(n);
  col.resize(n);
  active_child.resize(2 * n);
  for(int i = 0;i < n;i++){
    cin >> col[i];
    col[i]--;
  }

  for(int i = 0;i < n - 1;i++){
    int a, b;
    cin >> a >> b;
    a--, b--;
    adj[a].push_back(b);
    adj[b].push_back(a);
  }


  for(int i = 0;i < n;i++){
    cnt[i] = 1;
    lst[i] = i + n;
    sz[i + n] = n + 1;
    adj[i + n].push_back(0);
  }
  dfs(0);

  for(int i = 0;i < n;i++){
//    cout << solve(i + n) << ' ';
    cout << (1ll * n * n + n - solve(i + n)) / 2 << endl;
  }
  return 0;
}


Measured memory_bytes: 83560
#include<bits/stdc++.h>
#define ll long long
#define ull unsigned ll
#define uint unsigned
#define pii pair<int,int>
#define pll pair<ll,ll>
#define PB push_back
#define fi first
#define se second
#define For(i,j,k) for (int i=(int)(j);i<=(int)(k);i++)
#define Rep(i,j,k) for (int i=(int)(j);i>=(int)(k);i--)
#define CLR(a,v) memset(a,v,sizeof(a));
#define CPY(a,b) memcpy(a,b,sizeof(a));
using namespace std;
const int N=100005;
ll D[N],S[N],SS[N];
int n,id[N],fa[N];
bool cmp(int x,int y){
	return D[x]<D[y];
}
int main(){
	scanf("%d",&n);
	For(i,1,n) scanf("%lld",&D[i]);
	For(i,1,n) id[i]=i,S[i]=1,SS[i]=0;
	sort(id+1,id+n+1,cmp);
	Rep(i,n,2){
		ll fv=D[id[i]]-n+2*S[id[i]];
		int l=1,r=i-1,ans=0;
		while (l<=r&&!ans){
			int mid=(l+r)/2;
			if (D[id[mid]]==fv)	ans=mid;
			else if (D[id[mid]]<fv) l=mid+1;
			else r=mid-1;
		}
		if (!ans) return puts("-1"),0;
		int fa=::fa[id[i]]=id[ans];
		S[fa]+=S[id[i]];
		SS[fa]+=SS[id[i]];
		SS[fa]+=S[id[i]];
	}
	if (SS[id[1]]!=D[id[1]]) return puts("-1"),0;
	For(i,2,n) printf("%d %d\n",fa[id[i]],id[i]);
}

Measured memory_bytes: 4480
#include <iostream>
#include <cstdio>
#include <cmath>
#include <cstring>
#include <algorithm>
#define int long long
using namespace std;
typedef long double DB;
const int N = 3e3 + 5;
const DB pi = 3.141592653589793238462;
int read() {
	int x = 0, f = 1; char ch;
	while(! isdigit(ch = getchar())) (ch == '-') && (f = -f);
	for(x = ch ^ 48; isdigit(ch = getchar()); x = (x << 3) + (x << 1) + (ch ^ 48));
	return x * f;
}
template <class T> T Max(T a, T b) { return a > b ? a : b; }
template <class T> T Min(T a, T b) { return a < b ? a : b; }
int n, L;
DB ansx, ansy, t[N];
signed main() {
	n = read(); L = read();
	for(int i = 1; i <= n; ++ i) cin >> t[i];
	for(int i = 1; i <= n; ++ i) {
		for(int j = i + 1; j <= n; ++ j) {
			int cnt = j - i - 1;
			DB tmp = pi * (t[i] + t[j]) / L;
			ansx += cos(tmp) * (n - 2 * cnt - 2);
			ansy += sin(tmp) * (n - 2 * cnt - 2);
		}
	}
	ansx = ansx / (n * (n - 1) * (n - 2) / 6);
	ansy = ansy / (n * (n - 1) * (n - 2) / 6);
	printf("%.12Lf %.12Lf\n", ansx, ansy);
	return 0;
}


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


int main(){
  int a,b;
  cin >> a >> b;
  if(b%a==0) cout << a + b << endl;
  else cout << b-a << endl;
  }


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

using namespace std;

vector < vector <int> > graph;
int mat[55][55];

int par[55];

void dfs(int u, int p = 0) {
	par[u] = p;
	for (int v : graph[u]) {
		if (v == p) {
			continue;
		}
		dfs(v, u);
	}
}

long long edgeMask[55];

void asign(int src, int des, int q) {
	dfs(src);
	int v = des;
	do {
		int u = par[v];
		int edge = mat[u][v];
		edgeMask[edge] |= (1LL << q);
		v = u;
	} while (v != src);
}

int n;
int m;

long long dp[51][(1LL << 20) + 5];

long long solve(int pos = 1, long long mask = 0) {
	if (pos >= n) {
		if (__builtin_popcountll(mask) == m) {
			return 1;
		}
		return 0;
	}
	long long &ret = dp[pos][mask];
	if (~ret) {
		return ret;
	}
	ret = solve(pos + 1, mask);
	ret += solve(pos + 1, mask | edgeMask[pos]);
	return ret;
}

signed main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(nullptr); cout.tie(nullptr);
	
	cin >> n;
	graph.resize(n + 1);
	for (int e = 1; e < n; e++) {
		int u, v;
		cin >> u >> v;
		graph[u].push_back(v);
		graph[v].push_back(u);
		mat[u][v] = mat[v][u] = e;
	}
	cin >> m;
	for (int q = 0; q < m; q++) {
		int u, v;
		cin >> u >> v;
		asign(u, v, q);
	}
	memset(dp, -1, sizeof dp);
	cout << solve() << endl;
}

Measured memory_bytes: 421444
n,a,b=map(int,input().split())
x=list(map(int,input().split()))
ans=0
for i in range(n-1):
  if (x[i+1]-x[i])*a>=b:
    ans+=b
  else:
    ans+=(x[i+1]-x[i])*a
print(ans)

Measured memory_bytes: 14252
#include <bits/stdc++.h>
using namespace std;
 
int main() {
	
    int64_t N;
    int64_t K;
    cin >> N >> K;
   int i=0;
   while (N>K-1) {
    N /=K;
    i++;
  //  cout << N << " " << i << endl;
   }
    cout <<i+1 << endl;
    
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <string>
#include <memory.h>
#include <cstring>
#include <set>
#include <algorithm>
using namespace std;

const int maxn = 200200;

int main() {
    int n;
    while(scanf("%d", &n) != EOF) {
        long long ans = 0; int tmp = 1;
        for(int i = 1; i <= n; i ++) {
            int a; scanf("%d", &a);
            if(a < tmp) continue;
            if(a == tmp) tmp ++;
            else if(a % tmp) {
                ans += a / tmp;
                a %= tmp;
            }
            else {
                ans += (a - tmp) / tmp;
                if(tmp < 2) tmp ++;
            }
        }
        cout << ans << endl;
    }
    return 0;
}





Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cstring>
#include <vector>
#include <deque>
#include <queue>
#include <array>
#include <set>
#include <map>
#include <cmath>
#include <algorithm>
#include <numeric>
#include <cassert>
#include <utility>
#include <functional>
#include <bitset>
#include <cstdint>

using namespace std;
using i64 = int64_t;
using i32 = int32_t;
template<class T, class U> void init_n(vector<T>& v, size_t n, U x) 
{ v = vector<T>(n, x); }
template<class T> void init_n(vector<T>& v, size_t n) { init_n(v, n, T()); }
template<class T> void read_n(vector<T>& v, size_t n, size_t o = 0) 
{ v = vector<T>(n+o); for (size_t i=o; i<n+o; ++i) cin >> v[i]; }
template<class T> void read_n(T a[], size_t n, size_t o = 0)
{ for (size_t i=o; i<n+o; ++i) cin >> a[i]; }
template<class T> T gabs(const T& x) { return max(x, -x); }
#define abs gabs

int main() {
  i64 h, w;
  vector<string> c;
  cin >> h >> w;
  read_n(c, h);
  for (string& s : c) cout << s << '\n' << s << '\n';
  return 0;
}


Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main(){

	ios::sync_with_stdio(false);

	int a,b;

	cin >> a >> b;

	if(a > 8 || b > 8){
		cout << ":(" << endl;
	}
	else{
		cout << "Yay!" << endl;
	}

	return 0;
}

Measured memory_bytes: 256
import java.io.IOException;
import java.util.Arrays;
import java.util.LinkedList;
import java.util.List;
import java.util.PriorityQueue;
import java.util.Scanner;

public class Main {
	
	public static final int MAX = 10000000;
	public static final int[] count = new int[MAX];
	
	public static void dps(int deep, int n, int cur, int m, int k){
		if(deep == n){
			count[Math.max(1, cur - k)-1]++;
		}else{
			for(int i = 1; i <= m; i++){
				dps(deep + 1, n, cur + i, m, k);
			}
		}
	}
	
	public static void main(String[] args) {
		final Scanner sc = new Scanner(System.in);

		while (true) {
			final int n = sc.nextInt();
			final int m = sc.nextInt();
			final int k = sc.nextInt();
			
			if(n == 0 && m == 0 && k == 0){
				break;
			}
			
			Arrays.fill(count, 0);
			
			dps(0, n, 0, m, k);
			
			double sum = 0;
			double pow = Math.pow(m, n);
			for(int i = 0; i < (n * m - k); i++){
				if(count[i] != 0){
					//System.out.print((i + 1) + " " + count[i] + " : ");
					sum += (double) (i + 1) * count[i] / (pow);
				}
			}
			
			System.out.println(sum);
		}
	}

}

Measured memory_bytes: 60996
import sys
sys.setrecursionlimit(1000000)
mod = 7 + 10 ** 9
from collections import deque

def comb(n, r, fact, revfact, mod):
    return (fact[n] * revfact[n-r] * revfact[r]) % mod

def dfs1(i, pre, Edge, Dist, Son, fact, revfact):
    under = 0
    for ne in Edge[i]:
        if ne != pre:
            sonNum = dfs1(ne, i, Edge, Dist, Son, fact, revfact)
            under += sonNum
            Dist[i] *= (comb(under, sonNum, fact, revfact, mod) * Dist[ne]) % mod
            Dist[i] %= mod
    Son[i] = under
    return under + 1 

def solve():
    input = sys.stdin.readline
    N = int(input())
    Edge = [[] for _ in range(N)]
    for _ in range(N - 1):
        a, b = map(int, input().split())
        Edge[a-1].append(b-1)
        Edge[b-1].append(a-1)
    fact = [1] * (N + 1)
    for i in range(1, N + 1): fact[i] = (fact[i-1] * i) % mod
    revfact = [1] * (N + 1)
    revfact[N] = pow(fact[N], mod - 2, mod)
    for i in reversed(range(1, N)): revfact[i] = ((i + 1) * revfact[i+1]) % mod

    Dist = [1] * N
    Son = [0] * N
    dfs1(0, 0, Edge, Dist, Son, fact, revfact)
    q = deque()
    for ne in Edge[0]:
        q.append((ne, 0))
    while q:
        ne, pre = q.pop()
        upper = (Dist[pre] * pow(comb(N - 1, Son[ne] + 1 , fact, revfact, mod), mod - 2, mod)) % mod
        Dist[ne] = (upper * comb(N - 1, N - 1- Son[ne], fact, revfact, mod)) % mod
        for nextEdge in Edge[ne]:
            if nextEdge != pre: q.append((nextEdge, ne))
    print("\n".join(map(str, Dist)))

    return 0

if __name__ == "__main__":
    solve()

Measured memory_bytes: 161116
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); i++)
#define irep(i, n) for (int i = (n); i >= 0; i++)
using namespace std;
using ll = long long;
using P = pair<int, int>;
const int INF = 1 << 30;
 
int main() {
  int n;
  cin >> n;
  map<int,int> d;
  rep(i,n) {
    int dd; cin >> dd;
    d[dd]++;
  }
  int m;
  cin >> m;
  bool can = true;
  rep(i,m) {
    int t; cin >> t;
    if (d[t] > 0) d[t]--;
    else {can = false;}
  }
  if (can) cout << "YES" << endl;
  else cout << "NO" << endl; 
  return 0;
}

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





int main() {
  int n,sum,x;
  cin>>n;
  x=n;
  sum=0;
  while (n>0){
    sum+=n%10;
    n/=10;
  }
  
  
  if (x%sum==0){
    cout<<"Yes"<<endl;
  }
  else {
    cout<<"No"<<endl;
  }
  
}

  













Measured memory_bytes: 256
from sys import stdin
n,k = map(int,stdin.readline().split())
a = list(map(int,stdin.readline().split()))
for i in range(n):
    a[i] -= 1
d = {}
d[0] = 0
cur = 0
step = 0
while step < k:
    cur = a[cur]
    step += 1
    if cur in d:
        looplen = step - d[cur]
        step += looplen * ((k-step)//looplen)
    else:
        d[cur] = step
print(cur + 1)


Measured memory_bytes: 110644
#include <bits/stdc++.h>
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 INF 2e9
#define ll long long

int main(){
    int p, q, r;
    cin>>p>>q>>r;
    int min1;
    int min2;

    min1 = min(p, q);
    min2 = min(min1, r);

    if(min2 == r){
        cout<<min2+min1<<endl;
    }
    else{
        if(min1 == p){
            cout<<min1+min(q, r)<<endl;
        }
        else{
            cout<<min1+min(p, r)<<endl;
        }
    }
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include "stdio.h"

using namespace std;

int main() {
  int a,b,c;

  scanf("%d%d%d", &a, &b, &c);

  if (a > c) {
    swap(a,c);
  }

  if (b > c) {
    swap(b,c);
  }

  if (a > b) {
    swap(b,a);
  }

  printf("%d %d %d\n", a, b, c);

  return 0;
}



Measured memory_bytes: 3228
#include <iostream>
#include <cmath>

using namespace std;

long long one(long long n, long long p){
    n++;
    long long block, rem;
    block = n / (p*2) * p;
    rem = n % (p*2);
    if(rem > p){
        rem -= p;
    }else{
        rem = 0;
    }
    return block + rem;
}

long long f(long long A, long long B){
    long long ans = 0, comp;
    for(int i=0; i <= log2(B); i++){
        comp = pow(2,i);
        if((one(B, comp) - one(A-1, comp))%2){
            ans += comp;
        }
    }
    return ans;
}

int main(){
    long long A, B;
    cin >> A >> B;
    cout << f(A,B) << endl;
    return 0;
}

Measured memory_bytes: 384
#include <stdio.h>
#include <string.h>
int main() {
    char S[100001];
    int cnt0 = 0, cnt1 = 0;
    if (scanf("%s", S) == -1) return -1;
    for (int i = 0; i < strlen(S); i++) {
        if (S[i] == '0') cnt0++;
        if (S[i] == '1') cnt1++;
    }
    printf("%d\n", ((cnt0 > cnt1) ? cnt1 : cnt0) * 2);
    return 0;
}

Measured memory_bytes: 256
function Main(input) {
	input = input.trim();
	input = input.split(" ");
	var apple = parseInt(input[0], 10);
	var piece = parseInt(input[1], 10);

	var all_piece = apple * 3 + piece;
   	var applepie = Math.floor(all_piece / 2);
  　
	console.log(applepie);
}
//*この行以降は編集しないでください（標準入出力から一度に読み込み、Mainを呼び出します）
Main(require("fs").readFileSync("/dev/stdin", "utf8"));

Measured memory_bytes: 11468
#include<bits/stdc++.h>
//ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
//clock_t start=clock();clock_t end=clock();cout<<(double)(end-start)/CLOCKS_PER_SEC<<endl;
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef unsigned int ui;
typedef pair<int,int> pii;
typedef pair<pii,int> ppii;
typedef pair<int,pii> pipi;
typedef pair<ll,ll> pll;
typedef pair<pll,ll> ppll;
typedef pair<ll,pll> plpl;
typedef pair<pii,pii> P;
typedef tuple<ll,ll,ll> tl;
typedef pair<double,double> pdd;
typedef vector<vector<ll>> mat;
ll mod=1000000007;
ll mod2=998244353;
ll mod3=1000003;
ll mod4=998244853;
ll mod5=1000000009;
ll inf=1LL<<62;
double pi=3.141592653589793238462643383279L;
double eps=1e-14;
#define rep(i,m,n) for(ll i=m;i<n;i++)
#define rrep(i,n,m) for(ll i=n;i>=m;i--)
#define srep(itr,st) for(auto itr=st.begin();itr!=st.end();itr++)
#define mrep(itr,mp) for(auto itr=mp.begin();itr!=mp.end();itr++)
#define Max(a,b) a=max(a,b)
#define Min(a,b) a=min(a,b)
typedef pair<pii,pii> e;
int dh[4]={1,-1,0,0};
int dw[4]={0,0,1,-1};
int ddh[8]={-1,-1,-1,0,0,1,1,1};
int ddw[8]={-1,0,1,-1,1,-1,0,1};
struct custom_hash {
    static uint64_t splitmix64(uint64_t x) {
        // http://xorshift.di.unimi.it/splitmix64.c
        x += 0x9e3779b97f4a7c15;
        x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9;
        x = (x ^ (x >> 27)) * 0x94d049bb133111eb;
        return x ^ (x >> 31);
    }

    size_t operator()(uint64_t x) const {
        static const uint64_t FIXED_RANDOM = chrono::steady_clock::now().time_since_epoch().count();
        return splitmix64(x + FIXED_RANDOM);
    }
};
#define umh unordered_map<ll,ll,custom_hash>
ll gcd(ll a,ll b){
    if(a<b)swap(a,b);
    if(b==0)return a;
    if(a%b==0)return b;
    return gcd(b,a%b);
}
ll lcm(ll a,ll b){
    ll c=gcd(a,b);
    return a*b/c;
}
ll Pow(ll n,ll k){
    ll ret=1;
    ll now=n;
    while(k>0){
        if(k&1)ret*=now;
        now*=now;
        k/=2;
    }
    return ret;
}
ll beki(ll n,ll k,ll md){
  ll ret=1;
  ll now=n;
    now%=md;
  while(k>0){
    if(k%2==1){
      ret*=now;
      ret%=md;
    }
    now*=now;
    now%=md;
    k/=2;
  }
  return ret;
}
ll gyaku(ll n,ll md){
  return beki(n,md-2,md);
}
ll popcount(ll n){
    ll ret=0;
    ll u=n;
    while(u>0){
        ret+=u%2;
        u/=2;
        
    }
    return ret;
}

int main(){
    ios::sync_with_stdio(false);cin.tie(0);
    int n;cin>>n;
    ll a[n];
    vector<pll> v;
    rep(i,0,n){
        cin>>a[i];
        v.push_back({a[i],i});
    }
    sort(v.begin(),v.end(),greater<pll>());
    ll dp[n+1][n+1];
    rep(i,0,n+1)rep(j,0,n+1)dp[i][j]=-inf;
    dp[0][0]=0;
    ll ans=0;
    rep(i,0,n){
        rep(j,0,n+1){
            ll num=v[i].second;
            ll ma=j,usi=i-ma;
            if(usi<0)continue;
            if(ma+1<=num){
                Max(dp[i+1][j+1],dp[i][j]+v[i].first*(num-ma));
            }
            if(n-1-usi>=num){
                Max(dp[i+1][j],dp[i][j]+v[i].first*(n-1-usi-num));
            }
        }
    }
   // rep(i,0,n+1)cout<<dp[1][i]<<" ";
    //cout<<endl;
    rep(i,0,n+1)Max(ans,dp[n][i]);
    cout<<ans<<endl;
}


Measured memory_bytes: 35020
package main
import "fmt"

func hisHappiness(money int) int{
    var hapiness500 int
    var hapiness5 int
	hapiness500 = money / 500 * 1000
	hapiness5 = (money%500) / 5 * 5

	return hapiness500 + hapiness5
}

func main(){
    // Your code here!
    var money int
    fmt.Scan(&money)
    fmt.Println(hisHappiness(money))
}


Measured memory_bytes: 512
#include <stdio.h>
#include <stdlib.h>
#include <math.h>

#define MAXOP 100
#define NUMBER '0'

int getop(char []);
void push(double);
double pop(void);

/*逆ポーランド電卓プログラム*/
main()
{
	int type;
	double op2;
	char s[MAXOP];

	while((type = getop(s)) != EOF) {
		switch (type) {
		case NUMBER:
			push(atof(s));
			break;
		case '+':
			push(pop() + pop());
			break;
		case '*':
			push(pop() * pop());
			break;
		case '-':
			op2 = pop();
			push(pop() - op2);
			break;
		case '/':
			op2 = pop();
			if (op2 != 0.0)
				push(pop() / op2);
			else
				printf("error: zero divisor\n");
			break;
		case '\n':
			printf("%.8g\n", pop());
			break;
		default:
			printf("error: unknown command %s\n", s);
			break;
		}
	}
	return 0;
}

#define MAXVAL 100

int sp = 0;
double val[MAXVAL];

/* push: fを値スタックにプッシュする*/
void push(double f)
{
	if (sp < MAXVAL)
		val[sp++] = f;
	else
		printf("error: stack full, can't push %g\n", f);
}

/* pop: スタックをポップし，一番上の値を返す*/
double pop(void)
{
	if (sp > 0)
		return val[--sp];
	else {
		printf("error: stack empty\n");
		return 0.0;
	}
}

#include <ctype.h>

int getch(void);
void ungetch(int);

/* getop:　次の演算子あるいは数値の被演算数をとってくる*/
int getop(char s[])
{
	int i, c;

	while ((s[0]= c = getch()) == ' ' || c == '\t')
		;
	s[1] = '\0';
	if (!isdigit(c) && c != '.')
		return c;	/*　cは数ではない */
	i = 0;
	if (isdigit(c)) /*　整数部を集める　*/
		while (isdigit(s[++i] = c = getch()))
			;
	if (c == '.') /*　小数部を集める　*/
		while (isdigit(s[++i] = c = getch()))
			;
	s[i] = '\0';
	if (c != EOF)
		ungetch(c);
	return NUMBER;
}

#define BUFSIZE 100

char buf[BUFSIZE];
int bufp =0;

int getch(void) /* 1文字を取ってくる */
{
	return (bufp > 0) ? buf[--bufp] : getchar();
}

void ungetch(int c) /* 文字を入力に戻す */
{
	if (bufp >= BUFSIZE)
		printf("ungetch: too many characters\n");
	else
		buf[bufp++] = c;
}

Measured memory_bytes: 576
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
	    // write your code here
        Scanner sc = new Scanner(System.in);

        int n = sc.nextInt();
        int m = sc.nextInt();

        // abc 128
        // bit全探索で考えます
        long[] swList = new long[m];
        int[] pList = new int[m];

        for (int i = 0; i < m; i++) {
            long sum = 0;
            int k = sc.nextInt();
            for (int j = 0; j < k; j++) {
                sum += (long)Math.pow(2, sc.nextInt() - 1);
            }
            swList[i] = sum;
        }

        for (int i = 0; i < m; i++) {
            pList[i] = sc.nextInt();
        }

        long ans = 0;

        parent : for (long i = 0; i <= Math.pow(2, n) - 1; i++) {
            for (int j = 0; j < m; j++) {
                if (Long.bitCount(i & swList[j]) % 2 != pList[j]) {
                    continue parent;
                }
            }
            ans++;
        }

        System.out.println(ans);
    }
}

Measured memory_bytes: 23892
import sys
import math
from collections import deque
from collections import defaultdict

def main():
    h1, m1, h2, m2, k = list(map(int,sys.stdin.readline().split()))
    h_v = h2 - h1 - 1
    m_v = (60 - m1) + m2
    time = h_v * 60 + m_v
    ans = time - k
    print(ans)
    return 0

if __name__ == "__main__":
    main()

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

namespace ConsoleApplication1
{
    class Program
    {
        static void Main(string[] args)
        {
            StringBuilder sb = new StringBuilder();

            string input;

            while (!string.IsNullOrEmpty(input = Console.ReadLine()))
            {
                string ans = "";
                int[] memo = new int[10];

                for (int i = 0; i < input.Length; i++)
                {
                    int index = int.Parse(input[i].ToString());
                    memo[index]++;
                }

                for (int i = 1; i <= 9; i++)
                {
                    if (memo[i] == 4) continue;
                    if (Check(memo, i)) ans += (i + " ");
                }

                if (ans == "") sb.AppendLine("0");
                else sb.AppendLine(ans.TrimEnd());
            }
            Console.Write(sb);
        }

        static bool Check(int[] source, int add)
        {
            for (int i = 1; i <= 9; i++)
            {
                int[] nums = (int[])source.Clone();
                nums[add]++;

                if (nums[i] < 2) continue;
                nums[i] -= 2;

                bool flg = true;

                for (int j = 1; j <= 9; j++)
                {
                    if (nums[j] >= 3) nums[j] -= 3;

                    if (nums[j] < 3 && j < 8)
                    {
                        while (nums[j] > 0)
                        {
                            nums[j]--;
                            nums[j + 1]--;
                            nums[j + 2]--;
                        }

                        if (nums[j + 1] < 0 || nums[j + 2] < 0)
                        {
                            flg = false;
                            break;
                        }
                    }

                    if (j >= 8 && nums[j] != 0)
                    {
                        flg = false;
                        break;
                    }
                }
                if (flg) return true;
            }
            return false;
        }
    }
}

Measured memory_bytes: 9104
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <queue>
#include <utility>
#include <climits>

using namespace std;

typedef unsigned long long ull;
typedef long long ll;
typedef unsigned int ui;

typedef vector<ull> vull;
typedef vector<ll> vll;
typedef vector<ui> vui;
typedef vector<long> vl;
typedef vector<int> vi;

typedef pair<ull, ull> pull;
typedef pair<ll, ll> pll;
typedef pair<ui, ui> pui;
typedef pair<long, long> pl;
typedef pair<int, int> pi;

int main() {
    int n; cin >> n;
    vi a; a.resize(n);
    for (int i = 0; i < n; ++i) cin >> a[i];
    sort(a.begin(), a.end());

    int m = a.back();

    int _min = INT_MAX;
    int idx = -1;
    if (a.size() > 2) {
        for (int i = 0; i < n; ++i) {
            if (_min >= abs(m / 2 - a[i])) {
                if (idx >= 0 && a[idx] > a[i]) {
                    continue;

                } else {
                    _min = abs(m / 2 - a[i]);
                    idx = i;
                }
            }
        }
        cout << m << " " << a[idx] << endl;

    } else {
        cout << m << " " << a[0] << endl;
    }

    return 0;
}


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

int main(){

  int N,cnt=1,tmp=1;
  
  cin>>N;

  int A[N];
  A[0]=0;
  A[N+1]=0;

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

  for(int i=0;i<N+2;i++){
    if(A[i]==1){ 
cnt++;
    }
    if(A[i]==0){
      if(cnt>tmp){ tmp=cnt; }
      cnt=1;

    }
  }
  cout<<tmp<<endl;

  return 0;
}



Measured memory_bytes: 3116
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> ii;

int main() {
	int n, d, ans = 0;
	cin >> n >> d;
	vector <ii> a(n);
	ll cur;
	for(int i = 0 ; i < n ; i++){
		cin >> a[i].first >> a[i].second;
		cur = 1ll*a[i].first*a[i].first + 1ll*a[i].second*a[i].second;
		if(cur <= 1ll*d*d) ans++;
	}
	cout << ans;
	return 0;
}

Measured memory_bytes: 4840
#include<bits/stdc++.h>
#define INF 1e9
#define llINF 1e18
#define MOD 1000000007
#define pb push_back
#define mp make_pair 
#define F first
#define S second
#define ll long long
#define vi vector<ll>
#define vvi vector<vi>
#define BITLE(n) (1LL<<((ll)n))
#define SHIFT_LEFT(n) (1LL<<((ll)n))
#define SUBS(s,f,t) ((s).substr((f)-1,(t)-(f)+1))
#define ALL(a) (a).begin(),(a).end()
#define EPS 1e-15
using namespace std;
ll gcd(ll a,ll b){
  ll r = a%b;
  while(r>0){
    a = b;b = r;
    r =a%b;
  }
  return b;
}
int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  ll p,q;cin>>p>>q;
  ll g = gcd(p,q);
  ll ans = 1;
  q/=g;
  ll loop = q;
  for(ll i = 2;i <= sqrt(loop);i++){
    if(q % i == 0){
      ans *= i;
      while(q%i == 0){
	q/=i;
      }
    }
  }
  cout<<ans*q<<endl;
  return 0;
}



Measured memory_bytes: 3212
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>


int cmp(const void *a,const void *b){
    if(*(int*)a>*(int*)b){return 1;}
    else if(*(int*)a<*(int*)b){return -1;}
    else {return 0;}
}


int main(void){
char s[105];
scanf("%s",s);
//回文チェック
for(int i=0;i!=strlen(s)-i-1;i++){
    if(s[i]!=s[strlen(s)-i-1]){printf("No");return 0;}
}
//回文チェック2
for(int i=0;i<(strlen(s)-1)/2;i++){
    if(s[i]!=s[(strlen(s)-1)/2-i-1]){printf("No");return 0;}
}

//回文チェック3
for(int i=(strlen(s)+3)/2-1;i<strlen(s);i++){
    if(s[i]!=s[strlen(s)-i-1]){printf("No");return 0;}
}
printf("Yes");

} 


Measured memory_bytes: 128
#include <iostream>
#include <string>
#include <vector>
#include <math.h>
#include <stdio.h>
#include <algorithm>
#include <utility>
#include <functional>
#define rep(i,n) for(int i=0;i<(n);i++)
#define psortsecond(A,N) sort(A,A+N,[](const pii &a, const pii &b){return a.second<b.second;});
#define psortfirst(A,N) sort(A,A+N,[](const pii &a, const pii &b){return a.first<b.first;});
#define All(x) (x).begin(),(x).end()
using namespace std;
using pii  = pair<int,int>;
long long gcd(long long a, long long b){return (b == 0 ? a : gcd(b, a%b));}
long long lcm(long long a, long long b){return a*b/gcd(a,b);}
typedef long long ll;
#define MOD 1000000007
#define EPS 10e-8

int main() {
    ll A[4];
    rep(i,3){
        cin >> A[i];
    }
    // sort(A,A+3);
    cout << (A[0]<=A[2]&&A[0]+A[1]>=A[2] ? "YES" : "NO") << endl;
}

Measured memory_bytes: 256
//  Created by Vignesh Manoharan

#include <iostream>
#include <vector>
#include <algorithm>
#include <cstdio>
#include <cmath>
#include <map>
#include <queue>
#include <stack>
#include <set>
#include <numeric>

using namespace std;

typedef long long ll;
typedef vector<ll> vi;
typedef pair<int,int> ii;
typedef vector<vi> vvi;
typedef vector<ii> vii;
typedef vector<vii> vvii;

const int INF = 2000000000;
const ll LINF = 1e17;
const double PI =3.141592653589793238;
const int mod=1000000007;
const double eps = 0.000001;

#define F(i,a,n) for(int i=(a);i<(n);i++)

template<typename T,typename TT> ostream& operator<<(ostream &s,pair<T,TT> t) {return s<<"("<<t.first<<","<<t.second<<")";}
template<typename T> ostream& operator<<(ostream &s,vector<T> t){
    for(int i=0;i<(t).size();i++)s<<t[i]<<((i<(t).size()-1)?" ":"");return s; }
template<typename T> ostream& operator<<(ostream &s,set<T> t){for(T x:t) s<<x<<" ";return s; }
template<typename T> istream& operator>>(istream &s,vector<T> &t){
    for(int _i=0;_i<t.size();_i++) s>>t[_i];return s; }

#define pb push_back
#define mp make_pair
#define all(v) v.begin(),v.end()

int main(int argc, const char * argv[]) {
    #ifdef LOCAL_TEST
    freopen("input", "r", stdin);
    freopen("output", "w", stdout);
    #endif
    int n,m;
    cin>>n>>m;
    vvii graph(n);
    F(i,0,m){
        int u,v,w;
        cin>>u>>v>>w;
        graph[u].push_back(ii(v,w));
    }
    // floyd warshall
    vvi dist(n,vi(n,INF));
    F(u,0,n) dist[u][u]=0;
    F(u,0,n) for(ii e: graph[u]){
        int v,w;
        tie(v,w)=e;
        dist[u][v]=w;
    }
    F(k,0,n){
        // relax every dist
        F(u,0,n){
            F(v,0,n){
                if(dist[u][k]<INF && dist[k][v]<INF)
                    dist[u][v]=min(dist[u][v],dist[u][k]+dist[k][v]);
            }
        }
    }
    vvi dist2(dist);
    int k=0;
    F(k,0,n){
        // relax every dist
        F(u,0,n){
            F(v,0,n){
                if(dist[u][k]<INF && dist[k][v]<INF)
                    dist[u][v]=min(dist[u][v],dist[u][k]+dist[k][v]);
            }
        }
    }
    if(dist!=dist2){
        cout<<"NEGATIVE CYCLE\n";
    } else {
        F(i,0,n){
            F(j,0,n){
            if(dist[i][j]==INF) cout<<"INF";
            else cout<<dist[i][j];
            if(j<n-1) cout<<" ";
            }
            cout<<"\n";
        }
    }
}

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

int main() {
  int N, L;
  cin >> N >> L;
  vector<string>data(N);
  for(int i=0;i<N;i++){
    cin >> data.at(i);
  }
  sort(data.begin(),data.end());
  string s="";
  for(int i=0;i<N;i++){
    s+=data.at(i);
  }
  cout << s << endl;
}


Measured memory_bytes: 256
import java.util.Scanner;

//20180509
//03

public class Main {
    public static void main(String[] args){
		Scanner scanner = new Scanner(System.in);

		while (scanner.hasNextLine()) {
			int m = scanner.nextInt();
			int f = scanner.nextInt();
			int r = scanner.nextInt();

			int m_f = m + f;

			if(m + f + r == -3) {
				break;
			} else if(m == -1 || f == -1) {
				System.out.println("F");
			} else if(m_f >= 80) {
				System.out.println("A");
			} else if(m_f >= 65 && m_f < 80) {
				System.out.println("B");
			} else if(m_f >= 50 && m_f < 65) {
				System.out.println("C");
			} else if(m_f >= 30 && m_f < 50 && r >= 50) {
				System.out.println("C");
			} else if(m_f >= 30 && m_f < 50) {
				System.out.println("D");
			} else if(m_f < 30) {
				System.out.println("F");
			}
		}
		scanner.close();
    }
}


Measured memory_bytes: 26364
package main

import "fmt"

func main() {
	var b string
	fmt.Scan(&b)
	if b == "A" {
		fmt.Println("T")
	} else if b == "T" {
		fmt.Println("A")
	} else if b == "G" {
		fmt.Println("C")
	} else {
		fmt.Println("G")
	}
}


Measured memory_bytes: 512
#include <stdio.h>
int main(){
    int i,n,q,l, r, m;
    int count = 0;
    int S[100000],T[50000];
  
    scanf("%d", &n);
    for( i=0; i<n; i++ ){
        scanf("%d", &S[i]);
    }
    scanf("%d", &q);
    for( i=0; i<q; i++ ){
        scanf("%d", &T[i]);
    }
    for( i=0; i<q; i++ ){
        l=0;
        r=n;
        while( l<r ){
            m=(l+r)/2;
            if( S[m]==T[i] ){
                count++;
                break;
            }
            else if( T[i]<S[m] ) r=m;
            else if( T[i]>S[m] ) l=m+1;
        }
    }
    printf("%d\n", count);
    return 0;
}
 

 

Measured memory_bytes: 2360
#!/usr/bin/env python
# -*- coding: utf-8 -*-
#
# FileName: 	queue
# CreatedDate:  2020-07-08 17:27:31 +0900
# LastModified: 2020-07-08 17:38:55 +0900
#


import os
import sys
# import numpy as np
# import pandas as pd
from collections import deque


def main():
    n, q = map(int, input().split())
    big_queue = []
    for _ in range(n):
        p = deque()
        big_queue.append(p)

    for _ in range(q):
        query = list(map(int, input().split()))
        if len(query) == 3:
            big_queue[query[1]].append(query[2])
        else:
            if query[0] == 1:
                if big_queue[query[1]]:
                    print(big_queue[query[1]][0])
            else:
                if big_queue[query[1]]:
                    big_queue[query[1]].popleft()
        


if __name__ == "__main__":
    main()



Measured memory_bytes: 14540
/// Rustで競技プログラミングの入力をスッキリ記述するマクロ
///
/// https://qiita.com/tanakh/items/0ba42c7ca36cd29d0ac8
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

    ($next:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
}

macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };

    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };

    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
    };

    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}

fn main() {
    input!{
        s: String,
    }

    let s: Vec<char> = s.chars().collect();
    let ans = s.windows(3).map(|string| (753 - string.iter().map(|c| *c).collect::<String>().parse::<i64>().unwrap()).abs()).min().unwrap();

    println!("{}", ans);
}


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

const int N = 1e5 + 10;
int n, a[N], ans;

int main() {
    ios :: sync_with_stdio(0);
    cin >> n;
    for(int i = 1 ; i <= n ; ++ i) cin >> a[i], ans += a[i];
    sort(a + 1, a + 1 + n);
    ans = ans - a[n] + a[n] / 2;
    cout << ans << endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ck(a,b,c) a<=b&&b<c
#define mod 1000000007
using namespace std;
int n, m, dp[307][307][307], res;
vector<pair<int, int> >lim[307];
int read()
{
	int num = 0;
	char c = getchar();
	while (c < '0' || c>'9')c = getchar();
	while (c >= '0' && c <= '9')num = num * 10 + c - '0', c = getchar();
	return num;
}
int main()
{
	n = read();
	m = read();
	for (int i = 1; i <= m; i++)
	{
		int l = read(), r = read(), x = read();
		lim[r].push_back(make_pair(l, x));
	}
	dp[0][0][0] = 1;
	for (int i = 1; i <= n; i++)
	{
		int lb = 0, rb = i, lc = 0, rc = i;
		for (int j = lim[i].size() - 1; j >= 0; j--)
		{
			int l = lim[i][j].first, x = lim[i][j].second;
			if (x == 1)rb = min(rb, l), rc = min(rc, l);
			if (x == 2)lb = max(lb, l), rc = min(rc, l);
			if (x == 3)lb = max(lb, l), lc = max(lc, l);
		}
		for (int j = 0; j < i; j++)
			for (int k = 0; k == 0 || k < j; k++)
			{
				if (ck(lb, j, rb) && ck(lc, k, rc))
					dp[i][j][k] = (dp[i][j][k] + dp[i - 1][j][k]) % mod;
				if (ck(lb, i - 1, rb) && ck(lc, j, rc))
					dp[i][i - 1][j] = (dp[i][i - 1][j] + dp[i - 1][j][k]) % mod;
				if (ck(lb, i - 1, rb) && ck(lc, k, rc))
					dp[i][i - 1][k] = (dp[i][i - 1][k] + dp[i - 1][j][k]) % mod;
			}
	}
	for (int j = 0; j <= n; j++)
		for (int k = 0; k <= n; k++)
			res = (res + dp[n][j][k]) % mod;
	cout << res << endl;
	return 0;
}

Measured memory_bytes: 110976
import math,sys

n,p=map(int,sys.stdin.readline().split())
limit = int(p ** (1/n))+1

def div_cnt(n,p):
    cnt = 0
    while p % n == 0:
        cnt += 1
        p /= n
    return p, cnt

if limit==1:
    print(1)
elif n==1:
    print(p)
else:
    cnt,ans=0,1

    p, cnt = div_cnt(2,p)
    ans *= 2 ** (cnt // n)
    
    for div in range(3, limit, 2):
        p,cnt = div_cnt(div,p)
        if cnt >= n:
            ans *= div ** (cnt // n)
    print(ans)

Measured memory_bytes: 3064
#include <iostream>
using namespace std;
 
    
    
int main(){
  int x,a,b,c;
  cin>>x;
  a=x/100;
  b=x%100/10;
  c=x%10;
  if ((a==7)||(b==7)||(c==7))
  {
    cout<<"Yes"<<endl;
  }
  else
  {
    cout<<"No"<<endl;
  }
  
    return 0;
}

Measured memory_bytes: 3580
#include <algorithm>
#include <cmath>
#include <complex>
#include <cstdio>
#include <iostream>
#include <iomanip>
#include <locale>
#include <map>
#include <numeric>
#include <queue>
#include <string>
#include <vector>

const long long int INF = 1e9;
typedef long long int ll;

#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define Rep(i, n) for(int i = 1; i <= (int)(n); i++)
#define llrep(i, n) for(ll i = 0; i < (ll)(n); i++)
#define llRep(i, n) for(ll i = 1; i <= (ll)(n); i++)

using namespace std;

struct Point{
	int x,y;
};

bool vector_finder(std::vector<ll> vec, ll number) {
    auto itr = std::find(vec.begin(), vec.end(), number);
    size_t index = std::distance( vec.begin(), itr );
  if (index != vec.size()) { // 発見できたとき
    return true;
    }
  else { // 発見できなかったとき
    return false;
    }
}

ll factorial(ll N){
    ll ans = 1;
    llRep(i,N){
        ans *= i;
    }
    return ans;
}

ll extended_factorial(ll N){
    ll ans = 1;
    llRep(i,N){
        ans *= i;
        ans %= (ll)(1e9+7);
    }
    return ans;
}

vector<ll> Eratosthenes(ll N){
    bool arr[N+1];
    //initialization
    arr[0] = false;
    arr[1] = false;
	for(ll i = 2; i < N+1; i++){
		arr[i] = true;
	}
    //eratosthenes
	for(ll i = 2; i <= sqrt(N); i++){
		if(arr[i]){
			for(ll j = 0; i * (j + 2) <= N; j++){
				arr[i *(j + 2)] = false;//not prime number
			}
		}
	}
    vector<ll> prime;
    llRep(i,N){
        if (arr[i]==true){
            prime.push_back(i);
        }
    }
    return prime;
}

ll gcd(ll a, ll b){
  ll temp;
	while (a % b != 0){
		temp = b;
		b = a % b;
		a = temp;
	}
	return b;
}

ll lcm(ll a, ll b){
  return a * b / gcd(a,b);
}

char alphabet[] = {
    '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'
};


int main(){
    ll N, cur, prev=INF, max=0;
    vector<ll > a;
    cin >> N;
    cin >> prev;
    a.push_back(0);
    llrep(i, N-1) {
        cin >> cur;
        if (prev < cur){
            a.push_back(i+1);
        }
        prev = cur;
    }
    a.push_back(N);
    llrep(i, a.size()-1){
        if (a[i+1] - a[i] > max) {
             max = a[i+1] - a[i];
        }
    }
    cout << max-1<< endl;
    return 0;
}


Measured memory_bytes: 1400
//include
//------------------------------------------
#include <vector>
#include <list>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>
#include <fstream>
#include <complex>
#include <math.h>

using namespace std;

//conversion
//------------------------------------------
inline long toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
inline long toLong(string s) {long 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 pair<long, long> PLL;
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 SORT(c) sort((c).begin(),(c).end())

//repetition
//------------------------------------------
#define FOR(i,a,b) for(long i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)

//constant
//--------------------------------------------

//clear memory
#define CLR(a) memset((a), 0 ,sizeof(a))

const long double EPS = 1e-12;
const double INF = 1e9;

struct edge{int to,cost;};
typedef pair<int,int> P;//firstは最短距離,secondは頂点番号


int main(){
	int n;
	long res[31];
	res[1]=1;
	res[2]=2;
	res[3]=4;
	FOR(i,4,31)res[i]=res[i-1]+res[i-2]+res[i-3];
	while(cin>>n){
		if(n==0)break;
		long ans=res[n]/10+(res[n]%10!=0);
		cout<<ans/365+(ans%365!=0)<<endl;
	}
	return 0;
}

Measured memory_bytes: 1160
#include "bits/stdc++.h"
using namespace std;
#define print(x) cout<<x<<endl;
#define rep(i,a,b) for(int i=a;i<b;i++)
#define REP(i,a) for(int i=0;i<a;i++)
#define printall(n,array) {for(int i=0;i<n;i++){cout<<array[i]<<" ";}cout<<endl;}
#define U() cout<<endl;
typedef long long ll;
typedef pair<int, int> PI;
typedef pair<int, PI> V;
typedef vector<int> VE;
const ll mod = 10000000007; //10^9+7


int main(){
  int n;
  ll a[202];
  cin>>n;
  REP(i,n)cin>>a[i];
  bool flag=true;
  ll ans=0;
  while(flag){
    ans++;
    REP(i,n){
      if(a[i]%2==0){
        a[i]=a[i]/2;
      }else{
        flag=false;
      }
    }
  }
  print(ans-1);
}

Measured memory_bytes: 256
#include <iostream>
//#include <algorithm>
#include <cstdlib>
//#include <vector>
using namespace std;

int main()
{
    int n;
    float t;
    float a;
    int i;
    int j;
    float k=10000;

    cin >> n;
    cin >> t;
    cin >> a;

    float h[n];

    for(i=0;i<n;i++){
       cin >> h[i];
    }


    if(a<0){
        for(j=0;j<n;j++)
        {
        h[j]=a-(t-h[j]*0.006);
        if(h[j]<0)h[j]=-1*h[j];
        }

    }
    else{
        for(j=0;j<n;j++){
             h[j]=a-(t-h[j]*0.006);
        if(h[j]<0)h[j]=-1*h[j];
        }
    }

    for(j=0;j<n;j++){

        if(k>h[j]){
            k=h[j];
            i=j;
        }
    }
    cout << i+1 <<endl;
   /* return 0;
    vector<int> a(n);
    for(int i=0;i<n;++i){
        cin >> a[i];
    }*/

    /*int sum=0;
    for (int i=0;i<n;++i){
        for(int j=0; j<n;++j){
            for(int k=0; k<n;++k){
                if(i==j || j==k || k==i){
                    continue;
                }
                int len=a[i]+a[j]+a[k];
                int amax=max(a[i],max(a[j],a[k]));
                if(amax<len-amax){
                    sum=max(sum,len);
                }

            }
        }
    }

    cout << sum << endl;*/

    return 0;
}


Measured memory_bytes: 888