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

typedef long long int ll;
typedef long double ld;
typedef vector<ll> vi;
typedef vector<string> vs;
typedef pair<ll,ll> P;
typedef vector<P> vp;
#define REP(i,n) for(int i=0;i<n;i++)
#define FOR(i,m,n) for(int i=m;i<n;i++)
#define REPR(i,n) for(int i=n-1;i>=0;i--)
#define FORR(i,n,m) for(int i=n-1;i>=m;i--)
#define ARR(array) for(int i=0;i<array.size();i++)
#define all(in) (in).begin(),(in).end()
#define ALL(in,K) (in),(in)+(K)

#define INF 1e18
#define MOD 1000000007
#define SIZE 10005
#define PI 	3.14159265358979323846

ll gcd(ll a, ll b) { return b ? gcd(b, a%b) : a; } //最大公約数
ll lcm(ll a, ll b) { return a/gcd(a, b)*b; } //最小公倍数

ll input(){
  ll a;
  cin >> a;
  return a;
}

int main(){
  int a,b;
  cin >> a >> b;
  cout << (a+b+1)/2 << endl;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
      // 準備
      Scanner sc = new Scanner(System.in);
      int d = sc.nextInt();
      int t = sc.nextInt();
      int s = sc.nextInt();

      if(d <= t*s)
        System.out.println("Yes");
      else
        System.out.println("No");

    }
}

Measured memory_bytes: 35868
import scala.io.StdIn._

object Main extends App {

  val Array(n,k) = readLine().split(" ").map(_.toInt)

  def solve() = {
    (1 to n).foldLeft(0D) { (acc, i) =>
      acc + calcProbability(i)
    }
  }

  def calcProbability(i: Int): Double = {
    var score = i
    var cnt = 0
    while(score < k) {
      score *= 2
      cnt += 1
    }
    Math.pow(1.toDouble/2, cnt) * 1.toDouble / n
  }

  println(solve())

}



Measured memory_bytes: 56144
import java.util.*;

public class Main{

    public static void main(String args[]){

        // スキャナーの宣言
        Scanner sc = new Scanner(System.in);
        // 整数の入力
		int a = sc.nextInt();
        // スペース区切りの整数の入力
        int b = sc.nextInt();
        int ans;
        if(b <= 1) ans = 0;
        else ans = a - b;
        // 出力
        System.out.println(ans);

    }

}


Measured memory_bytes: 23764
#include<bits/stdc++.h>
    using namespace std;
    int main(){
    	string s,t;
    	cin>>s>>t;
    	for(int i=0;i<s.size();i++){
    		if(s[i]!=t[i]){
    			cout<<"No"<<endl;
    			return(0);
    		}
    	}
    	cout<<"Yes"<<endl;
        return(0);
    }

Measured memory_bytes: 3596
#include<bits/stdc++.h>
#define ll long long 
#define ld long double
#define vl vector
#define pb push_back
#define ff first
#define ss second
using namespace std;

int main()
{
    ll n,m,i,a=0,b=0,k;
    cin>>n;
    while(1)
    {
        ll flag=0;
        for(i=2;i*i<=n;i++) 
        {
            if(n%i==0 && i!=n)
            {
                flag=1;
                break;
            }
        }
        if(flag==0) break;
        n++;
    }
    cout<<n;
}

Measured memory_bytes: 3620
h, w = map(int, input().split())
s = [list(input()) for _ in range(h)]

U = [[0 for _ in range(w)] for _ in range(h)]
D = [[0 for _ in range(w)] for _ in range(h)]
L = [[0 for _ in range(w)] for _ in range(h)]
R = [[0 for _ in range(w)] for _ in range(h)]

for i in range(h):
    for j in range(w):
        if s[i][j] == "#":
            U[i][j] = 0
            L[i][j] = 0
        else:
            if i == 0:
                U[i][j] = 1
            else:
                U[i][j] = U[i - 1][j] + 1
            if j == 0:
                L[i][j] = 1
            else:
                L[i][j] = L[i][j - 1] + 1


for i in reversed(range(h)):
    for j in reversed(range(w)):
        if s[i][j] == "#":
            D[i][j] = 0
            R[i][j] = 0
        else:
            if i == h-1:
                D[i][j] = 1
            else:
                D[i][j] = D[i + 1][j] + 1
            if j == w-1:
                R[i][j] = 1
            else:
                R[i][j] = R[i][j + 1] + 1

ans = 0
for i in range(h):
    for j in range(w):
        ans = max(ans, U[i][j] + D[i][j] + L[i][j] + R[i][j] - 3)

print(ans)

Measured memory_bytes: 364136
n,t = map(int,input().split())
ab = [list(map(int,input().split())) for _ in range(n)]
ab.sort() # 食べるのが早い順にソート

# ナップザック問題に落とし込む
dp = [[0 for i in range(t+1)]for j in range(n+1)]

for i in range(n):
    ti,vi = ab[i]
    for j in range(t+1):
        # 食べたほうがよい(t秒以内かつ満足度が上がるならば)
        if j + ti <= t:
            dp[i+1][j+ti] = max(dp[i+1][j+ti],dp[i][j]+vi)
        # 食べなかった場合の最高値を更新
        dp[i+1][j] = max(dp[i][j],dp[i+1][j])

ma = 0

for i in range(n):
    # 最後にi番目の皿を食べることができる
    ma = max(ma,dp[i][t-1]+ab[i][1])

print(ma)

Measured memory_bytes: 154516
#include <bits/stdc++.h>
using namespace std;
#define REP(i,a,n) for(int i=(a); i<(int)(n); i++)
#define rep(i,n) REP(i,0,n)
#define FOR(it,c) for(__typeof((c).begin()) it=(c).begin(); it!=(c).end(); ++it)
#define ALLOF(c) (c).begin(), (c).end()
typedef long long ll;
typedef unsigned long long ull;


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

  int now = N;
  vector<int> ret;
  while(now > 0){
    int mn = now;
    REP(i,1,M+1){
      if(now-i < 0) continue;
      if(S[now-i] == '0'){
        mn = now-i;
      }
    }
    if(mn == now){
      ret.clear();
      break;
    }
    ret.push_back(now - mn);
    now = mn;
  }

  if(ret.size() == 0){
    cout << -1 << endl;
  }else{
    reverse(ALLOF(ret));
    rep(i,ret.size()){
      if(i>0) cout << " ";
      cout << ret[i];
    }
    cout << endl;
  }
  
  return 0;
}


Measured memory_bytes: 1144
def readinput():
    n=int(input())
    return n

def main(m):
    n=m%10
    if (n==3):
        return 'bon'
    elif (n==0 or n==1 or n==6 or n==8):
        return 'pon'
    else:
        return 'hon'

if __name__=='__main__':
    n=readinput()
    ans=main(n)
    print(ans)


Measured memory_bytes: 9172
#include <stdio.h>


int main(){
	int a, b, i;
	scanf("%d %d", &a, &b);
	if(a>b){
		for(i=0; i<a; ++i)
			printf("%d", b);
	} else {
		for(i=0; i<b; ++i)
			printf("%d", a);
	}
	printf("\n");
	return 0;
	
}

Measured memory_bytes: 128
#include<bits/stdc++.h>
using namespace std;
int main(void)
{
	int a[10];
	for(int i=0;i<5;i++)
		cin>>a[i];
	for(int i=0;i<5;i++)
		if(a[i]==0)
		{
			cout<<i+1;
			return 0;
		}
} 

Measured memory_bytes: 3628
#include <bits/stdc++.h>
using namespace std;
#pragma GCC optimize("Ofast")
#define all(x) (x).begin(),(x).end()
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define REP(i, m, n) for(int i = m; i < n; i++)
#define SORT(v) sort(all(v))
#define REV(v) sort((v).begin(), (v).end(), greater<int>())
#define INF INT_MAX
#define MOD 1000000007
#define fcout cout << fixed << setprecision(15)
typedef long long ll;
typedef pair<int, int> P;
int gcd(int a,int b){return b?gcd(b,a%b):a;};
int lcm(int a,int b){return a * b / gcd(a, b);};
int mod(int a,int b){return (a+b-1)/b;};
int month[12] = {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
template<typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val){std::fill( (T*)array, (T*)(array+N), val );};
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;};



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

  int n;
  cin >> n;
  int a[n], b[n], c[n];
  rep(i, n) cin >> a[i];
  rep(i, n) cin >> b[i];
  rep(i, n - 1) cin >> c[i];
  int ans = 0;
  rep(i, n) {
    ans += b[a[i] - 1];
    if(i && a[i] == a[i - 1] + 1) ans += c[a[i] - 2];
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
COUNT = gets.to_i
array = readlines.map(&:chomp)

def run(array)
  check_uniqueness(array) && check_order(array) ? :Yes : :No
end

def check_uniqueness(array)
  array.uniq.size == array.size
end

def check_order(array)
  array.map.with_index(1){|a,idx| a[-1] == array[idx][0] if idx < COUNT}.compact.all?
end

puts run(array)

Measured memory_bytes: 1788
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0, i##_len = (n); i < i##_len; ++i)
#define rep2(i, x, n) for (int i = x, i##_len = (n); i < i##_len; ++i)
#define all(n) begin(n), end(n)
typedef long long ll;

int main()
{
  string s;
  cin >> s;
  rep(i, s.size()) if (i % 2 == 0) cout << s[i];
  cout << endl;
}

Measured memory_bytes: 512
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <climits>
#include <cfloat>
#include <ctime>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <memory>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <sstream>
#include <complex>
#include <stack>
#include <queue>
#include <numeric>
#include <list>

using namespace std;

#ifdef _MSC_VER
#define __typeof__ decltype
template <class T> int __builtin_popcount(T n) { return n ? 1 + __builtin_popcount(n & (n - 1)) : 0; }
#endif

#define foreach(it, c) for (__typeof__((c).begin()) it=(c).begin(); it != (c).end(); ++it)
#define all(c) (c).begin(), (c).end()
#define rall(c) (c).rbegin(), (c).rend()
#define CLEAR(arr, val) memset(arr, val, sizeof(arr))

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

template <class T> void max_swap(T& a, const T& b) { a = max(a, b); }
template <class T> void min_swap(T& a, const T& b) { a = min(a, b); }

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

const double PI = acos(-1.0);
const int dx[] = { 0, 1, 0, -1 };
const int dy[] = { 1, 0, -1, 0 };


struct Edge
{
	int to, cost;
	Edge(int to, int cost)
		: to(to), cost(cost) {}
};
int n, m;
vector<Edge> edge[128];
bool spanning(int mini, int maxi)
{
	bool used[128];
	fill_n(used, n, false);
	queue<int> q;
	used[0] = true;
	q.push(0);
	while (!q.empty())
	{
		int v = q.front(); q.pop();
		foreach (e, edge[v])
		{
			if (!used[e->to] && mini <= e->cost && e->cost <= maxi)
			{
				q.push(e->to);
				used[e->to] = true;
			}
		}
	}
	return count(used, used + n, true) == n;
}
int main()
{
	while (cin >> n >> m, n)
	{
		vector<int> w;
		rep (i, n)
			edge[i].clear();
		rep (i, m)
		{
			int a, b, t;
			cin >> a >> b >> t;
			--a, --b;
			edge[a].push_back(Edge(b, t));
			edge[b].push_back(Edge(a, t));
			w.push_back(t);
		}
		sort(all(w));
		w.erase(unique(all(w)), w.end());

		const int INF = 1 << 26;
		int res = INF;
		for (int i = 0; i < w.size(); ++i)
		{
			int low = i - 1, high = w.size();
			while (low + 1 < high)
			{
				int mid = (low + high) / 2;
				if (spanning(w[i], w[mid]))
					high = mid;
				else
					low = mid;
			}
			if (high < w.size())
				min_swap(res, w[high] - w[i]);
		}

		if (res == INF)
			res = -1;
		cout << res << endl;
	}
}

Measured memory_bytes: 1068
#include<bits/stdc++.h>
using namespace std;
#define l long
#define ll long long
#define nitro ios_base::sync_with_stdio(false);cin.tie(0);
#define vi vector<int>
#define pub push_back
#define puf push_front
#define pob pop_back
#define pof pop_front
#define PI 3.141592653589793238
#define endl '\n'
int main()
{
    nitro
    l int n;cin>>n;
    set<string>s;
    string st;
    for(l int i=0;i<n;i++)
    {
        cin>>st;
        s.insert(st);
    } cout<<s.size();
    return 0;
}





Measured memory_bytes: 19204
n=int(input())

count=0
c_list=[1]

for i in range(n):
    d1, d2=map(int, input().split())
    if d1==d2:
        count+=1
        c_list.append(count)
        #print(c_list)
    else:
        count=0
        
if max(c_list)>=3:
    print("Yes")
else:
    print("No")

Measured memory_bytes: 9172
#include <cmath>
#include <cstdio>
#include<string>
#include <vector>
#include <iostream>
#include<bits/stdc++.h>
#include <algorithm>
#define pb push_back
#define ll long long
#define mk make_pair
#define mod 200000
using namespace std;



int main()
{
    int n,m;
    cin>>n>>m;
    int x[n];
    for(int i=1;i<n;i++)x[i]=0;
    
    vector<int>u;
    for(int i=0;i<m;i++)
    {
        int a,b;
        cin>>a>>b;
        if(a==1)u.pb(b);
        if(b==n)x[a]=1;
    }
    sort(u.begin(),u.end());
    
    for(int i=0;i<u.size();i++){
        if(x[u[i]]==1){
            cout<<"POSSIBLE"<<endl;
            return 0;
        }
        }
    cout<<"IMPOSSIBLE"<<endl;
   
    
}

Measured memory_bytes: 1660
//ABC146A.cpp
#import <iostream>
#import <string>
using namespace std;
int main(){
	int ans;
	string S;
	cin>>S;
	if(S=="SAT")ans=1;
	else if(S=="FRI")ans=2;
	else if(S=="THU")ans=3;
	else if(S=="WED")ans=4;
	else if(S=="TUE")ans=5;
	else if(S=="MON")ans=6;
	else if(S=="SUN")ans=7;
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> lpair;
const ll MOD = 1e9 + 7;
#define rep(i,m,n) for(ll i = (m); i < (n); i++)
#define rrep(i,m,n) for(ll i = (m); i >= (n); i--)
#define print(x) cout << (x) << endl;
#define print2(x,y) cout << (x) << " " << (y) << endl;
#define printa(x,n) for(ll i = 0; i < n; i++){ cout << (x[i]) << " \n"[i == n-1];}
#define INF (1e18)

int main(){   
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll N;
    ll A[100010];
    cin >> N;
    rep(i,0,N) cin >> A[i];
    ll B[100010];
    memcpy(B, A, sizeof(A));
    sort(B, B+N);
    map<ll,ll> mp;
    rep(i,0,N){
        mp[B[i]] = i;
    }
    rep(i,0,N){
        A[i] = mp[A[i]];
    }
    // printa(A,N);
    ll ans = 0;
    rep(i,0,N){
        if(abs(A[i] - i) % 2 != 0){
            ans++;
        }
    }
    ans /= 2;
    print(ans);
}


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

    int minC = 1001;

    for (int i = 0; i < n; i++) {
        int c, t;
        cin >> c >> t;

        if (t <= T && c < minC) {
            minC = c;
        }
    }

    if (minC == 1001) {
        cout << "TLE" << endl;
    } else {
        cout << minC << endl;
    }

    return 0;
}

Measured memory_bytes: 256
#include <array>
#include <iostream>
#include <map>
#include <vector>

//! @brief Regard Map of {key, count} to record count of key, initialize with 0 if key not found, then add
//! adding to key's count.
template <typename Map, typename Value = typename Map::mapped_type>
Value &
MapAddCount(Map &map, typename Map::key_type key, Value adding)
{
    auto [it, flag] = map.try_emplace(key, 0);
    (void)flag;
    auto &count = it->second;
    count += adding;
    return count;
}

inline constexpr std::size_t BufferSize = 1024;

int
main()
{
    std::ios::sync_with_stdio(false);

    std::vector<int> bufferA;
    bufferA.resize(BufferSize, 0);
    std::vector<int> bufferB;
    bufferB.resize(BufferSize, 0);
    std::vector<int> bufferC;
    bufferC.resize(BufferSize, 0);

    std::vector<int> values;

    std::size_t valueCount;
    std::cin >> valueCount;

    auto usingValuesPtr = &bufferA;
    if (valueCount>BufferSize)
    {
        values.resize(valueCount);
        usingValuesPtr = &values;
    }
    auto &usingValues = *usingValuesPtr;

    for (std::size_t i = 0; i<valueCount; ++i)
    {
        std::cin >> usingValues[i];
    }

    std::size_t operationCount;
    std::cin >> operationCount;

    std::vector<int> oldValues;
    std::vector<int> newValues;

    auto usingOldValuesPtr = &bufferB;
    auto usingNewValuesPtr = &bufferC;
    if (operationCount>BufferSize)
    {
        oldValues.resize(operationCount);
        newValues.resize(operationCount);
        usingOldValuesPtr = &oldValues;
        usingNewValuesPtr = &newValues;
    }
    auto &usingOldValues = *usingOldValuesPtr;
    auto &usingNewValues = *usingNewValuesPtr;

    for (std::size_t i = 0; i<operationCount; ++i)
    {
        std::cin >> usingOldValues[i];
        std::cin >> usingNewValues[i];
    }

    long long sum = 0;
    std::map<int, int> valueCounts;
    for (auto &value : usingValues)
    {
        MapAddCount(valueCounts, value, 1);
        sum += value;
    }

    for (std::size_t i = 0; i<operationCount; ++i)
    {
        auto oldValue = usingOldValues[i];
        auto newValue = usingNewValues[i];

        auto count = MapAddCount(valueCounts, oldValue, 0);

        sum -= static_cast<long long>(oldValue)*count;
        sum += static_cast<long long>(newValue)*count;

        MapAddCount(valueCounts, oldValue, -count);
        MapAddCount(valueCounts, newValue, count);
        std::cout << sum << "\n";
    }
}


Measured memory_bytes: 8952
#include<bits/stdc++.h>
#define sci(x) scanf("%d",&(x))
using namespace std;	
vector<int> a[500];
int main()
{
	int n,m,q;
	scanf("%d%d%d",&n,&m,&q);
	for(int i=0;i<m;i++){
		int l,r;
		sci(l),sci(r);
		a[l].push_back(r);
	}		
 	for(int i=1;i<=500;i++){
 		sort(a[i].begin(),a[i].end());
	 }
	 for(int i=1;i<=q;i++){
	 	int ll,rr;
	 	int ans=0;
	 	sci(ll),sci(rr);
	 	for(int j=ll;j<=rr;j++){
	 		ans+=upper_bound(a[j].begin(),a[j].end(),rr)-a[j].begin();	
		}
		printf("%d\n",ans);
	 }
}

Measured memory_bytes: 2176
#include<stdio.h>
#include<string.h>

int main()
{
	int n;
	scanf("%d",&n);
	char ch;
	ch=getchar();
	int i;
	char s1[128],s2[128];
	scanf("%s%s",s1,s2);
	for (i=0;i<n;i++)
	{
		putchar(s1[i]); 
		putchar(s2[i]);
	}
	return 0;
}

Measured memory_bytes: 128
#!/usr/bin/env python

from collections import deque
import itertools as it
import sys
import math

sys.setrecursionlimit(1000000)

INF = 10 ** 18

H, W = map(int, raw_input().split())
h, w = map(int, raw_input().split())

print (H - h) * (W - w)

Measured memory_bytes: 2812
#include<stdio.h>

int main()
{
	int a[100],b[100],c[100],d[100],e[100],f[100],count=0,i;
	double x[100],y[100];
	while(scanf("%d %d %d %d %d %d",&a[count],&b[count],&c[count],&d[count],&e[count],&f[count]) != EOF){
		count++;
	}
	for(i=0;i<count;i++){
		if(d[i]!=0){
			y[i]=1.0*(c[i]*d[i]-a[i]*f[i])/(b[i]*d[i]-a[i]*e[i]);
			x[i]=(1.0*(-e[i])/d[i]*y[i])+(1.0*f[i]/d[i]);
		}else{
			y[i]=1.0*f[i]/e[i];
			x[i]=1.0*(c[i]*e[i]-b[i]*f[i])/(a[i]*e[i]);
		}

		printf("%.3f %.3f\n",x[i],y[i]);
	}

	return 0;
}

Measured memory_bytes: 640
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);

		String result = "";
		for (int i = 0; i < 3; i++) {
			result += sc.next().charAt(i);
		}

		System.out.println(result);

		sc.close();
	}

}




Measured memory_bytes: 21332
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <math.h>
#define MOD 1000000007
typedef long long ll;
using namespace std;

int main(){
  ll n,k;
  cin>>n>>k;
  ll a[n+1]={};
  ll b[n+1]={};
  ll ans=0;
  for(int i=0;i<n;i++){
    cin>>a[i]>>b[i];
    if((a[i]|k)==k) ans+=b[i];
  }

  for(int i=30;i>=0;i--){
    if(((1<<i)&k)==0) continue;
    ll x=(k/(1<<i)-1)*(pow(2,i))+pow(2,i)-1;
    //cout<<x<<endl;
    ll tmp=0;
    for(int i=0;i<n;i++){
      if((a[i]|x)==x) tmp+=b[i];
    }
    ans=max(ans,tmp);
  }

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


Measured memory_bytes: 1792
def solve():
    n = int(input())
    v = list(map(int, input().split()))
    c = list(map(int, input().split()))
    ans = 0
    for i in range(n):
        if v[i] > c[i]:
            ans += v[i] - c[i]
    print(ans)


if __name__ == '__main__':
    solve()


Measured memory_bytes: 3060
/**
 *  http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=ALDS1_2_A
 */
#include <iostream>
#include <sstream>
#include <vector>
#include <algorithm>

using namespace std;

void
printv(const vector<int> a)
{
    stringstream ss;
    for (auto it = a.cbegin(); it != a.cend(); it++) {
        if (it != a.begin()) {
            ss << ' ';
        }
        ss << *it;
    }
    cout << ss.str() << endl;
}

void
bubblesort(const vector<int> a)
{
    vector<int> work(a);

    bool flag = true;
    int count = 0;
    while (flag) {
        flag = false;
        for (auto it = work.rbegin(); it != work.rend() - 1; it++) {
            auto nit = next(it);
            if (*it < *nit) {
                iter_swap(nit, it);
                flag = true;
                count++;
            }
        }
    }
    printv(work);
    cout << count << endl;
}

int
main()
{
    int N;
    cin >> N; cin.ignore();

    vector<int> A(N);
    for (int i = 0; i < N; i++) {
        cin >> A[i]; cin.ignore();
    }
    bubblesort(A);

    return 0;
}

Measured memory_bytes: 3164
#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=a;i<b;i++)
#pragma GCC optimize ("-O3")
using namespace std; void _main(); int main() { cin.tie(0); ios::sync_with_stdio(false); _main(); }
//---------------------------------------------------------------------------------------------------
const double EPS = 1e-8;
const double INF = 1e12;
#define PI 2*acos(0.0)
typedef complex<double> P;
namespace std {
    bool operator < (const P& a, const P& b) { return real(a) != real(b) ? real(a) < real(b) : imag(a) < imag(b); } 
    bool operator == (const P& a, const P& b) { return abs(real(a) - real(b)) < EPS && abs(imag(a) - imag(b)) < EPS; }
    P operator / (const P& a, const double& b) { return P(real(a) / b, imag(a) / b); }
}
double cross(const P& a, const P& b) { return imag(conj(a)*b); }
double dot(const P& a, const P& b) { return real(conj(a)*b); }
struct L : public vector<P> { L() {} L(const P &a, const P &b) { push_back(a); push_back(b); } };
typedef vector<P> G;
struct C { P p; double r; C() {} C(const P &p, double r) : p(p), r(r) {} };
int ccw(P a, P b, P c) {
	b -= a; c -= a;
	if (cross(b, c) > 0)   return +1;       // counter clockwise
	if (cross(b, c) < 0)   return -1;       // clockwise
	if (dot(b, c) < 0)     return +2;       // c--a--b on line
	if (norm(b) < norm(c)) return -2;       // a--b--c on line
	return 0;
}
P rotate(P vec, double ang) {
    double x = real(vec), y = imag(vec);
    return P(x * cos(ang) - y * sin(ang), x * sin(ang) + y * cos(ang));
}
/*---------------------------------------------------------------------------------------------------
????????????????????????????????? ??§?????§  
??????????????? ??§?????§ ???????´<_??? ?????? Welcome to My Coding Space!
???????????? ??? ?´_???`??????/??? ???i     
?????????????????????????????? ???  |???|     
????????? /?????? /??£??£??£??£/??????|  
??? ???_(__??????/???    ???/ .| .|????????????  
??? ????????????/????????????/??????u??????  
---------------------------------------------------------------------------------------------------*/





void dump(P x) {
    printf("%.10f %.10f\n", real(x), imag(x));
}
void rec(int dpt, P a, P b) {
    if (0 < dpt) {
        P c, d, e;
        c = a + (b - a) / 3.0;
        d = c + rotate((b - a) / 3.0, PI / 3);
        e = a + (b - a) / 1.5;

        rec(dpt - 1, a, c);
        rec(dpt - 1, c, d);
        rec(dpt - 1, d, e);
        rec(dpt - 1, e, b);
    } else dump(b);
}
//---------------------------------------------------------------------------------------------------
void _main() {
    P A(0, 0), B(100, 0);
    dump(A);
    int N; cin >> N;
    rec(N, A, B);
}

Measured memory_bytes: 3136
#include<bits/stdc++.h>
using namespace std;using ll=long long;using vi=vector<int>;using vvi=vector<vi>;using vl=vector<ll>;using vvl=vector<vl>;using P=pair<int,int>;using PL=pair<ll,ll>;using vp=vector<P>;using vpl=vector<PL>;
template<typename T>constexpr auto inf=numeric_limits<T>::max()/2;constexpr int INF=inf<int>,MOD=998244353;constexpr ll LINF=inf<ll>;
#define _ol3(_1,_2,_3,name,...)name
#define _rep(i,n)_repi(i,0,n)
#define _repi(i,a,b)for(int i=a,i##_l=(b);i<i##_l;++i)
#define REP(...)_ol3(__VA_ARGS__,_repi,_rep,)(__VA_ARGS__)
#define REPR(i,n)for(int i=n-1;i>=0;--i)
#define REPA(i,v)REP(i,(v).size())
#define all(v)(v).begin(),(v).end()
#define rall(v)(v).rbegin(),(v).rend()
#define bit(n)(1ll<<(n))
#define F first
#define S second
#define endl '\n'
#define cho(n,a,b)cout<<((n)?a:b)<<endl
void YES(int n){cho(n,"YES","NO");}void Yes(int n){cho(n,"Yes","No");}void Poss(int n){cho(n,"Possible","Impossible");}
void _print(ostream&){}template<class T,class...U>void _print(ostream&s,const T&t,const U&...u){s<<t<<(sizeof...(u)?' ':'\n');_print(s,u...);}
template<class...T>void print(const T&...t){_print(cout,t...);}template<class...T>void dprint(const T&...t){_print(cerr,t...);}
#ifndef LOCAL
struct osd{template<class T>osd&operator<<(const T&t){return*this;}};osd cer_;
#define dprint(...)
#define cerr cer_
#endif
template<class T>bool chmax(T&a,const T&b){bool x=a<b;x?a=b:b;return x;}template<class T>bool chmin(T&a,const T&b){bool x=a>b;x?a=b:b;return x;}
template<class T,class U>ostream&operator<<(ostream&o,const pair<T,U>&p){return o<<p.F<<' '<<p.S;}
template<class T,class U>istream&operator>>(istream&i,pair<T,U>&p){return i>>p.F>>p.S;}
template<class T>class iterable{static false_type c(string v);template<class U>static auto c(U v)->decltype(all(v),true_type());static false_type c(...);public:const static bool value=decltype(c(declval<T>()))::value;};
template<class T,typename=enable_if_t<iterable<T>::value>>ostream&operator<<(ostream&o,const T&v){for(auto&&i:v)o<<i<<' ';return o;}
template<class T>istream&operator>>(istream&i,vector<T>&v){for(T&j:v)i>>j;return i;}
template<class T>vector<T>&operator<<(vector<T>&v,const T&t){v.push_back(t);return v;}
template<class T>set<T>&operator<<(set<T>&v,const T&t){v.insert(t);return v;}
template<class T>multiset<T>&operator<<(multiset<T>&v,const T&t){v.insert(t);return v;}

inline ll square(ll a){a%=MOD;return (a*a)%MOD;}
ll powa(ll a,ll b){
    a%=MOD;
    b%=MOD-1;
    if(b==0)return 1;
    if(b==1)return a;
    if(b%2){
        return (square(powa(a,b/2)%MOD)*a)%MOD;
    }else{
        return square(powa(a,b/2)%MOD);
    }
}

int main(){
    cin.tie(0);ios::sync_with_stdio(0);
    cout<<setprecision(10);
    int n;
    cin>>n;
    vi d(n);
    cin>>d;
    if(d[0]!=0){
        cout<<0<<endl;
        return 0;
    }
    vi m(n);
    REP(i,n){
        ++m[d[i]];
    }
    if(m[0]!=1){
        cout<<0<<endl;
        return 0;
    }
    ll ans=1;
    REP(i,1,n){
        //cerr<<cm[i-1]<<' ';
        //if(m[i]==0)break;
        (ans*=powa(m[i-1],m[i]))%=MOD;
        dprint(m[i-1],'^',m[i],'=',powa(m[i-1],m[i]));
    }
    //cerr<<endl;
    cout<<ans<<endl;
}


Measured memory_bytes: 1024
/*

 Remember, Hope is a good thing... May be the best of things... And No Good thing ever Dies !!!

*/
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define IOS ios::sync_with_stdio(0); cout.tie(0);
#define endl "\n"
#define MOD 1000000007
const ll inf=(1LL<<60)-1;
int dx[]= {-1,1,0,0};
int dy[]= {0,0,-1,1};
void solve()
{
    ll k;
    string s,s1;
    s1="...";
    cin>>k>>s;
    if(s.size()>k)
    {
        for(int i=0;i<k;i++)
            cout<<s[i];
        cout<<s1;
    }
    else
        cout<<s<<endl;

}
int main()
{
    IOS;
    // ll t;
    //cin>>t;
    //while(t--)
    solve();
    return 0;
}


Measured memory_bytes: 3636
import math
import sys
MAX_INT = int(10e9)
MIN_INT = -MAX_INT
mod = 1000000007
sys.setrecursionlimit(1000000000)
def IL(): return list(map(int,input().split()))
def SL(): return input().split()
def I(): return int(sys.stdin.readline())
def S(): return input()

N = I()
a = IL()
b = IL()

ans = 0
for i in range(N):
    if a[i] <= b[i]:
        ans += a[i]
        b[i] -= a[i]
        if a[i+1] <= b[i]:
            ans += a[i+1]
            a[i+1] = 0
        else:
            ans += b[i]
            a[i+1] -= b[i]
    else:
        ans += b[i]

print(ans)

Measured memory_bytes: 19244
/*
 * A.cpp
 *
 *  Created on: 2017/06/18
 *      Author: aihara
 */

#include<bits/stdc++.h>
#define MYDEBUG
#ifdef MYDBUG
#define dbp(x) cout<<#x<<": "<<x<<endl;
#else
#define dbp(x)
#endif
#define ll long long
#define rep(i,from,to) for(int i=from; i<to; ++i)
#define REP(i,from,to) for(int i=from; i<=to; ++i)

using namespace std;

int n;
int y, m, d;
int total = 196470;

void solve() {
	cin >> n;
	rep(test_case, 0, n)
	{
		cin >> y >> m >> d;
		//??´????????????
		int ans = 0;
		rep(yi, 1, y)
		{
			if (yi % 3 == 0) {
				ans += 10 * 20;
			} else {
				ans += 5 * 20 + 5 * 19;
			}
		}
		//???????????????
		rep(mi, 1, m)
		{
			if (y % 3 == 0 || mi % 2 != 0) {
				ans += 20;
			} else {
				ans += 19;
			}
		}
		ans += d - 1;
		cout << total - ans << endl;
	}
}

int main() {
	solve();
}

Measured memory_bytes: 3060
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(c) (c).begin(), (c).end()
using namespace std;
typedef long long ll;
typedef vector<int> vi;
template<class T> inline bool chmax( T &a, const T &b ) { return b>a ? a=b,true : false; }
template<class T> inline bool chmin( T &a, const T &b ) { return b<a ? a=b,true : false; }

int main() {
  int n;
  cin >> n;
  vector<ll> a(n);
  ll sum1=0;
  rep(i,n) {
    cin >> a[i];
    sum1+=a[i];
  }
  ll sum2=0,ans=1e18;
  rep(i,n-1) {
    sum2+=a[i];
    sum1-=a[i];
    chmin(ans,abs(sum2-sum1));
  }
  cout << ans << '\n';
  return 0;
}


Measured memory_bytes: 1792
#include <iostream>
#include <vector>
#include<list>
#include <algorithm>
#include <string>
#include <math.h>
#include<map>
#include <utility>

#include<queue>
using namespace std;
#define REP(i,k,n) for(int i=k;i<n;i++)
 
#define INF (1e9)
typedef long long unsigned int ll;
#define SIZE_OF_ARRAY(array) (sizeof(array)/sizeof(array[0]))
#define MOD 1000000007

template<typename T>
int vector_finder(std::vector<T> vec, T number) {
  auto itr = std::find(vec.begin(), vec.end(), number);
  size_t index = std::distance( vec.begin(), itr );
  if (index != vec.size()) { // 発見できたとき
    return 1;
  }
  else { // 発見できなかったとき
    return 0;
  }
}

template<typename T>
T gcd(T a,T b){
	if(b>0){
		return gcd(b, a % b);
	}else{
		return a;
	}
}

template<typename T>
T lcm(T a,T b){
	T g = gcd(a, b);
	return a * b / g;
}

void clear( std::queue<pair<int,int> > &q )
{
   std::queue<pair<int,int> > empty;
   std::swap( q, empty );
}

int N,M;
int c[100][100];
int main()
{
	cin>>N>>M;
	REP(i,0,N){
		REP(j,0,N){
			if(i==j){
				c[i][j]=0;
			}else{
			c[i][j]=INF;
			}
		}
	}
	int a[M],b[M],cc[M];

	REP(i,0,M){

		cin>>a[i]>>b[i]>>cc[i];
		a[i]--;b[i]--;
		c[a[i]][b[i]]=cc[i];
		c[b[i]][a[i]]=cc[i];
	}

	REP(k,0,N){
		REP(i,0,N){
			REP(j,0,N){
				if(c[i][j]>c[i][k]+c[k][j]){
					c[i][j]=c[i][k]+c[k][j];
				}
			}
		}
	}
	int ans=0;
	REP(i,0,M){
		bool flag=false;
		REP(s,0,N){
			REP(t,0,N){
				if(c[s][a[i]]+cc[i]+c[b[i]][t]==c[s][t]){
					flag=true;
				}
			}
		}
		if(!flag){
			ans++;
		}
	}

	cout<<ans<<endl;
	
	
	

	return 0;
}

Measured memory_bytes: 256
import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {
        Scanner sc=new Scanner(System.in);
        int a = sc.nextInt();
        System.out.print(a/3600);
        System.out.print(":");
        System.out.print((a%3600)/60);
        System.out.print(":");
        System.out.println((a%3600)%60);
        
        
        
    }
}



Measured memory_bytes: 26332
#include "bits/stdc++.h"
using namespace std;
#define rep(i,n) for(ll i=0;i<n;i++)
#define REP(i,a,n) for(ll i=a;i<n;i++)
#define ALL(s) s.begin(),s.end()
#define P pair<ll,ll>
#define vl vector<ll>
#define vl vector<ll>
#define vvl vector<vector<ll>>
#define vvl vector<vector<ll>>
#define print(n) cout<<n<<endl
const int M=100010;
const int inf=1000000007;
const long long INF=1000000000000000007;
using ll=long long;
int dx[4]={-1,0,1,0},dy[4]={0,-1,0,1};

int main(){
	int n,q,EBY[1000],WY[1000];
	string s[1000];
	while(1){
		cin>>n>>q;
		if(n==0)break;
		int ans=-1;
		rep(i,n)cin>>s[i]>>EBY[i]>>WY[i];
		int Y;
		rep(i,q){
			bool ok=false;
			cin>>Y;
			rep(j,n)
				if(WY[j]-EBY[j]<Y&&Y<=WY[j])
					print(s[j]<<" "<<Y+EBY[j]-WY[j]),ok=true;
			if(!ok)print("Unknown");
		}
	}
}



Measured memory_bytes: 3260
#include <bits/stdc++.h> 
#define int long long
#define quickie ios_base::sync_with_stdio(false); cin.tie(NULL);
#define rep(i, a, b) for(int i=a; i<b; i++)
#define rep1(i, a, b) for(int i=a; i<=b; i++)
#define repp(i, a, b) for(int i=b-1; i>=a; i--)
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define SZ(x) ((int)(x).size())
#define db double
#define mi map<int, int>
#define mc map<char, int>
#define ms map<string, int>
#define vi vector<int>
#define qi queue<int>
#define MI(x) power(x, mod-2)
#define test int t; cin >> t;
#define mod 1000000007LL
//#define mod 998244353 
using namespace std;
int power(int x, int y) ;
int gcd(int a, int b) ;

signed main() {
    quickie
    int n, a, b ;
    cin >> n >> a >> b ;
    int l = (n/(a+b))*a + min(a,(n%(a+b))) ;
    cout << l << endl ;
    
}
 
int power(int x, int y) {
    int res = 1; x %= mod;
    while (y > 0) {
        if (y & 1)
            res = (res*x) % mod;
        y = y>>1;
        x = (x*x) % mod;
    }
    return res%mod;
}
 
int gcd(int a,int b){
    if(a==0) return b;
    return gcd(b%a,a);
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define MAX 252*2
#define NIL 0
struct Node_struct{int k,p, l, r,s;};
typedef struct Node_struct Node;
Node T[MAX];
int D[MAX],H[MAX];

void print(int u){
 printf("node %d: key = %d, ",u,T[u].k);
 if(u!=1)printf("parent key = %d, ",T[u].p);
 if(T[u].l!=NIL)printf("left key = %d, ",T[u].l);
 if(T[u].r!=NIL)printf("right key = %d, ",T[u].r);
 printf("\n");

}

void calcDepth(int u, int p){
 D[u] = p;
 if(T[u].l!=NIL) calcDepth(T[u].l,p+1);
 if(T[u].r!=NIL) calcDepth(T[u].r,p+1);
}

int calcHeight(int u){
    if(u==NIL)return -1;
    int left=calcHeight(T[u].l);
    int right=calcHeight(T[u].r);\
    if(left>right)return H[u]=left+1;
    else return H[u]=right+1;
}

void Postorder(int n){
    if(n==NIL)return;

    Postorder(T[n].l);
    Postorder(T[n].r);
    cout<<" "<<n;

}
void Inorder(int n){
    if(n==NIL)return;

    Inorder(T[n].l);
    cout<<" "<<n;
    Inorder(T[n].r);
}
void Preorder(int n){
    if(n==NIL)return;
    cout<<" "<<n;
    Preorder(T[n].l);
    Preorder(T[n].r);
}

int main(){
  int i, left,right,j,data[MAX];
  int n;
 int id;
 int root = NIL;
 scanf("%d", &n);
 for(i=0; i<=(n+1)*2+2; i++) data[i]=T[i].k=T[i].p = T[i].l = T[i].r =T[i].s= NIL;
 for(i=1; i<=n; i++) scanf("%d", &data[i]);
 for(i=1; i<=n; i++) {
   left=2*i;
   right=2*i+1;
   T[i].k=data[i];
   if(i)T[i].p=data[i/2];
   if(data[left]!=NIL){
     T[i].l=data[left];
     T[left].p=data[i];
   }
   if(data[right]!=NIL){
     T[i].r=data[right];
     T[right].p=data[i];
   }
   if(data[left]!=NIL&&data[right]!=NIL){
     T[left].s=data[right];
     T[right].s=data[left];
   }
 }
 /*
 //根を求める (find the root)
 for(i=0; i<n; i++){
   if(T[i].p == -1) root = i;
 }

//  //それぞれのノードの深さを求める (find depth of each node)
//  calcDepth(root, 0);
//  calcHeight(root);

 //出力 (output)
 cout<<"Preorder"<<endl;
 Preorder(root);
 cout<<endl<<"Inorder"<<endl;
 Inorder(root);
 cout<<endl<<"Postorder"<<endl;
 Postorder(root);
 cout<<endl;
 */
 for(i=1;i<=n;i++)print(i);
 return 0;
}



Measured memory_bytes: 3248
// In His Name

#include <bits/stdc++.h>

#define pb push_back
#define F first
#define S second
#define gcd __gcd
#define int long long
#define ull unsigned long long

using namespace std;

typedef pair<int, int> pii;

const int MAX = 1e5 + 10;
int n, k, a[MAX];
bool dp[MAX], mark[MAX];

main(){
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	cin >> n >> k;
	fill (dp , dp + k + 10 , true);
	for (int i = 0 ; i < n ; i++){
		cin >> a[i];
		mark[a[i]] = true;
		dp[a[i]] = true;
	}
	for (int i = 1 ; i <= k ; i++){
		int ans = 1;
		if (mark[i]){
			continue;
		}
		for (int j = 0 ; j < n ; j++){
			if (i > a[j]){
				ans *= dp[i - a[j]];
			}
		}
		dp[i] = !(ans);
	}
	cout << (dp[k] ? "First" : "Second");
}

Measured memory_bytes: 512
#include <iostream>
#include <algorithm>
#include <vector>
using namespace std;

#define rep(i, n) for(int i = 0; i < (n); ++i)
typedef long long ll;
const ll INF = (1LL << 60)-1;

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

  int n; cin >> n;
  int value[101010][3];
  rep(i, n) rep(j, 3) cin >> value[i][j];
  ll dp[101010][3] = {};
  rep(i, 101010) rep(j, 3) dp[i][j] = -INF;
  rep(i, 3) dp[0][i] = 0;

  rep(i, n) {
    rep(j, 3) {
      rep(k, 3) {
        if(j != k) {
          dp[i+1][k] = max(dp[i+1][k], dp[i][j]+value[i][k]);
        }
      }
    }
  }

  ll ans = -1;
  rep(i, 3) {
    ans = max(ans, dp[n][i]);
  }
  cout << ans << '\n';
  return 0;
}


Measured memory_bytes: 3840
#include <iostream>
#include <cstdio>
#include <cmath>
#include <string>
#include <queue> 
#include <cassert>
#include <cstdlib>
#include <vector>
#include <algorithm>
#include <set>
#include <map>

#define INF 2000000000
#define MOD 1000000007

using namespace std;

int arr[200000];
int n;

int main() {
	long long sum = 0;
	cin >> n;
	for (int i = 0; i < n; i++) {
		cin >> arr[i];
		sum += arr[i];
	}	
	long long ans = INF;
	long long cur = 0;
	for (int i = 0; i < n - 1; i++) {
		cur += arr[i];
		ans = min(ans, abs(cur - sum + cur));
	}
	cout << ans << endl;
	return 0;
}

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

int main(){
    string s;
    int q;
    cin >> s >> q;
    deque<char> Q;
    for(char c : s) Q.push_back(c);
    bool flip = false;
    for(int i = 0;i < q;i++){
        int t;
        cin >> t;
        if(t == 1){
            flip = !flip;
        }else{
            int f;
            char c;
            cin >> f >> c;
            if(flip) f = 3 - f;
            if(f == 1) Q.push_front(c);
            else Q.push_back(c);
        }
    }
    if(flip) reverse(Q.begin(),Q.end());
    string ans;
    for(char c : Q) ans += c;
    cout << ans << endl;
}

Measured memory_bytes: 1412
n = int(input())
A = list(map(int, input().split()))

inf = 10 ** 18

dp = [[-inf] * 3  for _ in range(n + 1)]
k = 1 + n % 2
dp[0][0] = 0
for i in range(n):
    for j in range(k + 1):
        if j < k:
            dp[i + 1][j + 1] = max(dp[i + 1][j + 1], dp[i][j])
        now = dp[i][j]
        if (i + j) % 2 == 0:
            now += A[i]
        dp[i + 1][j] = max(dp[i + 1][j], now)
print(dp[n][k])


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

int gcd(int x, int y) {
	if (x % y == 0)
		return y;
	return gcd(y, x % y);
}

long long lcm(int x, int y) {
	return (long long) x * y / gcd(x, y);
}

long long int num(long long a, int c, int d) {
	return a - a / c - a / d + a / lcm(c, d);
}

int main() {
	long long a, b;
	int c, d;
	cin >> a >> b >> c >> d;
	a--;

	cout << num(b, c, d) - num(a, c, d);
}


Measured memory_bytes: 256
#include <iostream>
#include <fstream>
#include <cmath>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <cstdlib>
#include <cstdio>
#include <string>
#include <cstring>
#include <cassert>
#include <utility>
#include <iomanip>
#include <chrono>
#include <random>
#include <bitset>

using namespace std;

#define sz(x) (int) x.size()
#define unique(x) x.erase(unique(x.begin(), x.end()), x.end())
#define all(a) a.begin(), a.end()
#define sqr(x) ((x) * (x)) 
#define y1 aksjdaskdjksjfksdjf
#define left kdnvldvoiwejifejg
#define right lkdsjflksdjfdjfk
#define prev asdasfsadjkjsdfjs
#define tm aklsjdasjdasjdkdjjf
#define lcm hddalkwjeidjjhasda
#define random_shuffle asdasdd

string s;
int n;
int can;
long long dp[125][2][2][5];

long long calc(int pos, bool started, bool less, int rem) {
  long long &res = dp[pos][started][less][rem];
  if (res != -1) {
    return res;
  }
  res = 0;
  if (pos == n) {
    if (started && rem == 0) {
      res = 1;
    }
    return res;
  }
  int sNum = s[pos] - '0';
  for (int i = 0; i <= 9; i++) {
    if (i != 0 && rem == 0) {
      continue;
    }
    if (!less && i > sNum) {
      continue;
    }
    res += calc(pos + 1, started | (i > 0), less | (i < sNum), rem - (i > 0 ? 1 : 0));
  }

  // cerr << pos << " " << started << " " << less << " " << rem << " " << res << " " << endl;

  return res;
}

int main() { 

  getline(cin, s);
  scanf("%d", &can);
  n = sz(s);

  memset(dp, -1, sizeof(dp));

  cout << calc(0, false, false, can) << endl;

  return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<algorithm>
#include<set>
#include<map>
#include<queue>
#include<cassert>
#define PB push_back
#define MP make_pair
#define sz(v) (in((v).size()))
#define forn(i,n) for(in i=0;i<(n);++i)
#define forv(i,v) forn(i,sz(v))
#define fors(i,s) for(auto i=(s).begin();i!=(s).end();++i)
#define all(v) (v).begin(),(v).end()
using namespace std;
typedef long long ll;
int N = 200005;
int a[805][805];
int main(){
  string s, s1,s2;
  cin >> s >> s1 >> s2;
  if (s[s.size() - 1] == s1[0] && s1[s1.size() - 1] == s2[0]){
  	cout <<"YES\n";
  } else {
  	cout <<"NO\n";
  }
  return 0;
}

Measured memory_bytes: 256
import numpy as np
MOD = 10 ** 9 + 7

dp = np.zeros(13, dtype = np.int64)
dp[0] = 1

move = np.arange(0,52,4) % 13
ten = np.ones(10, dtype=np.int64)
for s in input():
  dp = dp[move]
  if s == '?':
    dp = np.convolve(dp, ten)
    dp[:9] += dp[13:22]
    dp %= MOD
  else:
    dp = np.roll(dp, int(s))
  
print(dp[5])


Measured memory_bytes: 22152
#include <stdio.h>
#define INF 100000000

int n,G[103][103];

int prim(void);

int main()
{
  int i,j;

  scanf("%d",&n);

  /* 重みつきグラフが与えられる。辺がないときは-1 */
  for(i = 1;i <= n;i++){
    for(j = 1;j <= n;j++){
      scanf("%d",&G[i][j]);
    }
  }

  /* 辺がないときをInfにする */
   for(i = 1;i <= n;i++){
    for(j = 1;j <= n;j++){
      if(G[i][j] == -1) G[i][j] = INF;
    }
   }

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

}

int prim(void)
{
  int u,v,i,mincost;
  int d[103],pi[103];
  char color[103];
  int total = 0;

  /* 初期化 */
  for(u = 1;u <= n;u++){
    d[u] = INF;
    pi[u] = -2;
    color[u] = 'W';
  }

  d[1] = 0;
    
  while(1){
    mincost = INF;
    for(i = 1;i <= n;i++){
      if(color[i] != 'B' && d[i] < mincost){
	mincost = d[i];
	u = i;
      }
    }
    
    if(mincost == INF) break;

    color[u] = 'B';
    
    for(v = 1;v <= n;v++){
      if(color[v] != 'B' && G[u][v] < d[v]){
	pi[v] = u;
	d[v] = G[u][v];
      }
    }
    color[v] = 'B';
  }

  for(i = 1;i <= n; i++){
    if(pi[i] != -2) total += G[i][pi[i]];
  }

  return total;
}

Measured memory_bytes: 640
#include <stdio.h>
#include <string.h>
 
void mD(char C, int *D) {
  switch (C) {
    int t;
  case 'N':
    t = D[0]; D[0] = D[1]; D[1] = D[5]; D[5] = D[4]; D[4] = t;
    break;
  case 'S':
    t = D[0]; D[0] = D[4]; D[4] = D[5]; D[5] = D[1]; D[1] = t;
    break;
  case 'E':
    t = D[0]; D[0] = D[3]; D[3] = D[5]; D[5] = D[2]; D[2] = t;
    break;
  case 'W':
    t = D[0]; D[0] = D[2]; D[2] = D[5]; D[5] = D[3]; D[3] = t;
    break;
  }
  return;
}
 
int main(void) {
  int D[6], d;
  char C[101];int c;
  for(d=0;d<6;d++)
    scanf("%d",&D[d]);
  scanf("%s",C);
  for (c=0;c<strlen(C);c++) {
    mD(C[c], D);
  }
  printf("%d\n",D[0]);
 
  return 0;
}

Measured memory_bytes: 596
#include <algorithm>
#include <complex>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <vector>
#define rep(i, n) for (int i = 0; i < (n); i++)
#define rrep(i, n) for (int i = (n)-1; i >= 0; i--)
using namespace std;
typedef long long int lli;
lli MOD = 1000000007;
string b = "Second";
string a = "First";
int main()
{
    string s;
    cin >> s;
    int k = s.size();
    int c = s[0] == s[s.size() - 1];
    k %= 2;
    if (c ^ k)
        cout << a << endl;
    else
        cout << b << endl;
}


Measured memory_bytes: 512
#include <bits/stdc++.h>
#define PREP(i, s, x) for(ll i = (s); i < (x); i++)
#define MREP(i, s, x) for(ll i = (s); i >= (x); i--)
#define REP(i, x) PREP(i, 0, x)
using namespace std;
using ll = long long;
using P = pair<ll, ll>;
template<typename T> inline bool chmax(T &a, T b) { return ((a < b) ? (a = b, true) : (false)); }
template<typename T> inline bool chmin(T &a, T b) { return ((a > b) ? (a = b, true) : (false)); }

// variable -------------------------------------------

constexpr ll INF = (1ll << 59);
constexpr ll MOD = 1000000007ll;

// structure ------------------------------------------

// function -------------------------------------------


// main -----------------------------------------------

int main() {
	ll h, w, m;
	cin >> h >> w >> m;

	map<ll, ll> tate, yoko;
	map<P, bool> data;
	
	REP(i, m){
		ll hh, ww;
		cin >> hh >> ww;
		hh --;
		ww --;
		tate[hh] ++;
		yoko[ww] ++;
		data[make_pair(hh, ww)] = true;
	}

	ll tatekinglength = 0, yokokinglength = 0;
	vector<ll> tateking, yokoking;
	for(auto v : tate){
		if(tatekinglength > v.second){
			continue;
		}else if(tatekinglength == v.second){
			tateking.push_back(v.first);
		}else if(tatekinglength < v.second){
			tatekinglength = v.second;
			tateking = vector<ll>();
			tateking.push_back(v.first);
		}
	}
	for(auto v : yoko){
		if(yokokinglength > v.second){
			continue;
		}else if(yokokinglength == v.second){
			yokoking.push_back(v.first);
		}else if(yokokinglength < v.second){
			yokokinglength = v.second;
			yokoking = vector<ll>();
			yokoking.push_back(v.first);
		}
	}

	ll ans = tatekinglength + yokokinglength;
	for(ll i : tateking){
		for(ll j : yokoking){
			if(data[make_pair(i, j)] == false){
				cout << ans << endl;
				return 0;
			}
		}
	}
	cout << ans - 1 << endl;

	return 0;
}

Measured memory_bytes: 67788
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<cmath>
#include<cstdlib>
#include<tuple>
#include<iomanip>
#include<map>
#include<queue>
#include<set>
#define int long long
using namespace std;
const int INF = 1e10;
const int ZERO = 0;

signed main() {
	int N;
	cin >> N;
	vector<int> vec(3 * N);
	for(int i = 0;i < 3 * N;i++) {
		cin >> vec.at(i);
	}
	sort(vec.begin(),vec.end());
	reverse(vec.begin(),vec.end());
	int ret = 0;
	for(int i = 0;i < N;i++) {
		ret += vec.at(i * 2 + 1);
	}
	cout << ret << endl;
}

Measured memory_bytes: 2560
N = int(input())
A = list(map(int,input().split()))

A = [[A[i],i] for i in range(N)]
A.sort()

dp = [[0]*(N+1) for i in range(N+1)]

ans = 0
for i in range(N+1):
    for j in range(N+1):
        if i+j>N:
            continue
        if i+j==0:
            continue
        a,k = A[-i-j]
        if i==0:
            dp[i][j] = dp[i][j-1]+a*(N-j-k)
        elif j==0:
            dp[i][j] = dp[i-1][j]+a*(k-i+1)
        else:
            dp[i][j] = max(dp[i-1][j]+a*(k-i+1),dp[i][j-1]+a*(N-j-k))
        ans = max(ans,dp[i][j])
print(ans)

Measured memory_bytes: 100500
#include <bits/stdc++.h>
#include <ext/hash_map>
#include <ext/numeric>

using namespace std;
using namespace __gnu_cxx;

#define REP(i,n) for( (i)=0 ; (i)<(n) ; (i)++ )
#define rep(i,x,n) for( (i)=(x) ; (i)<(n) ; (i)++ )
#define REV(i,n) for( (i)=(n) ; (i)>=0 ; (i)-- )
#define FORIT(it,x) for( (it)=(x).begin() ; (it)!=(x).end() ; (it)++ )
#define foreach(it,c) for(__typeof((c).begin()) it=(c).begin();it!=(c).end();++it)
#define rforeach(it,c) for(__typeof((c).rbegin()) it=(c).rbegin();it!=(c).rend();++it)
#define foreach2d(i, j, v) foreach(i,v) foreach(j,*i)
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
#define SZ(x) ((int)(x).size())
#define MMS(x,n) memset(x,n,sizeof(x))
#define mms(x,n,s) memset(x,n,sizeof(x)*s)
#define pb push_back
#define mp make_pair
#define NX next_permutation
#define UN(x) sort(all(x)),x.erase(unique(all(x)),x.end())
#define CV(x,n) count(all(x),(n))
#define FIND(x,n) find(all(x),(n))-(x).begin()
#define ACC(x) accumulate(all(x),0)
#define PPC(x) __builtin_popcountll(x)
#define LZ(x) __builtin_clz(x)
#define TZ(x) __builtin_ctz(x)
#define mxe(x) *max_element(all(x))
#define mne(x) *min_element(all(x))
#define low(x,i) lower_bound(all(x),i)
#define upp(x,i) upper_bound(all(x),i)
#define NXPOW2(x) (1ll << ((int)log2(x)+1))
#define PR(x) cout << #x << " = " << (x) << endl ;

typedef unsigned long long ull;
typedef long long ll;
typedef vector<int> vi;
typedef vector<vector<int> > vvi;
typedef pair<int, int> pii;

const int OO = (int) 2e9;
const double eps = 1e-9;

const int N = 22;
const int mod = (int) 1e9 + 7;

int n;
int a[N][N];
int dp[N][1 << (N - 1)];

int calc(int idx, int msk) {
	if (idx == n)
		return msk == (1 << n) - 1;
	int &ret = dp[idx][msk];
	if (ret != -1)
		return ret;
	ret = 0;
	for (int i = 0; i < n; i++) {
		if (!(msk & (1 << i)) && a[idx][i]) {
			(ret += calc(idx + 1, msk | (1 << i))) %= mod;
		}
	}
	return ret;
}

int main() {
	std::ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
#ifndef ONLINE_JUDGE
//	freopen("in.txt", "rt", stdin);
//	freopen("out.txt", "wt", stdout);
#endif
	cin >> n;
	for (int i = 0; i < n; i++)
		for (int j = 0; j < n; j++)
			cin >> a[i][j];
	MMS(dp, -1);
	cout << calc(0, 0) << endl;
//	dp[n][(1 << n) - 1] = 1;
//	for (int idx = n - 1; idx >= 0; idx--) {
//		for (int msk = 0; msk < (1 << n); msk++) {
//			for (int i = 0; i < n; i++) {
//				if (!(msk & (1 << i)) && a[idx][i]) {
//					(dp[idx][msk] += dp[idx + 1][msk | (1 << i)]) %= mod;
//				}
//			}
//		}
//	}
//	cout << dp[0][0] << endl;
	return 0;
}


Measured memory_bytes: 180608