akhauriyash/Code-Regression huggingface dataset:
#include <cmath>
#include<iostream>
#include<vector>
#include<algorithm>
#include<map>
#include<queue>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
ll inf = 1000000007;
vector<ll>to[100005];
int main() {
	int n, m;
	cin >> n >> m;
	int a, b;
	for (int i = 0; i < m; i++) {
		cin >> a >> b;
		a--; b--;
		to[a].push_back(b);
		to[b].push_back(a);
	}
	queue<ll>que;
	vector<ll>dist(n, inf);
	vector<ll>pre(n, -1);
	dist[0] = 0;
	que.push(0);
	while (!que.empty()) {
		int x = que.front();
		que.pop();
		for (int p : to[x]) {
			if (dist[p] != inf) {
				continue;
			}
			dist[p] = dist[x] + 1;
			pre[p] = x + 1;
			que.push(p);
		}
	}
	cout << "Yes" << endl;
	for (int i = 1; i < n; i++) {
		cout << pre[i] << endl;
	}
	return 0;
}



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

#ifndef INF
#define INF 1000000
#endif

int main(){
	int R;
	cin >> R;
	if(R < 1200){
		cout << "ABC" << endl;
	}else if(R < 2800){
		cout << "ARC" << endl;
	}else{
		cout << "AGC" << endl;
	}
	return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<cstring>
#include<stdio.h>
#include<algorithm>
#include<string.h>
#include <math.h>
#include<vector>
#include<stack>
#include<malloc.h>
#define INF 0x3f3f3f3f
#define maxn 1000006
using namespace std;

int main()
{  int a[102],b[102];
      int m,n,x,y,i;
      cin>>n>>m>>x>>y;
      for(i=0;i<n;i++)
        cin>>a[i];
       for(i=0;i<m;i++)
        cin>>b[i];
       sort(a,a+n);
       sort(b,b+m);

       for(i=x+1;i<=y;i++)
       {
           if(i>a[n-1]&&i<=b[0])
           {
               cout<<"No War"<<'\n';
               return 0;
           }
       }
       cout<<"War"<<'\n';
 return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
#define N 100

int l[N][N],n,flg[N];
int d[N],f[N],t;

void DFS(int );
void INDFS();

int main(){
  int i,j,u,v,k;
  scanf("%d",&n);
  for(i = 0; i<n; i++){
    for(j = 0; j<n; j++){
      l[i][j] = 0;
    }
  }

  for(i = 0; i<n ; i++){
    scanf("%d%d",&u,&k);
    for(j = 0; j<k; j++){
      scanf("%d",&v);
      l[u-1][v-1] = 1;
    }
  }
  INDFS();

  return 0;
}

void DFS(int u){
  int v;
  flg[u] = 1;
  ++t;
  d[u]  = t;
  for(v = 0; v<n; v++){
    if(l[u][v] == 0){
      continue;
    }
    if(flg[v] == 0){
      DFS(v);
    }
  }
  flg[u] = 2;
  ++t;
  f[u] = t;
}

void INDFS(){
  int i,j,l;
  for(i = 0; i<n; i++){
    flg[i] = 0;
  }
  t = 0;
  for(j = 0; j<n; j++){
    if(flg[j] == 0){
      DFS(j);
    }
  }
    for(l = 0; l<n; l++){
      printf("%d %d %d\n", l+1,d[l],f[l]);
    }
  }



Measured memory_bytes: 2112
#include <iostream>
#include <string>
#include <vector>
#include <set>
#include <algorithm>

using namespace std;

typedef pair<int, long long> P;
bool pairCompare(const P& firstElof, const P& secondElof)
{
    return firstElof.second > secondElof.second;
}

int main() {
    long long N, M; cin >> N >> M;

    vector<P> A;
    //vector<long long> D;
    for(int i=0; i<N; i++) {
        long long tmp; cin >> tmp;
        A.push_back(make_pair(1, tmp));
    }

    int B;
    long long C;
    for(int i=0; i<M; i++) {
        cin >> B >> C;
        A.push_back(make_pair(B, C));
    }

    sort(A.begin(), A.end(), pairCompare);

    long long ans = 0;
    int use = N, index=0;
    while(use != 0) {
        int tmp = min(A[index].first, use);
        use -= tmp;
        ans += tmp * A[index].second;
        index++;
    }

    cout << ans << endl;

    return 0;
}



Measured memory_bytes: 6256
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Security.Cryptography.X509Certificates;
using System.Text.RegularExpressions;
using Console = System.Console;

namespace Atcoder
{
    class Program
    {
        static void Main(string[] args)
        {
            var A = int.Parse(Console.ReadLine());
            var B = int.Parse(Console.ReadLine());
            var C = int.Parse(Console.ReadLine());
            var D = int.Parse(Console.ReadLine());
            Console.Write(Math.Min(A,B) + Math.Min(C,D));
        }
    }
}

Measured memory_bytes: 11092
/*#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<cmath>
#include<map>
#include<cstdio>
#include<stack>
#include<queue>
#include<fstream>
#include<cstdio>
#include<deque>
#include<iomanip>
#include <numeric>*/
#include<bits/stdc++.h>

using namespace std;
#define ok1 printf("ok1\n");
#define ok2 printf("ok2\n");
#define M 1000000000000000000LL
#define rep(i,n) for(int i=0;i<n;i++)
#define REP(i,s,n) for(int i=(s);i<(n);i++)
#define repr(i,n) for(int i=n-1;i>=0;i--)
#define REPR(i,s,n) for(int i=(s);i>=(n);(i)--)
#define all(a) (a).begin(),(a).end()
#define reall(a) (a).rbegin(),(a).rend()
#define pb push_back
#define pf push_front
#define MIN(a,b) a=min((a),(b))
#define MAX(a,b) a=max((a),(b))
#define SIZE(v) (int)v.size()
const double pi = acos(-1.0);

typedef vector<int> vi;
typedef vector<string> vs;
typedef long long ll;
typedef vector<ll> vll;
typedef vector<vi> vvi;
typedef vector<vll> vvll;
typedef deque<ll> dll;
typedef pair<ll, ll> P;
const ll mod = 1e9 + 7;
ll dx[4] = {-1,0,1,0};
ll dy[4] = {0,1,0,-1};

struct UnionFind {
    vector<int> par; // par[i]:iの親の番号　(例) par[3] = 2 : 3の親が2

    UnionFind(int N) : par(N) { //最初は全てが根であるとして初期化
        for(int i = 0; i < N; i++) par[i] = i;
    }

    int root(int x) { // データxが属する木の根を再帰で得る：root(x) = {xの木の根}
        if (par[x] == x) return x;
        return par[x] = root(par[x]);
    }

    void unite(int x, int y) { // xとyの木を併合
        int rx = root(x); //xの根をrx
        int ry = root(y); //yの根をry
        if (rx == ry) return; //xとyの根が同じ(=同じ木にある)時はそのまま
        par[rx] = ry; //xとyの根が同じでない(=同じ木にない)時：xの根rxをyの根ryにつける
    }

    bool same(int x, int y) { // 2つのデータx, yが属する木が同じならtrueを返す
        int rx = root(x);
        int ry = root(y);
        return rx == ry;
    }
};

int main(){
	ll h,w;
    cin >> h >> w;
	vs s(h);
	rep(i,h) cin >> s[i];
	UnionFind tree(h*w);
	rep(i,h){
		rep(j,w){
			rep(k,4){
				ll x = i + dx[k],y = j + dy[k];
				if(x >= 0 && x < h && y >= 0 && y < w){
					if(s[i][j] != s[x][y]) tree.unite((i * w + j),(x * w + y));
				}
			}
		}
	}
	vi c1(h * w),c2(h * w);
	rep(i,h){
		rep(j,w){
			if(s[i][j] == '.') c1[tree.root(i * w + j)]++;
			else c2[tree.root(i * w + j)]++;
		}
	}
	ll ans = 0;
	rep(i,h*w) ans += (ll)c1[i] * c2[i];
	cout << ans << endl;
    return 0;
}  

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

using namespace std;

int main(){

  string s;

  getline(cin,s);

  for(int i=0;i<s.length()-4;++i){
	
	if(s[i]=='a' && s[i+1]=='p' && s[i+2]=='p' && s[i+3]=='l' && s[i+4]=='e'){
	  s[i]='p';
	  s[i+1]='e';
	  s[i+2]='a';
	  s[i+3]='c';
	  s[i+4]='h';
	}

	else if(s[i]=='p' && s[i+1]=='e' && s[i+2]=='a' && s[i+3]=='c' && s[i+4]=='h'){
	  s[i]='a';
	  s[i+1]='p';
	  s[i+2]='p';
	  s[i+3]='l';
	  s[i+4]='e';
	}
  }

  cout<<s<<endl;
  
}



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

// #include <ext/pb_ds/assoc_container.hpp>
// #include <ext/pb_ds/tree_policy.hpp>
// #include <ext/pb_ds/detail/standard_policies.hpp>

using namespace std;
// using namespace __gnu_pbds;

#define int long long int
#define endl "\n"
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define all(c) c.begin(), c.end()

// typedef tree< int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;

signed main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
		
	string s, t;
	cin>>s>>t;
	int n1 = s.length(), n2 = t.length();
	int dp[n1+1][n2+1];
	memset(dp, 0, sizeof(dp));

	for(int i=1; i<=n1; i++) {
		for(int j=1; j<=n2; j++) {
			if(s[i-1] == t[j-1]) {
				dp[i][j] = max(dp[i-1][j-1] + 1, max(dp[i-1][j], dp[i][j-1]));
			} else {
				dp[i][j] = max(dp[i-1][j], dp[i][j-1]);
			}
		}
	}

	string ans = "";
	int i = n1, j = n2;
	while(i>0 && j>0) {
		if(dp[i][j] == dp[i-1][j]) {
			i -= 1;
		} else if (dp[i][j] == dp[i][j-1]) {
			j -= 1;
		} else {
			ans += s[i-1];
			i -= 1; j -= 1;
		}
	}
	reverse(all(ans));
	cout<<ans;

	return 0;
}

Measured memory_bytes: 70656
#pragma GCC optimize("O3")
#pragma comment(linker, "/stack:200000000")
#pragma GCC optimize("unroll-loops")

#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

using namespace std;
using namespace __gnu_pbds; 

#define int long long
#define pb push_back
#define pf push_front
#define eb emplace_back
#define mp make_pair
#define all(v) (v).begin(),(v).end()
#define rall(v) (v).rbegin(),(v).rend()
#define f first
#define s second
#define sz(x) (int)x.size()
#define endl "\n"
#define forn(i,n) for(int i=0;i<n;++i)
#define fore(i,l,r) for(int i=int(l);i<=int(r);++i)
#define rep(i,begin,end) for(__typeof(end) i=(begin);i!=(end);i++)
#define fill(a,value) memset(a,value,sizeof(a));
#define gcd(a,b) __gcd((a),(b))
#define watch1(x) cout<<(x)<<endl
#define watch2(x,y) cout<<(x)<<" "<<(y)<<endl
#define watch3(x,y,z) cout<<(x)<<" "<<(y)<<" "<<(z)<<endl
#define fastio ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);

typedef long long ll;
typedef long double ld; 
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<pii> vpii;
typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update> oset;

const int INF = 9e18;
const int mod = 1e9 + 7;
const int N = 1e4 + 5;

int i,n,x,t;

void solve()
{
    cin>>n>>x>>t;
    cout<<((n+x-1)/x)*t;
}

signed main()
{
    fastio;
    int tt;
    //cin>>tt;
    tt=1;
    while(tt--)
    {
        solve();
    }
    return 0;
}

Measured memory_bytes: 3648
<?php
list($n,$m)=explode(" ",trim(fgets(STDIN)));
$h=explode(" ",trim(fgets(STDIN)));
$i=0;
while($i<$m){
  list($a,$b)=explode(" ",trim(fgets(STDIN)));
  $map[$a][$b]=$h[$b-1];
  $map[$b][$a]=$h[$a-1];
  ++$i;
}
$ans=0;
$i=1;
while($i<=$n){
  if(isset($map[$i])){
    if($h[$i-1]>max($map[$i])){
      ++$ans;
    }
  }else{
    ++$ans;
  }
  ++$i;
}
echo $ans;

Measured memory_bytes: 58512
def main():
    i = int(input())+1
    s = 0
    for j in range(1, i):
        if j % 3 == 0 and s % 5 == 0:
            pass  # FizzBuzz
        elif j % 3 == 0:
            pass  # Fizz
        elif j % 5 == 0:
            pass  # Buzz
        else:
            s += j
    print(s)


main()


Measured memory_bytes: 67304
#include <iostream>

typedef unsigned long long ll;

int main()
{
  ll a, b, c;
  std::cin >> a >> b;
  c = a + b;

  if (a % 3 == 0 || b % 3 == 0 || c % 3 == 0)
    std::cout << "Possible" << std::endl;
  else
    std::cout << "Impossible" << std::endl;

  return 0;
}


Measured memory_bytes: 256
import math
N=int(input())
C=0
 
for l in range(N):
    for n in range(N):
        for m in range(N):
            if l==0 or m==0 or n==0:
                C+=1
            else:
                C+=math.gcd(math.gcd(l+1,m+1),n+1)
 
print(C)

Measured memory_bytes: 70452
fn read<T: std::str::FromStr>(
    stdin_lock: &mut std::io::StdinLock,
    buf: &mut Vec<u8>,
    delimiter: u8,
) -> T {
    buf.clear();
    let l = std::io::BufRead::read_until(stdin_lock, delimiter, buf).unwrap();
    buf.truncate(l - 1); // remove delimiter
    let s = unsafe { std::str::from_utf8_unchecked(&buf) };
    s.parse().unwrap_or_else(|_| panic!("read"))
}

fn main() {
    let stdin = std::io::stdin();
    let mut stdin_lock = stdin.lock();
    let mut buf: Vec<u8> = Vec::new();
    let n: usize = read(&mut stdin_lock, &mut buf, b' ');
    let q: usize = read(&mut stdin_lock, &mut buf, b'\n');
    let s: String = read(&mut stdin_lock, &mut buf, b'\n');
    let cv: Vec<char> = s.chars().collect();
    let mut lrv = vec![(0usize, 0usize); q];
    for i in 0..q {
        lrv[i].0 = read(&mut stdin_lock, &mut buf, b' ');
        lrv[i].1 = read(&mut stdin_lock, &mut buf, b'\n');
    }

    let mut sv = vec![0i32; s.len()];
    sv[0] = 0;
    for i in 1..n {
        sv[i] = sv[i - 1]
            + if cv[i - 1] == 'A' && cv[i] == 'C' {
                1
            } else {
                0
            };
    }

    for i in 0..q {
        println!("{}", sv[lrv[i].1 - 1] - sv[lrv[i].0 - 1]);
    }
}


Measured memory_bytes: 6908
#include<iostream>
#include<algorithm>
#include<vector>
#include<string>
using namespace std;
int main(){
  int m1,d1,m2,d2;
  std::cin >> m1>>d1>>m2>>d2;
  if(m1!=m2 && d2==1)std::cout << "1" << '\n';
  else std::cout << "0" << '\n';

  return 0;
}


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

int main() {
  string s; cin >> s;
  bool good = true;
  for(int i = 0; i < s.size();i++){
    if(i%2==0){
      if(!(s.at(i)=='R' || s.at(i)=='U' || s.at(i)=='D'))
        good = false;
    } else {
      if(!(s.at(i)=='L' || s.at(i)=='U' || s.at(i)=='D'))
        good = false;
    }
  }
  if(good) cout << "Yes" << endl;
  else cout << "No" << endl;
}


Measured memory_bytes: 3620
#include <iostream>
#include <iomanip>
#include <math.h>
#include <string>
#include <algorithm>
#include <vector>
#include <numeric>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <bitset>
using namespace std;

#define ll long long int
#define rep(i, a, n) for (ll i = a; i < n; i++)
#define repm(i, a, n) for (ll i = a; i >= n; i--)
#define INF 1e9
#define LINF 1e17
#define MOD (int)(1e9 + 7)
#define pi 3.141592653589
#define pii pair<int, int>
#define pll pair<ll, ll>
#define vi vector<int>
#define vd vector<double>
#define vb vector<bool>
#define vs vector<string>
#define vii vector<vector<int>>
#define vll vector<ll>
#define vllll vector<vector<ll>>
#define ALL(a) (a).begin(), (a).end()
#define sort_v(a) sort(a.begin(), a.end())
#define reverse_v(a) reverse(a.begin(), a.end())

void print(bool c)
{
    (c) ? (cout << "Yes" << endl) : (cout << "No" << endl);
}

void Print(bool c)
{
    (c) ? (cout << "YES" << endl) : (cout << "NO" << endl);
}

//最小公倍数
template <typename T>
T gcd(T a, T b)
{
    while (1)
    {
        if (a < b)
            swap(a, b);
        if (b == 0)
            break;
        a %= b;
    }
    return a;
}

//最大公約数
template <typename T>
T lcm(T a, T b)
{
    return a * b / gcd(a, b);
}
//セカンドキー->ファーストキーの順ソート
bool cmp(const pii &a, const pii &b)
{
    if (a.second != b.second)
        return a.second < b.second;
    return a.first < b.first;
}

//右下左上
int dx[8] = {1, 0, -1, 0, 1, 1, -1, -1};
int dy[8] = {0, 1, 0, -1, 1, -1, 1, -1};

int eve(int x)
{
    if (x % 400 == 0)
        return 1;
    if (x % 100 == 0)
        return 0;
    if (x % 4 == 0)
        return 1;
    return 0;
}

ll h, w;
vllll pass(50, vll(50));
vs s(50);
struct P
{
    int y, x, c;
} p;
queue<P> q;

ll bfs()
{
    if (q.empty())
        return -1;
    p = q.front();
    q.pop();
    if (p.y == h - 1 && p.x == w - 1)
        return p.c;
    rep(i, 0, 4)
    {
        int ny = p.y + dy[i], nx = p.x + dx[i];
        if (s[ny][nx] == '.' && (!pass[ny][nx]))
        {
            q.push({ny, nx, p.c + 1});
            pass[ny][nx] = 1;
        }
    }
    return bfs();
}

int main(void)
{
    ll n;
    cin >> n;
    map<ll, ll> l, r;
    ll a;
    rep(i, 0, n)
    {
        cin >> a;
        l[i + a]++;
        r[i - a]++;
    }
    ll ans = 0;
    rep(i, 0, n)
        ans += l[i] * r[i];
    cout << ans << endl;
}


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

int main()
{
    int N;
    cin >> N;
    vector<int> d(N);
    for (int i = 0; i < N; i++)
        cin >> d[i];
    int ans = 0;
    for (int i = 0; i < N - 1; i++)
    {
        for (int j = i + 1; j < N; j++)
        {
            ans += d[i] * d[j];
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
//
// Created by tattsun on 2017/02/14.
//

#include <iostream>
#include <vector>
#include <queue>

#define VERTEX_NUM_MAX 101

using namespace std;
typedef vector<int> Vertex;

int n;
Vertex vs[VERTEX_NUM_MAX];
int ds[VERTEX_NUM_MAX];

/*
void _bfs(vector<int>& targets, int distance) {
    vector<int> next_targets;

    for(auto it = targets.begin(); it != targets.end(); it++) {
        if(ds[*it] == -1) {
            ds[*it] = distance;

            auto& t = vs[*it];
            for(auto itt = t.begin(); itt != t.end(); itt++)
                next_targets.push_back(*itt);
        }
    }

    if(next_targets.empty())
        return;

    _bfs(next_targets, distance+1);
}

void bfs() {
    vector<int> targets;
    targets.push_back(1);

    _bfs(targets, 0);
}
 */

void bfs() {
    queue<int> q;
    q.push(1);
    ds[1] = 0;

    while(!q.empty()) {
        int i = q.front();
        q.pop();

        auto& v = vs[i];
        for(auto it = v.begin(); it != v.end(); it++) {
            if(ds[*it] != -1)
                continue;

            ds[*it] = ds[i] + 1;
            q.push(*it);
        }
    }
}

int main() {
    for(int i=0; i<VERTEX_NUM_MAX; i++) {
        ds[i] = -1;
    }

    cin >> n;

    int u, k, p;
    for(int i=1; i<=n; i++) {
        cin >> u >> k;
        for(int j=0; j<k; j++) {
            cin >> p;
            vs[i].push_back(p);
        }
    }

    bfs();

    for(int i=1; i<=n; i++) {
        cout << i << " " << ds[i] << endl;
    }
}

Measured memory_bytes: 3148
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

public class Main {

    private static Scanner sc;

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

    private void solve() {
        try {
          String[] aCards = sc.next().split("");
          String[] bCards = sc.next().split("");
          String[] cCards = sc.next().split("");

          String winner = "";
          String turn = "a";
          int firstA = 0;
          int firstB = 0;
          int firstC = 0;
          while(true) {
            if (turn.equals("a")) {
              if (aCards.length - 1 == firstA) {
                winner = "A";
                break;
              }
              turn = aCards[firstA];
              firstA++;
            } else if (turn.equals("b")) {
              if (bCards.length - 1 == firstB) {
                winner = "B";
                break;
              }
              turn = bCards[firstB];
              firstB++;
            } else {
              if (cCards.length - 1 == firstC) {
                winner = "C";
                break;
              }
              turn = cCards[firstC];
              firstC++;
            }
          }  

          System.out.println(winner);

        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    private class Scanner {
        String[] s;
        int i;
        BufferedReader br;
        String regex = " ";

        public Scanner() {
            s = new String[0];
            i = 0;
            br = new BufferedReader(new InputStreamReader(System.in));
        }

        @Override
        protected void finalize() throws Throwable {
            try {
                super.finalize();
            } finally {
                destruction();
            }
        }

        private void destruction() throws IOException {
            if (br != null) br.close();
        }

        public String next() throws IOException {
            if (i < s.length) return s[i++];
            String st = br.readLine();
            while (st == "") st = br.readLine();
            s = st.split(regex, 0);
            i = 0;
            return s[i++];
        }

        public int nextInt() throws NumberFormatException, IOException {
            return Integer.parseInt(next());
        }

        public Long nextLong() throws NumberFormatException, IOException {
            return Long.parseLong(next());
        }

        public Double nextDouble() throws NumberFormatException, IOException {
            return Double.parseDouble(next());
        }
    }
}


Measured memory_bytes: 8404
#include <iostream>
#include <sstream>
#include <string>
#include <algorithm>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <cassert>
//C++11
#if __cplusplus == 201103L
#include <tuple>
#endif

using namespace std;

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

template<class T> void debug(T begin, T end){ for(T i = begin; i != end; ++i) cout<<*i<<" "; cout<<endl; }

typedef long long ll;
const int INF = 100000000;
const double EPS = 1e-8;
const int MOD = 1000000007;
vector<int> adj[50];
int power[50];
bool used[50];
int ans, rest, sum;
int N;
vector<int> per;
void dfs(int k_){
  if(k_ == N){
    ans = max(ans,  sum);
    return ;
  }
  int k = per[k_];
  //printf("%d:%d %d %d\n", k,sum , rest, ans);
  if(sum + rest <= ans){
    return;
  }
  bool usedtmp[50];
  REP(i, 50) usedtmp[i] = used[i];
  int sumtmp = sum;
  int resttmp = rest;
  bool notuse = true;
  if(!used[k]){
    notuse = false;
    used[k] = true;
    sum += power[k];
    rest -= power[k];
    FORIT(it, adj[k])if(!used[*it]){
      notuse = true;
      rest -= power[*it];
      used[*it] = true;
    }
    dfs(k_ + 1);
    REP(i, 50) used[i] = usedtmp[i];
    sum = sumtmp;
    rest = resttmp;
  }
  if(k != 0 && notuse){
    if(!used[k])rest -= power[k];
    used[k] = true;
    dfs(k_ + 1);
    rest += power[k];
    used[k] = false;
  }
}

typedef pair<int, int> P;
int main(){
  while(cin>>N && N){
    ans = 0, rest = 0, sum = 0;
    REP(i, 50) adj[i].clear();
    memset(used, 0, sizeof(used));
    map<string, int> id;
    vector<string> adjstr[50];
    REP(i, N){
      string s; cin>>s; id[s] = i;
      cin>>power[i];
      rest += power[i];
      int k; cin>>k;
      while(k--){
        string str; cin>>str;
        adjstr[i].push_back(str);
      }
    }
    REP(i, N){
      REP(j, adjstr[i].size()){
        adj[i].push_back(id[adjstr[i][j]]);
      }
    }
    vector<P> ps(N-1);
    REP(i, N-1)ps[i] = P(-power[i+1], i+1);
    sort(ps.begin(), ps.end());
    per = vector<int>(N, 0);
    REP(i, N-1) per[i+1] = ps[i].second;
    dfs(0);
    cout<<ans<<endl;
  }
  return 0;
}

Measured memory_bytes: 1020
#!/usr/bin/env python3
import sys


def solve(N: int, K: int, C: int, S: str):
    # 最善だったら何ケースか
    work = 0
    rest = 0
    startWork = -1
    leftIndices = set()
    rightIndices = set()
    for i in range(N):
        if S[i] == "o" and rest <= 0:
            rest = C
            work += 1
            leftIndices.add(i)
        else:
            rest -= 1
    if work != K:
        print("")
        exit()
    work = 0
    rest = 0
    for i in range(N-1, -1, -1):
        if S[i] == "o" and rest <= 0:
            rest = C
            work += 1
            rightIndices.add(i)
        else:
            rest -= 1
    for i in sorted(list(leftIndices.intersection(rightIndices))):
        print(i+1)
    # print(rightIndices)
    # rest = -1
    # startWork = -1
    # for i in range(N-1, -1, -1):
    #     if S[i] == "o" and rest <= 0:
    #         rest = C
    #         startWork = i
    #         girigiriIndices.append(i)
    #         print(f"i{i},{rest}")
    #     else:
    #         rest -= 1

    # if work != K:
    #     print("")
    #     # print(work)
    #     exit()
    # for i in girigiriIndices:
    #     print(i+1)
    return


# Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    K = int(next(tokens))  # type: int
    C = int(next(tokens))  # type: int
    S = next(tokens)  # type: str
    solve(N, K, C, S)


if __name__ == '__main__':
    main()


Measured memory_bytes: 47400
#include<iostream>
#include<math.h>
#include<vector>
#include<algorithm>
#include<numeric>
#include<map>
#include<queue>
#include<deque>
#include<set>
#include<cstdio>
#include<cstring>
#include<string>
using namespace std;
typedef long long ll;
typedef vector<int> vec;
typedef vector<vector<int>> mat;

int main(){
    int A,B,C,D,E,F;
    cin>>A>>B>>C>>D>>E>>F;
    int a=100*A,b=100*B;
    int i=0,ans0,ans1;
    double con=-0.5;
    while(true){
        int j=0;
        while(true){
            if(i==0 && j==0)j++;
            int water=b*i+a*j;
            int max_sugar=water/100*E;
            int k=0;
            while(true){
                int l=0;
                while(true){
                    int sugar=D*k+C*l;
                    if(water+sugar<=F && sugar<=max_sugar){
                        double c=(double)sugar/(double)(water+sugar);
                        if(c>con){
                            con=c;
                            ans0=water+sugar;
                            ans1=sugar;
                        }
                        l++;
                    }
                    else break;
                }
                k++;
                if(k*D>max_sugar)break;
            }
            j++;
            if(b*i+a*j>F)break;
        }
        i++;
        if(b*i>F)break;
    }
    cout<<ans0<<" "<<ans1<<endl;
    return 0;
}

Measured memory_bytes: 256
import sys
def input():
    return sys.stdin.readline()[:-1]
N=int(input())
s=[[]for i in range(N)]
for i in range(N-1):
    a,b=map(lambda x: int(x)-1,input().split())
    s[a].append(b)
    s[b].append(a)
sys.setrecursionlimit(250000)
l=[None]*N
g=[1,0]
def hu(n,c):
    for i in s[n]:
        if l[i]==None:
            l[i]=c
            g[c%2]+=1
            hu(i,c+1)
l[0]=0
hu(0,1)
a=[1,2,3]
if min(g)>N//3:
    b,c=0,1
    for i in l:
        if i%2:
            print(a[b],end=" ")
            a[b]+=3    
            if a[b]>N:
                b=2
        else:
            print(a[c],end=" ")
            a[c]+=3
            if a[c]>N:
                c=2
else:
    if g[0]<g[1]:
        b,c=0,2
        for i in l:
            if i%2:
                print(a[b],end=" ")
                a[b]+=3
                if a[b]>N:
                    if b==0:
                        b=1
                    else:
                        b=2
            else:
                print(a[c],end=" ")
                a[c]+=3
    else:
        b,c=0,2
        for i in l:
            if not i%2:
                print(a[b],end=" ")
                a[b]+=3
                if a[b]>N:
                    if b==0:
                        b=1
                    else:
                        b=2
            else:
                print(a[c],end=" ")
                a[c]+=3

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

using namespace std;

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

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

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

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    
    int n, m;
    cin >> n >> m;
    LL a[n];
    for( int i = 0; i < n; ++i ) cin >> a[i];
    sort( a, a + n );
    vector< LP > v;
    for( int i = 0; i < m; ++i ) {
        LL b, c;
        cin >> b >> c;
        v.pb( MP( c, b ) );

    }
    sort( v.begin(), v.end(), greater< LP >() );
    int vpos = 0, apos = 0;
    while( vpos < v.size() && apos < n ) {
        if( a[apos] >= v[vpos].F ) break;
        else {
            a[apos] = v[vpos].F;
            v[vpos].S--;

        }
        if( v[vpos].S == 0 ) ++vpos;
        ++apos;

    }
    LL res = 0;
    for( int i = 0; i < n; ++i ) res += a[i];
    cout << res << endl;
    return 0;
}


Measured memory_bytes: 3188
#include <stdio.h>
#include <string.h>
typedef struct{
	int face[6];
}cube;
int rotation(char,cube*);
int rotation(char direction,cube *C){
	int temp;
	//cube C;
	switch(direction){
		case 'N':
			temp=C->face[4];
			C->face[4]=C->face[0];
			C->face[0]=C->face[1];
			C->face[1]=C->face[5];
			C->face[5]=temp;
		break;
		case 'E':
			temp=C->face[3];
			C->face[3]=C->face[5];
			C->face[5]=C->face[2];
			C->face[2]=C->face[0];
			C->face[0]=temp;
		break;
		case 'S':
			temp=C->face[0];
			C->face[0]=C->face[4];
			C->face[4]=C->face[5];
			C->face[5]=C->face[1];	
			C->face[1]=temp;//printf("S\n");
		break;
		case 'W':
			temp=C->face[0];
			C->face[0]=C->face[2];
			C->face[2]=C->face[5];
			C->face[5]=C->face[3];
			C->face[3]=temp;
		break;
		default :
		break;
	}
	return 1;
}

int main(void) {
	cube C1;
	int face;
	char str[120];
	for(int i=0;i<6;i++)scanf("%d",&C1.face[i]);
	scanf("%s",str);
	for(int i=0;i<strlen(str);i++){
		rotation(str[i],&C1);
		//for(int i=0;i<6;i++)printf("%d ",C1.face[i]);
		//printf("\n");
	}
	
	printf("%d\n",C1.face[0]);
	return 0;
}


Measured memory_bytes: 2100
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace abc058
{
    public class Program
    {
        public static void Main(string[] args)
        {
            string[] str = Console.ReadLine().Split(' ');

            int a = Convert.ToInt32(str[0]);
            int b = Convert.ToInt32(str[1]);
            int c = Convert.ToInt32(str[2]);

            Console.WriteLine(b - a == c - b ? "YES" : "NO");
        }
    }
}


Measured memory_bytes: 13268
#include<bits/stdc++.h>
#define ll long long int
#define ld long double
#define vii vector<ll> 
#define pb push_back
#define fast ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
using namespace std;
const int MOD = 1e9 + 7, N = 1e5 + 3;
 
int main(){
    fast;
    ll n, m, k;
    cin >> n >> m >> k;
    ll a[n+1], b[m+1], prefix_sum[n+1], prefix_sum1[m+1];
    prefix_sum[0] = 0;
    prefix_sum1[0] = 0;
    for(int i = 1; i <= n; ++i){
        cin >> a[i];
        prefix_sum[i] = prefix_sum[i-1] + a[i];
    }
    for(int i = 1; i <= m; ++i){
        cin >> b[i];
        prefix_sum1[i] = prefix_sum1[i-1] + b[i];
    }
    ll mx = 0;
    for(int i = 0; i <= n; ++i){
        ll diff = k - prefix_sum[i], ans = 0;
        if(diff < 0)
            break;
        ll low = 1, high = m;
        while(low <= high){
            ll mid = (low + high)/2;
            if(prefix_sum1[mid] <= diff){
                ans = mid;
                low = mid + 1; 
            }
            else
                high = mid - 1;
        }
        mx = max(mx, i+ans);  
        // cout << i << ' ' << ans << ' ';
    }
    cout << mx;
    return 0;
}


Measured memory_bytes: 9896
let n, m = Scanf.scanf " %d %d" @@ fun a b -> a, b
let d, k = abs @@ n - m, 1000000007
let rec f n a = if n <= 1 then a else f (n - 1) (a * n mod k)
let _ = Printf.printf "%d\n" @@ f n 1 * f m 1 * max 0 (2 - d) mod k

Measured memory_bytes: 384
#include <cmath>
#include <iostream>
#include <vector>
#include <queue>
#include <map>
#include <set>
#include <algorithm>
#include <utility>
#include <iomanip>

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

using namespace std;

typedef pair<int, int> P;

const int INF = 1e15;
const int MOD = 1e9+7;

signed main(){
    while(true){
        int n;
        cin >> n;

        if(n == 0){
            break;
        }

        vector<int> a(n);
        rep(i, n) cin >> a[i];

        vector<vector<bool>> able(n, vector<bool>(n, false));
        rep(i, n-1){
            if(abs(a[i] - a[i+1]) < 2){
                able[i][i+1] = true;
            }
        }
        for(int d = 3; d < n; d += 2){
            rep(i, n){
                if(i + d >= n){
                    continue;
                }

                if(i + 1 < i + d - 1 && able[i+1][i+d-1] && abs(a[i] - a[i+d]) < 2){
                    able[i][i+d] = true;
                    continue;
                }

                for(int k = i+1; k < i + d - 1; k++){
                    if(able[i][k] && able[k+1][i+d]){
                        able[i][i+d] = true;
                        break;
                    }
                }
            }
        }

        vector<vector<int>> dp(n, vector<int>(n));
        rep(i, n){
            rep(j, n){
                if(able[i][j]){
                    dp[i][j] = j - i + 1;
                }
            }
        }

        rep(i, n){
            for(int j = i+1; j < n; j++){
                for(int k = i; k < j; k++){
                    dp[i][j] = max(dp[i][j], dp[i][k] + dp[k+1][j]);
                }
            }
        }
        cout << dp[0][n-1] << endl;
    }

    return 0;
}



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

using namespace std;
#define _for(i,j,N) for(int i = (j);i < (N);i++)
#define _rep(i,j,N) for(int i = (j);i <= (N);i++)
#define ALL(x) x.begin(),x.end()
#define PB push_back
#define LL long long

template<typename T>
ostream& operator<<(ostream& os,const vector<T>& v) {
    _for(i,0,v.size()) os << v[i] << " ";
    return os;
}

template<typename T>
ostream& operator<<(ostream& os,const set<T>& v){
    for(typename set<T>::iterator it = v.begin();it != v.end();it++)
    os << *it <<" ";
    return os;
}

const int maxn = 1e5+5;
int vis[maxn];
int color[maxn];
vector<int> edge[maxn];
vector<int> weigh[maxn];

void dfs(int v,int c){
    color[v] = c;
    vis[v] = 1;
    _for(i,0,edge[v].size()){
        int u = edge[v][i];
        int w = weigh[v][i];
        if(!vis[u]){
            if(w % 2) dfs(u,c^1);
            else dfs(u,c);
        }
    }
}

int main()
{
    int N;cin >> N;
    _for(i,0,N-1){
        int v,w,weight;
        scanf("%d %d %d",&v,&w,&weight);
        edge[v].push_back(w);
        weigh[v].push_back(weight);

        edge[w].push_back(v);
        weigh[w].push_back(weight);
    }
    _rep(i,1,N){
        if(!vis[i]) dfs(i,1);
    }

    _rep(i,1,N){
        printf("%d\n",color[i]);
    }

    return 0;
}


Measured memory_bytes: 14720
#pragma GCC optimize ("O3")
#pragma GCC target ("avx")
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0; i < (n); i++)
#define rep1(i, n) for(int i = 1; i <= (n); i++)
#define co(x) cout << (x) << "\n"
#define cosp(x) cout << (x) << " "
#define ce(x) cerr << (x) << "\n"
#define cesp(x) cerr << (x) << " "
#define pb push_back
#define mp make_pair
#define chmin(x, y) x = min(x, y)
#define chmax(x, y) x = max(x, y)
#define Would
#define you
#define please

const int AS = 1 << 17;
ll dat[2 * AS];
const ll are = 1 << 30;
void modify(int p) {
	for (dat[p += AS] -= are; p > 1; p >>= 1) dat[p >> 1] = max(dat[p], dat[p ^ 1]);
}
void modify0(int p) {
	for (dat[p += AS] = 0; p > 1; p >>= 1) dat[p >> 1] = max(dat[p], dat[p ^ 1]);
}

const int dm = 1 << 20;
char dn[dm], * di = dn;
inline void putint(int X) {
	int keta = 0;
	char C[10];
	while (X) {
		*(C + keta) = '0' + X % 10;
		X /= 10;
		keta++;
	}
	for (int i = keta - 1; i >= 0; i--)* di++ = (*(C + i));
	*di++ = ' ';
}

int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);


	int N;
	cin >> N;
	int A[100000];
	rep(i, N) {
		cin >> A[i];
		A[i]--;
		dat[AS + A[i]]++;
	}
	rep(i, N) dat[AS + i] = (dat[AS + i] << 30) + i;
	for (int i = AS - 1; i > 0; i--) dat[i] = max(dat[i << 1], dat[i << 1 | 1]);

	if (N == 2) {
		co(-1);
		return 0;
	}

	int dame = -1;
	int j = 0;
	const int m = (1 << 30) - 1;
	bool used[100000] = {};
	rep(i, N - 3) {
		int kotae;
		ll tmp = dat[1];
		if (N - i - 1 == tmp >> 30) kotae = tmp & m;
		else {
			int k = j;
			while (used[k] || k == dame) k++;
			kotae = k;
		}
		putint(kotae + 1);
		used[kotae] = 1;
		dame = A[kotae];
		while (used[j]) j++;
		modify(dame);
		modify0(kotae);
	}

	int kouho[3];
	int k = 0;
	for (int i = j; i < N; i++) {
		if (!used[i]) kouho[k++] = i;
	}
	while (1) {
		if (dame != kouho[0] && A[kouho[0]] != kouho[1] && A[kouho[1]] != kouho[2]) break;
		next_permutation(kouho, kouho + 3);
	}
	putint(kouho[0] + 1);
	putint(kouho[1] + 1);
	putint(kouho[2] + 1);

	fwrite(dn, 1, di - dn, stdout);

	Would you please return 0;
}

Measured memory_bytes: 3712
#include<bits/stdc++.h>
#define rep(i,N) for(int i=0;i<(N);i++)
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
using namespace std;
const long long MOD = 1e9 + 7;
const long long INF = 1e12;
const int inf = 1e9;
const int mod = 1e9+7;
typedef long long ll;
typedef pair<ll,int> P;
typedef set<int> S;
int main(){
    cout << fixed << setprecision(10);
    int n,y;
    cin >> n >> y;
    for(int i=0;i<=n;i++){
        for(int j=0;j<=n-i;j++){
            int k = n - i - j;
                if(10000*i+5000*j+1000*k==y){
                    cout << i << " " << j << " " << k << endl;
                    return 0;
                }
            }
    }
    cout << "-1 -1 -1"  << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i =0;i<(int)(n);i++)
#define endl '\n'
typedef pair<int,int> P;
typedef long long ll;
int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    int n;
    cin >> n;
    ll ans = 0;
    for(int i=1;i<=n;i++){
        ans += (n-1)/i;
    }
    cout << ans << endl;
}

Measured memory_bytes: 3656
import std.stdio, std.conv, std.string, std.algorithm,
       std.math, std.array, std.container, std.typecons;

void main() {
  int n = readln.chomp.to!int;
  bool[string] map;
  for(int i=0; i<n; i++) map[readln.chomp] = true;
  writeln(map.length);
}


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

int main() {
	ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    
    ll n;
    cin>>n;
    
    string s;
    cin>>s;
    ll ans=0,ans1=0,countr=0,countw=0;
    for(ll i=0;i<n;i++)
    {
        if(s[i]=='R')
        {
            countr++;
        }
        else
        {
            countw++;
        }
    }
 
    for(ll i=0;i<n;i++)
    {
        if(i<countr && s[i]!='R')
        {
            ans++;
        }
        else if(i>=countr && s[i]!='W')
        {
            ans1++;
        }
    }
  
    cout<<max(ans,ans1)<<endl;
}


Measured memory_bytes: 3784
#include <vector>
#include <string>
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <math.h>
using namespace std;
int MOD=1000000007; 

void itsvgg() 
{
    ios::sync_with_stdio(0);cin.tie(0);
    #ifndef ONLINE_JUDGE
    freopen("input.txt","r",stdin);
    freopen("output.txt", "w", stdout);
    #endif
} 

int main()
{
	ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
	itsvgg();

	int n,k;
	cin>>n>>k;
	int a[n];
	for(int i=0;i<n;i++)
		cin>>a[i];
	int memo[n];
	memo[0]=0;
	for(int i=1;i<n;i++)	
	{
		int min=MOD;
		for(int j=1;j<=k && j<=i;j++)
		{
				if(min>abs(a[i]-a[i-j])+memo[i-j])
				min=abs(a[i]-a[i-j])+memo[i-j];
		}
		memo[i]=min;
		//cout<<min<<endl;
	}	
	cout<<memo[n-1];



}	


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

#define rep(i, n) for(int i = 0; i < (n); ++i)
#define pb push_back
#define ALL(obj) (obj).begin(), (obj).end()      //昇順
#define RALL(obj) (obj).rbegin(), (obj).rend()   //降順
#define print(obj) cout << obj << endl
#define scan(obj) cin >> obj

typedef long long ll;

using namespace std;

int main(void){
    string s;
    cin >> s;
    int so, se, so1 = 0, so0 = 0, se1 = 0, se0 = 0;
    so = (s.length() / 2) + s.length() % 2;
    se = s.length() / 2;
    rep(i, so){
        if(s[i * 2] == '0') so0++;
        else so1++;
    }
    rep(i, se){
        if(s[i * 2 + 1] == '0') se0++;
        else se1++;
    }
    if(so0 + se1 >= so1 + se0){
        print(so1 + se0);
    } else{
        print(so0 + se1);
    }
}

Measured memory_bytes: 512
// TLEはずせなかった
//
// 素因数分解を高速に行う方法がわからなかった

#include <bits/stdc++.h>
#define rep(i, n) for (ll i = 0; i < (n); i++)
#define rep1(i, n) for (ll i = 1; i <= (n); i++)
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;

const char wall = '#';
vector<vector<char>> fields;
vector<vector<bool>> used;
vector<vector<ll>> dist;
const int dx[4] = {0, -1, 0, 1};
const int dy[4] = {1, 0, -1, 0};


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

vector<pair<ll, ll>> factorize(ll n) {
  vector<pair<ll, ll>> res;
  for (ll i = 2; i * i <= n; ++i) {
    if (n%i) continue;
    res.emplace_back(i, 0);
    //res.push_back(pair<ll, ll>(i, 0)); と同義
    //res.push_back({i, 0}); と同義
    while (n%i == 0) {
      n /= i;
      res.back().second++;
    }
  }
  if ( n != 1) res.emplace_back(n, 1);
  return res;
}

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);

  ll a, b;
  cin >> a >> b;
  ll g = gcd(a, b);
  auto f = factorize(g);
  cout << f.size() + 1 << endl;
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)n;i++)
#define rep1(i,n) for(int i=1;i<=(int)n;i++)
#define sp(n) cout << fixed << setprecision(n)
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
typedef long long ll;
using namespace std;
ll A,B,C,D;
map<ll,ll> mp;
ll dfs(ll x){
    if(x==0)return 0;
    if(x==1)return D;
    if(mp[x]!=0)return mp[x];
    ll l2=(x/2)*2,r2=((x+1)/2)*2;
    ll l3=(x/3)*3,r3=((x+2)/3)*3;
    ll l5=(x/5)*5,r5=((x+4)/5)*5;
    ll res=1e+18;
    if(res/D>x)res=D*x;
    chmin(res,abs(x-l2)*D+A+dfs(l2/2));
    chmin(res,abs(x-r2)*D+A+dfs(r2/2));
    chmin(res,abs(x-l3)*D+B+dfs(l3/3));
    chmin(res,abs(x-r3)*D+B+dfs(r3/3));
    chmin(res,abs(x-l5)*D+C+dfs(l5/5));
    chmin(res,abs(x-r5)*D+C+dfs(r5/5));
    
    mp[x]=res;
    return res;
}

int main(void){
    int t;cin>>t;
    rep(i,t){
        mp.clear();
        ll n,a,b,c,d;cin>>n>>a>>b>>c>>d;
        A=a;B=b;C=c;D=d;
        ll res=dfs(n);
        cout<<res<<endl;
    }
}

Measured memory_bytes: 4244
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define ll long long
#define FILE_READ_IN freopen("input.txt","r",stdin);
#define FILE_READ_OUT freopen("output.txt","w",stdout);
#define Fast ios_base::sync_with_stdio(false);cin.tie();cout.tie();
#define deb(x) cout<<#x<<" "<<x<<endl;
#define all(v) v.begin(),v.end()
#define endl '\n'
using namespace __gnu_pbds;
using namespace std;

template <typename T>
using ordered_set =
    tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

void judge() {
#ifndef ONLINE_JUDGE
	FILE_READ_IN
	FILE_READ_OUT
#endif
}

int main() {
	Fast;
	int t = 1;
	judge();
	// cin >> t;
	while (t--) {
		ll n;
		cin >> n;
		ll a[n];
		for (ll i = 0; i < n; i++)cin >> a[i];
		ll st = 1000 / a[0];
		ll rem = 1000 % a[0];
		ll cst = a[0];
		for (ll i = 0; i < n - 1; i++) {
			if (a[i + 1] > a[i]) {
				st = st + rem / a[i];
				rem = rem % a[i];
				cst = a[i + 1];
			}
			else {
				rem += st * cst;
				st = 0;
				cst = 0;
			}
		}
		rem += st * cst;
		cout << rem << endl;
	}
}


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

int main()
{
	double v;
	while(cin>>v){
		double t = v/9.8;
		double y = 4.9*t*t;
		int N;
		for(N=1;;N++){
			if(5*N-5>=y) break;
		}
		cout<<N<<endl;
	}
	return 0;
}

Measured memory_bytes: 1224
#include<iostream>
#include<math.h>
#include<iomanip>
#include<vector>
#include<algorithm>
#include<queue>
#include<string>
using namespace std;
#define PI 3.14159265358979
#define rep(i,n) for(int i=0;i<n;i++)




int main(void)
{
    int n1,n2;
    cin>>n1>>n2;

  int ans =(n1-1)*(n2-1);
    cout<<ans<<endl;    



}



Measured memory_bytes: 256
import java.util.Scanner;
public class Main {
    public static void main(String[] args){
    
    Scanner sc = new Scanner(System.in);
    int n = sc.nextInt();
    String S = sc.next();
   
    if(n%2 != 0) {
    	System.out.println("No");
    }else if(S.substring(0,n/2).equals(S.substring(n/2,n))){
		System.out.println("Yes");
    }else {
    	System.out.println("No");
    }
      }
}


Measured memory_bytes: 35896
mlist = []
flist = []
rlist = []
 
while(1):
    m, f, r = map(int, input().split())
    if m == -1 and f == -1 and r == -1:
        break
    mlist.append(m)
    flist.append(f)
    rlist.append(r)

for m, f, r in zip(mlist, flist, rlist):
    if m == -1 or f == -1:
        print("F")
    elif 80 <= m + f:
        print("A")
    elif 65 <= m + f < 80:
        print("B")
    elif 50 <= m + f < 65:
        print("C")
    elif 30 <= m + f < 50:
        if 50 <= r:
            print("C")
        else:
            print("D")
    else:
        print("F")





Measured memory_bytes: 5600
// luogu-judger-enable-o2
#include<bits/stdc++.h>
using namespace std;
const int maxn=3030;

int w[maxn],n;
int head[maxn],tot;

struct edge{
	int to,nxt;
}e[maxn<<1];

void add(int x,int y)
{
	e[++tot].to=y;
	e[tot].nxt=head[x];
	head[x]=tot;
 } 

bool dfs(int x,int fa)
{
	for(int i=head[x];i;i=e[i].nxt)
	{
		int y=e[i].to;
		if(y==fa)continue;
		if(w[x]>w[y]&&!dfs(y,fa))return true;
	}
	return false;
}

int main()
{
	scanf("%d",&n);
	for(int i=1;i<=n;i++)scanf("%d",&w[i]);
	for(int i=1;i<n;i++){
		int x,y;
		scanf("%d%d",&x,&y);
		add(x,y);add(y,x);
	}	
	for(int x=1;x<=n;x++)
	{
		if(dfs(x,0))cout<<x<<" ";
	}
}

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

using namespace std;
const int inf=1e9+1;

int n,m,w[105],v[105],dp[105][100005];

int main()
{
	scanf("%d %d",&n,&m);
	for(int i=1;i<=n;i++) scanf("%d %d",&w[i],&v[i]);
	for(int i=0;i<=n;i++) for(int j=0;j<=100000;j++) dp[i][j]=(j==0?0:inf);
	for(int i=1;i<=n;i++){
		for(int j=1;j<=100000;j++){
			dp[i][j]=min(dp[i-1][j],dp[i][j]);
			if(j>=v[i]) dp[i][j]=min(dp[i][j],dp[i-1][j-v[i]]+w[i]);
		}
	}
	
	int ans=0;
	for(int i=1;i<=100000;i++) if(dp[n][i]<=m) ans=i;
	printf("%d\n",ans);
}

Measured memory_bytes: 41216
import java.util.Scanner;

public class Main {

  public static void main(String[] args ){

    Scanner sc = new Scanner(System.in);

    String S = sc.next();
    boolean containsA = S.contains("A");
    boolean containsB = S.contains("B");

    System.out.println((containsA && containsB) ? "Yes" : "No");
  }
}


Measured memory_bytes: 21844
#include <stdio.h>
#include <algorithm>
#include <iostream>
#include <vector>
#include <assert.h>
#include <map>
#include <set>
#include <unordered_set>
#include <unordered_map>
#include <stdlib.h>
#include <math.h>
#include <string>
#include <time.h>
#include <string.h>
#include <queue>
#include <complex>
#include <iomanip>
#include <stack>
using namespace std;
typedef long long int ll;
typedef unsigned long long int ull;
ll mod=1e9+7;
double eps=1e-7;
ll exp(ll x,ll y){if(y<0) return 0; ll ret=1;for(;y;y>>=1,x=(x*x)%mod){if(y&1)ret=(ret*x)%mod;}return ret;}
ull pexp(ull x,ull y){if(y<0) return 0; ull ret=1; for(;y;y>>=1,x=(x*x)){if(y&1)ret=(ret*x);}return ret;}
ll gcd(ll x,ll y){if(!x||!y) return x+y; return x%y==0?y:gcd(y,x%y);}
ll lcm(ll x,ll y){return x*(y/gcd(x,y));}
ll bsum(ll u,ll b){ll ret=0;if(u<b)return u;while(u){ret+=u%b;u/=b;}return ret;}
ll prival(ll u,ll p){ll cn=0;while(u%p==0){cn++;u=u/p;}return cn;}
ll minv(ll a,ll b){return 1<a?b-minv(b%a,a)*b/a:1;}
ll extm(ll a,ll b){ll ret=0;while(a!=0){if(a%2==1){ret+=b;ret%=mod;}a>>=1;b=(2*b)%mod;}return ret;}   
ll eaphi(ll x){ll t=x,ret=x,i;for(i=2;i*i<=x;i++){if(t%i==0){ret-=ret/i;while(t%i==0) t/=i;}}if(t!=1) ret-=ret/t;return ret;}
ll eadivc(ll x){ll ret=0;ll i;for(i=1;i*i<=x;i++){if(x%i==0 && i*i!=x) ret+=2;if(x%i==0 && i*i==x) ret+=1;}return ret;}
ll eadivs(ll x){ll ret=0;ll i;for(i=1;i*i<=x;i++){if(x%i==0 && i*i!=x) ret+=i+x/i;if(x%i==0 && i*i==x) ret+=i;}return ret;}
ll ndig(ll x, ll b){ll ret=0;while(x){x/=b; ret++;}return ret;}
ll rev(ll n, ll b){ll ret=0;while(n){ret=b*ret+n%b; n/=b;}return ret;}
ll sq(ll x){ll t=(ll)sqrt(x); for(ll i=t-2 ; i<=t+2 ; i++) if(i*i==x) return abs(i); return -1;}
ll extexp(ll x,ll y){if(y<0) return 0; ll ret=1;for(;y;y>>=1,x=extm(x,x)){if(y&1)ret=extm(ret,x);}return ret;}
bool isprime(ll x){if(x<=1) return false; for(ll i=2;i*i<=x;i++){if(x%i==0){return false;}}return true;}
int n;
int cnt[26];
int vv[26];
string s;

int main(void)
{
	cin>>n; int i, j;
	for(i=0 ; i<26 ; i++) vv[i]=1e9;
	for(i=1 ; i<=n ; i++)
	{
		cin>>s;
		for(j=0 ; j<26 ; j++) cnt[j]=0;
		for(j=0 ; j<s.length() ; j++) cnt[s[j]-'a']++;
		for(j=0 ; j<26 ; j++) vv[j]=min(vv[j],cnt[j]);
	}
	for(i=0 ; i<26 ; i++)
		for(j=0 ; j<vv[i] ; j++) printf("%c",'a'+i);
	return 0;
}

Measured memory_bytes: 256