akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <string>
#include <string.h>
#include <algorithm>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <cmath>
#include <stdio.h>
#include <vector>
#include <thread>
#include <atomic>
#include <mutex>
#include <future>
#define int long long
#define endre getchar();getchar();return 0
#define INF 1000000007
using namespace std;
bool prime(int n) {
	for (int i = 2; i <= sqrt(n); i++) {
		if (n%i == 0)return false;
	}
	return n != 1;
}
int gcd(int x, int y) {
	if (x < y)swap(x, y);
	if (y == 0)return x;
	return (y, x%y);
}
int lcm(int x, int y) {
	return x * y / gcd(x, y);
}
int kai(int n) {
	if (n == 0)return 1;
	return kai(n - 1)*n;
}
int mod_pow(int x, int y, int mod) {
	int res = 1;
	while (y > 0) {
		if (y & 1) {
			res = res * x%mod;
		}
		x = x * x%mod;
		y >>= 1;
	}
	return res;
}
string s;
int k;
vector<string>vec;
signed main() {
	cin >> s >> k;
	for (int i = 0; i < s.size(); i++) {
		for (int j = 1; j <= 5; j++) {
			if (i + j - 1 >= s.size())break;
			vec.push_back(s.substr(i, j));
		}
	}
	sort(vec.begin(), vec.end());
	unique(vec.begin(), vec.end());
	cout << vec[k - 1] << endl;
	endre;
}


Measured memory_bytes: 1660
import java.io.*;
 
public class Main {
    public static void main(String[] args) throws IOException {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
         
        String s = br.readLine();
        int x = Integer.parseInt(s);
        int secound = x % 60;
        x = x / 60;
        int minutes = x % 60;
        x = x / 60;
        int hour = x;
         
         
        System.out.println(hour + ":" + minutes + ":" + secound);
    }
 
}
 

Measured memory_bytes: 24404
using System;
using System.IO;
using System.Linq;

namespace KyoproCSharp
{
    public class Program
    {
        public static void Main()
        {
            var writer = new StreamWriter(Console.OpenStandardOutput()) {AutoFlush = false};
            new Program().Resolve(Console.In, writer);
            writer.Flush();
        }

        public void Resolve(TextReader reader, TextWriter writer)
        {
            var S = reader.ReadToEnd().Trim();
            var red = S.Count(_=>_=='0');
            var blue = S.Count(_=>_=='1');
            writer.WriteLine(red+blue - Math.Abs(red-blue));
        }
    }
}

Measured memory_bytes: 11616
import sys
def getch(i,j):
  rgb = {'R':0,'G':1,'B':2}
  for k in rgb:
    if i == k or j == k:
      continue
    return k,rgb[k]
N = int(input())
S = list(input())
l = len(S)
rgb_num = [[0,0,0] for i in range(l)]
for i in range(l):
  for j in range(i+1,l):
    if S[j] == 'R':
      rgb_num[i][0] += 1
    elif S[j] == 'G':
      rgb_num[i][1] += 1
    else:
      rgb_num[i][2] += 1

su = 0

for i in range(l):
  si = S[i]
  for j in range(i+1,l):
    sj = S[j]
    if si != sj:
      k = 2*(j+1) - (i+1)-1
      sk,n = getch(si,sj)
      if k < l and S[k] == sk:
        su += rgb_num[j][n]-1
      else:
        su += rgb_num[j][n]
print(su)

Measured memory_bytes: 70240
#include <iostream>

int main(void){
    int a[2];

    //for(int i = 0; i < 2; i++){
    //    std::cin >> a[i];
    //}
    std::cin >> a[0];
    std::cin >> a[1];

    
    if(a[0] > 9 || a[1] > 9){
        std::cout << -1 << std::endl;
    }else{
        std::cout << a[0]*a[1] << std::endl;

    }
}


Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<vector>
#include<string>
#include<map>
#include<set>
#include<deque>

using namespace std;

#define sz(x) (int)(x.size())
#define rep(i,a,b) for(int i=a;i<b;++i)
#define per(i,a,b) for(int i=b-1;i>=a;--i)
#define mp make_pair
#define pb push_back
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
/////////////////////

int const N = 141;
int const M = N * N;

int d[N][M], s[N];
int n;

void solve(){
	cin >> n;
	rep(i, 1, n+1) cin >> s[i];
	d[0][0] = 1;
	rep(i, 0, n){
		rep(j, 0, M){
			if(d[i][j]){
				d[i+1][j] = 1;
				if(j + s[i+1] < M){
					d[i+1][j+s[i+1]] = 1;
				}
			}
		}
	}
	int ans = 0;
	rep(i, 0, n+1){
		rep(j, 0, M) if(d[i][j]){
			int v = j;
			if(j % 10 == 0) v = 0;
			ans = max(ans, v);
		}
	}
	cout << ans << endl;
}


int main(){
#ifdef _DEBUG
	freopen("input.txt","r",stdin);
	freopen("output.txt","w",stdout);
#endif

	solve();


	return 0;
}

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

typedef long long ll;
#define endl "\n"
#define deb(x) cerr << #x << ":" << x << "\n"

void solve(){
    ll k,ans=0;
    cin>>k;
    for(int i=1;i<=k;i++){
        for(int j=1;j<=k;j++){
            for(int p=1;p<=k;p++){
                ans+=__gcd(__gcd(i,j),p);
            }
        }
    }
    cout<<ans;
}

int main()
{

    ios::sync_with_stdio(0);
    cin.tie(0);
    ll t=1;
    // cin>>t;
    while(t--){
        solve();
    }
    return 0;
}


Measured memory_bytes: 3652
retsu=input()
nagasa=len(retsu)
first=0
last=0
for i in range(nagasa):
    if retsu[i:i+1]=="A":
        first=i
        k=i
        break
for j in range(k,nagasa):
    if retsu[j:j+1]=="Z":
        last=j
    
print(last-first+1)
    

Measured memory_bytes: 3516
import os, sys, re, math

N = int(input())
v = [int(s) for s in input().split(' ')]
c = [int(s) for s in input().split(' ')]
ret = 0
for i in range(len(v)):
  if v[i] - c[i] > 0:
    ret += v[i] - c[i]
  
print(ret)

Measured memory_bytes: 3188
var
	n,i,j,k:Longint;
	s:int64;
	a,f:array[1..300,1..300]of Longint;
begin
	read(n);
	for i:=1 to n do for j:=1 to n do read(a[i,j]);
	for i:=1 to n do for j:=1 to n do for k:=1 to n do begin
		if a[i,k]+a[k,j]<a[i,j]then begin
			writeln(-1);
			exit;
		end;
		if(a[i,k]+a[k,j]=a[i,j])and(i<>k)and(j<>k)then f[i,j]:=1;
	end;
	for i:=1 to n do for j:=i to n do inc(s,a[i,j]*(1-f[i,j]));
	writeln(s);
end.


Measured memory_bytes: 896
#include <vector>
#include <iostream>
#include <cmath>
#include <iomanip>
#include <string>
#include <utility>
#include <stack>
#include <numeric>
#include <random>
#include <algorithm>
#include <queue>
#include <functional>
#include <iterator>
#include <list>
#include <unordered_map>
#include <deque>
#include <math.h>
#include <tgmath.h>
using namespace std;

#define all(x) (x).begin(), (x).end()
#define rep(i, b, e) for(i = b; i < e; ++i)
#define repr(i, b, e) for (i = b; i >= e; --i)
#define ull unsigned long long int
#define ll long long int
#define pint pair<int, int>

#define M_DEBUG 1
#define PI 3.141592653589793

#define E '\n'

#define print(x) cout << (x) << endl;
#define printa(x,n) for(int i = 0; i < n; i++){ cout << (x[i]) << "\n";}
#define INF (1e18)

const ll MAX = 1000000000;
const ll MOD = 1e9 + 7;

ll a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p, q, r, s, t, u, v, w, x, y, z;

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

ll aabs(ll a) {
    if (a < 0) return -a;
    return a;
}

//fast power
ll calc(ll a, ll b) {
    if (b == 0) return 1;
    else if (b % 2 == 0) {
        ll d = calc(a, b / 2);
        return (d * d) % MOD;
    }
    else return (a * calc(a, b - 1)) % MOD;
}

//fast combination
ll comb(ll n, ll a) {
    ll b = 1, c = 1;
    for (ll i = 1; i <= a; ++i) {
        b = b * i % MOD;
        c = c * (n - i + 1) % MOD;
    }

    return c * calc(b, MOD - 2) % MOD;
}

ll comb2(ll a) {
    ll b = a / 2;
    if (a % 2) {
        b = (a - 1) / 2;
        return (b * a);
    }
    return (b * (a - 1));
}

int dfs(int x, int y, int z) {
    if (x == a && y == b && z == c) return 1;
    
    int ans = 0;
    if (x != a) ans += dfs(x + 1, y, z);
    if (x >= y + 1/* && y != b*/) ans += dfs(x, y + 1, z);
    if (y >= z + 1/* && z != c*/) ans += dfs(x, y, z + 1); 

    return ans;
}

uint64_t gcd_impl( uint64_t n, uint64_t m ) {
        for( int i = 0; i < 10; ++i ) {
                uint64_t t = n - m;
                bool q = m > t;
                n = q ? m : t;
                m = q ? t : m;
                if( m == 0 ) { return n; }
        }
        return gcd_impl( m, n % m );
}

uint64_t gcd( uint64_t n, uint64_t m ) {
        return n > m ? gcd_impl( n, m ) : gcd_impl( m, n );
}

int main(void) {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cin >> a >> b >> c >> d;

    while (a > 0 && c > 0) {
        c -= b;
        if (c <= 0) {
            cout << "Yes" << endl;
            return 0;
        }
        a -= d;
        if (a <= 0) {
            cout <<"No" << endl;
            return 0;
        }
    }

    return 0;
}



Measured memory_bytes: 3644
#include<iostream>
#include<algorithm>
#include<string>
#include<vector>
#include<math.h>
using namespace std;
static const int MAX = 200000;
int main(){
    int n,r[MAX];
    cin >> n;
    for(int i=0;i<n;i++){
        cin >> r[i];
    }

    int maxv = -2000000000;
    int minv = r[0];

    for(int i=1;i<n;i++){
        maxv = max(maxv, r[i]-minv);
        minv = min(minv, r[i]);
    }

    cout << maxv << endl;

    return 0;
}


Measured memory_bytes: 3884
using System;
using System.IO;

class Program
{
    static void Main(string[] args) {
        var writer = new StreamWriter(Console.OpenStandardOutput()) {AutoFlush = false};
        Console.SetOut(writer);
        Console.WriteLine(Solve());
        Console.Out.Flush();
    }

    static object Solve() {
        var s = Console.ReadLine();
        var len = s.Length;
        var isScanning = false;
        var start = 0;
        var result = 0;
        for (int i = 0; i < len; i++) {
            if (s[i] == 'A' && !isScanning) {
                isScanning = true;
                start = i;
            }
            if (s[i] == 'Z') {
                result = Math.Max(result, i - start + 1);
            }
        }
        return result;
    }
}

Measured memory_bytes: 26504
#include<bits/stdc++.h>
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
#define mod 1000000007
#define MAX 1e18
#define all(v) v.begin(),v.end()
#define rep(i,a,b) for(i=(ll)a;i<(ll)b;i++)
#define revrep(i,a,b) for(i=(ll)a;i>=(ll)b;i--)
#define ii pair<ll,ll>
#define MP make_pair
#define pb push_back
#define f first
#define se second
#define ll long long int
#define vi vector<ll>
ll modexp(ll a,ll b,ll m){ ll res = 1; while(b > 0){  if(b & 1) res = (res * a) % m;  a = (a * a) % m;  b/=2;  }  return res; }
#define rs resize
typedef tree< ll, null_type, less<ll>, rb_tree_tag, tree_order_statistics_node_update > OST;
#define TRACE
#ifdef TRACE
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
    template <typename Arg1>
    void __f(const char* name, Arg1&& arg1){
        cout << name << " : " << arg1 << endl;
    }
    template <typename Arg1, typename... Args>
    void __f(const char* names, Arg1&& arg1, Args&&... args){
        const char* comma = strchr(names + 1, ','); cout.write(names, comma - names) << " : " << arg1<<" | ";__f(comma+1, args...);
    }
#else
#define trace(...)
#endif

const ll N = 3e3 + 2;
ll i,r,g,b,n,ans;
int main()
{
    std::ios_base::sync_with_stdio(false); cin.tie(NULL);
    cin>>r>>g>>b>>n;
    i = 0;
    while(i * r <= n){
        ll nn = n - i * r;
        ll j = 0;
        while(j * g <= nn){
            ll w = nn - j * g;
            if(w % b == 0)
                ans += 1;
            j += 1;
        }
        i += 1;
    }
    cout<<ans;
    return 0;
}

Measured memory_bytes: 256
/**
 *    author:  tourist
 *    created: 19.12.2019 15:01:36       
**/
#include <bits/stdc++.h>

using namespace std;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int h, w, n;
  cin >> h >> w >> n;
  vector<vector<int>> at(h);
  for (int i = 0; i < n; i++) {
    int x, y;
    cin >> x >> y;
    --x; --y;
    at[x].push_back(y);
  }
  int r = 0;
  for (int i = 1; i < h; i++) {
    sort(at[i].begin(), at[i].end());
    if (!at[i].empty() && at[i][0] <= r) {
      cout << i << '\n';
      return 0;
    }
    if (at[i].empty() || at[i][0] > r + 1) {
      ++r;
    }
  }
  cout << h << '\n';
  return 0;
}


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

using namespace std;
typedef long long ll;
#define rep(i, n, s) for (int i = s; i < (int)(n); i++)

ll calcNumOfCombination(ll n, ll r) {
    ll num = 1;
    for (ll i = 1; i <= r; i++) {
        num = num * (n - i + 1) / i;
    }
    return num;
}

int main() {
    ll N, K;
    cin >> N >> K;
    ll ans = 0;
    ll limit;
    ll h[N];
    rep(i, N, 0) cin >> h[i];

    limit = N - K;
    if (limit > 0) {
        sort(h, h + N);
        rep(i, limit, 0) {
            ans += h[i];
        }
    } else {
        ans = 0;
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 1792
#include <bits/stdc++.h>
using namespace std;
using i64 = int64_t;
using vi = vector<i64>;
using vvi = vector<vi>;

template <class T>
class SegTree {
    using F = function<T(T, T)>;
    int n;
    vector<T> data;
    const F f;
    const T e;
    
    int find(int a, int b, const T& x, int k, int l, int r) {
        if (data[k] > x || r <= a || b <= l) return -1;
        if (k >= n) {
            return k - n;
        }
        int t = find(a, b, x, 2 * k + 1, (l + r) >> 1, r);
        if (t != -1) return t;
        return find(a, b, x, 2 * k, l, (l + r) >> 1);
    }
    
public:
    SegTree(const vector<T>& as, const F f, const T& e) : f(f), e(e) {
        n = 1;
        while (n < as.size()) n <<= 1;
        data.assign(2 * n, e);
        for (int i = 0; i < as.size(); i++) {
            data[n + i] = as[i];
        }
        for (int i = n - 1; i > 0; i--) {
            data[i] = f(data[2 * i], data[2 * i + 1]);
        }
    }
    
    void update(int k, const T& x) {
        k += n;
        data[k] = x;
        while (k >>= 1) {
            data[k] = f(data[2 * k], data[2 * k + 1]);
        }
    }
    
    T query(int a, int b) {
        T L = e, R = e;
        for (a += n, b += n; a < b; a >>= 1, b >>= 1) {
            if (a & 1) {
                L = f(L, data[a++]);
            }
            if (b & 1) {
                R = f(data[--b], R);
            }
        }
        return f(L, R);
    }
    
    // [a, b)でx以下の値をもつ最右の要素の位置
    int find(int a, int b, const T& x) {
        return find(a, b, x, 1, 0, n);
    }
};

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);
    cout.setf(ios::fixed);
    cout.precision(10);
    int n, q;
    cin >> n >> q;
    vi sum(n + 1);
    for (int i = 0; i < n; i++) {
        cin >> sum[i + 1];
        sum[i + 1] += sum[i];
    }
    SegTree<i64> tree(sum, [](i64 a, i64 b){return min(a, b);}, 1e18);
    while (q--) {
        i64 x;
        cin >> x;
        i64 ret = 0;
        for (int i = 1; i <= n; i++) {
            int k = tree.find(i, n + 1, x + sum[i - 1]);
            if (k != -1) {
                ret += k - i + 1;
            }
        }
        cout << ret << endl;
    }
}



Measured memory_bytes: 5564
#include <iostream>
#include <cstring>
#include <cmath>
#include <vector>
#include <algorithm>
#include <stdio.h>
#include <math.h>
#include <stdlib.h>
#include <set>
#include <map>
#include <iterator>
#include <stack>
#include <string.h>
#include <cstdlib>
#include <queue>
#include <list>

using namespace std;

const int N = 1000000;
const int MOD = 1000000007;

long long fac[N],finv[N],inv[N];

void COMinit()
{
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2;i < N;i++){
        fac[i] = fac[i-1]*i%MOD;
        inv[i] = MOD - inv[MOD%i]*(MOD/i)%MOD;
        finv[i] = finv[i-1]*inv[i]%MOD;
    }
}

long long COM(int n,int k)
{
    if (n < k || n < 0 || k < 0){
        return 0;
    }
    else {
        return fac[n]*(finv[k]*finv[n-k]%MOD)%MOD;
    }
}

int main()
{
    int x,y;
    cin >> x >> y;
    
    if ((x*2-y)%3 == 0 && x*2-y >= 0 && (y*2-x)%3 == 0 && y*2-x >= 0){
        int s = (x*2-y)/3;
        int t = (y*2-x)/3;
        COMinit();
        cout << COM(s+t,t) << endl;
    }
    else {
        cout << "0" << endl;
    }
}


Measured memory_bytes: 23680
#include<bits/stdc++.h>
using namespace std;
using ll=long long;
const int N=1e5+10,M=1e2+10;
const int mod=1e9+7;
const int inf=1e9;
int w[M],v[M];
int dp[M][N];

int main(){
    int W,n;
    int val=0;
    cin>>n>>W;
    for(int i=1;i<=n;i++){
        cin>>w[i]>>v[i];
        val+=v[i];
    }
    dp[0][0]=0;
    for(int i=1;i<=val;i++) dp[0][i]=inf;
    for(int j=1;j<=n;j++){
        for(int i=0;i<=val;i++){
            dp[j][i]=dp[j-1][i];
            if(i>=v[j]){
                dp[j][i]=min(dp[j][i],dp[j-1][i-v[j]] + w[j]);
            }
        }
    }
    
    int ans=0;
    for(int i=1;i<=val;i++){
        if(dp[n][i]<=W) ans=i;
    }
    
    cout<<ans<<'\n';
    return 0;
}

Measured memory_bytes: 43004
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep1(i, n) for (int i = 1; i <= (int)(n); i++)
typedef int64_t Int;

bool kawaisou(int A, int B, int C) {
  if (A == B && A != C) return true;
  else if (A == C && A != B) return true;
  else if (B == C && A != B) return true;
  else return false;
}

int main(){
  int A, B, C;
  cin >> A >> B >> C;
  
  if (kawaisou(A,B,C)) cout << "Yes" << endl;
  else cout << "No" << endl;
  

}


Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<algorithm>
#include<iomanip>
#include<utility>
#include<iomanip>
#include<map>
#include<cmath>
#include<cstdio>
#define rep(i,n) for(int i=0; i<(n); ++i)
using namespace std;
using ll =long long;
using P = pair<int,int>;

int main(){
    int n,l,ans=0,ab;
    cin >> n >> l;
    vector<int> app(n);
    rep(i,n) app[i] = l+i; 

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

    ab = app[0];

    rep(i,n){
       ab = min(abs(ab),abs(app[i]));
       ans += app[i];
    }

    rep(i,n){
        if(ab==abs(app[i]))
            ab=app[i];
    }

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

Measured memory_bytes: 256
A, B = map(int, input().split())

def gcd(a, b):  # a,bの最大公約数
    while b:
        a, b = b, a % b
    return a

def prime_factor(n):  # nを素因数分解
    arr = []
    temp = n
    for i in range(2, int(-(-n**0.5//1))+1):
        if temp % i == 0:
            cnt = 0
            while temp % i == 0:
                cnt += 1
                temp //= i
            arr.append([i, cnt])
    if temp != 1:
        arr.append([temp, 1])
    if arr == []:
        arr.append([n, 1])
    return arr

g = gcd(A, B)
f = prime_factor(g)

ans = len(f)
if f[0][0] != 1:
    ans += 1
print(ans)

Measured memory_bytes: 3064
# 絶対値と言われたら＋とーのどっちにするのか分からない→全通りやれば良い
# 向きを固定する。
# 例えばxが+, yが-、zが+だとすると
# (x,y,z) = (3, -4, -1)の「貢献度」は3+4-1 = 6になる
# あとは貢献度の順にソートして、上位からM個を取れば良い

# L1ノルムが一定→ダイヤ型（正八面体）
# マンハッタン距離を使う問題とも通じるものがある。
# https://atcoder.jp/contests/abc178/tasks/abc178_e ABC178 E Dist Max
# 「いくつか向きの候補があるから、全通りを考えて最大を取ればいいよね。向きを固定すればあとは単純な貪欲だよね」

import copy

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

ans = 0
for x_sign in (1, -1):
    for y_sign in (1, -1):
        for z_sign in (1, -1):
            # params = temp.copy() これでは浅いコピーになるので、同じオブジェクトを指してしまう
            params = copy.deepcopy(temp)

            for xyz in params:
                xyz.append(x_sign * xyz[0] + y_sign * xyz[1] + z_sign * xyz[2])
            
            params.sort(key=lambda xyz: xyz[3], reverse=True)
            ans_sign = sum([xyz[3] for xyz in params[:m]])
            ans = max(ans, ans_sign)

print(ans)


Measured memory_bytes: 9696
#include <iostream>
#include <vector>
#include <random>

using namespace std;

std::mt19937 generator;

const int MAXN = 333;
int a[MAXN][MAXN];
int main()
{
    std::ios_base::sync_with_stdio(false);
    std::cin.tie(nullptr);

    int n;
    cin >> n;
    long long sum = 0;
    for (int i = 0; i < n; i++) {
        for (int j = 0; j < n; j++) {
            cin >> a[i][j];
            sum += a[i][j];
        }
    }

    for (int i = 0; i < n; i++) {
        for (int j = i + 1; j < n; j++) {
            for (int k = 0; k < n; k++) {
                if (k == i || k == j) continue;

                if (a[i][k] + a[k][j] < a[i][j]) {
                    cout << -1 << endl;
                    return 0;
                }
                if (a[i][k] + a[k][j] == a[i][j]) {
                    sum -= 2 * 1ll * a[i][j];
                    break;
                }
            }
        }
    }
    cout << sum / 2 << endl;


    return 0;
}


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

using namespace std;

const int maxA = 2000;
const int maxB = 2000;
const int maxN = maxA + maxB;
const char fendl = '\n';

int A, B, N;
bool f[maxN];

inline bool query(const int & a, const int & b) {
	cout << '?' << ' ' << a << ' ' << b << fendl;
	cout.flush();

	char c;
	cin >> c;

	return c == 'Y';
}

inline void answer(const bool & ans) {
	if (ans) {
		cout << '!' << ' ';
		for (int i = 0; i < N; i++)
			cout << f[i];
		cout << '\n';
		cout.flush();
	} else {
		cout << "Impossible" << fendl;
		cout.flush();
	}
}

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

	cin >> A >> B;

	if (A <= B) {
		answer(false);
	} else {
		N = A + B;
		stack<int> stk;
		for (int i = 0; i < N; ) {
			if (stk.empty()) {
				if (i == N - 1) {
					stk.push(i);
					i++;
				} else {
					if (query(i, i + 1)) {
						stk.push(i);
						stk.push(i + 1);
					}
					i += 2;
				}
			} else {
				int u = stk.top(), v = i;
				if (query(u, v))
					stk.push(v);
				else
					stk.pop();
				i++;
			}
		}
		int u = stk.top();
		f[u] = true;
		for (int i = 0; i < N; i++) {
			if (i == u)
				continue;
			f[i] = query(u, i);
		}
		answer(true);
	}

	return 0;
}


Measured memory_bytes: 724
from operator import itemgetter
from queue import deque

N = int(input())

xin = []
yin = []

for _ in range(N):
    x, y = map(int, input().split())
    xin.append(x)
    yin.append(y)
    
xin = sorted(list(enumerate(xin)), key=itemgetter(1))
yin = sorted(list(enumerate(yin)), key=itemgetter(1))

xd = []
yd = []

for i in range(N-1):
    xd.append((xin[i+1][1] - xin[i][1], (xin[i][0], xin[i+1][0])))
    yd.append((yin[i+1][1] - yin[i][1], (yin[i][0], yin[i+1][0])))
    
xdq = deque(sorted(xd))
ydq = deque(sorted(yd))

par = list(range(N))

def find(x):
    if x == par[x]:
        return x
    else:
        par[x] = find(par[x])
        return par[x]
    
    
def union(x, y):
    px, py = find(x), find(y)
    if px != py:
        par[py] = px
    
ans = 0

while xdq or ydq:
    if xdq and (not ydq or xdq[0] < ydq[0]):
        d, (i, j) = xdq.popleft()
    else:
        d, (i, j) = ydq.popleft()
        
    if find(i) != find(j):
        ans += d
        union(i, j)
        
print(ans)

Measured memory_bytes: 70884
#include <bits/stdc++.h>
#include <algorithm>  
#include <unordered_set>
#include <cmath>

#define ll long long

using namespace std;

vector<ll> A;

bool checkAllCutLessK(ll x, ll k) {

	ll N = A.size();
	ll now = 0;

	for (ll i = 0; i < N; i++) {
		now += (A[i] - 1) / x;
	}

	return now <= k;
}

int main() {

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

	ll N, K;

	cin >> N >> K;

	A = vector<ll>(N);

	ll maxNum = -1;

	for (int i = 0; i < N; i++) {
		cin >> A[i];
		maxNum = max(A[i], maxNum);
	}

	
	ll left = 0;
	ll right = maxNum;

	while (left + 1 < right) {
		ll mid = (left + right) / 2;

		if (checkAllCutLessK(mid, K)) {
			right = mid;
		}
		else {
			left = mid;
		}
	}

	cout << right << endl;

	
	return 0;
}


Measured memory_bytes: 4720
import java.util.Scanner;

public class Main
{

	public static void main(String[] args)
	{
		Scanner in=new Scanner(System.in);
		int a,b;
		String op;
		
		a=in.nextInt();
		op=in.next();
		b=in.nextInt();
		
		while(!op.equals("?"))
		{
			if(op.equals("+"))
					System.out.println(a+b);
			else if(op.equals("-"))
				System.out.println(a-b);
			else if(op.equals("*"))
				System.out.println(a*b);
			else if(op.equals("/"))
				System.out.println(a/b);
			
			a=in.nextInt();
			op=in.next();
			b=in.nextInt();
		}

	}

}

Measured memory_bytes: 26348
#include <algorithm>
#include <iostream>
#include <vector>
#include <string>
#include <queue>

using namespace std;

using i8 = int8_t;
using i16 = int16_t;
using i32 = int32_t;
using i64 = int64_t;
using u8 = uint8_t;
using u16 = uint16_t;
using u32 = uint32_t;
using u64 = uint64_t;

int main(int argc, char* argv[]) {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);

  i32 N;
  cin >> N;
  
  vector<i32> A(N);
  for(i32 i = 0; i < N; ++i) {
    i32 a;
    cin >> a;
    A[a-1] = i+1;
  }
  
  for(i32 i = 0; i < N-1; ++i) {
    cout << A[i] << " ";
  }
  cout << A.back() << endl;
  
  return 0;
}


Measured memory_bytes: 1280
# -*- coding: utf-8 -*-
"""
Created on Fri Jan 24 18:15:07 2020
abc145b
@author: manakamura
"""
import sys

n = int(input())
#tmp = input().split()
#s = list(map(lambda a: int(a), tmp))
s = input()

if(n%2==1):
    print("No")
    sys.exit()
    

for i in range(n//2):
    if(s[i]!=s[i+n//2]):
        print("No")
        sys.exit()
print("Yes")





Measured memory_bytes: 3060
//yhn's
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<cmath>
#include<vector>
using namespace std;

typedef long long ll;
const int MAXN=2e5+5;

int n;
int fa[MAXN];
ll d,siz[MAXN],cnt[MAXN];
vector<pair<ll,int> > mp;
struct node{
    ll x,y;
    int id;
    bool operator < (const node &a) const{
        if(x==a.x) return y<a.y;
        return x<a.x;
    }
}p[MAXN];

int find(int x){
    if(fa[x]==x) return x;
    return fa[x]=find(fa[x]);
}

ll dis(int x,int y){
    return abs(p[x].x-p[y].x)+abs(p[x].y-p[y].y);
}

void work(int now){
    mp.clear();
    vector<pair<ll,int> >::iterator lasx,it;
    int las=1,flag=0;
    for(int i=1;i<=n;i++){
        if(p[i].x!=p[i-1].x){
            mp.clear();
            flag=1;
        }
        while(p[i].x-p[las].x>d&&las<=n) las++;
        while(p[i].x-p[las].x==d&&las<=n){
            mp.push_back(make_pair(p[las].y,p[las].id));
            las++;
        }
        it=lower_bound(mp.begin(),mp.end(),make_pair(p[i].y-d+now,0));
        if(it==mp.end()||it->first>p[i].y+d-now) continue;
        if(flag){
            flag=0;
            lasx=mp.begin();
        }
        lasx=max(lasx,it);
        for(;lasx!=mp.end()&&lasx->first<=p[i].y+d-now;lasx++){
            int x=lasx->second;
            int y=p[i].id;
            if(find(x)!=find(y))
                fa[find(x)]=find(y);
        }
        cnt[p[i].id]+=lasx-it;
        if(lasx!=it) lasx--;
    }
}

int main(){
    int a,b;
    scanf("%d%d%d",&n,&a,&b);
    for(int i=1;i<=n;i++)
        scanf("%lld%lld",&p[i].x,&p[i].y),p[i].id=i;
    for(int i=1;i<=n;i++) fa[i]=i;
    d=dis(a,b);
    for(int i=1;i<=n;i++){
        int x=p[i].x,y=p[i].y;
        p[i].x=x-y;
        p[i].y=x+y;
    }
    sort(p+1,p+n+1);
    work(0);
    for(int i=1;i<=n;i++)
        swap(p[i].x,p[i].y);
    sort(p+1,p+n+1);
    work(1);
    for(int i=1;i<=n;i++)
        siz[find(i)]+=cnt[i];
    printf("%lld",siz[find(a)]);
}


Measured memory_bytes: 9972
#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
#define rep(i,n) for(int i = 0, i_len = n; (i) < (i_len); ++(i))
#define repp(i,n) for(int i = 1, i_len = n; (i) <= (i_len); ++(i))
#define per(i,n) for(int i = n-1; (i) >= 0; --(i))
#define perr(i,n) for(int i = n; (i) > 0; --(i))
#define sz(x) ((int)(x).size())
#define popcnt __builtin_popcount
#define pb push_back
#define all(v) (v).begin(),(v).end()
#define rall(v) (v).begin(),(v).end(),greater<>()
#define debug(x) cerr << #x << ':' << x << '\n'
#define Pi 3.1415926535
#define MOD 1000000007
using namespace std;
using ll = long long;
using pint = pair<int,int>;
using itn = int;
using vint = vector<int>;
template<class T,class S> inline bool chmax(T& a, S b){if(a<b){a = b; return true;} return false;}
template<class T,class S> inline bool chmin(T& a, S b){if(a>b){a = b; return true;} return false;}
template<class T> T gcd(T a, T b){return b?gcd(b,a%b):a;}
template<class T> T lcm(T a, T b){return a*b/gcd(a,b);}
void yes(){cout << "Yes" << '\n';}
void no(){cout << "No" << '\n';}

int solve(){
    double n, d; cin >> n >> d;
    int ans = 0;
    vector<long double> x(n), y(n), dist(n);
    rep(i,n){
        cin >> x[i] >> y[i];

        if(x[i]*x[i]+y[i]*y[i] - d*d <= 0) ++ans;
    }
    cout << ans << endl;

    return 0;
}

int main(){
    cin.tie(0);
    cout << fixed << setprecision(10);
    ios::sync_with_stdio(false);
    solve();
    return 0;
}


Measured memory_bytes: 12784
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (n); i++)
#define ALL(v) (v).begin(), (v).end()
using ll = long long;
using P = pair<int, int>;
constexpr int INF = 1e9;
constexpr long long LINF = 1e18;
constexpr long long MOD = 1e9 + 7;

signed main() {
    ll a, b, n;
    cin >> a >> b >> n;
    ll x = min(n, b - 1);
    cout << a * x / b - a * (x / b) << endl;
    return 0;
}

Measured memory_bytes: 3620
#include <algorithm>
#include <cassert>
#include <cctype>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstring>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <vector>
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
#define show(x) cout << #x << " = " << x << endl;
int main() {
    ll k, a, b;
    cin >> k >> a >> b;
    ll ans = 0;
    if (a >= k) {
        cout << 1 << endl;
    } else {
        if (a <= b) {
            cout << -1 << endl;
        } else {
            cout << 1 + (k - a + a - b - 1) / (a - b) * 2 << endl;
        }
    }
}


Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <limits.h>
#include <queue>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
#define REP(i, n) for(int i=0; i<n; i++)

vector<ll> V[4];
ll w0;
int N;
ll W;

ll calc(int v0, int v1, int v2, int v3){
    ll sum = 0;
    ll w = W;
    REP(i,v0){
        sum += V[0][i];
        w -= w0;
    }
    REP(i,v1){
        sum += V[1][i];
        w -= w0+1;
    }
    REP(i,v2){
        sum += V[2][i];
        w -= w0+2;
    }
    REP(i,v3){
        sum += V[3][i];
        w -= w0+3;
    }
    
    return (w < 0) ? 0LL : sum;
}

int main(){
    cin >> N >> W;
    REP(i,N){
        ll w, v;
        cin >> w >> v;
        if(i == 0) w0 = w;
        V[w-w0].push_back(v);
    }
    REP(i,4){
        sort(V[i].begin(), V[i].end(), greater<ll>());
    }
    ll ans = 0;
    ll w = 0;
    REP(i,101){
        if(i > V[0].size()) break;
        //if(i > 0) w += w0;
        REP(j,101){
            if(j > V[1].size()) break;
            //if(j > 0) w += w0+1;
            REP(k,101){
                if(k > V[2].size()) break;
                //if(k > 0) w += w0+2;
                REP(l,101){
                    if(l > V[3].size()) break;
                    //if(l > 0) w += w0+3;
                    //if(w <= W){
                    ans = max(ans, calc(i,j,k,l));
                    //}
                }
            }
        }
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.math.BigInteger;
import java.util.*;

public class Main{

    static class FastReader {
        BufferedReader br;
        StringTokenizer st;

        public FastReader() {
            br = new BufferedReader(new InputStreamReader(System.in));
        }

        String next() {
            while (st == null || !st.hasMoreTokens()) {
                try {
                    st = new StringTokenizer(br.readLine());
                } catch (IOException e) {
                    // TODO Auto-generated catch block
                    e.printStackTrace();
                }
            }
            return st.nextToken();
        }

        String nextLine() {
            String str = "";
            try {
                str = br.readLine();
            } catch (IOException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }
            return str;
        }

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

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

        long nextLong() {

            return Long.parseLong(next());
        }

        BigInteger nextBigIntger() {
            BigInteger bb = new BigInteger(next());
            return bb;
        }
    }
    public static void main(String args[]) {
        FastReader sc = new FastReader();
        int n = sc.nextInt(),k =sc.nextInt(),ans=0;
        ans=(2*k-n);
        System.out.println(ans);
        }

}




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

using VI = vector<int>;
using VVI = vector<VI>;
using PII = pair<int, int>;
using LL = long long;
using VL = vector<LL>;
using VVL = vector<VL>;
using PLL = pair<LL, LL>;
using VS = vector<string>;

#define ALL(a)  begin((a)),end((a))
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define EB emplace_back
#define MP make_pair
#define SZ(a) int((a).size())
#define SORT(c) sort(ALL((c)))
#define RSORT(c) sort(RALL((c)))

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

#define FF first
#define SS second
template<class S, class T>
istream& operator>>(istream& is, pair<S,T>& p){
  return is >> p.FF >> p.SS;
}
template<class S, class T>
ostream& operator<<(ostream& os, const pair<S,T>& p){
  return os << p.FF << " " << p.SS;
}
template<class T>
void maxi(T& x, T y){
  if(x < y) x = y;
}
template<class T>
void mini(T& x, T y){
  if(x > y) x = y;
}


const double EPS = 1e-10;
const double PI  = acos(-1.0);
const LL MOD = 1e9+7;

const int UB = 110;
int N;
int rs[UB];
vector<vector<PII>> xs(3, vector<PII>(UB));

bool check(vector<vector<PII>> ss){
  vector<PII> score(N);
  REP(i,N) score[i].SS = i;
  REP(i,3)
	sort(RALL(ss[i]));
  REP(j,3){
	int rank = 0;
	REP(i,N){
	  if(i>0 && ss[j][i].FF != ss[j][i-1].FF)
		rank = i;
	  score[ss[j][i].SS].FF += rs[rank];
	}
  }

  sort(RALL(score));
  int rank = 0;
  for(int i=0;i<N;++i){
	if(i>0 && score[i].FF != score[i-1].FF)
	  rank = i;
	if(score[i].SS == 0)
	  break;
  }

  return rank+1 < 9;
}

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

  cin >> N;
  REP(i,N) cin >> rs[i];
  REP(i,N)
	cin >> xs[0][i].FF >> xs[1][i].FF >> xs[2][i].FF;
  REP(i,N) REP(j,3)
	xs[j][i].SS = i;

  REP(k,101){
	auto tmp = xs;
	REP(j,3){
	  tmp[j][0].FF += k;
	  if(check(tmp)){
		cout << k << endl;
		return 0;
	  }
	  tmp[j][0].FF -= k;
	}
  }
  cout << "Saiko" << endl;

  return 0;
}

Measured memory_bytes: 3208
n, k = [int(i) for i in input().split()]
A = [int(i) for i in input().split()]

B = []
for i, a in zip(range(1, n+1), A):
    B.append([a, i])

B.sort(reverse=True)
ans = []

for i in range(n):
    B[i][0] -= 1
    B[i].append(i)
    ans.append(B[i][1])

last = n - 1
for i in range(k):
    mixi = min(B[:last] + B[last+1:])[2]
    cnt = 1
    for j in range(n):
        if j == last or j == mixi:
            continue
        B[j][0] -= 1
        if B[j][0] < 0:
            print(-1)
            exit()
        ans.append(B[j][1])

    ans.append(B[mixi][1])
    B[mixi][0] -= 1
    if B[mixi][0] < 0:
        print(-1)
        exit()
    last = mixi

print(len(ans))
print(*ans)

Measured memory_bytes: 42480
import java.util.ArrayList;
import java.util.Scanner;

public class Main {

	static Scanner sc = new Scanner(System.in);
	static int[][] map;
	static int[] DY = new int[] { 1, 0, -1, 0 };
	static int[] DX = new int[] { 0, 1, 0, -1 };

	public static void main(String[] args) {
		while (true) {
			int W = sc.nextInt();
			if (W == 0) break;
			int H = sc.nextInt();
			map = new int[H + 2][W + 2];
			int sx = 0;
			int sy = 0;
			for (int i = 0; i < H; ++i) {
				for (int j = 0; j < W; ++j) {
					int s = sc.nextInt();
					if (s == 2) {
						sx = j + 1;
						sy = i + 1;
						s = 1;
					}
					map[i + 1][j + 1] = s;
				}
			}
			boolean[][][] visited = new boolean[H + 2][W + 2][7];
			ArrayList<State> cur = new ArrayList<State>();
			cur.add(new State(sx, sy, 6));
			visited[sy][sx][6] = true;
			int ans = -1;
			int t = 1;
			BFS: while (!cur.isEmpty()) {
				ArrayList<State> next = new ArrayList<State>();
				for (State st : cur) {
					if (st.h <= 1) continue;
					for (int i = 0; i < 4; ++i) {
						int nx = st.x + DX[i];
						int ny = st.y + DY[i];
						if (map[ny][nx] == 3) {
							ans = t;
							break BFS;
						}
						if (map[ny][nx] == 0) continue;
						int nh = (map[ny][nx] == 4 ? 6 : st.h - 1);
						if (visited[ny][nx][nh]) continue;
						visited[ny][nx][nh] = true;
						next.add(new State(nx, ny, nh));
					}
				}
				cur = next;
				++t;
			}
			System.out.println(ans);
		}
	}

	static class State {
		int x, y, h;

		State(int x, int y, int h) {
			this.x = x;
			this.y = y;
			this.h = h;
		}
	}

}

Measured memory_bytes: 12000
#include <iostream>
#include <string>
#include <algorithm>
using namespace std;
string st[1001];
int main(){
	int i,j,k,n,m;
	cin>>n>>m;
	for(i=1;i<=n;i++)cin>>st[i];
	sort(st+1,st+n+1);
	for(i=1;i<=n;i++)cout<<st[i];
	cout<<endl;
	return 0;
}

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

int main(){
	char s[300000];
	int i;
	int min = 300000;
	int max = 0;
	
		
	scanf("%s",s);
	for(i=0;s[i]!='\0';i++){
		if(s[i]=='A' && min == 300000){
			min = i;
		}
		if(s[i]=='Z'&&max<i){
			max = i;
		}
	}
	printf("%d\n",max-min+1);
	
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for(ll i = 0, i##_len = (n); i < i##_len; i++)
#define reps(i, s, n) for(ll i = (s), i##_len = (n); i < i##_len; i++)
#define rrep(i, n) for(ll i = (n) - 1; i >= 0; i--)
#define rreps(i, e, n) for(ll i = (n) - 1; i >= (e); i--)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define sz(x) ((ll)(x).size())
#define len(x) ((ll)(x).length())
#define endl "\n"

const ll inf = LONG_LONG_MAX / 2 - 1;
ll n, k;
vector<ll> a;
vector<ll> dist;
ll st = -1, si = -1, idx = -1;

void dfs(ll v, ll d = 0) {
    if (dist[v] != inf) {
        idx = v;
        st = dist[v];
        si = d - st;
        return;
    }
    dist[v] = d;
    dfs(a[v], d + 1);
}

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    // ifstream in("input.txt");
    // cin.rdbuf(in.rdbuf());
    cin >> n >> k;
    a.resize(n);
    rep(i, n) {
        cin >> a[i];
        a[i]--;
    }
    dist.resize(n, inf);
    dfs(0);
    if (st >= k) {
        rep(i, n) {
            if (dist[i] == k) {
                cout << (i + 1) << endl;
                return 0;
            }
        }
    }
    else {
        k -= st;
        k %= si;
        ll v = dist[idx] + k;
        rep(i, n) {
            if (dist[i] == v) {
                cout << (i + 1) << endl;
                return 0;
            }
        }
    }
    return 0;
}


Measured memory_bytes: 6364
using namespace std;

//#define fileio

#ifndef fileio
#include <iostream>
#endif
#include <fstream>
#include <vector>
#include <queue>
#include <algorithm>
#include <set>
#include <map>
#include <assert.h>
#include <functional>
#include <math.h>
#include <string>
#include <ctime>

typedef long long ll;

#ifdef fileio
ifstream cin;
ofstream cout;
#endif


template< int mod >
struct ModInt {
    int x;

    ModInt() : x(0) {}

    ModInt(int64_t y) : x(y >= 0 ? y % mod : (mod - (-y) % mod) % mod) {}

    ModInt& operator+=(const ModInt& p) {
        if ((x += p.x) >= mod) x -= mod;
        return *this;
    }

    ModInt& operator-=(const ModInt& p) {
        if ((x += mod - p.x) >= mod) x -= mod;
        return *this;
    }

    ModInt& operator*=(const ModInt& p) {
        x = (int)(1LL * x * p.x % mod);
        return *this;
    }

    ModInt& operator/=(const ModInt& p) {
        *this *= p.inverse();
        return *this;
    }

    ModInt operator-() const { return ModInt(-x); }

    ModInt operator+(const ModInt& p) const { return ModInt(*this) += p; }

    ModInt operator-(const ModInt& p) const { return ModInt(*this) -= p; }

    ModInt operator*(const ModInt& p) const { return ModInt(*this) *= p; }

    ModInt operator/(const ModInt& p) const { return ModInt(*this) /= p; }

    bool operator==(const ModInt& p) const { return x == p.x; }

    bool operator!=(const ModInt& p) const { return x != p.x; }

    ModInt inverse() const {
        int a = x, b = mod, u = 1, v = 0, t;
        while (b > 0) {
            t = a / b;
            swap(a -= t * b, b);
            swap(u -= t * v, v);
        }
        return ModInt(u);
    }

    ModInt pow(int64_t n) const {
        ModInt ret(1), mul(x);
        while (n > 0) {
            if (n & 1) ret *= mul;
            mul *= mul;
            n >>= 1;
        }
        return ret;
    }

    friend ostream& operator<<(ostream& os, const ModInt& p) {
        return os << p.x;
    }

    friend istream& operator>>(istream& is, ModInt& a) {
        int64_t t;
        is >> t;
        a = ModInt< mod >(t);
        return (is);
    }

    static int get_mod() { return mod; }
};

using mint = ModInt< 1000000007 >;





int main() {
    ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#ifdef fileio
    cin.open("Text.txt");
    cout.open("Output.txt");
#endif
    int n;
    cin >> n;
    mint sum = 0;
    mint sumsq = 0;
    for (int i = 0; i < n; i++) {
        mint x;
        cin >> x;
        sum += x;
        sumsq += (x * x);
    }
    cout << (sum * sum - sumsq) / 2 << endl;
    

}


Measured memory_bytes: 3636
K, N = map(int, input().split(' '))
A_ls = list(map(int, input().split(' ')))
max_l = -1
for i in range(N):
    l = A_ls[(i + 1) % len(A_ls)] - A_ls[i]
    if l < 0:
        l = K - A_ls[i] + A_ls[(i + 1) % len(A_ls)]
    if max_l == -1:
        max_l = l
    else:
        max_l = max(max_l, l)
print(K - max_l)

Measured memory_bytes: 32296
N=int(input())
H=list(map(int,input().split()))
a=1
if N>1 and H[0]>H[1]:
    H[0]-=1
for i in range(N-1):
    if H[i]<H[i+1]:
        H[i+1]-=1
    elif H[i]>H[i+1]:
        a=0
        break
print(['No','Yes'][a])

Measured memory_bytes: 14252
#include <iostream>
#include <functional>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <vector>
#include <string>
#include <set>
#include <queue>
#include <map>
#include <iomanip>
using namespace std;
#define rep(i,n) for(ll i=0;i<n;++i)
#define repi(i,n) for(ll i=n-1;i>=0;--i)
#define sll(n) scanf("%lld", &n);
#define slf(n) scanf("%lf", &n);
typedef long long ll;
typedef double lf;
static const ll max_n = 100010;
static const ll mod = 1000000007;
static const ll max_value = 100000000000100;
static const ll max_value2 = 1000000000000000000;
// vector<vector<vector<ll>>> dp(max_n, vector<vector<ll>>(max_n, vector<ll>(max_n*max_n, 0)));



void Main(){
    // bool is_ok = true;
    // printf("------------- V=%lld---------\n", V);
    ll N, a, ans = 1;
    sll(N);
    bool is_ok = true;
    bool has_zero = false;
    rep(i, N){
        sll(a);
        ll res = max_value2 % a;
        ll baisu = max_value2 - res;
        if(a == 0 || ans == 0){
            ans = 0;
            has_zero = true;
            is_ok = true;
        }else{
            if(max_value2 / a < ans){
                is_ok = false;
            }else if(is_ok){
                ans *= a;
            }
        }

    }

    if(is_ok){
        cout << ans <<endl;
    }else{
        cout << "-1" <<endl;
    }




    // cout<<fixed<<setprecision(10)<<num<<endl;
    // cout << num << endl;

}

int main(){
    Main();

    return 0;

}

Measured memory_bytes: 3240
import java.util.*;

public class Main {

    public static void main(String args[]) {

        // 入力
        Scanner sc = new Scanner(System.in);
        int n = Integer.parseInt(sc.next());
        Integer[] a = new Integer[n];
        Arrays.setAll(a, i -> Integer.parseInt(sc.next()) - 1);
        sc.close();

        // 主処理
        List<Integer> pushed = new ArrayList<>();
        int index = 0;
        int count = 0;
        while (index != 1) {
            if (a[index] == 0) {
                break;
            }
            int temp = a[index];
            a[index] = 0;
            index = temp;
            count++;
        }

        boolean judge = index == 1;
        int result = judge ? count : -1;

        // 出力
        System.out.println(result);
    }
}


Measured memory_bytes: 50056
// #define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(v) v.begin(), v.end()
#define Graph vector<vector<int>>
typedef long long ll;
typedef pair<int, int> P;
const int INF = 1000000007;

// #include <boost/multiprecision/cpp_dec_float.hpp>
// #include <boost/multiprecision/cpp_int.hpp>
// namespace mp = boost::multiprecision;
// using Bint = mp::cpp_int;
// using Real = mp::number<mp::cpp_dec_float<1024>>;

int main(){
    int N; 
    scanf("%d", &N);
    vector<int> A(N);
    rep(i, N) scanf("%d", &A[i]);
    int flag = 1, ans = 0;
    while(flag){
        flag = 0;
        for(int j = N -1; j >=0 ; j--){
            if(A[j] < A[j - 1]){
                swap(A[j], A[j-1]);
                flag = 1;
                ans++;
            }
        }
    }
    rep(i, N){
        printf("%d", A[i]);
        if(i != N - 1) printf(" ");
        else printf("\n");
    }
    printf("%d\n", ans);
}


Measured memory_bytes: 3232
c = [ list(map(int, input().split())) for i in range(3) ]
x,y = [0]*3, [0]*3

for i in range(3):
    y[i]=c[0][i]-x[0]
    for j in range(3):
        x[i]=c[i][0]-y[0]

for i in range(3):
    for j in range(3):
        if x[i]+y[j] != c[i][j]:
            print("No")
            exit(0)

print("Yes")
exit(0)


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

prev = a[0]
ans = 1

while True:
    if prev == 2 or ans > N:
        break
    else:
        prev = a[prev-1]
        ans += 1

print(ans if ans <= N else -1)



Measured memory_bytes: 7084
s = raw_input()
#print(s)

ch_lst = "abcdefghijklmnopqrstqvwxyz"
#ch_lst = [chr(i) for i in range(ord('a'), ord('z')+1)]
#print(ch_lst)

match = 0
for j in ch_lst:
  ch = s.find(j)
  if ch != -1:
    continue
  else:
    match = 1
    break

if match == 0:
  print("None")
elif match == 1:
  print(j)

Measured memory_bytes: 2692
#include<iostream>
#include<queue>
#include<string>
#include<cmath>
#include<cstdio>
#include<cctype>
#include<cstring>
#include<iomanip>
#include<cstdlib>
#include<ctime>
#include<set>
#include<map>
#include<utility>
#include<vector>
#include<stack>
#include<sstream>
#include<algorithm>
using namespace std;
/****************************/
#define ll long long
#define vi vector<int>
#define pii pair<int,int>
#define vpii vector<pair<int,int> >
#define qi queue<int>
#define mii map<int,int>
#define msi map<string,int>
#define vs vector<string>
#define vc vector<char>
/****************************/
#define rep(i,n) for(ll i=0;i<(n);i++)
#define rep2(i,n) for(ll i=(n)-1;i>=0;i--)
#define rep3(i,a,n) for(ll i=(a);i<(n);i++)
#define rep4(i,a,n) for(ll i=(a)-1;i>=n;i--)
#define mp make_pair
#define pb push_back
#define st first
#define nd second
#define pi 3.1415926535897932384626433832795
#define zero(n) memset(n,0,sizeof(n));
#define SZ(n) n.size()
#define sn st.nd 
ll dx[4]={0,-1,0,1};
ll dy[4]={1,0,-1,0};
/****************************/
string s;
ll n,m,k;
vi v;
vi uni(vi v)
{
	vi ans=v;
	sort(ans.begin(),ans.end());
	ans.erase(unique(ans.begin(),ans.end()),ans.end());
	return ans;
}
int quickpower(int m,int n)
{
    if(n==1) return m;
    int temp=quickpower(m,n/2);
    return (n%2==0 ? 1 : m)*temp*temp;
}
int main()
{
	ios::sync_with_stdio(0);
	cin>>s;
	if(s=="ABC")
	{
		cout<<"ARC";
	}
	else
	{
		cout<<"ABC";
	}
	return 0;
}

Measured memory_bytes: 3608