akhauriyash/Code-Regression huggingface dataset:
//***********************
//Author:kibi11
//Quarantine Days
//***********************

#include "bits/stdc++.h"
using namespace std;
#define ll long long
#define N 100005
#define MOD 1000000007
#define dd double
#define fr(i, n) for(int i = 0; i < n; i++)
#define fr1(i,a,b) for(int i=a;i<b;i++)
#define frr(i,a,k) for(int i=a;i>=k;i--)
#define same int t;cin>>t;while(t--)
#define check(x) cout << (#x) << " is " << (x) << endl;
#define pb push_back
#define mp make_pair
#define clr(x) x.clear()
#define sz(x) ((int)(x).size())
#define f first
#define s second
#define XOX
#define pi = 3.14159265358979323846

//////////////////////////////////////////////////////////////////////////
/////////////////DEBUGING ZONE//////////////////////////////

vector<string> vec_splitter(string s) {
	s += ',';
	vector<string> res;
	while(!s.empty()) {
		res.push_back(s.substr(0, s.find(',')));
		s = s.substr(s.find(',') + 1);
	}
	return res;
}
void debug_out(
vector<string> __attribute__ ((unused)) args,
__attribute__ ((unused)) int idx, 
__attribute__ ((unused)) int LINE_NUM) { cerr << endl; } 
template <typename Head, typename... Tail>
void debug_out(vector<string> args, int idx, int LINE_NUM, Head H, Tail... T) {
	if(idx > 0) cerr << ", "; else cerr << "Line(" << LINE_NUM << ") ";
	stringstream ss; ss << H;
	cerr << args[idx] << " = " << ss.str();
	debug_out(args, idx + 1, LINE_NUM, T...);
}
#ifdef XOX
#define debug(...) debug_out(vec_splitter(#__VA_ARGS__), 0, __LINE__, __VA_ARGS__)
#else
#define debug(...) 42
#endif
///////////////////////////////////////////////////////////////////////////
 
ll powermod(ll base, ll exp, ll mod) {
	ll result = 1;
	while (exp != 0) {
		if ((exp % 2) == 1) {
			result = (result * base) % mod;
		}
		base = (base * base) % mod;
		exp /= 2;
	}
	return result;
}

///////////////////////////////

// check a cycle in a directed graph: source codeforces;

// void dfs(int v, int p){
//   color[v] = 1; // GREY
//   for(int w : g[v]){
//     if(color[w] == 1){
//       // you found a cycle, it's easy to recover it now.
//     }
//     if(color[w] == 0) dfs(w, v);
//   }
//   color[v] = 2; // BLACK
// }


///////////////////////////////////////////////////////////////////////////
//Fuctions if any:





///////////////////////////////////////////////////////////////////////////
int main() 
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int tt = clock();

int n,x,t;
cin>>n>>x>>t;
cout<<t*(n/x+(n%x!=0))<<endl;
cerr << "TIME = " << (double) 1.0 * (clock() - tt) / CLOCKS_PER_SEC << " seconds" << endl;
return 0;
}

Measured memory_bytes: 3764
class Array
  def lcm
    self.inject{|a,b| a.lcm(b)}
  end

  def gcd
    self.inject{|a,b| a.gcd(b)}
  end
end

ARGF.each do |line|
  a, b = line.split.map(&:to_i)
  gcd = [a, b].gcd
  lcm = [a, b].lcm
  puts "#{gcd} #{lcm}"
end

Measured memory_bytes: 8736
from collections import Counter

N = int(input())
ans = Counter()
for i in range(0, N):
    c = str(input())
    ans[c] += 1
print('AC x {}'.format(ans['AC']))
print('WA x {}'.format(ans['WA']))
print('TLE x {}'.format(ans['TLE']))
print('RE x {}'.format(ans['RE']))


Measured memory_bytes: 9392
#include <bits/stdc++.h>
#include <vector>
#include <string>
#include <stdlib.h>
#include <algorithm>
#include <functional>
 
using namespace std;
 
int main(void) {
    unsigned long int N = 0, K = 0, H[200001], sum = 0;
    cin >> N >> K;
    if(N <= K){
        cout << 0 << endl;
        return 0;
    }
    for(int i = 0 ; i < N ; i++){
        unsigned long int x = 0;
        cin >> H[i];
    }
    sort(H, H + N);
    for(int i = 0 ; i < N - K ; i++){
        sum += H[i];
    }
    cout << sum << endl;
    return 0;
}

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

#define REP(i,s,n) for(int i=s; i<n; ++i)
#define rep(i,n) REP(i,0,n)
#define SORT(c) sort((c).begin(),(c).end())
#define IINF INT_MAX
#define LLINF LLONG_MAX

typedef long long ll;
typedef pair<int, int> ii;

/*
class Node {
public:
  int num;
  int index;
  bool operator<(const Node& b) const {
    if(num < b.num) return (num < b.num);
    else return index > b.index;
  }

  Node(){
    num=0; index=0;
  }
  Node(int n, int i) : num(n), index(i){
  }
};
*/

int main(){

  int n, a, b;
  cin >> n >>a>>b;
  string s;
  cin >> s;

  int cnta = 0, cntb = 0;

  rep(i, s.size()){
    if(s[i] == 'a'){
      if(cnta + cntb < a + b){
        cout << "Yes" <<endl;
        cnta++;
      }
      else cout << "No" <<endl;
    }
    else if(s[i] == 'b'){
      if(cnta + cntb < a + b && cntb < b){
        cout << "Yes" <<endl;
        cntb++;
      }
      else cout << "No" <<endl;
    }
    else cout << "No" <<endl;


  }

  return 0;
}


Measured memory_bytes: 896
#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(void)
{
    int64_t n,i,sa,ans;

    cin >> n;

    ans = 0;

    vector<int64_t> a(n);

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

    for(i=1;i<n;i++){
        if(a[i] < a[i-1]){
            sa = a[i-1] - a[i];
            a[i] += sa;
            ans += sa;
        }
    }

    cout << ans << endl;

}

Measured memory_bytes: 4748
h, w = map(int, input().split())

dx = [0,0,1,-1]
dy = [1,-1,0,0]
s = []
for i in range(h):
	t = input()
	s.append(t)

for i in range(h):
	for j in range(w):
		if s[i][j] == ".":
			continue
		flg = 0
		for k in range(4):
			x = i + dx[k]
			y = j + dy[k]
			if x < 0 or x >= h or y < 0 or y >= w:
				continue
			if s[x][y] == "#":
				flg = 1
				break
		if flg == 0:
			print ("No")
			exit()
print ("Yes")


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

char Solve(const string& s, const int k) {
  for (int i = 0; i < s.size(); ++i) {
    if (i == k - 1)
      return s[i];
    if (s[i] != '1')
      return s[i];
  }
  return '1';
}

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

  cout << Solve(s, k) << "\n";

  return 0;
}


Measured memory_bytes: 256
import java.util.*;
public class Main{
    static Scanner kbd = new Scanner(System.in);
    public static void main(String[] args){
	while(kbd.hasNext()){
	    double a = kbd.nextDouble();
	    double b = kbd.nextDouble();
	    double c = kbd.nextDouble();
	    double d = kbd.nextDouble();
	    double e = kbd.nextDouble();
	    double f = kbd.nextDouble();
	    
	    double x = (e*c-f*b)/(a*e-b*d);
	    double y = (a*f-d*c)/(a*e-b*d);
	    if(x==0) x=0;
	    if(y==0) y=0;

	    System.out.printf("%.3f %.3f\n", x, y);
	}
    }
}

	    

Measured memory_bytes: 18748
#pragma GCC optimize ("Ofast")
#include<bits/stdc++.h>
using namespace std;
inline void rd(int &x){
  int k;
  int m=0;
  x=0;
  for(;;){
    k = getchar_unlocked();
    if(k=='-'){
      m=1;
      break;
    }
    if('0'<=k&&k<='9'){
      x=k-'0';
      break;
    }
  }
  for(;;){
    k = getchar_unlocked();
    if(k<'0'||k>'9'){
      break;
    }
    x=x*10+k-'0';
  }
  if(m){
    x=-x;
  }
}
inline void rd(char &c){
  int i;
  for(;;){
    i = getchar_unlocked();
    if(i!=' '&&i!='\n'&&i!='\r'&&i!='\t'&&i!=EOF){
      break;
    }
  }
  c = i;
}
inline int rd(char c[]){
  int i;
  int sz = 0;
  for(;;){
    i = getchar_unlocked();
    if(i!=' '&&i!='\n'&&i!='\r'&&i!='\t'&&i!=EOF){
      break;
    }
  }
  c[sz++] = i;
  for(;;){
    i = getchar_unlocked();
    if(i==' '||i=='\n'||i=='\r'||i=='\t'||i==EOF){
      break;
    }
    c[sz++] = i;
  }
  c[sz]='\0';
  return sz;
}
inline void wt_L(char a){
  putchar_unlocked(a);
}
inline void wt_L(const char c[]){
  int i=0;
  for(i=0;c[i]!='\0';i++){
    putchar_unlocked(c[i]);
  }
}
template<class T> int arrCountVal(int N, T A[], T val){
  int i;
  int res = 0;
  for(i=(0);i<(N);i++){
    if(A[i]==val){
      res++;
    }
  }
  return res;
}
int H;
int W;
char A[10];
int main(){
  int i;
  int cnt = 0;
  rd(H);
  rd(W);
  for(i=(0);i<(H);i++){
    rd(A);
    cnt += arrCountVal(W, A, '#');
  }
  if(cnt==H+W-1){
    wt_L("Possible");
    wt_L('\n');
  }
  else{
    wt_L("Impossible");
    wt_L('\n');
  }
  return 0;
}
// cLay varsion 20191125-1

// --- original code ---
// int H, W;
// char A[10];
// {
//   int cnt = 0;
//   rd(H,W);
//   rep(i,H) rd(A), cnt += arrCountVal(W, A, '#');
//   wt(if[cnt==H+W-1, "Possible", "Impossible"]);
// }


Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<algorithm>
#include<cctype>
#include<utility>
#include<string>
#include<cmath>
#include<cstring>
#include<queue>
#include<map>
#include<set>

#define REP(i, n) for(int i = 0;i < n;i++)
#define REPR(i, n) for(int i = n;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 llong long long
#define pb(a) push_back(a)

using namespace std;

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


template<typename T>
vector<T> make_v(size_t a) { return vector<T>(a); }
template<typename T, typename... Ts>
auto make_v(size_t a, Ts... ts) {
	return vector<decltype(make_v<T>(ts...))>(a, make_v<T>(ts...));
}
template<typename T, typename V>
typename enable_if<is_class<T>::value == 0>::type
fill_v(T& t, const V& v) { t = v; }
template<typename T, typename V>
typename enable_if<is_class<T>::value != 0>::type
fill_v(T& t, const V& v) {
	for (auto& e : t) fill_v(e, v);
}


#define ARRAY_MAX 100005
const int INF = 1e9 + 7;


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

const int MOD = 1e9 + 7;



//ユークリッド互除法
template<typename T>
T gcd(T x, T y) {

	if (y == 0) {
		return x;
	}
	else {
		return gcd(y, x % y);
	}
}
/*最小公倍数*/
template<typename T>
T lcm(T x, T y) {
	T tmp = gcd(x, y);
	return (x / tmp) * y;
}


/******************************************************************************************/


ll dp[3050][3050];

int main() {

	
	ll n, t, s;
	cin >> n >> t >> s;
	vector<ll> a(n), b(n);
	for (int i = 0; i < n; i++)
	{
		cin >> a[i] >> b[i];
	}

	dp[0][0] = 0;

	for (int i = 0; i < n; i++)
	{
		for (int j = 0; j <= t; j++)
		{

			if (j < s && j + b[i] > s) {
				//花火が見られないケース


				dp[i + 1][j] = max(dp[i + 1][j], dp[i][j]);
			}
			else
			{
				if (j + b[i] <= t) {
					dp[i + 1][j + b[i]] = max(dp[i + 1][j + b[i]], dp[i][j] + a[i]);//遊ぶ場合
				}
				dp[i + 1][j] = max(dp[i + 1][j], dp[i][j]);
			}
		}
	}






	ll maxi = 0;
	for (int i = 0; i <= t; i++)
	{
		maxi = max(maxi, dp[n][i]);
	}

	cout << maxi << endl;

	return 0;
}



Measured memory_bytes: 74640
#include <stdio.h>
int main(void){
    int A;
    int B;
    int T;
    int n=0;
    scanf("%d %d %d",&A,&B,&T);
    for(int t=A;t<T+0.5;t=t+A){
        n=n+B;
    }
    printf("%d\n",n);
    return 0;
}


Measured memory_bytes: 128
#include <cstdio>
#include <cstring>
#include <iostream>
#include <string>
#include <cmath>
#include <bitset>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <algorithm>
#include <complex>
#include <unordered_map>
#include <unordered_set>
#include <random>
#include <cassert>
using namespace std;
typedef long long int ll;
typedef pair<int, int> P;

int main()
{
	int n, k; cin>>n>>k;
	if(n>=2*k-1) cout<<"YES"<<endl;
	else cout<<"NO"<<endl;
	return 0;
}

Measured memory_bytes: 256
import java.util.*;
public class Main {
  public static void main (String[] args) {
    Scanner sc = new Scanner (System.in);
    int N = sc.nextInt();
    ArrayList<Integer> list = new ArrayList<Integer>();
    int K = 0;
    for (int i=0; i<N; i++) {
      int n = sc.nextInt();
      list.add(n);
      K = Math.max(K,n);
    }
    Collections.sort(list);
    int ans = 0;
    
    for (int k=0; k<=K; k++) {
      if (list.get(N/2) >= k && list.get(N/2-1) < k)
        ans++;    
    }
    
    System.out.println(ans);
    
  }
}

Measured memory_bytes: 61284
import java.util.Arrays;
import java.util.Scanner;

public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int N = sc.nextInt();
    int M = sc.nextInt();
    int[] x = new int[M];
    for (int i = 0; i < M; i++) {
      x[i] = sc.nextInt();
    }
    Main abc117C = new Main();
    System.out.println(abc117C.solve(N, x));
  }

  public int solve(int N, int[] x) {
    Arrays.sort(x);
    int[] diffs = new int[x.length - 1];
    for (int i = 0; i < x.length - 1; i++) {
      diffs[i] = x[i + 1] - x[i];
    }
    Arrays.sort(diffs);
    int ans = 0;
    for (int i = 0; i < diffs.length - N + 1; i++) {
      ans += diffs[i];
    }
    return ans;
  }
}


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

int main() {
  
  string s;
  cin >> s;
  
  for ( int i = 0; i < 3; i++){
    if ( s[i] == '1' ){
      s[i] = '9';
    }else if ( s[i] == '9' ){
      s[i] = '1';
    }
  }
  
  cout << s << endl;
  
  
}



Measured memory_bytes: 256
#include <cstdio>
#include <algorithm>

int main()
{
  int a, b, k;
  scanf("%d%d%d", &a, &b, &k);
  
  int i = a;
  for (; i < a + k && i <= b; ++i)
  {
    printf("%d\n", i);
  }
  for (i = std::max(i, b - k + 1); i <= b; ++i)
  {
    printf("%d\n", i);
  }
  return 0;
}

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

using namespace std;

#define debug(n) cerr << #n << ':' << n << endl;
#define dline    cerr << __LINE__ << endl;

using ll = long long;
using ull = unsigned long long;
template<class T, class U> using P = pair<T,U>;
template<class T> using Heap = priority_queue<T>;
template<class T> using heaP = priority_queue<T,vector<T>,greater<T>>;
template<class T,class U> using umap = unordered_map<T,U>;
template<class T> using uset = unordered_set<T>;

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

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

template<class T, size_t N, class U>
void Fill(T (&a)[N], const U&v){
    fill((U*)a,(U*)(a+N),v);
}

template<class T,class U>
istream& operator >> (istream&is, P<T,U>&p){
  is >> p.first >> p.second;
  return is;
}

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

int main(){
  int n; cin >> n;
  vector<int> v(n);
  for(int i = 0; i < n; ++i){
    int bt = 1;
    for(int j = 0; j < 10; ++j){
      int f; cin >> f;
      if(f)v[i] |= bt;
      bt <<= 1;
    }
  }
  int p[100][11] = {};
  for(int i = 0; i < n; ++i)
    for(int j = 0; j < 11; ++j)
      cin >> p[i][j];
  int ans = -1001001001;
  int k = 0;
  for(int i = 1; i < (1<<10); ++i){
    int tmp = 0;
    for(int j = 0; j < n; ++j){
      tmp += p[j][__builtin_popcount(v[j]&i)];     
    }
    if(ChangeMax(ans,tmp))k = i;
  }
  cout << ans << endl;
}



Measured memory_bytes: 3616
N = int(input())
A = list(map(int,input().split()))
B = list((i for i in A if i % 2 == 0))
 
count = 0
 
for i in B:
    if i%3 == 0 or i%5 == 0:
        count += 1
 
if count == len(B):
    print("APPROVED")
else:
    print("DENIED")

Measured memory_bytes: 3060
import itertools
import bisect
n = int(input())
a=sorted(list(map(int, input().split())))
b=sorted(list(map(int, input().split())))
c=sorted(list(map(int, input().split())))
cnt=0

for i in range(0,len(b)):
    a_index = bisect.bisect_left(a,b[i])
    c_index = bisect.bisect_right(c,b[i])
    cnt+=a_index*(len(c)-c_index)
    
print(cnt)

Measured memory_bytes: 107108
/* Suryansh Kumar */
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp> 
#define ll long long int
#define MOD 1000000007
#define oo 1000000000000000000
#define forr(i,n) for(ll i=0;i<n;i++)
#define fastio ios_base::sync_with_stdio(false); cin.tie(0) ; cout.tie(0);
#define all(x) x.begin(),x.end()
#define eb emplace_back
#define pb push_back
#define vect(x) vector<x>
#define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update> 
 
using namespace __gnu_pbds; 
using namespace std;

ll valueOfIndex(ordered_set&s , ll i){ return *(s.find_by_order(i)); }
ll indexOfValue(ordered_set&s , ll x){ return s.order_of_key(x); }

ll add(ll a, ll b,ll p=MOD) { a%=p; b%=p; return (a+b + p)%p;}
ll mul(ll a, ll b,ll p=MOD) { a%=p; b%=p; return (a*b + p)%p;}

ll power(ll x,ll n,ll p=MOD){ if(x==0) return 0; if(n==0 || x==1) return 1LL;
    ll r = (power(x,n/2,p))%p; if(n&1) return mul(mul(r,r,p) , x,p); else return mul(r,r,p);
}

ll dp[3010][3010][2];
ll a[3010];
ll n;
    
ll get(ll s, ll e, ll turn)
{
    if(s>e) return 0;
    
    if(dp[s][e][turn]!=-1) return dp[s][e][turn];
    
    if(turn==0)
        return dp[s][e][turn] = max( a[e] + get(s,e-1,1) , a[s] + get(s+1,e,1));
    else 
        return dp[s][e][turn] = min( get(s,e-1,0) - a[e] ,  get(s+1,e,0) - a[s] );
}
    
    
void solve()
{
    
    cin >> n;
    forr(i,n) cin >> a[i];
    
    memset(dp,-1,sizeof(dp));
    cout << get(0,n-1 ,0) << "\n";

    
    return;
}


int main()
{
    
    
    fastio
    
    ll tc=1;
  //  read(tc);
    while(tc--)
    {
        solve();
    }
    
    return 0;
}

Measured memory_bytes: 141952
//
// Created on 2020/05/10.
//


#include <iostream> // cout, endl, cin
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower
#include <math.h>
#include <ios>
#include <iomanip>
#include <numeric>

#define all(x) (x).begin(),(x).end()
typedef long long ll;
using namespace std;
const long long LINF =1e18;
const int INF = 1e9;



int main() {
    ll ans;
    ll n;
    ll k;
    cin>>n>>k;
    vector<bool>seen(n,false);
    vector<ll>tel(n);
    for (ll i = 0; i < n; ++i) {
        ll temp;
        cin>>temp;
        temp --;
        tel[i] = temp;
    }
    queue<ll>q;
    vector<ll>log;
    q.push(0);
    ll loop_start;
    while(!q.empty()){
        ll now_v = q.front();
        q.pop();

        if(seen[now_v] == true){
            //訪問済み
            ll i = log.size()-1;
            while(log[i] != now_v){
                i --;
            }
            loop_start = i;
            break;
        }
        else{
            log.push_back(now_v);
            seen[now_v] = true;
        }
        q.push(tel[now_v]);
    }

    if(k > loop_start){
        k = k - loop_start;
        ll loop_size = log.size() - loop_start;
        ll amari = k % loop_size;
        ans = log[loop_start + amari];
        ans ++;
    }else{
        ans = log[k];
        ans ++;
    }

    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 6960
#include <bits/stdc++.h>
#include <unistd.h>
 
using namespace std;
 
typedef long long ll;
typedef pair<ll,ll> P;
 
long long int INF = 3e18;
const ll fact_table = 800008;
double Pi = 3.1415926535897932384626;
 
//vector<ll> G[550010];
//vector<P> tree[500010];
priority_queue <ll> pql;
priority_queue <P> pqp;
//big priority queue
priority_queue <ll,vector<ll>,greater<ll> > pqls;
// priority_queue <P,vector<P>,greater<P> > pqps;
//small priority queue
//top pop
 
ll dx[8]={1,0,-1,0,1,1,-1,-1};
ll dy[8]={0,1,0,-1,1,-1,-1,1};
char dir[] = "DRUL";
//ll bit[500005];
//↓,→,↑,←
 
 
#define p(x) cout<<x<<"\n";
#define el cout<<endl;
#define pe(x) cout<<(x)<<" ";
#define ps(x) cout<<fixed<<setprecision(25)<<x<<endl;
#define pu(x) cout<<(x);
#define pb push_back
#define lb lower_bound
#define ub upper_bound
#define CLEAR(a) a = decltype(a)(); 
 
 
//ll mod = 998244353;
ll mod = 1000000007;
 
ll rui(ll number1,ll number2){
 
    if(number2 == 0){
        return 1;
    }else{
        ll number3 = rui(number1,number2 / 2);
        number3 *= number3;
        number3 %= mod;
        if(number2%2==1){
            number3 *= number1;
            number3 %= mod;
        }
        return number3;
    }
}
ll gcd(ll number1,ll number2){
 
    if(number1 > number2){
        swap(number1,number2);
    }
    if(number1 == 0 || number1 == number2){
        return number2;
    }else{
        return gcd(number2 % number1,number1);
    }
}
void YES(bool condition){
 
    if(condition){
        p("YES");
    }else{
        p("NO");
    }
    return;
}
void Yes(bool condition){
 
    if(condition){
        p("Yes");
    }else{
        p("No");
    }
    return;
}
 
/*
ll fact[fact_table + 5],rfact[fact_table + 5];
 
void c3_init(){
    fact[0] = rfact[0] = 1;
    for(ll i=1; i<=fact_table; i++){
        fact[i] = (fact[i-1]*i) % mod;
    }
    rfact[fact_table] = rui(fact[fact_table],mod - 2);
    for(ll i=fact_table; i>=1; i--){
       rfact[i-1] = rfact[i] * i;
       rfact[i-1] %= mod;
    }
    return;}
ll c3(ll n,ll r){
    return (((fact[n] * rfact[r]) % mod ) * rfact[n-r]) % mod;}
*/
 
ll n,m,num,sum,a,b,c,d,e,g,h,w, i,j,q,r,l;
ll k;
ll ans;
ll x[500005], y[200005], z[200005];
char s[500005], t[500005];
bool used[3005][3004];


int main(){
    /*
    cin.tie(0);
    ios::sync_with_stdio(false);
    */
    cin >> h >> w >> n;
    ll ans1 = (n - 1) / h + 1;
    ll ans2 = (n - 1) / w + 1;
    p(min(ans1, ans2));

    return 0;
}
 
 











Measured memory_bytes: 256
#include<stdio.h>
int a[101][101];
int main()
{
	int h, w;
	int n;
	int tmp;
	scanf("%d %d", &h, &w);
	scanf("%d", &n);
	int j = 1, k = 1;
	int flag = 1;
	for (int i = 1; i <= n; i++)
	{
		scanf("%d", &tmp);
		while (tmp > 0)
		{
			for (j; j <= h;)
			{
				if (flag)
				{
					for (k; k <= w && tmp; k++)
					{
						a[j][k] = i;
						tmp--;
					}
					if (k == w + 1)
					{
						k = w;
						flag = 0;
						j++;
					}
				}
				if (!flag)
				{
					for (k; k >= 1 && tmp; k--)
					{
						a[j][k] = i;
						tmp--;
					}
					if (k == 0)
					{
						k = 1;
						flag = 1;
						j++;
					}
				}
				if (!tmp) break;
			}
		}
	}
	for (int i = 1; i <= h; i++)
	{
		for (int j = 1; j <= w; j++)
			printf("%d ", a[i][j]);
		printf("\n");
	}
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <string>
#include <vector>
#include <queue>
#include <algorithm>
#include <utility>
#include <cmath>
#include <map>
#include <set>
#include <stack>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cassert>
#include <cctype>
#include <complex>
using namespace std;

#define INF_LL (ll)1e18
#define INF (int)1e9
#define REP(i, n) for(int i = 0;i < (n);i++)
#define FOR(i, a, b) for(int i = (a);i < (b);i++)
#define all(x) x.begin(),x.end()
#define fs first
#define sc second
using ll = long long;
using PII = pair<int, int>;
using PLL = pair<ll, ll>;

const double eps = 1e-10;

template<typename A, typename B>inline void chmin(A &a, B b){if(a > b) a = b;}
template<typename A, typename B>inline void chmax(A &a, B b){if(a < b) a = b;}

int main(void){
	cin.tie(0);
	ios::sync_with_stdio(false);
	ll X, Y;
	cin >> X >> Y;
	if(X%Y == 0){
		cout << -1 << endl;
		return 0;
	}else{
		cout << X << endl;
		return 0;
	}
	
}


Measured memory_bytes: 256
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <cmath>
#include <ctime>
#include <vector>
#include <cstdio>
#include <string>
#include <iomanip>
#include <cstring>
#include <iostream>
#include <algorithm>
using namespace std;

int main()
{
    long long K, res=7, ans =1;
  	cin >> K;
      int flag = 0;
	for(long long i = 0; i <= K; i++){
		if( res % K == 0){

			cout << ans << endl;
            flag = 1;
            break;
		}
		else{
			res =( (res * 10) + 7) % K;
		}
		ans ++;
	}
    if(flag == 0)
	cout << "-1" << endl;
  return 0;
}

Measured memory_bytes: 3636
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <stdio.h>
#include <string.h>
using namespace std;

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

    string s, t;
    int q;
    cin >> s >> t >> q;

    vector<int> sm(s.size() + 1), tm(t.size() + 1);
    for (int i = 1; i <= s.size(); i++) {
        sm[i] = sm[i - 1] + (s[i - 1] == 'A' ? 1 : 2);
        if (sm[i] >= 3) sm[i] -= 3;
    }
    for (int i = 1; i <= t.size(); i++) {
        tm[i] = tm[i - 1] + (t[i - 1] == 'A' ? 1 : 2);
        if (tm[i] >= 3) tm[i] -= 3;
    }

    for (int i = 0; i < q; i++) {
        int a, b, c, d;
        cin >> a >> b >> c >> d;
        a--; b--; c--; d--;
        cout << (((sm[b + 1] - sm[a] + 3) % 3 == (tm[d + 1] - tm[c] + 3) % 3) ? "YES" : "NO") << '\n';
    }

    return 0;
}

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

using namespace std;

int town[100005], hero[100005];
int main() {
#ifndef ONLINE_JUDGE
//	freopen("input.in", "r", stdin);
//	freopen("output.out", "w", stdout);
#endif
    int n;
    scanf("%d", &n);
    for(int i=0; i<n+1; i++)
        scanf("%d", town + i);
    long long res = 0;
    for(int i=0; i<n; i++){
        scanf("%d", hero + i);

        if(hero[i] >= town[i]){
            res += town[i];
            hero[i] -= town[i];
        }else{
            res += hero[i];
            hero[i] = 0;
        }

        if(hero[i] >= town[i+1]){
            res += town[i+1];
            town[i+1] = 0;
        }else{
            res += hero[i];
            town[i+1] -= hero[i];
        }
    }
    printf("%lld\n", res);
    return 0;
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
#include <boost/range/algorithm.hpp>
#include <boost/range/numeric.hpp>
#include <boost/integer/common_factor.hpp>
#include <boost/integer/common_factor_rt.hpp>
#include <boost/multiprecision/cpp_dec_float.hpp>
#include <boost/multiprecision/cpp_int.hpp>

using std::string;
using std::vector;
using std::set;
using std::multiset;
using std::unordered_set;
using std::map;
using std::multimap;
using std::unordered_map;
using std::pair;
using std::cin;
using std::cout;

using boost::multiprecision::cpp_int;
using cpp_dec_float_1000 = boost::multiprecision::number<boost::multiprecision::cpp_dec_float<1000>>;

typedef uintmax_t    ull;
typedef intmax_t     ll;
typedef uint64_t     ul;
typedef uint32_t     ui;
typedef uint8_t      uc;

constexpr char CRLF  = '\n';
constexpr char SPACE = ' ';
constexpr char VECTOR_COUT_SEPARATOR = SPACE;
constexpr ll INF = 1000'000'007;
constexpr int MOD = 1000'000'007;

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; }
template<class T> std::ostream& operator<< (std::ostream& os, const std::vector<T>& vc) { for(auto it = vc.begin(); it != vc.end(); ++it) { if (std::next(it) == vc.end()) os << *it; else os << *it << VECTOR_COUT_SEPARATOR; } return os; }
template<class T1, class T2> inline std::ostream & operator<< (std::ostream & os, const std::pair<T1, T2> & p) { return os << p.first << ' ' << p.second; }
template<class T> T modinv(T a, T m) { T b = m, u = 1, v = 0; while (b) { T t = a / b; a -= t * b; boost::swap(a, b); u -= t * v; boost::swap(u, v); } u %= m; if (u < 0) u += m; return u; }
template<class T> inline bool isSosuu(const T& n) { if (n == T(1)) { return false; } for (T i = 2; i*i <= n; ++i) { if (n % i == 0) { return false; } } return true; }
template<class T> vector<vector<T>> split (const vector<T>& S, T delim) { vector<vector<T>> ret{}; vector<T> buff{}; for (auto c : S) { if (c == delim) { if (!buff.empty()) ret.push_back(buff); buff.clear(); } else { buff.push_back(c); } } if (!buff.empty()) ret.push_back(buff); return ret; }

struct Tmp
{
public:
  Tmp(int N);
};

Tmp::Tmp(int N){}

void solve(void)
{
  int a, b, c, d; cin >> a >> b >> c >> d;
  auto l = a+b;
  auto r = c+d;
  auto ans = (l == r)
    ? "Balanced"
    : (l > r)
      ? "Left"
      : "Right";
  cout << ans << CRLF;
  return;
}

int main(void)
{
  std::ios_base::sync_with_stdio(false);
  std::cin.tie(0);

  solve();

  return 0;
}


Measured memory_bytes: 384
program main
  implicit none
  
  integer :: a,b,k,i,out(100)=0,c=0,chk=0,j
  
  read(*,*)a,b,k
  if ((b-a) <= k) then
    do i = a, b
      write(*,*)i
    end do
    stop
  end if
  
  do i = a, a+k-1
    c = c + 1
    write(*,*)i
    out(c) = i
  end do
  
  do i = b-k+1, b
    chk = 0
    do j = 1, c
      if (out(c) == i) then
        chk = 1
      end if
    end do
    if (chk == 1) then
      cycle
    else
      write(*,*)i
    end if
  end do
end program main

Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vll = vector<ll>;
using vvll = vector<vll>;
using vc = vector<char>;
using vvc = vector<vc>;
using pll = pair<ll, ll>;
using vpll = vector<pll>;
const ll INF = 1LL << 60;
const ll MOD = 1e9 + 7;
#define rep(i, n) for (ll i = 0; i < (n); i++)
#define debug(x) cerr << #x << ": " << x << endl;
template<typename T1,typename T2> inline void chmin(T1 &a,T2 b){if(a>b) a=b;}
template<typename T1,typename T2> inline void chmax(T1 &a,T2 b){if(a<b) a=b;}

int main() {
    ll a, b, c, d;
    cin >> a >> b >> c >> d;
    if((c+b-1)/b <= (a+d-1)/d) cout << "Yes" << endl;
    else cout << "No" << endl;
}


Measured memory_bytes: 3580
#include <bits/stdc++.h>
#define all(v) (v).begin(),(v).end()
using namespace std;

int primes[1000001];


void seive(){
    for(int i=2;i<=1000000;++i){
        if(primes[i]==0){
            for(int j=i;j<=1000000;j+=i){
                if(primes[j] == 0)
                    primes[j] = i;
            }
        }
    }
}

long long int getDiv(int n){
    if(n == 1) return 1;
    map<int,int> m;
    int temp1 = n;
    while(n!=1){
        int val = primes[n];
        n = n/val;
        m[val]++;
    }
    long long int temp = 1;
    for(auto &p : m){
        temp *= ((long long int)p.second+1);
    }
    return temp;
}


int main(){
    ios_base::sync_with_stdio(false); cin.tie(NULL);
    seive();
    int n; cin >> n;
    long long int count = 0;
    for(int i=1;i<n;++i){
        count += getDiv(i);
    }
    cout << count << '\n';
    return 0;
}

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

#define ll long long
#define fornum(A,B,C) for(A=B;A<C;++A)
#define pii pair<int,int>
#define pll pair<ll,ll>

using namespace std;

/////////////////////////////////////////////////////

ll N, K;
ll V[1 << 19], W[1 << 19];
ll Q;
ll v[1 << 19], L[1 << 19];
ll dp[(1 << 9) + 10][101010];


ll i, j, k;

void dpcalc(ll a){
    if(a>N||a>=(1<<9)){
        return;
    }
    ll i = 0;
    auto &dpp = dp[a / 2];
    auto &dpa = dp[a];
    //printf("\n%lld: ", a);
    fornum(i,1,100010){
        dpa[i] = max(dpp[i], dpa[i - 1]);
        if(i>=W[a])
          dpa[i] = max(dpa[i], dpp[i - W[a]] + V[a]);
        //if(i<=10)
        //printf("%lld,%lld ", i, dpa[i]);
    }
    dpcalc(a * 2);
    dpcalc(a * 2 + 1);
}

ll qcalc(ll v,ll L){
    if(v<(1<<9)){
        return dp[v][L];
    }
    ll r = qcalc(v / 2, L);
    if(L>=W[v])
        r = max(r, qcalc(v / 2, L - W[v]) + V[v]);
    return r;
}

void query(){
    ll v, L;
    scanf("%lld%lld", &v, &L);
    printf("%lld\n", qcalc(v, L));
}

int main(){
    scanf("%lld", &N);
    fornum(i,0,N){
        scanf("%lld%lld", &V[i+1],&W[i+1]);
    }
    dpcalc(1);
    scanf("%lld", &Q);
    while(Q--){
        query();
    }
    return 0;
}

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

int main(){
  int A[N];
  int n,flag,i,j,x,c;
   
  scanf("%d", &n);
  for(j = 0 ; j < n ; j++) scanf("%d", &A[j]);
  
  flag = 1;
  i = 0;
  c = 0;
  
  while(flag){
    flag = 0;
    for(j = n-1 ; j >= i+1 ; j--){
      if(A[j] < A[j-1]){
	x = A[j];
	A[j] = A[j-1];
	A[j-1] = x;
	flag = 1;
	c++;
      }      
    }
    i++;
    
  }
  for(j = 0 ; j < n-1 ; j++) printf("%d ",A[j]);
  printf("%d",A[n-1]);
  printf("\n%d\n",c);
  
  return 0;
}



Measured memory_bytes: 2128
#include <bits/stdc++.h>
using namespace std;
int main() {
    string s;
    cin>>s;
    int u = 0;
    int l = 0;
    int d = 0;
    int r = 0;
    for(int i = 0; i < s.size(); ++i) {
        if(s[i] == 'N') u = 1;
        if(s[i] == 'W') l = 1;
        if(s[i] == 'S') d = 1;
        if(s[i] == 'E') r = 1;
    }
    if(u != d || l != r) {
        cout<<"No\n";
        return 0;
    }
    cout<<"Yes\n";
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        String S = sc.next();
        
        switch (S) {
            case "Sunny":
                System.out.println("Cloudy");
                break;
            case "Cloudy":
                System.out.println("Rainy");
                break;
            case "Rainy":
                System.out.println("Sunny");
                break;
        }
    }
}

Measured memory_bytes: 20692
import sys

sys.setrecursionlimit(10 ** 7)
f_inf = float('inf')
mod = 10 ** 9 + 7


def resolve():
    x = int(input())

    cnt = 0
    v = 100
    while v < x:
        v = int(v + v * 0.01)
        cnt += 1

    print(cnt)


if __name__ == '__main__':
    resolve()


Measured memory_bytes: 9128
#include <iostream>
#include <algorithm>
#include <vector>
using namespace std; 
typedef long long ll;
int n;
int main(){
    cin >> n;
    vector<ll> a(n);
    for(int i=0; i<n; i++) cin >> a[i];
    sort(a.begin(), a.end(), greater<ll>());
    ll ans=0;
    for(int i=0; i<n-1; i++){
        if(i==0){ans+=a[0]; continue;}
        int a_index=i/2+i%2;
        ans += a[a_index];  
    }
    cout << ans << "\n";
}

Measured memory_bytes: 4776
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int H = sc.nextInt();
		int W = sc.nextInt();
		String[]C = new String[H];
		for(int i = 0; i < H; i++) {
			C[i] = sc.next();
		}
		sc.close();
		for(int i = 0; i < H; i++) {
			if(C[i].length() == W) {
				System.out.println(C[i]);
				System.out.println(C[i]);
			}
		}
	}
}

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

using namespace std;

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

    vector<int> vec(n);

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

    reverse(vec.begin(), vec.end());

    for (int i = 0; i < n; i++)
    {
        cout << vec[i];

        if (i + 1 == n)
            break;

        cout << " ";
    }
    cout << endl;
}


Measured memory_bytes: 3112
N = gets.to_i
H = gets.split.map(&:to_i)

dp = Array.new(N + 1, Float::INFINITY)
dp[1] = 0

H.unshift(Float::INFINITY)

1.upto(N - 1) do |i|
  if i + 1 <= N
    dp[i + 1] = [dp[i + 1], dp[i] + (H[i + 1] - H[i]).abs].min
  end

  if i + 2 <= N
    dp[i + 2] = [dp[i + 2], dp[i] + (H[i + 2] - H[i]).abs].min
  end
end

puts dp[N]


Measured memory_bytes: 11788
#include<cstdio>
int main(){
  char s[105];
  int sum,i,a[105];
  while(scanf("%s",s)!=EOF){
    sum = 0;
    for(i=0;s[i]!='\0';i++){
      if(s[i] == 'M') a[i] = 1000;
      if(s[i] == 'D') a[i] = 500;
      if(s[i] == 'C') a[i] = 100;
      if(s[i] == 'L') a[i] = 50;
      if(s[i] == 'X') a[i] = 10;
      if(s[i] == 'V') a[i] = 5;
      if(s[i] == 'I') a[i] = 1;
      if(i>0) sum += a[i-1]<a[i]?-a[i-1]:a[i-1];
    }
    printf("%d\n",sum+a[i-1]);
  }
  return(0);
}



Measured memory_bytes: 2668
#include <stdio.h>
int main(void){
    char p[4], a[4];
    int cnt = 0;

    scanf("%s%s", &p, &a);


    //scanf("%s%s%s", &p[0], &p[1], &p[2]);
    //scanf("%s%s%s", &p[0], &p[1], &p[2]);
for (int i = 0; i < 3; i++){
    if (p[i] == a[i]){
        cnt++;
    }
}
printf("%d", cnt);
}




Measured memory_bytes: 128
/*
ABHIJEET BISWAS
CSE 4th SEM 
MNNIT ALLAHBAD
https://atcoder.jp/contests/dp/tasks/dp_i
USING 1D DP

*/

#include <bits/stdc++.h>
using namespace std;
#define MOD 1000000007
#define INF 1e18
#define ll long long
#define ld long double
#define pii pair<int,int>
#define pli pair<long long,int>
#define pll pair<long long,long long>
#define MAX 1000009
#define pb push_back
#define mp map<int,int>
#define f first
#define s second
#define fastIO ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
ld pi=2.0*acos(0.0);
double dp[3000];
double arr[3000];
int main() {
	fastIO
	int n;
	cin>>n;
	for(int i=1;i<=n;i++)
	cin>>arr[i];
	dp[0]=1;
	
	for(int i=1;i<=n;i++)
	{
		
		dp[i]=arr[i]*dp[i-1];
		for(int j=i-1;j>=1;j--)
		dp[j]=(dp[j]*(1-arr[i])+dp[j-1]*arr[i]);
		dp[0]=dp[0]*(1-arr[i]);
	}
	double ans=0;
	for(int i=n/2 +1;i<=n;i++)
	ans+=dp[i];
	cout<<setprecision(9)<<ans<<endl;
	return 0;
}

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

int main(){
	
	int n;
	double a;
	int b[6]={0};
	cin>>n;
	for(int i=0;i<n;i++){
		cin>>a;
	if(a<165.0)
		b[0]++;
	else if(a<170.0)
		b[1]++;
	else if(a<175.0)
		b[2]++;
	else if(a<180.0)
		b[3]++;
	else if(a<185.0)
		b[4]++;
	else
		b[5]++;
	}
	for(int i=0;i<6;i++){
		cout<<i+1<<":";
	for(int j=0;j<b[i];j++)
		cout<<'*';
		cout<<endl;
	}
	
}

Measured memory_bytes: 1232
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i,n) for (ll i=0; i<(ll)(n); i++)
#define repd(i,n) for (ll i=n-1; i>=0; i--)
#define all(x) (x).begin(), (x).end()
#define F first
#define S second
#define PF push_front
#define PB push_back
#define setprecision sp

int main()
{
    int A,B,C;
    cin >> A >> B >> C;
    swap(A,B);
    swap(A,C);
    cout << A << " " << B  << " " << C << endl; 
}

Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Arrays;
import java.util.stream.IntStream;

public class Main {

    static int h, w;

    public static void main(String[] args) throws NumberFormatException, IOException{
        try(BufferedReader br = new BufferedReader(new InputStreamReader(System.in))) {
            while (true) {

                int[] arr = Arrays.stream(br.readLine().split(" ")).mapToInt(Integer::parseInt).toArray();

                h = arr[0];
                w = arr[1];

                if (h == 0 && w == 0) {
                    break;
                }

                IntStream.rangeClosed(1, h).forEach(i -> {
                    if (i % 2 == 0) {
                        System.out.println(getEvenLineString(w, new StringBuilder()));
                    } else {
                        System.out.println(getOddLineString(w, new StringBuilder()));
                    }
                });

                System.out.println();
            }
        }
    }

    public static String getOddLineString(int n, StringBuilder sb) {

        if(sb.length() % 2 == 0) {
            sb.append("#");
        }else {
            sb.append(".");
        }

        if(n == 1) {
            return sb.toString();
        }else {
            return getOddLineString(n - 1, sb);
        }
    }

    public static String getEvenLineString(int n, StringBuilder sb) {
        if(sb.length() % 2 == 1) {
            sb.append("#");
        }else {
            sb.append(".");
        }

        if(n == 1) {
            return sb.toString();
        }else {
            return getEvenLineString(n - 1, sb);
        }
    }
}


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

#define inf 9023372036854775807

using namespace std;

map <long long, map <long long, long long>> a;

signed main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);

    long long h, w, n;
    cin >> h >> w >> n;

    pair <long long, long long> p[n];

    for (long long i = 0; i < n; ++i) {
        long long x, y;
        cin >> x >> y;
        p[i].first = x;
        p[i].second = y;
        a[x][y] = 1;
    }

    long long ans = h, x = 1, y = 1, cn[max(w, h) + 10];
    for (auto &i : cn) {
        i = inf;
    }


    while (x <= h && y <= w) {
        cn[y] = min(cn[y], x);
        if (a[x + 1][y]) {
            ans = x;
            break;
        }
        ++x;
        if (!a[x][y + 1]) {
            ++y;
        }
        if (x > h || y > w) {
            break;
        }
        cn[y] = min(cn[y], x);
    }


    sort(p, p + n);


    for (long long i = 0; i < n; ++i) {
        if (p[i].first > cn[p[i].second]) {
            ans = min(ans, p[i].first - 1);
        }
    }

    cout << ans << '\n';



    return 0;
}

Measured memory_bytes: 56832
use proconio::fastout;
use proconio::input;
#[allow(unused_imports)]
use proconio::marker::*;

#[fastout]
fn main() {
    input! {
        k: usize,
        s: String,
    }
    let ans = if s.len() <= k {
        s
    } else {
        let t = s[..k].to_string() + "...";
        t
    };
    println!("{}", ans);
}


Measured memory_bytes: 2168
#include <cstdio>
#include <algorithm>
long long INF = 100000000;

using namespace std;

void warshall_floyd (int c[10][10], int dist[10][10]) {
  int i, j, k;
  for (k = 0; k < 10; k++) {
    for (i = 0; i < 10; i++) {
      for (j = 0; j < 10; j++) {
	dist[i][j] = min(dist[i][j], dist[i][k]+dist[k][j]);
      }
    }
  }
}

int main() {
  int H, W;
  int i, j;
  int c[10][10];
  int dist[10][10];
  scanf("%d %d", &H, &W);
  for (i = 0; i < 10; i++) {
    for (j = 0; j < 10; j++) {
      scanf("%d", &c[i][j]);
      dist[i][j] = c[i][j];
      //printf("%d ", dist[i][j]);
    }
    //printf("\n");
  }
  warshall_floyd(c, dist);
  //for (i = 0; i < 10; i++) {
  //  for (j = 0; j < 10; j++) {
  //   printf("%d ", dist[i][j]);
  //  }
  //  printf("\n");
  //}
  int ans = 0;
  int aij;
  for (i = 0; i < H; i++) {
    for (j = 0; j < W; j++) {
      scanf("%d", &aij);
      if (aij == -1) {
	continue;
      }
      ans += dist[aij][1];
    }
  }
  printf("%d", ans);   
  return 0;
}

Measured memory_bytes: 128
from itertools import product

n, m = map(int, input().split())
ks = [list(map(int, input().split())) for _ in range(m)]
p = list(map(int, input().split()))

cnt = 0
for pat in product([0, 1], repeat=n):
    for i in range(m):
        if sum(pat[ks[i][j + 1] - 1] for j in range(ks[i][0])) % 2 != p[i]:
            break
    else:
        cnt += 1

print(cnt)


Measured memory_bytes: 42480
using System;
using System.Text;
using System.Linq;
using System.Collections;
using System.Collections.Generic;
using static System.Console;
using static System.Math;

namespace AtCoder
{
    public class Program
    {
        public static void Main(string[] args)
        {
            new Program().Solve(new ConsoleInput(Console.In, ' '));
        }

        public void Solve(ConsoleInput cin)
        {

            double N = cin.ReadDouble;
            double newN = Math.Sqrt(N);
            int[] array = new int[10050];
            for (int i =0; i < 10050; i++) {
                array[i] = 0;
            }

            int n = 1;
                int counter = 0;
                for (int x = 1; x < newN; x++)
                {
                    for (int y = 1; y < newN; y++)
                    {
                        for (int z = 1; z < newN; z++)
                        {

                        int v = x * x + y * y + z * z + x * y + y * z + z * x;
                        if (v < 10050) {
                            array[v] += 1;
                        }
                    }
                    }
                }

            for (int i =0; i < N; i++) {
                WriteLine(array[i + 1]);
            }
    }
    }

    public class ConsoleInput
    {
        private readonly System.IO.TextReader _stream;
        private char _separator = ' ';
        private Queue<string> inputStream;
        public ConsoleInput(System.IO.TextReader stream, char separator = ' ')
        {
            this._separator = separator;
            this._stream = stream;
            inputStream = new Queue<string>();
        }
        public string Read
        {
            get
            {
                if (inputStream.Count != 0) return inputStream.Dequeue();
                string[] tmp = _stream.ReadLine().Split(_separator);
                for (int i = 0; i < tmp.Length; ++i)
                    inputStream.Enqueue(tmp[i]);
                return inputStream.Dequeue();
            }
        }
        public string ReadLine { get { return _stream.ReadLine(); } }
        public int ReadInt { get { return int.Parse(Read); } }
        public long ReadLong { get { return long.Parse(Read); } }
        public double ReadDouble { get { return double.Parse(Read); } }
        public string[] ReadStrArray(long N) { var ret = new string[N]; for (long i = 0; i < N; ++i) ret[i] = Read; return ret; }
        public int[] ReadIntArray(long N) { var ret = new int[N]; for (long i = 0; i < N; ++i) ret[i] = ReadInt; return ret; }
        public long[] ReadLongArray(long N) { var ret = new long[N]; for (long i = 0; i < N; ++i) ret[i] = ReadLong; return ret; }
    }
}

Measured memory_bytes: 27732
if __name__ == '__main__':
    N = int(input())
    ac = 0
    wa = 0
    tle = 0
    re = 0

    for i in range(N):
        S = input()
        if S == "AC":
            ac += 1
        elif S == "WA":
            wa += 1
        elif S == "TLE":
            tle += 1
        elif S == "RE":
            re += 1
    print("AC x", ac)
    print("WA x", wa)
    print("TLE x", tle)
    print("RE x", re)

Measured memory_bytes: 9200
import sys
import socket

hostname = socket.gethostname()

if hostname == 'F451C':
    sys.stdin = open('d1.in')


def read_int_list():
    return list(map(int, input().split()))


def read_str_list():
    return input().split()


def read_int():
    return int(input())


def read_str():
    return input()


def main():
    M = 10 ** 9 + 7
    N, K = read_int_list()
    res = 0
    for i in range(K, N + 2):
      d = (i - 1) * i // 2
      f = i * N - d
      res += f - d + 1
      res = res % M
    print(res)


main()


Measured memory_bytes: 9880
/** 
If comrades that you trust gather around you, hope can take physical form and become visible. That’s what I believe.
*/
#include <bits/stdc++.h>
using namespace std;
/**
(▀̿Ĺ̯▀̿ ̿) (ง ͠° ͟ل͜ ͡°)ง
*/
auto main() -> int {
	ios_base::sync_with_stdio(false); cin.tie(0);
    int k, a, b; cin >> k >> a >> b;
    int ta = a / k;
    int tb = b / k;
    if (a % k == 0) --ta;
    if (b % k == 0) ++tb;
    if (ta < tb) cout << "OK\n";
    else cout << "NG\n";
	return 0;
}


Measured memory_bytes: 3648
/*
    Author: Alam Khan
    AUST CSE 40th Batch

*/

#include<bits/stdc++.h>
using namespace std;
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/detail/standard_policies.hpp>
using namespace __gnu_pbds;

typedef long long ll;
typedef pair<ll,ll> pll;
typedef vector<ll> vl;
typedef deque<ll> dl;
typedef stack<ll> stl;
typedef set<ll> sl;
typedef map<string, ll> msl;
typedef map<ll,ll> mll;
typedef tree<ll,null_type,less_equal<ll>,rb_tree_tag,tree_order_statistics_node_update>ordered_set;
#define sf(n)     scanf("%lld",&n)
#define sff(n,m)     scanf("%lld %lld",&n,&m)
#define sfff(n,m,r)     scanf("%lld %lld %lld",&n,&m,&r)
#define sfs(n)     scanf("%s",n)
#define pf(n)     printf("%lld\n",n)
#define pff(n,m)     printf("%lld %lld\n",n,m)
#define pfff(n,m,r)     printf("%lld %lld %lld\n",n,m,r)
#define pfs(n)     printf("%s\n",n)
#define pfcs(i,n)     printf("Case %lld: %lld\n",i,n)
#define pb     push_back
#define prf     printf
#define inf     2e18
#define low     -1000000000000
#define PI        acos(-1.0)
#define rep1(i,n) for(i=1;i<n;i++)
#define rep0(i,n) for(i=0;i<n;i++)
#define rep(i,a,n) for(i=a;i<n;i++)
#define repe1(i,n) for(i=1;i<=n;i++)
#define repe0(i,n) for(i=0;i<=n;i++)
#define repe(i,a,n) for(i=a;i<=n;i++)
#define endl  "\n"
#define FAST  ios_base::sync_with_stdio(false);cin.tie(NULL);
#define fr freopen("input.txt","r",stdin)
#define fw freopen("output.txt","w",stdout)

ll ma[110];
int main()
{
    ll i,n,t,k,j,x=0,y=0,m;
    cin>>n;

    for(i=0;i<n;i++)
    {
        ma[i]  =inf;
    }
    for(i=0;i<n-1;i++)
    {
        cin>>x;
        ma[i] = min(ma[i],x);
        ma[i+1] = min(ma[i+1],x);
    }
    x=  0;
    for(i=0;i<n;i++)
        x+= ma[i];
    cout<<x<<endl;

    return 0;
}



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

using namespace std;

int main() {
  int B, A;
  
  cin >> A >> B;
  
  for (int i = 1; i <= 10000; i++) {
    if (floor(i * 0.08d) == A && floor(i * 0.1d) == B) {
      cout << i << endl;
      return 0;
    }
  }
  
  cout << "-1" << endl;
  return 0;
}

Measured memory_bytes: 256