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

int main(){
  string s;
  cin >> s;
  vector<bool> vec(26,true);
  for(char c:s)vec.at(c-97) = false;
  for(int i=0;i<26;i++)if(vec.at(i)){
    cout << (char)(i+97) << endl;
    return 0;
  }
  cout << "None" << endl;
}

Measured memory_bytes: 512
#include<cstdio>
#include<string>
#include<cstring>
#include<utility>
#include<cmath>
#include<map>
#include<queue>
#include<set>
#include<algorithm>
#include<vector>
#include<iostream>
#define ll long long
#define pii pair<int,int>
#define mp make_pair
#define fi first
#define se second
#define inf 0x7fffffff
using namespace std;
int main()
{
	int i,j,k,n,m,x,y;
	bool bo=1;
	scanf("%d%d",&n,&m);
	for(i=2;i<=sqrt(m);i++)
	{
		if(m%i==0)
		{
			bo=0;
			break;
		}
	}
	if(bo)
	{
		printf("1");
		return 0;
	}
	for(i=n;i<=m;i++)
	{
		if(m%i==0)
		{
			printf("%d",m/i);
			return 0;
		}
	}
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ll long long
#define INF 1e18
using namespace std;int u[10001],v[10001];ll w[10001],dis[5001];ll p;
int main(){
	int n,m;
	cin>>n>>m>>p;
	for(int i=1;i<=m;i++){
		scanf("%d%d%lld",&u[i],&v[i],&w[i]);
		w[i]-=p;
	}
	for(int i=2;i<=n;i++){
		dis[i]=-INF;
	}dis[1]=0;
	for(int i=1;i<=n;i++){
		for(int j=1;j<=m;j++){
			if(dis[u[j]]!=-INF&&dis[u[j]]+w[j]>dis[v[j]])dis[v[j]]=dis[u[j]]+w[j];
		}
	}
	for(int i=1;i<=n;i++){
		for(int j=1;j<=m;j++){if(dis[u[j]]==-INF) continue;
			if(dis[u[j]]+w[j]>dis[v[j]])dis[v[j]]=INF;
		}
	}
	if(dis[n]==INF) cout<<-1;
	else cout<<max(dis[n],0ll);
}
/*3 3 10
1 2 20
2 3 30
1 3 45
*/

Measured memory_bytes: 512
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {

		Scanner s = new Scanner(System.in);
		final int A = s.nextInt();
		final int B = s.nextInt();
		s.close();

		if(A%3 == 0 || B%3 == 0 || (A+B)%3 == 0) {
			System.out.println("Possible");
		} else {
			System.out.println("Impossible");
		}

	}

}

Measured memory_bytes: 21716
#include<bits/stdc++.h>
using namespace std;
int main(){
    /*ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);cout.precision(30);*/
    int n,i;
    int avg=0;
    float avg1,avg2;
    int res=0;
    int res2=0;
    cin>>n;
    int coordinates [n];
    for(i=0;i<n;i++){
        cin>>coordinates[i];
        avg=avg+coordinates[i];
    }
    avg1=floor((float)avg/(float)n);
    avg2=ceil((float)avg/(float)n);
    for(i=0;i<n;i++){
        res=res+pow((coordinates[i]-avg1),2);
        res2=res2+pow((coordinates[i]-(avg2)),2);
    }
    if(res2>=res){
        cout<<res;
    }
    else{
        cout<<res2;
    }
    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cmath>
#include<queue>
#include<vector>
#include<map>
#include<list>
#include<cctype>
#include<climits>
#include<bitset>
#include<stack>

using namespace std;

typedef long long ll;

const int dx[4] = { 1, 0, -1, 0 }, dy[4] = { 0, 1, 0, -1 };
const int MAX = 18;
int W, H, fld[10][10];
int P, sx, sy;
map<pair<pair<int, int>, int>, int> memo;

inline int CountBit(int s)
{
	int res = 0;
	for (int i = 0; i < P; i++) res += (s >> i) & 1;
	return res;
}

inline bool IsInside(int x, int y)
{
	return 0 <= x && x < W && 0 <= y && y < H;
}

inline bool CanDown(int x, int y, int s, int noBits)
{
	if (x == sx && y == sy && noBits == P) return true;
	if (fld[y][x] == -1) return false;
	return ((s >> fld[y][x]) & 1) == 0;
}

int DFS(int x, int y, int s, int &order)
{
	order++;
	int noBits = CountBit(s);
	if (x == sx && y == sy && noBits == P) return 1;
	pair<pair<int, int>, int> state = make_pair(make_pair(x, y), s);
	if (noBits < MAX)
	{
		map<pair<pair<int, int>, int>, int>::iterator itr = memo.find(state);
		if (itr != memo.end()) return itr->second;
	}
	int sum = 0, cnt = 0;
	for (int i = 0; i < 4; i++)
	{
		int nx = x + dx[i], ny = y + dy[i];
		while (IsInside(nx, ny) && !CanDown(nx, ny, s, noBits))
			nx += dx[i], ny += dy[i];
		if (!IsInside(nx, ny)) continue;
		sum += DFS(nx, ny, s | (1 << fld[ny][nx]), cnt);
	}
	order += cnt;
	if (noBits < MAX && cnt >= 10) memo[state] = sum;
	return sum;
}

signed main()
{
	while (cin >> W >> H, W || H)
	{
		memo.clear();
		P = 0;
		for (int i = 0; i < H; i++)
		{
			for (int j = 0; j < W; j++)
			{
				cin >> fld[i][j];
				if (fld[i][j] == 0) fld[i][j] = -1;
				else if (fld[i][j] == 1) fld[i][j] = P++;
				else sx = j, sy = i, fld[i][j] = -1;
			}
		}
		int cnt = 0;
		printf("%d\n", DFS(sx, sy, 0, cnt));
	}
	return 0;
}

Measured memory_bytes: 35824
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main {
	public static void main(String[] args)throws IOException {
		 BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(System.in));
		 while(true){
			 String [] str = bufferedReader.readLine().split(" ");
			 Integer hInteger = Integer.parseInt(str[0]);
			 Integer wInteger = Integer.parseInt(str[1]);
			 
			 StringBuffer stringBuffer = new StringBuffer();
		 
			 if(hInteger == 0 && wInteger == 0){
				 break;
			 }
			 for(int i = 0; i < hInteger; i++){
				 for(int j = 0; j < wInteger; j++){
					 stringBuffer.append((i + j) % 2 == 0 ? "#" : ".");
					  }
				 stringBuffer.append("\n");
				 
			 }	 
			 System.out.println(stringBuffer);
		 }
		 
	}
}

Measured memory_bytes: 25976
""" abc055_a """

import sys

H = pow(10, 9) + 7

def _main():
    n_s, n_c = map(int, sys.stdin.readline().split(' '))

    if 2 * n_s <= n_c:
        result = n_s + int((n_c - n_s * 2) / 4)
    else:
        result = int(n_c / 2)

    print(result)

if __name__ == '__main__':
    _main()


Measured memory_bytes: 2940
#include <bits/stdc++.h>
#define ll long long
#define mod 1000000007
using namespace std;

int main()
{
	ios::sync_with_stdio(false);
	cin.tie(0);
	int n;	cin>>n;
	int a[n+1],b[n+1],i,j;
	for(i=1;i<=n;i++){
		cin>>a[i];	b[a[i]]=i;
	}

	int dp[n+1],len=0;
	for(i=n;i>=1;i--){
		dp[i]=1;
		if(a[i]<n && b[a[i]+1]>i)	dp[i]+=dp[b[a[i]+1]];
		len=max(len,dp[i]);
	}

	cout<<n-len<<endl;

	return 0;
}

Measured memory_bytes: 2560
#include<iostream>
#include<cstdio>
#include<cstring>
using namespace std;

struct C{
    int num;
    string str;
};

C Q[100000];

int head, tail;
int score;
int q;
int a;

void enqueue(C c){
    Q[tail] = c;
    if (tail == 99999) tail = 0;
    else tail++;
}

void dequeue(){
    C c = Q[head];
    if (head == 99999) head = 0;
    else head++;
}

void cul(C c){
    if (c.num > q){
        c.num -= q;
        score += q;
        dequeue();
        enqueue(c);
    }
    else {
        score += c.num;
        cout << c.str << ' ' << score << endl;
        dequeue();
        a ++;
    }
}


int main(){
    score = 0;
    a = 0;
    int n;
    cin >> n >> q;
    for(int i = 0; i < n; i ++){
        cin >> Q[i].str >> Q[i].num;
    }
    head = 0;
    tail = n;
    
    while(1){
        if (a == n) break;
        cul(Q[head]);
    }
    
    return 0;
}


Measured memory_bytes: 6964
from collections import defaultdict
from itertools import combinations


# time complexity: O(√n)
def prime_factorize(n, prime_factors=None):
    if prime_factors is None:
        prime_factors = defaultdict(int)
    i = 2
    while i * i <= n:
        if n % i == 0:
            while n % i == 0:
                prime_factors[i] += 1
                n //= i
        i += 1
    if n != 1:
        prime_factors[n] += 1
    return prime_factors


N = int(input())
prime_factors = defaultdict(int)
for n in range(1, N + 1):
    prime_factors = prime_factorize(n, prime_factors)

over_primes = defaultdict(list)
for p, e in prime_factors.items():
    for threshold in (2, 4, 14, 24, 74):
        if e >= threshold:
            over_primes[threshold].append(p)
num_shichigos = 0
for p1 in over_primes[2]:
    # (2, 4, 4)
    for p2_1, p2_2 in combinations(over_primes[4], 2):
        if p1 != p2_1 and p1 != p2_2:
            num_shichigos += 1
    # (2, 24)
    for p3 in over_primes[24]:
        if p1 != p3:
            num_shichigos += 1
for p1 in over_primes[4]:
    # (4, 14)
    for p2 in over_primes[14]:
        if p1 != p2:
            num_shichigos += 1
# (74)
num_shichigos += len(over_primes[74])
print(num_shichigos)


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

using namespace std;

#ifndef ONLINE_JUDGE
  #define pr_debug(...) do { printf("DEBUG: line %d: %s: ", __LINE__, __PRETTY_FUNCTION__); printf(__VA_ARGS__); } while(0)
  #define pr_vars(...) do { pr_debug(" "); pr_var(split(#__VA_ARGS__, ',').begin(), __VA_ARGS__); } while(0)
#else
  __attribute__ ((constructor)) static void fast_cin() { ios_base::sync_with_stdio(false); cin.tie(0); }
  #define pr_debug(...) do { } while(0)
  #define pr_vars(...) do { } while(0)
#endif /* ONLINE_JUDGE */

using ll = int64_t;
using ull = uint64_t;

template<typename T> ostream &operator<< (ostream &fout, const vector<T> &vec)
{ for (const auto &el : vec) fout << el << ' '; return fout; }

template<typename T> istream &operator>> (istream &fin, vector<T> &vec)
{ for (size_t i = 0; i < vec.size(); i++) fin >> vec[i]; return fin; }

vector<string> split(const string &s, char c) { vector<string> v; ull st = 0, fn = 0, lvl = 0;
for ( ; fn < s.size(); fn++ ) { if (s[fn] == c && lvl == 0) { v.push_back(s.substr(st, fn - st)); st = fn + 1; }
if (s[fn] == '(') { lvl++; } if (s[fn] == ')') { lvl--; } } v.push_back(s.substr(st, fn - st)); return v; }

void pr_var(vector<string>::iterator it) { (void) it; cout << endl; }
template<typename T, typename... Args> void pr_var(vector<string>::iterator it, T a, Args... args)
{ cout << *it << "=" << a << "  "; pr_var(++it, args...); }

ll div_ceil(ll n, ll d) { ll res = n / d; if (res >= 0) res += n % d ? 1 : 0; return res; }
ll gcd(ll a, ll b) { a = llabs(a); b = llabs(b); while (a && b) a > b ? a %= b : b %= a; return a + b; }
ll lcm(ll a, ll b) { ll c = gcd(a, b); return c == 0 ? 0 : llabs(a / c * b); }

#define setp(a) fixed << setprecision(a)
const double PI = acos(-1.0);
constexpr double EPS = 1e-9;
constexpr double INF = 2e18;

using mp = pair<ll, ll>;
using mt = tuple<ll, ll, ll>;    // unpack: tie(ll, ll, ll) = mt;

constexpr ll MAX = 1e5 + 5;

int main()
{
    ll n, h; cin >> n >> h;
    vector<mp> va(n), vb(n);

    for (ll i = 0; i < n; i++) {
        ll a, b; cin >> a >> b;
        va[i] = mp(a, i);
        vb[i] = mp(b, i);
    }
    sort(va.begin(), va.end());
    sort(vb.begin(), vb.end());

    ll dd = va[va.size() - 1].first;
    //ll di = va[va.size() - 1].second;

    ll res = 0;
    ll ib = vb.size() - 1;
    while (h > 0) {
        if (ib >= 0 && vb[ib].first > dd) { res++; h -= vb[ib].first; ib--; }
        else { ll c = div_ceil(h, dd); res += c; h -= dd * c; }
    }

    cout << res << endl;
    return 0;
}


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

int main(int argc, char const *argv[])
{
	int n,a,b;
	cin>>n>>a>>b;
	int ans[3]={},p;
	for (int i = 0; i < n; ++i)
	{
		cin>>p;
		if (p<=a)
		{
			++ans[0];
		}
		else if (p>=b+1)
		{
			++ans[2];
		}
		else
		{
			++ans[1];
		}
	}
	cout<<min({ans[0],ans[1],ans[2]})<<endl;
	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include<bits/stdc++.h>
#include<vector>
#define fo(i,n) for(long long i=0;i<n;i++)
#define ll long long int
#define inf 999999999999999999
#define pb push_back
#define fi first
#define se second
#define vi vector<ll>
#define vii vector<vector<ll>>
#define pi pair<ll,ll>
#define mp make_pair
#define MOD 1000000007
#define tr(c,it) for(auto it = (c).begin(); it != (c).end(); ++it)
#define fio ios_base::sync_with_stdio(false);cin.tie(0);
using namespace std;
//cerr<< '\n' << "Time elapsed :" << clock() * 1000.0 / CLOCKS_PER_SEC << " ms\n" ;
//freopen("explicit.in", "r", stdin);
//freopen("explicit.out", "w", stdout);
 
void SieveOfEratosthenes() 
{ 
    bool prime[10000001];
    memset(prime, true, sizeof(prime)); 
  
    for (ll p=2; p*p<=10000000; p++) 
    { 
        if (prime[p] == true) 
        { 
            // Update all multiples of p greater than or  
            // equal to the square of it 
            // numbers which are multiple of p and are 
            // less than p^2 are already been marked.  
            for (ll i=p*p; i<=10000000; i += p) {
                prime[i] = false; 
            }
        } 
    }  
} 
ll binpow(ll a, ll b) {
    ll res = 1;
    while (b > 0) {
        if (b & 1)
            res = (res * a);
        a = (a * a);
        b >>= 1;
    }
    return res;
}
ll gcd(ll a,ll b)
{
	if(b%a==0)
	   return a;
	return gcd(b%a,a);
}
ll power(ll x,ll y,ll p) 
{ 
    ll r = 1;
  
    x = x % p;
    while (y > 0) {
        if (y & 1) 
            r = (r * x) % p;
        y = y >> 1; 
        x = (x * x) % p; 
    } 
    return r; 
}  
ll modInverse(ll n, ll p) 
{ 
    return power(n, p - 2, p); 
} 
 
ll nCrModP(ll n,ll r, ll p) 
{ 
    ll fac[100005];
    if (r == 0) 
        return 1; 
  
    return (fac[n] * modInverse(fac[r], p) % p * modInverse(fac[n - r], p) % p) % p; 
}
int32_t main() 
{
    fio
	ll j,i,n,t,l,r,c,h,k,m,maxi,d,x;
	cin>>n;
	ll ans=0;
	ans=0;
	k=0;
	for(j=0;j<n;j++)
	{
		cin>>c>>d;
		if(c==d)
			ans++;
		else
			ans=0;
		if(ans==3)
			k=1;
	}
	if(k)
		cout<<"Yes";
	else
		cout<<"No";
}


	

		

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

int main(int argc, const char * argv[]) {
    // fasten cin
    cin.tie(0);
    ios::sync_with_stdio(false);
    // implement
    int64_t x;
    cin >> x;
    int64_t counter = 1;
    int64_t amount = 100;
    rep(i,1000000000000000007){
        amount *= 1.01;
        if(amount >= x){
            break;
        }
        counter++;
    }
    cout << counter << endl;
}

Measured memory_bytes: 3656
fn main() {
    let n:usize = read();
    let mut a:Vec<i64> = read_vec();
    let mut b:Vec<i64> = read_vec();

    let mut ans:i64 = 0;
    for i in 0..n {
        let k = std::cmp::min(a[i],b[i]);
        ans += k; a[i] -= k; b[i] -= k;
        let k = std::cmp::min(a[i+1],b[i]);
        ans += k; a[i+1] -= k;
    }

    println!("{}",ans);
}

fn get_line() -> String {
    let mut buf = String::new();
    std::io::stdin().read_line(&mut buf).ok();
    buf.trim().to_owned()
}

fn read<T: std::str::FromStr>() -> T{
    get_line().parse().ok().unwrap()
}

fn read_vec<T: std::str::FromStr>() -> Vec<T>{
    get_line().split_whitespace()
        .map(|e| e.parse().ok().unwrap()).collect()
}

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

int main(){
	int a = 1, b = 0, c = 0;
	char x, y, w;
	while(cin >> x >> w >> y){
		if(x == 'A' && y == 'B') swap(a, b);
		else if(x == 'A' && y == 'C') swap(a, c);
		else if(x == 'B' && y == 'A') swap(b, a);
		else if(x == 'B' && y == 'C') swap(b, c);
		else if(x == 'C' && y == 'A') swap(c, a);
		else if(x == 'C' && y == 'B') swap(c, b);
	}
	if(a == 1) cout << 'A' << endl;
	else if(b == 1) cout << 'B' << endl;
	else if(c == 1) cout << 'C' << endl;

}

Measured memory_bytes: 1132
import java.util.*;
public class Main{
	public static void main(String[] args){
		Scanner sc=new Scanner(System.in);
		int n,seq=1;
		double area;
		while(true){
			n=sc.nextInt();
			if(n!=0){
				area=0.0;
				int[] x=new int[n],y=new int[n];
				for(int i=0;i<n;i++){
					x[i]=sc.nextInt();
					y[i]=sc.nextInt();
				}
				for(int i=0;i<n-1;i++){
					area+=(y[i]*x[i+1]-x[i]*y[i+1]);
				}
				area+=(y[n-1]*x[0]-x[n-1]*y[0]);
				area/=2.0;
				System.out.printf("%d %.1f\n",seq++,area);
			}
			else{
				break;
			}
		}
	}
}


Measured memory_bytes: 29440
#include <cstring>
#include <regex>
#include <cstdio>
#include <algorithm>
#include <iostream>
#include <vector>
#include <map>
#include <unordered_map>
#include <cmath>
#include <queue>
#include <set>
#include <stack>

using namespace std;
typedef long long ll;
typedef pair<int, int> P;
#define rep(i, n) for(ll i = 0; i < (ll)(n); i++)
#define repr(i, n) for(ll i = n - 1; i >= 0; i--)
#define repone(i, n) for(ll i = 1; i <= (ll)(n); i++)
#define each(i, mp) for(auto i:mp)
#define FOR(i, m, n) for(ll i = m;i < n;i++)
const int dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};
const ll mod = 1000000007;
const ll inf = ll(1e9);
const ll half_inf = ll(1e5);
const ll ll_inf = ll(1e9) * ll(1e9);

int main() {
    string s;
    cin >> s;
    regex re1(".*keyence");
    regex re2("k.*eyence");
    regex re3("ke.*yence");
    regex re4("key.*ence");
    regex re5("keye.*nce");
    regex re6("keyen.*ce");
    regex re7("keyenc.*e");
    regex re8("keyence.*");

    regex re[8] = {re1, re2, re3, re4, re5, re6, re7, re8};
    rep(i, 8) if (regex_match(s, re[i])) {
            cout << "YES" << endl;
            return 0;
        }
    cout << "NO" << endl;
    return 0;
}

Measured memory_bytes: 256
#include <algorithm>
#include <cstdio>
#include <functional>
#include <iostream>
#include <cfloat>
#include <climits>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <map>
#include <unordered_map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <time.h>
#include <vector>
using namespace std;

long long N, M, dp[100090][40], mod = 1000000007;

long long inv[1<<20]; // ith index will store (1/i)%mod
long long finv[1<<20]; // ith index will store (1/i!)%mod
long long fact[1<<20]; // ith index will store (i!)%mod

map<long long, long long> ma;

void populate() {
    fact[0] = fact[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;

    for(int i = 2;i <= N;i++) {
        fact[i] = (i*fact[i-1])%mod;
        inv[i] = mod-((inv[mod%i]*(mod/i))%mod);
        finv[i] = (finv[i-1]*inv[i])%mod;
    }
}

void primeFactor(long long num) {
  for(long long i = 2;i * i <= num;i++) {
    if(num % i == 0) {
      ma[i]++;
      primeFactor(num/i);
      return;
    }
  }

  ma[num]++;
}

int main() {
  //freopen("input.in","r",stdin);
  //freopen("output.out","w",stdout);

  cin >> N >> M;
  if(M == 1) {
    cout << 1 << endl;
    return 0;
  }

  primeFactor(M);

  for(int i = 1;i <= N;i++) {
    for(int j = 0;j <= 30;j++) {
      if(i == 1 || j == 0) {
        dp[i][j] = 1;
      } else {
        dp[i][j] = (dp[i][j-1] + dp[i-1][j]) % mod;
      }
    }
  }

  long long ans = 1;
  for(auto it = ma.begin();it != ma.end();it++) {
    // cout << it->first << " " << it->second << endl;
    ans = (ans * dp[N][it->second]) % mod;
  }

  cout << ans << endl;

  return 0;
}

Measured memory_bytes: 31488
#include <iostream>
using namespace std;
int p[200000];
int main(int argc, const char * argv[])
{
    int n,k;
    int ans=0;
    cin>>n>>k;
    for(int i=0;i<n;i++)
        cin>>p[i];
    for(int i=0;i<k;i++)
        ans+=p[i];
    int t = ans;
    for(int i=k;i<n;i++)
    {
        t=t+p[i]-p[i-k];
        if(t>ans) ans=t;
            
    }
    cout.setf(ios::fixed);
    cout.precision(12);
    cout<<(ans+k)/2.0<<endl;
    return 0;
}

Measured memory_bytes: 1024
#include <stdio.h>

int main(){
	int a, b;
	while(1){
	scanf("%d %d", &a, &b);
		if(a == 0 && b == 0){
			break;
		}
		if(a < b){
			printf("%d %d\n", a, b);
		}
		else{
		printf("%d %d\n", b, a);
		}
	}
	return 0;
}

Measured memory_bytes: 600
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define fi first
#define se second
#define pb push_back
#define all(v) (v).begin(),(v).end()
ll mod = 1000000007;
ll INF = 1000000099;
signed main(){
    ll n,ans=1;
    cin>>n;
    vector<ll> v(n);
    
    if(n%2==0){
        for(int i=0;i < n;i++)
        {
            ll x;
            cin>>x;
            if(x%2==1){
                v.at(x)++;
            }else{
                cout<<0<<endl;
                return 0;
            }
        }

        for(int i=1;i < n;i+=2)
        {
            if(v.at(i)!=2){
                cout<<0<<endl;
                return 0;
            }else{
                ans*=2;
                ans%=mod;
            }
        }

    }else{
        for(int i=0;i < n;i++)
        {
            ll x;
            cin>>x;
            if(x%2==0){
                v.at(x)++;
            }else{
                cout<<0<<endl;
                return 0;
            }
        }

        for(int i=2;i < n;i+=2)
        {
            if(v.at(i)!=2){
                cout<<0<<endl;
                return 0;
            }else{
                ans*=2;
                ans%=mod;
            }
        }
        if(v.at(0)!=1){
            cout<<0<<endl;
            return 0;
        }
    }

    cout << ans << endl;
}


Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
#define  ft  ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define  ll  long long
#define  pi  pair<int,int>
#define  pb  push_back
#define  F   first
#define  S   second
#define  B   begin()
#define  E   end()
const int N=2e5+3;
//string s,p;
//vector<int>v;
//map<int,int>mp;

int main()
{
    ft
    int t,i,j,n,m,l,r,a[3];
    for(i=0;i<3;i++)
    {
        cin>>a[i];
    }
    sort(a,a+3);
    cout<<a[0]+a[1]<<"\n";
    return 0;
}



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

using namespace std;

//////////////////////////////////////////////////
class SegmentTree
{
public:
    typedef long long Int;
    static const Int INF = 1LL << 60; 
    vector<Int> data;
    Int N;

    SegmentTree(vector<Int> vec) {
        Int x = 1;
        while (x < (Int)vec.size()) {
            x *= 2;
        }
        this->N = x;
        data = vector<Int>(2 * x, INF);
        for (int i = 0; i < (Int)vec.size(); i++) {
            update(i, vec[i]);
        }
    }

    Int get(Int l, Int r) {
        return getSub(l, r, 0, N, 1);
    }

    void update(Int index, Int val) {
        Int v = index + N;
        data[v] = val;

        v /= 2;
        while (v > 0) {
            data[v] = min(data[2 * v], data[2 * v + 1]);
            v /= 2;
        }
    }

    Int getSub(Int l, Int r, Int myl, Int myr, Int v) {
        if (myr <= l || r <= myl) return INF;
        if (l <= myl && myr <= r) return data[v];

        Int mid = (myl + myr) / 2;
        return min(getSub(l, r, myl, mid, 2 * v),
                   getSub(l, r, mid, myr, 2 * v + 1));
    }
};
//////////////////////////////////////////////////

int main() {
    int n, q;
    cin >> n >> q;
    SegmentTree seg(vector<long long>(n, (1LL << 31) - 1));
    for (int i = 0; i < q; i++) {
        int c, x, y;
        cin >> c >> x >> y;
        if (c == 0) {
            seg.update(x, y);
        } else {
            cout << seg.get(x, y + 1) << endl;
        }
    }
    return 0;
}

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

int main(){
  int N,K,sum=0;
  cin >> N >> K;
  vector<int> L(N);
  for(int i=0;i<N;i++){
    cin >> L.at(i);
  }
  sort(L.begin(),L.end());
  reverse(L.begin(),L.end());
  for(int i=0;i<K;i++){
    sum+=L.at(i);
  }
  cout<< sum << endl;
}

Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace abc059_a
{
    class Program
    {
        static void Main(string[] args)
        {
            string[] input = Console.ReadLine().Split(' ');
            string s1 = input[0].ToUpper();
            string s2 = input[1].ToUpper();
            string s3 = input[2].ToUpper();
            Console.Write(s1[0]);
            Console.Write(s2[0]);
            Console.Write(s3[0]);
            Console.Read();
        }
    }
}


Measured memory_bytes: 11092
#include <bits/stdc++.h>
#define loop(n) for (int ngtkana_is_genius = 0; ngtkana_is_genius < int(n); ngtkana_is_genius++)
#define rep(i, begin, end) for(int i = int(begin); i < int(end); i++)
#define all(v) v.begin(), v.end()
#define rand(l, r) std::uniform_int_distribution<>(l, r)(mt)
using lint = long long;
auto mt = std::mt19937_64(std::random_device{}());
auto cmn = [](auto& a, auto b){if (a > b) {a = b; return true;} return false;};
auto cmx = [](auto& a, auto b){if (a < b) {a = b; return true;} return false;};
void debug_impl() { std::cerr << std::endl; }
template <typename Head, typename... Tail>
void debug_impl(Head head, Tail... tail){
  std::cerr << " " << head;
  debug_impl(tail...);
}
#ifdef STOPIT
#define debug(...) 0
#else
#define debug(...)\
do {\
  std::cerr << std::boolalpha << "[" << #__VA_ARGS__ << "]:";\
  debug_impl(__VA_ARGS__);\
  std::cerr << std::noboolalpha;\
} while (false)
#endif

int main() {
  std::cin.tie(0); std::cin.sync_with_stdio(false);
  int n; std::cin >> n;
  std::cout << n*n << std::endl;
  return 0;
}


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

int H, W, D;
const int MAX_HW = 300 + 100;
vector<pair<int, pair<int, int> > > A;
int Q;
const int MAX_Q = 1.0e5 + 100;
int L[MAX_Q], R[MAX_Q];


int main() {
    cin >> H >> W >> D;
    for (int i = 0; i < H; i++) {
        for (int j = 0; j < W; j++) {
            int A_in;
            cin >> A_in;
            A.push_back(make_pair(A_in - 1, make_pair(i, j)));
        }
    }
    cin >> Q;
    for (int i = 0; i < Q; i++) {
        int l_in, r_in;
        cin >> l_in >> r_in;
        L[i] = l_in - 1;
        R[i] = r_in - 1;
    }

    sort(begin(A), end(A));

    int mp[A.size()];
    for (int i = 0; i < A.size(); i++) {
        if (i < D) {
            mp[i] = 0;
        }
        else {
            pair<int, int> xy_old = A[i - D].second;
            pair<int, int> xy_new = A[i].second;
            mp[i] = mp[i - D] +abs(xy_new.first - xy_old.first) 
                + abs(xy_new.second - xy_old.second);
        }
    }

    for (int i = 0; i < Q; i++) {
        cout << mp[R[i]] - mp[L[i]] << endl;
    }

    return 0;
}


Measured memory_bytes: 3444
#include <stdio.h>
#include <string.h>
#include <math.h>
#include <stdlib.h>
#include <limits.h>
#include <stdbool.h>

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

//qsort(str, n, sizeof(int), up_comp);
int up_comp(const void *a, const void *b){return *(int*)a - *(int*)b;}
int down_comp(const void *a, const void *b){return *(int*)b - *(int*)a;}
int int_sort( const void * a , const void * b ) {return strcmp(( char * )a , ( char * )b );}
int count_digit(int a){int i=0;while(a!=0){a=a/10;i++;}return i;}
int euclid( int a, int b ){int temp;if(a<b){temp=a;a=b;b=temp;}if(b<1)return -1;if(a%b==0) return b;return euclid(b,a%b);}

int main(void){
    
    int d, t, s;
    
    scanf("%d%d%d", &d, &t, &s);
    
    if (t*s>=d) {
        printf("Yes");
    } else {
        printf("No");
    }
    
    return 0;
}


Measured memory_bytes: 1728
#include<stdio.h>
#include<algorithm>
#include<string.h>
#include<string>
#include<math.h>
#include<stdlib.h>
#include<time.h>
#include<map>
#include<queue>
#include<set>
#define fo(i,a,b) for(int i=a;i<=b;i++)
#define fd(i,a,b) for(int i=a;i>=b;i--)
using namespace std;
int n,m,x,y,be[110000],et,s[110000],st,a[110000],at;
bool vis[110000];
struct edg{
	int y,ne;
};
edg e[220000];
inline void add_edge(int x,int y){
	e[++et].y=y;
	e[et].ne=be[x];
	be[x]=et;
}
void dfs1(int x){
	s[++st]=x;
	vis[x]=1;
	int i=be[x];
	while (i){
		int &y=e[i].y;
		if (!vis[y]){
			dfs1(y);
			return;
		}
		i=e[i].ne;
	}
}
void dfs2(int x){
	a[++at]=x;
	vis[x]=1;
	int i=be[x];
	while (i){
		int &y=e[i].y;
		if (!vis[y]){
			dfs2(y);
			return;
		}
		i=e[i].ne;
	}	
}
int main(){
	scanf("%d%d",&n,&m);
	while (m--){
		scanf("%d%d",&x,&y);
		add_edge(x,y);
		add_edge(y,x);
	}
	vis[y]=1;//!!
	dfs1(x);
	dfs2(y);
	printf("%d\n",st+at);//!!!!!
	fd(i,at,1) printf("%d ",a[i]);
	fo(i,1,st) printf("%d ",s[i]);
	return 0;
}

Measured memory_bytes: 3072
using System;
using System.Collections.Generic;

namespace CompetitiveProgramming
{
    class Program
    {
        static void Main(string[] args)
        {
            int n = int.Parse(Console.ReadLine());
            //var price_list = new List<float>();
            //var kind_list = new List<string>();
            double sum = 0.0;


            for (var i = 0; i < n; i++)
            {
                string[] s = Console.ReadLine().Split(' ');
                if (s[1] == "JPY")
                {
                    sum += double.Parse(s[0]);
                }else{
                    sum += double.Parse(s[0])*380000.0;
                }
            }
            Console.WriteLine(sum);
        }
    }
}

Measured memory_bytes: 13140
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.Collections;
import java.util.StringTokenizer;

public class Main {

	public static void main(String[] args) {
		FastScanner fs=new FastScanner();
		int n=fs.nextInt();
		System.out.println((-n%1000+1000)%1000);
	}

	static void sort(int[] a) {
		ArrayList<Integer> l=new ArrayList<>();
		for (int i:a) l.add(i);
		Collections.sort(l);
		for (int i=0; i<a.length; i++) a[i]=l.get(i);
	}
	
	static class FastScanner {
		BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
		StringTokenizer st=new StringTokenizer("");
		String next() {
			while (!st.hasMoreTokens())
				try {
					st=new StringTokenizer(br.readLine());
				} catch (IOException e) {
					e.printStackTrace();
				}
			return st.nextToken();
		}
		
		int nextInt() {
			return Integer.parseInt(next());
		}
		int[] readArray(int n) {
			int[] a=new int[n];
			for (int i=0; i<n; i++) a[i]=nextInt();
			return a;
		}
		long nextLong() {
			return Long.parseLong(next());
		}
	}

	
}


Measured memory_bytes: 32760
//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
#define vec vector
#define fi first
#define se second
#define eb emplace_back
#define ef emplace_front
#define pof pop_front()
#define pob pop_back()
#define Rep(i,n) for(li i=0,nn=(li)(n);i!=nn;++i)
#define Rep1(i,n) for(li i=1,nn=(li)(n)+1;i!=nn;++i)
#define Size(v) (li)(v.size())
#define SortA(v) sort(v.begin(),v.end())
#define SortD(v) sort(v.rbegin(),v.rend())
#define All(a) (a).begin(),(a).end()
#define Input(a) for(li ii=0,nn=(li)(a.size());ii!=nn;++ii){cin>>(a).at(ii);}
#define Input2(a,b) for(li ii=0,nn=(li)(a.size());ii!=nn;++ii){cin>>(a).at(ii)>>(b).at(ii);}
#define mp make_pair
using li = int64_t;
using intl = int64_t;
using vi = vec<li>;
using vb = vec<bool>;
using vvi = vec<vi>;
using qi = deque<li>;
using pi = pair<li,li>;
using vpi = vec<pi>;
using si = set<li>;
using vsi = vec<si>;
using mii = map<li,li>;
using vmii = vec<mii>;
vec<li> dx = {0, 1, 0, -1, 1, 1, -1, -1};
vec<li> dy = {1, 0, -1, 0, 1, -1, 1, -1};
constexpr li INF = LLONG_MAX;

void Yes(li b){
  if(b)cout<<"Yes";
  else cout<<"No";
}
void yes(li b){
  if(b)cout<<"yes";
  else cout<<"no";
}

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

  li H,N;

  cin>>H>>N;

  vpi AM(N);

  Rep(i,N){
  	cin>>AM[i].fi>>AM[i].se;
  }

  SortA(AM);
  li maxA = AM[0].fi;

  vi dp(H,0);

  Rep(i,H){
  	li minM = INF;

  	for(auto am:AM){
  		if(i<am.fi){
  			minM=min(minM,am.se);
  		}
  		else{
  			minM=min(minM,dp[i-am.fi]+am.se);
  		}
  	}

  	dp[i]=minM;

  }

  cout<<dp[H-1];



  

}

Measured memory_bytes: 3752
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <memory.h>
#include <math.h>
#include <assert.h>
#include <queue>
#include <map>
#include <set>
#include <string>
#include <algorithm>
#include <iostream>
#include <functional>
#include <unordered_map>
#include <unordered_set>
#include <list>
#include <bitset>

using namespace std;
typedef pair<int, int> pii;
typedef long long ll;
#define Fi first
#define Se second
#define pb(x) push_back(x)
#define szz(x) ((int)(x).size())
#define rep(i, n) for(int i=0;i<n;i++)
#define all(x) (x).begin(), (x).end()
typedef tuple<int, int, int> t3;
typedef pair<ll, ll> pll;
typedef long double ldouble;
typedef pair<double, double> pdd;

char S[100010];

void solve() {
	scanf("%s", S+1);
	int n = (int)strlen(S+1);
	int ans = n;
	for(int i=2;i<=n;i++) if(S[i] != S[i-1]) {
		ans = min(ans, max(i-1, n-i+1));
	}
	printf("%d\n", ans);
}

int main(){
	int Tc = 1; // scanf("%d\n", &Tc);
	for(int tc=1;tc<=Tc;tc++){
		solve();
	}
	return 0;
}




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

using namespace std;

const int maxn=2*100005;
const int maxm=100005;

struct point{
	int x,y;
}a[maxn];

int ans[maxn];
int num[maxn];

bool cmp(point a,point b)
{
	return a.x<b.x;
}

int main()
{
	int n,m;
	scanf("%d%d",&n,&m);
	for(int i=1;i<=m;i++){
		scanf("%d%d",&a[i].x,&a[i].y);
	}
	sort(a+1,a+m+1,cmp);
	for(int i=1;i<=n;i++){
		ans[i]++;
	}
	for(int i=1;i<=m;i++){
		int t=ans[a[i].y];
		ans[a[i].y]+=ans[a[i].y+1]-num[a[i].y];
		ans[a[i].y+1]+=t-num[a[i].y];
		num[a[i].y]=ans[a[i].y];
	}
	for(int i=1;i<=n;i++){
		if(i!=n)
		printf("%d ",ans[i]);
		else printf("%d\n",ans[i]);
	}
	return 0;
}

Measured memory_bytes: 5600
#define _GIBCXX_DEBUG
#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 namespace std;
using ll = long long;
using P = pair<int, int>;


int main(void) {
  string s;
  cin >> s;

  if (s[0] == s[2]) {
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }
  
  return 0;
}

Measured memory_bytes: 3532
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define loop(i,a,b) for(ll i=a; i<b; i++)
#define revloop(i,a,b) for(ll i=a; i>=b; i--)
#define pb push_back
#define vl vector<ll>
#define vvl vector<vl>
#define pl pair<ll,ll>
#define vpl vector<pl>
#define all(c) (c).begin(), (c).end()
#define sz(a) ((a).size())
#define tr(c,i) for(typeof((c).begin() i = (c).begin(); i!=(c).end(); i++))
#define mp make_pair
#define ss second
#define ff first
const ll INF = 1e13;
const ll N = 200001;
const ll mod=998244353;
bool prime(ll x)
{
	if(x<2) return false;
	for(ll i=2; i*i<=x; i++) if(x%i==0) return false;
	return true;
}
vl fac(N);
void fact()
{
	fac[0]=1;
	loop(i,1,N) fac[i]=(fac[i-1]*i)%mod;
}
ll lcs(string s, string t, vvl& dp)
{
	loop(i,1,s.size()+1)
	{
		loop(j,1,t.size()+1)
		{
			if(s[i-1]==t[j-1]) dp[i][j] = 1 + dp[i-1][j-1];
			
			dp[i][j] = max(dp[i][j], max(dp[i][j-1], dp[i-1][j]));
		}
	}
	return dp[s.size()][t.size()];
}
void solve()
{
  string s,t;
  cin>>s>>t;
  vvl dp(s.size()+1, vl(t.size()+1,0));
  ll size = lcs(s,t,dp);
  string ans = "";
  ll i = s.size(), j = t.size();
  while(i>0 && j>0)
  {
  	if(dp[i-1][j-1]+1==dp[i][j] && dp[i-1][j]+1==dp[i][j] && dp[i][j-1]+1==dp[i][j])
  	{
  		i--; j--;
  		ans = s[i]+ans;
	}
	else if(dp[i][j-1]>dp[i-1][j]) j--;
	else i--;
  }
  cout<<ans;
}

int main()
{
	ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    ll t=1;
    //cin>>t;
    while(t--) solve();
 return 0;
}

Measured memory_bytes: 72320
#include <iostream>
#include <vector>
using namespace std;
#define rep(i,n) for(int i=0; i<n; i++)

int main()
{
  int n;
  cin >> n;
  if(n){
    cout << '0' << endl;
  }
  else{
    cout << '1' << endl;
  }
  return 0;
}

Measured memory_bytes: 3564
n,m,x=map(int, input().split())
a = [0] * m
ans = 100000000
c = []
p = []
cost=0

for i in range(n):
    tmp=list(map(int, input().split()))
    c.append(tmp)  

for i in range(2 ** n):
    for j in range(n):
        if i >> j & 1:
            cost += c[j][0]
            for k in range(m):
                a[k] = a[k] + c[j][k+1]
    if all((l >= x for l in a)):
        ans = min(ans,cost)
    #print(cost,a,ans)
    cost=0
    a = [0] * m

if ans == 100000000:
    print(-1)
else:
    print(ans)

Measured memory_bytes: 9240
#include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <complex>
#include <queue>
#include <map>
#include <set>
#include <cstring>
#include <cstdlib>
#include <string>
#include <cmath>
#include <bitset>
using namespace std;

#define REP(i,n) for(int i=0;i<(int)n;++i)
#define FOR(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)
#define ALL(c) (c).begin(), (c).end()
const int INF = 1<<29;


int n;
int dame;

int rec(int S, int num) {                // ツつサツづ個クツδ債ッツクツづタツスツクツづーツ始ツづ淞づァツづェツづ按つッツづェツづ篠ビツッツトツつェツ１
//  cout << bitset<7>(S) << " " << num << endl;
  if (num == 10) return n;
  int res = INF;
  for (int i=1;i<n;++i) {
    if (!(S >> i & 1)) {
      int tmp = S >> i;
      tmp |= dame;
      res = min(res, rec(tmp, num+1) + i);
    }
  }
  return res;
}

int main() {
  while(cin>>n,n) {
    int table[n];
    REP(i,5) {
      REP(j,n) {
        char c;
        cin >> c;
        if (c == 'X')
          table[j] = i; 
      }
    }
    dame = 0;
    for (int i=1; i<n; ++i) {
      REP(j, i) {
        if (table[i] == table[j]) {
          dame |= 1 << i-j;
        }
      }
    }
    cout << rec(dame,1) << endl;
  }
}

Measured memory_bytes: 0
#include <bits/stdc++.h>
#include <math.h>
#define REP(i, n) for(int i = 0; i < (n); i++)
#define ALL(v) (v).begin(), (v).end()
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
const int INF = 1001001001;
const int mINF = -1001001001;
// << fixed << setprecision(10) <<

int main() {
ll n;
cin >> n;
ll mi=9223372036854775807;
for(ll i=1;i<=sqrt(n);i++) {
  if(n%i==0) {
    mi=min(mi,(n/i)+i);
  }
}
cout << mi-2 << endl;
return 0;
}


Measured memory_bytes: 256
package main 
 
import (
  "fmt"
)
 

func main() {
  var n int
  fmt.Scan(&n)

  h := make([]int ,n)
  for i := 0; i < n; i++ {
    fmt.Scan(&h[i])
  }
  
  for i := 1; i < n; i++ {
    if h[i-1] < h[i] {
      h[i] -= 1
    }
    
    if h[i-1] > h[i] {
      fmt.Println("No")
      return
    }
  }
  fmt.Println("Yes")
}

Measured memory_bytes: 5504
using AtCoderBeginnerContest140.Questions;
using AtCoderBeginnerContest140.Extensions;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;

namespace AtCoderBeginnerContest140.Questions
{
    public class QuestionC : AtCoderQuestionBase
    {
        public override IEnumerable<object> Solve(TextReader inputStream)
        {
            int n = inputStream.ReadInt();
            var b = inputStream.ReadIntArray();

            var sum = b[0];
            for (int i = 1; i < b.Length; i++)
            {
                sum += Math.Min(b[i - 1], b[i]);
            }
            sum += b[b.Length - 1];

            yield return sum;
        }
    }
}


namespace AtCoderBeginnerContest140
{
    class Program
    {
        static void Main(string[] args)
        {
            IAtCoderQuestion question = new QuestionC();    // 問題に合わせて書き換え
            var answers = question.Solve(Console.In);
            foreach (var answer in answers)
            {
                Console.WriteLine(answer);
            }
        }
    }
}

#region Base Classes

namespace AtCoderBeginnerContest140.Questions
{

    public interface IAtCoderQuestion
    {
        IEnumerable<object> Solve(string input);
        IEnumerable<object> Solve(TextReader inputStream);
    }

    public abstract class AtCoderQuestionBase : IAtCoderQuestion
    {
        public IEnumerable<object> Solve(string input)
        {
            var stream = new MemoryStream(Encoding.Unicode.GetBytes(input));
            var reader = new StreamReader(stream, Encoding.Unicode);

            return Solve(reader);
        }

        public abstract IEnumerable<object> Solve(TextReader inputStream);
    }

}

#endregion

#region Extensions

namespace AtCoderBeginnerContest140.Extensions
{
    internal static class TextReaderExtensions
    {
        internal static int ReadInt(this TextReader reader) => int.Parse(ReadString(reader));
        internal static long ReadLong(this TextReader reader) => long.Parse(ReadString(reader));
        internal static double ReadDouble(this TextReader reader) => double.Parse(ReadString(reader));
        internal static string ReadString(this TextReader reader) => reader.ReadLine();

        internal static int[] ReadIntArray(this TextReader reader, char separator = ' ') => ReadStringArray(reader, separator).Select(int.Parse).ToArray();
        internal static long[] ReadLongArray(this TextReader reader, char separator = ' ') => ReadStringArray(reader, separator).Select(long.Parse).ToArray();
        internal static double[] ReadDoubleArray(this TextReader reader, char separator = ' ') => ReadStringArray(reader, separator).Select(double.Parse).ToArray();
        internal static string[] ReadStringArray(this TextReader reader, char separator = ' ') => reader.ReadLine().Split(separator);
    }
}

#endregion

Measured memory_bytes: 13396
#include <iostream>
#include <string>

using namespace std;

int main(){
	long long k = 1000000007;
	long long N;
	long long A[200001] = {0};
	long long sum = 0;
	long long s_tmp;
	long long tmp_sum = 0;

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

	for (int i = 1; i < N; i++) {
		tmp_sum += A[i];
	}
		// cout << "sum = " << sum << "\n";

	for (int i = 0; i < N-1; i++) {
		s_tmp = (A[i] * (tmp_sum%k));
		s_tmp = s_tmp % k;
		sum += s_tmp;
		sum = sum % k;
		tmp_sum -=A[i+1];
		// cout << "sum = " << sum << "\n";
		// cout << "tmp = " << tmp_sum << "\n";
	}
	cout << sum%k << "\n";
	return 0;
}

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

long long N;
string S;

long long solve()
{
    vector<long long> val(2019, 0);
    long long tenfactor = 1;
    long long cur = 0;
    val[cur]++;
    for (int i = 0; i < N; ++i)
    {
        cur = (cur + (S[N - i - 1] - '0') * tenfactor) % 2019;
        tenfactor = (tenfactor * 10) % 2019;
        val[cur]++;
    }
    long long res = 0;
    for (int p = 0; p < 2019; ++p)
        res += val[p] * (val[p] - 1) / 2;
    return res;
}

int main()
{
    cin >> S;
    N = S.size();
    cout << solve() << endl;
}

Measured memory_bytes: 3724
import sys

readline = sys.stdin.readline
MOD = 10 ** 9 + 7
INF = float('INF')
sys.setrecursionlimit(10 ** 5)


def main():
    N = int(readline())
    s = set()

    for i in range(1, 10):
        for j in range(1, 10):
            s.add(i * j)

    if N in s:
        print("Yes")
    else:
        print("No")


if __name__ == '__main__':
    main()


Measured memory_bytes: 61228
#include <stdio.h>
#include <cmath>
#include <algorithm>
#include <stack>
#include <queue>
#include <vector>
typedef long long int ll;

#define BIG_NUM 2000000000

using namespace std;

struct Info{
	Info(){
		h = 0;
		r = 0;
		used = false;
		may_in_num = in_num = 0;
	}
	int h,r,may_in_num,in_num;
	bool used;
};

void func(int n){

	Info info[401];
	int m;

	for(int i = 0; i < n; i++){
		scanf("%d %d",&info[i].h,&info[i].r);
	}

	scanf("%d",&m);

	for(int i = 0; i < m; i++){
		scanf("%d %d",&info[n+i].h,&info[n+i].r);
	}

	int count,maximum = 0,limit = n+m;

	while(true){
		count = 0;

		for(int i = 0; i < limit; i++){
			if(info[i].used)continue;
			for(int k = 0; k < limit; k++){
				if(info[k].used == false && info[k].h < info[i].h && info[k].r < info[i].r){
					info[i].may_in_num++;
				}
			}
		}

		for(int i = 0; i < limit; i++){
			if(info[i].may_in_num == 0){
				info[i].used = true;

				for(int k = 0; k < limit; k++){
					if(info[k].h > info[i].h && info[k].r > info[i].r){
						if(info[k].in_num < info[i].in_num+1){
							count++;
							info[k].in_num = info[i].in_num+1;
							maximum = max(maximum,info[k].in_num);
						}
					}
				}
			}
		}

		for(int i = 0; i < limit; i++){
			if(info[i].used == false){
				info[i].may_in_num = 0;
			}
		}

		if(count == 0)break;
	}

	printf("%d\n",maximum+1);

}

int main(){

	int n;

	while(true){
		scanf("%d",&n);
		if(n == 0)break;

		func(n);
	}

    return 0;
}

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

int main()
{
	int N;
	cin >> N;
	vector<int> A(N);
	vector<int> Target(N);
	for (int i = 0; i < N; i++)
	{
		cin >> A[i];
	}
	multiset<int> s;
	for (int i = 0; i < N; i++)
	{
		s.insert(A[i]);
	}
	std::sort(A.begin(), A.end());
	int nn = 1;
	for (int i = 0; i < N; i++)
	{
		if (nn <= A[i])
		{
			while (nn <= A[i])
			{
				nn *= 2;
			}
		}
		Target[i] = nn - A[i];
	}
	int cnt = 0;
	for (int i = N - 1; i >= 0; i--)
	{
		auto nItr = s.find(A[i]);
		if (nItr == s.end())continue;
		s.erase(nItr);
		auto tItr = s.find(Target[i]);
		if (tItr == s.end())continue;
		s.erase(tItr);
		cnt++;
	}
	cout << cnt << endl;
}

Measured memory_bytes: 11136
import numpy as np
n, k = map(int, input().split())
a = np.array(sorted(list(map(int, input().split()))))
f = np.array(sorted(list(map(int, input().split())), reverse=True))


def test(x):
    cost = np.maximum(0, a-x//f).sum()
    return cost <= k


left = -1
right = 10**12
while left+1 < right:
    mid = (left+right)//2
    if test(mid):
        right = mid
    else:
        left = mid

print(right)

Measured memory_bytes: 37272
N=int(input())
H=[int(x) for x in input().split()]

def dfs(l):
    if len(l)==1:
        return l[0]
    else:
        a=l.index(min(l))
        if a==0:
            return dfs(l[1:])
        elif a==len(l)-1:
            return dfs(l[:-1])
        else:
            return dfs(l[:a])+dfs(l[a+1:])-min(l)

print(dfs(H))

Measured memory_bytes: 3064
#include<stdio.h>
using namespace std;

int main(void)
{
	int N, X;
	int L[100];

	scanf("%d%d", &N, &X);
	for (int i = 1; i <= N; i++) {
		scanf("%d", &L[i]);
		//printf("%d\n", L[i]);
	}
	int count = 0;
	int sum = 0;
	for (int j = 0; j <= N; j++) {
		if (j == 0) {
			count++;
			sum += 0;
		}
		else {
			sum += L[j];
			//printf("%d\n", sum);
			count++;
			if (sum > X) {
				printf("%d", count - 1);
				return 0;
			}
		}
	}
	printf("%d", count);
	return 0;
	

}

Measured memory_bytes: 128
from sys import stdin


def main():
    S = stdin.readline().strip()
    T = stdin.readline().strip()
    lst = [""] * (ord("z") - ord("a") + 1)
    flg = True
    for s, t in zip(S, T):
        # 同アルファベット、違アルファベット変換チェック
        if lst[ord(s) - ord("a")] and lst[ord(s) - ord("a")] != t:
            flg = False
            break
        lst[ord(s) - ord("a")] = t
    lst = [i for i in lst if i != ""]
    # 変換先の重複チェック
    if len(lst) != len(set(lst)):
        flg = False
    print("Yes" if flg else "No")
    return


main()


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

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 ll = long long;

const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
const int INF = 1<<30;
const ll mod = 1000000007LL;

int main(){
  string s;
  cin>>s;
  bool can = false;
  for(int i = 0; i < 3; i++){
    if(s[i]=='7') {can = true; break;}
  }
  if(!can)cout<<"No"<<endl;
  else cout<<"Yes"<<endl;
}

Measured memory_bytes: 3588
#include <bits/stdc++.h>
using namespace std;
 
int main(){
	int n;long long k;
	scanf("%d%lld",&n,&k);
	int arr;
	vector<long long> neg,pos;
	for(int i=0;i<n;i++){
		scanf("%d",&arr);
		if(arr<0)neg.push_back(arr);
		else if(arr>0)pos.push_back(arr);
	}
	//find the smallest number such that there are >=k products less than it
	sort(neg.begin(),neg.end());
	sort(pos.begin(),pos.end());
	long long l=neg.size(),r=pos.size();
	long long zeros=n-l-r;
	if(l*r>=k){
		l=0;r=2012345678012345678;
		for(int i=0;i<(int)neg.size();i++)neg[i]*=-1;
		reverse(neg.begin(),neg.end());
		//find the largest number such that there are >=k products >= than it
		while(l<r){
			long long mid=(l+r+1)/2;
			int ptr=0;
			long long count=0;
			for(int i=(int)neg.size()-1;i>=0;i--){
				while(ptr<(int)pos.size()&&neg[i]*pos[ptr]<mid)ptr++;
				count+=(int)pos.size()-ptr;
			}
			//printf("%lld %lld\n",l,r);
			if(k>count)r=mid-1;
			else l=mid;
		}
		printf("%lld",-l);
	}else if((zeros)*(l+r)+(zeros)*(zeros-1)/2>=k-l*r){
		printf("0");
	}else{
		k-=l*r;
		k-=((zeros)*(l+r)+(zeros)*(zeros-1)/2);
		reverse(neg.begin(),neg.end());
		//find the smallest number such that there are >=k products <= it
		//printf("%lld\n",k);
		l=0;r=2012345678012345678;
		while(l<r){
			long long mid=(l+r)/2;
			int ptr=(int)pos.size()-1;
			long long count=0;
			for(int i=0;i<(int)pos.size();i++){
				while(ptr>=0&&pos[i]*pos[ptr]>mid)ptr--;
				count+=min(ptr+1,i);
			}
			ptr=(int)neg.size()-1;
			for(int i=0;i<(int)neg.size();i++){
				while(ptr>=0&&neg[i]*neg[ptr]>mid)ptr--;
				count+=min(ptr+1,i);
			}
			//printf("%lld %lld %lld\n",l,r,count);
			if(k>count)l=mid+1;
			else r=mid;
		}
		printf("%lld",l);
	}
}

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

int main() {
    string S;
    cin >> S;
    string s1 = S.substr(0, 2);
    string s2 = S.substr(2, 2);
    int n1 = stoi(s1);
    int n2 = stoi(s2);

    if (n1 >= 1 && n1 <= 12 && n2 >= 1 && n2 <= 12) {
        cout << "AMBIGUOUS" << endl;
    } else if (n1 >= 1 && n1 <= 12) {
        cout << "MMYY" << endl;
    } else if (n2 >= 1 && n2 <= 12) {
        cout << "YYMM" << endl;
    } else {
        cout << "NA" << endl;
    }

    return 0;
}

Measured memory_bytes: 256