akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i) 
#define PI acos(-1)

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

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

    int n;
    cin>>n;
    vector<ll> fibs(n + 1);
    fibs[0] = 1;
    fibs[1] = 1;
    rep(i, n - 1) {
        fibs[i + 2] = fibs[i + 1] + fibs[i];
    }
    cout<<fibs[n]<<endl;
}


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

int main() {
  int N; cin >> N;
  vector<int> A(N);

  double below = 0.0;
  for (int i = 0; i < N; ++i) {
    double a; cin >> a;
    below += 1/a;
  }


  cout << fixed << setprecision(5);
  cout << 1 / below << endl;
}

Measured memory_bytes: 256
import java.util.Scanner;

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

        String k = sc.next();
        // int a = sc.nextInt();
        // int b = sc.nextInt();

        System.out.println(k.equals("ARC") ? "ABC" : "ARC");

        sc.close();
    }
}

Measured memory_bytes: 35696
#include <iostream>
#include <string>
#include <algorithm>
#include <functional>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <cstdio>
#include <cmath>
#include <tuple>
#include <iomanip>
#include <numeric>
#include <unordered_map>
#include <sstream>   
#include<limits.h>
using namespace std;
#define i64  long long

#define I32_MAX 2147483647
#define I64_MAX 9223372036854775807


template< typename T >
struct edge {
  int src, to;
  T cost;

  edge(int to, T cost) : src(-1), to(to), cost(cost) {}

  edge(int src, int to, T cost) : src(src), to(to), cost(cost) {}

  edge &operator=(const int &x) {
    to = x;
    return *this;
  }

  operator int() const { return to; }
};

template< typename T >
using Edges = vector< edge< T > >;
template< typename T >
using WeightedGraph = vector< Edges< T > >;
using UnWeightedGraph = vector< vector< int > >;
template< typename T >
using Matrix = vector< vector< T > >;


template< typename T >
void warshall_floyd(Matrix< T > &g, T INF) {
  for(int k = 0; k < g.size(); k++) { //経由地点
    for(int i = 0; i < g.size(); i++) { //開始点
      for(int j = 0; j < g.size(); j++) { //終着点
        if(g[i][k] == INF || g[k][j] == INF) continue;
        g[i][j] = min(g[i][j], g[i][k] + g[k][j]);
      }
    }
  }
}

void solve()
{
 int V, E,L;
  cin>>V>>E>>L;
  Matrix< i64 > mat(V, vector< i64 >(V, I32_MAX));
  //隣接行列のようなもの
  for(int i = 0; i < V; i++) mat[i][i] = 0;
  for(int i = 0; i < E; i++) {
    int x, y, z;

    cin>>x>>y>>z;
    x--;
    y--;
    mat[x][y] = z;
    mat[y][x] = z;
  }
  i64 lmax = I64_MAX;

  warshall_floyd(mat, lmax);

  Matrix<i64> mat_L (V,vector<i64>(V,I64_MAX));
  //隣接行列のようなもの

  for (int i = 0; i < V; i++)
  {
    for (int j = 0; j < V; j++)
    {
      if(mat[i][j] <= L)
      mat_L[i][j] = 1;
    }
  }
  
  // for(int i = 0; i < V; i++) mat_L[i][i] = 0;

  warshall_floyd(mat_L,lmax);
  int M;
  cin>>M;

  // for (int i = 0; i < V; i++)
  // {
  //   for (int j = 0; j < V; j++)
  //   {
  //     cout<<mat_L[i][j]<<" ";
  //   }

  //   cout<<endl;
    
  // }
  
  for (int i = 0; i < M; i++)
  {
    int A,B;
    cin>>A>>B;
    A--;
    B--;
    if((mat_L[A][B] > 1000) || (mat_L[A][B]<0)) cout<<-1<<endl;
    else
    cout<<mat_L[A][B] -1 <<endl ;
  }
  
  return;
}

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

  solve();

  return 0;
}


Measured memory_bytes: 1920
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int maxn = 1e5 + 5;
ll dp[maxn];
ll n,V;
ll w[105],v[105];
ll tot = 0;
int main(){
	scanf("%lld%lld",&n,&V);
	for(ll i = 1;i <= n;i++){
		cin >> w[i] >> v[i];
		tot += v[i];
	}
	memset(dp,0x3f3f,sizeof(dp));
	dp[0] = 0;
	for(ll i = 1;i <= n;i++){
		for(ll j = tot;j >= 0;j--){
			if(j >= v[i]) dp[j] = min(dp[j],dp[j - v[i]] + w[i]);
		}
	}
	for(ll i = tot;i >= 0;i--){
		if(dp[i] <= V){
			printf("%lld\n",i);
			break;
		}
	}
	return 0;
}

Measured memory_bytes: 1024
n, m = gets.split(' ').map(&:to_i)
matrix = []
vector = []
n.times do
    matrix << gets.split(' ').map(&:to_i)
end

m.times do
    vector << gets.to_i
end

matrix.each do |n|
    sum = 0
    m.times do |i|
        sum += n[i] * vector[i]
    end
    puts sum
end


Measured memory_bytes: 6976
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		String S = sc.next();
		sc.close();
		if(S.charAt(1) == S.charAt(2) && S.charAt(1) != S.charAt(3) && S.charAt(3) == S.charAt(0) ) {
			System.out.println("Yes");
		}else if(S.charAt(1) == S.charAt(3) && S.charAt(1) != S.charAt(2) &&  S.charAt(2) == S.charAt(0) ) {
			System.out.println("Yes");
		}else if(S.charAt(1) == S.charAt(0) && S.charAt(1) != S.charAt(2) &&  S.charAt(2) == S.charAt(3) ) {
			System.out.println("Yes");
		}else {
			System.out.println("No");
		}
	}

}


Measured memory_bytes: 21844
#include<stdio.h>
 
int main() {
    int n,i,u,k,v,j;
    scanf("%d",&n);
    int g[n][n];
    for(i=0;i<n;i++){
    for(j=0;j<n;j++){
        g[i][j]=0;
    }
    }
    for(i=0;i<n;i++){
    scanf("%d %d",&u, &k);
    for(j=0;j<k;j++){
        scanf("%d",&v);
        g[u-1][v-1]=1;
    }
    }
    for(i=0;i<n;i++){
    for(j=0;j<n;j++){
        if (j) printf(" ");
        printf("%d",g[i][j]);
        if(j==n-1)printf("\n");
    }
    }
    return 0;
}

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

using namespace std;
#define inf 1000000000
#define unvisited -1
#define visited 1
#define eps 1e-9
#define mp make_pair
#define pb push_back
#define pi acos(-1.0)
#define uint64 unsigned long long
#define FastSlowInput ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define debug if(true)
typedef long long ll;
typedef vector<int> vi;
typedef pair<int,int> ii;
typedef vector<ii> vii;

string temp[7];
string s[7];

void setTemp(int n) {
	for(int i=0;i<n;i++){
		temp[i] = s[i];
	}
}

int main(){
	int n,m,z,i,j;
	scanf("%d %d %d",&n,&m,&z);
	
	for(i=0;i<n;i++){
		cin>>s[i];
		temp[i] = s[i];
	}
	int ans = 0;

	for(i=0;i<(1<<n);i++){
		vi listRow;
		for(j=0;j<n;j++){
			if((1<<j) & i) {
				listRow.pb(j);
			}
		}
		for(j=0;j<(1<<m);j++){
			vi listCol;
			for(int l=0;l<m;l++){
				if((1<<l) & j) {
					listCol.pb(l);
				}
			}

			setTemp(n);

			//process listCOl and listRow
			for(int k=0;k<listRow.size();k++){
				int row = listRow[k];
				for(int l=0;l<m;l++){
					temp[row][l] = 'z';
				}
			}

			for(int k=0;k<listCol.size();k++){
				int col = listCol[k];
				for(int l=0;l<n;l++){
					temp[l][col] = 'z';
				}
			}

			int cnt = 0;
			for(int k=0;k<n;k++){
				for(int l=0;l<m;l++){
					if(temp[k][l] == '#'){
						cnt++;
					}
				}
			}
			if(cnt == z){
				// printf("z: %d\n",z);
				// for(int k=0;k<listRow.size();k++){
				// 	printf("%d ",listRow[k]);
				// }
				// printf("\n");
				// for(int k=0;k<listCol.size();k++){
				// 	printf("%d ",listCol[k]);
				// }
				// printf("\n");
				ans++;
			}
		}
	}
	printf("%d\n",ans);
	return 0;
};

Measured memory_bytes: 3756
import java.util.Scanner;
public class Main{
  public static void main(String args[]){
  	Scanner sc = new Scanner(System.in);
    int a = Integer.parseInt(sc.next());
    int b = Integer.parseInt(sc.next());
    double d = a/0.08;
    int x = (int)(a/0.08);//a=x*0.08
    if(d!=x) x++;
    System.err.println(x);
      //消費税がa円である範囲(とりあえずxは範囲内)
    int min = a;
    int max = a;
    int xmin = x;
    int xmax = x;
    int i = 0;
    while(min==a){
      min = (int)(xmin*0.08);
      xmin--;
    }
    while(max==a){
      max = (int)(xmax*0.08);
      xmax++;
    }
    System.err.println("min:"+xmin+" max:"+xmax);
    //xmin<x<xmaxの間の数のうち最小のものが答
   	for(int j = xmin+2; j<xmax-1; j++){
      if(b==(int)(j*0.1)){
        System.out.println(j);
        return;
      }
    }
    System.out.println(-1);
  }
}

Measured memory_bytes: 22868
#include <stdio.h>
#include <string.h>
#define TRUE 1
#define FALSE 0

int main(void){
	int n,num,i,j;
	char mark[256];
	int cards[4][13];

	for(i = 0;i < 4;i++){
		for(j = 0;j < 13;j++){
			cards[i][j] = FALSE;
		}
	}

	scanf("%d", &n);

	if(n > 52){
		return 0;
	}

	for(i = 0;i < n;i++){
		scanf("%s %d", mark, &num);
		if(num >= 1 && num <= 13){
			if(strcmp(mark,"S") == 0){
				cards[0][num - 1] = TRUE;
			}else if(strcmp(mark,"H") == 0){
				cards[1][num - 1] = TRUE;
			}else if(strcmp(mark,"C") == 0){
				cards[2][num - 1] = TRUE;
			}else if(strcmp(mark,"D") == 0){
				cards[3][num - 1] = TRUE;
			}else{
				return 0;
			}
		}else{
			return 0;
		}
	}

	for(i = 0;i < 4;i++){
		for(j = 0;j < 13;j++){
			if(cards[i][j] == FALSE){
				switch(i){
					case 0:
						printf("S");
						break;
					case 1:
						printf("H");
						break;
					case 2:
						printf("C");
						break;
					case 3:
						printf("D");
						break;
					default:
						break;
				}
				printf(" %d\n", j + 1);
			}
		}
	}

	return 0;
}

Measured memory_bytes: 600
nPieces, nCoords = map(int, input().split())
a = sorted(list(map(int, input().split())), reverse=True)
if nPieces >= nCoords:
    print(0)
    exit()
diffs = sorted([a[i] - a[i + 1] for i in range(nCoords - 1)], reverse=True)
print(sum(diffs[nPieces - 1:]))


Measured memory_bytes: 13960
#include<iostream>
#include<vector>
#include<algorithm>
#include<queue>
#include<set>
#include<string>
#include<stdio.h>
#include<cmath>
#include<map>
#include<bitset>

using namespace std;

#define rep(i, n) for(int i = 0; i < n; i++)
#define repn(i, n) for(int i = 1; i <= n; i++)
#define repr(i, n) for(int i = n-1; i >= 0; i--)
#define all(x) (x).begin(), (x).end()
#define lint long long

// ログを出すやつ。簡単なデバッグに
inline void logger(){ cout << endl; }
template<typename A, typename... B>
void logger(const A& a, const B&... b){
    cout << a << " , ";
    logger(b...);
}

int e[3][30];

int main(){
    int n, c_max; cin >> n >> c_max;
    int d[30][30];
    rep(i, c_max) rep(j, c_max){
        cin >> d[i][j];
    }

    int c[500][500];
    rep(i, n) rep(j, n){
        cin >> c[i][j];
        c[i][j]--;
        e[(i + j) % 3][c[i][j]]++;
    }

    long ans = 1e9;
    rep(i, c_max) rep(j, c_max) rep(k, c_max){
        if((i-j)*(j-k)*(k-i) == 0) continue;
        long discomfort = 0;
        rep(l, c_max){
            discomfort += e[0][l] * d[l][i];
            discomfort += e[1][l] * d[l][j];
            discomfort += e[2][l] * d[l][k];
        }
        ans = min(ans, discomfort);
    }
    cout << ans << endl;
}

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

int main(int argc, char const *argv[])
{
	int n, m, X, Y;
	int *x, *y;
	scanf("%d%d%d%d", &n, &m, &X, &Y);
	x=(int *)malloc(sizeof(int)*n);
	y=(int *)malloc(sizeof(int)*m);
	for (int i = 0; i < n; ++i)
	{
		scanf("%d", &x[i]);
	}
	for (int i = 0; i < m; ++i)
	{
		scanf("%d", &y[i]);
	}
	for (int i = 0; i < n; ++i)
	{
		if (X < x[i])
		{
			X=x[i];
		}
	}
	for (int i = 0; i < m; ++i)
	{
		if (Y > y[i])
		{
			Y=y[i];
		}
	}

	if (Y-X>=1)
	{
		printf("No War\n");
	}
	else
	{
		printf("War\n");
	}
	free(x);
	free(y);
	return 0;
}

Measured memory_bytes: 128
#include <iostream>
#include <stdio.h>
#include <vector> 
#include <math.h> 
#include <map>
typedef long long ll;
using namespace std;
void saiki(ll &c, int tmp, map<ll,ll> m) {
    if (tmp % 2 == 0) {
        tmp = tmp / 2;
    } else {
        tmp = 3 * tmp + 1;
    }
    if (m.count(tmp)) return;
    m[tmp] = 1;
    c = c+1;
    saiki(c,tmp,m);
}

int main(void){
    ll s; cin >> s;
    map<ll,ll> m; 
    ll counter = 2;
    m[s] = 1;
    saiki(counter, s, m);
    cout << counter << endl;
}

Measured memory_bytes: 3976
from collections import deque
h, w = map(int, input().split())
wall = '/'
grid = [[wall] * (w + 2)]
wn = 0

q = deque()
for y in range(1, h+1):
    grid.append([wall] + [c for c in input()] + [wall])
    for x in range(1, w+1):
        if grid[y][x] == '.':
            wn += 1
        if grid[y][x] == '#':
            q.append((y, x, 0))
grid.append([wall] * (w + 2))

move = [(-1, 0), (1, 0), (0, -1), (0, 1)]

while q:
    y, x, i = q.popleft()
    grid[y][x] = '#'
    for dy, dx in move:
        if grid[y + dy][x + dx] == '.':
            grid[y + dy][x + dx] = '#'
            q.append((y + dy, x + dx, i + 1))
    
print(i)


Measured memory_bytes: 215904
#include <bits/stdc++.h>
using namespace std;
using ll = long long int;
using ull = unsigned long long int;

#define MATHPI acos(-1)

template<class T> void chmax(T &a, T b) {
    if (a < b) a = b;
}
template<class T> void chmin(T &a, T b) {
    if (b < a) a = b;
}

using Mat = vector<vector<ll>>;
using Column = vector<ll>;

int main(int argc, char const *argv[])
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);

    int N,K;cin>>N>>K;
    int cnt=0;
    while(N) {
        N/=K;
        cnt++;
    }
    cout << cnt<<"\n";

    return 0;
}


Measured memory_bytes: 256
#include <ios>
#include <iomanip>
#include <iostream>
#include <functional>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <string>
#include <sstream>
#include <complex>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
#include <climits>

using namespace std;
typedef long long int ll;
typedef long double ld;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()
#define MOD 1000000007
#define INF (1e9)
#define PI (acos(-1))
#define print(x) cout << x << endl
#define yes cout << "Yes" << endl
#define YES cout << "YES" << endl
#define no cout << "No" << endl
#define NO cout << "NO" << endl

ll gcd(ll a, ll b) { return b ? gcd(b,a%b) : a;}
ll lcm(ll a, ll b) { return a / gcd(a, b) * b; }
typedef pair <ll,ll> P;

int main()
{
    string s, t;
    cin >> s >> t;
    ll N = s.size();
    ll M = t.size();
    vector<string> ans;
    for(ll i = 0; i <= N-M; i++) {
        bool flag = false;
        for(ll j = 0; j < M; j++) {
            if (s[i+j] != '?' & s[i+j] != t[j]) {
                flag = true;
                break;
            }
        }
        if (!flag) {
            string tmp = s;
            tmp.replace(i, M, t);
            for(ll k = 0; k < tmp.size(); k++) {
                if (tmp[k] == '?') tmp[k] = 'a';
            }
            ans.push_back(tmp);
        }
    }
    if (ans.size() == 0) {
        print("UNRESTORABLE");
    } else {
        sort(all(ans));
        print(ans[0]);
    }

    return 0;
}


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

ll N,H,d,h;

int main(){
  cin >> N >> H;
  ll ans = 0;

  ll cur = H;
  priority_queue<pll> q;
  for(int i=0;i<N-1;i++){

    cin >> d >> h;
    ll rem = H-cur;
    priority_queue<pll> tmp;
    while(q.size() && q.top().first >= h){
      pll p = q.top(); q.pop();
      rem -= p.second * p.first;
      tmp.push(p);
    }
    swap(q,tmp);
    ll times = rem/h;
    //cerr << rem << " " << h << " " << times << endl;
    if(times)q.push(pll(h,times));
    if(times*h != rem)q.push(pll(rem-times*h,1));

    cur -= d;
    while(cur<=0){
      //cerr << cur << endl;
      pll p = q.top(); q.pop();
      ll need = -cur/p.first+1;
      //cerr << p.first << " " << need << " " << p.second << endl;

      if(need <= p.second){
	ans += need;
	p.second -= need;
	cur += need * p.first;
	if(p.second)q.push(p);
      }else{
	ans += p.second;
	cur += p.first * p.second;
      }
    }
    //cerr << endl;
  }

  cout << ans << endl;
}

Measured memory_bytes: 1196
import math
import numpy as np
A,B = list(map(int,input().split()))
if A == 1:
  print(B)
  exit()
if B == 1:
  print(A)
  exit()
C = A*B
D = []
for i in range(int(math.sqrt(C)),1,-1):
  if A % i == 0 and B % i == 0:
    D.append(i)
    A = A // i
    B = B // i
    C = A*B
if len(D) != 0:
  p = np.prod(D)
  C = C*p
print(C)

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

int main()
{
	map<string, bool> exis;
	int n; cin>>n;
	for(int i = 0; i < n; ++i) {
		string opt, str; cin>>opt>>str;
		if(opt[0] == 'i') {
			exis[str] = true;
		} else {
			cout<<(exis.find(str) != exis.end()?"yes":"no")<<endl;
		}
	}
	return 0;
}



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

#define l long long
l N;
l K;
l h[100006];
l memo[100006];
bool flag[100006];


l DP(l pos){
	if(pos == N)return 0;
	
	if(flag[pos])return memo[pos];

	l ans = 999999999;
	for(int i=1;i<=K;i++){
		if(pos + i <=N){
		l hx = abs(h[pos+i]-h[pos])+DP(pos+i);
		 ans = min(ans,hx);
		}
	}
	memo[pos] = ans;
	flag[pos] = true;
	return ans;
}

int main() {
	// your code goes here
	cin>>N;
	cin>>K;
	for(l i=1;i<=N;i++){
		cin>>h[i];
	}
	l ans = DP(1);
	
	cout<<ans;
	
	return 0;
}

Measured memory_bytes: 6528
#include "bits/stdc++.h"
using namespace std;
using ll=long long;
#define print(n) cout<<n<<endl
#define rep(i,a,n) for(int i=a;i<n;i++)
#define ALL(s) s.begin(),s.end()
#define P pair<ll,ll>
#define vl vector<ll>
#define vi vector<int>
#define vvl vector<vector<ll>>
#define vvi vector<vector<int>>
const int M=100111;
const int inf=1000000007;
const long long INF=1e18;
int dx[4]={-1,0,1,0},dy[4]={0,-1,0,1};
int ddx[8]={1,-1,0,0,1,-1,-1,1},ddy[8]={0,0,1,-1,1,-1,1,-1};

/*
vvl comb(int n, int r) {
	vvl v(n + 1,vl(n + 1, 0));
	for (int i = 0; i < v.size(); i++) {
		v[i][0] = 1;
		v[i][i] = 1;
	}
	for (int j = 1; j < v.size(); j++) {
		for (int k = 1; k < j; k++) {
			v[j][k] = (v[j - 1][k - 1] + v[j - 1][k]);
		}
	}
	return v;
}
*/

int main() {
	int a,b;
	cin>>a>>b;
	print(max({a+b,a-b,a*b}));

}

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

using namespace std;

const int N = 1e3 + 5, MAX_S = 2e4 + 5;
int n;
long long dp[N][MAX_S], ans;

struct Block {
    int w, s, v;
    Block (int w = 0, int s = 0, int v = 0) : w(w), s(s), v(v) {}
    bool operator< (const Block& rhs) const { return w + s == rhs.w + rhs.s ? s < rhs.s : w + s < rhs.w + rhs.s; }
} block[N];

int main () {
    scanf("%d", &n);
    for (int i = 1; i <= n; ++i) {
        int w, s, v; scanf("%d %d %d", &w, &s, &v);
        block[i] = Block(w, s, v);
    }
    sort(block + 1, block + n + 1);

    memset(dp, -1, sizeof dp);
    dp[0][0] = 0;
    for (int i = 1; i <= n; ++i) {
        for (int j = 0; j < MAX_S; ++j) {
            dp[i][j] = max(dp[i][j], dp[i - 1][j]);
            if (j - block[i].w >= 0 && j - block[i].w <= block[i].s && dp[i - 1][ j - block[i].w ] != -1) dp[i][j] = max(dp[i][j], dp[i - 1][ j - block[i].w ] + block[i].v);

            ans = max(ans, dp[i][j]);
        }
    }

    printf("%lld", ans);

    return 0;
}


Measured memory_bytes: 157312
#include <algorithm>
#include <string>
#include <iostream>

#define DEBUG

using namespace std;


string RtnRvsBinExp(int num) {
    string bin = "";

    if(num <= 0){
        cout << "ERROR: invalid function argument (line: "
            << __LINE__ << ")" << endl;
        exit(1);
    }

    while(num > 0){
        if(num % 2 == 0){
            bin += "0";
        }else{
            bin += "1";
        }
        num /= 2;
    }

    return bin;
}


void AddBit(char &bit) {
    if(bit == '0'){
        bit = '1';
    }else if(bit == '1'){
        bit = '2';
    }else{
        cout << "ERROR: invalid function argument (line: "
            << __LINE__ << ")" << endl;
        exit(1);
    }
}


void FormRvsBin(string &bin) {
    int i=0;
    while(i < bin.length()){
        if(bin[i] == '2'){
            if(!(i+1 < bin.length())){
                bin += "1";
            }else{
                AddBit(bin[i+1]);
            }
            bin[i] = '0';
        }
        i++;
    }
}


void ConvRvsBinMns(string &bin, bool negative) {
    int i=0;

    while(i < bin.length()){
        if( (!negative && i%2 == 1 || negative && i%2 == 0) && bin[i] == '1'){
            if(!(i+1 < bin.length())){
                bin += "1";
            }else{
                AddBit(bin[i+1]);
            }
            FormRvsBin(bin);
        }
        i++;
    }
}


int main(){
    int N;
    bool negative;
    string ans;

    cin >> N;
    if(N < 0){
        negative = true;
        N *= -1;
    }else{
        negative = false;
    }

    if(N == 0){
        ans = "0";
    }else{
        ans = RtnRvsBinExp(N);
        ConvRvsBinMns(ans, negative);
        reverse(ans.begin(), ans.end());
    }

    cout << ans << endl;

    return 0;
}



Measured memory_bytes: 256
#include <iostream>
 
using namespace std;
 
int main(){
  int n, x;
  cin >> n >> x;
  int p[n];
  for (int i=0;i<n;i++){
    cin >> p[i] ;
  }
  int ans = 1;
  int l = 0;
  for (int i=0;i<n;i++){
    l += p[i];
    if (l <= x)ans++;
  }
  cout << ans << endl;
  return 0;
 
 }


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

int main()
{
	long long N;
	cin >> N;
	if (N % 2 == 1)
	{
		cout << 0 << '\n';
		return 0;
	}
	
	long long fives = 0;
	for (int power = 1; log(N) / log(5) >= (double)power; ++power)
		fives += N / (long long)round(pow(5.0, power)) / 2;
		
	cout << fives << '\n';
}


Measured memory_bytes: 256
#!/usr/bin/env python3
from collections import defaultdict
from itertools import combinations

_, *s = open(0).read().split()
d = defaultdict(int)
for i in s:
    d[i[0]] += 1
ans = 0
for a, b, c in combinations(["M", "A", "R", "C", "H"], 3):
    ans += d[a] * d[b] * d[c]
print(ans)


Measured memory_bytes: 17560
// KOI NI YAAR SAB SAHI HOEGA  BAS  CHORRO MAT
// ENJOR KARO YAAR
// HAAR MAT MAANO
// // APNA TIME AAYEGA
// BEILIEVE IN GOD
#include<bits/stdc++.h>
using namespace std;
#define lli int
#define loop(i,a,b) for(lli i=a;i<b;i++)
#define loopb(i,a,b) for (lli i=a;i>=b;i--)
#define pb push_back
#define mod 1000000007
#define fast() ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define mem(a,b) memset(a,b,sizeof(a))
#define gcd(a,b) (__gcd((a),(b)))
#define lcm(a,b)(((a)*(b))/gcd((a),(b)))
#define ma 1e18
#define bc __builtin_popcountll
#define vi vector<lli>
#define pr pair<lli,lli>
#define vp vector<pr>
#define F  first
#define S   second
#define lld long double
#define PI  3.14159265358979
#define pri  priority_queue<ll>
#define prim  priority_queue<ll,vector<ll>,greater<ll>>
#define flush  cout<<flush

const lli  N=3e3+10;
 
vector<vector<lld>> dp(N,vector<lld>(N,-1)); 
lli n;
vector<lld>a;



lld solve(lli index , lli tails)
{if(index == n)
{if(tails<=n/2)
{return 1;
}
else
{return 0;
}
}
if(dp[index][tails]!=-1)
{return dp[index][tails];
}
return dp[index][tails] = (a[index] * solve(index+1,tails)) + (1-a[index])  *  solve(index+1,tails+1);
}

int main()
{lli num;
fast();
cin>>n;
a.resize(n);
loop(i,0,n)
{cin>>a[i];
}

cout<<fixed<<setprecision(10)<<solve(0,0)<<"\n";
}


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

void showA(int *A, int N){

  for(int i = 0; i < N; i++){
    if(i < N-1)
      std::cout << A[i] << ' ';
    else
      std::cout << A[i] << std::endl;
  }

  return;

}


void insertionSort(int *A, int N){

  showA(A, N);

  int v, j;
  for(int i=1; i<N; i++){
    v = A[i];
    j = i - 1;

    while(j >= 0 && A[j] > v){
      A[j+1] = A[j];
      j--;
    }

    A[j+1] = v;

    showA(A, N);
  }

  return;

}


int main(){
  int N;
  int* A;

  std::cin >> N;

  A = (int*)malloc( sizeof(int) * N );

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

  insertionSort(A, N);

  return 0;
}

Measured memory_bytes: 3084
#!python
# -*- coding: utf-8 -*-


def main():
    N, M = map(int, input().split())
    cakes = []

    for i in range(N):
        cakes.append(list(map(int, input().split())))

    ANS = 0

    for i in range(2 ** 3):
        x = i % 2 or -1
        y = i // 2 % 2 or -1
        z = i // 4 % 2 or -1

        points = []
        for c_x, c_y, c_z in cakes:
            points.append(c_x * x + c_y * y + c_z * z)
        points.sort(reverse=True)
        s = sum(points[:M])

        if ANS < s:
            ANS = s

    print(ANS)


if __name__ == '__main__':
    main()


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

int main(){

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

	if(a > b){
		int temp = a;
		a = b;
		b = temp;
	}

	if(b > c){
		int temp = b;
		b = c;
		c = temp;
	}

	if(a > b){
		int temp = a;
		a = b;
		b = temp;
	}

	cout << a << " " << b << " " << c << endl;

return 0;
}

Measured memory_bytes: 1164
import math
from functools import reduce

def gcd(*nums):
  return reduce(math.gcd, nums)

k = int(input())

total = 0

for i in range(1, k + 1):
  for j in range(i, k + 1):
    for l in range(j, k + 1):
      if i == j == l:
        total += i
      elif i == j and i != l:
        total += gcd(i, l) * 3
      elif i == l and i != j:
        total += gcd(i, j) * 3
      elif j == l and i != j:
        total += gcd(i, j) * 3
      else:
        total += gcd(i, j, l) * 6

print(total)

Measured memory_bytes: 9572
#include <iostream>
#include <string>
#include <string.h>
#include <algorithm>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <cmath>
#include <stdio.h>
#include <vector>
#include <thread>
#include <atomic>
#include <mutex>
#include <future>
#define int long long
#define endre getchar();getchar();return 0
#define INF 1000000007
using namespace std;
bool prime(int n) {
	for (int i = 2; i <= sqrt(n); i++) {
		if (n%i == 0)return false;
	}
	return n != 1;
}
int gcd(int x, int y) {
	if (x < y)swap(x, y);
	if (y == 0)return x;
	return (y, x%y);
}
int lcm(int x, int y) {
	return x * y / gcd(x, y);
}
int kai(int n) {
	if (n == 0)return 1;
	return (kai(n - 1)*n) % INF;
}
int mod_pow(int x, int y, int mod) {
	int res = 1;
	while (y > 0) {
		if (y & 1) {
			res = res * x%mod;
		}
		x = x * x%mod;
		y >>= 1;
	}
	return res;
}
int mystoi(string s) {
	int cnt = 0;
	for (int i = 0; i < s.size(); i++) {
		cnt += (int)(s[i] - '0') * pow(10, s.size() - i - 1);
	}
	return cnt;
}

signed main() {
	int n;
	cin >> n;
	if (n % 111) {
		cout << (n / 111 + 1) * 111 << endl;
	}
	else {
		cout << n << endl;
	}
	endre;
}

Measured memory_bytes: 256
import java.util.*;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n=sc.nextInt();
        int m=sc.nextInt();
        int[] output=new int[n];
        for(int i=0;i<m;i++){
            output[sc.nextInt()-1]++;
            output[sc.nextInt()-1]++;
        }
        for(int a:output){
            System.out.println(a);
        }
    }
     
}

Measured memory_bytes: 21588
#include <stdio.h>

int Mdigit(const int x) {
	if (99999 < x) {
		return x / 100000;
	}
	else if (9999 < x && x < 100000) {
		return x / 10000;
	}
	else if (999 < x && x < 10000) {
		return x / 1000;
	}
	else if (99 < x && x < 1000) {
		return x / 100;
	}
	else if (9 < x && x < 100) {
		return x / 10;
	}
	else {
		return x;
	}
}

int mdigit(const int x) {
	return x % 10;
}

int main() {
	int N, i, j, AM, Am;
	long ans = 0;
	long c[10][10];
	scanf("%d", &N);
	for (i = 0; i <= 9; i++) {
		for (j = 0; j <= 9; j++) {
			c[i][j] = 0;
		}
	}

	for (i = 1; i <= N; i++) {
		c[Mdigit(i)][mdigit(i)]++;
	}

	//各Aに対して...
	for (i = 1; i <= N; i++) {
		AM = Mdigit(i);
		Am = mdigit(i);
		ans += c[Am][AM];
	}
	printf("%ld", ans);
	return 0;
}

Measured memory_bytes: 128
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
using namespace std;
int main(){
    int N;
    cin >> N;
    vector<string> S(N);
    for(int i = 0; i < N; i++) cin >> S[i];
    long long ans= 0;
    long long cntab = 0, cnta = 0, cntb = 0;
    for(int i = 0; i < N; i++){
        if(S[i][0] == 'B' && S[i][S[i].size() - 1] == 'A') cntab++;
        else if(S[i][0] == 'B') cntb++;
        else if(S[i][S[i].size() - 1] == 'A') cnta++;
        for(int j = 0; j < S[i].size(); j++){
            if(j < S[i].size() - 1 && S[i][j] == 'A' && S[i][j + 1] == 'B') ans++;
        }
    }
    if(cntab == 0) ans += min(cnta, cntb);
    else if(cnta == 0 && cntb == 0) ans += cntab - 1;
    else if(cnta == 0 || cntb == 0) ans += cntab;
    else if(cnta == cntb) ans += cntab + cnta;
    else ans += cntab + min(cnta, cntb);
    cout << ans << endl; 
}


Measured memory_bytes: 768
#include <iostream>
#include <vector>
#include <array>
#include <algorithm>
#include <limits>
#include <cmath>
#include <numeric>
#include <string>

using namespace std;

using ll = long long int;
using ull = unsigned long long int;
#define rep(i, a, b) for(int i = (a); i < (b); ++i )
#define rrep(i, a, b) for(int i = (a); i > (b); --i )
#define REP(i, a, b) for(int i = (a); i <= (b); ++i )
#define RREP(i, a, b) for(int i = (a); i >= (b); --i )
#define llrep(i, a, b) for(ll i = (a); i < (b); ++i )
#define llrrep(i, a, b) for(ll i = (a); i > (b); --i )
#define llREP(i, a, b) for(ll i = (a); i <= (b); ++i )
#define llRREP(i, a, b) for(ll i = (a); i >= (b); --i )
#define ullrep(i, a, b) for(ull i = (a); i < (b); ++i )
#define ullrrep(i, a, b) for(ull i = (a); i > (b); --i )
#define ullREP(i, a, b) for(ull i = (a); i <= (b); ++i )
#define ullRREP(i, a, b) for(ull i = (a); i >= (b); --i )

class UnionFind {
public:
    UnionFind(unsigned long long n) : rank_(n, 0), p_(n, 0) {
        rep(i, 0, n) {
            MakeSet(i);
        }
    }

    void MakeSet(int x) {
        p_[x] = x;
        rank_[x] = 0;
    }

    bool Same(int x, int y) {
        return FindSet(x) == FindSet(y);
    }

    void Link(int x, int y) {
        if (rank_[x] > rank_[y]) {
            p_[y] = x;
        } else {
            p_[x] = y;
            if (rank_[x] == rank_[y]) {
                rank_[y]++;
            }
        }
    }

    void Unite(int x, int y) {
        Link(FindSet(x), FindSet(y));
    }

    int FindSet(int x) {
        if (x != p_[x]) {
            p_[x] = FindSet(p_[x]);
        }
        return p_[x];
    }

private:
    std::vector<int> rank_, p_;
};

int N, Q;

int G[100][100];
int d[100];
int p[100];
int c[100];

int main() {
    cin >> N;
    rep(i, 0, N) {
        rep(j, 0, N) {
            G[i][j] = 10000010;
        }
    }
    rep(i, 0, N) {
        int u, k;
        cin >> u >> k;
        rep(j, 0, k) {
            int t, d;
            cin >> t >> d;
            G[u][t] = d;
        }
    }
    rep(i, 0, N) {
        d[i] = numeric_limits<int>::max();
    }

    d[0] = 0;
    p[0] = 0;
    while (true) {
        int m = -1;
        int min_d = numeric_limits<int>::max();
        rep(i, 0, N) {
            if ((c[i] == 0) && (min_d > d[i])) {
                min_d = d[i];
                m = i;
            }
        }
        if (m < 0) {
            break;
        }
        c[m] = 1;
        rep(i, 0, N) {
            if ((d[m] + G[m][i]) < d[i]) {
                d[i] = d[m] + G[m][i];
                p[i] = m;
            }
        }
    }
    rep(i, 0, N) {
        cout << i << " " << d[i] << endl;
    }
}




Measured memory_bytes: 3132
#include <iostream>

using namespace std;
int a,b,c,d;
int main(){
	cin>>a>>b>>c>>d;
	if(a+b>c+d)cout<<"Left";
	if(a+b==c+d)cout<<"Balanced";
	if(a+b<c+d)cout<<"Right";
	return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;
public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		 int N = sc.nextInt();
		 if(0<N && N<=999) {
			  String N2 =Integer.toString(N);
			  //文字列の最後尾から１文字取り出す。
			  N2 = N2.substring(N2.length() -1);
			 switch(N2.charAt(0)){
			 case '2':
			 case '4':
			 case '5':
			 case '7':
			 case '9':
				 System.out.println("hon");
				 break;
			 case '0':
			 case '1':
			 case '6':
			 case '8':
				 System.out.println("pon");
				 break;
			 case '3':
				 System.out.println("bon");
				 break;
			 }
			 sc.close();
		 }
	}
}

Measured memory_bytes: 35596
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
#include<math.h>
#define PI 3.141592653589793
#define MOD 1000000007


int main(){
	int r,g,b,n;
	scanf("%d%d%d%d", &r, &g, &b, &n);
	int count = 0, i=0, j, k, temp;
	while(r*i<=n){
		j=0;
		while(r*i+g*j<=n){
			temp = n - (r*i+g*j);
			if(temp%b == 0){
				k = temp/b;
				//printf("%d %d %d\n", i, j, k);
				count++;
			}
			j++;
		}
		i++;
	}
	
	printf("%d\n", count);
	return 0;
}

Measured memory_bytes: 128
program main
    use,intrinsic :: iso_fortran_env
    implicit none
    integer(int32):: n,i,j,l,ans=0
    integer(int32), allocatable:: a(:),divisor(:)

    read*, n
    allocate(a(n))
    read*, a(:)

    l = maxval(a)
    allocate(divisor(l),source=0)

    do i=1,n
        divisor(a(i))=divisor(a(i))+1
        if (divisor(a(i)) > 1) cycle
        j=2
        do while(a(i)*j <= l)
            divisor(a(i)*j)=divisor(a(i)*j)+1
            j=j+1
        end do
    end do

    do i=1,n
        if (divisor(a(i)) == 1) ans=ans+1
    end do
    print'(i0)', ans
end program main

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

using namespace std;

bool isIncrease(string s)
{
  for(int i = 1; i < s.size(); i++) {
    if(s[i - 1] + 1 != s[i]) return (false);
  }
  return (true);
}

int main()
{
  int N, A[1000];

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

  int ret = -1;
  for(int i = 0; i < N; i++) {
    for(int j = 0; j < i; j++) {
      int product = A[i] * A[j];
      stringstream sss;
      sss << product;
      if(isIncrease(sss.str())) ret = max(ret, product);
    }
  }
  cout << ret << endl;
}

Measured memory_bytes: 3152
#include <algorithm>
#include <deque>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <set>
#include <string>
#include <tuple>
#include <vector>

using namespace std;

typedef long long ll;
constexpr ll MOD = 1000000007;

// struct UnionFind {
//     vector<int> par;
    
//     UnionFind(int N): par(N) {
//         for (int i=0;i<N;i++) par[i] = i;
//     }

//     int root(int x) {
//         if (par[x] == x) return x;
//         else return par[x] = root(par[x]);
//     }

//     void unite(int x, int y) {
//         int rx = root(x);
//         int ry = root(y);
//         if (rx == ry) return;
//         par[rx] = ry;
//     }

//     bool same(int x, int y) {
//         int rx = root(x);
//         int ry = root(y);
//         return rx == ry;
//     }
// };

int main(void) {
    ll L, R;
    cin >> L >> R;
    if (R-L < 2018) {
        int m = 2018;
        for (ll i=L;i<R;i++) for (ll j=L+1;j<=R;j++) {
            m = min((ll)m, (i*j)%2019);
        }
        cout << m << endl;
    } else cout << 0 << endl;

    return 0;
}


Measured memory_bytes: 256
//#include <tourist>
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> p;
const int INF = 1e9;
const ll LINF = ll(1e18) + 1;
const int MOD = 1000000007;
const int dx[4] = {0, 1, 0, -1}, dy[4] = {-1, 0, 1, 0};
const int Dx[8] = {0, 1, 1, 1, 0, -1, -1, -1}, Dy[8] = {-1, -1, 0, 1, 1, 1, 0, -1};
#define yes cout << "Yes" << endl
#define YES cout << "YES" << endl
#define no cout << "No" << endl
#define NO cout << "NO" << endl
#define rep(i, n) for (int i = 0; i < n; i++)
#define ALL(v) v.begin(), v.end()
#define debug(v)          \
    cout << #v << ":";    \
    for (auto x : v)      \
    {                     \
        cout << x << ' '; \
    }                     \
    cout << endl;
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;
}
//cout<<fixed<<setprecision(15);有効数字15桁
//-std=c++14
ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }
ll lcm(ll a, ll b) { return a / gcd(a, b) * b; }
int n, m;
vector<int> a;
string s;
int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll k;
    cin >> s >> k;
    ll ans = 0;
    if (s.size() == 1)
    {
        cout << k / 2 << "\n";
        return 0;
    }
    bool check = false;
    for (int i = 1; i < s.size(); i++)
    {
        if (s[i] == s[i - 1] && !check)
        {
            ans++;
            check = true;
        }
        else
        {
            check = false;
        }
    }
    ll seq = 1, seqb = 1;
    for (int i = 0; i < s.size() - 1; i++)
    {
        if (s[i] == s[i + 1])
            seq++;
            else{
            break;
        }
    }
    for (int i = s.size() - 1; i >= 1; i--)
    {
        if (s[i] == s[i - 1])
            seqb++;
        else{
            break;
        }
    }
    if(seq==s.size())return cout<<s.size()*k/2<<"\n",0;
    if (s[0] == s[s.size() - 1])
    {
        //cout<<ans*k<<" "<<seq/2*k<<" "<<seqb/2*k<<" "<<(seq+seqb)/2*k<<"\n";
        cout<<ans*k-seq/2*(k-1)-seqb/2*(k-1)+(seq+seqb)/2*(k-1)<<"\n";
        return 0;
    }
    cout << ans*k << "\n";
}


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

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

#define ira(a, b, c) (a <= b && b < c)

int main(){
    int h, w, c = 0;
    cin >> h >> w;
    char arr[h][w];
    for(int i = 0; i < h; i++){
        for(int j = 0; j < w; j++){
            cin >> arr[i][j];
            if(arr[i][j] == '#') c++;
        }
    }
    queue< pair<int,int> > q;
    q.push({ 0, 0 });
    int r = 0;
    while(q.size()){
        int ps = q.size();
        while(ps--){
            int vi = q.front().first, vj = q.front().second;
            if(vi == h-1 && vj == w-1){
                cout << (h*w - (r+1) - c) << '\n';
                return 0;
            }
            q.pop();
            for(int i = 0; i < 4; i++){
                if(ira(0, vi + dx[i], h) && ira(0, vj + dy[i], w)
                        && arr[vi + dx[i]][vj + dy[i]] == '.'){
                    arr[vi + dx[i]][vj + dy[i]] = '#';
                    q.push({ vi + dx[i], vj + dy[i] });
                }
            }
        }
        r++;
    }
    cout << "-1\n";
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>

using namespace std;

int main(){
    int n;
    cin >> n;
    int d[n];
    for(int i = 0; i < n; i++) cin >> d[i];
    sort(d, d+n);
    cout << d[n/2] - d[n/2-1] << endl;
    return 0;
}

Measured memory_bytes: 640
#include <stdio.h>

typedef struct
{
    int face[6];

} Dice;

void rotate(char operation, Dice* dice)
{
    int move;
    switch(operation)
    {
        case 'N': move = 1; break;
        case 'S': move = 4; break;
        case 'E': move = 3; break;
        case 'W': move = 2; break;
        default : break;
    }

    int temp = dice->face[0];
    dice->face[0]      = dice->face[move];
    dice->face[move]   = dice->face[5];
    dice->face[5]      = dice->face[5-move];
    dice->face[5-move] = temp;
}

int main(void)
{
    Dice dice;
    char operation[101];
    
    int i;
    for(i = 0; i < 6; ++i) scanf("%d", &dice.face[i]);
    scanf("%s", &operation);

    int temp;
    for(i = 0; operation[i] != '\0'; ++i) rotate(operation[i], &dice);

    printf("%d\n", dice.face[0]);
    return 0;
}

Measured memory_bytes: 596
n = int(input())

s = []

for i in range(n):
    s.append(''.join(sorted(input())))

t = {}
for i in range(n):
    if s[i] in t:
        t[s[i]] += 1
    else:
        t[s[i]] = 1

print(sum(t[k]*(t[k]-1)//2 for k in t)) # t[k] Combi 2のlistのsumが答えになる


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

public class Main {

	public static void main(String[] args) throws IOException {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		
		String line = br.readLine();
		String[] oneline = line.split(" ");
		
		int[] data = {0,0};
		
		for(int i=0; i<oneline.length; i++){
			data[i] = Integer.parseInt(oneline[i]);
		}
		
		int area = data[0] * data[1];
		int length = 2 *(data[0]+data[1]);
		
		System.out.println(area +" "+ length);
	}
}

Measured memory_bytes: 24212
#最大公約数
def gcd(a, b):
    while b != 0:
        a, b = b, a % b
    return a

#最大公約数の個数
def ngcd(a):
    res = a[0]
    for i in range(len(a)):
        if res != 1:
            res = gcd(a[i], res)
    return res

#最小公倍数
def lcm(a,b):
    return a * b // gcd(a, b)

#最小公倍数の個数
def nlcm(a):
    res = a[0]
    for i in range(len(a)):
        res = lcm(res, a[i])
    return res

n = int(input())
a = list(map(int, input().split()))

res = 1
for i in range(n):
    res = lcm(res, a[i])

res -= 1
ans = 0
for i in range(n):
    ans += res % a[i]
print(ans)


Measured memory_bytes: 3316
// AOJ 2912: Sum of QQ
// 2019.2.23 bal4u

#include <stdio.h>
#include <stdlib.h>
#include <math.h>

int combi(int b)
{
	int p, q, ans;

	b <<= 1, ans = 0;
	for (p = (int)sqrt(b); p > 0; p--) {
		if (b % p == 0) {
			q = b / p;
			if ((p + q) & 1) ans++;
		}
	}
	return ans;
}

int main()
{
	int S, x, y, lim, ans;

	scanf("%d", &S);
	ans = 0;
	lim = (int)sqrt(S);
	for (x = 1; x <= lim; x++) {
		if (S % x == 0) {
			y = S / x;
			if (x == y) {
				int k = combi(x);
				ans += k * k;
			} else ans += 2 * combi(x)*combi(y);
		}
	}
	printf("%d\n", ans);
	return 0;
}


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

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

int main() {

    int A, B, C, X, Y;
    cin >> A >> B >> C >> X >> Y;

    int ans = 0;
    if (A + B >= 2 * C) {
        int mi = min(X, Y);
        ans += mi * 2 * C;
        X -= mi;
        Y -= mi;

        if (!(X == Y && X == 0)) {
            if (X == 0) {
                if (B <= 2 * C)
                    ans += B * Y;
                else
                    ans += 2 * C * Y;
            } else {
                if (A <= 2 * C)
                    ans += A * X;
                else
                    ans += 2 * C * X;
            }
        }
    } else {
        ans += A * X + B * Y;
    }

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <set>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define reps(i, s, n) for (int i = s; i < (int)(n); i++)
#define out(x) cout << x << endl
#define INF 1000000;
#include <map>
#include <math.h>
 
using ll = long long;
using namespace std;

ll n, k;
const ll mod = 1000000007;

int main(){
   string c1, c2, c3;
   cin >> c1 >> c2 >> c3;
   cout << c1[0] << c2[1] << c3[2]<< endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ll          long long
#define vl          vector<ll>
#define vi          vector<int>
#define pi          pair<int,int>
#define pl          pair<ll,ll>
#define all(a)      a.begin(),a.end()
#define mem(a,x)    memset(a,x,sizeof(a))
#define pb          push_back
#define mp          make_pair
#define F           first
#define S           second
#define endl 		"\n"
#define rep(i,a,b)  for(int i=a;i<b;i++)
#define fast_io     std::ios::sync_with_stdio(false),cin.tie(NULL),cout.tie(NULL)
#define trace(...) ZZ(#__VA_ARGS__, __VA_ARGS__);
template <typename Arg1> void ZZ(const char* name, Arg1&& arg1) {std::cerr << name << " = " << arg1 << endl;}
template <typename Arg1, typename... Args>void ZZ(const char* names, Arg1&& arg1, Args&&... args)
{
	const char* comma = strchr(names + 1, ',');
	std::cerr.write(names, comma - names) << " : " << arg1;
	ZZ(comma, args...);
}

void solve() {
	ll n;
	cin >> n;
	ll ret = 1;
	double d = 0;
	vl a(n);
	rep(i, 0, n) {
		cin >> a[i];
		if (a[i] == 0) {
			cout << 0;
			return;
		}
		double t = log10(a[i]);
		d += t;
	}
	if (d > 18.1) {
		cout << -1;
		return;
	}
	ll m = 1e18;
	rep(i, 0, n) {
		ll x;
		x = a[i];
		if (ret * x > m) {cout << -1; return;}
		ret *= x;
	}
	cout << ret;
}
int main() {
	fast_io;
	int t = 1;
	// cin>>t;
	while (t--) {
		solve();
	}
	// cerr << "Time elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " s.\n";
	return 0;
}

Measured memory_bytes: 4012
#include <iostream>
#include <array>
#include <algorithm>
#include <vector>
#include <set>
#include <unordered_set>
#include <cmath>
#include <complex>
#include <deque>
#include <iterator>
#include <numeric>
#include <map>
#include <unordered_map>
#include <queue>
#include <stack>
#include <string>
#include <tuple>
#include <utility>
#include <limits>
#include <iomanip>
using namespace std;

using ll=long long;
template<class T> using V = vector<T>;
template<class T, class U> using P = pair<T, U>;
using vll = V<ll>;
using vvll = V<vll>;
#define rep(i, k, n) for (ll i=k; i<(ll)n; ++i)
#define REP(i, n) rep(i, 0, n)
#define ALL(v) v.begin(),v.end()
template<class T> inline bool chmax(T& a, T b) {if (a<b) {a=b; return true;} return false;}
template<class T> inline bool chmin(T& a, T b) {if (a>b) {a=b; return true;} return false;}

const ll MOD = 1000000007;
const ll HIGHINF = (ll)1e18;

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll n; cin >> n;
    vll a(n), b(n), c(n);
    REP(i, n) cin >> a[i] >> b[i] >> c[i];
    vvll dp(n, vll(3, 0));
    dp[0][0] = a[0]; dp[0][1] = b[0]; dp[0][2] = c[0];
    rep(i, 1, n) {
        dp[i][0] = max(dp[i-1][1]+a[i], dp[i-1][2]+a[i]);
        dp[i][1] = max(dp[i-1][0]+b[i], dp[i-1][2]+b[i]);
        dp[i][2] = max(dp[i-1][0]+c[i], dp[i-1][1]+c[i]);
    }
    cout << max({dp[n-1][0], dp[n-1][1], dp[n-1][2]}) << '\n';
    return 0;
}


Measured memory_bytes: 8064
# -*- coding: utf-8 -*-

import sys
import subprocess
import json
import time
import math
import re
import sqlite3

N = int(input())
a = [int(input()) - 1 for i in range(N)]

visited = [False] * N
cur = 0
cnt = 0
while True:
    if visited[cur]:
        print(-1)
        exit(0)    
    if cur == 1:
        print(cnt)
        exit(0)

    visited[cur] = True    
    cur = a[cur]
    cnt += 1


Measured memory_bytes: 10148
#include<algorithm>
#include<iostream>
#include<cstdio>
#include<map>
#include<set>
using namespace std;
string s, t;
set<string> S;

void Work()
{
    int lens = s.size();
    int lent = t.size();
    for(int i = 0; i < lens; i++)
    {
        if(s[i] == '?' || s[i] == t[0])
        {
            string tmp = s;
            for(int j = 0; j < i; j++)
                if(tmp[j] == '?')
                    tmp[j] ='a';
            bool can = false;
            for(int j = 0; j < lent; j++)
            {

                if(tmp[i+j]!= '?' && tmp[i+j] != t[j])
                    break;
                tmp[i+j] = t[j];
                if(j == lent - 1) can = true;
            }
            if(can)
            {
                for(int j = i + lent; j < lens; j++) if(tmp[j] == '?') tmp[j] = 'a';
                S.insert(tmp);
            }
        }
    }
    if(S.size() == 0) cout << "UNRESTORABLE" << endl;
    else cout << *S.begin() << endl;
}
int main()
{
    cin >> s >> t;
    Work();
}

Measured memory_bytes: 256
#include <iostream>
#include <bits/stdc++.h>
#include <queue>
#include <stack>
#include <vector>
#define loop(n) for(ll i=0;i<n;i++)
#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);
using namespace std;
typedef long long int ll;

ll expo(ll a,ll b)
{
    ll result = 1;
    ll hold = a;
    while (b >= 1)
    {
        if(b%2 != 0)
        {
            result *= a;
        }
        b /= 2;
        a *= a;
    }
    return result;
}

int main()
{
    fastio;
    ll a;
    cin>>a;
    cout<<a+a*a+a*a*a<<endl;
    return 0;
}

Measured memory_bytes: 3616
#include<bits/stdc++.h>
using namespace std;
int main(){
    string s,s1,s2;
    cin>>s;
    s1=s.substr(0,2),s2=s.substr(2,4);
    bool b1="01"<=s1&&s1<="12",b2="01"<=s2&&s2<="12";
    cout<<(b1?b2?"AMBIGUOUS":"MMYY":b2?"YYMM":"NA")<<endl;
}


Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<algorithm>
using namespace std;
int n,m,cnt[4],num[26];
char s[110];
int main(){
	scanf("%d%d",&n,&m);
	for (int i=1;i<=n;++i){
		scanf("%s",s+1);
		for (int j=1;j<=m;++j) ++num[s[j]-'a'];
	}
	for (int i=0;i<26;++i) ++cnt[num[i]%4];
	if ((n&1)&&(m&1)){
		puts(cnt[1]+cnt[3]<=1&&cnt[2]+cnt[3]<=(n+m)/2-1?"Yes":"No");
	}else if ((n&1)||(m&1)){
		if (m&1) swap(n,m);
		puts(cnt[1]+cnt[3]==0&&cnt[2]<=m/2?"Yes":"No");
	}else{
		puts(cnt[1]+cnt[2]+cnt[3]==0?"Yes":"No");
	}
	return 0;
}

Measured memory_bytes: 256
#include<stdio.h>

int main(void)
{

    int W,H,x,y,r;

    scanf("%d %d %d %d %d",&W,&H,&x,&y,&r);

    if(x - r < 0 || y - r < 0 || x + r > W || y + r > H)
      printf("No\n");
    else
      printf("Yes\n");

    return 0;
}


Measured memory_bytes: 2704