akhauriyash/Code-Regression huggingface dataset:
s = list(input())
for i in range(4):
    if i == 0:
        y = int(s[i])*1000
    elif i == 1:
        y += int(s[i])*100
    elif i == 2:
        y += int(s[i])*10
    else:
        y += int(s[i])
for i in range(5,7):
    if i == 5:
        m = int(s[i])*10
    else:
        m += int(s[i])
for i in range(8,10):
    if i == 8:
        d = int(s[i])*10
    else:
        d += int(s[i])
if y <= 2019:
    if m <= 4:
        if d <= 30:
            print("Heisei")
        else:
            print("TBD")
    else:
        print("TBD")

else:
    print("TBD")

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

int bubble(vector<int>&);

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

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

    int cnt = bubble(a);

    for (int i = 0; i < n - 1; i++) {
        cout << a[i] << " ";
    }
    cout << a[n - 1] << endl << cnt << endl;

    return 0;
}

int bubble(vector<int>& a) {
    int cnt = 0;
    bool flag = true;
    while(flag == true) {
        flag = false;
        for (int i = a.size() - 1; i > 0; i--) {
            if (a[i] < a[i - 1]) { 
                int temp = a[i];
                a[i] = a[i - 1];
                a[i - 1] = temp;
                flag = true;
                cnt++;
            }
        }
    }
    return cnt;
}



Measured memory_bytes: 3112
a,b,c,d,e=map(int,input().split())
ret = 10**18
for i in range(max(d,e)+1):
  cnt = 2*i*c
  cnt += max(d-i,0)*a
  cnt+= max(0,e-i)*b
  ret=min(ret,cnt)
print(ret)

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

using namespace std;

int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n, ans = 0;
    cin >> n;
    vector < int > a(n + 1), b(n + 1, 100000);
    for(int i = 1; i < n; ++i) cin >> a[i];
    for(int i = 2; i <= n; ++i) {
        b[i] = min(a[i - 1], b[i]);
        b[i - 1] = min(a[i - 1], b[i - 1]);
    }
    for(int i = 1; i <= n; ++i) ans += b[i];
    cout << ans << "\n";
    return 0;
}


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

#define ll long long int
#define ld long double
#define fastIO ios_base::sync_with_stdio(false); cin.tie(nullptr)
#define pb push_back

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

int main() {
    fastIO;
    string s;
    cin >> s;
    if (s[s.length() - 1] != 's') cout << s + 's';
    else cout << s + "es";


}


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

int main(){
  int h,w; cin>>h>>w;
  vector<string> a(h);
  for(int i=0; i<h; i++)cin>>a[i];

  vector<bool> hi(h,false);
  vector<bool> wi(w,false);

  for(int i=0; i<h; i++){
    for(int j=0; j<w; j++){
      if(a[i][j] == '#'){
        hi[i] = true;
        wi[j] = true;
      }
    }
  }

  for(int i=0; i<h; i++){
    if(hi[i]){
      for(int j=0; j<w; j++){
        if(wi[j]){
          cout<<a[i][j];
        }
      }
      cout<<endl;
  }
}

return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cstdlib>
#include<vector>
#include<map>
#include<queue>
#include<string>
#include<numeric>
#include<sstream>
#include<cmath>
using namespace std;
long long int mod = 1e9;

int main(){
  int a, b, t; cin >> a >> b >> t;
  cout << b * (t/a) << endl;

  return 0;
}




// EOF


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define r1(i, n) for (int i=0;i<n;i++)
#define r2(i, n) for (int i=1;i<n+1;i++)
#define intc(n) int n; cin >> n;
#define ll long long
#define llc(n) ll n; cin >> n;
#define stringc(s) string s; cin >> s;
using namespace std;
int main() {
  int k,a,b;
  cin >> k >> a >> b;
  string s="NG";
  if(a+k<=b) s="OK";
  else {
    a=a%k;
    b=b%k;
    if(a>b || a*b==0) s="OK";
  }
  cout << s << endl;
}

Measured memory_bytes: 3628
#include<stdio.h>
 
int main(void){
  long int abc[5];
  long int n;
  long int time = 4;
  int i;
  
  scanf("%ld%ld", &n, &abc[0]);
  long int min = abc[0];
  for(i = 1;i < 5;i++){
    scanf("%ld", &abc[i]);
    if(min > abc[i]){
      min = abc[i];
    }
  }
  
  if(n % min != 0){
    time += n / min + 1;
  }
  else{
    time += n / min;
  }
 
  printf("%ld\n", time);
  return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
#define For(i,a,b) for(ll i=(a); i<(b); ++i)
using namespace std;
typedef unsigned long long ll;

int main(){
	ll n,k;
	cin>>n>>k;
	ll a[n];
	For(i,0,n)
		cin>>a[i];
	if (k>=n)
		cout<<0;
	else{
		sort(a,a+n);
		ll sum=0;
		For(i,0,n-k)
			sum+=a[i];
		cout<<sum;
	}
	return 0;
}

Measured memory_bytes: 1792
#include <stdio.h>

int main(void) {

  long n,a,cur = 0,step = 0;
  scanf("%ld", &n);
  for (long i = 0; i < n; i++) {
    scanf("%ld", &a);
    if (a < cur) {
      step += cur-a;
    } else {
      cur = a;
    }
  }
  printf("%ld\n", step);

  return 0;
}

Measured memory_bytes: 1736
package main

import (
	"bufio"
	"fmt"
	"log"
	"math"
	"os"
	"strconv"
	"strings"
)

type color int

const (
	white color = iota // 未訪問
	mst                // MSTとして確定
)

// 頂点
type node struct {
	matrix   []int // 隣接行列
	minToMst int   // MSTへの重み最小値
	parent   int   // 最小値の相手
	color    color
}

func main() {
	scanner := bufio.NewScanner(os.Stdin)
	n := eGetInt(scanner)

	nodes := make([]node, n)
	for i := 0; i < n; i++ {
		nodes[i].matrix = eAtoi((strings.Fields(eGetline(scanner))))
		nodes[i].parent = -1
		nodes[i].minToMst = math.MaxInt16
		nodes[i].color = white
	}

	// 初回はnode[0]がMSTに入るように,minToMstを設定
	nodes[0].minToMst = 0
	for { // 全部チェックするまで

		// どの頂点を新たにMSTに取り込むか
		min := math.MaxInt16
		u := -1
		for i := 0; i < n; i++ {
			if nodes[i].color == mst {
				continue
			}
			if nodes[i].minToMst < min {
				u = i
				min = nodes[i].minToMst
			}
		}

		if u == -1 {
			break
		}
		// MSTに追加する頂点決定
		nodes[u].color = mst

		// MSTに属していない頂点それぞれについて,MSTとの最小の重みを更新
		for i := 0; i < n; i++ {
			if nodes[i].color == mst {
				continue
			}
			if nodes[i].matrix[u] == -1 {
				// 接してない
				continue
			}
			if nodes[i].matrix[u] < nodes[i].minToMst {
				// node[u]との重みが最小
				nodes[i].minToMst = nodes[i].matrix[u]
				nodes[i].parent = u
			}
		}
	}

	sum := 0
	for _, v := range nodes {
		// node[0]はparentが入っていない
		if v.parent != -1 {
			sum += v.matrix[v.parent]
		}
	}
	fmt.Println(sum)
}

func eGetInt(scanner *bufio.Scanner) int {
	t := eAtoi(strings.Fields(eGetline(scanner)))
	return t[0]
}

func eGetline(p *bufio.Scanner) string {
	if !p.Scan() {
		if err := p.Err(); err != nil {
			log.Fatal(err.Error())
		}
		return ""
	}
	return p.Text()
}

func eAtoi(s []string) []int {
	ints := make([]int, len(s))
	var err error
	for i, e := range s {
		ints[i], err = strconv.Atoi(e)
		if err != nil {
			log.Fatal(err.Error())
		}
	}
	return ints
}



Measured memory_bytes: 1420
//From Naruto to Hokage
//#include <RJ>
#include<bits/stdc++.h>
using namespace std;

#define ll          long long
#define pb          push_back
#define eb          emplace_back
#define endl        '\n'
#define mii         map<ll,ll>
#define pii         pair<ll,ll>
#define vi          vector<ll>
#define all(a)      (a).begin(),(a).end()
#define F           first
#define S           second
#define sz(x)       (ll)x.size()
#define hell        1000000007
#define INF         (1ll<<60)
#define rep(i,a,b)  for(ll i=a;i<=b;i++)
#define rrep(i,a,b)  for(ll i=a;i>=b;i--)
#define present(c,x) ((c).find(x) != (c).end())
#define cpresent(c,x) (find(all(c),x) != (c).end())
#define ios ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define time        cerr << "\nTime elapsed: " << 1000 * clock() / CLOCKS_PER_SEC << "ms\n";
ll gcd(ll a, ll b) { return b == 0 ? a : gcd(b, a % b); }
ll lcm(ll a, ll b) { return a * (b / gcd(a, b)); }
const int N=100005;
void solve(){
    ll n,a,b,c;
    cin>>n;
    ll dp[n+1][3];
    memset(dp,0,sizeof(dp));
    rep(i,1,n){
        cin>>a>>b>>c;
        dp[i][0]=a+max(dp[i-1][1],dp[i-1][2]);
        dp[i][1]=b+max(dp[i-1][0],dp[i-1][2]);
        dp[i][2]=c+max(dp[i-1][0],dp[i-1][1]);
    }
    cout<<max({dp[n][0],dp[n][1],dp[n][2]});
}
signed main()
{
    ios
    int TESTS=1;
    //cin>>TESTS;
    while(TESTS--){
        solve();
    }
    time
    return 0;
}

Measured memory_bytes: 2560
/*
	Created by Rahul Goel.
*/
 
#include <iostream>
#include <vector>
#include <cstring>
#include <string>
#include <queue>
#include <deque>
#include <stack>
#include <algorithm>
#include <cmath>
 
using namespace std;
typedef long long ll;
ll mod = 1000000007;
const int INF = 1000000000;
 
#define pii pair < int, int >
#define vi vector < int >
#define vb vector < bool >
#define vvi vector < vector < int > >
#define vvb vector < vector < bool > >
#define vpii vector < pair < int, int > >
#define vvpii vector < vector < pair < int, int > > >
#define pb push_back
#define f first
#define s second
#define mp make_pair

int main(){
    int x;
    cin >> x;
    int ans = (x/500)*1000 + ((x%500)/5)*5;
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long
#define MODV 1000000007
#define INFLL LLONG_MAX // 9223372036854775807
#define EPS 1e-9
#define rep(i, n) for(ll i=0, i##_len=(ll)(n); i<i##_len; i++)
#define repf(i, n) for(ll i=1, i##_len=(ll)(n+1); i<i##_len; i++)
#define all(v) v.begin(), v.end()
#define endl "\n"
#define vi vector<ll>
#define vvi vector<vector<ll>>
#define Yes() cout << "Yes" << endl
#define YES() cout << "YES" << endl
#define No() cout << "No" << endl
#define NO() cout << "NO" << endl
#define Init() std::ios::sync_with_stdio(false); std::cin.tie(0); std::cout<<fixed<<setprecision(15);
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; }
using namespace std;

// 4方向（左、右、上、下）（左上を0, 0とした場合）
vector<long long> dx = {-1, 1, 0, 0};
vector<long long> dy = { 0, 0, 1, -1};

int main(){
    Init();
    string s; ll x, y;
    cin >> s >> x >> y;
    ll n = s.size();
    vector<int> tcnt;
    ll cnt = 0;
    for(ll i=0; i<n; i++){
        if(s[i] == 'F') cnt++;
        else{
            tcnt.push_back(cnt);
            cnt = 0;
        }
    }
    tcnt.push_back(cnt);

    // tcnt[0]は右方向、tcnt[1]は上下、tcnt[2]は左右...と移動可能場所を考えていく
    // (0, 0) -> (8000, 8000)として考える。
    // dp1; 左右で到達可能な場所 i回目でjに移動可能なら1
    // dp2; 上下で到達可能な場所 i回目でjに移動可能なら1
    vector<vector<int>> dp1((tcnt.size()+1)/2+1, vector<int>(16002)); dp1[0][8000] = 1;
    vector<vector<int>> dp2((tcnt.size()+1)/2+1, vector<int>(16002)); dp2[0][8000] = 1;

    rep(i, tcnt.size()){
        if(i == 0) dp1[i+1][8000+tcnt[0]] = 1;
        else if(i%2 == 1){
            // 上下移動の場合
            ll idx = i/2;
            for(ll j=1; j<=16000; j++) if(dp2[idx][j] == 1) dp2[idx+1][j+tcnt[i]] = 1, dp2[idx+1][j-tcnt[i]] = 1;
        }
        else{
            // 左右移動の場合
            ll idx = i/2;
            for(ll j=1; j<=16000; j++) if(dp1[idx][j] == 1) dp1[idx+1][j+tcnt[i]] = 1, dp1[idx+1][j-tcnt[i]] = 1;
        }
    }
    x += 8000, y += 8000;
    (dp1[dp1.size()-1][x] == 1 && dp2[dp2.size()-((tcnt.size()%2 == 0) ? 1 : 2)][y] == 1) ? Yes() : No();
    return 0;
}

Measured memory_bytes: 499684
#include <bits/stdc++.h>
#define ALL(A) (A).begin(), (A).end()
#define ll long long
#define rep(i, n) for (int i = 0; i < (n); i++)

using namespace std;

const ll mod = 1e9 + 7;

ll powmod(ll a,ll b,ll p){
    // a^b mod p を返す
    if(b==0 || a == 1)return 1;
    ll ret = 1;
    while(b){
        if(b%2==0){
            a = (a*a)%mod;
            b/=2;
        }else {
            ret *= a;
            ret %= mod;
            b--;
        }
    }
    return ret%mod;
}

vector<int> div(int x){
    vector<int> ret;
    for(int i=1;i*i<=x;i++){
        if(x%i==0){
            if(i*i==x)ret.push_back(i);
            else{
                ret.push_back(i);
                ret.push_back(x/i);
            }
        }
    }
    return ret;
}

ll d[100005];

int main(void){
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(20);
    ll n,k;
    cin >> n >> k;
    ll ans = 0;
    for(int i=k;i>0;i--){
        // gcd がiの倍数の数列の個数 cnt 
        ll cnt = (powmod(k/i,n,mod) - d[i] + mod)%mod;
        ans += (i * cnt) % mod;
        ans %= mod;
        auto v = div(i);
        for(auto x:v){
            d[x] += cnt;
            d[x] %= mod;
        }
    }
    cout << ans % mod << endl;
}

Measured memory_bytes: 4424
// https://cf17-final.contest.atcoder.jp/tasks/cf17_final_e
#include<iostream>
#include<vector>
#include<unordered_map>

#ifdef _GLIBCXX_DEBUG
#define cin cin_
#include<sstream>
namespace std{std::stringstream cin(R"(
20 17
)");}
#endif

int k; // maximum value of an element
int MOD=1000000007;
std::vector<int> kp1_xp;

std::vector<std::unordered_map<int,int>> g_mem;
int g(int p,int e){
	if(p==1){
		return (
			// if a[1]==0
			e +
			// if a[1]==1
			(e+1)
		)%MOD;
	}

	auto it=g_mem[p].find(e);
	if(it!=g_mem[p].end())return it->second;

	int ans=0;
	for(int i=0;i<=k;++i){
		// i = a[p]
		if(i>p){
			ans=(ans+g(p-1,e))%MOD; // this can be optimized?
		}else{
			int nStep=(i+e)/p;
			ans=(ans+g(p-1,e+nStep)+nStep*(int64_t)kp1_xp[p-1])%MOD;
		}
	}

	g_mem[p].emplace(e,ans);
	return ans;
}

int main(){
	std::ios::sync_with_stdio(false);std::cin.tie(nullptr);
	int n;std::cin>>n>>k;

	// init kp1_xp (kp1_xp[x] = (k+1)**x %MOD)
	kp1_xp.resize(n+1);
	kp1_xp[0]=1;
	for(int i=1;i<=n;++i)
		kp1_xp[i]=int64_t(k+1)*kp1_xp[i-1]%MOD;

	int sum_all=k*int64_t(k+1)/2 %MOD *kp1_xp[n-1] %MOD *n %MOD;
	// avg each position: k/2, n. of seq: (k+1)**n, n. of pos: n

	g_mem.resize(n+1);
	std::cout<<(sum_all+MOD-g(n,0))%MOD<<std::endl;
}


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

// iterator
#define REP(i,from, to) for(lli i=from;i<to;i++)
#define REPE(i,from, to) for(lli i=from;i<=to;i++)
#define REP_R(i,from, to) for(lli i=from;i>to;i--)
#define REPE_R(i,from, to) for(lli i=from;i>=to;i--)
#define REPIT(it,container) for(auto it = container.begin(); it != container.end(); it++)
#define REPIT_R(it,container) for(auto it = container.rbegin(); it != container.rend(); it++)

// input
#define cin1(x)             cin >> x
#define cin2(x, y)          cin >> x >> y
#define cin3(x, y, z)       cin >> x >> y >> z
#define ncin1(n, x)         REP(i, 0, n) {cin1(x[i]);}
#define ncin2(n, x, y)      REP(i, 0, n) {cin2(x[i], y[i]);}
#define ncin3(n, x, y, z)   REP(i, 0, n) {cin3(x[i], y[i], z[i]);}

// output
#define cout1(x)         cout << #x << ": " << x << endl;
#define cout2(x, y)      cout << #x << ": " << x << ", " << #y << ": " << y << endl;
#define cout3(x, y, z)   cout << #x << ": " << x << ", " << #y << ": " << y << ", " << #z << ": " << z << endl;;
#define ncout1(n, x)     REP(i, 0, n) {cout << #x << "[" << i << "]: "<< x[i] << endl;}

#define coutp(p)         cout << #p << ":" <<  " (" << p.first << ", " << p.second << ")" << endl;

// sort
#define sort_r(x, y)        sort(x, y, greater<lli>()); // 降順(5,4,3,,,)

#define ARRAY_LENGTH(array) (sizeof(array) / sizeof(array[0]))

typedef long long int lli;
typedef pair<lli, lli> P;
typedef tuple<lli, lli, lli> tup;

// dp[k][i][j]: k 個目までを中間地点として使って良いとしたときの、iとjの最短距離
//              たどり着けないときはINF、i==jならば0が入る
//              kを0から|V|まで回せば、全ての点を中間地点として使う場合の全点間最短距離が
//              算出されていることになる
lli dp[301][301]; // k 個分用意しなくても上書きしてけば良いので、dp[i][j]のみ用意
lli dp2[301][301]; // 最短経路が l 以下になっている場合に1の辺を貼るグラフ

#define INF (LLONG_MAX / 3)

int main() {
    lli n,m,l;
    cin3(n,m,l);
    lli a[m],b[m],c[m];
    ncin3(m,a,b,c);
    lli q;
    cin1(q);
    lli s[q];
    lli t[q];
    ncin2(q,s,t);

    REP(i, 0, m) {
        if (c[i] <= l)
            dp[a[i]][b[i]] = dp[b[i]][a[i]] = c[i];
    }
    // 初期化
    REPE(i, 1, n) {
        REPE(j, 1, n) {
            if (dp[i][j])
                continue;
            if (i == j)
                continue;
            dp[i][j] = INF;
            dp2[i][j] = INF;
        }
    }

    REPE(k, 1, n) {
        REPE(i, 1, n) {
            REPE(j, 1, n) {
                dp[j][i] = dp[i][j] = min(dp[i][j], dp[i][k]+dp[k][j]);
            }
        }
    }
    REPE(i,1,n) {
        REPE(j,i+1,n) {
            if (dp[i][j] <= l) {
                dp2[j][i] = dp2[i][j] = 1;
            }
            //cout3(i,j,dp[i][j]);
        }
    }
    REPE(k, 1, n) {
        REPE(i, 1, n) {
            REPE(j, 1, n) {
                dp2[j][i] = dp2[i][j] = min(dp2[i][j], dp2[i][k]+dp2[k][j]);
            }
        }
    }
    REP(i,0,q) {
        if (dp[s[i]][t[i]] == INF)
            cout << -1 << endl;
        else
            cout << dp2[s[i]][t[i]]-1 << endl;
    }

}


Measured memory_bytes: 4224
#include <stdio.h>

int main(){
  int a,b,c;
  scanf("%d %d %d",&a,&b,&c);
  if(a>=b){
    if(c>=a){
      printf("%d",a+b);
    }else{
      printf("%d",b+c);
    }
  }else{
    if(c>=b){
      printf("%d",a+b);
    }else{
      printf("%d",a+c);
    }
  }
  return 0;
}

Measured memory_bytes: 128
S = input()
K = int(input())
List = []
ans = 1
num = 0
for i in range(len(S)):
    List.append(int(S[i]))
for j in range(len(S)):
    if List[j] != 1:
        ans = List[j]
        num = j+1
        break
if K < num:
    print(1)
else:
    print(ans)

Measured memory_bytes: 3064
if __name__ == "__main__":
    N = int(input())
    A = list(map(int, input().split()))
    B = list(map(int, input().split()))
    C = list(map(int, input().split()))

    res = 0
    for i in range(N):
        if i > 0:
            if A[i] - A[i-1] == 1:
                res += C[A[i-1]-1]
        res += B[A[i]-1]

    print(res)


Measured memory_bytes: 3064
def main():
    a, b, x = map(int, input().split())

    b_count = (b // x) + 1
    if a == 0:
        a_count = 0
    else:
        a_count = ((a - 1) // x) + 1
    print(b_count - a_count)

    # mod = [i for i in range(a, b + 1) if i % x == 0]
    # print(len(mod))

if __name__ == "__main__":

    main()


Measured memory_bytes: 2940
(n, m) = [int(i) for i in input().split()]

A = []
b = []


for i in range(n):
    A.append([int(j) for j in input().split()])

for i in range(m):
    b.append(int(input()))


for i in range(n):
    c = 0

    for j in range(m):
         c += A[i][j] * b[j]

    print(c)

Measured memory_bytes: 7008
import java.util.ArrayDeque;
import java.util.HashMap;
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		int[] init = {0, 1, 2, 3, 4, 5, 6, 7};
		HashMap<Integer, Integer> map = new HashMap<Integer, Integer>();
		map.put(encode(init), 0);
		ArrayDeque<int[]> que = new ArrayDeque<int[]>();
		que.add(init);
		
		while (!que.isEmpty()) {
			int[] arr = que.remove();
			int[][] swap = {{0,1},{1,2},{2,3},{4,5},{5,6},{6,7},{0,4},{1,5},{2,6},{3,7}};
			for (int[] ij: swap) {
				int i = ij[0], j = ij[1];
				if (arr[i] == 0 || arr[j] == 0) {
					int[] _arr = arr.clone();
					_arr[i] = arr[j];
					_arr[j] = arr[i];
					if (!map.containsKey(encode(_arr))) {
						map.put(encode(_arr), map.get(encode(arr)) + 1);
						que.add(_arr);
					}
				}
			}
		}
		
		Scanner in = new Scanner(System.in);
		while (in.hasNext()) {
			int[] arr = new int[8];
			for (int i = 0; i < 8; i++) {
				arr[i] = in.nextInt();
			}
			System.out.println(map.get(encode(arr)));
		}
	}
	
	static int encode(int[] arr) {
		int code = 0;
		for (int n: arr) {
			code = (code << 3) + n;
		}
		return code;
	}
}

Measured memory_bytes: 41028
n = int(input())
a = [int(x) for x in input().split()]
m = 1000000007
ans = 0

b = [0]
for i in range(1,n+1):
  b.append((a[i-1] + b[i-1]) % m)
#print(a,b)
           
for i in range(n):
	p = b[n] - b[i+1]
	p *= a[i]
	p = p % m
	ans += p
	ans = ans % m
print(ans)

Measured memory_bytes: 31492
#include<iostream>
#include<vector>
#include<algorithm>
#include<math.h>
using namespace std;
typedef long long ll;

int main(){
    int n;
    cin >> n;
    int cnt = 0;
    bool f = false;
    ll sum = 0;
    ll minv = 10000000000000;
    vector<ll> v(n);
    for (int i = 0; i < n; i++)
    {
        cin >> v[i];
        sum += abs(v[i]);
        minv = min(minv, abs(v[i]));
        if (v[i] < 0)
        {
            cnt++;
        }
        else if (v[i]==0)
        {
            f = true;
        }
    }
    if(f || cnt%2==0)
    {
        cout << sum << endl;
        return 0;
    }
    else
    {
        cout << sum - 2 * minv << endl;
        return 0;
    }
}

Measured memory_bytes: 1024
#include <iostream>
#include <iomanip>
#include <math.h>
#include <float.h>
using namespace std;

#ifndef M_PI
#define M_PI (4.0*atan(1.0))
#endif

int main() {
	// your code goes here
	
	int a, b, answer;
	std::string op;
	while(1){
		std::cin>>a>>op>>b;
		if(op=="+"){
			answer=a+b;
		} else if(op=="-"){
			answer=a-b;
		} else if(op=="*"){
			answer=a*b;
		} else if(op=="/"){
			answer=a/b;
		} else  if(op=="?"){
			break;
		}
		std::cout<<setprecision(16)<<answer<<std::endl;
	}
	return 0;
}

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

namespace ForAtcoder
{
    class Program
    {
        static void Main(string[] args)
        {
            long[] inputLongArray = Console.ReadLine().Split(' ').Select(i => long.Parse(i)).ToArray();
            var a = inputLongArray[0];
            var b = inputLongArray[1];
            var k = (int)inputLongArray[2];
            var alist = new List<long> { };
            for (var i = a + b; i > 0; i--)
            {
                if (a % i == 0 && b % i == 0) alist.Add(i);
            }
            Console.WriteLine(alist[k-1]);
        }
    }
}

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

int main() {
    int N;
    while(true) {
        cin >> N;
        if(!N) break;

        vector<int> b(N);
        for(int i = 0;i < N;i++) cin >> b[i];

        int ans = 0;

        int k = 0;
        for(int i = 0;i < N;i++) k += b[i];
        if(k * (k + 1) % 2 != 0) {
            ans = -1;
            break;
        }

        while(true) {
            bool ok = true;
            for(int i = 0;i < b.size();i++) {
                if(b[i] != i + 1) {
                    ok = false;
                    break;
                }
            }
            if(ok) break;

            ans++;

            for(int i = 0;i < b.size();i++) b[i]--;
            b.push_back(b.size());
            b.erase(remove(b.begin(), b.end(), 0), b.end());

            if(ans >= 10000) {
                ans = -1;
                break;
            }
        }
        cout << ans << endl;
    }
}

Measured memory_bytes: 1232
#include<bits/stdc++.h>
#include <iostream>
#include <sstream>
#include <cstdio>
#include <cmath>
#include <cstring>
#include <cctype>
#include <string>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <algorithm>
#include <functional>
using namespace std; 
#define DEBUG(x) cout << '>' << #x << ':' << x << endl;
#define REP(i,n) for(int i=0;i<(n);i++)
#define FOR(i,a,b) for(int i=(a);i<=(b);i++)
#define FORD(i,a,b) for(int i=(a);i>=(b);i--)
inline bool EQ(double a, double b) { return fabs(a-b) < 1e-9; }
const int INF = 1<<29;
typedef long long int ll;
inline int two(int n) { return 1 << n; }
inline int test(int n, int b) { return (n>>b)&1; }
inline void set_bit(int & n, int b) { n |= two(b); }
inline void unset_bit(int & n, int b) { n &= ~two(b); }
inline int last_bit(int n) { return n & (-n); }
inline int ones(int n) { int res = 0; while(n && ++res) n-=n&(-n); return res; }
template<class T> void chmax(T & a, const T & b) { a = max(a, b); }
template<class T> void chmin(T & a, const T & b) { a = min(a, b); }
const int MOD=1000000007;

bool isPowerOfTwo (ll x)  
{  
    return x && (!(x&(x-1)));  
}
bool isPrime(int n) 
{ 
    if (n <= 1)  return false; 
    if (n <= 3)  return true; 
    if (n%2 == 0 || n%3 == 0) return false; 
  
    for (int i=5; i*i<=n; i=i+6) 
        if (n%i == 0 || n%(i+2) == 0) 
           return false; 
  
    return true; 
}
int highestPowerof2(unsigned int n) 
{ 
    // Invalid input 
    if (n < 1) 
        return 0; 
  
    int res = 1;
    for (int i=0; i<8*sizeof(unsigned int); i++) 
    { 
        int curr = 1 << i; 
        if (curr > n) 
           break; 
  
        res = curr; 
    } 
  
    return res; 
} 
long long binpow(long long a, long long b) {
    long long res = 1;
    while (b > 0) {
        if (b & 1)
            res = res * a;
        a = a * a;
        b >>= 1;
    }
    return res;
}       
////////////////////////////////////////////////////////////////////

int main()
{
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);  
  cout.tie(NULL);
  int t=1;
  while(t--)
  {
    ll n;
    cin>>n;
    ll ans=0;
    for(int i=1;i<=n;i++)
    {
        if(i%5!=0 && i%3!=0)
        ans+=i;
    }
    cout<<ans;
  }
  return 0;
}

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

int main(){

    int N, K, d;
    cin >> N >> K;
    vector<int> flg(N);
    int i, j, count=0, temp;

    for (i=0; i<K; i++){
        cin >> d;
//        vector<int> array(d);

        for (j=0; j<d; j++){
            cin >> temp;
            flg.at(temp-1) = 1;
        }
    }

    for (int i=0; i<N; i++){
        if (flg.at(i) == 0){
            count++;
        }
    }

    cout << count << endl;
    return 0;
}

Measured memory_bytes: 3628
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0; i<(n); i++)
using namespace std;
using ll = long long;
using P  = pair<int,int>;
using vi = vector<int>;
using vv = vector<vi>;
//const int MOD = 1000000007;
//const int MOD = 998244353;
const ll INF = 1001001001001;

//ABC176D 編集中


int main(){
    int h,w;
    cin >> h >> w;
    int ch,cw;
    int dh,dw;
    cin >> ch>>cw;
    ch--;cw--;
    cin >> dh>>dw;
    dh--;dw--;
    vector<string> s(h);
    rep(i,h)cin>>s[i];
    
    vv check(h, vi (w,-1));
    
    deque<P> q;
    q.push_front(P(ch,cw));
    check[ch][cw] = 0;
    
    while(!q.empty()){
        int pi = q.front().first;
        int pj = q.front().second;
        q.pop_front();
        
        for(int i=-2; i<=2; i++){
            for(int j=-2; j<=2; j++){
                if(!i && !j)continue;
                int ni = pi + i;
                int nj = pj + j;
                if(ni<0 || ni>=h || nj<0 || nj>=w)continue;
                if(s[ni][nj]=='#')continue;
                if(check[ni][nj]>=0 && check[ni][nj]<=check[pi][pj])continue;
                if(abs(i)+abs(j)==1){
                    check[ni][nj] = check[pi][pj];
                    q.push_front(P(ni,nj));
                }else{
                    check[ni][nj] = check[pi][pj]+1;
                    q.push_back(P(ni,nj));
                }
            }
        }
        
    }
    
    cout<<check[dh][dw]<<endl;
    
    return 0;
}

Measured memory_bytes: 10180
#include <bits/stdc++.h>
#define repz(i, z, n) for (decltype(n) i = (z); i < (n); i++)
#define rep(i, n) for (decltype(n) i = 0; i < (n); i++)

#define REPZ(i, z, n) for (decltype(n) i = (z); i <= (n); i++)
#define REP(i, n) for (decltype(n) i = 0; i <= (n); i++)
#define ALL(v) v.begin(), v.end()
#define SIZE(v) ((ll)(v).size())
#define MAX(v) (*max_element(ALL(v)))
#define MIN(v) (*min_element(ALL(v)))
#define INF 1000000000000  // 1E+12

// 略
#define PB push_back
#define F first
#define S second
#define MP make_pair
#define READ cin >>
#define PRINT cout <<
#define PYES cout << "Yes" << endl;
#define POK cout << "OK" << endl;
#define PNO cout << "No" << endl;
#define PNG cout << "NG" << endl;

using namespace std;

// デバッグ用
void debug_out() { cout << endl; }
template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
  cout << H << " ";
  debug_out(T...);
}

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

#ifdef _DEBUG
#define debug(...) debug_out(__VA_ARGS__)
#else
#define debug(...)
#endif

// typedef
typedef long long ll;
typedef unsigned long long ul;
typedef long double ld;
typedef pair<ll, ll> pl;

// const
// 円周率
const ld pi = acos(-1);
// mod用
// 1E+9 +7
const ll mod = (int)1e+9 + 7;
// 1s間で可能なループ回数2E+8回
// int        最大値2147483647         〜2E+9
// long long  最大値9223372036854775807〜9E+18
// 総和accumulate
// 単純リストvector<type> push_back
// 連想配列map<key,value> insert,
// 集合set<type>
// pair キーとバリューを格納 firstとsecondでアクセス
// 小数点指定 cout << fixed << setprecision(15) << endl;
// to_string<->stoi
// stoll(longlong)
// stod(double)
// deep copy v1->v2 copy(v1.begin(), v1.end(), back_inserter(v2) );
// 大文字65-90(-32)
// 小文字97-122(+32)
//  priority_queue<pair<ll, ll>, vector<pair<ll, ll>>, greater<pair<ll, ll>>>
//  ba;
int main() {
  // faster
  // C言語流の入出力は使用できない
  ios::sync_with_stdio(false);
  std::cin.tie(nullptr);
  ll n, m;
  cin >> n >> m;
  vector<ll> card(n);
  rep(i, n) cin >> card[i];
  sort(ALL(card));
  priority_queue<pl> replace_card;
  map<ll, ll> temp_map;
  rep(i, m) {
    ll b, c;
    cin >> b >> c;
    temp_map[c] += b;
  }
  for (pl i : temp_map) {
    replace_card.push(i);
  }
  pl r_c = replace_card.top();
  replace_card.pop();

  for (ll i = 0; i < n; i++) {
    if (r_c.S == 0) {
      if (SIZE(replace_card) == 0) {
        break;
      } else {
        r_c = replace_card.top();
        replace_card.pop();
      }
    }
    if (card[i] < r_c.F) card[i] = r_c.F;
    r_c.S--;
  }
  ll res = 0;
  rep(i, n) res += card[i];
  cout << res << endl;

  return 0;
}


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

using namespace std;



int main()
{
    int n;
    cin >> n;
    long long max = -9999999999;
    long long min = 9999999999;
    for(int i = 0;i<n;i++){
        long long a;
        scanf("%lld",&a);
        if(a-min > max) max = a-min;
        if(a < min) min = a;
    }
    cout << max << endl;
    
   

    return 0;
}


Measured memory_bytes: 3188
# Alchemist
N = int(input())
V = list(map(int, input().split()))

V = sorted(V) # 小さい順に並ぶ

V[0] = V[0]/(2**(N-1))
for i in range(1, N):
	V[i] = V[i]/(2**(N-i))
	
ans = sum(V)
print(ans)



Measured memory_bytes: 3060
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
using namespace std;
#define Khela ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define ll long long int
#define llu long long unsigned int
#define pf printf
#define sf scanf
#define f first
#define s second
#define pb push_back
#define mk make_pair
#define pii pair<int ,int>
#define PII pair<ll ,ll>
 
int dx8[] = {0, 0, 1, 1, 1, -1, -1, -1};
int dy8[] = {1,-1, 1, -1, 0, 0, -1, 1};
int dx4[] = {0, 0, 1, -1};
int dy4[] = {1, -1, 0, 0};
 
typedef tree<pair<int,int>,null_type,less<pair<int,int>>,rb_tree_tag,tree_order_statistics_node_update>ordered_set;
int Set(int N,int pos){return N=N | (1<<pos);}
int reset(int N,int pos){return N= N & ~(1<<pos);}
bool check(int N,int pos){return (bool)(N & (1<<pos));}
const int Max=1e9+100;
const ll  MAX=1e18+500;
const int sz=1e3+100;


int main()
{
    Khela
    ll a,b,c,i,j,k,q,p,x,y,ct,ct1,m,l,r,x1,y1,mn,h,sum1,in,z,mid,n,mx;
    char ch;
    double d;
    string str1,str2,str;
    bool bl,bl1;
    int t,cs=1;
    while(cin>>str>>str1)
    {
        string ans=str1+str;
        cout<<ans<<endl;
    }


}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <queue>
using namespace std;
int main(void){
    std::string S;
    cin >> S;
    int Q;
    cin >> Q;
    vector<int> b(Q),k(Q);
    vector<char> c(Q);
    string U,M;
    for(int i = 0; i < Q; i++){
        cin >> b[i];
        if(b[i] == 2) cin >> k[i] >> c[i];
    }
    bool flag = true;
    int Count = 0;
    for(int i = 0; i < Q; i++){
        if(b[i] == 1) Count++;
    }
    if(Count%2 == 1){
        flag = false;
        reverse(S.begin(),S.end());
    }
    for(int i = 0; i < Q; i++){
        if(b[i] == 1 && flag == true) flag = false;
        else if(b[i] == 1 && flag == false) flag = true;
        else if((b[i] == 2 && k[i] == 1 && flag == true) || (b[i] == 2 && k[i] == 2 && flag == false)) M.push_back(c[i]);
        else if((b[i] == 2 && k[i] == 1 && flag == false) || (b[i] == 2 && k[i] == 2 && flag == true)) U.push_back(c[i]);
    }
    reverse(M.begin(),M.end());
    
    cout << M + S + U << endl;
}


Measured memory_bytes: 3140
import java.util.*;

public class Main {

    public static void main(String[] args) {
        // write your code here
        Scanner scanner = new Scanner(System.in);
        int n = scanner.nextInt();
        long[] array = new long[n];
        Arrays.setAll(array, i -> scanner.nextLong());
        long sum = 0L;
        long evenSum = 0L;
        for (int i = 0; i < n; i++) {
            sum += array[i];
            if (i % 2 == 1) {
                evenSum += array[i];
            }
        }
        long start = sum - (2 * evenSum);

        System.out.println(start);

        for (int i = 1; i < n; i++) {
            start = 2 * array[i - 1] - start;
            System.out.println(start);
        }
    }
}

Measured memory_bytes: 62436
n = int(input())
info = []
for _ in range(n):
  x, y, h = map(int,input().split())
  info.append((x, y, h))

def check(cx, cy):
  H = None
  fin = []
  for i in info:
    x = i[0]
    y = i[1]
    h = i[2]
    if h != 0:
      tmpH = h + abs(x-cx) + abs(y-cy)
      if H:
        if H != tmpH:
          return 0
      else:
        H = tmpH
    else:
      fin.append((x, y, h))
  for f in fin:
    x = f[0]
    y = f[1]
    if H - abs(x-cx) -abs(y-cy) > 0:
      return 0
  return H
      

for cx in range(101):
  for cy in range(101):
    h = check(cx, cy)
    if h >= 1:
      print(cx)
      print(cy)
      print(h)
      break

Measured memory_bytes: 68732
#include<stdio.h>
#include<stdlib.h>
#include<iostream>
#include<string>
#include<algorithm>
#include<vector> 
#include<limits>
#include<numeric>
#include<type_traits>
#include<math.h>
using namespace std;
typedef long long ll;

#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define repi(i,a,b) for(int i = (int)(a); i < (int)(b); i++)
#define in(x) cin >> x
#define out(str) cout << str << endl

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 N,ans;

int main(){
    cin>>N;
    int v[N],c[N];
    rep(i,N){
        cin>>v[i];
    }
    rep(i,N){
        cin>>c[i];
        if(v[i]>c[i])ans+=v[i]-c[i];
    }
    out(ans);
}


Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;
using System.Numerics;
using System.Text;
using System.Text.RegularExpressions;

namespace AtCoder.ABC
{
    class QuestionB
    {
        public static void Main(string[] args)
        {
            var n = long.Parse(Console.ReadLine());

            var max = long.MaxValue;

            for(long i = 1; i * i <= n; i++) {
                if(n % i == 0) {
                    max = Math.Min(Math.Max(i.ToString().Length, (n / i).ToString().Length), max);
                }
            }

            Console.WriteLine(max);
        }
    }
}


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


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

    int ar[n+10],ans[n+10];

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

    ans[0]=0;


    for(int i=0; i<n; i++)
    {
        for(int j=i+1; j<min(i+1+k,n); j++)
        {
            int r1,r2;

            r1=abs(ar[j]-ar[i])+ans[i];
            ans[j]=min(r1,ans[j]);
        }

    }

    cout<<ans[n-1]<<endl;

    return 0;
}


Measured memory_bytes: 1024
#include<iostream>
#include<iomanip>
#include<cmath>
#include<string>
#include<cstring>
#include<vector>
#include<list>
#include<algorithm>
#include<map>
#include<set>
#include<queue>
#include<stack>
using namespace std;
typedef long long ll;
#define fi first
#define se second
#define mp make_pair
#define mt make_tuple
#define pqueue priority_queue
const int inf=1e9+7;
const ll mod=1e9+7;
const ll mod1=998244353;
const ll big=1e18;
const double PI=2*asin(1);

int main() {
  int H, W, D; cin>>H>>W>>D;
  vector<vector<int> > A(H, vector<int>(W));
  map<int, pair<int, int> > amap;
  for(int i=0;i<H;++i) {
    for(int j=0;j<W;++j) {
      cin>>A[i][j];
      if(A[i][j]>D) {
        amap[A[i][j]-D] = mp(i, j);
      }
    }
  }
  int ans[H*W+1];
  for(int i=0;i<=H*W;++i) ans[i] = 0;
  for(int i=0;i<H;++i) {
    for(int j=0;j<W;++j) {
      if(A[i][j]+D>H*W) continue;
      ans[A[i][j]] = abs(amap[A[i][j]].fi-i)+abs(amap[A[i][j]].se-j);
    }
  }
  vector<vector<int> > ansarr(D);
  for(int i=0;i<D;++i) ansarr[i].push_back(0);
  for(int i=1;i<H*W;++i) {
    if(ans[i]==0) break;
    ansarr[i%D].push_back(ans[i]);
  }
  for(int i=0;i<D;++i) {
    for(int j=1;j<ansarr[i].size();++j) ansarr[i][j] += ansarr[i][j-1];
  }
  /**
  for(int i=0;i<D;++i) {
    cout<<i<<endl;
    for(int j=0;j<ansarr[i].size();++j) cout<<ansarr[i][j]<<" ";
    cout<<endl;
  }
  **/
  int Q;
  cin>>Q;
  int l, r;
  int ans1[Q];
  for(int i=0;i<Q;++i) {
    cin>>l>>r;
    if(l%D==0) ans1[i] = ansarr[l%D][r/D-1]-ansarr[l%D][l/D-1];
    else ans1[i] = ansarr[l%D][(r-l%D)/D]-ansarr[l%D][(l-l%D)/D];
  }
  for(int i=0;i<Q;++i) cout<<ans1[i]<<endl;
}


Measured memory_bytes: 10816
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define inf 1001001001
#define mod 1000000007
#define pi 3.141592653589793
ll gcd(ll a,ll b){
    if(b>a) swap(a,b);
    if(b==0) return a;
    return gcd(b,a%b);
}
ll lcm(ll a,ll b){
    ll g=gcd(a,b);
    return a/g*b;
}
ll rep_jijo(ll n,ll x){
    if(x==0) return 1;
    if(x%2==0){
        ll t=rep_jijo(n,x/2);
        return t*t%mod;
    }
    return n*rep_jijo(n,x-1)%mod;
}
ll com(ll n,ll r){
    ll x=1,y=1;
    ll tmp=n;
    while(tmp>=n-r+1){
        x=x*tmp%mod;
        tmp--;
    }
    while(r>0){
        y=y*r%mod;
        r--;
    }
    return x*rep_jijo(y,mod-2)%mod;
}

int main (){
    double n,m;
    double sum=0;
    int ans=0;
    cin >> n >>m;
    double m4=4*m;
    vector<int>a(n);
    rep(i,n) {
        double x;
        cin >> x;
        sum+=x;
        a[i]=x;
    }
    double lim=sum/m4;
    rep(i,n){
        if(a[i]<lim) continue;
        else ans++;
    }
    if(ans>=m) cout << "Yes" <<endl;
    else cout << "No" <<endl;

    return 0;
}



Measured memory_bytes: 256
n,k=map(int,input().split())
v=list(map(int,input().split()))

ans=0

for l in range(n):
    for r in range(n-l+1):
        if l + r > k:
            break #操作は最大k回まで。超えたら次のlへ。
        nv = v[:l] + v[n-r:] #左からl^1個。
        nv.sort()
        for i in range(k-l-r):
            if not nv or nv[0] >= 0:
                break
            del nv[0]
        ans=max(ans,sum(nv))

print(ans)

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

#define SZ(x) (((int)x.size()))
#define all(x) (x).begin(), (x).end()
#define pb push_back

typedef long long ll;
typedef long double ld;

using namespace std;

const int maxn = 200*1000+10;
map<int, int> m;
int n, x;
ll ans;

int main()
{
    cin >> n;
    for (int i = 0; i < n; i++)
    {
        cin >> x;
        ans += m[i - x];
        m[i + x]++;
    }
    cout << ans;
	return 0;
}


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

int main () {
  int n, k, r, s, p;
  string t;
  
  cin >> n >> k;
  cin >> r >> s >> p;
  cin >> t;
    
  char a[n];
  long long score = 0;
  
  for (int i = 0; i < n; i++) {
    a[i] = t.at(i);
    
    if (i < k or a[i] != a[i-k]) {
      switch (a[i]) {
        case 'r':
          score += p;
          break;
        case 's':
          score += r;
          break;
        case 'p':
          score += s;
          break;
        default:
          score += 0;
          break;
      }
      
    } else if (a[i] == a[i-k]) {
      a[i] = 'x';
    }
  }
  cout << score << endl;
}
        
          


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

x=A.pop()
dif=0
ans=0
for i in range(n-1):
    a=A[i]
    tmp=min(a, x-a)
    if tmp>=dif:
        dif=tmp
        ans=a

print(x, ans)

Measured memory_bytes: 14052
/* 
   AOJ 2014
   Surrounding Area
   2015/9/18
*/

#include<stdio.h>
#define W_MAX 51
#define H_MAX 51
#define DIR_N 4

int w, h, white_area = 0, black_area = 0, count, flag;
char area[H_MAX][W_MAX];
int dir[DIR_N][2] = {{0, 1}, {1, 0}, {0, -1}, {-1, 0}};
/* dir := down->right->up->left */

int is_area(int x, int y)
{
  return (0 <= x && x < w && 0 <= y && y < h && area[y][x] != 'V');
}

void dfs(int x, int y)
{
  int i, j, dir_x, dir_y;
  count++;
  area[y][x] = 'V';

  for(i = 0; i < DIR_N; i++)
    {
      dir_x = x + dir[i][0];
      dir_y = y + dir[i][1];
      if(is_area(dir_x, dir_y))
	{
	  if(area[dir_y][dir_x] == 'W')
	    {
	      if(flag == 0)
		{
		  flag = 1;
		}
	      if(flag == 2)
		{
		  flag = 3;
		}
	      continue;
	    }
	  if(area[dir_y][dir_x] == 'B')
	    {
	      if(flag == 0)
		{
		  flag = 2;
		}
	      if(flag == 1)
		{
		  flag = 3;
		}
	      continue;
	    }
	  dfs(dir_x, dir_y);
	}
    }
}

void ans_f(int x, int y)
{
  count = 0;
  flag = 0;
  dfs(x, y);
  if(flag == 1)
    {
      white_area += count;
    }
  if(flag == 2)
    {
      black_area += count;
    }
}

int main(void)
{
  int i, j;

  while(1)
    {
      white_area = 0;
      black_area = 0;
      count = 0;
      scanf("%d %d", &w, &h);
      if(w == 0 && h == 0)
	{
	  break;
	}
      for(i = 0; i < h; i++)
	{
	  scanf("%s", area[i]);
	}
      for(i = 0; i < h; i++)
	{
	  for(j = 0; j < w; j++)
	    {
	      if(area[i][j] == '.')
		{
		  ans_f(j, i);
		}
	    }
	}
      printf("%d %d\n",black_area, white_area);
    }

  return 0;
}

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

typedef long long int LL;
typedef long long int LLint;

//Faster Program
#define endl "\n"

//Faster Coding
#define ED return
#define GET(a) int a;cin >> a
#define DGET(a) double a;cin >> a
#define SGET(a) string a;cin >> a
#define CGET(a) char a;cin >> a
#define PRINT(a) cout << a << "\n"
#define ANS(a,b) int a;cin >> a;cout << b << "\n"
#define FOR(n) for(int i = 0;i < n;i++)
#define SORT(vec) sort(vec.begin(),vec.end())
#define REV(vec) reverse(vec.begin(),vec.end())

//As Function
#define UP(a,b) ((a+(b-1))/b)
#define ipow(x,y) LL(pow(x,y))

//Debug
#define TEST cout << "OK\n"

const double PI = M_PI;
const long long INF = int(10e9-1);
const long long MOD = int(10e9+7);

//Settings
const bool DO_BENCHMARK = false;
const int DOUBLE_ACCURACY = 15;

int main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(DOUBLE_ACCURACY);
    void solve();
    if(DO_BENCHMARK){
        clock_t clock_start = clock();
        solve();
        clock_t clock_end = clock();
        const double time = static_cast<double>(clock_end-clock_start)/CLOCKS_PER_SEC*1000.0;
        cout << "\n" << time << "[ms]\n";
    }
    else solve();
}

void solve(){
    GET(N);
    SGET(S);
    for(int i = 0;i < S.size();i++){
        S[i] += N;
        if(S[i] > 'Z'){
            S[i] -= 26;
        }
    }
    PRINT(S);
}


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

int main(){
    int W,H,x,y,r;
    cin>>W>>H>>x>>y>>r;
    if((x-r)>=0&&(x+r)<=W&&(y-r)>=0&&(y+r)<=H){
        cout<<"Yes\n";
    }else{
        cout <<"No\n";
    }
    return 0;
}

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


def main():
    n = int(input())
    b = list(map(int, input().split()))
    ans = list()

    # KeyInsight
    # 数列aに数字を追加して数列bが作れるか?
    # ⇒数列bのk番目の値kを取り除くことができるか? と言い換える
    # https://www.youtube.com/watch?v=wOacBGq5OWU

    while b:
        index = -1
        candidate = -1

        # 一致するkが複数ある場合は，最も右側の値を選択
        for i, bi in enumerate(b, 1):
            if bi == i:
                index = i
                candidate = bi

        if index == -1:
            print(-1)
            exit()

        b.pop(index - 1)
        ans.append(candidate)

    # 最後の操作から行っているため，反転させる
    print('\n'.join(map(str, ans[::-1])))


if __name__ == '__main__':
    main()


Measured memory_bytes: 3064
import sys

read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

a, b, c, d = map(int, read().split())

def main(a, b, c, d):
    while True:
        if c <= b:
            return 'Yes'
        c -= b
        if a <= d:
            return 'No'
        a -= d

print(main(a, b, c, d))

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


int main() {
	int N, C;
	cin >> N >> C;

	ll cost[32][32];
	for(int i=0;i<C;i++) {
		for(int j=0;j<C;j++) {
			cin >> cost[i][j];
		}
	}

	vector<ll> cnt[3];
	cnt[0].assign(C, 0);
	cnt[1].assign(C, 0);
	cnt[2].assign(C, 0);
	for(int i=0;i<N;i++) {
		for(int j=0;j<N;j++) {
			int c;
			cin >> c;
			cnt[(i + j) % 3][c - 1]++;
		}
	}

	ll ans = 1LL << 60;
	for(int i=0;i<C;i++) {
		for(int j=0;j<C;j++) {
			if (i == j) continue;
			for(int k=0;k<C;k++) {
				if (i == k || j == k) continue;
				ll cand = 0;
				for(int c=0;c<C;c++) {
					cand += cnt[0][c] * cost[c][i];
					cand += cnt[1][c] * cost[c][j];
					cand += cnt[2][c] * cost[c][k];
				}
				ans = min(ans, cand);
			}
		}
	}
	cout << ans << endl;

	return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
#include <iostream>

using namespace std;

void bubbleprint(int A[], int N,int replace)
{
	for (int i = 0; i < N; i++)
	{
		if (i > 0)
		{
			printf(" ");
		}

		printf("%d", A[i]);
	}
	printf("\r\n");
	printf("%d", replace);
	printf("\r\n");
}

void bubbleSort(int A[], int N)
{
	int flg = 1;
	int replace=0;

	while (flg)
	{
		flg = 0;
		for (int i = N-1; i>0; i--)
		{
			if (A[i] < A[i - 1]) 
			{
				swap(A[i],A[i - 1]);
				replace++;
				flg = 1;
			}
		}
	}

	bubbleprint(A,N,replace);
}

int main()
{
	int N, A[100];

	scanf("%d", &N);

	for (int i = 0; i < N; i++)
	{
		scanf("%d", &A[i]);
	}
	bubbleSort(A, N);

	return 0;
}


Measured memory_bytes: 3208
#include <bits/stdc++.h>
using namespace std;
template<class T> inline bool chmin(T& a, T b) { if (a > b ) { a = b; return true; } else { return true; } }

const long long INF = 1LL << 60;

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

  int ary[100010];
  for (int i = 0; i < N; i++) {
    cin >> ary[i];
  }

  long long dp[100010];
  for (int i = 0; i < 100010; i++) {
    dp[i] = INF;
  }

  dp[0] = 0;
  dp[1] = abs(ary[0] - ary[1]);

  for (int i = 2; i < N; i++) {
    chmin(dp[i], dp[i - 1] + abs(ary[i - 1] - ary[i]));
    chmin(dp[i], dp[i - 2] + abs(ary[i - 2] - ary[i]));
  }

  cout << dp[N - 1] << endl;

  return 0;
}


Measured memory_bytes: 1408
module Main where
import qualified Control.Monad as C
import qualified Data.Char as C
import qualified Data.List as L
import qualified Data.Map as M
import qualified Data.Array as A

int = read :: String -> Int
getWord :: IO String
getWord = do
  c <- getChar
  if C.isSpace c
  then
    return []
  else do
    ws <- getWord
    return (c:ws)
getInt = fmap int getWord
replace pred a = map (\x -> if pred x then a else x)

main = interact $ printer . solver . parser
parser = int
printer = unlines . (:[]) . show

solver x = 1000 * a + 5 * c
  where
    a = x `div` 500
    b = x `mod` 500
    c = b `div` 5



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

#define INF_LL (int64)1e18
#define INF (int32)1e9
#define REP(i, n) for(int i = 0;i < (n);i++)
#define FOR(i, a, b) for(int i = (a);i < (b);i++)
#define all(x) x.begin(),x.end()
#define fs first
#define sc second

using int32 = int_fast32_t;
using uint32 = uint_fast32_t;
using int64 = int_fast64_t;
using uint64 = uint_fast64_t;
using PII = pair<int32, int32>;
using PLL = pair<int64, int64>;

const double eps = 1e-6;

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

const int64 mod = 1e9+7;

int main(void){
	int32 N;
	while(cin >> N && N){
		vector<int64> dp(1<<N, INF_LL);
		vector<vector<int64>> t(N, vector<int64>(N+1));
		dp[0] = 0;
		REP(i, N) REP(j, N+1) cin >> t[i][j];
		REP(i, 1 << N){
			REP(j, N){
				if(i >> j & 1) continue;

				int64 cost = t[j][0];
				REP(k, N){
					if(i >> k & 1) cost = min(cost, t[j][k+1]);
				}
				dp[i|(1<<j)] = min(dp[i|(1<<j)], dp[i]+cost);
			}
		}
		cout << dp[(1<<N)-1] << endl;
	}
}


Measured memory_bytes: 3624
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int main(){
	ll k;
	scanf("%lld",&k);
	ll now=0;
	if(k%2==0||k%5==0){
		puts("-1");return 0;
	}
	for(ll i=1;;i++){
		now=(now*10+7)%k;
		if(now==0){
			printf("%lld",i);
			break;
		}
		if(i==5e7){
			puts("-1");return 0;
		}
	}
	return 0;
}

Measured memory_bytes: 3824