akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
#define mp       make_pair
#define pb       push_back
#define all(x)   (x).begin(),(x).end()
#define YES() printf("YES\n")
#define NO() printf("NO\n")
#define Yes() printf("Yes\n")
#define No() printf("No\n")
#define in(x,y,h,w) x >= 0 && x < h && y >= 0 && y < w

//#define int long long
//using ll = long long;
using P = pair<int,int>;

template <typename T> T &chmin(T &a, const T &b) { return a = min(a, b); }
template <typename T> T &chmax(T &a, const T &b) { return a = max(a, b); }
 
const int INF=1e+18;
const double EPS=1e-9;
const int MOD=1000000007;

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

signed main(){
	vector<int> G[610];
	int n,m;
	scanf("%d %d",&n,&m);
	for(int i = 0;i < m;i++){
		int a,b;
		scanf("%d %d",&a,&b);
		G[a - 1].push_back(b - 1);
	}
	double p[610] = {1},e[610] = {};
	for(int i = 0;i < n;i++){
		for(int to : G[i]){
			p[to] += p[i] / G[i].size();
		}
	}
	for(int i = n - 1;i >= 0;i--){
		for(int to : G[i]){
			e[i] += (e[to] + 1) / G[i].size();
		}
	}
	double mi = e[0];
	for(int i = 0;i < n;i++){
		if(G[i].size() == 1) continue;
		double ea = 0,ma = 0;
		for(int to : G[i]){
			ea += (e[to] + 1) / (G[i].size() - 1);
			ma = max(ma,(e[to] + 1) / (G[i].size() - 1));
		}
		chmin(mi,e[0] + p[i] * (ea - ma - e[i]));
	}
	printf("%.12lf\n",mi);
}


Measured memory_bytes: 1408
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

N,*A = map(int,read().split())

S = sum(A)
x = S//2 - sum(A[1::2])

rain = [x+x]
for x in A[:-1]:
    rain.append(x+x-rain[-1])
print(' '.join(map(str,rain)))

Measured memory_bytes: 19808
#include<iostream>
using namespace std;
int main()
{
    string s;
    cin>>s;
    int count=0,maxi=0;
    for(int i=0;i<3;i++)
    {
        if(s[i]=='R')
        {
         count++;
         maxi=max(maxi,count);
        }
        else
        {
            count=0;
        }
    }
    cout<<maxi<<endl;
}

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

int N;

vector<string> ans;

void dfs(string tmp, int mx) {
    int p = tmp.length();
    if (p == N) {
        ans.push_back(tmp);
        return;
    }

    int tl = max((int)(tmp[p-1] - 'a' + 1), mx);

    for (int i = 0; i <= tl; i++) {
        dfs(tmp + (char)('a' + i), tl);
    }
    return;
}

int main() {
    cin >> N;

    dfs("a" , 1);

    sort(ans.begin(), ans.end());

    for (int i=0; i < ans.size(); i++) {
        cout << ans[i] << endl;
    }

    return 0;
}


Measured memory_bytes: 9588
from bisect import bisect_left
n = int(input())
a = list(map(int, input().split()))

if n==2:
  print(str(max(a))+" "+str(min(a)))
  quit()

a.sort()
ans1=a.pop(n-1)
#print(a)
num = ans1//2
c = bisect_left(a, num)
cand1 = a[c]

if c!=0:
  cand2 = a[c-1]
  if abs(cand2-ans1/2)<abs(cand1-ans1/2):
    cand1=cand2
print(str(ans1)+" "+str(cand1))

Measured memory_bytes: 20044
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
int main(){
  int n,t,a,ans=0,mn=1e9,tmp;
  cin >> n >> t >> a;
  t*=1000;
  a*=1000;
  rep(i,n){
    cin >> tmp;
    if(mn>abs(t-6*tmp-a)){
      mn=abs(t-tmp*6-a);
      ans=i+1;
    }
  }
  cout << ans << endl;
}

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

using namespace std;
using ll = long long int;
using lc = complex<double>;

int main(void) {
    constexpr ll MOD = 1e9 + 7;
    constexpr double PI = acos(-1);
    cout << fixed << setprecision(32);
    cin.tie(0); ios::sync_with_stdio(false);

    ll d;
    cin >> d;
    ll a = 26;
    vector<ll> c(a);
    vector<vector<ll>> s(d, vector<ll>(a));
    for(auto &e: c) cin >> e;
    for(auto &l: s) for(auto &e: l) cin >> e;
    
    vector<ll> t(d);
    // for(auto &e: t) cin >> e, e--;

    vector<ll> last(a, -1);
    ll score = 0;
    for(ll i=0; i<d; i++) {

        ll mx = -1e9, mxi;
        for(ll j=0; j<a; j++)
            if(mx < s[i][j] + c[j] * (i - last[j]))
                mx = s[i][j] + c[j] * (i - last[j]), mxi = j;

        t[i] = mxi;
        last[t[i]] = i;

        score += s[i][t[i]];
        for(ll j=0; j<a; j++)
            score -= c[j] * (i - last[j]);
    }
    for(auto &e: t) cout << e+1 << endl;
}

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

int gcd(int x, int y)
{
    int res;
    if (y > x){
        int tmp = x;
        x = y;
        y = tmp;
    }
    res = x % y;
    if (res == 0){
        return(y);
    }else{
        res = gcd(res, y);
        return(res);
    }
}

int main()
{
    int x, y, res;
    std::cin >> x;
    std::cin >> y;
    res = gcd(x, y);
    std::cout << res << std::endl;
}


Measured memory_bytes: 3092
#include<bits/stdc++.h>
#define MOD 1e9+7
using namespace std;
#define  pp push_back
#define  po pop_back
#define  mp make_pair
#define clr(a) memset(a,0,sizeof(a))
#define neg(a) memset(a,-1,sizeof(a))
#define fas(a) memset(a,false,sizeof(a))
#define debug(x) cout<<#x<<": "<<x<<endl
#define debug1(x) cout<<#x<<": "<<x<<" "
#define rev(x) reverse(x.begin(), x.end())
#define int long long 
#define F first
#define S second
//int a[2000];
void printvector(std::vector<int> v){  for (int i = 0; i < v.size(); ++i){cout<<v[i]<<" ";}cout<<""<<endl;}
void printarray(int a[],int n){for (int i = 0; i < n; ++i){cout<<a[i]<<" ";}cout<<""<<endl;}
 
 

 

void  solve()
{
  int n;string s;cin>>n>>s;
  map<char,int> m;
  for(auto it:s)
  {
     m[it]++;
  }  

  int ans=1;
  int mod=MOD;
  for(auto it:m)
  { 
     ans=(ans*(it.S+1))%mod;
  }
  ans=(ans-1+mod)%mod;

  cout<<ans<<endl;


}




 int32_t main() 
{

  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
    
   solve();

return 0;

}

Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
int main(){
  int a,b,x,y,z;
  string name;
  cin>>x>>y>>name;
  cout<<"+";
  for(a=0;a<x-2;a++){cout<<"-";}
  cout<<"+"<<endl;
  for(b=0;b<(y-2)/2;b++){
  cout<<"|";
  for(a=0;a<x-2;a++){cout<<".";}
  cout<<"|"<<endl;
  }
  cout<<"|";
  for(a=0;a<(x-2)/2;a++){cout<<".";}
  cout<<name;
  for(a=0;a<(x-2)/2;a++){cout<<".";}
  cout<<"|"<<endl;
   for(b=0;b<(y-2)/2;b++){
  cout<<"|";
  for(a=0;a<x-2;a++){cout<<".";}
  cout<<"|"<<endl;
  }
   cout<<"+";
  for(a=0;a<x-2;a++){cout<<"-";}
  cout<<"+"<<endl; 
  
  return 0;
}



Measured memory_bytes: 3172
#include<iostream>
#include<cstdio>
#include<cmath>
using namespace std;
int main()
{
    int a[100],sum=0;
    int i,j,k=1000000,mini=0;
    scanf("%d%d%d%d%d",&a[0],&a[1],&a[2],&a[3],&a[4]);
    for(i=0; i<5; i++)
    {
        if((a[i]%10)!=0)
        {

            if(a[i]%10<k)
            {
                k=a[i]%10;
               mini=i;
            }
        }
    }

    for(i=0; i<5; i++)
    {
        if(i!=mini)
        {
            if(a[i]%10!=0)
                a[i]=(a[i]/10+1)*10;
            sum=sum+a[i];

        }
        //printf("sum=%d ",sum);
    }
    sum=sum+a[mini];
    printf("%d",sum);

}


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

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

int main() {
  i64 n, k;
  cin >> n >> k;
  i64 s = (n - 1) * (n - 2) / 2;
  if (k > s) { cout << -1 << '\n'; return 0; }

  cout << n - 1 + (s - k) << '\n';
  for (i64 v = 2; v <= n; ++v) {
    cout << 1 << ' ' << v << '\n';
  }
  for (i64 u = 2; s > k && u <= n; ++u) {
    for (i64 v = u + 1; s > k && v <= n; ++v) {
      cout << u << ' ' << v << '\n';
      --s;
    }
  }
  return 0;
}



Measured memory_bytes: 256
#54b
import numpy as np

N,M = map(int, input().split())

a_array = []
b_array = []

for i in range(N):
    a = str(input())
    a_list = [a[i] for i in range(N)]
    a_array.append(a_list)

for i in range(M):
    b = str(input())
    b_list = [b[i] for i in range(M)]
    b_array.append(b_list)

a_nparrary = np.array(a_array)
b_nparrary = np.array(b_array)
break_flag = 0

for x in range(N-M+1):
    for y in range(N-M+1):
        sliced_a_nparray = a_nparrary[x:x+M,y:y+M]
        #print(sliced_a_nparray)
        
        if (sliced_a_nparray == b_nparrary).all():
            print("Yes")
            break_flag = 1
            break
    
    if break_flag == 1:
        break
else:
    print("No")

Measured memory_bytes: 12404
#include<bits/stdc++.h>
using namespace std;
int main(){
    int n,result=0;
    cin>>n;

    string s = to_string(n);//Converter para string, 
                            //para saber quantos digitos tem o valor.
    int num = n;
    for(int i=0;i<s.size();i++){
        result  += (n%10);
        n = n/10;
    }

    //printf("%d ",result);
    
    if(num%result==0)
        cout<<"Yes";
    else
        cout<<"No";

    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<cstdlib>
#include<string>
#include<map>
#include<algorithm>
#include<vector>
#include<cmath>
#include<iomanip>
#define rep(i,n) for(int i(0);i<n;i++)
typedef long long ll;

using namespace std;

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

    int ans(0);

    rep(i,n){
        if(a[i]+ans != i+1){
            ans++;
        }
    }
    if(ans == n) cout << "-1" << endl;
    else cout << ans << endl;

    return 0;
}


Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i=0; i<n; i++)
#define rep1(i, n) for(int i=1; i<=n; i++)
#define repr(i, n) for(int i=n-1; i>=0; i--)
#define repr1(i, n) for(int i=n; i>=1; i--)
#define all(v) v.begin(),v.end()
using ll = long long;
using pii = pair<int, int>;
using pil = pair<int, ll>;
using pli = pair<ll, int>;
using pll = pair<ll, ll>;
const int INF = 1e9;
const ll LLINF = 1e18;
const ll MOD = 1e9+7;
const double EPS = 1e-10;
const double PI = acos(-1);
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

int main() {
    int n, m; cin >> n >> m;
    vector<vector<pli>> g(n);

    rep(i, n-1) {
        g[i+1].emplace_back(0, i);
    }

    rep(i, m) {
        int l, r; ll c;
        cin >> l >> r >> c;
        l--; r--;
        g[l].emplace_back(c, r);
        g[r].emplace_back(c, l);
    }

    priority_queue<pli, vector<pli>, greater<pli>> q;
    q.emplace(0, 0);
    vector<ll> dist(n, LLINF);
    dist[0] = 0;
    while (!q.empty()) {
        pli top = q.top(); q.pop();
        int u = top.second;
        for (auto &e: g[u]) {
            int v = e.second;
            ll cost = e.first;
            if (chmin(dist[v], dist[u] + cost)) {
                q.emplace(dist[v], v);
            }
        }
    }
    cout << (dist[n-1] == LLINF ? -1 : dist[n-1]) << endl;
}


Measured memory_bytes: 13048
#include <cassert>
#include <cctype>
#include <cerrno>
#include <cfloat>
#include <ciso646>
#include <climits>
#include <clocale>
#include <cmath>
#include <csetjmp>
#include <csignal>
#include <cstdarg>
#include <cstddef>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <cwchar>
#include <cwctype>
#include <ccomplex>
#include <cfenv>
#include <cinttypes>
#include <cstdbool>
#include <cstdint>
#include <ctgmath>
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>
#include <array>
#include <atomic>
#include <chrono>
#include <codecvt>
#include <condition_variable>
#include <forward_list>
#include <future>
#include <initializer_list>
#include <mutex>
#include <random>
#include <ratio>
#include <regex>
#include <scoped_allocator>
#include <system_error>
#include <thread>
#include <tuple>
#include <typeindex>
#include <type_traits>
#include <unordered_map>
#include <unordered_set>
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define rep2(i, n) for(int i = 1; i <= (int)(n); i++)
#define all(x) (x).begin(),(x).end()
using namespace std;
typedef int64_t ll;
typedef long double ld;
const ll INF=(1LL<<62);
const double inf=pow(10,10);
const ld pi=acosl(1);
const ll mod = 1000000007;
const int dx[4]={0,1,0,-1};
const int dy[4]={1,0,-1,0};
const int ddx[8]={1,0,-1,-1,-1,0,1,1};
const int ddy[8]={1,1,1,0,-1,-1,-1,0};

bool check(pair<ll,ll>a,pair<ll,ll>b){
	return (a.first>b.first&&a.second>b.second);
}

bool fun(pair<ll,ll>b,pair<ll,ll>a){
	if(a.first==b.first)return a.second>b.second;
	else return a.first<b.first;
}

void add(string* s,ll i){

	if(i>=(*s).size()){
		(*s).push_back('1');
		return;
	}
	if((*s)[i]!='9'){
		(*s)[i]++;
		return;
	}
	else{
		(*s)[i]='0';
		add(s,i+1);
		return ;
	}
	
}

int main(){
	rep(i,3){
		string s;cin>>s;
		cout<<s[0];
	}
	cout<<endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define pi acos(-1)
#define IOS ios_base::sync_with_stdio(0); cin.tie(); cout.tie();
#define ff first
#define ss second
#define pb push_back
#define debug(val) cerr << "The value of " << #val << " is = " << val << '\n';
typedef long long ll;
typedef unsigned long long ull;
const ll mod = 1e9 + 7;
const ll inf = 0x3f3f3f3f;
const ll mininf = -922337203685477;
const ll nax = 0;
long double n, ans=0.0;

int main(){
	IOS
	cin >> n;
	for(int i=0;i<n;i++){
		long double a;
		cin >> a;
		ans+=(1/a);
	}
	cout << setprecision(9) << fixed;
	cout << 1/ans << '\n';
} 


Measured memory_bytes: 3784
import sys
f = sys.stdin

def drop(paper, x, y):
    if 0 <= x < len(paper[0]) and 0 <= y < len(paper):
        paper[y][x] += 1

drop_range = {}
drop_range[1] = ((0, 0), (0, -1), (1, 0), (0, 1), (-1, 0))
drop_range[2] = drop_range[1] + ((-1, -1), (1, -1), (1, 1), (-1, 1))
drop_range[3] = drop_range[2] + ((0, -2), (2, 0), (0, 2), (-2, 0))

paper = [[0 for j in range(10)] for i in range(10)] 

for line in f:
    x, y, size = map(int, line.split(','))
    
    for dx, dy in drop_range[size]:
        drop(paper, x + dx, y + dy)

paper = [x for y in paper for x in y]
print(sum(1 for thick in paper if thick == 0))
print(max(paper))

Measured memory_bytes: 6756
#include <stdio.h>
int main(void)
{
    int a;
    int b;
    scanf("%d",&a);
    scanf("%d",&b);
    if((a+b)%2==0)
    {
        printf("%d\n",(a+b)/2);
    }
    else
    {
        printf("%d\n",(a+b)/2+1);
    }
    return 0;   
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
 
#define rep(i, j, n) for(int i=j;i<n;++i)
#define all(i) i.begin(),i.end()
#define rall(i) i.rbegin(),i.rend()
#define INF 1e9
#define LINF 1e18
const int mod = 1e9 + 7;
 
typedef long long i64;
typedef pair<int, int> pi;
 
template <class T> using vt = vector<T>;
template <class T> using vvt = vector<vector<T>>;
 
i64 gcd(i64 n, i64 m) {return (m == 0? n : gcd(m, n % m));}
i64 lcm(i64 n, i64 m) {return (n / gcd(n, m) * m);}
int dx[] = {0, -1, 0, 1, 1, 1, -1, -1};
int dy[] = {-1, 0, 1, 0, 1, -1, 1, -1};

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

  i64 a, b;
  int k;
  cin >> a >> b >> k;

  rep(i, 0, k) {
    if(i % 2 == 0) {
      if(a % 2) a--;
      b += a / 2;
      a /= 2;
    }
    else {
      if(b % 2) b--;
      a += b / 2;
      b /= 2;
    }
  }
  cout << a << " " << b << endl;
}


Measured memory_bytes: 256
import java.io.*;
import java.nio.CharBuffer;
import java.util.NoSuchElementException;

public class Main {

    public static void main(String[] args) {
        SimpleScanner scanner = new SimpleScanner(System.in);
        PrintWriter writer = new PrintWriter(System.out);

        int n = scanner.nextInt();
        char[] s = scanner.next().toCharArray();
        boolean valid = true;
        if (n % 2 == 0) {
            for (int i = 0; i < n / 2; ++i) {
                if (s[i] != s[i + n / 2]) {
                    valid = false;
                    break;
                }
            }
        } else
            valid = false;
        writer.println(valid ? "Yes" : "No");

        writer.close();
    }

    private static class SimpleScanner {

        private static final int BUFFER_SIZE = 10240;

        private Readable in;
        private CharBuffer buffer;
        private boolean eof;

        SimpleScanner(InputStream in) {
            this.in = new BufferedReader(new InputStreamReader(in));
            buffer = CharBuffer.allocate(BUFFER_SIZE);
            buffer.limit(0);
            eof = false;
        }


        private char read() {
            if (!buffer.hasRemaining()) {
                buffer.clear();
                int n;
                try {
                    n = in.read(buffer);
                } catch (IOException e) {
                    n = -1;
                }
                if (n <= 0) {
                    eof = true;
                    return '\0';
                }
                buffer.flip();
            }
            return buffer.get();
        }

        private void checkEof() {
            if (eof)
                throw new NoSuchElementException();
        }

        private char nextChar() {
            checkEof();
            char b = read();
            checkEof();
            return b;
        }

        private String next() {
            char b;
            do {
                b = read();
                checkEof();
            } while (Character.isWhitespace(b));
            StringBuilder sb = new StringBuilder();
            do {
                sb.append(b);
                b = read();
            } while (!eof && !Character.isWhitespace(b));
            return sb.toString();
        }

        private int nextInt() {
            return Integer.parseInt(next());
        }

        private long nextLong() {
            return Long.parseLong(next());
        }

        private double nextDouble() {
            return Double.parseDouble(next());
        }
    }
}

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

int main()
{
    int N;
    cin >> N;
    string txt = (N / 10 == 9 || N % 10 == 9) ? "Yes" : "No";
    cout << txt << endl;
    return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>
int cmp(const int *a,const int *b){
  return *b-*a;
}
int main(){
  int n,s=0,l[200],i;
  scanf("%d",&n);
  for(i=0;i<2*n;i++)scanf("%d",&l[i]);
  qsort(l,2*n,sizeof(int),cmp);
  for(i=0;i<n;i++)s+=l[2*i+1];
  printf("%d",s);
  return 0;
}

Measured memory_bytes: 128
S = input()
T = input()
st = {}
ts = {}
for s, t in zip(S, T):
  if st.get(s, t) != t:
    print('No')
    break
  else:
    st[s] = t
  if ts.get(t, s) != s:
    print('No')
    break
  else:
    ts[t] = s
else:
  print('Yes')

Measured memory_bytes: 3632
def lucas(n)
  return 1 if n == 1

  l1, l2 = 2, 1
  ll = l1 + l2

  i = 2
  until i == n
    nl = l2 + ll

    l1 = l2
    l2 = ll
    ll = nl

    i += 1
  end
  ll
end

n = gets.to_i
puts lucas(n)


Measured memory_bytes: 1788
#include <bits/stdc++.h>
#define INF LLONG_MAX
#define ll  long long
#define ull unsigned long long
#define rep(i,n) for(int i=0; i<n; ++i)
#define MOD 1000000007
using namespace std;
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 N; cin >> N;
  vector<ll> H(N);
  rep(i, N) cin >> H[i];

  if(N==1) {
    cout << "Yes" << endl;
    return 0;
  }
  rep(i, N-1) {
    if(H[i] < H[i+1]) H[i+1]--;
  }
  rep(i, N-1) {
    if(H[i] <= H[i+1]){
      continue;
    } else {
      cout << "No" << endl;
      return 0;
    }
  }
  cout << "Yes" << endl;
}


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

int main() {
  int N;
  cin >> N;
  
  for  (int i = 0; i < N; i++) {
    string S;
    cin >> S;
    
    if (S == "Y") {
      cout << "Four" << endl;
      break;
    }
    if (i == N - 1) {
      cout << "Three" << endl;
    }
  }
}

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

int main() {
    int N;
    cin >> N;
    vector<int> t(N+1), x(N+1), y(N+1);
    t[0] = x[0] = y[0] = 0;
    rep (i, N) cin >> t[i+1] >> x[i+1] >> y[i+1];

    bool can = true;
    rep(i, N) {
        int dt = t[i+1] - t[i];
        int dist = abs(x[i+1] - x[i]) + abs(y[i+1] - y[i]);
        if (dt < dist || dt % 2 != dist % 2) {
            can = false;
            break;
        }
    }
    if (can) cout << "Yes" << endl;
    else cout << "No" << endl;
}

Measured memory_bytes: 1408
x=input()
a=int(x[0])
b=int(x[1])
c=int(x[2])
d=int(x[3])
if a+b+c+d==7:
  print(str(a)+'+'+str(b)+'+'+str(c)+'+'+str(d)+'=7')
elif a+b+c-d==7:
  print(str(a)+'+'+str(b)+'+'+str(c)+'-'+str(d)+'=7')
elif a+b-c+d==7:
  print(str(a)+'+'+str(b)+'-'+str(c)+'+'+str(d)+'=7')
elif a+b-c-d==7:
  print(str(a)+'+'+str(b)+'-'+str(c)+'-'+str(d)+'=7')
elif a-b+c+d==7:
  print(str(a)+'-'+str(b)+'+'+str(c)+'+'+str(d)+'=7')
elif a-b+c-d==7:
  print(str(a)+'-'+str(b)+'+'+str(c)+'-'+str(d)+'=7')
elif a-b-c+d==7:
  print(str(a)+'-'+str(b)+'-'+str(c)+'+'+str(d)+'=7')
elif a-b-c-d==7:
  print(str(a)+'-'+str(b)+'-'+str(c)+'-'+str(d)+'=7')

Measured memory_bytes: 3064
//
//  main.cpp
//  CompetitiveProgramming
//
//  Created by yumarimo on 2018/03/02.
//  Copyright © 2018年 yumarimo. All rights reserved.
//

#include <iostream>
#include <cmath>
#include <cstdio>
#include <algorithm>
#include <random>
#include <string>
#include <bitset>
#include <map>
#include <vector>
#include <stack>
#include <queue>
#include <list>
#include <set>
#include <cstring>
#include <cstdlib>
#include <cctype>

#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 INF 999999999

using namespace std;

typedef pair<int, int> P;
typedef pair<llong, llong> LP;
typedef pair<int, P> PP;
typedef pair<llong, LP> LPP;

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

llong pow(int x, int n) {
    llong ans = x;
    if (n == 0) return 1;

    for(int i = 0; i < n - 1; i++) {
        ans *= x;
    }

    return ans;
}

void swap(int *X, int *Y){
    int t = *X; *X = *Y; *Y = t;
}

string toUpper(string s) {
    string t = s;
    REP(i, s.size()) {
        t[i] = toupper(s[i]);
    }
    return t;
}

string toLower(string s) {
    string t = s;
    REP(i, s.size()) {
        t[i] = tolower(s[i]);
    }
    return t;
}

int main() {
    int n, m, a[1000], b[1000], c[1000], distance[100][100];
    cin >> n >> m;

    REP(i, m) {
        cin >> a[i] >> b[i] >> c[i];
        a[i]--;
        b[i]--;
    }

    REP(i, n) {
        REP(j, n) {
            if (i == j) distance[i][j] = 0;
            else distance[i][j] = INF;
        }
    }

    REP(i, m) {
        distance[a[i]][b[i]] = min(distance[a[i]][b[i]], c[i]);
        distance[b[i]][a[i]] = min(distance[b[i]][a[i]], c[i]);
    }

    REP(k, n) {
        REP(i, n) {
            REP(j, n) {
                distance[i][j] = min(distance[i][j], distance[i][k] + distance[k][j]);
            }
        }
    }

    int ans = m;
    REP(i, m) {
        bool shortest = false;
        REP(j, n) if (distance[j][a[i]] + c[i] == distance[j][b[i]]) shortest = true;
        if (shortest) ans -= 1;
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int n,m,tmp,s;
int d(int a,int b)
{
	a=a^b;
	b=b^a;
	b=b>>2;
	a=a<<2;
	a=(a^b)^(a&b)|(--a)&(--b)^(a|b);
	b=a^b;
	return b|a;
}
int main()
{
	cin>>n>>m;
	tmp=m/n;
	for(int i=tmp;i>=1;i--)
	{
		s+=d(i,tmp);
		if(!(m%i))
		{
			printf("%d",i);
			return 0;
		}
	}
	printf("%d",s);
}


Measured memory_bytes: 256
#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;i >= 0;i--)
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define fi first
#define se second
#define mp make_pair
#define itrfor(itr,A) for(auto itr = A.begin(); itr !=A.end();itr++)
template <class T> using reversed_priority_queue = priority_queue<T, vector<T>, greater<T> >;
typedef long long llong;
char moji[26]={'a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z'};
char moji2[26]={'A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z'};
char moji3[10]={'0','1','2','3','4','5','6','7','8','9'};
#define Sort(a) sort(a.begin(),a.end());
#define Reverse(a) reverse(a.begin(),a.end());
#define print(a) cout << a << endl;
#define MOD llong(1e9+7)
#define MAX int(2 * 1e5 +5)
#define debug(x)  cout << #x << " = " << (x) << endl;
#define pi acos(-1.0)
#define int llong
#define INF llong(1e18 + 3)
template<class T> bool chmax(T &a,  T b) {if(a<b){a=b; return 1;} return 0;}
template<class T> bool chmin(T &a,  T b) {if(a>b){a=b; return 1;} return 0;}
bool Add(int &a,int b){a = (a + b) % MOD;}
void myprint(int* A,int A_num){
   REP(i,A_num) cout << A[i] << " ";
   cout << endl;
}

struct edge{
    int from,to,w;
};

signed main(){
    int n,m;
    cin >> n >> m;
    edge E[m];
    REP(i,m){
        cin >> E[i].from >> E[i].to >> E[i].w;
        E[i].from --;
        E[i].to --;
        E[i].w *= - 1;
    }

    int d[n];
    REP(i,n) d[i] = INF;
    d[0] = 0;

    REP(i, n - 1){
        REP(j,m){
            chmin(d[E[j].to], d[E[j].from] + E[j].w);
        }
    }
    REP(i,n - 1){
        REP(j,m){
            if(E[j].to == n - 1 and d[n - 1] > d[E[j].from] + E[j].w){
                cout << "inf" << endl;
                return 0;
            }
            chmin(d[E[j].to], d[E[j].from] + E[j].w);            
        }
    }
    /*
    REP(j,m){
        if(d[E[j].to] > d[E[j].from] + E[j].w){
            cout <<"inf" << endl;
            return 0;
        }
    }
    */

    cout << -d[n-1] << endl;
}

Measured memory_bytes: 256
#include <iostream>

int main()
{
    int a[100] = {}, n, m = 0;
    while (std::cin >> n) {
        ++a[n - 1];
        if (m < a[n - 1]) m = a[n - 1];
    }
    for (int i = 0; i < 100; ++i)
        if (a[i] == m) std::cout << i + 1 << std::endl;
}

Measured memory_bytes: 1156
N = int(input())
P = []
for i in range(N):
    P.append(int(input()))

W = {}
for p in P:
    if p in W.keys():
        W[p+1] = W[p] + 1
        del W[p]
    else:
        W[p+1] = 1

#print(W)
print(N - max(W.values()))


Measured memory_bytes: 34956
n = int(input())
a = list(map(int,input().split()))
b = list(map(int,input().split()))
counter = 0
for i in range(n):
    if b[i] <= a[i]:
        a[i] -= b[i]
        counter += b[i]
    else:
        counter += a[i]
        b[i] = b[i] - a[i]
        a[i] = 0
        if b[i] <= a[i+1]:
            a[i+1] -= b[i]
            counter += b[i]
        else:
            counter += a[i+1]
            b[i] = b[i] - a[i+1]
            a[i+1] = 0
print(counter)

Measured memory_bytes: 18476
// C
#ifndef _GLIBCXX_NO_ASSERT
#include <cassert>
#endif
#include <cctype>
#include <cerrno>
#include <cfloat>
#include <ciso646>
#include <climits>
#include <clocale>
#include <cmath>
#include <csetjmp>
#include <csignal>
#include <cstdarg>
#include <cstddef>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>

#ifdef __GXX_EXPERIMENTAL_CXX0X__
#include <ccomplex>
#include <cfenv>
#include <cinttypes>
#include <cstdbool>
#include <cstdint>
#include <ctgmath>
#include <cwchar>
#include <cwctype>
#endif

// C++
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>

#ifdef __GXX_EXPERIMENTAL_CXX0X__
#include <array>
#include <atomic>
#include <chrono>
#include <condition_variable>
#include <forward_list>
#include <future>
#include <initializer_list>
#include <mutex>
#include <random>
#include <ratio>
#include <regex>
#include <system_error>
#include <thread>
#include <tuple>
#include <typeindex>
#include <type_traits>
#include <unordered_map>
#include <unordered_set>
#endif
//#include <bits/stdc++.h>

#define all(v) v.begin(), v.end()
typedef long long ll;
#define rep(i, z, n) for(ll i = z; i < n; i++)
//const int INF = 1<<29;
//const int MODINF = 1000000007;
using namespace std;

int main(){
    ll N, D;
    cin >> N >> D;
    int count = 0;
    rep(i, 0, N){
        ll X, Y;
        cin >> X >> Y;
        ll kyori = X*X + Y*Y;
        if(D*D >= kyori) count++;
    }
    cout << count << endl;
}

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

def main():
    n = int(input())
    d, x = map(int, input().split())
    a = []
    for i in range(n):
        a.append(int(input()))
    cnt = 0
    
    for i in range(1, d+1):
        for j in a:
            if (i - 1) % j == 0:
                cnt += 1
    print(cnt + x)

if __name__ == '__main__':
    main()

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
int r,d,x[2020];
int main() {
    cin>>r>>d>>x[2000];
    for (int i=2001; i<=2010; i++) {
        x[i]=x[i-1]*r-d;
        cout<<x[i]<<'\n';
    }
}

Measured memory_bytes: 3512
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define sz(x) int(x.size())
#define ALL(c) (c).begin(), (c).end()
#define SUM(x) std::accumulate(ALL(x), 0LL)
#define MIN(v) *std::min_element(v.begin(), v.end())
#define MAX(v) *std::max_element(v.begin(), v.end())
#define EXIST(v, x) (std::find(v.begin(), v.end(), x) != v.end())

using namespace std;
typedef long long ll;

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; }
const int INF = 1001001001;
const long long INFL = (1LL<<60);
const double eps = (1e-9);

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

  ll ans = 0;
  ans += (x / 500) * 1000;
  x %= 500;
  ans += (x / 5) * 5;

  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 256
T = gets.to_i

T.times do
  ary_R = Array.new
  ary_G = Array.new
  ary_B = Array.new
  r_idx = 0
  g_idx = 0
  b_idx = 0 
  num = gets.chomp.split(' ').map(&:to_i)
  color = gets.chomp.split(' ')

  for i in 0..8
    case color[i]
    when 'R'
      ary_R[r_idx] = [num[i], color[i]]
      r_idx += 1
    when 'G'
      ary_G[g_idx] = [num[i], color[i]]
      g_idx += 1
    when 'B'
      ary_B[b_idx] = [num[i], color[i]]
      b_idx += 1
    end
  end

  set = 0
  data = [ ary_R.sort!, ary_G.sort!, ary_B.sort! ]

  data.each do |ary|
    next if ary.size < 3
    while true
      break if ary.size < 3
      card = ary.shift
      for i in 0...ary.size-1
        equal = 1
        snum = 1
        end_flag = 0
        case ary[i][0] - card[0]
        when 0
          equal += 1
        when 1
          snum += 1
        else
          break
        end

        for j in i+1...ary.size
          case ary[j][0] - card[0]
          when 0
            equal += 1
          when 2
            snum += 1
          else
            break
          end
          if equal == 3 || snum == 3
            set += 1
            ary.delete_at(ary.find_index(ary[i]))
            ary.delete_at(ary.find_index(ary[j-1]))
            end_flag = 1
            break
          end
        end
        break if end_flag == 1
      end
    end
  end
  case set
  when 3
    puts 1
  else
    puts 0
  end
 end

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

using namespace std;

int main (void) {
  int a, b, c;
  cin >> a >> b;
  
  c = b;
  while (c) {
    a *= 10;
    c /= 10;
  }
  
  a += b;

  c = (int) sqrt (a);
  cout << ((c * c == a) ? "Yes" : "No") << endl;
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(){
	int a,b;
	cin>>a>>b;
	int ar[a+2];
	int sum=0;
	for(int i=1;i<=a;i++){
		ar[i]=((i-1)+b);
		sum+=ar[i];
	}
	int ma=99999999;
	for(int i=1;i<=a;i++){
		ma=min(ma,abs(ar[i]));
		//cout<<abs(abs(ar[i])-abs(sum))<<endl;
	}
	if(sum>=0){
	cout<<sum-ma<<endl;}
	else{
		sum+=ma;
		cout<<sum<<endl;
	}
}

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

int main() {
	int n;
	cin >> n;
	int ans = 0;
	for (int i = 1;i <= n;i += 2) {
		int res = 0;
		for (int j = 1;j <= i;++j) {
			if (i % j == 0) {
				++res;
			}
		}
		if (res == 8) {
			++ans;
		}
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 256
x = input()
n = int(x.split()[0])
m = int(x.split()[1])
y = input()
list = y.split(' ')
sum = 0

for i in list:
    i = int(i)
    sum = sum + i

if n >= sum:
    answer = n - sum
else:
    answer = '-1'
print(answer)

Measured memory_bytes: 9520
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); i++)
using namespace std;
using ll = long long;
const long long mod = 1e9 + 7;

int main(){
  int n, k;
  cin >> n >> k;
  vector<ll> h(n);
  rep(i,n){
    cin >> h[i];
  }
  vector<ll> dp(n + 1, 1000000000000000);
  dp[0] = 0;
  for (int now = 0; now < n; now++){
    for (int j = 1; j <= k; j++){
      if(now + j <  n){
        dp[now + j] = min(dp[now + j], dp[now] + abs(h[now + j] - h[now]));
      }
    }
  }
  cout << dp[n - 1] << endl;
  return 0;
}

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

int main() {
  
  vector<int> vec(3);
  
  for (int i = 0; i < 3; i++) cin >> vec[i];
  
  sort(vec.begin(), vec.end());
  
  int minNum = vec[0]; int midNum = vec[1]; int maxNum = vec[2];
  
  int difSum = (maxNum - midNum) + (maxNum - minNum);
  
  if (difSum % 2 == 0) cout << difSum / 2 << endl;
  
  else cout << difSum / 2 + 2 << endl;
  
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using int64 = long long;
#define int int64
#define rep(i, n) for(int i=0; i<n; i++)
#define FOR(i, a, b) for(int i=a; i<b; i++)
#define SORT(x) sort(x.begin(), x.end())
#define GSORT(x) sort(x.begin(), x.end(), greater<int>())
#define mk make_pair
#define fi first
#define se second
#define pb push_back
#define ALL(x) x.begin(), x.end()
#define V(T) vector<T>
typedef pair<int, int> P;
typedef pair<P, P> PP;
typedef vector<int> vi;
typedef vector<vi> vvi;
int max(int a, int b) {if(b>a) return b; else return a;}
int min(int a, int b) {if(b<a) return b; else return a;}
const int INF = 1e18;

signed main() {
    int N;
    cin >> N;
    vi A(N);
    map<int, int> mp;
    rep(i, N) {
        cin >> A[i];
        mp[A[i]]++;
    }
    SORT(A);

    int res = 0;
    for(int i=30; i>=0; i--) {
        int t = pow(2, i);
        rep(j, N) {
            if(A[j]>t) break;
            if(mp[A[j]]) {
                if(t-A[j]>0 && mp[t-A[j]]-(t-A[j]==A[j] ? 1 : 0)) {
                    //cout << A[j] << " " << t-A[j] << endl;
                    res++;
                    mp[A[j]]--;
                    mp[t-A[j]]--;
                }
            }
        }
    }

    cout << res << endl;

    return 0;
}

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

using namespace std;

int main() {
int n,k,count=0;
cin>>n>>k;
int arr[n];
    for (int i = 0; i <n ; ++i) {
        cin>>arr[i];
    }
    sort(arr,arr+n);
    for (int i = 0; i <k ; ++i) {
        count+=arr[i];
    }
    cout<<count;
}




Measured memory_bytes: 3536
#include <stdio.h>
#include <math.h>

int main(){
    int X;

    scanf("%d", &X);

    while(1){
        int i;

        int flg = 0;

        for(i = 2; i <= sqrt(X) + 1e-6; i ++){
            if(X % i == 0){
                flg = 1;

                break;
            }
        }
        if(flg == 0){
            break;
        }
        X ++;
    }
    printf("%d\n", X);
}

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

struct Node {
  int key;
  struct Node *rig, *lef, *parent;
};

struct Node *root,*NIL;

void insert(int);
void inorder(struct Node *);
void preorder(struct Node *);

int main(){
  int n,i,x;
  char c[10];
  char in[10]="insert";
  char pri[10]="print";

  scanf("%d",&n);

  for(i=0;i<n;i++){
    scanf("%s",c);

    if(strcmp(c,in) == 0) {
      scanf("%d",&x);
      insert(x);
    } else if(strcmp(c,pri) == 0) {
      inorder(root);
      printf("\n");
      preorder(root);
      printf("\n");
    }
  }

  return 0;
}

void insert(int a){
  struct Node *y = NIL;
  struct Node *x = root;
  struct Node *z;

  z = (struct Node *)malloc(sizeof(struct Node));
  z->key = a;
  z->lef = NIL;
  z->rig = NIL;

  while(x != NIL){
    y = x;
    if(z->key < x->key){
      x = x->lef;
    }else {
      x = x->rig;
    }
  }

  z->parent = y;
  if(y == NIL){
    root = z;
  }else {
    if(z->key < y->key){
      y->lef = z;
    }else{
      y->rig = z;
    }
  }
}

void inorder(struct Node *u){
  if(u == NIL) return;
  inorder(u->lef);
  printf(" %d",u->key);
  inorder(u->rig);
}

void preorder(struct Node *u){
  if(u == NIL) return;
  printf(" %d",u->key);
  preorder(u->lef);
  preorder(u->rig);
}



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

using ll = long long;
using namespace std;


int main()
{
    int n, k; cin >> n >> k;
    vector<ll> a(n);
    for(int i = 0; i < n; i++)cin >> a[i];

    ll ans = 10000000000000000;

    for(int bit = 0; bit < (1 << n); bit++)
    {
        ll sum = 0,count = 0, cur_max = 0;
        //bit := 前よりも高く見せるビルのフラグ
        for(int i = 0; i < n; i++){

            if(bit & (1 << i)){
                sum += max(0LL, cur_max - a[i] + 1);
                count++;
            }else {cur_max = max(cur_max, a[i]);continue;}
            cur_max = max(cur_max, a[i] + max(0LL, cur_max - a[i] + 1));
        }
        if(count < k)continue;
        ans = min(sum, ans);
    }
    cout << ans << endl;
}

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

using namespace std;
using llong = long long;
using P = pair<llong, llong>;

#define BE(x) x.begin(), x.end()

const llong inf = llong(1e18)+7;
const llong mod = 1e9+7;

int main(){
	int a,b;
	string s;

	cin >> a >> b >> s;
	bool check = true;
	for(int i = 0; i < a+b+1;i++){
		if(i == a){
			if(s[a] != '-')
				check = false;
		}else
			if(s[i] == '-')
				check = false;

	}

	if(check)
		cout << "Yes" << endl;
	else
		cout << "No" << endl;

	return 0;
}

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

int main()
{
    int a,b,c,i,j=0;
    cin >> a >> b >> c;
    for (i = a;i <= b;++i )
        {
            if (c % i == 0)
                ++j;
        }

    cout << j << endl;
    return 0;
}

Measured memory_bytes: 1160
import java.io.IOException;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.List;
import java.util.Scanner;

public class Main {
    public static void main(String[] args) throws IOException {
        List<Integer> inputs = new ArrayList<Integer>();

        Scanner sc = new Scanner(System.in);
        for(int i=0; i<10; i++) {
            if(!sc.hasNextInt()) {
                break;
            }
            int input = sc.nextInt();
            inputs.add(Integer.valueOf(input));
        }

        Collections.sort(inputs, new Comparator<Integer>() {
            @Override
            public int compare(Integer o1, Integer o2) {
                return o2-o1;
            }
        });
        
        for(int height : inputs.subList(0, Math.min(inputs.size(), 3))) {
            System.out.println(height);
        }
    }
}

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

using namespace std;

std::vector<std::vector<long long>> warshall_floyd(std::vector<std::vector<long long>> dist) {
  const long long LINF = 1000000000000000018LL;
  int n = (int)dist.size();
  for (int k = 0; k < n; k++) {
    for (int i = 0; i < n; i++) {
      if (dist[i][k] == LINF) {
        continue;
      }
      for (int j = 0; j < n; j++) {
        if (dist[k][j] == LINF) {
          continue;
        }
        dist[i][j] = std::min(dist[i][j], dist[i][k] + dist[k][j]);
      }
    }
  }
  return dist;
}

int main() {
  int H, W;
  std::cin >> H >> W;

  std::vector<std::vector<long long>> G(10, std::vector<long long>(10));
  for (int y = 0; y < 10; y++) {
    for (int x = 0; x < 10; x++) {
      std::cin >> G[y][x];
    }
  }
  auto dist = warshall_floyd(G);

  int ans = 0;
  for (int y = 0; y < H; y++) {
    for (int x = 0; x < W; x++) {
      int A;
      std::cin >> A;
      if (A != -1) {
        ans += dist[A][1];
      }
    }
  }
  std::cout << ans << "\n";

  return 0;
}

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

const int H=1e3+5, W=1e3+5, MODULO=1e9+7;
int w,h;
char maze[H][W];
long long dp[H][W];

bool isValid(int i, int j){
    return i>0&&j>0&&i<=h&&j<=w&&maze[i][j]=='.';
}

long long solve(int i, int j){
    if(i==h && j==w)
        return 1;
    long long &ret=dp[i][j];
     if(~ret) return ret;
    ret=0;
    if(isValid(i,j)){
        maze[i][j]='x';
        if(isValid(i+1,j)) ret+=solve(i+1,j)%MODULO;
        if(isValid(i,j+1)) ret+=solve(i,j+1)%MODULO;
        maze[i][j]='.';

    }
    return ret;
}

int main(){
    // freopen("out.txt","wt",stdout);
    memset(dp, -1, sizeof dp);
    scanf("%d %d", &h, &w);
    for (int i = 1; i <= h; ++i)
    {
        cin.ignore();
        for (int j = 1; j <= w; ++j)
        {
            scanf("%c", &maze[i][j]);
        }
    }
    int b=0;
    printf("%lld\n", solve(1,1)%MODULO);
    return 0;
}


Measured memory_bytes: 9216
#include<bits/stdc++.h>
using namespace std;
typedef long long LL;
void READ() {
#define R READ();
#define INFI 0x3f3f3f3f
#define INFL 0x3f3f3f3f3f3f3f3f
#define MEMX(x,num) memset(x,num,sizeof(x))
#define prln(x) cout<<#x<<"="<<x<<endl
#define prt(x) cout<<x<<endl
#define prk(x) x<<" "
#define sz(x) int(x.size())
#define PB(x) push_back(x)
#define LINK(x,y) G[x].PB(y),G[y].PB(x)
#define rep(i,a,b) for(int i=a;i<=b;i++)
#define per(i,a,b) for(int i=a;i>=b;i--)
#ifndef ONLINE_JUDGE
    freopen("A.in", "r", stdin);
#endif
    std::ios::sync_with_stdio(0);
    cin.tie(0);
    cout << fixed << setprecision(6);
}
///////////////////////////
const int N = 5 + 1e5;
int t, n,m, k, a[N],vis[N],ans;
vector<int>G[N],v1,v2;
void bfs(int x) {
    queue<int>q;
    vis[x]=1;
    q.push(x);
    v1.PB(x);
    v2.PB(a[x]);
    while(!q.empty())
    {
        int u=q.front();q.pop();
        rep(i,0,(int)G[u].size()-1)
        {
            int v=G[u][i];
            if(vis[v])continue;
            vis[v]=1;
            q.push(v);
            v1.PB(v);
            v2.PB(a[v]);
        }
    }
}
int main () {
    
    cin >> n >> m;
    rep(i, 1, n) {
        cin >> a[i];
    }
    int x,y;
    rep(i, 1, m) {
        cin >> x >> y;
        LINK(x, y);
    }
    rep(i, 1, n) {
        if(vis[i])continue;
        bfs(i);
        sort(v1.begin(),v1.end());
        sort(v2.begin(),v2.end());
        for(int i=0,j=0;i<v1.size()&&j<v2.size();)
        {
            if(v1[i]==v2[j])ans++,i++,j++;
            else if(v1[i]>v2[j])j++;
            else i++;
        }
        v1.clear();
        v2.clear();
    }
    cout<<ans;

    return 0;
}




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

int main() {
	int n;
    while(cin>>n){
        int dp[10001]={0};
        dp[1]=2;
        for(int i=2;i<=n;i++){
            dp[i]=dp[i-1]+i;
        }
        cout<<dp[n]<<endl;
    }
	return 0;
}

Measured memory_bytes: 1208
from collections import Counter,defaultdict,deque
from heapq import heappop,heappush,heapify
import sys,bisect,math,itertools,pprint,fractions
sys.setrecursionlimit(10**8)
mod = 10**9+7
mod2 = 998244353
INF = float('inf')
def inp(): return int(sys.stdin.readline())
def inpl(): return list(map(int, sys.stdin.readline().split()))
def inpln(n): return list(int(sys.stdin.readline()) for i in range(n))

n,m,r = inpl()
x = inpl()
g = [[INF] *n for i in range(n)]
for i in range(m):
    a,b,c = inpl()
    g[a-1][b-1] = c
    g[b-1][a-1] = c
for i in range(n):
    g[i][i] = 0
for k in range(n):
    for i in range(n):
        for j in range(n):
            g[i][j] = min(g[i][k]+g[k][j], g[i][j])

res = INF
for flag in itertools.permutations(range(r)):
    cnt = 0
    for i in range(r-1):
        cnt += g[x[flag[i]]-1][x[flag[i+1]]-1]
    res = min(res, cnt)
print(res)

Measured memory_bytes: 94680
#include <iostream>
#include <string>
#include <algorithm>
#include <set>
#include <cmath>
#include <vector>
#include <queue>

typedef long long ll;
const ll LL_MAX (1LL<<60);

#define rep(i,s,e) for(ll i=(s); i<(e); i++) 

using namespace std;

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

    //vector<ll> a(n);
    //rep(i, 0, n) cin >> a[i];
    priority_queue<ll> a;
    rep(i, 0, n)
    {
        ll b;
        cin >> b;
        a.push(b);
    }

    rep(i,0,m)
    {
        ll t = a.top()/2;
        a.pop();
        a.push(t);
    }
    
    ll ans;
    while (!a.empty())
        ans+=a.top(), a.pop();

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


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

signed main(){
	int D,G; cin>>D>>G;
	vector<int> p(D);
	vector<int> c(D);
	for(int i=0;i<D;i++)cin>>p[i]>>c[i];
	int ans=INT_MAX;
	for(int bit=0;bit<(1<<D);bit++){
		int tmp=0;//解く問題数
		int point=0;//得られる得点
		int m=0;
		for(int j=0;j<D;j++){
			if(bit & (1<<j)){
				tmp+=p[j];
				point+=100*(j+1)*p[j]+c[j];
			}
			else m=j;
		}
		if(point<G){
			if(100*(m+1)*(p[m]-1)<G-point)continue;
			tmp+=min(p[m],(G-point+100*(m+1)-1)/(100*(m+1)));
		}
		ans=min(ans,tmp);
	}
	cout<<ans<<endl;
}

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

#define rep(i, n) for (int i = 0; i < (n); ++i)
#define REP(i,a,b)for(int i=(int)(a);(i)<(int)(b);i++)
#define BTC 380000.0

typedef unsigned long long ull;
typedef long long ll;

const int INF = 1001001001;

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

    vector<int> L(n);
    int maxi = 0;
    rep(i, n) { 
        cin >> L[i];
        maxi = max(maxi, L[i]);
    }

    int sum = 0; int count = 0;
    rep(i, n) { 
        if (L[i] != maxi || count)
        {
            /* code */
            sum += L[i];
        }
        else count++;
    }
    cout << ((maxi < sum) ? "Yes" : "No") << endl;
}

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

int main()
{
    ll n;
    cin >> n;
    vector<ll> a(n);
    vector<ll> kosu(n);
    rep(i, n)
    {
        cin >> a.at(i);
        kosu.at(a.at(i) - 1)++;
    }

    ll sum = 0;
    rep(i, n)
    {
        sum += kosu.at(i) * (kosu.at(i) - 1) / 2;
    }

    for (int k = 0; k < n; k++)
    {
        ll b ;
        b = sum + (kosu.at(a.at(k)-1)-1)*(kosu.at(a.at(k)-1)-2)/2 -(kosu.at(a.at(k)-1))*(kosu.at(a.at(k)-1)-1)/2 ;
        cout << b << endl ;
    }
}

Measured memory_bytes: 6404
def main():
    N = int(input())
    A = list(map(int, input().split()))
    R = [A[0]]
    for i in range(1, N):
        R.append(R[-1]+A[i])
    ans = 2*(10**9)
    for i in range(N-1):
        x = R[i]
        y = R[N-1] - R[i]
        ans = min(ans, abs(x-y))
    print(ans)


if __name__ == "__main__":
    main()


Measured memory_bytes: 23792