akhauriyash/Code-Regression huggingface dataset:
import sys
input = sys.stdin.readline

n = int(input())
s = list(input())
res = 10**9

cta = 0
ctb = 0
a = [0]*n
b = [0]*n
for i in range(n):
    if s[i] == '.':
        cta += 1
    else:
        ctb += 1
    a[i] = cta
    b[i] = ctb
for i in range(n):
    res = min(res,b[i]+a[-1]-a[i])
res = min(res,a[-1],b[-1])
print(res)

Measured memory_bytes: 14180
#include<bits/stdc++.h>
using namespace std;
int main(){
    int h,n,x=0;
    cin>>h>>n;
    int a[n];
    for(int i=0;i<n;i++){
        cin>>a[i];
        x+=a[i];
    }
    if(x>=h)cout<<"Yes"<<endl;
    else cout<<"No"<<endl;
    return 0;
}

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

int main(){
    int K;
    int A, B;
    std::cin >> K;
    std::cin >> A >> B;

    for(int i=A; i<=B; i++){
        if(i % K == 0){
            std::cout << "OK" << std::endl;
            break;
        }
        else if(i == B){
            std::cout << "NG" << std::endl;
        }
    }

}

Measured memory_bytes: 3624
#include<stdio.h>



int main()
{
	int times ;

	int rock ,person ;


	scanf( "%d" ,&times ) ;


	while( times-- )
	{
		scanf( "%d %d" ,&rock ,&person ) ;


		rock = rock % person ;


		printf( "%d\n" ,rock > 0 ? rock : person ) ;
	}



	return 0 ;
}

Measured memory_bytes: 596
#include<stdio.h>
#include<stdlib.h>

struct node{
  struct node *right;
  struct node *left;
  struct node *parent;
  int key;
};
typedef struct node * Node;
#define NIL NULL

Node root;

Node treeMinimum(Node x){
  while(x->left!=NIL)
    {
      x=x->left;
    }
  return x;
}

Node treeMaximum(Node x){
  while(x->right!=NIL)
    {
      x=x->right;
    }
  return x;
}

Node treeSearch(Node u, int k){
  if(u==NIL || k==u->key)
    {
      return u;
    }
  if(k<u->key)
    {
      return treeSearch(u->left,k);
    }
  else
    {
      return treeSearch(u->right,k);
    }
}

Node treeSuccessor(Node x){
  Node y;
  if(x->right!=NIL)
    {
      return treeMaximum(x->right);
    }
  y=x->parent;
  while(y!=NIL && x==y->right)
    {
      x=y;
      y=y->parent;
      return y;
    }
}

void treeDelete(Node z){
  Node y; // node to be deleted
  Node x; // child of y
  if(z->left==NIL || z->right==NIL)
    {
      y=z;
    }
  else
    {
      y=treeSuccessor(z);
    }
  if(y->left!=NIL)
    {
      x=y->left;
    }
  if(x!=NIL)
    {
      x->parent=y->parent;
    }
  if(y->parent==NIL)
    {
      root=x;
    }
  else if(y==y->parent->left)
    {
      y->parent->left=x;
    }
  else
    {
      y->parent->right=x;
    }
  if(y!=z)
    {
      z->key=y->key;
    }

}

void insert(int k){
  Node y = NIL;
  Node x = root;
  Node z;

  z = malloc(sizeof(struct node));
  z->key = k;
  z->left = NIL;
  z->right = NIL;

  while(x!=NIL)
    {
      y=x;
      if(z->key < x->key)
        {
          x=x->left;
        }
      else
        {
          x=x->right;
        }
    }
  z->parent=y;
  if(y==NIL)
    {
      root=z;
    }
  else if(z->key < y->key)
    {
      y->left=z;
    }
  else
    {
      y->right=z;
    }
}




void inorder(Node u){
  if(u->left!=NIL)
      inorder(u->left);
      printf(" %d",u->key);
      if(u->right!=NIL)
      inorder(u->right);
    }
void preorder(Node u){
      printf(" %d",u->key);
      if(u->left!=NIL)
      preorder(u->left);
      if(u->right!=NIL)
      preorder(u->right);
    
}


int main(){
  int n, i, x;
  char com[20];
  scanf("%d", &n);

  for ( i = 0; i < n; i++ ){
    scanf("%s", com);
    if ( com[0] == 'f' ){
      scanf("%d", &x);
      Node t = treeSearch(root, x);
      if ( t != NIL ) printf("yes\n");
      else printf("no\n");
    } else if ( com[0] == 'i' ){
      scanf("%d", &x);
      insert(x);
    } else if ( com[0] == 'p' ){
      inorder(root);
      printf("\n");
      preorder(root);
      printf("\n");
    } else if ( com[0] == 'd' ){
      scanf("%d", &x);
      treeDelete(treeSearch(root, x));
    }
  }

  return 0;
}



Measured memory_bytes: 20484
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.Map;
import java.util.TreeMap;

public class Main {
	public static void main(String[] args) throws Exception {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		int n = Integer.parseInt(br.readLine());
		int[] a = new int[n];
		for (int i = 0; i < n; i++) {
			a[i] = Integer.parseInt(br.readLine());
		}
		br.close();

		TreeMap<Integer, Integer> map = new TreeMap<>();
		for (int i = 0; i < n; i++) {
			Integer l = map.lowerKey(a[i]);
			putCntMap(map, a[i]);
			removeCntMap(map, l);
		}

		int ans = 0;
		for (Integer k : map.keySet()) {
			ans += map.get(k);
		}
		System.out.println(ans);
	}

	static void putCntMap(Map<Integer, Integer> map, Integer key) {
		if (map.containsKey(key)) {
			map.put(key, map.get(key) + 1);
		} else {
			map.put(key, 1);
		}
	}

	static void removeCntMap(Map<Integer, Integer> map, Integer key) {
		if (key != null && map.containsKey(key)) {
			int val = map.get(key);
			if (val == 1) {
				map.remove(key);
			} else {
				map.put(key, val - 1);
			}
		}
	}
}


Measured memory_bytes: 39224
import java.util.Scanner;
import java.util.*;
public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        String s = sc.next();
        int cnt1 = 0;
        int cnt0 = 0;
        for (int i = 0; i < s.length(); i++) {
            if (s.charAt(i) == '1') {
                cnt1++;
            } else {
                cnt0++;
            }
        }
        int ans = 2 * Math.min(cnt1, cnt0);
        System.out.println(ans);
    }
}


Measured memory_bytes: 24216
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <math.h>
using namespace std;
using std::swap;
// priceをキーに降順でソート
//sort(fruits.begin(), fruits.end(),
//     [](const fruit& x, const fruit& y) { return x.price > y.price;});

/*
int main() {
    int A,B;
    std:cin >> A >> B;
    if((A+B)%2==1){
        std::cout << "IMPOSSIBLE" <<std::endl;
    }
    else{
        std::cout << (A+B)/2 << std::endl;
    }
    return 0;
}
 */

int main(){
    int N;
    std::cin >> N;
    int a[N];
    int flg=0;
    for(int i=0; i<N; i++){
        std::cin >> a[i];
    }
    for(int i=0; i<N; i++){
        if(a[i]!=i+1){
            flg++;
        }

        if(flg==3){
            std::cout << "NO" << std::endl;
            return 0;
        }
    }
    std::cout << "YES" << std::endl;
    return 0;
}


Measured memory_bytes: 256
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cmath>
#include <ctime>
#include <cstring>
#include <functional>
#include <iostream>
#include <iomanip>
#include <limits>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <regex>
#include <vector>

#define fix(n)          cout<<fixed<<setprecision(n)
#define rep(i,n)        for (int i = 0; i < (n); ++i)
#define sort(a)         sort((a).begin(), (a).end())
#define uniq(a)         sort(a);(a).erase(unique((a).begin(), (a).end()), (a).end())
#define reverse(a)      reverse((a).begin(), (a).end())
#define ctos(c)         string(1, (c))
#define out(d)          cout << (d)
#define outl(d)         std::cout<<(d)<<"\n"
#define YES()           cout << "YES" << endl
#define NO()            cout << "NO" << endl
#define Yes()           cout << "Yes" << endl
#define No()            cout << "No" << endl
#define ceil(x, y)      ((x + y - 1) / (y))
#define debug(x)        cerr << #x << ": " << (x) << '\n'
#define debug2(x, y)    cerr << #x << ": " << (x) << ", " << #y << ": " << (y) << '\n'
#define debug3(x, y, z) cerr << #x << ": " << (x) << ", " << #y << ": " << (y) << ", " << #z << ": " << (z) << '\n'
#define dbg(v)          for (size_t _ = 0; _ < v.size(); ++_){ cerr << #v << "[" << _ << "] : " << v[_] << '\n'; }

using namespace std;
using ll = long long;
using ld = long double;
using P = pair<ll,ll>;

const ll MOD = 1000000007; // 10^9 + 7
const int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
const int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};

void solve() {
  int n; cin >> n;
  set<int> set;
  for (int i = 0; 4 * i <= n; i++) {
    for (int j = 0; 4 * i + 7 * j <= n; j++) {
      set.insert(4 * i + 7 * j);
    }
  }
  if (set.find(n) == set.end()) No();
  else Yes();
}

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  srand((unsigned)time(NULL));
  fix(12);

  solve();
}


Measured memory_bytes: 256
#include <algorithm>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <vector>

using namespace std;

typedef long long ll;
typedef pair < int,int> pii;
typedef pair < double,double> pt;

const int N = 1e5 + 500;
const int M = 1e6 + 500;
const int INF = 0x3f3f3f3f;
const int MOD = 1e9 + 7;

int guess(int x){
    string y;
    cout << x << endl;
    cin >> y;
    if(y == "Male") return 0;
    if(y == "Female") return 1;
    return 2;
}

void bin(int lo,int hi,int x1){
    int mid = (lo + hi) / 2;
    int res = guess(mid);
    int ol = res;
    if(res == 2) return;
    res ^= (( mid - lo) & 1) ^ x1;
    if(res )
        bin(lo, mid, x1);
    else
        bin(mid, hi, ol);
}

int main(){
    ios_base::sync_with_stdio(false);
    int st,n;
    scanf("%d",&n);
    st = guess(0);
    bin(0, n, st);
}


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

using namespace std;

int main() {
  int N, Y;
  bool ans = false;
  
  cin >> N >> Y;
  
  int a = Y / 1000;
  
  for (int i = 0; i <= N; i++) {
    for (int j = 0; j <= N - i; j++) {
      int k = N - i - j;
      
      if (i + 5 * j + 10 * k == a) {
        cout << k << " " << j << " " << i << endl;
        
        return 0;
      }
    }
  }
  
  cout << "-1 -1 -1" << endl;
  
  return 0;
}

Measured memory_bytes: 3632
#include <iostream>
#include <string>
#include <vector>
#include <set>
#include <algorithm>
#include <cctype>
#include <cmath>
#include <queue>
#include <map>
#include <numeric>
#include <unordered_map>
#include <iomanip>
#include <functional>
#include <bitset>
#include <complex>
#include <stack>



#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define repi(i,a,b) for(int i=int(a);i<int(b);i++)
#define all(x) (x).begin(),(x).end()

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; }

typedef long long ll;

using namespace std;


int main()
{
  ios::sync_with_stdio(false);
  cin.tie(0);
  vector<int>f(100);
  string s;
  cin>>s;
  for(char c:s)
  {
    int i=c-'a';
    f[i]=1;
  }
  rep(i,26)
  {
    if(f[i]==0){cout<<(char)('a'+i)<<endl;return 0;}
  }
  cout<<"None"<<endl;

  return 0;

}


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

#define MAX_N 100000

using namespace std;

int main()
{
    int n, ans;

    scanf("%d", &n);

    vector<int> a(n);
    for (int i = 0; i <= n - 1; i++)
    {
        scanf("%d", &(a[i]));
    }

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

    for (int i = 0; i < n - 1; i++)
    {
        if(a[i] * 2 > a[n - 1])
        {
            ans = a[i] - a[n - 1] / 2 > a[n - 1] / 2 - a[i - 1] ? a[i - 1] : a[i];
            break;
        }
        
        if(i == n - 2)
        ans = a[i];
    }

    printf("%d %d\n", a[n - 1], ans);

    return 0;
}


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

#define file freopen("input.txt", "r", stdin);// freopen("output.txt", "w", stdout)
#define fast ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0)
#define pi 3.141592653589793238462643383279;
#define int long long
using namespace std;
const int MOD = 1e9 + 7;

signed main(){
    //file;
    fast;
    int n, q = 0;
    cin >> n;
    vector <int> b(n + 1);
    vector <int> ans;
    for(int i = 1; i <= n; i++){
    	cin >> b[i];
    }
    for(int i = 1; i <= n; i++){
    	if(b[i] > i){
    		cout << -1;
    		return 0;
    	}
    }
    while(b.size() > 1){
    	for(int i = b.size() - 1; i >= 1; i--){
    		if(b[i] == i){
    			b.erase(b.begin() + i);
    			ans.push_back(i);
    			break;
    		}
    	}
    }
    for(int i = ans.size() - 1; i >= 0; i--){
    	cout << ans[i] << endl;
    }
    return 0;
}


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

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

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

  while(true) {
    a.erase(unique(a.begin(), a.end()), a.end());

    int min = a[0];
    for (int i=1; i<a.size(); i++) {
      int temp = a[i] % min;
      if (temp == 0) {
        a.erase(a.begin() + i);
      } else {
        a[i] = temp;
      }
    }

    if (a.size() == 1) {
      cout << min << endl;
      break;
    } else {
      sort(a.begin(), a.end());;
    }
  }

  return 0;
}


Measured memory_bytes: 640
S = sorted(list(set(input())))
ABC = [chr(i) for i in range(97, 123)]
S_box = ["F" for i in range(26)]
ans = "None"
for i in range(26):
    for j in range(len(S)):
        if S[j] == ABC[i]:
            S_box[i] = ABC[i]
if len(S) == 26:
    pass
else:
    for i in range(26):
        if S_box[i] == "F":
            ans = ABC[i]
            break            
print(ans)

Measured memory_bytes: 66336
#include<bits/stdc++.h>
using namespace std;
int main(){
    int n;
    cin >> n;
    int h[n];
    for(int i=0;i<n;i++)cin >> h[i];
    vector<int>dp(n,1<<30);
    dp[0] = 0;
    for(int i=0;i<n;i++){
        if(i+1<n)dp[i+1] = min(dp[i+1],dp[i] + abs(h[i+1]-h[i]));
        if(i+2<n)dp[i+2] = min(dp[i+2],dp[i]+abs(h[i+2]-h[i])); 
    }
    cout << dp[n-1] << endl;
}


Measured memory_bytes: 1024
import std.algorithm;
import std.array;
import std.container;
import std.conv;
import std.math;
import std.numeric;
import std.range;
import std.stdio;
import std.string;
import std.typecons;

void scan(T...)(ref T a) {
    string[] ss = readln.split;
    foreach (i, t; T) a[i] = ss[i].to!t;
}
T read(T)() { return readln.chomp.to!T; }
T[] reads(T)() { return readln.split.to!(T[]); }
alias readint = read!int;
alias readints = reads!int;

const MOD = 10^^9 + 7;

int[int] fac(int n) {
    assert(n > 1);

    int[int] ps;
    while (n % 2 == 0) {
        ps[2]++;
        n /= 2;
    }
    for (int i = 3; i * i <= n; i += 2) {
        while (n % i == 0) {
            ps[i]++;
            n /= i;
        }
    }
    if (n > 1) ps[n]++;
    return ps;
}

long calc(int n, int m) {
    if (m == 1) return 1;
//    if (n == 1) return 1;

//    import std.exception;
//    enforce(n > 1);

    long ans = 1;
    foreach (v; fac(m).values) {
        // v 個の素因数と n - 1 個の仕切りの並べ方
        ans = (ans * nck(v + n - 1, n - 1)) % MOD;
    }
    return ans;
}

void main() {
    initFactTable(210000);

    int n, m; scan(n, m);
    writeln(calc(n, m));
}

long[] fact; // 階乗
long[] factInv; // 階乗の逆元

void initFactTable(int n) {
    fact = new long[n + 1];
    fact[0] = 1;
    for (int i = 1; i <= n; i++)
        fact[i] = i * fact[i - 1] % MOD;

    factInv = new long[n + 1];
    factInv[n] = modPow(fact[n], MOD - 2, MOD);
    for (int i = n - 1; i >= 0; i--)
        factInv[i] = factInv[i + 1] * (i + 1) % MOD;
}

long modPow(long x, long k, long m) {
    if (k == 0) return 1;
    if (k % 2 == 0) return modPow(x * x % m, k / 2, m);
    return x * modPow(x, k - 1, m) % m;
}

long nck(int n, int k) {
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return (fact[n] * factInv[k] % MOD) * factInv[n - k] % MOD;
}


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

typedef long long ll;
const ll INF = 1010000000000000017LL;
const ll MOD = 1000000007LL;

#define REP(i, n) for(ll i = 0 ; i < n; i++)

//#define DEBUG(fmt, ...)
#define DEBUG(fmt, ...) fprintf(stderr, fmt "\n", ##__VA_ARGS__)

int main(){
    std::cout<<std::fixed<<std::setprecision(10);

    ll N, M;
    cin >> N >> M;

    set<ll> a;
    REP(i,M){
       ll b;
       cin >> b;
       a.insert(b);
    }

    vector<ll> ans(N+1);
    ans[0] = 1;

    for(int i = 1; i < N+1; i++ ){
       if( a.find(i) != a.end() ){
          ans[i] = 0;
       }else{
          if( i > 1 ){
             ans[i] = ans[i-1]+ans[i-2];
          }else{
             ans[i] = ans[i-1];
          }
       }
       ans[i] = ans[i]%MOD;
    }

    cout << ans[N] << endl;

}


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

int main(){
  int s;
  cin >> s;
  vector<int> a(1000009);
  a[1]=s;
  for(int i=2;i<=1000000;i++){
    if(a[i-1]%2==0){a[i]=a[i-1]/2;}
    else{a[i]=3*a[i-1]+1;}
  }
  int ans;
  for(int i=1;i<=1000000;i++){
    for(int j=1;j<i;j++){
      if(a[i]==a[j]){ans=i; goto abc;}
    }
  }
  abc:
  cout << ans << endl;
}

Measured memory_bytes: 4096
//#line 2 "SubstringQueries.cpp"

#define _CRT_SECURE_NO_WARNINGS

#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cfloat>
#include <cstring>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <memory>
#include <string>
#include <vector>
#include <list>
#include <random>
#include <algorithm>
#include <functional>
#include <sstream>
#include <complex>
#include <stack>
#include <queue>
#include <unordered_set>
#include <unordered_map>
#include <array>
#include <cassert>
#include <bitset>
#include <cstdint>
using namespace std;
using LL = long long;

int N;
vector<int>G[123456];
vector<int>child[123456];
int memo1[123456];
int dp1(int v, int las) {
	int res = 0;
	for (int ch : G[v]) {
		if (las == ch)continue;
		child[v].push_back(ch);
		res = max(res, dp1(ch, v) + 1);
	}
	return memo1[v] = res;
}
int memo2[123456];
int dp2(int v, int d) {
	vector<pair<int, int>>rank;
	rank.push_back({ d,-1 });
	for (int ch : child[v]) {
		rank.push_back({ memo1[ch] + 1 ,ch });
	}
	sort(rank.rbegin(), rank.rend());
	for (int ch : child[v]) {
		if (rank[0].second == ch) {
			dp2(ch, rank[1].first + 1);
		}
		else {
			dp2(ch, rank[0].first + 1);
		}
	}
	return memo2[v] = d;
}

int main() {
	cin >> N;
	if (N == 1) {
		cout << 1 << endl;
		return 0;
	}
	if (N == 2) {
		cout << 11 << endl;
		return 0;
	}
	for (int i = 1; i < N; ++i) {
		int a, b;
		cin >> a >> b;
		a--; b--;
		G[a].push_back(b);
		G[b].push_back(a);
	}
	dp1(0, -1);
	dp2(0, 0);
	int big = 0;
	for (int i = 0; i < N; ++i) {
		vector<int>rank;
		for (int v : child[i]) {
			rank.push_back(memo1[v] + 1);
		}
		if (i != 0) {
			rank.push_back(memo2[i]);
		}
		sort(rank.rbegin(), rank.rend());
		if (rank.size() >= 3) {
			int opt = rank[0] + rank[2] - (rank[0] == rank[2] ? 1 : 0);
			big = max(big, opt);
		}
	}
	for (int i = 1; i <= N; ++i) {
		if (i <= 2) {
			cout << 1;
		}
		else {
			if (big >= i) {
				cout << 0;
			}
			else {
				cout << 1;
			}
		}
	}
	cout << endl;
	return 0;
}


Measured memory_bytes: 33120
#include <cstdio>

using namespace std;

int main() {
	int max = -1;
	int min = 1001;
	int tmp;
	int n;


	scanf("%d", &n);
	for (int i = 0; i < n; i++) {
		scanf("%d", &tmp);
		if (tmp < min) {
			min = tmp;
		}
		if (tmp > max) {
			max = tmp;
		}
	}
	printf("%d\n", max - min);

}

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

#undef _P
#define _P(...) (void)printf(__VA_ARGS__)
#define FOR(x,to) for(x=0;x<(to);x++)
#define FORR(x,arr) for(auto& x:arr)
#define ITR(x,c) for(__typeof(c.begin()) x=c.begin();x!=c.end();x++)
#define ALL(a) (a.begin()),(a.end())
#define ZERO(a) memset(a,0,sizeof(a))
#define MINUS(a) memset(a,0xff,sizeof(a))
//-------------------------------------------------------


int N;
ll A[202020],P[202020],B[202020];
const ll mo=200003;

typedef complex<long double> Comp;

vector<Comp> fft(vector<Comp> v, bool rev=false) {
	int n=v.size(),i,j,m;
	
	for(i=0,j=1;j<n-1;j++) {
		for(int k=n>>1;k>(i^=k);k>>=1);
		if(i>j) swap(v[i],v[j]);
	}
	for(int m=2; m<=n; m*=2) {
		long double deg=(rev?-1:1) * 2*acos(-1)/m;
		Comp wr(cos(deg),sin(deg));
		for(i=0;i<n;i+=m) {
			Comp w(1,0);
			for(int j1=i,j2=i+m/2;j2<i+m;j1++,j2++) {
				Comp t1=v[j1],t2=w*v[j2];
				v[j1]=t1+t2, v[j2]=t1-t2;
				w*=wr;
			}
		}
	}
	if(rev) FOR(i,n) v[i]*=(long double)1.0/n;
	return v;
}

vector<Comp> MultPoly(vector<Comp> P,vector<Comp> Q,bool resize=false) {
	if(resize) {
		int maxind=0,pi=0,qi=0,i;
		int s=2;
		FOR(i,P.size()) if(norm(P[i])) pi=i;
		FOR(i,Q.size()) if(norm(Q[i])) qi=i;
		maxind=pi+qi+1;
		while(s*2<maxind) s*=2;
		P.resize(s*2);Q.resize(s*2);
	}
	P=fft(P), Q=fft(Q);
	for(int i=0;i<P.size();i++) P[i]*=Q[i];
	return fft(P,true);
}


void solve() {
	int i,j,k,l,r,x,y; string s;
	
	ll cur=1;
	FOR(i,mo-1) {
		A[cur]=i;
		P[i]=cur;
		cur=cur*2%mo;
	}
	
	vector<Comp> X(1<<19);
	ll ret=0;
	cin>>N;
	FOR(i,N) {
		cin>>x;
		B[i]=x;
		if(x) {
			X[A[x]]+=1;
			//cout<<x<<" "<<1LL*x*x%mo<<" "<<A[x]<<endl;
		}
		ret-=B[i]*B[i]%mo;
	}
	
	auto Y=MultPoly(X,X,true);
	//cout<<ret<<endl;
	FOR(i,Y.size()) {
		ll a=floor(Y[i].real()+0.3);
		ret+=a*P[i%(mo-1)];
	}
	
	cout<<ret/2<<endl;
	
	
}


int main(int argc,char** argv){
	string s;int i;
	if(argc==1) ios::sync_with_stdio(false), cin.tie(0);
	FOR(i,argc-1) s+=argv[i+1],s+='\n'; FOR(i,s.size()) ungetc(s[s.size()-1-i],stdin);
	cout.tie(0); solve(); return 0;
}


Measured memory_bytes: 73952
#include <bits/stdc++.h>
using namespace std;
string S;
int K;
int main()
{
	cin>>S>>K;
	vector<string>vec;
	for (int i=0;i<S.size();i++)
	{
		for (int j=i;j<min((int)S.size(),i+6);j++) vec.push_back(S.substr(i,j-i+1));
	}
	sort(vec.begin(),vec.end());
	vec.erase(unique(vec.begin(),vec.end()),vec.end());
	cout<<vec[K-1]<<endl;
	return 0;
}

Measured memory_bytes: 1916
#

import sys
from collections import deque
input=sys.stdin.readline

def main():
    H,W,K=map(int,input().split())
    x1,y1,x2,y2=map(int,input().split())
    x1-=1
    y1-=1
    x2-=1
    y2-=1
    mas=[list(input()) for i in range(H)]

    dist=[[-1]*W for i in range(H)]
    dist[x1][y1]=0
    
    qu=deque([(x1,y1)])
    qup=qu.popleft
    qua=qu.append
    
    d=((-1,0),(1,0),(0,-1),(0,1))
    
    while(len(qu)>0):
        v=qup()
        for di in d:
            for i in range(1,K+1):
                nvh=v[0]+i*di[0]
                nvw=v[1]+i*di[1]
                if nvh<0 or nvh>=H or nvw<0 or nvw>=W or mas[nvh][nvw]=="@":
                    break
                if dist[nvh][nvw]!=-1 and dist[nvh][nvw]<=dist[v[0]][v[1]]:
                    break
                if dist[nvh][nvw]==-1:
                    dist[nvh][nvw]=dist[v[0]][v[1]]+1
                    qua((nvh,nvw))
    print(dist[x2][y2])
    
if __name__=="__main__":
    main()

Measured memory_bytes: 44556
N, Y = map(int, input().split())

res = "{} {} {}"
def calc(N, Y):
    tmp = 0
    for i in range(N+1):
        for k in range(N+1-i):
            w = N-i-k
            tmp = i * 10000 + k * 5000 + w * 1000
            if tmp == Y:
                return res.format(i, k, w)
    return res.format(-1, -1, -1)

print(calc(N,Y))

Measured memory_bytes: 3188
#include "bits/stdc++.h"
#define rep(i,n) for(int i = 0; i < (n); ++i)
using namespace std;
typedef long long int ll;
typedef pair<ll, ll> P;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

ll gcd(ll a, ll b) {
    if (b == 0) return a;
    return gcd(b, a % b);
}

ll lcm(ll a, ll b){
    ll g = gcd(a, b);
    return a / g * b;
}

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n;
    cin >> n;
    ll ans = 1;
    rep(i,n){
        ll t;
        cin >> t;
        ans = lcm(ans, t);
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 384
#include<stdio.h>

int main(void)
{
    char buffer[256];
    int w[30]={1}, h[30]={1};
    int counter=0;
    while(1){
        fgets(buffer, 256, stdin);
        sscanf(buffer, "%d %d", &w[counter], &h[counter]);
        if(w[counter]==0&& h[counter]==0) break;
        counter++;
    }
    int i, j, k;
    for(i=0;i<counter;i++)
    {
        char mark[3]="#.";
        int flag;
        for(j=0;j<w[i];j++)
        {
            if (j%2==0)flag=0;
            else flag=1;
            for(k=0;k<h[i];k++)
            {
                printf("%c", mark[flag]);
                if(flag)flag--;
                else flag++;
            }
            putchar('\n');
        }
        putchar('\n');
    }
}


Measured memory_bytes: 2100
#pragma GCC optimize("O3")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx")

#include <bits/stdc++.h>

#define pb push_back
#define fi first
#define se second
#define all(v) v.begin(), v.end()

using namespace std;
using ll = int64_t;

constexpr ll MAX_BIT = 45;

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

  int N, K;
  cin >> N >> K;
  vector<ll> a(N);
  for (auto& i : a)
    cin >> i;

  vector<ll> sums;
  sums.reserve(N * (N + 1) / 2);
  for (int l = 0; l < N; l++) {
    ll sum = 0;
    for (int r = l; r < N; r++) {
      sum += a[r];
      sums.pb(sum);
    }
  }

  ll answer = 0;
  for (ll bit = MAX_BIT; bit >= 0; bit--) {
    int cnt = 0;
    for (auto& i : sums) {
      if (((i >> bit) & 1) && (i & answer) == answer)
        ++cnt;
    }
    if (cnt >= K) {
      answer += (1LL << bit);
    }
  }
  cout << answer << endl;

  return 0;
}


Measured memory_bytes: 4224
using System;

namespace B_002_59
{
    internal class Program
    {
        private static void Main(string[] args)
        {

            new Logic_B().Start();
 
        }

        public class Logic_B
        {
            public void Start()
            {
                var a = Console.ReadLine();
                var b = Console.ReadLine();

                if (a.Length != b.Length)
                {
                    Console.WriteLine(a.Length > b.Length ? "GREATER" : "LESS");
                }
                else
                {
                    for (int i = 0; i < a.Length; i++)
                    {
                        if (a[i] == b[i])
                        {
                            continue;
                        }
                        else
                        {
                            if (a[i] > b[i])
                            {
                                Console.WriteLine("GREATER");
                                return;
                            }
                            else
                            {
                                Console.WriteLine("LESS");
                                return;
                            }
                        }
                    }

                    Console.WriteLine("EQUAL");
                }
            }
        }

       
    }
}

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

const int INF = 1e9;
const int MOD = 1e9 + 7;

using namespace std;

typedef long long ll;

#define REP(i, n) for (int i = 0; i < int(n); i++)
#define REPD(i, n) for (int i = n - 1; i >= 0; i--)
#define FOR(i, a, b) for (int i = a; i < int(b); i++)
#define FORD(i, a, b) for (int i = b - 1; i >= int(a); i--)
#define WRAP(y, x, h, w) (0 <= y && y < h && 0 <= x && x < w)

#define ALL(x) (x).begin(), (x).end()

int gcd(int a, int b)
{
    return b ? gcd(b, a % b) : a;
}
int dx[4] = { 1, 0, -1, 0 };
int dy[4] = { 0, 1, 0, -1 };

int main()
{
    int n;
    cin >> n;
    vector<int> vi(n);
    vector<ll> vi2(n, 0);
    vector<ll> vi3(n, 0);

    REP(i, n)
    {
        cin >> vi[i];
        if (0 <= i - vi[i])
            vi2[i - vi[i]]++;
        if (i + vi[i] < n)
            vi3[i + vi[i]]++;
    }

    ll ans = 0;
    REP(i, n)
    {
        ans += vi2[i] * vi3[i];
    }
    cout << ans << endl;
}

Measured memory_bytes: 7216
import copy
N, M, X = list(map(int, input().split()))

unds = [[0 for _ in range(M + 1)]]

for n in range(N):
    i = list(map(int, input().split()))
    C = i[0]
    A = i[1:]

    new_unds = list()
    for und in unds:
        new_und = copy.copy(und)
        new_und[-1] += C
        for m in range(M):
            new_und[m] += A[m]
        new_unds.append(new_und)
    unds.extend(new_unds)

minc = 10e10
for und in unds:
    for m in range(M):
        if und[m] < X:
            break
    else:
        if minc > und[-1]:
            minc = und[-1]

if minc > 10e9:
    minc = -1

print(minc)


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

//AtCoder ABC 77

using namespace std;

#define int long long
#define all(m) m.begin(),m.end()
#define all_mas(m) for(auto &i: m) cout << i  << " ";\
cout << endl;
#define fast ios::sync_with_stdio(0), cin.tie(), cout.tie()

signed main() {
    string s;
    cin >> s;
    string t;
    cin >> t;
    reverse(all(s));
    if (t == s) cout << "YES";
    else cout << "NO";
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include<algorithm>
#include<set>
#include<iterator>
#include<map>
#include<unordered_map>
#include<vector>
#include<math.h>
using namespace std;

#define int long long
#define endl "\n"
#define pb push_back
#define F first
#define S second

int32_t main() {
   
    int n;
    cin>>n;
    
    int arr[n+1];
    
    for(int i=1;i<=n;++i)
        cin>>arr[i];
    
    int x;
    int ct = 1;
    int i = 1;
     while(n--){
         if(arr[i]==2)
         {
             cout<<ct;
             return 0;
         }
         else
         {
             i = arr[i];
             ct++;
         }
         
     }
    cout<<"-1";
    
    
    
    
    
    
	return 0;
}


Measured memory_bytes: 1152
#include <iostream>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

#define TABLE_SIZE 16777216
#define ORDER_LENGTH 7
#define STR_LENGTH 13

using namespace std;

int array[128];

int translateStr(char buf[]){
    int sum = -1,mult = 1;
    for(int i = 0; buf[i] != '\0'; i++){
        sum += array[buf[i]]*mult;
        mult *= 4;
    }
    return sum;
}

int main(){

    array['A']=1,array['C']=2,array['G']=3,array['T']=4;

    int n;
    scanf("%d",&n);
    char order[ORDER_LENGTH],str[STR_LENGTH];

    char* check_table = new char[TABLE_SIZE];

    for(int i = 0; i < n; i++){
        scanf("%s %s",order,str);
        if(order[0] == 'i'){
            check_table[translateStr(str)] = 'Y';
        }else{
            if(check_table[translateStr(str)] == 'Y'){
                printf("yes\n");
            }else{
                printf("no\n");
            }
        }
    }
}



Measured memory_bytes: 4532
#include <cstdio>
#include <algorithm>

using namespace std;

struct point
{
	int x,y;
	inline bool operator < (const point t) const
	{
		return x<t.x;
	}
};

point p[300000];
int tree[1000000];
int g[300000];
int i,k,m,n,s;

inline bool inserttree1(int l,int r,int x,int y,int z,int node)
{
	if (tree[node])
		return false;
	if (l==r)
		return tree[node]=z,true;
	int mid=(l+r)>>1;
	bool b;
	if ((l==x) && (r==y))
		if (! tree[node<<1])
			return b=inserttree1(l,mid,x,mid,z,node<<1),tree[node]=min(tree[node<<1],tree[node<<1|1]),b;
		else
			return b=inserttree1(mid+1,r,mid+1,y,z,node<<1|1),tree[node]=min(tree[node<<1],tree[node<<1|1]),b;
	if (y<=mid)
		return b=inserttree1(l,mid,x,y,z,node<<1),tree[node]=min(tree[node<<1],tree[node<<1|1]),b;
	if (x>mid)
		return b=inserttree1(mid+1,r,x,y,z,node<<1|1),tree[node]=min(tree[node<<1],tree[node<<1|1]),b;
	if (b=inserttree1(l,mid,x,mid,z,node<<1))
		return tree[node]=min(tree[node<<1],tree[node<<1|1]),b;
	else
		return b=inserttree1(mid+1,r,mid+1,y,z,node<<1|1),tree[node]=min(tree[node<<1],tree[node<<1|1]),b;
}

inline bool inserttree2(int l,int r,int x,int y,int z,int node)
{
	if (tree[node]>=z)
		return false;
	if (l==r)
	{
		if (tree[node])
			k++,g[k]=tree[node];
		tree[node]=z;
		return true;
	}
	int mid=(l+r)>>1;
	bool b;
	if ((l==x) && (r==y))
		if (tree[node<<1]<z)
			return b=inserttree2(l,mid,x,mid,z,node<<1),tree[node]=min(tree[node<<1],tree[node<<1|1]),b;
		else
			return b=inserttree2(mid+1,r,mid+1,y,z,node<<1|1),tree[node]=min(tree[node<<1],tree[node<<1|1]),b;
	if (y<=mid)
		return b=inserttree2(l,mid,x,y,z,node<<1),tree[node]=min(tree[node<<1],tree[node<<1|1]),b;
	if (x>mid)
		return b=inserttree2(mid+1,r,x,y,z,node<<1|1),tree[node]=min(tree[node<<1],tree[node<<1|1]),b;
	if (b=inserttree2(l,mid,x,mid,z,node<<1))
		return tree[node]=min(tree[node<<1],tree[node<<1|1]),b;
	else
		return b=inserttree2(mid+1,r,mid+1,y,z,node<<1|1),tree[node]=min(tree[node<<1],tree[node<<1|1]),b;
}

int main()
{
	scanf("%d%d",&n,&m);
	for (i=1;i<=n;i++)
		scanf("%d%d",&p[i].x,&p[i].y);
	sort(p+1,p+n+1);
	for (i=1;i<=n;i++)
	{
		if ((p[i].x) && (inserttree1(1,m,1,p[i].x,p[i].y,1)))
			continue;
		if ((p[i].x) && (inserttree2(1,m,1,p[i].x,p[i].y,1)))
			continue;
		k++,g[k]=p[i].y;
	}
	sort(g+1,g+k+1);
	for (i=k;i>0;i--)
	{
		if ((g[i]<=m) && (inserttree1(1,m,g[i],m,1,1)))
			continue;
		if ((g[i]<=m) && (inserttree2(1,m,g[i],m,1,1)))
			continue;
		s++;
	}
	printf("%d",s);
	return 0;
}

Measured memory_bytes: 6400
//Author: Bishal Sarang

#include <bits/stdc++.h>
#define MAX 10000000
using namespace std;

//typedefs
typedef long long ll;
typedef unsigned long long ull;

typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<ull> vull;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<pii> vpii;
typedef map<int, int> mii;

//Constants
const ll MOD = 10e9 + 7;
const long double PI = acos((long double)(-1.0));
const long double EPS = 1e-9;

#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define __lcm(a, b)   (a * b)/__gcd(a, b);


int main()
{
  cin.sync_with_stdio(false);
	cin.tie(0);
	#ifdef DEBUG
    freopen("in.txt", "r", stdin);
	#endif // DEGUBG
 long a, b;
 cin >> a >> b;
 cout << max({a + b, a - b, a * b});

 cerr << "\nTime elapsed " << 1.0 * clock() / CLOCKS_PER_SEC << " secs";
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define _GLIBCXX_DEBUG //GCC5.4.1で配列の範囲外アクセスをエラーにする

//cmdで g++ test.cpp とするとコンパイルできる
//制限1秒なら10^6は余裕 10^7は多分間に合う 10^8はよほど単純でないと厳しい

#define ALL(x) x.begin(),x.end()
typedef long long ll; //long long
typedef pair<int,int> pii; //pair<int,int>
typedef vector<int> vi; //vector<int>
typedef vector<vector<int>> vvi; //vector<vector<int>>
typedef vector<ll> vll; //vector<long long>
typedef vector<vector<ll>> vvll; //vector<vector<long long>>
typedef priority_queue<int, vector<int>, greater<int> > gpq; //逆順priority_queue
typedef priority_queue<int> pq;

//const int MOD=998244353;
const int MOD=1000000007; //10^9+7
const double PI=3.1415926535;

ll gcd(ll x,ll y){
    ll b=max(x,y),s=min(x,y);
    if(s<=0)return b;
    return gcd(s,b%s);
}

int main(){
    int N;
    string S;
    cin>>N>>S;
    vi R(0),G(0),B(0);
    for(int i=0;i<N;i++){
        if(S[i]=='R'){
            R.push_back(i);
        }else if(S[i]=='G'){
            G.push_back(i);
        }else if(S[i]=='B'){
            B.push_back(i);
        }
    }
    ll NR=R.size(),NG=G.size(),NB=B.size();
    //cout<<NR<<" "<<NG<<" "<<NB<<endl;
    ll ans=NR*NG*NB;
    for(int r=0;r<NR;r++){
        for(int g=0;g<NG;g++){
            int dif=abs(R[r]-G[g]);
            int x1=max(R[r],G[g])+dif,x2=min(R[r],G[g])-dif;
            int a1=upper_bound(ALL(B),x1)-lower_bound(ALL(B),x1);
            int a2=upper_bound(ALL(B),x2)-lower_bound(ALL(B),x2);
            if(a1!=0){
                ans--;
            }
            if(a2!=0){
                ans--;
            }
            if(abs(R[r]-G[g])%2==0){
                int x3=(R[r]+G[g])/2;
                int a3=upper_bound(ALL(B),x3)-lower_bound(ALL(B),x3);
                if(a3!=0)ans--;
            }
        }
    }
    cout<<ans<<endl;
}


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

using namespace std;
typedef long long ll;

int main(void)
{
  ll N,M;cin>>N>>M;
  vector<bool> check(N,false);
  vector<ll> WAtimes(N,0);
  ll AC=0,WA=0;
  for(ll i=0;i<M;i++){
    ll prob;cin>>prob;
    prob--;
    string ans;cin>>ans;
    if(ans=="AC" && !check[prob]){
      check[prob]=true;
      AC++;
      WA += WAtimes[prob];
    }
    if(ans=="WA"){
      ++WAtimes[prob];
    }
  }
  cout<<AC<<" "<<WA<<endl;
    return 0;
}

Measured memory_bytes: 1024
#include <iostream>
#include <vector>
#include <algorithm>
#include <cstdio>
#include <string>
#define rep(x,to) for(int x=0;x<to;x++)
#define rep2(x,from,to) for(int x=from;x<to;x++)

using namespace std;




int main(void){
 
double hi,hmx=-999,hmn=99999999;
	while(cin >> hi){
		hmx = max(hmx, hi);
		hmn = min(hmn, hi);
	}

	printf("%.1lf\n",hmx-hmn);
    return 0;
}

Measured memory_bytes: 1236
#include<bits/stdc++.h>
using namespace std;
map<int,int> m;

void call(int x){

    while(x%2==0){
        m[2]++;
        x/=2;
    }
    for(int i=3; i<=sqrt(x); i+=2){
        while(x%i==0){
            m[i]++;
            x/=i;
        }
    }
    if(x>1)
        m[x]++;
}

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


    int n;
    cin>>n;

    for(int i=2; i<=n; i++){
        call(i);
    }
    long long ans=1,mod=1e9+7;

    for(auto it: m){
        ans*=(it.second+1);
        ans%=mod;
    }

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


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define int long long 
#define uint unsigned long long 
#define double long double 
#define all(c) (c).begin(),(c).end()
#define rall(c) (c).rbegin(),(c).rend()
#define sz(a) (int)(a).size()
#define hell 1000000007
#define vi vector<int> 
#define vb vector<bool> 
#define vpi vector<pair<int,int>> 
#define x first 
#define y second 
#define endl '\n'

using namespace std;


void solve(){
	double a , b , x;
	cin >> a >> b >> x; 
	
	double mid_area = (1.0*a*a*b)/2;
	//cout << mid_area << endl;
	if((double)x > mid_area){

		double ans = atan((a*a*a*.5)/(a*a*b-x));
		ans = (ans*180)/M_PI;
		cout << 90-ans << endl;
	}else if( (double)x < mid_area ){
		double ans = atan((2*x)/(a*b*b));
		ans = (ans*180)/M_PI;
		cout << 90-ans << endl;
	}else {
		cout << 45.0000000 << endl;
	}
}

int32_t main(){
	
	ios_base::sync_with_stdio(false);
	cin.tie(nullptr);
	cout.tie(nullptr);
	cout << fixed;
	cout.precision(20);

	int t = 1;
	//cin >> t ;
	while(t--){
		solve();
	}
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <cmath>
#include <cstring>

using namespace std;

int main(){

    long long N;
    cin >> N;

    long long ans = 0;

    for(int i = 1; i < min(N, 1000000LL); i++){
        if(N % i == 0){
            long long temp = N / i - 1;
            if(temp <= i){
                break;
            }
            ans += temp;
        }
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
#define int long long
#define rng(i, l, r) for (size_t i = (l); i < (r); ++i)
#define rep(i, n) rng(i, 0, n)
#define gnr(i, l, r) for (size_t i = (r)-1; i >= (l); i--)
#define per(i, b) gnr(i, 0, b)
#define ALL(obj) (obj).begin(), (obj).end()    //1,2,3,...
#define rALL(obj) (obj).rbegin(), (obj).rend() //...,3,2,1
using namespace std;
const int INF = 1e18;
const int MOD = 1000000007;
vector<pair<int, int>> prime_factorize(int n)
{
    vector<pair<int, int>> result;

    for (int factor = 2; factor * factor <= n; factor++)
    {
        if (n % factor != 0)
            continue;

        int power = 0;
        while (n % factor == 0)
        {
            power++;
            n /= factor;
        }
        result.push_back({factor, power});
    }

    if (n != 1)
        result.push_back({n, 1});

    return result;
}

int calc(int n)
{
    for (int i = 0; i < 100; i++)
    {
        bool islow = i * (i + 1) <= 2 * n;
        bool istop = 2 * n < (i + 1) * (i + 2);
        if (islow && istop)
        {
            return i;
        }
    }
    return 0;
}
void solve()
{

    // remove the bottom 3 lines when you submit this code.
    std::ifstream in("sample.txt");
    std::cin.rdbuf(in.rdbuf());

    cin.tie(0);
    ios::sync_with_stdio(false);

    int n;
    cin >> n;
    vector<pair<int, int>> pf = prime_factorize(n);

    int ans = 0;
    rep(i, pf.size())
    {
        ans += calc(pf[i].second);
    }

    cout << ans << endl;
}

signed main()
{
    solve();
    return 0;
}


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

using namespace std;

const int MAXN = 20010;

int n;

int v[MAXN];
int a[MAXN];
int b[MAXN];
int lazy[MAXN];

int main()
{
	scanf("%d",&n);

	for(int i = 1 ; i <= n ; i++)
		scanf("%d",&v[i]);

	for(int i = 1 ; i <= n ; i++)
	{
		a[i] = i;
		b[i] = n - i + 1;
	}

	for(int i = 1 ; i <= n ; i++)
		lazy[ v[i] ] = i;

	int sum = 0;

	for(int i = 1 ; i <= n ; i++)
	{
		sum += lazy[i];
		a[i] += sum;
	}

	sum = 0;

	for(int i = n ; i > 0 ; i--)
	{
		sum += lazy[i];
		b[i] += sum;
	}

	for(int i = 1 ; i <= n ; i++)
		printf("%d ",a[i]);

	printf("\n");

	for(int i = 1 ; i <= n ; i++)
		printf("%d ",b[i]);
}

Measured memory_bytes: 896
#include <bits/stdc++.h>
#define be(v) (v).begin(),(v).end()
#define pb(q) push_back(q)
typedef long long ll;
using namespace std;
const ll mod=1000000007, INF=(1LL<<60);
#define doublecout(a) cout<<fixed<<setprecision(10)<<a<<endl;

int main() {
    cin.tie(0);
    cout.tie(0);
    ios::sync_with_stdio(false);
    int n;
    int a;
    cin >> n;
    int ans = 0;
    for(int i=0;i<n;i++){
    	cin >> a;
    	if((i&1)==0) if(a&1) ans++;
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 3632
#include <bits/stdc++.h>
#define ll long long
using namespace std;
const int N = 55;
struct P{
    int v, a, b;
};
vector<P> G[N];
int c[N], d[N];
ll f[N][N * N];
int main() {
    int n, m, s;
    scanf("%d%d%d", &n, &m, &s), s = min(s, 2500);
    for(int i = 0, u, v, a, b; i < m; i++) {
        scanf("%d%d%d%d", &u, &v, &a, &b);
        G[u].push_back({v, a, b});
        G[v].push_back({u, a, b});
    }
    for(int i = 1; i <= n; i++) {
        scanf("%d%d", &c[i], &d[i]);
    }
    for(int i = 0; i < N; i++) {
        for(int j = 0; j < N * N; j++) {
            f[i][j] = 1e18;
        }
    }
    f[1][s] = 0;
    typedef tuple<ll, int, int> T;
    priority_queue<T, vector<T>, greater<T>> qu;
    qu.push(T(0, 1, s));
    while(!qu.empty()) {
        ll t = get<0>(qu.top());
        int u = get<1>(qu.top()), w = get<2>(qu.top());
        qu.pop();
        if(f[u][w] > t) continue;
        for(int i = 0; i < G[u].size(); i++) {
            int v = G[u][i].v, a = G[u][i].a, b = G[u][i].b;
            if(w >= a && f[v][w - a] > t + b) {
                f[v][w - a] = t + b;
                qu.push(T(t + b, v, w - a));
            }
        }
        if(f[u][min(w + c[u], 2500)] > t + d[u]) {
            f[u][min(w + c[u], 2500)] = t + d[u];
            qu.push(T(t + d[u], u, min(w + c[u], 2500)));
        }
    }
    for(int i = 2; i <= n; i++) {
        ll ans = 1e18;
        for(int j = 0; j <= 2500; j++) {
            ans = min(ans, f[i][j]);
        }
        printf("%lld\n", ans);
    }
    return 0;
}

Measured memory_bytes: 6560
import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        String[] arrays = {"P", "W", "G", "Y"};
        boolean[] arrayb = {false, false, false, false};
        for (int i = 0; i < n; i++) {
            String s = sc.next();
            for (int j = 0; j < 4; j++) {
                if (s.equals(arrays[j])) {
                    arrayb[j] = true;
                }
            }
        }
        if (arrayb[0] && arrayb[1] && arrayb[2] && arrayb[3]) {
            System.out.println("Four");
        } else {
            System.out.println("Three");
        }
    }
}


Measured memory_bytes: 22356
H, W, D = map(int, input().split())
m = [None] * (H*W+1) # 数値の場所
s = [0] * (H*W+1) # その数値までD刻みで移動する累積コスト
for y in range(H):
  A = list(map(int, input().split()))
  for x, a in enumerate(A):
    m[a] = (x, y)

for i in range(D+1, H*W+1):
  x, y = m[i]
  px, py = m[i-D]
  s[i] = s[i-D] + abs(x-px) + abs(y-py)

Q = int(input())
for i in range(Q):
  L, R = map(int, input().split())
  print(s[R] - s[L])

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



int main(){
    int L; cin >> L;
    int N;
    int memo[21];
    vector<pair<pair<int,int>, int> > ans;
    rep(i, 0, 21){
        if(i == 0)memo[i] = 1;
        else memo[i] = memo[i-1] << 1;
    }
    if(L <= 3){
        N = 2;
        rep(i, 0, L){
            ans.push_back({{1,2}, i});
        }
    }else{
        rep(i, 0, 21){
            if(L < memo[i]){
                N = i;
                break;
            } 
        }
        rep(i,0, 4) ans.push_back({{N-1,N},i} );
        rep(i, 2, N-1){
            ans.push_back({{i,i+1},memo[N-i]});
            ans.push_back({{i,i+1}, 0});
        }
        while(L > 3){
            int index = 0;
            while(L >= memo[index+1]) index++;
            ans.push_back({{1,N-index+1}, L - memo[index]});
            L -= memo[index];
        }
        rep(i, 0, L){
            ans.push_back({{1,N}, i});
        }
    }
    int M = ans.size();
    
    cout << N << " " << M << endl;
    rep(i, 0, M){
        cout << ans[i].first.first << " " <<  ans[i].first.second << " " << ans[i].second << endl;
    }
    return 0;
}

Measured memory_bytes: 256
<?php
// Your code here!
list($a, $b) = explode(' ',fgets(STDIN));

$res = '';
if(($a*$b)%2==0){
    $res = 'Even';
}elseif (($a*$b)%2!=0) {
    // code...
    $res = 'Odd';
}

echo $res;

?>

Measured memory_bytes: 3828
#include<iostream>
#include<vector>
#include<map>
using namespace std;

vector<string> con, res;
int score, t;
string s;
map<int,int> m;

void dfs(int cur){
    if(cur == s.length()){
        int tmp = 0;
        for(string x : con) tmp += stoi(x);
        if(tmp <= t && tmp >= score){
            score = tmp;
            res = con;
            m[tmp]++;
        }
        return;
    }

    for(int k = cur+1; k <= s.length(); k++){
        con.push_back(s.substr(cur, k-cur));
        dfs(k);
        con.pop_back();
    }
}

int main(){
    while(cin >> t >> s, t != 0 && s != "0"){
        m.clear();
        con.clear();
        score = -1;
        int tmp = 0;
        for(char c : s)   tmp += c-'0';
        if(t < tmp){
            cout << "error" << endl;
            continue;
        }
        dfs(0);
        if(m[score] != 1){
            cout << "rejected" << endl;
        }else{
            cout << score << " ";
            for(int i = 0; i < res.size(); i++)    cout << res[i] << " \n"[i+1==res.size()];
        } 
    }
    return 0;
}


Measured memory_bytes: 3144
#include<iostream>
#include <iomanip>
#include<vector>
#include<string>
#include<string.h>
#include<math.h>
#include<utility>
#include<algorithm>
#include<functional>
using namespace std;




int min(int a,int b)
{
	int sa=a,sb=b;
if(a<b)
	{
		swap(a,b);
}
while(b)
{
a=a%b;
swap(a,b);
}

return sa*sb/a;
}

int n;
int a=1,b=1;

int main()
{
	cin>>n;
	
	for(int i=0;i<n;i++)
	{
	cin>>b;
	
	a=min(a,b);

	}

	cout<<a<<endl;

	return 0;
}

Measured memory_bytes: 1160
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
	    String S = sc.next();
	    sc.close();
	    
	    if (S.length()%2==0){
	    	S = S.substring(0,S.length()-2);
	    	while (S.length()!=0){
	    		String first = S.substring(0, S.length()/2);
	    		String second = S.substring(S.length()/2,S.length());
	    		
	    		if (first.toString().equals(second.toString())==false){
	    			S = S.substring(0,S.length()-2);	
	    		}
	    		else
	    			break;
	    	}
	    }
	    else {
	    	S = S.substring(0,S.length()-1);	
	    	while (S.length()!=1){
	    		String first = S.substring(0, S.length()/2);
	    		String second = S.substring(S.length()/2,S.length());
	    		
	    		if (first.toString().equals(second.toString())==false){
	    			S = S.substring(0,S.length()-2);	
	    		}
	    		else
	    			break;
	    	}
	    }
	    if (S.length()==1)
	    	System.out.println(0);
	    else 
	    	System.out.println(S.length());

	}

}


Measured memory_bytes: 23764