akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
#define lld long long int
// #define M 1000000007
#define fors(i,n) for(int i=0;i<n;++i)
#define fore(i,a,b) for(int i=a;i<=b;++i)
#define fastio ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define vv std::vector<int>
#define endl "\n"
#define test(i) cout<<i<<endl
#define tests(i) cout<<"i: "<<i<<endl;
#define itrt int t; cin>>t; fors(i,t)
#define itr1 int t; cin>>t;
#define ff first
#define ss second
#define pb push_back
#define vmp make_pair
#define ppb pop_back
#define sorta(a,n) sort(arr,arr+n)
#define sortv(x) sort(x.begin(),x.end())
void file(){
    #ifdef LOCAL
    freopen("demo.in","r",stdin);
    freopen("demo.out","w",stdout);
    #endif
}

#define N 10000005

void test_case(){
    int n,k;
    cin>>n>>k;
    vv v(n,0);
    for(int i=0;i<k;++i){
        int x;
        cin>>x;
        for(int j=0;j<x;++j){
            int xx;
            cin>>xx;
            --xx;
            v[xx]=1;
        }
    }
    int cnt=0;
    for(int i=0;i<n;++i){
        if(v[i]==0){
            ++cnt;
        }
    }
    test(cnt);
}

int main(){
    fastio;
    file();
    int T=1;
    // int T;
    // cin>>T;
    for(int nr=1;nr<=T;++nr) {
        // cout<<"Case #"<<nr<<": ";
		test_case();
		return 0;
    }
}

Measured memory_bytes: 3664
import java.util.Scanner;

class Main{
  public static void main(String args[]){
    Scanner sc = new Scanner(System.in);
    int a = sc.nextInt();
    int b = sc.nextInt();
    int c = sc.nextInt();
    if(a < b && b < c){
      System.out.println("Yes");
    }else{
      System.out.println("No");
    }
  }
}



Measured memory_bytes: 26344
#include <iostream>
#include <vector>

using namespace std;

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

int gcd(int a, int b) { return b ? gcd(b, a%b) : a; }

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

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

    vector<int> left(n+1, 0), right(n+1, 0);
    for(int i = 0; i < n; i++){
        left[i+1] = gcd(left[i], a[i]);
    }

    for(int i = n-1; i >= 0; i--){
        right[i] = gcd(right[i+1], a[i]);
    }
    
    int answer;
    for(int i = 0; i < n; i++)
    {
       int l = left[i];
       int r = right[i+1];
       
       chmax(answer, gcd(l, r));
    }
    
    cout << answer << endl;
    return 0;
}

Measured memory_bytes: 1408
#include <bits/stdc++.h>
#define r(i,n) for(int i=0;i<n;i++)
#define mk make_pair
using namespace std;
int dx[]={0,0,1,-1},dy[]={1,-1,0,0};
int main(){
  int h,w,x,y,sol=0,pri=0;
  cin>>h>>w;
  bool b[h][w];
  string s[h];
  r(i,h)cin>>s[i];
  r(i,h)r(j,w)if(s[i][j]=='%')x=j,y=i;
  r(i,h)r(j,w)b[i][j]=0;
  queue<pair<int,int> >Q;
  queue<int>q1;
  q1.push(0);
  Q.push(mk(y,x));
  b[y][x]=1;
  while(!Q.empty()){
    pair<int,int >a=Q.front();Q.pop();
    int xx=a.second,yy=a.first,cc=q1.front();q1.pop();
    if(pri&&pri<cc)break;
    if(s[yy][xx]=='$'){sol=cc;break;}
    if(s[yy][xx]=='@'){pri=cc;}
    r(i,4){
      int x1=xx+dx[i],y1=yy+dy[i];
      if(x1<0||x1>=w||y1<0||y1>=h||b[y1][x1]||s[y1][x1]=='#')continue;
      Q.push(mk(y1,x1));b[y1][x1]=1;
      q1.push(cc+1);
    }
  }
  if(sol==0)cout<<"Yes"<<endl;
  else cout<<"No"<<endl;
}

Measured memory_bytes: 3240
#define _CRT_SECURE_NO_WARNINGS
#include <cstdio>

using namespace std;

int main()
{
    const char *delicious = "delicious";
    const char *safe = "safe";
    const char *dangerous = "dangerous";

    int X, A, B;
    if (scanf("%d%d%d", &X, &A, &B) < 3) return 0;

    int a = B - A;
    int b = X - a;

    printf("%s\n",
        a <= 0 ? delicious
            : 0 < a && 0 <= b ? safe
                : dangerous);

    return 0;
}


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

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

int H, W;
char grid[55][55];

int main() {
  fill(grid[0], grid[54], '.');
  cin >> H >> W;
  for (int i = 1; i < H + 1; i++) {
    for (int j = 1; j < W + 1; j++) {
      cin >> grid[i][j];
    }
  }

  for (int i = 1; i < H + 1; i++) {
    for (int j = 1; j < W + 1; j++) {
      if (grid[i][j] == '.') continue;
      bool flag = false;
      char c = grid[i][j];
      for (int k = 0; k < 4; k++) {
        if (grid[i+dy[k]][j+dx[k]] == c) {
          flag = true;
        }
      }
      if (!flag) {
        cout << "No" << endl;
        return 0;
      }
    }
  }

  cout << "Yes" << endl;
  return 0;
}


Measured memory_bytes: 256
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time,copy,functools

sys.setrecursionlimit(10**7)
inf = 10**20
eps = 1.0 / 10**15
mod = 10**9+7

def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def S(): return input()
def pf(s): return print(s, flush=True)


def main():
    n,c = LI()
    a = [-1] * (c+1)
    b = sorted([LI() for _ in range(n)])
    for s,t,d in b:
        for i in range(c):
            if a[i] < s:
                a[i] = t
                break

    for i in range(c+1):
        if a[i] < 0:
            return i

    return -1



print(main())




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

using namespace std;
using namespace __gnu_pbds;

const int maxn = 2e5 + 7;
const int mod = 998244353;

int A,B;
int ans;

int main()
{
	scanf("%d%d",&A,&B);
	for(int i=1;i<=10000;i++)
	{
		double a = (double)i*8/100.0;
		double b = (double)i*10/100.0;
		if((int)a==A && (int)b==B)
		{
			printf("%d\n",i);
			return 0;
		}
	}
	printf("-1\n");
	return 0;
}




Measured memory_bytes: 256
#include <bits/stdc++.h>
#define REP(i,n) for(int i=0;i<(n);++i)
using namespace std;
typedef long long ll;

// dp[i][0]: Aiに対して操作しない場合の、Aiまでの合計数
// dp[i][1]: Aiに対して操作した場合の、Aiまでの合計数
ll dp[100005][2];

int main() {
  int N;
  cin >> N;
  vector<ll> A(N);
  REP(i,N) {
    cin >> A[i];
  }
  dp[0][0] = A[0];
  dp[0][1] = -A[0];

  REP(i,N-1) {
    dp[i+1][0] = max( dp[i][0] + A[i+1], dp[i][1] - A[i+1] );
    dp[i+1][1] = max( dp[i][0] - A[i+1], dp[i][1] + A[i+1] );
  }
  cout << dp[N-1][0] << endl;

//  REP(i,N) cout << dp[i][0] << " " << dp[i][1] << endl;
  
}



Measured memory_bytes: 2560
#include <bits/stdc++.h>
#define MOD 1000000007LL
using namespace std;
typedef long long ll;
typedef pair<int,int> P;

int k;
string s;

int main(void){
	scanf("%d",&k);
	cin >> s;
	if(s.size()<=k){
		cout << s << endl;
	}else{
		cout << s.substr(0,k) << "..." << endl;
	}
	return 0;
}


Measured memory_bytes: 3700
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <cmath>
#include <stack>
#include <queue>
#include <set>
#include <map>
using namespace std;
typedef long long ll;
typedef vector<int> VI;
typedef vector< vector<int> > VVI;
typedef pair<int,int> P;
#define rep(i,n) for(int i=0;i<(n);i++)
#define all(a) (a).begin(),(a).end()

int main(){
  int N;
  cin>>N;
  VI A(N);
  rep(i,N) cin>>A[i];
  int X[100010]={};
  ll ans=3;
  ll mod=1000000007;
  ll Y=2;
  rep(i,N){
    X[A[i]]++;
    if(i){
      if(A[i]){
        ans=(ans*X[A[i]-1])%mod;
        X[A[i]-1]--;
      }else{
        ans=(ans*Y)%mod;
        Y--;
      }
    }
  }
  if(A[0]==0) cout<<ans<<endl;
  else cout<<0<<endl;
}





Measured memory_bytes: 1024
#include <bits/stdc++.h>
#define cout16 cout << setprecision(16) 
#define rep(i,n) for(int i=0;i<n;i++ )
#define rep2(i,f,n) for(int i=f;i<n;i++ )
#define MAX(A) *max_element(A.begin(),A.end())
#define MIN(A) *min_element(A.begin(),A.end())
#define SORT(A) sort(A.begin(),A.end())
#define REV(A) reverse(A.begin(),A.end())
typedef long long int ll;
using vi = std::vector<int>;
using vvi = std::vector<std::vector<int>>;
using vll = std::vector<ll>;
using vvll = std::vector<std::vector<ll>>;
using P = std::pair<int,int>;
using vp = std::vector<P>;
using namespace std;
#define INF 1001001001
#define LL_INF 1001001001001001001

int main(void) {
	int n,k; cin >> n >> k;
	vi v(n); rep(i,n) cin >> v[i];
	int ans = 0;
	rep(l,k+1)rep(r,k-l+1){
		if(l+r>n) continue;
//		cout << endl << l << " " << r << " " << endl;
		int d=k-l-r;
		priority_queue<int, vector<int>, greater<int> > q;
		int sum=0;
		rep(i,l) q.push(v[i]);
		rep(j,r) q.push(v[n-j-1]);
		int cnt=0;
		while(!q.empty()&&cnt<d){
			if(q.top()<0){
//				cout << q.top() << ".pop()" << endl;			
				q.pop();
				cnt++;
			}
			else break;
		}
		while(!q.empty()){
			sum += q.top();
			q.pop();
		}
		ans = max(ans,sum);
//		cout << "sum = " << sum << endl;
	}
	cout << ans << endl;
}




Measured memory_bytes: 256
#include<stdio.h>

int main(){/*main*/
  int n;

  while(scanf("%d",&n)!=EOF)
    {

      while(n>78)
	{
	  n=n-39;
	}
      if(n<=39)
	{
	}
      else{
      n=n-39;
      }
      if(n>=10){
	printf("3C%d\n",n);
      }
      else if(n==0){
	printf("3C39\n");
      }
      else{
	printf("3C0%d\n",n);
      }
    }
  return 0;
}/*E-main*/

Measured memory_bytes: 0
#include <iostream>
#include <iomanip>
using namespace std;
 
int main() {
    double a, b, c, d, e, f;
    double x, y;

    while (cin >> a >> b >> c >> d >> e >> f) {
        x = (double)(c*e - b*f)/(a*e - b*d);
        y = (double)(c*d - a*f)/(b*d - a*e);
        cout << setprecision(3) << setiosflags(ios::fixed);
        cout << x+0.0000000001 << ' ' << y+0.0000000001 << endl;
    }
    return 0;
}

Measured memory_bytes: 1284
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define MOD 1000007
#define MAX 100005
#define PAIR pair<ll,ll>

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

    ll a,b,c,d;

    cin>>a>>b>>c>>d;

    ll ans = a*c;
    ans = max(ans,a*d);
    ans = max(ans,b*c);
    ans = max(ans,b*d);

    cout<<ans<<endl;



    return 0;
}


Measured memory_bytes: 3648
//
// Created by Huang,Zhiqiang on 2018/9/30.
//

#include <iostream>
#include <map>
#include <algorithm>
#include <memory.h>
using namespace std;
const int N = 1e5 + 5;
int a[N];


int main() {
    memset(a, 0, sizeof(a));
    int n;
    cin >> n;
    for (int i = 1; i <= n; i++) cin >> a[i];
    if (n == 2) {
        int ans = a[1] == a[2] ? 1 : 0;
        cout << ans << endl;
        return 0;
    }
    map<int, int> m1, m2;
    for (int i = 1; i <= n; i++) {
        if (i % 2 == 1) m1[a[i]]++;
        else m2[a[i]]++;
    }
    map<int, int>::iterator iter = m1.begin();
    map<int, int>::iterator m1_f = iter,m1_s = iter;
    while (iter != m1.end()) {
        if (iter->second >= m1_f->second) {
            m1_f = iter;
        }
        iter++;
    }
    iter = m1.begin();
    while (iter != m1.end()) {
        if (iter != m1_f) {
            if (iter->second >= m1_s->second) {
                m1_s = iter;
            }
        }
        iter++;
    }
    iter = m2.begin();
    map<int, int>::iterator m2_f = iter,m2_s = iter;
    while (iter != m2.end()) {
        if (iter->second >= m2_f->second) {
            m2_f = iter;
        }
        iter++;
    }
    iter = m2.begin();
    while (iter != m2.end()) {
        if (iter != m2_f) {
            if (iter->second >= m2_s->second) {
                m2_s = iter;
            }
        }
        iter++;
    }
    int ans = 0;
    if (m1_f->first != m2_f->first) {
        ans = n - m1_f->second - m2_f->second;
    } else {
        int t1 = n, t2 = n;
        int k11 = 0, k12 = 0, k21 = 0, k22 = 0;
        if (m1_f->first == m1_s->first) {
            k11= m1_f->second;
        } else {
            k11 = m1_f->second;
            k12 = m1_s->second;
        }
        if (m2_f->first == m2_s->first) {
            k21 = m2_f->second;
        } else {
            k21 = m2_f->second;
            k22 = m2_s->second;
        }
        t1 = n - k12 - k21;
        t2 = n - k11 - k22;
        ans = min(t1, t2);
    }
    cout << ans << endl;
}

Measured memory_bytes: 5376
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); i++)
#define all(x) (x).begin(), (x).end()
typedef long long ll;
using namespace std;

struct city {
    int P;
    int Y;
    int i;

    bool operator<(const city &another) const {
        if (P == another.P)
            return Y < another.Y;
        else
            return P < another.P;
    };
};

int main() {
    int N, M;
    cin >> N >> M;
    vector<city> c(M);
    vector<vector<int>> ans(M);
    rep(i, M) {
        cin >> c[i].P >> c[i].Y;
        c[i].i = i;
    }
    sort(all(c));

    int before = -1;
    int cnt    = 1;
    rep(i, M) {
        int ci = c[i].P;

        if (ci == before)
            cnt++;
        else
            cnt = 1;

        before    = ci;
        int index = c[i].i;
        ans[index].push_back(ci);
        ans[index].push_back(cnt);
    }

    rep(i, M) printf("%06d%06d\n", ans[i][0], ans[i][1]);
}

Measured memory_bytes: 8192
// Vicfred
// https://atcoder.jp/contests/abc147/tasks/abc147_b
// string manipulation
use std::io;

fn main() {
    let mut s = String::new();

    io::stdin()
        .read_line(&mut s)
        .unwrap();

    let s = s.trim();

    let n = s.len();
    let s: Vec<char> = s.chars().collect();

    let mut answer = 0;

    for i in 0..n as usize {
        if s[i] != s[n-i-1] {
            answer += 1;
        }
    }

    println!("{}", answer/2);

}




Measured memory_bytes: 2060
#include <bits/stdc++.h>
#define ll long long int
#define MOD 1000000007
#define INF 1000000000000000000

using namespace std;

#define N 1000001

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

vector<bool> isprime;

void make_table(){
  isprime[0] = isprime[1] = 0;
  for (ll i = 2; i < N; i++){
    if (isprime[i]){
      for (ll j = i*i; j < N; j += i){
        isprime[j] = 0;
      }
    }
  }
}


int main(void){
  ll n;
  cin >> n;
  
  isprime = vector<bool>(N, 1);

  vector<ll> a(n);
  bool is1 = 0;
  int id = 0;
  for (int i = 0; i < n; i++){
    ll b;
    cin >> b;
    
    if (b != 1){
      a[id] = b;
      id++;
    }
    else if (!is1){
      a[id] = b;
      id++;
      is1 = 1;
    }
  }
  

  n = id;
  // setwise
  ll g = a[0];
  for (int i = 0; i < n; i++){
    g = gcd(g, a[i]);
  }


  // pairwise
  vector<ll> primes(0);
  make_table();
  for (int i = 0; i < N; i++){
    if (isprime[i])
      primes.emplace_back(i);
  }



  int ok = 1;
  if (n > primes.size()){
    ok = 0;
  }
  else {
    for (int i = 0; i < n; i++){
      /*
      for (int j = 0; j < primes.size(); j++){
        if (a[i] % primes[j] == 0 && isprime[primes[j]] == 0){
          ok = 0;
        }
        else if (a[i] % primes[j] == 0){
          isprime[primes[j]] = 0;
        }
      }
      */


      for (int j = 2; j*j <= a[i]; j++){
        if (a[i] % j == 0){
          if (isprime[j] == 0){
            ok = 0;
          }
          else {
            isprime[j] = 0;
            while (a[i] % j == 0){
              a[i] /= j;
            }
          }
        }
      }
      if (a[i] != 1){
        if (isprime[a[i]] == 0){
          ok = 0;
        }
        else {
          isprime[a[i]] = 0;
        }
      }
    }
  }
  
  if (ok){
    cout << "pairwise coprime" << endl;
  }
  else if (g == 1){
    cout << "setwise coprime" << endl;
  }
  else
    cout << "not coprime" << endl;

  return 0;
}


Measured memory_bytes: 12156
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
#define rep(i, n) for(ll i = 0; i < (n); ++i)
#define FOR(i, m, n) for(ll i = m; i < (n); i++)
#define all(x) (x).begin(),(x).end()
using namespace std;
typedef long long ll;
using vi = vector<int>;
using vii = vector<vi>;
using pii = pair<int, int>; 
using vl = vector<ll>;
using vll = vector<vl>;
using pll = pair<ll, ll>;

int main() {
    ll d,t,s;
    cin >> d >> t >> s;
    if((d+s-1) / s <= t){
        cout << "Yes";
    }else{
        cout << "No";
    }
}

Measured memory_bytes: 3632
n = int(input())
d, x = map(int, input().split())
a = 0
for i in range(n):
  c = int(input())
  t = c
  a += 1
  j = 1
  while c + 1 <= d:
    a+= 1
    j += 1
    c = t * j
a += x
print(a)

Measured memory_bytes: 9032
#include<bits/stdc++.h>
using namespace std;
#define MOD 1000000007

int main() {

  int H,W;
  cin >> H >> W;

  int ch,cw,dh,dw;
  cin >> ch >> cw >> dh >> dw;
  ch--; cw--;
  dh--; dw--;

  vector<string> S(H);
  for(int i = 0;i < H;i++) cin >> S[i];

  vector<vector<int>> cost(H,vector<int>(W,-1)),seen(H,vector<int>(W,0));
  deque<pair<int,int>> deq;
  deq.emplace_back(ch,cw);
  cost[ch][cw] = 0;
  int dx[] = {1,-1,0,0},dy[] = {0,0,1,-1};

  while(deq.size()) {
    pair<int,int> p = deq.front();
    deq.pop_front();
    int y = p.first,x = p.second;
    if(seen[y][x]) continue; 
    seen[y][x] = 1;

    for(int i = 0;i < 4;i++) {
      int Y = y+dy[i],X = x+dx[i];
      if(Y < 0 || Y >= H || X < 0 || X >= W) continue;
      if(cost[Y][X] == cost[y][x] || S[Y][X] == '#') continue;
      cost[Y][X] = cost[y][x];
      deq.emplace_front(Y,X);
    }

    for(int i = -2;i <= 2;i++) {
      for(int j = -2;j <= 2;j++) {
        int Y = y+i,X = x+j;
        if(Y < 0 || Y >= H || X < 0 || X >= W) continue;
        if(cost[Y][X] != -1 || S[Y][X] == '#') continue;
        cost[Y][X] = cost[y][x]+1;
        deq.emplace_back(Y,X);
      }
    }

  }

  cout << cost[dh][dw] << endl;


}


Measured memory_bytes: 13440
def s()
  gets().chomp
end
def i()
  gets.to_i
end
def li()
  gets.split.map(&:to_i)
end
def ili()
  n = gets.to_i
  as = gets.split.map(&:to_i)
  [n, as]
end
class Array
  def sum
    total = 0
    self.each do |item|
      total += item
    end
    total
  end
end

def eratosthenes(size)
  prime_list = []
  is_prime = Array.new(size, true)
  is_prime[0] = false
  is_prime[1] = false

  2.upto(size-1){|i|
    if is_prime[i]
      prime_list << i
      (2).upto((size.to_f/i).ceil-1){|j|
        is_prime[j*i] = false
      }
    end
  }
  [prime_list, is_prime]
end

def dijkstra(s, e, cost)
  size = cost.length
  if s==e
    return 0
  end
  dp = {}
  dp[s] = 0
  undefined_node = {}
  size.times{|i|
    if i != s
      undefined_node[i] = cost[s][i]
    end
  }
  while undefined_node.length != 0
    min = undefined_node.min_by{|_, v| v}
    stock = {}
    temp = undefined_node.clone
    temp.each{|k, v|
      if min[1] == v
        undefined_node.delete(k)
        if k == e
          return v
        end
        dp[k] = v
        stock[k] = v
      end
    }

    stock.each{|k, v|
      undefined_node.each{|k2, v2|
        undefined_node[k2] = v + cost[k][k2] < v2 ?  v + cost[k][k2] : v2
      }
    }
  end
end

def get_bits(len)
  res =  []
  (2**len).times{|i|
    res << i.to_s(2).rjust(len, '0')
  }
  res
end

def get_GCD(m, n)
  tmp = [n, m].max
  n = [n, m].min
  m = tmp
  while n != 0
    tmp = m % n
    m = n
    n = tmp
  end
  m
end


n = i()
an = li()
def solve(n, an)
  if an.size == 2
    return an.max
  end
  ln = Array.new(n-1)
  rn = Array.new(n-1)
  ln[0] = an[0]
  rn[0] = an[n-1]
  (n-1).times{|i|
    ln[i+1] = get_GCD(ln[i], an[i+1])
    rn[i+1] = get_GCD(rn[i], an[n-1-i-1])
  }

  max = 0

  n.times{|i|
    temp = if i == 0
      rn[n-2]
    elsif i == n-1
      ln[n-2]
    else
      get_GCD(ln[i-1], rn[n-2-i])
    end
    max = [temp, max].max
  }
  max
end

p solve(n, an)


Measured memory_bytes: 14756
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <map>
#define rep(i,cc,n) for(int i=cc;i<=n;++i)
#define drep(i,cc,n) for(int i=cc;i>=n;--i)
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
const long long INF = 1LL <<60;
typedef long long ll;
using namespace std;

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

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

ll choose2(ll n){
    return n*(n-1)/2;
}

int main(){
    int n;
    cin>>n;
    vector<ll> a(n);
    rep(i,0,n-1){
        cin>>a[i];
        if(a[i] == 0){
            cout<<0<<endl;
            return 0;
        }
    }
    long long ans = 1;
    int cnt = 0;
    rep(i,0,n-1){
        if(a[i] == 0){
            ans = 0;
            break;
        }
        if(ans < __LONG_LONG_MAX__ / a[i]) ans *= a[i];
        else {
            ans = -1;
            break;
        }
    }
        
    if(ans > 1000000000000000000) ans = -1;

    cout<<ans<<endl;

    return 0;
}

Measured memory_bytes: 4052
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
const int INF = (int)1e7;  
using  p = pair<int,int>;
using  v = vector<int>;

int main(){
   int n,k;
   cin >> n >> k;
   auto l = vector<int>(n,0);
   for (int i = 0; i < n; i++)
   {
      cin >> l[i];
   }

   sort(l.begin(),l.end(),greater<int>());

   ll sum = 0;
   for (int i = 0; i < k; i++)
   {
      sum+=l[i];
   }
   
   cout << sum;
   
   return 0;
}
  
  

Measured memory_bytes: 256
def out_prod(v0, v1)
  return v0[0] * v1[1] - v0[1] * v1[0]
end

### main

while (line = gets)
  fs = line.chop.split(/\s+/).map { |s| s.to_f }
  #p fs.join(", ")

  p0 = out_prod([fs[2] - fs[0], fs[3] - fs[1]], [fs[6] - fs[2], fs[7] - fs[3]]);
  p1 = out_prod([fs[4] - fs[2], fs[5] - fs[3]], [fs[6] - fs[4], fs[7] - fs[5]]);
  p2 = out_prod([fs[0] - fs[4], fs[1] - fs[5]], [fs[6] - fs[0], fs[7] - fs[1]]);

  if (p0 > 0 && p1 > 0 && p2 > 0 ||
      p0 < 0 && p1 < 0 && p2 < 0)
    puts "YES"
  else
    puts"NO"
  end
end

Measured memory_bytes: 6148
#include<bits/stdc++.h>
using namespace std;
#define ll long long
const int N=1e5+5;
int n,h,w;
struct Point
{
	int r,c;
	ll a;
}a[N];
bool cmp(Point a,Point b)
{
	return a.a>b.a;
}
int fa[N*2],sum[N*2];
int find(int x)
{
	if(fa[x]!=x)
	fa[x]=find(fa[x]);
	return fa[x];
}
ll ans=0;
int main()
{
	cin>>n>>h>>w;
	for(int i=1;i<=h+w;++i)
	{
		fa[i]=i;
		sum[i]=1;
	}
	for(int i=1;i<=n;++i)
	{
		scanf("%d%d%lld",&a[i].r,&a[i].c,&a[i].a);
		a[i].c+=h;
	}
	sort(a+1,a+1+n,cmp);
	for(int i=1;i<=n;++i)
	{
		int fr=find(a[i].r),fc=find(a[i].c);
		if(fr!=fc)
		{
			fa[fr]=fc;
			sum[fc]+=sum[fr];
			sum[fr]=0;
		}
		if(sum[fc]>0)
		{
			ans+=a[i].a;
			sum[fc]--;
		}
	}
	printf("%lld\n",ans);
	return 0;
}

Measured memory_bytes: 7372
#include <iostream>
#include <set>
using namespace std;
using ll = long long;

template <typename T> T gcd(T m, T n) {
  T temp = 0;
  while(m % n != 0) {
    temp = n;
    n = m % n;
    m = temp;
  }
  return n;
}

int main() {
  ll A, B;
  cin >> A >> B;

  ll g = gcd(A, B);
  set<ll> s;

  s.insert(1);
  ll G = g;
  for(ll i = 2; i * i <= G; ++i) {
    while(g % i == 0) {
      s.insert(i);
      g /= i;
    }
  }
  s.insert(g);
  cout << s.size() << endl;
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, n) for (ll i = 0; i < (n); i++)
#define all(x) (x).begin(), (x).end()
using ll = long long;
using namespace std;
template <typename T> using vec = std::vector<T>;

int main() {
    int N;
    cin >> N;
    
    vec<int> A(N);
    rep(i, N) cin >> A[i];
    vec<int> B(N);
    rep(i, N) cin >> B[i];
    vec<int> C(N);
    rep(i, N) cin >> C[i];
    sort(all(A));
    sort(all(B));
    sort(all(C));

    ll ans = 0;
    rep(i,N){
        int b = B[i];
        ll countA,countC;
        countA = lower_bound(all(A),b) - A.begin();
        countC = N - (upper_bound(all(C),b) - C.begin());
        ans+=countA*countC;
    }
    cout << ans << endl;
}


Measured memory_bytes: 4580
#include <stdio.h>

char s[10001], a[100], x;

int main()
{	 
	int n, i;
		
	scanf("%d", &n);
	x = 65 + (n < 26 ? n : 0);
	for(i = 65; i < 91; i++, x++){
		if(x == 91) x = 65;
		a[i] = x;
	}
	scanf("%s", s);
	for(i = 0; s[i]; i++) putchar(a[s[i]]);
	puts("");
		
	return 0;
}

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

typedef long long ll;
typedef pair<ll, ll> P;

const int MAX = 1e5 + 10;
const int INF = 1e9;
const int MOD = 1e9 + 7;

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

    if(3200 <= a){
        cout << s << endl;
    } else {
        cout << "red" << endl;
    }
}

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

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

    const int p = std::pow(2, K);
    const int max = std::max({A, B, C});
    int ans = 0;
    if (max == A) {
        ans = B + C + A * p;
    } else if (max == B) {
        ans = A + C + B * p;
    } else {
        ans = A + B + C * p;
    }

    std::cout << ans << std::endl;

    return 0;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;i++)
using namespace std;
int n,sum;
vector<int>a(100001),b;
int main(){
  cin>>n;
  rep(i,n)scanf("%d",&a[i]);
  sort(a.begin(),a.begin()+n);
  for(int i=1;i*i<=a[n-1];i++){
    if(a[n-1]%i == 0){
      b.push_back(i);
      b.push_back(a[n-1]/i);
    }
  }
  sort(b.begin(),b.end());
  rep(i,n) sum += *lower_bound(b.begin(),b.end(),a[i]) - a[i];
  cout<< sum <<endl;
}

Measured memory_bytes: 3484
#include <iostream>
using namespace std;
int main(){
    int N;
    cin>>N;
    switch(N){
        case 1:case 2:case 3:case 5:case 6:case 9:case 10:case 13:case 17:
        cout<<"No"<<endl;
        break;
        default:
        cout<<"Yes"<<endl;
    }
}

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

int main(){
    int n;
    cin >> n;
    vector<int> a(n);
    for(int i=0;i<n;i++)cin >> a[i];
    int cnt;
    for(cnt=0;;cnt++){
        for(int i=0;i<n;i++){
            if(a[i]%2==1){
                cout << cnt << endl;
                return 0;
            }else{
                a[i] = a[i]/2;
            }
        }
    }
    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>

typedef struct{
  int num;
  char c;
  int key;
}Quick;

Quick A[100001];

int Partition(int, int);
void Quicksort(int, int);

int main(){
  char c1, c2, c3;
  int n, i, x = 0;

  scanf("%d%c", &n, &c1);

  for(i = 0; i < n; i++){
    scanf("%c%c%d%c",&A[i].c, &c2, &A[i].num, &c3);
    A[i].key = i;
  }

  Quicksort(0, n-1);
  for(i =0 ; i < n; i++){
    if(A[i].key > A[i+1].key && A[i].num == A[i+1].num){
      x = 1;
      break;
    }
  }
  if(x == 0) printf("Stable\n");
  if(x == 1) printf("Not stable\n");

  for(i = 0; i < n; i++){
    printf("%c %d\n", A[i].c, A[i].num);
  }
  return 0;
}

int Partition(int p, int r){
  int i, j;
  Quick x, tmp;
  x.num = A[r].num;
  i = p-1;
  for(j = p;j < r;j++){
    if(A[j].num <= x.num){
      i = i + 1;
      tmp = A[i];
      A[i] = A[j];
      A[j] = tmp;
    }
  }
  tmp = A[i+1];
  A[i + 1] = A[r];
  A[r] = tmp;
  return i + 1;
}

void Quicksort(int p, int r){
  int q;
  if(p < r){
    q = Partition(p, r);
    Quicksort(p, q-1);
    Quicksort(q + 1, r);
  }
}

Measured memory_bytes: 1780
// I am Varun Das from Jadavpur University
#include <bits/stdc++.h>
#define mod 1000000007
#define ll long long
#define dbg(x) cerr << #x << " = " << x << endl
#define INF LLONG_MAX
#define loop(i,a,b) for(int i=a;i<b;i++)
#define rep(i,a,b) for(int i=a;i>=b;i--)
using namespace std;

int main() {
#ifdef _DEBUG
	freopen("input.txt", "r", stdin);
//	freopen("output.txt", "w", stdout);
#endif
ios_base::sync_with_stdio(false);
cin.tie(NULL);
//cout<<fixed<<setprecision(12);
ll n,k,a[1003];
cin>>n>>k;
loop(i,0,n) cin>>a[i];
bool dp[100007];
memset(dp,0,sizeof(dp));
// dp[i] -> will the first person loose or win ??
loop(i,0,k+1){
    loop(j,0,n){
        if(i >= a[j] and !dp[i - a[j]] ) 
        dp[i]=true;
    }
}
if(dp[k]) cout<<"First";
else cout<<"Second";

	return 0;
}

Measured memory_bytes: 384
import java.util.Scanner;

public class Main {

	static Scanner sc = new Scanner(System.in);
	public static void main(String[] args) {
		while (sc.hasNext()) {
			Integral( sc.nextInt() );
		}
	}

	private static void Integral(int nextInt) {
		int d = nextInt;
		long a = 0;
			for (int i = 1; i < 600 / d; i++) {
				a += f( i * d ) * d;
			}
		System.out.println(a);
	}

	private static long f(long i) {
		return i * i;
	}

}


Measured memory_bytes: 26316
#include <stdio.h>
int main()
{
	int x,day;
	scanf("%d",&x);
	day=x%7;
	switch(day){
	case 0:
	printf("thu\n");
	break;
	case 1:
	printf("fri\n");
	break;
	case 2:
	printf("sat\n");
	break;
	case 3:
	printf("sun\n");
	break;
	case 4:
	printf("mon\n");
	break;
	case 5:
	printf("tue\n");
	break;
	case 6:
	printf("wed\n");
	break;
	}
	return 0;
}



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

#define F first
#define S second
#define PB push_back

using namespace std;

typedef long long LL;
typedef pair<int, int> PII;
typedef priority_queue<int> HEAP;
typedef priority_queue<int, vector<int>, greater<int> > RHEAP;

const int N = 15, M = 1010;

int n, m, k;
int f[N][M];
char g[N][M];

bool check(int n, int l, int r)
{
	for (int i = 1; i <= n; i ++ )
		if (f[i][r] - f[i][l - 1] > k)
			return false;
	return true;
}

int main()
{
	cin >> n >> m >> k;
	for (int i = 0; i < n; i ++ ) cin >> g[i] + 1;
	
	int res = 0x3f3f3f3f;
	for (int t = 0; t < 1 << (n - 1); t ++ )
	{
		int cnt = 0, row = 1;
		bool flag = true;
		memset(f, 0, sizeof f);
		
		for (int i = 0; i < n; i ++ )
		{
			for (int j = 1; j <= m; j ++ )
			{
				f[row][j] += g[i][j] - '0';
				if (f[row][j] > k)
				{
					flag = false;
					break;
				}
			}
			if ((t >> i) & 1) row ++ , cnt ++ ;
		}
		if (!flag) continue;
		
		for (int i = 1; i <= row; i ++ )
			for (int j = 1; j <= m; j ++ )
				f[i][j] += f[i][j - 1];
		
		for (int i = 1; i <= m; i ++ )
		{
			int j = i;
			while (j <= m && check(row, i, j)) j ++ ;
			
			if (j <= m) cnt ++ ;
			i = j - 1;
		}
		res = min(res, cnt);
	}
	
	cout << res << endl;
	return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main{
	public static void main(String[] args){
		Scanner s = new Scanner(System.in);
  		int a = s.nextInt();
    	int b = s.nextInt();
   		int c = s.nextInt();
		System.out.println(a+b+c >= 22 ? "bust" : "win");
	}
}


Measured memory_bytes: 21844
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) REP(i,0,n)
#define REP(i,s,e) for(int i=(s); i<(int)(e); i++)
#define repr(i, n) REPR(i, n, 0)
#define REPR(i, s, e) for(int i=(int)(s-1); i>=(int)(e); i--)
#define pb push_back
#define all(r) r.begin(),r.end()
#define rall(r) r.rbegin(),r.rend()
#define fi first
#define se second

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

const ll INF = 1e18;
const ll MOD = 1e9 + 7;
const double EPS = 1e-8;

template<typename T> T chmax(T& a, const T& b){return a = (a > b ? a : b);}
template<typename T> T chmin(T& a, const T& b){return a = (a < b ? a : b);}

int main(){
    string s;
    cin >> s;
    if(s[2] == s[3] && s[4] == s[5]) cout << "Yes" << '\n';
    else cout << "No" << '\n';
    return 0;
}

Measured memory_bytes: 256
p = [0 for _ in range(10**5+11)]
p[0] = 1
p[1] = 1
for i in range(2,10**5+10):
  for j in range(2,10**5+10):
    if 0 <= i*j <= 10**5+10:
      p[i*j] = 1
    else:
      break
n = int(input())
while True:
  if p[n] == 0:
    print(n)
    break
  n += 1

Measured memory_bytes: 3864
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <cmath>
#include <vector>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <queue>
#include <ctime>
#include <cassert>
#include <complex>
#include <string>
#include <cstring>
#include <chrono>
#include <random>
#include <queue>
#include <bitset>

using namespace std;

typedef long long ll;
typedef pair<int, int> ii;
typedef pair<ll, int> pli;
typedef pair<ll, ll> pll;
typedef long double ld;

#define FOR(i, a, b) for (int i = (a), _b = (b); i <= _b; i++)
#define FORD(i, b, a) for (int i = (b), _a = (a); i >= _a; i--)
#define REP(i, n) for (int i = 0, _n = (n); i < _n; i++)
#define FORE(i, v) for (__typeof((v).begin()) i = (v).begin(); i != (v).end(); i++)
#define fi   first
#define se   second
#define MASK(i) (1LL << (i))
#define BIT(x, i) (((x) >> (i)) & 1)

const int N = 1e5 + 5;
int a[N][5], dp[N][5], n;

void input() {
	scanf("%d", &n);
	FOR(i, 1, n) scanf("%d %d %d", &a[i][1], &a[i][2], &a[i][3]);
	FOR(i, 1, n) FOR(j, 1, 3) dp[i][j] = 0;
}

void solve() {
	FOR(i, 1, 3) dp[1][i] = a[1][i];
	FOR(i, 2, n) {
		FOR(j, 1, 3) {
			FOR(k, 1, 3) if (k != j) {
				dp[i][j] = max(dp[i][j], dp[i - 1][k] + a[i][j]);
			}
		}
	}
	int res = 0;
	FOR(i,1,3) res = max(res, dp[n][i]);
	printf("%d\n", res);
}

int main(int argc, char const *argv[])
{	

	input();
	solve();

	return 0;
}

Measured memory_bytes: 4096
#include <bits/stdc++.h>
using namespace std;
const int mxn(3e5 + 10), mxm(4e5 + 10);
const long long modl(998244353);
int nm, n, m, p, t, k;
int h[mxn << 2];
int _n;
int ql, qr;
int ans;
int a[mxn], b[mxn], c[mxn];
void init() {
  _n = 1;
  while (_n < mxn) _n <<= 1;
//  while (_n < n) _n <<= 1;
//  for (int i = 0; i < _n << 1; ++i) h[i] = 0;
}
void upd(int o, int x) {
  o += _n;
  h[o] = x;
  o >>= 1;
  while (o) {
    h[o] = max(h[o << 1], h[(o << 1) + 1]);
    o >>= 1;
  }
}
int qry(int o, int l, int r) {
  if (qr <= l || r <= ql) return 0;
  if (ql <= l && qr >= r) return h[o];
  int ml = qry(o << 1, l, (l + r) >> 1);
  int mr = qry((o << 1) + 1, (l + r) >> 1, r);
  return max(ml, mr);
}
int main() {
  ios_base::sync_with_stdio(false);
//  freopen("in.txt", "r", stdin);///////////////////////////
//  cin >> nm;
//  string s;
  while (cin >> n >> m) {
    init();
    while (n--) {
      cin >> p;
      ql = p - m, qr = p + m + 1;
      upd(p, qry(1, 0, _n) + 1);
    }
    ans = h[1];
    cout << ans;
    cout << endl;
  }
  return 0;
}
////////////////////////////////////////////////////////////////////////////////
//    if (t) cout << "YES";
//    else cout << "NO";


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

int main() {
    int x1, y1, x2, y2;
    cin >> x1 >> y1 >> x2 >> y2;

    int x3, y3, x4, y4;

    int vx;
    int vy;

    vx = x2 - x1;
    vy = y2 - y1;

    x3 = x2 - vy;
    y3 = y2 + vx;

    x4 = x3 - vx;
    y4 = y3 - vy;

    cout << x3 << ' ' << y3 << ' ' << x4 << ' ' << y4 << endl;
    return 0;
}

Measured memory_bytes: 888
import java.util.Arrays;
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		solver();
	}

	static void solver() {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int m = sc.nextInt();
		int[] s = new int[n];
		int[] t = new int[n];
		for (int i = 0; i < n; i++) {
			s[i] = sc.nextInt();
			t[i] = sc.nextInt();
		}
		int[] p = new int[m];
		for (int i = 0; i < m; i++) {
			p[i] = sc.nextInt();
		}
		Arrays.sort(p);

		int[] sum = new int[m];
		for (int i = 1; i < m; i++) {
			if (i <= 2) {
				sum[i] = p[i] - p[i - 1];
			} else {
				sum[i] = sum[i - 2] + p[i] - p[i - 1];
			}
		}

		long res = 0;
		for (int i = 0; i < n; i++) {
			boolean swapped = s[i] > t[i];
			if (s[i] > t[i]) {
				int d = s[i];
				s[i] = t[i];
				t[i] = d;
			}
			int a = lower_bound(p, s[i]);// s[i]????????§??????????°??????????
			int b = lower_bound(p, t[i]) - 1;// t[i]???????°????????????§?????????

			// ?¬????????????¨?????????
			if (a > b) {
				res += t[i] - s[i];
			} else {
				if ((a - b) % 2 == 0) {
					if (!swapped) {
						res += sum[b] - sum[a] + Math.abs(p[a] - s[i]);
					} else {
						res += (t[i] - p[a]) - (sum[b] - sum[a]);
					}
				} else {
					res += Math.abs(sum[a] - sum[b - 1]) + Math.abs(p[a] - s[i]) + Math.abs(t[i] - p[b]);
				}
			}
		}
		System.out.println(res);
	}

	// a????????§key??\?????????????°?????????´???????????????
	static int lower_bound(int[] a, int key) {
		int lo = -1;
		int hi = a.length;
		while (hi - lo > 1) {
			int mid = (lo + hi) / 2;
			if (a[mid] < key) {
				lo = mid;
			} else {
				hi = mid;
			}
		}
		return hi;
	}

	static void tr(Object... objects) {
		System.out.println(Arrays.deepToString(objects));
	}
}

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

#define crap ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define db1(x) cout<<#x<<"="<<x<<'\n'
#define db2(x,y) cout<<#x<<"="<<x<<","<<#y<<"="<<y<<'\n'
#define db3(x,y,z) cout<<#x<<"="<<x<<","<<#y<<"="<<y<<","<<#z<<"="<<z<<'\n'
#define rep(i,n) for(int i=0;i<(n);++i)
#define repA(i,a,n) for(int i=a;i<=(n);++i)
#define repD(i,a,n) for(int i=a;i>=(n);--i)
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define CN cout<<"NO\n"
#define CY cout<<"YES\n"

using namespace std;
using ll = long long;
ll gcd(ll a, ll b) 
{ 
    if (b == 0) 
        return a; 
    return gcd(b, a % b);  
      
} 
// #define MAXN 1000001 
// ll sieve[MAXN]; 
// void makesieve()
// {
//     sieve[1] = 1; 
//     for (int i = 2; i < MAXN; i++) 
//         sieve[i] = i; 
//     for (int i = 4; i < MAXN; i += 2) 
//         sieve[i] = 2; 
//     for (int i = 3; i * i < MAXN; i++) { 
//         if (sieve[i] == i) { 
//             for (int j = i * i; j < MAXN; j += i) 
//                 if (sieve[j] == j) 
//                     sieve[j] = i; 
//         } 
//     } 
// }
ll powerflow(ll x, ll n)
{
    ll res;
    if (n == 0) {
        return 1;
    }
    res = powerflow(x, n-1);             // recurse
    if(INT_MAX / res < x) {          // check for overflow
        return -1; //LONG_MAX;
    }
    return x * res;
}
struct compare  
 {  
   bool operator()(const int& l, const int& r)  
   {  
       return l > r;  
   }  
 };
void solve()
{
    int x; cin>>x;
    cout<<1-x;
}
int main()
{
    crap;
    #ifndef ONLINE_JUDGE
        freopen("input.txt","r", stdin) ;
        freopen("output.txt","w", stdout) ;
        freopen("error.txt","w", stderr) ;
    #endif
    int t;t=1;
    //cin>>t;
    while(t--)
        {solve();}
    return 0;
}

Measured memory_bytes: 3604
n, m = map(int, input().strip().split())
d = [i for i in map(int, input().strip().split())]
assert len(d) == m

cands = sorted(d)
data = [i for i in range(n+1)]

for c in cands:
    for i in range(n+1):
        if i + c <= n and data[i+c] > data[i] + 1:
            data[i+c] = data[i] + 1
print(data[-1])



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

#define ll long long
#define pi pair<int,int>
#define x first
#define y second

#define in ({ll x=0;int o=0,c=getchar();for(;!isdigit(c);c=getchar()) o=c=='-';for(;isdigit(c);c=getchar()) x=x*10+c-'0';o?-x:x;})
#define inchar ({char c=getchar();while(c==' '||c=='\n') c=getchar();c;})
#define instring ({string s;char c=getchar();for(;c==' '||c=='\n';c=getchar());for(;c==' '||c=='\n';c=getchar()) s+=c;s;})

#define FOR(i,a,b) for(auto i=a,b2=b;i<=b2;i++)
#define ROF(i,a,b) for(auto i=b,a2=a;a2<=i;i--)
#define rr(x) " "<<#x<<'='<<x<<" "

#define bit(x,i) ((x>>(i-1))&1ll)
#define on(x,i) (x|(1ll<<(i-1)))
#define off(x,i) (x&~(1ll<<(i-1)))
#define bitnum(x) __builtin_popcountll(x)
#define bitl(x) (64-__builtin_clzll(x))
#define pw2(x) (1<<x)

#define VEC(i,a) for(auto&i:a)
#define pb push_back
#define vall(a) a.begin(),a.end()
#define fiv(a) (int)a.size()-1

#define false(x) if(!(x))
#define middle(a,b) (a+(b-(a))/2)
#define Min(a,b) ({bool o=false;auto b2=b;if(a>b2) {a=b2;o=true;};o;})
#define Max(a,b) ({bool o=false;auto b2=b;if(a<b2) {a=b2;o=true;};o;})
////////////////////////////////////////// HUX
const int N=1e6+5,MOD=998244353;
int n;
int a[N];
ll f[N],res;


ll POW(ll x,int y)
{
    ll res=1;
    for(;y>0;y>>=1,x=(x*x)%MOD) if(y&1) res=(res*x)%MOD;
    return res;
}
void SOLVE(int x)
{
    ll sum=0;
    for(int i=x;i<=1000000;i+=x) FOR(__,1,a[i])
    {
        f[x]+=sum*i%MOD;
        sum+=i;
    }
    for(int i=2*x;i<=1000000;i+=x) f[x]=(f[x]-f[i])%MOD;f[x]=(f[x]+MOD)%MOD;
    res+=f[x]*POW(x,MOD-2)%MOD;
    res%=MOD;
}
main()
{
    //freopen("hx.inp","r",stdin);
    n=in;
    //FOR(i,1,n) a[i]=in;
    FOR(i,1,n) a[in]++;
    ROF(i,1,1000000) SOLVE(i);
    cout<<res;
}


Measured memory_bytes: 11904
n,m = map(int, input().split())
s = input()
t = input()

def lcd(n, m):
    # 最大公約数
    a = max(n,m)
    b = min(n,m)
    while b:
        a, b = b, a % b
    return n*m//a

l = lcd(n,m)
m1 = l//m
n1 = l//n

for i in range(n*m//l):
    a = m1*i 
    b = n1*i 
    if s[a] != t[b]:
        print(-1)
        exit()
print(l)

Measured memory_bytes: 39664
def digitsum(n):
	s = 0
	while n > 0:
		s += n % 10
		n = n // 10
	return s

N = int(input())
m = N
for A in range(1,N):
	B = N - A
	m = min(m, digitsum(A) + digitsum(B))

print(m)



Measured memory_bytes: 2940
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cassert>
#include<cmath>
#include<vector>
#include<map>
#include<set>
#include<string>
#include<queue>
#include<stack>
using namespace std;
#define MOD 1000000007
#define MOD2 998244353
#define INF ((1<<30)-1)
#define LINF (1LL<<60)
#define EPS (1e-10)
typedef long long Int;
typedef pair<Int, Int> P;

Int a[3300];
Int dp[3300][3300];
Int n;

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

    for(int width = 1;width <= n;width++){
        for(int l = 0;l + width <= n;l++){
            int r = l + width;
            if(width % 2 == n % 2){//tarou
                dp[l][r] = max(dp[l+1][r] + a[l], dp[l][r-1] + a[r-1]);
            }
            else{//jirou
                dp[l][r] = min(dp[l+1][r] - a[l], dp[l][r-1] - a[r-1]);
            }
        }
    }

    cout << dp[0][n] << endl;
    
    return 0;
}

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

const int N = 100000;

int n, m, a[N];
int main()
{
    scanf("%d%d", &n, &m);
    for (int i = 0; i < n; ++ i) {
        scanf("%d", a + i);
    }
    int result = INT_MAX;
    for (int i = 0; i + m <= n; ++ i) {
        int L = std::max(-a[i], 0);
        int R = std::max(a[i + m - 1], 0);
        result = std::min(result, L + R + std::min(L, R));
    }
    printf("%d\n", result);
}

Measured memory_bytes: 640
#include<bits/stdc++.h>
#define range(i,a,b) for(int i = (a); i < (b); i++)
#define rep(i,b) for(int i = 0; i < (b); i++)
#define all(a) (a).begin(), (a).end()
#define show(x)  cerr << #x << " = " << (x) << endl;
//const int INF = 1e8;
using namespace std;

map<pair<int, int>, int> m;

int main(){
	long long h, w, n;
	cin >> h >> w >> n;

	rep(i,n){
		int x, y;
		cin >> y >> x;
		x--; y--;
		rep(i,3){
			rep(j,3){
				m[make_pair(x - i, y - j)]++;
			}
		}
	}

	vector<long long> ans(10,0);
	for(auto i : m){
		pair<int, int> c;
		int b;
		tie(c,b) = i;

		if(c.first < 0 or c.second < 0 or c.first >= w - 2 or c.second >= h - 2) continue;
		ans[b]++;
	}

	ans[0] = (w - 2) * (h - 2) - accumulate(all(ans),0LL);
	for(auto i : ans){
		cout << i << endl;
	}
}


Measured memory_bytes: 56448
#include <bits/stdc++.h>
#define N 20
#define ll long long
#define lson l,mid,o<<1
#define rson mid+1,r,o<<1|1
#define Ls(o) t[o].ls
#define Rs(o) t[o].rs
#define For(i,x,y) for(int i=(x);i<=(y);++i)
#define Rof(i,x,y) for(int i=(x);i>=(y);--i)
#define Edge(x) for(int i=head[x];i;i=e[i].nxt)
#define mcpy(x,y) memcpy(x,y,sizeof(x))
#define mset(x,y) memset(x,y,sizeof(x))
using namespace std;
int ans=1e9,t,n,m,fa[N],a[N][N],_;
vector<int> g[N];
bool vis[N],use[N*N],p[N][N];
struct ed{ int u,v,w; }e[N*N],tmp[N*N];
void dfs(int x,int f){
	fa[x]=f;
	for(auto to:g[x]) if(to!=f) dfs(to,x);
}
bool cmp(const ed &x,const ed &y){ return x.w>y.w; }
void dfs2(int rt,int x,int f,int cnt){
	if(cnt<=1 && ~a[x][rt] && !p[x][rt] && !(vis[x] && vis[rt]) && f!=rt) _+=a[x][rt];
	for(auto to:g[x]) if(to!=f) dfs2(rt,to,x,cnt+vis[to]);
}
int find(int x){ return x==fa[x]?x:fa[x]=find(fa[x]); }
int solve(){
	int tot=0;_=0;
	For(i,1,n) fa[i]=i,vis[i]=0;
	For(i,1,n) For(j,1,n) p[i][j]=0;
	For(i,1,m) use[i]=0;
	For(i,1,m){
		int u=find(tmp[i].u),v=find(tmp[i].v);
		if(u==v) continue;
		if(u>v) swap(u,v);fa[v]=u;
		tot+=tmp[i].w,use[i]=1,p[tmp[i].u][tmp[i].v]=p[tmp[i].v][tmp[i].u]=1;
	}
	For(i,1,n) g[i].clear();
	For(i,1,m) if(use[i]) g[tmp[i].u].push_back(tmp[i].v),g[tmp[i].v].push_back(tmp[i].u);
	For(i,1,n) fa[i]=0;
	dfs(1,0);
	for(int i=n;i;i=fa[i]) vis[i]=1;
	For(i,1,n) dfs2(i,i,0,vis[i]);
	tot+=_/2;
	return tot;
}
void Rand(){
	random_shuffle(tmp+1,tmp+m+1);
	ans=max(ans,solve());	
}
int main(){
	int qwq=0,u,v,w;
	srand(20000000);srand(rand());srand(rand());
	scanf("%d%d",&n,&m);
	mset(a,-1);
	For(i,1,m){
		scanf("%d%d%d",&u,&v,&w);
		e[i]=(ed){u,v,w},qwq+=w,a[u][v]=a[v][u]=w;
		tmp[i]=e[i],g[u].push_back(v),g[v].push_back(u);
	}
	sort(e+1,e+m+1,cmp);
	For(i,1,m) tmp[i]=e[i];
	ans=solve();
	For(i,1,500500) Rand();
	printf("%d\n",qwq-ans);
}

Measured memory_bytes: 256
#define  _CRT_SECURE_NO_WARNINGS
#include <vector>
#include <string>
#include <iostream>
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <map>
#include <set>
#include <string.h>
#include <queue>
#include <functional>
#include <utility>
using namespace std;
signed main() {
	int n;
	long long tmp,past=0, ans=0;
	cin >> n;
	for (int i = 1; i <= n; i++) {
		cin >> tmp;
		if (past == 1) {
			if (tmp == 0) {
				ans -= 1; past = 0;
				continue;
			}
			else {
				tmp -= 1;
			}
		}
		if (tmp % 2 == 0) {
			ans += tmp / 2; past = 0;
		}
		else { ans += tmp / 2 + 1; past = 1; }
	}
	if (past == 1)ans -= 1;
	cout << ans;

}

Measured memory_bytes: 256
array = []
while 1:
    n = input()
    if n == "0 0":
        break
    array.append(n.split())
for i in range(len(array)):
    if int(array[i][0]) > int(array[i][1]):
        print(array[i][1]+" "+array[i][0])
    else:
        print(array[i][0]+" "+array[i][1])

Measured memory_bytes: 8188
#include <limits.h>
#include <algorithm>
#include <bitset>
#include <cctype>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>

#define int long long
#define REP(i, n) for (int i = 0, i##_len = (n); i < i##_len; ++i)
#define REPS(i, n) for (int i = 1, i##_len = (n); i <= i##_len; ++i)
#define FOR(i, a, b) for (int i = (a), i##_len = (b); i <= i##_len; ++i)
#define REV(i, a, b) for (int i = (a); i >= (b); --i)
#define CLR(a, b) memset((a), (b), sizeof(a))
#define DUMP(x) cout << #x << " = " << (x) << endl;
#define INF (LLONG_MAX - 1e5)
#define fcout cout << fixed << setprecision(10)

using namespace std;

int N, A[300000];

signed main() {
    ios::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);

    cin >> N;
    REP(i, N) {
        int a;
        cin >> a;
        A[a] = i;
    }

    set<int> s;
    s.insert(-1);
    s.insert(N);

    int ans = 0;
    FOR(i, 1, N)
    {
        int t = A[i];
        auto itr = s.upper_bound(t);
        int high = *itr;
        int low = *(--itr);

        ans += i * (high - t) * (t-low);
        s.insert(t);
    }
    cout << ans << endl;


    return 0;
}


Measured memory_bytes: 11264