akhauriyash/Code-Regression huggingface dataset:
#![allow(unused_imports, unused_macros, dead_code)]

macro_rules! min {
    (.. $x:expr) => {{
        let mut it = $x.iter();
        it.next().map(|z| it.fold(z, |x, y| min!(x, y)))
    }};
    ($x:expr) => ($x);
    ($x:expr, $($ys:expr),*) => {{
        let t = min!($($ys),*);
        if $x < t { $x } else { t }
    }}
}
macro_rules! max {
    (.. $x:expr) => {{
        let mut it = $x.iter();
        it.next().map(|z| it.fold(z, |x, y| max!(x, y)))
    }};
    ($x:expr) => ($x);
    ($x:expr, $($ys:expr),*) => {{
        let t = max!($($ys),*);
        if $x > t { $x } else { t }
    }}
}


macro_rules! ewriteln {
    ($($args:expr),*) => { let _ = writeln!(&mut std::io::stderr(), $($args),*); };
}
macro_rules! trace {
    ($x:expr) => { ewriteln!(">>> {} = {:?}", stringify!($x), $x) };
    ($($xs:expr),*) => { trace!(($($xs),*)) }
}
macro_rules! put {
    (.. $x:expr) => {{
        let mut it = $x.iter();
        if let Some(x) = it.next() { print!("{}", x); }
        for x in it { print!(" {}", x); }
        println!("");
    }};
    ($x:expr) => { println!("{}", $x) };
    ($x:expr, $($xs:expr),*) => { print!("{} ", $x); put!($($xs),*) }
}

const M: i64 = 1_000_000_007;

fn main() {
    let mut sc = Scanner::new();
    let n: usize = sc.cin();
    let mut xs:Vec<(usize, usize)>= (0..n).map(|i| (sc.cin(), i)).collect();
    xs.sort();
    let ans: Vec<usize> = xs.iter().map(|&item| item.1 + 1).collect();
    put!(..ans);
}

use std::io::{self, Write};
use std::str::FromStr;
use std::collections::VecDeque;

struct Scanner { stdin: io::Stdin, buffer: VecDeque<String>, }
impl Scanner {
    fn new() -> Self { Scanner { stdin: io::stdin(), buffer: VecDeque::new() } }
    fn cin<T: FromStr>(&mut self) -> T {
        while self.buffer.len() == 0 {
            let mut line = String::new();
            let _ = self.stdin.read_line(&mut line);
            for w in line.split_whitespace() {
                self.buffer.push_back(String::from(w));
            }
        }
        self.buffer.pop_front().unwrap().parse::<T>().ok().unwrap()
    }
}


Measured memory_bytes: 12540
#include <bits/stdc++.h>
using namespace std;
#define FOR(i, s, e) for (int(i) = (s); (i) < (e); (i)++)
#define FORR(i, s, e) for (int(i) = (s); (i) > (e); (i)--)
struct csf{
    int C;
    int S;
    int F;
    int time;
};
int main() {
    cin.tie(0);
    ios_base::sync_with_stdio(false);
    struct csf train[505];
    int n;
    cin >> n;
    FOR(i,1,n){
        cin >> train[i].C >> train[i].S >> train[i].F;
        train[i].time =0;
    }
    train[n].time =0;
    FOR(i,1,n){
        train[i].time = train[i].S + train[i].C;
        FOR(j,1,i){
            if(train[j].time <= train[i].S) {
                train[j].time = train[i].S + train[i].C;
            }else{
                if(train[j].time%train[i].F == 0)
                    train[j].time--;
                train[j].time /= train[i].F;
                train[j].time = (train[j].time + 1)*train[i].F + train[i].C;
            }
        }
    }
    FOR(i,1,n){
        cout << train[i].time << endl;
    }
    cout << 0;
    return 0;
}

Measured memory_bytes: 256
using System;
using System.Linq;
using System.Collections.Generic;
using System.Numerics;

namespace ABC175
{
    class Program
    {
        static void Main(string[] args)
        {
            //var NK = Console.ReadLine().Split().Select(long.Parse).ToArray();
            // var N = NK[0]; var K = NK[1];
            // var A = Console.ReadLine().Split().Select(long.Parse).OrderBy(x => x).ToArray();
            // var CA = Enumerable.Repeat(0, (int)N).Select(_ => Console.ReadLine().Split().Select(long.Parse).ToArray()).ToArray();
            var S = Console.ReadLine();
            var ans = 0;
            /*
            for (int i = 0; i < 3; i++)
            {
                if(i == 0 && S[i] == 'R') ans++;
                else if(S[i-1] == 'R' && S[i] == 'R') ans++;
                
            }
            */

            if(S == "SSS") ans = 0;
            if(S == "RSS") ans = 1;
            if(S == "SRS") ans = 1;
            if(S == "SSR") ans = 1;
            if(S == "SRR") ans = 2;
            if(S == "RRS") ans = 2;
            if(S == "RSR") ans = 1;
            if(S == "RRR") ans = 3;

            Console.WriteLine(ans);
        }
    }
}


Measured memory_bytes: 25692
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <cmath>
#include <stack>
#include <queue>
#include <functional>
#include <set>
#include <map>
#include <tuple>
#include <bitset>
#include <random>
#define REP(i,n) for(int i=0;i<n;i++)
#define INF 100000000000007
using namespace std;
using pii=pair<int,int>;
using LL=int64_t;





int main(){
    int h,w,k;
    cin>>h>>w>>k;
    vector<vector<char>> c(h,vector<char>(w));
    REP(i,h){
        REP(j,w){
            cin>>c.at(i).at(j);
        }
    }

    
    int ans=0;
    // {0, 1, ..., h-1} の部分集合の全探索
    for (int bit = 0; bit < (1<<h); ++bit)
    {
        /* bit で表される集合の処理を書く */
        for (int bit2 = 0; bit2 < (1<<w); ++bit2)
        {
            /* bit で表される集合の処理を書く */
            int count=0;
            REP(i,h){
                REP(j,w){
                    if(!(bit & (1<<i))&&!(bit2 & (1<<j))){
                        if(c.at(i).at(j)=='#'){
                            count++;
                        }
                    }
                    

                }
            }

            if(count==k){
                ans++;
            }


        }

    }


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

Measured memory_bytes: 3176
#include <iostream> // cout, endl, cin
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower
#include <cmath>
#include <iomanip>

using namespace std;
using ll = long long;

#define rep(i,N) for(int i=0;i<(int)N;++i)

#include <iostream>

int main()
{
	string S;
	cin >> S;
	if (S[0] == S[1] && S[1]!=S[2] && S[2] == S[3]) { cout << "Yes" << endl; }
	else if (S[0] == S[2] && S[2]!=S[1] && S[1] == S[3]) { cout << "Yes" << endl; }
	else if (S[0] == S[3] && S[3]!=S[1] && S[1] == S[2]) { cout << "Yes" << endl; }
	else { cout << "No" << endl; }
}


Measured memory_bytes: 256
#include<stdio.h>
int main(void){
    int a, b;
    scanf("%d %d", &a, &b);
    if (a < b)
    {
        printf("a < b\n");
    }
    else if (a == b)
    {
        printf("a == b\n");
    }
    else
    {
        printf("a > b\n");
    }
    return 0;
}


Measured memory_bytes: 2056
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>

using namespace std;

int main()
{
    string s;
    int k, ssize, a;
    vector<string> str;

    cin >> s;
    cin >> k;

    ssize = min(k, (int)s.length()); //s.length();
    a = 0;
    while (ssize > 0)
    {
        for (int i = 0; i < s.length() - ssize + 1; i++)
        {
            string tmp = s.substr(i, ssize);
            int j = a;
            bool b = true;
            if (str.size() != 0 && str[0] == tmp)
                b = false;
            if (b)
                while (str.size() != 0 && j < str.size() && str[j] < tmp)
                {

                    j++;
                    if (j < str.size() && str[j] == tmp)
                        b = false;
                }

            if (b)
            {
                str.insert(str.begin() + j, tmp);
            }
        }

        a = 0; //str.size();

        ssize--;
    }

    cout << str[k - 1] << endl;
    //for (int i = 0; i < str.size(); i++)
    //    cout << str[i] << endl;

    return 0;
}

Measured memory_bytes: 1024
import java.util.Scanner;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

public class Main {
	public static void main(String[] args) {
		Scanner in = new Scanner(System.in);
		Pattern pt = Pattern.compile("Hoshino");
		Matcher mc = pt.matcher("");
		in.nextLine();
		while (in.hasNextLine()) {
			mc.reset(in.nextLine());
			System.out.println(mc.replaceAll("Hoshina"));
		}
	}
}

Measured memory_bytes: 12000
n,a,b = map(int, input().split())
ans = 0

def sum(k):
  s = 0
  for j in range(len(k)):
    s+=int(k[j])
  return s

for i in range(1,n+1):
  if a<=sum(str(i))<=b:
    ans+=i
print(ans)


Measured memory_bytes: 3060
#include<bits/stdc++.h>
using namespace std;
int main(){
  int N,count=0,xmin=1000000000;
  int64_t sum=0;
  cin>>N;
  vector<int> A(N);
  for(int i=0;i<N;i++){
    cin>>A.at(i);
    if(A.at(i)>=0){
      sum+=A.at(i);
      xmin=min(xmin,A.at(i));
      }
    else{
      sum+=-A.at(i);
      xmin=min(xmin,-A.at(i));
      count++;
      }
    }
  if(count%2==0)
    cout<<sum<<endl;
  else
    cout<<sum-2*xmin<<endl;
  }


Measured memory_bytes: 640
//region Template
#include <bits/stdc++.h>
using namespace std;
#ifdef LOCAL
template<typename T> void debug_out(string name, T arg) { cerr<<name<<"="<<arg<<endl; }
template<typename T1, typename... T2> void debug_out(string name, T1 arg, T2... args) {
    cerr<<name.substr(0, name.find(','))<<"="<<arg<<", ";
    debug_out(name.substr(name.find(',') + 1), args...); }
#define debug(...) debug_out(#__VA_ARGS__, __VA_ARGS__)
#else
#define debug(...) 42
#endif
#define FASTIO ios_base::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr); cout<<fixed<<setprecision(12);
#define FOR(i, n) for(int i=0; i<int(n); i++)
#define RNG(i, f, t) for(int i=int(f); i<=int(t); i++)
#define REV(i, f, t) for(int i=int(f); i>=int(t); --i)
#define ALL(v) (v).begin(), (v).end()
#define EXIT(answer) { cerr<<"EXIT #"<<__LINE__<<endl; cout<<answer<<endl; exit(0); }
#define sz(v) int(v.size())
bool RELAXED = false;
template<int,typename T> struct MINMAX{ T val; MINMAX(T val) : val(val) {} };
template<typename T> MINMAX<1,T> MAX(T val) { return MINMAX<1,T>(val); };
template<typename T> MINMAX<2,T> MIN(T val) { return MINMAX<2,T>(val); };
template<typename T, typename U> inline T& operator|=(T &lhs, MINMAX<1,U> rhs) { return lhs = (rhs.val > lhs ? (RELAXED=true,rhs.val) : (RELAXED=false,lhs)); }
template<typename T, typename U> inline T& operator|=(T &lhs, MINMAX<2,U> rhs) { return lhs = (rhs.val < lhs ? (RELAXED=true,rhs.val) : (RELAXED=false,lhs)); }
template<typename T, typename U> istream& operator>>(istream& in, pair<T,U> &p) { in>>p.first>>p.second; return in; }
template<typename T> inline vector<T> READ(int n) { vector<T> vec(n); FOR(i,n) cin>>vec[i]; return vec; }
template<typename T> using min_heap = priority_queue<T, vector<T>, greater<T> >;
typedef signed long long int ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<pii> vpii;
typedef vector<pll> vpll;
//endregion


ll dp[2005][2005];

int main() {
    FASTIO

    int n; cin>>n;
    vi a = READ<int>(n);

    vpii p;
    FOR(i,n)
        p.push_back({a[i], i});
    sort(ALL(p));
    reverse(ALL(p));

    FOR(i,n) {
        pii pi = p[i];
        FOR(l,i+1) {
            int r = n-1-i+l;
            dp[i+1][l+1] |= MAX(dp[i][l] + 1LL* pi.first * abs(pi.second-l));
            dp[i+1][l] |= MAX(dp[i][l] + 1LL*pi.first * abs(pi.second-r));
        }
    }

    cout<<*max_element(dp[n], dp[n]+2005)<<endl;



}

Measured memory_bytes: 26340
#include<stdio.h>
#define MAX 2000000
int kazu,A[MAX+1];
void swap(int *a,int *b);
void maxheapify(int i){
  int l,r,largest;
  l=2*i;
  r=2*i+1;

  if(l<=kazu && A[l]>A[i])largest=l;
  else largest=i;
  if(r<=kazu && A[r]>A[largest])largest=r;

  if(largest!=i){
    swap(&A[i],&A[largest]);
    maxheapify(largest);
  }
}

int main(){
  scanf("%d",&kazu);
  for(int i=1;i<=kazu;i++)scanf("%d",&A[i]);
  for(int i=kazu/2;i>=1;i--)maxheapify(i);
  for(int i=1;i<=kazu;i++){
    printf(" %d",A[i]);
  }
  printf("\n");
  return 0;
}
void swap(int *a,int *b){
  int temp;
  temp=*a;
  *a=*b;
  *b=temp;
}



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

int F[102][102];

void
DFS (int Y, int X, int A)
{
  if (F[Y][X] != A)
    return;

  F[Y][X] = 7;

  DFS (Y - 1, X, A);
  DFS (Y, X + 1, A);
  DFS (Y + 1, X, A);
  DFS (Y, X - 1, A);
}

int
main ()
{
  int w, h;
  int xs, ys;
  int xg, yg;
  int n;
  int c, d, x, y;

  while (true)
    {
      cin >> w >> h;
      if (w == 0 && h == 0)
	break;
      cin >> xs >> ys;
      cin >> xg >> yg;
      cin >> n;

      for (int i = 0; i < n; i++)
	{
	  cin >> c >> d >> x >> y;
	  if (d == 0)
	    {
	      for (int a = 0; a < 4; a++)
		{
		  for (int b = 0; b < 2; b++)
		    {
		      F[y + b][x + a] = c;
		    }
		}

	    }
	  else
	    {
	      for (int a = 0; a < 2; a++)
		{
		  for (int b = 0; b < 4; b++)
		    {
		      F[y + b][x + a] = c;
		    }
		}
	    }

	}


      if (F[ys][xs] == 1 || F[ys][xs] == 2 || F[ys][xs] == 3
	  || F[ys][xs] == 4 || F[ys][xs] == 5)
	{
	  DFS (ys, xs, F[ys][xs]);
	}

      if (F[yg][xg] == F[ys][xs])
	{
	  cout << "OK" << endl;
	}
      else
	{
	  cout << "NG" << endl;
	}

    }

  return 0;
}

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

int comp(const void *a,const void *b){
    return *(int *)a-*(int *)b;
}

main(){
    int N;
    scanf("%d",&N);
    int p[N];
    int i=0;
    while(i<N)scanf("%d",&p[i++]);

    qsort(p,N,sizeof(int),comp);
    int n=-1;
    int sum=0;
    for(i=0;i<N;i++){
        if(n!=p[i]){
            n=p[i];
            sum++;
        }else{
            n=-1;
            sum--;
        }
    }
    printf("%d\n",sum);
    return 0;
}

Measured memory_bytes: 892
#include<stdio.h>
#include <string.h>

int main(void)
{
    int len;
    int i;
    int score=0;
    int score2=0;
    int scoreb=0;
    int scorec=0;

    char text[100];
    scanf("%s",text);
    len = strlen(text);

    for(i=0;i<=len/2-1;i++){
        if(text[i]==text[len-i-1])
            score++;
    }
    
    if(score == (len-1)/2)
        score2++;
    
    for(i=0;i<=(len-1)/4-1;i++){
        if(text[i]==text[(len-1)/2-i-1])
            scoreb++;
    }

    if(scoreb == (len-1)/4)
        score2++;
    
    for(i=(len+3)/2-1;i<=(3*len+3)/4-1;i++){
        if(text[i]==text[len-1-i])
            scorec++;
    }
    
    if(scorec==(3*len+3)/4 - (len+3)/2 +1)
        score2++;
    
    if(score2 == 3)
        printf("Yes");
    else
        printf("No");

    
    return 0;
}

Measured memory_bytes: 128
#include<algorithm>
#include<cstdio>
using namespace std;
int n,ans,cur;
char s[110];
int main()
{
	scanf("%d %s",&n,s);
	for(int i=0;i<n;++i)
	{
		if(s[i]=='I')
		{
			++cur;
			ans=max(ans,cur);
		}
		else	--cur;
	}
	printf("%d",ans);
	return 0;
}

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

int main() {
  vector<int> a(5);
  for(int i=0;i<5;i++){
    cin>>a.at(i);
  }
  for(int i=0;i<5;i++){
    if(a.at(i)==0)
      cout<<i+1<<endl;
  }
}

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

int a[10005];

int main()
{
    int i, n, m, res, dif, sum;

    cin>>n>>m;

    sum=0;
    for(i=0; i<m; i++){
        cin>>a[i];
        sum = sum + a[i];
    }

    dif = n-sum;

    if(dif<0)
        cout<<-1<<endl;
    else
        cout<<dif<<endl;

    return 0;
}


Measured memory_bytes: 3672
# -*- coding: utf-8 -*-
import sys
from collections import deque, defaultdict
from math import sqrt, factorial, gcd
# def input(): return sys.stdin.readline()[:-1] # warning not \n
# def input(): return sys.stdin.buffer.readline().strip() # warning bytes
# def input(): return sys.stdin.buffer.readline().decode('utf-8')


def solve():
    n = int(input())
    a = [int(x)-1 for x in input().split()]
    ans = 0
    for i in range(n):
        if a[i] == i:
            if i + 1 < n:
                a[i], a[i+1] = a[i+1], a[i]
            else:
                a[i], a[i-1] = a[i-1], a[i]
            ans += 1

    print(ans)

t = 1
# t = int(input())
for case in range(1,t+1):
    ans = solve()


"""

abc

"""


Measured memory_bytes: 20832
#include <iostream>

using namespace std;

int main()
{
    int N, M, C;

    cin >> N >> M >> C;

    int coef[M];

    for (int i = 0;i < M; i++)
        cin >> coef[i];

    int ans = 0;
    int temp, temp_sum;
    for (int i =0; i < N; i++)
    {
        temp_sum = 0;
        for (int j = 0; j < M; j++)
        {
            cin >> temp;
            temp_sum+=temp*coef[j];
        }
        if (temp_sum+C>0)
            ans++;
    }

    cout << ans;

    return 0;
}


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

int main() {
  ll v,e;
  cin >> v >> e;
  vector<map<ll,ll>> E(v);
  for(ll i=0;i<e;i++) {
    ll s,t,dis;
    cin >> s >> t >> dis;
    E[s][t]=dis;
    E[t][s]=dis;
  }
  set<ll> al;
  al.insert(0);
  priority_queue<pll,vector<pll>,greater<pll>> q;
  for(auto p:E[0]) {
    q.push(pll(p.second,p.first));
  }
  ll ans=0;
  while(al.size()<v) {
    auto p=q.top();
    q.pop();
    if(al.count(p.second)) continue;
    ans+=p.first;
    al.insert(p.second);
    for(auto pp:E[p.second]) {
      q.push(pll(pp.second,pp.first));
    }
  }
  cout << ans << endl;
}


Measured memory_bytes: 20260
#include <iostream>
using namespace std;
int main(void){
    // Your code here!
    string s, t, u;
    cin >> s;
    int len = s.length();
    for (int i = 2; i < len; i += 2) {
        t = s.substr(0, (len - i) / 2);
        u = s.substr((len - i) / 2, (len - i) / 2);
        if (t == u) {
            cout << len - i << endl;
            break;
        }
    }
}


Measured memory_bytes: 256
#include "bits/stdc++.h"
#define rep(i,n) for(int i=0;i<(n);i++)
typedef long long ll;

using namespace std;

int main(){
 ll a,b,c,d,e,f;
 cin>>a;
 vector<ll>A(a);
 ll all=0;
 rep(i,a){
     cin>>A[i];
     all+=A[i];
 }
 ll ans=1000000000000000000;
 ll sum=0;
 rep(i,a){
     sum+=A[i];
    if(ans>abs(all-sum*2))ans=abs(all-sum*2);
}
 cout<<ans<<endl;
}


Measured memory_bytes: 1792
import sys
input = sys.stdin.readline
from collections import *

MOD = 10**9+7

class Comb:
    def __init__(self, N):
        self.fac = [1] * (N+1)
        for i in range(2, N+1): self.fac[i] = self.fac[i-1] * i % MOD

    def pow(self, a, b):
        res = 1
        while b:
            if b & 1: res = res * a % MOD
            a = a**2 % MOD
            b >>= 1
        return res

    def comb(self, n, r):
        if r < 0 or r > n: return 0
        return (self.fac[n] * self.pow(self.fac[r], MOD-2)) % MOD * self.pow(self.fac[n-r], MOD-2) % MOD

    def permutation(self, n, r):
        return self.fac[n] * self.pow(self.fac[n-r], MOD-2) % MOD

def main():
    N, K = list(map(int, input().split()))
    g = [[] for i in range(N+1)]
    ans = K

    for i in range(N-1):
        a, b = list(map(int, input().split()))
        g[a].append(b)
        g[b].append(a)

    comb = Comb(K)

    q = deque([(-1, 1)])
    while q:
        par, chi = q.pop()
        r = len(g[chi])-1
        if par == -1: k = K-1; r += 1
        else: k = K-2
        if k < r: ans = 0; break

        ans = ans * comb.permutation(k, r) % MOD
        for c in g[chi]:
            if c != par: q.append((chi, c))

    print(ans%MOD)
    
if __name__ == '__main__':
    main()


Measured memory_bytes: 39568
import java.util.*;
public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
      String[] nyu=sc.nextLine().split(" ");
//     String nyu=sc.nextLine();


int num=Integer.parseInt(nyu[0]);
int numnext=Integer.parseInt(nyu[1]);
int numend=Integer.parseInt(nyu[2]);

if(num*numnext<numend){



System.out.println(num*numnext);
}else{
System.out.println(numend);

}

//System.out.println(a/b);


	}
}

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

const int MOD = 1000000007;

//メモ化再帰

int H,W;
char a[1010][1010];

int dp[1010][1010];//dp[i][j]は、マス(i,j)からマス(H,W)への経路数

int search_way(int i,int j)
{
    if(i == H && j == W) return 1;
    else if(dp[i][j] == -1 && i + 1 <= H && j + 1 <= W){
        //else if(i == H -  && j == W - 1) return 1;
        //下と右のマスが壁なら
        if(a[i + 1][j] == '#' && a[i][j + 1] == '#') return dp[i][j] = 0;
        //下のマスだけが壁なら
        else if(a[i + 1][j] == '#' && a[i][j + 1] == '.') return dp[i][j] = search_way(i,j + 1)%MOD;
        //右のマスだけが壁なら
        else if(a[i + 1][j] == '.' && a[i][j + 1] == '#') return dp[i][j] = search_way(i + 1,j)%MOD;
        //行く手に壁がないとき
        else if(a[i + 1][j] == '.' && a[i][j + 1] == '.'){
         return dp[i][j] = (search_way(i + 1,j) + search_way(i,j + 1))%MOD;
       }
    }
    else if(i == H && j != W){
        //右のマスだけが壁なら
        if(a[i][j + 1] == '#') return dp[i][j] = 0;
        //行く手に壁がないとき
        else if(a[i][j + 1] == '.') return dp[i][j] = search_way(i,j + 1)%MOD;       
    }  
    else if(i != H && j == W){
        //下のマスだけが壁なら
        if(a[i + 1][j] == '#') return dp[i][j] = 0;
        //行く手に壁がないとき
        else if(a[i + 1][j] == '.')  return dp[i][j] = search_way(i + 1,j)%MOD;
    }
    return dp[i][j];
}


int main()
{
    cin >> H >> W;
    for(int i = 1; i <= H; i++){
        for(int j = 1; j <= W; j++){
            cin >> a[i][j];
            dp[i][j] = -1;
        }
    }
    cout << search_way(1,1);
   
    return 0;
}

Measured memory_bytes: 5376
#include <bits/stdc++.h>
#include <iostream>
#include <vector>
#include <string>
#include <deque>
#include <algorithm>

#define fr(i,b,e) for(int i=(b); i!=(e); ++i)
#define all(x) (x).begin(),(x).end()
using namespace std;
typedef long int li;
typedef long long ll;




int main(void){
    string s;
    string front;
    string back;
    int q;
    
    bool rev=false;

    cin >> s;
    cin >>q;

    front.reserve(q);
    back.reserve(q);

    int t,f;
    char c;

    fr(i,0,q){
        cin >> t;
        if(t==1){
            rev=!rev;
        }else{
            cin >> f >> c;
            if(f==1){
                if(rev==false){
                    front.push_back(c);
                }else{
                    back.push_back(c);
                }
            }else{
                if(rev==false){
                    back.push_back(c);
                }else{
                    front.push_back(c);
                }
            }
        }
    }

    if(rev==false){
        reverse(all(front));
        cout << front+s+back << endl;
    }else{
        reverse(all(back));
        reverse(all(s));
        cout << back+s+front << endl;
    }
}


Measured memory_bytes: 1244
import java.util.Scanner;

public class Main {

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

        int A = sc.nextInt();
		int B = sc.nextInt();
		int C = sc.nextInt();
		int X = sc.nextInt();
		int Y = sc.nextInt();
        System.out.println(calcMin(A, B, C, X, Y));
    }

    public static int calcMin(int A, int B, int C, int X, int Y) {
		int total = 0;

    	int pattern1, pattern2, pattern3;

    	// パターン１：全部AとBピザでまかなう
		pattern1 = A * X + B * Y;

		total = pattern1;

		// パターン２：ABピザでAピザを全てまかなう
		pattern2 = 2 * C * X;
		if (X < Y) {
			pattern2 = pattern2 + (Y-X) * B;
		}

    	total = Integer.min(total, pattern2);

		// パターン３：ABピザでBピザを全てまかなう
		pattern3 = 2 * C * Y;
		if (X > Y) {
			pattern3 = pattern3 + (X-Y) * A;
		}

		total = Integer.min(total, pattern3);

		return total;
	}

}


Measured memory_bytes: 23764
mod = (10**9) + 7
n = int(input())
a = [int(i) for i in input().split()]
if n % 2 == 1:
    t = [0]
    for i in range(2, n, 2):
        t.extend([i]*2)
else:
    t = [i for i in range(1, n, 2)]
    t.extend(t)
t.sort()
a.sort()
if a == t:
    ans = (2 ** (n//2)) % mod
else:
    ans = 0
print(ans)

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

#define ll long long
#define fw(p) for(int w=0;w<(p);w++)
#define fx(p) for(int x=0;x<(p);x++)
#define fy(p) for(int y=0;y<(p);y++)
#define fz(p) for(int z=0;z<(p);z++)
#define fyg(p,g) for(int y=(g);y<(p);y++)
#define fzg(p,g) for(int z=(g);z<(p);z++)
#define ce(d) cout<<d<<endl;
#define vecp(p) int aa;cin>>aa;(p).push_back(aa);
#define vecpl(p) long long aa;cin>>aa;(p).push_back(aa);
#define vecps(p) string aa;cin>>aa;(p).push_back(aa);
#define vecp2(p) cin>>aa;(p).push_back(aa);
#define vecpl2(p) long long a	b;cin>>ab;(p).push_back(ab);
#define vecps2(p) string ab;cin>>ab;(p).push_back(ab);
#define sorts(c) sort((c).begin(),(c).end());
#define reverses(c) reverse((c).begin(),(c).end());
#define vec(b) vector<int> (b);
#define vecl(b) vector<long long> (b);
#define vecs(b) vector<string> (b);
#define pb(b,a) (b).push_back((a));
#define doublece(a,b) cout<<(a)<<' '<<(b)<<endl;
#define pairs(s) vector<pair<int,int>> (s);
#define pairsp(s) int aa,bb;cin>>aa>>bb;(s).push_back(make_pair(aa,bb));
#define MOD 1000000007
#define cey ce("Yes")
#define cen ce("No")
#define ceY ce("YES")
#define ceN ce("NO")


int main()
{
	ll X;
	cin >> X;
	ce(X/500*1000+(X%500)/5*5)

    return 0;
}



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

#define int long long
#define rep(i, n) for (int i = 0; i < (int) (n); i++)
#define reps(i, n) for (int i = 1; i <= (int) (n); i++)
#define all(x) (x).begin(), (x).end()
#define uniq(x) (x).erase(unique(all(x)), (x).end()))
#define bit(n) (1LL << (n))
#define cdiv(a, b) (((a) - 1) / (b) + 1)
#define dump(x) cerr << #x " = " << (x) << endl
using vint = vector<int>;
using vvint = vector<vint>;
using pint = pair<int, int>;
using vpint = vector<pint>;
template<typename T> using priority_queue_rev = priority_queue<T, vector<T>, greater<T>>;
constexpr double PI = 3.1415926535897932384626433832795028;
constexpr int DY[8] = {0, 1, 0, -1, 1, 1, -1, -1};
constexpr int DX[8] = {1, 0, -1, 0, 1, -1, -1, 1};
int gcd(int a, int b) {
    while (b) { swap(a %= b, b); }
    return a;
}
int lcm(int a, int b) { return a / gcd(a, b) * b; }
template<typename T> void fin(T mes) {
    cout << mes << endl;
    exit(0);
}
template<typename T, typename U> bool chmax(T &a, const U &b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}
template<typename T, typename U> bool chmin(T &a, const U &b) {
    if (b < a) {
        a = b;
        return true;
    }
    return false;
}
template<typename T, typename U> ostream &operator<<(ostream &os, const pair<T, U> &rhs) {
    os << "(" << rhs.first << ", " << rhs.second << ")";
    return os;
}
template<typename T> ostream &operator<<(ostream &os, const vector<T> &rhs) {
    os << "{";
    for (auto itr = rhs.begin(); itr != rhs.end(); itr++) {
        os << *itr << (next(itr) != rhs.end() ? ", " : "");
    }
    os << "}";
    return os;
}
struct setup {
    static constexpr int PREC = 20;
    setup() {
        cout << fixed << setprecision(PREC);
        cerr << fixed << setprecision(PREC);
    };
} setup;

signed main() {
    int T;
    cin >> T;
    while (T--) {
        int N;
        cin >> N;
        vint A(N);
        string S;
        rep(i, N) { cin >> A[i]; }
        cin >> S;
        bool ans = true;
        rep(i, N) {
            if (S[i] == '1') {
                int x = A[i];
                vint B;
                for (int j = i + 1; j < N; j++) { if (S[j] == '0') { B.push_back(A[j]); }}
                for (int k = 63; k >= 0; k--) {
                    int idx = -1;
                    rep(j, B.size()) { if (B[j] & bit(k)) { idx = j; }}
                    if ((x & bit(k)) && idx == -1) {
                        ans = false;
                        break;
                    }
                    if ((x & bit(k)) &&idx != -1) { x ^= B[idx]; }
                    rep(j, B.size()) { if (B[j] & bit(k)) { B[j] ^= B[idx]; }}
                }
            }
        }
        if (ans) { cout << 0 << endl; }
        else { cout << 1 << endl; }
    }
}

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

int main(){
	int n;
	while(cin >> n){
		int cnt = 0;
	for(int a = 0;a <= 9;a++){
		for(int b = 0;b <= 9;b++){
			for(int c = 0;c <= 9;c++){
				for(int d = 0;d <= 9;d++){
					if((a + b + c + d) == n){
						cnt++;
					}
				}
			}
		}
	}
	cout << cnt <<endl;
	}


return 0;
}

Measured memory_bytes: 3084
#include <iostream> // cout, endl, cin
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower
#define _GLIBCXX_DEBUG // check []
#define DIVISOR 1000000007

using namespace std;
typedef pair<int,int> pii;
typedef pair<int64_t, int64_t> pII;

template<typename T>
void cins(vector<T>& arr) { for(T& e: arr) cin >> e; }

#ifdef DEBUG
#define debug(fmt, ...) \
    printf("[debug: %s] " fmt, __func__, __VA_ARGS__)
#else
#define debug(fmt, ...)
#endif

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


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

int main(int argc, char **argv) {
	string s;
	string s2 = "CODEFESTIVAL2016";
	cin >> s;
	int cnt = 0;
	for (int i = 0; i < 16; ++i) {
		if(s[i] != s2[i]) { cnt ++; }
	}
	cout << cnt << endl;
}


Measured memory_bytes: 256
#include <stdio.h>

int main(){

  int S[101][101],i,j,n,a,b,c;

  scanf("%d",&n);

  for(i=0;i<n;i++){
    for(j=0;j<n;j++){
      S[i][j]=0;
    }
  }

  for(i=0;i<n;i++){
    scanf("%d %d",&a,&b);
    for(j=0;j<b;j++){
      scanf("%d",&c);
      S[a-1][c-1]=1;
    }
  }

  for(i=0;i<n;i++){
    for(j=0;j<n;j++){
      if(j==0) printf("%d",S[i][j]);
      else printf(" %d",S[i][j]);
    }
    printf("\n");
  }

  return 0;
  
}

Measured memory_bytes: 640
#include<iostream>
#include<algorithm>
#include<vector>
#include<queue>
#include<cmath>
#include<tuple>
#include<string>
typedef long long ll;
#define rep(i,a,b) for(ll i=(a);i<(b);i++)
#define repm(i,a,b) for(int i=(a);i>(b);i--)
#define F first
#define S second
using namespace std;
const ll INF = 1e12;
const double PI = 3.1415926535897932;
const int i_INF = 2147483647;
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; }


int main() {
	int n;
	cin >> n;
	cout << (n-1) / 2 << endl;
	return 0;
}

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

using namespace std;

typedef long long ll;

int main() {
    ll n, m, d;
    cin >> n >> m >> d;
    long double ans = n - max(0LL, 2 * d - n);
    if (d) {
        ans += max(0LL, n - 2 * d);
    }
    ans *= m - 1;
    ans /= n * n;
    cout << setprecision(20) << fixed << ans;
    return 0;
}


Measured memory_bytes: 256
import core.bitop, std.algorithm, std.ascii, std.bigint, std.conv, std.math,
    std.functional, std.numeric, std.range, std.stdio, std.string, std.random,
    std.typecons, std.container, std.format;

// dfmt off
T lread(T = long)(){return readln.chomp.to!T();}
T[] aryread(T = long)(){return readln.split.to!(T[])();}
void scan(TList...)(ref TList Args){auto line = readln.split();
foreach (i, T; TList){T val = line[i].to!(T);Args[i] = val;}}
alias sread = () => readln.chomp();enum MOD = 10 ^^ 9 + 7;
alias PQueue = BinaryHeap!(Array!long, "a<b");
// dfmt on

void main()
{
    long N = lread();
    long ma, mb;
    scan(ma, mb);
    foreach (_; 1 .. N)
    {
        long a, b;
        scan(a, b);
        if (ma < a)
        {
            ma = a;
            mb = b;
        }
    }
    writeln(ma + mb);
}


Measured memory_bytes: 1276
/*
これを入れて実行
g++ code.cpp
./a.out
 */
 
#include <iostream>
#include <stdio.h>
#include <vector>
#include <string>
#include <cstring>
#include <queue>
#include <deque>
#include <algorithm>
#include <utility>
#include <set>
#include <map>
#include <unordered_map>
#include <cmath>
#include <math.h>
#include <tuple>
#include <iomanip>
#include <bitset>
#include <functional>

#define all(x) (x).begin(),(x).end()
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
 
using namespace std;
typedef long long ll;
typedef long double ld;
 
int dy4[4] = {-1, 0, +1, 0};
int dx4[4] = {0, +1, 0, -1};
int dy8[8] = {-1, -1, 0, 1, 1, 1, 0, -1};
int dx8[8] = {0, 1, 1, 1, 0, -1, -1, -1};
 
const long long INF = 1LL << 62;
const ll MOD = 1e9 + 7;
 
bool greaterSecond(const pair<int, int>& f, const pair<int, int>& s){
    return f.second > s.second;
}
 
ll gcd(ll a, ll b){
	if (b == 0)return a;
	return gcd(b, a % b);
}
 
ll lcm(ll a, ll b){
    return a / gcd(a, b) * b;
}
 
ll nCr(ll n, ll r){
    if(r == 0 || r == n){
        return 1;
    } else if(r == 1){
        return n;
    }
    return (nCr(n - 1, r) + nCr(n - 1, r - 1));
}
 
ll nPr(ll n, ll r){
    r = n - r;
    ll ret = 1;
    for (ll i = n; i >= r + 1; i--) ret *= i;
    return ret;
}
 
//-----------------------ここから-----------
int main(void){
    ll n, d, a;
    cin >> n >> d >> a;

    vector<pair<ll,ll>> vec(n);
    rep(i, n){
        ll x, h;
        cin >> x >> h;
        vec[i] = {x, h};
    }

    sort(all(vec));

    vector<ll> point(n);
    rep(i, n) point[i] = vec[i].first;

    queue<pair<ll,ll>> q;
    q.push({0, -1});
    ll nowd = 0;
    ll ans = 0;
    rep(i, n){
        while(!q.empty() && q.front().second < point[i]){
            nowd -= q.front().first;
            q.pop();
        }
        //ll r = lower_bound(all(point), point[i] + 2 * d) - point.begin();
        ll nec = 0;
        if(vec[i].second - nowd >= 0){
            if((vec[i].second - nowd) % a == 0){
                nec = (vec[i].second - nowd) / a;
            } else {
                nec = (vec[i].second - nowd) / a + 1;
            }
        }

        //cout << i << " " << nec <<  " " << nowd << endl;
        nowd += a * nec;
        ans += nec;

        q.push({a * nec, point[i] + 2 * d});
    }
    cout << ans << endl;
}

Measured memory_bytes: 8192
import sys

array = list(map(int, input().strip().split(' ')))

X = array[0]
Y = array[1]


#print(A)
#print(B)
#print(K)


if X < 1:
    sys.exit()
if X > 100:
    sys.exit()

#print("Bok")


if Y < 1:
    sys.exit()
if Y > 100:
    sys.exit()
if Y % 2 ==1:
    sys.exit()


x = int(X + Y / 2)

print(x)


Measured memory_bytes: 3060
#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;

vector<long long>dp;
vector<long long>pre;


void compute_score(int i, const vector<int>& not_taken, long long score_so_far, int mask, int group) {
  if (i == not_taken.size()) {
    dp[mask] = max(dp[mask], score_so_far + pre[group]);
    return;
  }
  compute_score(i + 1, not_taken, score_so_far, mask ^ (1 << not_taken[i]), group ^ (1 << not_taken[i]));
  compute_score(i + 1, not_taken, score_so_far, mask, group);
}

int main() {
  int n; cin >> n;
  vector<vector<int>>a(n, vector<int>(n));
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < n; j++) {
      cin >> a[i][j];
    }
  }
  dp.resize(1<<n, -1e3);
  pre.resize(1<<n, 0);
  dp[0] = 0;
  for (int mask = 0; mask < (1 << n); mask++) {
    for (int i = 0; i < n; i++) {
      if ((1 << i) & mask) {
        for (int j = i + 1; j < n; j++) {
          if ((1 << j) & mask) {
            pre[mask] += a[i][j];
          }
        }
      }
    }
  }
  for (int mask = 0; mask < (1 << n); mask++) {
    vector<int>not_taken;
    for (int i = 0; i < n; i++) {
      if (!((1<<i) & mask)) {
        not_taken.push_back(i);
      }
    }
    compute_score(0, not_taken, dp[mask], mask, 0);
  }
  cout << dp[(1 << n) - 1] << "\n";
  return 0;
}


Measured memory_bytes: 1280
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<int(n);++i)
#define all(a) a.begin(),a.end()
#define lb(s,x) lower_bound(all(s),x)-s.begin()

struct Line{
    int start,end,pos;
    bool operator<(const Line& b) const{
        return pos < b.pos;
    }
};

int main(){
    vector<Line> vx,vy;
    int n,cnt=0;
    cin>>n;
    rep(i,n){
        int x1,y1,x2,y2;
        cin>>x1>>y1>>x2>>y2;
        if(x1!=x2)vx.push_back({min(x1,x2),max(x1,x2),y1}); 
        else      vy.push_back({min(y1,y2),max(y1,y2),x1});      
    }
    sort(all(vy));
    for(auto _:vx){
        Line s = {0,0,_.start};
        Line e = {0,0,_.end+1};
        int l = lb(vy,s);
        int r = lb(vy,e);
        for(int i=l;i<r;++i){
            if(vy[i].start<=_.pos && _.pos<=vy[i].end)cnt++;
        }
    }
    cout<<cnt<<endl;
    return 0;
}

Measured memory_bytes: 4608
// AtCoder My Practice
// author: Leonardone @ NEETSDKASU

fn main() {
	let mut stdin = String::new();
    std::io::Read::read_to_string(
    	&mut std::io::stdin(),
        &mut stdin).unwrap();
	let mut stdin = stdin.split_whitespace();
    let mut get = || stdin.next().unwrap();
    macro_rules! get {
    	($t:ty) => (get().parse::<$t>().unwrap());
        () => (get!(i64));
    }
    
    let n = get!();
    
    if n < 1000 {
    	println!("ABC");
    } else {
    	println!("ABD");
    }
    
}

Measured memory_bytes: 4352
n = int(input())
A = sorted(list(map(int, input().split())))
M = 10**6 + 1
L = [0]*M
for a in A:
    L[a] += 1
    if L[a] == 1:
        # k>=2として k*aは全て不適
        for i in range(2*a, M, a):
            L[i] += 2
# flagの数が答え
print(L.count(1))

Measured memory_bytes: 32236
from collections import Counter


N = int(input())
A = list(map(int, input().split()))
count_A = Counter(A)
sum_A = sum([i*(i-1)//2 for i in count_A.values()])

for k in range(N):
    n = count_A[A[k]]
    ans = sum_A - n + 1
    print(ans)

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

int main(){
    int n, m ,p;
    int cnt, winner;
    int tmp;
    while (1){
        cin >> n >> m >> p;
        if (n == 0 && m == 0 && p == 0) break;
        cnt = 0;
        for (int i = 1; i <= n; i++){
            cin >> tmp;
            cnt += tmp;
            if (i == m) winner = tmp;
        }
        if (winner) cout << cnt * (100 - p) / winner << endl;
        else cout << 0 << endl;
    }
}



Measured memory_bytes: 3084
n, h = list(map(int, input().split()))
cut = 0
throw = []

for i in range(n):
    a, b = list(map(int, input().split()))
    cut = max(cut, a)
    throw.append(b)

throw.sort(reverse=True)
throw_cam = []
for i in range(n):
    if cut > throw[i]:
        break
    if i == 0:
        throw_cam.append(throw[0])
    else:
        throw_cam.append(throw[i] + throw_cam[i-1])

if throw_cam[len(throw_cam)-1] < h:
    rh = h - throw_cam[len(throw_cam)-1]
    if rh % cut == 0:
        print(len(throw_cam) + rh//cut)
    else:
        print(len(throw_cam) + rh//cut + 1)
else:
    for i in range(len(throw_cam)):
        d = throw_cam[i]
        if d >= h:
            print(i+1)
            break




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

int alpha_to_int(char a) {
    string alpha = "abcdefghijklmnopqrstuvwxyz";
    return alpha.find(a);
}

int main() {
    string s;
    cin >> s;
    int cnt[26] = {};
    rep(i,s.size()) {
        cnt[alpha_to_int(s[i])]++;
    }
    rep(i,26) {
        if (cnt[i] % 2 != 0) {
            cout << "No" << endl;
            return 0;
        }
    }
    cout << "Yes" << endl;
}

Measured memory_bytes: 256
import java.util.*;
public class Main {
	public static void main(String[] args) {
	Scanner sc = new Scanner(System.in);
	
	int i;		
	int diff1,diff2,result;

	Integer[] Input = new Integer[3];
	
	for(i=0;i<3;i++) {
		Input[i] = sc.nextInt();
	}
	
	Arrays.sort(Input);
	
	
	diff1 = Input[1] - Input[0];
	diff2 = Input[2] - Input[1];
	result = diff1 + diff2;
	
	
	System.out.println(result);
	
	}
}


Measured memory_bytes: 21844
#include<bits/stdc++.h>
// #include <boost/lexical_cast.hpp>
using namespace std;

#define ll long long int
#define vll vector<ll>
#define vllv vector<vector<ll>> 
#define vpii vector<pair<ll,ll>>
#define sz size()
#define pb push_back
#define ff first
#define ss second
#define all(v) v.begin(),v.end()
#define allr(v) v.rbegin(),v.rend()
#define fast ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
ll MOD=1000000000+7;
ll ceil1(ll n,ll m){if(n%m==0){return n/m;}return n/m +1;}
vll factor(ll n){
    vll ans;
	if(n==2)ans.pb(2);
	else
    {for(ll i=2;i*i<=n;i++){if(n%i==0 && n%i!=i){ans.pb(i);if(n/i!=i)ans.pb(n/i);}}ans.pb(n);}
    return ans;
}
ll fact(ll n){ll res = 1;for (ll i = 2; i <= n; i++)res = res * i; 
    return res; } 
  
ll nCr(ll n, ll r){ return fact(n) / (fact(r) * fact(n - r)); } 
  
void dfs(vllv &v,ll k,vll &par,vll &dis,ll p)
{
    par[k]=p;
    dis[k]=dis[p]+1;
    for(ll i=0;i<v[k].sz;i++){
        if(v[k][i]!=p){
            dfs(v,v[k][i],par,dis,k);
        }
    }
}
bool sortbysec(const pair<string,int> &a,const pair<string,int> &b){return (a.second<b.second);} 

ll pow2(ll n,ll k){ll ans=1;
    while(k>0){
        if(k%2==1)ans=ans*n;n=n*n;k/=2;
    }return ans;}
bool prime(int n){
    int i,j;
    for(i=2;i<=sqrt(n);i++){
        if(n%i==0){
            return false;
        }
    }
    return true;
}
bool bserch(vector<string> a, string s){
	ll l=0,r=a.sz-1,mid;
	while(l<=r){
		mid=(l+r)/2;
		if(a[mid]==s)return true;
		if(a[mid]<s){
			l=mid+1;
		}else{
			r=mid-1;
		}
	}
	return false;
}

bool sortcol(const vector<int>& v1, 
               const vector<int>& v2){ 
 return v1[0] < v2[0]; } 

 ll degit(ll n)
 {
 	ll t=0;
 	while(n>0)
 	{
 		t++;
 		n/=10; 	}
 		return t;
 }

void solve()
{	
	ll a;
	cin>>a;
	cout<<a*(1+a+a*a);
	return;
}

int main()
{
	fast;
    ll q;
    q=1;
    // cin>>q;
    while(q--)
    {
        solve();
    }
    return 0;
}


Measured memory_bytes: 3616
#include <bits/stdc++.h>
#define PI 3.14159265358979323846
#define MAXINF (1e18L)
#define INF (1e9L)
#define EPS (1e-9)
#define MOD ((ll)(1e9+7))
#define REP(i, n) for(int i=0;i<int(n);++i)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define RREP(i, n) for(int i=int(n)-1;i>=0;--i)
#define ALL(v) v.begin(),v.end()
#define FIND(v,x) (binary_search(ALL(v),(x)))
#define SORT(v) sort(ALL(v))
#define RSORT(v) sort(ALL(v));reverse(ALL(v))
#define DEBUG(x) cerr<<#x<<": "<<x<<endl;
#define DEBUG_VEC(v) cerr<<#v<<":";for(int i=0;i<v.size();i++) cerr<<" "<<v[i]; cerr<<endl
#define Yes(n) cout<<((n)?"Yes":"No")<<endl
#define YES(n) cout<<((n)?"YES":"NO")<<endl
#define pb push_back
#define fi first
#define se second
using namespace std;
template<class A>void pr(A a){cout << (a) << endl;}
template<class A,class B>void pr(A a,B b){cout << a << " "  ;pr(b);}
template<class A,class B,class C>void pr(A a,B b,C c){cout << a << " " ;pr(b,c);}
template<class A,class B,class C,class D>void pr(A a,B b,C c,D d){cout << a << " " ;pr(b,c,d);}
template<class T> inline bool chmin(T& a, T b){return a>b ? a=b, true : false;}
template<class T> inline bool chmax(T& a, T b){return a<b ? a=b, true : false;}
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll,ll> pll;

int main(void)
{
    string S;
    cin >> S;
    if(S=="AAA" || S=="BBB"){
        Yes(0);
    }else{
        Yes(1);
    }
}

Measured memory_bytes: 256
#include <iostream>
#include <complex>
#include <cstdio>
#include <vector>
#include <queue>
using namespace std;
typedef complex<double> P;
typedef pair<P,P> L;
#define X real()
#define Y imag()
const double EPS = (1e-10);
const double INF = (1e15);

double dot(P a, P b){
  return a.X * b.X + a.Y * b.Y;
}
double cross(P a, P b){
  return a.X * b.Y - a.Y * b.X;
}

int ccw(P a, P b, P c) {
  b -= a; c -= a;
  if( cross(b,c) > EPS ) return +1;
  if( cross(b,c) < -EPS ) return -1;
  if( dot(b,c) < 0 ) return +2;
  if( abs(b) + EPS < abs(c) ) return -2;
  return 0;
}

bool is_cross(L a, L b){
  return (ccw(a.first,a.second,b.first)*ccw(a.first,a.second,b.second) <= 0 &&
          ccw(b.first,b.second,a.first)*ccw(b.first,b.second,a.second) <= 0);
}

double dijkstra(vector< vector< pair<int, double> > > &G){
  int N = G.size();
  priority_queue< pair<double, int> > wait;
  vector<double> D(N, INF);
  wait.emplace(0, 0);
  while(!wait.empty()){
    double d = -wait.top().first;
    int v = wait.top().second;
    wait.pop();
    if(d > D[v] + EPS) continue;
    D[v] = d;
    for(int i = 0; i < G[v].size(); ++i){
      int v_ = G[v][i].first;
      double d_ = d + G[v][i].second;
      if(d_ < D[v_]){
        D[v_] = d_;
        wait.emplace(-d_, v_);
      }
    }
  }
  return D[1];
}

double solve(vector<P> &A, vector<P> &B){
  L l = L(A[0], A[1]);
  int Nb = B.size();
  vector< vector< pair<int, double> > > G(Nb);
  for(int i = 0; i < Nb; ++i){
    for(int j = 0; j < i; ++j){
      if(is_cross(l, L(B[i], B[j]))) continue;
      G[i].emplace_back(j, abs(B[i] - B[j]));
      G[j].emplace_back(i, abs(B[i] - B[j]));
    }
  }
  return dijkstra(G) + abs(A[0] - A[1]);
}

int main(){
  int Na, Nb;
  cin >> Na >> Nb;
  vector<P> A(Na), B(Nb);
  for(int i = 0; i < Na; ++i){
    double x, y;
    cin >> x >> y;
    A[i] = P(x, y);
  }
  for(int i = 0; i < Nb; ++i){
    double x, y;
    cin >> x >> y;
    B[i] = P(x, y);
  }
  double ans = min(solve(A, B), solve(B, A));
  if(ans >= INF - EPS) cout << -1 << endl;
  else printf("%.12f\n", ans);
  return 0;
}



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

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

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

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

ll gcd(ll x, ll y) {
  if (y == 0) {
    return x;
  }
  return gcd(y, x % y);
}

ll nCr(ll n, ll r) {
  if (n < r) {
    return 0;
  }
  ll p = 1, k = 1;
  if (n - r < r)
    r = n - r;

  if (r != 0) {
    while (r) {
      p *= n;
      k *= r;
      ll m = gcd(p, k);
      p /= m;
      k /= m;
      n--;
      r--;
    }
  } else {
    p = 1;
  }
  return p;
}

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

    ll N;
    cin >> N;

    vector<ll> array(N, 0);
    vector<ll> counts(N, 0);
    REP(i, N){ 
        ll val;
        cin >> val;
        array[i] = val - 1 ;
        counts[val-1]++;
    }

    vector<ll> combs(N, 0);

    ll total = 0;
    REP(i, N){
        combs[i] = nCr(counts[i],2);
        total += combs[i];
    }

    REP(i,N){
        ll val = array[i];
        ll new_total = total - ( combs[val] - nCr(counts[val]-1, 2) );
        cout << new_total << endl;
    }
}


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

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

	vector<string> S(N);

	for (int i = 0; i < N; i++) {
		cin >> S.at(i);
	}

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

	int count = 1;
	int num_words = 0;
	vector<int> index(N);
	vector<int> num(N);
	int num_max = 0;
	vector<string> S2(N);
	for (int i = 0; i < N - 1; i++) {
		if (S.at(i) == S.at(i + 1)) {
			count++;
		} else {
			S2.at(num_words) = S.at(i);
			num.at(num_words) = count;
			if (num_max < count) {
				num_max = count;
			}
			count = 1;
			num_words++;
		}
	}
	if (S.at(N - 2) == S.at(N - 1)) {
		S2.at(num_words) = S.at(N - 1);
		if (num_max < count) {
			num_max = count;
		}
		num.at(num_words) = count;
	} else {
		S2.at(num_words) = S.at(N - 1);
		num.at(num_words) = 1;
	}
	num_words++;

	int i = 0;
	for (int i = 0; i < num_words; i++) {
		if (num.at(i) == num_max) {
			cout << S2.at(i) << endl;
		}
	}

	return 0;
}


Measured memory_bytes: 17408
#include <bits/stdc++.h>
using namespace std;
 
int main(){
  int N, K;
  cin >> N >> K;
 
  vector<int> d;
  vector<vector<int>> A;
  d.resize(K);
  A.resize(K, vector<int>());
  int i, j;
  int ans = 0;
 
  for (i = 0; i < K; i++){
    cin >> d[i];
    A[i].resize(d[i]);
    for (j = 0; j < d[i]; j++){
      cin >> A[i][j];
    }
  }
  
  for (i = 1; i <= N; i++){
    bool have = false;
    for(auto v : A){
      for(auto p : v){
         if(p == i) have = true;
      }
    }
    if(!have) ans++;
  }
  cout << ans << endl;
 
}

Measured memory_bytes: 3640