akhauriyash/Code-Regression huggingface dataset:
#[allow(unused_macros)]
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

#[allow(unused_macros)]
macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

    ($next:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };

    ($next:expr, mut $var:ident : $t:tt $($r:tt)*) => {
        let mut $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
}

#[allow(unused_macros)]
macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };

    ($next:expr, [ $t:tt ]) => {
        {
            let len = read_value!($next, usize);
            (0..len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
        }
    };

    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };

    ($next:expr, bytes) => {
        read_value!($next, String).into_bytes()
    };

    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
    };

    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}

fn main() {
    input! {
        c: [[usize; 3]; 3],
    }
    for a1 in 0..c[0][0] + 1 {
        let b1 = c[0][0] - a1;
        for a2 in 0..c[1][1] + 1 {
            let b2 = c[1][1] - a2;
            if a1 + b2 != c[0][1] || a2 + b1 != c[1][0] {
                continue;
            }
            for a3 in 0..c[2][2] + 1 {
                let b3 = c[2][2] - a3;
                if a1 + b3 != c[0][2] || a3 + b1 != c[2][0] {
                    continue;
                }
                if a2 + b3 != c[1][2] || a3 + b2 != c[2][1] {
                    continue;
                }
                println!("Yes");
                return;
            }
        }
    }
    println!("No");
}


Measured memory_bytes: 4352
// C++ includes used for precompiling -*- C++ -*-

// Copyright (C) 2003-2013 Free Software Foundation, Inc.
//
// This file is part of the GNU ISO C++ Library.  This library is free
// software; you can redistribute it and/or modify it under the
// terms of the GNU General Public License as published by the
// Free Software Foundation; either version 3, or (at your option)
// any later version.

// This library is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
// GNU General Public License for more details.

// Under Section 7 of GPL version 3, you are granted additional
// permissions described in the GCC Runtime Library Exception, version
// 3.1, as published by the Free Software Foundation.

// You should have received a copy of the GNU General Public License and
// a copy of the GCC Runtime Library Exception along with this program;
// see the files COPYING3 and COPYING.RUNTIME respectively.  If not, see
// <http://www.gnu.org/licenses/>.

/** @file stdc++.h
 *  This is an implementation file for a precompiled header.
 */

// 17.4.1.2 Headers

// C
#ifndef _GLIBCXX_NO_ASSERT
#include <cassert>
#endif
#include <cctype>
#include <cerrno>
#include <cfloat>
#include <ciso646>
#include <climits>
#include <clocale>
#include <cmath>
#include <csetjmp>
#include <csignal>
#include <cstdarg>
#include <cstddef>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>

#if __cplusplus >= 201103L
#include <ccomplex>
#include <cfenv>
#include <cinttypes>
#include <cstdbool>
#include <cstdint>
#include <ctgmath>
#include <cwchar>
#include <cwctype>
#endif

// C++
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>

#if __cplusplus >= 201103L
#include <array>
#include <atomic>
#include <chrono>
#include <condition_variable>
#include <forward_list>
#include <future>
#include <initializer_list>
#include <mutex>
#include <random>
#include <ratio>
#include <regex>
#include <scoped_allocator>
#include <system_error>
#include <thread>
#include <tuple>
#include <typeindex>
#include <type_traits>
#include <unordered_map>
#include <unordered_set>
#endif

/*全てのライブラリをインクルード*/
#define rep(i, n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
using P = pair<int, int>;

int main()
{
    ll a,b,c,d;
    cin>>a>>b>>c>>d;
    ll size1=a*b;
    ll size2=c*d;
    cout<<(size1>size2?size1:size2)<<endl;
    return 0;
}

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

const long long MOD = 1e9+7;

long long dfs(int k, const vector<vector<int>>&graph, int now, int from) {

    int can_use_color_num;
    if (from == -1) {
        can_use_color_num = k - 1;
    }
    else {
        can_use_color_num = k - 2;
    }

    if (k < graph[now].size()) {
        return 0;
    }
    else {
        long long case_num = 1;
        for (auto e :graph[now]) {
            if (e == from) continue;

            case_num *= can_use_color_num;
            can_use_color_num--;
            case_num %= MOD;
        }
        for (auto e :graph[now]) {
            if (e == from) continue;

            case_num *= dfs(k, graph, e, now);
            case_num %= MOD;
        }
        return case_num;
    }
}

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

    vector<vector<int>> graph(n);
    for (int i = 0; i < n - 1; i++) {
        int a, b;
        cin >> a >> b;
        a--;
        b--;

        graph[a].push_back(b);
        graph[b].push_back(a);
    }

    long long ans = k * dfs(k, graph, 0, -1);

    cout << (ans % MOD) << endl;
    return 0;
}

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

int main(){
  string s, t;
  cin >> s >> t;
  int ans = 0;
  for(int i = 0; i < 3; i++){
   	if(s[i] == t[i]) ans++; 
  }
  cout << ans << '\n';
}

Measured memory_bytes: 256
#include<stdio.h>
#include<algorithm>
using namespace std;
int main()
{
	int k,x;
	scanf("%d%d",&k,&x);
	for(int i=x-k+1;i<=x+k-1;i++)
	{
		if(i==x-k+1)
		{
			printf("%d",i);
		}
		else printf(" %d",i);
	}
	 printf("\n");
	return 0;
}

Measured memory_bytes: 128
#include<iostream>
#include<string>
#include<vector>
#include<queue>
#include<map>
#include<algorithm>
#include<unordered_map>
#include<set>
#include<cmath>
#include<stack>
#include<iomanip>
#include<cstdio>
using namespace std;
int isHuiwen(string s,int start,int end)
{
    //int len=s.length(),fin=len-1,use=len/2;
    int fin=end,use=(end+1)/2;
    
    for(int i = 0;i<use;i++,fin--)
    {
        if(s.at(i)!=s.at(fin))
            return 0;
    }
           return 1;
}
int main()
{
    double l,ans,max=-1.0;
    string s;
    cin>>l;
    l=l/3;
    max=l*l*l;
    cout<<fixed<<setprecision(10)<<max<<endl;
    return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
#include<string.h>
#include<math.h>
#include<iostream>
#include<algorithm>
#include<queue>
using namespace std;
int a[1000000];
long long sum[1000000];
bool vis[1000000];
int main()
{
    int n,m;
    scanf("%d%d",&n,&m);
    memset(vis,0,sizeof(vis));
    memset(a,0,sizeof(a));
    for(int i=1;i<=m;i++)
    {
        scanf("%d",&a[i]);
        vis[a[i]]=1;
    }
    if(vis[1]==1)
        sum[1]=0;
    else
        sum[1]=1;
    if(vis[2]==1)
        sum[2]=0;
    else
        sum[2]=sum[1]+1;
    for(int i=3;i<=n;i++)
    {
        if(vis[i-1]==0&&vis[i-2]==0)
            sum[i]=sum[i-1]%1000000007+sum[i-2]%1000000007;
        if(vis[i-1]==1&&vis[i-2]==0)
            sum[i]=sum[i-2]%1000000007;
        if(vis[i-1]==0&&vis[i-2]==1)
            sum[i]=sum[i-1]%1000000007;
        if(vis[i-1]==1&&vis[i-2]==1)
        {
            sum[n]==0;
            break;
        }
    }
    printf("%lld",sum[n]%1000000007);
        return 0;
}


Measured memory_bytes: 6528
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rrep(i, n) for (int i = (int)(n - 1); i >= 0; i--)
#define all(x) (x).begin(), (x).end()
#define sz(x) int(x.size())
#define get_unique(x) x.erase(unique(all(x)), x.end());
typedef long long ll;
typedef complex<double> Complex;
const int INF = 1e9;
const ll MOD = 1e9 + 7;
const ll LINF = 1e18;
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;
}
template <class T>
vector<T> make_vec(size_t a) {
    return vector<T>(a);
}
template <class T, class... Ts>
auto make_vec(size_t a, Ts... ts) {
    return vector<decltype(make_vec<T>(ts...))>(a, make_vec<T>(ts...));
}
int main() {
    int n, W;
    cin >> n >> W;
    vector<int> v(n), w(n);
    rep(i, n) cin >> v[i] >> w[i];

    auto dp = make_vec<int>(n + 10, W + 10);
    int ans = 0;
    rep(i, n) {
        rep(j, W + 1) {
            if (j - w[i] >= 0) chmax(dp[i + 1][j], dp[i][j - w[i]] + v[i]);
            chmax(dp[i + 1][j], dp[i][j]);
            chmax(ans, dp[n][j]);
        }
    }
    cout << ans << endl;
}


Measured memory_bytes: 7012
#include<bits/stdc++.h>
using namespace std;
//#define int long long
#define fo(a,b) for(int a=0;a<b;a++)
#define Sort(a) sort(a.begin(),a.end())
#define rev(a) reverse(a.begin(),a.end())
#define fi first
#define se second
#define co(a) cout<<a<<endl
#define sz size()
#define bgn begin()
#define en end()
#define pb(a) push_back(a)
#define pop pop_back
#define V vector
#define P pair
#define V2(a,b,c) V<V<int>> a(b,V<int>(c))
#define V2a(a,b,c,d) V<V<int>> a(b,V<int>(c,d))
#define incin(a) int a; cin>>a
//#define min min<int>
//#define max max<int>
template<class T>
 void cou(vector<vector<T>> a){
  int b=a.size();
  int c=a[0].size();
  fo(i,b){
    fo(j,c){
      cout<<a[i][j];
      if(j==c-1)
        cout<<endl;
      else
        cout<<' ';
    }
  }
}
/*template<>
 void cou(vector<vector<char>> a){
  int b=a.size();
  int c=a[0].size();
  fo(i,b){
    fo(j,c){
      cout<<a[i][j];
      if(j==c-1)
        cout<<endl;
      else
        cout<<' ';
    }
  }
}*/
 int wari(int a,int b) {
   if(a%b==0)
     return a/b;
   else
     return a/b+1;
 }
 int keta(int a){
  double b=a;
  b=log10(b);
  int c=b;
  return c+1;
 }
 int souwa(int a){
  return a*(a+1)/2;
 }
 int lcm(int a,int b){
  int d=a,e=b,f;
  if(a<b)
    swap(a,b);
  int c,m=1;
  while(m){
    c=a%b;
    if(c==0){
       f=b;
      m--;
    }
    else{
      a=b;
      b=c;
 }
  }
  return d*e/f;
    }
  int gcm(int a,int b){
      int d=a,e=b,f;
  if(a<b)
    swap(a,b);
  int c,m=1;
  while(m){
    c=a%b;
    if(c==0){
       f=b;
      m--;
    }
    else{
      a=b;
      b=c;
 }
  }
  return f;
  }
 bool prime(int a){
   if(a<2)
     return false;
   else if(a==2)
     return true;
   else if(a%2==0)
     return false;
   double b=sqrt(a);
    for(int i=3;i<=b;i+=2){
      if(a%i==0){
        return false;
      }
    }
   return true;
 }
struct Union{
  vector<int> par;
  Union(int n){
	par= vector<int>(n, -1);
  }
  int find(int x){
    if(par[x]<0)
      return x;
    else
      return par[x]=find(par[x]);
  }
  bool same(int a,int b){
    return find(a)==find(b);
  }
  int Size(int a){
    return -par[find(a)];
  }
  void unite(int a,int b){
    a=find(a);
    b=find(b);
    if(a==b)
      return;
    if(Size(b)>Size(a))
      swap<int>(a,b);
    par[a]+=par[b];
    par[b]=a;
  }
};
int ketas(int a){
  string b=to_string(a);
  int c=0;
  fo(i,keta(a)){
    c+=b[i]-'0';
  }
  return c;
}
/*struct aa{
	vector<int> gt;
  aa(int n){
	gt= vector<int>(n, 1);
  }
	void c(V<int> d,int b){
	if(d[b]==0){
		gt[d[b]-1]++;
		gt[gt.sz-1]++;
	}
	else{
		gt[d[b]-1]++;
		c(d,d[d[b]]-1);
	}
}
void cok(int a){
	cout<<gt[a-1]<<endl;
	fo(i,a-1)
	cout<<gt[i]<<endl;
}
};
*/
signed main(){
	int a,b;
	cin>>a>>b;
	if(a%b==0)
		cout<<-1<<endl;
	else
		cout<<a<<endl;
}

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

int main() {
  int r, c;
  cin >> r >> c;
  
  int table[110][110] = {};
  for (int i = 0; i < r; i++)
    for (int j = 0; j < c; j++)
      cin >> table[i][j];

  for (int i = 0; i < r; i++) {
    for (int j = 0; j < c; j++) {
      table[r][j] += table[i][j];
      table[i][c] += table[i][j];
      table[r][c] += table[i][j];
    }
  }

  for (int i = 0; i <= r; i++) {
    for (int j = 0; j <= c; j++) {
      cout << table[i][j];
      if (j < c) cout << " ";
    }
    cout << endl;
  }
  return 0;
}


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



int main() {
	
	
	int l, r, d; cin >> l >> r >> d;
	
	int i;
	int ans = 0;
	//if(l%d == 0) ans++;
	for(i = l; i <= r; i++){
		if(i % d == 0) ans++;
	}
	
	

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


Measured memory_bytes: 3592
import sys
input = sys.stdin.readline
import numpy as np
N = int(input())
a = [int(x) for x in input().split()]
import collections
c = collections.Counter(a)
ans = 0
for i in c:
    d = c[i] - i
    if d < 0:
        ans += c[i]
    else:
        ans += d
print(ans)
    

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

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);

		int N = sc.nextInt();
		ArrayList<Integer> list = new ArrayList<Integer>();

		for(int i = 0; i < N; i++) {
			list.add(sc.nextInt());
		}

		int count = 0;
		for(int i=0; i<list.size(); i++) {
			int love = list.get(i);
			if((i + 1) == (list.get(love - 1))) count++;
		}

		System.out.println(count/2);
	}
}

Measured memory_bytes: 48280
#include <bits/stdc++.h>
#define REP(i, n) for(long long i = 0; i < n; i++)
#define REPR(i, n) for(long long i = n - 1; i >= 0; i--)
#define FOR(i, m, n) for(long long i = m; i <= n; i++)
#define FORR(i, m, n) for(long long i = m; i >= n; i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define VSORTR(v) sort(v.rbegin(), v.rend());
#define ALL(v) (v).begin(),(v).end()
#define FIN ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
using namespace std;
using ll = long long;
using vll = vector<ll>;
using vvll = vector<vector<ll>>;
using P = pair<ll, ll>;
const ll mod = 1e9+7;



int main(){FIN

    ll n; cin>>n;
    vll a(n); REP(i,n) cin>>a[i];
    vll l(n); vll r(n);
    l[0] = a[0]; r[0] = a[n-1];
    REP(i,n-1){
        l[i+1] = __gcd(l[i], a[i+1]);
        r[i+1] = __gcd(r[i], a[n-2-i]);
    }
    ll ans = 0;
    ll gcd=0;
    REP(i,n){
        if(i==0) gcd = r[n-2];
        else if (i==n-1) gcd = l[n-2];
        else gcd = __gcd(l[i-1], r[n-2-i]);
        ans = max(ans, gcd);
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 2560
#include <cstdio>

int main()
{
    int N;

    scanf("%d", &N);

    for (int i = 1; i <= 9; ++i)
    {
        int result = (N / i);
        if ((result < 10) && (result * i == N))
        {
            printf("Yes\n");
            return 0;
        }
    }

    printf("No\n");
    return 0;
}


Measured memory_bytes: 888
#include <iostream>
#include <vector>
#include <utility>
#include <map>
#include <algorithm>
#include <queue>
#include <cmath>

using namespace std;

int main() {
  string S, T;
  cin >> S >> T;
  std::vector<int> start(26, -1);
  std::vector<int> goal(26, -1);
  for (int i = 0; i < S.size(); i++){
    int a = S[i] - 'a';
    int b = T[i] - 'a';

    if (start[a] != -1 || goal[b] != -1){
      if (start[a] != b || goal[b] != a){
        cout << "No" << endl;
        return 0;
      }
    } else {
      start[a] = b;
      goal[b] = a;
    }
  }
  cout << "Yes" << endl;
}


Measured memory_bytes: 776
n, m = map(int, input().split())
if n % 2 != 0:
    for i in range(m):
        print(i + 1, n - i)
else:
    for i in range(m):
        if i < m / 2:
            print(i + 1, n - i)
        else:
            print(i + 1, n - i - 1)


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

long long n, w;

int values[110], weights[110];

int sDP[101][100][101];

int saved;

int dp(short index, int weight, int cnt) {
	int &ret = sDP[index][weight][cnt];
	if (ret != -1) return ret;
	
	if (index == n-1) {
		weight += weights[index];
		cnt++;
		if (weight + cnt*saved > w) {
			return ret = 0;
		} else {
			return ret = values[index];
		}
	}
	
	ret = dp(index+1, weight, cnt);
	if (weight + weights[index] + (cnt+1)*saved <= w) {
		ret = max(ret, dp(index+1, weight + weights[index], cnt+1) + values[index]);
	}
	
	return ret;
}

int main() {
	memset(sDP, -1, sizeof(sDP));
	
	cin >> n >> w;
	cin >> weights[0] >> values[0];
	saved = weights[0];
	weights[0] = 0;
	for (int i = 1; i < n; i++) {
		cin >> weights[i] >> values[i];
		weights[i] -= saved;
	}
	cout << dp(0, 0, 0);
}

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

int wd[26][26];
bool done[26];

int st[26] = {0} , en[26] = {0};

int dfs(int pos){
	done[pos] = true;
	rep(v, 26) if ( !done[v] && wd[pos][v] ) dfs(v);
}
bool wrap(){
	int nc = 0;
	bool f = false;
	rep(i,26)done[i] = 0;
	rep(i, 26){
		if(!st[i] && !en[i])continue;
		if ( !done[i] ){
			if(f)return false;
			else f = true;
			dfs(i);
		}
	}
	return true;
}


int main(){
	int n;
	
	while(cin >> n , n){
		rep(i,26)rep(j,26)wd[i][j] = 0;
		rep(i,26)st[i] = en[i] = 0;
		bool f = true;
		rep(i,n){
			string in; cin >> in;
			st[in[0]-'a']++;
			en[in[in.size()-1]-'a']++;
			wd[in[0]-'a'][in[in.size()-1]-'a'] = 1;
		}
		rep(i,26)f &= st[i] == en[i];
		
		
		
		cout << (f && wrap()?"OK":"NG") << endl;
	}
}

Measured memory_bytes: 912
#include<iostream>
#include<cstdio>
#include<algorithm>
using namespace std;
int N, M;
int P[1001];
int PP[1002001];
int ans=0;
int main()
{
	while (true){
		ans = 0;
		scanf("%d%d", &N, &M);
		if (N == 0 && M == 0)break;
		for (int i = 0; i < N; i++)scanf("%d", &P[i]);
		P[N] = 0;
		for (int i = 0; i <= N; i++)for (int j = 0; j <= N; j++)PP[i*(N + 1) + j] = P[i] + P[j];
		sort(PP, PP + (N + 1)*(N + 1));
		int l = 0, r = (N + 1)*(N + 1) - 1;
		while (r >= l){
			int sum = PP[l] + PP[r];
			if (sum <= M){
				ans = max(ans, sum);
				l++;
			}
			else r--;

		}
		printf("%d\n", ans);
	}
	return 0;
}

Measured memory_bytes: 5120
#include "bits/stdc++.h"
#include "math.h"
 
using namespace std;
typedef long long ll;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef vector<bool> vb;
typedef vector<vb> vvb;
typedef vector<int> vin;
typedef vector<pair<ll,ll> > vp;
#define rep(i,a,b) for(ll i=(a);i<(b);++i)
const int MOD = 1000000007;
const int MAX = 510000;

int main(){
  ll x,ans;cin>>x;
  ans=(x/11)*2;
  if(x%11>=7){ans+=2;}
  else if(x%11>0){ans++;}
  cout<<ans<<endl;
}



Measured memory_bytes: 256
#include <stdio.h>

int isprime(int n){
  int i;

  if(n == 1 || (n != 2 && !(n%2))){
    return 0;
  }

  for(i = 3;i*i <= n;i += 2){
    if(!(n%i)){
      return 0;
    }
  }

  return 1;
}

int main(){
  int N,cnt,i;

  while(scanf("%d",&N) != EOF){
    cnt = 0;
    for(i = 2;i <= N;i++){
      if(isprime(i) && isprime(N-i+1)){
        cnt++;
      }
    }
    printf("%d\n",cnt);
  }

  return 0;
}

Measured memory_bytes: 596
long a[3][1<<18],b,c,x,y,N[1<<18],M[1<<18],i,j;main(n){scanf("%d",&n);for(i=0;i<3;++i)for(j=0;j<n;++j){scanf("%d",&a[i][j]);--a[i][j];}for(i=0;i<n;++i){if(a[0][i]/3!=a[1][i]/3||a[1][i]/3!=a[2][i]/3||a[2][i]/3!=a[0][i]/3||a[1][i]%3!=1||(a[1][i]/3-i)%2){puts("No");return 0;}x=a[1][i]/3+1;while(x){if(i&1)c-=M[x];else b-=N[x];x-=x&-x;}if(i&1)c+=i/2;else b+=i/2;y=a[2][i]/3+1;while(y<1<<18){if(i&1)++M[y];else++N[y];y+=y&-y;}if(a[0][i]%3){if(i&1)++b;else++c;}}puts((b&1)||(c&1)?"No":"Yes");}

Measured memory_bytes: 5596
#pragma GCC optimize ("O3")
#include<map>
#include<iostream>
#include<deque>
#include<algorithm>
#include<string>
#include<cctype>
#include<iomanip>
#include<vector>
#include<queue>
#include<math.h>
#include<bitset>
#include<random>
#include<set>
using namespace std;
using ll = __int64_t;
using lll = __int128_t;
typedef pair<ll,ll> P;
#define REP(i,b,e) for(ll i=(ll)b;i<(ll)e;i++)
#define rep0(i,n) REP(i,0ll,n)
#define rep1(i,n) REP(i,1ll,n+1)
const ll longinf=1ll<<60;
const int inf=(1<<30)-1;
const ll mod=1e9+7;


int main(){
      int n;
      cin>>n;
      int pow2n=(1<<n);
      multiset<int> notchoose;
      multiset<int> choosed;
      
      rep0(i,pow2n){
            int s;
            cin>>s;
            notchoose.insert(-s);
      }
      notchoose.insert(1);
      auto itr=notchoose.begin();
      choosed.insert(*itr);
      notchoose.erase(itr);
      for(int i=0;i<n;i++){
            int pow2i=(1<<i);
            auto bitr=choosed.begin();
            auto eitr=choosed.end();
            vector<int> horyuu;
            for(auto itr=bitr;itr!=eitr;itr++){
                  ll pos=*itr;
                  auto korosu=notchoose.lower_bound(pos+1);
                  horyuu.push_back(*korosu);
                  notchoose.erase(korosu);
                  if(*korosu>0){
                        cout<<"No"<<endl;
                        return 0;
                  }
            }
        for(auto a:horyuu){
          choosed.insert(a);
        }
      }
      cout<<"Yes"<<endl;

      return 0;
}


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

int main() {
    int N;  cin >> N;
    vector<int> d(N);
    for (int i = 0; i < N; ++i) cin >> d[i];
    int ans = 0;
    for (int i = 0; i < N; ++i) {
        for (int j = i + 1; j < N; ++j) {
            ans += d[i] * d[j];
        }
    }
    cout << ans << endl;
}


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

int main() {
  ios::sync_with_stdio(false), cin.tie(0);
  for (int i = 0; i < 5; i++) {
    int x;
    cin >> x;
    if (x == 0) {
      cout << i + 1 << '\n';
      return 0;
    }
  }
  return 0;
}

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

void solve(){
  long long x; cin >> x;
  long long ans = x/11;
  ans *= 2;
  x%=11;
  if(x == 0)cout << ans << endl;
  else if(x <=6) cout << ans + 1 << endl;
  else cout << ans + 2 << endl;
  
}

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

Measured memory_bytes: 3608
#include<bits/stdc++.h>
//using namespace std;
#define rep(i,j,n) for(ll i=(ll)(j);i<(ll)(n);i++)
#define REP(i,j,n) for(ll i=(ll)(j);i<=(ll)(n);i++)
#define per(i,j,n) for(ll i=(ll)(j);(ll)(n)<=i;i--)
#define ll long long
#define ALL(a) (a).begin(),(a).end()
#define disup(A,key) distance(A.begin(),upper_bound(ALL(A),(ll)(key)))
#define dislow(A,key) distance(A.begin(),lower_bound(ALL(A),(ll)(key)))
#define pb push_back
#define mp std::make_pair
#define endl "\n"
using std::cin;
using std::cout;
using std::vector;
using std::string;
using std::upper_bound;
using std::lower_bound;
using vi=vector<ll>;
using vii=vector<vi>;
using pii=std::pair<ll,ll>;
//const ll MOD=1e9+7;
const ll MOD=998244353;
//const ll MOD=100000;
const ll MAX=1e7;
const ll INF=(1ll<<60);
template<class T>
class prique :public std::priority_queue<T, std::vector<T>, std::greater<T>> {};
struct Binary_indexed_tree{
    int N;
    vi bit;
    Binary_indexed_tree(int n):N(n){
        bit.resize(N+1,0);
    }
    void add(int x,int a){
        for(x;x<=N;x+=(x&-x)) bit[x]+=a;
    }
    ll sum(int x){
        ll ret=0;
        for(x;x>0;x-=(x&-x)) ret+=bit[x];
        return ret;
    }
};
ll modpow(ll X,ll Y){
    ll sum=X,cnt=1;
    vi A;
    while(cnt<=Y){
        A.pb(sum);
        sum*=sum;
        sum%=MOD;
        cnt*=2;
    }
    int M=A.size();
    ll ret=1;
    REP(i,1,M){
        if(Y>=(1ll<<M-i)){
            Y-=(1ll<<M-i);
            ret*=A[M-i];
            ret%=MOD;
        }
    }
    return ret;
}
ll fac[MAX],finv[MAX],inv[MAX];
/*void COMinit(){
    fac[0]=fac[1]=finv[1]=finv[0]=inv[0]=inv[1]=1;
    rep(i,2,MAX){
        fac[i]=fac[i-1]*i%MOD;
        inv[i]=modpow(i,MOD-2);
        finv[i]=finv[i-1]*inv[i]%MOD;
    }
}*/
void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}
ll COM(ll n,ll r){
    if(n<r||n<0||r<0) return 0;
    return fac[n]*finv[r]%MOD*finv[n-r]%MOD;
}
signed main(){
    COMinit();
    ll N,M; cin>>N>>M;
    ll ans=0;
    REP(i,0,std::min(N,M)){
        if(M%2!=i%2) continue;
        ll sum=COM((3*M-i)/2+N-1,N-1)+MOD*2-i*COM((M-i)/2+N-1,N-1)%MOD-(N-i)*COM((M-i-2)/2+N-1,N-1)%MOD;
        sum%=MOD;
        sum*=COM(N,i);
        sum%=MOD;
        ans+=sum;
        ans%=MOD;
    }
    cout<<ans<<endl;
}


Measured memory_bytes: 234624
fun main(args: Array<String>) {
    val n = readLine()!!.toInt()
    val a = readLine()!!.split(' ').map { it.toInt() }
    val q = readLine()!!.toInt()

    val choice = BooleanArray(n) { false }
    fun chk(m: Int) :Boolean {
        var sum = 0
        for (i in 0 until n) {
            sum += if (choice[i]) a[i] else 0
        }
        return sum == m
    }
    fun select (m: Int, d: Int): Boolean {
        arrayOf(true, false).forEach {
            choice[d] = it
            if (d+1 == n) {
                if(chk(m)) return true
            } else {
                if(select(m,d+1)) return true
            }
        }
        return false
    }

    val m = readLine()!!.split(' ')
    repeat(q) {
        val M = m[it].toInt()
        if (select(M, 0) ) println("yes")
        else println("no")
    }

}




Measured memory_bytes: 98656
#include <bits/stdc++.h>
#define all(a) a.begin(), a.end()
#define db(a) cout << fixed << #a << " = " << a << endl;

using namespace std;

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


int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	ll N;
	cin >> N;
	ll result = 0; 
	ll NN = N;
	for (ll i = 2; i*i <= N; i++) {
		if (NN % i == 0) {
			ll counter = 0;
			ll p = i; 
			while (NN % p == 0) {
				counter++;
				NN /= p;
			}
			for (int j = 1; j < 10000; j++) {
				if (j <= counter) {
					result++;
					counter -= j;
				} else {
					break;
				}
			}
		}
	}
	cout << result + (NN != 1) << endl;
}




Measured memory_bytes: 3636
#include <stdio.h>
int map[4][3]={{1989,1,7},{1926,12,24},{1912,7,29},{1868,9,7}};
char map1[5][10]={"heisei","showa","taisho","meiji","pre-meiji"};
int sign;
void set(int search[]){
    int temp=sign;
    if(map[sign][0]>=search[0]){
        if(map[sign][0]>search[0])
            sign++;
        else if(map[sign][1]>search[1])
            sign++;
        else if(map[sign][1]==search[1] && map[sign][2]>=search[2])
            sign++;
    }
    if(sign==temp || sign==4)
        return;
    else
        set(search);;
}
int main(void){
    int line[3];
    for(;sign=0,scanf("%d %d %d",&line[0],&line[1],&line[2])!=EOF;){
        set(line);
        if(sign==4)
            printf("%s\n",map1[4]);
        else
            printf("%s %d %d %d\n",map1[sign],line[0]-map[sign][0]+1,line[1],line[2]);
    }
    return 0;
}

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

namespace Atcoder
{
    class Program
    {
        static void Main(string[] args)
        {
            var s = ReadLine();

            Console.WriteLine((s == "ABC") ? "ARC" : "ABC");
            ReadLine();
        }

        //最大公約数
        static int gcd(int a, int b)
        {
            if (a > b) {
                return gcd(b, a);
            }

            while (b != 0) {
                var remainder = a % b;
                a = b;
                b = remainder;
            }

            return a;
        }

        //最小公倍数
        static int lcm(int a, int b) => a * b / gcd(a, b);

        /// <summary>
        /// コンビネーション
        /// </summary>
        static int nCm(int n, int m)
        {
            if (m == 0) return 1;
            if (n == 0) return 0;
            return n * nCm(n - 1, m - 1) / m;
        }

        public static string ReadLine() => Console.ReadLine();
        public static int ReadLineInt() => int.Parse(Console.ReadLine());
        public static long ReadLineLongInt() => long.Parse(Console.ReadLine());
        public static string[] ReadLineStringSplit(char a = ' ') => ReadLine().Split(a).ToArray();
        public static int[] ReadLineIntSpilit(char a = ' ') => ReadLine().Split(a).Select(x => int.Parse(x)).ToArray();
        public static long[] ReadLineLongSpilit(char a = ' ') => ReadLine().Split(a).Select(x => long.Parse(x)).ToArray();
        static string[] GetAplhaLowerArray() => new string[] { "a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l", "m", "n", "o", "p", "q", "r", "s", "t", "u", "v", "w", "x", "y", "z" };
        static string[] GetAplhaUpperArray() => new string[] { "A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K", "L", "M", "N", "O", "P", "Q", "R", "S", "T", "U", "V", "W", "X", "Y", "Z" };
    }
}


Measured memory_bytes: 25796
// C++(Clang 10.0.0)

//GCC用 ナゾです
//#pragma GCC target("avx")
//#pragma GCC optimize("O3")
//#pragma GCC optimize("unroll-loops")

#include <iostream>
#include <stdio.h>
#include <stdlib.h> //rand() 0~RAND_MAX2147483647
#include <math.h>
#include <time.h>   //srand((unsigned int)time(NULL));
#include <unistd.h> //sleep
#include <algorithm>
#include <cmath>
#include <vector>
#include <regex> //正規表現
#include <map>
#include <unordered_map>
#include <set>
#include <cassert> //assart(x>=0) -> x<0の時異常終了
#include <numeric>
#include <iterator>
#include <list>
#include <tuple>
#include <queue>

using namespace std;
#define ll long long int
#define FOR(i,min,max) for(ll i=(min);i<(max);i++)
#define FOReq(i,min,max) for(ll i=(min);i<=(max);i++)
#define FORREV(i,max,min) for(ll i=(max)-1;i>=(min);i--)
#define FORREVeq(i,max,min) for(ll i=(max);i>=(min);i--)

#define all(vec) (vec).begin(),(vec).end()

const int MOD=1e9+7;
const int MOD2=998244353;
const int not0=1;
const int INF=2000000001;
const ll INFll=2e18;
//const int MAX_V=10000;
const double  Micro=1e-5;

int UnUsedVariable(){
    if(INF || Micro || MOD || INFll || MOD2 || not0){;}
    return 0;
}

#define inarray(array,min,max) FOR(i,min,max){cin>>array[i];}
#define inarrayW(arrayA,arrayB,min,max) FOR(i,min,max){cin>>arrayA[i]>>arrayB[i];}
#define br printf("\n");
#define OutputAndReturn0(x) {cout<<(x)<<endl;return 0;}
#define elif else if

#define issame(a,b,c,d) ((a)==(b) and (b)==(c) and (c)==(d))
#define isdiff3(a,b,c) ((a)!=(b) and (b)!=(c) and (c)!=(a))
#define isdiff4(a,b,c,d) ((a)!=(b) and (b)!=(c) and (c)!=(a) and (d)!=(a) and (d)!=(b) and (d)!=(c))
#define isdiff5(a,b,c,d,e) ((a)!=(b) and (b)!=(c) and (c)!=(a) and (d)!=(a) and (d)!=(b) and (d)!=(c) and (e)!=(a) and (e)!=(b) and (e)!=(c) and (e)!=(d))
#define Func3(f,a,b,c) (f)((f)((a),(b)),(c))
#define Func4(f,a,b,c,d) (f)((f)((f)((a),(b)),(c)),(d))

inline int isEven(int x){return x%2==0;}
inline int isOdd (int x){return x%2==1;}
inline ll samepair(ll x){return x*(x-1)/2;}
inline ll  gcd(ll a,ll b){ if(b==0)return a;else return gcd(b,a%b);}//最大公約数 なお一方が0なら答えは他方になるので番兵は０で良い また、負の数もOK -4%3=-1となるため
inline ll  lcm(ll a,ll b){return a*b/gcd(a,b);}//MODやオーバーフローには注意！
//inline ll  ceil(double a){return (ll)a+1;}
//ans = accumulate(A, A+N, 0, [](int a, int b) {return gcd(a,b);});
//auto count = std::count_if(v.begin(), v.end(), [](int x) { return x == 1 || x == 3; } );

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

//累積和　しゃくとり法　木構造　DP キュー　乱択アルゴリズム　嘘解法　ハッシュ　next_permulation

//課題：DP 木構造　Xor

ll probNow(){
    ll ans;ans=0;
    ll N,K;N=0;
    cin>>N>>K;
    OutputAndReturn0(min(N%K,K-N%K));
    return 0;
}

signed main(){
    cin.tie(0);    //cinとcoutの結び付き解除（cout時にcinの内容を吐き出さなくなる）
    ios::sync_with_stdio(false);  //coutとprintfの結び付き解除（coutとprintfを同時に使うな！）
    probNow();
    return 0;
}


Measured memory_bytes: 256
s = input()

txt = "abcdefghijklmnopqrstuvwxyz"

if(s[0] != "A"):
    print("WA")
    exit()

if((s[1] in txt) == False):
    print("WA")
    exit()

count = 0
for i in s[2:-1]:
    if(i == "C"): count += 1
    elif((i in txt) == False):
        print("WA")
        exit()
if(count != 1):
    print("WA")
    exit()

if((s[-1] in txt) == False):
    print("WA")
    exit()

print("AC")

Measured memory_bytes: 3064
n, m, x, y = gets.split(" ").map(&:to_i)
ary_x = gets.split(" ").map(&:to_i)
ary_y = gets.split(" ").map(&:to_i)

if ary_x.max < ary_y.min
    if ((ary_x.max+1..ary_y.min).to_a & (x+1..y).to_a).size >= 1
        puts "No War"
    else
        puts "War"
    end
else
    puts "War"
end


Measured memory_bytes: 1788
<?php
fscanf(STDIN, "%d", $n);
fscanf(STDIN, "%s %s", $s, $t);
$splited_s = str_split($s);
$splited_t = str_split($t);

for ($i=0; $i<$n; $i++) {
  echo $splited_s[$i].$splited_t[$i];
}

Measured memory_bytes: 4604
#include<algorithm>
#include <iostream>
#include<cstdio>
#include<cmath>
#include<iomanip>
#include<string>
#include<cstdlib>
#include<ctime>
#include<vector>
using namespace std;

int main(){


   int a,b,c;
   cin>>a>>b>>c;

   if(a==b){
       if(a==c){
           cout<<"No"<<endl;
           return 0;
       }else{
           cout<<"Yes"<<endl;
           return 0;
       }
   }
   if(b==c){
       cout<<"Yes"<<endl;
       return 0;
   }
   if(c==a){
       cout<<"Yes"<<endl;
       return 0;
   }
   cout<<"No"<<endl;


return 0;
}

Measured memory_bytes: 256
def main():
    s = list(input())
    n = len(s)
    res = [1]*n
    for i in range(n-2):
        # s[i]=='R' and s[i+1]=='L':
        #   continue
        if s[i]=='R' and s[i+1]=='R':
            res[i+2]+=res[i]
            res[i]=0
    for i in range(n-1,1,-1):
        # s[i]=='L' and s[i-1]=='R':
        #   continue
        if s[i]=='L' and s[i-1]=='L':
            res[i-2]+=res[i]
            res[i]=0
    print(*res)

if __name__ == '__main__':
    main()



Measured memory_bytes: 51064
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<map>
#include<queue>
#include<stack>
#include<cmath>	

using namespace std;

int main() {
	int N;
	cin >> N;
	vector<int> A;
	vector<int> B;
	int maxA = 0;
	for (int i = 0; i < N; ++i) {
		int a;
		cin >> a;
		maxA = max(maxA, a);
		A.push_back(a);
		B.push_back(a);
	}

	sort(B.rbegin(), B.rend());
	for (int i = 0; i < N; ++i) {
		if (A[i] != maxA) {
			cout << B[0] << endl;
		}
		else {
			cout << B[1] << endl;
		}
	}

	return 0;
}

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

int main()
{
 int n;
  cin >> n;
  vector<int> a;
  double ave = 0;
  for (int i = 0;i < n;i++)
  {
   int tmp;
    cin >> tmp;
    a.push_back(tmp);
    ave += tmp;
  }
  ave /= n;
  
  double mn = 1000;
  int idx = 0;
  for (int i = 0; i < n; i++)
  {
    if (abs(ave-a[i]) < mn)
    {
      mn = abs(ave-a[i]);
      idx = i;
    }
  }
  cout << idx << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using vi = vector<int>;
using vvi = vector<vector<int>>;
using vl = vector<ll>;
using vvl = vector<vector<ll>>;
using pl = pair<ll,ll>;
using pi = pair<int,int>;
#define all(x) x.begin(),x.end()
#define rep(i,j,n) for (long long i = j; i < (long long)(n); i++)
#define _GLIBCXX_DEBUG
const ll MOD = 1000000007;
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; }
//(a+b-1)/b
//priority_queue<ll, vector<ll>, greater<ll>> q;

signed main(){
	//cout << fixed << setprecision(10);
    int n; cin >> n;
	ll now = 0;
	map<int,int> mp;
	rep(i,0,n){
		int a; cin >> a;
		now += a;
		mp[a]++;
	}
	int q; cin >> q;
	while(q--){
		int b,c; cin >> b >> c;
		now += (c - b) * mp[b];
		mp[c] += mp[b];
		mp[b] = 0;
		cout << now << endl;
	}

	return 0;
}

Measured memory_bytes: 8032
#include <bits/stdc++.h>
using namespace std;
#define mp make_pair
#define pb push_back
#define re return
typedef vector<int> vi;
typedef long long ll;
typedef pair<int, int> pii;
int n,m;
int p[100010];
int ans;
int find(int id){
	if(p[id]!=id)return p[id]=find(p[id]);
	return id;
}
void con(int id1,int id2){
	int p1=find(id1);
	int p2=find(id2);
	if(p1==p2)return;
	p[p2]=p1;
	ans--;
	return;
}
int main() { 
    //freopen("input.txt","r",stdin);
	//freopen("output.txt","w",stdout);
	int n;
	cin>>n>>m;
	for(int i=1;i<=n;i++){
		p[i]=i;
	}
	int a,b,c;
	ans=n;
	for(int i=0;i<m;i++){
		cin>>a>>b>>c;
		con(a,b);
	}
	cout<<ans<<endl;
    return 0; 
}

Measured memory_bytes: 640
#include <iostream>
#include <cstdio>
#define N 100005
using namespace std;

typedef long long ll;
ll n, b, a[N];

ll abs(ll p) {return p > 0 ? p : -p;}

ll f(ll p) {
	ll i, q = 0, s = 0;
	for (i = 0; i < n; i++, p = -p) {
		q += a[i];
		if (p > 0) {
			if (q <= 0) s += -q + 1, q = 1;
		} else {
			if (q >= 0) s += q + 1, q = -1;
		}
	}
	return s;
}

int main()
{
	ll i;
	cin >> n;
	for (i = 0; i < n; i++) scanf("%lld", &a[i]);
	cout << min(f(1), f(-1));
    return 0;
}

Measured memory_bytes: 1024
k, n = input().split()
k, n = int(k), int(n)
a = input().split()
a = [int(dist) for dist in a]
dMax = a[0]+(k-a[n-1])
for dist in range(1, n-1):
    dMax = max(dMax, a[dist+1]-a[dist])
print(k-dMax)


Measured memory_bytes: 24948
#include<iostream>
#include<vector>
#include<algorithm>
 
using namespace std;
 
int main(){ 
  int N; cin >> N;
  vector<int> X(N);vector<int> Y(N);
   for(int i = 0; i < N; i++){ cin >> X[i] ; Y[i] = X[i]; }
  
  sort(Y.begin(),Y.end());
  
  int y = Y[N/2];
  for(int i = 0; i < N; i++){
    if( X[i] < Y[N/2]){cout << Y[N/2];}
    else{cout << Y[N/2 - 1];}  cout << endl;}return 0;}

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

using namespace std;

int main() {
  string s, t;
  cin >> s >> t;
  int cnt = 0;
  for (int i = 0; i < static_cast<int>(s.size()); ++i)
    cnt += s[i] != t[i];
  cout << cnt << endl;
}

Measured memory_bytes: 3832
#include <iostream>
#include <algorithm>
#include <cstdio>
#include <vector>
#include <math.h>
#include <iomanip>
#include <bitset>
#include <string>
#include <cstring>
#include <stdlib.h>
#include <utility>
#include <set>
#include <queue>
using namespace std;
typedef long long int ll;
typedef long double ld;
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; }
const long long INF = 1LL << 60;
typedef pair<ll,ll> pairs;
vector<pairs> p;
bool pairCompare(const pair<double,ll>& firstElof, const pair<double,ll>& secondElof){
    return firstElof.first < secondElof.first;
}
bool pairCompareSecond(const pair<double,ll>& firstElof, const pair<double,ll>& secondElof){
    return firstElof.second < secondElof.second;
}
#define MAX_N 100100
#define MOD 1000000007
bool x[MAX_N];
ll num[MAX_N];
ll fibl[MAX_N]={0};
// 四方向への移動ベクトル
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};

ll fib(ll a){
    if (fibl[a]!=0)return fibl[a];
    if (a==0){
        return 0;
    }else if (a==1){
        return 1;
    }
    return fibl[a]=fib(a-1)+fib(a-2);
}
 
ll eratosthenes(ll n) {
    int p = 0;
    for (ll i=0; i<=n; ++i) x[i] = true;
    x[0] = x[1] = false;
    for(int i=2; i<=n; ++i) {
        if(x[i]) {
            p++;
            for(int j=2*i; j<=n; j+=i) x[j] = false;
        }
        
        num[i] = p;
    }
    return p;
}
 
ll gcd(ll a,ll b){
    if (a%b==0)return(b);
    else return(gcd(b,a%b));
}
 
ll keta(ll N){
    int tmp{};
    while( N > 0 ){
        tmp += ( N % 10 );
        N /= 10;
    }
    N = tmp;
    return N;
}

int main() {
    string n;
    cin >> n;
    ll a=0;
    for (ll i=0;i<n.size();i++){
        a+=n[i]-'0';
    }
    if (a==1){
        cout << 10 << endl;
    }else{
        cout << a << 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;
typedef long long ll;

vector<ll> solve(ll m){
    vector<ll> ans;
    for(ll i=1L;i*i<m;i++){
        if(m%i==0){
            ans.push_back(i);
            ll j= m/i;
            if(j!=i)ans.push_back(j);
        }
    }
    sort(ans.begin(),ans.end(),greater<ll>());
    return ans;
}
int main(){
    ll n, m;
    cin >> n >> m;
    auto ans = solve(m);
    ll res = 1;
    for(auto d : ans){
        if(d*n <=m) res = max(res,d);
    }
    cout<<res<<endl;
}

Measured memory_bytes: 256
def main():
    n, m = map(int, input().split())
    answer = [-1 for _ in range(n)]
    is_possible = True
    for _ in range(m):
        s, c = map(int, input().split())
        s -= 1
        if is_possible:
            if n <= s:
                is_possible = False
            if answer[s] == -1:
                answer[s] = c
            elif answer[s] != c:
                is_possible = False
    if answer[0] == 0 and 1 < n:
        is_possible = False
    for i in range(n):
        if answer[i] == -1:
            answer[i] = 0 if (0 < i or n < 1) or n == 1 else 1
    print("".join(map(str, answer)) if is_possible else -1)


if __name__ == '__main__':
    main()



Measured memory_bytes: 3064
#include<iostream>
#include<algorithm>
#include<vector>
using namespace std;
int N,A[500],K;
main()
{
	cin>>N>>K;
	int sum=0;
	for(int i=0;i<N;i++)
	{
		cin>>A[i];
		sum+=A[i];
	}
	vector<int>X;
	for(int i=1;i*i<=sum;i++)
	{
		if(sum%i==0)
		{
			X.push_back(i);
			if(sum/i!=i)X.push_back(sum/i);
		}
	}
	int ans=1;
	for(int x:X)
	{
		vector<int>B(N);
		for(int i=0;i<N;i++)B[i]=A[i]%x;
		sort(B.begin(),B.end());
		int T=0;
		for(int i=0;i<N;i++)
		{
			if(T+B[i]<=K)
			{
				T+=B[i];
				B[i]=0;
			}
		}
		for(int i=0;i<N;i++)
		{
			if(B[i]>0)
			{
				if(B[i]+T>=x)
				{
					T-=x-B[i];
					B[i]=0;
				}
			}
		}
		bool flag=true;
		for(int i=0;i<N;i++)flag&=B[i]==0;
		if(flag)ans=max(ans,x);
	}
	cout<<ans<<endl;
}


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

public class Main {
	public static void main(String[] args) throws Exception {
		Scanner sc = new Scanner(System.in);
		ArrayList<Integer> num = new ArrayList<Integer>();
		ArrayList<String> param = new ArrayList<String>();
		int system = 0; // 文字の空白区切り　0:ON　1:OFF

		while (sc.hasNext()) {
			if (sc.hasNextInt()) {
				num.add(sc.nextInt());
			} else {
				if(system==0) param.add(sc.next());
				if(system==1) param.add(sc.nextLine());
			}
		}
		Method(num, param);
	}

	static void Method(ArrayList<Integer> num, ArrayList<String> param) {
		
		if(param.get(0).equals("+")){
			System.out.println(num.get(0) + num.get(1));
		} else {
			System.out.println(num.get(0) - num.get(1));
		}
	}
}

Measured memory_bytes: 23892
N = int(input())


def resol_a(x, a):
    if x < 10:
        return int(x >= a)
    d = 0
    while x > 10**(d+1):
        d += 1
    f = x // 10 ** d
    r = x % 10 ** d
    c = resol_a(r, a)
    b = resol_a(10 ** d - 1, a)
    bb = resol_a(10 ** (d - 1), a)
    if f > a:
        return b + 1
    elif f == a:
        return b + c - bb
    else:
        return b


def resol_ab(x, a, b):
    d = 0
    if x < 100:
        return (x >= 10 * b + a) + (x >= 10 * a + b)
    while x > 10 ** (d + 1):
        d += 1
    f = x // 10 ** d
    r = x % 10 ** d
    if f > a:
        return resol_ab((a+1)*10**d-1, a, b)
    elif f == a:
        return resol_ab(a * 10 ** d - 1, a, b) + max(resol_ab(r, a, b) - resol_ab(10 **
                                                                                  (d - 1), a, b), 0) + max(resol_a(r, b) - resol_a(10 ** (d - 1), b), 0)
    elif f > b:
        return resol_ab((b+1)*10 ** d - 1, a, b)
    elif f == b:
        return resol_ab(b * 10 ** d - 1, a, b) + max(resol_ab(r, a, b) - resol_ab(10 **
                                                                                  (d - 1), a, b), 0) + max(resol_a(r, a) - resol_a(10 ** (d - 1), a), 0)
    else:
        return resol_ab(10 ** d - 1, a, b)


def resol_abc(x, a, b, c):
    if x < 1000:
        A, B, C = str(a), str(b), str(c)
        return sum([x >= int(_) for _ in [A+B+C, A+C+B, B+A+C, B+C+A, C+A+B, C+B+A]])
    d = 0
    while x > 10 ** (d + 1):
        d += 1
    f = x // 10 ** d
    r = x % 10 ** d
    if f > a:
        return resol_abc((a+1)*10**d-1, a, b, c)
    elif f == a:
        return resol_abc(a*10**d-1, a, b, c)+max(resol_abc(r, a, b, c)-resol_abc(10**(d-1), a, b, c), 0)+max(resol_ab(r, b, c)-resol_ab(10**(d-1), b, c), 0)
    elif f > b:
        return resol_abc((b+1)*10**d-1, a, b, c)
    elif f == b:
        return resol_abc(b*10**d-1, a, b, c)+max(resol_abc(r, a, b, c)-resol_abc(10**(d-1), a, b, c), 0)+max(resol_ab(r, a, c)-resol_ab(10**(d-1), a, c), 0)
    elif f > c:
        return resol_abc((c+1)*10**d-1, a, b, c)
    elif f == c:
        return resol_abc(c*10**d-1, a, b, c)+max(resol_abc(r, a, b, c)-resol_abc(10**(d-1), a, b, c), 0)+max(resol_ab(r, a, b)-resol_ab(10**(d-1), a, b), 0)
    else:
        return resol_abc(10**d-1, a, b, c)


print(resol_abc(N, 7, 5, 3))

Measured memory_bytes: 3320
def cmb(n, r, mod):
    if ( r<0 or r>n ):
        return 0
    r = min(r, n-r)
    return g1[n] * g2[r] * g2[n-r] % mod

mod = 10**9+7 #出力の制限
N = (2*(10**6))+5
g1 = [1, 1] # 元テーブル
g2 = [1, 1] #逆元テーブル
inverse = [0, 1] #逆元テーブル計算用テーブル
for i in range( 2, N + 1 ):
    g1.append( ( g1[-1] * i ) % mod )
    inverse.append( ( -inverse[mod % i] * (mod//i) ) % mod )
    g2.append( (g2[-1] * inverse[-1]) % mod )
a,b,c,d=map(int,input().split())
print((cmb(c+d+2,c+1,mod)-cmb(d+1+a,a,mod)-cmb(b+c+1,c+1,mod)+cmb(a+b,a,mod))%mod)

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

int main() {
  int N,Q;
  cin>>N>>Q;
  string S;
  cin>>S;
  int l[N],r[N];
  int ac[N];

  for(int i=0;i<Q;i++){
    cin>>l[i]>>r[i];
  }
  for(int i=0;i<N-1;i++){
    string s2=S.substr(i,2);
    if(s2=="AC") ac[i]=1;
    else ac[i]=0;
  }

  for(int i=1;i<N-1;i++){
    ac[i] += ac[i-1];
  }
  /*
  for(int i=0;i<N-1;i++){
    cout<<ac[i]<<endl;
  }
  */
  for(int i=0;i<Q;i++){
    cout<<ac[r[i]-2]-ac[l[i]-2]<<endl;
  }

  }


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

#define int long long
#define INF 1e18

int const mod = 1e9+7;

int n;

int tab[22][22];

int memo[2097152][22];

signed main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    cin >> n;
    for(int i = 0; i< n; i++){
        for(int j = 0; j < n; j++){
            cin >> tab[i][j];
        }
    }
    for(int i = 0; i < (1<<n); i++) memo[i][n] = 1;
    for(int mask = (1<<n)-2; mask >= 0; mask--){
        int c = __builtin_popcountll(mask);
        for(int i = 0; i < n; i++){
            if(((1<<i)&mask)) continue;
            if(!tab[c][i]) continue;
            memo[mask][c]+=memo[mask|(1<<i)][c+1];
            if(memo[mask][c] >= mod) memo[mask][c]-=mod;
        }
    }
    cout << memo[0][0] << endl;
}


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



int main(){
    long long N,K;
    cin >> N >> K;
    if(K%2!=0){
        cout << (N/K)*(N/K)*(N/K) << endl;
    }
    if(K%2==0){
        cout << (N/K)*(N/K)*(N/K)+(N/(K/2)-N/K)*(N/(K/2)-N/K)*(N/(K/2)-N/K)<< endl;
    }
    return 0;
}


Measured memory_bytes: 256