akhauriyash/Code-Regression huggingface dataset:
<?php
  fscanf(STDIN,"%d%d",$h,$w);
  for($i=0; $i<$h; $i++){
      $s[] = trim(fgets(STDIN));
  }
  for($i=0; $i<$h; $i++){
      for($j=0; $j<$w; $j++){
          $flag = true;
          if($s[$i][$j] == "#"){
              if($s[$i-1][$j] == "#" || $s[$i+1][$j] == "#" ||
                 $s[$i][$j-1] == "#" || $s[$i][$j+1] == "#"){
                     $flag = false;
                 }
              if($flag){
              echo "No";
              exit;
              }
          }
      }
  }
  echo "Yes";

Measured memory_bytes: 4604
#include<bits/stdc++.h>
using namespace std;
int main(){
  int n,m;cin>>n>>m;
  vector<int> dp(1<<n,1e9);
  dp[0] = 0;
  for(int i=0;i<m;++i){
    int cost;int num;
    cin>>cost>>num;
    int keys = 0;
    for(int j=0;j<num;++j){
        int cur;cin>>cur;
        keys |= (1<<(cur-1));
    }
    for(int mask = 0;mask<(1<<n);++mask){
      if((mask|keys) > mask){
        dp[mask|keys] = min(dp[mask] + cost,dp[mask|keys]);
      }
    }
  }
  
  if(dp[(1<<n)-1] < 1e9){
    cout<<dp[(1<<n)-1]<<endl;
  }else{
    cout<<-1<<endl;
  }
  return 0;
}

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

using namespace std;
typedef long long ll;

#define rep(i, n) for (ll i = 0; i < (n); ++i)
//#define rep(i, n) for (int i = 0; i < (n); ++i)
#define sz(x) ll(x.size())
//typedef pair<int, int> P;
typedef pair<ll, ll> P;
//const double INF = 1e10;
const ll INF = LONG_LONG_MAX;
const ll MINF = LONG_LONG_MIN;
//const int INF = INT_MAX;
#define cmin(x, y) x = min(x, y)
#define cmax(x, y) x = max(x, y)

bool contain(set<int> &s, int a) { return s.find(a) != s.end(); }


//ifstream myfile("C:\\Users\\riku\\Downloads\\0_00.txt");
//ofstream outfile("log.txt");
//outfile << setw(6) << setfill('0') << prefecture << setw(6) << setfill('0') << rank << endl;
// std::cout << std::bitset<8>(9);

typedef priority_queue<ll, vector<ll>, greater<ll>> PQ_ASK;
//const int mod = 1000000007;
const ll mod = INF / 1000;

bool check(int candidate, vector<ll> &points, int voting_count, int task_count, ll judge_count) {
    if (candidate < task_count) return true;
    ll border = points[task_count - 1];
    ll me = points[candidate];
    ll me_max = me + judge_count;
    if (me_max < border) return false;

    voting_count--; // 自分に
    ll strong = (task_count - 1);// 入れるから
    voting_count -= strong; // 既に当確の奴に全部入れる
    int weak = points.size() - candidate - 1; // 自分より弱い奴にはいくら上げてもいい
    voting_count -= weak;

    if (voting_count <= 0) return true;

    ll all_voting_count = judge_count * voting_count;

    for (int t = task_count - 1; t < candidate; t++) {
        ll capacity = me_max - points[t]; // 受け入れられる票数
        if (capacity >= judge_count) {
            all_voting_count -= judge_count;
        } else {
            all_voting_count -= capacity;
        }
    }

    return all_voting_count <= 0;
}


int main() {

    int n, v, p;
    ll m;
    cin >> n >> m >> v >> p;

    vector<ll> points(n);

    rep(i, n) cin >> points[i];
    sort(points.rbegin(), points.rend());

    // 当落線

    int ceil = n - 1;
    int floor = 0;

    if (check(ceil, points, v, p, m)) {
        cout << n << endl;
        return 0;
    }

    while (floor + 1 < ceil) {
        int mid = (floor + ceil) / 2;
        if (check(mid, points, v, p, m)) {
            floor = mid;
        } else {
            ceil = mid;
        }
    }


    cout << ceil << endl;

}


Measured memory_bytes: 1152
import math

def inputs():
    return [int(s) for s in input().split(" ")]

#----------#
elem = inputs()
N = elem[0]
D = elem[1]

points = []
for i in range(N):
    points.append(inputs())

anscount = 0
for i_pt in points:
    for j_pt in points:
        if i_pt == j_pt:
            break
        sumup = 0
        for k in range(D):
            sumup += abs(i_pt[k] - j_pt[k]) ** 2
        if(math.sqrt(sumup) % 1 == 0):
            anscount +=1

print(anscount)

Measured memory_bytes: 3064
#include <bits/stdc++.h>
#ifdef HIRO
#define d(f_, ...) printf((f_), ##__VA_ARGS__)
#else
#define d(f_, ...)
#endif

using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<long long> vll;
typedef queue<int> qi;
typedef queue< pair<int, int> > qp;
#define mp make_pair
#define pi 3.14159265358979323846
#define MAX max_element
#define MIN min_element
#define all(v) v.begin(), v.end()
#define gt(T) greater<T>()
#define sum(v) accumulate(v.begin(), v.end(), 0)
#define uni(v) do{ \
  sort(v.begin(), v.end()); \
  decltype(v)::iterator result = unique(v.begin(), v.end()); \
  v.erase(result, v.end()); \
}while(0)
#define fi(init, n) for(int i = init; i < n; ++i)
#define fj(init, n) for(int j = init; j < n; ++j)
#define fk(init, n) for(int k = init; k < n; ++k)
#define zero(x) memset(x, 0, sizeof(x))
#define negative(x) memset(x, ~0, sizeof(x))
const ll MOD = 1e9 + 7;
const int INF = 1e9;
const int di[] = { 0, 1, 0, -1 };
const int dj[] = { 1, 0, -1, 0 };

template<typename T>
T gcd(T a, T b) {
	return b ? gcd(b, a % b) : a;
}
template<typename T>
T lcm(T a, T b) {
	return a * b / gcd(a, b);
}
template<typename T>
int finder(vector<T> vec, T number) {
	auto itr = find(vec.begin(), vec.end(), number);
	size_t index = distance(vec.begin(), itr);
	if (index != vec.size()) return 1;
	else return 0;
}
ll frac(ll n){
	if (n == 0) return 1;
	return (n * frac(n - 1)) % MOD;
}
template<class T> inline bool chmin(T& a, T b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}
template<class T> inline bool chmax(T& a, T b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}

int main(int argc, char** argv) {
#ifdef HIRO
  string quiz(argv[1]);
  string id(argv[2]);
  string filename("input/" + quiz + "/" + id + ".txt");
  ifstream fin(filename);
  if (fin.peek() == ifstream::traits_type::eof()) {
    cout << "No input.";
    return 0;
  }
  ifstream cin(filename);
  std::cin.rdbuf(cin.rdbuf());
#endif
  ll ans = 0;
  // ll n;
  // cin >> n;
  // ll n, m;
  // cin >> n >> m;
  // ll n, m, k;
  // cin >> n >> m >> k;
  int arr[3][3];
  fi(0, 3)
    fj(0, 3) {
      cin >> arr[i][j];
    }
  int ng = 0;
  fi(0, 2)
    if(arr[i][0] - arr[i + 1][0] != arr[i][1] - arr[i + 1][1] || arr[i][0] - arr[i + 1][0] != arr[i][2] - arr[i + 1][2] || arr[i][1] - arr[i + 1][1] != arr[i][2] - arr[i + 1][2])
      ng = 1;
  fi(0, 2)
    if(arr[0][i] - arr[0][i + 1] != arr[1][i] - arr[1][i + 1] || arr[0][i] - arr[0][i + 1] != arr[2][i] - arr[2][i + 1] || arr[1][i] - arr[1][i + 1] != arr[2][i] - arr[2][i + 1])
      ng = 1;
  //   fj(0, 3)
  //     if(arr[i][j] != arr[i + 1][j])
  //       ng = 1;
  // fi(0, 2)
  //   fj(0, 3)
  //     if(arr[j][i] != arr[j][i + 1])
  //       ng = 1;
  if(ng)
    cout << "No\n";
  else
    cout << "Yes\n";
  // cout << ans << endl;
  return 0;
}



Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define IOS ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define pb push_back
#define ff first
#define ss second
#define rep(i,a,n) for(int i=a;i<n;i++)
#define M 1000000007
ll power(ll x, ll y, ll p)
{
    int res = 1;
    x = x % p;
    while (y > 0)
    {   if (y & 1)
        res = (res*x) % p;
        y = y>>1;
        x = (x*x) % p;
    }
    return res;
}
int main()
{
	IOS;
	int n;
	cin>>n;
	int a[n];
	rep(i,0,n)cin>>a[i];
	int count[n];
	memset(count,0,sizeof(count));
	if(n%2==0)
	{
		rep(i,0,n)count[a[i]]++;
		rep(i,0,n)
		{
			if(i%2==0&&count[i]!=0)
			{
				return cout<<0,0;
			}
			else if(i%2!=0&&count[i]!=2)
			{
				return cout<<0,0;
			}
		}
	}
	else
	{
		rep(i,0,n)count[a[i]]++;
		if(count[0]!=1)
		return cout<<0,0;
		rep(i,1,n)
		{
			
			if(i%2!=0&&count[i]!=0)
			{
				return cout<<0,0;
			}
			else if(i%2==0&&count[i]!=2)
			{
				return cout<<0,0;
			}
		}
	}
	cout<<power(2,n/2,M);
}


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

#define rep(i,n) for(i = 0;i < n;++i)
#define all(v) v.begin(), v.end()
using ll = long long;

int main()
{
    ll i,j;
    ll n,x;
    cin >> n >> x;
    if(x == 1 || x == 2*n-1){
        cout << "No" << endl;
        return 0;
    }
    vector<ll> ans(2*n-1,0);
    vector<bool> used(2*n,false);
    if(n == 2){
        if(x == 2){
            cout << "Yes" << endl;
            for(i = 1;i <= 3;++i){
                cout << i << endl;
            }
        }else{
            cout << "No" << endl;
        }
        return 0;
    }
    if(x != 2){
        ans.at(n-2) = x-1;
        used.at(x-1) = true;
        ans.at(n-1) = x;
        used.at(x) = true;
        ans.at(n) = x+1;
        used.at(x+1) = true;
        ans.at(n+1) = x-2;
        used.at(x-2) = true;
        ll now = 1;
        for(i = 0;i < 2*n-1;++i){
            if(!ans.at(i)){
                while(used.at(now)) ++now;
                ans.at(i) = now;
                used.at(now) = true;
            }
        }
        cout << "Yes" << endl;
        for(i = 0;i < 2*n-1;++i){
            cout << ans.at(i) << endl;
        }

    }else{
        ans.at(n-2) = x+1;
        used.at(x+1) = true;
        ans.at(n-1) = x;
        used.at(x) = true;
        ans.at(n) = x-1;
        used.at(x-1) = true;
        ans.at(n+1) = x+2;
        used.at(x+2) = true;
        ll now = 1;
        for(i = 0;i < 2*n-1;++i){
            if(!ans.at(i)){
                while(used.at(now)) ++now;
                ans.at(i) = now;
                used.at(now) = true;
            }
        }
        cout << "Yes" << endl;
        for(i = 0;i < 2*n-1;++i){
            cout << ans.at(i) << endl;
        }
    }

    return 0;
}

Measured memory_bytes: 3072
#include <iostream>
#include<sstream>
#include<string>
#include<vector>
#include <cmath>
#include <limits>
#include <queue>
#include<algorithm>
#include<cstring>
#include <cstdlib>
#include <cstdio>
#include <set>
 
using namespace std;
 
#define rep(i,n) for (int (i)=0;(i)<(n);i++)


int main(){
    string s;
    cin >> s;
    int a,b,c,d;
    a = s[0]-'0';
    b = s[1]-'0';
    c = s[2]-'0';
    d = s[3]-'0';
    if (a+b+c+d == 7){
        cout << a << "+" << b << "+" << c << "+" << d << "=" << 7 << endl;
    }
    else if (a+b+c-d == 7){
        cout << a << "+" << b << "+" << c << "-" << d << "=" << 7 << endl;
    }
    else if (a+b-c+d == 7){
        cout << a << "+" << b << "-" << c << "+" << d << "=" << 7 << endl;
    }
    else if (a-b+c+d == 7){
        cout << a << "-" << b << "+" << c << "+" << d << "=" << 7 << endl;
    }
    else if (a+b-c-d == 7){
        cout << a << "+" << b << "-" << c << "-" << d << "=" << 7 << endl;
    }
    else if (a-b+c-d == 7){
        cout << a << "-" << b << "+" << c << "-" << d << "=" << 7 << endl;
    }
    else if (a-b-c+d == 7){
        cout << a << "-" << b << "-" << c << "+" << d << "=" << 7 << endl;
    }
    else if (a-b-c-d == 7){
        cout << a << "-" << b << "-" << c << "-" << d << "=" << 7 << endl;
    }


    return 0;
}

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

class MainClass
{
    static void Main()
    {
        string s = Console.ReadLine();
        var ep = Console.ReadLine().Split().Select(_=>int.Parse(_)+8000).ToArray();
        
        var dpx = new HashSet<int>();
        var dpy = new HashSet<int>();

        int index = 0;
        int fx = 8000;
        while (index < s.Length && s[index] == 'F')
        {
            fx++;
            index++;
        }
        dpx.Add(fx);
        dpy.Add(8000);

        bool dir = false;

        while (index < s.Length)
        {
            while (index < s.Length && s[index] == 'T')
            {
                dir = !dir;
                index++;
            }

            int dist = 0;
            while (index < s.Length && s[index] == 'F')
            {
                dist++;
                index++;
            }

            if (dir)
            {
                var ny = new HashSet<int>() ;
                foreach (var i in dpy)
                {
                    ny.Add(i - dist);
                    ny.Add(i + dist);
                }
                
                dpy = ny;
            }
            else
            {
                var nx = new HashSet<int>();
                foreach (var i in dpx)
                {
                    nx.Add(i - dist);
                    nx.Add(i + dist);
                }
                dpx = nx;
            }
        }

        Console.WriteLine((dpx.Contains(ep[0]) && dpy.Contains(ep[1])) ? "Yes" : "No");
    }
}


Measured memory_bytes: 47528
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);}
var PriorityQueue=(function(){
  function f(){return new PriorityQueue();}
  function PriorityQueue(){
    this.heap=[];
  }
  PriorityQueue.prototype.push=function(x){
    var h=this.heap,i=h.length++,j;
    while(i){
      j=i-1>>1;
      if(h[j]<=x)break;
      h[i]=h[j],i=j;
    }
    h[i]=x;
  };
  PriorityQueue.prototype.pop=function(){
    var h=this.heap,r=h[0],x=h.pop(),l=h.length;
    if(l===0)return r;
    var i=0,j,k=l-->>1;
    while(i<k){
      j=(i<<1)+1;
      if(j<l&&h[j+1]<h[j])j++;
      if(x<=h[j])break;
      h[i]=h[j],i=j;
    }
    h[i]=x;
    return r;
  };
  return f;
})();

console.log(main());
function main(){
  var n = o.a();
  var m = o.a();
  var a = o.m(n);
  a.push([1e9,0]);
  a.sort((a,b)=>a[0]-b[0]);
  var ans = 0, j = 0;
  var pq = PriorityQueue();
  for(var i = 1; i <= m; i++){
    while(a[j][0] <= i){
      pq.push(-a[j++][1]);
    }
    if(pq.heap.length)ans -= pq.pop();
  }
  return ans;
}

Measured memory_bytes: 66152
from collections import Counter
from collections import deque
from functools import reduce
from operator import mul
from pprint import pprint
import bisect
import copy
import fractions
import itertools
import math
import queue
import random
import sys
import time
sys.setrecursionlimit(10**7)
INF = 10 ** 18
MOD = 10 ** 9 + 7
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def MI(): return map(int, sys.stdin.readline().split())
def II(): return int(sys.stdin.readline())
def IS(): return input()
def C(x): return Counter(x)
def GCD_LIST(numbers): return reduce(fractions.gcd, numbers)
def LCM_LIST(numbers): return reduce(LCM, numbers)
def LCM(m, n): return (m * n // fractions.gcd(m, n))
def COMBINATION(n, r):
    if n < 0 or r < 0 or n < r:
        return 0
    r = min(n-r, r)
    if r == 0:
        return 1
    o = reduce(mul, range(n, n - r, -1))
    u = reduce(mul, range(1, r + 1))
    return o // u
class UnionFind():

    def __init__(self, n):
        self.n = n
        self.node = [i for i in range(n)]
        self.size = [1 for _ in range(n)]

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

    def root(self, x):
        if self.node[x] == x:
            return x
        else:
            self.node[x] = self.root(self.node[x])  # 経路圧縮
            return self.node[x]

    def unite(self, x, y):
        x, y = self.root(x), self.root(y)
        if x == y:
            return  # 結合不要
        if self.size[x] < self.size[y]:
            x, y = y, x
        self.node[y] = x
        self.size[x] += self.size[y]

    def return_size(self, x):
        return self.size[self.root(x)]


s = IS()
right = [0] * len(s)
left = [0] * len(s)
for i in range(len(s)-1):
    if s[i] == 'R':
        if s[i+1] == 'L':
            right[i] += 1
        else:
            right[i+2] += 1
            right[i+2] += right[i]
            right[i] = 0

# print(right)

for i in range(len(s)-1, 0, -1):
    if s[i] == 'L':
        if s[i-1] == 'R':
            left[i] += 1
        else:
            left[i-2] += 1
            left[i-2] += left[i]
            left[i] = 0


# print(left)

ans = [right[i] + left[i] for i in range(len(s))]
print(*ans)


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

int main(){
	string str;
	while(getline(cin,str) && str != "."){
		string c;
		for(int i = 0 ; i < str.size() ; i++)
			if(str[i] == ')' || str[i] == '(' || str[i] == '[' || str[i] == ']')
				c += str[i];
		stack<char> s;
		bool f = true;
		for(int i = 0 ; i < c.length() ; i++){
			if(s.empty() || c[i] == '(' || c[i] == '[')
				s.push(c[i]);
			else if( (s.top() == '(' && c[i] == ')') || (s.top() == '[' && c[i] == ']') ){
				s.pop();
			}else{
				f = false;
				break;
			}
		}
		cout << (f && s.empty() ?"yes":"no") << endl;
	}
}

Measured memory_bytes: 900
require 'set'

class Dictionary

  def initialize
    @values = Set.new
  end

  def insert(value)
    @values << value
  end

  def find(value)
    if @values.include? value
      puts 'yes'
    else
      puts 'no'
    end
  end
end

n = gets.to_i
dictionary = Dictionary.new
n.times do
  input = gets.chomp.split(' ').map(&:to_sym)
  case input[0]
  when :insert
    dictionary.insert input[1]
  when :find
    dictionary.find input[1]
  end
end


Measured memory_bytes: 85520
from collections import Counter

S = input()
N = len(S)

dp = [0] * N
dp[N-1] = int(S[N-1])
times = 10
for i in reversed(range(1, N)):
    dp[i-1] = (dp[i] + times * int(S[i-1])) % 2019
    times *= 10
    times %= 2019

T = Counter(dp)
ans = T[0]
for t in T.values():
    ans += t*(t-1)//2

print(ans)

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

int h, n, ma, ans=1e9, a[1005], b[1005], d[20005];
int main() {
	int i, j;
	cin >> h >> n;
	for(i=0; i<n; i++) {
		cin >> a[i] >> b[i];
		ma = max(ma, a[i]);
	}
	for(i=1; i<=h+ma; i++) {
		d[i] = 1e9;
		for(j=0; j<n; j++) {
			if(i >= a[j]) d[i] = min(d[i], d[i-a[j]] + b[j]);
		}
		if(i>=h) ans = min(ans, d[i]);
	}
	cout << ans;
	return 0;
}

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

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

typedef long long ll;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<long long> VL;
typedef vector<vector<long long>> VVL;
typedef vector<string> VS;
typedef pair<int, int> P;
typedef tuple<int,int,int> tpl;

#define ALL(a)  (a).begin(),(a).end()
#define SORT(c) sort((c).begin(),(c).end())
#define REVERSE(c) reverse((c).begin(),(c).end())
#define LB(a,x) lower_bound((a).begin(), (a).end(), x) - (a).begin()
#define UB(a,x) upper_bound((a).begin(), (a).end(), x) - (a).begin()

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define RFOR(i,a,b) for(int i=(a)-1;i>=(b);--i)
#define RREP(i,n) RFOR(i,n,0)

#define en "\n"

constexpr double EPS = 1e-9;
constexpr double PI  = 3.1415926535897932;
constexpr int INF = 2147483647;
constexpr long long LINF = 1LL<<60;
constexpr long long MOD = 1000000007; // 998244353;

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

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

void Main(){
    VL a(7); REP(i,7) cin >> a[i];
    ll ans = a[1], t = 0;
    for(int i : VI{0,3,4}){
        ans += a[i]/2 * 2;
    }

    ll tmp = a[1];
    if(a[0]&&a[3]&&a[4]){
        a[0]--; a[3]--; a[4]--;
        tmp += 3;
        for(int i : VI{0,3,4}){
            tmp += a[i]/2 * 2;
        }
    }
    chmax(ans, tmp);
    cout << ans << en;
    return;
}

int main(void){
    cin.tie(0);ios_base::sync_with_stdio(0);cout<<fixed<<setprecision(15);
    int t=1; //cin>>t;
    REP(_,t){
        Main();
    }
    return 0;
}

Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main()
{
  int N, H, W;
  cin >> N >> H >> W;
  int r = 0;
  while (N--) {
    int h, w;
    cin >> h >> w;
    if (H <= h && W <= w) r++;
  }
  cout << r << endl;
}

Measured memory_bytes: 256
import java.io.IOException;
import java.io.InputStream;
import java.util.NoSuchElementException;

public class Main {
    private static FastScanner sc = new FastScanner();
    private static boolean DEBUG_FLG = false;

    public static void main(String[] args) {
    	int N = sc.nextInt();
    	int K = sc.nextInt() - 1;
    	char[] S = sc.next().toCharArray();
    	S[K] = (char) (S[K] + 32);
    	System.out.println(S);
    }

    static void debug(long... args) {
    	if(!DEBUG_FLG) return;
    	boolean flg = false;
    	for(long s : args) {
    		if(flg) System.out.print(" ");
    		flg = true;
    		System.out.print(s);
    	}
    	System.out.println();
    }

    static class FastScanner {
        private final InputStream in = System.in;
        private final byte[] buffer = new byte[1024];
        private int ptr = 0;
        private int buflen = 0;
        private boolean hasNextByte() {
            if(ptr < buflen) {
                return true;
            } else {
                ptr = 0;
                try {
                    buflen = in.read(buffer);
                } catch(IOException e) {
                    e.printStackTrace();
                }
                if(buflen <= 0) {
                    return false;
                }
            }
            return true;
        }
        private int readByte() { if (hasNextByte()) return buffer[ptr++]; else return -1;}
        private static boolean isPrintableChar(int c) { return 33 <= c && c <= 126;}
        private void skipUnprintable() { while(hasNextByte() && !isPrintableChar(buffer[ptr])) ptr++;}
        public boolean hasNext() { skipUnprintable(); return hasNextByte();}
        public String next() {
            if (!hasNext()) throw new NoSuchElementException();
            StringBuilder sb = new StringBuilder();
            int b = readByte();
            while(isPrintableChar(b)) {
                sb.appendCodePoint(b);
                b = readByte();
            }
            return sb.toString();
        }
        public long nextLong() {
            return Long.parseLong(next());
        }
        public int nextInt(){
            return Integer.parseInt(next());
        }
        public double nextDouble(){
            return Double.parseDouble(next());
        }
    }
}


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

int main(){
	string b;
	cin >> b;
	if (b == "A"){
		cout << "T" << endl;
	}
	else if (b == "T"){
		cout << "A" << endl;
	}
	else if (b == "C"){
		cout << "G" << endl;
	}
	else{
		cout << "C" << endl;
	}
	return 0;
}

Measured memory_bytes: 256
# -*- coding: utf-8 -*-

red_cards = []
blue_cards = []
N = int(input())
for i in range(N):
    blue_cards.append(input())
M = int(input())
for i in range(M):
    red_cards.append(input())


all_words = set(blue_cards + red_cards)

ans = 0
for i,w in enumerate(all_words):
    cnt_b = cnt_r = 0
    for b in blue_cards:
        if b == w:
            cnt_b += 1
    for r in red_cards:
        if r == w:
            cnt_r+= 1

    diff = cnt_b - cnt_r
    if diff > ans:
        ans = diff

print(ans)

Measured memory_bytes: 9116
#include <iostream>
using namespace std;
long long binaryPowerMethod(long long z,long long n, long long mod){
  long long ans = 1;
  while(n != 0){
    if(n%2){
      ans*=z;
      if(mod)ans%=mod;
    }
    n/=2;
    z*=z;
    if(mod)z%=mod;
  }
  return ans;
}
int main(){
    long long n,m;cin>>n>>m;
    cout << binaryPowerMethod(n,m,1000000007) << endl;
}


Measured memory_bytes: 3100
#include <stdio.h>
char strings[127];
int main() {
	int pin, ein, end, fx, keta;
	int x[2], other[2];
	int i;
	while(scanf("%s", strings) != EOF) {
		fx = 0;
		for(pin = 0; pin < 127 && strings[pin] != '+'; ++ pin);
		for(ein = pin + 1; ein < 127 && strings[ein] != '='; ++ ein);
		for(end = ein + 1; end < 127 && strings[end] != 0; ++ end);
		for(i = 0; i < 3; ++ i) x[i] = other[i] = 0;
		keta = 1;
		for(i = pin - 1; i > -1; -- i) {
			if(strings[i] == 'X') {
				if(i == 0 && i != pin - 1) fx = 1;
				x[0] += keta;
			} else {
				other[0] += (strings[i] - '0') * keta;
			}
			keta *= 10;
		}
		keta = 1;
		for(i = ein - 1; i > pin; -- i) {
			if(strings[i] == 'X') {
				if(i == pin + 1 && i != ein - 1) fx = 1;
				x[0] += keta;
			} else {
				other[0] += (strings[i] - '0') * keta;
			}
			keta *= 10;
		}
		keta = 1;
		for(i = end - 1; i > ein; -- i) {
			if(strings[i] == 'X') {
				if(i == ein + 1 && i != end - 1) fx = 1;
				x[1] += keta;
			} else {
				other[1] += (strings[i] - '0') * keta;
			}
			keta *= 10;
		}
		for(i = fx; i < 10; ++ i) if(other[0] + x[0] * i == other[1] + x[1] * i) break;
		if(i == 10) printf("NA\n");
		else printf("%d\n", i);
	}
	return 0;
}

Measured memory_bytes: 552
import java.util.*;

public class Main{

    public static void main(String args[]){

        Scanner scan = new Scanner(System.in);
        Integer h = scan.nextInt();
        Integer a = scan.nextInt();
        
        if(h%a == 0)
            System.out.println((h/a));
        else
        System.out.println((h/a)+1);
    }

    static int factorial(int n){
        if(n == 0){
          return 1;
        }
        return n * factorial(n-1);
      }
}

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

int main() {
 int n;
  string s;
  cin>>n>>s;
  vector<long long> a(3,0);
  for(int i=0;i<n;i++){
    if(s[i]=='R') a[0]++;
    if(s[i]=='G') a[1]++;
    if(s[i]=='B') a[2]++;
  }
  long long count=0,ans=0;
  for(int i=0;i<n;i++){
    for(int j=1;i+2*j<n;j++){
      if(s[i]!=s[i+j]&&s[i]!=s[i+2*j]&&s[i+j]!=s[i+2*j])  count++; 
    }
  }
  ans=a[0]*a[1]*a[2]-count;
  cout<<ans<<endl;
}

Measured memory_bytes: 3644
#include<iostream>

// ms
const int b1[7] = { 35500, 37500, 40000, 43000, 50000, 55000, 70000 },
		  b2[7] = { 71000, 77000, 83000, 89000, 105000, 116000, 148000 };

const char* cls [7] = { "AAA", "AA", "A", "B", "C", "D", "E" };

int main()
{
	double t1, t2;
	while( std::cin >> t1 >> t2 )
	{
		t1 *= 1000.0, t2 *= 1000.0;

		bool f = false;
		for( int i = 0; i != 7; ++i )
		{
			if( t1 < b1[i] && t2 < b2[i] )
			{
				std::cout << cls[i] << std::endl;
				f = true;
				break;
			}
		}

		if( !f )
			std::cout << "NA" << std::endl;
	}

	return 0;
}

Measured memory_bytes: 1224
#include<stdio.h>
int main(){
  int n , i , s;
  char c;
  int data[4][13];
  for(i = 0 ; i < 4 ; i++){
    for(s = 0 ; s < 13 ; s++){
      data[i][s] = 0;
    }
  }
  scanf("%d\n", &n);
  for(i = 0 ; i < n ; i++){
    scanf("%c%d\n", &c, &s); //S=0 H=1 C=2 D=3
    if(c == 'S'){
      data[0][s-1] = 1;
    }
    else if(c == 'H'){
      data[1][s-1] = 1;
    }
    else if(c == 'C'){
      data[2][s-1] = 1;
    }
    else if(c == 'D'){
      data[3][s-1] = 1;
    }
  }
  for(i = 0 ; i < 4 ; i++){
    for(s = 0 ; s < 13 ; s++){
      if(data[i][s] == 0){
	if(i == 0){
	  printf("S %-d\n", s+1);
	}
	else if(i == 1){
	  printf("H %-d\n", s+1);
	}
	else if(i == 2){
	  printf("C %-d\n", s+1);
	}
	else if(i == 3){
	  printf("D %-d\n", s+1);
	}
      }
    }
  }
}



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

int main()
{	int n;
	cin >> n;
	int x[n];
	for(int i=0;i<n;i++){
		cin >> x[i];
		}
	for(int j=n-1;j>=0;j--){
		if(j!=n-1) cout << " " ;
		cout << x[j];
		}
		cout<<endl;
		
}

Measured memory_bytes: 1160
#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n - 1; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i <= n; i++)
#define FORR(i, m, n) for(int i = m; i >= n; i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define VSORTR(v) sort(v.rbegin(), v.rend());
#define ALL(v) (v).begin(),(v).end()
 
using ll = long long;
using vll = vector<ll>;
using vvll = vector<vector<ll>>;
using P = pair<ll, ll>;

template<typename T> using min_priority_queue = priority_queue<T, vector<T>, greater<T>>;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }

const ll mod = 1e9 + 7;
const ll inf = 1e18;

int main(){
	cin.tie(0);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(10);

    ll n;
    cin >> n;
    vll num(3);
    REP(i, 3) {
        cin >> num[i];
    }
    vector<string> s(n);
    REP(i, n) {
        cin >> s[i];
    }
    vector<string> mem = {"AB", "AC", "BC"};
    ll cur, nxt;
    vector<char> res;
    ll p, q;
    REP(i, n - 1) {
        REP(j, 3) {
            if (s[i] == mem[j]) cur = 2 - j;
            if (s[i + 1] == mem[j]) nxt = 2 - j;
        }
        p = -1, q = -1;
        REP(j, 3) {
            if (j == cur) continue;
            if (p == -1) p = j;
            else q = j;
        }
        // 同時に 0 を引いたら終了
        if (num[p] == 0 && num[q] == 0) {
            cout << "No" << endl;
            return 0;
        }
        // 片方 0 のとき選択肢なし
        if (num[p] == 0) {
            res.push_back(char('A' + p));
            num[p]++;
            num[q]--;
            continue;
        }
        if (num[q] == 0) {
            res.push_back(char('A' + q));
            num[q]++;
            num[p]--;
            continue;
        }
        // 両方 1 以上のとき, 次順引き得る方に足して危機回避
        // cur == nxt ならどうやってもいい
        if (p == nxt) {
            res.push_back(char('A' + q));
            num[q]++;
            num[p]--;
        }
        else {
            res.push_back(char('A' + p));
            num[p]++;
            num[q]--;
        }
    }
    p = -1, q = -1;
    REP(j, 3) {
        if (s[n - 1] == mem[j]) continue;
        if (p == -1) p = 2 - j;
        else q = 2 - j;
    }
    if (num[p] == 0 && num[q] == 0) {
        cout << "No" << endl;
        return 0;
    }
    if (num[p] != 0) res.push_back(char('A' + q));
    else res.push_back(char('A' + p));
    cout << "Yes" << endl;
    REP(i, n) {
        cout << res[i] << endl;
    }
    return 0;
}

Measured memory_bytes: 6676
/* HARDWORK IS THE KEY TO SUCCESS.
   RATING IS TEMPORARY , KNOWLEDGE IS PERMANENT.!!!*/
 
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ld long double
#define T ll t = 1; cin>>t; while(t--)
#define ain ll n,k,i; cin>>n; ll a[n]; for(i=0; i<n; i++) cin>>a[i]
#define matin ll m,n; cin >> n >> m; ll a[n + 1][m + 1]; for(ll i=1;i<=n;i++) for(ll j=1;j<=m;j++) cin>>a[i][j];
#define all(x) (x).begin(), (x).end()
#define F first
#define S second
#define I insert
#define pb push_back
 
const ll maxs = 1e5+3;
const ll maxs1 = 1e3+4;
const ll mod = 1e9 + 7;
inline ll add(ll a, ll b) { return (mod + a + b) % mod;}
inline ll sub(ll a, ll b) {return (a - b + mod) % mod;}
inline ll mul(ll a, ll b) {return (1ll * a * b) % mod;}
ll fastpow(ll x, ll y) {
    ll res = 1; x = x % mod; while (y > 0) { if(y & 1) res = (res * x) % mod; y = y >> 1;x = (x * x) % mod;}return res;}
ll inv(ll x) {
    return fastpow(x, mod - 2);
}
 
 
 
int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    ld a,b;
    cin >> a >> b;
    ld c = a * b;
    ll x = (ll)(c);
    cout << x;
    
 
 //cout << pro;
}

Measured memory_bytes: 3824
#include <cstdio>
#include <iostream>
#include <cmath>
#include <cstring>
#include <sstream>
#include <algorithm>
#include <cstdlib>
#include <map>
#include <queue>
#include <utility>
#include <vector>
#include <set>
#include <memory.h>
#include <iomanip>
#include <bitset>
#include <list>
#include <stack>
#include <deque>
#include <numeric>

using namespace std;

#define mod 1000000007


int n;
vector<vector<int> > graph;
map<pair<int, int>, int> pairToNodeId;

vector<bool> ischecked_dfs(1000001, false);
vector<bool> passed(1000001, false);

bool hasloop_dfs(int now)
{
	for(int i = 0; i < graph[now].size(); i++){
		int next = graph[now][i];
		if(passed[next]) return true;
		if(ischecked_dfs[next]) continue;
		passed[next] = true;
		if(hasloop_dfs(next)) return true;
		passed[next] = false;
	}
	ischecked_dfs[now] = true;
	return false;
}

bool hasloop()
{
	for(int i = 0; i < graph.size(); i++){
		if(ischecked_dfs[i]) continue;
		passed[i] = true;
		if(hasloop_dfs(i)) return true;
		passed[i] = false;
	}
	return false;
}

vector<int> result_dfs(1000001, -1);

int getMaxPath_dfs(int now)
{
	if(result_dfs[now] > 0) return result_dfs[now];
	int ans = 1;
	for(int i = 0; i < graph[now].size(); i++){
		int next = graph[now][i];
		ans = max(ans, getMaxPath_dfs(next) + 1);
	}
	return result_dfs[now] = ans;
}

int getMaxPath()
{
	int ans = 0;
	for(int i = 0; i < graph.size(); i++){
		ans = max(ans, getMaxPath_dfs(i));
	}
	return ans;
}

int getNodeId(int i, int j)
{
	if(j < i) swap(i, j);
	return pairToNodeId[make_pair(i, j)];
}

int main()
{
	cin >> n;
	int cnt = 0;
	for(int i = 1; i <= n; i++){
		for(int j = i + 1; j <= n; j++){
			pairToNodeId[make_pair(i, j)] = cnt;
			cnt++;
		}
	}
	graph = vector<vector<int> >(cnt);
	for(int i = 1; i <= n; i++){
		int pre_a;
		cin >> pre_a;
		for(int j = 1; j < n - 1; j++){
			int a;
			cin >> a;
			// i vs pre_a の試合は i vs a より早く行われる
			graph[getNodeId(i, pre_a)].push_back(getNodeId(i, a));
			pre_a = a;
		}
	}

	if(hasloop()) cout << -1 << endl;
	else cout << getMaxPath() << endl;
}

Measured memory_bytes: 63104
#include <iostream>
#include <string>
#include <algorithm>
#include <functional>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <cstdio>
#include <cmath>
#include <tuple>


using namespace std;

// vector<vector<int>> mat(N, vector<int>(M, 0));


int main(int argc, const char *argv[])
{
  int N;
  cin>>N;

  cout<<N*N*N;

  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
template<typename T>
using ordered_set = tree<T, null_type,less<T>, rb_tree_tag,tree_order_statistics_node_update>;
#define ll long long
#define ff first
#define ss second

ll mod = 1000000007;

ll mulmod(ll a, ll b)
{
    if(b == 0)
        return 0;

    ll x = 0;
    if(b&1)
        x = a;
    ll y = mulmod(a, b/2);

    return ((y+y)%mod + x)%mod;
}

ll BigMod(ll B,ll P,ll M)
{
	ll R=1;
	while(P>0)
	{
		if(P%2==1)
		{
			R=(R*B)%M;
		}
		P/=2;
		B=(B*B)%M;
	}
	return R;
}

ll Extended_Euclidean(ll a,ll b,ll &x,ll &y)
{
    if(b==0)
    {
        x=1;y=0;
        return a;
    }

    ll d;

    d=Extended_Euclidean(b,a%b,y,x);
    y=y-(a/b)*x;

    return d;
}
ll Inverse_Modulo(ll a,ll m)
{
    ll x,y,d;

    d=Extended_Euclidean(a,m,x,y);

    if(d==1)    return (x+m)%m; //Solution Exists
    return -1;  //No Solution
}



ll func(ll r, ll c)
{
    ll i, ret = 0, x = 1;

    ll y = 1;
    for(i = r+c+2; i >= c+2; i--)
        y = (y*i)%mod;

    for(i = 2; i <= r+1; i++)
        x = (x*i)%mod;
//        y = (y*Inverse_Modulo(i, mod))%mod;

//    cout << r << " " << c << " " << y << " " << x << " " << Inverse_Modulo(x, mod) << endl;

    return mulmod(y, Inverse_Modulo(x, mod)) - 1;
}

//void nCr(ll n, ll r)
//{
//    if(r == 0)
//        return 1;
//    if(r == 1)
//        return n%mod;
//    return (nCr(n-1, r-1) + nCr(n-1, r))%mod;
//}


int main()
{
    ll r1, r2, c1, c2, i, ans = 0, x;
    cin >> r1 >> c1 >> r2 >> c2;

    ans = (ans + func(r2, c2))%mod;
    ans = (ans - func(r2, c1-1))%mod;
    ans = (ans - func(r1-1, c2))%mod;
    ans = (ans + func(r1-1, c1-1))%mod;
    ans = (ans + mod)%mod;

    cout << ans;
}


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

using namespace std;
#define pb push_back

typedef long long ll;

int N,M;
int L[200100],R[200100];
int rui[400100];
vector<int> zip;
int main(){
	cin >> N >> M;
	for(int i=0;i<N;i++){
		cin >> L[i] >> R[i];
		zip.pb(L[i]);
		zip.pb(R[i]);
	}
	zip.pb(0);
	zip.pb(M);
	sort(zip.begin(),zip.end());
	zip.erase(unique(zip.begin(),zip.end()),zip.end());
	for(int i=0;i<N;i++){
		L[i] = lower_bound(zip.begin(),zip.end(),L[i])-zip.begin();
		R[i] = lower_bound(zip.begin(),zip.end(),R[i])-zip.begin();
	}
	for(int i=0;i<N;i++){
		rui[L[i]]++;
		rui[R[i]+1]--;
	}
	int mx = 0;
	for(int i=1;i<zip.size();i++){
		rui[i] += rui[i-1];
		mx = max(mx,rui[i]);
	}
	int min_ind = 1000000000;
	int max_ind = -1;
	for(int i=0;i<zip.size();i++){
		if(rui[i]==mx){
			min_ind = min(min_ind,i);
			max_ind = max(max_ind,i);
		}
	}
	ll base = (ll)(mx-1)*(ll)M;
	if(mx%2==0){
		base += M-zip[min_ind];
	}else{
		base += zip[max_ind];
	}
	cout << base << endl;
	return 0;
}



Measured memory_bytes: 7572
#include <stdio.h>
#include <string>
#include <cstring>
#include <stdlib.h>
#include <math.h>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <list>
#include <iterator>
#include <assert.h>
#pragma warning(disable:4996) 
 
typedef long long ll;
#define MIN(a, b) ((a)>(b)? (b): (a))
#define MAX(a, b) ((a)<(b)? (b): (a))
#define LINF 9223300000000000000
#define INF 2140000000
const long long MOD = 1000000007;
//const long long MOD = 998244353;

using namespace std;

char str[2005];

void calc(int n, string& s0, string& s1, vector<int>& v)
{
    int n0 = strlen(s0.c_str());
    int n1 = strlen(s1.c_str());
    int i,j;
    for (i = 0; i <n; i++) {
        int bad = 0;
        for (j = i; j < n0; j++) {
            int k = j - i;
            if (k >= 0 && k < n1) {
                if (s0[j] != '?' && s1[k] != '?' && s0[j] != s1[k]) {
                    bad = 1;
                    break;
                }
            }
        }
        v[i] = (bad ? 0 : 1);
    }

    return;
}

int solve3(int n, string& s0, string& s1, string& s2)
{
    int ans = INF;

    vector<int> v01(n), v12(n), v02(n);
    calc(n, s0, s1, v01);
    calc(n, s1, s2, v12);
    calc(n, s0, s2, v02);

    int len0 = strlen(s0.c_str());
    int len1 = strlen(s1.c_str());
    int i, j;
    for (i = 0; i <= len0+len1; i++) {
        if (v01[i] == 0) continue;
        for (j = 0; j <= len0+len1-i; j++) {
            if (v12[j] == 0) continue;
            if (v02[i + j]) {
                int len0= i + j+strlen(s2.c_str());
                int len1 = i + strlen(s1.c_str());
                int len2 = strlen(s0.c_str());
                int ans0 = MAX(MAX(len0, len1), len2);
                ans=MIN(ans,ans0);
            }
        }
    }
    return ans;
}

void solve()
{
    int i,j;
    string s[3];
    for (i = 0; i < 3; i++) {
        scanf("%s", str);
        s[i]=string(str);
    }
    int n0 = strlen(s[0].c_str());
    int n1 = strlen(s[1].c_str());
    int n2 = strlen(s[2].c_str());
    int n = n0 + n1 + n2+5;

    int ans = INF;
    for (i = 0; i < 3; i++) {
        for (j = 0; j < 3; j++) {
            if (i == j) continue;
            int k = 3 - i - j;

            int ans0 = solve3(n, s[i], s[j], s[k]);
#ifdef _DEBUG
            printf("%s %s %s %d\n", s[i].c_str(), s[j].c_str(), s[k].c_str(), ans0);
#endif
            ans = MIN(ans, ans0);
        }
    }
    printf("%d\n", ans);
    return;
}

int main(int argc, char* argv[])
{
#if 1
    solve();
#else
    int T; scanf("%d", &T);
    while(T--) {
        solve();
    }
#endif
    return 0;
}


Measured memory_bytes: 256
/* cerberus97 - Hanit Banga */

#include <iostream>
#include <iomanip>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <vector>
#include <algorithm>

using namespace std;

#define pb push_back
#define fast_cin() ios_base::sync_with_stdio(false); cin.tie(NULL)

typedef long long ll;
typedef long double ld;
typedef pair <int, int> pii;
typedef pair <ll, ll> pll;

const int K = 1e5 + 10, S = 50, inf = 1e9;

bool seen[K][S];

void dfs(int m, int s, int k, int mx);

int main() {
	fast_cin();
	int k; cin >> k;
	int best = 0, temp = k;
	while (temp) {
		best += temp % 10;
		temp /= 10;
	}
	dfs(0, 0, k, best);
	for (int s = 1; s <= best; ++s) {
		if (seen[0][s]) {
			cout << s << endl;
			break;
		}
	}
}

void dfs(int m, int s, int k, int mx) {
	if (s > mx or seen[m][s]) {
		return;
	}
	seen[m][s] = true;
	for (int d = 0; d < 10; ++d) {
		dfs(((10 * m) + d) % k, s + d, k, mx);
	}
}

Measured memory_bytes: 91904
#include <iostream>
#include <cstdio>
#include <vector>
#include <climits>
using namespace std;

const int WHITE = 0;
const int GRAY = 1;
const int BLACK = 2;

int n;
vector<vector<int>> G;
vector<int> d;
vector<int> p;
vector<int> colors;

void sssp(int s){
    d[s] = 0;
    while(true){
        int cur_min = INT_MAX;
        int min_id = -1;
        for(int i =0;i<n;i++){
            if(colors[i]!=BLACK && d[i] < cur_min){
                min_id = i;
                //printf("%d %d\n",cur_min,d[i]);
                cur_min = d[i];
            }
        }
        if(min_id==-1) break;
        int u = min_id;
        colors[u] = BLACK;
        for(int v = 0;v<n;v++){
            if(colors[v] !=BLACK && G[u][v]!=INT_MAX){
                if(d[u]+G[u][v] < d[v]){
                    d[v] = d[u]+G[u][v];
                    p[v] = u;
                }
            }
        }
    }
    for(int i =0;i<n;i++) printf("%d %d\n",i,d[i]);
}

int main()
{
    //freopen("data.txt","r",stdin);
    cin >> n;
    G.resize(n,vector<int>(n,INT_MAX));
    d.resize(n,INT_MAX);
    p.resize(n,-1);
    colors.resize(n,WHITE);
    for(int i =0;i<n;i++){
        int u,k;
        cin >>u>>k;
        for(int j=0;j<k;j++){
            int v,c;
            cin >> v >>c;
            G[u][v] = c;
        }
    }
    sssp(0);
    //printf("YES\n");
    return 0;
}



Measured memory_bytes: 3264
from functools import reduce
from operator import mul

n = int(input())
a_list = list(map(int, input().split()))

if 0 in a_list:
    print(0)
    exit()

result = 1
for i in range(n):
    result *= a_list[i]
    if result > 10**18:
        print(-1)
        exit()
print(result)

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

int main() {
   
	long long n,i,j,k,ans,count=0,sum=0,d,mx=0,m;
    cin>>n>>m;
    long long a[m],b[n+1]={0},c[n+1]={0};
    string s[m];
    for(i=0;i<m;i++)
    {
        cin>>a[i]>>s[i];
        if(s[i]=="AC")
        b[a[i]]=1;
        if(s[i]=="WA" && b[a[i]]==0)
        {
            c[a[i]]++;
        }
    }
     for(i=0;i<=n;i++)
     {
         if(b[i]==1)
         sum++;
     }
      for(i=0;i<=n;i++)
     {
         if(b[i]==1)
         count+=c[i];
     }
     cout<<sum<<" "<<count;
	return 0;
}

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

typedef long long lglg;
const int INF = 1 << 28;

int main() {
	ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
	
	int n; cin >> n;
	int adj[n][n];
	vector<pair<int,int>> edges;
	for (int i=0; i<n; ++i) {
		string x; cin >> x;
		for (int j=0; j<n; ++j) {
			if (i == j) adj[i][j] = 0;
			else if (x[j] == '1') {
				adj[i][j] = 1;
				if (i < j) edges.push_back({i, j});
			}
			else adj[i][j] = INF;
		}
	}

	for (int k=0; k<n; ++k)
		for (int i=0; i<n; ++i)
			for (int j=0; j<n; ++j)
				adj[i][j] = min(adj[i][j], adj[i][k] + adj[k][j]);
	
	bool failed = false;
	for (int start=0; start<n; ++start) {
		for (pair<int,int> pr : edges) {
			int x, y; tie(x, y) = pr;
			if (adj[start][x] == adj[start][y]) {
				failed = true;
				break;
			}
		}
		if (failed) break;
	}
	if (failed) cout << -1;
	else {
		int best = -1;
		for (int i=0; i<n; ++i) for (int j=0; j<n; ++j) best = max(best, adj[i][j]);
		cout << best+1;
	}
}

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

using namespace std;
typedef long long int ll;
#define debug(val) "[ " << #val " : " << (val) << " ]\n"
#define space " "
#define space " "
#define vi vector<int>
#define PI atan(1)*4
#define pb push_back
#define ff first
#define ss second
#define PI atan(1)*4


void solve() {
	int n , W ; 
	cin >> n >> W ; 
	vector<ll> dp(W+2, 0) ;
	ll res =0;
	for(int i=0;i<n;i++){
		int v , w ; 
		cin >> w >> v ; 
		
		for(int j=W;j>=w;j--){
			dp[j] = max(dp[j] , dp[j-w] + v) ; 
			res = max(dp[j] , res) ; 
		}
	}
	cout << res << endl; 
   
}
int main() {
#ifdef _DEBUG // place in cmake-build-debug folder
    freopen("in.txt", "r", stdin);
    freopen("out.txt", "w", stdout);
#endif
    ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
    int q = 1;
    //cin >> q;
    for (int i = 1; i <= q; i++) {
        // cout << "Case #" << i << ": ";
        solve();
    }
}


Measured memory_bytes: 3992
#include <bits/stdc++.h>
#define all(vec) vec.begin(), vec.end()
#define pb push_back
#define eb emplace_back
#define fi first
#define se second
using namespace std;
using ll = long long;
using P = pair<ll, ll>;
template <class T>
using V = vector<T>;
constexpr ll INF = (1LL << 30) - 1LL;
constexpr ll MOD = 998244353LL;
constexpr int dx[4] = {0, 1, 0, -1}, dy[4] = {1, 0, -1, 0};
template <class T>
void chmin(T &a, T b) { a = min(a, b); }
template <class T>
void chmax(T &a, T b) { a = max(a, b); }
void debug() { cerr << "ok" << endl; }
template <class T>
void printv(const vector<T> &v) {
    for (int i = 0; i < v.size(); i++) cout << v[i] << (i + 1 == v.size() ? '\n' : ' ');
}
template <class T>
void readv(vector<T> &v) {
    for (int i = 0; i < v.size(); i++) cin >> v[i];
}
int main() {
    ios::sync_with_stdio(0);
    cin.tie(0);
    int k;
    cin >> k;
    ll res = 0;
    for (int i = 1; i <= k; i++) {
        for (int j = 1; j <= k; j++) {
            for (int l = 1; l <= k; l++) {
                res += __gcd(i, __gcd(j, l));
            }
        }
    }
    cout << res << '\n';
}

Measured memory_bytes: 3652