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

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

  vector<vector<int>> v(M);
  for (int i = 0; i < M; i++) {
    int k;
    cin >> k;
    v[i].resize(k);
    for (int j = 0; j < k; j++) {
      cin >> v[i][j];
      v[i][j] -= 1;
    }
  }

  vector<int> p(M);
  for (int i = 0; i < M; i++) {
    cin >> p[i];
  }

  int answer = 0;
  for (int i = 0; i < (1 << N); i++) {
    bool validate = true;
    for (int j = 0; j < M; j++) {
      int c = 0;
      for (int k = 0; k < v[j].size(); k++) {
        if ((i >> v[j][k]) & 1) {
          c++;
        }
      }
      if ((c % 2) != p[j]) {
        validate = false;
      }
    }
    if (validate) {
      answer++;
    }
  }

  cout << answer << endl;

}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define REP(i, n) for (int i = 0; i < (n); ++i)
#define SORT(v) sort((v).begin(), (v).end())
#define RSORT(v) sort((v).rbegin(), (v).rend())
const ll MOD = 1000000007;
const int nmax = 8;
bool graph[nmax][nmax];
const int INF = 1e9;
vector<vector<ll>> dist = vector<vector<ll>>(nmax, vector<ll>(nmax, INF));
void warshall_floyd(ll n)
{
    for (size_t i = 0; i < n; i++)
    {
        for (size_t j = 0; j < n; j++)
        {
            for (size_t k = 0; k < n; k++)
            {
                dist[j][k] = min(dist[j][k], dist[j][i] + dist[i][k]);
            }
        }
    }
}
ll gcd(ll a, ll b)
{
    if (b == 0)
        return a;
    return gcd(b, a % b);
}

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

ll mulMod(ll a, ll b)
{
    return (((a % MOD) * (b % MOD)) % MOD);
}

ll powMod(ll a, ll p)
{
    if (p == 0)
    {
        return 1;
    }
    else if (p % 2 == 0)
    {
        ll half = powMod(a, p / 2);
        return mulMod(half, half);
    }
    else
    {
        return mulMod(powMod(a, p - 1), a);
    }
}

const string YES = "Yes";
const string NO = "No";

int main()
{
    long long N;
    string str;
    cin >> str;
    N = stoi(str);
    ll S = 0;
    for (int i = 0; i < str.size(); i++)
    {
        S += (int)(str[i] - '0');
    }

    if (N % S == 0)
    {
        cout << YES << endl;
    }
    else
    {
        cout << NO << endl;
    }

    return 0;
}


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

#define A_CHARACTER 'A'
#define B_CHARACTER 'B'
#define C_CHARACTER 'C'

int main()
{
	int lettersAmount, printOutput = 0;	
	char inputChar;
	scanf("%d", &lettersAmount);
	char *letterArray;

	letterArray = malloc(sizeof(char) * lettersAmount);

	for (int i = 0; i < lettersAmount + 1; i++)
	{
		scanf("%c", &inputChar);
		letterArray[i - 1] = inputChar;
	}

	for (int i = 0; i < lettersAmount; i++)
	{
		char stringABC[3];
		if (letterArray[i] == A_CHARACTER && i < lettersAmount && i + 1 < lettersAmount && i + 2 < lettersAmount)
		{
			stringABC[0] = letterArray[i];
			stringABC[1] = letterArray[i + 1];
			stringABC[2] = letterArray[i + 2];
		}
		if (stringABC[0] == 'A' && stringABC[1] == 'B' && stringABC[2] == 'C')
		{
			printOutput++;
		}

		stringABC[0] = NULL;
		stringABC[1] = NULL;
		stringABC[2] = NULL;
	}

	printf("%d \n", printOutput);
	return 0;
}

Measured memory_bytes: 128
n, k = gets.chomp.split(" ").map(&:to_i)

heights = []

n.times do
  heights.push(gets.chomp.to_i)
end

heights = heights.sort

possible = Float::INFINITY

heights.each_with_index do |h, i|
  break if heights[i+k-1].nil?
  possible = [(h - heights[i+k-1]).abs, possible].min
end

puts possible

Measured memory_bytes: 4216
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;

int main(){
  int x;
  cin >> x;
  if (x) {
    cout << 0 << endl;
  } else {
    cout << 1 << endl;
  }
}


Measured memory_bytes: 3628
import java.util.*;
public class Main {
	public static void main(String args[]) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int p[] = new int[n];
		for(int i = 0; i < n; i++) {
			p[i] = sc.nextInt();
		}
		
		int ans = 0;
		for(int i = 1; i < n - 1; i++) {
			if(p[i - 1] < p[i] && p[i] < p[i + 1]) {
				ans++;
			} else if(p[i - 1] > p[i] && p[i] > p[i + 1]) {
				ans++;
			}
		}
		System.out.println(ans);
	}
}


Measured memory_bytes: 20692
#include<bits/stdc++.h>
using namespace std;
int main(){
	int x,y,z,ans=0;
	cin>>x>>y>>z;
	x-=2*z;
	while(x>=y){
		x-=y+z;
		ans++;
	}
	cout<<ans<<endl;
  return(0);
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<ll,ll> P;
typedef pair<int,int> Pi;
#define rep(i,n) for(ll i=0;i<n;i++)
#define FOR(i,a,b) for(ll i=a;i<b;i++)
#define fi first
#define se second
#define endl "\n"

template<typename T> inline bool chmax(T &a, T b){if(a<b){a=b;return true;}return false;}
template<typename T> inline bool chmin(T &a, T b){if(a>b){a=b;return true;}return false;}
template<typename T> ostream& operator<<(ostream& s,const complex<T>& d) {return s<<"("<<d.real()<<", "<<d.imag()<< ")";}
template<typename T1, typename T2> ostream& operator<<(ostream& s,const pair<T1,T2>& d) {return s<<"("<<d.first<<", "<<d.second<<")";}
template<typename T> ostream& operator<<(ostream& s, const vector<T>& d){int len=d.size();rep(i,len){s<<d[i];if(i<len-1) s<<" ";}return s;}
template<typename T> ostream& operator<<(ostream& s,const vector<vector<T>>& d){int len=d.size();rep(i,len){s<<d[i]<<endl;}return s;}
template<typename T> ostream& operator<<(ostream& s,const set<T>& v){s<<"{ ";for(auto itr=v.begin();itr!=v.end();++itr) {if (itr!=v.begin()) {s<< ", ";}s<<(*itr);}s<<" }";return s;}
template<typename T1, typename T2> ostream& operator<<(ostream& s,const map<T1,T2>& m){s<<"{"<<endl;for(auto itr=m.begin();itr!=m.end();++itr){s<<" "<<(*itr).first<<" : "<<(*itr).second<<endl;}s<<"}"<<endl;return s;}

const ll mod=1e9+7;
const ll inf=1e17;
const int INF=1e9;
const double PI=acos(-1);
const double EPS=1e-10;

int main(){
	cin.tie(0);ios::sync_with_stdio(false);
	int a,b,c;
	cin>>a>>b>>c;
	FOR(k,1,1e8){
		if((k*a-c)%b==0){
			cout<<"YES"<<endl;
			return 0;
		}
	}
	cout<<"NO"<<endl;
}

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




int32_t main()
{
	ios::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	int N;
	cin >> N;
	int total = 0;
	int actu = 0;
	for (int i = 0 ; i < N ; i++)
	{
		int a;
		cin >> a;
		total += max(0ll , actu - a);
		actu = max(actu , a);
	}
	cout<<total<<endl;
}

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

typedef long long LL;
typedef pair<int, int> PII;
typedef vector<int> VI;
#define MP make_pair
#define PB push_back
#define X first
#define Y second

#define FOR(i, a, b) for(int i = (a); i < (b); ++i)
#define RFOR(i, b, a) for(int i = (b) - 1; i >= (a); --i)
#define ITER(it, a) for(__typeof(a.begin()) it = a.begin(); it != a.end(); ++it)
#define ALL(a) a.begin(), a.end()
#define SZ(a) (int)((a).size())
#define FILL(a, value) memset(a, value, sizeof(a))
#define debug(a) cout << #a << " = " << a << endl;

const double PI = acos(-1.0);
const LL INF = 1e9;
const LL LINF = INF * INF;

const int MAX = 404;
int n;
int a[MAX];
LL dp[MAX][MAX];
LL sum[MAX];

LL get(int l, int r)
{
	LL res = sum[r];
	if (l)
		res -= sum[l - 1];
	return res;
}

int main()
{
	ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
	//freopen("In.txt", "r", stdin);
	//freopen("In.txt", "w", stdout);

	cin >> n;
	FOR(i, 0, n)
		cin >> a[i];
	sum[0] = a[0];
	FOR(i, 1, n)
		sum[i] = sum[i - 1] + a[i];
	
	FOR(i, 0, n)
		FOR(j, 0, n)
			dp[i][j] = LINF;
	FOR(i, 0, n - 1)
		dp[i][i + 1] = a[i] + a[i + 1];
	
	FOR(i, 0, n)
		dp[i][i] = 0;
	
	FOR(len, 3, n + 1)
	{
		FOR(l, 0, n)
		{
			int r = l + len - 1;
			if (r >= n)
				break;
			
			FOR(k, l, r)
			{
				LL bude = dp[l][k] + dp[k + 1][r];
				dp[l][r] = min(dp[l][r], bude);
			}
			
			dp[l][r] += get(l, r);
		}
	}

	cout << dp[0][n - 1] << endl;
	cerr << "Time elapsed: " << clock() / (double)CLOCKS_PER_SEC << endl;
	return 0;
}


Measured memory_bytes: 1536
COM_UNITE = 0
COM_SAME = 1


class UnionFind():
    def __init__(self, n):
        self.parent = list(range(n))
        self.rank = [0] * n

    def find(self, x):
        if self.parent[x] == x:
            return x
        else:
            self.parent[x] = self.find(self.parent[x])
            return self.parent[x]

    def unite(self, x, y):
        x, y = self.find(x), self.find(y)

        if x == y:
            return

        if self.rank[x] < self.rank[y]:
            self.parent[x] = y
        else:
            self.parent[y] = x
            if self.rank[x] == self.rank[y]:
                self.rank[x] += 1

    def same(self, x, y):
        return self.find(x) == self.find(y)


if __name__ == '__main__':
    n, q = (int(s) for s in input().split())
    tree = UnionFind(n)

    for i in range(q):
        com, x, y = (int(s) for s in input().split())
        if com == COM_UNITE:
            tree.unite(x, y)
        else:
            print(int(tree.same(x, y)))

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

int main()
{
  int n;
  cin >> n;
  vector<int> sq(8);
  int tmp = 1;
  rep(i, 8)
  {
    sq[i] = tmp;
    tmp *= 2;
  }
  rep(i, 8)
  {
    if (n < sq[i])
    {
      cout << sq[i - 1] << endl;
      return 0;
    }
    else if (n == sq[i])
    {
      cout << sq[i] << endl;
      return 0;
    }
  }
  return 0;
}

Measured memory_bytes: 3596
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()
const ll INF = 1LL << 60;

typedef pair<int,int> P;
//締め切りが早い順に取り組めば良い
int main(){
    int n;
    cin >> n;
    vector<P> p(n);
    //bでソートしたいのでaをsecond、bをfirstに格納する
    rep(i,n) cin >> p[i].second >> p[i].first;
    sort(all(p));

    //経過時間を0とする
    ll t=0;
    rep(i,n){
        t += p[i].second;
        //締め切りをオーバーしていたら即時終了
        if(t > p[i].first){
            cout << "No" << endl;
            return 0;
        }
    }
    cout << "Yes" << endl;
    return 0;



}

Measured memory_bytes: 4812
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
constexpr long long int MOD = 1000000007;

vector<pair<ll,ll>> factorization(ll a){
    vector<pair<ll, ll>> factorize;
    for(int i = 2; i * i <= a; i++){
        if (a % i != 0) continue;
        ll cnt = 0;
        while(a % i == 0){
            a /= i;
            cnt++;
        }
        factorize.push_back({i, cnt});
    }
    if (a != 1) factorize.push_back({a, 1});
    return factorize;
}



int main(void){
    int S, W; cin >> S >> W;
    
    if (W >= S) cout << "unsafe" << endl;
    else cout << "safe" << endl;
}


Measured memory_bytes: 3600
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0; i < (n); i++)
using Graph = vector<vector<int>>;
ll mod = 1000000007;

int main()
{
    ll n;
    cin >> n;
    vector<ll> c(n);
    rep(i, n) {
        cin >> c[i];
    }
    sort(c.begin(), c.end());
    ll pow4n = 1LL;
    rep(i, n - 1) {
        pow4n *= 4;
        pow4n %= mod;
    }

    ll ans = 0;
    rep(i, n) {
        ans += c[i] * (n - i + 1);
        ans %= mod;
    }

    ans *= pow4n;
    ans %= mod;
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 1792
import java.util.Scanner;

class Main{
    public static void main(String[] args){
        Scanner sc=new Scanner(System.in);
        int a=sc.nextInt();
        int b=sc.nextInt();
        
        if(a>b){
            System.out.println("a > b");
        }else if(a==b){
            System.out.println("a == b");
        }else if(a<b){
            System.out.println("a < b");
        }
        
        
    }
}


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

int main() {
  int N, A, M;
  cin >> N >> A;
  M = N / 500;
  
  if (N - 500 * M <= A) {
    cout << "Yes" << endl;
  }
  else {
    cout << "No" << endl;
  }
}


Measured memory_bytes: 256
using static System.Console;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace B_palindrome_philia
{
    class Program
    {
        static void Main(string[] args)
        {
            string input = ReadLine();
            int count = 0;
            for (int i = 0; i < input.Length/2; i++) {
                if (input[i]!=input[input.Length-1-i]) {
                    count++;
                }
            }
            WriteLine(count);
            ReadKey();          
        }
    }
}


Measured memory_bytes: 13140
#include <iostream>
#include <vector>

using namespace std;

int main(int argc, char *argv[])
{
  int N, M, K;
  cin >> N >> M >> K;
  for (int i = 0; i <= N; i++ ) {
    int cnti = M * i;
    for (int j = 0; j <= M; j++ ) {
      int cntj = cnti + ((N - i) - i) * j;
      if (cntj == K) {
        std::cout << "Yes" << std::endl;
        return 0;
      }
    }
  }
  std::cout << "No" << std::endl;
  return 0;
}


Measured memory_bytes: 256
#get input
n = input()
S = list(map(lambda x: int(x), input().split(' ')))
q = input()
T = list(map(lambda x: int(x), input().split(' ')))

#iterate T and count
count = 0
for i in T:
    #binary search
    left = 0
    right = len(S)-1
    while left <= right:
        pointer = (left+right)//2
        if S[pointer] == i:
            count += 1
            break
        elif S[pointer] < i:
            left = pointer+1
        else:
            right = pointer -1
print(count)


Measured memory_bytes: 16704
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int mod = 1e9+7;

int main() {
    ll N, T;
    cin >> N >> T;
    vector<int> d(N);
    for (int i=0; i<N; ++i) cin >> d[i];
    sort(d.begin(), d.end());

    ll res = 1;
    for (int i=0; i<N; ++i) {
        ll t = i - (lower_bound(d.begin(), d.begin()+i, d[i]-T) - d.begin()) + 1;
        (res *= t) %= mod;
    }
    cout << res << endl;
    return 0;
}


Measured memory_bytes: 3172
#include <iostream>
#include <cmath>
#include <vector>
#include <string>
#include <map>
#include <queue>
#include <algorithm>
#include <numeric>
#include <fstream>
#include <iomanip>

typedef long double ld;
typedef long long ll;
const ll INF = (ll)1e18 + 1;
const ll MOD = 1e9 + 7;

// Output
template<class T, class S> std::ostream& operator <<(std::ostream& os, std::pair<T, S> p)
{
  return os << "(" << p.first << " " << p.second << ")";
}

template<class T> std::ostream& operator <<(std::ostream& os, std::vector< T > v)
{
  for (ll i = 0; i < (ll)v.size(); i++){ os << " [" << i << "]" << v[i]; if (i % 10 == 9) os << std::endl; }
  //os << v[0]; for (ll i = 1; i < (ll)v.size(); i++){ os << " " << v[i]; }
  return os;
}

template<class T, class S> std::ostream& operator <<(std::ostream& os, std::map< T, S > m)
{
  ll i = 0; for (auto p : m){ os << " [" << i << "]" << p.first << "->" << p.second; i++;}
  return os;
}

template<class T> std::ostream& operator <<(std::ostream& os, std::vector< std::vector<T> > vv)
{
  for (auto& vec : vv){ os << vec << std::endl; }
  os << "--------" << std::endl;
  return os;
}

void print(){ std::cout << std::endl; }
template<typename H> void print(H&& head){ std::cout << head << std::endl; }
template<typename H, typename... T> void print(H&& head, T&&... tail){
  std::cout << head << " ", print(std::forward<T>(tail)...);
}

// FAIL
void finish(ll ans){ print(ans); std::exit(0); }
//void fail(){ print("No"); std::exit(0); }

void solve()
{
  ll N;
  std::cin >> N;
  std::vector< ll > va(N, 0LL);
  for (ll i = 0; i < N; i++) {
    std::cin >> va[i];
    if (va[i] == 0) {
      finish(0);
    }
  }

  ll ans = 1LL;
  for (auto a : va) {
    ld check = 1e18 / (ld)a;
    if (ans > check) {
      finish(-1);
    }
    ans *= a;
  }

  print(ans);
  return;
}

int main()
{
  std::cin.tie(nullptr);
  std::cout.tie(nullptr);
  std::ios::sync_with_stdio(false);

  solve();
  return 0;
}



Measured memory_bytes: 4400
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        Node[] nodes = new Node[n];
        for (int i = 0; i < n; i++) {
            int id = sc.nextInt();
            int[] children = new int[]{sc.nextInt(), sc.nextInt()};
            nodes[id] = new Node(id, children);
        }

        solve(nodes);

        for (int i = 0; i < nodes.length; i++) {
            Node node = nodes[i];
            int degree = 0;
            for (int j = 0; j < node.children.length; j++) {
                if (node.children[j] != -1) {
                    degree++;
                }
            }
            String type = node.type == Type.INTERNAL_NODE ? "internal node" : node.type == Type.LEAF ? "leaf" : "root";
            System.out.println("node " + node.id + ": parent = " + node.parent + ", sibling = " + node.sibling
                               + ", degree = " + degree + ", depth = " + node.depth + ", height = " + node.height
                               + ", " + type);
        }
    }

    private static void solve(Node[] nodes) {
        for (int i = 0; i < nodes.length; i++) {
            Node n = nodes[i];
            if (n.children[0] != -1) {
                nodes[n.children[0]].parent = n.id;
                nodes[n.children[0]].sibling = n.children[1];
            }
            if (n.children[1] != -1) {
                nodes[n.children[1]].parent = n.id;
                nodes[n.children[1]].sibling = n.children[0];
            }
        }

        int root = -1;
        for (int i = 0; i < nodes.length; i++) {
            Node n = nodes[i];
            if (n.parent == -1) {
                root = n.id;
                n.type = Type.ROOT;
                n.depth = 0;
            }
        }

        nodes[root].height = rec(nodes, root, 1);
    }

    private static int rec(Node[] nodes, int parent, int depth) {
        int[] children = nodes[parent].children;
        int height = -1;
        for (int i = 0; i < children.length; i++) {
            if (children[i] != -1) {
                Node node = nodes[children[i]];
                node.depth = depth;
                node.height = rec(nodes, children[i], depth + 1);
                height = Math.max(height, node.height);
                if (node.height != 0) {
                    node.type = Type.INTERNAL_NODE;
                } else {
                    node.type = Type.LEAF;
                }
            }
        }
        return height + 1;
    }

    static class Node {

        Node(int id, int[] children) {
            this.id = id;
            this.children = children;
            this.parent = -1;
            this.sibling = -1;
        }

        int id;
        int sibling;
        int parent;
        int depth;
        int height;
        int[] children;
        Type type;
    }

    enum Type {
        ROOT, INTERNAL_NODE, LEAF;
    }
}

Measured memory_bytes: 26248
import sys 
x=[]
for i in range(3):
  a,b,c=map(int,input().split())
  x.append(a)
  x.append(b)
  x.append(c)
n=int(input())
p=[int(input()) for i in range(n)]
for i in range(9):
  if x[i] in p:
    x[i]=0
def ch(s,d):
  global x
  if x[s]==0 and x[s+d]==0 and x[s+d+d]==0:
    print('Yes')
    sys.exit()
d=1
ch(0,d)
ch(3,d)
ch(6,d)
d=3
for i in range(3):
  ch(i,d)
ch(2,2)
ch(0,4)
print('No')

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
const int maxn = 200200;
int x[maxn], y[maxn], q[maxn], cnt;
void add(int x){
	q[x]++;
	if(q[x] == 1) cnt++;
}
void rem(int x){
	q[x]--;
	if(q[x] == 0) cnt--;
}
int main(){
	int n; cin >> n;
	for(int i = 1; i <= n; i++) cin >> x[i] >> y[i];
	vector<pair<int, int> > vals;
	for(int i = 1; i <= n; i++){
		vals.push_back({x[i], -i});
		vals.push_back({y[i], +i});
	}
	sort(vals.begin(), vals.end());
	int mn = vals[0].first, mx = vals.back().first;
	long long ans = 1ll * (mx - mn) * (mx - mn);
	vector<int> g1, g2;
	for(int i = 1; i <= n; i++){
		if(x[i] > y[i]) swap(x[i], y[i]);
		g1.push_back(x[i]);
		g2.push_back(y[i]);
	}
	sort(g1.begin(), g1.end());
	sort(g2.begin(), g2.end());
	ans = min(ans, 1ll * (g1.back() - g1[0]) * (g2.back() - g2[0]));
	for(int i = 0, j = 0; i < 2 * n; i++){
		while(j < 2 * n && cnt < n){
			int id = vals[j].second;
			if(id < 0) id = -id;
			add(id);
			j++;
		}
		if(cnt == n){
			ans = min(ans, 1ll * (mx - mn) * (vals[j - 1].first - vals[i].first));
		}
		int id = vals[i].second;
		if(id < 0) id = -id;
		rem(id);
	}
	cout << ans << endl;
	return 0;
}



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

int main(){
    int n,m,c;
    cin >> n >> m >> c;
    vector<int> b(m);
    vector<vector<int>> a(n,vector<int>(m));
    for (int i = 0;i < m;i++){
        cin >> b.at(i);
    }

    for (int i = 0;i < n;i++){
        for (int j = 0;j < m;j++){
            cin >> a.at(i).at(j);
        }
    }

    int cnt = 0;
    for (int i = 0;i < n;i++){
        int sum = 0;
        for (int j = 0;j < m;j++){
            sum += a.at(i).at(j)*b.at(j);
        }
        if (sum + c > 0){
            cnt++;
        }
    }

    cout << cnt << endl;
}

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

int main(){
	int x;
	cin>>x;
	for(int a=-1000; a<1000; a++) for(int b=-1000; b<1000; b++) if((ll)a*a*a*a*a-(ll)b*b*b*b*b==x){
		cout<<a<<" "<<b<<endl;
		return 0;
	}
	return 0;
}


Measured memory_bytes: 3608
// 27
#include <bits/stdc++.h>
using namespace std;
#define endl '\n'
#define fors(_, x, n, s) for (int _ = x; _ < n; _ += s)
#define forn(_, x, n) fors(_, x, n, 1)
#define rep(_, n) forn(_, 0, n)
#define forrs(_, x, n, s) for (int _ = x; _ > n; _ -= s)
#define forrn(_, x, n) forrs(_, x, n, 1)
#define rrep(_, n) forrn(_, n - 1, -1)
#define fi first
#define se second
#define pb push_back
#define pairii pair<int, int>
#define all(x) x.begin(), x.end()
#define len(x) int(x.size())
#define lli __int128_t
#define li long long int
#define ld long double
#ifdef LOCAL
#define debug(e) cerr << "\033[48;5;196m\033[38;5;15m" << e << "\033[0m";
#else
#define debug(e)
#endif
// 4
template <class A, class B>
ostream &operator<<(ostream &o, const pair<A, B> &p) {
  return o << "(" << p.fi << " " << p.se << ")";
}
// 8
template <class T>
ostream &operator<<(ostream &o, const vector<T> &v) {
  rep(i, (int)v.size()) o << setw(7) << left << v[i];
  return o << endl;
}
// 5
template <class A, class B>
ostream &operator<<(ostream &o, const map<A, B> &m) {
  for (auto &kv : m) o << kv;
  return o;
}
// 3
void _main(int tc) {
  int h, w;
  cin >> h >> w;
  vector<vector<char>> o(h, vector<char>(w)), a(2 * h, vector<char>(w));
  rep(i, h) {
    rep(j, w) { cin >> o[i][j]; }
  }
  rep(i, 2 * h) {
    rep(j, w) { a[i][j] = o[i / 2][j]; }
  }

  rep(i, 2 * h) {
    rep(j, w) { cout << a[i][j];}
    cout << endl;
  }
}
// 7
int main() {
  ios_base::sync_with_stdio(0), cin.tie(0);
  _main(0), exit(0);
  int tc;
  cin >> tc;
  rep(i, tc) _main(i + 1);
}

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

int main()
{
	int n,y,k;
	cin>>n>>y;
	for(int i=0; i<=y/10000; i++){
		for(int j=0; j<=y/5000; j++){
			k=n-i-j;
			if(k>=0 && i*10000+j*5000+k*1000==y){
				cout<<i<<" "<<j<<" "<<k<<endl;
				return 0;
			}
		}
	}
	cout<<"-1 -1 -1"<<endl;
	
	return 0;
}

Measured memory_bytes: 256
import sys, bisect, math, itertools, heapq, collections
from operator import itemgetter
# a.sort(key=itemgetter(i)) # i番目要素でsort
from functools import lru_cache
# @lru_cache(maxsize=None)
sys.setrecursionlimit(10**8)
input = sys.stdin.readline
INF = float('inf')
mod = 10**9 + 7
eps = 10**-7


def inp():
    '''
    一つの整数
    '''
    return int(input())


def inpl():
    '''
    一行に複数の整数
    '''
    return list(map(int, input().split()))


def str_inp():
    '''
    文字列をリストとして読み込む
    '''
    return list(input()[:-1])


n, x, t = inpl()
print(math.ceil(n / x) * t)


Measured memory_bytes: 68544
#include <algorithm>
#include <bitset>
#include <cmath>
#include <complex>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>

typedef long long ll;

#define rep(i, a, n) for (ll i = a; i < (ll)n; ++i)
#define INF 10e12
#define MOD 1000000000 + 7
#define MAX 51000
#define all(x) (x).begin(), (x).end()
#define MX(x) *max_element(all(x))
#define MN(x) *min_element(all(x))

using namespace std;

int main(void)
{
    cin.tie(0);
    cout.tie(0);
    ios::sync_with_stdio(false);
    string s;
    cin >> s;
    int ans = 0;
    rep(i, 0, s.size() / 2)
    {
        if (s[i] != s[s.size() - 1 - i])
            ans++;
    }
    cout << ans << endl;
}

Measured memory_bytes: 3640
#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=a;i<b;i++)
#define rrep(i,a,b) for(int i=a;i>=b;i--)
#define fore(i,a) for(auto &i:a)
#define all(x) (x).begin(),(x).end()
#define INF 10000000
using namespace std;
typedef long long ll;

int main() {
    int n;
    cin >> n;
    vector<int> h(n);
    vector<int> dp(n, INF);
    for (int i = 0; i < n; ++i) {
        cin >> h[i];
    }
    dp[0] = 0;
    /*
       for (int i = 0; i + 1 < n; ++i) {
       if (dp[i + 1] > dp[i] + abs(h[i] - h[i + 1])) {
       dp[i + 1] = dp[i] + abs(h[i] - h[i + 1]);
       }
       if (i + 2 < n && dp[i + 2] > dp[i] + abs(h[i] - h[i + 2])) {
       dp[i + 2] = dp[i] + abs(h[i] - h[i + 2]);
       }
       }
       */
    for (int i = 1; i < n; ++i) {
        if (i==1) {
            dp[i] = abs(h[0] - h[1]);
        } else {
            dp[i] = min(dp[i-2]+abs(h[i-2]-h[i]),dp[i-1]+abs(h[i-1]-h[i]));
        }
    }
    cout << dp[n - 1] << endl;
}


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

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

#define mod 1e9+7;
#define inf 1e18+7;

typedef long long ll;

int main() {
    int n;
    string a,b;
    cin>>n>>a>>b;

    rep(i,n){
        cout<<a[i]<<b[i];
    }
    cout<<endl;
}


Measured memory_bytes: 256
main () {
    int H, W;
    scanf("%d %d", &H, &W);
    while ((H != 0) && (W != 0)) {
        for (int i = 1; i <= H; i++) {
            for (int j = 1; j <= W; j++) {
                printf("#");
            }
            printf("\n");
        }
        printf("\n");
        scanf("%d %d", &H, &W);
    }
}


Measured memory_bytes: 2052
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<int(n);++i)
#define all(a) a.begin(),a.end()

using P = pair<int,int>;

int area(P c){
    return c.first*c.second;
}

namespace std {
    bool operator<(const P a, const P b) {
        return area(a) < area(b);
    }
}

pair<P,P> cut(P c,int s){
    int w = c.first, h = c.second;
    s %= (c.first+c.second)*2;
    P p1,p2;
    if(s < w){
        p1 = {s,h}, p2 = {w-s,h};
    }else if(s < w+h){
        s -= w;
        p1 = {w,s}, p2 = {w,h-s};
    }else if(s < w*2+h){
        s -= w+h;
        p1 = {s,h}, p2 = {w-s,h};
    }else{
        s -= w*2+h;
        p1 = {w,s}, p2 = {w,h-s};
    }
    return minmax(p1,p2);
}

int main(void){
    int N,W,H;
    while(cin>>N>>W>>H, N|W|H){
        vector<P> cake = {{W,H}};
        rep(i,N){
            int p,s;
            cin>>p>>s;
            p--;
            pair<P,P> cake_pair = cut(cake[p],s);
            cake.erase(cake.begin()+p);
            cake.push_back(cake_pair.first);
            cake.push_back(cake_pair.second);
        }
        sort(all(cake));
        rep(i,N+1){
            cout<<area(cake[i])<<(i<N ? " " : "\n");
        }
    }
    return 0;
}



Measured memory_bytes: 3012
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <ctime>
#include <cctype>

#include <algorithm>
#include <random>
#include <bitset>
#include <queue>
#include <functional>
#include <set>
#include <map>
#include <vector>
#include <chrono>
#include <iostream>
#include <limits>
#include <numeric>

#define LOG(FMT...) fprintf(stderr, FMT)

using namespace std;

typedef long long ll;
typedef unsigned long long ull;

// mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

template <class T>
istream& operator>>(istream& is, vector<T>& v) {
  for (T& x : v)
    is >> x;
  return is;
}

template <class T>
ostream& operator<<(ostream& os, const vector<T>& v) {
  if (!v.empty()) {
    os << v.front();
    for (int i = 1; i < v.size(); ++i)
      os << ' ' << v[i];
  }
  return os;
}

int main() {
#ifdef LBT
  freopen("test.in", "r", stdin);
  int nol_cl = clock();
#endif
  ios::sync_with_stdio(false);
  cin.tie(nullptr);

  int M;
  cin >> M;
  ll ans = -1, sum = 0;
  while (M--) {
    int d;
    ll c;
    cin >> d >> c;
    sum += d * c;
    ans += c;
  }
  if (sum > 9)
    ans += (sum - 1) / 9;
  cout << ans << '\n';

#ifdef LBT
  LOG("Time: %dms\n", int ((clock()
          -nol_cl) / (double)CLOCKS_PER_SEC * 1000));
#endif
  return 0;
}


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

using namespace std;

#pragma GCC optimize("-O3")
#pragma GCC target("avx2")

#define int long long

const int INF = 1e18;

int32_t main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    int n;
    cin >> n;
    int m = INF;
    vector<int> a(n);
    for (int i = 0; i < n; ++i)
    {
        cin >> a[i];
        if (a[i] == 0)
        {
            cout << 0 << endl;
            return 0;
        }
        m /= a[i];
    }
    if (m == 0)
    {
        cout << -1 << endl;
    }
    else
    {
        int ans = 1;
        for (auto el : a)
        {
            ans *= el;
        }
        cout << ans << endl;
    }
    return 0;
}


Measured memory_bytes: 3976
#include <bits/stdc++.h>
using namespace std;
#define pp pair<int,int>
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define ll long long
#define ld long double
#define all(a) (a).begin(),(a).end()
#define mk make_pair
ll MOD=1000000007;
ll mod=998244353;
int inf=1000001000;
ll INF=1e18+5;


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


Measured memory_bytes: 256
n, x = map(int, input().split())

pate, slice = [1], [1]
for _ in range(n+1):
    pate.append(2 * pate[-1] + 1)
    slice.append(2 * slice[-1] + 3)

ans = 0
while n >= 0 and x > 0:
    if n == 0 and x > 0:
        ans += 1
        x -= 1
    elif x >= slice[n - 1] + 2:
        ans += pate[n - 1] + 1
        x -= slice[n - 1] + 2
    elif x < slice[n - 1] + 2:
        x -= 1
    n -= 1
print(ans)


Measured memory_bytes: 61872
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;

public class Main {
    public static void main(String args[]) {
        Scanner sc = new Scanner(System.in);
        int x = sc.nextInt();
        int y = sc.nextInt();
        List<Integer> xPrimes = primeFactors(x);
        List<Integer> yPrimes = primeFactors(y);
        if (x % y != 0) {
            System.out.println(x);
        } else {
            System.out.println(-1);
        }
        /*
        for(int p : xPrimes) {
            if (!yPrimes.contains(p)) {
                long temp = x * p;
                if (temp % y != 0) {
                    System.out.println(x * p);
                    return;
                }
            } else {
                yPrimes.remove(Integer.valueOf(p));
            }
        }
        System.out.println(-1);
        */
    }

    public static List<Integer> primeFactors(int numbers) {
        int n = numbers;
        List<Integer> factors = new ArrayList<Integer>();
        for (int i = 2; i <= n / i; i++) {
            while (n % i == 0) {
                factors.add(i);
                n /= i;
            }
        }
        if (n > 1) {
            factors.add(n);
        }
        return factors;
    }
}


Measured memory_bytes: 23892
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		try(Scanner scan = new Scanner(System.in)){
			byte[] distances = new byte[5];
			byte k;
			for(int i = 0; i < 5; i++) {
				distances[i] = scan.nextByte();
			}
			k = scan.nextByte();
			
			boolean isOk = true;
			// a:=0, b:=1, c:=2, d:=3, e:=4 
			for(int i = 0; i < 5; i++){
				for(int j = i+1; j < 5; j++) {
					if(!isCommunicatable(distances[i], distances[j], k)) {
						isOk = false;
						break;
					}
				}
			}
			System.out.println(isOk ? "Yay!" : ":(");
		}
		
	}
	
	private static boolean isCommunicatable(int c1, int c2, int k) {
		return (c2 - c1) <= k;
	}
}


Measured memory_bytes: 21716
#include <bits/stdc++.h>
#include <math.h>
using namespace std;
void ABC70(void);
void ABC71(void);
void ABC72(void);
void ABC73(void);
void ABC74(void);
void ABC75(void);
void ABC76(void);
void ABC77(void);
void ABC78(void);
void ABC79(void);

int main(void){
    ABC76();
}

void ABC76(){
    int n,k,ans=1,i;
    cin>>n>>k;
    for(i=0;i<n;i++){
        if(ans*2<ans+k)ans*=2;
        else ans+=k;
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 256
#include<algorithm>
#include<cmath>
#include<cstdio>
#include<functional>
#include<iomanip>
#include<iostream>
#include<map>
#include<queue>
#include<set>
#include<string>
#include<utility>
#include<vector>

using namespace std;
typedef long long ll;
const ll mod = 1000000007;
#define rep(i,n) for(int i=0;i<n;i++)
#define repl(i,s,e) for(int i=s;i<e;i++)
#define reple(i,s,e) for(int i=s;i<=e;i++)
#define revrep(i,n) for(int i=n-1;i>=0;i--)
#define all(x) (x).begin(),(x).end()


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

	ll d = 0;

	for (ll i = 1; i * i <= n; i++)
	{
		if (n % i == 0)
		{
			d = i;
		}
	}

	cout << d + n / d - 2 << endl;

	return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main
{
    public static void main(String[] args)
    {
        Scanner in = new Scanner(System.in);
        String n = in.nextLine();
        int answer = 0;
        answer += n.charAt(0) == '+' ? 1 : -1 ;
        answer += n.charAt(1) == '+' ? 1 : -1 ;
        answer += n.charAt(2) == '+' ? 1 : -1 ;
        answer += n.charAt(3) == '+' ? 1 : -1 ;
        System.out.println(answer);
    }
}


Measured memory_bytes: 23764
//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 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(){
	double rnk[]={165.0,170.0,175.0,180.0,185.0,INF};
	int n;
	cin>>n;
	string cnt[6];
	REP(i,6)cnt[i]="";
	REP(i,n){
		double t;
		cin>>t;
		REP(i,6){
			if(t<rnk[i]){
				cnt[i]+='*';
				break;
			}
		}
	}
	REP(i,6)cout<<i+1<<":"<<cnt[i]<<endl;
	return 0;
}

Measured memory_bytes: 1240
#include <bits/stdc++.h>
using namespace std;
int main(){
    int n;
    cin >> n;
    int arr[n][3];
    for(int i=0; i<n; i++)
    {
        for(int j=0; j<3; j++)
        {
            cin >> arr[i][j];
        }
    }
    int dp[n][3];
    memset(dp, -1, sizeof(dp));
    dp[0][0] = arr[0][0];
    dp[0][1] = arr[0][1];
    dp[0][2] = arr[0][2];
    for(int i=1; i<n; i++)
    {
        for(int j=0; j<3; j++)
        {
            for(int k=0; k<3; k++)
            {
                if(j==k)
                    continue;
                dp[i][j] = max(dp[i][j], arr[i][j] + dp[i-1][k]);
            }
        }
    }
    cout << max({dp[n-1][0], dp[n-1][1], dp[n-1][2]}) << endl;
}

Measured memory_bytes: 2560
var GET=(function(){function f(s){return new g(s);}function g(s){this._s=s.trim().split("\n");this._y=0;}g.prototype.a=function(f){var s=this._s, y=this._y, r;if(typeof s[y]==="string")s[y]=s[y].split(" ").reverse();r=s[y].pop();if(!s[y].length)this._y++;return f?r:+r;};g.prototype.l=function(f){var s=this._s[this._y++].split(" ");return f?s:s.map(a=>+a);};g.prototype.m=function(n,f){var r=this._s.slice(this._y,this._y+=n).map(a=>a.split(" "));return f?r:r.map(a=>a.map(a=>+a));};g.prototype.r=function(n,f){var r=this._s.slice(this._y,this._y+=n);return f?r:r.map(a=>+a);};return f;})();
var o=GET(require("fs").readFileSync("/dev/stdin","utf8"));
function xArray(v){var a=arguments,l=a.length,r="Array(a["+--l+"]).fill(0).map(x=>{return "+v+";})";while(--l)r="Array(a["+l+"]).fill(0).map(x=>"+r+")";return eval(r);}

console.log(main());
function main(){
  var a = o.a();
  var b = o.a();
  if((a+b)%2)return "IMPOSSIBLE";
  return (a+b)/2;
}

Measured memory_bytes: 23092
#include "bits/stdc++.h"
using namespace std;

int main(){
	string s;
	cin>>s;
	for(int i=0;i<s.size();i++){
		if(s[i]=='9'){
			cout<<"Yes"<<endl;
			return 0;
		}
	}
	
	cout<<"No"<<endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long
#define ld long double
#define pb push_back
#define pp pop_back
#define mp make_pair
#define ff first
#define ss second
#define maxn 1000000007
#define PI 3.14159265358979323846
#define MAX 1000007 
using namespace std; 

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL); 
    //cout<<fixed<<setprecision(20);
    ll n;
    cin>>n;
    ll a[n],b[n];
    ll t=0;
    pair<ll,ll> c[n];
    for (int i = 0; i < n; ++i)
    {
        cin>>a[i]>>b[i];
        c[i].ff=b[i];
        c[i].ss=a[i];
    }
    sort(c,c+n);
    for (int i = 0; i < n; ++i)
    {
        pair<ll,ll> p=c[i];
        t+=p.ss;
        if(t>p.ff)
        {
            cout<<"No"<<endl;
            return 0;
        }
    }
    cout<<"Yes"<<endl;
    return 0;
}

Measured memory_bytes: 6528
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < n; i++)
#define FOR(i, m, n) for (int i = m; i < n; i++)
#define ALL(v) (v).begin(), (v).end()
#define coutd(n) cout << fixed << setprecision(n)
#define ll long long int
#define vl vector<ll>
#define vi vector<int>
const int INF = 2147483647;
const ll MOD = 1000000007;

using namespace std;

int main() {
  int h, w;
  cin >> h >> w;
  vector<string> s(h);
  REP(i, h) { cin >> s[i]; }

  int ans = 0;
  REP(i, h) {
    REP(j, w) {
      if (s[i][j] == '#')
        continue;
      queue<pair<pair<int, int>, int>> q;
      vector<vector<bool>> checked(h);
      REP(_i, h) {
        REP(_j, w) { checked[_i].push_back(false); }
      }
      q.push(make_pair(make_pair(i, j), 0));
      checked[i][j] = true;
      while (!q.empty()) {
        auto c = q.front();
        q.pop();
        ans = max(ans, c.second);
        int x = c.first.second;
        int y = c.first.first;
        if (x > 0 && s[y][x - 1] == '.' && !checked[y][x - 1]) {
          q.push(make_pair(make_pair(y, x - 1), c.second + 1));
          checked[y][x - 1] = true;
        }
        if (x < w - 1 && s[y][x + 1] == '.' && !checked[y][x + 1]) {
          q.push(make_pair(make_pair(y, x + 1), c.second + 1));
          checked[y][x + 1] = true;
        }
        if (y > 0 && s[y - 1][x] == '.' && !checked[y - 1][x]) {
          q.push(make_pair(make_pair(y - 1, x), c.second + 1));
          checked[y - 1][x] = true;
        }
        if (y < h - 1 && s[y + 1][x] == '.' && !checked[y + 1][x]) {
          checked[y + 1][x] = true;

          q.push(make_pair(make_pair(y + 1, x), c.second + 1));
        }
      }
    }
  }
  cout << ans << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
//#include <cstdlib>
#include <cmath>
#include <vector>
#include <algorithm>
#include <string>
#include <map>
#include <set>
#include <queue>
//#include <limits>
#include <sstream>
//#include <functional>
using namespace std;

#define len(array)  (sizeof (array) / sizeof *(array))
#define rep(i, s, e) for(int i = s;i < e;i++)
#define rrep(i, e, s) for(int i = e;s <= i;i--)
#define vrange(v) v.begin(), v.end()
#define vrrange(v) v.rbegin(), v.rend()
#define vsort(v) sort(vrange(v))
#define vrsort(v) sort(vrrange(v))
#define arange(a) a, a + len(a)
#define asort(a) sort(arange(a))
#define arsort(a, t) sort(arange(a), greater<t>())
#define afill(a, v) fill(arange(a), v)
#define afill2(a, v, t) fill((t *)a, (t *)(a + len(a)), v)
#define fmax(a, b) (a < b? b : a)
#define fmin(a, b) (a > b? b : a)
#define fabs(a) (a < 0? -a : a)
typedef unsigned int ui;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<string, int> P;
typedef pair<int, int> P2;
const int INF = (int)1e9;
const int MOD = (int)1e9 + 7;
const double EPS = 1e-10;
//const int dx[] = {1, -1, 0, 0, 1, -1, -1, 1};
//const int dy[] = {0, 0, 1, -1, -1, -1, 1, 1};
//const int weight[] = {0,1,10,100,1000,10000,100000,1000000,10000000};
//priority_queue<int, vector<int>, greater<int>> q;

vector<P> edge[41];
int n, a, s, g, x, y;

void doIt(){
  string ss, costs[2][41];
  // int nums[41];
  int now, prev;
  bool bOK;
  int mxlen;
  const string inf = "INF";
	while(true){
		cin >> n >> a >> s >> g;
		if(n+a+s+g == 0) break;
		mxlen = 0;
		rep(i, 0, a){
			cin >> x >> y >> ss;
			//逆に辿る
			edge[y].push_back(P(ss, x));
			mxlen = fmax(mxlen, ss.length());
		}
		//rep(i, 0, n) vsort(edge[i]);
		//Bermann-Ford
		now = 0;
		prev = 1;
		afill2(costs, inf, string);
		// afill(nums, 0);
		costs[prev][g] = costs[now][g] =  "";
		bOK = true;
		rep(k, 0, (mxlen+1)*n + 2){
		  rep(i, 0, n){
			if(costs[prev][i] != inf){
			  rep(j, 0, edge[i].size()){
				P e = edge[i][j];
				if(costs[now][e.second] == inf || e.first + costs[prev][i] < costs[now][e.second]){
				  // cout << "bef : " << costs[now][e.second] << endl;
				  costs[now][e.second] = e.first + costs[prev][i];
				  // cout << "aft : " <<  costs[now][e.second] << endl;
				  if(e.second == s && n <= k){
					bOK = false;
					break;
				  }
				}
			  }
			}
		  }
		  rep(i, 0, n){
			costs[prev][i] = costs[now][i];
		  }
		  prev = 1 - prev;
		  now = 1 - now;

		}
		if(bOK && costs[now][s] != inf) cout << costs[now][s] << endl;
		else cout << "NO" << endl;
		rep(i, 0, n) edge[i].clear();
	}

}

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

Measured memory_bytes: 1372
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <utility>
using namespace std;
typedef long long ll;
#define rep(i, n) for (int i=0;i < (int)(n);i++)

int table[101][101];



int main(){
    int n;
    string s,t;
    cin >> s >> t;
    if(s[0] == t[2] && s[1] == t[1] && s[2] == t[0]) cout << "YES" << endl;
    else cout << "NO" << endl;


    return 0;
}

Measured memory_bytes: 256
/*input
naohiro
*/
/*

**************************
*						 *
* AUTHOR :: knight_coder *
*						 *
**************************

*/
#include<bits/stdc++.h>
#define lld          long long int
#define pb          push_back
#define ppb         pop_back
#define	endl		'\n'
#define mii         map<lld,lld>
#define msi         map<string,lld>
#define mis         map<lld, string>
#define mpi         map<pair<lld ,lld >,lld >
#define pii         pair<lld,lld>
#define vi          vector<lld>
#define vpi 		vector<pii>
#define vs          vector<string>
#define all(a)      (a).begin(),(a).end()
#define F           first
#define S           second
#define sz(x)       (lld)x.size()
#define hell        1000000007
#define rrep(i,m,n)	for(lld i=m;i>=n;i--)
#define rep(i,m,n)	for(lld i=m;i<n;i++)
#define lbnd        lower_bound
#define ubnd        upper_bound
#define bs          binary_search
#define mp          make_pair
#define what_is(x)  cerr << #x << " is " << x << endl;
#define pr(x) 		cout<< x << " ";
#define pre(x)		cout<< x << endl ;
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
template<typename T>
using ordered_set = tree<T,null_type,less<T>,rb_tree_tag,tree_order_statistics_node_update>; 
//change null_type to get ordered_map
#define N  100005
void solve()
{
	string s;
	cin >> s;
	cout << s.substr(0,3) << endl; 
}
int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	int tests=1;
	//cin>>tests;
	while(tests--)
	{
		solve();
	}
}

Measured memory_bytes: 3660
#include <stdio.h>
//#include <stdlib.h>
//#include <string.h>
//#include <stdbool.h>
//#include <limits.h>
//#include <math.h>

#define MOD 1000000007
#define N 1000001
#define MIN(a, b) ((a<b) ? a : b)

long fac[N], inv[N], finv[N];
void com_init()
{
  fac[0] = 1;
  fac[1] = 1;
  finv[0] = 1;
  finv[1] = 1;
  inv[1] = 1;
  for (int i = 2; i < N; i++)
  {
    fac[i] = fac[i - 1] * i % MOD;
    inv[i] = MOD - inv[MOD % i] * (MOD / i) % MOD;
    finv[i] = finv[i - 1] * inv[i] % MOD;
  }
}

long combination(int a, int b)
{
  if (a < b)
    return 0;
  if (a < 0 || b < 0)
    return 0;
  return fac[a] * (finv[b] * finv[a - b] % MOD) % MOD;
}

int main() {
  int x, y;
  scanf("%d%d", &x, &y);
  if ((x+y)%3 == 0) {
    int a = x - (x+y)/3, b = y - (x+y)/3;
    com_init();
    printf("%ld\n", combination(a+b, MIN(a, b)));
    return 0;
  }
  printf("0\n");
  return 0;
}


Measured memory_bytes: 23552
#include<bits/stdc++.h>
using namespace std;
#define ll  long long
#define endl '\n'
#define FASTINOUT ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
int main()
{
    FASTINOUT;
    ll x,k,d;
    cin>>x>>k>>d;
    ll dis=abs(x)/d;
    if (k<=dis)
    {
        if (x<0)
            cout<<abs(x+d*k);
        else
            cout<<abs(x-d*k);
    }
    else
    {
        ll m=dis;
        dis=(x<0?x+d*dis:x-d*dis);
        k-=m;
        //cout<<k<<endl;
        //cout<<dis<<endl;

        if (dis<0)
            cout<<(k%2==1?abs(dis+d):abs(dis));
        else
            cout<<(k%2==1?abs(dis-d):abs(dis));

    }
    return 0;
}


Measured memory_bytes: 3664
import java.util.*;
public class Main{
  public static void main(String[] args){
    Scanner sc =new Scanner(System.in);
    long X =sc.nextInt();
    long x; long y;
    for(long i=1;;i++){
      for(long k=0;k<i;k++){
        x=i*i*i*i*i;
        y=k*k*k*k*k;
        if(x-y==X){System.out.println(i+" "+k);
                   System.exit(0);}
        if(x+y==X){System.out.println(i+" "+-k);
                   System.exit(0);}
      }
    }
  }
}

Measured memory_bytes: 38940
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll MOD = 1000000007;
const double PI = acos(-1);  

int main(){
  string s; cin >> s;

  string ans="YES";
  if(s=="AKIHABARA");
  else if(s=="KIHABARA" || s=="AKIHBARA" || s=="AKIHABRA"|| s=="AKIHABAR");
  else if(s=="KIHBARA" || s=="KIHABRA" || s=="KIHABAR");
  else if(s=="AKIHBRA" || s=="AKIHBAR" || s=="AKIHABR");
  else if(s=="KIHBRA" || s=="KIHBAR" || s=="AKIHBR"|| s=="KIHABR" );
  else if(s=="KIHBR");
  else ans = "NO";
  cout << ans << endl;
}


Measured memory_bytes: 256