akhauriyash/Code-Regression huggingface dataset:
import sys
sys.setrecursionlimit(2147483647)
INF=float("inf")
MOD=10**9+7
input=lambda:sys.stdin.readline().rstrip()
from collections import defaultdict
from bisect import bisect
def resolve():
    S=input()
    T=input()

    if(len(set(S))!=len(set(S+T))):
        print("-1")
        return

    idx=defaultdict(list)
    for i,s in enumerate(2*S):
        idx[s].append(i)

    now=-1
    n=len(S)
    for t in T:
        i=bisect(idx[t],now%n)
        now+=idx[t][i]-now%n

    print(now+1)
resolve()

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

#define fastio 			ios::sync_with_stdio(0);	cin.tie(0); cout.tie(0);  cout<<fixed;  cout<<setprecision(12);
#define randomINT 		mt19937 rnd(chrono::steady_clock::now().time_since_epoch().count());
#define	newl 			cout<<"\n"
#define DISP(as)		for(auto it : as) cout<<it<<" ";newl;
#define all(x)         	(x).begin(),(x).end()
#define mset(x,val)    	memset(x,val,sizeof(x))
#define newl           	cout<<"\n"
#define pb             	push_back
#define mp             	make_pair
#define f 				first
#define s 				second
#define dline          cerr<<"///REACHED///\n";
#define deb1(x)        cerr<<#x<<" = "<<x<<'\n';
#define deb2(x,y)      cerr<<'['<<#x<<','<<#y<<"] = "<<'['<<x<<','<<y<<']'<<'\n';
#define deb3(x,y,z)    cerr<<'['<<#x<<','<<#y<<','<<#z<<"] = "<<'['<<x<<','<<y<<','<<z<<']'<<'\n';

typedef long long 				ll;
typedef long double 			ld;
typedef vector<ll> 				vll;
typedef pair<ll , ll> 			pll;
typedef pair<ld, ld> 			pld;
typedef unordered_map<ll, ll> 	um;
typedef vector<pll> 			vpll;

const ll 	MAX5 	= 	1e+5 + 7;
const ll 	MAX7 	= 	1e+7 + 7;
const ll 	MAXN 	= 	MAX7;
const ll   	INF   	=  	0x7f7f7f7f7f7f7f7f;
const int  	INFi 	=  	0x7f7f7f7f;
const ll 	MOD		=  	1e+9 + 7;


// <------------- Declare Variables Here ------------> //

ll T = 1;
ll n, x, m, y, k, z, N;
string s, t, d, c;


// <------------- Implement Functions Here ----------> //



// <------------- Start of main() -------------------> //

void MAIN() {
	cin>>n;
	vll a(n);
	for(ll i=0;i<n;i++) cin>>a[i];

	ll mini = INT_MAX;
	ll sum = 0;
	for(ll i=-100;i<=100;i++) {
		sum = 0;
		for(ll j=0;j<n;j++) {
			sum += (i-a[j])*(i-a[j]);
		}
		mini = min(mini,sum);
	}
	cout<<mini;
}

int main() {
	fastio; randomINT;
	//cin >> T;
	while (T--) {
		MAIN();
	}
	return 0;
}


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

#define ll long long
#define pll pair<ll,ll> 

int main() {

	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);

	string s;
	cin>>s;
	regex e("(dream|dreamer|erase|eraser)+");
	if(regex_match(s,e))
		cout<<"YES";
	else cout<<"NO";
	cout<<endl;
}


Measured memory_bytes: 28196
#include <bits/stdc++.h>
#define mx 10000001
using namespace std;
typedef long long ll;
typedef long double ld;

int main()
{

    //freopen("Input.txt","r",stdin);
    // ios_base :: sync_with_stdio(false);

    string s,t;
    cin>>s>>t;
    ll cnt=0;
    for(int i=0;i<s.size();i++)
    {
        if(s[i]!=t[i])
            cnt++;
    }
    cout<<cnt<<endl;
}


Measured memory_bytes: 3920
#include<iostream>
#include<vector>
#include<cstring>
#include<algorithm>
#include<cmath>
#include<queue>
#include<deque>
#include<map>
#include<bitset>

using namespace std;
using ll = long long;

#define rep(i, n) for(int i = 0;i < (n);i++)
#define repr(i, n) for(int i = (n);i >= 0;i--)
#define repf(i, m, n) for(int i = (m);i < (n);i++)

template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1;} return 0;}
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1;} return 0;}

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

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

const ll mod = 1e9+7;

vector<ll> list_minv(ll n, ll m) {
    vector<ll> inv(n + 1);
    inv[1] = 1;
    for (int i = 2; i <= n; ++i) {
        inv[i] = inv[m % i] * (m - m / i) % m;
    }
    return inv;
}

int main() {
    int n; cin >> n;
    vector<ll> x(n);
    rep(i, n) cin >> x[i];

    // 前処理
    vector<ll> inv(n+1), kaijo(n+1);
    inv = list_minv(n, mod);
    kaijo[0] = 1;
    for (int i = 1; i <= n; i++) {
        kaijo[i] = kaijo[i-1] * i % mod;
    }

    ll a = 0;
    ll ans = 0;
    repf(i, 1, n) {
        (a += kaijo[n-1]*inv[i]) %= mod;
        (ans += a*(x[i]-x[i-1])) %= mod;
        // cout << a << endl;
    }

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


Measured memory_bytes: 3328
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<string>
#include<algorithm>
#include<vector>
using namespace std;
 
 
int main(){
	int n, k;
	int hate[10];
	scanf("%d%d", &n, &k);
	fill(hate, hate + 10, 10);
	for (int i = 0; i < k; i++){
		scanf("%d", &hate[i]);
	}
	int i;
	for (i = n;; i++){
		string s = to_string(i);
		bool flag = true;
		for (int j = 0; j < k; j++){
			if ((int)s.find(to_string(hate[j])) >= 0)flag = false;
		}
		if (flag)break;
	}
	printf("%d\n", i);
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using lint = long long int;
#define FOR(i, begin, end) for(int i=(begin),i##_end_=(end);i<i##_end_;i++)
#define IFOR(i, begin, end) for(int i=(end)-1,i##_begin_=(begin);i>=i##_begin_;i--)
#define REP(i, n) FOR(i,0,n)
#define IREP(i, n) IFOR(i,0,n)
constexpr int MOD = 1000000007;
constexpr int INF = 2147483647;
int main()
{
   lint N, K, S;
   cin >> N >> K >> S;
   vector<lint> ans(N);
   REP(i, K) {
       ans[i] = S;
   } 
   FOR(i, K, N) {
       if(S != 1000000000) {
           ans[i] = S+1;
       } else {
           ans[i] = S-1;
       }
   }
   REP(i, N) cout << ans[i] << (i!=N-1 ? " " : "");
   cout << endl;
}

Measured memory_bytes: 2048
#include <bits/stdc++.h>
#include <stdlib.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
typedef pair<ll,ll> llP;

int main() {
  int x,y,z;
  cin>>x>>y>>z;
  cout<<z<<' '<<x<<' '<<y<<endl;
  return 0;
}


Measured memory_bytes: 256
#include "stdio.h"

int main()
{
    int inSec=0;
    int sec=0;
    int min=0;
    int hour=0;

    scanf("%d",&inSec);
    if((inSec < 0) || (inSec >= 86400))
    {
        return 0;
    }

    hour = inSec/3600;

    inSec = inSec - 3600*hour;
    min = inSec/60;
    inSec = inSec - min*60;

   sec = inSec;

 
   printf("%d:%d:%d\n", hour, min, sec);

   return 0;
}


Measured memory_bytes: 2104
#include <bits/stdc++.h>
using namespace std;
#define rep(i,ini,n) for(int i=ini;i<n;i++)
#define _rep(i,ini,n) for(int i=ini;i>=n;i--)
#define ToEnd(a) a.begin(),a.end()
uint64_t MOD=1000000007;

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

    bool correct=true;
    int cntC=0;
    rep(i,0,S.size()){
        char c=S.at(i);
        if(i==0){
            if(c!='A') correct=false;
        }
        else if(c>='A' && c<='Z'){
            if(c=='C'){
                if(i>1 && i<S.size()-1) cntC++;
            }
            else correct=false;
        }
    }
    if(cntC!=1) correct=false;

    if(correct) cout<<"AC"<<endl;
    else cout<<"WA"<<endl;
}

Measured memory_bytes: 256
while True:
    a, op, b = raw_input().split()
    a = int(a)
    b = int(b)
    if op == "?":
        break
    elif op == "+":
        print a + b
    elif op == "-":
        print a - b
    elif op == "*":
        print a * b
    elif op == "/":
        print a / b


Measured memory_bytes: 4628
import sys

N = int(input())
A = list(map(int,input().split()))

if 0 in A:
    print(0)
else:
    x = 1
    for i in range(N):
        x = x * A[i]
        if x>10**18:
            print(-1)
            sys.exit()
        
    print(x)

Measured memory_bytes: 21588
#include<stdio.h>
int N, i;
long long int A[2];
int main(){
  scanf("%d", &N);
  A[0] = 2;
  A[1] = 1;
  for(i=2; i<=N; i++){
    A[i&1] += A[(i+1)&1];
  }
  printf("%lld\n", A[N&1]);
}


Measured memory_bytes: 128
from statistics import mean, median,variance,stdev
import numpy as np
import sys
import math
import fractions
import itertools
import copy

def j(q):
    if q==1: print("YES")
    else:print("NO")
    exit(0)


def ct(x,y):
    if (x>y):print("GREATER")
    elif (x<y): print("LESS")
    else: print("EQUAL")

def ip():
    return int(input())


#n = ip()                              #入力整数1つ
#n,m= (int(i) for i in input().split())      #入力整数横2つ
a,b,k = (int(i) for i in input().split())    #入力整数横3つ
#n,a,b,c= (int(i) for i in input().split())  #入力整数横4つ
#a = [int(i) for i in input().split()]        #入力整数配列
#a = input()                                  #入力文字列
#a = input().split()                          #入力文字配列
#n = ip()                      #入力セット(整数改行あり)(1/2)
#a=[ip() for i in range(n)]    #入力セット(整数改行あり)(2/2)
#a=[input() for i in range(h)]
#jの変数はしようできないので注意
#全足しにsum変数使用はsum関数使用できないので注意
la = [i for i in range(1,a+1) if a%i == 0]
lb = [i for i in range(1,a+1) if (b%i == 0 and i in la)]
lb.sort(reverse = True)
print(lb[k-1])



Measured memory_bytes: 23056
require 'set'

s = gets.to_i

a = s
i = 1
aset = Set.new([a])

loop do
  i = i + 1
  if a.odd?
    a = 3 * a + 1
  else
    a = a / 2
  end

  if aset.include?(a)
    puts i
    exit
  else
    aset << a
  end
end

Measured memory_bytes: 14424
#include<bits/stdc++.h>
using namespace std;
#define rep(i,x,y) for(int i=x;i<y;i++)
#define print(A,x,n) rep(I,0,n){cout<<(I ? " ":"")<<A[I]x;}cout<<endl;
#define pprint(A,y,m,n) rep(J,0,m){print(A[J],y,n);}
const long mod=1e9+7;
const int size=1e5;
const int inf=1e9;
int N;
long A[size];
vector<int> g[size];
bool dfs(int p, int v){
	long sum = 0; long grt = 0;
	for(int u:g[v]){
		if(u == p) continue;
		if(!dfs(v, u)) return false;
        grt = max(grt, A[u]);
		sum += A[u];
	}
    if(g[v].size() == 1) return true;
    long t = 2 * A[v] - sum;
    if(0 <= t && max(t, grt) <= A[v]){ A[v] = t; return true; }
    else return false;
}
int main(){
	cin>>N;
	rep(i,0,N) cin>>A[i];
    if(N == 2){ cout<<(A[0] == A[1] ? "YES" : "NO")<<endl; return 0; }
	int a,b;
	rep(i,0,N-1){
		cin>>a>>b; a--; b--;
		g[a].push_back(b);
		g[b].push_back(a);
	}
    rep(i,0,N)if(g[i].size() > 1){
        if(dfs(-1, i) && A[i] == 0) cout<<"YES"<<endl;
        else cout<<"NO"<<endl;
        return 0;
    }
}

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

typedef long long int ll;
typedef pair<ll, ll> pii;
#define f(i,a,b) for(ll i=a;i<b;i++)
#define fo(i,a,b) for(ll i = a; i<=b;i+=1)
#define rf(i,a,b)  for(ll i=a;i>=b;i--)
#define vll vector<ll>
#define sz(a) ll(a.size())
#define all(v) v.begin(),v.end()
#define pb push_back
#define pf push_front 
#define MAXN 100010
#define MOD 1000000007
#define mod 998244353
#define deb(x) cout << '>' << #x << ':' << x << endl;
#define debug(x) cout << '>' << #x << ':' << x << " ";
#define nl '\n'
#define INF 1000000000000000000
#define IO                 \
    ios::sync_with_stdio(0); \
    cin.tie(0);              \
    cout.tie(0);
#define int long long int

void solve(){
    int x;
    cin >> x;
    cout << 1-x << nl;
}
main()
{
    IO;
    #ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
    #endif
    int T = 1;
    // cin >> T;
    fo(c, 1, T){
        solve();
        // cout<<"Case #"<<c<<": ";
    }
    return 0;
}

Measured memory_bytes: 3608
def checkPalindrome(string):
    string_len = len(string)
    for i in range(int(string_len/ 2)):
        if(string[i] != string[string_len - i - 1]):
            return False
    return True

S = input()
string_len = len(S)
if(checkPalindrome(S) and checkPalindrome(S[:int((string_len-1)/2)]) and checkPalindrome(S[int((string_len + 3)/2-1):])):
    print("Yes")
else:
    print("No")

Measured memory_bytes: 3064
a, b = gets.chomp.split(" ").map(&:to_i)
diff = (a.abs - b.abs).abs
count = 0
if a==0
    if b.positive?
        count += diff
    else
        count += diff + 1
    end
elsif b==0
    if a.positive?
        count += diff + 1
    else
        count += diff
    end
elsif a.positive? != b.positive?
    count += diff + 1
else
    if a < b
        count += diff
    else
        count += diff + 2
    end
end
puts count

Measured memory_bytes: 3836
#include <bits/stdc++.h>
using namespace std;
#define M_PI 3.14159265358979323846
#define MOD 1000000007
typedef long long ll;
typedef vector<int> vint;
typedef vector<vint> vvint;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef pair<int, int> ipair;
typedef pair<ll, ll> llpair;
    
/*
    Author: Koushik Sahu
    Created: 11 Sep 2020 15:31:14
*/

int n, m, e1, e2;
vvint g;

vint topoSort(){
    vint ans;
    queue<int> q;
    int indeg[n];
    fill_n(indeg, n, 0);
    for(int i=0; i<n; i++){
        for(int j: g[i]) indeg[j]++;
    }
    for(int i=0; i<n; i++){
        if(indeg[i]==0){
            q.push(i);
        }
    }
    while(!q.empty()){
        int u = q.front();
        q.pop();
        ans.push_back(u);
        for(int v: g[u]){
            indeg[v]--;
            if(indeg[v]==0) q.push(v);
        }
    }
    return ans;
}

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL), cout.tie(NULL);
    cin>>n>>m;
    g.resize(n);
    for(int i=0; i<m; i++){
        cin>>e1>>e2;
        e1--, e2--;
        g[e1].push_back(e2);
    }
    vint topo_order = topoSort();
    int dist[n];
    fill_n(dist, n, INT_MIN);
    for(int i=0; i<topo_order.size(); i++){
        int u = topo_order[i];
        if(dist[u]==INT_MIN) dist[u] = 0;
        for(int v: g[u]){
            if(dist[v]<dist[u]+1){
                dist[v] = dist[u] + 1;
            }
        }
    }
    cout<<*max_element(dist, dist+n)<<"\n";
    return 0;
}

Measured memory_bytes: 9528
#include <bits/stdc++.h>
#define PI 3.14159265359
using namespace std;
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 long long INF = 1LL << 60;
using pll = pair<long long, long long>;

int vector_finder(std::vector<int> vec, int 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;
  }
}

int main() {
  // 標準入力が早くなる。Cスタイルの入出力とC++スタイルの入出力を混合させてはならない。
  cin.tie(nullptr);
  ios_base::sync_with_stdio(false);
  int N, K;
  cin >> N >> K;

  vector<int> A;

  for (int i = 0; i < N; i++) {
    int d;
    cin >> d;

    for (int i = 0; i < d; i++) {
      int element;
      cin >> element;
      A.push_back(element);
    }
  }

  sort(A.begin(), A.end());
  A.erase(unique(A.begin(), A.end()), A.end());

  cout << N - A.size() << endl;

  return 0;
}


Measured memory_bytes: 3724
#include <bits/stdc++.h>
using namespace std;
#define FIN ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);

int main() {FIN
    
    int n, r;
    cin >> n;
    r = n % 1000;
    cout << (r > 0 ? 1000 - r : r) << "\n";
    return 0;
}


Measured memory_bytes: 3644
/*
 * src.cpp
 *
 *  Created on: 2016/08/04
 *      Author: joi
 */

#include <bits/stdc++.h>

using namespace std;

#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REP(i,a) FOR(i,0,a)

typedef pair<int,int> P;

const int MAX_N=1e4;

int n;
P pa[MAX_N];

int main(){
	do{
		cin>>n;
		if (n){
			REP(i,n){
				int p,d1,d2;
				cin>>p>>d1>>d2;
				pa[i]=P(d1+d2,p);
			}
			sort(pa,pa+n);
			cout<<pa[n-1].second<<" "<<pa[n-1].first<<endl;
		}
	}while (n);
	return 0;
}

Measured memory_bytes: 1240
import std.stdio, std.algorithm, std.conv, std.array, std.string, std.math, std.typecons, std.numeric;

void main()
{
    auto N = readln.chomp.to!int;
    auto LS = readln.split.to!(int[]);
    sort(LS);
    long res;
    foreach (i; 0..N-2) {
        foreach (j; i+1..N-1) {
            auto a = LS[i], b = LS[j];
            auto ll = max(a-b, b-a);
            auto rl = a+b;

            if (LS[j+1] >= rl || LS[N-1] <= ll) continue;

            int l = j+1, r = N-1;

            if (LS[j+1] > ll) {
                ll = j+1;
            } else {
                while (l+1 < r) {
                    auto m = (l+r)/2;
                    if (LS[m] > ll) {
                        r = m;
                    } else {
                        l = m;
                    }
                }
                ll = r;
            }

            if (LS[N-1] < rl) {
                rl = N-1;
            } else {
                l = j+1;
                r = N-1;
                while (l+1 < r) {
                    auto m = (l+r)/2;
                    if (LS[m] < rl) {
                        l = m;
                    } else {
                        r = m;
                    }
                }
                rl = l;
            }
            res += rl - ll + 1;
        }
    }
    writeln(res);
}

Measured memory_bytes: 2428
#include <bits/stdc++.h>
using namespace std;
#define int long long int
const int N = 1e6 , M = 1e3; ;
int n;
int a[N];
int dp[4*M][4*M][2];
int foo(int start , int end ,int chance  ){
	if(start > end) return 0;
	if(dp[start][end][chance]!=-1) return dp[start][end][chance]; 
	int ans = 0;
	if(chance) ans = max( a[start] + foo(start + 1 , end , chance^1) , a[end] + foo(start , end - 1 , chance^1) );
	else ans = min( -a[start] + foo(start + 1 , end , chance^1) , -a[end] + foo(start , end - 1 , chance^1) );   
	dp[start][end][chance] = ans; 
	return ans;
}


int32_t main(){
	cin >> n;
	memset(dp , - 1 , sizeof dp);
	for(int i = 1 ; i <= n ;i++){
		cin >> a[i];
	}
	cout << foo(1 , n , 1) << "\n"; 
	return 0;
}

Measured memory_bytes: 252288
/*
    CP Submission
*/

#include<bits/stdc++.h>

using namespace std;

/* Shortcuts */
#define MP make_pair
#define PB push_back
#define ALL(x) x.begin(), x.end()
#define VAL(x) cout << #x << ": " << (x) << endl;
#define LOG(x) cout << (x) << endl;
#define SZ(x) (int)(x.size())
#define REP(i, a, b) for(int i = a; i < b; i++)
#define LOGR(x) for(auto a : (x)) cout << a << '\n';

/* typedefs */
typedef long long ll;
typedef pair<int,int> ii;
typedef pair<string,int> si;
typedef pair<int,ii> iii;
typedef vector <si> vsi;
typedef vector <ii> vii;
typedef vector <int> vi;
typedef vector <vi> vvi;
typedef vector <char> vc;
typedef vector <string> vs;
typedef map <string,vs> msvs;
typedef map <string,int> msi;
typedef map <string,string> mss;

const int MAXN = 1e5;

int dp[MAXN];

vvi adj;

int longestPath(int v){
    if(dp[v] != -1) return dp[v];
    
    
    int maxl = 0;
    for(int u : adj[v]){
        maxl = max(maxl, longestPath(u) + 1);
    }

    return dp[v] = maxl;
}

int main(){

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

    int n, m;
    cin>>n>>m;

    adj = vvi(n);

    memset(dp, -1, sizeof(dp[0]) * MAXN);

    REP(i,0,m){
        int x, y;
        cin>>x>>y;
        --x; --y;
        adj[y].PB(x); // backwards edge
    }

    int ans = 0;
    REP(i,0,n){
        ans = max(ans, longestPath(i));
    }

    LOG(ans);

    return 0;
}


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

int main() {

    int X;
    cin >> X;

    cout << 8 - (X-400)/200 << endl;

    return 0;
}


Measured memory_bytes: 3632
#include "algorithm"
#include "iostream"
#define rep(i, to) for (ll i = 0; i < (to); ++i)
using namespace std;
typedef long long ll;

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

  string S;
  cin >> S;

  string a[]{"", "SAT", "FRI", "THU", "WED", "TUE", "MON", "SUN"};

  rep(i, 8) {
    if (S == a[i]) {
      cout << i << endl;
    }
  }

  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <limits.h>
#include <algorithm>
#include <string>
#include <math.h>
#include <limits.h>
#include <queue>
#include <map>
#include <set>
#include <iomanip>
#include <bitset>
#include <cassert>
#include <random>
#include <functional>
#include <stack>
#include <iomanip>
#include <cassert>
//#include <boost/multiprecision/cpp_int.hpp>
#include <complex>
#include <cstdio>
#include <list>

//< in.txt > out.txt
using namespace std;
//std::ios::sync_with_stdio(false);
//std::cin.tie(0);
const long long MOD = 1e9 + 7;
typedef long long ll;
typedef long long LL;
typedef long double ld;
typedef pair<ll, ll> pll;
typedef pair<ld, ll> pdl;
typedef pair<ld, ld> pdd;
typedef vector<ll> VLL;
typedef vector<VLL> VVLL;
//typedef boost::multiprecision::cpp_int bigint;

LL H, W;
VVLL MAP;   //1->unavailable

LL bfs(LL sx, LL sy) {
	if (MAP[sx][sy] == 1)return 0;
	struct query {
		LL x, y, d;
	};
	queue<query> q;
	LL V[4][2] = {
		{0,1},{0,-1},{1,0},{-1,0}
	};
	VVLL res;
	res.resize(W, VLL(H, -1));
	q.push({ sx,sy,0 });
	LL ans = 0;
	res[sx][sy] = 0;
	while(q.size() > 0) {
		LL x = q.front().x;
		LL y = q.front().y;
		LL d = q.front().d;
		q.pop();
		for (LL v = 0; v < 4; v++) {
			LL nx = x + V[v][0];
			LL ny = y + V[v][1];
			if (nx < 0 || nx >= W || ny < 0 || ny >= H)continue;
			if (MAP[nx][ny] == 1)continue;
			if (res[nx][ny] != -1)continue;
			res[nx][ny] = d + 1;
			q.push({ nx,ny,d + 1 });
			ans = max(ans, d + 1);
		}
	}
	return ans;
}

int main() {
	std::ios::sync_with_stdio(false);
	std::cin.tie(0);
	cin >> H >> W;
	MAP.resize(W, VLL(H, 0));
	for (LL y = 0; y < H; y++) {
		string S;
		cin >> S;
		for (LL x = 0; x < W; x++) {
			if (S[x] == '#')MAP[x][y] = 1;
		}
	}
	LL ans = 0;
	for (LL sx = 0; sx < W; sx++) {
		for (LL sy = 0; sy < H; sy++) {
			ans = max(ans, bfs(sx, sy));
		}
	}
	cout << ans << "\n";
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ll long long
using namespace std;
ll i,j,k,n,m,ans;
ll sum[60],S[60];
void fun(ll x,ll y){
//	cout<<x<<' '<<y<<' '<<sum[x-1]<<' '<<S[x-1]<<' '<<ans<<endl;
	if(x==0){
		if(y!=0)++ans;
		return;
	}--y;
	if(y>=sum[x-1]){
		ans+=S[x-1];
		y-=sum[x-1];
		if(y==0)return;
		--y;
		ans++;
	}
	if(y==0)return;
	fun(x-1,y);
	/*
	cout<<x<<' '<<y<<' '<<sum[x-1]<<' '<<S[x-1]<<' '<<ans<<endl;
	if(x==0);
	if(y<=1)return;
	if(y<sum[x-1]+2)fun(x-1,y);
	else{
		ans+=S[x-1]+1;
		//cout<<x<<' '<<ans<<endl;
		fun(x-1,y-sum[x-1]-1);
	}*/
}
int main(){
	cin>>n>>m;
	sum[0]=S[0]=1;
	for(i=1;i<=50;i++){
		sum[i]=sum[i-1]*2+3;
		S[i]=S[i-1]*2+1;
//		cout<<m<<endl<<sum[i]<<' '<<S[i]<<endl;
	}
	fun(n,m);
	cout<<ans<<endl;
	return 0;
}

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

int const MAXN = 6003;

int dp[MAXN][MAXN];

int n,t;
pair<int, int> arr[MAXN];

int solve(int i, int x){
    if (dp[i][x] != -1) return dp[i][x];
    if (x >= t || i > n) return dp[i][x] = 0;

    return dp[i][x] = max(solve(i+1, x+arr[i].first) + arr[i].second, solve(i+1,x));
}

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

    cin >> n >> t;
    for (int i=1; i<=n; i++) cin >> arr[i].first >> arr[i].second;
    sort(arr+1, arr+n+1);

    memset(dp, -1, sizeof dp);
    cout << solve(1,0) << endl;

}

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

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

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

int main() {
	ll n, k;
	cin >> n >> k;
	vector<ll> a(n);
	rep(i, n) cin >> a[i];
	SORT(a);
	reverse(a.begin(), a.end());

	set<ll> st;

	ll ans = 0;
	rep(i, n){
		if(a[i] >= k){
			ans = i + 1;
			continue;
		}
		set<ll> tmp(st);
		tmp.insert(a[i]);
		for(auto it : st){
			if(a[i] + it >= k) ans = i + 1;
      else tmp.insert(a[i] + it);
		}
		st = tmp;
	}

  cout << n - ans << endl;

	return 0;
}

Measured memory_bytes: 768
/**
 * code generated by JHelper
 * More info: https://github.com/AlexeyDmitriev/JHelper
 * @author
 */

#include <iostream>
#include <fstream>

#include <iostream>
#include <string>
#include <vector>
#include <math.h>
#include <map>
#include <set>
#include <algorithm>
#include <numeric>
#include <bitset>
using namespace std;
using ll = long long;
constexpr ll INF = 1010000000000000017LL;
#define rep(i, n) for(ll i = 0; i < (ll)(n); i++)
#define all(v) v.begin(), v.end()

class DIHateFactorization {
public:
	void solve(std::istream& in, std::ostream& out) {
        ll x;
        in>>x;
        for(ll a=-120; a < 121; ++a){
            for(ll b=-120; b < 121; ++b){
                ll a5 = a*a*a*a*a;
                ll b5 = b*b*b*b*b;
                if(a5-b5==x){
                    out<<a<<' '<<b<<endl;
                    return;
                }
            }
        }
	}
};


int main() {
	DIHateFactorization solver;
	std::istream& in(std::cin);
	std::ostream& out(std::cout);
	solver.solve(in, out);
	return 0;
}


Measured memory_bytes: 3148
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(10 ** 7)

s = input()
cnt = 0
for i in range(len(s) // 2):
    if s[i] != s[-(i + 1)]:
        cnt += 1
print(cnt)


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

using ll = long long;
using ull = unsigned long long;

#define MOD 1000000007

int main(void) {
    string A, B, C;
    cin >> A >> B >> C;
    cout << A[0] << B[1] << C[2] << endl;
    return 0;
}


Measured memory_bytes: 256
#include<iostream>

using namespace std;
int main()
{
  int n,cnt=1,min;
  cin >> n;
  int p;
  for(int i=0; i<n; i++)
  {
    cin >> p;
    if(i==0){
      min = p;
      continue;
    }
    
    if(min > p){
      min = p;
      cnt++;
    }
    
  }
  cout << cnt << endl;
  return 0;
  
}

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

const Long MX = 5001;

Long A[MX];
Long cel[MX][200];
Long ans[MX][MX];
pair<Long,Long> st[MX<<2];

void build(Long l, Long r, Long nodo, Long t){
	if(l == r){
		st[nodo] = {cel[l][t],l};
		return;
	}
	Long med = (l+r)/2;
	build(l,med,nodo*2,t);
	build(med+1,r,nodo*2+1,t);
	st[nodo] = max(st[nodo * 2],st[2 * nodo + 1]);
	return;
}

pair<Long,Long> query(Long ini, Long fin, Long l, Long r, Long nodo){
	if(fin<l || r<ini) return {0ll,0ll};
	if(ini<=l && r<=fin) return st[nodo];
	Long med=(l+r)/2;
	pair<Long,Long> L = query(ini,fin,l,med,nodo*2);
	pair<Long,Long> R = query(ini,fin,med+1,r,nodo*2+1);
	return max(L,R);
}

void updateAns(Long l, Long r, Long n){
	if(l > r) return;
	pair<Long,Long> aux = query(l,r,0,n-1,1);
	Long mnx = l;
	Long mny = aux.second;
	Long mxx = aux.second;
	Long mxy = r;
	//cout << l << " " << r << " " << aux.first << " " << aux.second << " -> " << mnx << " " << mny << " | " << mxx << " " << mxy << endl;
	ans[mnx][mny] += aux.first;
	ans[mnx][mxy + 1] -= aux.first;
	ans[mxx + 1][mny] -= aux.first;
	ans[mxx + 1][mxy + 1] += aux.first;
	updateAns(l,aux.second - 1,n);
	updateAns(aux.second + 1,r,n);
	return;
}

int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	cout.precision(10);
	cout << fixed;
	
	Long n, m, x;
	cin >> n >> m;
	A[0] = 0;
	for(Long i = 1; i < n; i++){
		cin >> A[i];
		A[i] = A[i] + A[i-1];
	}
	
	for(Long i = 0; i < n; i++){
		for(Long j = 0; j < m; j++){
			cin >> cel[i][j];
		}
	}
	
	for(Long i = 0; i < m; i++){
		build(0,n-1,1,i);
		updateAns(0,n-1,n);
	}
	
	Long rp = 0;
	for(Long i = 0; i < n; i++){
		for(Long j = 0; j < n; j++){
			ans[i][j] = ans[i][j] + (i != 0 ? ans[i-1][j] : 0) + (j != 0 ? ans[i][j-1] : 0) - (i != 0 && j != 0 ? ans[i-1][j-1] : 0);
			if(i <= j) rp = max(rp,ans[i][j] - (A[j] - A[i]));
		}
	}
	
	cout << rp << "\n";
	return 0;
}


Measured memory_bytes: 203776
/*
 * ITP1_6_A.cpp
 *
 *  Created on: Apr 20, 2018
 *      Author: 13743
 */

#include <iostream>

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





Measured memory_bytes: 3088
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {

		new Main().run();
	}

	private void run() {
		Scanner scanner = new Scanner(System.in);
		while (true) {
			int n = scanner.nextInt();
			if (n == 0)
				break;
			int year = scanner.nextInt();
			int ans = 0;
			double max = 0;
			for (int i = 0; i < n; i++) {
				int id = scanner.nextInt();
				int r = scanner.nextInt();
				int t = scanner.nextInt();
				double a = 0;
				if (t == 1)
					a = 1 + year * r / 100.0;
				else
					a = Math.pow(1 + r / 100.0, year);
				if (a > max) {
					max = a;
					ans = id;
				}
			}
			System.out.println(ans);
		}
	}
}

Measured memory_bytes: 35948
#include <stdio.h>
int main(){
    int n, i, min, maxProfit;
    scanf("%d", &n);
    int input[n];
    for(i=0;i<n;i++){
        scanf("%d", &input[i]);
    }
    min = input[0];
    maxProfit = input[1] - min;
    for(i=1;i<n;i++){
        if(input[i] - min > maxProfit) maxProfit = input[i] - min;
        if(input[i] < min) min = input[i];
    }
    printf("%d\n",maxProfit);
    return 0;
}


Measured memory_bytes: 2552
#include <string.h>
#include <iostream>
using namespace std;

long long n, q, x, y, m = 1;
long long a[300000];

void add(long long x, long long y) {
	long long k = m + x - 1;
	a[k] += y;
	while (k > 0) {
		k = (k - 1) / 2;
		a[k] = a[k * 2 + 1] + a[k * 2 + 2];
	}
}

long long gs(long long x, long long y, long long k, long long l, long long r) {
	if (x <= l && y >= r)
		return a[k];
	else if (x >= r || y <= l)
		return 0;
	else {
		long long lm = gs(x, y, k * 2 + 1, l, (l + r) / 2);
		long long rm = gs(x, y, k * 2 + 2, (l + r) / 2, r);

		return lm + rm;
	}
}

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

	while (m <= n)
		m *= 2;

	memset(a, 0, sizeof(a));

	for (int j = 0; j < q; j++) {
		int p;
		cin >> p;

		if (p == 0) {
			cin >> x >> y;
			add(x - 1, y);
		}
		else if (p == 1) {
			cin >> x >> y;
			cout << gs(x - 1, y, 0, 0, m) << endl;
		}
	}

	return 0;
}


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

using namespace std;
typedef long long LL;
typedef pair<int,int> pii;

#define pb push_back
#define eb emplace_back
#define mp make_pair
#define fi first
#define se second

template<class T, class... Args>
auto create(size_t n, Args&&... args) {
	if constexpr(sizeof...(args) == 1)
		return vector<T>(n, args...);
	else
		return vector(n, create<T>(args...));
}

void __print(int x) {cerr << x;}
void __print(long x) {cerr << x;}
void __print(long long x) {cerr << x;}
void __print(unsigned x) {cerr << x;}
void __print(unsigned long x) {cerr << x;}
void __print(unsigned long long x) {cerr << x;}
void __print(float x) {cerr << x;}
void __print(double x) {cerr << x;}
void __print(long double x) {cerr << x;}
void __print(char x) {cerr << '\'' << x << '\'';}
void __print(const char *x) {cerr << '\"' << x << '\"';}
void __print(const string &x) {cerr << '\"' << x << '\"';}
void __print(bool x) {cerr << (x ? "true" : "false");}

template<typename T, typename V>
void __print(const pair<T, V> &x) {cerr << '{'; __print(x.first); cerr << ','; __print(x.second); cerr << '}';}
template<typename T>
void __print(const T &x) {int f = 0; cerr << '{'; for (auto &i: x) cerr << (f++ ? "," : ""), __print(i); cerr << "}";}
void _print() {cerr << "]\n";}
template <typename T, typename... V>
void _print(T t, V... v) {__print(t); if (sizeof...(v)) cerr << ", "; _print(v...);}

#ifdef OJ
#define debug(x...) cerr << "[" << #x << "] = ["; _print(x)
#else
#define debug(x...)
#endif
#define all(x) (x).begin(), (x).end()
#define rsort(x) sort((x).rbegin(), (x).rend())
#define sz(x) ((int)x.size())
#define fori(i, n) for (int i = 0; i < (int)(n); ++i)
#define ford(i, n, e) for (int i = (int)(n); i >= (int)(e); --i)
#define fore(i, a, b) for (int i = (int)(a); i <= (int)(b); ++i)
template<typename T> bool mmax(T &m, const T q) { if (m < q) {m = q; return true;} else return false; }
template<typename T> bool mmin(T &m, const T q) { if (m > q) {m = q; return true;} else return false; }
#define RETURN(x) do{cout << (x) << '\n'; return 0;}while(0)

const char en = '\n';
const int MOD = 0;
const int MAXN = 0;
const int INF = 1e9+1;

int solve() {
    int n; cin >> n;
    int c = 0;
    fori(i,n) {
        int a,b; cin >> a >> b;
        if(a == b) c++;
        else c = 0;
        if(c == 3) RETURN("Yes");
    }
    cout << "No\n";
    return 0;
} 

int main(int argc, char **argv) {
#ifdef OJ
    freopen("input.txt", "rt", stdin);
    //freopen("output.txt", "wt", stdout);
#endif
    ios::sync_with_stdio(false);
    cin.tie(0);

    int ntest = 1;
    //cin >> ntest;
    fori(test, ntest) {
        //cout << "Case #" << test+1 << ": ";
        solve();
    }

    return 0;
}


Measured memory_bytes: 3648
#include<bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < n ; i++)
#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define whole(f, x, ...) ([&](decltype((x)) whole) { return (f)(begin(whole), end(whole), ## __VA_ARGS__); })(x) // decltypeで型取得、引数があればva_argsのところに入れる
using namespace std;
typedef long long ll; // long longをllでかけるようにした
const int INF = 1e9;
const double PI = 3.1415926535;
const int MOD = 1000000007; // 計算してからmodで割る ans = (ans * a) % mod
#define int long long
template <typename T = long long > T in () { T x; cin >> x; return(x);}
// int a = in() のように使うlong long以外の型の時はstirng s = in<string>()のように型を指定する

long long modPow(long long a, long long n, long long p){
    if(n == 1) return a % p;
    if(n % 2 == 1) return (a * modPow(a, n - 1, p)) % p;
    long long t = modPow(a, n / 2, p) % p;
    return (t * t) % p;
}

long long modInv(long long a, long long p){
    return modPow(a, p - 2, p);
}

long long modCom(long long n, long long r, long long p){
    long long ue = 1, shita = 1;
    for(int i = 0; i < r; i++){
        ue = (ue *(n - i)) % p;
        shita = (shita * (r - i)) % p;
    }
    return ue * modInv(shita, p) % p;
}

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

    long long ans = (modPow(2, n, MOD) - 1 - modCom(n, a, MOD)) % MOD;
    if(ans < 0) ans += MOD;

    ans = (ans - modCom(n, b, MOD)) % MOD;
    if(ans < 0) ans += MOD;
    
    cout << ans << endl;

}

Measured memory_bytes: 256
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.lang.reflect.Array;
import java.util.Arrays;
import java.util.Scanner;

public class Main {

  public static void main(String[] args) throws FileNotFoundException {

//    Scanner cin = new Scanner(new FileReader("input.txt"));
    Scanner cin = new Scanner(System.in);

    int n = cin.nextInt();
    long[] hp = new long[n];

    for (int i=0;i<n;i++) {
      hp[i] = cin.nextLong();
    }

    Arrays.sort(hp);

    if (hp[0] == 1) {
      System.out.println(1);
      return;
    }
    else {
      long flag = hp[0];
      int start = 0;
//      System.out.println(flag);
      while (true) {

        for (int i=start+1;i<n;i++) {
          hp[i] = hp[i]%flag;
        }
        Arrays.sort(hp);
//        System.out.println(Arrays.toString(hp));
        int zeroCount = 0;
        while (hp[zeroCount]==0) {
          zeroCount++;
        }
        if (zeroCount==n-1) {
          System.out.println(hp[n-1]);
          return;
        }
        else {
          flag = hp[zeroCount];
          start = zeroCount;
          if (flag==1) {
            System.out.println(flag);
            return;
          }
        }

      }
    }

  }

}


Measured memory_bytes: 51412
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.StringTokenizer;
import java.io.IOException;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 */
public class Main {
	public static void main(String[] args) {
		InputStream inputStream = System.in;
		OutputStream outputStream = System.out;
		FastScanner in = new FastScanner(inputStream);
		PrintWriter out = new PrintWriter(outputStream);
		TaskB solver = new TaskB();
		solver.solve(1, in, out);
		out.close();
	}

	static class TaskB {
		int[] firstEdge;
		int[] edgeNxt;
		int[] edgeDst;
		int numEdges;
		boolean[] used;

		public void solve(int testNumber, FastScanner in, PrintWriter out) {
			int n = in.nextInt();
			int m = in.nextInt();
			firstEdge = new int[n];
			Arrays.fill(firstEdge, -1);
			edgeNxt = new int[2 * m];
			edgeDst = new int[2 * m];
			for (int i = 0; i < m; i++) {
				int a = in.nextInt() - 1;
				int b = in.nextInt() - 1;
				addEdge(a, b);
				addEdge(b, a);
			}
			used = new boolean[2 * m];
			for (int i = 0; i < n; i++) {
				while (true) {
					int e = firstEdge[i];
					while (e >= 0 && used[e]) {
						e = edgeNxt[e];
						firstEdge[i] = e;
					}
					if (e < 0) {
						break;
					}
					int j = i;
					boolean foundCycle = false;
					while (true) {
						e = firstEdge[j];
						while (e >= 0 && used[e]) {
							e = edgeNxt[e];
							firstEdge[j] = e;
						}
						if (e < 0) {
							break;
						}
						used[e] = true;
						used[e ^ 1] = true;
						j = edgeDst[e];
						if (j == i) {
							foundCycle = true;
							break;
						}
					}

					if (!foundCycle) {
						out.println("NO");
						return;
					}
				}
			}
			out.println("YES");
		}

		private void addEdge(int a, int b) {
			int e = numEdges++;
			edgeNxt[e] = firstEdge[a];
			edgeDst[e] = b;
			firstEdge[a] = e;
		}

	}

	static class FastScanner {
		private BufferedReader in;
		private StringTokenizer st;

		public FastScanner(InputStream stream) {
			in = new BufferedReader(new InputStreamReader(stream));
		}

		public String next() {
			while (st == null || !st.hasMoreTokens()) {
				try {
					String rl = in.readLine();
					if (rl == null) {
						return null;
					}
					st = new StringTokenizer(rl);
				} catch (IOException e) {
					throw new RuntimeException(e);
				}
			}
			return st.nextToken();
		}

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

	}
}



Measured memory_bytes: 46940
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<(n);i++)
typedef long long ll;
template<typename T>
void print(T x) {
    cout << x << endl;
}
int main(void) {
    vector<int> x(5);
    rep(i, 5) cin >> x[i];
    sort(x.begin(), x.end());
    int k; cin >> k;
    if(k >= x[4] - x[0]) print("Yay!");
    else print(":(");
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <cmath>
using namespace std;
int main() {
    int ans = 753;
    string s;
    cin >> s;
    for (int i = 0; i <= s.size() - 3; i++) {
        int t = abs(753 - stoi(s.substr(i, 3)));
        if (t < ans) ans = t;
    }
    cout << ans << endl;
}


Measured memory_bytes: 256
use std::cmp;
use std::collections::*;
use std::i32;
use std::io::{self, Read};
use std::mem;

const MOD: usize = 1000000007;

fn main() {
    let stdin = io::stdin();
    let mut sc = Scanner::new(stdin.lock());

    let n: usize = sc.read().unwrap();
    let k: usize = sc.read().unwrap();
    let x: Vec<i64> = sc.read_vec(n).unwrap();

    let mut ans = MOD as i64;
    for i in 0..n - k + 1 {
        let l = x[i];
        let r = x[i + k - 1];

        ans = cmp::min(ans, l.abs() + (r - l).abs());
        ans = cmp::min(ans, r.abs() + (r - l).abs());
    }
    println!("{}", ans);
}

struct Scanner<R: Read> {
    reader: R,
}

impl<R: Read> Scanner<R> {
    fn new(reader: R) -> Scanner<R> {
        Scanner { reader: reader }
    }

    fn read<T: std::str::FromStr>(&mut self) -> Option<T> {
        self.reader
            .by_ref()
            .bytes()
            .map(|b| b.unwrap() as char)
            .skip_while(|c| c.is_whitespace())
            .take_while(|c| !c.is_whitespace())
            .collect::<String>()
            .parse()
            .ok()
    }

    fn read_vec<T: std::str::FromStr>(&mut self, n: usize) -> Option<Vec<T>> {
        (0..n).map(|_| self.read()).collect()
    }

    fn read_vec2d<T: std::str::FromStr>(&mut self, m: usize, n: usize) -> Option<Vec<Vec<T>>> {
        (0..m).map(|_| self.read_vec(n)).collect()
    }

    fn read_board(&mut self, n: usize) -> Option<Vec<Vec<char>>> {
        (0..n)
            .map(|_| {
                self.read::<String>()
                    .map(|s| s.chars().collect::<Vec<char>>())
            })
            .collect()
    }
}


Measured memory_bytes: 4352
#include <stdio.h>
#include <stdlib.h>
int compare_int(const void *a, const void *b){return *(int*)a - *(int*)b;}
int main(void){
	int n,i,ans=0;
	scanf("%d",&n);
	int s[n];
	for(i=0;i<n;i++){
		scanf("%d",&s[i]);
		ans += s[i];
	}
	if(ans%10==0){
		qsort(s, n, sizeof(int), compare_int);
		for(i=0;i<n;i++){
			ans -= s[i];
			if(ans%10!=0)break;
			ans += s[i];
		}
		if(i==n)ans=0;
	}
	
	printf("%d",ans);
	return 0;
}

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

#define rep(i,n) for(int i=0;i<(n);++i)
#define reps(i,n) for(int i=1;i<=(n);++i)
#define all(x) (x).begin(),(x).end()
#define int long long
using pii = pair<int,int>;
constexpr int INF  = 0x3f3f3f3f;
constexpr long long LINF = 0x3f3f3f3f3f3f3f3fLL;

signed main(){
    int k,t;
    cin >> k >> t;
    int a,x=0;
    int maxv = -100,minv = INF;
    rep(i,t){
        cin >> a;
        maxv = max(maxv,a);
        minv = min(minv,a);
    }   
    if(maxv - (k - maxv ) -1 < 0) cout << 0 << '\n';
    else cout << maxv - (k - maxv) -1 << '\n';
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef		 long long int    ll;
typedef		 long double   ld;
typedef		vector<ll>      vll;
#define     fi              first
#define     print(v)        for(ll i:v) cout<<i<<ss
#define     se              second
#define		pb              push_back
#define		nn              "\n"
#define		all(p)          p.begin(),p.end()
#define		zz(v)           (ll)v.size()
#define 	S(a)            scanf("%lld",&a)
#define 	SS(a,b)         scanf("%lld %lld",&a,&b)
#define 	SSS(a,b,c)      scanf("%lld %lld %lld",&a,&b,&c)
#define		ss              ' '
#define     pii             pair<ll,ll>
#define		gcd(a,b)        __gcd(a,b)
#define		lcm(a,b)        (a*b)/gcd(a,b)
const double eps = 1e-8;


ll mod=1e9+7;

int main()
{
    ll n;
    cin>>n;
    if(n==1)
    {
        cout<<0<<nn;
        return 0;
    }
    if(n==2)
    {
        cout<<2<<nn;
        return 0;
    }

    ll sum=1;
    ll t=n;
    while(t--)
    {
        sum=(sum*10)%mod;
    }
    ll s1=1;
    t=n;
    while(t--)
    {
        s1=(s1*9)%mod;
    }
    s1=(s1*2)%mod;

    ll s2=1;
    t=n;
    while(t--)
    {
        s2=(s2*8)%mod;
    }
    s1=(s1-s2+mod)%mod;

    cout<<(sum-s1+mod)%mod<<nn;






}


/* Final check before submit :

1. array size or integer overflow,like uninitialised 0 index.

2. Think twice,code once.check all possible counter test case.

3. Be careful about corner case! n=1?k=1? something about 0?

4. avoid stupid mistake!complexity(t/m)?precision error?submit same code twice?

5. if got WA than remember that you are missing something common.
   *** Be confident!!! who knows? may be your one step back to AC ***
4. minus mod ans=(ans-k+mod)%mod;

*/






Measured memory_bytes: 3572
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define mp make_pair
#define pb push_back
#define ff first
#define ss second
#define vi vector<int>
#define vint vector<int> 
#define inf 1000000000
#define mod 1000000007

int power(int a, int b)
{
    int prod = 1;
    while(b)
    {
        if(b&1)
        prod = (prod*a);
        a = (a*a);
        b >>= 1;
    }
    return prod;
}

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

	
	dp[0] = 0;
	dp[1] = abs(a[0]-a[1]);
	for(int i = 2 ; i < n ; i++)
		for(int j = i-1 , w = 0  ; w < k && j >= 0 ; j-- , w++)
		dp[i] = min(dp[i] , dp[j]+abs(a[j]-a[i]));

	cout << dp[n-1];
 	return 0;

}




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

#define int long long
#define ll long long
#define rep(i,n) for (int i = 0; i < (n); i++)  
#define rrep(i,n) for (int i = (n)-1; i >= 0; i--)
#define rap(i,a,n) for (int i = a; i < (n); i++) 
#define rrap(i,n,a) for (int i = (n)-1; i >= a; i--) 
#define INT_MAX 2147483647
#define LL_MAX 9223372036854775807
#define MOD 1000000007

typedef vector<int> vi;  
typedef pair<int,int> ii;  
typedef vector<ii> vii;  
typedef list<int> li;  
typedef unordered_map<int,int> mii;

vector<vi> dp,v;

int32_t main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);

    int h,w;
    string s;
    char c;
    cin >> h >> w;
    v.assign(h,vector<int>(w,0));
    dp.assign(h,vector<int>(w,0));

    rep(i,h) {
        cin >> s;
        rep(j,w) {
            v[i][j] = s[j];
        }
    }

    dp[0][0] = 1;

    rep(i,h) {
        rep(j,w) {
            if (i==h-1) {
                if (j==w-1) continue;
                if (v[i][j+1] == '#') continue;
                dp[i][j+1] = (dp[i][j] + dp[i][j+1])%MOD;
            }
            else {
                if (j==w-1) {
                    if (v[i+1][j] == '#') continue;
                    dp[i+1][j] = (dp[i][j] + dp[i+1][j])%MOD;
                }
                else {
                    if (v[i+1][j] != '#') {
                        dp[i+1][j] = (dp[i][j] + dp[i+1][j])%MOD;
                    }
                    if (v[i][j+1] != '#') {
                        dp[i][j+1] = (dp[i][j] + dp[i][j+1])%MOD;
                    }
                }
            }
        }
    }

    cout << dp[h-1][w-1] << '\n';

    return 0;
    //compile: g++ -std=c++14 -O2 -Wall NAME.cpp -o NAME
}

Measured memory_bytes: 16000
typedef long long ll;
#include <bits/stdc++.h>
using namespace std;
int main() {
    ll n;
    string s;
    std::cin >> n;
    std::cin >> s;
    const ll MOD = 998244353;
    
    vector<ll> cnt(3,0);
    vector<ll> cnt2(3,0);

    ll result = 1;
    
    for (int i = 0; i < 3*n; i++) {
        int x;
        if(s[i] == 'R') x = 0;
        if(s[i] == 'G') x = 1;
        if(s[i] == 'B') x = 2;
        int x1,x2;
        x1 = (x+1)%3;
        x2 = (x+2)%3;
        
        // 合体できるやつがいる
        if( cnt2[x] >= 1 ){
            // その数だけ自由度がある
            result *= cnt2[x];
            result %= MOD;
            cnt2[x]--;
        // 単体でいる
        }else if( cnt[x1] >= 1 ){
            // どの単体と合体するか
            result *= cnt[x1];
            result %= MOD;
            cnt2[x2]++;
            cnt[x1]--;
        }else if( cnt[x2] >= 1 ){
            result *= cnt[x2];
            result %= MOD;
            cnt2[x1]++;
            cnt[x2]--;
        }else{
            cnt[x]++;
        }
    }
    
    for (int i = 1; i <= n; i++) {
        result *= i;
        result %= MOD;
    }
    
    std::cout << result << std::endl;
}

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


int main()
{
   int h1,m1,h2,m2,k;
   cin >> h1>>m1>>h2>>m2>>k;
   int a,b;
   a = h2-h1;
   b = m2-m1;
   int c;
   c = (a*60) + b;
   cout << c-k << endl;
  return 0;
}

Measured memory_bytes: 3620
#include<bits/stdc++.h>
#define int  long long
using namespace std;
int n,m,ans[100010],x[100010],y[100010],f[100010],num[100010];
int find(int x)
{
	if(f[x]==x)
		return x;
	return f[x]=find(f[x]);
}
signed main()
{
	scanf("%lld%lld",&n,&m);
	for(register int i=1;i<=m;i++)
		scanf("%lld%lld",&x[i],&y[i]);
	ans[m]=n*(n-1)/2;
	for(register int i=1;i<=n;i++)
	{
		f[i]=i;
		num[i]=1;
	}
	for(register int i=m;i>=1;i--)
	{
		int u=find(x[i]),v=find(y[i]);
		ans[i-1]=ans[i];
		if(u!=v)
		{
			f[u]=v;
			ans[i-1]-=num[u]*num[v];
			num[v]+=num[u];
		}
	}
	for(register int i=1;i<=m;i++)
		printf("%lld\n",ans[i]);
	return 0;
}

Measured memory_bytes: 5248
#include <stdio.h>
 
#define inf 200000
#define NIL -1000000
#define WHITE 9999999
#define BLACK 8888888
 
int prim(int, int(*)[], int[], int[], int[]);
 
int main(){
  int i,j,n,ans;
  scanf("%d", &n);
 
  int w[n][n];
  int d[n];
  int pi[n];
  int color[n];
 
  for(i = 0; i < n; i++)
    for(j = 0; j < n; j++)
      scanf("%d", &w[i][j]);
 
  ans = prim(n, w, d, pi, color);
  printf("%d\n", ans);
  return 0;
}
 
int prim(int n, int w[n][n], int d[n], int pi[n], int color[n]){
  int i,j,u,ans = 0;
  int mincost;
  for(u = 0; u < n; u++){
    d[u] = inf;
    pi[u] = NIL;
    color[u] = WHITE;
  }
  d[0] = 0;
  while(1){
    mincost = inf;
    for(i = 0; i < n; i++){
      if(color[i] != BLACK && d[i] < mincost){
        mincost = d[i];
        u = i;
      }
    }
    if(mincost == inf)
      break;
 
    color[u] = BLACK;
 
    for(j = 0; j < n; j++){
      if(color[j] != BLACK && w[u][j] < d[j] && w[u][j] != -1){
        pi[j] = u;
        d[j] = w[u][j];
      }
    }
  }
 
  for(i = 0; i < n; i++)
    ans += d[i];
 
  return ans;
}

Measured memory_bytes: 640